2021-06-04 13:45:04

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v1 0/7] port asix ax88772 to the PHYlib

Port ax88772 part of asix driver to the phylib to be able to use more
advanced external PHY attached to this controller.

Oleksij Rempel (7):
net: usb: asix: ax88772_bind: use devm_kzalloc() instead of kzalloc()
net: usb: asix: ax88772: add phylib support
net: usb/phy: asix: add support for ax88772A/C PHYs
net: usb: asix: ax88772: add generic selftest support
net: usb: asix: add error handling for asix_mdio_* functions
net: phy: do not print dump stack if device was removed
usbnet: run unbind() before unregister_netdev()

drivers/net/phy/ax88796b.c | 74 ++++++++++++++++-
drivers/net/phy/phy.c | 3 +
drivers/net/usb/Kconfig | 2 +
drivers/net/usb/asix.h | 10 +++
drivers/net/usb/asix_common.c | 68 +++++++++++++--
drivers/net/usb/asix_devices.c | 148 +++++++++++++++++++++++----------
drivers/net/usb/ax88172a.c | 14 ----
drivers/net/usb/usbnet.c | 6 +-
8 files changed, 253 insertions(+), 72 deletions(-)

--
2.29.2


2021-06-04 13:45:25

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v1 1/7] net: usb: asix: ax88772_bind: use devm_kzalloc() instead of kzalloc()

Make resource management easier, use devm_kzalloc().

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/usb/asix_devices.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 19a8fafb8f04..5f767a33264e 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -746,11 +746,11 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
dev->rx_urb_size = 2048;
}

- dev->driver_priv = kzalloc(sizeof(struct asix_common_private), GFP_KERNEL);
- if (!dev->driver_priv)
+ priv = devm_kzalloc(&dev->udev->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
return -ENOMEM;

- priv = dev->driver_priv;
+ dev->driver_priv = priv;

priv->presvd_phy_bmcr = 0;
priv->presvd_phy_advertise = 0;
@@ -768,7 +768,6 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
{
asix_rx_fixup_common_free(dev->driver_priv);
- kfree(dev->driver_priv);
}

static const struct ethtool_ops ax88178_ethtool_ops = {
--
2.29.2

2021-06-04 13:45:54

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v1 4/7] net: usb: asix: ax88772: add generic selftest support

With working phylib support we are able now to use generic selftests.

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/usb/Kconfig | 1 +
drivers/net/usb/asix.h | 1 +
drivers/net/usb/asix_devices.c | 23 +++++++++++++++++++++++
3 files changed, 25 insertions(+)

diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 6f7be47974f6..4c5d69732a7e 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -165,6 +165,7 @@ config USB_NET_AX8817X
select CRC32
select PHYLIB
select AX88796B_PHY
+ imply NET_SELFTESTS
default y
help
This option adds support for ASIX AX88xxx based USB 2.0
diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
index 062e8147b1b3..c2897e9850d4 100644
--- a/drivers/net/usb/asix.h
+++ b/drivers/net/usb/asix.h
@@ -26,6 +26,7 @@
#include <linux/slab.h>
#include <linux/if_vlan.h>
#include <linux/phy.h>
+#include <net/selftests.h>

#define DRIVER_VERSION "22-Dec-2011"
#define DRIVER_NAME "asix"
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index fc41c3e28e80..02cc187632c5 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -280,6 +280,26 @@ static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
return ret;
}

