Skip to contentSkip to conversation

net: usb: move exported code to usbnet

PATCH Superseded Oliver Neukum 4 participants 14 messages Jul 2 – Jul 9

Subsystems (6)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Oliver Neukum

author maintainer
#0 lore raw

cover net: usb: move exported code to usbnet

Some drivers are reusing common code originating in other drivers. This means that two drivers need to be loaded for one device. Also maintainability is reduced if changes in one driver affect another driver.
Shift common code to usbnet.

author maintainer
#8 lore raw

PATCH 3/4 net: usb: usbnet: add cdc_state to struct usbnet

This allows centralisation of code using cdc_state in usbnet, reducing code duplication. No functional change intended.

---
 include/linux/usb/usbnet.h | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
include/linux/usb/usbnet.h +9 -7
index bbf799ccf3b3..79f48eb388ee 100644
@@ -16,6 +16,14 @@
 #include <linux/usb.h>
 #include <linux/spinlock.h>
 
+struct cdc_state {
+	struct usb_cdc_header_desc      *header;
+	struct usb_cdc_union_desc       *u;
+	struct usb_cdc_ether_desc       *ether;
+	struct usb_interface            *control;
+	struct usb_interface            *data;
+};
+
 /* interface from usbnet core to each USB networking link we handle */
 struct usbnet {
 	/* housekeeping */
@@ -41,6 +49,7 @@ struct usbnet {
 	/* protocol/interface state */
 	struct net_device	*net;
 	int			msg_enable;
+	struct cdc_state	cdc;		/* too common to leave out*/
 	unsigned long		data[5];
 	u32			xid;
 	u32			hard_mtu;	/* count any extra framing */
@@ -211,13 +220,6 @@ extern int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype,
  * (notably, using multiple interfaces according to the CDC
  * union descriptor) get some helper code.
  */
-struct cdc_state {
-	struct usb_cdc_header_desc	*header;
-	struct usb_cdc_union_desc	*u;
-	struct usb_cdc_ether_desc	*ether;
-	struct usb_interface		*control;
-	struct usb_interface		*data;
-};
 
 extern void usbnet_cdc_update_filter(struct usbnet *dev);
 extern int usbnet_generic_cdc_bind(struct usbnet *, struct usb_interface *);
Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH 1/4 net: usb: move updating filter and status from cdc to usbnet

In reply to Oliver Neukum

These helpers are used by multiple drivers and do not depend on the rest of cdc. Leavin them in a cdc driver means that more drivers are loaded just for infrastructure, not hardware support.

---
 drivers/net/usb/cdc_ether.c | 75 ------------------------------------
 drivers/net/usb/usbnet.c    | 76 +++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 75 deletions(-)
drivers/net/usb/cdc_ether.c +0 -75
index a0a5740590b9..b4df32e18461 100644
@@ -63,35 +63,6 @@ static const u8 mbm_guid[16] = {
 	0xa6, 0x07, 0xc0, 0xff, 0xcb, 0x7e, 0x39, 0x2a,
 };
 
-void usbnet_cdc_update_filter(struct usbnet *dev)
-{
-	struct net_device	*net = dev->net;
-
-	u16 cdc_filter = USB_CDC_PACKET_TYPE_DIRECTED
-			| USB_CDC_PACKET_TYPE_BROADCAST;
-
-	/* filtering on the device is an optional feature and not worth
-	 * the hassle so we just roughly care about snooping and if any
-	 * multicast is requested, we take every multicast
-	 */
-	if (net->flags & IFF_PROMISC)
-		cdc_filter |= USB_CDC_PACKET_TYPE_PROMISCUOUS;
-	if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI))
-		cdc_filter |= USB_CDC_PACKET_TYPE_ALL_MULTICAST;
-
-	usb_control_msg(dev->udev,
-			usb_sndctrlpipe(dev->udev, 0),
-			USB_CDC_SET_ETHERNET_PACKET_FILTER,
-			USB_TYPE_CLASS | USB_RECIP_INTERFACE,
-			cdc_filter,
-			dev->intf->cur_altsetting->desc.bInterfaceNumber,
-			NULL,
-			0,
-			USB_CTRL_SET_TIMEOUT
-		);
-}
-EXPORT_SYMBOL_GPL(usbnet_cdc_update_filter);
-
 /* We need to override usbnet_*_link_ksettings in bind() */
 static const struct ethtool_ops cdc_ether_ethtool_ops = {
 	.get_link		= usbnet_get_link,
@@ -400,52 +371,6 @@ EXPORT_SYMBOL_GPL(usbnet_cdc_unbind);
  * (by Brad Hards) talked with, with more functionality.
  */
 
-static void speed_change(struct usbnet *dev, __le32 *speeds)
-{
-	dev->tx_speed = __le32_to_cpu(speeds[0]);
-	dev->rx_speed = __le32_to_cpu(speeds[1]);
-}
-
-void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
-{
-	struct usb_cdc_notification	*event;
-
-	if (urb->actual_length < sizeof(*event))
-		return;
-
-	/* SPEED_CHANGE can get split into two 8-byte packets */
-	if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) {
-		speed_change(dev, (__le32 *) urb->transfer_buffer);
-		return;
-	}
-
-	event = urb->transfer_buffer;
-	switch (event->bNotificationType) {
-	case USB_CDC_NOTIFY_NETWORK_CONNECTION:
-		netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
-			  event->wValue ? "on" : "off");
-		if (netif_carrier_ok(dev->net) != !!event->wValue)
-			usbnet_link_change(dev, !!event->wValue, 0);
-		break;
-	case USB_CDC_NOTIFY_SPEED_CHANGE:	/* tx/rx rates */
-		netif_dbg(dev, timer, dev->net, "CDC: speed change (len %d)\n",
-			  urb->actual_length);
-		if (urb->actual_length != (sizeof(*event) + 8))
-			set_bit(EVENT_STS_SPLIT, &dev->flags);
-		else
-			speed_change(dev, (__le32 *) &event[1]);
-		break;
-	/* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS),
-	 * but there are no standard formats for the response data.
-	 */
-	default:
-		netdev_err(dev->net, "CDC: unexpected notification %02x!\n",
-			   event->bNotificationType);
-		break;
-	}
-}
-EXPORT_SYMBOL_GPL(usbnet_cdc_status);
-
 int usbnet_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
 {
 	int				status;
drivers/net/usb/usbnet.c +76 -0

88 lines not on this page · raw message

Signature · 1 line
2.54.0
author maintainer
#4 lore raw

PATCH 2/4 net: usb: centralize usbnet_cdc_zte_rx_fixup in usbnet

In reply to Oliver Neukum

This helper is used by multiple drivers using usbnet. It is better to be provided by usbnet than one of them.

---
 drivers/net/usb/cdc_ether.c | 19 -------------------
 drivers/net/usb/usbnet.c    | 19 +++++++++++++++++++
 2 files changed, 19 insertions(+), 19 deletions(-)
drivers/net/usb/cdc_ether.c +0 -19
index b4df32e18461..e688fb99c61d 100644
@@ -404,25 +404,6 @@ static int usbnet_cdc_zte_bind(struct usbnet *dev, struct usb_interface *intf)
 	return status;
 }
 
