From fb4c24637de82a81374622d3f2f96452e0fb07d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wxcaf=C3=A9?= Date: Mon, 13 Jul 2020 16:16:14 -0400 Subject: [PATCH 1/3] net: cdc_ether: export generic usbnet_cdc_update_filter This makes the function avaiable to other drivers, like cdn_ncm. Other drivers will use different dev->data types, so the exported function must not use it; instead the exported function takes an additional pointer to the control interface. Within cdc_ether the control interface is still taken from the control field from struct cdc_state stored in dev->data. --- drivers/net/usb/cdc_ether.c | 24 ++++++++++++++++-------- include/linux/usb/usbnet.h | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c index a657943c9f01..b201adc885f6 100644 --- a/drivers/net/usb/cdc_ether.c +++ b/drivers/net/usb/cdc_ether.c @@ -63,10 +63,8 @@ static const u8 mbm_guid[16] = { 0xa6, 0x07, 0xc0, 0xff, 0xcb, 0x7e, 0x39, 0x2a, }; -static void usbnet_cdc_update_filter(struct usbnet *dev) +void usbnet_cdc_update_filter(struct usbnet *dev, struct usb_interface *control) { - struct cdc_state *info = (void *) &dev->data; - struct usb_interface *intf = info->control; struct net_device *net = dev->net; u16 cdc_filter = USB_CDC_PACKET_TYPE_DIRECTED @@ -86,12 +84,22 @@ static void usbnet_cdc_update_filter(struct usbnet *dev) USB_CDC_SET_ETHERNET_PACKET_FILTER, USB_TYPE_CLASS | USB_RECIP_INTERFACE, cdc_filter, - intf->cur_altsetting->desc.bInterfaceNumber, + control->cur_altsetting->desc.bInterfaceNumber, NULL, 0, USB_CTRL_SET_TIMEOUT ); } +EXPORT_SYMBOL_GPL(usbnet_cdc_update_filter); + +/* the control interface is not always necessarily the probed interface + * dev->intf, see rndis handling in usbnet_generic_cdc_bind. + */ +static void usbnet_cdc_ether_update_filter(struct usbnet *dev) { + struct cdc_state *info = (void *)&dev->data; + + usbnet_cdc_update_filter(dev, info->control); +} /* probes control interface, claims data interface, collects the bulk * endpoints, activates data interface (if needed), maybe sets MTU. @@ -336,7 +344,7 @@ int usbnet_ether_cdc_bind(struct usbnet *dev, struct usb_interface *intf) * don't do reset all the way. So the packet filter should * be set to a sane initial value. */ - usbnet_cdc_update_filter(dev); + usbnet_cdc_ether_update_filter(dev); bail_out: return rv; @@ -514,7 +522,7 @@ static const struct driver_info cdc_info = { .bind = usbnet_cdc_bind, .unbind = usbnet_cdc_unbind, .status = usbnet_cdc_status, - .set_rx_mode = usbnet_cdc_update_filter, + .set_rx_mode = usbnet_cdc_ether_update_filter, .manage_power = usbnet_manage_power, }; @@ -524,7 +532,7 @@ static const struct driver_info zte_cdc_info = { .bind = usbnet_cdc_zte_bind, .unbind = usbnet_cdc_unbind, .status = usbnet_cdc_zte_status, - .set_rx_mode = usbnet_cdc_update_filter, + .set_rx_mode = usbnet_cdc_ether_update_filter, .manage_power = usbnet_manage_power, .rx_fixup = usbnet_cdc_zte_rx_fixup, }; @@ -535,7 +543,7 @@ static const struct driver_info wwan_info = { .bind = usbnet_cdc_bind, .unbind = usbnet_cdc_unbind, .status = usbnet_cdc_status, - .set_rx_mode = usbnet_cdc_update_filter, + .set_rx_mode = usbnet_cdc_ether_update_filter, .manage_power = usbnet_manage_power, }; diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h index b0bff3083278..387f3da06e9d 100644 --- a/include/linux/usb/usbnet.h +++ b/include/linux/usb/usbnet.h @@ -286,4 +286,6 @@ extern void usbnet_update_max_qlen(struct usbnet *dev); extern void usbnet_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats); +extern void usbnet_cdc_update_filter(struct usbnet *, struct usb_interface *); + #endif /* __LINUX_USB_USBNET_H */ -- 2.27.0