Subject: re-submit4 [ANNOUNCEMENT] NET: usb: sierra_net.c driver
Subsystems (3)
Subject: re-submit4 [ANNOUNCEMENT] NET: usb: sierra_net.c driver
From: Elina Pasheva <[email protected]>
The following is a new Linux driver which exposes certain models of Sierra Wireless modems to the operating system as Network Interface Cards (NICs).
This driver requires a version of the sierra.c driver which supports blacklisting to work properly. The blacklist in sierra.c rejects the interfaces claimed by sierra_net.c. Likewise, the sierra_net.c driver only accepts (i.e. whitelists) the interface(s) used for USB-to-WWAN traffic. The version of sierra.c which supports blacklisting is
available from the sierra wireless knowledge base page for older kernels. It is also available in Linux kernel starting from version 2.6.31.
This driver works with all Sierra Wireless devices configured with PID=68A3 like USB305, USB306 provided the corresponding firmware version is I2.0 (for USB305) or M3.0 (for USB306) and later.
This driver will not work with earlier firmware versions than the ones shown above. In this case the driver will issue an error message indicating incompatibility and will not serve the device's USB-to-WWAN interface.
Sierra_net.c sits atop a pre-existing Linux driver called usbnet.c. A series of hook functions are provided in sierra_net.c which are called by usbnet.c in response to a particular condition such as receipt or transmission of a data packet. As such, usbnet.c does most of the work of making a modem appear to the system as a network device and for properly exchanging traffic between the USB subsystem and the Network card interface. Sierra_net.c is concerned with managing the data exchanged between the USB-to-WWAN interface and the upper layers of the operating system.
The version number of sierra_net.c driver is set to 2.0.
Thanks to Dan Williams for his generous help in generating this patch. This patch has been checked against net-2.6 tree.
---
drivers/net/usb/Kconfig | 10 + drivers/net/usb/Makefile | 2 +- drivers/net/usb/sierra_net.c | 987 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 998 insertions(+), 1 deletions(-) create mode 100644 drivers/net/usb/sierra_net.c
drivers/net/usb/Kconfig +10 -0
@@ -385,4 +385,14 @@ config USB_CDC_PHONET cellular modem, as found on most Nokia handsets with the "PC suite" USB profile. +config USB_SIERRA_NET + tristate "USB-to-WWAN Driver for Sierra Wireless modems" + depends on USB_USBNET + default y + help + Choose this option if you have a Sierra Wireless USB-to-WWAN device. + + To compile this driver as a module, choose M here: the + module will be called sierra_net. + endmenu
drivers/net/usb/Makefile +1 -1
@@ -23,4 +23,4 @@ obj-$(CONFIG_USB_NET_MCS7830) += mcs7830.o obj-$(CONFIG_USB_USBNET) += usbnet.o obj-$(CONFIG_USB_NET_INT51X1) += int51x1.o obj-$(CONFIG_USB_CDC_PHONET) += cdc-phonet.o - +obj-$(CONFIG_USB_SIERRA_NET) += sierra_net.o
drivers/net/usb/sierra_net.c new file +987 -0
987 lines not on this page · raw message
Signature · 1 line
1.5.4.3
drivers/net/usb/sierra_net.c line 325
Quoted 10 lines · Elina Pasheva
drivers/net/usb/sierra_net.c new file +10
-0+static void sierra_net_send_cmd (struct usbnet *dev, +u8 *cmd,int cmdlen,const char * cmd_name) +{ +struct sierra_net_data *priv =sierra_net_get_private (dev); +int status; + + status =usb_control_msg (dev->udev,usb_sndctrlpipe (dev->udev,0 ), +USB_CDC_SEND_ENCAPSULATED_COMMAND , +USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE ,0 , + priv->ifnum, cmd, cmdlen,0 );
No timeout?
drivers/net/usb/sierra_net.c line 471
Quoted 5 lines
drivers/net/usb/sierra_net.c new file +5
-0+ ifnum = priv->ifnum; + len =usb_control_msg (dev->udev,usb_rcvctrlpipe (dev->udev,0 ), +USB_CDC_GET_ENCAPSULATED_RESPONSE , +USB_DIR_IN |USB_TYPE_CLASS |USB_RECIP_INTERFACE , +0 , ifnum, buf,SIERRA_NET_USBCTL_BUF_LEN ,0 );
No timeout?
drivers/net/usb/sierra_net.c line 475
Quoted 3 lines
drivers/net/usb/sierra_net.c new file +3
-0+if (unlikely (len <0 )) { +netdev_err (dev->net, +"usb_control_msg failed, status %d\n" , len);
You don't need "unlikely", this is an extreemly slow path here. Also, what happens for a "short read"? You don't handle that properly.
thanks,
greg k-h
Quoted 22 lines · Greg KH
drivers/net/usb/sierra_net.c line 325
Quoted 10 lines · Elina Pasheva
drivers/net/usb/sierra_net.c new file +10
-0+static void sierra_net_send_cmd (struct usbnet *dev, +u8 *cmd,int cmdlen,const char * cmd_name) +{ +struct sierra_net_data *priv =sierra_net_get_private (dev); +int status; + + status =usb_control_msg (dev->udev,usb_sndctrlpipe (dev->udev,0 ), +USB_CDC_SEND_ENCAPSULATED_COMMAND , +USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE ,0 , + priv->ifnum, cmd, cmdlen,0 );No timeout?
drivers/net/usb/sierra_net.c line 471
Quoted 5 lines
drivers/net/usb/sierra_net.c new file +5
-0+ ifnum = priv->ifnum; + len =usb_control_msg (dev->udev,usb_rcvctrlpipe (dev->udev,0 ), +USB_CDC_GET_ENCAPSULATED_RESPONSE , +USB_DIR_IN |USB_TYPE_CLASS |USB_RECIP_INTERFACE , +0 , ifnum, buf,SIERRA_NET_USBCTL_BUF_LEN ,0 );No timeout?
Quoted 6 lines
drivers/net/usb/sierra_net.c line 475
Quoted 3 lines
drivers/net/usb/sierra_net.c new file +3
-0+if (unlikely (len <0 )) { +netdev_err (dev->net, +"usb_control_msg failed, status %d\n" , len);You don't need "unlikely", this is an extreemly slow path here. Also, what happens for a "short read"? You don't handle that properly.
Is the code doc for usb_unlink_urb() in urb.c the best thing to look at for how to handle short reads? I assume that involves checking if the returned error is -EREMOTEIO and if so, ignoring it? I spent about an hour googling and poking around in the kernel sources and couldn't find much about how to handle short reads. The only non-host-side driver that cares about EREMOTEIO is misc/rio500.c, the rest is all under host/ or gadget/.
In the 3 places that this driver calls usb_control_msg(), the codepaths don't need any special -EREMOTEIO handling.
Dan
Quoted 30 lines · Dan Williams
Quoted 22 lines · Greg KH
drivers/net/usb/sierra_net.c line 325
Quoted 10 lines · Elina Pasheva
drivers/net/usb/sierra_net.c new file +10
-0+static void sierra_net_send_cmd (struct usbnet *dev, +u8 *cmd,int cmdlen,const char * cmd_name) +{ +struct sierra_net_data *priv =sierra_net_get_private (dev); +int status; + + status =usb_control_msg (dev->udev,usb_sndctrlpipe (dev->udev,0 ), +USB_CDC_SEND_ENCAPSULATED_COMMAND , +USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE ,0 , + priv->ifnum, cmd, cmdlen,0 );No timeout?
drivers/net/usb/sierra_net.c line 471
Quoted 5 lines
drivers/net/usb/sierra_net.c new file +5
-0+ ifnum = priv->ifnum; + len =usb_control_msg (dev->udev,usb_rcvctrlpipe (dev->udev,0 ), +USB_CDC_GET_ENCAPSULATED_RESPONSE , +USB_DIR_IN |USB_TYPE_CLASS |USB_RECIP_INTERFACE , +0 , ifnum, buf,SIERRA_NET_USBCTL_BUF_LEN ,0 );No timeout?
Quoted 6 lines
drivers/net/usb/sierra_net.c line 475
Quoted 3 lines
drivers/net/usb/sierra_net.c new file +3
-0+if (unlikely (len <0 )) { +netdev_err (dev->net, +"usb_control_msg failed, status %d\n" , len);You don't need "unlikely", this is an extreemly slow path here. Also, what happens for a "short read"? You don't handle that properly.
Quoted 7 lines
Is the code doc for
usb_unlink_urb()inurb.cthe best thing to look at for how to handle short reads? I assume that involves checking if the returned error is-EREMOTEIOand if so, ignoring it? I spent about an hour googling and poking around in the kernel sources and couldn't find much about how to handle short reads. The only non-host-side driver that cares about EREMOTEIO ismisc/rio500.c, the rest is all under host/ or gadget/.
Well, if the return value is less than what you expect it to be, something went wrong and you should error out. Some of the calls handle this properly in this driver, some do not. Consistency is key :)
thanks,
greg k-h
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Greg KH
Quoted 7 lines
Quoted 7 lines
drivers/net/usb/sierra_net.c line 325
Quoted 5 lines
drivers/net/usb/sierra_net.c new file +5
-0+ + status =usb_control_msg (dev->udev,usb_sndctrlpipe (dev->udev,0 ), +USB_CDC_SEND_ENCAPSULATED_COMMAND , +USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE ,0 , + priv->ifnum, cmd, cmdlen,0 );No timeout?
Good catch. Will fix.
Quoted 1 line
Quoted 1 line
Quoted 1 line
No timeout?
Will fix.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/net/usb/sierra_net.c line 475
Quoted 4 lines
drivers/net/usb/sierra_net.c new file +3
-0+if (unlikely (len <0 )) { +netdev_err (dev->net, +"usb_control_msg failed, status %d\n" , len);You don't need "unlikely", this is an extreemly slow path here.
Will fix.
Quoted 3 lines
Well, if the return value is less than what you expect it to be, something went wrong and you should error out. Some of the calls handle this properly in this driver, some do not. Consistency is key :)
Good point. Thanks. Will check for consistency and resubmit.
Elina
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html