All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches
@ 2022-05-30 10:42 Arun Ramadoss
  2022-05-30 10:42 ` [RFC Patch net-next v2 01/15] net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect Arun Ramadoss
                   ` (14 more replies)
  0 siblings, 15 replies; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch series aims to refactor the ksz_switch_register routine to have the
common flow for the ksz series switch. At present ksz8795.c & ksz9477.c have
its own dsa_switch_ops and switch detect functionality.
In ksz_switch_register, ksz_dev_ops is assigned based on the function parameter
passed by the individual ksz8/ksz9477 switch register function. And then switch
detect is performed based on the ksz_dev_ops.detect hook.  This patch modifies
the ksz_switch_register such a way that switch detect is performed first, based
on the chip ksz_dev_ops is assigned to ksz_device structure. It ensures the
common flow for the existing as well as LAN937x switches.
It also replaces the individual dsa_switch_ops structure to common
dsa_switch_ops in the ksz_common.  Based on the ksz_dev_ops hook pointer,
particular functionality for the switches may or may not executed.
Finally replaces the two spi probes such as ksz8795_spi.c and ksz9477_spi.c to
common ksz_spi.c. These switches have different regmap config and it is
differentited using the of_device_id data.

Changes in RFC v2
- Fixed the compilation issue.
- Reduced the patch set to 15.

Arun Ramadoss (15):
  net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect
  net: dsa: microchip: move switch chip_id detection to ksz_common
  net: dsa: microchip: move tag_protocol & phy read/write to ksz_common
  net: dsa: microchip: move vlan functionality to ksz_common
  net: dsa: microchip: move the port mirror to ksz_common
  net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by
    ksz_dev_ops
  net: dsa: microchip: update the ksz_phylink_get_caps
  net: dsa: microchip: update the ksz_port_mdb_add/del
  net: dsa: microchip: update fdb add/del/dump in ksz_common
  net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common
  net: dsa: microchip: common dsa_switch_ops for ksz switches
  net: dsa: microchip: ksz9477: separate phylink mode from switch
    register
  net: dsa: microchip: common menuconfig for ksz series switch
  net: dsa: microchip: move ksz_dev_ops to ksz_common.c
  net: dsa: microchip: common ksz_spi_probe for ksz switches

 drivers/net/dsa/microchip/Kconfig             |  42 +-
 drivers/net/dsa/microchip/Makefile            |  10 +-
 drivers/net/dsa/microchip/ksz8.h              |  46 ++
 drivers/net/dsa/microchip/ksz8795.c           | 309 +++++------
 drivers/net/dsa/microchip/ksz8795_reg.h       |  13 -
 drivers/net/dsa/microchip/ksz8863_smi.c       |   2 +-
 drivers/net/dsa/microchip/ksz9477.c           | 225 ++------
 drivers/net/dsa/microchip/ksz9477.h           |  58 ++
 drivers/net/dsa/microchip/ksz9477_i2c.c       |   2 +-
 drivers/net/dsa/microchip/ksz9477_reg.h       |   1 -
 drivers/net/dsa/microchip/ksz9477_spi.c       | 150 -----
 drivers/net/dsa/microchip/ksz_common.c        | 521 +++++++++++++-----
 drivers/net/dsa/microchip/ksz_common.h        |  91 +--
 .../microchip/{ksz8795_spi.c => ksz_spi.c}    |  85 ++-
 14 files changed, 821 insertions(+), 734 deletions(-)
 create mode 100644 drivers/net/dsa/microchip/ksz9477.h
 delete mode 100644 drivers/net/dsa/microchip/ksz9477_spi.c
 rename drivers/net/dsa/microchip/{ksz8795_spi.c => ksz_spi.c} (61%)

-- 
2.36.1


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 01/15] net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-12 14:20   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 02/15] net: dsa: microchip: move switch chip_id detection to ksz_common Arun Ramadoss
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

The ksz9477_switch_detect performs the detecting the chip id from the
location 0x00 and also check gigabit compatibility check & number of
ports based on the register global_options0. To prepare the common ksz
switch detect function, routine other than chip id read is moved to
ksz9477_switch_init.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz9477.c | 48 +++++++++++++----------------
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index ab40b700cf1a..7afc06681c02 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -1362,12 +1362,30 @@ static u32 ksz9477_get_port_addr(int port, int offset)
 
 static int ksz9477_switch_detect(struct ksz_device *dev)
 {
-	u8 data8;
-	u8 id_hi;
-	u8 id_lo;
 	u32 id32;
 	int ret;
 
+	/* read chip id */
+	ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32);
+	if (ret)
+		return ret;
+
+	dev_dbg(dev->dev, "Switch detect: ID=%08x\n", id32);
+
+	dev->chip_id = id32 & 0x00FFFF00;
+
+	return 0;
+}
+
+static int ksz9477_switch_init(struct ksz_device *dev)
+{
+	u8 data8;
+	int ret;
+
+	dev->ds->ops = &ksz9477_switch_ops;
+
+	dev->port_mask = (1 << dev->info->port_cnt) - 1;
+
 	/* turn off SPI DO Edge select */
 	ret = ksz_read8(dev, REG_SW_GLOBAL_SERIAL_CTRL_0, &data8);
 	if (ret)
@@ -1378,10 +1396,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev)
 	if (ret)
 		return ret;
 
-	/* read chip id */
-	ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32);
-	if (ret)
-		return ret;
 	ret = ksz_read8(dev, REG_GLOBAL_OPTIONS, &data8);
 	if (ret)
 		return ret;
@@ -1392,10 +1406,7 @@ static int ksz9477_switch_detect(struct ksz_device *dev)
 	/* Default capability is gigabit capable. */
 	dev->features = GBIT_SUPPORT;
 
