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 <linux/atomic.h>
52 #include <linux/usb/usbnet.h>
53 #include <linux/usb/cdc.h>
54 #include <linux/usb/cdc_ncm.h>
56 #define DRIVER_VERSION "14-Mar-2012"
58 #if IS_ENABLED(CONFIG_USB_NET_CDC_MBIM)
59 static bool prefer_mbim
= true;
61 static bool prefer_mbim
;
63 module_param(prefer_mbim
, bool, S_IRUGO
| S_IWUSR
);
64 MODULE_PARM_DESC(prefer_mbim
, "Prefer MBIM setting on dual NCM/MBIM functions");
66 static void cdc_ncm_txpath_bh(unsigned long param
);
67 static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx
*ctx
);
68 static enum hrtimer_restart
cdc_ncm_tx_timer_cb(struct hrtimer
*hr_timer
);
69 static struct usb_driver cdc_ncm_driver
;
72 cdc_ncm_get_drvinfo(struct net_device
*net
, struct ethtool_drvinfo
*info
)
74 struct usbnet
*dev
= netdev_priv(net
);
76 strlcpy(info
->driver
, dev
->driver_name
, sizeof(info
->driver
));
77 strlcpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
));
78 strlcpy(info
->fw_version
, dev
->driver_info
->description
,
79 sizeof(info
->fw_version
));
80 usb_make_path(dev
->udev
, info
->bus_info
, sizeof(info
->bus_info
));
83 static u8
cdc_ncm_setup(struct cdc_ncm_ctx
*ctx
)
90 u16 ntb_fmt_supported
;
93 struct usbnet
*dev
= netdev_priv(ctx
->netdev
);
95 iface_no
= ctx
->control
->cur_altsetting
->desc
.bInterfaceNumber
;
97 err
= usbnet_read_cmd(dev
, USB_CDC_GET_NTB_PARAMETERS
,
98 USB_TYPE_CLASS
| USB_DIR_IN
100 0, iface_no
, &ctx
->ncm_parm
,
101 sizeof(ctx
->ncm_parm
));
103 pr_debug("failed GET_NTB_PARAMETERS\n");
107 /* read correct set of parameters according to device mode */
108 ctx
->rx_max
= le32_to_cpu(ctx
->ncm_parm
.dwNtbInMaxSize
);
109 ctx
->tx_max
= le32_to_cpu(ctx
->ncm_parm
.dwNtbOutMaxSize
);
110 ctx
->tx_remainder
= le16_to_cpu(ctx
->ncm_parm
.wNdpOutPayloadRemainder
);
111 ctx
->tx_modulus
= le16_to_cpu(ctx
->ncm_parm
.wNdpOutDivisor
);
112 ctx
->tx_ndp_modulus
= le16_to_cpu(ctx
->ncm_parm
.wNdpOutAlignment
);
113 /* devices prior to NCM Errata shall set this field to zero */
114 ctx
->tx_max_datagrams
= le16_to_cpu(ctx
->ncm_parm
.wNtbOutMaxDatagrams
);
115 ntb_fmt_supported
= le16_to_cpu(ctx
->ncm_parm
.bmNtbFormatsSupported
);
118 min_dgram_size
= CDC_NCM_MIN_DATAGRAM_SIZE
;
119 min_hdr_size
= CDC_NCM_MIN_HDR_SIZE
;
120 if (ctx
->mbim_desc
!= NULL
) {
121 flags
= ctx
->mbim_desc
->bmNetworkCapabilities
;
123 min_dgram_size
= CDC_MBIM_MIN_DATAGRAM_SIZE
;
125 } else if (ctx
->func_desc
!= NULL
) {
126 flags
= ctx
->func_desc
->bmNetworkCapabilities
;
131 pr_debug("dwNtbInMaxSize=%u dwNtbOutMaxSize=%u "
132 "wNdpOutPayloadRemainder=%u wNdpOutDivisor=%u "
133 "wNdpOutAlignment=%u wNtbOutMaxDatagrams=%u flags=0x%x\n",
134 ctx
->rx_max
, ctx
->tx_max
, ctx
->tx_remainder
, ctx
->tx_modulus
,
135 ctx
->tx_ndp_modulus
, ctx
->tx_max_datagrams
, flags
);
137 /* max count of tx datagrams */
138 if ((ctx
->tx_max_datagrams
== 0) ||
139 (ctx
->tx_max_datagrams
> CDC_NCM_DPT_DATAGRAMS_MAX
))
140 ctx
->tx_max_datagrams
= CDC_NCM_DPT_DATAGRAMS_MAX
;
142 /* verify maximum size of received NTB in bytes */
143 if (ctx
->rx_max
< USB_CDC_NCM_NTB_MIN_IN_SIZE
) {
144 pr_debug("Using min receive length=%d\n",
145 USB_CDC_NCM_NTB_MIN_IN_SIZE
);
146 ctx
->rx_max
= USB_CDC_NCM_NTB_MIN_IN_SIZE
;
149 if (ctx
->rx_max
> CDC_NCM_NTB_MAX_SIZE_RX
) {
150 pr_debug("Using default maximum receive length=%d\n",
151 CDC_NCM_NTB_MAX_SIZE_RX
);
152 ctx
->rx_max
= CDC_NCM_NTB_MAX_SIZE_RX
;
155 /* inform device about NTB input size changes */
156 if (ctx
->rx_max
!= le32_to_cpu(ctx
->ncm_parm
.dwNtbInMaxSize
)) {
157 __le32 dwNtbInMaxSize
= cpu_to_le32(ctx
->rx_max
);
159 err
= usbnet_write_cmd(dev
, USB_CDC_SET_NTB_INPUT_SIZE
,
160 USB_TYPE_CLASS
| USB_DIR_OUT
161 | USB_RECIP_INTERFACE
,
162 0, iface_no
, &dwNtbInMaxSize
, 4);
164 pr_debug("Setting NTB Input Size failed\n");
167 /* verify maximum size of transmitted NTB in bytes */
169 (min_hdr_size
+ min_dgram_size
)) ||
170 (ctx
->tx_max
> CDC_NCM_NTB_MAX_SIZE_TX
)) {
171 pr_debug("Using default maximum transmit length=%d\n",
172 CDC_NCM_NTB_MAX_SIZE_TX
);
173 ctx
->tx_max
= CDC_NCM_NTB_MAX_SIZE_TX
;
177 * verify that the structure alignment is:
179 * - not greater than the maximum transmit length
180 * - not less than four bytes
182 val
= ctx
->tx_ndp_modulus
;
184 if ((val
< USB_CDC_NCM_NDP_ALIGN_MIN_SIZE
) ||
185 (val
!= ((-val
) & val
)) || (val
>= ctx
->tx_max
)) {
186 pr_debug("Using default alignment: 4 bytes\n");
187 ctx
->tx_ndp_modulus
= USB_CDC_NCM_NDP_ALIGN_MIN_SIZE
;
191 * verify that the payload alignment is:
193 * - not greater than the maximum transmit length
194 * - not less than four bytes
196 val
= ctx
->tx_modulus
;
198 if ((val
< USB_CDC_NCM_NDP_ALIGN_MIN_SIZE
) ||
199 (val
!= ((-val
) & val
)) || (val
>= ctx
->tx_max
)) {
200 pr_debug("Using default transmit modulus: 4 bytes\n");
201 ctx
->tx_modulus
= USB_CDC_NCM_NDP_ALIGN_MIN_SIZE
;
204 /* verify the payload remainder */
205 if (ctx
->tx_remainder
>= ctx
->tx_modulus
) {
206 pr_debug("Using default transmit remainder: 0 bytes\n");
207 ctx
->tx_remainder
= 0;
210 /* adjust TX-remainder according to NCM specification. */
211 ctx
->tx_remainder
= ((ctx
->tx_remainder
- eth_hlen
) &
212 (ctx
->tx_modulus
- 1));
214 /* additional configuration */
217 if (flags
& USB_CDC_NCM_NCAP_CRC_MODE
) {
218 err
= usbnet_write_cmd(dev
, USB_CDC_SET_CRC_MODE
,
219 USB_TYPE_CLASS
| USB_DIR_OUT
220 | USB_RECIP_INTERFACE
,
221 USB_CDC_NCM_CRC_NOT_APPENDED
,
224 pr_debug("Setting CRC mode off failed\n");
227 /* set NTB format, if both formats are supported */
228 if (ntb_fmt_supported
& USB_CDC_NCM_NTH32_SIGN
) {
229 err
= usbnet_write_cmd(dev
, USB_CDC_SET_NTB_FORMAT
,
230 USB_TYPE_CLASS
| USB_DIR_OUT
231 | USB_RECIP_INTERFACE
,
232 USB_CDC_NCM_NTB16_FORMAT
,
235 pr_debug("Setting NTB format to 16-bit failed\n");
238 ctx
->max_datagram_size
= min_dgram_size
;
240 /* set Max Datagram Size (MTU) */
241 if (flags
& USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE
) {
242 __le16 max_datagram_size
;
244 if (ctx
->ether_desc
!= NULL
)
245 eth_max_sz
= le16_to_cpu(ctx
->ether_desc
->wMaxSegmentSize
);
246 else if (ctx
->mbim_desc
!= NULL
)
247 eth_max_sz
= le16_to_cpu(ctx
->mbim_desc
->wMaxSegmentSize
);
251 err
= usbnet_read_cmd(dev
, USB_CDC_GET_MAX_DATAGRAM_SIZE
,
252 USB_TYPE_CLASS
| USB_DIR_IN
253 | USB_RECIP_INTERFACE
,
254 0, iface_no
, &max_datagram_size
, 2);
256 pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
259 ctx
->max_datagram_size
=
260 le16_to_cpu(max_datagram_size
);
261 /* Check Eth descriptor value */
262 if (ctx
->max_datagram_size
> eth_max_sz
)
263 ctx
->max_datagram_size
= eth_max_sz
;
265 if (ctx
->max_datagram_size
> CDC_NCM_MAX_DATAGRAM_SIZE
)
266 ctx
->max_datagram_size
= CDC_NCM_MAX_DATAGRAM_SIZE
;
268 if (ctx
->max_datagram_size
< min_dgram_size
)
269 ctx
->max_datagram_size
= min_dgram_size
;
271 /* if value changed, update device */
272 if (ctx
->max_datagram_size
!=
273 le16_to_cpu(max_datagram_size
)) {
274 err
= usbnet_write_cmd(dev
,
275 USB_CDC_SET_MAX_DATAGRAM_SIZE
,
276 USB_TYPE_CLASS
| USB_DIR_OUT
277 | USB_RECIP_INTERFACE
,
279 iface_no
, &max_datagram_size
,
282 pr_debug("SET_MAX_DGRAM_SIZE failed\n");
288 if (ctx
->netdev
->mtu
!= (ctx
->max_datagram_size
- eth_hlen
))
289 ctx
->netdev
->mtu
= ctx
->max_datagram_size
- eth_hlen
;
295 cdc_ncm_find_endpoints(struct cdc_ncm_ctx
*ctx
, struct usb_interface
*intf
)
297 struct usb_host_endpoint
*e
;
300 for (ep
= 0; ep
< intf
->cur_altsetting
->desc
.bNumEndpoints
; ep
++) {
302 e
= intf
->cur_altsetting
->endpoint
+ ep
;
303 switch (e
->desc
.bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) {
304 case USB_ENDPOINT_XFER_INT
:
305 if (usb_endpoint_dir_in(&e
->desc
)) {
306 if (ctx
->status_ep
== NULL
)
311 case USB_ENDPOINT_XFER_BULK
:
312 if (usb_endpoint_dir_in(&e
->desc
)) {
313 if (ctx
->in_ep
== NULL
)
316 if (ctx
->out_ep
== NULL
)
327 static void cdc_ncm_free(struct cdc_ncm_ctx
*ctx
)
332 if (ctx
->tx_rem_skb
!= NULL
) {
333 dev_kfree_skb_any(ctx
->tx_rem_skb
);
334 ctx
->tx_rem_skb
= NULL
;
337 if (ctx
->tx_curr_skb
!= NULL
) {
338 dev_kfree_skb_any(ctx
->tx_curr_skb
);
339 ctx
->tx_curr_skb
= NULL
;
345 static const struct ethtool_ops cdc_ncm_ethtool_ops
= {
346 .get_drvinfo
= cdc_ncm_get_drvinfo
,
347 .get_link
= usbnet_get_link
,
348 .get_msglevel
= usbnet_get_msglevel
,
349 .set_msglevel
= usbnet_set_msglevel
,
350 .get_settings
= usbnet_get_settings
,
351 .set_settings
= usbnet_set_settings
,
352 .nway_reset
= usbnet_nway_reset
,
355 int cdc_ncm_bind_common(struct usbnet
*dev
, struct usb_interface
*intf
, u8 data_altsetting
)
357 struct cdc_ncm_ctx
*ctx
;
358 struct usb_driver
*driver
;
364 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
368 hrtimer_init(&ctx
->tx_timer
, CLOCK_MONOTONIC
, HRTIMER_MODE_REL
);
369 ctx
->tx_timer
.function
= &cdc_ncm_tx_timer_cb
;
370 ctx
->bh
.data
= (unsigned long)ctx
;
371 ctx
->bh
.func
= cdc_ncm_txpath_bh
;
372 atomic_set(&ctx
->stop
, 0);
373 spin_lock_init(&ctx
->mtx
);
374 ctx
->netdev
= dev
->net
;
376 /* store ctx pointer in device data field */
377 dev
->data
[0] = (unsigned long)ctx
;
379 /* get some pointers */
380 driver
= driver_of(intf
);
381 buf
= intf
->cur_altsetting
->extra
;
382 len
= intf
->cur_altsetting
->extralen
;
384 ctx
->udev
= dev
->udev
;
387 /* parse through descriptors associated with control interface */
388 while ((len
> 0) && (buf
[0] > 2) && (buf
[0] <= len
)) {
390 if (buf
[1] != USB_DT_CS_INTERFACE
)
394 case USB_CDC_UNION_TYPE
:
395 if (buf
[0] < sizeof(*(ctx
->union_desc
)))
399 (const struct usb_cdc_union_desc
*)buf
;
401 ctx
->control
= usb_ifnum_to_if(dev
->udev
,
402 ctx
->union_desc
->bMasterInterface0
);
403 ctx
->data
= usb_ifnum_to_if(dev
->udev
,
404 ctx
->union_desc
->bSlaveInterface0
);
407 case USB_CDC_ETHERNET_TYPE
:
408 if (buf
[0] < sizeof(*(ctx
->ether_desc
)))
412 (const struct usb_cdc_ether_desc
*)buf
;
414 le16_to_cpu(ctx
->ether_desc
->wMaxSegmentSize
);
416 if (dev
->hard_mtu
< CDC_NCM_MIN_DATAGRAM_SIZE
)
417 dev
->hard_mtu
= CDC_NCM_MIN_DATAGRAM_SIZE
;
418 else if (dev
->hard_mtu
> CDC_NCM_MAX_DATAGRAM_SIZE
)
419 dev
->hard_mtu
= CDC_NCM_MAX_DATAGRAM_SIZE
;
422 case USB_CDC_NCM_TYPE
:
423 if (buf
[0] < sizeof(*(ctx
->func_desc
)))
426 ctx
->func_desc
= (const struct usb_cdc_ncm_desc
*)buf
;
429 case USB_CDC_MBIM_TYPE
:
430 if (buf
[0] < sizeof(*(ctx
->mbim_desc
)))
433 ctx
->mbim_desc
= (const struct usb_cdc_mbim_desc
*)buf
;
440 /* advance to next descriptor */
446 /* some buggy devices have an IAD but no CDC Union */
447 if (!ctx
->union_desc
&& intf
->intf_assoc
&& intf
->intf_assoc
->bInterfaceCount
== 2) {
449 ctx
->data
= usb_ifnum_to_if(dev
->udev
, intf
->cur_altsetting
->desc
.bInterfaceNumber
+ 1);
450 dev_dbg(&intf
->dev
, "CDC Union missing - got slave from IAD\n");
453 /* check if we got everything */
454 if ((ctx
->control
== NULL
) || (ctx
->data
== NULL
) ||
455 ((!ctx
->mbim_desc
) && ((ctx
->ether_desc
== NULL
) || (ctx
->control
!= intf
))))
458 /* claim data interface, if different from control */
459 if (ctx
->data
!= ctx
->control
) {
460 temp
= usb_driver_claim_interface(driver
, ctx
->data
, dev
);
465 iface_no
= ctx
->data
->cur_altsetting
->desc
.bInterfaceNumber
;
467 /* Reset data interface. Some devices will not reset properly
468 * unless they are configured first. Toggle the altsetting to
471 usb_set_interface(dev
->udev
, iface_no
, data_altsetting
);
472 temp
= usb_set_interface(dev
->udev
, iface_no
, 0);
476 /* initialize data interface */
477 if (cdc_ncm_setup(ctx
))
480 /* Some firmwares need a pause here or they will silently fail
481 * to set up the interface properly. This value was decided
482 * empirically on a Sierra Wireless MC7455 running 02.08.02.00
485 usleep_range(10000, 20000);
487 /* configure data interface */
488 temp
= usb_set_interface(dev
->udev
, iface_no
, data_altsetting
);
492 cdc_ncm_find_endpoints(ctx
, ctx
->data
);
493 cdc_ncm_find_endpoints(ctx
, ctx
->control
);
495 if ((ctx
->in_ep
== NULL
) || (ctx
->out_ep
== NULL
) ||
496 (ctx
->status_ep
== NULL
))
499 dev
->net
->ethtool_ops
= &cdc_ncm_ethtool_ops
;
501 usb_set_intfdata(ctx
->data
, dev
);
502 usb_set_intfdata(ctx
->control
, dev
);
503 usb_set_intfdata(ctx
->intf
, dev
);
505 if (ctx
->ether_desc
) {
506 temp
= usbnet_get_ethernet_addr(dev
, ctx
->ether_desc
->iMACAddress
);
509 dev_info(&dev
->udev
->dev
, "MAC-Address: %pM\n", dev
->net
->dev_addr
);
513 dev
->in
= usb_rcvbulkpipe(dev
->udev
,
514 ctx
->in_ep
->desc
.bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
);
515 dev
->out
= usb_sndbulkpipe(dev
->udev
,
516 ctx
->out_ep
->desc
.bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
);
517 dev
->status
= ctx
->status_ep
;
518 dev
->rx_urb_size
= ctx
->rx_max
;
520 ctx
->tx_speed
= ctx
->rx_speed
= 0;
524 usb_set_intfdata(ctx
->control
, NULL
);
525 usb_set_intfdata(ctx
->data
, NULL
);
526 if (ctx
->data
!= ctx
->control
)
527 usb_driver_release_interface(driver
, ctx
->data
);
529 cdc_ncm_free((struct cdc_ncm_ctx
*)dev
->data
[0]);
531 dev_info(&dev
->udev
->dev
, "bind() failure\n");
534 EXPORT_SYMBOL_GPL(cdc_ncm_bind_common
);
536 void cdc_ncm_unbind(struct usbnet
*dev
, struct usb_interface
*intf
)
538 struct cdc_ncm_ctx
*ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
539 struct usb_driver
*driver
= driver_of(intf
);
542 return; /* no setup */
544 atomic_set(&ctx
->stop
, 1);
546 if (hrtimer_active(&ctx
->tx_timer
))
547 hrtimer_cancel(&ctx
->tx_timer
);
549 tasklet_kill(&ctx
->bh
);
551 /* handle devices with combined control and data interface */
552 if (ctx
->control
== ctx
->data
)
555 /* disconnect master --> disconnect slave */
556 if (intf
== ctx
->control
&& ctx
->data
) {
557 usb_set_intfdata(ctx
->data
, NULL
);
558 usb_driver_release_interface(driver
, ctx
->data
);
561 } else if (intf
== ctx
->data
&& ctx
->control
) {
562 usb_set_intfdata(ctx
->control
, NULL
);
563 usb_driver_release_interface(driver
, ctx
->control
);
567 usb_set_intfdata(ctx
->intf
, NULL
);
570 EXPORT_SYMBOL_GPL(cdc_ncm_unbind
);
572 /* Select the MBIM altsetting iff it is preferred and available,
573 * returning the number of the corresponding data interface altsetting
575 u8
cdc_ncm_select_altsetting(struct usbnet
*dev
, struct usb_interface
*intf
)
577 struct usb_host_interface
*alt
;
579 /* The MBIM spec defines a NCM compatible default altsetting,
580 * which we may have matched:
582 * "Functions that implement both NCM 1.0 and MBIM (an
583 * “NCM/MBIM function”) according to this recommendation
584 * shall provide two alternate settings for the
585 * Communication Interface. Alternate setting 0, and the
586 * associated class and endpoint descriptors, shall be
587 * constructed according to the rules given for the
588 * Communication Interface in section 5 of [USBNCM10].
589 * Alternate setting 1, and the associated class and
590 * endpoint descriptors, shall be constructed according to
591 * the rules given in section 6 (USB Device Model) of this
594 if (prefer_mbim
&& intf
->num_altsetting
== 2) {
595 alt
= usb_altnum_to_altsetting(intf
, CDC_NCM_COMM_ALTSETTING_MBIM
);
596 if (alt
&& cdc_ncm_comm_intf_is_mbim(alt
) &&
597 !usb_set_interface(dev
->udev
,
598 intf
->cur_altsetting
->desc
.bInterfaceNumber
,
599 CDC_NCM_COMM_ALTSETTING_MBIM
))
600 return CDC_NCM_DATA_ALTSETTING_MBIM
;
602 return CDC_NCM_DATA_ALTSETTING_NCM
;
604 EXPORT_SYMBOL_GPL(cdc_ncm_select_altsetting
);
606 static int cdc_ncm_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
608 /* MBIM backwards compatible function? */
609 cdc_ncm_select_altsetting(dev
, intf
);
610 if (cdc_ncm_comm_intf_is_mbim(intf
->cur_altsetting
))
613 /* NCM data altsetting is always 1 */
614 return cdc_ncm_bind_common(dev
, intf
, 1);
617 static void cdc_ncm_align_tail(struct sk_buff
*skb
, size_t modulus
, size_t remainder
, size_t max
)
619 size_t align
= ALIGN(skb
->len
, modulus
) - skb
->len
+ remainder
;
621 if (skb
->len
+ align
> max
)
622 align
= max
- skb
->len
;
623 if (align
&& skb_tailroom(skb
) >= align
)
624 memset(skb_put(skb
, align
), 0, align
);
627 /* return a pointer to a valid struct usb_cdc_ncm_ndp16 of type sign, possibly
628 * allocating a new one within skb
630 static struct usb_cdc_ncm_ndp16
*cdc_ncm_ndp(struct cdc_ncm_ctx
*ctx
, struct sk_buff
*skb
, __le32 sign
, size_t reserve
)
632 struct usb_cdc_ncm_ndp16
*ndp16
= NULL
;
633 struct usb_cdc_ncm_nth16
*nth16
= (void *)skb
->data
;
634 size_t ndpoffset
= le16_to_cpu(nth16
->wNdpIndex
);
636 /* follow the chain of NDPs, looking for a match */
638 ndp16
= (struct usb_cdc_ncm_ndp16
*)(skb
->data
+ ndpoffset
);
639 if (ndp16
->dwSignature
== sign
)
641 ndpoffset
= le16_to_cpu(ndp16
->wNextNdpIndex
);
645 cdc_ncm_align_tail(skb
, ctx
->tx_ndp_modulus
, 0, ctx
->tx_max
);
647 /* verify that there is room for the NDP and the datagram (reserve) */
648 if ((ctx
->tx_max
- skb
->len
- reserve
) < CDC_NCM_NDP_SIZE
)
653 ndp16
->wNextNdpIndex
= cpu_to_le16(skb
->len
);
655 nth16
->wNdpIndex
= cpu_to_le16(skb
->len
);
657 /* push a new empty NDP */
658 ndp16
= (struct usb_cdc_ncm_ndp16
*)memset(skb_put(skb
, CDC_NCM_NDP_SIZE
), 0, CDC_NCM_NDP_SIZE
);
659 ndp16
->dwSignature
= sign
;
660 ndp16
->wLength
= cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp16
) + sizeof(struct usb_cdc_ncm_dpe16
));
665 cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx
*ctx
, struct sk_buff
*skb
, __le32 sign
)
667 struct usb_cdc_ncm_nth16
*nth16
;
668 struct usb_cdc_ncm_ndp16
*ndp16
;
669 struct sk_buff
*skb_out
;
670 u16 n
= 0, index
, ndplen
;
673 /* if there is a remaining skb, it gets priority */
675 swap(skb
, ctx
->tx_rem_skb
);
676 swap(sign
, ctx
->tx_rem_sign
);
681 /* check if we are resuming an OUT skb */
682 skb_out
= ctx
->tx_curr_skb
;
684 /* allocate a new OUT skb */
686 skb_out
= alloc_skb((ctx
->tx_max
+ 1), GFP_ATOMIC
);
687 if (skb_out
== NULL
) {
689 dev_kfree_skb_any(skb
);
690 ctx
->netdev
->stats
.tx_dropped
++;
694 /* fill out the initial 16-bit NTB header */
695 nth16
= (struct usb_cdc_ncm_nth16
*)memset(skb_put(skb_out
, sizeof(struct usb_cdc_ncm_nth16
)), 0, sizeof(struct usb_cdc_ncm_nth16
));
696 nth16
->dwSignature
= cpu_to_le32(USB_CDC_NCM_NTH16_SIGN
);
697 nth16
->wHeaderLength
= cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16
));
698 nth16
->wSequence
= cpu_to_le16(ctx
->tx_seq
++);
700 /* count total number of frames in this NTB */
701 ctx
->tx_curr_frame_num
= 0;
704 for (n
= ctx
->tx_curr_frame_num
; n
< ctx
->tx_max_datagrams
; n
++) {
705 /* send any remaining skb first */
707 skb
= ctx
->tx_rem_skb
;
708 sign
= ctx
->tx_rem_sign
;
709 ctx
->tx_rem_skb
= NULL
;
711 /* check for end of skb */
716 /* get the appropriate NDP for this skb */
717 ndp16
= cdc_ncm_ndp(ctx
, skb_out
, sign
, skb
->len
+ ctx
->tx_modulus
+ ctx
->tx_remainder
);
719 /* align beginning of next frame */
720 cdc_ncm_align_tail(skb_out
, ctx
->tx_modulus
, ctx
->tx_remainder
, ctx
->tx_max
);
722 /* check if we had enough room left for both NDP and frame */
723 if (!ndp16
|| skb_out
->len
+ skb
->len
> ctx
->tx_max
) {
725 /* won't fit, MTU problem? */
726 dev_kfree_skb_any(skb
);
728 ctx
->netdev
->stats
.tx_dropped
++;
730 /* no room for skb - store for later */
731 if (ctx
->tx_rem_skb
!= NULL
) {
732 dev_kfree_skb_any(ctx
->tx_rem_skb
);
733 ctx
->netdev
->stats
.tx_dropped
++;
735 ctx
->tx_rem_skb
= skb
;
736 ctx
->tx_rem_sign
= sign
;
743 /* calculate frame number withing this NDP */
744 ndplen
= le16_to_cpu(ndp16
->wLength
);
745 index
= (ndplen
- sizeof(struct usb_cdc_ncm_ndp16
)) / sizeof(struct usb_cdc_ncm_dpe16
) - 1;
747 /* OK, add this skb */
748 ndp16
->dpe16
[index
].wDatagramLength
= cpu_to_le16(skb
->len
);
749 ndp16
->dpe16
[index
].wDatagramIndex
= cpu_to_le16(skb_out
->len
);
750 ndp16
->wLength
= cpu_to_le16(ndplen
+ sizeof(struct usb_cdc_ncm_dpe16
));
751 memcpy(skb_put(skb_out
, skb
->len
), skb
->data
, skb
->len
);
752 dev_kfree_skb_any(skb
);
755 /* send now if this NDP is full */
756 if (index
>= CDC_NCM_DPT_DATAGRAMS_MAX
) {
762 /* free up any dangling skb */
764 dev_kfree_skb_any(skb
);
766 ctx
->netdev
->stats
.tx_dropped
++;
769 ctx
->tx_curr_frame_num
= n
;
772 /* wait for more frames */
774 ctx
->tx_curr_skb
= skb_out
;
777 } else if ((n
< ctx
->tx_max_datagrams
) && (ready2send
== 0)) {
778 /* wait for more frames */
780 ctx
->tx_curr_skb
= skb_out
;
781 /* set the pending count */
782 if (n
< CDC_NCM_RESTART_TIMER_DATAGRAM_CNT
)
783 ctx
->tx_timer_pending
= CDC_NCM_TIMER_PENDING_CNT
;
788 /* variables will be reset at next call */
792 * If collected data size is less or equal CDC_NCM_MIN_TX_PKT bytes,
793 * we send buffers as it is. If we get more data, it would be more
794 * efficient for USB HS mobile device with DMA engine to receive a full
795 * size NTB, than canceling DMA transfer and receiving a short packet.
797 if (skb_out
->len
> CDC_NCM_MIN_TX_PKT
)
798 /* final zero padding */
799 memset(skb_put(skb_out
, ctx
->tx_max
- skb_out
->len
), 0, ctx
->tx_max
- skb_out
->len
);
801 /* do we need to prevent a ZLP? */
802 if (((skb_out
->len
% le16_to_cpu(ctx
->out_ep
->desc
.wMaxPacketSize
)) == 0) &&
803 (skb_out
->len
< le32_to_cpu(ctx
->ncm_parm
.dwNtbOutMaxSize
)) && skb_tailroom(skb_out
))
804 *skb_put(skb_out
, 1) = 0; /* force short packet */
806 /* set final frame length */
807 nth16
= (struct usb_cdc_ncm_nth16
*)skb_out
->data
;
808 nth16
->wBlockLength
= cpu_to_le16(skb_out
->len
);
811 ctx
->tx_curr_skb
= NULL
;
812 ctx
->netdev
->stats
.tx_packets
+= ctx
->tx_curr_frame_num
;
816 /* Start timer, if there is a remaining skb */
817 if (ctx
->tx_curr_skb
!= NULL
)
818 cdc_ncm_tx_timeout_start(ctx
);
821 EXPORT_SYMBOL_GPL(cdc_ncm_fill_tx_frame
);
823 static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx
*ctx
)
825 /* start timer, if not already started */
826 if (!(hrtimer_active(&ctx
->tx_timer
) || atomic_read(&ctx
->stop
)))
827 hrtimer_start(&ctx
->tx_timer
,
828 ktime_set(0, CDC_NCM_TIMER_INTERVAL
),
832 static enum hrtimer_restart
cdc_ncm_tx_timer_cb(struct hrtimer
*timer
)
834 struct cdc_ncm_ctx
*ctx
=
835 container_of(timer
, struct cdc_ncm_ctx
, tx_timer
);
837 if (!atomic_read(&ctx
->stop
))
838 tasklet_schedule(&ctx
->bh
);
839 return HRTIMER_NORESTART
;
842 static void cdc_ncm_txpath_bh(unsigned long param
)
844 struct cdc_ncm_ctx
*ctx
= (struct cdc_ncm_ctx
*)param
;
846 spin_lock_bh(&ctx
->mtx
);
847 if (ctx
->tx_timer_pending
!= 0) {
848 ctx
->tx_timer_pending
--;
849 cdc_ncm_tx_timeout_start(ctx
);
850 spin_unlock_bh(&ctx
->mtx
);
851 } else if (ctx
->netdev
!= NULL
) {
852 spin_unlock_bh(&ctx
->mtx
);
853 netif_tx_lock_bh(ctx
->netdev
);
854 usbnet_start_xmit(NULL
, ctx
->netdev
);
855 netif_tx_unlock_bh(ctx
->netdev
);
857 spin_unlock_bh(&ctx
->mtx
);
861 static struct sk_buff
*
862 cdc_ncm_tx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
, gfp_t flags
)
864 struct sk_buff
*skb_out
;
865 struct cdc_ncm_ctx
*ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
868 * The Ethernet API we are using does not support transmitting
869 * multiple Ethernet frames in a single call. This driver will
870 * accumulate multiple Ethernet frames and send out a larger
871 * USB frame when the USB buffer is full or when a single jiffies
877 spin_lock_bh(&ctx
->mtx
);
878 skb_out
= cdc_ncm_fill_tx_frame(ctx
, skb
, cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN
));
879 spin_unlock_bh(&ctx
->mtx
);
884 dev_kfree_skb_any(skb
);
889 /* verify NTB header and return offset of first NDP, or negative error */
890 int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx
*ctx
, struct sk_buff
*skb_in
)
892 struct usb_cdc_ncm_nth16
*nth16
;
899 if (skb_in
->len
< (sizeof(struct usb_cdc_ncm_nth16
) +
900 sizeof(struct usb_cdc_ncm_ndp16
))) {
901 pr_debug("frame too short\n");
905 nth16
= (struct usb_cdc_ncm_nth16
*)skb_in
->data
;
907 if (le32_to_cpu(nth16
->dwSignature
) != USB_CDC_NCM_NTH16_SIGN
) {
908 pr_debug("invalid NTH16 signature <%u>\n",
909 le32_to_cpu(nth16
->dwSignature
));
913 len
= le16_to_cpu(nth16
->wBlockLength
);
914 if (len
> ctx
->rx_max
) {
915 pr_debug("unsupported NTB block length %u/%u\n", len
,
920 if ((ctx
->rx_seq
+ 1) != le16_to_cpu(nth16
->wSequence
) &&
921 (ctx
->rx_seq
|| le16_to_cpu(nth16
->wSequence
)) &&
922 !((ctx
->rx_seq
== 0xffff) && !le16_to_cpu(nth16
->wSequence
))) {
923 pr_debug("sequence number glitch prev=%d curr=%d\n",
924 ctx
->rx_seq
, le16_to_cpu(nth16
->wSequence
));
926 ctx
->rx_seq
= le16_to_cpu(nth16
->wSequence
);
928 ret
= le16_to_cpu(nth16
->wNdpIndex
);
932 EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_nth16
);
934 /* verify NDP header and return number of datagrams, or negative error */
935 int cdc_ncm_rx_verify_ndp16(struct sk_buff
*skb_in
, int ndpoffset
)
937 struct usb_cdc_ncm_ndp16
*ndp16
;
940 if ((ndpoffset
+ sizeof(struct usb_cdc_ncm_ndp16
)) > skb_in
->len
) {
941 pr_debug("invalid NDP offset <%u>\n", ndpoffset
);
944 ndp16
= (struct usb_cdc_ncm_ndp16
*)(skb_in
->data
+ ndpoffset
);
946 if (le16_to_cpu(ndp16
->wLength
) < USB_CDC_NCM_NDP16_LENGTH_MIN
) {
947 pr_debug("invalid DPT16 length <%u>\n",
948 le32_to_cpu(ndp16
->dwSignature
));
952 ret
= ((le16_to_cpu(ndp16
->wLength
) -
953 sizeof(struct usb_cdc_ncm_ndp16
)) /
954 sizeof(struct usb_cdc_ncm_dpe16
));
955 ret
--; /* we process NDP entries except for the last one */
957 if ((sizeof(struct usb_cdc_ncm_ndp16
) + ret
* (sizeof(struct usb_cdc_ncm_dpe16
))) >
959 pr_debug("Invalid nframes = %d\n", ret
);
966 EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_ndp16
);
968 static int cdc_ncm_rx_fixup(struct usbnet
*dev
, struct sk_buff
*skb_in
)
971 struct cdc_ncm_ctx
*ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
976 struct usb_cdc_ncm_ndp16
*ndp16
;
977 struct usb_cdc_ncm_dpe16
*dpe16
;
979 int loopcount
= 50; /* arbitrary max preventing infinite loop */
981 ndpoffset
= cdc_ncm_rx_verify_nth16(ctx
, skb_in
);
986 nframes
= cdc_ncm_rx_verify_ndp16(skb_in
, ndpoffset
);
990 ndp16
= (struct usb_cdc_ncm_ndp16
*)(skb_in
->data
+ ndpoffset
);
992 if (le32_to_cpu(ndp16
->dwSignature
) != USB_CDC_NCM_NDP16_NOCRC_SIGN
) {
993 pr_debug("invalid DPT16 signature <%u>\n",
994 le32_to_cpu(ndp16
->dwSignature
));
997 dpe16
= ndp16
->dpe16
;
999 for (x
= 0; x
< nframes
; x
++, dpe16
++) {
1000 offset
= le16_to_cpu(dpe16
->wDatagramIndex
);
1001 len
= le16_to_cpu(dpe16
->wDatagramLength
);
1005 * All entries after first NULL entry are to be ignored
1007 if ((offset
== 0) || (len
== 0)) {
1009 goto err_ndp
; /* empty NTB */
1013 /* sanity checking */
1014 if (((offset
+ len
) > skb_in
->len
) ||
1015 (len
> ctx
->rx_max
) || (len
< ETH_HLEN
)) {
1016 pr_debug("invalid frame detected (ignored)"
1017 "offset[%u]=%u, length=%u, skb=%p\n",
1018 x
, offset
, len
, skb_in
);
1024 skb
= skb_clone(skb_in
, GFP_ATOMIC
);
1028 skb
->data
= ((u8
*)skb_in
->data
) + offset
;
1029 skb_set_tail_pointer(skb
, len
);
1030 usbnet_skb_return(dev
, skb
);
1034 /* are there more NDPs to process? */
1035 ndpoffset
= le16_to_cpu(ndp16
->wNextNdpIndex
);
1036 if (ndpoffset
&& loopcount
--)
1045 cdc_ncm_speed_change(struct cdc_ncm_ctx
*ctx
,
1046 struct usb_cdc_speed_change
*data
)
1048 uint32_t rx_speed
= le32_to_cpu(data
->DLBitRRate
);
1049 uint32_t tx_speed
= le32_to_cpu(data
->ULBitRate
);
1052 * Currently the USB-NET API does not support reporting the actual
1053 * device speed. Do print it instead.
1055 if ((tx_speed
!= ctx
->tx_speed
) || (rx_speed
!= ctx
->rx_speed
)) {
1056 ctx
->tx_speed
= tx_speed
;
1057 ctx
->rx_speed
= rx_speed
;
1059 if ((tx_speed
> 1000000) && (rx_speed
> 1000000)) {
1060 printk(KERN_INFO KBUILD_MODNAME
1061 ": %s: %u mbit/s downlink "
1062 "%u mbit/s uplink\n",
1064 (unsigned int)(rx_speed
/ 1000000U),
1065 (unsigned int)(tx_speed
/ 1000000U));
1067 printk(KERN_INFO KBUILD_MODNAME
1068 ": %s: %u kbit/s downlink "
1069 "%u kbit/s uplink\n",
1071 (unsigned int)(rx_speed
/ 1000U),
1072 (unsigned int)(tx_speed
/ 1000U));
1077 static void cdc_ncm_status(struct usbnet
*dev
, struct urb
*urb
)
1079 struct cdc_ncm_ctx
*ctx
;
1080 struct usb_cdc_notification
*event
;
1082 ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
1084 if (urb
->actual_length
< sizeof(*event
))
1087 /* test for split data in 8-byte chunks */
1088 if (test_and_clear_bit(EVENT_STS_SPLIT
, &dev
->flags
)) {
1089 cdc_ncm_speed_change(ctx
,
1090 (struct usb_cdc_speed_change
*)urb
->transfer_buffer
);
1094 event
= urb
->transfer_buffer
;
1096 switch (event
->bNotificationType
) {
1097 case USB_CDC_NOTIFY_NETWORK_CONNECTION
:
1099 * According to the CDC NCM specification ch.7.1
1100 * USB_CDC_NOTIFY_NETWORK_CONNECTION notification shall be
1101 * sent by device after USB_CDC_NOTIFY_SPEED_CHANGE.
1103 ctx
->connected
= le16_to_cpu(event
->wValue
);
1105 printk(KERN_INFO KBUILD_MODNAME
": %s: network connection:"
1107 ctx
->netdev
->name
, ctx
->connected
? "" : "dis");
1109 usbnet_link_change(dev
, ctx
->connected
, 0);
1110 if (!ctx
->connected
)
1111 ctx
->tx_speed
= ctx
->rx_speed
= 0;
1114 case USB_CDC_NOTIFY_SPEED_CHANGE
:
1115 if (urb
->actual_length
< (sizeof(*event
) +
1116 sizeof(struct usb_cdc_speed_change
)))
1117 set_bit(EVENT_STS_SPLIT
, &dev
->flags
);
1119 cdc_ncm_speed_change(ctx
,
1120 (struct usb_cdc_speed_change
*) &event
[1]);
1124 dev_dbg(&dev
->udev
->dev
,
1125 "NCM: unexpected notification 0x%02x!\n",
1126 event
->bNotificationType
);
1131 static int cdc_ncm_check_connect(struct usbnet
*dev
)
1133 struct cdc_ncm_ctx
*ctx
;
1135 ctx
= (struct cdc_ncm_ctx
*)dev
->data
[0];
1137 return 1; /* disconnected */
1139 return !ctx
->connected
;
1143 cdc_ncm_probe(struct usb_interface
*udev
, const struct usb_device_id
*prod
)
1145 return usbnet_probe(udev
, prod
);
1148 static void cdc_ncm_disconnect(struct usb_interface
*intf
)
1150 struct usbnet
*dev
= usb_get_intfdata(intf
);
1153 return; /* already disconnected */
1155 usbnet_disconnect(intf
);
1158 static const struct driver_info cdc_ncm_info
= {
1159 .description
= "CDC NCM",
1160 .flags
= FLAG_POINTTOPOINT
| FLAG_NO_SETINT
| FLAG_MULTI_PACKET
1162 .bind
= cdc_ncm_bind
,
1163 .unbind
= cdc_ncm_unbind
,
1164 .check_connect
= cdc_ncm_check_connect
,
1165 .manage_power
= usbnet_manage_power
,
1166 .status
= cdc_ncm_status
,
1167 .rx_fixup
= cdc_ncm_rx_fixup
,
1168 .tx_fixup
= cdc_ncm_tx_fixup
,
1171 /* Same as cdc_ncm_info, but with FLAG_WWAN */
1172 static const struct driver_info wwan_info
= {
1173 .description
= "Mobile Broadband Network Device",
1174 .flags
= FLAG_POINTTOPOINT
| FLAG_NO_SETINT
| FLAG_MULTI_PACKET
1175 | FLAG_LINK_INTR
| FLAG_WWAN
,
1176 .bind
= cdc_ncm_bind
,
1177 .unbind
= cdc_ncm_unbind
,
1178 .check_connect
= cdc_ncm_check_connect
,
1179 .manage_power
= usbnet_manage_power
,
1180 .status
= cdc_ncm_status
,
1181 .rx_fixup
= cdc_ncm_rx_fixup
,
1182 .tx_fixup
= cdc_ncm_tx_fixup
,
1185 /* Same as wwan_info, but with FLAG_NOARP */
1186 static const struct driver_info wwan_noarp_info
= {
1187 .description
= "Mobile Broadband Network Device (NO ARP)",
1188 .flags
= FLAG_POINTTOPOINT
| FLAG_NO_SETINT
| FLAG_MULTI_PACKET
1189 | FLAG_LINK_INTR
| FLAG_WWAN
| FLAG_NOARP
,
1190 .bind
= cdc_ncm_bind
,
1191 .unbind
= cdc_ncm_unbind
,
1192 .check_connect
= cdc_ncm_check_connect
,
1193 .manage_power
= usbnet_manage_power
,
1194 .status
= cdc_ncm_status
,
1195 .rx_fixup
= cdc_ncm_rx_fixup
,
1196 .tx_fixup
= cdc_ncm_tx_fixup
,
1199 static const struct usb_device_id cdc_devs
[] = {
1200 /* Ericsson MBM devices like F5521gw */
1201 { .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
1202 | USB_DEVICE_ID_MATCH_VENDOR
,
1204 .bInterfaceClass
= USB_CLASS_COMM
,
1205 .bInterfaceSubClass
= USB_CDC_SUBCLASS_NCM
,
1206 .bInterfaceProtocol
= USB_CDC_PROTO_NONE
,
1207 .driver_info
= (unsigned long) &wwan_info
,
1210 /* Dell branded MBM devices like DW5550 */
1211 { .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
1212 | USB_DEVICE_ID_MATCH_VENDOR
,
1214 .bInterfaceClass
= USB_CLASS_COMM
,
1215 .bInterfaceSubClass
= USB_CDC_SUBCLASS_NCM
,
1216 .bInterfaceProtocol
= USB_CDC_PROTO_NONE
,
1217 .driver_info
= (unsigned long) &wwan_info
,
1220 /* Toshiba branded MBM devices */
1221 { .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
1222 | USB_DEVICE_ID_MATCH_VENDOR
,
1224 .bInterfaceClass
= USB_CLASS_COMM
,
1225 .bInterfaceSubClass
= USB_CDC_SUBCLASS_NCM
,
1226 .bInterfaceProtocol
= USB_CDC_PROTO_NONE
,
1227 .driver_info
= (unsigned long) &wwan_info
,
1230 /* tag Huawei devices as wwan */
1231 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1,
1233 USB_CDC_SUBCLASS_NCM
,
1234 USB_CDC_PROTO_NONE
),
1235 .driver_info
= (unsigned long)&wwan_info
,
1238 /* Huawei NCM devices disguised as vendor specific */
1239 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x16),
1240 .driver_info
= (unsigned long)&wwan_info
,
1242 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x46),
1243 .driver_info
= (unsigned long)&wwan_info
,
1245 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x76),
1246 .driver_info
= (unsigned long)&wwan_info
,
1249 /* Infineon(now Intel) HSPA Modem platform */
1250 { USB_DEVICE_AND_INTERFACE_INFO(0x1519, 0x0443,
1252 USB_CDC_SUBCLASS_NCM
, USB_CDC_PROTO_NONE
),
1253 .driver_info
= (unsigned long)&wwan_noarp_info
,
1256 /* Generic CDC-NCM devices */
1257 { USB_INTERFACE_INFO(USB_CLASS_COMM
,
1258 USB_CDC_SUBCLASS_NCM
, USB_CDC_PROTO_NONE
),
1259 .driver_info
= (unsigned long)&cdc_ncm_info
,
1264 MODULE_DEVICE_TABLE(usb
, cdc_devs
);
1266 static struct usb_driver cdc_ncm_driver
= {
1268 .id_table
= cdc_devs
,
1269 .probe
= cdc_ncm_probe
,
1270 .disconnect
= cdc_ncm_disconnect
,
1271 .suspend
= usbnet_suspend
,
1272 .resume
= usbnet_resume
,
1273 .reset_resume
= usbnet_resume
,
1274 .supports_autosuspend
= 1,
1275 .disable_hub_initiated_lpm
= 1,
1278 module_usb_driver(cdc_ncm_driver
);
1280 MODULE_AUTHOR("Hans Petter Selasky");
1281 MODULE_DESCRIPTION("USB CDC NCM host driver");
1282 MODULE_LICENSE("Dual BSD/GPL");