rtl8367b.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. /*
  2. * Platform driver for the Realtek RTL8367R-VB ethernet switches
  3. *
  4. * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. #include <linux/of.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/delay.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/rtl8367.h>
  19. #include "rtl8366_smi.h"
  20. #define RTL8367B_RESET_DELAY 1000 /* msecs*/
  21. #define RTL8367B_PHY_ADDR_MAX 8
  22. #define RTL8367B_PHY_REG_MAX 31
  23. #define RTL8367B_VID_MASK 0x3fff
  24. #define RTL8367B_FID_MASK 0xf
  25. #define RTL8367B_UNTAG_MASK 0xff
  26. #define RTL8367B_MEMBER_MASK 0xff
  27. #define RTL8367B_PORT_MISC_CFG_REG(_p) (0x000e + 0x20 * (_p))
  28. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_SHIFT 4
  29. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_MASK 0x3
  30. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_ORIGINAL 0
  31. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_KEEP 1
  32. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_PRI 2
  33. #define RTL8367B_PORT_MISC_CFG_EGRESS_MODE_REAL 3
  34. #define RTL8367B_BYPASS_LINE_RATE_REG 0x03f7
  35. #define RTL8367B_TA_CTRL_REG 0x0500 /*GOOD*/
  36. #define RTL8367B_TA_CTRL_SPA_SHIFT 8
  37. #define RTL8367B_TA_CTRL_SPA_MASK 0x7
  38. #define RTL8367B_TA_CTRL_METHOD BIT(4)/*GOOD*/
  39. #define RTL8367B_TA_CTRL_CMD_SHIFT 3
  40. #define RTL8367B_TA_CTRL_CMD_READ 0
  41. #define RTL8367B_TA_CTRL_CMD_WRITE 1
  42. #define RTL8367B_TA_CTRL_TABLE_SHIFT 0 /*GOOD*/
  43. #define RTL8367B_TA_CTRL_TABLE_ACLRULE 1
  44. #define RTL8367B_TA_CTRL_TABLE_ACLACT 2
  45. #define RTL8367B_TA_CTRL_TABLE_CVLAN 3
  46. #define RTL8367B_TA_CTRL_TABLE_L2 4
  47. #define RTL8367B_TA_CTRL_CVLAN_READ \
  48. ((RTL8367B_TA_CTRL_CMD_READ << RTL8367B_TA_CTRL_CMD_SHIFT) | \
  49. RTL8367B_TA_CTRL_TABLE_CVLAN)
  50. #define RTL8367B_TA_CTRL_CVLAN_WRITE \
  51. ((RTL8367B_TA_CTRL_CMD_WRITE << RTL8367B_TA_CTRL_CMD_SHIFT) | \
  52. RTL8367B_TA_CTRL_TABLE_CVLAN)
  53. #define RTL8367B_TA_ADDR_REG 0x0501/*GOOD*/
  54. #define RTL8367B_TA_ADDR_MASK 0x3fff/*GOOD*/
  55. #define RTL8367B_TA_LUT_REG 0x0502/*GOOD*/
  56. #define RTL8367B_TA_WRDATA_REG(_x) (0x0510 + (_x))/*GOOD*/
  57. #define RTL8367B_TA_VLAN_NUM_WORDS 2
  58. #define RTL8367B_TA_VLAN_VID_MASK RTL8367B_VID_MASK
  59. #define RTL8367B_TA_VLAN0_MEMBER_SHIFT 0
  60. #define RTL8367B_TA_VLAN0_MEMBER_MASK RTL8367B_MEMBER_MASK
  61. #define RTL8367B_TA_VLAN0_UNTAG_SHIFT 8
  62. #define RTL8367B_TA_VLAN0_UNTAG_MASK RTL8367B_MEMBER_MASK
  63. #define RTL8367B_TA_VLAN1_FID_SHIFT 0
  64. #define RTL8367B_TA_VLAN1_FID_MASK RTL8367B_FID_MASK
  65. #define RTL8367B_TA_RDDATA_REG(_x) (0x0520 + (_x))/*GOOD*/
  66. #define RTL8367B_VLAN_PVID_CTRL_REG(_p) (0x0700 + (_p) / 2) /*GOOD*/
  67. #define RTL8367B_VLAN_PVID_CTRL_MASK 0x1f /*GOOD*/
  68. #define RTL8367B_VLAN_PVID_CTRL_SHIFT(_p) (8 * ((_p) % 2)) /*GOOD*/
  69. #define RTL8367B_VLAN_MC_BASE(_x) (0x0728 + (_x) * 4) /*GOOD*/
  70. #define RTL8367B_VLAN_MC_NUM_WORDS 4 /*GOOD*/
  71. #define RTL8367B_VLAN_MC0_MEMBER_SHIFT 0/*GOOD*/
  72. #define RTL8367B_VLAN_MC0_MEMBER_MASK RTL8367B_MEMBER_MASK/*GOOD*/
  73. #define RTL8367B_VLAN_MC1_FID_SHIFT 0/*GOOD*/
  74. #define RTL8367B_VLAN_MC1_FID_MASK RTL8367B_FID_MASK/*GOOD*/
  75. #define RTL8367B_VLAN_MC3_EVID_SHIFT 0/*GOOD*/
  76. #define RTL8367B_VLAN_MC3_EVID_MASK RTL8367B_VID_MASK/*GOOD*/
  77. #define RTL8367B_VLAN_CTRL_REG 0x07a8 /*GOOD*/
  78. #define RTL8367B_VLAN_CTRL_ENABLE BIT(0)
  79. #define RTL8367B_VLAN_INGRESS_REG 0x07a9 /*GOOD*/
  80. #define RTL8367B_PORT_ISOLATION_REG(_p) (0x08a2 + (_p)) /*GOOD*/
  81. #define RTL8367B_MIB_COUNTER_REG(_x) (0x1000 + (_x)) /*GOOD*/
  82. #define RTL8367B_MIB_COUNTER_PORT_OFFSET 0x007c /*GOOD*/
  83. #define RTL8367B_MIB_ADDRESS_REG 0x1004 /*GOOD*/
  84. #define RTL8367B_MIB_CTRL0_REG(_x) (0x1005 + (_x)) /*GOOD*/
  85. #define RTL8367B_MIB_CTRL0_GLOBAL_RESET_MASK BIT(11) /*GOOD*/
  86. #define RTL8367B_MIB_CTRL0_QM_RESET_MASK BIT(10) /*GOOD*/
  87. #define RTL8367B_MIB_CTRL0_PORT_RESET_MASK(_p) BIT(2 + (_p)) /*GOOD*/
  88. #define RTL8367B_MIB_CTRL0_RESET_MASK BIT(1) /*GOOD*/
  89. #define RTL8367B_MIB_CTRL0_BUSY_MASK BIT(0) /*GOOD*/
  90. #define RTL8367B_SWC0_REG 0x1200/*GOOD*/
  91. #define RTL8367B_SWC0_MAX_LENGTH_SHIFT 13/*GOOD*/
  92. #define RTL8367B_SWC0_MAX_LENGTH(_x) ((_x) << 13) /*GOOD*/
  93. #define RTL8367B_SWC0_MAX_LENGTH_MASK RTL8367B_SWC0_MAX_LENGTH(0x3)
  94. #define RTL8367B_SWC0_MAX_LENGTH_1522 RTL8367B_SWC0_MAX_LENGTH(0)
  95. #define RTL8367B_SWC0_MAX_LENGTH_1536 RTL8367B_SWC0_MAX_LENGTH(1)
  96. #define RTL8367B_SWC0_MAX_LENGTH_1552 RTL8367B_SWC0_MAX_LENGTH(2)
  97. #define RTL8367B_SWC0_MAX_LENGTH_16000 RTL8367B_SWC0_MAX_LENGTH(3)
  98. #define RTL8367B_CHIP_NUMBER_REG 0x1300/*GOOD*/
  99. #define RTL8367B_CHIP_VER_REG 0x1301/*GOOD*/
  100. #define RTL8367B_CHIP_VER_RLVID_SHIFT 12/*GOOD*/
  101. #define RTL8367B_CHIP_VER_RLVID_MASK 0xf/*GOOD*/
  102. #define RTL8367B_CHIP_VER_MCID_SHIFT 8/*GOOD*/
  103. #define RTL8367B_CHIP_VER_MCID_MASK 0xf/*GOOD*/
  104. #define RTL8367B_CHIP_VER_BOID_SHIFT 4/*GOOD*/
  105. #define RTL8367B_CHIP_VER_BOID_MASK 0xf/*GOOD*/
  106. #define RTL8367B_CHIP_VER_AFE_SHIFT 0/*GOOD*/
  107. #define RTL8367B_CHIP_VER_AFE_MASK 0x1/*GOOD*/
  108. #define RTL8367B_CHIP_MODE_REG 0x1302
  109. #define RTL8367B_CHIP_MODE_MASK 0x7
  110. #define RTL8367B_CHIP_DEBUG0_REG 0x1303
  111. #define RTL8367B_CHIP_DEBUG0_DUMMY0(_x) BIT(8 + (_x))
  112. #define RTL8367B_CHIP_DEBUG1_REG 0x1304
  113. #define RTL8367B_DIS_REG 0x1305
  114. #define RTL8367B_DIS_SKIP_MII_RXER(_x) BIT(12 + (_x))
  115. #define RTL8367B_DIS_RGMII_SHIFT(_x) (4 * (_x))
  116. #define RTL8367B_DIS_RGMII_MASK 0x7
  117. #define RTL8367B_EXT_RGMXF_REG(_x) (0x1306 + (_x))
  118. #define RTL8367B_EXT_RGMXF_DUMMY0_SHIFT 5
  119. #define RTL8367B_EXT_RGMXF_DUMMY0_MASK 0x7ff
  120. #define RTL8367B_EXT_RGMXF_TXDELAY_SHIFT 3
  121. #define RTL8367B_EXT_RGMXF_TXDELAY_MASK 1
  122. #define RTL8367B_EXT_RGMXF_RXDELAY_MASK 0x7
  123. #define RTL8367B_DI_FORCE_REG(_x) (0x1310 + (_x))
  124. #define RTL8367B_DI_FORCE_MODE BIT(12)
  125. #define RTL8367B_DI_FORCE_NWAY BIT(7)
  126. #define RTL8367B_DI_FORCE_TXPAUSE BIT(6)
  127. #define RTL8367B_DI_FORCE_RXPAUSE BIT(5)
  128. #define RTL8367B_DI_FORCE_LINK BIT(4)
  129. #define RTL8367B_DI_FORCE_DUPLEX BIT(2)
  130. #define RTL8367B_DI_FORCE_SPEED_MASK 3
  131. #define RTL8367B_DI_FORCE_SPEED_10 0
  132. #define RTL8367B_DI_FORCE_SPEED_100 1
  133. #define RTL8367B_DI_FORCE_SPEED_1000 2
  134. #define RTL8367B_MAC_FORCE_REG(_x) (0x1312 + (_x))
  135. #define RTL8367B_CHIP_RESET_REG 0x1322 /*GOOD*/
  136. #define RTL8367B_CHIP_RESET_SW BIT(1) /*GOOD*/
  137. #define RTL8367B_CHIP_RESET_HW BIT(0) /*GOOD*/
  138. #define RTL8367B_PORT_STATUS_REG(_p) (0x1352 + (_p)) /*GOOD*/
  139. #define RTL8367B_PORT_STATUS_EN_1000_SPI BIT(11) /*GOOD*/
  140. #define RTL8367B_PORT_STATUS_EN_100_SPI BIT(10)/*GOOD*/
  141. #define RTL8367B_PORT_STATUS_NWAY_FAULT BIT(9)/*GOOD*/
  142. #define RTL8367B_PORT_STATUS_LINK_MASTER BIT(8)/*GOOD*/
  143. #define RTL8367B_PORT_STATUS_NWAY BIT(7)/*GOOD*/
  144. #define RTL8367B_PORT_STATUS_TXPAUSE BIT(6)/*GOOD*/
  145. #define RTL8367B_PORT_STATUS_RXPAUSE BIT(5)/*GOOD*/
  146. #define RTL8367B_PORT_STATUS_LINK BIT(4)/*GOOD*/
  147. #define RTL8367B_PORT_STATUS_DUPLEX BIT(2)/*GOOD*/
  148. #define RTL8367B_PORT_STATUS_SPEED_MASK 0x0003/*GOOD*/
  149. #define RTL8367B_PORT_STATUS_SPEED_10 0/*GOOD*/
  150. #define RTL8367B_PORT_STATUS_SPEED_100 1/*GOOD*/
  151. #define RTL8367B_PORT_STATUS_SPEED_1000 2/*GOOD*/
  152. #define RTL8367B_RTL_MAGIC_ID_REG 0x13c2
  153. #define RTL8367B_RTL_MAGIC_ID_VAL 0x0249
  154. #define RTL8367B_IA_CTRL_REG 0x1f00
  155. #define RTL8367B_IA_CTRL_RW(_x) ((_x) << 1)
  156. #define RTL8367B_IA_CTRL_RW_READ RTL8367B_IA_CTRL_RW(0)
  157. #define RTL8367B_IA_CTRL_RW_WRITE RTL8367B_IA_CTRL_RW(1)
  158. #define RTL8367B_IA_CTRL_CMD_MASK BIT(0)
  159. #define RTL8367B_IA_STATUS_REG 0x1f01
  160. #define RTL8367B_IA_STATUS_PHY_BUSY BIT(2)
  161. #define RTL8367B_IA_STATUS_SDS_BUSY BIT(1)
  162. #define RTL8367B_IA_STATUS_MDX_BUSY BIT(0)
  163. #define RTL8367B_IA_ADDRESS_REG 0x1f02
  164. #define RTL8367B_IA_WRITE_DATA_REG 0x1f03
  165. #define RTL8367B_IA_READ_DATA_REG 0x1f04
  166. #define RTL8367B_INTERNAL_PHY_REG(_a, _r) (0x2000 + 32 * (_a) + (_r))
  167. #define RTL8367B_NUM_MIB_COUNTERS 58
  168. #define RTL8367B_CPU_PORT_NUM 5
  169. #define RTL8367B_NUM_PORTS 8
  170. #define RTL8367B_NUM_VLANS 32
  171. #define RTL8367B_NUM_VIDS 4096
  172. #define RTL8367B_PRIORITYMAX 7
  173. #define RTL8367B_FIDMAX 7
  174. #define RTL8367B_PORT_0 BIT(0)
  175. #define RTL8367B_PORT_1 BIT(1)
  176. #define RTL8367B_PORT_2 BIT(2)
  177. #define RTL8367B_PORT_3 BIT(3)
  178. #define RTL8367B_PORT_4 BIT(4)
  179. #define RTL8367B_PORT_E0 BIT(5) /* External port 0 */
  180. #define RTL8367B_PORT_E1 BIT(6) /* External port 1 */
  181. #define RTL8367B_PORT_E2 BIT(7) /* External port 2 */
  182. #define RTL8367B_PORTS_ALL \
  183. (RTL8367B_PORT_0 | RTL8367B_PORT_1 | RTL8367B_PORT_2 | \
  184. RTL8367B_PORT_3 | RTL8367B_PORT_4 | RTL8367B_PORT_E0 | \
  185. RTL8367B_PORT_E1 | RTL8367B_PORT_E2)
  186. #define RTL8367B_PORTS_ALL_BUT_CPU \
  187. (RTL8367B_PORT_0 | RTL8367B_PORT_1 | RTL8367B_PORT_2 | \
  188. RTL8367B_PORT_3 | RTL8367B_PORT_4 | RTL8367B_PORT_E1 | \
  189. RTL8367B_PORT_E2)
  190. struct rtl8367b_initval {
  191. u16 reg;
  192. u16 val;
  193. };
  194. #define RTL8367B_MIB_RXB_ID 0 /* IfInOctets */
  195. #define RTL8367B_MIB_TXB_ID 28 /* IfOutOctets */
  196. static struct rtl8366_mib_counter
  197. rtl8367b_mib_counters[RTL8367B_NUM_MIB_COUNTERS] = {
  198. {0, 0, 4, "ifInOctets" },
  199. {0, 4, 2, "dot3StatsFCSErrors" },
  200. {0, 6, 2, "dot3StatsSymbolErrors" },
  201. {0, 8, 2, "dot3InPauseFrames" },
  202. {0, 10, 2, "dot3ControlInUnknownOpcodes" },
  203. {0, 12, 2, "etherStatsFragments" },
  204. {0, 14, 2, "etherStatsJabbers" },
  205. {0, 16, 2, "ifInUcastPkts" },
  206. {0, 18, 2, "etherStatsDropEvents" },
  207. {0, 20, 2, "ifInMulticastPkts" },
  208. {0, 22, 2, "ifInBroadcastPkts" },
  209. {0, 24, 2, "inMldChecksumError" },
  210. {0, 26, 2, "inIgmpChecksumError" },
  211. {0, 28, 2, "inMldSpecificQuery" },
  212. {0, 30, 2, "inMldGeneralQuery" },
  213. {0, 32, 2, "inIgmpSpecificQuery" },
  214. {0, 34, 2, "inIgmpGeneralQuery" },
  215. {0, 36, 2, "inMldLeaves" },
  216. {0, 38, 2, "inIgmpLeaves" },
  217. {0, 40, 4, "etherStatsOctets" },
  218. {0, 44, 2, "etherStatsUnderSizePkts" },
  219. {0, 46, 2, "etherOversizeStats" },
  220. {0, 48, 2, "etherStatsPkts64Octets" },
  221. {0, 50, 2, "etherStatsPkts65to127Octets" },
  222. {0, 52, 2, "etherStatsPkts128to255Octets" },
  223. {0, 54, 2, "etherStatsPkts256to511Octets" },
  224. {0, 56, 2, "etherStatsPkts512to1023Octets" },
  225. {0, 58, 2, "etherStatsPkts1024to1518Octets" },
  226. {0, 60, 4, "ifOutOctets" },
  227. {0, 64, 2, "dot3StatsSingleCollisionFrames" },
  228. {0, 66, 2, "dot3StatMultipleCollisionFrames" },
  229. {0, 68, 2, "dot3sDeferredTransmissions" },
  230. {0, 70, 2, "dot3StatsLateCollisions" },
  231. {0, 72, 2, "etherStatsCollisions" },
  232. {0, 74, 2, "dot3StatsExcessiveCollisions" },
  233. {0, 76, 2, "dot3OutPauseFrames" },
  234. {0, 78, 2, "ifOutDiscards" },
  235. {0, 80, 2, "dot1dTpPortInDiscards" },
  236. {0, 82, 2, "ifOutUcastPkts" },
  237. {0, 84, 2, "ifOutMulticastPkts" },
  238. {0, 86, 2, "ifOutBroadcastPkts" },
  239. {0, 88, 2, "outOampduPkts" },
  240. {0, 90, 2, "inOampduPkts" },
  241. {0, 92, 2, "inIgmpJoinsSuccess" },
  242. {0, 94, 2, "inIgmpJoinsFail" },
  243. {0, 96, 2, "inMldJoinsSuccess" },
  244. {0, 98, 2, "inMldJoinsFail" },
  245. {0, 100, 2, "inReportSuppressionDrop" },
  246. {0, 102, 2, "inLeaveSuppressionDrop" },
  247. {0, 104, 2, "outIgmpReports" },
  248. {0, 106, 2, "outIgmpLeaves" },
  249. {0, 108, 2, "outIgmpGeneralQuery" },
  250. {0, 110, 2, "outIgmpSpecificQuery" },
  251. {0, 112, 2, "outMldReports" },
  252. {0, 114, 2, "outMldLeaves" },
  253. {0, 116, 2, "outMldGeneralQuery" },
  254. {0, 118, 2, "outMldSpecificQuery" },
  255. {0, 120, 2, "inKnownMulticastPkts" },
  256. };
  257. #define REG_RD(_smi, _reg, _val) \
  258. do { \
  259. err = rtl8366_smi_read_reg(_smi, _reg, _val); \
  260. if (err) \
  261. return err; \
  262. } while (0)
  263. #define REG_WR(_smi, _reg, _val) \
  264. do { \
  265. err = rtl8366_smi_write_reg(_smi, _reg, _val); \
  266. if (err) \
  267. return err; \
  268. } while (0)
  269. #define REG_RMW(_smi, _reg, _mask, _val) \
  270. do { \
  271. err = rtl8366_smi_rmwr(_smi, _reg, _mask, _val); \
  272. if (err) \
  273. return err; \
  274. } while (0)
  275. static const struct rtl8367b_initval rtl8367r_vb_initvals_0[] = {
  276. {0x1B03, 0x0876}, {0x1200, 0x7FC4}, {0x0301, 0x0026}, {0x1722, 0x0E14},
  277. {0x205F, 0x0002}, {0x2059, 0x1A00}, {0x205F, 0x0000}, {0x207F, 0x0002},
  278. {0x2077, 0x0000}, {0x2078, 0x0000}, {0x2079, 0x0000}, {0x207A, 0x0000},
  279. {0x207B, 0x0000}, {0x207F, 0x0000}, {0x205F, 0x0002}, {0x2053, 0x0000},
  280. {0x2054, 0x0000}, {0x2055, 0x0000}, {0x2056, 0x0000}, {0x2057, 0x0000},
  281. {0x205F, 0x0000}, {0x12A4, 0x110A}, {0x12A6, 0x150A}, {0x13F1, 0x0013},
  282. {0x13F4, 0x0010}, {0x13F5, 0x0000}, {0x0018, 0x0F00}, {0x0038, 0x0F00},
  283. {0x0058, 0x0F00}, {0x0078, 0x0F00}, {0x0098, 0x0F00}, {0x12B6, 0x0C02},
  284. {0x12B7, 0x030F}, {0x12B8, 0x11FF}, {0x12BC, 0x0004}, {0x1362, 0x0115},
  285. {0x1363, 0x0002}, {0x1363, 0x0000}, {0x133F, 0x0030}, {0x133E, 0x000E},
  286. {0x221F, 0x0007}, {0x221E, 0x002D}, {0x2218, 0xF030}, {0x221F, 0x0007},
  287. {0x221E, 0x0023}, {0x2216, 0x0005}, {0x2215, 0x00B9}, {0x2219, 0x0044},
  288. {0x2215, 0x00BA}, {0x2219, 0x0020}, {0x2215, 0x00BB}, {0x2219, 0x00C1},
  289. {0x2215, 0x0148}, {0x2219, 0x0096}, {0x2215, 0x016E}, {0x2219, 0x0026},
  290. {0x2216, 0x0000}, {0x2216, 0x0000}, {0x221E, 0x002D}, {0x2218, 0xF010},
  291. {0x221F, 0x0007}, {0x221E, 0x0020}, {0x2215, 0x0D00}, {0x221F, 0x0000},
  292. {0x221F, 0x0000}, {0x2217, 0x2160}, {0x221F, 0x0001}, {0x2210, 0xF25E},
  293. {0x221F, 0x0007}, {0x221E, 0x0042}, {0x2215, 0x0F00}, {0x2215, 0x0F00},
  294. {0x2216, 0x7408}, {0x2215, 0x0E00}, {0x2215, 0x0F00}, {0x2215, 0x0F01},
  295. {0x2216, 0x4000}, {0x2215, 0x0E01}, {0x2215, 0x0F01}, {0x2215, 0x0F02},
  296. {0x2216, 0x9400}, {0x2215, 0x0E02}, {0x2215, 0x0F02}, {0x2215, 0x0F03},
  297. {0x2216, 0x7408}, {0x2215, 0x0E03}, {0x2215, 0x0F03}, {0x2215, 0x0F04},
  298. {0x2216, 0x4008}, {0x2215, 0x0E04}, {0x2215, 0x0F04}, {0x2215, 0x0F05},
  299. {0x2216, 0x9400}, {0x2215, 0x0E05}, {0x2215, 0x0F05}, {0x2215, 0x0F06},
  300. {0x2216, 0x0803}, {0x2215, 0x0E06}, {0x2215, 0x0F06}, {0x2215, 0x0D00},
  301. {0x2215, 0x0100}, {0x221F, 0x0001}, {0x2210, 0xF05E}, {0x221F, 0x0000},
  302. {0x2217, 0x2100}, {0x221F, 0x0000}, {0x220D, 0x0003}, {0x220E, 0x0015},
  303. {0x220D, 0x4003}, {0x220E, 0x0006}, {0x221F, 0x0000}, {0x2200, 0x1340},
  304. {0x133F, 0x0010}, {0x12A0, 0x0058}, {0x12A1, 0x0058}, {0x133E, 0x000E},
  305. {0x133F, 0x0030}, {0x221F, 0x0000}, {0x2210, 0x0166}, {0x221F, 0x0000},
  306. {0x133E, 0x000E}, {0x133F, 0x0010}, {0x133F, 0x0030}, {0x133E, 0x000E},
  307. {0x221F, 0x0005}, {0x2205, 0xFFF6}, {0x2206, 0x0080}, {0x2205, 0x8B6E},
  308. {0x2206, 0x0000}, {0x220F, 0x0100}, {0x2205, 0x8000}, {0x2206, 0x0280},
  309. {0x2206, 0x28F7}, {0x2206, 0x00E0}, {0x2206, 0xFFF7}, {0x2206, 0xA080},
  310. {0x2206, 0x02AE}, {0x2206, 0xF602}, {0x2206, 0x0153}, {0x2206, 0x0201},
  311. {0x2206, 0x6602}, {0x2206, 0x80B9}, {0x2206, 0xE08B}, {0x2206, 0x8CE1},
  312. {0x2206, 0x8B8D}, {0x2206, 0x1E01}, {0x2206, 0xE18B}, {0x2206, 0x8E1E},
  313. {0x2206, 0x01A0}, {0x2206, 0x00E7}, {0x2206, 0xAEDB}, {0x2206, 0xEEE0},
  314. {0x2206, 0x120E}, {0x2206, 0xEEE0}, {0x2206, 0x1300}, {0x2206, 0xEEE0},
  315. {0x2206, 0x2001}, {0x2206, 0xEEE0}, {0x2206, 0x2166}, {0x2206, 0xEEE0},
  316. {0x2206, 0xC463}, {0x2206, 0xEEE0}, {0x2206, 0xC5E8}, {0x2206, 0xEEE0},
  317. {0x2206, 0xC699}, {0x2206, 0xEEE0}, {0x2206, 0xC7C2}, {0x2206, 0xEEE0},
  318. {0x2206, 0xC801}, {0x2206, 0xEEE0}, {0x2206, 0xC913}, {0x2206, 0xEEE0},
  319. {0x2206, 0xCA30}, {0x2206, 0xEEE0}, {0x2206, 0xCB3E}, {0x2206, 0xEEE0},
  320. {0x2206, 0xDCE1}, {0x2206, 0xEEE0}, {0x2206, 0xDD00}, {0x2206, 0xEEE2},
  321. {0x2206, 0x0001}, {0x2206, 0xEEE2}, {0x2206, 0x0100}, {0x2206, 0xEEE4},
  322. {0x2206, 0x8860}, {0x2206, 0xEEE4}, {0x2206, 0x8902}, {0x2206, 0xEEE4},
  323. {0x2206, 0x8C00}, {0x2206, 0xEEE4}, {0x2206, 0x8D30}, {0x2206, 0xEEEA},
  324. {0x2206, 0x1480}, {0x2206, 0xEEEA}, {0x2206, 0x1503}, {0x2206, 0xEEEA},
  325. {0x2206, 0xC600}, {0x2206, 0xEEEA}, {0x2206, 0xC706}, {0x2206, 0xEE85},
  326. {0x2206, 0xEE00}, {0x2206, 0xEE85}, {0x2206, 0xEF00}, {0x2206, 0xEE8B},
  327. {0x2206, 0x6750}, {0x2206, 0xEE8B}, {0x2206, 0x6632}, {0x2206, 0xEE8A},
  328. {0x2206, 0xD448}, {0x2206, 0xEE8A}, {0x2206, 0xD548}, {0x2206, 0xEE8A},
  329. {0x2206, 0xD649}, {0x2206, 0xEE8A}, {0x2206, 0xD7F8}, {0x2206, 0xEE8B},
  330. {0x2206, 0x85E2}, {0x2206, 0xEE8B}, {0x2206, 0x8700}, {0x2206, 0xEEFF},
  331. {0x2206, 0xF600}, {0x2206, 0xEEFF}, {0x2206, 0xF7FC}, {0x2206, 0x04F8},
  332. {0x2206, 0xE08B}, {0x2206, 0x8EAD}, {0x2206, 0x2023}, {0x2206, 0xF620},
  333. {0x2206, 0xE48B}, {0x2206, 0x8E02}, {0x2206, 0x2877}, {0x2206, 0x0225},
  334. {0x2206, 0xC702}, {0x2206, 0x26A1}, {0x2206, 0x0281}, {0x2206, 0xB302},
  335. {0x2206, 0x8496}, {0x2206, 0x0202}, {0x2206, 0xA102}, {0x2206, 0x27F1},
  336. {0x2206, 0x0228}, {0x2206, 0xF902}, {0x2206, 0x2AA0}, {0x2206, 0x0282},
  337. {0x2206, 0xB8E0}, {0x2206, 0x8B8E}, {0x2206, 0xAD21}, {0x2206, 0x08F6},
  338. {0x2206, 0x21E4}, {0x2206, 0x8B8E}, {0x2206, 0x0202}, {0x2206, 0x80E0},
  339. {0x2206, 0x8B8E}, {0x2206, 0xAD22}, {0x2206, 0x05F6}, {0x2206, 0x22E4},
  340. {0x2206, 0x8B8E}, {0x2206, 0xE08B}, {0x2206, 0x8EAD}, {0x2206, 0x2305},
  341. {0x2206, 0xF623}, {0x2206, 0xE48B}, {0x2206, 0x8EE0}, {0x2206, 0x8B8E},
  342. {0x2206, 0xAD24}, {0x2206, 0x08F6}, {0x2206, 0x24E4}, {0x2206, 0x8B8E},
  343. {0x2206, 0x0227}, {0x2206, 0x6AE0}, {0x2206, 0x8B8E}, {0x2206, 0xAD25},
  344. {0x2206, 0x05F6}, {0x2206, 0x25E4}, {0x2206, 0x8B8E}, {0x2206, 0xE08B},
  345. {0x2206, 0x8EAD}, {0x2206, 0x260B}, {0x2206, 0xF626}, {0x2206, 0xE48B},
  346. {0x2206, 0x8E02}, {0x2206, 0x830D}, {0x2206, 0x021D}, {0x2206, 0x6BE0},
  347. {0x2206, 0x8B8E}, {0x2206, 0xAD27}, {0x2206, 0x05F6}, {0x2206, 0x27E4},
  348. {0x2206, 0x8B8E}, {0x2206, 0x0281}, {0x2206, 0x4402}, {0x2206, 0x045C},
  349. {0x2206, 0xFC04}, {0x2206, 0xF8E0}, {0x2206, 0x8B83}, {0x2206, 0xAD23},
  350. {0x2206, 0x30E0}, {0x2206, 0xE022}, {0x2206, 0xE1E0}, {0x2206, 0x2359},
  351. {0x2206, 0x02E0}, {0x2206, 0x85EF}, {0x2206, 0xE585}, {0x2206, 0xEFAC},
  352. {0x2206, 0x2907}, {0x2206, 0x1F01}, {0x2206, 0x9E51}, {0x2206, 0xAD29},
  353. {0x2206, 0x20E0}, {0x2206, 0x8B83}, {0x2206, 0xAD21}, {0x2206, 0x06E1},
  354. {0x2206, 0x8B84}, {0x2206, 0xAD28}, {0x2206, 0x42E0}, {0x2206, 0x8B85},
  355. {0x2206, 0xAD21}, {0x2206, 0x06E1}, {0x2206, 0x8B84}, {0x2206, 0xAD29},
  356. {0x2206, 0x36BF}, {0x2206, 0x34BF}, {0x2206, 0x022C}, {0x2206, 0x31AE},
  357. {0x2206, 0x2EE0}, {0x2206, 0x8B83}, {0x2206, 0xAD21}, {0x2206, 0x10E0},
  358. {0x2206, 0x8B84}, {0x2206, 0xF620}, {0x2206, 0xE48B}, {0x2206, 0x84EE},
  359. {0x2206, 0x8ADA}, {0x2206, 0x00EE}, {0x2206, 0x8ADB}, {0x2206, 0x00E0},
  360. {0x2206, 0x8B85}, {0x2206, 0xAD21}, {0x2206, 0x0CE0}, {0x2206, 0x8B84},
  361. {0x2206, 0xF621}, {0x2206, 0xE48B}, {0x2206, 0x84EE}, {0x2206, 0x8B72},
  362. {0x2206, 0xFFBF}, {0x2206, 0x34C2}, {0x2206, 0x022C}, {0x2206, 0x31FC},
  363. {0x2206, 0x04F8}, {0x2206, 0xFAEF}, {0x2206, 0x69E0}, {0x2206, 0x8B85},
  364. {0x2206, 0xAD21}, {0x2206, 0x42E0}, {0x2206, 0xE022}, {0x2206, 0xE1E0},
  365. {0x2206, 0x2358}, {0x2206, 0xC059}, {0x2206, 0x021E}, {0x2206, 0x01E1},
  366. {0x2206, 0x8B72}, {0x2206, 0x1F10}, {0x2206, 0x9E2F}, {0x2206, 0xE48B},
  367. {0x2206, 0x72AD}, {0x2206, 0x2123}, {0x2206, 0xE18B}, {0x2206, 0x84F7},
  368. {0x2206, 0x29E5}, {0x2206, 0x8B84}, {0x2206, 0xAC27}, {0x2206, 0x10AC},
  369. {0x2206, 0x2605}, {0x2206, 0x0205}, {0x2206, 0x23AE}, {0x2206, 0x1602},
  370. {0x2206, 0x0535}, {0x2206, 0x0282}, {0x2206, 0x30AE}, {0x2206, 0x0E02},
  371. {0x2206, 0x056A}, {0x2206, 0x0282}, {0x2206, 0x75AE}, {0x2206, 0x0602},
  372. {0x2206, 0x04DC}, {0x2206, 0x0282}, {0x2206, 0x04EF}, {0x2206, 0x96FE},
  373. {0x2206, 0xFC04}, {0x2206, 0xF8F9}, {0x2206, 0xE08B}, {0x2206, 0x87AD},
  374. {0x2206, 0x2321}, {0x2206, 0xE0EA}, {0x2206, 0x14E1}, {0x2206, 0xEA15},
  375. {0x2206, 0xAD26}, {0x2206, 0x18F6}, {0x2206, 0x27E4}, {0x2206, 0xEA14},
  376. {0x2206, 0xE5EA}, {0x2206, 0x15F6}, {0x2206, 0x26E4}, {0x2206, 0xEA14},
  377. {0x2206, 0xE5EA}, {0x2206, 0x15F7}, {0x2206, 0x27E4}, {0x2206, 0xEA14},
  378. {0x2206, 0xE5EA}, {0x2206, 0x15FD}, {0x2206, 0xFC04}, {0x2206, 0xF8F9},
  379. {0x2206, 0xE08B}, {0x2206, 0x87AD}, {0x2206, 0x233A}, {0x2206, 0xAD22},
  380. {0x2206, 0x37E0}, {0x2206, 0xE020}, {0x2206, 0xE1E0}, {0x2206, 0x21AC},
  381. {0x2206, 0x212E}, {0x2206, 0xE0EA}, {0x2206, 0x14E1}, {0x2206, 0xEA15},
  382. {0x2206, 0xF627}, {0x2206, 0xE4EA}, {0x2206, 0x14E5}, {0x2206, 0xEA15},
  383. {0x2206, 0xE2EA}, {0x2206, 0x12E3}, {0x2206, 0xEA13}, {0x2206, 0x5A8F},
  384. {0x2206, 0x6A20}, {0x2206, 0xE6EA}, {0x2206, 0x12E7}, {0x2206, 0xEA13},
  385. {0x2206, 0xF726}, {0x2206, 0xE4EA}, {0x2206, 0x14E5}, {0x2206, 0xEA15},
  386. {0x2206, 0xF727}, {0x2206, 0xE4EA}, {0x2206, 0x14E5}, {0x2206, 0xEA15},
  387. {0x2206, 0xFDFC}, {0x2206, 0x04F8}, {0x2206, 0xF9E0}, {0x2206, 0x8B87},
  388. {0x2206, 0xAD23}, {0x2206, 0x38AD}, {0x2206, 0x2135}, {0x2206, 0xE0E0},
  389. {0x2206, 0x20E1}, {0x2206, 0xE021}, {0x2206, 0xAC21}, {0x2206, 0x2CE0},
  390. {0x2206, 0xEA14}, {0x2206, 0xE1EA}, {0x2206, 0x15F6}, {0x2206, 0x27E4},
  391. {0x2206, 0xEA14}, {0x2206, 0xE5EA}, {0x2206, 0x15E2}, {0x2206, 0xEA12},
  392. {0x2206, 0xE3EA}, {0x2206, 0x135A}, {0x2206, 0x8FE6}, {0x2206, 0xEA12},
  393. {0x2206, 0xE7EA}, {0x2206, 0x13F7}, {0x2206, 0x26E4}, {0x2206, 0xEA14},
  394. {0x2206, 0xE5EA}, {0x2206, 0x15F7}, {0x2206, 0x27E4}, {0x2206, 0xEA14},
  395. {0x2206, 0xE5EA}, {0x2206, 0x15FD}, {0x2206, 0xFC04}, {0x2206, 0xF8FA},
  396. {0x2206, 0xEF69}, {0x2206, 0xE08B}, {0x2206, 0x86AD}, {0x2206, 0x2146},
  397. {0x2206, 0xE0E0}, {0x2206, 0x22E1}, {0x2206, 0xE023}, {0x2206, 0x58C0},
  398. {0x2206, 0x5902}, {0x2206, 0x1E01}, {0x2206, 0xE18B}, {0x2206, 0x651F},
  399. {0x2206, 0x109E}, {0x2206, 0x33E4}, {0x2206, 0x8B65}, {0x2206, 0xAD21},
  400. {0x2206, 0x22AD}, {0x2206, 0x272A}, {0x2206, 0xD400}, {0x2206, 0x01BF},
  401. {0x2206, 0x34F2}, {0x2206, 0x022C}, {0x2206, 0xA2BF}, {0x2206, 0x34F5},
  402. {0x2206, 0x022C}, {0x2206, 0xE0E0}, {0x2206, 0x8B67}, {0x2206, 0x1B10},
  403. {0x2206, 0xAA14}, {0x2206, 0xE18B}, {0x2206, 0x660D}, {0x2206, 0x1459},
  404. {0x2206, 0x0FAE}, {0x2206, 0x05E1}, {0x2206, 0x8B66}, {0x2206, 0x590F},
  405. {0x2206, 0xBF85}, {0x2206, 0x6102}, {0x2206, 0x2CA2}, {0x2206, 0xEF96},
  406. {0x2206, 0xFEFC}, {0x2206, 0x04F8}, {0x2206, 0xF9FA}, {0x2206, 0xFBEF},
  407. {0x2206, 0x79E2}, {0x2206, 0x8AD2}, {0x2206, 0xAC19}, {0x2206, 0x2DE0},
  408. {0x2206, 0xE036}, {0x2206, 0xE1E0}, {0x2206, 0x37EF}, {0x2206, 0x311F},
  409. {0x2206, 0x325B}, {0x2206, 0x019E}, {0x2206, 0x1F7A}, {0x2206, 0x0159},
  410. {0x2206, 0x019F}, {0x2206, 0x0ABF}, {0x2206, 0x348E}, {0x2206, 0x022C},
  411. {0x2206, 0x31F6}, {0x2206, 0x06AE}, {0x2206, 0x0FF6}, {0x2206, 0x0302},
  412. {0x2206, 0x0470}, {0x2206, 0xF703}, {0x2206, 0xF706}, {0x2206, 0xBF34},
  413. {0x2206, 0x9302}, {0x2206, 0x2C31}, {0x2206, 0xAC1A}, {0x2206, 0x25E0},
  414. {0x2206, 0xE022}, {0x2206, 0xE1E0}, {0x2206, 0x23EF}, {0x2206, 0x300D},
  415. {0x2206, 0x311F}, {0x2206, 0x325B}, {0x2206, 0x029E}, {0x2206, 0x157A},
  416. {0x2206, 0x0258}, {0x2206, 0xC4A0}, {0x2206, 0x0408}, {0x2206, 0xBF34},
  417. {0x2206, 0x9E02}, {0x2206, 0x2C31}, {0x2206, 0xAE06}, {0x2206, 0xBF34},
  418. {0x2206, 0x9C02}, {0x2206, 0x2C31}, {0x2206, 0xAC1B}, {0x2206, 0x4AE0},
  419. {0x2206, 0xE012}, {0x2206, 0xE1E0}, {0x2206, 0x13EF}, {0x2206, 0x300D},
  420. {0x2206, 0x331F}, {0x2206, 0x325B}, {0x2206, 0x1C9E}, {0x2206, 0x3AEF},
  421. {0x2206, 0x325B}, {0x2206, 0x1C9F}, {0x2206, 0x09BF}, {0x2206, 0x3498},
  422. {0x2206, 0x022C}, {0x2206, 0x3102}, {0x2206, 0x83C5}, {0x2206, 0x5A03},
  423. {0x2206, 0x0D03}, {0x2206, 0x581C}, {0x2206, 0x1E20}, {0x2206, 0x0207},
  424. {0x2206, 0xA0A0}, {0x2206, 0x000E}, {0x2206, 0x0284}, {0x2206, 0x17AD},
  425. {0x2206, 0x1817}, {0x2206, 0xBF34}, {0x2206, 0x9A02}, {0x2206, 0x2C31},
  426. {0x2206, 0xAE0F}, {0x2206, 0xBF34}, {0x2206, 0xC802}, {0x2206, 0x2C31},
  427. {0x2206, 0xBF34}, {0x2206, 0xC502}, {0x2206, 0x2C31}, {0x2206, 0x0284},
  428. {0x2206, 0x52E6}, {0x2206, 0x8AD2}, {0x2206, 0xEF97}, {0x2206, 0xFFFE},
  429. {0x2206, 0xFDFC}, {0x2206, 0x04F8}, {0x2206, 0xBF34}, {0x2206, 0xDA02},
  430. {0x2206, 0x2CE0}, {0x2206, 0xE58A}, {0x2206, 0xD3BF}, {0x2206, 0x34D4},
  431. {0x2206, 0x022C}, {0x2206, 0xE00C}, {0x2206, 0x1159}, {0x2206, 0x02E0},
  432. {0x2206, 0x8AD3}, {0x2206, 0x1E01}, {0x2206, 0xE48A}, {0x2206, 0xD3D1},
  433. {0x2206, 0x00BF}, {0x2206, 0x34DA}, {0x2206, 0x022C}, {0x2206, 0xA2D1},
  434. {0x2206, 0x01BF}, {0x2206, 0x34D4}, {0x2206, 0x022C}, {0x2206, 0xA2BF},
  435. {0x2206, 0x34CB}, {0x2206, 0x022C}, {0x2206, 0xE0E5}, {0x2206, 0x8ACE},
  436. {0x2206, 0xBF85}, {0x2206, 0x6702}, {0x2206, 0x2CE0}, {0x2206, 0xE58A},
  437. {0x2206, 0xCFBF}, {0x2206, 0x8564}, {0x2206, 0x022C}, {0x2206, 0xE0E5},
  438. {0x2206, 0x8AD0}, {0x2206, 0xBF85}, {0x2206, 0x6A02}, {0x2206, 0x2CE0},
  439. {0x2206, 0xE58A}, {0x2206, 0xD1FC}, {0x2206, 0x04F8}, {0x2206, 0xE18A},
  440. {0x2206, 0xD1BF}, {0x2206, 0x856A}, {0x2206, 0x022C}, {0x2206, 0xA2E1},
  441. {0x2206, 0x8AD0}, {0x2206, 0xBF85}, {0x2206, 0x6402}, {0x2206, 0x2CA2},
  442. {0x2206, 0xE18A}, {0x2206, 0xCFBF}, {0x2206, 0x8567}, {0x2206, 0x022C},
  443. {0x2206, 0xA2E1}, {0x2206, 0x8ACE}, {0x2206, 0xBF34}, {0x2206, 0xCB02},
  444. {0x2206, 0x2CA2}, {0x2206, 0xE18A}, {0x2206, 0xD3BF}, {0x2206, 0x34DA},
  445. {0x2206, 0x022C}, {0x2206, 0xA2E1}, {0x2206, 0x8AD3}, {0x2206, 0x0D11},
  446. {0x2206, 0xBF34}, {0x2206, 0xD402}, {0x2206, 0x2CA2}, {0x2206, 0xFC04},
  447. {0x2206, 0xF9A0}, {0x2206, 0x0405}, {0x2206, 0xE38A}, {0x2206, 0xD4AE},
  448. {0x2206, 0x13A0}, {0x2206, 0x0805}, {0x2206, 0xE38A}, {0x2206, 0xD5AE},
  449. {0x2206, 0x0BA0}, {0x2206, 0x0C05}, {0x2206, 0xE38A}, {0x2206, 0xD6AE},
  450. {0x2206, 0x03E3}, {0x2206, 0x8AD7}, {0x2206, 0xEF13}, {0x2206, 0xBF34},
  451. {0x2206, 0xCB02}, {0x2206, 0x2CA2}, {0x2206, 0xEF13}, {0x2206, 0x0D11},
  452. {0x2206, 0xBF85}, {0x2206, 0x6702}, {0x2206, 0x2CA2}, {0x2206, 0xEF13},
  453. {0x2206, 0x0D14}, {0x2206, 0xBF85}, {0x2206, 0x6402}, {0x2206, 0x2CA2},
  454. {0x2206, 0xEF13}, {0x2206, 0x0D17}, {0x2206, 0xBF85}, {0x2206, 0x6A02},
  455. {0x2206, 0x2CA2}, {0x2206, 0xFD04}, {0x2206, 0xF8E0}, {0x2206, 0x8B85},
  456. {0x2206, 0xAD27}, {0x2206, 0x2DE0}, {0x2206, 0xE036}, {0x2206, 0xE1E0},
  457. {0x2206, 0x37E1}, {0x2206, 0x8B73}, {0x2206, 0x1F10}, {0x2206, 0x9E20},
  458. {0x2206, 0xE48B}, {0x2206, 0x73AC}, {0x2206, 0x200B}, {0x2206, 0xAC21},
  459. {0x2206, 0x0DAC}, {0x2206, 0x250F}, {0x2206, 0xAC27}, {0x2206, 0x0EAE},
  460. {0x2206, 0x0F02}, {0x2206, 0x84CC}, {0x2206, 0xAE0A}, {0x2206, 0x0284},
  461. {0x2206, 0xD1AE}, {0x2206, 0x05AE}, {0x2206, 0x0302}, {0x2206, 0x84D8},
  462. {0x2206, 0xFC04}, {0x2206, 0xEE8B}, {0x2206, 0x6800}, {0x2206, 0x0402},
  463. {0x2206, 0x84E5}, {0x2206, 0x0285}, {0x2206, 0x2804}, {0x2206, 0x0285},
  464. {0x2206, 0x4904}, {0x2206, 0xEE8B}, {0x2206, 0x6800}, {0x2206, 0xEE8B},
  465. {0x2206, 0x6902}, {0x2206, 0x04F8}, {0x2206, 0xF9E0}, {0x2206, 0x8B85},
  466. {0x2206, 0xAD26}, {0x2206, 0x38D0}, {0x2206, 0x0B02}, {0x2206, 0x2B4D},
  467. {0x2206, 0x5882}, {0x2206, 0x7882}, {0x2206, 0x9F2D}, {0x2206, 0xE08B},
  468. {0x2206, 0x68E1}, {0x2206, 0x8B69}, {0x2206, 0x1F10}, {0x2206, 0x9EC8},
  469. {0x2206, 0x10E4}, {0x2206, 0x8B68}, {0x2206, 0xE0E0}, {0x2206, 0x00E1},
  470. {0x2206, 0xE001}, {0x2206, 0xF727}, {0x2206, 0xE4E0}, {0x2206, 0x00E5},
  471. {0x2206, 0xE001}, {0x2206, 0xE2E0}, {0x2206, 0x20E3}, {0x2206, 0xE021},
  472. {0x2206, 0xAD30}, {0x2206, 0xF7F6}, {0x2206, 0x27E4}, {0x2206, 0xE000},
  473. {0x2206, 0xE5E0}, {0x2206, 0x01FD}, {0x2206, 0xFC04}, {0x2206, 0xF8FA},
  474. {0x2206, 0xEF69}, {0x2206, 0xE08B}, {0x2206, 0x86AD}, {0x2206, 0x2212},
  475. {0x2206, 0xE0E0}, {0x2206, 0x14E1}, {0x2206, 0xE015}, {0x2206, 0xAD26},
  476. {0x2206, 0x9CE1}, {0x2206, 0x85E0}, {0x2206, 0xBF85}, {0x2206, 0x6D02},
  477. {0x2206, 0x2CA2}, {0x2206, 0xEF96}, {0x2206, 0xFEFC}, {0x2206, 0x04F8},
  478. {0x2206, 0xFAEF}, {0x2206, 0x69E0}, {0x2206, 0x8B86}, {0x2206, 0xAD22},
  479. {0x2206, 0x09E1}, {0x2206, 0x85E1}, {0x2206, 0xBF85}, {0x2206, 0x6D02},
  480. {0x2206, 0x2CA2}, {0x2206, 0xEF96}, {0x2206, 0xFEFC}, {0x2206, 0x0464},
  481. {0x2206, 0xE48C}, {0x2206, 0xFDE4}, {0x2206, 0x80CA}, {0x2206, 0xE480},
  482. {0x2206, 0x66E0}, {0x2206, 0x8E70}, {0x2206, 0xE076}, {0x2205, 0xE142},
  483. {0x2206, 0x0701}, {0x2205, 0xE140}, {0x2206, 0x0405}, {0x220F, 0x0000},
  484. {0x221F, 0x0000}, {0x2200, 0x1340}, {0x133E, 0x000E}, {0x133F, 0x0010},
  485. {0x13EB, 0x11BB}
  486. };
  487. static const struct rtl8367b_initval rtl8367r_vb_initvals_1[] = {
  488. {0x1B03, 0x0876}, {0x1200, 0x7FC4}, {0x1305, 0xC000}, {0x121E, 0x03CA},
  489. {0x1233, 0x0352}, {0x1234, 0x0064}, {0x1237, 0x0096}, {0x1238, 0x0078},
  490. {0x1239, 0x0084}, {0x123A, 0x0030}, {0x205F, 0x0002}, {0x2059, 0x1A00},
  491. {0x205F, 0x0000}, {0x207F, 0x0002}, {0x2077, 0x0000}, {0x2078, 0x0000},
  492. {0x2079, 0x0000}, {0x207A, 0x0000}, {0x207B, 0x0000}, {0x207F, 0x0000},
  493. {0x205F, 0x0002}, {0x2053, 0x0000}, {0x2054, 0x0000}, {0x2055, 0x0000},
  494. {0x2056, 0x0000}, {0x2057, 0x0000}, {0x205F, 0x0000}, {0x133F, 0x0030},
  495. {0x133E, 0x000E}, {0x221F, 0x0005}, {0x2205, 0x8B86}, {0x2206, 0x800E},
  496. {0x221F, 0x0000}, {0x133F, 0x0010}, {0x12A3, 0x2200}, {0x6107, 0xE58B},
  497. {0x6103, 0xA970}, {0x0018, 0x0F00}, {0x0038, 0x0F00}, {0x0058, 0x0F00},
  498. {0x0078, 0x0F00}, {0x0098, 0x0F00}, {0x133F, 0x0030}, {0x133E, 0x000E},
  499. {0x221F, 0x0005}, {0x2205, 0x8B6E}, {0x2206, 0x0000}, {0x220F, 0x0100},
  500. {0x2205, 0xFFF6}, {0x2206, 0x0080}, {0x2205, 0x8000}, {0x2206, 0x0280},
  501. {0x2206, 0x2BF7}, {0x2206, 0x00E0}, {0x2206, 0xFFF7}, {0x2206, 0xA080},
  502. {0x2206, 0x02AE}, {0x2206, 0xF602}, {0x2206, 0x0153}, {0x2206, 0x0201},
  503. {0x2206, 0x6602}, {0x2206, 0x8044}, {0x2206, 0x0201}, {0x2206, 0x7CE0},
  504. {0x2206, 0x8B8C}, {0x2206, 0xE18B}, {0x2206, 0x8D1E}, {0x2206, 0x01E1},
  505. {0x2206, 0x8B8E}, {0x2206, 0x1E01}, {0x2206, 0xA000}, {0x2206, 0xE4AE},
  506. {0x2206, 0xD8EE}, {0x2206, 0x85C0}, {0x2206, 0x00EE}, {0x2206, 0x85C1},
  507. {0x2206, 0x00EE}, {0x2206, 0x8AFC}, {0x2206, 0x07EE}, {0x2206, 0x8AFD},
  508. {0x2206, 0x73EE}, {0x2206, 0xFFF6}, {0x2206, 0x00EE}, {0x2206, 0xFFF7},
  509. {0x2206, 0xFC04}, {0x2206, 0xF8E0}, {0x2206, 0x8B8E}, {0x2206, 0xAD20},
  510. {0x2206, 0x0302}, {0x2206, 0x8050}, {0x2206, 0xFC04}, {0x2206, 0xF8F9},
  511. {0x2206, 0xE08B}, {0x2206, 0x85AD}, {0x2206, 0x2548}, {0x2206, 0xE08A},
  512. {0x2206, 0xE4E1}, {0x2206, 0x8AE5}, {0x2206, 0x7C00}, {0x2206, 0x009E},
  513. {0x2206, 0x35EE}, {0x2206, 0x8AE4}, {0x2206, 0x00EE}, {0x2206, 0x8AE5},
  514. {0x2206, 0x00E0}, {0x2206, 0x8AFC}, {0x2206, 0xE18A}, {0x2206, 0xFDE2},
  515. {0x2206, 0x85C0}, {0x2206, 0xE385}, {0x2206, 0xC102}, {0x2206, 0x2DAC},
  516. {0x2206, 0xAD20}, {0x2206, 0x12EE}, {0x2206, 0x8AE4}, {0x2206, 0x03EE},
  517. {0x2206, 0x8AE5}, {0x2206, 0xB7EE}, {0x2206, 0x85C0}, {0x2206, 0x00EE},
  518. {0x2206, 0x85C1}, {0x2206, 0x00AE}, {0x2206, 0x1115}, {0x2206, 0xE685},
  519. {0x2206, 0xC0E7}, {0x2206, 0x85C1}, {0x2206, 0xAE08}, {0x2206, 0xEE85},
  520. {0x2206, 0xC000}, {0x2206, 0xEE85}, {0x2206, 0xC100}, {0x2206, 0xFDFC},
  521. {0x2206, 0x0400}, {0x2205, 0xE142}, {0x2206, 0x0701}, {0x2205, 0xE140},
  522. {0x2206, 0x0405}, {0x220F, 0x0000}, {0x221F, 0x0000}, {0x133E, 0x000E},
  523. {0x133F, 0x0010}, {0x13EB, 0x11BB}, {0x207F, 0x0002}, {0x2073, 0x1D22},
  524. {0x207F, 0x0000}, {0x133F, 0x0030}, {0x133E, 0x000E}, {0x2200, 0x1340},
  525. {0x133E, 0x000E}, {0x133F, 0x0010},
  526. };
  527. static int rtl8367b_write_initvals(struct rtl8366_smi *smi,
  528. const struct rtl8367b_initval *initvals,
  529. int count)
  530. {
  531. int err;
  532. int i;
  533. for (i = 0; i < count; i++)
  534. REG_WR(smi, initvals[i].reg, initvals[i].val);
  535. return 0;
  536. }
  537. static int rtl8367b_read_phy_reg(struct rtl8366_smi *smi,
  538. u32 phy_addr, u32 phy_reg, u32 *val)
  539. {
  540. int timeout;
  541. u32 data;
  542. int err;
  543. if (phy_addr > RTL8367B_PHY_ADDR_MAX)
  544. return -EINVAL;
  545. if (phy_reg > RTL8367B_PHY_REG_MAX)
  546. return -EINVAL;
  547. REG_RD(smi, RTL8367B_IA_STATUS_REG, &data);
  548. if (data & RTL8367B_IA_STATUS_PHY_BUSY)
  549. return -ETIMEDOUT;
  550. /* prepare address */
  551. REG_WR(smi, RTL8367B_IA_ADDRESS_REG,
  552. RTL8367B_INTERNAL_PHY_REG(phy_addr, phy_reg));
  553. /* send read command */
  554. REG_WR(smi, RTL8367B_IA_CTRL_REG,
  555. RTL8367B_IA_CTRL_CMD_MASK | RTL8367B_IA_CTRL_RW_READ);
  556. timeout = 5;
  557. do {
  558. REG_RD(smi, RTL8367B_IA_STATUS_REG, &data);
  559. if ((data & RTL8367B_IA_STATUS_PHY_BUSY) == 0)
  560. break;
  561. if (timeout--) {
  562. dev_err(smi->parent, "phy read timed out\n");
  563. return -ETIMEDOUT;
  564. }
  565. udelay(1);
  566. } while (1);
  567. /* read data */
  568. REG_RD(smi, RTL8367B_IA_READ_DATA_REG, val);
  569. dev_dbg(smi->parent, "phy_read: addr:%02x, reg:%02x, val:%04x\n",
  570. phy_addr, phy_reg, *val);
  571. return 0;
  572. }
  573. static int rtl8367b_write_phy_reg(struct rtl8366_smi *smi,
  574. u32 phy_addr, u32 phy_reg, u32 val)
  575. {
  576. int timeout;
  577. u32 data;
  578. int err;
  579. dev_dbg(smi->parent, "phy_write: addr:%02x, reg:%02x, val:%04x\n",
  580. phy_addr, phy_reg, val);
  581. if (phy_addr > RTL8367B_PHY_ADDR_MAX)
  582. return -EINVAL;
  583. if (phy_reg > RTL8367B_PHY_REG_MAX)
  584. return -EINVAL;
  585. REG_RD(smi, RTL8367B_IA_STATUS_REG, &data);
  586. if (data & RTL8367B_IA_STATUS_PHY_BUSY)
  587. return -ETIMEDOUT;
  588. /* preapre data */
  589. REG_WR(smi, RTL8367B_IA_WRITE_DATA_REG, val);
  590. /* prepare address */
  591. REG_WR(smi, RTL8367B_IA_ADDRESS_REG,
  592. RTL8367B_INTERNAL_PHY_REG(phy_addr, phy_reg));
  593. /* send write command */
  594. REG_WR(smi, RTL8367B_IA_CTRL_REG,
  595. RTL8367B_IA_CTRL_CMD_MASK | RTL8367B_IA_CTRL_RW_WRITE);
  596. timeout = 5;
  597. do {
  598. REG_RD(smi, RTL8367B_IA_STATUS_REG, &data);
  599. if ((data & RTL8367B_IA_STATUS_PHY_BUSY) == 0)
  600. break;
  601. if (timeout--) {
  602. dev_err(smi->parent, "phy write timed out\n");
  603. return -ETIMEDOUT;
  604. }
  605. udelay(1);
  606. } while (1);
  607. return 0;
  608. }
  609. static int rtl8367b_init_regs(struct rtl8366_smi *smi)
  610. {
  611. const struct rtl8367b_initval *initvals;
  612. u32 chip_ver;
  613. u32 rlvid;
  614. int count;
  615. int err;
  616. REG_WR(smi, RTL8367B_RTL_MAGIC_ID_REG, RTL8367B_RTL_MAGIC_ID_VAL);
  617. REG_RD(smi, RTL8367B_CHIP_VER_REG, &chip_ver);
  618. rlvid = (chip_ver >> RTL8367B_CHIP_VER_RLVID_SHIFT) &
  619. RTL8367B_CHIP_VER_RLVID_MASK;
  620. switch (rlvid) {
  621. case 0:
  622. initvals = rtl8367r_vb_initvals_0;
  623. count = ARRAY_SIZE(rtl8367r_vb_initvals_0);
  624. break;
  625. case 1:
  626. initvals = rtl8367r_vb_initvals_1;
  627. count = ARRAY_SIZE(rtl8367r_vb_initvals_1);
  628. break;
  629. default:
  630. dev_err(smi->parent, "unknow rlvid %u\n", rlvid);
  631. return -ENODEV;
  632. }
  633. /* TODO: disable RLTP */
  634. return rtl8367b_write_initvals(smi, initvals, count);
  635. }
  636. static int rtl8367b_reset_chip(struct rtl8366_smi *smi)
  637. {
  638. int timeout = 10;
  639. int err;
  640. u32 data;
  641. REG_WR(smi, RTL8367B_CHIP_RESET_REG, RTL8367B_CHIP_RESET_HW);
  642. msleep(RTL8367B_RESET_DELAY);
  643. do {
  644. REG_RD(smi, RTL8367B_CHIP_RESET_REG, &data);
  645. if (!(data & RTL8367B_CHIP_RESET_HW))
  646. break;
  647. msleep(1);
  648. } while (--timeout);
  649. if (!timeout) {
  650. dev_err(smi->parent, "chip reset timed out\n");
  651. return -ETIMEDOUT;
  652. }
  653. return 0;
  654. }
  655. static int rtl8367b_extif_set_mode(struct rtl8366_smi *smi, int id,
  656. enum rtl8367_extif_mode mode)
  657. {
  658. int err;
  659. /* set port mode */
  660. switch (mode) {
  661. case RTL8367_EXTIF_MODE_RGMII:
  662. case RTL8367_EXTIF_MODE_RGMII_33V:
  663. REG_WR(smi, RTL8367B_CHIP_DEBUG0_REG, 0x0367);
  664. REG_WR(smi, RTL8367B_CHIP_DEBUG1_REG, 0x7777);
  665. break;
  666. case RTL8367_EXTIF_MODE_TMII_MAC:
  667. case RTL8367_EXTIF_MODE_TMII_PHY:
  668. REG_RMW(smi, RTL8367B_BYPASS_LINE_RATE_REG,
  669. BIT((id + 1) % 2), BIT((id + 1) % 2));
  670. break;
  671. case RTL8367_EXTIF_MODE_GMII:
  672. REG_RMW(smi, RTL8367B_CHIP_DEBUG0_REG,
  673. RTL8367B_CHIP_DEBUG0_DUMMY0(id),
  674. RTL8367B_CHIP_DEBUG0_DUMMY0(id));
  675. REG_RMW(smi, RTL8367B_EXT_RGMXF_REG(id), BIT(6), BIT(6));
  676. break;
  677. case RTL8367_EXTIF_MODE_MII_MAC:
  678. case RTL8367_EXTIF_MODE_MII_PHY:
  679. case RTL8367_EXTIF_MODE_DISABLED:
  680. REG_RMW(smi, RTL8367B_BYPASS_LINE_RATE_REG,
  681. BIT((id + 1) % 2), 0);
  682. REG_RMW(smi, RTL8367B_EXT_RGMXF_REG(id), BIT(6), 0);
  683. break;
  684. default:
  685. dev_err(smi->parent,
  686. "invalid mode for external interface %d\n", id);
  687. return -EINVAL;
  688. }
  689. REG_RMW(smi, RTL8367B_DIS_REG,
  690. RTL8367B_DIS_RGMII_MASK << RTL8367B_DIS_RGMII_SHIFT(id),
  691. mode << RTL8367B_DIS_RGMII_SHIFT(id));
  692. return 0;
  693. }
  694. static int rtl8367b_extif_set_force(struct rtl8366_smi *smi, int id,
  695. struct rtl8367_port_ability *pa)
  696. {
  697. u32 mask;
  698. u32 val;
  699. int err;
  700. mask = (RTL8367B_DI_FORCE_MODE |
  701. RTL8367B_DI_FORCE_NWAY |
  702. RTL8367B_DI_FORCE_TXPAUSE |
  703. RTL8367B_DI_FORCE_RXPAUSE |
  704. RTL8367B_DI_FORCE_LINK |
  705. RTL8367B_DI_FORCE_DUPLEX |
  706. RTL8367B_DI_FORCE_SPEED_MASK);
  707. val = pa->speed;
  708. val |= pa->force_mode ? RTL8367B_DI_FORCE_MODE : 0;
  709. val |= pa->nway ? RTL8367B_DI_FORCE_NWAY : 0;
  710. val |= pa->txpause ? RTL8367B_DI_FORCE_TXPAUSE : 0;
  711. val |= pa->rxpause ? RTL8367B_DI_FORCE_RXPAUSE : 0;
  712. val |= pa->link ? RTL8367B_DI_FORCE_LINK : 0;
  713. val |= pa->duplex ? RTL8367B_DI_FORCE_DUPLEX : 0;
  714. REG_RMW(smi, RTL8367B_DI_FORCE_REG(id), mask, val);
  715. return 0;
  716. }
  717. static int rtl8367b_extif_set_rgmii_delay(struct rtl8366_smi *smi, int id,
  718. unsigned txdelay, unsigned rxdelay)
  719. {
  720. u32 mask;
  721. u32 val;
  722. int err;
  723. mask = (RTL8367B_EXT_RGMXF_RXDELAY_MASK |
  724. (RTL8367B_EXT_RGMXF_TXDELAY_MASK <<
  725. RTL8367B_EXT_RGMXF_TXDELAY_SHIFT));
  726. val = rxdelay;
  727. val |= txdelay << RTL8367B_EXT_RGMXF_TXDELAY_SHIFT;
  728. REG_RMW(smi, RTL8367B_EXT_RGMXF_REG(id), mask, val);
  729. return 0;
  730. }
  731. static int rtl8367b_extif_init(struct rtl8366_smi *smi, int id,
  732. struct rtl8367_extif_config *cfg)
  733. {
  734. enum rtl8367_extif_mode mode;
  735. int err;
  736. mode = (cfg) ? cfg->mode : RTL8367_EXTIF_MODE_DISABLED;
  737. err = rtl8367b_extif_set_mode(smi, id, mode);
  738. if (err)
  739. return err;
  740. if (mode != RTL8367_EXTIF_MODE_DISABLED) {
  741. err = rtl8367b_extif_set_force(smi, id, &cfg->ability);
  742. if (err)
  743. return err;
  744. err = rtl8367b_extif_set_rgmii_delay(smi, id, cfg->txdelay,
  745. cfg->rxdelay);
  746. if (err)
  747. return err;
  748. }
  749. return 0;
  750. }
  751. #ifdef CONFIG_OF
  752. static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id,
  753. const char *name)
  754. {
  755. struct rtl8367_extif_config *cfg;
  756. const __be32 *prop;
  757. int size;
  758. int err;
  759. prop = of_get_property(smi->parent->of_node, name, &size);
  760. if (!prop)
  761. return rtl8367b_extif_init(smi, id, NULL);
  762. if (size != (9 * sizeof(*prop))) {
  763. dev_err(smi->parent, "%s property is invalid\n", name);
  764. return -EINVAL;
  765. }
  766. cfg = kzalloc(sizeof(struct rtl8367_extif_config), GFP_KERNEL);
  767. if (!cfg)
  768. return -ENOMEM;
  769. cfg->txdelay = be32_to_cpup(prop++);
  770. cfg->rxdelay = be32_to_cpup(prop++);
  771. cfg->mode = be32_to_cpup(prop++);
  772. cfg->ability.force_mode = be32_to_cpup(prop++);
  773. cfg->ability.txpause = be32_to_cpup(prop++);
  774. cfg->ability.rxpause = be32_to_cpup(prop++);
  775. cfg->ability.link = be32_to_cpup(prop++);
  776. cfg->ability.duplex = be32_to_cpup(prop++);
  777. cfg->ability.speed = be32_to_cpup(prop++);
  778. err = rtl8367b_extif_init(smi, id, cfg);
  779. kfree(cfg);
  780. return err;
  781. }
  782. #else
  783. static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id,
  784. const char *name)
  785. {
  786. return -EINVAL;
  787. }
  788. #endif
  789. static int rtl8367b_setup(struct rtl8366_smi *smi)
  790. {
  791. struct rtl8367_platform_data *pdata;
  792. int err;
  793. int i;
  794. pdata = smi->parent->platform_data;
  795. err = rtl8367b_init_regs(smi);
  796. if (err)
  797. return err;
  798. /* initialize external interfaces */
  799. if (smi->parent->of_node) {
  800. err = rtl8367b_extif_init_of(smi, 0, "realtek,extif0");
  801. if (err)
  802. return err;
  803. err = rtl8367b_extif_init_of(smi, 1, "realtek,extif1");
  804. if (err)
  805. return err;
  806. } else {
  807. err = rtl8367b_extif_init(smi, 0, pdata->extif0_cfg);
  808. if (err)
  809. return err;
  810. err = rtl8367b_extif_init(smi, 1, pdata->extif1_cfg);
  811. if (err)
  812. return err;
  813. }
  814. /* set maximum packet length to 1536 bytes */
  815. REG_RMW(smi, RTL8367B_SWC0_REG, RTL8367B_SWC0_MAX_LENGTH_MASK,
  816. RTL8367B_SWC0_MAX_LENGTH_1536);
  817. /*
  818. * discard VLAN tagged packets if the port is not a member of
  819. * the VLAN with which the packets is associated.
  820. */
  821. REG_WR(smi, RTL8367B_VLAN_INGRESS_REG, RTL8367B_PORTS_ALL);
  822. /*
  823. * Setup egress tag mode for each port.
  824. */
  825. for (i = 0; i < RTL8367B_NUM_PORTS; i++)
  826. REG_RMW(smi,
  827. RTL8367B_PORT_MISC_CFG_REG(i),
  828. RTL8367B_PORT_MISC_CFG_EGRESS_MODE_MASK <<
  829. RTL8367B_PORT_MISC_CFG_EGRESS_MODE_SHIFT,
  830. RTL8367B_PORT_MISC_CFG_EGRESS_MODE_ORIGINAL <<
  831. RTL8367B_PORT_MISC_CFG_EGRESS_MODE_SHIFT);
  832. return 0;
  833. }
  834. static int rtl8367b_get_mib_counter(struct rtl8366_smi *smi, int counter,
  835. int port, unsigned long long *val)
  836. {
  837. struct rtl8366_mib_counter *mib;
  838. int offset;
  839. int i;
  840. int err;
  841. u32 addr, data;
  842. u64 mibvalue;
  843. if (port > RTL8367B_NUM_PORTS ||
  844. counter >= RTL8367B_NUM_MIB_COUNTERS)
  845. return -EINVAL;
  846. mib = &rtl8367b_mib_counters[counter];
  847. addr = RTL8367B_MIB_COUNTER_PORT_OFFSET * port + mib->offset;
  848. /*
  849. * Writing access counter address first
  850. * then ASIC will prepare 64bits counter wait for being retrived
  851. */
  852. REG_WR(smi, RTL8367B_MIB_ADDRESS_REG, addr >> 2);
  853. /* read MIB control register */
  854. REG_RD(smi, RTL8367B_MIB_CTRL0_REG(0), &data);
  855. if (data & RTL8367B_MIB_CTRL0_BUSY_MASK)
  856. return -EBUSY;
  857. if (data & RTL8367B_MIB_CTRL0_RESET_MASK)
  858. return -EIO;
  859. if (mib->length == 4)
  860. offset = 3;
  861. else
  862. offset = (mib->offset + 1) % 4;
  863. mibvalue = 0;
  864. for (i = 0; i < mib->length; i++) {
  865. REG_RD(smi, RTL8367B_MIB_COUNTER_REG(offset - i), &data);
  866. mibvalue = (mibvalue << 16) | (data & 0xFFFF);
  867. }
  868. *val = mibvalue;
  869. return 0;
  870. }
  871. static int rtl8367b_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
  872. struct rtl8366_vlan_4k *vlan4k)
  873. {
  874. u32 data[RTL8367B_TA_VLAN_NUM_WORDS];
  875. int err;
  876. int i;
  877. memset(vlan4k, '\0', sizeof(struct rtl8366_vlan_4k));
  878. if (vid >= RTL8367B_NUM_VIDS)
  879. return -EINVAL;
  880. /* write VID */
  881. REG_WR(smi, RTL8367B_TA_ADDR_REG, vid);
  882. /* write table access control word */
  883. REG_WR(smi, RTL8367B_TA_CTRL_REG, RTL8367B_TA_CTRL_CVLAN_READ);
  884. for (i = 0; i < ARRAY_SIZE(data); i++)
  885. REG_RD(smi, RTL8367B_TA_RDDATA_REG(i), &data[i]);
  886. vlan4k->vid = vid;
  887. vlan4k->member = (data[0] >> RTL8367B_TA_VLAN0_MEMBER_SHIFT) &
  888. RTL8367B_TA_VLAN0_MEMBER_MASK;
  889. vlan4k->untag = (data[0] >> RTL8367B_TA_VLAN0_UNTAG_SHIFT) &
  890. RTL8367B_TA_VLAN0_UNTAG_MASK;
  891. vlan4k->fid = (data[1] >> RTL8367B_TA_VLAN1_FID_SHIFT) &
  892. RTL8367B_TA_VLAN1_FID_MASK;
  893. return 0;
  894. }
  895. static int rtl8367b_set_vlan_4k(struct rtl8366_smi *smi,
  896. const struct rtl8366_vlan_4k *vlan4k)
  897. {
  898. u32 data[RTL8367B_TA_VLAN_NUM_WORDS];
  899. int err;
  900. int i;
  901. if (vlan4k->vid >= RTL8367B_NUM_VIDS ||
  902. vlan4k->member > RTL8367B_TA_VLAN0_MEMBER_MASK ||
  903. vlan4k->untag > RTL8367B_UNTAG_MASK ||
  904. vlan4k->fid > RTL8367B_FIDMAX)
  905. return -EINVAL;
  906. memset(data, 0, sizeof(data));
  907. data[0] = (vlan4k->member & RTL8367B_TA_VLAN0_MEMBER_MASK) <<
  908. RTL8367B_TA_VLAN0_MEMBER_SHIFT;
  909. data[0] |= (vlan4k->untag & RTL8367B_TA_VLAN0_UNTAG_MASK) <<
  910. RTL8367B_TA_VLAN0_UNTAG_SHIFT;
  911. data[1] = (vlan4k->fid & RTL8367B_TA_VLAN1_FID_MASK) <<
  912. RTL8367B_TA_VLAN1_FID_SHIFT;
  913. for (i = 0; i < ARRAY_SIZE(data); i++)
  914. REG_WR(smi, RTL8367B_TA_WRDATA_REG(i), data[i]);
  915. /* write VID */
  916. REG_WR(smi, RTL8367B_TA_ADDR_REG,
  917. vlan4k->vid & RTL8367B_TA_VLAN_VID_MASK);
  918. /* write table access control word */
  919. REG_WR(smi, RTL8367B_TA_CTRL_REG, RTL8367B_TA_CTRL_CVLAN_WRITE);
  920. return 0;
  921. }
  922. static int rtl8367b_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
  923. struct rtl8366_vlan_mc *vlanmc)
  924. {
  925. u32 data[RTL8367B_VLAN_MC_NUM_WORDS];
  926. int err;
  927. int i;
  928. memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
  929. if (index >= RTL8367B_NUM_VLANS)
  930. return -EINVAL;
  931. for (i = 0; i < ARRAY_SIZE(data); i++)
  932. REG_RD(smi, RTL8367B_VLAN_MC_BASE(index) + i, &data[i]);
  933. vlanmc->member = (data[0] >> RTL8367B_VLAN_MC0_MEMBER_SHIFT) &
  934. RTL8367B_VLAN_MC0_MEMBER_MASK;
  935. vlanmc->fid = (data[1] >> RTL8367B_VLAN_MC1_FID_SHIFT) &
  936. RTL8367B_VLAN_MC1_FID_MASK;
  937. vlanmc->vid = (data[3] >> RTL8367B_VLAN_MC3_EVID_SHIFT) &
  938. RTL8367B_VLAN_MC3_EVID_MASK;
  939. return 0;
  940. }
  941. static int rtl8367b_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
  942. const struct rtl8366_vlan_mc *vlanmc)
  943. {
  944. u32 data[RTL8367B_VLAN_MC_NUM_WORDS];
  945. int err;
  946. int i;
  947. if (index >= RTL8367B_NUM_VLANS ||
  948. vlanmc->vid >= RTL8367B_NUM_VIDS ||
  949. vlanmc->priority > RTL8367B_PRIORITYMAX ||
  950. vlanmc->member > RTL8367B_VLAN_MC0_MEMBER_MASK ||
  951. vlanmc->untag > RTL8367B_UNTAG_MASK ||
  952. vlanmc->fid > RTL8367B_FIDMAX)
  953. return -EINVAL;
  954. data[0] = (vlanmc->member & RTL8367B_VLAN_MC0_MEMBER_MASK) <<
  955. RTL8367B_VLAN_MC0_MEMBER_SHIFT;
  956. data[1] = (vlanmc->fid & RTL8367B_VLAN_MC1_FID_MASK) <<
  957. RTL8367B_VLAN_MC1_FID_SHIFT;
  958. data[2] = 0;
  959. data[3] = (vlanmc->vid & RTL8367B_VLAN_MC3_EVID_MASK) <<
  960. RTL8367B_VLAN_MC3_EVID_SHIFT;
  961. for (i = 0; i < ARRAY_SIZE(data); i++)
  962. REG_WR(smi, RTL8367B_VLAN_MC_BASE(index) + i, data[i]);
  963. return 0;
  964. }
  965. static int rtl8367b_get_mc_index(struct rtl8366_smi *smi, int port, int *val)
  966. {
  967. u32 data;
  968. int err;
  969. if (port >= RTL8367B_NUM_PORTS)
  970. return -EINVAL;
  971. REG_RD(smi, RTL8367B_VLAN_PVID_CTRL_REG(port), &data);
  972. *val = (data >> RTL8367B_VLAN_PVID_CTRL_SHIFT(port)) &
  973. RTL8367B_VLAN_PVID_CTRL_MASK;
  974. return 0;
  975. }
  976. static int rtl8367b_set_mc_index(struct rtl8366_smi *smi, int port, int index)
  977. {
  978. if (port >= RTL8367B_NUM_PORTS || index >= RTL8367B_NUM_VLANS)
  979. return -EINVAL;
  980. return rtl8366_smi_rmwr(smi, RTL8367B_VLAN_PVID_CTRL_REG(port),
  981. RTL8367B_VLAN_PVID_CTRL_MASK <<
  982. RTL8367B_VLAN_PVID_CTRL_SHIFT(port),
  983. (index & RTL8367B_VLAN_PVID_CTRL_MASK) <<
  984. RTL8367B_VLAN_PVID_CTRL_SHIFT(port));
  985. }
  986. static int rtl8367b_enable_vlan(struct rtl8366_smi *smi, int enable)
  987. {
  988. return rtl8366_smi_rmwr(smi, RTL8367B_VLAN_CTRL_REG,
  989. RTL8367B_VLAN_CTRL_ENABLE,
  990. (enable) ? RTL8367B_VLAN_CTRL_ENABLE : 0);
  991. }
  992. static int rtl8367b_enable_vlan4k(struct rtl8366_smi *smi, int enable)
  993. {
  994. return 0;
  995. }
  996. static int rtl8367b_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
  997. {
  998. unsigned max = RTL8367B_NUM_VLANS;
  999. if (smi->vlan4k_enabled)
  1000. max = RTL8367B_NUM_VIDS - 1;
  1001. if (vlan == 0 || vlan >= max)
  1002. return 0;
  1003. return 1;
  1004. }
  1005. static int rtl8367b_enable_port(struct rtl8366_smi *smi, int port, int enable)
  1006. {
  1007. int err;
  1008. REG_WR(smi, RTL8367B_PORT_ISOLATION_REG(port),
  1009. (enable) ? RTL8367B_PORTS_ALL : 0);
  1010. return 0;
  1011. }
  1012. static int rtl8367b_sw_reset_mibs(struct switch_dev *dev,
  1013. const struct switch_attr *attr,
  1014. struct switch_val *val)
  1015. {
  1016. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1017. return rtl8366_smi_rmwr(smi, RTL8367B_MIB_CTRL0_REG(0), 0,
  1018. RTL8367B_MIB_CTRL0_GLOBAL_RESET_MASK);
  1019. }
  1020. static int rtl8367b_sw_get_port_link(struct switch_dev *dev,
  1021. int port,
  1022. struct switch_port_link *link)
  1023. {
  1024. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1025. u32 data = 0;
  1026. u32 speed;
  1027. if (port >= RTL8367B_NUM_PORTS)
  1028. return -EINVAL;
  1029. rtl8366_smi_read_reg(smi, RTL8367B_PORT_STATUS_REG(port), &data);
  1030. link->link = !!(data & RTL8367B_PORT_STATUS_LINK);
  1031. if (!link->link)
  1032. return 0;
  1033. link->duplex = !!(data & RTL8367B_PORT_STATUS_DUPLEX);
  1034. link->rx_flow = !!(data & RTL8367B_PORT_STATUS_RXPAUSE);
  1035. link->tx_flow = !!(data & RTL8367B_PORT_STATUS_TXPAUSE);
  1036. link->aneg = !!(data & RTL8367B_PORT_STATUS_NWAY);
  1037. speed = (data & RTL8367B_PORT_STATUS_SPEED_MASK);
  1038. switch (speed) {
  1039. case 0:
  1040. link->speed = SWITCH_PORT_SPEED_10;
  1041. break;
  1042. case 1:
  1043. link->speed = SWITCH_PORT_SPEED_100;
  1044. break;
  1045. case 2:
  1046. link->speed = SWITCH_PORT_SPEED_1000;
  1047. break;
  1048. default:
  1049. link->speed = SWITCH_PORT_SPEED_UNKNOWN;
  1050. break;
  1051. }
  1052. return 0;
  1053. }
  1054. static int rtl8367b_sw_get_max_length(struct switch_dev *dev,
  1055. const struct switch_attr *attr,
  1056. struct switch_val *val)
  1057. {
  1058. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1059. u32 data;
  1060. rtl8366_smi_read_reg(smi, RTL8367B_SWC0_REG, &data);
  1061. val->value.i = (data & RTL8367B_SWC0_MAX_LENGTH_MASK) >>
  1062. RTL8367B_SWC0_MAX_LENGTH_SHIFT;
  1063. return 0;
  1064. }
  1065. static int rtl8367b_sw_set_max_length(struct switch_dev *dev,
  1066. const struct switch_attr *attr,
  1067. struct switch_val *val)
  1068. {
  1069. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1070. u32 max_len;
  1071. switch (val->value.i) {
  1072. case 0:
  1073. max_len = RTL8367B_SWC0_MAX_LENGTH_1522;
  1074. break;
  1075. case 1:
  1076. max_len = RTL8367B_SWC0_MAX_LENGTH_1536;
  1077. break;
  1078. case 2:
  1079. max_len = RTL8367B_SWC0_MAX_LENGTH_1552;
  1080. break;
  1081. case 3:
  1082. max_len = RTL8367B_SWC0_MAX_LENGTH_16000;
  1083. break;
  1084. default:
  1085. return -EINVAL;
  1086. }
  1087. return rtl8366_smi_rmwr(smi, RTL8367B_SWC0_REG,
  1088. RTL8367B_SWC0_MAX_LENGTH_MASK, max_len);
  1089. }
  1090. static int rtl8367b_sw_reset_port_mibs(struct switch_dev *dev,
  1091. const struct switch_attr *attr,
  1092. struct switch_val *val)
  1093. {
  1094. struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
  1095. int port;
  1096. port = val->port_vlan;
  1097. if (port >= RTL8367B_NUM_PORTS)
  1098. return -EINVAL;
  1099. return rtl8366_smi_rmwr(smi, RTL8367B_MIB_CTRL0_REG(port / 8), 0,
  1100. RTL8367B_MIB_CTRL0_PORT_RESET_MASK(port % 8));
  1101. }
  1102. static int rtl8367b_sw_get_port_stats(struct switch_dev *dev, int port,
  1103. struct switch_port_stats *stats)
  1104. {
  1105. return (rtl8366_sw_get_port_stats(dev, port, stats,
  1106. RTL8367B_MIB_TXB_ID, RTL8367B_MIB_RXB_ID));
  1107. }
  1108. static struct switch_attr rtl8367b_globals[] = {
  1109. {
  1110. .type = SWITCH_TYPE_INT,
  1111. .name = "enable_vlan",
  1112. .description = "Enable VLAN mode",
  1113. .set = rtl8366_sw_set_vlan_enable,
  1114. .get = rtl8366_sw_get_vlan_enable,
  1115. .max = 1,
  1116. .ofs = 1
  1117. }, {
  1118. .type = SWITCH_TYPE_INT,
  1119. .name = "enable_vlan4k",
  1120. .description = "Enable VLAN 4K mode",
  1121. .set = rtl8366_sw_set_vlan_enable,
  1122. .get = rtl8366_sw_get_vlan_enable,
  1123. .max = 1,
  1124. .ofs = 2
  1125. }, {
  1126. .type = SWITCH_TYPE_NOVAL,
  1127. .name = "reset_mibs",
  1128. .description = "Reset all MIB counters",
  1129. .set = rtl8367b_sw_reset_mibs,
  1130. }, {
  1131. .type = SWITCH_TYPE_INT,
  1132. .name = "max_length",
  1133. .description = "Get/Set the maximum length of valid packets"
  1134. "(0:1522, 1:1536, 2:1552, 3:16000)",
  1135. .set = rtl8367b_sw_set_max_length,
  1136. .get = rtl8367b_sw_get_max_length,
  1137. .max = 3,
  1138. }
  1139. };
  1140. static struct switch_attr rtl8367b_port[] = {
  1141. {
  1142. .type = SWITCH_TYPE_NOVAL,
  1143. .name = "reset_mib",
  1144. .description = "Reset single port MIB counters",
  1145. .set = rtl8367b_sw_reset_port_mibs,
  1146. }, {
  1147. .type = SWITCH_TYPE_STRING,
  1148. .name = "mib",
  1149. .description = "Get MIB counters for port",
  1150. .max = 33,
  1151. .set = NULL,
  1152. .get = rtl8366_sw_get_port_mib,
  1153. },
  1154. };
  1155. static struct switch_attr rtl8367b_vlan[] = {
  1156. {
  1157. .type = SWITCH_TYPE_STRING,
  1158. .name = "info",
  1159. .description = "Get vlan information",
  1160. .max = 1,
  1161. .set = NULL,
  1162. .get = rtl8366_sw_get_vlan_info,
  1163. },
  1164. };
  1165. static const struct switch_dev_ops rtl8367b_sw_ops = {
  1166. .attr_global = {
  1167. .attr = rtl8367b_globals,
  1168. .n_attr = ARRAY_SIZE(rtl8367b_globals),
  1169. },
  1170. .attr_port = {
  1171. .attr = rtl8367b_port,
  1172. .n_attr = ARRAY_SIZE(rtl8367b_port),
  1173. },
  1174. .attr_vlan = {
  1175. .attr = rtl8367b_vlan,
  1176. .n_attr = ARRAY_SIZE(rtl8367b_vlan),
  1177. },
  1178. .get_vlan_ports = rtl8366_sw_get_vlan_ports,
  1179. .set_vlan_ports = rtl8366_sw_set_vlan_ports,
  1180. .get_port_pvid = rtl8366_sw_get_port_pvid,
  1181. .set_port_pvid = rtl8366_sw_set_port_pvid,
  1182. .reset_switch = rtl8366_sw_reset_switch,
  1183. .get_port_link = rtl8367b_sw_get_port_link,
  1184. .get_port_stats = rtl8367b_sw_get_port_stats,
  1185. };
  1186. static int rtl8367b_switch_init(struct rtl8366_smi *smi)
  1187. {
  1188. struct switch_dev *dev = &smi->sw_dev;
  1189. int err;
  1190. dev->name = "RTL8367B";
  1191. dev->cpu_port = smi->cpu_port;
  1192. dev->ports = RTL8367B_NUM_PORTS;
  1193. dev->vlans = RTL8367B_NUM_VIDS;
  1194. dev->ops = &rtl8367b_sw_ops;
  1195. dev->alias = dev_name(smi->parent);
  1196. err = register_switch(dev, NULL);
  1197. if (err)
  1198. dev_err(smi->parent, "switch registration failed\n");
  1199. return err;
  1200. }
  1201. static void rtl8367b_switch_cleanup(struct rtl8366_smi *smi)
  1202. {
  1203. unregister_switch(&smi->sw_dev);
  1204. }
  1205. static int rtl8367b_mii_read(struct mii_bus *bus, int addr, int reg)
  1206. {
  1207. struct rtl8366_smi *smi = bus->priv;
  1208. u32 val = 0;
  1209. int err;
  1210. err = rtl8367b_read_phy_reg(smi, addr, reg, &val);
  1211. if (err)
  1212. return 0xffff;
  1213. return val;
  1214. }
  1215. static int rtl8367b_mii_write(struct mii_bus *bus, int addr, int reg, u16 val)
  1216. {
  1217. struct rtl8366_smi *smi = bus->priv;
  1218. u32 t;
  1219. int err;
  1220. err = rtl8367b_write_phy_reg(smi, addr, reg, val);
  1221. if (err)
  1222. return err;
  1223. /* flush write */
  1224. (void) rtl8367b_read_phy_reg(smi, addr, reg, &t);
  1225. return err;
  1226. }
  1227. static int rtl8367b_detect(struct rtl8366_smi *smi)
  1228. {
  1229. const char *chip_name;
  1230. u32 chip_num;
  1231. u32 chip_ver;
  1232. u32 chip_mode;
  1233. int ret;
  1234. /* TODO: improve chip detection */
  1235. rtl8366_smi_write_reg(smi, RTL8367B_RTL_MAGIC_ID_REG,
  1236. RTL8367B_RTL_MAGIC_ID_VAL);
  1237. ret = rtl8366_smi_read_reg(smi, RTL8367B_CHIP_NUMBER_REG, &chip_num);
  1238. if (ret) {
  1239. dev_err(smi->parent, "unable to read %s register\n",
  1240. "chip number");
  1241. return ret;
  1242. }
  1243. ret = rtl8366_smi_read_reg(smi, RTL8367B_CHIP_VER_REG, &chip_ver);
  1244. if (ret) {
  1245. dev_err(smi->parent, "unable to read %s register\n",
  1246. "chip version");
  1247. return ret;
  1248. }
  1249. ret = rtl8366_smi_read_reg(smi, RTL8367B_CHIP_MODE_REG, &chip_mode);
  1250. if (ret) {
  1251. dev_err(smi->parent, "unable to read %s register\n",
  1252. "chip mode");
  1253. return ret;
  1254. }
  1255. switch (chip_ver) {
  1256. case 0x1000:
  1257. chip_name = "8367RB";
  1258. break;
  1259. case 0x1010:
  1260. chip_name = "8367R-VB";
  1261. break;
  1262. default:
  1263. dev_err(smi->parent,
  1264. "unknown chip num:%04x ver:%04x, mode:%04x\n",
  1265. chip_num, chip_ver, chip_mode);
  1266. return -ENODEV;
  1267. }
  1268. dev_info(smi->parent, "RTL%s chip found\n", chip_name);
  1269. return 0;
  1270. }
  1271. static struct rtl8366_smi_ops rtl8367b_smi_ops = {
  1272. .detect = rtl8367b_detect,
  1273. .reset_chip = rtl8367b_reset_chip,
  1274. .setup = rtl8367b_setup,
  1275. .mii_read = rtl8367b_mii_read,
  1276. .mii_write = rtl8367b_mii_write,
  1277. .get_vlan_mc = rtl8367b_get_vlan_mc,
  1278. .set_vlan_mc = rtl8367b_set_vlan_mc,
  1279. .get_vlan_4k = rtl8367b_get_vlan_4k,
  1280. .set_vlan_4k = rtl8367b_set_vlan_4k,
  1281. .get_mc_index = rtl8367b_get_mc_index,
  1282. .set_mc_index = rtl8367b_set_mc_index,
  1283. .get_mib_counter = rtl8367b_get_mib_counter,
  1284. .is_vlan_valid = rtl8367b_is_vlan_valid,
  1285. .enable_vlan = rtl8367b_enable_vlan,
  1286. .enable_vlan4k = rtl8367b_enable_vlan4k,
  1287. .enable_port = rtl8367b_enable_port,
  1288. };
  1289. static int rtl8367b_probe(struct platform_device *pdev)
  1290. {
  1291. struct rtl8366_smi *smi;
  1292. int err;
  1293. smi = rtl8366_smi_probe(pdev);
  1294. if (IS_ERR(smi))
  1295. return PTR_ERR(smi);
  1296. smi->clk_delay = 1500;
  1297. smi->cmd_read = 0xb9;
  1298. smi->cmd_write = 0xb8;
  1299. smi->ops = &rtl8367b_smi_ops;
  1300. smi->num_ports = RTL8367B_NUM_PORTS;
  1301. if (of_property_read_u32(pdev->dev.of_node, "cpu_port", &smi->cpu_port)
  1302. || smi->cpu_port >= smi->num_ports)
  1303. smi->cpu_port = RTL8367B_CPU_PORT_NUM;
  1304. smi->num_vlan_mc = RTL8367B_NUM_VLANS;
  1305. smi->mib_counters = rtl8367b_mib_counters;
  1306. smi->num_mib_counters = ARRAY_SIZE(rtl8367b_mib_counters);
  1307. err = rtl8366_smi_init(smi);
  1308. if (err)
  1309. goto err_free_smi;
  1310. platform_set_drvdata(pdev, smi);
  1311. err = rtl8367b_switch_init(smi);
  1312. if (err)
  1313. goto err_clear_drvdata;
  1314. return 0;
  1315. err_clear_drvdata:
  1316. platform_set_drvdata(pdev, NULL);
  1317. rtl8366_smi_cleanup(smi);
  1318. err_free_smi:
  1319. kfree(smi);
  1320. return err;
  1321. }
  1322. static int rtl8367b_remove(struct platform_device *pdev)
  1323. {
  1324. struct rtl8366_smi *smi = platform_get_drvdata(pdev);
  1325. if (smi) {
  1326. rtl8367b_switch_cleanup(smi);
  1327. platform_set_drvdata(pdev, NULL);
  1328. rtl8366_smi_cleanup(smi);
  1329. kfree(smi);
  1330. }
  1331. return 0;
  1332. }
  1333. static void rtl8367b_shutdown(struct platform_device *pdev)
  1334. {
  1335. struct rtl8366_smi *smi = platform_get_drvdata(pdev);
  1336. if (smi)
  1337. rtl8367b_reset_chip(smi);
  1338. }
  1339. #ifdef CONFIG_OF
  1340. static const struct of_device_id rtl8367b_match[] = {
  1341. { .compatible = "realtek,rtl8367b" },
  1342. {},
  1343. };
  1344. MODULE_DEVICE_TABLE(of, rtl8367b_match);
  1345. #endif
  1346. static struct platform_driver rtl8367b_driver = {
  1347. .driver = {
  1348. .name = RTL8367B_DRIVER_NAME,
  1349. .owner = THIS_MODULE,
  1350. #ifdef CONFIG_OF
  1351. .of_match_table = of_match_ptr(rtl8367b_match),
  1352. #endif
  1353. },
  1354. .probe = rtl8367b_probe,
  1355. .remove = rtl8367b_remove,
  1356. .shutdown = rtl8367b_shutdown,
  1357. };
  1358. module_platform_driver(rtl8367b_driver);
  1359. MODULE_DESCRIPTION("Realtek RTL8367B ethernet switch driver");
  1360. MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
  1361. MODULE_LICENSE("GPL v2");
  1362. MODULE_ALIAS("platform:" RTL8367B_DRIVER_NAME);