Skip to contentSkip to conversation

net: dsa: microchip: common spi probe for the ksz series switches - part 2

PATCH Applied Arun Ramadoss 3 participants 16 messages Jun 22, 2022 – Jun 24, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover net: dsa: microchip: common spi probe for the ksz series switches - part 2

This patch series aims to refactor the ksz_switch_register routine to have the common flow for the ksz series switch. And this is the follow up patch series.

First, it tries moves the common implementation in the setup from individual files to ksz_setup. Then implements the common dsa_switch_ops structure instead of independent registration. And then moves the ksz_dev_ops to ksz_common.c, it allows the dynamic detection of which ksz_dev_ops to be used based on the switch detection function.

Finally, the patch updates the ksz_spi probe function to be same for all the ksz_switches.

Arun Ramadoss (13):
net: dsa: microchip: rename shutdown to reset in ksz_dev_ops
net: dsa: microchip: add config_cpu_port to struct ksz_dev_ops
net: dsa: microchip: add the enable_stp_addr pointer in ksz_dev_ops
net: dsa: microchip: move setup function to ksz_common
net: dsa: microchip: move broadcast rate limit to ksz_setup
net: dsa: microchip: move multicast enable to ksz_setup
net: dsa: microchip: move start of switch to ksz_setup
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: remove the ksz8/ksz9477_switch_register
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              |  48 +++
 drivers/net/dsa/microchip/ksz8795.c           | 195 +++--------
 drivers/net/dsa/microchip/ksz8795_reg.h       |  12 -
 drivers/net/dsa/microchip/ksz8863_smi.c       |   2 +-
 drivers/net/dsa/microchip/ksz9477.c           | 244 +++++--------
 drivers/net/dsa/microchip/ksz9477.h           |  60 ++++
 drivers/net/dsa/microchip/ksz9477_i2c.c       |   6 +-
 drivers/net/dsa/microchip/ksz9477_reg.h       |  12 -
 drivers/net/dsa/microchip/ksz9477_spi.c       | 150 --------
 drivers/net/dsa/microchip/ksz_common.c        | 326 +++++++++++++-----
 drivers/net/dsa/microchip/ksz_common.h        |  82 ++---
 .../microchip/{ksz8795_spi.c => ksz_spi.c}    |  89 +++--
 14 files changed, 598 insertions(+), 680 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} (60%)

base-commit: 8720bd951b8e8515ffd995c7631790fdabaa9265

Signature · 1 line
2.36.1
#1 lore raw

PATCH 1/13 net: dsa: microchip: rename shutdown to reset in ksz_dev_ops

This patch renames the shutdown to reset in ksz_dev_ops in order to use the reset dev_ops in the ksz_setup.

---
 drivers/net/dsa/microchip/ksz8795.c     | 4 ++--
 drivers/net/dsa/microchip/ksz8795_spi.c | 4 ++--
 drivers/net/dsa/microchip/ksz9477.c     | 4 ++--
 drivers/net/dsa/microchip/ksz9477_i2c.c | 4 ++--
 drivers/net/dsa/microchip/ksz_common.h  | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +2 -2
index 23ed05f4efcc..ad58112bda44 100644
@@ -1379,7 +1379,7 @@ static int ksz8_setup(struct dsa_switch *ds)
 	if (!dev->vlan_cache)
 		return -ENOMEM;
 
-	ret = ksz8_reset_switch(dev);
+	ret = dev->dev_ops->reset(dev);
 	if (ret) {
 		dev_err(ds->dev, "failed to reset switch\n");
 		return ret;
@@ -1545,7 +1545,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.mirror_add = ksz8_port_mirror_add,
 	.mirror_del = ksz8_port_mirror_del,
 	.get_caps = ksz8_get_caps,
-	.shutdown = ksz8_reset_switch,
+	.reset = ksz8_reset_switch,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
 };
drivers/net/dsa/microchip/ksz8795_spi.c +2 -2
index 961a74c359a8..3f27aee9b6d3 100644
@@ -110,8 +110,8 @@ static void ksz8795_spi_shutdown(struct spi_device *spi)
 	if (!dev)
 		return;
 
-	if (dev->dev_ops->shutdown)
-		dev->dev_ops->shutdown(dev);
+	if (dev->dev_ops->reset)
+		dev->dev_ops->reset(dev);
 
 	dsa_switch_shutdown(dev->ds);
 
drivers/net/dsa/microchip/ksz9477.c +2 -2
index 5b4fc16e1692..4e0e9507e62a 100644
@@ -1246,7 +1246,7 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	if (!dev->vlan_cache)
 		return -ENOMEM;
 
-	ret = ksz9477_reset_switch(dev);
+	ret = dev->dev_ops->reset(dev);
 	if (ret) {
 		dev_err(ds->dev, "failed to reset switch\n");
 		return ret;
@@ -1400,7 +1400,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.mdb_del = ksz9477_mdb_del,
 	.change_mtu = ksz9477_change_mtu,
 	.max_mtu = ksz9477_max_mtu,
-	.shutdown = ksz9477_reset_switch,
+	.reset = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
 };
drivers/net/dsa/microchip/ksz9477_i2c.c +2 -2
index faa3163c86b0..4ade64387f3a 100644
@@ -71,8 +71,8 @@ static void ksz9477_i2c_shutdown(struct i2c_client *i2c)
 	if (!dev)
 		return;
 
-	if (dev->dev_ops->shutdown)
-		dev->dev_ops->shutdown(dev);
+	if (dev->dev_ops->reset)
+		dev->dev_ops->reset(dev);
 
 	dsa_switch_shutdown(dev->ds);
 
drivers/net/dsa/microchip/ksz_common.h +1 -1
index ebcfa688ea2c..44f60922be92 100644
@@ -204,7 +204,7 @@ struct ksz_dev_ops {
 	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);
+	int (*reset)(struct ksz_device *dev);
 	int (*init)(struct ksz_device *dev);
 	void (*exit)(struct ksz_device *dev);
 };
Signature · 1 line
2.36.1
#2 lore raw

PATCH 2/13 net: dsa: microchip: add config_cpu_port to struct ksz_dev_ops

In reply to Arun Ramadoss

To have the common set of initialization in ksz_setup, introduced the new config_cpu_port member to ksz_dev_ops. Since both the ksz8795.c and ksz9477.c configuring the cpu port in the setup function, introduced the member.

---
 drivers/net/dsa/microchip/ksz8795.c    | 3 ++-
 drivers/net/dsa/microchip/ksz9477.c    | 3 ++-
 drivers/net/dsa/microchip/ksz_common.h | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +2 -1
