4 * Copyright (C) ST-Ericsson 2010-2012
5 * Contact: Alexey Orishko <alexey.orishko@stericsson.com>
6 * Original author: Hans Petter Selasky <hans.petter.selasky@stericsson.com>
8 * USB Host Driver for Network Control Model (NCM)
9 * http://www.usb.org/developers/devclass_docs/NCM10.zip
11 * The NCM encoding, decoding and initialization logic
12 * derives from FreeBSD 8.x. if_cdce.c and if_cdcereg.h
14 * This software is available to you under a choice of one of two
15 * licenses. You may choose this file to be licensed under the terms
16 * of the GNU General Public License (GPL) Version 2 or the 2-clause
17 * BSD license listed below:
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #include <linux/module.h>
42 #include <linux/init.h>
43 #include <linux/netdevice.h>
44 #include <linux/ctype.h>
45 #include <linux/ethtool.h>
46 #include <linux/workqueue.h>
47 #include <linux/mii.h>
48 #include <linux/crc32.h>
49 #include <linux/usb.h>
50 #include <linux/hrtimer.h>
51 #include <asm/uaccess.h>
53 #include <linux/usb/usbnet.h>
54 #include <linux/usb/cdc.h>
55 #include <linux/usb/cdc_ncm.h>
57 #define DRIVER_VERSION "14-Mar-2012"
59 #ifdef CONFIG_USB_NET_CDC_MBIM
60 static int prefer_mbim
= true;
62 static int prefer_mbim
= false;
64 module_param(prefer_mbim
, bool, S_IRUGO
| S_IWUSR
);
65 MODULE_PARM_DESC(prefer_mbim
, "Prefer MBIM setting on dual NCM/MBIM functions");
67 static void cdc_ncm_txpath_bh(unsigned long param
);
68 static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx
*ctx
);
69 static enum hrtimer_restart
cdc_ncm_tx_timer_cb(struct hrtimer
*hr_timer
);
70 static struct usb_driver cdc_ncm_driver
;
73 cdc_ncm_get_drvinfo(struct net_device
*net
, struct ethtool_drvinfo
*info
)
75 struct usbnet
*dev
= netdev_priv(net
);
77 strncpy(info
->driver
, dev
->driver_name
, sizeof(info
->driver
));
78 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
));
79 strncpy(info
->fw_version
, dev
->driver_info
->description
,
80 sizeof(info
->fw_version
));
81 usb_make_path(dev
->udev
, info
->bus_info
, sizeof(info
->bus_info
));
84 static u8
cdc_ncm_setup(struct cdc_ncm_ctx
*ctx
)
91 u16 ntb_fmt_supported
;
95 iface_no
= ctx
->control
->cur_altsetting
->desc
.bInterfaceNumber
;
97 err
= usb_control_msg(ctx
->udev
,
98 usb_rcvctrlpipe(ctx
->udev
, 0),
99 USB_CDC_GET_NTB_PARAMETERS
,
100 USB_TYPE_CLASS
| USB_DIR_IN
101 | USB_RECIP_INTERFACE
,
102 0, iface_no
, &ctx
->ncm_parm
,
103 sizeof(ctx
->ncm_parm
), 10000);
105 pr_debug("failed GET_NTB_PARAMETERS\n");
109 /* read correct set of parameters according to device mode */
110 ctx
->rx_max
= le32_to_cpu(ctx
->ncm_parm
.dwNtbInMaxSize
);
111 ctx
->tx_max
= le32_to_cpu(ctx
->ncm_parm
.dwNtbOutMaxSize
);
112 ctx
->tx_remainder
= le16_to_cpu(ctx
->ncm_parm
.wNdpOutPayloadRemainder
);
113 ctx
->tx_modulus
= le16_to_cpu(ctx
->ncm_parm
.wNdpOutDivisor
);
114 ctx
->tx_ndp_modulus
= le16_to_cpu(ctx
->ncm_parm
.wNdpOutAlignment
);
115 /* devices prior to NCM Errata shall set this field to zero */
116 ctx
->tx_max_datagrams
= le16_to_cpu(ctx
->ncm_parm
.wNtbOutMaxDatagrams
);
117 ntb_fmt_supported
= le16_to_cpu(ctx
->ncm_parm
.bmNtbFormatsSupported
);
120 min_dgram_size
= CDC_NCM_MIN_DATAGRAM_SIZE
;
121 min_hdr_size
= CDC_NCM_MIN_HDR_SIZE
;
122 if (ctx
->mbim_desc
!= NULL
) {
123 flags
= ctx
->mbim_desc
->bmNetworkCapabilities
;
125 min_dgram_size
= CDC_MBIM_MIN_DATAGRAM_SIZE
;
127 } else if (ctx
->func_desc
!= NULL
) {
128 flags
= ctx
->func_desc
->bmNetworkCapabilities
;
133 pr_debug("dwNtbInMaxSize=%u dwNtbOutMaxSize=%u "
134 "wNdpOutPayloadRemainder=%u wNdpOutDivisor=%u "
135 "wNdpOutAlignment=%u wNtbOutMaxDatagrams=%u flags=0x%x\n",
136 ctx
->rx_max
, ctx
->tx_max
, ctx
->tx_remainder
, ctx
->tx_modulus
,
137 ctx
->tx_ndp_modulus
, ctx
->tx_max_datagrams
, flags
);
139 /* max count of tx datagrams */
140 if ((ctx
->tx_max_datagrams
== 0) ||
141 (ctx
->tx_max_datagrams
> CDC_NCM_DPT_DATAGRAMS_MAX
))
142 ctx
->tx_max_datagrams
= CDC_NCM_DPT_DATAGRAMS_MAX
;
144 /* verify maximum size of received NTB in bytes */
145 if (ctx
->rx_max
< USB_CDC_NCM_NTB_MIN_IN_SIZE
) {
146 pr_debug("Using min receive length=%d\n",
147 USB_CDC_NCM_NTB_MIN_IN_SIZE
);
148 ctx
->rx_max
= USB_CDC_NCM_NTB_MIN_IN_SIZE
;
151 if (ctx
->rx_max
> CDC_NCM_NTB_MAX_SIZE_RX
) {
152 pr_debug("Using default maximum receive length=%d\n",
153 CDC_NCM_NTB_MAX_SIZE_RX
);
154 ctx
->rx_max
= CDC_NCM_NTB_MAX_SIZE_RX
;
157 /* inform device about NTB input size changes */
158 if (ctx
->rx_max
!= le32_to_cpu(ctx
->ncm_parm
.dwNtbInMaxSize
)) {
159 __le32
*dwNtbInMaxSize
;
161 dwNtbInMaxSize
= kzalloc(sizeof(*dwNtbInMaxSize
), GFP_KERNEL
);
162 if (!dwNtbInMaxSize
) {
166 *dwNtbInMaxSize
= cpu_to_le32(ctx
->rx_max
);
167 err
= usb_control_msg(ctx
->udev
,
168 usb_sndctrlpipe(ctx
->udev
, 0),
169 USB_CDC_SET_NTB_INPUT_SIZE
,
170 USB_TYPE_CLASS
| USB_DIR_OUT
171 | USB_RECIP_INTERFACE
,
172 0, iface_no
, dwNtbInMaxSize
, 4, 1000);
173 kfree(dwNtbInMaxSize
);
176 pr_debug("Setting NTB Input Size failed\n");
179 /* verify maximum size of transmitted NTB in bytes */
181 (min_hdr_size
+ min_dgram_size
)) ||
182 (ctx
->tx_max
> CDC_NCM_NTB_MAX_SIZE_TX
)) {
183 pr_debug("Using default maximum transmit length=%d\n",
184 CDC_NCM_NTB_MAX_SIZE_TX
);
185 ctx
->tx_max
= CDC_NCM_NTB_MAX_SIZE_TX
;
189 * verify that the structure alignment is:
191 * - not greater than the maximum transmit length
192 * - not less than four bytes
194 val
= ctx
->tx_ndp_modulus
;
196 if ((val
< USB_CDC_NCM_NDP_ALIGN_MIN_SIZE
) ||
197 (val
!= ((-val
) & val
)) || (val
>= ctx
->tx_max
)) {
198 pr_debug("Using default alignment: 4 bytes\n");
199 ctx
->tx_ndp_modulus
= USB_CDC_NCM_NDP_ALIGN_MIN_SIZE
;
203 * verify that the payload alignment is:
205 * - not greater than the maximum transmit length
206 * - not less than four bytes
208 val
= ctx
->tx_modulus
;
210 if ((val
< USB_CDC_NCM_NDP_ALIGN_MIN_SIZE
) ||
211 (val
!= ((-val
) & val
)) || (val
>= ctx
->tx_max
)) {
212 pr_debug("Using default transmit modulus: 4 bytes\n");
213 ctx
->tx_modulus
= USB_CDC_NCM_NDP_ALIGN_MIN_SIZE
;
216 /* verify the payload remainder */
217 if (ctx
->tx_remainder
>= ctx
->tx_modulus
) {
218 pr_debug("Using default transmit remainder: 0 bytes\n");
219 ctx
->tx_remainder
= 0;
222 /* adjust TX-remainder according to NCM specification. */
223 ctx
->tx_remainder
= ((ctx
->tx_remainder
- eth_hlen
) &
224 (ctx
->tx_modulus
- 1));
226 /* additional configuration */
229 if (flags
& USB_CDC_NCM_NCAP_CRC_MODE
) {
230 err
= usb_control_msg(ctx
->udev
, usb_sndctrlpipe(ctx
->udev
, 0),
231 USB_CDC_SET_CRC_MODE
,
232 USB_TYPE_CLASS
| USB_DIR_OUT
233 | USB_RECIP_INTERFACE
,
234 USB_CDC_NCM_CRC_NOT_APPENDED
,
235 iface_no
, NULL
, 0, 1000);
237 pr_debug("Setting CRC mode off failed\n");
240 /* set NTB format, if both formats are supported */
241 if (ntb_fmt_supported
& USB_CDC_NCM_NTH32_SIGN
) {
242 err
= usb_control_msg(ctx
->udev
, usb_sndctrlpipe(ctx
->udev
, 0),
243 USB_CDC_SET_NTB_FORMAT
, USB_TYPE_CLASS
244 | USB_DIR_OUT
| USB_RECIP_INTERFACE
,
245 USB_CDC_NCM_NTB16_FORMAT
,
246 iface_no
, NULL
, 0, 1000);
248 pr_debug("Setting NTB format to 16-bit failed\n");
251 ctx
->max_datagram_size
= min_dgram_size
;
253 /* set Max Datagram Size (MTU) */
254 if (flags
& USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE
) {
255 __le16
*max_datagram_size
;
257 if (ctx
->ether_desc
!= NULL
)
258 eth_max_sz
= le16_to_cpu(ctx
->ether_desc
->wMaxSegmentSize
);
259 else if (ctx
->mbim_desc
!= NULL
)
260 eth_max_sz
= le16_to_cpu(ctx
->mbim_desc
->wMaxSegmentSize
);
264 max_datagram_size
= kzalloc(sizeof(*max_datagram_size
),
266 if (!max_datagram_size
) {
271 err
= usb_control_msg(ctx
->udev
, usb_rcvctrlpipe(ctx
->udev
, 0),
272 USB_CDC_GET_MAX_DATAGRAM_SIZE
,
273 USB_TYPE_CLASS
| USB_DIR_IN
274 | USB_RECIP_INTERFACE
,
275 0, iface_no
, max_datagram_size
,
278 pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
281 ctx
->max_datagram_size
=
282 le16_to_cpu(*max_datagram_size
);
283 /* Check Eth descriptor value */
284 if (ctx
->max_datagram_size
> eth_max_sz
)
285 ctx
->max_datagram_size
= eth_max_sz
;
287 if (ctx
->max_datagram_size
> CDC_NCM_MAX_DATAGRAM_SIZE
)
288 ctx
->max_datagram_size
= CDC_NCM_MAX_DATAGRAM_SIZE
;
290 if (ctx
->max_datagram_size
< min_dgram_size
)
291 ctx
->max_datagram_size
= min_dgram_size
;
293 /* if value changed, update device */
294 if (ctx
->max_datagram_size
!=
295 le16_to_cpu(*max_datagram_size
)) {
296 err
= usb_control_msg(ctx
->udev
,
297 usb_sndctrlpipe(ctx
->udev
, 0),
298 USB_CDC_SET_MAX_DATAGRAM_SIZE
,
299 USB_TYPE_CLASS
| USB_DIR_OUT
300 | USB_RECIP_INTERFACE
,
302 iface_no
, max_datagram_size
,
305 pr_debug("SET_MAX_DGRAM_SIZE failed\n");
308 kfree(max_datagram_size
);
312 if (ctx
->netdev
->mtu
!= (ctx
->max_datagram_size
- eth_hlen
))
313 ctx
->netdev
->mtu
= ctx
->max_datagram_size
- eth_hlen
;
319 cdc_ncm_find_endpoints(struct cdc_ncm_ctx
*ctx
, struct usb_interface
*intf
)
321 struct usb_host_endpoint
*e
;
324 for (ep
= 0; ep
< intf
->cur_altsetting
->desc
.bNumEndpoints
; ep
++) {
326 e
= intf
->cur_altsetting
->endpoint
+ ep
;
327 switch (e
->desc
.bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) {
328 case USB_ENDPOINT_XFER_INT
:
329 if (usb_endpoint_dir_in(&e
->desc
)) {
330 if (ctx
->status_ep
== NULL
)
335 case USB_ENDPOINT_XFER_BULK
:
336 if (usb_endpoint_dir_in(&e
->desc
)) {
337 if (ctx
->in_ep
== NULL
)
340 if (ctx
->out_ep
== NULL
)
351 static void cdc_ncm_free(struct cdc_ncm_ctx
*ctx
)
356 if (ctx
->tx_rem_skb
!= NULL
) {
357 dev_kfree_skb_any(ctx
->tx_rem_skb
);
358 ctx
->tx_rem_skb
= NULL
;
361 if (ctx
->tx_curr_skb
!= NULL
) {
362 dev_kfree_skb_any(ctx
->tx_curr_skb
);
363 ctx
->tx_curr_skb
= NULL
;
369 static const struct ethtool_ops cdc_ncm_ethtool_ops
= {
370 .get_drvinfo
= cdc_ncm_get_drvinfo
,
372 .get_settings
= usbnet_get_settings
,
373 .set_settings
= usbnet_set_settings
,
374 .nway_reset
= usbnet_nway_reset
,
375 .get_link
= usbnet_get_link
,
377 .get_msglevel
= usbnet_get_msglevel
,
378 .set_msglevel
= usbnet_set_msglevel
,
381 int cdc_ncm_bind_common(struct usbnet
*dev
, struct usb_interface
*intf
, u8 data_altsetting
)
383 struct cdc_ncm_ctx
*ctx
;
384 struct usb_driver
*driver
;
390 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
394 hrtimer_init(&ctx
->tx_timer
, CLOCK_MONOTONIC
, HRTIMER_MODE_REL
);
395 ctx
->tx_timer
.function
= &cdc_ncm_tx_timer_cb
;
396 ctx
->bh
.data
= (unsigned long)ctx
;
397 ctx
->bh
.func
= cdc_ncm_txpath_bh
;
398 atomic_set(&ctx
->stop
, 0);
399 spin_lock_init(&ctx
->mtx
);
400 ctx
->netdev
= dev
->net
;
402 /* store ctx pointer in device data field */
403 dev
->data
[0] = (unsigned long)ctx
;
405 /* get some pointers */
406 driver
= driver_of(intf
);
407 buf
= intf
->cur_altsetting
->extra
;
408 len
= intf
->cur_altsetting
->extralen
;
410 ctx
->udev
= dev
->udev
;
413 /* parse through descriptors associated with control interface */
414 while ((len
> 0) && (buf
[0] > 2) && (buf
[0] <= len
)) {
416 if (buf
[1] != USB_DT_CS_INTERFACE
)
420 case USB_CDC_UNION_TYPE
:
421 if (buf
[0] < sizeof(*(ctx
->union_desc
)))
425 (const struct usb_cdc_union_desc
*)buf
;
427 ctx
->control
= usb_ifnum_to_if(dev
->udev
,
428 ctx
->union_desc
->bMasterInterface0
);
429 ctx
->data
= usb_ifnum_to_if(dev
->udev
,
430 ctx
->union_desc
->bSlaveInterface0
);
433 case USB_CDC_ETHERNET_TYPE
:
434 if (buf
[0] < sizeof(*(ctx
->ether_desc
)))
438 (const struct usb_cdc_ether_desc
*)buf
;
440 le16_to_cpu(ctx
->ether_desc
->wMaxSegmentSize
);
442 if (dev
->hard_mtu
< CDC_NCM_MIN_DATAGRAM_SIZE
)
443 dev
->hard_mtu
= CDC_NCM_MIN_DATAGRAM_SIZE
;
444 else if (dev
->hard_mtu
> CDC_NCM_MAX_DATAGRAM_SIZE
)
445 dev
->hard_mtu
= CDC_NCM_MAX_DATAGRAM_SIZE
;
448 case USB_CDC_NCM_TYPE
:
449 if (buf
[0] < sizeof(*(ctx
->func_desc
)))
452 ctx
->func_desc
= (const struct usb_cdc_ncm_desc
*)buf
;
455 case USB_CDC_MBIM_TYPE
:
456 if (buf
[0] < sizeof(*(ctx
->mbim_desc
)))
459 ctx
->mbim_desc
= (const struct usb_cdc_mbim_desc
*)buf
;
466 /* advance to next descriptor */
472 /* some buggy devices have an IAD but no CDC Union */
473 if (!ctx
->union_desc
&& intf
->intf_assoc
&& intf
->intf_assoc
->bInterfaceCount
== 2) {
475 ctx
->data
= usb_ifnum_to_if(dev
->udev
, intf
->cur_altsetting
->desc
.bInterfaceNumber
+ 1);
476 dev_dbg(&intf
->dev
, "CDC Union missing - got slave from IAD\n");
479 /* check if we got everything */
480 if ((ctx
->control
== NULL
) || (ctx
->data
== NULL
) ||
481 ((!ctx
->mbim_desc
) && ((ctx
->ether_desc
== NULL
) || (ctx
->control
!= intf
))))
484 /* claim data interface, if different from control */
485 if (ctx
->data
!= ctx
->control
) {
486 temp
= usb_driver_claim_interface(driver
, ctx
->data
, dev
);
491 iface_no
= ctx
->data
->cur_altsetting
->desc
.bInterfaceNumber
;
493 /* reset data interface */
494 temp
= usb_set_interface(dev
->udev
, iface_no
, 0);
498 /* initialize data interface */
499 if (cdc_ncm_setup(ctx
))
502 /* configure data interface */
503 temp
= usb_set_interface(dev
->udev
, iface_no
, data_altsetting
);
507 cdc_ncm_find_endpoints(ctx
, ctx
->data
);
508 cdc_ncm_find_endpoints(ctx
, ctx
->control
);
510 if ((ctx
->in_ep
== NULL
) || (ctx
->out_ep
== NULL
) ||
511 (ctx
->status_ep
== NULL
))
514 dev
->net
->ethtool_ops
= &cdc_ncm_ethtool_ops
;
516 usb_set_intfdata(ctx
->data
, dev
);
517 usb_set_intfdata(ctx
->control
, dev
);
518 usb_set_intfdata(ctx
->intf
, dev
);
520 if (ctx
->ether_desc
) {
521 temp
= usbnet_get_ethernet_addr(dev
, ctx
->ether_desc
->iMACAddress
);
524 dev_info(&dev
->udev
->dev
, "MAC-Address: %pM\n", dev
->net
->dev_addr
);
528 dev
->in
= usb_rcvbulkpipe(dev
->udev
,
529 ctx
->in_ep
->desc
.bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
);
530 dev
->out
= usb_sndbulkpipe(dev
->udev
,
531 ctx
->out_ep
->desc
.bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
);
532 dev
->status
= ctx
->status_ep
;
533 dev
->rx_urb_size
= ctx
->rx_max
;
535 ctx
->tx_speed
= ctx
->rx_speed
= 0;
539 usb_set_intfdata(ctx
->control
, NULL
);
540 usb_set_intfdata(ctx
->data
, NULL
);
541 if (ctx
->data
!= ctx
->control
)
542 usb_driver_release_interface(driver
, ctx
->data
);
544 cdc_ncm_free((struct cdc_ncm_ctx
*)dev
->data
[0]);
546 dev_info(&dev
->udev
->dev
, "bind() failure\n");
549 EXPORT_SYMBOL_GPL(cdc_ncm_bind_common
);
551 void cdc_ncm_unbind(struct usbnet
*dev
, struct usb_interface
*intf
)
553 struct cdc_ncm_ctx
*ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
554 struct usb_driver
*driver
= driver_of(intf
);
557 return; /* no setup */
559 atomic_set(&ctx
->stop
, 1);
561 if (hrtimer_active(&ctx
->tx_timer
))
562 hrtimer_cancel(&ctx
->tx_timer
);
564 tasklet_kill(&ctx
->bh
);
566 /* handle devices with combined control and data interface */
567 if (ctx
->control
== ctx
->data
)
570 /* disconnect master --> disconnect slave */
571 if (intf
== ctx
->control
&& ctx
->data
) {
572 usb_set_intfdata(ctx
->data
, NULL
);
573 usb_driver_release_interface(driver
, ctx
->data
);
576 } else if (intf
== ctx
->data
&& ctx
->control
) {
577 usb_set_intfdata(ctx
->control
, NULL
);
578 usb_driver_release_interface(driver
, ctx
->control
);
582 usb_set_intfdata(ctx
->intf
, NULL
);
585 EXPORT_SYMBOL_GPL(cdc_ncm_unbind
);
587 /* Select the MBIM altsetting iff it is preferred and available,
588 * returning the number of the corresponding data interface altsetting
590 u8
cdc_ncm_select_altsetting(struct usbnet
*dev
, struct usb_interface
*intf
)
592 struct usb_host_interface
*alt
;
594 /* The MBIM spec defines a NCM compatible default altsetting,
595 * which we may have matched:
597 * "Functions that implement both NCM 1.0 and MBIM (an
598 * “NCM/MBIM function”) according to this recommendation
599 * shall provide two alternate settings for the
600 * Communication Interface. Alternate setting 0, and the
601 * associated class and endpoint descriptors, shall be
602 * constructed according to the rules given for the
603 * Communication Interface in section 5 of [USBNCM10].
604 * Alternate setting 1, and the associated class and
605 * endpoint descriptors, shall be constructed according to
606 * the rules given in section 6 (USB Device Model) of this
609 if (prefer_mbim
&& intf
->num_altsetting
== 2) {
610 alt
= usb_altnum_to_altsetting(intf
, CDC_NCM_COMM_ALTSETTING_MBIM
);
611 if (alt
&& cdc_ncm_comm_intf_is_mbim(alt
) &&
612 !usb_set_interface(dev
->udev
,
613 intf
->cur_altsetting
->desc
.bInterfaceNumber
,
614 CDC_NCM_COMM_ALTSETTING_MBIM
))
615 return CDC_NCM_DATA_ALTSETTING_MBIM
;
617 return CDC_NCM_DATA_ALTSETTING_NCM
;
619 EXPORT_SYMBOL_GPL(cdc_ncm_select_altsetting
);
621 static int cdc_ncm_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
625 /* MBIM backwards compatible function? */
626 cdc_ncm_select_altsetting(dev
, intf
);
627 if (cdc_ncm_comm_intf_is_mbim(intf
->cur_altsetting
))
630 /* NCM data altsetting is always 1 */
631 ret
= cdc_ncm_bind_common(dev
, intf
, 1);
634 * We should get an event when network connection is "connected" or
635 * "disconnected". Set network connection in "disconnected" state
636 * (carrier is OFF) during attach, so the IP network stack does not
637 * start IPv6 negotiation and more.
639 netif_carrier_off(dev
->net
);
643 static void cdc_ncm_align_tail(struct sk_buff
*skb
, size_t modulus
, size_t remainder
, size_t max
)
645 size_t align
= ALIGN(skb
->len
, modulus
) - skb
->len
+ remainder
;
647 if (skb
->len
+ align
> max
)
648 align
= max
- skb
->len
;
649 if (align
&& skb_tailroom(skb
) >= align
)
650 memset(skb_put(skb
, align
), 0, align
);
653 /* return a pointer to a valid struct usb_cdc_ncm_ndp16 of type sign, possibly
654 * allocating a new one within skb
656 static struct usb_cdc_ncm_ndp16
*cdc_ncm_ndp(struct cdc_ncm_ctx
*ctx
, struct sk_buff
*skb
, __le32 sign
, size_t reserve
)
658 struct usb_cdc_ncm_ndp16
*ndp16
= NULL
;
659 struct usb_cdc_ncm_nth16
*nth16
= (void *)skb
->data
;
660 size_t ndpoffset
= le16_to_cpu(nth16
->wNdpIndex
);
662 /* follow the chain of NDPs, looking for a match */
664 ndp16
= (struct usb_cdc_ncm_ndp16
*)(skb
->data
+ ndpoffset
);
665 if (ndp16
->dwSignature
== sign
)
667 ndpoffset
= le16_to_cpu(ndp16
->wNextNdpIndex
);
671 cdc_ncm_align_tail(skb
, ctx
->tx_ndp_modulus
, 0, ctx
->tx_max
);
673 /* verify that there is room for the NDP and the datagram (reserve) */
674 if ((ctx
->tx_max
- skb
->len
- reserve
) < CDC_NCM_NDP_SIZE
)
679 ndp16
->wNextNdpIndex
= cpu_to_le16(skb
->len
);
681 nth16
->wNdpIndex
= cpu_to_le16(skb
->len
);
683 /* push a new empty NDP */
684 ndp16
= (struct usb_cdc_ncm_ndp16
*)memset(skb_put(skb
, CDC_NCM_NDP_SIZE
), 0, CDC_NCM_NDP_SIZE
);
685 ndp16
->dwSignature
= sign
;
686 ndp16
->wLength
= cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp16
) + sizeof(struct usb_cdc_ncm_dpe16
));
691 cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx
*ctx
, struct sk_buff
*skb
, __le32 sign
)
693 struct usb_cdc_ncm_nth16
*nth16
;
694 struct usb_cdc_ncm_ndp16
*ndp16
;
695 struct sk_buff
*skb_out
;
696 u16 n
= 0, index
, ndplen
;
699 /* if there is a remaining skb, it gets priority */
701 swap(skb
, ctx
->tx_rem_skb
);
702 swap(sign
, ctx
->tx_rem_sign
);
707 /* check if we are resuming an OUT skb */
708 skb_out
= ctx
->tx_curr_skb
;
710 /* allocate a new OUT skb */
712 skb_out
= alloc_skb((ctx
->tx_max
+ 1), GFP_ATOMIC
);
713 if (skb_out
== NULL
) {
715 dev_kfree_skb_any(skb
);
716 ctx
->netdev
->stats
.tx_dropped
++;
720 /* fill out the initial 16-bit NTB header */
721 nth16
= (struct usb_cdc_ncm_nth16
*)memset(skb_put(skb_out
, sizeof(struct usb_cdc_ncm_nth16
)), 0, sizeof(struct usb_cdc_ncm_nth16
));
722 nth16
->dwSignature
= cpu_to_le32(USB_CDC_NCM_NTH16_SIGN
);
723 nth16
->wHeaderLength
= cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16
));
724 nth16
->wSequence
= cpu_to_le16(ctx
->tx_seq
++);
726 /* count total number of frames in this NTB */
727 ctx
->tx_curr_frame_num
= 0;
730 for (n
= ctx
->tx_curr_frame_num
; n
< ctx
->tx_max_datagrams
; n
++) {
731 /* send any remaining skb first */
733 skb
= ctx
->tx_rem_skb
;
734 sign
= ctx
->tx_rem_sign
;
735 ctx
->tx_rem_skb
= NULL
;
737 /* check for end of skb */
742 /* get the appropriate NDP for this skb */
743 ndp16
= cdc_ncm_ndp(ctx
, skb_out
, sign
, skb
->len
+ ctx
->tx_modulus
+ ctx
->tx_remainder
);
745 /* align beginning of next frame */
746 cdc_ncm_align_tail(skb_out
, ctx
->tx_modulus
, ctx
->tx_remainder
, ctx
->tx_max
);
748 /* check if we had enough room left for both NDP and frame */
749 if (!ndp16
|| skb_out
->len
+ skb
->len
> ctx
->tx_max
) {
751 /* won't fit, MTU problem? */
752 dev_kfree_skb_any(skb
);
754 ctx
->netdev
->stats
.tx_dropped
++;
756 /* no room for skb - store for later */
757 if (ctx
->tx_rem_skb
!= NULL
) {
758 dev_kfree_skb_any(ctx
->tx_rem_skb
);
759 ctx
->netdev
->stats
.tx_dropped
++;
761 ctx
->tx_rem_skb
= skb
;
762 ctx
->tx_rem_sign
= sign
;
769 /* calculate frame number withing this NDP */
770 ndplen
= le16_to_cpu(ndp16
->wLength
);
771 index
= (ndplen
- sizeof(struct usb_cdc_ncm_ndp16
)) / sizeof(struct usb_cdc_ncm_dpe16
) - 1;
773 /* OK, add this skb */
774 ndp16
->dpe16
[index
].wDatagramLength
= cpu_to_le16(skb
->len
);
775 ndp16
->dpe16
[index
].wDatagramIndex
= cpu_to_le16(skb_out
->len
);
776 ndp16
->wLength
= cpu_to_le16(ndplen
+ sizeof(struct usb_cdc_ncm_dpe16
));
777 memcpy(skb_put(skb_out
, skb
->len
), skb
->data
, skb
->len
);
778 dev_kfree_skb_any(skb
);
781 /* send now if this NDP is full */
782 if (index
>= CDC_NCM_DPT_DATAGRAMS_MAX
) {
788 /* free up any dangling skb */
790 dev_kfree_skb_any(skb
);
792 ctx
->netdev
->stats
.tx_dropped
++;
795 ctx
->tx_curr_frame_num
= n
;
798 /* wait for more frames */
800 ctx
->tx_curr_skb
= skb_out
;
803 } else if ((n
< ctx
->tx_max_datagrams
) && (ready2send
== 0)) {
804 /* wait for more frames */
806 ctx
->tx_curr_skb
= skb_out
;
807 /* set the pending count */
808 if (n
< CDC_NCM_RESTART_TIMER_DATAGRAM_CNT
)
809 ctx
->tx_timer_pending
= CDC_NCM_TIMER_PENDING_CNT
;
814 /* variables will be reset at next call */
818 * If collected data size is less or equal CDC_NCM_MIN_TX_PKT bytes,
819 * we send buffers as it is. If we get more data, it would be more
820 * efficient for USB HS mobile device with DMA engine to receive a full
821 * size NTB, than canceling DMA transfer and receiving a short packet.
823 if (skb_out
->len
> CDC_NCM_MIN_TX_PKT
)
824 /* final zero padding */
825 memset(skb_put(skb_out
, ctx
->tx_max
- skb_out
->len
), 0, ctx
->tx_max
- skb_out
->len
);
827 /* do we need to prevent a ZLP? */
828 if (((skb_out
->len
% le16_to_cpu(ctx
->out_ep
->desc
.wMaxPacketSize
)) == 0) &&
829 (skb_out
->len
< le32_to_cpu(ctx
->ncm_parm
.dwNtbOutMaxSize
)) && skb_tailroom(skb_out
))
830 *skb_put(skb_out
, 1) = 0; /* force short packet */
832 /* set final frame length */
833 nth16
= (struct usb_cdc_ncm_nth16
*)skb_out
->data
;
834 nth16
->wBlockLength
= cpu_to_le16(skb_out
->len
);
837 ctx
->tx_curr_skb
= NULL
;
838 ctx
->netdev
->stats
.tx_packets
+= ctx
->tx_curr_frame_num
;
842 /* Start timer, if there is a remaining skb */
843 if (ctx
->tx_curr_skb
!= NULL
)
844 cdc_ncm_tx_timeout_start(ctx
);
847 EXPORT_SYMBOL_GPL(cdc_ncm_fill_tx_frame
);
849 static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx
*ctx
)
851 /* start timer, if not already started */
852 if (!(hrtimer_active(&ctx
->tx_timer
) || atomic_read(&ctx
->stop
)))
853 hrtimer_start(&ctx
->tx_timer
,
854 ktime_set(0, CDC_NCM_TIMER_INTERVAL
),
858 static enum hrtimer_restart
cdc_ncm_tx_timer_cb(struct hrtimer
*timer
)
860 struct cdc_ncm_ctx
*ctx
=
861 container_of(timer
, struct cdc_ncm_ctx
, tx_timer
);
863 if (!atomic_read(&ctx
->stop
))
864 tasklet_schedule(&ctx
->bh
);
865 return HRTIMER_NORESTART
;
868 static void cdc_ncm_txpath_bh(unsigned long param
)
870 struct cdc_ncm_ctx
*ctx
= (struct cdc_ncm_ctx
*)param
;
872 spin_lock_bh(&ctx
->mtx
);
873 if (ctx
->tx_timer_pending
!= 0) {
874 ctx
->tx_timer_pending
--;
875 cdc_ncm_tx_timeout_start(ctx
);
876 spin_unlock_bh(&ctx
->mtx
);
877 } else if (ctx
->netdev
!= NULL
) {
878 spin_unlock_bh(&ctx
->mtx
);
879 netif_tx_lock_bh(ctx
->netdev
);
880 usbnet_start_xmit(NULL
, ctx
->netdev
);
881 netif_tx_unlock_bh(ctx
->netdev
);
883 spin_unlock_bh(&ctx
->mtx
);
887 static struct sk_buff
*
888 cdc_ncm_tx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
, gfp_t flags
)
890 struct sk_buff
*skb_out
;
891 struct cdc_ncm_ctx
*ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
894 * The Ethernet API we are using does not support transmitting
895 * multiple Ethernet frames in a single call. This driver will
896 * accumulate multiple Ethernet frames and send out a larger
897 * USB frame when the USB buffer is full or when a single jiffies
903 spin_lock_bh(&ctx
->mtx
);
904 skb_out
= cdc_ncm_fill_tx_frame(ctx
, skb
, cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN
));
905 spin_unlock_bh(&ctx
->mtx
);
910 dev_kfree_skb_any(skb
);
915 /* verify NTB header and return offset of first NDP, or negative error */
916 int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx
*ctx
, struct sk_buff
*skb_in
)
918 struct usb_cdc_ncm_nth16
*nth16
;
925 if (skb_in
->len
< (sizeof(struct usb_cdc_ncm_nth16
) +
926 sizeof(struct usb_cdc_ncm_ndp16
))) {
927 pr_debug("frame too short\n");
931 nth16
= (struct usb_cdc_ncm_nth16
*)skb_in
->data
;
933 if (le32_to_cpu(nth16
->dwSignature
) != USB_CDC_NCM_NTH16_SIGN
) {
934 pr_debug("invalid NTH16 signature <%u>\n",
935 le32_to_cpu(nth16
->dwSignature
));
939 len
= le16_to_cpu(nth16
->wBlockLength
);
940 if (len
> ctx
->rx_max
) {
941 pr_debug("unsupported NTB block length %u/%u\n", len
,
946 if ((ctx
->rx_seq
+ 1) != le16_to_cpu(nth16
->wSequence
) &&
947 (ctx
->rx_seq
|| le16_to_cpu(nth16
->wSequence
)) &&
948 !((ctx
->rx_seq
== 0xffff) && !le16_to_cpu(nth16
->wSequence
))) {
949 pr_debug("sequence number glitch prev=%d curr=%d\n",
950 ctx
->rx_seq
, le16_to_cpu(nth16
->wSequence
));
952 ctx
->rx_seq
= le16_to_cpu(nth16
->wSequence
);
954 ret
= le16_to_cpu(nth16
->wNdpIndex
);
958 EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_nth16
);
960 /* verify NDP header and return number of datagrams, or negative error */
961 int cdc_ncm_rx_verify_ndp16(struct sk_buff
*skb_in
, int ndpoffset
)
963 struct usb_cdc_ncm_ndp16
*ndp16
;
966 if ((ndpoffset
+ sizeof(struct usb_cdc_ncm_ndp16
)) > skb_in
->len
) {
967 pr_debug("invalid NDP offset <%u>\n", ndpoffset
);
970 ndp16
= (struct usb_cdc_ncm_ndp16
*)(skb_in
->data
+ ndpoffset
);
972 if (le16_to_cpu(ndp16
->wLength
) < USB_CDC_NCM_NDP16_LENGTH_MIN
) {
973 pr_debug("invalid DPT16 length <%u>\n",
974 le32_to_cpu(ndp16
->dwSignature
));
978 ret
= ((le16_to_cpu(ndp16
->wLength
) -
979 sizeof(struct usb_cdc_ncm_ndp16
)) /
980 sizeof(struct usb_cdc_ncm_dpe16
));
981 ret
--; /* we process NDP entries except for the last one */
983 if ((sizeof(struct usb_cdc_ncm_ndp16
) + ret
* (sizeof(struct usb_cdc_ncm_dpe16
))) >
985 pr_debug("Invalid nframes = %d\n", ret
);
992 EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_ndp16
);
994 static int cdc_ncm_rx_fixup(struct usbnet
*dev
, struct sk_buff
*skb_in
)
997 struct cdc_ncm_ctx
*ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
1002 struct usb_cdc_ncm_ndp16
*ndp16
;
1003 struct usb_cdc_ncm_dpe16
*dpe16
;
1005 int loopcount
= 50; /* arbitrary max preventing infinite loop */
1007 ndpoffset
= cdc_ncm_rx_verify_nth16(ctx
, skb_in
);
1012 nframes
= cdc_ncm_rx_verify_ndp16(skb_in
, ndpoffset
);
1016 ndp16
= (struct usb_cdc_ncm_ndp16
*)(skb_in
->data
+ ndpoffset
);
1018 if (le32_to_cpu(ndp16
->dwSignature
) != USB_CDC_NCM_NDP16_NOCRC_SIGN
) {
1019 pr_debug("invalid DPT16 signature <%u>\n",
1020 le32_to_cpu(ndp16
->dwSignature
));
1023 dpe16
= ndp16
->dpe16
;
1025 for (x
= 0; x
< nframes
; x
++, dpe16
++) {
1026 offset
= le16_to_cpu(dpe16
->wDatagramIndex
);
1027 len
= le16_to_cpu(dpe16
->wDatagramLength
);
1031 * All entries after first NULL entry are to be ignored
1033 if ((offset
== 0) || (len
== 0)) {
1035 goto err_ndp
; /* empty NTB */
1039 /* sanity checking */
1040 if (((offset
+ len
) > skb_in
->len
) ||
1041 (len
> ctx
->rx_max
) || (len
< ETH_HLEN
)) {
1042 pr_debug("invalid frame detected (ignored)"
1043 "offset[%u]=%u, length=%u, skb=%p\n",
1044 x
, offset
, len
, skb_in
);
1050 skb
= skb_clone(skb_in
, GFP_ATOMIC
);
1054 skb
->data
= ((u8
*)skb_in
->data
) + offset
;
1055 skb_set_tail_pointer(skb
, len
);
1056 usbnet_skb_return(dev
, skb
);
1060 /* are there more NDPs to process? */
1061 ndpoffset
= le16_to_cpu(ndp16
->wNextNdpIndex
);
1062 if (ndpoffset
&& loopcount
--)
1071 cdc_ncm_speed_change(struct cdc_ncm_ctx
*ctx
,
1072 struct usb_cdc_speed_change
*data
)
1074 uint32_t rx_speed
= le32_to_cpu(data
->DLBitRRate
);
1075 uint32_t tx_speed
= le32_to_cpu(data
->ULBitRate
);
1078 * Currently the USB-NET API does not support reporting the actual
1079 * device speed. Do print it instead.
1081 if ((tx_speed
!= ctx
->tx_speed
) || (rx_speed
!= ctx
->rx_speed
)) {
1082 ctx
->tx_speed
= tx_speed
;
1083 ctx
->rx_speed
= rx_speed
;
1085 if ((tx_speed
> 1000000) && (rx_speed
> 1000000)) {
1086 printk(KERN_INFO KBUILD_MODNAME
1087 ": %s: %u mbit/s downlink "
1088 "%u mbit/s uplink\n",
1090 (unsigned int)(rx_speed
/ 1000000U),
1091 (unsigned int)(tx_speed
/ 1000000U));
1093 printk(KERN_INFO KBUILD_MODNAME
1094 ": %s: %u kbit/s downlink "
1095 "%u kbit/s uplink\n",
1097 (unsigned int)(rx_speed
/ 1000U),
1098 (unsigned int)(tx_speed
/ 1000U));
1103 static void cdc_ncm_status(struct usbnet
*dev
, struct urb
*urb
)
1105 struct cdc_ncm_ctx
*ctx
;
1106 struct usb_cdc_notification
*event
;
1108 ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
1110 if (urb
->actual_length
< sizeof(*event
))
1113 /* test for split data in 8-byte chunks */
1114 if (test_and_clear_bit(EVENT_STS_SPLIT
, &dev
->flags
)) {
1115 cdc_ncm_speed_change(ctx
,
1116 (struct usb_cdc_speed_change
*)urb
->transfer_buffer
);
1120 event
= urb
->transfer_buffer
;
1122 switch (event
->bNotificationType
) {
1123 case USB_CDC_NOTIFY_NETWORK_CONNECTION
:
1125 * According to the CDC NCM specification ch.7.1
1126 * USB_CDC_NOTIFY_NETWORK_CONNECTION notification shall be
1127 * sent by device after USB_CDC_NOTIFY_SPEED_CHANGE.
1129 ctx
->connected
= le16_to_cpu(event
->wValue
);
1131 printk(KERN_INFO KBUILD_MODNAME
": %s: network connection:"
1133 ctx
->netdev
->name
, ctx
->connected
? "" : "dis");
1136 netif_carrier_on(dev
->net
);
1138 netif_carrier_off(dev
->net
);
1139 ctx
->tx_speed
= ctx
->rx_speed
= 0;
1143 case USB_CDC_NOTIFY_RESPONSE_AVAILABLE
:
1144 /* Not implemented yet */
1145 dev_dbg(&dev
->udev
->dev
, "NCM: ResponseAvailable - Value=%d, Index=%d\n",
1146 le16_to_cpu(event
->wValue
), le16_to_cpu(event
->wIndex
));
1149 case USB_CDC_NOTIFY_SPEED_CHANGE
:
1150 if (urb
->actual_length
< (sizeof(*event
) +
1151 sizeof(struct usb_cdc_speed_change
)))
1152 set_bit(EVENT_STS_SPLIT
, &dev
->flags
);
1154 cdc_ncm_speed_change(ctx
,
1155 (struct usb_cdc_speed_change
*) &event
[1]);
1159 dev_err(&dev
->udev
->dev
, "NCM: unexpected "
1160 "notification 0x%02x!\n", event
->bNotificationType
);
1165 static int cdc_ncm_check_connect(struct usbnet
*dev
)
1167 struct cdc_ncm_ctx
*ctx
;
1169 ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
1171 return 1; /* disconnected */
1173 return !ctx
->connected
;
1177 cdc_ncm_probe(struct usb_interface
*udev
, const struct usb_device_id
*prod
)
1179 return usbnet_probe(udev
, prod
);
1182 static void cdc_ncm_disconnect(struct usb_interface
*intf
)
1184 struct usbnet
*dev
= usb_get_intfdata(intf
);
1187 return; /* already disconnected */
1189 usbnet_disconnect(intf
);
1192 static int cdc_ncm_manage_power(struct usbnet
*dev
, int status
)
1194 dev
->intf
->needs_remote_wakeup
= status
;
1198 static const struct driver_info cdc_ncm_info
= {
1199 .description
= "CDC NCM",
1200 .flags
= FLAG_NO_SETINT
| FLAG_MULTI_PACKET
,
1201 .bind
= cdc_ncm_bind
,
1202 .unbind
= cdc_ncm_unbind
,
1203 .check_connect
= cdc_ncm_check_connect
,
1204 // .manage_power = cdc_ncm_manage_power,
1205 .status
= cdc_ncm_status
,
1206 .rx_fixup
= cdc_ncm_rx_fixup
,
1207 .tx_fixup
= cdc_ncm_tx_fixup
,
1210 /* Same as cdc_ncm_info, but with FLAG_WWAN */
1211 static const struct driver_info wwan_info
= {
1212 .description
= "Mobile Broadband Network Device",
1213 .flags
= FLAG_NO_SETINT
| FLAG_MULTI_PACKET
,
1214 .bind
= cdc_ncm_bind
,
1215 .unbind
= cdc_ncm_unbind
,
1216 .check_connect
= cdc_ncm_check_connect
,
1217 // .manage_power = cdc_ncm_manage_power,
1218 .status
= cdc_ncm_status
,
1219 .rx_fixup
= cdc_ncm_rx_fixup
,
1220 .tx_fixup
= cdc_ncm_tx_fixup
,
1223 /* Same as wwan_info, but with FLAG_NOARP */
1224 static const struct driver_info wwan_noarp_info
= {
1225 .description
= "Mobile Broadband Network Device (NO ARP)",
1226 .flags
= FLAG_NO_SETINT
| FLAG_MULTI_PACKET
| FLAG_NOARP
,
1227 .bind
= cdc_ncm_bind
,
1228 .unbind
= cdc_ncm_unbind
,
1229 .check_connect
= cdc_ncm_check_connect
,
1230 // .manage_power = cdc_ncm_manage_power,
1231 .status
= cdc_ncm_status
,
1232 .rx_fixup
= cdc_ncm_rx_fixup
,
1233 .tx_fixup
= cdc_ncm_tx_fixup
,
1236 static const struct usb_device_id cdc_devs
[] = {
1237 /* Ericsson MBM devices like F5521gw */
1238 { .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
1239 | USB_DEVICE_ID_MATCH_VENDOR
,
1241 .bInterfaceClass
= USB_CLASS_COMM
,
1242 .bInterfaceSubClass
= USB_CDC_SUBCLASS_NCM
,
1243 .bInterfaceProtocol
= USB_CDC_PROTO_NONE
,
1244 .driver_info
= (unsigned long) &wwan_info
,
1247 /* Dell branded MBM devices like DW5550 */
1248 { .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
1249 | USB_DEVICE_ID_MATCH_VENDOR
,
1251 .bInterfaceClass
= USB_CLASS_COMM
,
1252 .bInterfaceSubClass
= USB_CDC_SUBCLASS_NCM
,
1253 .bInterfaceProtocol
= USB_CDC_PROTO_NONE
,
1254 .driver_info
= (unsigned long) &wwan_info
,
1257 /* Toshiba branded MBM devices */
1258 { .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
1259 | USB_DEVICE_ID_MATCH_VENDOR
,
1261 .bInterfaceClass
= USB_CLASS_COMM
,
1262 .bInterfaceSubClass
= USB_CDC_SUBCLASS_NCM
,
1263 .bInterfaceProtocol
= USB_CDC_PROTO_NONE
,
1264 .driver_info
= (unsigned long) &wwan_info
,
1267 /* Huawei NCM devices disguised as vendor specific */
1268 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x16),
1269 .driver_info
= (unsigned long)&wwan_info
,
1271 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x46),
1272 .driver_info
= (unsigned long)&wwan_info
,
1274 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x76),
1275 .driver_info
= (unsigned long)&wwan_info
,
1278 /* Infineon(now Intel) HSPA Modem platform */
1279 { USB_DEVICE_AND_INTERFACE_INFO(0x1519, 0x0443,
1281 USB_CDC_SUBCLASS_NCM
, USB_CDC_PROTO_NONE
),
1282 .driver_info
= (unsigned long)&wwan_noarp_info
,
1285 /* Generic CDC-NCM devices */
1286 { USB_INTERFACE_INFO(USB_CLASS_COMM
,
1287 USB_CDC_SUBCLASS_NCM
, USB_CDC_PROTO_NONE
),
1288 .driver_info
= (unsigned long)&cdc_ncm_info
,
1293 MODULE_DEVICE_TABLE(usb
, cdc_devs
);
1295 static struct usb_driver cdc_ncm_driver
= {
1297 .id_table
= cdc_devs
,
1298 .probe
= cdc_ncm_probe
,
1299 .disconnect
= cdc_ncm_disconnect
,
1300 .suspend
= usbnet_suspend
,
1301 .resume
= usbnet_resume
,
1302 .reset_resume
= usbnet_resume
,
1303 .supports_autosuspend
= 1,
1306 static int __init
cdc_ncm_init(void)
1308 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_VERSION
"\n");
1309 return usb_register(&cdc_ncm_driver
);
1312 module_init(cdc_ncm_init
);
1314 static void __exit
cdc_ncm_exit(void)
1316 usb_deregister(&cdc_ncm_driver
);
1319 module_exit(cdc_ncm_exit
);
1321 MODULE_AUTHOR("Hans Petter Selasky");
1322 MODULE_DESCRIPTION("USB CDC NCM host driver");
1323 MODULE_LICENSE("Dual BSD/GPL");