-/* Make sure packets have correct destination MAC address
- *
- * A firmware bug observed on some devices (ZTE MF823/831/910) is that the
- * device sends packets with a static, bogus, random MAC address (event if
- * device MAC address has been updated). Always set MAC address to that of the
- * device.
- */
-int usbnet_cdc_zte_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
-{
-	if (skb->len < ETH_HLEN || !(skb->data[0] & 0x02))
-		return 1;
-
-	skb_reset_mac_header(skb);
-	ether_addr_copy(eth_hdr(skb)->h_dest, dev->net->dev_addr);
-
-	return 1;
-}
-EXPORT_SYMBOL_GPL(usbnet_cdc_zte_rx_fixup);
-
 /* Ensure correct link state
  *
  * Some devices (ZTE MF823/831/910) export two carrier on notifications when
drivers/net/usb/usbnet.c +19 -0
index 5544af1f4aa5..7beea6d0e731 100644
@@ -2347,6 +2347,25 @@ void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
 	}
 }
 EXPORT_SYMBOL_GPL(usbnet_cdc_status);
+
+/* Make sure packets have correct destination MAC address
+ *
+ * A firmware bug observed on some devices (ZTE MF823/831/910) is that the
+ * device sends packets with a static, bogus, random MAC address (event if
+ * device MAC address has been updated). Always set MAC address to that of the
+ * device.
+ */
+int usbnet_cdc_zte_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
+{
+	if (skb->len < ETH_HLEN || !(skb->data[0] & 0x02))
+		return 1;
+
+	skb_reset_mac_header(skb);
+	ether_addr_copy(eth_hdr(skb)->h_dest, dev->net->dev_addr);
+
+	return 1;
+}
+EXPORT_SYMBOL_GPL(usbnet_cdc_zte_rx_fixup);
 /*-------------------------------------------------------------------------*/
 
 static int __init usbnet_init(void)
