usb_wwan.c 18 KB

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