+static void ax88772_ethtool_get_strings(struct net_device *netdev, u32 sset,
+ u8 *data)
+{
+ switch (sset) {
+ case ETH_SS_TEST:
+ net_selftest_get_strings(data);
+ break;
+ }
+}
+
+static int ax88772_ethtool_get_sset_count(struct net_device *ndev, int sset)
+{
+ switch (sset) {
+ case ETH_SS_TEST:
+ return net_selftest_get_count();
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
static const struct ethtool_ops ax88772_ethtool_ops = {
.get_drvinfo = asix_get_drvinfo,
.get_link = usbnet_get_link,
@@ -293,6 +313,9 @@ static const struct ethtool_ops ax88772_ethtool_ops = {
.nway_reset = phy_ethtool_nway_reset,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
+ .self_test = net_selftest,
+ .get_strings = ax88772_ethtool_get_strings,
+ .get_sset_count = ax88772_ethtool_get_sset_count,
};

static int ax88772_reset(struct usbnet *dev)
--
2.29.2

2021-06-04 13:46:31

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v1 7/7] usbnet: run unbind() before unregister_netdev()

unbind() is the proper place to disconnect PHY, but it will fail if
netdev is already unregistered.

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/usb/usbnet.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index ecf62849f4c1..57a5a025255c 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1597,6 +1597,9 @@ void usbnet_disconnect (struct usb_interface *intf)
xdev->bus->bus_name, xdev->devpath,
dev->driver_info->description);

+ if (dev->driver_info->unbind)
+ dev->driver_info->unbind(dev, intf);
+
net = dev->net;
unregister_netdev (net);

@@ -1604,9 +1607,6 @@ void usbnet_disconnect (struct usb_interface *intf)

usb_scuttle_anchored_urbs(&dev->deferred);

- if (dev->driver_info->unbind)
- dev->driver_info->unbind (dev, intf);
-
usb_kill_urb(dev->interrupt);
usb_free_urb(dev->interrupt);
kfree(dev->padding_pkt);
--
2.29.2

2021-06-04 13:48:15

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH net-next v1 2/7] net: usb: asix: ax88772: add phylib support

To be able to use ax88772 with external PHYs and use advantage of
existing PHY drivers, we need to port at least ax88772 part of asix
driver to the phylib framework.

Signed-off-by: Oleksij Rempel <[email protected]>
---
drivers/net/usb/asix.h | 9 +++
drivers/net/usb/asix_common.c | 34 ++++++++++
drivers/net/usb/asix_devices.c | 118 +++++++++++++++++++++------------
drivers/net/usb/ax88172a.c | 14 ----
4 files changed, 120 insertions(+), 55 deletions(-)

diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
index 3b53685301de..062e8147b1b3 100644
--- a/drivers/net/usb/asix.h
+++ b/drivers/net/usb/asix.h
@@ -25,6 +25,7 @@
#include <linux/usb/usbnet.h>
#include <linux/slab.h>
#include <linux/if_vlan.h>
+#include <linux/phy.h>

#define DRIVER_VERSION "22-Dec-2011"
#define DRIVER_NAME "asix"
@@ -178,6 +179,10 @@ struct asix_common_private {
u16 presvd_phy_advertise;
u16 presvd_phy_bmcr;
struct asix_rx_fixup_info rx_fixup_info;
+ struct mii_bus *mdio;
+ struct phy_device *phydev;
+ u16 phy_addr;
+ char phy_name[20];
};

extern const struct driver_info ax88172a_info;
@@ -215,6 +220,7 @@ int asix_write_rx_ctl(struct usbnet *dev, u16 mode, int in_pm);

u16 asix_read_medium_status(struct usbnet *dev, int in_pm);
int asix_write_medium_mode(struct usbnet *dev, u16 mode, int in_pm);
+void asix_adjust_link(struct net_device *netdev);

int asix_write_gpio(struct usbnet *dev, u16 value, int sleep, int in_pm);

@@ -223,6 +229,9 @@ void asix_set_multicast(struct net_device *net);
int asix_mdio_read(struct net_device *netdev, int phy_id, int loc);
void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val);

+int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum);
+int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val);
+
int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc);
void asix_mdio_write_nopm(struct net_device *netdev, int phy_id, int loc,
int val);
diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
index 7bc6e8f856fe..6b94c27576b7 100644
--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -383,6 +383,27 @@ int asix_write_medium_mode(struct usbnet *dev, u16 mode, int in_pm)
return ret;
}

+/* set MAC link settings according to information from phylib */
+void asix_adjust_link(struct net_device *netdev)
+{
+ struct phy_device *phydev = netdev->phydev;
+ struct usbnet *dev = netdev_priv(netdev);
+ u16 mode = 0;
+
+ if (phydev->link) {
+ mode = AX88772_MEDIUM_DEFAULT;
+
+ if (phydev->duplex == DUPLEX_HALF)
+ mode &= ~AX_MEDIUM_FD;
+
+ if (phydev->speed != SPEED_100)
+ mode &= ~AX_MEDIUM_PS;
+ }
+
+ asix_write_medium_mode(dev, mode, 0);
+ phy_print_status(phydev);
+}
+
int asix_write_gpio(struct usbnet *dev, u16 value, int sleep, int in_pm)
{
int ret;
@@ -505,6 +526,19 @@ void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
mutex_unlock(&dev->phy_mutex);
}

