b53_common.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163
  1. /*
  2. * B53 switch driver main logic
  3. *
  4. * Copyright (C) 2011-2013 Jonas Gorski <jogo@openwrt.org>
  5. * Copyright (C) 2016 Florian Fainelli <f.fainelli@gmail.com>
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/delay.h>
  21. #include <linux/export.h>
  22. #include <linux/gpio.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_data/b53.h>
  26. #include <linux/phy.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/if_bridge.h>
  29. #include <net/dsa.h>
  30. #include "b53_regs.h"
  31. #include "b53_priv.h"
  32. struct b53_mib_desc {
  33. u8 size;
  34. u8 offset;
  35. const char *name;
  36. };
  37. /* BCM5365 MIB counters */
  38. static const struct b53_mib_desc b53_mibs_65[] = {
  39. { 8, 0x00, "TxOctets" },
  40. { 4, 0x08, "TxDropPkts" },
  41. { 4, 0x10, "TxBroadcastPkts" },
  42. { 4, 0x14, "TxMulticastPkts" },
  43. { 4, 0x18, "TxUnicastPkts" },
  44. { 4, 0x1c, "TxCollisions" },
  45. { 4, 0x20, "TxSingleCollision" },
  46. { 4, 0x24, "TxMultipleCollision" },
  47. { 4, 0x28, "TxDeferredTransmit" },
  48. { 4, 0x2c, "TxLateCollision" },
  49. { 4, 0x30, "TxExcessiveCollision" },
  50. { 4, 0x38, "TxPausePkts" },
  51. { 8, 0x44, "RxOctets" },
  52. { 4, 0x4c, "RxUndersizePkts" },
  53. { 4, 0x50, "RxPausePkts" },
  54. { 4, 0x54, "Pkts64Octets" },
  55. { 4, 0x58, "Pkts65to127Octets" },
  56. { 4, 0x5c, "Pkts128to255Octets" },
  57. { 4, 0x60, "Pkts256to511Octets" },
  58. { 4, 0x64, "Pkts512to1023Octets" },
  59. { 4, 0x68, "Pkts1024to1522Octets" },
  60. { 4, 0x6c, "RxOversizePkts" },
  61. { 4, 0x70, "RxJabbers" },
  62. { 4, 0x74, "RxAlignmentErrors" },
  63. { 4, 0x78, "RxFCSErrors" },
  64. { 8, 0x7c, "RxGoodOctets" },
  65. { 4, 0x84, "RxDropPkts" },
  66. { 4, 0x88, "RxUnicastPkts" },
  67. { 4, 0x8c, "RxMulticastPkts" },
  68. { 4, 0x90, "RxBroadcastPkts" },
  69. { 4, 0x94, "RxSAChanges" },
  70. { 4, 0x98, "RxFragments" },
  71. };
  72. #define B53_MIBS_65_SIZE ARRAY_SIZE(b53_mibs_65)
  73. /* BCM63xx MIB counters */
  74. static const struct b53_mib_desc b53_mibs_63xx[] = {
  75. { 8, 0x00, "TxOctets" },
  76. { 4, 0x08, "TxDropPkts" },
  77. { 4, 0x0c, "TxQoSPkts" },
  78. { 4, 0x10, "TxBroadcastPkts" },
  79. { 4, 0x14, "TxMulticastPkts" },
  80. { 4, 0x18, "TxUnicastPkts" },
  81. { 4, 0x1c, "TxCollisions" },
  82. { 4, 0x20, "TxSingleCollision" },
  83. { 4, 0x24, "TxMultipleCollision" },
  84. { 4, 0x28, "TxDeferredTransmit" },
  85. { 4, 0x2c, "TxLateCollision" },
  86. { 4, 0x30, "TxExcessiveCollision" },
  87. { 4, 0x38, "TxPausePkts" },
  88. { 8, 0x3c, "TxQoSOctets" },
  89. { 8, 0x44, "RxOctets" },
  90. { 4, 0x4c, "RxUndersizePkts" },
  91. { 4, 0x50, "RxPausePkts" },
  92. { 4, 0x54, "Pkts64Octets" },
  93. { 4, 0x58, "Pkts65to127Octets" },
  94. { 4, 0x5c, "Pkts128to255Octets" },
  95. { 4, 0x60, "Pkts256to511Octets" },
  96. { 4, 0x64, "Pkts512to1023Octets" },
  97. { 4, 0x68, "Pkts1024to1522Octets" },
  98. { 4, 0x6c, "RxOversizePkts" },
  99. { 4, 0x70, "RxJabbers" },
  100. { 4, 0x74, "RxAlignmentErrors" },
  101. { 4, 0x78, "RxFCSErrors" },
  102. { 8, 0x7c, "RxGoodOctets" },
  103. { 4, 0x84, "RxDropPkts" },
  104. { 4, 0x88, "RxUnicastPkts" },
  105. { 4, 0x8c, "RxMulticastPkts" },
  106. { 4, 0x90, "RxBroadcastPkts" },
  107. { 4, 0x94, "RxSAChanges" },
  108. { 4, 0x98, "RxFragments" },
  109. { 4, 0xa0, "RxSymbolErrors" },
  110. { 4, 0xa4, "RxQoSPkts" },
  111. { 8, 0xa8, "RxQoSOctets" },
  112. { 4, 0xb0, "Pkts1523to2047Octets" },
  113. { 4, 0xb4, "Pkts2048to4095Octets" },
  114. { 4, 0xb8, "Pkts4096to8191Octets" },
  115. { 4, 0xbc, "Pkts8192to9728Octets" },
  116. { 4, 0xc0, "RxDiscarded" },
  117. };
  118. #define B53_MIBS_63XX_SIZE ARRAY_SIZE(b53_mibs_63xx)
  119. /* MIB counters */
  120. static const struct b53_mib_desc b53_mibs[] = {
  121. { 8, 0x00, "TxOctets" },
  122. { 4, 0x08, "TxDropPkts" },
  123. { 4, 0x10, "TxBroadcastPkts" },
  124. { 4, 0x14, "TxMulticastPkts" },
  125. { 4, 0x18, "TxUnicastPkts" },
  126. { 4, 0x1c, "TxCollisions" },
  127. { 4, 0x20, "TxSingleCollision" },
  128. { 4, 0x24, "TxMultipleCollision" },
  129. { 4, 0x28, "TxDeferredTransmit" },
  130. { 4, 0x2c, "TxLateCollision" },
  131. { 4, 0x30, "TxExcessiveCollision" },
  132. { 4, 0x38, "TxPausePkts" },
  133. { 8, 0x50, "RxOctets" },
  134. { 4, 0x58, "RxUndersizePkts" },
  135. { 4, 0x5c, "RxPausePkts" },
  136. { 4, 0x60, "Pkts64Octets" },
  137. { 4, 0x64, "Pkts65to127Octets" },
  138. { 4, 0x68, "Pkts128to255Octets" },
  139. { 4, 0x6c, "Pkts256to511Octets" },
  140. { 4, 0x70, "Pkts512to1023Octets" },
  141. { 4, 0x74, "Pkts1024to1522Octets" },
  142. { 4, 0x78, "RxOversizePkts" },
  143. { 4, 0x7c, "RxJabbers" },
  144. { 4, 0x80, "RxAlignmentErrors" },
  145. { 4, 0x84, "RxFCSErrors" },
  146. { 8, 0x88, "RxGoodOctets" },
  147. { 4, 0x90, "RxDropPkts" },
  148. { 4, 0x94, "RxUnicastPkts" },
  149. { 4, 0x98, "RxMulticastPkts" },
  150. { 4, 0x9c, "RxBroadcastPkts" },
  151. { 4, 0xa0, "RxSAChanges" },
  152. { 4, 0xa4, "RxFragments" },
  153. { 4, 0xa8, "RxJumboPkts" },
  154. { 4, 0xac, "RxSymbolErrors" },
  155. { 4, 0xc0, "RxDiscarded" },
  156. };
  157. #define B53_MIBS_SIZE ARRAY_SIZE(b53_mibs)
  158. static const struct b53_mib_desc b53_mibs_58xx[] = {
  159. { 8, 0x00, "TxOctets" },
  160. { 4, 0x08, "TxDropPkts" },
  161. { 4, 0x0c, "TxQPKTQ0" },
  162. { 4, 0x10, "TxBroadcastPkts" },
  163. { 4, 0x14, "TxMulticastPkts" },
  164. { 4, 0x18, "TxUnicastPKts" },
  165. { 4, 0x1c, "TxCollisions" },
  166. { 4, 0x20, "TxSingleCollision" },
  167. { 4, 0x24, "TxMultipleCollision" },
  168. { 4, 0x28, "TxDeferredCollision" },
  169. { 4, 0x2c, "TxLateCollision" },
  170. { 4, 0x30, "TxExcessiveCollision" },
  171. { 4, 0x34, "TxFrameInDisc" },
  172. { 4, 0x38, "TxPausePkts" },
  173. { 4, 0x3c, "TxQPKTQ1" },
  174. { 4, 0x40, "TxQPKTQ2" },
  175. { 4, 0x44, "TxQPKTQ3" },
  176. { 4, 0x48, "TxQPKTQ4" },
  177. { 4, 0x4c, "TxQPKTQ5" },
  178. { 8, 0x50, "RxOctets" },
  179. { 4, 0x58, "RxUndersizePkts" },
  180. { 4, 0x5c, "RxPausePkts" },
  181. { 4, 0x60, "RxPkts64Octets" },
  182. { 4, 0x64, "RxPkts65to127Octets" },
  183. { 4, 0x68, "RxPkts128to255Octets" },
  184. { 4, 0x6c, "RxPkts256to511Octets" },
  185. { 4, 0x70, "RxPkts512to1023Octets" },
  186. { 4, 0x74, "RxPkts1024toMaxPktsOctets" },
  187. { 4, 0x78, "RxOversizePkts" },
  188. { 4, 0x7c, "RxJabbers" },
  189. { 4, 0x80, "RxAlignmentErrors" },
  190. { 4, 0x84, "RxFCSErrors" },
  191. { 8, 0x88, "RxGoodOctets" },
  192. { 4, 0x90, "RxDropPkts" },
  193. { 4, 0x94, "RxUnicastPkts" },
  194. { 4, 0x98, "RxMulticastPkts" },
  195. { 4, 0x9c, "RxBroadcastPkts" },
  196. { 4, 0xa0, "RxSAChanges" },
  197. { 4, 0xa4, "RxFragments" },
  198. { 4, 0xa8, "RxJumboPkt" },
  199. { 4, 0xac, "RxSymblErr" },
  200. { 4, 0xb0, "InRangeErrCount" },
  201. { 4, 0xb4, "OutRangeErrCount" },
  202. { 4, 0xb8, "EEELpiEvent" },
  203. { 4, 0xbc, "EEELpiDuration" },
  204. { 4, 0xc0, "RxDiscard" },
  205. { 4, 0xc8, "TxQPKTQ6" },
  206. { 4, 0xcc, "TxQPKTQ7" },
  207. { 4, 0xd0, "TxPkts64Octets" },
  208. { 4, 0xd4, "TxPkts65to127Octets" },
  209. { 4, 0xd8, "TxPkts128to255Octets" },
  210. { 4, 0xdc, "TxPkts256to511Ocets" },
  211. { 4, 0xe0, "TxPkts512to1023Ocets" },
  212. { 4, 0xe4, "TxPkts1024toMaxPktOcets" },
  213. };
  214. #define B53_MIBS_58XX_SIZE ARRAY_SIZE(b53_mibs_58xx)
  215. static int b53_do_vlan_op(struct b53_device *dev, u8 op)
  216. {
  217. unsigned int i;
  218. b53_write8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], VTA_START_CMD | op);
  219. for (i = 0; i < 10; i++) {
  220. u8 vta;
  221. b53_read8(dev, B53_ARLIO_PAGE, dev->vta_regs[0], &vta);
  222. if (!(vta & VTA_START_CMD))
  223. return 0;
  224. usleep_range(100, 200);
  225. }
  226. return -EIO;
  227. }
  228. static void b53_set_vlan_entry(struct b53_device *dev, u16 vid,
  229. struct b53_vlan *vlan)
  230. {
  231. if (is5325(dev)) {
  232. u32 entry = 0;
  233. if (vlan->members) {
  234. entry = ((vlan->untag & VA_UNTAG_MASK_25) <<
  235. VA_UNTAG_S_25) | vlan->members;
  236. if (dev->core_rev >= 3)
  237. entry |= VA_VALID_25_R4 | vid << VA_VID_HIGH_S;
  238. else
  239. entry |= VA_VALID_25;
  240. }
  241. b53_write32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, entry);
  242. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
  243. VTA_RW_STATE_WR | VTA_RW_OP_EN);
  244. } else if (is5365(dev)) {
  245. u16 entry = 0;
  246. if (vlan->members)
  247. entry = ((vlan->untag & VA_UNTAG_MASK_65) <<
  248. VA_UNTAG_S_65) | vlan->members | VA_VALID_65;
  249. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, entry);
  250. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
  251. VTA_RW_STATE_WR | VTA_RW_OP_EN);
  252. } else {
  253. b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
  254. b53_write32(dev, B53_ARLIO_PAGE, dev->vta_regs[2],
  255. (vlan->untag << VTE_UNTAG_S) | vlan->members);
  256. b53_do_vlan_op(dev, VTA_CMD_WRITE);
  257. }
  258. dev_dbg(dev->ds->dev, "VID: %d, members: 0x%04x, untag: 0x%04x\n",
  259. vid, vlan->members, vlan->untag);
  260. }
  261. static void b53_get_vlan_entry(struct b53_device *dev, u16 vid,
  262. struct b53_vlan *vlan)
  263. {
  264. if (is5325(dev)) {
  265. u32 entry = 0;
  266. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, vid |
  267. VTA_RW_STATE_RD | VTA_RW_OP_EN);
  268. b53_read32(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_25, &entry);
  269. if (dev->core_rev >= 3)
  270. vlan->valid = !!(entry & VA_VALID_25_R4);
  271. else
  272. vlan->valid = !!(entry & VA_VALID_25);
  273. vlan->members = entry & VA_MEMBER_MASK;
  274. vlan->untag = (entry >> VA_UNTAG_S_25) & VA_UNTAG_MASK_25;
  275. } else if (is5365(dev)) {
  276. u16 entry = 0;
  277. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_65, vid |
  278. VTA_RW_STATE_WR | VTA_RW_OP_EN);
  279. b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_WRITE_65, &entry);
  280. vlan->valid = !!(entry & VA_VALID_65);
  281. vlan->members = entry & VA_MEMBER_MASK;
  282. vlan->untag = (entry >> VA_UNTAG_S_65) & VA_UNTAG_MASK_65;
  283. } else {
  284. u32 entry = 0;
  285. b53_write16(dev, B53_ARLIO_PAGE, dev->vta_regs[1], vid);
  286. b53_do_vlan_op(dev, VTA_CMD_READ);
  287. b53_read32(dev, B53_ARLIO_PAGE, dev->vta_regs[2], &entry);
  288. vlan->members = entry & VTE_MEMBERS;
  289. vlan->untag = (entry >> VTE_UNTAG_S) & VTE_MEMBERS;
  290. vlan->valid = true;
  291. }
  292. }
  293. static void b53_set_forwarding(struct b53_device *dev, int enable)
  294. {
  295. u8 mgmt;
  296. b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
  297. if (enable)
  298. mgmt |= SM_SW_FWD_EN;
  299. else
  300. mgmt &= ~SM_SW_FWD_EN;
  301. b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
  302. /* Include IMP port in dumb forwarding mode
  303. */
  304. b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt);
  305. mgmt |= B53_MII_DUMB_FWDG_EN;
  306. b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
  307. }
  308. static void b53_enable_vlan(struct b53_device *dev, bool enable)
  309. {
  310. u8 mgmt, vc0, vc1, vc4 = 0, vc5;
  311. b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
  312. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, &vc0);
  313. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, &vc1);
  314. if (is5325(dev) || is5365(dev)) {
  315. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
  316. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, &vc5);
  317. } else if (is63xx(dev)) {
  318. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, &vc4);
  319. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, &vc5);
  320. } else {
  321. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, &vc4);
  322. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, &vc5);
  323. }
  324. mgmt &= ~SM_SW_FWD_MODE;
  325. if (enable) {
  326. vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID;
  327. vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN;
  328. vc4 &= ~VC4_ING_VID_CHECK_MASK;
  329. vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S;
  330. vc5 |= VC5_DROP_VTABLE_MISS;
  331. if (is5325(dev))
  332. vc0 &= ~VC0_RESERVED_1;
  333. if (is5325(dev) || is5365(dev))
  334. vc1 |= VC1_RX_MCST_TAG_EN;
  335. } else {
  336. vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID);
  337. vc1 &= ~(VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN);
  338. vc4 &= ~VC4_ING_VID_CHECK_MASK;
  339. vc5 &= ~VC5_DROP_VTABLE_MISS;
  340. if (is5325(dev) || is5365(dev))
  341. vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S;
  342. else
  343. vc4 |= VC4_ING_VID_VIO_TO_IMP << VC4_ING_VID_CHECK_S;
  344. if (is5325(dev) || is5365(dev))
  345. vc1 &= ~VC1_RX_MCST_TAG_EN;
  346. }
  347. if (!is5325(dev) && !is5365(dev))
  348. vc5 &= ~VC5_VID_FFF_EN;
  349. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL0, vc0);
  350. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL1, vc1);
  351. if (is5325(dev) || is5365(dev)) {
  352. /* enable the high 8 bit vid check on 5325 */
  353. if (is5325(dev) && enable)
  354. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3,
  355. VC3_HIGH_8BIT_EN);
  356. else
  357. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0);
  358. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, vc4);
  359. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_25, vc5);
  360. } else if (is63xx(dev)) {
  361. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3_63XX, 0);
  362. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_63XX, vc4);
  363. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5_63XX, vc5);
  364. } else {
  365. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_CTRL3, 0);
  366. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4, vc4);
  367. b53_write8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL5, vc5);
  368. }
  369. b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
  370. }
  371. static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100)
  372. {
  373. u32 port_mask = 0;
  374. u16 max_size = JMS_MIN_SIZE;
  375. if (is5325(dev) || is5365(dev))
  376. return -EINVAL;
  377. if (enable) {
  378. port_mask = dev->enabled_ports;
  379. max_size = JMS_MAX_SIZE;
  380. if (allow_10_100)
  381. port_mask |= JPM_10_100_JUMBO_EN;
  382. }
  383. b53_write32(dev, B53_JUMBO_PAGE, dev->jumbo_pm_reg, port_mask);
  384. return b53_write16(dev, B53_JUMBO_PAGE, dev->jumbo_size_reg, max_size);
  385. }
  386. static int b53_flush_arl(struct b53_device *dev, u8 mask)
  387. {
  388. unsigned int i;
  389. b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
  390. FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask);
  391. for (i = 0; i < 10; i++) {
  392. u8 fast_age_ctrl;
  393. b53_read8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
  394. &fast_age_ctrl);
  395. if (!(fast_age_ctrl & FAST_AGE_DONE))
  396. goto out;
  397. msleep(1);
  398. }
  399. return -ETIMEDOUT;
  400. out:
  401. /* Only age dynamic entries (default behavior) */
  402. b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL, FAST_AGE_DYNAMIC);
  403. return 0;
  404. }
  405. static int b53_fast_age_port(struct b53_device *dev, int port)
  406. {
  407. b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port);
  408. return b53_flush_arl(dev, FAST_AGE_PORT);
  409. }
  410. static int b53_fast_age_vlan(struct b53_device *dev, u16 vid)
  411. {
  412. b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid);
  413. return b53_flush_arl(dev, FAST_AGE_VLAN);
  414. }
  415. void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
  416. {
  417. struct b53_device *dev = ds->priv;
  418. unsigned int i;
  419. u16 pvlan;
  420. /* Enable the IMP port to be in the same VLAN as the other ports
  421. * on a per-port basis such that we only have Port i and IMP in
  422. * the same VLAN.
  423. */
  424. b53_for_each_port(dev, i) {
  425. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &pvlan);
  426. pvlan |= BIT(cpu_port);
  427. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan);
  428. }
  429. }
  430. EXPORT_SYMBOL(b53_imp_vlan_setup);
  431. int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
  432. {
  433. struct b53_device *dev = ds->priv;
  434. unsigned int cpu_port = ds->ports[port].cpu_dp->index;
  435. u16 pvlan;
  436. /* Clear the Rx and Tx disable bits and set to no spanning tree */
  437. b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), 0);
  438. /* Set this port, and only this one to be in the default VLAN,
  439. * if member of a bridge, restore its membership prior to
  440. * bringing down this port.
  441. */
  442. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
  443. pvlan &= ~0x1ff;
  444. pvlan |= BIT(port);
  445. pvlan |= dev->ports[port].vlan_ctl_mask;
  446. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
  447. b53_imp_vlan_setup(ds, cpu_port);
  448. /* If EEE was enabled, restore it */
  449. if (dev->ports[port].eee.eee_enabled)
  450. b53_eee_enable_set(ds, port, true);
  451. return 0;
  452. }
  453. EXPORT_SYMBOL(b53_enable_port);
  454. void b53_disable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
  455. {
  456. struct b53_device *dev = ds->priv;
  457. u8 reg;
  458. /* Disable Tx/Rx for the port */
  459. b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
  460. reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE;
  461. b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
  462. }
  463. EXPORT_SYMBOL(b53_disable_port);
  464. void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
  465. {
  466. bool tag_en = !(ds->ops->get_tag_protocol(ds, port) ==
  467. DSA_TAG_PROTO_NONE);
  468. struct b53_device *dev = ds->priv;
  469. u8 hdr_ctl, val;
  470. u16 reg;
  471. /* Resolve which bit controls the Broadcom tag */
  472. switch (port) {
  473. case 8:
  474. val = BRCM_HDR_P8_EN;
  475. break;
  476. case 7:
  477. val = BRCM_HDR_P7_EN;
  478. break;
  479. case 5:
  480. val = BRCM_HDR_P5_EN;
  481. break;
  482. default:
  483. val = 0;
  484. break;
  485. }
  486. /* Enable Broadcom tags for IMP port */
  487. b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl);
  488. if (tag_en)
  489. hdr_ctl |= val;
  490. else
  491. hdr_ctl &= ~val;
  492. b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl);
  493. /* Registers below are only accessible on newer devices */
  494. if (!is58xx(dev))
  495. return;
  496. /* Enable reception Broadcom tag for CPU TX (switch RX) to
  497. * allow us to tag outgoing frames
  498. */
  499. b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, &reg);
  500. if (tag_en)
  501. reg &= ~BIT(port);
  502. else
  503. reg |= BIT(port);
  504. b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg);
  505. /* Enable transmission of Broadcom tags from the switch (CPU RX) to
  506. * allow delivering frames to the per-port net_devices
  507. */
  508. b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, &reg);
  509. if (tag_en)
  510. reg &= ~BIT(port);
  511. else
  512. reg |= BIT(port);
  513. b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg);
  514. }
  515. EXPORT_SYMBOL(b53_brcm_hdr_setup);
  516. static void b53_enable_cpu_port(struct b53_device *dev, int port)
  517. {
  518. u8 port_ctrl;
  519. /* BCM5325 CPU port is at 8 */
  520. if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25)
  521. port = B53_CPU_PORT;
  522. port_ctrl = PORT_CTRL_RX_BCST_EN |
  523. PORT_CTRL_RX_MCST_EN |
  524. PORT_CTRL_RX_UCST_EN;
  525. b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl);
  526. b53_brcm_hdr_setup(dev->ds, port);
  527. }
  528. static void b53_enable_mib(struct b53_device *dev)
  529. {
  530. u8 gc;
  531. b53_read8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
  532. gc &= ~(GC_RESET_MIB | GC_MIB_AC_EN);
  533. b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc);
  534. }
  535. int b53_configure_vlan(struct dsa_switch *ds)
  536. {
  537. struct b53_device *dev = ds->priv;
  538. struct b53_vlan vl = { 0 };
  539. int i;
  540. /* clear all vlan entries */
  541. if (is5325(dev) || is5365(dev)) {
  542. for (i = 1; i < dev->num_vlans; i++)
  543. b53_set_vlan_entry(dev, i, &vl);
  544. } else {
  545. b53_do_vlan_op(dev, VTA_CMD_CLEAR);
  546. }
  547. b53_enable_vlan(dev, false);
  548. b53_for_each_port(dev, i)
  549. b53_write16(dev, B53_VLAN_PAGE,
  550. B53_VLAN_PORT_DEF_TAG(i), 1);
  551. if (!is5325(dev) && !is5365(dev))
  552. b53_set_jumbo(dev, dev->enable_jumbo, false);
  553. return 0;
  554. }
  555. EXPORT_SYMBOL(b53_configure_vlan);
  556. static void b53_switch_reset_gpio(struct b53_device *dev)
  557. {
  558. int gpio = dev->reset_gpio;
  559. if (gpio < 0)
  560. return;
  561. /* Reset sequence: RESET low(50ms)->high(20ms)
  562. */
  563. gpio_set_value(gpio, 0);
  564. mdelay(50);
  565. gpio_set_value(gpio, 1);
  566. mdelay(20);
  567. dev->current_page = 0xff;
  568. }
  569. static int b53_switch_reset(struct b53_device *dev)
  570. {
  571. unsigned int timeout = 1000;
  572. u8 mgmt, reg;
  573. b53_switch_reset_gpio(dev);
  574. if (is539x(dev)) {
  575. b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83);
  576. b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00);
  577. }
  578. /* This is specific to 58xx devices here, do not use is58xx() which
  579. * covers the larger Starfigther 2 family, including 7445/7278 which
  580. * still use this driver as a library and need to perform the reset
  581. * earlier.
  582. */
  583. if (dev->chip_id == BCM58XX_DEVICE_ID) {
  584. b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg);
  585. reg |= SW_RST | EN_SW_RST | EN_CH_RST;
  586. b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg);
  587. do {
  588. b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg);
  589. if (!(reg & SW_RST))
  590. break;
  591. usleep_range(1000, 2000);
  592. } while (timeout-- > 0);
  593. if (timeout == 0)
  594. return -ETIMEDOUT;
  595. }
  596. b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
  597. if (!(mgmt & SM_SW_FWD_EN)) {
  598. mgmt &= ~SM_SW_FWD_MODE;
  599. mgmt |= SM_SW_FWD_EN;
  600. b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
  601. b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
  602. if (!(mgmt & SM_SW_FWD_EN)) {
  603. dev_err(dev->dev, "Failed to enable switch!\n");
  604. return -EINVAL;
  605. }
  606. }
  607. b53_enable_mib(dev);
  608. return b53_flush_arl(dev, FAST_AGE_STATIC);
  609. }
  610. static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg)
  611. {
  612. struct b53_device *priv = ds->priv;
  613. u16 value = 0;
  614. int ret;
  615. if (priv->ops->phy_read16)
  616. ret = priv->ops->phy_read16(priv, addr, reg, &value);
  617. else
  618. ret = b53_read16(priv, B53_PORT_MII_PAGE(addr),
  619. reg * 2, &value);
  620. return ret ? ret : value;
  621. }
  622. static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
  623. {
  624. struct b53_device *priv = ds->priv;
  625. if (priv->ops->phy_write16)
  626. return priv->ops->phy_write16(priv, addr, reg, val);
  627. return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val);
  628. }
  629. static int b53_reset_switch(struct b53_device *priv)
  630. {
  631. /* reset vlans */
  632. priv->enable_jumbo = false;
  633. memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans);
  634. memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports);
  635. return b53_switch_reset(priv);
  636. }
  637. static int b53_apply_config(struct b53_device *priv)
  638. {
  639. /* disable switching */
  640. b53_set_forwarding(priv, 0);
  641. b53_configure_vlan(priv->ds);
  642. /* enable switching */
  643. b53_set_forwarding(priv, 1);
  644. return 0;
  645. }
  646. static void b53_reset_mib(struct b53_device *priv)
  647. {
  648. u8 gc;
  649. b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
  650. b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB);
  651. msleep(1);
  652. b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB);
  653. msleep(1);
  654. }
  655. static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev)
  656. {
  657. if (is5365(dev))
  658. return b53_mibs_65;
  659. else if (is63xx(dev))
  660. return b53_mibs_63xx;
  661. else if (is58xx(dev))
  662. return b53_mibs_58xx;
  663. else
  664. return b53_mibs;
  665. }
  666. static unsigned int b53_get_mib_size(struct b53_device *dev)
  667. {
  668. if (is5365(dev))
  669. return B53_MIBS_65_SIZE;
  670. else if (is63xx(dev))
  671. return B53_MIBS_63XX_SIZE;
  672. else if (is58xx(dev))
  673. return B53_MIBS_58XX_SIZE;
  674. else
  675. return B53_MIBS_SIZE;
  676. }
  677. static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port)
  678. {
  679. /* These ports typically do not have built-in PHYs */
  680. switch (port) {
  681. case B53_CPU_PORT_25:
  682. case 7:
  683. case B53_CPU_PORT:
  684. return NULL;
  685. }
  686. return mdiobus_get_phy(ds->slave_mii_bus, port);
  687. }
  688. void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
  689. uint8_t *data)
  690. {
  691. struct b53_device *dev = ds->priv;
  692. const struct b53_mib_desc *mibs = b53_get_mib(dev);
  693. unsigned int mib_size = b53_get_mib_size(dev);
  694. struct phy_device *phydev;
  695. unsigned int i;
  696. if (stringset == ETH_SS_STATS) {
  697. for (i = 0; i < mib_size; i++)
  698. strlcpy(data + i * ETH_GSTRING_LEN,
  699. mibs[i].name, ETH_GSTRING_LEN);
  700. } else if (stringset == ETH_SS_PHY_STATS) {
  701. phydev = b53_get_phy_device(ds, port);
  702. if (!phydev)
  703. return;
  704. phy_ethtool_get_strings(phydev, data);
  705. }
  706. }
  707. EXPORT_SYMBOL(b53_get_strings);
  708. void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data)
  709. {
  710. struct b53_device *dev = ds->priv;
  711. const struct b53_mib_desc *mibs = b53_get_mib(dev);
  712. unsigned int mib_size = b53_get_mib_size(dev);
  713. const struct b53_mib_desc *s;
  714. unsigned int i;
  715. u64 val = 0;
  716. if (is5365(dev) && port == 5)
  717. port = 8;
  718. mutex_lock(&dev->stats_mutex);
  719. for (i = 0; i < mib_size; i++) {
  720. s = &mibs[i];
  721. if (s->size == 8) {
  722. b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val);
  723. } else {
  724. u32 val32;
  725. b53_read32(dev, B53_MIB_PAGE(port), s->offset,
  726. &val32);
  727. val = val32;
  728. }
  729. data[i] = (u64)val;
  730. }
  731. mutex_unlock(&dev->stats_mutex);
  732. }
  733. EXPORT_SYMBOL(b53_get_ethtool_stats);
  734. void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data)
  735. {
  736. struct phy_device *phydev;
  737. phydev = b53_get_phy_device(ds, port);
  738. if (!phydev)
  739. return;
  740. phy_ethtool_get_stats(phydev, NULL, data);
  741. }
  742. EXPORT_SYMBOL(b53_get_ethtool_phy_stats);
  743. int b53_get_sset_count(struct dsa_switch *ds, int port, int sset)
  744. {
  745. struct b53_device *dev = ds->priv;
  746. struct phy_device *phydev;
  747. if (sset == ETH_SS_STATS) {
  748. return b53_get_mib_size(dev);
  749. } else if (sset == ETH_SS_PHY_STATS) {
  750. phydev = b53_get_phy_device(ds, port);
  751. if (!phydev)
  752. return 0;
  753. return phy_ethtool_get_sset_count(phydev);
  754. }
  755. return 0;
  756. }
  757. EXPORT_SYMBOL(b53_get_sset_count);
  758. static int b53_setup(struct dsa_switch *ds)
  759. {
  760. struct b53_device *dev = ds->priv;
  761. unsigned int port;
  762. int ret;
  763. ret = b53_reset_switch(dev);
  764. if (ret) {
  765. dev_err(ds->dev, "failed to reset switch\n");
  766. return ret;
  767. }
  768. b53_reset_mib(dev);
  769. ret = b53_apply_config(dev);
  770. if (ret)
  771. dev_err(ds->dev, "failed to apply configuration\n");
  772. /* Configure IMP/CPU port, disable unused ports. Enabled
  773. * ports will be configured with .port_enable
  774. */
  775. for (port = 0; port < dev->num_ports; port++) {
  776. if (dsa_is_cpu_port(ds, port))
  777. b53_enable_cpu_port(dev, port);
  778. else if (dsa_is_unused_port(ds, port))
  779. b53_disable_port(ds, port, NULL);
  780. }
  781. return ret;
  782. }
  783. static void b53_adjust_link(struct dsa_switch *ds, int port,
  784. struct phy_device *phydev)
  785. {
  786. struct b53_device *dev = ds->priv;
  787. struct ethtool_eee *p = &dev->ports[port].eee;
  788. u8 rgmii_ctrl = 0, reg = 0, off;
  789. if (!phy_is_pseudo_fixed_link(phydev))
  790. return;
  791. /* Override the port settings */
  792. if (port == dev->cpu_port) {
  793. off = B53_PORT_OVERRIDE_CTRL;
  794. reg = PORT_OVERRIDE_EN;
  795. } else {
  796. off = B53_GMII_PORT_OVERRIDE_CTRL(port);
  797. reg = GMII_PO_EN;
  798. }
  799. /* Set the link UP */
  800. if (phydev->link)
  801. reg |= PORT_OVERRIDE_LINK;
  802. if (phydev->duplex == DUPLEX_FULL)
  803. reg |= PORT_OVERRIDE_FULL_DUPLEX;
  804. switch (phydev->speed) {
  805. case 2000:
  806. reg |= PORT_OVERRIDE_SPEED_2000M;
  807. /* fallthrough */
  808. case SPEED_1000:
  809. reg |= PORT_OVERRIDE_SPEED_1000M;
  810. break;
  811. case SPEED_100:
  812. reg |= PORT_OVERRIDE_SPEED_100M;
  813. break;
  814. case SPEED_10:
  815. reg |= PORT_OVERRIDE_SPEED_10M;
  816. break;
  817. default:
  818. dev_err(ds->dev, "unknown speed: %d\n", phydev->speed);
  819. return;
  820. }
  821. /* Enable flow control on BCM5301x's CPU port */
  822. if (is5301x(dev) && port == dev->cpu_port)
  823. reg |= PORT_OVERRIDE_RX_FLOW | PORT_OVERRIDE_TX_FLOW;
  824. if (phydev->pause) {
  825. if (phydev->asym_pause)
  826. reg |= PORT_OVERRIDE_TX_FLOW;
  827. reg |= PORT_OVERRIDE_RX_FLOW;
  828. }
  829. b53_write8(dev, B53_CTRL_PAGE, off, reg);
  830. if (is531x5(dev) && phy_interface_is_rgmii(phydev)) {
  831. if (port == 8)
  832. off = B53_RGMII_CTRL_IMP;
  833. else
  834. off = B53_RGMII_CTRL_P(port);
  835. /* Configure the port RGMII clock delay by DLL disabled and
  836. * tx_clk aligned timing (restoring to reset defaults)
  837. */
  838. b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl);
  839. rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC |
  840. RGMII_CTRL_TIMING_SEL);
  841. /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make
  842. * sure that we enable the port TX clock internal delay to
  843. * account for this internal delay that is inserted, otherwise
  844. * the switch won't be able to receive correctly.
  845. *
  846. * PHY_INTERFACE_MODE_RGMII means that we are not introducing
  847. * any delay neither on transmission nor reception, so the
  848. * BCM53125 must also be configured accordingly to account for
  849. * the lack of delay and introduce
  850. *
  851. * The BCM53125 switch has its RX clock and TX clock control
  852. * swapped, hence the reason why we modify the TX clock path in
  853. * the "RGMII" case
  854. */
  855. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
  856. rgmii_ctrl |= RGMII_CTRL_DLL_TXC;
  857. if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
  858. rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC;
  859. rgmii_ctrl |= RGMII_CTRL_TIMING_SEL;
  860. b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl);
  861. dev_info(ds->dev, "Configured port %d for %s\n", port,
  862. phy_modes(phydev->interface));
  863. }
  864. /* configure MII port if necessary */
  865. if (is5325(dev)) {
  866. b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
  867. &reg);
  868. /* reverse mii needs to be enabled */
  869. if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
  870. b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
  871. reg | PORT_OVERRIDE_RV_MII_25);
  872. b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
  873. &reg);
  874. if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
  875. dev_err(ds->dev,
  876. "Failed to enable reverse MII mode\n");
  877. return;
  878. }
  879. }
  880. } else if (is5301x(dev)) {
  881. if (port != dev->cpu_port) {
  882. u8 po_reg = B53_GMII_PORT_OVERRIDE_CTRL(dev->cpu_port);
  883. u8 gmii_po;
  884. b53_read8(dev, B53_CTRL_PAGE, po_reg, &gmii_po);
  885. gmii_po |= GMII_PO_LINK |
  886. GMII_PO_RX_FLOW |
  887. GMII_PO_TX_FLOW |
  888. GMII_PO_EN |
  889. GMII_PO_SPEED_2000M;
  890. b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po);
  891. }
  892. }
  893. /* Re-negotiate EEE if it was enabled already */
  894. p->eee_enabled = b53_eee_init(ds, port, phydev);
  895. }
  896. int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
  897. {
  898. return 0;
  899. }
  900. EXPORT_SYMBOL(b53_vlan_filtering);
  901. int b53_vlan_prepare(struct dsa_switch *ds, int port,
  902. const struct switchdev_obj_port_vlan *vlan)
  903. {
  904. struct b53_device *dev = ds->priv;
  905. if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0)
  906. return -EOPNOTSUPP;
  907. if (vlan->vid_end > dev->num_vlans)
  908. return -ERANGE;
  909. b53_enable_vlan(dev, true);
  910. return 0;
  911. }
  912. EXPORT_SYMBOL(b53_vlan_prepare);
  913. void b53_vlan_add(struct dsa_switch *ds, int port,
  914. const struct switchdev_obj_port_vlan *vlan)
  915. {
  916. struct b53_device *dev = ds->priv;
  917. bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
  918. bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
  919. struct b53_vlan *vl;
  920. u16 vid;
  921. for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
  922. vl = &dev->vlans[vid];
  923. b53_get_vlan_entry(dev, vid, vl);
  924. vl->members |= BIT(port);
  925. if (untagged)
  926. vl->untag |= BIT(port);
  927. else
  928. vl->untag &= ~BIT(port);
  929. b53_set_vlan_entry(dev, vid, vl);
  930. b53_fast_age_vlan(dev, vid);
  931. }
  932. if (pvid) {
  933. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
  934. vlan->vid_end);
  935. b53_fast_age_vlan(dev, vid);
  936. }
  937. }
  938. EXPORT_SYMBOL(b53_vlan_add);
  939. int b53_vlan_del(struct dsa_switch *ds, int port,
  940. const struct switchdev_obj_port_vlan *vlan)
  941. {
  942. struct b53_device *dev = ds->priv;
  943. bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
  944. struct b53_vlan *vl;
  945. u16 vid;
  946. u16 pvid;
  947. b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
  948. for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
  949. vl = &dev->vlans[vid];
  950. b53_get_vlan_entry(dev, vid, vl);
  951. vl->members &= ~BIT(port);
  952. if (pvid == vid) {
  953. if (is5325(dev) || is5365(dev))
  954. pvid = 1;
  955. else
  956. pvid = 0;
  957. }
  958. if (untagged)
  959. vl->untag &= ~(BIT(port));
  960. b53_set_vlan_entry(dev, vid, vl);
  961. b53_fast_age_vlan(dev, vid);
  962. }
  963. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid);
  964. b53_fast_age_vlan(dev, pvid);
  965. return 0;
  966. }
  967. EXPORT_SYMBOL(b53_vlan_del);
  968. /* Address Resolution Logic routines */
  969. static int b53_arl_op_wait(struct b53_device *dev)
  970. {
  971. unsigned int timeout = 10;
  972. u8 reg;
  973. do {
  974. b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg);
  975. if (!(reg & ARLTBL_START_DONE))
  976. return 0;
  977. usleep_range(1000, 2000);
  978. } while (timeout--);
  979. dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg);
  980. return -ETIMEDOUT;
  981. }
  982. static int b53_arl_rw_op(struct b53_device *dev, unsigned int op)
  983. {
  984. u8 reg;
  985. if (op > ARLTBL_RW)
  986. return -EINVAL;
  987. b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg);
  988. reg |= ARLTBL_START_DONE;
  989. if (op)
  990. reg |= ARLTBL_RW;
  991. else
  992. reg &= ~ARLTBL_RW;
  993. b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg);
  994. return b53_arl_op_wait(dev);
  995. }
  996. static int b53_arl_read(struct b53_device *dev, u64 mac,
  997. u16 vid, struct b53_arl_entry *ent, u8 *idx,
  998. bool is_valid)
  999. {
  1000. unsigned int i;
  1001. int ret;
  1002. ret = b53_arl_op_wait(dev);
  1003. if (ret)
  1004. return ret;
  1005. /* Read the bins */
  1006. for (i = 0; i < dev->num_arl_entries; i++) {
  1007. u64 mac_vid;
  1008. u32 fwd_entry;
  1009. b53_read64(dev, B53_ARLIO_PAGE,
  1010. B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid);
  1011. b53_read32(dev, B53_ARLIO_PAGE,
  1012. B53_ARLTBL_DATA_ENTRY(i), &fwd_entry);
  1013. b53_arl_to_entry(ent, mac_vid, fwd_entry);
  1014. if (!(fwd_entry & ARLTBL_VALID))
  1015. continue;
  1016. if ((mac_vid & ARLTBL_MAC_MASK) != mac)
  1017. continue;
  1018. *idx = i;
  1019. }
  1020. return -ENOENT;
  1021. }
  1022. static int b53_arl_op(struct b53_device *dev, int op, int port,
  1023. const unsigned char *addr, u16 vid, bool is_valid)
  1024. {
  1025. struct b53_arl_entry ent;
  1026. u32 fwd_entry;
  1027. u64 mac, mac_vid = 0;
  1028. u8 idx = 0;
  1029. int ret;
  1030. /* Convert the array into a 64-bit MAC */
  1031. mac = ether_addr_to_u64(addr);
  1032. /* Perform a read for the given MAC and VID */
  1033. b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac);
  1034. b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
  1035. /* Issue a read operation for this MAC */
  1036. ret = b53_arl_rw_op(dev, 1);
  1037. if (ret)
  1038. return ret;
  1039. ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid);
  1040. /* If this is a read, just finish now */
  1041. if (op)
  1042. return ret;
  1043. /* We could not find a matching MAC, so reset to a new entry */
  1044. if (ret) {
  1045. fwd_entry = 0;
  1046. idx = 1;
  1047. }
  1048. memset(&ent, 0, sizeof(ent));
  1049. ent.port = port;
  1050. ent.is_valid = is_valid;
  1051. ent.vid = vid;
  1052. ent.is_static = true;
  1053. memcpy(ent.mac, addr, ETH_ALEN);
  1054. b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
  1055. b53_write64(dev, B53_ARLIO_PAGE,
  1056. B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid);
  1057. b53_write32(dev, B53_ARLIO_PAGE,
  1058. B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
  1059. return b53_arl_rw_op(dev, 0);
  1060. }
  1061. int b53_fdb_add(struct dsa_switch *ds, int port,
  1062. const unsigned char *addr, u16 vid)
  1063. {
  1064. struct b53_device *priv = ds->priv;
  1065. /* 5325 and 5365 require some more massaging, but could
  1066. * be supported eventually
  1067. */
  1068. if (is5325(priv) || is5365(priv))
  1069. return -EOPNOTSUPP;
  1070. return b53_arl_op(priv, 0, port, addr, vid, true);
  1071. }
  1072. EXPORT_SYMBOL(b53_fdb_add);
  1073. int b53_fdb_del(struct dsa_switch *ds, int port,
  1074. const unsigned char *addr, u16 vid)
  1075. {
  1076. struct b53_device *priv = ds->priv;
  1077. return b53_arl_op(priv, 0, port, addr, vid, false);
  1078. }
  1079. EXPORT_SYMBOL(b53_fdb_del);
  1080. static int b53_arl_search_wait(struct b53_device *dev)
  1081. {
  1082. unsigned int timeout = 1000;
  1083. u8 reg;
  1084. do {
  1085. b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, &reg);
  1086. if (!(reg & ARL_SRCH_STDN))
  1087. return 0;
  1088. if (reg & ARL_SRCH_VLID)
  1089. return 0;
  1090. usleep_range(1000, 2000);
  1091. } while (timeout--);
  1092. return -ETIMEDOUT;
  1093. }
  1094. static void b53_arl_search_rd(struct b53_device *dev, u8 idx,
  1095. struct b53_arl_entry *ent)
  1096. {
  1097. u64 mac_vid;
  1098. u32 fwd_entry;
  1099. b53_read64(dev, B53_ARLIO_PAGE,
  1100. B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid);
  1101. b53_read32(dev, B53_ARLIO_PAGE,
  1102. B53_ARL_SRCH_RSTL(idx), &fwd_entry);
  1103. b53_arl_to_entry(ent, mac_vid, fwd_entry);
  1104. }
  1105. static int b53_fdb_copy(int port, const struct b53_arl_entry *ent,
  1106. dsa_fdb_dump_cb_t *cb, void *data)
  1107. {
  1108. if (!ent->is_valid)
  1109. return 0;
  1110. if (port != ent->port)
  1111. return 0;
  1112. return cb(ent->mac, ent->vid, ent->is_static, data);
  1113. }
  1114. int b53_fdb_dump(struct dsa_switch *ds, int port,
  1115. dsa_fdb_dump_cb_t *cb, void *data)
  1116. {
  1117. struct b53_device *priv = ds->priv;
  1118. struct b53_arl_entry results[2];
  1119. unsigned int count = 0;
  1120. int ret;
  1121. u8 reg;
  1122. /* Start search operation */
  1123. reg = ARL_SRCH_STDN;
  1124. b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);
  1125. do {
  1126. ret = b53_arl_search_wait(priv);
  1127. if (ret)
  1128. return ret;
  1129. b53_arl_search_rd(priv, 0, &results[0]);
  1130. ret = b53_fdb_copy(port, &results[0], cb, data);
  1131. if (ret)
  1132. return ret;
  1133. if (priv->num_arl_entries > 2) {
  1134. b53_arl_search_rd(priv, 1, &results[1]);
  1135. ret = b53_fdb_copy(port, &results[1], cb, data);
  1136. if (ret)
  1137. return ret;
  1138. if (!results[0].is_valid && !results[1].is_valid)
  1139. break;
  1140. }
  1141. } while (count++ < 1024);
  1142. return 0;
  1143. }
  1144. EXPORT_SYMBOL(b53_fdb_dump);
  1145. int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
  1146. {
  1147. struct b53_device *dev = ds->priv;
  1148. s8 cpu_port = ds->ports[port].cpu_dp->index;
  1149. u16 pvlan, reg;
  1150. unsigned int i;
  1151. /* Make this port leave the all VLANs join since we will have proper
  1152. * VLAN entries from now on
  1153. */
  1154. if (is58xx(dev)) {
  1155. b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg);
  1156. reg &= ~BIT(port);
  1157. if ((reg & BIT(cpu_port)) == BIT(cpu_port))
  1158. reg &= ~BIT(cpu_port);
  1159. b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
  1160. }
  1161. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
  1162. b53_for_each_port(dev, i) {
  1163. if (dsa_to_port(ds, i)->bridge_dev != br)
  1164. continue;
  1165. /* Add this local port to the remote port VLAN control
  1166. * membership and update the remote port bitmask
  1167. */
  1168. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
  1169. reg |= BIT(port);
  1170. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
  1171. dev->ports[i].vlan_ctl_mask = reg;
  1172. pvlan |= BIT(i);
  1173. }
  1174. /* Configure the local port VLAN control membership to include
  1175. * remote ports and update the local port bitmask
  1176. */
  1177. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
  1178. dev->ports[port].vlan_ctl_mask = pvlan;
  1179. return 0;
  1180. }
  1181. EXPORT_SYMBOL(b53_br_join);
  1182. void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
  1183. {
  1184. struct b53_device *dev = ds->priv;
  1185. struct b53_vlan *vl = &dev->vlans[0];
  1186. s8 cpu_port = ds->ports[port].cpu_dp->index;
  1187. unsigned int i;
  1188. u16 pvlan, reg, pvid;
  1189. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
  1190. b53_for_each_port(dev, i) {
  1191. /* Don't touch the remaining ports */
  1192. if (dsa_to_port(ds, i)->bridge_dev != br)
  1193. continue;
  1194. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
  1195. reg &= ~BIT(port);
  1196. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
  1197. dev->ports[port].vlan_ctl_mask = reg;
  1198. /* Prevent self removal to preserve isolation */
  1199. if (port != i)
  1200. pvlan &= ~BIT(i);
  1201. }
  1202. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
  1203. dev->ports[port].vlan_ctl_mask = pvlan;
  1204. if (is5325(dev) || is5365(dev))
  1205. pvid = 1;
  1206. else
  1207. pvid = 0;
  1208. /* Make this port join all VLANs without VLAN entries */
  1209. if (is58xx(dev)) {
  1210. b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg);
  1211. reg |= BIT(port);
  1212. if (!(reg & BIT(cpu_port)))
  1213. reg |= BIT(cpu_port);
  1214. b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
  1215. } else {
  1216. b53_get_vlan_entry(dev, pvid, vl);
  1217. vl->members |= BIT(port) | BIT(cpu_port);
  1218. vl->untag |= BIT(port) | BIT(cpu_port);
  1219. b53_set_vlan_entry(dev, pvid, vl);
  1220. }
  1221. }
  1222. EXPORT_SYMBOL(b53_br_leave);
  1223. void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state)
  1224. {
  1225. struct b53_device *dev = ds->priv;
  1226. u8 hw_state;
  1227. u8 reg;
  1228. switch (state) {
  1229. case BR_STATE_DISABLED:
  1230. hw_state = PORT_CTRL_DIS_STATE;
  1231. break;
  1232. case BR_STATE_LISTENING:
  1233. hw_state = PORT_CTRL_LISTEN_STATE;
  1234. break;
  1235. case BR_STATE_LEARNING:
  1236. hw_state = PORT_CTRL_LEARN_STATE;
  1237. break;
  1238. case BR_STATE_FORWARDING:
  1239. hw_state = PORT_CTRL_FWD_STATE;
  1240. break;
  1241. case BR_STATE_BLOCKING:
  1242. hw_state = PORT_CTRL_BLOCK_STATE;
  1243. break;
  1244. default:
  1245. dev_err(ds->dev, "invalid STP state: %d\n", state);
  1246. return;
  1247. }
  1248. b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
  1249. reg &= ~PORT_CTRL_STP_STATE_MASK;
  1250. reg |= hw_state;
  1251. b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
  1252. }
  1253. EXPORT_SYMBOL(b53_br_set_stp_state);
  1254. void b53_br_fast_age(struct dsa_switch *ds, int port)
  1255. {
  1256. struct b53_device *dev = ds->priv;
  1257. if (b53_fast_age_port(dev, port))
  1258. dev_err(ds->dev, "fast ageing failed\n");
  1259. }
  1260. EXPORT_SYMBOL(b53_br_fast_age);
  1261. static bool b53_possible_cpu_port(struct dsa_switch *ds, int port)
  1262. {
  1263. /* Broadcom switches will accept enabling Broadcom tags on the
  1264. * following ports: 5, 7 and 8, any other port is not supported
  1265. */
  1266. switch (port) {
  1267. case B53_CPU_PORT_25:
  1268. case 7:
  1269. case B53_CPU_PORT:
  1270. return true;
  1271. }
  1272. return false;
  1273. }
  1274. static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port)
  1275. {
  1276. bool ret = b53_possible_cpu_port(ds, port);
  1277. if (!ret)
  1278. dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n",
  1279. port);
  1280. return ret;
  1281. }
  1282. enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port)
  1283. {
  1284. struct b53_device *dev = ds->priv;
  1285. /* Older models (5325, 5365) support a different tag format that we do
  1286. * not support in net/dsa/tag_brcm.c yet. 539x and 531x5 require managed
  1287. * mode to be turned on which means we need to specifically manage ARL
  1288. * misses on multicast addresses (TBD).
  1289. */
  1290. if (is5325(dev) || is5365(dev) || is539x(dev) || is531x5(dev) ||
  1291. !b53_can_enable_brcm_tags(ds, port))
  1292. return DSA_TAG_PROTO_NONE;
  1293. /* Broadcom BCM58xx chips have a flow accelerator on Port 8
  1294. * which requires us to use the prepended Broadcom tag type
  1295. */
  1296. if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT)
  1297. return DSA_TAG_PROTO_BRCM_PREPEND;
  1298. return DSA_TAG_PROTO_BRCM;
  1299. }
  1300. EXPORT_SYMBOL(b53_get_tag_protocol);
  1301. int b53_mirror_add(struct dsa_switch *ds, int port,
  1302. struct dsa_mall_mirror_tc_entry *mirror, bool ingress)
  1303. {
  1304. struct b53_device *dev = ds->priv;
  1305. u16 reg, loc;
  1306. if (ingress)
  1307. loc = B53_IG_MIR_CTL;
  1308. else
  1309. loc = B53_EG_MIR_CTL;
  1310. b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
  1311. reg &= ~MIRROR_MASK;
  1312. reg |= BIT(port);
  1313. b53_write16(dev, B53_MGMT_PAGE, loc, reg);
  1314. b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg);
  1315. reg &= ~CAP_PORT_MASK;
  1316. reg |= mirror->to_local_port;
  1317. reg |= MIRROR_EN;
  1318. b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
  1319. return 0;
  1320. }
  1321. EXPORT_SYMBOL(b53_mirror_add);
  1322. void b53_mirror_del(struct dsa_switch *ds, int port,
  1323. struct dsa_mall_mirror_tc_entry *mirror)
  1324. {
  1325. struct b53_device *dev = ds->priv;
  1326. bool loc_disable = false, other_loc_disable = false;
  1327. u16 reg, loc;
  1328. if (mirror->ingress)
  1329. loc = B53_IG_MIR_CTL;
  1330. else
  1331. loc = B53_EG_MIR_CTL;
  1332. /* Update the desired ingress/egress register */
  1333. b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
  1334. reg &= ~BIT(port);
  1335. if (!(reg & MIRROR_MASK))
  1336. loc_disable = true;
  1337. b53_write16(dev, B53_MGMT_PAGE, loc, reg);
  1338. /* Now look at the other one to know if we can disable mirroring
  1339. * entirely
  1340. */
  1341. if (mirror->ingress)
  1342. b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, &reg);
  1343. else
  1344. b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, &reg);
  1345. if (!(reg & MIRROR_MASK))
  1346. other_loc_disable = true;
  1347. b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg);
  1348. /* Both no longer have ports, let's disable mirroring */
  1349. if (loc_disable && other_loc_disable) {
  1350. reg &= ~MIRROR_EN;
  1351. reg &= ~mirror->to_local_port;
  1352. }
  1353. b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
  1354. }
  1355. EXPORT_SYMBOL(b53_mirror_del);
  1356. void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
  1357. {
  1358. struct b53_device *dev = ds->priv;
  1359. u16 reg;
  1360. b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, &reg);
  1361. if (enable)
  1362. reg |= BIT(port);
  1363. else
  1364. reg &= ~BIT(port);
  1365. b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg);
  1366. }
  1367. EXPORT_SYMBOL(b53_eee_enable_set);
  1368. /* Returns 0 if EEE was not enabled, or 1 otherwise
  1369. */
  1370. int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy)
  1371. {
  1372. int ret;
  1373. ret = phy_init_eee(phy, 0);
  1374. if (ret)
  1375. return 0;
  1376. b53_eee_enable_set(ds, port, true);
  1377. return 1;
  1378. }
  1379. EXPORT_SYMBOL(b53_eee_init);
  1380. int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
  1381. {
  1382. struct b53_device *dev = ds->priv;
  1383. struct ethtool_eee *p = &dev->ports[port].eee;
  1384. u16 reg;
  1385. if (is5325(dev) || is5365(dev))
  1386. return -EOPNOTSUPP;
  1387. b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, &reg);
  1388. e->eee_enabled = p->eee_enabled;
  1389. e->eee_active = !!(reg & BIT(port));
  1390. return 0;
  1391. }
  1392. EXPORT_SYMBOL(b53_get_mac_eee);
  1393. int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
  1394. {
  1395. struct b53_device *dev = ds->priv;
  1396. struct ethtool_eee *p = &dev->ports[port].eee;
  1397. if (is5325(dev) || is5365(dev))
  1398. return -EOPNOTSUPP;
  1399. p->eee_enabled = e->eee_enabled;
  1400. b53_eee_enable_set(ds, port, e->eee_enabled);
  1401. return 0;
  1402. }
  1403. EXPORT_SYMBOL(b53_set_mac_eee);
  1404. static const struct dsa_switch_ops b53_switch_ops = {
  1405. .get_tag_protocol = b53_get_tag_protocol,
  1406. .setup = b53_setup,
  1407. .get_strings = b53_get_strings,
  1408. .get_ethtool_stats = b53_get_ethtool_stats,
  1409. .get_sset_count = b53_get_sset_count,
  1410. .get_ethtool_phy_stats = b53_get_ethtool_phy_stats,
  1411. .phy_read = b53_phy_read16,
  1412. .phy_write = b53_phy_write16,
  1413. .adjust_link = b53_adjust_link,
  1414. .port_enable = b53_enable_port,
  1415. .port_disable = b53_disable_port,
  1416. .get_mac_eee = b53_get_mac_eee,
  1417. .set_mac_eee = b53_set_mac_eee,
  1418. .port_bridge_join = b53_br_join,
  1419. .port_bridge_leave = b53_br_leave,
  1420. .port_stp_state_set = b53_br_set_stp_state,
  1421. .port_fast_age = b53_br_fast_age,
  1422. .port_vlan_filtering = b53_vlan_filtering,
  1423. .port_vlan_prepare = b53_vlan_prepare,
  1424. .port_vlan_add = b53_vlan_add,
  1425. .port_vlan_del = b53_vlan_del,
  1426. .port_fdb_dump = b53_fdb_dump,
  1427. .port_fdb_add = b53_fdb_add,
  1428. .port_fdb_del = b53_fdb_del,
  1429. .port_mirror_add = b53_mirror_add,
  1430. .port_mirror_del = b53_mirror_del,
  1431. };
  1432. struct b53_chip_data {
  1433. u32 chip_id;
  1434. const char *dev_name;
  1435. u16 vlans;
  1436. u16 enabled_ports;
  1437. u8 cpu_port;
  1438. u8 vta_regs[3];
  1439. u8 arl_entries;
  1440. u8 duplex_reg;
  1441. u8 jumbo_pm_reg;
  1442. u8 jumbo_size_reg;
  1443. };
  1444. #define B53_VTA_REGS \
  1445. { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY }
  1446. #define B53_VTA_REGS_9798 \
  1447. { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 }
  1448. #define B53_VTA_REGS_63XX \
  1449. { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX }
  1450. static const struct b53_chip_data b53_switch_chips[] = {
  1451. {
  1452. .chip_id = BCM5325_DEVICE_ID,
  1453. .dev_name = "BCM5325",
  1454. .vlans = 16,
  1455. .enabled_ports = 0x1f,
  1456. .arl_entries = 2,
  1457. .cpu_port = B53_CPU_PORT_25,
  1458. .duplex_reg = B53_DUPLEX_STAT_FE,
  1459. },
  1460. {
  1461. .chip_id = BCM5365_DEVICE_ID,
  1462. .dev_name = "BCM5365",
  1463. .vlans = 256,
  1464. .enabled_ports = 0x1f,
  1465. .arl_entries = 2,
  1466. .cpu_port = B53_CPU_PORT_25,
  1467. .duplex_reg = B53_DUPLEX_STAT_FE,
  1468. },
  1469. {
  1470. .chip_id = BCM5395_DEVICE_ID,
  1471. .dev_name = "BCM5395",
  1472. .vlans = 4096,
  1473. .enabled_ports = 0x1f,
  1474. .arl_entries = 4,
  1475. .cpu_port = B53_CPU_PORT,
  1476. .vta_regs = B53_VTA_REGS,
  1477. .duplex_reg = B53_DUPLEX_STAT_GE,
  1478. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1479. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1480. },
  1481. {
  1482. .chip_id = BCM5397_DEVICE_ID,
  1483. .dev_name = "BCM5397",
  1484. .vlans = 4096,
  1485. .enabled_ports = 0x1f,
  1486. .arl_entries = 4,
  1487. .cpu_port = B53_CPU_PORT,
  1488. .vta_regs = B53_VTA_REGS_9798,
  1489. .duplex_reg = B53_DUPLEX_STAT_GE,
  1490. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1491. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1492. },
  1493. {
  1494. .chip_id = BCM5398_DEVICE_ID,
  1495. .dev_name = "BCM5398",
  1496. .vlans = 4096,
  1497. .enabled_ports = 0x7f,
  1498. .arl_entries = 4,
  1499. .cpu_port = B53_CPU_PORT,
  1500. .vta_regs = B53_VTA_REGS_9798,
  1501. .duplex_reg = B53_DUPLEX_STAT_GE,
  1502. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1503. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1504. },
  1505. {
  1506. .chip_id = BCM53115_DEVICE_ID,
  1507. .dev_name = "BCM53115",
  1508. .vlans = 4096,
  1509. .enabled_ports = 0x1f,
  1510. .arl_entries = 4,
  1511. .vta_regs = B53_VTA_REGS,
  1512. .cpu_port = B53_CPU_PORT,
  1513. .duplex_reg = B53_DUPLEX_STAT_GE,
  1514. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1515. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1516. },
  1517. {
  1518. .chip_id = BCM53125_DEVICE_ID,
  1519. .dev_name = "BCM53125",
  1520. .vlans = 4096,
  1521. .enabled_ports = 0xff,
  1522. .arl_entries = 4,
  1523. .cpu_port = B53_CPU_PORT,
  1524. .vta_regs = B53_VTA_REGS,
  1525. .duplex_reg = B53_DUPLEX_STAT_GE,
  1526. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1527. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1528. },
  1529. {
  1530. .chip_id = BCM53128_DEVICE_ID,
  1531. .dev_name = "BCM53128",
  1532. .vlans = 4096,
  1533. .enabled_ports = 0x1ff,
  1534. .arl_entries = 4,
  1535. .cpu_port = B53_CPU_PORT,
  1536. .vta_regs = B53_VTA_REGS,
  1537. .duplex_reg = B53_DUPLEX_STAT_GE,
  1538. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1539. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1540. },
  1541. {
  1542. .chip_id = BCM63XX_DEVICE_ID,
  1543. .dev_name = "BCM63xx",
  1544. .vlans = 4096,
  1545. .enabled_ports = 0, /* pdata must provide them */
  1546. .arl_entries = 4,
  1547. .cpu_port = B53_CPU_PORT,
  1548. .vta_regs = B53_VTA_REGS_63XX,
  1549. .duplex_reg = B53_DUPLEX_STAT_63XX,
  1550. .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX,
  1551. .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX,
  1552. },
  1553. {
  1554. .chip_id = BCM53010_DEVICE_ID,
  1555. .dev_name = "BCM53010",
  1556. .vlans = 4096,
  1557. .enabled_ports = 0x1f,
  1558. .arl_entries = 4,
  1559. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1560. .vta_regs = B53_VTA_REGS,
  1561. .duplex_reg = B53_DUPLEX_STAT_GE,
  1562. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1563. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1564. },
  1565. {
  1566. .chip_id = BCM53011_DEVICE_ID,
  1567. .dev_name = "BCM53011",
  1568. .vlans = 4096,
  1569. .enabled_ports = 0x1bf,
  1570. .arl_entries = 4,
  1571. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1572. .vta_regs = B53_VTA_REGS,
  1573. .duplex_reg = B53_DUPLEX_STAT_GE,
  1574. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1575. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1576. },
  1577. {
  1578. .chip_id = BCM53012_DEVICE_ID,
  1579. .dev_name = "BCM53012",
  1580. .vlans = 4096,
  1581. .enabled_ports = 0x1bf,
  1582. .arl_entries = 4,
  1583. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1584. .vta_regs = B53_VTA_REGS,
  1585. .duplex_reg = B53_DUPLEX_STAT_GE,
  1586. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1587. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1588. },
  1589. {
  1590. .chip_id = BCM53018_DEVICE_ID,
  1591. .dev_name = "BCM53018",
  1592. .vlans = 4096,
  1593. .enabled_ports = 0x1f,
  1594. .arl_entries = 4,
  1595. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1596. .vta_regs = B53_VTA_REGS,
  1597. .duplex_reg = B53_DUPLEX_STAT_GE,
  1598. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1599. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1600. },
  1601. {
  1602. .chip_id = BCM53019_DEVICE_ID,
  1603. .dev_name = "BCM53019",
  1604. .vlans = 4096,
  1605. .enabled_ports = 0x1f,
  1606. .arl_entries = 4,
  1607. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1608. .vta_regs = B53_VTA_REGS,
  1609. .duplex_reg = B53_DUPLEX_STAT_GE,
  1610. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1611. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1612. },
  1613. {
  1614. .chip_id = BCM58XX_DEVICE_ID,
  1615. .dev_name = "BCM585xx/586xx/88312",
  1616. .vlans = 4096,
  1617. .enabled_ports = 0x1ff,
  1618. .arl_entries = 4,
  1619. .cpu_port = B53_CPU_PORT,
  1620. .vta_regs = B53_VTA_REGS,
  1621. .duplex_reg = B53_DUPLEX_STAT_GE,
  1622. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1623. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1624. },
  1625. {
  1626. .chip_id = BCM7445_DEVICE_ID,
  1627. .dev_name = "BCM7445",
  1628. .vlans = 4096,
  1629. .enabled_ports = 0x1ff,
  1630. .arl_entries = 4,
  1631. .cpu_port = B53_CPU_PORT,
  1632. .vta_regs = B53_VTA_REGS,
  1633. .duplex_reg = B53_DUPLEX_STAT_GE,
  1634. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1635. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1636. },
  1637. {
  1638. .chip_id = BCM7278_DEVICE_ID,
  1639. .dev_name = "BCM7278",
  1640. .vlans = 4096,
  1641. .enabled_ports = 0x1ff,
  1642. .arl_entries= 4,
  1643. .cpu_port = B53_CPU_PORT,
  1644. .vta_regs = B53_VTA_REGS,
  1645. .duplex_reg = B53_DUPLEX_STAT_GE,
  1646. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1647. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1648. },
  1649. };
  1650. static int b53_switch_init(struct b53_device *dev)
  1651. {
  1652. unsigned int i;
  1653. int ret;
  1654. for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) {
  1655. const struct b53_chip_data *chip = &b53_switch_chips[i];
  1656. if (chip->chip_id == dev->chip_id) {
  1657. if (!dev->enabled_ports)
  1658. dev->enabled_ports = chip->enabled_ports;
  1659. dev->name = chip->dev_name;
  1660. dev->duplex_reg = chip->duplex_reg;
  1661. dev->vta_regs[0] = chip->vta_regs[0];
  1662. dev->vta_regs[1] = chip->vta_regs[1];
  1663. dev->vta_regs[2] = chip->vta_regs[2];
  1664. dev->jumbo_pm_reg = chip->jumbo_pm_reg;
  1665. dev->cpu_port = chip->cpu_port;
  1666. dev->num_vlans = chip->vlans;
  1667. dev->num_arl_entries = chip->arl_entries;
  1668. break;
  1669. }
  1670. }
  1671. /* check which BCM5325x version we have */
  1672. if (is5325(dev)) {
  1673. u8 vc4;
  1674. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
  1675. /* check reserved bits */
  1676. switch (vc4 & 3) {
  1677. case 1:
  1678. /* BCM5325E */
  1679. break;
  1680. case 3:
  1681. /* BCM5325F - do not use port 4 */
  1682. dev->enabled_ports &= ~BIT(4);
  1683. break;
  1684. default:
  1685. /* On the BCM47XX SoCs this is the supported internal switch.*/
  1686. #ifndef CONFIG_BCM47XX
  1687. /* BCM5325M */
  1688. return -EINVAL;
  1689. #else
  1690. break;
  1691. #endif
  1692. }
  1693. } else if (dev->chip_id == BCM53115_DEVICE_ID) {
  1694. u64 strap_value;
  1695. b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value);
  1696. /* use second IMP port if GMII is enabled */
  1697. if (strap_value & SV_GMII_CTRL_115)
  1698. dev->cpu_port = 5;
  1699. }
  1700. /* cpu port is always last */
  1701. dev->num_ports = dev->cpu_port + 1;
  1702. dev->enabled_ports |= BIT(dev->cpu_port);
  1703. /* Include non standard CPU port built-in PHYs to be probed */
  1704. if (is539x(dev) || is531x5(dev)) {
  1705. for (i = 0; i < dev->num_ports; i++) {
  1706. if (!(dev->ds->phys_mii_mask & BIT(i)) &&
  1707. !b53_possible_cpu_port(dev->ds, i))
  1708. dev->ds->phys_mii_mask |= BIT(i);
  1709. }
  1710. }
  1711. dev->ports = devm_kzalloc(dev->dev,
  1712. sizeof(struct b53_port) * dev->num_ports,
  1713. GFP_KERNEL);
  1714. if (!dev->ports)
  1715. return -ENOMEM;
  1716. dev->vlans = devm_kzalloc(dev->dev,
  1717. sizeof(struct b53_vlan) * dev->num_vlans,
  1718. GFP_KERNEL);
  1719. if (!dev->vlans)
  1720. return -ENOMEM;
  1721. dev->reset_gpio = b53_switch_get_reset_gpio(dev);
  1722. if (dev->reset_gpio >= 0) {
  1723. ret = devm_gpio_request_one(dev->dev, dev->reset_gpio,
  1724. GPIOF_OUT_INIT_HIGH, "robo_reset");
  1725. if (ret)
  1726. return ret;
  1727. }
  1728. return 0;
  1729. }
  1730. struct b53_device *b53_switch_alloc(struct device *base,
  1731. const struct b53_io_ops *ops,
  1732. void *priv)
  1733. {
  1734. struct dsa_switch *ds;
  1735. struct b53_device *dev;
  1736. ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
  1737. if (!ds)
  1738. return NULL;
  1739. dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
  1740. if (!dev)
  1741. return NULL;
  1742. ds->priv = dev;
  1743. dev->dev = base;
  1744. dev->ds = ds;
  1745. dev->priv = priv;
  1746. dev->ops = ops;
  1747. ds->ops = &b53_switch_ops;
  1748. mutex_init(&dev->reg_mutex);
  1749. mutex_init(&dev->stats_mutex);
  1750. return dev;
  1751. }
  1752. EXPORT_SYMBOL(b53_switch_alloc);
  1753. int b53_switch_detect(struct b53_device *dev)
  1754. {
  1755. u32 id32;
  1756. u16 tmp;
  1757. u8 id8;
  1758. int ret;
  1759. ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8);
  1760. if (ret)
  1761. return ret;
  1762. switch (id8) {
  1763. case 0:
  1764. /* BCM5325 and BCM5365 do not have this register so reads
  1765. * return 0. But the read operation did succeed, so assume this
  1766. * is one of them.
  1767. *
  1768. * Next check if we can write to the 5325's VTA register; for
  1769. * 5365 it is read only.
  1770. */
  1771. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf);
  1772. b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp);
  1773. if (tmp == 0xf)
  1774. dev->chip_id = BCM5325_DEVICE_ID;
  1775. else
  1776. dev->chip_id = BCM5365_DEVICE_ID;
  1777. break;
  1778. case BCM5395_DEVICE_ID:
  1779. case BCM5397_DEVICE_ID:
  1780. case BCM5398_DEVICE_ID:
  1781. dev->chip_id = id8;
  1782. break;
  1783. default:
  1784. ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32);
  1785. if (ret)
  1786. return ret;
  1787. switch (id32) {
  1788. case BCM53115_DEVICE_ID:
  1789. case BCM53125_DEVICE_ID:
  1790. case BCM53128_DEVICE_ID:
  1791. case BCM53010_DEVICE_ID:
  1792. case BCM53011_DEVICE_ID:
  1793. case BCM53012_DEVICE_ID:
  1794. case BCM53018_DEVICE_ID:
  1795. case BCM53019_DEVICE_ID:
  1796. dev->chip_id = id32;
  1797. break;
  1798. default:
  1799. pr_err("unsupported switch detected (BCM53%02x/BCM%x)\n",
  1800. id8, id32);
  1801. return -ENODEV;
  1802. }
  1803. }
  1804. if (dev->chip_id == BCM5325_DEVICE_ID)
  1805. return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25,
  1806. &dev->core_rev);
  1807. else
  1808. return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID,
  1809. &dev->core_rev);
  1810. }
  1811. EXPORT_SYMBOL(b53_switch_detect);
  1812. int b53_switch_register(struct b53_device *dev)
  1813. {
  1814. int ret;
  1815. if (dev->pdata) {
  1816. dev->chip_id = dev->pdata->chip_id;
  1817. dev->enabled_ports = dev->pdata->enabled_ports;
  1818. }
  1819. if (!dev->chip_id && b53_switch_detect(dev))
  1820. return -EINVAL;
  1821. ret = b53_switch_init(dev);
  1822. if (ret)
  1823. return ret;
  1824. pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev);
  1825. return dsa_register_switch(dev->ds);
  1826. }
  1827. EXPORT_SYMBOL(b53_switch_register);
  1828. MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>");
  1829. MODULE_DESCRIPTION("B53 switch library");
  1830. MODULE_LICENSE("Dual BSD/GPL");