1 // SPDX-License-Identifier: GPL-2.0
3 * Lantiq / Intel GSWIP switch driver for VRX200 SoCs
5 * Copyright (C) 2010 Lantiq Deutschland
9 * The VLAN and bridge model the GSWIP hardware uses does not directly
10 * matches the model DSA uses.
12 * The hardware has 64 possible table entries for bridges with one VLAN
13 * ID, one flow id and a list of ports for each bridge. All entries which
14 * match the same flow ID are combined in the mac learning table, they
15 * act as one global bridge.
16 * The hardware does not support VLAN filter on the port, but on the
17 * bridge, this driver converts the DSA model to the hardware.
19 * The CPU gets all the exception frames which do not match any forwarding
20 * rule and the CPU port is also added to all bridges. This makes it possible
21 * to handle all the special cases easily in software.
22 * At the initialization the driver allocates one bridge table entry for
23 * each switch port which is used when the port is used without an
24 * explicit bridge. This prevents the frames from being forwarded
25 * between all LAN ports by default.
28 #include <linux/clk.h>
29 #include <linux/delay.h>
30 #include <linux/etherdevice.h>
31 #include <linux/firmware.h>
32 #include <linux/if_bridge.h>
33 #include <linux/if_vlan.h>
34 #include <linux/iopoll.h>
35 #include <linux/mfd/syscon.h>
36 #include <linux/module.h>
37 #include <linux/of_mdio.h>
38 #include <linux/of_net.h>
39 #include <linux/of_platform.h>
40 #include <linux/phy.h>
41 #include <linux/phylink.h>
42 #include <linux/platform_device.h>
43 #include <linux/regmap.h>
44 #include <linux/reset.h>
46 #include <dt-bindings/mips/lantiq_rcu_gphy.h>
48 #include "lantiq_pce.h"
50 /* GSWIP MDIO Registers */
51 #define GSWIP_MDIO_GLOB 0x00
52 #define GSWIP_MDIO_GLOB_ENABLE BIT(15)
53 #define GSWIP_MDIO_CTRL 0x08
54 #define GSWIP_MDIO_CTRL_BUSY BIT(12)
55 #define GSWIP_MDIO_CTRL_RD BIT(11)
56 #define GSWIP_MDIO_CTRL_WR BIT(10)
57 #define GSWIP_MDIO_CTRL_PHYAD_MASK 0x1f
58 #define GSWIP_MDIO_CTRL_PHYAD_SHIFT 5
59 #define GSWIP_MDIO_CTRL_REGAD_MASK 0x1f
60 #define GSWIP_MDIO_READ 0x09
61 #define GSWIP_MDIO_WRITE 0x0A
62 #define GSWIP_MDIO_MDC_CFG0 0x0B
63 #define GSWIP_MDIO_MDC_CFG1 0x0C
64 #define GSWIP_MDIO_PHYp(p) (0x15 - (p))
65 #define GSWIP_MDIO_PHY_LINK_MASK 0x6000
66 #define GSWIP_MDIO_PHY_LINK_AUTO 0x0000
67 #define GSWIP_MDIO_PHY_LINK_DOWN 0x4000
68 #define GSWIP_MDIO_PHY_LINK_UP 0x2000
69 #define GSWIP_MDIO_PHY_SPEED_MASK 0x1800
70 #define GSWIP_MDIO_PHY_SPEED_AUTO 0x1800
71 #define GSWIP_MDIO_PHY_SPEED_M10 0x0000
72 #define GSWIP_MDIO_PHY_SPEED_M100 0x0800
73 #define GSWIP_MDIO_PHY_SPEED_G1 0x1000
74 #define GSWIP_MDIO_PHY_FDUP_MASK 0x0600
75 #define GSWIP_MDIO_PHY_FDUP_AUTO 0x0000
76 #define GSWIP_MDIO_PHY_FDUP_EN 0x0200
77 #define GSWIP_MDIO_PHY_FDUP_DIS 0x0600
78 #define GSWIP_MDIO_PHY_FCONTX_MASK 0x0180
79 #define GSWIP_MDIO_PHY_FCONTX_AUTO 0x0000
80 #define GSWIP_MDIO_PHY_FCONTX_EN 0x0100
81 #define GSWIP_MDIO_PHY_FCONTX_DIS 0x0180
82 #define GSWIP_MDIO_PHY_FCONRX_MASK 0x0060
83 #define GSWIP_MDIO_PHY_FCONRX_AUTO 0x0000
84 #define GSWIP_MDIO_PHY_FCONRX_EN 0x0020
85 #define GSWIP_MDIO_PHY_FCONRX_DIS 0x0060
86 #define GSWIP_MDIO_PHY_ADDR_MASK 0x001f
87 #define GSWIP_MDIO_PHY_MASK (GSWIP_MDIO_PHY_ADDR_MASK | \
88 GSWIP_MDIO_PHY_FCONRX_MASK | \
89 GSWIP_MDIO_PHY_FCONTX_MASK | \
90 GSWIP_MDIO_PHY_LINK_MASK | \
91 GSWIP_MDIO_PHY_SPEED_MASK | \
92 GSWIP_MDIO_PHY_FDUP_MASK)
94 /* GSWIP MII Registers */
95 #define GSWIP_MII_CFG0 0x00
96 #define GSWIP_MII_CFG1 0x02
97 #define GSWIP_MII_CFG5 0x04
98 #define GSWIP_MII_CFG_EN BIT(14)
99 #define GSWIP_MII_CFG_LDCLKDIS BIT(12)
100 #define GSWIP_MII_CFG_MODE_MIIP 0x0
101 #define GSWIP_MII_CFG_MODE_MIIM 0x1
102 #define GSWIP_MII_CFG_MODE_RMIIP 0x2
103 #define GSWIP_MII_CFG_MODE_RMIIM 0x3
104 #define GSWIP_MII_CFG_MODE_RGMII 0x4
105 #define GSWIP_MII_CFG_MODE_MASK 0xf
106 #define GSWIP_MII_CFG_RATE_M2P5 0x00
107 #define GSWIP_MII_CFG_RATE_M25 0x10
108 #define GSWIP_MII_CFG_RATE_M125 0x20
109 #define GSWIP_MII_CFG_RATE_M50 0x30
110 #define GSWIP_MII_CFG_RATE_AUTO 0x40
111 #define GSWIP_MII_CFG_RATE_MASK 0x70
112 #define GSWIP_MII_PCDU0 0x01
113 #define GSWIP_MII_PCDU1 0x03
114 #define GSWIP_MII_PCDU5 0x05
115 #define GSWIP_MII_PCDU_TXDLY_MASK GENMASK(2, 0)
116 #define GSWIP_MII_PCDU_RXDLY_MASK GENMASK(9, 7)
118 /* GSWIP Core Registers */
119 #define GSWIP_SWRES 0x000
120 #define GSWIP_SWRES_R1 BIT(1) /* GSWIP Software reset */
121 #define GSWIP_SWRES_R0 BIT(0) /* GSWIP Hardware reset */
122 #define GSWIP_VERSION 0x013
123 #define GSWIP_VERSION_REV_SHIFT 0
124 #define GSWIP_VERSION_REV_MASK GENMASK(7, 0)
125 #define GSWIP_VERSION_MOD_SHIFT 8
126 #define GSWIP_VERSION_MOD_MASK GENMASK(15, 8)
127 #define GSWIP_VERSION_2_0 0x100
128 #define GSWIP_VERSION_2_1 0x021
129 #define GSWIP_VERSION_2_2 0x122
130 #define GSWIP_VERSION_2_2_ETC 0x022
132 #define GSWIP_BM_RAM_VAL(x) (0x043 - (x))
133 #define GSWIP_BM_RAM_ADDR 0x044
134 #define GSWIP_BM_RAM_CTRL 0x045
135 #define GSWIP_BM_RAM_CTRL_BAS BIT(15)
136 #define GSWIP_BM_RAM_CTRL_OPMOD BIT(5)
137 #define GSWIP_BM_RAM_CTRL_ADDR_MASK GENMASK(4, 0)
138 #define GSWIP_BM_QUEUE_GCTRL 0x04A
139 #define GSWIP_BM_QUEUE_GCTRL_GL_MOD BIT(10)
140 /* buffer management Port Configuration Register */
141 #define GSWIP_BM_PCFGp(p) (0x080 + ((p) * 2))
142 #define GSWIP_BM_PCFG_CNTEN BIT(0) /* RMON Counter Enable */
143 #define GSWIP_BM_PCFG_IGCNT BIT(1) /* Ingres Special Tag RMON count */
144 /* buffer management Port Control Register */
145 #define GSWIP_BM_RMON_CTRLp(p) (0x81 + ((p) * 2))
146 #define GSWIP_BM_CTRL_RMON_RAM1_RES BIT(0) /* Software Reset for RMON RAM 1 */
147 #define GSWIP_BM_CTRL_RMON_RAM2_RES BIT(1) /* Software Reset for RMON RAM 2 */
150 #define GSWIP_PCE_TBL_KEY(x) (0x447 - (x))
151 #define GSWIP_PCE_TBL_MASK 0x448
152 #define GSWIP_PCE_TBL_VAL(x) (0x44D - (x))
153 #define GSWIP_PCE_TBL_ADDR 0x44E
154 #define GSWIP_PCE_TBL_CTRL 0x44F
155 #define GSWIP_PCE_TBL_CTRL_BAS BIT(15)
156 #define GSWIP_PCE_TBL_CTRL_TYPE BIT(13)
157 #define GSWIP_PCE_TBL_CTRL_VLD BIT(12)
158 #define GSWIP_PCE_TBL_CTRL_KEYFORM BIT(11)
159 #define GSWIP_PCE_TBL_CTRL_GMAP_MASK GENMASK(10, 7)
160 #define GSWIP_PCE_TBL_CTRL_OPMOD_MASK GENMASK(6, 5)
161 #define GSWIP_PCE_TBL_CTRL_OPMOD_ADRD 0x00
162 #define GSWIP_PCE_TBL_CTRL_OPMOD_ADWR 0x20
163 #define GSWIP_PCE_TBL_CTRL_OPMOD_KSRD 0x40
164 #define GSWIP_PCE_TBL_CTRL_OPMOD_KSWR 0x60
165 #define GSWIP_PCE_TBL_CTRL_ADDR_MASK GENMASK(4, 0)
166 #define GSWIP_PCE_PMAP1 0x453 /* Monitoring port map */
167 #define GSWIP_PCE_PMAP2 0x454 /* Default Multicast port map */
168 #define GSWIP_PCE_PMAP3 0x455 /* Default Unknown Unicast port map */
169 #define GSWIP_PCE_GCTRL_0 0x456
170 #define GSWIP_PCE_GCTRL_0_MTFL BIT(0) /* MAC Table Flushing */
171 #define GSWIP_PCE_GCTRL_0_MC_VALID BIT(3)
172 #define GSWIP_PCE_GCTRL_0_VLAN BIT(14) /* VLAN aware Switching */
173 #define GSWIP_PCE_GCTRL_1 0x457
174 #define GSWIP_PCE_GCTRL_1_MAC_GLOCK BIT(2) /* MAC Address table lock */
175 #define GSWIP_PCE_GCTRL_1_MAC_GLOCK_MOD BIT(3) /* Mac address table lock forwarding mode */
176 #define GSWIP_PCE_PCTRL_0p(p) (0x480 + ((p) * 0xA))
177 #define GSWIP_PCE_PCTRL_0_TVM BIT(5) /* Transparent VLAN mode */
178 #define GSWIP_PCE_PCTRL_0_VREP BIT(6) /* VLAN Replace Mode */
179 #define GSWIP_PCE_PCTRL_0_INGRESS BIT(11) /* Accept special tag in ingress */
180 #define GSWIP_PCE_PCTRL_0_PSTATE_LISTEN 0x0
181 #define GSWIP_PCE_PCTRL_0_PSTATE_RX 0x1
182 #define GSWIP_PCE_PCTRL_0_PSTATE_TX 0x2
183 #define GSWIP_PCE_PCTRL_0_PSTATE_LEARNING 0x3
184 #define GSWIP_PCE_PCTRL_0_PSTATE_FORWARDING 0x7
185 #define GSWIP_PCE_PCTRL_0_PSTATE_MASK GENMASK(2, 0)
186 #define GSWIP_PCE_VCTRL(p) (0x485 + ((p) * 0xA))
187 #define GSWIP_PCE_VCTRL_UVR BIT(0) /* Unknown VLAN Rule */
188 #define GSWIP_PCE_VCTRL_VIMR BIT(3) /* VLAN Ingress Member violation rule */
189 #define GSWIP_PCE_VCTRL_VEMR BIT(4) /* VLAN Egress Member violation rule */
190 #define GSWIP_PCE_VCTRL_VSR BIT(5) /* VLAN Security */
191 #define GSWIP_PCE_VCTRL_VID0 BIT(6) /* Priority Tagged Rule */
192 #define GSWIP_PCE_DEFPVID(p) (0x486 + ((p) * 0xA))
194 #define GSWIP_MAC_FLEN 0x8C5
195 #define GSWIP_MAC_CTRL_2p(p) (0x905 + ((p) * 0xC))
196 #define GSWIP_MAC_CTRL_2_MLEN BIT(3) /* Maximum Untagged Frame Lnegth */
198 /* Ethernet Switch Fetch DMA Port Control Register */
199 #define GSWIP_FDMA_PCTRLp(p) (0xA80 + ((p) * 0x6))
200 #define GSWIP_FDMA_PCTRL_EN BIT(0) /* FDMA Port Enable */
201 #define GSWIP_FDMA_PCTRL_STEN BIT(1) /* Special Tag Insertion Enable */
202 #define GSWIP_FDMA_PCTRL_VLANMOD_MASK GENMASK(4, 3) /* VLAN Modification Control */
203 #define GSWIP_FDMA_PCTRL_VLANMOD_SHIFT 3 /* VLAN Modification Control */
204 #define GSWIP_FDMA_PCTRL_VLANMOD_DIS (0x0 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT)
205 #define GSWIP_FDMA_PCTRL_VLANMOD_PRIO (0x1 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT)
206 #define GSWIP_FDMA_PCTRL_VLANMOD_ID (0x2 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT)
207 #define GSWIP_FDMA_PCTRL_VLANMOD_BOTH (0x3 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT)
209 /* Ethernet Switch Store DMA Port Control Register */
210 #define GSWIP_SDMA_PCTRLp(p) (0xBC0 + ((p) * 0x6))
211 #define GSWIP_SDMA_PCTRL_EN BIT(0) /* SDMA Port Enable */
212 #define GSWIP_SDMA_PCTRL_FCEN BIT(1) /* Flow Control Enable */
213 #define GSWIP_SDMA_PCTRL_PAUFWD BIT(1) /* Pause Frame Forwarding */
215 #define GSWIP_TABLE_ACTIVE_VLAN 0x01
216 #define GSWIP_TABLE_VLAN_MAPPING 0x02
217 #define GSWIP_TABLE_MAC_BRIDGE 0x0b
218 #define GSWIP_TABLE_MAC_BRIDGE_STATIC 0x01 /* Static not, aging entry */
220 #define XRX200_GPHY_FW_ALIGN (16 * 1024)
222 struct gswip_hw_info {
227 struct xway_gphy_match_data {
228 char *fe_firmware_name;
229 char *ge_firmware_name;
232 struct gswip_gphy_fw {
233 struct clk *clk_gate;
234 struct reset_control *reset;
240 struct net_device *bridge;
249 const struct gswip_hw_info *hw_info;
250 const struct xway_gphy_match_data *gphy_fw_name_cfg;
251 struct dsa_switch *ds;
253 struct regmap *rcu_regmap;
254 struct gswip_vlan vlans[64];
256 struct gswip_gphy_fw *gphy_fw;
257 u32 port_vlan_filter;
260 struct gswip_pce_table_entry {
261 u16 index; // PCE_TBL_ADDR.ADDR = pData->table_index
262 u16 table; // PCE_TBL_CTRL.ADDR = pData->table
272 struct gswip_rmon_cnt_desc {
278 #define MIB_DESC(_size, _offset, _name) {.size = _size, .offset = _offset, .name = _name}
280 static const struct gswip_rmon_cnt_desc gswip_rmon_cnt[] = {
281 /** Receive Packet Count (only packets that are accepted and not discarded). */
282 MIB_DESC(1, 0x1F, "RxGoodPkts"),
283 MIB_DESC(1, 0x23, "RxUnicastPkts"),
284 MIB_DESC(1, 0x22, "RxMulticastPkts"),
285 MIB_DESC(1, 0x21, "RxFCSErrorPkts"),
286 MIB_DESC(1, 0x1D, "RxUnderSizeGoodPkts"),
287 MIB_DESC(1, 0x1E, "RxUnderSizeErrorPkts"),
288 MIB_DESC(1, 0x1B, "RxOversizeGoodPkts"),
289 MIB_DESC(1, 0x1C, "RxOversizeErrorPkts"),
290 MIB_DESC(1, 0x20, "RxGoodPausePkts"),
291 MIB_DESC(1, 0x1A, "RxAlignErrorPkts"),
292 MIB_DESC(1, 0x12, "Rx64BytePkts"),
293 MIB_DESC(1, 0x13, "Rx127BytePkts"),
294 MIB_DESC(1, 0x14, "Rx255BytePkts"),
295 MIB_DESC(1, 0x15, "Rx511BytePkts"),
296 MIB_DESC(1, 0x16, "Rx1023BytePkts"),
297 /** Receive Size 1024-1522 (or more, if configured) Packet Count. */
298 MIB_DESC(1, 0x17, "RxMaxBytePkts"),
299 MIB_DESC(1, 0x18, "RxDroppedPkts"),
300 MIB_DESC(1, 0x19, "RxFilteredPkts"),
301 MIB_DESC(2, 0x24, "RxGoodBytes"),
302 MIB_DESC(2, 0x26, "RxBadBytes"),
303 MIB_DESC(1, 0x11, "TxAcmDroppedPkts"),
304 MIB_DESC(1, 0x0C, "TxGoodPkts"),
305 MIB_DESC(1, 0x06, "TxUnicastPkts"),
306 MIB_DESC(1, 0x07, "TxMulticastPkts"),
307 MIB_DESC(1, 0x00, "Tx64BytePkts"),
308 MIB_DESC(1, 0x01, "Tx127BytePkts"),
309 MIB_DESC(1, 0x02, "Tx255BytePkts"),
310 MIB_DESC(1, 0x03, "Tx511BytePkts"),
311 MIB_DESC(1, 0x04, "Tx1023BytePkts"),
312 /** Transmit Size 1024-1522 (or more, if configured) Packet Count. */
313 MIB_DESC(1, 0x05, "TxMaxBytePkts"),
314 MIB_DESC(1, 0x08, "TxSingleCollCount"),
315 MIB_DESC(1, 0x09, "TxMultCollCount"),
316 MIB_DESC(1, 0x0A, "TxLateCollCount"),
317 MIB_DESC(1, 0x0B, "TxExcessCollCount"),
318 MIB_DESC(1, 0x0D, "TxPauseCount"),
319 MIB_DESC(1, 0x10, "TxDroppedPkts"),
320 MIB_DESC(2, 0x0E, "TxGoodBytes"),
323 static u32 gswip_switch_r(struct gswip_priv *priv, u32 offset)
325 return __raw_readl(priv->gswip + (offset * 4));
328 static void gswip_switch_w(struct gswip_priv *priv, u32 val, u32 offset)
330 __raw_writel(val, priv->gswip + (offset * 4));
333 static void gswip_switch_mask(struct gswip_priv *priv, u32 clear, u32 set,
336 u32 val = gswip_switch_r(priv, offset);
340 gswip_switch_w(priv, val, offset);
343 static u32 gswip_switch_r_timeout(struct gswip_priv *priv, u32 offset,
348 return readx_poll_timeout(__raw_readl, priv->gswip + (offset * 4), val,
349 (val & cleared) == 0, 20, 50000);
352 static u32 gswip_mdio_r(struct gswip_priv *priv, u32 offset)
354 return __raw_readl(priv->mdio + (offset * 4));
357 static void gswip_mdio_w(struct gswip_priv *priv, u32 val, u32 offset)
359 __raw_writel(val, priv->mdio + (offset * 4));
362 static void gswip_mdio_mask(struct gswip_priv *priv, u32 clear, u32 set,
365 u32 val = gswip_mdio_r(priv, offset);
369 gswip_mdio_w(priv, val, offset);
372 static u32 gswip_mii_r(struct gswip_priv *priv, u32 offset)
374 return __raw_readl(priv->mii + (offset * 4));
377 static void gswip_mii_w(struct gswip_priv *priv, u32 val, u32 offset)
379 __raw_writel(val, priv->mii + (offset * 4));
382 static void gswip_mii_mask(struct gswip_priv *priv, u32 clear, u32 set,
385 u32 val = gswip_mii_r(priv, offset);
389 gswip_mii_w(priv, val, offset);
392 static void gswip_mii_mask_cfg(struct gswip_priv *priv, u32 clear, u32 set,
397 gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG0);
400 gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG1);
403 gswip_mii_mask(priv, clear, set, GSWIP_MII_CFG5);
408 static void gswip_mii_mask_pcdu(struct gswip_priv *priv, u32 clear, u32 set,
413 gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU0);
416 gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU1);
419 gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU5);
424 static int gswip_mdio_poll(struct gswip_priv *priv)
428 while (likely(cnt--)) {
429 u32 ctrl = gswip_mdio_r(priv, GSWIP_MDIO_CTRL);
431 if ((ctrl & GSWIP_MDIO_CTRL_BUSY) == 0)
433 usleep_range(20, 40);
439 static int gswip_mdio_wr(struct mii_bus *bus, int addr, int reg, u16 val)
441 struct gswip_priv *priv = bus->priv;
444 err = gswip_mdio_poll(priv);
446 dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n");
450 gswip_mdio_w(priv, val, GSWIP_MDIO_WRITE);
451 gswip_mdio_w(priv, GSWIP_MDIO_CTRL_BUSY | GSWIP_MDIO_CTRL_WR |
452 ((addr & GSWIP_MDIO_CTRL_PHYAD_MASK) << GSWIP_MDIO_CTRL_PHYAD_SHIFT) |
453 (reg & GSWIP_MDIO_CTRL_REGAD_MASK),
459 static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg)
461 struct gswip_priv *priv = bus->priv;
464 err = gswip_mdio_poll(priv);
466 dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n");
470 gswip_mdio_w(priv, GSWIP_MDIO_CTRL_BUSY | GSWIP_MDIO_CTRL_RD |
471 ((addr & GSWIP_MDIO_CTRL_PHYAD_MASK) << GSWIP_MDIO_CTRL_PHYAD_SHIFT) |
472 (reg & GSWIP_MDIO_CTRL_REGAD_MASK),
475 err = gswip_mdio_poll(priv);
477 dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n");
481 return gswip_mdio_r(priv, GSWIP_MDIO_READ);
484 static int gswip_mdio(struct gswip_priv *priv, struct device_node *mdio_np)
486 struct dsa_switch *ds = priv->ds;
488 ds->slave_mii_bus = devm_mdiobus_alloc(priv->dev);
489 if (!ds->slave_mii_bus)
492 ds->slave_mii_bus->priv = priv;
493 ds->slave_mii_bus->read = gswip_mdio_rd;
494 ds->slave_mii_bus->write = gswip_mdio_wr;
495 ds->slave_mii_bus->name = "lantiq,xrx200-mdio";
496 snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "%s-mii",
497 dev_name(priv->dev));
498 ds->slave_mii_bus->parent = priv->dev;
499 ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask;
501 return of_mdiobus_register(ds->slave_mii_bus, mdio_np);
504 static int gswip_pce_table_entry_read(struct gswip_priv *priv,
505 struct gswip_pce_table_entry *tbl)
510 u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSRD :
511 GSWIP_PCE_TBL_CTRL_OPMOD_ADRD;
513 err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
514 GSWIP_PCE_TBL_CTRL_BAS);
518 gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR);
519 gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK |
520 GSWIP_PCE_TBL_CTRL_OPMOD_MASK,
521 tbl->table | addr_mode | GSWIP_PCE_TBL_CTRL_BAS,
524 err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
525 GSWIP_PCE_TBL_CTRL_BAS);
529 for (i = 0; i < ARRAY_SIZE(tbl->key); i++)
530 tbl->key[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_KEY(i));
532 for (i = 0; i < ARRAY_SIZE(tbl->val); i++)
533 tbl->val[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_VAL(i));
535 tbl->mask = gswip_switch_r(priv, GSWIP_PCE_TBL_MASK);
537 crtl = gswip_switch_r(priv, GSWIP_PCE_TBL_CTRL);
539 tbl->type = !!(crtl & GSWIP_PCE_TBL_CTRL_TYPE);
540 tbl->valid = !!(crtl & GSWIP_PCE_TBL_CTRL_VLD);
541 tbl->gmap = (crtl & GSWIP_PCE_TBL_CTRL_GMAP_MASK) >> 7;
546 static int gswip_pce_table_entry_write(struct gswip_priv *priv,
547 struct gswip_pce_table_entry *tbl)
552 u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSWR :
553 GSWIP_PCE_TBL_CTRL_OPMOD_ADWR;
555 err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
556 GSWIP_PCE_TBL_CTRL_BAS);
560 gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR);
561 gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK |
562 GSWIP_PCE_TBL_CTRL_OPMOD_MASK,
563 tbl->table | addr_mode,
566 for (i = 0; i < ARRAY_SIZE(tbl->key); i++)
567 gswip_switch_w(priv, tbl->key[i], GSWIP_PCE_TBL_KEY(i));
569 for (i = 0; i < ARRAY_SIZE(tbl->val); i++)
570 gswip_switch_w(priv, tbl->val[i], GSWIP_PCE_TBL_VAL(i));
572 gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK |
573 GSWIP_PCE_TBL_CTRL_OPMOD_MASK,
574 tbl->table | addr_mode,
577 gswip_switch_w(priv, tbl->mask, GSWIP_PCE_TBL_MASK);
579 crtl = gswip_switch_r(priv, GSWIP_PCE_TBL_CTRL);
580 crtl &= ~(GSWIP_PCE_TBL_CTRL_TYPE | GSWIP_PCE_TBL_CTRL_VLD |
581 GSWIP_PCE_TBL_CTRL_GMAP_MASK);
583 crtl |= GSWIP_PCE_TBL_CTRL_TYPE;
585 crtl |= GSWIP_PCE_TBL_CTRL_VLD;
586 crtl |= (tbl->gmap << 7) & GSWIP_PCE_TBL_CTRL_GMAP_MASK;
587 crtl |= GSWIP_PCE_TBL_CTRL_BAS;
588 gswip_switch_w(priv, crtl, GSWIP_PCE_TBL_CTRL);
590 return gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
591 GSWIP_PCE_TBL_CTRL_BAS);
594 /* Add the LAN port into a bridge with the CPU port by
595 * default. This prevents automatic forwarding of
596 * packages between the LAN ports when no explicit
597 * bridge is configured.
599 static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add)
601 struct gswip_pce_table_entry vlan_active = {0,};
602 struct gswip_pce_table_entry vlan_mapping = {0,};
603 unsigned int cpu_port = priv->hw_info->cpu_port;
604 unsigned int max_ports = priv->hw_info->max_ports;
607 if (port >= max_ports) {
608 dev_err(priv->dev, "single port for %i supported\n", port);
612 vlan_active.index = port + 1;
613 vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN;
614 vlan_active.key[0] = 0; /* vid */
615 vlan_active.val[0] = port + 1 /* fid */;
616 vlan_active.valid = add;
617 err = gswip_pce_table_entry_write(priv, &vlan_active);
619 dev_err(priv->dev, "failed to write active VLAN: %d\n", err);
626 vlan_mapping.index = port + 1;
627 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
628 vlan_mapping.val[0] = 0 /* vid */;
629 vlan_mapping.val[1] = BIT(port) | BIT(cpu_port);
630 vlan_mapping.val[2] = 0;
631 err = gswip_pce_table_entry_write(priv, &vlan_mapping);
633 dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
640 static int gswip_port_enable(struct dsa_switch *ds, int port,
641 struct phy_device *phydev)
643 struct gswip_priv *priv = ds->priv;
646 if (!dsa_is_user_port(ds, port))
649 if (!dsa_is_cpu_port(ds, port)) {
650 err = gswip_add_single_port_br(priv, port, true);
655 /* RMON Counter Enable for port */
656 gswip_switch_w(priv, GSWIP_BM_PCFG_CNTEN, GSWIP_BM_PCFGp(port));
658 /* enable port fetch/store dma & VLAN Modification */
659 gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_EN |
660 GSWIP_FDMA_PCTRL_VLANMOD_BOTH,
661 GSWIP_FDMA_PCTRLp(port));
662 gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN,
663 GSWIP_SDMA_PCTRLp(port));
665 if (!dsa_is_cpu_port(ds, port)) {
666 u32 macconf = GSWIP_MDIO_PHY_LINK_AUTO |
667 GSWIP_MDIO_PHY_SPEED_AUTO |
668 GSWIP_MDIO_PHY_FDUP_AUTO |
669 GSWIP_MDIO_PHY_FCONTX_AUTO |
670 GSWIP_MDIO_PHY_FCONRX_AUTO |
671 (phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK);
673 gswip_mdio_w(priv, macconf, GSWIP_MDIO_PHYp(port));
674 /* Activate MDIO auto polling */
675 gswip_mdio_mask(priv, 0, BIT(port), GSWIP_MDIO_MDC_CFG0);
681 static void gswip_port_disable(struct dsa_switch *ds, int port)
683 struct gswip_priv *priv = ds->priv;
685 if (!dsa_is_user_port(ds, port))
688 if (!dsa_is_cpu_port(ds, port)) {
689 gswip_mdio_mask(priv, GSWIP_MDIO_PHY_LINK_DOWN,
690 GSWIP_MDIO_PHY_LINK_MASK,
691 GSWIP_MDIO_PHYp(port));
692 /* Deactivate MDIO auto polling */
693 gswip_mdio_mask(priv, BIT(port), 0, GSWIP_MDIO_MDC_CFG0);
696 gswip_switch_mask(priv, GSWIP_FDMA_PCTRL_EN, 0,
697 GSWIP_FDMA_PCTRLp(port));
698 gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0,
699 GSWIP_SDMA_PCTRLp(port));
702 static int gswip_pce_load_microcode(struct gswip_priv *priv)
707 gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK |
708 GSWIP_PCE_TBL_CTRL_OPMOD_MASK,
709 GSWIP_PCE_TBL_CTRL_OPMOD_ADWR, GSWIP_PCE_TBL_CTRL);
710 gswip_switch_w(priv, 0, GSWIP_PCE_TBL_MASK);
712 for (i = 0; i < ARRAY_SIZE(gswip_pce_microcode); i++) {
713 gswip_switch_w(priv, i, GSWIP_PCE_TBL_ADDR);
714 gswip_switch_w(priv, gswip_pce_microcode[i].val_0,
715 GSWIP_PCE_TBL_VAL(0));
716 gswip_switch_w(priv, gswip_pce_microcode[i].val_1,
717 GSWIP_PCE_TBL_VAL(1));
718 gswip_switch_w(priv, gswip_pce_microcode[i].val_2,
719 GSWIP_PCE_TBL_VAL(2));
720 gswip_switch_w(priv, gswip_pce_microcode[i].val_3,
721 GSWIP_PCE_TBL_VAL(3));
723 /* start the table access: */
724 gswip_switch_mask(priv, 0, GSWIP_PCE_TBL_CTRL_BAS,
726 err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
727 GSWIP_PCE_TBL_CTRL_BAS);
732 /* tell the switch that the microcode is loaded */
733 gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_MC_VALID,
739 static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port,
741 struct switchdev_trans *trans)
743 struct gswip_priv *priv = ds->priv;
745 /* Do not allow changing the VLAN filtering options while in bridge */
746 if (switchdev_trans_ph_prepare(trans)) {
747 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
752 if (!!(priv->port_vlan_filter & BIT(port)) != vlan_filtering)
758 if (vlan_filtering) {
759 /* Use port based VLAN tag */
760 gswip_switch_mask(priv,
762 GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR |
763 GSWIP_PCE_VCTRL_VEMR,
764 GSWIP_PCE_VCTRL(port));
765 gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_TVM, 0,
766 GSWIP_PCE_PCTRL_0p(port));
768 /* Use port based VLAN tag */
769 gswip_switch_mask(priv,
770 GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR |
771 GSWIP_PCE_VCTRL_VEMR,
773 GSWIP_PCE_VCTRL(port));
774 gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_TVM,
775 GSWIP_PCE_PCTRL_0p(port));
781 static int gswip_setup(struct dsa_switch *ds)
783 struct gswip_priv *priv = ds->priv;
784 unsigned int cpu_port = priv->hw_info->cpu_port;
788 gswip_switch_w(priv, GSWIP_SWRES_R0, GSWIP_SWRES);
789 usleep_range(5000, 10000);
790 gswip_switch_w(priv, 0, GSWIP_SWRES);
792 /* disable port fetch/store dma on all ports */
793 for (i = 0; i < priv->hw_info->max_ports; i++) {
794 struct switchdev_trans trans;
796 /* Skip the prepare phase, this shouldn't return an error
799 trans.ph_prepare = false;
801 gswip_port_disable(ds, i);
802 gswip_port_vlan_filtering(ds, i, false, &trans);
806 gswip_mdio_mask(priv, 0, GSWIP_MDIO_GLOB_ENABLE, GSWIP_MDIO_GLOB);
808 err = gswip_pce_load_microcode(priv);
810 dev_err(priv->dev, "writing PCE microcode failed, %i", err);
814 /* Default unknown Broadcast/Multicast/Unicast port maps */
815 gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP1);
816 gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP2);
817 gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP3);
819 /* disable PHY auto polling */
820 gswip_mdio_w(priv, 0x0, GSWIP_MDIO_MDC_CFG0);
821 /* Configure the MDIO Clock 2.5 MHz */
822 gswip_mdio_mask(priv, 0xff, 0x09, GSWIP_MDIO_MDC_CFG1);
824 /* Disable the xMII link */
825 gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, 0);
826 gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, 1);
827 gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, 5);
829 /* enable special tag insertion on cpu port */
830 gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_STEN,
831 GSWIP_FDMA_PCTRLp(cpu_port));
833 /* accept special tag in ingress direction */
834 gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_INGRESS,
835 GSWIP_PCE_PCTRL_0p(cpu_port));
837 gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN,
838 GSWIP_MAC_CTRL_2p(cpu_port));
839 gswip_switch_w(priv, VLAN_ETH_FRAME_LEN + 8, GSWIP_MAC_FLEN);
840 gswip_switch_mask(priv, 0, GSWIP_BM_QUEUE_GCTRL_GL_MOD,
841 GSWIP_BM_QUEUE_GCTRL);
843 /* VLAN aware Switching */
844 gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_VLAN, GSWIP_PCE_GCTRL_0);
846 /* Flush MAC Table */
847 gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_MTFL, GSWIP_PCE_GCTRL_0);
849 err = gswip_switch_r_timeout(priv, GSWIP_PCE_GCTRL_0,
850 GSWIP_PCE_GCTRL_0_MTFL);
852 dev_err(priv->dev, "MAC flushing didn't finish\n");
856 gswip_port_enable(ds, cpu_port, NULL);
860 static enum dsa_tag_protocol gswip_get_tag_protocol(struct dsa_switch *ds,
862 enum dsa_tag_protocol mp)
864 return DSA_TAG_PROTO_GSWIP;
867 static int gswip_vlan_active_create(struct gswip_priv *priv,
868 struct net_device *bridge,
871 struct gswip_pce_table_entry vlan_active = {0,};
872 unsigned int max_ports = priv->hw_info->max_ports;
877 /* Look for a free slot */
878 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
879 if (!priv->vlans[i].bridge) {
891 vlan_active.index = idx;
892 vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN;
893 vlan_active.key[0] = vid;
894 vlan_active.val[0] = fid;
895 vlan_active.valid = true;
897 err = gswip_pce_table_entry_write(priv, &vlan_active);
899 dev_err(priv->dev, "failed to write active VLAN: %d\n", err);
903 priv->vlans[idx].bridge = bridge;
904 priv->vlans[idx].vid = vid;
905 priv->vlans[idx].fid = fid;
910 static int gswip_vlan_active_remove(struct gswip_priv *priv, int idx)
912 struct gswip_pce_table_entry vlan_active = {0,};
915 vlan_active.index = idx;
916 vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN;
917 vlan_active.valid = false;
918 err = gswip_pce_table_entry_write(priv, &vlan_active);
920 dev_err(priv->dev, "failed to delete active VLAN: %d\n", err);
921 priv->vlans[idx].bridge = NULL;
926 static int gswip_vlan_add_unaware(struct gswip_priv *priv,
927 struct net_device *bridge, int port)
929 struct gswip_pce_table_entry vlan_mapping = {0,};
930 unsigned int max_ports = priv->hw_info->max_ports;
931 unsigned int cpu_port = priv->hw_info->cpu_port;
932 bool active_vlan_created = false;
937 /* Check if there is already a page for this bridge */
938 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
939 if (priv->vlans[i].bridge == bridge) {
945 /* If this bridge is not programmed yet, add a Active VLAN table
946 * entry in a free slot and prepare the VLAN mapping table entry.
949 idx = gswip_vlan_active_create(priv, bridge, -1, 0);
952 active_vlan_created = true;
954 vlan_mapping.index = idx;
955 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
956 /* VLAN ID byte, maps to the VLAN ID of vlan active table */
957 vlan_mapping.val[0] = 0;
959 /* Read the existing VLAN mapping entry from the switch */
960 vlan_mapping.index = idx;
961 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
962 err = gswip_pce_table_entry_read(priv, &vlan_mapping);
964 dev_err(priv->dev, "failed to read VLAN mapping: %d\n",
970 /* Update the VLAN mapping entry and write it to the switch */
971 vlan_mapping.val[1] |= BIT(cpu_port);
972 vlan_mapping.val[1] |= BIT(port);
973 err = gswip_pce_table_entry_write(priv, &vlan_mapping);
975 dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
976 /* In case an Active VLAN was creaetd delete it again */
977 if (active_vlan_created)
978 gswip_vlan_active_remove(priv, idx);
982 gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port));
986 static int gswip_vlan_add_aware(struct gswip_priv *priv,
987 struct net_device *bridge, int port,
988 u16 vid, bool untagged,
991 struct gswip_pce_table_entry vlan_mapping = {0,};
992 unsigned int max_ports = priv->hw_info->max_ports;
993 unsigned int cpu_port = priv->hw_info->cpu_port;
994 bool active_vlan_created = false;
1000 /* Check if there is already a page for this bridge */
1001 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
1002 if (priv->vlans[i].bridge == bridge) {
1003 if (fid != -1 && fid != priv->vlans[i].fid)
1004 dev_err(priv->dev, "one bridge with multiple flow ids\n");
1005 fid = priv->vlans[i].fid;
1006 if (priv->vlans[i].vid == vid) {
1013 /* If this bridge is not programmed yet, add a Active VLAN table
1014 * entry in a free slot and prepare the VLAN mapping table entry.
1017 idx = gswip_vlan_active_create(priv, bridge, fid, vid);
1020 active_vlan_created = true;
1022 vlan_mapping.index = idx;
1023 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
1024 /* VLAN ID byte, maps to the VLAN ID of vlan active table */
1025 vlan_mapping.val[0] = vid;
1027 /* Read the existing VLAN mapping entry from the switch */
1028 vlan_mapping.index = idx;
1029 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
1030 err = gswip_pce_table_entry_read(priv, &vlan_mapping);
1032 dev_err(priv->dev, "failed to read VLAN mapping: %d\n",
1038 vlan_mapping.val[0] = vid;
1039 /* Update the VLAN mapping entry and write it to the switch */
1040 vlan_mapping.val[1] |= BIT(cpu_port);
1041 vlan_mapping.val[2] |= BIT(cpu_port);
1042 vlan_mapping.val[1] |= BIT(port);
1044 vlan_mapping.val[2] &= ~BIT(port);
1046 vlan_mapping.val[2] |= BIT(port);
1047 err = gswip_pce_table_entry_write(priv, &vlan_mapping);
1049 dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
1050 /* In case an Active VLAN was creaetd delete it again */
1051 if (active_vlan_created)
1052 gswip_vlan_active_remove(priv, idx);
1057 gswip_switch_w(priv, idx, GSWIP_PCE_DEFPVID(port));
1062 static int gswip_vlan_remove(struct gswip_priv *priv,
1063 struct net_device *bridge, int port,
1064 u16 vid, bool pvid, bool vlan_aware)
1066 struct gswip_pce_table_entry vlan_mapping = {0,};
1067 unsigned int max_ports = priv->hw_info->max_ports;
1068 unsigned int cpu_port = priv->hw_info->cpu_port;
1073 /* Check if there is already a page for this bridge */
1074 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
1075 if (priv->vlans[i].bridge == bridge &&
1076 (!vlan_aware || priv->vlans[i].vid == vid)) {
1083 dev_err(priv->dev, "bridge to leave does not exists\n");
1087 vlan_mapping.index = idx;
1088 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
1089 err = gswip_pce_table_entry_read(priv, &vlan_mapping);
1091 dev_err(priv->dev, "failed to read VLAN mapping: %d\n", err);
1095 vlan_mapping.val[1] &= ~BIT(port);
1096 vlan_mapping.val[2] &= ~BIT(port);
1097 err = gswip_pce_table_entry_write(priv, &vlan_mapping);
1099 dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
1103 /* In case all ports are removed from the bridge, remove the VLAN */
1104 if ((vlan_mapping.val[1] & ~BIT(cpu_port)) == 0) {
1105 err = gswip_vlan_active_remove(priv, idx);
1107 dev_err(priv->dev, "failed to write active VLAN: %d\n",
1113 /* GSWIP 2.2 (GRX300) and later program here the VID directly. */
1115 gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port));
1120 static int gswip_port_bridge_join(struct dsa_switch *ds, int port,
1121 struct net_device *bridge)
1123 struct gswip_priv *priv = ds->priv;
1126 /* When the bridge uses VLAN filtering we have to configure VLAN
1127 * specific bridges. No bridge is configured here.
1129 if (!br_vlan_enabled(bridge)) {
1130 err = gswip_vlan_add_unaware(priv, bridge, port);
1133 priv->port_vlan_filter &= ~BIT(port);
1135 priv->port_vlan_filter |= BIT(port);
1137 return gswip_add_single_port_br(priv, port, false);
1140 static void gswip_port_bridge_leave(struct dsa_switch *ds, int port,
1141 struct net_device *bridge)
1143 struct gswip_priv *priv = ds->priv;
1145 gswip_add_single_port_br(priv, port, true);
1147 /* When the bridge uses VLAN filtering we have to configure VLAN
1148 * specific bridges. No bridge is configured here.
1150 if (!br_vlan_enabled(bridge))
1151 gswip_vlan_remove(priv, bridge, port, 0, true, false);
1154 static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port,
1155 const struct switchdev_obj_port_vlan *vlan)
1157 struct gswip_priv *priv = ds->priv;
1158 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
1159 unsigned int max_ports = priv->hw_info->max_ports;
1162 int pos = max_ports;
1164 /* We only support VLAN filtering on bridges */
1165 if (!dsa_is_cpu_port(ds, port) && !bridge)
1168 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1171 /* Check if there is already a page for this VLAN */
1172 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
1173 if (priv->vlans[i].bridge == bridge &&
1174 priv->vlans[i].vid == vid) {
1180 /* If this VLAN is not programmed yet, we have to reserve
1181 * one entry in the VLAN table. Make sure we start at the
1182 * next position round.
1185 /* Look for a free slot */
1186 for (; pos < ARRAY_SIZE(priv->vlans); pos++) {
1187 if (!priv->vlans[pos].bridge) {
1202 static void gswip_port_vlan_add(struct dsa_switch *ds, int port,
1203 const struct switchdev_obj_port_vlan *vlan)
1205 struct gswip_priv *priv = ds->priv;
1206 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
1207 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1208 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1211 /* We have to receive all packets on the CPU port and should not
1212 * do any VLAN filtering here. This is also called with bridge
1213 * NULL and then we do not know for which bridge to configure
1216 if (dsa_is_cpu_port(ds, port))
1219 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid)
1220 gswip_vlan_add_aware(priv, bridge, port, vid, untagged, pvid);
1223 static int gswip_port_vlan_del(struct dsa_switch *ds, int port,
1224 const struct switchdev_obj_port_vlan *vlan)
1226 struct gswip_priv *priv = ds->priv;
1227 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
1228 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
1232 /* We have to receive all packets on the CPU port and should not
1233 * do any VLAN filtering here. This is also called with bridge
1234 * NULL and then we do not know for which bridge to configure
1237 if (dsa_is_cpu_port(ds, port))
1240 for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) {
1241 err = gswip_vlan_remove(priv, bridge, port, vid, pvid, true);
1249 static void gswip_port_fast_age(struct dsa_switch *ds, int port)
1251 struct gswip_priv *priv = ds->priv;
1252 struct gswip_pce_table_entry mac_bridge = {0,};
1256 for (i = 0; i < 2048; i++) {
1257 mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE;
1258 mac_bridge.index = i;
1260 err = gswip_pce_table_entry_read(priv, &mac_bridge);
1262 dev_err(priv->dev, "failed to read mac bridge: %d\n",
1267 if (!mac_bridge.valid)
1270 if (mac_bridge.val[1] & GSWIP_TABLE_MAC_BRIDGE_STATIC)
1273 if (((mac_bridge.val[0] & GENMASK(7, 4)) >> 4) != port)
1276 mac_bridge.valid = false;
1277 err = gswip_pce_table_entry_write(priv, &mac_bridge);
1279 dev_err(priv->dev, "failed to write mac bridge: %d\n",
1286 static void gswip_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
1288 struct gswip_priv *priv = ds->priv;
1292 case BR_STATE_DISABLED:
1293 gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0,
1294 GSWIP_SDMA_PCTRLp(port));
1296 case BR_STATE_BLOCKING:
1297 case BR_STATE_LISTENING:
1298 stp_state = GSWIP_PCE_PCTRL_0_PSTATE_LISTEN;
1300 case BR_STATE_LEARNING:
1301 stp_state = GSWIP_PCE_PCTRL_0_PSTATE_LEARNING;
1303 case BR_STATE_FORWARDING:
1304 stp_state = GSWIP_PCE_PCTRL_0_PSTATE_FORWARDING;
1307 dev_err(priv->dev, "invalid STP state: %d\n", state);
1311 gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN,
1312 GSWIP_SDMA_PCTRLp(port));
1313 gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_PSTATE_MASK, stp_state,
1314 GSWIP_PCE_PCTRL_0p(port));
1317 static int gswip_port_fdb(struct dsa_switch *ds, int port,
1318 const unsigned char *addr, u16 vid, bool add)
1320 struct gswip_priv *priv = ds->priv;
1321 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
1322 struct gswip_pce_table_entry mac_bridge = {0,};
1323 unsigned int cpu_port = priv->hw_info->cpu_port;
1331 for (i = cpu_port; i < ARRAY_SIZE(priv->vlans); i++) {
1332 if (priv->vlans[i].bridge == bridge) {
1333 fid = priv->vlans[i].fid;
1339 dev_err(priv->dev, "Port not part of a bridge\n");
1343 mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE;
1344 mac_bridge.key_mode = true;
1345 mac_bridge.key[0] = addr[5] | (addr[4] << 8);
1346 mac_bridge.key[1] = addr[3] | (addr[2] << 8);
1347 mac_bridge.key[2] = addr[1] | (addr[0] << 8);
1348 mac_bridge.key[3] = fid;
1349 mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
1350 mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_STATIC;
1351 mac_bridge.valid = add;
1353 err = gswip_pce_table_entry_write(priv, &mac_bridge);
1355 dev_err(priv->dev, "failed to write mac bridge: %d\n", err);
1360 static int gswip_port_fdb_add(struct dsa_switch *ds, int port,
1361 const unsigned char *addr, u16 vid)
1363 return gswip_port_fdb(ds, port, addr, vid, true);
1366 static int gswip_port_fdb_del(struct dsa_switch *ds, int port,
1367 const unsigned char *addr, u16 vid)
1369 return gswip_port_fdb(ds, port, addr, vid, false);
1372 static int gswip_port_fdb_dump(struct dsa_switch *ds, int port,
1373 dsa_fdb_dump_cb_t *cb, void *data)
1375 struct gswip_priv *priv = ds->priv;
1376 struct gswip_pce_table_entry mac_bridge = {0,};
1377 unsigned char addr[6];
1381 for (i = 0; i < 2048; i++) {
1382 mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE;
1383 mac_bridge.index = i;
1385 err = gswip_pce_table_entry_read(priv, &mac_bridge);
1387 dev_err(priv->dev, "failed to write mac bridge: %d\n",
1392 if (!mac_bridge.valid)
1395 addr[5] = mac_bridge.key[0] & 0xff;
1396 addr[4] = (mac_bridge.key[0] >> 8) & 0xff;
1397 addr[3] = mac_bridge.key[1] & 0xff;
1398 addr[2] = (mac_bridge.key[1] >> 8) & 0xff;
1399 addr[1] = mac_bridge.key[2] & 0xff;
1400 addr[0] = (mac_bridge.key[2] >> 8) & 0xff;
1401 if (mac_bridge.val[1] & GSWIP_TABLE_MAC_BRIDGE_STATIC) {
1402 if (mac_bridge.val[0] & BIT(port))
1403 cb(addr, 0, true, data);
1405 if (((mac_bridge.val[0] & GENMASK(7, 4)) >> 4) == port)
1406 cb(addr, 0, false, data);
1412 static void gswip_phylink_validate(struct dsa_switch *ds, int port,
1413 unsigned long *supported,
1414 struct phylink_link_state *state)
1416 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
1421 if (!phy_interface_mode_is_rgmii(state->interface) &&
1422 state->interface != PHY_INTERFACE_MODE_MII &&
1423 state->interface != PHY_INTERFACE_MODE_REVMII &&
1424 state->interface != PHY_INTERFACE_MODE_RMII)
1430 if (state->interface != PHY_INTERFACE_MODE_INTERNAL)
1434 if (!phy_interface_mode_is_rgmii(state->interface) &&
1435 state->interface != PHY_INTERFACE_MODE_INTERNAL)
1439 bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
1440 dev_err(ds->dev, "Unsupported port: %i\n", port);
1444 /* Allow all the expected bits */
1445 phylink_set(mask, Autoneg);
1446 phylink_set_port_modes(mask);
1447 phylink_set(mask, Pause);
1448 phylink_set(mask, Asym_Pause);
1450 /* With the exclusion of MII and Reverse MII, we support Gigabit,
1451 * including Half duplex
1453 if (state->interface != PHY_INTERFACE_MODE_MII &&
1454 state->interface != PHY_INTERFACE_MODE_REVMII) {
1455 phylink_set(mask, 1000baseT_Full);
1456 phylink_set(mask, 1000baseT_Half);
1459 phylink_set(mask, 10baseT_Half);
1460 phylink_set(mask, 10baseT_Full);
1461 phylink_set(mask, 100baseT_Half);
1462 phylink_set(mask, 100baseT_Full);
1464 bitmap_and(supported, supported, mask,
1465 __ETHTOOL_LINK_MODE_MASK_NBITS);
1466 bitmap_and(state->advertising, state->advertising, mask,
1467 __ETHTOOL_LINK_MODE_MASK_NBITS);
1471 bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
1472 dev_err(ds->dev, "Unsupported interface '%s' for port %d\n",
1473 phy_modes(state->interface), port);
1477 static void gswip_phylink_mac_config(struct dsa_switch *ds, int port,
1479 const struct phylink_link_state *state)
1481 struct gswip_priv *priv = ds->priv;
1484 miicfg |= GSWIP_MII_CFG_LDCLKDIS;
1486 switch (state->interface) {
1487 case PHY_INTERFACE_MODE_MII:
1488 case PHY_INTERFACE_MODE_INTERNAL:
1489 miicfg |= GSWIP_MII_CFG_MODE_MIIM;
1491 case PHY_INTERFACE_MODE_REVMII:
1492 miicfg |= GSWIP_MII_CFG_MODE_MIIP;
1494 case PHY_INTERFACE_MODE_RMII:
1495 miicfg |= GSWIP_MII_CFG_MODE_RMIIM;
1497 case PHY_INTERFACE_MODE_RGMII:
1498 case PHY_INTERFACE_MODE_RGMII_ID:
1499 case PHY_INTERFACE_MODE_RGMII_RXID:
1500 case PHY_INTERFACE_MODE_RGMII_TXID:
1501 miicfg |= GSWIP_MII_CFG_MODE_RGMII;
1505 "Unsupported interface: %d\n", state->interface);
1508 gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_MODE_MASK, miicfg, port);
1510 switch (state->interface) {
1511 case PHY_INTERFACE_MODE_RGMII_ID:
1512 gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_TXDLY_MASK |
1513 GSWIP_MII_PCDU_RXDLY_MASK, 0, port);
1515 case PHY_INTERFACE_MODE_RGMII_RXID:
1516 gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_RXDLY_MASK, 0, port);
1518 case PHY_INTERFACE_MODE_RGMII_TXID:
1519 gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_TXDLY_MASK, 0, port);
1526 static void gswip_phylink_mac_link_down(struct dsa_switch *ds, int port,
1528 phy_interface_t interface)
1530 struct gswip_priv *priv = ds->priv;
1532 gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, port);
1535 static void gswip_phylink_mac_link_up(struct dsa_switch *ds, int port,
1537 phy_interface_t interface,
1538 struct phy_device *phydev,
1539 int speed, int duplex,
1540 bool tx_pause, bool rx_pause)
1542 struct gswip_priv *priv = ds->priv;
1544 /* Enable the xMII interface only for the external PHY */
1545 if (interface != PHY_INTERFACE_MODE_INTERNAL)
1546 gswip_mii_mask_cfg(priv, 0, GSWIP_MII_CFG_EN, port);
1549 static void gswip_get_strings(struct dsa_switch *ds, int port, u32 stringset,
1554 if (stringset != ETH_SS_STATS)
1557 for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++)
1558 strncpy(data + i * ETH_GSTRING_LEN, gswip_rmon_cnt[i].name,
1562 static u32 gswip_bcm_ram_entry_read(struct gswip_priv *priv, u32 table,
1568 gswip_switch_w(priv, index, GSWIP_BM_RAM_ADDR);
1569 gswip_switch_mask(priv, GSWIP_BM_RAM_CTRL_ADDR_MASK |
1570 GSWIP_BM_RAM_CTRL_OPMOD,
1571 table | GSWIP_BM_RAM_CTRL_BAS,
1574 err = gswip_switch_r_timeout(priv, GSWIP_BM_RAM_CTRL,
1575 GSWIP_BM_RAM_CTRL_BAS);
1577 dev_err(priv->dev, "timeout while reading table: %u, index: %u",
1582 result = gswip_switch_r(priv, GSWIP_BM_RAM_VAL(0));
1583 result |= gswip_switch_r(priv, GSWIP_BM_RAM_VAL(1)) << 16;
1588 static void gswip_get_ethtool_stats(struct dsa_switch *ds, int port,
1591 struct gswip_priv *priv = ds->priv;
1592 const struct gswip_rmon_cnt_desc *rmon_cnt;
1596 for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++) {
1597 rmon_cnt = &gswip_rmon_cnt[i];
1599 data[i] = gswip_bcm_ram_entry_read(priv, port,
1601 if (rmon_cnt->size == 2) {
1602 high = gswip_bcm_ram_entry_read(priv, port,
1603 rmon_cnt->offset + 1);
1604 data[i] |= high << 32;
1609 static int gswip_get_sset_count(struct dsa_switch *ds, int port, int sset)
1611 if (sset != ETH_SS_STATS)
1614 return ARRAY_SIZE(gswip_rmon_cnt);
1617 static const struct dsa_switch_ops gswip_switch_ops = {
1618 .get_tag_protocol = gswip_get_tag_protocol,
1619 .setup = gswip_setup,
1620 .port_enable = gswip_port_enable,
1621 .port_disable = gswip_port_disable,
1622 .port_bridge_join = gswip_port_bridge_join,
1623 .port_bridge_leave = gswip_port_bridge_leave,
1624 .port_fast_age = gswip_port_fast_age,
1625 .port_vlan_filtering = gswip_port_vlan_filtering,
1626 .port_vlan_prepare = gswip_port_vlan_prepare,
1627 .port_vlan_add = gswip_port_vlan_add,
1628 .port_vlan_del = gswip_port_vlan_del,
1629 .port_stp_state_set = gswip_port_stp_state_set,
1630 .port_fdb_add = gswip_port_fdb_add,
1631 .port_fdb_del = gswip_port_fdb_del,
1632 .port_fdb_dump = gswip_port_fdb_dump,
1633 .phylink_validate = gswip_phylink_validate,
1634 .phylink_mac_config = gswip_phylink_mac_config,
1635 .phylink_mac_link_down = gswip_phylink_mac_link_down,
1636 .phylink_mac_link_up = gswip_phylink_mac_link_up,
1637 .get_strings = gswip_get_strings,
1638 .get_ethtool_stats = gswip_get_ethtool_stats,
1639 .get_sset_count = gswip_get_sset_count,
1642 static const struct xway_gphy_match_data xrx200a1x_gphy_data = {
1643 .fe_firmware_name = "lantiq/xrx200_phy22f_a14.bin",
1644 .ge_firmware_name = "lantiq/xrx200_phy11g_a14.bin",
1647 static const struct xway_gphy_match_data xrx200a2x_gphy_data = {
1648 .fe_firmware_name = "lantiq/xrx200_phy22f_a22.bin",
1649 .ge_firmware_name = "lantiq/xrx200_phy11g_a22.bin",
1652 static const struct xway_gphy_match_data xrx300_gphy_data = {
1653 .fe_firmware_name = "lantiq/xrx300_phy22f_a21.bin",
1654 .ge_firmware_name = "lantiq/xrx300_phy11g_a21.bin",
1657 static const struct of_device_id xway_gphy_match[] = {
1658 { .compatible = "lantiq,xrx200-gphy-fw", .data = NULL },
1659 { .compatible = "lantiq,xrx200a1x-gphy-fw", .data = &xrx200a1x_gphy_data },
1660 { .compatible = "lantiq,xrx200a2x-gphy-fw", .data = &xrx200a2x_gphy_data },
1661 { .compatible = "lantiq,xrx300-gphy-fw", .data = &xrx300_gphy_data },
1662 { .compatible = "lantiq,xrx330-gphy-fw", .data = &xrx300_gphy_data },
1666 static int gswip_gphy_fw_load(struct gswip_priv *priv, struct gswip_gphy_fw *gphy_fw)
1668 struct device *dev = priv->dev;
1669 const struct firmware *fw;
1671 dma_addr_t dma_addr;
1672 dma_addr_t dev_addr;
1676 ret = clk_prepare_enable(gphy_fw->clk_gate);
1680 reset_control_assert(gphy_fw->reset);
1682 ret = request_firmware(&fw, gphy_fw->fw_name, dev);
1684 dev_err(dev, "failed to load firmware: %s, error: %i\n",
1685 gphy_fw->fw_name, ret);
1689 /* GPHY cores need the firmware code in a persistent and contiguous
1690 * memory area with a 16 kB boundary aligned start address.
1692 size = fw->size + XRX200_GPHY_FW_ALIGN;
1694 fw_addr = dmam_alloc_coherent(dev, size, &dma_addr, GFP_KERNEL);
1696 fw_addr = PTR_ALIGN(fw_addr, XRX200_GPHY_FW_ALIGN);
1697 dev_addr = ALIGN(dma_addr, XRX200_GPHY_FW_ALIGN);
1698 memcpy(fw_addr, fw->data, fw->size);
1700 dev_err(dev, "failed to alloc firmware memory\n");
1701 release_firmware(fw);
1705 release_firmware(fw);
1707 ret = regmap_write(priv->rcu_regmap, gphy_fw->fw_addr_offset, dev_addr);
1711 reset_control_deassert(gphy_fw->reset);
1716 static int gswip_gphy_fw_probe(struct gswip_priv *priv,
1717 struct gswip_gphy_fw *gphy_fw,
1718 struct device_node *gphy_fw_np, int i)
1720 struct device *dev = priv->dev;
1725 snprintf(gphyname, sizeof(gphyname), "gphy%d", i);
1727 gphy_fw->clk_gate = devm_clk_get(dev, gphyname);
1728 if (IS_ERR(gphy_fw->clk_gate)) {
1729 dev_err(dev, "Failed to lookup gate clock\n");
1730 return PTR_ERR(gphy_fw->clk_gate);
1733 ret = of_property_read_u32(gphy_fw_np, "reg", &gphy_fw->fw_addr_offset);
1737 ret = of_property_read_u32(gphy_fw_np, "lantiq,gphy-mode", &gphy_mode);
1738 /* Default to GE mode */
1740 gphy_mode = GPHY_MODE_GE;
1742 switch (gphy_mode) {
1744 gphy_fw->fw_name = priv->gphy_fw_name_cfg->fe_firmware_name;
1747 gphy_fw->fw_name = priv->gphy_fw_name_cfg->ge_firmware_name;
1750 dev_err(dev, "Unknown GPHY mode %d\n", gphy_mode);
1754 gphy_fw->reset = of_reset_control_array_get_exclusive(gphy_fw_np);
1755 if (IS_ERR(gphy_fw->reset)) {
1756 if (PTR_ERR(gphy_fw->reset) != -EPROBE_DEFER)
1757 dev_err(dev, "Failed to lookup gphy reset\n");
1758 return PTR_ERR(gphy_fw->reset);
1761 return gswip_gphy_fw_load(priv, gphy_fw);
1764 static void gswip_gphy_fw_remove(struct gswip_priv *priv,
1765 struct gswip_gphy_fw *gphy_fw)
1769 /* check if the device was fully probed */
1770 if (!gphy_fw->fw_name)
1773 ret = regmap_write(priv->rcu_regmap, gphy_fw->fw_addr_offset, 0);
1775 dev_err(priv->dev, "can not reset GPHY FW pointer");
1777 clk_disable_unprepare(gphy_fw->clk_gate);
1779 reset_control_put(gphy_fw->reset);
1782 static int gswip_gphy_fw_list(struct gswip_priv *priv,
1783 struct device_node *gphy_fw_list_np, u32 version)
1785 struct device *dev = priv->dev;
1786 struct device_node *gphy_fw_np;
1787 const struct of_device_id *match;
1791 /* The VRX200 rev 1.1 uses the GSWIP 2.0 and needs the older
1792 * GPHY firmware. The VRX200 rev 1.2 uses the GSWIP 2.1 and also
1793 * needs a different GPHY firmware.
1795 if (of_device_is_compatible(gphy_fw_list_np, "lantiq,xrx200-gphy-fw")) {
1797 case GSWIP_VERSION_2_0:
1798 priv->gphy_fw_name_cfg = &xrx200a1x_gphy_data;
1800 case GSWIP_VERSION_2_1:
1801 priv->gphy_fw_name_cfg = &xrx200a2x_gphy_data;
1804 dev_err(dev, "unknown GSWIP version: 0x%x", version);
1809 match = of_match_node(xway_gphy_match, gphy_fw_list_np);
1810 if (match && match->data)
1811 priv->gphy_fw_name_cfg = match->data;
1813 if (!priv->gphy_fw_name_cfg) {
1814 dev_err(dev, "GPHY compatible type not supported");
1818 priv->num_gphy_fw = of_get_available_child_count(gphy_fw_list_np);
1819 if (!priv->num_gphy_fw)
1822 priv->rcu_regmap = syscon_regmap_lookup_by_phandle(gphy_fw_list_np,
1824 if (IS_ERR(priv->rcu_regmap))
1825 return PTR_ERR(priv->rcu_regmap);
1827 priv->gphy_fw = devm_kmalloc_array(dev, priv->num_gphy_fw,
1828 sizeof(*priv->gphy_fw),
1829 GFP_KERNEL | __GFP_ZERO);
1833 for_each_available_child_of_node(gphy_fw_list_np, gphy_fw_np) {
1834 err = gswip_gphy_fw_probe(priv, &priv->gphy_fw[i],
1841 /* The standalone PHY11G requires 300ms to be fully
1842 * initialized and ready for any MDIO communication after being
1843 * taken out of reset. For the SoC-internal GPHY variant there
1844 * is no (known) documentation for the minimum time after a
1845 * reset. Use the same value as for the standalone variant as
1846 * some users have reported internal PHYs not being detected
1847 * without any delay.
1854 for (i = 0; i < priv->num_gphy_fw; i++)
1855 gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
1859 static int gswip_probe(struct platform_device *pdev)
1861 struct gswip_priv *priv;
1862 struct device_node *mdio_np, *gphy_fw_np;
1863 struct device *dev = &pdev->dev;
1868 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1872 priv->gswip = devm_platform_ioremap_resource(pdev, 0);
1873 if (IS_ERR(priv->gswip))
1874 return PTR_ERR(priv->gswip);
1876 priv->mdio = devm_platform_ioremap_resource(pdev, 1);
1877 if (IS_ERR(priv->mdio))
1878 return PTR_ERR(priv->mdio);
1880 priv->mii = devm_platform_ioremap_resource(pdev, 2);
1881 if (IS_ERR(priv->mii))
1882 return PTR_ERR(priv->mii);
1884 priv->hw_info = of_device_get_match_data(dev);
1888 priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL);
1892 priv->ds->dev = dev;
1893 priv->ds->num_ports = priv->hw_info->max_ports;
1894 priv->ds->priv = priv;
1895 priv->ds->ops = &gswip_switch_ops;
1897 version = gswip_switch_r(priv, GSWIP_VERSION);
1899 /* bring up the mdio bus */
1900 gphy_fw_np = of_get_compatible_child(dev->of_node, "lantiq,gphy-fw");
1902 err = gswip_gphy_fw_list(priv, gphy_fw_np, version);
1903 of_node_put(gphy_fw_np);
1905 dev_err(dev, "gphy fw probe failed\n");
1910 /* bring up the mdio bus */
1911 mdio_np = of_get_compatible_child(dev->of_node, "lantiq,xrx200-mdio");
1913 err = gswip_mdio(priv, mdio_np);
1915 dev_err(dev, "mdio probe failed\n");
1920 err = dsa_register_switch(priv->ds);
1922 dev_err(dev, "dsa switch register failed: %i\n", err);
1925 if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) {
1926 dev_err(dev, "wrong CPU port defined, HW only supports port: %i",
1927 priv->hw_info->cpu_port);
1929 goto disable_switch;
1932 platform_set_drvdata(pdev, priv);
1934 dev_info(dev, "probed GSWIP version %lx mod %lx\n",
1935 (version & GSWIP_VERSION_REV_MASK) >> GSWIP_VERSION_REV_SHIFT,
1936 (version & GSWIP_VERSION_MOD_MASK) >> GSWIP_VERSION_MOD_SHIFT);
1940 gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB);
1941 dsa_unregister_switch(priv->ds);
1944 mdiobus_unregister(priv->ds->slave_mii_bus);
1946 of_node_put(mdio_np);
1947 for (i = 0; i < priv->num_gphy_fw; i++)
1948 gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
1952 static int gswip_remove(struct platform_device *pdev)
1954 struct gswip_priv *priv = platform_get_drvdata(pdev);
1957 /* disable the switch */
1958 gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB);
1960 dsa_unregister_switch(priv->ds);
1962 if (priv->ds->slave_mii_bus) {
1963 mdiobus_unregister(priv->ds->slave_mii_bus);
1964 of_node_put(priv->ds->slave_mii_bus->dev.of_node);
1967 for (i = 0; i < priv->num_gphy_fw; i++)
1968 gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
1973 static const struct gswip_hw_info gswip_xrx200 = {
1978 static const struct of_device_id gswip_of_match[] = {
1979 { .compatible = "lantiq,xrx200-gswip", .data = &gswip_xrx200 },
1982 MODULE_DEVICE_TABLE(of, gswip_of_match);
1984 static struct platform_driver gswip_driver = {
1985 .probe = gswip_probe,
1986 .remove = gswip_remove,
1989 .of_match_table = gswip_of_match,
1993 module_platform_driver(gswip_driver);
1995 MODULE_FIRMWARE("lantiq/xrx300_phy11g_a21.bin");
1996 MODULE_FIRMWARE("lantiq/xrx300_phy22f_a21.bin");
1997 MODULE_FIRMWARE("lantiq/xrx200_phy11g_a14.bin");
1998 MODULE_FIRMWARE("lantiq/xrx200_phy11g_a22.bin");
1999 MODULE_FIRMWARE("lantiq/xrx200_phy22f_a14.bin");
2000 MODULE_FIRMWARE("lantiq/xrx200_phy22f_a22.bin");
2002 MODULE_DESCRIPTION("Lantiq / Intel GSWIP driver");
2003 MODULE_LICENSE("GPL v2");