generic.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * USB Serial Converter Generic functions
  4. *
  5. * Copyright (C) 2010 - 2013 Johan Hovold (jhovold@gmail.com)
  6. * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/sched/signal.h>
  10. #include <linux/errno.h>
  11. #include <linux/slab.h>
  12. #include <linux/sysrq.h>
  13. #include <linux/tty.h>
  14. #include <linux/tty_flip.h>
  15. #include <linux/module.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/usb.h>
  18. #include <linux/usb/serial.h>
  19. #include <linux/uaccess.h>
  20. #include <linux/kfifo.h>
  21. #include <linux/serial.h>
  22. #ifdef CONFIG_USB_SERIAL_GENERIC
  23. static __u16 vendor = 0x05f9;
  24. static __u16 product = 0xffff;
  25. module_param(vendor, ushort, 0);
  26. MODULE_PARM_DESC(vendor, "User specified USB idVendor");
  27. module_param(product, ushort, 0);
  28. MODULE_PARM_DESC(product, "User specified USB idProduct");
  29. static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */
  30. static int usb_serial_generic_probe(struct usb_serial *serial,
  31. const struct usb_device_id *id)
  32. {
  33. struct device *dev = &serial->interface->dev;
  34. dev_info(dev, "The \"generic\" usb-serial driver is only for testing and one-off prototypes.\n");
  35. dev_info(dev, "Tell linux-usb@vger.kernel.org to add your device to a proper driver.\n");
  36. return 0;
  37. }
  38. static int usb_serial_generic_calc_num_ports(struct usb_serial *serial,
  39. struct usb_serial_endpoints *epds)
  40. {
  41. struct device *dev = &serial->interface->dev;
  42. int num_ports;
  43. num_ports = max(epds->num_bulk_in, epds->num_bulk_out);
  44. if (num_ports == 0) {
  45. dev_err(dev, "device has no bulk endpoints\n");
  46. return -ENODEV;
  47. }
  48. return num_ports;
  49. }
  50. static struct usb_serial_driver usb_serial_generic_device = {
  51. .driver = {
  52. .owner = THIS_MODULE,
  53. .name = "generic",
  54. },
  55. .id_table = generic_device_ids,
  56. .probe = usb_serial_generic_probe,
  57. .calc_num_ports = usb_serial_generic_calc_num_ports,
  58. .throttle = usb_serial_generic_throttle,
  59. .unthrottle = usb_serial_generic_unthrottle,
  60. .resume = usb_serial_generic_resume,
  61. };
  62. static struct usb_serial_driver * const serial_drivers[] = {
  63. &usb_serial_generic_device, NULL
  64. };
  65. #endif
  66. int usb_serial_generic_register(void)
  67. {
  68. int retval = 0;
  69. #ifdef CONFIG_USB_SERIAL_GENERIC
  70. generic_device_ids[0].idVendor = vendor;
  71. generic_device_ids[0].idProduct = product;
  72. generic_device_ids[0].match_flags =
  73. USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
  74. retval = usb_serial_register_drivers(serial_drivers,
  75. "usbserial_generic", generic_device_ids);
  76. #endif
  77. return retval;
  78. }
  79. void usb_serial_generic_deregister(void)
  80. {
  81. #ifdef CONFIG_USB_SERIAL_GENERIC
  82. usb_serial_deregister_drivers(serial_drivers);
  83. #endif
  84. }
  85. int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port)
  86. {
  87. int result = 0;
  88. unsigned long flags;
  89. spin_lock_irqsave(&port->lock, flags);
  90. port->throttled = 0;
  91. port->throttle_req = 0;
  92. spin_unlock_irqrestore(&port->lock, flags);
  93. if (port->bulk_in_size)
  94. result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
  95. return result;
  96. }
  97. EXPORT_SYMBOL_GPL(usb_serial_generic_open);
  98. void usb_serial_generic_close(struct usb_serial_port *port)
  99. {
  100. unsigned long flags;
  101. int i;
  102. if (port->bulk_out_size) {
  103. for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
  104. usb_kill_urb(port->write_urbs[i]);
  105. spin_lock_irqsave(&port->lock, flags);
  106. kfifo_reset_out(&port->write_fifo);
  107. spin_unlock_irqrestore(&port->lock, flags);
  108. }
  109. if (port->bulk_in_size) {
  110. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
  111. usb_kill_urb(port->read_urbs[i]);
  112. }
  113. }
  114. EXPORT_SYMBOL_GPL(usb_serial_generic_close);
  115. int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
  116. void *dest, size_t size)
  117. {
  118. return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock);
  119. }
  120. /**
  121. * usb_serial_generic_write_start - start writing buffered data
  122. * @port: usb-serial port
  123. * @mem_flags: flags to use for memory allocations
  124. *
  125. * Serialised using USB_SERIAL_WRITE_BUSY flag.
  126. *
  127. * Return: Zero on success or if busy, otherwise a negative errno value.
  128. */
  129. int usb_serial_generic_write_start(struct usb_serial_port *port,
  130. gfp_t mem_flags)
  131. {
  132. struct urb *urb;
  133. int count, result;
  134. unsigned long flags;
  135. int i;
  136. if (test_and_set_bit_lock(USB_SERIAL_WRITE_BUSY, &port->flags))
  137. return 0;
  138. retry:
  139. spin_lock_irqsave(&port->lock, flags);
  140. if (!port->write_urbs_free || !kfifo_len(&port->write_fifo)) {
  141. clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
  142. spin_unlock_irqrestore(&port->lock, flags);
  143. return 0;
  144. }
  145. i = (int)find_first_bit(&port->write_urbs_free,
  146. ARRAY_SIZE(port->write_urbs));
  147. spin_unlock_irqrestore(&port->lock, flags);
  148. urb = port->write_urbs[i];
  149. count = port->serial->type->prepare_write_buffer(port,
  150. urb->transfer_buffer,
  151. port->bulk_out_size);
  152. urb->transfer_buffer_length = count;
  153. usb_serial_debug_data(&port->dev, __func__, count, urb->transfer_buffer);
  154. spin_lock_irqsave(&port->lock, flags);
  155. port->tx_bytes += count;
  156. spin_unlock_irqrestore(&port->lock, flags);
  157. clear_bit(i, &port->write_urbs_free);
  158. result = usb_submit_urb(urb, mem_flags);
  159. if (result) {
  160. dev_err_console(port, "%s - error submitting urb: %d\n",
  161. __func__, result);
  162. set_bit(i, &port->write_urbs_free);
  163. spin_lock_irqsave(&port->lock, flags);
  164. port->tx_bytes -= count;
  165. spin_unlock_irqrestore(&port->lock, flags);
  166. clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
  167. return result;
  168. }
  169. goto retry; /* try sending off another urb */
  170. }
  171. EXPORT_SYMBOL_GPL(usb_serial_generic_write_start);
  172. /**
  173. * usb_serial_generic_write - generic write function
  174. * @tty: tty for the port
  175. * @port: usb-serial port
  176. * @buf: data to write
  177. * @count: number of bytes to write
  178. *
  179. * Return: The number of characters buffered, which may be anything from
  180. * zero to @count, or a negative errno value.
  181. */
  182. int usb_serial_generic_write(struct tty_struct *tty,
  183. struct usb_serial_port *port, const unsigned char *buf, int count)
  184. {
  185. int result;
  186. if (!port->bulk_out_size)
  187. return -ENODEV;
  188. if (!count)
  189. return 0;
  190. count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
  191. result = usb_serial_generic_write_start(port, GFP_ATOMIC);
  192. if (result)
  193. return result;
  194. return count;
  195. }
  196. EXPORT_SYMBOL_GPL(usb_serial_generic_write);
  197. int usb_serial_generic_write_room(struct tty_struct *tty)
  198. {
  199. struct usb_serial_port *port = tty->driver_data;
  200. unsigned long flags;
  201. int room;
  202. if (!port->bulk_out_size)
  203. return 0;
  204. spin_lock_irqsave(&port->lock, flags);
  205. room = kfifo_avail(&port->write_fifo);
  206. spin_unlock_irqrestore(&port->lock, flags);
  207. dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
  208. return room;
  209. }
  210. int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
  211. {
  212. struct usb_serial_port *port = tty->driver_data;
  213. unsigned long flags;
  214. int chars;
  215. if (!port->bulk_out_size)
  216. return 0;
  217. spin_lock_irqsave(&port->lock, flags);
  218. chars = kfifo_len(&port->write_fifo) + port->tx_bytes;
  219. spin_unlock_irqrestore(&port->lock, flags);
  220. dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
  221. return chars;
  222. }
  223. EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer);
  224. void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout)
  225. {
  226. struct usb_serial_port *port = tty->driver_data;
  227. unsigned int bps;
  228. unsigned long period;
  229. unsigned long expire;
  230. bps = tty_get_baud_rate(tty);
  231. if (!bps)
  232. bps = 9600; /* B0 */
  233. /*
  234. * Use a poll-period of roughly the time it takes to send one
  235. * character or at least one jiffy.
  236. */
  237. period = max_t(unsigned long, (10 * HZ / bps), 1);
  238. if (timeout)
  239. period = min_t(unsigned long, period, timeout);
  240. dev_dbg(&port->dev, "%s - timeout = %u ms, period = %u ms\n",
  241. __func__, jiffies_to_msecs(timeout),
  242. jiffies_to_msecs(period));
  243. expire = jiffies + timeout;
  244. while (!port->serial->type->tx_empty(port)) {
  245. schedule_timeout_interruptible(period);
  246. if (signal_pending(current))
  247. break;
  248. if (timeout && time_after(jiffies, expire))
  249. break;
  250. }
  251. }
  252. EXPORT_SYMBOL_GPL(usb_serial_generic_wait_until_sent);
  253. static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
  254. int index, gfp_t mem_flags)
  255. {
  256. int res;
  257. if (!test_and_clear_bit(index, &port->read_urbs_free))
  258. return 0;
  259. dev_dbg(&port->dev, "%s - urb %d\n", __func__, index);
  260. res = usb_submit_urb(port->read_urbs[index], mem_flags);
  261. if (res) {
  262. if (res != -EPERM && res != -ENODEV) {
  263. dev_err(&port->dev,
  264. "%s - usb_submit_urb failed: %d\n",
  265. __func__, res);
  266. }
  267. set_bit(index, &port->read_urbs_free);
  268. return res;
  269. }
  270. return 0;
  271. }
  272. int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port,
  273. gfp_t mem_flags)
  274. {
  275. int res;
  276. int i;
  277. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
  278. res = usb_serial_generic_submit_read_urb(port, i, mem_flags);
  279. if (res)
  280. goto err;
  281. }
  282. return 0;
  283. err:
  284. for (; i >= 0; --i)
  285. usb_kill_urb(port->read_urbs[i]);
  286. return res;
  287. }
  288. EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urbs);
  289. void usb_serial_generic_process_read_urb(struct urb *urb)
  290. {
  291. struct usb_serial_port *port = urb->context;
  292. char *ch = (char *)urb->transfer_buffer;
  293. int i;
  294. if (!urb->actual_length)
  295. return;
  296. /*
  297. * The per character mucking around with sysrq path it too slow for
  298. * stuff like 3G modems, so shortcircuit it in the 99.9999999% of
  299. * cases where the USB serial is not a console anyway.
  300. */
  301. if (!port->port.console || !port->sysrq) {
  302. tty_insert_flip_string(&port->port, ch, urb->actual_length);
  303. } else {
  304. for (i = 0; i < urb->actual_length; i++, ch++) {
  305. if (!usb_serial_handle_sysrq_char(port, *ch))
  306. tty_insert_flip_char(&port->port, *ch, TTY_NORMAL);
  307. }
  308. }
  309. tty_flip_buffer_push(&port->port);
  310. }
  311. EXPORT_SYMBOL_GPL(usb_serial_generic_process_read_urb);
  312. void usb_serial_generic_read_bulk_callback(struct urb *urb)
  313. {
  314. struct usb_serial_port *port = urb->context;
  315. unsigned char *data = urb->transfer_buffer;
  316. unsigned long flags;
  317. bool stopped = false;
  318. int status = urb->status;
  319. int i;
  320. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
  321. if (urb == port->read_urbs[i])
  322. break;
  323. }
  324. dev_dbg(&port->dev, "%s - urb %d, len %d\n", __func__, i,
  325. urb->actual_length);
  326. switch (status) {
  327. case 0:
  328. usb_serial_debug_data(&port->dev, __func__, urb->actual_length,
  329. data);
  330. port->serial->type->process_read_urb(urb);
  331. break;
  332. case -ENOENT:
  333. case -ECONNRESET:
  334. case -ESHUTDOWN:
  335. dev_dbg(&port->dev, "%s - urb stopped: %d\n",
  336. __func__, status);
  337. stopped = true;
  338. break;
  339. case -EPIPE:
  340. dev_err(&port->dev, "%s - urb stopped: %d\n",
  341. __func__, status);
  342. stopped = true;
  343. break;
  344. default:
  345. dev_dbg(&port->dev, "%s - nonzero urb status: %d\n",
  346. __func__, status);
  347. break;
  348. }
  349. /*
  350. * Make sure URB processing is done before marking as free to avoid
  351. * racing with unthrottle() on another CPU. Matches the barriers
  352. * implied by the test_and_clear_bit() in
  353. * usb_serial_generic_submit_read_urb().
  354. */
  355. smp_mb__before_atomic();
  356. set_bit(i, &port->read_urbs_free);
  357. /*
  358. * Make sure URB is marked as free before checking the throttled flag
  359. * to avoid racing with unthrottle() on another CPU. Matches the
  360. * smp_mb() in unthrottle().
  361. */
  362. smp_mb__after_atomic();
  363. if (stopped)
  364. return;
  365. /* Throttle the device if requested by tty */
  366. spin_lock_irqsave(&port->lock, flags);
  367. port->throttled = port->throttle_req;
  368. if (!port->throttled) {
  369. spin_unlock_irqrestore(&port->lock, flags);
  370. usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
  371. } else {
  372. spin_unlock_irqrestore(&port->lock, flags);
  373. }
  374. }
  375. EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
  376. void usb_serial_generic_write_bulk_callback(struct urb *urb)
  377. {
  378. unsigned long flags;
  379. struct usb_serial_port *port = urb->context;
  380. int status = urb->status;
  381. int i;
  382. for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) {
  383. if (port->write_urbs[i] == urb)
  384. break;
  385. }
  386. spin_lock_irqsave(&port->lock, flags);
  387. port->tx_bytes -= urb->transfer_buffer_length;
  388. set_bit(i, &port->write_urbs_free);
  389. spin_unlock_irqrestore(&port->lock, flags);
  390. switch (status) {
  391. case 0:
  392. break;
  393. case -ENOENT:
  394. case -ECONNRESET:
  395. case -ESHUTDOWN:
  396. dev_dbg(&port->dev, "%s - urb stopped: %d\n",
  397. __func__, status);
  398. return;
  399. case -EPIPE:
  400. dev_err_console(port, "%s - urb stopped: %d\n",
  401. __func__, status);
  402. return;
  403. default:
  404. dev_err_console(port, "%s - nonzero urb status: %d\n",
  405. __func__, status);
  406. goto resubmit;
  407. }
  408. resubmit:
  409. usb_serial_generic_write_start(port, GFP_ATOMIC);
  410. usb_serial_port_softint(port);
  411. }
  412. EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
  413. void usb_serial_generic_throttle(struct tty_struct *tty)
  414. {
  415. struct usb_serial_port *port = tty->driver_data;
  416. unsigned long flags;
  417. spin_lock_irqsave(&port->lock, flags);
  418. port->throttle_req = 1;
  419. spin_unlock_irqrestore(&port->lock, flags);
  420. }
  421. EXPORT_SYMBOL_GPL(usb_serial_generic_throttle);
  422. void usb_serial_generic_unthrottle(struct tty_struct *tty)
  423. {
  424. struct usb_serial_port *port = tty->driver_data;
  425. int was_throttled;
  426. spin_lock_irq(&port->lock);
  427. was_throttled = port->throttled;
  428. port->throttled = port->throttle_req = 0;
  429. spin_unlock_irq(&port->lock);
  430. /*
  431. * Matches the smp_mb__after_atomic() in
  432. * usb_serial_generic_read_bulk_callback().
  433. */
  434. smp_mb();
  435. if (was_throttled)
  436. usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
  437. }
  438. EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle);
  439. static bool usb_serial_generic_msr_changed(struct tty_struct *tty,
  440. unsigned long arg, struct async_icount *cprev)
  441. {
  442. struct usb_serial_port *port = tty->driver_data;
  443. struct async_icount cnow;
  444. unsigned long flags;
  445. bool ret;
  446. /*
  447. * Use tty-port initialised flag to detect all hangups including the
  448. * one generated at USB-device disconnect.
  449. */
  450. if (!tty_port_initialized(&port->port))
  451. return true;
  452. spin_lock_irqsave(&port->lock, flags);
  453. cnow = port->icount; /* atomic copy*/
  454. spin_unlock_irqrestore(&port->lock, flags);
  455. ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
  456. ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
  457. ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
  458. ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
  459. *cprev = cnow;
  460. return ret;
  461. }
  462. int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg)
  463. {
  464. struct usb_serial_port *port = tty->driver_data;
  465. struct async_icount cnow;
  466. unsigned long flags;
  467. int ret;
  468. spin_lock_irqsave(&port->lock, flags);
  469. cnow = port->icount; /* atomic copy */
  470. spin_unlock_irqrestore(&port->lock, flags);
  471. ret = wait_event_interruptible(port->port.delta_msr_wait,
  472. usb_serial_generic_msr_changed(tty, arg, &cnow));
  473. if (!ret && !tty_port_initialized(&port->port))
  474. ret = -EIO;
  475. return ret;
  476. }
  477. EXPORT_SYMBOL_GPL(usb_serial_generic_tiocmiwait);
  478. int usb_serial_generic_get_icount(struct tty_struct *tty,
  479. struct serial_icounter_struct *icount)
  480. {
  481. struct usb_serial_port *port = tty->driver_data;
  482. struct async_icount cnow;
  483. unsigned long flags;
  484. spin_lock_irqsave(&port->lock, flags);
  485. cnow = port->icount; /* atomic copy */
  486. spin_unlock_irqrestore(&port->lock, flags);
  487. icount->cts = cnow.cts;
  488. icount->dsr = cnow.dsr;
  489. icount->rng = cnow.rng;
  490. icount->dcd = cnow.dcd;
  491. icount->tx = cnow.tx;
  492. icount->rx = cnow.rx;
  493. icount->frame = cnow.frame;
  494. icount->parity = cnow.parity;
  495. icount->overrun = cnow.overrun;
  496. icount->brk = cnow.brk;
  497. icount->buf_overrun = cnow.buf_overrun;
  498. return 0;
  499. }
  500. EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
  501. #ifdef CONFIG_MAGIC_SYSRQ
  502. int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
  503. {
  504. if (port->sysrq && port->port.console) {
  505. if (ch && time_before(jiffies, port->sysrq)) {
  506. handle_sysrq(ch);
  507. port->sysrq = 0;
  508. return 1;
  509. }
  510. port->sysrq = 0;
  511. }
  512. return 0;
  513. }
  514. #else
  515. int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
  516. {
  517. return 0;
  518. }
  519. #endif
  520. EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
  521. int usb_serial_handle_break(struct usb_serial_port *port)
  522. {
  523. if (!port->sysrq) {
  524. port->sysrq = jiffies + HZ*5;
  525. return 1;
  526. }
  527. port->sysrq = 0;
  528. return 0;
  529. }
  530. EXPORT_SYMBOL_GPL(usb_serial_handle_break);
  531. /**
  532. * usb_serial_handle_dcd_change - handle a change of carrier detect state
  533. * @port: usb-serial port
  534. * @tty: tty for the port
  535. * @status: new carrier detect status, nonzero if active
  536. */
  537. void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
  538. struct tty_struct *tty, unsigned int status)
  539. {
  540. struct tty_port *port = &usb_port->port;
  541. dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status);
  542. if (tty) {
  543. struct tty_ldisc *ld = tty_ldisc_ref(tty);
  544. if (ld) {
  545. if (ld->ops->dcd_change)
  546. ld->ops->dcd_change(tty, status);
  547. tty_ldisc_deref(ld);
  548. }
  549. }
  550. if (status)
  551. wake_up_interruptible(&port->open_wait);
  552. else if (tty && !C_CLOCAL(tty))
  553. tty_hangup(tty);
  554. }
  555. EXPORT_SYMBOL_GPL(usb_serial_handle_dcd_change);
  556. int usb_serial_generic_resume(struct usb_serial *serial)
  557. {
  558. struct usb_serial_port *port;
  559. int i, c = 0, r;
  560. for (i = 0; i < serial->num_ports; i++) {
  561. port = serial->port[i];
  562. if (!tty_port_initialized(&port->port))
  563. continue;
  564. if (port->bulk_in_size) {
  565. r = usb_serial_generic_submit_read_urbs(port,
  566. GFP_NOIO);
  567. if (r < 0)
  568. c++;
  569. }
  570. if (port->bulk_out_size) {
  571. r = usb_serial_generic_write_start(port, GFP_NOIO);
  572. if (r < 0)
  573. c++;
  574. }
  575. }
  576. return c ? -EIO : 0;
  577. }
  578. EXPORT_SYMBOL_GPL(usb_serial_generic_resume);