blob: fc7db94cc0c9b35f0051d3428082c59b8db4c780 [file] [log] [blame]
Thomas Gleixner97fb5e82019-05-29 07:17:58 -07001/* SPDX-License-Identifier: GPL-2.0-only */
John Crispin6b93fb42016-09-15 16:26:41 +02002/*
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.
John Crispin6b93fb42016-09-15 16:26:41 +02006 */
7
8#ifndef __QCA8K_H
9#define __QCA8K_H
10
11#include <linux/delay.h>
12#include <linux/regmap.h>
Christian Lampartera653f2f2019-06-25 10:41:51 +020013#include <linux/gpio.h>
John Crispin6b93fb42016-09-15 16:26:41 +020014
15#define QCA8K_NUM_PORTS 7
Jonathan McDowellf58d2592020-07-18 17:32:14 +010016#define QCA8K_MAX_MTU 9000
John Crispin6b93fb42016-09-15 16:26:41 +020017
Ansuel Smith6e82a452021-05-14 22:59:59 +020018#define PHY_ID_QCA8327 0x004dd034
19#define QCA8K_ID_QCA8327 0x12
John Crispin6b93fb42016-09-15 16:26:41 +020020#define PHY_ID_QCA8337 0x004dd036
21#define QCA8K_ID_QCA8337 0x13
22
Ansuel Smith617960d2021-05-14 23:00:09 +020023#define QCA8K_BUSY_WAIT_TIMEOUT 2000
Ansuel Smith2ad255f2021-05-14 22:59:52 +020024
John Crispin6b93fb42016-09-15 16:26:41 +020025#define QCA8K_NUM_FDB_RECORDS 2048
26
27#define QCA8K_CPU_PORT 0
28
Jonathan McDowelle9d204f2020-08-01 18:05:54 +010029#define QCA8K_PORT_VID_DEF 1
30
John Crispin6b93fb42016-09-15 16:26:41 +020031/* Global control registers */
32#define QCA8K_REG_MASK_CTRL 0x000
Ansuel Smith95ffeaf2021-05-14 23:00:04 +020033#define QCA8K_MASK_CTRL_REV_ID_MASK GENMASK(7, 0)
34#define QCA8K_MASK_CTRL_REV_ID(x) ((x) >> 0)
35#define QCA8K_MASK_CTRL_DEVICE_ID_MASK GENMASK(15, 8)
36#define QCA8K_MASK_CTRL_DEVICE_ID(x) ((x) >> 8)
John Crispin6b93fb42016-09-15 16:26:41 +020037#define QCA8K_REG_PORT0_PAD_CTRL 0x004
38#define QCA8K_REG_PORT5_PAD_CTRL 0x008
39#define QCA8K_REG_PORT6_PAD_CTRL 0x00c
40#define QCA8K_PORT_PAD_RGMII_EN BIT(26)
Ansuel Smithe4b99772021-05-14 23:00:06 +020041#define QCA8K_PORT_PAD_RGMII_TX_DELAY(x) ((x) << 22)
42#define QCA8K_PORT_PAD_RGMII_RX_DELAY(x) ((x) << 20)
43#define QCA8K_PORT_PAD_RGMII_TX_DELAY_EN BIT(25)
John Crispin6b93fb42016-09-15 16:26:41 +020044#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24)
Ansuel Smithe4b99772021-05-14 23:00:06 +020045#define QCA8K_MAX_DELAY 3
John Crispin6b93fb42016-09-15 16:26:41 +020046#define QCA8K_PORT_PAD_SGMII_EN BIT(7)
Jonathan McDowellf6dadd52020-06-20 11:31:05 +010047#define QCA8K_REG_PWS 0x010
48#define QCA8K_PWS_SERDES_AEN_DIS BIT(7)
John Crispin6b93fb42016-09-15 16:26:41 +020049#define QCA8K_REG_MODULE_EN 0x030
50#define QCA8K_MODULE_EN_MIB BIT(0)
51#define QCA8K_REG_MIB 0x034
52#define QCA8K_MIB_FLUSH BIT(24)
53#define QCA8K_MIB_CPU_KEEP BIT(20)
54#define QCA8K_MIB_BUSY BIT(17)
Christian Lamparterdb460c52019-03-22 01:05:03 +010055#define QCA8K_MDIO_MASTER_CTRL 0x3c
56#define QCA8K_MDIO_MASTER_BUSY BIT(31)
57#define QCA8K_MDIO_MASTER_EN BIT(30)
58#define QCA8K_MDIO_MASTER_READ BIT(27)
59#define QCA8K_MDIO_MASTER_WRITE 0
60#define QCA8K_MDIO_MASTER_SUP_PRE BIT(26)
61#define QCA8K_MDIO_MASTER_PHY_ADDR(x) ((x) << 21)
62#define QCA8K_MDIO_MASTER_REG_ADDR(x) ((x) << 16)
63#define QCA8K_MDIO_MASTER_DATA(x) (x)
64#define QCA8K_MDIO_MASTER_DATA_MASK GENMASK(15, 0)
65#define QCA8K_MDIO_MASTER_MAX_PORTS 5
66#define QCA8K_MDIO_MASTER_MAX_REG 32
John Crispin6b93fb42016-09-15 16:26:41 +020067#define QCA8K_GOL_MAC_ADDR0 0x60
68#define QCA8K_GOL_MAC_ADDR1 0x64
Jonathan McDowellf58d2592020-07-18 17:32:14 +010069#define QCA8K_MAX_FRAME_SIZE 0x78
John Crispin6b93fb42016-09-15 16:26:41 +020070#define QCA8K_REG_PORT_STATUS(_i) (0x07c + (_i) * 4)
Michal Vokáč79a4ed42018-05-23 08:20:21 +020071#define QCA8K_PORT_STATUS_SPEED GENMASK(1, 0)
72#define QCA8K_PORT_STATUS_SPEED_10 0
73#define QCA8K_PORT_STATUS_SPEED_100 0x1
74#define QCA8K_PORT_STATUS_SPEED_1000 0x2
John Crispin6b93fb42016-09-15 16:26:41 +020075#define QCA8K_PORT_STATUS_TXMAC BIT(2)
76#define QCA8K_PORT_STATUS_RXMAC BIT(3)
77#define QCA8K_PORT_STATUS_TXFLOW BIT(4)
78#define QCA8K_PORT_STATUS_RXFLOW BIT(5)
79#define QCA8K_PORT_STATUS_DUPLEX BIT(6)
80#define QCA8K_PORT_STATUS_LINK_UP BIT(8)
81#define QCA8K_PORT_STATUS_LINK_AUTO BIT(9)
82#define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10)
Jonathan McDowellf6dadd52020-06-20 11:31:05 +010083#define QCA8K_PORT_STATUS_FLOW_AUTO BIT(12)
John Crispin6b93fb42016-09-15 16:26:41 +020084#define QCA8K_REG_PORT_HDR_CTRL(_i) (0x9c + (_i * 4))
85#define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2)
86#define QCA8K_PORT_HDR_CTRL_RX_S 2
87#define QCA8K_PORT_HDR_CTRL_TX_MASK GENMASK(1, 0)
88#define QCA8K_PORT_HDR_CTRL_TX_S 0
89#define QCA8K_PORT_HDR_CTRL_ALL 2
90#define QCA8K_PORT_HDR_CTRL_MGMT 1
91#define QCA8K_PORT_HDR_CTRL_NONE 0
Jonathan McDowellf6dadd52020-06-20 11:31:05 +010092#define QCA8K_REG_SGMII_CTRL 0x0e0
93#define QCA8K_SGMII_EN_PLL BIT(1)
94#define QCA8K_SGMII_EN_RX BIT(2)
95#define QCA8K_SGMII_EN_TX BIT(3)
96#define QCA8K_SGMII_EN_SD BIT(4)
97#define QCA8K_SGMII_CLK125M_DELAY BIT(7)
98#define QCA8K_SGMII_MODE_CTRL_MASK (BIT(22) | BIT(23))
99#define QCA8K_SGMII_MODE_CTRL_BASEX (0 << 22)
100#define QCA8K_SGMII_MODE_CTRL_PHY (1 << 22)
101#define QCA8K_SGMII_MODE_CTRL_MAC (2 << 22)
John Crispin6b93fb42016-09-15 16:26:41 +0200102
Ansuel Smithd8b6f5b2021-10-14 00:39:06 +0200103/* MAC_PWR_SEL registers */
104#define QCA8K_REG_MAC_PWR_SEL 0x0e4
105#define QCA8K_MAC_PWR_RGMII1_1_8V BIT(18)
106#define QCA8K_MAC_PWR_RGMII0_1_8V BIT(19)
107
John Crispin6b93fb42016-09-15 16:26:41 +0200108/* EEE control registers */
109#define QCA8K_REG_EEE_CTRL 0x100
110#define QCA8K_REG_EEE_CTRL_LPI_EN(_i) ((_i + 1) * 2)
111
112/* ACL registers */
113#define QCA8K_REG_PORT_VLAN_CTRL0(_i) (0x420 + (_i * 8))
114#define QCA8K_PORT_VLAN_CVID(x) (x << 16)
115#define QCA8K_PORT_VLAN_SVID(x) x
116#define QCA8K_REG_PORT_VLAN_CTRL1(_i) (0x424 + (_i * 8))
117#define QCA8K_REG_IPV4_PRI_BASE_ADDR 0x470
118#define QCA8K_REG_IPV4_PRI_ADDR_MASK 0x474
119
120/* Lookup registers */
121#define QCA8K_REG_ATU_DATA0 0x600
122#define QCA8K_ATU_ADDR2_S 24
123#define QCA8K_ATU_ADDR3_S 16
124#define QCA8K_ATU_ADDR4_S 8
125#define QCA8K_REG_ATU_DATA1 0x604
126#define QCA8K_ATU_PORT_M 0x7f
127#define QCA8K_ATU_PORT_S 16
128#define QCA8K_ATU_ADDR0_S 8
129#define QCA8K_REG_ATU_DATA2 0x608
130#define QCA8K_ATU_VID_M 0xfff
131#define QCA8K_ATU_VID_S 8
132#define QCA8K_ATU_STATUS_M 0xf
133#define QCA8K_ATU_STATUS_STATIC 0xf
134#define QCA8K_REG_ATU_FUNC 0x60c
135#define QCA8K_ATU_FUNC_BUSY BIT(31)
136#define QCA8K_ATU_FUNC_PORT_EN BIT(14)
137#define QCA8K_ATU_FUNC_MULTI_EN BIT(13)
138#define QCA8K_ATU_FUNC_FULL BIT(12)
139#define QCA8K_ATU_FUNC_PORT_M 0xf
140#define QCA8K_ATU_FUNC_PORT_S 8
Jonathan McDowell69462fe2020-08-01 18:06:46 +0100141#define QCA8K_REG_VTU_FUNC0 0x610
142#define QCA8K_VTU_FUNC0_VALID BIT(20)
143#define QCA8K_VTU_FUNC0_IVL_EN BIT(19)
144#define QCA8K_VTU_FUNC0_EG_MODE_S(_i) (4 + (_i) * 2)
145#define QCA8K_VTU_FUNC0_EG_MODE_MASK 3
146#define QCA8K_VTU_FUNC0_EG_MODE_UNMOD 0
147#define QCA8K_VTU_FUNC0_EG_MODE_UNTAG 1
148#define QCA8K_VTU_FUNC0_EG_MODE_TAG 2
149#define QCA8K_VTU_FUNC0_EG_MODE_NOT 3
150#define QCA8K_REG_VTU_FUNC1 0x614
151#define QCA8K_VTU_FUNC1_BUSY BIT(31)
152#define QCA8K_VTU_FUNC1_VID_S 16
153#define QCA8K_VTU_FUNC1_FULL BIT(4)
John Crispin6b93fb42016-09-15 16:26:41 +0200154#define QCA8K_REG_GLOBAL_FW_CTRL0 0x620
155#define QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN BIT(10)
156#define QCA8K_REG_GLOBAL_FW_CTRL1 0x624
157#define QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S 24
158#define QCA8K_GLOBAL_FW_CTRL1_BC_DP_S 16
159#define QCA8K_GLOBAL_FW_CTRL1_MC_DP_S 8
160#define QCA8K_GLOBAL_FW_CTRL1_UC_DP_S 0
161#define QCA8K_PORT_LOOKUP_CTRL(_i) (0x660 + (_i) * 0xc)
162#define QCA8K_PORT_LOOKUP_MEMBER GENMASK(6, 0)
Jonathan McDowell69462fe2020-08-01 18:06:46 +0100163#define QCA8K_PORT_LOOKUP_VLAN_MODE GENMASK(9, 8)
164#define QCA8K_PORT_LOOKUP_VLAN_MODE_NONE (0 << 8)
165#define QCA8K_PORT_LOOKUP_VLAN_MODE_FALLBACK (1 << 8)
166#define QCA8K_PORT_LOOKUP_VLAN_MODE_CHECK (2 << 8)
167#define QCA8K_PORT_LOOKUP_VLAN_MODE_SECURE (3 << 8)
John Crispin6b93fb42016-09-15 16:26:41 +0200168#define QCA8K_PORT_LOOKUP_STATE_MASK GENMASK(18, 16)
169#define QCA8K_PORT_LOOKUP_STATE_DISABLED (0 << 16)
170#define QCA8K_PORT_LOOKUP_STATE_BLOCKING (1 << 16)
171#define QCA8K_PORT_LOOKUP_STATE_LISTENING (2 << 16)
172#define QCA8K_PORT_LOOKUP_STATE_LEARNING (3 << 16)
173#define QCA8K_PORT_LOOKUP_STATE_FORWARD (4 << 16)
174#define QCA8K_PORT_LOOKUP_STATE GENMASK(18, 16)
175#define QCA8K_PORT_LOOKUP_LEARN BIT(20)
176
Ansuel Smith0fc57e42021-05-14 23:00:03 +0200177#define QCA8K_REG_GLOBAL_FC_THRESH 0x800
178#define QCA8K_GLOBAL_FC_GOL_XON_THRES(x) ((x) << 16)
179#define QCA8K_GLOBAL_FC_GOL_XON_THRES_S GENMASK(24, 16)
180#define QCA8K_GLOBAL_FC_GOL_XOFF_THRES(x) ((x) << 0)
181#define QCA8K_GLOBAL_FC_GOL_XOFF_THRES_S GENMASK(8, 0)
182
Ansuel Smith83a3ceb2021-05-14 23:00:01 +0200183#define QCA8K_REG_PORT_HOL_CTRL0(_i) (0x970 + (_i) * 0x8)
184#define QCA8K_PORT_HOL_CTRL0_EG_PRI0_BUF GENMASK(3, 0)
185#define QCA8K_PORT_HOL_CTRL0_EG_PRI0(x) ((x) << 0)
186#define QCA8K_PORT_HOL_CTRL0_EG_PRI1_BUF GENMASK(7, 4)
187#define QCA8K_PORT_HOL_CTRL0_EG_PRI1(x) ((x) << 4)
188#define QCA8K_PORT_HOL_CTRL0_EG_PRI2_BUF GENMASK(11, 8)
189#define QCA8K_PORT_HOL_CTRL0_EG_PRI2(x) ((x) << 8)
190#define QCA8K_PORT_HOL_CTRL0_EG_PRI3_BUF GENMASK(15, 12)
191#define QCA8K_PORT_HOL_CTRL0_EG_PRI3(x) ((x) << 12)
192#define QCA8K_PORT_HOL_CTRL0_EG_PRI4_BUF GENMASK(19, 16)
193#define QCA8K_PORT_HOL_CTRL0_EG_PRI4(x) ((x) << 16)
194#define QCA8K_PORT_HOL_CTRL0_EG_PRI5_BUF GENMASK(23, 20)
195#define QCA8K_PORT_HOL_CTRL0_EG_PRI5(x) ((x) << 20)
196#define QCA8K_PORT_HOL_CTRL0_EG_PORT_BUF GENMASK(29, 24)
197#define QCA8K_PORT_HOL_CTRL0_EG_PORT(x) ((x) << 24)
198
199#define QCA8K_REG_PORT_HOL_CTRL1(_i) (0x974 + (_i) * 0x8)
200#define QCA8K_PORT_HOL_CTRL1_ING_BUF GENMASK(3, 0)
201#define QCA8K_PORT_HOL_CTRL1_ING(x) ((x) << 0)
202#define QCA8K_PORT_HOL_CTRL1_EG_PRI_BUF_EN BIT(6)
203#define QCA8K_PORT_HOL_CTRL1_EG_PORT_BUF_EN BIT(7)
204#define QCA8K_PORT_HOL_CTRL1_WRED_EN BIT(8)
205#define QCA8K_PORT_HOL_CTRL1_EG_MIRROR_EN BIT(16)
206
John Crispin6b93fb42016-09-15 16:26:41 +0200207/* Pkt edit registers */
208#define QCA8K_EGRESS_VLAN(x) (0x0c70 + (4 * (x / 2)))
209
210/* L3 registers */
211#define QCA8K_HROUTER_CONTROL 0xe00
212#define QCA8K_HROUTER_CONTROL_GLB_LOCKTIME_M GENMASK(17, 16)
213#define QCA8K_HROUTER_CONTROL_GLB_LOCKTIME_S 16
214#define QCA8K_HROUTER_CONTROL_ARP_AGE_MODE 1
215#define QCA8K_HROUTER_PBASED_CONTROL1 0xe08
216#define QCA8K_HROUTER_PBASED_CONTROL2 0xe0c
217#define QCA8K_HNAT_CONTROL 0xe38
218
219/* MIB registers */
220#define QCA8K_PORT_MIB_COUNTER(_i) (0x1000 + (_i) * 0x100)
221
222/* QCA specific MII registers */
223#define MII_ATH_MMD_ADDR 0x0d
224#define MII_ATH_MMD_DATA 0x0e
225
226enum {
227 QCA8K_PORT_SPEED_10M = 0,
228 QCA8K_PORT_SPEED_100M = 1,
229 QCA8K_PORT_SPEED_1000M = 2,
230 QCA8K_PORT_SPEED_ERR = 3,
231};
232
233enum qca8k_fdb_cmd {
234 QCA8K_FDB_FLUSH = 1,
235 QCA8K_FDB_LOAD = 2,
236 QCA8K_FDB_PURGE = 3,
237 QCA8K_FDB_NEXT = 6,
238 QCA8K_FDB_SEARCH = 7,
239};
240
Jonathan McDowell69462fe2020-08-01 18:06:46 +0100241enum qca8k_vlan_cmd {
242 QCA8K_VLAN_FLUSH = 1,
243 QCA8K_VLAN_LOAD = 2,
244 QCA8K_VLAN_PURGE = 3,
245 QCA8K_VLAN_REMOVE_PORT = 4,
246 QCA8K_VLAN_NEXT = 5,
247 QCA8K_VLAN_READ = 6,
248};
249
John Crispin6b93fb42016-09-15 16:26:41 +0200250struct ar8xxx_port_status {
John Crispin6b93fb42016-09-15 16:26:41 +0200251 int enabled;
252};
253
Ansuel Smith6e82a452021-05-14 22:59:59 +0200254struct qca8k_match_data {
255 u8 id;
256};
257
John Crispin6b93fb42016-09-15 16:26:41 +0200258struct qca8k_priv {
Ansuel Smith83a3ceb2021-05-14 23:00:01 +0200259 u8 switch_id;
Ansuel Smith95ffeaf2021-05-14 23:00:04 +0200260 u8 switch_revision;
Ansuel Smithe4b99772021-05-14 23:00:06 +0200261 u8 rgmii_tx_delay;
262 u8 rgmii_rx_delay;
Ansuel Smith759bafb2021-05-14 23:00:10 +0200263 bool legacy_phy_port_mapping;
John Crispin6b93fb42016-09-15 16:26:41 +0200264 struct regmap *regmap;
265 struct mii_bus *bus;
266 struct ar8xxx_port_status port_sts[QCA8K_NUM_PORTS];
267 struct dsa_switch *ds;
268 struct mutex reg_mutex;
Michal Vokáč9bb22892018-05-23 08:20:22 +0200269 struct device *dev;
Christian Lamparterdb460c52019-03-22 01:05:03 +0100270 struct dsa_switch_ops ops;
Christian Lampartera653f2f2019-06-25 10:41:51 +0200271 struct gpio_desc *reset_gpio;
Jonathan McDowellf58d2592020-07-18 17:32:14 +0100272 unsigned int port_mtu[QCA8K_NUM_PORTS];
John Crispin6b93fb42016-09-15 16:26:41 +0200273};
274
275struct qca8k_mib_desc {
276 unsigned int size;
277 unsigned int offset;
278 const char *name;
279};
280
281struct qca8k_fdb {
282 u16 vid;
283 u8 port_mask;
284 u8 aging;
285 u8 mac[6];
286};
287
288#endif /* __QCA8K_H */