Merge tag 'perf-urgent-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / drivers / usb / serial / usb_wwan.c
CommitLineData
0d456194
MG
1/*
2 USB Driver layer for GSM modems
3
4 Copyright (C) 2005 Matthias Urlichs <smurf@smurf.noris.de>
5
6 This driver is free software; you can redistribute it and/or modify
7 it under the terms of Version 2 of the GNU General Public License as
8 published by the Free Software Foundation.
9
10 Portions copied from the Keyspan driver by Hugh Blemings <hugh@blemings.org>
11
12 History: see the git log.
13
14 Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
15
16 This driver exists because the "normal" serial driver doesn't work too well
17 with GSM modems. Issues:
18 - data loss -- one single Receive URB is not nearly enough
19 - controlling the baud rate doesn't make sense
20*/
21
22#define DRIVER_VERSION "v0.7.2"
23#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
24#define DRIVER_DESC "USB Driver for GSM modems"
25
26#include <linux/kernel.h>
27#include <linux/jiffies.h>
28#include <linux/errno.h>
29#include <linux/slab.h>
30#include <linux/tty.h>
31#include <linux/tty_flip.h>
32#include <linux/module.h>
33#include <linux/bitops.h>
66921edd 34#include <linux/uaccess.h>
0d456194
MG
35#include <linux/usb.h>
36#include <linux/usb/serial.h>
02303f73 37#include <linux/serial.h>
0d456194
MG
38#include "usb-wwan.h"
39
0d456194
MG
40void usb_wwan_dtr_rts(struct usb_serial_port *port, int on)
41{
42 struct usb_serial *serial = port->serial;
43 struct usb_wwan_port_private *portdata;
0d456194
MG
44 struct usb_wwan_intf_private *intfdata;
45
0d456194
MG
46 intfdata = port->serial->private;
47
48 if (!intfdata->send_setup)
49 return;
50
51 portdata = usb_get_serial_port_data(port);
52 mutex_lock(&serial->disc_mutex);
53 portdata->rts_state = on;
54 portdata->dtr_state = on;
55 if (serial->dev)
56 intfdata->send_setup(port);
57 mutex_unlock(&serial->disc_mutex);
58}
59EXPORT_SYMBOL(usb_wwan_dtr_rts);
60
61void usb_wwan_set_termios(struct tty_struct *tty,
62 struct usb_serial_port *port,
63 struct ktermios *old_termios)
64{
65 struct usb_wwan_intf_private *intfdata = port->serial->private;
66
0d456194 67 /* Doesn't support option setting */
adc8d746 68 tty_termios_copy_hw(&tty->termios, old_termios);
0d456194
MG
69
70 if (intfdata->send_setup)
71 intfdata->send_setup(port);
72}
73EXPORT_SYMBOL(usb_wwan_set_termios);
74
60b33c13 75int usb_wwan_tiocmget(struct tty_struct *tty)
0d456194
MG
76{
77 struct usb_serial_port *port = tty->driver_data;
78 unsigned int value;
79 struct usb_wwan_port_private *portdata;
80
81 portdata = usb_get_serial_port_data(port);
82
83 value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
84 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
85 ((portdata->cts_state) ? TIOCM_CTS : 0) |
86 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
87 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
88 ((portdata->ri_state) ? TIOCM_RNG : 0);
89
90 return value;
91}
92EXPORT_SYMBOL(usb_wwan_tiocmget);
93
20b9d177 94int usb_wwan_tiocmset(struct tty_struct *tty,
0d456194
MG
95 unsigned int set, unsigned int clear)
96{
97 struct usb_serial_port *port = tty->driver_data;
98 struct usb_wwan_port_private *portdata;
99 struct usb_wwan_intf_private *intfdata;
100
101 portdata = usb_get_serial_port_data(port);
102 intfdata = port->serial->private;
103
104 if (!intfdata->send_setup)
105 return -EINVAL;
106
107 /* FIXME: what locks portdata fields ? */
108 if (set & TIOCM_RTS)
109 portdata->rts_state = 1;
110 if (set & TIOCM_DTR)
111 portdata->dtr_state = 1;
112
113 if (clear & TIOCM_RTS)
114 portdata->rts_state = 0;
115 if (clear & TIOCM_DTR)
116 portdata->dtr_state = 0;
117 return intfdata->send_setup(port);
118}
119EXPORT_SYMBOL(usb_wwan_tiocmset);
120
02303f73
DW
121static int get_serial_info(struct usb_serial_port *port,
122 struct serial_struct __user *retinfo)
123{
124 struct serial_struct tmp;
125
126 if (!retinfo)
127 return -EFAULT;
128
129 memset(&tmp, 0, sizeof(tmp));
130 tmp.line = port->serial->minor;
131 tmp.port = port->number;
132 tmp.baud_base = tty_get_baud_rate(port->port.tty);
133 tmp.close_delay = port->port.close_delay / 10;
134 tmp.closing_wait = port->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
135 ASYNC_CLOSING_WAIT_NONE :
136 port->port.closing_wait / 10;
137
138 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
139 return -EFAULT;
140 return 0;
141}
142
143static int set_serial_info(struct usb_serial_port *port,
144 struct serial_struct __user *newinfo)
145{
146 struct serial_struct new_serial;
147 unsigned int closing_wait, close_delay;
148 int retval = 0;
149
150 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
151 return -EFAULT;
152
153 close_delay = new_serial.close_delay * 10;
154 closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
155 ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
156
157 mutex_lock(&port->port.mutex);
158
159 if (!capable(CAP_SYS_ADMIN)) {
160 if ((close_delay != port->port.close_delay) ||
161 (closing_wait != port->port.closing_wait))
162 retval = -EPERM;
163 else
164 retval = -EOPNOTSUPP;
165 } else {
166 port->port.close_delay = close_delay;
167 port->port.closing_wait = closing_wait;
168 }
169
170 mutex_unlock(&port->port.mutex);
171 return retval;
172}
173
00a0d0d6 174int usb_wwan_ioctl(struct tty_struct *tty,
02303f73
DW
175 unsigned int cmd, unsigned long arg)
176{
177 struct usb_serial_port *port = tty->driver_data;
178
a80be97d 179 dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd);
02303f73
DW
180
181 switch (cmd) {
182 case TIOCGSERIAL:
183 return get_serial_info(port,
184 (struct serial_struct __user *) arg);
185 case TIOCSSERIAL:
186 return set_serial_info(port,
187 (struct serial_struct __user *) arg);
188 default:
189 break;
190 }
191
a80be97d 192 dev_dbg(&port->dev, "%s arg not supported\n", __func__);
02303f73
DW
193
194 return -ENOIOCTLCMD;
195}
196EXPORT_SYMBOL(usb_wwan_ioctl);
197
0d456194
MG
198/* Write */
199int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
200 const unsigned char *buf, int count)
201{
202 struct usb_wwan_port_private *portdata;
203 struct usb_wwan_intf_private *intfdata;
204 int i;
205 int left, todo;
206 struct urb *this_urb = NULL; /* spurious */
207 int err;
208 unsigned long flags;
209
210 portdata = usb_get_serial_port_data(port);
211 intfdata = port->serial->private;
212
a80be97d 213 dev_dbg(&port->dev, "%s: write (%d chars)\n", __func__, count);
0d456194
MG
214
215 i = 0;
216 left = count;
217 for (i = 0; left > 0 && i < N_OUT_URB; i++) {
218 todo = left;
219 if (todo > OUT_BUFLEN)
220 todo = OUT_BUFLEN;
221
222 this_urb = portdata->out_urbs[i];
223 if (test_and_set_bit(i, &portdata->out_busy)) {
224 if (time_before(jiffies,
225 portdata->tx_start_time[i] + 10 * HZ))
226 continue;
227 usb_unlink_urb(this_urb);
228 continue;
229 }
a80be97d
GKH
230 dev_dbg(&port->dev, "%s: endpoint %d buf %d\n", __func__,
231 usb_pipeendpoint(this_urb->pipe), i);
0d456194
MG
232
233 err = usb_autopm_get_interface_async(port->serial->interface);
234 if (err < 0)
235 break;
236
237 /* send the data */
238 memcpy(this_urb->transfer_buffer, buf, todo);
239 this_urb->transfer_buffer_length = todo;
240
241 spin_lock_irqsave(&intfdata->susp_lock, flags);
242 if (intfdata->suspended) {
243 usb_anchor_urb(this_urb, &portdata->delayed);
244 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
245 } else {
246 intfdata->in_flight++;
247 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
248 err = usb_submit_urb(this_urb, GFP_ATOMIC);
249 if (err) {
a80be97d
GKH
250 dev_dbg(&port->dev,
251 "usb_submit_urb %p (write bulk) failed (%d)\n",
252 this_urb, err);
0d456194
MG
253 clear_bit(i, &portdata->out_busy);
254 spin_lock_irqsave(&intfdata->susp_lock, flags);
255 intfdata->in_flight--;
256 spin_unlock_irqrestore(&intfdata->susp_lock,
257 flags);
3d06bf15 258 usb_autopm_put_interface_async(port->serial->interface);
433508ae 259 break;
0d456194
MG
260 }
261 }
262
263 portdata->tx_start_time[i] = jiffies;
264 buf += todo;
265 left -= todo;
266 }
267
268 count -= left;
a80be97d 269 dev_dbg(&port->dev, "%s: wrote (did %d)\n", __func__, count);
0d456194
MG
270 return count;
271}
272EXPORT_SYMBOL(usb_wwan_write);
273
274static void usb_wwan_indat_callback(struct urb *urb)
275{
276 int err;
277 int endpoint;
278 struct usb_serial_port *port;
279 struct tty_struct *tty;
a80be97d 280 struct device *dev;
0d456194
MG
281 unsigned char *data = urb->transfer_buffer;
282 int status = urb->status;
283
0d456194
MG
284 endpoint = usb_pipeendpoint(urb->pipe);
285 port = urb->context;
a80be97d 286 dev = &port->dev;
0d456194
MG
287
288 if (status) {
a80be97d
GKH
289 dev_dbg(dev, "%s: nonzero status: %d on endpoint %02x.\n",
290 __func__, status, endpoint);
0d456194
MG
291 } else {
292 tty = tty_port_tty_get(&port->port);
38237fd2
JS
293 if (tty) {
294 if (urb->actual_length) {
295 tty_insert_flip_string(tty, data,
296 urb->actual_length);
297 tty_flip_buffer_push(tty);
298 } else
a80be97d 299 dev_dbg(dev, "%s: empty read urb received\n", __func__);
38237fd2
JS
300 tty_kref_put(tty);
301 }
0d456194
MG
302
303 /* Resubmit urb so we continue receiving */
ec42899c
DC
304 err = usb_submit_urb(urb, GFP_ATOMIC);
305 if (err) {
306 if (err != -EPERM) {
a80be97d 307 dev_err(dev, "%s: resubmit read urb failed. (%d)\n", __func__, err);
ec42899c 308 /* busy also in error unless we are killed */
0d456194 309 usb_mark_last_busy(port->serial->dev);
c9c4558f 310 }
ec42899c
DC
311 } else {
312 usb_mark_last_busy(port->serial->dev);
0d456194 313 }
0d456194 314 }
0d456194
MG
315}
316
317static void usb_wwan_outdat_callback(struct urb *urb)
318{
319 struct usb_serial_port *port;
320 struct usb_wwan_port_private *portdata;
321 struct usb_wwan_intf_private *intfdata;
322 int i;
323
0d456194
MG
324 port = urb->context;
325 intfdata = port->serial->private;
326
327 usb_serial_port_softint(port);
328 usb_autopm_put_interface_async(port->serial->interface);
329 portdata = usb_get_serial_port_data(port);
330 spin_lock(&intfdata->susp_lock);
331 intfdata->in_flight--;
332 spin_unlock(&intfdata->susp_lock);
333
334 for (i = 0; i < N_OUT_URB; ++i) {
335 if (portdata->out_urbs[i] == urb) {
336 smp_mb__before_clear_bit();
337 clear_bit(i, &portdata->out_busy);
338 break;
339 }
340 }
341}
342
343int usb_wwan_write_room(struct tty_struct *tty)
344{
345 struct usb_serial_port *port = tty->driver_data;
346 struct usb_wwan_port_private *portdata;
347 int i;
348 int data_len = 0;
349 struct urb *this_urb;
350
351 portdata = usb_get_serial_port_data(port);
352
353 for (i = 0; i < N_OUT_URB; i++) {
354 this_urb = portdata->out_urbs[i];
355 if (this_urb && !test_bit(i, &portdata->out_busy))
356 data_len += OUT_BUFLEN;
357 }
358
a80be97d 359 dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
0d456194
MG
360 return data_len;
361}
362EXPORT_SYMBOL(usb_wwan_write_room);
363
364int usb_wwan_chars_in_buffer(struct tty_struct *tty)
365{
366 struct usb_serial_port *port = tty->driver_data;
367 struct usb_wwan_port_private *portdata;
368 int i;
369 int data_len = 0;
370 struct urb *this_urb;
371
372 portdata = usb_get_serial_port_data(port);
373
374 for (i = 0; i < N_OUT_URB; i++) {
375 this_urb = portdata->out_urbs[i];
376 /* FIXME: This locking is insufficient as this_urb may
377 go unused during the test */
378 if (this_urb && test_bit(i, &portdata->out_busy))
379 data_len += this_urb->transfer_buffer_length;
380 }
a80be97d 381 dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
0d456194
MG
382 return data_len;
383}
384EXPORT_SYMBOL(usb_wwan_chars_in_buffer);
385
386int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
387{
388 struct usb_wwan_port_private *portdata;
389 struct usb_wwan_intf_private *intfdata;
390 struct usb_serial *serial = port->serial;
391 int i, err;
392 struct urb *urb;
393
394 portdata = usb_get_serial_port_data(port);
395 intfdata = serial->private;
396
0d456194
MG
397 /* Start reading from the IN endpoint */
398 for (i = 0; i < N_IN_URB; i++) {
399 urb = portdata->in_urbs[i];
400 if (!urb)
401 continue;
402 err = usb_submit_urb(urb, GFP_KERNEL);
403 if (err) {
a80be97d
GKH
404 dev_dbg(&port->dev, "%s: submit urb %d failed (%d) %d\n",
405 __func__, i, err, urb->transfer_buffer_length);
0d456194
MG
406 }
407 }
408
409 if (intfdata->send_setup)
410 intfdata->send_setup(port);
411
412 serial->interface->needs_remote_wakeup = 1;
413 spin_lock_irq(&intfdata->susp_lock);
414 portdata->opened = 1;
415 spin_unlock_irq(&intfdata->susp_lock);
9a91aedc 416 /* this balances a get in the generic USB serial code */
0d456194
MG
417 usb_autopm_put_interface(serial->interface);
418
419 return 0;
420}
421EXPORT_SYMBOL(usb_wwan_open);
422
423void usb_wwan_close(struct usb_serial_port *port)
424{
425 int i;
426 struct usb_serial *serial = port->serial;
427 struct usb_wwan_port_private *portdata;
428 struct usb_wwan_intf_private *intfdata = port->serial->private;
429
0d456194
MG
430 portdata = usb_get_serial_port_data(port);
431
432 if (serial->dev) {
433 /* Stop reading/writing urbs */
434 spin_lock_irq(&intfdata->susp_lock);
435 portdata->opened = 0;
436 spin_unlock_irq(&intfdata->susp_lock);
437
438 for (i = 0; i < N_IN_URB; i++)
439 usb_kill_urb(portdata->in_urbs[i]);
440 for (i = 0; i < N_OUT_URB; i++)
441 usb_kill_urb(portdata->out_urbs[i]);
9a91aedc
ON
442 /* balancing - important as an error cannot be handled*/
443 usb_autopm_get_interface_no_resume(serial->interface);
0d456194
MG
444 serial->interface->needs_remote_wakeup = 0;
445 }
446}
447EXPORT_SYMBOL(usb_wwan_close);
448
449/* Helper functions used by usb_wwan_setup_urbs */
450static struct urb *usb_wwan_setup_urb(struct usb_serial *serial, int endpoint,
451 int dir, void *ctx, char *buf, int len,
452 void (*callback) (struct urb *))
453{
454 struct urb *urb;
455
456 if (endpoint == -1)
457 return NULL; /* endpoint not needed */
458
459 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
460 if (urb == NULL) {
a80be97d
GKH
461 dev_dbg(&serial->interface->dev,
462 "%s: alloc for endpoint %d failed.\n", __func__,
463 endpoint);
0d456194
MG
464 return NULL;
465 }
466
467 /* Fill URB using supplied data. */
468 usb_fill_bulk_urb(urb, serial->dev,
469 usb_sndbulkpipe(serial->dev, endpoint) | dir,
470 buf, len, callback, ctx);
471
472 return urb;
473}
474
475/* Setup urbs */
476static void usb_wwan_setup_urbs(struct usb_serial *serial)
477{
478 int i, j;
479 struct usb_serial_port *port;
480 struct usb_wwan_port_private *portdata;
481
0d456194
MG
482 for (i = 0; i < serial->num_ports; i++) {
483 port = serial->port[i];
484 portdata = usb_get_serial_port_data(port);
485
486 /* Do indat endpoints first */
487 for (j = 0; j < N_IN_URB; ++j) {
488 portdata->in_urbs[j] = usb_wwan_setup_urb(serial,
489 port->
490 bulk_in_endpointAddress,
491 USB_DIR_IN,
492 port,
493 portdata->
494 in_buffer[j],
495 IN_BUFLEN,
496 usb_wwan_indat_callback);
497 }
498
499 /* outdat endpoints */
500 for (j = 0; j < N_OUT_URB; ++j) {
501 portdata->out_urbs[j] = usb_wwan_setup_urb(serial,
502 port->
503 bulk_out_endpointAddress,
504 USB_DIR_OUT,
505 port,
506 portdata->
507 out_buffer
508 [j],
509 OUT_BUFLEN,
510 usb_wwan_outdat_callback);
511 }
512 }
513}
514
515int usb_wwan_startup(struct usb_serial *serial)
516{
517 int i, j, err;
518 struct usb_serial_port *port;
519 struct usb_wwan_port_private *portdata;
520 u8 *buffer;
521
0d456194
MG
522 /* Now setup per port private data */
523 for (i = 0; i < serial->num_ports; i++) {
524 port = serial->port[i];
525 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
526 if (!portdata) {
a80be97d
GKH
527 dev_dbg(&port->dev, "%s: kmalloc for usb_wwan_port_private (%d) failed!.\n",
528 __func__, i);
0d456194
MG
529 return 1;
530 }
531 init_usb_anchor(&portdata->delayed);
532
533 for (j = 0; j < N_IN_URB; j++) {
534 buffer = (u8 *) __get_free_page(GFP_KERNEL);
535 if (!buffer)
536 goto bail_out_error;
537 portdata->in_buffer[j] = buffer;
538 }
539
540 for (j = 0; j < N_OUT_URB; j++) {
541 buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL);
542 if (!buffer)
543 goto bail_out_error2;
544 portdata->out_buffer[j] = buffer;
545 }
546
547 usb_set_serial_port_data(port, portdata);
548
549 if (!port->interrupt_in_urb)
550 continue;
551 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
552 if (err)
a80be97d
GKH
553 dev_dbg(&port->dev, "%s: submit irq_in urb failed %d\n",
554 __func__, err);
0d456194
MG
555 }
556 usb_wwan_setup_urbs(serial);
557 return 0;
558
559bail_out_error2:
560 for (j = 0; j < N_OUT_URB; j++)
561 kfree(portdata->out_buffer[j]);
562bail_out_error:
563 for (j = 0; j < N_IN_URB; j++)
564 if (portdata->in_buffer[j])
565 free_page((unsigned long)portdata->in_buffer[j]);
566 kfree(portdata);
567 return 1;
568}
569EXPORT_SYMBOL(usb_wwan_startup);
570
a1028f0a 571int usb_wwan_port_remove(struct usb_serial_port *port)
0d456194 572{
a1028f0a 573 int i;
0d456194
MG
574 struct usb_wwan_port_private *portdata;
575
a1028f0a
BM
576 portdata = usb_get_serial_port_data(port);
577 usb_set_serial_port_data(port, NULL);
578
579 /* Stop reading/writing urbs and free them */
580 for (i = 0; i < N_IN_URB; i++) {
581 usb_kill_urb(portdata->in_urbs[i]);
582 usb_free_urb(portdata->in_urbs[i]);
583 free_page((unsigned long)portdata->in_buffer[i]);
584 }
585 for (i = 0; i < N_OUT_URB; i++) {
586 usb_kill_urb(portdata->out_urbs[i]);
587 usb_free_urb(portdata->out_urbs[i]);
588 kfree(portdata->out_buffer[i]);
0d456194 589 }
0d456194 590
a1028f0a
BM
591 /* Now free port private data */
592 kfree(portdata);
593 return 0;
0d456194 594}
a1028f0a 595EXPORT_SYMBOL(usb_wwan_port_remove);
0d456194 596
a1028f0a
BM
597#ifdef CONFIG_PM
598static void stop_read_write_urbs(struct usb_serial *serial)
0d456194
MG
599{
600 int i, j;
601 struct usb_serial_port *port;
602 struct usb_wwan_port_private *portdata;
603
a1028f0a 604 /* Stop reading/writing urbs */
0d456194
MG
605 for (i = 0; i < serial->num_ports; ++i) {
606 port = serial->port[i];
607 portdata = usb_get_serial_port_data(port);
032129cb
BM
608 if (!portdata)
609 continue;
a1028f0a
BM
610 for (j = 0; j < N_IN_URB; j++)
611 usb_kill_urb(portdata->in_urbs[j]);
612 for (j = 0; j < N_OUT_URB; j++)
613 usb_kill_urb(portdata->out_urbs[j]);
0d456194
MG
614 }
615}
0d456194 616
0d456194
MG
617int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
618{
619 struct usb_wwan_intf_private *intfdata = serial->private;
620 int b;
621
5b1b0b81 622 if (PMSG_IS_AUTO(message)) {
0d456194
MG
623 spin_lock_irq(&intfdata->susp_lock);
624 b = intfdata->in_flight;
625 spin_unlock_irq(&intfdata->susp_lock);
626
627 if (b)
628 return -EBUSY;
629 }
630
631 spin_lock_irq(&intfdata->susp_lock);
632 intfdata->suspended = 1;
633 spin_unlock_irq(&intfdata->susp_lock);
634 stop_read_write_urbs(serial);
635
636 return 0;
637}
638EXPORT_SYMBOL(usb_wwan_suspend);
639
16871dca
ON
640static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata)
641{
642 int i;
643
644 for (i = 0; i < N_OUT_URB; i++) {
645 if (urb == portdata->out_urbs[i]) {
646 clear_bit(i, &portdata->out_busy);
647 break;
648 }
649 }
650}
651
0d456194
MG
652static void play_delayed(struct usb_serial_port *port)
653{
654 struct usb_wwan_intf_private *data;
655 struct usb_wwan_port_private *portdata;
656 struct urb *urb;
657 int err;
658
659 portdata = usb_get_serial_port_data(port);
660 data = port->serial->private;
661 while ((urb = usb_get_from_anchor(&portdata->delayed))) {
662 err = usb_submit_urb(urb, GFP_ATOMIC);
16871dca 663 if (!err) {
0d456194 664 data->in_flight++;
16871dca
ON
665 } else {
666 /* we have to throw away the rest */
667 do {
668 unbusy_queued_urb(urb, portdata);
97ac01d8 669 usb_autopm_put_interface_no_suspend(port->serial->interface);
16871dca
ON
670 } while ((urb = usb_get_from_anchor(&portdata->delayed)));
671 break;
672 }
0d456194
MG
673 }
674}
675
676int usb_wwan_resume(struct usb_serial *serial)
677{
678 int i, j;
679 struct usb_serial_port *port;
680 struct usb_wwan_intf_private *intfdata = serial->private;
681 struct usb_wwan_port_private *portdata;
682 struct urb *urb;
683 int err = 0;
684
0d456194
MG
685 /* get the interrupt URBs resubmitted unconditionally */
686 for (i = 0; i < serial->num_ports; i++) {
687 port = serial->port[i];
688 if (!port->interrupt_in_urb) {
a80be97d 689 dev_dbg(&port->dev, "%s: No interrupt URB for port\n", __func__);
0d456194
MG
690 continue;
691 }
692 err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
a80be97d 693 dev_dbg(&port->dev, "Submitted interrupt URB for port (result %d)\n", err);
0d456194 694 if (err < 0) {
3a1c2a82
GKH
695 dev_err(&port->dev, "%s: Error %d for interrupt URB\n",
696 __func__, err);
0d456194
MG
697 goto err_out;
698 }
699 }
700
701 for (i = 0; i < serial->num_ports; i++) {
702 /* walk all ports */
703 port = serial->port[i];
704 portdata = usb_get_serial_port_data(port);
705
706 /* skip closed ports */
707 spin_lock_irq(&intfdata->susp_lock);
032129cb 708 if (!portdata || !portdata->opened) {
0d456194
MG
709 spin_unlock_irq(&intfdata->susp_lock);
710 continue;
711 }
712
713 for (j = 0; j < N_IN_URB; j++) {
714 urb = portdata->in_urbs[j];
715 err = usb_submit_urb(urb, GFP_ATOMIC);
716 if (err < 0) {
3a1c2a82
GKH
717 dev_err(&port->dev, "%s: Error %d for bulk URB %d\n",
718 __func__, err, i);
0d456194
MG
719 spin_unlock_irq(&intfdata->susp_lock);
720 goto err_out;
721 }
722 }
723 play_delayed(port);
724 spin_unlock_irq(&intfdata->susp_lock);
725 }
726 spin_lock_irq(&intfdata->susp_lock);
727 intfdata->suspended = 0;
728 spin_unlock_irq(&intfdata->susp_lock);
729err_out:
730 return err;
731}
732EXPORT_SYMBOL(usb_wwan_resume);
733#endif
734
735MODULE_AUTHOR(DRIVER_AUTHOR);
736MODULE_DESCRIPTION(DRIVER_DESC);
737MODULE_VERSION(DRIVER_VERSION);
738MODULE_LICENSE("GPL");
This page took 0.221234 seconds and 5 git commands to generate.