Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * cdc_ncm.c |
| 3 | * |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 4 | * Copyright (C) ST-Ericsson 2010-2012 |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 5 | * 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 Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 50 | #include <linux/hrtimer.h> |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 51 | #include <linux/atomic.h> |
| 52 | #include <linux/usb/usbnet.h> |
| 53 | #include <linux/usb/cdc.h> |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 54 | #include <linux/usb/cdc_ncm.h> |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 55 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 56 | #define DRIVER_VERSION "14-Mar-2012" |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 57 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 58 | static void cdc_ncm_txpath_bh(unsigned long param); |
| 59 | static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx); |
| 60 | static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 61 | static struct usb_driver cdc_ncm_driver; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 62 | |
| 63 | static void |
| 64 | cdc_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 Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 75 | static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx) |
| 76 | { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 77 | u32 val; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 78 | u8 flags; |
| 79 | u8 iface_no; |
| 80 | int err; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 81 | int eth_hlen; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 82 | u16 ntb_fmt_supported; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 83 | u32 min_dgram_size; |
| 84 | u32 min_hdr_size; |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 85 | struct usbnet *dev = netdev_priv(ctx->netdev); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 86 | |
| 87 | iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber; |
| 88 | |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 89 | 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 Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 94 | if (err < 0) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 95 | 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 Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 105 | /* 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 Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 108 | |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 109 | 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 Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 118 | flags = ctx->func_desc->bmNetworkCapabilities; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 119 | } else { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 120 | flags = 0; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 121 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 122 | |
| 123 | pr_debug("dwNtbInMaxSize=%u dwNtbOutMaxSize=%u " |
| 124 | "wNdpOutPayloadRemainder=%u wNdpOutDivisor=%u " |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 125 | "wNdpOutAlignment=%u wNtbOutMaxDatagrams=%u flags=0x%x\n", |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 126 | ctx->rx_max, ctx->tx_max, ctx->tx_remainder, ctx->tx_modulus, |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 127 | ctx->tx_ndp_modulus, ctx->tx_max_datagrams, flags); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 128 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 129 | /* 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 Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 133 | |
| 134 | /* verify maximum size of received NTB in bytes */ |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 135 | 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 Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 142 | 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 Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 147 | /* inform device about NTB input size changes */ |
| 148 | if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) { |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 149 | __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max); |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 150 | |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 151 | 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 Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 155 | if (err < 0) |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 156 | pr_debug("Setting NTB Input Size failed\n"); |
| 157 | } |
| 158 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 159 | /* verify maximum size of transmitted NTB in bytes */ |
| 160 | if ((ctx->tx_max < |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 161 | (min_hdr_size + min_dgram_size)) || |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 162 | (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 Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 203 | ctx->tx_remainder = ((ctx->tx_remainder - eth_hlen) & |
| 204 | (ctx->tx_modulus - 1)); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 205 | |
| 206 | /* additional configuration */ |
| 207 | |
| 208 | /* set CRC Mode */ |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 209 | if (flags & USB_CDC_NCM_NCAP_CRC_MODE) { |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 210 | 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 Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 215 | if (err < 0) |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 216 | pr_debug("Setting CRC mode off failed\n"); |
| 217 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 218 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 219 | /* set NTB format, if both formats are supported */ |
| 220 | if (ntb_fmt_supported & USB_CDC_NCM_NTH32_SIGN) { |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 221 | 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 Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 226 | if (err < 0) |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 227 | pr_debug("Setting NTB format to 16-bit failed\n"); |
| 228 | } |
| 229 | |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 230 | ctx->max_datagram_size = min_dgram_size; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 231 | |
| 232 | /* set Max Datagram Size (MTU) */ |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 233 | if (flags & USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE) { |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 234 | __le16 max_datagram_size; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 235 | 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 Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 242 | |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 243 | 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 Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 247 | if (err < 0) { |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 248 | pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n", |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 249 | min_dgram_size); |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 250 | } else { |
Josh Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 251 | ctx->max_datagram_size = |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 252 | le16_to_cpu(max_datagram_size); |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 253 | /* Check Eth descriptor value */ |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 254 | if (ctx->max_datagram_size > eth_max_sz) |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 255 | ctx->max_datagram_size = eth_max_sz; |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 256 | |
| 257 | if (ctx->max_datagram_size > CDC_NCM_MAX_DATAGRAM_SIZE) |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 258 | ctx->max_datagram_size = CDC_NCM_MAX_DATAGRAM_SIZE; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 259 | |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 260 | if (ctx->max_datagram_size < min_dgram_size) |
| 261 | ctx->max_datagram_size = min_dgram_size; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 262 | |
| 263 | /* if value changed, update device */ |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 264 | if (ctx->max_datagram_size != |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 265 | le16_to_cpu(max_datagram_size)) { |
| 266 | err = usbnet_write_cmd(dev, |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 267 | USB_CDC_SET_MAX_DATAGRAM_SIZE, |
| 268 | USB_TYPE_CLASS | USB_DIR_OUT |
| 269 | | USB_RECIP_INTERFACE, |
| 270 | 0, |
Ming Lei | 90b8b03 | 2012-10-24 19:46:56 +0000 | [diff] [blame] | 271 | iface_no, &max_datagram_size, |
| 272 | 2); |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 273 | if (err < 0) |
| 274 | pr_debug("SET_MAX_DGRAM_SIZE failed\n"); |
| 275 | } |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 276 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 279 | max_dgram_err: |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 280 | if (ctx->netdev->mtu != (ctx->max_datagram_size - eth_hlen)) |
| 281 | ctx->netdev->mtu = ctx->max_datagram_size - eth_hlen; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static void |
| 287 | cdc_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 | |
| 319 | static void cdc_ncm_free(struct cdc_ncm_ctx *ctx) |
| 320 | { |
| 321 | if (ctx == NULL) |
| 322 | return; |
| 323 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 324 | 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 Williams | f94898e | 2012-07-24 08:43:22 +0000 | [diff] [blame] | 337 | static 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 Mork | 9992c2e | 2013-01-21 05:50:38 +0000 | [diff] [blame^] | 347 | /* return first slave interface if an IAD matches the given master */ |
| 348 | static struct usb_interface *get_iad_slave(struct usb_device *udev, |
| 349 | struct usb_interface *master) { |
| 350 | int i; |
| 351 | struct usb_interface_assoc_descriptor *iad; |
| 352 | u8 mnum = master->cur_altsetting->desc.bInterfaceNumber; |
| 353 | |
| 354 | for (i = 0; i < USB_MAXIADS; i++) { |
| 355 | iad = udev->actconfig->intf_assoc[i]; |
| 356 | if (!iad) |
| 357 | break; |
| 358 | if (iad->bFirstInterface == mnum && iad->bInterfaceCount == 2) |
| 359 | return usb_ifnum_to_if(udev, mnum + 1); |
| 360 | } |
| 361 | return NULL; |
| 362 | } |
| 363 | |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 364 | int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_altsetting) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 365 | { |
| 366 | struct cdc_ncm_ctx *ctx; |
| 367 | struct usb_driver *driver; |
| 368 | u8 *buf; |
| 369 | int len; |
| 370 | int temp; |
| 371 | u8 iface_no; |
| 372 | |
Thomas Meyer | c796984 | 2011-11-17 12:43:40 +0000 | [diff] [blame] | 373 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 374 | if (ctx == NULL) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 375 | return -ENODEV; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 376 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 377 | hrtimer_init(&ctx->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 378 | ctx->tx_timer.function = &cdc_ncm_tx_timer_cb; |
| 379 | ctx->bh.data = (unsigned long)ctx; |
| 380 | ctx->bh.func = cdc_ncm_txpath_bh; |
| 381 | atomic_set(&ctx->stop, 0); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 382 | spin_lock_init(&ctx->mtx); |
| 383 | ctx->netdev = dev->net; |
| 384 | |
| 385 | /* store ctx pointer in device data field */ |
| 386 | dev->data[0] = (unsigned long)ctx; |
| 387 | |
| 388 | /* get some pointers */ |
| 389 | driver = driver_of(intf); |
| 390 | buf = intf->cur_altsetting->extra; |
| 391 | len = intf->cur_altsetting->extralen; |
| 392 | |
| 393 | ctx->udev = dev->udev; |
| 394 | ctx->intf = intf; |
| 395 | |
| 396 | /* parse through descriptors associated with control interface */ |
| 397 | while ((len > 0) && (buf[0] > 2) && (buf[0] <= len)) { |
| 398 | |
| 399 | if (buf[1] != USB_DT_CS_INTERFACE) |
| 400 | goto advance; |
| 401 | |
| 402 | switch (buf[2]) { |
| 403 | case USB_CDC_UNION_TYPE: |
| 404 | if (buf[0] < sizeof(*(ctx->union_desc))) |
| 405 | break; |
| 406 | |
| 407 | ctx->union_desc = |
| 408 | (const struct usb_cdc_union_desc *)buf; |
| 409 | |
| 410 | ctx->control = usb_ifnum_to_if(dev->udev, |
| 411 | ctx->union_desc->bMasterInterface0); |
| 412 | ctx->data = usb_ifnum_to_if(dev->udev, |
| 413 | ctx->union_desc->bSlaveInterface0); |
| 414 | break; |
| 415 | |
| 416 | case USB_CDC_ETHERNET_TYPE: |
| 417 | if (buf[0] < sizeof(*(ctx->ether_desc))) |
| 418 | break; |
| 419 | |
| 420 | ctx->ether_desc = |
| 421 | (const struct usb_cdc_ether_desc *)buf; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 422 | dev->hard_mtu = |
| 423 | le16_to_cpu(ctx->ether_desc->wMaxSegmentSize); |
| 424 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 425 | if (dev->hard_mtu < CDC_NCM_MIN_DATAGRAM_SIZE) |
| 426 | dev->hard_mtu = CDC_NCM_MIN_DATAGRAM_SIZE; |
| 427 | else if (dev->hard_mtu > CDC_NCM_MAX_DATAGRAM_SIZE) |
| 428 | dev->hard_mtu = CDC_NCM_MAX_DATAGRAM_SIZE; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 429 | break; |
| 430 | |
| 431 | case USB_CDC_NCM_TYPE: |
| 432 | if (buf[0] < sizeof(*(ctx->func_desc))) |
| 433 | break; |
| 434 | |
| 435 | ctx->func_desc = (const struct usb_cdc_ncm_desc *)buf; |
| 436 | break; |
| 437 | |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 438 | case USB_CDC_MBIM_TYPE: |
| 439 | if (buf[0] < sizeof(*(ctx->mbim_desc))) |
| 440 | break; |
| 441 | |
| 442 | ctx->mbim_desc = (const struct usb_cdc_mbim_desc *)buf; |
| 443 | break; |
| 444 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 445 | default: |
| 446 | break; |
| 447 | } |
| 448 | advance: |
| 449 | /* advance to next descriptor */ |
| 450 | temp = buf[0]; |
| 451 | buf += temp; |
| 452 | len -= temp; |
| 453 | } |
| 454 | |
Bjørn Mork | 9992c2e | 2013-01-21 05:50:38 +0000 | [diff] [blame^] | 455 | /* some buggy devices have an IAD but no CDC Union */ |
| 456 | if (!ctx->union_desc) { |
| 457 | dev_dbg(&intf->dev, "missing CDC Union descriptor\n"); |
| 458 | ctx->data = get_iad_slave(dev->udev, intf); |
| 459 | if (ctx->data) { |
| 460 | ctx->control = intf; |
| 461 | dev_dbg(&intf->dev, "got slave from IAD\n"); |
| 462 | } |
| 463 | } |
| 464 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 465 | /* check if we got everything */ |
| 466 | if ((ctx->control == NULL) || (ctx->data == NULL) || |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 467 | ((!ctx->mbim_desc) && ((ctx->ether_desc == NULL) || (ctx->control != intf)))) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 468 | goto error; |
| 469 | |
Bjørn Mork | bbc8d92 | 2012-11-13 03:19:43 +0000 | [diff] [blame] | 470 | /* claim data interface, if different from control */ |
| 471 | if (ctx->data != ctx->control) { |
| 472 | temp = usb_driver_claim_interface(driver, ctx->data, dev); |
| 473 | if (temp) |
| 474 | goto error; |
| 475 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 476 | |
| 477 | iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; |
| 478 | |
| 479 | /* reset data interface */ |
| 480 | temp = usb_set_interface(dev->udev, iface_no, 0); |
| 481 | if (temp) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 482 | goto error2; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 483 | |
| 484 | /* initialize data interface */ |
| 485 | if (cdc_ncm_setup(ctx)) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 486 | goto error2; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 487 | |
| 488 | /* configure data interface */ |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 489 | temp = usb_set_interface(dev->udev, iface_no, data_altsetting); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 490 | if (temp) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 491 | goto error2; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 492 | |
| 493 | cdc_ncm_find_endpoints(ctx, ctx->data); |
| 494 | cdc_ncm_find_endpoints(ctx, ctx->control); |
| 495 | |
| 496 | if ((ctx->in_ep == NULL) || (ctx->out_ep == NULL) || |
| 497 | (ctx->status_ep == NULL)) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 498 | goto error2; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 499 | |
| 500 | dev->net->ethtool_ops = &cdc_ncm_ethtool_ops; |
| 501 | |
| 502 | usb_set_intfdata(ctx->data, dev); |
| 503 | usb_set_intfdata(ctx->control, dev); |
| 504 | usb_set_intfdata(ctx->intf, dev); |
| 505 | |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 506 | if (ctx->ether_desc) { |
| 507 | temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress); |
| 508 | if (temp) |
| 509 | goto error2; |
| 510 | dev_info(&dev->udev->dev, "MAC-Address: %pM\n", dev->net->dev_addr); |
| 511 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 512 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 513 | |
| 514 | dev->in = usb_rcvbulkpipe(dev->udev, |
| 515 | ctx->in_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
| 516 | dev->out = usb_sndbulkpipe(dev->udev, |
| 517 | ctx->out_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
| 518 | dev->status = ctx->status_ep; |
| 519 | dev->rx_urb_size = ctx->rx_max; |
| 520 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 521 | ctx->tx_speed = ctx->rx_speed = 0; |
| 522 | return 0; |
| 523 | |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 524 | error2: |
| 525 | usb_set_intfdata(ctx->control, NULL); |
| 526 | usb_set_intfdata(ctx->data, NULL); |
| 527 | usb_driver_release_interface(driver, ctx->data); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 528 | error: |
| 529 | cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]); |
| 530 | dev->data[0] = 0; |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 531 | dev_info(&dev->udev->dev, "bind() failure\n"); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 532 | return -ENODEV; |
| 533 | } |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 534 | EXPORT_SYMBOL_GPL(cdc_ncm_bind_common); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 535 | |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 536 | void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 537 | { |
| 538 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 539 | struct usb_driver *driver = driver_of(intf); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 540 | |
| 541 | if (ctx == NULL) |
| 542 | return; /* no setup */ |
| 543 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 544 | atomic_set(&ctx->stop, 1); |
| 545 | |
| 546 | if (hrtimer_active(&ctx->tx_timer)) |
| 547 | hrtimer_cancel(&ctx->tx_timer); |
| 548 | |
| 549 | tasklet_kill(&ctx->bh); |
| 550 | |
Bjørn Mork | bbc8d92 | 2012-11-13 03:19:43 +0000 | [diff] [blame] | 551 | /* handle devices with combined control and data interface */ |
| 552 | if (ctx->control == ctx->data) |
| 553 | ctx->data = NULL; |
| 554 | |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 555 | /* disconnect master --> disconnect slave */ |
| 556 | if (intf == ctx->control && ctx->data) { |
| 557 | usb_set_intfdata(ctx->data, NULL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 558 | usb_driver_release_interface(driver, ctx->data); |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 559 | ctx->data = NULL; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 560 | |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 561 | } else if (intf == ctx->data && ctx->control) { |
| 562 | usb_set_intfdata(ctx->control, NULL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 563 | usb_driver_release_interface(driver, ctx->control); |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 564 | ctx->control = NULL; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 567 | usb_set_intfdata(ctx->intf, NULL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 568 | cdc_ncm_free(ctx); |
| 569 | } |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 570 | EXPORT_SYMBOL_GPL(cdc_ncm_unbind); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 571 | |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 572 | static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf) |
| 573 | { |
| 574 | int ret; |
| 575 | |
Bjørn Mork | bd329e1 | 2012-10-22 10:56:38 +0000 | [diff] [blame] | 576 | /* The MBIM spec defines a NCM compatible default altsetting, |
| 577 | * which we may have matched: |
| 578 | * |
| 579 | * "Functions that implement both NCM 1.0 and MBIM (an |
| 580 | * “NCM/MBIM function”) according to this recommendation |
| 581 | * shall provide two alternate settings for the |
| 582 | * Communication Interface. Alternate setting 0, and the |
| 583 | * associated class and endpoint descriptors, shall be |
| 584 | * constructed according to the rules given for the |
| 585 | * Communication Interface in section 5 of [USBNCM10]. |
| 586 | * Alternate setting 1, and the associated class and |
| 587 | * endpoint descriptors, shall be constructed according to |
| 588 | * the rules given in section 6 (USB Device Model) of this |
| 589 | * specification." |
| 590 | * |
| 591 | * Do not bind to such interfaces, allowing cdc_mbim to handle |
| 592 | * them |
| 593 | */ |
| 594 | #if IS_ENABLED(CONFIG_USB_NET_CDC_MBIM) |
| 595 | if ((intf->num_altsetting == 2) && |
| 596 | !usb_set_interface(dev->udev, |
| 597 | intf->cur_altsetting->desc.bInterfaceNumber, |
| 598 | CDC_NCM_COMM_ALTSETTING_MBIM) && |
| 599 | cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting)) |
| 600 | return -ENODEV; |
| 601 | #endif |
| 602 | |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 603 | /* NCM data altsetting is always 1 */ |
| 604 | ret = cdc_ncm_bind_common(dev, intf, 1); |
| 605 | |
| 606 | /* |
| 607 | * We should get an event when network connection is "connected" or |
| 608 | * "disconnected". Set network connection in "disconnected" state |
| 609 | * (carrier is OFF) during attach, so the IP network stack does not |
| 610 | * start IPv6 negotiation and more. |
| 611 | */ |
| 612 | netif_carrier_off(dev->net); |
| 613 | return ret; |
| 614 | } |
| 615 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 616 | static void cdc_ncm_align_tail(struct sk_buff *skb, size_t modulus, size_t remainder, size_t max) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 617 | { |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 618 | size_t align = ALIGN(skb->len, modulus) - skb->len + remainder; |
| 619 | |
| 620 | if (skb->len + align > max) |
| 621 | align = max - skb->len; |
| 622 | if (align && skb_tailroom(skb) >= align) |
| 623 | memset(skb_put(skb, align), 0, align); |
| 624 | } |
| 625 | |
| 626 | /* return a pointer to a valid struct usb_cdc_ncm_ndp16 of type sign, possibly |
| 627 | * allocating a new one within skb |
| 628 | */ |
| 629 | static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32 sign, size_t reserve) |
| 630 | { |
| 631 | struct usb_cdc_ncm_ndp16 *ndp16 = NULL; |
| 632 | struct usb_cdc_ncm_nth16 *nth16 = (void *)skb->data; |
| 633 | size_t ndpoffset = le16_to_cpu(nth16->wNdpIndex); |
| 634 | |
| 635 | /* follow the chain of NDPs, looking for a match */ |
| 636 | while (ndpoffset) { |
| 637 | ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb->data + ndpoffset); |
| 638 | if (ndp16->dwSignature == sign) |
| 639 | return ndp16; |
| 640 | ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex); |
| 641 | } |
| 642 | |
| 643 | /* align new NDP */ |
| 644 | cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_max); |
| 645 | |
| 646 | /* verify that there is room for the NDP and the datagram (reserve) */ |
| 647 | if ((ctx->tx_max - skb->len - reserve) < CDC_NCM_NDP_SIZE) |
| 648 | return NULL; |
| 649 | |
| 650 | /* link to it */ |
| 651 | if (ndp16) |
| 652 | ndp16->wNextNdpIndex = cpu_to_le16(skb->len); |
| 653 | else |
| 654 | nth16->wNdpIndex = cpu_to_le16(skb->len); |
| 655 | |
| 656 | /* push a new empty NDP */ |
| 657 | ndp16 = (struct usb_cdc_ncm_ndp16 *)memset(skb_put(skb, CDC_NCM_NDP_SIZE), 0, CDC_NCM_NDP_SIZE); |
| 658 | ndp16->dwSignature = sign; |
| 659 | ndp16->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp16) + sizeof(struct usb_cdc_ncm_dpe16)); |
| 660 | return ndp16; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 663 | struct sk_buff * |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 664 | cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32 sign) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 665 | { |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 666 | struct usb_cdc_ncm_nth16 *nth16; |
| 667 | struct usb_cdc_ncm_ndp16 *ndp16; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 668 | struct sk_buff *skb_out; |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 669 | u16 n = 0, index, ndplen; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 670 | u8 ready2send = 0; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 671 | |
| 672 | /* if there is a remaining skb, it gets priority */ |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 673 | if (skb != NULL) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 674 | swap(skb, ctx->tx_rem_skb); |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 675 | swap(sign, ctx->tx_rem_sign); |
| 676 | } else { |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 677 | ready2send = 1; |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 678 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 679 | |
| 680 | /* check if we are resuming an OUT skb */ |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 681 | skb_out = ctx->tx_curr_skb; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 682 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 683 | /* allocate a new OUT skb */ |
| 684 | if (!skb_out) { |
Alexey Orishko | 6c60408 | 2011-05-06 03:01:30 +0000 | [diff] [blame] | 685 | skb_out = alloc_skb((ctx->tx_max + 1), GFP_ATOMIC); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 686 | if (skb_out == NULL) { |
| 687 | if (skb != NULL) { |
| 688 | dev_kfree_skb_any(skb); |
| 689 | ctx->netdev->stats.tx_dropped++; |
| 690 | } |
| 691 | goto exit_no_skb; |
| 692 | } |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 693 | /* fill out the initial 16-bit NTB header */ |
| 694 | nth16 = (struct usb_cdc_ncm_nth16 *)memset(skb_put(skb_out, sizeof(struct usb_cdc_ncm_nth16)), 0, sizeof(struct usb_cdc_ncm_nth16)); |
| 695 | nth16->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH16_SIGN); |
| 696 | nth16->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16)); |
| 697 | nth16->wSequence = cpu_to_le16(ctx->tx_seq++); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 698 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 699 | /* count total number of frames in this NTB */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 700 | ctx->tx_curr_frame_num = 0; |
| 701 | } |
| 702 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 703 | for (n = ctx->tx_curr_frame_num; n < ctx->tx_max_datagrams; n++) { |
| 704 | /* send any remaining skb first */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 705 | if (skb == NULL) { |
| 706 | skb = ctx->tx_rem_skb; |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 707 | sign = ctx->tx_rem_sign; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 708 | ctx->tx_rem_skb = NULL; |
| 709 | |
| 710 | /* check for end of skb */ |
| 711 | if (skb == NULL) |
| 712 | break; |
| 713 | } |
| 714 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 715 | /* get the appropriate NDP for this skb */ |
| 716 | ndp16 = cdc_ncm_ndp(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder); |
| 717 | |
| 718 | /* align beginning of next frame */ |
| 719 | cdc_ncm_align_tail(skb_out, ctx->tx_modulus, ctx->tx_remainder, ctx->tx_max); |
| 720 | |
| 721 | /* check if we had enough room left for both NDP and frame */ |
| 722 | if (!ndp16 || skb_out->len + skb->len > ctx->tx_max) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 723 | if (n == 0) { |
| 724 | /* won't fit, MTU problem? */ |
| 725 | dev_kfree_skb_any(skb); |
| 726 | skb = NULL; |
| 727 | ctx->netdev->stats.tx_dropped++; |
| 728 | } else { |
| 729 | /* no room for skb - store for later */ |
| 730 | if (ctx->tx_rem_skb != NULL) { |
| 731 | dev_kfree_skb_any(ctx->tx_rem_skb); |
| 732 | ctx->netdev->stats.tx_dropped++; |
| 733 | } |
| 734 | ctx->tx_rem_skb = skb; |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 735 | ctx->tx_rem_sign = sign; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 736 | skb = NULL; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 737 | ready2send = 1; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 738 | } |
| 739 | break; |
| 740 | } |
| 741 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 742 | /* calculate frame number withing this NDP */ |
| 743 | ndplen = le16_to_cpu(ndp16->wLength); |
| 744 | index = (ndplen - sizeof(struct usb_cdc_ncm_ndp16)) / sizeof(struct usb_cdc_ncm_dpe16) - 1; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 745 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 746 | /* OK, add this skb */ |
| 747 | ndp16->dpe16[index].wDatagramLength = cpu_to_le16(skb->len); |
| 748 | ndp16->dpe16[index].wDatagramIndex = cpu_to_le16(skb_out->len); |
| 749 | ndp16->wLength = cpu_to_le16(ndplen + sizeof(struct usb_cdc_ncm_dpe16)); |
| 750 | memcpy(skb_put(skb_out, skb->len), skb->data, skb->len); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 751 | dev_kfree_skb_any(skb); |
| 752 | skb = NULL; |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 753 | |
| 754 | /* send now if this NDP is full */ |
| 755 | if (index >= CDC_NCM_DPT_DATAGRAMS_MAX) { |
| 756 | ready2send = 1; |
| 757 | break; |
| 758 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /* free up any dangling skb */ |
| 762 | if (skb != NULL) { |
| 763 | dev_kfree_skb_any(skb); |
| 764 | skb = NULL; |
| 765 | ctx->netdev->stats.tx_dropped++; |
| 766 | } |
| 767 | |
| 768 | ctx->tx_curr_frame_num = n; |
| 769 | |
| 770 | if (n == 0) { |
| 771 | /* wait for more frames */ |
| 772 | /* push variables */ |
| 773 | ctx->tx_curr_skb = skb_out; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 774 | goto exit_no_skb; |
| 775 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 776 | } else if ((n < ctx->tx_max_datagrams) && (ready2send == 0)) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 777 | /* wait for more frames */ |
| 778 | /* push variables */ |
| 779 | ctx->tx_curr_skb = skb_out; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 780 | /* set the pending count */ |
| 781 | if (n < CDC_NCM_RESTART_TIMER_DATAGRAM_CNT) |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 782 | ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 783 | goto exit_no_skb; |
| 784 | |
| 785 | } else { |
| 786 | /* frame goes out */ |
| 787 | /* variables will be reset at next call */ |
| 788 | } |
| 789 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 790 | /* |
| 791 | * If collected data size is less or equal CDC_NCM_MIN_TX_PKT bytes, |
| 792 | * we send buffers as it is. If we get more data, it would be more |
| 793 | * efficient for USB HS mobile device with DMA engine to receive a full |
| 794 | * size NTB, than canceling DMA transfer and receiving a short packet. |
| 795 | */ |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 796 | if (skb_out->len > CDC_NCM_MIN_TX_PKT) |
| 797 | /* final zero padding */ |
| 798 | memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0, ctx->tx_max - skb_out->len); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 799 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 800 | /* do we need to prevent a ZLP? */ |
| 801 | if (((skb_out->len % le16_to_cpu(ctx->out_ep->desc.wMaxPacketSize)) == 0) && |
| 802 | (skb_out->len < le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize)) && skb_tailroom(skb_out)) |
| 803 | *skb_put(skb_out, 1) = 0; /* force short packet */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 804 | |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 805 | /* set final frame length */ |
| 806 | nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data; |
| 807 | nth16->wBlockLength = cpu_to_le16(skb_out->len); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 808 | |
| 809 | /* return skb */ |
| 810 | ctx->tx_curr_skb = NULL; |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 811 | ctx->netdev->stats.tx_packets += ctx->tx_curr_frame_num; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 812 | return skb_out; |
| 813 | |
| 814 | exit_no_skb: |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 815 | /* Start timer, if there is a remaining skb */ |
| 816 | if (ctx->tx_curr_skb != NULL) |
| 817 | cdc_ncm_tx_timeout_start(ctx); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 818 | return NULL; |
| 819 | } |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 820 | EXPORT_SYMBOL_GPL(cdc_ncm_fill_tx_frame); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 821 | |
| 822 | static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx) |
| 823 | { |
| 824 | /* start timer, if not already started */ |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 825 | if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop))) |
| 826 | hrtimer_start(&ctx->tx_timer, |
| 827 | ktime_set(0, CDC_NCM_TIMER_INTERVAL), |
| 828 | HRTIMER_MODE_REL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 831 | static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *timer) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 832 | { |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 833 | struct cdc_ncm_ctx *ctx = |
| 834 | container_of(timer, struct cdc_ncm_ctx, tx_timer); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 835 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 836 | if (!atomic_read(&ctx->stop)) |
| 837 | tasklet_schedule(&ctx->bh); |
| 838 | return HRTIMER_NORESTART; |
| 839 | } |
| 840 | |
| 841 | static void cdc_ncm_txpath_bh(unsigned long param) |
| 842 | { |
| 843 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)param; |
| 844 | |
| 845 | spin_lock_bh(&ctx->mtx); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 846 | if (ctx->tx_timer_pending != 0) { |
| 847 | ctx->tx_timer_pending--; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 848 | cdc_ncm_tx_timeout_start(ctx); |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 849 | spin_unlock_bh(&ctx->mtx); |
Alexey Orishko | f742aa8 | 2011-01-17 07:07:25 +0000 | [diff] [blame] | 850 | } else if (ctx->netdev != NULL) { |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 851 | spin_unlock_bh(&ctx->mtx); |
| 852 | netif_tx_lock_bh(ctx->netdev); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 853 | usbnet_start_xmit(NULL, ctx->netdev); |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 854 | netif_tx_unlock_bh(ctx->netdev); |
Bjørn Mork | 7b1e0cb | 2012-10-25 21:44:09 +0000 | [diff] [blame] | 855 | } else { |
| 856 | spin_unlock_bh(&ctx->mtx); |
Alexey Orishko | f742aa8 | 2011-01-17 07:07:25 +0000 | [diff] [blame] | 857 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static struct sk_buff * |
| 861 | cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) |
| 862 | { |
| 863 | struct sk_buff *skb_out; |
| 864 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 865 | |
| 866 | /* |
| 867 | * The Ethernet API we are using does not support transmitting |
| 868 | * multiple Ethernet frames in a single call. This driver will |
| 869 | * accumulate multiple Ethernet frames and send out a larger |
| 870 | * USB frame when the USB buffer is full or when a single jiffies |
| 871 | * timeout happens. |
| 872 | */ |
| 873 | if (ctx == NULL) |
| 874 | goto error; |
| 875 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 876 | spin_lock_bh(&ctx->mtx); |
Bjørn Mork | c78b7c5 | 2012-10-22 10:56:34 +0000 | [diff] [blame] | 877 | skb_out = cdc_ncm_fill_tx_frame(ctx, skb, cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN)); |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 878 | spin_unlock_bh(&ctx->mtx); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 879 | return skb_out; |
| 880 | |
| 881 | error: |
| 882 | if (skb != NULL) |
| 883 | dev_kfree_skb_any(skb); |
| 884 | |
| 885 | return NULL; |
| 886 | } |
| 887 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 888 | /* verify NTB header and return offset of first NDP, or negative error */ |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 889 | int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_in) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 890 | { |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 891 | struct usb_cdc_ncm_nth16 *nth16; |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 892 | int len; |
| 893 | int ret = -EINVAL; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 894 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 895 | if (ctx == NULL) |
| 896 | goto error; |
| 897 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 898 | if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth16) + |
| 899 | sizeof(struct usb_cdc_ncm_ndp16))) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 900 | pr_debug("frame too short\n"); |
| 901 | goto error; |
| 902 | } |
| 903 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 904 | nth16 = (struct usb_cdc_ncm_nth16 *)skb_in->data; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 905 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 906 | if (le32_to_cpu(nth16->dwSignature) != USB_CDC_NCM_NTH16_SIGN) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 907 | pr_debug("invalid NTH16 signature <%u>\n", |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 908 | le32_to_cpu(nth16->dwSignature)); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 909 | goto error; |
| 910 | } |
| 911 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 912 | len = le16_to_cpu(nth16->wBlockLength); |
| 913 | if (len > ctx->rx_max) { |
| 914 | pr_debug("unsupported NTB block length %u/%u\n", len, |
| 915 | ctx->rx_max); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 916 | goto error; |
| 917 | } |
| 918 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 919 | if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) && |
| 920 | (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) && |
| 921 | !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth16->wSequence))) { |
| 922 | pr_debug("sequence number glitch prev=%d curr=%d\n", |
| 923 | ctx->rx_seq, le16_to_cpu(nth16->wSequence)); |
| 924 | } |
| 925 | ctx->rx_seq = le16_to_cpu(nth16->wSequence); |
| 926 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 927 | ret = le16_to_cpu(nth16->wNdpIndex); |
| 928 | error: |
| 929 | return ret; |
| 930 | } |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 931 | EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_nth16); |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 932 | |
| 933 | /* verify NDP header and return number of datagrams, or negative error */ |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 934 | int cdc_ncm_rx_verify_ndp16(struct sk_buff *skb_in, int ndpoffset) |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 935 | { |
| 936 | struct usb_cdc_ncm_ndp16 *ndp16; |
| 937 | int ret = -EINVAL; |
| 938 | |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 939 | if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp16)) > skb_in->len) { |
| 940 | pr_debug("invalid NDP offset <%u>\n", ndpoffset); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 941 | goto error; |
| 942 | } |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 943 | ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 944 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 945 | if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 946 | pr_debug("invalid DPT16 length <%u>\n", |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 947 | le32_to_cpu(ndp16->dwSignature)); |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 948 | goto error; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 951 | ret = ((le16_to_cpu(ndp16->wLength) - |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 952 | sizeof(struct usb_cdc_ncm_ndp16)) / |
| 953 | sizeof(struct usb_cdc_ncm_dpe16)); |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 954 | ret--; /* we process NDP entries except for the last one */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 955 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 956 | if ((sizeof(struct usb_cdc_ncm_ndp16) + ret * (sizeof(struct usb_cdc_ncm_dpe16))) > |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 957 | skb_in->len) { |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 958 | pr_debug("Invalid nframes = %d\n", ret); |
| 959 | ret = -EINVAL; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 962 | error: |
| 963 | return ret; |
| 964 | } |
Bjørn Mork | c91ce3b | 2012-10-22 10:56:35 +0000 | [diff] [blame] | 965 | EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_ndp16); |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame] | 966 | |
| 967 | static int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in) |
| 968 | { |
| 969 | struct sk_buff *skb; |
| 970 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
| 971 | int len; |
| 972 | int nframes; |
| 973 | int x; |
| 974 | int offset; |
| 975 | struct usb_cdc_ncm_ndp16 *ndp16; |
| 976 | struct usb_cdc_ncm_dpe16 *dpe16; |
| 977 | int ndpoffset; |
| 978 | int loopcount = 50; /* arbitrary max preventing infinite loop */ |
| 979 | |
| 980 | ndpoffset = cdc_ncm_rx_verify_nth16(ctx, skb_in); |
| 981 | if (ndpoffset < 0) |
| 982 | goto error; |
| 983 | |
| 984 | next_ndp: |
| 985 | nframes = cdc_ncm_rx_verify_ndp16(skb_in, ndpoffset); |
| 986 | if (nframes < 0) |
| 987 | goto error; |
| 988 | |
| 989 | ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset); |
| 990 | |
| 991 | if (le32_to_cpu(ndp16->dwSignature) != USB_CDC_NCM_NDP16_NOCRC_SIGN) { |
| 992 | pr_debug("invalid DPT16 signature <%u>\n", |
| 993 | le32_to_cpu(ndp16->dwSignature)); |
| 994 | goto err_ndp; |
| 995 | } |
| 996 | dpe16 = ndp16->dpe16; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 997 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 998 | for (x = 0; x < nframes; x++, dpe16++) { |
| 999 | offset = le16_to_cpu(dpe16->wDatagramIndex); |
| 1000 | len = le16_to_cpu(dpe16->wDatagramLength); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1001 | |
| 1002 | /* |
| 1003 | * CDC NCM ch. 3.7 |
| 1004 | * All entries after first NULL entry are to be ignored |
| 1005 | */ |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1006 | if ((offset == 0) || (len == 0)) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1007 | if (!x) |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 1008 | goto err_ndp; /* empty NTB */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1009 | break; |
| 1010 | } |
| 1011 | |
| 1012 | /* sanity checking */ |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1013 | if (((offset + len) > skb_in->len) || |
| 1014 | (len > ctx->rx_max) || (len < ETH_HLEN)) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1015 | pr_debug("invalid frame detected (ignored)" |
Alexey Orishko | f742aa8 | 2011-01-17 07:07:25 +0000 | [diff] [blame] | 1016 | "offset[%u]=%u, length=%u, skb=%p\n", |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1017 | x, offset, len, skb_in); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1018 | if (!x) |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 1019 | goto err_ndp; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | |
| 1022 | } else { |
| 1023 | skb = skb_clone(skb_in, GFP_ATOMIC); |
Jesper Juhl | 9e56790 | 2011-01-13 11:40:11 +0000 | [diff] [blame] | 1024 | if (!skb) |
| 1025 | goto error; |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1026 | skb->len = len; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1027 | skb->data = ((u8 *)skb_in->data) + offset; |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1028 | skb_set_tail_pointer(skb, len); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1029 | usbnet_skb_return(dev, skb); |
| 1030 | } |
| 1031 | } |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 1032 | err_ndp: |
| 1033 | /* are there more NDPs to process? */ |
| 1034 | ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex); |
| 1035 | if (ndpoffset && loopcount--) |
| 1036 | goto next_ndp; |
| 1037 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1038 | return 1; |
| 1039 | error: |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | static void |
| 1044 | cdc_ncm_speed_change(struct cdc_ncm_ctx *ctx, |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1045 | struct usb_cdc_speed_change *data) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1046 | { |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1047 | uint32_t rx_speed = le32_to_cpu(data->DLBitRRate); |
| 1048 | uint32_t tx_speed = le32_to_cpu(data->ULBitRate); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1049 | |
| 1050 | /* |
| 1051 | * Currently the USB-NET API does not support reporting the actual |
| 1052 | * device speed. Do print it instead. |
| 1053 | */ |
| 1054 | if ((tx_speed != ctx->tx_speed) || (rx_speed != ctx->rx_speed)) { |
| 1055 | ctx->tx_speed = tx_speed; |
| 1056 | ctx->rx_speed = rx_speed; |
| 1057 | |
| 1058 | if ((tx_speed > 1000000) && (rx_speed > 1000000)) { |
| 1059 | printk(KERN_INFO KBUILD_MODNAME |
| 1060 | ": %s: %u mbit/s downlink " |
| 1061 | "%u mbit/s uplink\n", |
| 1062 | ctx->netdev->name, |
| 1063 | (unsigned int)(rx_speed / 1000000U), |
| 1064 | (unsigned int)(tx_speed / 1000000U)); |
| 1065 | } else { |
| 1066 | printk(KERN_INFO KBUILD_MODNAME |
| 1067 | ": %s: %u kbit/s downlink " |
| 1068 | "%u kbit/s uplink\n", |
| 1069 | ctx->netdev->name, |
| 1070 | (unsigned int)(rx_speed / 1000U), |
| 1071 | (unsigned int)(tx_speed / 1000U)); |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | static void cdc_ncm_status(struct usbnet *dev, struct urb *urb) |
| 1077 | { |
| 1078 | struct cdc_ncm_ctx *ctx; |
| 1079 | struct usb_cdc_notification *event; |
| 1080 | |
| 1081 | ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
| 1082 | |
| 1083 | if (urb->actual_length < sizeof(*event)) |
| 1084 | return; |
| 1085 | |
| 1086 | /* test for split data in 8-byte chunks */ |
| 1087 | if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) { |
| 1088 | cdc_ncm_speed_change(ctx, |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1089 | (struct usb_cdc_speed_change *)urb->transfer_buffer); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1090 | return; |
| 1091 | } |
| 1092 | |
| 1093 | event = urb->transfer_buffer; |
| 1094 | |
| 1095 | switch (event->bNotificationType) { |
| 1096 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: |
| 1097 | /* |
| 1098 | * According to the CDC NCM specification ch.7.1 |
| 1099 | * USB_CDC_NOTIFY_NETWORK_CONNECTION notification shall be |
| 1100 | * sent by device after USB_CDC_NOTIFY_SPEED_CHANGE. |
| 1101 | */ |
Bjørn Mork | 1a7c6cc | 2012-10-25 21:44:08 +0000 | [diff] [blame] | 1102 | ctx->connected = le16_to_cpu(event->wValue); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1103 | |
| 1104 | printk(KERN_INFO KBUILD_MODNAME ": %s: network connection:" |
| 1105 | " %sconnected\n", |
| 1106 | ctx->netdev->name, ctx->connected ? "" : "dis"); |
| 1107 | |
| 1108 | if (ctx->connected) |
| 1109 | netif_carrier_on(dev->net); |
| 1110 | else { |
| 1111 | netif_carrier_off(dev->net); |
| 1112 | ctx->tx_speed = ctx->rx_speed = 0; |
| 1113 | } |
| 1114 | break; |
| 1115 | |
| 1116 | case USB_CDC_NOTIFY_SPEED_CHANGE: |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1117 | if (urb->actual_length < (sizeof(*event) + |
| 1118 | sizeof(struct usb_cdc_speed_change))) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1119 | set_bit(EVENT_STS_SPLIT, &dev->flags); |
| 1120 | else |
| 1121 | cdc_ncm_speed_change(ctx, |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1122 | (struct usb_cdc_speed_change *) &event[1]); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1123 | break; |
| 1124 | |
| 1125 | default: |
| 1126 | dev_err(&dev->udev->dev, "NCM: unexpected " |
| 1127 | "notification 0x%02x!\n", event->bNotificationType); |
| 1128 | break; |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | static int cdc_ncm_check_connect(struct usbnet *dev) |
| 1133 | { |
| 1134 | struct cdc_ncm_ctx *ctx; |
| 1135 | |
| 1136 | ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
| 1137 | if (ctx == NULL) |
| 1138 | return 1; /* disconnected */ |
| 1139 | |
| 1140 | return !ctx->connected; |
| 1141 | } |
| 1142 | |
| 1143 | static int |
| 1144 | cdc_ncm_probe(struct usb_interface *udev, const struct usb_device_id *prod) |
| 1145 | { |
| 1146 | return usbnet_probe(udev, prod); |
| 1147 | } |
| 1148 | |
| 1149 | static void cdc_ncm_disconnect(struct usb_interface *intf) |
| 1150 | { |
| 1151 | struct usbnet *dev = usb_get_intfdata(intf); |
| 1152 | |
| 1153 | if (dev == NULL) |
| 1154 | return; /* already disconnected */ |
| 1155 | |
| 1156 | usbnet_disconnect(intf); |
| 1157 | } |
| 1158 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1159 | static const struct driver_info cdc_ncm_info = { |
| 1160 | .description = "CDC NCM", |
Arnd Bergmann | c261344 | 2011-04-01 20:12:02 -0700 | [diff] [blame] | 1161 | .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET, |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1162 | .bind = cdc_ncm_bind, |
| 1163 | .unbind = cdc_ncm_unbind, |
| 1164 | .check_connect = cdc_ncm_check_connect, |
Oliver Neukum | a5e4070 | 2012-12-18 04:46:12 +0000 | [diff] [blame] | 1165 | .manage_power = usbnet_manage_power, |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1166 | .status = cdc_ncm_status, |
| 1167 | .rx_fixup = cdc_ncm_rx_fixup, |
| 1168 | .tx_fixup = cdc_ncm_tx_fixup, |
| 1169 | }; |
| 1170 | |
Dan Williams | f94898e | 2012-07-24 08:43:22 +0000 | [diff] [blame] | 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_WWAN, |
| 1176 | .bind = cdc_ncm_bind, |
| 1177 | .unbind = cdc_ncm_unbind, |
| 1178 | .check_connect = cdc_ncm_check_connect, |
Oliver Neukum | a5e4070 | 2012-12-18 04:46:12 +0000 | [diff] [blame] | 1179 | .manage_power = usbnet_manage_power, |
Dan Williams | f94898e | 2012-07-24 08:43:22 +0000 | [diff] [blame] | 1180 | .status = cdc_ncm_status, |
| 1181 | .rx_fixup = cdc_ncm_rx_fixup, |
| 1182 | .tx_fixup = cdc_ncm_tx_fixup, |
| 1183 | }; |
| 1184 | |
| 1185 | static const struct usb_device_id cdc_devs[] = { |
| 1186 | /* Ericsson MBM devices like F5521gw */ |
| 1187 | { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 1188 | | USB_DEVICE_ID_MATCH_VENDOR, |
| 1189 | .idVendor = 0x0bdb, |
| 1190 | .bInterfaceClass = USB_CLASS_COMM, |
| 1191 | .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM, |
| 1192 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
| 1193 | .driver_info = (unsigned long) &wwan_info, |
| 1194 | }, |
| 1195 | |
Peter Meiser | f3a1ef9 | 2012-08-02 02:30:20 +0000 | [diff] [blame] | 1196 | /* Dell branded MBM devices like DW5550 */ |
| 1197 | { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 1198 | | USB_DEVICE_ID_MATCH_VENDOR, |
| 1199 | .idVendor = 0x413c, |
| 1200 | .bInterfaceClass = USB_CLASS_COMM, |
| 1201 | .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM, |
| 1202 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
| 1203 | .driver_info = (unsigned long) &wwan_info, |
| 1204 | }, |
| 1205 | |
| 1206 | /* Toshiba branded MBM devices */ |
| 1207 | { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 1208 | | USB_DEVICE_ID_MATCH_VENDOR, |
| 1209 | .idVendor = 0x0930, |
| 1210 | .bInterfaceClass = USB_CLASS_COMM, |
| 1211 | .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM, |
| 1212 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
| 1213 | .driver_info = (unsigned long) &wwan_info, |
| 1214 | }, |
| 1215 | |
Bjørn Mork | bbc8d92 | 2012-11-13 03:19:43 +0000 | [diff] [blame] | 1216 | /* Huawei NCM devices disguised as vendor specific */ |
| 1217 | { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x16), |
| 1218 | .driver_info = (unsigned long)&wwan_info, |
| 1219 | }, |
| 1220 | { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, 0xff, 0x02, 0x46), |
| 1221 | .driver_info = (unsigned long)&wwan_info, |
| 1222 | }, |
| 1223 | |
Dan Williams | f94898e | 2012-07-24 08:43:22 +0000 | [diff] [blame] | 1224 | /* Generic CDC-NCM devices */ |
| 1225 | { USB_INTERFACE_INFO(USB_CLASS_COMM, |
| 1226 | USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE), |
| 1227 | .driver_info = (unsigned long)&cdc_ncm_info, |
| 1228 | }, |
| 1229 | { |
| 1230 | }, |
| 1231 | }; |
| 1232 | MODULE_DEVICE_TABLE(usb, cdc_devs); |
| 1233 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1234 | static struct usb_driver cdc_ncm_driver = { |
| 1235 | .name = "cdc_ncm", |
| 1236 | .id_table = cdc_devs, |
| 1237 | .probe = cdc_ncm_probe, |
| 1238 | .disconnect = cdc_ncm_disconnect, |
| 1239 | .suspend = usbnet_suspend, |
| 1240 | .resume = usbnet_resume, |
Stefan Metzmacher | 85e3c65 | 2011-06-01 02:01:41 +0000 | [diff] [blame] | 1241 | .reset_resume = usbnet_resume, |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1242 | .supports_autosuspend = 1, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 1243 | .disable_hub_initiated_lpm = 1, |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1244 | }; |
| 1245 | |
Greg Kroah-Hartman | d632eb1 | 2011-11-18 09:44:20 -0800 | [diff] [blame] | 1246 | module_usb_driver(cdc_ncm_driver); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1247 | |
| 1248 | MODULE_AUTHOR("Hans Petter Selasky"); |
| 1249 | MODULE_DESCRIPTION("USB CDC NCM host driver"); |
| 1250 | MODULE_LICENSE("Dual BSD/GPL"); |