-	dev_dbg(dev->dev, "Switch detect: ID=%08x%02x\n", id32, data8);
-	id_hi = (u8)(id32 >> 16);
-	id_lo = (u8)(id32 >> 8);
-	if ((id_lo & 0xf) == 3) {
+	if (dev->chip_id == KSZ9893_CHIP_ID) {
 		/* Chip is from KSZ9893 design. */
 		dev_info(dev->dev, "Found KSZ9893\n");
 		dev->features |= IS_9893;
@@ -1413,21 +1424,6 @@ static int ksz9477_switch_detect(struct ksz_device *dev)
 		if (!(data8 & SW_GIGABIT_ABLE))
 			dev->features &= ~GBIT_SUPPORT;
 	}
-
-	/* Change chip id to known ones so it can be matched against them. */
-	id32 = (id_hi << 16) | (id_lo << 8);
-
-	dev->chip_id = id32;
-
-	return 0;
-}
-
-static int ksz9477_switch_init(struct ksz_device *dev)
-{
-	dev->ds->ops = &ksz9477_switch_ops;
-
-	dev->port_mask = (1 << dev->info->port_cnt) - 1;
-
 	return 0;
 }
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 02/15] net: dsa: microchip: move switch chip_id detection to ksz_common
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
  2022-05-30 10:42 ` [RFC Patch net-next v2 01/15] net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-13  9:18   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 03/15] net: dsa: microchip: move tag_protocol & phy read/write " Arun Ramadoss
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

KSZ87xx and KSZ88xx have chip_id representation at reg location 0. And
KSZ9477 compatible switch and LAN937x switch have same chip_id detection
at location 0x01 and 0x02. To have the common switch detect
functionality for ksz switches, ksz_switch_detect function is
introduced.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c     | 46 ---------------
 drivers/net/dsa/microchip/ksz8795_reg.h | 13 -----
 drivers/net/dsa/microchip/ksz9477.c     | 21 -------
 drivers/net/dsa/microchip/ksz9477_reg.h |  1 -
 drivers/net/dsa/microchip/ksz_common.c  | 78 +++++++++++++++++++++++--
 drivers/net/dsa/microchip/ksz_common.h  | 19 +++++-
 6 files changed, 92 insertions(+), 86 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 12a599d5e61a..927db57d02db 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -1424,51 +1424,6 @@ static u32 ksz8_get_port_addr(int port, int offset)
 	return PORT_CTRL_ADDR(port, offset);
 }
 
-static int ksz8_switch_detect(struct ksz_device *dev)
-{
-	u8 id1, id2;
-	u16 id16;
-	int ret;
-
-	/* read chip id */
-	ret = ksz_read16(dev, REG_CHIP_ID0, &id16);
-	if (ret)
-		return ret;
-
-	id1 = id16 >> 8;
-	id2 = id16 & SW_CHIP_ID_M;
-
-	switch (id1) {
-	case KSZ87_FAMILY_ID:
-		if ((id2 != CHIP_ID_94 && id2 != CHIP_ID_95))
-			return -ENODEV;
-
-		if (id2 == CHIP_ID_95) {
-			u8 val;
-
-			id2 = 0x95;
-			ksz_read8(dev, REG_PORT_STATUS_0, &val);
-			if (val & PORT_FIBER_MODE)
-				id2 = 0x65;
-		} else if (id2 == CHIP_ID_94) {
-			id2 = 0x94;
-		}
-		break;
-	case KSZ88_FAMILY_ID:
-		if (id2 != CHIP_ID_63)
-			return -ENODEV;
-		break;
-	default:
-		dev_err(dev->dev, "invalid family id: %d\n", id1);
-		return -ENODEV;
-	}
-	id16 &= ~0xff;
-	id16 |= id2;
-	dev->chip_id = id16;
-
-	return 0;
-}
-
 static int ksz8_switch_init(struct ksz_device *dev)
 {
 	struct ksz8 *ksz8 = dev->priv;
@@ -1522,7 +1477,6 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.freeze_mib = ksz8_freeze_mib,
 	.port_init_cnt = ksz8_port_init_cnt,
 	.shutdown = ksz8_reset_switch,
-	.detect = ksz8_switch_detect,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
 };
diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h
index 4109433b6b6c..50cdc2a09f5a 100644
--- a/drivers/net/dsa/microchip/ksz8795_reg.h
+++ b/drivers/net/dsa/microchip/ksz8795_reg.h
@@ -14,23 +14,10 @@
 #define KS_PRIO_M			0x3
 #define KS_PRIO_S			2
 
-#define REG_CHIP_ID0			0x00
-
-#define KSZ87_FAMILY_ID			0x87
-#define KSZ88_FAMILY_ID			0x88
-
-#define REG_CHIP_ID1			0x01
-
-#define SW_CHIP_ID_M			0xF0
-#define SW_CHIP_ID_S			4
 #define SW_REVISION_M			0x0E
 #define SW_REVISION_S			1
 #define SW_START			0x01
 
-#define CHIP_ID_94			0x60
-#define CHIP_ID_95			0x90
-#define CHIP_ID_63			0x30
-
 #define KSZ8863_REG_SW_RESET		0x43
 
 #define KSZ8863_GLOBAL_SOFTWARE_RESET	BIT(4)
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 7afc06681c02..7d3c8f6908b6 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -1360,23 +1360,6 @@ static u32 ksz9477_get_port_addr(int port, int offset)
 	return PORT_CTRL_ADDR(port, offset);
 }
 
-static int ksz9477_switch_detect(struct ksz_device *dev)
-{
-	u32 id32;
-	int ret;
-
-	/* read chip id */
-	ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32);
-	if (ret)
-		return ret;
-
-	dev_dbg(dev->dev, "Switch detect: ID=%08x\n", id32);
-
-	dev->chip_id = id32 & 0x00FFFF00;
-
-	return 0;
-}
-
 static int ksz9477_switch_init(struct ksz_device *dev)
 {
 	u8 data8;
@@ -1407,8 +1390,6 @@ static int ksz9477_switch_init(struct ksz_device *dev)
 	dev->features = GBIT_SUPPORT;
 
 	if (dev->chip_id == KSZ9893_CHIP_ID) {
-		/* Chip is from KSZ9893 design. */
-		dev_info(dev->dev, "Found KSZ9893\n");
 		dev->features |= IS_9893;
 
 		/* Chip does not support gigabit. */
@@ -1416,7 +1397,6 @@ static int ksz9477_switch_init(struct ksz_device *dev)
 			dev->features &= ~GBIT_SUPPORT;
 		dev->phy_port_cnt = 2;
 	} else {
-		dev_info(dev->dev, "Found KSZ9477 or compatible\n");
 		/* Chip uses new XMII register definitions. */
 		dev->features |= NEW_XMII;
 
@@ -1443,7 +1423,6 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.freeze_mib = ksz9477_freeze_mib,
 	.port_init_cnt = ksz9477_port_init_cnt,
 	.shutdown = ksz9477_reset_switch,
-	.detect = ksz9477_switch_detect,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
 };
diff --git a/drivers/net/dsa/microchip/ksz9477_reg.h b/drivers/net/dsa/microchip/ksz9477_reg.h
index 7a2c8d4767af..077e35ab11b5 100644
--- a/drivers/net/dsa/microchip/ksz9477_reg.h
+++ b/drivers/net/dsa/microchip/ksz9477_reg.h
@@ -25,7 +25,6 @@
 
 #define REG_CHIP_ID2__1			0x0002
 
-#define CHIP_ID_63			0x63
 #define CHIP_ID_66			0x66
 #define CHIP_ID_67			0x67
 #define CHIP_ID_77			0x77
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 9ca8c8d7740f..9057cdb5971c 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -930,6 +930,72 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port,
 }
 EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
 
+static int ksz_switch_detect(struct ksz_device *dev)
+{
+	u8 id1, id2;
+	u16 id16;
+	u32 id32;
+	int ret;
+
+	/* read chip id */
+	ret = ksz_read16(dev, REG_CHIP_ID0, &id16);
+	if (ret)
+		return ret;
+
+	id1 = FIELD_GET(SW_FAMILY_ID_M, id16);
+	id2 = FIELD_GET(SW_CHIP_ID_M, id16);
+
+	switch (id1) {
+	case KSZ87_FAMILY_ID:
+		if (id2 == CHIP_ID_95) {
+			u8 val;
+
+			dev->chip_id = KSZ8795_CHIP_ID;
+
+			ksz_read8(dev, KSZ8_PORT_STATUS_0, &val);
+			if (val & KSZ8_PORT_FIBER_MODE)
+				dev->chip_id = KSZ8765_CHIP_ID;
+		} else if (id2 == CHIP_ID_94) {
+			dev->chip_id = KSZ8794_CHIP_ID;
+		} else {
+			return -ENODEV;
+		}
+		break;
+	case KSZ88_FAMILY_ID:
+		if (id2 == CHIP_ID_63)
+			dev->chip_id = KSZ8830_CHIP_ID;
+		else
+			return -ENODEV;
+		break;
+	default:
+		ret = ksz_read32(dev, REG_CHIP_ID0, &id32);
+		if (ret)
+			return ret;
+
+		dev->chip_rev = FIELD_GET(SW_REV_ID_M, id32);
+		id32 &= ~0xFF;
+
+		switch (id32) {
+		case KSZ9477_CHIP_ID:
+		case KSZ9897_CHIP_ID:
+		case KSZ9893_CHIP_ID:
+		case KSZ9567_CHIP_ID:
+		case LAN9370_CHIP_ID:
+		case LAN9371_CHIP_ID:
+		case LAN9372_CHIP_ID:
+		case LAN9373_CHIP_ID:
+		case LAN9374_CHIP_ID:
+			dev->chip_id = id32;
+			break;
+		default:
+			dev_err(dev->dev,
+				"unsupported switch detected %x)\n", id32);
+			return -ENODEV;
+		}
+	}
+	return 0;
+}
+
 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
 {
 	struct dsa_switch *ds;
@@ -986,10 +1052,9 @@ int ksz_switch_register(struct ksz_device *dev,
 	mutex_init(&dev->alu_mutex);
 	mutex_init(&dev->vlan_mutex);
 
-	dev->dev_ops = ops;
-
-	if (dev->dev_ops->detect(dev))
-		return -EINVAL;
+	ret = ksz_switch_detect(dev);
+	if (ret)
+		return ret;
 
 	info = ksz_lookup_info(dev->chip_id);
 	if (!info)
@@ -998,10 +1063,15 @@ int ksz_switch_register(struct ksz_device *dev,
 	/* Update the compatible info with the probed one */
 	dev->info = info;
 
+	dev_info(dev->dev, "found switch: %s, rev %i\n",
+		 dev->info->dev_name, dev->chip_rev);
+
 	ret = ksz_check_device_id(dev);
 	if (ret)
 		return ret;
 
+	dev->dev_ops = ops;
+
 	ret = dev->dev_ops->init(dev);
 	if (ret)
 		return ret;
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 8500eaedad67..d16c095cdefb 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -90,6 +90,7 @@ struct ksz_device {
 
 	/* chip specific data */
 	u32 chip_id;
+	u8 chip_rev;
 	int cpu_port;			/* port connected to CPU */
 	int phy_port_cnt;
 	phy_interface_t compat_interface;
@@ -182,7 +183,6 @@ struct ksz_dev_ops {
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
 	int (*shutdown)(struct ksz_device *dev);
-	int (*detect)(struct ksz_device *dev);
 	int (*init)(struct ksz_device *dev);
 	void (*exit)(struct ksz_device *dev);
 };
@@ -353,6 +353,23 @@ static inline void ksz_regmap_unlock(void *__mtx)
 #define PORT_RX_ENABLE			BIT(1)
 #define PORT_LEARN_DISABLE		BIT(0)
 
+/* Switch ID Defines */
+#define REG_CHIP_ID0			0x00
+
+#define SW_FAMILY_ID_M			GENMASK(15, 8)
+#define KSZ87_FAMILY_ID			0x87
+#define KSZ88_FAMILY_ID			0x88
+
+#define KSZ8_PORT_STATUS_0		0x08
+#define KSZ8_PORT_FIBER_MODE		BIT(7)
+
+#define SW_CHIP_ID_M			GENMASK(7, 4)
+#define CHIP_ID_94			0x6
+#define CHIP_ID_95			0x9
+#define CHIP_ID_63			0x3
+
+#define SW_REV_ID_M			GENMASK(7, 4)
+
 /* Regmap tables generation */
 #define KSZ_SPI_OP_RD		3
 #define KSZ_SPI_OP_WR		2
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 03/15] net: dsa: microchip: move tag_protocol & phy read/write to ksz_common
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
  2022-05-30 10:42 ` [RFC Patch net-next v2 01/15] net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect Arun Ramadoss
  2022-05-30 10:42 ` [RFC Patch net-next v2 02/15] net: dsa: microchip: move switch chip_id detection to ksz_common Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-13  9:22   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 04/15] net: dsa: microchip: move vlan functionality " Arun Ramadoss
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch move the dsa hook get_tag_protocol to ksz_common file. And
the tag_protocol is returned based on the dev->chip_id.
ksz8795 and ksz9477 implementation on phy read/write hooks are
different. This patch modifies the ksz9477 implementation same as
ksz8795 by updating the ksz9477_dev_ops structure.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    | 13 +--------
 drivers/net/dsa/microchip/ksz9477.c    | 37 ++++++++------------------
 drivers/net/dsa/microchip/ksz_common.c | 24 +++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h |  2 ++
 4 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 927db57d02db..6e5f665fa1f6 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -898,17 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 	}
 }
 
-static enum dsa_tag_protocol ksz8_get_tag_protocol(struct dsa_switch *ds,
-						   int port,
-						   enum dsa_tag_protocol mp)
-{
-	struct ksz_device *dev = ds->priv;
-
-	/* ksz88x3 uses the same tag schema as KSZ9893 */
-	return ksz_is_ksz88x3(dev) ?
-		DSA_TAG_PROTO_KSZ9893 : DSA_TAG_PROTO_KSZ8795;
-}
-
 static u32 ksz8_sw_get_phy_flags(struct dsa_switch *ds, int port)
 {
 	/* Silicon Errata Sheet (DS80000830A):
@@ -1394,7 +1383,7 @@ static void ksz8_get_caps(struct dsa_switch *ds, int port,
 }
 
 static const struct dsa_switch_ops ksz8_switch_ops = {
-	.get_tag_protocol	= ksz8_get_tag_protocol,
+	.get_tag_protocol	= ksz_get_tag_protocol,
 	.get_phy_flags		= ksz8_sw_get_phy_flags,
 	.setup			= ksz8_setup,
 	.phy_read		= ksz_phy_read16,
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 7d3c8f6908b6..4fb96e53487e 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -276,21 +276,8 @@ static void ksz9477_port_init_cnt(struct ksz_device *dev, int port)
 	mutex_unlock(&mib->cnt_mutex);
 }
 
-static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds,
-						      int port,
-						      enum dsa_tag_protocol mp)
+static void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 {
-	enum dsa_tag_protocol proto = DSA_TAG_PROTO_KSZ9477;
-	struct ksz_device *dev = ds->priv;
-
-	if (dev->features & IS_9893)
-		proto = DSA_TAG_PROTO_KSZ9893;
-	return proto;
-}
-
-static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg)
-{
-	struct ksz_device *dev = ds->priv;
 	u16 val = 0xffff;
 
 	/* No real PHY after this. Simulate the PHY.
@@ -335,24 +322,20 @@ static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg)
 		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
 	}
 
-	return val;
+	*data = val;
 }
 
-static int ksz9477_phy_write16(struct dsa_switch *ds, int addr, int reg,
-			       u16 val)
+static void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
 {
-	struct ksz_device *dev = ds->priv;
-
 	/* No real PHY after this. */
 	if (addr >= dev->phy_port_cnt)
-		return 0;
+		return;
 
 	/* No gigabit support.  Do not write to this register. */
 	if (!(dev->features & GBIT_SUPPORT) && reg == MII_CTRL1000)
-		return 0;
-	ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
+		return;
 
-	return 0;
+	ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
 }
 
 static void ksz9477_cfg_port_member(struct ksz_device *dev, int port,
@@ -1326,10 +1309,10 @@ static int ksz9477_setup(struct dsa_switch *ds)
 }
 
 static const struct dsa_switch_ops ksz9477_switch_ops = {
-	.get_tag_protocol	= ksz9477_get_tag_protocol,
+	.get_tag_protocol	= ksz_get_tag_protocol,
 	.setup			= ksz9477_setup,
-	.phy_read		= ksz9477_phy_read16,
-	.phy_write		= ksz9477_phy_write16,
+	.phy_read		= ksz_phy_read16,
+	.phy_write		= ksz_phy_write16,
 	.phylink_mac_link_down	= ksz_mac_link_down,
 	.phylink_get_caps	= ksz9477_get_caps,
 	.port_enable		= ksz_enable_port,
@@ -1417,6 +1400,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.cfg_port_member = ksz9477_cfg_port_member,
 	.flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
 	.port_setup = ksz9477_port_setup,
+	.r_phy = ksz9477_r_phy,
+	.w_phy = ksz9477_w_phy,
 	.r_mib_cnt = ksz9477_r_mib_cnt,
 	.r_mib_pkt = ksz9477_r_mib_pkt,
 	.r_mib_stat64 = ksz_r_mib_stats64,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 9057cdb5971c..a43b01c2e67f 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -930,6 +930,30 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port,
 }
 EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
 
+enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
+					   int port, enum dsa_tag_protocol mp)
+{
+	struct ksz_device *dev = ds->priv;
+	enum dsa_tag_protocol proto;
+
+	if (dev->chip_id == KSZ8795_CHIP_ID ||
+	    dev->chip_id == KSZ8794_CHIP_ID ||
+	    dev->chip_id == KSZ8765_CHIP_ID)
+		proto = DSA_TAG_PROTO_KSZ8795;
+
+	if (dev->chip_id == KSZ8830_CHIP_ID ||
+	    dev->chip_id == KSZ9893_CHIP_ID)
+		proto = DSA_TAG_PROTO_KSZ9893;
+
+	if (dev->chip_id == KSZ9477_CHIP_ID ||
+	    dev->chip_id == KSZ9897_CHIP_ID ||
+	    dev->chip_id == KSZ9567_CHIP_ID)
+		proto = DSA_TAG_PROTO_KSZ9477;
+
+	return proto;
+}
+EXPORT_SYMBOL_GPL(ksz_get_tag_protocol);
+
 static int ksz_switch_detect(struct ksz_device *dev)
 {
 	u8 id1, id2;
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index d16c095cdefb..f253f3f22386 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -231,6 +231,8 @@ int ksz_port_mdb_del(struct dsa_switch *ds, int port,
 int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
 void ksz_get_strings(struct dsa_switch *ds, int port,
 		     u32 stringset, uint8_t *buf);
+enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
+					   int port, enum dsa_tag_protocol mp);
 
 /* Common register access functions */
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 04/15] net: dsa: microchip: move vlan functionality to ksz_common
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (2 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 03/15] net: dsa: microchip: move tag_protocol & phy read/write " Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-13  9:24   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 05/15] net: dsa: microchip: move the port mirror " Arun Ramadoss
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch moves the vlan dsa_switch_ops such as vlan_add, vlan_del and
vlan_filtering from the individual files ksz8795.c, ksz9477.c to
ksz_common.c file.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    | 19 ++++++------
 drivers/net/dsa/microchip/ksz9477.c    | 19 ++++++------
 drivers/net/dsa/microchip/ksz_common.c | 40 ++++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h | 14 +++++++++
 4 files changed, 72 insertions(+), 20 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 6e5f665fa1f6..157d69e46793 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -958,11 +958,9 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
 	}
 }
 
-static int ksz8_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag,
+static int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,
 				    struct netlink_ext_ack *extack)
 {
-	struct ksz_device *dev = ds->priv;
-
 	if (ksz_is_ksz88x3(dev))
 		return -ENOTSUPP;
 
@@ -987,12 +985,11 @@ static void ksz8_port_enable_pvid(struct ksz_device *dev, int port, bool state)
 	}
 }
 
-static int ksz8_port_vlan_add(struct dsa_switch *ds, int port,
+static int ksz8_port_vlan_add(struct ksz_device *dev, int port,
 			      const struct switchdev_obj_port_vlan *vlan,
 			      struct netlink_ext_ack *extack)
 {
 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
-	struct ksz_device *dev = ds->priv;
 	struct ksz_port *p = &dev->ports[port];
 	u16 data, new_pvid = 0;
 	u8 fid, member, valid;
@@ -1060,10 +1057,9 @@ static int ksz8_port_vlan_add(struct dsa_switch *ds, int port,
 	return 0;
 }
 
-static int ksz8_port_vlan_del(struct dsa_switch *ds, int port,
+static int ksz8_port_vlan_del(struct ksz_device *dev, int port,
 			      const struct switchdev_obj_port_vlan *vlan)
 {
-	struct ksz_device *dev = ds->priv;
 	u16 data, pvid;
 	u8 fid, member, valid;
 
@@ -1398,9 +1394,9 @@ static const struct dsa_switch_ops ksz8_switch_ops = {
 	.port_bridge_leave	= ksz_port_bridge_leave,
 	.port_stp_state_set	= ksz8_port_stp_state_set,
 	.port_fast_age		= ksz_port_fast_age,
-	.port_vlan_filtering	= ksz8_port_vlan_filtering,
-	.port_vlan_add		= ksz8_port_vlan_add,
-	.port_vlan_del		= ksz8_port_vlan_del,
+	.port_vlan_filtering	= ksz_port_vlan_filtering,
+	.port_vlan_add		= ksz_port_vlan_add,
+	.port_vlan_del		= ksz_port_vlan_del,
 	.port_fdb_dump		= ksz_port_fdb_dump,
 	.port_mdb_add           = ksz_port_mdb_add,
 	.port_mdb_del           = ksz_port_mdb_del,
@@ -1465,6 +1461,9 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.r_mib_pkt = ksz8_r_mib_pkt,
 	.freeze_mib = ksz8_freeze_mib,
 	.port_init_cnt = ksz8_port_init_cnt,
+	.vlan_filtering = ksz8_port_vlan_filtering,
+	.vlan_add = ksz8_port_vlan_add,
+	.vlan_del = ksz8_port_vlan_del,
 	.shutdown = ksz8_reset_switch,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 4fb96e53487e..e230fe1d1917 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -372,12 +372,10 @@ static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port)
 	}
 }
 
-static int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port,
+static int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port,
 				       bool flag,
 				       struct netlink_ext_ack *extack)
 {
-	struct ksz_device *dev = ds->priv;
-
 	if (flag) {
 		ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL,
 			     PORT_VLAN_LOOKUP_VID_0, true);
@@ -391,11 +389,10 @@ static int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port,
 	return 0;
 }
 
-static int ksz9477_port_vlan_add(struct dsa_switch *ds, int port,
+static int ksz9477_port_vlan_add(struct ksz_device *dev, int port,
 				 const struct switchdev_obj_port_vlan *vlan,
 				 struct netlink_ext_ack *extack)
 {
-	struct ksz_device *dev = ds->priv;
 	u32 vlan_table[3];
 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
 	int err;
@@ -428,10 +425,9 @@ static int ksz9477_port_vlan_add(struct dsa_switch *ds, int port,
 	return 0;
 }
 
-static int ksz9477_port_vlan_del(struct dsa_switch *ds, int port,
+static int ksz9477_port_vlan_del(struct ksz_device *dev, int port,
 				 const struct switchdev_obj_port_vlan *vlan)
 {
-	struct ksz_device *dev = ds->priv;
 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
 	u32 vlan_table[3];
 	u16 pvid;
@@ -1323,9 +1319,9 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.port_bridge_leave	= ksz_port_bridge_leave,
 	.port_stp_state_set	= ksz9477_port_stp_state_set,
 	.port_fast_age		= ksz_port_fast_age,
-	.port_vlan_filtering	= ksz9477_port_vlan_filtering,
-	.port_vlan_add		= ksz9477_port_vlan_add,
-	.port_vlan_del		= ksz9477_port_vlan_del,
+	.port_vlan_filtering	= ksz_port_vlan_filtering,
+	.port_vlan_add		= ksz_port_vlan_add,
+	.port_vlan_del		= ksz_port_vlan_del,
 	.port_fdb_dump		= ksz9477_port_fdb_dump,
 	.port_fdb_add		= ksz9477_port_fdb_add,
 	.port_fdb_del		= ksz9477_port_fdb_del,
@@ -1407,6 +1403,9 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.r_mib_stat64 = ksz_r_mib_stats64,
 	.freeze_mib = ksz9477_freeze_mib,
 	.port_init_cnt = ksz9477_port_init_cnt,
+	.vlan_filtering = ksz9477_port_vlan_filtering,
+	.vlan_add = ksz9477_port_vlan_add,
+	.vlan_del = ksz9477_port_vlan_del,
 	.shutdown = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index a43b01c2e67f..a1fef9e4e36c 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -954,6 +954,46 @@ enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
 }
 EXPORT_SYMBOL_GPL(ksz_get_tag_protocol);
 
+int ksz_port_vlan_filtering(struct dsa_switch *ds, int port,
+			    bool flag, struct netlink_ext_ack *extack)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->vlan_filtering)
+		ret = dev->dev_ops->vlan_filtering(dev, port, flag, extack);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ksz_port_vlan_filtering);
+
+int ksz_port_vlan_add(struct dsa_switch *ds, int port,
+		      const struct switchdev_obj_port_vlan *vlan,
+		      struct netlink_ext_ack *extack)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->vlan_add)
+		ret = dev->dev_ops->vlan_add(dev, port, vlan, extack);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ksz_port_vlan_add);
+
+int ksz_port_vlan_del(struct dsa_switch *ds, int port,
+		      const struct switchdev_obj_port_vlan *vlan)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->vlan_del)
+		ret = dev->dev_ops->vlan_del(dev, port, vlan);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ksz_port_vlan_del);
+
 static int ksz_switch_detect(struct ksz_device *dev)
 {
 	u8 id1, id2;
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index f253f3f22386..03e738c0cbb8 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -180,6 +180,13 @@ struct ksz_dev_ops {
 	void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
 			  u64 *dropped, u64 *cnt);
 	void (*r_mib_stat64)(struct ksz_device *dev, int port);
+	int  (*vlan_filtering)(struct ksz_device *dev, int port,
+			       bool flag, struct netlink_ext_ack *extack);
+	int  (*vlan_add)(struct ksz_device *dev, int port,
+			 const struct switchdev_obj_port_vlan *vlan,
+			 struct netlink_ext_ack *extack);
+	int  (*vlan_del)(struct ksz_device *dev, int port,
+			 const struct switchdev_obj_port_vlan *vlan);
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
 	int (*shutdown)(struct ksz_device *dev);
@@ -233,6 +240,13 @@ void ksz_get_strings(struct dsa_switch *ds, int port,
 		     u32 stringset, uint8_t *buf);
 enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
 					   int port, enum dsa_tag_protocol mp);
+int ksz_port_vlan_filtering(struct dsa_switch *ds, int port,
+			    bool flag, struct netlink_ext_ack *extack);
+int ksz_port_vlan_add(struct dsa_switch *ds, int port,
+		      const struct switchdev_obj_port_vlan *vlan,
+		      struct netlink_ext_ack *extack);
+int ksz_port_vlan_del(struct dsa_switch *ds, int port,
+		      const struct switchdev_obj_port_vlan *vlan);
 
 /* Common register access functions */
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 05/15] net: dsa: microchip: move the port mirror to ksz_common
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (3 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 04/15] net: dsa: microchip: move vlan functionality " Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-13  9:28   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 06/15] net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by ksz_dev_ops Arun Ramadoss
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch updates the common port mirror add/del dsa_switch_ops in
ksz_common.c. The individual switches implementation is executed based
on the ksz_dev_ops function pointers.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    | 13 ++++++-------
 drivers/net/dsa/microchip/ksz9477.c    | 12 ++++++------
 drivers/net/dsa/microchip/ksz_common.c | 25 +++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h | 10 ++++++++++
 4 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 157d69e46793..8657b520b336 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -1089,12 +1089,10 @@ static int ksz8_port_vlan_del(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz8_port_mirror_add(struct dsa_switch *ds, int port,
+static int ksz8_port_mirror_add(struct ksz_device *dev, int port,
 				struct dsa_mall_mirror_tc_entry *mirror,
 				bool ingress, struct netlink_ext_ack *extack)
 {
-	struct ksz_device *dev = ds->priv;
-
 	if (ingress) {
 		ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX, true);
 		dev->mirror_rx |= BIT(port);
@@ -1113,10 +1111,9 @@ static int ksz8_port_mirror_add(struct dsa_switch *ds, int port,
 	return 0;
 }
 
-static void ksz8_port_mirror_del(struct dsa_switch *ds, int port,
+static void ksz8_port_mirror_del(struct ksz_device *dev, int port,
 				 struct dsa_mall_mirror_tc_entry *mirror)
 {
-	struct ksz_device *dev = ds->priv;
 	u8 data;
 
 	if (mirror->ingress) {
@@ -1400,8 +1397,8 @@ static const struct dsa_switch_ops ksz8_switch_ops = {
 	.port_fdb_dump		= ksz_port_fdb_dump,
 	.port_mdb_add           = ksz_port_mdb_add,
 	.port_mdb_del           = ksz_port_mdb_del,
-	.port_mirror_add	= ksz8_port_mirror_add,
-	.port_mirror_del	= ksz8_port_mirror_del,
+	.port_mirror_add	= ksz_port_mirror_add,
+	.port_mirror_del	= ksz_port_mirror_del,
 };
 
 static u32 ksz8_get_port_addr(int port, int offset)
@@ -1464,6 +1461,8 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.vlan_filtering = ksz8_port_vlan_filtering,
 	.vlan_add = ksz8_port_vlan_add,
 	.vlan_del = ksz8_port_vlan_del,
+	.mirror_add = ksz8_port_mirror_add,
+	.mirror_del = ksz8_port_mirror_del,
 	.shutdown = ksz8_reset_switch,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index e230fe1d1917..6796c9d89ab9 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -811,11 +811,10 @@ static int ksz9477_port_mdb_del(struct dsa_switch *ds, int port,
 	return ret;
 }
 
-static int ksz9477_port_mirror_add(struct dsa_switch *ds, int port,
+static int ksz9477_port_mirror_add(struct ksz_device *dev, int port,
 				   struct dsa_mall_mirror_tc_entry *mirror,
 				   bool ingress, struct netlink_ext_ack *extack)
 {
-	struct ksz_device *dev = ds->priv;
 	u8 data;
 	int p;
 
@@ -851,10 +850,9 @@ static int ksz9477_port_mirror_add(struct dsa_switch *ds, int port,
 	return 0;
 }
 
-static void ksz9477_port_mirror_del(struct dsa_switch *ds, int port,
+static void ksz9477_port_mirror_del(struct ksz_device *dev, int port,
 				    struct dsa_mall_mirror_tc_entry *mirror)
 {
-	struct ksz_device *dev = ds->priv;
 	bool in_use = false;
 	u8 data;
 	int p;
@@ -1327,8 +1325,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.port_fdb_del		= ksz9477_port_fdb_del,
 	.port_mdb_add           = ksz9477_port_mdb_add,
 	.port_mdb_del           = ksz9477_port_mdb_del,
-	.port_mirror_add	= ksz9477_port_mirror_add,
-	.port_mirror_del	= ksz9477_port_mirror_del,
+	.port_mirror_add	= ksz_port_mirror_add,
+	.port_mirror_del	= ksz_port_mirror_del,
 	.get_stats64		= ksz_get_stats64,
 	.port_change_mtu	= ksz9477_change_mtu,
 	.port_max_mtu		= ksz9477_max_mtu,
@@ -1406,6 +1404,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.vlan_filtering = ksz9477_port_vlan_filtering,
 	.vlan_add = ksz9477_port_vlan_add,
 	.vlan_del = ksz9477_port_vlan_del,
+	.mirror_add = ksz9477_port_mirror_add,
+	.mirror_del = ksz9477_port_mirror_del,
 	.shutdown = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index a1fef9e4e36c..1ed4cc94795e 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -994,6 +994,31 @@ int ksz_port_vlan_del(struct dsa_switch *ds, int port,
 }
 EXPORT_SYMBOL_GPL(ksz_port_vlan_del);
 
+int ksz_port_mirror_add(struct dsa_switch *ds, int port,
+			struct dsa_mall_mirror_tc_entry *mirror,
+			bool ingress, struct netlink_ext_ack *extack)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->mirror_add)
+		ret = dev->dev_ops->mirror_add(dev, port, mirror, ingress,
+					       extack);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ksz_port_mirror_add);
+
+void ksz_port_mirror_del(struct dsa_switch *ds, int port,
+			 struct dsa_mall_mirror_tc_entry *mirror)
+{
+	struct ksz_device *dev = ds->priv;
+
+	if (dev->dev_ops->mirror_del)
+		dev->dev_ops->mirror_del(dev, port, mirror);
+}
+EXPORT_SYMBOL_GPL(ksz_port_mirror_del);
+
 static int ksz_switch_detect(struct ksz_device *dev)
 {
 	u8 id1, id2;
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 03e738c0cbb8..01080ec22bf1 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -187,6 +187,11 @@ struct ksz_dev_ops {
 			 struct netlink_ext_ack *extack);
 	int  (*vlan_del)(struct ksz_device *dev, int port,
 			 const struct switchdev_obj_port_vlan *vlan);
+	int (*mirror_add)(struct ksz_device *dev, int port,
+			  struct dsa_mall_mirror_tc_entry *mirror,
+			  bool ingress, struct netlink_ext_ack *extack);
+	void (*mirror_del)(struct ksz_device *dev, int port,
+			   struct dsa_mall_mirror_tc_entry *mirror);
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
 	int (*shutdown)(struct ksz_device *dev);
@@ -247,6 +252,11 @@ int ksz_port_vlan_add(struct dsa_switch *ds, int port,
 		      struct netlink_ext_ack *extack);
 int ksz_port_vlan_del(struct dsa_switch *ds, int port,
 		      const struct switchdev_obj_port_vlan *vlan);
+int ksz_port_mirror_add(struct dsa_switch *ds, int port,
+			struct dsa_mall_mirror_tc_entry *mirror,
+			bool ingress, struct netlink_ext_ack *extack);
+void ksz_port_mirror_del(struct dsa_switch *ds, int port,
+			 struct dsa_mall_mirror_tc_entry *mirror);
 
 /* Common register access functions */
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 06/15] net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by ksz_dev_ops
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (4 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 05/15] net: dsa: microchip: move the port mirror " Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-13  9:31   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 07/15] net: dsa: microchip: update the ksz_phylink_get_caps Arun Ramadoss
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

At present, P_STP_CTRL register value is passed as parameter to
ksz_port_stp_state from the individual dsa_switch_ops hooks. This patch
update the function to retrieve the register value through the
ksz_dev_ops function pointer.
And add the static to ksz_update_port_member since it is not called
outside the ksz_common.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    |  9 +++++----
 drivers/net/dsa/microchip/ksz9477.c    | 10 +++++-----
 drivers/net/dsa/microchip/ksz_common.c |  9 +++++----
 drivers/net/dsa/microchip/ksz_common.h |  5 ++---
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 8657b520b336..e6982fa9d382 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -920,9 +920,9 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
 	ksz_pwrite8(dev, port, P_MIRROR_CTRL, data);
 }
 
-static void ksz8_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
+static int ksz8_get_stp_reg(void)
 {
-	ksz_port_stp_state_set(ds, port, state, P_STP_CTRL);
+	return P_STP_CTRL;
 }
 
 static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
@@ -1240,7 +1240,7 @@ static void ksz8_config_cpu_port(struct dsa_switch *ds)
 	for (i = 0; i < dev->phy_port_cnt; i++) {
 		p = &dev->ports[i];
 
-		ksz8_port_stp_state_set(ds, i, BR_STATE_DISABLED);
+		ksz_port_stp_state_set(ds, i, BR_STATE_DISABLED);
 
 		/* Last port may be disabled. */
 		if (i == dev->phy_port_cnt)
@@ -1389,7 +1389,7 @@ static const struct dsa_switch_ops ksz8_switch_ops = {
 	.get_sset_count		= ksz_sset_count,
 	.port_bridge_join	= ksz_port_bridge_join,
 	.port_bridge_leave	= ksz_port_bridge_leave,
-	.port_stp_state_set	= ksz8_port_stp_state_set,
+	.port_stp_state_set	= ksz_port_stp_state_set,
 	.port_fast_age		= ksz_port_fast_age,
 	.port_vlan_filtering	= ksz_port_vlan_filtering,
 	.port_vlan_add		= ksz_port_vlan_add,
@@ -1463,6 +1463,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.vlan_del = ksz8_port_vlan_del,
 	.mirror_add = ksz8_port_mirror_add,
 	.mirror_del = ksz8_port_mirror_del,
+	.get_stp_reg = ksz8_get_stp_reg,
 	.shutdown = ksz8_reset_switch,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 6796c9d89ab9..f08694aba6bb 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -344,10 +344,9 @@ static void ksz9477_cfg_port_member(struct ksz_device *dev, int port,
 	ksz_pwrite32(dev, port, REG_PORT_VLAN_MEMBERSHIP__4, member);
 }
 
-static void ksz9477_port_stp_state_set(struct dsa_switch *ds, int port,
-				       u8 state)
+static int ksz9477_get_stp_reg(void)
 {
-	ksz_port_stp_state_set(ds, port, state, P_STP_CTRL);
+	return P_STP_CTRL;
 }
 
 static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port)
@@ -1237,7 +1236,7 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 			continue;
 		p = &dev->ports[i];
 
-		ksz9477_port_stp_state_set(ds, i, BR_STATE_DISABLED);
+		ksz_port_stp_state_set(ds, i, BR_STATE_DISABLED);
 		p->on = 1;
 		if (i < dev->phy_port_cnt)
 			p->phy = 1;
@@ -1315,7 +1314,7 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.get_sset_count		= ksz_sset_count,
 	.port_bridge_join	= ksz_port_bridge_join,
 	.port_bridge_leave	= ksz_port_bridge_leave,
-	.port_stp_state_set	= ksz9477_port_stp_state_set,
+	.port_stp_state_set	= ksz_port_stp_state_set,
 	.port_fast_age		= ksz_port_fast_age,
 	.port_vlan_filtering	= ksz_port_vlan_filtering,
 	.port_vlan_add		= ksz_port_vlan_add,
@@ -1406,6 +1405,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.vlan_del = ksz9477_port_vlan_del,
 	.mirror_add = ksz9477_port_mirror_add,
 	.mirror_del = ksz9477_port_mirror_del,
+	.get_stp_reg = ksz9477_get_stp_reg,
 	.shutdown = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 1ed4cc94795e..5cf183f753d9 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -532,7 +532,7 @@ void ksz_get_strings(struct dsa_switch *ds, int port,
 }
 EXPORT_SYMBOL_GPL(ksz_get_strings);
 
-void ksz_update_port_member(struct ksz_device *dev, int port)
+static void ksz_update_port_member(struct ksz_device *dev, int port)
 {
 	struct ksz_port *p = &dev->ports[port];
 	struct dsa_switch *ds = dev->ds;
@@ -589,7 +589,6 @@ void ksz_update_port_member(struct ksz_device *dev, int port)
 
 	dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port);
 }
-EXPORT_SYMBOL_GPL(ksz_update_port_member);
 
 static void port_r_cnt(struct ksz_device *dev, int port)
 {
@@ -890,12 +889,14 @@ int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
 }
 EXPORT_SYMBOL_GPL(ksz_enable_port);
 
-void ksz_port_stp_state_set(struct dsa_switch *ds, int port,
-			    u8 state, int reg)
+void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
 {
 	struct ksz_device *dev = ds->priv;
 	struct ksz_port *p;
 	u8 data;
+	int reg;
+
+	reg = dev->dev_ops->get_stp_reg();
 
 	ksz_pread8(dev, port, reg, &data);
 	data &= ~(PORT_TX_ENABLE | PORT_RX_ENABLE | PORT_LEARN_DISABLE);
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 01080ec22bf1..2727934b7171 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -192,6 +192,7 @@ struct ksz_dev_ops {
 			  bool ingress, struct netlink_ext_ack *extack);
 	void (*mirror_del)(struct ksz_device *dev, int port,
 			   struct dsa_mall_mirror_tc_entry *mirror);
+	int (*get_stp_reg)(void);
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
 	int (*shutdown)(struct ksz_device *dev);
@@ -207,7 +208,6 @@ void ksz_switch_remove(struct ksz_device *dev);
 int ksz8_switch_register(struct ksz_device *dev);
 int ksz9477_switch_register(struct ksz_device *dev);
 
-void ksz_update_port_member(struct ksz_device *dev, int port);
 void ksz_init_mib_timer(struct ksz_device *dev);
 void ksz_r_mib_stats64(struct ksz_device *dev, int port);
 void ksz_get_stats64(struct dsa_switch *ds, int port,
@@ -229,8 +229,7 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port,
 			 struct netlink_ext_ack *extack);
 void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
 			   struct dsa_bridge bridge);
-void ksz_port_stp_state_set(struct dsa_switch *ds, int port,
-			    u8 state, int reg);
+void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
 void ksz_port_fast_age(struct dsa_switch *ds, int port);
 int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
 		      void *data);
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 07/15] net: dsa: microchip: update the ksz_phylink_get_caps
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (5 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 06/15] net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by ksz_dev_ops Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-13  9:32   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 08/15] net: dsa: microchip: update the ksz_port_mdb_add/del Arun Ramadoss
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch assigns the phylink_get_caps in ksz8795 and ksz9477 to
ksz_phylink_get_caps. And update their mac_capabilities in the
respective ksz_dev_ops.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    | 9 +++------
 drivers/net/dsa/microchip/ksz9477.c    | 7 +++----
 drivers/net/dsa/microchip/ksz_common.c | 3 +++
 drivers/net/dsa/microchip/ksz_common.h | 2 ++
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index e6982fa9d382..25763d89c67a 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -1353,13 +1353,9 @@ static int ksz8_setup(struct dsa_switch *ds)
 	return ksz8_handle_global_errata(ds);
 }
 
-static void ksz8_get_caps(struct dsa_switch *ds, int port,
+static void ksz8_get_caps(struct ksz_device *dev, int port,
 			  struct phylink_config *config)
 {
-	struct ksz_device *dev = ds->priv;
-
-	ksz_phylink_get_caps(ds, port, config);
-
 	config->mac_capabilities = MAC_10 | MAC_100;
 
 	/* Silicon Errata Sheet (DS80000830A):
@@ -1381,7 +1377,7 @@ static const struct dsa_switch_ops ksz8_switch_ops = {
 	.setup			= ksz8_setup,
 	.phy_read		= ksz_phy_read16,
 	.phy_write		= ksz_phy_write16,
-	.phylink_get_caps	= ksz8_get_caps,
+	.phylink_get_caps	= ksz_phylink_get_caps,
 	.phylink_mac_link_down	= ksz_mac_link_down,
 	.port_enable		= ksz_enable_port,
 	.get_strings		= ksz_get_strings,
@@ -1464,6 +1460,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.mirror_add = ksz8_port_mirror_add,
 	.mirror_del = ksz8_port_mirror_del,
 	.get_stp_reg = ksz8_get_stp_reg,
+	.get_caps = ksz8_get_caps,
 	.shutdown = ksz8_reset_switch,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index f08694aba6bb..494f93e4c7f8 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -1073,11 +1073,9 @@ static void ksz9477_phy_errata_setup(struct ksz_device *dev, int port)
 	ksz9477_port_mmd_write(dev, port, 0x1c, 0x20, 0xeeee);
 }
 
-static void ksz9477_get_caps(struct dsa_switch *ds, int port,
+static void ksz9477_get_caps(struct ksz_device *dev, int port,
 			     struct phylink_config *config)
 {
-	ksz_phylink_get_caps(ds, port, config);
-
 	config->mac_capabilities = MAC_10 | MAC_100 | MAC_1000FD |
 				   MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
 }
@@ -1307,7 +1305,7 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.phy_read		= ksz_phy_read16,
 	.phy_write		= ksz_phy_write16,
 	.phylink_mac_link_down	= ksz_mac_link_down,
-	.phylink_get_caps	= ksz9477_get_caps,
+	.phylink_get_caps	= ksz_phylink_get_caps,
 	.port_enable		= ksz_enable_port,
 	.get_strings		= ksz_get_strings,
 	.get_ethtool_stats	= ksz_get_ethtool_stats,
@@ -1406,6 +1404,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.mirror_add = ksz9477_port_mirror_add,
 	.mirror_del = ksz9477_port_mirror_del,
 	.get_stp_reg = ksz9477_get_stp_reg,
+	.get_caps = ksz9477_get_caps,
 	.shutdown = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 5cf183f753d9..c1303a46a9b7 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -456,6 +456,9 @@ void ksz_phylink_get_caps(struct dsa_switch *ds, int port,
 	if (dev->info->internal_phy[port])
 		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
 			  config->supported_interfaces);
+
+	if (dev->dev_ops->get_caps)
+		dev->dev_ops->get_caps(dev, port, config);
 }
 EXPORT_SYMBOL_GPL(ksz_phylink_get_caps);
 
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 2727934b7171..8124737a1170 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -193,6 +193,8 @@ struct ksz_dev_ops {
 	void (*mirror_del)(struct ksz_device *dev, int port,
 			   struct dsa_mall_mirror_tc_entry *mirror);
 	int (*get_stp_reg)(void);
+	void (*get_caps)(struct ksz_device *dev, int port,
+			 struct phylink_config *config);
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
 	int (*shutdown)(struct ksz_device *dev);
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 08/15] net: dsa: microchip: update the ksz_port_mdb_add/del
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (6 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 07/15] net: dsa: microchip: update the ksz_phylink_get_caps Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-13  9:36   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 09/15] net: dsa: microchip: update fdb add/del/dump in ksz_common Arun Ramadoss
                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

ksz_mdb_add/del in ksz_common.c is specific for the ksz8795.c file. The
ksz9477 has its separate ksz9477_port_mdb_add/del functions.  This patch
moves the ksz8795 specific mdb functionality from ksz_common to ksz8795.
And this dsa_switch_ops hooks for ksz8795/ksz9477 are invoked through
the ksz_port_mdb_add/del.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    | 76 ++++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz9477.c    | 20 +++----
 drivers/net/dsa/microchip/ksz_common.c | 66 +++-------------------
 drivers/net/dsa/microchip/ksz_common.h |  6 ++
 4 files changed, 100 insertions(+), 68 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 25763d89c67a..abd28dc44eb5 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -958,6 +958,80 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
 	}
 }
 
+static int ksz8_mdb_add(struct ksz_device *dev, int port,
+			const struct switchdev_obj_port_mdb *mdb,
+			struct dsa_db db)
+{
+	struct alu_struct alu;
+	int index;
+	int empty = 0;
+
+	alu.port_forward = 0;
+	for (index = 0; index < dev->info->num_statics; index++) {
+		if (!dev->dev_ops->r_sta_mac_table(dev, index, &alu)) {
+			/* Found one already in static MAC table. */
+			if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) &&
+			    alu.fid == mdb->vid)
+				break;
+		/* Remember the first empty entry. */
+		} else if (!empty) {
+			empty = index + 1;
+		}
+	}
+
+	/* no available entry */
+	if (index == dev->info->num_statics && !empty)
+		return -ENOSPC;
+
+	/* add entry */
+	if (index == dev->info->num_statics) {
+		index = empty - 1;
+		memset(&alu, 0, sizeof(alu));
+		memcpy(alu.mac, mdb->addr, ETH_ALEN);
+		alu.is_static = true;
+	}
+	alu.port_forward |= BIT(port);
+	if (mdb->vid) {
+		alu.is_use_fid = true;
+
+		/* Need a way to map VID to FID. */
+		alu.fid = mdb->vid;
+	}
+	dev->dev_ops->w_sta_mac_table(dev, index, &alu);
+
+	return 0;
+}
+
+static int ksz8_mdb_del(struct ksz_device *dev, int port,
+			const struct switchdev_obj_port_mdb *mdb,
+			struct dsa_db db)
+{
+	struct alu_struct alu;
+	int index;
+
+	for (index = 0; index < dev->info->num_statics; index++) {
+		if (!dev->dev_ops->r_sta_mac_table(dev, index, &alu)) {
+			/* Found one already in static MAC table. */
+			if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) &&
+			    alu.fid == mdb->vid)
+				break;
+		}
+	}
+
+	/* no available entry */
+	if (index == dev->info->num_statics)
+		goto exit;
+
+	/* clear port */
+	alu.port_forward &= ~BIT(port);
+	if (!alu.port_forward)
+		alu.is_static = false;
+	dev->dev_ops->w_sta_mac_table(dev, index, &alu);
+
+exit:
+	return 0;
+}
+
 static int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,
 				    struct netlink_ext_ack *extack)
 {
@@ -1454,6 +1528,8 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.r_mib_pkt = ksz8_r_mib_pkt,
 	.freeze_mib = ksz8_freeze_mib,
 	.port_init_cnt = ksz8_port_init_cnt,
+	.mdb_add = ksz8_mdb_add,
+	.mdb_del = ksz8_mdb_del,
 	.vlan_filtering = ksz8_port_vlan_filtering,
 	.vlan_add = ksz8_port_vlan_add,
 	.vlan_del = ksz8_port_vlan_del,
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 494f93e4c7f8..045856656466 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -658,11 +658,10 @@ static int ksz9477_port_fdb_dump(struct dsa_switch *ds, int port,
 	return ret;
 }
 
-static int ksz9477_port_mdb_add(struct dsa_switch *ds, int port,
-				const struct switchdev_obj_port_mdb *mdb,
-				struct dsa_db db)
+static int ksz9477_mdb_add(struct ksz_device *dev, int port,
+			   const struct switchdev_obj_port_mdb *mdb,
+			   struct dsa_db db)
 {
-	struct ksz_device *dev = ds->priv;
 	u32 static_table[4];
 	u32 data;
 	int index;
@@ -734,11 +733,10 @@ static int ksz9477_port_mdb_add(struct dsa_switch *ds, int port,
 	return err;
 }
 
-static int ksz9477_port_mdb_del(struct dsa_switch *ds, int port,
-				const struct switchdev_obj_port_mdb *mdb,
-				struct dsa_db db)
+static int ksz9477_mdb_del(struct ksz_device *dev, int port,
+			   const struct switchdev_obj_port_mdb *mdb,
+			   struct dsa_db db)
 {
-	struct ksz_device *dev = ds->priv;
 	u32 static_table[4];
 	u32 data;
 	int index;
@@ -1320,8 +1318,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.port_fdb_dump		= ksz9477_port_fdb_dump,
 	.port_fdb_add		= ksz9477_port_fdb_add,
 	.port_fdb_del		= ksz9477_port_fdb_del,
-	.port_mdb_add           = ksz9477_port_mdb_add,
-	.port_mdb_del           = ksz9477_port_mdb_del,
+	.port_mdb_add           = ksz_port_mdb_add,
+	.port_mdb_del           = ksz_port_mdb_del,
 	.port_mirror_add	= ksz_port_mirror_add,
 	.port_mirror_del	= ksz_port_mirror_del,
 	.get_stats64		= ksz_get_stats64,
@@ -1405,6 +1403,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.mirror_del = ksz9477_port_mirror_del,
 	.get_stp_reg = ksz9477_get_stp_reg,
 	.get_caps = ksz9477_get_caps,
+	.mdb_add = ksz9477_mdb_add,
+	.mdb_del = ksz9477_mdb_del,
 	.shutdown = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index c1303a46a9b7..b9082952db0f 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -801,44 +801,12 @@ int ksz_port_mdb_add(struct dsa_switch *ds, int port,
 		     struct dsa_db db)
 {
 	struct ksz_device *dev = ds->priv;
-	struct alu_struct alu;
-	int index;
-	int empty = 0;
-
-	alu.port_forward = 0;
-	for (index = 0; index < dev->info->num_statics; index++) {
-		if (!dev->dev_ops->r_sta_mac_table(dev, index, &alu)) {
-			/* Found one already in static MAC table. */
-			if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) &&
-			    alu.fid == mdb->vid)
-				break;
-		/* Remember the first empty entry. */
-		} else if (!empty) {
-			empty = index + 1;
-		}
-	}
-
-	/* no available entry */
-	if (index == dev->info->num_statics && !empty)
-		return -ENOSPC;
-
-	/* add entry */
-	if (index == dev->info->num_statics) {
-		index = empty - 1;
-		memset(&alu, 0, sizeof(alu));
-		memcpy(alu.mac, mdb->addr, ETH_ALEN);
-		alu.is_static = true;
-	}
-	alu.port_forward |= BIT(port);
-	if (mdb->vid) {
-		alu.is_use_fid = true;
+	int ret = -EOPNOTSUPP;
 
-		/* Need a way to map VID to FID. */
-		alu.fid = mdb->vid;
-	}
-	dev->dev_ops->w_sta_mac_table(dev, index, &alu);
+	if (dev->dev_ops->mdb_add)
+		ret = dev->dev_ops->mdb_add(dev, port, mdb, db);
 
-	return 0;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(ksz_port_mdb_add);
 
@@ -847,30 +815,12 @@ int ksz_port_mdb_del(struct dsa_switch *ds, int port,
 		     struct dsa_db db)
 {
 	struct ksz_device *dev = ds->priv;
-	struct alu_struct alu;
-	int index;
-
-	for (index = 0; index < dev->info->num_statics; index++) {
-		if (!dev->dev_ops->r_sta_mac_table(dev, index, &alu)) {
-			/* Found one already in static MAC table. */
-			if (!memcmp(alu.mac, mdb->addr, ETH_ALEN) &&
-			    alu.fid == mdb->vid)
-				break;
-		}
-	}
-
-	/* no available entry */
-	if (index == dev->info->num_statics)
-		goto exit;
+	int ret = -EOPNOTSUPP;
 
-	/* clear port */
-	alu.port_forward &= ~BIT(port);
-	if (!alu.port_forward)
-		alu.is_static = false;
-	dev->dev_ops->w_sta_mac_table(dev, index, &alu);
+	if (dev->dev_ops->mdb_del)
+		ret = dev->dev_ops->mdb_del(dev, port, mdb, db);
 
-exit:
-	return 0;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(ksz_port_mdb_del);
 
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 8124737a1170..816581dd7f8e 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -192,6 +192,12 @@ struct ksz_dev_ops {
 			  bool ingress, struct netlink_ext_ack *extack);
 	void (*mirror_del)(struct ksz_device *dev, int port,
 			   struct dsa_mall_mirror_tc_entry *mirror);
+	int (*mdb_add)(struct ksz_device *dev, int port,
+		       const struct switchdev_obj_port_mdb *mdb,
+		       struct dsa_db db);
+	int (*mdb_del)(struct ksz_device *dev, int port,
+		       const struct switchdev_obj_port_mdb *mdb,
+		       struct dsa_db db);
 	int (*get_stp_reg)(void);
 	void (*get_caps)(struct ksz_device *dev, int port,
 			 struct phylink_config *config);
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 09/15] net: dsa: microchip: update fdb add/del/dump in ksz_common
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (7 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 08/15] net: dsa: microchip: update the ksz_port_mdb_add/del Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-13  9:42   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 10/15] net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common Arun Ramadoss
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch makes the dsa_switch_hook for fdbs to use ksz_common.c file.
And from ksz_common, individual switches fdb functions are called using
the dev->dev_ops.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    | 30 +++++++++++++++
 drivers/net/dsa/microchip/ksz9477.c    | 28 +++++++-------
 drivers/net/dsa/microchip/ksz_common.c | 52 +++++++++++++++-----------
 drivers/net/dsa/microchip/ksz_common.h | 10 +++++
 4 files changed, 84 insertions(+), 36 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index abd28dc44eb5..528de481b319 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -958,6 +958,35 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
 	}
 }
 
+static int ksz8_fdb_dump(struct ksz_device *dev, int port,
+			 dsa_fdb_dump_cb_t *cb, void *data)
+{
+	int ret = 0;
+	u16 i = 0;
+	u16 entries = 0;
+	u8 timestamp = 0;
+	u8 fid;
+	u8 member;
+	struct alu_struct alu;
+
+	do {
+		alu.is_static = false;
+		ret = dev->dev_ops->r_dyn_mac_table(dev, i, alu.mac, &fid,
+						    &member, &timestamp,
+						    &entries);
+		if (!ret && (member & BIT(port))) {
+			ret = cb(alu.mac, alu.fid, alu.is_static, data);
+			if (ret)
+				break;
+		}
+		i++;
+	} while (i < entries);
+	if (i >= entries)
+		ret = 0;
+
+	return ret;
+}
+
 static int ksz8_mdb_add(struct ksz_device *dev, int port,
 			const struct switchdev_obj_port_mdb *mdb,
 			struct dsa_db db)
@@ -1528,6 +1557,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.r_mib_pkt = ksz8_r_mib_pkt,
 	.freeze_mib = ksz8_freeze_mib,
 	.port_init_cnt = ksz8_port_init_cnt,
+	.fdb_dump = ksz8_fdb_dump,
 	.mdb_add = ksz8_mdb_add,
 	.mdb_del = ksz8_mdb_del,
 	.vlan_filtering = ksz8_port_vlan_filtering,
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 045856656466..d70e0c32b309 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -457,11 +457,10 @@ static int ksz9477_port_vlan_del(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz9477_port_fdb_add(struct dsa_switch *ds, int port,
-				const unsigned char *addr, u16 vid,
-				struct dsa_db db)
+static int ksz9477_fdb_add(struct ksz_device *dev, int port,
+			   const unsigned char *addr, u16 vid,
+			   struct dsa_db db)
 {
-	struct ksz_device *dev = ds->priv;
 	u32 alu_table[4];
 	u32 data;
 	int ret = 0;
@@ -515,11 +514,10 @@ static int ksz9477_port_fdb_add(struct dsa_switch *ds, int port,
 	return ret;
 }
 
-static int ksz9477_port_fdb_del(struct dsa_switch *ds, int port,
-				const unsigned char *addr, u16 vid,
-				struct dsa_db db)
+static int ksz9477_fdb_del(struct ksz_device *dev, int port,
+			   const unsigned char *addr, u16 vid,
+			   struct dsa_db db)
 {
-	struct ksz_device *dev = ds->priv;
 	u32 alu_table[4];
 	u32 data;
 	int ret = 0;
@@ -606,10 +604,9 @@ static void ksz9477_convert_alu(struct alu_struct *alu, u32 *alu_table)
 	alu->mac[5] = alu_table[3] & 0xFF;
 }
 
-static int ksz9477_port_fdb_dump(struct dsa_switch *ds, int port,
-				 dsa_fdb_dump_cb_t *cb, void *data)
+static int ksz9477_fdb_dump(struct ksz_device *dev, int port,
+			    dsa_fdb_dump_cb_t *cb, void *data)
 {
-	struct ksz_device *dev = ds->priv;
 	int ret = 0;
 	u32 ksz_data;
 	u32 alu_table[4];
@@ -1315,9 +1312,9 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.port_vlan_filtering	= ksz_port_vlan_filtering,
 	.port_vlan_add		= ksz_port_vlan_add,
 	.port_vlan_del		= ksz_port_vlan_del,
-	.port_fdb_dump		= ksz9477_port_fdb_dump,
-	.port_fdb_add		= ksz9477_port_fdb_add,
-	.port_fdb_del		= ksz9477_port_fdb_del,
+	.port_fdb_dump		= ksz_port_fdb_dump,
+	.port_fdb_add		= ksz_port_fdb_add,
+	.port_fdb_del		= ksz_port_fdb_del,
 	.port_mdb_add           = ksz_port_mdb_add,
 	.port_mdb_del           = ksz_port_mdb_del,
 	.port_mirror_add	= ksz_port_mirror_add,
@@ -1403,6 +1400,9 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.mirror_del = ksz9477_port_mirror_del,
 	.get_stp_reg = ksz9477_get_stp_reg,
 	.get_caps = ksz9477_get_caps,
+	.fdb_dump = ksz9477_fdb_dump,
+	.fdb_add = ksz9477_fdb_add,
+	.fdb_del = ksz9477_fdb_del,
 	.mdb_add = ksz9477_mdb_add,
 	.mdb_del = ksz9477_mdb_del,
 	.shutdown = ksz9477_reset_switch,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index b9082952db0f..8f79ff1ac648 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -765,32 +765,40 @@ void ksz_port_fast_age(struct dsa_switch *ds, int port)
 }
 EXPORT_SYMBOL_GPL(ksz_port_fast_age);
 
+int ksz_port_fdb_add(struct dsa_switch *ds, int port,
+		     const unsigned char *addr, u16 vid, struct dsa_db db)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->fdb_add)
+		ret = dev->dev_ops->fdb_add(dev, port, addr, vid, db);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ksz_port_fdb_add);
+
+int ksz_port_fdb_del(struct dsa_switch *ds, int port,
+		     const unsigned char *addr, u16 vid, struct dsa_db db)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->fdb_del)
+		ret = dev->dev_ops->fdb_del(dev, port, addr, vid, db);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ksz_port_fdb_del);
+
 int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
 		      void *data)
 {
 	struct ksz_device *dev = ds->priv;
-	int ret = 0;
-	u16 i = 0;
-	u16 entries = 0;
-	u8 timestamp = 0;
-	u8 fid;
-	u8 member;
-	struct alu_struct alu;
-
-	do {
-		alu.is_static = false;
-		ret = dev->dev_ops->r_dyn_mac_table(dev, i, alu.mac, &fid,
-						    &member, &timestamp,
-						    &entries);
-		if (!ret && (member & BIT(port))) {
-			ret = cb(alu.mac, alu.fid, alu.is_static, data);
-			if (ret)
-				break;
-		}
-		i++;
-	} while (i < entries);
-	if (i >= entries)
-		ret = 0;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->fdb_dump)
+		ret = dev->dev_ops->fdb_dump(dev, port, cb, data);
 
 	return ret;
 }
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 816581dd7f8e..133b1a257868 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -192,6 +192,12 @@ struct ksz_dev_ops {
 			  bool ingress, struct netlink_ext_ack *extack);
 	void (*mirror_del)(struct ksz_device *dev, int port,
 			   struct dsa_mall_mirror_tc_entry *mirror);
+	int (*fdb_add)(struct ksz_device *dev, int port,
+		       const unsigned char *addr, u16 vid, struct dsa_db db);
+	int (*fdb_del)(struct ksz_device *dev, int port,
+		       const unsigned char *addr, u16 vid, struct dsa_db db);
+	int (*fdb_dump)(struct ksz_device *dev, int port,
+			dsa_fdb_dump_cb_t *cb, void *data);
 	int (*mdb_add)(struct ksz_device *dev, int port,
 		       const struct switchdev_obj_port_mdb *mdb,
 		       struct dsa_db db);
@@ -239,6 +245,10 @@ void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
 			   struct dsa_bridge bridge);
 void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
 void ksz_port_fast_age(struct dsa_switch *ds, int port);
+int ksz_port_fdb_add(struct dsa_switch *ds, int port,
+		     const unsigned char *addr, u16 vid, struct dsa_db db);
+int ksz_port_fdb_del(struct dsa_switch *ds, int port,
+		     const unsigned char *addr, u16 vid, struct dsa_db db);
 int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
 		      void *data);
 int ksz_port_mdb_add(struct dsa_switch *ds, int port,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 10/15] net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (8 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 09/15] net: dsa: microchip: update fdb add/del/dump in ksz_common Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-14  8:15   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 11/15] net: dsa: microchip: common dsa_switch_ops for ksz switches Arun Ramadoss
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch assigns the .setup, get_phy_flags & mtu  hook of ksz8795 and
ksz9477 in dsa_switch_ops to ksz_common. And the individual switches
setup implementations are called based on the ksz_dev_ops.  For
get_phy_flags hooks,checks whether the chip is ksz8863/kss8793 then it
returns error for port1.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    | 17 ++-------
 drivers/net/dsa/microchip/ksz9477.c    | 14 ++++----
 drivers/net/dsa/microchip/ksz_common.c | 50 ++++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h |  7 ++++
 4 files changed, 68 insertions(+), 20 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 528de481b319..1058b6883caa 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -898,18 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 	}
 }
 
-static u32 ksz8_sw_get_phy_flags(struct dsa_switch *ds, int port)
-{
-	/* Silicon Errata Sheet (DS80000830A):
-	 * Port 1 does not work with LinkMD Cable-Testing.
-	 * Port 1 does not respond to received PAUSE control frames.
-	 */
-	if (!port)
-		return MICREL_KSZ8_P1_ERRATA;
-
-	return 0;
-}
-
 static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
 {
 	u8 data;
@@ -1476,8 +1464,8 @@ static void ksz8_get_caps(struct ksz_device *dev, int port,
 
 static const struct dsa_switch_ops ksz8_switch_ops = {
 	.get_tag_protocol	= ksz_get_tag_protocol,
-	.get_phy_flags		= ksz8_sw_get_phy_flags,
-	.setup			= ksz8_setup,
+	.get_phy_flags		= ksz_get_phy_flags,
+	.setup			= ksz_setup,
 	.phy_read		= ksz_phy_read16,
 	.phy_write		= ksz_phy_write16,
 	.phylink_get_caps	= ksz_phylink_get_caps,
@@ -1544,6 +1532,7 @@ static void ksz8_switch_exit(struct ksz_device *dev)
 }
 
 static const struct ksz_dev_ops ksz8_dev_ops = {
+	.setup = ksz8_setup,
 	.get_port_addr = ksz8_get_port_addr,
 	.cfg_port_member = ksz8_cfg_port_member,
 	.flush_dyn_mac_table = ksz8_flush_dyn_mac_table,
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index d70e0c32b309..d7474d9d4384 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -47,9 +47,8 @@ static void ksz9477_port_cfg32(struct ksz_device *dev, int port, int offset,
 			   bits, set ? bits : 0);
 }
 
-static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu)
+static int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu)
 {
-	struct ksz_device *dev = ds->priv;
 	u16 frame_size, max_frame = 0;
 	int i;
 
@@ -65,7 +64,7 @@ static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu)
 				  REG_SW_MTU_MASK, max_frame);
 }
 
-static int ksz9477_max_mtu(struct dsa_switch *ds, int port)
+static int ksz9477_max_mtu(struct ksz_device *dev, int port)
 {
 	return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
 }
@@ -1296,7 +1295,7 @@ static int ksz9477_setup(struct dsa_switch *ds)
 
 static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.get_tag_protocol	= ksz_get_tag_protocol,
-	.setup			= ksz9477_setup,
+	.setup			= ksz_setup,
 	.phy_read		= ksz_phy_read16,
 	.phy_write		= ksz_phy_write16,
 	.phylink_mac_link_down	= ksz_mac_link_down,
@@ -1320,8 +1319,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
 	.port_mirror_add	= ksz_port_mirror_add,
 	.port_mirror_del	= ksz_port_mirror_del,
 	.get_stats64		= ksz_get_stats64,
-	.port_change_mtu	= ksz9477_change_mtu,
-	.port_max_mtu		= ksz9477_max_mtu,
+	.port_change_mtu	= ksz_change_mtu,
+	.port_max_mtu		= ksz_max_mtu,
 };
 
 static u32 ksz9477_get_port_addr(int port, int offset)
@@ -1382,6 +1381,7 @@ static void ksz9477_switch_exit(struct ksz_device *dev)
 }
 
 static const struct ksz_dev_ops ksz9477_dev_ops = {
+	.setup = ksz9477_setup,
 	.get_port_addr = ksz9477_get_port_addr,
 	.cfg_port_member = ksz9477_cfg_port_member,
 	.flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
@@ -1405,6 +1405,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.fdb_del = ksz9477_fdb_del,
 	.mdb_add = ksz9477_mdb_add,
 	.mdb_del = ksz9477_mdb_del,
+	.change_mtu = ksz9477_change_mtu,
+	.max_mtu = ksz9477_max_mtu,
 	.shutdown = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 8f79ff1ac648..19f8e492d3aa 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -16,6 +16,7 @@
 #include <linux/if_bridge.h>
 #include <linux/of_device.h>
 #include <linux/of_net.h>
+#include <linux/micrel_phy.h>
 #include <net/dsa.h>
 #include <net/switchdev.h>
 
@@ -593,6 +594,14 @@ static void ksz_update_port_member(struct ksz_device *dev, int port)
 	dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port);
 }
 
+int ksz_setup(struct dsa_switch *ds)
+{
+	struct ksz_device *dev = ds->priv;
+
+	return dev->dev_ops->setup(ds);
+}
+EXPORT_SYMBOL_GPL(ksz_setup);
+
 static void port_r_cnt(struct ksz_device *dev, int port)
 {
 	struct ksz_port_mib *mib = &dev->ports[port].mib;
@@ -692,6 +701,23 @@ int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
 }
 EXPORT_SYMBOL_GPL(ksz_phy_write16);
 
+u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
+{
+	struct ksz_device *dev = ds->priv;
+
+	if (dev->chip_id == KSZ8830_CHIP_ID) {
+		/* Silicon Errata Sheet (DS80000830A):
+		 * Port 1 does not work with LinkMD Cable-Testing.
+		 * Port 1 does not respond to received PAUSE control frames.
+		 */
+		if (!port)
+			return MICREL_KSZ8_P1_ERRATA;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(ksz_get_phy_flags);
+
 void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
 		       phy_interface_t interface)
 {
@@ -981,6 +1007,30 @@ void ksz_port_mirror_del(struct dsa_switch *ds, int port,
 }
 EXPORT_SYMBOL_GPL(ksz_port_mirror_del);
 
+int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->change_mtu)
+		ret = dev->dev_ops->change_mtu(dev, port, mtu);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ksz_change_mtu);
+
+int ksz_max_mtu(struct dsa_switch *ds, int port)
+{
+	struct ksz_device *dev = ds->priv;
+	int ret = -EOPNOTSUPP;
+
+	if (dev->dev_ops->max_mtu)
+		ret = dev->dev_ops->max_mtu(dev, port);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ksz_max_mtu);
+
 static int ksz_switch_detect(struct ksz_device *dev)
 {
 	u8 id1, id2;
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 133b1a257868..f7275c4f633a 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -161,6 +161,7 @@ struct alu_struct {
 };
 
 struct ksz_dev_ops {
+	int (*setup)(struct dsa_switch *ds);
 	u32 (*get_port_addr)(int port, int offset);
 	void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
 	void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
@@ -207,6 +208,8 @@ struct ksz_dev_ops {
 	int (*get_stp_reg)(void);
 	void (*get_caps)(struct ksz_device *dev, int port,
 			 struct phylink_config *config);
+	int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
+	int (*max_mtu)(struct ksz_device *dev, int port);
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
 	int (*shutdown)(struct ksz_device *dev);
@@ -232,8 +235,10 @@ extern const struct ksz_chip_data ksz_switch_chips[];
 
 /* Common DSA access functions */
 
+int ksz_setup(struct dsa_switch *ds);
 int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg);
 int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val);
+u32 ksz_get_phy_flags(struct dsa_switch *ds, int port);
 void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
 		       phy_interface_t interface);
 int ksz_sset_count(struct dsa_switch *ds, int port, int sset);
@@ -274,6 +279,8 @@ int ksz_port_mirror_add(struct dsa_switch *ds, int port,
 			bool ingress, struct netlink_ext_ack *extack);
 void ksz_port_mirror_del(struct dsa_switch *ds, int port,
 			 struct dsa_mall_mirror_tc_entry *mirror);
+int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu);
+int ksz_max_mtu(struct dsa_switch *ds, int port);
 
 /* Common register access functions */
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 11/15] net: dsa: microchip: common dsa_switch_ops for ksz switches
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (9 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 10/15] net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-05-30 10:42 ` [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register Arun Ramadoss
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

At present, ksz8795.c and ksz9477.c have separate dsa_switch_ops
structure initialization. This patch modifies the files such a way that
ksz switches has common dsa_switch_ops in the ksz_common.c file.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8795.c    |  28 -----
 drivers/net/dsa/microchip/ksz9477.c    |  33 +----
 drivers/net/dsa/microchip/ksz_common.c | 164 +++++++++++++------------
 drivers/net/dsa/microchip/ksz_common.h |  54 +-------
 4 files changed, 89 insertions(+), 190 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 1058b6883caa..ff4b33a3b1b4 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -1462,32 +1462,6 @@ static void ksz8_get_caps(struct ksz_device *dev, int port,
 		config->mac_capabilities |= MAC_ASYM_PAUSE;
 }
 
-static const struct dsa_switch_ops ksz8_switch_ops = {
-	.get_tag_protocol	= ksz_get_tag_protocol,
-	.get_phy_flags		= ksz_get_phy_flags,
-	.setup			= ksz_setup,
-	.phy_read		= ksz_phy_read16,
-	.phy_write		= ksz_phy_write16,
-	.phylink_get_caps	= ksz_phylink_get_caps,
-	.phylink_mac_link_down	= ksz_mac_link_down,
-	.port_enable		= ksz_enable_port,
-	.get_strings		= ksz_get_strings,
-	.get_ethtool_stats	= ksz_get_ethtool_stats,
-	.get_sset_count		= ksz_sset_count,
-	.port_bridge_join	= ksz_port_bridge_join,
-	.port_bridge_leave	= ksz_port_bridge_leave,
-	.port_stp_state_set	= ksz_port_stp_state_set,
-	.port_fast_age		= ksz_port_fast_age,
-	.port_vlan_filtering	= ksz_port_vlan_filtering,
-	.port_vlan_add		= ksz_port_vlan_add,
-	.port_vlan_del		= ksz_port_vlan_del,
-	.port_fdb_dump		= ksz_port_fdb_dump,
-	.port_mdb_add           = ksz_port_mdb_add,
-	.port_mdb_del           = ksz_port_mdb_del,
-	.port_mirror_add	= ksz_port_mirror_add,
-	.port_mirror_del	= ksz_port_mirror_del,
-};
-
 static u32 ksz8_get_port_addr(int port, int offset)
 {
 	return PORT_CTRL_ADDR(port, offset);
@@ -1497,8 +1471,6 @@ static int ksz8_switch_init(struct ksz_device *dev)
 {
 	struct ksz8 *ksz8 = dev->priv;
 
-	dev->ds->ops = &ksz8_switch_ops;
-
 	dev->cpu_port = fls(dev->info->cpu_ports) - 1;
 	dev->phy_port_cnt = dev->info->port_cnt - 1;
 	dev->port_mask = (BIT(dev->phy_port_cnt) - 1) | dev->info->cpu_ports;
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index d7474d9d4384..ecce99b77ef6 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -1293,36 +1293,6 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	return 0;
 }
 
-static const struct dsa_switch_ops ksz9477_switch_ops = {
-	.get_tag_protocol	= ksz_get_tag_protocol,
-	.setup			= ksz_setup,
-	.phy_read		= ksz_phy_read16,
-	.phy_write		= ksz_phy_write16,
-	.phylink_mac_link_down	= ksz_mac_link_down,
-	.phylink_get_caps	= ksz_phylink_get_caps,
-	.port_enable		= ksz_enable_port,
-	.get_strings		= ksz_get_strings,
-	.get_ethtool_stats	= ksz_get_ethtool_stats,
-	.get_sset_count		= ksz_sset_count,
-	.port_bridge_join	= ksz_port_bridge_join,
-	.port_bridge_leave	= ksz_port_bridge_leave,
-	.port_stp_state_set	= ksz_port_stp_state_set,
-	.port_fast_age		= ksz_port_fast_age,
-	.port_vlan_filtering	= ksz_port_vlan_filtering,
-	.port_vlan_add		= ksz_port_vlan_add,
-	.port_vlan_del		= ksz_port_vlan_del,
-	.port_fdb_dump		= ksz_port_fdb_dump,
-	.port_fdb_add		= ksz_port_fdb_add,
-	.port_fdb_del		= ksz_port_fdb_del,
-	.port_mdb_add           = ksz_port_mdb_add,
-	.port_mdb_del           = ksz_port_mdb_del,
-	.port_mirror_add	= ksz_port_mirror_add,
-	.port_mirror_del	= ksz_port_mirror_del,
-	.get_stats64		= ksz_get_stats64,
-	.port_change_mtu	= ksz_change_mtu,
-	.port_max_mtu		= ksz_max_mtu,
-};
-
 static u32 ksz9477_get_port_addr(int port, int offset)
 {
 	return PORT_CTRL_ADDR(port, offset);
@@ -1333,8 +1303,6 @@ static int ksz9477_switch_init(struct ksz_device *dev)
 	u8 data8;
 	int ret;
 
-	dev->ds->ops = &ksz9477_switch_ops;
-
 	dev->port_mask = (1 << dev->info->port_cnt) - 1;
 
 	/* turn off SPI DO Edge select */
@@ -1372,6 +1340,7 @@ static int ksz9477_switch_init(struct ksz_device *dev)
 		if (!(data8 & SW_GIGABIT_ABLE))
 			dev->features &= ~GBIT_SUPPORT;
 	}
+
 	return 0;
 }
 
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 19f8e492d3aa..ace5cf0ad5a8 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -437,8 +437,8 @@ static int ksz_check_device_id(struct ksz_device *dev)
 	return 0;
 }
 