Signature · 1 line
2.54.0
author maintainer
#9 lore raw

PATCH 4/4 net: usb: use cdc_state in struct usbnet

In reply to Oliver Neukum

Remove private copies as now a central state can be used.

---
 drivers/net/usb/cdc_ether.c  | 9 +++------
 drivers/net/usb/rndis_host.c | 6 +++---
 2 files changed, 6 insertions(+), 9 deletions(-)
drivers/net/usb/cdc_ether.c +3 -6
index e688fb99c61d..76ad4ffa950a 100644
@@ -85,7 +85,7 @@ int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
 	u8				*buf = intf->cur_altsetting->extra;
 	int				len = intf->cur_altsetting->extralen;
 	struct usb_interface_descriptor	*d;
-	struct cdc_state		*info = (void *) &dev->data;
+	struct cdc_state		*info = &dev->cdc;
 	int				status = -ENODEV;
 	int				rndis;
 	bool				android_rndis_quirk = false;
@@ -336,7 +336,7 @@ EXPORT_SYMBOL_GPL(usbnet_ether_cdc_bind);
 
 void usbnet_cdc_unbind(struct usbnet *dev, struct usb_interface *intf)
 {
-	struct cdc_state		*info = (void *) &dev->data;
+	struct cdc_state		*info = &dev->cdc;
 	struct usb_driver		*driver = driver_of(intf);
 
 	/* combined interface - nothing  to do */
@@ -374,10 +374,7 @@ EXPORT_SYMBOL_GPL(usbnet_cdc_unbind);
 int usbnet_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
 {
 	int				status;
-	struct cdc_state		*info = (void *) &dev->data;
-
-	BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data)
-			< sizeof(struct cdc_state)));
+	struct cdc_state		*info = &dev->cdc;
 
 	status = usbnet_ether_cdc_bind(dev, intf);
 	if (status < 0)
