usb_wwan.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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->serial->minor;
  100. tmp.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. /* Resubmit urb so we continue receiving */
  242. err = usb_submit_urb(urb, GFP_ATOMIC);
  243. if (err) {
  244. if (err != -EPERM) {
  245. dev_err(dev, "%s: resubmit read urb failed. (%d)\n", __func__, err);
  246. /* busy also in error unless we are killed */
  247. usb_mark_last_busy(port->serial->dev);
  248. }
  249. } else {
  250. usb_mark_last_busy(port->serial->dev);
  251. }
  252. }
  253. }
  254. static void usb_wwan_outdat_callback(struct urb *urb)
  255. {
  256. struct usb_serial_port *port;
  257. struct usb_wwan_port_private *portdata;
  258. struct usb_wwan_intf_private *intfdata;
  259. int i;
  260. port = urb->context;
  261. intfdata = port->serial->private;
  262. usb_serial_port_softint(port);
  263. usb_autopm_put_interface_async(port->serial->interface);
  264. portdata = usb_get_serial_port_data(port);
  265. spin_lock(&intfdata->susp_lock);
  266. intfdata->in_flight--;
  267. spin_unlock(&intfdata->susp_lock);
  268. for (i = 0; i < N_OUT_URB; ++i) {
  269. if (portdata->out_urbs[i] == urb) {
  270. smp_mb__before_clear_bit();
  271. clear_bit(i, &portdata->out_busy);
  272. break;
  273. }
  274. }
  275. }
  276. int usb_wwan_write_room(struct tty_struct *tty)
  277. {
  278. struct usb_serial_port *port = tty->driver_data;
  279. struct usb_wwan_port_private *portdata;
  280. int i;
  281. int data_len = 0;
  282. struct urb *this_urb;
  283. portdata = usb_get_serial_port_data(port);
  284. for (i = 0; i < N_OUT_URB; i++) {
  285. this_urb = portdata->out_urbs[i];
  286. if (this_urb && !test_bit(i, &portdata->out_busy))
  287. data_len += OUT_BUFLEN;
  288. }
  289. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  290. return data_len;
  291. }
  292. EXPORT_SYMBOL(usb_wwan_write_room);
  293. int usb_wwan_chars_in_buffer(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. /* FIXME: This locking is insufficient as this_urb may
  304. go unused during the test */
  305. if (this_urb && test_bit(i, &portdata->out_busy))
  306. data_len += this_urb->transfer_buffer_length;
  307. }
  308. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  309. return data_len;
  310. }
  311. EXPORT_SYMBOL(usb_wwan_chars_in_buffer);
  312. int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
  313. {
  314. struct usb_wwan_port_private *portdata;
  315. struct usb_wwan_intf_private *intfdata;
  316. struct usb_serial *serial = port->serial;
  317. int i, err;
  318. struct urb *urb;
  319. portdata = usb_get_serial_port_data(port);
  320. intfdata = serial->private;
  321. /* Start reading from the IN endpoint */
  322. for (i = 0; i < N_IN_URB; i++) {
  323. urb = portdata->in_urbs[i];
  324. if (!urb)
  325. continue;
  326. err = usb_submit_urb(urb, GFP_KERNEL);
  327. if (err) {
  328. dev_dbg(&port->dev, "%s: submit urb %d failed (%d) %d\n",
  329. __func__, i, err, urb->transfer_buffer_length);
  330. }
  331. }
  332. if (intfdata->send_setup)
  333. intfdata->send_setup(port);
  334. serial->interface->needs_remote_wakeup = 1;
  335. spin_lock_irq(&intfdata->susp_lock);
  336. portdata->opened = 1;
  337. spin_unlock_irq(&intfdata->susp_lock);
  338. /* this balances a get in the generic USB serial code */
  339. usb_autopm_put_interface(serial->interface);
  340. return 0;
  341. }
  342. EXPORT_SYMBOL(usb_wwan_open);
  343. void usb_wwan_close(struct usb_serial_port *port)
  344. {
  345. int i;
  346. struct usb_serial *serial = port->serial;
  347. struct usb_wwan_port_private *portdata;
  348. struct usb_wwan_intf_private *intfdata = port->serial->private;
  349. portdata = usb_get_serial_port_data(port);
  350. if (serial->dev) {
  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. }
  364. EXPORT_SYMBOL(usb_wwan_close);
  365. /* Helper functions used by usb_wwan_setup_urbs */
  366. static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
  367. int endpoint,
  368. int dir, void *ctx, char *buf, int len,
  369. void (*callback) (struct urb *))
  370. {
  371. struct usb_serial *serial = port->serial;
  372. struct urb *urb;
  373. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  374. if (urb == NULL) {
  375. dev_dbg(&serial->interface->dev,
  376. "%s: alloc for endpoint %d failed.\n", __func__,
  377. endpoint);
  378. return NULL;
  379. }
  380. /* Fill URB using supplied data. */
  381. usb_fill_bulk_urb(urb, serial->dev,
  382. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  383. buf, len, callback, ctx);
  384. return urb;
  385. }
  386. int usb_wwan_port_probe(struct usb_serial_port *port)
  387. {
  388. struct usb_wwan_port_private *portdata;
  389. struct urb *urb;
  390. u8 *buffer;
  391. int err;
  392. int i;
  393. portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
  394. if (!portdata)
  395. return -ENOMEM;
  396. init_usb_anchor(&portdata->delayed);
  397. for (i = 0; i < N_IN_URB; i++) {
  398. if (!port->bulk_in_size)
  399. break;
  400. buffer = (u8 *)__get_free_page(GFP_KERNEL);
  401. if (!buffer)
  402. goto bail_out_error;
  403. portdata->in_buffer[i] = buffer;
  404. urb = usb_wwan_setup_urb(port, port->bulk_in_endpointAddress,
  405. USB_DIR_IN, port,
  406. buffer, IN_BUFLEN,
  407. usb_wwan_indat_callback);
  408. portdata->in_urbs[i] = urb;
  409. }
  410. for (i = 0; i < N_OUT_URB; i++) {
  411. if (!port->bulk_out_size)
  412. break;
  413. buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL);
  414. if (!buffer)
  415. goto bail_out_error2;
  416. portdata->out_buffer[i] = buffer;
  417. urb = usb_wwan_setup_urb(port, port->bulk_out_endpointAddress,
  418. USB_DIR_OUT, port,
  419. buffer, OUT_BUFLEN,
  420. usb_wwan_outdat_callback);
  421. portdata->out_urbs[i] = urb;
  422. }
  423. usb_set_serial_port_data(port, portdata);
  424. if (port->interrupt_in_urb) {
  425. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  426. if (err)
  427. dev_dbg(&port->dev, "%s: submit irq_in urb failed %d\n",
  428. __func__, err);
  429. }
  430. return 0;
  431. bail_out_error2:
  432. for (i = 0; i < N_OUT_URB; i++) {
  433. usb_free_urb(portdata->out_urbs[i]);
  434. kfree(portdata->out_buffer[i]);
  435. }
  436. bail_out_error:
  437. for (i = 0; i < N_IN_URB; i++) {
  438. usb_free_urb(portdata->in_urbs[i]);
  439. free_page((unsigned long)portdata->in_buffer[i]);
  440. }
  441. kfree(portdata);
  442. return -ENOMEM;
  443. }
  444. EXPORT_SYMBOL_GPL(usb_wwan_port_probe);
  445. int usb_wwan_port_remove(struct usb_serial_port *port)
  446. {
  447. int i;
  448. struct usb_wwan_port_private *portdata;
  449. portdata = usb_get_serial_port_data(port);
  450. usb_set_serial_port_data(port, NULL);
  451. /* Stop reading/writing urbs and free them */
  452. for (i = 0; i < N_IN_URB; i++) {
  453. usb_kill_urb(portdata->in_urbs[i]);
  454. usb_free_urb(portdata->in_urbs[i]);
  455. free_page((unsigned long)portdata->in_buffer[i]);
  456. }
  457. for (i = 0; i < N_OUT_URB; i++) {
  458. usb_kill_urb(portdata->out_urbs[i]);
  459. usb_free_urb(portdata->out_urbs[i]);
  460. kfree(portdata->out_buffer[i]);
  461. }
  462. /* Now free port private data */
  463. kfree(portdata);
  464. return 0;
  465. }
  466. EXPORT_SYMBOL(usb_wwan_port_remove);
  467. #ifdef CONFIG_PM
  468. static void stop_read_write_urbs(struct usb_serial *serial)
  469. {
  470. int i, j;
  471. struct usb_serial_port *port;
  472. struct usb_wwan_port_private *portdata;
  473. /* Stop reading/writing urbs */
  474. for (i = 0; i < serial->num_ports; ++i) {
  475. port = serial->port[i];
  476. portdata = usb_get_serial_port_data(port);
  477. if (!portdata)
  478. continue;
  479. for (j = 0; j < N_IN_URB; j++)
  480. usb_kill_urb(portdata->in_urbs[j]);
  481. for (j = 0; j < N_OUT_URB; j++)
  482. usb_kill_urb(portdata->out_urbs[j]);
  483. }
  484. }
  485. int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
  486. {
  487. struct usb_wwan_intf_private *intfdata = serial->private;
  488. int b;
  489. if (PMSG_IS_AUTO(message)) {
  490. spin_lock_irq(&intfdata->susp_lock);
  491. b = intfdata->in_flight;
  492. spin_unlock_irq(&intfdata->susp_lock);
  493. if (b)
  494. return -EBUSY;
  495. }
  496. spin_lock_irq(&intfdata->susp_lock);
  497. intfdata->suspended = 1;
  498. spin_unlock_irq(&intfdata->susp_lock);
  499. stop_read_write_urbs(serial);
  500. return 0;
  501. }
  502. EXPORT_SYMBOL(usb_wwan_suspend);
  503. static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata)
  504. {
  505. int i;
  506. for (i = 0; i < N_OUT_URB; i++) {
  507. if (urb == portdata->out_urbs[i]) {
  508. clear_bit(i, &portdata->out_busy);
  509. break;
  510. }
  511. }
  512. }
  513. static void play_delayed(struct usb_serial_port *port)
  514. {
  515. struct usb_wwan_intf_private *data;
  516. struct usb_wwan_port_private *portdata;
  517. struct urb *urb;
  518. int err;
  519. portdata = usb_get_serial_port_data(port);
  520. data = port->serial->private;
  521. while ((urb = usb_get_from_anchor(&portdata->delayed))) {
  522. err = usb_submit_urb(urb, GFP_ATOMIC);
  523. if (!err) {
  524. data->in_flight++;
  525. } else {
  526. /* we have to throw away the rest */
  527. do {
  528. unbusy_queued_urb(urb, portdata);
  529. usb_autopm_put_interface_no_suspend(port->serial->interface);
  530. } while ((urb = usb_get_from_anchor(&portdata->delayed)));
  531. break;
  532. }
  533. }
  534. }
  535. int usb_wwan_resume(struct usb_serial *serial)
  536. {
  537. int i, j;
  538. struct usb_serial_port *port;
  539. struct usb_wwan_intf_private *intfdata = serial->private;
  540. struct usb_wwan_port_private *portdata;
  541. struct urb *urb;
  542. int err = 0;
  543. /* get the interrupt URBs resubmitted unconditionally */
  544. for (i = 0; i < serial->num_ports; i++) {
  545. port = serial->port[i];
  546. if (!port->interrupt_in_urb) {
  547. dev_dbg(&port->dev, "%s: No interrupt URB for port\n", __func__);
  548. continue;
  549. }
  550. err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
  551. dev_dbg(&port->dev, "Submitted interrupt URB for port (result %d)\n", err);
  552. if (err < 0) {
  553. dev_err(&port->dev, "%s: Error %d for interrupt URB\n",
  554. __func__, err);
  555. goto err_out;
  556. }
  557. }
  558. for (i = 0; i < serial->num_ports; i++) {
  559. /* walk all ports */
  560. port = serial->port[i];
  561. portdata = usb_get_serial_port_data(port);
  562. /* skip closed ports */
  563. spin_lock_irq(&intfdata->susp_lock);
  564. if (!portdata || !portdata->opened) {
  565. spin_unlock_irq(&intfdata->susp_lock);
  566. continue;
  567. }
  568. for (j = 0; j < N_IN_URB; j++) {
  569. urb = portdata->in_urbs[j];
  570. err = usb_submit_urb(urb, GFP_ATOMIC);
  571. if (err < 0) {
  572. dev_err(&port->dev, "%s: Error %d for bulk URB %d\n",
  573. __func__, err, i);
  574. spin_unlock_irq(&intfdata->susp_lock);
  575. goto err_out;
  576. }
  577. }
  578. play_delayed(port);
  579. spin_unlock_irq(&intfdata->susp_lock);
  580. }
  581. spin_lock_irq(&intfdata->susp_lock);
  582. intfdata->suspended = 0;
  583. spin_unlock_irq(&intfdata->susp_lock);
  584. err_out:
  585. return err;
  586. }
  587. EXPORT_SYMBOL(usb_wwan_resume);
  588. #endif
  589. MODULE_AUTHOR(DRIVER_AUTHOR);
  590. MODULE_DESCRIPTION(DRIVER_DESC);
  591. MODULE_LICENSE("GPL");