-void ksz_phylink_get_caps(struct dsa_switch *ds, int port,
-			  struct phylink_config *config)
+static void ksz_phylink_get_caps(struct dsa_switch *ds, int port,
+				 struct phylink_config *config)
 {
 	struct ksz_device *dev = ds->priv;
 
@@ -461,7 +461,6 @@ void ksz_phylink_get_caps(struct dsa_switch *ds, int port,
 	if (dev->dev_ops->get_caps)
 		dev->dev_ops->get_caps(dev, port, config);
 }
-EXPORT_SYMBOL_GPL(ksz_phylink_get_caps);
 
 void ksz_r_mib_stats64(struct ksz_device *dev, int port)
 {
@@ -506,8 +505,8 @@ void ksz_r_mib_stats64(struct ksz_device *dev, int port)
 }
 EXPORT_SYMBOL_GPL(ksz_r_mib_stats64);
 
-void ksz_get_stats64(struct dsa_switch *ds, int port,
-		     struct rtnl_link_stats64 *s)
+static void ksz_get_stats64(struct dsa_switch *ds, int port,
+			    struct rtnl_link_stats64 *s)
 {
 	struct ksz_device *dev = ds->priv;
 	struct ksz_port_mib *mib;
@@ -518,10 +517,9 @@ void ksz_get_stats64(struct dsa_switch *ds, int port,
 	memcpy(s, &mib->stats64, sizeof(*s));
 	spin_unlock(&mib->stats64_lock);
 }
-EXPORT_SYMBOL_GPL(ksz_get_stats64);
 
-void ksz_get_strings(struct dsa_switch *ds, int port,
-		     u32 stringset, uint8_t *buf)
+static void ksz_get_strings(struct dsa_switch *ds, int port,
+			    u32 stringset, uint8_t *buf)
 {
 	struct ksz_device *dev = ds->priv;
 	int i;
@@ -534,7 +532,6 @@ void ksz_get_strings(struct dsa_switch *ds, int port,
 		       dev->info->mib_names[i].string, ETH_GSTRING_LEN);
 	}
 }
-EXPORT_SYMBOL_GPL(ksz_get_strings);
 
 static void ksz_update_port_member(struct ksz_device *dev, int port)
 {
@@ -594,13 +591,12 @@ static void ksz_update_port_member(struct ksz_device *dev, int port)
 	dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port);
 }
 
-int ksz_setup(struct dsa_switch *ds)
+static int ksz_setup(struct dsa_switch *ds)
 {
 	struct ksz_device *dev = ds->priv;
 
 	return dev->dev_ops->setup(ds);
 }
-EXPORT_SYMBOL_GPL(ksz_setup);
 
 static void port_r_cnt(struct ksz_device *dev, int port)
 {
@@ -680,7 +676,7 @@ void ksz_init_mib_timer(struct ksz_device *dev)
 }
 EXPORT_SYMBOL_GPL(ksz_init_mib_timer);
 
-int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg)
+static int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg)
 {
 	struct ksz_device *dev = ds->priv;
 	u16 val = 0xffff;
@@ -689,9 +685,8 @@ int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg)
 
 	return val;
 }
-EXPORT_SYMBOL_GPL(ksz_phy_read16);
 
-int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
+static int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
 {
 	struct ksz_device *dev = ds->priv;
 
@@ -699,9 +694,8 @@ int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(ksz_phy_write16);
 
-u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
+static u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
 {
 	struct ksz_device *dev = ds->priv;
 
@@ -716,10 +710,9 @@ u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(ksz_get_phy_flags);
 
-void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
-		       phy_interface_t interface)
+static void ksz_mac_link_down(struct dsa_switch *ds, int port,
+			      unsigned int mode, phy_interface_t interface)
 {
 	struct ksz_device *dev = ds->priv;
 	struct ksz_port *p = &dev->ports[port];
@@ -730,9 +723,8 @@ void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
 	if (dev->mib_read_interval)
 		schedule_delayed_work(&dev->mib_read, 0);
 }
-EXPORT_SYMBOL_GPL(ksz_mac_link_down);
 
-int ksz_sset_count(struct dsa_switch *ds, int port, int sset)
+static int ksz_sset_count(struct dsa_switch *ds, int port, int sset)
 {
 	struct ksz_device *dev = ds->priv;
 
@@ -741,9 +733,9 @@ int ksz_sset_count(struct dsa_switch *ds, int port, int sset)
 
 	return dev->info->mib_cnt;
 }
-EXPORT_SYMBOL_GPL(ksz_sset_count);
 
-void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf)
+static void ksz_get_ethtool_stats(struct dsa_switch *ds, int port,
+				  uint64_t *buf)
 {
 	const struct dsa_port *dp = dsa_to_port(ds, port);
 	struct ksz_device *dev = ds->priv;
@@ -759,12 +751,11 @@ void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf)
 	memcpy(buf, mib->counters, dev->info->mib_cnt * sizeof(u64));
 	mutex_unlock(&mib->cnt_mutex);
 }
-EXPORT_SYMBOL_GPL(ksz_get_ethtool_stats);
 
-int ksz_port_bridge_join(struct dsa_switch *ds, int port,
-			 struct dsa_bridge bridge,
-			 bool *tx_fwd_offload,
-			 struct netlink_ext_ack *extack)
+static int ksz_port_bridge_join(struct dsa_switch *ds, int port,
+				struct dsa_bridge bridge,
+				bool *tx_fwd_offload,
+				struct netlink_ext_ack *extack)
 {
 	/* port_stp_state_set() will be called after to put the port in
 	 * appropriate state so there is no need to do anything.
@@ -772,27 +763,25 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(ksz_port_bridge_join);
 
-void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
-			   struct dsa_bridge bridge)
+static void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
+				  struct dsa_bridge bridge)
 {
 	/* port_stp_state_set() will be called after to put the port in
 	 * forwarding state so there is no need to do anything.
 	 */
 }
-EXPORT_SYMBOL_GPL(ksz_port_bridge_leave);
 
-void ksz_port_fast_age(struct dsa_switch *ds, int port)
+static void ksz_port_fast_age(struct dsa_switch *ds, int port)
 {
 	struct ksz_device *dev = ds->priv;
 
 	dev->dev_ops->flush_dyn_mac_table(dev, port);
 }
-EXPORT_SYMBOL_GPL(ksz_port_fast_age);
 
-int ksz_port_fdb_add(struct dsa_switch *ds, int port,
-		     const unsigned char *addr, u16 vid, struct dsa_db db)
+static int ksz_port_fdb_add(struct dsa_switch *ds, int port,
+			    const unsigned char *addr, u16 vid,
+			    struct dsa_db db)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -802,10 +791,10 @@ int ksz_port_fdb_add(struct dsa_switch *ds, int port,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_fdb_add);
 
-int ksz_port_fdb_del(struct dsa_switch *ds, int port,
-		     const unsigned char *addr, u16 vid, struct dsa_db db)
+static int ksz_port_fdb_del(struct dsa_switch *ds, int port,
+			    const unsigned char *addr,
+			    u16 vid, struct dsa_db db)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -815,10 +804,9 @@ int ksz_port_fdb_del(struct dsa_switch *ds, int port,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_fdb_del);
 
-int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
-		      void *data)
+static int ksz_port_fdb_dump(struct dsa_switch *ds, int port,
+			     dsa_fdb_dump_cb_t *cb, void *data)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -828,11 +816,10 @@ int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_fdb_dump);
 
-int ksz_port_mdb_add(struct dsa_switch *ds, int port,
-		     const struct switchdev_obj_port_mdb *mdb,
-		     struct dsa_db db)
+static int ksz_port_mdb_add(struct dsa_switch *ds, int port,
+			    const struct switchdev_obj_port_mdb *mdb,
+			    struct dsa_db db)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -842,11 +829,10 @@ int ksz_port_mdb_add(struct dsa_switch *ds, int port,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_mdb_add);
 
-int ksz_port_mdb_del(struct dsa_switch *ds, int port,
-		     const struct switchdev_obj_port_mdb *mdb,
-		     struct dsa_db db)
+static int ksz_port_mdb_del(struct dsa_switch *ds, int port,
+			    const struct switchdev_obj_port_mdb *mdb,
+			    struct dsa_db db)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -856,9 +842,9 @@ int ksz_port_mdb_del(struct dsa_switch *ds, int port,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_mdb_del);
 
-int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
+static int ksz_enable_port(struct dsa_switch *ds, int port,
+			   struct phy_device *phy)
 {
 	struct ksz_device *dev = ds->priv;
 
@@ -874,7 +860,6 @@ int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(ksz_enable_port);
 
 void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
 {
@@ -918,8 +903,9 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
 }
 EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
 
-enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
-					   int port, enum dsa_tag_protocol mp)
+static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
+						  int port,
+						  enum dsa_tag_protocol mp)
 {
 	struct ksz_device *dev = ds->priv;
 	enum dsa_tag_protocol proto;
@@ -940,10 +926,9 @@ enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
 
 	return proto;
 }
-EXPORT_SYMBOL_GPL(ksz_get_tag_protocol);
 
-int ksz_port_vlan_filtering(struct dsa_switch *ds, int port,
-			    bool flag, struct netlink_ext_ack *extack)
+static int ksz_port_vlan_filtering(struct dsa_switch *ds, int port,
+				   bool flag, struct netlink_ext_ack *extack)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -953,11 +938,10 @@ int ksz_port_vlan_filtering(struct dsa_switch *ds, int port,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_vlan_filtering);
 
-int ksz_port_vlan_add(struct dsa_switch *ds, int port,
-		      const struct switchdev_obj_port_vlan *vlan,
-		      struct netlink_ext_ack *extack)
+static int ksz_port_vlan_add(struct dsa_switch *ds, int port,
+			     const struct switchdev_obj_port_vlan *vlan,
+			     struct netlink_ext_ack *extack)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -967,10 +951,9 @@ int ksz_port_vlan_add(struct dsa_switch *ds, int port,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_vlan_add);
 
-int ksz_port_vlan_del(struct dsa_switch *ds, int port,
-		      const struct switchdev_obj_port_vlan *vlan)
+static int ksz_port_vlan_del(struct dsa_switch *ds, int port,
+			     const struct switchdev_obj_port_vlan *vlan)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -980,11 +963,10 @@ int ksz_port_vlan_del(struct dsa_switch *ds, int port,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_vlan_del);
 
-int ksz_port_mirror_add(struct dsa_switch *ds, int port,
-			struct dsa_mall_mirror_tc_entry *mirror,
-			bool ingress, struct netlink_ext_ack *extack)
+static int ksz_port_mirror_add(struct dsa_switch *ds, int port,
+			       struct dsa_mall_mirror_tc_entry *mirror,
+			       bool ingress, struct netlink_ext_ack *extack)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -995,19 +977,17 @@ int ksz_port_mirror_add(struct dsa_switch *ds, int port,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_port_mirror_add);
 
-void ksz_port_mirror_del(struct dsa_switch *ds, int port,
-			 struct dsa_mall_mirror_tc_entry *mirror)
+static void ksz_port_mirror_del(struct dsa_switch *ds, int port,
+				struct dsa_mall_mirror_tc_entry *mirror)
 {
 	struct ksz_device *dev = ds->priv;
 
 	if (dev->dev_ops->mirror_del)
 		dev->dev_ops->mirror_del(dev, port, mirror);
 }
-EXPORT_SYMBOL_GPL(ksz_port_mirror_del);
 
-int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu)
+static int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -1017,9 +997,8 @@ int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu)
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_change_mtu);
 
-int ksz_max_mtu(struct dsa_switch *ds, int port)
+static int ksz_max_mtu(struct dsa_switch *ds, int port)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = -EOPNOTSUPP;
@@ -1029,7 +1008,6 @@ int ksz_max_mtu(struct dsa_switch *ds, int port)
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(ksz_max_mtu);
 
 static int ksz_switch_detect(struct ksz_device *dev)
 {
@@ -1097,6 +1075,37 @@ static int ksz_switch_detect(struct ksz_device *dev)
 	return 0;
 }
 
+static const struct dsa_switch_ops ksz_switch_ops = {
+	.get_tag_protocol	= ksz_get_tag_protocol,
+	.get_phy_flags		= ksz_get_phy_flags,
+	.setup			= ksz_setup,
+	.phy_read		= ksz_phy_read16,
+	.phy_write		= ksz_phy_write16,
+	.phylink_get_caps	= ksz_phylink_get_caps,
+	.phylink_mac_link_down	= ksz_mac_link_down,
+	.port_enable		= ksz_enable_port,
+	.get_strings		= ksz_get_strings,
+	.get_ethtool_stats	= ksz_get_ethtool_stats,
+	.get_sset_count		= ksz_sset_count,
+	.port_bridge_join	= ksz_port_bridge_join,
+	.port_bridge_leave	= ksz_port_bridge_leave,
+	.port_stp_state_set	= ksz_port_stp_state_set,
+	.port_fast_age		= ksz_port_fast_age,
+	.port_vlan_filtering	= ksz_port_vlan_filtering,
+	.port_vlan_add		= ksz_port_vlan_add,
+	.port_vlan_del		= ksz_port_vlan_del,
+	.port_fdb_dump		= ksz_port_fdb_dump,
+	.port_fdb_add		= ksz_port_fdb_add,
+	.port_fdb_del		= ksz_port_fdb_del,
+	.port_mdb_add           = ksz_port_mdb_add,
+	.port_mdb_del           = ksz_port_mdb_del,
+	.port_mirror_add	= ksz_port_mirror_add,
+	.port_mirror_del	= ksz_port_mirror_del,
+	.get_stats64		= ksz_get_stats64,
+	.port_change_mtu	= ksz_change_mtu,
+	.port_max_mtu		= ksz_max_mtu,
+};
+
 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
 {
 	struct dsa_switch *ds;
@@ -1108,6 +1117,7 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
 
 	ds->dev = base;
 	ds->num_ports = DSA_MAX_PORTS;
+	ds->ops = &ksz_switch_ops;
 
 	swdev = devm_kzalloc(base, sizeof(*swdev), GFP_KERNEL);
 	if (!swdev)
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index f7275c4f633a..872d378ac45c 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -227,60 +227,8 @@ int ksz9477_switch_register(struct ksz_device *dev);
 
 void ksz_init_mib_timer(struct ksz_device *dev);
 void ksz_r_mib_stats64(struct ksz_device *dev, int port);
-void ksz_get_stats64(struct dsa_switch *ds, int port,
-		     struct rtnl_link_stats64 *s);
-void ksz_phylink_get_caps(struct dsa_switch *ds, int port,
-			  struct phylink_config *config);
-extern const struct ksz_chip_data ksz_switch_chips[];
-
-/* Common DSA access functions */
-
-int ksz_setup(struct dsa_switch *ds);
-int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg);
-int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val);
-u32 ksz_get_phy_flags(struct dsa_switch *ds, int port);
-void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
-		       phy_interface_t interface);
-int ksz_sset_count(struct dsa_switch *ds, int port, int sset);
-void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf);
-int ksz_port_bridge_join(struct dsa_switch *ds, int port,
-			 struct dsa_bridge bridge, bool *tx_fwd_offload,
-			 struct netlink_ext_ack *extack);
-void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
-			   struct dsa_bridge bridge);
 void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
-void ksz_port_fast_age(struct dsa_switch *ds, int port);
-int ksz_port_fdb_add(struct dsa_switch *ds, int port,
-		     const unsigned char *addr, u16 vid, struct dsa_db db);
-int ksz_port_fdb_del(struct dsa_switch *ds, int port,
-		     const unsigned char *addr, u16 vid, struct dsa_db db);
-int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
-		      void *data);
-int ksz_port_mdb_add(struct dsa_switch *ds, int port,
-		     const struct switchdev_obj_port_mdb *mdb,
-		     struct dsa_db db);
-int ksz_port_mdb_del(struct dsa_switch *ds, int port,
-		     const struct switchdev_obj_port_mdb *mdb,
-		     struct dsa_db db);
-int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
-void ksz_get_strings(struct dsa_switch *ds, int port,
-		     u32 stringset, uint8_t *buf);
-enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
-					   int port, enum dsa_tag_protocol mp);
-int ksz_port_vlan_filtering(struct dsa_switch *ds, int port,
-			    bool flag, struct netlink_ext_ack *extack);
-int ksz_port_vlan_add(struct dsa_switch *ds, int port,
-		      const struct switchdev_obj_port_vlan *vlan,
-		      struct netlink_ext_ack *extack);
-int ksz_port_vlan_del(struct dsa_switch *ds, int port,
-		      const struct switchdev_obj_port_vlan *vlan);
-int ksz_port_mirror_add(struct dsa_switch *ds, int port,
-			struct dsa_mall_mirror_tc_entry *mirror,
-			bool ingress, struct netlink_ext_ack *extack);
-void ksz_port_mirror_del(struct dsa_switch *ds, int port,
-			 struct dsa_mall_mirror_tc_entry *mirror);
-int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu);
-int ksz_max_mtu(struct dsa_switch *ds, int port);
+extern const struct ksz_chip_data ksz_switch_chips[];
 
 /* Common register access functions */
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (10 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 11/15] net: dsa: microchip: common dsa_switch_ops for ksz switches Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-06-14  8:24   ` Vladimir Oltean
  2022-05-30 10:42 ` [RFC Patch net-next v2 13/15] net: dsa: microchip: common menuconfig for ksz series switch Arun Ramadoss
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

