netcp_ethss.c 85 KB

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