netcp_ethss.c 106 KB

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