netcp_ethss.c 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787
  1. /*
  2. * Keystone GBE and XGBE subsystem code
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated
  5. * Authors: Sandeep Nair <sandeep_n@ti.com>
  6. * Sandeep Paulraj <s-paulraj@ti.com>
  7. * Cyril Chemparathy <cyril@ti.com>
  8. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  9. * Wingman Kwok <w-kwok2@ti.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation version 2.
  14. *
  15. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  16. * kind, whether express or implied; without even the implied warranty
  17. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. */
  20. #include <linux/io.h>
  21. #include <linux/module.h>
  22. #include <linux/of_mdio.h>
  23. #include <linux/of_address.h>
  24. #include <linux/if_vlan.h>
  25. #include <linux/ptp_classify.h>
  26. #include <linux/net_tstamp.h>
  27. #include <linux/ethtool.h>
  28. #include "cpsw_ale.h"
  29. #include "netcp.h"
  30. #include "cpts.h"
  31. #define NETCP_DRIVER_NAME "TI KeyStone Ethernet Driver"
  32. #define NETCP_DRIVER_VERSION "v1.0"
  33. #define GBE_IDENT(reg) ((reg >> 16) & 0xffff)
  34. #define GBE_MAJOR_VERSION(reg) (reg >> 8 & 0x7)
  35. #define GBE_MINOR_VERSION(reg) (reg & 0xff)
  36. #define GBE_RTL_VERSION(reg) ((reg >> 11) & 0x1f)
  37. /* 1G Ethernet SS defines */
  38. #define GBE_MODULE_NAME "netcp-gbe"
  39. #define GBE_SS_VERSION_14 0x4ed21104
  40. #define GBE_SS_REG_INDEX 0
  41. #define GBE_SGMII34_REG_INDEX 1
  42. #define GBE_SM_REG_INDEX 2
  43. /* offset relative to base of GBE_SS_REG_INDEX */
  44. #define GBE13_SGMII_MODULE_OFFSET 0x100
  45. /* offset relative to base of GBE_SM_REG_INDEX */
  46. #define GBE13_HOST_PORT_OFFSET 0x34
  47. #define GBE13_SLAVE_PORT_OFFSET 0x60
  48. #define GBE13_EMAC_OFFSET 0x100
  49. #define GBE13_SLAVE_PORT2_OFFSET 0x200
  50. #define GBE13_HW_STATS_OFFSET 0x300
  51. #define GBE13_CPTS_OFFSET 0x500
  52. #define GBE13_ALE_OFFSET 0x600
  53. #define GBE13_HOST_PORT_NUM 0
  54. #define GBE13_NUM_ALE_ENTRIES 1024
  55. /* 1G Ethernet NU SS defines */
  56. #define GBENU_MODULE_NAME "netcp-gbenu"
  57. #define GBE_SS_ID_NU 0x4ee6
  58. #define GBE_SS_ID_2U 0x4ee8
  59. #define IS_SS_ID_MU(d) \
  60. ((GBE_IDENT((d)->ss_version) == GBE_SS_ID_NU) || \
  61. (GBE_IDENT((d)->ss_version) == GBE_SS_ID_2U))
  62. #define IS_SS_ID_NU(d) \
  63. (GBE_IDENT((d)->ss_version) == GBE_SS_ID_NU)
  64. #define GBENU_SS_REG_INDEX 0
  65. #define GBENU_SM_REG_INDEX 1
  66. #define GBENU_SGMII_MODULE_OFFSET 0x100
  67. #define GBENU_HOST_PORT_OFFSET 0x1000
  68. #define GBENU_SLAVE_PORT_OFFSET 0x2000
  69. #define GBENU_EMAC_OFFSET 0x2330
  70. #define GBENU_HW_STATS_OFFSET 0x1a000
  71. #define GBENU_CPTS_OFFSET 0x1d000
  72. #define GBENU_ALE_OFFSET 0x1e000
  73. #define GBENU_HOST_PORT_NUM 0
  74. #define GBENU_SGMII_MODULE_SIZE 0x100
  75. /* 10G Ethernet SS defines */
  76. #define XGBE_MODULE_NAME "netcp-xgbe"
  77. #define XGBE_SS_VERSION_10 0x4ee42100
  78. #define XGBE_SS_REG_INDEX 0
  79. #define XGBE_SM_REG_INDEX 1
  80. #define XGBE_SERDES_REG_INDEX 2
  81. /* offset relative to base of XGBE_SS_REG_INDEX */
  82. #define XGBE10_SGMII_MODULE_OFFSET 0x100
  83. #define IS_SS_ID_XGBE(d) ((d)->ss_version == XGBE_SS_VERSION_10)
  84. /* offset relative to base of XGBE_SM_REG_INDEX */
  85. #define XGBE10_HOST_PORT_OFFSET 0x34
  86. #define XGBE10_SLAVE_PORT_OFFSET 0x64
  87. #define XGBE10_EMAC_OFFSET 0x400
  88. #define XGBE10_CPTS_OFFSET 0x600
  89. #define XGBE10_ALE_OFFSET 0x700
  90. #define XGBE10_HW_STATS_OFFSET 0x800
  91. #define XGBE10_HOST_PORT_NUM 0
  92. #define XGBE10_NUM_ALE_ENTRIES 2048
  93. #define GBE_TIMER_INTERVAL (HZ / 2)
  94. /* Soft reset register values */
  95. #define SOFT_RESET_MASK BIT(0)
  96. #define SOFT_RESET BIT(0)
  97. #define DEVICE_EMACSL_RESET_POLL_COUNT 100
  98. #define GMACSL_RET_WARN_RESET_INCOMPLETE -2
  99. #define MACSL_RX_ENABLE_CSF BIT(23)
  100. #define MACSL_ENABLE_EXT_CTL BIT(18)
  101. #define MACSL_XGMII_ENABLE BIT(13)
  102. #define MACSL_XGIG_MODE BIT(8)
  103. #define MACSL_GIG_MODE BIT(7)
  104. #define MACSL_GMII_ENABLE BIT(5)
  105. #define MACSL_FULLDUPLEX BIT(0)
  106. #define GBE_CTL_P0_ENABLE BIT(2)
  107. #define ETH_SW_CTL_P0_TX_CRC_REMOVE BIT(13)
  108. #define GBE13_REG_VAL_STAT_ENABLE_ALL 0xff
  109. #define XGBE_REG_VAL_STAT_ENABLE_ALL 0xf
  110. #define GBE_STATS_CD_SEL BIT(28)
  111. #define GBE_PORT_MASK(x) (BIT(x) - 1)
  112. #define GBE_MASK_NO_PORTS 0
  113. #define GBE_DEF_1G_MAC_CONTROL \
  114. (MACSL_GIG_MODE | MACSL_GMII_ENABLE | \
  115. MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF)
  116. #define GBE_DEF_10G_MAC_CONTROL \
  117. (MACSL_XGIG_MODE | MACSL_XGMII_ENABLE | \
  118. MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF)
  119. #define GBE_STATSA_MODULE 0
  120. #define GBE_STATSB_MODULE 1
  121. #define GBE_STATSC_MODULE 2
  122. #define GBE_STATSD_MODULE 3
  123. #define GBENU_STATS0_MODULE 0
  124. #define GBENU_STATS1_MODULE 1
  125. #define GBENU_STATS2_MODULE 2
  126. #define GBENU_STATS3_MODULE 3
  127. #define GBENU_STATS4_MODULE 4
  128. #define GBENU_STATS5_MODULE 5
  129. #define GBENU_STATS6_MODULE 6
  130. #define GBENU_STATS7_MODULE 7
  131. #define GBENU_STATS8_MODULE 8
  132. #define XGBE_STATS0_MODULE 0
  133. #define XGBE_STATS1_MODULE 1
  134. #define XGBE_STATS2_MODULE 2
  135. /* s: 0-based slave_port */
  136. #define SGMII_BASE(d, s) \
  137. (((s) < 2) ? (d)->sgmii_port_regs : (d)->sgmii_port34_regs)
  138. #define GBE_TX_QUEUE 648
  139. #define GBE_TXHOOK_ORDER 0
  140. #define GBE_RXHOOK_ORDER 0
  141. #define GBE_DEFAULT_ALE_AGEOUT 30
  142. #define SLAVE_LINK_IS_XGMII(s) ((s)->link_interface >= XGMII_LINK_MAC_PHY)
  143. #define NETCP_LINK_STATE_INVALID -1
  144. #define GBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
  145. offsetof(struct gbe##_##rb, rn)
  146. #define GBENU_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
  147. offsetof(struct gbenu##_##rb, rn)
  148. #define XGBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
  149. offsetof(struct xgbe##_##rb, rn)
  150. #define GBE_REG_ADDR(p, rb, rn) (p->rb + p->rb##_ofs.rn)
  151. #define HOST_TX_PRI_MAP_DEFAULT 0x00000000
  152. #if IS_ENABLED(CONFIG_TI_CPTS)
  153. /* Px_TS_CTL register fields */
  154. #define TS_RX_ANX_F_EN BIT(0)
  155. #define TS_RX_VLAN_LT1_EN BIT(1)
  156. #define TS_RX_VLAN_LT2_EN BIT(2)
  157. #define TS_RX_ANX_D_EN BIT(3)
  158. #define TS_TX_ANX_F_EN BIT(4)
  159. #define TS_TX_VLAN_LT1_EN BIT(5)
  160. #define TS_TX_VLAN_LT2_EN BIT(6)
  161. #define TS_TX_ANX_D_EN BIT(7)
  162. #define TS_LT2_EN BIT(8)
  163. #define TS_RX_ANX_E_EN BIT(9)
  164. #define TS_TX_ANX_E_EN BIT(10)
  165. #define TS_MSG_TYPE_EN_SHIFT 16
  166. #define TS_MSG_TYPE_EN_MASK 0xffff
  167. /* Px_TS_SEQ_LTYPE register fields */
  168. #define TS_SEQ_ID_OFS_SHIFT 16
  169. #define TS_SEQ_ID_OFS_MASK 0x3f
  170. /* Px_TS_CTL_LTYPE2 register fields */
  171. #define TS_107 BIT(16)
  172. #define TS_129 BIT(17)
  173. #define TS_130 BIT(18)
  174. #define TS_131 BIT(19)
  175. #define TS_132 BIT(20)
  176. #define TS_319 BIT(21)
  177. #define TS_320 BIT(22)
  178. #define TS_TTL_NONZERO BIT(23)
  179. #define TS_UNI_EN BIT(24)
  180. #define TS_UNI_EN_SHIFT 24
  181. #define TS_TX_ANX_ALL_EN \
  182. (TS_TX_ANX_D_EN | TS_TX_ANX_E_EN | TS_TX_ANX_F_EN)
  183. #define TS_RX_ANX_ALL_EN \
  184. (TS_RX_ANX_D_EN | TS_RX_ANX_E_EN | TS_RX_ANX_F_EN)
  185. #define TS_CTL_DST_PORT TS_319
  186. #define TS_CTL_DST_PORT_SHIFT 21
  187. #define TS_CTL_MADDR_ALL \
  188. (TS_107 | TS_129 | TS_130 | TS_131 | TS_132)
  189. #define TS_CTL_MADDR_SHIFT 16
  190. /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */
  191. #define EVENT_MSG_BITS (BIT(0) | BIT(1) | BIT(2) | BIT(3))
  192. #endif /* CONFIG_TI_CPTS */
  193. struct xgbe_ss_regs {
  194. u32 id_ver;
  195. u32 synce_count;
  196. u32 synce_mux;
  197. u32 control;
  198. };
  199. struct xgbe_switch_regs {
  200. u32 id_ver;
  201. u32 control;
  202. u32 emcontrol;
  203. u32 stat_port_en;
  204. u32 ptype;
  205. u32 soft_idle;
  206. u32 thru_rate;
  207. u32 gap_thresh;
  208. u32 tx_start_wds;
  209. u32 flow_control;
  210. u32 cppi_thresh;
  211. };
  212. struct xgbe_port_regs {
  213. u32 blk_cnt;
  214. u32 port_vlan;
  215. u32 tx_pri_map;
  216. u32 sa_lo;
  217. u32 sa_hi;
  218. u32 ts_ctl;
  219. u32 ts_seq_ltype;
  220. u32 ts_vlan;
  221. u32 ts_ctl_ltype2;
  222. u32 ts_ctl2;
  223. u32 control;
  224. };
  225. struct xgbe_host_port_regs {
  226. u32 blk_cnt;
  227. u32 port_vlan;
  228. u32 tx_pri_map;
  229. u32 src_id;
  230. u32 rx_pri_map;
  231. u32 rx_maxlen;
  232. };
  233. struct xgbe_emac_regs {
  234. u32 id_ver;
  235. u32 mac_control;
  236. u32 mac_status;
  237. u32 soft_reset;
  238. u32 rx_maxlen;
  239. u32 __reserved_0;
  240. u32 rx_pause;
  241. u32 tx_pause;
  242. u32 em_control;
  243. u32 __reserved_1;
  244. u32 tx_gap;
  245. u32 rsvd[4];
  246. };
  247. struct xgbe_host_hw_stats {
  248. u32 rx_good_frames;
  249. u32 rx_broadcast_frames;
  250. u32 rx_multicast_frames;
  251. u32 __rsvd_0[3];
  252. u32 rx_oversized_frames;
  253. u32 __rsvd_1;
  254. u32 rx_undersized_frames;
  255. u32 __rsvd_2;
  256. u32 overrun_type4;
  257. u32 overrun_type5;
  258. u32 rx_bytes;
  259. u32 tx_good_frames;
  260. u32 tx_broadcast_frames;
  261. u32 tx_multicast_frames;
  262. u32 __rsvd_3[9];
  263. u32 tx_bytes;
  264. u32 tx_64byte_frames;
  265. u32 tx_65_to_127byte_frames;
  266. u32 tx_128_to_255byte_frames;
  267. u32 tx_256_to_511byte_frames;
  268. u32 tx_512_to_1023byte_frames;
  269. u32 tx_1024byte_frames;
  270. u32 net_bytes;
  271. u32 rx_sof_overruns;
  272. u32 rx_mof_overruns;
  273. u32 rx_dma_overruns;
  274. };
  275. struct xgbe_hw_stats {
  276. u32 rx_good_frames;
  277. u32 rx_broadcast_frames;
  278. u32 rx_multicast_frames;
  279. u32 rx_pause_frames;
  280. u32 rx_crc_errors;
  281. u32 rx_align_code_errors;
  282. u32 rx_oversized_frames;
  283. u32 rx_jabber_frames;
  284. u32 rx_undersized_frames;
  285. u32 rx_fragments;
  286. u32 overrun_type4;
  287. u32 overrun_type5;
  288. u32 rx_bytes;
  289. u32 tx_good_frames;
  290. u32 tx_broadcast_frames;
  291. u32 tx_multicast_frames;
  292. u32 tx_pause_frames;
  293. u32 tx_deferred_frames;
  294. u32 tx_collision_frames;
  295. u32 tx_single_coll_frames;
  296. u32 tx_mult_coll_frames;
  297. u32 tx_excessive_collisions;
  298. u32 tx_late_collisions;
  299. u32 tx_underrun;
  300. u32 tx_carrier_sense_errors;
  301. u32 tx_bytes;
  302. u32 tx_64byte_frames;
  303. u32 tx_65_to_127byte_frames;
  304. u32 tx_128_to_255byte_frames;
  305. u32 tx_256_to_511byte_frames;
  306. u32 tx_512_to_1023byte_frames;
  307. u32 tx_1024byte_frames;
  308. u32 net_bytes;
  309. u32 rx_sof_overruns;
  310. u32 rx_mof_overruns;
  311. u32 rx_dma_overruns;
  312. };
  313. struct gbenu_ss_regs {
  314. u32 id_ver;
  315. u32 synce_count; /* NU */
  316. u32 synce_mux; /* NU */
  317. u32 control; /* 2U */
  318. u32 __rsvd_0[2]; /* 2U */
  319. u32 rgmii_status; /* 2U */
  320. u32 ss_status; /* 2U */
  321. };
  322. struct gbenu_switch_regs {
  323. u32 id_ver;
  324. u32 control;
  325. u32 __rsvd_0[2];
  326. u32 emcontrol;
  327. u32 stat_port_en;
  328. u32 ptype; /* NU */
  329. u32 soft_idle;
  330. u32 thru_rate; /* NU */
  331. u32 gap_thresh; /* NU */
  332. u32 tx_start_wds; /* NU */
  333. u32 eee_prescale; /* 2U */
  334. u32 tx_g_oflow_thresh_set; /* NU */
  335. u32 tx_g_oflow_thresh_clr; /* NU */
  336. u32 tx_g_buf_thresh_set_l; /* NU */
  337. u32 tx_g_buf_thresh_set_h; /* NU */
  338. u32 tx_g_buf_thresh_clr_l; /* NU */
  339. u32 tx_g_buf_thresh_clr_h; /* NU */
  340. };
  341. struct gbenu_port_regs {
  342. u32 __rsvd_0;
  343. u32 control;
  344. u32 max_blks; /* 2U */
  345. u32 mem_align1;
  346. u32 blk_cnt;
  347. u32 port_vlan;
  348. u32 tx_pri_map; /* NU */
  349. u32 pri_ctl; /* 2U */
  350. u32 rx_pri_map;
  351. u32 rx_maxlen;
  352. u32 tx_blks_pri; /* NU */
  353. u32 __rsvd_1;
  354. u32 idle2lpi; /* 2U */
  355. u32 lpi2idle; /* 2U */
  356. u32 eee_status; /* 2U */
  357. u32 __rsvd_2;
  358. u32 __rsvd_3[176]; /* NU: more to add */
  359. u32 __rsvd_4[2];
  360. u32 sa_lo;
  361. u32 sa_hi;
  362. u32 ts_ctl;
  363. u32 ts_seq_ltype;
  364. u32 ts_vlan;
  365. u32 ts_ctl_ltype2;
  366. u32 ts_ctl2;
  367. };
  368. struct gbenu_host_port_regs {
  369. u32 __rsvd_0;
  370. u32 control;
  371. u32 flow_id_offset; /* 2U */
  372. u32 __rsvd_1;
  373. u32 blk_cnt;
  374. u32 port_vlan;
  375. u32 tx_pri_map; /* NU */
  376. u32 pri_ctl;
  377. u32 rx_pri_map;
  378. u32 rx_maxlen;
  379. u32 tx_blks_pri; /* NU */
  380. u32 __rsvd_2;
  381. u32 idle2lpi; /* 2U */
  382. u32 lpi2wake; /* 2U */
  383. u32 eee_status; /* 2U */
  384. u32 __rsvd_3;
  385. u32 __rsvd_4[184]; /* NU */
  386. u32 host_blks_pri; /* NU */
  387. };
  388. struct gbenu_emac_regs {
  389. u32 mac_control;
  390. u32 mac_status;
  391. u32 soft_reset;
  392. u32 boff_test;
  393. u32 rx_pause;
  394. u32 __rsvd_0[11]; /* NU */
  395. u32 tx_pause;
  396. u32 __rsvd_1[11]; /* NU */
  397. u32 em_control;
  398. u32 tx_gap;
  399. };
  400. /* Some hw stat regs are applicable to slave port only.
  401. * This is handled by gbenu_et_stats struct. Also some
  402. * are for SS version NU and some are for 2U.
  403. */
  404. struct gbenu_hw_stats {
  405. u32 rx_good_frames;
  406. u32 rx_broadcast_frames;
  407. u32 rx_multicast_frames;
  408. u32 rx_pause_frames; /* slave */
  409. u32 rx_crc_errors;
  410. u32 rx_align_code_errors; /* slave */
  411. u32 rx_oversized_frames;
  412. u32 rx_jabber_frames; /* slave */
  413. u32 rx_undersized_frames;
  414. u32 rx_fragments; /* slave */
  415. u32 ale_drop;
  416. u32 ale_overrun_drop;
  417. u32 rx_bytes;
  418. u32 tx_good_frames;
  419. u32 tx_broadcast_frames;
  420. u32 tx_multicast_frames;
  421. u32 tx_pause_frames; /* slave */
  422. u32 tx_deferred_frames; /* slave */
  423. u32 tx_collision_frames; /* slave */
  424. u32 tx_single_coll_frames; /* slave */
  425. u32 tx_mult_coll_frames; /* slave */
  426. u32 tx_excessive_collisions; /* slave */
  427. u32 tx_late_collisions; /* slave */
  428. u32 rx_ipg_error; /* slave 10G only */
  429. u32 tx_carrier_sense_errors; /* slave */
  430. u32 tx_bytes;
  431. u32 tx_64B_frames;
  432. u32 tx_65_to_127B_frames;
  433. u32 tx_128_to_255B_frames;
  434. u32 tx_256_to_511B_frames;
  435. u32 tx_512_to_1023B_frames;
  436. u32 tx_1024B_frames;
  437. u32 net_bytes;
  438. u32 rx_bottom_fifo_drop;
  439. u32 rx_port_mask_drop;
  440. u32 rx_top_fifo_drop;
  441. u32 ale_rate_limit_drop;
  442. u32 ale_vid_ingress_drop;
  443. u32 ale_da_eq_sa_drop;
  444. u32 __rsvd_0[3];
  445. u32 ale_unknown_ucast;
  446. u32 ale_unknown_ucast_bytes;
  447. u32 ale_unknown_mcast;
  448. u32 ale_unknown_mcast_bytes;
  449. u32 ale_unknown_bcast;
  450. u32 ale_unknown_bcast_bytes;
  451. u32 ale_pol_match;
  452. u32 ale_pol_match_red; /* NU */
  453. u32 ale_pol_match_yellow; /* NU */
  454. u32 __rsvd_1[44];
  455. u32 tx_mem_protect_err;
  456. /* following NU only */
  457. u32 tx_pri0;
  458. u32 tx_pri1;
  459. u32 tx_pri2;
  460. u32 tx_pri3;
  461. u32 tx_pri4;
  462. u32 tx_pri5;
  463. u32 tx_pri6;
  464. u32 tx_pri7;
  465. u32 tx_pri0_bcnt;
  466. u32 tx_pri1_bcnt;
  467. u32 tx_pri2_bcnt;
  468. u32 tx_pri3_bcnt;
  469. u32 tx_pri4_bcnt;
  470. u32 tx_pri5_bcnt;
  471. u32 tx_pri6_bcnt;
  472. u32 tx_pri7_bcnt;
  473. u32 tx_pri0_drop;
  474. u32 tx_pri1_drop;
  475. u32 tx_pri2_drop;
  476. u32 tx_pri3_drop;
  477. u32 tx_pri4_drop;
  478. u32 tx_pri5_drop;
  479. u32 tx_pri6_drop;
  480. u32 tx_pri7_drop;
  481. u32 tx_pri0_drop_bcnt;
  482. u32 tx_pri1_drop_bcnt;
  483. u32 tx_pri2_drop_bcnt;
  484. u32 tx_pri3_drop_bcnt;
  485. u32 tx_pri4_drop_bcnt;
  486. u32 tx_pri5_drop_bcnt;
  487. u32 tx_pri6_drop_bcnt;
  488. u32 tx_pri7_drop_bcnt;
  489. };
  490. #define GBENU_HW_STATS_REG_MAP_SZ 0x200
  491. struct gbe_ss_regs {
  492. u32 id_ver;
  493. u32 synce_count;
  494. u32 synce_mux;
  495. };
  496. struct gbe_ss_regs_ofs {
  497. u16 id_ver;
  498. u16 control;
  499. };
  500. struct gbe_switch_regs {
  501. u32 id_ver;
  502. u32 control;
  503. u32 soft_reset;
  504. u32 stat_port_en;
  505. u32 ptype;
  506. u32 soft_idle;
  507. u32 thru_rate;
  508. u32 gap_thresh;
  509. u32 tx_start_wds;
  510. u32 flow_control;
  511. };
  512. struct gbe_switch_regs_ofs {
  513. u16 id_ver;
  514. u16 control;
  515. u16 soft_reset;
  516. u16 emcontrol;
  517. u16 stat_port_en;
  518. u16 ptype;
  519. u16 flow_control;
  520. };
  521. struct gbe_port_regs {
  522. u32 max_blks;
  523. u32 blk_cnt;
  524. u32 port_vlan;
  525. u32 tx_pri_map;
  526. u32 sa_lo;
  527. u32 sa_hi;
  528. u32 ts_ctl;
  529. u32 ts_seq_ltype;
  530. u32 ts_vlan;
  531. u32 ts_ctl_ltype2;
  532. u32 ts_ctl2;
  533. };
  534. struct gbe_port_regs_ofs {
  535. u16 port_vlan;
  536. u16 tx_pri_map;
  537. u16 sa_lo;
  538. u16 sa_hi;
  539. u16 ts_ctl;
  540. u16 ts_seq_ltype;
  541. u16 ts_vlan;
  542. u16 ts_ctl_ltype2;
  543. u16 ts_ctl2;
  544. u16 rx_maxlen; /* 2U, NU */
  545. };
  546. struct gbe_host_port_regs {
  547. u32 src_id;
  548. u32 port_vlan;
  549. u32 rx_pri_map;
  550. u32 rx_maxlen;
  551. };
  552. struct gbe_host_port_regs_ofs {
  553. u16 port_vlan;
  554. u16 tx_pri_map;
  555. u16 rx_maxlen;
  556. };
  557. struct gbe_emac_regs {
  558. u32 id_ver;
  559. u32 mac_control;
  560. u32 mac_status;
  561. u32 soft_reset;
  562. u32 rx_maxlen;
  563. u32 __reserved_0;
  564. u32 rx_pause;
  565. u32 tx_pause;
  566. u32 __reserved_1;
  567. u32 rx_pri_map;
  568. u32 rsvd[6];
  569. };
  570. struct gbe_emac_regs_ofs {
  571. u16 mac_control;
  572. u16 soft_reset;
  573. u16 rx_maxlen;
  574. };
  575. struct gbe_hw_stats {
  576. u32 rx_good_frames;
  577. u32 rx_broadcast_frames;
  578. u32 rx_multicast_frames;
  579. u32 rx_pause_frames;
  580. u32 rx_crc_errors;
  581. u32 rx_align_code_errors;
  582. u32 rx_oversized_frames;
  583. u32 rx_jabber_frames;
  584. u32 rx_undersized_frames;
  585. u32 rx_fragments;
  586. u32 __pad_0[2];
  587. u32 rx_bytes;
  588. u32 tx_good_frames;
  589. u32 tx_broadcast_frames;
  590. u32 tx_multicast_frames;
  591. u32 tx_pause_frames;
  592. u32 tx_deferred_frames;
  593. u32 tx_collision_frames;
  594. u32 tx_single_coll_frames;
  595. u32 tx_mult_coll_frames;
  596. u32 tx_excessive_collisions;
  597. u32 tx_late_collisions;
  598. u32 tx_underrun;
  599. u32 tx_carrier_sense_errors;
  600. u32 tx_bytes;
  601. u32 tx_64byte_frames;
  602. u32 tx_65_to_127byte_frames;
  603. u32 tx_128_to_255byte_frames;
  604. u32 tx_256_to_511byte_frames;
  605. u32 tx_512_to_1023byte_frames;
  606. u32 tx_1024byte_frames;
  607. u32 net_bytes;
  608. u32 rx_sof_overruns;
  609. u32 rx_mof_overruns;
  610. u32 rx_dma_overruns;
  611. };
  612. #define GBE_MAX_HW_STAT_MODS 9
  613. #define GBE_HW_STATS_REG_MAP_SZ 0x100
  614. struct ts_ctl {
  615. int uni;
  616. u8 dst_port_map;
  617. u8 maddr_map;
  618. u8 ts_mcast_type;
  619. };
  620. struct gbe_slave {
  621. void __iomem *port_regs;
  622. void __iomem *emac_regs;
  623. struct gbe_port_regs_ofs port_regs_ofs;
  624. struct gbe_emac_regs_ofs emac_regs_ofs;
  625. int slave_num; /* 0 based logical number */
  626. int port_num; /* actual port number */
  627. atomic_t link_state;
  628. bool open;
  629. struct phy_device *phy;
  630. u32 link_interface;
  631. u32 mac_control;
  632. u8 phy_port_t;
  633. struct device_node *phy_node;
  634. struct ts_ctl ts_ctl;
  635. struct list_head slave_list;
  636. };
  637. struct gbe_priv {
  638. struct device *dev;
  639. struct netcp_device *netcp_device;
  640. struct timer_list timer;
  641. u32 num_slaves;
  642. u32 ale_entries;
  643. u32 ale_ports;
  644. bool enable_ale;
  645. u8 max_num_slaves;
  646. u8 max_num_ports; /* max_num_slaves + 1 */
  647. u8 num_stats_mods;
  648. struct netcp_tx_pipe tx_pipe;
  649. int host_port;
  650. u32 rx_packet_max;
  651. u32 ss_version;
  652. u32 stats_en_mask;
  653. void __iomem *ss_regs;
  654. void __iomem *switch_regs;
  655. void __iomem *host_port_regs;
  656. void __iomem *ale_reg;
  657. void __iomem *cpts_reg;
  658. void __iomem *sgmii_port_regs;
  659. void __iomem *sgmii_port34_regs;
  660. void __iomem *xgbe_serdes_regs;
  661. void __iomem *hw_stats_regs[GBE_MAX_HW_STAT_MODS];
  662. struct gbe_ss_regs_ofs ss_regs_ofs;
  663. struct gbe_switch_regs_ofs switch_regs_ofs;
  664. struct gbe_host_port_regs_ofs host_port_regs_ofs;
  665. struct cpsw_ale *ale;
  666. unsigned int tx_queue_id;
  667. const char *dma_chan_name;
  668. struct list_head gbe_intf_head;
  669. struct list_head secondary_slaves;
  670. struct net_device *dummy_ndev;
  671. u64 *hw_stats;
  672. u32 *hw_stats_prev;
  673. const struct netcp_ethtool_stat *et_stats;
  674. int num_et_stats;
  675. /* Lock for updating the hwstats */
  676. spinlock_t hw_stats_lock;
  677. int cpts_registered;
  678. struct cpts *cpts;
  679. };
  680. struct gbe_intf {
  681. struct net_device *ndev;
  682. struct device *dev;
  683. struct gbe_priv *gbe_dev;
  684. struct netcp_tx_pipe tx_pipe;
  685. struct gbe_slave *slave;
  686. struct list_head gbe_intf_list;
  687. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  688. };
  689. static struct netcp_module gbe_module;
  690. static struct netcp_module xgbe_module;
  691. /* Statistic management */
  692. struct netcp_ethtool_stat {
  693. char desc[ETH_GSTRING_LEN];
  694. int type;
  695. u32 size;
  696. int offset;
  697. };
  698. #define GBE_STATSA_INFO(field) \
  699. { \
  700. "GBE_A:"#field, GBE_STATSA_MODULE, \
  701. FIELD_SIZEOF(struct gbe_hw_stats, field), \
  702. offsetof(struct gbe_hw_stats, field) \
  703. }
  704. #define GBE_STATSB_INFO(field) \
  705. { \
  706. "GBE_B:"#field, GBE_STATSB_MODULE, \
  707. FIELD_SIZEOF(struct gbe_hw_stats, field), \
  708. offsetof(struct gbe_hw_stats, field) \
  709. }
  710. #define GBE_STATSC_INFO(field) \
  711. { \
  712. "GBE_C:"#field, GBE_STATSC_MODULE, \
  713. FIELD_SIZEOF(struct gbe_hw_stats, field), \
  714. offsetof(struct gbe_hw_stats, field) \
  715. }
  716. #define GBE_STATSD_INFO(field) \
  717. { \
  718. "GBE_D:"#field, GBE_STATSD_MODULE, \
  719. FIELD_SIZEOF(struct gbe_hw_stats, field), \
  720. offsetof(struct gbe_hw_stats, field) \
  721. }
  722. static const struct netcp_ethtool_stat gbe13_et_stats[] = {
  723. /* GBE module A */
  724. GBE_STATSA_INFO(rx_good_frames),
  725. GBE_STATSA_INFO(rx_broadcast_frames),
  726. GBE_STATSA_INFO(rx_multicast_frames),
  727. GBE_STATSA_INFO(rx_pause_frames),
  728. GBE_STATSA_INFO(rx_crc_errors),
  729. GBE_STATSA_INFO(rx_align_code_errors),
  730. GBE_STATSA_INFO(rx_oversized_frames),
  731. GBE_STATSA_INFO(rx_jabber_frames),
  732. GBE_STATSA_INFO(rx_undersized_frames),
  733. GBE_STATSA_INFO(rx_fragments),
  734. GBE_STATSA_INFO(rx_bytes),
  735. GBE_STATSA_INFO(tx_good_frames),
  736. GBE_STATSA_INFO(tx_broadcast_frames),
  737. GBE_STATSA_INFO(tx_multicast_frames),
  738. GBE_STATSA_INFO(tx_pause_frames),
  739. GBE_STATSA_INFO(tx_deferred_frames),
  740. GBE_STATSA_INFO(tx_collision_frames),
  741. GBE_STATSA_INFO(tx_single_coll_frames),
  742. GBE_STATSA_INFO(tx_mult_coll_frames),
  743. GBE_STATSA_INFO(tx_excessive_collisions),
  744. GBE_STATSA_INFO(tx_late_collisions),
  745. GBE_STATSA_INFO(tx_underrun),
  746. GBE_STATSA_INFO(tx_carrier_sense_errors),
  747. GBE_STATSA_INFO(tx_bytes),
  748. GBE_STATSA_INFO(tx_64byte_frames),
  749. GBE_STATSA_INFO(tx_65_to_127byte_frames),
  750. GBE_STATSA_INFO(tx_128_to_255byte_frames),
  751. GBE_STATSA_INFO(tx_256_to_511byte_frames),
  752. GBE_STATSA_INFO(tx_512_to_1023byte_frames),
  753. GBE_STATSA_INFO(tx_1024byte_frames),
  754. GBE_STATSA_INFO(net_bytes),
  755. GBE_STATSA_INFO(rx_sof_overruns),
  756. GBE_STATSA_INFO(rx_mof_overruns),
  757. GBE_STATSA_INFO(rx_dma_overruns),
  758. /* GBE module B */
  759. GBE_STATSB_INFO(rx_good_frames),
  760. GBE_STATSB_INFO(rx_broadcast_frames),
  761. GBE_STATSB_INFO(rx_multicast_frames),
  762. GBE_STATSB_INFO(rx_pause_frames),
  763. GBE_STATSB_INFO(rx_crc_errors),
  764. GBE_STATSB_INFO(rx_align_code_errors),
  765. GBE_STATSB_INFO(rx_oversized_frames),
  766. GBE_STATSB_INFO(rx_jabber_frames),
  767. GBE_STATSB_INFO(rx_undersized_frames),
  768. GBE_STATSB_INFO(rx_fragments),
  769. GBE_STATSB_INFO(rx_bytes),
  770. GBE_STATSB_INFO(tx_good_frames),
  771. GBE_STATSB_INFO(tx_broadcast_frames),
  772. GBE_STATSB_INFO(tx_multicast_frames),
  773. GBE_STATSB_INFO(tx_pause_frames),
  774. GBE_STATSB_INFO(tx_deferred_frames),
  775. GBE_STATSB_INFO(tx_collision_frames),
  776. GBE_STATSB_INFO(tx_single_coll_frames),
  777. GBE_STATSB_INFO(tx_mult_coll_frames),
  778. GBE_STATSB_INFO(tx_excessive_collisions),
  779. GBE_STATSB_INFO(tx_late_collisions),
  780. GBE_STATSB_INFO(tx_underrun),
  781. GBE_STATSB_INFO(tx_carrier_sense_errors),
  782. GBE_STATSB_INFO(tx_bytes),
  783. GBE_STATSB_INFO(tx_64byte_frames),
  784. GBE_STATSB_INFO(tx_65_to_127byte_frames),
  785. GBE_STATSB_INFO(tx_128_to_255byte_frames),
  786. GBE_STATSB_INFO(tx_256_to_511byte_frames),
  787. GBE_STATSB_INFO(tx_512_to_1023byte_frames),
  788. GBE_STATSB_INFO(tx_1024byte_frames),
  789. GBE_STATSB_INFO(net_bytes),
  790. GBE_STATSB_INFO(rx_sof_overruns),
  791. GBE_STATSB_INFO(rx_mof_overruns),
  792. GBE_STATSB_INFO(rx_dma_overruns),
  793. /* GBE module C */
  794. GBE_STATSC_INFO(rx_good_frames),
  795. GBE_STATSC_INFO(rx_broadcast_frames),
  796. GBE_STATSC_INFO(rx_multicast_frames),
  797. GBE_STATSC_INFO(rx_pause_frames),
  798. GBE_STATSC_INFO(rx_crc_errors),
  799. GBE_STATSC_INFO(rx_align_code_errors),
  800. GBE_STATSC_INFO(rx_oversized_frames),
  801. GBE_STATSC_INFO(rx_jabber_frames),
  802. GBE_STATSC_INFO(rx_undersized_frames),
  803. GBE_STATSC_INFO(rx_fragments),
  804. GBE_STATSC_INFO(rx_bytes),
  805. GBE_STATSC_INFO(tx_good_frames),
  806. GBE_STATSC_INFO(tx_broadcast_frames),
  807. GBE_STATSC_INFO(tx_multicast_frames),
  808. GBE_STATSC_INFO(tx_pause_frames),
  809. GBE_STATSC_INFO(tx_deferred_frames),
  810. GBE_STATSC_INFO(tx_collision_frames),
  811. GBE_STATSC_INFO(tx_single_coll_frames),
  812. GBE_STATSC_INFO(tx_mult_coll_frames),
  813. GBE_STATSC_INFO(tx_excessive_collisions),
  814. GBE_STATSC_INFO(tx_late_collisions),
  815. GBE_STATSC_INFO(tx_underrun),
  816. GBE_STATSC_INFO(tx_carrier_sense_errors),
  817. GBE_STATSC_INFO(tx_bytes),
  818. GBE_STATSC_INFO(tx_64byte_frames),
  819. GBE_STATSC_INFO(tx_65_to_127byte_frames),
  820. GBE_STATSC_INFO(tx_128_to_255byte_frames),
  821. GBE_STATSC_INFO(tx_256_to_511byte_frames),
  822. GBE_STATSC_INFO(tx_512_to_1023byte_frames),
  823. GBE_STATSC_INFO(tx_1024byte_frames),
  824. GBE_STATSC_INFO(net_bytes),
  825. GBE_STATSC_INFO(rx_sof_overruns),
  826. GBE_STATSC_INFO(rx_mof_overruns),
  827. GBE_STATSC_INFO(rx_dma_overruns),
  828. /* GBE module D */
  829. GBE_STATSD_INFO(rx_good_frames),
  830. GBE_STATSD_INFO(rx_broadcast_frames),
  831. GBE_STATSD_INFO(rx_multicast_frames),
  832. GBE_STATSD_INFO(rx_pause_frames),
  833. GBE_STATSD_INFO(rx_crc_errors),
  834. GBE_STATSD_INFO(rx_align_code_errors),
  835. GBE_STATSD_INFO(rx_oversized_frames),
  836. GBE_STATSD_INFO(rx_jabber_frames),
  837. GBE_STATSD_INFO(rx_undersized_frames),
  838. GBE_STATSD_INFO(rx_fragments),
  839. GBE_STATSD_INFO(rx_bytes),
  840. GBE_STATSD_INFO(tx_good_frames),
  841. GBE_STATSD_INFO(tx_broadcast_frames),
  842. GBE_STATSD_INFO(tx_multicast_frames),
  843. GBE_STATSD_INFO(tx_pause_frames),
  844. GBE_STATSD_INFO(tx_deferred_frames),
  845. GBE_STATSD_INFO(tx_collision_frames),
  846. GBE_STATSD_INFO(tx_single_coll_frames),
  847. GBE_STATSD_INFO(tx_mult_coll_frames),
  848. GBE_STATSD_INFO(tx_excessive_collisions),
  849. GBE_STATSD_INFO(tx_late_collisions),
  850. GBE_STATSD_INFO(tx_underrun),
  851. GBE_STATSD_INFO(tx_carrier_sense_errors),
  852. GBE_STATSD_INFO(tx_bytes),
  853. GBE_STATSD_INFO(tx_64byte_frames),
  854. GBE_STATSD_INFO(tx_65_to_127byte_frames),
  855. GBE_STATSD_INFO(tx_128_to_255byte_frames),
  856. GBE_STATSD_INFO(tx_256_to_511byte_frames),
  857. GBE_STATSD_INFO(tx_512_to_1023byte_frames),
  858. GBE_STATSD_INFO(tx_1024byte_frames),
  859. GBE_STATSD_INFO(net_bytes),
  860. GBE_STATSD_INFO(rx_sof_overruns),
  861. GBE_STATSD_INFO(rx_mof_overruns),
  862. GBE_STATSD_INFO(rx_dma_overruns),
  863. };
  864. /* This is the size of entries in GBENU_STATS_HOST */
  865. #define GBENU_ET_STATS_HOST_SIZE 52
  866. #define GBENU_STATS_HOST(field) \
  867. { \
  868. "GBE_HOST:"#field, GBENU_STATS0_MODULE, \
  869. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  870. offsetof(struct gbenu_hw_stats, field) \
  871. }
  872. /* This is the size of entries in GBENU_STATS_PORT */
  873. #define GBENU_ET_STATS_PORT_SIZE 65
  874. #define GBENU_STATS_P1(field) \
  875. { \
  876. "GBE_P1:"#field, GBENU_STATS1_MODULE, \
  877. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  878. offsetof(struct gbenu_hw_stats, field) \
  879. }
  880. #define GBENU_STATS_P2(field) \
  881. { \
  882. "GBE_P2:"#field, GBENU_STATS2_MODULE, \
  883. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  884. offsetof(struct gbenu_hw_stats, field) \
  885. }
  886. #define GBENU_STATS_P3(field) \
  887. { \
  888. "GBE_P3:"#field, GBENU_STATS3_MODULE, \
  889. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  890. offsetof(struct gbenu_hw_stats, field) \
  891. }
  892. #define GBENU_STATS_P4(field) \
  893. { \
  894. "GBE_P4:"#field, GBENU_STATS4_MODULE, \
  895. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  896. offsetof(struct gbenu_hw_stats, field) \
  897. }
  898. #define GBENU_STATS_P5(field) \
  899. { \
  900. "GBE_P5:"#field, GBENU_STATS5_MODULE, \
  901. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  902. offsetof(struct gbenu_hw_stats, field) \
  903. }
  904. #define GBENU_STATS_P6(field) \
  905. { \
  906. "GBE_P6:"#field, GBENU_STATS6_MODULE, \
  907. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  908. offsetof(struct gbenu_hw_stats, field) \
  909. }
  910. #define GBENU_STATS_P7(field) \
  911. { \
  912. "GBE_P7:"#field, GBENU_STATS7_MODULE, \
  913. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  914. offsetof(struct gbenu_hw_stats, field) \
  915. }
  916. #define GBENU_STATS_P8(field) \
  917. { \
  918. "GBE_P8:"#field, GBENU_STATS8_MODULE, \
  919. FIELD_SIZEOF(struct gbenu_hw_stats, field), \
  920. offsetof(struct gbenu_hw_stats, field) \
  921. }
  922. static const struct netcp_ethtool_stat gbenu_et_stats[] = {
  923. /* GBENU Host Module */
  924. GBENU_STATS_HOST(rx_good_frames),
  925. GBENU_STATS_HOST(rx_broadcast_frames),
  926. GBENU_STATS_HOST(rx_multicast_frames),
  927. GBENU_STATS_HOST(rx_crc_errors),
  928. GBENU_STATS_HOST(rx_oversized_frames),
  929. GBENU_STATS_HOST(rx_undersized_frames),
  930. GBENU_STATS_HOST(ale_drop),
  931. GBENU_STATS_HOST(ale_overrun_drop),
  932. GBENU_STATS_HOST(rx_bytes),
  933. GBENU_STATS_HOST(tx_good_frames),
  934. GBENU_STATS_HOST(tx_broadcast_frames),
  935. GBENU_STATS_HOST(tx_multicast_frames),
  936. GBENU_STATS_HOST(tx_bytes),
  937. GBENU_STATS_HOST(tx_64B_frames),
  938. GBENU_STATS_HOST(tx_65_to_127B_frames),
  939. GBENU_STATS_HOST(tx_128_to_255B_frames),
  940. GBENU_STATS_HOST(tx_256_to_511B_frames),
  941. GBENU_STATS_HOST(tx_512_to_1023B_frames),
  942. GBENU_STATS_HOST(tx_1024B_frames),
  943. GBENU_STATS_HOST(net_bytes),
  944. GBENU_STATS_HOST(rx_bottom_fifo_drop),
  945. GBENU_STATS_HOST(rx_port_mask_drop),
  946. GBENU_STATS_HOST(rx_top_fifo_drop),
  947. GBENU_STATS_HOST(ale_rate_limit_drop),
  948. GBENU_STATS_HOST(ale_vid_ingress_drop),
  949. GBENU_STATS_HOST(ale_da_eq_sa_drop),
  950. GBENU_STATS_HOST(ale_unknown_ucast),
  951. GBENU_STATS_HOST(ale_unknown_ucast_bytes),
  952. GBENU_STATS_HOST(ale_unknown_mcast),
  953. GBENU_STATS_HOST(ale_unknown_mcast_bytes),
  954. GBENU_STATS_HOST(ale_unknown_bcast),
  955. GBENU_STATS_HOST(ale_unknown_bcast_bytes),
  956. GBENU_STATS_HOST(ale_pol_match),
  957. GBENU_STATS_HOST(ale_pol_match_red),
  958. GBENU_STATS_HOST(ale_pol_match_yellow),
  959. GBENU_STATS_HOST(tx_mem_protect_err),
  960. GBENU_STATS_HOST(tx_pri0_drop),
  961. GBENU_STATS_HOST(tx_pri1_drop),
  962. GBENU_STATS_HOST(tx_pri2_drop),
  963. GBENU_STATS_HOST(tx_pri3_drop),
  964. GBENU_STATS_HOST(tx_pri4_drop),
  965. GBENU_STATS_HOST(tx_pri5_drop),
  966. GBENU_STATS_HOST(tx_pri6_drop),
  967. GBENU_STATS_HOST(tx_pri7_drop),
  968. GBENU_STATS_HOST(tx_pri0_drop_bcnt),
  969. GBENU_STATS_HOST(tx_pri1_drop_bcnt),
  970. GBENU_STATS_HOST(tx_pri2_drop_bcnt),
  971. GBENU_STATS_HOST(tx_pri3_drop_bcnt),
  972. GBENU_STATS_HOST(tx_pri4_drop_bcnt),
  973. GBENU_STATS_HOST(tx_pri5_drop_bcnt),
  974. GBENU_STATS_HOST(tx_pri6_drop_bcnt),
  975. GBENU_STATS_HOST(tx_pri7_drop_bcnt),
  976. /* GBENU Module 1 */
  977. GBENU_STATS_P1(rx_good_frames),
  978. GBENU_STATS_P1(rx_broadcast_frames),
  979. GBENU_STATS_P1(rx_multicast_frames),
  980. GBENU_STATS_P1(rx_pause_frames),
  981. GBENU_STATS_P1(rx_crc_errors),
  982. GBENU_STATS_P1(rx_align_code_errors),
  983. GBENU_STATS_P1(rx_oversized_frames),
  984. GBENU_STATS_P1(rx_jabber_frames),
  985. GBENU_STATS_P1(rx_undersized_frames),
  986. GBENU_STATS_P1(rx_fragments),
  987. GBENU_STATS_P1(ale_drop),
  988. GBENU_STATS_P1(ale_overrun_drop),
  989. GBENU_STATS_P1(rx_bytes),
  990. GBENU_STATS_P1(tx_good_frames),
  991. GBENU_STATS_P1(tx_broadcast_frames),
  992. GBENU_STATS_P1(tx_multicast_frames),
  993. GBENU_STATS_P1(tx_pause_frames),
  994. GBENU_STATS_P1(tx_deferred_frames),
  995. GBENU_STATS_P1(tx_collision_frames),
  996. GBENU_STATS_P1(tx_single_coll_frames),
  997. GBENU_STATS_P1(tx_mult_coll_frames),
  998. GBENU_STATS_P1(tx_excessive_collisions),
  999. GBENU_STATS_P1(tx_late_collisions),
  1000. GBENU_STATS_P1(rx_ipg_error),
  1001. GBENU_STATS_P1(tx_carrier_sense_errors),
  1002. GBENU_STATS_P1(tx_bytes),
  1003. GBENU_STATS_P1(tx_64B_frames),
  1004. GBENU_STATS_P1(tx_65_to_127B_frames),
  1005. GBENU_STATS_P1(tx_128_to_255B_frames),
  1006. GBENU_STATS_P1(tx_256_to_511B_frames),
  1007. GBENU_STATS_P1(tx_512_to_1023B_frames),
  1008. GBENU_STATS_P1(tx_1024B_frames),
  1009. GBENU_STATS_P1(net_bytes),
  1010. GBENU_STATS_P1(rx_bottom_fifo_drop),
  1011. GBENU_STATS_P1(rx_port_mask_drop),
  1012. GBENU_STATS_P1(rx_top_fifo_drop),
  1013. GBENU_STATS_P1(ale_rate_limit_drop),
  1014. GBENU_STATS_P1(ale_vid_ingress_drop),
  1015. GBENU_STATS_P1(ale_da_eq_sa_drop),
  1016. GBENU_STATS_P1(ale_unknown_ucast),
  1017. GBENU_STATS_P1(ale_unknown_ucast_bytes),
  1018. GBENU_STATS_P1(ale_unknown_mcast),
  1019. GBENU_STATS_P1(ale_unknown_mcast_bytes),
  1020. GBENU_STATS_P1(ale_unknown_bcast),
  1021. GBENU_STATS_P1(ale_unknown_bcast_bytes),
  1022. GBENU_STATS_P1(ale_pol_match),
  1023. GBENU_STATS_P1(ale_pol_match_red),
  1024. GBENU_STATS_P1(ale_pol_match_yellow),
  1025. GBENU_STATS_P1(tx_mem_protect_err),
  1026. GBENU_STATS_P1(tx_pri0_drop),
  1027. GBENU_STATS_P1(tx_pri1_drop),
  1028. GBENU_STATS_P1(tx_pri2_drop),
  1029. GBENU_STATS_P1(tx_pri3_drop),
  1030. GBENU_STATS_P1(tx_pri4_drop),
  1031. GBENU_STATS_P1(tx_pri5_drop),
  1032. GBENU_STATS_P1(tx_pri6_drop),
  1033. GBENU_STATS_P1(tx_pri7_drop),
  1034. GBENU_STATS_P1(tx_pri0_drop_bcnt),
  1035. GBENU_STATS_P1(tx_pri1_drop_bcnt),
  1036. GBENU_STATS_P1(tx_pri2_drop_bcnt),
  1037. GBENU_STATS_P1(tx_pri3_drop_bcnt),
  1038. GBENU_STATS_P1(tx_pri4_drop_bcnt),
  1039. GBENU_STATS_P1(tx_pri5_drop_bcnt),
  1040. GBENU_STATS_P1(tx_pri6_drop_bcnt),
  1041. GBENU_STATS_P1(tx_pri7_drop_bcnt),
  1042. /* GBENU Module 2 */
  1043. GBENU_STATS_P2(rx_good_frames),
  1044. GBENU_STATS_P2(rx_broadcast_frames),
  1045. GBENU_STATS_P2(rx_multicast_frames),
  1046. GBENU_STATS_P2(rx_pause_frames),
  1047. GBENU_STATS_P2(rx_crc_errors),
  1048. GBENU_STATS_P2(rx_align_code_errors),
  1049. GBENU_STATS_P2(rx_oversized_frames),
  1050. GBENU_STATS_P2(rx_jabber_frames),
  1051. GBENU_STATS_P2(rx_undersized_frames),
  1052. GBENU_STATS_P2(rx_fragments),
  1053. GBENU_STATS_P2(ale_drop),
  1054. GBENU_STATS_P2(ale_overrun_drop),
  1055. GBENU_STATS_P2(rx_bytes),
  1056. GBENU_STATS_P2(tx_good_frames),
  1057. GBENU_STATS_P2(tx_broadcast_frames),
  1058. GBENU_STATS_P2(tx_multicast_frames),
  1059. GBENU_STATS_P2(tx_pause_frames),
  1060. GBENU_STATS_P2(tx_deferred_frames),
  1061. GBENU_STATS_P2(tx_collision_frames),
  1062. GBENU_STATS_P2(tx_single_coll_frames),
  1063. GBENU_STATS_P2(tx_mult_coll_frames),
  1064. GBENU_STATS_P2(tx_excessive_collisions),
  1065. GBENU_STATS_P2(tx_late_collisions),
  1066. GBENU_STATS_P2(rx_ipg_error),
  1067. GBENU_STATS_P2(tx_carrier_sense_errors),
  1068. GBENU_STATS_P2(tx_bytes),
  1069. GBENU_STATS_P2(tx_64B_frames),
  1070. GBENU_STATS_P2(tx_65_to_127B_frames),
  1071. GBENU_STATS_P2(tx_128_to_255B_frames),
  1072. GBENU_STATS_P2(tx_256_to_511B_frames),
  1073. GBENU_STATS_P2(tx_512_to_1023B_frames),
  1074. GBENU_STATS_P2(tx_1024B_frames),
  1075. GBENU_STATS_P2(net_bytes),
  1076. GBENU_STATS_P2(rx_bottom_fifo_drop),
  1077. GBENU_STATS_P2(rx_port_mask_drop),
  1078. GBENU_STATS_P2(rx_top_fifo_drop),
  1079. GBENU_STATS_P2(ale_rate_limit_drop),
  1080. GBENU_STATS_P2(ale_vid_ingress_drop),
  1081. GBENU_STATS_P2(ale_da_eq_sa_drop),
  1082. GBENU_STATS_P2(ale_unknown_ucast),
  1083. GBENU_STATS_P2(ale_unknown_ucast_bytes),
  1084. GBENU_STATS_P2(ale_unknown_mcast),
  1085. GBENU_STATS_P2(ale_unknown_mcast_bytes),
  1086. GBENU_STATS_P2(ale_unknown_bcast),
  1087. GBENU_STATS_P2(ale_unknown_bcast_bytes),
  1088. GBENU_STATS_P2(ale_pol_match),
  1089. GBENU_STATS_P2(ale_pol_match_red),
  1090. GBENU_STATS_P2(ale_pol_match_yellow),
  1091. GBENU_STATS_P2(tx_mem_protect_err),
  1092. GBENU_STATS_P2(tx_pri0_drop),
  1093. GBENU_STATS_P2(tx_pri1_drop),
  1094. GBENU_STATS_P2(tx_pri2_drop),
  1095. GBENU_STATS_P2(tx_pri3_drop),
  1096. GBENU_STATS_P2(tx_pri4_drop),
  1097. GBENU_STATS_P2(tx_pri5_drop),
  1098. GBENU_STATS_P2(tx_pri6_drop),
  1099. GBENU_STATS_P2(tx_pri7_drop),
  1100. GBENU_STATS_P2(tx_pri0_drop_bcnt),
  1101. GBENU_STATS_P2(tx_pri1_drop_bcnt),
  1102. GBENU_STATS_P2(tx_pri2_drop_bcnt),
  1103. GBENU_STATS_P2(tx_pri3_drop_bcnt),
  1104. GBENU_STATS_P2(tx_pri4_drop_bcnt),
  1105. GBENU_STATS_P2(tx_pri5_drop_bcnt),
  1106. GBENU_STATS_P2(tx_pri6_drop_bcnt),
  1107. GBENU_STATS_P2(tx_pri7_drop_bcnt),
  1108. /* GBENU Module 3 */
  1109. GBENU_STATS_P3(rx_good_frames),
  1110. GBENU_STATS_P3(rx_broadcast_frames),
  1111. GBENU_STATS_P3(rx_multicast_frames),
  1112. GBENU_STATS_P3(rx_pause_frames),
  1113. GBENU_STATS_P3(rx_crc_errors),
  1114. GBENU_STATS_P3(rx_align_code_errors),
  1115. GBENU_STATS_P3(rx_oversized_frames),
  1116. GBENU_STATS_P3(rx_jabber_frames),
  1117. GBENU_STATS_P3(rx_undersized_frames),
  1118. GBENU_STATS_P3(rx_fragments),
  1119. GBENU_STATS_P3(ale_drop),
  1120. GBENU_STATS_P3(ale_overrun_drop),
  1121. GBENU_STATS_P3(rx_bytes),
  1122. GBENU_STATS_P3(tx_good_frames),
  1123. GBENU_STATS_P3(tx_broadcast_frames),
  1124. GBENU_STATS_P3(tx_multicast_frames),
  1125. GBENU_STATS_P3(tx_pause_frames),
  1126. GBENU_STATS_P3(tx_deferred_frames),
  1127. GBENU_STATS_P3(tx_collision_frames),
  1128. GBENU_STATS_P3(tx_single_coll_frames),
  1129. GBENU_STATS_P3(tx_mult_coll_frames),
  1130. GBENU_STATS_P3(tx_excessive_collisions),
  1131. GBENU_STATS_P3(tx_late_collisions),
  1132. GBENU_STATS_P3(rx_ipg_error),
  1133. GBENU_STATS_P3(tx_carrier_sense_errors),
  1134. GBENU_STATS_P3(tx_bytes),
  1135. GBENU_STATS_P3(tx_64B_frames),
  1136. GBENU_STATS_P3(tx_65_to_127B_frames),
  1137. GBENU_STATS_P3(tx_128_to_255B_frames),
  1138. GBENU_STATS_P3(tx_256_to_511B_frames),
  1139. GBENU_STATS_P3(tx_512_to_1023B_frames),
  1140. GBENU_STATS_P3(tx_1024B_frames),
  1141. GBENU_STATS_P3(net_bytes),
  1142. GBENU_STATS_P3(rx_bottom_fifo_drop),
  1143. GBENU_STATS_P3(rx_port_mask_drop),
  1144. GBENU_STATS_P3(rx_top_fifo_drop),
  1145. GBENU_STATS_P3(ale_rate_limit_drop),
  1146. GBENU_STATS_P3(ale_vid_ingress_drop),
  1147. GBENU_STATS_P3(ale_da_eq_sa_drop),
  1148. GBENU_STATS_P3(ale_unknown_ucast),
  1149. GBENU_STATS_P3(ale_unknown_ucast_bytes),
  1150. GBENU_STATS_P3(ale_unknown_mcast),
  1151. GBENU_STATS_P3(ale_unknown_mcast_bytes),
  1152. GBENU_STATS_P3(ale_unknown_bcast),
  1153. GBENU_STATS_P3(ale_unknown_bcast_bytes),
  1154. GBENU_STATS_P3(ale_pol_match),
  1155. GBENU_STATS_P3(ale_pol_match_red),
  1156. GBENU_STATS_P3(ale_pol_match_yellow),
  1157. GBENU_STATS_P3(tx_mem_protect_err),
  1158. GBENU_STATS_P3(tx_pri0_drop),
  1159. GBENU_STATS_P3(tx_pri1_drop),
  1160. GBENU_STATS_P3(tx_pri2_drop),
  1161. GBENU_STATS_P3(tx_pri3_drop),
  1162. GBENU_STATS_P3(tx_pri4_drop),
  1163. GBENU_STATS_P3(tx_pri5_drop),
  1164. GBENU_STATS_P3(tx_pri6_drop),
  1165. GBENU_STATS_P3(tx_pri7_drop),
  1166. GBENU_STATS_P3(tx_pri0_drop_bcnt),
  1167. GBENU_STATS_P3(tx_pri1_drop_bcnt),
  1168. GBENU_STATS_P3(tx_pri2_drop_bcnt),
  1169. GBENU_STATS_P3(tx_pri3_drop_bcnt),
  1170. GBENU_STATS_P3(tx_pri4_drop_bcnt),
  1171. GBENU_STATS_P3(tx_pri5_drop_bcnt),
  1172. GBENU_STATS_P3(tx_pri6_drop_bcnt),
  1173. GBENU_STATS_P3(tx_pri7_drop_bcnt),
  1174. /* GBENU Module 4 */
  1175. GBENU_STATS_P4(rx_good_frames),
  1176. GBENU_STATS_P4(rx_broadcast_frames),
  1177. GBENU_STATS_P4(rx_multicast_frames),
  1178. GBENU_STATS_P4(rx_pause_frames),
  1179. GBENU_STATS_P4(rx_crc_errors),
  1180. GBENU_STATS_P4(rx_align_code_errors),
  1181. GBENU_STATS_P4(rx_oversized_frames),
  1182. GBENU_STATS_P4(rx_jabber_frames),
  1183. GBENU_STATS_P4(rx_undersized_frames),
  1184. GBENU_STATS_P4(rx_fragments),
  1185. GBENU_STATS_P4(ale_drop),
  1186. GBENU_STATS_P4(ale_overrun_drop),
  1187. GBENU_STATS_P4(rx_bytes),
  1188. GBENU_STATS_P4(tx_good_frames),
  1189. GBENU_STATS_P4(tx_broadcast_frames),
  1190. GBENU_STATS_P4(tx_multicast_frames),
  1191. GBENU_STATS_P4(tx_pause_frames),
  1192. GBENU_STATS_P4(tx_deferred_frames),
  1193. GBENU_STATS_P4(tx_collision_frames),
  1194. GBENU_STATS_P4(tx_single_coll_frames),
  1195. GBENU_STATS_P4(tx_mult_coll_frames),
  1196. GBENU_STATS_P4(tx_excessive_collisions),
  1197. GBENU_STATS_P4(tx_late_collisions),
  1198. GBENU_STATS_P4(rx_ipg_error),
  1199. GBENU_STATS_P4(tx_carrier_sense_errors),
  1200. GBENU_STATS_P4(tx_bytes),
  1201. GBENU_STATS_P4(tx_64B_frames),
  1202. GBENU_STATS_P4(tx_65_to_127B_frames),
  1203. GBENU_STATS_P4(tx_128_to_255B_frames),
  1204. GBENU_STATS_P4(tx_256_to_511B_frames),
  1205. GBENU_STATS_P4(tx_512_to_1023B_frames),
  1206. GBENU_STATS_P4(tx_1024B_frames),
  1207. GBENU_STATS_P4(net_bytes),
  1208. GBENU_STATS_P4(rx_bottom_fifo_drop),
  1209. GBENU_STATS_P4(rx_port_mask_drop),
  1210. GBENU_STATS_P4(rx_top_fifo_drop),
  1211. GBENU_STATS_P4(ale_rate_limit_drop),
  1212. GBENU_STATS_P4(ale_vid_ingress_drop),
  1213. GBENU_STATS_P4(ale_da_eq_sa_drop),
  1214. GBENU_STATS_P4(ale_unknown_ucast),
  1215. GBENU_STATS_P4(ale_unknown_ucast_bytes),
  1216. GBENU_STATS_P4(ale_unknown_mcast),
  1217. GBENU_STATS_P4(ale_unknown_mcast_bytes),
  1218. GBENU_STATS_P4(ale_unknown_bcast),
  1219. GBENU_STATS_P4(ale_unknown_bcast_bytes),
  1220. GBENU_STATS_P4(ale_pol_match),
  1221. GBENU_STATS_P4(ale_pol_match_red),
  1222. GBENU_STATS_P4(ale_pol_match_yellow),
  1223. GBENU_STATS_P4(tx_mem_protect_err),
  1224. GBENU_STATS_P4(tx_pri0_drop),
  1225. GBENU_STATS_P4(tx_pri1_drop),
  1226. GBENU_STATS_P4(tx_pri2_drop),
  1227. GBENU_STATS_P4(tx_pri3_drop),
  1228. GBENU_STATS_P4(tx_pri4_drop),
  1229. GBENU_STATS_P4(tx_pri5_drop),
  1230. GBENU_STATS_P4(tx_pri6_drop),
  1231. GBENU_STATS_P4(tx_pri7_drop),
  1232. GBENU_STATS_P4(tx_pri0_drop_bcnt),
  1233. GBENU_STATS_P4(tx_pri1_drop_bcnt),
  1234. GBENU_STATS_P4(tx_pri2_drop_bcnt),
  1235. GBENU_STATS_P4(tx_pri3_drop_bcnt),
  1236. GBENU_STATS_P4(tx_pri4_drop_bcnt),
  1237. GBENU_STATS_P4(tx_pri5_drop_bcnt),
  1238. GBENU_STATS_P4(tx_pri6_drop_bcnt),
  1239. GBENU_STATS_P4(tx_pri7_drop_bcnt),
  1240. /* GBENU Module 5 */
  1241. GBENU_STATS_P5(rx_good_frames),
  1242. GBENU_STATS_P5(rx_broadcast_frames),
  1243. GBENU_STATS_P5(rx_multicast_frames),
  1244. GBENU_STATS_P5(rx_pause_frames),
  1245. GBENU_STATS_P5(rx_crc_errors),
  1246. GBENU_STATS_P5(rx_align_code_errors),
  1247. GBENU_STATS_P5(rx_oversized_frames),
  1248. GBENU_STATS_P5(rx_jabber_frames),
  1249. GBENU_STATS_P5(rx_undersized_frames),
  1250. GBENU_STATS_P5(rx_fragments),
  1251. GBENU_STATS_P5(ale_drop),
  1252. GBENU_STATS_P5(ale_overrun_drop),
  1253. GBENU_STATS_P5(rx_bytes),
  1254. GBENU_STATS_P5(tx_good_frames),
  1255. GBENU_STATS_P5(tx_broadcast_frames),
  1256. GBENU_STATS_P5(tx_multicast_frames),
  1257. GBENU_STATS_P5(tx_pause_frames),
  1258. GBENU_STATS_P5(tx_deferred_frames),
  1259. GBENU_STATS_P5(tx_collision_frames),
  1260. GBENU_STATS_P5(tx_single_coll_frames),
  1261. GBENU_STATS_P5(tx_mult_coll_frames),
  1262. GBENU_STATS_P5(tx_excessive_collisions),
  1263. GBENU_STATS_P5(tx_late_collisions),
  1264. GBENU_STATS_P5(rx_ipg_error),
  1265. GBENU_STATS_P5(tx_carrier_sense_errors),
  1266. GBENU_STATS_P5(tx_bytes),
  1267. GBENU_STATS_P5(tx_64B_frames),
  1268. GBENU_STATS_P5(tx_65_to_127B_frames),
  1269. GBENU_STATS_P5(tx_128_to_255B_frames),
  1270. GBENU_STATS_P5(tx_256_to_511B_frames),
  1271. GBENU_STATS_P5(tx_512_to_1023B_frames),
  1272. GBENU_STATS_P5(tx_1024B_frames),
  1273. GBENU_STATS_P5(net_bytes),
  1274. GBENU_STATS_P5(rx_bottom_fifo_drop),
  1275. GBENU_STATS_P5(rx_port_mask_drop),
  1276. GBENU_STATS_P5(rx_top_fifo_drop),
  1277. GBENU_STATS_P5(ale_rate_limit_drop),
  1278. GBENU_STATS_P5(ale_vid_ingress_drop),
  1279. GBENU_STATS_P5(ale_da_eq_sa_drop),
  1280. GBENU_STATS_P5(ale_unknown_ucast),
  1281. GBENU_STATS_P5(ale_unknown_ucast_bytes),
  1282. GBENU_STATS_P5(ale_unknown_mcast),
  1283. GBENU_STATS_P5(ale_unknown_mcast_bytes),
  1284. GBENU_STATS_P5(ale_unknown_bcast),
  1285. GBENU_STATS_P5(ale_unknown_bcast_bytes),
  1286. GBENU_STATS_P5(ale_pol_match),
  1287. GBENU_STATS_P5(ale_pol_match_red),
  1288. GBENU_STATS_P5(ale_pol_match_yellow),
  1289. GBENU_STATS_P5(tx_mem_protect_err),
  1290. GBENU_STATS_P5(tx_pri0_drop),
  1291. GBENU_STATS_P5(tx_pri1_drop),
  1292. GBENU_STATS_P5(tx_pri2_drop),
  1293. GBENU_STATS_P5(tx_pri3_drop),
  1294. GBENU_STATS_P5(tx_pri4_drop),
  1295. GBENU_STATS_P5(tx_pri5_drop),
  1296. GBENU_STATS_P5(tx_pri6_drop),
  1297. GBENU_STATS_P5(tx_pri7_drop),
  1298. GBENU_STATS_P5(tx_pri0_drop_bcnt),
  1299. GBENU_STATS_P5(tx_pri1_drop_bcnt),
  1300. GBENU_STATS_P5(tx_pri2_drop_bcnt),
  1301. GBENU_STATS_P5(tx_pri3_drop_bcnt),
  1302. GBENU_STATS_P5(tx_pri4_drop_bcnt),
  1303. GBENU_STATS_P5(tx_pri5_drop_bcnt),
  1304. GBENU_STATS_P5(tx_pri6_drop_bcnt),
  1305. GBENU_STATS_P5(tx_pri7_drop_bcnt),
  1306. /* GBENU Module 6 */
  1307. GBENU_STATS_P6(rx_good_frames),
  1308. GBENU_STATS_P6(rx_broadcast_frames),
  1309. GBENU_STATS_P6(rx_multicast_frames),
  1310. GBENU_STATS_P6(rx_pause_frames),
  1311. GBENU_STATS_P6(rx_crc_errors),
  1312. GBENU_STATS_P6(rx_align_code_errors),
  1313. GBENU_STATS_P6(rx_oversized_frames),
  1314. GBENU_STATS_P6(rx_jabber_frames),
  1315. GBENU_STATS_P6(rx_undersized_frames),
  1316. GBENU_STATS_P6(rx_fragments),
  1317. GBENU_STATS_P6(ale_drop),
  1318. GBENU_STATS_P6(ale_overrun_drop),
  1319. GBENU_STATS_P6(rx_bytes),
  1320. GBENU_STATS_P6(tx_good_frames),
  1321. GBENU_STATS_P6(tx_broadcast_frames),
  1322. GBENU_STATS_P6(tx_multicast_frames),
  1323. GBENU_STATS_P6(tx_pause_frames),
  1324. GBENU_STATS_P6(tx_deferred_frames),
  1325. GBENU_STATS_P6(tx_collision_frames),
  1326. GBENU_STATS_P6(tx_single_coll_frames),
  1327. GBENU_STATS_P6(tx_mult_coll_frames),
  1328. GBENU_STATS_P6(tx_excessive_collisions),
  1329. GBENU_STATS_P6(tx_late_collisions),
  1330. GBENU_STATS_P6(rx_ipg_error),
  1331. GBENU_STATS_P6(tx_carrier_sense_errors),
  1332. GBENU_STATS_P6(tx_bytes),
  1333. GBENU_STATS_P6(tx_64B_frames),
  1334. GBENU_STATS_P6(tx_65_to_127B_frames),
  1335. GBENU_STATS_P6(tx_128_to_255B_frames),
  1336. GBENU_STATS_P6(tx_256_to_511B_frames),
  1337. GBENU_STATS_P6(tx_512_to_1023B_frames),
  1338. GBENU_STATS_P6(tx_1024B_frames),
  1339. GBENU_STATS_P6(net_bytes),
  1340. GBENU_STATS_P6(rx_bottom_fifo_drop),
  1341. GBENU_STATS_P6(rx_port_mask_drop),
  1342. GBENU_STATS_P6(rx_top_fifo_drop),
  1343. GBENU_STATS_P6(ale_rate_limit_drop),
  1344. GBENU_STATS_P6(ale_vid_ingress_drop),
  1345. GBENU_STATS_P6(ale_da_eq_sa_drop),
  1346. GBENU_STATS_P6(ale_unknown_ucast),
  1347. GBENU_STATS_P6(ale_unknown_ucast_bytes),
  1348. GBENU_STATS_P6(ale_unknown_mcast),
  1349. GBENU_STATS_P6(ale_unknown_mcast_bytes),
  1350. GBENU_STATS_P6(ale_unknown_bcast),
  1351. GBENU_STATS_P6(ale_unknown_bcast_bytes),
  1352. GBENU_STATS_P6(ale_pol_match),
  1353. GBENU_STATS_P6(ale_pol_match_red),
  1354. GBENU_STATS_P6(ale_pol_match_yellow),
  1355. GBENU_STATS_P6(tx_mem_protect_err),
  1356. GBENU_STATS_P6(tx_pri0_drop),
  1357. GBENU_STATS_P6(tx_pri1_drop),
  1358. GBENU_STATS_P6(tx_pri2_drop),
  1359. GBENU_STATS_P6(tx_pri3_drop),
  1360. GBENU_STATS_P6(tx_pri4_drop),
  1361. GBENU_STATS_P6(tx_pri5_drop),
  1362. GBENU_STATS_P6(tx_pri6_drop),
  1363. GBENU_STATS_P6(tx_pri7_drop),
  1364. GBENU_STATS_P6(tx_pri0_drop_bcnt),
  1365. GBENU_STATS_P6(tx_pri1_drop_bcnt),
  1366. GBENU_STATS_P6(tx_pri2_drop_bcnt),
  1367. GBENU_STATS_P6(tx_pri3_drop_bcnt),
  1368. GBENU_STATS_P6(tx_pri4_drop_bcnt),
  1369. GBENU_STATS_P6(tx_pri5_drop_bcnt),
  1370. GBENU_STATS_P6(tx_pri6_drop_bcnt),
  1371. GBENU_STATS_P6(tx_pri7_drop_bcnt),
  1372. /* GBENU Module 7 */
  1373. GBENU_STATS_P7(rx_good_frames),
  1374. GBENU_STATS_P7(rx_broadcast_frames),
  1375. GBENU_STATS_P7(rx_multicast_frames),
  1376. GBENU_STATS_P7(rx_pause_frames),
  1377. GBENU_STATS_P7(rx_crc_errors),
  1378. GBENU_STATS_P7(rx_align_code_errors),
  1379. GBENU_STATS_P7(rx_oversized_frames),
  1380. GBENU_STATS_P7(rx_jabber_frames),
  1381. GBENU_STATS_P7(rx_undersized_frames),
  1382. GBENU_STATS_P7(rx_fragments),
  1383. GBENU_STATS_P7(ale_drop),
  1384. GBENU_STATS_P7(ale_overrun_drop),
  1385. GBENU_STATS_P7(rx_bytes),
  1386. GBENU_STATS_P7(tx_good_frames),
  1387. GBENU_STATS_P7(tx_broadcast_frames),
  1388. GBENU_STATS_P7(tx_multicast_frames),
  1389. GBENU_STATS_P7(tx_pause_frames),
  1390. GBENU_STATS_P7(tx_deferred_frames),
  1391. GBENU_STATS_P7(tx_collision_frames),
  1392. GBENU_STATS_P7(tx_single_coll_frames),
  1393. GBENU_STATS_P7(tx_mult_coll_frames),
  1394. GBENU_STATS_P7(tx_excessive_collisions),
  1395. GBENU_STATS_P7(tx_late_collisions),
  1396. GBENU_STATS_P7(rx_ipg_error),
  1397. GBENU_STATS_P7(tx_carrier_sense_errors),
  1398. GBENU_STATS_P7(tx_bytes),
  1399. GBENU_STATS_P7(tx_64B_frames),
  1400. GBENU_STATS_P7(tx_65_to_127B_frames),
  1401. GBENU_STATS_P7(tx_128_to_255B_frames),
  1402. GBENU_STATS_P7(tx_256_to_511B_frames),
  1403. GBENU_STATS_P7(tx_512_to_1023B_frames),
  1404. GBENU_STATS_P7(tx_1024B_frames),
  1405. GBENU_STATS_P7(net_bytes),
  1406. GBENU_STATS_P7(rx_bottom_fifo_drop),
  1407. GBENU_STATS_P7(rx_port_mask_drop),
  1408. GBENU_STATS_P7(rx_top_fifo_drop),
  1409. GBENU_STATS_P7(ale_rate_limit_drop),
  1410. GBENU_STATS_P7(ale_vid_ingress_drop),
  1411. GBENU_STATS_P7(ale_da_eq_sa_drop),
  1412. GBENU_STATS_P7(ale_unknown_ucast),
  1413. GBENU_STATS_P7(ale_unknown_ucast_bytes),
  1414. GBENU_STATS_P7(ale_unknown_mcast),
  1415. GBENU_STATS_P7(ale_unknown_mcast_bytes),
  1416. GBENU_STATS_P7(ale_unknown_bcast),
  1417. GBENU_STATS_P7(ale_unknown_bcast_bytes),
  1418. GBENU_STATS_P7(ale_pol_match),
  1419. GBENU_STATS_P7(ale_pol_match_red),
  1420. GBENU_STATS_P7(ale_pol_match_yellow),
  1421. GBENU_STATS_P7(tx_mem_protect_err),
  1422. GBENU_STATS_P7(tx_pri0_drop),
  1423. GBENU_STATS_P7(tx_pri1_drop),
  1424. GBENU_STATS_P7(tx_pri2_drop),
  1425. GBENU_STATS_P7(tx_pri3_drop),
  1426. GBENU_STATS_P7(tx_pri4_drop),
  1427. GBENU_STATS_P7(tx_pri5_drop),
  1428. GBENU_STATS_P7(tx_pri6_drop),
  1429. GBENU_STATS_P7(tx_pri7_drop),
  1430. GBENU_STATS_P7(tx_pri0_drop_bcnt),
  1431. GBENU_STATS_P7(tx_pri1_drop_bcnt),
  1432. GBENU_STATS_P7(tx_pri2_drop_bcnt),
  1433. GBENU_STATS_P7(tx_pri3_drop_bcnt),
  1434. GBENU_STATS_P7(tx_pri4_drop_bcnt),
  1435. GBENU_STATS_P7(tx_pri5_drop_bcnt),
  1436. GBENU_STATS_P7(tx_pri6_drop_bcnt),
  1437. GBENU_STATS_P7(tx_pri7_drop_bcnt),
  1438. /* GBENU Module 8 */
  1439. GBENU_STATS_P8(rx_good_frames),
  1440. GBENU_STATS_P8(rx_broadcast_frames),
  1441. GBENU_STATS_P8(rx_multicast_frames),
  1442. GBENU_STATS_P8(rx_pause_frames),
  1443. GBENU_STATS_P8(rx_crc_errors),
  1444. GBENU_STATS_P8(rx_align_code_errors),
  1445. GBENU_STATS_P8(rx_oversized_frames),
  1446. GBENU_STATS_P8(rx_jabber_frames),
  1447. GBENU_STATS_P8(rx_undersized_frames),
  1448. GBENU_STATS_P8(rx_fragments),
  1449. GBENU_STATS_P8(ale_drop),
  1450. GBENU_STATS_P8(ale_overrun_drop),
  1451. GBENU_STATS_P8(rx_bytes),
  1452. GBENU_STATS_P8(tx_good_frames),
  1453. GBENU_STATS_P8(tx_broadcast_frames),
  1454. GBENU_STATS_P8(tx_multicast_frames),
  1455. GBENU_STATS_P8(tx_pause_frames),
  1456. GBENU_STATS_P8(tx_deferred_frames),
  1457. GBENU_STATS_P8(tx_collision_frames),
  1458. GBENU_STATS_P8(tx_single_coll_frames),
  1459. GBENU_STATS_P8(tx_mult_coll_frames),
  1460. GBENU_STATS_P8(tx_excessive_collisions),
  1461. GBENU_STATS_P8(tx_late_collisions),
  1462. GBENU_STATS_P8(rx_ipg_error),
  1463. GBENU_STATS_P8(tx_carrier_sense_errors),
  1464. GBENU_STATS_P8(tx_bytes),
  1465. GBENU_STATS_P8(tx_64B_frames),
  1466. GBENU_STATS_P8(tx_65_to_127B_frames),
  1467. GBENU_STATS_P8(tx_128_to_255B_frames),
  1468. GBENU_STATS_P8(tx_256_to_511B_frames),
  1469. GBENU_STATS_P8(tx_512_to_1023B_frames),
  1470. GBENU_STATS_P8(tx_1024B_frames),
  1471. GBENU_STATS_P8(net_bytes),
  1472. GBENU_STATS_P8(rx_bottom_fifo_drop),
  1473. GBENU_STATS_P8(rx_port_mask_drop),
  1474. GBENU_STATS_P8(rx_top_fifo_drop),
  1475. GBENU_STATS_P8(ale_rate_limit_drop),
  1476. GBENU_STATS_P8(ale_vid_ingress_drop),
  1477. GBENU_STATS_P8(ale_da_eq_sa_drop),
  1478. GBENU_STATS_P8(ale_unknown_ucast),
  1479. GBENU_STATS_P8(ale_unknown_ucast_bytes),
  1480. GBENU_STATS_P8(ale_unknown_mcast),
  1481. GBENU_STATS_P8(ale_unknown_mcast_bytes),
  1482. GBENU_STATS_P8(ale_unknown_bcast),
  1483. GBENU_STATS_P8(ale_unknown_bcast_bytes),
  1484. GBENU_STATS_P8(ale_pol_match),
  1485. GBENU_STATS_P8(ale_pol_match_red),
  1486. GBENU_STATS_P8(ale_pol_match_yellow),
  1487. GBENU_STATS_P8(tx_mem_protect_err),
  1488. GBENU_STATS_P8(tx_pri0_drop),
  1489. GBENU_STATS_P8(tx_pri1_drop),
  1490. GBENU_STATS_P8(tx_pri2_drop),
  1491. GBENU_STATS_P8(tx_pri3_drop),
  1492. GBENU_STATS_P8(tx_pri4_drop),
  1493. GBENU_STATS_P8(tx_pri5_drop),
  1494. GBENU_STATS_P8(tx_pri6_drop),
  1495. GBENU_STATS_P8(tx_pri7_drop),
  1496. GBENU_STATS_P8(tx_pri0_drop_bcnt),
  1497. GBENU_STATS_P8(tx_pri1_drop_bcnt),
  1498. GBENU_STATS_P8(tx_pri2_drop_bcnt),
  1499. GBENU_STATS_P8(tx_pri3_drop_bcnt),
  1500. GBENU_STATS_P8(tx_pri4_drop_bcnt),
  1501. GBENU_STATS_P8(tx_pri5_drop_bcnt),
  1502. GBENU_STATS_P8(tx_pri6_drop_bcnt),
  1503. GBENU_STATS_P8(tx_pri7_drop_bcnt),
  1504. };
  1505. #define XGBE_STATS0_INFO(field) \
  1506. { \
  1507. "GBE_0:"#field, XGBE_STATS0_MODULE, \
  1508. FIELD_SIZEOF(struct xgbe_hw_stats, field), \
  1509. offsetof(struct xgbe_hw_stats, field) \
  1510. }
  1511. #define XGBE_STATS1_INFO(field) \
  1512. { \
  1513. "GBE_1:"#field, XGBE_STATS1_MODULE, \
  1514. FIELD_SIZEOF(struct xgbe_hw_stats, field), \
  1515. offsetof(struct xgbe_hw_stats, field) \
  1516. }
  1517. #define XGBE_STATS2_INFO(field) \
  1518. { \
  1519. "GBE_2:"#field, XGBE_STATS2_MODULE, \
  1520. FIELD_SIZEOF(struct xgbe_hw_stats, field), \
  1521. offsetof(struct xgbe_hw_stats, field) \
  1522. }
  1523. static const struct netcp_ethtool_stat xgbe10_et_stats[] = {
  1524. /* GBE module 0 */
  1525. XGBE_STATS0_INFO(rx_good_frames),
  1526. XGBE_STATS0_INFO(rx_broadcast_frames),
  1527. XGBE_STATS0_INFO(rx_multicast_frames),
  1528. XGBE_STATS0_INFO(rx_oversized_frames),
  1529. XGBE_STATS0_INFO(rx_undersized_frames),
  1530. XGBE_STATS0_INFO(overrun_type4),
  1531. XGBE_STATS0_INFO(overrun_type5),
  1532. XGBE_STATS0_INFO(rx_bytes),
  1533. XGBE_STATS0_INFO(tx_good_frames),
  1534. XGBE_STATS0_INFO(tx_broadcast_frames),
  1535. XGBE_STATS0_INFO(tx_multicast_frames),
  1536. XGBE_STATS0_INFO(tx_bytes),
  1537. XGBE_STATS0_INFO(tx_64byte_frames),
  1538. XGBE_STATS0_INFO(tx_65_to_127byte_frames),
  1539. XGBE_STATS0_INFO(tx_128_to_255byte_frames),
  1540. XGBE_STATS0_INFO(tx_256_to_511byte_frames),
  1541. XGBE_STATS0_INFO(tx_512_to_1023byte_frames),
  1542. XGBE_STATS0_INFO(tx_1024byte_frames),
  1543. XGBE_STATS0_INFO(net_bytes),
  1544. XGBE_STATS0_INFO(rx_sof_overruns),
  1545. XGBE_STATS0_INFO(rx_mof_overruns),
  1546. XGBE_STATS0_INFO(rx_dma_overruns),
  1547. /* XGBE module 1 */
  1548. XGBE_STATS1_INFO(rx_good_frames),
  1549. XGBE_STATS1_INFO(rx_broadcast_frames),
  1550. XGBE_STATS1_INFO(rx_multicast_frames),
  1551. XGBE_STATS1_INFO(rx_pause_frames),
  1552. XGBE_STATS1_INFO(rx_crc_errors),
  1553. XGBE_STATS1_INFO(rx_align_code_errors),
  1554. XGBE_STATS1_INFO(rx_oversized_frames),
  1555. XGBE_STATS1_INFO(rx_jabber_frames),
  1556. XGBE_STATS1_INFO(rx_undersized_frames),
  1557. XGBE_STATS1_INFO(rx_fragments),
  1558. XGBE_STATS1_INFO(overrun_type4),
  1559. XGBE_STATS1_INFO(overrun_type5),
  1560. XGBE_STATS1_INFO(rx_bytes),
  1561. XGBE_STATS1_INFO(tx_good_frames),
  1562. XGBE_STATS1_INFO(tx_broadcast_frames),
  1563. XGBE_STATS1_INFO(tx_multicast_frames),
  1564. XGBE_STATS1_INFO(tx_pause_frames),
  1565. XGBE_STATS1_INFO(tx_deferred_frames),
  1566. XGBE_STATS1_INFO(tx_collision_frames),
  1567. XGBE_STATS1_INFO(tx_single_coll_frames),
  1568. XGBE_STATS1_INFO(tx_mult_coll_frames),
  1569. XGBE_STATS1_INFO(tx_excessive_collisions),
  1570. XGBE_STATS1_INFO(tx_late_collisions),
  1571. XGBE_STATS1_INFO(tx_underrun),
  1572. XGBE_STATS1_INFO(tx_carrier_sense_errors),
  1573. XGBE_STATS1_INFO(tx_bytes),
  1574. XGBE_STATS1_INFO(tx_64byte_frames),
  1575. XGBE_STATS1_INFO(tx_65_to_127byte_frames),
  1576. XGBE_STATS1_INFO(tx_128_to_255byte_frames),
  1577. XGBE_STATS1_INFO(tx_256_to_511byte_frames),
  1578. XGBE_STATS1_INFO(tx_512_to_1023byte_frames),
  1579. XGBE_STATS1_INFO(tx_1024byte_frames),
  1580. XGBE_STATS1_INFO(net_bytes),
  1581. XGBE_STATS1_INFO(rx_sof_overruns),
  1582. XGBE_STATS1_INFO(rx_mof_overruns),
  1583. XGBE_STATS1_INFO(rx_dma_overruns),
  1584. /* XGBE module 2 */
  1585. XGBE_STATS2_INFO(rx_good_frames),
  1586. XGBE_STATS2_INFO(rx_broadcast_frames),
  1587. XGBE_STATS2_INFO(rx_multicast_frames),
  1588. XGBE_STATS2_INFO(rx_pause_frames),
  1589. XGBE_STATS2_INFO(rx_crc_errors),
  1590. XGBE_STATS2_INFO(rx_align_code_errors),
  1591. XGBE_STATS2_INFO(rx_oversized_frames),
  1592. XGBE_STATS2_INFO(rx_jabber_frames),
  1593. XGBE_STATS2_INFO(rx_undersized_frames),
  1594. XGBE_STATS2_INFO(rx_fragments),
  1595. XGBE_STATS2_INFO(overrun_type4),
  1596. XGBE_STATS2_INFO(overrun_type5),
  1597. XGBE_STATS2_INFO(rx_bytes),
  1598. XGBE_STATS2_INFO(tx_good_frames),
  1599. XGBE_STATS2_INFO(tx_broadcast_frames),
  1600. XGBE_STATS2_INFO(tx_multicast_frames),
  1601. XGBE_STATS2_INFO(tx_pause_frames),
  1602. XGBE_STATS2_INFO(tx_deferred_frames),
  1603. XGBE_STATS2_INFO(tx_collision_frames),
  1604. XGBE_STATS2_INFO(tx_single_coll_frames),
  1605. XGBE_STATS2_INFO(tx_mult_coll_frames),
  1606. XGBE_STATS2_INFO(tx_excessive_collisions),
  1607. XGBE_STATS2_INFO(tx_late_collisions),
  1608. XGBE_STATS2_INFO(tx_underrun),
  1609. XGBE_STATS2_INFO(tx_carrier_sense_errors),
  1610. XGBE_STATS2_INFO(tx_bytes),
  1611. XGBE_STATS2_INFO(tx_64byte_frames),
  1612. XGBE_STATS2_INFO(tx_65_to_127byte_frames),
  1613. XGBE_STATS2_INFO(tx_128_to_255byte_frames),
  1614. XGBE_STATS2_INFO(tx_256_to_511byte_frames),
  1615. XGBE_STATS2_INFO(tx_512_to_1023byte_frames),
  1616. XGBE_STATS2_INFO(tx_1024byte_frames),
  1617. XGBE_STATS2_INFO(net_bytes),
  1618. XGBE_STATS2_INFO(rx_sof_overruns),
  1619. XGBE_STATS2_INFO(rx_mof_overruns),
  1620. XGBE_STATS2_INFO(rx_dma_overruns),
  1621. };
  1622. #define for_each_intf(i, priv) \
  1623. list_for_each_entry((i), &(priv)->gbe_intf_head, gbe_intf_list)
  1624. #define for_each_sec_slave(slave, priv) \
  1625. list_for_each_entry((slave), &(priv)->secondary_slaves, slave_list)
  1626. #define first_sec_slave(priv) \
  1627. list_first_entry(&priv->secondary_slaves, \
  1628. struct gbe_slave, slave_list)
  1629. static void keystone_get_drvinfo(struct net_device *ndev,
  1630. struct ethtool_drvinfo *info)
  1631. {
  1632. strncpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver));
  1633. strncpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version));
  1634. }
  1635. static u32 keystone_get_msglevel(struct net_device *ndev)
  1636. {
  1637. struct netcp_intf *netcp = netdev_priv(ndev);
  1638. return netcp->msg_enable;
  1639. }
  1640. static void keystone_set_msglevel(struct net_device *ndev, u32 value)
  1641. {
  1642. struct netcp_intf *netcp = netdev_priv(ndev);
  1643. netcp->msg_enable = value;
  1644. }
  1645. static struct gbe_intf *keystone_get_intf_data(struct netcp_intf *netcp)
  1646. {
  1647. struct gbe_intf *gbe_intf;
  1648. gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
  1649. if (!gbe_intf)
  1650. gbe_intf = netcp_module_get_intf_data(&xgbe_module, netcp);
  1651. return gbe_intf;
  1652. }
  1653. static void keystone_get_stat_strings(struct net_device *ndev,
  1654. uint32_t stringset, uint8_t *data)
  1655. {
  1656. struct netcp_intf *netcp = netdev_priv(ndev);
  1657. struct gbe_intf *gbe_intf;
  1658. struct gbe_priv *gbe_dev;
  1659. int i;
  1660. gbe_intf = keystone_get_intf_data(netcp);
  1661. if (!gbe_intf)
  1662. return;
  1663. gbe_dev = gbe_intf->gbe_dev;
  1664. switch (stringset) {
  1665. case ETH_SS_STATS:
  1666. for (i = 0; i < gbe_dev->num_et_stats; i++) {
  1667. memcpy(data, gbe_dev->et_stats[i].desc,
  1668. ETH_GSTRING_LEN);
  1669. data += ETH_GSTRING_LEN;
  1670. }
  1671. break;
  1672. case ETH_SS_TEST:
  1673. break;
  1674. }
  1675. }
  1676. static int keystone_get_sset_count(struct net_device *ndev, int stringset)
  1677. {
  1678. struct netcp_intf *netcp = netdev_priv(ndev);
  1679. struct gbe_intf *gbe_intf;
  1680. struct gbe_priv *gbe_dev;
  1681. gbe_intf = keystone_get_intf_data(netcp);
  1682. if (!gbe_intf)
  1683. return -EINVAL;
  1684. gbe_dev = gbe_intf->gbe_dev;
  1685. switch (stringset) {
  1686. case ETH_SS_TEST:
  1687. return 0;
  1688. case ETH_SS_STATS:
  1689. return gbe_dev->num_et_stats;
  1690. default:
  1691. return -EINVAL;
  1692. }
  1693. }
  1694. static void gbe_reset_mod_stats(struct gbe_priv *gbe_dev, int stats_mod)
  1695. {
  1696. void __iomem *base = gbe_dev->hw_stats_regs[stats_mod];
  1697. u32 __iomem *p_stats_entry;
  1698. int i;
  1699. for (i = 0; i < gbe_dev->num_et_stats; i++) {
  1700. if (gbe_dev->et_stats[i].type == stats_mod) {
  1701. p_stats_entry = base + gbe_dev->et_stats[i].offset;
  1702. gbe_dev->hw_stats[i] = 0;
  1703. gbe_dev->hw_stats_prev[i] = readl(p_stats_entry);
  1704. }
  1705. }
  1706. }
  1707. static inline void gbe_update_hw_stats_entry(struct gbe_priv *gbe_dev,
  1708. int et_stats_entry)
  1709. {
  1710. void __iomem *base = NULL;
  1711. u32 __iomem *p_stats_entry;
  1712. u32 curr, delta;
  1713. /* The hw_stats_regs pointers are already
  1714. * properly set to point to the right base:
  1715. */
  1716. base = gbe_dev->hw_stats_regs[gbe_dev->et_stats[et_stats_entry].type];
  1717. p_stats_entry = base + gbe_dev->et_stats[et_stats_entry].offset;
  1718. curr = readl(p_stats_entry);
  1719. delta = curr - gbe_dev->hw_stats_prev[et_stats_entry];
  1720. gbe_dev->hw_stats_prev[et_stats_entry] = curr;
  1721. gbe_dev->hw_stats[et_stats_entry] += delta;
  1722. }
  1723. static void gbe_update_stats(struct gbe_priv *gbe_dev, uint64_t *data)
  1724. {
  1725. int i;
  1726. for (i = 0; i < gbe_dev->num_et_stats; i++) {
  1727. gbe_update_hw_stats_entry(gbe_dev, i);
  1728. if (data)
  1729. data[i] = gbe_dev->hw_stats[i];
  1730. }
  1731. }
  1732. static inline void gbe_stats_mod_visible_ver14(struct gbe_priv *gbe_dev,
  1733. int stats_mod)
  1734. {
  1735. u32 val;
  1736. val = readl(GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
  1737. switch (stats_mod) {
  1738. case GBE_STATSA_MODULE:
  1739. case GBE_STATSB_MODULE:
  1740. val &= ~GBE_STATS_CD_SEL;
  1741. break;
  1742. case GBE_STATSC_MODULE:
  1743. case GBE_STATSD_MODULE:
  1744. val |= GBE_STATS_CD_SEL;
  1745. break;
  1746. default:
  1747. return;
  1748. }
  1749. /* make the stat module visible */
  1750. writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
  1751. }
  1752. static void gbe_reset_mod_stats_ver14(struct gbe_priv *gbe_dev, int stats_mod)
  1753. {
  1754. gbe_stats_mod_visible_ver14(gbe_dev, stats_mod);
  1755. gbe_reset_mod_stats(gbe_dev, stats_mod);
  1756. }
  1757. static void gbe_update_stats_ver14(struct gbe_priv *gbe_dev, uint64_t *data)
  1758. {
  1759. u32 half_num_et_stats = (gbe_dev->num_et_stats / 2);
  1760. int et_entry, j, pair;
  1761. for (pair = 0; pair < 2; pair++) {
  1762. gbe_stats_mod_visible_ver14(gbe_dev, (pair ?
  1763. GBE_STATSC_MODULE :
  1764. GBE_STATSA_MODULE));
  1765. for (j = 0; j < half_num_et_stats; j++) {
  1766. et_entry = pair * half_num_et_stats + j;
  1767. gbe_update_hw_stats_entry(gbe_dev, et_entry);
  1768. if (data)
  1769. data[et_entry] = gbe_dev->hw_stats[et_entry];
  1770. }
  1771. }
  1772. }
  1773. static void keystone_get_ethtool_stats(struct net_device *ndev,
  1774. struct ethtool_stats *stats,
  1775. uint64_t *data)
  1776. {
  1777. struct netcp_intf *netcp = netdev_priv(ndev);
  1778. struct gbe_intf *gbe_intf;
  1779. struct gbe_priv *gbe_dev;
  1780. gbe_intf = keystone_get_intf_data(netcp);
  1781. if (!gbe_intf)
  1782. return;
  1783. gbe_dev = gbe_intf->gbe_dev;
  1784. spin_lock_bh(&gbe_dev->hw_stats_lock);
  1785. if (gbe_dev->ss_version == GBE_SS_VERSION_14)
  1786. gbe_update_stats_ver14(gbe_dev, data);
  1787. else
  1788. gbe_update_stats(gbe_dev, data);
  1789. spin_unlock_bh(&gbe_dev->hw_stats_lock);
  1790. }
  1791. static int keystone_get_link_ksettings(struct net_device *ndev,
  1792. struct ethtool_link_ksettings *cmd)
  1793. {
  1794. struct netcp_intf *netcp = netdev_priv(ndev);
  1795. struct phy_device *phy = ndev->phydev;
  1796. struct gbe_intf *gbe_intf;
  1797. int ret;
  1798. if (!phy)
  1799. return -EINVAL;
  1800. gbe_intf = keystone_get_intf_data(netcp);
  1801. if (!gbe_intf)
  1802. return -EINVAL;
  1803. if (!gbe_intf->slave)
  1804. return -EINVAL;
  1805. ret = phy_ethtool_ksettings_get(phy, cmd);
  1806. if (!ret)
  1807. cmd->base.port = gbe_intf->slave->phy_port_t;
  1808. return ret;
  1809. }
  1810. static int keystone_set_link_ksettings(struct net_device *ndev,
  1811. const struct ethtool_link_ksettings *cmd)
  1812. {
  1813. struct netcp_intf *netcp = netdev_priv(ndev);
  1814. struct phy_device *phy = ndev->phydev;
  1815. struct gbe_intf *gbe_intf;
  1816. u8 port = cmd->base.port;
  1817. u32 advertising, supported;
  1818. u32 features;
  1819. ethtool_convert_link_mode_to_legacy_u32(&advertising,
  1820. cmd->link_modes.advertising);
  1821. ethtool_convert_link_mode_to_legacy_u32(&supported,
  1822. cmd->link_modes.supported);
  1823. features = advertising & supported;
  1824. if (!phy)
  1825. return -EINVAL;
  1826. gbe_intf = keystone_get_intf_data(netcp);
  1827. if (!gbe_intf)
  1828. return -EINVAL;
  1829. if (!gbe_intf->slave)
  1830. return -EINVAL;
  1831. if (port != gbe_intf->slave->phy_port_t) {
  1832. if ((port == PORT_TP) && !(features & ADVERTISED_TP))
  1833. return -EINVAL;
  1834. if ((port == PORT_AUI) && !(features & ADVERTISED_AUI))
  1835. return -EINVAL;
  1836. if ((port == PORT_BNC) && !(features & ADVERTISED_BNC))
  1837. return -EINVAL;
  1838. if ((port == PORT_MII) && !(features & ADVERTISED_MII))
  1839. return -EINVAL;
  1840. if ((port == PORT_FIBRE) && !(features & ADVERTISED_FIBRE))
  1841. return -EINVAL;
  1842. }
  1843. gbe_intf->slave->phy_port_t = port;
  1844. return phy_ethtool_ksettings_set(phy, cmd);
  1845. }
  1846. #if IS_ENABLED(CONFIG_TI_CPTS)
  1847. static int keystone_get_ts_info(struct net_device *ndev,
  1848. struct ethtool_ts_info *info)
  1849. {
  1850. struct netcp_intf *netcp = netdev_priv(ndev);
  1851. struct gbe_intf *gbe_intf;
  1852. gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
  1853. if (!gbe_intf || !gbe_intf->gbe_dev->cpts)
  1854. return -EINVAL;
  1855. info->so_timestamping =
  1856. SOF_TIMESTAMPING_TX_HARDWARE |
  1857. SOF_TIMESTAMPING_TX_SOFTWARE |
  1858. SOF_TIMESTAMPING_RX_HARDWARE |
  1859. SOF_TIMESTAMPING_RX_SOFTWARE |
  1860. SOF_TIMESTAMPING_SOFTWARE |
  1861. SOF_TIMESTAMPING_RAW_HARDWARE;
  1862. info->phc_index = gbe_intf->gbe_dev->cpts->phc_index;
  1863. info->tx_types =
  1864. (1 << HWTSTAMP_TX_OFF) |
  1865. (1 << HWTSTAMP_TX_ON);
  1866. info->rx_filters =
  1867. (1 << HWTSTAMP_FILTER_NONE) |
  1868. (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  1869. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
  1870. return 0;
  1871. }
  1872. #else
  1873. static int keystone_get_ts_info(struct net_device *ndev,
  1874. struct ethtool_ts_info *info)
  1875. {
  1876. info->so_timestamping =
  1877. SOF_TIMESTAMPING_TX_SOFTWARE |
  1878. SOF_TIMESTAMPING_RX_SOFTWARE |
  1879. SOF_TIMESTAMPING_SOFTWARE;
  1880. info->phc_index = -1;
  1881. info->tx_types = 0;
  1882. info->rx_filters = 0;
  1883. return 0;
  1884. }
  1885. #endif /* CONFIG_TI_CPTS */
  1886. static const struct ethtool_ops keystone_ethtool_ops = {
  1887. .get_drvinfo = keystone_get_drvinfo,
  1888. .get_link = ethtool_op_get_link,
  1889. .get_msglevel = keystone_get_msglevel,
  1890. .set_msglevel = keystone_set_msglevel,
  1891. .get_strings = keystone_get_stat_strings,
  1892. .get_sset_count = keystone_get_sset_count,
  1893. .get_ethtool_stats = keystone_get_ethtool_stats,
  1894. .get_link_ksettings = keystone_get_link_ksettings,
  1895. .set_link_ksettings = keystone_set_link_ksettings,
  1896. .get_ts_info = keystone_get_ts_info,
  1897. };
  1898. #define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \
  1899. ((mac)[2] << 16) | ((mac)[3] << 24))
  1900. #define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8))
  1901. static void gbe_set_slave_mac(struct gbe_slave *slave,
  1902. struct gbe_intf *gbe_intf)
  1903. {
  1904. struct net_device *ndev = gbe_intf->ndev;
  1905. writel(mac_hi(ndev->dev_addr), GBE_REG_ADDR(slave, port_regs, sa_hi));
  1906. writel(mac_lo(ndev->dev_addr), GBE_REG_ADDR(slave, port_regs, sa_lo));
  1907. }
  1908. static int gbe_get_slave_port(struct gbe_priv *priv, u32 slave_num)
  1909. {
  1910. if (priv->host_port == 0)
  1911. return slave_num + 1;
  1912. return slave_num;
  1913. }
  1914. static void netcp_ethss_link_state_action(struct gbe_priv *gbe_dev,
  1915. struct net_device *ndev,
  1916. struct gbe_slave *slave,
  1917. int up)
  1918. {
  1919. struct phy_device *phy = slave->phy;
  1920. u32 mac_control = 0;
  1921. if (up) {
  1922. mac_control = slave->mac_control;
  1923. if (phy && (phy->speed == SPEED_1000)) {
  1924. mac_control |= MACSL_GIG_MODE;
  1925. mac_control &= ~MACSL_XGIG_MODE;
  1926. } else if (phy && (phy->speed == SPEED_10000)) {
  1927. mac_control |= MACSL_XGIG_MODE;
  1928. mac_control &= ~MACSL_GIG_MODE;
  1929. }
  1930. writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
  1931. mac_control));
  1932. cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
  1933. ALE_PORT_STATE,
  1934. ALE_PORT_STATE_FORWARD);
  1935. if (ndev && slave->open &&
  1936. slave->link_interface != SGMII_LINK_MAC_PHY &&
  1937. slave->link_interface != XGMII_LINK_MAC_PHY)
  1938. netif_carrier_on(ndev);
  1939. } else {
  1940. writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
  1941. mac_control));
  1942. cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
  1943. ALE_PORT_STATE,
  1944. ALE_PORT_STATE_DISABLE);
  1945. if (ndev &&
  1946. slave->link_interface != SGMII_LINK_MAC_PHY &&
  1947. slave->link_interface != XGMII_LINK_MAC_PHY)
  1948. netif_carrier_off(ndev);
  1949. }
  1950. if (phy)
  1951. phy_print_status(phy);
  1952. }
  1953. static bool gbe_phy_link_status(struct gbe_slave *slave)
  1954. {
  1955. return !slave->phy || slave->phy->link;
  1956. }
  1957. static void netcp_ethss_update_link_state(struct gbe_priv *gbe_dev,
  1958. struct gbe_slave *slave,
  1959. struct net_device *ndev)
  1960. {
  1961. int sp = slave->slave_num;
  1962. int phy_link_state, sgmii_link_state = 1, link_state;
  1963. if (!slave->open)
  1964. return;
  1965. if (!SLAVE_LINK_IS_XGMII(slave)) {
  1966. sgmii_link_state =
  1967. netcp_sgmii_get_port_link(SGMII_BASE(gbe_dev, sp), sp);
  1968. }
  1969. phy_link_state = gbe_phy_link_status(slave);
  1970. link_state = phy_link_state & sgmii_link_state;
  1971. if (atomic_xchg(&slave->link_state, link_state) != link_state)
  1972. netcp_ethss_link_state_action(gbe_dev, ndev, slave,
  1973. link_state);
  1974. }
  1975. static void xgbe_adjust_link(struct net_device *ndev)
  1976. {
  1977. struct netcp_intf *netcp = netdev_priv(ndev);
  1978. struct gbe_intf *gbe_intf;
  1979. gbe_intf = netcp_module_get_intf_data(&xgbe_module, netcp);
  1980. if (!gbe_intf)
  1981. return;
  1982. netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave,
  1983. ndev);
  1984. }
  1985. static void gbe_adjust_link(struct net_device *ndev)
  1986. {
  1987. struct netcp_intf *netcp = netdev_priv(ndev);
  1988. struct gbe_intf *gbe_intf;
  1989. gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
  1990. if (!gbe_intf)
  1991. return;
  1992. netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave,
  1993. ndev);
  1994. }
  1995. static void gbe_adjust_link_sec_slaves(struct net_device *ndev)
  1996. {
  1997. struct gbe_priv *gbe_dev = netdev_priv(ndev);
  1998. struct gbe_slave *slave;
  1999. for_each_sec_slave(slave, gbe_dev)
  2000. netcp_ethss_update_link_state(gbe_dev, slave, NULL);
  2001. }
  2002. /* Reset EMAC
  2003. * Soft reset is set and polled until clear, or until a timeout occurs
  2004. */
  2005. static int gbe_port_reset(struct gbe_slave *slave)
  2006. {
  2007. u32 i, v;
  2008. /* Set the soft reset bit */
  2009. writel(SOFT_RESET, GBE_REG_ADDR(slave, emac_regs, soft_reset));
  2010. /* Wait for the bit to clear */
  2011. for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++) {
  2012. v = readl(GBE_REG_ADDR(slave, emac_regs, soft_reset));
  2013. if ((v & SOFT_RESET_MASK) != SOFT_RESET)
  2014. return 0;
  2015. }
  2016. /* Timeout on the reset */
  2017. return GMACSL_RET_WARN_RESET_INCOMPLETE;
  2018. }
  2019. /* Configure EMAC */
  2020. static void gbe_port_config(struct gbe_priv *gbe_dev, struct gbe_slave *slave,
  2021. int max_rx_len)
  2022. {
  2023. void __iomem *rx_maxlen_reg;
  2024. u32 xgmii_mode;
  2025. if (max_rx_len > NETCP_MAX_FRAME_SIZE)
  2026. max_rx_len = NETCP_MAX_FRAME_SIZE;
  2027. /* Enable correct MII mode at SS level */
  2028. if ((gbe_dev->ss_version == XGBE_SS_VERSION_10) &&
  2029. (slave->link_interface >= XGMII_LINK_MAC_PHY)) {
  2030. xgmii_mode = readl(GBE_REG_ADDR(gbe_dev, ss_regs, control));
  2031. xgmii_mode |= (1 << slave->slave_num);
  2032. writel(xgmii_mode, GBE_REG_ADDR(gbe_dev, ss_regs, control));
  2033. }
  2034. if (IS_SS_ID_MU(gbe_dev))
  2035. rx_maxlen_reg = GBE_REG_ADDR(slave, port_regs, rx_maxlen);
  2036. else
  2037. rx_maxlen_reg = GBE_REG_ADDR(slave, emac_regs, rx_maxlen);
  2038. writel(max_rx_len, rx_maxlen_reg);
  2039. writel(slave->mac_control, GBE_REG_ADDR(slave, emac_regs, mac_control));
  2040. }
  2041. static void gbe_sgmii_rtreset(struct gbe_priv *priv,
  2042. struct gbe_slave *slave, bool set)
  2043. {
  2044. if (SLAVE_LINK_IS_XGMII(slave))
  2045. return;
  2046. netcp_sgmii_rtreset(SGMII_BASE(priv, slave->slave_num),
  2047. slave->slave_num, set);
  2048. }
  2049. static void gbe_slave_stop(struct gbe_intf *intf)
  2050. {
  2051. struct gbe_priv *gbe_dev = intf->gbe_dev;
  2052. struct gbe_slave *slave = intf->slave;
  2053. gbe_sgmii_rtreset(gbe_dev, slave, true);
  2054. gbe_port_reset(slave);
  2055. /* Disable forwarding */
  2056. cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
  2057. ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
  2058. cpsw_ale_del_mcast(gbe_dev->ale, intf->ndev->broadcast,
  2059. 1 << slave->port_num, 0, 0);
  2060. if (!slave->phy)
  2061. return;
  2062. phy_stop(slave->phy);
  2063. phy_disconnect(slave->phy);
  2064. slave->phy = NULL;
  2065. }
  2066. static void gbe_sgmii_config(struct gbe_priv *priv, struct gbe_slave *slave)
  2067. {
  2068. if (SLAVE_LINK_IS_XGMII(slave))
  2069. return;
  2070. netcp_sgmii_reset(SGMII_BASE(priv, slave->slave_num), slave->slave_num);
  2071. netcp_sgmii_config(SGMII_BASE(priv, slave->slave_num), slave->slave_num,
  2072. slave->link_interface);
  2073. }
  2074. static int gbe_slave_open(struct gbe_intf *gbe_intf)
  2075. {
  2076. struct gbe_priv *priv = gbe_intf->gbe_dev;
  2077. struct gbe_slave *slave = gbe_intf->slave;
  2078. phy_interface_t phy_mode;
  2079. bool has_phy = false;
  2080. void (*hndlr)(struct net_device *) = gbe_adjust_link;
  2081. gbe_sgmii_config(priv, slave);
  2082. gbe_port_reset(slave);
  2083. gbe_sgmii_rtreset(priv, slave, false);
  2084. gbe_port_config(priv, slave, priv->rx_packet_max);
  2085. gbe_set_slave_mac(slave, gbe_intf);
  2086. /* enable forwarding */
  2087. cpsw_ale_control_set(priv->ale, slave->port_num,
  2088. ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
  2089. cpsw_ale_add_mcast(priv->ale, gbe_intf->ndev->broadcast,
  2090. 1 << slave->port_num, 0, 0, ALE_MCAST_FWD_2);
  2091. if (slave->link_interface == SGMII_LINK_MAC_PHY) {
  2092. has_phy = true;
  2093. phy_mode = PHY_INTERFACE_MODE_SGMII;
  2094. slave->phy_port_t = PORT_MII;
  2095. } else if (slave->link_interface == XGMII_LINK_MAC_PHY) {
  2096. has_phy = true;
  2097. phy_mode = PHY_INTERFACE_MODE_NA;
  2098. slave->phy_port_t = PORT_FIBRE;
  2099. }
  2100. if (has_phy) {
  2101. if (priv->ss_version == XGBE_SS_VERSION_10)
  2102. hndlr = xgbe_adjust_link;
  2103. slave->phy = of_phy_connect(gbe_intf->ndev,
  2104. slave->phy_node,
  2105. hndlr, 0,
  2106. phy_mode);
  2107. if (!slave->phy) {
  2108. dev_err(priv->dev, "phy not found on slave %d\n",
  2109. slave->slave_num);
  2110. return -ENODEV;
  2111. }
  2112. dev_dbg(priv->dev, "phy found: id is: 0x%s\n",
  2113. phydev_name(slave->phy));
  2114. phy_start(slave->phy);
  2115. }
  2116. return 0;
  2117. }
  2118. static void gbe_init_host_port(struct gbe_priv *priv)
  2119. {
  2120. int bypass_en = 1;
  2121. /* Host Tx Pri */
  2122. if (IS_SS_ID_NU(priv) || IS_SS_ID_XGBE(priv))
  2123. writel(HOST_TX_PRI_MAP_DEFAULT,
  2124. GBE_REG_ADDR(priv, host_port_regs, tx_pri_map));
  2125. /* Max length register */
  2126. writel(NETCP_MAX_FRAME_SIZE, GBE_REG_ADDR(priv, host_port_regs,
  2127. rx_maxlen));
  2128. cpsw_ale_start(priv->ale);
  2129. if (priv->enable_ale)
  2130. bypass_en = 0;
  2131. cpsw_ale_control_set(priv->ale, 0, ALE_BYPASS, bypass_en);
  2132. cpsw_ale_control_set(priv->ale, 0, ALE_NO_PORT_VLAN, 1);
  2133. cpsw_ale_control_set(priv->ale, priv->host_port,
  2134. ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
  2135. cpsw_ale_control_set(priv->ale, 0,
  2136. ALE_PORT_UNKNOWN_VLAN_MEMBER,
  2137. GBE_PORT_MASK(priv->ale_ports));
  2138. cpsw_ale_control_set(priv->ale, 0,
  2139. ALE_PORT_UNKNOWN_MCAST_FLOOD,
  2140. GBE_PORT_MASK(priv->ale_ports - 1));
  2141. cpsw_ale_control_set(priv->ale, 0,
  2142. ALE_PORT_UNKNOWN_REG_MCAST_FLOOD,
  2143. GBE_PORT_MASK(priv->ale_ports));
  2144. cpsw_ale_control_set(priv->ale, 0,
  2145. ALE_PORT_UNTAGGED_EGRESS,
  2146. GBE_PORT_MASK(priv->ale_ports));
  2147. }
  2148. static void gbe_add_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr)
  2149. {
  2150. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2151. u16 vlan_id;
  2152. cpsw_ale_add_mcast(gbe_dev->ale, addr,
  2153. GBE_PORT_MASK(gbe_dev->ale_ports), 0, 0,
  2154. ALE_MCAST_FWD_2);
  2155. for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
  2156. cpsw_ale_add_mcast(gbe_dev->ale, addr,
  2157. GBE_PORT_MASK(gbe_dev->ale_ports),
  2158. ALE_VLAN, vlan_id, ALE_MCAST_FWD_2);
  2159. }
  2160. }
  2161. static void gbe_add_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr)
  2162. {
  2163. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2164. u16 vlan_id;
  2165. cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0);
  2166. for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID)
  2167. cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port,
  2168. ALE_VLAN, vlan_id);
  2169. }
  2170. static void gbe_del_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr)
  2171. {
  2172. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2173. u16 vlan_id;
  2174. cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, 0, 0);
  2175. for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
  2176. cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, ALE_VLAN, vlan_id);
  2177. }
  2178. }
  2179. static void gbe_del_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr)
  2180. {
  2181. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2182. u16 vlan_id;
  2183. cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0);
  2184. for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
  2185. cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port,
  2186. ALE_VLAN, vlan_id);
  2187. }
  2188. }
  2189. static int gbe_add_addr(void *intf_priv, struct netcp_addr *naddr)
  2190. {
  2191. struct gbe_intf *gbe_intf = intf_priv;
  2192. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2193. dev_dbg(gbe_dev->dev, "ethss adding address %pM, type %d\n",
  2194. naddr->addr, naddr->type);
  2195. switch (naddr->type) {
  2196. case ADDR_MCAST:
  2197. case ADDR_BCAST:
  2198. gbe_add_mcast_addr(gbe_intf, naddr->addr);
  2199. break;
  2200. case ADDR_UCAST:
  2201. case ADDR_DEV:
  2202. gbe_add_ucast_addr(gbe_intf, naddr->addr);
  2203. break;
  2204. case ADDR_ANY:
  2205. /* nothing to do for promiscuous */
  2206. default:
  2207. break;
  2208. }
  2209. return 0;
  2210. }
  2211. static int gbe_del_addr(void *intf_priv, struct netcp_addr *naddr)
  2212. {
  2213. struct gbe_intf *gbe_intf = intf_priv;
  2214. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2215. dev_dbg(gbe_dev->dev, "ethss deleting address %pM, type %d\n",
  2216. naddr->addr, naddr->type);
  2217. switch (naddr->type) {
  2218. case ADDR_MCAST:
  2219. case ADDR_BCAST:
  2220. gbe_del_mcast_addr(gbe_intf, naddr->addr);
  2221. break;
  2222. case ADDR_UCAST:
  2223. case ADDR_DEV:
  2224. gbe_del_ucast_addr(gbe_intf, naddr->addr);
  2225. break;
  2226. case ADDR_ANY:
  2227. /* nothing to do for promiscuous */
  2228. default:
  2229. break;
  2230. }
  2231. return 0;
  2232. }
  2233. static int gbe_add_vid(void *intf_priv, int vid)
  2234. {
  2235. struct gbe_intf *gbe_intf = intf_priv;
  2236. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2237. set_bit(vid, gbe_intf->active_vlans);
  2238. cpsw_ale_add_vlan(gbe_dev->ale, vid,
  2239. GBE_PORT_MASK(gbe_dev->ale_ports),
  2240. GBE_MASK_NO_PORTS,
  2241. GBE_PORT_MASK(gbe_dev->ale_ports),
  2242. GBE_PORT_MASK(gbe_dev->ale_ports - 1));
  2243. return 0;
  2244. }
  2245. static int gbe_del_vid(void *intf_priv, int vid)
  2246. {
  2247. struct gbe_intf *gbe_intf = intf_priv;
  2248. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2249. cpsw_ale_del_vlan(gbe_dev->ale, vid, 0);
  2250. clear_bit(vid, gbe_intf->active_vlans);
  2251. return 0;
  2252. }
  2253. #if IS_ENABLED(CONFIG_TI_CPTS)
  2254. #define HAS_PHY_TXTSTAMP(p) ((p)->drv && (p)->drv->txtstamp)
  2255. #define HAS_PHY_RXTSTAMP(p) ((p)->drv && (p)->drv->rxtstamp)
  2256. static void gbe_txtstamp(void *context, struct sk_buff *skb)
  2257. {
  2258. struct gbe_intf *gbe_intf = context;
  2259. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2260. cpts_tx_timestamp(gbe_dev->cpts, skb);
  2261. }
  2262. static bool gbe_need_txtstamp(struct gbe_intf *gbe_intf,
  2263. const struct netcp_packet *p_info)
  2264. {
  2265. struct sk_buff *skb = p_info->skb;
  2266. unsigned int class = ptp_classify_raw(skb);
  2267. if (class == PTP_CLASS_NONE)
  2268. return false;
  2269. switch (class) {
  2270. case PTP_CLASS_V1_IPV4:
  2271. case PTP_CLASS_V1_IPV6:
  2272. case PTP_CLASS_V2_IPV4:
  2273. case PTP_CLASS_V2_IPV6:
  2274. case PTP_CLASS_V2_L2:
  2275. case (PTP_CLASS_V2_VLAN | PTP_CLASS_L2):
  2276. case (PTP_CLASS_V2_VLAN | PTP_CLASS_IPV4):
  2277. case (PTP_CLASS_V2_VLAN | PTP_CLASS_IPV6):
  2278. return true;
  2279. }
  2280. return false;
  2281. }
  2282. static int gbe_txtstamp_mark_pkt(struct gbe_intf *gbe_intf,
  2283. struct netcp_packet *p_info)
  2284. {
  2285. struct phy_device *phydev = p_info->skb->dev->phydev;
  2286. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2287. if (!(skb_shinfo(p_info->skb)->tx_flags & SKBTX_HW_TSTAMP) ||
  2288. !cpts_is_tx_enabled(gbe_dev->cpts))
  2289. return 0;
  2290. /* If phy has the txtstamp api, assume it will do it.
  2291. * We mark it here because skb_tx_timestamp() is called
  2292. * after all the txhooks are called.
  2293. */
  2294. if (phydev && HAS_PHY_TXTSTAMP(phydev)) {
  2295. skb_shinfo(p_info->skb)->tx_flags |= SKBTX_IN_PROGRESS;
  2296. return 0;
  2297. }
  2298. if (gbe_need_txtstamp(gbe_intf, p_info)) {
  2299. p_info->txtstamp = gbe_txtstamp;
  2300. p_info->ts_context = (void *)gbe_intf;
  2301. skb_shinfo(p_info->skb)->tx_flags |= SKBTX_IN_PROGRESS;
  2302. }
  2303. return 0;
  2304. }
  2305. static int gbe_rxtstamp(struct gbe_intf *gbe_intf, struct netcp_packet *p_info)
  2306. {
  2307. struct phy_device *phydev = p_info->skb->dev->phydev;
  2308. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2309. if (p_info->rxtstamp_complete)
  2310. return 0;
  2311. if (phydev && HAS_PHY_RXTSTAMP(phydev)) {
  2312. p_info->rxtstamp_complete = true;
  2313. return 0;
  2314. }
  2315. cpts_rx_timestamp(gbe_dev->cpts, p_info->skb);
  2316. p_info->rxtstamp_complete = true;
  2317. return 0;
  2318. }
  2319. static int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, struct ifreq *ifr)
  2320. {
  2321. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2322. struct cpts *cpts = gbe_dev->cpts;
  2323. struct hwtstamp_config cfg;
  2324. if (!cpts)
  2325. return -EOPNOTSUPP;
  2326. cfg.flags = 0;
  2327. cfg.tx_type = cpts_is_tx_enabled(cpts) ?
  2328. HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
  2329. cfg.rx_filter = (cpts_is_rx_enabled(cpts) ?
  2330. cpts->rx_enable : HWTSTAMP_FILTER_NONE);
  2331. return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
  2332. }
  2333. static void gbe_hwtstamp(struct gbe_intf *gbe_intf)
  2334. {
  2335. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2336. struct gbe_slave *slave = gbe_intf->slave;
  2337. u32 ts_en, seq_id, ctl;
  2338. if (!cpts_is_rx_enabled(gbe_dev->cpts) &&
  2339. !cpts_is_tx_enabled(gbe_dev->cpts)) {
  2340. writel(0, GBE_REG_ADDR(slave, port_regs, ts_ctl));
  2341. return;
  2342. }
  2343. seq_id = (30 << TS_SEQ_ID_OFS_SHIFT) | ETH_P_1588;
  2344. ts_en = EVENT_MSG_BITS << TS_MSG_TYPE_EN_SHIFT;
  2345. ctl = ETH_P_1588 | TS_TTL_NONZERO |
  2346. (slave->ts_ctl.dst_port_map << TS_CTL_DST_PORT_SHIFT) |
  2347. (slave->ts_ctl.uni ? TS_UNI_EN :
  2348. slave->ts_ctl.maddr_map << TS_CTL_MADDR_SHIFT);
  2349. if (cpts_is_tx_enabled(gbe_dev->cpts))
  2350. ts_en |= (TS_TX_ANX_ALL_EN | TS_TX_VLAN_LT1_EN);
  2351. if (cpts_is_rx_enabled(gbe_dev->cpts))
  2352. ts_en |= (TS_RX_ANX_ALL_EN | TS_RX_VLAN_LT1_EN);
  2353. writel(ts_en, GBE_REG_ADDR(slave, port_regs, ts_ctl));
  2354. writel(seq_id, GBE_REG_ADDR(slave, port_regs, ts_seq_ltype));
  2355. writel(ctl, GBE_REG_ADDR(slave, port_regs, ts_ctl_ltype2));
  2356. }
  2357. static int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *ifr)
  2358. {
  2359. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2360. struct cpts *cpts = gbe_dev->cpts;
  2361. struct hwtstamp_config cfg;
  2362. if (!cpts)
  2363. return -EOPNOTSUPP;
  2364. if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
  2365. return -EFAULT;
  2366. /* reserved for future extensions */
  2367. if (cfg.flags)
  2368. return -EINVAL;
  2369. switch (cfg.tx_type) {
  2370. case HWTSTAMP_TX_OFF:
  2371. cpts_tx_enable(cpts, 0);
  2372. break;
  2373. case HWTSTAMP_TX_ON:
  2374. cpts_tx_enable(cpts, 1);
  2375. break;
  2376. default:
  2377. return -ERANGE;
  2378. }
  2379. switch (cfg.rx_filter) {
  2380. case HWTSTAMP_FILTER_NONE:
  2381. cpts_rx_enable(cpts, 0);
  2382. break;
  2383. case HWTSTAMP_FILTER_ALL:
  2384. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  2385. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  2386. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  2387. cpts_rx_enable(cpts, HWTSTAMP_FILTER_PTP_V1_L4_EVENT);
  2388. cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  2389. break;
  2390. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  2391. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  2392. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  2393. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  2394. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  2395. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  2396. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  2397. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  2398. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  2399. cpts_rx_enable(cpts, HWTSTAMP_FILTER_PTP_V2_EVENT);
  2400. cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  2401. break;
  2402. default:
  2403. return -ERANGE;
  2404. }
  2405. gbe_hwtstamp(gbe_intf);
  2406. return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
  2407. }
  2408. static void gbe_register_cpts(struct gbe_priv *gbe_dev)
  2409. {
  2410. if (!gbe_dev->cpts)
  2411. return;
  2412. if (gbe_dev->cpts_registered > 0)
  2413. goto done;
  2414. if (cpts_register(gbe_dev->cpts)) {
  2415. dev_err(gbe_dev->dev, "error registering cpts device\n");
  2416. return;
  2417. }
  2418. done:
  2419. ++gbe_dev->cpts_registered;
  2420. }
  2421. static void gbe_unregister_cpts(struct gbe_priv *gbe_dev)
  2422. {
  2423. if (!gbe_dev->cpts || (gbe_dev->cpts_registered <= 0))
  2424. return;
  2425. if (--gbe_dev->cpts_registered)
  2426. return;
  2427. cpts_unregister(gbe_dev->cpts);
  2428. }
  2429. #else
  2430. static inline int gbe_txtstamp_mark_pkt(struct gbe_intf *gbe_intf,
  2431. struct netcp_packet *p_info)
  2432. {
  2433. return 0;
  2434. }
  2435. static inline int gbe_rxtstamp(struct gbe_intf *gbe_intf,
  2436. struct netcp_packet *p_info)
  2437. {
  2438. return 0;
  2439. }
  2440. static inline int gbe_hwtstamp(struct gbe_intf *gbe_intf,
  2441. struct ifreq *ifr, int cmd)
  2442. {
  2443. return -EOPNOTSUPP;
  2444. }
  2445. static inline void gbe_register_cpts(struct gbe_priv *gbe_dev)
  2446. {
  2447. }
  2448. static inline void gbe_unregister_cpts(struct gbe_priv *gbe_dev)
  2449. {
  2450. }
  2451. static inline int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, struct ifreq *req)
  2452. {
  2453. return -EOPNOTSUPP;
  2454. }
  2455. static inline int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *req)
  2456. {
  2457. return -EOPNOTSUPP;
  2458. }
  2459. #endif /* CONFIG_TI_CPTS */
  2460. static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd)
  2461. {
  2462. struct gbe_intf *gbe_intf = intf_priv;
  2463. struct phy_device *phy = gbe_intf->slave->phy;
  2464. if (!phy || !phy->drv->hwtstamp) {
  2465. switch (cmd) {
  2466. case SIOCGHWTSTAMP:
  2467. return gbe_hwtstamp_get(gbe_intf, req);
  2468. case SIOCSHWTSTAMP:
  2469. return gbe_hwtstamp_set(gbe_intf, req);
  2470. }
  2471. }
  2472. if (phy)
  2473. return phy_mii_ioctl(phy, req, cmd);
  2474. return -EOPNOTSUPP;
  2475. }
  2476. static void netcp_ethss_timer(unsigned long arg)
  2477. {
  2478. struct gbe_priv *gbe_dev = (struct gbe_priv *)arg;
  2479. struct gbe_intf *gbe_intf;
  2480. struct gbe_slave *slave;
  2481. /* Check & update SGMII link state of interfaces */
  2482. for_each_intf(gbe_intf, gbe_dev) {
  2483. if (!gbe_intf->slave->open)
  2484. continue;
  2485. netcp_ethss_update_link_state(gbe_dev, gbe_intf->slave,
  2486. gbe_intf->ndev);
  2487. }
  2488. /* Check & update SGMII link state of secondary ports */
  2489. for_each_sec_slave(slave, gbe_dev) {
  2490. netcp_ethss_update_link_state(gbe_dev, slave, NULL);
  2491. }
  2492. /* A timer runs as a BH, no need to block them */
  2493. spin_lock(&gbe_dev->hw_stats_lock);
  2494. if (gbe_dev->ss_version == GBE_SS_VERSION_14)
  2495. gbe_update_stats_ver14(gbe_dev, NULL);
  2496. else
  2497. gbe_update_stats(gbe_dev, NULL);
  2498. spin_unlock(&gbe_dev->hw_stats_lock);
  2499. gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL;
  2500. add_timer(&gbe_dev->timer);
  2501. }
  2502. static int gbe_txhook(int order, void *data, struct netcp_packet *p_info)
  2503. {
  2504. struct gbe_intf *gbe_intf = data;
  2505. p_info->tx_pipe = &gbe_intf->tx_pipe;
  2506. return gbe_txtstamp_mark_pkt(gbe_intf, p_info);
  2507. }
  2508. static int gbe_rxhook(int order, void *data, struct netcp_packet *p_info)
  2509. {
  2510. struct gbe_intf *gbe_intf = data;
  2511. return gbe_rxtstamp(gbe_intf, p_info);
  2512. }
  2513. static int gbe_open(void *intf_priv, struct net_device *ndev)
  2514. {
  2515. struct gbe_intf *gbe_intf = intf_priv;
  2516. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2517. struct netcp_intf *netcp = netdev_priv(ndev);
  2518. struct gbe_slave *slave = gbe_intf->slave;
  2519. int port_num = slave->port_num;
  2520. u32 reg, val;
  2521. int ret;
  2522. reg = readl(GBE_REG_ADDR(gbe_dev, switch_regs, id_ver));
  2523. dev_dbg(gbe_dev->dev, "initializing gbe version %d.%d (%d) GBE identification value 0x%x\n",
  2524. GBE_MAJOR_VERSION(reg), GBE_MINOR_VERSION(reg),
  2525. GBE_RTL_VERSION(reg), GBE_IDENT(reg));
  2526. /* For 10G and on NetCP 1.5, use directed to port */
  2527. if ((gbe_dev->ss_version == XGBE_SS_VERSION_10) || IS_SS_ID_MU(gbe_dev))
  2528. gbe_intf->tx_pipe.flags = SWITCH_TO_PORT_IN_TAGINFO;
  2529. if (gbe_dev->enable_ale)
  2530. gbe_intf->tx_pipe.switch_to_port = 0;
  2531. else
  2532. gbe_intf->tx_pipe.switch_to_port = port_num;
  2533. dev_dbg(gbe_dev->dev,
  2534. "opened TX channel %s: %p with to port %d, flags %d\n",
  2535. gbe_intf->tx_pipe.dma_chan_name,
  2536. gbe_intf->tx_pipe.dma_channel,
  2537. gbe_intf->tx_pipe.switch_to_port,
  2538. gbe_intf->tx_pipe.flags);
  2539. gbe_slave_stop(gbe_intf);
  2540. /* disable priority elevation and enable statistics on all ports */
  2541. writel(0, GBE_REG_ADDR(gbe_dev, switch_regs, ptype));
  2542. /* Control register */
  2543. val = GBE_CTL_P0_ENABLE;
  2544. if (IS_SS_ID_MU(gbe_dev)) {
  2545. val |= ETH_SW_CTL_P0_TX_CRC_REMOVE;
  2546. netcp->hw_cap = ETH_SW_CAN_REMOVE_ETH_FCS;
  2547. }
  2548. writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, control));
  2549. /* All statistics enabled and STAT AB visible by default */
  2550. writel(gbe_dev->stats_en_mask, GBE_REG_ADDR(gbe_dev, switch_regs,
  2551. stat_port_en));
  2552. ret = gbe_slave_open(gbe_intf);
  2553. if (ret)
  2554. goto fail;
  2555. netcp_register_txhook(netcp, GBE_TXHOOK_ORDER, gbe_txhook, gbe_intf);
  2556. netcp_register_rxhook(netcp, GBE_RXHOOK_ORDER, gbe_rxhook, gbe_intf);
  2557. slave->open = true;
  2558. netcp_ethss_update_link_state(gbe_dev, slave, ndev);
  2559. gbe_register_cpts(gbe_dev);
  2560. return 0;
  2561. fail:
  2562. gbe_slave_stop(gbe_intf);
  2563. return ret;
  2564. }
  2565. static int gbe_close(void *intf_priv, struct net_device *ndev)
  2566. {
  2567. struct gbe_intf *gbe_intf = intf_priv;
  2568. struct netcp_intf *netcp = netdev_priv(ndev);
  2569. struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
  2570. gbe_unregister_cpts(gbe_dev);
  2571. gbe_slave_stop(gbe_intf);
  2572. netcp_unregister_rxhook(netcp, GBE_RXHOOK_ORDER, gbe_rxhook, gbe_intf);
  2573. netcp_unregister_txhook(netcp, GBE_TXHOOK_ORDER, gbe_txhook, gbe_intf);
  2574. gbe_intf->slave->open = false;
  2575. atomic_set(&gbe_intf->slave->link_state, NETCP_LINK_STATE_INVALID);
  2576. return 0;
  2577. }
  2578. #if IS_ENABLED(CONFIG_TI_CPTS)
  2579. static void init_slave_ts_ctl(struct gbe_slave *slave)
  2580. {
  2581. slave->ts_ctl.uni = 1;
  2582. slave->ts_ctl.dst_port_map =
  2583. (TS_CTL_DST_PORT >> TS_CTL_DST_PORT_SHIFT) & 0x3;
  2584. slave->ts_ctl.maddr_map =
  2585. (TS_CTL_MADDR_ALL >> TS_CTL_MADDR_SHIFT) & 0x1f;
  2586. }
  2587. #else
  2588. static void init_slave_ts_ctl(struct gbe_slave *slave)
  2589. {
  2590. }
  2591. #endif /* CONFIG_TI_CPTS */
  2592. static int init_slave(struct gbe_priv *gbe_dev, struct gbe_slave *slave,
  2593. struct device_node *node)
  2594. {
  2595. int port_reg_num;
  2596. u32 port_reg_ofs, emac_reg_ofs;
  2597. u32 port_reg_blk_sz, emac_reg_blk_sz;
  2598. if (of_property_read_u32(node, "slave-port", &slave->slave_num)) {
  2599. dev_err(gbe_dev->dev, "missing slave-port parameter\n");
  2600. return -EINVAL;
  2601. }
  2602. if (of_property_read_u32(node, "link-interface",
  2603. &slave->link_interface)) {
  2604. dev_warn(gbe_dev->dev,
  2605. "missing link-interface value defaulting to 1G mac-phy link\n");
  2606. slave->link_interface = SGMII_LINK_MAC_PHY;
  2607. }
  2608. slave->open = false;
  2609. if ((slave->link_interface == SGMII_LINK_MAC_PHY) ||
  2610. (slave->link_interface == XGMII_LINK_MAC_PHY))
  2611. slave->phy_node = of_parse_phandle(node, "phy-handle", 0);
  2612. slave->port_num = gbe_get_slave_port(gbe_dev, slave->slave_num);
  2613. if (slave->link_interface >= XGMII_LINK_MAC_PHY)
  2614. slave->mac_control = GBE_DEF_10G_MAC_CONTROL;
  2615. else
  2616. slave->mac_control = GBE_DEF_1G_MAC_CONTROL;
  2617. /* Emac regs memmap are contiguous but port regs are not */
  2618. port_reg_num = slave->slave_num;
  2619. if (gbe_dev->ss_version == GBE_SS_VERSION_14) {
  2620. if (slave->slave_num > 1) {
  2621. port_reg_ofs = GBE13_SLAVE_PORT2_OFFSET;
  2622. port_reg_num -= 2;
  2623. } else {
  2624. port_reg_ofs = GBE13_SLAVE_PORT_OFFSET;
  2625. }
  2626. emac_reg_ofs = GBE13_EMAC_OFFSET;
  2627. port_reg_blk_sz = 0x30;
  2628. emac_reg_blk_sz = 0x40;
  2629. } else if (IS_SS_ID_MU(gbe_dev)) {
  2630. port_reg_ofs = GBENU_SLAVE_PORT_OFFSET;
  2631. emac_reg_ofs = GBENU_EMAC_OFFSET;
  2632. port_reg_blk_sz = 0x1000;
  2633. emac_reg_blk_sz = 0x1000;
  2634. } else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) {
  2635. port_reg_ofs = XGBE10_SLAVE_PORT_OFFSET;
  2636. emac_reg_ofs = XGBE10_EMAC_OFFSET;
  2637. port_reg_blk_sz = 0x30;
  2638. emac_reg_blk_sz = 0x40;
  2639. } else {
  2640. dev_err(gbe_dev->dev, "unknown ethss(0x%x)\n",
  2641. gbe_dev->ss_version);
  2642. return -EINVAL;
  2643. }
  2644. slave->port_regs = gbe_dev->switch_regs + port_reg_ofs +
  2645. (port_reg_blk_sz * port_reg_num);
  2646. slave->emac_regs = gbe_dev->switch_regs + emac_reg_ofs +
  2647. (emac_reg_blk_sz * slave->slave_num);
  2648. if (gbe_dev->ss_version == GBE_SS_VERSION_14) {
  2649. /* Initialize slave port register offsets */
  2650. GBE_SET_REG_OFS(slave, port_regs, port_vlan);
  2651. GBE_SET_REG_OFS(slave, port_regs, tx_pri_map);
  2652. GBE_SET_REG_OFS(slave, port_regs, sa_lo);
  2653. GBE_SET_REG_OFS(slave, port_regs, sa_hi);
  2654. GBE_SET_REG_OFS(slave, port_regs, ts_ctl);
  2655. GBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
  2656. GBE_SET_REG_OFS(slave, port_regs, ts_vlan);
  2657. GBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
  2658. GBE_SET_REG_OFS(slave, port_regs, ts_ctl2);
  2659. /* Initialize EMAC register offsets */
  2660. GBE_SET_REG_OFS(slave, emac_regs, mac_control);
  2661. GBE_SET_REG_OFS(slave, emac_regs, soft_reset);
  2662. GBE_SET_REG_OFS(slave, emac_regs, rx_maxlen);
  2663. } else if (IS_SS_ID_MU(gbe_dev)) {
  2664. /* Initialize slave port register offsets */
  2665. GBENU_SET_REG_OFS(slave, port_regs, port_vlan);
  2666. GBENU_SET_REG_OFS(slave, port_regs, tx_pri_map);
  2667. GBENU_SET_REG_OFS(slave, port_regs, sa_lo);
  2668. GBENU_SET_REG_OFS(slave, port_regs, sa_hi);
  2669. GBENU_SET_REG_OFS(slave, port_regs, ts_ctl);
  2670. GBENU_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
  2671. GBENU_SET_REG_OFS(slave, port_regs, ts_vlan);
  2672. GBENU_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
  2673. GBENU_SET_REG_OFS(slave, port_regs, ts_ctl2);
  2674. GBENU_SET_REG_OFS(slave, port_regs, rx_maxlen);
  2675. /* Initialize EMAC register offsets */
  2676. GBENU_SET_REG_OFS(slave, emac_regs, mac_control);
  2677. GBENU_SET_REG_OFS(slave, emac_regs, soft_reset);
  2678. } else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) {
  2679. /* Initialize slave port register offsets */
  2680. XGBE_SET_REG_OFS(slave, port_regs, port_vlan);
  2681. XGBE_SET_REG_OFS(slave, port_regs, tx_pri_map);
  2682. XGBE_SET_REG_OFS(slave, port_regs, sa_lo);
  2683. XGBE_SET_REG_OFS(slave, port_regs, sa_hi);
  2684. XGBE_SET_REG_OFS(slave, port_regs, ts_ctl);
  2685. XGBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
  2686. XGBE_SET_REG_OFS(slave, port_regs, ts_vlan);
  2687. XGBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
  2688. XGBE_SET_REG_OFS(slave, port_regs, ts_ctl2);
  2689. /* Initialize EMAC register offsets */
  2690. XGBE_SET_REG_OFS(slave, emac_regs, mac_control);
  2691. XGBE_SET_REG_OFS(slave, emac_regs, soft_reset);
  2692. XGBE_SET_REG_OFS(slave, emac_regs, rx_maxlen);
  2693. }
  2694. atomic_set(&slave->link_state, NETCP_LINK_STATE_INVALID);
  2695. init_slave_ts_ctl(slave);
  2696. return 0;
  2697. }
  2698. static void init_secondary_ports(struct gbe_priv *gbe_dev,
  2699. struct device_node *node)
  2700. {
  2701. struct device *dev = gbe_dev->dev;
  2702. phy_interface_t phy_mode;
  2703. struct gbe_priv **priv;
  2704. struct device_node *port;
  2705. struct gbe_slave *slave;
  2706. bool mac_phy_link = false;
  2707. for_each_child_of_node(node, port) {
  2708. slave = devm_kzalloc(dev, sizeof(*slave), GFP_KERNEL);
  2709. if (!slave) {
  2710. dev_err(dev,
  2711. "memomry alloc failed for secondary port(%s), skipping...\n",
  2712. port->name);
  2713. continue;
  2714. }
  2715. if (init_slave(gbe_dev, slave, port)) {
  2716. dev_err(dev,
  2717. "Failed to initialize secondary port(%s), skipping...\n",
  2718. port->name);
  2719. devm_kfree(dev, slave);
  2720. continue;
  2721. }
  2722. gbe_sgmii_config(gbe_dev, slave);
  2723. gbe_port_reset(slave);
  2724. gbe_port_config(gbe_dev, slave, gbe_dev->rx_packet_max);
  2725. list_add_tail(&slave->slave_list, &gbe_dev->secondary_slaves);
  2726. gbe_dev->num_slaves++;
  2727. if ((slave->link_interface == SGMII_LINK_MAC_PHY) ||
  2728. (slave->link_interface == XGMII_LINK_MAC_PHY))
  2729. mac_phy_link = true;
  2730. slave->open = true;
  2731. if (gbe_dev->num_slaves >= gbe_dev->max_num_slaves) {
  2732. of_node_put(port);
  2733. break;
  2734. }
  2735. }
  2736. /* of_phy_connect() is needed only for MAC-PHY interface */
  2737. if (!mac_phy_link)
  2738. return;
  2739. /* Allocate dummy netdev device for attaching to phy device */
  2740. gbe_dev->dummy_ndev = alloc_netdev(sizeof(gbe_dev), "dummy",
  2741. NET_NAME_UNKNOWN, ether_setup);
  2742. if (!gbe_dev->dummy_ndev) {
  2743. dev_err(dev,
  2744. "Failed to allocate dummy netdev for secondary ports, skipping phy_connect()...\n");
  2745. return;
  2746. }
  2747. priv = netdev_priv(gbe_dev->dummy_ndev);
  2748. *priv = gbe_dev;
  2749. if (slave->link_interface == SGMII_LINK_MAC_PHY) {
  2750. phy_mode = PHY_INTERFACE_MODE_SGMII;
  2751. slave->phy_port_t = PORT_MII;
  2752. } else {
  2753. phy_mode = PHY_INTERFACE_MODE_NA;
  2754. slave->phy_port_t = PORT_FIBRE;
  2755. }
  2756. for_each_sec_slave(slave, gbe_dev) {
  2757. if ((slave->link_interface != SGMII_LINK_MAC_PHY) &&
  2758. (slave->link_interface != XGMII_LINK_MAC_PHY))
  2759. continue;
  2760. slave->phy =
  2761. of_phy_connect(gbe_dev->dummy_ndev,
  2762. slave->phy_node,
  2763. gbe_adjust_link_sec_slaves,
  2764. 0, phy_mode);
  2765. if (!slave->phy) {
  2766. dev_err(dev, "phy not found for slave %d\n",
  2767. slave->slave_num);
  2768. slave->phy = NULL;
  2769. } else {
  2770. dev_dbg(dev, "phy found: id is: 0x%s\n",
  2771. phydev_name(slave->phy));
  2772. phy_start(slave->phy);
  2773. }
  2774. }
  2775. }
  2776. static void free_secondary_ports(struct gbe_priv *gbe_dev)
  2777. {
  2778. struct gbe_slave *slave;
  2779. while (!list_empty(&gbe_dev->secondary_slaves)) {
  2780. slave = first_sec_slave(gbe_dev);
  2781. if (slave->phy)
  2782. phy_disconnect(slave->phy);
  2783. list_del(&slave->slave_list);
  2784. }
  2785. if (gbe_dev->dummy_ndev)
  2786. free_netdev(gbe_dev->dummy_ndev);
  2787. }
  2788. static int set_xgbe_ethss10_priv(struct gbe_priv *gbe_dev,
  2789. struct device_node *node)
  2790. {
  2791. struct resource res;
  2792. void __iomem *regs;
  2793. int ret, i;
  2794. ret = of_address_to_resource(node, XGBE_SS_REG_INDEX, &res);
  2795. if (ret) {
  2796. dev_err(gbe_dev->dev,
  2797. "Can't xlate xgbe of node(%s) ss address at %d\n",
  2798. node->name, XGBE_SS_REG_INDEX);
  2799. return ret;
  2800. }
  2801. regs = devm_ioremap_resource(gbe_dev->dev, &res);
  2802. if (IS_ERR(regs)) {
  2803. dev_err(gbe_dev->dev, "Failed to map xgbe ss register base\n");
  2804. return PTR_ERR(regs);
  2805. }
  2806. gbe_dev->ss_regs = regs;
  2807. ret = of_address_to_resource(node, XGBE_SM_REG_INDEX, &res);
  2808. if (ret) {
  2809. dev_err(gbe_dev->dev,
  2810. "Can't xlate xgbe of node(%s) sm address at %d\n",
  2811. node->name, XGBE_SM_REG_INDEX);
  2812. return ret;
  2813. }
  2814. regs = devm_ioremap_resource(gbe_dev->dev, &res);
  2815. if (IS_ERR(regs)) {
  2816. dev_err(gbe_dev->dev, "Failed to map xgbe sm register base\n");
  2817. return PTR_ERR(regs);
  2818. }
  2819. gbe_dev->switch_regs = regs;
  2820. ret = of_address_to_resource(node, XGBE_SERDES_REG_INDEX, &res);
  2821. if (ret) {
  2822. dev_err(gbe_dev->dev,
  2823. "Can't xlate xgbe serdes of node(%s) address at %d\n",
  2824. node->name, XGBE_SERDES_REG_INDEX);
  2825. return ret;
  2826. }
  2827. regs = devm_ioremap_resource(gbe_dev->dev, &res);
  2828. if (IS_ERR(regs)) {
  2829. dev_err(gbe_dev->dev, "Failed to map xgbe serdes register base\n");
  2830. return PTR_ERR(regs);
  2831. }
  2832. gbe_dev->xgbe_serdes_regs = regs;
  2833. gbe_dev->num_stats_mods = gbe_dev->max_num_ports;
  2834. gbe_dev->et_stats = xgbe10_et_stats;
  2835. gbe_dev->num_et_stats = ARRAY_SIZE(xgbe10_et_stats);
  2836. gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev,
  2837. gbe_dev->num_et_stats * sizeof(u64),
  2838. GFP_KERNEL);
  2839. if (!gbe_dev->hw_stats) {
  2840. dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
  2841. return -ENOMEM;
  2842. }
  2843. gbe_dev->hw_stats_prev =
  2844. devm_kzalloc(gbe_dev->dev,
  2845. gbe_dev->num_et_stats * sizeof(u32),
  2846. GFP_KERNEL);
  2847. if (!gbe_dev->hw_stats_prev) {
  2848. dev_err(gbe_dev->dev,
  2849. "hw_stats_prev memory allocation failed\n");
  2850. return -ENOMEM;
  2851. }
  2852. gbe_dev->ss_version = XGBE_SS_VERSION_10;
  2853. gbe_dev->sgmii_port_regs = gbe_dev->ss_regs +
  2854. XGBE10_SGMII_MODULE_OFFSET;
  2855. gbe_dev->host_port_regs = gbe_dev->ss_regs + XGBE10_HOST_PORT_OFFSET;
  2856. for (i = 0; i < gbe_dev->max_num_ports; i++)
  2857. gbe_dev->hw_stats_regs[i] = gbe_dev->switch_regs +
  2858. XGBE10_HW_STATS_OFFSET + (GBE_HW_STATS_REG_MAP_SZ * i);
  2859. gbe_dev->ale_reg = gbe_dev->switch_regs + XGBE10_ALE_OFFSET;
  2860. gbe_dev->cpts_reg = gbe_dev->switch_regs + XGBE10_CPTS_OFFSET;
  2861. gbe_dev->ale_ports = gbe_dev->max_num_ports;
  2862. gbe_dev->host_port = XGBE10_HOST_PORT_NUM;
  2863. gbe_dev->ale_entries = XGBE10_NUM_ALE_ENTRIES;
  2864. gbe_dev->stats_en_mask = (1 << (gbe_dev->max_num_ports)) - 1;
  2865. /* Subsystem registers */
  2866. XGBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
  2867. XGBE_SET_REG_OFS(gbe_dev, ss_regs, control);
  2868. /* Switch module registers */
  2869. XGBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
  2870. XGBE_SET_REG_OFS(gbe_dev, switch_regs, control);
  2871. XGBE_SET_REG_OFS(gbe_dev, switch_regs, ptype);
  2872. XGBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
  2873. XGBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control);
  2874. /* Host port registers */
  2875. XGBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
  2876. XGBE_SET_REG_OFS(gbe_dev, host_port_regs, tx_pri_map);
  2877. XGBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
  2878. return 0;
  2879. }
  2880. static int get_gbe_resource_version(struct gbe_priv *gbe_dev,
  2881. struct device_node *node)
  2882. {
  2883. struct resource res;
  2884. void __iomem *regs;
  2885. int ret;
  2886. ret = of_address_to_resource(node, GBE_SS_REG_INDEX, &res);
  2887. if (ret) {
  2888. dev_err(gbe_dev->dev,
  2889. "Can't translate of node(%s) of gbe ss address at %d\n",
  2890. node->name, GBE_SS_REG_INDEX);
  2891. return ret;
  2892. }
  2893. regs = devm_ioremap_resource(gbe_dev->dev, &res);
  2894. if (IS_ERR(regs)) {
  2895. dev_err(gbe_dev->dev, "Failed to map gbe register base\n");
  2896. return PTR_ERR(regs);
  2897. }
  2898. gbe_dev->ss_regs = regs;
  2899. gbe_dev->ss_version = readl(gbe_dev->ss_regs);
  2900. return 0;
  2901. }
  2902. static int set_gbe_ethss14_priv(struct gbe_priv *gbe_dev,
  2903. struct device_node *node)
  2904. {
  2905. struct resource res;
  2906. void __iomem *regs;
  2907. int i, ret;
  2908. ret = of_address_to_resource(node, GBE_SGMII34_REG_INDEX, &res);
  2909. if (ret) {
  2910. dev_err(gbe_dev->dev,
  2911. "Can't translate of gbe node(%s) address at index %d\n",
  2912. node->name, GBE_SGMII34_REG_INDEX);
  2913. return ret;
  2914. }
  2915. regs = devm_ioremap_resource(gbe_dev->dev, &res);
  2916. if (IS_ERR(regs)) {
  2917. dev_err(gbe_dev->dev,
  2918. "Failed to map gbe sgmii port34 register base\n");
  2919. return PTR_ERR(regs);
  2920. }
  2921. gbe_dev->sgmii_port34_regs = regs;
  2922. ret = of_address_to_resource(node, GBE_SM_REG_INDEX, &res);
  2923. if (ret) {
  2924. dev_err(gbe_dev->dev,
  2925. "Can't translate of gbe node(%s) address at index %d\n",
  2926. node->name, GBE_SM_REG_INDEX);
  2927. return ret;
  2928. }
  2929. regs = devm_ioremap_resource(gbe_dev->dev, &res);
  2930. if (IS_ERR(regs)) {
  2931. dev_err(gbe_dev->dev,
  2932. "Failed to map gbe switch module register base\n");
  2933. return PTR_ERR(regs);
  2934. }
  2935. gbe_dev->switch_regs = regs;
  2936. gbe_dev->num_stats_mods = gbe_dev->max_num_slaves;
  2937. gbe_dev->et_stats = gbe13_et_stats;
  2938. gbe_dev->num_et_stats = ARRAY_SIZE(gbe13_et_stats);
  2939. gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev,
  2940. gbe_dev->num_et_stats * sizeof(u64),
  2941. GFP_KERNEL);
  2942. if (!gbe_dev->hw_stats) {
  2943. dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
  2944. return -ENOMEM;
  2945. }
  2946. gbe_dev->hw_stats_prev =
  2947. devm_kzalloc(gbe_dev->dev,
  2948. gbe_dev->num_et_stats * sizeof(u32),
  2949. GFP_KERNEL);
  2950. if (!gbe_dev->hw_stats_prev) {
  2951. dev_err(gbe_dev->dev,
  2952. "hw_stats_prev memory allocation failed\n");
  2953. return -ENOMEM;
  2954. }
  2955. gbe_dev->sgmii_port_regs = gbe_dev->ss_regs + GBE13_SGMII_MODULE_OFFSET;
  2956. gbe_dev->host_port_regs = gbe_dev->switch_regs + GBE13_HOST_PORT_OFFSET;
  2957. /* K2HK has only 2 hw stats modules visible at a time, so
  2958. * module 0 & 2 points to one base and
  2959. * module 1 & 3 points to the other base
  2960. */
  2961. for (i = 0; i < gbe_dev->max_num_slaves; i++) {
  2962. gbe_dev->hw_stats_regs[i] =
  2963. gbe_dev->switch_regs + GBE13_HW_STATS_OFFSET +
  2964. (GBE_HW_STATS_REG_MAP_SZ * (i & 0x1));
  2965. }
  2966. gbe_dev->cpts_reg = gbe_dev->switch_regs + GBE13_CPTS_OFFSET;
  2967. gbe_dev->ale_reg = gbe_dev->switch_regs + GBE13_ALE_OFFSET;
  2968. gbe_dev->ale_ports = gbe_dev->max_num_ports;
  2969. gbe_dev->host_port = GBE13_HOST_PORT_NUM;
  2970. gbe_dev->ale_entries = GBE13_NUM_ALE_ENTRIES;
  2971. gbe_dev->stats_en_mask = GBE13_REG_VAL_STAT_ENABLE_ALL;
  2972. /* Subsystem registers */
  2973. GBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
  2974. /* Switch module registers */
  2975. GBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
  2976. GBE_SET_REG_OFS(gbe_dev, switch_regs, control);
  2977. GBE_SET_REG_OFS(gbe_dev, switch_regs, soft_reset);
  2978. GBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
  2979. GBE_SET_REG_OFS(gbe_dev, switch_regs, ptype);
  2980. GBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control);
  2981. /* Host port registers */
  2982. GBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
  2983. GBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
  2984. return 0;
  2985. }
  2986. static int set_gbenu_ethss_priv(struct gbe_priv *gbe_dev,
  2987. struct device_node *node)
  2988. {
  2989. struct resource res;
  2990. void __iomem *regs;
  2991. int i, ret;
  2992. gbe_dev->num_stats_mods = gbe_dev->max_num_ports;
  2993. gbe_dev->et_stats = gbenu_et_stats;
  2994. if (IS_SS_ID_NU(gbe_dev))
  2995. gbe_dev->num_et_stats = GBENU_ET_STATS_HOST_SIZE +
  2996. (gbe_dev->max_num_slaves * GBENU_ET_STATS_PORT_SIZE);
  2997. else
  2998. gbe_dev->num_et_stats = GBENU_ET_STATS_HOST_SIZE +
  2999. GBENU_ET_STATS_PORT_SIZE;
  3000. gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev,
  3001. gbe_dev->num_et_stats * sizeof(u64),
  3002. GFP_KERNEL);
  3003. if (!gbe_dev->hw_stats) {
  3004. dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
  3005. return -ENOMEM;
  3006. }
  3007. gbe_dev->hw_stats_prev =
  3008. devm_kzalloc(gbe_dev->dev,
  3009. gbe_dev->num_et_stats * sizeof(u32),
  3010. GFP_KERNEL);
  3011. if (!gbe_dev->hw_stats_prev) {
  3012. dev_err(gbe_dev->dev,
  3013. "hw_stats_prev memory allocation failed\n");
  3014. return -ENOMEM;
  3015. }
  3016. ret = of_address_to_resource(node, GBENU_SM_REG_INDEX, &res);
  3017. if (ret) {
  3018. dev_err(gbe_dev->dev,
  3019. "Can't translate of gbenu node(%s) addr at index %d\n",
  3020. node->name, GBENU_SM_REG_INDEX);
  3021. return ret;
  3022. }
  3023. regs = devm_ioremap_resource(gbe_dev->dev, &res);
  3024. if (IS_ERR(regs)) {
  3025. dev_err(gbe_dev->dev,
  3026. "Failed to map gbenu switch module register base\n");
  3027. return PTR_ERR(regs);
  3028. }
  3029. gbe_dev->switch_regs = regs;
  3030. gbe_dev->sgmii_port_regs = gbe_dev->ss_regs + GBENU_SGMII_MODULE_OFFSET;
  3031. /* Although sgmii modules are mem mapped to one contiguous
  3032. * region on GBENU devices, setting sgmii_port34_regs allows
  3033. * consistent code when accessing sgmii api
  3034. */
  3035. gbe_dev->sgmii_port34_regs = gbe_dev->sgmii_port_regs +
  3036. (2 * GBENU_SGMII_MODULE_SIZE);
  3037. gbe_dev->host_port_regs = gbe_dev->switch_regs + GBENU_HOST_PORT_OFFSET;
  3038. for (i = 0; i < (gbe_dev->max_num_ports); i++)
  3039. gbe_dev->hw_stats_regs[i] = gbe_dev->switch_regs +
  3040. GBENU_HW_STATS_OFFSET + (GBENU_HW_STATS_REG_MAP_SZ * i);
  3041. gbe_dev->cpts_reg = gbe_dev->switch_regs + GBENU_CPTS_OFFSET;
  3042. gbe_dev->ale_reg = gbe_dev->switch_regs + GBENU_ALE_OFFSET;
  3043. gbe_dev->ale_ports = gbe_dev->max_num_ports;
  3044. gbe_dev->host_port = GBENU_HOST_PORT_NUM;
  3045. gbe_dev->stats_en_mask = (1 << (gbe_dev->max_num_ports)) - 1;
  3046. /* Subsystem registers */
  3047. GBENU_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
  3048. /* Switch module registers */
  3049. GBENU_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
  3050. GBENU_SET_REG_OFS(gbe_dev, switch_regs, control);
  3051. GBENU_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
  3052. GBENU_SET_REG_OFS(gbe_dev, switch_regs, ptype);
  3053. /* Host port registers */
  3054. GBENU_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
  3055. GBENU_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
  3056. /* For NU only. 2U does not need tx_pri_map.
  3057. * NU cppi port 0 tx pkt streaming interface has (n-1)*8 egress threads
  3058. * while 2U has only 1 such thread
  3059. */
  3060. GBENU_SET_REG_OFS(gbe_dev, host_port_regs, tx_pri_map);
  3061. return 0;
  3062. }
  3063. static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
  3064. struct device_node *node, void **inst_priv)
  3065. {
  3066. struct device_node *interfaces, *interface;
  3067. struct device_node *secondary_ports;
  3068. struct cpsw_ale_params ale_params;
  3069. struct gbe_priv *gbe_dev;
  3070. u32 slave_num;
  3071. int i, ret = 0;
  3072. if (!node) {
  3073. dev_err(dev, "device tree info unavailable\n");
  3074. return -ENODEV;
  3075. }
  3076. gbe_dev = devm_kzalloc(dev, sizeof(struct gbe_priv), GFP_KERNEL);
  3077. if (!gbe_dev)
  3078. return -ENOMEM;
  3079. if (of_device_is_compatible(node, "ti,netcp-gbe-5") ||
  3080. of_device_is_compatible(node, "ti,netcp-gbe")) {
  3081. gbe_dev->max_num_slaves = 4;
  3082. } else if (of_device_is_compatible(node, "ti,netcp-gbe-9")) {
  3083. gbe_dev->max_num_slaves = 8;
  3084. } else if (of_device_is_compatible(node, "ti,netcp-gbe-2")) {
  3085. gbe_dev->max_num_slaves = 1;
  3086. } else if (of_device_is_compatible(node, "ti,netcp-xgbe")) {
  3087. gbe_dev->max_num_slaves = 2;
  3088. } else {
  3089. dev_err(dev, "device tree node for unknown device\n");
  3090. return -EINVAL;
  3091. }
  3092. gbe_dev->max_num_ports = gbe_dev->max_num_slaves + 1;
  3093. gbe_dev->dev = dev;
  3094. gbe_dev->netcp_device = netcp_device;
  3095. gbe_dev->rx_packet_max = NETCP_MAX_FRAME_SIZE;
  3096. /* init the hw stats lock */
  3097. spin_lock_init(&gbe_dev->hw_stats_lock);
  3098. if (of_find_property(node, "enable-ale", NULL)) {
  3099. gbe_dev->enable_ale = true;
  3100. dev_info(dev, "ALE enabled\n");
  3101. } else {
  3102. gbe_dev->enable_ale = false;
  3103. dev_dbg(dev, "ALE bypass enabled*\n");
  3104. }
  3105. ret = of_property_read_u32(node, "tx-queue",
  3106. &gbe_dev->tx_queue_id);
  3107. if (ret < 0) {
  3108. dev_err(dev, "missing tx_queue parameter\n");
  3109. gbe_dev->tx_queue_id = GBE_TX_QUEUE;
  3110. }
  3111. ret = of_property_read_string(node, "tx-channel",
  3112. &gbe_dev->dma_chan_name);
  3113. if (ret < 0) {
  3114. dev_err(dev, "missing \"tx-channel\" parameter\n");
  3115. return -EINVAL;
  3116. }
  3117. if (!strcmp(node->name, "gbe")) {
  3118. ret = get_gbe_resource_version(gbe_dev, node);
  3119. if (ret)
  3120. return ret;
  3121. dev_dbg(dev, "ss_version: 0x%08x\n", gbe_dev->ss_version);
  3122. if (gbe_dev->ss_version == GBE_SS_VERSION_14)
  3123. ret = set_gbe_ethss14_priv(gbe_dev, node);
  3124. else if (IS_SS_ID_MU(gbe_dev))
  3125. ret = set_gbenu_ethss_priv(gbe_dev, node);
  3126. else
  3127. ret = -ENODEV;
  3128. } else if (!strcmp(node->name, "xgbe")) {
  3129. ret = set_xgbe_ethss10_priv(gbe_dev, node);
  3130. if (ret)
  3131. return ret;
  3132. ret = netcp_xgbe_serdes_init(gbe_dev->xgbe_serdes_regs,
  3133. gbe_dev->ss_regs);
  3134. } else {
  3135. dev_err(dev, "unknown GBE node(%s)\n", node->name);
  3136. ret = -ENODEV;
  3137. }
  3138. if (ret)
  3139. return ret;
  3140. interfaces = of_get_child_by_name(node, "interfaces");
  3141. if (!interfaces)
  3142. dev_err(dev, "could not find interfaces\n");
  3143. ret = netcp_txpipe_init(&gbe_dev->tx_pipe, netcp_device,
  3144. gbe_dev->dma_chan_name, gbe_dev->tx_queue_id);
  3145. if (ret)
  3146. return ret;
  3147. ret = netcp_txpipe_open(&gbe_dev->tx_pipe);
  3148. if (ret)
  3149. return ret;
  3150. /* Create network interfaces */
  3151. INIT_LIST_HEAD(&gbe_dev->gbe_intf_head);
  3152. for_each_child_of_node(interfaces, interface) {
  3153. ret = of_property_read_u32(interface, "slave-port", &slave_num);
  3154. if (ret) {
  3155. dev_err(dev, "missing slave-port parameter, skipping interface configuration for %s\n",
  3156. interface->name);
  3157. continue;
  3158. }
  3159. gbe_dev->num_slaves++;
  3160. if (gbe_dev->num_slaves >= gbe_dev->max_num_slaves) {
  3161. of_node_put(interface);
  3162. break;
  3163. }
  3164. }
  3165. of_node_put(interfaces);
  3166. if (!gbe_dev->num_slaves)
  3167. dev_warn(dev, "No network interface configured\n");
  3168. /* Initialize Secondary slave ports */
  3169. secondary_ports = of_get_child_by_name(node, "secondary-slave-ports");
  3170. INIT_LIST_HEAD(&gbe_dev->secondary_slaves);
  3171. if (secondary_ports && (gbe_dev->num_slaves < gbe_dev->max_num_slaves))
  3172. init_secondary_ports(gbe_dev, secondary_ports);
  3173. of_node_put(secondary_ports);
  3174. if (!gbe_dev->num_slaves) {
  3175. dev_err(dev,
  3176. "No network interface or secondary ports configured\n");
  3177. ret = -ENODEV;
  3178. goto free_sec_ports;
  3179. }
  3180. memset(&ale_params, 0, sizeof(ale_params));
  3181. ale_params.dev = gbe_dev->dev;
  3182. ale_params.ale_regs = gbe_dev->ale_reg;
  3183. ale_params.ale_ageout = GBE_DEFAULT_ALE_AGEOUT;
  3184. ale_params.ale_entries = gbe_dev->ale_entries;
  3185. ale_params.ale_ports = gbe_dev->ale_ports;
  3186. if (IS_SS_ID_MU(gbe_dev)) {
  3187. ale_params.major_ver_mask = 0x7;
  3188. ale_params.nu_switch_ale = true;
  3189. }
  3190. gbe_dev->ale = cpsw_ale_create(&ale_params);
  3191. if (!gbe_dev->ale) {
  3192. dev_err(gbe_dev->dev, "error initializing ale engine\n");
  3193. ret = -ENODEV;
  3194. goto free_sec_ports;
  3195. } else {
  3196. dev_dbg(gbe_dev->dev, "Created a gbe ale engine\n");
  3197. }
  3198. gbe_dev->cpts = cpts_create(gbe_dev->dev, gbe_dev->cpts_reg, node);
  3199. if (IS_ENABLED(CONFIG_TI_CPTS) && IS_ERR(gbe_dev->cpts)) {
  3200. ret = PTR_ERR(gbe_dev->cpts);
  3201. goto free_sec_ports;
  3202. }
  3203. /* initialize host port */
  3204. gbe_init_host_port(gbe_dev);
  3205. spin_lock_bh(&gbe_dev->hw_stats_lock);
  3206. for (i = 0; i < gbe_dev->num_stats_mods; i++) {
  3207. if (gbe_dev->ss_version == GBE_SS_VERSION_14)
  3208. gbe_reset_mod_stats_ver14(gbe_dev, i);
  3209. else
  3210. gbe_reset_mod_stats(gbe_dev, i);
  3211. }
  3212. spin_unlock_bh(&gbe_dev->hw_stats_lock);
  3213. init_timer(&gbe_dev->timer);
  3214. gbe_dev->timer.data = (unsigned long)gbe_dev;
  3215. gbe_dev->timer.function = netcp_ethss_timer;
  3216. gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL;
  3217. add_timer(&gbe_dev->timer);
  3218. *inst_priv = gbe_dev;
  3219. return 0;
  3220. free_sec_ports:
  3221. free_secondary_ports(gbe_dev);
  3222. return ret;
  3223. }
  3224. static int gbe_attach(void *inst_priv, struct net_device *ndev,
  3225. struct device_node *node, void **intf_priv)
  3226. {
  3227. struct gbe_priv *gbe_dev = inst_priv;
  3228. struct gbe_intf *gbe_intf;
  3229. int ret;
  3230. if (!node) {
  3231. dev_err(gbe_dev->dev, "interface node not available\n");
  3232. return -ENODEV;
  3233. }
  3234. gbe_intf = devm_kzalloc(gbe_dev->dev, sizeof(*gbe_intf), GFP_KERNEL);
  3235. if (!gbe_intf)
  3236. return -ENOMEM;
  3237. gbe_intf->ndev = ndev;
  3238. gbe_intf->dev = gbe_dev->dev;
  3239. gbe_intf->gbe_dev = gbe_dev;
  3240. gbe_intf->slave = devm_kzalloc(gbe_dev->dev,
  3241. sizeof(*gbe_intf->slave),
  3242. GFP_KERNEL);
  3243. if (!gbe_intf->slave) {
  3244. ret = -ENOMEM;
  3245. goto fail;
  3246. }
  3247. if (init_slave(gbe_dev, gbe_intf->slave, node)) {
  3248. ret = -ENODEV;
  3249. goto fail;
  3250. }
  3251. gbe_intf->tx_pipe = gbe_dev->tx_pipe;
  3252. ndev->ethtool_ops = &keystone_ethtool_ops;
  3253. list_add_tail(&gbe_intf->gbe_intf_list, &gbe_dev->gbe_intf_head);
  3254. *intf_priv = gbe_intf;
  3255. return 0;
  3256. fail:
  3257. if (gbe_intf->slave)
  3258. devm_kfree(gbe_dev->dev, gbe_intf->slave);
  3259. if (gbe_intf)
  3260. devm_kfree(gbe_dev->dev, gbe_intf);
  3261. return ret;
  3262. }
  3263. static int gbe_release(void *intf_priv)
  3264. {
  3265. struct gbe_intf *gbe_intf = intf_priv;
  3266. gbe_intf->ndev->ethtool_ops = NULL;
  3267. list_del(&gbe_intf->gbe_intf_list);
  3268. devm_kfree(gbe_intf->dev, gbe_intf->slave);
  3269. devm_kfree(gbe_intf->dev, gbe_intf);
  3270. return 0;
  3271. }
  3272. static int gbe_remove(struct netcp_device *netcp_device, void *inst_priv)
  3273. {
  3274. struct gbe_priv *gbe_dev = inst_priv;
  3275. del_timer_sync(&gbe_dev->timer);
  3276. cpts_release(gbe_dev->cpts);
  3277. cpsw_ale_stop(gbe_dev->ale);
  3278. cpsw_ale_destroy(gbe_dev->ale);
  3279. netcp_txpipe_close(&gbe_dev->tx_pipe);
  3280. free_secondary_ports(gbe_dev);
  3281. if (!list_empty(&gbe_dev->gbe_intf_head))
  3282. dev_alert(gbe_dev->dev,
  3283. "unreleased ethss interfaces present\n");
  3284. return 0;
  3285. }
  3286. static struct netcp_module gbe_module = {
  3287. .name = GBE_MODULE_NAME,
  3288. .owner = THIS_MODULE,
  3289. .primary = true,
  3290. .probe = gbe_probe,
  3291. .open = gbe_open,
  3292. .close = gbe_close,
  3293. .remove = gbe_remove,
  3294. .attach = gbe_attach,
  3295. .release = gbe_release,
  3296. .add_addr = gbe_add_addr,
  3297. .del_addr = gbe_del_addr,
  3298. .add_vid = gbe_add_vid,
  3299. .del_vid = gbe_del_vid,
  3300. .ioctl = gbe_ioctl,
  3301. };
  3302. static struct netcp_module xgbe_module = {
  3303. .name = XGBE_MODULE_NAME,
  3304. .owner = THIS_MODULE,
  3305. .primary = true,
  3306. .probe = gbe_probe,
  3307. .open = gbe_open,
  3308. .close = gbe_close,
  3309. .remove = gbe_remove,
  3310. .attach = gbe_attach,
  3311. .release = gbe_release,
  3312. .add_addr = gbe_add_addr,
  3313. .del_addr = gbe_del_addr,
  3314. .add_vid = gbe_add_vid,
  3315. .del_vid = gbe_del_vid,
  3316. .ioctl = gbe_ioctl,
  3317. };
  3318. static int __init keystone_gbe_init(void)
  3319. {
  3320. int ret;
  3321. ret = netcp_register_module(&gbe_module);
  3322. if (ret)
  3323. return ret;
  3324. ret = netcp_register_module(&xgbe_module);
  3325. if (ret)
  3326. return ret;
  3327. return 0;
  3328. }
  3329. module_init(keystone_gbe_init);
  3330. static void __exit keystone_gbe_exit(void)
  3331. {
  3332. netcp_unregister_module(&gbe_module);
  3333. netcp_unregister_module(&xgbe_module);
  3334. }
  3335. module_exit(keystone_gbe_exit);
  3336. MODULE_LICENSE("GPL v2");
  3337. MODULE_DESCRIPTION("TI NETCP ETHSS driver for Keystone SOCs");
  3338. MODULE_AUTHOR("Sandeep Nair <sandeep_n@ti.com");