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 | { |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 44 | struct usb_wwan_port_private *portdata; |
| 45 | |
| 46 | struct usb_wwan_intf_private *intfdata; |
| 47 | |
| 48 | dbg("%s", __func__); |
| 49 | |
| 50 | intfdata = port->serial->private; |
| 51 | |
| 52 | if (!intfdata->send_setup) |
| 53 | return; |
| 54 | |
| 55 | portdata = usb_get_serial_port_data(port); |
Johan Hovold | 906c9c4 | 2013-02-13 17:53:28 +0100 | [diff] [blame] | 56 | /* FIXME: locking */ |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 57 | portdata->rts_state = on; |
| 58 | portdata->dtr_state = on; |
Johan Hovold | 906c9c4 | 2013-02-13 17:53:28 +0100 | [diff] [blame] | 59 | |
| 60 | intfdata->send_setup(port); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 61 | } |
| 62 | EXPORT_SYMBOL(usb_wwan_dtr_rts); |
| 63 | |
| 64 | void usb_wwan_set_termios(struct tty_struct *tty, |
| 65 | struct usb_serial_port *port, |
| 66 | struct ktermios *old_termios) |
| 67 | { |
| 68 | struct usb_wwan_intf_private *intfdata = port->serial->private; |
| 69 | |
| 70 | dbg("%s", __func__); |
| 71 | |
| 72 | /* Doesn't support option setting */ |
| 73 | tty_termios_copy_hw(tty->termios, old_termios); |
| 74 | |
| 75 | if (intfdata->send_setup) |
| 76 | intfdata->send_setup(port); |
| 77 | } |
| 78 | EXPORT_SYMBOL(usb_wwan_set_termios); |
| 79 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 80 | int usb_wwan_tiocmget(struct tty_struct *tty) |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 81 | { |
| 82 | struct usb_serial_port *port = tty->driver_data; |
| 83 | unsigned int value; |
| 84 | struct usb_wwan_port_private *portdata; |
| 85 | |
| 86 | portdata = usb_get_serial_port_data(port); |
| 87 | |
| 88 | value = ((portdata->rts_state) ? TIOCM_RTS : 0) | |
| 89 | ((portdata->dtr_state) ? TIOCM_DTR : 0) | |
| 90 | ((portdata->cts_state) ? TIOCM_CTS : 0) | |
| 91 | ((portdata->dsr_state) ? TIOCM_DSR : 0) | |
| 92 | ((portdata->dcd_state) ? TIOCM_CAR : 0) | |
| 93 | ((portdata->ri_state) ? TIOCM_RNG : 0); |
| 94 | |
| 95 | return value; |
| 96 | } |
| 97 | EXPORT_SYMBOL(usb_wwan_tiocmget); |
| 98 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 99 | int usb_wwan_tiocmset(struct tty_struct *tty, |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 100 | unsigned int set, unsigned int clear) |
| 101 | { |
| 102 | struct usb_serial_port *port = tty->driver_data; |
| 103 | struct usb_wwan_port_private *portdata; |
| 104 | struct usb_wwan_intf_private *intfdata; |
| 105 | |
| 106 | portdata = usb_get_serial_port_data(port); |
| 107 | intfdata = port->serial->private; |
| 108 | |
| 109 | if (!intfdata->send_setup) |
| 110 | return -EINVAL; |
| 111 | |
| 112 | /* FIXME: what locks portdata fields ? */ |
| 113 | if (set & TIOCM_RTS) |
| 114 | portdata->rts_state = 1; |
| 115 | if (set & TIOCM_DTR) |
| 116 | portdata->dtr_state = 1; |
| 117 | |
| 118 | if (clear & TIOCM_RTS) |
| 119 | portdata->rts_state = 0; |
| 120 | if (clear & TIOCM_DTR) |
| 121 | portdata->dtr_state = 0; |
| 122 | return intfdata->send_setup(port); |
| 123 | } |
| 124 | EXPORT_SYMBOL(usb_wwan_tiocmset); |
| 125 | |
Dan Williams | 02303f7 | 2010-11-19 16:04:00 -0600 | [diff] [blame] | 126 | static int get_serial_info(struct usb_serial_port *port, |
| 127 | struct serial_struct __user *retinfo) |
| 128 | { |
| 129 | struct serial_struct tmp; |
| 130 | |
| 131 | if (!retinfo) |
| 132 | return -EFAULT; |
| 133 | |
| 134 | memset(&tmp, 0, sizeof(tmp)); |
| 135 | tmp.line = port->serial->minor; |
| 136 | tmp.port = port->number; |
| 137 | tmp.baud_base = tty_get_baud_rate(port->port.tty); |
| 138 | tmp.close_delay = port->port.close_delay / 10; |
| 139 | tmp.closing_wait = port->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? |
| 140 | ASYNC_CLOSING_WAIT_NONE : |
| 141 | port->port.closing_wait / 10; |
| 142 | |
| 143 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
| 144 | return -EFAULT; |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static int set_serial_info(struct usb_serial_port *port, |
| 149 | struct serial_struct __user *newinfo) |
| 150 | { |
| 151 | struct serial_struct new_serial; |
| 152 | unsigned int closing_wait, close_delay; |
| 153 | int retval = 0; |
| 154 | |
| 155 | if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) |
| 156 | return -EFAULT; |
| 157 | |
| 158 | close_delay = new_serial.close_delay * 10; |
| 159 | closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ? |
| 160 | ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10; |
| 161 | |
| 162 | mutex_lock(&port->port.mutex); |
| 163 | |
| 164 | if (!capable(CAP_SYS_ADMIN)) { |
| 165 | if ((close_delay != port->port.close_delay) || |
| 166 | (closing_wait != port->port.closing_wait)) |
| 167 | retval = -EPERM; |
| 168 | else |
| 169 | retval = -EOPNOTSUPP; |
| 170 | } else { |
| 171 | port->port.close_delay = close_delay; |
| 172 | port->port.closing_wait = closing_wait; |
| 173 | } |
| 174 | |
| 175 | mutex_unlock(&port->port.mutex); |
| 176 | return retval; |
| 177 | } |
| 178 | |
Alan Cox | 00a0d0d | 2011-02-14 16:27:06 +0000 | [diff] [blame] | 179 | int usb_wwan_ioctl(struct tty_struct *tty, |
Dan Williams | 02303f7 | 2010-11-19 16:04:00 -0600 | [diff] [blame] | 180 | unsigned int cmd, unsigned long arg) |
| 181 | { |
| 182 | struct usb_serial_port *port = tty->driver_data; |
| 183 | |
| 184 | dbg("%s cmd 0x%04x", __func__, cmd); |
| 185 | |
| 186 | switch (cmd) { |
| 187 | case TIOCGSERIAL: |
| 188 | return get_serial_info(port, |
| 189 | (struct serial_struct __user *) arg); |
| 190 | case TIOCSSERIAL: |
| 191 | return set_serial_info(port, |
| 192 | (struct serial_struct __user *) arg); |
| 193 | default: |
| 194 | break; |
| 195 | } |
| 196 | |
| 197 | dbg("%s arg not supported", __func__); |
| 198 | |
| 199 | return -ENOIOCTLCMD; |
| 200 | } |
| 201 | EXPORT_SYMBOL(usb_wwan_ioctl); |
| 202 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 203 | /* Write */ |
| 204 | int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, |
| 205 | const unsigned char *buf, int count) |
| 206 | { |
| 207 | struct usb_wwan_port_private *portdata; |
| 208 | struct usb_wwan_intf_private *intfdata; |
| 209 | int i; |
| 210 | int left, todo; |
| 211 | struct urb *this_urb = NULL; /* spurious */ |
| 212 | int err; |
| 213 | unsigned long flags; |
| 214 | |
| 215 | portdata = usb_get_serial_port_data(port); |
| 216 | intfdata = port->serial->private; |
| 217 | |
| 218 | dbg("%s: write (%d chars)", __func__, count); |
| 219 | |
| 220 | i = 0; |
| 221 | left = count; |
| 222 | for (i = 0; left > 0 && i < N_OUT_URB; i++) { |
| 223 | todo = left; |
| 224 | if (todo > OUT_BUFLEN) |
| 225 | todo = OUT_BUFLEN; |
| 226 | |
| 227 | this_urb = portdata->out_urbs[i]; |
| 228 | if (test_and_set_bit(i, &portdata->out_busy)) { |
| 229 | if (time_before(jiffies, |
| 230 | portdata->tx_start_time[i] + 10 * HZ)) |
| 231 | continue; |
| 232 | usb_unlink_urb(this_urb); |
| 233 | continue; |
| 234 | } |
| 235 | dbg("%s: endpoint %d buf %d", __func__, |
| 236 | usb_pipeendpoint(this_urb->pipe), i); |
| 237 | |
| 238 | err = usb_autopm_get_interface_async(port->serial->interface); |
xiao jin | 640768a | 2014-05-26 19:23:13 +0200 | [diff] [blame] | 239 | if (err < 0) { |
| 240 | clear_bit(i, &portdata->out_busy); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 241 | break; |
xiao jin | 640768a | 2014-05-26 19:23:13 +0200 | [diff] [blame] | 242 | } |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 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 | c7525b8 | 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 | c7525b8 | 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 | c7525b8 | 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 | c7525b8 | 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 | c7525b8 | 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 | c7525b8 | 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 | c7525b8 | 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 | c7525b8 | 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 | 71d2f46 | 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 | c7525b8 | 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 | 71d2f46 | 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 | |
Johan Hovold | 0886f4e | 2014-05-26 19:23:17 +0200 | [diff] [blame] | 523 | if (port->interrupt_in_urb) { |
| 524 | err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 525 | if (err) { |
| 526 | dev_dbg(&port->dev, "%s: submit int urb failed: %d\n", |
| 527 | __func__, err); |
| 528 | } |
| 529 | } |
| 530 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 531 | /* Start reading from the IN endpoint */ |
| 532 | for (i = 0; i < N_IN_URB; i++) { |
| 533 | urb = portdata->in_urbs[i]; |
| 534 | if (!urb) |
| 535 | continue; |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 536 | usb_anchor_urb(urb, &portdata->submitted); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 537 | err = usb_submit_urb(urb, GFP_KERNEL); |
| 538 | if (err) { |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 539 | usb_unanchor_urb(urb); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 540 | dbg("%s: submit urb %d failed (%d) %d", |
| 541 | __func__, i, err, urb->transfer_buffer_length); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | if (intfdata->send_setup) |
| 546 | intfdata->send_setup(port); |
| 547 | |
| 548 | serial->interface->needs_remote_wakeup = 1; |
| 549 | spin_lock_irq(&intfdata->susp_lock); |
| 550 | portdata->opened = 1; |
| 551 | spin_unlock_irq(&intfdata->susp_lock); |
Oliver Neukum | 9a91aed | 2011-02-10 15:33:37 +0100 | [diff] [blame] | 552 | /* this balances a get in the generic USB serial code */ |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 553 | usb_autopm_put_interface(serial->interface); |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | EXPORT_SYMBOL(usb_wwan_open); |
| 558 | |
Johan Hovold | ca91395 | 2014-05-26 19:23:16 +0200 | [diff] [blame] | 559 | static void unbusy_queued_urb(struct urb *urb, |
| 560 | struct usb_wwan_port_private *portdata) |
| 561 | { |
| 562 | int i; |
| 563 | |
| 564 | for (i = 0; i < N_OUT_URB; i++) { |
| 565 | if (urb == portdata->out_urbs[i]) { |
| 566 | clear_bit(i, &portdata->out_busy); |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 572 | void usb_wwan_close(struct usb_serial_port *port) |
| 573 | { |
| 574 | int i; |
| 575 | struct usb_serial *serial = port->serial; |
| 576 | struct usb_wwan_port_private *portdata; |
| 577 | struct usb_wwan_intf_private *intfdata = port->serial->private; |
Johan Hovold | ca91395 | 2014-05-26 19:23:16 +0200 | [diff] [blame] | 578 | struct urb *urb; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 579 | |
| 580 | dbg("%s", __func__); |
| 581 | portdata = usb_get_serial_port_data(port); |
| 582 | |
| 583 | if (serial->dev) { |
| 584 | /* Stop reading/writing urbs */ |
| 585 | spin_lock_irq(&intfdata->susp_lock); |
| 586 | portdata->opened = 0; |
| 587 | spin_unlock_irq(&intfdata->susp_lock); |
| 588 | |
Johan Hovold | ca91395 | 2014-05-26 19:23:16 +0200 | [diff] [blame] | 589 | for (;;) { |
| 590 | urb = usb_get_from_anchor(&portdata->delayed); |
| 591 | if (!urb) |
| 592 | break; |
| 593 | unbusy_queued_urb(urb, portdata); |
| 594 | usb_autopm_put_interface_async(serial->interface); |
| 595 | } |
| 596 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 597 | for (i = 0; i < N_IN_URB; i++) |
| 598 | usb_kill_urb(portdata->in_urbs[i]); |
| 599 | for (i = 0; i < N_OUT_URB; i++) |
| 600 | usb_kill_urb(portdata->out_urbs[i]); |
Johan Hovold | 0886f4e | 2014-05-26 19:23:17 +0200 | [diff] [blame] | 601 | usb_kill_urb(port->interrupt_in_urb); |
Oliver Neukum | 9a91aed | 2011-02-10 15:33:37 +0100 | [diff] [blame] | 602 | /* balancing - important as an error cannot be handled*/ |
| 603 | usb_autopm_get_interface_no_resume(serial->interface); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 604 | serial->interface->needs_remote_wakeup = 0; |
| 605 | } |
| 606 | } |
| 607 | EXPORT_SYMBOL(usb_wwan_close); |
| 608 | |
| 609 | /* Helper functions used by usb_wwan_setup_urbs */ |
| 610 | static struct urb *usb_wwan_setup_urb(struct usb_serial *serial, int endpoint, |
| 611 | int dir, void *ctx, char *buf, int len, |
| 612 | void (*callback) (struct urb *)) |
| 613 | { |
| 614 | struct urb *urb; |
| 615 | |
| 616 | if (endpoint == -1) |
| 617 | return NULL; /* endpoint not needed */ |
| 618 | |
| 619 | urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ |
| 620 | if (urb == NULL) { |
| 621 | dbg("%s: alloc for endpoint %d failed.", __func__, endpoint); |
| 622 | return NULL; |
| 623 | } |
| 624 | |
| 625 | /* Fill URB using supplied data. */ |
| 626 | usb_fill_bulk_urb(urb, serial->dev, |
| 627 | usb_sndbulkpipe(serial->dev, endpoint) | dir, |
| 628 | buf, len, callback, ctx); |
| 629 | |
| 630 | return urb; |
| 631 | } |
| 632 | |
| 633 | /* Setup urbs */ |
| 634 | static void usb_wwan_setup_urbs(struct usb_serial *serial) |
| 635 | { |
| 636 | int i, j; |
| 637 | struct usb_serial_port *port; |
| 638 | struct usb_wwan_port_private *portdata; |
| 639 | |
| 640 | dbg("%s", __func__); |
| 641 | |
| 642 | for (i = 0; i < serial->num_ports; i++) { |
| 643 | port = serial->port[i]; |
| 644 | portdata = usb_get_serial_port_data(port); |
| 645 | |
| 646 | /* Do indat endpoints first */ |
| 647 | for (j = 0; j < N_IN_URB; ++j) { |
| 648 | portdata->in_urbs[j] = usb_wwan_setup_urb(serial, |
| 649 | port-> |
| 650 | bulk_in_endpointAddress, |
| 651 | USB_DIR_IN, |
| 652 | port, |
| 653 | portdata-> |
| 654 | in_buffer[j], |
| 655 | IN_BUFLEN, |
| 656 | usb_wwan_indat_callback); |
| 657 | } |
| 658 | |
| 659 | /* outdat endpoints */ |
| 660 | for (j = 0; j < N_OUT_URB; ++j) { |
| 661 | portdata->out_urbs[j] = usb_wwan_setup_urb(serial, |
| 662 | port-> |
| 663 | bulk_out_endpointAddress, |
| 664 | USB_DIR_OUT, |
| 665 | port, |
| 666 | portdata-> |
| 667 | out_buffer |
| 668 | [j], |
| 669 | OUT_BUFLEN, |
| 670 | usb_wwan_outdat_callback); |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | int usb_wwan_startup(struct usb_serial *serial) |
| 676 | { |
Johan Hovold | 0886f4e | 2014-05-26 19:23:17 +0200 | [diff] [blame] | 677 | int i, j; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 678 | struct usb_serial_port *port; |
| 679 | struct usb_wwan_port_private *portdata; |
| 680 | u8 *buffer; |
| 681 | |
| 682 | dbg("%s", __func__); |
| 683 | |
| 684 | /* Now setup per port private data */ |
| 685 | for (i = 0; i < serial->num_ports; i++) { |
| 686 | port = serial->port[i]; |
| 687 | portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); |
| 688 | if (!portdata) { |
| 689 | dbg("%s: kmalloc for usb_wwan_port_private (%d) failed!.", |
| 690 | __func__, i); |
| 691 | return 1; |
| 692 | } |
| 693 | init_usb_anchor(&portdata->delayed); |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 694 | init_usb_anchor(&portdata->submitted); |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 695 | INIT_WORK(&portdata->in_work, usb_wwan_in_work); |
| 696 | INIT_LIST_HEAD(&portdata->in_urb_list); |
| 697 | spin_lock_init(&portdata->in_lock); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 698 | |
| 699 | for (j = 0; j < N_IN_URB; j++) { |
Vamsi Krishna | 6ef832f | 2012-01-27 16:29:21 -0800 | [diff] [blame] | 700 | buffer = kmalloc(IN_BUFLEN, GFP_KERNEL); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 701 | if (!buffer) |
| 702 | goto bail_out_error; |
| 703 | portdata->in_buffer[j] = buffer; |
| 704 | } |
| 705 | |
| 706 | for (j = 0; j < N_OUT_URB; j++) { |
| 707 | buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL); |
| 708 | if (!buffer) |
| 709 | goto bail_out_error2; |
| 710 | portdata->out_buffer[j] = buffer; |
| 711 | } |
| 712 | |
| 713 | usb_set_serial_port_data(port, portdata); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 714 | } |
| 715 | usb_wwan_setup_urbs(serial); |
| 716 | return 0; |
| 717 | |
| 718 | bail_out_error2: |
| 719 | for (j = 0; j < N_OUT_URB; j++) |
| 720 | kfree(portdata->out_buffer[j]); |
| 721 | bail_out_error: |
| 722 | for (j = 0; j < N_IN_URB; j++) |
Vamsi Krishna | 6ef832f | 2012-01-27 16:29:21 -0800 | [diff] [blame] | 723 | kfree(portdata->in_buffer[j]); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 724 | kfree(portdata); |
| 725 | return 1; |
| 726 | } |
| 727 | EXPORT_SYMBOL(usb_wwan_startup); |
| 728 | |
| 729 | static void stop_read_write_urbs(struct usb_serial *serial) |
| 730 | { |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 731 | int i; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 732 | struct usb_serial_port *port; |
| 733 | struct usb_wwan_port_private *portdata; |
| 734 | |
| 735 | /* Stop reading/writing urbs */ |
| 736 | for (i = 0; i < serial->num_ports; ++i) { |
| 737 | port = serial->port[i]; |
| 738 | portdata = usb_get_serial_port_data(port); |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 739 | usb_kill_anchored_urbs(&portdata->submitted); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
| 743 | void usb_wwan_disconnect(struct usb_serial *serial) |
| 744 | { |
| 745 | dbg("%s", __func__); |
| 746 | |
| 747 | stop_read_write_urbs(serial); |
| 748 | } |
| 749 | EXPORT_SYMBOL(usb_wwan_disconnect); |
| 750 | |
| 751 | void usb_wwan_release(struct usb_serial *serial) |
| 752 | { |
| 753 | int i, j; |
| 754 | struct usb_serial_port *port; |
| 755 | struct usb_wwan_port_private *portdata; |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 756 | struct urb *urb; |
| 757 | struct list_head *q; |
| 758 | unsigned long flags; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 759 | |
| 760 | /* Now free them */ |
| 761 | for (i = 0; i < serial->num_ports; ++i) { |
| 762 | port = serial->port[i]; |
| 763 | portdata = usb_get_serial_port_data(port); |
| 764 | |
Vamsi Krishna | 6f806b8 | 2012-05-07 16:29:08 -0700 | [diff] [blame] | 765 | cancel_work_sync(&portdata->in_work); |
| 766 | /* TBD: do we really need this */ |
| 767 | spin_lock_irqsave(&portdata->in_lock, flags); |
| 768 | q = &portdata->in_urb_list; |
| 769 | while (!list_empty(q)) { |
| 770 | urb = list_first_entry(q, struct urb, urb_list); |
| 771 | list_del_init(&urb->urb_list); |
| 772 | } |
| 773 | spin_unlock_irqrestore(&portdata->in_lock, flags); |
| 774 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 775 | for (j = 0; j < N_IN_URB; j++) { |
| 776 | usb_free_urb(portdata->in_urbs[j]); |
Vamsi Krishna | 6ef832f | 2012-01-27 16:29:21 -0800 | [diff] [blame] | 777 | kfree(portdata->in_buffer[j]); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 778 | portdata->in_urbs[j] = NULL; |
| 779 | } |
| 780 | for (j = 0; j < N_OUT_URB; j++) { |
| 781 | usb_free_urb(portdata->out_urbs[j]); |
| 782 | kfree(portdata->out_buffer[j]); |
| 783 | portdata->out_urbs[j] = NULL; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | /* Now free per port private data */ |
| 788 | for (i = 0; i < serial->num_ports; i++) { |
| 789 | port = serial->port[i]; |
| 790 | kfree(usb_get_serial_port_data(port)); |
| 791 | } |
| 792 | } |
| 793 | EXPORT_SYMBOL(usb_wwan_release); |
| 794 | |
| 795 | #ifdef CONFIG_PM |
| 796 | int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message) |
| 797 | { |
| 798 | struct usb_wwan_intf_private *intfdata = serial->private; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 799 | |
| 800 | dbg("%s entered", __func__); |
| 801 | |
Johan Hovold | 887b3c3 | 2014-05-26 19:23:15 +0200 | [diff] [blame] | 802 | spin_lock_irq(&intfdata->susp_lock); |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 803 | if (PMSG_IS_AUTO(message)) { |
Paul | 1097d78 | 2015-01-11 17:15:40 -0800 | [diff] [blame] | 804 | if (intfdata->in_flight || |
| 805 | pm_runtime_autosuspend_expiration(&serial->dev->dev)) { |
Johan Hovold | 887b3c3 | 2014-05-26 19:23:15 +0200 | [diff] [blame] | 806 | spin_unlock_irq(&intfdata->susp_lock); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 807 | return -EBUSY; |
Johan Hovold | 887b3c3 | 2014-05-26 19:23:15 +0200 | [diff] [blame] | 808 | } |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 811 | intfdata->suspended = 1; |
| 812 | spin_unlock_irq(&intfdata->susp_lock); |
Johan Hovold | 887b3c3 | 2014-05-26 19:23:15 +0200 | [diff] [blame] | 813 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 814 | stop_read_write_urbs(serial); |
| 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | EXPORT_SYMBOL(usb_wwan_suspend); |
| 819 | |
Johan Hovold | 9e91351 | 2014-05-26 19:23:18 +0200 | [diff] [blame] | 820 | static int play_delayed(struct usb_serial_port *port) |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 821 | { |
| 822 | struct usb_wwan_intf_private *data; |
| 823 | struct usb_wwan_port_private *portdata; |
| 824 | struct urb *urb; |
Johan Hovold | 9e91351 | 2014-05-26 19:23:18 +0200 | [diff] [blame] | 825 | int err = 0; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 826 | |
| 827 | portdata = usb_get_serial_port_data(port); |
| 828 | data = port->serial->private; |
| 829 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 830 | usb_anchor_urb(urb, &portdata->submitted); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 831 | err = usb_submit_urb(urb, GFP_ATOMIC); |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 832 | if (!err) { |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 833 | data->in_flight++; |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 834 | } else { |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 835 | usb_unanchor_urb(urb); |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 836 | /* we have to throw away the rest */ |
| 837 | do { |
| 838 | unbusy_queued_urb(urb, portdata); |
Oliver Neukum | 97ac01d | 2011-03-18 12:44:17 +0100 | [diff] [blame] | 839 | usb_autopm_put_interface_no_suspend(port->serial->interface); |
Oliver Neukum | 16871dc | 2011-02-10 15:33:29 +0100 | [diff] [blame] | 840 | } while ((urb = usb_get_from_anchor(&portdata->delayed))); |
| 841 | break; |
| 842 | } |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 843 | } |
Johan Hovold | 9e91351 | 2014-05-26 19:23:18 +0200 | [diff] [blame] | 844 | |
| 845 | return err; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | int usb_wwan_resume(struct usb_serial *serial) |
| 849 | { |
| 850 | int i, j; |
| 851 | struct usb_serial_port *port; |
| 852 | struct usb_wwan_intf_private *intfdata = serial->private; |
| 853 | struct usb_wwan_port_private *portdata; |
| 854 | struct urb *urb; |
Johan Hovold | 9e91351 | 2014-05-26 19:23:18 +0200 | [diff] [blame] | 855 | int err; |
| 856 | int err_count = 0; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 857 | |
| 858 | dbg("%s entered", __func__); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 859 | |
Hemant Kumar | 8e52b12 | 2012-05-15 12:18:12 -0700 | [diff] [blame] | 860 | spin_lock_irq(&intfdata->susp_lock); |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 861 | for (i = 0; i < serial->num_ports; i++) { |
| 862 | /* walk all ports */ |
| 863 | port = serial->port[i]; |
| 864 | portdata = usb_get_serial_port_data(port); |
| 865 | |
| 866 | /* skip closed ports */ |
xiao jin | 50476ee | 2014-05-26 19:23:14 +0200 | [diff] [blame] | 867 | if (!portdata || !portdata->opened) |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 868 | continue; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 869 | |
Johan Hovold | 0886f4e | 2014-05-26 19:23:17 +0200 | [diff] [blame] | 870 | if (port->interrupt_in_urb) { |
| 871 | err = usb_submit_urb(port->interrupt_in_urb, |
| 872 | GFP_ATOMIC); |
| 873 | if (err) { |
| 874 | dev_err(&port->dev, |
| 875 | "%s: submit int urb failed: %d\n", |
| 876 | __func__, err); |
Johan Hovold | 9e91351 | 2014-05-26 19:23:18 +0200 | [diff] [blame] | 877 | err_count++; |
Johan Hovold | 0886f4e | 2014-05-26 19:23:17 +0200 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | |
Johan Hovold | 9e91351 | 2014-05-26 19:23:18 +0200 | [diff] [blame] | 881 | err = play_delayed(port); |
| 882 | if (err) |
| 883 | err_count++; |
| 884 | |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 885 | for (j = 0; j < N_IN_URB; j++) { |
| 886 | urb = portdata->in_urbs[j]; |
| 887 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 888 | if (err < 0) { |
| 889 | err("%s: Error %d for bulk URB %d", |
| 890 | __func__, err, i); |
Johan Hovold | 9e91351 | 2014-05-26 19:23:18 +0200 | [diff] [blame] | 891 | err_count++; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 892 | } |
| 893 | } |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 894 | } |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 895 | intfdata->suspended = 0; |
Hemant Kumar | 1ffb039 | 2012-06-14 16:00:24 -0700 | [diff] [blame] | 896 | spin_unlock_irq(&intfdata->susp_lock); |
| 897 | |
Johan Hovold | 9e91351 | 2014-05-26 19:23:18 +0200 | [diff] [blame] | 898 | if (err_count) |
| 899 | return -EIO; |
| 900 | |
| 901 | return 0; |
Matthew Garrett | 0d45619 | 2010-04-01 12:31:07 -0400 | [diff] [blame] | 902 | } |
| 903 | EXPORT_SYMBOL(usb_wwan_resume); |
| 904 | #endif |
| 905 | |
| 906 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 907 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 908 | MODULE_VERSION(DRIVER_VERSION); |
| 909 | MODULE_LICENSE("GPL"); |
| 910 | |
| 911 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 912 | MODULE_PARM_DESC(debug, "Debug messages"); |