+/* MDIO read and write wrappers for phylib */
+int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum)
+{
+ return asix_mdio_read(((struct usbnet *)bus->priv)->net, phy_id,
+ regnum);
+}
+
+int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val)
+{
+ asix_mdio_write(((struct usbnet *)bus->priv)->net, phy_id, regnum, val);
+ return 0;
+}
+
int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc)
{
struct usbnet *dev = netdev_priv(netdev);
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 5f767a33264e..fc41c3e28e80 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -282,7 +282,7 @@ static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)

static const struct ethtool_ops ax88772_ethtool_ops = {
.get_drvinfo = asix_get_drvinfo,
- .get_link = asix_get_link,
+ .get_link = usbnet_get_link,
.get_msglevel = usbnet_get_msglevel,
.set_msglevel = usbnet_set_msglevel,
.get_wol = asix_get_wol,
@@ -290,37 +290,15 @@ static const struct ethtool_ops ax88772_ethtool_ops = {
.get_eeprom_len = asix_get_eeprom_len,
.get_eeprom = asix_get_eeprom,
.set_eeprom = asix_set_eeprom,
- .nway_reset = usbnet_nway_reset,
- .get_link_ksettings = usbnet_get_link_ksettings_mii,
- .set_link_ksettings = usbnet_set_link_ksettings_mii,
+ .nway_reset = phy_ethtool_nway_reset,
+ .get_link_ksettings = phy_ethtool_get_link_ksettings,
+ .set_link_ksettings = phy_ethtool_set_link_ksettings,
};

-static int ax88772_link_reset(struct usbnet *dev)
-{
- u16 mode;
- struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
-
- mii_check_media(&dev->mii, 1, 1);
- mii_ethtool_gset(&dev->mii, &ecmd);
- mode = AX88772_MEDIUM_DEFAULT;
-
- if (ethtool_cmd_speed(&ecmd) != SPEED_100)
- mode &= ~AX_MEDIUM_PS;
-
- if (ecmd.duplex != DUPLEX_FULL)
- mode &= ~AX_MEDIUM_FD;
-
- netdev_dbg(dev->net, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
- ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
-
- asix_write_medium_mode(dev, mode, 0);
-
- return 0;
-}
-
static int ax88772_reset(struct usbnet *dev)
{
struct asix_data *data = (struct asix_data *)&dev->data;
+ struct asix_common_private *priv = dev->driver_priv;
int ret;

/* Rewrite MAC address */
@@ -339,6 +317,8 @@ static int ax88772_reset(struct usbnet *dev)
if (ret < 0)
goto out;

+ phy_start(priv->phydev);
+
return 0;

out:
@@ -583,7 +563,7 @@ static const struct net_device_ops ax88772_netdev_ops = {
.ndo_get_stats64 = dev_get_tstats64,
.ndo_set_mac_address = asix_set_mac_address,
.ndo_validate_addr = eth_validate_addr,
- .ndo_do_ioctl = asix_ioctl,
+ .ndo_do_ioctl = phy_do_ioctl_running,
.ndo_set_rx_mode = asix_set_multicast,
};

@@ -674,12 +654,58 @@ static int asix_resume(struct usb_interface *intf)
return usbnet_resume(intf);
}

+static int ax88772_init_mdio(struct usbnet *dev)
+{
+ struct asix_common_private *priv = dev->driver_priv;
+
+ priv->mdio = devm_mdiobus_alloc(&dev->udev->dev);
+ if (!priv->mdio)
+ return -ENOMEM;
+
+ priv->mdio->priv = dev;
+ priv->mdio->read = &asix_mdio_bus_read;
+ priv->mdio->write = &asix_mdio_bus_write;
+ priv->mdio->name = "Asix MDIO Bus";
+ /* mii bus name is usb-<usb bus number>-<usb device number> */
+ snprintf(priv->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
+ dev->udev->bus->busnum, dev->udev->devnum);
+
+ return devm_mdiobus_register(&dev->udev->dev, priv->mdio);
+}
+
+static int ax88772_init_phy(struct usbnet *dev)
+{
+ struct asix_common_private *priv = dev->driver_priv;
+ int ret;
+
+ priv->phy_addr = asix_get_phy_addr(dev);
+ /* asix_read_phy_addr() is using ret < 2 as error value */
+ if (priv->phy_addr < 2)
+ return -ENODEV;
+
+ snprintf(priv->phy_name, sizeof(priv->phy_name), PHY_ID_FMT,
+ priv->mdio->id, priv->phy_addr);
+
+ priv->phydev = phy_connect(dev->net, priv->phy_name, &asix_adjust_link,
+ PHY_INTERFACE_MODE_INTERNAL);
+ if (IS_ERR(priv->phydev)) {
+ netdev_err(dev->net, "Could not connect to PHY device %s\n",
+ priv->phy_name);
+ ret = PTR_ERR(priv->phydev);
+ return ret;
+ }
+
+ phy_attached_info(priv->phydev);
+
+ return 0;
+}
+
static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
{
- int ret, i;
u8 buf[ETH_ALEN] = {0}, chipcode = 0;
- u32 phyid;
struct asix_common_private *priv;
+ int ret, i;
+ u32 phyid;

usbnet_get_endpoints(dev, intf);

@@ -711,14 +737,6 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)

asix_set_netdev_dev_addr(dev, buf);

- /* Initialize MII structure */
- dev->mii.dev = dev->net;
- dev->mii.mdio_read = asix_mdio_read;
- dev->mii.mdio_write = asix_mdio_write;
- dev->mii.phy_id_mask = 0x1f;
- dev->mii.reg_num_mask = 0x1f;
- dev->mii.phy_id = asix_get_phy_addr(dev);
-
dev->net->netdev_ops = &ax88772_netdev_ops;
dev->net->ethtool_ops = &ax88772_ethtool_ops;
dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
@@ -762,11 +780,31 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
priv->suspend = ax88772_suspend;
}

+ ret = ax88772_init_mdio(dev);
+ if (ret)
+ return ret;
+
+ return ax88772_init_phy(dev);
+}
+
+static int ax88772_stop(struct usbnet *dev)
+{
+ struct asix_common_private *priv = dev->driver_priv;
+
+ /* On unplugged USB, we will get MDIO communication errors and the
+ * PHY will be set in to PHY_HALTED state.
+ */
+ if (priv->phydev->state != PHY_HALTED)
+ phy_stop(priv->phydev);
+
return 0;
}