As per 'commit 3506b2f42dff ("net: dsa: microchip: call
phy_remove_link_mode during probe")' phy_remove_link_mode is added in
the switch_register function after dsa_switch_register. In order to have
the common switch register function, moving this phy init after
dsa_register_switch using the new ksz_dev_ops.dsa_init hook.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz9477.c    | 49 ++++++++++++++------------
 drivers/net/dsa/microchip/ksz_common.c |  5 ++-
 drivers/net/dsa/microchip/ksz_common.h |  1 +
 3 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index ecce99b77ef6..c87ce0e2afd8 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -1349,6 +1349,30 @@ static void ksz9477_switch_exit(struct ksz_device *dev)
 	ksz9477_reset_switch(dev);
 }
 
+static int ksz9477_dsa_init(struct ksz_device *dev)
+{
+	struct phy_device *phydev;
+	int i;
+
+	for (i = 0; i < dev->phy_port_cnt; ++i) {
+		if (!dsa_is_user_port(dev->ds, i))
+			continue;
+
+		phydev = dsa_to_port(dev->ds, i)->slave->phydev;
+
+		/* The MAC actually cannot run in 1000 half-duplex mode. */
+		phy_remove_link_mode(phydev,
+				     ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
+
+		/* PHY does not support gigabit. */
+		if (!(dev->features & GBIT_SUPPORT))
+			phy_remove_link_mode(phydev,
+					     ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
+	}
+
+	return 0;
+}
+
 static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.setup = ksz9477_setup,
 	.get_port_addr = ksz9477_get_port_addr,
@@ -1377,35 +1401,14 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.change_mtu = ksz9477_change_mtu,
 	.max_mtu = ksz9477_max_mtu,
 	.shutdown = ksz9477_reset_switch,
+	.dsa_init = ksz9477_dsa_init,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
 };
 
 int ksz9477_switch_register(struct ksz_device *dev)
 {
-	int ret, i;
-	struct phy_device *phydev;
-
-	ret = ksz_switch_register(dev, &ksz9477_dev_ops);
-	if (ret)
-		return ret;
-
-	for (i = 0; i < dev->phy_port_cnt; ++i) {
-		if (!dsa_is_user_port(dev->ds, i))
-			continue;
-
-		phydev = dsa_to_port(dev->ds, i)->slave->phydev;
-
-		/* The MAC actually cannot run in 1000 half-duplex mode. */
-		phy_remove_link_mode(phydev,
-				     ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
-
-		/* PHY does not support gigabit. */
-		if (!(dev->features & GBIT_SUPPORT))
-			phy_remove_link_mode(phydev,
-					     ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
-	}
-	return ret;
+	return ksz_switch_register(dev, &ksz9477_dev_ops);
 }
 EXPORT_SYMBOL(ksz9477_switch_register);
 
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index ace5cf0ad5a8..f40d64858d35 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -1253,7 +1253,10 @@ int ksz_switch_register(struct ksz_device *dev,
 	/* Start the MIB timer. */
 	schedule_delayed_work(&dev->mib_read, 0);
 
-	return 0;
+	if (dev->dev_ops->dsa_init)
+		ret = dev->dev_ops->dsa_init(dev);
+
+	return ret;
 }
 EXPORT_SYMBOL(ksz_switch_register);
 
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 872d378ac45c..23962f47df46 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -213,6 +213,7 @@ struct ksz_dev_ops {
 	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
 	void (*port_init_cnt)(struct ksz_device *dev, int port);
 	int (*shutdown)(struct ksz_device *dev);
+	int (*dsa_init)(struct ksz_device *dev);
 	int (*init)(struct ksz_device *dev);
 	void (*exit)(struct ksz_device *dev);
 };
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 13/15] net: dsa: microchip: common menuconfig for ksz series switch
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (11 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-05-30 10:42 ` [RFC Patch net-next v2 14/15] net: dsa: microchip: move ksz_dev_ops to ksz_common.c Arun Ramadoss
  2022-05-30 10:42 ` [RFC Patch net-next v2 15/15] net: dsa: microchip: common ksz_spi_probe for ksz switches Arun Ramadoss
  14 siblings, 0 replies; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch replaces the two different menuconfig for ksz9477 and ksz8795
to single ksz_common. so that it can be extended for the other switch
like lan937x. And removes the export_symbols for the extern functions in
the ksz_common.h.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/Kconfig      | 28 +++++++++-----------------
 drivers/net/dsa/microchip/Makefile     |  7 ++++---
 drivers/net/dsa/microchip/ksz_common.c |  3 ---
 3 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/drivers/net/dsa/microchip/Kconfig b/drivers/net/dsa/microchip/Kconfig
index c9e2a8989556..d21ff069e5aa 100644
--- a/drivers/net/dsa/microchip/Kconfig
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -1,39 +1,29 @@
 # SPDX-License-Identifier: GPL-2.0-only
-config NET_DSA_MICROCHIP_KSZ_COMMON
-	select NET_DSA_TAG_KSZ
-	tristate
-
-menuconfig NET_DSA_MICROCHIP_KSZ9477
-	tristate "Microchip KSZ9477 series switch support"
+menuconfig NET_DSA_MICROCHIP_KSZ_COMMON
+	tristate "Microchip KSZ8795/KSZ9477 series switch support"
 	depends on NET_DSA
-	select NET_DSA_MICROCHIP_KSZ_COMMON
+	select NET_DSA_TAG_KSZ
 	help
-	  This driver adds support for Microchip KSZ9477 switch chips.
+	  This driver adds support for Microchip KSZ9477 series switch and
+	  KSZ8795/KSZ88x3 switch chips.
 
 config NET_DSA_MICROCHIP_KSZ9477_I2C
 	tristate "KSZ9477 series I2C connected switch driver"
-	depends on NET_DSA_MICROCHIP_KSZ9477 && I2C
+	depends on NET_DSA_MICROCHIP_KSZ_COMMON && I2C
 	select REGMAP_I2C
 	help
 	  Select to enable support for registering switches configured through I2C.
 
 config NET_DSA_MICROCHIP_KSZ9477_SPI
 	tristate "KSZ9477 series SPI connected switch driver"
-	depends on NET_DSA_MICROCHIP_KSZ9477 && SPI
+	depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI
 	select REGMAP_SPI
 	help
 	  Select to enable support for registering switches configured through SPI.
 
-menuconfig NET_DSA_MICROCHIP_KSZ8795
-	tristate "Microchip KSZ8795 series switch support"
-	depends on NET_DSA
-	select NET_DSA_MICROCHIP_KSZ_COMMON
-	help
-	  This driver adds support for Microchip KSZ8795/KSZ88X3 switch chips.
-
 config NET_DSA_MICROCHIP_KSZ8795_SPI
 	tristate "KSZ8795 series SPI connected switch driver"
-	depends on NET_DSA_MICROCHIP_KSZ8795 && SPI
+	depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI
 	select REGMAP_SPI
 	help
 	  This driver accesses KSZ8795 chip through SPI.
@@ -43,7 +33,7 @@ config NET_DSA_MICROCHIP_KSZ8795_SPI
 
 config NET_DSA_MICROCHIP_KSZ8863_SMI
 	tristate "KSZ series SMI connected switch driver"
-	depends on NET_DSA_MICROCHIP_KSZ8795
+	depends on NET_DSA_MICROCHIP_KSZ_COMMON
 	select MDIO_BITBANG
 	help
 	  Select to enable support for registering switches configured through
diff --git a/drivers/net/dsa/microchip/Makefile b/drivers/net/dsa/microchip/Makefile
index 2a03b21a3386..4cf4755e6426 100644
--- a/drivers/net/dsa/microchip/Makefile
+++ b/drivers/net/dsa/microchip/Makefile
@@ -1,8 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON)	+= ksz_common.o
-obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477)		+= ksz9477.o
+obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON)	+= ksz_switch.o
+ksz_switch-objs := ksz_common.o
+ksz_switch-objs += ksz9477.o
+ksz_switch-objs += ksz8795.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C)	+= ksz9477_i2c.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI)	+= ksz9477_spi.o
-obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795)		+= ksz8795.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795_SPI)	+= ksz8795_spi.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI)	+= ksz8863_smi.o
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index f40d64858d35..8f852649c217 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -503,7 +503,6 @@ void ksz_r_mib_stats64(struct ksz_device *dev, int port)
 
 	spin_unlock(&mib->stats64_lock);
 }
-EXPORT_SYMBOL_GPL(ksz_r_mib_stats64);
 
 static void ksz_get_stats64(struct dsa_switch *ds, int port,
 			    struct rtnl_link_stats64 *s)
@@ -674,7 +673,6 @@ void ksz_init_mib_timer(struct ksz_device *dev)
 		memset(mib->counters, 0, dev->info->mib_cnt * sizeof(u64));
 	}
 }
-EXPORT_SYMBOL_GPL(ksz_init_mib_timer);
 
 static int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg)
 {
@@ -901,7 +899,6 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
 
 	ksz_update_port_member(dev, port);
 }
-EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
 
 static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
 						  int port,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 14/15] net: dsa: microchip: move ksz_dev_ops to ksz_common.c
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (12 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 13/15] net: dsa: microchip: common menuconfig for ksz series switch Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  2022-05-30 10:42 ` [RFC Patch net-next v2 15/15] net: dsa: microchip: common ksz_spi_probe for ksz switches Arun Ramadoss
  14 siblings, 0 replies; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

This patch move the ksz_dev_ops from individual files to ksz_common.c.
And the dev_ops is assigned to ksz_device based on the switch detect.
This reduces the redundant function and allows to reuse the
functionality for LAN937x which has similar register set.
And deletes the ksz8_switch_register and ksz9477_switch_register since
both are calling the ksz_switch_register function. Instead the
ksz_switch_register is called from the probe function.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/ksz8.h        |  46 ++++++++
 drivers/net/dsa/microchip/ksz8795.c     | 123 ++++++++--------------
 drivers/net/dsa/microchip/ksz8795_spi.c |   2 +-
 drivers/net/dsa/microchip/ksz8863_smi.c |   2 +-
 drivers/net/dsa/microchip/ksz9477.c     | 133 ++++++++----------------
 drivers/net/dsa/microchip/ksz9477.h     |  58 +++++++++++
 drivers/net/dsa/microchip/ksz9477_i2c.c |   2 +-
 drivers/net/dsa/microchip/ksz9477_spi.c |   2 +-
 drivers/net/dsa/microchip/ksz_common.c  |  78 +++++++++++++-
 drivers/net/dsa/microchip/ksz_common.h  |   7 +-
 10 files changed, 271 insertions(+), 182 deletions(-)
 create mode 100644 drivers/net/dsa/microchip/ksz9477.h

diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h
index 03da369675c6..90d5c7ea7850 100644
--- a/drivers/net/dsa/microchip/ksz8.h
+++ b/drivers/net/dsa/microchip/ksz8.h
@@ -8,6 +8,8 @@
 #ifndef __KSZ8XXX_H
 #define __KSZ8XXX_H
 #include <linux/kernel.h>
+#include <net/dsa.h>
+#include "ksz_common.h"
 
 enum ksz_regs {
 	REG_IND_CTRL_0,
@@ -67,4 +69,48 @@ struct ksz8 {
 	void *priv;
 };
 
+int ksz8_setup(struct dsa_switch *ds);
+u32 ksz8_get_port_addr(int port, int offset);
+void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member);
+void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port);
+void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port);
+void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
+void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
+int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
+			 u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries);
+int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
+			 struct alu_struct *alu);
+void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
+			  struct alu_struct *alu);
+void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt);
+void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
+		    u64 *dropped, u64 *cnt);
+void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze);
+void ksz8_port_init_cnt(struct ksz_device *dev, int port);
+int ksz8_fdb_dump(struct ksz_device *dev, int port,
+		  dsa_fdb_dump_cb_t *cb, void *data);
+int ksz8_mdb_add(struct ksz_device *dev, int port,
+		 const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
+int ksz8_mdb_del(struct ksz_device *dev, int port,
+		 const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
+int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,
+			     struct netlink_ext_ack *extack);
+int ksz8_port_vlan_add(struct ksz_device *dev, int port,
+		       const struct switchdev_obj_port_vlan *vlan,
+		       struct netlink_ext_ack *extack);
+int ksz8_port_vlan_del(struct ksz_device *dev, int port,
+		       const struct switchdev_obj_port_vlan *vlan);
+int ksz8_port_mirror_add(struct ksz_device *dev, int port,
+			 struct dsa_mall_mirror_tc_entry *mirror,
+			 bool ingress, struct netlink_ext_ack *extack);
+void ksz8_port_mirror_del(struct ksz_device *dev, int port,
+			  struct dsa_mall_mirror_tc_entry *mirror);
+int ksz8_get_stp_reg(void);
+void ksz8_get_caps(struct ksz_device *dev, int port,
+		   struct phylink_config *config);
+int ksz8_reset_switch(struct ksz_device *dev);
+int ksz8_switch_detect(struct ksz_device *dev);
+int ksz8_switch_init(struct ksz_device *dev);
+void ksz8_switch_exit(struct ksz_device *dev);
+
 #endif
diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index ff4b33a3b1b4..3c9d32caa9ad 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -162,7 +162,7 @@ static int ksz8_ind_write8(struct ksz_device *dev, u8 table, u16 addr, u8 data)
 	return ret;
 }
 
-static int ksz8_reset_switch(struct ksz_device *dev)
+int ksz8_reset_switch(struct ksz_device *dev)
 {
 	if (ksz_is_ksz88x3(dev)) {
 		/* reset switch */
@@ -213,7 +213,7 @@ static void ksz8795_set_prio_queue(struct ksz_device *dev, int port, int queue)
 			true);
 }
 
-static void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt)
+void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt)
 {
 	struct ksz8 *ksz8 = dev->priv;
 	const u32 *masks;
@@ -334,8 +334,8 @@ static void ksz8863_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
 	}
 }
 
-static void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
-			   u64 *dropped, u64 *cnt)
+void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
+		    u64 *dropped, u64 *cnt)
 {
 	if (ksz_is_ksz88x3(dev))
 		ksz8863_r_mib_pkt(dev, port, addr, dropped, cnt);
@@ -343,7 +343,7 @@ static void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
 		ksz8795_r_mib_pkt(dev, port, addr, dropped, cnt);
 }
 
-static void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze)
+void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze)
 {
 	if (ksz_is_ksz88x3(dev))
 		return;
@@ -358,7 +358,7 @@ static void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze)
 		ksz_cfg(dev, REG_SW_CTRL_6, BIT(port), false);
 }
 
-static void ksz8_port_init_cnt(struct ksz_device *dev, int port)
+void ksz8_port_init_cnt(struct ksz_device *dev, int port)
 {
 	struct ksz_port_mib *mib = &dev->ports[port].mib;
 	u64 *dropped;
@@ -447,9 +447,8 @@ static int ksz8_valid_dyn_entry(struct ksz_device *dev, u8 *data)
 	return 0;
 }
 
-static int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr,
-				u8 *mac_addr, u8 *fid, u8 *src_port,
-				u8 *timestamp, u16 *entries)
+int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
+			 u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries)
 {
 	struct ksz8 *ksz8 = dev->priv;
 	u32 data_hi, data_lo;
@@ -512,8 +511,8 @@ static int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr,
 	return rc;
 }
 
-static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
-				struct alu_struct *alu)
+int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
+			 struct alu_struct *alu)
 {
 	struct ksz8 *ksz8 = dev->priv;
 	u32 data_hi, data_lo;
@@ -551,8 +550,8 @@ static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
 	return -ENXIO;
 }
 
-static void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
-				 struct alu_struct *alu)
+void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
+			  struct alu_struct *alu)
 {
 	struct ksz8 *ksz8 = dev->priv;
 	u32 data_hi, data_lo;
@@ -663,7 +662,7 @@ static void ksz8_w_vlan_table(struct ksz_device *dev, u16 vid, u16 vlan)
 	ksz8_w_table(dev, TABLE_VLAN, addr, buf);
 }
 
-static void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
+void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 {
 	struct ksz8 *ksz8 = dev->priv;
 	u8 restart, speed, ctrl, link;
@@ -786,7 +785,7 @@ static void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 		*val = data;
 }
 
-static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
+void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 {
 	struct ksz8 *ksz8 = dev->priv;
 	u8 restart, speed, ctrl, data;
@@ -898,7 +897,7 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 	}
 }
 
-static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
+void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
 {
 	u8 data;
 
@@ -908,12 +907,12 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
 	ksz_pwrite8(dev, port, P_MIRROR_CTRL, data);
 }
 
-static int ksz8_get_stp_reg(void)
+int ksz8_get_stp_reg(void)
 {
 	return P_STP_CTRL;
 }
 
-static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
+void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
 {
 	u8 learn[DSA_MAX_PORTS];
 	int first, index, cnt;
@@ -946,8 +945,8 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
 	}
 }
 
-static int ksz8_fdb_dump(struct ksz_device *dev, int port,
-			 dsa_fdb_dump_cb_t *cb, void *data)
+int ksz8_fdb_dump(struct ksz_device *dev, int port,
+		  dsa_fdb_dump_cb_t *cb, void *data)
 {
 	int ret = 0;
 	u16 i = 0;
@@ -975,9 +974,8 @@ static int ksz8_fdb_dump(struct ksz_device *dev, int port,
 	return ret;
 }
 
-static int ksz8_mdb_add(struct ksz_device *dev, int port,
-			const struct switchdev_obj_port_mdb *mdb,
-			struct dsa_db db)
+int ksz8_mdb_add(struct ksz_device *dev, int port,
+		 const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
 {
 	struct alu_struct alu;
 	int index;
@@ -1019,9 +1017,8 @@ static int ksz8_mdb_add(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz8_mdb_del(struct ksz_device *dev, int port,
-			const struct switchdev_obj_port_mdb *mdb,
-			struct dsa_db db)
+int ksz8_mdb_del(struct ksz_device *dev, int port,
+		 const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
 {
 	struct alu_struct alu;
 	int index;
@@ -1049,8 +1046,8 @@ static int ksz8_mdb_del(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,
-				    struct netlink_ext_ack *extack)
+int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,
+			     struct netlink_ext_ack *extack)
 {
 	if (ksz_is_ksz88x3(dev))
 		return -ENOTSUPP;
@@ -1076,9 +1073,9 @@ static void ksz8_port_enable_pvid(struct ksz_device *dev, int port, bool state)
 	}
 }
 
-static int ksz8_port_vlan_add(struct ksz_device *dev, int port,
-			      const struct switchdev_obj_port_vlan *vlan,
-			      struct netlink_ext_ack *extack)
+int ksz8_port_vlan_add(struct ksz_device *dev, int port,
+		       const struct switchdev_obj_port_vlan *vlan,
+		       struct netlink_ext_ack *extack)
 {
 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
 	struct ksz_port *p = &dev->ports[port];
@@ -1148,8 +1145,8 @@ static int ksz8_port_vlan_add(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz8_port_vlan_del(struct ksz_device *dev, int port,
-			      const struct switchdev_obj_port_vlan *vlan)
+int ksz8_port_vlan_del(struct ksz_device *dev, int port,
+		       const struct switchdev_obj_port_vlan *vlan)
 {
 	u16 data, pvid;
 	u8 fid, member, valid;
@@ -1180,9 +1177,9 @@ static int ksz8_port_vlan_del(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz8_port_mirror_add(struct ksz_device *dev, int port,
-				struct dsa_mall_mirror_tc_entry *mirror,
-				bool ingress, struct netlink_ext_ack *extack)
+int ksz8_port_mirror_add(struct ksz_device *dev, int port,
+			 struct dsa_mall_mirror_tc_entry *mirror,
+			 bool ingress, struct netlink_ext_ack *extack)
 {
 	if (ingress) {
 		ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX, true);
@@ -1202,8 +1199,8 @@ static int ksz8_port_mirror_add(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static void ksz8_port_mirror_del(struct ksz_device *dev, int port,
-				 struct dsa_mall_mirror_tc_entry *mirror)
+void ksz8_port_mirror_del(struct ksz_device *dev, int port,
+			  struct dsa_mall_mirror_tc_entry *mirror)
 {
 	u8 data;
 
@@ -1270,7 +1267,7 @@ static void ksz8795_cpu_interface_select(struct ksz_device *dev, int port)
 	p->phydev.duplex = 1;
 }
 
-static void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
+void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 {
 	struct dsa_switch *ds = dev->ds;
 	struct ksz8 *ksz8 = dev->priv;
@@ -1374,7 +1371,7 @@ static int ksz8_handle_global_errata(struct dsa_switch *ds)
 	return ret;
 }
 
-static int ksz8_setup(struct dsa_switch *ds)
+int ksz8_setup(struct dsa_switch *ds)
 {
 	struct ksz_device *dev = ds->priv;
 	struct alu_struct alu;
@@ -1444,8 +1441,8 @@ static int ksz8_setup(struct dsa_switch *ds)
 	return ksz8_handle_global_errata(ds);
 }
 
-static void ksz8_get_caps(struct ksz_device *dev, int port,
-			  struct phylink_config *config)
+void ksz8_get_caps(struct ksz_device *dev, int port,
+		   struct phylink_config *config)
 {
 	config->mac_capabilities = MAC_10 | MAC_100;
 
@@ -1462,12 +1459,12 @@ static void ksz8_get_caps(struct ksz_device *dev, int port,
 		config->mac_capabilities |= MAC_ASYM_PAUSE;
 }
 
-static u32 ksz8_get_port_addr(int port, int offset)
+u32 ksz8_get_port_addr(int port, int offset)
 {
 	return PORT_CTRL_ADDR(port, offset);
 }
 
-static int ksz8_switch_init(struct ksz_device *dev)
+int ksz8_switch_init(struct ksz_device *dev)
 {
 	struct ksz8 *ksz8 = dev->priv;
 
@@ -1498,47 +1495,11 @@ static int ksz8_switch_init(struct ksz_device *dev)
 	return 0;
 }
 
-static void ksz8_switch_exit(struct ksz_device *dev)
+void ksz8_switch_exit(struct ksz_device *dev)
 {
 	ksz8_reset_switch(dev);
 }
 
-static const struct ksz_dev_ops ksz8_dev_ops = {
-	.setup = ksz8_setup,
-	.get_port_addr = ksz8_get_port_addr,
-	.cfg_port_member = ksz8_cfg_port_member,
-	.flush_dyn_mac_table = ksz8_flush_dyn_mac_table,
-	.port_setup = ksz8_port_setup,
-	.r_phy = ksz8_r_phy,
-	.w_phy = ksz8_w_phy,
-	.r_dyn_mac_table = ksz8_r_dyn_mac_table,
-	.r_sta_mac_table = ksz8_r_sta_mac_table,
-	.w_sta_mac_table = ksz8_w_sta_mac_table,
-	.r_mib_cnt = ksz8_r_mib_cnt,
-	.r_mib_pkt = ksz8_r_mib_pkt,
-	.freeze_mib = ksz8_freeze_mib,
-	.port_init_cnt = ksz8_port_init_cnt,
-	.fdb_dump = ksz8_fdb_dump,
-	.mdb_add = ksz8_mdb_add,
-	.mdb_del = ksz8_mdb_del,
-	.vlan_filtering = ksz8_port_vlan_filtering,
-	.vlan_add = ksz8_port_vlan_add,
-	.vlan_del = ksz8_port_vlan_del,
-	.mirror_add = ksz8_port_mirror_add,
-	.mirror_del = ksz8_port_mirror_del,
-	.get_stp_reg = ksz8_get_stp_reg,
-	.get_caps = ksz8_get_caps,
-	.shutdown = ksz8_reset_switch,
-	.init = ksz8_switch_init,
-	.exit = ksz8_switch_exit,
-};
-
-int ksz8_switch_register(struct ksz_device *dev)
-{
-	return ksz_switch_register(dev, &ksz8_dev_ops);
-}
-EXPORT_SYMBOL(ksz8_switch_register);
-
 MODULE_AUTHOR("Tristram Ha <Tristram.Ha@microchip.com>");
 MODULE_DESCRIPTION("Microchip KSZ8795 Series Switch DSA Driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/dsa/microchip/ksz8795_spi.c b/drivers/net/dsa/microchip/ksz8795_spi.c
index 961a74c359a8..3a816661989c 100644
--- a/drivers/net/dsa/microchip/ksz8795_spi.c
+++ b/drivers/net/dsa/microchip/ksz8795_spi.c
@@ -82,7 +82,7 @@ static int ksz8795_spi_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = ksz8_switch_register(dev);
+	ret = ksz_switch_register(dev);
 
 	/* Main DSA driver may not be started yet. */
 	if (ret)
diff --git a/drivers/net/dsa/microchip/ksz8863_smi.c b/drivers/net/dsa/microchip/ksz8863_smi.c
index b6f99e641dca..d71df05b8b7b 100644
--- a/drivers/net/dsa/microchip/ksz8863_smi.c
+++ b/drivers/net/dsa/microchip/ksz8863_smi.c
@@ -174,7 +174,7 @@ static int ksz8863_smi_probe(struct mdio_device *mdiodev)
 	if (mdiodev->dev.platform_data)
 		dev->pdata = mdiodev->dev.platform_data;
 
-	ret = ksz8_switch_register(dev);
+	ret = ksz_switch_register(dev);
 
 	/* Main DSA driver may not be started yet. */
 	if (ret)
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index c87ce0e2afd8..430dcbf48a46 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -17,6 +17,7 @@
 
 #include "ksz9477_reg.h"
 #include "ksz_common.h"
+#include "ksz9477.h"
 
 /* Used with variable features to indicate capabilities. */
 #define GBIT_SUPPORT			BIT(0)
@@ -47,7 +48,7 @@ static void ksz9477_port_cfg32(struct ksz_device *dev, int port, int offset,
 			   bits, set ? bits : 0);
 }
 
-static int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu)
+int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu)
 {
 	u16 frame_size, max_frame = 0;
 	int i;
@@ -64,7 +65,7 @@ static int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu)
 				  REG_SW_MTU_MASK, max_frame);
 }
 
-static int ksz9477_max_mtu(struct ksz_device *dev, int port)
+int ksz9477_max_mtu(struct ksz_device *dev, int port)
 {
 	return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
 }
@@ -174,7 +175,7 @@ static int ksz9477_wait_alu_sta_ready(struct ksz_device *dev)
 					10, 1000);
 }
 
-static int ksz9477_reset_switch(struct ksz_device *dev)
+int ksz9477_reset_switch(struct ksz_device *dev)
 {
 	u8 data8;
 	u32 data32;
@@ -213,8 +214,7 @@ static int ksz9477_reset_switch(struct ksz_device *dev)
 	return 0;
 }
 
-static void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr,
-			      u64 *cnt)
+void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt)
 {
 	struct ksz_port *p = &dev->ports[port];
 	unsigned int val;
@@ -241,14 +241,14 @@ static void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr,
 	*cnt += data;
 }
 
-static void ksz9477_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
-			      u64 *dropped, u64 *cnt)
+void ksz9477_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
+		       u64 *dropped, u64 *cnt)
 {
 	addr = dev->info->mib_names[addr].index;
 	ksz9477_r_mib_cnt(dev, port, addr, cnt);
 }
 
-static void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze)
+void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze)
 {
 	u32 val = freeze ? MIB_COUNTER_FLUSH_FREEZE : 0;
 	struct ksz_port *p = &dev->ports[port];
@@ -262,7 +262,7 @@ static void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze)
 	mutex_unlock(&p->mib.cnt_mutex);
 }
 
-static void ksz9477_port_init_cnt(struct ksz_device *dev, int port)
+void ksz9477_port_init_cnt(struct ksz_device *dev, int port)
 {
 	struct ksz_port_mib *mib = &dev->ports[port].mib;
 
@@ -275,7 +275,7 @@ static void ksz9477_port_init_cnt(struct ksz_device *dev, int port)
 	mutex_unlock(&mib->cnt_mutex);
 }
 
-static void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
+void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 {
 	u16 val = 0xffff;
 
@@ -324,7 +324,7 @@ static void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 	*data = val;
 }
 
-static void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
+void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
 {
 	/* No real PHY after this. */
 	if (addr >= dev->phy_port_cnt)
@@ -337,18 +337,17 @@ static void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
 	ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
 }
 
-static void ksz9477_cfg_port_member(struct ksz_device *dev, int port,
-				    u8 member)
+void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member)
 {
 	ksz_pwrite32(dev, port, REG_PORT_VLAN_MEMBERSHIP__4, member);
 }
 
-static int ksz9477_get_stp_reg(void)
+int ksz9477_get_stp_reg(void)
 {
 	return P_STP_CTRL;
 }
 
-static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port)
+void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port)
 {
 	u8 data;
 
@@ -370,9 +369,8 @@ static void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port)
 	}
 }
 
-static int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port,
-				       bool flag,
-				       struct netlink_ext_ack *extack)
+int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port,
+				bool flag, struct netlink_ext_ack *extack)
 {
 	if (flag) {
 		ksz_port_cfg(dev, port, REG_PORT_LUE_CTRL,
@@ -387,9 +385,9 @@ static int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz9477_port_vlan_add(struct ksz_device *dev, int port,
-				 const struct switchdev_obj_port_vlan *vlan,
-				 struct netlink_ext_ack *extack)
+int ksz9477_port_vlan_add(struct ksz_device *dev, int port,
+			  const struct switchdev_obj_port_vlan *vlan,
+			  struct netlink_ext_ack *extack)
 {
 	u32 vlan_table[3];
 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
@@ -423,8 +421,8 @@ static int ksz9477_port_vlan_add(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz9477_port_vlan_del(struct ksz_device *dev, int port,
-				 const struct switchdev_obj_port_vlan *vlan)
+int ksz9477_port_vlan_del(struct ksz_device *dev, int port,
+			  const struct switchdev_obj_port_vlan *vlan)
 {
 	bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
 	u32 vlan_table[3];
@@ -456,9 +454,8 @@ static int ksz9477_port_vlan_del(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static int ksz9477_fdb_add(struct ksz_device *dev, int port,
-			   const unsigned char *addr, u16 vid,
-			   struct dsa_db db)
+int ksz9477_fdb_add(struct ksz_device *dev, int port,
+		    const unsigned char *addr, u16 vid, struct dsa_db db)
 {
 	u32 alu_table[4];
 	u32 data;
@@ -513,9 +510,8 @@ static int ksz9477_fdb_add(struct ksz_device *dev, int port,
 	return ret;
 }
 
-static int ksz9477_fdb_del(struct ksz_device *dev, int port,
-			   const unsigned char *addr, u16 vid,
-			   struct dsa_db db)
+int ksz9477_fdb_del(struct ksz_device *dev, int port,
+		    const unsigned char *addr, u16 vid, struct dsa_db db)
 {
 	u32 alu_table[4];
 	u32 data;
@@ -603,8 +599,8 @@ static void ksz9477_convert_alu(struct alu_struct *alu, u32 *alu_table)
 	alu->mac[5] = alu_table[3] & 0xFF;
 }
 
-static int ksz9477_fdb_dump(struct ksz_device *dev, int port,
-			    dsa_fdb_dump_cb_t *cb, void *data)
+int ksz9477_fdb_dump(struct ksz_device *dev, int port,
+		     dsa_fdb_dump_cb_t *cb, void *data)
 {
 	int ret = 0;
 	u32 ksz_data;
@@ -654,9 +650,8 @@ static int ksz9477_fdb_dump(struct ksz_device *dev, int port,
 	return ret;
 }
 
-static int ksz9477_mdb_add(struct ksz_device *dev, int port,
-			   const struct switchdev_obj_port_mdb *mdb,
-			   struct dsa_db db)
+int ksz9477_mdb_add(struct ksz_device *dev, int port,
+		    const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
 {
 	u32 static_table[4];
 	u32 data;
@@ -729,9 +724,8 @@ static int ksz9477_mdb_add(struct ksz_device *dev, int port,
 	return err;
 }
 
-static int ksz9477_mdb_del(struct ksz_device *dev, int port,
-			   const struct switchdev_obj_port_mdb *mdb,
-			   struct dsa_db db)
+int ksz9477_mdb_del(struct ksz_device *dev, int port,
+		    const struct switchdev_obj_port_mdb *mdb, struct dsa_db db)
 {
 	u32 static_table[4];
 	u32 data;
@@ -804,9 +798,9 @@ static int ksz9477_mdb_del(struct ksz_device *dev, int port,
 	return ret;
 }
 
-static int ksz9477_port_mirror_add(struct ksz_device *dev, int port,
-				   struct dsa_mall_mirror_tc_entry *mirror,
-				   bool ingress, struct netlink_ext_ack *extack)
+int ksz9477_port_mirror_add(struct ksz_device *dev, int port,
+			    struct dsa_mall_mirror_tc_entry *mirror,
+			    bool ingress, struct netlink_ext_ack *extack)
 {
 	u8 data;
 	int p;
@@ -843,8 +837,8 @@ static int ksz9477_port_mirror_add(struct ksz_device *dev, int port,
 	return 0;
 }
 
-static void ksz9477_port_mirror_del(struct ksz_device *dev, int port,
-				    struct dsa_mall_mirror_tc_entry *mirror)
+void ksz9477_port_mirror_del(struct ksz_device *dev, int port,
+			     struct dsa_mall_mirror_tc_entry *mirror)
 {
 	bool in_use = false;
 	u8 data;
@@ -1067,14 +1061,14 @@ static void ksz9477_phy_errata_setup(struct ksz_device *dev, int port)
 	ksz9477_port_mmd_write(dev, port, 0x1c, 0x20, 0xeeee);
 }
 
-static void ksz9477_get_caps(struct ksz_device *dev, int port,
-			     struct phylink_config *config)
+void ksz9477_get_caps(struct ksz_device *dev, int port,
+		      struct phylink_config *config)
 {
 	config->mac_capabilities = MAC_10 | MAC_100 | MAC_1000FD |
 				   MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
 }
 
-static void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)
+void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 {
 	struct ksz_port *p = &dev->ports[port];
 	struct dsa_switch *ds = dev->ds;
@@ -1241,7 +1235,7 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 	}
 }
 
-static int ksz9477_setup(struct dsa_switch *ds)
+int ksz9477_setup(struct dsa_switch *ds)
 {
 	struct ksz_device *dev = ds->priv;
 	int ret = 0;
@@ -1293,12 +1287,12 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	return 0;
 }
 
-static u32 ksz9477_get_port_addr(int port, int offset)
+u32 ksz9477_get_port_addr(int port, int offset)
 {
 	return PORT_CTRL_ADDR(port, offset);
 }
 
-static int ksz9477_switch_init(struct ksz_device *dev)
+int ksz9477_switch_init(struct ksz_device *dev)
 {
 	u8 data8;
 	int ret;
@@ -1344,12 +1338,12 @@ static int ksz9477_switch_init(struct ksz_device *dev)
 	return 0;
 }
 
-static void ksz9477_switch_exit(struct ksz_device *dev)
+void ksz9477_switch_exit(struct ksz_device *dev)
 {
 	ksz9477_reset_switch(dev);
 }
 
-static int ksz9477_dsa_init(struct ksz_device *dev)
+int ksz9477_dsa_init(struct ksz_device *dev)
 {
 	struct phy_device *phydev;
 	int i;
@@ -1373,45 +1367,6 @@ static int ksz9477_dsa_init(struct ksz_device *dev)
 	return 0;
 }
 
-static const struct ksz_dev_ops ksz9477_dev_ops = {
-	.setup = ksz9477_setup,
-	.get_port_addr = ksz9477_get_port_addr,
-	.cfg_port_member = ksz9477_cfg_port_member,
-	.flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
-	.port_setup = ksz9477_port_setup,
-	.r_phy = ksz9477_r_phy,
-	.w_phy = ksz9477_w_phy,
-	.r_mib_cnt = ksz9477_r_mib_cnt,
-	.r_mib_pkt = ksz9477_r_mib_pkt,
-	.r_mib_stat64 = ksz_r_mib_stats64,
-	.freeze_mib = ksz9477_freeze_mib,
-	.port_init_cnt = ksz9477_port_init_cnt,
-	.vlan_filtering = ksz9477_port_vlan_filtering,
-	.vlan_add = ksz9477_port_vlan_add,
-	.vlan_del = ksz9477_port_vlan_del,
-	.mirror_add = ksz9477_port_mirror_add,
-	.mirror_del = ksz9477_port_mirror_del,
-	.get_stp_reg = ksz9477_get_stp_reg,
-	.get_caps = ksz9477_get_caps,
-	.fdb_dump = ksz9477_fdb_dump,
-	.fdb_add = ksz9477_fdb_add,
-	.fdb_del = ksz9477_fdb_del,
-	.mdb_add = ksz9477_mdb_add,
-	.mdb_del = ksz9477_mdb_del,
-	.change_mtu = ksz9477_change_mtu,
-	.max_mtu = ksz9477_max_mtu,
-	.shutdown = ksz9477_reset_switch,
-	.dsa_init = ksz9477_dsa_init,
-	.init = ksz9477_switch_init,
-	.exit = ksz9477_switch_exit,
-};
-
-int ksz9477_switch_register(struct ksz_device *dev)
-{
-	return ksz_switch_register(dev, &ksz9477_dev_ops);
-}
-EXPORT_SYMBOL(ksz9477_switch_register);
-
 MODULE_AUTHOR("Woojung Huh <Woojung.Huh@microchip.com>");
 MODULE_DESCRIPTION("Microchip KSZ9477 Series Switch DSA Driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h
new file mode 100644
index 000000000000..feb5464e8c2b
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz9477.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Microchip KSZ9477 series Header file
+ *
+ * Copyright (C) 2017-2022 Microchip Technology Inc.
+ */
+
+#ifndef __KSZ9477_H
+#define __KSZ9477_H
+
+#include <net/dsa.h>
+#include "ksz_common.h"
+
+int ksz9477_setup(struct dsa_switch *ds);
+u32 ksz9477_get_port_addr(int port, int offset);
+void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member);
+void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port);
+void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port);
+void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data);
+void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val);
+void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt);
+void ksz9477_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
+		       u64 *dropped, u64 *cnt);
+void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze);
+void ksz9477_port_init_cnt(struct ksz_device *dev, int port);
+int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port,
+				bool flag, struct netlink_ext_ack *extack);
+int ksz9477_port_vlan_add(struct ksz_device *dev, int port,
+			  const struct switchdev_obj_port_vlan *vlan,
+			  struct netlink_ext_ack *extack);
+int ksz9477_port_vlan_del(struct ksz_device *dev, int port,
+			  const struct switchdev_obj_port_vlan *vlan);
+int ksz9477_port_mirror_add(struct ksz_device *dev, int port,
+			    struct dsa_mall_mirror_tc_entry *mirror,
+			    bool ingress, struct netlink_ext_ack *extack);
+void ksz9477_port_mirror_del(struct ksz_device *dev, int port,
+			     struct dsa_mall_mirror_tc_entry *mirror);
+int ksz9477_get_stp_reg(void);
+void ksz9477_get_caps(struct ksz_device *dev, int port,
+		      struct phylink_config *config);
+int ksz9477_fdb_dump(struct ksz_device *dev, int port,
+		     dsa_fdb_dump_cb_t *cb, void *data);
+int ksz9477_fdb_add(struct ksz_device *dev, int port,
+		    const unsigned char *addr, u16 vid, struct dsa_db db);
+int ksz9477_fdb_del(struct ksz_device *dev, int port,
+		    const unsigned char *addr, u16 vid, struct dsa_db db);
+int ksz9477_mdb_add(struct ksz_device *dev, int port,
+		    const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
+int ksz9477_mdb_del(struct ksz_device *dev, int port,
+		    const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
+int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu);
+int ksz9477_max_mtu(struct ksz_device *dev, int port);
+int ksz9477_reset_switch(struct ksz_device *dev);
+int ksz9477_dsa_init(struct ksz_device *dev);
+int ksz9477_switch_init(struct ksz_device *dev);
+void ksz9477_switch_exit(struct ksz_device *dev);
+
+#endif
diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c
index faa3163c86b0..984fe5df1643 100644
--- a/drivers/net/dsa/microchip/ksz9477_i2c.c
+++ b/drivers/net/dsa/microchip/ksz9477_i2c.c
@@ -41,7 +41,7 @@ static int ksz9477_i2c_probe(struct i2c_client *i2c,
 	if (i2c->dev.platform_data)
 		dev->pdata = i2c->dev.platform_data;
 
-	ret = ksz9477_switch_register(dev);
+	ret = ksz_switch_register(dev);
 
 	/* Main DSA driver may not be started yet. */
 	if (ret)
diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c
index 1bc8b0cbe458..2ee0601bc014 100644
--- a/drivers/net/dsa/microchip/ksz9477_spi.c
+++ b/drivers/net/dsa/microchip/ksz9477_spi.c
@@ -54,7 +54,7 @@ static int ksz9477_spi_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = ksz9477_switch_register(dev);
+	ret = ksz_switch_register(dev);
 
 	/* Main DSA driver may not be started yet. */
 	if (ret)
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 8f852649c217..44d62ceff427 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -21,6 +21,8 @@
 #include <net/switchdev.h>
 
 #include "ksz_common.h"
+#include "ksz8.h"
+#include "ksz9477.h"
 
 #define MIB_COUNTER_NUM 0x20
 
@@ -139,6 +141,69 @@ static const struct ksz_mib_names ksz9477_mib_names[] = {
 	{ 0x83, "tx_discards" },
 };
 
+static const struct ksz_dev_ops ksz8_dev_ops = {
+	.setup = ksz8_setup,
+	.get_port_addr = ksz8_get_port_addr,
+	.cfg_port_member = ksz8_cfg_port_member,
+	.flush_dyn_mac_table = ksz8_flush_dyn_mac_table,
+	.port_setup = ksz8_port_setup,
+	.r_phy = ksz8_r_phy,
+	.w_phy = ksz8_w_phy,
+	.r_dyn_mac_table = ksz8_r_dyn_mac_table,
+	.r_sta_mac_table = ksz8_r_sta_mac_table,
+	.w_sta_mac_table = ksz8_w_sta_mac_table,
+	.r_mib_cnt = ksz8_r_mib_cnt,
+	.r_mib_pkt = ksz8_r_mib_pkt,
+	.freeze_mib = ksz8_freeze_mib,
+	.port_init_cnt = ksz8_port_init_cnt,
+	.fdb_dump = ksz8_fdb_dump,
+	.mdb_add = ksz8_mdb_add,
+	.mdb_del = ksz8_mdb_del,
+	.vlan_filtering = ksz8_port_vlan_filtering,
+	.vlan_add = ksz8_port_vlan_add,
+	.vlan_del = ksz8_port_vlan_del,
+	.mirror_add = ksz8_port_mirror_add,
+	.mirror_del = ksz8_port_mirror_del,
+	.get_stp_reg = ksz8_get_stp_reg,
+	.get_caps = ksz8_get_caps,
+	.shutdown = ksz8_reset_switch,
+	.init = ksz8_switch_init,
+	.exit = ksz8_switch_exit,
+};
+
+static const struct ksz_dev_ops ksz9477_dev_ops = {
+	.setup = ksz9477_setup,
+	.get_port_addr = ksz9477_get_port_addr,
+	.cfg_port_member = ksz9477_cfg_port_member,
+	.flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
+	.port_setup = ksz9477_port_setup,
+	.r_phy = ksz9477_r_phy,
+	.w_phy = ksz9477_w_phy,
+	.r_mib_cnt = ksz9477_r_mib_cnt,
+	.r_mib_pkt = ksz9477_r_mib_pkt,
+	.r_mib_stat64 = ksz_r_mib_stats64,
+	.freeze_mib = ksz9477_freeze_mib,
+	.port_init_cnt = ksz9477_port_init_cnt,
+	.vlan_filtering = ksz9477_port_vlan_filtering,
+	.vlan_add = ksz9477_port_vlan_add,
+	.vlan_del = ksz9477_port_vlan_del,
+	.mirror_add = ksz9477_port_mirror_add,
+	.mirror_del = ksz9477_port_mirror_del,
+	.get_stp_reg = ksz9477_get_stp_reg,
+	.get_caps = ksz9477_get_caps,
+	.fdb_dump = ksz9477_fdb_dump,
+	.fdb_add = ksz9477_fdb_add,
+	.fdb_del = ksz9477_fdb_del,
+	.mdb_add = ksz9477_mdb_add,
+	.mdb_del = ksz9477_mdb_del,
+	.change_mtu = ksz9477_change_mtu,
+	.max_mtu = ksz9477_max_mtu,
+	.shutdown = ksz9477_reset_switch,
+	.dsa_init = ksz9477_dsa_init,
+	.init = ksz9477_switch_init,
+	.exit = ksz9477_switch_exit,
+};
+
 const struct ksz_chip_data ksz_switch_chips[] = {
 	[KSZ8795] = {
 		.chip_id = KSZ8795_CHIP_ID,
@@ -148,6 +213,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.num_statics = 8,
 		.cpu_ports = 0x10,	/* can be configured as cpu port */
 		.port_cnt = 5,		/* total cpu and user ports */
+		.ops = &ksz8_dev_ops,
 		.ksz87xx_eee_link_erratum = true,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -180,6 +246,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.num_statics = 8,
 		.cpu_ports = 0x10,	/* can be configured as cpu port */
 		.port_cnt = 5,		/* total cpu and user ports */
+		.ops = &ksz8_dev_ops,
 		.ksz87xx_eee_link_erratum = true,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -198,6 +265,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.num_statics = 8,
 		.cpu_ports = 0x10,	/* can be configured as cpu port */
 		.port_cnt = 5,		/* total cpu and user ports */
+		.ops = &ksz8_dev_ops,
 		.ksz87xx_eee_link_erratum = true,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -216,6 +284,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.num_statics = 8,
 		.cpu_ports = 0x4,	/* can be configured as cpu port */
 		.port_cnt = 3,
+		.ops = &ksz8_dev_ops,
 		.mib_names = ksz88xx_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz88xx_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
@@ -232,6 +301,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.num_statics = 16,
 		.cpu_ports = 0x7F,	/* can be configured as cpu port */
 		.port_cnt = 7,		/* total physical port count */
+		.ops = &ksz9477_dev_ops,
 		.phy_errata_9477 = true,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -254,6 +324,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.num_statics = 16,
 		.cpu_ports = 0x7F,	/* can be configured as cpu port */
 		.port_cnt = 7,		/* total physical port count */
+		.ops = &ksz9477_dev_ops,
 		.phy_errata_9477 = true,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -276,6 +347,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.num_statics = 16,
 		.cpu_ports = 0x07,	/* can be configured as cpu port */
 		.port_cnt = 3,		/* total port count */
+		.ops = &ksz9477_dev_ops,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
@@ -293,6 +365,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.num_statics = 16,
 		.cpu_ports = 0x7F,	/* can be configured as cpu port */
 		.port_cnt = 7,		/* total physical port count */
+		.ops = &ksz9477_dev_ops,
 		.phy_errata_9477 = true,
 		.mib_names = ksz9477_mib_names,
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
@@ -1130,8 +1203,7 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
 }
 EXPORT_SYMBOL(ksz_switch_alloc);
 
-int ksz_switch_register(struct ksz_device *dev,
-			const struct ksz_dev_ops *ops)
+int ksz_switch_register(struct ksz_device *dev)
 {
 	const struct ksz_chip_data *info;
 	struct device_node *port, *ports;
@@ -1178,7 +1250,7 @@ int ksz_switch_register(struct ksz_device *dev,
 	if (ret)
 		return ret;
 
-	dev->dev_ops = ops;
+	dev->dev_ops = dev->info->ops;
 
 	ret = dev->dev_ops->init(dev);
 	if (ret)
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 23962f47df46..dbd194e4039a 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -41,6 +41,7 @@ struct ksz_chip_data {
 	int num_statics;
 	int cpu_ports;
 	int port_cnt;
+	const struct ksz_dev_ops *ops;
 	bool phy_errata_9477;
 	bool ksz87xx_eee_link_erratum;
 	const struct ksz_mib_names *mib_names;
@@ -219,13 +220,9 @@ struct ksz_dev_ops {
 };
 
 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
-int ksz_switch_register(struct ksz_device *dev,
-			const struct ksz_dev_ops *ops);
+int ksz_switch_register(struct ksz_device *dev);
 void ksz_switch_remove(struct ksz_device *dev);
 
-int ksz8_switch_register(struct ksz_device *dev);
-int ksz9477_switch_register(struct ksz_device *dev);
-
 void ksz_init_mib_timer(struct ksz_device *dev);
 void ksz_r_mib_stats64(struct ksz_device *dev, int port);
 void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [RFC Patch net-next v2 15/15] net: dsa: microchip: common ksz_spi_probe for ksz switches
  2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
                   ` (13 preceding siblings ...)
  2022-05-30 10:42 ` [RFC Patch net-next v2 14/15] net: dsa: microchip: move ksz_dev_ops to ksz_common.c Arun Ramadoss
@ 2022-05-30 10:42 ` Arun Ramadoss
  14 siblings, 0 replies; 35+ messages in thread
From: Arun Ramadoss @ 2022-05-30 10:42 UTC (permalink / raw)
  To: linux-kernel, netdev
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

As of now, there are two spi probes, one ksz8795_spi.c and other
ksz9477_spi.c. This patch combines two files into single ksz_spi.c. The
difference between the two are regmap config and struct ksz8. The regmap
config is assigned based on the platform data. And struct ksz8 is left
untouched, as it is used only ksz8795.c. It can be used for all
other switches also in future.

Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
---
 drivers/net/dsa/microchip/Kconfig             |  16 +-
 drivers/net/dsa/microchip/Makefile            |   3 +-
 drivers/net/dsa/microchip/ksz9477_spi.c       | 150 ------------------
 .../microchip/{ksz8795_spi.c => ksz_spi.c}    |  83 +++++++---
 4 files changed, 69 insertions(+), 183 deletions(-)
 delete mode 100644 drivers/net/dsa/microchip/ksz9477_spi.c
 rename drivers/net/dsa/microchip/{ksz8795_spi.c => ksz_spi.c} (61%)

diff --git a/drivers/net/dsa/microchip/Kconfig b/drivers/net/dsa/microchip/Kconfig
index d21ff069e5aa..2edb88080790 100644
--- a/drivers/net/dsa/microchip/Kconfig
+++ b/drivers/net/dsa/microchip/Kconfig
@@ -8,29 +8,19 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON
 	  KSZ8795/KSZ88x3 switch chips.
 
 config NET_DSA_MICROCHIP_KSZ9477_I2C
-	tristate "KSZ9477 series I2C connected switch driver"
+	tristate "KSZ series I2C connected switch driver"
 	depends on NET_DSA_MICROCHIP_KSZ_COMMON && I2C
 	select REGMAP_I2C
 	help
 	  Select to enable support for registering switches configured through I2C.
 
-config NET_DSA_MICROCHIP_KSZ9477_SPI
-	tristate "KSZ9477 series SPI connected switch driver"
+config NET_DSA_MICROCHIP_KSZ_SPI
+	tristate "KSZ series SPI connected switch driver"
 	depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI
 	select REGMAP_SPI
 	help
 	  Select to enable support for registering switches configured through SPI.
 
-config NET_DSA_MICROCHIP_KSZ8795_SPI
-	tristate "KSZ8795 series SPI connected switch driver"
-	depends on NET_DSA_MICROCHIP_KSZ_COMMON && SPI
-	select REGMAP_SPI
-	help
-	  This driver accesses KSZ8795 chip through SPI.
-
-	  It is required to use the KSZ8795 switch driver as the only access
-	  is through SPI.
-
 config NET_DSA_MICROCHIP_KSZ8863_SMI
 	tristate "KSZ series SMI connected switch driver"
 	depends on NET_DSA_MICROCHIP_KSZ_COMMON
diff --git a/drivers/net/dsa/microchip/Makefile b/drivers/net/dsa/microchip/Makefile
index 4cf4755e6426..b2ba7c1bcb93 100644
--- a/drivers/net/dsa/microchip/Makefile
+++ b/drivers/net/dsa/microchip/Makefile
@@ -4,6 +4,5 @@ ksz_switch-objs := ksz_common.o
 ksz_switch-objs += ksz9477.o
 ksz_switch-objs += ksz8795.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C)	+= ksz9477_i2c.o
-obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI)	+= ksz9477_spi.o
-obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8795_SPI)	+= ksz8795_spi.o
+obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_SPI)		+= ksz_spi.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI)	+= ksz8863_smi.o
diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c
deleted file mode 100644
index 2ee0601bc014..000000000000
--- a/drivers/net/dsa/microchip/ksz9477_spi.c
+++ /dev/null
@@ -1,150 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Microchip KSZ9477 series register access through SPI
- *
- * Copyright (C) 2017-2019 Microchip Technology Inc.
- */
-
-#include <asm/unaligned.h>
-
-#include <linux/delay.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/regmap.h>
-#include <linux/spi/spi.h>
-
-#include "ksz_common.h"
-
-#define SPI_ADDR_SHIFT			24
-#define SPI_ADDR_ALIGN			3
-#define SPI_TURNAROUND_SHIFT		5
-
-KSZ_REGMAP_TABLE(ksz9477, 32, SPI_ADDR_SHIFT,
-		 SPI_TURNAROUND_SHIFT, SPI_ADDR_ALIGN);
-
-static int ksz9477_spi_probe(struct spi_device *spi)
-{
-	struct regmap_config rc;
-	struct ksz_device *dev;
-	int i, ret;
-
-	dev = ksz_switch_alloc(&spi->dev, spi);
-	if (!dev)
-		return -ENOMEM;
-
-	for (i = 0; i < ARRAY_SIZE(ksz9477_regmap_config); i++) {
-		rc = ksz9477_regmap_config[i];
-		rc.lock_arg = &dev->regmap_mutex;
-		dev->regmap[i] = devm_regmap_init_spi(spi, &rc);
-		if (IS_ERR(dev->regmap[i])) {
-			ret = PTR_ERR(dev->regmap[i]);
-			dev_err(&spi->dev,
-				"Failed to initialize regmap%i: %d\n",
-				ksz9477_regmap_config[i].val_bits, ret);
-			return ret;
-		}
-	}
-
-	if (spi->dev.platform_data)
-		dev->pdata = spi->dev.platform_data;
-
-	/* setup spi */
-	spi->mode = SPI_MODE_3;
-	ret = spi_setup(spi);
-	if (ret)
-		return ret;
-
-	ret = ksz_switch_register(dev);
-
-	/* Main DSA driver may not be started yet. */
-	if (ret)
-		return ret;
-
-	spi_set_drvdata(spi, dev);
-
-	return 0;
-}
-
-static void ksz9477_spi_remove(struct spi_device *spi)
-{
-	struct ksz_device *dev = spi_get_drvdata(spi);
-
-	if (dev)
-		ksz_switch_remove(dev);
-
-	spi_set_drvdata(spi, NULL);
-}
-
-static void ksz9477_spi_shutdown(struct spi_device *spi)
-{
-	struct ksz_device *dev = spi_get_drvdata(spi);
-
-	if (dev)
-		dsa_switch_shutdown(dev->ds);
-
-	spi_set_drvdata(spi, NULL);
-}
-
-static const struct of_device_id ksz9477_dt_ids[] = {
-	{
-		.compatible = "microchip,ksz9477",
-		.data = &ksz_switch_chips[KSZ9477]
-	},
-	{
-		.compatible = "microchip,ksz9897",
-		.data = &ksz_switch_chips[KSZ9897]
-	},
-	{
-		.compatible = "microchip,ksz9893",
-		.data = &ksz_switch_chips[KSZ9893]
-	},
-	{
-		.compatible = "microchip,ksz9563",
-		.data = &ksz_switch_chips[KSZ9893]
-	},
-	{
-		.compatible = "microchip,ksz8563",
-		.data = &ksz_switch_chips[KSZ9893]
-	},
-	{
-		.compatible = "microchip,ksz9567",
-		.data = &ksz_switch_chips[KSZ9567]
-	},
-	{},
-};
-MODULE_DEVICE_TABLE(of, ksz9477_dt_ids);
-
-static const struct spi_device_id ksz9477_spi_ids[] = {
-	{ "ksz9477" },
-	{ "ksz9897" },
-	{ "ksz9893" },
-	{ "ksz9563" },
-	{ "ksz8563" },
-	{ "ksz9567" },
-	{ },
-};
-MODULE_DEVICE_TABLE(spi, ksz9477_spi_ids);
-
-static struct spi_driver ksz9477_spi_driver = {
-	.driver = {
-		.name	= "ksz9477-switch",
-		.owner	= THIS_MODULE,
-		.of_match_table = of_match_ptr(ksz9477_dt_ids),
-	},
-	.id_table = ksz9477_spi_ids,
-	.probe	= ksz9477_spi_probe,
-	.remove	= ksz9477_spi_remove,
-	.shutdown = ksz9477_spi_shutdown,
-};
-
-module_spi_driver(ksz9477_spi_driver);
-
-MODULE_ALIAS("spi:ksz9477");
-MODULE_ALIAS("spi:ksz9897");
-MODULE_ALIAS("spi:ksz9893");
-MODULE_ALIAS("spi:ksz9563");
-MODULE_ALIAS("spi:ksz8563");
-MODULE_ALIAS("spi:ksz9567");
-MODULE_AUTHOR("Woojung Huh <Woojung.Huh@microchip.com>");
-MODULE_DESCRIPTION("Microchip KSZ9477 Series Switch SPI access Driver");
-MODULE_LICENSE("GPL");
diff --git a/drivers/net/dsa/microchip/ksz8795_spi.c b/drivers/net/dsa/microchip/ksz_spi.c
similarity index 61%
rename from drivers/net/dsa/microchip/ksz8795_spi.c
rename to drivers/net/dsa/microchip/ksz_spi.c
index 3a816661989c..baec2fbf9537 100644
--- a/drivers/net/dsa/microchip/ksz8795_spi.c
+++ b/drivers/net/dsa/microchip/ksz_spi.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Microchip KSZ8795 series register access through SPI
+ * Microchip ksz series register access through SPI
  *
  * Copyright (C) 2017 Microchip Technology Inc.
  *	Tristram Ha <Tristram.Ha@microchip.com>
@@ -25,13 +25,20 @@
 #define KSZ8863_SPI_ADDR_ALIGN			8
 #define KSZ8863_SPI_TURNAROUND_SHIFT		0
 
+#define KSZ9477_SPI_ADDR_SHIFT			24
+#define KSZ9477_SPI_ADDR_ALIGN			3
+#define KSZ9477_SPI_TURNAROUND_SHIFT		5
+
 KSZ_REGMAP_TABLE(ksz8795, 16, KSZ8795_SPI_ADDR_SHIFT,
 		 KSZ8795_SPI_TURNAROUND_SHIFT, KSZ8795_SPI_ADDR_ALIGN);
 
 KSZ_REGMAP_TABLE(ksz8863, 16, KSZ8863_SPI_ADDR_SHIFT,
 		 KSZ8863_SPI_TURNAROUND_SHIFT, KSZ8863_SPI_ADDR_ALIGN);
 
-static int ksz8795_spi_probe(struct spi_device *spi)
+KSZ_REGMAP_TABLE(ksz9477, 32, KSZ9477_SPI_ADDR_SHIFT,
+		 KSZ9477_SPI_TURNAROUND_SHIFT, KSZ9477_SPI_ADDR_ALIGN);
+
+static int ksz_spi_probe(struct spi_device *spi)
 {
 	const struct regmap_config *regmap_config;
 	const struct ksz_chip_data *chip;
@@ -57,8 +64,12 @@ static int ksz8795_spi_probe(struct spi_device *spi)
 
 	if (chip->chip_id == KSZ8830_CHIP_ID)
 		regmap_config = ksz8863_regmap_config;
-	else
+	else if (chip->chip_id == KSZ8795_CHIP_ID ||
+		 chip->chip_id == KSZ8794_CHIP_ID ||
+		 chip->chip_id == KSZ8765_CHIP_ID)
 		regmap_config = ksz8795_regmap_config;
+	else
+		regmap_config = ksz9477_regmap_config;
 
 	for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) {
 		rc = regmap_config[i];
@@ -93,7 +104,7 @@ static int ksz8795_spi_probe(struct spi_device *spi)
 	return 0;
 }
 
-static void ksz8795_spi_remove(struct spi_device *spi)
+static void ksz_spi_remove(struct spi_device *spi)
 {
 	struct ksz_device *dev = spi_get_drvdata(spi);
 
@@ -103,7 +114,7 @@ static void ksz8795_spi_remove(struct spi_device *spi)
 	spi_set_drvdata(spi, NULL);
 }
 
-static void ksz8795_spi_shutdown(struct spi_device *spi)
+static void ksz_spi_shutdown(struct spi_device *spi)
 {
 	struct ksz_device *dev = spi_get_drvdata(spi);
 
@@ -118,7 +129,7 @@ static void ksz8795_spi_shutdown(struct spi_device *spi)
 	spi_set_drvdata(spi, NULL);
 }
 
-static const struct of_device_id ksz8795_dt_ids[] = {
+static const struct of_device_id ksz_dt_ids[] = {
 	{
 		.compatible = "microchip,ksz8765",
 		.data = &ksz_switch_chips[KSZ8765]
@@ -139,34 +150,70 @@ static const struct of_device_id ksz8795_dt_ids[] = {
 		.compatible = "microchip,ksz8873",
 		.data = &ksz_switch_chips[KSZ8830]
 	},
+	{
+		.compatible = "microchip,ksz9477",
+		.data = &ksz_switch_chips[KSZ9477]
+	},
+	{
+		.compatible = "microchip,ksz9897",
+		.data = &ksz_switch_chips[KSZ9897]
+	},
+	{
+		.compatible = "microchip,ksz9893",
+		.data = &ksz_switch_chips[KSZ9893]
+	},
+	{
+		.compatible = "microchip,ksz9563",
+		.data = &ksz_switch_chips[KSZ9893]
+	},
+	{
+		.compatible = "microchip,ksz8563",
+		.data = &ksz_switch_chips[KSZ9893]
+	},
+	{
+		.compatible = "microchip,ksz9567",
+		.data = &ksz_switch_chips[KSZ9567]
+	},
 	{},
 };
-MODULE_DEVICE_TABLE(of, ksz8795_dt_ids);
+MODULE_DEVICE_TABLE(of, ksz_dt_ids);
 
-static const struct spi_device_id ksz8795_spi_ids[] = {
+static const struct spi_device_id ksz_spi_ids[] = {
 	{ "ksz8765" },
 	{ "ksz8794" },
 	{ "ksz8795" },
 	{ "ksz8863" },
 	{ "ksz8873" },
+	{ "ksz9477" },
+	{ "ksz9897" },
+	{ "ksz9893" },
+	{ "ksz9563" },
+	{ "ksz8563" },
+	{ "ksz9567" },
 	{ },
 };
-MODULE_DEVICE_TABLE(spi, ksz8795_spi_ids);
+MODULE_DEVICE_TABLE(spi, ksz_spi_ids);
 
-static struct spi_driver ksz8795_spi_driver = {
+static struct spi_driver ksz_spi_driver = {
 	.driver = {
-		.name	= "ksz8795-switch",
+		.name	= "ksz-switch",
 		.owner	= THIS_MODULE,
-		.of_match_table = of_match_ptr(ksz8795_dt_ids),
+		.of_match_table = of_match_ptr(ksz_dt_ids),
 	},
-	.id_table = ksz8795_spi_ids,
-	.probe	= ksz8795_spi_probe,
-	.remove	= ksz8795_spi_remove,
-	.shutdown = ksz8795_spi_shutdown,
+	.id_table = ksz_spi_ids,
+	.probe	= ksz_spi_probe,
+	.remove	= ksz_spi_remove,
+	.shutdown = ksz_spi_shutdown,
 };
 
-module_spi_driver(ksz8795_spi_driver);
+module_spi_driver(ksz_spi_driver);
 
+MODULE_ALIAS("spi:ksz9477");
+MODULE_ALIAS("spi:ksz9897");
+MODULE_ALIAS("spi:ksz9893");
+MODULE_ALIAS("spi:ksz9563");
+MODULE_ALIAS("spi:ksz8563");
+MODULE_ALIAS("spi:ksz9567");
 MODULE_AUTHOR("Tristram Ha <Tristram.Ha@microchip.com>");
-MODULE_DESCRIPTION("Microchip KSZ8795 Series Switch SPI Driver");
+MODULE_DESCRIPTION("Microchip ksz Series Switch SPI Driver");
 MODULE_LICENSE("GPL");
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 01/15] net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect
  2022-05-30 10:42 ` [RFC Patch net-next v2 01/15] net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect Arun Ramadoss
@ 2022-06-12 14:20   ` Vladimir Oltean
  0 siblings, 0 replies; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-12 14:20 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:43PM +0530, Arun Ramadoss wrote:
> The ksz9477_switch_detect performs the detecting the chip id from the
> location 0x00 and also check gigabit compatibility check & number of
> ports based on the register global_options0. To prepare the common ksz
> switch detect function, routine other than chip id read is moved to
> ksz9477_switch_init.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 02/15] net: dsa: microchip: move switch chip_id detection to ksz_common
  2022-05-30 10:42 ` [RFC Patch net-next v2 02/15] net: dsa: microchip: move switch chip_id detection to ksz_common Arun Ramadoss
@ 2022-06-13  9:18   ` Vladimir Oltean
  2022-06-14  7:10     ` Arun.Ramadoss
  0 siblings, 1 reply; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-13  9:18 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:44PM +0530, Arun Ramadoss wrote:
> KSZ87xx and KSZ88xx have chip_id representation at reg location 0. And
> KSZ9477 compatible switch and LAN937x switch have same chip_id detection
> at location 0x01 and 0x02. To have the common switch detect
> functionality for ksz switches, ksz_switch_detect function is
> introduced.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---
>  drivers/net/dsa/microchip/ksz8795.c     | 46 ---------------
>  drivers/net/dsa/microchip/ksz8795_reg.h | 13 -----
>  drivers/net/dsa/microchip/ksz9477.c     | 21 -------
>  drivers/net/dsa/microchip/ksz9477_reg.h |  1 -
>  drivers/net/dsa/microchip/ksz_common.c  | 78 +++++++++++++++++++++++--
>  drivers/net/dsa/microchip/ksz_common.h  | 19 +++++-
>  6 files changed, 92 insertions(+), 86 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 12a599d5e61a..927db57d02db 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -1424,51 +1424,6 @@ static u32 ksz8_get_port_addr(int port, int offset)
>  	return PORT_CTRL_ADDR(port, offset);
>  }
>  
> -static int ksz8_switch_detect(struct ksz_device *dev)
> -{
> -	u8 id1, id2;
> -	u16 id16;
> -	int ret;
> -
> -	/* read chip id */
> -	ret = ksz_read16(dev, REG_CHIP_ID0, &id16);
> -	if (ret)
> -		return ret;
> -
> -	id1 = id16 >> 8;
> -	id2 = id16 & SW_CHIP_ID_M;
> -
> -	switch (id1) {
> -	case KSZ87_FAMILY_ID:
> -		if ((id2 != CHIP_ID_94 && id2 != CHIP_ID_95))
> -			return -ENODEV;
> -
> -		if (id2 == CHIP_ID_95) {
> -			u8 val;
> -
> -			id2 = 0x95;
> -			ksz_read8(dev, REG_PORT_STATUS_0, &val);

Could you replace all remaining occurrences of REG_PORT_STATUS_0 and
PORT_FIBER_MODE with KSZ8_PORT_STATUS_0 and KSZ8_PORT_FIBER_MODE?
It would be good to not have multiple definitions for the same thing.

> -			if (val & PORT_FIBER_MODE)
> -				id2 = 0x65;
> -		} else if (id2 == CHIP_ID_94) {
> -			id2 = 0x94;
> -		}
> -		break;
> -	case KSZ88_FAMILY_ID:
> -		if (id2 != CHIP_ID_63)
> -			return -ENODEV;
> -		break;
> -	default:
> -		dev_err(dev->dev, "invalid family id: %d\n", id1);
> -		return -ENODEV;
> -	}
> -	id16 &= ~0xff;
> -	id16 |= id2;
> -	dev->chip_id = id16;
> -
> -	return 0;
> -}
> -
>  static int ksz8_switch_init(struct ksz_device *dev)
>  {
>  	struct ksz8 *ksz8 = dev->priv;
> @@ -1522,7 +1477,6 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
>  	.freeze_mib = ksz8_freeze_mib,
>  	.port_init_cnt = ksz8_port_init_cnt,
>  	.shutdown = ksz8_reset_switch,
> -	.detect = ksz8_switch_detect,
>  	.init = ksz8_switch_init,
>  	.exit = ksz8_switch_exit,
>  };
> diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h
> index 4109433b6b6c..50cdc2a09f5a 100644
> --- a/drivers/net/dsa/microchip/ksz8795_reg.h
> +++ b/drivers/net/dsa/microchip/ksz8795_reg.h
> @@ -14,23 +14,10 @@
>  #define KS_PRIO_M			0x3
>  #define KS_PRIO_S			2
>  
> -#define REG_CHIP_ID0			0x00
> -
> -#define KSZ87_FAMILY_ID			0x87
> -#define KSZ88_FAMILY_ID			0x88
> -
> -#define REG_CHIP_ID1			0x01
> -
> -#define SW_CHIP_ID_M			0xF0
> -#define SW_CHIP_ID_S			4
>  #define SW_REVISION_M			0x0E
>  #define SW_REVISION_S			1
>  #define SW_START			0x01
>  
> -#define CHIP_ID_94			0x60
> -#define CHIP_ID_95			0x90
> -#define CHIP_ID_63			0x30
> -
>  #define KSZ8863_REG_SW_RESET		0x43
>  
>  #define KSZ8863_GLOBAL_SOFTWARE_RESET	BIT(4)
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index 7afc06681c02..7d3c8f6908b6 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -1360,23 +1360,6 @@ static u32 ksz9477_get_port_addr(int port, int offset)
>  	return PORT_CTRL_ADDR(port, offset);
>  }
>  
> -static int ksz9477_switch_detect(struct ksz_device *dev)
> -{
> -	u32 id32;
> -	int ret;
> -
> -	/* read chip id */
> -	ret = ksz_read32(dev, REG_CHIP_ID0__1, &id32);
> -	if (ret)
> -		return ret;
> -
> -	dev_dbg(dev->dev, "Switch detect: ID=%08x\n", id32);
> -
> -	dev->chip_id = id32 & 0x00FFFF00;
> -
> -	return 0;
> -}
> -
>  static int ksz9477_switch_init(struct ksz_device *dev)
>  {
>  	u8 data8;
> @@ -1407,8 +1390,6 @@ static int ksz9477_switch_init(struct ksz_device *dev)
>  	dev->features = GBIT_SUPPORT;
>  
>  	if (dev->chip_id == KSZ9893_CHIP_ID) {
> -		/* Chip is from KSZ9893 design. */
> -		dev_info(dev->dev, "Found KSZ9893\n");
>  		dev->features |= IS_9893;
>  
>  		/* Chip does not support gigabit. */
> @@ -1416,7 +1397,6 @@ static int ksz9477_switch_init(struct ksz_device *dev)
>  			dev->features &= ~GBIT_SUPPORT;
>  		dev->phy_port_cnt = 2;
>  	} else {
> -		dev_info(dev->dev, "Found KSZ9477 or compatible\n");
>  		/* Chip uses new XMII register definitions. */
>  		dev->features |= NEW_XMII;
>  
> @@ -1443,7 +1423,6 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
>  	.freeze_mib = ksz9477_freeze_mib,
>  	.port_init_cnt = ksz9477_port_init_cnt,
>  	.shutdown = ksz9477_reset_switch,
> -	.detect = ksz9477_switch_detect,
>  	.init = ksz9477_switch_init,
>  	.exit = ksz9477_switch_exit,
>  };
> diff --git a/drivers/net/dsa/microchip/ksz9477_reg.h b/drivers/net/dsa/microchip/ksz9477_reg.h
> index 7a2c8d4767af..077e35ab11b5 100644
> --- a/drivers/net/dsa/microchip/ksz9477_reg.h
> +++ b/drivers/net/dsa/microchip/ksz9477_reg.h
> @@ -25,7 +25,6 @@
>  
>  #define REG_CHIP_ID2__1			0x0002
>  
> -#define CHIP_ID_63			0x63
>  #define CHIP_ID_66			0x66
>  #define CHIP_ID_67			0x67
>  #define CHIP_ID_77			0x77
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index 9ca8c8d7740f..9057cdb5971c 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -930,6 +930,72 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port,
>  }
>  EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
>  
> +static int ksz_switch_detect(struct ksz_device *dev)
> +{
> +	u8 id1, id2;
> +	u16 id16;
> +	u32 id32;
> +	int ret;
> +
> +	/* read chip id */
> +	ret = ksz_read16(dev, REG_CHIP_ID0, &id16);
> +	if (ret)
> +		return ret;
> +
> +	id1 = FIELD_GET(SW_FAMILY_ID_M, id16);
> +	id2 = FIELD_GET(SW_CHIP_ID_M, id16);
> +
> +	switch (id1) {
> +	case KSZ87_FAMILY_ID:
> +		if (id2 == CHIP_ID_95) {
> +			u8 val;
> +
> +			dev->chip_id = KSZ8795_CHIP_ID;
> +
> +			ksz_read8(dev, KSZ8_PORT_STATUS_0, &val);
> +			if (val & KSZ8_PORT_FIBER_MODE)
> +				dev->chip_id = KSZ8765_CHIP_ID;
> +		} else if (id2 == CHIP_ID_94) {
> +			dev->chip_id = KSZ8794_CHIP_ID;
> +		} else {
> +			return -ENODEV;
> +		}
> +		break;
> +	case KSZ88_FAMILY_ID:
> +		if (id2 == CHIP_ID_63)
> +			dev->chip_id = KSZ8830_CHIP_ID;
> +		else
> +			return -ENODEV;
> +		break;
> +	default:
> +		ret = ksz_read32(dev, REG_CHIP_ID0, &id32);
> +		if (ret)
> +			return ret;
> +
> +		dev->chip_rev = FIELD_GET(SW_REV_ID_M, id32);
> +		id32 &= ~0xFF;
> +
> +		switch (id32) {
> +		case KSZ9477_CHIP_ID:
> +		case KSZ9897_CHIP_ID:
> +		case KSZ9893_CHIP_ID:
> +		case KSZ9567_CHIP_ID:
> +		case LAN9370_CHIP_ID:
> +		case LAN9371_CHIP_ID:
> +		case LAN9372_CHIP_ID:
> +		case LAN9373_CHIP_ID:
> +		case LAN9374_CHIP_ID:
> +			dev->chip_id = id32;
> +			break;
> +		default:
> +			dev_err(dev->dev,
> +				"unsupported switch detected %x)\n", id32);
> +			return -ENODEV;
> +		}
> +	}
> +	return 0;
> +}
> +
>  struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
>  {
>  	struct dsa_switch *ds;
> @@ -986,10 +1052,9 @@ int ksz_switch_register(struct ksz_device *dev,
>  	mutex_init(&dev->alu_mutex);
>  	mutex_init(&dev->vlan_mutex);
>  
> -	dev->dev_ops = ops;
> -
> -	if (dev->dev_ops->detect(dev))
> -		return -EINVAL;
> +	ret = ksz_switch_detect(dev);
> +	if (ret)
> +		return ret;
>  
>  	info = ksz_lookup_info(dev->chip_id);
>  	if (!info)
> @@ -998,10 +1063,15 @@ int ksz_switch_register(struct ksz_device *dev,
>  	/* Update the compatible info with the probed one */
>  	dev->info = info;
>  
> +	dev_info(dev->dev, "found switch: %s, rev %i\n",
> +		 dev->info->dev_name, dev->chip_rev);
> +
>  	ret = ksz_check_device_id(dev);
>  	if (ret)
>  		return ret;
>  
> +	dev->dev_ops = ops;
> +
>  	ret = dev->dev_ops->init(dev);
>  	if (ret)
>  		return ret;
> diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
> index 8500eaedad67..d16c095cdefb 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -90,6 +90,7 @@ struct ksz_device {
>  
>  	/* chip specific data */
>  	u32 chip_id;
> +	u8 chip_rev;
>  	int cpu_port;			/* port connected to CPU */
>  	int phy_port_cnt;
>  	phy_interface_t compat_interface;
> @@ -182,7 +183,6 @@ struct ksz_dev_ops {
>  	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
>  	void (*port_init_cnt)(struct ksz_device *dev, int port);
>  	int (*shutdown)(struct ksz_device *dev);
> -	int (*detect)(struct ksz_device *dev);
>  	int (*init)(struct ksz_device *dev);
>  	void (*exit)(struct ksz_device *dev);
>  };
> @@ -353,6 +353,23 @@ static inline void ksz_regmap_unlock(void *__mtx)
>  #define PORT_RX_ENABLE			BIT(1)
>  #define PORT_LEARN_DISABLE		BIT(0)
>  
> +/* Switch ID Defines */
> +#define REG_CHIP_ID0			0x00
> +
> +#define SW_FAMILY_ID_M			GENMASK(15, 8)
> +#define KSZ87_FAMILY_ID			0x87
> +#define KSZ88_FAMILY_ID			0x88
> +
> +#define KSZ8_PORT_STATUS_0		0x08
> +#define KSZ8_PORT_FIBER_MODE		BIT(7)
> +
> +#define SW_CHIP_ID_M			GENMASK(7, 4)
> +#define CHIP_ID_94			0x6
> +#define CHIP_ID_95			0x9

KSZ87_CHIP_ID_xxx maybe?

> +#define CHIP_ID_63			0x3

And KSZ88_CHIP_ID_63.

> +
> +#define SW_REV_ID_M			GENMASK(7, 4)
> +
>  /* Regmap tables generation */
>  #define KSZ_SPI_OP_RD		3
>  #define KSZ_SPI_OP_WR		2
> -- 
> 2.36.1
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 03/15] net: dsa: microchip: move tag_protocol & phy read/write to ksz_common
  2022-05-30 10:42 ` [RFC Patch net-next v2 03/15] net: dsa: microchip: move tag_protocol & phy read/write " Arun Ramadoss
@ 2022-06-13  9:22   ` Vladimir Oltean
  2022-06-15  6:36     ` Arun.Ramadoss
  0 siblings, 1 reply; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-13  9:22 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:45PM +0530, Arun Ramadoss wrote:
> This patch move the dsa hook get_tag_protocol to ksz_common file. And
> the tag_protocol is returned based on the dev->chip_id.
> ksz8795 and ksz9477 implementation on phy read/write hooks are
> different. This patch modifies the ksz9477 implementation same as
> ksz8795 by updating the ksz9477_dev_ops structure.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---

It would be easier to review if you would split the phy_read/phy_write
change from the get_tag_protocol change.

>  drivers/net/dsa/microchip/ksz8795.c    | 13 +--------
>  drivers/net/dsa/microchip/ksz9477.c    | 37 ++++++++------------------
>  drivers/net/dsa/microchip/ksz_common.c | 24 +++++++++++++++++
>  drivers/net/dsa/microchip/ksz_common.h |  2 ++
>  4 files changed, 38 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 927db57d02db..6e5f665fa1f6 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -898,17 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
>  	}
>  }
>  
> -static enum dsa_tag_protocol ksz8_get_tag_protocol(struct dsa_switch *ds,
> -						   int port,
> -						   enum dsa_tag_protocol mp)
> -{
> -	struct ksz_device *dev = ds->priv;
> -
> -	/* ksz88x3 uses the same tag schema as KSZ9893 */
> -	return ksz_is_ksz88x3(dev) ?
> -		DSA_TAG_PROTO_KSZ9893 : DSA_TAG_PROTO_KSZ8795;
> -}
> -
>  static u32 ksz8_sw_get_phy_flags(struct dsa_switch *ds, int port)
>  {
>  	/* Silicon Errata Sheet (DS80000830A):
> @@ -1394,7 +1383,7 @@ static void ksz8_get_caps(struct dsa_switch *ds, int port,
>  }
>  
>  static const struct dsa_switch_ops ksz8_switch_ops = {
> -	.get_tag_protocol	= ksz8_get_tag_protocol,
> +	.get_tag_protocol	= ksz_get_tag_protocol,
>  	.get_phy_flags		= ksz8_sw_get_phy_flags,
>  	.setup			= ksz8_setup,
>  	.phy_read		= ksz_phy_read16,
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index 7d3c8f6908b6..4fb96e53487e 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -276,21 +276,8 @@ static void ksz9477_port_init_cnt(struct ksz_device *dev, int port)
>  	mutex_unlock(&mib->cnt_mutex);
>  }
>  
> -static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds,
> -						      int port,
> -						      enum dsa_tag_protocol mp)
> +static void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
>  {
> -	enum dsa_tag_protocol proto = DSA_TAG_PROTO_KSZ9477;
> -	struct ksz_device *dev = ds->priv;
> -
> -	if (dev->features & IS_9893)
> -		proto = DSA_TAG_PROTO_KSZ9893;
> -	return proto;
> -}
> -
> -static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg)
> -{
> -	struct ksz_device *dev = ds->priv;
>  	u16 val = 0xffff;
>  
>  	/* No real PHY after this. Simulate the PHY.
> @@ -335,24 +322,20 @@ static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg)
>  		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
>  	}
>  
> -	return val;
> +	*data = val;
>  }
>  
> -static int ksz9477_phy_write16(struct dsa_switch *ds, int addr, int reg,
> -			       u16 val)
> +static void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
>  {
> -	struct ksz_device *dev = ds->priv;
> -
>  	/* No real PHY after this. */
>  	if (addr >= dev->phy_port_cnt)
> -		return 0;
> +		return;
>  
>  	/* No gigabit support.  Do not write to this register. */
>  	if (!(dev->features & GBIT_SUPPORT) && reg == MII_CTRL1000)
> -		return 0;
> -	ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
> +		return;
>  
> -	return 0;
> +	ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
>  }
>  
>  static void ksz9477_cfg_port_member(struct ksz_device *dev, int port,
> @@ -1326,10 +1309,10 @@ static int ksz9477_setup(struct dsa_switch *ds)
>  }
>  
>  static const struct dsa_switch_ops ksz9477_switch_ops = {
> -	.get_tag_protocol	= ksz9477_get_tag_protocol,
> +	.get_tag_protocol	= ksz_get_tag_protocol,
>  	.setup			= ksz9477_setup,
> -	.phy_read		= ksz9477_phy_read16,
> -	.phy_write		= ksz9477_phy_write16,
> +	.phy_read		= ksz_phy_read16,
> +	.phy_write		= ksz_phy_write16,
>  	.phylink_mac_link_down	= ksz_mac_link_down,
>  	.phylink_get_caps	= ksz9477_get_caps,
>  	.port_enable		= ksz_enable_port,
> @@ -1417,6 +1400,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
>  	.cfg_port_member = ksz9477_cfg_port_member,
>  	.flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
>  	.port_setup = ksz9477_port_setup,
> +	.r_phy = ksz9477_r_phy,
> +	.w_phy = ksz9477_w_phy,
>  	.r_mib_cnt = ksz9477_r_mib_cnt,
>  	.r_mib_pkt = ksz9477_r_mib_pkt,
>  	.r_mib_stat64 = ksz_r_mib_stats64,
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index 9057cdb5971c..a43b01c2e67f 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -930,6 +930,30 @@ void ksz_port_stp_state_set(struct dsa_switch *ds, int port,
>  }
>  EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
>  
> +enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
> +					   int port, enum dsa_tag_protocol mp)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	enum dsa_tag_protocol proto;

Please choose a default value in case the dev->chip_id does not take any
of the branches, or at least do something to not return uninitialized
variables from the stack.

> +
> +	if (dev->chip_id == KSZ8795_CHIP_ID ||
> +	    dev->chip_id == KSZ8794_CHIP_ID ||
> +	    dev->chip_id == KSZ8765_CHIP_ID)
> +		proto = DSA_TAG_PROTO_KSZ8795;
> +
> +	if (dev->chip_id == KSZ8830_CHIP_ID ||
> +	    dev->chip_id == KSZ9893_CHIP_ID)
> +		proto = DSA_TAG_PROTO_KSZ9893;
> +
> +	if (dev->chip_id == KSZ9477_CHIP_ID ||
> +	    dev->chip_id == KSZ9897_CHIP_ID ||
> +	    dev->chip_id == KSZ9567_CHIP_ID)
> +		proto = DSA_TAG_PROTO_KSZ9477;
> +
> +	return proto;
> +}
> +EXPORT_SYMBOL_GPL(ksz_get_tag_protocol);
> +
>  static int ksz_switch_detect(struct ksz_device *dev)
>  {
>  	u8 id1, id2;
> diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
> index d16c095cdefb..f253f3f22386 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -231,6 +231,8 @@ int ksz_port_mdb_del(struct dsa_switch *ds, int port,
>  int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
>  void ksz_get_strings(struct dsa_switch *ds, int port,
>  		     u32 stringset, uint8_t *buf);
> +enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
> +					   int port, enum dsa_tag_protocol mp);
>  
>  /* Common register access functions */
>  
> -- 
> 2.36.1
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 04/15] net: dsa: microchip: move vlan functionality to ksz_common
  2022-05-30 10:42 ` [RFC Patch net-next v2 04/15] net: dsa: microchip: move vlan functionality " Arun Ramadoss
@ 2022-06-13  9:24   ` Vladimir Oltean
  0 siblings, 0 replies; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-13  9:24 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:46PM +0530, Arun Ramadoss wrote:
> This patch moves the vlan dsa_switch_ops such as vlan_add, vlan_del and
> vlan_filtering from the individual files ksz8795.c, ksz9477.c to
> ksz_common.c file.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 05/15] net: dsa: microchip: move the port mirror to ksz_common
  2022-05-30 10:42 ` [RFC Patch net-next v2 05/15] net: dsa: microchip: move the port mirror " Arun Ramadoss
@ 2022-06-13  9:28   ` Vladimir Oltean
  2022-06-15  6:40     ` Arun.Ramadoss
  0 siblings, 1 reply; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-13  9:28 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:47PM +0530, Arun Ramadoss wrote:
> This patch updates the common port mirror add/del dsa_switch_ops in
> ksz_common.c. The individual switches implementation is executed based
> on the ksz_dev_ops function pointers.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>

>  drivers/net/dsa/microchip/ksz8795.c    | 13 ++++++-------
>  drivers/net/dsa/microchip/ksz9477.c    | 12 ++++++------
>  drivers/net/dsa/microchip/ksz_common.c | 25 +++++++++++++++++++++++++
>  drivers/net/dsa/microchip/ksz_common.h | 10 ++++++++++
>  4 files changed, 47 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 157d69e46793..8657b520b336 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -1089,12 +1089,10 @@ static int ksz8_port_vlan_del(struct ksz_device *dev, int port,
>  	return 0;
>  }
>  
> -static int ksz8_port_mirror_add(struct dsa_switch *ds, int port,
> +static int ksz8_port_mirror_add(struct ksz_device *dev, int port,
>  				struct dsa_mall_mirror_tc_entry *mirror,
>  				bool ingress, struct netlink_ext_ack *extack)
>  {
> -	struct ksz_device *dev = ds->priv;
> -
>  	if (ingress) {
>  		ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX, true);
>  		dev->mirror_rx |= BIT(port);
> @@ -1113,10 +1111,9 @@ static int ksz8_port_mirror_add(struct dsa_switch *ds, int port,
>  	return 0;
>  }
>  
> -static void ksz8_port_mirror_del(struct dsa_switch *ds, int port,
> +static void ksz8_port_mirror_del(struct ksz_device *dev, int port,
>  				 struct dsa_mall_mirror_tc_entry *mirror)
>  {
> -	struct ksz_device *dev = ds->priv;
>  	u8 data;
>  
>  	if (mirror->ingress) {
> @@ -1400,8 +1397,8 @@ static const struct dsa_switch_ops ksz8_switch_ops = {
>  	.port_fdb_dump		= ksz_port_fdb_dump,
>  	.port_mdb_add           = ksz_port_mdb_add,
>  	.port_mdb_del           = ksz_port_mdb_del,
> -	.port_mirror_add	= ksz8_port_mirror_add,
> -	.port_mirror_del	= ksz8_port_mirror_del,
> +	.port_mirror_add	= ksz_port_mirror_add,
> +	.port_mirror_del	= ksz_port_mirror_del,
>  };
>  
>  static u32 ksz8_get_port_addr(int port, int offset)
> @@ -1464,6 +1461,8 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
>  	.vlan_filtering = ksz8_port_vlan_filtering,
>  	.vlan_add = ksz8_port_vlan_add,
>  	.vlan_del = ksz8_port_vlan_del,
> +	.mirror_add = ksz8_port_mirror_add,
> +	.mirror_del = ksz8_port_mirror_del,
>  	.shutdown = ksz8_reset_switch,
>  	.init = ksz8_switch_init,
>  	.exit = ksz8_switch_exit,
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index e230fe1d1917..6796c9d89ab9 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -811,11 +811,10 @@ static int ksz9477_port_mdb_del(struct dsa_switch *ds, int port,
>  	return ret;
>  }
>  
> -static int ksz9477_port_mirror_add(struct dsa_switch *ds, int port,
> +static int ksz9477_port_mirror_add(struct ksz_device *dev, int port,
>  				   struct dsa_mall_mirror_tc_entry *mirror,
>  				   bool ingress, struct netlink_ext_ack *extack)
>  {
> -	struct ksz_device *dev = ds->priv;
>  	u8 data;
>  	int p;
>  
> @@ -851,10 +850,9 @@ static int ksz9477_port_mirror_add(struct dsa_switch *ds, int port,
>  	return 0;
>  }
>  
> -static void ksz9477_port_mirror_del(struct dsa_switch *ds, int port,
> +static void ksz9477_port_mirror_del(struct ksz_device *dev, int port,
>  				    struct dsa_mall_mirror_tc_entry *mirror)
>  {
> -	struct ksz_device *dev = ds->priv;
>  	bool in_use = false;
>  	u8 data;
>  	int p;
> @@ -1327,8 +1325,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
>  	.port_fdb_del		= ksz9477_port_fdb_del,
>  	.port_mdb_add           = ksz9477_port_mdb_add,
>  	.port_mdb_del           = ksz9477_port_mdb_del,
> -	.port_mirror_add	= ksz9477_port_mirror_add,
> -	.port_mirror_del	= ksz9477_port_mirror_del,
> +	.port_mirror_add	= ksz_port_mirror_add,
> +	.port_mirror_del	= ksz_port_mirror_del,
>  	.get_stats64		= ksz_get_stats64,
>  	.port_change_mtu	= ksz9477_change_mtu,
>  	.port_max_mtu		= ksz9477_max_mtu,
> @@ -1406,6 +1404,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
>  	.vlan_filtering = ksz9477_port_vlan_filtering,
>  	.vlan_add = ksz9477_port_vlan_add,
>  	.vlan_del = ksz9477_port_vlan_del,
> +	.mirror_add = ksz9477_port_mirror_add,
> +	.mirror_del = ksz9477_port_mirror_del,
>  	.shutdown = ksz9477_reset_switch,
>  	.init = ksz9477_switch_init,
>  	.exit = ksz9477_switch_exit,
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index a1fef9e4e36c..1ed4cc94795e 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -994,6 +994,31 @@ int ksz_port_vlan_del(struct dsa_switch *ds, int port,
>  }
>  EXPORT_SYMBOL_GPL(ksz_port_vlan_del);
>  
> +int ksz_port_mirror_add(struct dsa_switch *ds, int port,
> +			struct dsa_mall_mirror_tc_entry *mirror,
> +			bool ingress, struct netlink_ext_ack *extack)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	int ret = -EOPNOTSUPP;
> +
> +	if (dev->dev_ops->mirror_add)
> +		ret = dev->dev_ops->mirror_add(dev, port, mirror, ingress,
> +					       extack);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(ksz_port_mirror_add);

Just as a minor style comment, take it or leave it.

If you switch the function pointer presence check, you reduce the
indentation of the long statement, making it fit a single line, and you
eliminate the need for a "ret" variable:

	if (!dev->dev_ops->mirror_add)
		return -EOPNOTSUPP;

	return dev->dev_ops->mirror_add(dev, port, mirror, ingress, extack);

> +
> +void ksz_port_mirror_del(struct dsa_switch *ds, int port,
> +			 struct dsa_mall_mirror_tc_entry *mirror)
> +{
> +	struct ksz_device *dev = ds->priv;
> +
> +	if (dev->dev_ops->mirror_del)
> +		dev->dev_ops->mirror_del(dev, port, mirror);
> +}
> +EXPORT_SYMBOL_GPL(ksz_port_mirror_del);
> +
>  static int ksz_switch_detect(struct ksz_device *dev)
>  {
>  	u8 id1, id2;
> diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
> index 03e738c0cbb8..01080ec22bf1 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -187,6 +187,11 @@ struct ksz_dev_ops {
>  			 struct netlink_ext_ack *extack);
>  	int  (*vlan_del)(struct ksz_device *dev, int port,
>  			 const struct switchdev_obj_port_vlan *vlan);
> +	int (*mirror_add)(struct ksz_device *dev, int port,
> +			  struct dsa_mall_mirror_tc_entry *mirror,
> +			  bool ingress, struct netlink_ext_ack *extack);
> +	void (*mirror_del)(struct ksz_device *dev, int port,
> +			   struct dsa_mall_mirror_tc_entry *mirror);
>  	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
>  	void (*port_init_cnt)(struct ksz_device *dev, int port);
>  	int (*shutdown)(struct ksz_device *dev);
> @@ -247,6 +252,11 @@ int ksz_port_vlan_add(struct dsa_switch *ds, int port,
>  		      struct netlink_ext_ack *extack);
>  int ksz_port_vlan_del(struct dsa_switch *ds, int port,
>  		      const struct switchdev_obj_port_vlan *vlan);
> +int ksz_port_mirror_add(struct dsa_switch *ds, int port,
> +			struct dsa_mall_mirror_tc_entry *mirror,
> +			bool ingress, struct netlink_ext_ack *extack);
> +void ksz_port_mirror_del(struct dsa_switch *ds, int port,
> +			 struct dsa_mall_mirror_tc_entry *mirror);
>  
>  /* Common register access functions */
>  
> -- 
> 2.36.1
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 06/15] net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by ksz_dev_ops
  2022-05-30 10:42 ` [RFC Patch net-next v2 06/15] net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by ksz_dev_ops Arun Ramadoss
@ 2022-06-13  9:31   ` Vladimir Oltean
  2022-06-15  6:49     ` Arun.Ramadoss
  0 siblings, 1 reply; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-13  9:31 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:48PM +0530, Arun Ramadoss wrote:
> At present, P_STP_CTRL register value is passed as parameter to
> ksz_port_stp_state from the individual dsa_switch_ops hooks. This patch
> update the function to retrieve the register value through the
> ksz_dev_ops function pointer.
> And add the static to ksz_update_port_member since it is not called
> outside the ksz_common.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---
>  drivers/net/dsa/microchip/ksz8795.c    |  9 +++++----
>  drivers/net/dsa/microchip/ksz9477.c    | 10 +++++-----
>  drivers/net/dsa/microchip/ksz_common.c |  9 +++++----
>  drivers/net/dsa/microchip/ksz_common.h |  5 ++---
>  4 files changed, 17 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 8657b520b336..e6982fa9d382 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -920,9 +920,9 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
>  	ksz_pwrite8(dev, port, P_MIRROR_CTRL, data);
>  }
>  
> -static void ksz8_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
> +static int ksz8_get_stp_reg(void)
>  {
> -	ksz_port_stp_state_set(ds, port, state, P_STP_CTRL);
> +	return P_STP_CTRL;
>  }

Since there's nothing dynamic about get_stp_reg(), can the STP register
location stay in struct ksz_chip_data?

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 07/15] net: dsa: microchip: update the ksz_phylink_get_caps
  2022-05-30 10:42 ` [RFC Patch net-next v2 07/15] net: dsa: microchip: update the ksz_phylink_get_caps Arun Ramadoss
@ 2022-06-13  9:32   ` Vladimir Oltean
  0 siblings, 0 replies; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-13  9:32 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:49PM +0530, Arun Ramadoss wrote:
> This patch assigns the phylink_get_caps in ksz8795 and ksz9477 to
> ksz_phylink_get_caps. And update their mac_capabilities in the
> respective ksz_dev_ops.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 08/15] net: dsa: microchip: update the ksz_port_mdb_add/del
  2022-05-30 10:42 ` [RFC Patch net-next v2 08/15] net: dsa: microchip: update the ksz_port_mdb_add/del Arun Ramadoss
@ 2022-06-13  9:36   ` Vladimir Oltean
  0 siblings, 0 replies; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-13  9:36 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:50PM +0530, Arun Ramadoss wrote:
> ksz_mdb_add/del in ksz_common.c is specific for the ksz8795.c file. The

ksz_port_mdb_add

> ksz9477 has its separate ksz9477_port_mdb_add/del functions.  This patch
> moves the ksz8795 specific mdb functionality from ksz_common to ksz8795.
> And this dsa_switch_ops hooks for ksz8795/ksz9477 are invoked through
> the ksz_port_mdb_add/del.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 09/15] net: dsa: microchip: update fdb add/del/dump in ksz_common
  2022-05-30 10:42 ` [RFC Patch net-next v2 09/15] net: dsa: microchip: update fdb add/del/dump in ksz_common Arun Ramadoss
@ 2022-06-13  9:42   ` Vladimir Oltean
  2022-06-15  6:57     ` Arun.Ramadoss
  0 siblings, 1 reply; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-13  9:42 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:51PM +0530, Arun Ramadoss wrote:
> This patch makes the dsa_switch_hook for fdbs to use ksz_common.c file.
> And from ksz_common, individual switches fdb functions are called using
> the dev->dev_ops.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---

I had to jump ahead and look at the other patches to see if you plan on
doing anything about the r_dyn_mac_table, r_sta_mac_table, w_sta_mac_table
dev_ops which are only implemented for ksz8. They become redundant when
you introduce new dev_ops for the entire FDB dump, add, del procedure.

I see those aren't touched - what's the plan there?

>  drivers/net/dsa/microchip/ksz8795.c    | 30 +++++++++++++++
>  drivers/net/dsa/microchip/ksz9477.c    | 28 +++++++-------
>  drivers/net/dsa/microchip/ksz_common.c | 52 +++++++++++++++-----------
>  drivers/net/dsa/microchip/ksz_common.h | 10 +++++
>  4 files changed, 84 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index abd28dc44eb5..528de481b319 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -958,6 +958,35 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
>  	}
>  }
>  
> +static int ksz8_fdb_dump(struct ksz_device *dev, int port,
> +			 dsa_fdb_dump_cb_t *cb, void *data)
> +{
> +	int ret = 0;
> +	u16 i = 0;
> +	u16 entries = 0;
> +	u8 timestamp = 0;
> +	u8 fid;
> +	u8 member;
> +	struct alu_struct alu;
> +
> +	do {
> +		alu.is_static = false;
> +		ret = dev->dev_ops->r_dyn_mac_table(dev, i, alu.mac, &fid,
> +						    &member, &timestamp,
> +						    &entries);
> +		if (!ret && (member & BIT(port))) {
> +			ret = cb(alu.mac, alu.fid, alu.is_static, data);
> +			if (ret)
> +				break;
> +		}
> +		i++;
> +	} while (i < entries);
> +	if (i >= entries)
> +		ret = 0;
> +
> +	return ret;
> +}
> +
>  static int ksz8_mdb_add(struct ksz_device *dev, int port,
>  			const struct switchdev_obj_port_mdb *mdb,
>  			struct dsa_db db)
> @@ -1528,6 +1557,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
>  	.r_mib_pkt = ksz8_r_mib_pkt,
>  	.freeze_mib = ksz8_freeze_mib,
>  	.port_init_cnt = ksz8_port_init_cnt,
> +	.fdb_dump = ksz8_fdb_dump,
>  	.mdb_add = ksz8_mdb_add,
>  	.mdb_del = ksz8_mdb_del,
>  	.vlan_filtering = ksz8_port_vlan_filtering,
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index 045856656466..d70e0c32b309 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -457,11 +457,10 @@ static int ksz9477_port_vlan_del(struct ksz_device *dev, int port,
>  	return 0;
>  }
>  
> -static int ksz9477_port_fdb_add(struct dsa_switch *ds, int port,
> -				const unsigned char *addr, u16 vid,
> -				struct dsa_db db)
> +static int ksz9477_fdb_add(struct ksz_device *dev, int port,
> +			   const unsigned char *addr, u16 vid,
> +			   struct dsa_db db)
>  {
> -	struct ksz_device *dev = ds->priv;
>  	u32 alu_table[4];
>  	u32 data;
>  	int ret = 0;
> @@ -515,11 +514,10 @@ static int ksz9477_port_fdb_add(struct dsa_switch *ds, int port,
>  	return ret;
>  }
>  
> -static int ksz9477_port_fdb_del(struct dsa_switch *ds, int port,
> -				const unsigned char *addr, u16 vid,
> -				struct dsa_db db)
> +static int ksz9477_fdb_del(struct ksz_device *dev, int port,
> +			   const unsigned char *addr, u16 vid,
> +			   struct dsa_db db)
>  {
> -	struct ksz_device *dev = ds->priv;
>  	u32 alu_table[4];
>  	u32 data;
>  	int ret = 0;
> @@ -606,10 +604,9 @@ static void ksz9477_convert_alu(struct alu_struct *alu, u32 *alu_table)
>  	alu->mac[5] = alu_table[3] & 0xFF;
>  }
>  
> -static int ksz9477_port_fdb_dump(struct dsa_switch *ds, int port,
> -				 dsa_fdb_dump_cb_t *cb, void *data)
> +static int ksz9477_fdb_dump(struct ksz_device *dev, int port,
> +			    dsa_fdb_dump_cb_t *cb, void *data)
>  {
> -	struct ksz_device *dev = ds->priv;
>  	int ret = 0;
>  	u32 ksz_data;
>  	u32 alu_table[4];
> @@ -1315,9 +1312,9 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
>  	.port_vlan_filtering	= ksz_port_vlan_filtering,
>  	.port_vlan_add		= ksz_port_vlan_add,
>  	.port_vlan_del		= ksz_port_vlan_del,
> -	.port_fdb_dump		= ksz9477_port_fdb_dump,
> -	.port_fdb_add		= ksz9477_port_fdb_add,
> -	.port_fdb_del		= ksz9477_port_fdb_del,
> +	.port_fdb_dump		= ksz_port_fdb_dump,
> +	.port_fdb_add		= ksz_port_fdb_add,
> +	.port_fdb_del		= ksz_port_fdb_del,
>  	.port_mdb_add           = ksz_port_mdb_add,
>  	.port_mdb_del           = ksz_port_mdb_del,
>  	.port_mirror_add	= ksz_port_mirror_add,
> @@ -1403,6 +1400,9 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
>  	.mirror_del = ksz9477_port_mirror_del,
>  	.get_stp_reg = ksz9477_get_stp_reg,
>  	.get_caps = ksz9477_get_caps,
> +	.fdb_dump = ksz9477_fdb_dump,
> +	.fdb_add = ksz9477_fdb_add,
> +	.fdb_del = ksz9477_fdb_del,
>  	.mdb_add = ksz9477_mdb_add,
>  	.mdb_del = ksz9477_mdb_del,
>  	.shutdown = ksz9477_reset_switch,
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index b9082952db0f..8f79ff1ac648 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -765,32 +765,40 @@ void ksz_port_fast_age(struct dsa_switch *ds, int port)
>  }
>  EXPORT_SYMBOL_GPL(ksz_port_fast_age);
>  
> +int ksz_port_fdb_add(struct dsa_switch *ds, int port,
> +		     const unsigned char *addr, u16 vid, struct dsa_db db)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	int ret = -EOPNOTSUPP;
> +
> +	if (dev->dev_ops->fdb_add)
> +		ret = dev->dev_ops->fdb_add(dev, port, addr, vid, db);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(ksz_port_fdb_add);
> +
> +int ksz_port_fdb_del(struct dsa_switch *ds, int port,
> +		     const unsigned char *addr, u16 vid, struct dsa_db db)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	int ret = -EOPNOTSUPP;
> +
> +	if (dev->dev_ops->fdb_del)
> +		ret = dev->dev_ops->fdb_del(dev, port, addr, vid, db);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(ksz_port_fdb_del);
> +
>  int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
>  		      void *data)
>  {
>  	struct ksz_device *dev = ds->priv;
> -	int ret = 0;
> -	u16 i = 0;
> -	u16 entries = 0;
> -	u8 timestamp = 0;
> -	u8 fid;
> -	u8 member;
> -	struct alu_struct alu;
> -
> -	do {
> -		alu.is_static = false;
> -		ret = dev->dev_ops->r_dyn_mac_table(dev, i, alu.mac, &fid,
> -						    &member, &timestamp,
> -						    &entries);
> -		if (!ret && (member & BIT(port))) {
> -			ret = cb(alu.mac, alu.fid, alu.is_static, data);
> -			if (ret)
> -				break;
> -		}
> -		i++;
> -	} while (i < entries);
> -	if (i >= entries)
> -		ret = 0;
> +	int ret = -EOPNOTSUPP;
> +
> +	if (dev->dev_ops->fdb_dump)
> +		ret = dev->dev_ops->fdb_dump(dev, port, cb, data);
>  
>  	return ret;
>  }
> diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
> index 816581dd7f8e..133b1a257868 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -192,6 +192,12 @@ struct ksz_dev_ops {
>  			  bool ingress, struct netlink_ext_ack *extack);
>  	void (*mirror_del)(struct ksz_device *dev, int port,
>  			   struct dsa_mall_mirror_tc_entry *mirror);
> +	int (*fdb_add)(struct ksz_device *dev, int port,
> +		       const unsigned char *addr, u16 vid, struct dsa_db db);
> +	int (*fdb_del)(struct ksz_device *dev, int port,
> +		       const unsigned char *addr, u16 vid, struct dsa_db db);
> +	int (*fdb_dump)(struct ksz_device *dev, int port,
> +			dsa_fdb_dump_cb_t *cb, void *data);
>  	int (*mdb_add)(struct ksz_device *dev, int port,
>  		       const struct switchdev_obj_port_mdb *mdb,
>  		       struct dsa_db db);
> @@ -239,6 +245,10 @@ void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
>  			   struct dsa_bridge bridge);
>  void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
>  void ksz_port_fast_age(struct dsa_switch *ds, int port);
> +int ksz_port_fdb_add(struct dsa_switch *ds, int port,
> +		     const unsigned char *addr, u16 vid, struct dsa_db db);
> +int ksz_port_fdb_del(struct dsa_switch *ds, int port,
> +		     const unsigned char *addr, u16 vid, struct dsa_db db);
>  int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
>  		      void *data);
>  int ksz_port_mdb_add(struct dsa_switch *ds, int port,
> -- 
> 2.36.1
> 

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 02/15] net: dsa: microchip: move switch chip_id detection to ksz_common
  2022-06-13  9:18   ` Vladimir Oltean
@ 2022-06-14  7:10     ` Arun.Ramadoss
  0 siblings, 0 replies; 35+ messages in thread
From: Arun.Ramadoss @ 2022-06-14  7:10 UTC (permalink / raw)
  To: olteanv
  Cc: andrew, linux-kernel, UNGLinuxDriver, vivien.didelot, linux,
	f.fainelli, kuba, edumazet, pabeni, netdev, Woojung.Huh, davem

Hi Vladimir,
Thanks for the comment. 

On Mon, 2022-06-13 at 12:18 +0300, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> On Mon, May 30, 2022 at 04:12:44PM +0530, Arun Ramadoss wrote:
> > KSZ87xx and KSZ88xx have chip_id representation at reg location 0.
> > And
> > KSZ9477 compatible switch and LAN937x switch have same chip_id
> > detection
> > at location 0x01 and 0x02. To have the common switch detect
> > functionality for ksz switches, ksz_switch_detect function is
> > introduced.
> > 
> > Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> > ---
> >  drivers/net/dsa/microchip/ksz8795.c     | 46 ---------------
> >  drivers/net/dsa/microchip/ksz8795_reg.h | 13 -----
> >  drivers/net/dsa/microchip/ksz9477.c     | 21 -------
> >  drivers/net/dsa/microchip/ksz9477_reg.h |  1 -
> >  drivers/net/dsa/microchip/ksz_common.c  | 78
> > +++++++++++++++++++++++--
> >  drivers/net/dsa/microchip/ksz_common.h  | 19 +++++-
> >  6 files changed, 92 insertions(+), 86 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz8795.c
> > b/drivers/net/dsa/microchip/ksz8795.c
> > index 12a599d5e61a..927db57d02db 100644
> > --- a/drivers/net/dsa/microchip/ksz8795.c
> > +++ b/drivers/net/dsa/microchip/ksz8795.c
> > @@ -1424,51 +1424,6 @@ static u32 ksz8_get_port_addr(int port, int
> > offset)
> >       return PORT_CTRL_ADDR(port, offset);
> >  }
> > 
> > -static int ksz8_switch_detect(struct ksz_device *dev)
> > -{
> > -     u8 id1, id2;
> > -     u16 id16;
> > -     int ret;
> > -
> > -     /* read chip id */
> > -     ret = ksz_read16(dev, REG_CHIP_ID0, &id16);
> > -     if (ret)
> > -             return ret;
> > -
> > -     id1 = id16 >> 8;
> > -     id2 = id16 & SW_CHIP_ID_M;
> > -
> > -     switch (id1) {
> > -     case KSZ87_FAMILY_ID:
> > -             if ((id2 != CHIP_ID_94 && id2 != CHIP_ID_95))
> > -                     return -ENODEV;
> > -
> > -             if (id2 == CHIP_ID_95) {
> > -                     u8 val;
> > -
> > -                     id2 = 0x95;
> > -                     ksz_read8(dev, REG_PORT_STATUS_0, &val);
> 
> Could you replace all remaining occurrences of REG_PORT_STATUS_0 and
> PORT_FIBER_MODE with KSZ8_PORT_STATUS_0 and KSZ8_PORT_FIBER_MODE?
> It would be good to not have multiple definitions for the same thing.

Ok. I will update the macro unique for KSZ8 Switches.

> > -                     if (val & PORT_FIBER_MODE)
> > -                             id2 = 0x65;
> > -             } else if (id2 == CHIP_ID_94) {
> > -                     id2 = 0x94;
> > -             }
> > -             break;
> > -     case KSZ88_FAMILY_ID:
> > -             if (id2 != CHIP_ID_63)
> > -                     return -ENODEV;
> > -             break;
> > -     default:
> > -             dev_err(dev->dev, "invalid family id: %d\n", id1);
> > -             return -ENODEV;
> > -     }
> > -     id16 &= ~0xff;
> > -     id16 |= id2;
> > -     dev->chip_id = id16;
> > -
> > -     return 0;
> > -}
> > -
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h
> > b/drivers/net/dsa/microchip/ksz8795_reg.h
> > index 4109433b6b6c..50cdc2a09f5a 100644
> > --- a/drivers/net/dsa/microchip/ksz8795_reg.h
> > +++ b/drivers/net/dsa/microchip/ksz8795_reg.h
> > @@ -14,23 +14,10 @@
> >  #define KS_PRIO_M                    0x3
> >  #define KS_PRIO_S                    2
> > 
> > -#define REG_CHIP_ID0                 0x00
> > -
> > -#define KSZ87_FAMILY_ID                      0x87
> > -#define KSZ88_FAMILY_ID                      0x88
> > -
> > -#define REG_CHIP_ID1                 0x01
> > -
> > -#define SW_CHIP_ID_M                 0xF0
> > -#define SW_CHIP_ID_S                 4
> >  #define SW_REVISION_M                        0x0E
> >  #define SW_REVISION_S                        1
> >  #define SW_START                     0x01
> > 
> > -#define CHIP_ID_94                   0x60
> > -#define CHIP_ID_95                   0x90
> > -#define CHIP_ID_63                   0x30
> > -
> >  #define KSZ8863_REG_SW_RESET         0x43
> > 
> >  #define KSZ8863_GLOBAL_SOFTWARE_RESET        BIT(4)
> > diff --git a/drivers/net/dsa/microchip/ksz9477.c
> > b/drivers/net/dsa/microchip/ksz9477.c
> > index 7afc06681c02..7d3c8f6908b6 100644
> > --- a/drivers/net/dsa/microchip/ksz9477.c
> > +++ b/drivers/net/dsa/microchip/ksz9477.c
> > @@ -1360,23 +1360,6 @@ static u32 ksz9477_get_port_addr(int port,
> > int offset)
> >       return PORT_CTRL_ADDR(port, offset);
> >  }
> > 
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz9477_reg.h
> > b/drivers/net/dsa/microchip/ksz9477_reg.h
> > index 7a2c8d4767af..077e35ab11b5 100644
> > --- a/drivers/net/dsa/microchip/ksz9477_reg.h
> > +++ b/drivers/net/dsa/microchip/ksz9477_reg.h
> > @@ -25,7 +25,6 @@
> > 
> >  #define REG_CHIP_ID2__1                      0x0002
> > 
> > -#define CHIP_ID_63                   0x63
> >  #define CHIP_ID_66                   0x66
> >  #define CHIP_ID_67                   0x67
> >  #define CHIP_ID_77                   0x77
> > diff --git a/drivers/net/dsa/microchip/ksz_common.c
> > b/drivers/net/dsa/microchip/ksz_common.c
> > index 9ca8c8d7740f..9057cdb5971c 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.c
> > +++ b/drivers/net/dsa/microchip/ksz_common.c
> > @@ -930,6 +930,72 @@ void ksz_port_stp_state_set(struct dsa_switch
> > *ds, int port,
> >  }
> >  EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
> > 
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz_common.h
> > b/drivers/net/dsa/microchip/ksz_common.h
> > index 8500eaedad67..d16c095cdefb 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.h
> > +++ b/drivers/net/dsa/microchip/ksz_common.h
> > @@ -90,6 +90,7 @@ struct ksz_device {
> > 
> >       /* chip specific data */
> >       u32 chip_id;
> > +     u8 chip_rev;
> >       int cpu_port;                   /* port connected to CPU */
> >       int phy_port_cnt;
> >       phy_interface_t compat_interface;
> > @@ -182,7 +183,6 @@ struct ksz_dev_ops {
> >       void (*freeze_mib)(struct ksz_device *dev, int port, bool
> > freeze);
> >       void (*port_init_cnt)(struct ksz_device *dev, int port);
> >       int (*shutdown)(struct ksz_device *dev);
> > -     int (*detect)(struct ksz_device *dev);
> >       int (*init)(struct ksz_device *dev);
> >       void (*exit)(struct ksz_device *dev);
> >  };
> > @@ -353,6 +353,23 @@ static inline void ksz_regmap_unlock(void
> > *__mtx)
> >  #define PORT_RX_ENABLE                       BIT(1)
> >  #define PORT_LEARN_DISABLE           BIT(0)
> > 
> > +/* Switch ID Defines */
> > +#define REG_CHIP_ID0                 0x00
> > +
> > +#define SW_FAMILY_ID_M                       GENMASK(15, 8)
> > +#define KSZ87_FAMILY_ID                      0x87
> > +#define KSZ88_FAMILY_ID                      0x88
> > +
> > +#define KSZ8_PORT_STATUS_0           0x08
> > +#define KSZ8_PORT_FIBER_MODE         BIT(7)
> > +
> > +#define SW_CHIP_ID_M                 GENMASK(7, 4)
> > +#define CHIP_ID_94                   0x6
> > +#define CHIP_ID_95                   0x9
> 
> KSZ87_CHIP_ID_xxx maybe?

Ok. I will update.

> 
> > +#define CHIP_ID_63                   0x3
> 
> And KSZ88_CHIP_ID_63.

I will rename it this. 

> 
> > +
> > +#define SW_REV_ID_M                  GENMASK(7, 4)
> > +
> >  /* Regmap tables generation */
> >  #define KSZ_SPI_OP_RD                3
> >  #define KSZ_SPI_OP_WR                2
> > --
> > 2.36.1
> > 
> 
> 

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 10/15] net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common
  2022-05-30 10:42 ` [RFC Patch net-next v2 10/15] net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common Arun Ramadoss
@ 2022-06-14  8:15   ` Vladimir Oltean
  2022-06-15  8:36     ` Arun.Ramadoss
  0 siblings, 1 reply; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-14  8:15 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:52PM +0530, Arun Ramadoss wrote:
> This patch assigns the .setup, get_phy_flags & mtu  hook of ksz8795 and
> ksz9477 in dsa_switch_ops to ksz_common. And the individual switches
> setup implementations are called based on the ksz_dev_ops.  For
> get_phy_flags hooks,checks whether the chip is ksz8863/kss8793 then it
> returns error for port1.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---
>  drivers/net/dsa/microchip/ksz8795.c    | 17 ++-------
>  drivers/net/dsa/microchip/ksz9477.c    | 14 ++++----
>  drivers/net/dsa/microchip/ksz_common.c | 50 ++++++++++++++++++++++++++
>  drivers/net/dsa/microchip/ksz_common.h |  7 ++++
>  4 files changed, 68 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 528de481b319..1058b6883caa 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -898,18 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
>  	}
>  }
>  
> -static u32 ksz8_sw_get_phy_flags(struct dsa_switch *ds, int port)
> -{
> -	/* Silicon Errata Sheet (DS80000830A):
> -	 * Port 1 does not work with LinkMD Cable-Testing.
> -	 * Port 1 does not respond to received PAUSE control frames.
> -	 */
> -	if (!port)
> -		return MICREL_KSZ8_P1_ERRATA;
> -
> -	return 0;
> -}
> -
>  static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
>  {
>  	u8 data;
> @@ -1476,8 +1464,8 @@ static void ksz8_get_caps(struct ksz_device *dev, int port,
>  
>  static const struct dsa_switch_ops ksz8_switch_ops = {
>  	.get_tag_protocol	= ksz_get_tag_protocol,
> -	.get_phy_flags		= ksz8_sw_get_phy_flags,
> -	.setup			= ksz8_setup,
> +	.get_phy_flags		= ksz_get_phy_flags,
> +	.setup			= ksz_setup,
>  	.phy_read		= ksz_phy_read16,
>  	.phy_write		= ksz_phy_write16,
>  	.phylink_get_caps	= ksz_phylink_get_caps,
> @@ -1544,6 +1532,7 @@ static void ksz8_switch_exit(struct ksz_device *dev)
>  }
>  
>  static const struct ksz_dev_ops ksz8_dev_ops = {
> +	.setup = ksz8_setup,
>  	.get_port_addr = ksz8_get_port_addr,
>  	.cfg_port_member = ksz8_cfg_port_member,
>  	.flush_dyn_mac_table = ksz8_flush_dyn_mac_table,
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index d70e0c32b309..d7474d9d4384 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -47,9 +47,8 @@ static void ksz9477_port_cfg32(struct ksz_device *dev, int port, int offset,
>  			   bits, set ? bits : 0);
>  }
>  
> -static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu)
> +static int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu)
>  {
> -	struct ksz_device *dev = ds->priv;
>  	u16 frame_size, max_frame = 0;
>  	int i;
>  
> @@ -65,7 +64,7 @@ static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu)
>  				  REG_SW_MTU_MASK, max_frame);
>  }
>  
> -static int ksz9477_max_mtu(struct dsa_switch *ds, int port)
> +static int ksz9477_max_mtu(struct ksz_device *dev, int port)
>  {
>  	return KSZ9477_MAX_FRAME_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN;
>  }
> @@ -1296,7 +1295,7 @@ static int ksz9477_setup(struct dsa_switch *ds)
>  
>  static const struct dsa_switch_ops ksz9477_switch_ops = {
>  	.get_tag_protocol	= ksz_get_tag_protocol,
> -	.setup			= ksz9477_setup,
> +	.setup			= ksz_setup,
>  	.phy_read		= ksz_phy_read16,
>  	.phy_write		= ksz_phy_write16,
>  	.phylink_mac_link_down	= ksz_mac_link_down,
> @@ -1320,8 +1319,8 @@ static const struct dsa_switch_ops ksz9477_switch_ops = {
>  	.port_mirror_add	= ksz_port_mirror_add,
>  	.port_mirror_del	= ksz_port_mirror_del,
>  	.get_stats64		= ksz_get_stats64,
> -	.port_change_mtu	= ksz9477_change_mtu,
> -	.port_max_mtu		= ksz9477_max_mtu,
> +	.port_change_mtu	= ksz_change_mtu,
> +	.port_max_mtu		= ksz_max_mtu,
>  };
>  
>  static u32 ksz9477_get_port_addr(int port, int offset)
> @@ -1382,6 +1381,7 @@ static void ksz9477_switch_exit(struct ksz_device *dev)
>  }
>  
>  static const struct ksz_dev_ops ksz9477_dev_ops = {
> +	.setup = ksz9477_setup,
>  	.get_port_addr = ksz9477_get_port_addr,
>  	.cfg_port_member = ksz9477_cfg_port_member,
>  	.flush_dyn_mac_table = ksz9477_flush_dyn_mac_table,
> @@ -1405,6 +1405,8 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
>  	.fdb_del = ksz9477_fdb_del,
>  	.mdb_add = ksz9477_mdb_add,
>  	.mdb_del = ksz9477_mdb_del,
> +	.change_mtu = ksz9477_change_mtu,
> +	.max_mtu = ksz9477_max_mtu,
>  	.shutdown = ksz9477_reset_switch,
>  	.init = ksz9477_switch_init,
>  	.exit = ksz9477_switch_exit,
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index 8f79ff1ac648..19f8e492d3aa 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -16,6 +16,7 @@
>  #include <linux/if_bridge.h>
>  #include <linux/of_device.h>
>  #include <linux/of_net.h>
> +#include <linux/micrel_phy.h>
>  #include <net/dsa.h>
>  #include <net/switchdev.h>
>  
> @@ -593,6 +594,14 @@ static void ksz_update_port_member(struct ksz_device *dev, int port)
>  	dev->dev_ops->cfg_port_member(dev, port, port_member | cpu_port);
>  }
>  
> +int ksz_setup(struct dsa_switch *ds)
> +{
> +	struct ksz_device *dev = ds->priv;
> +
> +	return dev->dev_ops->setup(ds);
> +}
> +EXPORT_SYMBOL_GPL(ksz_setup);

I see these changes as being of questionable value if you do not plan to
actually share some code between ->setup implementations. What would be
desirable is if ksz_common.c decides what to do, and ksz8795.c /
ksz9477.c only offer the implementations for fine-grained dev_ops.
Currently there is code that can be reused between the setup functions
of the 2 drivers, but also there is some divergence in configuration
which doesn't have its place (10% rate limit for broadcast storm
protection in ksz8795?). The goal should be for individual switch
drivers to not apply configuration behind the curtains as much as possible.

