b53_common.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  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. dev->chip_id == BCM583XX_DEVICE_ID) {
  585. b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg);
  586. reg |= SW_RST | EN_SW_RST | EN_CH_RST;
  587. b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, reg);
  588. do {
  589. b53_read8(dev, B53_CTRL_PAGE, B53_SOFTRESET, &reg);
  590. if (!(reg & SW_RST))
  591. break;
  592. usleep_range(1000, 2000);
  593. } while (timeout-- > 0);
  594. if (timeout == 0)
  595. return -ETIMEDOUT;
  596. }
  597. b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
  598. if (!(mgmt & SM_SW_FWD_EN)) {
  599. mgmt &= ~SM_SW_FWD_MODE;
  600. mgmt |= SM_SW_FWD_EN;
  601. b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
  602. b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, &mgmt);
  603. if (!(mgmt & SM_SW_FWD_EN)) {
  604. dev_err(dev->dev, "Failed to enable switch!\n");
  605. return -EINVAL;
  606. }
  607. }
  608. b53_enable_mib(dev);
  609. return b53_flush_arl(dev, FAST_AGE_STATIC);
  610. }
  611. static int b53_phy_read16(struct dsa_switch *ds, int addr, int reg)
  612. {
  613. struct b53_device *priv = ds->priv;
  614. u16 value = 0;
  615. int ret;
  616. if (priv->ops->phy_read16)
  617. ret = priv->ops->phy_read16(priv, addr, reg, &value);
  618. else
  619. ret = b53_read16(priv, B53_PORT_MII_PAGE(addr),
  620. reg * 2, &value);
  621. return ret ? ret : value;
  622. }
  623. static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
  624. {
  625. struct b53_device *priv = ds->priv;
  626. if (priv->ops->phy_write16)
  627. return priv->ops->phy_write16(priv, addr, reg, val);
  628. return b53_write16(priv, B53_PORT_MII_PAGE(addr), reg * 2, val);
  629. }
  630. static int b53_reset_switch(struct b53_device *priv)
  631. {
  632. /* reset vlans */
  633. priv->enable_jumbo = false;
  634. memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans);
  635. memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports);
  636. return b53_switch_reset(priv);
  637. }
  638. static int b53_apply_config(struct b53_device *priv)
  639. {
  640. /* disable switching */
  641. b53_set_forwarding(priv, 0);
  642. b53_configure_vlan(priv->ds);
  643. /* enable switching */
  644. b53_set_forwarding(priv, 1);
  645. return 0;
  646. }
  647. static void b53_reset_mib(struct b53_device *priv)
  648. {
  649. u8 gc;
  650. b53_read8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, &gc);
  651. b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc | GC_RESET_MIB);
  652. msleep(1);
  653. b53_write8(priv, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc & ~GC_RESET_MIB);
  654. msleep(1);
  655. }
  656. static const struct b53_mib_desc *b53_get_mib(struct b53_device *dev)
  657. {
  658. if (is5365(dev))
  659. return b53_mibs_65;
  660. else if (is63xx(dev))
  661. return b53_mibs_63xx;
  662. else if (is58xx(dev))
  663. return b53_mibs_58xx;
  664. else
  665. return b53_mibs;
  666. }
  667. static unsigned int b53_get_mib_size(struct b53_device *dev)
  668. {
  669. if (is5365(dev))
  670. return B53_MIBS_65_SIZE;
  671. else if (is63xx(dev))
  672. return B53_MIBS_63XX_SIZE;
  673. else if (is58xx(dev))
  674. return B53_MIBS_58XX_SIZE;
  675. else
  676. return B53_MIBS_SIZE;
  677. }
  678. static struct phy_device *b53_get_phy_device(struct dsa_switch *ds, int port)
  679. {
  680. /* These ports typically do not have built-in PHYs */
  681. switch (port) {
  682. case B53_CPU_PORT_25:
  683. case 7:
  684. case B53_CPU_PORT:
  685. return NULL;
  686. }
  687. return mdiobus_get_phy(ds->slave_mii_bus, port);
  688. }
  689. void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
  690. uint8_t *data)
  691. {
  692. struct b53_device *dev = ds->priv;
  693. const struct b53_mib_desc *mibs = b53_get_mib(dev);
  694. unsigned int mib_size = b53_get_mib_size(dev);
  695. struct phy_device *phydev;
  696. unsigned int i;
  697. if (stringset == ETH_SS_STATS) {
  698. for (i = 0; i < mib_size; i++)
  699. strlcpy(data + i * ETH_GSTRING_LEN,
  700. mibs[i].name, ETH_GSTRING_LEN);
  701. } else if (stringset == ETH_SS_PHY_STATS) {
  702. phydev = b53_get_phy_device(ds, port);
  703. if (!phydev)
  704. return;
  705. phy_ethtool_get_strings(phydev, data);
  706. }
  707. }
  708. EXPORT_SYMBOL(b53_get_strings);
  709. void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data)
  710. {
  711. struct b53_device *dev = ds->priv;
  712. const struct b53_mib_desc *mibs = b53_get_mib(dev);
  713. unsigned int mib_size = b53_get_mib_size(dev);
  714. const struct b53_mib_desc *s;
  715. unsigned int i;
  716. u64 val = 0;
  717. if (is5365(dev) && port == 5)
  718. port = 8;
  719. mutex_lock(&dev->stats_mutex);
  720. for (i = 0; i < mib_size; i++) {
  721. s = &mibs[i];
  722. if (s->size == 8) {
  723. b53_read64(dev, B53_MIB_PAGE(port), s->offset, &val);
  724. } else {
  725. u32 val32;
  726. b53_read32(dev, B53_MIB_PAGE(port), s->offset,
  727. &val32);
  728. val = val32;
  729. }
  730. data[i] = (u64)val;
  731. }
  732. mutex_unlock(&dev->stats_mutex);
  733. }
  734. EXPORT_SYMBOL(b53_get_ethtool_stats);
  735. void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data)
  736. {
  737. struct phy_device *phydev;
  738. phydev = b53_get_phy_device(ds, port);
  739. if (!phydev)
  740. return;
  741. phy_ethtool_get_stats(phydev, NULL, data);
  742. }
  743. EXPORT_SYMBOL(b53_get_ethtool_phy_stats);
  744. int b53_get_sset_count(struct dsa_switch *ds, int port, int sset)
  745. {
  746. struct b53_device *dev = ds->priv;
  747. struct phy_device *phydev;
  748. if (sset == ETH_SS_STATS) {
  749. return b53_get_mib_size(dev);
  750. } else if (sset == ETH_SS_PHY_STATS) {
  751. phydev = b53_get_phy_device(ds, port);
  752. if (!phydev)
  753. return 0;
  754. return phy_ethtool_get_sset_count(phydev);
  755. }
  756. return 0;
  757. }
  758. EXPORT_SYMBOL(b53_get_sset_count);
  759. static int b53_setup(struct dsa_switch *ds)
  760. {
  761. struct b53_device *dev = ds->priv;
  762. unsigned int port;
  763. int ret;
  764. ret = b53_reset_switch(dev);
  765. if (ret) {
  766. dev_err(ds->dev, "failed to reset switch\n");
  767. return ret;
  768. }
  769. b53_reset_mib(dev);
  770. ret = b53_apply_config(dev);
  771. if (ret)
  772. dev_err(ds->dev, "failed to apply configuration\n");
  773. /* Configure IMP/CPU port, disable unused ports. Enabled
  774. * ports will be configured with .port_enable
  775. */
  776. for (port = 0; port < dev->num_ports; port++) {
  777. if (dsa_is_cpu_port(ds, port))
  778. b53_enable_cpu_port(dev, port);
  779. else if (dsa_is_unused_port(ds, port))
  780. b53_disable_port(ds, port, NULL);
  781. }
  782. return ret;
  783. }
  784. static void b53_adjust_link(struct dsa_switch *ds, int port,
  785. struct phy_device *phydev)
  786. {
  787. struct b53_device *dev = ds->priv;
  788. struct ethtool_eee *p = &dev->ports[port].eee;
  789. u8 rgmii_ctrl = 0, reg = 0, off;
  790. if (!phy_is_pseudo_fixed_link(phydev))
  791. return;
  792. /* Override the port settings */
  793. if (port == dev->cpu_port) {
  794. off = B53_PORT_OVERRIDE_CTRL;
  795. reg = PORT_OVERRIDE_EN;
  796. } else {
  797. off = B53_GMII_PORT_OVERRIDE_CTRL(port);
  798. reg = GMII_PO_EN;
  799. }
  800. /* Set the link UP */
  801. if (phydev->link)
  802. reg |= PORT_OVERRIDE_LINK;
  803. if (phydev->duplex == DUPLEX_FULL)
  804. reg |= PORT_OVERRIDE_FULL_DUPLEX;
  805. switch (phydev->speed) {
  806. case 2000:
  807. reg |= PORT_OVERRIDE_SPEED_2000M;
  808. /* fallthrough */
  809. case SPEED_1000:
  810. reg |= PORT_OVERRIDE_SPEED_1000M;
  811. break;
  812. case SPEED_100:
  813. reg |= PORT_OVERRIDE_SPEED_100M;
  814. break;
  815. case SPEED_10:
  816. reg |= PORT_OVERRIDE_SPEED_10M;
  817. break;
  818. default:
  819. dev_err(ds->dev, "unknown speed: %d\n", phydev->speed);
  820. return;
  821. }
  822. /* Enable flow control on BCM5301x's CPU port */
  823. if (is5301x(dev) && port == dev->cpu_port)
  824. reg |= PORT_OVERRIDE_RX_FLOW | PORT_OVERRIDE_TX_FLOW;
  825. if (phydev->pause) {
  826. if (phydev->asym_pause)
  827. reg |= PORT_OVERRIDE_TX_FLOW;
  828. reg |= PORT_OVERRIDE_RX_FLOW;
  829. }
  830. b53_write8(dev, B53_CTRL_PAGE, off, reg);
  831. if (is531x5(dev) && phy_interface_is_rgmii(phydev)) {
  832. if (port == 8)
  833. off = B53_RGMII_CTRL_IMP;
  834. else
  835. off = B53_RGMII_CTRL_P(port);
  836. /* Configure the port RGMII clock delay by DLL disabled and
  837. * tx_clk aligned timing (restoring to reset defaults)
  838. */
  839. b53_read8(dev, B53_CTRL_PAGE, off, &rgmii_ctrl);
  840. rgmii_ctrl &= ~(RGMII_CTRL_DLL_RXC | RGMII_CTRL_DLL_TXC |
  841. RGMII_CTRL_TIMING_SEL);
  842. /* PHY_INTERFACE_MODE_RGMII_TXID means TX internal delay, make
  843. * sure that we enable the port TX clock internal delay to
  844. * account for this internal delay that is inserted, otherwise
  845. * the switch won't be able to receive correctly.
  846. *
  847. * PHY_INTERFACE_MODE_RGMII means that we are not introducing
  848. * any delay neither on transmission nor reception, so the
  849. * BCM53125 must also be configured accordingly to account for
  850. * the lack of delay and introduce
  851. *
  852. * The BCM53125 switch has its RX clock and TX clock control
  853. * swapped, hence the reason why we modify the TX clock path in
  854. * the "RGMII" case
  855. */
  856. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
  857. rgmii_ctrl |= RGMII_CTRL_DLL_TXC;
  858. if (phydev->interface == PHY_INTERFACE_MODE_RGMII)
  859. rgmii_ctrl |= RGMII_CTRL_DLL_TXC | RGMII_CTRL_DLL_RXC;
  860. rgmii_ctrl |= RGMII_CTRL_TIMING_SEL;
  861. b53_write8(dev, B53_CTRL_PAGE, off, rgmii_ctrl);
  862. dev_info(ds->dev, "Configured port %d for %s\n", port,
  863. phy_modes(phydev->interface));
  864. }
  865. /* configure MII port if necessary */
  866. if (is5325(dev)) {
  867. b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
  868. &reg);
  869. /* reverse mii needs to be enabled */
  870. if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
  871. b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
  872. reg | PORT_OVERRIDE_RV_MII_25);
  873. b53_read8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL,
  874. &reg);
  875. if (!(reg & PORT_OVERRIDE_RV_MII_25)) {
  876. dev_err(ds->dev,
  877. "Failed to enable reverse MII mode\n");
  878. return;
  879. }
  880. }
  881. } else if (is5301x(dev)) {
  882. if (port != dev->cpu_port) {
  883. u8 po_reg = B53_GMII_PORT_OVERRIDE_CTRL(dev->cpu_port);
  884. u8 gmii_po;
  885. b53_read8(dev, B53_CTRL_PAGE, po_reg, &gmii_po);
  886. gmii_po |= GMII_PO_LINK |
  887. GMII_PO_RX_FLOW |
  888. GMII_PO_TX_FLOW |
  889. GMII_PO_EN |
  890. GMII_PO_SPEED_2000M;
  891. b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po);
  892. }
  893. }
  894. /* Re-negotiate EEE if it was enabled already */
  895. p->eee_enabled = b53_eee_init(ds, port, phydev);
  896. }
  897. int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
  898. {
  899. return 0;
  900. }
  901. EXPORT_SYMBOL(b53_vlan_filtering);
  902. int b53_vlan_prepare(struct dsa_switch *ds, int port,
  903. const struct switchdev_obj_port_vlan *vlan)
  904. {
  905. struct b53_device *dev = ds->priv;
  906. if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0)
  907. return -EOPNOTSUPP;
  908. if (vlan->vid_end > dev->num_vlans)
  909. return -ERANGE;
  910. b53_enable_vlan(dev, true);
  911. return 0;
  912. }
  913. EXPORT_SYMBOL(b53_vlan_prepare);
  914. void b53_vlan_add(struct dsa_switch *ds, int port,
  915. const struct switchdev_obj_port_vlan *vlan)
  916. {
  917. struct b53_device *dev = ds->priv;
  918. bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
  919. bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
  920. struct b53_vlan *vl;
  921. u16 vid;
  922. for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
  923. vl = &dev->vlans[vid];
  924. b53_get_vlan_entry(dev, vid, vl);
  925. vl->members |= BIT(port);
  926. if (untagged && !dsa_is_cpu_port(ds, port))
  927. vl->untag |= BIT(port);
  928. else
  929. vl->untag &= ~BIT(port);
  930. b53_set_vlan_entry(dev, vid, vl);
  931. b53_fast_age_vlan(dev, vid);
  932. }
  933. if (pvid) {
  934. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
  935. vlan->vid_end);
  936. b53_fast_age_vlan(dev, vid);
  937. }
  938. }
  939. EXPORT_SYMBOL(b53_vlan_add);
  940. int b53_vlan_del(struct dsa_switch *ds, int port,
  941. const struct switchdev_obj_port_vlan *vlan)
  942. {
  943. struct b53_device *dev = ds->priv;
  944. bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
  945. struct b53_vlan *vl;
  946. u16 vid;
  947. u16 pvid;
  948. b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
  949. for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
  950. vl = &dev->vlans[vid];
  951. b53_get_vlan_entry(dev, vid, vl);
  952. vl->members &= ~BIT(port);
  953. if (pvid == vid) {
  954. if (is5325(dev) || is5365(dev))
  955. pvid = 1;
  956. else
  957. pvid = 0;
  958. }
  959. if (untagged && !dsa_is_cpu_port(ds, port))
  960. vl->untag &= ~(BIT(port));
  961. b53_set_vlan_entry(dev, vid, vl);
  962. b53_fast_age_vlan(dev, vid);
  963. }
  964. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid);
  965. b53_fast_age_vlan(dev, pvid);
  966. return 0;
  967. }
  968. EXPORT_SYMBOL(b53_vlan_del);
  969. /* Address Resolution Logic routines */
  970. static int b53_arl_op_wait(struct b53_device *dev)
  971. {
  972. unsigned int timeout = 10;
  973. u8 reg;
  974. do {
  975. b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg);
  976. if (!(reg & ARLTBL_START_DONE))
  977. return 0;
  978. usleep_range(1000, 2000);
  979. } while (timeout--);
  980. dev_warn(dev->dev, "timeout waiting for ARL to finish: 0x%02x\n", reg);
  981. return -ETIMEDOUT;
  982. }
  983. static int b53_arl_rw_op(struct b53_device *dev, unsigned int op)
  984. {
  985. u8 reg;
  986. if (op > ARLTBL_RW)
  987. return -EINVAL;
  988. b53_read8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, &reg);
  989. reg |= ARLTBL_START_DONE;
  990. if (op)
  991. reg |= ARLTBL_RW;
  992. else
  993. reg &= ~ARLTBL_RW;
  994. b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg);
  995. return b53_arl_op_wait(dev);
  996. }
  997. static int b53_arl_read(struct b53_device *dev, u64 mac,
  998. u16 vid, struct b53_arl_entry *ent, u8 *idx,
  999. bool is_valid)
  1000. {
  1001. unsigned int i;
  1002. int ret;
  1003. ret = b53_arl_op_wait(dev);
  1004. if (ret)
  1005. return ret;
  1006. /* Read the bins */
  1007. for (i = 0; i < dev->num_arl_entries; i++) {
  1008. u64 mac_vid;
  1009. u32 fwd_entry;
  1010. b53_read64(dev, B53_ARLIO_PAGE,
  1011. B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid);
  1012. b53_read32(dev, B53_ARLIO_PAGE,
  1013. B53_ARLTBL_DATA_ENTRY(i), &fwd_entry);
  1014. b53_arl_to_entry(ent, mac_vid, fwd_entry);
  1015. if (!(fwd_entry & ARLTBL_VALID))
  1016. continue;
  1017. if ((mac_vid & ARLTBL_MAC_MASK) != mac)
  1018. continue;
  1019. *idx = i;
  1020. }
  1021. return -ENOENT;
  1022. }
  1023. static int b53_arl_op(struct b53_device *dev, int op, int port,
  1024. const unsigned char *addr, u16 vid, bool is_valid)
  1025. {
  1026. struct b53_arl_entry ent;
  1027. u32 fwd_entry;
  1028. u64 mac, mac_vid = 0;
  1029. u8 idx = 0;
  1030. int ret;
  1031. /* Convert the array into a 64-bit MAC */
  1032. mac = ether_addr_to_u64(addr);
  1033. /* Perform a read for the given MAC and VID */
  1034. b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac);
  1035. b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
  1036. /* Issue a read operation for this MAC */
  1037. ret = b53_arl_rw_op(dev, 1);
  1038. if (ret)
  1039. return ret;
  1040. ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid);
  1041. /* If this is a read, just finish now */
  1042. if (op)
  1043. return ret;
  1044. /* We could not find a matching MAC, so reset to a new entry */
  1045. if (ret) {
  1046. fwd_entry = 0;
  1047. idx = 1;
  1048. }
  1049. memset(&ent, 0, sizeof(ent));
  1050. ent.port = port;
  1051. ent.is_valid = is_valid;
  1052. ent.vid = vid;
  1053. ent.is_static = true;
  1054. memcpy(ent.mac, addr, ETH_ALEN);
  1055. b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
  1056. b53_write64(dev, B53_ARLIO_PAGE,
  1057. B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid);
  1058. b53_write32(dev, B53_ARLIO_PAGE,
  1059. B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
  1060. return b53_arl_rw_op(dev, 0);
  1061. }
  1062. int b53_fdb_add(struct dsa_switch *ds, int port,
  1063. const unsigned char *addr, u16 vid)
  1064. {
  1065. struct b53_device *priv = ds->priv;
  1066. /* 5325 and 5365 require some more massaging, but could
  1067. * be supported eventually
  1068. */
  1069. if (is5325(priv) || is5365(priv))
  1070. return -EOPNOTSUPP;
  1071. return b53_arl_op(priv, 0, port, addr, vid, true);
  1072. }
  1073. EXPORT_SYMBOL(b53_fdb_add);
  1074. int b53_fdb_del(struct dsa_switch *ds, int port,
  1075. const unsigned char *addr, u16 vid)
  1076. {
  1077. struct b53_device *priv = ds->priv;
  1078. return b53_arl_op(priv, 0, port, addr, vid, false);
  1079. }
  1080. EXPORT_SYMBOL(b53_fdb_del);
  1081. static int b53_arl_search_wait(struct b53_device *dev)
  1082. {
  1083. unsigned int timeout = 1000;
  1084. u8 reg;
  1085. do {
  1086. b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, &reg);
  1087. if (!(reg & ARL_SRCH_STDN))
  1088. return 0;
  1089. if (reg & ARL_SRCH_VLID)
  1090. return 0;
  1091. usleep_range(1000, 2000);
  1092. } while (timeout--);
  1093. return -ETIMEDOUT;
  1094. }
  1095. static void b53_arl_search_rd(struct b53_device *dev, u8 idx,
  1096. struct b53_arl_entry *ent)
  1097. {
  1098. u64 mac_vid;
  1099. u32 fwd_entry;
  1100. b53_read64(dev, B53_ARLIO_PAGE,
  1101. B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid);
  1102. b53_read32(dev, B53_ARLIO_PAGE,
  1103. B53_ARL_SRCH_RSTL(idx), &fwd_entry);
  1104. b53_arl_to_entry(ent, mac_vid, fwd_entry);
  1105. }
  1106. static int b53_fdb_copy(int port, const struct b53_arl_entry *ent,
  1107. dsa_fdb_dump_cb_t *cb, void *data)
  1108. {
  1109. if (!ent->is_valid)
  1110. return 0;
  1111. if (port != ent->port)
  1112. return 0;
  1113. return cb(ent->mac, ent->vid, ent->is_static, data);
  1114. }
  1115. int b53_fdb_dump(struct dsa_switch *ds, int port,
  1116. dsa_fdb_dump_cb_t *cb, void *data)
  1117. {
  1118. struct b53_device *priv = ds->priv;
  1119. struct b53_arl_entry results[2];
  1120. unsigned int count = 0;
  1121. int ret;
  1122. u8 reg;
  1123. /* Start search operation */
  1124. reg = ARL_SRCH_STDN;
  1125. b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);
  1126. do {
  1127. ret = b53_arl_search_wait(priv);
  1128. if (ret)
  1129. return ret;
  1130. b53_arl_search_rd(priv, 0, &results[0]);
  1131. ret = b53_fdb_copy(port, &results[0], cb, data);
  1132. if (ret)
  1133. return ret;
  1134. if (priv->num_arl_entries > 2) {
  1135. b53_arl_search_rd(priv, 1, &results[1]);
  1136. ret = b53_fdb_copy(port, &results[1], cb, data);
  1137. if (ret)
  1138. return ret;
  1139. if (!results[0].is_valid && !results[1].is_valid)
  1140. break;
  1141. }
  1142. } while (count++ < 1024);
  1143. return 0;
  1144. }
  1145. EXPORT_SYMBOL(b53_fdb_dump);
  1146. int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
  1147. {
  1148. struct b53_device *dev = ds->priv;
  1149. s8 cpu_port = ds->ports[port].cpu_dp->index;
  1150. u16 pvlan, reg;
  1151. unsigned int i;
  1152. /* Make this port leave the all VLANs join since we will have proper
  1153. * VLAN entries from now on
  1154. */
  1155. if (is58xx(dev)) {
  1156. b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg);
  1157. reg &= ~BIT(port);
  1158. if ((reg & BIT(cpu_port)) == BIT(cpu_port))
  1159. reg &= ~BIT(cpu_port);
  1160. b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
  1161. }
  1162. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
  1163. b53_for_each_port(dev, i) {
  1164. if (dsa_to_port(ds, i)->bridge_dev != br)
  1165. continue;
  1166. /* Add this local port to the remote port VLAN control
  1167. * membership and update the remote port bitmask
  1168. */
  1169. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
  1170. reg |= BIT(port);
  1171. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
  1172. dev->ports[i].vlan_ctl_mask = reg;
  1173. pvlan |= BIT(i);
  1174. }
  1175. /* Configure the local port VLAN control membership to include
  1176. * remote ports and update the local port bitmask
  1177. */
  1178. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
  1179. dev->ports[port].vlan_ctl_mask = pvlan;
  1180. return 0;
  1181. }
  1182. EXPORT_SYMBOL(b53_br_join);
  1183. void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
  1184. {
  1185. struct b53_device *dev = ds->priv;
  1186. struct b53_vlan *vl = &dev->vlans[0];
  1187. s8 cpu_port = ds->ports[port].cpu_dp->index;
  1188. unsigned int i;
  1189. u16 pvlan, reg, pvid;
  1190. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
  1191. b53_for_each_port(dev, i) {
  1192. /* Don't touch the remaining ports */
  1193. if (dsa_to_port(ds, i)->bridge_dev != br)
  1194. continue;
  1195. b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), &reg);
  1196. reg &= ~BIT(port);
  1197. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), reg);
  1198. dev->ports[port].vlan_ctl_mask = reg;
  1199. /* Prevent self removal to preserve isolation */
  1200. if (port != i)
  1201. pvlan &= ~BIT(i);
  1202. }
  1203. b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
  1204. dev->ports[port].vlan_ctl_mask = pvlan;
  1205. if (is5325(dev) || is5365(dev))
  1206. pvid = 1;
  1207. else
  1208. pvid = 0;
  1209. /* Make this port join all VLANs without VLAN entries */
  1210. if (is58xx(dev)) {
  1211. b53_read16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, &reg);
  1212. reg |= BIT(port);
  1213. if (!(reg & BIT(cpu_port)))
  1214. reg |= BIT(cpu_port);
  1215. b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
  1216. } else {
  1217. b53_get_vlan_entry(dev, pvid, vl);
  1218. vl->members |= BIT(port) | BIT(cpu_port);
  1219. vl->untag |= BIT(port) | BIT(cpu_port);
  1220. b53_set_vlan_entry(dev, pvid, vl);
  1221. }
  1222. }
  1223. EXPORT_SYMBOL(b53_br_leave);
  1224. void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state)
  1225. {
  1226. struct b53_device *dev = ds->priv;
  1227. u8 hw_state;
  1228. u8 reg;
  1229. switch (state) {
  1230. case BR_STATE_DISABLED:
  1231. hw_state = PORT_CTRL_DIS_STATE;
  1232. break;
  1233. case BR_STATE_LISTENING:
  1234. hw_state = PORT_CTRL_LISTEN_STATE;
  1235. break;
  1236. case BR_STATE_LEARNING:
  1237. hw_state = PORT_CTRL_LEARN_STATE;
  1238. break;
  1239. case BR_STATE_FORWARDING:
  1240. hw_state = PORT_CTRL_FWD_STATE;
  1241. break;
  1242. case BR_STATE_BLOCKING:
  1243. hw_state = PORT_CTRL_BLOCK_STATE;
  1244. break;
  1245. default:
  1246. dev_err(ds->dev, "invalid STP state: %d\n", state);
  1247. return;
  1248. }
  1249. b53_read8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), &reg);
  1250. reg &= ~PORT_CTRL_STP_STATE_MASK;
  1251. reg |= hw_state;
  1252. b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
  1253. }
  1254. EXPORT_SYMBOL(b53_br_set_stp_state);
  1255. void b53_br_fast_age(struct dsa_switch *ds, int port)
  1256. {
  1257. struct b53_device *dev = ds->priv;
  1258. if (b53_fast_age_port(dev, port))
  1259. dev_err(ds->dev, "fast ageing failed\n");
  1260. }
  1261. EXPORT_SYMBOL(b53_br_fast_age);
  1262. static bool b53_possible_cpu_port(struct dsa_switch *ds, int port)
  1263. {
  1264. /* Broadcom switches will accept enabling Broadcom tags on the
  1265. * following ports: 5, 7 and 8, any other port is not supported
  1266. */
  1267. switch (port) {
  1268. case B53_CPU_PORT_25:
  1269. case 7:
  1270. case B53_CPU_PORT:
  1271. return true;
  1272. }
  1273. return false;
  1274. }
  1275. static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port)
  1276. {
  1277. bool ret = b53_possible_cpu_port(ds, port);
  1278. if (!ret)
  1279. dev_warn(ds->dev, "Port %d is not Broadcom tag capable\n",
  1280. port);
  1281. return ret;
  1282. }
  1283. enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port)
  1284. {
  1285. struct b53_device *dev = ds->priv;
  1286. /* Older models (5325, 5365) support a different tag format that we do
  1287. * not support in net/dsa/tag_brcm.c yet. 539x and 531x5 require managed
  1288. * mode to be turned on which means we need to specifically manage ARL
  1289. * misses on multicast addresses (TBD).
  1290. */
  1291. if (is5325(dev) || is5365(dev) || is539x(dev) || is531x5(dev) ||
  1292. !b53_can_enable_brcm_tags(ds, port))
  1293. return DSA_TAG_PROTO_NONE;
  1294. /* Broadcom BCM58xx chips have a flow accelerator on Port 8
  1295. * which requires us to use the prepended Broadcom tag type
  1296. */
  1297. if (dev->chip_id == BCM58XX_DEVICE_ID && port == B53_CPU_PORT)
  1298. return DSA_TAG_PROTO_BRCM_PREPEND;
  1299. return DSA_TAG_PROTO_BRCM;
  1300. }
  1301. EXPORT_SYMBOL(b53_get_tag_protocol);
  1302. int b53_mirror_add(struct dsa_switch *ds, int port,
  1303. struct dsa_mall_mirror_tc_entry *mirror, bool ingress)
  1304. {
  1305. struct b53_device *dev = ds->priv;
  1306. u16 reg, loc;
  1307. if (ingress)
  1308. loc = B53_IG_MIR_CTL;
  1309. else
  1310. loc = B53_EG_MIR_CTL;
  1311. b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
  1312. reg &= ~MIRROR_MASK;
  1313. reg |= BIT(port);
  1314. b53_write16(dev, B53_MGMT_PAGE, loc, reg);
  1315. b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg);
  1316. reg &= ~CAP_PORT_MASK;
  1317. reg |= mirror->to_local_port;
  1318. reg |= MIRROR_EN;
  1319. b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
  1320. return 0;
  1321. }
  1322. EXPORT_SYMBOL(b53_mirror_add);
  1323. void b53_mirror_del(struct dsa_switch *ds, int port,
  1324. struct dsa_mall_mirror_tc_entry *mirror)
  1325. {
  1326. struct b53_device *dev = ds->priv;
  1327. bool loc_disable = false, other_loc_disable = false;
  1328. u16 reg, loc;
  1329. if (mirror->ingress)
  1330. loc = B53_IG_MIR_CTL;
  1331. else
  1332. loc = B53_EG_MIR_CTL;
  1333. /* Update the desired ingress/egress register */
  1334. b53_read16(dev, B53_MGMT_PAGE, loc, &reg);
  1335. reg &= ~BIT(port);
  1336. if (!(reg & MIRROR_MASK))
  1337. loc_disable = true;
  1338. b53_write16(dev, B53_MGMT_PAGE, loc, reg);
  1339. /* Now look at the other one to know if we can disable mirroring
  1340. * entirely
  1341. */
  1342. if (mirror->ingress)
  1343. b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, &reg);
  1344. else
  1345. b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, &reg);
  1346. if (!(reg & MIRROR_MASK))
  1347. other_loc_disable = true;
  1348. b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &reg);
  1349. /* Both no longer have ports, let's disable mirroring */
  1350. if (loc_disable && other_loc_disable) {
  1351. reg &= ~MIRROR_EN;
  1352. reg &= ~mirror->to_local_port;
  1353. }
  1354. b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
  1355. }
  1356. EXPORT_SYMBOL(b53_mirror_del);
  1357. void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
  1358. {
  1359. struct b53_device *dev = ds->priv;
  1360. u16 reg;
  1361. b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, &reg);
  1362. if (enable)
  1363. reg |= BIT(port);
  1364. else
  1365. reg &= ~BIT(port);
  1366. b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg);
  1367. }
  1368. EXPORT_SYMBOL(b53_eee_enable_set);
  1369. /* Returns 0 if EEE was not enabled, or 1 otherwise
  1370. */
  1371. int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy)
  1372. {
  1373. int ret;
  1374. ret = phy_init_eee(phy, 0);
  1375. if (ret)
  1376. return 0;
  1377. b53_eee_enable_set(ds, port, true);
  1378. return 1;
  1379. }
  1380. EXPORT_SYMBOL(b53_eee_init);
  1381. int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
  1382. {
  1383. struct b53_device *dev = ds->priv;
  1384. struct ethtool_eee *p = &dev->ports[port].eee;
  1385. u16 reg;
  1386. if (is5325(dev) || is5365(dev))
  1387. return -EOPNOTSUPP;
  1388. b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, &reg);
  1389. e->eee_enabled = p->eee_enabled;
  1390. e->eee_active = !!(reg & BIT(port));
  1391. return 0;
  1392. }
  1393. EXPORT_SYMBOL(b53_get_mac_eee);
  1394. int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
  1395. {
  1396. struct b53_device *dev = ds->priv;
  1397. struct ethtool_eee *p = &dev->ports[port].eee;
  1398. if (is5325(dev) || is5365(dev))
  1399. return -EOPNOTSUPP;
  1400. p->eee_enabled = e->eee_enabled;
  1401. b53_eee_enable_set(ds, port, e->eee_enabled);
  1402. return 0;
  1403. }
  1404. EXPORT_SYMBOL(b53_set_mac_eee);
  1405. static const struct dsa_switch_ops b53_switch_ops = {
  1406. .get_tag_protocol = b53_get_tag_protocol,
  1407. .setup = b53_setup,
  1408. .get_strings = b53_get_strings,
  1409. .get_ethtool_stats = b53_get_ethtool_stats,
  1410. .get_sset_count = b53_get_sset_count,
  1411. .get_ethtool_phy_stats = b53_get_ethtool_phy_stats,
  1412. .phy_read = b53_phy_read16,
  1413. .phy_write = b53_phy_write16,
  1414. .adjust_link = b53_adjust_link,
  1415. .port_enable = b53_enable_port,
  1416. .port_disable = b53_disable_port,
  1417. .get_mac_eee = b53_get_mac_eee,
  1418. .set_mac_eee = b53_set_mac_eee,
  1419. .port_bridge_join = b53_br_join,
  1420. .port_bridge_leave = b53_br_leave,
  1421. .port_stp_state_set = b53_br_set_stp_state,
  1422. .port_fast_age = b53_br_fast_age,
  1423. .port_vlan_filtering = b53_vlan_filtering,
  1424. .port_vlan_prepare = b53_vlan_prepare,
  1425. .port_vlan_add = b53_vlan_add,
  1426. .port_vlan_del = b53_vlan_del,
  1427. .port_fdb_dump = b53_fdb_dump,
  1428. .port_fdb_add = b53_fdb_add,
  1429. .port_fdb_del = b53_fdb_del,
  1430. .port_mirror_add = b53_mirror_add,
  1431. .port_mirror_del = b53_mirror_del,
  1432. };
  1433. struct b53_chip_data {
  1434. u32 chip_id;
  1435. const char *dev_name;
  1436. u16 vlans;
  1437. u16 enabled_ports;
  1438. u8 cpu_port;
  1439. u8 vta_regs[3];
  1440. u8 arl_entries;
  1441. u8 duplex_reg;
  1442. u8 jumbo_pm_reg;
  1443. u8 jumbo_size_reg;
  1444. };
  1445. #define B53_VTA_REGS \
  1446. { B53_VT_ACCESS, B53_VT_INDEX, B53_VT_ENTRY }
  1447. #define B53_VTA_REGS_9798 \
  1448. { B53_VT_ACCESS_9798, B53_VT_INDEX_9798, B53_VT_ENTRY_9798 }
  1449. #define B53_VTA_REGS_63XX \
  1450. { B53_VT_ACCESS_63XX, B53_VT_INDEX_63XX, B53_VT_ENTRY_63XX }
  1451. static const struct b53_chip_data b53_switch_chips[] = {
  1452. {
  1453. .chip_id = BCM5325_DEVICE_ID,
  1454. .dev_name = "BCM5325",
  1455. .vlans = 16,
  1456. .enabled_ports = 0x1f,
  1457. .arl_entries = 2,
  1458. .cpu_port = B53_CPU_PORT_25,
  1459. .duplex_reg = B53_DUPLEX_STAT_FE,
  1460. },
  1461. {
  1462. .chip_id = BCM5365_DEVICE_ID,
  1463. .dev_name = "BCM5365",
  1464. .vlans = 256,
  1465. .enabled_ports = 0x1f,
  1466. .arl_entries = 2,
  1467. .cpu_port = B53_CPU_PORT_25,
  1468. .duplex_reg = B53_DUPLEX_STAT_FE,
  1469. },
  1470. {
  1471. .chip_id = BCM5389_DEVICE_ID,
  1472. .dev_name = "BCM5389",
  1473. .vlans = 4096,
  1474. .enabled_ports = 0x1f,
  1475. .arl_entries = 4,
  1476. .cpu_port = B53_CPU_PORT,
  1477. .vta_regs = B53_VTA_REGS,
  1478. .duplex_reg = B53_DUPLEX_STAT_GE,
  1479. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1480. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1481. },
  1482. {
  1483. .chip_id = BCM5395_DEVICE_ID,
  1484. .dev_name = "BCM5395",
  1485. .vlans = 4096,
  1486. .enabled_ports = 0x1f,
  1487. .arl_entries = 4,
  1488. .cpu_port = B53_CPU_PORT,
  1489. .vta_regs = B53_VTA_REGS,
  1490. .duplex_reg = B53_DUPLEX_STAT_GE,
  1491. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1492. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1493. },
  1494. {
  1495. .chip_id = BCM5397_DEVICE_ID,
  1496. .dev_name = "BCM5397",
  1497. .vlans = 4096,
  1498. .enabled_ports = 0x1f,
  1499. .arl_entries = 4,
  1500. .cpu_port = B53_CPU_PORT,
  1501. .vta_regs = B53_VTA_REGS_9798,
  1502. .duplex_reg = B53_DUPLEX_STAT_GE,
  1503. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1504. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1505. },
  1506. {
  1507. .chip_id = BCM5398_DEVICE_ID,
  1508. .dev_name = "BCM5398",
  1509. .vlans = 4096,
  1510. .enabled_ports = 0x7f,
  1511. .arl_entries = 4,
  1512. .cpu_port = B53_CPU_PORT,
  1513. .vta_regs = B53_VTA_REGS_9798,
  1514. .duplex_reg = B53_DUPLEX_STAT_GE,
  1515. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1516. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1517. },
  1518. {
  1519. .chip_id = BCM53115_DEVICE_ID,
  1520. .dev_name = "BCM53115",
  1521. .vlans = 4096,
  1522. .enabled_ports = 0x1f,
  1523. .arl_entries = 4,
  1524. .vta_regs = B53_VTA_REGS,
  1525. .cpu_port = B53_CPU_PORT,
  1526. .duplex_reg = B53_DUPLEX_STAT_GE,
  1527. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1528. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1529. },
  1530. {
  1531. .chip_id = BCM53125_DEVICE_ID,
  1532. .dev_name = "BCM53125",
  1533. .vlans = 4096,
  1534. .enabled_ports = 0xff,
  1535. .arl_entries = 4,
  1536. .cpu_port = B53_CPU_PORT,
  1537. .vta_regs = B53_VTA_REGS,
  1538. .duplex_reg = B53_DUPLEX_STAT_GE,
  1539. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1540. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1541. },
  1542. {
  1543. .chip_id = BCM53128_DEVICE_ID,
  1544. .dev_name = "BCM53128",
  1545. .vlans = 4096,
  1546. .enabled_ports = 0x1ff,
  1547. .arl_entries = 4,
  1548. .cpu_port = B53_CPU_PORT,
  1549. .vta_regs = B53_VTA_REGS,
  1550. .duplex_reg = B53_DUPLEX_STAT_GE,
  1551. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1552. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1553. },
  1554. {
  1555. .chip_id = BCM63XX_DEVICE_ID,
  1556. .dev_name = "BCM63xx",
  1557. .vlans = 4096,
  1558. .enabled_ports = 0, /* pdata must provide them */
  1559. .arl_entries = 4,
  1560. .cpu_port = B53_CPU_PORT,
  1561. .vta_regs = B53_VTA_REGS_63XX,
  1562. .duplex_reg = B53_DUPLEX_STAT_63XX,
  1563. .jumbo_pm_reg = B53_JUMBO_PORT_MASK_63XX,
  1564. .jumbo_size_reg = B53_JUMBO_MAX_SIZE_63XX,
  1565. },
  1566. {
  1567. .chip_id = BCM53010_DEVICE_ID,
  1568. .dev_name = "BCM53010",
  1569. .vlans = 4096,
  1570. .enabled_ports = 0x1f,
  1571. .arl_entries = 4,
  1572. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1573. .vta_regs = B53_VTA_REGS,
  1574. .duplex_reg = B53_DUPLEX_STAT_GE,
  1575. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1576. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1577. },
  1578. {
  1579. .chip_id = BCM53011_DEVICE_ID,
  1580. .dev_name = "BCM53011",
  1581. .vlans = 4096,
  1582. .enabled_ports = 0x1bf,
  1583. .arl_entries = 4,
  1584. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1585. .vta_regs = B53_VTA_REGS,
  1586. .duplex_reg = B53_DUPLEX_STAT_GE,
  1587. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1588. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1589. },
  1590. {
  1591. .chip_id = BCM53012_DEVICE_ID,
  1592. .dev_name = "BCM53012",
  1593. .vlans = 4096,
  1594. .enabled_ports = 0x1bf,
  1595. .arl_entries = 4,
  1596. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1597. .vta_regs = B53_VTA_REGS,
  1598. .duplex_reg = B53_DUPLEX_STAT_GE,
  1599. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1600. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1601. },
  1602. {
  1603. .chip_id = BCM53018_DEVICE_ID,
  1604. .dev_name = "BCM53018",
  1605. .vlans = 4096,
  1606. .enabled_ports = 0x1f,
  1607. .arl_entries = 4,
  1608. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1609. .vta_regs = B53_VTA_REGS,
  1610. .duplex_reg = B53_DUPLEX_STAT_GE,
  1611. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1612. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1613. },
  1614. {
  1615. .chip_id = BCM53019_DEVICE_ID,
  1616. .dev_name = "BCM53019",
  1617. .vlans = 4096,
  1618. .enabled_ports = 0x1f,
  1619. .arl_entries = 4,
  1620. .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
  1621. .vta_regs = B53_VTA_REGS,
  1622. .duplex_reg = B53_DUPLEX_STAT_GE,
  1623. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1624. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1625. },
  1626. {
  1627. .chip_id = BCM58XX_DEVICE_ID,
  1628. .dev_name = "BCM585xx/586xx/88312",
  1629. .vlans = 4096,
  1630. .enabled_ports = 0x1ff,
  1631. .arl_entries = 4,
  1632. .cpu_port = B53_CPU_PORT,
  1633. .vta_regs = B53_VTA_REGS,
  1634. .duplex_reg = B53_DUPLEX_STAT_GE,
  1635. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1636. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1637. },
  1638. {
  1639. .chip_id = BCM583XX_DEVICE_ID,
  1640. .dev_name = "BCM583xx/11360",
  1641. .vlans = 4096,
  1642. .enabled_ports = 0x103,
  1643. .arl_entries = 4,
  1644. .cpu_port = B53_CPU_PORT,
  1645. .vta_regs = B53_VTA_REGS,
  1646. .duplex_reg = B53_DUPLEX_STAT_GE,
  1647. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1648. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1649. },
  1650. {
  1651. .chip_id = BCM7445_DEVICE_ID,
  1652. .dev_name = "BCM7445",
  1653. .vlans = 4096,
  1654. .enabled_ports = 0x1ff,
  1655. .arl_entries = 4,
  1656. .cpu_port = B53_CPU_PORT,
  1657. .vta_regs = B53_VTA_REGS,
  1658. .duplex_reg = B53_DUPLEX_STAT_GE,
  1659. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1660. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1661. },
  1662. {
  1663. .chip_id = BCM7278_DEVICE_ID,
  1664. .dev_name = "BCM7278",
  1665. .vlans = 4096,
  1666. .enabled_ports = 0x1ff,
  1667. .arl_entries= 4,
  1668. .cpu_port = B53_CPU_PORT,
  1669. .vta_regs = B53_VTA_REGS,
  1670. .duplex_reg = B53_DUPLEX_STAT_GE,
  1671. .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
  1672. .jumbo_size_reg = B53_JUMBO_MAX_SIZE,
  1673. },
  1674. };
  1675. static int b53_switch_init(struct b53_device *dev)
  1676. {
  1677. unsigned int i;
  1678. int ret;
  1679. for (i = 0; i < ARRAY_SIZE(b53_switch_chips); i++) {
  1680. const struct b53_chip_data *chip = &b53_switch_chips[i];
  1681. if (chip->chip_id == dev->chip_id) {
  1682. if (!dev->enabled_ports)
  1683. dev->enabled_ports = chip->enabled_ports;
  1684. dev->name = chip->dev_name;
  1685. dev->duplex_reg = chip->duplex_reg;
  1686. dev->vta_regs[0] = chip->vta_regs[0];
  1687. dev->vta_regs[1] = chip->vta_regs[1];
  1688. dev->vta_regs[2] = chip->vta_regs[2];
  1689. dev->jumbo_pm_reg = chip->jumbo_pm_reg;
  1690. dev->cpu_port = chip->cpu_port;
  1691. dev->num_vlans = chip->vlans;
  1692. dev->num_arl_entries = chip->arl_entries;
  1693. break;
  1694. }
  1695. }
  1696. /* check which BCM5325x version we have */
  1697. if (is5325(dev)) {
  1698. u8 vc4;
  1699. b53_read8(dev, B53_VLAN_PAGE, B53_VLAN_CTRL4_25, &vc4);
  1700. /* check reserved bits */
  1701. switch (vc4 & 3) {
  1702. case 1:
  1703. /* BCM5325E */
  1704. break;
  1705. case 3:
  1706. /* BCM5325F - do not use port 4 */
  1707. dev->enabled_ports &= ~BIT(4);
  1708. break;
  1709. default:
  1710. /* On the BCM47XX SoCs this is the supported internal switch.*/
  1711. #ifndef CONFIG_BCM47XX
  1712. /* BCM5325M */
  1713. return -EINVAL;
  1714. #else
  1715. break;
  1716. #endif
  1717. }
  1718. } else if (dev->chip_id == BCM53115_DEVICE_ID) {
  1719. u64 strap_value;
  1720. b53_read48(dev, B53_STAT_PAGE, B53_STRAP_VALUE, &strap_value);
  1721. /* use second IMP port if GMII is enabled */
  1722. if (strap_value & SV_GMII_CTRL_115)
  1723. dev->cpu_port = 5;
  1724. }
  1725. /* cpu port is always last */
  1726. dev->num_ports = dev->cpu_port + 1;
  1727. dev->enabled_ports |= BIT(dev->cpu_port);
  1728. /* Include non standard CPU port built-in PHYs to be probed */
  1729. if (is539x(dev) || is531x5(dev)) {
  1730. for (i = 0; i < dev->num_ports; i++) {
  1731. if (!(dev->ds->phys_mii_mask & BIT(i)) &&
  1732. !b53_possible_cpu_port(dev->ds, i))
  1733. dev->ds->phys_mii_mask |= BIT(i);
  1734. }
  1735. }
  1736. dev->ports = devm_kcalloc(dev->dev,
  1737. dev->num_ports, sizeof(struct b53_port),
  1738. GFP_KERNEL);
  1739. if (!dev->ports)
  1740. return -ENOMEM;
  1741. dev->vlans = devm_kcalloc(dev->dev,
  1742. dev->num_vlans, sizeof(struct b53_vlan),
  1743. GFP_KERNEL);
  1744. if (!dev->vlans)
  1745. return -ENOMEM;
  1746. dev->reset_gpio = b53_switch_get_reset_gpio(dev);
  1747. if (dev->reset_gpio >= 0) {
  1748. ret = devm_gpio_request_one(dev->dev, dev->reset_gpio,
  1749. GPIOF_OUT_INIT_HIGH, "robo_reset");
  1750. if (ret)
  1751. return ret;
  1752. }
  1753. return 0;
  1754. }
  1755. struct b53_device *b53_switch_alloc(struct device *base,
  1756. const struct b53_io_ops *ops,
  1757. void *priv)
  1758. {
  1759. struct dsa_switch *ds;
  1760. struct b53_device *dev;
  1761. ds = dsa_switch_alloc(base, DSA_MAX_PORTS);
  1762. if (!ds)
  1763. return NULL;
  1764. dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
  1765. if (!dev)
  1766. return NULL;
  1767. ds->priv = dev;
  1768. dev->dev = base;
  1769. dev->ds = ds;
  1770. dev->priv = priv;
  1771. dev->ops = ops;
  1772. ds->ops = &b53_switch_ops;
  1773. mutex_init(&dev->reg_mutex);
  1774. mutex_init(&dev->stats_mutex);
  1775. return dev;
  1776. }
  1777. EXPORT_SYMBOL(b53_switch_alloc);
  1778. int b53_switch_detect(struct b53_device *dev)
  1779. {
  1780. u32 id32;
  1781. u16 tmp;
  1782. u8 id8;
  1783. int ret;
  1784. ret = b53_read8(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id8);
  1785. if (ret)
  1786. return ret;
  1787. switch (id8) {
  1788. case 0:
  1789. /* BCM5325 and BCM5365 do not have this register so reads
  1790. * return 0. But the read operation did succeed, so assume this
  1791. * is one of them.
  1792. *
  1793. * Next check if we can write to the 5325's VTA register; for
  1794. * 5365 it is read only.
  1795. */
  1796. b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf);
  1797. b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp);
  1798. if (tmp == 0xf)
  1799. dev->chip_id = BCM5325_DEVICE_ID;
  1800. else
  1801. dev->chip_id = BCM5365_DEVICE_ID;
  1802. break;
  1803. case BCM5389_DEVICE_ID:
  1804. case BCM5395_DEVICE_ID:
  1805. case BCM5397_DEVICE_ID:
  1806. case BCM5398_DEVICE_ID:
  1807. dev->chip_id = id8;
  1808. break;
  1809. default:
  1810. ret = b53_read32(dev, B53_MGMT_PAGE, B53_DEVICE_ID, &id32);
  1811. if (ret)
  1812. return ret;
  1813. switch (id32) {
  1814. case BCM53115_DEVICE_ID:
  1815. case BCM53125_DEVICE_ID:
  1816. case BCM53128_DEVICE_ID:
  1817. case BCM53010_DEVICE_ID:
  1818. case BCM53011_DEVICE_ID:
  1819. case BCM53012_DEVICE_ID:
  1820. case BCM53018_DEVICE_ID:
  1821. case BCM53019_DEVICE_ID:
  1822. dev->chip_id = id32;
  1823. break;
  1824. default:
  1825. pr_err("unsupported switch detected (BCM53%02x/BCM%x)\n",
  1826. id8, id32);
  1827. return -ENODEV;
  1828. }
  1829. }
  1830. if (dev->chip_id == BCM5325_DEVICE_ID)
  1831. return b53_read8(dev, B53_STAT_PAGE, B53_REV_ID_25,
  1832. &dev->core_rev);
  1833. else
  1834. return b53_read8(dev, B53_MGMT_PAGE, B53_REV_ID,
  1835. &dev->core_rev);
  1836. }
  1837. EXPORT_SYMBOL(b53_switch_detect);
  1838. int b53_switch_register(struct b53_device *dev)
  1839. {
  1840. int ret;
  1841. if (dev->pdata) {
  1842. dev->chip_id = dev->pdata->chip_id;
  1843. dev->enabled_ports = dev->pdata->enabled_ports;
  1844. }
  1845. if (!dev->chip_id && b53_switch_detect(dev))
  1846. return -EINVAL;
  1847. ret = b53_switch_init(dev);
  1848. if (ret)
  1849. return ret;
  1850. pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev);
  1851. return dsa_register_switch(dev->ds);
  1852. }
  1853. EXPORT_SYMBOL(b53_switch_register);
  1854. MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>");
  1855. MODULE_DESCRIPTION("B53 switch library");
  1856. MODULE_LICENSE("Dual BSD/GPL");