index ad58112bda44..0df2140b7ccc 100644
@@ -1402,7 +1402,7 @@ static int ksz8_setup(struct dsa_switch *ds)
 			   UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP,
 			   UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP);
 
-	ksz8_config_cpu_port(ds);
+	dev->dev_ops->config_cpu_port(ds);
 
 	ksz_cfg(dev, REG_SW_CTRL_2, MULTICAST_STORM_DISABLE, true);
 
@@ -1545,6 +1545,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.mirror_add = ksz8_port_mirror_add,
 	.mirror_del = ksz8_port_mirror_del,
 	.get_caps = ksz8_get_caps,
+	.config_cpu_port = ksz8_config_cpu_port,
 	.reset = ksz8_reset_switch,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
drivers/net/dsa/microchip/ksz9477.c +2 -1
index 4e0e9507e62a..fef8142440cf 100644
@@ -1268,7 +1268,7 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	if (ret)
 		return ret;
 
-	ksz9477_config_cpu_port(ds);
+	dev->dev_ops->config_cpu_port(ds);
 
 	ksz_cfg(dev, REG_SW_MAC_CTRL_1, MULTICAST_STORM_DISABLE, true);
 
@@ -1400,6 +1400,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.mdb_del = ksz9477_mdb_del,
 	.change_mtu = ksz9477_change_mtu,
 	.max_mtu = ksz9477_max_mtu,
+	.config_cpu_port = ksz9477_config_cpu_port,
 	.reset = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
drivers/net/dsa/microchip/ksz_common.h +1 -0
index 44f60922be92..d5b53b5b7b51 100644
@@ -204,6 +204,7 @@ struct ksz_dev_ops {
 	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);
+	void (*config_cpu_port)(struct dsa_switch *ds);
 	int (*reset)(struct ksz_device *dev);
 	int (*init)(struct ksz_device *dev);
 	void (*exit)(struct ksz_device *dev);
Signature · 1 line
2.36.1
#3 lore raw

PATCH 3/13 net: dsa: microchip: add the enable_stp_addr pointer in ksz_dev_ops

In reply to Arun Ramadoss

In order to transmit the STP BPDU packet to the CPU port, the STP address 01-80-c2-00-00-00 has to be added to static alu table for ksz8795 series switch. For the ksz9477 switch, there is reserved multicast table which handles forwarding the particular set of multicast address to cpu port. So enabling the multicast reserved table and updated the cpu port index. The stp addr is enabled during the setup phase using the enable_stp_addr pointer in struct ksz_dev_ops.

---
 drivers/net/dsa/microchip/ksz8795.c    | 27 ++++++++++++++-------
 drivers/net/dsa/microchip/ksz9477.c    | 33 ++++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h |  1 +
 3 files changed, 52 insertions(+), 9 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +18 -9
index 0df2140b7ccc..30052dc5b9a1 100644
@@ -1368,10 +1368,25 @@ static int ksz8_handle_global_errata(struct dsa_switch *ds)
 	return ret;
 }
 
+static int ksz8_enable_stp_addr(struct ksz_device *dev)
+{
+	struct alu_struct alu;
+
+	/* Setup STP address for STP operation. */
+	memset(&alu, 0, sizeof(alu));
+	ether_addr_copy(alu.mac, eth_stp_addr);
+	alu.is_static = true;
+	alu.is_override = true;
+	alu.port_forward = dev->info->cpu_ports;
+
+	ksz8_w_sta_mac_table(dev, 0, &alu);
+
+	return 0;
+}
+
 static int ksz8_setup(struct dsa_switch *ds)
 {
 	struct ksz_device *dev = ds->priv;
-	struct alu_struct alu;
 	int i, ret = 0;
 
 	dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
@@ -1422,14 +1437,7 @@ static int ksz8_setup(struct dsa_switch *ds)
 	for (i = 0; i < (dev->info->num_vlans / 4); i++)
 		ksz8_r_vlan_entries(dev, i);
 
-	/* Setup STP address for STP operation. */
-	memset(&alu, 0, sizeof(alu));
-	ether_addr_copy(alu.mac, eth_stp_addr);
-	alu.is_static = true;
-	alu.is_override = true;
-	alu.port_forward = dev->info->cpu_ports;
-
-	ksz8_w_sta_mac_table(dev, 0, &alu);
+	dev->dev_ops->enable_stp_addr(dev);
 
 	ksz_init_mib_timer(dev);
 
@@ -1546,6 +1554,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
 	.mirror_del = ksz8_port_mirror_del,
 	.get_caps = ksz8_get_caps,
 	.config_cpu_port = ksz8_config_cpu_port,
+	.enable_stp_addr = ksz8_enable_stp_addr,
 	.reset = ksz8_reset_switch,
 	.init = ksz8_switch_init,
 	.exit = ksz8_switch_exit,
drivers/net/dsa/microchip/ksz9477.c +33 -0
index fef8142440cf..6ca0d5753df0 100644
@@ -1236,6 +1236,36 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
 	}
 }
 