drivers/net/usb/rndis_host.c +3 -3
index 5e39d05a2d7b..d539654687c3 100644
@@ -57,7 +57,7 @@ EXPORT_SYMBOL_GPL(rndis_status);
 static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg,
 				int buflen)
 {
-	struct cdc_state *info = (void *)&dev->data;
+	struct cdc_state *info = &dev->cdc;
 	struct device *udev = &info->control->dev;
 
 	if (dev->driver_info->indication) {
@@ -90,7 +90,7 @@ static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg,
  */
 int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
 {
-	struct cdc_state	*info = (void *) &dev->data;
+	struct cdc_state	*info = &dev->cdc;
 	struct usb_cdc_notification notification;
 	int			master_ifnum;
 	int			retval;
@@ -290,7 +290,7 @@ generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags)
 {
 	int			retval;
 	struct net_device	*net = dev->net;
-	struct cdc_state	*info = (void *) &dev->data;
+	struct cdc_state	*info = &dev->cdc;
 	union {
 		void			*buf;
 		struct rndis_msg_hdr	*header;
Signature · 1 line
2.54.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH net-next 1/4] net: usb: move updating filter and status from cdc to usbnet

In reply to Oliver Neukum

Hi,
I have a couple suggestions for you patch. Some parts are weird to read - it could also be that my perception today is off.

Quoted 1 line · Oliver Neukum

These helpers are used by multiple drivers and do not depend

"and do not only depend on cdc core. They also depend on other cdc drivers."
is this better?

Quoted 1 line

on the rest of cdc. Leavin them in a cdc driver means that

/Leavin/Leaving/

Quoted 1 line

more drivers are loaded just for infrastructure, not hardware

just for the support of other drivers, not their hardware.

Quoted 106 lines

support.

---
 drivers/net/usb/cdc_ether.c | 75 ------------------------------------ drivers/net/usb/usbnet.c    | 76 +++++++++++++++++++++++++++++++++++++

 2 files changed, 76 insertions(+), 75 deletions(-)
drivers/net/usb/cdc_ether.c +0 -0
index a0a5740590b9..b4df32e18461 100644
@@ -63,35 +63,6 @@ static const u8 mbm_guid[16] = {
  	0xa6, 0x07, 0xc0, 0xff, 0xcb, 0x7e, 0x39, 0x2a,
  };

drivers/net/usb/cdc_ether.c +0 -29
-void usbnet_cdc_update_filter(struct usbnet *dev)
-{
-	struct net_device	*net = dev->net;
-
-	u16 cdc_filter = USB_CDC_PACKET_TYPE_DIRECTED
-			| USB_CDC_PACKET_TYPE_BROADCAST;
-
-	/* filtering on the device is an optional feature and not worth
-	 * the hassle so we just roughly care about snooping and if any
-	 * multicast is requested, we take every multicast
-	 */
-	if (net->flags & IFF_PROMISC)
-		cdc_filter |= USB_CDC_PACKET_TYPE_PROMISCUOUS;
-	if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI))
-		cdc_filter |= USB_CDC_PACKET_TYPE_ALL_MULTICAST;
-
-	usb_control_msg(dev->udev,
-			usb_sndctrlpipe(dev->udev, 0),
-			USB_CDC_SET_ETHERNET_PACKET_FILTER,
-			USB_TYPE_CLASS | USB_RECIP_INTERFACE,
-			cdc_filter,
-			dev->intf->cur_altsetting->desc.bInterfaceNumber,
-			NULL,
-			0,
-			USB_CTRL_SET_TIMEOUT
-		);
-}
-EXPORT_SYMBOL_GPL(usbnet_cdc_update_filter);
-

 /* We need to override usbnet_*_link_ksettings in bind() */ static const struct ethtool_ops cdc_ether_ethtool_ops = {
  .get_link = usbnet_get_link,

drivers/net/usb/cdc_ether.c +0 -0
@@ -400,52 +371,6 @@ EXPORT_SYMBOL_GPL(usbnet_cdc_unbind);
   * (by Brad Hards) talked with, with more functionality.
   */

drivers/net/usb/cdc_ether.c +0 -46
-static void speed_change(struct usbnet *dev, __le32 *speeds)
-{
-	dev->tx_speed = __le32_to_cpu(speeds[0]);
-	dev->rx_speed = __le32_to_cpu(speeds[1]);
-}
-
-void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
-{
-	struct usb_cdc_notification	*event;
-
-	if (urb->actual_length < sizeof(*event))
-		return;
-
-	/* SPEED_CHANGE can get split into two 8-byte packets */
-	if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) {
-		speed_change(dev, (__le32 *) urb->transfer_buffer);
-		return;
-	}
-
-	event = urb->transfer_buffer;
-	switch (event->bNotificationType) {
-	case USB_CDC_NOTIFY_NETWORK_CONNECTION:
-		netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
-			  event->wValue ? "on" : "off");
-		if (netif_carrier_ok(dev->net) != !!event->wValue)
-			usbnet_link_change(dev, !!event->wValue, 0);
-		break;
-	case USB_CDC_NOTIFY_SPEED_CHANGE:	/* tx/rx rates */
-		netif_dbg(dev, timer, dev->net, "CDC: speed change (len %d)\n",
-			  urb->actual_length);
-		if (urb->actual_length != (sizeof(*event) + 8))
-			set_bit(EVENT_STS_SPLIT, &dev->flags);
-		else
-			speed_change(dev, (__le32 *) &event[1]);
-		break;
-	/* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS),
-	 * but there are no standard formats for the response data.
-	 */
-	default:
-		netdev_err(dev->net, "CDC: unexpected notification %02x!\n",
-			   event->bNotificationType);
-		break;
-	}
-}
-EXPORT_SYMBOL_GPL(usbnet_cdc_status);
-

 int usbnet_cdc_bind(struct usbnet *dev, struct usb_interface *intf) {
  int status;

drivers/net/usb/usbnet.c +0 -0
index 25518635b7b7..5544af1f4aa5 100644

drivers/net/usb/usbnet.c line 25

Quoted 4 lines
drivers/net/usb/usbnet.c +1 -0
@@ -22,6 +22,7 @@
  #include <linux/init.h>
  #include <linux/netdevice.h>
  #include <linux/etherdevice.h>
+#include <linux/usb/cdc.h>

why do you put it there?
it could be alphabetical instead.

Quoted 8 lines
drivers/net/usb/usbnet.c +0 -0
  #include <linux/ctype.h>
  #include <linux/ethtool.h>
  #include <linux/workqueue.h>
@@ -2271,6 +2272,81 @@ int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8
 reqtype,


 }
 EXPORT_SYMBOL_GPL(usbnet_write_cmd_async);

