rtl838x.h 37 KB

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