+static int ksz9477_enable_stp_addr(struct ksz_device *dev)
+{
+	u32 data;
+	int ret;
+
+	/* Enable Reserved multicast table */
+	ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_RESV_MCAST_ENABLE, true);
+
+	/* Set the Override bit for forwarding BPDU packet to CPU */
+	ret = ksz_write32(dev, REG_SW_ALU_VAL_B,
+			  ALU_V_OVERRIDE | BIT(dev->cpu_port));
+	if (ret < 0)
+		return ret;
+
+	data = ALU_STAT_START | ALU_RESV_MCAST_ADDR;
+
+	ret = ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
+	if (ret < 0)
+		return ret;
+
+	/* wait to be finished */
+	ret = ksz9477_wait_alu_sta_ready(dev);
+	if (ret < 0) {
+		dev_err(dev->dev, "Failed to update Reserved Multicast table\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 static int ksz9477_setup(struct dsa_switch *ds)
 {
 	struct ksz_device *dev = ds->priv;
@@ -1281,6 +1311,8 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	/* start switch */
 	ksz_cfg(dev, REG_SW_OPERATION, SW_START, true);
 
+	dev->dev_ops->enable_stp_addr(dev);
+
 	ksz_init_mib_timer(dev);
 
 	ds->configure_vlan_while_not_filtering = false;
@@ -1401,6 +1433,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 	.change_mtu = ksz9477_change_mtu,
 	.max_mtu = ksz9477_max_mtu,
 	.config_cpu_port = ksz9477_config_cpu_port,
+	.enable_stp_addr = ksz9477_enable_stp_addr,
 	.reset = ksz9477_reset_switch,
 	.init = ksz9477_switch_init,
 	.exit = ksz9477_switch_exit,
drivers/net/dsa/microchip/ksz_common.h +1 -0
index d5b53b5b7b51..e38bdf1f5b41 100644
@@ -205,6 +205,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);
 	void (*config_cpu_port)(struct dsa_switch *ds);
+	int (*enable_stp_addr)(struct ksz_device *dev);
 	int (*reset)(struct ksz_device *dev);
 	int (*init)(struct ksz_device *dev);
 	void (*exit)(struct ksz_device *dev);
Signature · 1 line
2.36.1
#4 lore raw

PATCH 4/13 net: dsa: microchip: move setup function to ksz_common

In reply to Arun Ramadoss

This patch move the common initialization of switches to ksz_setup and perform the switch specific initialization using the ksz_dev_ops function pointer.

---
 drivers/net/dsa/microchip/ksz8795.c    | 24 +++---------------
 drivers/net/dsa/microchip/ksz9477.c    | 22 ++---------------
 drivers/net/dsa/microchip/ksz_common.c | 34 ++++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h |  2 ++
 4 files changed, 41 insertions(+), 41 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +3 -21
index 30052dc5b9a1..3d692d5816cb 100644
@@ -1387,18 +1387,7 @@ static int ksz8_enable_stp_addr(struct ksz_device *dev)
 static int ksz8_setup(struct dsa_switch *ds)
 {
 	struct ksz_device *dev = ds->priv;
-	int i, ret = 0;
-
-	dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
-				       dev->info->num_vlans, GFP_KERNEL);
-	if (!dev->vlan_cache)
-		return -ENOMEM;
-
-	ret = dev->dev_ops->reset(dev);
-	if (ret) {
-		dev_err(ds->dev, "failed to reset switch\n");
-		return ret;
-	}
+	int i;
 
 	ksz_cfg(dev, S_REPLACE_VID_CTRL, SW_FLOW_CTRL, true);
 
@@ -1417,8 +1406,6 @@ static int ksz8_setup(struct dsa_switch *ds)
 			   UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP,
 			   UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP);
 
-	dev->dev_ops->config_cpu_port(ds);
-
 	ksz_cfg(dev, REG_SW_CTRL_2, MULTICAST_STORM_DISABLE, true);
 
 	ksz_cfg(dev, S_REPLACE_VID_CTRL, SW_REPLACE_VID, false);
@@ -1437,12 +1424,6 @@ static int ksz8_setup(struct dsa_switch *ds)
 	for (i = 0; i < (dev->info->num_vlans / 4); i++)
 		ksz8_r_vlan_entries(dev, i);
 
-	dev->dev_ops->enable_stp_addr(dev);
-
-	ksz_init_mib_timer(dev);
-
-	ds->configure_vlan_while_not_filtering = false;
-
 	return ksz8_handle_global_errata(ds);
 }
 
@@ -1467,7 +1448,7 @@ 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		= ksz_get_phy_flags,
-	.setup			= ksz8_setup,
+	.setup			= ksz_setup,
 	.phy_read		= ksz_phy_read16,
 	.phy_write		= ksz_phy_write16,
 	.phylink_get_caps	= ksz_phylink_get_caps,
@@ -1534,6 +1515,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,
drivers/net/dsa/microchip/ksz9477.c +2 -20
index 6ca0d5753df0..c8965012d1c7 100644
@@ -1271,17 +1271,6 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	struct ksz_device *dev = ds->priv;
 	int ret = 0;
 
-	dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
-				       dev->info->num_vlans, GFP_KERNEL);
-	if (!dev->vlan_cache)
-		return -ENOMEM;
-
-	ret = dev->dev_ops->reset(dev);
-	if (ret) {
-		dev_err(ds->dev, "failed to reset switch\n");
-		return ret;
-	}
-
 	/* Required for port partitioning. */
 	ksz9477_cfg32(dev, REG_SW_QM_CTRL__4, UNICAST_VLAN_BOUNDARY,
 		      true);
@@ -1298,8 +1287,6 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	if (ret)
 		return ret;
 
-	dev->dev_ops->config_cpu_port(ds);
-
 	ksz_cfg(dev, REG_SW_MAC_CTRL_1, MULTICAST_STORM_DISABLE, true);
 
 	/* queue based egress rate limit */
@@ -1311,18 +1298,12 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	/* start switch */
 	ksz_cfg(dev, REG_SW_OPERATION, SW_START, true);
 
-	dev->dev_ops->enable_stp_addr(dev);
-
-	ksz_init_mib_timer(dev);
-
-	ds->configure_vlan_while_not_filtering = false;
-
 	return 0;
 }
 
 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,
@@ -1408,6 +1389,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,
drivers/net/dsa/microchip/ksz_common.c +34 -0
index 3fc401959f00..792f891579ae 100644
@@ -607,6 +607,40 @@ 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;
+	int ret;
+
+	dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table),
+				       dev->info->num_vlans, GFP_KERNEL);
+	if (!dev->vlan_cache)
+		return -ENOMEM;
+
+	ret = dev->dev_ops->reset(dev);
+	if (ret) {
+		dev_err(ds->dev, "failed to reset switch\n");
+		return ret;
+	}
+
+	dev->dev_ops->config_cpu_port(ds);
+
+	dev->dev_ops->enable_stp_addr(dev);
+
+	ksz_init_mib_timer(dev);
+
+	ds->configure_vlan_while_not_filtering = false;
+
+	if (dev->dev_ops->setup) {
+		ret = dev->dev_ops->setup(ds);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+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;
drivers/net/dsa/microchip/ksz_common.h +2 -0
index e38bdf1f5b41..3b8e1d1887b8 100644
@@ -162,6 +162,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);
@@ -229,6 +230,7 @@ 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);
Signature · 1 line
2.36.1
#5 lore raw

PATCH 5/13 net: dsa: microchip: move broadcast rate limit to ksz_setup

In reply to Arun Ramadoss

This patch move the 10% broadcast protection from the individual setup to ksz_setup. In the ksz9477, broadcast protection is updated in reset function.

---
 drivers/net/dsa/microchip/ksz8795.c     |  6 ------
 drivers/net/dsa/microchip/ksz8795_reg.h | 10 ----------
 drivers/net/dsa/microchip/ksz9477.c     |  6 ------
 drivers/net/dsa/microchip/ksz9477_reg.h | 10 ----------
 drivers/net/dsa/microchip/ksz_common.c  | 19 +++++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h  | 11 +++++++++++
 6 files changed, 30 insertions(+), 32 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +0 -6
