ar8216.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 AR8216_PORT_CPU 0
  20. #define AR8216_NUM_PORTS 6
  21. #define AR8216_NUM_VLANS 16
  22. #define AR8316_NUM_VLANS 4096
  23. /* Atheros specific MII registers */
  24. #define MII_ATH_DBG_ADDR 0x1d
  25. #define MII_ATH_DBG_DATA 0x1e
  26. #define AR8216_REG_CTRL 0x0000
  27. #define AR8216_CTRL_REVISION BITS(0, 8)
  28. #define AR8216_CTRL_REVISION_S 0
  29. #define AR8216_CTRL_VERSION BITS(8, 8)
  30. #define AR8216_CTRL_VERSION_S 8
  31. #define AR8216_CTRL_RESET BIT(31)
  32. #define AR8216_REG_FLOOD_MASK 0x002C
  33. #define AR8216_FM_UNI_DEST_PORTS BITS(0, 6)
  34. #define AR8216_FM_MULTI_DEST_PORTS BITS(16, 6)
  35. #define AR8216_REG_GLOBAL_CTRL 0x0030
  36. #define AR8216_GCTRL_MTU BITS(0, 11)
  37. #define AR8236_GCTRL_MTU BITS(0, 14)
  38. #define AR8316_GCTRL_MTU BITS(0, 14)
  39. #define AR8216_REG_VTU 0x0040
  40. #define AR8216_VTU_OP BITS(0, 3)
  41. #define AR8216_VTU_OP_NOOP 0x0
  42. #define AR8216_VTU_OP_FLUSH 0x1
  43. #define AR8216_VTU_OP_LOAD 0x2
  44. #define AR8216_VTU_OP_PURGE 0x3
  45. #define AR8216_VTU_OP_REMOVE_PORT 0x4
  46. #define AR8216_VTU_ACTIVE BIT(3)
  47. #define AR8216_VTU_FULL BIT(4)
  48. #define AR8216_VTU_PORT BITS(8, 4)
  49. #define AR8216_VTU_PORT_S 8
  50. #define AR8216_VTU_VID BITS(16, 12)
  51. #define AR8216_VTU_VID_S 16
  52. #define AR8216_VTU_PRIO BITS(28, 3)
  53. #define AR8216_VTU_PRIO_S 28
  54. #define AR8216_VTU_PRIO_EN BIT(31)
  55. #define AR8216_REG_VTU_DATA 0x0044
  56. #define AR8216_VTUDATA_MEMBER BITS(0, 10)
  57. #define AR8236_VTUDATA_MEMBER BITS(0, 7)
  58. #define AR8216_VTUDATA_VALID BIT(11)
  59. #define AR8216_REG_ATU 0x0050
  60. #define AR8216_ATU_OP BITS(0, 3)
  61. #define AR8216_ATU_OP_NOOP 0x0
  62. #define AR8216_ATU_OP_FLUSH 0x1
  63. #define AR8216_ATU_OP_LOAD 0x2
  64. #define AR8216_ATU_OP_PURGE 0x3
  65. #define AR8216_ATU_OP_FLUSH_LOCKED 0x4
  66. #define AR8216_ATU_OP_FLUSH_UNICAST 0x5
  67. #define AR8216_ATU_OP_GET_NEXT 0x6
  68. #define AR8216_ATU_ACTIVE BIT(3)
  69. #define AR8216_ATU_PORT_NUM BITS(8, 4)
  70. #define AR8216_ATU_FULL_VIO BIT(12)
  71. #define AR8216_ATU_ADDR4 BITS(16, 8)
  72. #define AR8216_ATU_ADDR5 BITS(24, 8)
  73. #define AR8216_REG_ATU_DATA 0x0054
  74. #define AR8216_ATU_ADDR3 BITS(0, 8)
  75. #define AR8216_ATU_ADDR2 BITS(8, 8)
  76. #define AR8216_ATU_ADDR1 BITS(16, 8)
  77. #define AR8216_ATU_ADDR0 BITS(24, 8)
  78. #define AR8216_REG_ATU_CTRL 0x005C
  79. #define AR8216_ATU_CTRL_AGE_EN BIT(17)
  80. #define AR8216_ATU_CTRL_AGE_TIME BITS(0, 16)
  81. #define AR8216_ATU_CTRL_AGE_TIME_S 0
  82. #define AR8216_PORT_OFFSET(_i) (0x0100 * (_i + 1))
  83. #define AR8216_REG_PORT_STATUS(_i) (AR8216_PORT_OFFSET(_i) + 0x0000)
  84. #define AR8216_PORT_STATUS_SPEED BITS(0,2)
  85. #define AR8216_PORT_STATUS_SPEED_S 0
  86. #define AR8216_PORT_STATUS_TXMAC BIT(2)
  87. #define AR8216_PORT_STATUS_RXMAC BIT(3)
  88. #define AR8216_PORT_STATUS_TXFLOW BIT(4)
  89. #define AR8216_PORT_STATUS_RXFLOW BIT(5)
  90. #define AR8216_PORT_STATUS_DUPLEX BIT(6)
  91. #define AR8216_PORT_STATUS_LINK_UP BIT(8)
  92. #define AR8216_PORT_STATUS_LINK_AUTO BIT(9)
  93. #define AR8216_PORT_STATUS_LINK_PAUSE BIT(10)
  94. #define AR8216_REG_PORT_CTRL(_i) (AR8216_PORT_OFFSET(_i) + 0x0004)
  95. /* port forwarding state */
  96. #define AR8216_PORT_CTRL_STATE BITS(0, 3)
  97. #define AR8216_PORT_CTRL_STATE_S 0
  98. #define AR8216_PORT_CTRL_LEARN_LOCK BIT(7)
  99. /* egress 802.1q mode */
  100. #define AR8216_PORT_CTRL_VLAN_MODE BITS(8, 2)
  101. #define AR8216_PORT_CTRL_VLAN_MODE_S 8
  102. #define AR8216_PORT_CTRL_IGMP_SNOOP BIT(10)
  103. #define AR8216_PORT_CTRL_HEADER BIT(11)
  104. #define AR8216_PORT_CTRL_MAC_LOOP BIT(12)
  105. #define AR8216_PORT_CTRL_SINGLE_VLAN BIT(13)
  106. #define AR8216_PORT_CTRL_LEARN BIT(14)
  107. #define AR8216_PORT_CTRL_MIRROR_TX BIT(16)
  108. #define AR8216_PORT_CTRL_MIRROR_RX BIT(17)
  109. #define AR8216_REG_PORT_VLAN(_i) (AR8216_PORT_OFFSET(_i) + 0x0008)
  110. #define AR8216_PORT_VLAN_DEFAULT_ID BITS(0, 12)
  111. #define AR8216_PORT_VLAN_DEFAULT_ID_S 0
  112. #define AR8216_PORT_VLAN_DEST_PORTS BITS(16, 9)
  113. #define AR8216_PORT_VLAN_DEST_PORTS_S 16
  114. /* bit0 added to the priority field of egress frames */
  115. #define AR8216_PORT_VLAN_TX_PRIO BIT(27)
  116. /* port default priority */
  117. #define AR8216_PORT_VLAN_PRIORITY BITS(28, 2)
  118. #define AR8216_PORT_VLAN_PRIORITY_S 28
  119. /* ingress 802.1q mode */
  120. #define AR8216_PORT_VLAN_MODE BITS(30, 2)
  121. #define AR8216_PORT_VLAN_MODE_S 30
  122. #define AR8216_REG_PORT_RATE(_i) (AR8216_PORT_OFFSET(_i) + 0x000c)
  123. #define AR8216_REG_PORT_PRIO(_i) (AR8216_PORT_OFFSET(_i) + 0x0010)
  124. #define AR8236_REG_PORT_VLAN(_i) (AR8216_PORT_OFFSET((_i)) + 0x0008)
  125. #define AR8236_PORT_VLAN_DEFAULT_ID BITS(16, 12)
  126. #define AR8236_PORT_VLAN_DEFAULT_ID_S 16
  127. #define AR8236_PORT_VLAN_PRIORITY BITS(29, 3)
  128. #define AR8236_PORT_VLAN_PRIORITY_S 28
  129. #define AR8236_REG_PORT_VLAN2(_i) (AR8216_PORT_OFFSET((_i)) + 0x000c)
  130. #define AR8236_PORT_VLAN2_MEMBER BITS(16, 7)
  131. #define AR8236_PORT_VLAN2_MEMBER_S 16
  132. #define AR8236_PORT_VLAN2_TX_PRIO BIT(23)
  133. #define AR8236_PORT_VLAN2_VLAN_MODE BITS(30, 2)
  134. #define AR8236_PORT_VLAN2_VLAN_MODE_S 30
  135. #define AR8327_NUM_PORTS 7
  136. #define AR8327_NUM_PHYS 5
  137. #define AR8327_PORTS_ALL 0x7f
  138. #define AR8327_REG_MASK 0x000
  139. #define AR8327_REG_PAD0_MODE 0x004
  140. #define AR8327_REG_PAD5_MODE 0x008
  141. #define AR8327_REG_PAD6_MODE 0x00c
  142. #define AR8327_PAD_MAC_MII_RXCLK_SEL BIT(0)
  143. #define AR8327_PAD_MAC_MII_TXCLK_SEL BIT(1)
  144. #define AR8327_PAD_MAC_MII_EN BIT(2)
  145. #define AR8327_PAD_MAC_GMII_RXCLK_SEL BIT(4)
  146. #define AR8327_PAD_MAC_GMII_TXCLK_SEL BIT(5)
  147. #define AR8327_PAD_MAC_GMII_EN BIT(6)
  148. #define AR8327_PAD_SGMII_EN BIT(7)
  149. #define AR8327_PAD_PHY_MII_RXCLK_SEL BIT(8)
  150. #define AR8327_PAD_PHY_MII_TXCLK_SEL BIT(9)
  151. #define AR8327_PAD_PHY_MII_EN BIT(10)
  152. #define AR8327_PAD_PHY_GMII_PIPE_RXCLK_SEL BIT(11)
  153. #define AR8327_PAD_PHY_GMII_RXCLK_SEL BIT(12)
  154. #define AR8327_PAD_PHY_GMII_TXCLK_SEL BIT(13)
  155. #define AR8327_PAD_PHY_GMII_EN BIT(14)
  156. #define AR8327_PAD_PHYX_GMII_EN BIT(16)
  157. #define AR8327_PAD_PHYX_RGMII_EN BIT(17)
  158. #define AR8327_PAD_PHYX_MII_EN BIT(18)
  159. #define AR8327_PAD_RGMII_RXCLK_DELAY_SEL BITS(20, 2)
  160. #define AR8327_PAD_RGMII_RXCLK_DELAY_SEL_S 20
  161. #define AR8327_PAD_RGMII_TXCLK_DELAY_SEL BITS(22, 2)
  162. #define AR8327_PAD_RGMII_TXCLK_DELAY_SEL_S 22
  163. #define AR8327_PAD_RGMII_RXCLK_DELAY_EN BIT(24)
  164. #define AR8327_PAD_RGMII_TXCLK_DELAY_EN BIT(25)
  165. #define AR8327_PAD_RGMII_EN BIT(26)
  166. #define AR8327_REG_POWER_ON_STRIP 0x010
  167. #define AR8327_REG_INT_STATUS0 0x020
  168. #define AR8327_INT0_VT_DONE BIT(20)
  169. #define AR8327_REG_INT_STATUS1 0x024
  170. #define AR8327_REG_INT_MASK0 0x028
  171. #define AR8327_REG_INT_MASK1 0x02c
  172. #define AR8327_REG_SERVICE_TAG 0x048
  173. #define AR8327_REG_LED_CTRL0 0x050
  174. #define AR8327_REG_LED_CTRL1 0x054
  175. #define AR8327_REG_LED_CTRL2 0x058
  176. #define AR8327_REG_LED_CTRL3 0x05c
  177. #define AR8327_REG_MAC_ADDR0 0x060
  178. #define AR8327_REG_MAC_ADDR1 0x064
  179. #define AR8327_REG_MAX_FRAME_SIZE 0x078
  180. #define AR8327_MAX_FRAME_SIZE_MTU BITS(0, 14)
  181. #define AR8327_REG_PORT_STATUS(_i) (0x07c + (_i) * 4)
  182. #define AR8327_REG_HEADER_CTRL 0x098
  183. #define AR8327_REG_PORT_HEADER(_i) (0x09c + (_i) * 4)
  184. #define AR8327_REG_PORT_VLAN0(_i) (0x420 + (_i) * 0x8)
  185. #define AR8327_PORT_VLAN0_DEF_SVID BITS(0, 12)
  186. #define AR8327_PORT_VLAN0_DEF_SVID_S 0
  187. #define AR8327_PORT_VLAN0_DEF_CVID BITS(16, 12)
  188. #define AR8327_PORT_VLAN0_DEF_CVID_S 16
  189. #define AR8327_REG_PORT_VLAN1(_i) (0x424 + (_i) * 0x8)
  190. #define AR8327_PORT_VLAN1_PORT_VLAN_PROP BIT(6)
  191. #define AR8327_PORT_VLAN1_OUT_MODE BITS(12, 2)
  192. #define AR8327_PORT_VLAN1_OUT_MODE_S 12
  193. #define AR8327_PORT_VLAN1_OUT_MODE_UNMOD 0
  194. #define AR8327_PORT_VLAN1_OUT_MODE_UNTAG 1
  195. #define AR8327_PORT_VLAN1_OUT_MODE_TAG 2
  196. #define AR8327_PORT_VLAN1_OUT_MODE_UNTOUCH 3
  197. #define AR8327_REG_ATU_DATA0 0x600
  198. #define AR8327_REG_ATU_DATA1 0x604
  199. #define AR8327_REG_ATU_DATA2 0x608
  200. #define AR8327_REG_ATU_FUNC 0x60c
  201. #define AR8327_ATU_FUNC_OP BITS(0, 4)
  202. #define AR8327_ATU_FUNC_OP_NOOP 0x0
  203. #define AR8327_ATU_FUNC_OP_FLUSH 0x1
  204. #define AR8327_ATU_FUNC_OP_LOAD 0x2
  205. #define AR8327_ATU_FUNC_OP_PURGE 0x3
  206. #define AR8327_ATU_FUNC_OP_FLUSH_LOCKED 0x4
  207. #define AR8327_ATU_FUNC_OP_FLUSH_UNICAST 0x5
  208. #define AR8327_ATU_FUNC_OP_GET_NEXT 0x6
  209. #define AR8327_ATU_FUNC_OP_SEARCH_MAC 0x7
  210. #define AR8327_ATU_FUNC_OP_CHANGE_TRUNK 0x8
  211. #define AR8327_ATU_FUNC_BUSY BIT(31)
  212. #define AR8327_REG_VTU_FUNC0 0x0610
  213. #define AR8327_VTU_FUNC0_EG_MODE BITS(4, 14)
  214. #define AR8327_VTU_FUNC0_EG_MODE_S(_i) (4 + (_i) * 2)
  215. #define AR8327_VTU_FUNC0_EG_MODE_KEEP 0
  216. #define AR8327_VTU_FUNC0_EG_MODE_UNTAG 1
  217. #define AR8327_VTU_FUNC0_EG_MODE_TAG 2
  218. #define AR8327_VTU_FUNC0_EG_MODE_NOT 3
  219. #define AR8327_VTU_FUNC0_IVL BIT(19)
  220. #define AR8327_VTU_FUNC0_VALID BIT(20)
  221. #define AR8327_REG_VTU_FUNC1 0x0614
  222. #define AR8327_VTU_FUNC1_OP BITS(0, 3)
  223. #define AR8327_VTU_FUNC1_OP_NOOP 0
  224. #define AR8327_VTU_FUNC1_OP_FLUSH 1
  225. #define AR8327_VTU_FUNC1_OP_LOAD 2
  226. #define AR8327_VTU_FUNC1_OP_PURGE 3
  227. #define AR8327_VTU_FUNC1_OP_REMOVE_PORT 4
  228. #define AR8327_VTU_FUNC1_OP_GET_NEXT 5
  229. #define AR8327_VTU_FUNC1_OP_GET_ONE 6
  230. #define AR8327_VTU_FUNC1_FULL BIT(4)
  231. #define AR8327_VTU_FUNC1_PORT BIT(8, 4)
  232. #define AR8327_VTU_FUNC1_PORT_S 8
  233. #define AR8327_VTU_FUNC1_VID BIT(16, 12)
  234. #define AR8327_VTU_FUNC1_VID_S 16
  235. #define AR8327_VTU_FUNC1_BUSY BIT(31)
  236. #define AR8327_REG_FWD_CTRL0 0x620
  237. #define AR8327_FWD_CTRL0_CPU_PORT_EN BIT(10)
  238. #define AR8327_FWD_CTRL0_MIRROR_PORT BITS(4, 4)
  239. #define AR8327_FWD_CTRL0_MIRROR_PORT_S 4
  240. #define AR8327_REG_FWD_CTRL1 0x624
  241. #define AR8327_FWD_CTRL1_UC_FLOOD BITS(0, 7)
  242. #define AR8327_FWD_CTRL1_UC_FLOOD_S 0
  243. #define AR8327_FWD_CTRL1_MC_FLOOD BITS(8, 7)
  244. #define AR8327_FWD_CTRL1_MC_FLOOD_S 8
  245. #define AR8327_FWD_CTRL1_BC_FLOOD BITS(16, 7)
  246. #define AR8327_FWD_CTRL1_BC_FLOOD_S 16
  247. #define AR8327_FWD_CTRL1_IGMP BITS(24, 7)
  248. #define AR8327_FWD_CTRL1_IGMP_S 24
  249. #define AR8327_REG_PORT_LOOKUP(_i) (0x660 + (_i) * 0xc)
  250. #define AR8327_PORT_LOOKUP_MEMBER BITS(0, 7)
  251. #define AR8327_PORT_LOOKUP_IN_MODE BITS(8, 2)
  252. #define AR8327_PORT_LOOKUP_IN_MODE_S 8
  253. #define AR8327_PORT_LOOKUP_STATE BITS(16, 3)
  254. #define AR8327_PORT_LOOKUP_STATE_S 16
  255. #define AR8327_PORT_LOOKUP_LEARN BIT(20)
  256. #define AR8327_REG_PORT_PRIO(_i) (0x664 + (_i) * 0xc)
  257. /* port speed */
  258. enum {
  259. AR8216_PORT_SPEED_10M = 0,
  260. AR8216_PORT_SPEED_100M = 1,
  261. AR8216_PORT_SPEED_1000M = 2,
  262. AR8216_PORT_SPEED_ERR = 3,
  263. };
  264. /* ingress 802.1q mode */
  265. enum {
  266. AR8216_IN_PORT_ONLY = 0,
  267. AR8216_IN_PORT_FALLBACK = 1,
  268. AR8216_IN_VLAN_ONLY = 2,
  269. AR8216_IN_SECURE = 3
  270. };
  271. /* egress 802.1q mode */
  272. enum {
  273. AR8216_OUT_KEEP = 0,
  274. AR8216_OUT_STRIP_VLAN = 1,
  275. AR8216_OUT_ADD_VLAN = 2
  276. };
  277. /* port forwarding state */
  278. enum {
  279. AR8216_PORT_STATE_DISABLED = 0,
  280. AR8216_PORT_STATE_BLOCK = 1,
  281. AR8216_PORT_STATE_LISTEN = 2,
  282. AR8216_PORT_STATE_LEARN = 3,
  283. AR8216_PORT_STATE_FORWARD = 4
  284. };
  285. /* device */
  286. enum {
  287. UNKNOWN = 0,
  288. AR8216 = 8216,
  289. AR8236 = 8236,
  290. AR8316 = 8316,
  291. AR8327 = 8327,
  292. };
  293. #endif