Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 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> |
Peter Huewe | 66921ed | 2010-12-09 23:27:35 +0100 | [diff] [blame] | 34 | #include <linux/uaccess.h> |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 35 | #include <linux/usb.h> |
| 36 | #include <linux/usb/serial.h> |
Dan Williams | 02303f7 | 2010-11-19 16:04:00 -0600 | [diff] [blame] | 37 | #include <linux/serial.h> |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 38 | #include "usb-wwan.h" |
| 39 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 40 | static bool debug; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 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 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 82 | int usb_wwan_tiocmget(struct tty_struct *tty) |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 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 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 101 | int usb_wwan_tiocmset(struct tty_struct *tty, |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 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 | |
Dan Williams | 02303f7 | 2010-11-19 16:04:00 -0600 | [diff] [blame] | 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 | |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 181 | int usb_wwan_ioctl(struct tty_struct *tty, |
Dan Williams | 02303f7 | 2010-11-19 16:04:00 -0600 | [diff] [blame] | 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 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 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); |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 255 | usb_anchor_urb(this_urb, &portdata->submitted); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 256 | err = usb_submit_urb(this_urb, GFP_ATOMIC); |
| 257 | if (err) { |
| 258 | dbg("usb_submit_urb %p (write bulk) failed " |
| 259 | "(%d)", this_urb, err); |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 260 | usb_unanchor_urb(this_urb); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 261 | clear_bit(i, &portdata->out_busy); |
| 262 | spin_lock_irqsave(&intfdata->susp_lock, flags); |
| 263 | intfdata->in_flight--; |
| 264 | spin_unlock_irqrestore(&intfdata->susp_lock, |
| 265 | flags); |
Oliver Neukum | 3d06bf1 | 2011-02-10 15:33:17 +0100 | [diff] [blame] | 266 | usb_autopm_put_interface_async(port->serial->interface); |
Oliver Neukum | 433508a | 2011-02-10 15:33:23 +0100 | [diff] [blame] | 267 | break; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
| 271 | portdata->tx_start_time[i] = jiffies; |
| 272 | buf += todo; |
| 273 | left -= todo; |
| 274 | } |
| 275 | |
| 276 | count -= left; |
| 277 | dbg("%s: wrote (did %d)", __func__, count); |
| 278 | return count; |
| 279 | } |
| 280 | EXPORT_SYMBOL(usb_wwan_write); |
| 281 | |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 282 | static void usb_wwan_in_work(struct work_struct *w) |
| 283 | { |
| 284 | struct usb_wwan_port_private *portdata = |
| 285 | container_of(w, struct usb_wwan_port_private, in_work); |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 286 | struct usb_wwan_intf_private *intfdata; |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 287 | struct list_head *q = &portdata->in_urb_list; |
| 288 | struct urb *urb; |
| 289 | unsigned char *data; |
| 290 | struct tty_struct *tty; |
| 291 | struct usb_serial_port *port; |
| 292 | int err; |
| 293 | ssize_t len; |
| 294 | ssize_t count; |
| 295 | unsigned long flags; |
| 296 | |
| 297 | spin_lock_irqsave(&portdata->in_lock, flags); |
| 298 | while (!list_empty(q)) { |
| 299 | urb = list_first_entry(q, struct urb, urb_list); |
| 300 | port = urb->context; |
| 301 | if (port->throttle_req || port->throttled) |
| 302 | break; |
| 303 | |
| 304 | tty = tty_port_tty_get(&port->port); |
| 305 | if (!tty) |
Hemant Kumar | 9386739 | 2012-07-09 12:23:06 -0700 | [diff] [blame] | 306 | break; |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 307 | |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 308 | /* list_empty() will still be false after this; it means |
| 309 | * URB is still being processed */ |
| 310 | list_del(&urb->urb_list); |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 311 | |
| 312 | spin_unlock_irqrestore(&portdata->in_lock, flags); |
| 313 | |
| 314 | len = urb->actual_length - portdata->n_read; |
| 315 | data = urb->transfer_buffer + portdata->n_read; |
| 316 | count = tty_insert_flip_string(tty, data, len); |
| 317 | tty_flip_buffer_push(tty); |
| 318 | tty_kref_put(tty); |
| 319 | |
| 320 | if (count < len) { |
| 321 | dbg("%s: len:%d count:%d n_read:%d\n", __func__, |
| 322 | len, count, portdata->n_read); |
| 323 | portdata->n_read += count; |
| 324 | port->throttled = true; |
| 325 | |
| 326 | /* add request back to list */ |
| 327 | spin_lock_irqsave(&portdata->in_lock, flags); |
| 328 | list_add(&urb->urb_list, q); |
| 329 | spin_unlock_irqrestore(&portdata->in_lock, flags); |
| 330 | return; |
| 331 | } |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 332 | |
| 333 | /* re-init list pointer to indicate we are done with it */ |
| 334 | INIT_LIST_HEAD(&urb->urb_list); |
| 335 | |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 336 | portdata->n_read = 0; |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 337 | intfdata = port->serial->private; |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 338 | |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 339 | spin_lock_irqsave(&intfdata->susp_lock, flags); |
| 340 | if (!intfdata->suspended && !urb->anchor) { |
| 341 | usb_anchor_urb(urb, &portdata->submitted); |
| 342 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 343 | if (err) { |
| 344 | usb_unanchor_urb(urb); |
| 345 | if (err != -EPERM) |
| 346 | pr_err("%s: submit read urb failed:%d", |
| 347 | __func__, err); |
| 348 | } |
| 349 | |
| 350 | usb_mark_last_busy(port->serial->dev); |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 351 | } |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 352 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 353 | spin_lock_irqsave(&portdata->in_lock, flags); |
| 354 | } |
| 355 | spin_unlock_irqrestore(&portdata->in_lock, flags); |
| 356 | } |
| 357 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 358 | static void usb_wwan_indat_callback(struct urb *urb) |
| 359 | { |
| 360 | int err; |
| 361 | int endpoint; |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 362 | struct usb_wwan_port_private *portdata; |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 363 | struct usb_wwan_intf_private *intfdata; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 364 | struct usb_serial_port *port; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 365 | int status = urb->status; |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 366 | unsigned long flags; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 367 | |
| 368 | dbg("%s: %p", __func__, urb); |
| 369 | |
| 370 | endpoint = usb_pipeendpoint(urb->pipe); |
| 371 | port = urb->context; |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 372 | portdata = usb_get_serial_port_data(port); |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 373 | intfdata = port->serial->private; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 374 | |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 375 | usb_mark_last_busy(port->serial->dev); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 376 | |
Hemant Kumar | e8e40df | 2012-07-25 15:24:45 -0700 | [diff] [blame] | 377 | if ((status == -ENOENT || !status) && urb->actual_length) { |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 378 | spin_lock_irqsave(&portdata->in_lock, flags); |
| 379 | list_add_tail(&urb->urb_list, &portdata->in_urb_list); |
| 380 | spin_unlock_irqrestore(&portdata->in_lock, flags); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 381 | |
Pavankumar Kondeti | 52de63a | 2013-03-04 18:31:57 +0530 | [diff] [blame] | 382 | queue_work(system_nrt_wq, &portdata->in_work); |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 383 | |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | dbg("%s: nonzero status: %d on endpoint %02x.", |
| 388 | __func__, status, endpoint); |
| 389 | |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 390 | spin_lock(&intfdata->susp_lock); |
| 391 | if (intfdata->suspended || !portdata->opened) { |
| 392 | spin_unlock(&intfdata->susp_lock); |
| 393 | return; |
| 394 | } |
| 395 | spin_unlock(&intfdata->susp_lock); |
| 396 | |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 397 | if (status != -ESHUTDOWN) { |
| 398 | usb_anchor_urb(urb, &portdata->submitted); |
| 399 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 400 | if (err) { |
| 401 | usb_unanchor_urb(urb); |
| 402 | if (err != -EPERM) |
| 403 | pr_err("%s: submit read urb failed:%d", |
| 404 | __func__, err); |
| 405 | } |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 406 | } |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static void usb_wwan_outdat_callback(struct urb *urb) |
| 410 | { |
| 411 | struct usb_serial_port *port; |
| 412 | struct usb_wwan_port_private *portdata; |
| 413 | struct usb_wwan_intf_private *intfdata; |
| 414 | int i; |
| 415 | |
| 416 | dbg("%s", __func__); |
| 417 | |
| 418 | port = urb->context; |
| 419 | intfdata = port->serial->private; |
| 420 | |
| 421 | usb_serial_port_softint(port); |
| 422 | usb_autopm_put_interface_async(port->serial->interface); |
| 423 | portdata = usb_get_serial_port_data(port); |
| 424 | spin_lock(&intfdata->susp_lock); |
| 425 | intfdata->in_flight--; |
| 426 | spin_unlock(&intfdata->susp_lock); |
| 427 | |
| 428 | for (i = 0; i < N_OUT_URB; ++i) { |
| 429 | if (portdata->out_urbs[i] == urb) { |
| 430 | smp_mb__before_clear_bit(); |
| 431 | clear_bit(i, &portdata->out_busy); |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | int usb_wwan_write_room(struct tty_struct *tty) |
| 438 | { |
| 439 | struct usb_serial_port *port = tty->driver_data; |
| 440 | struct usb_wwan_port_private *portdata; |
| 441 | int i; |
| 442 | int data_len = 0; |
| 443 | struct urb *this_urb; |
| 444 | |
| 445 | portdata = usb_get_serial_port_data(port); |
| 446 | |
| 447 | for (i = 0; i < N_OUT_URB; i++) { |
| 448 | this_urb = portdata->out_urbs[i]; |
| 449 | if (this_urb && !test_bit(i, &portdata->out_busy)) |
| 450 | data_len += OUT_BUFLEN; |
| 451 | } |
| 452 | |
| 453 | dbg("%s: %d", __func__, data_len); |
| 454 | return data_len; |
| 455 | } |
| 456 | EXPORT_SYMBOL(usb_wwan_write_room); |
| 457 | |
| 458 | int usb_wwan_chars_in_buffer(struct tty_struct *tty) |
| 459 | { |
| 460 | struct usb_serial_port *port = tty->driver_data; |
| 461 | struct usb_wwan_port_private *portdata; |
| 462 | int i; |
| 463 | int data_len = 0; |
| 464 | struct urb *this_urb; |
| 465 | |
| 466 | portdata = usb_get_serial_port_data(port); |
| 467 | |
| 468 | for (i = 0; i < N_OUT_URB; i++) { |
| 469 | this_urb = portdata->out_urbs[i]; |
| 470 | /* FIXME: This locking is insufficient as this_urb may |
| 471 | go unused during the test */ |
| 472 | if (this_urb && test_bit(i, &portdata->out_busy)) |
| 473 | data_len += this_urb->transfer_buffer_length; |
| 474 | } |
| 475 | dbg("%s: %d", __func__, data_len); |
| 476 | return data_len; |
| 477 | } |
| 478 | EXPORT_SYMBOL(usb_wwan_chars_in_buffer); |
| 479 | |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 480 | void usb_wwan_throttle(struct tty_struct *tty) |
| 481 | { |
| 482 | struct usb_serial_port *port = tty->driver_data; |
| 483 | |
| 484 | port->throttle_req = true; |
| 485 | |
| 486 | dbg("%s:\n", __func__); |
| 487 | } |
| 488 | EXPORT_SYMBOL(usb_wwan_throttle); |
| 489 | |
| 490 | void usb_wwan_unthrottle(struct tty_struct *tty) |
| 491 | { |
| 492 | struct usb_serial_port *port = tty->driver_data; |
| 493 | struct usb_wwan_port_private *portdata; |
| 494 | |
| 495 | portdata = usb_get_serial_port_data(port); |
| 496 | |
| 497 | dbg("%s:\n", __func__); |
| 498 | port->throttle_req = false; |
| 499 | port->throttled = false; |
| 500 | |
Pavankumar Kondeti | 52de63a | 2013-03-04 18:31:57 +0530 | [diff] [blame] | 501 | queue_work(system_nrt_wq, &portdata->in_work); |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 502 | } |
| 503 | EXPORT_SYMBOL(usb_wwan_unthrottle); |
| 504 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 505 | int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port) |
| 506 | { |
| 507 | struct usb_wwan_port_private *portdata; |
| 508 | struct usb_wwan_intf_private *intfdata; |
| 509 | struct usb_serial *serial = port->serial; |
| 510 | int i, err; |
| 511 | struct urb *urb; |
| 512 | |
| 513 | portdata = usb_get_serial_port_data(port); |
| 514 | intfdata = serial->private; |
| 515 | |
Vamsi Krishna | 6819448 | 2011-12-12 18:28:48 -0800 | [diff] [blame] | 516 | /* explicitly set the driver mode to raw */ |
Vamsi Krishna | c502ecc | 2012-01-03 15:44:00 -0800 | [diff] [blame] | 517 | tty->raw = 1; |
| 518 | tty->real_raw = 1; |
Vamsi Krishna | 6819448 | 2011-12-12 18:28:48 -0800 | [diff] [blame] | 519 | |
Vamsi Krishna | 6ef832f | 2012-01-27 16:29:21 -0800 | [diff] [blame] | 520 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 521 | dbg("%s", __func__); |
| 522 | |
| 523 | /* Start reading from the IN endpoint */ |
| 524 | for (i = 0; i < N_IN_URB; i++) { |
| 525 | urb = portdata->in_urbs[i]; |
| 526 | if (!urb) |
| 527 | continue; |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 528 | usb_anchor_urb(urb, &portdata->submitted); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 529 | err = usb_submit_urb(urb, GFP_KERNEL); |
| 530 | if (err) { |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 531 | usb_unanchor_urb(urb); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 532 | dbg("%s: submit urb %d failed (%d) %d", |
| 533 | __func__, i, err, urb->transfer_buffer_length); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | if (intfdata->send_setup) |
| 538 | intfdata->send_setup(port); |
| 539 | |
| 540 | serial->interface->needs_remote_wakeup = 1; |
| 541 | spin_lock_irq(&intfdata->susp_lock); |
| 542 | portdata->opened = 1; |
| 543 | spin_unlock_irq(&intfdata->susp_lock); |
Oliver Neukum | 9a91aed | 2011-02-10 15:33:37 +0100 | [diff] [blame] | 544 | /* this balances a get in the generic USB serial code */ |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 545 | usb_autopm_put_interface(serial->interface); |
| 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | EXPORT_SYMBOL(usb_wwan_open); |
| 550 | |
| 551 | void usb_wwan_close(struct usb_serial_port *port) |
| 552 | { |
| 553 | int i; |
| 554 | struct usb_serial *serial = port->serial; |
| 555 | struct usb_wwan_port_private *portdata; |
| 556 | struct usb_wwan_intf_private *intfdata = port->serial->private; |
| 557 | |
| 558 | dbg("%s", __func__); |
| 559 | portdata = usb_get_serial_port_data(port); |
| 560 | |
| 561 | if (serial->dev) { |
| 562 | /* Stop reading/writing urbs */ |
| 563 | spin_lock_irq(&intfdata->susp_lock); |
| 564 | portdata->opened = 0; |
| 565 | spin_unlock_irq(&intfdata->susp_lock); |
| 566 | |
| 567 | for (i = 0; i < N_IN_URB; i++) |
| 568 | usb_kill_urb(portdata->in_urbs[i]); |
| 569 | for (i = 0; i < N_OUT_URB; i++) |
| 570 | usb_kill_urb(portdata->out_urbs[i]); |
Oliver Neukum | 9a91aed | 2011-02-10 15:33:37 +0100 | [diff] [blame] | 571 | /* balancing - important as an error cannot be handled*/ |
| 572 | usb_autopm_get_interface_no_resume(serial->interface); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 573 | serial->interface->needs_remote_wakeup = 0; |
| 574 | } |
| 575 | } |
| 576 | EXPORT_SYMBOL(usb_wwan_close); |
| 577 | |
| 578 | /* Helper functions used by usb_wwan_setup_urbs */ |
| 579 | static struct urb *usb_wwan_setup_urb(struct usb_serial *serial, int endpoint, |
| 580 | int dir, void *ctx, char *buf, int len, |
| 581 | void (*callback) (struct urb *)) |
| 582 | { |
| 583 | struct urb *urb; |
| 584 | |
| 585 | if (endpoint == -1) |
| 586 | return NULL; /* endpoint not needed */ |
| 587 | |
| 588 | urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ |
| 589 | if (urb == NULL) { |
| 590 | dbg("%s: alloc for endpoint %d failed.", __func__, endpoint); |
| 591 | return NULL; |
| 592 | } |
| 593 | |
| 594 | /* Fill URB using supplied data. */ |
| 595 | usb_fill_bulk_urb(urb, serial->dev, |
| 596 | usb_sndbulkpipe(serial->dev, endpoint) | dir, |
| 597 | buf, len, callback, ctx); |
| 598 | |
| 599 | return urb; |
| 600 | } |
| 601 | |
| 602 | /* Setup urbs */ |
| 603 | static void usb_wwan_setup_urbs(struct usb_serial *serial) |
| 604 | { |
| 605 | int i, j; |
| 606 | struct usb_serial_port *port; |
| 607 | struct usb_wwan_port_private *portdata; |
| 608 | |
| 609 | dbg("%s", __func__); |
| 610 | |
| 611 | for (i = 0; i < serial->num_ports; i++) { |
| 612 | port = serial->port[i]; |
| 613 | portdata = usb_get_serial_port_data(port); |
| 614 | |
| 615 | /* Do indat endpoints first */ |
| 616 | for (j = 0; j < N_IN_URB; ++j) { |
| 617 | portdata->in_urbs[j] = usb_wwan_setup_urb(serial, |
| 618 | port-> |
| 619 | bulk_in_endpointAddress, |
| 620 | USB_DIR_IN, |
| 621 | port, |
| 622 | portdata-> |
| 623 | in_buffer[j], |
| 624 | IN_BUFLEN, |
| 625 | usb_wwan_indat_callback); |
| 626 | } |
| 627 | |
| 628 | /* outdat endpoints */ |
| 629 | for (j = 0; j < N_OUT_URB; ++j) { |
| 630 | portdata->out_urbs[j] = usb_wwan_setup_urb(serial, |
| 631 | port-> |
| 632 | bulk_out_endpointAddress, |
| 633 | USB_DIR_OUT, |
| 634 | port, |
| 635 | portdata-> |
| 636 | out_buffer |
| 637 | [j], |
| 638 | OUT_BUFLEN, |
| 639 | usb_wwan_outdat_callback); |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | int usb_wwan_startup(struct usb_serial *serial) |
| 645 | { |
| 646 | int i, j, err; |
| 647 | struct usb_serial_port *port; |
| 648 | struct usb_wwan_port_private *portdata; |
| 649 | u8 *buffer; |
| 650 | |
| 651 | dbg("%s", __func__); |
| 652 | |
| 653 | /* Now setup per port private data */ |
| 654 | for (i = 0; i < serial->num_ports; i++) { |
| 655 | port = serial->port[i]; |
| 656 | portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); |
| 657 | if (!portdata) { |
| 658 | dbg("%s: kmalloc for usb_wwan_port_private (%d) failed!.", |
| 659 | __func__, i); |
| 660 | return 1; |
| 661 | } |
| 662 | init_usb_anchor(&portdata->delayed); |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 663 | init_usb_anchor(&portdata->submitted); |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 664 | INIT_WORK(&portdata->in_work, usb_wwan_in_work); |
| 665 | INIT_LIST_HEAD(&portdata->in_urb_list); |
| 666 | spin_lock_init(&portdata->in_lock); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 667 | |
| 668 | for (j = 0; j < N_IN_URB; j++) { |
Vamsi Krishna | 6ef832f | 2012-01-27 16:29:21 -0800 | [diff] [blame] | 669 | buffer = kmalloc(IN_BUFLEN, GFP_KERNEL); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 670 | if (!buffer) |
| 671 | goto bail_out_error; |
| 672 | portdata->in_buffer[j] = buffer; |
| 673 | } |
| 674 | |
| 675 | for (j = 0; j < N_OUT_URB; j++) { |
| 676 | buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL); |
| 677 | if (!buffer) |
| 678 | goto bail_out_error2; |
| 679 | portdata->out_buffer[j] = buffer; |
| 680 | } |
| 681 | |
| 682 | usb_set_serial_port_data(port, portdata); |
| 683 | |
| 684 | if (!port->interrupt_in_urb) |
| 685 | continue; |
| 686 | err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 687 | if (err) |
| 688 | dbg("%s: submit irq_in urb failed %d", __func__, err); |
| 689 | } |
| 690 | usb_wwan_setup_urbs(serial); |
| 691 | return 0; |
| 692 | |
| 693 | bail_out_error2: |
| 694 | for (j = 0; j < N_OUT_URB; j++) |
| 695 | kfree(portdata->out_buffer[j]); |
| 696 | bail_out_error: |
| 697 | for (j = 0; j < N_IN_URB; j++) |
Vamsi Krishna | 6ef832f | 2012-01-27 16:29:21 -0800 | [diff] [blame] | 698 | kfree(portdata->in_buffer[j]); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 699 | kfree(portdata); |
| 700 | return 1; |
| 701 | } |
| 702 | EXPORT_SYMBOL(usb_wwan_startup); |
| 703 | |
| 704 | static void stop_read_write_urbs(struct usb_serial *serial) |
| 705 | { |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 706 | int i; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 707 | struct usb_serial_port *port; |
| 708 | struct usb_wwan_port_private *portdata; |
| 709 | |
| 710 | /* Stop reading/writing urbs */ |
| 711 | for (i = 0; i < serial->num_ports; ++i) { |
| 712 | port = serial->port[i]; |
| 713 | portdata = usb_get_serial_port_data(port); |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 714 | usb_kill_anchored_urbs(&portdata->submitted); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
| 718 | void usb_wwan_disconnect(struct usb_serial *serial) |
| 719 | { |
| 720 | dbg("%s", __func__); |
| 721 | |
| 722 | stop_read_write_urbs(serial); |
| 723 | } |
| 724 | EXPORT_SYMBOL(usb_wwan_disconnect); |
| 725 | |
| 726 | void usb_wwan_release(struct usb_serial *serial) |
| 727 | { |
| 728 | int i, j; |
| 729 | struct usb_serial_port *port; |
| 730 | struct usb_wwan_port_private *portdata; |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 731 | struct urb *urb; |
| 732 | struct list_head *q; |
| 733 | unsigned long flags; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 734 | |
| 735 | /* Now free them */ |
| 736 | for (i = 0; i < serial->num_ports; ++i) { |
| 737 | port = serial->port[i]; |
| 738 | portdata = usb_get_serial_port_data(port); |
| 739 | |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 740 | cancel_work_sync(&portdata->in_work); |
| 741 | /* TBD: do we really need this */ |
| 742 | spin_lock_irqsave(&portdata->in_lock, flags); |
| 743 | q = &portdata->in_urb_list; |
| 744 | while (!list_empty(q)) { |
| 745 | urb = list_first_entry(q, struct urb, urb_list); |
| 746 | list_del_init(&urb->urb_list); |
| 747 | } |
| 748 | spin_unlock_irqrestore(&portdata->in_lock, flags); |
| 749 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 750 | for (j = 0; j < N_IN_URB; j++) { |
| 751 | usb_free_urb(portdata->in_urbs[j]); |
Vamsi Krishna | 6ef832f | 2012-01-27 16:29:21 -0800 | [diff] [blame] | 752 | kfree(portdata->in_buffer[j]); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 753 | portdata->in_urbs[j] = NULL; |
| 754 | } |
| 755 | for (j = 0; j < N_OUT_URB; j++) { |
| 756 | usb_free_urb(portdata->out_urbs[j]); |
| 757 | kfree(portdata->out_buffer[j]); |
| 758 | portdata->out_urbs[j] = NULL; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | /* Now free per port private data */ |
| 763 | for (i = 0; i < serial->num_ports; i++) { |
| 764 | port = serial->port[i]; |
| 765 | kfree(usb_get_serial_port_data(port)); |
| 766 | } |
| 767 | } |
| 768 | EXPORT_SYMBOL(usb_wwan_release); |
| 769 | |
| 770 | #ifdef CONFIG_PM |
| 771 | int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message) |
| 772 | { |
| 773 | struct usb_wwan_intf_private *intfdata = serial->private; |
| 774 | int b; |
| 775 | |
| 776 | dbg("%s entered", __func__); |
| 777 | |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 778 | if (PMSG_IS_AUTO(message)) { |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 779 | spin_lock_irq(&intfdata->susp_lock); |
| 780 | b = intfdata->in_flight; |
| 781 | spin_unlock_irq(&intfdata->susp_lock); |
| 782 | |
Hemant Kumar | f2285db | 2012-07-23 20:02:51 -0700 | [diff] [blame] | 783 | if (b || pm_runtime_autosuspend_expiration(&serial->dev->dev)) |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 784 | return -EBUSY; |
| 785 | } |
| 786 | |
| 787 | spin_lock_irq(&intfdata->susp_lock); |
| 788 | intfdata->suspended = 1; |
| 789 | spin_unlock_irq(&intfdata->susp_lock); |
| 790 | stop_read_write_urbs(serial); |
| 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | EXPORT_SYMBOL(usb_wwan_suspend); |
| 795 | |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 796 | static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata) |
| 797 | { |
| 798 | int i; |
| 799 | |
| 800 | for (i = 0; i < N_OUT_URB; i++) { |
| 801 | if (urb == portdata->out_urbs[i]) { |
| 802 | clear_bit(i, &portdata->out_busy); |
| 803 | break; |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 808 | static void play_delayed(struct usb_serial_port *port) |
| 809 | { |
| 810 | struct usb_wwan_intf_private *data; |
| 811 | struct usb_wwan_port_private *portdata; |
| 812 | struct urb *urb; |
| 813 | int err; |
| 814 | |
| 815 | portdata = usb_get_serial_port_data(port); |
| 816 | data = port->serial->private; |
| 817 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 818 | usb_anchor_urb(urb, &portdata->submitted); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 819 | err = usb_submit_urb(urb, GFP_ATOMIC); |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 820 | if (!err) { |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 821 | data->in_flight++; |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 822 | } else { |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 823 | usb_unanchor_urb(urb); |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 824 | /* we have to throw away the rest */ |
| 825 | do { |
| 826 | unbusy_queued_urb(urb, portdata); |
Oliver Neukum | 97ac01d | 2011-03-18 12:44:17 +0100 | [diff] [blame] | 827 | usb_autopm_put_interface_no_suspend(port->serial->interface); |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 828 | } while ((urb = usb_get_from_anchor(&portdata->delayed))); |
| 829 | break; |
| 830 | } |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | |
| 834 | int usb_wwan_resume(struct usb_serial *serial) |
| 835 | { |
| 836 | int i, j; |
| 837 | struct usb_serial_port *port; |
| 838 | struct usb_wwan_intf_private *intfdata = serial->private; |
| 839 | struct usb_wwan_port_private *portdata; |
| 840 | struct urb *urb; |
| 841 | int err = 0; |
| 842 | |
| 843 | dbg("%s entered", __func__); |
| 844 | /* get the interrupt URBs resubmitted unconditionally */ |
| 845 | for (i = 0; i < serial->num_ports; i++) { |
| 846 | port = serial->port[i]; |
| 847 | if (!port->interrupt_in_urb) { |
| 848 | dbg("%s: No interrupt URB for port %d", __func__, i); |
| 849 | continue; |
| 850 | } |
| 851 | err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO); |
| 852 | dbg("Submitted interrupt URB for port %d (result %d)", i, err); |
| 853 | if (err < 0) { |
| 854 | err("%s: Error %d for interrupt URB of port%d", |
| 855 | __func__, err, i); |
| 856 | goto err_out; |
| 857 | } |
| 858 | } |
| 859 | |
Hemant Kumar | 8e52b12 | 2012-05-15 12:18:12 -0700 | [diff] [blame] | 860 | spin_lock_irq(&intfdata->susp_lock); |
| 861 | intfdata->suspended = 0; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 862 | for (i = 0; i < serial->num_ports; i++) { |
| 863 | /* walk all ports */ |
| 864 | port = serial->port[i]; |
| 865 | portdata = usb_get_serial_port_data(port); |
| 866 | |
| 867 | /* skip closed ports */ |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 868 | if (!portdata->opened) |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 869 | continue; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 870 | |
| 871 | for (j = 0; j < N_IN_URB; j++) { |
| 872 | urb = portdata->in_urbs[j]; |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 873 | |
| 874 | /* don't re-submit if it already was submitted or if |
| 875 | * it is being processed by in_work */ |
| 876 | if (urb->anchor || !list_empty(&urb->urb_list)) |
| 877 | continue; |
| 878 | |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 879 | usb_anchor_urb(urb, &portdata->submitted); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 880 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 881 | if (err < 0) { |
Jack Pham | 74715d9 | 2012-08-28 18:26:54 -0700 | [diff] [blame] | 882 | err("%s: Error %d for bulk URB[%d]:%p %d", |
| 883 | __func__, err, j, urb, i); |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 884 | usb_unanchor_urb(urb); |
| 885 | intfdata->suspended = 1; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 886 | spin_unlock_irq(&intfdata->susp_lock); |
| 887 | goto err_out; |
| 888 | } |
| 889 | } |
| 890 | play_delayed(port); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 891 | } |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 892 | spin_unlock_irq(&intfdata->susp_lock); |
| 893 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 894 | err_out: |
| 895 | return err; |
| 896 | } |
| 897 | EXPORT_SYMBOL(usb_wwan_resume); |
| 898 | #endif |
| 899 | |
| 900 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 901 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 902 | MODULE_VERSION(DRIVER_VERSION); |
| 903 | MODULE_LICENSE("GPL"); |
| 904 | |
| 905 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 906 | MODULE_PARM_DESC(debug, "Debug messages"); |