blob: 9197b2c72ca36dd9e62bbccafbea388d5fc99793 [file] [log] [blame]
Alexey Orishko900d4952010-11-29 23:23:28 +00001/*
2 * cdc_ncm.c
3 *
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +00004 * Copyright (C) ST-Ericsson 2010-2012
Alexey Orishko900d4952010-11-29 23:23:28 +00005 * Contact: Alexey Orishko <alexey.orishko@stericsson.com>
6 * Original author: Hans Petter Selasky <hans.petter.selasky@stericsson.com>
7 *
8 * USB Host Driver for Network Control Model (NCM)
9 * http://www.usb.org/developers/devclass_docs/NCM10.zip
10 *
11 * The NCM encoding, decoding and initialization logic
12 * derives from FreeBSD 8.x. if_cdce.c and if_cdcereg.h
13 *
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:
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
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.
27 *
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
38 * SUCH DAMAGE.
39 */
40
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>
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +000050#include <linux/hrtimer.h>
Alexey Orishko900d4952010-11-29 23:23:28 +000051#include <linux/atomic.h>
52#include <linux/usb/usbnet.h>
53#include <linux/usb/cdc.h>
Bjørn Morkc91ce3b2012-10-22 10:56:35 +000054#include <linux/usb/cdc_ncm.h>
Alexey Orishko900d4952010-11-29 23:23:28 +000055
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +000056#define DRIVER_VERSION "14-Mar-2012"
Alexey Orishko900d4952010-11-29 23:23:28 +000057
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +000058static void cdc_ncm_txpath_bh(unsigned long param);
59static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
60static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer);
Alexey Orishko900d4952010-11-29 23:23:28 +000061static struct usb_driver cdc_ncm_driver;
Alexey Orishko900d4952010-11-29 23:23:28 +000062
63static void
64cdc_ncm_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
65{
66 struct usbnet *dev = netdev_priv(net);
67
68 strncpy(info->driver, dev->driver_name, sizeof(info->driver));
69 strncpy(info->version, DRIVER_VERSION, sizeof(info->version));
70 strncpy(info->fw_version, dev->driver_info->description,
71 sizeof(info->fw_version));
72 usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info));
73}
74
Alexey Orishko900d4952010-11-29 23:23:28 +000075static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
76{
Alexey Orishko900d4952010-11-29 23:23:28 +000077 u32 val;
Alexey Orishko900d4952010-11-29 23:23:28 +000078 u8 flags;
79 u8 iface_no;
80 int err;
Greg Suarez2d1c4312012-10-22 10:56:30 +000081 int eth_hlen;
Alexey Orishko84e77a82011-02-07 09:45:10 +000082 u16 ntb_fmt_supported;
Greg Suarez2d1c4312012-10-22 10:56:30 +000083 u32 min_dgram_size;
84 u32 min_hdr_size;
Ming Lei90b8b032012-10-24 19:46:56 +000085 struct usbnet *dev = netdev_priv(ctx->netdev);
Alexey Orishko900d4952010-11-29 23:23:28 +000086
87 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
88
Ming Lei90b8b032012-10-24 19:46:56 +000089 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS,
90 USB_TYPE_CLASS | USB_DIR_IN
91 |USB_RECIP_INTERFACE,
92 0, iface_no, &ctx->ncm_parm,
93 sizeof(ctx->ncm_parm));
Giuseppe Scrivano36c35412011-08-03 22:10:29 +000094 if (err < 0) {
Alexey Orishko900d4952010-11-29 23:23:28 +000095 pr_debug("failed GET_NTB_PARAMETERS\n");
96 return 1;
97 }
98
99 /* read correct set of parameters according to device mode */
100 ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize);
101 ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize);
102 ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder);
103 ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor);
104 ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment);
Alexey Orishko84e77a82011-02-07 09:45:10 +0000105 /* devices prior to NCM Errata shall set this field to zero */
106 ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams);
107 ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported);
Alexey Orishko900d4952010-11-29 23:23:28 +0000108
Greg Suarez2d1c4312012-10-22 10:56:30 +0000109 eth_hlen = ETH_HLEN;
110 min_dgram_size = CDC_NCM_MIN_DATAGRAM_SIZE;
111 min_hdr_size = CDC_NCM_MIN_HDR_SIZE;
112 if (ctx->mbim_desc != NULL) {
113 flags = ctx->mbim_desc->bmNetworkCapabilities;
114 eth_hlen = 0;
115 min_dgram_size = CDC_MBIM_MIN_DATAGRAM_SIZE;
116 min_hdr_size = 0;
117 } else if (ctx->func_desc != NULL) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000118 flags = ctx->func_desc->bmNetworkCapabilities;
Greg Suarez2d1c4312012-10-22 10:56:30 +0000119 } else {
Alexey Orishko900d4952010-11-29 23:23:28 +0000120 flags = 0;
Greg Suarez2d1c4312012-10-22 10:56:30 +0000121 }
Alexey Orishko900d4952010-11-29 23:23:28 +0000122
123 pr_debug("dwNtbInMaxSize=%u dwNtbOutMaxSize=%u "
124 "wNdpOutPayloadRemainder=%u wNdpOutDivisor=%u "
Alexey Orishko84e77a82011-02-07 09:45:10 +0000125 "wNdpOutAlignment=%u wNtbOutMaxDatagrams=%u flags=0x%x\n",
Alexey Orishko900d4952010-11-29 23:23:28 +0000126 ctx->rx_max, ctx->tx_max, ctx->tx_remainder, ctx->tx_modulus,
Alexey Orishko84e77a82011-02-07 09:45:10 +0000127 ctx->tx_ndp_modulus, ctx->tx_max_datagrams, flags);
Alexey Orishko900d4952010-11-29 23:23:28 +0000128
Alexey Orishko84e77a82011-02-07 09:45:10 +0000129 /* max count of tx datagrams */
130 if ((ctx->tx_max_datagrams == 0) ||
131 (ctx->tx_max_datagrams > CDC_NCM_DPT_DATAGRAMS_MAX))
132 ctx->tx_max_datagrams = CDC_NCM_DPT_DATAGRAMS_MAX;
Alexey Orishko900d4952010-11-29 23:23:28 +0000133
134 /* verify maximum size of received NTB in bytes */
Alexey Orishko84e77a82011-02-07 09:45:10 +0000135 if (ctx->rx_max < USB_CDC_NCM_NTB_MIN_IN_SIZE) {
136 pr_debug("Using min receive length=%d\n",
137 USB_CDC_NCM_NTB_MIN_IN_SIZE);
138 ctx->rx_max = USB_CDC_NCM_NTB_MIN_IN_SIZE;
139 }
140
141 if (ctx->rx_max > CDC_NCM_NTB_MAX_SIZE_RX) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000142 pr_debug("Using default maximum receive length=%d\n",
143 CDC_NCM_NTB_MAX_SIZE_RX);
144 ctx->rx_max = CDC_NCM_NTB_MAX_SIZE_RX;
145 }
146
Alexey Orishko84e77a82011-02-07 09:45:10 +0000147 /* inform device about NTB input size changes */
148 if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
Ming Lei90b8b032012-10-24 19:46:56 +0000149 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
Alexey Orishko84e77a82011-02-07 09:45:10 +0000150
Ming Lei90b8b032012-10-24 19:46:56 +0000151 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE,
152 USB_TYPE_CLASS | USB_DIR_OUT
153 | USB_RECIP_INTERFACE,
154 0, iface_no, &dwNtbInMaxSize, 4);
Giuseppe Scrivano36c35412011-08-03 22:10:29 +0000155 if (err < 0)
Alexey Orishko84e77a82011-02-07 09:45:10 +0000156 pr_debug("Setting NTB Input Size failed\n");
157 }
158
Alexey Orishko900d4952010-11-29 23:23:28 +0000159 /* verify maximum size of transmitted NTB in bytes */
160 if ((ctx->tx_max <
Greg Suarez2d1c4312012-10-22 10:56:30 +0000161 (min_hdr_size + min_dgram_size)) ||
Alexey Orishko900d4952010-11-29 23:23:28 +0000162 (ctx->tx_max > CDC_NCM_NTB_MAX_SIZE_TX)) {
163 pr_debug("Using default maximum transmit length=%d\n",
164 CDC_NCM_NTB_MAX_SIZE_TX);
165 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX;
166 }
167
168 /*
169 * verify that the structure alignment is:
170 * - power of two
171 * - not greater than the maximum transmit length
172 * - not less than four bytes
173 */
174 val = ctx->tx_ndp_modulus;
175
176 if ((val < USB_CDC_NCM_NDP_ALIGN_MIN_SIZE) ||
177 (val != ((-val) & val)) || (val >= ctx->tx_max)) {
178 pr_debug("Using default alignment: 4 bytes\n");
179 ctx->tx_ndp_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE;
180 }
181
182 /*
183 * verify that the payload alignment is:
184 * - power of two
185 * - not greater than the maximum transmit length
186 * - not less than four bytes
187 */
188 val = ctx->tx_modulus;
189
190 if ((val < USB_CDC_NCM_NDP_ALIGN_MIN_SIZE) ||
191 (val != ((-val) & val)) || (val >= ctx->tx_max)) {
192 pr_debug("Using default transmit modulus: 4 bytes\n");
193 ctx->tx_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE;
194 }
195
196 /* verify the payload remainder */
197 if (ctx->tx_remainder >= ctx->tx_modulus) {
198 pr_debug("Using default transmit remainder: 0 bytes\n");
199 ctx->tx_remainder = 0;
200 }
201
202 /* adjust TX-remainder according to NCM specification. */
Greg Suarez2d1c4312012-10-22 10:56:30 +0000203 ctx->tx_remainder = ((ctx->tx_remainder - eth_hlen) &
204 (ctx->tx_modulus - 1));
Alexey Orishko900d4952010-11-29 23:23:28 +0000205
206 /* additional configuration */
207
208 /* set CRC Mode */
Alexey Orishko84e77a82011-02-07 09:45:10 +0000209 if (flags & USB_CDC_NCM_NCAP_CRC_MODE) {
Ming Lei90b8b032012-10-24 19:46:56 +0000210 err = usbnet_write_cmd(dev, USB_CDC_SET_CRC_MODE,
211 USB_TYPE_CLASS | USB_DIR_OUT
212 | USB_RECIP_INTERFACE,
213 USB_CDC_NCM_CRC_NOT_APPENDED,
214 iface_no, NULL, 0);
Giuseppe Scrivano36c35412011-08-03 22:10:29 +0000215 if (err < 0)
Alexey Orishko84e77a82011-02-07 09:45:10 +0000216 pr_debug("Setting CRC mode off failed\n");
217 }
Alexey Orishko900d4952010-11-29 23:23:28 +0000218
Alexey Orishko84e77a82011-02-07 09:45:10 +0000219 /* set NTB format, if both formats are supported */
220 if (ntb_fmt_supported & USB_CDC_NCM_NTH32_SIGN) {
Ming Lei90b8b032012-10-24 19:46:56 +0000221 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_FORMAT,
222 USB_TYPE_CLASS | USB_DIR_OUT
223 | USB_RECIP_INTERFACE,
224 USB_CDC_NCM_NTB16_FORMAT,
225 iface_no, NULL, 0);
Giuseppe Scrivano36c35412011-08-03 22:10:29 +0000226 if (err < 0)
Alexey Orishko84e77a82011-02-07 09:45:10 +0000227 pr_debug("Setting NTB format to 16-bit failed\n");
228 }
229
Greg Suarez2d1c4312012-10-22 10:56:30 +0000230 ctx->max_datagram_size = min_dgram_size;
Alexey Orishko900d4952010-11-29 23:23:28 +0000231
232 /* set Max Datagram Size (MTU) */
Alexey Orishko84e77a82011-02-07 09:45:10 +0000233 if (flags & USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE) {
Ming Lei90b8b032012-10-24 19:46:56 +0000234 __le16 max_datagram_size;
Greg Suarez2d1c4312012-10-22 10:56:30 +0000235 u16 eth_max_sz;
236 if (ctx->ether_desc != NULL)
237 eth_max_sz = le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
238 else if (ctx->mbim_desc != NULL)
239 eth_max_sz = le16_to_cpu(ctx->mbim_desc->wMaxSegmentSize);
240 else
241 goto max_dgram_err;
Josh Boyer75bc8ef2011-08-08 02:34:07 +0000242
Ming Lei90b8b032012-10-24 19:46:56 +0000243 err = usbnet_read_cmd(dev, USB_CDC_GET_MAX_DATAGRAM_SIZE,
244 USB_TYPE_CLASS | USB_DIR_IN
245 | USB_RECIP_INTERFACE,
246 0, iface_no, &max_datagram_size, 2);
Giuseppe Scrivano36c35412011-08-03 22:10:29 +0000247 if (err < 0) {
Alexey Orishko84e77a82011-02-07 09:45:10 +0000248 pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
Greg Suarez2d1c4312012-10-22 10:56:30 +0000249 min_dgram_size);
Alexey Orishko84e77a82011-02-07 09:45:10 +0000250 } else {
Josh Boyer75bc8ef2011-08-08 02:34:07 +0000251 ctx->max_datagram_size =
Ming Lei90b8b032012-10-24 19:46:56 +0000252 le16_to_cpu(max_datagram_size);
Alexey Orishko84e77a82011-02-07 09:45:10 +0000253 /* Check Eth descriptor value */
Alexey Orishko3f658cd2012-03-14 11:26:11 +0000254 if (ctx->max_datagram_size > eth_max_sz)
Alexey Orishko84e77a82011-02-07 09:45:10 +0000255 ctx->max_datagram_size = eth_max_sz;
Alexey Orishko3f658cd2012-03-14 11:26:11 +0000256
257 if (ctx->max_datagram_size > CDC_NCM_MAX_DATAGRAM_SIZE)
Greg Suarez2d1c4312012-10-22 10:56:30 +0000258 ctx->max_datagram_size = CDC_NCM_MAX_DATAGRAM_SIZE;
Alexey Orishko84e77a82011-02-07 09:45:10 +0000259
Greg Suarez2d1c4312012-10-22 10:56:30 +0000260 if (ctx->max_datagram_size < min_dgram_size)
261 ctx->max_datagram_size = min_dgram_size;
Alexey Orishko84e77a82011-02-07 09:45:10 +0000262
263 /* if value changed, update device */
Alexey Orishko3f658cd2012-03-14 11:26:11 +0000264 if (ctx->max_datagram_size !=
Ming Lei90b8b032012-10-24 19:46:56 +0000265 le16_to_cpu(max_datagram_size)) {
266 err = usbnet_write_cmd(dev,
Giuseppe Scrivano36c35412011-08-03 22:10:29 +0000267 USB_CDC_SET_MAX_DATAGRAM_SIZE,
268 USB_TYPE_CLASS | USB_DIR_OUT
269 | USB_RECIP_INTERFACE,
270 0,
Ming Lei90b8b032012-10-24 19:46:56 +0000271 iface_no, &max_datagram_size,
272 2);
Alexey Orishko3f658cd2012-03-14 11:26:11 +0000273 if (err < 0)
274 pr_debug("SET_MAX_DGRAM_SIZE failed\n");
275 }
Alexey Orishko84e77a82011-02-07 09:45:10 +0000276 }
Alexey Orishko900d4952010-11-29 23:23:28 +0000277 }
278
Alexey Orishko3f658cd2012-03-14 11:26:11 +0000279max_dgram_err:
Greg Suarez2d1c4312012-10-22 10:56:30 +0000280 if (ctx->netdev->mtu != (ctx->max_datagram_size - eth_hlen))
281 ctx->netdev->mtu = ctx->max_datagram_size - eth_hlen;
Alexey Orishko900d4952010-11-29 23:23:28 +0000282
283 return 0;
284}
285
286static void
287cdc_ncm_find_endpoints(struct cdc_ncm_ctx *ctx, struct usb_interface *intf)
288{
289 struct usb_host_endpoint *e;
290 u8 ep;
291
292 for (ep = 0; ep < intf->cur_altsetting->desc.bNumEndpoints; ep++) {
293
294 e = intf->cur_altsetting->endpoint + ep;
295 switch (e->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
296 case USB_ENDPOINT_XFER_INT:
297 if (usb_endpoint_dir_in(&e->desc)) {
298 if (ctx->status_ep == NULL)
299 ctx->status_ep = e;
300 }
301 break;
302
303 case USB_ENDPOINT_XFER_BULK:
304 if (usb_endpoint_dir_in(&e->desc)) {
305 if (ctx->in_ep == NULL)
306 ctx->in_ep = e;
307 } else {
308 if (ctx->out_ep == NULL)
309 ctx->out_ep = e;
310 }
311 break;
312
313 default:
314 break;
315 }
316 }
317}
318
319static void cdc_ncm_free(struct cdc_ncm_ctx *ctx)
320{
321 if (ctx == NULL)
322 return;
323
Alexey Orishko900d4952010-11-29 23:23:28 +0000324 if (ctx->tx_rem_skb != NULL) {
325 dev_kfree_skb_any(ctx->tx_rem_skb);
326 ctx->tx_rem_skb = NULL;
327 }
328
329 if (ctx->tx_curr_skb != NULL) {
330 dev_kfree_skb_any(ctx->tx_curr_skb);
331 ctx->tx_curr_skb = NULL;
332 }
333
334 kfree(ctx);
335}
336
Dan Williamsf94898e2012-07-24 08:43:22 +0000337static const struct ethtool_ops cdc_ncm_ethtool_ops = {
338 .get_drvinfo = cdc_ncm_get_drvinfo,
339 .get_link = usbnet_get_link,
340 .get_msglevel = usbnet_get_msglevel,
341 .set_msglevel = usbnet_set_msglevel,
342 .get_settings = usbnet_get_settings,
343 .set_settings = usbnet_set_settings,
344 .nway_reset = usbnet_nway_reset,
345};
346
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000347int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_altsetting)
Alexey Orishko900d4952010-11-29 23:23:28 +0000348{
349 struct cdc_ncm_ctx *ctx;
350 struct usb_driver *driver;
351 u8 *buf;
352 int len;
353 int temp;
354 u8 iface_no;
355
Thomas Meyerc7969842011-11-17 12:43:40 +0000356 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
Alexey Orishko900d4952010-11-29 23:23:28 +0000357 if (ctx == NULL)
Alexey Orishko19694ac2011-05-24 05:26:13 +0000358 return -ENODEV;
Alexey Orishko900d4952010-11-29 23:23:28 +0000359
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000360 hrtimer_init(&ctx->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
361 ctx->tx_timer.function = &cdc_ncm_tx_timer_cb;
362 ctx->bh.data = (unsigned long)ctx;
363 ctx->bh.func = cdc_ncm_txpath_bh;
364 atomic_set(&ctx->stop, 0);
Alexey Orishko900d4952010-11-29 23:23:28 +0000365 spin_lock_init(&ctx->mtx);
366 ctx->netdev = dev->net;
367
368 /* store ctx pointer in device data field */
369 dev->data[0] = (unsigned long)ctx;
370
371 /* get some pointers */
372 driver = driver_of(intf);
373 buf = intf->cur_altsetting->extra;
374 len = intf->cur_altsetting->extralen;
375
376 ctx->udev = dev->udev;
377 ctx->intf = intf;
378
379 /* parse through descriptors associated with control interface */
380 while ((len > 0) && (buf[0] > 2) && (buf[0] <= len)) {
381
382 if (buf[1] != USB_DT_CS_INTERFACE)
383 goto advance;
384
385 switch (buf[2]) {
386 case USB_CDC_UNION_TYPE:
387 if (buf[0] < sizeof(*(ctx->union_desc)))
388 break;
389
390 ctx->union_desc =
391 (const struct usb_cdc_union_desc *)buf;
392
393 ctx->control = usb_ifnum_to_if(dev->udev,
394 ctx->union_desc->bMasterInterface0);
395 ctx->data = usb_ifnum_to_if(dev->udev,
396 ctx->union_desc->bSlaveInterface0);
397 break;
398
399 case USB_CDC_ETHERNET_TYPE:
400 if (buf[0] < sizeof(*(ctx->ether_desc)))
401 break;
402
403 ctx->ether_desc =
404 (const struct usb_cdc_ether_desc *)buf;
Alexey Orishko900d4952010-11-29 23:23:28 +0000405 dev->hard_mtu =
406 le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
407
Alexey Orishko84e77a82011-02-07 09:45:10 +0000408 if (dev->hard_mtu < CDC_NCM_MIN_DATAGRAM_SIZE)
409 dev->hard_mtu = CDC_NCM_MIN_DATAGRAM_SIZE;
410 else if (dev->hard_mtu > CDC_NCM_MAX_DATAGRAM_SIZE)
411 dev->hard_mtu = CDC_NCM_MAX_DATAGRAM_SIZE;
Alexey Orishko900d4952010-11-29 23:23:28 +0000412 break;
413
414 case USB_CDC_NCM_TYPE:
415 if (buf[0] < sizeof(*(ctx->func_desc)))
416 break;
417
418 ctx->func_desc = (const struct usb_cdc_ncm_desc *)buf;
419 break;
420
Greg Suarez38396e42012-10-22 10:56:31 +0000421 case USB_CDC_MBIM_TYPE:
422 if (buf[0] < sizeof(*(ctx->mbim_desc)))
423 break;
424
425 ctx->mbim_desc = (const struct usb_cdc_mbim_desc *)buf;
426 break;
427
Alexey Orishko900d4952010-11-29 23:23:28 +0000428 default:
429 break;
430 }
431advance:
432 /* advance to next descriptor */
433 temp = buf[0];
434 buf += temp;
435 len -= temp;
436 }
437
Bjørn Mork9992c2e2013-01-21 05:50:38 +0000438 /* some buggy devices have an IAD but no CDC Union */
Bjørn Mork56a666d2013-01-25 23:36:59 +0000439 if (!ctx->union_desc && intf->intf_assoc && intf->intf_assoc->bInterfaceCount == 2) {
440 ctx->control = intf;
441 ctx->data = usb_ifnum_to_if(dev->udev, intf->cur_altsetting->desc.bInterfaceNumber + 1);
442 dev_dbg(&intf->dev, "CDC Union missing - got slave from IAD\n");
Bjørn Mork9992c2e2013-01-21 05:50:38 +0000443 }
444
Alexey Orishko900d4952010-11-29 23:23:28 +0000445 /* check if we got everything */
446 if ((ctx->control == NULL) || (ctx->data == NULL) ||
Greg Suarez38396e42012-10-22 10:56:31 +0000447 ((!ctx->mbim_desc) && ((ctx->ether_desc == NULL) || (ctx->control != intf))))
Alexey Orishko900d4952010-11-29 23:23:28 +0000448 goto error;
449
Bjørn Morkbbc8d922012-11-13 03:19:43 +0000450 /* claim data interface, if different from control */
451 if (ctx->data != ctx->control) {
452 temp = usb_driver_claim_interface(driver, ctx->data, dev);
453 if (temp)
454 goto error;
455 }
Alexey Orishko900d4952010-11-29 23:23:28 +0000456
457 iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber;
458
459 /* reset data interface */
460 temp = usb_set_interface(dev->udev, iface_no, 0);
461 if (temp)
Alexey Orishko19694ac2011-05-24 05:26:13 +0000462 goto error2;
Alexey Orishko900d4952010-11-29 23:23:28 +0000463
464 /* initialize data interface */
465 if (cdc_ncm_setup(ctx))
Alexey Orishko19694ac2011-05-24 05:26:13 +0000466 goto error2;
Alexey Orishko900d4952010-11-29 23:23:28 +0000467
468 /* configure data interface */
Greg Suarez38396e42012-10-22 10:56:31 +0000469 temp = usb_set_interface(dev->udev, iface_no, data_altsetting);
Alexey Orishko900d4952010-11-29 23:23:28 +0000470 if (temp)
Alexey Orishko19694ac2011-05-24 05:26:13 +0000471 goto error2;
Alexey Orishko900d4952010-11-29 23:23:28 +0000472
473 cdc_ncm_find_endpoints(ctx, ctx->data);
474 cdc_ncm_find_endpoints(ctx, ctx->control);
475
476 if ((ctx->in_ep == NULL) || (ctx->out_ep == NULL) ||
477 (ctx->status_ep == NULL))
Alexey Orishko19694ac2011-05-24 05:26:13 +0000478 goto error2;
Alexey Orishko900d4952010-11-29 23:23:28 +0000479
480 dev->net->ethtool_ops = &cdc_ncm_ethtool_ops;
481
482 usb_set_intfdata(ctx->data, dev);
483 usb_set_intfdata(ctx->control, dev);
484 usb_set_intfdata(ctx->intf, dev);
485
Greg Suarez38396e42012-10-22 10:56:31 +0000486 if (ctx->ether_desc) {
487 temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress);
488 if (temp)
489 goto error2;
490 dev_info(&dev->udev->dev, "MAC-Address: %pM\n", dev->net->dev_addr);
491 }
Alexey Orishko900d4952010-11-29 23:23:28 +0000492
Alexey Orishko900d4952010-11-29 23:23:28 +0000493
494 dev->in = usb_rcvbulkpipe(dev->udev,
495 ctx->in_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
496 dev->out = usb_sndbulkpipe(dev->udev,
497 ctx->out_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
498 dev->status = ctx->status_ep;
499 dev->rx_urb_size = ctx->rx_max;
500
Alexey Orishko900d4952010-11-29 23:23:28 +0000501 ctx->tx_speed = ctx->rx_speed = 0;
502 return 0;
503
Alexey Orishko19694ac2011-05-24 05:26:13 +0000504error2:
505 usb_set_intfdata(ctx->control, NULL);
506 usb_set_intfdata(ctx->data, NULL);
Bjørn Mork6b4ef602013-01-21 05:50:40 +0000507 if (ctx->data != ctx->control)
508 usb_driver_release_interface(driver, ctx->data);
Alexey Orishko900d4952010-11-29 23:23:28 +0000509error:
510 cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]);
511 dev->data[0] = 0;
Alexey Orishko19694ac2011-05-24 05:26:13 +0000512 dev_info(&dev->udev->dev, "bind() failure\n");
Alexey Orishko900d4952010-11-29 23:23:28 +0000513 return -ENODEV;
514}
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000515EXPORT_SYMBOL_GPL(cdc_ncm_bind_common);
Alexey Orishko900d4952010-11-29 23:23:28 +0000516
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000517void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf)
Alexey Orishko900d4952010-11-29 23:23:28 +0000518{
519 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
Alexey Orishko19694ac2011-05-24 05:26:13 +0000520 struct usb_driver *driver = driver_of(intf);
Alexey Orishko900d4952010-11-29 23:23:28 +0000521
522 if (ctx == NULL)
523 return; /* no setup */
524
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000525 atomic_set(&ctx->stop, 1);
526
527 if (hrtimer_active(&ctx->tx_timer))
528 hrtimer_cancel(&ctx->tx_timer);
529
530 tasklet_kill(&ctx->bh);
531
Bjørn Morkbbc8d922012-11-13 03:19:43 +0000532 /* handle devices with combined control and data interface */
533 if (ctx->control == ctx->data)
534 ctx->data = NULL;
535
Alexey Orishko19694ac2011-05-24 05:26:13 +0000536 /* disconnect master --> disconnect slave */
537 if (intf == ctx->control && ctx->data) {
538 usb_set_intfdata(ctx->data, NULL);
Alexey Orishko900d4952010-11-29 23:23:28 +0000539 usb_driver_release_interface(driver, ctx->data);
Alexey Orishko19694ac2011-05-24 05:26:13 +0000540 ctx->data = NULL;
Alexey Orishko900d4952010-11-29 23:23:28 +0000541
Alexey Orishko19694ac2011-05-24 05:26:13 +0000542 } else if (intf == ctx->data && ctx->control) {
543 usb_set_intfdata(ctx->control, NULL);
Alexey Orishko900d4952010-11-29 23:23:28 +0000544 usb_driver_release_interface(driver, ctx->control);
Alexey Orishko19694ac2011-05-24 05:26:13 +0000545 ctx->control = NULL;
Alexey Orishko900d4952010-11-29 23:23:28 +0000546 }
547
Alexey Orishko19694ac2011-05-24 05:26:13 +0000548 usb_set_intfdata(ctx->intf, NULL);
Alexey Orishko900d4952010-11-29 23:23:28 +0000549 cdc_ncm_free(ctx);
550}
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000551EXPORT_SYMBOL_GPL(cdc_ncm_unbind);
Alexey Orishko900d4952010-11-29 23:23:28 +0000552
Greg Suarez38396e42012-10-22 10:56:31 +0000553static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
554{
555 int ret;
556
Bjørn Morkbd329e12012-10-22 10:56:38 +0000557 /* The MBIM spec defines a NCM compatible default altsetting,
558 * which we may have matched:
559 *
560 * "Functions that implement both NCM 1.0 and MBIM (an
561 * “NCM/MBIM function”) according to this recommendation
562 * shall provide two alternate settings for the
563 * Communication Interface. Alternate setting 0, and the
564 * associated class and endpoint descriptors, shall be
565 * constructed according to the rules given for the
566 * Communication Interface in section 5 of [USBNCM10].
567 * Alternate setting 1, and the associated class and
568 * endpoint descriptors, shall be constructed according to
569 * the rules given in section 6 (USB Device Model) of this
570 * specification."
571 *
572 * Do not bind to such interfaces, allowing cdc_mbim to handle
573 * them
574 */
575#if IS_ENABLED(CONFIG_USB_NET_CDC_MBIM)
576 if ((intf->num_altsetting == 2) &&
577 !usb_set_interface(dev->udev,
578 intf->cur_altsetting->desc.bInterfaceNumber,
579 CDC_NCM_COMM_ALTSETTING_MBIM) &&
580 cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting))
581 return -ENODEV;
582#endif
583
Greg Suarez38396e42012-10-22 10:56:31 +0000584 /* NCM data altsetting is always 1 */
585 ret = cdc_ncm_bind_common(dev, intf, 1);
586
587 /*
588 * We should get an event when network connection is "connected" or
589 * "disconnected". Set network connection in "disconnected" state
590 * (carrier is OFF) during attach, so the IP network stack does not
591 * start IPv6 negotiation and more.
592 */
593 netif_carrier_off(dev->net);
594 return ret;
595}
596
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000597static void cdc_ncm_align_tail(struct sk_buff *skb, size_t modulus, size_t remainder, size_t max)
Alexey Orishko900d4952010-11-29 23:23:28 +0000598{
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000599 size_t align = ALIGN(skb->len, modulus) - skb->len + remainder;
600
601 if (skb->len + align > max)
602 align = max - skb->len;
603 if (align && skb_tailroom(skb) >= align)
604 memset(skb_put(skb, align), 0, align);
605}
606
607/* return a pointer to a valid struct usb_cdc_ncm_ndp16 of type sign, possibly
608 * allocating a new one within skb
609 */
610static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32 sign, size_t reserve)
611{
612 struct usb_cdc_ncm_ndp16 *ndp16 = NULL;
613 struct usb_cdc_ncm_nth16 *nth16 = (void *)skb->data;
614 size_t ndpoffset = le16_to_cpu(nth16->wNdpIndex);
615
616 /* follow the chain of NDPs, looking for a match */
617 while (ndpoffset) {
618 ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb->data + ndpoffset);
619 if (ndp16->dwSignature == sign)
620 return ndp16;
621 ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex);
622 }
623
624 /* align new NDP */
625 cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_max);
626
627 /* verify that there is room for the NDP and the datagram (reserve) */
628 if ((ctx->tx_max - skb->len - reserve) < CDC_NCM_NDP_SIZE)
629 return NULL;
630
631 /* link to it */
632 if (ndp16)
633 ndp16->wNextNdpIndex = cpu_to_le16(skb->len);
634 else
635 nth16->wNdpIndex = cpu_to_le16(skb->len);
636
637 /* push a new empty NDP */
638 ndp16 = (struct usb_cdc_ncm_ndp16 *)memset(skb_put(skb, CDC_NCM_NDP_SIZE), 0, CDC_NCM_NDP_SIZE);
639 ndp16->dwSignature = sign;
640 ndp16->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp16) + sizeof(struct usb_cdc_ncm_dpe16));
641 return ndp16;
Alexey Orishko900d4952010-11-29 23:23:28 +0000642}
643
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000644struct sk_buff *
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000645cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32 sign)
Alexey Orishko900d4952010-11-29 23:23:28 +0000646{
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000647 struct usb_cdc_ncm_nth16 *nth16;
648 struct usb_cdc_ncm_ndp16 *ndp16;
Alexey Orishko900d4952010-11-29 23:23:28 +0000649 struct sk_buff *skb_out;
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000650 u16 n = 0, index, ndplen;
Alexey Orishko84e77a82011-02-07 09:45:10 +0000651 u8 ready2send = 0;
Alexey Orishko900d4952010-11-29 23:23:28 +0000652
653 /* if there is a remaining skb, it gets priority */
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000654 if (skb != NULL) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000655 swap(skb, ctx->tx_rem_skb);
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000656 swap(sign, ctx->tx_rem_sign);
657 } else {
Alexey Orishko84e77a82011-02-07 09:45:10 +0000658 ready2send = 1;
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000659 }
Alexey Orishko900d4952010-11-29 23:23:28 +0000660
661 /* check if we are resuming an OUT skb */
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000662 skb_out = ctx->tx_curr_skb;
Alexey Orishko900d4952010-11-29 23:23:28 +0000663
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000664 /* allocate a new OUT skb */
665 if (!skb_out) {
Alexey Orishko6c604082011-05-06 03:01:30 +0000666 skb_out = alloc_skb((ctx->tx_max + 1), GFP_ATOMIC);
Alexey Orishko900d4952010-11-29 23:23:28 +0000667 if (skb_out == NULL) {
668 if (skb != NULL) {
669 dev_kfree_skb_any(skb);
670 ctx->netdev->stats.tx_dropped++;
671 }
672 goto exit_no_skb;
673 }
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000674 /* fill out the initial 16-bit NTB header */
675 nth16 = (struct usb_cdc_ncm_nth16 *)memset(skb_put(skb_out, sizeof(struct usb_cdc_ncm_nth16)), 0, sizeof(struct usb_cdc_ncm_nth16));
676 nth16->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH16_SIGN);
677 nth16->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16));
678 nth16->wSequence = cpu_to_le16(ctx->tx_seq++);
Alexey Orishko900d4952010-11-29 23:23:28 +0000679
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000680 /* count total number of frames in this NTB */
Alexey Orishko900d4952010-11-29 23:23:28 +0000681 ctx->tx_curr_frame_num = 0;
682 }
683
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000684 for (n = ctx->tx_curr_frame_num; n < ctx->tx_max_datagrams; n++) {
685 /* send any remaining skb first */
Alexey Orishko900d4952010-11-29 23:23:28 +0000686 if (skb == NULL) {
687 skb = ctx->tx_rem_skb;
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000688 sign = ctx->tx_rem_sign;
Alexey Orishko900d4952010-11-29 23:23:28 +0000689 ctx->tx_rem_skb = NULL;
690
691 /* check for end of skb */
692 if (skb == NULL)
693 break;
694 }
695
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000696 /* get the appropriate NDP for this skb */
697 ndp16 = cdc_ncm_ndp(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder);
698
699 /* align beginning of next frame */
700 cdc_ncm_align_tail(skb_out, ctx->tx_modulus, ctx->tx_remainder, ctx->tx_max);
701
702 /* check if we had enough room left for both NDP and frame */
703 if (!ndp16 || skb_out->len + skb->len > ctx->tx_max) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000704 if (n == 0) {
705 /* won't fit, MTU problem? */
706 dev_kfree_skb_any(skb);
707 skb = NULL;
708 ctx->netdev->stats.tx_dropped++;
709 } else {
710 /* no room for skb - store for later */
711 if (ctx->tx_rem_skb != NULL) {
712 dev_kfree_skb_any(ctx->tx_rem_skb);
713 ctx->netdev->stats.tx_dropped++;
714 }
715 ctx->tx_rem_skb = skb;
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000716 ctx->tx_rem_sign = sign;
Alexey Orishko900d4952010-11-29 23:23:28 +0000717 skb = NULL;
Alexey Orishko84e77a82011-02-07 09:45:10 +0000718 ready2send = 1;
Alexey Orishko900d4952010-11-29 23:23:28 +0000719 }
720 break;
721 }
722
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000723 /* calculate frame number withing this NDP */
724 ndplen = le16_to_cpu(ndp16->wLength);
725 index = (ndplen - sizeof(struct usb_cdc_ncm_ndp16)) / sizeof(struct usb_cdc_ncm_dpe16) - 1;
Alexey Orishko900d4952010-11-29 23:23:28 +0000726
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000727 /* OK, add this skb */
728 ndp16->dpe16[index].wDatagramLength = cpu_to_le16(skb->len);
729 ndp16->dpe16[index].wDatagramIndex = cpu_to_le16(skb_out->len);
730 ndp16->wLength = cpu_to_le16(ndplen + sizeof(struct usb_cdc_ncm_dpe16));
731 memcpy(skb_put(skb_out, skb->len), skb->data, skb->len);
Alexey Orishko900d4952010-11-29 23:23:28 +0000732 dev_kfree_skb_any(skb);
733 skb = NULL;
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000734
735 /* send now if this NDP is full */
736 if (index >= CDC_NCM_DPT_DATAGRAMS_MAX) {
737 ready2send = 1;
738 break;
739 }
Alexey Orishko900d4952010-11-29 23:23:28 +0000740 }
741
742 /* free up any dangling skb */
743 if (skb != NULL) {
744 dev_kfree_skb_any(skb);
745 skb = NULL;
746 ctx->netdev->stats.tx_dropped++;
747 }
748
749 ctx->tx_curr_frame_num = n;
750
751 if (n == 0) {
752 /* wait for more frames */
753 /* push variables */
754 ctx->tx_curr_skb = skb_out;
Alexey Orishko900d4952010-11-29 23:23:28 +0000755 goto exit_no_skb;
756
Alexey Orishko84e77a82011-02-07 09:45:10 +0000757 } else if ((n < ctx->tx_max_datagrams) && (ready2send == 0)) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000758 /* wait for more frames */
759 /* push variables */
760 ctx->tx_curr_skb = skb_out;
Alexey Orishko900d4952010-11-29 23:23:28 +0000761 /* set the pending count */
762 if (n < CDC_NCM_RESTART_TIMER_DATAGRAM_CNT)
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000763 ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT;
Alexey Orishko900d4952010-11-29 23:23:28 +0000764 goto exit_no_skb;
765
766 } else {
767 /* frame goes out */
768 /* variables will be reset at next call */
769 }
770
Alexey Orishko900d4952010-11-29 23:23:28 +0000771 /*
772 * If collected data size is less or equal CDC_NCM_MIN_TX_PKT bytes,
773 * we send buffers as it is. If we get more data, it would be more
774 * efficient for USB HS mobile device with DMA engine to receive a full
775 * size NTB, than canceling DMA transfer and receiving a short packet.
776 */
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000777 if (skb_out->len > CDC_NCM_MIN_TX_PKT)
778 /* final zero padding */
779 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0, ctx->tx_max - skb_out->len);
Alexey Orishko900d4952010-11-29 23:23:28 +0000780
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000781 /* do we need to prevent a ZLP? */
782 if (((skb_out->len % le16_to_cpu(ctx->out_ep->desc.wMaxPacketSize)) == 0) &&
783 (skb_out->len < le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize)) && skb_tailroom(skb_out))
784 *skb_put(skb_out, 1) = 0; /* force short packet */
Alexey Orishko900d4952010-11-29 23:23:28 +0000785
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000786 /* set final frame length */
787 nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data;
788 nth16->wBlockLength = cpu_to_le16(skb_out->len);
Alexey Orishko900d4952010-11-29 23:23:28 +0000789
790 /* return skb */
791 ctx->tx_curr_skb = NULL;
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000792 ctx->netdev->stats.tx_packets += ctx->tx_curr_frame_num;
Alexey Orishko900d4952010-11-29 23:23:28 +0000793 return skb_out;
794
795exit_no_skb:
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000796 /* Start timer, if there is a remaining skb */
797 if (ctx->tx_curr_skb != NULL)
798 cdc_ncm_tx_timeout_start(ctx);
Alexey Orishko900d4952010-11-29 23:23:28 +0000799 return NULL;
800}
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000801EXPORT_SYMBOL_GPL(cdc_ncm_fill_tx_frame);
Alexey Orishko900d4952010-11-29 23:23:28 +0000802
803static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx)
804{
805 /* start timer, if not already started */
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000806 if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop)))
807 hrtimer_start(&ctx->tx_timer,
808 ktime_set(0, CDC_NCM_TIMER_INTERVAL),
809 HRTIMER_MODE_REL);
Alexey Orishko900d4952010-11-29 23:23:28 +0000810}
811
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000812static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *timer)
Alexey Orishko900d4952010-11-29 23:23:28 +0000813{
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000814 struct cdc_ncm_ctx *ctx =
815 container_of(timer, struct cdc_ncm_ctx, tx_timer);
Alexey Orishko900d4952010-11-29 23:23:28 +0000816
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000817 if (!atomic_read(&ctx->stop))
818 tasklet_schedule(&ctx->bh);
819 return HRTIMER_NORESTART;
820}
821
822static void cdc_ncm_txpath_bh(unsigned long param)
823{
824 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)param;
825
826 spin_lock_bh(&ctx->mtx);
Alexey Orishko900d4952010-11-29 23:23:28 +0000827 if (ctx->tx_timer_pending != 0) {
828 ctx->tx_timer_pending--;
Alexey Orishko900d4952010-11-29 23:23:28 +0000829 cdc_ncm_tx_timeout_start(ctx);
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000830 spin_unlock_bh(&ctx->mtx);
Alexey Orishkof742aa82011-01-17 07:07:25 +0000831 } else if (ctx->netdev != NULL) {
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000832 spin_unlock_bh(&ctx->mtx);
833 netif_tx_lock_bh(ctx->netdev);
Alexey Orishko900d4952010-11-29 23:23:28 +0000834 usbnet_start_xmit(NULL, ctx->netdev);
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000835 netif_tx_unlock_bh(ctx->netdev);
Bjørn Mork7b1e0cb2012-10-25 21:44:09 +0000836 } else {
837 spin_unlock_bh(&ctx->mtx);
Alexey Orishkof742aa82011-01-17 07:07:25 +0000838 }
Alexey Orishko900d4952010-11-29 23:23:28 +0000839}
840
841static struct sk_buff *
842cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
843{
844 struct sk_buff *skb_out;
845 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
Alexey Orishko900d4952010-11-29 23:23:28 +0000846
847 /*
848 * The Ethernet API we are using does not support transmitting
849 * multiple Ethernet frames in a single call. This driver will
850 * accumulate multiple Ethernet frames and send out a larger
851 * USB frame when the USB buffer is full or when a single jiffies
852 * timeout happens.
853 */
854 if (ctx == NULL)
855 goto error;
856
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000857 spin_lock_bh(&ctx->mtx);
Bjørn Morkc78b7c52012-10-22 10:56:34 +0000858 skb_out = cdc_ncm_fill_tx_frame(ctx, skb, cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN));
Alexey Orishkoc84ff1d2012-03-14 11:26:10 +0000859 spin_unlock_bh(&ctx->mtx);
Alexey Orishko900d4952010-11-29 23:23:28 +0000860 return skb_out;
861
862error:
863 if (skb != NULL)
864 dev_kfree_skb_any(skb);
865
866 return NULL;
867}
868
Bjørn Morkff06ab12012-10-22 10:56:33 +0000869/* verify NTB header and return offset of first NDP, or negative error */
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000870int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_in)
Alexey Orishko900d4952010-11-29 23:23:28 +0000871{
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000872 struct usb_cdc_ncm_nth16 *nth16;
Bjørn Morkff06ab12012-10-22 10:56:33 +0000873 int len;
874 int ret = -EINVAL;
Alexey Orishko900d4952010-11-29 23:23:28 +0000875
Alexey Orishko900d4952010-11-29 23:23:28 +0000876 if (ctx == NULL)
877 goto error;
878
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000879 if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth16) +
880 sizeof(struct usb_cdc_ncm_ndp16))) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000881 pr_debug("frame too short\n");
882 goto error;
883 }
884
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000885 nth16 = (struct usb_cdc_ncm_nth16 *)skb_in->data;
Alexey Orishko900d4952010-11-29 23:23:28 +0000886
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000887 if (le32_to_cpu(nth16->dwSignature) != USB_CDC_NCM_NTH16_SIGN) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000888 pr_debug("invalid NTH16 signature <%u>\n",
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000889 le32_to_cpu(nth16->dwSignature));
Alexey Orishko900d4952010-11-29 23:23:28 +0000890 goto error;
891 }
892
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000893 len = le16_to_cpu(nth16->wBlockLength);
894 if (len > ctx->rx_max) {
895 pr_debug("unsupported NTB block length %u/%u\n", len,
896 ctx->rx_max);
Alexey Orishko900d4952010-11-29 23:23:28 +0000897 goto error;
898 }
899
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000900 if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) &&
901 (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) &&
902 !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth16->wSequence))) {
903 pr_debug("sequence number glitch prev=%d curr=%d\n",
904 ctx->rx_seq, le16_to_cpu(nth16->wSequence));
905 }
906 ctx->rx_seq = le16_to_cpu(nth16->wSequence);
907
Bjørn Morkff06ab12012-10-22 10:56:33 +0000908 ret = le16_to_cpu(nth16->wNdpIndex);
909error:
910 return ret;
911}
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000912EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_nth16);
Bjørn Morkff06ab12012-10-22 10:56:33 +0000913
914/* verify NDP header and return number of datagrams, or negative error */
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000915int cdc_ncm_rx_verify_ndp16(struct sk_buff *skb_in, int ndpoffset)
Bjørn Morkff06ab12012-10-22 10:56:33 +0000916{
917 struct usb_cdc_ncm_ndp16 *ndp16;
918 int ret = -EINVAL;
919
Bjørn Mork75d67d32012-10-22 10:56:32 +0000920 if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp16)) > skb_in->len) {
921 pr_debug("invalid NDP offset <%u>\n", ndpoffset);
Alexey Orishko900d4952010-11-29 23:23:28 +0000922 goto error;
923 }
Bjørn Mork75d67d32012-10-22 10:56:32 +0000924 ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset);
Alexey Orishko900d4952010-11-29 23:23:28 +0000925
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000926 if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000927 pr_debug("invalid DPT16 length <%u>\n",
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000928 le32_to_cpu(ndp16->dwSignature));
Bjørn Morkff06ab12012-10-22 10:56:33 +0000929 goto error;
Alexey Orishko900d4952010-11-29 23:23:28 +0000930 }
931
Bjørn Morkff06ab12012-10-22 10:56:33 +0000932 ret = ((le16_to_cpu(ndp16->wLength) -
Alexey Orishko900d4952010-11-29 23:23:28 +0000933 sizeof(struct usb_cdc_ncm_ndp16)) /
934 sizeof(struct usb_cdc_ncm_dpe16));
Bjørn Morkff06ab12012-10-22 10:56:33 +0000935 ret--; /* we process NDP entries except for the last one */
Alexey Orishko900d4952010-11-29 23:23:28 +0000936
Bjørn Morkff06ab12012-10-22 10:56:33 +0000937 if ((sizeof(struct usb_cdc_ncm_ndp16) + ret * (sizeof(struct usb_cdc_ncm_dpe16))) >
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000938 skb_in->len) {
Bjørn Morkff06ab12012-10-22 10:56:33 +0000939 pr_debug("Invalid nframes = %d\n", ret);
940 ret = -EINVAL;
Alexey Orishko900d4952010-11-29 23:23:28 +0000941 }
942
Bjørn Morkff06ab12012-10-22 10:56:33 +0000943error:
944 return ret;
945}
Bjørn Morkc91ce3b2012-10-22 10:56:35 +0000946EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_ndp16);
Bjørn Morkff06ab12012-10-22 10:56:33 +0000947
948static int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
949{
950 struct sk_buff *skb;
951 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
952 int len;
953 int nframes;
954 int x;
955 int offset;
956 struct usb_cdc_ncm_ndp16 *ndp16;
957 struct usb_cdc_ncm_dpe16 *dpe16;
958 int ndpoffset;
959 int loopcount = 50; /* arbitrary max preventing infinite loop */
960
961 ndpoffset = cdc_ncm_rx_verify_nth16(ctx, skb_in);
962 if (ndpoffset < 0)
963 goto error;
964
965next_ndp:
966 nframes = cdc_ncm_rx_verify_ndp16(skb_in, ndpoffset);
967 if (nframes < 0)
968 goto error;
969
970 ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset);
971
972 if (le32_to_cpu(ndp16->dwSignature) != USB_CDC_NCM_NDP16_NOCRC_SIGN) {
973 pr_debug("invalid DPT16 signature <%u>\n",
974 le32_to_cpu(ndp16->dwSignature));
975 goto err_ndp;
976 }
977 dpe16 = ndp16->dpe16;
Alexey Orishko900d4952010-11-29 23:23:28 +0000978
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000979 for (x = 0; x < nframes; x++, dpe16++) {
980 offset = le16_to_cpu(dpe16->wDatagramIndex);
981 len = le16_to_cpu(dpe16->wDatagramLength);
Alexey Orishko900d4952010-11-29 23:23:28 +0000982
983 /*
984 * CDC NCM ch. 3.7
985 * All entries after first NULL entry are to be ignored
986 */
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000987 if ((offset == 0) || (len == 0)) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000988 if (!x)
Bjørn Mork75d67d32012-10-22 10:56:32 +0000989 goto err_ndp; /* empty NTB */
Alexey Orishko900d4952010-11-29 23:23:28 +0000990 break;
991 }
992
993 /* sanity checking */
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000994 if (((offset + len) > skb_in->len) ||
995 (len > ctx->rx_max) || (len < ETH_HLEN)) {
Alexey Orishko900d4952010-11-29 23:23:28 +0000996 pr_debug("invalid frame detected (ignored)"
Alexey Orishkof742aa82011-01-17 07:07:25 +0000997 "offset[%u]=%u, length=%u, skb=%p\n",
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +0000998 x, offset, len, skb_in);
Alexey Orishko900d4952010-11-29 23:23:28 +0000999 if (!x)
Bjørn Mork75d67d32012-10-22 10:56:32 +00001000 goto err_ndp;
Alexey Orishko900d4952010-11-29 23:23:28 +00001001 break;
1002
1003 } else {
1004 skb = skb_clone(skb_in, GFP_ATOMIC);
Jesper Juhl9e567902011-01-13 11:40:11 +00001005 if (!skb)
1006 goto error;
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +00001007 skb->len = len;
Alexey Orishko900d4952010-11-29 23:23:28 +00001008 skb->data = ((u8 *)skb_in->data) + offset;
Alexey Orishkod5ddb4a2012-03-14 11:26:12 +00001009 skb_set_tail_pointer(skb, len);
Alexey Orishko900d4952010-11-29 23:23:28 +00001010 usbnet_skb_return(dev, skb);
1011 }
1012 }
Bjørn Mork75d67d32012-10-22 10:56:32 +00001013err_ndp:
1014 /* are there more NDPs to process? */
1015 ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex);
1016 if (ndpoffset && loopcount--)
1017 goto next_ndp;
1018
Alexey Orishko900d4952010-11-29 23:23:28 +00001019 return 1;
1020error:
1021 return 0;
1022}
1023
1024static void
1025cdc_ncm_speed_change(struct cdc_ncm_ctx *ctx,
Alexey Orishko84e77a82011-02-07 09:45:10 +00001026 struct usb_cdc_speed_change *data)
Alexey Orishko900d4952010-11-29 23:23:28 +00001027{
Alexey Orishko84e77a82011-02-07 09:45:10 +00001028 uint32_t rx_speed = le32_to_cpu(data->DLBitRRate);
1029 uint32_t tx_speed = le32_to_cpu(data->ULBitRate);
Alexey Orishko900d4952010-11-29 23:23:28 +00001030
1031 /*
1032 * Currently the USB-NET API does not support reporting the actual
1033 * device speed. Do print it instead.
1034 */
1035 if ((tx_speed != ctx->tx_speed) || (rx_speed != ctx->rx_speed)) {
1036 ctx->tx_speed = tx_speed;
1037 ctx->rx_speed = rx_speed;
1038
1039 if ((tx_speed > 1000000) && (rx_speed > 1000000)) {
1040 printk(KERN_INFO KBUILD_MODNAME
1041 ": %s: %u mbit/s downlink "
1042 "%u mbit/s uplink\n",
1043 ctx->netdev->name,
1044 (unsigned int)(rx_speed / 1000000U),
1045 (unsigned int)(tx_speed / 1000000U));
1046 } else {
1047 printk(KERN_INFO KBUILD_MODNAME
1048 ": %s: %u kbit/s downlink "
1049 "%u kbit/s uplink\n",
1050 ctx->netdev->name,
1051 (unsigned int)(rx_speed / 1000U),
1052 (unsigned int)(tx_speed / 1000U));
1053 }
1054 }
1055}
1056
1057static void cdc_ncm_status(struct usbnet *dev, struct urb *urb)
1058{
1059 struct cdc_ncm_ctx *ctx;
1060 struct usb_cdc_notification *event;
1061
1062 ctx = (struct cdc_ncm_ctx *)dev->data[0];
1063
1064 if (urb->actual_length < sizeof(*event))
1065 return;
1066
1067 /* test for split data in 8-byte chunks */
1068 if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) {
1069 cdc_ncm_speed_change(ctx,
Alexey Orishko84e77a82011-02-07 09:45:10 +00001070 (struct usb_cdc_speed_change *)urb->transfer_buffer);
Alexey Orishko900d4952010-11-29 23:23:28 +00001071 return;
1072 }
1073
1074 event = urb->transfer_buffer;
1075
1076 switch (event->bNotificationType) {
1077 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
1078 /*
1079 * According to the CDC NCM specification ch.7.1
1080 * USB_CDC_NOTIFY_NETWORK_CONNECTION notification shall be
1081 * sent by device after USB_CDC_NOTIFY_SPEED_CHANGE.
1082 */
Bjørn Mork1a7c6cc2012-10-25 21:44:08 +00001083 ctx->connected = le16_to_cpu(event->wValue);
Alexey Orishko900d4952010-11-29 23:23:28 +00001084
1085 printk(KERN_INFO KBUILD_MODNAME ": %s: network connection:"
1086 " %sconnected\n",
1087 ctx->netdev->name, ctx->connected ? "" : "dis");
1088
1089 if (ctx->connected)
1090 netif_carrier_on(dev->net);
1091 else {
1092 netif_carrier_off(dev->net);
1093 ctx->tx_speed = ctx->rx_speed = 0;
1094 }
1095 break;
1096
1097 case USB_CDC_NOTIFY_SPEED_CHANGE:
Alexey Orishko84e77a82011-02-07 09:45:10 +00001098 if (urb->actual_length < (sizeof(*event) +
1099 sizeof(struct usb_cdc_speed_change)))
Alexey Orishko900d4952010-11-29 23:23:28 +00001100 set_bit(EVENT_STS_SPLIT, &dev->flags);
1101 else
1102 cdc_ncm_speed_change(ctx,
Alexey Orishko84e77a82011-02-07 09:45:10 +00001103 (struct usb_cdc_speed_change *) &event[1]);
Alexey Orishko900d4952010-11-29 23:23:28 +00001104 break;
1105
1106 default:
1107 dev_err(&dev->udev->dev, "NCM: unexpected "
1108 "notification 0x%02x!\n", event->bNotificationType);
1109 break;
1110 }
1111}
1112
1113static int cdc_ncm_check_connect(struct usbnet *dev)
1114{
1115 struct cdc_ncm_ctx *ctx;
1116
1117 ctx = (struct cdc_ncm_ctx *)dev->data[0];
1118 if (ctx == NULL)
1119 return 1; /* disconnected */
1120
1121 return !ctx->connected;
1122}
1123
1124static int
1125cdc_ncm_probe(struct usb_interface *udev, const struct usb_device_id *prod)
1126{
1127 return usbnet_probe(udev, prod);
1128}
1129
1130static void cdc_ncm_disconnect(struct usb_interface *intf)
1131{
1132 struct usbnet *dev = usb_get_intfdata(intf);
1133
1134 if (dev == NULL)
1135 return; /* already disconnected */
1136
1137 usbnet_disconnect(intf);
1138}
1139
Alexey Orishko900d4952010-11-29 23:23:28 +00001140static const struct driver_info cdc_ncm_info = {
1141 .description = "CDC NCM",
Arnd Bergmannc2613442011-04-01 20:12:02 -07001142 .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET,
Alexey Orishko900d4952010-11-29 23:23:28 +00001143 .bind = cdc_ncm_bind,
1144 .unbind = cdc_ncm_unbind,
1145 .check_connect = cdc_ncm_check_connect,
Oliver Neukuma5e40702012-12-18 04:46:12 +00001146 .manage_power = usbnet_manage_power,
Alexey Orishko900d4952010-11-29 23:23:28 +00001147 .status = cdc_ncm_status,
1148 .rx_fixup = cdc_ncm_rx_fixup,
1149 .tx_fixup = cdc_ncm_tx_fixup,
1150};
1151
Dan Williamsf94898e2012-07-24 08:43:22 +00001152/* Same as cdc_ncm_info, but with FLAG_WWAN */
1153static const struct driver_info wwan_info = {
1154 .description = "Mobile Broadband Network Device",
1155 .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET
1156 | FLAG_WWAN,
1157 .bind = cdc_ncm_bind,
1158 .unbind = cdc_ncm_unbind,
1159 .check_connect = cdc_ncm_check_connect,
Oliver Neukuma5e40702012-12-18 04:46:12 +00001160 .manage_power = usbnet_manage_power,
Dan Williamsf94898e2012-07-24 08:43:22 +00001161 .status = cdc_ncm_status,
1162 .rx_fixup = cdc_ncm_rx_fixup,
1163 .tx_fixup = cdc_ncm_tx_fixup,
1164};
1165
Wei Shuai2f62d5a2013-01-21 06:00:32 +00001166/* Same as wwan_info, but with FLAG_NOARP */
1167static const struct driver_info wwan_noarp_info = {
1168 .description = "Mobile Broadband Network Device (NO ARP)",
1169 .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET
1170 | FLAG_WWAN | FLAG_NOARP,
1171 .bind = cdc_ncm_bind,
1172 .unbind = cdc_ncm_unbind,
1173 .check_connect = cdc_ncm_check_connect,
1174 .manage_power = usbnet_manage_power,
1175 .status = cdc_ncm_status,
1176 .rx_fixup = cdc_ncm_rx_fixup,
1177 .tx_fixup = cdc_ncm_tx_fixup,
1178};
1179
Dan Williamsf94898e2012-07-24 08:43:22 +00001180static const struct usb_device_id cdc_devs[] = {
1181 /* Ericsson MBM devices like F5521gw */
1182 { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
1183 | USB_DEVICE_ID_MATCH_VENDOR,
1184 .idVendor = 0x0bdb,
1185 .bInterfaceClass = USB_CLASS_COMM,
1186 .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM,
1187 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
1188 .driver_info = (unsigned long) &wwan_info,
1189 },
1190
Peter Meiserf3a1ef92012-08-02 02:30:20 +00001191 /* Dell branded MBM devices like DW5550 */
1192 { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
1193 | USB_DEVICE_ID_MATCH_VENDOR,
1194 .idVendor = 0x413c,
1195 .bInterfaceClass = USB_CLASS_COMM,
1196 .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM,
1197 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
1198 .driver_info = (unsigned long) &wwan_info,
1199 },
1200
1201 /* Toshiba branded MBM devices */
1202 { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
1203 | USB_DEVICE_ID_MATCH_VENDOR,
1204 .idVendor = 0x0930,
1205 .bInterfaceClass = USB_CLASS_COMM,
1206 .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM,
1207 .bInterfaceProtocol = USB_CDC_PROTO_NONE,
1208 .driver_info = (unsigned long) &wwan_info,
1209 },
1210
Bjørn Morkbbc8d922012-11-13 03:19:43 +00001211 /* Huawei NCM devices disguised as vendor specific */
1212 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x16),
1213 .driver_info = (unsigned long)&wwan_info,
1214 },
1215 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x46),
1216 .driver_info = (unsigned long)&wwan_info,
1217 },
1218
Wei Shuai2f62d5a2013-01-21 06:00:32 +00001219 /* Infineon(now Intel) HSPA Modem platform */
1220 { USB_DEVICE_AND_INTERFACE_INFO(0x1519, 0x0443,
1221 USB_CLASS_COMM,
1222 USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
1223 .driver_info = (unsigned long)&wwan_noarp_info,
1224 },
1225
Dan Williamsf94898e2012-07-24 08:43:22 +00001226 /* Generic CDC-NCM devices */
1227 { USB_INTERFACE_INFO(USB_CLASS_COMM,
1228 USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
1229 .driver_info = (unsigned long)&cdc_ncm_info,
1230 },
1231 {
1232 },
1233};
1234MODULE_DEVICE_TABLE(usb, cdc_devs);
1235
Alexey Orishko900d4952010-11-29 23:23:28 +00001236static struct usb_driver cdc_ncm_driver = {
1237 .name = "cdc_ncm",
1238 .id_table = cdc_devs,
1239 .probe = cdc_ncm_probe,
1240 .disconnect = cdc_ncm_disconnect,
1241 .suspend = usbnet_suspend,
1242 .resume = usbnet_resume,
Stefan Metzmacher85e3c652011-06-01 02:01:41 +00001243 .reset_resume = usbnet_resume,
Alexey Orishko900d4952010-11-29 23:23:28 +00001244 .supports_autosuspend = 1,
Sarah Sharpe1f12eb2012-04-23 10:08:51 -07001245 .disable_hub_initiated_lpm = 1,
Alexey Orishko900d4952010-11-29 23:23:28 +00001246};
1247
Greg Kroah-Hartmand632eb12011-11-18 09:44:20 -08001248module_usb_driver(cdc_ncm_driver);
Alexey Orishko900d4952010-11-29 23:23:28 +00001249
1250MODULE_AUTHOR("Hans Petter Selasky");
1251MODULE_DESCRIPTION("USB CDC NCM host driver");
1252MODULE_LICENSE("Dual BSD/GPL");