usb_wwan.c 18 KB

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