Skip to contentSkip to conversation

Adding new drivers for Qualcomm MSM based LTE modems

PATCH In review Bjørn Mork 3 participants 8 messages Jan 15, 2012 4 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover Adding new drivers for Qualcomm MSM based LTE modems

This can probably support many more devices based on modern Qualcomm chipsets, but has only been tested with a Huawei E392 LTE modem based on Qualcomm MDM9200.

These chips require using the QMI protocol to enable anything but serial mode. They can, and should, still be configured using AT commands on one of the serial interfaces. In particular, this driver does not support entering SIM PIN code or APN, which may be required before opening a connection. PIN can be set by using the standard AT+CPIN="xxxx" command. APN can most likely be set by storing it in the default profile.

patch 1 relaxes the cdc_ether CDC descriptor parsing in such a way that it will allow a vendor specific data interface if and only if the control interface also is vendor specific. This allows us to reuse the bind() function from cdc_ether for one of the possible device configurations we support

patch 2 adds a new "subdriver" which exports the CDC encapsulated command interface as a character device, and also to the calling driver.

patch 3 adds the wwan driver, which uses the "subdriver" to configure the device via the Qualcomm MSM Interface (QMI) protocol encapsulated in CDC control commands. The actual network device is a minimalistic usbnet minidriver.

Bjørn Mork (3):
cdc_ether: allow vendor specific data interface if control interface
is vendor specific
net: usb: cdc_enc: New driver exposing USB CDC encapsulated protocols
net: usb: qmi_wwan: New driver for QMI WAN devices

 drivers/net/usb/Kconfig         |   28 +++
 drivers/net/usb/Makefile        |    3 +
 drivers/net/usb/cdc_enc.c       |  452 +++++++++++++++++++++++++++++++++++++
 drivers/net/usb/cdc_enc.h       |   77 +++++++
 drivers/net/usb/cdc_ether.c     |    6 +-
 drivers/net/usb/qmi_proto.c     |  475 +++++++++++++++++++++++++++++++++++++++
 drivers/net/usb/qmi_proto.h     |   98 ++++++++
 drivers/net/usb/qmi_wwan_core.c |  343 ++++++++++++++++++++++++++++
 8 files changed, 1481 insertions(+), 1 deletions(-)
 create mode 100644 drivers/net/usb/cdc_enc.c
 create mode 100644 drivers/net/usb/cdc_enc.h
 create mode 100644 drivers/net/usb/qmi_proto.c
 create mode 100644 drivers/net/usb/qmi_proto.h
 create mode 100644 drivers/net/usb/qmi_wwan_core.c
Signature · 6 lines
1.7.7.3

--
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
#2 lore raw

PATCH v2 1/3 cdc_ether: allow vendor specific data interface if control interface is vendor specific

In reply to a message not in the archive

Some vendors, like Huawei, use the vendor specific class code all over the place even for devices which otherwise conform pretty well to the CDC ECM specification. This allows such devices to be supported merely by adding them to the device specific whitelist.

---
Changes from v1: Removed an unintentional debug message change. Thanks to Joe Perches for pointing that out

 drivers/net/usb/cdc_ether.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/net/usb/cdc_ether.c +5 -1
index 41a61ef..a14a4a3 100644
@@ -211,7 +211,11 @@ int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
 
 			/* a data interface altsetting does the real i/o */
 			d = &info->data->cur_altsetting->desc;
