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