static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
{
+ struct asix_common_private *priv = dev->driver_priv;
+
+ phy_disconnect(priv->phydev);
asix_rx_fixup_common_free(dev->driver_priv);
}

@@ -1152,8 +1190,8 @@ static const struct driver_info ax88772_info = {
.bind = ax88772_bind,
.unbind = ax88772_unbind,
.status = asix_status,
- .link_reset = ax88772_link_reset,
.reset = ax88772_reset,
+ .stop = ax88772_stop,
.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET,
.rx_fixup = asix_rx_fixup_common,
.tx_fixup = asix_tx_fixup,
@@ -1164,7 +1202,6 @@ static const struct driver_info ax88772b_info = {
.bind = ax88772_bind,
.unbind = ax88772_unbind,
.status = asix_status,
- .link_reset = ax88772_link_reset,
.reset = ax88772_reset,
.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
FLAG_MULTI_PACKET,
@@ -1200,7 +1237,6 @@ static const struct driver_info hg20f9_info = {
.bind = ax88772_bind,
.unbind = ax88772_unbind,
.status = asix_status,
- .link_reset = ax88772_link_reset,
.reset = ax88772_reset,
.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
FLAG_MULTI_PACKET,
diff --git a/drivers/net/usb/ax88172a.c b/drivers/net/usb/ax88172a.c
index b404c9462dce..c168d36988f9 100644
--- a/drivers/net/usb/ax88172a.c
+++ b/drivers/net/usb/ax88172a.c
@@ -25,20 +25,6 @@ struct ax88172a_private {
struct asix_rx_fixup_info rx_fixup_info;
};

-/* MDIO read and write wrappers for phylib */
-static int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum)
-{
- return asix_mdio_read(((struct usbnet *)bus->priv)->net, phy_id,
- regnum);
-}
-
-static int asix_mdio_bus_write(struct mii_bus *bus, int phy_id, int regnum,
- u16 val)
-{
- asix_mdio_write(((struct usbnet *)bus->priv)->net, phy_id, regnum, val);
- return 0;
-}
-
/* set MAC link settings according to information from phylib */
static void ax88172a_adjust_link(struct net_device *netdev)
{
--
2.29.2

2021-06-04 23:08:00

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next v1 1/7] net: usb: asix: ax88772_bind: use devm_kzalloc() instead of kzalloc()

On Fri, Jun 04, 2021 at 03:42:38PM +0200, Oleksij Rempel wrote:
> Make resource management easier, use devm_kzalloc().
>
> Signed-off-by: Oleksij Rempel <[email protected]>

Reviewed-by: Andrew Lunn <[email protected]>

Andrew

2021-06-04 23:22:05

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next v1 2/7] net: usb: asix: ax88772: add phylib support

On Fri, Jun 04, 2021 at 03:42:39PM +0200, Oleksij Rempel wrote:
> To be able to use ax88772 with external PHYs and use advantage of

s/use/take/

> +/* MDIO read and write wrappers for phylib */
> +int asix_mdio_bus_read(struct mii_bus *bus, int phy_id, int regnum)
> +{
> + return asix_mdio_read(((struct usbnet *)bus->priv)->net, phy_id,
> + regnum);
> +}

Please avoid this cast. priv should be a void *, so you can do

struct usbnet *priv = bus->priv;

return asix_mdio_read(priv->net, phy_id, regnum);

> +static int ax88772_init_phy(struct usbnet *dev)
> +{
> + struct asix_common_private *priv = dev->driver_priv;
> + int ret;
> +
> + priv->phy_addr = asix_get_phy_addr(dev);
> + /* asix_read_phy_addr() is using ret < 2 as error value */
> + if (priv->phy_addr < 2)
> + return -ENODEV;

Really?

ax88172a.c does not check. ax88172_bind() does not
check. ax88772_bind() does not check. As far as i can see, nothing
really cares.

So please add another cleanup patch and make asix_read_phy_addr()
return -ENODEV.

Otherwise, this looks O.K.

2021-06-04 23:26:28

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next v1 4/7] net: usb: asix: ax88772: add generic selftest support

On Fri, Jun 04, 2021 at 03:42:41PM +0200, Oleksij Rempel wrote:
> With working phylib support we are able now to use generic selftests.
>
> Signed-off-by: Oleksij Rempel <[email protected]>

Reviewed-by: Andrew Lunn <[email protected]>

Andrew

2021-06-04 23:42:49

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next v1 7/7] usbnet: run unbind() before unregister_netdev()

