From: Bastien Curutchet <bastien.curutchet@bootlin.com>
To: Woojung Huh <woojung.huh@microchip.com>,
UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Russell King <linux@armlinux.org.uk>
Cc: "Pascal Eberhard" <pascal.eberhard@se.com>,
"Miquèl Raynal" <miquel.raynal@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Tristram Ha" <tristram.ha@microchip.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"Bastien Curutchet (Schneider Electric)"
<bastien.curutchet@bootlin.com>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>
Subject: [PATCH net-next 7/9] net: dsa: microchip: hook up ksz_switch_alloc() to chip-specific dsa_switch_ops
Date: Tue, 05 May 2026 16:25:07 +0200 [thread overview]
Message-ID: <20260505-clean-ksz-driver-v1-7-05d70fa42461@bootlin.com> (raw)
In-Reply-To: <20260505-clean-ksz-driver-v1-0-05d70fa42461@bootlin.com>
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Now that each switch driver has its own dsa_switch_ops (currently a copy
of ksz_switch_ops), we no longer need ksz_switch_ops and can remove it.
Get to the driver-specific dsa_switch_ops through the ksz_chip_data
structure.
Reorder the alloc()/get_match_data() calls such as to have that
pointer available.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
---
drivers/net/dsa/microchip/ksz8863_smi.c | 8 ++--
drivers/net/dsa/microchip/ksz9477_i2c.c | 8 ++--
drivers/net/dsa/microchip/ksz_common.c | 67 ++-------------------------------
drivers/net/dsa/microchip/ksz_common.h | 4 +-
drivers/net/dsa/microchip/ksz_spi.c | 8 ++--
5 files changed, 19 insertions(+), 76 deletions(-)
diff --git a/drivers/net/dsa/microchip/ksz8863_smi.c b/drivers/net/dsa/microchip/ksz8863_smi.c
index a8bfcd917bf70..ba08d2cf8e99f 100644
--- a/drivers/net/dsa/microchip/ksz8863_smi.c
+++ b/drivers/net/dsa/microchip/ksz8863_smi.c
@@ -140,14 +140,14 @@ static int ksz8863_smi_probe(struct mdio_device *mdiodev)
int ret;
int i;
- dev = ksz_switch_alloc(&mdiodev->dev, mdiodev);
- if (!dev)
- return -ENOMEM;
-
chip = device_get_match_data(ddev);
if (!chip)
return -EINVAL;
+ dev = ksz_switch_alloc(&mdiodev->dev, chip, mdiodev);
+ if (!dev)
+ return -ENOMEM;
+
for (i = 0; i < __KSZ_NUM_REGMAPS; i++) {
rc = ksz8863_regmap_config[i];
rc.lock_arg = &dev->regmap_mutex;
diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c
index a2beb27459f18..8e9d08f2e1d65 100644
--- a/drivers/net/dsa/microchip/ksz9477_i2c.c
+++ b/drivers/net/dsa/microchip/ksz9477_i2c.c
@@ -22,14 +22,14 @@ static int ksz9477_i2c_probe(struct i2c_client *i2c)
struct ksz_device *dev;
int i, ret;
- dev = ksz_switch_alloc(&i2c->dev, i2c);
- if (!dev)
- return -ENOMEM;
-
chip = device_get_match_data(ddev);
if (!chip)
return -EINVAL;
+ dev = ksz_switch_alloc(&i2c->dev, chip, i2c);
+ if (!dev)
+ return -ENOMEM;
+
/* Save chip id to do special initialization when probing. */
dev->chip_id = chip->chip_id;
for (i = 0; i < __KSZ_NUM_REGMAPS; i++) {
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index e48b9d5c06301..37e575bf4e14d 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -4640,68 +4640,9 @@ int ksz_resume(struct dsa_switch *ds)
return 0;
}
-static const struct dsa_switch_ops ksz_switch_ops = {
- .get_tag_protocol = ksz_get_tag_protocol,
- .connect_tag_protocol = ksz_connect_tag_protocol,
- .get_phy_flags = ksz_get_phy_flags,
- .setup = ksz_setup,
- .teardown = ksz_teardown,
- .phy_read = ksz_phy_read16,
- .phy_write = ksz_phy_write16,
- .phylink_get_caps = ksz_phylink_get_caps,
- .port_setup = ksz_port_setup,
- .set_ageing_time = ksz_set_ageing_time,
- .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_hsr_join = ksz_hsr_join,
- .port_hsr_leave = ksz_hsr_leave,
- .port_set_mac_address = ksz_port_set_mac_address,
- .port_stp_state_set = ksz_port_stp_state_set,
- .port_teardown = ksz_port_teardown,
- .port_pre_bridge_flags = ksz_port_pre_bridge_flags,
- .port_bridge_flags = ksz_port_bridge_flags,
- .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,
- .get_pause_stats = ksz_get_pause_stats,
- .port_change_mtu = ksz_change_mtu,
- .port_max_mtu = ksz_max_mtu,
- .get_wol = ksz_get_wol,
- .set_wol = ksz_set_wol,
- .suspend = ksz_suspend,
- .resume = ksz_resume,
- .get_ts_info = ksz_get_ts_info,
- .port_hwtstamp_get = ksz_hwtstamp_get,
- .port_hwtstamp_set = ksz_hwtstamp_set,
- .port_txtstamp = ksz_port_txtstamp,
- .port_rxtstamp = ksz_port_rxtstamp,
- .cls_flower_add = ksz_cls_flower_add,
- .cls_flower_del = ksz_cls_flower_del,
- .port_setup_tc = ksz_setup_tc,
- .support_eee = ksz_support_eee,
- .set_mac_eee = ksz_set_mac_eee,
- .port_get_default_prio = ksz_port_get_default_prio,
- .port_set_default_prio = ksz_port_set_default_prio,
- .port_get_dscp_prio = ksz_port_get_dscp_prio,
- .port_add_dscp_prio = ksz_port_add_dscp_prio,
- .port_del_dscp_prio = ksz_port_del_dscp_prio,
- .port_get_apptrust = ksz_port_get_apptrust,
- .port_set_apptrust = ksz_port_set_apptrust,
-};
-
-struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)
+struct ksz_device *ksz_switch_alloc(struct device *base,
+ const struct ksz_chip_data *chip,
+ void *priv)
{
struct dsa_switch *ds;
struct ksz_device *swdev;
@@ -4712,7 +4653,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;
+ ds->ops = chip->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 125740deb5a21..37923a1c43d80 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -460,7 +460,9 @@ struct ksz_dev_ops {
int (*pcs_create)(struct ksz_device *dev);
};
-struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
+struct ksz_device *ksz_switch_alloc(struct device *base,
+ const struct ksz_chip_data *chip,
+ void *priv);
int ksz_switch_register(struct ksz_device *dev);
void ksz_switch_remove(struct ksz_device *dev);
int ksz_switch_suspend(struct device *dev);
diff --git a/drivers/net/dsa/microchip/ksz_spi.c b/drivers/net/dsa/microchip/ksz_spi.c
index d8001734b0574..373e9054947cb 100644
--- a/drivers/net/dsa/microchip/ksz_spi.c
+++ b/drivers/net/dsa/microchip/ksz_spi.c
@@ -143,14 +143,14 @@ static int ksz_spi_probe(struct spi_device *spi)
struct ksz_device *dev;
int i, ret = 0;
- dev = ksz_switch_alloc(&spi->dev, spi);
- if (!dev)
- return -ENOMEM;
-
chip = device_get_match_data(ddev);
if (!chip)
return -EINVAL;
+ dev = ksz_switch_alloc(&spi->dev, chip, spi);
+ if (!dev)
+ return -ENOMEM;
+
/* Save chip id to do special initialization when probing. */
dev->chip_id = chip->chip_id;
if (chip->chip_id == KSZ88X3_CHIP_ID)
--
2.53.0
next prev parent reply other threads:[~2026-05-05 14:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 14:25 [PATCH net-next 0/9] net: dsa: microchip: Remove one indirection layer Bastien Curutchet (Schneider Electric)
2026-05-05 14:25 ` [PATCH net-next 1/9] net: dsa: microchip: Remove unused ksz8_all_queues_split() Bastien Curutchet (Schneider Electric)
2026-05-05 14:25 ` [PATCH net-next 2/9] net: dsa: microchip: remove unused port_cleanup() callback Bastien Curutchet (Schneider Electric)
2026-05-05 14:25 ` [PATCH net-next 3/9] net: dsa: microchip: move KSZ8 ksz_dev_ops to ksz8.c Bastien Curutchet
2026-05-05 14:25 ` [PATCH net-next 4/9] net: dsa: microchip: move KSZ9477 and LAN937 ksz_dev_ops to individual drivers Bastien Curutchet
2026-05-05 14:25 ` [PATCH net-next 5/9] net: dsa: microchip: move phylink_mac_ops " Bastien Curutchet
2026-05-05 14:25 ` [PATCH net-next 6/9] net: dsa: microchip: ensure each ksz_dev_ops has its own dsa_switch_ops Bastien Curutchet
2026-05-05 14:25 ` Bastien Curutchet [this message]
2026-05-05 14:25 ` [PATCH net-next 8/9] net: dsa: microchip: split ksz_get_tag_protocol() Bastien Curutchet
2026-05-05 14:25 ` [PATCH net-next 9/9] net: dsa: microchip: split ksz_connect_tag_protocol() Bastien Curutchet (Schneider Electric)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260505-clean-ksz-driver-v1-7-05d70fa42461@bootlin.com \
--to=bastien.curutchet@bootlin.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=pascal.eberhard@se.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tristram.ha@microchip.com \
--cc=vladimir.oltean@nxp.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox