linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v1 1/4] net: usb: asix: unify ax88772_resume code
@ 2022-03-10 11:44 Oleksij Rempel
  2022-03-10 11:44 ` [PATCH net-next v1 2/4] net: usb: asix: store chipid to avoid reading it on reset Oleksij Rempel
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Oleksij Rempel @ 2022-03-10 11:44 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Andrew Lunn, Heiner Kallweit,
	Russell King
  Cc: Oleksij Rempel, kernel, linux-kernel, linux-usb, netdev, paskripkin

The only difference is the reset code, so remove not needed duplicates.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/usb/asix.h         |  1 +
 drivers/net/usb/asix_devices.c | 32 ++++++++------------------------
 2 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
index 4334aafab59a..b5ac693cebf2 100644
--- a/drivers/net/usb/asix.h
+++ b/drivers/net/usb/asix.h
@@ -177,6 +177,7 @@ struct asix_rx_fixup_info {
 struct asix_common_private {
 	void (*resume)(struct usbnet *dev);
 	void (*suspend)(struct usbnet *dev);
+	int (*reset)(struct usbnet *dev, int in_pm);
 	u16 presvd_phy_advertise;
 	u16 presvd_phy_bmcr;
 	struct asix_rx_fixup_info rx_fixup_info;
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 6ea44e53713a..bb09181596c5 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -625,27 +625,13 @@ static void ax88772_resume(struct usbnet *dev)
 	int i;
 
 	for (i = 0; i < 3; i++)
-		if (!ax88772_hw_reset(dev, 1))
+		if (!priv->reset(dev, 1))
 			break;
 
 	if (netif_running(dev->net))
 		phy_start(priv->phydev);
 }
 
-static void ax88772a_resume(struct usbnet *dev)
-{
-	struct asix_common_private *priv = dev->driver_priv;
-	int i;
-
-	for (i = 0; i < 3; i++) {
-		if (!ax88772a_hw_reset(dev, 1))
-			break;
-	}
-
-	if (netif_running(dev->net))
-		phy_start(priv->phydev);
-}
-
 static int asix_resume(struct usb_interface *intf)
 {
 	struct usbnet *dev = usb_get_intfdata(intf);
@@ -763,9 +749,14 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 
 	chipcode &= AX_CHIPCODE_MASK;
 
-	ret = (chipcode == AX_AX88772_CHIPCODE) ? ax88772_hw_reset(dev, 0) :
-						  ax88772a_hw_reset(dev, 0);
+	priv->resume = ax88772_resume;
+	priv->suspend = ax88772_suspend;
+	if (chipcode == AX_AX88772_CHIPCODE)
+		priv->reset = ax88772_hw_reset;
+	else
+		priv->reset = ax88772a_hw_reset;
 
+	ret = priv->reset(dev, 0);
 	if (ret < 0) {
 		netdev_dbg(dev->net, "Failed to reset AX88772: %d\n", ret);
 		return ret;
@@ -780,13 +771,6 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 
 	priv->presvd_phy_bmcr = 0;
 	priv->presvd_phy_advertise = 0;
-	if (chipcode == AX_AX88772_CHIPCODE) {
-		priv->resume = ax88772_resume;
-		priv->suspend = ax88772_suspend;
-	} else {
-		priv->resume = ax88772a_resume;
-		priv->suspend = ax88772_suspend;
-	}
 
 	ret = ax88772_init_mdio(dev);
 	if (ret)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v1 2/4] net: usb: asix: store chipid to avoid reading it on reset
  2022-03-10 11:44 [PATCH net-next v1 1/4] net: usb: asix: unify ax88772_resume code Oleksij Rempel
@ 2022-03-10 11:44 ` Oleksij Rempel
  2022-03-10 11:44 ` [PATCH net-next v1 3/4] net: usb: asix: make use of mdiobus_get_phy and phy_connect_direct Oleksij Rempel
  2022-03-10 11:44 ` [PATCH net-next v1 4/4] net: usb: asix: suspend internal PHY if external is used Oleksij Rempel
  2 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2022-03-10 11:44 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Andrew Lunn, Heiner Kallweit,
	Russell King
  Cc: Oleksij Rempel, kernel, linux-kernel, linux-usb, netdev, paskripkin

