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