index 3d692d5816cb..1bbad202b238 100644
@@ -1415,12 +1415,6 @@ static int ksz8_setup(struct dsa_switch *ds)
 	if (!ksz_is_ksz88x3(dev))
 		ksz_cfg(dev, REG_SW_CTRL_19, SW_INS_TAG_ENABLE, true);
 
-	/* set broadcast storm protection 10% rate */
-	regmap_update_bits(dev->regmap[1], S_REPLACE_VID_CTRL,
-			   BROADCAST_STORM_RATE,
-			   (BROADCAST_STORM_VALUE *
-			   BROADCAST_STORM_PROT_RATE) / 100);
-
 	for (i = 0; i < (dev->info->num_vlans / 4); i++)
 		ksz8_r_vlan_entries(dev, i);
 
drivers/net/dsa/microchip/ksz8795_reg.h +0 -10
index b8f6ad7581bc..7b56e533a688 100644
@@ -64,13 +64,9 @@
 #define SW_FLOW_CTRL			BIT(5)
 #define SW_10_MBIT			BIT(4)
 #define SW_REPLACE_VID			BIT(3)
-#define BROADCAST_STORM_RATE_HI		0x07
 
 #define REG_SW_CTRL_5			0x07
 
-#define BROADCAST_STORM_RATE_LO		0xFF
-#define BROADCAST_STORM_RATE		0x07FF
-
 #define REG_SW_CTRL_6			0x08
 
 #define SW_MIB_COUNTER_FLUSH		BIT(7)
@@ -797,12 +793,6 @@
 #define REG_IND_EEE_GLOB2_LO		0x34
 #define REG_IND_EEE_GLOB2_HI		0x35
 
-/* Driver set switch broadcast storm protection at 10% rate. */
-#define BROADCAST_STORM_PROT_RATE	10
-
-/* 148,800 frames * 67 ms / 100 */
-#define BROADCAST_STORM_VALUE		9969
-
 /**
  * MIB_COUNTER_VALUE			00-00000000-3FFFFFFF
  * MIB_TOTAL_BYTES			00-0000000F-FFFFFFFF
drivers/net/dsa/microchip/ksz9477.c +0 -6
index c8965012d1c7..b2a6d2365c82 100644
@@ -197,12 +197,6 @@ static int ksz9477_reset_switch(struct ksz_device *dev)
 	ksz_write32(dev, REG_SW_PORT_INT_MASK__4, 0x7F);
 	ksz_read32(dev, REG_SW_PORT_INT_STATUS__4, &data32);
 
-	/* set broadcast storm protection 10% rate */
-	regmap_update_bits(dev->regmap[1], REG_SW_MAC_CTRL_2,
-			   BROADCAST_STORM_RATE,
-			   (BROADCAST_STORM_VALUE *
-			   BROADCAST_STORM_PROT_RATE) / 100);
-
 	data8 = SW_ENABLE_REFCLKO;
 	if (dev->synclko_disable)
 		data8 = 0;
drivers/net/dsa/microchip/ksz9477_reg.h +0 -10
index 077e35ab11b5..0345fc7ac850 100644
@@ -276,13 +276,9 @@
 #define REG_SW_MAC_CTRL_2		0x0332
 
 #define SW_REPLACE_VID			BIT(3)
-#define BROADCAST_STORM_RATE_HI		0x07
 
 #define REG_SW_MAC_CTRL_3		0x0333
 
-#define BROADCAST_STORM_RATE_LO		0xFF
-#define BROADCAST_STORM_RATE		0x07FF
-
 #define REG_SW_MAC_CTRL_4		0x0334
 
 #define SW_PASS_PAUSE			BIT(3)
@@ -1652,12 +1648,6 @@
 #define PTP_TRIG_UNIT_M			(BIT(MAX_TRIG_UNIT) - 1)
 #define PTP_TS_UNIT_M			(BIT(MAX_TIMESTAMP_UNIT) - 1)
 
-/* Driver set switch broadcast storm protection at 10% rate. */
-#define BROADCAST_STORM_PROT_RATE	10
-
-/* 148,800 frames * 67 ms / 100 */
-#define BROADCAST_STORM_VALUE		9969
-
 #define KSZ9477_MAX_FRAME_SIZE		9000
 
 #endif /* KSZ9477_REGS_H */
drivers/net/dsa/microchip/ksz_common.c +19 -0
index 792f891579ae..976b2b18908f 100644
@@ -153,6 +153,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x02,
+		.broadcast_ctrl_reg =  0x06,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -186,6 +187,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x02,
+		.broadcast_ctrl_reg =  0x06,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -205,6 +207,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x02,
+		.broadcast_ctrl_reg =  0x06,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -223,6 +226,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz88xx_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x02,
+		.broadcast_ctrl_reg =  0x06,
 		.supports_mii = {false, false, true},
 		.supports_rmii = {false, false, true},
 		.internal_phy = {true, true, false},