We already read chipid on probe. There is no need to read it on reset.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/usb/asix.h         |  1 +
 drivers/net/usb/asix_devices.c | 19 +++++++------------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
index b5ac693cebf2..691f37f45238 100644
--- a/drivers/net/usb/asix.h
+++ b/drivers/net/usb/asix.h
@@ -186,6 +186,7 @@ struct asix_common_private {
 	u16 phy_addr;
 	char phy_name[20];
 	bool embd_phy;
+	u8 chipcode;
 };
 
 extern const struct driver_info ax88172a_info;
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index bb09181596c5..34622c1adacf 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -450,7 +450,6 @@ static int ax88772a_hw_reset(struct usbnet *dev, int in_pm)
 	struct asix_data *data = (struct asix_data *)&dev->data;
 	struct asix_common_private *priv = dev->driver_priv;
 	u16 rx_ctl, phy14h, phy15h, phy16h;
-	u8 chipcode = 0;
 	int ret;
 
 	ret = asix_write_gpio(dev, AX_GPIO_RSE, 5, in_pm);
@@ -493,12 +492,7 @@ static int ax88772a_hw_reset(struct usbnet *dev, int in_pm)
 		goto out;
 	}
 
-	ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0,
-			    0, 1, &chipcode, in_pm);
-	if (ret < 0)
-		goto out;
-
-	if ((chipcode & AX_CHIPCODE_MASK) == AX_AX88772B_CHIPCODE) {
+	if (priv->chipcode == AX_AX88772B_CHIPCODE) {
 		ret = asix_write_cmd(dev, AX_QCTCTRL, 0x8000, 0x8001,
 				     0, NULL, in_pm);
 		if (ret < 0) {
@@ -506,7 +500,7 @@ static int ax88772a_hw_reset(struct usbnet *dev, int in_pm)
 				   ret);
 			goto out;
 		}
-	} else if ((chipcode & AX_CHIPCODE_MASK) == AX_AX88772A_CHIPCODE) {
+	} else if (priv->chipcode == AX_AX88772A_CHIPCODE) {
 		/* Check if the PHY registers have default settings */
 		phy14h = asix_mdio_read_nopm(dev->net, dev->mii.phy_id,
 					     AX88772A_PHY14H);
@@ -689,8 +683,8 @@ static int ax88772_init_phy(struct usbnet *dev)
 
 static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 {
-	u8 buf[ETH_ALEN] = {0}, chipcode = 0;
 	struct asix_common_private *priv;
+	u8 buf[ETH_ALEN] = {0};
 	int ret, i;
 
 	priv = devm_kzalloc(&dev->udev->dev, sizeof(*priv), GFP_KERNEL);
@@ -741,17 +735,18 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 	priv->phy_addr = ret;
 	priv->embd_phy = ((priv->phy_addr & 0x1f) == 0x10);
 
-	ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1, &chipcode, 0);
+	ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1,
+			    &priv->chipcode, 0);
 	if (ret < 0) {
 		netdev_dbg(dev->net, "Failed to read STATMNGSTS_REG: %d\n", ret);
 		return ret;
 	}
 
-	chipcode &= AX_CHIPCODE_MASK;
+	priv->chipcode &= AX_CHIPCODE_MASK;
 
 	priv->resume = ax88772_resume;
 	priv->suspend = ax88772_suspend;
