ar8216.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * ar8216.h: AR8216 switch driver
  3. *
  4. * Copyright (C) 2009 Felix Fietkau <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #ifndef __AR8216_H
  17. #define __AR8216_H
  18. #define BITS(_s, _n) (((1UL << (_n)) - 1) << _s)
  19. #define AR8XXX_CAP_GIGE BIT(0)
  20. #define AR8XXX_CAP_MIB_COUNTERS BIT(1)
  21. #define AR8XXX_NUM_PHYS 5
  22. #define AR8216_PORT_CPU 0
  23. #define AR8216_NUM_PORTS 6
  24. #define AR8216_NUM_VLANS 16
  25. #define AR7240SW_NUM_PORTS 5
  26. #define AR8316_NUM_VLANS 4096
  27. /* size of the vlan table */
  28. #define AR8X16_MAX_VLANS 128
  29. #define AR83X7_MAX_VLANS 4096
  30. #define AR8XXX_MAX_VLANS AR83X7_MAX_VLANS
  31. #define AR8X16_PROBE_RETRIES 10
  32. #define AR8X16_MAX_PORTS 8
  33. #define AR8XXX_REG_ARL_CTRL_AGE_TIME_SECS 7
  34. #define AR8XXX_DEFAULT_ARL_AGE_TIME 300
  35. /* Atheros specific MII registers */
  36. #define MII_ATH_MMD_ADDR 0x0d
  37. #define MII_ATH_MMD_DATA 0x0e
  38. #define MII_ATH_DBG_ADDR 0x1d
  39. #define MII_ATH_DBG_DATA 0x1e
  40. #define AR8216_REG_CTRL 0x0000
  41. #define AR8216_CTRL_REVISION BITS(0, 8)
  42. #define AR8216_CTRL_REVISION_S 0
  43. #define AR8216_CTRL_VERSION BITS(8, 8)
  44. #define AR8216_CTRL_VERSION_S 8
  45. #define AR8216_CTRL_RESET BIT(31)
  46. #define AR8216_REG_FLOOD_MASK 0x002C
  47. #define AR8216_FM_UNI_DEST_PORTS BITS(0, 6)
  48. #define AR8216_FM_MULTI_DEST_PORTS BITS(16, 6)
  49. #define AR8216_FM_CPU_BROADCAST_EN BIT(26)
  50. #define AR8229_FLOOD_MASK_UC_DP(_p) BIT(_p)
  51. #define AR8229_FLOOD_MASK_MC_DP(_p) BIT(16 + (_p))
  52. #define AR8229_FLOOD_MASK_BC_DP(_p) BIT(25 + (_p))
  53. #define AR8216_REG_GLOBAL_CTRL 0x0030
  54. #define AR8216_GCTRL_MTU BITS(0, 11)
  55. #define AR8236_GCTRL_MTU BITS(0, 14)
  56. #define AR8316_GCTRL_MTU BITS(0, 14)
  57. #define AR8216_REG_VTU 0x0040
  58. #define AR8216_VTU_OP BITS(0, 3)
  59. #define AR8216_VTU_OP_NOOP 0x0
  60. #define AR8216_VTU_OP_FLUSH 0x1
  61. #define AR8216_VTU_OP_LOAD 0x2
  62. #define AR8216_VTU_OP_PURGE 0x3
  63. #define AR8216_VTU_OP_REMOVE_PORT 0x4
  64. #define AR8216_VTU_ACTIVE BIT(3)
  65. #define AR8216_VTU_FULL BIT(4)
  66. #define AR8216_VTU_PORT BITS(8, 4)
  67. #define AR8216_VTU_PORT_S 8
  68. #define AR8216_VTU_VID BITS(16, 12)
  69. #define AR8216_VTU_VID_S 16
  70. #define AR8216_VTU_PRIO BITS(28, 3)
  71. #define AR8216_VTU_PRIO_S 28
  72. #define AR8216_VTU_PRIO_EN BIT(31)
  73. #define AR8216_REG_VTU_DATA 0x0044
  74. #define AR8216_VTUDATA_MEMBER BITS(0, 10)
  75. #define AR8236_VTUDATA_MEMBER BITS(0, 7)
  76. #define AR8216_VTUDATA_VALID BIT(11)
  77. #define AR8216_REG_ATU_FUNC0 0x0050
  78. #define AR8216_ATU_OP BITS(0, 3)
  79. #define AR8216_ATU_OP_NOOP 0x0
  80. #define AR8216_ATU_OP_FLUSH 0x1
  81. #define AR8216_ATU_OP_LOAD 0x2
  82. #define AR8216_ATU_OP_PURGE 0x3
  83. #define AR8216_ATU_OP_FLUSH_UNLOCKED 0x4
  84. #define AR8216_ATU_OP_FLUSH_PORT 0x5
  85. #define AR8216_ATU_OP_GET_NEXT 0x6
  86. #define AR8216_ATU_ACTIVE BIT(3)
  87. #define AR8216_ATU_PORT_NUM BITS(8, 4)
  88. #define AR8216_ATU_PORT_NUM_S 8
  89. #define AR8216_ATU_FULL_VIO BIT(12)
  90. #define AR8216_ATU_ADDR5 BITS(16, 8)
  91. #define AR8216_ATU_ADDR5_S 16
  92. #define AR8216_ATU_ADDR4 BITS(24, 8)
  93. #define AR8216_ATU_ADDR4_S 24
  94. #define AR8216_REG_ATU_FUNC1 0x0054
  95. #define AR8216_ATU_ADDR3 BITS(0, 8)
  96. #define AR8216_ATU_ADDR3_S 0
  97. #define AR8216_ATU_ADDR2 BITS(8, 8)
  98. #define AR8216_ATU_ADDR2_S 8
  99. #define AR8216_ATU_ADDR1 BITS(16, 8)
  100. #define AR8216_ATU_ADDR1_S 16
  101. #define AR8216_ATU_ADDR0 BITS(24, 8)
  102. #define AR8216_ATU_ADDR0_S 24
  103. #define AR8216_REG_ATU_FUNC2 0x0058
  104. #define AR8216_ATU_PORTS BITS(0, 6)
  105. #define AR8216_ATU_PORTS_S 0
  106. #define AR8216_ATU_PORT0 BIT(0)
  107. #define AR8216_ATU_PORT1 BIT(1)
  108. #define AR8216_ATU_PORT2 BIT(2)
  109. #define AR8216_ATU_PORT3 BIT(3)
  110. #define AR8216_ATU_PORT4 BIT(4)
  111. #define AR8216_ATU_PORT5 BIT(5)
  112. #define AR8216_ATU_STATUS BITS(16, 4)
  113. #define AR8216_ATU_STATUS_S 16
  114. #define AR8216_REG_ATU_CTRL 0x005C
  115. #define AR8216_ATU_CTRL_AGE_EN BIT(17)
  116. #define AR8216_ATU_CTRL_AGE_TIME BITS(0, 16)
  117. #define AR8216_ATU_CTRL_AGE_TIME_S 0
  118. #define AR8236_ATU_CTRL_RES BIT(20)
  119. #define AR8216_ATU_CTRL_LEARN_CHANGE BIT(18)
  120. #define AR8216_ATU_CTRL_RESERVED BIT(19)
  121. #define AR8216_ATU_CTRL_ARP_EN BIT(20)
  122. #define AR8216_REG_TAG_PRIORITY 0x0070
  123. #define AR8216_REG_SERVICE_TAG 0x0074
  124. #define AR8216_SERVICE_TAG_M BITS(0, 16)
  125. #define AR8216_REG_MIB_FUNC 0x0080
  126. #define AR8216_MIB_TIMER BITS(0, 16)
  127. #define AR8216_MIB_AT_HALF_EN BIT(16)
  128. #define AR8216_MIB_BUSY BIT(17)
  129. #define AR8216_MIB_FUNC BITS(24, 3)
  130. #define AR8216_MIB_FUNC_S 24
  131. #define AR8216_MIB_FUNC_NO_OP 0x0
  132. #define AR8216_MIB_FUNC_FLUSH 0x1
  133. #define AR8216_MIB_FUNC_CAPTURE 0x3
  134. #define AR8236_MIB_EN BIT(30)
  135. #define AR8216_REG_GLOBAL_CPUPORT 0x0078
  136. #define AR8216_GLOBAL_CPUPORT_MIRROR_PORT BITS(4, 4)
  137. #define AR8216_GLOBAL_CPUPORT_MIRROR_PORT_S 4
  138. #define AR8216_GLOBAL_CPUPORT_EN BIT(8)
  139. #define AR8216_REG_MDIO_CTRL 0x98
  140. #define AR8216_MDIO_CTRL_DATA_M BITS(0, 16)
  141. #define AR8216_MDIO_CTRL_REG_ADDR_S 16
  142. #define AR8216_MDIO_CTRL_PHY_ADDR_S 21
  143. #define AR8216_MDIO_CTRL_CMD_WRITE 0
  144. #define AR8216_MDIO_CTRL_CMD_READ BIT(27)
  145. #define AR8216_MDIO_CTRL_MASTER_EN BIT(30)
  146. #define AR8216_MDIO_CTRL_BUSY BIT(31)
  147. #define AR8216_PORT_OFFSET(_i) (0x0100 * (_i + 1))
  148. #define AR8216_REG_PORT_STATUS(_i) (AR8216_PORT_OFFSET(_i) + 0x0000)
  149. #define AR8216_PORT_STATUS_SPEED BITS(0,2)
  150. #define AR8216_PORT_STATUS_SPEED_S 0
  151. #define AR8216_PORT_STATUS_TXMAC BIT(2)
  152. #define AR8216_PORT_STATUS_RXMAC BIT(3)
  153. #define AR8216_PORT_STATUS_TXFLOW BIT(4)
  154. #define AR8216_PORT_STATUS_RXFLOW BIT(5)
  155. #define AR8216_PORT_STATUS_DUPLEX BIT(6)
  156. #define AR8216_PORT_STATUS_LINK_UP BIT(8)
  157. #define AR8216_PORT_STATUS_LINK_AUTO BIT(9)
  158. #define AR8216_PORT_STATUS_LINK_PAUSE BIT(10)
  159. #define AR8216_PORT_STATUS_FLOW_CONTROL BIT(12)
  160. #define AR8216_REG_PORT_CTRL(_i) (AR8216_PORT_OFFSET(_i) + 0x0004)
  161. /* port forwarding state */
  162. #define AR8216_PORT_CTRL_STATE BITS(0, 3)
  163. #define AR8216_PORT_CTRL_STATE_S 0
  164. #define AR8216_PORT_CTRL_LEARN_LOCK BIT(7)
  165. /* egress 802.1q mode */
  166. #define AR8216_PORT_CTRL_VLAN_MODE BITS(8, 2)
  167. #define AR8216_PORT_CTRL_VLAN_MODE_S 8
  168. #define AR8216_PORT_CTRL_IGMP_SNOOP BIT(10)
  169. #define AR8216_PORT_CTRL_HEADER BIT(11)
  170. #define AR8216_PORT_CTRL_MAC_LOOP BIT(12)
  171. #define AR8216_PORT_CTRL_SINGLE_VLAN BIT(13)
  172. #define AR8216_PORT_CTRL_LEARN BIT(14)
  173. #define AR8216_PORT_CTRL_MIRROR_TX BIT(16)
  174. #define AR8216_PORT_CTRL_MIRROR_RX BIT(17)
  175. #define AR8216_REG_PORT_VLAN(_i) (AR8216_PORT_OFFSET(_i) + 0x0008)
  176. #define AR8216_PORT_VLAN_DEFAULT_ID BITS(0, 12)
  177. #define AR8216_PORT_VLAN_DEFAULT_ID_S 0
  178. #define AR8216_PORT_VLAN_DEST_PORTS BITS(16, 9)
  179. #define AR8216_PORT_VLAN_DEST_PORTS_S 16
  180. /* bit0 added to the priority field of egress frames */
  181. #define AR8216_PORT_VLAN_TX_PRIO BIT(27)
  182. /* port default priority */
  183. #define AR8216_PORT_VLAN_PRIORITY BITS(28, 2)
  184. #define AR8216_PORT_VLAN_PRIORITY_S 28
  185. /* ingress 802.1q mode */
  186. #define AR8216_PORT_VLAN_MODE BITS(30, 2)
  187. #define AR8216_PORT_VLAN_MODE_S 30
  188. #define AR8216_REG_PORT_RATE(_i) (AR8216_PORT_OFFSET(_i) + 0x000c)
  189. #define AR8216_REG_PORT_PRIO(_i) (AR8216_PORT_OFFSET(_i) + 0x0010)
  190. #define AR8216_STATS_RXBROAD 0x00
  191. #define AR8216_STATS_RXPAUSE 0x04
  192. #define AR8216_STATS_RXMULTI 0x08
  193. #define AR8216_STATS_RXFCSERR 0x0c
  194. #define AR8216_STATS_RXALIGNERR 0x10
  195. #define AR8216_STATS_RXRUNT 0x14
  196. #define AR8216_STATS_RXFRAGMENT 0x18
  197. #define AR8216_STATS_RX64BYTE 0x1c
  198. #define AR8216_STATS_RX128BYTE 0x20
  199. #define AR8216_STATS_RX256BYTE 0x24
  200. #define AR8216_STATS_RX512BYTE 0x28
  201. #define AR8216_STATS_RX1024BYTE 0x2c
  202. #define AR8216_STATS_RXMAXBYTE 0x30
  203. #define AR8216_STATS_RXTOOLONG 0x34
  204. #define AR8216_STATS_RXGOODBYTE 0x38
  205. #define AR8216_STATS_RXBADBYTE 0x40
  206. #define AR8216_STATS_RXOVERFLOW 0x48
  207. #define AR8216_STATS_FILTERED 0x4c
  208. #define AR8216_STATS_TXBROAD 0x50
  209. #define AR8216_STATS_TXPAUSE 0x54
  210. #define AR8216_STATS_TXMULTI 0x58
  211. #define AR8216_STATS_TXUNDERRUN 0x5c
  212. #define AR8216_STATS_TX64BYTE 0x60
  213. #define AR8216_STATS_TX128BYTE 0x64
  214. #define AR8216_STATS_TX256BYTE 0x68
  215. #define AR8216_STATS_TX512BYTE 0x6c
  216. #define AR8216_STATS_TX1024BYTE 0x70
  217. #define AR8216_STATS_TXMAXBYTE 0x74
  218. #define AR8216_STATS_TXOVERSIZE 0x78
  219. #define AR8216_STATS_TXBYTE 0x7c
  220. #define AR8216_STATS_TXCOLLISION 0x84
  221. #define AR8216_STATS_TXABORTCOL 0x88
  222. #define AR8216_STATS_TXMULTICOL 0x8c
  223. #define AR8216_STATS_TXSINGLECOL 0x90
  224. #define AR8216_STATS_TXEXCDEFER 0x94
  225. #define AR8216_STATS_TXDEFER 0x98
  226. #define AR8216_STATS_TXLATECOL 0x9c
  227. #define AR8216_MIB_RXB_ID 14 /* RxGoodByte */
  228. #define AR8216_MIB_TXB_ID 29 /* TxByte */
  229. #define AR8229_REG_OPER_MODE0 0x04
  230. #define AR8229_OPER_MODE0_MAC_GMII_EN BIT(6)
  231. #define AR8229_OPER_MODE0_PHY_MII_EN BIT(10)
  232. #define AR8229_REG_OPER_MODE1 0x08
  233. #define AR8229_REG_OPER_MODE1_PHY4_MII_EN BIT(28)
  234. #define AR8229_REG_QM_CTRL 0x3c
  235. #define AR8229_QM_CTRL_ARP_EN BIT(15)
  236. #define AR8236_REG_PORT_VLAN(_i) (AR8216_PORT_OFFSET((_i)) + 0x0008)
  237. #define AR8236_PORT_VLAN_DEFAULT_ID BITS(16, 12)
  238. #define AR8236_PORT_VLAN_DEFAULT_ID_S 16
  239. #define AR8236_PORT_VLAN_PRIORITY BITS(29, 3)
  240. #define AR8236_PORT_VLAN_PRIORITY_S 28
  241. #define AR8236_REG_PORT_VLAN2(_i) (AR8216_PORT_OFFSET((_i)) + 0x000c)
  242. #define AR8236_PORT_VLAN2_MEMBER BITS(16, 7)
  243. #define AR8236_PORT_VLAN2_MEMBER_S 16
  244. #define AR8236_PORT_VLAN2_TX_PRIO BIT(23)
  245. #define AR8236_PORT_VLAN2_VLAN_MODE BITS(30, 2)
  246. #define AR8236_PORT_VLAN2_VLAN_MODE_S 30
  247. #define AR8236_STATS_RXBROAD 0x00
  248. #define AR8236_STATS_RXPAUSE 0x04
  249. #define AR8236_STATS_RXMULTI 0x08
  250. #define AR8236_STATS_RXFCSERR 0x0c
  251. #define AR8236_STATS_RXALIGNERR 0x10
  252. #define AR8236_STATS_RXRUNT 0x14
  253. #define AR8236_STATS_RXFRAGMENT 0x18
  254. #define AR8236_STATS_RX64BYTE 0x1c
  255. #define AR8236_STATS_RX128BYTE 0x20
  256. #define AR8236_STATS_RX256BYTE 0x24
  257. #define AR8236_STATS_RX512BYTE 0x28
  258. #define AR8236_STATS_RX1024BYTE 0x2c
  259. #define AR8236_STATS_RX1518BYTE 0x30
  260. #define AR8236_STATS_RXMAXBYTE 0x34
  261. #define AR8236_STATS_RXTOOLONG 0x38
  262. #define AR8236_STATS_RXGOODBYTE 0x3c
  263. #define AR8236_STATS_RXBADBYTE 0x44
  264. #define AR8236_STATS_RXOVERFLOW 0x4c
  265. #define AR8236_STATS_FILTERED 0x50
  266. #define AR8236_STATS_TXBROAD 0x54
  267. #define AR8236_STATS_TXPAUSE 0x58
  268. #define AR8236_STATS_TXMULTI 0x5c
  269. #define AR8236_STATS_TXUNDERRUN 0x60
  270. #define AR8236_STATS_TX64BYTE 0x64
  271. #define AR8236_STATS_TX128BYTE 0x68
  272. #define AR8236_STATS_TX256BYTE 0x6c
  273. #define AR8236_STATS_TX512BYTE 0x70
  274. #define AR8236_STATS_TX1024BYTE 0x74
  275. #define AR8236_STATS_TX1518BYTE 0x78
  276. #define AR8236_STATS_TXMAXBYTE 0x7c
  277. #define AR8236_STATS_TXOVERSIZE 0x80
  278. #define AR8236_STATS_TXBYTE 0x84
  279. #define AR8236_STATS_TXCOLLISION 0x8c
  280. #define AR8236_STATS_TXABORTCOL 0x90
  281. #define AR8236_STATS_TXMULTICOL 0x94
  282. #define AR8236_STATS_TXSINGLECOL 0x98
  283. #define AR8236_STATS_TXEXCDEFER 0x9c
  284. #define AR8236_STATS_TXDEFER 0xa0
  285. #define AR8236_STATS_TXLATECOL 0xa4
  286. #define AR8236_MIB_RXB_ID 15 /* RxGoodByte */
  287. #define AR8236_MIB_TXB_ID 31 /* TxByte */
  288. #define AR8316_REG_POSTRIP 0x0008
  289. #define AR8316_POSTRIP_MAC0_GMII_EN BIT(0)
  290. #define AR8316_POSTRIP_MAC0_RGMII_EN BIT(1)
  291. #define AR8316_POSTRIP_PHY4_GMII_EN BIT(2)
  292. #define AR8316_POSTRIP_PHY4_RGMII_EN BIT(3)
  293. #define AR8316_POSTRIP_MAC0_MAC_MODE BIT(4)
  294. #define AR8316_POSTRIP_RTL_MODE BIT(5)
  295. #define AR8316_POSTRIP_RGMII_RXCLK_DELAY_EN BIT(6)
  296. #define AR8316_POSTRIP_RGMII_TXCLK_DELAY_EN BIT(7)
  297. #define AR8316_POSTRIP_SERDES_EN BIT(8)
  298. #define AR8316_POSTRIP_SEL_ANA_RST BIT(9)
  299. #define AR8316_POSTRIP_GATE_25M_EN BIT(10)
  300. #define AR8316_POSTRIP_SEL_CLK25M BIT(11)
  301. #define AR8316_POSTRIP_HIB_PULSE_HW BIT(12)
  302. #define AR8316_POSTRIP_DBG_MODE_I BIT(13)
  303. #define AR8316_POSTRIP_MAC5_MAC_MODE BIT(14)
  304. #define AR8316_POSTRIP_MAC5_PHY_MODE BIT(15)
  305. #define AR8316_POSTRIP_POWER_DOWN_HW BIT(16)
  306. #define AR8316_POSTRIP_LPW_STATE_EN BIT(17)
  307. #define AR8316_POSTRIP_MAN_EN BIT(18)
  308. #define AR8316_POSTRIP_PHY_PLL_ON BIT(19)
  309. #define AR8316_POSTRIP_LPW_EXIT BIT(20)
  310. #define AR8316_POSTRIP_TXDELAY_S0 BIT(21)
  311. #define AR8316_POSTRIP_TXDELAY_S1 BIT(22)
  312. #define AR8316_POSTRIP_RXDELAY_S0 BIT(23)
  313. #define AR8316_POSTRIP_LED_OPEN_EN BIT(24)
  314. #define AR8316_POSTRIP_SPI_EN BIT(25)
  315. #define AR8316_POSTRIP_RXDELAY_S1 BIT(26)
  316. #define AR8316_POSTRIP_POWER_ON_SEL BIT(31)
  317. /* port speed */
  318. enum {
  319. AR8216_PORT_SPEED_10M = 0,
  320. AR8216_PORT_SPEED_100M = 1,
  321. AR8216_PORT_SPEED_1000M = 2,
  322. AR8216_PORT_SPEED_ERR = 3,
  323. };
  324. /* ingress 802.1q mode */
  325. enum {
  326. AR8216_IN_PORT_ONLY = 0,
  327. AR8216_IN_PORT_FALLBACK = 1,
  328. AR8216_IN_VLAN_ONLY = 2,
  329. AR8216_IN_SECURE = 3
  330. };
  331. /* egress 802.1q mode */
  332. enum {
  333. AR8216_OUT_KEEP = 0,
  334. AR8216_OUT_STRIP_VLAN = 1,
  335. AR8216_OUT_ADD_VLAN = 2
  336. };
  337. /* port forwarding state */
  338. enum {
  339. AR8216_PORT_STATE_DISABLED = 0,
  340. AR8216_PORT_STATE_BLOCK = 1,
  341. AR8216_PORT_STATE_LISTEN = 2,
  342. AR8216_PORT_STATE_LEARN = 3,
  343. AR8216_PORT_STATE_FORWARD = 4
  344. };
  345. /* mib counter type */
  346. enum {
  347. AR8XXX_MIB_BASIC = 0,
  348. AR8XXX_MIB_EXTENDED = 1
  349. };
  350. enum {
  351. AR8XXX_VER_AR8216 = 0x01,
  352. AR8XXX_VER_AR8236 = 0x03,
  353. AR8XXX_VER_AR8316 = 0x10,
  354. AR8XXX_VER_AR8327 = 0x12,
  355. AR8XXX_VER_AR8337 = 0x13,
  356. };
  357. #define AR8XXX_NUM_ARL_RECORDS 100
  358. enum arl_op {
  359. AR8XXX_ARL_INITIALIZE,
  360. AR8XXX_ARL_GET_NEXT
  361. };
  362. struct arl_entry {
  363. u16 portmap;
  364. u8 mac[6];
  365. };
  366. struct ar8xxx_priv;
  367. struct ar8xxx_mib_desc {
  368. unsigned int size;
  369. unsigned int offset;
  370. const char *name;
  371. u8 type;
  372. };
  373. struct ar8xxx_chip {
  374. unsigned long caps;
  375. bool config_at_probe;
  376. bool mii_lo_first;
  377. /* parameters to calculate REG_PORT_STATS_BASE */
  378. unsigned reg_port_stats_start;
  379. unsigned reg_port_stats_length;
  380. unsigned reg_arl_ctrl;
  381. int (*hw_init)(struct ar8xxx_priv *priv);
  382. void (*cleanup)(struct ar8xxx_priv *priv);
  383. const char *name;
  384. int vlans;
  385. int ports;
  386. const struct switch_dev_ops *swops;
  387. void (*init_globals)(struct ar8xxx_priv *priv);
  388. void (*init_port)(struct ar8xxx_priv *priv, int port);
  389. void (*setup_port)(struct ar8xxx_priv *priv, int port, u32 members);
  390. u32 (*read_port_status)(struct ar8xxx_priv *priv, int port);
  391. u32 (*read_port_eee_status)(struct ar8xxx_priv *priv, int port);
  392. int (*atu_flush)(struct ar8xxx_priv *priv);
  393. int (*atu_flush_port)(struct ar8xxx_priv *priv, int port);
  394. void (*vtu_flush)(struct ar8xxx_priv *priv);
  395. void (*vtu_load_vlan)(struct ar8xxx_priv *priv, u32 vid, u32 port_mask);
  396. void (*phy_fixup)(struct ar8xxx_priv *priv, int phy);
  397. void (*set_mirror_regs)(struct ar8xxx_priv *priv);
  398. void (*get_arl_entry)(struct ar8xxx_priv *priv, struct arl_entry *a,
  399. u32 *status, enum arl_op op);
  400. int (*sw_hw_apply)(struct switch_dev *dev);
  401. void (*phy_rgmii_set)(struct ar8xxx_priv *priv, struct phy_device *phydev);
  402. int (*phy_read)(struct ar8xxx_priv *priv, int addr, int regnum);
  403. int (*phy_write)(struct ar8xxx_priv *priv, int addr, int regnum, u16 val);
  404. const struct ar8xxx_mib_desc *mib_decs;
  405. unsigned num_mibs;
  406. unsigned mib_func;
  407. int mib_rxb_id;
  408. int mib_txb_id;
  409. };
  410. struct ar8xxx_priv {
  411. struct switch_dev dev;
  412. struct mii_bus *mii_bus;
  413. struct mii_bus *sw_mii_bus;
  414. struct phy_device *phy;
  415. struct device *pdev;
  416. int (*get_port_link)(unsigned port);
  417. const struct net_device_ops *ndo_old;
  418. struct net_device_ops ndo;
  419. struct mutex reg_mutex;
  420. u8 chip_ver;
  421. u8 chip_rev;
  422. const struct ar8xxx_chip *chip;
  423. void *chip_data;
  424. bool initialized;
  425. bool port4_phy;
  426. char buf[2048];
  427. struct arl_entry arl_table[AR8XXX_NUM_ARL_RECORDS];
  428. char arl_buf[AR8XXX_NUM_ARL_RECORDS * 32 + 256];
  429. bool link_up[AR8X16_MAX_PORTS];
  430. bool init;
  431. struct mutex mib_lock;
  432. struct delayed_work mib_work;
  433. u64 *mib_stats;
  434. u32 mib_poll_interval;
  435. u8 mib_type;
  436. struct list_head list;
  437. unsigned int use_count;
  438. /* all fields below are cleared on reset */
  439. struct_group(ar8xxx_priv_volatile,
  440. bool vlan;
  441. u16 vlan_id[AR8XXX_MAX_VLANS];
  442. u8 vlan_table[AR8XXX_MAX_VLANS];
  443. u8 vlan_tagged;
  444. u16 pvid[AR8X16_MAX_PORTS];
  445. int arl_age_time;
  446. /* mirroring */
  447. bool mirror_rx;
  448. bool mirror_tx;
  449. int source_port;
  450. int monitor_port;
  451. u8 port_vlan_prio[AR8X16_MAX_PORTS];
  452. );
  453. };
  454. u32
  455. ar8xxx_mii_read32(struct ar8xxx_priv *priv, int phy_id, int regnum);
  456. void
  457. ar8xxx_mii_write32(struct ar8xxx_priv *priv, int phy_id, int regnum, u32 val);
  458. u32
  459. ar8xxx_read(struct ar8xxx_priv *priv, int reg);
  460. void
  461. ar8xxx_write(struct ar8xxx_priv *priv, int reg, u32 val);
  462. u32
  463. ar8xxx_rmw(struct ar8xxx_priv *priv, int reg, u32 mask, u32 val);
  464. void
  465. ar8xxx_phy_dbg_read(struct ar8xxx_priv *priv, int phy_addr,
  466. u16 dbg_addr, u16 *dbg_data);
  467. void
  468. ar8xxx_phy_dbg_write(struct ar8xxx_priv *priv, int phy_addr,
  469. u16 dbg_addr, u16 dbg_data);
  470. void
  471. ar8xxx_phy_mmd_write(struct ar8xxx_priv *priv, int phy_addr, u16 addr, u16 reg, u16 data);
  472. u16
  473. ar8xxx_phy_mmd_read(struct ar8xxx_priv *priv, int phy_addr, u16 addr, u16 reg);
  474. void
  475. ar8xxx_phy_init(struct ar8xxx_priv *priv);
  476. int
  477. ar8xxx_sw_set_vlan(struct switch_dev *dev, const struct switch_attr *attr,
  478. struct switch_val *val);
  479. int
  480. ar8xxx_sw_get_vlan(struct switch_dev *dev, const struct switch_attr *attr,
  481. struct switch_val *val);
  482. int
  483. ar8xxx_sw_set_reset_mibs(struct switch_dev *dev,
  484. const struct switch_attr *attr,
  485. struct switch_val *val);
  486. int
  487. ar8xxx_sw_set_mib_poll_interval(struct switch_dev *dev,
  488. const struct switch_attr *attr,
  489. struct switch_val *val);
  490. int
  491. ar8xxx_sw_get_mib_poll_interval(struct switch_dev *dev,
  492. const struct switch_attr *attr,
  493. struct switch_val *val);
  494. int
  495. ar8xxx_sw_set_mib_type(struct switch_dev *dev,
  496. const struct switch_attr *attr,
  497. struct switch_val *val);
  498. int
  499. ar8xxx_sw_get_mib_type(struct switch_dev *dev,
  500. const struct switch_attr *attr,
  501. struct switch_val *val);
  502. int
  503. ar8xxx_sw_set_mirror_rx_enable(struct switch_dev *dev,
  504. const struct switch_attr *attr,
  505. struct switch_val *val);
  506. int
  507. ar8xxx_sw_get_mirror_rx_enable(struct switch_dev *dev,
  508. const struct switch_attr *attr,
  509. struct switch_val *val);
  510. int
  511. ar8xxx_sw_set_mirror_tx_enable(struct switch_dev *dev,
  512. const struct switch_attr *attr,
  513. struct switch_val *val);
  514. int
  515. ar8xxx_sw_get_mirror_tx_enable(struct switch_dev *dev,
  516. const struct switch_attr *attr,
  517. struct switch_val *val);
  518. int
  519. ar8xxx_sw_set_mirror_monitor_port(struct switch_dev *dev,
  520. const struct switch_attr *attr,
  521. struct switch_val *val);
  522. int
  523. ar8xxx_sw_get_mirror_monitor_port(struct switch_dev *dev,
  524. const struct switch_attr *attr,
  525. struct switch_val *val);
  526. int
  527. ar8xxx_sw_set_mirror_source_port(struct switch_dev *dev,
  528. const struct switch_attr *attr,
  529. struct switch_val *val);
  530. int
  531. ar8xxx_sw_get_mirror_source_port(struct switch_dev *dev,
  532. const struct switch_attr *attr,
  533. struct switch_val *val);
  534. int
  535. ar8xxx_sw_set_pvid(struct switch_dev *dev, int port, int vlan);
  536. int
  537. ar8xxx_sw_get_pvid(struct switch_dev *dev, int port, int *vlan);
  538. int
  539. ar8xxx_sw_hw_apply(struct switch_dev *dev);
  540. int
  541. ar8xxx_sw_reset_switch(struct switch_dev *dev);
  542. int
  543. ar8xxx_sw_get_port_link(struct switch_dev *dev, int port,
  544. struct switch_port_link *link);
  545. int
  546. ar8xxx_sw_set_port_reset_mib(struct switch_dev *dev,
  547. const struct switch_attr *attr,
  548. struct switch_val *val);
  549. int
  550. ar8xxx_sw_get_port_mib(struct switch_dev *dev,
  551. const struct switch_attr *attr,
  552. struct switch_val *val);
  553. int
  554. ar8xxx_sw_get_arl_age_time(struct switch_dev *dev,
  555. const struct switch_attr *attr,
  556. struct switch_val *val);
  557. int
  558. ar8xxx_sw_set_arl_age_time(struct switch_dev *dev,
  559. const struct switch_attr *attr,
  560. struct switch_val *val);
  561. int
  562. ar8xxx_sw_get_arl_table(struct switch_dev *dev,
  563. const struct switch_attr *attr,
  564. struct switch_val *val);
  565. int
  566. ar8xxx_sw_set_flush_arl_table(struct switch_dev *dev,
  567. const struct switch_attr *attr,
  568. struct switch_val *val);
  569. int
  570. ar8xxx_sw_set_flush_port_arl_table(struct switch_dev *dev,
  571. const struct switch_attr *attr,
  572. struct switch_val *val);
  573. int
  574. ar8xxx_sw_get_port_stats(struct switch_dev *dev, int port,
  575. struct switch_port_stats *stats);
  576. int
  577. ar8216_wait_bit(struct ar8xxx_priv *priv, int reg, u32 mask, u32 val);
  578. static inline struct ar8xxx_priv *
  579. swdev_to_ar8xxx(struct switch_dev *swdev)
  580. {
  581. return container_of(swdev, struct ar8xxx_priv, dev);
  582. }
  583. static inline bool ar8xxx_has_gige(struct ar8xxx_priv *priv)
  584. {
  585. return priv->chip->caps & AR8XXX_CAP_GIGE;
  586. }
  587. static inline bool ar8xxx_has_mib_counters(struct ar8xxx_priv *priv)
  588. {
  589. return priv->chip->caps & AR8XXX_CAP_MIB_COUNTERS;
  590. }
  591. static inline bool chip_is_ar8216(struct ar8xxx_priv *priv)
  592. {
  593. return priv->chip_ver == AR8XXX_VER_AR8216;
  594. }
  595. static inline bool chip_is_ar8236(struct ar8xxx_priv *priv)
  596. {
  597. return priv->chip_ver == AR8XXX_VER_AR8236;
  598. }
  599. static inline bool chip_is_ar8316(struct ar8xxx_priv *priv)
  600. {
  601. return priv->chip_ver == AR8XXX_VER_AR8316;
  602. }
  603. static inline bool chip_is_ar8327(struct ar8xxx_priv *priv)
  604. {
  605. return priv->chip_ver == AR8XXX_VER_AR8327;
  606. }
  607. static inline bool chip_is_ar8337(struct ar8xxx_priv *priv)
  608. {
  609. return priv->chip_ver == AR8XXX_VER_AR8337;
  610. }
  611. static inline void
  612. ar8xxx_reg_set(struct ar8xxx_priv *priv, int reg, u32 val)
  613. {
  614. ar8xxx_rmw(priv, reg, 0, val);
  615. }
  616. static inline void
  617. ar8xxx_reg_clear(struct ar8xxx_priv *priv, int reg, u32 val)
  618. {
  619. ar8xxx_rmw(priv, reg, val, 0);
  620. }
  621. static inline void
  622. split_addr(u32 regaddr, u16 *r1, u16 *r2, u16 *page)
  623. {
  624. regaddr >>= 1;
  625. *r1 = regaddr & 0x1e;
  626. regaddr >>= 5;
  627. *r2 = regaddr & 0x7;
  628. regaddr >>= 3;
  629. *page = regaddr & 0x1ff;
  630. }
  631. static inline void
  632. wait_for_page_switch(void)
  633. {
  634. udelay(5);
  635. }
  636. #endif