rtl838x.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. /* Registers of the internal Serdes of the 8390 */
  50. #define RTL8390_SDS0_1_XSG0 (0xA000)
  51. #define RTL8390_SDS0_1_XSG1 (0xA100)
  52. #define RTL839X_SDS12_13_XSG0 (0xB800)
  53. #define RTL839X_SDS12_13_XSG1 (0xB900)
  54. #define RTL839X_SDS12_13_PWR0 (0xb880)
  55. #define RTL839X_SDS12_13_PWR1 (0xb980)
  56. /* VLAN registers */
  57. #define RTL838X_VLAN_PROFILE (0x3A88)
  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_IGR_FLTR_0 (0x3A7C)
  62. #define RTL838X_VLAN_PORT_IGR_FLTR_1 (0x3A80)
  63. #define RTL839X_VLAN_PROFILE (0x25C0)
  64. #define RTL839X_VLAN_CTRL (0x26D4)
  65. #define RTL839X_VLAN_PORT_PB_VLAN (0x26D8)
  66. #define RTL839X_VLAN_PORT_IGR_FLTR (0x27B4)
  67. #define RTL839X_VLAN_PORT_EGR_FLTR (0x27C4)
  68. /* Table 0/1 access registers */
  69. #define RTL838X_TBL_ACCESS_CTRL_0 (0x6914)
  70. #define RTL838X_TBL_ACCESS_DATA_0 (0x6918)
  71. #define RTL838X_TBL_ACCESS_CTRL_1 (0xA4C8)
  72. #define RTL838X_TBL_ACCESS_DATA_1(idx) (0xA4CC + ((idx) << 2))
  73. #define RTL839X_TBL_ACCESS_CTRL_0 (0x1190)
  74. #define RTL839X_TBL_ACCESS_DATA_0 (0x1194)
  75. #define RTL839X_TBL_ACCESS_CTRL_1 (0x6b80)
  76. #define RTL839X_TBL_ACCESS_DATA_1(idx) (0x6b84 + ((idx) << 2))
  77. /* MAC handling */
  78. #define RTL838X_MAC_LINK_STS (0xa188)
  79. #define RTL839X_MAC_LINK_STS (0x0390)
  80. #define RTL838X_MAC_LINK_SPD_STS(port) (0xa190 + (((port >> 4) << 2)))
  81. #define RTL839X_MAC_LINK_SPD_STS(port) (0x03a0 + (((port >> 4) << 2)))
  82. #define RTL838X_MAC_LINK_DUP_STS (0xa19c)
  83. #define RTL839X_MAC_LINK_DUP_STS (0x03b0)
  84. #define RTL838X_MAC_TX_PAUSE_STS (0xa1a0)
  85. #define RTL839X_MAC_TX_PAUSE_STS (0x03b8)
  86. #define RTL838X_MAC_RX_PAUSE_STS (0xa1a4)
  87. #define RTL839X_MAC_RX_PAUSE_STS (0x03c0)
  88. #define RTL838X_EEE_TX_TIMER_GIGA_CTRL (0xaa04)
  89. #define RTL838X_EEE_TX_TIMER_GELITE_CTRL (0xaa08)
  90. #define RTL838X_DMA_IF_CTRL (0x9f58)
  91. /* MAC link state bits */
  92. #define FORCE_EN (1 << 0)
  93. #define FORCE_LINK_EN (1 << 1)
  94. #define NWAY_EN (1 << 2)
  95. #define DUPLX_MODE (1 << 3)
  96. #define TX_PAUSE_EN (1 << 6)
  97. #define RX_PAUSE_EN (1 << 7)
  98. /* EEE */
  99. #define RTL838X_MAC_EEE_ABLTY (0xa1a8)
  100. #define RTL838X_EEE_PORT_TX_EN (0x014c)
  101. #define RTL838X_EEE_PORT_RX_EN (0x0150)
  102. #define RTL838X_EEE_CLK_STOP_CTRL (0x0148)
  103. /* L2 functionality */
  104. #define RTL838X_L2_CTRL_0 (0x3200)
  105. #define RTL839X_L2_CTRL_0 (0x3800)
  106. #define RTL838X_L2_CTRL_1 (0x3204)
  107. #define RTL839X_L2_CTRL_1 (0x3804)
  108. #define RTL838X_L2_PORT_AGING_OUT (0x3358)
  109. #define RTL839X_L2_PORT_AGING_OUT (0x3b74)
  110. #define RTL838X_TBL_ACCESS_L2_CTRL (0x6900)
  111. #define RTL839X_TBL_ACCESS_L2_CTRL (0x1180)
  112. #define RTL838X_TBL_ACCESS_L2_DATA(idx) (0x6908 + ((idx) << 2))
  113. #define RTL839X_TBL_ACCESS_L2_DATA(idx) (0x1184 + ((idx) << 2))
  114. #define RTL838X_L2_TBL_FLUSH_CTRL (0x3370)
  115. #define RTL839X_L2_TBL_FLUSH_CTRL (0x3ba0)
  116. #define RTL838X_L2_PORT_NEW_SALRN(p) (0x328c + (((p >> 4) << 2)))
  117. #define RTL839X_L2_PORT_NEW_SALRN(p) (0x38F0 + (((p >> 4) << 2)))
  118. #define RTL838X_L2_PORT_NEW_SA_FWD(p) (0x3294 + (((p >> 4) << 2)))
  119. #define RTL839X_L2_PORT_NEW_SA_FWD(p) (0x3900 + (((p >> 4) << 2)))
  120. #define RTL838X_L2_PORT_SALRN(p) (0x328c + (((p >> 4) << 2)))
  121. #define RTL839X_L2_PORT_SALRN(p) (0x38F0 + (((p >> 4) << 2)))
  122. /* Port Mirroring */
  123. #define RTL838X_MIR_CTRL(grp) (0x5D00 + (((grp) << 2)))
  124. #define RTL838X_MIR_DPM_CTRL(grp) (0x5D20 + (((grp) << 2)))
  125. #define RTL838X_MIR_SPM_CTRL(grp) (0x5D10 + (((grp) << 2)))
  126. #define RTL839X_MIR_CTRL(grp) (0x2500 + (((grp) << 2)))
  127. #define RTL839X_MIR_DPM_CTRL(grp) (0x2530 + (((grp) << 2)))
  128. #define RTL839X_MIR_SPM_CTRL(grp) (0x2510 + (((grp) << 2)))
  129. enum phy_type {
  130. PHY_NONE = 0,
  131. PHY_RTL838X_SDS = 1,
  132. PHY_RTL8218B_INT = 2,
  133. PHY_RTL8218B_EXT = 3,
  134. PHY_RTL8214FC = 4,
  135. PHY_RTL839X_SDS = 5,
  136. };
  137. struct rtl838x_port {
  138. bool enable;
  139. u64 pm;
  140. u16 pvid;
  141. bool eee_enabled;
  142. enum phy_type phy;
  143. };
  144. struct rtl838x_vlan_info {
  145. u64 untagged_ports;
  146. u64 tagged_ports;
  147. u8 profile_id;
  148. bool hash_mc;
  149. bool hash_uc;
  150. u8 fid;
  151. };
  152. enum l2_entry_type {
  153. L2_INVALID = 0,
  154. L2_UNICAST = 1,
  155. L2_MULTICAST = 2,
  156. IP4_MULTICAST = 3,
  157. IP6_MULTICAST = 4,
  158. };
  159. struct rtl838x_l2_entry {
  160. u8 mac[ETH_ALEN];
  161. u16 vid;
  162. u16 rvid;
  163. u8 port;
  164. bool valid;
  165. enum l2_entry_type type;
  166. bool is_static;
  167. bool is_ip_mc;
  168. bool is_ipv6_mc;
  169. bool block_da;
  170. bool block_sa;
  171. bool suspended;
  172. bool next_hop;
  173. int age;
  174. u16 mc_portmask_index;
  175. };
  176. struct rtl838x_switch_priv;
  177. struct rtl838x_reg {
  178. void (*mask_port_reg_be)(u64 clear, u64 set, int reg);
  179. void (*set_port_reg_be)(u64 set, int reg);
  180. u64 (*get_port_reg_be)(int reg);
  181. void (*mask_port_reg_le)(u64 clear, u64 set, int reg);
  182. void (*set_port_reg_le)(u64 set, int reg);
  183. u64 (*get_port_reg_le)(int reg);
  184. int stat_port_rst;
  185. int stat_rst;
  186. int (*stat_port_std_mib)(int p);
  187. int (*port_iso_ctrl)(int p);
  188. int l2_ctrl_0;
  189. int l2_ctrl_1;
  190. int l2_port_aging_out;
  191. int smi_poll_ctrl;
  192. int l2_tbl_flush_ctrl;
  193. void (*exec_tbl0_cmd)(u32 cmd);
  194. void (*exec_tbl1_cmd)(u32 cmd);
  195. int (*tbl_access_data_0)(int i);
  196. int isr_glb_src;
  197. int isr_port_link_sts_chg;
  198. int imr_port_link_sts_chg;
  199. int imr_glb;
  200. void (*vlan_tables_read)(u32 vlan, struct rtl838x_vlan_info *info);
  201. void (*vlan_set_tagged)(u32 vlan, const struct rtl838x_vlan_info *info);
  202. void (*vlan_set_untagged)(u32 vlan, u64 portmask);
  203. int (*mac_force_mode_ctrl)(int port);
  204. int (*mac_port_ctrl)(int port);
  205. int (*l2_port_new_salrn)(int port);
  206. int (*l2_port_new_sa_fwd)(int port);
  207. int (*mir_ctrl)(int group);
  208. int (*mir_dpm)(int group);
  209. int (*mir_spm)(int group);
  210. int mac_link_sts;
  211. int mac_link_dup_sts;
  212. int (*mac_link_spd_sts)(int port);
  213. int mac_rx_pause_sts;
  214. int mac_tx_pause_sts;
  215. u64 (*read_l2_entry_using_hash)(u32 hash, u32 position, struct rtl838x_l2_entry *e);
  216. u64 (*read_cam)(int idx, struct rtl838x_l2_entry *e);
  217. int (*vlan_profile)(int profile);
  218. int (*vlan_port_egr_filter)(int port);
  219. int (*vlan_port_igr_filter)(int port);
  220. int (*vlan_port_pb)(int port);
  221. };
  222. struct rtl838x_switch_priv {
  223. /* Switch operation */
  224. struct dsa_switch *ds;
  225. struct device *dev;
  226. u16 id;
  227. u16 family_id;
  228. char version;
  229. struct rtl838x_port ports[54]; /* TODO: correct size! */
  230. struct mutex reg_mutex;
  231. int link_state_irq;
  232. int mirror_group_ports[4];
  233. struct mii_bus *mii_bus;
  234. const struct rtl838x_reg *r;
  235. u8 cpu_port;
  236. u8 port_mask;
  237. u32 fib_entries;
  238. };
  239. extern struct rtl838x_soc_info soc_info;
  240. extern void rtl8380_sds_rst(int mac);
  241. extern int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val);
  242. extern int rtl839x_write_phy(u32 port, u32 page, u32 reg, u32 val);
  243. extern int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val);
  244. extern int rtl839x_read_phy(u32 port, u32 page, u32 reg, u32 *val);
  245. extern int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val);
  246. extern int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val);
  247. #endif /* _RTL838X_H */