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> |
| 54 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 55 | #define DRIVER_VERSION "14-Mar-2012" |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 56 | |
| 57 | /* CDC NCM subclass 3.2.1 */ |
| 58 | #define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10 |
| 59 | |
| 60 | /* Maximum NTB length */ |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 61 | #define CDC_NCM_NTB_MAX_SIZE_TX 32768 /* bytes */ |
| 62 | #define CDC_NCM_NTB_MAX_SIZE_RX 32768 /* bytes */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 63 | |
| 64 | /* Minimum value for MaxDatagramSize, ch. 6.2.9 */ |
| 65 | #define CDC_NCM_MIN_DATAGRAM_SIZE 1514 /* bytes */ |
| 66 | |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 67 | /* Minimum value for MaxDatagramSize, ch. 8.1.3 */ |
| 68 | #define CDC_MBIM_MIN_DATAGRAM_SIZE 2048 /* bytes */ |
| 69 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 70 | #define CDC_NCM_MIN_TX_PKT 512 /* bytes */ |
| 71 | |
| 72 | /* Default value for MaxDatagramSize */ |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 73 | #define CDC_NCM_MAX_DATAGRAM_SIZE 8192 /* bytes */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Maximum amount of datagrams in NCM Datagram Pointer Table, not counting |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 77 | * the last NULL entry. |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 78 | */ |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 79 | #define CDC_NCM_DPT_DATAGRAMS_MAX 40 |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 80 | |
| 81 | /* Restart the timer, if amount of datagrams is less than given value */ |
| 82 | #define CDC_NCM_RESTART_TIMER_DATAGRAM_CNT 3 |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 83 | #define CDC_NCM_TIMER_PENDING_CNT 2 |
| 84 | #define CDC_NCM_TIMER_INTERVAL (400UL * NSEC_PER_USEC) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 85 | |
| 86 | /* The following macro defines the minimum header space */ |
| 87 | #define CDC_NCM_MIN_HDR_SIZE \ |
| 88 | (sizeof(struct usb_cdc_ncm_nth16) + sizeof(struct usb_cdc_ncm_ndp16) + \ |
| 89 | (CDC_NCM_DPT_DATAGRAMS_MAX + 1) * sizeof(struct usb_cdc_ncm_dpe16)) |
| 90 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 91 | struct cdc_ncm_data { |
| 92 | struct usb_cdc_ncm_nth16 nth16; |
| 93 | struct usb_cdc_ncm_ndp16 ndp16; |
| 94 | struct usb_cdc_ncm_dpe16 dpe16[CDC_NCM_DPT_DATAGRAMS_MAX + 1]; |
| 95 | }; |
| 96 | |
| 97 | struct cdc_ncm_ctx { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 98 | struct cdc_ncm_data tx_ncm; |
| 99 | struct usb_cdc_ncm_ntb_parameters ncm_parm; |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 100 | struct hrtimer tx_timer; |
| 101 | struct tasklet_struct bh; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 102 | |
| 103 | const struct usb_cdc_ncm_desc *func_desc; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 104 | const struct usb_cdc_mbim_desc *mbim_desc; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 105 | const struct usb_cdc_header_desc *header_desc; |
| 106 | const struct usb_cdc_union_desc *union_desc; |
| 107 | const struct usb_cdc_ether_desc *ether_desc; |
| 108 | |
| 109 | struct net_device *netdev; |
| 110 | struct usb_device *udev; |
| 111 | struct usb_host_endpoint *in_ep; |
| 112 | struct usb_host_endpoint *out_ep; |
| 113 | struct usb_host_endpoint *status_ep; |
| 114 | struct usb_interface *intf; |
| 115 | struct usb_interface *control; |
| 116 | struct usb_interface *data; |
| 117 | |
| 118 | struct sk_buff *tx_curr_skb; |
| 119 | struct sk_buff *tx_rem_skb; |
| 120 | |
| 121 | spinlock_t mtx; |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 122 | atomic_t stop; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 123 | |
| 124 | u32 tx_timer_pending; |
| 125 | u32 tx_curr_offset; |
| 126 | u32 tx_curr_last_offset; |
| 127 | u32 tx_curr_frame_num; |
| 128 | u32 rx_speed; |
| 129 | u32 tx_speed; |
| 130 | u32 rx_max; |
| 131 | u32 tx_max; |
| 132 | u32 max_datagram_size; |
| 133 | u16 tx_max_datagrams; |
| 134 | u16 tx_remainder; |
| 135 | u16 tx_modulus; |
| 136 | u16 tx_ndp_modulus; |
| 137 | u16 tx_seq; |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 138 | u16 rx_seq; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 139 | u16 connected; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 142 | static void cdc_ncm_txpath_bh(unsigned long param); |
| 143 | static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx); |
| 144 | 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] | 145 | static struct usb_driver cdc_ncm_driver; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 146 | |
| 147 | static void |
| 148 | cdc_ncm_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info) |
| 149 | { |
| 150 | struct usbnet *dev = netdev_priv(net); |
| 151 | |
| 152 | strncpy(info->driver, dev->driver_name, sizeof(info->driver)); |
| 153 | strncpy(info->version, DRIVER_VERSION, sizeof(info->version)); |
| 154 | strncpy(info->fw_version, dev->driver_info->description, |
| 155 | sizeof(info->fw_version)); |
| 156 | usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info)); |
| 157 | } |
| 158 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 159 | static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx) |
| 160 | { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 161 | u32 val; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 162 | u8 flags; |
| 163 | u8 iface_no; |
| 164 | int err; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 165 | int eth_hlen; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 166 | u16 ntb_fmt_supported; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 167 | u32 min_dgram_size; |
| 168 | u32 min_hdr_size; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 169 | |
| 170 | iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber; |
| 171 | |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 172 | err = usb_control_msg(ctx->udev, |
| 173 | usb_rcvctrlpipe(ctx->udev, 0), |
| 174 | USB_CDC_GET_NTB_PARAMETERS, |
| 175 | USB_TYPE_CLASS | USB_DIR_IN |
| 176 | | USB_RECIP_INTERFACE, |
| 177 | 0, iface_no, &ctx->ncm_parm, |
| 178 | sizeof(ctx->ncm_parm), 10000); |
| 179 | if (err < 0) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 180 | pr_debug("failed GET_NTB_PARAMETERS\n"); |
| 181 | return 1; |
| 182 | } |
| 183 | |
| 184 | /* read correct set of parameters according to device mode */ |
| 185 | ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize); |
| 186 | ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize); |
| 187 | ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder); |
| 188 | ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor); |
| 189 | ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment); |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 190 | /* devices prior to NCM Errata shall set this field to zero */ |
| 191 | ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams); |
| 192 | ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 193 | |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 194 | eth_hlen = ETH_HLEN; |
| 195 | min_dgram_size = CDC_NCM_MIN_DATAGRAM_SIZE; |
| 196 | min_hdr_size = CDC_NCM_MIN_HDR_SIZE; |
| 197 | if (ctx->mbim_desc != NULL) { |
| 198 | flags = ctx->mbim_desc->bmNetworkCapabilities; |
| 199 | eth_hlen = 0; |
| 200 | min_dgram_size = CDC_MBIM_MIN_DATAGRAM_SIZE; |
| 201 | min_hdr_size = 0; |
| 202 | } else if (ctx->func_desc != NULL) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 203 | flags = ctx->func_desc->bmNetworkCapabilities; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 204 | } else { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 205 | flags = 0; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 206 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 207 | |
| 208 | pr_debug("dwNtbInMaxSize=%u dwNtbOutMaxSize=%u " |
| 209 | "wNdpOutPayloadRemainder=%u wNdpOutDivisor=%u " |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 210 | "wNdpOutAlignment=%u wNtbOutMaxDatagrams=%u flags=0x%x\n", |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 211 | ctx->rx_max, ctx->tx_max, ctx->tx_remainder, ctx->tx_modulus, |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 212 | ctx->tx_ndp_modulus, ctx->tx_max_datagrams, flags); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 213 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 214 | /* max count of tx datagrams */ |
| 215 | if ((ctx->tx_max_datagrams == 0) || |
| 216 | (ctx->tx_max_datagrams > CDC_NCM_DPT_DATAGRAMS_MAX)) |
| 217 | ctx->tx_max_datagrams = CDC_NCM_DPT_DATAGRAMS_MAX; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 218 | |
| 219 | /* verify maximum size of received NTB in bytes */ |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 220 | if (ctx->rx_max < USB_CDC_NCM_NTB_MIN_IN_SIZE) { |
| 221 | pr_debug("Using min receive length=%d\n", |
| 222 | USB_CDC_NCM_NTB_MIN_IN_SIZE); |
| 223 | ctx->rx_max = USB_CDC_NCM_NTB_MIN_IN_SIZE; |
| 224 | } |
| 225 | |
| 226 | if (ctx->rx_max > CDC_NCM_NTB_MAX_SIZE_RX) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 227 | pr_debug("Using default maximum receive length=%d\n", |
| 228 | CDC_NCM_NTB_MAX_SIZE_RX); |
| 229 | ctx->rx_max = CDC_NCM_NTB_MAX_SIZE_RX; |
| 230 | } |
| 231 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 232 | /* inform device about NTB input size changes */ |
| 233 | if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) { |
Bjørn Mork | dad957d | 2012-10-22 10:56:28 +0000 | [diff] [blame] | 234 | __le32 *dwNtbInMaxSize; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 235 | |
Bjørn Mork | dad957d | 2012-10-22 10:56:28 +0000 | [diff] [blame] | 236 | dwNtbInMaxSize = kzalloc(sizeof(*dwNtbInMaxSize), GFP_KERNEL); |
| 237 | if (!dwNtbInMaxSize) { |
| 238 | err = -ENOMEM; |
| 239 | goto size_err; |
Josh Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 240 | } |
Bjørn Mork | dad957d | 2012-10-22 10:56:28 +0000 | [diff] [blame] | 241 | *dwNtbInMaxSize = cpu_to_le32(ctx->rx_max); |
| 242 | err = usb_control_msg(ctx->udev, |
| 243 | usb_sndctrlpipe(ctx->udev, 0), |
| 244 | USB_CDC_SET_NTB_INPUT_SIZE, |
| 245 | USB_TYPE_CLASS | USB_DIR_OUT |
| 246 | | USB_RECIP_INTERFACE, |
| 247 | 0, iface_no, dwNtbInMaxSize, 4, 1000); |
| 248 | kfree(dwNtbInMaxSize); |
Josh Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 249 | size_err: |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 250 | if (err < 0) |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 251 | pr_debug("Setting NTB Input Size failed\n"); |
| 252 | } |
| 253 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 254 | /* verify maximum size of transmitted NTB in bytes */ |
| 255 | if ((ctx->tx_max < |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 256 | (min_hdr_size + min_dgram_size)) || |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 257 | (ctx->tx_max > CDC_NCM_NTB_MAX_SIZE_TX)) { |
| 258 | pr_debug("Using default maximum transmit length=%d\n", |
| 259 | CDC_NCM_NTB_MAX_SIZE_TX); |
| 260 | ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX; |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * verify that the structure alignment is: |
| 265 | * - power of two |
| 266 | * - not greater than the maximum transmit length |
| 267 | * - not less than four bytes |
| 268 | */ |
| 269 | val = ctx->tx_ndp_modulus; |
| 270 | |
| 271 | if ((val < USB_CDC_NCM_NDP_ALIGN_MIN_SIZE) || |
| 272 | (val != ((-val) & val)) || (val >= ctx->tx_max)) { |
| 273 | pr_debug("Using default alignment: 4 bytes\n"); |
| 274 | ctx->tx_ndp_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE; |
| 275 | } |
| 276 | |
| 277 | /* |
| 278 | * verify that the payload alignment is: |
| 279 | * - power of two |
| 280 | * - not greater than the maximum transmit length |
| 281 | * - not less than four bytes |
| 282 | */ |
| 283 | val = ctx->tx_modulus; |
| 284 | |
| 285 | if ((val < USB_CDC_NCM_NDP_ALIGN_MIN_SIZE) || |
| 286 | (val != ((-val) & val)) || (val >= ctx->tx_max)) { |
| 287 | pr_debug("Using default transmit modulus: 4 bytes\n"); |
| 288 | ctx->tx_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE; |
| 289 | } |
| 290 | |
| 291 | /* verify the payload remainder */ |
| 292 | if (ctx->tx_remainder >= ctx->tx_modulus) { |
| 293 | pr_debug("Using default transmit remainder: 0 bytes\n"); |
| 294 | ctx->tx_remainder = 0; |
| 295 | } |
| 296 | |
| 297 | /* adjust TX-remainder according to NCM specification. */ |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 298 | ctx->tx_remainder = ((ctx->tx_remainder - eth_hlen) & |
| 299 | (ctx->tx_modulus - 1)); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 300 | |
| 301 | /* additional configuration */ |
| 302 | |
| 303 | /* set CRC Mode */ |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 304 | if (flags & USB_CDC_NCM_NCAP_CRC_MODE) { |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 305 | err = usb_control_msg(ctx->udev, usb_sndctrlpipe(ctx->udev, 0), |
| 306 | USB_CDC_SET_CRC_MODE, |
| 307 | USB_TYPE_CLASS | USB_DIR_OUT |
| 308 | | USB_RECIP_INTERFACE, |
| 309 | USB_CDC_NCM_CRC_NOT_APPENDED, |
| 310 | iface_no, NULL, 0, 1000); |
| 311 | if (err < 0) |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 312 | pr_debug("Setting CRC mode off failed\n"); |
| 313 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 314 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 315 | /* set NTB format, if both formats are supported */ |
| 316 | if (ntb_fmt_supported & USB_CDC_NCM_NTH32_SIGN) { |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 317 | err = usb_control_msg(ctx->udev, usb_sndctrlpipe(ctx->udev, 0), |
| 318 | USB_CDC_SET_NTB_FORMAT, USB_TYPE_CLASS |
| 319 | | USB_DIR_OUT | USB_RECIP_INTERFACE, |
| 320 | USB_CDC_NCM_NTB16_FORMAT, |
| 321 | iface_no, NULL, 0, 1000); |
| 322 | if (err < 0) |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 323 | pr_debug("Setting NTB format to 16-bit failed\n"); |
| 324 | } |
| 325 | |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 326 | ctx->max_datagram_size = min_dgram_size; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 327 | |
| 328 | /* set Max Datagram Size (MTU) */ |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 329 | if (flags & USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE) { |
Josh Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 330 | __le16 *max_datagram_size; |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 331 | u16 eth_max_sz; |
| 332 | if (ctx->ether_desc != NULL) |
| 333 | eth_max_sz = le16_to_cpu(ctx->ether_desc->wMaxSegmentSize); |
| 334 | else if (ctx->mbim_desc != NULL) |
| 335 | eth_max_sz = le16_to_cpu(ctx->mbim_desc->wMaxSegmentSize); |
| 336 | else |
| 337 | goto max_dgram_err; |
Josh Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 338 | |
| 339 | max_datagram_size = kzalloc(sizeof(*max_datagram_size), |
| 340 | GFP_KERNEL); |
| 341 | if (!max_datagram_size) { |
| 342 | err = -ENOMEM; |
| 343 | goto max_dgram_err; |
| 344 | } |
| 345 | |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 346 | err = usb_control_msg(ctx->udev, usb_rcvctrlpipe(ctx->udev, 0), |
| 347 | USB_CDC_GET_MAX_DATAGRAM_SIZE, |
| 348 | USB_TYPE_CLASS | USB_DIR_IN |
| 349 | | USB_RECIP_INTERFACE, |
Josh Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 350 | 0, iface_no, max_datagram_size, |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 351 | 2, 1000); |
| 352 | if (err < 0) { |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 353 | pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n", |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 354 | min_dgram_size); |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 355 | } else { |
Josh Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 356 | ctx->max_datagram_size = |
| 357 | le16_to_cpu(*max_datagram_size); |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 358 | /* Check Eth descriptor value */ |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 359 | if (ctx->max_datagram_size > eth_max_sz) |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 360 | ctx->max_datagram_size = eth_max_sz; |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 361 | |
| 362 | if (ctx->max_datagram_size > CDC_NCM_MAX_DATAGRAM_SIZE) |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 363 | ctx->max_datagram_size = CDC_NCM_MAX_DATAGRAM_SIZE; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 364 | |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 365 | if (ctx->max_datagram_size < min_dgram_size) |
| 366 | ctx->max_datagram_size = min_dgram_size; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 367 | |
| 368 | /* if value changed, update device */ |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 369 | if (ctx->max_datagram_size != |
| 370 | le16_to_cpu(*max_datagram_size)) { |
| 371 | err = usb_control_msg(ctx->udev, |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 372 | usb_sndctrlpipe(ctx->udev, 0), |
| 373 | USB_CDC_SET_MAX_DATAGRAM_SIZE, |
| 374 | USB_TYPE_CLASS | USB_DIR_OUT |
| 375 | | USB_RECIP_INTERFACE, |
| 376 | 0, |
Josh Boyer | 75bc8ef | 2011-08-08 02:34:07 +0000 | [diff] [blame] | 377 | iface_no, max_datagram_size, |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 378 | 2, 1000); |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 379 | if (err < 0) |
| 380 | pr_debug("SET_MAX_DGRAM_SIZE failed\n"); |
| 381 | } |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 382 | } |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 383 | kfree(max_datagram_size); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Alexey Orishko | 3f658cd | 2012-03-14 11:26:11 +0000 | [diff] [blame] | 386 | max_dgram_err: |
Greg Suarez | 2d1c431 | 2012-10-22 10:56:30 +0000 | [diff] [blame] | 387 | if (ctx->netdev->mtu != (ctx->max_datagram_size - eth_hlen)) |
| 388 | ctx->netdev->mtu = ctx->max_datagram_size - eth_hlen; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | static void |
| 394 | cdc_ncm_find_endpoints(struct cdc_ncm_ctx *ctx, struct usb_interface *intf) |
| 395 | { |
| 396 | struct usb_host_endpoint *e; |
| 397 | u8 ep; |
| 398 | |
| 399 | for (ep = 0; ep < intf->cur_altsetting->desc.bNumEndpoints; ep++) { |
| 400 | |
| 401 | e = intf->cur_altsetting->endpoint + ep; |
| 402 | switch (e->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { |
| 403 | case USB_ENDPOINT_XFER_INT: |
| 404 | if (usb_endpoint_dir_in(&e->desc)) { |
| 405 | if (ctx->status_ep == NULL) |
| 406 | ctx->status_ep = e; |
| 407 | } |
| 408 | break; |
| 409 | |
| 410 | case USB_ENDPOINT_XFER_BULK: |
| 411 | if (usb_endpoint_dir_in(&e->desc)) { |
| 412 | if (ctx->in_ep == NULL) |
| 413 | ctx->in_ep = e; |
| 414 | } else { |
| 415 | if (ctx->out_ep == NULL) |
| 416 | ctx->out_ep = e; |
| 417 | } |
| 418 | break; |
| 419 | |
| 420 | default: |
| 421 | break; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | static void cdc_ncm_free(struct cdc_ncm_ctx *ctx) |
| 427 | { |
| 428 | if (ctx == NULL) |
| 429 | return; |
| 430 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 431 | if (ctx->tx_rem_skb != NULL) { |
| 432 | dev_kfree_skb_any(ctx->tx_rem_skb); |
| 433 | ctx->tx_rem_skb = NULL; |
| 434 | } |
| 435 | |
| 436 | if (ctx->tx_curr_skb != NULL) { |
| 437 | dev_kfree_skb_any(ctx->tx_curr_skb); |
| 438 | ctx->tx_curr_skb = NULL; |
| 439 | } |
| 440 | |
| 441 | kfree(ctx); |
| 442 | } |
| 443 | |
Dan Williams | f94898e | 2012-07-24 08:43:22 +0000 | [diff] [blame] | 444 | static const struct ethtool_ops cdc_ncm_ethtool_ops = { |
| 445 | .get_drvinfo = cdc_ncm_get_drvinfo, |
| 446 | .get_link = usbnet_get_link, |
| 447 | .get_msglevel = usbnet_get_msglevel, |
| 448 | .set_msglevel = usbnet_set_msglevel, |
| 449 | .get_settings = usbnet_get_settings, |
| 450 | .set_settings = usbnet_set_settings, |
| 451 | .nway_reset = usbnet_nway_reset, |
| 452 | }; |
| 453 | |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 454 | static 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] | 455 | { |
| 456 | struct cdc_ncm_ctx *ctx; |
| 457 | struct usb_driver *driver; |
| 458 | u8 *buf; |
| 459 | int len; |
| 460 | int temp; |
| 461 | u8 iface_no; |
| 462 | |
Thomas Meyer | c796984 | 2011-11-17 12:43:40 +0000 | [diff] [blame] | 463 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 464 | if (ctx == NULL) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 465 | return -ENODEV; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 466 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 467 | hrtimer_init(&ctx->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 468 | ctx->tx_timer.function = &cdc_ncm_tx_timer_cb; |
| 469 | ctx->bh.data = (unsigned long)ctx; |
| 470 | ctx->bh.func = cdc_ncm_txpath_bh; |
| 471 | atomic_set(&ctx->stop, 0); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 472 | spin_lock_init(&ctx->mtx); |
| 473 | ctx->netdev = dev->net; |
| 474 | |
| 475 | /* store ctx pointer in device data field */ |
| 476 | dev->data[0] = (unsigned long)ctx; |
| 477 | |
| 478 | /* get some pointers */ |
| 479 | driver = driver_of(intf); |
| 480 | buf = intf->cur_altsetting->extra; |
| 481 | len = intf->cur_altsetting->extralen; |
| 482 | |
| 483 | ctx->udev = dev->udev; |
| 484 | ctx->intf = intf; |
| 485 | |
| 486 | /* parse through descriptors associated with control interface */ |
| 487 | while ((len > 0) && (buf[0] > 2) && (buf[0] <= len)) { |
| 488 | |
| 489 | if (buf[1] != USB_DT_CS_INTERFACE) |
| 490 | goto advance; |
| 491 | |
| 492 | switch (buf[2]) { |
| 493 | case USB_CDC_UNION_TYPE: |
| 494 | if (buf[0] < sizeof(*(ctx->union_desc))) |
| 495 | break; |
| 496 | |
| 497 | ctx->union_desc = |
| 498 | (const struct usb_cdc_union_desc *)buf; |
| 499 | |
| 500 | ctx->control = usb_ifnum_to_if(dev->udev, |
| 501 | ctx->union_desc->bMasterInterface0); |
| 502 | ctx->data = usb_ifnum_to_if(dev->udev, |
| 503 | ctx->union_desc->bSlaveInterface0); |
| 504 | break; |
| 505 | |
| 506 | case USB_CDC_ETHERNET_TYPE: |
| 507 | if (buf[0] < sizeof(*(ctx->ether_desc))) |
| 508 | break; |
| 509 | |
| 510 | ctx->ether_desc = |
| 511 | (const struct usb_cdc_ether_desc *)buf; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 512 | dev->hard_mtu = |
| 513 | le16_to_cpu(ctx->ether_desc->wMaxSegmentSize); |
| 514 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 515 | if (dev->hard_mtu < CDC_NCM_MIN_DATAGRAM_SIZE) |
| 516 | dev->hard_mtu = CDC_NCM_MIN_DATAGRAM_SIZE; |
| 517 | else if (dev->hard_mtu > CDC_NCM_MAX_DATAGRAM_SIZE) |
| 518 | dev->hard_mtu = CDC_NCM_MAX_DATAGRAM_SIZE; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 519 | break; |
| 520 | |
| 521 | case USB_CDC_NCM_TYPE: |
| 522 | if (buf[0] < sizeof(*(ctx->func_desc))) |
| 523 | break; |
| 524 | |
| 525 | ctx->func_desc = (const struct usb_cdc_ncm_desc *)buf; |
| 526 | break; |
| 527 | |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 528 | case USB_CDC_MBIM_TYPE: |
| 529 | if (buf[0] < sizeof(*(ctx->mbim_desc))) |
| 530 | break; |
| 531 | |
| 532 | ctx->mbim_desc = (const struct usb_cdc_mbim_desc *)buf; |
| 533 | break; |
| 534 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 535 | default: |
| 536 | break; |
| 537 | } |
| 538 | advance: |
| 539 | /* advance to next descriptor */ |
| 540 | temp = buf[0]; |
| 541 | buf += temp; |
| 542 | len -= temp; |
| 543 | } |
| 544 | |
| 545 | /* check if we got everything */ |
| 546 | if ((ctx->control == NULL) || (ctx->data == NULL) || |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 547 | ((!ctx->mbim_desc) && ((ctx->ether_desc == NULL) || (ctx->control != intf)))) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 548 | goto error; |
| 549 | |
| 550 | /* claim interfaces, if any */ |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 551 | temp = usb_driver_claim_interface(driver, ctx->data, dev); |
| 552 | if (temp) |
| 553 | goto error; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 554 | |
| 555 | iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; |
| 556 | |
| 557 | /* reset data interface */ |
| 558 | temp = usb_set_interface(dev->udev, iface_no, 0); |
| 559 | if (temp) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 560 | goto error2; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 561 | |
| 562 | /* initialize data interface */ |
| 563 | if (cdc_ncm_setup(ctx)) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 564 | goto error2; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 565 | |
| 566 | /* configure data interface */ |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 567 | temp = usb_set_interface(dev->udev, iface_no, data_altsetting); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 568 | if (temp) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 569 | goto error2; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 570 | |
| 571 | cdc_ncm_find_endpoints(ctx, ctx->data); |
| 572 | cdc_ncm_find_endpoints(ctx, ctx->control); |
| 573 | |
| 574 | if ((ctx->in_ep == NULL) || (ctx->out_ep == NULL) || |
| 575 | (ctx->status_ep == NULL)) |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 576 | goto error2; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 577 | |
| 578 | dev->net->ethtool_ops = &cdc_ncm_ethtool_ops; |
| 579 | |
| 580 | usb_set_intfdata(ctx->data, dev); |
| 581 | usb_set_intfdata(ctx->control, dev); |
| 582 | usb_set_intfdata(ctx->intf, dev); |
| 583 | |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 584 | if (ctx->ether_desc) { |
| 585 | temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress); |
| 586 | if (temp) |
| 587 | goto error2; |
| 588 | dev_info(&dev->udev->dev, "MAC-Address: %pM\n", dev->net->dev_addr); |
| 589 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 590 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 591 | |
| 592 | dev->in = usb_rcvbulkpipe(dev->udev, |
| 593 | ctx->in_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
| 594 | dev->out = usb_sndbulkpipe(dev->udev, |
| 595 | ctx->out_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
| 596 | dev->status = ctx->status_ep; |
| 597 | dev->rx_urb_size = ctx->rx_max; |
| 598 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 599 | ctx->tx_speed = ctx->rx_speed = 0; |
| 600 | return 0; |
| 601 | |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 602 | error2: |
| 603 | usb_set_intfdata(ctx->control, NULL); |
| 604 | usb_set_intfdata(ctx->data, NULL); |
| 605 | usb_driver_release_interface(driver, ctx->data); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 606 | error: |
| 607 | cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]); |
| 608 | dev->data[0] = 0; |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 609 | dev_info(&dev->udev->dev, "bind() failure\n"); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 610 | return -ENODEV; |
| 611 | } |
| 612 | |
| 613 | static void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf) |
| 614 | { |
| 615 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 616 | struct usb_driver *driver = driver_of(intf); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 617 | |
| 618 | if (ctx == NULL) |
| 619 | return; /* no setup */ |
| 620 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 621 | atomic_set(&ctx->stop, 1); |
| 622 | |
| 623 | if (hrtimer_active(&ctx->tx_timer)) |
| 624 | hrtimer_cancel(&ctx->tx_timer); |
| 625 | |
| 626 | tasklet_kill(&ctx->bh); |
| 627 | |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 628 | /* disconnect master --> disconnect slave */ |
| 629 | if (intf == ctx->control && ctx->data) { |
| 630 | usb_set_intfdata(ctx->data, NULL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 631 | usb_driver_release_interface(driver, ctx->data); |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 632 | ctx->data = NULL; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 633 | |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 634 | } else if (intf == ctx->data && ctx->control) { |
| 635 | usb_set_intfdata(ctx->control, NULL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 636 | usb_driver_release_interface(driver, ctx->control); |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 637 | ctx->control = NULL; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Alexey Orishko | 19694ac | 2011-05-24 05:26:13 +0000 | [diff] [blame] | 640 | usb_set_intfdata(ctx->intf, NULL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 641 | cdc_ncm_free(ctx); |
| 642 | } |
| 643 | |
Greg Suarez | 38396e4 | 2012-10-22 10:56:31 +0000 | [diff] [blame] | 644 | static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf) |
| 645 | { |
| 646 | int ret; |
| 647 | |
| 648 | /* NCM data altsetting is always 1 */ |
| 649 | ret = cdc_ncm_bind_common(dev, intf, 1); |
| 650 | |
| 651 | /* |
| 652 | * We should get an event when network connection is "connected" or |
| 653 | * "disconnected". Set network connection in "disconnected" state |
| 654 | * (carrier is OFF) during attach, so the IP network stack does not |
| 655 | * start IPv6 negotiation and more. |
| 656 | */ |
| 657 | netif_carrier_off(dev->net); |
| 658 | return ret; |
| 659 | } |
| 660 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 661 | static void cdc_ncm_zero_fill(u8 *ptr, u32 first, u32 end, u32 max) |
| 662 | { |
| 663 | if (first >= max) |
| 664 | return; |
| 665 | if (first >= end) |
| 666 | return; |
| 667 | if (end > max) |
| 668 | end = max; |
| 669 | memset(ptr + first, 0, end - first); |
| 670 | } |
| 671 | |
| 672 | static struct sk_buff * |
| 673 | cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb) |
| 674 | { |
| 675 | struct sk_buff *skb_out; |
| 676 | u32 rem; |
| 677 | u32 offset; |
| 678 | u32 last_offset; |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 679 | u16 n = 0, index; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 680 | u8 ready2send = 0; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 681 | |
| 682 | /* if there is a remaining skb, it gets priority */ |
| 683 | if (skb != NULL) |
| 684 | swap(skb, ctx->tx_rem_skb); |
| 685 | else |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 686 | ready2send = 1; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 687 | |
| 688 | /* |
| 689 | * +----------------+ |
| 690 | * | skb_out | |
| 691 | * +----------------+ |
| 692 | * ^ offset |
| 693 | * ^ last_offset |
| 694 | */ |
| 695 | |
| 696 | /* check if we are resuming an OUT skb */ |
| 697 | if (ctx->tx_curr_skb != NULL) { |
| 698 | /* pop variables */ |
| 699 | skb_out = ctx->tx_curr_skb; |
| 700 | offset = ctx->tx_curr_offset; |
| 701 | last_offset = ctx->tx_curr_last_offset; |
| 702 | n = ctx->tx_curr_frame_num; |
| 703 | |
| 704 | } else { |
| 705 | /* reset variables */ |
Alexey Orishko | 6c60408 | 2011-05-06 03:01:30 +0000 | [diff] [blame] | 706 | skb_out = alloc_skb((ctx->tx_max + 1), GFP_ATOMIC); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 707 | if (skb_out == NULL) { |
| 708 | if (skb != NULL) { |
| 709 | dev_kfree_skb_any(skb); |
| 710 | ctx->netdev->stats.tx_dropped++; |
| 711 | } |
| 712 | goto exit_no_skb; |
| 713 | } |
| 714 | |
| 715 | /* make room for NTH and NDP */ |
| 716 | offset = ALIGN(sizeof(struct usb_cdc_ncm_nth16), |
| 717 | ctx->tx_ndp_modulus) + |
| 718 | sizeof(struct usb_cdc_ncm_ndp16) + |
| 719 | (ctx->tx_max_datagrams + 1) * |
| 720 | sizeof(struct usb_cdc_ncm_dpe16); |
| 721 | |
| 722 | /* store last valid offset before alignment */ |
| 723 | last_offset = offset; |
| 724 | /* align first Datagram offset correctly */ |
| 725 | offset = ALIGN(offset, ctx->tx_modulus) + ctx->tx_remainder; |
| 726 | /* zero buffer till the first IP datagram */ |
| 727 | cdc_ncm_zero_fill(skb_out->data, 0, offset, offset); |
| 728 | n = 0; |
| 729 | ctx->tx_curr_frame_num = 0; |
| 730 | } |
| 731 | |
| 732 | for (; n < ctx->tx_max_datagrams; n++) { |
| 733 | /* check if end of transmit buffer is reached */ |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 734 | if (offset >= ctx->tx_max) { |
| 735 | ready2send = 1; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 736 | break; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 737 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 738 | /* compute maximum buffer size */ |
| 739 | rem = ctx->tx_max - offset; |
| 740 | |
| 741 | if (skb == NULL) { |
| 742 | skb = ctx->tx_rem_skb; |
| 743 | ctx->tx_rem_skb = NULL; |
| 744 | |
| 745 | /* check for end of skb */ |
| 746 | if (skb == NULL) |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | if (skb->len > rem) { |
| 751 | if (n == 0) { |
| 752 | /* won't fit, MTU problem? */ |
| 753 | dev_kfree_skb_any(skb); |
| 754 | skb = NULL; |
| 755 | ctx->netdev->stats.tx_dropped++; |
| 756 | } else { |
| 757 | /* no room for skb - store for later */ |
| 758 | if (ctx->tx_rem_skb != NULL) { |
| 759 | dev_kfree_skb_any(ctx->tx_rem_skb); |
| 760 | ctx->netdev->stats.tx_dropped++; |
| 761 | } |
| 762 | ctx->tx_rem_skb = skb; |
| 763 | skb = NULL; |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 764 | ready2send = 1; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 765 | } |
| 766 | break; |
| 767 | } |
| 768 | |
| 769 | memcpy(((u8 *)skb_out->data) + offset, skb->data, skb->len); |
| 770 | |
| 771 | ctx->tx_ncm.dpe16[n].wDatagramLength = cpu_to_le16(skb->len); |
| 772 | ctx->tx_ncm.dpe16[n].wDatagramIndex = cpu_to_le16(offset); |
| 773 | |
| 774 | /* update offset */ |
| 775 | offset += skb->len; |
| 776 | |
| 777 | /* store last valid offset before alignment */ |
| 778 | last_offset = offset; |
| 779 | |
| 780 | /* align offset correctly */ |
| 781 | offset = ALIGN(offset, ctx->tx_modulus) + ctx->tx_remainder; |
| 782 | |
| 783 | /* zero padding */ |
| 784 | cdc_ncm_zero_fill(skb_out->data, last_offset, offset, |
| 785 | ctx->tx_max); |
| 786 | dev_kfree_skb_any(skb); |
| 787 | skb = NULL; |
| 788 | } |
| 789 | |
| 790 | /* free up any dangling skb */ |
| 791 | if (skb != NULL) { |
| 792 | dev_kfree_skb_any(skb); |
| 793 | skb = NULL; |
| 794 | ctx->netdev->stats.tx_dropped++; |
| 795 | } |
| 796 | |
| 797 | ctx->tx_curr_frame_num = n; |
| 798 | |
| 799 | if (n == 0) { |
| 800 | /* wait for more frames */ |
| 801 | /* push variables */ |
| 802 | ctx->tx_curr_skb = skb_out; |
| 803 | ctx->tx_curr_offset = offset; |
| 804 | ctx->tx_curr_last_offset = last_offset; |
| 805 | goto exit_no_skb; |
| 806 | |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 807 | } else if ((n < ctx->tx_max_datagrams) && (ready2send == 0)) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 808 | /* wait for more frames */ |
| 809 | /* push variables */ |
| 810 | ctx->tx_curr_skb = skb_out; |
| 811 | ctx->tx_curr_offset = offset; |
| 812 | ctx->tx_curr_last_offset = last_offset; |
| 813 | /* set the pending count */ |
| 814 | if (n < CDC_NCM_RESTART_TIMER_DATAGRAM_CNT) |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 815 | ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 816 | goto exit_no_skb; |
| 817 | |
| 818 | } else { |
| 819 | /* frame goes out */ |
| 820 | /* variables will be reset at next call */ |
| 821 | } |
| 822 | |
| 823 | /* check for overflow */ |
| 824 | if (last_offset > ctx->tx_max) |
| 825 | last_offset = ctx->tx_max; |
| 826 | |
| 827 | /* revert offset */ |
| 828 | offset = last_offset; |
| 829 | |
| 830 | /* |
| 831 | * If collected data size is less or equal CDC_NCM_MIN_TX_PKT bytes, |
| 832 | * we send buffers as it is. If we get more data, it would be more |
| 833 | * efficient for USB HS mobile device with DMA engine to receive a full |
| 834 | * size NTB, than canceling DMA transfer and receiving a short packet. |
| 835 | */ |
| 836 | if (offset > CDC_NCM_MIN_TX_PKT) |
| 837 | offset = ctx->tx_max; |
| 838 | |
| 839 | /* final zero padding */ |
| 840 | cdc_ncm_zero_fill(skb_out->data, last_offset, offset, ctx->tx_max); |
| 841 | |
| 842 | /* store last offset */ |
| 843 | last_offset = offset; |
| 844 | |
Alexey Orishko | 6c60408 | 2011-05-06 03:01:30 +0000 | [diff] [blame] | 845 | if (((last_offset < ctx->tx_max) && ((last_offset % |
| 846 | le16_to_cpu(ctx->out_ep->desc.wMaxPacketSize)) == 0)) || |
| 847 | (((last_offset == ctx->tx_max) && ((ctx->tx_max % |
| 848 | le16_to_cpu(ctx->out_ep->desc.wMaxPacketSize)) == 0)) && |
| 849 | (ctx->tx_max < le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize)))) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 850 | /* force short packet */ |
| 851 | *(((u8 *)skb_out->data) + last_offset) = 0; |
| 852 | last_offset++; |
| 853 | } |
| 854 | |
| 855 | /* zero the rest of the DPEs plus the last NULL entry */ |
| 856 | for (; n <= CDC_NCM_DPT_DATAGRAMS_MAX; n++) { |
| 857 | ctx->tx_ncm.dpe16[n].wDatagramLength = 0; |
| 858 | ctx->tx_ncm.dpe16[n].wDatagramIndex = 0; |
| 859 | } |
| 860 | |
| 861 | /* fill out 16-bit NTB header */ |
| 862 | ctx->tx_ncm.nth16.dwSignature = cpu_to_le32(USB_CDC_NCM_NTH16_SIGN); |
| 863 | ctx->tx_ncm.nth16.wHeaderLength = |
| 864 | cpu_to_le16(sizeof(ctx->tx_ncm.nth16)); |
| 865 | ctx->tx_ncm.nth16.wSequence = cpu_to_le16(ctx->tx_seq); |
| 866 | ctx->tx_ncm.nth16.wBlockLength = cpu_to_le16(last_offset); |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 867 | index = ALIGN(sizeof(struct usb_cdc_ncm_nth16), ctx->tx_ndp_modulus); |
| 868 | ctx->tx_ncm.nth16.wNdpIndex = cpu_to_le16(index); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 869 | |
| 870 | memcpy(skb_out->data, &(ctx->tx_ncm.nth16), sizeof(ctx->tx_ncm.nth16)); |
| 871 | ctx->tx_seq++; |
| 872 | |
| 873 | /* fill out 16-bit NDP table */ |
| 874 | ctx->tx_ncm.ndp16.dwSignature = |
| 875 | cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN); |
| 876 | rem = sizeof(ctx->tx_ncm.ndp16) + ((ctx->tx_curr_frame_num + 1) * |
| 877 | sizeof(struct usb_cdc_ncm_dpe16)); |
| 878 | ctx->tx_ncm.ndp16.wLength = cpu_to_le16(rem); |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 879 | ctx->tx_ncm.ndp16.wNextNdpIndex = 0; /* reserved */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 880 | |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 881 | memcpy(((u8 *)skb_out->data) + index, |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 882 | &(ctx->tx_ncm.ndp16), |
| 883 | sizeof(ctx->tx_ncm.ndp16)); |
| 884 | |
Giuseppe Scrivano | 36c3541 | 2011-08-03 22:10:29 +0000 | [diff] [blame] | 885 | memcpy(((u8 *)skb_out->data) + index + sizeof(ctx->tx_ncm.ndp16), |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 886 | &(ctx->tx_ncm.dpe16), |
| 887 | (ctx->tx_curr_frame_num + 1) * |
| 888 | sizeof(struct usb_cdc_ncm_dpe16)); |
| 889 | |
| 890 | /* set frame length */ |
| 891 | skb_put(skb_out, last_offset); |
| 892 | |
| 893 | /* return skb */ |
| 894 | ctx->tx_curr_skb = NULL; |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 895 | ctx->netdev->stats.tx_packets += ctx->tx_curr_frame_num; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 896 | return skb_out; |
| 897 | |
| 898 | exit_no_skb: |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 899 | /* Start timer, if there is a remaining skb */ |
| 900 | if (ctx->tx_curr_skb != NULL) |
| 901 | cdc_ncm_tx_timeout_start(ctx); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 902 | return NULL; |
| 903 | } |
| 904 | |
| 905 | static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx) |
| 906 | { |
| 907 | /* start timer, if not already started */ |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 908 | if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop))) |
| 909 | hrtimer_start(&ctx->tx_timer, |
| 910 | ktime_set(0, CDC_NCM_TIMER_INTERVAL), |
| 911 | HRTIMER_MODE_REL); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 914 | static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *timer) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 915 | { |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 916 | struct cdc_ncm_ctx *ctx = |
| 917 | container_of(timer, struct cdc_ncm_ctx, tx_timer); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 918 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 919 | if (!atomic_read(&ctx->stop)) |
| 920 | tasklet_schedule(&ctx->bh); |
| 921 | return HRTIMER_NORESTART; |
| 922 | } |
| 923 | |
| 924 | static void cdc_ncm_txpath_bh(unsigned long param) |
| 925 | { |
| 926 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)param; |
| 927 | |
| 928 | spin_lock_bh(&ctx->mtx); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 929 | if (ctx->tx_timer_pending != 0) { |
| 930 | ctx->tx_timer_pending--; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 931 | cdc_ncm_tx_timeout_start(ctx); |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 932 | spin_unlock_bh(&ctx->mtx); |
Alexey Orishko | f742aa8 | 2011-01-17 07:07:25 +0000 | [diff] [blame] | 933 | } else if (ctx->netdev != NULL) { |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 934 | spin_unlock_bh(&ctx->mtx); |
| 935 | netif_tx_lock_bh(ctx->netdev); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 936 | usbnet_start_xmit(NULL, ctx->netdev); |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 937 | netif_tx_unlock_bh(ctx->netdev); |
Alexey Orishko | f742aa8 | 2011-01-17 07:07:25 +0000 | [diff] [blame] | 938 | } |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | static struct sk_buff * |
| 942 | cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) |
| 943 | { |
| 944 | struct sk_buff *skb_out; |
| 945 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 946 | |
| 947 | /* |
| 948 | * The Ethernet API we are using does not support transmitting |
| 949 | * multiple Ethernet frames in a single call. This driver will |
| 950 | * accumulate multiple Ethernet frames and send out a larger |
| 951 | * USB frame when the USB buffer is full or when a single jiffies |
| 952 | * timeout happens. |
| 953 | */ |
| 954 | if (ctx == NULL) |
| 955 | goto error; |
| 956 | |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 957 | spin_lock_bh(&ctx->mtx); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 958 | skb_out = cdc_ncm_fill_tx_frame(ctx, skb); |
Alexey Orishko | c84ff1d | 2012-03-14 11:26:10 +0000 | [diff] [blame] | 959 | spin_unlock_bh(&ctx->mtx); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 960 | return skb_out; |
| 961 | |
| 962 | error: |
| 963 | if (skb != NULL) |
| 964 | dev_kfree_skb_any(skb); |
| 965 | |
| 966 | return NULL; |
| 967 | } |
| 968 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 969 | /* verify NTB header and return offset of first NDP, or negative error */ |
| 970 | static 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] | 971 | { |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 972 | struct usb_cdc_ncm_nth16 *nth16; |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 973 | int len; |
| 974 | int ret = -EINVAL; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 975 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 976 | if (ctx == NULL) |
| 977 | goto error; |
| 978 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 979 | if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth16) + |
| 980 | sizeof(struct usb_cdc_ncm_ndp16))) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 981 | pr_debug("frame too short\n"); |
| 982 | goto error; |
| 983 | } |
| 984 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 985 | nth16 = (struct usb_cdc_ncm_nth16 *)skb_in->data; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 986 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 987 | if (le32_to_cpu(nth16->dwSignature) != USB_CDC_NCM_NTH16_SIGN) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 988 | pr_debug("invalid NTH16 signature <%u>\n", |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 989 | le32_to_cpu(nth16->dwSignature)); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 990 | goto error; |
| 991 | } |
| 992 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 993 | len = le16_to_cpu(nth16->wBlockLength); |
| 994 | if (len > ctx->rx_max) { |
| 995 | pr_debug("unsupported NTB block length %u/%u\n", len, |
| 996 | ctx->rx_max); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 997 | goto error; |
| 998 | } |
| 999 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1000 | if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) && |
| 1001 | (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) && |
| 1002 | !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth16->wSequence))) { |
| 1003 | pr_debug("sequence number glitch prev=%d curr=%d\n", |
| 1004 | ctx->rx_seq, le16_to_cpu(nth16->wSequence)); |
| 1005 | } |
| 1006 | ctx->rx_seq = le16_to_cpu(nth16->wSequence); |
| 1007 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 1008 | ret = le16_to_cpu(nth16->wNdpIndex); |
| 1009 | error: |
| 1010 | return ret; |
| 1011 | } |
| 1012 | |
| 1013 | /* verify NDP header and return number of datagrams, or negative error */ |
| 1014 | static int cdc_ncm_rx_verify_ndp16(struct sk_buff *skb_in, int ndpoffset) |
| 1015 | { |
| 1016 | struct usb_cdc_ncm_ndp16 *ndp16; |
| 1017 | int ret = -EINVAL; |
| 1018 | |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 1019 | if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp16)) > skb_in->len) { |
| 1020 | pr_debug("invalid NDP offset <%u>\n", ndpoffset); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1021 | goto error; |
| 1022 | } |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 1023 | ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1024 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1025 | if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1026 | pr_debug("invalid DPT16 length <%u>\n", |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1027 | le32_to_cpu(ndp16->dwSignature)); |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 1028 | goto error; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 1031 | ret = ((le16_to_cpu(ndp16->wLength) - |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1032 | sizeof(struct usb_cdc_ncm_ndp16)) / |
| 1033 | sizeof(struct usb_cdc_ncm_dpe16)); |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 1034 | ret--; /* we process NDP entries except for the last one */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1035 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 1036 | 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] | 1037 | skb_in->len) { |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 1038 | pr_debug("Invalid nframes = %d\n", ret); |
| 1039 | ret = -EINVAL; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Bjørn Mork | ff06ab1 | 2012-10-22 10:56:33 +0000 | [diff] [blame^] | 1042 | error: |
| 1043 | return ret; |
| 1044 | } |
| 1045 | |
| 1046 | static int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in) |
| 1047 | { |
| 1048 | struct sk_buff *skb; |
| 1049 | struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
| 1050 | int len; |
| 1051 | int nframes; |
| 1052 | int x; |
| 1053 | int offset; |
| 1054 | struct usb_cdc_ncm_ndp16 *ndp16; |
| 1055 | struct usb_cdc_ncm_dpe16 *dpe16; |
| 1056 | int ndpoffset; |
| 1057 | int loopcount = 50; /* arbitrary max preventing infinite loop */ |
| 1058 | |
| 1059 | ndpoffset = cdc_ncm_rx_verify_nth16(ctx, skb_in); |
| 1060 | if (ndpoffset < 0) |
| 1061 | goto error; |
| 1062 | |
| 1063 | next_ndp: |
| 1064 | nframes = cdc_ncm_rx_verify_ndp16(skb_in, ndpoffset); |
| 1065 | if (nframes < 0) |
| 1066 | goto error; |
| 1067 | |
| 1068 | ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset); |
| 1069 | |
| 1070 | if (le32_to_cpu(ndp16->dwSignature) != USB_CDC_NCM_NDP16_NOCRC_SIGN) { |
| 1071 | pr_debug("invalid DPT16 signature <%u>\n", |
| 1072 | le32_to_cpu(ndp16->dwSignature)); |
| 1073 | goto err_ndp; |
| 1074 | } |
| 1075 | dpe16 = ndp16->dpe16; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1076 | |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1077 | for (x = 0; x < nframes; x++, dpe16++) { |
| 1078 | offset = le16_to_cpu(dpe16->wDatagramIndex); |
| 1079 | len = le16_to_cpu(dpe16->wDatagramLength); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1080 | |
| 1081 | /* |
| 1082 | * CDC NCM ch. 3.7 |
| 1083 | * All entries after first NULL entry are to be ignored |
| 1084 | */ |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1085 | if ((offset == 0) || (len == 0)) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1086 | if (!x) |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 1087 | goto err_ndp; /* empty NTB */ |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1088 | break; |
| 1089 | } |
| 1090 | |
| 1091 | /* sanity checking */ |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1092 | if (((offset + len) > skb_in->len) || |
| 1093 | (len > ctx->rx_max) || (len < ETH_HLEN)) { |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1094 | pr_debug("invalid frame detected (ignored)" |
Alexey Orishko | f742aa8 | 2011-01-17 07:07:25 +0000 | [diff] [blame] | 1095 | "offset[%u]=%u, length=%u, skb=%p\n", |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1096 | x, offset, len, skb_in); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1097 | if (!x) |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 1098 | goto err_ndp; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1099 | break; |
| 1100 | |
| 1101 | } else { |
| 1102 | skb = skb_clone(skb_in, GFP_ATOMIC); |
Jesper Juhl | 9e56790 | 2011-01-13 11:40:11 +0000 | [diff] [blame] | 1103 | if (!skb) |
| 1104 | goto error; |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1105 | skb->len = len; |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1106 | skb->data = ((u8 *)skb_in->data) + offset; |
Alexey Orishko | d5ddb4a | 2012-03-14 11:26:12 +0000 | [diff] [blame] | 1107 | skb_set_tail_pointer(skb, len); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1108 | usbnet_skb_return(dev, skb); |
| 1109 | } |
| 1110 | } |
Bjørn Mork | 75d67d3 | 2012-10-22 10:56:32 +0000 | [diff] [blame] | 1111 | err_ndp: |
| 1112 | /* are there more NDPs to process? */ |
| 1113 | ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex); |
| 1114 | if (ndpoffset && loopcount--) |
| 1115 | goto next_ndp; |
| 1116 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1117 | return 1; |
| 1118 | error: |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
| 1122 | static void |
| 1123 | cdc_ncm_speed_change(struct cdc_ncm_ctx *ctx, |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1124 | struct usb_cdc_speed_change *data) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1125 | { |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1126 | uint32_t rx_speed = le32_to_cpu(data->DLBitRRate); |
| 1127 | uint32_t tx_speed = le32_to_cpu(data->ULBitRate); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1128 | |
| 1129 | /* |
| 1130 | * Currently the USB-NET API does not support reporting the actual |
| 1131 | * device speed. Do print it instead. |
| 1132 | */ |
| 1133 | if ((tx_speed != ctx->tx_speed) || (rx_speed != ctx->rx_speed)) { |
| 1134 | ctx->tx_speed = tx_speed; |
| 1135 | ctx->rx_speed = rx_speed; |
| 1136 | |
| 1137 | if ((tx_speed > 1000000) && (rx_speed > 1000000)) { |
| 1138 | printk(KERN_INFO KBUILD_MODNAME |
| 1139 | ": %s: %u mbit/s downlink " |
| 1140 | "%u mbit/s uplink\n", |
| 1141 | ctx->netdev->name, |
| 1142 | (unsigned int)(rx_speed / 1000000U), |
| 1143 | (unsigned int)(tx_speed / 1000000U)); |
| 1144 | } else { |
| 1145 | printk(KERN_INFO KBUILD_MODNAME |
| 1146 | ": %s: %u kbit/s downlink " |
| 1147 | "%u kbit/s uplink\n", |
| 1148 | ctx->netdev->name, |
| 1149 | (unsigned int)(rx_speed / 1000U), |
| 1150 | (unsigned int)(tx_speed / 1000U)); |
| 1151 | } |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | static void cdc_ncm_status(struct usbnet *dev, struct urb *urb) |
| 1156 | { |
| 1157 | struct cdc_ncm_ctx *ctx; |
| 1158 | struct usb_cdc_notification *event; |
| 1159 | |
| 1160 | ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
| 1161 | |
| 1162 | if (urb->actual_length < sizeof(*event)) |
| 1163 | return; |
| 1164 | |
| 1165 | /* test for split data in 8-byte chunks */ |
| 1166 | if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) { |
| 1167 | cdc_ncm_speed_change(ctx, |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1168 | (struct usb_cdc_speed_change *)urb->transfer_buffer); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1169 | return; |
| 1170 | } |
| 1171 | |
| 1172 | event = urb->transfer_buffer; |
| 1173 | |
| 1174 | switch (event->bNotificationType) { |
| 1175 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: |
| 1176 | /* |
| 1177 | * According to the CDC NCM specification ch.7.1 |
| 1178 | * USB_CDC_NOTIFY_NETWORK_CONNECTION notification shall be |
| 1179 | * sent by device after USB_CDC_NOTIFY_SPEED_CHANGE. |
| 1180 | */ |
| 1181 | ctx->connected = event->wValue; |
| 1182 | |
| 1183 | printk(KERN_INFO KBUILD_MODNAME ": %s: network connection:" |
| 1184 | " %sconnected\n", |
| 1185 | ctx->netdev->name, ctx->connected ? "" : "dis"); |
| 1186 | |
| 1187 | if (ctx->connected) |
| 1188 | netif_carrier_on(dev->net); |
| 1189 | else { |
| 1190 | netif_carrier_off(dev->net); |
| 1191 | ctx->tx_speed = ctx->rx_speed = 0; |
| 1192 | } |
| 1193 | break; |
| 1194 | |
| 1195 | case USB_CDC_NOTIFY_SPEED_CHANGE: |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1196 | if (urb->actual_length < (sizeof(*event) + |
| 1197 | sizeof(struct usb_cdc_speed_change))) |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1198 | set_bit(EVENT_STS_SPLIT, &dev->flags); |
| 1199 | else |
| 1200 | cdc_ncm_speed_change(ctx, |
Alexey Orishko | 84e77a8 | 2011-02-07 09:45:10 +0000 | [diff] [blame] | 1201 | (struct usb_cdc_speed_change *) &event[1]); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1202 | break; |
| 1203 | |
| 1204 | default: |
| 1205 | dev_err(&dev->udev->dev, "NCM: unexpected " |
| 1206 | "notification 0x%02x!\n", event->bNotificationType); |
| 1207 | break; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | static int cdc_ncm_check_connect(struct usbnet *dev) |
| 1212 | { |
| 1213 | struct cdc_ncm_ctx *ctx; |
| 1214 | |
| 1215 | ctx = (struct cdc_ncm_ctx *)dev->data[0]; |
| 1216 | if (ctx == NULL) |
| 1217 | return 1; /* disconnected */ |
| 1218 | |
| 1219 | return !ctx->connected; |
| 1220 | } |
| 1221 | |
| 1222 | static int |
| 1223 | cdc_ncm_probe(struct usb_interface *udev, const struct usb_device_id *prod) |
| 1224 | { |
| 1225 | return usbnet_probe(udev, prod); |
| 1226 | } |
| 1227 | |
| 1228 | static void cdc_ncm_disconnect(struct usb_interface *intf) |
| 1229 | { |
| 1230 | struct usbnet *dev = usb_get_intfdata(intf); |
| 1231 | |
| 1232 | if (dev == NULL) |
| 1233 | return; /* already disconnected */ |
| 1234 | |
| 1235 | usbnet_disconnect(intf); |
| 1236 | } |
| 1237 | |
| 1238 | static int cdc_ncm_manage_power(struct usbnet *dev, int status) |
| 1239 | { |
| 1240 | dev->intf->needs_remote_wakeup = status; |
| 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | static const struct driver_info cdc_ncm_info = { |
| 1245 | .description = "CDC NCM", |
Arnd Bergmann | c261344 | 2011-04-01 20:12:02 -0700 | [diff] [blame] | 1246 | .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET, |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1247 | .bind = cdc_ncm_bind, |
| 1248 | .unbind = cdc_ncm_unbind, |
| 1249 | .check_connect = cdc_ncm_check_connect, |
| 1250 | .manage_power = cdc_ncm_manage_power, |
| 1251 | .status = cdc_ncm_status, |
| 1252 | .rx_fixup = cdc_ncm_rx_fixup, |
| 1253 | .tx_fixup = cdc_ncm_tx_fixup, |
| 1254 | }; |
| 1255 | |
Dan Williams | f94898e | 2012-07-24 08:43:22 +0000 | [diff] [blame] | 1256 | /* Same as cdc_ncm_info, but with FLAG_WWAN */ |
| 1257 | static const struct driver_info wwan_info = { |
| 1258 | .description = "Mobile Broadband Network Device", |
| 1259 | .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET |
| 1260 | | FLAG_WWAN, |
| 1261 | .bind = cdc_ncm_bind, |
| 1262 | .unbind = cdc_ncm_unbind, |
| 1263 | .check_connect = cdc_ncm_check_connect, |
| 1264 | .manage_power = cdc_ncm_manage_power, |
| 1265 | .status = cdc_ncm_status, |
| 1266 | .rx_fixup = cdc_ncm_rx_fixup, |
| 1267 | .tx_fixup = cdc_ncm_tx_fixup, |
| 1268 | }; |
| 1269 | |
| 1270 | static const struct usb_device_id cdc_devs[] = { |
| 1271 | /* Ericsson MBM devices like F5521gw */ |
| 1272 | { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 1273 | | USB_DEVICE_ID_MATCH_VENDOR, |
| 1274 | .idVendor = 0x0bdb, |
| 1275 | .bInterfaceClass = USB_CLASS_COMM, |
| 1276 | .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM, |
| 1277 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
| 1278 | .driver_info = (unsigned long) &wwan_info, |
| 1279 | }, |
| 1280 | |
Peter Meiser | f3a1ef9c | 2012-08-02 02:30:20 +0000 | [diff] [blame] | 1281 | /* Dell branded MBM devices like DW5550 */ |
| 1282 | { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 1283 | | USB_DEVICE_ID_MATCH_VENDOR, |
| 1284 | .idVendor = 0x413c, |
| 1285 | .bInterfaceClass = USB_CLASS_COMM, |
| 1286 | .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM, |
| 1287 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
| 1288 | .driver_info = (unsigned long) &wwan_info, |
| 1289 | }, |
| 1290 | |
| 1291 | /* Toshiba branded MBM devices */ |
| 1292 | { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO |
| 1293 | | USB_DEVICE_ID_MATCH_VENDOR, |
| 1294 | .idVendor = 0x0930, |
| 1295 | .bInterfaceClass = USB_CLASS_COMM, |
| 1296 | .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM, |
| 1297 | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
| 1298 | .driver_info = (unsigned long) &wwan_info, |
| 1299 | }, |
| 1300 | |
Dan Williams | f94898e | 2012-07-24 08:43:22 +0000 | [diff] [blame] | 1301 | /* Generic CDC-NCM devices */ |
| 1302 | { USB_INTERFACE_INFO(USB_CLASS_COMM, |
| 1303 | USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE), |
| 1304 | .driver_info = (unsigned long)&cdc_ncm_info, |
| 1305 | }, |
| 1306 | { |
| 1307 | }, |
| 1308 | }; |
| 1309 | MODULE_DEVICE_TABLE(usb, cdc_devs); |
| 1310 | |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1311 | static struct usb_driver cdc_ncm_driver = { |
| 1312 | .name = "cdc_ncm", |
| 1313 | .id_table = cdc_devs, |
| 1314 | .probe = cdc_ncm_probe, |
| 1315 | .disconnect = cdc_ncm_disconnect, |
| 1316 | .suspend = usbnet_suspend, |
| 1317 | .resume = usbnet_resume, |
Stefan Metzmacher | 85e3c65 | 2011-06-01 02:01:41 +0000 | [diff] [blame] | 1318 | .reset_resume = usbnet_resume, |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1319 | .supports_autosuspend = 1, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 1320 | .disable_hub_initiated_lpm = 1, |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1321 | }; |
| 1322 | |
Greg Kroah-Hartman | d632eb1 | 2011-11-18 09:44:20 -0800 | [diff] [blame] | 1323 | module_usb_driver(cdc_ncm_driver); |
Alexey Orishko | 900d495 | 2010-11-29 23:23:28 +0000 | [diff] [blame] | 1324 | |
| 1325 | MODULE_AUTHOR("Hans Petter Selasky"); |
| 1326 | MODULE_DESCRIPTION("USB CDC NCM host driver"); |
| 1327 | MODULE_LICENSE("Dual BSD/GPL"); |