On Fri, Jun 04, 2021 at 03:42:44PM +0200, Oleksij Rempel wrote:
> unbind() is the proper place to disconnect PHY, but it will fail if
> netdev is already unregistered.

O.K, this partially answers the question i was about to ask for the
previous patch.

void phy_start(struct phy_device *phydev)
{
mutex_lock(&phydev->lock);

if (phydev->state != PHY_READY && phydev->state != PHY_HALTED) {
WARN(1, "called from state %s\n",
phy_state_to_str(phydev->state));
goto out;
}

By skipping phy_error(), phydev->state is not set to PHY_HALTED. So if
you try to start the phy again, without disconnecting it, it looks
like there could be a problem.

But with this patch, i assume the PHY will always be disconnected and
later reconnected when the device is replugged.

Andrew

2021-06-07 08:05:32

by Oleksij Rempel

[permalink] [raw]
Subject: Re: [PATCH net-next v1 7/7] usbnet: run unbind() before unregister_netdev()

On Sat, Jun 05, 2021 at 01:41:15AM +0200, Andrew Lunn wrote:
> On Fri, Jun 04, 2021 at 03:42:44PM +0200, Oleksij Rempel wrote:
> > unbind() is the proper place to disconnect PHY, but it will fail if
> > netdev is already unregistered.
>
> O.K, this partially answers the question i was about to ask for the
> previous patch.
>
> void phy_start(struct phy_device *phydev)
> {
> mutex_lock(&phydev->lock);
>
> if (phydev->state != PHY_READY && phydev->state != PHY_HALTED) {
> WARN(1, "called from state %s\n",
> phy_state_to_str(phydev->state));
> goto out;
> }
>
> By skipping phy_error(), phydev->state is not set to PHY_HALTED. So if
> you try to start the phy again, without disconnecting it, it looks
> like there could be a problem.
>
> But with this patch, i assume the PHY will always be disconnected and
> later reconnected when the device is replugged.

Yes. The PHY is disconnected and the PHY driver is unbinded.

Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |