option.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. Option Card (PCMCIA to) USB to Serial Driver
  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:
  9. 2005-05-19 v0.1 Initial version, based on incomplete docs
  10. and analysis of misbehavior with the standard driver
  11. 2005-05-20 v0.2 Extended the input buffer to avoid losing
  12. random 64-byte chunks of data
  13. 2005-05-21 v0.3 implemented chars_in_buffer()
  14. turned on low_latency
  15. simplified the code somewhat
  16. 2005-05-24 v0.4 option_write() sometimes deadlocked under heavy load
  17. removed some dead code
  18. added sponsor notice
  19. coding style clean-up
  20. 2005-06-20 v0.4.1 add missing braces :-/
  21. killed end-of-line whitespace
  22. 2005-07-15 v0.4.2 rename WLAN product to FUSION, add FUSION2
  23. 2005-09-10 v0.4.3 added HUAWEI E600 card and Audiovox AirCard
  24. 2005-09-20 v0.4.4 increased recv buffer size: the card sometimes
  25. wants to send >2000 bytes.
  26. Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
  27. */
  28. #define DRIVER_VERSION "v0.4"
  29. #define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
  30. #define DRIVER_DESC "Option Card (PC-Card to) USB to Serial Driver"
  31. #include <linux/config.h>
  32. #include <linux/kernel.h>
  33. #include <linux/jiffies.h>
  34. #include <linux/errno.h>
  35. #include <linux/tty.h>
  36. #include <linux/tty_flip.h>
  37. #include <linux/module.h>
  38. #include <linux/usb.h>
  39. #include "usb-serial.h"
  40. /* Function prototypes */
  41. static int option_open(struct usb_serial_port *port, struct file *filp);
  42. static void option_close(struct usb_serial_port *port, struct file *filp);
  43. static int option_startup(struct usb_serial *serial);
  44. static void option_shutdown(struct usb_serial *serial);
  45. static void option_rx_throttle(struct usb_serial_port *port);
  46. static void option_rx_unthrottle(struct usb_serial_port *port);
  47. static int option_write_room(struct usb_serial_port *port);
  48. static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
  49. static int option_write(struct usb_serial_port *port,
  50. const unsigned char *buf, int count);
  51. static int option_chars_in_buffer(struct usb_serial_port *port);
  52. static int option_ioctl(struct usb_serial_port *port, struct file *file,
  53. unsigned int cmd, unsigned long arg);
  54. static void option_set_termios(struct usb_serial_port *port,
  55. struct termios *old);
  56. static void option_break_ctl(struct usb_serial_port *port, int break_state);
  57. static int option_tiocmget(struct usb_serial_port *port, struct file *file);
  58. static int option_tiocmset(struct usb_serial_port *port, struct file *file,
  59. unsigned int set, unsigned int clear);
  60. static int option_send_setup(struct usb_serial_port *port);
  61. /* Vendor and product IDs */
  62. #define OPTION_VENDOR_ID 0x0AF0
  63. #define HUAWEI_VENDOR_ID 0x12D1
  64. #define AUDIOVOX_VENDOR_ID 0x0F3D
  65. #define OPTION_PRODUCT_OLD 0x5000
  66. #define OPTION_PRODUCT_FUSION 0x6000
  67. #define OPTION_PRODUCT_FUSION2 0x6300
  68. #define HUAWEI_PRODUCT_E600 0x1001
  69. #define AUDIOVOX_PRODUCT_AIRCARD 0x0112
  70. static struct usb_device_id option_ids[] = {
  71. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
  72. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
  73. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
  74. { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
  75. { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
  76. { } /* Terminating entry */
  77. };
  78. MODULE_DEVICE_TABLE(usb, option_ids);
  79. static struct usb_driver option_driver = {
  80. .name = "option",
  81. .probe = usb_serial_probe,
  82. .disconnect = usb_serial_disconnect,
  83. .id_table = option_ids,
  84. .no_dynamic_id = 1,
  85. };
  86. /* The card has three separate interfaces, wich the serial driver
  87. * recognizes separately, thus num_port=1.
  88. */
  89. static struct usb_serial_driver option_3port_device = {
  90. .driver = {
  91. .owner = THIS_MODULE,
  92. .name = "option",
  93. },
  94. .description = "Option 3G data card",
  95. .id_table = option_ids,
  96. .num_interrupt_in = NUM_DONT_CARE,
  97. .num_bulk_in = NUM_DONT_CARE,
  98. .num_bulk_out = NUM_DONT_CARE,
  99. .num_ports = 1, /* 3, but the card reports its ports separately */
  100. .open = option_open,
  101. .close = option_close,
  102. .write = option_write,
  103. .write_room = option_write_room,
  104. .chars_in_buffer = option_chars_in_buffer,
  105. .throttle = option_rx_throttle,
  106. .unthrottle = option_rx_unthrottle,
  107. .ioctl = option_ioctl,
  108. .set_termios = option_set_termios,
  109. .break_ctl = option_break_ctl,
  110. .tiocmget = option_tiocmget,
  111. .tiocmset = option_tiocmset,
  112. .attach = option_startup,
  113. .shutdown = option_shutdown,
  114. .read_int_callback = option_instat_callback,
  115. };
  116. #ifdef CONFIG_USB_DEBUG
  117. static int debug;
  118. #else
  119. #define debug 0
  120. #endif
  121. /* per port private data */
  122. #define N_IN_URB 4
  123. #define N_OUT_URB 1
  124. #define IN_BUFLEN 4096
  125. #define OUT_BUFLEN 128
  126. struct option_port_private {
  127. /* Input endpoints and buffer for this port */
  128. struct urb *in_urbs[N_IN_URB];
  129. char in_buffer[N_IN_URB][IN_BUFLEN];
  130. /* Output endpoints and buffer for this port */
  131. struct urb *out_urbs[N_OUT_URB];
  132. char out_buffer[N_OUT_URB][OUT_BUFLEN];
  133. /* Settings for the port */
  134. int rts_state; /* Handshaking pins (outputs) */
  135. int dtr_state;
  136. int cts_state; /* Handshaking pins (inputs) */
  137. int dsr_state;
  138. int dcd_state;
  139. int ri_state;
  140. unsigned long tx_start_time[N_OUT_URB];
  141. };
  142. /* Functions used by new usb-serial code. */
  143. static int __init option_init(void)
  144. {
  145. int retval;
  146. retval = usb_serial_register(&option_3port_device);
  147. if (retval)
  148. goto failed_3port_device_register;
  149. retval = usb_register(&option_driver);
  150. if (retval)
  151. goto failed_driver_register;
  152. info(DRIVER_DESC ": " DRIVER_VERSION);
  153. return 0;
  154. failed_driver_register:
  155. usb_serial_deregister (&option_3port_device);
  156. failed_3port_device_register:
  157. return retval;
  158. }
  159. static void __exit option_exit(void)
  160. {
  161. usb_deregister (&option_driver);
  162. usb_serial_deregister (&option_3port_device);
  163. }
  164. module_init(option_init);
  165. module_exit(option_exit);
  166. static void option_rx_throttle(struct usb_serial_port *port)
  167. {
  168. dbg("%s", __FUNCTION__);
  169. }
  170. static void option_rx_unthrottle(struct usb_serial_port *port)
  171. {
  172. dbg("%s", __FUNCTION__);
  173. }
  174. static void option_break_ctl(struct usb_serial_port *port, int break_state)
  175. {
  176. /* Unfortunately, I don't know how to send a break */
  177. dbg("%s", __FUNCTION__);
  178. }
  179. static void option_set_termios(struct usb_serial_port *port,
  180. struct termios *old_termios)
  181. {
  182. dbg("%s", __FUNCTION__);
  183. option_send_setup(port);
  184. }
  185. static int option_tiocmget(struct usb_serial_port *port, struct file *file)
  186. {
  187. unsigned int value;
  188. struct option_port_private *portdata;
  189. portdata = usb_get_serial_port_data(port);
  190. value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
  191. ((portdata->dtr_state) ? TIOCM_DTR : 0) |
  192. ((portdata->cts_state) ? TIOCM_CTS : 0) |
  193. ((portdata->dsr_state) ? TIOCM_DSR : 0) |
  194. ((portdata->dcd_state) ? TIOCM_CAR : 0) |
  195. ((portdata->ri_state) ? TIOCM_RNG : 0);
  196. return value;
  197. }
  198. static int option_tiocmset(struct usb_serial_port *port, struct file *file,
  199. unsigned int set, unsigned int clear)
  200. {
  201. struct option_port_private *portdata;
  202. portdata = usb_get_serial_port_data(port);
  203. if (set & TIOCM_RTS)
  204. portdata->rts_state = 1;
  205. if (set & TIOCM_DTR)
  206. portdata->dtr_state = 1;
  207. if (clear & TIOCM_RTS)
  208. portdata->rts_state = 0;
  209. if (clear & TIOCM_DTR)
  210. portdata->dtr_state = 0;
  211. return option_send_setup(port);
  212. }
  213. static int option_ioctl(struct usb_serial_port *port, struct file *file,
  214. unsigned int cmd, unsigned long arg)
  215. {
  216. return -ENOIOCTLCMD;
  217. }
  218. /* Write */
  219. static int option_write(struct usb_serial_port *port,
  220. const unsigned char *buf, int count)
  221. {
  222. struct option_port_private *portdata;
  223. int i;
  224. int left, todo;
  225. struct urb *this_urb = NULL; /* spurious */
  226. int err;
  227. portdata = usb_get_serial_port_data(port);
  228. dbg("%s: write (%d chars)", __FUNCTION__, count);
  229. i = 0;
  230. left = count;
  231. for (i=0; left > 0 && i < N_OUT_URB; i++) {
  232. todo = left;
  233. if (todo > OUT_BUFLEN)
  234. todo = OUT_BUFLEN;
  235. this_urb = portdata->out_urbs[i];
  236. if (this_urb->status == -EINPROGRESS) {
  237. if (time_before(jiffies,
  238. portdata->tx_start_time[i] + 10 * HZ))
  239. continue;
  240. usb_unlink_urb(this_urb);
  241. continue;
  242. }
  243. if (this_urb->status != 0)
  244. dbg("usb_write %p failed (err=%d)",
  245. this_urb, this_urb->status);
  246. dbg("%s: endpoint %d buf %d", __FUNCTION__,
  247. usb_pipeendpoint(this_urb->pipe), i);
  248. /* send the data */
  249. memcpy (this_urb->transfer_buffer, buf, todo);
  250. this_urb->transfer_buffer_length = todo;
  251. this_urb->dev = port->serial->dev;
  252. err = usb_submit_urb(this_urb, GFP_ATOMIC);
  253. if (err) {
  254. dbg("usb_submit_urb %p (write bulk) failed "
  255. "(%d, has %d)", this_urb,
  256. err, this_urb->status);
  257. continue;
  258. }
  259. portdata->tx_start_time[i] = jiffies;
  260. buf += todo;
  261. left -= todo;
  262. }
  263. count -= left;
  264. dbg("%s: wrote (did %d)", __FUNCTION__, count);
  265. return count;
  266. }
  267. static void option_indat_callback(struct urb *urb, struct pt_regs *regs)
  268. {
  269. int err;
  270. int endpoint;
  271. struct usb_serial_port *port;
  272. struct tty_struct *tty;
  273. unsigned char *data = urb->transfer_buffer;
  274. dbg("%s: %p", __FUNCTION__, urb);
  275. endpoint = usb_pipeendpoint(urb->pipe);
  276. port = (struct usb_serial_port *) urb->context;
  277. if (urb->status) {
  278. dbg("%s: nonzero status: %d on endpoint %02x.",
  279. __FUNCTION__, urb->status, endpoint);
  280. } else {
  281. tty = port->tty;
  282. if (urb->actual_length) {
  283. tty_buffer_request_room(tty, urb->actual_length);
  284. tty_insert_flip_string(tty, data, urb->actual_length);
  285. tty_flip_buffer_push(tty);
  286. } else {
  287. dbg("%s: empty read urb received", __FUNCTION__);
  288. }
  289. /* Resubmit urb so we continue receiving */
  290. if (port->open_count && urb->status != -ESHUTDOWN) {
  291. err = usb_submit_urb(urb, GFP_ATOMIC);
  292. if (err)
  293. printk(KERN_ERR "%s: resubmit read urb failed. "
  294. "(%d)", __FUNCTION__, err);
  295. }
  296. }
  297. return;
  298. }
  299. static void option_outdat_callback(struct urb *urb, struct pt_regs *regs)
  300. {
  301. struct usb_serial_port *port;
  302. dbg("%s", __FUNCTION__);
  303. port = (struct usb_serial_port *) urb->context;
  304. if (port->open_count)
  305. schedule_work(&port->work);
  306. }
  307. static void option_instat_callback(struct urb *urb, struct pt_regs *regs)
  308. {
  309. int err;
  310. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  311. struct option_port_private *portdata = usb_get_serial_port_data(port);
  312. struct usb_serial *serial = port->serial;
  313. dbg("%s", __FUNCTION__);
  314. dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
  315. if (urb->status == 0) {
  316. struct usb_ctrlrequest *req_pkt =
  317. (struct usb_ctrlrequest *)urb->transfer_buffer;
  318. if (!req_pkt) {
  319. dbg("%s: NULL req_pkt\n", __FUNCTION__);
  320. return;
  321. }
  322. if ((req_pkt->bRequestType == 0xA1) &&
  323. (req_pkt->bRequest == 0x20)) {
  324. int old_dcd_state;
  325. unsigned char signals = *((unsigned char *)
  326. urb->transfer_buffer +
  327. sizeof(struct usb_ctrlrequest));
  328. dbg("%s: signal x%x", __FUNCTION__, signals);
  329. old_dcd_state = portdata->dcd_state;
  330. portdata->cts_state = 1;
  331. portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
  332. portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
  333. portdata->ri_state = ((signals & 0x08) ? 1 : 0);
  334. if (port->tty && !C_CLOCAL(port->tty) &&
  335. old_dcd_state && !portdata->dcd_state)
  336. tty_hangup(port->tty);
  337. } else {
  338. dbg("%s: type %x req %x", __FUNCTION__,
  339. req_pkt->bRequestType,req_pkt->bRequest);
  340. }
  341. } else
  342. dbg("%s: error %d", __FUNCTION__, urb->status);
  343. /* Resubmit urb so we continue receiving IRQ data */
  344. if (urb->status != -ESHUTDOWN) {
  345. urb->dev = serial->dev;
  346. err = usb_submit_urb(urb, GFP_ATOMIC);
  347. if (err)
  348. dbg("%s: resubmit intr urb failed. (%d)",
  349. __FUNCTION__, err);
  350. }
  351. }
  352. static int option_write_room(struct usb_serial_port *port)
  353. {
  354. struct option_port_private *portdata;
  355. int i;
  356. int data_len = 0;
  357. struct urb *this_urb;
  358. portdata = usb_get_serial_port_data(port);
  359. for (i=0; i < N_OUT_URB; i++) {
  360. this_urb = portdata->out_urbs[i];
  361. if (this_urb && this_urb->status != -EINPROGRESS)
  362. data_len += OUT_BUFLEN;
  363. }
  364. dbg("%s: %d", __FUNCTION__, data_len);
  365. return data_len;
  366. }
  367. static int option_chars_in_buffer(struct usb_serial_port *port)
  368. {
  369. struct option_port_private *portdata;
  370. int i;
  371. int data_len = 0;
  372. struct urb *this_urb;
  373. portdata = usb_get_serial_port_data(port);
  374. for (i=0; i < N_OUT_URB; i++) {
  375. this_urb = portdata->out_urbs[i];
  376. if (this_urb && this_urb->status == -EINPROGRESS)
  377. data_len += this_urb->transfer_buffer_length;
  378. }
  379. dbg("%s: %d", __FUNCTION__, data_len);
  380. return data_len;
  381. }
  382. static int option_open(struct usb_serial_port *port, struct file *filp)
  383. {
  384. struct option_port_private *portdata;
  385. struct usb_serial *serial = port->serial;
  386. int i, err;
  387. struct urb *urb;
  388. portdata = usb_get_serial_port_data(port);
  389. dbg("%s", __FUNCTION__);
  390. /* Set some sane defaults */
  391. portdata->rts_state = 1;
  392. portdata->dtr_state = 1;
  393. /* Reset low level data toggle and start reading from endpoints */
  394. for (i = 0; i < N_IN_URB; i++) {
  395. urb = portdata->in_urbs[i];
  396. if (! urb)
  397. continue;
  398. if (urb->dev != serial->dev) {
  399. dbg("%s: dev %p != %p", __FUNCTION__,
  400. urb->dev, serial->dev);
  401. continue;
  402. }
  403. /*
  404. * make sure endpoint data toggle is synchronized with the
  405. * device
  406. */
  407. usb_clear_halt(urb->dev, urb->pipe);
  408. err = usb_submit_urb(urb, GFP_KERNEL);
  409. if (err) {
  410. dbg("%s: submit urb %d failed (%d) %d",
  411. __FUNCTION__, i, err,
  412. urb->transfer_buffer_length);
  413. }
  414. }
  415. /* Reset low level data toggle on out endpoints */
  416. for (i = 0; i < N_OUT_URB; i++) {
  417. urb = portdata->out_urbs[i];
  418. if (! urb)
  419. continue;
  420. urb->dev = serial->dev;
  421. /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
  422. usb_pipeout(urb->pipe), 0); */
  423. }
  424. port->tty->low_latency = 1;
  425. option_send_setup(port);
  426. return (0);
  427. }
  428. static inline void stop_urb(struct urb *urb)
  429. {
  430. if (urb && urb->status == -EINPROGRESS)
  431. usb_kill_urb(urb);
  432. }
  433. static void option_close(struct usb_serial_port *port, struct file *filp)
  434. {
  435. int i;
  436. struct usb_serial *serial = port->serial;
  437. struct option_port_private *portdata;
  438. dbg("%s", __FUNCTION__);
  439. portdata = usb_get_serial_port_data(port);
  440. portdata->rts_state = 0;
  441. portdata->dtr_state = 0;
  442. if (serial->dev) {
  443. option_send_setup(port);
  444. /* Stop reading/writing urbs */
  445. for (i = 0; i < N_IN_URB; i++)
  446. stop_urb(portdata->in_urbs[i]);
  447. for (i = 0; i < N_OUT_URB; i++)
  448. stop_urb(portdata->out_urbs[i]);
  449. }
  450. port->tty = NULL;
  451. }
  452. /* Helper functions used by option_setup_urbs */
  453. static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
  454. int dir, void *ctx, char *buf, int len,
  455. void (*callback)(struct urb *, struct pt_regs *regs))
  456. {
  457. struct urb *urb;
  458. if (endpoint == -1)
  459. return NULL; /* endpoint not needed */
  460. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  461. if (urb == NULL) {
  462. dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
  463. return NULL;
  464. }
  465. /* Fill URB using supplied data. */
  466. usb_fill_bulk_urb(urb, serial->dev,
  467. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  468. buf, len, callback, ctx);
  469. return urb;
  470. }
  471. /* Setup urbs */
  472. static void option_setup_urbs(struct usb_serial *serial)
  473. {
  474. int j;
  475. struct usb_serial_port *port;
  476. struct option_port_private *portdata;
  477. dbg("%s", __FUNCTION__);
  478. port = serial->port[0];
  479. portdata = usb_get_serial_port_data(port);
  480. /* Do indat endpoints first */
  481. for (j = 0; j <= N_IN_URB; ++j) {
  482. portdata->in_urbs[j] = option_setup_urb (serial,
  483. port->bulk_in_endpointAddress, USB_DIR_IN, port,
  484. portdata->in_buffer[j], IN_BUFLEN, option_indat_callback);
  485. }
  486. /* outdat endpoints */
  487. for (j = 0; j <= N_OUT_URB; ++j) {
  488. portdata->out_urbs[j] = option_setup_urb (serial,
  489. port->bulk_out_endpointAddress, USB_DIR_OUT, port,
  490. portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback);
  491. }
  492. }
  493. static int option_send_setup(struct usb_serial_port *port)
  494. {
  495. struct usb_serial *serial = port->serial;
  496. struct option_port_private *portdata;
  497. dbg("%s", __FUNCTION__);
  498. portdata = usb_get_serial_port_data(port);
  499. if (port->tty) {
  500. int val = 0;
  501. if (portdata->dtr_state)
  502. val |= 0x01;
  503. if (portdata->rts_state)
  504. val |= 0x02;
  505. return usb_control_msg(serial->dev,
  506. usb_rcvctrlpipe(serial->dev, 0),
  507. 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
  508. }
  509. return 0;
  510. }
  511. static int option_startup(struct usb_serial *serial)
  512. {
  513. int i, err;
  514. struct usb_serial_port *port;
  515. struct option_port_private *portdata;
  516. dbg("%s", __FUNCTION__);
  517. /* Now setup per port private data */
  518. for (i = 0; i < serial->num_ports; i++) {
  519. port = serial->port[i];
  520. portdata = kmalloc(sizeof(*portdata), GFP_KERNEL);
  521. if (!portdata) {
  522. dbg("%s: kmalloc for option_port_private (%d) failed!.",
  523. __FUNCTION__, i);
  524. return (1);
  525. }
  526. memset(portdata, 0, sizeof(struct option_port_private));
  527. usb_set_serial_port_data(port, portdata);
  528. if (! port->interrupt_in_urb)
  529. continue;
  530. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  531. if (err)
  532. dbg("%s: submit irq_in urb failed %d",
  533. __FUNCTION__, err);
  534. }
  535. option_setup_urbs(serial);
  536. return (0);
  537. }
  538. static void option_shutdown(struct usb_serial *serial)
  539. {
  540. int i, j;
  541. struct usb_serial_port *port;
  542. struct option_port_private *portdata;
  543. dbg("%s", __FUNCTION__);
  544. /* Stop reading/writing urbs */
  545. for (i = 0; i < serial->num_ports; ++i) {
  546. port = serial->port[i];
  547. portdata = usb_get_serial_port_data(port);
  548. for (j = 0; j < N_IN_URB; j++)
  549. stop_urb(portdata->in_urbs[j]);
  550. for (j = 0; j < N_OUT_URB; j++)
  551. stop_urb(portdata->out_urbs[j]);
  552. }
  553. /* Now free them */
  554. for (i = 0; i < serial->num_ports; ++i) {
  555. port = serial->port[i];
  556. portdata = usb_get_serial_port_data(port);
  557. for (j = 0; j < N_IN_URB; j++) {
  558. if (portdata->in_urbs[j]) {
  559. usb_free_urb(portdata->in_urbs[j]);
  560. portdata->in_urbs[j] = NULL;
  561. }
  562. }
  563. for (j = 0; j < N_OUT_URB; j++) {
  564. if (portdata->out_urbs[j]) {
  565. usb_free_urb(portdata->out_urbs[j]);
  566. portdata->out_urbs[j] = NULL;
  567. }
  568. }
  569. }
  570. /* Now free per port private data */
  571. for (i = 0; i < serial->num_ports; i++) {
  572. port = serial->port[i];
  573. kfree(usb_get_serial_port_data(port));
  574. }
  575. }
  576. MODULE_AUTHOR(DRIVER_AUTHOR);
  577. MODULE_DESCRIPTION(DRIVER_DESC);
  578. MODULE_VERSION(DRIVER_VERSION);
  579. MODULE_LICENSE("GPL");
  580. #ifdef CONFIG_USB_DEBUG
  581. module_param(debug, bool, S_IRUGO | S_IWUSR);
  582. MODULE_PARM_DESC(debug, "Debug messages");
  583. #endif