Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cdc-wdm.c |
| 3 | * |
| 4 | * This driver supports USB CDC WCM Device Management. |
| 5 | * |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 6 | * Copyright (c) 2007-2009 Oliver Neukum |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 7 | * |
| 8 | * Some code taken from cdc-acm.c |
| 9 | * |
| 10 | * Released under the GPLv2. |
| 11 | * |
| 12 | * Many thanks to Carl Nordbeck |
| 13 | */ |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/module.h> |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 18 | #include <linux/mutex.h> |
| 19 | #include <linux/uaccess.h> |
| 20 | #include <linux/bitops.h> |
| 21 | #include <linux/poll.h> |
| 22 | #include <linux/usb.h> |
| 23 | #include <linux/usb/cdc.h> |
| 24 | #include <asm/byteorder.h> |
| 25 | #include <asm/unaligned.h> |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 26 | #include <linux/usb/cdc-wdm.h> |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Version Information |
| 30 | */ |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 31 | #define DRIVER_VERSION "v0.03" |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 32 | #define DRIVER_AUTHOR "Oliver Neukum" |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 33 | #define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management" |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 34 | |
Bjørn Mork | fec67b4 | 2012-01-25 13:03:29 +0100 | [diff] [blame] | 35 | #define HUAWEI_VENDOR_ID 0x12D1 |
| 36 | |
Németh Márton | 6ef4852 | 2010-01-10 15:33:45 +0100 | [diff] [blame] | 37 | static const struct usb_device_id wdm_ids[] = { |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 38 | { |
| 39 | .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS | |
| 40 | USB_DEVICE_ID_MATCH_INT_SUBCLASS, |
| 41 | .bInterfaceClass = USB_CLASS_COMM, |
| 42 | .bInterfaceSubClass = USB_CDC_SUBCLASS_DMM |
| 43 | }, |
Bjørn Mork | fec67b4 | 2012-01-25 13:03:29 +0100 | [diff] [blame] | 44 | { |
| 45 | /* |
| 46 | * Huawei E392, E398 and possibly other Qualcomm based modems |
| 47 | * embed the Qualcomm QMI protocol inside CDC on CDC ECM like |
| 48 | * control interfaces. Userspace access to this is required |
| 49 | * to configure the accompanying data interface |
| 50 | */ |
| 51 | .match_flags = USB_DEVICE_ID_MATCH_VENDOR | |
| 52 | USB_DEVICE_ID_MATCH_INT_INFO, |
| 53 | .idVendor = HUAWEI_VENDOR_ID, |
| 54 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
| 55 | .bInterfaceSubClass = 1, |
| 56 | .bInterfaceProtocol = 9, /* NOTE: CDC ECM control interface! */ |
| 57 | }, |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 58 | { } |
| 59 | }; |
| 60 | |
Oliver Neukum | aa5380b | 2008-10-13 14:05:20 +0200 | [diff] [blame] | 61 | MODULE_DEVICE_TABLE (usb, wdm_ids); |
| 62 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 63 | #define WDM_MINOR_BASE 176 |
| 64 | |
| 65 | |
| 66 | #define WDM_IN_USE 1 |
| 67 | #define WDM_DISCONNECTING 2 |
| 68 | #define WDM_RESULT 3 |
| 69 | #define WDM_READ 4 |
| 70 | #define WDM_INT_STALL 5 |
| 71 | #define WDM_POLL_RUNNING 6 |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 72 | #define WDM_RESPONDING 7 |
Oliver Neukum | beb1d35 | 2010-02-27 20:55:52 +0100 | [diff] [blame] | 73 | #define WDM_SUSPENDING 8 |
Bjørn Mork | 8804420 | 2012-02-10 09:44:08 +0100 | [diff] [blame] | 74 | #define WDM_RESETTING 9 |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 75 | |
| 76 | #define WDM_MAX 16 |
| 77 | |
Bjørn Mork | 7e3054a | 2012-01-20 01:49:57 +0100 | [diff] [blame] | 78 | /* CDC-WMC r1.1 requires wMaxCommand to be "at least 256 decimal (0x100)" */ |
| 79 | #define WDM_DEFAULT_BUFSIZE 256 |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 80 | |
| 81 | static DEFINE_MUTEX(wdm_mutex); |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 82 | static DEFINE_SPINLOCK(wdm_device_list_lock); |
| 83 | static LIST_HEAD(wdm_device_list); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 84 | |
| 85 | /* --- method tables --- */ |
| 86 | |
| 87 | struct wdm_device { |
| 88 | u8 *inbuf; /* buffer for response */ |
| 89 | u8 *outbuf; /* buffer for command */ |
| 90 | u8 *sbuf; /* buffer for status */ |
| 91 | u8 *ubuf; /* buffer for copy to user space */ |
| 92 | |
| 93 | struct urb *command; |
| 94 | struct urb *response; |
| 95 | struct urb *validity; |
| 96 | struct usb_interface *intf; |
| 97 | struct usb_ctrlrequest *orq; |
| 98 | struct usb_ctrlrequest *irq; |
| 99 | spinlock_t iuspin; |
| 100 | |
| 101 | unsigned long flags; |
| 102 | u16 bufsize; |
| 103 | u16 wMaxCommand; |
| 104 | u16 wMaxPacketSize; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 105 | __le16 inum; |
| 106 | int reslength; |
| 107 | int length; |
| 108 | int read; |
| 109 | int count; |
| 110 | dma_addr_t shandle; |
| 111 | dma_addr_t ihandle; |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 112 | struct mutex wlock; |
| 113 | struct mutex rlock; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 114 | wait_queue_head_t wait; |
| 115 | struct work_struct rxwork; |
| 116 | int werr; |
| 117 | int rerr; |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 118 | |
| 119 | struct list_head device_list; |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 120 | int (*manage_power)(struct usb_interface *, int); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | static struct usb_driver wdm_driver; |
| 124 | |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 125 | /* return intfdata if we own the interface, else look up intf in the list */ |
| 126 | static struct wdm_device *wdm_find_device(struct usb_interface *intf) |
| 127 | { |
| 128 | struct wdm_device *desc = NULL; |
| 129 | |
| 130 | spin_lock(&wdm_device_list_lock); |
| 131 | list_for_each_entry(desc, &wdm_device_list, device_list) |
| 132 | if (desc->intf == intf) |
| 133 | break; |
| 134 | spin_unlock(&wdm_device_list_lock); |
| 135 | |
| 136 | return desc; |
| 137 | } |
| 138 | |
| 139 | static struct wdm_device *wdm_find_device_by_minor(int minor) |
| 140 | { |
| 141 | struct wdm_device *desc = NULL; |
| 142 | |
| 143 | spin_lock(&wdm_device_list_lock); |
| 144 | list_for_each_entry(desc, &wdm_device_list, device_list) |
| 145 | if (desc->intf->minor == minor) |
| 146 | break; |
| 147 | spin_unlock(&wdm_device_list_lock); |
| 148 | |
| 149 | return desc; |
| 150 | } |
| 151 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 152 | /* --- callbacks --- */ |
| 153 | static void wdm_out_callback(struct urb *urb) |
| 154 | { |
| 155 | struct wdm_device *desc; |
| 156 | desc = urb->context; |
| 157 | spin_lock(&desc->iuspin); |
| 158 | desc->werr = urb->status; |
| 159 | spin_unlock(&desc->iuspin); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 160 | kfree(desc->outbuf); |
Oliver Neukum | 5c22837 | 2012-04-26 21:59:10 +0200 | [diff] [blame] | 161 | desc->outbuf = NULL; |
| 162 | clear_bit(WDM_IN_USE, &desc->flags); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 163 | wake_up(&desc->wait); |
| 164 | } |
| 165 | |
| 166 | static void wdm_in_callback(struct urb *urb) |
| 167 | { |
| 168 | struct wdm_device *desc = urb->context; |
| 169 | int status = urb->status; |
| 170 | |
| 171 | spin_lock(&desc->iuspin); |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 172 | clear_bit(WDM_RESPONDING, &desc->flags); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 173 | |
| 174 | if (status) { |
| 175 | switch (status) { |
| 176 | case -ENOENT: |
| 177 | dev_dbg(&desc->intf->dev, |
| 178 | "nonzero urb status received: -ENOENT"); |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 179 | goto skip_error; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 180 | case -ECONNRESET: |
| 181 | dev_dbg(&desc->intf->dev, |
| 182 | "nonzero urb status received: -ECONNRESET"); |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 183 | goto skip_error; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 184 | case -ESHUTDOWN: |
| 185 | dev_dbg(&desc->intf->dev, |
| 186 | "nonzero urb status received: -ESHUTDOWN"); |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 187 | goto skip_error; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 188 | case -EPIPE: |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 189 | dev_err(&desc->intf->dev, |
| 190 | "nonzero urb status received: -EPIPE\n"); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 191 | break; |
| 192 | default: |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 193 | dev_err(&desc->intf->dev, |
| 194 | "Unexpected error %d\n", status); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 195 | break; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | desc->rerr = status; |
| 200 | desc->reslength = urb->actual_length; |
| 201 | memmove(desc->ubuf + desc->length, desc->inbuf, desc->reslength); |
| 202 | desc->length += desc->reslength; |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 203 | skip_error: |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 204 | wake_up(&desc->wait); |
| 205 | |
| 206 | set_bit(WDM_READ, &desc->flags); |
| 207 | spin_unlock(&desc->iuspin); |
| 208 | } |
| 209 | |
| 210 | static void wdm_int_callback(struct urb *urb) |
| 211 | { |
| 212 | int rv = 0; |
| 213 | int status = urb->status; |
| 214 | struct wdm_device *desc; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 215 | struct usb_cdc_notification *dr; |
| 216 | |
| 217 | desc = urb->context; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 218 | dr = (struct usb_cdc_notification *)desc->sbuf; |
| 219 | |
| 220 | if (status) { |
| 221 | switch (status) { |
| 222 | case -ESHUTDOWN: |
| 223 | case -ENOENT: |
| 224 | case -ECONNRESET: |
| 225 | return; /* unplug */ |
| 226 | case -EPIPE: |
| 227 | set_bit(WDM_INT_STALL, &desc->flags); |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 228 | dev_err(&desc->intf->dev, "Stall on int endpoint\n"); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 229 | goto sw; /* halt is cleared in work */ |
| 230 | default: |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 231 | dev_err(&desc->intf->dev, |
| 232 | "nonzero urb status received: %d\n", status); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 233 | break; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | if (urb->actual_length < sizeof(struct usb_cdc_notification)) { |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 238 | dev_err(&desc->intf->dev, "wdm_int_callback - %d bytes\n", |
| 239 | urb->actual_length); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 240 | goto exit; |
| 241 | } |
| 242 | |
| 243 | switch (dr->bNotificationType) { |
| 244 | case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: |
| 245 | dev_dbg(&desc->intf->dev, |
| 246 | "NOTIFY_RESPONSE_AVAILABLE received: index %d len %d", |
| 247 | dr->wIndex, dr->wLength); |
| 248 | break; |
| 249 | |
| 250 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: |
| 251 | |
| 252 | dev_dbg(&desc->intf->dev, |
| 253 | "NOTIFY_NETWORK_CONNECTION %s network", |
| 254 | dr->wValue ? "connected to" : "disconnected from"); |
| 255 | goto exit; |
| 256 | default: |
| 257 | clear_bit(WDM_POLL_RUNNING, &desc->flags); |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 258 | dev_err(&desc->intf->dev, |
| 259 | "unknown notification %d received: index %d len %d\n", |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 260 | dr->bNotificationType, dr->wIndex, dr->wLength); |
| 261 | goto exit; |
| 262 | } |
| 263 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 264 | spin_lock(&desc->iuspin); |
| 265 | clear_bit(WDM_READ, &desc->flags); |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 266 | set_bit(WDM_RESPONDING, &desc->flags); |
Oliver Neukum | beb1d35 | 2010-02-27 20:55:52 +0100 | [diff] [blame] | 267 | if (!test_bit(WDM_DISCONNECTING, &desc->flags) |
| 268 | && !test_bit(WDM_SUSPENDING, &desc->flags)) { |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 269 | rv = usb_submit_urb(desc->response, GFP_ATOMIC); |
| 270 | dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", |
| 271 | __func__, rv); |
| 272 | } |
| 273 | spin_unlock(&desc->iuspin); |
| 274 | if (rv < 0) { |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 275 | clear_bit(WDM_RESPONDING, &desc->flags); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 276 | if (rv == -EPERM) |
| 277 | return; |
| 278 | if (rv == -ENOMEM) { |
| 279 | sw: |
| 280 | rv = schedule_work(&desc->rxwork); |
| 281 | if (rv) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 282 | dev_err(&desc->intf->dev, |
| 283 | "Cannot schedule work\n"); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | exit: |
| 287 | rv = usb_submit_urb(urb, GFP_ATOMIC); |
| 288 | if (rv) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 289 | dev_err(&desc->intf->dev, |
| 290 | "%s - usb_submit_urb failed with result %d\n", |
| 291 | __func__, rv); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 292 | |
| 293 | } |
| 294 | |
| 295 | static void kill_urbs(struct wdm_device *desc) |
| 296 | { |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 297 | /* the order here is essential */ |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 298 | usb_kill_urb(desc->command); |
| 299 | usb_kill_urb(desc->validity); |
| 300 | usb_kill_urb(desc->response); |
| 301 | } |
| 302 | |
| 303 | static void free_urbs(struct wdm_device *desc) |
| 304 | { |
| 305 | usb_free_urb(desc->validity); |
| 306 | usb_free_urb(desc->response); |
| 307 | usb_free_urb(desc->command); |
| 308 | } |
| 309 | |
| 310 | static void cleanup(struct wdm_device *desc) |
| 311 | { |
Bjørn Mork | 8457d99 | 2012-01-16 15:12:00 +0100 | [diff] [blame] | 312 | kfree(desc->sbuf); |
| 313 | kfree(desc->inbuf); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 314 | kfree(desc->orq); |
| 315 | kfree(desc->irq); |
| 316 | kfree(desc->ubuf); |
| 317 | free_urbs(desc); |
| 318 | kfree(desc); |
| 319 | } |
| 320 | |
| 321 | static ssize_t wdm_write |
| 322 | (struct file *file, const char __user *buffer, size_t count, loff_t *ppos) |
| 323 | { |
| 324 | u8 *buf; |
| 325 | int rv = -EMSGSIZE, r, we; |
| 326 | struct wdm_device *desc = file->private_data; |
| 327 | struct usb_ctrlrequest *req; |
| 328 | |
| 329 | if (count > desc->wMaxCommand) |
| 330 | count = desc->wMaxCommand; |
| 331 | |
| 332 | spin_lock_irq(&desc->iuspin); |
| 333 | we = desc->werr; |
| 334 | desc->werr = 0; |
| 335 | spin_unlock_irq(&desc->iuspin); |
| 336 | if (we < 0) |
| 337 | return -EIO; |
| 338 | |
Oliver Neukum | 5c22837 | 2012-04-26 21:59:10 +0200 | [diff] [blame] | 339 | buf = kmalloc(count, GFP_KERNEL); |
Oliver Neukum | 860e41a | 2010-02-27 20:54:24 +0100 | [diff] [blame] | 340 | if (!buf) { |
| 341 | rv = -ENOMEM; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 342 | goto outnl; |
Oliver Neukum | 860e41a | 2010-02-27 20:54:24 +0100 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | r = copy_from_user(buf, buffer, count); |
| 346 | if (r > 0) { |
| 347 | kfree(buf); |
| 348 | rv = -EFAULT; |
| 349 | goto outnl; |
| 350 | } |
| 351 | |
| 352 | /* concurrent writes and disconnect */ |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 353 | r = mutex_lock_interruptible(&desc->wlock); |
Oliver Neukum | 860e41a | 2010-02-27 20:54:24 +0100 | [diff] [blame] | 354 | rv = -ERESTARTSYS; |
| 355 | if (r) { |
| 356 | kfree(buf); |
| 357 | goto outnl; |
| 358 | } |
| 359 | |
| 360 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 361 | kfree(buf); |
| 362 | rv = -ENODEV; |
| 363 | goto outnp; |
| 364 | } |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 365 | |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 366 | r = usb_autopm_get_interface(desc->intf); |
Oliver Neukum | 860e41a | 2010-02-27 20:54:24 +0100 | [diff] [blame] | 367 | if (r < 0) { |
| 368 | kfree(buf); |
Oliver Neukum | 12a98b2 | 2012-04-30 09:57:31 +0200 | [diff] [blame] | 369 | rv = usb_translate_errors(r); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 370 | goto outnp; |
Oliver Neukum | 860e41a | 2010-02-27 20:54:24 +0100 | [diff] [blame] | 371 | } |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 372 | |
David Sterba | 0cdfb81 | 2010-12-27 18:49:58 +0100 | [diff] [blame] | 373 | if (!(file->f_flags & O_NONBLOCK)) |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 374 | r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, |
| 375 | &desc->flags)); |
| 376 | else |
| 377 | if (test_bit(WDM_IN_USE, &desc->flags)) |
| 378 | r = -EAGAIN; |
Bjørn Mork | 8804420 | 2012-02-10 09:44:08 +0100 | [diff] [blame] | 379 | |
| 380 | if (test_bit(WDM_RESETTING, &desc->flags)) |
| 381 | r = -EIO; |
| 382 | |
Oliver Neukum | 860e41a | 2010-02-27 20:54:24 +0100 | [diff] [blame] | 383 | if (r < 0) { |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 384 | kfree(buf); |
Oliver Neukum | 12a98b2 | 2012-04-30 09:57:31 +0200 | [diff] [blame] | 385 | rv = r; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 386 | goto out; |
| 387 | } |
| 388 | |
| 389 | req = desc->orq; |
| 390 | usb_fill_control_urb( |
| 391 | desc->command, |
| 392 | interface_to_usbdev(desc->intf), |
| 393 | /* using common endpoint 0 */ |
| 394 | usb_sndctrlpipe(interface_to_usbdev(desc->intf), 0), |
| 395 | (unsigned char *)req, |
| 396 | buf, |
| 397 | count, |
| 398 | wdm_out_callback, |
| 399 | desc |
| 400 | ); |
| 401 | |
| 402 | req->bRequestType = (USB_DIR_OUT | USB_TYPE_CLASS | |
| 403 | USB_RECIP_INTERFACE); |
| 404 | req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND; |
| 405 | req->wValue = 0; |
| 406 | req->wIndex = desc->inum; |
| 407 | req->wLength = cpu_to_le16(count); |
| 408 | set_bit(WDM_IN_USE, &desc->flags); |
Oliver Neukum | 5c22837 | 2012-04-26 21:59:10 +0200 | [diff] [blame] | 409 | desc->outbuf = buf; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 410 | |
| 411 | rv = usb_submit_urb(desc->command, GFP_KERNEL); |
| 412 | if (rv < 0) { |
| 413 | kfree(buf); |
Oliver Neukum | 5c22837 | 2012-04-26 21:59:10 +0200 | [diff] [blame] | 414 | desc->outbuf = NULL; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 415 | clear_bit(WDM_IN_USE, &desc->flags); |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 416 | dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv); |
Oliver Neukum | 12a98b2 | 2012-04-30 09:57:31 +0200 | [diff] [blame] | 417 | rv = usb_translate_errors(rv); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 418 | } else { |
| 419 | dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d", |
| 420 | req->wIndex); |
| 421 | } |
| 422 | out: |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 423 | usb_autopm_put_interface(desc->intf); |
| 424 | outnp: |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 425 | mutex_unlock(&desc->wlock); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 426 | outnl: |
| 427 | return rv < 0 ? rv : count; |
| 428 | } |
| 429 | |
| 430 | static ssize_t wdm_read |
| 431 | (struct file *file, char __user *buffer, size_t count, loff_t *ppos) |
| 432 | { |
Ben Hutchings | 711c68b | 2012-02-12 06:00:41 +0000 | [diff] [blame] | 433 | int rv, cntr; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 434 | int i = 0; |
| 435 | struct wdm_device *desc = file->private_data; |
| 436 | |
| 437 | |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 438 | rv = mutex_lock_interruptible(&desc->rlock); /*concurrent reads */ |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 439 | if (rv < 0) |
| 440 | return -ERESTARTSYS; |
| 441 | |
Ben Hutchings | 711c68b | 2012-02-12 06:00:41 +0000 | [diff] [blame] | 442 | cntr = ACCESS_ONCE(desc->length); |
| 443 | if (cntr == 0) { |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 444 | desc->read = 0; |
| 445 | retry: |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 446 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 447 | rv = -ENODEV; |
| 448 | goto err; |
| 449 | } |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 450 | i++; |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 451 | if (file->f_flags & O_NONBLOCK) { |
| 452 | if (!test_bit(WDM_READ, &desc->flags)) { |
| 453 | rv = cntr ? cntr : -EAGAIN; |
| 454 | goto err; |
| 455 | } |
| 456 | rv = 0; |
| 457 | } else { |
| 458 | rv = wait_event_interruptible(desc->wait, |
| 459 | test_bit(WDM_READ, &desc->flags)); |
| 460 | } |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 461 | |
Oliver Neukum | 7f1dc313d | 2009-09-09 10:12:48 +0200 | [diff] [blame] | 462 | /* may have happened while we slept */ |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 463 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 464 | rv = -ENODEV; |
| 465 | goto err; |
| 466 | } |
Bjørn Mork | 8804420 | 2012-02-10 09:44:08 +0100 | [diff] [blame] | 467 | if (test_bit(WDM_RESETTING, &desc->flags)) { |
| 468 | rv = -EIO; |
| 469 | goto err; |
| 470 | } |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 471 | usb_mark_last_busy(interface_to_usbdev(desc->intf)); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 472 | if (rv < 0) { |
| 473 | rv = -ERESTARTSYS; |
| 474 | goto err; |
| 475 | } |
| 476 | |
| 477 | spin_lock_irq(&desc->iuspin); |
| 478 | |
| 479 | if (desc->rerr) { /* read completed, error happened */ |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 480 | desc->rerr = 0; |
| 481 | spin_unlock_irq(&desc->iuspin); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 482 | rv = -EIO; |
| 483 | goto err; |
| 484 | } |
| 485 | /* |
| 486 | * recheck whether we've lost the race |
| 487 | * against the completion handler |
| 488 | */ |
| 489 | if (!test_bit(WDM_READ, &desc->flags)) { /* lost race */ |
| 490 | spin_unlock_irq(&desc->iuspin); |
| 491 | goto retry; |
| 492 | } |
| 493 | if (!desc->reslength) { /* zero length read */ |
| 494 | spin_unlock_irq(&desc->iuspin); |
| 495 | goto retry; |
| 496 | } |
Ben Hutchings | 711c68b | 2012-02-12 06:00:41 +0000 | [diff] [blame] | 497 | cntr = desc->length; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 498 | spin_unlock_irq(&desc->iuspin); |
| 499 | } |
| 500 | |
Ben Hutchings | 711c68b | 2012-02-12 06:00:41 +0000 | [diff] [blame] | 501 | if (cntr > count) |
| 502 | cntr = count; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 503 | rv = copy_to_user(buffer, desc->ubuf, cntr); |
| 504 | if (rv > 0) { |
| 505 | rv = -EFAULT; |
| 506 | goto err; |
| 507 | } |
| 508 | |
Ben Hutchings | 711c68b | 2012-02-12 06:00:41 +0000 | [diff] [blame] | 509 | spin_lock_irq(&desc->iuspin); |
| 510 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 511 | for (i = 0; i < desc->length - cntr; i++) |
| 512 | desc->ubuf[i] = desc->ubuf[i + cntr]; |
| 513 | |
| 514 | desc->length -= cntr; |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 515 | /* in case we had outstanding data */ |
| 516 | if (!desc->length) |
| 517 | clear_bit(WDM_READ, &desc->flags); |
Ben Hutchings | 711c68b | 2012-02-12 06:00:41 +0000 | [diff] [blame] | 518 | |
| 519 | spin_unlock_irq(&desc->iuspin); |
| 520 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 521 | rv = cntr; |
| 522 | |
| 523 | err: |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 524 | mutex_unlock(&desc->rlock); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 525 | return rv; |
| 526 | } |
| 527 | |
| 528 | static int wdm_flush(struct file *file, fl_owner_t id) |
| 529 | { |
| 530 | struct wdm_device *desc = file->private_data; |
| 531 | |
| 532 | wait_event(desc->wait, !test_bit(WDM_IN_USE, &desc->flags)); |
Bjørn Mork | 6b0b79d | 2012-05-09 13:53:22 +0200 | [diff] [blame] | 533 | |
| 534 | /* cannot dereference desc->intf if WDM_DISCONNECTING */ |
| 535 | if (desc->werr < 0 && !test_bit(WDM_DISCONNECTING, &desc->flags)) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 536 | dev_err(&desc->intf->dev, "Error in flush path: %d\n", |
| 537 | desc->werr); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 538 | |
Oliver Neukum | 24a85ba | 2012-04-27 14:23:54 +0200 | [diff] [blame] | 539 | return usb_translate_errors(desc->werr); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static unsigned int wdm_poll(struct file *file, struct poll_table_struct *wait) |
| 543 | { |
| 544 | struct wdm_device *desc = file->private_data; |
| 545 | unsigned long flags; |
| 546 | unsigned int mask = 0; |
| 547 | |
| 548 | spin_lock_irqsave(&desc->iuspin, flags); |
| 549 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
Bjørn Mork | 616b693 | 2012-05-09 13:53:21 +0200 | [diff] [blame] | 550 | mask = POLLHUP | POLLERR; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 551 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 552 | goto desc_out; |
| 553 | } |
| 554 | if (test_bit(WDM_READ, &desc->flags)) |
| 555 | mask = POLLIN | POLLRDNORM; |
| 556 | if (desc->rerr || desc->werr) |
| 557 | mask |= POLLERR; |
| 558 | if (!test_bit(WDM_IN_USE, &desc->flags)) |
| 559 | mask |= POLLOUT | POLLWRNORM; |
| 560 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 561 | |
| 562 | poll_wait(file, &desc->wait, wait); |
| 563 | |
| 564 | desc_out: |
| 565 | return mask; |
| 566 | } |
| 567 | |
| 568 | static int wdm_open(struct inode *inode, struct file *file) |
| 569 | { |
| 570 | int minor = iminor(inode); |
| 571 | int rv = -ENODEV; |
| 572 | struct usb_interface *intf; |
| 573 | struct wdm_device *desc; |
| 574 | |
| 575 | mutex_lock(&wdm_mutex); |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 576 | desc = wdm_find_device_by_minor(minor); |
| 577 | if (!desc) |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 578 | goto out; |
| 579 | |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 580 | intf = desc->intf; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 581 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) |
| 582 | goto out; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 583 | file->private_data = desc; |
| 584 | |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 585 | rv = usb_autopm_get_interface(desc->intf); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 586 | if (rv < 0) { |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 587 | dev_err(&desc->intf->dev, "Error autopm - %d\n", rv); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 588 | goto out; |
| 589 | } |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 590 | |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 591 | /* using write lock to protect desc->count */ |
| 592 | mutex_lock(&desc->wlock); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 593 | if (!desc->count++) { |
Oliver Neukum | d771d8a | 2011-04-29 14:12:21 +0200 | [diff] [blame] | 594 | desc->werr = 0; |
| 595 | desc->rerr = 0; |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 596 | rv = usb_submit_urb(desc->validity, GFP_KERNEL); |
| 597 | if (rv < 0) { |
| 598 | desc->count--; |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 599 | dev_err(&desc->intf->dev, |
| 600 | "Error submitting int urb - %d\n", rv); |
Oliver Neukum | 12a98b2 | 2012-04-30 09:57:31 +0200 | [diff] [blame] | 601 | rv = usb_translate_errors(rv); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 602 | } |
| 603 | } else { |
| 604 | rv = 0; |
| 605 | } |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 606 | mutex_unlock(&desc->wlock); |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 607 | if (desc->count == 1) |
| 608 | desc->manage_power(intf, 1); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 609 | usb_autopm_put_interface(desc->intf); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 610 | out: |
| 611 | mutex_unlock(&wdm_mutex); |
| 612 | return rv; |
| 613 | } |
| 614 | |
| 615 | static int wdm_release(struct inode *inode, struct file *file) |
| 616 | { |
| 617 | struct wdm_device *desc = file->private_data; |
| 618 | |
| 619 | mutex_lock(&wdm_mutex); |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 620 | |
| 621 | /* using write lock to protect desc->count */ |
| 622 | mutex_lock(&desc->wlock); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 623 | desc->count--; |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 624 | mutex_unlock(&desc->wlock); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 625 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 626 | if (!desc->count) { |
Bjørn Mork | 880bca3 | 2012-04-30 09:26:11 +0200 | [diff] [blame] | 627 | if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { |
Bjørn Mork | 6b0b79d | 2012-05-09 13:53:22 +0200 | [diff] [blame] | 628 | dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); |
| 629 | kill_urbs(desc); |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 630 | desc->manage_power(desc->intf, 0); |
Bjørn Mork | 880bca3 | 2012-04-30 09:26:11 +0200 | [diff] [blame] | 631 | } else { |
Bjørn Mork | 6b0b79d | 2012-05-09 13:53:22 +0200 | [diff] [blame] | 632 | /* must avoid dev_printk here as desc->intf is invalid */ |
| 633 | pr_debug(KBUILD_MODNAME " %s: device gone - cleaning up\n", __func__); |
Oliver Neukum | 2f338c8 | 2012-04-27 14:36:37 +0200 | [diff] [blame] | 634 | cleanup(desc); |
Bjørn Mork | 880bca3 | 2012-04-30 09:26:11 +0200 | [diff] [blame] | 635 | } |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 636 | } |
| 637 | mutex_unlock(&wdm_mutex); |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | static const struct file_operations wdm_fops = { |
| 642 | .owner = THIS_MODULE, |
| 643 | .read = wdm_read, |
| 644 | .write = wdm_write, |
| 645 | .open = wdm_open, |
| 646 | .flush = wdm_flush, |
| 647 | .release = wdm_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 648 | .poll = wdm_poll, |
| 649 | .llseek = noop_llseek, |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 650 | }; |
| 651 | |
| 652 | static struct usb_class_driver wdm_class = { |
| 653 | .name = "cdc-wdm%d", |
| 654 | .fops = &wdm_fops, |
| 655 | .minor_base = WDM_MINOR_BASE, |
| 656 | }; |
| 657 | |
| 658 | /* --- error handling --- */ |
| 659 | static void wdm_rxwork(struct work_struct *work) |
| 660 | { |
| 661 | struct wdm_device *desc = container_of(work, struct wdm_device, rxwork); |
| 662 | unsigned long flags; |
| 663 | int rv; |
| 664 | |
| 665 | spin_lock_irqsave(&desc->iuspin, flags); |
| 666 | if (test_bit(WDM_DISCONNECTING, &desc->flags)) { |
| 667 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 668 | } else { |
| 669 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 670 | rv = usb_submit_urb(desc->response, GFP_KERNEL); |
| 671 | if (rv < 0 && rv != -EPERM) { |
| 672 | spin_lock_irqsave(&desc->iuspin, flags); |
| 673 | if (!test_bit(WDM_DISCONNECTING, &desc->flags)) |
| 674 | schedule_work(&desc->rxwork); |
| 675 | spin_unlock_irqrestore(&desc->iuspin, flags); |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /* --- hotplug --- */ |
| 681 | |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 682 | static int wdm_create(struct usb_interface *intf, struct usb_endpoint_descriptor *ep, |
| 683 | u16 bufsize, int (*manage_power)(struct usb_interface *, int)) |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 684 | { |
Bjørn Mork | 0dffb48 | 2012-03-06 17:29:20 +0100 | [diff] [blame] | 685 | int rv = -ENOMEM; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 686 | struct wdm_device *desc; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 687 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 688 | desc = kzalloc(sizeof(struct wdm_device), GFP_KERNEL); |
| 689 | if (!desc) |
| 690 | goto out; |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 691 | INIT_LIST_HEAD(&desc->device_list); |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 692 | mutex_init(&desc->rlock); |
| 693 | mutex_init(&desc->wlock); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 694 | spin_lock_init(&desc->iuspin); |
| 695 | init_waitqueue_head(&desc->wait); |
Bjørn Mork | 0dffb48 | 2012-03-06 17:29:20 +0100 | [diff] [blame] | 696 | desc->wMaxCommand = bufsize; |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 697 | /* this will be expanded and needed in hardware endianness */ |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 698 | desc->inum = cpu_to_le16((u16)intf->cur_altsetting->desc.bInterfaceNumber); |
| 699 | desc->intf = intf; |
| 700 | INIT_WORK(&desc->rxwork, wdm_rxwork); |
| 701 | |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 702 | rv = -EINVAL; |
Bjørn Mork | 0dffb48 | 2012-03-06 17:29:20 +0100 | [diff] [blame] | 703 | if (!usb_endpoint_is_int_in(ep)) |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 704 | goto err; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 705 | |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 706 | desc->wMaxPacketSize = usb_endpoint_maxp(ep); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 707 | |
| 708 | desc->orq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); |
| 709 | if (!desc->orq) |
| 710 | goto err; |
| 711 | desc->irq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); |
| 712 | if (!desc->irq) |
| 713 | goto err; |
| 714 | |
| 715 | desc->validity = usb_alloc_urb(0, GFP_KERNEL); |
| 716 | if (!desc->validity) |
| 717 | goto err; |
| 718 | |
| 719 | desc->response = usb_alloc_urb(0, GFP_KERNEL); |
| 720 | if (!desc->response) |
| 721 | goto err; |
| 722 | |
| 723 | desc->command = usb_alloc_urb(0, GFP_KERNEL); |
| 724 | if (!desc->command) |
| 725 | goto err; |
| 726 | |
| 727 | desc->ubuf = kmalloc(desc->wMaxCommand, GFP_KERNEL); |
| 728 | if (!desc->ubuf) |
| 729 | goto err; |
| 730 | |
Bjørn Mork | 8457d99 | 2012-01-16 15:12:00 +0100 | [diff] [blame] | 731 | desc->sbuf = kmalloc(desc->wMaxPacketSize, GFP_KERNEL); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 732 | if (!desc->sbuf) |
| 733 | goto err; |
| 734 | |
Bjørn Mork | 8457d99 | 2012-01-16 15:12:00 +0100 | [diff] [blame] | 735 | desc->inbuf = kmalloc(desc->wMaxCommand, GFP_KERNEL); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 736 | if (!desc->inbuf) |
Bjørn Mork | 8457d99 | 2012-01-16 15:12:00 +0100 | [diff] [blame] | 737 | goto err; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 738 | |
| 739 | usb_fill_int_urb( |
| 740 | desc->validity, |
| 741 | interface_to_usbdev(intf), |
| 742 | usb_rcvintpipe(interface_to_usbdev(intf), ep->bEndpointAddress), |
| 743 | desc->sbuf, |
| 744 | desc->wMaxPacketSize, |
| 745 | wdm_int_callback, |
| 746 | desc, |
| 747 | ep->bInterval |
| 748 | ); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 749 | |
Bjørn Mork | 19b85b3 | 2012-01-16 15:11:58 +0100 | [diff] [blame] | 750 | desc->irq->bRequestType = (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE); |
| 751 | desc->irq->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE; |
| 752 | desc->irq->wValue = 0; |
| 753 | desc->irq->wIndex = desc->inum; |
| 754 | desc->irq->wLength = cpu_to_le16(desc->wMaxCommand); |
| 755 | |
| 756 | usb_fill_control_urb( |
| 757 | desc->response, |
Bjørn Mork | 8143a89 | 2012-01-16 15:12:01 +0100 | [diff] [blame] | 758 | interface_to_usbdev(intf), |
Bjørn Mork | 19b85b3 | 2012-01-16 15:11:58 +0100 | [diff] [blame] | 759 | /* using common endpoint 0 */ |
| 760 | usb_rcvctrlpipe(interface_to_usbdev(desc->intf), 0), |
| 761 | (unsigned char *)desc->irq, |
| 762 | desc->inbuf, |
| 763 | desc->wMaxCommand, |
| 764 | wdm_in_callback, |
| 765 | desc |
| 766 | ); |
Bjørn Mork | 19b85b3 | 2012-01-16 15:11:58 +0100 | [diff] [blame] | 767 | |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 768 | desc->manage_power = manage_power; |
| 769 | |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 770 | spin_lock(&wdm_device_list_lock); |
| 771 | list_add(&desc->device_list, &wdm_device_list); |
| 772 | spin_unlock(&wdm_device_list_lock); |
| 773 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 774 | rv = usb_register_dev(intf, &wdm_class); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 775 | if (rv < 0) |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 776 | goto err; |
Oliver Neukum | 052fbc0 | 2009-04-20 17:24:49 +0200 | [diff] [blame] | 777 | else |
Bjørn Mork | 820c629 | 2012-01-20 04:17:25 +0100 | [diff] [blame] | 778 | dev_info(&intf->dev, "%s: USB WDM device\n", dev_name(intf->usb_dev)); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 779 | out: |
| 780 | return rv; |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 781 | err: |
Bjørn Mork | 6286d85 | 2012-05-09 13:53:23 +0200 | [diff] [blame] | 782 | spin_lock(&wdm_device_list_lock); |
| 783 | list_del(&desc->device_list); |
| 784 | spin_unlock(&wdm_device_list_lock); |
Bjørn Mork | 0dffb48 | 2012-03-06 17:29:20 +0100 | [diff] [blame] | 785 | cleanup(desc); |
| 786 | return rv; |
| 787 | } |
| 788 | |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 789 | static int wdm_manage_power(struct usb_interface *intf, int on) |
| 790 | { |
| 791 | /* need autopm_get/put here to ensure the usbcore sees the new value */ |
| 792 | int rv = usb_autopm_get_interface(intf); |
| 793 | if (rv < 0) |
| 794 | goto err; |
| 795 | |
| 796 | intf->needs_remote_wakeup = on; |
| 797 | usb_autopm_put_interface(intf); |
| 798 | err: |
| 799 | return rv; |
| 800 | } |
| 801 | |
Bjørn Mork | 0dffb48 | 2012-03-06 17:29:20 +0100 | [diff] [blame] | 802 | static int wdm_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 803 | { |
| 804 | int rv = -EINVAL; |
| 805 | struct usb_host_interface *iface; |
| 806 | struct usb_endpoint_descriptor *ep; |
| 807 | struct usb_cdc_dmm_desc *dmhd; |
| 808 | u8 *buffer = intf->altsetting->extra; |
| 809 | int buflen = intf->altsetting->extralen; |
| 810 | u16 maxcom = WDM_DEFAULT_BUFSIZE; |
| 811 | |
| 812 | if (!buffer) |
| 813 | goto err; |
| 814 | while (buflen > 2) { |
| 815 | if (buffer[1] != USB_DT_CS_INTERFACE) { |
| 816 | dev_err(&intf->dev, "skipping garbage\n"); |
| 817 | goto next_desc; |
| 818 | } |
| 819 | |
| 820 | switch (buffer[2]) { |
| 821 | case USB_CDC_HEADER_TYPE: |
| 822 | break; |
| 823 | case USB_CDC_DMM_TYPE: |
| 824 | dmhd = (struct usb_cdc_dmm_desc *)buffer; |
| 825 | maxcom = le16_to_cpu(dmhd->wMaxCommand); |
| 826 | dev_dbg(&intf->dev, |
| 827 | "Finding maximum buffer length: %d", maxcom); |
| 828 | break; |
| 829 | default: |
| 830 | dev_err(&intf->dev, |
| 831 | "Ignoring extra header, type %d, length %d\n", |
| 832 | buffer[2], buffer[0]); |
| 833 | break; |
| 834 | } |
| 835 | next_desc: |
| 836 | buflen -= buffer[0]; |
| 837 | buffer += buffer[0]; |
| 838 | } |
| 839 | |
| 840 | iface = intf->cur_altsetting; |
| 841 | if (iface->desc.bNumEndpoints != 1) |
| 842 | goto err; |
| 843 | ep = &iface->endpoint[0].desc; |
| 844 | |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 845 | rv = wdm_create(intf, ep, maxcom, &wdm_manage_power); |
Bjørn Mork | 0dffb48 | 2012-03-06 17:29:20 +0100 | [diff] [blame] | 846 | |
| 847 | err: |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 848 | return rv; |
| 849 | } |
| 850 | |
Bjørn Mork | 3cc3615 | 2012-03-06 17:29:22 +0100 | [diff] [blame] | 851 | /** |
| 852 | * usb_cdc_wdm_register - register a WDM subdriver |
| 853 | * @intf: usb interface the subdriver will associate with |
| 854 | * @ep: interrupt endpoint to monitor for notifications |
| 855 | * @bufsize: maximum message size to support for read/write |
| 856 | * |
| 857 | * Create WDM usb class character device and associate it with intf |
| 858 | * without binding, allowing another driver to manage the interface. |
| 859 | * |
| 860 | * The subdriver will manage the given interrupt endpoint exclusively |
| 861 | * and will issue control requests referring to the given intf. It |
| 862 | * will otherwise avoid interferring, and in particular not do |
| 863 | * usb_set_intfdata/usb_get_intfdata on intf. |
| 864 | * |
| 865 | * The return value is a pointer to the subdriver's struct usb_driver. |
| 866 | * The registering driver is responsible for calling this subdriver's |
| 867 | * disconnect, suspend, resume, pre_reset and post_reset methods from |
| 868 | * its own. |
| 869 | */ |
| 870 | struct usb_driver *usb_cdc_wdm_register(struct usb_interface *intf, |
| 871 | struct usb_endpoint_descriptor *ep, |
| 872 | int bufsize, |
| 873 | int (*manage_power)(struct usb_interface *, int)) |
| 874 | { |
| 875 | int rv = -EINVAL; |
| 876 | |
| 877 | rv = wdm_create(intf, ep, bufsize, manage_power); |
| 878 | if (rv < 0) |
| 879 | goto err; |
| 880 | |
| 881 | return &wdm_driver; |
| 882 | err: |
| 883 | return ERR_PTR(rv); |
| 884 | } |
| 885 | EXPORT_SYMBOL(usb_cdc_wdm_register); |
| 886 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 887 | static void wdm_disconnect(struct usb_interface *intf) |
| 888 | { |
| 889 | struct wdm_device *desc; |
| 890 | unsigned long flags; |
| 891 | |
| 892 | usb_deregister_dev(intf, &wdm_class); |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 893 | desc = wdm_find_device(intf); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 894 | mutex_lock(&wdm_mutex); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 895 | |
| 896 | /* the spinlock makes sure no new urbs are generated in the callbacks */ |
| 897 | spin_lock_irqsave(&desc->iuspin, flags); |
| 898 | set_bit(WDM_DISCONNECTING, &desc->flags); |
| 899 | set_bit(WDM_READ, &desc->flags); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 900 | /* to terminate pending flushes */ |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 901 | clear_bit(WDM_IN_USE, &desc->flags); |
| 902 | spin_unlock_irqrestore(&desc->iuspin, flags); |
Bjørn Mork | 62aaf24 | 2012-01-16 15:11:57 +0100 | [diff] [blame] | 903 | wake_up_all(&desc->wait); |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 904 | mutex_lock(&desc->rlock); |
| 905 | mutex_lock(&desc->wlock); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 906 | kill_urbs(desc); |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 907 | cancel_work_sync(&desc->rxwork); |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 908 | mutex_unlock(&desc->wlock); |
| 909 | mutex_unlock(&desc->rlock); |
Bjørn Mork | 6286d85 | 2012-05-09 13:53:23 +0200 | [diff] [blame] | 910 | |
| 911 | /* the desc->intf pointer used as list key is now invalid */ |
| 912 | spin_lock(&wdm_device_list_lock); |
| 913 | list_del(&desc->device_list); |
| 914 | spin_unlock(&wdm_device_list_lock); |
| 915 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 916 | if (!desc->count) |
| 917 | cleanup(desc); |
Bjørn Mork | 880bca3 | 2012-04-30 09:26:11 +0200 | [diff] [blame] | 918 | else |
| 919 | dev_dbg(&intf->dev, "%s: %d open files - postponing cleanup\n", __func__, desc->count); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 920 | mutex_unlock(&wdm_mutex); |
| 921 | } |
| 922 | |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 923 | #ifdef CONFIG_PM |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 924 | static int wdm_suspend(struct usb_interface *intf, pm_message_t message) |
| 925 | { |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 926 | struct wdm_device *desc = wdm_find_device(intf); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 927 | int rv = 0; |
| 928 | |
| 929 | dev_dbg(&desc->intf->dev, "wdm%d_suspend\n", intf->minor); |
| 930 | |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 931 | /* if this is an autosuspend the caller does the locking */ |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 932 | if (!PMSG_IS_AUTO(message)) { |
| 933 | mutex_lock(&desc->rlock); |
| 934 | mutex_lock(&desc->wlock); |
| 935 | } |
Oliver Neukum | 62e6685 | 2010-02-27 20:56:22 +0100 | [diff] [blame] | 936 | spin_lock_irq(&desc->iuspin); |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 937 | |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 938 | if (PMSG_IS_AUTO(message) && |
Oliver Neukum | 922a5ea | 2010-02-27 20:54:59 +0100 | [diff] [blame] | 939 | (test_bit(WDM_IN_USE, &desc->flags) |
| 940 | || test_bit(WDM_RESPONDING, &desc->flags))) { |
Oliver Neukum | 62e6685 | 2010-02-27 20:56:22 +0100 | [diff] [blame] | 941 | spin_unlock_irq(&desc->iuspin); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 942 | rv = -EBUSY; |
| 943 | } else { |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 944 | |
Oliver Neukum | beb1d35 | 2010-02-27 20:55:52 +0100 | [diff] [blame] | 945 | set_bit(WDM_SUSPENDING, &desc->flags); |
Oliver Neukum | 62e6685 | 2010-02-27 20:56:22 +0100 | [diff] [blame] | 946 | spin_unlock_irq(&desc->iuspin); |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 947 | /* callback submits work - order is essential */ |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 948 | kill_urbs(desc); |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 949 | cancel_work_sync(&desc->rxwork); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 950 | } |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 951 | if (!PMSG_IS_AUTO(message)) { |
| 952 | mutex_unlock(&desc->wlock); |
| 953 | mutex_unlock(&desc->rlock); |
| 954 | } |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 955 | |
| 956 | return rv; |
| 957 | } |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 958 | #endif |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 959 | |
| 960 | static int recover_from_urb_loss(struct wdm_device *desc) |
| 961 | { |
| 962 | int rv = 0; |
| 963 | |
| 964 | if (desc->count) { |
| 965 | rv = usb_submit_urb(desc->validity, GFP_NOIO); |
| 966 | if (rv < 0) |
Greg Kroah-Hartman | 9908a32 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 967 | dev_err(&desc->intf->dev, |
| 968 | "Error resume submitting int urb - %d\n", rv); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 969 | } |
| 970 | return rv; |
| 971 | } |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 972 | |
| 973 | #ifdef CONFIG_PM |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 974 | static int wdm_resume(struct usb_interface *intf) |
| 975 | { |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 976 | struct wdm_device *desc = wdm_find_device(intf); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 977 | int rv; |
| 978 | |
| 979 | dev_dbg(&desc->intf->dev, "wdm%d_resume\n", intf->minor); |
Oliver Neukum | 338124c | 2010-02-27 20:57:12 +0100 | [diff] [blame] | 980 | |
Oliver Neukum | beb1d35 | 2010-02-27 20:55:52 +0100 | [diff] [blame] | 981 | clear_bit(WDM_SUSPENDING, &desc->flags); |
Oliver Neukum | 62e6685 | 2010-02-27 20:56:22 +0100 | [diff] [blame] | 982 | rv = recover_from_urb_loss(desc); |
Oliver Neukum | 338124c | 2010-02-27 20:57:12 +0100 | [diff] [blame] | 983 | |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 984 | return rv; |
| 985 | } |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 986 | #endif |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 987 | |
| 988 | static int wdm_pre_reset(struct usb_interface *intf) |
| 989 | { |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 990 | struct wdm_device *desc = wdm_find_device(intf); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 991 | |
Oliver Neukum | d771d8a | 2011-04-29 14:12:21 +0200 | [diff] [blame] | 992 | /* |
| 993 | * we notify everybody using poll of |
| 994 | * an exceptional situation |
| 995 | * must be done before recovery lest a spontaneous |
| 996 | * message from the device is lost |
| 997 | */ |
| 998 | spin_lock_irq(&desc->iuspin); |
Bjørn Mork | 8804420 | 2012-02-10 09:44:08 +0100 | [diff] [blame] | 999 | set_bit(WDM_RESETTING, &desc->flags); /* inform read/write */ |
| 1000 | set_bit(WDM_READ, &desc->flags); /* unblock read */ |
| 1001 | clear_bit(WDM_IN_USE, &desc->flags); /* unblock write */ |
Oliver Neukum | d771d8a | 2011-04-29 14:12:21 +0200 | [diff] [blame] | 1002 | desc->rerr = -EINTR; |
| 1003 | spin_unlock_irq(&desc->iuspin); |
| 1004 | wake_up_all(&desc->wait); |
Bjørn Mork | 8804420 | 2012-02-10 09:44:08 +0100 | [diff] [blame] | 1005 | mutex_lock(&desc->rlock); |
| 1006 | mutex_lock(&desc->wlock); |
| 1007 | kill_urbs(desc); |
| 1008 | cancel_work_sync(&desc->rxwork); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static int wdm_post_reset(struct usb_interface *intf) |
| 1013 | { |
Bjørn Mork | b0c1386 | 2012-03-06 17:29:21 +0100 | [diff] [blame] | 1014 | struct wdm_device *desc = wdm_find_device(intf); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 1015 | int rv; |
| 1016 | |
Bjørn Mork | 8804420 | 2012-02-10 09:44:08 +0100 | [diff] [blame] | 1017 | clear_bit(WDM_RESETTING, &desc->flags); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 1018 | rv = recover_from_urb_loss(desc); |
Bjørn Mork | e8537bd | 2012-01-16 12:41:48 +0100 | [diff] [blame] | 1019 | mutex_unlock(&desc->wlock); |
| 1020 | mutex_unlock(&desc->rlock); |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 1021 | return 0; |
| 1022 | } |
| 1023 | |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 1024 | static struct usb_driver wdm_driver = { |
| 1025 | .name = "cdc_wdm", |
| 1026 | .probe = wdm_probe, |
| 1027 | .disconnect = wdm_disconnect, |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 1028 | #ifdef CONFIG_PM |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 1029 | .suspend = wdm_suspend, |
| 1030 | .resume = wdm_resume, |
| 1031 | .reset_resume = wdm_resume, |
Oliver Neukum | d93d16e | 2010-02-27 20:56:47 +0100 | [diff] [blame] | 1032 | #endif |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 1033 | .pre_reset = wdm_pre_reset, |
| 1034 | .post_reset = wdm_post_reset, |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 1035 | .id_table = wdm_ids, |
Oliver Neukum | 17d80d5 | 2008-06-24 15:56:10 +0200 | [diff] [blame] | 1036 | .supports_autosuspend = 1, |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 1037 | }; |
| 1038 | |
Greg Kroah-Hartman | 65db430 | 2011-11-18 09:34:02 -0800 | [diff] [blame] | 1039 | module_usb_driver(wdm_driver); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 1040 | |
| 1041 | MODULE_AUTHOR(DRIVER_AUTHOR); |
Oliver Neukum | 87d65e5 | 2008-06-19 14:20:18 +0200 | [diff] [blame] | 1042 | MODULE_DESCRIPTION(DRIVER_DESC); |
Oliver Neukum | afba937 | 2008-05-13 17:01:25 +0200 | [diff] [blame] | 1043 | MODULE_LICENSE("GPL"); |