drivers/net/usb/usbnet.c int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype, · line 2282

Quoted 8 lines
drivers/net/usb/usbnet.c +8 -0
+
+void usbnet_cdc_update_filter(struct usbnet *dev)
+{
+	struct net_device	*net = dev->net;
+
+	u16 cdc_filter = USB_CDC_PACKET_TYPE_DIRECTED
+			| USB_CDC_PACKET_TYPE_BROADCAST;
+

Multi-line-comments in coding-style:

	/*
	 * filtering on ..

drivers/net/usb/usbnet.c int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype, · line 2285

Quoted 3 lines
drivers/net/usb/usbnet.c +3 -0
+	/* filtering on the device is an optional feature and not worth
+	 * the hassle so we just roughly care about snooping and if any
+	 * multicast is requested, we take every multicast

, we take that multicast.
also that's a pretty long sentence.

Quoted 44 lines
drivers/net/usb/usbnet.c +44 -0
+	 */
+	if (net->flags & IFF_PROMISC)
+		cdc_filter |= USB_CDC_PACKET_TYPE_PROMISCUOUS;
+	if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI))
+		cdc_filter |= USB_CDC_PACKET_TYPE_ALL_MULTICAST;
+
+	usb_control_msg(dev->udev,
+			usb_sndctrlpipe(dev->udev, 0),
+			USB_CDC_SET_ETHERNET_PACKET_FILTER,
+			USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+			cdc_filter,
+			dev->intf->cur_altsetting->desc.bInterfaceNumber,
+			NULL,
+			0,
+			USB_CTRL_SET_TIMEOUT
+		);
+}
+EXPORT_SYMBOL_GPL(usbnet_cdc_update_filter);
+
+static void speed_change(struct usbnet *dev, __le32 *speeds)
+{
+	dev->tx_speed = __le32_to_cpu(speeds[0]);
+	dev->rx_speed = __le32_to_cpu(speeds[1]);
+}
+
+void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
+{
+	struct usb_cdc_notification	*event;
+
+	if (urb->actual_length < sizeof(*event))
+		return;
+
+	/* SPEED_CHANGE can get split into two 8-byte packets */
+	if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) {
+		speed_change(dev, (__le32 *)urb->transfer_buffer);
+		return;
+	}
+
+	event = urb->transfer_buffer;
+	switch (event->bNotificationType) {
+	case USB_CDC_NOTIFY_NETWORK_CONNECTION:
+		netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
+			  event->wValue ? "on" : "off");
+		if (netif_carrier_ok(dev->net) != !!event->wValue)

drivers/net/usb/usbnet.c int usbnet_write_cmd_async(struct usbnet *dev, u8 cmd, u8 reqtype, · line 2339

Quoted 10 lines
drivers/net/usb/usbnet.c +10 -0
+			usbnet_link_change(dev, !!event->wValue, 0);
+		break;
+	case USB_CDC_NOTIFY_SPEED_CHANGE:	/* tx/rx rates */
+		netif_dbg(dev, timer, dev->net, "CDC: speed change (len %d)\n",
+			  urb->actual_length);
+		if (urb->actual_length != (sizeof(*event) + 8))
+			set_bit(EVENT_STS_SPLIT, &dev->flags);
+		else
+			speed_change(dev, (__le32 *)&event[1]);
+		break;
	/*
	 * USB ..
Quoted 10 lines
drivers/net/usb/usbnet.c +10 -0
+	/* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS),
+	 * but there are no standard formats for the response data.
+	 */
+	default:
+		netdev_err(dev->net, "CDC: unexpected notification %02x!\n",
+			   event->bNotificationType);
+		break;
+	}
+}
+EXPORT_SYMBOL_GPL(usbnet_cdc_status);
Quoted 3 lines

 /*-------------------------------------------------------------------------*/
 static int __init usbnet_init(void)

You can add my

Thanks
Manuel

#10 lore raw
In reply to Oliver Neukum
Quoted 2 lines · Oliver Neukum

Some drivers are reusing common code originating in other drivers. This means that two drivers need to be loaded for one device.

Maybe consider using 'framework' or 'library', rather than driver, when referring to the shared code?

I tend to think of a driver as the leaf node which probes based on enumeration of a bus. But usbnet.c itself is never probed.

Andrew

#3 lore raw

Re: [PATCH net-next 1/4] net: usb: move updating filter and status from cdc to usbnet

In reply to Oliver Neukum
Quoted 2 lines · Oliver Neukum

These helpers are used by multiple drivers and do not depend on the rest of cdc. Leavin them in a cdc driver means that

leaving.

Quoted 2 lines

more drivers are loaded just for infrastructure, not hardware support.

Can there also be changes to Kconfig removing the dependency on cdc_ether for some drivers? They now only depend on usbnet?

Andrew

Reviewed-by on the v1 series
#13 lore raw
In reply to Oliver Neukum

Hallo,

On Thu, 2026-07-02 at 16:25 +0200, Oliver Neukum wrote:

I know this mail doesn't matter much, but i can't leave it as is.

Quoted 1 line

Some drivers are reusing common code originating in other drivers.

Some drivers are using code from other drivers.

Quoted 4 lines

This means that two drivers need to be loaded for one device. Also maintainability is reduced if changes in one driver affect another driver.
Shift common code to usbnet.

You can add my

to the series.

Thanks
Manuel

#5 lore raw

Re: [PATCH net-next 2/4] net: usb: centralize usbnet_cdc_zte_rx_fixup in usbnet

In reply to Oliver Neukum
Quoted 16 lines · Oliver Neukum

This helper is used by multiple drivers using usbnet. It is better to be provided by usbnet than one of them.

---
 drivers/net/usb/cdc_ether.c | 19 ------------------- drivers/net/usb/usbnet.c    | 19 +++++++++++++++++++

 2 files changed, 19 insertions(+), 19 deletions(-)

...

drivers/net/usb/usbnet.c +0 -0
index 5544af1f4aa5..7beea6d0e731 100644

drivers/net/usb/usbnet.c void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) · line 2351

Quoted 5 lines
drivers/net/usb/usbnet.c +2 -0
@@ -2347,6 +2347,25 @@ void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
  	}
  }
  EXPORT_SYMBOL_GPL(usbnet_cdc_status);
+
+/* Make sure packets have correct destination MAC address

/*
* Make sure packets have the correct destination MAC address

drivers/net/usb/usbnet.c void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) · line 2354

Quoted 3 lines
drivers/net/usb/usbnet.c +3 -0
+ *
+ * A firmware bug observed on some devices (ZTE MF823/831/910) is that the
+ * device sends packets with a static, bogus, random MAC address (event if

(even if the device ...

drivers/net/usb/usbnet.c void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) · line 2356

Quoted 2 lines
drivers/net/usb/usbnet.c +2 -0
+ * device MAC address has been updated). Always set MAC address to that of the
+ * device.

Always set the MAC address to the one of your device.

Thanks
Manuel

Quoted 16 lines
drivers/net/usb/usbnet.c +13 -0
+ * device.
+ */
+int usbnet_cdc_zte_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
+{
+	if (skb->len < ETH_HLEN || !(skb->data[0] & 0x02))
+		return 1;
+
+	skb_reset_mac_header(skb);
+	ether_addr_copy(eth_hdr(skb)->h_dest, dev->net->dev_addr);
+
+	return 1;
+}
+EXPORT_SYMBOL_GPL(usbnet_cdc_zte_rx_fixup);
  /*-------------------------------------------------------------------------*/


 static int __init usbnet_init(void)

author maintainer
#11 lore raw
In reply to Andrew Lunn
Quoted 9 lines · Andrew Lunn
Quoted 2 lines · Oliver Neukum