-	if (chipcode == AX_AX88772_CHIPCODE)
+	if (priv->chipcode == AX_AX88772_CHIPCODE)
 		priv->reset = ax88772_hw_reset;
 	else
 		priv->reset = ax88772a_hw_reset;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v1 3/4] net: usb: asix: make use of mdiobus_get_phy and phy_connect_direct
  2022-03-10 11:44 [PATCH net-next v1 1/4] net: usb: asix: unify ax88772_resume code Oleksij Rempel
  2022-03-10 11:44 ` [PATCH net-next v1 2/4] net: usb: asix: store chipid to avoid reading it on reset Oleksij Rempel
@ 2022-03-10 11:44 ` Oleksij Rempel
  2022-03-10 11:44 ` [PATCH net-next v1 4/4] net: usb: asix: suspend internal PHY if external is used Oleksij Rempel
  2 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2022-03-10 11:44 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Andrew Lunn, Heiner Kallweit,
	Russell King
  Cc: Oleksij Rempel, kernel, linux-kernel, linux-usb, netdev, paskripkin

In most cases we use own mdio bus, there is no need to create and store
string for the PHY address.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/usb/asix.h         |  1 -
 drivers/net/usb/asix_devices.c | 19 ++++++++++---------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
index 691f37f45238..072760d76a72 100644
--- a/drivers/net/usb/asix.h
+++ b/drivers/net/usb/asix.h
@@ -184,7 +184,6 @@ struct asix_common_private {
 	struct mii_bus *mdio;
 	struct phy_device *phydev;
 	u16 phy_addr;
-	char phy_name[20];
 	bool embd_phy;
 	u8 chipcode;
 };
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 34622c1adacf..fb617eb551bb 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -661,15 +661,16 @@ static int ax88772_init_phy(struct usbnet *dev)
 	struct asix_common_private *priv = dev->driver_priv;
 	int ret;
 
-	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);
+	priv->phydev = mdiobus_get_phy(priv->mdio, priv->phy_addr);
+	if (!priv->phydev) {
+		netdev_err(dev->net, "Could not find PHY\n");
+		return -ENODEV;
+	}
+
+	ret = phy_connect_direct(dev->net, priv->phydev, &asix_adjust_link,
+				 PHY_INTERFACE_MODE_INTERNAL);
+	if (ret) {
+		netdev_err(dev->net, "Could not connect PHY\n");
 		return ret;
 	}
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v1 4/4] net: usb: asix: suspend internal PHY if external is used
  2022-03-10 11:44 [PATCH net-next v1 1/4] net: usb: asix: unify ax88772_resume code Oleksij Rempel
  2022-03-10 11:44 ` [PATCH net-next v1 2/4] net: usb: asix: store chipid to avoid reading it on reset Oleksij Rempel
  2022-03-10 11:44 ` [PATCH net-next v1 3/4] net: usb: asix: make use of mdiobus_get_phy and phy_connect_direct Oleksij Rempel
@ 2022-03-10 11:44 ` Oleksij Rempel
  2022-03-10 19:19   ` Andrew Lunn
  2022-03-10 20:43   ` Jakub Kicinski
  2 siblings, 2 replies; 6+ messages in thread
From: Oleksij Rempel @ 2022-03-10 11:44 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Andrew Lunn, Heiner Kallweit,
	Russell King
  Cc: Oleksij Rempel, kernel, linux-kernel, linux-usb, netdev, paskripkin

In case external PHY is used, we need to take care of internal PHY.
Since there are no methods to disable this PHY from the MAC side, we
need to suspend it.
This we reduce electrical noise (PHY is continuing to send FLPs) and power
consumption by 0,22W.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/usb/asix.h         |  3 +++
 drivers/net/usb/asix_devices.c | 16 +++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
index 072760d76a72..8a087205355d 100644
--- a/drivers/net/usb/asix.h
+++ b/drivers/net/usb/asix.h
@@ -158,6 +158,8 @@
 #define AX_EEPROM_MAGIC		0xdeadbeef
 #define AX_EEPROM_LEN		0x200
 