@@ -241,6 +245,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii	= {false, false, false, false,
 				   false, true, false},
 		.supports_rmii	= {false, false, false, false,
@@ -264,6 +269,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii	= {false, false, false, false,
 				   false, true, true},
 		.supports_rmii	= {false, false, false, false,
@@ -286,6 +292,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii = {false, false, true},
 		.supports_rmii = {false, false, true},
 		.supports_rgmii = {false, false, true},
@@ -305,6 +312,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii	= {false, false, false, false,
 				   false, true, true},
 		.supports_rmii	= {false, false, false, false,
@@ -327,6 +335,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -345,6 +354,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii = {false, false, false, false, true, true},
 		.supports_rmii = {false, false, false, false, true, true},
 		.supports_rgmii = {false, false, false, false, true, true},
@@ -363,6 +373,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -385,6 +396,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -407,6 +419,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.mib_cnt = ARRAY_SIZE(ksz9477_mib_names),
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
+		.broadcast_ctrl_reg =  0x0332,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -623,6 +636,12 @@ int ksz_setup(struct dsa_switch *ds)
 		return ret;
 	}
 
+	/* set broadcast storm protection 10% rate */
+	regmap_update_bits(dev->regmap[1], dev->info->broadcast_ctrl_reg,
+			   BROADCAST_STORM_RATE,
+			   (BROADCAST_STORM_VALUE *
+			   BROADCAST_STORM_PROT_RATE) / 100);
+
 	dev->dev_ops->config_cpu_port(ds);
 
 	dev->dev_ops->enable_stp_addr(dev);
drivers/net/dsa/microchip/ksz_common.h +11 -0
index 3b8e1d1887b8..6aeee4771f06 100644
@@ -47,6 +47,7 @@ struct ksz_chip_data {
 	int mib_cnt;
 	u8 reg_mib_cnt;
 	int stp_ctrl_reg;
+	int broadcast_ctrl_reg;
 	bool supports_mii[KSZ_MAX_NUM_PORTS];
 	bool supports_rmii[KSZ_MAX_NUM_PORTS];
 	bool supports_rgmii[KSZ_MAX_NUM_PORTS];
@@ -415,6 +416,16 @@ static inline void ksz_regmap_unlock(void *__mtx)
 
 #define SW_REV_ID_M			GENMASK(7, 4)
 
+/* Driver set switch broadcast storm protection at 10% rate. */
+#define BROADCAST_STORM_PROT_RATE	10
+
+/* 148,800 frames * 67 ms / 100 */
+#define BROADCAST_STORM_VALUE		9969
+
+#define BROADCAST_STORM_RATE_HI		0x07
+#define BROADCAST_STORM_RATE_LO		0xFF
+#define BROADCAST_STORM_RATE		0x07FF
+
 /* Regmap tables generation */
 #define KSZ_SPI_OP_RD		3
 #define KSZ_SPI_OP_WR		2
Signature · 1 line
2.36.1
#6 lore raw

PATCH 6/13 net: dsa: microchip: move multicast enable to ksz_setup

In reply to Arun Ramadoss

This patch moves the enabling the multicast storm protection from individual setup function to ksz_setup function.

---
 drivers/net/dsa/microchip/ksz8795.c     |  2 --
 drivers/net/dsa/microchip/ksz8795_reg.h |  1 -
 drivers/net/dsa/microchip/ksz9477.c     |  2 --
 drivers/net/dsa/microchip/ksz9477_reg.h |  1 -
 drivers/net/dsa/microchip/ksz_common.c  | 16 ++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h  |  3 +++
 6 files changed, 19 insertions(+), 6 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +0 -2
index 1bbad202b238..662493db8638 100644
@@ -1406,8 +1406,6 @@ static int ksz8_setup(struct dsa_switch *ds)
 			   UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP,
 			   UNICAST_VLAN_BOUNDARY | NO_EXC_COLLISION_DROP);
 
-	ksz_cfg(dev, REG_SW_CTRL_2, MULTICAST_STORM_DISABLE, true);
-
 	ksz_cfg(dev, S_REPLACE_VID_CTRL, SW_REPLACE_VID, false);
 
 	ksz_cfg(dev, S_MIRROR_CTRL, SW_MIRROR_RX_TX, false);
drivers/net/dsa/microchip/ksz8795_reg.h +0 -1
index 7b56e533a688..f2b0399d69d1 100644
@@ -44,7 +44,6 @@
 #define REG_SW_CTRL_2			0x04
 
 #define UNICAST_VLAN_BOUNDARY		BIT(7)
-#define MULTICAST_STORM_DISABLE		BIT(6)
 #define SW_BACK_PRESSURE		BIT(5)
 #define FAIR_FLOW_CTRL			BIT(4)
 #define NO_EXC_COLLISION_DROP		BIT(3)
drivers/net/dsa/microchip/ksz9477.c +0 -2
index b2a6d2365c82..827e62b032d2 100644
@@ -1281,8 +1281,6 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	if (ret)
 		return ret;
 
-	ksz_cfg(dev, REG_SW_MAC_CTRL_1, MULTICAST_STORM_DISABLE, true);
-
 	/* queue based egress rate limit */
 	ksz_cfg(dev, REG_SW_MAC_CTRL_5, SW_OUT_RATE_LIMIT_QUEUE_BASED, true);
 
drivers/net/dsa/microchip/ksz9477_reg.h +0 -1
index 0345fc7ac850..57e03dfcf869 100644
@@ -265,7 +265,6 @@
 
 #define REG_SW_MAC_CTRL_1		0x0331
 
-#define MULTICAST_STORM_DISABLE		BIT(6)
 #define SW_BACK_PRESSURE		BIT(5)
 #define FAIR_FLOW_CTRL			BIT(4)
 #define NO_EXC_COLLISION_DROP		BIT(3)
drivers/net/dsa/microchip/ksz_common.c +16 -0
index 976b2b18908f..719fa1b0884e 100644
@@ -154,6 +154,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x02,
 		.broadcast_ctrl_reg =  0x06,
+		.multicast_ctrl_reg = 0x04,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -188,6 +189,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x02,
 		.broadcast_ctrl_reg =  0x06,
+		.multicast_ctrl_reg = 0x04,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -208,6 +210,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x02,
 		.broadcast_ctrl_reg =  0x06,
+		.multicast_ctrl_reg = 0x04,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -227,6 +230,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x02,
 		.broadcast_ctrl_reg =  0x06,
+		.multicast_ctrl_reg = 0x04,
 		.supports_mii = {false, false, true},
 		.supports_rmii = {false, false, true},
 		.internal_phy = {true, true, false},
@@ -246,6 +250,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii	= {false, false, false, false,
 				   false, true, false},
 		.supports_rmii	= {false, false, false, false,
@@ -270,6 +275,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii	= {false, false, false, false,
 				   false, true, true},
 		.supports_rmii	= {false, false, false, false,
@@ -293,6 +299,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii = {false, false, true},
 		.supports_rmii = {false, false, true},
 		.supports_rgmii = {false, false, true},
@@ -313,6 +320,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii	= {false, false, false, false,
 				   false, true, true},
 		.supports_rmii	= {false, false, false, false,
@@ -336,6 +344,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -355,6 +364,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii = {false, false, false, false, true, true},
 		.supports_rmii = {false, false, false, false, true, true},
 		.supports_rgmii = {false, false, false, false, true, true},
@@ -374,6 +384,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -397,6 +408,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -420,6 +432,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.reg_mib_cnt = MIB_COUNTER_NUM,
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
+		.multicast_ctrl_reg = 0x0331,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -646,6 +659,9 @@ int ksz_setup(struct dsa_switch *ds)
 
 	dev->dev_ops->enable_stp_addr(dev);
 
+	regmap_update_bits(dev->regmap[0], dev->info->multicast_ctrl_reg,
+			   MULTICAST_STORM_DISABLE, MULTICAST_STORM_DISABLE);
+
 	ksz_init_mib_timer(dev);
 
 	ds->configure_vlan_while_not_filtering = false;
drivers/net/dsa/microchip/ksz_common.h +3 -0
index 6aeee4771f06..35d734ee932e 100644
@@ -48,6 +48,7 @@ struct ksz_chip_data {
 	u8 reg_mib_cnt;
 	int stp_ctrl_reg;
 	int broadcast_ctrl_reg;
+	int multicast_ctrl_reg;
 	bool supports_mii[KSZ_MAX_NUM_PORTS];
 	bool supports_rmii[KSZ_MAX_NUM_PORTS];
 	bool supports_rgmii[KSZ_MAX_NUM_PORTS];
@@ -426,6 +427,8 @@ static inline void ksz_regmap_unlock(void *__mtx)
 #define BROADCAST_STORM_RATE_LO		0xFF
 #define BROADCAST_STORM_RATE		0x07FF
 
+#define MULTICAST_STORM_DISABLE		BIT(6)
+
 /* Regmap tables generation */
 #define KSZ_SPI_OP_RD		3
 #define KSZ_SPI_OP_WR		2
Signature · 1 line
2.36.1
#7 lore raw

PATCH 7/13 net: dsa: microchip: move start of switch to ksz_setup

In reply to Arun Ramadoss

This patch move the setting the start bit from the individual switch configuration to ksz_setup

---
 drivers/net/dsa/microchip/ksz8795_reg.h |  1 -
 drivers/net/dsa/microchip/ksz9477.c     |  3 ---
 drivers/net/dsa/microchip/ksz9477_reg.h |  1 -
 drivers/net/dsa/microchip/ksz_common.c  | 17 +++++++++++++++++
 drivers/net/dsa/microchip/ksz_common.h  |  3 +++
 5 files changed, 20 insertions(+), 5 deletions(-)
drivers/net/dsa/microchip/ksz8795_reg.h +0 -1
index f2b0399d69d1..32d985296520 100644
@@ -16,7 +16,6 @@
 
 #define SW_REVISION_M			0x0E
 #define SW_REVISION_S			1
-#define SW_START			0x01
 
 #define KSZ8863_REG_SW_RESET		0x43
 
drivers/net/dsa/microchip/ksz9477.c +0 -3
index 827e62b032d2..5fa5b3d09146 100644
@@ -1287,9 +1287,6 @@ static int ksz9477_setup(struct dsa_switch *ds)
 	/* enable global MIB counter freeze function */
 	ksz_cfg(dev, REG_SW_MAC_CTRL_6, SW_MIB_COUNTER_FREEZE, true);
 
-	/* start switch */
-	ksz_cfg(dev, REG_SW_OPERATION, SW_START, true);
-
 	return 0;
 }
 
drivers/net/dsa/microchip/ksz9477_reg.h +0 -1
index 57e03dfcf869..c0ad83753b13 100644
@@ -165,7 +165,6 @@
 
 #define SW_DOUBLE_TAG			BIT(7)
 #define SW_RESET			BIT(1)
-#define SW_START			BIT(0)
 
 #define REG_SW_MAC_ADDR_0		0x0302
 #define REG_SW_MAC_ADDR_1		0x0303
drivers/net/dsa/microchip/ksz_common.c +17 -0
index 719fa1b0884e..6da4df520397 100644
@@ -155,6 +155,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x02,
 		.broadcast_ctrl_reg =  0x06,
 		.multicast_ctrl_reg = 0x04,
+		.start_ctrl_reg = 0x01,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -190,6 +191,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x02,
 		.broadcast_ctrl_reg =  0x06,
 		.multicast_ctrl_reg = 0x04,
+		.start_ctrl_reg = 0x01,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -211,6 +213,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x02,
 		.broadcast_ctrl_reg =  0x06,
 		.multicast_ctrl_reg = 0x04,
+		.start_ctrl_reg = 0x01,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -231,6 +234,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x02,
 		.broadcast_ctrl_reg =  0x06,
 		.multicast_ctrl_reg = 0x04,
+		.start_ctrl_reg = 0x01,
 		.supports_mii = {false, false, true},
 		.supports_rmii = {false, false, true},
 		.internal_phy = {true, true, false},
@@ -251,6 +255,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii	= {false, false, false, false,
 				   false, true, false},
 		.supports_rmii	= {false, false, false, false,
@@ -276,6 +281,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii	= {false, false, false, false,
 				   false, true, true},
 		.supports_rmii	= {false, false, false, false,
@@ -300,6 +306,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii = {false, false, true},
 		.supports_rmii = {false, false, true},
 		.supports_rgmii = {false, false, true},
@@ -321,6 +328,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii	= {false, false, false, false,
 				   false, true, true},
 		.supports_rmii	= {false, false, false, false,
@@ -345,6 +353,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii = {false, false, false, false, true},
 		.supports_rmii = {false, false, false, false, true},
 		.supports_rgmii = {false, false, false, false, true},
@@ -365,6 +374,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii = {false, false, false, false, true, true},
 		.supports_rmii = {false, false, false, false, true, true},
 		.supports_rgmii = {false, false, false, false, true, true},
@@ -385,6 +395,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -409,6 +420,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -433,6 +445,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.stp_ctrl_reg = 0x0B04,
 		.broadcast_ctrl_reg =  0x0332,
 		.multicast_ctrl_reg = 0x0331,
+		.start_ctrl_reg = 0x0300,
 		.supports_mii	= {false, false, false, false,
 				   true, true, false, false},
 		.supports_rmii	= {false, false, false, false,
@@ -672,6 +685,10 @@ int ksz_setup(struct dsa_switch *ds)
 			return ret;
 	}
 
+	/* start switch */
+	regmap_update_bits(dev->regmap[0], dev->info->start_ctrl_reg,
+			   SW_START, SW_START);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(ksz_setup);
drivers/net/dsa/microchip/ksz_common.h +3 -0
index 35d734ee932e..2cf8474ba626 100644
@@ -49,6 +49,7 @@ struct ksz_chip_data {
 	int stp_ctrl_reg;
 	int broadcast_ctrl_reg;
 	int multicast_ctrl_reg;
+	int start_ctrl_reg;
 	bool supports_mii[KSZ_MAX_NUM_PORTS];
 	bool supports_rmii[KSZ_MAX_NUM_PORTS];
 	bool supports_rgmii[KSZ_MAX_NUM_PORTS];
@@ -429,6 +430,8 @@ static inline void ksz_regmap_unlock(void *__mtx)
 
 #define MULTICAST_STORM_DISABLE		BIT(6)
 
+#define SW_START			0x01
+
 /* Regmap tables generation */
 #define KSZ_SPI_OP_RD		3
 #define KSZ_SPI_OP_WR		2
Signature · 1 line
2.36.1
#8 lore raw

PATCH 8/13 net: dsa: microchip: common dsa_switch_ops for ksz switches

In reply to Arun Ramadoss

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.

---
 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(-)
drivers/net/dsa/microchip/ksz8795.c +0 -28
index 662493db8638..0734ee63ed19 100644
@@ -1437,32 +1437,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);
@@ -1472,8 +1446,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;
drivers/net/dsa/microchip/ksz9477.c +1 -32
index 5fa5b3d09146..e3989aef93f4 100644
@@ -1290,36 +1290,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);
@@ -1330,8 +1300,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 */
@@ -1369,6 +1337,7 @@ static int ksz9477_switch_init(struct ksz_device *dev)
 		if (!(data8 & SW_GIGABIT_ABLE))
 			dev->features &= ~GBIT_SUPPORT;
 	}
+
 	return 0;
 }
 
drivers/net/dsa/microchip/ksz_common.c +87 -77

388 lines not on this page · raw message

drivers/net/dsa/microchip/ksz_common.h +1 -53

61 lines not on this page · raw message

Signature · 1 line
2.36.1
#9 lore raw

PATCH 9/13 net: dsa: microchip: ksz9477: separate phylink mode from switch register

In reply to Arun Ramadoss

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 phylink validation to phylink_get_caps validation hook.

---
 drivers/net/dsa/microchip/ksz9477.c    | 31 +++++---------------------
 drivers/net/dsa/microchip/ksz_common.c |  2 +-
 2 files changed, 7 insertions(+), 26 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +6 -25
index e3989aef93f4..4fcc7923da4d 100644
@@ -1059,8 +1059,11 @@ static void ksz9477_phy_errata_setup(struct ksz_device *dev, int port)
 static 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;
+	config->mac_capabilities = MAC_10 | MAC_100 | MAC_ASYM_PAUSE |
+				   MAC_SYM_PAUSE;
+
+	if (dev->features & GBIT_SUPPORT)
+		config->mac_capabilities |= MAC_1000FD;
 }
 
 static void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port)
@@ -1381,29 +1384,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
 
 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);
 
drivers/net/dsa/microchip/ksz_common.c +1 -1
index 9ebeaba2c755..62d699a47589 100644
@@ -1332,7 +1332,7 @@ int ksz_switch_register(struct ksz_device *dev,
 	/* Start the MIB timer. */
 	schedule_delayed_work(&dev->mib_read, 0);
 
-	return 0;
+	return ret;
 }
 EXPORT_SYMBOL(ksz_switch_register);
 
Signature · 1 line
2.36.1
#10 lore raw

PATCH 10/13 net: dsa: microchip: common menuconfig for ksz series switch

In reply to Arun Ramadoss

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.

---
 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(-)
drivers/net/dsa/microchip/Kconfig +9 -19
index c9e2a8989556..d21ff069e5aa 100644
@@ -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
drivers/net/dsa/microchip/Makefile +4 -3
index 2a03b21a3386..4cf4755e6426 100644
@@ -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
drivers/net/dsa/microchip/ksz_common.c +0 -3
index 62d699a47589..d5d1aab54003 100644
@@ -555,7 +555,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)
@@ -765,7 +764,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)
 {
@@ -987,7 +985,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,
Signature · 1 line
2.36.1
#11 lore raw

PATCH 11/13 net: dsa: microchip: move ksz_dev_ops to ksz_common.c

In reply to Arun Ramadoss

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.

---
 drivers/net/dsa/microchip/ksz8.h       |  48 +++++++++
 drivers/net/dsa/microchip/ksz8795.c    | 119 +++++++++--------------
 drivers/net/dsa/microchip/ksz9477.c    | 129 +++++++++----------------
 drivers/net/dsa/microchip/ksz9477.h    |  60 ++++++++++++
 drivers/net/dsa/microchip/ksz_common.c |  75 +++++++++++++-
 drivers/net/dsa/microchip/ksz_common.h |   4 +-
 6 files changed, 271 insertions(+), 164 deletions(-)
 create mode 100644 drivers/net/dsa/microchip/ksz9477.h
drivers/net/dsa/microchip/ksz8.h +48 -0
index cae76f5e7787..de246989c81b 100644
@@ -9,6 +9,8 @@
 #define __KSZ8XXX_H
 
 #include <linux/types.h>
+#include <net/dsa.h>
+#include "ksz_common.h"
 
 enum ksz_regs {
 	REG_IND_CTRL_0,
@@ -68,4 +70,50 @@ 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);
+void ksz8_config_cpu_port(struct dsa_switch *ds);
+int ksz8_enable_stp_addr(struct ksz_device *dev);
+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
drivers/net/dsa/microchip/ksz8795.c +44 -75

291 lines not on this page · raw message

drivers/net/dsa/microchip/ksz9477.c +45 -84

310 lines not on this page · raw message

drivers/net/dsa/microchip/ksz9477.h new file +60 -0

60 lines not on this page · raw message

drivers/net/dsa/microchip/ksz_common.c +72 -3

147 lines not on this page · raw message

drivers/net/dsa/microchip/ksz_common.h +2 -2
index 8a2ebce37a49..4d8f09b67c5f 100644
@@ -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;
@@ -216,8 +217,7 @@ 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);
Signature · 1 line
2.36.1
#12 lore raw