Some drivers are reusing common code originating in other drivers. This means that two drivers need to be loaded for one device.

Maybe consider using 'framework' or 'library', rather than driver, when referring to the shared code?

I tend to think of a driver as the leaf node which probes based on enumeration of a bus. But usbnet.c itself is never probed.

Yes, I also think of a leaf node when a "driver" is referred to. That is the very point. Currently you need _two_ drivers and usbnet for some devices.
Should I reformulate? If so, how exactly?

Regards
Oliver

#12 lore raw
Quoted 8 lines · Oliver Neukum
Quoted 7 lines · Andrew Lunn
Quoted 2 lines · Oliver Neukum

Some drivers are reusing common code originating in other drivers. This means that two drivers need to be loaded for one device.

Maybe consider using 'framework' or 'library', rather than driver, when referring to the shared code?

Quoted 7 lines
Quoted 2 lines

I tend to think of a driver as the leaf node which probes based on enumeration of a bus. But usbnet.c itself is never probed.

Yes, I also think of a leaf node when a "driver" is referred to. That is the very point. Currently you need _two_ drivers and usbnet for some devices.
Should I reformulate? If so, how exactly?

Maybe give examples? List the two drivers used for one device? cdc_ether.c is being used both as a driver and a library? The EXPORT_SYMBOL_GPL() make this clear, a driver would normally not need exports. The patchset starts to make cdc_ether.c a pure driver, moving some of the shared code into the usbnet library.

Just to be clear, i think what you are doing is correct, i just had problems understanding the commit message.

Andrew

author maintainer
#6 lore raw

Re: [PATCH net-next 2/4] net: usb: centralize usbnet_cdc_zte_rx_fixup in usbnet

In reply to Manuel Ebner
Quoted 15 lines · Manuel Ebner

drivers/net/usb/usbnet.c void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) · line 2351

Quoted 11 lines · Oliver Neukum
drivers/net/usb/usbnet.c +2 -0
index 5544af1f4aa5..7beea6d0e731 100644
@@ -2347,6 +2347,25 @@ void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
  	}
  }
  EXPORT_SYMBOL_GPL(usbnet_cdc_status);
+
+/* Make sure packets have correct destination MAC address

/*
* Make sure packets have the correct destination MAC address

This sort of puts me into a conundrum. Does networking code use the short style of comments or not? The documentation says that it does. I am fine either way, but I need a clear rule.

Quoted 5 lines

drivers/net/usb/usbnet.c void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) · line 2354

Quoted 3 lines
drivers/net/usb/usbnet.c +3 -0
+ *
+ * A firmware bug observed on some devices (ZTE MF823/831/910) is that the
+ * device sends packets with a static, bogus, random MAC address (event if

(even if the device ...

Understood

Quoted 5 lines

drivers/net/usb/usbnet.c void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) · line 2356

Quoted 3 lines
drivers/net/usb/usbnet.c +2 -0
+ * device MAC address has been updated). Always set MAC address to that of the
+ * device.

Always set the MAC address to the one of your device.

Understood

Regards
Oliver

maintainer
#7 lore raw

Re: [PATCH net-next 2/4] net: usb: centralize usbnet_cdc_zte_rx_fixup in usbnet

Quoted 17 lines · Oliver Neukum
Quoted 15 lines · Manuel Ebner

drivers/net/usb/usbnet.c void usbnet_cdc_status(struct usbnet *dev, struct urb *urb) · line 2351

Quoted 11 lines · Oliver Neukum
drivers/net/usb/usbnet.c +2 -0
index 5544af1f4aa5..7beea6d0e731 100644
@@ -2347,6 +2347,25 @@ void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
  	}
  }
  EXPORT_SYMBOL_GPL(usbnet_cdc_status);
+
+/* Make sure packets have correct destination MAC address

/*
* Make sure packets have the correct destination MAC address

Quoted 3 lines

This sort of puts me into a conundrum. Does networking code use the short style of comments or not? The documentation says that it does. I am fine either way, but I need a clear rule.

Networking code used to require

/* for
* multiline comments
*/

but somewhat recently we switched to accept also the more common

/*
* multiline comment
*/

Checkpatch accepts both; it's not a deal breaker either ways.

/P