Add MV88E61xx DSA driver and use on gwventana
Subsystems (4)
cover Add MV88E61xx DSA driver and use on gwventana
This series adds a DSA driver for the MV88E61xx based on drivers/net/phy/mv88e61xx and uses in on the gwventana_gw5904_defconfig.
The hope is that the other three boards that use the MV88E61xx driver can move to this as well eventually so that we can remove the non-dm driver and the 4 Kconfig options it requires.
The MV88E61xx has an MDIO interface this DM_MDIO must be used so support for a UCLASS_MDIO driver is added to the fec_mxc ethernet driver in a way that allows a fallback to the previous non DM_MDIO case as there are many boards out there using this driver that define DM_MDIO but do not have the required dt props for a DM_MDIO driver which would cause a regression.
Additionally a patch to ensure MDIO children are scanned on post-bind is needed.
I'm making use of the dm_mdio_read/dm_mdio_write wrapper from Merak that is pending so it is in this series as well.
Best Regards,
Tim
Tim Harvey (6):
net: mdio-uclass: scan for dm mdio children on post-bind
net: dsa: move cpu port probe to dsa_post_probe
net: mdio-uclass: add wrappers for read/write/reset operations
net: fec: add support for DM_MDIO
net: add MV88E61xx DSA driver
board: gw_ventana: enable MV88E61XX DSA support
arch/arm/dts/imx6qdl-gw5904.dtsi | 35 + board/gateworks/gw_ventana/gw_ventana.c | 50 +- configs/gwventana_gw5904_defconfig | 7 +- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/fec_mxc.c | 113 ++- drivers/net/fec_mxc.h | 1 + drivers/net/mv88e61xx.c | 982 ++++++++++++++++++++++++ include/miiphy.h | 31 + net/dsa-uclass.c | 14 +- net/mdio-uclass.c | 35 + 11 files changed, 1227 insertions(+), 49 deletions(-) create mode 100644 drivers/net/mv88e61xx.c
Signature · 1 line
2.17.1
PATCH 1/6 net: mdio-uclass: scan for dm mdio children on post-bind
If a DM_MDIO driver is used we need to scan the subnodes as well.
--- net/mdio-uclass.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mdio-uclass.c +4 -0
@@ -59,7 +59,11 @@ static int dm_mdio_post_bind(struct udevice *dev)return -EINVAL ; } +#if CONFIG_IS_ENABLED (OF_REAL ) +return dm_scan_fdt_dev (dev); +#else return 0 ; +#endif }/*
Signature · 1 line
2.17.1
Re: [PATCH 1/6] net: mdio-uclass: scan for dm mdio children on post-bind
Quoted 26 lines · Tim Harvey
If a
DM_MDIOdriver is used we need to scan the subnodes as well.Signed-off-by Tim Harvey <[email protected]>Signed-off-by Vladimir Oltean <[email protected]>--- net/mdio-uclass.c | 4 ++++ 1 file changed, 4 insertions(+)net/mdio-uclass.c +4
-1@@ -59,7 +59,11 @@ static int dm_mdio_post_bind(struct udevice *dev)return -EINVAL ; } +#if CONFIG_IS_ENABLED (OF_REAL ) +return dm_scan_fdt_dev (dev); +#else return 0 ; +#endif }/* --
Quoted 2 lines
2.17.1
PATCH 2/6 net: dsa: move cpu port probe to dsa_post_probe
In reply to Tim HarveyIn order to ensure that a DSA driver probe gets called before dsa_ops->port_probe move the port_probe of the cpu_port to a post-probe function.
--- net/dsa-uclass.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
net/dsa-uclass.c +11 -3
@@ -466,8 +466,6 @@ static int dsa_pre_probe(struct udevice *dev) {struct dsa_pdata *pdata =dev_get_uclass_plat (dev);struct dsa_priv *priv =dev_get_uclass_priv (dev); -struct dsa_ops *ops =dsa_get_ops (dev); -int err; priv->num_ports = pdata->num_ports; priv->cpu_port = pdata->cpu_port;
@@ -480,6 +478,15 @@ static int dsa_pre_probe(struct udevice *dev)uclass_find_device_by_ofnode (UCLASS_ETH , pdata->master_node, &priv->master_dev); +return 0 ; +} + +static int dsa_post_probe (struct udevice *dev) +{ +struct dsa_priv *priv =dev_get_uclass_priv (dev); +struct dsa_ops *ops =dsa_get_ops (dev); +int err; +/* Simulate a probing event for the CPU port */ if (ops->port_probe) { err = ops->port_probe(dev, priv->cpu_port,
@@ -489,13 +496,14 @@ static int dsa_pre_probe(struct udevice *dev) }return 0 ; -} +};UCLASS_DRIVER (dsa) = { .id =UCLASS_DSA , .name ="dsa" , .post_bind = dsa_post_bind, .pre_probe = dsa_pre_probe, + .post_probe = dsa_post_probe, .per_device_auto =sizeof (struct dsa_priv ), .per_device_plat_auto =sizeof (struct dsa_pdata ), .per_child_plat_auto =sizeof (struct dsa_port_pdata ),
Signature · 1 line
2.17.1
Re: [PATCH 2/6] net: dsa: move cpu port probe to dsa_post_probe
Quoted 56 lines · Tim Harvey
In order to ensure that a DSA driver probe gets called before
dsa_ops->port_probemove theport_probeof thecpu_portto a post-probe function.Signed-off-by Tim Harvey <[email protected]>--- net/dsa-uclass.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)net/dsa-uclass.c +11
-4@@ -466,8 +466,6 @@ static int dsa_pre_probe(struct udevice *dev) {struct dsa_pdata *pdata =dev_get_uclass_plat (dev);struct dsa_priv *priv =dev_get_uclass_priv (dev); -struct dsa_ops *ops =dsa_get_ops (dev); -int err; priv->num_ports = pdata->num_ports; priv->cpu_port = pdata->cpu_port;@@ -480,6 +478,15 @@ static int dsa_pre_probe(struct udevice *dev)uclass_find_device_by_ofnode (UCLASS_ETH , pdata->master_node, &priv->master_dev); +return 0 ; +} + +static int dsa_post_probe (struct udevice *dev) +{ +struct dsa_priv *priv =dev_get_uclass_priv (dev); +struct dsa_ops *ops =dsa_get_ops (dev); +int err; +/* Simulate a probing event for the CPU port */ if (ops->port_probe) { err = ops->port_probe(dev, priv->cpu_port,@@ -489,13 +496,14 @@ static int dsa_pre_probe(struct udevice *dev) }return 0 ; -} +};UCLASS_DRIVER (dsa) = { .id =UCLASS_DSA , .name ="dsa" , .post_bind = dsa_post_bind, .pre_probe = dsa_pre_probe, + .post_probe = dsa_post_probe, .per_device_auto =sizeof (struct dsa_priv ), .per_device_plat_auto =sizeof (struct dsa_pdata ), .per_child_plat_auto =sizeof (struct dsa_port_pdata ), --
Quoted 2 lines
2.17.1
PATCH 3/6 net: mdio-uclass: add wrappers for read/write/reset operations
In reply to Tim HarveyAdd wrappers dm_mdio_read(), dm_mdio_write() and dm_mdio_reset() for DM MDIO's .read(), .write() and .reset() operations.
--- include/miiphy.h | 31 +++++++++++++++++++++++++++++++ net/mdio-uclass.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)
include/miiphy.h +31 -0
@@ -157,6 +157,37 @@ struct mdio_ops {*/ void dm_mdio_probe_devices (void ); +/** +* dm_mdio_read - Wrapper over .read() operation for DM MDIO +* +* @mdiodev: mdio device +* @addr: PHY address on MDIO bus +* @devad: device address on PHY if C45; should be MDIO_DEVAD_NONE if C22 +* @reg: register address +* Return: register value if non-negative, -error code otherwise +*/ +int dm_mdio_read (struct udevice *mdio_dev,int addr,int devad,int reg); + +/** +* dm_mdio_write - Wrapper over .write() operation for DM MDIO +* +* @mdiodev: mdio device +* @addr: PHY address on MDIO bus +* @devad: device address on PHY if C45; should be MDIO_DEVAD_NONE if C22 +* @reg: register address +* @val: value to write +* Return: 0 on success, -error code otherwise +*/ +int dm_mdio_write (struct udevice *mdio_dev,int addr,int devad,int reg,u16 val); + +/** +* dm_mdio_reset - Wrapper over .reset() operation for DM MDIO +* +* @mdiodev: mdio device +* Return: 0 on success, -error code otherwise +*/ +int dm_mdio_reset (struct udevice *mdio_dev); +/** * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO *
net/mdio-uclass.c +31 -0
@@ -66,6 +66,37 @@ static int dm_mdio_post_bind(struct udevice *dev)#endif } +int dm_mdio_read (struct udevice *mdio_dev,int addr,int devad,int reg) +{ +struct mdio_ops *ops =mdio_get_ops (mdio_dev); + +if (!ops->read) +return -ENOSYS ; + +return ops->read (mdio_dev, addr, devad, reg); +} + +int dm_mdio_write (struct udevice *mdio_dev,int addr,int devad,int reg, +u16 val) +{ +struct mdio_ops *ops =mdio_get_ops (mdio_dev); + +if (!ops->write) +return -ENOSYS ; + +return ops->write (mdio_dev, addr, devad, reg, val); +} + +int dm_mdio_reset (struct udevice *mdio_dev) +{ +struct mdio_ops *ops =mdio_get_ops (mdio_dev); + +if (!ops->reset) +return 0 ; + +return ops->reset (mdio_dev); +} +/* * Following read/write/reset functions are registered with legacy MII code. * These are called for PHY operations by upper layers and we further call the
Signature · 1 line
2.17.1
PATCH 4/6 net: fec: add support for DM_MDIO
In reply to Tim HarveyAdd support for DM_MDIO by registering a UCLASS_MDIO driver and attempting to use it. This is necessary if wanting to use a DSA driver for example hanging off of the FEC MAC.
Care is taken to fallback to non DM_MDIO as several boards define DM_MDIO without having the proper device-tree configuration necessary such as an mdio subnode, a phy-mode prop, and either a valid phy-handle prop or fixed-phy subnode.
--- drivers/net/fec_mxc.c | 113 ++++++++++++++++++++++++++++++++++++++---- drivers/net/fec_mxc.h | 1 + 2 files changed, 104 insertions(+), 10 deletions(-)
drivers/net/fec_mxc.c +103 -10
@@ -30,6 +30,8 @@#include <asm/arch/imx-regs.h> #include <asm/mach-imx/sys_proto.h> #include <asm-generic/gpio.h> +#include <dm/device_compat.h> +#include <dm/lists.h> #include "fec_mxc.h" #include <eth_phy.h>
@@ -1025,6 +1027,80 @@ struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id)return bus; } +#ifdef CONFIG_DM_MDIO +struct dm_fec_mdio_priv { +struct ethernet_regs *regs; +}; + +static int dm_fec_mdio_read (struct udevice *dev,int addr,int devad,int reg) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + +return fec_mdio_read (priv->regs, addr, reg); +} + +static int dm_fec_mdio_write (struct udevice *dev,int addr,int devad,int reg,u16 data) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + +return fec_mdio_write (priv->regs, addr, reg, data); +} + +static const struct mdio_ops dm_fec_mdio_ops = { + .read = dm_fec_mdio_read, + .write = dm_fec_mdio_write, +}; + +static int dm_fec_mdio_probe (struct udevice *dev) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + + priv->regs = (struct ethernet_regs *)ofnode_get_addr (dev_ofnode (dev->parent)); + +return 0 ; +} + +U_BOOT_DRIVER (fec_mdio) = { + .name ="fec_mdio" , + .id =UCLASS_MDIO , + .probe = dm_fec_mdio_probe, + .ops = &dm_fec_mdio_ops, + .priv_auto =sizeof (struct dm_fec_mdio_priv ), +}; + +static int dm_fec_bind_mdio (struct udevice *dev) +{ +struct udevice *mdiodev; +const char *name; +ofnode mdio; +int ret; + +/* for a UCLASS_MDIO driver we need to bind and probe manually +* for an internal MDIO bus that has no dt compatible of its own +*/ +ofnode_for_each_subnode (mdio,dev_ofnode (dev)) { + name =ofnode_get_name (mdio); + +if (strcmp (name,"mdio" )) +continue ; + + ret =device_bind_driver_to_node (dev,"fec_mdio" , + name, mdio, &mdiodev); +if (ret) +return ret; + +/* need to probe it as there is no compatible to do so */ + ret =uclass_get_device_by_ofnode (UCLASS_MDIO , mdio, &mdiodev); +if (!ret) +return 0 ; + +break ; + } + +return ret; +} +#endif +static int fecmxc_read_rom_hwaddr (struct udevice *dev) {struct fec_priv *priv =dev_get_priv (dev);
@@ -1088,7 +1164,7 @@ static int device_get_phy_addr(struct fec_priv *priv, struct udevice *dev)static int fec_phy_init (struct fec_priv *priv,struct udevice *dev) { -struct phy_device *phydev; +struct phy_device *phydev =NULL ;int addr; addr =device_get_phy_addr (priv, dev);
@@ -1096,7 +1172,12 @@ static int fec_phy_init(struct fec_priv *priv, struct udevice *dev) addr =CONFIG_FEC_MXC_PHYADDR ;#endif - phydev =phy_connect (priv->bus, addr, dev, priv->interface); +#ifdef CONFIG_DM_MDIO +if (priv->dm_mdio) + phydev =dm_eth_phy_connect (dev); +#endif +if (!phydev) + phydev =phy_connect (priv->bus, addr, dev, priv->interface);if (!phydev)return -ENODEV ;
@@ -1227,11 +1308,19 @@ static int fecmxc_probe(struct udevice *dev) priv->dev_id =dev_seq (dev); +#ifdef CONFIG_DM_MDIO + ret =dm_fec_bind_mdio (dev); +if (!ret) { + ret =fec_phy_init (priv, dev); +if (!ret) + priv->dm_mdio = true; + } +#endif #ifdef CONFIG_DM_ETH_PHY bus =eth_phy_get_mdio_bus (dev);#endif -if (!bus) { +if (!bus && !priv->dm_mdio) { dm_mii_bus = false;#ifdef CONFIG_FEC_MXC_MDIO_BASE bus = fec_get_miibus((ulong)CONFIG_FEC_MXC_MDIO_BASE,
@@ -1240,7 +1329,7 @@ static int fecmxc_probe(struct udevice *dev) bus =fec_get_miibus ((ulong )priv->eth,dev_seq (dev));#endif } -if (!bus) { +if (!bus && !priv->dm_mdio) { ret = -ENOMEM ; goto err_mii; }
@@ -1271,14 +1360,16 @@ static int fecmxc_probe(struct udevice *dev)break ; } - ret =fec_phy_init (priv, dev); -if (ret) - goto err_phy; +if (!priv->dm_mdio) { + ret =fec_phy_init (priv, dev); +if (ret) + goto err_phy; + }return 0 ; err_phy: -if (!dm_mii_bus) { +if (!dm_mii_bus && !priv->dm_mdio) {mdio_unregister (bus);free (bus); }
@@ -1294,8 +1385,10 @@ static int fecmxc_remove(struct udevice *dev)free (priv->phydev);fec_free_descs (priv); -mdio_unregister (priv->bus); -mdio_free (priv->bus); +if (priv->bus) { +mdio_unregister (priv->bus); +mdio_free (priv->bus); + }#ifdef CONFIG_DM_REGULATOR if (priv->phy_supply)
drivers/net/fec_mxc.h +1 -0
@@ -248,6 +248,7 @@ struct fec_priv {uint8_t *tdb_ptr;int dev_id;struct mii_dev *bus; +bool dm_mdio;#ifdef CONFIG_PHYLIB struct phy_device *phydev;ofnode phy_of_node;
Signature · 1 line
2.17.1
Re: [PATCH 4/6] net: fec: add support for DM_MDIO
Quoted 96 lines · Tim Harvey
Add support for
DM_MDIOby registering aUCLASS_MDIOdriver and attempting to use it. This is necessary if wanting to use a DSA driver for example hanging off of the FEC MAC.Care is taken to fallback to non
DM_MDIOas several boards defineDM_MDIOwithout having the proper device-tree configuration necessary such as an mdio subnode, a phy-mode prop, and either a valid phy-handle prop or fixed-phy subnode.Signed-off-by Tim Harvey <[email protected]>--- drivers/net/fec_mxc.c | 113 ++++++++++++++++++++++++++++++++++++++---- drivers/net/fec_mxc.h | 1 + 2 files changed, 104 insertions(+), 10 deletions(-)drivers/net/fec_mxc.c +66
-0@@ -30,6 +30,8 @@#include <asm/arch/imx-regs.h> #include <asm/mach-imx/sys_proto.h> #include <asm-generic/gpio.h> +#include <dm/device_compat.h> +#include <dm/lists.h> #include "fec_mxc.h" #include <eth_phy.h> @@ -1025,6 +1027,80 @@ struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id)return bus; } +#ifdef CONFIG_DM_MDIO +struct dm_fec_mdio_priv { +struct ethernet_regs *regs; +}; + +static int dm_fec_mdio_read (struct udevice *dev,int addr,int devad,int reg) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + +return fec_mdio_read (priv->regs, addr, reg); +} + +static int dm_fec_mdio_write (struct udevice *dev,int addr,int devad,int reg,u16 data) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + +return fec_mdio_write (priv->regs, addr, reg, data); +} + +static const struct mdio_ops dm_fec_mdio_ops = { + .read = dm_fec_mdio_read, + .write = dm_fec_mdio_write, +}; + +static int dm_fec_mdio_probe (struct udevice *dev) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + + priv->regs = (struct ethernet_regs *)ofnode_get_addr (dev_ofnode (dev->parent)); + +return 0 ; +} + +U_BOOT_DRIVER (fec_mdio) = { + .name ="fec_mdio" , + .id =UCLASS_MDIO , + .probe = dm_fec_mdio_probe, + .ops = &dm_fec_mdio_ops, + .priv_auto =sizeof (struct dm_fec_mdio_priv ), +}; + +static int dm_fec_bind_mdio (struct udevice *dev) +{ +struct udevice *mdiodev; +const char *name; +ofnode mdio; +int ret; + +/* for a UCLASS_MDIO driver we need to bind and probe manually +* for an internal MDIO bus that has no dt compatible of its own +*/ +ofnode_for_each_subnode (mdio,dev_ofnode (dev)) { + name =ofnode_get_name (mdio); + +if (strcmp (name,"mdio" )) +continue ; + + ret =device_bind_driver_to_node (dev,"fec_mdio" , + name, mdio, &mdiodev); +if (ret) +return ret; + +/* need to probe it as there is no compatible to do so */ + ret =uclass_get_device_by_ofnode (UCLASS_MDIO , mdio, &mdiodev);
drivers/net/fec_mxc.c struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id) · line 1103
Quoted 10 lines
drivers/net/fec_mxc.c +10
-0+if (!ret) +return 0 ; + + break; + } + +return ret; +} +#endif +
On which branch does this apply? The context above fecmxc_read_rom_hwaddr() is different in the branches I've checked:
https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/net/fec_mxc.c#L1276
https://source.denx.de/u-boot/custodians/u-boot-net/-/blob/next/drivers/net/fec_mxc.c#L1276
Quoted 105 lines
drivers/net/fec_mxc.c +27
-10static int fecmxc_read_rom_hwaddr (struct udevice *dev) {struct fec_priv *priv =dev_get_priv (dev);@@ -1088,7 +1164,7 @@ static int device_get_phy_addr(struct fec_priv *priv, struct udevice *dev)static int fec_phy_init (struct fec_priv *priv,struct udevice *dev) { -struct phy_device *phydev; +struct phy_device *phydev =NULL ;int addr; addr =device_get_phy_addr (priv, dev);@@ -1096,7 +1172,12 @@ static int fec_phy_init(struct fec_priv *priv, struct udevice *dev) addr =CONFIG_FEC_MXC_PHYADDR ;#endif - phydev =phy_connect (priv->bus, addr, dev, priv->interface); +#ifdef CONFIG_DM_MDIO +if (priv->dm_mdio) + phydev =dm_eth_phy_connect (dev); +#endif +if (!phydev) + phydev =phy_connect (priv->bus, addr, dev, priv->interface);if (!phydev)return -ENODEV ;@@ -1227,11 +1308,19 @@ static int fecmxc_probe(struct udevice *dev) priv->dev_id =dev_seq (dev); +#ifdef CONFIG_DM_MDIO + ret =dm_fec_bind_mdio (dev); +if (!ret) { + ret =fec_phy_init (priv, dev); +if (!ret) + priv->dm_mdio = true; + } +#endif #ifdef CONFIG_DM_ETH_PHY bus =eth_phy_get_mdio_bus (dev);#endif -if (!bus) { +if (!bus && !priv->dm_mdio) { dm_mii_bus = false;#ifdef CONFIG_FEC_MXC_MDIO_BASE bus = fec_get_miibus((ulong)CONFIG_FEC_MXC_MDIO_BASE,@@ -1240,7 +1329,7 @@ static int fecmxc_probe(struct udevice *dev) bus =fec_get_miibus ((ulong )priv->eth,dev_seq (dev));#endif } -if (!bus) { +if (!bus && !priv->dm_mdio) { ret = -ENOMEM ; goto err_mii; }@@ -1271,14 +1360,16 @@ static int fecmxc_probe(struct udevice *dev)break ; } - ret =fec_phy_init (priv, dev); -if (ret) - goto err_phy; +if (!priv->dm_mdio) { + ret =fec_phy_init (priv, dev); +if (ret) + goto err_phy; + }return 0 ; err_phy: -if (!dm_mii_bus) { +if (!dm_mii_bus && !priv->dm_mdio) {mdio_unregister (bus);free (bus); }@@ -1294,8 +1385,10 @@ static int fecmxc_remove(struct udevice *dev)free (priv->phydev);fec_free_descs (priv); -mdio_unregister (priv->bus); -mdio_free (priv->bus); +if (priv->bus) { +mdio_unregister (priv->bus); +mdio_free (priv->bus); + }#ifdef CONFIG_DM_REGULATOR if (priv->phy_supply)drivers/net/fec_mxc.h +1
-0@@ -248,6 +248,7 @@ struct fec_priv {uint8_t *tdb_ptr;int dev_id;struct mii_dev *bus; +bool dm_mdio;#ifdef CONFIG_PHYLIB struct phy_device *phydev;ofnode phy_of_node;Signature · 1 line
2.17.1
Re: [PATCH 4/6] net: fec: add support for DM_MDIO
Quoted 105 lines · Vladimir Oltean
Quoted 103 lines · Tim Harvey
Add support for
DM_MDIOby registering aUCLASS_MDIOdriver and attempting to use it. This is necessary if wanting to use a DSA driver for example hanging off of the FEC MAC.Care is taken to fallback to non
DM_MDIOas several boards defineDM_MDIOwithout having the proper device-tree configuration necessary such as an mdio subnode, a phy-mode prop, and either a valid phy-handle prop or fixed-phy subnode.Signed-off-by Tim Harvey <[email protected]>--- drivers/net/fec_mxc.c | 113 ++++++++++++++++++++++++++++++++++++++---- drivers/net/fec_mxc.h | 1 + 2 files changed, 104 insertions(+), 10 deletions(-)drivers/net/fec_mxc.c +73
-0@@ -30,6 +30,8 @@#include <asm/arch/imx-regs.h> #include <asm/mach-imx/sys_proto.h> #include <asm-generic/gpio.h> +#include <dm/device_compat.h> +#include <dm/lists.h> #include "fec_mxc.h" #include <eth_phy.h> @@ -1025,6 +1027,80 @@ struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id)return bus; } +#ifdef CONFIG_DM_MDIO +struct dm_fec_mdio_priv { +struct ethernet_regs *regs; +}; + +static int dm_fec_mdio_read (struct udevice *dev,int addr,int devad,int reg) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + +return fec_mdio_read (priv->regs, addr, reg); +} + +static int dm_fec_mdio_write (struct udevice *dev,int addr,int devad,int reg,u16 data) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + +return fec_mdio_write (priv->regs, addr, reg, data); +} + +static const struct mdio_ops dm_fec_mdio_ops = { + .read = dm_fec_mdio_read, + .write = dm_fec_mdio_write, +}; + +static int dm_fec_mdio_probe (struct udevice *dev) +{ +struct dm_fec_mdio_priv *priv =dev_get_priv (dev); + + priv->regs = (struct ethernet_regs *)ofnode_get_addr (dev_ofnode (dev->parent)); + +return 0 ; +} + +U_BOOT_DRIVER (fec_mdio) = { + .name ="fec_mdio" , + .id =UCLASS_MDIO , + .probe = dm_fec_mdio_probe, + .ops = &dm_fec_mdio_ops, + .priv_auto =sizeof (struct dm_fec_mdio_priv ), +}; + +static int dm_fec_bind_mdio (struct udevice *dev) +{ +struct udevice *mdiodev; +const char *name; +ofnode mdio; +int ret; + +/* for a UCLASS_MDIO driver we need to bind and probe manually +* for an internal MDIO bus that has no dt compatible of its own +*/ +ofnode_for_each_subnode (mdio,dev_ofnode (dev)) { + name =ofnode_get_name (mdio); + +if (strcmp (name,"mdio" )) +continue ; + + ret =device_bind_driver_to_node (dev,"fec_mdio" , + name, mdio, &mdiodev); +if (ret) +return ret; + +/* need to probe it as there is no compatible to do so */ + ret =uclass_get_device_by_ofnode (UCLASS_MDIO , mdio, &mdiodev); +if (!ret) +return 0 ; + +break ; + } + +return ret;
Quoted 9 lines
drivers/net/fec_mxc.c struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id) · line 1103
Quoted 3 lines
drivers/net/fec_mxc.c +3
-0+} +#endif +On which branch does this apply? The context above
fecmxc_read_rom_hwaddr()is different in the branches I've checked:
https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/net/fec_mxc.c#L1276
https://source.denx.de/u-boot/custodians/u-boot-net/-/blob/next/drivers/net/fec_mxc.c#L1276
Sorry, I should have specified in my cover letter that this is on top of next which removes the non dm-eth support from the driver which is quite the cleanup.
Also, after more testing I believe the dm-mdio driver code 'above' is correct but the business of trying to use it and fallback 'below' is wrong and needs work. It doesn't break current users of fec_mxc from what I can tell but it also doesn't properly connect the dm_mdio driver.
Quoted 97 lines
Quoted 97 lines
drivers/net/fec_mxc.c +27
-10static int fecmxc_read_rom_hwaddr (struct udevice *dev) {struct fec_priv *priv =dev_get_priv (dev);@@ -1088,7 +1164,7 @@ static int device_get_phy_addr(struct fec_priv *priv, struct udevice *dev)static int fec_phy_init (struct fec_priv *priv,struct udevice *dev) { -struct phy_device *phydev; +struct phy_device *phydev =NULL ;int addr; addr =device_get_phy_addr (priv, dev);@@ -1096,7 +1172,12 @@ static int fec_phy_init(struct fec_priv *priv, struct udevice *dev) addr =CONFIG_FEC_MXC_PHYADDR ;#endif - phydev =phy_connect (priv->bus, addr, dev, priv->interface); +#ifdef CONFIG_DM_MDIO +if (priv->dm_mdio) + phydev =dm_eth_phy_connect (dev); +#endif +if (!phydev) + phydev =phy_connect (priv->bus, addr, dev, priv->interface);if (!phydev)return -ENODEV ;@@ -1227,11 +1308,19 @@ static int fecmxc_probe(struct udevice *dev) priv->dev_id =dev_seq (dev); +#ifdef CONFIG_DM_MDIO + ret =dm_fec_bind_mdio (dev); +if (!ret) { + ret =fec_phy_init (priv, dev); +if (!ret) + priv->dm_mdio = true; + } +#endif #ifdef CONFIG_DM_ETH_PHY bus =eth_phy_get_mdio_bus (dev);#endif -if (!bus) { +if (!bus && !priv->dm_mdio) { dm_mii_bus = false;#ifdef CONFIG_FEC_MXC_MDIO_BASE bus = fec_get_miibus((ulong)CONFIG_FEC_MXC_MDIO_BASE,@@ -1240,7 +1329,7 @@ static int fecmxc_probe(struct udevice *dev) bus =fec_get_miibus ((ulong )priv->eth,dev_seq (dev));#endif } -if (!bus) { +if (!bus && !priv->dm_mdio) { ret = -ENOMEM ; goto err_mii; }@@ -1271,14 +1360,16 @@ static int fecmxc_probe(struct udevice *dev)break ; } - ret =fec_phy_init (priv, dev); -if (ret) - goto err_phy; +if (!priv->dm_mdio) { + ret =fec_phy_init (priv, dev); +if (ret) + goto err_phy; + }return 0 ; err_phy: -if (!dm_mii_bus) { +if (!dm_mii_bus && !priv->dm_mdio) {mdio_unregister (bus);free (bus); }@@ -1294,8 +1385,10 @@ static int fecmxc_remove(struct udevice *dev)free (priv->phydev);fec_free_descs (priv); -mdio_unregister (priv->bus); -mdio_free (priv->bus); +if (priv->bus) { +mdio_unregister (priv->bus); +mdio_free (priv->bus); + }#ifdef CONFIG_DM_REGULATOR if (priv->phy_supply)drivers/net/fec_mxc.h +0
-0@@ -248,6 +248,7 @@ struct fec_priv {uint8_t *tdb_ptr;int dev_id;
Quoted 8 lines
Quoted 8 lines
drivers/net/fec_mxc.h +1
-1struct mii_dev *bus; +bool dm_mdio;#ifdef CONFIG_PHYLIB struct phy_device *phydev;ofnode phy_of_node; --2.17.1
What I'm trying to accomplish here vs just simply using dm_fec_bind_mdio(dev) and dm_eth_phy_connect(dev) is to provide a fallback for the many users of fec_mxc that do not have a dt that works with dm-mdio yet still have defconfig's that enable DM_MDIO. Most of the users would not currently have an mdio subnode in the fec node, nor have the required phy-mode 'and' phy-handle prop or fixed-link subnode which would cause the dm_eth_phy_connect to fail.
Best Regards,
Tim
Re: [PATCH 4/6] net: fec: add support for DM_MDIO
Quoted 9 lines · Tim Harvey
Quoted 5 lines
On which branch does this apply? The context above
fecmxc_read_rom_hwaddr()is different in the branches I've checked:
https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/net/fec_mxc.c#L1276
https://source.denx.de/u-boot/custodians/u-boot-net/-/blob/next/drivers/net/fec_mxc.c#L1276Sorry, I should have specified in my cover letter that this is on top of next which removes the non dm-eth support from the driver which is quite the cleanup.
Ok, but now the next patch fails to apply to the 'next' branch:
Applying: net: dsa: move cpu port probe to dsa_post_probe
Applying: net: mdio-uclass: add wrappers for read/write/reset operations
Applying: net: fec: add support for DM_MDIO
Applying: net: add MV88E61xx DSA driver
error: patch failed: drivers/net/Kconfig:428
error: drivers/net/Kconfig: patch does not apply
error: patch failed: drivers/net/Makefile:66
error: drivers/net/Makefile: patch does not apply
Patch failed at 0005 net: add MV88E61xx DSA driver
Quoted 5 lines
Also, after more testing I believe the dm-mdio driver code 'above' is correct but the business of trying to use it and fallback 'below' is wrong and needs work. It doesn't break current users of
fec_mxcfrom what I can tell but it also doesn't properly connect thedm_mdiodriver.
Can you spell out what is wrong about the fallback logic?
The whole thing with eth_phy_get_mdio_bus()/eth_phy_set_mdio_bus() has me so confused that I am not really following along anymore.
Quoted 117 lines
Quoted 97 lines
Quoted 97 lines
static int
fecmxc_read_rom_hwaddr(struct udevice *dev){ struct fec_priv *priv = dev_get_priv(dev);drivers/net/fec_mxc.c +27
-10@@ -1088,7 +1164,7 @@ static int device_get_phy_addr(struct fec_priv *priv, struct udevice *dev)static int fec_phy_init (struct fec_priv *priv,struct udevice *dev) { -struct phy_device *phydev; +struct phy_device *phydev =NULL ;int addr; addr =device_get_phy_addr (priv, dev);@@ -1096,7 +1172,12 @@ static int fec_phy_init(struct fec_priv *priv, struct udevice *dev) addr =CONFIG_FEC_MXC_PHYADDR ;#endif - phydev =phy_connect (priv->bus, addr, dev, priv->interface); +#ifdef CONFIG_DM_MDIO +if (priv->dm_mdio) + phydev =dm_eth_phy_connect (dev); +#endif +if (!phydev) + phydev =phy_connect (priv->bus, addr, dev, priv->interface);if (!phydev)return -ENODEV ;@@ -1227,11 +1308,19 @@ static int fecmxc_probe(struct udevice *dev) priv->dev_id =dev_seq (dev); +#ifdef CONFIG_DM_MDIO + ret =dm_fec_bind_mdio (dev); +if (!ret) { + ret =fec_phy_init (priv, dev); +if (!ret) + priv->dm_mdio = true; + } +#endif #ifdef CONFIG_DM_ETH_PHY bus =eth_phy_get_mdio_bus (dev);#endif -if (!bus) { +if (!bus && !priv->dm_mdio) { dm_mii_bus = false;#ifdef CONFIG_FEC_MXC_MDIO_BASE bus = fec_get_miibus((ulong)CONFIG_FEC_MXC_MDIO_BASE,@@ -1240,7 +1329,7 @@ static int fecmxc_probe(struct udevice *dev) bus =fec_get_miibus ((ulong )priv->eth,dev_seq (dev));#endif } -if (!bus) { +if (!bus && !priv->dm_mdio) { ret = -ENOMEM ; goto err_mii; }@@ -1271,14 +1360,16 @@ static int fecmxc_probe(struct udevice *dev)break ; } - ret =fec_phy_init (priv, dev); -if (ret) - goto err_phy; +if (!priv->dm_mdio) { + ret =fec_phy_init (priv, dev); +if (ret) + goto err_phy; + }return 0 ; err_phy: -if (!dm_mii_bus) { +if (!dm_mii_bus && !priv->dm_mdio) {mdio_unregister (bus);free (bus); }@@ -1294,8 +1385,10 @@ static int fecmxc_remove(struct udevice *dev)free (priv->phydev);fec_free_descs (priv); -mdio_unregister (priv->bus); -mdio_free (priv->bus); +if (priv->bus) { +mdio_unregister (priv->bus); +mdio_free (priv->bus); + }#ifdef CONFIG_DM_REGULATOR if (priv->phy_supply)drivers/net/fec_mxc.h +0
-0@@ -248,6 +248,7 @@ struct fec_priv {uint8_t *tdb_ptr;int dev_id;Quoted 8 lines
Quoted 8 lines
drivers/net/fec_mxc.h +1
-1struct mii_dev *bus; +bool dm_mdio;#ifdef CONFIG_PHYLIB struct phy_device *phydev;ofnode phy_of_node; --2.17.1
What I'm trying to accomplish here vs just simply using
dm_fec_bind_mdio(dev)anddm_eth_phy_connect(dev)is to provide a fallback for the many users offec_mxcthat do not have a dt that works with dm-mdio yet still have defconfig's that enableDM_MDIO. Most of the users would not currently have an mdio subnode in the fec node, nor have the required phy-mode 'and' phy-handle prop or fixed-link subnode which would cause thedm_eth_phy_connectto fail.Best Regards,
Tim
Re: [PATCH 4/6] net: fec: add support for DM_MDIO
Quoted 8 lines · Vladimir Oltean
Quoted 6 lines · Tim Harvey
Quoted 5 lines
On which branch does this apply? The context above
fecmxc_read_rom_hwaddr()is different in the branches I've checked:
https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/net/fec_mxc.c#L1276
https://source.denx.de/u-boot/custodians/u-boot-net/-/blob/next/drivers/net/fec_mxc.c#L1276
Quoted 5 lines
Quoted 3 lines
Sorry, I should have specified in my cover letter that this is on top of next which removes the non dm-eth support from the driver which is quite the cleanup.
Ok, but now the next patch fails to apply to the 'next' branch:
I based on top of origin/next, specifically:34d2b7f20369 (origin/next) Merge tag 'v2022.04-rc5' into next
Quoted 11 lines
Applying: net: dsa: move cpu port probe to
dsa_post_probe
Applying: net: mdio-uclass: add wrappers for read/write/reset operations
Applying: net: fec: add support forDM_MDIO
Applying: net: add MV88E61xx DSA driver
error: patch failed:drivers/net/Kconfig:428
error:drivers/net/Kconfig: patch does not apply
error: patch failed:drivers/net/Makefile:66
error:drivers/net/Makefile: patch does not apply
Patch failed at 0005 net: add MV88E61xx DSA driver
Quoted 8 lines
Quoted 5 lines
Also, after more testing I believe the dm-mdio driver code 'above' is correct but the business of trying to use it and fallback 'below' is wrong and needs work. It doesn't break current users of
fec_mxcfrom what I can tell but it also doesn't properly connect thedm_mdiodriver.Can you spell out what is wrong about the fallback logic?
Let me revisit later today and see if I can better explain the issue here and/or come up with a proper fix.
Can you review 'net: add MV88E61xx DSA driver' for me?
Quoted 3 lines
The whole thing with eth_phy_get_mdio_bus()/eth_phy_set_mdio_bus() has me so confused that I am not really following along anymore.
I'm pretty confused at CONFIG_DM_ETH_PHY as well. I think that got added where dm_mdio should have been added instead. see commit 5fe419ef2a61 ("net: Add eth phy generic driver for shared MDIO").
I've added Ye and Peng to the list... maybe they could comment on why dm_mdio wasn't a viable solution for sharing an mdio bus? Its only used in for fec_mxc dwc_eth_qos which are only on IMX boards and believe it was added for IMX8M boards. It's enabled in a whole slew of imx defconfigs where most of them are likely not needed.
Tim
What I'm trying to accomplish here vs just simply using dm_fec_bind_mdio(dev) and dm_eth_phy_connect(dev) is to provide a fallback for the many users of fec_mxc that do not have a dt that works with dm-mdio yet still have defconfig's that enable DM_MDIO. Most of the users would not currently have an mdio subnode in the fec node, nor have the required phy-mode 'and' phy-handle prop or fixed-link subnode which would cause the dm_eth_phy_connect to fail.
Best Regards,
Tim
Re: [PATCH 4/6] net: fec: add support for DM_MDIO
Quoted 1 line · Tim Harvey
Can you review 'net: add MV88E61xx DSA driver' for me?
I will. I've been thinking all day today about what to say that isn't stupid. Give me some time and I'll provide feedback.
PATCH 5/6 net: add MV88E61xx DSA driver
In reply to Tim HarveyAdd a DSA driver for the MV88E61xx compatible GbE Ethernet switches.
--- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/mv88e61xx.c | 982 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 990 insertions(+) create mode 100644 drivers/net/mv88e61xx.c
drivers/net/Kconfig +7 -0
@@ -428,6 +428,13 @@ config LPC32XX_ETH depends on ARCH_LPC32XX default y +config MV88E61XX + bool "Marvell MV88E61xx GbE switch DSA driver" + depends on DM_DSA && DM_MDIO + help + This driver implements a DSA switch driver for the MV88E61xx family + of GbE switches using the MDIO interface + config MVGBE bool "Marvell Orion5x/Kirkwood network interface support" depends on ARCH_KIRKWOOD || ARCH_ORION5X
drivers/net/Makefile +1 -0
@@ -66,6 +66,7 @@ obj-$(CONFIG_MEDIATEK_ETH) += mtk_eth.o obj-$(CONFIG_MPC8XX_FEC) += mpc8xx_fec.o obj-$(CONFIG_MT7620_ETH) += mt7620-eth.o obj-$(CONFIG_MT7628_ETH) += mt7628-eth.o +obj-$(CONFIG_MV88E61XX) += mv88e61xx.o obj-$(CONFIG_MVGBE) += mvgbe.o obj-$(CONFIG_MVMDIO) += mvmdio.o obj-$(CONFIG_MVNETA) += mvneta.o
drivers/net/mv88e61xx.c new file +982 -0
982 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 3 lines · On Tue, 29 Mar 2022 15:52:39 -0700 Tim Harvey <[email protected]> wrote:
Add a DSA driver for the MV88E61xx compatible GbE Ethernet switches.
Signed-off-by Tim Harvey <[email protected]>
Is this final version that should be accepted?
The drivers seems to support not only 61xx, but 6xxx (6096, 6250, 6352, ...).
Also there are some commented lines, for example
drivers/net/mv88e61xx.c line 191
Quoted 3 lines
drivers/net/mv88e61xx.c new file +3
-0+// u16 port_stat_link_mask;/* Bitmask for port link status bits */ +// u16 port_stat_dup_mask; /* Bitmask for port duplex status bits */ +// u8 port_stat_speed_width;/* Width of speed status bitfield */
What is their purpose?
Why is mv88e61xx_dsa_xmit() no-op?
Marek
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 8 lines · Marek Behún
Quoted 3 lines · On Tue, 29 Mar 2022 15:52:39 -0700 Tim Harvey <[email protected]> wrote:
Add a DSA driver for the MV88E61xx compatible GbE Ethernet switches.
Signed-off-by Tim Harvey <[email protected]>
Marek,
Thanks for looking at this.
Quoted 1 line
Is this final version that should be accepted?
This is the first submission of the new driver.
Quoted 3 lines
The drivers seems to support not only 61xx, but 6xxx (6096, 6250, 6352, ...).
It should also support all the same devices that the non dsa driver it was derived from (drivers/net/phy/mv88e61xx.c) but I only have a board with 88E6176 to test with.
It is not completely clear to me what devices are supported in the original driver per Kconfig but from looking over the code I would say the following appear to be supported:
mv88e6096
mv88e6097
mv88e6020
mv88e6070
mv88e6071
mv88e6172
mv88e6176
mv88e6220
mv88e6240
mv88e6250
mv88e6352
Quoted 9 lines
Also there are some commented lines, for example
drivers/net/mv88e61xx.c line 191
Quoted 3 lines
drivers/net/mv88e61xx.c new file +3
-0+// u16 port_stat_link_mask;/* Bitmask for port link status bits */ +// u16 port_stat_dup_mask; /* Bitmask for port duplex status bits */ +// u8 port_stat_speed_width;/* Width of speed status bitfield */ What is their purpose?
oops... that was a mistake. I'm surprised checkpatch didn't catch those. Those were in the non-dsa driver and not used here so will be removed.
Quoted 1 line
Why is
mv88e61xx_dsa_xmit()no-op?
For DSA dsa-uclass calls the switch master eth device send function after calling the dsa_ops->xmit function so that a dsa driver can add any header/footer if needed. The function is required but in my case I don't care about header/footer tagging or vlan as only 1 port is active at a time in U-Boot so I just return success.
Best Regards,
Tim
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 55 lines · On Wed, 30 Mar 2022 08:46:06 -0700 Tim Harvey <[email protected]> wrote:
Quoted 8 lines · Marek Behún
Quoted 3 lines · On Tue, 29 Mar 2022 15:52:39 -0700 Tim Harvey <[email protected]> wrote:
Add a DSA driver for the MV88E61xx compatible GbE Ethernet switches.
Signed-off-by Tim Harvey <[email protected]>Marek,
Thanks for looking at this.
Quoted 1 line
Is this final version that should be accepted?
This is the first submission of the new driver.
Quoted 3 lines
The drivers seems to support not only 61xx, but 6xxx (6096, 6250, 6352, ...).
It should also support all the same devices that the non dsa driver it was derived from (
drivers/net/phy/mv88e61xx.c) but I only have a board with 88E6176 to test with.It is not completely clear to me what devices are supported in the original driver per
Kconfigbut from looking over the code I would say the following appear to be supported:
mv88e6096
mv88e6097
mv88e6020
mv88e6070
mv88e6071
mv88e6172
mv88e6176
mv88e6220
mv88e6240
mv88e6250
mv88e6352Quoted 9 lines
Also there are some commented lines, for example
drivers/net/mv88e61xx.c line 191
Quoted 3 lines
drivers/net/mv88e61xx.c new file +3
-0+// u16 port_stat_link_mask;/* Bitmask for port link status bits */ +// u16 port_stat_dup_mask; /* Bitmask for port duplex status bits */ +// u8 port_stat_speed_width;/* Width of speed status bitfield */ What is their purpose?
oops... that was a mistake. I'm surprised checkpatch didn't catch those. Those were in the non-dsa driver and not used here so will be removed.
Quoted 7 lines
Quoted 1 line
Why is
mv88e61xx_dsa_xmit()no-op?For DSA dsa-uclass calls the switch master eth device send function after calling the
dsa_ops->xmitfunction so that a dsa driver can add any header/footer if needed. The function is required but in my case I don't care about header/footer tagging or vlan as only 1 port is active at a time in U-Boot so I just return success.
So if I make one port active, the other are completely disabled? They won't even switch? Is that how DSA uclass is supposed to work in U-Boot?
I would think that it should be somehow configurable instead.
Marek
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 67 lines · Marek Behún
Quoted 55 lines · On Wed, 30 Mar 2022 08:46:06 -0700 Tim Harvey <[email protected]> wrote:
Quoted 8 lines · Marek Behún
Quoted 3 lines · On Tue, 29 Mar 2022 15:52:39 -0700 Tim Harvey <[email protected]> wrote:
Add a DSA driver for the MV88E61xx compatible GbE Ethernet switches.
Signed-off-by Tim Harvey <[email protected]>Marek,
Thanks for looking at this.
Quoted 1 line
Is this final version that should be accepted?
This is the first submission of the new driver.
Quoted 3 lines
The drivers seems to support not only 61xx, but 6xxx (6096, 6250, 6352, ...).
It should also support all the same devices that the non dsa driver it was derived from (
drivers/net/phy/mv88e61xx.c) but I only have a board with 88E6176 to test with.It is not completely clear to me what devices are supported in the original driver per
Kconfigbut from looking over the code I would say the following appear to be supported:
mv88e6096
mv88e6097
mv88e6020
mv88e6070
mv88e6071
mv88e6172
mv88e6176
mv88e6220
mv88e6240
mv88e6250
mv88e6352Quoted 9 lines
Also there are some commented lines, for example
drivers/net/mv88e61xx.c line 191
Quoted 3 lines
drivers/net/mv88e61xx.c new file +3
-0+// u16 port_stat_link_mask;/* Bitmask for port link status bits */ +// u16 port_stat_dup_mask; /* Bitmask for port duplex status bits */ +// u8 port_stat_speed_width;/* Width of speed status bitfield */ What is their purpose?
oops... that was a mistake. I'm surprised checkpatch didn't catch those. Those were in the non-dsa driver and not used here so will be removed.
Quoted 7 lines
Quoted 1 line
Why is
mv88e61xx_dsa_xmit()no-op?For DSA dsa-uclass calls the switch master eth device send function after calling the
dsa_ops->xmitfunction so that a dsa driver can add any header/footer if needed. The function is required but in my case I don't care about header/footer tagging or vlan as only 1 port is active at a time in U-Boot so I just return success.
Quoted 5 lines
So if I make one port active, the other are completely disabled? They won't even switch? Is that how DSA uclass is supposed to work in U-Boot?
I would think that it should be somehow configurable instead.
Marek,
I'll let Vladimir correct me if I'm wrong but my understanding is DSA in U-Boot is not intended to allow switches to forward packets on their own from port to port but instead just for forwarding packets between the active port and the MAC connected to the CPU (at least that's what I intended when I wrote the ksz9477 dsa driver previously).
In my opinion what a DSA driver provides is avoidance of putting switches in forwarding mode having the potential of easily creating bridge loops. With the existing mv88e61xx driver I've had users create bridge loops often.
Best regards,
Tim
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 22 lines · Tim Harvey
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Why is
mv88e61xx_dsa_xmit()no-op?For DSA dsa-uclass calls the switch master eth device send function after calling the
dsa_ops->xmitfunction so that a dsa driver can add any header/footer if needed. The function is required but in my case I don't care about header/footer tagging or vlan as only 1 port is active at a time in U-Boot so I just return success.Quoted 4 lines
So if I make one port active, the other are completely disabled? They won't even switch? Is that how DSA uclass is supposed to work in U-Boot?
I would think that it should be somehow configurable instead.
Marek,
I'll let Vladimir correct me if I'm wrong but my understanding is DSA in U-Boot is not intended to allow switches to forward packets on their own from port to port but instead just for forwarding packets between the active port and the MAC connected to the CPU (at least that's what I intended when I wrote the ksz9477 dsa driver previously).
Quoted 4 lines
In my opinion what a DSA driver provides is avoidance of putting switches in forwarding mode having the potential of easily creating bridge loops. With the existing mv88e61xx driver I've had users create bridge loops often.
DM_DSA follows the guiding principle that the user doesn't care about the switch more than being able to transfer a boot image through TFTP without causing switching loops in the network. The way this is achieved is by following the "port extender" model which is exactly the way in which Linux DSA was first introduced, prior to having support for L2 bridging offloads via switchdev. For U-Boot, packet forwarding across front ports is effectively a non-goal. In fact, what we want to avoid is the proliferation of bloatware such as cmd/ethsw.c, which can and will be abused to preconfigure a switch from the bootloader so you won't have to manage it from Linux.
Tim, I accept that U-Boot's Ethernet usage model (a single device active at a time, with RX in synchronous poll mode) simplifies DM_DSA to the point that creating/parsing DSA tags (which serve the purpose of multiplexing/demultiplexing packets to/from switch ports) on the CPU is more or less redundant when said multiplexing can be achieved on a time basis by disabling all the ports except the required source/destination switch port and the CPU port. This holds true even when DM_DSA gains support for multi-switch setups.
What I would like, however, is to avoid driver code putting pressure on the DSA uclass code. I don't really like the tracking of the priv->active_port as being the port on which ->port_enable was last called. The only reason this is done is to appease the "port_index != port_pdata->index" check from dsa_port_recv(). In turn, this is because the ->xmit() and ->rcv() DSA ops are not optional. Let's make them optional instead, instead of adding code to a C file that indirectly depends on the code structure from another C file.
But ->port_enable() and ->port_disable() are optional too, and that's not okay, because if the driver doesn't provide a way to enable/disable ports, packets can flow anywhere.
I suggest making it clear to driver writers that it has to be one or the other by sanitizing the ops:
net/dsa-uclass.c +17 -0
@@ -342,6 +342,19 @@ U_BOOT_DRIVER(dsa_port) = { .plat_auto = sizeof(struct eth_pdata), }; +static int dsa_sanitize_ops (struct udevice *dev) +{ +struct dsa_ops *ops =dsa_get_ops (dev); + +if ((!ops->xmit || !ops->rcv) && + (!ops->port_enable && !ops->port_disable)) { +dev_err (dev,"Packets cannot be steered to ports\n" ); +return -EINVAL ; + } + +return 0 ; +} +/* * This function mostly deals with pulling information out of the device tree * into the pdata structure.
@@ -358,6 +371,10 @@ static int dsa_post_bind(struct udevice *dev)if (!ofnode_valid (node))return -ENODEV ; + err =dsa_sanitize_ops (dev); +if (err) +return err; + pdata->master_node =ofnode_null (); node =ofnode_find_subnode (node,"ports" );
Then we can properly make rcv() and xmit() optional at the level of the DSA uclass. This way we avoid the tail chasing approach of pretending that "return priv->active_port" _is_ the way to decode a packet for a certain driver. It isn't, and it should just be DSA's fallback if no such method is known. I'd like to preserve the option to implement a rcv() and xmit() procedure, because it offers one extra layer of safety that the CPU is really talking to the switch port it thinks it's talking, plus inter-switch traffic is reduced in cross-chip topologies (which are not supported now, but maybe they will be).
I think that fallback could look like this:
net/dsa-uclass.c +19 -9
@@ -131,16 +131,15 @@ static void dsa_port_stop(struct udevice *pdev)* We copy the frame to a stack buffer where we have reserved headroom and * tailroom space. Headroom and tailroom are set to 0. */ -static int dsa_port_send (struct udevice *pdev,void *packet,int length) +static int dsa_port_mangle_packet (struct udevice *pdev,void *packet, +int length) { +struct dsa_port_pdata *port_pdata =dev_get_parent_plat (pdev);struct udevice *dev =dev_get_parent (pdev);struct dsa_priv *priv =dev_get_uclass_priv (dev);int head = priv->headroom, tail = priv->tailroom; -struct udevice *master =dsa_get_master (dev);struct dsa_ops *ops =dsa_get_ops (dev);uchar dsa_packet_tmp[PKTSIZE_ALIGN ]; -struct dsa_port_pdata *port_pdata; -int err;if (length + head + tail >PKTSIZE_ALIGN )return -EINVAL ;
@@ -152,10 +151,21 @@ static int dsa_port_send(struct udevice *pdev, void *packet, int length)/* copy back to preserve original buffer alignment */ memcpy (packet, dsa_packet_tmp, length); - port_pdata =dev_get_parent_plat (pdev); - err = ops->xmit (dev, port_pdata->index, packet, length); -if (err) -return err; +return ops->xmit (dev, port_pdata->index, packet, length); +} + +static int dsa_port_send (struct udevice *pdev,void *packet,int length) +{ +struct udevice *dev =dev_get_parent (pdev); +struct udevice *master =dsa_get_master (dev); +struct dsa_ops *ops =dsa_get_ops (dev); +int err; + +if (ops->xmit) { + err =dsa_port_mangle_packet (pdev, packet, length); +if (err) +return err; + }return eth_get_ops (master)->send (master, packet, length); }
@@ -172,7 +182,7 @@ static int dsa_port_recv(struct udevice *pdev, int flags, uchar **packetp)int length, port_index, err; length =eth_get_ops (master)->recv (master, flags, packetp); -if (length <=0 ) +if (length <=0 || !ops->rcv)return length;/*
I think part of the reason for which Tim is actively trying to avoid DSA tag inserting and parsing is because fec_mxc.c refuses to send packets larger than 1500 bytes. As a side note, I do think that limitation should be lifted and do allow for a reasonable amount of extra bytes, because as things stand, if somebody will want to implement rcv() and xmit() for either the mv88e6xxx or ksz9477 drivers, they'll involuntarily break the boards where fec is a DSA master, which isn't really very fair.
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 29 lines · Vladimir Oltean
Quoted 22 lines · Tim Harvey
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Why is
mv88e61xx_dsa_xmit()no-op?For DSA dsa-uclass calls the switch master eth device send function after calling the
dsa_ops->xmitfunction so that a dsa driver can add any header/footer if needed. The function is required but in my case I don't care about header/footer tagging or vlan as only 1 port is active at a time in U-Boot so I just return success.Quoted 4 lines
So if I make one port active, the other are completely disabled? They won't even switch? Is that how DSA uclass is supposed to work in U-Boot?
I would think that it should be somehow configurable instead.
Marek,
I'll let Vladimir correct me if I'm wrong but my understanding is DSA in U-Boot is not intended to allow switches to forward packets on their own from port to port but instead just for forwarding packets between the active port and the MAC connected to the CPU (at least that's what I intended when I wrote the ksz9477 dsa driver previously).
Quoted 4 lines
In my opinion what a DSA driver provides is avoidance of putting switches in forwarding mode having the potential of easily creating bridge loops. With the existing mv88e61xx driver I've had users create bridge loops often.
Quoted 10 lines
DM_DSAfollows the guiding principle that the user doesn't care about the switch more than being able to transfer a boot image through TFTP without causing switching loops in the network. The way this is achieved is by following the "port extender" model which is exactly the way in which Linux DSA was first introduced, prior to having support for L2 bridging offloads via switchdev. For U-Boot, packet forwarding across front ports is effectively a non-goal. In fact, what we want to avoid is the proliferation of bloatware such ascmd/ethsw.c, which can and will be abused to preconfigure a switch from the bootloader so you won't have to manage it from Linux.
Vladimir,
I also want to avoid the proliferation of bloatware which is primarily why I want to avoid having to muck with packets when there is only one port active at a time which I feel is completely unnecessary.
Quoted 127 lines
Tim, I accept that U-Boot's Ethernet usage model (a single device active at a time, with RX in synchronous poll mode) simplifies
DM_DSAto the point that creating/parsing DSA tags (which serve the purpose of multiplexing/demultiplexing packets to/from switch ports) on the CPU is more or less redundant when said multiplexing can be achieved on a time basis by disabling all the ports except the required source/destination switch port and the CPU port. This holds true even whenDM_DSAgains support for multi-switch setups.What I would like, however, is to avoid driver code putting pressure on the DSA uclass code. I don't really like the tracking of the
priv->active_portas being the port on which ->port_enable was last called. The only reason this is done is to appease the "port_index!=port_pdata->index" check fromdsa_port_recv(). In turn, this is because the ->xmit() and ->rcv() DSA ops are not optional. Let's make them optional instead, instead of adding code to a C file that indirectly depends on the code structure from another C file.But ->port_enable() and ->port_disable() are optional too, and that's not okay, because if the driver doesn't provide a way to enable/disable ports, packets can flow anywhere.
I suggest making it clear to driver writers that it has to be one or the other by sanitizing the ops:
net/dsa-uclass.c +17
-0@@ -342,6 +342,19 @@ U_BOOT_DRIVER(dsa_port) = { .plat_auto = sizeof(struct eth_pdata), }; +static int dsa_sanitize_ops (struct udevice *dev) +{ +struct dsa_ops *ops =dsa_get_ops (dev); + +if ((!ops->xmit || !ops->rcv) && + (!ops->port_enable && !ops->port_disable)) { +dev_err (dev,"Packets cannot be steered to ports\n" ); +return -EINVAL ; + } + +return 0 ; +} +/* * This function mostly deals with pulling information out of the device tree * into the pdata structure. @@ -358,6 +371,10 @@ static int dsa_post_bind(struct udevice *dev)if (!ofnode_valid (node))return -ENODEV ; + err =dsa_sanitize_ops (dev); +if (err) +return err; + pdata->master_node =ofnode_null (); node =ofnode_find_subnode (node,"ports" );Then we can properly make
rcv()andxmit()optional at the level of the DSA uclass. This way we avoid the tail chasing approach of pretending that "returnpriv->active_port" _is_ the way to decode a packet for a certain driver. It isn't, and it should just be DSA's fallback if no such method is known. I'd like to preserve the option to implement arcv()andxmit()procedure, because it offers one extra layer of safety that the CPU is really talking to the switch port it thinks it's talking, plus inter-switch traffic is reduced in cross-chip topologies (which are not supported now, but maybe they will be).I think that fallback could look like this:
net/dsa-uclass.c +18
-8@@ -131,16 +131,15 @@ static void dsa_port_stop(struct udevice *pdev)* We copy the frame to a stack buffer where we have reserved headroom and * tailroom space. Headroom and tailroom are set to 0. */ -static int dsa_port_send (struct udevice *pdev,void *packet,int length) +static int dsa_port_mangle_packet (struct udevice *pdev,void *packet, +int length) { +struct dsa_port_pdata *port_pdata =dev_get_parent_plat (pdev);struct udevice *dev =dev_get_parent (pdev);struct dsa_priv *priv =dev_get_uclass_priv (dev);int head = priv->headroom, tail = priv->tailroom; -struct udevice *master =dsa_get_master (dev);struct dsa_ops *ops =dsa_get_ops (dev);uchar dsa_packet_tmp[PKTSIZE_ALIGN ]; -struct dsa_port_pdata *port_pdata; -int err;if (length + head + tail >PKTSIZE_ALIGN )return -EINVAL ;@@ -152,10 +151,21 @@ static int dsa_port_send(struct udevice *pdev, void *packet, int length)/* copy back to preserve original buffer alignment */ memcpy (packet, dsa_packet_tmp, length); - port_pdata =dev_get_parent_plat (pdev); - err = ops->xmit (dev, port_pdata->index, packet, length); -if (err) -return err; +return ops->xmit (dev, port_pdata->index, packet, length); +} + +static int dsa_port_send (struct udevice *pdev,void *packet,int length) +{ +struct udevice *dev =dev_get_parent (pdev); +struct udevice *master =dsa_get_master (dev); +struct dsa_ops *ops =dsa_get_ops (dev); +int err; + +if (ops->xmit) { + err =dsa_port_mangle_packet (pdev, packet, length); +if (err) +return err; + }return eth_get_ops (master)->send (master, packet, length); }
net/dsa-uclass.c static int dsa_port_recv(struct udevice *pdev, int flags, uchar **packetp) · line 188
Quoted 8 lines
net/dsa-uclass.c +1
-1@@ -172,7 +182,7 @@ static int dsa_port_recv(struct udevice *pdev, int flags, uchar **packetp)int length, port_index, err; length =eth_get_ops (master)->recv (master, flags, packetp); -if (length <=0 ) +if (length <=0 || !ops->rcv)return length;/*
I can add this to my series if I submit a follow-up.
Quoted 8 lines
I think part of the reason for which Tim is actively trying to avoid DSA tag inserting and parsing is because
fec_mxc.crefuses to send packets larger than 1500 bytes. As a side note, I do think that limitation should be lifted and do allow for a reasonable amount of extra bytes, because as things stand, if somebody will want to implementrcv()and
xmit()for either the mv88e6xxx or ksz9477 drivers, they'll involuntarily break the boards where fec is a DSA master, which isn't really very fair.
Very likely.
I guess I'll have to invest in tagging packets if you won't accept the simplistic approach of not having to tag frames knowing that only one port is active at a time.
That said, I have no idea if or when I will re-visit this. Adding a DSA version of this driver was something on my personal wish list and not something that was necessary by any means by my employer so I may have to just drop it as I don't have the personal time to work through this part of it or unravelling the mii bus mess in the fec_mxc driver. It seems to me there is an issue with trying to create DM_MDIO drivers in general as most dt's I've seen wouldn't support the requirements yet configure DM_MDIO anyway (meaning if you implemented it you would break those boards as I found).
Best Regards,
Tim
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 3 lines · Tim Harvey
I guess I'll have to invest in tagging packets if you won't accept the simplistic approach of not having to tag frames knowing that only one port is active at a time.
I genuinely don't know where you got the impression from that I don't accept the simplistic approach. I gave you an option to make the xmit and receive ops actually optional at the DSA uclass level so you don't have to come up with a make-believe tag parsing function. In the end it goes towards the simplification of the Marvell driver. Let's let them battle it out for a while and if tag insertion/parsing won't be necessary even for multi-switch systems we can discuss about removing that logic completely.
Quoted 9 lines
That said, I have no idea if or when I will re-visit this. Adding a DSA version of this driver was something on my personal wish list and not something that was necessary by any means by my employer so I may have to just drop it as I don't have the personal time to work through this part of it or unravelling the mii bus mess in the
fec_mxcdriver. It seems to me there is an issue with trying to createDM_MDIOdrivers in general as most dt's I've seen wouldn't support the requirements yet configureDM_MDIOanyway (meaning if you implemented it you would break those boards as I found).
I don't know why there are boards which set CONFIG_DM_MDIO and then fight against the current trying to survive that config being set. Maybe you can look into disabling that config option on boards that aren't prepared to handle it?
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 6 lines · Vladimir Oltean
Quoted 3 lines · Tim Harvey
I guess I'll have to invest in tagging packets if you won't accept the simplistic approach of not having to tag frames knowing that only one port is active at a time.
Quoted 8 lines
I genuinely don't know where you got the impression from that I don't accept the simplistic approach. I gave you an option to make the xmit and receive ops actually optional at the DSA uclass level so you don't have to come up with a make-believe tag parsing function. In the end it goes towards the simplification of the Marvell driver. Let's let them battle it out for a while and if tag insertion/parsing won't be necessary even for multi-switch systems we can discuss about removing that logic completely.
Ok... sorry I misunderstood.
Quoted 11 lines
Quoted 10 lines
That said, I have no idea if or when I will re-visit this. Adding a DSA version of this driver was something on my personal wish list and not something that was necessary by any means by my employer so I may have to just drop it as I don't have the personal time to work through this part of it or unravelling the mii bus mess in the
fec_mxcdriver. It seems to me there is an issue with trying to createDM_MDIOdrivers in general as most dt's I've seen wouldn't support the requirements yet configureDM_MDIOanyway (meaning if you implemented it you would break those boards as I found).
Quoted 4 lines
I don't know why there are boards which set
CONFIG_DM_MDIOand then fight against the current trying to survive that config being set. Maybe you can look into disabling that config option on boards that aren't prepared to handle it?
There might not be many boards that would 'break'. Here's what uses FEC_MXC and DM_MDIO:
$ grep -H CONFIG_FEC_MXC configs/* | awk -F: '{ print $1 }' | xargs grep DM_MDIO
configs/colibri_imx7_defconfig:CONFIG_DM_MDIO=y
configs/colibri_imx7_emmc_defconfig:CONFIG_DM_MDIO=y
configs/ge_b1x5v2_defconfig:CONFIG_DM_MDIO=y
configs/gwventana_emmc_defconfig:CONFIG_DM_MDIO=y
configs/gwventana_gw5904_defconfig:CONFIG_DM_MDIO=y
configs/gwventana_nand_defconfig:CONFIG_DM_MDIO=y
configs/imx7_cm_defconfig:CONFIG_DM_MDIO=y
configs/imx7_cm_defconfig:CONFIG_DM_MDIO_MUX=y
configs/imx8mm_venice_defconfig:CONFIG_DM_MDIO=y
configs/imx8mn_venice_defconfig:CONFIG_DM_MDIO=y
configs/imx8mp_venice_defconfig:CONFIG_DM_MDIO=y
configs/m53menlo_defconfig:CONFIG_DM_MDIO=y
configs/mx7dsabresd_defconfig:CONFIG_DM_MDIO=y
configs/mx7dsabresd_defconfig:CONFIG_DM_MDIO_MUX=y
configs/mx7dsabresd_qspi_defconfig:CONFIG_DM_MDIO=y
configs/mx7dsabresd_qspi_defconfig:CONFIG_DM_MDIO_MUX=y
configs/opos6uldev_defconfig:CONFIG_DM_MDIO=y
configs/pcm058_defconfig:CONFIG_DM_MDIO=y
configs/pico-dwarf-imx7d_defconfig:CONFIG_DM_MDIO=y
configs/pico-hobbit-imx7d_defconfig:CONFIG_DM_MDIO=y
configs/pico-imx7d_bl33_defconfig:CONFIG_DM_MDIO=y
configs/pico-imx7d_defconfig:CONFIG_DM_MDIO=y
configs/pico-nymph-imx7d_defconfig:CONFIG_DM_MDIO=y
configs/pico-pi-imx7d_defconfig:CONFIG_DM_MDIO=y
configs/udoo_neo_defconfig:CONFIG_DM_MDIO=yThe venice/gwventana ones are mine so I can easily test/fix. For the others just looking at their CONFIG_DEFAULT_DEVICE_TREE and eliminating duplicates I see:
I believe these would break:arch/arm/dts/imx7-colibri-rawnand.dts (no mdio subnode) arch/arm/dts/imx7-colibri-emmc.dts (no mdio subnode) arch/arm/dts/imx6sx-udoo-neo-basic.dts (no phy-mode)
These should be ok; have phy-mode, phy-handle, mdio subnode arch/arm/dts/imx6dl-b1x5v2.dts arch/arm/dts/imx7-cm.dts arch/arm/dts/imx53-m53menlo.dts arch/arm/dts/imx6ul-opos6uldev.dts arch/arm/dts/imx6q-phytec-mira-rdk-nand.dts arch/arm/dts/imx7d-pico-pi.dts
These may be ok; has phy-mode, phy-handle, mdio subnode for fec1, but missing mdio subnode for fec2 (but should use mdio from fec1) arch/arm/dts/imx7d-sdb.dtsarch/arm/dts/imx7d-sdb-qspi.dts
I feel like I would need to get all board maintainers using FEC_MXC to sign-off that their boards still work.
But then there is this issue of CONFIG_DM_ETH_PHY that still throws around the concept of struct mii_dev* (which I think should have been handled by switching to DM_MDIO). There are now three drivers using this and I'm not sure what to do with that. There are 28 boards using CONFIG_DM_ETH_PHY (and likely some which are not even using one of the three drivers that even use CONFIG_DM_ETH_PHY).
Is there a move to try and move all network drivers to DM_MDIO eliminating the need for struct mii_dev* within those drivers?
Best Regards,
Tim
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 2 lines · On Thu, 7 Apr 2022 16:03:12 -0700 Tim Harvey <[email protected]> wrote:
Is there a move to try and move all network drivers to
DM_MDIOeliminating the need for struct mii_dev* within those drivers?
Yes.
Marek
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
In reply to Tim HarveyQuoted 73 lines · Tim Harvey
Add a DSA driver for the MV88E61xx compatible GbE Ethernet switches.
Signed-off-by Tim Harvey <[email protected]>--- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/mv88e61xx.c | 982 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 990 insertions(+) create mode 100644 drivers/net/mv88e61xx.cdrivers/net/Kconfig +7
-0@@ -428,6 +428,13 @@ config LPC32XX_ETH depends on ARCH_LPC32XX default y +config MV88E61XX + bool "Marvell MV88E61xx GbE switch DSA driver" + depends on DM_DSA && DM_MDIO + help + This driver implements a DSA switch driver for the MV88E61xx family + of GbE switches using the MDIO interface + config MVGBE bool "Marvell Orion5x/Kirkwood network interface support" depends on ARCH_KIRKWOOD || ARCH_ORION5Xdrivers/net/Makefile +1
-0@@ -66,6 +66,7 @@ obj-$(CONFIG_MEDIATEK_ETH) += mtk_eth.o obj-$(CONFIG_MPC8XX_FEC) += mpc8xx_fec.o obj-$(CONFIG_MT7620_ETH) += mt7620-eth.o obj-$(CONFIG_MT7628_ETH) += mt7628-eth.o +obj-$(CONFIG_MV88E61XX) += mv88e61xx.o obj-$(CONFIG_MVGBE) += mvgbe.o obj-$(CONFIG_MVMDIO) += mvmdio.o obj-$(CONFIG_MVNETA) += mvneta.odrivers/net/mv88e61xx.c new file +27
-0@@ -0,0 +1,982 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2022 +* Gateworks Corporation <www.gateworks.com> +* Tim Harvey <[email protected]> +* +* (C) Copyright 2015 +* Elecsys Corporation <www.elecsyscorp.com> +* Kevin Smith <[email protected]> +* +* Original driver: +* (C) Copyright 2009 +* Marvell Semiconductor <www.marvell.com> +* Prafulla Wadaskar <[email protected]> +*/ + +/* +* DSA driver for mv88e61xx ethernet switches. +* +* This driver configures the mv88e61xx for basic use as a DSA switch. +* +* This driver was adapted from drivers/net/phy/mv88e61xx and tested +* on the mv88e6176 via an SGMII interface. +*/ + +#include <bitfield.h> +#include <common.h>
drivers/net/mv88e61xx.c line 37
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+#include <miiphy.h> +#include <dm/device.h> +#include <dm/device_compat.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/of_extra.h> +#include <linux/delay.h> +#include <net/dsa.h> + +#define PORT_MASK (port_count) ((1 << (port_count)) - 1)
Not used.
Quoted 136 lines
drivers/net/mv88e61xx.c new file +136
-0+ +/* Device addresses */ +#define DEVADDR_PHY (p) (p) +#define DEVADDR_SERDES 0x0F + +/* SMI indirection registers for multichip addressing mode */ +#define SMI_CMD_REG 0x00 +#define SMI_DATA_REG 0x01 + +/* Global registers */ +#define GLOBAL1_STATUS 0x00 +#define GLOBAL1_CTRL 0x04 +#define GLOBAL1_MON_CTRL 0x1A + +/* Global 2 registers */ +#define GLOBAL2_REG_PHY_CMD 0x18 +#define GLOBAL2_REG_PHY_DATA 0x19 +#define GLOBAL2_REG_SCRATCH 0x1A + +/* Port registers */ +#define PORT_REG_STATUS 0x00 +#define PORT_REG_PHYS_CTRL 0x01 +#define PORT_REG_SWITCH_ID 0x03 +#define PORT_REG_CTRL 0x04 +#define PORT_REG_VLAN_MAP 0x06 +#define PORT_REG_VLAN_ID 0x07 +#define PORT_REG_LED_CTRL 0x16 + +/* Phy registers */ +#define PHY_REG_CTRL1 0x10 +#define PHY_REG_STATUS1 0x11 +#define PHY_REG_PAGE 0x16 + +/* Serdes registers */ +#define SERDES_REG_CTRL_1 0x10 + +/* Phy page numbers */ +#define PHY_PAGE_COPPER 0 +#define PHY_PAGE_SERDES 1 + +/* Register fields */ +#define GLOBAL1_CTRL_SWRESET BIT(15) + +#define GLOBAL1_MON_CTRL_CPUDEST_SHIFT 4 +#define GLOBAL1_MON_CTRL_CPUDEST_WIDTH 4 + +#define PORT_REG_STATUS_SPEED_SHIFT 8 +#define PORT_REG_STATUS_SPEED_10 0 +#define PORT_REG_STATUS_SPEED_100 1 +#define PORT_REG_STATUS_SPEED_1000 2 + +#define PORT_REG_STATUS_CMODE_MASK 0xF +#define PORT_REG_STATUS_CMODE_100BASE_X 0x8 +#define PORT_REG_STATUS_CMODE_1000BASE_X 0x9 +#define PORT_REG_STATUS_CMODE_SGMII 0xa + +#define PORT_REG_PHYS_CTRL_RGMII_DELAY_RXCLK BIT(15) +#define PORT_REG_PHYS_CTRL_RGMII_DELAY_TXCLK BIT(14) +#define PORT_REG_PHYS_CTRL_PCS_AN_EN BIT(10) +#define PORT_REG_PHYS_CTRL_PCS_AN_RST BIT(9) +#define PORT_REG_PHYS_CTRL_FC_VALUE BIT(7) +#define PORT_REG_PHYS_CTRL_FC_FORCE BIT(6) +#define PORT_REG_PHYS_CTRL_LINK_VALUE BIT(5) +#define PORT_REG_PHYS_CTRL_LINK_FORCE BIT(4) +#define PORT_REG_PHYS_CTRL_DUPLEX_VALUE BIT(3) +#define PORT_REG_PHYS_CTRL_DUPLEX_FORCE BIT(2) +#define PORT_REG_PHYS_CTRL_SPD1000 BIT(1) +#define PORT_REG_PHYS_CTRL_SPD100 BIT(0) +#define PORT_REG_PHYS_CTRL_SPD_MASK (BIT(1) | BIT(0)) + +#define PORT_REG_CTRL_PSTATE_SHIFT 0 +#define PORT_REG_CTRL_PSTATE_WIDTH 2 + +#define PORT_REG_VLAN_ID_DEF_VID_SHIFT 0 +#define PORT_REG_VLAN_ID_DEF_VID_WIDTH 12 + +#define PORT_REG_VLAN_MAP_TABLE_SHIFT 0 +#define PORT_REG_VLAN_MAP_TABLE_WIDTH 11 + +#define SERDES_REG_CTRL_1_FORCE_LINK BIT(10) + +/* Field values */ +#define PORT_REG_CTRL_PSTATE_DISABLED 0 +#define PORT_REG_CTRL_PSTATE_FORWARD 3 + +#define PHY_REG_CTRL1_ENERGY_DET_OFF 0 +#define PHY_REG_CTRL1_ENERGY_DET_SENSE_PULSE 1 +#define PHY_REG_CTRL1_ENERGY_DET_SENSE_ONLY 2 +#define PHY_REG_CTRL1_ENERGY_DET_SENSE_XMIT 3 + +/* PHY Status Register */ +#define PHY_REG_STATUS1_SPEED 0xc000 +#define PHY_REG_STATUS1_GBIT 0x8000 +#define PHY_REG_STATUS1_100 0x4000 +#define PHY_REG_STATUS1_DUPLEX 0x2000 +#define PHY_REG_STATUS1_SPDDONE 0x0800 +#define PHY_REG_STATUS1_LINK 0x0400 +#define PHY_REG_STATUS1_ENERGY 0x0010 + +/* +* Macros for building commands for indirect addressing modes. These are valid +* for both the indirect multichip addressing mode and the PHY indirection +* required for the writes to any PHY register. +*/ +#define SMI_BUSY BIT(15) +#define SMI_CMD_CLAUSE_22 BIT(12) +#define SMI_CMD_CLAUSE_22_OP_READ (2 << 10) +#define SMI_CMD_CLAUSE_22_OP_WRITE (1 << 10) + +#define SMI_CMD_READ (SMI_BUSY | SMI_CMD_CLAUSE_22 | \ + SMI_CMD_CLAUSE_22_OP_READ) +#define SMI_CMD_WRITE (SMI_BUSY | SMI_CMD_CLAUSE_22 | \ + SMI_CMD_CLAUSE_22_OP_WRITE) + +#define SMI_CMD_ADDR_SHIFT 5 +#define SMI_CMD_ADDR_WIDTH 5 +#define SMI_CMD_REG_SHIFT 0 +#define SMI_CMD_REG_WIDTH 5 + +/* Defines for Scratch and Misc Registers */ +#define SCRATCH_UPDATE BIT(15) +#define SCRATCH_ADDR_SHIFT 8 +#define SCRATCH_ADDR_WIDTH 7 + +/* Scratch registers */ +#define SCRATCH_ADDR_GPIO0DIR 0x62/* GPIO[7:0] direction 1=input */ +#define SCRATCH_ADDR_GPIO1DIR 0x63/* GPIO[14:8] direction 1=input */ +#define SCRATCH_ADDR_GPIO0DATA 0x64/* GPIO[7:0] data */ +#define SCRATCH_ADDR_GPIO1DATA 0x65/* GPIO[14:8] data */ +#define SCRATCH_ADDR_GPIO0CTRL 0x68/* GPIO[1:0] control */ +#define SCRATCH_ADDR_GPIO1CTRL 0x69/* GPIO[3:2] control */ + +/* ID register values for different switch models */ +#define PORT_SWITCH_ID_6020 0x0200 +#define PORT_SWITCH_ID_6070 0x0700 +#define PORT_SWITCH_ID_6071 0x0710
drivers/net/mv88e61xx.c line 183
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+#define PORT_SWITCH_ID_6096 0x0980 +#define PORT_SWITCH_ID_6097 0x0990 +#define PORT_SWITCH_ID_6172 0x1720 +#define PORT_SWITCH_ID_6176 0x1760 +#define PORT_SWITCH_ID_6220 0x2200 +#define PORT_SWITCH_ID_6240 0x2400 +#define PORT_SWITCH_ID_6250 0x2500 +#define PORT_SWITCH_ID_6352 0x3520 + +struct mv88e61xx_phy_priv {
Could we choose a better name than mv88e61xx_phy_priv? It is not a PHY, it is a switch.
Quoted 53 lines
drivers/net/mv88e61xx.c new file +53
-0+static int mv88e61xx_fixed_port_setup (struct udevice *dev,u8 port) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +int val; + + val =mv88e61xx_port_read (dev, port,PORT_REG_PHYS_CTRL ); +if (val <0 ) +return val; + + val &= ~(PORT_REG_PHYS_CTRL_SPD_MASK | +PORT_REG_PHYS_CTRL_FC_VALUE | +PORT_REG_PHYS_CTRL_FC_FORCE ); + val |=PORT_REG_PHYS_CTRL_FC_FORCE | +PORT_REG_PHYS_CTRL_DUPLEX_VALUE | +PORT_REG_PHYS_CTRL_DUPLEX_FORCE ; + +if (priv->id ==PORT_SWITCH_ID_6071 ) { + val |=PORT_REG_PHYS_CTRL_SPD100 ; + }else { + val |=PORT_REG_PHYS_CTRL_PCS_AN_EN | +PORT_REG_PHYS_CTRL_PCS_AN_RST | +PORT_REG_PHYS_CTRL_SPD1000 ; + } + +if (port == dsa_pdata->cpu_port) + val |=PORT_REG_PHYS_CTRL_LINK_VALUE | +PORT_REG_PHYS_CTRL_LINK_FORCE ; + +return mv88e61xx_port_write (dev, port,PORT_REG_PHYS_CTRL , val); +} + +static int mv88e61xx_set_cpu_port (struct udevice *dev) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +int val; + +/* Set CPUDest */ + val =mv88e61xx_reg_read (dev, priv->global1,GLOBAL1_MON_CTRL ); +if (val <0 ) +return val; + val =bitfield_replace (val,GLOBAL1_MON_CTRL_CPUDEST_SHIFT , +GLOBAL1_MON_CTRL_CPUDEST_WIDTH , + dsa_pdata->cpu_port); + val =mv88e61xx_reg_write (dev, priv->global1,GLOBAL1_MON_CTRL , val); +if (val <0 ) +return val; + +/* Enable CPU port */ + val =mv88e61xx_port_enable (dev, dsa_pdata->cpu_port); +if (val <0 ) +return val;
drivers/net/mv88e61xx.c line 591
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+ +/* If CPU is connected to serdes, initialize serdes */ +if (mv88e61xx_6352_family (dev)) { + val =mv88e61xx_get_cmode (dev, dsa_pdata->cpu_port); +if (val <0 ) +return val; +if (val ==PORT_REG_STATUS_CMODE_100BASE_X || + val ==PORT_REG_STATUS_CMODE_1000BASE_X || + val ==PORT_REG_STATUS_CMODE_SGMII ) { + val =mv88e61xx_serdes_init (dev);
Allow me to suggest that the SERDES init function is improperly placed in a function called "set_cpu_port".
Don't you need to initialize the SERDES also if a front port uses the SERDES, not just the CPU port?
What happens if you initialize it unconditionally?
Quoted 9 lines
drivers/net/mv88e61xx.c new file +9
-0+if (val <0 ) +return val; + } + }else { + val =mv88e61xx_fixed_port_setup (dev, dsa_pdata->cpu_port); +if (val <0 ) +return val; + } +
drivers/net/mv88e61xx.c line 610
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+return 0 ; +} + +static int mv88e61xx_switch_init (struct udevice *dev) +{ +static int init; +int res; + +if (init) +return 0 ;
Odd, why the static int?
Quoted 65 lines
drivers/net/mv88e61xx.c new file +65
-0+ + res =mv88e61xx_switch_reset (dev); +if (res <0 ) +return res; + + res =mv88e61xx_set_cpu_port (dev); +if (res <0 ) +return res; + + init =1 ; + +return 0 ; +} + +static int mv88e61xx_phy_setup (struct udevice *dev,u8 phy) +{ +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +int val; + +/* +* Enable energy-detect sensing on PHY, used to determine when a PHY +* port is physically connected +*/ + val =mv88e61xx_phy_read (dev, phy,PHY_REG_CTRL1 ); +if (val <0 ) +return val; + val =bitfield_replace (val, priv->phy_ctrl1_en_det_shift, + priv->phy_ctrl1_en_det_width, + priv->phy_ctrl1_en_det_ctrl); + val =mv88e61xx_phy_write (dev, phy,PHY_REG_CTRL1 , val); +if (val <0 ) +return val; + +return 0 ; +} + +/* +* This function is used to pre-configure the required register +* offsets, so that the indirect register access to the PHY registers +* is possible. This is necessary to be able to read the PHY ID +* while driver probing or in get_phy_id(). The globalN register +* offsets must be initialized correctly for a detected switch, +* otherwise detection of the PHY ID won't work! +*/ +static int mv88e61xx_priv_reg_offs_pre_init (struct udevice *dev) +{ +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); + +/* +* Initial 'port_reg_base' value must be an offset of existing +* port register, then reading the ID should succeed. First, try +* to read via port registers with device address 0x10 (88E6096 +* and compatible switches). +*/ + priv->port_reg_base =0x10 ; + priv->id =mv88e61xx_get_switch_id (dev); +if (priv->id !=0xfff0 ) { + priv->global1 =0x1B ; + priv->global2 =0x1C ; +return 0 ; + } + +/* +* Now try via port registers with device address 0x08 +* (88E6020 and compatible switches).
drivers/net/mv88e61xx.c line 685
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+*/ + priv->port_reg_base =0x08 ; + priv->id =mv88e61xx_get_switch_id (dev); +if (priv->id !=0xfff0 ) { + priv->global1 =0x0F ; + priv->global2 =0x07 ; +return 0 ; + } + +debug ("%s Unknown ID 0x%x\n" , __func__, priv->id);
This is the kind of error that is worth more than a "debug" message, no?
Quoted 13 lines
drivers/net/mv88e61xx.c new file +13
-0+return -ENODEV ; +} + +static int mv88e61xx_dsa_setup_cpu_interface (struct udevice *dev) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +int port = dsa_pdata->cpu_port; +phy_interface_t phy_interface; +bool duplex, fixed; +ofnode node; +int speed; +int val; +
drivers/net/mv88e61xx.c line 746
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+ fixed =ofnode_phy_is_fixed_link (dsa_pdata->cpu_port_node, &node); +if (fixed &&ofnode_valid (node)) { + speed =ofnode_read_u32_default (node,"speed" ,0 ); + duplex =ofnode_read_bool (node,"full-duplex" ); + }else { + duplex = false; + speed =0 ; + } + phy_interface =phy_get_interface_by_name (ofnode_read_string (dsa_pdata->cpu_port_node, +"phy-mode" ));
Isn't this something all too overcomplicated for the driver when you can just wait until mv88e61xx_dsa_port_enable() is called on the CPU port, and it passes the fixed PHY as argument, with PHY mode and all?
Quoted 49 lines
drivers/net/mv88e61xx.c new file +49
-0+ +dev_dbg (dev,"%s configuring CPU port P%d for %s fixed=%d speed=%d duplex=%d\n" , + __func__, port,phy_string_for_interface (phy_interface), + fixed, speed, duplex); + +/* Physical Control register: Table 62 */ + val =mv88e61xx_port_read (dev, port,PORT_REG_PHYS_CTRL ); + val &= ~(PORT_REG_PHYS_CTRL_RGMII_DELAY_RXCLK || +PORT_REG_PHYS_CTRL_RGMII_DELAY_TXCLK ); +if (phy_interface ==PHY_INTERFACE_MODE_RGMII_ID || + phy_interface ==PHY_INTERFACE_MODE_RGMII_RXID ) + val |=PORT_REG_PHYS_CTRL_RGMII_DELAY_RXCLK ; +if (phy_interface ==PHY_INTERFACE_MODE_RGMII_ID || + phy_interface ==PHY_INTERFACE_MODE_RGMII_TXID ) + val |=PORT_REG_PHYS_CTRL_RGMII_DELAY_TXCLK ; +if (fixed) + val |=BIT (5 ) |BIT (4 );/* Force link */ +switch (speed) { +case SPEED_10 : +break ; +case SPEED_100 : + val |=0x1 ; +break ; +case SPEED_1000 : + val |=0x2 ; +break ; +default : + val |=0x3 ;/* detect link speed */ +break ; + } +if (duplex) + val |=BIT (3 ) |BIT (2 ); + +return mv88e61xx_port_write (dev, port,PORT_REG_PHYS_CTRL , val); +} + +static int mv88e61xx_dsa_port_enable (struct udevice *dev,int port,struct phy_device *phy) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +int ret; + +dev_dbg (dev,"%s P%d phy:0x%08x %s\n" , __func__, port, + phy->phy_id,phy_string_for_interface (phy->interface)); + + ret =mv88e61xx_phy_setup (dev, port); +if (ret <0 ) { +dev_err (dev,"Error setting up PHY %i\n" , port); +return ret;
drivers/net/mv88e61xx.c line 805
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+ } + ret =mv88e61xx_port_enable (dev, port); +if (ret <0 ) { +dev_err (dev,"Error enabling PHY %i\n" , port); +return ret; + } +if (port != dsa_pdata->cpu_port) + priv->active_port = port; +else +mv88e61xx_set_cpu_port (dev);
Why is there a need to call this twice, first in mv88e61xx_switch_init() then here?
Quoted 4 lines
drivers/net/mv88e61xx.c new file +4
-0+ +return 0 ; +} +
drivers/net/mv88e61xx.c line 819
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+static void mv88e61xx_dsa_port_disable (struct udevice *dev,int port,struct phy_device *phy) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +int val; + +dev_dbg (dev,"%s P%d phy:0x%x\n" , __func__, port, phy->phy_id); + +/* can't disable CPU port without re-configuring/re-starting switch */ +if (port == dsa_pdata->cpu_port) +return ;
Interesting, do you know more?
Quoted 12 lines
drivers/net/mv88e61xx.c new file +11
-0+ + val =mv88e61xx_port_read (dev, port,PORT_REG_CTRL ); +if (val <0 ) +return ; + val =bitfield_replace (val,PORT_REG_CTRL_PSTATE_SHIFT , +PORT_REG_CTRL_PSTATE_WIDTH , +PORT_REG_CTRL_PSTATE_DISABLED ); + val =mv88e61xx_port_write (dev, port,PORT_REG_CTRL , val); +if (val <0 ) +return ; +}
drivers/net/mv88e61xx.c line 862
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+/* bind and probe the switch mdios */ +static int mv88e61xx_dsa_probe_mdio (struct udevice *dev) +{ +struct udevice *pdev; +ofnode node, mdios; +const char *name; +int ret; + +/* bind phy ports of mdios child node to mv88e61xx_mdio device */ + mdios =dev_read_subnode (dev,"mdios" );
The Linux driver doesn't parse the "mdios" subnode, do you intend to do some work in that direction?
Quoted 37 lines
drivers/net/mv88e61xx.c new file +37
-0+if (ofnode_valid (mdios)) { +ofnode_for_each_subnode (node, mdios) { + name =ofnode_get_name (node); + ret =device_bind_driver_to_node (dev, +"mv88e61xx_mdio" , + name, node, &pdev); +if (ret) { +dev_err (dev,"failed to bind %s: %d\n" , name, ret); +continue ; + } + +/* need to probe it as there is no compatible to do so */ + ret =uclass_get_device_by_ofnode (UCLASS_MDIO , node, &pdev); +if (ret) { +dev_err (dev,"failed to probe %s: %d\n" , name, ret); +continue ; + } + } + } + +/* bind the mdios node to the parent mdio driver */ + name =ofnode_get_name (mdios); + ret =device_bind_driver_to_node (dev, +"mv88e61xx_mdio" , + name, mdios, &pdev); +if (ret) +dev_err (dev,"failed to bind %s: %d\n" , name, ret); + +/* need to probe it as there is no compatible to do so */ + ret =uclass_get_device_by_ofnode (UCLASS_MDIO , mdios, &pdev); +if (ret) +dev_err (dev,"failed to probe %s: %d\n" , name, ret); + +return ret; +} + +static int mv88e61xx_dsa_probe (struct udevice *dev)
drivers/net/mv88e61xx.c line 909
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+{ +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +struct udevice *master =dsa_get_master (dev); +int ret; + +if (!master) +return -ENODEV ; + +dev_dbg (dev,"%s master:%s\n" , __func__, master->name); +dev_set_parent_priv (dev, priv);
Copy-pasta from the ksz9477 driver?
Quoted 13 lines
drivers/net/mv88e61xx.c new file +13
-0+ +/* probe internal mdio bus */ + ret =mv88e61xx_dsa_probe_mdio (dev); +if (ret) +return ret; + + ret =mv88e61xx_priv_reg_offs_pre_init (dev); +if (ret) +return ret; + +dev_dbg (dev,"ID=0x%x PORT_BASE=0x%02x GLOBAL1=0x%02x GLOBAL2=0x%02x\n" , + priv->id, priv->port_reg_base, priv->global1, priv->global2); +switch (priv->id) {
drivers/net/mv88e61xx.c line 932
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+case PORT_SWITCH_ID_6096 : +case PORT_SWITCH_ID_6097 : +case PORT_SWITCH_ID_6172 : +case PORT_SWITCH_ID_6176 : +case PORT_SWITCH_ID_6240 : +case PORT_SWITCH_ID_6352 : + priv->port_count =11 ; +// priv->port_stat_link_mask = BIT(11); +// priv->port_stat_dup_mask = BIT(10); +// priv->port_stat_speed_width = 2;
No commented code.
Quoted 53 lines
drivers/net/mv88e61xx.c new file +50
-0+ priv->phy_ctrl1_en_det_shift =8 ; + priv->phy_ctrl1_en_det_width =2 ; + priv->phy_ctrl1_en_det_ctrl = +PHY_REG_CTRL1_ENERGY_DET_SENSE_XMIT ; +break ; +case PORT_SWITCH_ID_6020 : +case PORT_SWITCH_ID_6070 : +case PORT_SWITCH_ID_6071 : +case PORT_SWITCH_ID_6220 : +case PORT_SWITCH_ID_6250 : + priv->port_count =7 ; +// priv->port_stat_link_mask = BIT(12); +// priv->port_stat_dup_mask = BIT(9); +// priv->port_stat_speed_width = 1; + priv->phy_ctrl1_en_det_shift =14 ; + priv->phy_ctrl1_en_det_width =1 ; + priv->phy_ctrl1_en_det_ctrl = +PHY_REG_CTRL1_ENERGY_DET_SENSE_PULSE ; +break ; +default : +return -ENODEV ; + } + +/* configure CPU port interface mode */ + ret =mv88e61xx_dsa_setup_cpu_interface (dev); +if (ret <0 ) +return ret; + + ret =mv88e61xx_switch_init (dev); +if (ret <0 ) +return ret; + +dsa_set_tagging (dev,0 ,0 ); + +return 0 ; +} + +static const struct udevice_id mv88e61xx_ids[] = { + { .compatible ="marvell,mv88e6085" }, + { } +}; + +U_BOOT_DRIVER (mv88e61xx) = { + .name ="mv88e61xx" , + .id =UCLASS_DSA , + .of_match = mv88e61xx_ids, + .probe = mv88e61xx_dsa_probe, + .ops = &mv88e61xx_dsa_ops, + .priv_auto =sizeof (struct mv88e61xx_phy_priv ), +};Signature · 1 line
2.17.1
Re: [PATCH 5/6] net: add MV88E61xx DSA driver
Quoted 77 lines · Vladimir Oltean
Quoted 75 lines · Tim Harvey
Add a DSA driver for the MV88E61xx compatible GbE Ethernet switches.
Signed-off-by Tim Harvey <[email protected]>--- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/mv88e61xx.c | 982 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 990 insertions(+) create mode 100644 drivers/net/mv88e61xx.cdrivers/net/Kconfig +7
-0@@ -428,6 +428,13 @@ config LPC32XX_ETH depends on ARCH_LPC32XX default y +config MV88E61XX + bool "Marvell MV88E61xx GbE switch DSA driver" + depends on DM_DSA && DM_MDIO + help + This driver implements a DSA switch driver for the MV88E61xx family + of GbE switches using the MDIO interface + config MVGBE bool "Marvell Orion5x/Kirkwood network interface support" depends on ARCH_KIRKWOOD || ARCH_ORION5Xdrivers/net/Makefile +1
-0@@ -66,6 +66,7 @@ obj-$(CONFIG_MEDIATEK_ETH) += mtk_eth.o obj-$(CONFIG_MPC8XX_FEC) += mpc8xx_fec.o obj-$(CONFIG_MT7620_ETH) += mt7620-eth.o obj-$(CONFIG_MT7628_ETH) += mt7628-eth.o +obj-$(CONFIG_MV88E61XX) += mv88e61xx.o obj-$(CONFIG_MVGBE) += mvgbe.o obj-$(CONFIG_MVMDIO) += mvmdio.o obj-$(CONFIG_MVNETA) += mvneta.odrivers/net/mv88e61xx.c new file +29
-0@@ -0,0 +1,982 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2022 +* Gateworks Corporation <www.gateworks.com> +* Tim Harvey <[email protected]> +* +* (C) Copyright 2015 +* Elecsys Corporation <www.elecsyscorp.com> +* Kevin Smith <[email protected]> +* +* Original driver: +* (C) Copyright 2009 +* Marvell Semiconductor <www.marvell.com> +* Prafulla Wadaskar <[email protected]> +*/ + +/* +* DSA driver for mv88e61xx ethernet switches. +* +* This driver configures the mv88e61xx for basic use as a DSA switch. +* +* This driver was adapted from drivers/net/phy/mv88e61xx and tested +* on the mv88e6176 via an SGMII interface. +*/ + +#include <bitfield.h> +#include <common.h> +#include <miiphy.h> +#include <dm/device.h>
Quoted 9 lines
drivers/net/mv88e61xx.c line 37
Quoted 8 lines
drivers/net/mv88e61xx.c new file +8
-0+#include <dm/device_compat.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/of_extra.h> +#include <linux/delay.h> +#include <net/dsa.h> + +#define PORT_MASK (port_count) ((1 << (port_count)) - 1)
Vladimir,
Thanks for the review.
Quoted 2 lines
Not used.
will remove
Quoted 141 lines
Quoted 141 lines
drivers/net/mv88e61xx.c new file +141
-0+ +/* Device addresses */ +#define DEVADDR_PHY (p) (p) +#define DEVADDR_SERDES 0x0F + +/* SMI indirection registers for multichip addressing mode */ +#define SMI_CMD_REG 0x00 +#define SMI_DATA_REG 0x01 + +/* Global registers */ +#define GLOBAL1_STATUS 0x00 +#define GLOBAL1_CTRL 0x04 +#define GLOBAL1_MON_CTRL 0x1A + +/* Global 2 registers */ +#define GLOBAL2_REG_PHY_CMD 0x18 +#define GLOBAL2_REG_PHY_DATA 0x19 +#define GLOBAL2_REG_SCRATCH 0x1A + +/* Port registers */ +#define PORT_REG_STATUS 0x00 +#define PORT_REG_PHYS_CTRL 0x01 +#define PORT_REG_SWITCH_ID 0x03 +#define PORT_REG_CTRL 0x04 +#define PORT_REG_VLAN_MAP 0x06 +#define PORT_REG_VLAN_ID 0x07 +#define PORT_REG_LED_CTRL 0x16 + +/* Phy registers */ +#define PHY_REG_CTRL1 0x10 +#define PHY_REG_STATUS1 0x11 +#define PHY_REG_PAGE 0x16 + +/* Serdes registers */ +#define SERDES_REG_CTRL_1 0x10 + +/* Phy page numbers */ +#define PHY_PAGE_COPPER 0 +#define PHY_PAGE_SERDES 1 + +/* Register fields */ +#define GLOBAL1_CTRL_SWRESET BIT(15) + +#define GLOBAL1_MON_CTRL_CPUDEST_SHIFT 4 +#define GLOBAL1_MON_CTRL_CPUDEST_WIDTH 4 + +#define PORT_REG_STATUS_SPEED_SHIFT 8 +#define PORT_REG_STATUS_SPEED_10 0 +#define PORT_REG_STATUS_SPEED_100 1 +#define PORT_REG_STATUS_SPEED_1000 2 + +#define PORT_REG_STATUS_CMODE_MASK 0xF +#define PORT_REG_STATUS_CMODE_100BASE_X 0x8 +#define PORT_REG_STATUS_CMODE_1000BASE_X 0x9 +#define PORT_REG_STATUS_CMODE_SGMII 0xa + +#define PORT_REG_PHYS_CTRL_RGMII_DELAY_RXCLK BIT(15) +#define PORT_REG_PHYS_CTRL_RGMII_DELAY_TXCLK BIT(14) +#define PORT_REG_PHYS_CTRL_PCS_AN_EN BIT(10) +#define PORT_REG_PHYS_CTRL_PCS_AN_RST BIT(9) +#define PORT_REG_PHYS_CTRL_FC_VALUE BIT(7) +#define PORT_REG_PHYS_CTRL_FC_FORCE BIT(6) +#define PORT_REG_PHYS_CTRL_LINK_VALUE BIT(5) +#define PORT_REG_PHYS_CTRL_LINK_FORCE BIT(4) +#define PORT_REG_PHYS_CTRL_DUPLEX_VALUE BIT(3) +#define PORT_REG_PHYS_CTRL_DUPLEX_FORCE BIT(2) +#define PORT_REG_PHYS_CTRL_SPD1000 BIT(1) +#define PORT_REG_PHYS_CTRL_SPD100 BIT(0) +#define PORT_REG_PHYS_CTRL_SPD_MASK (BIT(1) | BIT(0)) + +#define PORT_REG_CTRL_PSTATE_SHIFT 0 +#define PORT_REG_CTRL_PSTATE_WIDTH 2 + +#define PORT_REG_VLAN_ID_DEF_VID_SHIFT 0 +#define PORT_REG_VLAN_ID_DEF_VID_WIDTH 12 + +#define PORT_REG_VLAN_MAP_TABLE_SHIFT 0 +#define PORT_REG_VLAN_MAP_TABLE_WIDTH 11 + +#define SERDES_REG_CTRL_1_FORCE_LINK BIT(10) + +/* Field values */ +#define PORT_REG_CTRL_PSTATE_DISABLED 0 +#define PORT_REG_CTRL_PSTATE_FORWARD 3 + +#define PHY_REG_CTRL1_ENERGY_DET_OFF 0 +#define PHY_REG_CTRL1_ENERGY_DET_SENSE_PULSE 1 +#define PHY_REG_CTRL1_ENERGY_DET_SENSE_ONLY 2 +#define PHY_REG_CTRL1_ENERGY_DET_SENSE_XMIT 3 + +/* PHY Status Register */ +#define PHY_REG_STATUS1_SPEED 0xc000 +#define PHY_REG_STATUS1_GBIT 0x8000 +#define PHY_REG_STATUS1_100 0x4000 +#define PHY_REG_STATUS1_DUPLEX 0x2000 +#define PHY_REG_STATUS1_SPDDONE 0x0800 +#define PHY_REG_STATUS1_LINK 0x0400 +#define PHY_REG_STATUS1_ENERGY 0x0010 + +/* +* Macros for building commands for indirect addressing modes. These are valid +* for both the indirect multichip addressing mode and the PHY indirection +* required for the writes to any PHY register. +*/ +#define SMI_BUSY BIT(15) +#define SMI_CMD_CLAUSE_22 BIT(12) +#define SMI_CMD_CLAUSE_22_OP_READ (2 << 10) +#define SMI_CMD_CLAUSE_22_OP_WRITE (1 << 10) + +#define SMI_CMD_READ (SMI_BUSY | SMI_CMD_CLAUSE_22 | \ + SMI_CMD_CLAUSE_22_OP_READ) +#define SMI_CMD_WRITE (SMI_BUSY | SMI_CMD_CLAUSE_22 | \ + SMI_CMD_CLAUSE_22_OP_WRITE) + +#define SMI_CMD_ADDR_SHIFT 5 +#define SMI_CMD_ADDR_WIDTH 5 +#define SMI_CMD_REG_SHIFT 0 +#define SMI_CMD_REG_WIDTH 5 + +/* Defines for Scratch and Misc Registers */ +#define SCRATCH_UPDATE BIT(15) +#define SCRATCH_ADDR_SHIFT 8 +#define SCRATCH_ADDR_WIDTH 7 + +/* Scratch registers */ +#define SCRATCH_ADDR_GPIO0DIR 0x62/* GPIO[7:0] direction 1=input */ +#define SCRATCH_ADDR_GPIO1DIR 0x63/* GPIO[14:8] direction 1=input */ +#define SCRATCH_ADDR_GPIO0DATA 0x64/* GPIO[7:0] data */ +#define SCRATCH_ADDR_GPIO1DATA 0x65/* GPIO[14:8] data */ +#define SCRATCH_ADDR_GPIO0CTRL 0x68/* GPIO[1:0] control */ +#define SCRATCH_ADDR_GPIO1CTRL 0x69/* GPIO[3:2] control */ + +/* ID register values for different switch models */ +#define PORT_SWITCH_ID_6020 0x0200 +#define PORT_SWITCH_ID_6070 0x0700 +#define PORT_SWITCH_ID_6071 0x0710 +#define PORT_SWITCH_ID_6096 0x0980 +#define PORT_SWITCH_ID_6097 0x0990 +#define PORT_SWITCH_ID_6172 0x1720 +#define PORT_SWITCH_ID_6176 0x1760 +#define PORT_SWITCH_ID_6220 0x2200
Quoted 8 lines
drivers/net/mv88e61xx.c line 183
Quoted 5 lines
drivers/net/mv88e61xx.c new file +5
-0+#define PORT_SWITCH_ID_6240 0x2400 +#define PORT_SWITCH_ID_6250 0x2500 +#define PORT_SWITCH_ID_6352 0x3520 + +struct mv88e61xx_phy_priv {Could we choose a better name than
mv88e61xx_phy_priv? It is not a PHY, it is a switch.
Good point... this was a hold-over from when I was trying to combine the old and new drivers. Will replace with simple 'mv88e61xx_priv'
Quoted 68 lines
Quoted 54 lines
drivers/net/mv88e61xx.c new file +53
-0+static int mv88e61xx_fixed_port_setup (struct udevice *dev,u8 port) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +int val; + + val =mv88e61xx_port_read (dev, port,PORT_REG_PHYS_CTRL ); +if (val <0 ) +return val; + + val &= ~(PORT_REG_PHYS_CTRL_SPD_MASK | +PORT_REG_PHYS_CTRL_FC_VALUE | +PORT_REG_PHYS_CTRL_FC_FORCE ); + val |=PORT_REG_PHYS_CTRL_FC_FORCE | +PORT_REG_PHYS_CTRL_DUPLEX_VALUE | +PORT_REG_PHYS_CTRL_DUPLEX_FORCE ; + +if (priv->id ==PORT_SWITCH_ID_6071 ) { + val |=PORT_REG_PHYS_CTRL_SPD100 ; + }else { + val |=PORT_REG_PHYS_CTRL_PCS_AN_EN | +PORT_REG_PHYS_CTRL_PCS_AN_RST | +PORT_REG_PHYS_CTRL_SPD1000 ; + } + +if (port == dsa_pdata->cpu_port) + val |=PORT_REG_PHYS_CTRL_LINK_VALUE | +PORT_REG_PHYS_CTRL_LINK_FORCE ; + +return mv88e61xx_port_write (dev, port,PORT_REG_PHYS_CTRL , val); +} + +static int mv88e61xx_set_cpu_port (struct udevice *dev) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +int val; + +/* Set CPUDest */ + val =mv88e61xx_reg_read (dev, priv->global1,GLOBAL1_MON_CTRL ); +if (val <0 ) +return val; + val =bitfield_replace (val,GLOBAL1_MON_CTRL_CPUDEST_SHIFT , +GLOBAL1_MON_CTRL_CPUDEST_WIDTH , + dsa_pdata->cpu_port); + val =mv88e61xx_reg_write (dev, priv->global1,GLOBAL1_MON_CTRL , val); +if (val <0 ) +return val; + +/* Enable CPU port */ + val =mv88e61xx_port_enable (dev, dsa_pdata->cpu_port); +if (val <0 ) +return val;drivers/net/mv88e61xx.c line 591
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+ +/* If CPU is connected to serdes, initialize serdes */ +if (mv88e61xx_6352_family (dev)) { + val =mv88e61xx_get_cmode (dev, dsa_pdata->cpu_port); +if (val <0 ) +return val; +if (val ==PORT_REG_STATUS_CMODE_100BASE_X || + val ==PORT_REG_STATUS_CMODE_1000BASE_X || + val ==PORT_REG_STATUS_CMODE_SGMII ) { + val =mv88e61xx_serdes_init (dev);Allow me to suggest that the SERDES init function is improperly placed in a function called "
set_cpu_port".
Quoted 4 lines
Don't you need to initialize the SERDES also if a front port uses the SERDES, not just the CPU port?
What happens if you initialize it unconditionally?
I will have to look into this further.
Quoted 14 lines
Quoted 14 lines
drivers/net/mv88e61xx.c new file +13
-0+if (val <0 ) +return val; + } + }else { + val =mv88e61xx_fixed_port_setup (dev, dsa_pdata->cpu_port); +if (val <0 ) +return val; + } + +return 0 ; +} + +static int mv88e61xx_switch_init (struct udevice *dev)
Quoted 9 lines
drivers/net/mv88e61xx.c line 610
Quoted 6 lines
drivers/net/mv88e61xx.c new file +6
-0+{ +static int init; +int res; + +if (init) +return 0 ;Odd, why the static int?
another hold-over from the original driver and not needed now - will remove
Quoted 69 lines
Quoted 69 lines
drivers/net/mv88e61xx.c new file +69
-0+ + res =mv88e61xx_switch_reset (dev); +if (res <0 ) +return res; + + res =mv88e61xx_set_cpu_port (dev); +if (res <0 ) +return res; + + init =1 ; + +return 0 ; +} + +static int mv88e61xx_phy_setup (struct udevice *dev,u8 phy) +{ +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +int val; + +/* +* Enable energy-detect sensing on PHY, used to determine when a PHY +* port is physically connected +*/ + val =mv88e61xx_phy_read (dev, phy,PHY_REG_CTRL1 ); +if (val <0 ) +return val; + val =bitfield_replace (val, priv->phy_ctrl1_en_det_shift, + priv->phy_ctrl1_en_det_width, + priv->phy_ctrl1_en_det_ctrl); + val =mv88e61xx_phy_write (dev, phy,PHY_REG_CTRL1 , val); +if (val <0 ) +return val; + +return 0 ; +} + +/* +* This function is used to pre-configure the required register +* offsets, so that the indirect register access to the PHY registers +* is possible. This is necessary to be able to read the PHY ID +* while driver probing or in get_phy_id(). The globalN register +* offsets must be initialized correctly for a detected switch, +* otherwise detection of the PHY ID won't work! +*/ +static int mv88e61xx_priv_reg_offs_pre_init (struct udevice *dev) +{ +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); + +/* +* Initial 'port_reg_base' value must be an offset of existing +* port register, then reading the ID should succeed. First, try +* to read via port registers with device address 0x10 (88E6096 +* and compatible switches). +*/ + priv->port_reg_base =0x10 ; + priv->id =mv88e61xx_get_switch_id (dev); +if (priv->id !=0xfff0 ) { + priv->global1 =0x1B ; + priv->global2 =0x1C ; +return 0 ; + } + +/* +* Now try via port registers with device address 0x08 +* (88E6020 and compatible switches). +*/ + priv->port_reg_base =0x08 ; + priv->id =mv88e61xx_get_switch_id (dev); +if (priv->id !=0xfff0 ) {
Quoted 8 lines
drivers/net/mv88e61xx.c line 685
Quoted 6 lines
drivers/net/mv88e61xx.c new file +6
-0+ priv->global1 =0x0F ; + priv->global2 =0x07 ; +return 0 ; + } + +debug ("%s Unknown ID 0x%x\n" , __func__, priv->id);This is the kind of error that is worth more than a "debug" message, no?
agreed - will change to dev_warn()
Quoted 20 lines
Quoted 20 lines
drivers/net/mv88e61xx.c new file +19
-0+return -ENODEV ; +} + +static int mv88e61xx_dsa_setup_cpu_interface (struct udevice *dev) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +int port = dsa_pdata->cpu_port; +phy_interface_t phy_interface; +bool duplex, fixed; +ofnode node; +int speed; +int val; + + fixed =ofnode_phy_is_fixed_link (dsa_pdata->cpu_port_node, &node); +if (fixed &&ofnode_valid (node)) { + speed =ofnode_read_u32_default (node,"speed" ,0 ); + duplex =ofnode_read_bool (node,"full-duplex" ); + }else { + duplex = false;
Quoted 8 lines
drivers/net/mv88e61xx.c line 746
Quoted 4 lines
drivers/net/mv88e61xx.c new file +4
-0+ speed =0 ; + } + phy_interface =phy_get_interface_by_name (ofnode_read_string (dsa_pdata->cpu_port_node, +"phy-mode" ));Isn't this something all too overcomplicated for the driver when you can just wait until
mv88e61xx_dsa_port_enable()is called on the CPU port, and it passes the fixed PHY as argument, with PHY mode and all?
Agreed, I should be able to do this later. I will look into that.
Quoted 55 lines
Quoted 55 lines
drivers/net/mv88e61xx.c new file +54
-0+ +dev_dbg (dev,"%s configuring CPU port P%d for %s fixed=%d speed=%d duplex=%d\n" , + __func__, port,phy_string_for_interface (phy_interface), + fixed, speed, duplex); + +/* Physical Control register: Table 62 */ + val =mv88e61xx_port_read (dev, port,PORT_REG_PHYS_CTRL ); + val &= ~(PORT_REG_PHYS_CTRL_RGMII_DELAY_RXCLK || +PORT_REG_PHYS_CTRL_RGMII_DELAY_TXCLK ); +if (phy_interface ==PHY_INTERFACE_MODE_RGMII_ID || + phy_interface ==PHY_INTERFACE_MODE_RGMII_RXID ) + val |=PORT_REG_PHYS_CTRL_RGMII_DELAY_RXCLK ; +if (phy_interface ==PHY_INTERFACE_MODE_RGMII_ID || + phy_interface ==PHY_INTERFACE_MODE_RGMII_TXID ) + val |=PORT_REG_PHYS_CTRL_RGMII_DELAY_TXCLK ; +if (fixed) + val |=BIT (5 ) |BIT (4 );/* Force link */ +switch (speed) { +case SPEED_10 : +break ; +case SPEED_100 : + val |=0x1 ; +break ; +case SPEED_1000 : + val |=0x2 ; +break ; +default : + val |=0x3 ;/* detect link speed */ +break ; + } +if (duplex) + val |=BIT (3 ) |BIT (2 ); + +return mv88e61xx_port_write (dev, port,PORT_REG_PHYS_CTRL , val); +} + +static int mv88e61xx_dsa_port_enable (struct udevice *dev,int port,struct phy_device *phy) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +int ret; + +dev_dbg (dev,"%s P%d phy:0x%08x %s\n" , __func__, port, + phy->phy_id,phy_string_for_interface (phy->interface)); + + ret =mv88e61xx_phy_setup (dev, port); +if (ret <0 ) { +dev_err (dev,"Error setting up PHY %i\n" , port); +return ret; + } + ret =mv88e61xx_port_enable (dev, port); +if (ret <0 ) { +dev_err (dev,"Error enabling PHY %i\n" , port); +return ret;
Quoted 8 lines
drivers/net/mv88e61xx.c line 805
Quoted 5 lines
drivers/net/mv88e61xx.c new file +5
-0+ } +if (port != dsa_pdata->cpu_port) + priv->active_port = port; +else +mv88e61xx_set_cpu_port (dev);Why is there a need to call this twice, first in
mv88e61xx_switch_init()then here?
I'll refactor the init
Quoted 17 lines
Quoted 5 lines
drivers/net/mv88e61xx.c new file +4
-0+ +return 0 ; +} +drivers/net/mv88e61xx.c line 819
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+static void mv88e61xx_dsa_port_disable (struct udevice *dev,int port,struct phy_device *phy) +{ +struct dsa_pdata *dsa_pdata =dev_get_uclass_plat (dev); +int val; + +dev_dbg (dev,"%s P%d phy:0x%x\n" , __func__, port, phy->phy_id); + +/* can't disable CPU port without re-configuring/re-starting switch */ +if (port == dsa_pdata->cpu_port) +return ;Interesting, do you know more?
this is likely a lie and some bad cut-and-paste from my ksz9447 driver. Will remove and test
Quoted 13 lines
Quoted 12 lines
drivers/net/mv88e61xx.c new file +11
-0+ + val =mv88e61xx_port_read (dev, port,PORT_REG_CTRL ); +if (val <0 ) +return ; + val =bitfield_replace (val,PORT_REG_CTRL_PSTATE_SHIFT , +PORT_REG_CTRL_PSTATE_WIDTH , +PORT_REG_CTRL_PSTATE_DISABLED ); + val =mv88e61xx_port_write (dev, port,PORT_REG_CTRL , val); +if (val <0 ) +return ; +}
Quoted 13 lines
drivers/net/mv88e61xx.c line 862
Quoted 10 lines
drivers/net/mv88e61xx.c new file +10
-0+/* bind and probe the switch mdios */ +static int mv88e61xx_dsa_probe_mdio (struct udevice *dev) +{ +struct udevice *pdev; +ofnode node, mdios; +const char *name; +int ret; + +/* bind phy ports of mdios child node to mv88e61xx_mdio device */ + mdios =dev_read_subnode (dev,"mdios" );The Linux driver doesn't parse the "mdios" subnode, do you intend to do some work in that direction?
We need to bind to all the subnodes or the ports won't probe right? I have no idea how Linux does it... as we've discussed long ago Linux doesn't require the additional dt bindings that U-Boot does (see my dt patch) so there is a lot different.
Quoted 42 lines
Quoted 42 lines
drivers/net/mv88e61xx.c new file +41
-0+if (ofnode_valid (mdios)) { +ofnode_for_each_subnode (node, mdios) { + name =ofnode_get_name (node); + ret =device_bind_driver_to_node (dev, +"mv88e61xx_mdio" , + name, node, &pdev); +if (ret) { +dev_err (dev,"failed to bind %s: %d\n" , name, ret); +continue ; + } + +/* need to probe it as there is no compatible to do so */ + ret =uclass_get_device_by_ofnode (UCLASS_MDIO , node, &pdev); +if (ret) { +dev_err (dev,"failed to probe %s: %d\n" , name, ret); +continue ; + } + } + } + +/* bind the mdios node to the parent mdio driver */ + name =ofnode_get_name (mdios); + ret =device_bind_driver_to_node (dev, +"mv88e61xx_mdio" , + name, mdios, &pdev); +if (ret) +dev_err (dev,"failed to bind %s: %d\n" , name, ret); + +/* need to probe it as there is no compatible to do so */ + ret =uclass_get_device_by_ofnode (UCLASS_MDIO , mdios, &pdev); +if (ret) +dev_err (dev,"failed to probe %s: %d\n" , name, ret); + +return ret; +} + +static int mv88e61xx_dsa_probe (struct udevice *dev) +{ +struct mv88e61xx_phy_priv *priv =dev_get_priv (dev); +struct udevice *master =dsa_get_master (dev); +int ret;
Quoted 8 lines
drivers/net/mv88e61xx.c line 909
Quoted 6 lines
drivers/net/mv88e61xx.c new file +6
-0+ +if (!master) +return -ENODEV ; + +dev_dbg (dev,"%s master:%s\n" , __func__, master->name); +dev_set_parent_priv (dev, priv);Copy-pasta from the ksz9477 driver?
will remove
Quoted 18 lines
Quoted 18 lines
drivers/net/mv88e61xx.c new file +17
-0+ +/* probe internal mdio bus */ + ret =mv88e61xx_dsa_probe_mdio (dev); +if (ret) +return ret; + + ret =mv88e61xx_priv_reg_offs_pre_init (dev); +if (ret) +return ret; + +dev_dbg (dev,"ID=0x%x PORT_BASE=0x%02x GLOBAL1=0x%02x GLOBAL2=0x%02x\n" , + priv->id, priv->port_reg_base, priv->global1, priv->global2); +switch (priv->id) { +case PORT_SWITCH_ID_6096 : +case PORT_SWITCH_ID_6097 : +case PORT_SWITCH_ID_6172 : +case PORT_SWITCH_ID_6176 :
Quoted 8 lines
drivers/net/mv88e61xx.c line 932
Quoted 6 lines
drivers/net/mv88e61xx.c new file +6
-0+case PORT_SWITCH_ID_6240 : +case PORT_SWITCH_ID_6352 : + priv->port_count =11 ; +// priv->port_stat_link_mask = BIT(11); +// priv->port_stat_dup_mask = BIT(10); +// priv->port_stat_speed_width = 2; No commented code.
yes, will remove
Thanks for the review. I'm not sure when I will be able to get back to this as I'm out of the office next week and have a lot of other tasks piled up.
Best Regards,
Tim
Quoted 54 lines
Quoted 54 lines
drivers/net/mv88e61xx.c new file +50
-1+ priv->phy_ctrl1_en_det_shift =8 ; + priv->phy_ctrl1_en_det_width =2 ; + priv->phy_ctrl1_en_det_ctrl = +PHY_REG_CTRL1_ENERGY_DET_SENSE_XMIT ; +break ; +case PORT_SWITCH_ID_6020 : +case PORT_SWITCH_ID_6070 : +case PORT_SWITCH_ID_6071 : +case PORT_SWITCH_ID_6220 : +case PORT_SWITCH_ID_6250 : + priv->port_count =7 ; +// priv->port_stat_link_mask = BIT(12); +// priv->port_stat_dup_mask = BIT(9); +// priv->port_stat_speed_width = 1; + priv->phy_ctrl1_en_det_shift =14 ; + priv->phy_ctrl1_en_det_width =1 ; + priv->phy_ctrl1_en_det_ctrl = +PHY_REG_CTRL1_ENERGY_DET_SENSE_PULSE ; +break ; +default : +return -ENODEV ; + } + +/* configure CPU port interface mode */ + ret =mv88e61xx_dsa_setup_cpu_interface (dev); +if (ret <0 ) +return ret; + + ret =mv88e61xx_switch_init (dev); +if (ret <0 ) +return ret; + +dsa_set_tagging (dev,0 ,0 ); + +return 0 ; +} + +static const struct udevice_id mv88e61xx_ids[] = { + { .compatible ="marvell,mv88e6085" }, + { } +}; + +U_BOOT_DRIVER (mv88e61xx) = { + .name ="mv88e61xx" , + .id =UCLASS_DSA , + .of_match = mv88e61xx_ids, + .probe = mv88e61xx_dsa_probe, + .ops = &mv88e61xx_dsa_ops, + .priv_auto =sizeof (struct mv88e61xx_phy_priv ), +}; --2.17.1
PATCH 6/6 board: gw_ventana: enable MV88E61XX DSA support
In reply to Tim HarveyAdd MV88E61XX DSA support:
- update dt: U-Boot dsa driver requires different device-tree syntax than the linux driver in order to link the dsa ports to the mdio bus.
- update defconfig
- replace mv88e61xx_hw_reset weak override with board_phy_config support for mv88e61xx configuration that is outside the scope of the DSA driver
--- arch/arm/dts/imx6qdl-gw5904.dtsi | 35 +++++++++++++++++ board/gateworks/gw_ventana/gw_ventana.c | 50 +++++++++---------------- configs/gwventana_gw5904_defconfig | 7 ++-- 3 files changed, 56 insertions(+), 36 deletions(-)
arch/arm/dts/imx6qdl-gw5904.dtsi +35 -0
@@ -219,6 +219,27 @@ compatible = "marvell,mv88e6085"; reg = <0>; + mdios { + #address-cells = <1>; + #size-cells = <0>; + + sw_phy0: ethernet-phy@0 { + reg = <0x0>; + }; + + sw_phy1: ethernet-phy@1 { + reg = <0x1>; + }; + + sw_phy2: ethernet-phy@2 { + reg = <0x2>; + }; + + sw_phy3: ethernet-phy@3 { + reg = <0x3>; + }; + }; + ports { #address-cells = <1>; #size-cells = <0>;
@@ -226,27 +247,41 @@ port@0 { reg = <0>; label = "lan4"; + phy-mode = "internal"; + phy-handle = <&sw_phy0>; }; port@1 { reg = <1>; label = "lan3"; + phy-mode = "internal"; + phy-handle = <&sw_phy1>; }; port@2 { reg = <2>; label = "lan2"; + phy-mode = "internal"; + phy-handle = <&sw_phy2>; }; port@3 { reg = <3>; label = "lan1"; + phy-mode = "internal"; + phy-handle = <&sw_phy3>; }; port@5 { reg = <5>; label = "cpu"; ethernet = <&fec>; + phy-mode = "rgmii-id"; + + fixed-link { + speed = <1000>; + full-duplex; + }; }; }; };
board/gateworks/gw_ventana/gw_ventana.c +18 -32
62 lines not on this page · raw message
configs/gwventana_gw5904_defconfig +3 -4
@@ -103,12 +103,11 @@ CONFIG_SUPPORT_EMMC_BOOT=y CONFIG_FSL_USDHC=y CONFIG_MTD=y CONFIG_PHYLIB=y -CONFIG_MV88E61XX_SWITCH=y -CONFIG_MV88E61XX_CPU_PORT=5 -CONFIG_MV88E61XX_PHY_PORTS=0xf -CONFIG_MV88E61XX_FIXED_PORTS=0x0 +CONFIG_MV88E61XX=y +CONFIG_PHY_FIXED=y CONFIG_DM_ETH=y CONFIG_DM_MDIO=y +CONFIG_DM_DSA=y CONFIG_E1000=y CONFIG_FEC_MXC=y CONFIG_MII=y
Signature · 1 line
2.17.1
Quoted 47 lines · Tim Harvey
This series adds a DSA driver for the MV88E61xx based on
drivers/net/phy/mv88e61xxand uses in on thegwventana_gw5904_defconfig.The hope is that the other three boards that use the MV88E61xx driver can move to this as well eventually so that we can remove the non-dm driver and the 4
Kconfigoptions it requires.The MV88E61xx has an MDIO interface this
DM_MDIOmust be used so support for aUCLASS_MDIOdriver is added to thefec_mxcethernet driver in a way that allows a fallback to the previous nonDM_MDIOcase as there are many boards out there using this driver that defineDM_MDIObut do not have the required dt props for aDM_MDIOdriver which would cause a regression.Additionally a patch to ensure MDIO children are scanned on post-bind is needed.
I'm making use of the dm_mdio_read/dm_mdio_write wrapper from Merak that is pending so it is in this series as well.
Best Regards,
Tim
Tim Harvey (6):
net: mdio-uclass: scan for dm mdio children on post-bind
net: dsa: move cpu port probe todsa_post_probe
net: mdio-uclass: add wrappers for read/write/reset operations
net: fec: add support forDM_MDIO
net: add MV88E61xx DSA driver
board:gw_ventana: enable MV88E61XX DSA supportarch/arm/dts/imx6qdl-gw5904.dtsi | 35 + board/gateworks/gw_ventana/gw_ventana.c | 50 +- configs/gwventana_gw5904_defconfig | 7 +- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/fec_mxc.c | 113 ++- drivers/net/fec_mxc.h | 1 + drivers/net/mv88e61xx.c | 982 ++++++++++++++++++++++++ include/miiphy.h | 31 + net/dsa-uclass.c | 14 +- net/mdio-uclass.c | 35 + 11 files changed, 1227 insertions(+), 49 deletions(-) create mode 100644 drivers/net/mv88e61xx.c
Quoted 3 lines
--
2.17.1
Adding Chris and Anotolij to the thread as the maintainers of the only other boards using drivers/net/phy/mv88e61xx.c. If they can switch to the DSA driver it would allow us to remove the static Kconfig options to configure the switch which should be present in the device-tree.
Best Regards,
Tim
Hi Tim,
Quoted 47 lines · Tim Harvey
Quoted 46 lines · Tim Harvey
This series adds a DSA driver for the MV88E61xx based on
drivers/net/phy/mv88e61xxand uses in on thegwventana_gw5904_defconfig.The hope is that the other three boards that use the MV88E61xx driver can move to this as well eventually so that we can remove the non-dm driver and the 4
Kconfigoptions it requires.The MV88E61xx has an MDIO interface this
DM_MDIOmust be used so support for aUCLASS_MDIOdriver is added to thefec_mxcethernet driver in a way that allows a fallback to the previous nonDM_MDIOcase as there are many boards out there using this driver that defineDM_MDIObut do not have the required dt props for aDM_MDIOdriver which would cause a regression.Additionally a patch to ensure MDIO children are scanned on post-bind is needed.
I'm making use of the dm_mdio_read/dm_mdio_write wrapper from Merak that is pending so it is in this series as well.
Best Regards,
Tim
Tim Harvey (6):
net: mdio-uclass: scan for dm mdio children on post-bind
net: dsa: move cpu port probe todsa_post_probe
net: mdio-uclass: add wrappers for read/write/reset operations
net: fec: add support forDM_MDIO
net: add MV88E61xx DSA driver
board:gw_ventana: enable MV88E61XX DSA supportarch/arm/dts/imx6qdl-gw5904.dtsi | 35 + board/gateworks/gw_ventana/gw_ventana.c | 50 +- configs/gwventana_gw5904_defconfig | 7 +- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/fec_mxc.c | 113 ++- drivers/net/fec_mxc.h | 1 + drivers/net/mv88e61xx.c | 982 ++++++++++++++++++++++++ include/miiphy.h | 31 + net/dsa-uclass.c | 14 +- net/mdio-uclass.c | 35 + 11 files changed, 1227 insertions(+), 49 deletions(-)create mode 100644
drivers/net/mv88e61xx.c
Quoted 7 lines
Quoted 3 lines
--
2.17.1Adding Chris and Anotolij to the thread as the maintainers of the only other boards using
drivers/net/phy/mv88e61xx.c. If they can switch to the DSA driver it would allow us to remove the staticKconfigoptions to configure the switch which should be present in the device-tree.
I'd be keen to see DSA support for this chip. We are using the Linux DSA drivers on these boards so I'm reasonably sure the ported driver should work. I won't have much time to actually work on these boards (they're a bit of a pain to test remotely). If any of the code is getting in the way I'd be fine with removing it (effectively leaving eth0 as a fixed-link) and when I get some time I can add support for the 88e6097 back.
Quoted 4 lines
Best Regards,
Tim