option.c 18 KB

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