usb_wwan.c 18 KB

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