usb_wwan.c 18 KB

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