+#define AX_INTERNAL_PHY_ADDR	0x10
+
 /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
 struct asix_data {
 	u8 multi_filter[AX_MCAST_FILTER_SIZE];
@@ -183,6 +185,7 @@ struct asix_common_private {
 	struct asix_rx_fixup_info rx_fixup_info;
 	struct mii_bus *mdio;
 	struct phy_device *phydev;
+	struct phy_device *phydev_int;
 	u16 phy_addr;
 	bool embd_phy;
 	u8 chipcode;
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index fb617eb551bb..2c63fbe32ca2 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -679,6 +679,20 @@ static int ax88772_init_phy(struct usbnet *dev)
 
 	phy_attached_info(priv->phydev);
 
+	if (priv->embd_phy)
+		return 0;
+
+	/* In case main PHY is not the embedded PHY, we need to take care of
+	 * embedded PHY as well. */
+	priv->phydev_int = mdiobus_get_phy(priv->mdio, AX_INTERNAL_PHY_ADDR);
+	if (!priv->phydev_int) {
+		netdev_err(dev->net, "Could not find internal PHY\n");
+		return -ENODEV;
+	}
+
+	priv->phydev_int->mac_managed_pm = 1;
+	phy_suspend(priv->phydev_int);
+
 	return 0;
 }
 
@@ -734,7 +748,7 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 		return ret;
 
 	priv->phy_addr = ret;
-	priv->embd_phy = ((priv->phy_addr & 0x1f) == 0x10);
+	priv->embd_phy = ((priv->phy_addr & 0x1f) == AX_INTERNAL_PHY_ADDR);
 
 	ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1,
 			    &priv->chipcode, 0);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v1 4/4] net: usb: asix: suspend internal PHY if external is used
  2022-03-10 11:44 ` [PATCH net-next v1 4/4] net: usb: asix: suspend internal PHY if external is used Oleksij Rempel
@ 2022-03-10 19:19   ` Andrew Lunn
  2022-03-10 20:43   ` Jakub Kicinski
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2022-03-10 19:19 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: David S. Miller, Jakub Kicinski, Heiner Kallweit, Russell King,
	kernel, linux-kernel, linux-usb, netdev, paskripkin

On Thu, Mar 10, 2022 at 12:44:34PM +0100, Oleksij Rempel wrote:
> In case external PHY is used, we need to take care of internal PHY.
> Since there are no methods to disable this PHY from the MAC side, we
> need to suspend it.
> This we reduce electrical noise (PHY is continuing to send FLPs) and power
> consumption by 0,22W.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/usb/asix.h         |  3 +++
>  drivers/net/usb/asix_devices.c | 16 +++++++++++++++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
> index 072760d76a72..8a087205355d 100644
> --- a/drivers/net/usb/asix.h
> +++ b/drivers/net/usb/asix.h
> @@ -158,6 +158,8 @@
>  #define AX_EEPROM_MAGIC		0xdeadbeef
>  #define AX_EEPROM_LEN		0x200
>  
> +#define AX_INTERNAL_PHY_ADDR	0x10
> +
>  /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
>  struct asix_data {
>  	u8 multi_filter[AX_MCAST_FILTER_SIZE];
> @@ -183,6 +185,7 @@ struct asix_common_private {
>  	struct asix_rx_fixup_info rx_fixup_info;
>  	struct mii_bus *mdio;
>  	struct phy_device *phydev;
> +	struct phy_device *phydev_int;
>  	u16 phy_addr;
>  	bool embd_phy;
>  	u8 chipcode;
> diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
> index fb617eb551bb..2c63fbe32ca2 100644
> --- a/drivers/net/usb/asix_devices.c
> +++ b/drivers/net/usb/asix_devices.c
> @@ -679,6 +679,20 @@ static int ax88772_init_phy(struct usbnet *dev)
>  
>  	phy_attached_info(priv->phydev);
>  
> +	if (priv->embd_phy)
> +		return 0;

Minor nit pick: There appears to be some inconsistency with internal
and embedded. I think they are meant to mean the same thing? Maybe
replace internal with embedded in this patch?

The rest looks O.K.

    Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v1 4/4] net: usb: asix: suspend internal PHY if external is used
  2022-03-10 11:44 ` [PATCH net-next v1 4/4] net: usb: asix: suspend internal PHY if external is used Oleksij Rempel
  2022-03-10 19:19   ` Andrew Lunn
@ 2022-03-10 20:43   ` Jakub Kicinski
  1 sibling, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2022-03-10 20:43 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: David S. Miller, Andrew Lunn, Heiner Kallweit, Russell King,
	kernel, linux-kernel, linux-usb, netdev, paskripkin

On Thu, 10 Mar 2022 12:44:34 +0100 Oleksij Rempel wrote:
> +	/* In case main PHY is not the embedded PHY, we need to take care of
> +	 * embedded PHY as well. */

Another nit would be to move the */ to the next line like checkpatch
wants us to.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-10 20:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10 11:44 [PATCH net-next v1 1/4] net: usb: asix: unify ax88772_resume code Oleksij Rempel
2022-03-10 11:44 ` [PATCH net-next v1 2/4] net: usb: asix: store chipid to avoid reading it on reset Oleksij Rempel
2022-03-10 11:44 ` [PATCH net-next v1 3/4] net: usb: asix: make use of mdiobus_get_phy and phy_connect_direct Oleksij Rempel
2022-03-10 11:44 ` [PATCH net-next v1 4/4] net: usb: asix: suspend internal PHY if external is used Oleksij Rempel
2022-03-10 19:19   ` Andrew Lunn
2022-03-10 20:43   ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).