qca8k.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2009 Felix Fietkau <nbd@nbd.name>
  4. * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  6. */
  7. #ifndef __QCA8K_H
  8. #define __QCA8K_H
  9. #include <linux/delay.h>
  10. #include <linux/regmap.h>
  11. #include <linux/gpio.h>
  12. #define QCA8K_NUM_PORTS 7
  13. #define PHY_ID_QCA8337 0x004dd036
  14. #define QCA8K_ID_QCA8337 0x13
  15. #define QCA8K_NUM_FDB_RECORDS 2048
  16. #define QCA8K_CPU_PORT 0
  17. /* Global control registers */
  18. #define QCA8K_REG_MASK_CTRL 0x000
  19. #define QCA8K_MASK_CTRL_ID_M 0xff
  20. #define QCA8K_MASK_CTRL_ID_S 8
  21. #define QCA8K_REG_PORT0_PAD_CTRL 0x004
  22. #define QCA8K_REG_PORT5_PAD_CTRL 0x008
  23. #define QCA8K_REG_PORT6_PAD_CTRL 0x00c
  24. #define QCA8K_PORT_PAD_RGMII_EN BIT(26)
  25. #define QCA8K_PORT_PAD_RGMII_TX_DELAY(x) \
  26. ((0x8 + (x & 0x3)) << 22)
  27. #define QCA8K_PORT_PAD_RGMII_RX_DELAY(x) \
  28. ((0x10 + (x & 0x3)) << 20)
  29. #define QCA8K_MAX_DELAY 3
  30. #define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)
  31. #define QCA8K_PORT_PAD_SGMII_EN BIT(7)
  32. #define QCA8K_REG_MODULE_EN 0x030
  33. #define QCA8K_MODULE_EN_MIB BIT(0)
  34. #define QCA8K_REG_MIB 0x034
  35. #define QCA8K_MIB_FLUSH BIT(24)
  36. #define QCA8K_MIB_CPU_KEEP BIT(20)
  37. #define QCA8K_MIB_BUSY BIT(17)
  38. #define QCA8K_MDIO_MASTER_CTRL 0x3c
  39. #define QCA8K_MDIO_MASTER_BUSY BIT(31)
  40. #define QCA8K_MDIO_MASTER_EN BIT(30)
  41. #define QCA8K_MDIO_MASTER_READ BIT(27)
  42. #define QCA8K_MDIO_MASTER_WRITE 0
  43. #define QCA8K_MDIO_MASTER_SUP_PRE BIT(26)
  44. #define QCA8K_MDIO_MASTER_PHY_ADDR(x) ((x) << 21)
  45. #define QCA8K_MDIO_MASTER_REG_ADDR(x) ((x) << 16)
  46. #define QCA8K_MDIO_MASTER_DATA(x) (x)
  47. #define QCA8K_MDIO_MASTER_DATA_MASK GENMASK(15, 0)
  48. #define QCA8K_MDIO_MASTER_MAX_PORTS 5
  49. #define QCA8K_MDIO_MASTER_MAX_REG 32
  50. #define QCA8K_GOL_MAC_ADDR0 0x60
  51. #define QCA8K_GOL_MAC_ADDR1 0x64
  52. #define QCA8K_REG_PORT_STATUS(_i) (0x07c + (_i) * 4)
  53. #define QCA8K_PORT_STATUS_SPEED GENMASK(1, 0)
  54. #define QCA8K_PORT_STATUS_SPEED_10 0
  55. #define QCA8K_PORT_STATUS_SPEED_100 0x1
  56. #define QCA8K_PORT_STATUS_SPEED_1000 0x2
  57. #define QCA8K_PORT_STATUS_TXMAC BIT(2)
  58. #define QCA8K_PORT_STATUS_RXMAC BIT(3)
  59. #define QCA8K_PORT_STATUS_TXFLOW BIT(4)
  60. #define QCA8K_PORT_STATUS_RXFLOW BIT(5)
  61. #define QCA8K_PORT_STATUS_DUPLEX BIT(6)
  62. #define QCA8K_PORT_STATUS_LINK_UP BIT(8)
  63. #define QCA8K_PORT_STATUS_LINK_AUTO BIT(9)
  64. #define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10)
  65. #define QCA8K_REG_PORT_HDR_CTRL(_i) (0x9c + (_i * 4))
  66. #define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)
  67. #define QCA8K_PORT_HDR_CTRL_RX_S 2
  68. #define QCA8K_PORT_HDR_CTRL_TX_MASK GENMASK(1, 0)
  69. #define QCA8K_PORT_HDR_CTRL_TX_S 0
  70. #define QCA8K_PORT_HDR_CTRL_ALL 2
  71. #define QCA8K_PORT_HDR_CTRL_MGMT 1
  72. #define QCA8K_PORT_HDR_CTRL_NONE 0
  73. /* EEE control registers */
  74. #define QCA8K_REG_EEE_CTRL 0x100
  75. #define QCA8K_REG_EEE_CTRL_LPI_EN(_i) ((_i + 1) * 2)
  76. /* ACL registers */
  77. #define QCA8K_REG_PORT_VLAN_CTRL0(_i) (0x420 + (_i * 8))
  78. #define QCA8K_PORT_VLAN_CVID(x) (x << 16)
  79. #define QCA8K_PORT_VLAN_SVID(x) x
  80. #define QCA8K_REG_PORT_VLAN_CTRL1(_i) (0x424 + (_i * 8))
  81. #define QCA8K_REG_IPV4_PRI_BASE_ADDR 0x470
  82. #define QCA8K_REG_IPV4_PRI_ADDR_MASK 0x474
  83. /* Lookup registers */
  84. #define QCA8K_REG_ATU_DATA0 0x600
  85. #define QCA8K_ATU_ADDR2_S 24
  86. #define QCA8K_ATU_ADDR3_S 16
  87. #define QCA8K_ATU_ADDR4_S 8
  88. #define QCA8K_REG_ATU_DATA1 0x604
  89. #define QCA8K_ATU_PORT_M 0x7f
  90. #define QCA8K_ATU_PORT_S 16
  91. #define QCA8K_ATU_ADDR0_S 8
  92. #define QCA8K_REG_ATU_DATA2 0x608
  93. #define QCA8K_ATU_VID_M 0xfff
  94. #define QCA8K_ATU_VID_S 8
  95. #define QCA8K_ATU_STATUS_M 0xf
  96. #define QCA8K_ATU_STATUS_STATIC 0xf
  97. #define QCA8K_REG_ATU_FUNC 0x60c
  98. #define QCA8K_ATU_FUNC_BUSY BIT(31)
  99. #define QCA8K_ATU_FUNC_PORT_EN BIT(14)
  100. #define QCA8K_ATU_FUNC_MULTI_EN BIT(13)
  101. #define QCA8K_ATU_FUNC_FULL BIT(12)
  102. #define QCA8K_ATU_FUNC_PORT_M 0xf
  103. #define QCA8K_ATU_FUNC_PORT_S 8
  104. #define QCA8K_REG_GLOBAL_FW_CTRL0 0x620
  105. #define QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN BIT(10)
  106. #define QCA8K_REG_GLOBAL_FW_CTRL1 0x624
  107. #define QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S 24
  108. #define QCA8K_GLOBAL_FW_CTRL1_BC_DP_S 16
  109. #define QCA8K_GLOBAL_FW_CTRL1_MC_DP_S 8
  110. #define QCA8K_GLOBAL_FW_CTRL1_UC_DP_S 0
  111. #define QCA8K_PORT_LOOKUP_CTRL(_i) (0x660 + (_i) * 0xc)
  112. #define QCA8K_PORT_LOOKUP_MEMBER GENMASK(6, 0)
  113. #define QCA8K_PORT_LOOKUP_STATE_MASK GENMASK(18, 16)
  114. #define QCA8K_PORT_LOOKUP_STATE_DISABLED (0 << 16)
  115. #define QCA8K_PORT_LOOKUP_STATE_BLOCKING (1 << 16)
  116. #define QCA8K_PORT_LOOKUP_STATE_LISTENING (2 << 16)
  117. #define QCA8K_PORT_LOOKUP_STATE_LEARNING (3 << 16)
  118. #define QCA8K_PORT_LOOKUP_STATE_FORWARD (4 << 16)
  119. #define QCA8K_PORT_LOOKUP_STATE GENMASK(18, 16)
  120. #define QCA8K_PORT_LOOKUP_LEARN BIT(20)
  121. /* Pkt edit registers */
  122. #define QCA8K_EGRESS_VLAN(x) (0x0c70 + (4 * (x / 2)))
  123. /* L3 registers */
  124. #define QCA8K_HROUTER_CONTROL 0xe00
  125. #define QCA8K_HROUTER_CONTROL_GLB_LOCKTIME_M GENMASK(17, 16)
  126. #define QCA8K_HROUTER_CONTROL_GLB_LOCKTIME_S 16
  127. #define QCA8K_HROUTER_CONTROL_ARP_AGE_MODE 1
  128. #define QCA8K_HROUTER_PBASED_CONTROL1 0xe08
  129. #define QCA8K_HROUTER_PBASED_CONTROL2 0xe0c
  130. #define QCA8K_HNAT_CONTROL 0xe38
  131. /* MIB registers */
  132. #define QCA8K_PORT_MIB_COUNTER(_i) (0x1000 + (_i) * 0x100)
  133. /* QCA specific MII registers */
  134. #define MII_ATH_MMD_ADDR 0x0d
  135. #define MII_ATH_MMD_DATA 0x0e
  136. enum {
  137. QCA8K_PORT_SPEED_10M = 0,
  138. QCA8K_PORT_SPEED_100M = 1,
  139. QCA8K_PORT_SPEED_1000M = 2,
  140. QCA8K_PORT_SPEED_ERR = 3,
  141. };
  142. enum qca8k_fdb_cmd {
  143. QCA8K_FDB_FLUSH = 1,
  144. QCA8K_FDB_LOAD = 2,
  145. QCA8K_FDB_PURGE = 3,
  146. QCA8K_FDB_NEXT = 6,
  147. QCA8K_FDB_SEARCH = 7,
  148. };
  149. struct ar8xxx_port_status {
  150. int enabled;
  151. };
  152. struct qca8k_priv {
  153. struct regmap *regmap;
  154. struct mii_bus *bus;
  155. struct ar8xxx_port_status port_sts[QCA8K_NUM_PORTS];
  156. struct dsa_switch *ds;
  157. struct mutex reg_mutex;
  158. struct device *dev;
  159. struct dsa_switch_ops ops;
  160. struct gpio_desc *reset_gpio;
  161. };
  162. struct qca8k_mib_desc {
  163. unsigned int size;
  164. unsigned int offset;
  165. const char *name;
  166. };
  167. struct qca8k_fdb {
  168. u16 vid;
  169. u8 port_mask;
  170. u8 aging;
  171. u8 mac[6];
  172. };
  173. #endif /* __QCA8K_H */