net: dsa: b53: mmap: add dsa switch ops
cover net: dsa: b53: mmap: add dsa switch ops
B53 MMAP switches have a MDIO Mux bus controller which should be used instead of the default phy_read/phy_write ops used in the rest of the B53 controllers. Therefore, in order to use the proper MDIO Mux bus controller we need to replicate the default B53 DSA switch ops removing the phy_read/phy_write entries.
Without this, when external switches are configured together with B53 MMAP internal switches the device will hang on phy_read/phy_write ops.
This is an alternative to:
- https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
- https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
- https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
- https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
As discussed, it was an ABI break and not the correct way of fixing the issue.
And also to:
- https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Álvaro Fernández Rojas (1):
net: dsa: b53: mmap: add dsa switch ops
drivers/net/dsa/b53/b53_common.c | 22 +++++++++--------- drivers/net/dsa/b53/b53_mmap.c | 40 ++++++++++++++++++++++++++++++++ drivers/net/dsa/b53/b53_priv.h | 11 +++++++++ 3 files changed, 62 insertions(+), 11 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/1 net: dsa: b53: mmap: add dsa switch ops
B53 MMAP switches have a MDIO Mux bus controller which should be used instead of the default phy_read/phy_write ops used in the rest of the B53 controllers. Therefore, in order to use the proper MDIO Mux bus controller we need to replicate the default B53 DSA switch ops removing the phy_read/phy_write entries.
--- drivers/net/dsa/b53/b53_common.c | 22 +++++++++--------- drivers/net/dsa/b53/b53_mmap.c | 40 ++++++++++++++++++++++++++++++++ drivers/net/dsa/b53/b53_priv.h | 11 +++++++++ 3 files changed, 62 insertions(+), 11 deletions(-)
drivers/net/dsa/b53/b53_common.c +11 -11
@@ -1096,7 +1096,7 @@ int b53_setup_devlink_resources(struct dsa_switch *ds) }EXPORT_SYMBOL (b53_setup_devlink_resources); -static int b53_setup (struct dsa_switch *ds) +int b53_setup (struct dsa_switch *ds) {struct b53_device *dev = ds->priv;unsigned int port;
@@ -1134,7 +1134,7 @@ static int b53_setup(struct dsa_switch *ds)return b53_setup_devlink_resources (ds); } -static void b53_teardown (struct dsa_switch *ds) +void b53_teardown (struct dsa_switch *ds) {dsa_devlink_resources_unregister (ds); }
@@ -1253,8 +1253,8 @@ static void b53_adjust_63xx_rgmii(struct dsa_switch *ds, int port, phy_modes(interface)); } -static void b53_adjust_link (struct dsa_switch *ds,int port, -struct phy_device *phydev) +void b53_adjust_link (struct dsa_switch *ds,int port, +struct phy_device *phydev) {struct b53_device *dev = ds->priv;struct ethtool_eee *p = &dev->ports[port].eee;
@@ -1356,8 +1356,8 @@ void b53_port_event(struct dsa_switch *ds, int port) }EXPORT_SYMBOL (b53_port_event); -static void b53_phylink_get_caps (struct dsa_switch *ds,int port, -struct phylink_config *config) +void b53_phylink_get_caps (struct dsa_switch *ds,int port, +struct phylink_config *config) {struct b53_device *dev = ds->priv;
@@ -1401,9 +1401,9 @@ static void b53_phylink_get_caps(struct dsa_switch *ds, int port, config->legacy_pre_march2020 = false; } -static struct phylink_pcs *b53_phylink_mac_select_pcs (struct dsa_switch *ds, -int port, -phy_interface_t interface) +struct phylink_pcs *b53_phylink_mac_select_pcs (struct dsa_switch *ds, +int port, +phy_interface_t interface) {struct b53_device *dev = ds->priv;
@@ -2262,7 +2262,7 @@ int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) }EXPORT_SYMBOL (b53_set_mac_eee); -static int b53_change_mtu (struct dsa_switch *ds,int port,int mtu) +int b53_change_mtu (struct dsa_switch *ds,int port,int mtu) {struct b53_device *dev = ds->priv;bool enable_jumbo;
@@ -2277,7 +2277,7 @@ static int b53_change_mtu(struct dsa_switch *ds, int port, int mtu)return b53_set_jumbo (dev, enable_jumbo, allow_10_100); } -static int b53_get_max_mtu (struct dsa_switch *ds,int port) +int b53_get_max_mtu (struct dsa_switch *ds,int port) {return JMS_MAX_SIZE ; }
drivers/net/dsa/b53/b53_mmap.c +40 -0
@@ -22,6 +22,7 @@#include <linux/io.h> #include <linux/platform_device.h> #include <linux/platform_data/b53.h> +#include <net/dsa.h> #include "b53_priv.h"
@@ -29,6 +30,44 @@ struct b53_mmap_priv {void __iomem *regs; }; +static const struct dsa_switch_ops b53_mmap_switch_ops = { + .get_tag_protocol = b53_get_tag_protocol, + .setup = b53_setup, + .teardown = b53_teardown, + .get_strings = b53_get_strings, + .get_ethtool_stats = b53_get_ethtool_stats, + .get_sset_count = b53_get_sset_count, + .get_ethtool_phy_stats = b53_get_ethtool_phy_stats, + .adjust_link = b53_adjust_link, + .phylink_get_caps = b53_phylink_get_caps, + .phylink_mac_select_pcs = b53_phylink_mac_select_pcs, + .phylink_mac_config = b53_phylink_mac_config, + .phylink_mac_link_down = b53_phylink_mac_link_down, + .phylink_mac_link_up = b53_phylink_mac_link_up, + .port_enable = b53_enable_port, + .port_disable = b53_disable_port, + .get_mac_eee = b53_get_mac_eee, + .set_mac_eee = b53_set_mac_eee, + .port_bridge_join = b53_br_join, + .port_bridge_leave = b53_br_leave, + .port_pre_bridge_flags = b53_br_flags_pre, + .port_bridge_flags = b53_br_flags, + .port_stp_state_set = b53_br_set_stp_state, + .port_fast_age = b53_br_fast_age, + .port_vlan_filtering = b53_vlan_filtering, + .port_vlan_add = b53_vlan_add, + .port_vlan_del = b53_vlan_del, + .port_fdb_dump = b53_fdb_dump, + .port_fdb_add = b53_fdb_add, + .port_fdb_del = b53_fdb_del, + .port_mirror_add = b53_mirror_add, + .port_mirror_del = b53_mirror_del, + .port_mdb_add = b53_mdb_add, + .port_mdb_del = b53_mdb_del, + .port_max_mtu = b53_get_max_mtu, + .port_change_mtu = b53_change_mtu, +}; +static int b53_mmap_read8 (struct b53_device *dev,u8 page,u8 reg,u8 *val) {struct b53_mmap_priv *priv = dev->priv;
@@ -302,6 +341,7 @@ static int b53_mmap_probe(struct platform_device *pdev)if (!dev)return -ENOMEM ; + dev->ds->ops = &b53_mmap_switch_ops; dev->pdata = pdata;platform_set_drvdata (pdev, dev);
drivers/net/dsa/b53/b53_priv.h +11 -0
@@ -348,7 +348,16 @@ int b53_br_flags(struct dsa_switch *ds, int port,struct switchdev_brport_flags flags, struct netlink_ext_ack *extack);int b53_setup_devlink_resources (struct dsa_switch *ds); +int b53_setup (struct dsa_switch *ds); +void b53_teardown (struct dsa_switch *ds); +void b53_adjust_link (struct dsa_switch *ds,int port, +struct phy_device *phydev);void b53_port_event (struct dsa_switch *ds,int port); +void b53_phylink_get_caps (struct dsa_switch *ds,int port, +struct phylink_config *config); +struct phylink_pcs *b53_phylink_mac_select_pcs (struct dsa_switch *ds, +int port, +phy_interface_t interface);void b53_phylink_mac_config (struct dsa_switch *ds,int port,unsigned int mode,const struct phylink_link_state *state);
@@ -396,5 +405,7 @@ void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable);int b53_eee_init (struct dsa_switch *ds,int port,struct phy_device *phy);int b53_get_mac_eee (struct dsa_switch *ds,int port,struct ethtool_eee *e);int b53_set_mac_eee (struct dsa_switch *ds,int port,struct ethtool_eee *e); +int b53_change_mtu (struct dsa_switch *ds,int port,int mtu); +int b53_get_max_mtu (struct dsa_switch *ds,int port);#endif
Signature · 1 line
2.30.2
Quoted 5 lines · Álvaro Fernández Rojas
B53 MMAP switches have a MDIO Mux bus controller which should be used instead of the default phy_read/phy_write ops used in the rest of the B53 controllers. Therefore, in order to use the proper MDIO Mux bus controller we need to replicate the default B53 DSA switch ops removing the phy_read/phy_write entries.
Did you try to implement b53_mmap_ops::phy_read16/phy_write16 and have them return -EIO such that you do not fallback to the else path:
ret = b53_read16(priv, B53_PORT_MII_PAGE(addr),
reg * 2, &value);The reason for the hang I believe is because the B53_PORT_MII_PAGE is simply not mapped into the switch register space, and there is no logic within the switch block to return an error when you read at that invalid location.
Re-implementing dsa_switch_ops is usually done when you have a very different switch integration logic, ala bcm_sf2, here it seems a bit of a tall order for simply not using the phy_read16/phy_write16 functions.
Signature · 1 line
Florian
Quoted 10 lines · Florian Fainelli
Quoted 5 lines · Álvaro Fernández Rojas
B53 MMAP switches have a MDIO Mux bus controller which should be used instead of the default phy_read/phy_write ops used in the rest of the B53 controllers. Therefore, in order to use the proper MDIO Mux bus controller we need to replicate the default B53 DSA switch ops removing the phy_read/phy_write entries.
Did you try to implement b53_mmap_ops::phy_read16/phy_write16 and have them return
-EIOsuch that you do not fallback to the else path:
Actually I tried -EINVAL and it didn't work, but I've just tried -EIO and it works!
Many thanks for the suggestion!
I will send another patch adding phy_read/write ops and returning -EIO, so please ignore this patch and sorry for the noise, but it took a while until we reached a good solution for this :(...
Quoted 9 lines
ret = b53_read16(priv, B53_PORT_MII_PAGE(addr), reg * 2, &value);The reason for the hang I believe is because the
B53_PORT_MII_PAGEis simply not mapped into the switch register space, and there is no logic within the switch block to return an error when you read at that invalid location.
Quoted 6 lines
Re-implementing
dsa_switch_opsis usually done when you have a very different switch integration logic, alabcm_sf2, here it seems a bit of a tall order for simply not using the phy_read16/phy_write16 functions. --
Florian
--
Álvaro
Quoted 13 lines · Álvaro Fernández Rojas
Quoted 10 lines · Florian Fainelli
Quoted 5 lines · Álvaro Fernández Rojas
B53 MMAP switches have a MDIO Mux bus controller which should be used instead of the default phy_read/phy_write ops used in the rest of the B53 controllers. Therefore, in order to use the proper MDIO Mux bus controller we need to replicate the default B53 DSA switch ops removing the phy_read/phy_write entries.
Did you try to implement b53_mmap_ops::phy_read16/phy_write16 and have them return
-EIOsuch that you do not fallback to the else path:
Quoted 7 lines
Actually I tried
-EINVALand it didn't work, but I've just tried-EIOand it works!
Many thanks for the suggestion!I will send another patch adding phy_read/write ops and returning
-EIO, so please ignore this patch and sorry for the noise, but it took a while until we reached a good solution for this :(...
No worries, -EIO works because it is treated specially through the PHY library to indicate a read error occurred, whereas the other return codes do not necessarily produce that effect.
Thanks for your persistence!
Signature · 1 line
Florian