usb_wwan.c 18 KB

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