> +
>  static void port_r_cnt(struct ksz_device *dev, int port)
>  {
>  	struct ksz_port_mib *mib = &dev->ports[port].mib;
> @@ -692,6 +701,23 @@ int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
>  }
>  EXPORT_SYMBOL_GPL(ksz_phy_write16);
>  
> +u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
> +{
> +	struct ksz_device *dev = ds->priv;
> +
> +	if (dev->chip_id == KSZ8830_CHIP_ID) {
> +		/* Silicon Errata Sheet (DS80000830A):
> +		 * Port 1 does not work with LinkMD Cable-Testing.
> +		 * Port 1 does not respond to received PAUSE control frames.
> +		 */
> +		if (!port)
> +			return MICREL_KSZ8_P1_ERRATA;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(ksz_get_phy_flags);
> +
>  void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
>  		       phy_interface_t interface)
>  {
> @@ -981,6 +1007,30 @@ void ksz_port_mirror_del(struct dsa_switch *ds, int port,
>  }
>  EXPORT_SYMBOL_GPL(ksz_port_mirror_del);
>  
> +int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	int ret = -EOPNOTSUPP;
> +
> +	if (dev->dev_ops->change_mtu)
> +		ret = dev->dev_ops->change_mtu(dev, port, mtu);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(ksz_change_mtu);
> +
> +int ksz_max_mtu(struct dsa_switch *ds, int port)
> +{
> +	struct ksz_device *dev = ds->priv;
> +	int ret = -EOPNOTSUPP;
> +
> +	if (dev->dev_ops->max_mtu)
> +		ret = dev->dev_ops->max_mtu(dev, port);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(ksz_max_mtu);
> +
>  static int ksz_switch_detect(struct ksz_device *dev)
>  {
>  	u8 id1, id2;
> diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
> index 133b1a257868..f7275c4f633a 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -161,6 +161,7 @@ struct alu_struct {
>  };
>  
>  struct ksz_dev_ops {
> +	int (*setup)(struct dsa_switch *ds);
>  	u32 (*get_port_addr)(int port, int offset);
>  	void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
>  	void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
> @@ -207,6 +208,8 @@ struct ksz_dev_ops {
>  	int (*get_stp_reg)(void);
>  	void (*get_caps)(struct ksz_device *dev, int port,
>  			 struct phylink_config *config);
> +	int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
> +	int (*max_mtu)(struct ksz_device *dev, int port);
>  	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
>  	void (*port_init_cnt)(struct ksz_device *dev, int port);
>  	int (*shutdown)(struct ksz_device *dev);
> @@ -232,8 +235,10 @@ extern const struct ksz_chip_data ksz_switch_chips[];
>  
>  /* Common DSA access functions */
>  
> +int ksz_setup(struct dsa_switch *ds);
>  int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg);
>  int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val);
> +u32 ksz_get_phy_flags(struct dsa_switch *ds, int port);
>  void ksz_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
>  		       phy_interface_t interface);
>  int ksz_sset_count(struct dsa_switch *ds, int port, int sset);
> @@ -274,6 +279,8 @@ int ksz_port_mirror_add(struct dsa_switch *ds, int port,
>  			bool ingress, struct netlink_ext_ack *extack);
>  void ksz_port_mirror_del(struct dsa_switch *ds, int port,
>  			 struct dsa_mall_mirror_tc_entry *mirror);
> +int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu);
> +int ksz_max_mtu(struct dsa_switch *ds, int port);
>  
>  /* Common register access functions */
>  
> -- 
> 2.36.1
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register
  2022-05-30 10:42 ` [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register Arun Ramadoss
@ 2022-06-14  8:24   ` Vladimir Oltean
  2022-06-15  8:49     ` Arun.Ramadoss
  0 siblings, 1 reply; 35+ messages in thread
From: Vladimir Oltean @ 2022-06-14  8:24 UTC (permalink / raw)
  To: Arun Ramadoss
  Cc: linux-kernel, netdev, Woojung Huh, UNGLinuxDriver, Andrew Lunn,
	Vivien Didelot, Florian Fainelli, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Russell King

On Mon, May 30, 2022 at 04:12:54PM +0530, Arun Ramadoss wrote:
> As per 'commit 3506b2f42dff ("net: dsa: microchip: call
> phy_remove_link_mode during probe")' phy_remove_link_mode is added in
> the switch_register function after dsa_switch_register. In order to have
> the common switch register function, moving this phy init after
> dsa_register_switch using the new ksz_dev_ops.dsa_init hook.
> 
> Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> ---
>  drivers/net/dsa/microchip/ksz9477.c    | 49 ++++++++++++++------------
>  drivers/net/dsa/microchip/ksz_common.c |  5 ++-
>  drivers/net/dsa/microchip/ksz_common.h |  1 +
>  3 files changed, 31 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index ecce99b77ef6..c87ce0e2afd8 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -1349,6 +1349,30 @@ static void ksz9477_switch_exit(struct ksz_device *dev)
>  	ksz9477_reset_switch(dev);
>  }
>  
> +static int ksz9477_dsa_init(struct ksz_device *dev)
> +{
> +	struct phy_device *phydev;
> +	int i;
> +
> +	for (i = 0; i < dev->phy_port_cnt; ++i) {
> +		if (!dsa_is_user_port(dev->ds, i))
> +			continue;

I understand this is just code movement, but this is more efficient:

	struct dsa_switch *ds = dev->ds;
	struct dsa_port *dp;

	dsa_switch_for_each_user_port(dp, ds) {
		...
	}

> +
> +		phydev = dsa_to_port(dev->ds, i)->slave->phydev;
> +
> +		/* The MAC actually cannot run in 1000 half-duplex mode. */
> +		phy_remove_link_mode(phydev,
> +				     ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
> +
> +		/* PHY does not support gigabit. */
> +		if (!(dev->features & GBIT_SUPPORT))
> +			phy_remove_link_mode(phydev,
> +					     ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
> +	}

I wonder why the driver did not just remove these from the supported
mask in the phylink validation procedure in the first place?
Adding these link mode fixups to a dev_ops callback named "dsa_init"
does not sound quite right.

> +
> +	return 0;
> +}
> +
>  static const struct ksz_dev_ops ksz9477_dev_ops = {
>  	.setup = ksz9477_setup,
>  	.get_port_addr = ksz9477_get_port_addr,
> @@ -1377,35 +1401,14 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
>  	.change_mtu = ksz9477_change_mtu,
>  	.max_mtu = ksz9477_max_mtu,
>  	.shutdown = ksz9477_reset_switch,
> +	.dsa_init = ksz9477_dsa_init,
>  	.init = ksz9477_switch_init,
>  	.exit = ksz9477_switch_exit,
>  };
>  
>  int ksz9477_switch_register(struct ksz_device *dev)
>  {
> -	int ret, i;
> -	struct phy_device *phydev;
> -
> -	ret = ksz_switch_register(dev, &ksz9477_dev_ops);
> -	if (ret)
> -		return ret;
> -
> -	for (i = 0; i < dev->phy_port_cnt; ++i) {
> -		if (!dsa_is_user_port(dev->ds, i))
> -			continue;
> -
> -		phydev = dsa_to_port(dev->ds, i)->slave->phydev;
> -
> -		/* The MAC actually cannot run in 1000 half-duplex mode. */
> -		phy_remove_link_mode(phydev,
> -				     ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
> -
> -		/* PHY does not support gigabit. */
> -		if (!(dev->features & GBIT_SUPPORT))
> -			phy_remove_link_mode(phydev,
> -					     ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
> -	}
> -	return ret;
> +	return ksz_switch_register(dev, &ksz9477_dev_ops);
>  }
>  EXPORT_SYMBOL(ksz9477_switch_register);
>  
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index ace5cf0ad5a8..f40d64858d35 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -1253,7 +1253,10 @@ int ksz_switch_register(struct ksz_device *dev,
>  	/* Start the MIB timer. */
>  	schedule_delayed_work(&dev->mib_read, 0);
>  
> -	return 0;
> +	if (dev->dev_ops->dsa_init)
> +		ret = dev->dev_ops->dsa_init(dev);
> +
> +	return ret;
>  }
>  EXPORT_SYMBOL(ksz_switch_register);
>  
> diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
> index 872d378ac45c..23962f47df46 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -213,6 +213,7 @@ struct ksz_dev_ops {
>  	void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
>  	void (*port_init_cnt)(struct ksz_device *dev, int port);
>  	int (*shutdown)(struct ksz_device *dev);
> +	int (*dsa_init)(struct ksz_device *dev);
>  	int (*init)(struct ksz_device *dev);
>  	void (*exit)(struct ksz_device *dev);
>  };
> -- 
> 2.36.1
> 


^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 03/15] net: dsa: microchip: move tag_protocol & phy read/write to ksz_common
  2022-06-13  9:22   ` Vladimir Oltean
@ 2022-06-15  6:36     ` Arun.Ramadoss
  0 siblings, 0 replies; 35+ messages in thread
From: Arun.Ramadoss @ 2022-06-15  6:36 UTC (permalink / raw)
  To: olteanv
  Cc: andrew, linux-kernel, UNGLinuxDriver, vivien.didelot, linux,
	f.fainelli, kuba, edumazet, pabeni, netdev, Woojung.Huh, davem

On Mon, 2022-06-13 at 12:22 +0300, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> On Mon, May 30, 2022 at 04:12:45PM +0530, Arun Ramadoss wrote:
> > This patch move the dsa hook get_tag_protocol to ksz_common file.
> > And
> > the tag_protocol is returned based on the dev->chip_id.
> > ksz8795 and ksz9477 implementation on phy read/write hooks are
> > different. This patch modifies the ksz9477 implementation same as
> > ksz8795 by updating the ksz9477_dev_ops structure.
> > 
> > Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> > ---
> 
> It would be easier to review if you would split the
> phy_read/phy_write
> change from the get_tag_protocol change.
In the RFC v1, these two are in separate patch. But patchwork errored
like maximum patch in the series should be 15. So I merged them into
one. Is it ok if the patch size increased beyond 15 or should I split
this patch series into two.
> 
> >  drivers/net/dsa/microchip/ksz8795.c    | 13 +--------
> >  drivers/net/dsa/microchip/ksz9477.c    | 37 ++++++++------------
> > ------
> >  drivers/net/dsa/microchip/ksz_common.c | 24 +++++++++++++++++
> >  drivers/net/dsa/microchip/ksz_common.h |  2 ++
> >  4 files changed, 38 insertions(+), 38 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz8795.c
> > b/drivers/net/dsa/microchip/ksz8795.c
> > index 927db57d02db..6e5f665fa1f6 100644
> > --- a/drivers/net/dsa/microchip/ksz8795.c
> > +++ b/drivers/net/dsa/microchip/ksz8795.c
> > @@ -898,17 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev,
> > u16 phy, u16 reg, u16 val)
> >       }
> >  }
> > 
> > -static enum dsa_tag_protocol ksz8_get_tag_protocol(struct
> > dsa_switch *ds,
> > -                                                int port,
> > -                                                enum
> > dsa_tag_protocol mp)
> > -{
> > -     struct ksz_device *dev = ds->priv;
> > -
> > -     /* ksz88x3 uses the same tag schema as KSZ9893 */
> > -     return ksz_is_ksz88x3(dev) ?
> > -             DSA_TAG_PROTO_KSZ9893 : DSA_TAG_PROTO_KSZ8795;
> > -}
> > -
> >  static u32 ksz8_sw_get_phy_flags(struct dsa_switch *ds, int port)
> >  {
> >       /* Silicon Errata Sheet (DS80000830A):
> > @@ -1394,7 +1383,7 @@ static void ksz8_get_caps(struct dsa_switch
> > *ds, int port,
> >  }
> > 
> >  static const struct dsa_switch_ops ksz8_switch_ops = {
> > -     .get_tag_protocol       = ksz8_get_tag_protocol,
> > +     .get_tag_protocol       = ksz_get_tag_protocol,
> >       .get_phy_flags          = ksz8_sw_get_phy_flags,
> >       .setup                  = ksz8_setup,
> >       .phy_read               = ksz_phy_read16,
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz_common.c
> > b/drivers/net/dsa/microchip/ksz_common.c
> > index 9057cdb5971c..a43b01c2e67f 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.c
> > +++ b/drivers/net/dsa/microchip/ksz_common.c
> > @@ -930,6 +930,30 @@ void ksz_port_stp_state_set(struct dsa_switch
> > *ds, int port,
> >  }
>  EXPORT_SYMBOL_GPL(ksz_port_stp_state_set);
> > 
> > +enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
> > +                                        int port, enum
> > dsa_tag_protocol mp)
> > +{
> > +     struct ksz_device *dev = ds->priv;
> > +     enum dsa_tag_protocol proto;
> 
> Please choose a default value in case the dev->chip_id does not take
> any
> of the branches, or at least do something to not return uninitialized
> variables from the stack.

Ok. I will update the default value. 

> > +
> > +     if (dev->chip_id == KSZ8795_CHIP_ID ||
> > +         dev->chip_id == KSZ8794_CHIP_ID ||
> > +         dev->chip_id == KSZ8765_CHIP_ID)
> > +             proto = DSA_TAG_PROTO_KSZ8795;
> > +
> > +     if (dev->chip_id == KSZ8830_CHIP_ID ||
> > +         dev->chip_id == KSZ9893_CHIP_ID)
> > +             proto = DSA_TAG_PROTO_KSZ9893;
> > +
> > +     if (dev->chip_id == KSZ9477_CHIP_ID ||
> > +         dev->chip_id == KSZ9897_CHIP_ID ||
> > +         dev->chip_id == KSZ9567_CHIP_ID)
> > +             proto = DSA_TAG_PROTO_KSZ9477;
> > +
> > +     return proto;
> > +}
> > +EXPORT_SYMBOL_GPL(ksz_get_tag_protocol);
> > +
> >  static int ksz_switch_detect(struct ksz_device *dev)
> >  {
> >       u8 id1, id2;
> > diff --git a/drivers/net/dsa/microchip/ksz_common.h
> > b/drivers/net/dsa/microchip/ksz_common.h
> > index d16c095cdefb..f253f3f22386 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.h
> > +++ b/drivers/net/dsa/microchip/ksz_common.h
> > @@ -231,6 +231,8 @@ int ksz_port_mdb_del(struct dsa_switch *ds, int
> > port,
> >  int ksz_enable_port(struct dsa_switch *ds, int port, struct
> > phy_device *phy);
> >  void ksz_get_strings(struct dsa_switch *ds, int port,
> >                    u32 stringset, uint8_t *buf);
> > +enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
> > +                                        int port, enum
> > dsa_tag_protocol mp);
> > 
> >  /* Common register access functions */
> > 
> > --
> > 2.36.1
> > 
> 
> 

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 05/15] net: dsa: microchip: move the port mirror to ksz_common
  2022-06-13  9:28   ` Vladimir Oltean
@ 2022-06-15  6:40     ` Arun.Ramadoss
  0 siblings, 0 replies; 35+ messages in thread
From: Arun.Ramadoss @ 2022-06-15  6:40 UTC (permalink / raw)
  To: olteanv
  Cc: andrew, linux-kernel, UNGLinuxDriver, vivien.didelot, linux,
	f.fainelli, kuba, edumazet, pabeni, netdev, Woojung.Huh, davem

On Mon, 2022-06-13 at 12:28 +0300, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> On Mon, May 30, 2022 at 04:12:47PM +0530, Arun Ramadoss wrote:
> > This patch updates the common port mirror add/del dsa_switch_ops in
> > ksz_common.c. The individual switches implementation is executed
> > based
> > on the ksz_dev_ops function pointers.
> > 
> > Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> > ---
> 
> Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
> 
> >  drivers/net/dsa/microchip/ksz8795.c    | 13 ++++++-------
> >  drivers/net/dsa/microchip/ksz9477.c    | 12 ++++++------
> >  drivers/net/dsa/microchip/ksz_common.c | 25
> > +++++++++++++++++++++++++
> >  drivers/net/dsa/microchip/ksz_common.h | 10 ++++++++++
> >  4 files changed, 47 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz8795.c
> > b/drivers/net/dsa/microchip/ksz8795.c
> > index 157d69e46793..8657b520b336 100644
> > --- a/drivers/net/dsa/microchip/ksz8795.c
> > +++ b/drivers/net/dsa/microchip/ksz8795.c
> > @@ -1089,12 +1089,10 @@ static int ksz8_port_vlan_del(struct
> > ksz_device *dev, int port,
> >       return 0;
> >  }
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz_common.c
> > b/drivers/net/dsa/microchip/ksz_common.c
> > index a1fef9e4e36c..1ed4cc94795e 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.c
> > +++ b/drivers/net/dsa/microchip/ksz_common.c
> > @@ -994,6 +994,31 @@ int ksz_port_vlan_del(struct dsa_switch *ds,
> > int port,
> >  }
> >  EXPORT_SYMBOL_GPL(ksz_port_vlan_del);
> > 
> > +int ksz_port_mirror_add(struct dsa_switch *ds, int port,
> > +                     struct dsa_mall_mirror_tc_entry *mirror,
> > +                     bool ingress, struct netlink_ext_ack *extack)
> > +{
> > +     struct ksz_device *dev = ds->priv;
> > +     int ret = -EOPNOTSUPP;
> > +
> > +     if (dev->dev_ops->mirror_add)
> > +             ret = dev->dev_ops->mirror_add(dev, port, mirror,
> > ingress,
> > +                                            extack);
> > +
> > +     return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(ksz_port_mirror_add);
> 
> Just as a minor style comment, take it or leave it.
> 
> If you switch the function pointer presence check, you reduce the
> indentation of the long statement, making it fit a single line, and
> you
> eliminate the need for a "ret" variable:
> 
>         if (!dev->dev_ops->mirror_add)
>                 return -EOPNOTSUPP;
> 
>         return dev->dev_ops->mirror_add(dev, port, mirror, ingress,
> extack);

Yes it reduces the indentation. I will update it for other checks too.

> > +
> > +void ksz_port_mirror_del(struct dsa_switch *ds, int port,
> > +                      struct dsa_mall_mirror_tc_entry *mirror)
> > +{
> > +     struct ksz_device *dev = ds->priv;
> > +
> > +     if (dev->dev_ops->mirror_del)
> > +             dev->dev_ops->mirror_del(dev, port, mirror);
> > +}
> > +EXPORT_SYMBOL_GPL(ksz_port_mirror_del);
> > +
> >  static int ksz_switch_detect(struct ksz_device *dev)
> >  {
> >       u8 id1, id2;
> > 
> > 
> > --
> > 2.36.1
> > 
> 
> 

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 06/15] net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by ksz_dev_ops
  2022-06-13  9:31   ` Vladimir Oltean
@ 2022-06-15  6:49     ` Arun.Ramadoss
  0 siblings, 0 replies; 35+ messages in thread
From: Arun.Ramadoss @ 2022-06-15  6:49 UTC (permalink / raw)
  To: olteanv
  Cc: andrew, linux-kernel, UNGLinuxDriver, vivien.didelot, linux,
	f.fainelli, kuba, edumazet, pabeni, netdev, Woojung.Huh, davem

On Mon, 2022-06-13 at 12:31 +0300, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> On Mon, May 30, 2022 at 04:12:48PM +0530, Arun Ramadoss wrote:
> > At present, P_STP_CTRL register value is passed as parameter to
> > ksz_port_stp_state from the individual dsa_switch_ops hooks. This
> > patch
> > update the function to retrieve the register value through the
> > ksz_dev_ops function pointer.
> > And add the static to ksz_update_port_member since it is not called
> > outside the ksz_common.
> > 
> > Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> > ---
> >  drivers/net/dsa/microchip/ksz8795.c    |  9 +++++----
> >  drivers/net/dsa/microchip/ksz9477.c    | 10 +++++-----
> >  drivers/net/dsa/microchip/ksz_common.c |  9 +++++----
> >  drivers/net/dsa/microchip/ksz_common.h |  5 ++---
> >  4 files changed, 17 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz8795.c
> > b/drivers/net/dsa/microchip/ksz8795.c
> > index 8657b520b336..e6982fa9d382 100644
> > --- a/drivers/net/dsa/microchip/ksz8795.c
> > +++ b/drivers/net/dsa/microchip/ksz8795.c
> > @@ -920,9 +920,9 @@ static void ksz8_cfg_port_member(struct
> > ksz_device *dev, int port, u8 member)
> >       ksz_pwrite8(dev, port, P_MIRROR_CTRL, data);
> >  }
> > 
> > -static void ksz8_port_stp_state_set(struct dsa_switch *ds, int
> > port, u8 state)
> > +static int ksz8_get_stp_reg(void)
> >  {
> > -     ksz_port_stp_state_set(ds, port, state, P_STP_CTRL);
> > +     return P_STP_CTRL;
> >  }
> 
> Since there's nothing dynamic about get_stp_reg(), can the STP
> register
> location stay in struct ksz_chip_data?

I will update the ksz_chip_data for holding the address of STP_CTL 
register.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 09/15] net: dsa: microchip: update fdb add/del/dump in ksz_common
  2022-06-13  9:42   ` Vladimir Oltean
@ 2022-06-15  6:57     ` Arun.Ramadoss
  0 siblings, 0 replies; 35+ messages in thread
From: Arun.Ramadoss @ 2022-06-15  6:57 UTC (permalink / raw)
  To: olteanv
  Cc: andrew, linux-kernel, UNGLinuxDriver, vivien.didelot, linux,
	f.fainelli, kuba, edumazet, pabeni, netdev, Woojung.Huh, davem

On Mon, 2022-06-13 at 12:42 +0300, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> On Mon, May 30, 2022 at 04:12:51PM +0530, Arun Ramadoss wrote:
> > This patch makes the dsa_switch_hook for fdbs to use ksz_common.c
> > file.
> > And from ksz_common, individual switches fdb functions are called
> > using
> > the dev->dev_ops.
> > 
> > Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> > ---
> 
> I had to jump ahead and look at the other patches to see if you plan
> on
> doing anything about the r_dyn_mac_table, r_sta_mac_table,
> w_sta_mac_table
> dev_ops which are only implemented for ksz8. They become redundant
> when
> you introduce new dev_ops for the entire FDB dump, add, del
> procedure.
> 
> I see those aren't touched - what's the plan there?

Yes, static & dynamic table access becomes reduntant and used only for
ksz8. I will remove it from the ksz_dev_ops structure. 

> > 
> > -static int ksz9477_port_fdb_dump(struct dsa_switch *ds, int port,
> > -                              dsa_fdb_dump_cb_t *cb, void *data)
> > +static int ksz9477_fdb_dump(struct ksz_device *dev, int port,
> > +                         dsa_fdb_dump_cb_t *cb, void *data)
> >  {
> > -     struct ksz_device *dev = ds->priv;
> >       int ret = 0;
> >       u32 ksz_data;
> >       u32 alu_table[4];
> > @@ -1315,9 +1312,9 @@ static const struct dsa_switch_ops
> > ksz9477_switch_ops = {
> >       .port_vlan_filtering    = ksz_port_vlan_filtering,
> >       .port_vlan_add          = ksz_port_vlan_add,
> >       .port_vlan_del          = ksz_port_vlan_del,
> > -     .port_fdb_dump          = ksz9477_port_fdb_dump,
> > -     .port_fdb_add           = ksz9477_port_fdb_add,
> > -     .port_fdb_del           = ksz9477_port_fdb_del,
> > +     .port_fdb_dump          = ksz_port_fdb_dump,
> > +     .port_fdb_add           = ksz_port_fdb_add,
> > +     .port_fdb_del           = ksz_port_fdb_del,
> >       .port_mdb_add           = ksz_port_mdb_add,
> >       .port_mdb_del           = ksz_port_mdb_del,
> >       .port_mirror_add        = ksz_port_mirror_add,
> > @@ -1403,6 +1400,9 @@ static const struct ksz_dev_ops
> > ksz9477_dev_ops = {
> >       .mirror_del = ksz9477_port_mirror_del,
> >       .get_stp_reg = ksz9477_get_stp_reg,
> >       .get_caps = ksz9477_get_caps,
> > +     .fdb_dump = ksz9477_fdb_dump,
> > +     .fdb_add = ksz9477_fdb_add,
> > +     .fdb_del = ksz9477_fdb_del,
> >       .mdb_add = ksz9477_mdb_add,
> >       .mdb_del = ksz9477_mdb_del,
> >       .shutdown = ksz9477_reset_switch,
> > diff --git a/drivers/net/dsa/microchip/ksz_common.c
> > b/drivers/net/dsa/microchip/ksz_common.c
> > index b9082952db0f..8f79ff1ac648 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.c
> > +++ b/drivers/net/dsa/microchip/ksz_common.c
> > @@ -765,32 +765,40 @@ void ksz_port_fast_age(struct dsa_switch *ds,
> > int port)
> >  }
> >  EXPORT_SYMBOL_GPL(ksz_port_fast_age);
> > 
> > 
> >  int ksz_port_fdb_dump(struct dsa_switch *ds, int port,
> > dsa_fdb_dump_cb_t *cb,
> >                     void *data)
> >  {
> >       struct ksz_device *dev = ds->priv;
> > -     int ret = 0;
> > -     u16 i = 0;
> > -     u16 entries = 0;
> > -     u8 timestamp = 0;
> > -     u8 fid;
> > -     u8 member;
> > -     struct alu_struct alu;
> > -
> > -     do {
> > -             alu.is_static = false;
> > -             ret = dev->dev_ops->r_dyn_mac_table(dev, i, alu.mac,
> > &fid,
> > -                                                 &member,
> > &timestamp,
> > -                                                 &entries);
> > -             if (!ret && (member & BIT(port))) {
> > -                     ret = cb(alu.mac, alu.fid, alu.is_static,
> > data);
> > -                     if (ret)
> > -                             break;
> > -             }
> > -             i++;
> > -     } while (i < entries);
> > -     if (i >= entries)
> > -             ret = 0;
> > +     int ret = -EOPNOTSUPP;
> > +
> > +     if (dev->dev_ops->fdb_dump)
> > +             ret = dev->dev_ops->fdb_dump(dev, port, cb, data);
> > 
> >       return ret;
> >  }
> > diff --git a/drivers/net/dsa/microchip/ksz_common.h
> > b/drivers/net/dsa/microchip/ksz_common.h
> > index 816581dd7f8e..133b1a257868 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.h
> > +++ b/drivers/net/dsa/microchip/ksz_common.h
> > @@ -192,6 +192,12 @@ struct ksz_dev_ops {
> >                         bool ingress, struct netlink_ext_ack
> > *extack);
> >       void (*mirror_del)(struct ksz_device *dev, int port,
> >                          struct dsa_mall_mirror_tc_entry *mirror);
> > +     int (*fdb_add)(struct ksz_device *dev, int port,
> > +                    const unsigned char *addr, u16 vid, struct
> > dsa_db db);
> > +     int (*fdb_del)(struct ksz_device *dev, int port,
> > +                    const unsigned char *addr, u16 vid, struct
> > dsa_db db);
> > +     int (*fdb_dump)(struct ksz_device *dev, int port,
> > +                     dsa_fdb_dump_cb_t *cb, void *data);
> >       int (*mdb_add)(struct ksz_device *dev, int port,
> >                      const struct switchdev_obj_port_mdb *mdb,
> >                      struct dsa_db db);
> > @@ -239,6 +245,10 @@ void ksz_port_bridge_leave(struct dsa_switch
> > *ds, int port,
> >                          struct dsa_bridge bridge);
> >  void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8
> > state);
> >  void ksz_port_fast_age(struct dsa_switch *ds, int port);
> > +int ksz_port_fdb_add(struct dsa_switch *ds, int port,
> > +                  const unsigned char *addr, u16 vid, struct
> > dsa_db db);
> > +int ksz_port_fdb_del(struct dsa_switch *ds, int port,
> > +                  const unsigned char *addr, u16 vid, struct
> > dsa_db db);
> >  int ksz_port_fdb_dump(struct dsa_switch *ds, int port,
> > dsa_fdb_dump_cb_t *cb,
> >                     void *data);
> >  int ksz_port_mdb_add(struct dsa_switch *ds, int port,
> > --
> > 2.36.1
> > 

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 10/15] net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common
  2022-06-14  8:15   ` Vladimir Oltean
@ 2022-06-15  8:36     ` Arun.Ramadoss
  0 siblings, 0 replies; 35+ messages in thread
From: Arun.Ramadoss @ 2022-06-15  8:36 UTC (permalink / raw)
  To: olteanv
  Cc: andrew, linux-kernel, UNGLinuxDriver, vivien.didelot, linux,
	f.fainelli, kuba, edumazet, pabeni, netdev, Woojung.Huh, davem

On Tue, 2022-06-14 at 11:15 +0300, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> On Mon, May 30, 2022 at 04:12:52PM +0530, Arun Ramadoss wrote:
> > This patch assigns the .setup, get_phy_flags & mtu  hook of ksz8795
> > and
> > ksz9477 in dsa_switch_ops to ksz_common. And the individual
> > switches
> > setup implementations are called based on the ksz_dev_ops.  For
> > get_phy_flags hooks,checks whether the chip is ksz8863/kss8793 then
> > it
> > returns error for port1.
> > 
> > Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> > ---
> >  drivers/net/dsa/microchip/ksz8795.c    | 17 ++-------
> >  drivers/net/dsa/microchip/ksz9477.c    | 14 ++++----
> >  drivers/net/dsa/microchip/ksz_common.c | 50
> > ++++++++++++++++++++++++++
> >  drivers/net/dsa/microchip/ksz_common.h |  7 ++++
> >  4 files changed, 68 insertions(+), 20 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz8795.c
> > b/drivers/net/dsa/microchip/ksz8795.c
> > index 528de481b319..1058b6883caa 100644
> > --- a/drivers/net/dsa/microchip/ksz8795.c
> > +++ b/drivers/net/dsa/microchip/ksz8795.c
> > @@ -898,18 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev,
> > u16 phy, u16 reg, u16 val)
> >       }
> >  }
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz9477.c
> > b/drivers/net/dsa/microchip/ksz9477.c
> > index d70e0c32b309..d7474d9d4384 100644
> > --- a/drivers/net/dsa/microchip/ksz9477.c
> > +++ b/drivers/net/dsa/microchip/ksz9477.c
> > @@ -47,9 +47,8 @@ static void ksz9477_port_cfg32(struct ksz_device
> > *dev, int port, int offset,
> >                          bits, set ? bits : 0);
> >  }
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz_common.c
> > b/drivers/net/dsa/microchip/ksz_common.c
> > index 8f79ff1ac648..19f8e492d3aa 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.c
> > +++ b/drivers/net/dsa/microchip/ksz_common.c
> > @@ -16,6 +16,7 @@
> >  #include <linux/if_bridge.h>
> >  #include <linux/of_device.h>
> >  #include <linux/of_net.h>
> > +#include <linux/micrel_phy.h>
> >  #include <net/dsa.h>
> >  #include <net/switchdev.h>
> > 
> > @@ -593,6 +594,14 @@ static void ksz_update_port_member(struct
> > ksz_device *dev, int port)
> >       dev->dev_ops->cfg_port_member(dev, port, port_member |
> > cpu_port);
> >  }
> > 
> > +int ksz_setup(struct dsa_switch *ds)
> > +{
> > +     struct ksz_device *dev = ds->priv;
> > +
> > +     return dev->dev_ops->setup(ds);
> > +}
> > +EXPORT_SYMBOL_GPL(ksz_setup);
> 
> I see these changes as being of questionable value if you do not plan
> to
> actually share some code between ->setup implementations. What would
> be
> desirable is if ksz_common.c decides what to do, and ksz8795.c /
> ksz9477.c only offer the implementations for fine-grained dev_ops.
> Currently there is code that can be reused between the setup
> functions
> of the 2 drivers, but also there is some divergence in configuration
> which doesn't have its place (10% rate limit for broadcast storm
> protection in ksz8795?). The goal should be for individual switch
> drivers to not apply configuration behind the curtains as much as
> possible.

Ok. I will try to move common configuration between the switches to
ksz->setup and have less configuration in the individual switch setup.

> 
> > +
> >  static void port_r_cnt(struct ksz_device *dev, int port)
> >  {
> >       struct ksz_port_mib *mib = &dev->ports[port].mib;
> > @@ -692,6 +701,23 @@ int ksz_phy_write16(struct dsa_switch *ds, int
> > addr, int reg, u16 val)
> >  }
> >  EXPORT_SYMBOL_GPL(ksz_phy_write16);
> > 
> > +u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
> > +{
> > +     struct ksz_device *dev = ds->priv;
> > +
> > +     if (dev->chip_id == KSZ8830_CHIP_ID) {
> > +             /* Silicon Errata Sheet (DS80000830A):
> > +              * Port 1 does not work with LinkMD Cable-Testing.
> > +              * Port 1 does not respond to received PAUSE control
> > frames.
> > +              */
> > +             if (!port)
> > +                     return MICREL_KSZ8_P1_ERRATA;
> > +     }
> > +
> > +     return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(ksz_get_phy_flags);
> > 
> > --
> > 2.36.1
> > 
> 
> 

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register
  2022-06-14  8:24   ` Vladimir Oltean
@ 2022-06-15  8:49     ` Arun.Ramadoss
  2022-06-15 11:14       ` Russell King (Oracle)
  0 siblings, 1 reply; 35+ messages in thread
From: Arun.Ramadoss @ 2022-06-15  8:49 UTC (permalink / raw)
  To: olteanv
  Cc: andrew, linux-kernel, UNGLinuxDriver, vivien.didelot, linux,
	f.fainelli, kuba, edumazet, pabeni, netdev, Woojung.Huh, davem

On Tue, 2022-06-14 at 11:24 +0300, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
> 
> On Mon, May 30, 2022 at 04:12:54PM +0530, Arun Ramadoss wrote:
> > As per 'commit 3506b2f42dff ("net: dsa: microchip: call
> > phy_remove_link_mode during probe")' phy_remove_link_mode is added
> > in
> > the switch_register function after dsa_switch_register. In order to
> > have
> > the common switch register function, moving this phy init after
> > dsa_register_switch using the new ksz_dev_ops.dsa_init hook.
> > 
> > Signed-off-by: Arun Ramadoss <arun.ramadoss@microchip.com>
> > ---
> >  drivers/net/dsa/microchip/ksz9477.c    | 49 ++++++++++++++------
> > ------
> >  drivers/net/dsa/microchip/ksz_common.c |  5 ++-
> >  drivers/net/dsa/microchip/ksz_common.h |  1 +
> >  3 files changed, 31 insertions(+), 24 deletions(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz9477.c
> > b/drivers/net/dsa/microchip/ksz9477.c
> > index ecce99b77ef6..c87ce0e2afd8 100644
> > --- a/drivers/net/dsa/microchip/ksz9477.c
> > +++ b/drivers/net/dsa/microchip/ksz9477.c
> > @@ -1349,6 +1349,30 @@ static void ksz9477_switch_exit(struct
> > ksz_device *dev)
> >       ksz9477_reset_switch(dev);
> >  }
> > 
> > +static int ksz9477_dsa_init(struct ksz_device *dev)
> > +{
> > +     struct phy_device *phydev;
> > +     int i;
> > +
> > +     for (i = 0; i < dev->phy_port_cnt; ++i) {
> > +             if (!dsa_is_user_port(dev->ds, i))
> > +                     continue;
> 
> I understand this is just code movement, but this is more efficient:
> 
>         struct dsa_switch *ds = dev->ds;
>         struct dsa_port *dp;
> 
>         dsa_switch_for_each_user_port(dp, ds) {
>                 ...
>         }

Yes. I will use the macro where ever possible.

> 
> > +
> > +             phydev = dsa_to_port(dev->ds, i)->slave->phydev;
> > +
> > +             /* The MAC actually cannot run in 1000 half-duplex
> > mode. */
> > +             phy_remove_link_mode(phydev,
> > +                                  ETHTOOL_LINK_MODE_1000baseT_Half
> > _BIT);
> > +
> > +             /* PHY does not support gigabit. */
> > +             if (!(dev->features & GBIT_SUPPORT))
> > +                     phy_remove_link_mode(phydev,
> > +                                          ETHTOOL_LINK_MODE_1000ba
> > seT_Full_BIT);
> > +     }
> 
> I wonder why the driver did not just remove these from the supported
> mask in the phylink validation procedure in the first place?
> Adding these link mode fixups to a dev_ops callback named "dsa_init"
> does not sound quite right.

So, it means if the link modes are updated correctly in the
phylink_get_caps then we don't need these link mode removal. Is my
understanding correct?

> 
> > +
> > +     return 0;
> > +}
> > +
> >  static const struct ksz_dev_ops ksz9477_dev_ops = {
> >       .setup = ksz9477_setup,
> >       .get_port_addr = ksz9477_get_port_addr,
> > @@ -1377,35 +1401,14 @@ static const struct ksz_dev_ops
> > ksz9477_dev_ops = {
> >       .change_mtu = ksz9477_change_mtu,
> >       .max_mtu = ksz9477_max_mtu,
> >       .shutdown = ksz9477_reset_switch,
> > +     .dsa_init = ksz9477_dsa_init,
> >       .init = ksz9477_switch_init,
> >       .exit = ksz9477_switch_exit,
> >  };
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz_common.h
> > b/drivers/net/dsa/microchip/ksz_common.h
> > index 872d378ac45c..23962f47df46 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.h
> > +++ b/drivers/net/dsa/microchip/ksz_common.h
> > @@ -213,6 +213,7 @@ struct ksz_dev_ops {
> >       void (*freeze_mib)(struct ksz_device *dev, int port, bool
> > freeze);
> >       void (*port_init_cnt)(struct ksz_device *dev, int port);
> >       int (*shutdown)(struct ksz_device *dev);
> > +     int (*dsa_init)(struct ksz_device *dev);
> >       int (*init)(struct ksz_device *dev);
> >       void (*exit)(struct ksz_device *dev);
> >  };
> > --
> > 2.36.1
> > 
> 
> 

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register
  2022-06-15  8:49     ` Arun.Ramadoss
@ 2022-06-15 11:14       ` Russell King (Oracle)
  0 siblings, 0 replies; 35+ messages in thread
From: Russell King (Oracle) @ 2022-06-15 11:14 UTC (permalink / raw)
  To: Arun.Ramadoss
  Cc: olteanv, andrew, linux-kernel, UNGLinuxDriver, vivien.didelot,
	f.fainelli, kuba, edumazet, pabeni, netdev, Woojung.Huh, davem

On Wed, Jun 15, 2022 at 08:49:46AM +0000, Arun.Ramadoss@microchip.com wrote:
> On Tue, 2022-06-14 at 11:24 +0300, Vladimir Oltean wrote:
> > I wonder why the driver did not just remove these from the supported
> > mask in the phylink validation procedure in the first place?
> > Adding these link mode fixups to a dev_ops callback named "dsa_init"
> > does not sound quite right.
> 
> So, it means if the link modes are updated correctly in the
> phylink_get_caps then we don't need these link mode removal. Is my
> understanding correct?

Yes.

If you tell phylink what you support, then phylink will use that to
restrict what is supported by e.g. the PHY.

If you find that isn't the case, then I definitely want to know,
because that's probably a bug that needs to be fixed!

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2022-06-15 11:14 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-30 10:42 [RFC Patch net-next v2 00/15] net: dsa: microchip: common spi probe for the ksz series switches Arun Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 01/15] net: dsa: microchip: ksz9477: cleanup the ksz9477_switch_detect Arun Ramadoss
2022-06-12 14:20   ` Vladimir Oltean
2022-05-30 10:42 ` [RFC Patch net-next v2 02/15] net: dsa: microchip: move switch chip_id detection to ksz_common Arun Ramadoss
2022-06-13  9:18   ` Vladimir Oltean
2022-06-14  7:10     ` Arun.Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 03/15] net: dsa: microchip: move tag_protocol & phy read/write " Arun Ramadoss
2022-06-13  9:22   ` Vladimir Oltean
2022-06-15  6:36     ` Arun.Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 04/15] net: dsa: microchip: move vlan functionality " Arun Ramadoss
2022-06-13  9:24   ` Vladimir Oltean
2022-05-30 10:42 ` [RFC Patch net-next v2 05/15] net: dsa: microchip: move the port mirror " Arun Ramadoss
2022-06-13  9:28   ` Vladimir Oltean
2022-06-15  6:40     ` Arun.Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 06/15] net: dsa: microchip: get P_STP_CTRL in ksz_port_stp_state by ksz_dev_ops Arun Ramadoss
2022-06-13  9:31   ` Vladimir Oltean
2022-06-15  6:49     ` Arun.Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 07/15] net: dsa: microchip: update the ksz_phylink_get_caps Arun Ramadoss
2022-06-13  9:32   ` Vladimir Oltean
2022-05-30 10:42 ` [RFC Patch net-next v2 08/15] net: dsa: microchip: update the ksz_port_mdb_add/del Arun Ramadoss
2022-06-13  9:36   ` Vladimir Oltean
2022-05-30 10:42 ` [RFC Patch net-next v2 09/15] net: dsa: microchip: update fdb add/del/dump in ksz_common Arun Ramadoss
2022-06-13  9:42   ` Vladimir Oltean
2022-06-15  6:57     ` Arun.Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 10/15] net: dsa: microchip: move the setup, get_phy_flags & mtu to ksz_common Arun Ramadoss
2022-06-14  8:15   ` Vladimir Oltean
2022-06-15  8:36     ` Arun.Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 11/15] net: dsa: microchip: common dsa_switch_ops for ksz switches Arun Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 12/15] net: dsa: microchip: ksz9477: separate phylink mode from switch register Arun Ramadoss
2022-06-14  8:24   ` Vladimir Oltean
2022-06-15  8:49     ` Arun.Ramadoss
2022-06-15 11:14       ` Russell King (Oracle)
2022-05-30 10:42 ` [RFC Patch net-next v2 13/15] net: dsa: microchip: common menuconfig for ksz series switch Arun Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 14/15] net: dsa: microchip: move ksz_dev_ops to ksz_common.c Arun Ramadoss
2022-05-30 10:42 ` [RFC Patch net-next v2 15/15] net: dsa: microchip: common ksz_spi_probe for ksz switches Arun Ramadoss

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.