PATCH 12/13 net: dsa: microchip: remove the ksz8/ksz9477_switch_register

In reply to Arun Ramadoss

This patch delete 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.

---
 drivers/net/dsa/microchip/ksz8795.c     | 6 ------
 drivers/net/dsa/microchip/ksz8795_spi.c | 2 +-
 drivers/net/dsa/microchip/ksz8863_smi.c | 2 +-
 drivers/net/dsa/microchip/ksz9477.c     | 6 ------
 drivers/net/dsa/microchip/ksz9477_i2c.c | 2 +-
 drivers/net/dsa/microchip/ksz9477_spi.c | 2 +-
 drivers/net/dsa/microchip/ksz_common.h  | 3 ---
 7 files changed, 4 insertions(+), 19 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +0 -6
index 78fa33a23b4e..df7d782e3fcd 100644
@@ -1475,12 +1475,6 @@ void ksz8_switch_exit(struct ksz_device *dev)
 	ksz8_reset_switch(dev);
 }
 
-int ksz8_switch_register(struct ksz_device *dev)
-{
-	return ksz_switch_register(dev);
-}
-EXPORT_SYMBOL(ksz8_switch_register);
-
 MODULE_AUTHOR("Tristram Ha <[email protected]>");
 MODULE_DESCRIPTION("Microchip KSZ8795 Series Switch DSA Driver");
 MODULE_LICENSE("GPL");
