rtl8366rb.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Realtek SMI subdriver for the Realtek RTL8366RB ethernet switch
  3. *
  4. * This is a sparsely documented chip, the only viable documentation seems
  5. * to be a patched up code drop from the vendor that appear in various
  6. * GPL source trees.
  7. *
  8. * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
  9. * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  10. * Copyright (C) 2010 Antti Seppälä <a.seppala@gmail.com>
  11. * Copyright (C) 2010 Roman Yeryomin <roman@advem.lv>
  12. * Copyright (C) 2011 Colin Leitner <colin.leitner@googlemail.com>
  13. */
  14. #include <linux/bitops.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irqdomain.h>
  18. #include <linux/irqchip/chained_irq.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/regmap.h>
  21. #include "realtek-smi.h"
  22. #define RTL8366RB_PORT_NUM_CPU 5
  23. #define RTL8366RB_NUM_PORTS 6
  24. #define RTL8366RB_PHY_NO_MAX 4
  25. #define RTL8366RB_PHY_ADDR_MAX 31
  26. /* Switch Global Configuration register */
  27. #define RTL8366RB_SGCR 0x0000
  28. #define RTL8366RB_SGCR_EN_BC_STORM_CTRL BIT(0)
  29. #define RTL8366RB_SGCR_MAX_LENGTH(a) ((a) << 4)
  30. #define RTL8366RB_SGCR_MAX_LENGTH_MASK RTL8366RB_SGCR_MAX_LENGTH(0x3)
  31. #define RTL8366RB_SGCR_MAX_LENGTH_1522 RTL8366RB_SGCR_MAX_LENGTH(0x0)
  32. #define RTL8366RB_SGCR_MAX_LENGTH_1536 RTL8366RB_SGCR_MAX_LENGTH(0x1)
  33. #define RTL8366RB_SGCR_MAX_LENGTH_1552 RTL8366RB_SGCR_MAX_LENGTH(0x2)
  34. #define RTL8366RB_SGCR_MAX_LENGTH_9216 RTL8366RB_SGCR_MAX_LENGTH(0x3)
  35. #define RTL8366RB_SGCR_EN_VLAN BIT(13)
  36. #define RTL8366RB_SGCR_EN_VLAN_4KTB BIT(14)
  37. /* Port Enable Control register */
  38. #define RTL8366RB_PECR 0x0001
  39. /* Switch Security Control registers */
  40. #define RTL8366RB_SSCR0 0x0002
  41. #define RTL8366RB_SSCR1 0x0003
  42. #define RTL8366RB_SSCR2 0x0004
  43. #define RTL8366RB_SSCR2_DROP_UNKNOWN_DA BIT(0)
  44. /* Port Mirror Control Register */
  45. #define RTL8366RB_PMCR 0x0007
  46. #define RTL8366RB_PMCR_SOURCE_PORT(a) (a)
  47. #define RTL8366RB_PMCR_SOURCE_PORT_MASK 0x000f
  48. #define RTL8366RB_PMCR_MONITOR_PORT(a) ((a) << 4)
  49. #define RTL8366RB_PMCR_MONITOR_PORT_MASK 0x00f0
  50. #define RTL8366RB_PMCR_MIRROR_RX BIT(8)
  51. #define RTL8366RB_PMCR_MIRROR_TX BIT(9)
  52. #define RTL8366RB_PMCR_MIRROR_SPC BIT(10)
  53. #define RTL8366RB_PMCR_MIRROR_ISO BIT(11)
  54. /* bits 0..7 = port 0, bits 8..15 = port 1 */
  55. #define RTL8366RB_PAACR0 0x0010
  56. /* bits 0..7 = port 2, bits 8..15 = port 3 */
  57. #define RTL8366RB_PAACR1 0x0011
  58. /* bits 0..7 = port 4, bits 8..15 = port 5 */
  59. #define RTL8366RB_PAACR2 0x0012
  60. #define RTL8366RB_PAACR_SPEED_10M 0
  61. #define RTL8366RB_PAACR_SPEED_100M 1
  62. #define RTL8366RB_PAACR_SPEED_1000M 2
  63. #define RTL8366RB_PAACR_FULL_DUPLEX BIT(2)
  64. #define RTL8366RB_PAACR_LINK_UP BIT(4)
  65. #define RTL8366RB_PAACR_TX_PAUSE BIT(5)
  66. #define RTL8366RB_PAACR_RX_PAUSE BIT(6)
  67. #define RTL8366RB_PAACR_AN BIT(7)
  68. #define RTL8366RB_PAACR_CPU_PORT (RTL8366RB_PAACR_SPEED_1000M | \
  69. RTL8366RB_PAACR_FULL_DUPLEX | \
  70. RTL8366RB_PAACR_LINK_UP | \
  71. RTL8366RB_PAACR_TX_PAUSE | \
  72. RTL8366RB_PAACR_RX_PAUSE)
  73. /* bits 0..7 = port 0, bits 8..15 = port 1 */
  74. #define RTL8366RB_PSTAT0 0x0014
  75. /* bits 0..7 = port 2, bits 8..15 = port 3 */
  76. #define RTL8366RB_PSTAT1 0x0015
  77. /* bits 0..7 = port 4, bits 8..15 = port 5 */
  78. #define RTL8366RB_PSTAT2 0x0016
  79. #define RTL8366RB_POWER_SAVING_REG 0x0021
  80. /* CPU port control reg */
  81. #define RTL8368RB_CPU_CTRL_REG 0x0061
  82. #define RTL8368RB_CPU_PORTS_MSK 0x00FF
  83. /* Enables inserting custom tag length/type 0x8899 */
  84. #define RTL8368RB_CPU_INSTAG BIT(15)
  85. #define RTL8366RB_SMAR0 0x0070 /* bits 0..15 */
  86. #define RTL8366RB_SMAR1 0x0071 /* bits 16..31 */
  87. #define RTL8366RB_SMAR2 0x0072 /* bits 32..47 */
  88. #define RTL8366RB_RESET_CTRL_REG 0x0100
  89. #define RTL8366RB_CHIP_CTRL_RESET_HW BIT(0)
  90. #define RTL8366RB_CHIP_CTRL_RESET_SW BIT(1)
  91. #define RTL8366RB_CHIP_ID_REG 0x0509
  92. #define RTL8366RB_CHIP_ID_8366 0x5937
  93. #define RTL8366RB_CHIP_VERSION_CTRL_REG 0x050A
  94. #define RTL8366RB_CHIP_VERSION_MASK 0xf
  95. /* PHY registers control */
  96. #define RTL8366RB_PHY_ACCESS_CTRL_REG 0x8000
  97. #define RTL8366RB_PHY_CTRL_READ BIT(0)
  98. #define RTL8366RB_PHY_CTRL_WRITE 0
  99. #define RTL8366RB_PHY_ACCESS_BUSY_REG 0x8001
  100. #define RTL8366RB_PHY_INT_BUSY BIT(0)
  101. #define RTL8366RB_PHY_EXT_BUSY BIT(4)
  102. #define RTL8366RB_PHY_ACCESS_DATA_REG 0x8002
  103. #define RTL8366RB_PHY_EXT_CTRL_REG 0x8010
  104. #define RTL8366RB_PHY_EXT_WRDATA_REG 0x8011
  105. #define RTL8366RB_PHY_EXT_RDDATA_REG 0x8012
  106. #define RTL8366RB_PHY_REG_MASK 0x1f
  107. #define RTL8366RB_PHY_PAGE_OFFSET 5
  108. #define RTL8366RB_PHY_PAGE_MASK (0xf << 5)
  109. #define RTL8366RB_PHY_NO_OFFSET 9
  110. #define RTL8366RB_PHY_NO_MASK (0x1f << 9)
  111. #define RTL8366RB_VLAN_INGRESS_CTRL2_REG 0x037f
  112. /* LED control registers */
  113. #define RTL8366RB_LED_BLINKRATE_REG 0x0430
  114. #define RTL8366RB_LED_BLINKRATE_MASK 0x0007
  115. #define RTL8366RB_LED_BLINKRATE_28MS 0x0000
  116. #define RTL8366RB_LED_BLINKRATE_56MS 0x0001
  117. #define RTL8366RB_LED_BLINKRATE_84MS 0x0002
  118. #define RTL8366RB_LED_BLINKRATE_111MS 0x0003
  119. #define RTL8366RB_LED_BLINKRATE_222MS 0x0004
  120. #define RTL8366RB_LED_BLINKRATE_446MS 0x0005
  121. #define RTL8366RB_LED_CTRL_REG 0x0431
  122. #define RTL8366RB_LED_OFF 0x0
  123. #define RTL8366RB_LED_DUP_COL 0x1
  124. #define RTL8366RB_LED_LINK_ACT 0x2
  125. #define RTL8366RB_LED_SPD1000 0x3
  126. #define RTL8366RB_LED_SPD100 0x4
  127. #define RTL8366RB_LED_SPD10 0x5
  128. #define RTL8366RB_LED_SPD1000_ACT 0x6
  129. #define RTL8366RB_LED_SPD100_ACT 0x7
  130. #define RTL8366RB_LED_SPD10_ACT 0x8
  131. #define RTL8366RB_LED_SPD100_10_ACT 0x9
  132. #define RTL8366RB_LED_FIBER 0xa
  133. #define RTL8366RB_LED_AN_FAULT 0xb
  134. #define RTL8366RB_LED_LINK_RX 0xc
  135. #define RTL8366RB_LED_LINK_TX 0xd
  136. #define RTL8366RB_LED_MASTER 0xe
  137. #define RTL8366RB_LED_FORCE 0xf
  138. #define RTL8366RB_LED_0_1_CTRL_REG 0x0432
  139. #define RTL8366RB_LED_1_OFFSET 6
  140. #define RTL8366RB_LED_2_3_CTRL_REG 0x0433
  141. #define RTL8366RB_LED_3_OFFSET 6
  142. #define RTL8366RB_MIB_COUNT 33
  143. #define RTL8366RB_GLOBAL_MIB_COUNT 1
  144. #define RTL8366RB_MIB_COUNTER_PORT_OFFSET 0x0050
  145. #define RTL8366RB_MIB_COUNTER_BASE 0x1000
  146. #define RTL8366RB_MIB_CTRL_REG 0x13F0
  147. #define RTL8366RB_MIB_CTRL_USER_MASK 0x0FFC
  148. #define RTL8366RB_MIB_CTRL_BUSY_MASK BIT(0)
  149. #define RTL8366RB_MIB_CTRL_RESET_MASK BIT(1)
  150. #define RTL8366RB_MIB_CTRL_PORT_RESET(_p) BIT(2 + (_p))
  151. #define RTL8366RB_MIB_CTRL_GLOBAL_RESET BIT(11)
  152. #define RTL8366RB_PORT_VLAN_CTRL_BASE 0x0063
  153. #define RTL8366RB_PORT_VLAN_CTRL_REG(_p) \
  154. (RTL8366RB_PORT_VLAN_CTRL_BASE + (_p) / 4)
  155. #define RTL8366RB_PORT_VLAN_CTRL_MASK 0xf
  156. #define RTL8366RB_PORT_VLAN_CTRL_SHIFT(_p) (4 * ((_p) % 4))
  157. #define RTL8366RB_VLAN_TABLE_READ_BASE 0x018C
  158. #define RTL8366RB_VLAN_TABLE_WRITE_BASE 0x0185
  159. #define RTL8366RB_TABLE_ACCESS_CTRL_REG 0x0180
  160. #define RTL8366RB_TABLE_VLAN_READ_CTRL 0x0E01
  161. #define RTL8366RB_TABLE_VLAN_WRITE_CTRL 0x0F01
  162. #define RTL8366RB_VLAN_MC_BASE(_x) (0x0020 + (_x) * 3)
  163. #define RTL8366RB_PORT_LINK_STATUS_BASE 0x0014
  164. #define RTL8366RB_PORT_STATUS_SPEED_MASK 0x0003
  165. #define RTL8366RB_PORT_STATUS_DUPLEX_MASK 0x0004
  166. #define RTL8366RB_PORT_STATUS_LINK_MASK 0x0010
  167. #define RTL8366RB_PORT_STATUS_TXPAUSE_MASK 0x0020
  168. #define RTL8366RB_PORT_STATUS_RXPAUSE_MASK 0x0040
  169. #define RTL8366RB_PORT_STATUS_AN_MASK 0x0080
  170. #define RTL8366RB_NUM_VLANS 16
  171. #define RTL8366RB_NUM_LEDGROUPS 4
  172. #define RTL8366RB_NUM_VIDS 4096
  173. #define RTL8366RB_PRIORITYMAX 7
  174. #define RTL8366RB_FIDMAX 7
  175. #define RTL8366RB_PORT_1 BIT(0) /* In userspace port 0 */
  176. #define RTL8366RB_PORT_2 BIT(1) /* In userspace port 1 */
  177. #define RTL8366RB_PORT_3 BIT(2) /* In userspace port 2 */
  178. #define RTL8366RB_PORT_4 BIT(3) /* In userspace port 3 */
  179. #define RTL8366RB_PORT_5 BIT(4) /* In userspace port 4 */
  180. #define RTL8366RB_PORT_CPU BIT(5) /* CPU port */
  181. #define RTL8366RB_PORT_ALL (RTL8366RB_PORT_1 | \
  182. RTL8366RB_PORT_2 | \
  183. RTL8366RB_PORT_3 | \
  184. RTL8366RB_PORT_4 | \
  185. RTL8366RB_PORT_5 | \
  186. RTL8366RB_PORT_CPU)
  187. #define RTL8366RB_PORT_ALL_BUT_CPU (RTL8366RB_PORT_1 | \
  188. RTL8366RB_PORT_2 | \
  189. RTL8366RB_PORT_3 | \
  190. RTL8366RB_PORT_4 | \
  191. RTL8366RB_PORT_5)
  192. #define RTL8366RB_PORT_ALL_EXTERNAL (RTL8366RB_PORT_1 | \
  193. RTL8366RB_PORT_2 | \
  194. RTL8366RB_PORT_3 | \
  195. RTL8366RB_PORT_4)
  196. #define RTL8366RB_PORT_ALL_INTERNAL RTL8366RB_PORT_CPU
  197. /* First configuration word per member config, VID and prio */
  198. #define RTL8366RB_VLAN_VID_MASK 0xfff
  199. #define RTL8366RB_VLAN_PRIORITY_SHIFT 12
  200. #define RTL8366RB_VLAN_PRIORITY_MASK 0x7
  201. /* Second configuration word per member config, member and untagged */
  202. #define RTL8366RB_VLAN_UNTAG_SHIFT 8
  203. #define RTL8366RB_VLAN_UNTAG_MASK 0xff
  204. #define RTL8366RB_VLAN_MEMBER_MASK 0xff
  205. /* Third config word per member config, STAG currently unused */
  206. #define RTL8366RB_VLAN_STAG_MBR_MASK 0xff
  207. #define RTL8366RB_VLAN_STAG_MBR_SHIFT 8
  208. #define RTL8366RB_VLAN_STAG_IDX_MASK 0x7
  209. #define RTL8366RB_VLAN_STAG_IDX_SHIFT 5
  210. #define RTL8366RB_VLAN_FID_MASK 0x7
  211. /* Port ingress bandwidth control */
  212. #define RTL8366RB_IB_BASE 0x0200
  213. #define RTL8366RB_IB_REG(pnum) (RTL8366RB_IB_BASE + (pnum))
  214. #define RTL8366RB_IB_BDTH_MASK 0x3fff
  215. #define RTL8366RB_IB_PREIFG BIT(14)
  216. /* Port egress bandwidth control */
  217. #define RTL8366RB_EB_BASE 0x02d1
  218. #define RTL8366RB_EB_REG(pnum) (RTL8366RB_EB_BASE + (pnum))
  219. #define RTL8366RB_EB_BDTH_MASK 0x3fff
  220. #define RTL8366RB_EB_PREIFG_REG 0x02f8
  221. #define RTL8366RB_EB_PREIFG BIT(9)
  222. #define RTL8366RB_BDTH_SW_MAX 1048512 /* 1048576? */
  223. #define RTL8366RB_BDTH_UNIT 64
  224. #define RTL8366RB_BDTH_REG_DEFAULT 16383
  225. /* QOS */
  226. #define RTL8366RB_QOS BIT(15)
  227. /* Include/Exclude Preamble and IFG (20 bytes). 0:Exclude, 1:Include. */
  228. #define RTL8366RB_QOS_DEFAULT_PREIFG 1
  229. /* Interrupt handling */
  230. #define RTL8366RB_INTERRUPT_CONTROL_REG 0x0440
  231. #define RTL8366RB_INTERRUPT_POLARITY BIT(0)
  232. #define RTL8366RB_P4_RGMII_LED BIT(2)
  233. #define RTL8366RB_INTERRUPT_MASK_REG 0x0441
  234. #define RTL8366RB_INTERRUPT_LINK_CHGALL GENMASK(11, 0)
  235. #define RTL8366RB_INTERRUPT_ACLEXCEED BIT(8)
  236. #define RTL8366RB_INTERRUPT_STORMEXCEED BIT(9)
  237. #define RTL8366RB_INTERRUPT_P4_FIBER BIT(12)
  238. #define RTL8366RB_INTERRUPT_P4_UTP BIT(13)
  239. #define RTL8366RB_INTERRUPT_VALID (RTL8366RB_INTERRUPT_LINK_CHGALL | \
  240. RTL8366RB_INTERRUPT_ACLEXCEED | \
  241. RTL8366RB_INTERRUPT_STORMEXCEED | \
  242. RTL8366RB_INTERRUPT_P4_FIBER | \
  243. RTL8366RB_INTERRUPT_P4_UTP)
  244. #define RTL8366RB_INTERRUPT_STATUS_REG 0x0442
  245. #define RTL8366RB_NUM_INTERRUPT 14 /* 0..13 */
  246. /* bits 0..5 enable force when cleared */
  247. #define RTL8366RB_MAC_FORCE_CTRL_REG 0x0F11
  248. #define RTL8366RB_OAM_PARSER_REG 0x0F14
  249. #define RTL8366RB_OAM_MULTIPLEXER_REG 0x0F15
  250. #define RTL8366RB_GREEN_FEATURE_REG 0x0F51
  251. #define RTL8366RB_GREEN_FEATURE_MSK 0x0007
  252. #define RTL8366RB_GREEN_FEATURE_TX BIT(0)
  253. #define RTL8366RB_GREEN_FEATURE_RX BIT(2)
  254. static struct rtl8366_mib_counter rtl8366rb_mib_counters[] = {
  255. { 0, 0, 4, "IfInOctets" },
  256. { 0, 4, 4, "EtherStatsOctets" },
  257. { 0, 8, 2, "EtherStatsUnderSizePkts" },
  258. { 0, 10, 2, "EtherFragments" },
  259. { 0, 12, 2, "EtherStatsPkts64Octets" },
  260. { 0, 14, 2, "EtherStatsPkts65to127Octets" },
  261. { 0, 16, 2, "EtherStatsPkts128to255Octets" },
  262. { 0, 18, 2, "EtherStatsPkts256to511Octets" },
  263. { 0, 20, 2, "EtherStatsPkts512to1023Octets" },
  264. { 0, 22, 2, "EtherStatsPkts1024to1518Octets" },
  265. { 0, 24, 2, "EtherOversizeStats" },
  266. { 0, 26, 2, "EtherStatsJabbers" },
  267. { 0, 28, 2, "IfInUcastPkts" },
  268. { 0, 30, 2, "EtherStatsMulticastPkts" },
  269. { 0, 32, 2, "EtherStatsBroadcastPkts" },
  270. { 0, 34, 2, "EtherStatsDropEvents" },
  271. { 0, 36, 2, "Dot3StatsFCSErrors" },
  272. { 0, 38, 2, "Dot3StatsSymbolErrors" },
  273. { 0, 40, 2, "Dot3InPauseFrames" },
  274. { 0, 42, 2, "Dot3ControlInUnknownOpcodes" },
  275. { 0, 44, 4, "IfOutOctets" },
  276. { 0, 48, 2, "Dot3StatsSingleCollisionFrames" },
  277. { 0, 50, 2, "Dot3StatMultipleCollisionFrames" },
  278. { 0, 52, 2, "Dot3sDeferredTransmissions" },
  279. { 0, 54, 2, "Dot3StatsLateCollisions" },
  280. { 0, 56, 2, "EtherStatsCollisions" },
  281. { 0, 58, 2, "Dot3StatsExcessiveCollisions" },
  282. { 0, 60, 2, "Dot3OutPauseFrames" },
  283. { 0, 62, 2, "Dot1dBasePortDelayExceededDiscards" },
  284. { 0, 64, 2, "Dot1dTpPortInDiscards" },
  285. { 0, 66, 2, "IfOutUcastPkts" },
  286. { 0, 68, 2, "IfOutMulticastPkts" },
  287. { 0, 70, 2, "IfOutBroadcastPkts" },
  288. };
  289. static int rtl8366rb_get_mib_counter(struct realtek_smi *smi,
  290. int port,
  291. struct rtl8366_mib_counter *mib,
  292. u64 *mibvalue)
  293. {
  294. u32 addr, val;
  295. int ret;
  296. int i;
  297. addr = RTL8366RB_MIB_COUNTER_BASE +
  298. RTL8366RB_MIB_COUNTER_PORT_OFFSET * (port) +
  299. mib->offset;
  300. /* Writing access counter address first
  301. * then ASIC will prepare 64bits counter wait for being retrived
  302. */
  303. ret = regmap_write(smi->map, addr, 0); /* Write whatever */
  304. if (ret)
  305. return ret;
  306. /* Read MIB control register */
  307. ret = regmap_read(smi->map, RTL8366RB_MIB_CTRL_REG, &val);
  308. if (ret)
  309. return -EIO;
  310. if (val & RTL8366RB_MIB_CTRL_BUSY_MASK)
  311. return -EBUSY;
  312. if (val & RTL8366RB_MIB_CTRL_RESET_MASK)
  313. return -EIO;
  314. /* Read each individual MIB 16 bits at the time */
  315. *mibvalue = 0;
  316. for (i = mib->length; i > 0; i--) {
  317. ret = regmap_read(smi->map, addr + (i - 1), &val);
  318. if (ret)
  319. return ret;
  320. *mibvalue = (*mibvalue << 16) | (val & 0xFFFF);
  321. }
  322. return 0;
  323. }
  324. static u32 rtl8366rb_get_irqmask(struct irq_data *d)
  325. {
  326. int line = irqd_to_hwirq(d);
  327. u32 val;
  328. /* For line interrupts we combine link down in bits
  329. * 6..11 with link up in bits 0..5 into one interrupt.
  330. */
  331. if (line < 12)
  332. val = BIT(line) | BIT(line + 6);
  333. else
  334. val = BIT(line);
  335. return val;
  336. }
  337. static void rtl8366rb_mask_irq(struct irq_data *d)
  338. {
  339. struct realtek_smi *smi = irq_data_get_irq_chip_data(d);
  340. int ret;
  341. ret = regmap_update_bits(smi->map, RTL8366RB_INTERRUPT_MASK_REG,
  342. rtl8366rb_get_irqmask(d), 0);
  343. if (ret)
  344. dev_err(smi->dev, "could not mask IRQ\n");
  345. }
  346. static void rtl8366rb_unmask_irq(struct irq_data *d)
  347. {
  348. struct realtek_smi *smi = irq_data_get_irq_chip_data(d);
  349. int ret;
  350. ret = regmap_update_bits(smi->map, RTL8366RB_INTERRUPT_MASK_REG,
  351. rtl8366rb_get_irqmask(d),
  352. rtl8366rb_get_irqmask(d));
  353. if (ret)
  354. dev_err(smi->dev, "could not unmask IRQ\n");
  355. }
  356. static irqreturn_t rtl8366rb_irq(int irq, void *data)
  357. {
  358. struct realtek_smi *smi = data;
  359. u32 stat;
  360. int ret;
  361. /* This clears the IRQ status register */
  362. ret = regmap_read(smi->map, RTL8366RB_INTERRUPT_STATUS_REG,
  363. &stat);
  364. if (ret) {
  365. dev_err(smi->dev, "can't read interrupt status\n");
  366. return IRQ_NONE;
  367. }
  368. stat &= RTL8366RB_INTERRUPT_VALID;
  369. if (!stat)
  370. return IRQ_NONE;
  371. while (stat) {
  372. int line = __ffs(stat);
  373. int child_irq;
  374. stat &= ~BIT(line);
  375. /* For line interrupts we combine link down in bits
  376. * 6..11 with link up in bits 0..5 into one interrupt.
  377. */
  378. if (line < 12 && line > 5)
  379. line -= 5;
  380. child_irq = irq_find_mapping(smi->irqdomain, line);
  381. handle_nested_irq(child_irq);
  382. }
  383. return IRQ_HANDLED;
  384. }
  385. static struct irq_chip rtl8366rb_irq_chip = {
  386. .name = "RTL8366RB",
  387. .irq_mask = rtl8366rb_mask_irq,
  388. .irq_unmask = rtl8366rb_unmask_irq,
  389. };
  390. static int rtl8366rb_irq_map(struct irq_domain *domain, unsigned int irq,
  391. irq_hw_number_t hwirq)
  392. {
  393. irq_set_chip_data(irq, domain->host_data);
  394. irq_set_chip_and_handler(irq, &rtl8366rb_irq_chip, handle_simple_irq);
  395. irq_set_nested_thread(irq, 1);
  396. irq_set_noprobe(irq);
  397. return 0;
  398. }
  399. static void rtl8366rb_irq_unmap(struct irq_domain *d, unsigned int irq)
  400. {
  401. irq_set_nested_thread(irq, 0);
  402. irq_set_chip_and_handler(irq, NULL, NULL);
  403. irq_set_chip_data(irq, NULL);
  404. }
  405. static const struct irq_domain_ops rtl8366rb_irqdomain_ops = {
  406. .map = rtl8366rb_irq_map,
  407. .unmap = rtl8366rb_irq_unmap,
  408. .xlate = irq_domain_xlate_onecell,
  409. };
  410. static int rtl8366rb_setup_cascaded_irq(struct realtek_smi *smi)
  411. {
  412. struct device_node *intc;
  413. unsigned long irq_trig;
  414. int irq;
  415. int ret;
  416. u32 val;
  417. int i;
  418. intc = of_get_child_by_name(smi->dev->of_node, "interrupt-controller");
  419. if (!intc) {
  420. dev_err(smi->dev, "missing child interrupt-controller node\n");
  421. return -EINVAL;
  422. }
  423. /* RB8366RB IRQs cascade off this one */
  424. irq = of_irq_get(intc, 0);
  425. if (irq <= 0) {
  426. dev_err(smi->dev, "failed to get parent IRQ\n");
  427. return irq ? irq : -EINVAL;
  428. }
  429. /* This clears the IRQ status register */
  430. ret = regmap_read(smi->map, RTL8366RB_INTERRUPT_STATUS_REG,
  431. &val);
  432. if (ret) {
  433. dev_err(smi->dev, "can't read interrupt status\n");
  434. return ret;
  435. }
  436. /* Fetch IRQ edge information from the descriptor */
  437. irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq));
  438. switch (irq_trig) {
  439. case IRQF_TRIGGER_RISING:
  440. case IRQF_TRIGGER_HIGH:
  441. dev_info(smi->dev, "active high/rising IRQ\n");
  442. val = 0;
  443. break;
  444. case IRQF_TRIGGER_FALLING:
  445. case IRQF_TRIGGER_LOW:
  446. dev_info(smi->dev, "active low/falling IRQ\n");
  447. val = RTL8366RB_INTERRUPT_POLARITY;
  448. break;
  449. }
  450. ret = regmap_update_bits(smi->map, RTL8366RB_INTERRUPT_CONTROL_REG,
  451. RTL8366RB_INTERRUPT_POLARITY,
  452. val);
  453. if (ret) {
  454. dev_err(smi->dev, "could not configure IRQ polarity\n");
  455. return ret;
  456. }
  457. ret = devm_request_threaded_irq(smi->dev, irq, NULL,
  458. rtl8366rb_irq, IRQF_ONESHOT,
  459. "RTL8366RB", smi);
  460. if (ret) {
  461. dev_err(smi->dev, "unable to request irq: %d\n", ret);
  462. return ret;
  463. }
  464. smi->irqdomain = irq_domain_add_linear(intc,
  465. RTL8366RB_NUM_INTERRUPT,
  466. &rtl8366rb_irqdomain_ops,
  467. smi);
  468. if (!smi->irqdomain) {
  469. dev_err(smi->dev, "failed to create IRQ domain\n");
  470. return -EINVAL;
  471. }
  472. for (i = 0; i < smi->num_ports; i++)
  473. irq_set_parent(irq_create_mapping(smi->irqdomain, i), irq);
  474. return 0;
  475. }
  476. static int rtl8366rb_set_addr(struct realtek_smi *smi)
  477. {
  478. u8 addr[ETH_ALEN];
  479. u16 val;
  480. int ret;
  481. eth_random_addr(addr);
  482. dev_info(smi->dev, "set MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
  483. addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
  484. val = addr[0] << 8 | addr[1];
  485. ret = regmap_write(smi->map, RTL8366RB_SMAR0, val);
  486. if (ret)
  487. return ret;
  488. val = addr[2] << 8 | addr[3];
  489. ret = regmap_write(smi->map, RTL8366RB_SMAR1, val);
  490. if (ret)
  491. return ret;
  492. val = addr[4] << 8 | addr[5];
  493. ret = regmap_write(smi->map, RTL8366RB_SMAR2, val);
  494. if (ret)
  495. return ret;
  496. return 0;
  497. }
  498. /* Found in a vendor driver */
  499. /* For the "version 0" early silicon, appear in most source releases */
  500. static const u16 rtl8366rb_init_jam_ver_0[] = {
  501. 0x000B, 0x0001, 0x03A6, 0x0100, 0x03A7, 0x0001, 0x02D1, 0x3FFF,
  502. 0x02D2, 0x3FFF, 0x02D3, 0x3FFF, 0x02D4, 0x3FFF, 0x02D5, 0x3FFF,
  503. 0x02D6, 0x3FFF, 0x02D7, 0x3FFF, 0x02D8, 0x3FFF, 0x022B, 0x0688,
  504. 0x022C, 0x0FAC, 0x03D0, 0x4688, 0x03D1, 0x01F5, 0x0000, 0x0830,
  505. 0x02F9, 0x0200, 0x02F7, 0x7FFF, 0x02F8, 0x03FF, 0x0080, 0x03E8,
  506. 0x0081, 0x00CE, 0x0082, 0x00DA, 0x0083, 0x0230, 0xBE0F, 0x2000,
  507. 0x0231, 0x422A, 0x0232, 0x422A, 0x0233, 0x422A, 0x0234, 0x422A,
  508. 0x0235, 0x422A, 0x0236, 0x422A, 0x0237, 0x422A, 0x0238, 0x422A,
  509. 0x0239, 0x422A, 0x023A, 0x422A, 0x023B, 0x422A, 0x023C, 0x422A,
  510. 0x023D, 0x422A, 0x023E, 0x422A, 0x023F, 0x422A, 0x0240, 0x422A,
  511. 0x0241, 0x422A, 0x0242, 0x422A, 0x0243, 0x422A, 0x0244, 0x422A,
  512. 0x0245, 0x422A, 0x0246, 0x422A, 0x0247, 0x422A, 0x0248, 0x422A,
  513. 0x0249, 0x0146, 0x024A, 0x0146, 0x024B, 0x0146, 0xBE03, 0xC961,
  514. 0x024D, 0x0146, 0x024E, 0x0146, 0x024F, 0x0146, 0x0250, 0x0146,
  515. 0xBE64, 0x0226, 0x0252, 0x0146, 0x0253, 0x0146, 0x024C, 0x0146,
  516. 0x0251, 0x0146, 0x0254, 0x0146, 0xBE62, 0x3FD0, 0x0084, 0x0320,
  517. 0x0255, 0x0146, 0x0256, 0x0146, 0x0257, 0x0146, 0x0258, 0x0146,
  518. 0x0259, 0x0146, 0x025A, 0x0146, 0x025B, 0x0146, 0x025C, 0x0146,
  519. 0x025D, 0x0146, 0x025E, 0x0146, 0x025F, 0x0146, 0x0260, 0x0146,
  520. 0x0261, 0xA23F, 0x0262, 0x0294, 0x0263, 0xA23F, 0x0264, 0x0294,
  521. 0x0265, 0xA23F, 0x0266, 0x0294, 0x0267, 0xA23F, 0x0268, 0x0294,
  522. 0x0269, 0xA23F, 0x026A, 0x0294, 0x026B, 0xA23F, 0x026C, 0x0294,
  523. 0x026D, 0xA23F, 0x026E, 0x0294, 0x026F, 0xA23F, 0x0270, 0x0294,
  524. 0x02F5, 0x0048, 0xBE09, 0x0E00, 0xBE1E, 0x0FA0, 0xBE14, 0x8448,
  525. 0xBE15, 0x1007, 0xBE4A, 0xA284, 0xC454, 0x3F0B, 0xC474, 0x3F0B,
  526. 0xBE48, 0x3672, 0xBE4B, 0x17A7, 0xBE4C, 0x0B15, 0xBE52, 0x0EDD,
  527. 0xBE49, 0x8C00, 0xBE5B, 0x785C, 0xBE5C, 0x785C, 0xBE5D, 0x785C,
  528. 0xBE61, 0x368A, 0xBE63, 0x9B84, 0xC456, 0xCC13, 0xC476, 0xCC13,
  529. 0xBE65, 0x307D, 0xBE6D, 0x0005, 0xBE6E, 0xE120, 0xBE2E, 0x7BAF,
  530. };
  531. /* This v1 init sequence is from Belkin F5D8235 U-Boot release */
  532. static const u16 rtl8366rb_init_jam_ver_1[] = {
  533. 0x0000, 0x0830, 0x0001, 0x8000, 0x0400, 0x8130, 0xBE78, 0x3C3C,
  534. 0x0431, 0x5432, 0xBE37, 0x0CE4, 0x02FA, 0xFFDF, 0x02FB, 0xFFE0,
  535. 0xC44C, 0x1585, 0xC44C, 0x1185, 0xC44C, 0x1585, 0xC46C, 0x1585,
  536. 0xC46C, 0x1185, 0xC46C, 0x1585, 0xC451, 0x2135, 0xC471, 0x2135,
  537. 0xBE10, 0x8140, 0xBE15, 0x0007, 0xBE6E, 0xE120, 0xBE69, 0xD20F,
  538. 0xBE6B, 0x0320, 0xBE24, 0xB000, 0xBE23, 0xFF51, 0xBE22, 0xDF20,
  539. 0xBE21, 0x0140, 0xBE20, 0x00BB, 0xBE24, 0xB800, 0xBE24, 0x0000,
  540. 0xBE24, 0x7000, 0xBE23, 0xFF51, 0xBE22, 0xDF60, 0xBE21, 0x0140,
  541. 0xBE20, 0x0077, 0xBE24, 0x7800, 0xBE24, 0x0000, 0xBE2E, 0x7B7A,
  542. 0xBE36, 0x0CE4, 0x02F5, 0x0048, 0xBE77, 0x2940, 0x000A, 0x83E0,
  543. 0xBE79, 0x3C3C, 0xBE00, 0x1340,
  544. };
  545. /* This v2 init sequence is from Belkin F5D8235 U-Boot release */
  546. static const u16 rtl8366rb_init_jam_ver_2[] = {
  547. 0x0450, 0x0000, 0x0400, 0x8130, 0x000A, 0x83ED, 0x0431, 0x5432,
  548. 0xC44F, 0x6250, 0xC46F, 0x6250, 0xC456, 0x0C14, 0xC476, 0x0C14,
  549. 0xC44C, 0x1C85, 0xC44C, 0x1885, 0xC44C, 0x1C85, 0xC46C, 0x1C85,
  550. 0xC46C, 0x1885, 0xC46C, 0x1C85, 0xC44C, 0x0885, 0xC44C, 0x0881,
  551. 0xC44C, 0x0885, 0xC46C, 0x0885, 0xC46C, 0x0881, 0xC46C, 0x0885,
  552. 0xBE2E, 0x7BA7, 0xBE36, 0x1000, 0xBE37, 0x1000, 0x8000, 0x0001,
  553. 0xBE69, 0xD50F, 0x8000, 0x0000, 0xBE69, 0xD50F, 0xBE6E, 0x0320,
  554. 0xBE77, 0x2940, 0xBE78, 0x3C3C, 0xBE79, 0x3C3C, 0xBE6E, 0xE120,
  555. 0x8000, 0x0001, 0xBE15, 0x1007, 0x8000, 0x0000, 0xBE15, 0x1007,
  556. 0xBE14, 0x0448, 0xBE1E, 0x00A0, 0xBE10, 0x8160, 0xBE10, 0x8140,
  557. 0xBE00, 0x1340, 0x0F51, 0x0010,
  558. };
  559. /* Appears in a DDWRT code dump */
  560. static const u16 rtl8366rb_init_jam_ver_3[] = {
  561. 0x0000, 0x0830, 0x0400, 0x8130, 0x000A, 0x83ED, 0x0431, 0x5432,
  562. 0x0F51, 0x0017, 0x02F5, 0x0048, 0x02FA, 0xFFDF, 0x02FB, 0xFFE0,
  563. 0xC456, 0x0C14, 0xC476, 0x0C14, 0xC454, 0x3F8B, 0xC474, 0x3F8B,
  564. 0xC450, 0x2071, 0xC470, 0x2071, 0xC451, 0x226B, 0xC471, 0x226B,
  565. 0xC452, 0xA293, 0xC472, 0xA293, 0xC44C, 0x1585, 0xC44C, 0x1185,
  566. 0xC44C, 0x1585, 0xC46C, 0x1585, 0xC46C, 0x1185, 0xC46C, 0x1585,
  567. 0xC44C, 0x0185, 0xC44C, 0x0181, 0xC44C, 0x0185, 0xC46C, 0x0185,
  568. 0xC46C, 0x0181, 0xC46C, 0x0185, 0xBE24, 0xB000, 0xBE23, 0xFF51,
  569. 0xBE22, 0xDF20, 0xBE21, 0x0140, 0xBE20, 0x00BB, 0xBE24, 0xB800,
  570. 0xBE24, 0x0000, 0xBE24, 0x7000, 0xBE23, 0xFF51, 0xBE22, 0xDF60,
  571. 0xBE21, 0x0140, 0xBE20, 0x0077, 0xBE24, 0x7800, 0xBE24, 0x0000,
  572. 0xBE2E, 0x7BA7, 0xBE36, 0x1000, 0xBE37, 0x1000, 0x8000, 0x0001,
  573. 0xBE69, 0xD50F, 0x8000, 0x0000, 0xBE69, 0xD50F, 0xBE6B, 0x0320,
  574. 0xBE77, 0x2800, 0xBE78, 0x3C3C, 0xBE79, 0x3C3C, 0xBE6E, 0xE120,
  575. 0x8000, 0x0001, 0xBE10, 0x8140, 0x8000, 0x0000, 0xBE10, 0x8140,
  576. 0xBE15, 0x1007, 0xBE14, 0x0448, 0xBE1E, 0x00A0, 0xBE10, 0x8160,
  577. 0xBE10, 0x8140, 0xBE00, 0x1340, 0x0450, 0x0000, 0x0401, 0x0000,
  578. };
  579. /* Belkin F5D8235 v1, "belkin,f5d8235-v1" */
  580. static const u16 rtl8366rb_init_jam_f5d8235[] = {
  581. 0x0242, 0x02BF, 0x0245, 0x02BF, 0x0248, 0x02BF, 0x024B, 0x02BF,
  582. 0x024E, 0x02BF, 0x0251, 0x02BF, 0x0254, 0x0A3F, 0x0256, 0x0A3F,
  583. 0x0258, 0x0A3F, 0x025A, 0x0A3F, 0x025C, 0x0A3F, 0x025E, 0x0A3F,
  584. 0x0263, 0x007C, 0x0100, 0x0004, 0xBE5B, 0x3500, 0x800E, 0x200F,
  585. 0xBE1D, 0x0F00, 0x8001, 0x5011, 0x800A, 0xA2F4, 0x800B, 0x17A3,
  586. 0xBE4B, 0x17A3, 0xBE41, 0x5011, 0xBE17, 0x2100, 0x8000, 0x8304,
  587. 0xBE40, 0x8304, 0xBE4A, 0xA2F4, 0x800C, 0xA8D5, 0x8014, 0x5500,
  588. 0x8015, 0x0004, 0xBE4C, 0xA8D5, 0xBE59, 0x0008, 0xBE09, 0x0E00,
  589. 0xBE36, 0x1036, 0xBE37, 0x1036, 0x800D, 0x00FF, 0xBE4D, 0x00FF,
  590. };
  591. /* DGN3500, "netgear,dgn3500", "netgear,dgn3500b" */
  592. static const u16 rtl8366rb_init_jam_dgn3500[] = {
  593. 0x0000, 0x0830, 0x0400, 0x8130, 0x000A, 0x83ED, 0x0F51, 0x0017,
  594. 0x02F5, 0x0048, 0x02FA, 0xFFDF, 0x02FB, 0xFFE0, 0x0450, 0x0000,
  595. 0x0401, 0x0000, 0x0431, 0x0960,
  596. };
  597. /* This jam table activates "green ethernet", which means low power mode
  598. * and is claimed to detect the cable length and not use more power than
  599. * necessary, and the ports should enter power saving mode 10 seconds after
  600. * a cable is disconnected. Seems to always be the same.
  601. */
  602. static const u16 rtl8366rb_green_jam[][2] = {
  603. {0xBE78, 0x323C}, {0xBE77, 0x5000}, {0xBE2E, 0x7BA7},
  604. {0xBE59, 0x3459}, {0xBE5A, 0x745A}, {0xBE5B, 0x785C},
  605. {0xBE5C, 0x785C}, {0xBE6E, 0xE120}, {0xBE79, 0x323C},
  606. };
  607. static int rtl8366rb_setup(struct dsa_switch *ds)
  608. {
  609. struct realtek_smi *smi = ds->priv;
  610. const u16 *jam_table;
  611. u32 chip_ver = 0;
  612. u32 chip_id = 0;
  613. int jam_size;
  614. u32 val;
  615. int ret;
  616. int i;
  617. ret = regmap_read(smi->map, RTL8366RB_CHIP_ID_REG, &chip_id);
  618. if (ret) {
  619. dev_err(smi->dev, "unable to read chip id\n");
  620. return ret;
  621. }
  622. switch (chip_id) {
  623. case RTL8366RB_CHIP_ID_8366:
  624. break;
  625. default:
  626. dev_err(smi->dev, "unknown chip id (%04x)\n", chip_id);
  627. return -ENODEV;
  628. }
  629. ret = regmap_read(smi->map, RTL8366RB_CHIP_VERSION_CTRL_REG,
  630. &chip_ver);
  631. if (ret) {
  632. dev_err(smi->dev, "unable to read chip version\n");
  633. return ret;
  634. }
  635. dev_info(smi->dev, "RTL%04x ver %u chip found\n",
  636. chip_id, chip_ver & RTL8366RB_CHIP_VERSION_MASK);
  637. /* Do the init dance using the right jam table */
  638. switch (chip_ver) {
  639. case 0:
  640. jam_table = rtl8366rb_init_jam_ver_0;
  641. jam_size = ARRAY_SIZE(rtl8366rb_init_jam_ver_0);
  642. break;
  643. case 1:
  644. jam_table = rtl8366rb_init_jam_ver_1;
  645. jam_size = ARRAY_SIZE(rtl8366rb_init_jam_ver_1);
  646. break;
  647. case 2:
  648. jam_table = rtl8366rb_init_jam_ver_2;
  649. jam_size = ARRAY_SIZE(rtl8366rb_init_jam_ver_2);
  650. break;
  651. default:
  652. jam_table = rtl8366rb_init_jam_ver_3;
  653. jam_size = ARRAY_SIZE(rtl8366rb_init_jam_ver_3);
  654. break;
  655. }
  656. /* Special jam tables for special routers
  657. * TODO: are these necessary? Maintainers, please test
  658. * without them, using just the off-the-shelf tables.
  659. */
  660. if (of_machine_is_compatible("belkin,f5d8235-v1")) {
  661. jam_table = rtl8366rb_init_jam_f5d8235;
  662. jam_size = ARRAY_SIZE(rtl8366rb_init_jam_f5d8235);
  663. }
  664. if (of_machine_is_compatible("netgear,dgn3500") ||
  665. of_machine_is_compatible("netgear,dgn3500b")) {
  666. jam_table = rtl8366rb_init_jam_dgn3500;
  667. jam_size = ARRAY_SIZE(rtl8366rb_init_jam_dgn3500);
  668. }
  669. i = 0;
  670. while (i < jam_size) {
  671. if ((jam_table[i] & 0xBE00) == 0xBE00) {
  672. ret = regmap_read(smi->map,
  673. RTL8366RB_PHY_ACCESS_BUSY_REG,
  674. &val);
  675. if (ret)
  676. return ret;
  677. if (!(val & RTL8366RB_PHY_INT_BUSY)) {
  678. ret = regmap_write(smi->map,
  679. RTL8366RB_PHY_ACCESS_CTRL_REG,
  680. RTL8366RB_PHY_CTRL_WRITE);
  681. if (ret)
  682. return ret;
  683. }
  684. }
  685. dev_dbg(smi->dev, "jam %04x into register %04x\n",
  686. jam_table[i + 1],
  687. jam_table[i]);
  688. ret = regmap_write(smi->map,
  689. jam_table[i],
  690. jam_table[i + 1]);
  691. if (ret)
  692. return ret;
  693. i += 2;
  694. }
  695. /* Set up the "green ethernet" feature */
  696. i = 0;
  697. while (i < ARRAY_SIZE(rtl8366rb_green_jam)) {
  698. ret = regmap_read(smi->map, RTL8366RB_PHY_ACCESS_BUSY_REG,
  699. &val);
  700. if (ret)
  701. return ret;
  702. if (!(val & RTL8366RB_PHY_INT_BUSY)) {
  703. ret = regmap_write(smi->map,
  704. RTL8366RB_PHY_ACCESS_CTRL_REG,
  705. RTL8366RB_PHY_CTRL_WRITE);
  706. if (ret)
  707. return ret;
  708. ret = regmap_write(smi->map,
  709. rtl8366rb_green_jam[i][0],
  710. rtl8366rb_green_jam[i][1]);
  711. if (ret)
  712. return ret;
  713. i++;
  714. }
  715. }
  716. ret = regmap_write(smi->map,
  717. RTL8366RB_GREEN_FEATURE_REG,
  718. (chip_ver == 1) ? 0x0007 : 0x0003);
  719. if (ret)
  720. return ret;
  721. /* Vendor driver sets 0x240 in registers 0xc and 0xd (undocumented) */
  722. ret = regmap_write(smi->map, 0x0c, 0x240);
  723. if (ret)
  724. return ret;
  725. ret = regmap_write(smi->map, 0x0d, 0x240);
  726. if (ret)
  727. return ret;
  728. /* Set some random MAC address */
  729. ret = rtl8366rb_set_addr(smi);
  730. if (ret)
  731. return ret;
  732. /* Enable CPU port and enable inserting CPU tag
  733. *
  734. * Disabling RTL8368RB_CPU_INSTAG here will change the behaviour
  735. * of the switch totally and it will start talking Realtek RRCP
  736. * internally. It is probably possible to experiment with this,
  737. * but then the kernel needs to understand and handle RRCP first.
  738. */
  739. ret = regmap_update_bits(smi->map, RTL8368RB_CPU_CTRL_REG,
  740. 0xFFFF,
  741. RTL8368RB_CPU_INSTAG | BIT(smi->cpu_port));
  742. if (ret)
  743. return ret;
  744. /* Make sure we default-enable the fixed CPU port */
  745. ret = regmap_update_bits(smi->map, RTL8366RB_PECR,
  746. BIT(smi->cpu_port),
  747. 0);
  748. if (ret)
  749. return ret;
  750. /* Set maximum packet length to 1536 bytes */
  751. ret = regmap_update_bits(smi->map, RTL8366RB_SGCR,
  752. RTL8366RB_SGCR_MAX_LENGTH_MASK,
  753. RTL8366RB_SGCR_MAX_LENGTH_1536);
  754. if (ret)
  755. return ret;
  756. /* Enable learning for all ports */
  757. ret = regmap_write(smi->map, RTL8366RB_SSCR0, 0);
  758. if (ret)
  759. return ret;
  760. /* Enable auto ageing for all ports */
  761. ret = regmap_write(smi->map, RTL8366RB_SSCR1, 0);
  762. if (ret)
  763. return ret;
  764. /* Discard VLAN tagged packets if the port is not a member of
  765. * the VLAN with which the packets is associated.
  766. */
  767. ret = regmap_write(smi->map, RTL8366RB_VLAN_INGRESS_CTRL2_REG,
  768. RTL8366RB_PORT_ALL);
  769. if (ret)
  770. return ret;
  771. /* Don't drop packets whose DA has not been learned */
  772. ret = regmap_update_bits(smi->map, RTL8366RB_SSCR2,
  773. RTL8366RB_SSCR2_DROP_UNKNOWN_DA, 0);
  774. if (ret)
  775. return ret;
  776. /* Set blinking, TODO: make this configurable */
  777. ret = regmap_update_bits(smi->map, RTL8366RB_LED_BLINKRATE_REG,
  778. RTL8366RB_LED_BLINKRATE_MASK,
  779. RTL8366RB_LED_BLINKRATE_56MS);
  780. if (ret)
  781. return ret;
  782. /* Set up LED activity:
  783. * Each port has 4 LEDs, we configure all ports to the same
  784. * behaviour (no individual config) but we can set up each
  785. * LED separately.
  786. */
  787. if (smi->leds_disabled) {
  788. /* Turn everything off */
  789. regmap_update_bits(smi->map,
  790. RTL8366RB_LED_0_1_CTRL_REG,
  791. 0x0FFF, 0);
  792. regmap_update_bits(smi->map,
  793. RTL8366RB_LED_2_3_CTRL_REG,
  794. 0x0FFF, 0);
  795. regmap_update_bits(smi->map,
  796. RTL8366RB_INTERRUPT_CONTROL_REG,
  797. RTL8366RB_P4_RGMII_LED,
  798. 0);
  799. val = RTL8366RB_LED_OFF;
  800. } else {
  801. /* TODO: make this configurable per LED */
  802. val = RTL8366RB_LED_FORCE;
  803. }
  804. for (i = 0; i < 4; i++) {
  805. ret = regmap_update_bits(smi->map,
  806. RTL8366RB_LED_CTRL_REG,
  807. 0xf << (i * 4),
  808. val << (i * 4));
  809. if (ret)
  810. return ret;
  811. }
  812. ret = rtl8366_init_vlan(smi);
  813. if (ret)
  814. return ret;
  815. ret = rtl8366rb_setup_cascaded_irq(smi);
  816. if (ret)
  817. dev_info(smi->dev, "no interrupt support\n");
  818. ret = realtek_smi_setup_mdio(smi);
  819. if (ret) {
  820. dev_info(smi->dev, "could not set up MDIO bus\n");
  821. return -ENODEV;
  822. }
  823. return 0;
  824. }
  825. static enum dsa_tag_protocol rtl8366_get_tag_protocol(struct dsa_switch *ds,
  826. int port)
  827. {
  828. /* For now, the RTL switches are handled without any custom tags.
  829. *
  830. * It is possible to turn on "custom tags" by removing the
  831. * RTL8368RB_CPU_INSTAG flag when enabling the port but what it
  832. * does is unfamiliar to DSA: ethernet frames of type 8899, the Realtek
  833. * Remote Control Protocol (RRCP) start to appear on the CPU port of
  834. * the device. So this is not the ordinary few extra bytes in the
  835. * frame. Instead it appears that the switch starts to talk Realtek
  836. * RRCP internally which means a pretty complex RRCP implementation
  837. * decoding and responding the RRCP protocol is needed to exploit this.
  838. *
  839. * The OpenRRCP project (dormant since 2009) have reverse-egineered
  840. * parts of the protocol.
  841. */
  842. return DSA_TAG_PROTO_NONE;
  843. }
  844. static void rtl8366rb_adjust_link(struct dsa_switch *ds, int port,
  845. struct phy_device *phydev)
  846. {
  847. struct realtek_smi *smi = ds->priv;
  848. int ret;
  849. if (port != smi->cpu_port)
  850. return;
  851. dev_info(smi->dev, "adjust link on CPU port (%d)\n", port);
  852. /* Force the fixed CPU port into 1Gbit mode, no autonegotiation */
  853. ret = regmap_update_bits(smi->map, RTL8366RB_MAC_FORCE_CTRL_REG,
  854. BIT(port), BIT(port));
  855. if (ret)
  856. return;
  857. ret = regmap_update_bits(smi->map, RTL8366RB_PAACR2,
  858. 0xFF00U,
  859. RTL8366RB_PAACR_CPU_PORT << 8);
  860. if (ret)
  861. return;
  862. /* Enable the CPU port */
  863. ret = regmap_update_bits(smi->map, RTL8366RB_PECR, BIT(port),
  864. 0);
  865. if (ret)
  866. return;
  867. }
  868. static void rb8366rb_set_port_led(struct realtek_smi *smi,
  869. int port, bool enable)
  870. {
  871. u16 val = enable ? 0x3f : 0;
  872. int ret;
  873. if (smi->leds_disabled)
  874. return;
  875. switch (port) {
  876. case 0:
  877. ret = regmap_update_bits(smi->map,
  878. RTL8366RB_LED_0_1_CTRL_REG,
  879. 0x3F, val);
  880. break;
  881. case 1:
  882. ret = regmap_update_bits(smi->map,
  883. RTL8366RB_LED_0_1_CTRL_REG,
  884. 0x3F << RTL8366RB_LED_1_OFFSET,
  885. val << RTL8366RB_LED_1_OFFSET);
  886. break;
  887. case 2:
  888. ret = regmap_update_bits(smi->map,
  889. RTL8366RB_LED_2_3_CTRL_REG,
  890. 0x3F, val);
  891. break;
  892. case 3:
  893. ret = regmap_update_bits(smi->map,
  894. RTL8366RB_LED_2_3_CTRL_REG,
  895. 0x3F << RTL8366RB_LED_3_OFFSET,
  896. val << RTL8366RB_LED_3_OFFSET);
  897. break;
  898. case 4:
  899. ret = regmap_update_bits(smi->map,
  900. RTL8366RB_INTERRUPT_CONTROL_REG,
  901. RTL8366RB_P4_RGMII_LED,
  902. enable ? RTL8366RB_P4_RGMII_LED : 0);
  903. break;
  904. default:
  905. dev_err(smi->dev, "no LED for port %d\n", port);
  906. return;
  907. }
  908. if (ret)
  909. dev_err(smi->dev, "error updating LED on port %d\n", port);
  910. }
  911. static int
  912. rtl8366rb_port_enable(struct dsa_switch *ds, int port,
  913. struct phy_device *phy)
  914. {
  915. struct realtek_smi *smi = ds->priv;
  916. int ret;
  917. dev_dbg(smi->dev, "enable port %d\n", port);
  918. ret = regmap_update_bits(smi->map, RTL8366RB_PECR, BIT(port),
  919. 0);
  920. if (ret)
  921. return ret;
  922. rb8366rb_set_port_led(smi, port, true);
  923. return 0;
  924. }
  925. static void
  926. rtl8366rb_port_disable(struct dsa_switch *ds, int port,
  927. struct phy_device *phy)
  928. {
  929. struct realtek_smi *smi = ds->priv;
  930. int ret;
  931. dev_dbg(smi->dev, "disable port %d\n", port);
  932. ret = regmap_update_bits(smi->map, RTL8366RB_PECR, BIT(port),
  933. BIT(port));
  934. if (ret)
  935. return;
  936. rb8366rb_set_port_led(smi, port, false);
  937. }
  938. static int rtl8366rb_get_vlan_4k(struct realtek_smi *smi, u32 vid,
  939. struct rtl8366_vlan_4k *vlan4k)
  940. {
  941. u32 data[3];
  942. int ret;
  943. int i;
  944. memset(vlan4k, '\0', sizeof(struct rtl8366_vlan_4k));
  945. if (vid >= RTL8366RB_NUM_VIDS)
  946. return -EINVAL;
  947. /* write VID */
  948. ret = regmap_write(smi->map, RTL8366RB_VLAN_TABLE_WRITE_BASE,
  949. vid & RTL8366RB_VLAN_VID_MASK);
  950. if (ret)
  951. return ret;
  952. /* write table access control word */
  953. ret = regmap_write(smi->map, RTL8366RB_TABLE_ACCESS_CTRL_REG,
  954. RTL8366RB_TABLE_VLAN_READ_CTRL);
  955. if (ret)
  956. return ret;
  957. for (i = 0; i < 3; i++) {
  958. ret = regmap_read(smi->map,
  959. RTL8366RB_VLAN_TABLE_READ_BASE + i,
  960. &data[i]);
  961. if (ret)
  962. return ret;
  963. }
  964. vlan4k->vid = vid;
  965. vlan4k->untag = (data[1] >> RTL8366RB_VLAN_UNTAG_SHIFT) &
  966. RTL8366RB_VLAN_UNTAG_MASK;
  967. vlan4k->member = data[1] & RTL8366RB_VLAN_MEMBER_MASK;
  968. vlan4k->fid = data[2] & RTL8366RB_VLAN_FID_MASK;
  969. return 0;
  970. }
  971. static int rtl8366rb_set_vlan_4k(struct realtek_smi *smi,
  972. const struct rtl8366_vlan_4k *vlan4k)
  973. {
  974. u32 data[3];
  975. int ret;
  976. int i;
  977. if (vlan4k->vid >= RTL8366RB_NUM_VIDS ||
  978. vlan4k->member > RTL8366RB_VLAN_MEMBER_MASK ||
  979. vlan4k->untag > RTL8366RB_VLAN_UNTAG_MASK ||
  980. vlan4k->fid > RTL8366RB_FIDMAX)
  981. return -EINVAL;
  982. data[0] = vlan4k->vid & RTL8366RB_VLAN_VID_MASK;
  983. data[1] = (vlan4k->member & RTL8366RB_VLAN_MEMBER_MASK) |
  984. ((vlan4k->untag & RTL8366RB_VLAN_UNTAG_MASK) <<
  985. RTL8366RB_VLAN_UNTAG_SHIFT);
  986. data[2] = vlan4k->fid & RTL8366RB_VLAN_FID_MASK;
  987. for (i = 0; i < 3; i++) {
  988. ret = regmap_write(smi->map,
  989. RTL8366RB_VLAN_TABLE_WRITE_BASE + i,
  990. data[i]);
  991. if (ret)
  992. return ret;
  993. }
  994. /* write table access control word */
  995. ret = regmap_write(smi->map, RTL8366RB_TABLE_ACCESS_CTRL_REG,
  996. RTL8366RB_TABLE_VLAN_WRITE_CTRL);
  997. return ret;
  998. }
  999. static int rtl8366rb_get_vlan_mc(struct realtek_smi *smi, u32 index,
  1000. struct rtl8366_vlan_mc *vlanmc)
  1001. {
  1002. u32 data[3];
  1003. int ret;
  1004. int i;
  1005. memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
  1006. if (index >= RTL8366RB_NUM_VLANS)
  1007. return -EINVAL;
  1008. for (i = 0; i < 3; i++) {
  1009. ret = regmap_read(smi->map,
  1010. RTL8366RB_VLAN_MC_BASE(index) + i,
  1011. &data[i]);
  1012. if (ret)
  1013. return ret;
  1014. }
  1015. vlanmc->vid = data[0] & RTL8366RB_VLAN_VID_MASK;
  1016. vlanmc->priority = (data[0] >> RTL8366RB_VLAN_PRIORITY_SHIFT) &
  1017. RTL8366RB_VLAN_PRIORITY_MASK;
  1018. vlanmc->untag = (data[1] >> RTL8366RB_VLAN_UNTAG_SHIFT) &
  1019. RTL8366RB_VLAN_UNTAG_MASK;
  1020. vlanmc->member = data[1] & RTL8366RB_VLAN_MEMBER_MASK;
  1021. vlanmc->fid = data[2] & RTL8366RB_VLAN_FID_MASK;
  1022. return 0;
  1023. }
  1024. static int rtl8366rb_set_vlan_mc(struct realtek_smi *smi, u32 index,
  1025. const struct rtl8366_vlan_mc *vlanmc)
  1026. {
  1027. u32 data[3];
  1028. int ret;
  1029. int i;
  1030. if (index >= RTL8366RB_NUM_VLANS ||
  1031. vlanmc->vid >= RTL8366RB_NUM_VIDS ||
  1032. vlanmc->priority > RTL8366RB_PRIORITYMAX ||
  1033. vlanmc->member > RTL8366RB_VLAN_MEMBER_MASK ||
  1034. vlanmc->untag > RTL8366RB_VLAN_UNTAG_MASK ||
  1035. vlanmc->fid > RTL8366RB_FIDMAX)
  1036. return -EINVAL;
  1037. data[0] = (vlanmc->vid & RTL8366RB_VLAN_VID_MASK) |
  1038. ((vlanmc->priority & RTL8366RB_VLAN_PRIORITY_MASK) <<
  1039. RTL8366RB_VLAN_PRIORITY_SHIFT);
  1040. data[1] = (vlanmc->member & RTL8366RB_VLAN_MEMBER_MASK) |
  1041. ((vlanmc->untag & RTL8366RB_VLAN_UNTAG_MASK) <<
  1042. RTL8366RB_VLAN_UNTAG_SHIFT);
  1043. data[2] = vlanmc->fid & RTL8366RB_VLAN_FID_MASK;
  1044. for (i = 0; i < 3; i++) {
  1045. ret = regmap_write(smi->map,
  1046. RTL8366RB_VLAN_MC_BASE(index) + i,
  1047. data[i]);
  1048. if (ret)
  1049. return ret;
  1050. }
  1051. return 0;
  1052. }
  1053. static int rtl8366rb_get_mc_index(struct realtek_smi *smi, int port, int *val)
  1054. {
  1055. u32 data;
  1056. int ret;
  1057. if (port >= smi->num_ports)
  1058. return -EINVAL;
  1059. ret = regmap_read(smi->map, RTL8366RB_PORT_VLAN_CTRL_REG(port),
  1060. &data);
  1061. if (ret)
  1062. return ret;
  1063. *val = (data >> RTL8366RB_PORT_VLAN_CTRL_SHIFT(port)) &
  1064. RTL8366RB_PORT_VLAN_CTRL_MASK;
  1065. return 0;
  1066. }
  1067. static int rtl8366rb_set_mc_index(struct realtek_smi *smi, int port, int index)
  1068. {
  1069. if (port >= smi->num_ports || index >= RTL8366RB_NUM_VLANS)
  1070. return -EINVAL;
  1071. return regmap_update_bits(smi->map, RTL8366RB_PORT_VLAN_CTRL_REG(port),
  1072. RTL8366RB_PORT_VLAN_CTRL_MASK <<
  1073. RTL8366RB_PORT_VLAN_CTRL_SHIFT(port),
  1074. (index & RTL8366RB_PORT_VLAN_CTRL_MASK) <<
  1075. RTL8366RB_PORT_VLAN_CTRL_SHIFT(port));
  1076. }
  1077. static bool rtl8366rb_is_vlan_valid(struct realtek_smi *smi, unsigned int vlan)
  1078. {
  1079. unsigned int max = RTL8366RB_NUM_VLANS;
  1080. if (smi->vlan4k_enabled)
  1081. max = RTL8366RB_NUM_VIDS - 1;
  1082. if (vlan == 0 || vlan >= max)
  1083. return false;
  1084. return true;
  1085. }
  1086. static int rtl8366rb_enable_vlan(struct realtek_smi *smi, bool enable)
  1087. {
  1088. dev_dbg(smi->dev, "%s VLAN\n", enable ? "enable" : "disable");
  1089. return regmap_update_bits(smi->map,
  1090. RTL8366RB_SGCR, RTL8366RB_SGCR_EN_VLAN,
  1091. enable ? RTL8366RB_SGCR_EN_VLAN : 0);
  1092. }
  1093. static int rtl8366rb_enable_vlan4k(struct realtek_smi *smi, bool enable)
  1094. {
  1095. dev_dbg(smi->dev, "%s VLAN 4k\n", enable ? "enable" : "disable");
  1096. return regmap_update_bits(smi->map, RTL8366RB_SGCR,
  1097. RTL8366RB_SGCR_EN_VLAN_4KTB,
  1098. enable ? RTL8366RB_SGCR_EN_VLAN_4KTB : 0);
  1099. }
  1100. static int rtl8366rb_phy_read(struct realtek_smi *smi, int phy, int regnum)
  1101. {
  1102. u32 val;
  1103. u32 reg;
  1104. int ret;
  1105. if (phy > RTL8366RB_PHY_NO_MAX)
  1106. return -EINVAL;
  1107. ret = regmap_write(smi->map, RTL8366RB_PHY_ACCESS_CTRL_REG,
  1108. RTL8366RB_PHY_CTRL_READ);
  1109. if (ret)
  1110. return ret;
  1111. reg = 0x8000 | (1 << (phy + RTL8366RB_PHY_NO_OFFSET)) | regnum;
  1112. ret = regmap_write(smi->map, reg, 0);
  1113. if (ret) {
  1114. dev_err(smi->dev,
  1115. "failed to write PHY%d reg %04x @ %04x, ret %d\n",
  1116. phy, regnum, reg, ret);
  1117. return ret;
  1118. }
  1119. ret = regmap_read(smi->map, RTL8366RB_PHY_ACCESS_DATA_REG, &val);
  1120. if (ret)
  1121. return ret;
  1122. dev_dbg(smi->dev, "read PHY%d register 0x%04x @ %08x, val <- %04x\n",
  1123. phy, regnum, reg, val);
  1124. return val;
  1125. }
  1126. static int rtl8366rb_phy_write(struct realtek_smi *smi, int phy, int regnum,
  1127. u16 val)
  1128. {
  1129. u32 reg;
  1130. int ret;
  1131. if (phy > RTL8366RB_PHY_NO_MAX)
  1132. return -EINVAL;
  1133. ret = regmap_write(smi->map, RTL8366RB_PHY_ACCESS_CTRL_REG,
  1134. RTL8366RB_PHY_CTRL_WRITE);
  1135. if (ret)
  1136. return ret;
  1137. reg = 0x8000 | (1 << (phy + RTL8366RB_PHY_NO_OFFSET)) | regnum;
  1138. dev_dbg(smi->dev, "write PHY%d register 0x%04x @ %04x, val -> %04x\n",
  1139. phy, regnum, reg, val);
  1140. ret = regmap_write(smi->map, reg, val);
  1141. if (ret)
  1142. return ret;
  1143. return 0;
  1144. }
  1145. static int rtl8366rb_reset_chip(struct realtek_smi *smi)
  1146. {
  1147. int timeout = 10;
  1148. u32 val;
  1149. int ret;
  1150. realtek_smi_write_reg_noack(smi, RTL8366RB_RESET_CTRL_REG,
  1151. RTL8366RB_CHIP_CTRL_RESET_HW);
  1152. do {
  1153. usleep_range(20000, 25000);
  1154. ret = regmap_read(smi->map, RTL8366RB_RESET_CTRL_REG, &val);
  1155. if (ret)
  1156. return ret;
  1157. if (!(val & RTL8366RB_CHIP_CTRL_RESET_HW))
  1158. break;
  1159. } while (--timeout);
  1160. if (!timeout) {
  1161. dev_err(smi->dev, "timeout waiting for the switch to reset\n");
  1162. return -EIO;
  1163. }
  1164. return 0;
  1165. }
  1166. static int rtl8366rb_detect(struct realtek_smi *smi)
  1167. {
  1168. struct device *dev = smi->dev;
  1169. int ret;
  1170. u32 val;
  1171. /* Detect device */
  1172. ret = regmap_read(smi->map, 0x5c, &val);
  1173. if (ret) {
  1174. dev_err(dev, "can't get chip ID (%d)\n", ret);
  1175. return ret;
  1176. }
  1177. switch (val) {
  1178. case 0x6027:
  1179. dev_info(dev, "found an RTL8366S switch\n");
  1180. dev_err(dev, "this switch is not yet supported, submit patches!\n");
  1181. return -ENODEV;
  1182. case 0x5937:
  1183. dev_info(dev, "found an RTL8366RB switch\n");
  1184. smi->cpu_port = RTL8366RB_PORT_NUM_CPU;
  1185. smi->num_ports = RTL8366RB_NUM_PORTS;
  1186. smi->num_vlan_mc = RTL8366RB_NUM_VLANS;
  1187. smi->mib_counters = rtl8366rb_mib_counters;
  1188. smi->num_mib_counters = ARRAY_SIZE(rtl8366rb_mib_counters);
  1189. break;
  1190. default:
  1191. dev_info(dev, "found an Unknown Realtek switch (id=0x%04x)\n",
  1192. val);
  1193. break;
  1194. }
  1195. ret = rtl8366rb_reset_chip(smi);
  1196. if (ret)
  1197. return ret;
  1198. return 0;
  1199. }
  1200. static const struct dsa_switch_ops rtl8366rb_switch_ops = {
  1201. .get_tag_protocol = rtl8366_get_tag_protocol,
  1202. .setup = rtl8366rb_setup,
  1203. .adjust_link = rtl8366rb_adjust_link,
  1204. .get_strings = rtl8366_get_strings,
  1205. .get_ethtool_stats = rtl8366_get_ethtool_stats,
  1206. .get_sset_count = rtl8366_get_sset_count,
  1207. .port_vlan_filtering = rtl8366_vlan_filtering,
  1208. .port_vlan_prepare = rtl8366_vlan_prepare,
  1209. .port_vlan_add = rtl8366_vlan_add,
  1210. .port_vlan_del = rtl8366_vlan_del,
  1211. .port_enable = rtl8366rb_port_enable,
  1212. .port_disable = rtl8366rb_port_disable,
  1213. };
  1214. static const struct realtek_smi_ops rtl8366rb_smi_ops = {
  1215. .detect = rtl8366rb_detect,
  1216. .get_vlan_mc = rtl8366rb_get_vlan_mc,
  1217. .set_vlan_mc = rtl8366rb_set_vlan_mc,
  1218. .get_vlan_4k = rtl8366rb_get_vlan_4k,
  1219. .set_vlan_4k = rtl8366rb_set_vlan_4k,
  1220. .get_mc_index = rtl8366rb_get_mc_index,
  1221. .set_mc_index = rtl8366rb_set_mc_index,
  1222. .get_mib_counter = rtl8366rb_get_mib_counter,
  1223. .is_vlan_valid = rtl8366rb_is_vlan_valid,
  1224. .enable_vlan = rtl8366rb_enable_vlan,
  1225. .enable_vlan4k = rtl8366rb_enable_vlan4k,
  1226. .phy_read = rtl8366rb_phy_read,
  1227. .phy_write = rtl8366rb_phy_write,
  1228. };
  1229. const struct realtek_smi_variant rtl8366rb_variant = {
  1230. .ds_ops = &rtl8366rb_switch_ops,
  1231. .ops = &rtl8366rb_smi_ops,
  1232. .clk_delay = 10,
  1233. .cmd_read = 0xa9,
  1234. .cmd_write = 0xa8,
  1235. };
  1236. EXPORT_SYMBOL_GPL(rtl8366rb_variant);