blob: 174ca3a484a09da0407c0c66ec5ff551e2d314b8 [file] [log] [blame]
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Lantiq / Intel GSWIP switch driver for VRX200 SoCs
4 *
5 * Copyright (C) 2010 Lantiq Deutschland
6 * Copyright (C) 2012 John Crispin <john@phrozen.org>
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +02007 * Copyright (C) 2017 - 2019 Hauke Mehrtens <hauke@hauke-m.de>
8 *
9 * The VLAN and bridge model the GSWIP hardware uses does not directly
10 * matches the model DSA uses.
11 *
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.
18 *
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.
Hauke Mehrtens14fceff2018-09-09 22:20:39 +020026 */
27
28#include <linux/clk.h>
Martin Blumenstingl2a1828e2020-11-15 17:57:57 +010029#include <linux/delay.h>
Hauke Mehrtens14fceff2018-09-09 22:20:39 +020030#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>
45#include <net/dsa.h>
46#include <dt-bindings/mips/lantiq_rcu_gphy.h>
47
48#include "lantiq_pce.h"
49
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)
93
94/* GSWIP MII Registers */
Martin Blumenstingl709a3c92021-01-03 02:25:44 +010095#define GSWIP_MII_CFGp(p) (0x2 * (p))
Hauke Mehrtens14fceff2018-09-09 22:20:39 +020096#define GSWIP_MII_CFG_EN BIT(14)
97#define GSWIP_MII_CFG_LDCLKDIS BIT(12)
98#define GSWIP_MII_CFG_MODE_MIIP 0x0
99#define GSWIP_MII_CFG_MODE_MIIM 0x1
100#define GSWIP_MII_CFG_MODE_RMIIP 0x2
101#define GSWIP_MII_CFG_MODE_RMIIM 0x3
102#define GSWIP_MII_CFG_MODE_RGMII 0x4
103#define GSWIP_MII_CFG_MODE_MASK 0xf
104#define GSWIP_MII_CFG_RATE_M2P5 0x00
105#define GSWIP_MII_CFG_RATE_M25 0x10
106#define GSWIP_MII_CFG_RATE_M125 0x20
107#define GSWIP_MII_CFG_RATE_M50 0x30
108#define GSWIP_MII_CFG_RATE_AUTO 0x40
109#define GSWIP_MII_CFG_RATE_MASK 0x70
110#define GSWIP_MII_PCDU0 0x01
111#define GSWIP_MII_PCDU1 0x03
112#define GSWIP_MII_PCDU5 0x05
113#define GSWIP_MII_PCDU_TXDLY_MASK GENMASK(2, 0)
114#define GSWIP_MII_PCDU_RXDLY_MASK GENMASK(9, 7)
115
116/* GSWIP Core Registers */
117#define GSWIP_SWRES 0x000
118#define GSWIP_SWRES_R1 BIT(1) /* GSWIP Software reset */
119#define GSWIP_SWRES_R0 BIT(0) /* GSWIP Hardware reset */
120#define GSWIP_VERSION 0x013
121#define GSWIP_VERSION_REV_SHIFT 0
122#define GSWIP_VERSION_REV_MASK GENMASK(7, 0)
123#define GSWIP_VERSION_MOD_SHIFT 8
124#define GSWIP_VERSION_MOD_MASK GENMASK(15, 8)
125#define GSWIP_VERSION_2_0 0x100
126#define GSWIP_VERSION_2_1 0x021
127#define GSWIP_VERSION_2_2 0x122
128#define GSWIP_VERSION_2_2_ETC 0x022
129
130#define GSWIP_BM_RAM_VAL(x) (0x043 - (x))
131#define GSWIP_BM_RAM_ADDR 0x044
132#define GSWIP_BM_RAM_CTRL 0x045
133#define GSWIP_BM_RAM_CTRL_BAS BIT(15)
134#define GSWIP_BM_RAM_CTRL_OPMOD BIT(5)
135#define GSWIP_BM_RAM_CTRL_ADDR_MASK GENMASK(4, 0)
136#define GSWIP_BM_QUEUE_GCTRL 0x04A
137#define GSWIP_BM_QUEUE_GCTRL_GL_MOD BIT(10)
138/* buffer management Port Configuration Register */
139#define GSWIP_BM_PCFGp(p) (0x080 + ((p) * 2))
140#define GSWIP_BM_PCFG_CNTEN BIT(0) /* RMON Counter Enable */
141#define GSWIP_BM_PCFG_IGCNT BIT(1) /* Ingres Special Tag RMON count */
142/* buffer management Port Control Register */
143#define GSWIP_BM_RMON_CTRLp(p) (0x81 + ((p) * 2))
144#define GSWIP_BM_CTRL_RMON_RAM1_RES BIT(0) /* Software Reset for RMON RAM 1 */
145#define GSWIP_BM_CTRL_RMON_RAM2_RES BIT(1) /* Software Reset for RMON RAM 2 */
146
147/* PCE */
148#define GSWIP_PCE_TBL_KEY(x) (0x447 - (x))
149#define GSWIP_PCE_TBL_MASK 0x448
150#define GSWIP_PCE_TBL_VAL(x) (0x44D - (x))
151#define GSWIP_PCE_TBL_ADDR 0x44E
152#define GSWIP_PCE_TBL_CTRL 0x44F
153#define GSWIP_PCE_TBL_CTRL_BAS BIT(15)
154#define GSWIP_PCE_TBL_CTRL_TYPE BIT(13)
155#define GSWIP_PCE_TBL_CTRL_VLD BIT(12)
156#define GSWIP_PCE_TBL_CTRL_KEYFORM BIT(11)
157#define GSWIP_PCE_TBL_CTRL_GMAP_MASK GENMASK(10, 7)
158#define GSWIP_PCE_TBL_CTRL_OPMOD_MASK GENMASK(6, 5)
159#define GSWIP_PCE_TBL_CTRL_OPMOD_ADRD 0x00
160#define GSWIP_PCE_TBL_CTRL_OPMOD_ADWR 0x20
161#define GSWIP_PCE_TBL_CTRL_OPMOD_KSRD 0x40
162#define GSWIP_PCE_TBL_CTRL_OPMOD_KSWR 0x60
163#define GSWIP_PCE_TBL_CTRL_ADDR_MASK GENMASK(4, 0)
164#define GSWIP_PCE_PMAP1 0x453 /* Monitoring port map */
165#define GSWIP_PCE_PMAP2 0x454 /* Default Multicast port map */
166#define GSWIP_PCE_PMAP3 0x455 /* Default Unknown Unicast port map */
167#define GSWIP_PCE_GCTRL_0 0x456
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200168#define GSWIP_PCE_GCTRL_0_MTFL BIT(0) /* MAC Table Flushing */
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200169#define GSWIP_PCE_GCTRL_0_MC_VALID BIT(3)
170#define GSWIP_PCE_GCTRL_0_VLAN BIT(14) /* VLAN aware Switching */
171#define GSWIP_PCE_GCTRL_1 0x457
172#define GSWIP_PCE_GCTRL_1_MAC_GLOCK BIT(2) /* MAC Address table lock */
173#define GSWIP_PCE_GCTRL_1_MAC_GLOCK_MOD BIT(3) /* Mac address table lock forwarding mode */
174#define GSWIP_PCE_PCTRL_0p(p) (0x480 + ((p) * 0xA))
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200175#define GSWIP_PCE_PCTRL_0_TVM BIT(5) /* Transparent VLAN mode */
176#define GSWIP_PCE_PCTRL_0_VREP BIT(6) /* VLAN Replace Mode */
177#define GSWIP_PCE_PCTRL_0_INGRESS BIT(11) /* Accept special tag in ingress */
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200178#define GSWIP_PCE_PCTRL_0_PSTATE_LISTEN 0x0
179#define GSWIP_PCE_PCTRL_0_PSTATE_RX 0x1
180#define GSWIP_PCE_PCTRL_0_PSTATE_TX 0x2
181#define GSWIP_PCE_PCTRL_0_PSTATE_LEARNING 0x3
182#define GSWIP_PCE_PCTRL_0_PSTATE_FORWARDING 0x7
183#define GSWIP_PCE_PCTRL_0_PSTATE_MASK GENMASK(2, 0)
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200184#define GSWIP_PCE_VCTRL(p) (0x485 + ((p) * 0xA))
185#define GSWIP_PCE_VCTRL_UVR BIT(0) /* Unknown VLAN Rule */
186#define GSWIP_PCE_VCTRL_VIMR BIT(3) /* VLAN Ingress Member violation rule */
187#define GSWIP_PCE_VCTRL_VEMR BIT(4) /* VLAN Egress Member violation rule */
188#define GSWIP_PCE_VCTRL_VSR BIT(5) /* VLAN Security */
189#define GSWIP_PCE_VCTRL_VID0 BIT(6) /* Priority Tagged Rule */
190#define GSWIP_PCE_DEFPVID(p) (0x486 + ((p) * 0xA))
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200191
192#define GSWIP_MAC_FLEN 0x8C5
193#define GSWIP_MAC_CTRL_2p(p) (0x905 + ((p) * 0xC))
194#define GSWIP_MAC_CTRL_2_MLEN BIT(3) /* Maximum Untagged Frame Lnegth */
195
196/* Ethernet Switch Fetch DMA Port Control Register */
197#define GSWIP_FDMA_PCTRLp(p) (0xA80 + ((p) * 0x6))
198#define GSWIP_FDMA_PCTRL_EN BIT(0) /* FDMA Port Enable */
199#define GSWIP_FDMA_PCTRL_STEN BIT(1) /* Special Tag Insertion Enable */
200#define GSWIP_FDMA_PCTRL_VLANMOD_MASK GENMASK(4, 3) /* VLAN Modification Control */
201#define GSWIP_FDMA_PCTRL_VLANMOD_SHIFT 3 /* VLAN Modification Control */
202#define GSWIP_FDMA_PCTRL_VLANMOD_DIS (0x0 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT)
203#define GSWIP_FDMA_PCTRL_VLANMOD_PRIO (0x1 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT)
204#define GSWIP_FDMA_PCTRL_VLANMOD_ID (0x2 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT)
205#define GSWIP_FDMA_PCTRL_VLANMOD_BOTH (0x3 << GSWIP_FDMA_PCTRL_VLANMOD_SHIFT)
206
207/* Ethernet Switch Store DMA Port Control Register */
208#define GSWIP_SDMA_PCTRLp(p) (0xBC0 + ((p) * 0x6))
209#define GSWIP_SDMA_PCTRL_EN BIT(0) /* SDMA Port Enable */
210#define GSWIP_SDMA_PCTRL_FCEN BIT(1) /* Flow Control Enable */
211#define GSWIP_SDMA_PCTRL_PAUFWD BIT(1) /* Pause Frame Forwarding */
212
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200213#define GSWIP_TABLE_ACTIVE_VLAN 0x01
214#define GSWIP_TABLE_VLAN_MAPPING 0x02
Hauke Mehrtens45813482019-05-06 00:25:09 +0200215#define GSWIP_TABLE_MAC_BRIDGE 0x0b
216#define GSWIP_TABLE_MAC_BRIDGE_STATIC 0x01 /* Static not, aging entry */
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200217
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200218#define XRX200_GPHY_FW_ALIGN (16 * 1024)
219
220struct gswip_hw_info {
221 int max_ports;
222 int cpu_port;
223};
224
225struct xway_gphy_match_data {
226 char *fe_firmware_name;
227 char *ge_firmware_name;
228};
229
230struct gswip_gphy_fw {
231 struct clk *clk_gate;
232 struct reset_control *reset;
233 u32 fw_addr_offset;
234 char *fw_name;
235};
236
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200237struct gswip_vlan {
238 struct net_device *bridge;
239 u16 vid;
240 u8 fid;
241};
242
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200243struct gswip_priv {
244 __iomem void *gswip;
245 __iomem void *mdio;
246 __iomem void *mii;
247 const struct gswip_hw_info *hw_info;
248 const struct xway_gphy_match_data *gphy_fw_name_cfg;
249 struct dsa_switch *ds;
250 struct device *dev;
251 struct regmap *rcu_regmap;
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200252 struct gswip_vlan vlans[64];
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200253 int num_gphy_fw;
254 struct gswip_gphy_fw *gphy_fw;
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +0200255 u32 port_vlan_filter;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200256};
257
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200258struct gswip_pce_table_entry {
259 u16 index; // PCE_TBL_ADDR.ADDR = pData->table_index
260 u16 table; // PCE_TBL_CTRL.ADDR = pData->table
261 u16 key[8];
262 u16 val[5];
263 u16 mask;
264 u8 gmap;
265 bool type;
266 bool valid;
267 bool key_mode;
268};
269
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200270struct gswip_rmon_cnt_desc {
271 unsigned int size;
272 unsigned int offset;
273 const char *name;
274};
275
276#define MIB_DESC(_size, _offset, _name) {.size = _size, .offset = _offset, .name = _name}
277
278static const struct gswip_rmon_cnt_desc gswip_rmon_cnt[] = {
279 /** Receive Packet Count (only packets that are accepted and not discarded). */
280 MIB_DESC(1, 0x1F, "RxGoodPkts"),
281 MIB_DESC(1, 0x23, "RxUnicastPkts"),
282 MIB_DESC(1, 0x22, "RxMulticastPkts"),
283 MIB_DESC(1, 0x21, "RxFCSErrorPkts"),
284 MIB_DESC(1, 0x1D, "RxUnderSizeGoodPkts"),
285 MIB_DESC(1, 0x1E, "RxUnderSizeErrorPkts"),
286 MIB_DESC(1, 0x1B, "RxOversizeGoodPkts"),
287 MIB_DESC(1, 0x1C, "RxOversizeErrorPkts"),
288 MIB_DESC(1, 0x20, "RxGoodPausePkts"),
289 MIB_DESC(1, 0x1A, "RxAlignErrorPkts"),
290 MIB_DESC(1, 0x12, "Rx64BytePkts"),
291 MIB_DESC(1, 0x13, "Rx127BytePkts"),
292 MIB_DESC(1, 0x14, "Rx255BytePkts"),
293 MIB_DESC(1, 0x15, "Rx511BytePkts"),
294 MIB_DESC(1, 0x16, "Rx1023BytePkts"),
295 /** Receive Size 1024-1522 (or more, if configured) Packet Count. */
296 MIB_DESC(1, 0x17, "RxMaxBytePkts"),
297 MIB_DESC(1, 0x18, "RxDroppedPkts"),
298 MIB_DESC(1, 0x19, "RxFilteredPkts"),
299 MIB_DESC(2, 0x24, "RxGoodBytes"),
300 MIB_DESC(2, 0x26, "RxBadBytes"),
301 MIB_DESC(1, 0x11, "TxAcmDroppedPkts"),
302 MIB_DESC(1, 0x0C, "TxGoodPkts"),
303 MIB_DESC(1, 0x06, "TxUnicastPkts"),
304 MIB_DESC(1, 0x07, "TxMulticastPkts"),
305 MIB_DESC(1, 0x00, "Tx64BytePkts"),
306 MIB_DESC(1, 0x01, "Tx127BytePkts"),
307 MIB_DESC(1, 0x02, "Tx255BytePkts"),
308 MIB_DESC(1, 0x03, "Tx511BytePkts"),
309 MIB_DESC(1, 0x04, "Tx1023BytePkts"),
310 /** Transmit Size 1024-1522 (or more, if configured) Packet Count. */
311 MIB_DESC(1, 0x05, "TxMaxBytePkts"),
312 MIB_DESC(1, 0x08, "TxSingleCollCount"),
313 MIB_DESC(1, 0x09, "TxMultCollCount"),
314 MIB_DESC(1, 0x0A, "TxLateCollCount"),
315 MIB_DESC(1, 0x0B, "TxExcessCollCount"),
316 MIB_DESC(1, 0x0D, "TxPauseCount"),
317 MIB_DESC(1, 0x10, "TxDroppedPkts"),
318 MIB_DESC(2, 0x0E, "TxGoodBytes"),
319};
320
321static u32 gswip_switch_r(struct gswip_priv *priv, u32 offset)
322{
323 return __raw_readl(priv->gswip + (offset * 4));
324}
325
326static void gswip_switch_w(struct gswip_priv *priv, u32 val, u32 offset)
327{
328 __raw_writel(val, priv->gswip + (offset * 4));
329}
330
331static void gswip_switch_mask(struct gswip_priv *priv, u32 clear, u32 set,
332 u32 offset)
333{
334 u32 val = gswip_switch_r(priv, offset);
335
336 val &= ~(clear);
337 val |= set;
338 gswip_switch_w(priv, val, offset);
339}
340
341static u32 gswip_switch_r_timeout(struct gswip_priv *priv, u32 offset,
342 u32 cleared)
343{
344 u32 val;
345
346 return readx_poll_timeout(__raw_readl, priv->gswip + (offset * 4), val,
347 (val & cleared) == 0, 20, 50000);
348}
349
350static u32 gswip_mdio_r(struct gswip_priv *priv, u32 offset)
351{
352 return __raw_readl(priv->mdio + (offset * 4));
353}
354
355static void gswip_mdio_w(struct gswip_priv *priv, u32 val, u32 offset)
356{
357 __raw_writel(val, priv->mdio + (offset * 4));
358}
359
360static void gswip_mdio_mask(struct gswip_priv *priv, u32 clear, u32 set,
361 u32 offset)
362{
363 u32 val = gswip_mdio_r(priv, offset);
364
365 val &= ~(clear);
366 val |= set;
367 gswip_mdio_w(priv, val, offset);
368}
369
370static u32 gswip_mii_r(struct gswip_priv *priv, u32 offset)
371{
372 return __raw_readl(priv->mii + (offset * 4));
373}
374
375static void gswip_mii_w(struct gswip_priv *priv, u32 val, u32 offset)
376{
377 __raw_writel(val, priv->mii + (offset * 4));
378}
379
380static void gswip_mii_mask(struct gswip_priv *priv, u32 clear, u32 set,
381 u32 offset)
382{
383 u32 val = gswip_mii_r(priv, offset);
384
385 val &= ~(clear);
386 val |= set;
387 gswip_mii_w(priv, val, offset);
388}
389
390static void gswip_mii_mask_cfg(struct gswip_priv *priv, u32 clear, u32 set,
391 int port)
392{
Martin Blumenstingl709a3c92021-01-03 02:25:44 +0100393 /* There's no MII_CFG register for the CPU port */
394 if (!dsa_is_cpu_port(priv->ds, port))
395 gswip_mii_mask(priv, clear, set, GSWIP_MII_CFGp(port));
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200396}
397
398static void gswip_mii_mask_pcdu(struct gswip_priv *priv, u32 clear, u32 set,
399 int port)
400{
401 switch (port) {
402 case 0:
403 gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU0);
404 break;
405 case 1:
406 gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU1);
407 break;
408 case 5:
409 gswip_mii_mask(priv, clear, set, GSWIP_MII_PCDU5);
410 break;
411 }
412}
413
414static int gswip_mdio_poll(struct gswip_priv *priv)
415{
416 int cnt = 100;
417
418 while (likely(cnt--)) {
419 u32 ctrl = gswip_mdio_r(priv, GSWIP_MDIO_CTRL);
420
421 if ((ctrl & GSWIP_MDIO_CTRL_BUSY) == 0)
422 return 0;
423 usleep_range(20, 40);
424 }
425
426 return -ETIMEDOUT;
427}
428
429static int gswip_mdio_wr(struct mii_bus *bus, int addr, int reg, u16 val)
430{
431 struct gswip_priv *priv = bus->priv;
432 int err;
433
434 err = gswip_mdio_poll(priv);
435 if (err) {
436 dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n");
437 return err;
438 }
439
440 gswip_mdio_w(priv, val, GSWIP_MDIO_WRITE);
441 gswip_mdio_w(priv, GSWIP_MDIO_CTRL_BUSY | GSWIP_MDIO_CTRL_WR |
442 ((addr & GSWIP_MDIO_CTRL_PHYAD_MASK) << GSWIP_MDIO_CTRL_PHYAD_SHIFT) |
443 (reg & GSWIP_MDIO_CTRL_REGAD_MASK),
444 GSWIP_MDIO_CTRL);
445
446 return 0;
447}
448
449static int gswip_mdio_rd(struct mii_bus *bus, int addr, int reg)
450{
451 struct gswip_priv *priv = bus->priv;
452 int err;
453
454 err = gswip_mdio_poll(priv);
455 if (err) {
456 dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n");
457 return err;
458 }
459
460 gswip_mdio_w(priv, GSWIP_MDIO_CTRL_BUSY | GSWIP_MDIO_CTRL_RD |
461 ((addr & GSWIP_MDIO_CTRL_PHYAD_MASK) << GSWIP_MDIO_CTRL_PHYAD_SHIFT) |
462 (reg & GSWIP_MDIO_CTRL_REGAD_MASK),
463 GSWIP_MDIO_CTRL);
464
465 err = gswip_mdio_poll(priv);
466 if (err) {
467 dev_err(&bus->dev, "waiting for MDIO bus busy timed out\n");
468 return err;
469 }
470
471 return gswip_mdio_r(priv, GSWIP_MDIO_READ);
472}
473
474static int gswip_mdio(struct gswip_priv *priv, struct device_node *mdio_np)
475{
476 struct dsa_switch *ds = priv->ds;
477
478 ds->slave_mii_bus = devm_mdiobus_alloc(priv->dev);
479 if (!ds->slave_mii_bus)
480 return -ENOMEM;
481
482 ds->slave_mii_bus->priv = priv;
483 ds->slave_mii_bus->read = gswip_mdio_rd;
484 ds->slave_mii_bus->write = gswip_mdio_wr;
485 ds->slave_mii_bus->name = "lantiq,xrx200-mdio";
486 snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "%s-mii",
487 dev_name(priv->dev));
488 ds->slave_mii_bus->parent = priv->dev;
489 ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask;
490
491 return of_mdiobus_register(ds->slave_mii_bus, mdio_np);
492}
493
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200494static int gswip_pce_table_entry_read(struct gswip_priv *priv,
495 struct gswip_pce_table_entry *tbl)
496{
497 int i;
498 int err;
499 u16 crtl;
500 u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSRD :
501 GSWIP_PCE_TBL_CTRL_OPMOD_ADRD;
502
503 err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
504 GSWIP_PCE_TBL_CTRL_BAS);
505 if (err)
506 return err;
507
508 gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR);
509 gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK |
510 GSWIP_PCE_TBL_CTRL_OPMOD_MASK,
511 tbl->table | addr_mode | GSWIP_PCE_TBL_CTRL_BAS,
512 GSWIP_PCE_TBL_CTRL);
513
514 err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
515 GSWIP_PCE_TBL_CTRL_BAS);
516 if (err)
517 return err;
518
519 for (i = 0; i < ARRAY_SIZE(tbl->key); i++)
520 tbl->key[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_KEY(i));
521
522 for (i = 0; i < ARRAY_SIZE(tbl->val); i++)
523 tbl->val[i] = gswip_switch_r(priv, GSWIP_PCE_TBL_VAL(i));
524
525 tbl->mask = gswip_switch_r(priv, GSWIP_PCE_TBL_MASK);
526
527 crtl = gswip_switch_r(priv, GSWIP_PCE_TBL_CTRL);
528
529 tbl->type = !!(crtl & GSWIP_PCE_TBL_CTRL_TYPE);
530 tbl->valid = !!(crtl & GSWIP_PCE_TBL_CTRL_VLD);
531 tbl->gmap = (crtl & GSWIP_PCE_TBL_CTRL_GMAP_MASK) >> 7;
532
533 return 0;
534}
535
536static int gswip_pce_table_entry_write(struct gswip_priv *priv,
537 struct gswip_pce_table_entry *tbl)
538{
539 int i;
540 int err;
541 u16 crtl;
542 u16 addr_mode = tbl->key_mode ? GSWIP_PCE_TBL_CTRL_OPMOD_KSWR :
543 GSWIP_PCE_TBL_CTRL_OPMOD_ADWR;
544
545 err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
546 GSWIP_PCE_TBL_CTRL_BAS);
547 if (err)
548 return err;
549
550 gswip_switch_w(priv, tbl->index, GSWIP_PCE_TBL_ADDR);
551 gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK |
552 GSWIP_PCE_TBL_CTRL_OPMOD_MASK,
553 tbl->table | addr_mode,
554 GSWIP_PCE_TBL_CTRL);
555
556 for (i = 0; i < ARRAY_SIZE(tbl->key); i++)
557 gswip_switch_w(priv, tbl->key[i], GSWIP_PCE_TBL_KEY(i));
558
559 for (i = 0; i < ARRAY_SIZE(tbl->val); i++)
560 gswip_switch_w(priv, tbl->val[i], GSWIP_PCE_TBL_VAL(i));
561
562 gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK |
563 GSWIP_PCE_TBL_CTRL_OPMOD_MASK,
564 tbl->table | addr_mode,
565 GSWIP_PCE_TBL_CTRL);
566
567 gswip_switch_w(priv, tbl->mask, GSWIP_PCE_TBL_MASK);
568
569 crtl = gswip_switch_r(priv, GSWIP_PCE_TBL_CTRL);
570 crtl &= ~(GSWIP_PCE_TBL_CTRL_TYPE | GSWIP_PCE_TBL_CTRL_VLD |
571 GSWIP_PCE_TBL_CTRL_GMAP_MASK);
572 if (tbl->type)
573 crtl |= GSWIP_PCE_TBL_CTRL_TYPE;
574 if (tbl->valid)
575 crtl |= GSWIP_PCE_TBL_CTRL_VLD;
576 crtl |= (tbl->gmap << 7) & GSWIP_PCE_TBL_CTRL_GMAP_MASK;
577 crtl |= GSWIP_PCE_TBL_CTRL_BAS;
578 gswip_switch_w(priv, crtl, GSWIP_PCE_TBL_CTRL);
579
580 return gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
581 GSWIP_PCE_TBL_CTRL_BAS);
582}
583
584/* Add the LAN port into a bridge with the CPU port by
585 * default. This prevents automatic forwarding of
586 * packages between the LAN ports when no explicit
587 * bridge is configured.
588 */
589static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add)
590{
591 struct gswip_pce_table_entry vlan_active = {0,};
592 struct gswip_pce_table_entry vlan_mapping = {0,};
593 unsigned int cpu_port = priv->hw_info->cpu_port;
594 unsigned int max_ports = priv->hw_info->max_ports;
595 int err;
596
597 if (port >= max_ports) {
598 dev_err(priv->dev, "single port for %i supported\n", port);
599 return -EIO;
600 }
601
602 vlan_active.index = port + 1;
603 vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN;
604 vlan_active.key[0] = 0; /* vid */
605 vlan_active.val[0] = port + 1 /* fid */;
606 vlan_active.valid = add;
607 err = gswip_pce_table_entry_write(priv, &vlan_active);
608 if (err) {
609 dev_err(priv->dev, "failed to write active VLAN: %d\n", err);
610 return err;
611 }
612
613 if (!add)
614 return 0;
615
616 vlan_mapping.index = port + 1;
617 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
618 vlan_mapping.val[0] = 0 /* vid */;
619 vlan_mapping.val[1] = BIT(port) | BIT(cpu_port);
620 vlan_mapping.val[2] = 0;
621 err = gswip_pce_table_entry_write(priv, &vlan_mapping);
622 if (err) {
623 dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
624 return err;
625 }
626
627 return 0;
628}
629
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200630static int gswip_port_enable(struct dsa_switch *ds, int port,
631 struct phy_device *phydev)
632{
633 struct gswip_priv *priv = ds->priv;
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200634 int err;
635
Vivien Didelot74be4ba2019-08-19 16:00:49 -0400636 if (!dsa_is_user_port(ds, port))
637 return 0;
638
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200639 if (!dsa_is_cpu_port(ds, port)) {
640 err = gswip_add_single_port_br(priv, port, true);
641 if (err)
642 return err;
643 }
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200644
645 /* RMON Counter Enable for port */
646 gswip_switch_w(priv, GSWIP_BM_PCFG_CNTEN, GSWIP_BM_PCFGp(port));
647
648 /* enable port fetch/store dma & VLAN Modification */
649 gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_EN |
650 GSWIP_FDMA_PCTRL_VLANMOD_BOTH,
651 GSWIP_FDMA_PCTRLp(port));
652 gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN,
653 GSWIP_SDMA_PCTRLp(port));
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200654
655 if (!dsa_is_cpu_port(ds, port)) {
656 u32 macconf = GSWIP_MDIO_PHY_LINK_AUTO |
657 GSWIP_MDIO_PHY_SPEED_AUTO |
658 GSWIP_MDIO_PHY_FDUP_AUTO |
659 GSWIP_MDIO_PHY_FCONTX_AUTO |
660 GSWIP_MDIO_PHY_FCONRX_AUTO |
661 (phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK);
662
663 gswip_mdio_w(priv, macconf, GSWIP_MDIO_PHYp(port));
664 /* Activate MDIO auto polling */
665 gswip_mdio_mask(priv, 0, BIT(port), GSWIP_MDIO_MDC_CFG0);
666 }
667
668 return 0;
669}
670
Andrew Lunn75104db2019-02-24 20:44:43 +0100671static void gswip_port_disable(struct dsa_switch *ds, int port)
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200672{
673 struct gswip_priv *priv = ds->priv;
674
Vivien Didelot74be4ba2019-08-19 16:00:49 -0400675 if (!dsa_is_user_port(ds, port))
676 return;
677
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200678 if (!dsa_is_cpu_port(ds, port)) {
679 gswip_mdio_mask(priv, GSWIP_MDIO_PHY_LINK_DOWN,
680 GSWIP_MDIO_PHY_LINK_MASK,
681 GSWIP_MDIO_PHYp(port));
682 /* Deactivate MDIO auto polling */
683 gswip_mdio_mask(priv, BIT(port), 0, GSWIP_MDIO_MDC_CFG0);
684 }
685
686 gswip_switch_mask(priv, GSWIP_FDMA_PCTRL_EN, 0,
687 GSWIP_FDMA_PCTRLp(port));
688 gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0,
689 GSWIP_SDMA_PCTRLp(port));
690}
691
692static int gswip_pce_load_microcode(struct gswip_priv *priv)
693{
694 int i;
695 int err;
696
697 gswip_switch_mask(priv, GSWIP_PCE_TBL_CTRL_ADDR_MASK |
698 GSWIP_PCE_TBL_CTRL_OPMOD_MASK,
699 GSWIP_PCE_TBL_CTRL_OPMOD_ADWR, GSWIP_PCE_TBL_CTRL);
700 gswip_switch_w(priv, 0, GSWIP_PCE_TBL_MASK);
701
702 for (i = 0; i < ARRAY_SIZE(gswip_pce_microcode); i++) {
703 gswip_switch_w(priv, i, GSWIP_PCE_TBL_ADDR);
704 gswip_switch_w(priv, gswip_pce_microcode[i].val_0,
705 GSWIP_PCE_TBL_VAL(0));
706 gswip_switch_w(priv, gswip_pce_microcode[i].val_1,
707 GSWIP_PCE_TBL_VAL(1));
708 gswip_switch_w(priv, gswip_pce_microcode[i].val_2,
709 GSWIP_PCE_TBL_VAL(2));
710 gswip_switch_w(priv, gswip_pce_microcode[i].val_3,
711 GSWIP_PCE_TBL_VAL(3));
712
713 /* start the table access: */
714 gswip_switch_mask(priv, 0, GSWIP_PCE_TBL_CTRL_BAS,
715 GSWIP_PCE_TBL_CTRL);
716 err = gswip_switch_r_timeout(priv, GSWIP_PCE_TBL_CTRL,
717 GSWIP_PCE_TBL_CTRL_BAS);
718 if (err)
719 return err;
720 }
721
722 /* tell the switch that the microcode is loaded */
723 gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_MC_VALID,
724 GSWIP_PCE_GCTRL_0);
725
726 return 0;
727}
728
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200729static int gswip_port_vlan_filtering(struct dsa_switch *ds, int port,
Vladimir Olteanbae33f22021-01-09 02:01:50 +0200730 bool vlan_filtering)
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200731{
Vladimir Olteanbae33f22021-01-09 02:01:50 +0200732 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200733 struct gswip_priv *priv = ds->priv;
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +0200734
735 /* Do not allow changing the VLAN filtering options while in bridge */
Vladimir Olteanbae33f22021-01-09 02:01:50 +0200736 if (bridge && !!(priv->port_vlan_filter & BIT(port)) != vlan_filtering)
737 return -EIO;
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200738
739 if (vlan_filtering) {
740 /* Use port based VLAN tag */
741 gswip_switch_mask(priv,
742 GSWIP_PCE_VCTRL_VSR,
743 GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR |
744 GSWIP_PCE_VCTRL_VEMR,
745 GSWIP_PCE_VCTRL(port));
746 gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_TVM, 0,
747 GSWIP_PCE_PCTRL_0p(port));
748 } else {
749 /* Use port based VLAN tag */
750 gswip_switch_mask(priv,
751 GSWIP_PCE_VCTRL_UVR | GSWIP_PCE_VCTRL_VIMR |
752 GSWIP_PCE_VCTRL_VEMR,
753 GSWIP_PCE_VCTRL_VSR,
754 GSWIP_PCE_VCTRL(port));
755 gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_TVM,
756 GSWIP_PCE_PCTRL_0p(port));
757 }
758
759 return 0;
760}
761
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200762static int gswip_setup(struct dsa_switch *ds)
763{
764 struct gswip_priv *priv = ds->priv;
765 unsigned int cpu_port = priv->hw_info->cpu_port;
766 int i;
767 int err;
768
769 gswip_switch_w(priv, GSWIP_SWRES_R0, GSWIP_SWRES);
770 usleep_range(5000, 10000);
771 gswip_switch_w(priv, 0, GSWIP_SWRES);
772
773 /* disable port fetch/store dma on all ports */
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200774 for (i = 0; i < priv->hw_info->max_ports; i++) {
Andrew Lunn75104db2019-02-24 20:44:43 +0100775 gswip_port_disable(ds, i);
Vladimir Olteanbae33f22021-01-09 02:01:50 +0200776 gswip_port_vlan_filtering(ds, i, false);
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200777 }
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200778
779 /* enable Switch */
780 gswip_mdio_mask(priv, 0, GSWIP_MDIO_GLOB_ENABLE, GSWIP_MDIO_GLOB);
781
782 err = gswip_pce_load_microcode(priv);
783 if (err) {
784 dev_err(priv->dev, "writing PCE microcode failed, %i", err);
785 return err;
786 }
787
788 /* Default unknown Broadcast/Multicast/Unicast port maps */
789 gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP1);
790 gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP2);
791 gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP3);
792
793 /* disable PHY auto polling */
794 gswip_mdio_w(priv, 0x0, GSWIP_MDIO_MDC_CFG0);
795 /* Configure the MDIO Clock 2.5 MHz */
796 gswip_mdio_mask(priv, 0xff, 0x09, GSWIP_MDIO_MDC_CFG1);
797
798 /* Disable the xMII link */
Martin Blumenstingl709a3c92021-01-03 02:25:44 +0100799 for (i = 0; i < priv->hw_info->max_ports; i++)
800 gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, i);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200801
802 /* enable special tag insertion on cpu port */
803 gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_STEN,
804 GSWIP_FDMA_PCTRLp(cpu_port));
805
Hauke Mehrtens30d893832019-05-06 00:25:06 +0200806 /* accept special tag in ingress direction */
807 gswip_switch_mask(priv, 0, GSWIP_PCE_PCTRL_0_INGRESS,
808 GSWIP_PCE_PCTRL_0p(cpu_port));
809
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200810 gswip_switch_mask(priv, 0, GSWIP_MAC_CTRL_2_MLEN,
811 GSWIP_MAC_CTRL_2p(cpu_port));
812 gswip_switch_w(priv, VLAN_ETH_FRAME_LEN + 8, GSWIP_MAC_FLEN);
813 gswip_switch_mask(priv, 0, GSWIP_BM_QUEUE_GCTRL_GL_MOD,
814 GSWIP_BM_QUEUE_GCTRL);
815
816 /* VLAN aware Switching */
817 gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_VLAN, GSWIP_PCE_GCTRL_0);
818
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200819 /* Flush MAC Table */
820 gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_MTFL, GSWIP_PCE_GCTRL_0);
821
822 err = gswip_switch_r_timeout(priv, GSWIP_PCE_GCTRL_0,
823 GSWIP_PCE_GCTRL_0_MTFL);
824 if (err) {
825 dev_err(priv->dev, "MAC flushing didn't finish\n");
826 return err;
827 }
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200828
829 gswip_port_enable(ds, cpu_port, NULL);
Vladimir Oltean0ee2af42021-01-16 01:19:19 +0200830
831 ds->configure_vlan_while_not_filtering = false;
832
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200833 return 0;
834}
835
836static enum dsa_tag_protocol gswip_get_tag_protocol(struct dsa_switch *ds,
Florian Fainelli4d776482020-01-07 21:06:05 -0800837 int port,
838 enum dsa_tag_protocol mp)
Hauke Mehrtens14fceff2018-09-09 22:20:39 +0200839{
840 return DSA_TAG_PROTO_GSWIP;
841}
842
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +0200843static int gswip_vlan_active_create(struct gswip_priv *priv,
844 struct net_device *bridge,
845 int fid, u16 vid)
846{
847 struct gswip_pce_table_entry vlan_active = {0,};
848 unsigned int max_ports = priv->hw_info->max_ports;
849 int idx = -1;
850 int err;
851 int i;
852
853 /* Look for a free slot */
854 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
855 if (!priv->vlans[i].bridge) {
856 idx = i;
857 break;
858 }
859 }
860
861 if (idx == -1)
862 return -ENOSPC;
863
864 if (fid == -1)
865 fid = idx;
866
867 vlan_active.index = idx;
868 vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN;
869 vlan_active.key[0] = vid;
870 vlan_active.val[0] = fid;
871 vlan_active.valid = true;
872
873 err = gswip_pce_table_entry_write(priv, &vlan_active);
874 if (err) {
875 dev_err(priv->dev, "failed to write active VLAN: %d\n", err);
876 return err;
877 }
878
879 priv->vlans[idx].bridge = bridge;
880 priv->vlans[idx].vid = vid;
881 priv->vlans[idx].fid = fid;
882
883 return idx;
884}
885
886static int gswip_vlan_active_remove(struct gswip_priv *priv, int idx)
887{
888 struct gswip_pce_table_entry vlan_active = {0,};
889 int err;
890
891 vlan_active.index = idx;
892 vlan_active.table = GSWIP_TABLE_ACTIVE_VLAN;
893 vlan_active.valid = false;
894 err = gswip_pce_table_entry_write(priv, &vlan_active);
895 if (err)
896 dev_err(priv->dev, "failed to delete active VLAN: %d\n", err);
897 priv->vlans[idx].bridge = NULL;
898
899 return err;
900}
901
902static int gswip_vlan_add_unaware(struct gswip_priv *priv,
903 struct net_device *bridge, int port)
904{
905 struct gswip_pce_table_entry vlan_mapping = {0,};
906 unsigned int max_ports = priv->hw_info->max_ports;
907 unsigned int cpu_port = priv->hw_info->cpu_port;
908 bool active_vlan_created = false;
909 int idx = -1;
910 int i;
911 int err;
912
913 /* Check if there is already a page for this bridge */
914 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
915 if (priv->vlans[i].bridge == bridge) {
916 idx = i;
917 break;
918 }
919 }
920
921 /* If this bridge is not programmed yet, add a Active VLAN table
922 * entry in a free slot and prepare the VLAN mapping table entry.
923 */
924 if (idx == -1) {
925 idx = gswip_vlan_active_create(priv, bridge, -1, 0);
926 if (idx < 0)
927 return idx;
928 active_vlan_created = true;
929
930 vlan_mapping.index = idx;
931 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
932 /* VLAN ID byte, maps to the VLAN ID of vlan active table */
933 vlan_mapping.val[0] = 0;
934 } else {
935 /* Read the existing VLAN mapping entry from the switch */
936 vlan_mapping.index = idx;
937 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
938 err = gswip_pce_table_entry_read(priv, &vlan_mapping);
939 if (err) {
940 dev_err(priv->dev, "failed to read VLAN mapping: %d\n",
941 err);
942 return err;
943 }
944 }
945
946 /* Update the VLAN mapping entry and write it to the switch */
947 vlan_mapping.val[1] |= BIT(cpu_port);
948 vlan_mapping.val[1] |= BIT(port);
949 err = gswip_pce_table_entry_write(priv, &vlan_mapping);
950 if (err) {
951 dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
952 /* In case an Active VLAN was creaetd delete it again */
953 if (active_vlan_created)
954 gswip_vlan_active_remove(priv, idx);
955 return err;
956 }
957
958 gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port));
959 return 0;
960}
961
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +0200962static int gswip_vlan_add_aware(struct gswip_priv *priv,
963 struct net_device *bridge, int port,
964 u16 vid, bool untagged,
965 bool pvid)
966{
967 struct gswip_pce_table_entry vlan_mapping = {0,};
968 unsigned int max_ports = priv->hw_info->max_ports;
969 unsigned int cpu_port = priv->hw_info->cpu_port;
970 bool active_vlan_created = false;
971 int idx = -1;
972 int fid = -1;
973 int i;
974 int err;
975
976 /* Check if there is already a page for this bridge */
977 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
978 if (priv->vlans[i].bridge == bridge) {
979 if (fid != -1 && fid != priv->vlans[i].fid)
980 dev_err(priv->dev, "one bridge with multiple flow ids\n");
981 fid = priv->vlans[i].fid;
982 if (priv->vlans[i].vid == vid) {
983 idx = i;
984 break;
985 }
986 }
987 }
988
989 /* If this bridge is not programmed yet, add a Active VLAN table
990 * entry in a free slot and prepare the VLAN mapping table entry.
991 */
992 if (idx == -1) {
993 idx = gswip_vlan_active_create(priv, bridge, fid, vid);
994 if (idx < 0)
995 return idx;
996 active_vlan_created = true;
997
998 vlan_mapping.index = idx;
999 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
1000 /* VLAN ID byte, maps to the VLAN ID of vlan active table */
1001 vlan_mapping.val[0] = vid;
1002 } else {
1003 /* Read the existing VLAN mapping entry from the switch */
1004 vlan_mapping.index = idx;
1005 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
1006 err = gswip_pce_table_entry_read(priv, &vlan_mapping);
1007 if (err) {
1008 dev_err(priv->dev, "failed to read VLAN mapping: %d\n",
1009 err);
1010 return err;
1011 }
1012 }
1013
1014 vlan_mapping.val[0] = vid;
1015 /* Update the VLAN mapping entry and write it to the switch */
1016 vlan_mapping.val[1] |= BIT(cpu_port);
1017 vlan_mapping.val[2] |= BIT(cpu_port);
1018 vlan_mapping.val[1] |= BIT(port);
1019 if (untagged)
1020 vlan_mapping.val[2] &= ~BIT(port);
1021 else
1022 vlan_mapping.val[2] |= BIT(port);
1023 err = gswip_pce_table_entry_write(priv, &vlan_mapping);
1024 if (err) {
1025 dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
1026 /* In case an Active VLAN was creaetd delete it again */
1027 if (active_vlan_created)
1028 gswip_vlan_active_remove(priv, idx);
1029 return err;
1030 }
1031
1032 if (pvid)
1033 gswip_switch_w(priv, idx, GSWIP_PCE_DEFPVID(port));
1034
1035 return 0;
1036}
1037
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +02001038static int gswip_vlan_remove(struct gswip_priv *priv,
1039 struct net_device *bridge, int port,
1040 u16 vid, bool pvid, bool vlan_aware)
1041{
1042 struct gswip_pce_table_entry vlan_mapping = {0,};
1043 unsigned int max_ports = priv->hw_info->max_ports;
1044 unsigned int cpu_port = priv->hw_info->cpu_port;
1045 int idx = -1;
1046 int i;
1047 int err;
1048
1049 /* Check if there is already a page for this bridge */
1050 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
1051 if (priv->vlans[i].bridge == bridge &&
1052 (!vlan_aware || priv->vlans[i].vid == vid)) {
1053 idx = i;
1054 break;
1055 }
1056 }
1057
1058 if (idx == -1) {
1059 dev_err(priv->dev, "bridge to leave does not exists\n");
1060 return -ENOENT;
1061 }
1062
1063 vlan_mapping.index = idx;
1064 vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
1065 err = gswip_pce_table_entry_read(priv, &vlan_mapping);
1066 if (err) {
1067 dev_err(priv->dev, "failed to read VLAN mapping: %d\n", err);
1068 return err;
1069 }
1070
1071 vlan_mapping.val[1] &= ~BIT(port);
1072 vlan_mapping.val[2] &= ~BIT(port);
1073 err = gswip_pce_table_entry_write(priv, &vlan_mapping);
1074 if (err) {
1075 dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
1076 return err;
1077 }
1078
1079 /* In case all ports are removed from the bridge, remove the VLAN */
1080 if ((vlan_mapping.val[1] & ~BIT(cpu_port)) == 0) {
1081 err = gswip_vlan_active_remove(priv, idx);
1082 if (err) {
1083 dev_err(priv->dev, "failed to write active VLAN: %d\n",
1084 err);
1085 return err;
1086 }
1087 }
1088
1089 /* GSWIP 2.2 (GRX300) and later program here the VID directly. */
1090 if (pvid)
1091 gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port));
1092
1093 return 0;
1094}
1095
1096static int gswip_port_bridge_join(struct dsa_switch *ds, int port,
1097 struct net_device *bridge)
1098{
1099 struct gswip_priv *priv = ds->priv;
1100 int err;
1101
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001102 /* When the bridge uses VLAN filtering we have to configure VLAN
1103 * specific bridges. No bridge is configured here.
1104 */
1105 if (!br_vlan_enabled(bridge)) {
1106 err = gswip_vlan_add_unaware(priv, bridge, port);
1107 if (err)
1108 return err;
1109 priv->port_vlan_filter &= ~BIT(port);
1110 } else {
1111 priv->port_vlan_filter |= BIT(port);
1112 }
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +02001113 return gswip_add_single_port_br(priv, port, false);
1114}
1115
1116static void gswip_port_bridge_leave(struct dsa_switch *ds, int port,
1117 struct net_device *bridge)
1118{
1119 struct gswip_priv *priv = ds->priv;
1120
1121 gswip_add_single_port_br(priv, port, true);
1122
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001123 /* When the bridge uses VLAN filtering we have to configure VLAN
1124 * specific bridges. No bridge is configured here.
1125 */
1126 if (!br_vlan_enabled(bridge))
1127 gswip_vlan_remove(priv, bridge, port, 0, true, false);
1128}
1129
1130static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02001131 const struct switchdev_obj_port_vlan *vlan,
1132 struct netlink_ext_ack *extack)
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001133{
1134 struct gswip_priv *priv = ds->priv;
1135 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
1136 unsigned int max_ports = priv->hw_info->max_ports;
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001137 int pos = max_ports;
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001138 int i, idx = -1;
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001139
1140 /* We only support VLAN filtering on bridges */
1141 if (!dsa_is_cpu_port(ds, port) && !bridge)
1142 return -EOPNOTSUPP;
1143
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001144 /* Check if there is already a page for this VLAN */
1145 for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
1146 if (priv->vlans[i].bridge == bridge &&
1147 priv->vlans[i].vid == vlan->vid) {
1148 idx = i;
1149 break;
1150 }
1151 }
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001152
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001153 /* If this VLAN is not programmed yet, we have to reserve
1154 * one entry in the VLAN table. Make sure we start at the
1155 * next position round.
1156 */
1157 if (idx == -1) {
1158 /* Look for a free slot */
1159 for (; pos < ARRAY_SIZE(priv->vlans); pos++) {
1160 if (!priv->vlans[pos].bridge) {
1161 idx = pos;
1162 pos++;
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001163 break;
1164 }
1165 }
1166
Vladimir Oltean31046a52021-02-13 22:43:18 +02001167 if (idx == -1) {
1168 NL_SET_ERR_MSG_MOD(extack, "No slot in VLAN table");
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001169 return -ENOSPC;
Vladimir Oltean31046a52021-02-13 22:43:18 +02001170 }
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001171 }
1172
1173 return 0;
1174}
1175
Vladimir Oltean1958d582021-01-09 02:01:53 +02001176static int gswip_port_vlan_add(struct dsa_switch *ds, int port,
Vladimir Oltean31046a52021-02-13 22:43:18 +02001177 const struct switchdev_obj_port_vlan *vlan,
1178 struct netlink_ext_ack *extack)
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001179{
1180 struct gswip_priv *priv = ds->priv;
1181 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
1182 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1183 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Vladimir Oltean1958d582021-01-09 02:01:53 +02001184 int err;
1185
Vladimir Oltean31046a52021-02-13 22:43:18 +02001186 err = gswip_port_vlan_prepare(ds, port, vlan, extack);
Vladimir Oltean1958d582021-01-09 02:01:53 +02001187 if (err)
1188 return err;
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001189
1190 /* We have to receive all packets on the CPU port and should not
1191 * do any VLAN filtering here. This is also called with bridge
1192 * NULL and then we do not know for which bridge to configure
1193 * this.
1194 */
1195 if (dsa_is_cpu_port(ds, port))
Vladimir Oltean1958d582021-01-09 02:01:53 +02001196 return 0;
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001197
Vladimir Oltean1958d582021-01-09 02:01:53 +02001198 return gswip_vlan_add_aware(priv, bridge, port, vlan->vid,
1199 untagged, pvid);
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001200}
1201
1202static int gswip_port_vlan_del(struct dsa_switch *ds, int port,
1203 const struct switchdev_obj_port_vlan *vlan)
1204{
1205 struct gswip_priv *priv = ds->priv;
1206 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
1207 bool pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001208
1209 /* We have to receive all packets on the CPU port and should not
1210 * do any VLAN filtering here. This is also called with bridge
1211 * NULL and then we do not know for which bridge to configure
1212 * this.
1213 */
1214 if (dsa_is_cpu_port(ds, port))
1215 return 0;
1216
Vladimir Olteanb7a9e0d2021-01-09 02:01:46 +02001217 return gswip_vlan_remove(priv, bridge, port, vlan->vid, pvid, true);
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +02001218}
1219
Hauke Mehrtens45813482019-05-06 00:25:09 +02001220static void gswip_port_fast_age(struct dsa_switch *ds, int port)
1221{
1222 struct gswip_priv *priv = ds->priv;
1223 struct gswip_pce_table_entry mac_bridge = {0,};
1224 int i;
1225 int err;
1226
1227 for (i = 0; i < 2048; i++) {
1228 mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE;
1229 mac_bridge.index = i;
1230
1231 err = gswip_pce_table_entry_read(priv, &mac_bridge);
1232 if (err) {
Colin Ian Kingd6759172019-05-08 11:22:09 +01001233 dev_err(priv->dev, "failed to read mac bridge: %d\n",
Hauke Mehrtens45813482019-05-06 00:25:09 +02001234 err);
1235 return;
1236 }
1237
1238 if (!mac_bridge.valid)
1239 continue;
1240
1241 if (mac_bridge.val[1] & GSWIP_TABLE_MAC_BRIDGE_STATIC)
1242 continue;
1243
1244 if (((mac_bridge.val[0] & GENMASK(7, 4)) >> 4) != port)
1245 continue;
1246
1247 mac_bridge.valid = false;
1248 err = gswip_pce_table_entry_write(priv, &mac_bridge);
1249 if (err) {
Colin Ian Kingd6759172019-05-08 11:22:09 +01001250 dev_err(priv->dev, "failed to write mac bridge: %d\n",
Hauke Mehrtens45813482019-05-06 00:25:09 +02001251 err);
1252 return;
1253 }
1254 }
1255}
1256
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +02001257static void gswip_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
1258{
1259 struct gswip_priv *priv = ds->priv;
1260 u32 stp_state;
1261
1262 switch (state) {
1263 case BR_STATE_DISABLED:
1264 gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0,
1265 GSWIP_SDMA_PCTRLp(port));
1266 return;
1267 case BR_STATE_BLOCKING:
1268 case BR_STATE_LISTENING:
1269 stp_state = GSWIP_PCE_PCTRL_0_PSTATE_LISTEN;
1270 break;
1271 case BR_STATE_LEARNING:
1272 stp_state = GSWIP_PCE_PCTRL_0_PSTATE_LEARNING;
1273 break;
1274 case BR_STATE_FORWARDING:
1275 stp_state = GSWIP_PCE_PCTRL_0_PSTATE_FORWARDING;
1276 break;
1277 default:
1278 dev_err(priv->dev, "invalid STP state: %d\n", state);
1279 return;
1280 }
1281
1282 gswip_switch_mask(priv, 0, GSWIP_SDMA_PCTRL_EN,
1283 GSWIP_SDMA_PCTRLp(port));
1284 gswip_switch_mask(priv, GSWIP_PCE_PCTRL_0_PSTATE_MASK, stp_state,
1285 GSWIP_PCE_PCTRL_0p(port));
1286}
1287
Hauke Mehrtens58c59ef2019-05-06 00:25:10 +02001288static int gswip_port_fdb(struct dsa_switch *ds, int port,
1289 const unsigned char *addr, u16 vid, bool add)
1290{
1291 struct gswip_priv *priv = ds->priv;
1292 struct net_device *bridge = dsa_to_port(ds, port)->bridge_dev;
1293 struct gswip_pce_table_entry mac_bridge = {0,};
1294 unsigned int cpu_port = priv->hw_info->cpu_port;
1295 int fid = -1;
1296 int i;
1297 int err;
1298
1299 if (!bridge)
1300 return -EINVAL;
1301
1302 for (i = cpu_port; i < ARRAY_SIZE(priv->vlans); i++) {
1303 if (priv->vlans[i].bridge == bridge) {
1304 fid = priv->vlans[i].fid;
1305 break;
1306 }
1307 }
1308
1309 if (fid == -1) {
1310 dev_err(priv->dev, "Port not part of a bridge\n");
1311 return -EINVAL;
1312 }
1313
1314 mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE;
1315 mac_bridge.key_mode = true;
1316 mac_bridge.key[0] = addr[5] | (addr[4] << 8);
1317 mac_bridge.key[1] = addr[3] | (addr[2] << 8);
1318 mac_bridge.key[2] = addr[1] | (addr[0] << 8);
1319 mac_bridge.key[3] = fid;
1320 mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
1321 mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_STATIC;
1322 mac_bridge.valid = add;
1323
1324 err = gswip_pce_table_entry_write(priv, &mac_bridge);
1325 if (err)
Colin Ian Kingd6759172019-05-08 11:22:09 +01001326 dev_err(priv->dev, "failed to write mac bridge: %d\n", err);
Hauke Mehrtens58c59ef2019-05-06 00:25:10 +02001327
1328 return err;
1329}
1330
1331static int gswip_port_fdb_add(struct dsa_switch *ds, int port,
1332 const unsigned char *addr, u16 vid)
1333{
1334 return gswip_port_fdb(ds, port, addr, vid, true);
1335}
1336
1337static int gswip_port_fdb_del(struct dsa_switch *ds, int port,
1338 const unsigned char *addr, u16 vid)
1339{
1340 return gswip_port_fdb(ds, port, addr, vid, false);
1341}
1342
1343static int gswip_port_fdb_dump(struct dsa_switch *ds, int port,
1344 dsa_fdb_dump_cb_t *cb, void *data)
1345{
1346 struct gswip_priv *priv = ds->priv;
1347 struct gswip_pce_table_entry mac_bridge = {0,};
1348 unsigned char addr[6];
1349 int i;
1350 int err;
1351
1352 for (i = 0; i < 2048; i++) {
1353 mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE;
1354 mac_bridge.index = i;
1355
1356 err = gswip_pce_table_entry_read(priv, &mac_bridge);
1357 if (err) {
Colin Ian Kingd6759172019-05-08 11:22:09 +01001358 dev_err(priv->dev, "failed to write mac bridge: %d\n",
Hauke Mehrtens58c59ef2019-05-06 00:25:10 +02001359 err);
1360 return err;
1361 }
1362
1363 if (!mac_bridge.valid)
1364 continue;
1365
1366 addr[5] = mac_bridge.key[0] & 0xff;
1367 addr[4] = (mac_bridge.key[0] >> 8) & 0xff;
1368 addr[3] = mac_bridge.key[1] & 0xff;
1369 addr[2] = (mac_bridge.key[1] >> 8) & 0xff;
1370 addr[1] = mac_bridge.key[2] & 0xff;
1371 addr[0] = (mac_bridge.key[2] >> 8) & 0xff;
1372 if (mac_bridge.val[1] & GSWIP_TABLE_MAC_BRIDGE_STATIC) {
1373 if (mac_bridge.val[0] & BIT(port))
1374 cb(addr, 0, true, data);
1375 } else {
1376 if (((mac_bridge.val[0] & GENMASK(7, 4)) >> 4) == port)
1377 cb(addr, 0, false, data);
1378 }
1379 }
1380 return 0;
1381}
1382
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001383static void gswip_phylink_validate(struct dsa_switch *ds, int port,
1384 unsigned long *supported,
1385 struct phylink_link_state *state)
1386{
1387 __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
1388
1389 switch (port) {
1390 case 0:
1391 case 1:
1392 if (!phy_interface_mode_is_rgmii(state->interface) &&
1393 state->interface != PHY_INTERFACE_MODE_MII &&
1394 state->interface != PHY_INTERFACE_MODE_REVMII &&
Hauke Mehrtens0e630b52018-09-15 14:08:48 +02001395 state->interface != PHY_INTERFACE_MODE_RMII)
1396 goto unsupported;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001397 break;
1398 case 2:
1399 case 3:
1400 case 4:
Hauke Mehrtens0e630b52018-09-15 14:08:48 +02001401 if (state->interface != PHY_INTERFACE_MODE_INTERNAL)
1402 goto unsupported;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001403 break;
1404 case 5:
1405 if (!phy_interface_mode_is_rgmii(state->interface) &&
Hauke Mehrtens0e630b52018-09-15 14:08:48 +02001406 state->interface != PHY_INTERFACE_MODE_INTERNAL)
1407 goto unsupported;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001408 break;
Hauke Mehrtens0e630b52018-09-15 14:08:48 +02001409 default:
1410 bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
1411 dev_err(ds->dev, "Unsupported port: %i\n", port);
1412 return;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001413 }
1414
1415 /* Allow all the expected bits */
1416 phylink_set(mask, Autoneg);
1417 phylink_set_port_modes(mask);
1418 phylink_set(mask, Pause);
1419 phylink_set(mask, Asym_Pause);
1420
Aleksander Jan Bajkowski35454542021-01-07 20:58:18 +01001421 /* With the exclusion of MII, Reverse MII and Reduced MII, we
1422 * support Gigabit, including Half duplex
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001423 */
1424 if (state->interface != PHY_INTERFACE_MODE_MII &&
Aleksander Jan Bajkowski35454542021-01-07 20:58:18 +01001425 state->interface != PHY_INTERFACE_MODE_REVMII &&
1426 state->interface != PHY_INTERFACE_MODE_RMII) {
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001427 phylink_set(mask, 1000baseT_Full);
1428 phylink_set(mask, 1000baseT_Half);
1429 }
1430
1431 phylink_set(mask, 10baseT_Half);
1432 phylink_set(mask, 10baseT_Full);
1433 phylink_set(mask, 100baseT_Half);
1434 phylink_set(mask, 100baseT_Full);
1435
1436 bitmap_and(supported, supported, mask,
1437 __ETHTOOL_LINK_MODE_MASK_NBITS);
1438 bitmap_and(state->advertising, state->advertising, mask,
1439 __ETHTOOL_LINK_MODE_MASK_NBITS);
Hauke Mehrtens0e630b52018-09-15 14:08:48 +02001440 return;
1441
1442unsupported:
1443 bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
Martin Blumenstingl4d3da2d2020-06-07 15:02:58 +02001444 dev_err(ds->dev, "Unsupported interface '%s' for port %d\n",
1445 phy_modes(state->interface), port);
Hauke Mehrtens0e630b52018-09-15 14:08:48 +02001446 return;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001447}
1448
1449static void gswip_phylink_mac_config(struct dsa_switch *ds, int port,
1450 unsigned int mode,
1451 const struct phylink_link_state *state)
1452{
1453 struct gswip_priv *priv = ds->priv;
1454 u32 miicfg = 0;
1455
1456 miicfg |= GSWIP_MII_CFG_LDCLKDIS;
1457
1458 switch (state->interface) {
1459 case PHY_INTERFACE_MODE_MII:
1460 case PHY_INTERFACE_MODE_INTERNAL:
1461 miicfg |= GSWIP_MII_CFG_MODE_MIIM;
1462 break;
1463 case PHY_INTERFACE_MODE_REVMII:
1464 miicfg |= GSWIP_MII_CFG_MODE_MIIP;
1465 break;
1466 case PHY_INTERFACE_MODE_RMII:
1467 miicfg |= GSWIP_MII_CFG_MODE_RMIIM;
1468 break;
1469 case PHY_INTERFACE_MODE_RGMII:
1470 case PHY_INTERFACE_MODE_RGMII_ID:
1471 case PHY_INTERFACE_MODE_RGMII_RXID:
1472 case PHY_INTERFACE_MODE_RGMII_TXID:
1473 miicfg |= GSWIP_MII_CFG_MODE_RGMII;
1474 break;
1475 default:
1476 dev_err(ds->dev,
1477 "Unsupported interface: %d\n", state->interface);
1478 return;
1479 }
1480 gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_MODE_MASK, miicfg, port);
1481
1482 switch (state->interface) {
1483 case PHY_INTERFACE_MODE_RGMII_ID:
1484 gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_TXDLY_MASK |
1485 GSWIP_MII_PCDU_RXDLY_MASK, 0, port);
1486 break;
1487 case PHY_INTERFACE_MODE_RGMII_RXID:
1488 gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_RXDLY_MASK, 0, port);
1489 break;
1490 case PHY_INTERFACE_MODE_RGMII_TXID:
1491 gswip_mii_mask_pcdu(priv, GSWIP_MII_PCDU_TXDLY_MASK, 0, port);
1492 break;
1493 default:
1494 break;
1495 }
1496}
1497
1498static void gswip_phylink_mac_link_down(struct dsa_switch *ds, int port,
1499 unsigned int mode,
1500 phy_interface_t interface)
1501{
1502 struct gswip_priv *priv = ds->priv;
1503
1504 gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, port);
1505}
1506
1507static void gswip_phylink_mac_link_up(struct dsa_switch *ds, int port,
1508 unsigned int mode,
1509 phy_interface_t interface,
Russell King5b502a72020-02-26 10:23:46 +00001510 struct phy_device *phydev,
1511 int speed, int duplex,
1512 bool tx_pause, bool rx_pause)
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001513{
1514 struct gswip_priv *priv = ds->priv;
1515
Martin Blumenstinglc1a9ec72021-01-03 02:25:43 +01001516 gswip_mii_mask_cfg(priv, 0, GSWIP_MII_CFG_EN, port);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001517}
1518
1519static void gswip_get_strings(struct dsa_switch *ds, int port, u32 stringset,
1520 uint8_t *data)
1521{
1522 int i;
1523
1524 if (stringset != ETH_SS_STATS)
1525 return;
1526
1527 for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++)
1528 strncpy(data + i * ETH_GSTRING_LEN, gswip_rmon_cnt[i].name,
1529 ETH_GSTRING_LEN);
1530}
1531
1532static u32 gswip_bcm_ram_entry_read(struct gswip_priv *priv, u32 table,
1533 u32 index)
1534{
1535 u32 result;
1536 int err;
1537
1538 gswip_switch_w(priv, index, GSWIP_BM_RAM_ADDR);
1539 gswip_switch_mask(priv, GSWIP_BM_RAM_CTRL_ADDR_MASK |
1540 GSWIP_BM_RAM_CTRL_OPMOD,
1541 table | GSWIP_BM_RAM_CTRL_BAS,
1542 GSWIP_BM_RAM_CTRL);
1543
1544 err = gswip_switch_r_timeout(priv, GSWIP_BM_RAM_CTRL,
1545 GSWIP_BM_RAM_CTRL_BAS);
1546 if (err) {
1547 dev_err(priv->dev, "timeout while reading table: %u, index: %u",
1548 table, index);
1549 return 0;
1550 }
1551
1552 result = gswip_switch_r(priv, GSWIP_BM_RAM_VAL(0));
1553 result |= gswip_switch_r(priv, GSWIP_BM_RAM_VAL(1)) << 16;
1554
1555 return result;
1556}
1557
1558static void gswip_get_ethtool_stats(struct dsa_switch *ds, int port,
1559 uint64_t *data)
1560{
1561 struct gswip_priv *priv = ds->priv;
1562 const struct gswip_rmon_cnt_desc *rmon_cnt;
1563 int i;
1564 u64 high;
1565
1566 for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++) {
1567 rmon_cnt = &gswip_rmon_cnt[i];
1568
1569 data[i] = gswip_bcm_ram_entry_read(priv, port,
1570 rmon_cnt->offset);
1571 if (rmon_cnt->size == 2) {
1572 high = gswip_bcm_ram_entry_read(priv, port,
1573 rmon_cnt->offset + 1);
1574 data[i] |= high << 32;
1575 }
1576 }
1577}
1578
1579static int gswip_get_sset_count(struct dsa_switch *ds, int port, int sset)
1580{
1581 if (sset != ETH_SS_STATS)
1582 return 0;
1583
1584 return ARRAY_SIZE(gswip_rmon_cnt);
1585}
1586
1587static const struct dsa_switch_ops gswip_switch_ops = {
1588 .get_tag_protocol = gswip_get_tag_protocol,
1589 .setup = gswip_setup,
1590 .port_enable = gswip_port_enable,
1591 .port_disable = gswip_port_disable,
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +02001592 .port_bridge_join = gswip_port_bridge_join,
1593 .port_bridge_leave = gswip_port_bridge_leave,
Hauke Mehrtens45813482019-05-06 00:25:09 +02001594 .port_fast_age = gswip_port_fast_age,
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001595 .port_vlan_filtering = gswip_port_vlan_filtering,
Hauke Mehrtens9bbb1c02019-05-06 00:25:08 +02001596 .port_vlan_add = gswip_port_vlan_add,
1597 .port_vlan_del = gswip_port_vlan_del,
Hauke Mehrtens8206e0c2019-05-06 00:25:07 +02001598 .port_stp_state_set = gswip_port_stp_state_set,
Hauke Mehrtens58c59ef2019-05-06 00:25:10 +02001599 .port_fdb_add = gswip_port_fdb_add,
1600 .port_fdb_del = gswip_port_fdb_del,
1601 .port_fdb_dump = gswip_port_fdb_dump,
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001602 .phylink_validate = gswip_phylink_validate,
1603 .phylink_mac_config = gswip_phylink_mac_config,
1604 .phylink_mac_link_down = gswip_phylink_mac_link_down,
1605 .phylink_mac_link_up = gswip_phylink_mac_link_up,
1606 .get_strings = gswip_get_strings,
1607 .get_ethtool_stats = gswip_get_ethtool_stats,
1608 .get_sset_count = gswip_get_sset_count,
1609};
1610
1611static const struct xway_gphy_match_data xrx200a1x_gphy_data = {
1612 .fe_firmware_name = "lantiq/xrx200_phy22f_a14.bin",
1613 .ge_firmware_name = "lantiq/xrx200_phy11g_a14.bin",
1614};
1615
1616static const struct xway_gphy_match_data xrx200a2x_gphy_data = {
1617 .fe_firmware_name = "lantiq/xrx200_phy22f_a22.bin",
1618 .ge_firmware_name = "lantiq/xrx200_phy11g_a22.bin",
1619};
1620
1621static const struct xway_gphy_match_data xrx300_gphy_data = {
1622 .fe_firmware_name = "lantiq/xrx300_phy22f_a21.bin",
1623 .ge_firmware_name = "lantiq/xrx300_phy11g_a21.bin",
1624};
1625
1626static const struct of_device_id xway_gphy_match[] = {
1627 { .compatible = "lantiq,xrx200-gphy-fw", .data = NULL },
1628 { .compatible = "lantiq,xrx200a1x-gphy-fw", .data = &xrx200a1x_gphy_data },
1629 { .compatible = "lantiq,xrx200a2x-gphy-fw", .data = &xrx200a2x_gphy_data },
1630 { .compatible = "lantiq,xrx300-gphy-fw", .data = &xrx300_gphy_data },
1631 { .compatible = "lantiq,xrx330-gphy-fw", .data = &xrx300_gphy_data },
1632 {},
1633};
1634
1635static int gswip_gphy_fw_load(struct gswip_priv *priv, struct gswip_gphy_fw *gphy_fw)
1636{
1637 struct device *dev = priv->dev;
1638 const struct firmware *fw;
1639 void *fw_addr;
1640 dma_addr_t dma_addr;
1641 dma_addr_t dev_addr;
1642 size_t size;
1643 int ret;
1644
1645 ret = clk_prepare_enable(gphy_fw->clk_gate);
1646 if (ret)
1647 return ret;
1648
1649 reset_control_assert(gphy_fw->reset);
1650
1651 ret = request_firmware(&fw, gphy_fw->fw_name, dev);
1652 if (ret) {
1653 dev_err(dev, "failed to load firmware: %s, error: %i\n",
1654 gphy_fw->fw_name, ret);
1655 return ret;
1656 }
1657
1658 /* GPHY cores need the firmware code in a persistent and contiguous
1659 * memory area with a 16 kB boundary aligned start address.
1660 */
1661 size = fw->size + XRX200_GPHY_FW_ALIGN;
1662
1663 fw_addr = dmam_alloc_coherent(dev, size, &dma_addr, GFP_KERNEL);
1664 if (fw_addr) {
1665 fw_addr = PTR_ALIGN(fw_addr, XRX200_GPHY_FW_ALIGN);
1666 dev_addr = ALIGN(dma_addr, XRX200_GPHY_FW_ALIGN);
1667 memcpy(fw_addr, fw->data, fw->size);
1668 } else {
1669 dev_err(dev, "failed to alloc firmware memory\n");
1670 release_firmware(fw);
1671 return -ENOMEM;
1672 }
1673
1674 release_firmware(fw);
1675
1676 ret = regmap_write(priv->rcu_regmap, gphy_fw->fw_addr_offset, dev_addr);
1677 if (ret)
1678 return ret;
1679
1680 reset_control_deassert(gphy_fw->reset);
1681
1682 return ret;
1683}
1684
1685static int gswip_gphy_fw_probe(struct gswip_priv *priv,
1686 struct gswip_gphy_fw *gphy_fw,
1687 struct device_node *gphy_fw_np, int i)
1688{
1689 struct device *dev = priv->dev;
1690 u32 gphy_mode;
1691 int ret;
1692 char gphyname[10];
1693
1694 snprintf(gphyname, sizeof(gphyname), "gphy%d", i);
1695
1696 gphy_fw->clk_gate = devm_clk_get(dev, gphyname);
1697 if (IS_ERR(gphy_fw->clk_gate)) {
1698 dev_err(dev, "Failed to lookup gate clock\n");
1699 return PTR_ERR(gphy_fw->clk_gate);
1700 }
1701
1702 ret = of_property_read_u32(gphy_fw_np, "reg", &gphy_fw->fw_addr_offset);
1703 if (ret)
1704 return ret;
1705
1706 ret = of_property_read_u32(gphy_fw_np, "lantiq,gphy-mode", &gphy_mode);
1707 /* Default to GE mode */
1708 if (ret)
1709 gphy_mode = GPHY_MODE_GE;
1710
1711 switch (gphy_mode) {
1712 case GPHY_MODE_FE:
1713 gphy_fw->fw_name = priv->gphy_fw_name_cfg->fe_firmware_name;
1714 break;
1715 case GPHY_MODE_GE:
1716 gphy_fw->fw_name = priv->gphy_fw_name_cfg->ge_firmware_name;
1717 break;
1718 default:
1719 dev_err(dev, "Unknown GPHY mode %d\n", gphy_mode);
1720 return -EINVAL;
1721 }
1722
1723 gphy_fw->reset = of_reset_control_array_get_exclusive(gphy_fw_np);
Wei Yongjunf592e0b2018-09-15 01:33:38 +00001724 if (IS_ERR(gphy_fw->reset)) {
1725 if (PTR_ERR(gphy_fw->reset) != -EPROBE_DEFER)
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001726 dev_err(dev, "Failed to lookup gphy reset\n");
Wei Yongjunf592e0b2018-09-15 01:33:38 +00001727 return PTR_ERR(gphy_fw->reset);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001728 }
1729
1730 return gswip_gphy_fw_load(priv, gphy_fw);
1731}
1732
1733static void gswip_gphy_fw_remove(struct gswip_priv *priv,
1734 struct gswip_gphy_fw *gphy_fw)
1735{
1736 int ret;
1737
1738 /* check if the device was fully probed */
1739 if (!gphy_fw->fw_name)
1740 return;
1741
1742 ret = regmap_write(priv->rcu_regmap, gphy_fw->fw_addr_offset, 0);
1743 if (ret)
1744 dev_err(priv->dev, "can not reset GPHY FW pointer");
1745
1746 clk_disable_unprepare(gphy_fw->clk_gate);
1747
1748 reset_control_put(gphy_fw->reset);
1749}
1750
1751static int gswip_gphy_fw_list(struct gswip_priv *priv,
1752 struct device_node *gphy_fw_list_np, u32 version)
1753{
1754 struct device *dev = priv->dev;
1755 struct device_node *gphy_fw_np;
1756 const struct of_device_id *match;
1757 int err;
1758 int i = 0;
1759
Hauke Mehrtens0e630b52018-09-15 14:08:48 +02001760 /* The VRX200 rev 1.1 uses the GSWIP 2.0 and needs the older
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001761 * GPHY firmware. The VRX200 rev 1.2 uses the GSWIP 2.1 and also
1762 * needs a different GPHY firmware.
1763 */
1764 if (of_device_is_compatible(gphy_fw_list_np, "lantiq,xrx200-gphy-fw")) {
1765 switch (version) {
1766 case GSWIP_VERSION_2_0:
1767 priv->gphy_fw_name_cfg = &xrx200a1x_gphy_data;
1768 break;
1769 case GSWIP_VERSION_2_1:
1770 priv->gphy_fw_name_cfg = &xrx200a2x_gphy_data;
1771 break;
1772 default:
1773 dev_err(dev, "unknown GSWIP version: 0x%x", version);
1774 return -ENOENT;
1775 }
1776 }
1777
1778 match = of_match_node(xway_gphy_match, gphy_fw_list_np);
1779 if (match && match->data)
1780 priv->gphy_fw_name_cfg = match->data;
1781
1782 if (!priv->gphy_fw_name_cfg) {
1783 dev_err(dev, "GPHY compatible type not supported");
1784 return -ENOENT;
1785 }
1786
1787 priv->num_gphy_fw = of_get_available_child_count(gphy_fw_list_np);
1788 if (!priv->num_gphy_fw)
1789 return -ENOENT;
1790
1791 priv->rcu_regmap = syscon_regmap_lookup_by_phandle(gphy_fw_list_np,
1792 "lantiq,rcu");
1793 if (IS_ERR(priv->rcu_regmap))
1794 return PTR_ERR(priv->rcu_regmap);
1795
1796 priv->gphy_fw = devm_kmalloc_array(dev, priv->num_gphy_fw,
1797 sizeof(*priv->gphy_fw),
1798 GFP_KERNEL | __GFP_ZERO);
1799 if (!priv->gphy_fw)
1800 return -ENOMEM;
1801
1802 for_each_available_child_of_node(gphy_fw_list_np, gphy_fw_np) {
1803 err = gswip_gphy_fw_probe(priv, &priv->gphy_fw[i],
1804 gphy_fw_np, i);
1805 if (err)
1806 goto remove_gphy;
1807 i++;
1808 }
1809
Martin Blumenstingl2a1828e2020-11-15 17:57:57 +01001810 /* The standalone PHY11G requires 300ms to be fully
1811 * initialized and ready for any MDIO communication after being
1812 * taken out of reset. For the SoC-internal GPHY variant there
1813 * is no (known) documentation for the minimum time after a
1814 * reset. Use the same value as for the standalone variant as
1815 * some users have reported internal PHYs not being detected
1816 * without any delay.
1817 */
1818 msleep(300);
1819
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001820 return 0;
1821
1822remove_gphy:
1823 for (i = 0; i < priv->num_gphy_fw; i++)
1824 gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
1825 return err;
1826}
1827
1828static int gswip_probe(struct platform_device *pdev)
1829{
1830 struct gswip_priv *priv;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001831 struct device_node *mdio_np, *gphy_fw_np;
1832 struct device *dev = &pdev->dev;
1833 int err;
1834 int i;
1835 u32 version;
1836
1837 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1838 if (!priv)
1839 return -ENOMEM;
1840
YueHaibing6551c8c2019-08-01 20:25:46 +08001841 priv->gswip = devm_platform_ioremap_resource(pdev, 0);
Wei Yongjunf5de8bf2018-09-15 01:33:21 +00001842 if (IS_ERR(priv->gswip))
1843 return PTR_ERR(priv->gswip);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001844
YueHaibing6551c8c2019-08-01 20:25:46 +08001845 priv->mdio = devm_platform_ioremap_resource(pdev, 1);
Wei Yongjunf5de8bf2018-09-15 01:33:21 +00001846 if (IS_ERR(priv->mdio))
1847 return PTR_ERR(priv->mdio);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001848
YueHaibing6551c8c2019-08-01 20:25:46 +08001849 priv->mii = devm_platform_ioremap_resource(pdev, 2);
Wei Yongjunf5de8bf2018-09-15 01:33:21 +00001850 if (IS_ERR(priv->mii))
1851 return PTR_ERR(priv->mii);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001852
1853 priv->hw_info = of_device_get_match_data(dev);
1854 if (!priv->hw_info)
1855 return -EINVAL;
1856
Vivien Didelot7e99e342019-10-21 16:51:30 -04001857 priv->ds = devm_kzalloc(dev, sizeof(*priv->ds), GFP_KERNEL);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001858 if (!priv->ds)
1859 return -ENOMEM;
1860
Vivien Didelot7e99e342019-10-21 16:51:30 -04001861 priv->ds->dev = dev;
1862 priv->ds->num_ports = priv->hw_info->max_ports;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001863 priv->ds->priv = priv;
1864 priv->ds->ops = &gswip_switch_ops;
1865 priv->dev = dev;
1866 version = gswip_switch_r(priv, GSWIP_VERSION);
1867
1868 /* bring up the mdio bus */
Johan Hovoldc8cbcb02019-01-16 11:23:34 +01001869 gphy_fw_np = of_get_compatible_child(dev->of_node, "lantiq,gphy-fw");
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001870 if (gphy_fw_np) {
1871 err = gswip_gphy_fw_list(priv, gphy_fw_np, version);
Johan Hovoldc8cbcb02019-01-16 11:23:34 +01001872 of_node_put(gphy_fw_np);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001873 if (err) {
1874 dev_err(dev, "gphy fw probe failed\n");
1875 return err;
1876 }
1877 }
1878
1879 /* bring up the mdio bus */
Johan Hovoldc8cbcb02019-01-16 11:23:34 +01001880 mdio_np = of_get_compatible_child(dev->of_node, "lantiq,xrx200-mdio");
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001881 if (mdio_np) {
1882 err = gswip_mdio(priv, mdio_np);
1883 if (err) {
1884 dev_err(dev, "mdio probe failed\n");
Johan Hovoldc8cbcb02019-01-16 11:23:34 +01001885 goto put_mdio_node;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001886 }
1887 }
1888
1889 err = dsa_register_switch(priv->ds);
1890 if (err) {
1891 dev_err(dev, "dsa switch register failed: %i\n", err);
1892 goto mdio_bus;
1893 }
Hauke Mehrtens0e630b52018-09-15 14:08:48 +02001894 if (!dsa_is_cpu_port(priv->ds, priv->hw_info->cpu_port)) {
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001895 dev_err(dev, "wrong CPU port defined, HW only supports port: %i",
1896 priv->hw_info->cpu_port);
1897 err = -EINVAL;
Johan Hovoldaed13f22019-01-16 11:23:33 +01001898 goto disable_switch;
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001899 }
1900
1901 platform_set_drvdata(pdev, priv);
1902
1903 dev_info(dev, "probed GSWIP version %lx mod %lx\n",
1904 (version & GSWIP_VERSION_REV_MASK) >> GSWIP_VERSION_REV_SHIFT,
1905 (version & GSWIP_VERSION_MOD_MASK) >> GSWIP_VERSION_MOD_SHIFT);
1906 return 0;
1907
Johan Hovoldaed13f22019-01-16 11:23:33 +01001908disable_switch:
1909 gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB);
1910 dsa_unregister_switch(priv->ds);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001911mdio_bus:
1912 if (mdio_np)
1913 mdiobus_unregister(priv->ds->slave_mii_bus);
Johan Hovoldc8cbcb02019-01-16 11:23:34 +01001914put_mdio_node:
1915 of_node_put(mdio_np);
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001916 for (i = 0; i < priv->num_gphy_fw; i++)
1917 gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
1918 return err;
1919}
1920
1921static int gswip_remove(struct platform_device *pdev)
1922{
1923 struct gswip_priv *priv = platform_get_drvdata(pdev);
1924 int i;
1925
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001926 /* disable the switch */
1927 gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB);
1928
1929 dsa_unregister_switch(priv->ds);
1930
Johan Hovoldc8cbcb02019-01-16 11:23:34 +01001931 if (priv->ds->slave_mii_bus) {
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001932 mdiobus_unregister(priv->ds->slave_mii_bus);
Johan Hovoldc8cbcb02019-01-16 11:23:34 +01001933 of_node_put(priv->ds->slave_mii_bus->dev.of_node);
1934 }
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001935
1936 for (i = 0; i < priv->num_gphy_fw; i++)
1937 gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]);
1938
1939 return 0;
1940}
1941
1942static const struct gswip_hw_info gswip_xrx200 = {
1943 .max_ports = 7,
1944 .cpu_port = 6,
1945};
1946
1947static const struct of_device_id gswip_of_match[] = {
1948 { .compatible = "lantiq,xrx200-gswip", .data = &gswip_xrx200 },
1949 {},
1950};
1951MODULE_DEVICE_TABLE(of, gswip_of_match);
1952
1953static struct platform_driver gswip_driver = {
1954 .probe = gswip_probe,
1955 .remove = gswip_remove,
1956 .driver = {
1957 .name = "gswip",
1958 .of_match_table = gswip_of_match,
1959 },
1960};
1961
1962module_platform_driver(gswip_driver);
1963
Hauke Mehrtenscffde202019-02-22 20:11:13 +01001964MODULE_FIRMWARE("lantiq/xrx300_phy11g_a21.bin");
1965MODULE_FIRMWARE("lantiq/xrx300_phy22f_a21.bin");
1966MODULE_FIRMWARE("lantiq/xrx200_phy11g_a14.bin");
1967MODULE_FIRMWARE("lantiq/xrx200_phy11g_a22.bin");
1968MODULE_FIRMWARE("lantiq/xrx200_phy22f_a14.bin");
1969MODULE_FIRMWARE("lantiq/xrx200_phy22f_a22.bin");
Hauke Mehrtens14fceff2018-09-09 22:20:39 +02001970MODULE_AUTHOR("Hauke Mehrtens <hauke@hauke-m.de>");
1971MODULE_DESCRIPTION("Lantiq / Intel GSWIP driver");
1972MODULE_LICENSE("GPL v2");