drivers/net/dsa/microchip/ksz8795_spi.c +1 -1
index 3f27aee9b6d3..9d74e59624a6 100644
@@ -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)
drivers/net/dsa/microchip/ksz8863_smi.c +1 -1
index b6f99e641dca..d71df05b8b7b 100644
@@ -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)
drivers/net/dsa/microchip/ksz9477.c +0 -6
index fe471626350f..fa498ad8ca40 100644
@@ -1343,12 +1343,6 @@ void ksz9477_switch_exit(struct ksz_device *dev)
 	ksz9477_reset_switch(dev);
 }
 
-int ksz9477_switch_register(struct ksz_device *dev)
-{
-	return ksz_switch_register(dev);
-}
-EXPORT_SYMBOL(ksz9477_switch_register);
-
 MODULE_AUTHOR("Woojung Huh <[email protected]>");
 MODULE_DESCRIPTION("Microchip KSZ9477 Series Switch DSA Driver");
 MODULE_LICENSE("GPL");
drivers/net/dsa/microchip/ksz9477_i2c.c +1 -1
index 4ade64387f3a..99966514d444 100644
@@ -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)
drivers/net/dsa/microchip/ksz9477_spi.c +1 -1
index 1bc8b0cbe458..2ee0601bc014 100644
@@ -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)
drivers/net/dsa/microchip/ksz_common.h +0 -3
index 4d8f09b67c5f..0e7f15efbb79 100644
@@ -220,9 +220,6 @@ struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
 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);
