2
0

rtl838x.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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_CPU_PORT 28
  9. #define RTL839X_CPU_PORT 52
  10. #define RTL838X_MAC_PORT_CTRL(port) (0xd560 + (((port) << 7)))
  11. #define RTL839X_MAC_PORT_CTRL(port) (0x8004 + (((port) << 7)))
  12. #define RTL838X_RST_GLB_CTRL_0 (0x003c)
  13. #define RTL838X_MAC_FORCE_MODE_CTRL (0xa104)
  14. #define RTL839X_MAC_FORCE_MODE_CTRL (0x02bc)
  15. #define RTL838X_DMY_REG31 (0x3b28)
  16. #define RTL838X_SDS_MODE_SEL (0x0028)
  17. #define RTL838X_SDS_CFG_REG (0x0034)
  18. #define RTL838X_INT_MODE_CTRL (0x005c)
  19. #define RTL838X_CHIP_INFO (0x00d8)
  20. #define RTL839X_CHIP_INFO (0x0ff4)
  21. #define RTL838X_SDS4_REG28 (0xef80)
  22. #define RTL838X_SDS4_DUMMY0 (0xef8c)
  23. #define RTL838X_SDS5_EXT_REG6 (0xf18c)
  24. #define RTL838X_PORT_ISO_CTRL(port) (0x4100 + ((port) << 2))
  25. #define RTL839X_PORT_ISO_CTRL(port) (0x1400 + ((port) << 3))
  26. #define RTL8380_SDS4_FIB_REG0 (0xF800)
  27. #define RTL838X_STAT_PORT_STD_MIB (0x1200)
  28. #define RTL839X_STAT_PORT_STD_MIB (0xC000)
  29. #define RTL838X_STAT_RST (0x3100)
  30. #define RTL839X_STAT_RST (0xF504)
  31. #define RTL838X_STAT_PORT_RST (0x3104)
  32. #define RTL839X_STAT_PORT_RST (0xF508)
  33. #define RTL838X_STAT_CTRL (0x3108)
  34. #define RTL839X_STAT_CTRL (0x04cc)
  35. /* Registers of the internal Serdes of the 8390 */
  36. #define RTL8390_SDS0_1_XSG0 (0xA000)
  37. #define RTL8390_SDS0_1_XSG1 (0xA100)
  38. #define RTL839X_SDS12_13_XSG0 (0xB800)
  39. #define RTL839X_SDS12_13_XSG1 (0xB900)
  40. #define RTL839X_SDS12_13_PWR0 (0xb880)
  41. #define RTL839X_SDS12_13_PWR1 (0xb980)
  42. /* Registers of the internal Serdes of the 8380 */
  43. #define MAPLE_SDS4_REG0r RTL838X_SDS4_REG28
  44. #define MAPLE_SDS5_REG0r (RTL838X_SDS4_REG28 + 0x100)
  45. #define MAPLE_SDS4_REG3r RTL838X_SDS4_DUMMY0
  46. #define MAPLE_SDS5_REG3r (RTL838X_SDS4_REG28 + 0x100)
  47. #define MAPLE_SDS4_FIB_REG0r (RTL838X_SDS4_REG28 + 0x880)
  48. #define MAPLE_SDS5_FIB_REG0r (RTL838X_SDS4_REG28 + 0x980)
  49. /* VLAN registers */
  50. #define RTL838X_VLAN_PROFILE(idx) (0x3A88 + ((idx) << 2))
  51. #define RTL838X_VLAN_PORT_EGR_FLTR (0x3A84)
  52. #define RTL838X_VLAN_PORT_PB_VLAN(port) (0x3C00 + ((port) << 2))
  53. #define RTL838X_VLAN_PORT_IGR_FLTR(port) (0x3A7C + (((port >> 4) << 2)))
  54. #define RTL838X_VLAN_PORT_IGR_FLTR_0 (0x3A7C)
  55. #define RTL838X_VLAN_PORT_IGR_FLTR_1 (0x3A7C + 4)
  56. #define RTL838X_VLAN_PORT_TAG_STS_CTRL(port) (0xA530 + (((port) << 2)))
  57. #define RTL839X_VLAN_PROFILE(idx) (0x25C0 + (((idx) << 3)))
  58. #define RTL839X_VLAN_CTRL (0x26D4)
  59. #define RTL839X_VLAN_PORT_PB_VLAN(port) (0x26D8 + (((port) << 2)))
  60. #define RTL839X_VLAN_PORT_IGR_FLTR(port) (0x27B4 + (((port >> 4) << 2)))
  61. #define RTL839X_VLAN_PORT_EGR_FLTR(port) (0x27C4 + (((port >> 5) << 2)))
  62. #define RTL839X_VLAN_PORT_TAG_STS_CTRL(port) (0x6828 + (((port) << 2)))
  63. /* Table 0/1 access registers */
  64. #define RTL838X_TBL_ACCESS_CTRL_0 (0x6914)
  65. #define RTL838X_TBL_ACCESS_DATA_0(idx) (0x6918 + ((idx) << 2))
  66. #define RTL838X_TBL_ACCESS_CTRL_1 (0xA4C8)
  67. #define RTL838X_TBL_ACCESS_DATA_1(idx) (0xA4CC + ((idx) << 2))
  68. #define RTL839X_TBL_ACCESS_CTRL_0 (0x1190)
  69. #define RTL839X_TBL_ACCESS_DATA_0(idx) (0x1194 + ((idx) << 2))
  70. #define RTL839X_TBL_ACCESS_CTRL_1 (0x6b80)
  71. #define RTL839X_TBL_ACCESS_DATA_1(idx) (0x6b84 + ((idx) << 2))
  72. /* MAC handling */
  73. #define RTL838X_MAC_LINK_STS (0xa188)
  74. #define RTL839X_MAC_LINK_STS (0x0390)
  75. #define RTL838X_MAC_LINK_SPD_STS(port) (0xa190 + (((port >> 4) << 2)))
  76. #define RTL839X_MAC_LINK_SPD_STS(port) (0x03a0 + (((port >> 4) << 2)))
  77. #define RTL838X_MAC_LINK_DUP_STS (0xa19c)
  78. #define RTL839X_MAC_LINK_DUP_STS (0x03b0)
  79. #define RTL838X_MAC_TX_PAUSE_STS (0xa1a0)
  80. #define RTL839X_MAC_TX_PAUSE_STS (0x03b8)
  81. #define RTL838X_MAC_RX_PAUSE_STS (0xa1a4)
  82. #define RTL839X_MAC_RX_PAUSE_STS (0x03c0)
  83. #define RTL838X_EEE_TX_TIMER_GIGA_CTRL (0xaa04)
  84. #define RTL838X_EEE_TX_TIMER_GELITE_CTRL (0xaa08)
  85. #define RTL838X_DMA_IF_CTRL (0x9f58)
  86. /* MAC link state bits */
  87. #define FORCE_EN (1 << 0)
  88. #define FORCE_LINK_EN (1 << 1)
  89. #define NWAY_EN (1 << 2)
  90. #define DUPLX_MODE (1 << 3)
  91. #define TX_PAUSE_EN (1 << 6)
  92. #define RX_PAUSE_EN (1 << 7)
  93. /* EEE */
  94. #define RTL838X_MAC_EEE_ABLTY (0xa1a8)
  95. #define RTL838X_EEE_PORT_TX_EN (0x014c)
  96. #define RTL838X_EEE_PORT_RX_EN (0x0150)
  97. #define RTL838X_EEE_CLK_STOP_CTRL (0x0148)
  98. /* L2 functionality */
  99. #define RTL838X_L2_CTRL_0 (0x3200)
  100. #define RTL839X_L2_CTRL_0 (0x3800)
  101. #define RTL838X_L2_CTRL_1 (0x3204)
  102. #define RTL839X_L2_CTRL_1 (0x3804)
  103. #define RTL838X_L2_PORT_AGING_OUT (0x3358)
  104. #define RTL839X_L2_PORT_AGING_OUT (0x3b74)
  105. #define RTL838X_TBL_ACCESS_L2_CTRL (0x6900)
  106. #define RTL839X_TBL_ACCESS_L2_CTRL (0x1180)
  107. #define RTL838X_TBL_ACCESS_L2_DATA(idx) (0x6908 + ((idx) << 2))
  108. #define RTL839X_TBL_ACCESS_L2_DATA(idx) (0x1184 + ((idx) << 2))
  109. #define RTL838X_L2_TBL_FLUSH_CTRL (0x3370)
  110. #define RTL839X_L2_TBL_FLUSH_CTRL (0x3ba0)
  111. #define RTL838X_L2_PORT_NEW_SALRN(p) (0x328c + (((p >> 4) << 2)))
  112. #define RTL839X_L2_PORT_NEW_SALRN(p) (0x38F0 + (((p >> 4) << 2)))
  113. #define RTL838X_L2_PORT_NEW_SA_FWD(p) (0x3294 + (((p >> 4) << 2)))
  114. #define RTL839X_L2_PORT_NEW_SA_FWD(p) (0x3900 + (((p >> 4) << 2)))
  115. #define RTL838X_L2_PORT_SALRN(p) (0x328c + (((p >> 4) << 2)))
  116. #define RTL839X_L2_PORT_SALRN(p) (0x38F0 + (((p >> 4) << 2)))
  117. /* Port Mirroring */
  118. #define RTL838X_MIR_CTRL(grp) (0x5D00 + (((grp) << 2)))
  119. #define RTL838X_MIR_DPM_CTRL(grp) (0x5D20 + (((grp) << 2)))
  120. #define RTL838X_MIR_SPM_CTRL(grp) (0x5D10 + (((grp) << 2)))
  121. #define RTL839X_MIR_CTRL(grp) (0x2500 + (((grp) << 2)))
  122. #define RTL839X_MIR_DPM_CTRL(grp) (0x2530 + (((grp) << 2)))
  123. #define RTL839X_MIR_SPM_CTRL(grp) (0x2510 + (((grp) << 2)))
  124. /* Storm control */
  125. #define RTL838X_STORM_CTRL (0x4700)
  126. #define RTL839X_STORM_CTRL (0x1800)
  127. #define RTL838X_STORM_CTRL_LB_CTRL(p) (0x4884 + (((p) << 2)))
  128. #define RTL838X_STORM_CTRL_BURST_PPS_0 (0x4874)
  129. #define RTL838X_STORM_CTRL_BURST_PPS_1 (0x4878)
  130. #define RTL838X_STORM_CTRL_BURST_0 (0x487c)
  131. #define RTL838X_STORM_CTRL_BURST_1 (0x4880)
  132. #define RTL838X_SCHED_CTRL (0xB980)
  133. #define RTL838X_SCHED_LB_TICK_TKN_CTRL_0 (0xAD58)
  134. #define RTL838X_SCHED_LB_TICK_TKN_CTRL_1 (0xAD5C)
  135. #define RTL839X_SCHED_LB_TICK_TKN_CTRL_0 (0x1804)
  136. #define RTL839X_SCHED_LB_TICK_TKN_CTRL_1 (0x1808)
  137. #define RTL838X_SCHED_LB_THR (0xB984)
  138. #define RTL838X_STORM_CTRL_PORT_BC_EXCEED (0x470C)
  139. #define RTL838X_STORM_CTRL_PORT_MC_EXCEED (0x4710)
  140. #define RTL838X_STORM_CTRL_PORT_UC_EXCEED (0x4714)
  141. #define RTL839X_STORM_CTRL_PORT_BC_EXCEED(p) (0x180c + (((p >> 5) << 2)))
  142. #define RTL839X_STORM_CTRL_PORT_MC_EXCEED(p) (0x1814 + (((p >> 5) << 2)))
  143. #define RTL839X_STORM_CTRL_PORT_UC_EXCEED(p) (0x181c + (((p >> 5) << 2)))
  144. #define RTL838X_STORM_CTRL_PORT_UC(p) (0x4718 + (((p) << 2)))
  145. #define RTL838X_STORM_CTRL_PORT_MC(p) (0x478c + (((p) << 2)))
  146. #define RTL838X_STORM_CTRL_PORT_BC(p) (0x4800 + (((p) << 2)))
  147. /* Attack prevention */
  148. #define RTL838X_ATK_PRVNT_PORT_EN (0x5B00)
  149. #define RTL838X_ATK_PRVNT_CTRL (0x5B04)
  150. #define RTL838X_ATK_PRVNT_ACT (0x5B08)
  151. #define RTL838X_ATK_PRVNT_STS (0x5B1C)
  152. enum phy_type {
  153. PHY_NONE = 0,
  154. PHY_RTL838X_SDS = 1,
  155. PHY_RTL8218B_INT = 2,
  156. PHY_RTL8218B_EXT = 3,
  157. PHY_RTL8214FC = 4,
  158. PHY_RTL839X_SDS = 5,
  159. };
  160. struct rtl838x_port {
  161. bool enable;
  162. u64 pm;
  163. u16 pvid;
  164. bool eee_enabled;
  165. enum phy_type phy;
  166. const struct dsa_port *dp;
  167. };
  168. struct rtl838x_vlan_info {
  169. u64 untagged_ports;
  170. u64 tagged_ports;
  171. u8 profile_id;
  172. bool hash_mc_fid;
  173. bool hash_uc_fid;
  174. u8 fid;
  175. };
  176. enum l2_entry_type {
  177. L2_INVALID = 0,
  178. L2_UNICAST = 1,
  179. L2_MULTICAST = 2,
  180. IP4_MULTICAST = 3,
  181. IP6_MULTICAST = 4,
  182. };
  183. struct rtl838x_l2_entry {
  184. u8 mac[6];
  185. u16 vid;
  186. u16 rvid;
  187. u8 port;
  188. bool valid;
  189. enum l2_entry_type type;
  190. bool is_static;
  191. bool is_ip_mc;
  192. bool is_ipv6_mc;
  193. bool block_da;
  194. bool block_sa;
  195. bool suspended;
  196. bool next_hop;
  197. int age;
  198. u16 mc_portmask_index;
  199. };
  200. struct rtl838x_switch_priv;
  201. struct rtl838x_reg {
  202. void (*mask_port_reg_be)(u64 clear, u64 set, int reg);
  203. void (*set_port_reg_be)(u64 set, int reg);
  204. u64 (*get_port_reg_be)(int reg);
  205. void (*mask_port_reg_le)(u64 clear, u64 set, int reg);
  206. void (*set_port_reg_le)(u64 set, int reg);
  207. u64 (*get_port_reg_le)(int reg);
  208. int stat_port_rst;
  209. int stat_rst;
  210. int (*stat_port_std_mib)(int p);
  211. int (*port_iso_ctrl)(int p);
  212. int l2_ctrl_0;
  213. int l2_ctrl_1;
  214. int l2_port_aging_out;
  215. int smi_poll_ctrl;
  216. int l2_tbl_flush_ctrl;
  217. void (*exec_tbl0_cmd)(u32 cmd);
  218. void (*exec_tbl1_cmd)(u32 cmd);
  219. int (*tbl_access_data_0)(int i);
  220. int isr_glb_src;
  221. int isr_port_link_sts_chg;
  222. int imr_port_link_sts_chg;
  223. int imr_glb;
  224. void (*vlan_tables_read)(u32 vlan, struct rtl838x_vlan_info *info);
  225. void (*vlan_set_tagged)(u32 vlan, struct rtl838x_vlan_info *info);
  226. void (*vlan_set_untagged)(u32 vlan, u64 portmask);
  227. int (*mac_force_mode_ctrl)(int port);
  228. int (*mac_port_ctrl)(int port);
  229. int (*l2_port_new_salrn)(int port);
  230. int (*l2_port_new_sa_fwd)(int port);
  231. int (*mir_ctrl)(int group);
  232. int (*mir_dpm)(int group);
  233. int (*mir_spm)(int group);
  234. int mac_link_sts;
  235. int mac_link_dup_sts;
  236. int (*mac_link_spd_sts)(int port);
  237. int mac_rx_pause_sts;
  238. int mac_tx_pause_sts;
  239. u64 (*read_l2_entry_using_hash)(u32 hash, u32 position, struct rtl838x_l2_entry *e);
  240. u64 (*read_cam)(int idx, struct rtl838x_l2_entry *e);
  241. int (*vlan_profile)(int profile);
  242. int (*vlan_port_egr_filter)(int port);
  243. int (*vlan_port_igr_filter)(int port);
  244. int (*vlan_port_pb)(int port);
  245. int (*vlan_port_tag_sts_ctrl)(int port);
  246. };
  247. struct rtl838x_switch_priv {
  248. /* Switch operation */
  249. struct dsa_switch *ds;
  250. struct device *dev;
  251. u16 id;
  252. u16 family_id;
  253. char version;
  254. struct rtl838x_port ports[54]; /* TODO: correct size! */
  255. struct mutex reg_mutex;
  256. int link_state_irq;
  257. int mirror_group_ports[4];
  258. struct mii_bus *mii_bus;
  259. const struct rtl838x_reg *r;
  260. u8 cpu_port;
  261. u8 port_mask;
  262. u32 fib_entries;
  263. struct dentry *dbgfs_dir;
  264. };
  265. void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv);
  266. #endif /* _RTL838X_H */