diff mbox series

[PATCHv3,2/3] usbnet: add method for reporting speed without MDIO

Message ID 20210218102038.2996-3-oneukum@suse.com
State New
Headers show
Series usbnet: speed reporting for devices without MDIO | expand

Commit Message

Oliver Neukum Feb. 18, 2021, 10:20 a.m. UTC
The old method for reporting network speed upwards
assumed that a device uses MDIO and uses the generic phy
functions based on that.
Add a a primitive internal version not making the assumption
reporting back directly what the status operations record.

v2: rebased on upstream
v3: changed names and made clear which units are used

Signed-off-by: Oliver Neukum <oneukum@suse.com>
Tested-by: Roland Dreier <roland@kernel.org>
---
 drivers/net/usb/usbnet.c   | 11 +++++++----
 include/linux/usb/usbnet.h |  6 ++++--
 2 files changed, 11 insertions(+), 6 deletions(-)

Comments

Jakub Kicinski Feb. 18, 2021, 7:06 p.m. UTC | #1
On Thu, 18 Feb 2021 11:20:37 +0100 Oliver Neukum wrote:
> The old method for reporting network speed upwards
> assumed that a device uses MDIO and uses the generic phy
> functions based on that.
> Add a a primitive internal version not making the assumption
> reporting back directly what the status operations record.
> 
> v2: rebased on upstream
> v3: changed names and made clear which units are used
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.com>
> Tested-by: Roland Dreier <roland@kernel.org>

ERROR: trailing whitespace
#48: FILE: drivers/net/usb/usbnet.c:1690:
+^Idev->tx_speed = SPEED_UNSET; $
diff mbox series

Patch

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index f3e5ad9befd0..368428a4290b 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -971,10 +971,10 @@  int usbnet_get_link_ksettings_internal(struct net_device *net,
 	 * For wireless stuff it is not true.
 	 * We assume that rxspeed matters more.
 	 */
-	if (dev->rxspeed != SPEED_UNKNOWN)
-		cmd->base.speed = dev->rxspeed / 1000000;
-	else if (dev->txspeed != SPEED_UNKNOWN)
-		cmd->base.speed = dev->txspeed / 1000000;
+	if (dev->rx_speed != SPEED_UNSET)
+		cmd->base.speed = dev->rx_speed / 1000000;
+	else if (dev->tx_speed != SPEED_UNSET)
+		cmd->base.speed = dev->tx_speed / 1000000;
 	else
 		cmd->base.speed = SPEED_UNKNOWN;
 
@@ -1685,6 +1685,9 @@  usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
 	dev->intf = udev;
 	dev->driver_info = info;
 	dev->driver_name = name;
+	/* cannot use 0, as simplex devices may exist */
+	dev->rx_speed = SPEED_UNSET; /* unknown or handled by MII */
+	dev->tx_speed = SPEED_UNSET; 
 
 	net->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
 	if (!net->tstats)
diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
index 132c1b5e14bb..7f445c1e0003 100644
--- a/include/linux/usb/usbnet.h
+++ b/include/linux/usb/usbnet.h
@@ -53,6 +53,10 @@  struct usbnet {
 	u32			hard_mtu;	/* count any extra framing */
 	size_t			rx_urb_size;	/* size for rx urbs */
 	struct mii_if_info	mii;
+	/* These are bits per second unlike what ethernet uses */
+	long			rx_speed;	/* if MII is not used */
+	long			tx_speed;	/* if MII is not used */
+#		define SPEED_UNSET	-1
 
 	/* various kinds of pending driver work */
 	struct sk_buff_head	rxq;
@@ -81,8 +85,6 @@  struct usbnet {
 #		define EVENT_LINK_CHANGE	11
 #		define EVENT_SET_RX_MODE	12
 #		define EVENT_NO_IP_ALIGN	13
-	u32			rx_speed;	/* in bps - NOT Mbps */
-	u32			tx_speed;	/* in bps - NOT Mbps */
 };
 
 static inline struct usb_driver *driver_of(struct usb_interface *intf)