rtl838x.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef _RTL838X_H
  3. #define _RTL838X_H
  4. #include <net/dsa.h>
  5. /*
  6. * Register definition
  7. */
  8. #define RTL838X_MAC_PORT_CTRL(port) (0xd560 + (((port) << 7)))
  9. #define RTL839X_MAC_PORT_CTRL(port) (0x8004 + (((port) << 7)))
  10. #define RTL930X_MAC_PORT_CTRL(port) (0x3260 + (((port) << 6)))
  11. #define RTL931X_MAC_PORT_CTRL (0x6004)
  12. #define RTL930X_MAC_L2_PORT_CTRL(port) (0x3268 + (((port) << 6)))
  13. #define RTL931X_MAC_L2_PORT_CTRL (0x6000)
  14. #define RTL838X_RST_GLB_CTRL_0 (0x003c)
  15. #define RTL838X_MAC_FORCE_MODE_CTRL (0xa104)
  16. #define RTL839X_MAC_FORCE_MODE_CTRL (0x02bc)
  17. #define RTL930X_MAC_FORCE_MODE_CTRL (0xCA1C)
  18. #define RTL931X_MAC_FORCE_MODE_CTRL (0x0DCC)
  19. #define RTL838X_DMY_REG31 (0x3b28)
  20. #define RTL838X_SDS_MODE_SEL (0x0028)
  21. #define RTL838X_SDS_CFG_REG (0x0034)
  22. #define RTL838X_INT_MODE_CTRL (0x005c)
  23. #define RTL838X_CHIP_INFO (0x00d8)
  24. #define RTL839X_CHIP_INFO (0x0ff4)
  25. #define RTL838X_PORT_ISO_CTRL(port) (0x4100 + ((port) << 2))
  26. #define RTL839X_PORT_ISO_CTRL(port) (0x1400 + ((port) << 3))
  27. /* Packet statistics */
  28. #define RTL838X_STAT_PORT_STD_MIB (0x1200)
  29. #define RTL839X_STAT_PORT_STD_MIB (0xC000)
  30. #define RTL930X_STAT_PORT_MIB_CNTR (0x0664)
  31. #define RTL838X_STAT_RST (0x3100)
  32. #define RTL839X_STAT_RST (0xF504)
  33. #define RTL930X_STAT_RST (0x3240)
  34. #define RTL931X_STAT_RST (0x7ef4)
  35. #define RTL838X_STAT_PORT_RST (0x3104)
  36. #define RTL839X_STAT_PORT_RST (0xF508)
  37. #define RTL930X_STAT_PORT_RST (0x3244)
  38. #define RTL931X_STAT_PORT_RST (0x7ef8)
  39. #define RTL838X_STAT_CTRL (0x3108)
  40. #define RTL839X_STAT_CTRL (0x04cc)
  41. #define RTL930X_STAT_CTRL (0x3248)
  42. #define RTL931X_STAT_CTRL (0x5720)
  43. /* Registers of the internal Serdes of the 8390 */
  44. #define RTL8390_SDS0_1_XSG0 (0xA000)
  45. #define RTL8390_SDS0_1_XSG1 (0xA100)
  46. #define RTL839X_SDS12_13_XSG0 (0xB800)
  47. #define RTL839X_SDS12_13_XSG1 (0xB900)
  48. #define RTL839X_SDS12_13_PWR0 (0xb880)
  49. #define RTL839X_SDS12_13_PWR1 (0xb980)
  50. /* Registers of the internal Serdes of the 8380 */
  51. #define RTL838X_SDS4_FIB_REG0 (0xF800)
  52. #define RTL838X_SDS4_REG28 (0xef80)
  53. #define RTL838X_SDS4_DUMMY0 (0xef8c)
  54. #define RTL838X_SDS5_EXT_REG6 (0xf18c)
  55. /* VLAN registers */
  56. #define RTL838X_VLAN_CTRL (0x3A74)
  57. #define RTL838X_VLAN_PROFILE(idx) (0x3A88 + ((idx) << 2))
  58. #define RTL838X_VLAN_PORT_EGR_FLTR (0x3A84)
  59. #define RTL838X_VLAN_PORT_PB_VLAN (0x3C00)
  60. #define RTL838X_VLAN_PORT_IGR_FLTR (0x3A7C)
  61. #define RTL839X_VLAN_PROFILE(idx) (0x25C0 + (((idx) << 3)))
  62. #define RTL839X_VLAN_CTRL (0x26D4)
  63. #define RTL839X_VLAN_PORT_PB_VLAN (0x26D8)
  64. #define RTL839X_VLAN_PORT_IGR_FLTR (0x27B4)
  65. #define RTL839X_VLAN_PORT_EGR_FLTR (0x27C4)
  66. #define RTL930X_VLAN_PROFILE_SET(idx) (0x9c60 + (((idx) * 20)))
  67. #define RTL930X_VLAN_CTRL (0x82D4)
  68. #define RTL930X_VLAN_PORT_PB_VLAN (0x82D8)
  69. #define RTL930X_VLAN_PORT_IGR_FLTR (0x83C0)
  70. #define RTL930X_VLAN_PORT_EGR_FLTR (0x83C8)
  71. #define RTL931X_VLAN_PROFILE_SET(idx) (0x9800 + (((idx) * 28)))
  72. #define RTL931X_VLAN_CTRL (0x94E4)
  73. #define RTL931X_VLAN_PORT_IGR_CTRL (0x94E8)
  74. #define RTL931X_VLAN_PORT_IGR_FLTR (0x96B4)
  75. #define RTL931X_VLAN_PORT_EGR_FLTR (0x96C4)
  76. /* Table access registers */
  77. #define RTL838X_TBL_ACCESS_CTRL_0 (0x6914)
  78. #define RTL838X_TBL_ACCESS_DATA_0(idx) (0x6918 + ((idx) << 2))
  79. #define RTL838X_TBL_ACCESS_CTRL_1 (0xA4C8)
  80. #define RTL838X_TBL_ACCESS_DATA_1(idx) (0xA4CC + ((idx) << 2))
  81. #define RTL839X_TBL_ACCESS_CTRL_0 (0x1190)
  82. #define RTL839X_TBL_ACCESS_DATA_0(idx) (0x1194 + ((idx) << 2))
  83. #define RTL839X_TBL_ACCESS_CTRL_1 (0x6b80)
  84. #define RTL839X_TBL_ACCESS_DATA_1(idx) (0x6b84 + ((idx) << 2))
  85. #define RTL839X_TBL_ACCESS_CTRL_2 (0x611C)
  86. #define RTL839X_TBL_ACCESS_DATA_2(i) (0x6120 + (((i) << 2)))
  87. #define RTL930X_TBL_ACCESS_CTRL_0 (0xB340)
  88. #define RTL930X_TBL_ACCESS_DATA_0(idx) (0xB344 + ((idx) << 2))
  89. #define RTL930X_TBL_ACCESS_CTRL_1 (0xB3A0)
  90. #define RTL930X_TBL_ACCESS_DATA_1(idx) (0xB3A4 + ((idx) << 2))
  91. #define RTL930X_TBL_ACCESS_CTRL_2 (0xCE04)
  92. #define RTL930X_TBL_ACCESS_DATA_2(i) (0xCE08 + (((i) << 2)))
  93. #define RTL931X_TBL_ACCESS_CTRL_0 (0x8500)
  94. #define RTL931X_TBL_ACCESS_DATA_0(idx) (0x8508 + ((idx) << 2))
  95. #define RTL931X_TBL_ACCESS_CTRL_1 (0x40C0)
  96. #define RTL931X_TBL_ACCESS_DATA_1(idx) (0x40C4 + ((idx) << 2))
  97. #define RTL931X_TBL_ACCESS_CTRL_2 (0x8528)
  98. #define RTL931X_TBL_ACCESS_DATA_2(i) (0x852C + (((i) << 2)))
  99. #define RTL931X_TBL_ACCESS_CTRL_3 (0x0200)
  100. #define RTL931X_TBL_ACCESS_DATA_3(i) (0x0204 + (((i) << 2)))
  101. #define RTL931X_TBL_ACCESS_CTRL_4 (0x20DC)
  102. #define RTL931X_TBL_ACCESS_DATA_4(i) (0x20E0 + (((i) << 2)))
  103. #define RTL931X_TBL_ACCESS_CTRL_5 (0x7E1C)
  104. #define RTL931X_TBL_ACCESS_DATA_5(i) (0x7E20 + (((i) << 2)))
  105. /* MAC handling */
  106. #define RTL838X_MAC_LINK_STS (0xa188)
  107. #define RTL839X_MAC_LINK_STS (0x0390)
  108. #define RTL930X_MAC_LINK_STS (0xCB10)
  109. #define RTL931X_MAC_LINK_STS (0x0EC0)
  110. #define RTL838X_MAC_LINK_SPD_STS(p) (0xa190 + (((p >> 4) << 2)))
  111. #define RTL839X_MAC_LINK_SPD_STS(p) (0x03a0 + (((p >> 4) << 2)))
  112. #define RTL930X_MAC_LINK_SPD_STS(p) (0xCB18 + (((p >> 3) << 2)))
  113. #define RTL931X_MAC_LINK_SPD_STS (0x0ED0)
  114. #define RTL838X_MAC_LINK_DUP_STS (0xa19c)
  115. #define RTL839X_MAC_LINK_DUP_STS (0x03b0)
  116. #define RTL930X_MAC_LINK_DUP_STS (0xCB28)
  117. #define RTL931X_MAC_LINK_DUP_STS (0x0EF0)
  118. #define RTL838X_MAC_TX_PAUSE_STS (0xa1a0)
  119. #define RTL839X_MAC_TX_PAUSE_STS (0x03b8)
  120. #define RTL930X_MAC_TX_PAUSE_STS (0xCB2C)
  121. #define RTL931X_MAC_TX_PAUSE_STS (0x0EF8)
  122. #define RTL838X_MAC_RX_PAUSE_STS (0xa1a4)
  123. #define RTL839X_MAC_RX_PAUSE_STS (0x03c0)
  124. #define RTL930X_MAC_RX_PAUSE_STS (0xCB30)
  125. #define RTL931X_MAC_RX_PAUSE_STS (0x0F00)
  126. #define RTL930X_MAC_LINK_MEDIA_STS (0xCB14)
  127. #define RTL931X_MAC_LINK_MEDIA_STS (0x0EC8)
  128. /* MAC link state bits */
  129. #define RTL838X_FORCE_EN (1 << 0)
  130. #define RTL838X_FORCE_LINK_EN (1 << 1)
  131. #define RTL838X_NWAY_EN (1 << 2)
  132. #define RTL838X_DUPLEX_MODE (1 << 3)
  133. #define RTL838X_TX_PAUSE_EN (1 << 6)
  134. #define RTL838X_RX_PAUSE_EN (1 << 7)
  135. #define RTL838X_MAC_FORCE_FC_EN (1 << 8)
  136. #define RTL839X_FORCE_EN (1 << 0)
  137. #define RTL839X_FORCE_LINK_EN (1 << 1)
  138. #define RTL839X_DUPLEX_MODE (1 << 2)
  139. #define RTL839X_TX_PAUSE_EN (1 << 5)
  140. #define RTL839X_RX_PAUSE_EN (1 << 6)
  141. #define RTL839X_MAC_FORCE_FC_EN (1 << 7)
  142. #define RTL930X_FORCE_EN (1 << 0)
  143. #define RTL930X_FORCE_LINK_EN (1 << 1)
  144. #define RTL930X_DUPLEX_MODE (1 << 2)
  145. #define RTL930X_TX_PAUSE_EN (1 << 7)
  146. #define RTL930X_RX_PAUSE_EN (1 << 8)
  147. #define RTL930X_MAC_FORCE_FC_EN (1 << 9)
  148. #define RTL931X_FORCE_EN (1 << 9)
  149. #define RTL931X_FORCE_LINK_EN (1 << 0)
  150. #define RTL931X_DUPLEX_MODE (1 << 2)
  151. #define RTL931X_MAC_FORCE_FC_EN (1 << 4)
  152. #define RTL931X_TX_PAUSE_EN (1 << 16)
  153. #define RTL931X_RX_PAUSE_EN (1 << 17)
  154. /* EEE */
  155. #define RTL838X_MAC_EEE_ABLTY (0xa1a8)
  156. #define RTL838X_EEE_PORT_TX_EN (0x014c)
  157. #define RTL838X_EEE_PORT_RX_EN (0x0150)
  158. #define RTL838X_EEE_CLK_STOP_CTRL (0x0148)
  159. #define RTL838X_EEE_TX_TIMER_GIGA_CTRL (0xaa04)
  160. #define RTL838X_EEE_TX_TIMER_GELITE_CTRL (0xaa08)
  161. #define RTL839X_EEE_TX_TIMER_GELITE_CTRL (0x042C)
  162. #define RTL839X_EEE_TX_TIMER_GIGA_CTRL (0x0430)
  163. #define RTL839X_EEE_TX_TIMER_10G_CTRL (0x0434)
  164. #define RTL839X_EEE_CTRL(p) (0x8008 + ((p) << 7))
  165. #define RTL839X_MAC_EEE_ABLTY (0x03C8)
  166. #define RTL930X_MAC_EEE_ABLTY (0xCB34)
  167. #define RTL930X_EEE_CTRL(p) (0x3274 + ((p) << 6))
  168. #define RTL930X_EEEP_PORT_CTRL(p) (0x3278 + ((p) << 6))
  169. /* L2 functionality */
  170. #define RTL838X_L2_CTRL_0 (0x3200)
  171. #define RTL839X_L2_CTRL_0 (0x3800)
  172. #define RTL930X_L2_CTRL (0x8FD8)
  173. #define RTL931X_L2_CTRL (0xC800)
  174. #define RTL838X_L2_CTRL_1 (0x3204)
  175. #define RTL839X_L2_CTRL_1 (0x3804)
  176. #define RTL930X_L2_AGE_CTRL (0x8FDC)
  177. #define RTL931X_L2_AGE_CTRL (0xC804)
  178. #define RTL838X_L2_PORT_AGING_OUT (0x3358)
  179. #define RTL839X_L2_PORT_AGING_OUT (0x3b74)
  180. #define RTL930X_L2_PORT_AGE_CTRL (0x8FE0)
  181. #define RTL931X_L2_PORT_AGE_CTRL (0xc808)
  182. #define RTL838X_TBL_ACCESS_L2_CTRL (0x6900)
  183. #define RTL839X_TBL_ACCESS_L2_CTRL (0x1180)
  184. #define RTL930X_TBL_ACCESS_L2_CTRL (0xB320)
  185. #define RTL930X_TBL_ACCESS_L2_METHOD_CTRL (0xB324)
  186. #define RTL838X_TBL_ACCESS_L2_DATA(idx) (0x6908 + ((idx) << 2))
  187. #define RTL839X_TBL_ACCESS_L2_DATA(idx) (0x1184 + ((idx) << 2))
  188. #define RTL930X_TBL_ACCESS_L2_DATA(idx) (0xab08 + ((idx) << 2))
  189. #define RTL838X_L2_TBL_FLUSH_CTRL (0x3370)
  190. #define RTL839X_L2_TBL_FLUSH_CTRL (0x3ba0)
  191. #define RTL930X_L2_TBL_FLUSH_CTRL (0x9404)
  192. #define RTL931X_L2_TBL_FLUSH_CTRL (0xCD9C)
  193. #define RTL838X_L2_LRN_CONSTRT (0x329C)
  194. #define RTL839X_L2_LRN_CONSTRT (0x3910)
  195. #define RTL930X_L2_LRN_CONSTRT_CTRL (0x909c)
  196. #define RTL931X_L2_LRN_CONSTRT_CTRL (0xC964)
  197. #define RTL838X_L2_FLD_PMSK (0x3288)
  198. #define RTL839X_L2_FLD_PMSK (0x38EC)
  199. #define RTL930X_L2_BC_FLD_PMSK (0x9068)
  200. #define RTL931X_L2_BC_FLD_PMSK (0xC8FC)
  201. #define RTL930X_L2_UNKN_UC_FLD_PMSK (0x9064)
  202. #define RTL931X_L2_UNKN_UC_FLD_PMSK (0xC8F4)
  203. #define RTL838X_L2_LRN_CONSTRT_EN (0x3368)
  204. #define RTL838X_L2_PORT_LRN_CONSTRT (0x32A0)
  205. #define RTL839X_L2_PORT_LRN_CONSTRT (0x3914)
  206. #define RTL838X_L2_PORT_NEW_SALRN(p) (0x328c + (((p >> 4) << 2)))
  207. #define RTL839X_L2_PORT_NEW_SALRN(p) (0x38F0 + (((p >> 4) << 2)))
  208. #define RTL930X_L2_PORT_SALRN(p) (0x8FEC + (((p >> 4) << 2)))
  209. #define RTL931X_L2_PORT_NEW_SALRN(p) (0xC820 + (((p >> 4) << 2)))
  210. #define SALRN_PORT_SHIFT(p) ((p % 16) * 2)
  211. #define SALRN_MODE_MASK 0x3
  212. #define SALRN_MODE_HARDWARE 0
  213. #define SALRN_MODE_DISABLED 2
  214. #define RTL838X_L2_PORT_NEW_SA_FWD(p) (0x3294 + (((p >> 4) << 2)))
  215. #define RTL839X_L2_PORT_NEW_SA_FWD(p) (0x3900 + (((p >> 4) << 2)))
  216. #define RTL930X_L2_PORT_NEW_SA_FWD(p) (0x8FF4 + (((p / 10) << 2)))
  217. #define RTL931X_L2_PORT_NEW_SA_FWD(p) (0xC830 + (((p / 10) << 2)))
  218. #define RTL930X_ST_CTRL (0x8798)
  219. #define RTL930X_L2_PORT_SABLK_CTRL (0x905c)
  220. #define RTL930X_L2_PORT_DABLK_CTRL (0x9060)
  221. #define RTL838X_L2_PORT_LM_ACT(p) (0x3208 + ((p) << 2))
  222. #define RTL838X_VLAN_PORT_FWD (0x3A78)
  223. #define RTL839X_VLAN_PORT_FWD (0x27AC)
  224. #define RTL930X_VLAN_PORT_FWD (0x834C)
  225. #define RTL931X_VLAN_PORT_FWD (0x95CC)
  226. #define RTL838X_VLAN_FID_CTRL (0x3aa8)
  227. /* Port Mirroring */
  228. #define RTL838X_MIR_CTRL (0x5D00)
  229. #define RTL838X_MIR_DPM_CTRL (0x5D20)
  230. #define RTL838X_MIR_SPM_CTRL (0x5D10)
  231. #define RTL839X_MIR_CTRL (0x2500)
  232. #define RTL839X_MIR_DPM_CTRL (0x2530)
  233. #define RTL839X_MIR_SPM_CTRL (0x2510)
  234. #define RTL930X_MIR_CTRL (0xA2A0)
  235. #define RTL930X_MIR_DPM_CTRL (0xA2C0)
  236. #define RTL930X_MIR_SPM_CTRL (0xA2B0)
  237. #define RTL931X_MIR_CTRL (0xAF00)
  238. #define RTL931X_MIR_DPM_CTRL (0xAF30)
  239. #define RTL931X_MIR_SPM_CTRL (0xAF10)
  240. /* Storm/rate control and scheduling */
  241. #define RTL838X_STORM_CTRL (0x4700)
  242. #define RTL839X_STORM_CTRL (0x1800)
  243. #define RTL838X_STORM_CTRL_LB_CTRL(p) (0x4884 + (((p) << 2)))
  244. #define RTL838X_STORM_CTRL_BURST_PPS_0 (0x4874)
  245. #define RTL838X_STORM_CTRL_BURST_PPS_1 (0x4878)
  246. #define RTL838X_STORM_CTRL_BURST_0 (0x487c)
  247. #define RTL838X_STORM_CTRL_BURST_1 (0x4880)
  248. #define RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_0 (0x1804)
  249. #define RTL839X_STORM_CTRL_LB_TICK_TKN_CTRL_1 (0x1808)
  250. #define RTL838X_SCHED_CTRL (0xB980)
  251. #define RTL839X_SCHED_CTRL (0x60F4)
  252. #define RTL838X_SCHED_LB_TICK_TKN_CTRL_0 (0xAD58)
  253. #define RTL838X_SCHED_LB_TICK_TKN_CTRL_1 (0xAD5C)
  254. #define RTL839X_SCHED_LB_TICK_TKN_CTRL_0 (0x1804)
  255. #define RTL839X_SCHED_LB_TICK_TKN_CTRL_1 (0x1808)
  256. #define RTL839X_STORM_CTRL_SPCL_LB_TICK_TKN_CTRL (0x2000)
  257. #define RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_0 (0x1604)
  258. #define RTL839X_IGR_BWCTRL_LB_TICK_TKN_CTRL_1 (0x1608)
  259. #define RTL839X_SCHED_LB_TICK_TKN_CTRL (0x60F8)
  260. #define RTL839X_SCHED_LB_TICK_TKN_PPS_CTRL (0x6200)
  261. #define RTL838X_SCHED_LB_THR (0xB984)
  262. #define RTL839X_SCHED_LB_THR (0x60FC)
  263. #define RTL838X_SCHED_P_EGR_RATE_CTRL(p) (0xC008 + (((p) << 7)))
  264. #define RTL838X_SCHED_Q_EGR_RATE_CTRL(p, q) (0xC00C + (p << 7) + (((q) << 2)))
  265. #define RTL838X_STORM_CTRL_PORT_BC_EXCEED (0x470C)
  266. #define RTL838X_STORM_CTRL_PORT_MC_EXCEED (0x4710)
  267. #define RTL838X_STORM_CTRL_PORT_UC_EXCEED (0x4714)
  268. #define RTL839X_STORM_CTRL_PORT_BC_EXCEED(p) (0x180c + (((p >> 5) << 2)))
  269. #define RTL839X_STORM_CTRL_PORT_MC_EXCEED(p) (0x1814 + (((p >> 5) << 2)))
  270. #define RTL839X_STORM_CTRL_PORT_UC_EXCEED(p) (0x181c + (((p >> 5) << 2)))
  271. #define RTL838X_STORM_CTRL_PORT_UC(p) (0x4718 + (((p) << 2)))
  272. #define RTL838X_STORM_CTRL_PORT_MC(p) (0x478c + (((p) << 2)))
  273. #define RTL838X_STORM_CTRL_PORT_BC(p) (0x4800 + (((p) << 2)))
  274. #define RTL839X_STORM_CTRL_PORT_UC_0(p) (0x185C + (((p) << 3)))
  275. #define RTL839X_STORM_CTRL_PORT_UC_1(p) (0x1860 + (((p) << 3)))
  276. #define RTL839X_STORM_CTRL_PORT_MC_0(p) (0x19FC + (((p) << 3)))
  277. #define RTL839X_STORM_CTRL_PORT_MC_1(p) (0x1a00 + (((p) << 3)))
  278. #define RTL839X_STORM_CTRL_PORT_BC_0(p) (0x1B9C + (((p) << 3)))
  279. #define RTL839X_STORM_CTRL_PORT_BC_1(p) (0x1BA0 + (((p) << 3)))
  280. #define RTL839X_TBL_ACCESS_CTRL_2 (0x611C)
  281. #define RTL839X_TBL_ACCESS_DATA_2(i) (0x6120 + (((i) << 2)))
  282. #define RTL839X_IGR_BWCTRL_PORT_CTRL_10G_0(p) (0x1618 + (((p) << 3)))
  283. #define RTL839X_IGR_BWCTRL_PORT_CTRL_10G_1(p) (0x161C + (((p) << 3)))
  284. #define RTL839X_IGR_BWCTRL_PORT_CTRL_0(p) (0x1640 + (((p) << 3)))
  285. #define RTL839X_IGR_BWCTRL_PORT_CTRL_1(p) (0x1644 + (((p) << 3)))
  286. #define RTL839X_IGR_BWCTRL_CTRL_LB_THR (0x1614)
  287. /* Link aggregation (Trunking) */
  288. #define TRUNK_DISTRIBUTION_ALGO_SPA_BIT 0x01
  289. #define TRUNK_DISTRIBUTION_ALGO_SMAC_BIT 0x02
  290. #define TRUNK_DISTRIBUTION_ALGO_DMAC_BIT 0x04
  291. #define TRUNK_DISTRIBUTION_ALGO_SIP_BIT 0x08
  292. #define TRUNK_DISTRIBUTION_ALGO_DIP_BIT 0x10
  293. #define TRUNK_DISTRIBUTION_ALGO_SRC_L4PORT_BIT 0x20
  294. #define TRUNK_DISTRIBUTION_ALGO_DST_L4PORT_BIT 0x40
  295. #define TRUNK_DISTRIBUTION_ALGO_MASKALL 0x7F
  296. #define TRUNK_DISTRIBUTION_ALGO_L2_SPA_BIT 0x01
  297. #define TRUNK_DISTRIBUTION_ALGO_L2_SMAC_BIT 0x02
  298. #define TRUNK_DISTRIBUTION_ALGO_L2_DMAC_BIT 0x04
  299. #define TRUNK_DISTRIBUTION_ALGO_L2_VLAN_BIT 0x08
  300. #define TRUNK_DISTRIBUTION_ALGO_L2_MASKALL 0xF
  301. #define TRUNK_DISTRIBUTION_ALGO_L3_SPA_BIT 0x01
  302. #define TRUNK_DISTRIBUTION_ALGO_L3_SMAC_BIT 0x02
  303. #define TRUNK_DISTRIBUTION_ALGO_L3_DMAC_BIT 0x04
  304. #define TRUNK_DISTRIBUTION_ALGO_L3_VLAN_BIT 0x08
  305. #define TRUNK_DISTRIBUTION_ALGO_L3_SIP_BIT 0x10
  306. #define TRUNK_DISTRIBUTION_ALGO_L3_DIP_BIT 0x20
  307. #define TRUNK_DISTRIBUTION_ALGO_L3_SRC_L4PORT_BIT 0x40
  308. #define TRUNK_DISTRIBUTION_ALGO_L3_DST_L4PORT_BIT 0x80
  309. #define TRUNK_DISTRIBUTION_ALGO_L3_PROTO_BIT 0x100
  310. #define TRUNK_DISTRIBUTION_ALGO_L3_FLOW_LABEL_BIT 0x200
  311. #define TRUNK_DISTRIBUTION_ALGO_L3_MASKALL 0x3FF
  312. #define RTL838X_TRK_MBR_CTR (0x3E00)
  313. #define RTL838X_TRK_HASH_IDX_CTRL (0x3E20)
  314. #define RTL838X_TRK_HASH_CTRL (0x3E24)
  315. #define RTL839X_TRK_MBR_CTR (0x2200)
  316. #define RTL839X_TRK_HASH_IDX_CTRL (0x2280)
  317. #define RTL839X_TRK_HASH_CTRL (0x2284)
  318. #define RTL930X_TRK_MBR_CTRL (0xA41C)
  319. #define RTL930X_TRK_HASH_CTRL (0x9F80)
  320. #define RTL931X_TRK_MBR_CTRL (0xB8D0)
  321. #define RTL931X_TRK_HASH_CTRL (0xBA70)
  322. /* Attack prevention */
  323. #define RTL838X_ATK_PRVNT_PORT_EN (0x5B00)
  324. #define RTL838X_ATK_PRVNT_CTRL (0x5B04)
  325. #define RTL838X_ATK_PRVNT_ACT (0x5B08)
  326. #define RTL838X_ATK_PRVNT_STS (0x5B1C)
  327. /* 802.1X */
  328. #define RTL838X_RMA_BPDU_FLD_PMSK (0x4348)
  329. #define RTL930X_RMA_BPDU_FLD_PMSK (0x9F18)
  330. #define RTL931X_RMA_BPDU_FLD_PMSK (0x8950)
  331. #define RTL839X_RMA_BPDU_FLD_PMSK (0x125C)
  332. #define RTL838X_SPCL_TRAP_CTRL (0x6980)
  333. #define RTL838X_SPCL_TRAP_EAPOL_CTRL (0x6988)
  334. #define RTL838X_SPCL_TRAP_ARP_CTRL (0x698C)
  335. #define RTL838X_SPCL_TRAP_IGMP_CTRL (0x6984)
  336. #define RTL838X_SPCL_TRAP_IPV6_CTRL (0x6994)
  337. #define RTL838X_SPCL_TRAP_SWITCH_MAC_CTRL (0x6998)
  338. #define RTL839X_SPCL_TRAP_CTRL (0x1054)
  339. #define RTL839X_SPCL_TRAP_EAPOL_CTRL (0x105C)
  340. #define RTL839X_SPCL_TRAP_ARP_CTRL (0x1060)
  341. #define RTL839X_SPCL_TRAP_IGMP_CTRL (0x1058)
  342. #define RTL839X_SPCL_TRAP_IPV6_CTRL (0x1064)
  343. #define RTL839X_SPCL_TRAP_SWITCH_MAC_CTRL (0x1068)
  344. #define RTL839X_SPCL_TRAP_SWITCH_IPV4_ADDR_CTRL (0x106C)
  345. #define RTL839X_SPCL_TRAP_CRC_CTRL (0x1070)
  346. /* special port action controls */
  347. /*
  348. values:
  349. 0 = FORWARD (default)
  350. 1 = DROP
  351. 2 = TRAP2CPU
  352. 3 = FLOOD IN ALL PORT
  353. Register encoding.
  354. offset = CTRL + (port >> 4) << 2
  355. value/mask = 3 << ((port&0xF) << 1)
  356. */
  357. typedef enum {
  358. BPDU = 0,
  359. PTP,
  360. PTP_UDP,
  361. PTP_ETH2,
  362. LLTP,
  363. EAPOL,
  364. GRATARP,
  365. } rma_ctrl_t;
  366. typedef enum {
  367. FORWARD = 0,
  368. DROP,
  369. TRAP2CPU,
  370. FLOODALL,
  371. TRAP2MASTERCPU,
  372. COPY2CPU,
  373. } action_type_t;
  374. #define RTL838X_RMA_BPDU_CTRL (0x4330)
  375. #define RTL839X_RMA_BPDU_CTRL (0x122C)
  376. #define RTL930X_RMA_BPDU_CTRL (0x9E7C)
  377. #define RTL931X_RMA_BPDU_CTRL (0x881C)
  378. #define RTL838X_RMA_PTP_CTRL (0x4338)
  379. #define RTL839X_RMA_PTP_CTRL (0x123C)
  380. #define RTL930X_RMA_PTP_CTRL (0x9E88)
  381. #define RTL931X_RMA_PTP_CTRL (0x8834)
  382. #define RTL838X_RMA_LLTP_CTRL (0x4340)
  383. #define RTL839X_RMA_LLTP_CTRL (0x124C)
  384. #define RTL930X_RMA_LLTP_CTRL (0x9EFC)
  385. #define RTL931X_RMA_LLTP_CTRL (0x8918)
  386. #define RTL930X_RMA_EAPOL_CTRL (0x9F08)
  387. #define RTL931X_RMA_EAPOL_CTRL (0x8930)
  388. #define RTL931X_TRAP_ARP_GRAT_PORT_ACT (0x8C04)
  389. /* QoS */
  390. #define RTL838X_QM_INTPRI2QID_CTRL (0x5F00)
  391. #define RTL839X_QM_INTPRI2QID_CTRL(q) (0x1110 + (q << 2))
  392. #define RTL839X_QM_PORT_QNUM(p) (0x1130 + (((p / 10) << 2)))
  393. #define RTL838X_PRI_SEL_PORT_PRI(p) (0x5FB8 + (((p / 10) << 2)))
  394. #define RTL839X_PRI_SEL_PORT_PRI(p) (0x10A8 + (((p / 10) << 2)))
  395. #define RTL838X_QM_PKT2CPU_INTPRI_MAP (0x5F10)
  396. #define RTL839X_QM_PKT2CPU_INTPRI_MAP (0x1154)
  397. #define RTL838X_PRI_SEL_CTRL (0x10E0)
  398. #define RTL839X_PRI_SEL_CTRL (0x10E0)
  399. #define RTL838X_PRI_SEL_TBL_CTRL(i) (0x5FD8 + (((i) << 2)))
  400. #define RTL839X_PRI_SEL_TBL_CTRL(i) (0x10D0 + (((i) << 2)))
  401. #define RTL838X_QM_PKT2CPU_INTPRI_0 (0x5F04)
  402. #define RTL838X_QM_PKT2CPU_INTPRI_1 (0x5F08)
  403. #define RTL838X_QM_PKT2CPU_INTPRI_2 (0x5F0C)
  404. #define RTL839X_OAM_CTRL (0x2100)
  405. #define RTL839X_OAM_PORT_ACT_CTRL(p) (0x2104 + (((p) << 2)))
  406. #define RTL839X_RMK_PORT_DEI_TAG_CTRL(p) (0x6A9C + (((p >> 5) << 2)))
  407. #define RTL839X_PRI_SEL_IPRI_REMAP (0x1080)
  408. #define RTL838X_PRI_SEL_IPRI_REMAP (0x5F8C)
  409. #define RTL839X_PRI_SEL_DEI2DP_REMAP (0x10EC)
  410. #define RTL839X_PRI_SEL_DSCP2DP_REMAP_ADDR(i) (0x10F0 + (((i >> 4) << 2)))
  411. #define RTL839X_RMK_DEI_CTRL (0x6AA4)
  412. #define RTL839X_WRED_PORT_THR_CTRL(i) (0x6084 + ((i) << 2))
  413. #define RTL839X_WRED_QUEUE_THR_CTRL(q, i) (0x6090 + ((q) * 12) + ((i) << 2))
  414. #define RTL838X_PRI_DSCP_INVLD_CTRL0 (0x5FE8)
  415. #define RTL838X_RMK_IPRI_CTRL (0xA460)
  416. #define RTL838X_RMK_OPRI_CTRL (0xA464)
  417. #define RTL838X_SCHED_P_TYPE_CTRL(p) (0xC04C + (((p) << 7)))
  418. #define RTL838X_SCHED_LB_CTRL(p) (0xC004 + (((p) << 7)))
  419. #define RTL838X_FC_P_EGR_DROP_CTRL(p) (0x6B1C + (((p) << 2)))
  420. /* Debug features */
  421. #define RTL930X_STAT_PRVTE_DROP_COUNTER0 (0xB5B8)
  422. /* Packet Inspection Engine */
  423. #define RTL838X_METER_GLB_CTRL (0x4B08)
  424. #define RTL839X_METER_GLB_CTRL (0x1300)
  425. #define RTL930X_METER_GLB_CTRL (0xa0a0)
  426. #define RTL931X_METER_GLB_CTRL (0x411C)
  427. #define RTL839X_ACL_CTRL (0x1288)
  428. #define RTL838X_ACL_BLK_LOOKUP_CTRL (0x6100)
  429. #define RTL839X_ACL_BLK_LOOKUP_CTRL (0x1280)
  430. #define RTL930X_PIE_BLK_LOOKUP_CTRL (0xa5a0)
  431. #define RTL931X_PIE_BLK_LOOKUP_CTRL (0x4180)
  432. #define RTL838X_ACL_BLK_PWR_CTRL (0x6104)
  433. #define RTL839X_PS_ACL_PWR_CTRL (0x049c)
  434. #define RTL838X_ACL_BLK_TMPLTE_CTRL(block) (0x6108 + ((block) << 2))
  435. #define RTL839X_ACL_BLK_TMPLTE_CTRL(block) (0x128c + ((block) << 2))
  436. #define RTL930X_PIE_BLK_TMPLTE_CTRL(block) (0xa624 + ((block) << 2))
  437. #define RTL931X_PIE_BLK_TMPLTE_CTRL(block) (0x4214 + ((block) << 2))
  438. #define RTL838X_ACL_BLK_GROUP_CTRL (0x615C)
  439. #define RTL839X_ACL_BLK_GROUP_CTRL (0x12ec)
  440. #define RTL838X_ACL_CLR_CTRL (0x6168)
  441. #define RTL839X_ACL_CLR_CTRL (0x12fc)
  442. #define RTL930X_PIE_CLR_CTRL (0xa66c)
  443. #define RTL931X_PIE_CLR_CTRL (0x42D8)
  444. #define RTL838X_DMY_REG27 (0x3378)
  445. #define RTL838X_ACL_PORT_LOOKUP_CTRL(p) (0x616C + (((p) << 2)))
  446. #define RTL930X_ACL_PORT_LOOKUP_CTRL(p) (0xA784 + (((p) << 2)))
  447. #define RTL931X_ACL_PORT_LOOKUP_CTRL(p) (0x44F8 + (((p) << 2)))
  448. #define RTL930X_PIE_BLK_PHASE_CTRL (0xA5A4)
  449. #define RTL931X_PIE_BLK_PHASE_CTRL (0x4184)
  450. // PIE actions
  451. #define PIE_ACT_COPY_TO_PORT 2
  452. #define PIE_ACT_REDIRECT_TO_PORT 4
  453. #define PIE_ACT_ROUTE_UC 6
  454. #define PIE_ACT_VID_ASSIGN 0
  455. // L3 actions
  456. #define L3_FORWARD 0
  457. #define L3_DROP 1
  458. #define L3_TRAP2CPU 2
  459. #define L3_COPY2CPU 3
  460. #define L3_TRAP2MASTERCPU 4
  461. #define L3_COPY2MASTERCPU 5
  462. #define L3_HARDDROP 6
  463. // Route actions
  464. #define ROUTE_ACT_FORWARD 0
  465. #define ROUTE_ACT_TRAP2CPU 1
  466. #define ROUTE_ACT_COPY2CPU 2
  467. #define ROUTE_ACT_DROP 3
  468. /* L3 Routing */
  469. #define RTL839X_ROUTING_SA_CTRL 0x6afc
  470. #define RTL930X_L3_HOST_TBL_CTRL (0xAB48)
  471. #define RTL930X_L3_IPUC_ROUTE_CTRL (0xAB4C)
  472. #define RTL930X_L3_IP6UC_ROUTE_CTRL (0xAB50)
  473. #define RTL930X_L3_IPMC_ROUTE_CTRL (0xAB54)
  474. #define RTL930X_L3_IP6MC_ROUTE_CTRL (0xAB58)
  475. #define RTL930X_L3_IP_MTU_CTRL(i) (0xAB5C + ((i >> 1) << 2))
  476. #define RTL930X_L3_IP6_MTU_CTRL(i) (0xAB6C + ((i >> 1) << 2))
  477. #define RTL930X_L3_HW_LU_KEY_CTRL (0xAC9C)
  478. #define RTL930X_L3_HW_LU_KEY_IP_CTRL (0xACA0)
  479. #define RTL930X_L3_HW_LU_CTRL (0xACC0)
  480. #define RTL930X_L3_IP_ROUTE_CTRL 0xab44
  481. /* Port LED Control */
  482. #define RTL930X_LED_PORT_NUM_CTRL(p) (0xCC04 + (((p >> 4) << 2)))
  483. #define RTL930X_LED_SET0_0_CTRL (0xCC28)
  484. #define RTL930X_LED_PORT_COPR_SET_SEL_CTRL(p) (0xCC2C + (((p >> 4) << 2)))
  485. #define RTL930X_LED_PORT_FIB_SET_SEL_CTRL(p) (0xCC34 + (((p >> 4) << 2)))
  486. #define RTL930X_LED_PORT_COPR_MASK_CTRL (0xCC3C)
  487. #define RTL930X_LED_PORT_FIB_MASK_CTRL (0xCC40)
  488. #define RTL930X_LED_PORT_COMBO_MASK_CTRL (0xCC44)
  489. #define RTL931X_LED_PORT_NUM_CTRL(p) (0x0604 + (((p >> 4) << 2)))
  490. #define RTL931X_LED_SET0_0_CTRL (0x0630)
  491. #define RTL931X_LED_PORT_COPR_SET_SEL_CTRL(p) (0x0634 + (((p >> 4) << 2)))
  492. #define RTL931X_LED_PORT_FIB_SET_SEL_CTRL(p) (0x0644 + (((p >> 4) << 2)))
  493. #define RTL931X_LED_PORT_COPR_MASK_CTRL (0x0654)
  494. #define RTL931X_LED_PORT_FIB_MASK_CTRL (0x065c)
  495. #define RTL931X_LED_PORT_COMBO_MASK_CTRL (0x0664)
  496. #define MAX_VLANS 4096
  497. #define MAX_LAGS 16
  498. #define MAX_PRIOS 8
  499. #define RTL930X_PORT_IGNORE 0x3f
  500. #define MAX_MC_GROUPS 512
  501. #define UNKNOWN_MC_PMASK (MAX_MC_GROUPS - 1)
  502. #define PIE_BLOCK_SIZE 128
  503. #define MAX_PIE_ENTRIES (18 * PIE_BLOCK_SIZE)
  504. #define N_FIXED_FIELDS 12
  505. #define N_FIXED_FIELDS_RTL931X 14
  506. #define MAX_COUNTERS 2048
  507. #define MAX_ROUTES 512
  508. #define MAX_HOST_ROUTES 1536
  509. #define MAX_INTF_MTUS 8
  510. #define DEFAULT_MTU 1536
  511. #define MAX_INTERFACES 100
  512. #define MAX_ROUTER_MACS 64
  513. #define L3_EGRESS_DMACS 2048
  514. #define MAX_SMACS 64
  515. enum phy_type {
  516. PHY_NONE = 0,
  517. PHY_RTL838X_SDS = 1,
  518. PHY_RTL8218B_INT = 2,
  519. PHY_RTL8218B_EXT = 3,
  520. PHY_RTL8214FC = 4,
  521. PHY_RTL839X_SDS = 5,
  522. PHY_RTL930X_SDS = 6,
  523. };
  524. enum pbvlan_type {
  525. PBVLAN_TYPE_INNER = 0,
  526. PBVLAN_TYPE_OUTER,
  527. };
  528. enum pbvlan_mode {
  529. PBVLAN_MODE_UNTAG_AND_PRITAG = 0,
  530. PBVLAN_MODE_UNTAG_ONLY,
  531. PBVLAN_MODE_ALL_PKT,
  532. };
  533. struct rtl838x_port {
  534. bool enable;
  535. u64 pm;
  536. u16 pvid;
  537. bool eee_enabled;
  538. enum phy_type phy;
  539. bool phy_is_integrated;
  540. bool is10G;
  541. bool is2G5;
  542. int sds_num;
  543. int led_set;
  544. const struct dsa_port *dp;
  545. };
  546. struct rtl838x_vlan_info {
  547. u64 untagged_ports;
  548. u64 tagged_ports;
  549. u8 profile_id;
  550. bool hash_mc_fid;
  551. bool hash_uc_fid;
  552. u8 fid; // AKA MSTI
  553. // The following fields are used only by the RTL931X
  554. int if_id; // Interface (index in L3_EGR_INTF_IDX)
  555. u16 multicast_grp_mask;
  556. int l2_tunnel_list_id;
  557. };
  558. enum l2_entry_type {
  559. L2_INVALID = 0,
  560. L2_UNICAST = 1,
  561. L2_MULTICAST = 2,
  562. IP4_MULTICAST = 3,
  563. IP6_MULTICAST = 4,
  564. };
  565. struct rtl838x_l2_entry {
  566. u8 mac[6];
  567. u16 vid;
  568. u16 rvid;
  569. u8 port;
  570. bool valid;
  571. enum l2_entry_type type;
  572. bool is_static;
  573. bool is_ip_mc;
  574. bool is_ipv6_mc;
  575. bool block_da;
  576. bool block_sa;
  577. bool suspended;
  578. bool next_hop;
  579. int age;
  580. u8 trunk;
  581. bool is_trunk;
  582. u8 stack_dev;
  583. u16 mc_portmask_index;
  584. u32 mc_gip;
  585. u32 mc_sip;
  586. u16 mc_mac_index;
  587. u16 nh_route_id;
  588. bool nh_vlan_target; // Only RTL83xx: VLAN used for next hop
  589. // The following is only valid on RTL931x
  590. bool is_open_flow;
  591. bool is_pe_forward;
  592. bool is_local_forward;
  593. bool is_remote_forward;
  594. bool is_l2_tunnel;
  595. int l2_tunnel_id;
  596. int l2_tunnel_list_id;
  597. };
  598. enum fwd_rule_action {
  599. FWD_RULE_ACTION_NONE = 0,
  600. FWD_RULE_ACTION_FWD = 1,
  601. };
  602. enum pie_phase {
  603. PHASE_VACL = 0,
  604. PHASE_IACL = 1,
  605. };
  606. enum igr_filter {
  607. IGR_FORWARD = 0,
  608. IGR_DROP = 1,
  609. IGR_TRAP = 2,
  610. };
  611. enum egr_filter {
  612. EGR_DISABLE = 0,
  613. EGR_ENABLE = 1,
  614. };
  615. /* Intermediate representation of a Packet Inspection Engine Rule
  616. * as suggested by the Kernel's tc flower offload subsystem
  617. * Field meaning is universal across SoC families, but data content is specific
  618. * to SoC family (e.g. because of different port ranges) */
  619. struct pie_rule {
  620. int id;
  621. enum pie_phase phase; // Phase in which this template is applied
  622. int packet_cntr; // ID of a packet counter assigned to this rule
  623. int octet_cntr; // ID of a byte counter assigned to this rule
  624. u32 last_packet_cnt;
  625. u64 last_octet_cnt;
  626. // The following are requirements for the pie template
  627. bool is_egress;
  628. bool is_ipv6; // This is a rule with IPv6 fields
  629. // Fixed fields that are always matched against on RTL8380
  630. u8 spmmask_fix;
  631. u8 spn; // Source port number
  632. bool stacking_port; // Source port is stacking port
  633. bool mgnt_vlan; // Packet arrived on management VLAN
  634. bool dmac_hit_sw; // The packet's destination MAC matches one of the device's
  635. bool content_too_deep; // The content of the packet cannot be parsed: too many layers
  636. bool not_first_frag; // Not the first IP fragment
  637. u8 frame_type_l4; // 0: UDP, 1: TCP, 2: ICMP/ICMPv6, 3: IGMP
  638. u8 frame_type; // 0: ARP, 1: L2 only, 2: IPv4, 3: IPv6
  639. bool otag_fmt; // 0: outer tag packet, 1: outer priority tag or untagged
  640. bool itag_fmt; // 0: inner tag packet, 1: inner priority tag or untagged
  641. bool otag_exist; // packet with outer tag
  642. bool itag_exist; // packet with inner tag
  643. bool frame_type_l2; // 0: Ethernet, 1: LLC_SNAP, 2: LLC_Other, 3: Reserved
  644. bool igr_normal_port; // Ingress port is not cpu or stacking port
  645. u8 tid; // The template ID defining the what the templated fields mean
  646. // Masks for the fields that are always matched against on RTL8380
  647. u8 spmmask_fix_m;
  648. u8 spn_m;
  649. bool stacking_port_m;
  650. bool mgnt_vlan_m;
  651. bool dmac_hit_sw_m;
  652. bool content_too_deep_m;
  653. bool not_first_frag_m;
  654. u8 frame_type_l4_m;
  655. u8 frame_type_m;
  656. bool otag_fmt_m;
  657. bool itag_fmt_m;
  658. bool otag_exist_m;
  659. bool itag_exist_m;
  660. bool frame_type_l2_m;
  661. bool igr_normal_port_m;
  662. u8 tid_m;
  663. // Logical operations between rules, special rules for rule numbers apply
  664. bool valid;
  665. bool cond_not; // Matches when conditions not match
  666. bool cond_and1; // And this rule 2n with the next rule 2n+1 in same block
  667. bool cond_and2; // And this rule m in block 2n with rule m in block 2n+1
  668. bool ivalid;
  669. // Actions to be performed
  670. bool drop; // Drop the packet
  671. bool fwd_sel; // Forward packet: to port, portmask, dest route, next rule, drop
  672. bool ovid_sel; // So something to outer vlan-id: shift, re-assign
  673. bool ivid_sel; // Do something to inner vlan-id: shift, re-assign
  674. bool flt_sel; // Filter the packet when sending to certain ports
  675. bool log_sel; // Log the packet in one of the LOG-table counters
  676. bool rmk_sel; // Re-mark the packet, i.e. change the priority-tag
  677. bool meter_sel; // Meter the packet, i.e. limit rate of this type of packet
  678. bool tagst_sel; // Change the ergress tag
  679. bool mir_sel; // Mirror the packet to a Link Aggregation Group
  680. bool nopri_sel; // Change the normal priority
  681. bool cpupri_sel; // Change the CPU priority
  682. bool otpid_sel; // Change Outer Tag Protocol Identifier (802.1q)
  683. bool itpid_sel; // Change Inner Tag Protocol Identifier (802.1q)
  684. bool shaper_sel; // Apply traffic shaper
  685. bool mpls_sel; // MPLS actions
  686. bool bypass_sel; // Bypass actions
  687. bool fwd_sa_lrn; // Learn the source address when forwarding
  688. bool fwd_mod_to_cpu; // Forward the modified VLAN tag format to CPU-port
  689. // Fields used in predefined templates 0-2 on RTL8380 / 90 / 9300
  690. u64 spm; // Source Port Matrix
  691. u16 otag; // Outer VLAN-ID
  692. u8 smac[ETH_ALEN]; // Source MAC address
  693. u8 dmac[ETH_ALEN]; // Destination MAC address
  694. u16 ethertype; // Ethernet frame type field in ethernet header
  695. u16 itag; // Inner VLAN-ID
  696. u16 field_range_check;
  697. u32 sip; // Source IP
  698. struct in6_addr sip6; // IPv6 Source IP
  699. u32 dip; // Destination IP
  700. struct in6_addr dip6; // IPv6 Destination IP
  701. u16 tos_proto; // IPv4: TOS + Protocol fields, IPv6: Traffic class + next header
  702. u16 sport; // TCP/UDP source port
  703. u16 dport; // TCP/UDP destination port
  704. u16 icmp_igmp;
  705. u16 tcp_info;
  706. u16 dsap_ssap; // Destination / Source Service Access Point bytes (802.3)
  707. u64 spm_m;
  708. u16 otag_m;
  709. u8 smac_m[ETH_ALEN];
  710. u8 dmac_m[ETH_ALEN];
  711. u8 ethertype_m;
  712. u16 itag_m;
  713. u16 field_range_check_m;
  714. u32 sip_m;
  715. struct in6_addr sip6_m; // IPv6 Source IP mask
  716. u32 dip_m;
  717. struct in6_addr dip6_m; // IPv6 Destination IP mask
  718. u16 tos_proto_m;
  719. u16 sport_m;
  720. u16 dport_m;
  721. u16 icmp_igmp_m;
  722. u16 tcp_info_m;
  723. u16 dsap_ssap_m;
  724. // Data associated with actions
  725. u8 fwd_act; // Type of forwarding action
  726. // 0: permit, 1: drop, 2: copy to port id, 4: copy to portmask
  727. // 4: redirect to portid, 5: redirect to portmask
  728. // 6: route, 7: vlan leaky (only 8380)
  729. u16 fwd_data; // Additional data for forwarding action, e.g. destination port
  730. u8 ovid_act;
  731. u16 ovid_data; // Outer VLAN ID
  732. u8 ivid_act;
  733. u16 ivid_data; // Inner VLAN ID
  734. u16 flt_data; // Filtering data
  735. u16 log_data; // ID of packet or octet counter in LOG table, on RTL93xx
  736. // unnecessary since PIE-Rule-ID == LOG-counter-ID
  737. bool log_octets;
  738. u8 mpls_act; // MPLS action type
  739. u16 mpls_lib_idx; // MPLS action data
  740. u16 rmk_data; // Data for remarking
  741. u16 meter_data; // ID of meter for bandwidth control
  742. u16 tagst_data;
  743. u16 mir_data;
  744. u16 nopri_data;
  745. u16 cpupri_data;
  746. u16 otpid_data;
  747. u16 itpid_data;
  748. u16 shaper_data;
  749. // Bypass actions, ignored on RTL8380
  750. bool bypass_all; // Not clear
  751. bool bypass_igr_stp; // Bypass Ingress STP state
  752. bool bypass_ibc_sc; // Bypass Ingress Bandwidth Control and Storm Control
  753. };
  754. struct rtl838x_l3_intf {
  755. u16 vid;
  756. u8 smac_idx;
  757. u8 ip4_mtu_id;
  758. u8 ip6_mtu_id;
  759. u16 ip4_mtu;
  760. u16 ip6_mtu;
  761. u8 ttl_scope;
  762. u8 hl_scope;
  763. u8 ip4_icmp_redirect;
  764. u8 ip6_icmp_redirect;
  765. u8 ip4_pbr_icmp_redirect;
  766. u8 ip6_pbr_icmp_redirect;
  767. };
  768. /*
  769. * An entry in the RTL93XX SoC's ROUTER_MAC tables setting up a termination point
  770. * for the L3 routing system. Packets arriving and matching an entry in this table
  771. * will be considered for routing.
  772. * Mask fields state whether the corresponding data fields matter for matching
  773. */
  774. struct rtl93xx_rt_mac {
  775. bool valid; // Valid or not
  776. bool p_type; // Individual (0) or trunk (1) port
  777. bool p_mask; // Whether the port type is used
  778. u8 p_id;
  779. u8 p_id_mask; // Mask for the port
  780. u8 action; // Routing action performed: 0: FORWARD, 1: DROP, 2: TRAP2CPU
  781. // 3: COPY2CPU, 4: TRAP2MASTERCPU, 5: COPY2MASTERCPU, 6: HARDDROP
  782. u16 vid;
  783. u16 vid_mask;
  784. u64 mac; // MAC address used as source MAC in the routed packet
  785. u64 mac_mask;
  786. };
  787. struct rtl83xx_nexthop {
  788. u16 id; // ID: L3_NEXT_HOP table-index or route-index set in L2_NEXT_HOP
  789. u32 dev_id;
  790. u16 port;
  791. u16 vid; // VLAN-ID for L2 table entry (saved from L2-UC entry)
  792. u16 rvid; // Relay VID/FID for the L2 table entry
  793. u64 mac; // The MAC address of the entry in the L2_NEXT_HOP table
  794. u16 mac_id;
  795. u16 l2_id; // Index of this next hop forwarding entry in L2 FIB table
  796. u64 gw; // The gateway MAC address packets are forwarded to
  797. int if_id; // Interface (into L3_EGR_INTF_IDX)
  798. };
  799. struct rtl838x_switch_priv;
  800. struct rtl83xx_flow {
  801. unsigned long cookie;
  802. struct rhash_head node;
  803. struct rcu_head rcu_head;
  804. struct rtl838x_switch_priv *priv;
  805. struct pie_rule rule;
  806. u32 flags;
  807. };
  808. struct rtl93xx_route_attr {
  809. bool valid;
  810. bool hit;
  811. bool ttl_dec;
  812. bool ttl_check;
  813. bool dst_null;
  814. bool qos_as;
  815. u8 qos_prio;
  816. u8 type;
  817. u8 action;
  818. };
  819. struct rtl83xx_route {
  820. u32 gw_ip; // IP of the route's gateway
  821. u32 dst_ip; // IP of the destination net
  822. struct in6_addr dst_ip6;
  823. int prefix_len; // Network prefix len of the destination net
  824. bool is_host_route;
  825. int id; // ID number of this route
  826. struct rhlist_head linkage;
  827. u16 switch_mac_id; // Index into switch's own MACs, RTL839X only
  828. struct rtl83xx_nexthop nh;
  829. struct pie_rule pr;
  830. struct rtl93xx_route_attr attr;
  831. };
  832. struct rtl838x_reg {
  833. void (*mask_port_reg_be)(u64 clear, u64 set, int reg);
  834. void (*set_port_reg_be)(u64 set, int reg);
  835. u64 (*get_port_reg_be)(int reg);
  836. void (*mask_port_reg_le)(u64 clear, u64 set, int reg);
  837. void (*set_port_reg_le)(u64 set, int reg);
  838. u64 (*get_port_reg_le)(int reg);
  839. int stat_port_rst;
  840. int stat_rst;
  841. int stat_port_std_mib;
  842. int (*port_iso_ctrl)(int p);
  843. void (*traffic_enable)(int source, int dest);
  844. void (*traffic_disable)(int source, int dest);
  845. void (*traffic_set)(int source, u64 dest_matrix);
  846. u64 (*traffic_get)(int source);
  847. int l2_ctrl_0;
  848. int l2_ctrl_1;
  849. int smi_poll_ctrl;
  850. u32 l2_port_aging_out;
  851. int l2_tbl_flush_ctrl;
  852. void (*exec_tbl0_cmd)(u32 cmd);
  853. void (*exec_tbl1_cmd)(u32 cmd);
  854. int (*tbl_access_data_0)(int i);
  855. int isr_glb_src;
  856. int isr_port_link_sts_chg;
  857. int imr_port_link_sts_chg;
  858. int imr_glb;
  859. void (*vlan_tables_read)(u32 vlan, struct rtl838x_vlan_info *info);
  860. void (*vlan_set_tagged)(u32 vlan, struct rtl838x_vlan_info *info);
  861. void (*vlan_set_untagged)(u32 vlan, u64 portmask);
  862. void (*vlan_profile_dump)(int index);
  863. void (*vlan_profile_setup)(int profile);
  864. void (*vlan_port_pvidmode_set)(int port, enum pbvlan_type type, enum pbvlan_mode mode);
  865. void (*vlan_port_pvid_set)(int port, enum pbvlan_type type, int pvid);
  866. void (*vlan_port_keep_tag_set)(int port, bool keep_outer, bool keep_inner);
  867. void (*set_vlan_igr_filter)(int port, enum igr_filter state);
  868. void (*set_vlan_egr_filter)(int port, enum egr_filter state);
  869. void (*enable_learning)(int port, bool enable);
  870. void (*enable_flood)(int port, bool enable);
  871. void (*enable_mcast_flood)(int port, bool enable);
  872. void (*enable_bcast_flood)(int port, bool enable);
  873. void (*stp_get)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]);
  874. void (*stp_set)(struct rtl838x_switch_priv *priv, u16 msti, u32 port_state[]);
  875. int (*mac_force_mode_ctrl)(int port);
  876. int (*mac_port_ctrl)(int port);
  877. int (*l2_port_new_salrn)(int port);
  878. int (*l2_port_new_sa_fwd)(int port);
  879. int (*set_ageing_time)(unsigned long msec);
  880. int mir_ctrl;
  881. int mir_dpm;
  882. int mir_spm;
  883. int mac_link_sts;
  884. int mac_link_dup_sts;
  885. int (*mac_link_spd_sts)(int port);
  886. int mac_rx_pause_sts;
  887. int mac_tx_pause_sts;
  888. u64 (*read_l2_entry_using_hash)(u32 hash, u32 position, struct rtl838x_l2_entry *e);
  889. void (*write_l2_entry_using_hash)(u32 hash, u32 pos, struct rtl838x_l2_entry *e);
  890. u64 (*read_cam)(int idx, struct rtl838x_l2_entry *e);
  891. void (*write_cam)(int idx, struct rtl838x_l2_entry *e);
  892. int (*trk_mbr_ctr)(int group);
  893. int rma_bpdu_fld_pmask;
  894. int spcl_trap_eapol_ctrl;
  895. void (*init_eee)(struct rtl838x_switch_priv *priv, bool enable);
  896. void (*port_eee_set)(struct rtl838x_switch_priv *priv, int port, bool enable);
  897. int (*eee_port_ability)(struct rtl838x_switch_priv *priv,
  898. struct ethtool_eee *e, int port);
  899. u64 (*l2_hash_seed)(u64 mac, u32 vid);
  900. u32 (*l2_hash_key)(struct rtl838x_switch_priv *priv, u64 seed);
  901. u64 (*read_mcast_pmask)(int idx);
  902. void (*write_mcast_pmask)(int idx, u64 portmask);
  903. void (*vlan_fwd_on_inner)(int port, bool is_set);
  904. void (*pie_init)(struct rtl838x_switch_priv *priv);
  905. int (*pie_rule_read)(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr);
  906. int (*pie_rule_write)(struct rtl838x_switch_priv *priv, int idx, struct pie_rule *pr);
  907. int (*pie_rule_add)(struct rtl838x_switch_priv *priv, struct pie_rule *rule);
  908. void (*pie_rule_rm)(struct rtl838x_switch_priv *priv, struct pie_rule *rule);
  909. void (*l2_learning_setup)(void);
  910. u32 (*packet_cntr_read)(int counter);
  911. void (*packet_cntr_clear)(int counter);
  912. void (*route_read)(int idx, struct rtl83xx_route *rt);
  913. void (*route_write)(int idx, struct rtl83xx_route *rt);
  914. void (*host_route_write)(int idx, struct rtl83xx_route *rt);
  915. int (*l3_setup)(struct rtl838x_switch_priv *priv);
  916. void (*set_l3_nexthop)(int idx, u16 dmac_id, u16 interface);
  917. void (*get_l3_nexthop)(int idx, u16 *dmac_id, u16 *interface);
  918. u64 (*get_l3_egress_mac)(u32 idx);
  919. void (*set_l3_egress_mac)(u32 idx, u64 mac);
  920. int (*find_l3_slot)(struct rtl83xx_route *rt, bool must_exist);
  921. int (*route_lookup_hw)(struct rtl83xx_route *rt);
  922. void (*get_l3_router_mac)(u32 idx, struct rtl93xx_rt_mac *m);
  923. void (*set_l3_router_mac)(u32 idx, struct rtl93xx_rt_mac *m);
  924. void (*set_l3_egress_intf)(int idx, struct rtl838x_l3_intf *intf);
  925. void (*set_distribution_algorithm)(int group, int algoidx, u32 algomask);
  926. void (*set_receive_management_action)(int port, rma_ctrl_t type, action_type_t action);
  927. void (*led_init)(struct rtl838x_switch_priv *priv);
  928. };
  929. struct rtl838x_switch_priv {
  930. /* Switch operation */
  931. struct dsa_switch *ds;
  932. struct device *dev;
  933. u16 id;
  934. u16 family_id;
  935. char version;
  936. struct rtl838x_port ports[57];
  937. struct mutex reg_mutex; // Mutex for individual register manipulations
  938. struct mutex pie_mutex; // Mutex for Packet Inspection Engine
  939. int link_state_irq;
  940. int mirror_group_ports[4];
  941. struct mii_bus *mii_bus;
  942. const struct rtl838x_reg *r;
  943. u8 cpu_port;
  944. u8 port_mask;
  945. u8 port_width;
  946. u8 port_ignore;
  947. u64 irq_mask;
  948. u32 fib_entries;
  949. int l2_bucket_size;
  950. struct dentry *dbgfs_dir;
  951. int n_lags;
  952. u64 lags_port_members[MAX_LAGS];
  953. struct net_device *lag_devs[MAX_LAGS];
  954. u32 lag_primary[MAX_LAGS];
  955. u32 is_lagmember[57];
  956. u64 lagmembers;
  957. struct notifier_block nb; // TODO: change to different name
  958. struct notifier_block ne_nb;
  959. struct notifier_block fib_nb;
  960. bool eee_enabled;
  961. unsigned long int mc_group_bm[MAX_MC_GROUPS >> 5];
  962. int mc_group_saves[MAX_MC_GROUPS];
  963. int n_pie_blocks;
  964. struct rhashtable tc_ht;
  965. unsigned long int pie_use_bm[MAX_PIE_ENTRIES >> 5];
  966. int n_counters;
  967. unsigned long int octet_cntr_use_bm[MAX_COUNTERS >> 5];
  968. unsigned long int packet_cntr_use_bm[MAX_COUNTERS >> 4];
  969. struct rhltable routes;
  970. unsigned long int route_use_bm[MAX_ROUTES >> 5];
  971. unsigned long int host_route_use_bm[MAX_HOST_ROUTES >> 5];
  972. struct rtl838x_l3_intf *interfaces[MAX_INTERFACES];
  973. u16 intf_mtus[MAX_INTF_MTUS];
  974. int intf_mtu_count[MAX_INTF_MTUS];
  975. };
  976. void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv);
  977. void rtl930x_dbgfs_init(struct rtl838x_switch_priv *priv);
  978. #endif /* _RTL838X_H */