ksz_dev_ops::phylink_mac_link_up() isn't used anywhere. Remove it. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 3dde7e7717272..0ab3b4f96595a 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -444,11 +444,6 @@ struct ksz_dev_ops { u8 data); void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); - void (*phylink_mac_link_up)(struct ksz_device *dev, int port, - unsigned int mode, - phy_interface_t interface, - struct phy_device *phydev, int speed, - int duplex, bool tx_pause, bool rx_pause); void (*setup_rgmii_delay)(struct ksz_device *dev, int port); int (*tc_cbs_set_cinc)(struct ksz_device *dev, int port, u32 val); void (*config_cpu_port)(struct dsa_switch *ds); -- 2.53.0 From: Vladimir Oltean dsa_switch_ops :: set_ageing_time() goes through ksz_set_ageing_time(), further dispatched through ksz_dev_ops :: set_ageing_time(). Only ksz9477 and lan937x provide an implementation for this, so remove the (optional) method from ksz8463_switch_ops, ksz87xx_switch_ops, ksz88xx_switch_ops. Also, hook up ksz9477 and lan937x dsa_switch_ops directly to their respective implementations. Every switch family provides a dsa_switch_ops :: port_fast_age() implementation, which is dispatched through ksz_dev_ops :: flush_dyn_mac_table(). Remove the dev_ops indirection and connect the flush_dyn_mac_table() methods directly to their respective dsa_switch_ops. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 15 +++++---------- drivers/net/dsa/microchip/ksz9477.c | 12 ++++++------ drivers/net/dsa/microchip/ksz9477.h | 2 +- drivers/net/dsa/microchip/ksz_common.c | 17 ----------------- drivers/net/dsa/microchip/ksz_common.h | 4 ---- drivers/net/dsa/microchip/lan937x_main.c | 9 ++++----- 6 files changed, 16 insertions(+), 43 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index abee0dc5ec04b..10ab89ff93b65 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -1278,8 +1278,9 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member) ksz_pwrite8(dev, port, offset, data); } -static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port) +static void ksz8_flush_dyn_mac_table(struct dsa_switch *ds, int port) { + struct ksz_device *dev = ds->priv; u8 learn[DSA_MAX_PORTS]; int first, index, cnt; const u16 *regs; @@ -2201,7 +2202,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .setup = ksz8_setup, .get_port_addr = ksz8463_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 = ksz8463_r_phy, .w_phy = ksz8463_w_phy, @@ -2233,7 +2233,6 @@ const struct ksz_dev_ops ksz87xx_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, @@ -2268,7 +2267,6 @@ const struct ksz_dev_ops ksz88xx_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, @@ -2309,7 +2307,6 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .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, @@ -2322,7 +2319,7 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .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_fast_age = ksz8_flush_dyn_mac_table, .port_vlan_filtering = ksz_port_vlan_filtering, .port_vlan_add = ksz_port_vlan_add, .port_vlan_del = ksz_port_vlan_del, @@ -2370,7 +2367,6 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .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, @@ -2383,7 +2379,7 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .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_fast_age = ksz8_flush_dyn_mac_table, .port_vlan_filtering = ksz_port_vlan_filtering, .port_vlan_add = ksz_port_vlan_add, .port_vlan_del = ksz_port_vlan_del, @@ -2431,7 +2427,6 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .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, @@ -2444,7 +2439,7 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .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_fast_age = ksz8_flush_dyn_mac_table, .port_vlan_filtering = ksz_port_vlan_filtering, .port_vlan_add = ksz_port_vlan_add, .port_vlan_del = ksz_port_vlan_del, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index ac2c63fe0588c..11e6fd1f46ce0 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -604,8 +604,9 @@ void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member) ksz_pwrite32(dev, port, REG_PORT_VLAN_MEMBERSHIP__4, member); } -void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port) +void ksz9477_flush_dyn_mac_table(struct dsa_switch *ds, int port) { + struct ksz_device *dev = ds->priv; const u16 *regs = dev->info->regs; u8 data; @@ -1170,8 +1171,9 @@ static void ksz9477_get_caps(struct ksz_device *dev, int port, } } -static int ksz9477_set_ageing_time(struct ksz_device *dev, unsigned int msecs) +static int ksz9477_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) { + struct ksz_device *dev = ds->priv; u32 secs = msecs / 1000; u8 data, mult, value; u32 max_val; @@ -1769,9 +1771,7 @@ 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, - .set_ageing_time = ksz9477_set_ageing_time, .r_phy = ksz9477_r_phy, .w_phy = ksz9477_w_phy, .r_mib_cnt = ksz9477_r_mib_cnt, @@ -1813,7 +1813,7 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .phy_write = ksz_phy_write16, .phylink_get_caps = ksz_phylink_get_caps, .port_setup = ksz_port_setup, - .set_ageing_time = ksz_set_ageing_time, + .set_ageing_time = ksz9477_set_ageing_time, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, .get_sset_count = ksz_sset_count, @@ -1826,7 +1826,7 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .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_fast_age = ksz9477_flush_dyn_mac_table, .port_vlan_filtering = ksz_port_vlan_filtering, .port_vlan_add = ksz_port_vlan_add, .port_vlan_del = ksz_port_vlan_del, diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h index bacadcbc478cc..8012904a21308 100644 --- a/drivers/net/dsa/microchip/ksz9477.h +++ b/drivers/net/dsa/microchip/ksz9477.h @@ -13,7 +13,7 @@ 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_flush_dyn_mac_table(struct dsa_switch *ds, int port); 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); diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 426414a218455..cfca29007e36b 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3085,23 +3085,6 @@ void ksz_port_bridge_leave(struct dsa_switch *ds, int port, */ } -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); -} - -int ksz_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) -{ - struct ksz_device *dev = ds->priv; - - if (!dev->dev_ops->set_ageing_time) - return -EOPNOTSUPP; - - return dev->dev_ops->set_ageing_time(dev, msecs); -} - int ksz_port_fdb_add(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db) diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 0ab3b4f96595a..80b3f2483e36d 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -363,9 +363,7 @@ struct ksz_dev_ops { void (*teardown)(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); void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port); - int (*set_ageing_time)(struct ksz_device *dev, unsigned int msecs); /** * @mdio_bus_preinit: Function pointer to pre-initialize the MDIO bus @@ -515,8 +513,6 @@ 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); -void ksz_port_fast_age(struct dsa_switch *ds, int port); -int ksz_set_ageing_time(struct dsa_switch *ds, unsigned int msecs); int ksz_port_fdb_add(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db); diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index e522990cce22e..19e444cb0a74a 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -461,8 +461,9 @@ static int lan937x_change_mtu(struct ksz_device *dev, int port, int new_mtu) return 0; } -static int lan937x_set_ageing_time(struct ksz_device *dev, unsigned int msecs) +static int lan937x_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) { + struct ksz_device *dev = ds->priv; u8 data, mult, value8; bool in_msec = false; u32 max_val, value; @@ -702,9 +703,7 @@ const struct ksz_dev_ops lan937x_dev_ops = { .teardown = lan937x_teardown, .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 = lan937x_port_setup, - .set_ageing_time = lan937x_set_ageing_time, .mdio_bus_preinit = lan937x_mdio_bus_preinit, .create_phy_addr_map = lan937x_create_phy_addr_map, .r_phy = lan937x_r_phy, @@ -745,7 +744,7 @@ const struct dsa_switch_ops lan937x_switch_ops = { .phy_write = ksz_phy_write16, .phylink_get_caps = ksz_phylink_get_caps, .port_setup = ksz_port_setup, - .set_ageing_time = ksz_set_ageing_time, + .set_ageing_time = lan937x_set_ageing_time, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, .get_sset_count = ksz_sset_count, @@ -758,7 +757,7 @@ const struct dsa_switch_ops lan937x_switch_ops = { .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_fast_age = ksz9477_flush_dyn_mac_table, .port_vlan_filtering = ksz_port_vlan_filtering, .port_vlan_add = ksz_port_vlan_add, .port_vlan_del = ksz_port_vlan_del, -- 2.53.0 From: Vladimir Oltean MTU changing is done through a common function that redirects the treatment to a specific ksz_dev_ops callback. This layer of indirection isn't needed since we now have a dsa_switch_ops struct for each switch family. Remove this indirection layer in MTU changing for KSZ switches, by directly connecting the ksz_dev_ops :: change_mtu() implementations to dsa_switch_ops. Remove the no longer used change_mtu() callback from ksz_dev_ops Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 12 +++++------- drivers/net/dsa/microchip/ksz9477.c | 6 +++--- drivers/net/dsa/microchip/ksz_common.c | 10 ---------- drivers/net/dsa/microchip/ksz_common.h | 2 -- drivers/net/dsa/microchip/lan937x_main.c | 7 +++---- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 10ab89ff93b65..dd603e7f1a639 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -188,8 +188,9 @@ static int ksz8795_change_mtu(struct ksz_device *dev, int frame_size) return ksz_rmw8(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE, ctrl2); } -static int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu) +static int ksz8_change_mtu(struct dsa_switch *ds, int port, int mtu) { + struct ksz_device *dev = ds->priv; u16 frame_size; if (!dsa_is_cpu_port(dev->ds, port)) @@ -2226,7 +2227,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .reset = ksz8_reset_switch, .init = ksz8_switch_init, .exit = ksz8_switch_exit, - .change_mtu = ksz8_change_mtu, }; const struct ksz_dev_ops ksz87xx_dev_ops = { @@ -2257,7 +2257,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { .reset = ksz8_reset_switch, .init = ksz8_switch_init, .exit = ksz8_switch_exit, - .change_mtu = ksz8_change_mtu, .pme_write8 = ksz8_pme_write8, .pme_pread8 = ksz8_pme_pread8, .pme_pwrite8 = ksz8_pme_pwrite8, @@ -2291,7 +2290,6 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .reset = ksz8_reset_switch, .init = ksz8_switch_init, .exit = ksz8_switch_exit, - .change_mtu = ksz8_change_mtu, .pme_write8 = ksz8_pme_write8, .pme_pread8 = ksz8_pme_pread8, .pme_pwrite8 = ksz8_pme_pwrite8, @@ -2332,7 +2330,7 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .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_change_mtu = ksz8_change_mtu, .port_max_mtu = ksz_max_mtu, .get_wol = ksz_get_wol, .set_wol = ksz_set_wol, @@ -2392,7 +2390,7 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .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_change_mtu = ksz8_change_mtu, .port_max_mtu = ksz_max_mtu, .get_wol = ksz_get_wol, .set_wol = ksz_set_wol, @@ -2452,7 +2450,7 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .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_change_mtu = ksz8_change_mtu, .port_max_mtu = ksz_max_mtu, .get_wol = ksz_get_wol, .set_wol = ksz_set_wol, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 11e6fd1f46ce0..f21a05a86b483 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -45,8 +45,9 @@ 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) +static int ksz9477_change_mtu(struct dsa_switch *ds, int port, int mtu) { + struct ksz_device *dev = ds->priv; u16 frame_size; if (!dsa_is_cpu_port(dev->ds, port)) @@ -1790,7 +1791,6 @@ 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, .pme_write8 = ksz_write8, .pme_pread8 = ksz_pread8, .pme_pwrite8 = ksz_pwrite8, @@ -1839,7 +1839,7 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .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_change_mtu = ksz9477_change_mtu, .port_max_mtu = ksz_max_mtu, .get_wol = ksz_get_wol, .set_wol = ksz_set_wol, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index cfca29007e36b..eb13d548ebff9 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3342,16 +3342,6 @@ void ksz_port_mirror_del(struct dsa_switch *ds, int port, dev->dev_ops->mirror_del(dev, port, mirror); } -int ksz_change_mtu(struct dsa_switch *ds, int port, int mtu) -{ - struct ksz_device *dev = ds->priv; - - if (!dev->dev_ops->change_mtu) - return -EOPNOTSUPP; - - return dev->dev_ops->change_mtu(dev, port, mtu); -} - int ksz_max_mtu(struct dsa_switch *ds, int port) { struct ksz_device *dev = ds->priv; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 80b3f2483e36d..0aa83c75c40a1 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -434,7 +434,6 @@ struct ksz_dev_ops { struct dsa_db db); 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 (*pme_write8)(struct ksz_device *dev, u32 reg, u8 value); int (*pme_pread8)(struct ksz_device *dev, int port, int offset, u8 *data); @@ -545,7 +544,6 @@ 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); bool ksz_support_eee(struct dsa_switch *ds, int port); diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index 19e444cb0a74a..feaaaafeace61 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -430,9 +430,9 @@ static void lan937x_config_cpu_port(struct dsa_switch *ds) } } -static int lan937x_change_mtu(struct ksz_device *dev, int port, int new_mtu) +static int lan937x_change_mtu(struct dsa_switch *ds, int port, int new_mtu) { - struct dsa_switch *ds = dev->ds; + struct ksz_device *dev = ds->priv; int ret; new_mtu += VLAN_ETH_HLEN + ETH_FCS_LEN; @@ -725,7 +725,6 @@ const struct ksz_dev_ops lan937x_dev_ops = { .fdb_del = ksz9477_fdb_del, .mdb_add = ksz9477_mdb_add, .mdb_del = ksz9477_mdb_del, - .change_mtu = lan937x_change_mtu, .config_cpu_port = lan937x_config_cpu_port, .tc_cbs_set_cinc = lan937x_tc_cbs_set_cinc, .enable_stp_addr = ksz9477_enable_stp_addr, @@ -770,7 +769,7 @@ const struct dsa_switch_ops lan937x_switch_ops = { .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_change_mtu = lan937x_change_mtu, .port_max_mtu = ksz_max_mtu, .get_wol = ksz_get_wol, .set_wol = ksz_set_wol, -- 2.53.0 From: Vladimir Oltean VLAN operations are handled through a common function that redirects the treatment to ksz_dev_ops callbacks. This level of indirection isn't needed since we now have a dsa_switch_ops for each kind of switch. Remove this useless layer of indirection by connecting directly the VLAN operations to the relevant dsa_switch_ops. Adapt their prototypes to match dsa_switch_ops expectations. Remove the now unused VLAN callbacks from ksz_dev_ops. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 39 ++++++++++++++------------------ drivers/net/dsa/microchip/ksz9477.c | 21 +++++++++-------- drivers/net/dsa/microchip/ksz9477.h | 6 ++--- drivers/net/dsa/microchip/ksz_common.c | 34 ---------------------------- drivers/net/dsa/microchip/ksz_common.h | 14 ------------ drivers/net/dsa/microchip/lan937x_main.c | 9 +++----- 6 files changed, 34 insertions(+), 89 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index dd603e7f1a639..94c8034a192a9 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -1446,9 +1446,11 @@ static int ksz8_fdb_del(struct ksz_device *dev, int port, return ksz8_del_sta_mac(dev, port, addr, vid); } -static int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag, +static int ksz8_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag, struct netlink_ext_ack *extack) { + struct ksz_device *dev = ds->priv; + if (ksz_is_ksz88x3(dev) || ksz_is_ksz8463(dev)) return -ENOTSUPP; @@ -1476,11 +1478,12 @@ 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, +static int ksz8_port_vlan_add(struct dsa_switch *ds, 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; @@ -1548,11 +1551,12 @@ 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, +static int ksz8_port_vlan_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { - u16 data, pvid; + struct ksz_device *dev = ds->priv; u8 fid, member, valid; + u16 data, pvid; if (ksz_is_ksz88x3(dev) || ksz_is_ksz8463(dev)) return -ENOTSUPP; @@ -2216,9 +2220,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .fdb_del = ksz8_fdb_del, .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_caps = ksz8_get_caps, @@ -2246,9 +2247,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { .fdb_del = ksz8_fdb_del, .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_caps = ksz8_get_caps, @@ -2279,9 +2277,6 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .fdb_del = ksz8_fdb_del, .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_caps = ksz8_get_caps, @@ -2318,9 +2313,9 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .port_pre_bridge_flags = ksz_port_pre_bridge_flags, .port_bridge_flags = ksz_port_bridge_flags, .port_fast_age = ksz8_flush_dyn_mac_table, - .port_vlan_filtering = ksz_port_vlan_filtering, - .port_vlan_add = ksz_port_vlan_add, - .port_vlan_del = ksz_port_vlan_del, + .port_vlan_filtering = ksz8_port_vlan_filtering, + .port_vlan_add = ksz8_port_vlan_add, + .port_vlan_del = ksz8_port_vlan_del, .port_fdb_dump = ksz_port_fdb_dump, .port_fdb_add = ksz_port_fdb_add, .port_fdb_del = ksz_port_fdb_del, @@ -2378,9 +2373,9 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .port_pre_bridge_flags = ksz_port_pre_bridge_flags, .port_bridge_flags = ksz_port_bridge_flags, .port_fast_age = ksz8_flush_dyn_mac_table, - .port_vlan_filtering = ksz_port_vlan_filtering, - .port_vlan_add = ksz_port_vlan_add, - .port_vlan_del = ksz_port_vlan_del, + .port_vlan_filtering = ksz8_port_vlan_filtering, + .port_vlan_add = ksz8_port_vlan_add, + .port_vlan_del = ksz8_port_vlan_del, .port_fdb_dump = ksz_port_fdb_dump, .port_fdb_add = ksz_port_fdb_add, .port_fdb_del = ksz_port_fdb_del, @@ -2438,9 +2433,9 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .port_pre_bridge_flags = ksz_port_pre_bridge_flags, .port_bridge_flags = ksz_port_bridge_flags, .port_fast_age = ksz8_flush_dyn_mac_table, - .port_vlan_filtering = ksz_port_vlan_filtering, - .port_vlan_add = ksz_port_vlan_add, - .port_vlan_del = ksz_port_vlan_del, + .port_vlan_filtering = ksz8_port_vlan_filtering, + .port_vlan_add = ksz8_port_vlan_add, + .port_vlan_del = ksz8_port_vlan_del, .port_fdb_dump = ksz_port_fdb_dump, .port_fdb_add = ksz_port_fdb_add, .port_fdb_del = ksz_port_fdb_del, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index f21a05a86b483..959229185df97 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -629,9 +629,11 @@ void ksz9477_flush_dyn_mac_table(struct dsa_switch *ds, int port) } } -int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port, +int ksz9477_port_vlan_filtering(struct dsa_switch *ds, 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); @@ -645,12 +647,13 @@ int ksz9477_port_vlan_filtering(struct ksz_device *dev, int port, return 0; } -int ksz9477_port_vlan_add(struct ksz_device *dev, int port, +int ksz9477_port_vlan_add(struct dsa_switch *ds, 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; + struct ksz_device *dev = ds->priv; + u32 vlan_table[3]; int err; err = ksz9477_get_vlan_table(dev, vlan->vid, vlan_table); @@ -681,10 +684,11 @@ int ksz9477_port_vlan_add(struct ksz_device *dev, int port, return 0; } -int ksz9477_port_vlan_del(struct ksz_device *dev, int port, +int ksz9477_port_vlan_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; + struct ksz_device *dev = ds->priv; u32 vlan_table[3]; u16 pvid; @@ -1780,9 +1784,6 @@ 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, .mirror_add = ksz9477_port_mirror_add, .mirror_del = ksz9477_port_mirror_del, .get_caps = ksz9477_get_caps, @@ -1827,9 +1828,9 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .port_pre_bridge_flags = ksz_port_pre_bridge_flags, .port_bridge_flags = ksz_port_bridge_flags, .port_fast_age = ksz9477_flush_dyn_mac_table, - .port_vlan_filtering = ksz_port_vlan_filtering, - .port_vlan_add = ksz_port_vlan_add, - .port_vlan_del = ksz_port_vlan_del, + .port_vlan_filtering = ksz9477_port_vlan_filtering, + .port_vlan_add = ksz9477_port_vlan_add, + .port_vlan_del = ksz9477_port_vlan_del, .port_fdb_dump = ksz_port_fdb_dump, .port_fdb_add = ksz_port_fdb_add, .port_fdb_del = ksz_port_fdb_del, diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h index 8012904a21308..75a7b2bfc7976 100644 --- a/drivers/net/dsa/microchip/ksz9477.h +++ b/drivers/net/dsa/microchip/ksz9477.h @@ -19,12 +19,12 @@ 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, +int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag, struct netlink_ext_ack *extack); -int ksz9477_port_vlan_add(struct ksz_device *dev, int port, +int ksz9477_port_vlan_add(struct dsa_switch *ds, 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, +int ksz9477_port_vlan_del(struct dsa_switch *ds, 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, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index eb13d548ebff9..07d1d58113f05 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3287,40 +3287,6 @@ int ksz_port_bridge_flags(struct dsa_switch *ds, int port, return 0; } -int ksz_port_vlan_filtering(struct dsa_switch *ds, int port, - bool flag, struct netlink_ext_ack *extack) -{ - struct ksz_device *dev = ds->priv; - - if (!dev->dev_ops->vlan_filtering) - return -EOPNOTSUPP; - - return dev->dev_ops->vlan_filtering(dev, port, flag, extack); -} - -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; - - if (!dev->dev_ops->vlan_add) - return -EOPNOTSUPP; - - return dev->dev_ops->vlan_add(dev, port, vlan, extack); -} - -int ksz_port_vlan_del(struct dsa_switch *ds, int port, - const struct switchdev_obj_port_vlan *vlan) -{ - struct ksz_device *dev = ds->priv; - - if (!dev->dev_ops->vlan_del) - return -EOPNOTSUPP; - - return dev->dev_ops->vlan_del(dev, port, 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) diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 0aa83c75c40a1..d07b3f5918f8e 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -408,13 +408,6 @@ 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); int (*mirror_add)(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror, bool ingress, struct netlink_ext_ack *extack); @@ -505,13 +498,6 @@ int ksz_port_pre_bridge_flags(struct dsa_switch *ds, int port, int ksz_port_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, struct netlink_ext_ack *extack); -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_fdb_add(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db); diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index feaaaafeace61..be6a457ee8e4b 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -713,9 +713,6 @@ const struct ksz_dev_ops lan937x_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, .mirror_add = ksz9477_port_mirror_add, .mirror_del = ksz9477_port_mirror_del, .get_caps = lan937x_phylink_get_caps, @@ -757,9 +754,9 @@ const struct dsa_switch_ops lan937x_switch_ops = { .port_pre_bridge_flags = ksz_port_pre_bridge_flags, .port_bridge_flags = ksz_port_bridge_flags, .port_fast_age = ksz9477_flush_dyn_mac_table, - .port_vlan_filtering = ksz_port_vlan_filtering, - .port_vlan_add = ksz_port_vlan_add, - .port_vlan_del = ksz_port_vlan_del, + .port_vlan_filtering = ksz9477_port_vlan_filtering, + .port_vlan_add = ksz9477_port_vlan_add, + .port_vlan_del = ksz9477_port_vlan_del, .port_fdb_dump = ksz_port_fdb_dump, .port_fdb_add = ksz_port_fdb_add, .port_fdb_del = ksz_port_fdb_del, -- 2.53.0 From: Vladimir Oltean FDB and MDB operations are handled through a common function that redirects the treatment to ksz_dev_ops callbacks. This layer of indirection isn't needed since we now have a dsa_switch_ops for each kind of switch. Remove one indirection layer for KSZ switches, by connecting the ksz_dev_ops :: fdb_dump(), fdb_add(), fdb_del(), mdb_add() and mdb_del() operations directly to dsa_switch_ops. Remove the FDB and MDB operations from ksz_dev_ops. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 64 +++++++++++++------------------- drivers/net/dsa/microchip/ksz9477.c | 42 ++++++++++----------- drivers/net/dsa/microchip/ksz9477.h | 10 ++--- drivers/net/dsa/microchip/ksz_common.c | 59 ----------------------------- drivers/net/dsa/microchip/ksz_common.h | 26 ------------- drivers/net/dsa/microchip/lan937x_main.c | 15 +++----- 6 files changed, 56 insertions(+), 160 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 94c8034a192a9..83795fd66aab2 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -1315,9 +1315,10 @@ static void ksz8_flush_dyn_mac_table(struct dsa_switch *ds, int port) } } -static int ksz8_fdb_dump(struct ksz_device *dev, int port, +static int ksz8_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, void *data) { + struct ksz_device *dev = ds->priv; u8 mac[ETH_ALEN]; u8 src_port, fid; u16 entries = 0; @@ -1420,30 +1421,30 @@ static int ksz8_del_sta_mac(struct ksz_device *dev, int port, return ksz8_w_sta_mac_table(dev, index, &alu); } -static int ksz8_mdb_add(struct ksz_device *dev, int port, +static int ksz8_mdb_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { - return ksz8_add_sta_mac(dev, port, mdb->addr, mdb->vid); + return ksz8_add_sta_mac(ds->priv, port, mdb->addr, mdb->vid); } -static int ksz8_mdb_del(struct ksz_device *dev, int port, +static int ksz8_mdb_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db) { - return ksz8_del_sta_mac(dev, port, mdb->addr, mdb->vid); + return ksz8_del_sta_mac(ds->priv, port, mdb->addr, mdb->vid); } -static int ksz8_fdb_add(struct ksz_device *dev, int port, +static int ksz8_fdb_add(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db) { - return ksz8_add_sta_mac(dev, port, addr, vid); + return ksz8_add_sta_mac(ds->priv, port, addr, vid); } -static int ksz8_fdb_del(struct ksz_device *dev, int port, +static int ksz8_fdb_del(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db) { - return ksz8_del_sta_mac(dev, port, addr, vid); + return ksz8_del_sta_mac(ds->priv, port, addr, vid); } static int ksz8_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag, @@ -2215,11 +2216,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .r_mib_stat64 = ksz88xx_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .fdb_dump = ksz8_fdb_dump, - .fdb_add = ksz8_fdb_add, - .fdb_del = ksz8_fdb_del, - .mdb_add = ksz8_mdb_add, - .mdb_del = ksz8_mdb_del, .mirror_add = ksz8_port_mirror_add, .mirror_del = ksz8_port_mirror_del, .get_caps = ksz8_get_caps, @@ -2242,11 +2238,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { .r_mib_stat64 = ksz_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .fdb_dump = ksz8_fdb_dump, - .fdb_add = ksz8_fdb_add, - .fdb_del = ksz8_fdb_del, - .mdb_add = ksz8_mdb_add, - .mdb_del = ksz8_mdb_del, .mirror_add = ksz8_port_mirror_add, .mirror_del = ksz8_port_mirror_del, .get_caps = ksz8_get_caps, @@ -2272,11 +2263,6 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .r_mib_stat64 = ksz88xx_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .fdb_dump = ksz8_fdb_dump, - .fdb_add = ksz8_fdb_add, - .fdb_del = ksz8_fdb_del, - .mdb_add = ksz8_mdb_add, - .mdb_del = ksz8_mdb_del, .mirror_add = ksz8_port_mirror_add, .mirror_del = ksz8_port_mirror_del, .get_caps = ksz8_get_caps, @@ -2316,11 +2302,11 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .port_vlan_filtering = ksz8_port_vlan_filtering, .port_vlan_add = ksz8_port_vlan_add, .port_vlan_del = ksz8_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_fdb_dump = ksz8_fdb_dump, + .port_fdb_add = ksz8_fdb_add, + .port_fdb_del = ksz8_fdb_del, + .port_mdb_add = ksz8_mdb_add, + .port_mdb_del = ksz8_mdb_del, .port_mirror_add = ksz_port_mirror_add, .port_mirror_del = ksz_port_mirror_del, .get_stats64 = ksz_get_stats64, @@ -2376,11 +2362,11 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .port_vlan_filtering = ksz8_port_vlan_filtering, .port_vlan_add = ksz8_port_vlan_add, .port_vlan_del = ksz8_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_fdb_dump = ksz8_fdb_dump, + .port_fdb_add = ksz8_fdb_add, + .port_fdb_del = ksz8_fdb_del, + .port_mdb_add = ksz8_mdb_add, + .port_mdb_del = ksz8_mdb_del, .port_mirror_add = ksz_port_mirror_add, .port_mirror_del = ksz_port_mirror_del, .get_stats64 = ksz_get_stats64, @@ -2436,11 +2422,11 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .port_vlan_filtering = ksz8_port_vlan_filtering, .port_vlan_add = ksz8_port_vlan_add, .port_vlan_del = ksz8_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_fdb_dump = ksz8_fdb_dump, + .port_fdb_add = ksz8_fdb_add, + .port_fdb_del = ksz8_fdb_del, + .port_mdb_add = ksz8_mdb_add, + .port_mdb_del = ksz8_mdb_del, .port_mirror_add = ksz_port_mirror_add, .port_mirror_del = ksz_port_mirror_del, .get_stats64 = ksz_get_stats64, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 959229185df97..69a4fb683b3a1 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -718,9 +718,10 @@ int ksz9477_port_vlan_del(struct dsa_switch *ds, int port, return 0; } -int ksz9477_fdb_add(struct ksz_device *dev, int port, +int ksz9477_fdb_add(struct dsa_switch *ds, 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; @@ -774,9 +775,10 @@ int ksz9477_fdb_add(struct ksz_device *dev, int port, return ret; } -int ksz9477_fdb_del(struct ksz_device *dev, int port, +int ksz9477_fdb_del(struct dsa_switch *ds, 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; @@ -863,13 +865,14 @@ static void ksz9477_convert_alu(struct alu_struct *alu, u32 *alu_table) alu->mac[5] = alu_table[3] & 0xFF; } -int ksz9477_fdb_dump(struct ksz_device *dev, int port, +int ksz9477_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, void *data) { - int ret = 0; - u32 ksz_data; - u32 alu_table[4]; + struct ksz_device *dev = ds->priv; struct alu_struct alu; + u32 alu_table[4]; + u32 ksz_data; + int ret = 0; int timeout; mutex_lock(&dev->alu_mutex); @@ -917,9 +920,10 @@ int ksz9477_fdb_dump(struct ksz_device *dev, int port, return ret; } -int ksz9477_mdb_add(struct ksz_device *dev, int port, +int ksz9477_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; u32 static_table[4]; const u8 *shifts; const u32 *masks; @@ -996,16 +1000,17 @@ int ksz9477_mdb_add(struct ksz_device *dev, int port, return err; } -int ksz9477_mdb_del(struct ksz_device *dev, int port, +int ksz9477_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; u32 static_table[4]; + u32 mac_hi, mac_lo; const u8 *shifts; const u32 *masks; - u32 data; - int index; int ret = 0; - u32 mac_hi, mac_lo; + int index; + u32 data; shifts = dev->info->shifts; masks = dev->info->masks; @@ -1787,11 +1792,6 @@ const struct ksz_dev_ops ksz9477_dev_ops = { .mirror_add = ksz9477_port_mirror_add, .mirror_del = ksz9477_port_mirror_del, .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, .pme_write8 = ksz_write8, .pme_pread8 = ksz_pread8, .pme_pwrite8 = ksz_pwrite8, @@ -1831,11 +1831,11 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .port_vlan_filtering = ksz9477_port_vlan_filtering, .port_vlan_add = ksz9477_port_vlan_add, .port_vlan_del = ksz9477_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_fdb_dump = ksz9477_fdb_dump, + .port_fdb_add = ksz9477_fdb_add, + .port_fdb_del = ksz9477_fdb_del, + .port_mdb_add = ksz9477_mdb_add, + .port_mdb_del = ksz9477_mdb_del, .port_mirror_add = ksz_port_mirror_add, .port_mirror_del = ksz_port_mirror_del, .get_stats64 = ksz_get_stats64, diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h index 75a7b2bfc7976..39f042e56f365 100644 --- a/drivers/net/dsa/microchip/ksz9477.h +++ b/drivers/net/dsa/microchip/ksz9477.h @@ -33,15 +33,15 @@ void ksz9477_port_mirror_del(struct ksz_device *dev, int port, struct dsa_mall_mirror_tc_entry *mirror); int ksz9477_errata_monitor(struct ksz_device *dev, int port, u64 tx_late_col); -int ksz9477_fdb_dump(struct ksz_device *dev, int port, +int ksz9477_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb, void *data); -int ksz9477_fdb_add(struct ksz_device *dev, int port, +int ksz9477_fdb_add(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db); -int ksz9477_fdb_del(struct ksz_device *dev, int port, +int ksz9477_fdb_del(struct dsa_switch *ds, int port, const unsigned char *addr, u16 vid, struct dsa_db db); -int ksz9477_mdb_add(struct ksz_device *dev, int port, +int ksz9477_mdb_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db); -int ksz9477_mdb_del(struct ksz_device *dev, int port, +int ksz9477_mdb_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_mdb *mdb, struct dsa_db db); int ksz9477_enable_stp_addr(struct ksz_device *dev); void ksz9477_port_queue_split(struct ksz_device *dev, int port); diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 07d1d58113f05..d17ce88d49471 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3085,65 +3085,6 @@ void ksz_port_bridge_leave(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) -{ - struct ksz_device *dev = ds->priv; - - if (!dev->dev_ops->fdb_add) - return -EOPNOTSUPP; - - return dev->dev_ops->fdb_add(dev, port, addr, vid, db); -} - -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; - - if (!dev->dev_ops->fdb_del) - return -EOPNOTSUPP; - - return dev->dev_ops->fdb_del(dev, port, addr, vid, db); -} - -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; - - if (!dev->dev_ops->fdb_dump) - return -EOPNOTSUPP; - - return dev->dev_ops->fdb_dump(dev, port, cb, data); -} - -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; - - if (!dev->dev_ops->mdb_add) - return -EOPNOTSUPP; - - return dev->dev_ops->mdb_add(dev, port, mdb, db); -} - -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; - - if (!dev->dev_ops->mdb_del) - return -EOPNOTSUPP; - - return dev->dev_ops->mdb_del(dev, port, mdb, db); -} - static int ksz9477_set_default_prio_queue_mapping(struct ksz_device *dev, int port) { diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index d07b3f5918f8e..fe3b2dad3d684 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -413,18 +413,6 @@ 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); - int (*mdb_del)(struct ksz_device *dev, int port, - const struct switchdev_obj_port_mdb *mdb, - struct dsa_db db); void (*get_caps)(struct ksz_device *dev, int port, struct phylink_config *config); int (*pme_write8)(struct ksz_device *dev, u32 reg, u8 value); @@ -498,20 +486,6 @@ int ksz_port_pre_bridge_flags(struct dsa_switch *ds, int port, int ksz_port_bridge_flags(struct dsa_switch *ds, int port, struct switchdev_brport_flags flags, struct netlink_ext_ack *extack); -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); void ksz_phylink_get_caps(struct dsa_switch *ds, int port, struct phylink_config *config); diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index be6a457ee8e4b..aa428353818d8 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -717,11 +717,6 @@ const struct ksz_dev_ops lan937x_dev_ops = { .mirror_del = ksz9477_port_mirror_del, .get_caps = lan937x_phylink_get_caps, .setup_rgmii_delay = lan937x_setup_rgmii_delay, - .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, .config_cpu_port = lan937x_config_cpu_port, .tc_cbs_set_cinc = lan937x_tc_cbs_set_cinc, .enable_stp_addr = ksz9477_enable_stp_addr, @@ -757,11 +752,11 @@ const struct dsa_switch_ops lan937x_switch_ops = { .port_vlan_filtering = ksz9477_port_vlan_filtering, .port_vlan_add = ksz9477_port_vlan_add, .port_vlan_del = ksz9477_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_fdb_dump = ksz9477_fdb_dump, + .port_fdb_add = ksz9477_fdb_add, + .port_fdb_del = ksz9477_fdb_del, + .port_mdb_add = ksz9477_mdb_add, + .port_mdb_del = ksz9477_mdb_del, .port_mirror_add = ksz_port_mirror_add, .port_mirror_del = ksz_port_mirror_del, .get_stats64 = ksz_get_stats64, -- 2.53.0 From: Vladimir Oltean Mirror operations are handled through a common function that redirects the treatment to ksz_dev_ops callbacks. This layer of indirection isn't needed since we now have a dsa_switch_ops for each switch family. Remove this indirection layer for KSZ switches, by connecting the ksz_dev_ops :: mirror_add() and mirror_del() operations directly to dsa_switch_ops. Remove the now unused mirror callbacks from ksz_dev_ops. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 24 ++++++++++-------------- drivers/net/dsa/microchip/ksz9477.c | 12 ++++++------ drivers/net/dsa/microchip/ksz9477.h | 4 ++-- drivers/net/dsa/microchip/ksz_common.c | 21 --------------------- drivers/net/dsa/microchip/ksz_common.h | 10 ---------- drivers/net/dsa/microchip/lan937x_main.c | 6 ++---- 6 files changed, 20 insertions(+), 57 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 83795fd66aab2..38876e1779564 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -1585,10 +1585,11 @@ static int ksz8_port_vlan_del(struct dsa_switch *ds, int port, return 0; } -static int ksz8_port_mirror_add(struct ksz_device *dev, int port, +static int ksz8_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 offset = P_MIRROR_CTRL; if (ksz_is_ksz8463(dev)) @@ -1611,9 +1612,10 @@ 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, +static void ksz8_port_mirror_del(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror) { + struct ksz_device *dev = ds->priv; int offset = P_MIRROR_CTRL; u8 data; @@ -2216,8 +2218,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .r_mib_stat64 = ksz88xx_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .mirror_add = ksz8_port_mirror_add, - .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, @@ -2238,8 +2238,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { .r_mib_stat64 = ksz_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .mirror_add = ksz8_port_mirror_add, - .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, @@ -2263,8 +2261,6 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .r_mib_stat64 = ksz88xx_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .mirror_add = ksz8_port_mirror_add, - .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, @@ -2307,8 +2303,8 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .port_fdb_del = ksz8_fdb_del, .port_mdb_add = ksz8_mdb_add, .port_mdb_del = ksz8_mdb_del, - .port_mirror_add = ksz_port_mirror_add, - .port_mirror_del = ksz_port_mirror_del, + .port_mirror_add = ksz8_port_mirror_add, + .port_mirror_del = ksz8_port_mirror_del, .get_stats64 = ksz_get_stats64, .get_pause_stats = ksz_get_pause_stats, .port_change_mtu = ksz8_change_mtu, @@ -2367,8 +2363,8 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .port_fdb_del = ksz8_fdb_del, .port_mdb_add = ksz8_mdb_add, .port_mdb_del = ksz8_mdb_del, - .port_mirror_add = ksz_port_mirror_add, - .port_mirror_del = ksz_port_mirror_del, + .port_mirror_add = ksz8_port_mirror_add, + .port_mirror_del = ksz8_port_mirror_del, .get_stats64 = ksz_get_stats64, .get_pause_stats = ksz_get_pause_stats, .port_change_mtu = ksz8_change_mtu, @@ -2427,8 +2423,8 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .port_fdb_del = ksz8_fdb_del, .port_mdb_add = ksz8_mdb_add, .port_mdb_del = ksz8_mdb_del, - .port_mirror_add = ksz_port_mirror_add, - .port_mirror_del = ksz_port_mirror_del, + .port_mirror_add = ksz8_port_mirror_add, + .port_mirror_del = ksz8_port_mirror_del, .get_stats64 = ksz_get_stats64, .get_pause_stats = ksz_get_pause_stats, .port_change_mtu = ksz8_change_mtu, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 69a4fb683b3a1..14ee9686ca0ab 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1080,10 +1080,11 @@ int ksz9477_mdb_del(struct dsa_switch *ds, int port, return ret; } -int ksz9477_port_mirror_add(struct ksz_device *dev, int port, +int ksz9477_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; u8 data; int p; @@ -1119,9 +1120,10 @@ int ksz9477_port_mirror_add(struct ksz_device *dev, int port, return 0; } -void ksz9477_port_mirror_del(struct ksz_device *dev, int port, +void ksz9477_port_mirror_del(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror) { + struct ksz_device *dev = ds->priv; bool in_use = false; u8 data; int p; @@ -1789,8 +1791,6 @@ 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, - .mirror_add = ksz9477_port_mirror_add, - .mirror_del = ksz9477_port_mirror_del, .get_caps = ksz9477_get_caps, .pme_write8 = ksz_write8, .pme_pread8 = ksz_pread8, @@ -1836,8 +1836,8 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .port_fdb_del = ksz9477_fdb_del, .port_mdb_add = ksz9477_mdb_add, .port_mdb_del = ksz9477_mdb_del, - .port_mirror_add = ksz_port_mirror_add, - .port_mirror_del = ksz_port_mirror_del, + .port_mirror_add = ksz9477_port_mirror_add, + .port_mirror_del = ksz9477_port_mirror_del, .get_stats64 = ksz_get_stats64, .get_pause_stats = ksz_get_pause_stats, .port_change_mtu = ksz9477_change_mtu, diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h index 39f042e56f365..599db0a6ba2e3 100644 --- a/drivers/net/dsa/microchip/ksz9477.h +++ b/drivers/net/dsa/microchip/ksz9477.h @@ -26,10 +26,10 @@ int ksz9477_port_vlan_add(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack); int ksz9477_port_vlan_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan); -int ksz9477_port_mirror_add(struct ksz_device *dev, int port, +int ksz9477_port_mirror_add(struct dsa_switch *ds, 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, +void ksz9477_port_mirror_del(struct dsa_switch *ds, int port, struct dsa_mall_mirror_tc_entry *mirror); int ksz9477_errata_monitor(struct ksz_device *dev, int port, u64 tx_late_col); diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index d17ce88d49471..ad7615849c7a4 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3228,27 +3228,6 @@ int ksz_port_bridge_flags(struct dsa_switch *ds, int port, return 0; } -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; - - 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); -} - int ksz_max_mtu(struct dsa_switch *ds, int port) { struct ksz_device *dev = ds->priv; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index fe3b2dad3d684..94eb79fa34392 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -408,11 +408,6 @@ 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 (*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 (*get_caps)(struct ksz_device *dev, int port, struct phylink_config *config); int (*pme_write8)(struct ksz_device *dev, u32 reg, u8 value); @@ -499,11 +494,6 @@ void ksz_phylink_mac_link_down(struct phylink_config *config, unsigned int mode, phy_interface_t interface); -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_max_mtu(struct dsa_switch *ds, int port); bool ksz_support_eee(struct dsa_switch *ds, int port); diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index aa428353818d8..621139a2c3025 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -713,8 +713,6 @@ const struct ksz_dev_ops lan937x_dev_ops = { .r_mib_stat64 = ksz_r_mib_stats64, .freeze_mib = ksz9477_freeze_mib, .port_init_cnt = ksz9477_port_init_cnt, - .mirror_add = ksz9477_port_mirror_add, - .mirror_del = ksz9477_port_mirror_del, .get_caps = lan937x_phylink_get_caps, .setup_rgmii_delay = lan937x_setup_rgmii_delay, .config_cpu_port = lan937x_config_cpu_port, @@ -757,8 +755,8 @@ const struct dsa_switch_ops lan937x_switch_ops = { .port_fdb_del = ksz9477_fdb_del, .port_mdb_add = ksz9477_mdb_add, .port_mdb_del = ksz9477_mdb_del, - .port_mirror_add = ksz_port_mirror_add, - .port_mirror_del = ksz_port_mirror_del, + .port_mirror_add = ksz9477_port_mirror_add, + .port_mirror_del = ksz9477_port_mirror_del, .get_stats64 = ksz_get_stats64, .get_pause_stats = ksz_get_pause_stats, .port_change_mtu = lan937x_change_mtu, -- 2.53.0 From: Vladimir Oltean ksz_phylink_get_caps() is a bit different from other generic methods. It has a dev_ops->get_caps() call in the middle of the function, and it does other stuff before (set some supported_interfaces) and after (set lpi_interfaces from supported_interfaces). Whereas the dev_ops->get_caps() methods set mac_capabilities and (optionally) logically OR the supported_interfaces with that of the PCS. The idea is that this can be expressed simpler, and avoid a indirect function call to dev_ops->get_caps(). If we tail-call the common ksz_phylink_get_caps() from individual phylink_get_caps() methods, we do reorder the settings, but in an inconsequential way (the transfer from supported_interfaces to lpi_interfaces still sees a complete list of the supported_interfaces). Remove the no longer used get_caps() callbacl the ksz_dev_ops. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 17 +++++++++-------- drivers/net/dsa/microchip/ksz9477.c | 11 +++++++---- drivers/net/dsa/microchip/ksz_common.c | 3 --- drivers/net/dsa/microchip/ksz_common.h | 2 -- drivers/net/dsa/microchip/lan937x_main.c | 9 ++++++--- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 38876e1779564..825133e9ce6e6 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -1995,9 +1995,11 @@ static int ksz8_setup(struct dsa_switch *ds) return ret; } -static void ksz8_get_caps(struct ksz_device *dev, int port, - struct phylink_config *config) +static void ksz8_phylink_get_caps(struct dsa_switch *ds, int port, + struct phylink_config *config) { + struct ksz_device *dev = ds->priv; + config->mac_capabilities = MAC_10 | MAC_100; /* Silicon Errata Sheet (DS80000830A): @@ -2011,6 +2013,8 @@ static void ksz8_get_caps(struct ksz_device *dev, int port, /* Asym pause is not supported on KSZ8863 and KSZ8873 */ if (!ksz_is_ksz88x3(dev)) config->mac_capabilities |= MAC_ASYM_PAUSE; + + ksz_phylink_get_caps(ds, port, config); } static u32 ksz8_get_port_addr(int port, int offset) @@ -2218,7 +2222,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .r_mib_stat64 = ksz88xx_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .get_caps = ksz8_get_caps, .config_cpu_port = ksz8_config_cpu_port, .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, @@ -2238,7 +2241,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { .r_mib_stat64 = ksz_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .get_caps = ksz8_get_caps, .config_cpu_port = ksz8_config_cpu_port, .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, @@ -2261,7 +2263,6 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .r_mib_stat64 = ksz88xx_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .get_caps = ksz8_get_caps, .config_cpu_port = ksz8_config_cpu_port, .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, @@ -2280,7 +2281,7 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, - .phylink_get_caps = ksz_phylink_get_caps, + .phylink_get_caps = ksz8_phylink_get_caps, .port_setup = ksz_port_setup, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, @@ -2340,7 +2341,7 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, - .phylink_get_caps = ksz_phylink_get_caps, + .phylink_get_caps = ksz8_phylink_get_caps, .port_setup = ksz_port_setup, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, @@ -2400,7 +2401,7 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, - .phylink_get_caps = ksz_phylink_get_caps, + .phylink_get_caps = ksz8_phylink_get_caps, .port_setup = ksz_port_setup, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 14ee9686ca0ab..65fd07ef73ad0 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1165,9 +1165,11 @@ static phy_interface_t ksz9477_get_interface(struct ksz_device *dev, int port) return interface; } -static void ksz9477_get_caps(struct ksz_device *dev, int port, - struct phylink_config *config) +static void ksz9477_phylink_get_caps(struct dsa_switch *ds, int port, + struct phylink_config *config) { + struct ksz_device *dev = ds->priv; + config->mac_capabilities = MAC_10 | MAC_100 | MAC_ASYM_PAUSE | MAC_SYM_PAUSE; @@ -1181,6 +1183,8 @@ static void ksz9477_get_caps(struct ksz_device *dev, int port, config->supported_interfaces, p->pcs->supported_interfaces); } + + ksz_phylink_get_caps(ds, port, config); } static int ksz9477_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) @@ -1791,7 +1795,6 @@ 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, - .get_caps = ksz9477_get_caps, .pme_write8 = ksz_write8, .pme_pread8 = ksz_pread8, .pme_pwrite8 = ksz_pwrite8, @@ -1812,7 +1815,7 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, - .phylink_get_caps = ksz_phylink_get_caps, + .phylink_get_caps = ksz9477_phylink_get_caps, .port_setup = ksz_port_setup, .set_ageing_time = ksz9477_set_ageing_time, .get_strings = ksz_get_strings, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index ad7615849c7a4..4a7bcd1a93927 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -1995,9 +1995,6 @@ void ksz_phylink_get_caps(struct dsa_switch *ds, int port, config->supported_interfaces); } - if (dev->dev_ops->get_caps) - dev->dev_ops->get_caps(dev, port, config); - if (ds->ops->support_eee && ds->ops->support_eee(ds, port)) { memcpy(config->lpi_interfaces, config->supported_interfaces, sizeof(config->lpi_interfaces)); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 94eb79fa34392..f6dad256a550f 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -408,8 +408,6 @@ 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); - void (*get_caps)(struct ksz_device *dev, int port, - struct phylink_config *config); int (*pme_write8)(struct ksz_device *dev, u32 reg, u8 value); int (*pme_pread8)(struct ksz_device *dev, int port, int offset, u8 *data); diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index 621139a2c3025..f84548168b371 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -575,9 +575,11 @@ static void lan937x_set_rgmii_rx_delay(struct ksz_device *dev, int port) lan937x_set_tune_adj(dev, port, REG_PORT_XMII_CTRL_4, val); } -static void lan937x_phylink_get_caps(struct ksz_device *dev, int port, +static void lan937x_phylink_get_caps(struct dsa_switch *ds, int port, struct phylink_config *config) { + struct ksz_device *dev = ds->priv; + config->mac_capabilities = MAC_100FD; if (dev->info->supports_rgmii[port]) { @@ -588,6 +590,8 @@ static void lan937x_phylink_get_caps(struct ksz_device *dev, int port, config->mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE | MAC_100HD | MAC_10; } + + ksz_phylink_get_caps(ds, port, config); } static void lan937x_setup_rgmii_delay(struct ksz_device *dev, int port) @@ -713,7 +717,6 @@ const struct ksz_dev_ops lan937x_dev_ops = { .r_mib_stat64 = ksz_r_mib_stats64, .freeze_mib = ksz9477_freeze_mib, .port_init_cnt = ksz9477_port_init_cnt, - .get_caps = lan937x_phylink_get_caps, .setup_rgmii_delay = lan937x_setup_rgmii_delay, .config_cpu_port = lan937x_config_cpu_port, .tc_cbs_set_cinc = lan937x_tc_cbs_set_cinc, @@ -731,7 +734,7 @@ const struct dsa_switch_ops lan937x_switch_ops = { .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, - .phylink_get_caps = ksz_phylink_get_caps, + .phylink_get_caps = lan937x_phylink_get_caps, .port_setup = ksz_port_setup, .set_ageing_time = lan937x_set_ageing_time, .get_strings = ksz_get_strings, -- 2.53.0 From: Vladimir Oltean The ksz_switch driver is one of the few which reset the switch when unbinding the driver or shutting down - in the same category with ar9331_sw_remove(), bcm_sf2_sw_remove(), and ks8995_remove(), vsc73xx_remove() and lan9303_remove(). I don't think there exists any requirement to do this, and in fact it does create complications for WoL, as the code already shows. My issue with this logic is that it is the only thing keeping dev_ops->reset() necessary, which I would like to remove after individual KSZ switch families get their own setup() and teardown() methods that don't go through dev_ops. Don't reset the switch when unbinding the driver or shutting down. Remove the exit callbacks from the ksz_dev_ops. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 8 -------- drivers/net/dsa/microchip/ksz9477.c | 6 ------ drivers/net/dsa/microchip/ksz_common.c | 32 ++++++++------------------------ drivers/net/dsa/microchip/ksz_common.h | 1 - drivers/net/dsa/microchip/lan937x_main.c | 6 ------ 5 files changed, 8 insertions(+), 45 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 825133e9ce6e6..ccbc3480717f0 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -2109,11 +2109,6 @@ static int ksz8_switch_init(struct ksz_device *dev) return 0; } -static void ksz8_switch_exit(struct ksz_device *dev) -{ - ksz8_reset_switch(dev); -} - static enum dsa_tag_protocol ksz8463_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -2226,7 +2221,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, .init = ksz8_switch_init, - .exit = ksz8_switch_exit, }; const struct ksz_dev_ops ksz87xx_dev_ops = { @@ -2245,7 +2239,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, .init = ksz8_switch_init, - .exit = ksz8_switch_exit, .pme_write8 = ksz8_pme_write8, .pme_pread8 = ksz8_pme_pread8, .pme_pwrite8 = ksz8_pme_pwrite8, @@ -2267,7 +2260,6 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .enable_stp_addr = ksz8_enable_stp_addr, .reset = ksz8_reset_switch, .init = ksz8_switch_init, - .exit = ksz8_switch_exit, .pme_write8 = ksz8_pme_write8, .pme_pread8 = ksz8_pme_pread8, .pme_pwrite8 = ksz8_pme_pwrite8, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 65fd07ef73ad0..88a5ff62aae89 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1624,11 +1624,6 @@ static int ksz9477_switch_init(struct ksz_device *dev) return 0; } -static void ksz9477_switch_exit(struct ksz_device *dev) -{ - ksz9477_reset_switch(dev); -} - static enum dsa_tag_protocol ksz9477_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -1803,7 +1798,6 @@ const struct ksz_dev_ops ksz9477_dev_ops = { .enable_stp_addr = ksz9477_enable_stp_addr, .reset = ksz9477_reset_switch, .init = ksz9477_switch_init, - .exit = ksz9477_switch_exit, .pcs_create = ksz9477_pcs_create, }; diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 4a7bcd1a93927..78d77a60a6ce2 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -4170,16 +4170,15 @@ int ksz_set_wol(struct dsa_switch *ds, int port, * the wol_enabled flag accordingly to reflect whether WoL is active on any * port. */ -static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) +static void ksz_wol_pre_shutdown(struct ksz_device *dev) { const struct ksz_dev_ops *ops = dev->dev_ops; const u16 *regs = dev->info->regs; u8 pme_pin_en = PME_ENABLE; + bool wol_enabled = false; struct dsa_port *dp; int ret; - *wol_enabled = false; - if (!is_ksz9477(dev) && !ksz_is_ksz87xx(dev)) return; @@ -4192,7 +4191,7 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) ret = ops->pme_pread8(dev, dp->index, regs[REG_PORT_PME_CTRL], &pme_ctrl); if (!ret && pme_ctrl) - *wol_enabled = true; + wol_enabled = true; /* make sure there are no pending wake events which would * prevent the device from going to sleep/shutdown. @@ -4201,7 +4200,7 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) } /* Now we are save to enable PME pin. */ - if (*wol_enabled) { + if (wol_enabled) { if (dev->pme_active_high) pme_pin_en |= PME_POLARITY; ops->pme_write8(dev, regs[REG_SW_PME_CTRL], pme_pin_en); @@ -4480,20 +4479,12 @@ EXPORT_SYMBOL(ksz_switch_alloc); * @dev: The switch device structure. * * This function is responsible for initiating a shutdown sequence for the - * switch device. It invokes the reset operation defined in the device - * operations, if available, to reset the switch. Subsequently, it calls the - * DSA framework's shutdown function to ensure a proper shutdown of the DSA - * switch. + * switch device. Subsequently, it calls the DSA framework's shutdown function + * to ensure a proper shutdown of the DSA switch. */ void ksz_switch_shutdown(struct ksz_device *dev) { - bool wol_enabled = false; - - ksz_wol_pre_shutdown(dev, &wol_enabled); - - if (dev->dev_ops->reset && !wol_enabled) - dev->dev_ops->reset(dev); - + ksz_wol_pre_shutdown(dev); dsa_switch_shutdown(dev->ds); } EXPORT_SYMBOL(ksz_switch_shutdown); @@ -4943,10 +4934,8 @@ int ksz_switch_register(struct ksz_device *dev) } ret = dsa_register_switch(dev->ds); - if (ret) { - dev->dev_ops->exit(dev); + if (ret) return ret; - } /* Read MIB counters every 30 seconds to avoid overflow. */ dev->mib_read_interval = msecs_to_jiffies(5000); @@ -4966,12 +4955,7 @@ void ksz_switch_remove(struct ksz_device *dev) cancel_delayed_work_sync(&dev->mib_read); } - dev->dev_ops->exit(dev); dsa_unregister_switch(dev->ds); - - if (dev->reset_gpio) - gpiod_set_value_cansleep(dev->reset_gpio, 1); - } EXPORT_SYMBOL(ksz_switch_remove); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index f6dad256a550f..1cdb6661729a6 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -421,7 +421,6 @@ struct ksz_dev_ops { 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); int (*pcs_create)(struct ksz_device *dev); }; diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index f84548168b371..778e32f568df4 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -668,11 +668,6 @@ static void lan937x_teardown(struct dsa_switch *ds) } -static void lan937x_switch_exit(struct ksz_device *dev) -{ - lan937x_reset_switch(dev); -} - static enum dsa_tag_protocol lan937x_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) @@ -723,7 +718,6 @@ const struct ksz_dev_ops lan937x_dev_ops = { .enable_stp_addr = ksz9477_enable_stp_addr, .reset = lan937x_reset_switch, .init = lan937x_switch_init, - .exit = lan937x_switch_exit, }; const struct dsa_switch_ops lan937x_switch_ops = { -- 2.53.0 From: Vladimir Oltean The KSZ switch families are sufficiently different that a common ds->ops->setup() - ksz_setup() with micro-managed dev_ops->reset(), dev_ops->pcs_create(), dev_ops->config_cpu_port(), dev_ops->enable_stp_addr(), dev_ops->setup() seems to be too convoluted. I am proposing to make each KSZ switch family part ways for dsa_switch_ops :: setup() and teardown(), to allow them greater flexibility. This here is the implementation for lan937x, which is nothing other than a copy of ksz_setup() with the dev_ops function pointers replaced with direct function calls. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 12 ++-- drivers/net/dsa/microchip/ksz_common.h | 6 ++ drivers/net/dsa/microchip/lan937x_main.c | 116 ++++++++++++++++++++++++++++--- 3 files changed, 116 insertions(+), 18 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 78d77a60a6ce2..c2624b1930f51 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2488,7 +2488,7 @@ static int ksz_parse_dt_phy_config(struct ksz_device *dev, struct mii_bus *bus, * * Return: 0 on success, or a negative error code on failure. */ -static int ksz_mdio_register(struct ksz_device *dev) +int ksz_mdio_register(struct ksz_device *dev) { struct device_node *parent_bus_node; struct mii_bus *parent_bus = NULL; @@ -2644,7 +2644,7 @@ static const struct irq_domain_ops ksz_irq_domain_ops = { .xlate = irq_domain_xlate_twocell, }; -static void ksz_irq_free(struct ksz_irq *kirq) +void ksz_irq_free(struct ksz_irq *kirq) { int irq, virq; @@ -2713,7 +2713,7 @@ static int ksz_irq_common_setup(struct ksz_device *dev, struct ksz_irq *kirq) return ret; } -static int ksz_girq_setup(struct ksz_device *dev) +int ksz_girq_setup(struct ksz_device *dev) { struct ksz_irq *girq = &dev->girq; @@ -2728,7 +2728,7 @@ static int ksz_girq_setup(struct ksz_device *dev) return ksz_irq_common_setup(dev, girq); } -static int ksz_pirq_setup(struct ksz_device *dev, u8 p) +int ksz_pirq_setup(struct ksz_device *dev, u8 p) { struct ksz_irq *pirq = &dev->ports[p].pirq; @@ -2745,8 +2745,6 @@ static int ksz_pirq_setup(struct ksz_device *dev, u8 p) return ksz_irq_common_setup(dev, pirq); } -static int ksz_parse_drive_strength(struct ksz_device *dev); - int ksz_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; @@ -4698,7 +4696,7 @@ static int ksz88x3_drive_strength_write(struct ksz_device *dev, * * Return: 0 on success, error code otherwise */ -static int ksz_parse_drive_strength(struct ksz_device *dev) +int ksz_parse_drive_strength(struct ksz_device *dev) { struct ksz_driver_strength_prop of_props[] = { [KSZ_DRIVER_STRENGTH_HI] = { diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 1cdb6661729a6..5fad56c2d067a 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -518,6 +518,12 @@ int ksz_hsr_leave(struct dsa_switch *ds, int port, int ksz_suspend(struct dsa_switch *ds); int ksz_resume(struct dsa_switch *ds); +int ksz_mdio_register(struct ksz_device *dev); +int ksz_pirq_setup(struct ksz_device *dev, u8 p); +int ksz_girq_setup(struct ksz_device *dev); +void ksz_irq_free(struct ksz_irq *kirq); +int ksz_parse_drive_strength(struct ksz_device *dev); + /* Common register access functions */ static inline struct regmap *ksz_regmap_8(struct ksz_device *dev) { diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index 778e32f568df4..ecb072cd99819 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -626,8 +626,49 @@ static int lan937x_switch_init(struct ksz_device *dev) static int lan937x_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; + u16 storm_mask, storm_rate; + struct dsa_port *dp; + struct ksz_port *p; + const u16 *regs; int ret; + regs = dev->info->regs; + + dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), + dev->info->num_vlans, GFP_KERNEL); + if (!dev->vlan_cache) + return -ENOMEM; + + ret = lan937x_reset_switch(dev); + if (ret) { + dev_err(ds->dev, "failed to reset switch\n"); + return ret; + } + + ret = ksz_parse_drive_strength(dev); + if (ret) + return ret; + + /* set broadcast storm protection 10% rate */ + storm_mask = BROADCAST_STORM_RATE; + storm_rate = (BROADCAST_STORM_VALUE * BROADCAST_STORM_PROT_RATE) / 100; + regmap_update_bits(ksz_regmap_16(dev), regs[S_BROADCAST_CTRL], + storm_mask, storm_rate); + + lan937x_config_cpu_port(ds); + + ksz9477_enable_stp_addr(dev); + + ds->num_tx_queues = dev->info->num_tx_queues; + + regmap_update_bits(ksz_regmap_8(dev), regs[S_MULTICAST_CTRL], + MULTICAST_STORM_DISABLE, MULTICAST_STORM_DISABLE); + + ksz_init_mib_timer(dev); + + ds->configure_vlan_while_not_filtering = false; + ds->dscp_prio_mapping_is_global = true; + /* The VLAN aware is a global setting. Mixed vlan * filterings are not supported. */ @@ -659,13 +700,71 @@ static int lan937x_setup(struct dsa_switch *ds) return ret; /* Disable global VPHY support. Related to CPU interface only? */ - return ksz_rmw32(dev, REG_SW_CFG_STRAP_OVR, SW_VPHY_DISABLE, - SW_VPHY_DISABLE); -} + ret = ksz_rmw32(dev, REG_SW_CFG_STRAP_OVR, SW_VPHY_DISABLE, + SW_VPHY_DISABLE); + if (ret < 0) + return ret; -static void lan937x_teardown(struct dsa_switch *ds) -{ + /* Start with learning disabled on standalone user ports, and enabled + * on the CPU port. In lack of other finer mechanisms, learning on the + * CPU port will avoid flooding bridge local addresses on the network + * in some cases. + */ + p = &dev->ports[dev->cpu_port]; + p->learning = true; + if (dev->irq > 0) { + ret = ksz_girq_setup(dev); + if (ret) + return ret; + + dsa_switch_for_each_user_port(dp, dev->ds) { + ret = ksz_pirq_setup(dev, dp->index); + if (ret) + goto port_release; + + ret = ksz_ptp_irq_setup(ds, dp->index); + if (ret) + goto pirq_release; + } + } + + ret = ksz_ptp_clock_register(ds); + if (ret) { + dev_err(dev->dev, "Failed to register PTP clock: %d\n", + ret); + goto port_release; + } + + ret = ksz_mdio_register(dev); + if (ret < 0) { + dev_err(dev->dev, "failed to register the mdio"); + goto out_ptp_clock_unregister; + } + + ret = ksz_dcb_init(dev); + if (ret) + goto out_ptp_clock_unregister; + + /* start switch */ + regmap_update_bits(ksz_regmap_8(dev), regs[S_START_CTRL], + SW_START, SW_START); + + return 0; + +out_ptp_clock_unregister: + ksz_ptp_clock_unregister(ds); +port_release: + if (dev->irq > 0) { + dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds) { + ksz_ptp_irq_free(ds, dp->index); +pirq_release: + ksz_irq_free(&dev->ports[dp->index].pirq); + } + ksz_irq_free(&dev->girq); + } + + return ret; } static enum dsa_tag_protocol lan937x_get_tag_protocol(struct dsa_switch *ds, @@ -698,8 +797,6 @@ const struct phylink_mac_ops lan937x_phylink_mac_ops = { }; const struct ksz_dev_ops lan937x_dev_ops = { - .setup = lan937x_setup, - .teardown = lan937x_teardown, .get_port_addr = ksz9477_get_port_addr, .cfg_port_member = ksz9477_cfg_port_member, .port_setup = lan937x_port_setup, @@ -713,10 +810,7 @@ const struct ksz_dev_ops lan937x_dev_ops = { .freeze_mib = ksz9477_freeze_mib, .port_init_cnt = ksz9477_port_init_cnt, .setup_rgmii_delay = lan937x_setup_rgmii_delay, - .config_cpu_port = lan937x_config_cpu_port, .tc_cbs_set_cinc = lan937x_tc_cbs_set_cinc, - .enable_stp_addr = ksz9477_enable_stp_addr, - .reset = lan937x_reset_switch, .init = lan937x_switch_init, }; @@ -724,7 +818,7 @@ const struct dsa_switch_ops lan937x_switch_ops = { .get_tag_protocol = lan937x_get_tag_protocol, .connect_tag_protocol = lan937x_connect_tag_protocol, .get_phy_flags = ksz_get_phy_flags, - .setup = ksz_setup, + .setup = lan937x_setup, .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, -- 2.53.0 From: Vladimir Oltean The KSZ switch families are sufficiently different that a common ds->ops->setup() - ksz_setup() with micro-managed dev_ops->reset(), dev_ops->pcs_create(), dev_ops->config_cpu_port(), dev_ops->enable_stp_addr(), dev_ops->setup() seems to be too convoluted. I am proposing to make each KSZ switch family part ways for dsa_switch_ops :: setup() and teardown(), to allow them greater flexibility. This here is the implementation for ksz9477, which is nothing other than a copy of ksz_setup() with the dev_ops function pointers replaced with direct function calls. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz9477.c | 127 +++++++++++++++++++++++++++++++++--- 1 file changed, 118 insertions(+), 9 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 88a5ff62aae89..7385aa4e788a1 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1477,9 +1477,54 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev) static int ksz9477_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; - const u16 *regs = dev->info->regs; - int ret = 0; + u16 storm_mask, storm_rate; + struct dsa_port *dp; + struct ksz_port *p; + const u16 *regs; + int ret; + + regs = dev->info->regs; + + dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), + dev->info->num_vlans, GFP_KERNEL); + if (!dev->vlan_cache) + return -ENOMEM; + + ret = ksz9477_reset_switch(dev); + if (ret) { + dev_err(ds->dev, "failed to reset switch\n"); + return ret; + } + + ret = ksz_parse_drive_strength(dev); + if (ret) + return ret; + if (ksz_has_sgmii_port(dev)) { + ret = ksz9477_pcs_create(dev); + if (ret) + return ret; + } + + /* set broadcast storm protection 10% rate */ + storm_mask = BROADCAST_STORM_RATE; + storm_rate = (BROADCAST_STORM_VALUE * BROADCAST_STORM_PROT_RATE) / 100; + regmap_update_bits(ksz_regmap_16(dev), regs[S_BROADCAST_CTRL], + storm_mask, storm_rate); + + ksz9477_config_cpu_port(ds); + + ksz9477_enable_stp_addr(dev); + + ds->num_tx_queues = dev->info->num_tx_queues; + + regmap_update_bits(ksz_regmap_8(dev), regs[S_MULTICAST_CTRL], + MULTICAST_STORM_DISABLE, MULTICAST_STORM_DISABLE); + + ksz_init_mib_timer(dev); + + ds->configure_vlan_while_not_filtering = false; + ds->dscp_prio_mapping_is_global = true; ds->mtu_enforcement_ingress = true; /* Required for port partitioning. */ @@ -1512,7 +1557,76 @@ static int ksz9477_setup(struct dsa_switch *ds) * be enabled by ksz_wol_pre_shutdown(). Otherwise, some PMICs * do not like PME events changes before shutdown. */ - return ksz_write8(dev, regs[REG_SW_PME_CTRL], 0); + ret = ksz_write8(dev, regs[REG_SW_PME_CTRL], 0); + if (ret < 0) + return ret; + + /* Start with learning disabled on standalone user ports, and enabled + * on the CPU port. In lack of other finer mechanisms, learning on the + * CPU port will avoid flooding bridge local addresses on the network + * in some cases. + */ + p = &dev->ports[dev->cpu_port]; + p->learning = true; + + if (dev->irq > 0) { + ret = ksz_girq_setup(dev); + if (ret) + return ret; + + dsa_switch_for_each_user_port(dp, dev->ds) { + ret = ksz_pirq_setup(dev, dp->index); + if (ret) + goto port_release; + + if (dev->info->ptp_capable) { + ret = ksz_ptp_irq_setup(ds, dp->index); + if (ret) + goto pirq_release; + } + } + } + + if (dev->info->ptp_capable) { + ret = ksz_ptp_clock_register(ds); + if (ret) { + dev_err(dev->dev, "Failed to register PTP clock: %d\n", + ret); + goto port_release; + } + } + + ret = ksz_mdio_register(dev); + if (ret < 0) { + dev_err(dev->dev, "failed to register the mdio"); + goto out_ptp_clock_unregister; + } + + ret = ksz_dcb_init(dev); + if (ret) + goto out_ptp_clock_unregister; + + /* start switch */ + regmap_update_bits(ksz_regmap_8(dev), regs[S_START_CTRL], + SW_START, SW_START); + + return 0; + +out_ptp_clock_unregister: + if (dev->info->ptp_capable) + ksz_ptp_clock_unregister(ds); +port_release: + if (dev->irq > 0) { + dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds) { + if (dev->info->ptp_capable) + ksz_ptp_irq_free(ds, dp->index); +pirq_release: + ksz_irq_free(&dev->ports[dp->index].pirq); + } + ksz_irq_free(&dev->girq); + } + + return ret; } u32 ksz9477_get_port_addr(int port, int offset) @@ -1779,7 +1893,6 @@ const struct phylink_mac_ops ksz9477_phylink_mac_ops = { }; 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, .port_setup = ksz9477_port_setup, @@ -1793,19 +1906,15 @@ const struct ksz_dev_ops ksz9477_dev_ops = { .pme_write8 = ksz_write8, .pme_pread8 = ksz_pread8, .pme_pwrite8 = ksz_pwrite8, - .config_cpu_port = ksz9477_config_cpu_port, .tc_cbs_set_cinc = ksz9477_tc_cbs_set_cinc, - .enable_stp_addr = ksz9477_enable_stp_addr, - .reset = ksz9477_reset_switch, .init = ksz9477_switch_init, - .pcs_create = ksz9477_pcs_create, }; const struct dsa_switch_ops ksz9477_switch_ops = { .get_tag_protocol = ksz9477_get_tag_protocol, .connect_tag_protocol = ksz9477_connect_tag_protocol, .get_phy_flags = ksz_get_phy_flags, - .setup = ksz_setup, + .setup = ksz9477_setup, .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, -- 2.53.0 From: Vladimir Oltean The KSZ switch families are sufficiently different that a common ds->ops->setup() - ksz_setup() with micro-managed dev_ops->reset(), dev_ops->pcs_create(), dev_ops->config_cpu_port(), dev_ops->enable_stp_addr(), dev_ops->setup() seems to be too convoluted. I am proposing to make each KSZ switch family part ways for dsa_switch_ops :: setup() and teardown(), to allow them greater flexibility. This here is the implementation for ksz8, which is nothing other than a copy of ksz_setup() with the dev_ops function pointers replaced with direct function calls. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 139 +++++++++++++++++++++++++++++++++------ 1 file changed, 119 insertions(+), 20 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index ccbc3480717f0..acc898c68f985 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -1935,9 +1935,52 @@ static int ksz8_enable_stp_addr(struct ksz_device *dev) static int ksz8_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; - const u16 *regs = dev->info->regs; - int i, ret = 0; + u16 storm_mask, storm_rate; + struct dsa_port *dp; + struct ksz_port *p; + const u16 *regs; + int i, ret; + + regs = dev->info->regs; + + dev->vlan_cache = devm_kcalloc(dev->dev, sizeof(struct vlan_table), + dev->info->num_vlans, GFP_KERNEL); + if (!dev->vlan_cache) + return -ENOMEM; + + ret = ksz8_reset_switch(dev); + if (ret) { + dev_err(ds->dev, "failed to reset switch\n"); + return ret; + } + + ret = ksz_parse_drive_strength(dev); + if (ret) + return ret; + + /* set broadcast storm protection 10% rate */ + storm_mask = BROADCAST_STORM_RATE; + storm_rate = (BROADCAST_STORM_VALUE * BROADCAST_STORM_PROT_RATE) / 100; + if (ksz_is_ksz8463(dev)) { + storm_mask = swab16(storm_mask); + storm_rate = swab16(storm_rate); + } + regmap_update_bits(ksz_regmap_16(dev), regs[S_BROADCAST_CTRL], + storm_mask, storm_rate); + + ksz8_config_cpu_port(ds); + + ksz8_enable_stp_addr(dev); + + ds->num_tx_queues = dev->info->num_tx_queues; + + regmap_update_bits(ksz_regmap_8(dev), regs[S_MULTICAST_CTRL], + MULTICAST_STORM_DISABLE, MULTICAST_STORM_DISABLE); + + ksz_init_mib_timer(dev); + ds->configure_vlan_while_not_filtering = false; + ds->dscp_prio_mapping_is_global = true; ds->mtu_enforcement_ingress = true; /* We rely on software untagging on the CPU port, so that we @@ -1987,12 +2030,80 @@ static int ksz8_setup(struct dsa_switch *ds) ret = ksz8_pme_write8(dev, regs[REG_SW_PME_CTRL], 0); if (!ret) ret = ksz_rmw8(dev, REG_INT_ENABLE, INT_PME, 0); + if (ret) + return ret; } - if (!ret) - return ksz8_handle_global_errata(ds); - else + ret = ksz8_handle_global_errata(ds); + if (ret) return ret; + + /* Start with learning disabled on standalone user ports, and enabled + * on the CPU port. In lack of other finer mechanisms, learning on the + * CPU port will avoid flooding bridge local addresses on the network + * in some cases. + */ + p = &dev->ports[dev->cpu_port]; + p->learning = true; + + if (dev->irq > 0) { + ret = ksz_girq_setup(dev); + if (ret) + return ret; + + dsa_switch_for_each_user_port(dp, dev->ds) { + ret = ksz_pirq_setup(dev, dp->index); + if (ret) + goto port_release; + + if (dev->info->ptp_capable) { + ret = ksz_ptp_irq_setup(ds, dp->index); + if (ret) + goto pirq_release; + } + } + } + + if (dev->info->ptp_capable) { + ret = ksz_ptp_clock_register(ds); + if (ret) { + dev_err(dev->dev, "Failed to register PTP clock: %d\n", + ret); + goto port_release; + } + } + + ret = ksz_mdio_register(dev); + if (ret < 0) { + dev_err(dev->dev, "failed to register the mdio"); + goto out_ptp_clock_unregister; + } + + ret = ksz_dcb_init(dev); + if (ret) + goto out_ptp_clock_unregister; + + /* start switch */ + regmap_update_bits(ksz_regmap_8(dev), regs[S_START_CTRL], + SW_START, SW_START); + + return 0; + +out_ptp_clock_unregister: + if (dev->info->ptp_capable) + ksz_ptp_clock_unregister(ds); +port_release: + if (dev->irq > 0) { + dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds) { + if (dev->info->ptp_capable) + ksz_ptp_irq_free(ds, dp->index); +pirq_release: + ksz_irq_free(&dev->ports[dp->index].pirq); + } + ksz_irq_free(&dev->girq); + } + + return ret; } static void ksz8_phylink_get_caps(struct dsa_switch *ds, int port, @@ -2206,7 +2317,6 @@ const struct phylink_mac_ops ksz8_phylink_mac_ops = { }; const struct ksz_dev_ops ksz8463_dev_ops = { - .setup = ksz8_setup, .get_port_addr = ksz8463_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, .port_setup = ksz8_port_setup, @@ -2217,14 +2327,10 @@ const struct ksz_dev_ops ksz8463_dev_ops = { .r_mib_stat64 = ksz88xx_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .config_cpu_port = ksz8_config_cpu_port, - .enable_stp_addr = ksz8_enable_stp_addr, - .reset = ksz8_reset_switch, .init = ksz8_switch_init, }; const struct ksz_dev_ops ksz87xx_dev_ops = { - .setup = ksz8_setup, .get_port_addr = ksz8_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, .port_setup = ksz8_port_setup, @@ -2235,9 +2341,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { .r_mib_stat64 = ksz_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .config_cpu_port = ksz8_config_cpu_port, - .enable_stp_addr = ksz8_enable_stp_addr, - .reset = ksz8_reset_switch, .init = ksz8_switch_init, .pme_write8 = ksz8_pme_write8, .pme_pread8 = ksz8_pme_pread8, @@ -2245,7 +2348,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { }; const struct ksz_dev_ops ksz88xx_dev_ops = { - .setup = ksz8_setup, .get_port_addr = ksz8_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, .port_setup = ksz8_port_setup, @@ -2256,9 +2358,6 @@ const struct ksz_dev_ops ksz88xx_dev_ops = { .r_mib_stat64 = ksz88xx_r_mib_stats64, .freeze_mib = ksz8_freeze_mib, .port_init_cnt = ksz8_port_init_cnt, - .config_cpu_port = ksz8_config_cpu_port, - .enable_stp_addr = ksz8_enable_stp_addr, - .reset = ksz8_reset_switch, .init = ksz8_switch_init, .pme_write8 = ksz8_pme_write8, .pme_pread8 = ksz8_pme_pread8, @@ -2269,7 +2368,7 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .get_tag_protocol = ksz8463_get_tag_protocol, .connect_tag_protocol = ksz8463_connect_tag_protocol, .get_phy_flags = ksz_get_phy_flags, - .setup = ksz_setup, + .setup = ksz8_setup, .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, @@ -2329,7 +2428,7 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .get_tag_protocol = ksz87xx_get_tag_protocol, .connect_tag_protocol = ksz87xx_connect_tag_protocol, .get_phy_flags = ksz_get_phy_flags, - .setup = ksz_setup, + .setup = ksz8_setup, .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, @@ -2389,7 +2488,7 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .get_tag_protocol = ksz88xx_get_tag_protocol, .connect_tag_protocol = ksz88xx_connect_tag_protocol, .get_phy_flags = ksz_get_phy_flags, - .setup = ksz_setup, + .setup = ksz8_setup, .teardown = ksz_teardown, .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, -- 2.53.0 From: Vladimir Oltean All switch families have been converted to have their own ds->ops->setup() methods and to call the common ksz_teardown(). Remove the no longer used ksz_setup() function and the associated ksz_dev_ops callbacks. Signed-off-by: Vladimir Oltean Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 133 --------------------------------- drivers/net/dsa/microchip/ksz_common.h | 8 -- 2 files changed, 141 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index c2624b1930f51..60edb02846481 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2745,136 +2745,6 @@ int ksz_pirq_setup(struct ksz_device *dev, u8 p) return ksz_irq_common_setup(dev, pirq); } -int ksz_setup(struct dsa_switch *ds) -{ - struct ksz_device *dev = ds->priv; - u16 storm_mask, storm_rate; - struct dsa_port *dp; - struct ksz_port *p; - const u16 *regs; - int ret; - - regs = dev->info->regs; - - 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; - } - - ret = ksz_parse_drive_strength(dev); - if (ret) - return ret; - - if (ksz_has_sgmii_port(dev) && dev->dev_ops->pcs_create) { - ret = dev->dev_ops->pcs_create(dev); - if (ret) - return ret; - } - - /* set broadcast storm protection 10% rate */ - storm_mask = BROADCAST_STORM_RATE; - storm_rate = (BROADCAST_STORM_VALUE * BROADCAST_STORM_PROT_RATE) / 100; - if (ksz_is_ksz8463(dev)) { - storm_mask = swab16(storm_mask); - storm_rate = swab16(storm_rate); - } - regmap_update_bits(ksz_regmap_16(dev), regs[S_BROADCAST_CTRL], - storm_mask, storm_rate); - - dev->dev_ops->config_cpu_port(ds); - - dev->dev_ops->enable_stp_addr(dev); - - ds->num_tx_queues = dev->info->num_tx_queues; - - regmap_update_bits(ksz_regmap_8(dev), regs[S_MULTICAST_CTRL], - MULTICAST_STORM_DISABLE, MULTICAST_STORM_DISABLE); - - ksz_init_mib_timer(dev); - - ds->configure_vlan_while_not_filtering = false; - ds->dscp_prio_mapping_is_global = true; - - if (dev->dev_ops->setup) { - ret = dev->dev_ops->setup(ds); - if (ret) - return ret; - } - - /* Start with learning disabled on standalone user ports, and enabled - * on the CPU port. In lack of other finer mechanisms, learning on the - * CPU port will avoid flooding bridge local addresses on the network - * in some cases. - */ - p = &dev->ports[dev->cpu_port]; - p->learning = true; - - if (dev->irq > 0) { - ret = ksz_girq_setup(dev); - if (ret) - return ret; - - dsa_switch_for_each_user_port(dp, dev->ds) { - ret = ksz_pirq_setup(dev, dp->index); - if (ret) - goto port_release; - - if (dev->info->ptp_capable) { - ret = ksz_ptp_irq_setup(ds, dp->index); - if (ret) - goto pirq_release; - } - } - } - - if (dev->info->ptp_capable) { - ret = ksz_ptp_clock_register(ds); - if (ret) { - dev_err(dev->dev, "Failed to register PTP clock: %d\n", - ret); - goto port_release; - } - } - - ret = ksz_mdio_register(dev); - if (ret < 0) { - dev_err(dev->dev, "failed to register the mdio"); - goto out_ptp_clock_unregister; - } - - ret = ksz_dcb_init(dev); - if (ret) - goto out_ptp_clock_unregister; - - /* start switch */ - regmap_update_bits(ksz_regmap_8(dev), regs[S_START_CTRL], - SW_START, SW_START); - - return 0; - -out_ptp_clock_unregister: - if (dev->info->ptp_capable) - ksz_ptp_clock_unregister(ds); -port_release: - if (dev->irq > 0) { - dsa_switch_for_each_user_port_continue_reverse(dp, dev->ds) { - if (dev->info->ptp_capable) - ksz_ptp_irq_free(ds, dp->index); -pirq_release: - ksz_irq_free(&dev->ports[dp->index].pirq); - } - ksz_irq_free(&dev->girq); - } - - return ret; -} - void ksz_teardown(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; @@ -2893,9 +2763,6 @@ void ksz_teardown(struct dsa_switch *ds) ksz_irq_free(&dev->girq); } - - if (dev->dev_ops->teardown) - dev->dev_ops->teardown(ds); } static void port_r_cnt(struct ksz_device *dev, int port) diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 5fad56c2d067a..f80034488cd1b 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -359,8 +359,6 @@ struct alu_struct { }; struct ksz_dev_ops { - int (*setup)(struct dsa_switch *ds); - void (*teardown)(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 (*port_setup)(struct ksz_device *dev, int port, bool cpu_port); @@ -417,12 +415,7 @@ struct ksz_dev_ops { void (*port_init_cnt)(struct ksz_device *dev, int port); void (*setup_rgmii_delay)(struct ksz_device *dev, int port); int (*tc_cbs_set_cinc)(struct ksz_device *dev, int port, u32 val); - 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); - - int (*pcs_create)(struct ksz_device *dev); }; struct ksz_device *ksz_switch_alloc(struct device *base, @@ -433,7 +426,6 @@ void ksz_switch_remove(struct ksz_device *dev); int ksz_switch_suspend(struct device *dev); int ksz_switch_resume(struct device *dev); -int ksz_setup(struct dsa_switch *ds); void ksz_teardown(struct dsa_switch *ds); int ksz_port_setup(struct dsa_switch *ds, int port); void ksz_port_teardown(struct dsa_switch *ds, int port); -- 2.53.0 port_setup() is handled through a common function that redirects the treatment to ksz_dev_ops callbacks. This layer of indirection isn't needed since we now have a dsa_switch_ops for each switch family Remove one indirection layer for KSZ switches, by connecting the ksz_dev_ops :: port_setup() operations directly to dsa_switch_ops. Make ksz9477_set_default_prio_queue_mapping() non-static since it's used by ksz_common for tc operations and by ksz9477.c for this port_setup(). Remove the now unused port_setup() callback from ksz_dev_ops. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 20 ++++++++++++++------ drivers/net/dsa/microchip/ksz9477.c | 20 ++++++++++++++++++-- drivers/net/dsa/microchip/ksz9477.h | 1 + drivers/net/dsa/microchip/ksz_common.c | 27 +-------------------------- drivers/net/dsa/microchip/ksz_common.h | 3 +-- drivers/net/dsa/microchip/lan937x_main.c | 3 +-- 6 files changed, 36 insertions(+), 38 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index acc898c68f985..09968aec65063 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -1692,6 +1692,17 @@ static void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) ksz8_pme_pwrite8(dev, port, regs[REG_PORT_PME_CTRL], 0); } +static int ksz8_dsa_port_setup(struct dsa_switch *ds, int port) +{ + struct ksz_device *dev = ds->priv; + + if (!dsa_is_user_port(ds, port)) + return 0; + + ksz8_port_setup(dev, port, false); + return ksz_dcb_init_port(dev, port); +} + static void ksz88x3_config_rmii_clk(struct ksz_device *dev) { struct dsa_port *cpu_dp = dsa_to_port(dev->ds, dev->cpu_port); @@ -2319,7 +2330,6 @@ const struct phylink_mac_ops ksz8_phylink_mac_ops = { const struct ksz_dev_ops ksz8463_dev_ops = { .get_port_addr = ksz8463_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, - .port_setup = ksz8_port_setup, .r_phy = ksz8463_r_phy, .w_phy = ksz8463_w_phy, .r_mib_cnt = ksz8_r_mib_cnt, @@ -2333,7 +2343,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { const struct ksz_dev_ops ksz87xx_dev_ops = { .get_port_addr = ksz8_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, - .port_setup = ksz8_port_setup, .r_phy = ksz8_r_phy, .w_phy = ksz8_w_phy, .r_mib_cnt = ksz8_r_mib_cnt, @@ -2350,7 +2359,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { const struct ksz_dev_ops ksz88xx_dev_ops = { .get_port_addr = ksz8_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, - .port_setup = ksz8_port_setup, .r_phy = ksz8_r_phy, .w_phy = ksz8_w_phy, .r_mib_cnt = ksz8_r_mib_cnt, @@ -2373,7 +2381,7 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_get_caps = ksz8_phylink_get_caps, - .port_setup = ksz_port_setup, + .port_setup = ksz8_dsa_port_setup, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, .get_sset_count = ksz_sset_count, @@ -2433,7 +2441,7 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_get_caps = ksz8_phylink_get_caps, - .port_setup = ksz_port_setup, + .port_setup = ksz8_dsa_port_setup, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, .get_sset_count = ksz_sset_count, @@ -2493,7 +2501,7 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_get_caps = ksz8_phylink_get_caps, - .port_setup = ksz_port_setup, + .port_setup = ksz8_dsa_port_setup, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, .get_sset_count = ksz_sset_count, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 7385aa4e788a1..2f63a3a7d6ceb 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1309,6 +1309,23 @@ static void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port) ksz_pwrite8(dev, port, regs[REG_PORT_PME_CTRL], 0); } +int ksz9477_dsa_port_setup(struct dsa_switch *ds, int port) +{ + struct ksz_device *dev = ds->priv; + int ret; + + if (!dsa_is_user_port(ds, port)) + return 0; + + ksz9477_port_setup(dev, port, false); + + ret = ksz9477_set_default_prio_queue_mapping(dev, port); + if (ret) + return ret; + + return ksz_dcb_init_port(dev, port); +}; + static void ksz9477_config_cpu_port(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; @@ -1895,7 +1912,6 @@ const struct phylink_mac_ops ksz9477_phylink_mac_ops = { const struct ksz_dev_ops ksz9477_dev_ops = { .get_port_addr = ksz9477_get_port_addr, .cfg_port_member = ksz9477_cfg_port_member, - .port_setup = ksz9477_port_setup, .r_phy = ksz9477_r_phy, .w_phy = ksz9477_w_phy, .r_mib_cnt = ksz9477_r_mib_cnt, @@ -1919,7 +1935,7 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_get_caps = ksz9477_phylink_get_caps, - .port_setup = ksz_port_setup, + .port_setup = ksz9477_dsa_port_setup, .set_ageing_time = ksz9477_set_ageing_time, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h index 599db0a6ba2e3..6f59bba3c0860 100644 --- a/drivers/net/dsa/microchip/ksz9477.h +++ b/drivers/net/dsa/microchip/ksz9477.h @@ -18,6 +18,7 @@ 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); +int ksz9477_dsa_port_setup(struct dsa_switch *ds, int port); void ksz9477_port_init_cnt(struct ksz_device *dev, int port); int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port, bool flag, struct netlink_ext_ack *extack); diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 60edb02846481..f44974cf4e595 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2947,8 +2947,7 @@ void ksz_port_bridge_leave(struct dsa_switch *ds, int port, */ } -static int ksz9477_set_default_prio_queue_mapping(struct ksz_device *dev, - int port) +int ksz9477_set_default_prio_queue_mapping(struct ksz_device *dev, int port) { u32 queue_map = 0; int ipm; @@ -2970,30 +2969,6 @@ static int ksz9477_set_default_prio_queue_mapping(struct ksz_device *dev, return ksz_pwrite32(dev, port, KSZ9477_PORT_MRI_TC_MAP__4, queue_map); } -int ksz_port_setup(struct dsa_switch *ds, int port) -{ - struct ksz_device *dev = ds->priv; - int ret; - - if (!dsa_is_user_port(ds, port)) - return 0; - - /* setup user port */ - dev->dev_ops->port_setup(dev, port, false); - - if (!is_ksz8(dev)) { - ret = ksz9477_set_default_prio_queue_mapping(dev, port); - if (ret) - return ret; - } - - /* port_stp_state_set() will be called after to enable the port so - * there is no need to do anything. - */ - - return ksz_dcb_init_port(dev, port); -} - void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state) { struct ksz_device *dev = ds->priv; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index f80034488cd1b..c66d75347c6cb 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -361,7 +361,6 @@ struct alu_struct { struct ksz_dev_ops { u32 (*get_port_addr)(int port, int offset); void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member); - void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port); /** * @mdio_bus_preinit: Function pointer to pre-initialize the MDIO bus @@ -427,7 +426,6 @@ int ksz_switch_suspend(struct device *dev); int ksz_switch_resume(struct device *dev); void ksz_teardown(struct dsa_switch *ds); -int ksz_port_setup(struct dsa_switch *ds, int port); void ksz_port_teardown(struct dsa_switch *ds, int port); void ksz_init_mib_timer(struct ksz_device *dev); @@ -515,6 +513,7 @@ int ksz_pirq_setup(struct ksz_device *dev, u8 p); int ksz_girq_setup(struct ksz_device *dev); void ksz_irq_free(struct ksz_irq *kirq); int ksz_parse_drive_strength(struct ksz_device *dev); +int ksz9477_set_default_prio_queue_mapping(struct ksz_device *dev, int port); /* Common register access functions */ static inline struct regmap *ksz_regmap_8(struct ksz_device *dev) diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index ecb072cd99819..aff0c2735c307 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -799,7 +799,6 @@ const struct phylink_mac_ops lan937x_phylink_mac_ops = { const struct ksz_dev_ops lan937x_dev_ops = { .get_port_addr = ksz9477_get_port_addr, .cfg_port_member = ksz9477_cfg_port_member, - .port_setup = lan937x_port_setup, .mdio_bus_preinit = lan937x_mdio_bus_preinit, .create_phy_addr_map = lan937x_create_phy_addr_map, .r_phy = lan937x_r_phy, @@ -823,7 +822,7 @@ const struct dsa_switch_ops lan937x_switch_ops = { .phy_read = ksz_phy_read16, .phy_write = ksz_phy_write16, .phylink_get_caps = lan937x_phylink_get_caps, - .port_setup = ksz_port_setup, + .port_setup = ksz9477_dsa_port_setup, .set_ageing_time = lan937x_set_ageing_time, .get_strings = ksz_get_strings, .get_ethtool_stats = ksz_get_ethtool_stats, -- 2.53.0 ksz_sw_mdio_read() and ksz_sw_mdio_write() respectively call ksz_dev_ops::phy_r() and ksz_dev_ops::phy_w() just like dsa_switch_ops::phy_read() and dsa_switch_ops::phy_write() do. Call dsa_switch_ops::phy_read() from ksz_sw_mdio_read() and dsa_switch_ops::phy_write() from ksz_sw_mdio_write() so we'll be able to get rid of the useless indirections provided by ksz_dev_ops in upcoming patch. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz_common.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index f44974cf4e595..0d66592dff703 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2260,22 +2260,18 @@ static void ksz_update_port_member(struct ksz_device *dev, int port) static int ksz_sw_mdio_read(struct mii_bus *bus, int addr, int regnum) { struct ksz_device *dev = bus->priv; - u16 val; - int ret; - - ret = dev->dev_ops->r_phy(dev, addr, regnum, &val); - if (ret < 0) - return ret; + struct dsa_switch *ds = dev->ds; - return val; + return ds->ops->phy_read(ds, addr, regnum); } static int ksz_sw_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val) { struct ksz_device *dev = bus->priv; + struct dsa_switch *ds = dev->ds; - return dev->dev_ops->w_phy(dev, addr, regnum, val); + return ds->ops->phy_write(ds, addr, regnum, val); } /** -- 2.53.0 phy_read() and phy_write() are handled through common functions that redirect the treatment to ksz_dev_ops callbacks. This layer of indirection isn't needed since we now have a dsa_switch_ops for each kind of switch Remove one indirection layer for KSZ switches, by connecting the ksz_dev_ops::phy_r() and ksz_dev_ops::phy_w() operations directly to dsa_switch_ops. Remove the now unused phy_r()/phy_w() callbacks from ksz_dev_ops. Signed-off-by: Bastien Curutchet (Schneider Electric) --- drivers/net/dsa/microchip/ksz8.c | 68 ++++++++++++++++++++++++++------ drivers/net/dsa/microchip/ksz9477.c | 31 +++++++++++++-- drivers/net/dsa/microchip/ksz_common.c | 25 ------------ drivers/net/dsa/microchip/ksz_common.h | 4 -- drivers/net/dsa/microchip/lan937x_main.c | 29 ++++++++++---- 5 files changed, 104 insertions(+), 53 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c index 09968aec65063..0f84b2e7d25d8 100644 --- a/drivers/net/dsa/microchip/ksz8.c +++ b/drivers/net/dsa/microchip/ksz8.c @@ -1057,6 +1057,19 @@ static int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) return 0; } +static int ksz8_phy_read16(struct dsa_switch *ds, int addr, int reg) +{ + struct ksz_device *dev = ds->priv; + u16 val = 0xffff; + int ret; + + ret = ksz8_r_phy(dev, addr, reg, &val); + if (ret) + return ret; + + return val; +} + /** * ksz8_w_phy_ctrl - Translates and writes to the SMI interface from a MIIM PHY * Control register (Reg. 31). @@ -1266,6 +1279,18 @@ static int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) return 0; } +static int ksz8_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) +{ + struct ksz_device *dev = ds->priv; + int ret; + + ret = ksz8_w_phy(dev, addr, reg, val); + if (ret) + return ret; + + return 0; +} + static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member) { int offset = P_MIRROR_CTRL; @@ -2194,6 +2219,19 @@ static int ksz8463_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val) return 0; } +static int ksz8463_phy_read16(struct dsa_switch *ds, int addr, int reg) +{ + struct ksz_device *dev = ds->priv; + u16 val = 0xffff; + int ret; + + ret = ksz8463_r_phy(dev, addr, reg, &val); + if (ret) + return ret; + + return val; +} + static int ksz8463_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) { u16 sw_reg = 0; @@ -2222,6 +2260,18 @@ static int ksz8463_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) return 0; } +static int ksz8463_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) +{ + struct ksz_device *dev = ds->priv; + int ret; + + ret = ksz8463_w_phy(dev, addr, reg, val); + if (ret) + return ret; + + return 0; +} + static int ksz8_switch_init(struct ksz_device *dev) { dev->cpu_port = fls(dev->info->cpu_ports) - 1; @@ -2330,8 +2380,6 @@ const struct phylink_mac_ops ksz8_phylink_mac_ops = { const struct ksz_dev_ops ksz8463_dev_ops = { .get_port_addr = ksz8463_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, - .r_phy = ksz8463_r_phy, - .w_phy = ksz8463_w_phy, .r_mib_cnt = ksz8_r_mib_cnt, .r_mib_pkt = ksz8_r_mib_pkt, .r_mib_stat64 = ksz88xx_r_mib_stats64, @@ -2343,8 +2391,6 @@ const struct ksz_dev_ops ksz8463_dev_ops = { const struct ksz_dev_ops ksz87xx_dev_ops = { .get_port_addr = ksz8_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, - .r_phy = ksz8_r_phy, - .w_phy = ksz8_w_phy, .r_mib_cnt = ksz8_r_mib_cnt, .r_mib_pkt = ksz8_r_mib_pkt, .r_mib_stat64 = ksz_r_mib_stats64, @@ -2359,8 +2405,6 @@ const struct ksz_dev_ops ksz87xx_dev_ops = { const struct ksz_dev_ops ksz88xx_dev_ops = { .get_port_addr = ksz8_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, - .r_phy = ksz8_r_phy, - .w_phy = ksz8_w_phy, .r_mib_cnt = ksz8_r_mib_cnt, .r_mib_pkt = ksz8_r_mib_pkt, .r_mib_stat64 = ksz88xx_r_mib_stats64, @@ -2378,8 +2422,8 @@ const struct dsa_switch_ops ksz8463_switch_ops = { .get_phy_flags = ksz_get_phy_flags, .setup = ksz8_setup, .teardown = ksz_teardown, - .phy_read = ksz_phy_read16, - .phy_write = ksz_phy_write16, + .phy_read = ksz8463_phy_read16, + .phy_write = ksz8463_phy_write16, .phylink_get_caps = ksz8_phylink_get_caps, .port_setup = ksz8_dsa_port_setup, .get_strings = ksz_get_strings, @@ -2438,8 +2482,8 @@ const struct dsa_switch_ops ksz87xx_switch_ops = { .get_phy_flags = ksz_get_phy_flags, .setup = ksz8_setup, .teardown = ksz_teardown, - .phy_read = ksz_phy_read16, - .phy_write = ksz_phy_write16, + .phy_read = ksz8_phy_read16, + .phy_write = ksz8_phy_write16, .phylink_get_caps = ksz8_phylink_get_caps, .port_setup = ksz8_dsa_port_setup, .get_strings = ksz_get_strings, @@ -2498,8 +2542,8 @@ const struct dsa_switch_ops ksz88xx_switch_ops = { .get_phy_flags = ksz_get_phy_flags, .setup = ksz8_setup, .teardown = ksz_teardown, - .phy_read = ksz_phy_read16, - .phy_write = ksz_phy_write16, + .phy_read = ksz8_phy_read16, + .phy_write = ksz8_phy_write16, .phylink_get_caps = ksz8_phylink_get_caps, .port_setup = ksz8_dsa_port_setup, .get_strings = ksz_get_strings, diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 2f63a3a7d6ceb..00c2e23bc5669 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -575,6 +575,19 @@ static int ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data) return 0; } +static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg) +{ + struct ksz_device *dev = ds->priv; + u16 val = 0xffff; + int ret; + + ret = ksz9477_r_phy(dev, addr, reg, &val); + if (ret) + return ret; + + return val; +} + static int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) { u32 mask, val32; @@ -600,6 +613,18 @@ static int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) return ksz_prmw32(dev, addr, 0x100 + (reg << 1), mask, val32); } +static int ksz9477_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) +{ + struct ksz_device *dev = ds->priv; + int ret; + + ret = ksz9477_w_phy(dev, addr, reg, val); + if (ret) + return ret; + + return 0; +} + void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member) { ksz_pwrite32(dev, port, REG_PORT_VLAN_MEMBERSHIP__4, member); @@ -1912,8 +1937,6 @@ const struct phylink_mac_ops ksz9477_phylink_mac_ops = { const struct ksz_dev_ops ksz9477_dev_ops = { .get_port_addr = ksz9477_get_port_addr, .cfg_port_member = ksz9477_cfg_port_member, - .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, @@ -1932,8 +1955,8 @@ const struct dsa_switch_ops ksz9477_switch_ops = { .get_phy_flags = ksz_get_phy_flags, .setup = ksz9477_setup, .teardown = ksz_teardown, - .phy_read = ksz_phy_read16, - .phy_write = ksz_phy_write16, + .phy_read = ksz9477_phy_read16, + .phy_write = ksz9477_phy_write16, .phylink_get_caps = ksz9477_phylink_get_caps, .port_setup = ksz9477_dsa_port_setup, .set_ageing_time = ksz9477_set_ageing_time, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 0d66592dff703..95aa3ab5b5719 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2838,31 +2838,6 @@ void ksz_init_mib_timer(struct ksz_device *dev) } } -int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg) -{ - struct ksz_device *dev = ds->priv; - u16 val = 0xffff; - int ret; - - ret = dev->dev_ops->r_phy(dev, addr, reg, &val); - if (ret) - return ret; - - return val; -} - -int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) -{ - struct ksz_device *dev = ds->priv; - int ret; - - ret = dev->dev_ops->w_phy(dev, addr, reg, val); - if (ret) - return ret; - - return 0; -} - u32 ksz_get_phy_flags(struct dsa_switch *ds, int port) { struct ksz_device *dev = ds->priv; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index c66d75347c6cb..b67038cf1bd09 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -398,8 +398,6 @@ struct ksz_dev_ops { * - Negative error code on failure (e.g., invalid configuration). */ int (*create_phy_addr_map)(struct ksz_device *dev, bool side_mdio); - int (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val); - int (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val); void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr, u64 *cnt); void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr, @@ -442,8 +440,6 @@ void ksz_switch_macaddr_put(struct dsa_switch *ds); void ksz_switch_shutdown(struct ksz_device *dev); int ksz_handle_wake_reason(struct ksz_device *dev, int port); -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); int ksz_sset_count(struct dsa_switch *ds, int port, int sset); diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index aff0c2735c307..5b0e8d2002c7d 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -334,14 +334,29 @@ static int lan937x_internal_phy_read(struct ksz_device *dev, int addr, int reg, return ksz_read16(dev, REG_VPHY_IND_DATA__2, val); } -static int lan937x_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data) +static int lan937x_phy_read16(struct dsa_switch *ds, int addr, int reg) { - return lan937x_internal_phy_read(dev, addr, reg, data); + struct ksz_device *dev = ds->priv; + u16 val = 0xffff; + int ret; + + ret = lan937x_internal_phy_read(dev, addr, reg, &val); + if (ret) + return ret; + + return val; } -static int lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val) +static int lan937x_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val) { - return lan937x_internal_phy_write(dev, addr, reg, val); + struct ksz_device *dev = ds->priv; + int ret; + + ret = lan937x_internal_phy_write(dev, addr, reg, val); + if (ret) + return ret; + + return 0; } static int lan937x_reset_switch(struct ksz_device *dev) @@ -801,8 +816,6 @@ const struct ksz_dev_ops lan937x_dev_ops = { .cfg_port_member = ksz9477_cfg_port_member, .mdio_bus_preinit = lan937x_mdio_bus_preinit, .create_phy_addr_map = lan937x_create_phy_addr_map, - .r_phy = lan937x_r_phy, - .w_phy = lan937x_w_phy, .r_mib_cnt = ksz9477_r_mib_cnt, .r_mib_pkt = ksz9477_r_mib_pkt, .r_mib_stat64 = ksz_r_mib_stats64, @@ -819,8 +832,8 @@ const struct dsa_switch_ops lan937x_switch_ops = { .get_phy_flags = ksz_get_phy_flags, .setup = lan937x_setup, .teardown = ksz_teardown, - .phy_read = ksz_phy_read16, - .phy_write = ksz_phy_write16, + .phy_read = lan937x_phy_read16, + .phy_write = lan937x_phy_write16, .phylink_get_caps = lan937x_phylink_get_caps, .port_setup = ksz9477_dsa_port_setup, .set_ageing_time = lan937x_set_ageing_time, -- 2.53.0