usb_wwan.c 17 KB

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