-			if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
+			if ((d->bInterfaceClass != USB_CLASS_CDC_DATA) &&
+				/* Allow vendor specific data interface iff
+				   control interface is vendor specific */
+				!(info->control->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
+					d->bInterfaceClass == USB_CLASS_VENDOR_SPEC)) {
 				dev_dbg(&intf->dev, "slave class %u\n",
 					d->bInterfaceClass);
 				goto bad_desc;
Signature · 6 lines
1.7.7.3

--
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
#3 lore raw

PATCH v2 2/3 net: usb: cdc_enc: New driver exposing USB CDC encapsulated protocols

In reply to a message not in the archive

USB CDC Ethernet devices may encapsulate vendor specific protocols inside USB_CDC_SEND_ENCAPSULATED_COMMAND +USB_CDC_GET_ENCAPSULATED_RESPONSE control messages. Devices based on Qualcomm MSM
chipsets are known to use this for exporting the Qualcomm
MSM Interface (QMI) protocol. Examples of such devices are the Huawei E392 and E398 LTE modems.

This is only a subdriver which needs to be linked from a real CDC ethernet driver like the QMI WWAN driver. The basic idea is that the USB ethernet driver will know what protocol, if any, the devices supports cia CDC encapsulated commands. It calls this driver to register it, naming the protocol, while this driver is completely protocol agnostic.

The encapsulated protocol is exported as a character device, and the protocol name is made available to userspace as a sysfs attribute.

---
Changes from v1: Completely rewritten and this generic part has been split out as a separate subdriver. It currently needs to be called from another usbnet based driver, and will abuse the status interrupt part of that for its own needs.

 drivers/net/usb/Kconfig   |   14 ++
 drivers/net/usb/Makefile  |    1 +
 drivers/net/usb/cdc_enc.c |  452 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/usb/cdc_enc.h |   77 ++++++++
 4 files changed, 544 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/cdc_enc.c
 create mode 100644 drivers/net/usb/cdc_enc.h
drivers/net/usb/Kconfig +14 -0
index 2335761..1425b08 100644
@@ -461,4 +461,18 @@ config USB_VL600
 
 	  http://ubuntuforums.org/showpost.php?p=10589647&postcount=17
 
+config USB_NET_CDC_ENC
+	tristate "CDC encapsulated command helper"
+	help
+	  USB CDC Ethernet devices may encapsulate vendor specific
+	  protocols inside CDC commands. Devices based on Qualcomm MSM
+	  chipsets are known to use this for exporting the Qualcomm
+	  MSM Interface (QMI) protocol. Examples of such devices are
+	  the Huawei E392 and E398 LTE modems.
+
+	  This is only a subdriver which needs to be linked from a
+	  real CDC Ethernet driver like the QMI WWAN driver.
+
+	  The encapsulated protocol is exported as a character device.
+
 endmenu
drivers/net/usb/Makefile +1 -0
index c203fa2..1edfc1b 100644
@@ -29,4 +29,5 @@ obj-$(CONFIG_USB_SIERRA_NET)	+= sierra_net.o
 obj-$(CONFIG_USB_NET_CX82310_ETH)	+= cx82310_eth.o
 obj-$(CONFIG_USB_NET_CDC_NCM)	+= cdc_ncm.o
 obj-$(CONFIG_USB_VL600)		+= lg-vl600.o
+obj-$(CONFIG_USB_NET_CDC_ENC)	+= cdc_enc.o
 
drivers/net/usb/cdc_enc.c new file +452 -0

452 lines not on this page · raw message

drivers/net/usb/cdc_enc.h new file +77 -0

77 lines not on this page · raw message

Signature · 6 lines
1.7.7.3

--
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
#11 lore raw

PATCH v2 3/3 net: usb: qmi_wwan: New driver for QMI WAN devices

In reply to a message not in the archive

Some WWAN LTE/3G devices based on chipsets from Qualcomm provide near standard CDC ECM interfaces in addition to the usual serial interfaces. But they cannot be fully configured using AT commands over a serial interface. It is necessary to speak the proprietary Qualcomm MSM Interface (QMI) protocol to the device to enable the ethernet proxy functionality.

This driver uses the cdc_enc subdriver to get access to the encapsulated QMI protocol interface, and implements the basic QMI support needed to bring up and down the interface. There is still a need to pre-configure some settings using e.g. a modem mananger application. Most users will want to set an APN and enter a PIN code, and some may also have to confgure authentication.

The layout of the usb interfaces can vary a lot within a single device, depending on which "modeswitch" command has been used to switch it from usb-storage mode. Control and data interfaces can be combined, or they can look like standard CDC ECM interfaces with the appropriate descriptors but with vendor specific class code. This driver is attempting to support them all, by reusing as much as possible of the existing usbnet infrastructure.

---
Changes from v1: Complete rewrite. The QMI protocol specific parts are split out from the rest of the driver, and all unnecessary QMI commands has been removed as per comments from Dan Williams. The full QMI protocol is instead exposed to userspace via a character device provided by the cdc_enc subdriver.

Some comments regarding the other QMI driver implementations I've come across:
- Gobi: similar to this driver, but does not use usbnet. Does expose the QMI protocol via a character device, but requires the user to send a number of ioctls to use it.

Should be less than problematic to create a compatible interface if there are any application using it. Are there?

- The Android MSM driver: uses a shared menory interface to talk to the modem, and does not expose QMI to userspace. Does have nice QMI message parsing (I wish I had noticed before...) and some of it could probably be split out in some common part. But I don't know if it's worth it.

 drivers/net/usb/Kconfig         |   14 ++
 drivers/net/usb/Makefile        |    2 +
 drivers/net/usb/qmi_proto.c     |  475 +++++++++++++++++++++++++++++++++++++++
 drivers/net/usb/qmi_proto.h     |   98 ++++++++
 drivers/net/usb/qmi_wwan_core.c |  343 ++++++++++++++++++++++++++++
 5 files changed, 932 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/qmi_proto.c
 create mode 100644 drivers/net/usb/qmi_proto.h
 create mode 100644 drivers/net/usb/qmi_wwan_core.c
drivers/net/usb/Kconfig +14 -0
index 1425b08..cc93122 100644
@@ -475,4 +475,18 @@ config USB_NET_CDC_ENC
 
 	  The encapsulated protocol is exported as a character device.
 
+config USB_NET_QMI_WWAN
+	tristate "QMI WWAN driver for Qualcomm MSM based 3G and LTE modems"
+	depends on USB_NET_CDCETHER
+	select USB_NET_CDC_ENC
+	help
+	  Support WWAN LTE/3G devices based on MSM chipsets from
+	  Qualcomm, using the Qualcomm MSM Interface (QMI) protocol to
+	  configure the device.
+
+	  Note that it is still necessary to configure parameters like
+	  PIN code, APN, username and password using AT commands on a
+	  ttyUSBx port.  Select the "option" driver to support these.
+
+
 endmenu
drivers/net/usb/Makefile +2 -0
index 1edfc1b..644d512 100644
@@ -30,4 +30,6 @@ obj-$(CONFIG_USB_NET_CX82310_ETH)	+= cx82310_eth.o
 obj-$(CONFIG_USB_NET_CDC_NCM)	+= cdc_ncm.o
 obj-$(CONFIG_USB_VL600)		+= lg-vl600.o
 obj-$(CONFIG_USB_NET_CDC_ENC)	+= cdc_enc.o
+obj-$(CONFIG_USB_NET_QMI_WWAN)	+= qmi_wwan.o
+qmi_wwan-objs := qmi_wwan_core.o qmi_proto.o
 
drivers/net/usb/qmi_proto.c new file +475 -0

475 lines not on this page · raw message

drivers/net/usb/qmi_proto.h new file +98 -0

98 lines not on this page · raw message

drivers/net/usb/qmi_wwan_core.c new file +343 -0

343 lines not on this page · raw message

Signature · 6 lines
1.7.7.3

--
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
#5 lore raw

Re: [PATCH v2 2/3] net: usb: cdc_enc: New driver exposing USB CDC encapsulated protocols

In reply to a message not in the archive

Am Sonntag, 15. Januar 2012, 07:40:36 schrieb Bjørn Mork:

Quoted 6 lines

USB CDC Ethernet devices may encapsulate vendor specific protocols inside USB_CDC_SEND_ENCAPSULATED_COMMAND +USB_CDC_GET_ENCAPSULATED_RESPONSE control messages. Devices based on Qualcomm MSM
chipsets are known to use this for exporting the Qualcomm
MSM Interface (QMI) protocol. Examples of such devices are the Huawei E392 and E398 LTE modems.

The problem is that this is another version of the code already in cdc-wdm, which is tested well.
I'd really like to unify this stuff.

Quoted 16 lines
drivers/net/usb/cdc_enc.c new file +16 -0
+static ssize_t cdc_enc_fops_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
+{
+	struct cdc_enc_client *client = file->private_data;
+	int ret = -EFAULT;
+
+	if (!client || !client->cdc_enc)
+		return -ENODEV;
+
+	while (!test_bit(CDC_ENC_CLIENT_RX, &client->flags)) {/* no data */
+		if (file->f_flags & O_NONBLOCK)
+			return -EAGAIN;
+
+		if (wait_for_completion_interruptible(&client->ready) < 0)
+			return -EINTR;
+
+		/* shutdown requested? */

drivers/net/usb/cdc_enc.c line 148

Quoted 10 lines
drivers/net/usb/cdc_enc.c new file +10 -0
+		if (test_bit(CDC_ENC_CLIENT_SHUTDOWN, &client->flags))
+			return -ENXIO;
+	}
+
+	/* someone else is using our buffer */
+	if (test_and_set_bit(CDC_ENC_CLIENT_BUSY, &client->flags))
+		return -ERESTARTSYS;
+
+	/* must read a complete packet */
+	if (client->len > size || copy_to_user(buf, client->buf, client->len)) {

This is not nice at all.

drivers/net/usb/cdc_enc.c line 157

Quoted 9 lines
drivers/net/usb/cdc_enc.c new file +9 -0
+		ret = -EFAULT;
+		goto err;
+	}
+	ret = client->len;
+
+err:
+	/* order is important! */
+	clear_bit(CDC_ENC_CLIENT_RX, &client->flags);
+	clear_bit(CDC_ENC_CLIENT_BUSY, &client->flags);

If order is important here, you need write barriers. And read barriers at another place.

Quoted 20 lines
drivers/net/usb/cdc_enc.c new file +20 -0
+	return ret;
+}
+
+static ssize_t cdc_enc_fops_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
+{
+	struct cdc_enc_client *client = file->private_data;
+	int ret = -EFAULT;
+
+	if (!client || !client->cdc_enc)
+		return -ENODEV;
+
+	/* shutdown requested? */
+	if (test_bit(CDC_ENC_CLIENT_SHUTDOWN, &client->flags))
+		return -ENXIO;
+
+	/* no meaning in attempting to send an incomplete packet */
+	if (size > sizeof(client->tx_buf))
+		return -EFAULT;
+
+	/* are someone else using our buffer? */

drivers/net/usb/cdc_enc.c line 188

Quoted 10 lines
drivers/net/usb/cdc_enc.c new file +10 -0
+	if (test_and_set_bit(CDC_ENC_CLIENT_TX, &client->flags))
+		return -ERESTARTSYS;
+
+	if (size > sizeof(client->tx_buf) || copy_from_user(client->tx_buf, buf, size))
+		goto err;
+
+	/* send to the device */
+	ret = cdc_enc_send_sync(client, client->tx_buf, size);
+	if (ret < 0)
+		return -EFAULT;

Error handling is shot. The device is now eternally busy.

drivers/net/usb/cdc_enc.c line 215

Quoted 12 lines
drivers/net/usb/cdc_enc.c new file +12 -0
+static int cdc_enc_fops_open(struct inode *inode, struct file *file)
+{
+	struct cdc_enc_state *cdc_enc;
+	struct cdc_enc_client *client;
+
+	/* associate the file with our backing CDC_ENC device */
+	cdc_enc = container_of(inode->i_cdev, struct cdc_enc_state, cdev);
+	if (!cdc_enc)
+		return -ENODEV;
+
+	/* don't allow interface to sleep while we are using it */
+	usb_autopm_get_interface(cdc_enc->intf);

This can fail.

drivers/net/usb/cdc_enc.c line 224

Quoted 8 lines
drivers/net/usb/cdc_enc.c new file +8 -0
+	/* enable status URB even if networking is down */
+	cdc_enc_status_urb(cdc_enc, GFP_KERNEL);
+
+	/* set up a ring buffer to receive our readable data? */
+	client = cdc_enc_add_client(cdc_enc, cdc_enc_newdata_rcvd);
+
+	if (!client)
+		return -ENOMEM;

Error handling. The device now can never again autosuspend.

Quoted 4 lines
drivers/net/usb/cdc_enc.c new file +4 -0
+
+	file->private_data = client;
+	return 0;
+}

[..]

Quoted 5 lines
drivers/net/usb/cdc_enc.c new file +5 -0
+/* disable and free a CDC_ENC state device */
+int cdc_enc_free_one(struct cdc_enc_state *cdc_enc)
+{
+	struct cdc_enc_client *tmp;
+

drivers/net/usb/cdc_enc.c line 399

Quoted 10 lines
drivers/net/usb/cdc_enc.c new file +10 -0
+	/* kill any pending recv urb */
+	cdc_enc_kill_readurb(cdc_enc);
+
+	/* wait for all clients to exit first ... */
+	list_for_each_entry(tmp, &cdc_enc->clients, list) {
+		dev_dbg(&cdc_enc->intf->dev, "waiting for client %p to die\n", tmp);
+		set_bit(CDC_ENC_CLIENT_SHUTDOWN, &tmp->flags);
+		complete(&tmp->ready);
+	}
+	wait_event_interruptible(cdc_enc->waitq, list_empty(&cdc_enc->clients));

If you wait interruptably, you need to handle being interrupted.

drivers/net/usb/cdc_enc.h line 44

Quoted 7 lines
drivers/net/usb/cdc_enc.h new file +7 -0
+
+/* per CDC_ENC interface state */
+struct cdc_enc_state {
+	struct usb_interface *intf;
+	struct urb *urb;		/* receive urb */
+	struct urb *interrupt;		/* interrupt urb */
+	unsigned char rcvbuf[CDC_ENC_BUFLEN];     /* receive buffer */

This is a violation of the DMA requirements. You must use kmalloc.

I had a not very detailed look at this driver, but I would really prefer if you could have a look at making unified code for this, cdc-wdm and cdc-acm.

Regards
Oliver
--
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

#7 lore raw

Re: [PATCH v2 2/3] net: usb: cdc_enc: New driver exposing USB CDC encapsulated protocols

In reply to a message not in the archive
Quoted 10 lines · Oliver Neukum

Am Sonntag, 15. Januar 2012, 07:40:36 schrieb Bjørn Mork:

Quoted 6 lines

USB CDC Ethernet devices may encapsulate vendor specific protocols inside USB_CDC_SEND_ENCAPSULATED_COMMAND +USB_CDC_GET_ENCAPSULATED_RESPONSE control messages. Devices based on Qualcomm MSM
chipsets are known to use this for exporting the Qualcomm
MSM Interface (QMI) protocol. Examples of such devices are the Huawei E392 and E398 LTE modems.

The problem is that this is another version of the code already in cdc-wdm, which is tested well.

Huh? I thought that was something entirely different. Isn't it?

Anyway, I see that I should look thoroughly at it as it does these things in a much nicer way. Thanks for the pointer.

Quoted 1 line

I'd really like to unify this stuff.

That makes sense.

[snipped a number of detailed issues which I obviously need to fix]

Quoted 9 lines

drivers/net/usb/cdc_enc.h line 44

Quoted 7 lines
drivers/net/usb/cdc_enc.h new file +7 -0
+
+/* per CDC_ENC interface state */
+struct cdc_enc_state {
+	struct usb_interface *intf;
+	struct urb *urb;		/* receive urb */
+	struct urb *interrupt;		/* interrupt urb */
+	unsigned char rcvbuf[CDC_ENC_BUFLEN];     /* receive buffer */

This is a violation of the DMA requirements. You must use kmalloc.

This probably only demonstrates my lack of understanding these requirements. I thought this was OK as long as I kmalloc'ed the whole struct, but I see now that that isn't necessarily true.

Quoted 3 lines

I had a not very detailed look at this driver, but I would really prefer if you could have a look at making unified code for this, cdc-wdm and cdc-acm.

Will do. Thanks a lot for the fast review.

Bjørn
--
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

#8 lore raw

Re: [PATCH v2 2/3] net: usb: cdc_enc: New driver exposing USB CDC encapsulated protocols

Quoted 9 lines · Bjørn Mork
Quoted 8 lines · Oliver Neukum

Am Sonntag, 15. Januar 2012, 07:40:36 schrieb Bjørn Mork:

Quoted 6 lines

USB CDC Ethernet devices may encapsulate vendor specific protocols inside USB_CDC_SEND_ENCAPSULATED_COMMAND +USB_CDC_GET_ENCAPSULATED_RESPONSE control messages. Devices based on Qualcomm MSM
chipsets are known to use this for exporting the Qualcomm
MSM Interface (QMI) protocol. Examples of such devices are the Huawei E392 and E398 LTE modems.

Quoted 4 lines
Quoted 2 lines

The problem is that this is another version of the code already in cdc-wdm, which is tested well.

Huh? I thought that was something entirely different. Isn't it?

I should look at things before asking. I see what you mean. The cdc-wdm code is very similar, and should be fairly easy to adapt. Why didn't I just research that from the start? Well, you learn more from doing such mistakes ;-)

There is one fundamental design issue which worries me though: cdc-wdm doesn't support multiple simultaneous readers/writers. This is sort of a blocker for my use case, as I will need to keep a reader/writer for the driver internal wwan management at all times. So two simultaneous clients are necessary to actually have something available for userspace at all.

Are there any reasons for this choice, and do you think it's feasible changing it without destroying the advantage of the well tested code? I seem to remember that cdc-wdm allowed simultaneous reading/writing in the past, but this changed somewhere between 2.6.32 and 3.0. I have an Ericsson modem with two such AT command speaking interfaces, and I use a simple shell script to configure it. At one point I had to switch from using /dev/cdc-wdm0 to /dev/ttyACM0 because the former started hanging on constructs like this:

    while read x; do
    case "$x" in
         foo)
              echo -e "AT+bar\r" >/dev/cdc-wdm0
              ;;
         ...
        esac
    done </dev/cdc-wdm0

This used to work with 2.6.32, but that might have been just pure luck? Anyway, that change really made cdc-wdm much less usable for me, and that sort of proves that supporting simultaneous read/write would be an improvement even for the existing supported devices.

And then there are a couple of minor issues which I believe needs sorting out. If I understand the WDM spec correctly (without bothering to actually read if, of course), then it only defines the interface but not the protocol. Exactly like the embedded CDC Ethernet command interface. So I have the Ericsson modem which which speaks an AT command protocol, of course with a number of vendor specific AT commands included. And then I have the Huawei modem which speaks QMI. Just mapping these to a number of /dev/cdc-wdmX interfaces isn't going to help user applications much. They need to be told *what* protocol to use on the character device. And the driver should know this, either by detection or maybe best: vid/pid based tables and sane fallbacks.

I'm not sure this will do (if the latter was changed to a cdc-wdmX device):

bjorn@nemi:~$ grep . /sys/class/usb/cdc-wdm0/device/*
/sys/class/usb/cdc-wdm0/device/bAlternateSetting: 0
/sys/class/usb/cdc-wdm0/device/bInterfaceClass:02
/sys/class/usb/cdc-wdm0/device/bInterfaceNumber:05
/sys/class/usb/cdc-wdm0/device/bInterfaceProtocol:01
/sys/class/usb/cdc-wdm0/device/bInterfaceSubClass:09
/sys/class/usb/cdc-wdm0/device/bNumEndpoints:01
/sys/class/usb/cdc-wdm0/device/interface:Ericsson F3507g Mobile Broadband Minicard Device Management
/sys/class/usb/cdc-wdm0/device/modalias:usb:v0BDBp1900d0000dc02dsc00dp00ic02isc09ip01
/sys/class/usb/cdc-wdm0/device/supports_autosuspend:1
/sys/class/usb/cdc-wdm0/device/uevent:DEVTYPE=usb_interface
/sys/class/usb/cdc-wdm0/device/uevent:DRIVER=cdc_wdm
/sys/class/usb/cdc-wdm0/device/uevent:DEVICE=/proc/bus/usb/002/056
/sys/class/usb/cdc-wdm0/device/uevent:PRODUCT=bdb/1900/0
/sys/class/usb/cdc-wdm0/device/uevent:TYPE=2/0/0
/sys/class/usb/cdc-wdm0/device/uevent:INTERFACE=2/9/1
/sys/class/usb/cdc-wdm0/device/uevent:MODALIAS=usb:v0BDBp1900d0000dc02dsc00dp00ic02isc09ip01
bjorn@canardo:~$ grep . /sys/class/cdc_enc/cdc-enc0/device/*
/sys/class/cdc_enc/cdc-enc0/device/bAlternateSetting: 0
/sys/class/cdc_enc/cdc-enc0/device/bInterfaceClass:ff
/sys/class/cdc_enc/cdc-enc0/device/bInterfaceNumber:03
/sys/class/cdc_enc/cdc-enc0/device/bInterfaceProtocol:09
/sys/class/cdc_enc/cdc-enc0/device/bInterfaceSubClass:01
/sys/class/cdc_enc/cdc-enc0/device/bNumEndpoints:01
/sys/class/cdc_enc/cdc-enc0/device/modalias:usb:v12D1p1506d0000dc00dsc00dp00icFFisc01ip09
/sys/class/cdc_enc/cdc-enc0/device/supports_autosuspend:1
/sys/class/cdc_enc/cdc-enc0/device/uevent:DEVTYPE=usb_interface
/sys/class/cdc_enc/cdc-enc0/device/uevent:DRIVER=qmi_wwan
/sys/class/cdc_enc/cdc-enc0/device/uevent:DEVICE=/proc/bus/usb/001/020
/sys/class/cdc_enc/cdc-enc0/device/uevent:PRODUCT=12d1/1506/0
/sys/class/cdc_enc/cdc-enc0/device/uevent:TYPE=0/0/0
/sys/class/cdc_enc/cdc-enc0/device/uevent:INTERFACE=255/1/9
/sys/class/cdc_enc/cdc-enc0/device/uevent:MODALIAS=usb:v12D1p1506d0000dc00dsc00dp00icFFisc01ip09

So my proposal have been something like a "protocol" attribute:

bjorn@canardo:~$ grep . /sys/class/cdc_enc/cdc-enc0/*
/sys/class/cdc_enc/cdc-enc0/dev:250:0
/sys/class/cdc_enc/cdc-enc0/protocol:qmi
/sys/class/cdc_enc/cdc-enc0/uevent:MAJOR=250
/sys/class/cdc_enc/cdc-enc0/uevent:MINOR=0
/sys/class/cdc_enc/cdc-enc0/uevent:DEVNAME=cdc-enc0
bjorn@nemi:~$ grep . /sys/class/usb/cdc-wdm0/*
/sys/class/usb/cdc-wdm0/dev:180:0
/sys/class/usb/cdc-wdm0/uevent:MAJOR=180
/sys/class/usb/cdc-wdm0/uevent:MINOR=0
/sys/class/usb/cdc-wdm0/uevent:DEVNAME=cdc-wdm0

Do you think it would be possible to add that (or similar meta data) to the cdc-wdmX devices? Maybe letting it default to "AT"? Or "unknown"? Any thoughts on this? How do actual user applications deal with this?

Bjørn

#10 lore raw

Re: [PATCH v2 2/3] net: usb: cdc_enc: New driver exposing USB CDC encapsulated protocols

In reply to a message not in the archive

Am Sonntag, 15. Januar 2012, 20:52:38 schrieb Bjørn Mork:

Quoted 6 lines

There is one fundamental design issue which worries me though: cdc-wdm doesn't support multiple simultaneous readers/writers. This is sort of a blocker for my use case, as I will need to keep a reader/writer for the driver internal wwan management at all times. So two simultaneous clients are necessary to actually have something available for userspace at all.

What exactly do you need? The ability to write while another task is reading?

Quoted 1 line

Are there any reasons for this choice, and do you think it's feasible

Easier to get the locking right.

Quoted 3 lines

changing it without destroying the advantage of the well tested code? I seem to remember that cdc-wdm allowed simultaneous reading/writing in the past, but this changed somewhere between 2.6.32 and 3.0. I have an

There might have been a locking bug which was easy to fix this way.

Quoted 15 lines

Ericsson modem with two such AT command speaking interfaces, and I use a simple shell script to configure it. At one point I had to switch from using /dev/cdc-wdm0 to /dev/ttyACM0 because the former started hanging on constructs like this:

    while read x; do
    case "$x" in
         foo)
              echo -e "AT+bar\r" >/dev/cdc-wdm0
              ;;
         ...
        esac
    done </dev/cdc-wdm0
Quoted 4 lines

This used to work with 2.6.32, but that might have been just pure luck? Anyway, that change really made cdc-wdm much less usable for me, and that sort of proves that supporting simultaneous read/write would be an improvement even for the existing supported devices.

Then feel free to add it, just beware of deadlocks.

Quoted 11 lines

And then there are a couple of minor issues which I believe needs sorting out. If I understand the WDM spec correctly (without bothering to actually read if, of course), then it only defines the interface but not the protocol. Exactly like the embedded CDC Ethernet command interface. So I have the Ericsson modem which which speaks an AT command protocol, of course with a number of vendor specific AT commands included. And then I have the Huawei modem which speaks QMI. Just mapping these to a number of /dev/cdc-wdmX interfaces isn't going to help user applications much. They need to be told *what* protocol to use on the character device. And the driver should know this, either by detection or maybe best: vid/pid based tables and sane fallbacks.

I see.

Quoted 3 lines

Do you think it would be possible to add that (or similar meta data) to the cdc-wdmX devices? Maybe letting it default to "AT"? Or "unknown"? Any thoughts on this? How do actual user applications deal with this?

Well, you need a pointer at the correct "control" interface anyway. Wouldn't you better put the "protocol" attribute there?

Regards
Oliver
--
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