netcp_ethss.c 104 KB

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