Signature · 1 line
2.36.1
#13 lore raw

PATCH 13/13 net: dsa: microchip: common ksz_spi_probe for ksz switches

In reply to Arun Ramadoss

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.

---
 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%)
drivers/net/dsa/microchip/Kconfig +3 -13
index d21ff069e5aa..2edb88080790 100644
@@ -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
drivers/net/dsa/microchip/Makefile +1 -2
index 4cf4755e6426..b2ba7c1bcb93 100644
@@ -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
drivers/net/dsa/microchip/ksz9477_spi.c deleted +0 -150

150 lines not on this page · raw message

drivers/net/dsa/microchip/ksz_spi.c renamed from drivers/net/dsa/microchip/ksz8795_spi.c +65 -18

147 lines not on this page · raw message

Signature · 1 line
2.36.1
#14 lore raw
In reply to Arun Ramadoss
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 10 lines · On Wed, 22 Jun 2022 14:34:12 +0530 you wrote:

This patch series aims to refactor the ksz_switch_register routine to have the common flow for the ksz series switch. And this is the follow up patch series.

First, it tries moves the common implementation in the setup from individual files to ksz_setup. Then implements the common dsa_switch_ops structure instead of independent registration. And then moves the ksz_dev_ops to ksz_common.c, it allows the dynamic detection of which ksz_dev_ops to be used based on the switch detection function.

[...]

Here is the summary with links:
- [net-next,01/13] net: dsa: microchip: rename shutdown to reset in ksz_dev_ops

    https://git.kernel.org/netdev/net-next/c/673b196fdd34
  - [net-next,02/13] net: dsa: microchip: add config_cpu_port to struct ksz_dev_ops
    https://git.kernel.org/netdev/net-next/c/fb9324beb5d4
  - [net-next,03/13] net: dsa: microchip: add the enable_stp_addr pointer in ksz_dev_ops
    https://git.kernel.org/netdev/net-next/c/331d64f752bb
  - [net-next,04/13] net: dsa: microchip: move setup function to ksz_common
    https://git.kernel.org/netdev/net-next/c/d2822e686879
  - [net-next,05/13] net: dsa: microchip: move broadcast rate limit to ksz_setup
    https://git.kernel.org/netdev/net-next/c/1ca6437fafc9
  - [net-next,06/13] net: dsa: microchip: move multicast enable to ksz_setup
    https://git.kernel.org/netdev/net-next/c/0abab9f3ec6b
  - [net-next,07/13] net: dsa: microchip: move start of switch to ksz_setup
    https://git.kernel.org/netdev/net-next/c/ad08ac189758
  - [net-next,08/13] net: dsa: microchip: common dsa_switch_ops for ksz switches
    https://git.kernel.org/netdev/net-next/c/1958eee85f67
  - [net-next,09/13] net: dsa: microchip: ksz9477: separate phylink mode from switch register
    https://git.kernel.org/netdev/net-next/c/7a8988a17c48
  - [net-next,10/13] net: dsa: microchip: common menuconfig for ksz series switch
    https://git.kernel.org/netdev/net-next/c/07bca160469b
  - [net-next,11/13] net: dsa: microchip: move ksz_dev_ops to ksz_common.c
    https://git.kernel.org/netdev/net-next/c/6ec23aaaac43
  - [net-next,12/13] net: dsa: microchip: remove the ksz8/ksz9477_switch_register
    https://git.kernel.org/netdev/net-next/c/ff3f3a3090d2
  - [net-next,13/13] net: dsa: microchip: common ksz_spi_probe for ksz switches
    https://git.kernel.org/netdev/net-next/c/4658f2fe8fbc

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
maintainer
#15 lore raw
In reply to Arun Ramadoss
Quoted 11 lines · Arun Ramadoss

This patch series aims to refactor the ksz_switch_register routine to have the common flow for the ksz series switch. And this is the follow up patch series.

First, it tries moves the common implementation in the setup from individual files to ksz_setup. Then implements the common dsa_switch_ops structure instead of independent registration. And then moves the ksz_dev_ops to ksz_common.c, it allows the dynamic detection of which ksz_dev_ops to be used based on the switch detection function.

Finally, the patch updates the ksz_spi probe function to be same for all the ksz_switches.

Sorry for being late to the party again. I've looked over the resulting code and it appears that there is still some cleanup to do.

We now have a stray struct ksz8 pointer being allocated by the common ksz_spi_probe(), and passed as dev->priv to ksz_switch_alloc() by this generic code.

Only ksz8 accesses dev->priv, although it is interesting to note that ksz9477_i2c_probe() calls ksz_switch_alloc() with a type-incompatible struct i2c_client *i2c that is unused but bogus.

The concept of struct ksz8 was added by commit 9f73e11250fb ("net: dsa:
microchip: ksz8795: move register offsets and shifts to separate struct"), and in essence it isn't a bad idea, it's just that I wasn't aware of it, and only ksz8 makes use of it.

You've added some register offsets yourself to ksz_chip_data (stp_ctrl_reg, broadcast_ctrl_reg, multicast_ctrl_reg, start_ctrl_reg), and it looks like struct ksz8 shares more or less the same purpose - regs, masks, shifts etc. Would you mind doing some more consolidation work and trying to figure out if we could eliminate a data structure unique for ksz8 and integrate that information into struct ksz_chip_data (and perhaps use it in more places)?