PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/irda/irda-usb.c

http://github.com/mirrors/linux
C | 1913 lines | 1043 code | 237 blank | 633 comment | 213 complexity | e604f5500a6e0295bf13fbb75a2bb5ed MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /*****************************************************************************
  2. *
  3. * Filename: irda-usb.c
  4. * Version: 0.10
  5. * Description: IrDA-USB Driver
  6. * Status: Experimental
  7. * Author: Dag Brattli <dag@brattli.net>
  8. *
  9. * Copyright (C) 2000, Roman Weissgaerber <weissg@vienna.at>
  10. * Copyright (C) 2001, Dag Brattli <dag@brattli.net>
  11. * Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com>
  12. * Copyright (C) 2004, SigmaTel, Inc. <irquality@sigmatel.com>
  13. * Copyright (C) 2005, Milan Beno <beno@pobox.sk>
  14. * Copyright (C) 2006, Nick Fedchik <nick@fedchik.org.ua>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. *
  30. *****************************************************************************/
  31. /*
  32. * IMPORTANT NOTE
  33. * --------------
  34. *
  35. * As of kernel 2.5.20, this is the state of compliance and testing of
  36. * this driver (irda-usb) with regards to the USB low level drivers...
  37. *
  38. * This driver has been tested SUCCESSFULLY with the following drivers :
  39. * o usb-uhci-hcd (For Intel/Via USB controllers)
  40. * o uhci-hcd (Alternate/JE driver for Intel/Via USB controllers)
  41. * o ohci-hcd (For other USB controllers)
  42. *
  43. * This driver has NOT been tested with the following drivers :
  44. * o ehci-hcd (USB 2.0 controllers)
  45. *
  46. * Note that all HCD drivers do URB_ZERO_PACKET and timeout properly,
  47. * so we don't have to worry about that anymore.
  48. * One common problem is the failure to set the address on the dongle,
  49. * but this happens before the driver gets loaded...
  50. *
  51. * Jean II
  52. */
  53. /*------------------------------------------------------------------*/
  54. #include <linux/module.h>
  55. #include <linux/moduleparam.h>
  56. #include <linux/kernel.h>
  57. #include <linux/types.h>
  58. #include <linux/skbuff.h>
  59. #include <linux/netdevice.h>
  60. #include <linux/slab.h>
  61. #include <linux/rtnetlink.h>
  62. #include <linux/usb.h>
  63. #include <linux/firmware.h>
  64. #include "irda-usb.h"
  65. /*------------------------------------------------------------------*/
  66. static int qos_mtt_bits = 0;
  67. /* These are the currently known IrDA USB dongles. Add new dongles here */
  68. static struct usb_device_id dongles[] = {
  69. /* ACTiSYS Corp., ACT-IR2000U FIR-USB Adapter */
  70. { USB_DEVICE(0x9c4, 0x011), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
  71. /* Look like ACTiSYS, Report : IBM Corp., IBM UltraPort IrDA */
  72. { USB_DEVICE(0x4428, 0x012), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
  73. /* KC Technology Inc., KC-180 USB IrDA Device */
  74. { USB_DEVICE(0x50f, 0x180), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
  75. /* Extended Systems, Inc., XTNDAccess IrDA USB (ESI-9685) */
  76. { USB_DEVICE(0x8e9, 0x100), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
  77. /* SigmaTel STIR4210/4220/4116 USB IrDA (VFIR) Bridge */
  78. { USB_DEVICE(0x66f, 0x4210), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
  79. { USB_DEVICE(0x66f, 0x4220), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
  80. { USB_DEVICE(0x66f, 0x4116), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
  81. { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
  82. USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  83. .bInterfaceClass = USB_CLASS_APP_SPEC,
  84. .bInterfaceSubClass = USB_CLASS_IRDA,
  85. .driver_info = IUC_DEFAULT, },
  86. { }, /* The end */
  87. };
  88. /*
  89. * Important note :
  90. * Devices based on the SigmaTel chipset (0x66f, 0x4200) are not designed
  91. * using the "USB-IrDA specification" (yes, there exist such a thing), and
  92. * therefore not supported by this driver (don't add them above).
  93. * There is a Linux driver, stir4200, that support those USB devices.
  94. * Jean II
  95. */
  96. MODULE_DEVICE_TABLE(usb, dongles);
  97. /*------------------------------------------------------------------*/
  98. static void irda_usb_init_qos(struct irda_usb_cb *self) ;
  99. static struct irda_class_desc *irda_usb_find_class_desc(struct usb_interface *intf);
  100. static void irda_usb_disconnect(struct usb_interface *intf);
  101. static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self);
  102. static netdev_tx_t irda_usb_hard_xmit(struct sk_buff *skb,
  103. struct net_device *dev);
  104. static int irda_usb_open(struct irda_usb_cb *self);
  105. static void irda_usb_close(struct irda_usb_cb *self);
  106. static void speed_bulk_callback(struct urb *urb);
  107. static void write_bulk_callback(struct urb *urb);
  108. static void irda_usb_receive(struct urb *urb);
  109. static void irda_usb_rx_defer_expired(unsigned long data);
  110. static int irda_usb_net_open(struct net_device *dev);
  111. static int irda_usb_net_close(struct net_device *dev);
  112. static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  113. static void irda_usb_net_timeout(struct net_device *dev);
  114. /************************ TRANSMIT ROUTINES ************************/
  115. /*
  116. * Receive packets from the IrDA stack and send them on the USB pipe.
  117. * Handle speed change, timeout and lot's of ugliness...
  118. */
  119. /*------------------------------------------------------------------*/
  120. /*
  121. * Function irda_usb_build_header(self, skb, header)
  122. *
  123. * Builds USB-IrDA outbound header
  124. *
  125. * When we send an IrDA frame over an USB pipe, we add to it a 1 byte
  126. * header. This function create this header with the proper values.
  127. *
  128. * Important note : the USB-IrDA spec 1.0 say very clearly in chapter 5.4.2.2
  129. * that the setting of the link speed and xbof number in this outbound header
  130. * should be applied *AFTER* the frame has been sent.
  131. * Unfortunately, some devices are not compliant with that... It seems that
  132. * reading the spec is far too difficult...
  133. * Jean II
  134. */
  135. static void irda_usb_build_header(struct irda_usb_cb *self,
  136. __u8 *header,
  137. int force)
  138. {
  139. /* Here we check if we have an STIR421x chip,
  140. * and if either speed or xbofs (or both) needs
  141. * to be changed.
  142. */
  143. if (self->capability & IUC_STIR421X &&
  144. ((self->new_speed != -1) || (self->new_xbofs != -1))) {
  145. /* With STIR421x, speed and xBOFs must be set at the same
  146. * time, even if only one of them changes.
  147. */
  148. if (self->new_speed == -1)
  149. self->new_speed = self->speed ;
  150. if (self->new_xbofs == -1)
  151. self->new_xbofs = self->xbofs ;
  152. }
  153. /* Set the link speed */
  154. if (self->new_speed != -1) {
  155. /* Hum... Ugly hack :-(
  156. * Some device are not compliant with the spec and change
  157. * parameters *before* sending the frame. - Jean II
  158. */
  159. if ((self->capability & IUC_SPEED_BUG) &&
  160. (!force) && (self->speed != -1)) {
  161. /* No speed and xbofs change here
  162. * (we'll do it later in the write callback) */
  163. pr_debug("%s(), not changing speed yet\n", __func__);
  164. *header = 0;
  165. return;
  166. }
  167. pr_debug("%s(), changing speed to %d\n",
  168. __func__, self->new_speed);
  169. self->speed = self->new_speed;
  170. /* We will do ` self->new_speed = -1; ' in the completion
  171. * handler just in case the current URB fail - Jean II */
  172. switch (self->speed) {
  173. case 2400:
  174. *header = SPEED_2400;
  175. break;
  176. default:
  177. case 9600:
  178. *header = SPEED_9600;
  179. break;
  180. case 19200:
  181. *header = SPEED_19200;
  182. break;
  183. case 38400:
  184. *header = SPEED_38400;
  185. break;
  186. case 57600:
  187. *header = SPEED_57600;
  188. break;
  189. case 115200:
  190. *header = SPEED_115200;
  191. break;
  192. case 576000:
  193. *header = SPEED_576000;
  194. break;
  195. case 1152000:
  196. *header = SPEED_1152000;
  197. break;
  198. case 4000000:
  199. *header = SPEED_4000000;
  200. self->new_xbofs = 0;
  201. break;
  202. case 16000000:
  203. *header = SPEED_16000000;
  204. self->new_xbofs = 0;
  205. break;
  206. }
  207. } else
  208. /* No change */
  209. *header = 0;
  210. /* Set the negotiated additional XBOFS */
  211. if (self->new_xbofs != -1) {
  212. pr_debug("%s(), changing xbofs to %d\n",
  213. __func__, self->new_xbofs);
  214. self->xbofs = self->new_xbofs;
  215. /* We will do ` self->new_xbofs = -1; ' in the completion
  216. * handler just in case the current URB fail - Jean II */
  217. switch (self->xbofs) {
  218. case 48:
  219. *header |= 0x10;
  220. break;
  221. case 28:
  222. case 24: /* USB spec 1.0 says 24 */
  223. *header |= 0x20;
  224. break;
  225. default:
  226. case 12:
  227. *header |= 0x30;
  228. break;
  229. case 5: /* Bug in IrLAP spec? (should be 6) */
  230. case 6:
  231. *header |= 0x40;
  232. break;
  233. case 3:
  234. *header |= 0x50;
  235. break;
  236. case 2:
  237. *header |= 0x60;
  238. break;
  239. case 1:
  240. *header |= 0x70;
  241. break;
  242. case 0:
  243. *header |= 0x80;
  244. break;
  245. }
  246. }
  247. }
  248. /*
  249. * calculate turnaround time for SigmaTel header
  250. */
  251. static __u8 get_turnaround_time(struct sk_buff *skb)
  252. {
  253. int turnaround_time = irda_get_mtt(skb);
  254. if ( turnaround_time == 0 )
  255. return 0;
  256. else if ( turnaround_time <= 10 )
  257. return 1;
  258. else if ( turnaround_time <= 50 )
  259. return 2;
  260. else if ( turnaround_time <= 100 )
  261. return 3;
  262. else if ( turnaround_time <= 500 )
  263. return 4;
  264. else if ( turnaround_time <= 1000 )
  265. return 5;
  266. else if ( turnaround_time <= 5000 )
  267. return 6;
  268. else
  269. return 7;
  270. }
  271. /*------------------------------------------------------------------*/
  272. /*
  273. * Send a command to change the speed of the dongle
  274. * Need to be called with spinlock on.
  275. */
  276. static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
  277. {
  278. __u8 *frame;
  279. struct urb *urb;
  280. int ret;
  281. pr_debug("%s(), speed=%d, xbofs=%d\n", __func__,
  282. self->new_speed, self->new_xbofs);
  283. /* Grab the speed URB */
  284. urb = self->speed_urb;
  285. if (urb->status != 0) {
  286. net_warn_ratelimited("%s(), URB still in use!\n", __func__);
  287. return;
  288. }
  289. /* Allocate the fake frame */
  290. frame = self->speed_buff;
  291. /* Set the new speed and xbofs in this fake frame */
  292. irda_usb_build_header(self, frame, 1);
  293. if (self->capability & IUC_STIR421X) {
  294. if (frame[0] == 0) return ; // do nothing if no change
  295. frame[1] = 0; // other parameters don't change here
  296. frame[2] = 0;
  297. }
  298. /* Submit the 0 length IrDA frame to trigger new speed settings */
  299. usb_fill_bulk_urb(urb, self->usbdev,
  300. usb_sndbulkpipe(self->usbdev, self->bulk_out_ep),
  301. frame, IRDA_USB_SPEED_MTU,
  302. speed_bulk_callback, self);
  303. urb->transfer_buffer_length = self->header_length;
  304. urb->transfer_flags = 0;
  305. /* Irq disabled -> GFP_ATOMIC */
  306. if ((ret = usb_submit_urb(urb, GFP_ATOMIC))) {
  307. net_warn_ratelimited("%s(), failed Speed URB\n", __func__);
  308. }
  309. }
  310. /*------------------------------------------------------------------*/
  311. /*
  312. * Speed URB callback
  313. * Now, we can only get called for the speed URB.
  314. */
  315. static void speed_bulk_callback(struct urb *urb)
  316. {
  317. struct irda_usb_cb *self = urb->context;
  318. /* We should always have a context */
  319. IRDA_ASSERT(self != NULL, return;);
  320. /* We should always be called for the speed URB */
  321. IRDA_ASSERT(urb == self->speed_urb, return;);
  322. /* Check for timeout and other USB nasties */
  323. if (urb->status != 0) {
  324. /* I get a lot of -ECONNABORTED = -103 here - Jean II */
  325. pr_debug("%s(), URB complete status %d, transfer_flags 0x%04X\n",
  326. __func__, urb->status, urb->transfer_flags);
  327. /* Don't do anything here, that might confuse the USB layer.
  328. * Instead, we will wait for irda_usb_net_timeout(), the
  329. * network layer watchdog, to fix the situation.
  330. * Jean II */
  331. /* A reset of the dongle might be welcomed here - Jean II */
  332. return;
  333. }
  334. /* urb is now available */
  335. //urb->status = 0; -> tested above
  336. /* New speed and xbof is now committed in hardware */
  337. self->new_speed = -1;
  338. self->new_xbofs = -1;
  339. /* Allow the stack to send more packets */
  340. netif_wake_queue(self->netdev);
  341. }
  342. /*------------------------------------------------------------------*/
  343. /*
  344. * Send an IrDA frame to the USB dongle (for transmission)
  345. */
  346. static netdev_tx_t irda_usb_hard_xmit(struct sk_buff *skb,
  347. struct net_device *netdev)
  348. {
  349. struct irda_usb_cb *self = netdev_priv(netdev);
  350. struct urb *urb = self->tx_urb;
  351. unsigned long flags;
  352. s32 speed;
  353. s16 xbofs;
  354. int res, mtt;
  355. pr_debug("%s() on %s\n", __func__, netdev->name);
  356. netif_stop_queue(netdev);
  357. /* Protect us from USB callbacks, net watchdog and else. */
  358. spin_lock_irqsave(&self->lock, flags);
  359. /* Check if the device is still there.
  360. * We need to check self->present under the spinlock because
  361. * of irda_usb_disconnect() is synchronous - Jean II */
  362. if (!self->present) {
  363. pr_debug("%s(), Device is gone...\n", __func__);
  364. goto drop;
  365. }
  366. /* Check if we need to change the number of xbofs */
  367. xbofs = irda_get_next_xbofs(skb);
  368. if ((xbofs != self->xbofs) && (xbofs != -1)) {
  369. self->new_xbofs = xbofs;
  370. }
  371. /* Check if we need to change the speed */
  372. speed = irda_get_next_speed(skb);
  373. if ((speed != self->speed) && (speed != -1)) {
  374. /* Set the desired speed */
  375. self->new_speed = speed;
  376. /* Check for empty frame */
  377. if (!skb->len) {
  378. /* IrLAP send us an empty frame to make us change the
  379. * speed. Changing speed with the USB adapter is in
  380. * fact sending an empty frame to the adapter, so we
  381. * could just let the present function do its job.
  382. * However, we would wait for min turn time,
  383. * do an extra memcpy and increment packet counters...
  384. * Jean II */
  385. irda_usb_change_speed_xbofs(self);
  386. netif_trans_update(netdev);
  387. /* Will netif_wake_queue() in callback */
  388. goto drop;
  389. }
  390. }
  391. if (urb->status != 0) {
  392. net_warn_ratelimited("%s(), URB still in use!\n", __func__);
  393. goto drop;
  394. }
  395. skb_copy_from_linear_data(skb, self->tx_buff + self->header_length, skb->len);
  396. /* Change setting for next frame */
  397. if (self->capability & IUC_STIR421X) {
  398. __u8 turnaround_time;
  399. __u8* frame = self->tx_buff;
  400. turnaround_time = get_turnaround_time( skb );
  401. irda_usb_build_header(self, frame, 0);
  402. frame[2] = turnaround_time;
  403. if ((skb->len != 0) &&
  404. ((skb->len % 128) == 0) &&
  405. ((skb->len % 512) != 0)) {
  406. /* add extra byte for special SigmaTel feature */
  407. frame[1] = 1;
  408. skb_put(skb, 1);
  409. } else {
  410. frame[1] = 0;
  411. }
  412. } else {
  413. irda_usb_build_header(self, self->tx_buff, 0);
  414. }
  415. /* FIXME: Make macro out of this one */
  416. ((struct irda_skb_cb *)skb->cb)->context = self;
  417. usb_fill_bulk_urb(urb, self->usbdev,
  418. usb_sndbulkpipe(self->usbdev, self->bulk_out_ep),
  419. self->tx_buff, skb->len + self->header_length,
  420. write_bulk_callback, skb);
  421. /* This flag (URB_ZERO_PACKET) indicates that what we send is not
  422. * a continuous stream of data but separate packets.
  423. * In this case, the USB layer will insert an empty USB frame (TD)
  424. * after each of our packets that is exact multiple of the frame size.
  425. * This is how the dongle will detect the end of packet - Jean II */
  426. urb->transfer_flags = URB_ZERO_PACKET;
  427. /* Generate min turn time. FIXME: can we do better than this? */
  428. /* Trying to a turnaround time at this level is trying to measure
  429. * processor clock cycle with a wrist-watch, approximate at best...
  430. *
  431. * What we know is the last time we received a frame over USB.
  432. * Due to latency over USB that depend on the USB load, we don't
  433. * know when this frame was received over IrDA (a few ms before ?)
  434. * Then, same story for our outgoing frame...
  435. *
  436. * In theory, the USB dongle is supposed to handle the turnaround
  437. * by itself (spec 1.0, chater 4, page 6). Who knows ??? That's
  438. * why this code is enabled only for dongles that doesn't meet
  439. * the spec.
  440. * Jean II */
  441. if (self->capability & IUC_NO_TURN) {
  442. mtt = irda_get_mtt(skb);
  443. if (mtt) {
  444. int diff;
  445. diff = ktime_us_delta(ktime_get(), self->stamp);
  446. #ifdef IU_USB_MIN_RTT
  447. /* Factor in USB delays -> Get rid of udelay() that
  448. * would be lost in the noise - Jean II */
  449. diff += IU_USB_MIN_RTT;
  450. #endif /* IU_USB_MIN_RTT */
  451. /* Check if the mtt is larger than the time we have
  452. * already used by all the protocol processing
  453. */
  454. if (mtt > diff) {
  455. mtt -= diff;
  456. if (mtt > 1000)
  457. mdelay(mtt/1000);
  458. else
  459. udelay(mtt);
  460. }
  461. }
  462. }
  463. /* Ask USB to send the packet - Irq disabled -> GFP_ATOMIC */
  464. if ((res = usb_submit_urb(urb, GFP_ATOMIC))) {
  465. net_warn_ratelimited("%s(), failed Tx URB\n", __func__);
  466. netdev->stats.tx_errors++;
  467. /* Let USB recover : We will catch that in the watchdog */
  468. /*netif_start_queue(netdev);*/
  469. } else {
  470. /* Increment packet stats */
  471. netdev->stats.tx_packets++;
  472. netdev->stats.tx_bytes += skb->len;
  473. netif_trans_update(netdev);
  474. }
  475. spin_unlock_irqrestore(&self->lock, flags);
  476. return NETDEV_TX_OK;
  477. drop:
  478. /* Drop silently the skb and exit */
  479. dev_kfree_skb(skb);
  480. spin_unlock_irqrestore(&self->lock, flags);
  481. return NETDEV_TX_OK;
  482. }
  483. /*------------------------------------------------------------------*/
  484. /*
  485. * Note : this function will be called only for tx_urb...
  486. */
  487. static void write_bulk_callback(struct urb *urb)
  488. {
  489. unsigned long flags;
  490. struct sk_buff *skb = urb->context;
  491. struct irda_usb_cb *self = ((struct irda_skb_cb *) skb->cb)->context;
  492. /* We should always have a context */
  493. IRDA_ASSERT(self != NULL, return;);
  494. /* We should always be called for the speed URB */
  495. IRDA_ASSERT(urb == self->tx_urb, return;);
  496. /* Free up the skb */
  497. dev_kfree_skb_any(skb);
  498. urb->context = NULL;
  499. /* Check for timeout and other USB nasties */
  500. if (urb->status != 0) {
  501. /* I get a lot of -ECONNABORTED = -103 here - Jean II */
  502. pr_debug("%s(), URB complete status %d, transfer_flags 0x%04X\n",
  503. __func__, urb->status, urb->transfer_flags);
  504. /* Don't do anything here, that might confuse the USB layer,
  505. * and we could go in recursion and blow the kernel stack...
  506. * Instead, we will wait for irda_usb_net_timeout(), the
  507. * network layer watchdog, to fix the situation.
  508. * Jean II */
  509. /* A reset of the dongle might be welcomed here - Jean II */
  510. return;
  511. }
  512. /* urb is now available */
  513. //urb->status = 0; -> tested above
  514. /* Make sure we read self->present properly */
  515. spin_lock_irqsave(&self->lock, flags);
  516. /* If the network is closed, stop everything */
  517. if ((!self->netopen) || (!self->present)) {
  518. pr_debug("%s(), Network is gone...\n", __func__);
  519. spin_unlock_irqrestore(&self->lock, flags);
  520. return;
  521. }
  522. /* If changes to speed or xbofs is pending... */
  523. if ((self->new_speed != -1) || (self->new_xbofs != -1)) {
  524. if ((self->new_speed != self->speed) ||
  525. (self->new_xbofs != self->xbofs)) {
  526. /* We haven't changed speed yet (because of
  527. * IUC_SPEED_BUG), so do it now - Jean II */
  528. pr_debug("%s(), Changing speed now...\n", __func__);
  529. irda_usb_change_speed_xbofs(self);
  530. } else {
  531. /* New speed and xbof is now committed in hardware */
  532. self->new_speed = -1;
  533. self->new_xbofs = -1;
  534. /* Done, waiting for next packet */
  535. netif_wake_queue(self->netdev);
  536. }
  537. } else {
  538. /* Otherwise, allow the stack to send more packets */
  539. netif_wake_queue(self->netdev);
  540. }
  541. spin_unlock_irqrestore(&self->lock, flags);
  542. }
  543. /*------------------------------------------------------------------*/
  544. /*
  545. * Watchdog timer from the network layer.
  546. * After a predetermined timeout, if we don't give confirmation that
  547. * the packet has been sent (i.e. no call to netif_wake_queue()),
  548. * the network layer will call this function.
  549. * Note that URB that we submit have also a timeout. When the URB timeout
  550. * expire, the normal URB callback is called (write_bulk_callback()).
  551. */
  552. static void irda_usb_net_timeout(struct net_device *netdev)
  553. {
  554. unsigned long flags;
  555. struct irda_usb_cb *self = netdev_priv(netdev);
  556. struct urb *urb;
  557. int done = 0; /* If we have made any progress */
  558. pr_debug("%s(), Network layer thinks we timed out!\n", __func__);
  559. IRDA_ASSERT(self != NULL, return;);
  560. /* Protect us from USB callbacks, net Tx and else. */
  561. spin_lock_irqsave(&self->lock, flags);
  562. /* self->present *MUST* be read under spinlock */
  563. if (!self->present) {
  564. net_warn_ratelimited("%s(), device not present!\n", __func__);
  565. netif_stop_queue(netdev);
  566. spin_unlock_irqrestore(&self->lock, flags);
  567. return;
  568. }
  569. /* Check speed URB */
  570. urb = self->speed_urb;
  571. if (urb->status != 0) {
  572. pr_debug("%s: Speed change timed out, urb->status=%d, urb->transfer_flags=0x%04X\n",
  573. netdev->name, urb->status, urb->transfer_flags);
  574. switch (urb->status) {
  575. case -EINPROGRESS:
  576. usb_unlink_urb(urb);
  577. /* Note : above will *NOT* call netif_wake_queue()
  578. * in completion handler, we will come back here.
  579. * Jean II */
  580. done = 1;
  581. break;
  582. case -ECONNRESET:
  583. case -ENOENT: /* urb unlinked by us */
  584. default: /* ??? - Play safe */
  585. urb->status = 0;
  586. netif_wake_queue(self->netdev);
  587. done = 1;
  588. break;
  589. }
  590. }
  591. /* Check Tx URB */
  592. urb = self->tx_urb;
  593. if (urb->status != 0) {
  594. struct sk_buff *skb = urb->context;
  595. pr_debug("%s: Tx timed out, urb->status=%d, urb->transfer_flags=0x%04X\n",
  596. netdev->name, urb->status, urb->transfer_flags);
  597. /* Increase error count */
  598. netdev->stats.tx_errors++;
  599. #ifdef IU_BUG_KICK_TIMEOUT
  600. /* Can't be a bad idea to reset the speed ;-) - Jean II */
  601. if(self->new_speed == -1)
  602. self->new_speed = self->speed;
  603. if(self->new_xbofs == -1)
  604. self->new_xbofs = self->xbofs;
  605. irda_usb_change_speed_xbofs(self);
  606. #endif /* IU_BUG_KICK_TIMEOUT */
  607. switch (urb->status) {
  608. case -EINPROGRESS:
  609. usb_unlink_urb(urb);
  610. /* Note : above will *NOT* call netif_wake_queue()
  611. * in completion handler, because urb->status will
  612. * be -ENOENT. We will fix that at the next watchdog,
  613. * leaving more time to USB to recover...
  614. * Jean II */
  615. done = 1;
  616. break;
  617. case -ECONNRESET:
  618. case -ENOENT: /* urb unlinked by us */
  619. default: /* ??? - Play safe */
  620. if(skb != NULL) {
  621. dev_kfree_skb_any(skb);
  622. urb->context = NULL;
  623. }
  624. urb->status = 0;
  625. netif_wake_queue(self->netdev);
  626. done = 1;
  627. break;
  628. }
  629. }
  630. spin_unlock_irqrestore(&self->lock, flags);
  631. /* Maybe we need a reset */
  632. /* Note : Some drivers seem to use a usb_set_interface() when they
  633. * need to reset the hardware. Hum...
  634. */
  635. /* if(done == 0) */
  636. }
  637. /************************* RECEIVE ROUTINES *************************/
  638. /*
  639. * Receive packets from the USB layer stack and pass them to the IrDA stack.
  640. * Try to work around USB failures...
  641. */
  642. /*
  643. * Note :
  644. * Some of you may have noticed that most dongle have an interrupt in pipe
  645. * that we don't use. Here is the little secret...
  646. * When we hang a Rx URB on the bulk in pipe, it generates some USB traffic
  647. * in every USB frame. This is unnecessary overhead.
  648. * The interrupt in pipe will generate an event every time a packet is
  649. * received. Reading an interrupt pipe adds minimal overhead, but has some
  650. * latency (~1ms).
  651. * If we are connected (speed != 9600), we want to minimise latency, so
  652. * we just always hang the Rx URB and ignore the interrupt.
  653. * If we are not connected (speed == 9600), there is usually no Rx traffic,
  654. * and we want to minimise the USB overhead. In this case we should wait
  655. * on the interrupt pipe and hang the Rx URB only when an interrupt is
  656. * received.
  657. * Jean II
  658. *
  659. * Note : don't read the above as what we are currently doing, but as
  660. * something we could do with KC dongle. Also don't forget that the
  661. * interrupt pipe is not part of the original standard, so this would
  662. * need to be optional...
  663. * Jean II
  664. */
  665. /*------------------------------------------------------------------*/
  666. /*
  667. * Submit a Rx URB to the USB layer to handle reception of a frame
  668. * Mostly called by the completion callback of the previous URB.
  669. *
  670. * Jean II
  671. */
  672. static void irda_usb_submit(struct irda_usb_cb *self, struct sk_buff *skb, struct urb *urb)
  673. {
  674. struct irda_skb_cb *cb;
  675. int ret;
  676. /* This should never happen */
  677. IRDA_ASSERT(skb != NULL, return;);
  678. IRDA_ASSERT(urb != NULL, return;);
  679. /* Save ourselves in the skb */
  680. cb = (struct irda_skb_cb *) skb->cb;
  681. cb->context = self;
  682. /* Reinitialize URB */
  683. usb_fill_bulk_urb(urb, self->usbdev,
  684. usb_rcvbulkpipe(self->usbdev, self->bulk_in_ep),
  685. skb->data, IRDA_SKB_MAX_MTU,
  686. irda_usb_receive, skb);
  687. urb->status = 0;
  688. /* Can be called from irda_usb_receive (irq handler) -> GFP_ATOMIC */
  689. ret = usb_submit_urb(urb, GFP_ATOMIC);
  690. if (ret) {
  691. /* If this ever happen, we are in deep s***.
  692. * Basically, the Rx path will stop... */
  693. net_warn_ratelimited("%s(), Failed to submit Rx URB %d\n",
  694. __func__, ret);
  695. }
  696. }
  697. /*------------------------------------------------------------------*/
  698. /*
  699. * Function irda_usb_receive(urb)
  700. *
  701. * Called by the USB subsystem when a frame has been received
  702. *
  703. */
  704. static void irda_usb_receive(struct urb *urb)
  705. {
  706. struct sk_buff *skb = (struct sk_buff *) urb->context;
  707. struct irda_usb_cb *self;
  708. struct irda_skb_cb *cb;
  709. struct sk_buff *newskb;
  710. struct sk_buff *dataskb;
  711. struct urb *next_urb;
  712. unsigned int len, docopy;
  713. pr_debug("%s(), len=%d\n", __func__, urb->actual_length);
  714. /* Find ourselves */
  715. cb = (struct irda_skb_cb *) skb->cb;
  716. IRDA_ASSERT(cb != NULL, return;);
  717. self = (struct irda_usb_cb *) cb->context;
  718. IRDA_ASSERT(self != NULL, return;);
  719. /* If the network is closed or the device gone, stop everything */
  720. if ((!self->netopen) || (!self->present)) {
  721. pr_debug("%s(), Network is gone!\n", __func__);
  722. /* Don't re-submit the URB : will stall the Rx path */
  723. return;
  724. }
  725. /* Check the status */
  726. if (urb->status != 0) {
  727. switch (urb->status) {
  728. case -EILSEQ:
  729. self->netdev->stats.rx_crc_errors++;
  730. /* Also precursor to a hot-unplug on UHCI. */
  731. /* Fallthrough... */
  732. case -ECONNRESET:
  733. /* Random error, if I remember correctly */
  734. /* uhci_cleanup_unlink() is going to kill the Rx
  735. * URB just after we return. No problem, at this
  736. * point the URB will be idle ;-) - Jean II */
  737. case -ESHUTDOWN:
  738. /* That's usually a hot-unplug. Submit will fail... */
  739. case -ETIME:
  740. /* Usually precursor to a hot-unplug on OHCI. */
  741. default:
  742. self->netdev->stats.rx_errors++;
  743. pr_debug("%s(), RX status %d, transfer_flags 0x%04X\n",
  744. __func__, urb->status, urb->transfer_flags);
  745. break;
  746. }
  747. /* If we received an error, we don't want to resubmit the
  748. * Rx URB straight away but to give the USB layer a little
  749. * bit of breathing room.
  750. * We are in the USB thread context, therefore there is a
  751. * danger of recursion (new URB we submit fails, we come
  752. * back here).
  753. * With recent USB stack (2.6.15+), I'm seeing that on
  754. * hot unplug of the dongle...
  755. * Lowest effective timer is 10ms...
  756. * Jean II */
  757. self->rx_defer_timer.function = irda_usb_rx_defer_expired;
  758. self->rx_defer_timer.data = (unsigned long) urb;
  759. mod_timer(&self->rx_defer_timer,
  760. jiffies + msecs_to_jiffies(10));
  761. return;
  762. }
  763. /* Check for empty frames */
  764. if (urb->actual_length <= self->header_length) {
  765. net_warn_ratelimited("%s(), empty frame!\n", __func__);
  766. goto done;
  767. }
  768. /*
  769. * Remember the time we received this frame, so we can
  770. * reduce the min turn time a bit since we will know
  771. * how much time we have used for protocol processing
  772. */
  773. self->stamp = ktime_get();
  774. /* Check if we need to copy the data to a new skb or not.
  775. * For most frames, we use ZeroCopy and pass the already
  776. * allocated skb up the stack.
  777. * If the frame is small, it is more efficient to copy it
  778. * to save memory (copy will be fast anyway - that's
  779. * called Rx-copy-break). Jean II */
  780. docopy = (urb->actual_length < IRDA_RX_COPY_THRESHOLD);
  781. /* Allocate a new skb */
  782. if (self->capability & IUC_STIR421X)
  783. newskb = dev_alloc_skb(docopy ? urb->actual_length :
  784. IRDA_SKB_MAX_MTU +
  785. USB_IRDA_STIR421X_HEADER);
  786. else
  787. newskb = dev_alloc_skb(docopy ? urb->actual_length :
  788. IRDA_SKB_MAX_MTU);
  789. if (!newskb) {
  790. self->netdev->stats.rx_dropped++;
  791. /* We could deliver the current skb, but this would stall
  792. * the Rx path. Better drop the packet... Jean II */
  793. goto done;
  794. }
  795. /* Make sure IP header get aligned (IrDA header is 5 bytes) */
  796. /* But IrDA-USB header is 1 byte. Jean II */
  797. //skb_reserve(newskb, USB_IRDA_HEADER - 1);
  798. if(docopy) {
  799. /* Copy packet, so we can recycle the original */
  800. skb_copy_from_linear_data(skb, newskb->data, urb->actual_length);
  801. /* Deliver this new skb */
  802. dataskb = newskb;
  803. /* And hook the old skb to the URB
  804. * Note : we don't need to "clean up" the old skb,
  805. * as we never touched it. Jean II */
  806. } else {
  807. /* We are using ZeroCopy. Deliver old skb */
  808. dataskb = skb;
  809. /* And hook the new skb to the URB */
  810. skb = newskb;
  811. }
  812. /* Set proper length on skb & remove USB-IrDA header */
  813. skb_put(dataskb, urb->actual_length);
  814. skb_pull(dataskb, self->header_length);
  815. /* Ask the networking layer to queue the packet for the IrDA stack */
  816. dataskb->dev = self->netdev;
  817. skb_reset_mac_header(dataskb);
  818. dataskb->protocol = htons(ETH_P_IRDA);
  819. len = dataskb->len;
  820. netif_rx(dataskb);
  821. /* Keep stats up to date */
  822. self->netdev->stats.rx_bytes += len;
  823. self->netdev->stats.rx_packets++;
  824. done:
  825. /* Note : at this point, the URB we've just received (urb)
  826. * is still referenced by the USB layer. For example, if we
  827. * have received a -ECONNRESET, uhci_cleanup_unlink() will
  828. * continue to process it (in fact, cleaning it up).
  829. * If we were to submit this URB, disaster would ensue.
  830. * Therefore, we submit our idle URB, and put this URB in our
  831. * idle slot....
  832. * Jean II */
  833. /* Note : with this scheme, we could submit the idle URB before
  834. * processing the Rx URB. I don't think it would buy us anything as
  835. * we are running in the USB thread context. Jean II */
  836. next_urb = self->idle_rx_urb;
  837. /* Recycle Rx URB : Now, the idle URB is the present one */
  838. urb->context = NULL;
  839. self->idle_rx_urb = urb;
  840. /* Submit the idle URB to replace the URB we've just received.
  841. * Do it last to avoid race conditions... Jean II */
  842. irda_usb_submit(self, skb, next_urb);
  843. }
  844. /*------------------------------------------------------------------*/
  845. /*
  846. * In case of errors, we want the USB layer to have time to recover.
  847. * Now, it is time to resubmit ouur Rx URB...
  848. */
  849. static void irda_usb_rx_defer_expired(unsigned long data)
  850. {
  851. struct urb *urb = (struct urb *) data;
  852. struct sk_buff *skb = (struct sk_buff *) urb->context;
  853. struct irda_usb_cb *self;
  854. struct irda_skb_cb *cb;
  855. struct urb *next_urb;
  856. /* Find ourselves */
  857. cb = (struct irda_skb_cb *) skb->cb;
  858. IRDA_ASSERT(cb != NULL, return;);
  859. self = (struct irda_usb_cb *) cb->context;
  860. IRDA_ASSERT(self != NULL, return;);
  861. /* Same stuff as when Rx is done, see above... */
  862. next_urb = self->idle_rx_urb;
  863. urb->context = NULL;
  864. self->idle_rx_urb = urb;
  865. irda_usb_submit(self, skb, next_urb);
  866. }
  867. /*------------------------------------------------------------------*/
  868. /*
  869. * Callbak from IrDA layer. IrDA wants to know if we have
  870. * started receiving anything.
  871. */
  872. static int irda_usb_is_receiving(struct irda_usb_cb *self)
  873. {
  874. /* Note : because of the way UHCI works, it's almost impossible
  875. * to get this info. The Controller DMA directly to memory and
  876. * signal only when the whole frame is finished. To know if the
  877. * first TD of the URB has been filled or not seems hard work...
  878. *
  879. * The other solution would be to use the "receiving" command
  880. * on the default decriptor with a usb_control_msg(), but that
  881. * would add USB traffic and would return result only in the
  882. * next USB frame (~1ms).
  883. *
  884. * I've been told that current dongles send status info on their
  885. * interrupt endpoint, and that's what the Windows driver uses
  886. * to know this info. Unfortunately, this is not yet in the spec...
  887. *
  888. * Jean II
  889. */
  890. return 0; /* For now */
  891. }
  892. #define STIR421X_PATCH_PRODUCT_VER "Product Version: "
  893. #define STIR421X_PATCH_STMP_TAG "STMP"
  894. #define STIR421X_PATCH_CODE_OFFSET 512 /* patch image starts before here */
  895. /* marks end of patch file header (PC DOS text file EOF character) */
  896. #define STIR421X_PATCH_END_OF_HDR_TAG 0x1A
  897. #define STIR421X_PATCH_BLOCK_SIZE 1023
  898. /*
  899. * Function stir421x_fwupload (struct irda_usb_cb *self,
  900. * unsigned char *patch,
  901. * const unsigned int patch_len)
  902. *
  903. * Upload firmware code to SigmaTel 421X IRDA-USB dongle
  904. */
  905. static int stir421x_fw_upload(struct irda_usb_cb *self,
  906. const unsigned char *patch,
  907. const unsigned int patch_len)
  908. {
  909. int ret = -ENOMEM;
  910. int actual_len = 0;
  911. unsigned int i;
  912. unsigned int block_size = 0;
  913. unsigned char *patch_block;
  914. patch_block = kzalloc(STIR421X_PATCH_BLOCK_SIZE, GFP_KERNEL);
  915. if (patch_block == NULL)
  916. return -ENOMEM;
  917. /* break up patch into 1023-byte sections */
  918. for (i = 0; i < patch_len; i += block_size) {
  919. block_size = patch_len - i;
  920. if (block_size > STIR421X_PATCH_BLOCK_SIZE)
  921. block_size = STIR421X_PATCH_BLOCK_SIZE;
  922. /* upload the patch section */
  923. memcpy(patch_block, patch + i, block_size);
  924. ret = usb_bulk_msg(self->usbdev,
  925. usb_sndbulkpipe(self->usbdev,
  926. self->bulk_out_ep),
  927. patch_block, block_size,
  928. &actual_len, msecs_to_jiffies(500));
  929. pr_debug("%s(): Bulk send %u bytes, ret=%d\n",
  930. __func__, actual_len, ret);
  931. if (ret < 0)
  932. break;
  933. mdelay(10);
  934. }
  935. kfree(patch_block);
  936. return ret;
  937. }
  938. /*
  939. * Function stir421x_patch_device(struct irda_usb_cb *self)
  940. *
  941. * Get a firmware code from userspase using hotplug request_firmware() call
  942. */
  943. static int stir421x_patch_device(struct irda_usb_cb *self)
  944. {
  945. unsigned int i;
  946. int ret;
  947. char stir421x_fw_name[12];
  948. const struct firmware *fw;
  949. const unsigned char *fw_version_ptr; /* pointer to version string */
  950. unsigned long fw_version = 0;
  951. /*
  952. * Known firmware patch file names for STIR421x dongles
  953. * are "42101001.sb" or "42101002.sb"
  954. */
  955. sprintf(stir421x_fw_name, "4210%4X.sb",
  956. self->usbdev->descriptor.bcdDevice);
  957. ret = request_firmware(&fw, stir421x_fw_name, &self->usbdev->dev);
  958. if (ret < 0)
  959. return ret;
  960. /* We get a patch from userspace */
  961. net_info_ratelimited("%s(): Received firmware %s (%zu bytes)\n",
  962. __func__, stir421x_fw_name, fw->size);
  963. ret = -EINVAL;
  964. /* Get the bcd product version */
  965. if (!memcmp(fw->data, STIR421X_PATCH_PRODUCT_VER,
  966. sizeof(STIR421X_PATCH_PRODUCT_VER) - 1)) {
  967. fw_version_ptr = fw->data +
  968. sizeof(STIR421X_PATCH_PRODUCT_VER) - 1;
  969. /* Let's check if the product version is dotted */
  970. if (fw_version_ptr[3] == '.' &&
  971. fw_version_ptr[7] == '.') {
  972. unsigned long major, minor, build;
  973. major = simple_strtoul(fw_version_ptr, NULL, 10);
  974. minor = simple_strtoul(fw_version_ptr + 4, NULL, 10);
  975. build = simple_strtoul(fw_version_ptr + 8, NULL, 10);
  976. fw_version = (major << 12)
  977. + (minor << 8)
  978. + ((build / 10) << 4)
  979. + (build % 10);
  980. pr_debug("%s(): Firmware Product version %ld\n",
  981. __func__, fw_version);
  982. }
  983. }
  984. if (self->usbdev->descriptor.bcdDevice == cpu_to_le16(fw_version)) {
  985. /*
  986. * If we're here, we've found a correct patch
  987. * The actual image starts after the "STMP" keyword
  988. * so forward to the firmware header tag
  989. */
  990. for (i = 0; i < fw->size && fw->data[i] !=
  991. STIR421X_PATCH_END_OF_HDR_TAG; i++) ;
  992. /* here we check for the out of buffer case */
  993. if (i < STIR421X_PATCH_CODE_OFFSET && i < fw->size &&
  994. STIR421X_PATCH_END_OF_HDR_TAG == fw->data[i]) {
  995. if (!memcmp(fw->data + i + 1, STIR421X_PATCH_STMP_TAG,
  996. sizeof(STIR421X_PATCH_STMP_TAG) - 1)) {
  997. /* We can upload the patch to the target */
  998. i += sizeof(STIR421X_PATCH_STMP_TAG);
  999. ret = stir421x_fw_upload(self, &fw->data[i],
  1000. fw->size - i);
  1001. }
  1002. }
  1003. }
  1004. release_firmware(fw);
  1005. return ret;
  1006. }
  1007. /********************** IRDA DEVICE CALLBACKS **********************/
  1008. /*
  1009. * Main calls from the IrDA/Network subsystem.
  1010. * Mostly registering a new irda-usb device and removing it....
  1011. * We only deal with the IrDA side of the business, the USB side will
  1012. * be dealt with below...
  1013. */
  1014. /*------------------------------------------------------------------*/
  1015. /*
  1016. * Function irda_usb_net_open (dev)
  1017. *
  1018. * Network device is taken up. Usually this is done by "ifconfig irda0 up"
  1019. *
  1020. * Note : don't mess with self->netopen - Jean II
  1021. */
  1022. static int irda_usb_net_open(struct net_device *netdev)
  1023. {
  1024. struct irda_usb_cb *self;
  1025. unsigned long flags;
  1026. char hwname[16];
  1027. int i;
  1028. IRDA_ASSERT(netdev != NULL, return -1;);
  1029. self = netdev_priv(netdev);
  1030. IRDA_ASSERT(self != NULL, return -1;);
  1031. spin_lock_irqsave(&self->lock, flags);
  1032. /* Can only open the device if it's there */
  1033. if(!self->present) {
  1034. spin_unlock_irqrestore(&self->lock, flags);
  1035. net_warn_ratelimited("%s(), device not present!\n", __func__);
  1036. return -1;
  1037. }
  1038. if(self->needspatch) {
  1039. spin_unlock_irqrestore(&self->lock, flags);
  1040. net_warn_ratelimited("%s(), device needs patch\n", __func__);
  1041. return -EIO ;
  1042. }
  1043. /* Initialise default speed and xbofs value
  1044. * (IrLAP will change that soon) */
  1045. self->speed = -1;
  1046. self->xbofs = -1;
  1047. self->new_speed = -1;
  1048. self->new_xbofs = -1;
  1049. /* To do *before* submitting Rx urbs and starting net Tx queue
  1050. * Jean II */
  1051. self->netopen = 1;
  1052. spin_unlock_irqrestore(&self->lock, flags);
  1053. /*
  1054. * Now that everything should be initialized properly,
  1055. * Open new IrLAP layer instance to take care of us...
  1056. * Note : will send immediately a speed change...
  1057. */
  1058. sprintf(hwname, "usb#%d", self->usbdev->devnum);
  1059. self->irlap = irlap_open(netdev, &self->qos, hwname);
  1060. IRDA_ASSERT(self->irlap != NULL, return -1;);
  1061. /* Allow IrLAP to send data to us */
  1062. netif_start_queue(netdev);
  1063. /* We submit all the Rx URB except for one that we keep idle.
  1064. * Need to be initialised before submitting other USBs, because
  1065. * in some cases as soon as we submit the URBs the USB layer
  1066. * will trigger a dummy receive - Jean II */
  1067. self->idle_rx_urb = self->rx_urb[IU_MAX_ACTIVE_RX_URBS];
  1068. self->idle_rx_urb->context = NULL;
  1069. /* Now that we can pass data to IrLAP, allow the USB layer
  1070. * to send us some data... */
  1071. for (i = 0; i < IU_MAX_ACTIVE_RX_URBS; i++) {
  1072. struct sk_buff *skb = dev_alloc_skb(IRDA_SKB_MAX_MTU);
  1073. if (!skb) {
  1074. /* If this ever happen, we are in deep s***.
  1075. * Basically, we can't start the Rx path... */
  1076. return -1;
  1077. }
  1078. //skb_reserve(newskb, USB_IRDA_HEADER - 1);
  1079. irda_usb_submit(self, skb, self->rx_urb[i]);
  1080. }
  1081. /* Ready to play !!! */
  1082. return 0;
  1083. }
  1084. /*------------------------------------------------------------------*/
  1085. /*
  1086. * Function irda_usb_net_close (self)
  1087. *
  1088. * Network device is taken down. Usually this is done by
  1089. * "ifconfig irda0 down"
  1090. */
  1091. static int irda_usb_net_close(struct net_device *netdev)
  1092. {
  1093. struct irda_usb_cb *self;
  1094. int i;
  1095. IRDA_ASSERT(netdev != NULL, return -1;);
  1096. self = netdev_priv(netdev);
  1097. IRDA_ASSERT(self != NULL, return -1;);
  1098. /* Clear this flag *before* unlinking the urbs and *before*
  1099. * stopping the network Tx queue - Jean II */
  1100. self->netopen = 0;
  1101. /* Stop network Tx queue */
  1102. netif_stop_queue(netdev);
  1103. /* Kill defered Rx URB */
  1104. del_timer(&self->rx_defer_timer);
  1105. /* Deallocate all the Rx path buffers (URBs and skb) */
  1106. for (i = 0; i < self->max_rx_urb; i++) {
  1107. struct urb *urb = self->rx_urb[i];
  1108. struct sk_buff *skb = (struct sk_buff *) urb->context;
  1109. /* Cancel the receive command */
  1110. usb_kill_urb(urb);
  1111. /* The skb is ours, free it */
  1112. if(skb) {
  1113. dev_kfree_skb(skb);
  1114. urb->context = NULL;
  1115. }
  1116. }
  1117. /* Cancel Tx and speed URB - need to be synchronous to avoid races */
  1118. usb_kill_urb(self->tx_urb);
  1119. usb_kill_urb(self->speed_urb);
  1120. /* Stop and remove instance of IrLAP */
  1121. if (self->irlap)
  1122. irlap_close(self->irlap);
  1123. self->irlap = NULL;
  1124. return 0;
  1125. }
  1126. /*------------------------------------------------------------------*/
  1127. /*
  1128. * IOCTLs : Extra out-of-band network commands...
  1129. */
  1130. static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  1131. {
  1132. unsigned long flags;
  1133. struct if_irda_req *irq = (struct if_irda_req *) rq;
  1134. struct irda_usb_cb *self;
  1135. int ret = 0;
  1136. IRDA_ASSERT(dev != NULL, return -1;);
  1137. self = netdev_priv(dev);
  1138. IRDA_ASSERT(self != NULL, return -1;);
  1139. pr_debug("%s(), %s, (cmd=0x%X)\n", __func__, dev->name, cmd);
  1140. switch (cmd) {
  1141. case SIOCSBANDWIDTH: /* Set bandwidth */
  1142. if (!capable(CAP_NET_ADMIN))
  1143. return -EPERM;
  1144. /* Protect us from USB callbacks, net watchdog and else. */
  1145. spin_lock_irqsave(&self->lock, flags);
  1146. /* Check if the device is still there */
  1147. if(self->present) {
  1148. /* Set the desired speed */
  1149. self->new_speed = irq->ifr_baudrate;
  1150. irda_usb_change_speed_xbofs(self);
  1151. }
  1152. spin_unlock_irqrestore(&self->lock, flags);
  1153. break;
  1154. case SIOCSMEDIABUSY: /* Set media busy */
  1155. if (!capable(CAP_NET_ADMIN))
  1156. return -EPERM;
  1157. /* Check if the IrDA stack is still there */
  1158. if(self->netopen)
  1159. irda_device_set_media_busy(self->netdev, TRUE);
  1160. break;
  1161. case SIOCGRECEIVING: /* Check if we are receiving right now */
  1162. irq->ifr_receiving = irda_usb_is_receiving(self);
  1163. break;
  1164. default:
  1165. ret = -EOPNOTSUPP;
  1166. }
  1167. return ret;
  1168. }
  1169. /*------------------------------------------------------------------*/
  1170. /********************* IRDA CONFIG SUBROUTINES *********************/
  1171. /*
  1172. * Various subroutines dealing with IrDA and network stuff we use to
  1173. * configure and initialise each irda-usb instance.
  1174. * These functions are used below in the main calls of the driver...
  1175. */
  1176. /*------------------------------------------------------------------*/
  1177. /*
  1178. * Set proper values in the IrDA QOS structure
  1179. */
  1180. static inline void irda_usb_init_qos(struct irda_usb_cb *self)
  1181. {
  1182. struct irda_class_desc *desc;
  1183. desc = self->irda_desc;
  1184. /* Initialize QoS for this device */
  1185. irda_init_max_qos_capabilies(&self->qos);
  1186. /* See spec section 7.2 for meaning.
  1187. * Values are little endian (as most USB stuff), the IrDA stack
  1188. * use it in native order (see parameters.c). - Jean II */
  1189. self->qos.baud_rate.bits = le16_to_cpu(desc->wBaudRate);
  1190. self->qos.min_turn_time.bits = desc->bmMinTurnaroundTime;
  1191. self->qos.additional_bofs.bits = desc->bmAdditionalBOFs;
  1192. self->qos.window_size.bits = desc->bmWindowSize;
  1193. self->qos.data_size.bits = desc->bmDataSize;
  1194. pr_debug("%s(), dongle says speed=0x%X, size=0x%X, window=0x%X, bofs=0x%X, turn=0x%X\n",
  1195. __func__, self->qos.baud_rate.bits, self->qos.data_size.bits,
  1196. self->qos.window_size.bits, self->qos.additional_bofs.bits,
  1197. self->qos.min_turn_time.bits);
  1198. /* Don't always trust what the dongle tell us */
  1199. if(self->capability & IUC_SIR_ONLY)
  1200. self->qos.baud_rate.bits &= 0x00ff;
  1201. if(self->capability & IUC_SMALL_PKT)
  1202. self->qos.data_size.bits = 0x07;
  1203. if(self->capability & IUC_NO_WINDOW)
  1204. self->qos.window_size.bits = 0x01;
  1205. if(self->capability & IUC_MAX_WINDOW)
  1206. self->qos.window_size.bits = 0x7f;
  1207. if(self->capability & IUC_MAX_XBOFS)
  1208. self->qos.additional_bofs.bits = 0x01;
  1209. #if 1
  1210. /* Module parameter can override the rx window size */
  1211. if (qos_mtt_bits)
  1212. self->qos.min_turn_time.bits = qos_mtt_bits;
  1213. #endif
  1214. /*
  1215. * Note : most of those values apply only for the receive path,
  1216. * the transmit path will be set differently - Jean II
  1217. */
  1218. irda_qos_bits_to_value(&self->qos);
  1219. }
  1220. /*------------------------------------------------------------------*/
  1221. static const struct net_device_ops irda_usb_netdev_ops = {
  1222. .ndo_open = irda_usb_net_open,
  1223. .ndo_stop = irda_usb_net_close,
  1224. .ndo_do_ioctl = irda_usb_net_ioctl,
  1225. .ndo_start_xmit = irda_usb_hard_xmit,
  1226. .ndo_tx_timeout = irda_usb_net_timeout,
  1227. };
  1228. /*
  1229. * Initialise the network side of the irda-usb instance
  1230. * Called when a new USB instance is registered in irda_usb_probe()
  1231. */
  1232. static inline int irda_usb_open(struct irda_usb_cb *self)
  1233. {
  1234. struct net_device *netdev = self->netdev;
  1235. netdev->netdev_ops = &irda_usb_netdev_ops;
  1236. irda_usb_init_qos(self);
  1237. return register_netdev(netdev);
  1238. }
  1239. /*------------------------------------------------------------------*/
  1240. /*
  1241. * Cleanup the network side of the irda-usb instance
  1242. * Called when a USB instance is removed in irda_usb_disconnect()
  1243. */
  1244. static inline void irda_usb_close(struct irda_usb_cb *self)
  1245. {
  1246. /* Remove netdevice */
  1247. unregister_netdev(self->netdev);
  1248. /* Remove the speed buffer */
  1249. kfree(self->speed_buff);
  1250. self->speed_buff = NULL;
  1251. kfree(self->tx_buff);
  1252. self->tx_buff = NULL;
  1253. }
  1254. /********************** USB CONFIG SUBROUTINES **********************/
  1255. /*
  1256. * Various subroutines dealing with USB stuff we use to configure and
  1257. * initialise each irda-usb instance.
  1258. * These functions are used below in the main calls of the driver...
  1259. */
  1260. /*------------------------------------------------------------------*/
  1261. /*
  1262. * Function irda_usb_parse_endpoints(dev, ifnum)
  1263. *
  1264. * Parse the various endpoints and find the one we need.
  1265. *
  1266. * The endpoint are the pipes used to communicate with the USB device.
  1267. * The spec defines 2 endpoints of type bulk transfer, one in, and one out.
  1268. * These are used to pass frames back and forth with the dongle.
  1269. * Most dongle have also an interrupt endpoint, that will be probably
  1270. * documented in the next spec...
  1271. */
  1272. static inline int irda_usb_parse_endpoints(struct irda_usb_cb *self, struct usb_host_endpoint *endpoint, int ennum)
  1273. {
  1274. int i; /* Endpoint index in table */
  1275. /* Init : no endpoints */
  1276. self->bulk_in_ep = 0;
  1277. self->bulk_out_ep = 0;
  1278. self->bulk_int_ep = 0;
  1279. /* Let's look at all those endpoints */
  1280. for(i = 0; i < ennum; i++) {
  1281. /* All those variables will get optimised by the compiler,
  1282. * so let's aim for clarity... - Jean II */
  1283. __u8 ep; /* Endpoint address */
  1284. __u8 dir; /* Endpoint direction */
  1285. __u8 attr; /* Endpoint attribute */
  1286. __u16 psize; /* Endpoint max packet size in bytes */
  1287. /* Get endpoint address, direction and attribute */
  1288. ep = endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
  1289. dir = endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK;
  1290. attr = endpoint[i].desc.bmAttributes;
  1291. psize = le16_to_cpu(endpoint[i].desc.wMaxPacketSize);
  1292. /* Is it a bulk endpoint ??? */
  1293. if(attr == USB_ENDPOINT_XFER_BULK) {
  1294. /* We need to find an IN and an OUT */
  1295. if(dir == USB_DIR_IN) {
  1296. /* This is our Rx endpoint */
  1297. self->bulk_in_ep = ep;
  1298. } else {
  1299. /* This is our Tx endpoint */
  1300. self->bulk_out_ep = ep;
  1301. self->bulk_out_mtu = psize;
  1302. }
  1303. } else {
  1304. if((attr == USB_ENDPOINT_XFER_INT) &&
  1305. (dir == USB_DIR_IN)) {
  1306. /* This is our interrupt endpoint */
  1307. self->bulk_int_ep = ep;
  1308. } else {
  1309. net_err_ratelimited("%s(), Unrecognised endpoint %02X\n",
  1310. __func__, ep);
  1311. }
  1312. }
  1313. }
  1314. pr_debug("%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n",
  1315. __func__, self->bulk_in_ep, self->bulk_out_ep,
  1316. self->bulk_out_mtu, self->bulk_int_ep);
  1317. return (self->bulk_in_ep != 0) && (self->bulk_out_ep != 0);
  1318. }
  1319. #ifdef IU_DUMP_CLASS_DESC
  1320. /*------------------------------------------------------------------*/
  1321. /*
  1322. * Function usb_irda_dump_class_desc(desc)
  1323. *
  1324. * Prints out the contents of the IrDA class descriptor
  1325. *
  1326. */
  1327. static inline void irda_usb_dump_class_desc(struct irda_class_desc *desc)
  1328. {
  1329. /* Values are little endian */
  1330. printk("bLength=%x\n", desc->bLength);
  1331. printk("bDescriptorType=%x\n", desc->bDescriptorType);
  1332. printk("bcdSpecRevision=%x\n", le16_to_cpu(desc->bcdSpecRevision));
  1333. printk("bmDataSize=%x\n", desc->bmDataSize);
  1334. printk("bmWindowSize=%x\n", desc->bmWindowSize);
  1335. printk("bmMinTurnaroundTime=%d\n", desc->bmMinTurnaroundTime);
  1336. printk("wBaudRate=%x\n", le16_to_cpu(desc->wBaudRate));
  1337. printk("bmAdditionalBOFs=%x\n", desc->bmAdditionalBOFs);
  1338. printk("bIrdaRateSniff=%x\n", desc->bIrdaRateSniff);
  1339. printk("bMaxUnicastList=%x\n", desc->bMaxUnicastList);
  1340. }
  1341. #endif /* IU_DUMP_CLASS_DESC */
  1342. /*------------------------------------------------------------------*/
  1343. /*
  1344. * Function irda_usb_find_class_desc(intf)
  1345. *
  1346. * Returns instance of IrDA class descriptor, or NULL if not found
  1347. *
  1348. * The class descriptor is some extra info that IrDA USB devices will
  1349. * offer to us, describing their IrDA characteristics. We will use that in
  1350. * irda_usb_init_qos()
  1351. */
  1352. static inline struct irda_class_desc *irda_usb_find_class_desc(struct usb_interface *intf)
  1353. {
  1354. struct usb_device *dev = interface_to_usbdev (intf);
  1355. struct irda_class_desc *desc;
  1356. int ret;
  1357. desc = kzalloc(sizeof(*desc), GFP_KERNEL);
  1358. if (!desc)
  1359. return NULL;
  1360. /* USB-IrDA class spec 1.0:
  1361. * 6.1.3: Standard "Get Descriptor" Device Request is not
  1362. * appropriate to retrieve class-specific descriptor
  1363. * 6.2.5: Class Specific "Get Class Descriptor" Interface Request
  1364. * is mandatory and returns the USB-IrDA class descriptor
  1365. */
  1366. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0),
  1367. IU_REQ_GET_CLASS_DESC,
  1368. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  1369. 0, intf->altsetting->desc.bInterfaceNumber, desc,
  1370. sizeof(*desc), 500);
  1371. pr_debug("%s(), ret=%d\n", __func__, ret);
  1372. if (ret < sizeof(*desc)) {
  1373. net_warn_ratelimited("usb-irda: class_descriptor read %s (%d)\n",
  1374. ret < 0 ? "failed" : "too short", ret);
  1375. }
  1376. else if (desc->bDescriptorType != USB_DT_IRDA) {
  1377. net_warn_ratelimited("usb-irda: bad class_descriptor type\n");
  1378. }
  1379. else {
  1380. #ifdef IU_DUMP_CLASS_DESC
  1381. irda_usb_dump_class_desc(desc);
  1382. #endif /* IU_DUMP_CLASS_DESC */
  1383. return desc;
  1384. }
  1385. kfree(desc);
  1386. return NULL;
  1387. }
  1388. /*********************** USB DEVICE CALLBACKS ***********************/
  1389. /*
  1390. * Main calls from the USB subsystem.
  1391. * Mostly registering a new irda-usb device and removing it....
  1392. */
  1393. /*------------------------------------------------------------------*/
  1394. /*
  1395. * This routine is called by the USB subsystem for each new device
  1396. * in the system. We need to check if the device is ours, and in
  1397. * this case start handling it.
  1398. * The USB layer protect us from reentrancy (via BKL), so we don't need
  1399. * to spinlock in there... Jean II
  1400. */
  1401. static int irda_usb_probe(struct usb_interface *intf,
  1402. const struct usb_device_id *id)
  1403. {
  1404. struct net_device *net;
  1405. struct usb_device *dev = interface_to_usbdev(intf);
  1406. struct irda_usb_cb *self;
  1407. struct usb_host_interface *interface;
  1408. struct irda_class_desc *irda_desc;
  1409. int ret = -ENOMEM;
  1410. int i; /* Driver instance index / Rx URB index */
  1411. /* Note : the probe make sure to call us only for devices that
  1412. * matches the list of dongle (top of the file). So, we
  1413. * don't need to check if the dongle is really ours.
  1414. * Jean II */
  1415. net_info_ratelimited("IRDA-USB found at address %d, Vendor: %x, Product: %x\n",
  1416. dev->devnum, le16_to_cpu(dev->descriptor.idVendor),
  1417. le16_to_cpu(dev->descriptor.idProduct));
  1418. net = alloc_irdadev(sizeof(*self));
  1419. if (!net)
  1420. goto err_out;
  1421. SET_NETDEV_DEV(net, &intf->dev);
  1422. self = netdev_priv(net);
  1423. self->netdev = net;
  1424. spin_lock_init(&self->lock);
  1425. init_timer(&self->rx_defer_timer);
  1426. self->capability = id->driver_info;
  1427. self->needspatch = ((self->capability & IUC_STIR421X) != 0);
  1428. /* Create all of the needed urbs */
  1429. if (self->capability & IUC_STIR421X) {
  1430. self->max_rx_urb = IU_SIGMATEL_MAX_RX_URBS;
  1431. self->header_length = USB_IRDA_STIR421X_HEADER;
  1432. } else {
  1433. self->max_rx_urb = IU_MAX_RX_URBS;
  1434. self->header_length = USB_IRDA_HEADER;
  1435. }
  1436. self->rx_urb = kcalloc(self->max_rx_urb, sizeof(struct urb *),
  1437. GFP_KERNEL);
  1438. if (!self->rx_urb)
  1439. goto err_free_net;
  1440. for (i = 0; i < self->max_rx_urb; i++) {
  1441. self->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
  1442. if (!self->rx_urb[i]) {
  1443. goto err_out_1;
  1444. }
  1445. }
  1446. self->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
  1447. if (!self->tx_urb) {
  1448. goto err_out_1;
  1449. }
  1450. self->speed_urb = usb_alloc_urb(0, GFP_KERNEL);
  1451. if (!self->speed_urb) {
  1452. goto err_out_2;
  1453. }
  1454. /* Is this really necessary? (no, except maybe for broken devices) */
  1455. if (usb_reset_configuration (dev) < 0) {
  1456. dev_err(&intf->dev, "reset_configuration failed\n");
  1457. ret = -EIO;
  1458. goto err_out_3;
  1459. }
  1460. /* Is this really necessary? */
  1461. /* Note : some driver do hardcode the interface number, some others
  1462. * specify an alternate, but very few driver do like this.
  1463. * Jean II */
  1464. ret = usb_set_interface(dev, intf->altsetting->desc.bInterfaceNumber, 0);
  1465. pr_debug("usb-irda: set interface %d result %d\n",
  1466. intf->altsetting->desc.bInterfaceNumber, ret);
  1467. switch (ret) {
  1468. case 0:
  1469. break;
  1470. case -EPIPE: /* -EPIPE = -32 */
  1471. /* Martin Diehl says if we get a -EPIPE we should
  1472. * be fine and we don't need to do a usb_clear_halt().
  1473. * - Jean II */
  1474. pr_debug("%s(), Received -EPIPE, ignoring...\n",
  1475. __func__);
  1476. break;
  1477. default:
  1478. pr_debug("%s(), Unknown error %d\n", __func__, ret);
  1479. ret = -EIO;
  1480. goto err_out_3;
  1481. }
  1482. /* Find our endpoints */
  1483. interface = intf->cur_altsetting;
  1484. if(!irda_usb_parse_endpoints(self, interface->endpoint,
  1485. interface->desc.bNumEndpoints)) {
  1486. net_err_ratelimited("%s(), Bogus endpoints...\n", __func__);
  1487. ret = -EIO;
  1488. goto err_out_3;
  1489. }
  1490. self->usbdev = dev;
  1491. /* Find IrDA class descriptor */
  1492. irda_desc = irda_usb_find_class_desc(intf);
  1493. ret = -ENODEV;
  1494. if (!irda_desc)
  1495. goto err_out_3;
  1496. if (self->needspatch) {
  1497. ret = usb_control_msg (self->usbdev, usb_sndctrlpipe (self->usbdev, 0),
  1498. 0x02, 0x40, 0, 0, NULL, 0, 500);
  1499. if (ret < 0) {
  1500. pr_debug("usb_control_msg failed %d\n", ret);
  1501. goto err_out_3;
  1502. } else {
  1503. mdelay(10);
  1504. }
  1505. }
  1506. self->irda_desc = irda_desc;
  1507. self->present = 1;
  1508. self->netopen = 0;
  1509. self->usbintf = intf;
  1510. /* Allocate the buffer for speed changes */
  1511. /* Don't change this buffer size and allocation without doing
  1512. * some heavy and complete testing. Don't ask why :-(
  1513. * Jean II */
  1514. self->speed_buff = kzalloc(IRDA_USB_SPEED_MTU, GFP_KERNEL);
  1515. if (!self->speed_buff)
  1516. goto err_out_3;
  1517. self->tx_buff = kzalloc(IRDA_SKB_MAX_MTU + self->header_length,
  1518. GFP_KERNEL);
  1519. if (!self->tx_buff)
  1520. goto err_out_4;
  1521. ret = irda_usb_open(self);
  1522. if (ret)
  1523. goto err_out_5;
  1524. net_info_ratelimited("IrDA: Registered device %s\n", net->name);
  1525. usb_set_intfdata(intf, self);
  1526. if (self->needspatch) {
  1527. /* Now we fetch and upload the firmware patch */
  1528. ret = stir421x_patch_device(self);
  1529. self->needspatch = (ret < 0);
  1530. if (self->needspatch) {
  1531. net_err_ratelimited("STIR421X: Couldn't upload patch\n");
  1532. goto err_out_6;
  1533. }
  1534. /* replace IrDA class descriptor with what patched device is now reporting */
  1535. irda_desc = irda_usb_find_class_desc (self->usbintf);
  1536. if (!irda_desc) {
  1537. ret = -ENODEV;
  1538. goto err_out_6;
  1539. }
  1540. kfree(self->irda_desc);
  1541. self->irda_desc = irda_desc;
  1542. irda_usb_init_qos(self);
  1543. }
  1544. return 0;
  1545. err_out_6:
  1546. unregister_netdev(self->netdev);
  1547. err_out_5:
  1548. kfree(self->tx_buff);
  1549. err_out_4:
  1550. kfree(self->speed_buff);
  1551. err_out_3:
  1552. /* Free all urbs that we may have created */
  1553. usb_free_urb(self->speed_urb);
  1554. err_out_2:
  1555. usb_free_urb(self->tx_urb);
  1556. err_out_1:
  1557. for (i = 0; i < self->max_rx_urb; i++)
  1558. usb_free_urb(self->rx_urb[i]);
  1559. kfree(self->rx_urb);
  1560. err_free_net:
  1561. free_netdev(net);
  1562. err_out:
  1563. return ret;
  1564. }
  1565. /*------------------------------------------------------------------*/
  1566. /*
  1567. * The current irda-usb device is removed, the USB layer tell us
  1568. * to shut it down...
  1569. * One of the constraints is that when we exit this function,
  1570. * we cannot use the usb_device no more. Gone. Destroyed. kfree().
  1571. * Most other subsystem allow you to destroy the instance at a time
  1572. * when it's convenient to you, to postpone it to a later date, but
  1573. * not the USB subsystem.
  1574. * So, we must make bloody sure that everything gets deactivated.
  1575. * Jean II
  1576. */
  1577. static void irda_usb_disconnect(struct usb_interface *intf)
  1578. {
  1579. unsigned long flags;
  1580. struct irda_usb_cb *self = usb_get_intfdata(intf);
  1581. int i;
  1582. usb_set_intfdata(intf, NULL);
  1583. if (!self)
  1584. return;
  1585. /* Make sure that the Tx path is not executing. - Jean II */
  1586. spin_lock_irqsave(&self->lock, flags);
  1587. /* Oups ! We are not there any more.
  1588. * This will stop/desactivate the Tx path. - Jean II */
  1589. self->present = 0;
  1590. /* Kill defered Rx URB */
  1591. del_timer(&self->rx_defer_timer);
  1592. /* We need to have irq enabled to unlink the URBs. That's OK,
  1593. * at this point the Tx path is gone - Jean II */
  1594. spin_unlock_irqrestore(&self->lock, flags);
  1595. /* Hum... Check if networking is still active (avoid races) */
  1596. if((self->netopen) || (self->irlap)) {
  1597. /* Accept no more transmissions */
  1598. /*netif_device_detach(self->netdev);*/
  1599. netif_stop_queue(self->netdev);
  1600. /* Stop all the receive URBs. Must be synchronous. */
  1601. for (i = 0; i < self->max_rx_urb; i++)
  1602. usb_kill_urb(self->rx_urb[i]);
  1603. /* Cancel Tx and speed URB.
  1604. * Make sure it's synchronous to avoid races. */
  1605. usb_kill_urb(self->tx_urb);
  1606. usb_kill_urb(self->speed_urb);
  1607. }
  1608. /* Cleanup the device stuff */
  1609. irda_usb_close(self);
  1610. /* No longer attached to USB bus */
  1611. self->usbdev = NULL;
  1612. self->usbintf = NULL;
  1613. /* Clean up our urbs */
  1614. for (i = 0; i < self->max_rx_urb; i++)
  1615. usb_free_urb(self->rx_urb[i]);
  1616. kfree(self->rx_urb);
  1617. /* Clean up Tx and speed URB */
  1618. usb_free_urb(self->tx_urb);
  1619. usb_free_urb(self->speed_urb);
  1620. /* Free self and network device */
  1621. free_netdev(self->netdev);
  1622. pr_debug("%s(), USB IrDA Disconnected\n", __func__);
  1623. }
  1624. #ifdef CONFIG_PM
  1625. /* USB suspend, so power off the transmitter/receiver */
  1626. static int irda_usb_suspend(struct usb_interface *intf, pm_message_t message)
  1627. {
  1628. struct irda_usb_cb *self = usb_get_intfdata(intf);
  1629. int i;
  1630. netif_device_detach(self->netdev);
  1631. if (self->tx_urb != NULL)
  1632. usb_kill_urb(self->tx_urb);
  1633. if (self->speed_urb != NULL)
  1634. usb_kill_urb(self->speed_urb);
  1635. for (i = 0; i < self->max_rx_urb; i++) {
  1636. if (self->rx_urb[i] != NULL)
  1637. usb_kill_urb(self->rx_urb[i]);
  1638. }
  1639. return 0;
  1640. }
  1641. /* Coming out of suspend, so reset hardware */
  1642. static int irda_usb_resume(struct usb_interface *intf)
  1643. {
  1644. struct irda_usb_cb *self = usb_get_intfdata(intf);
  1645. int i;
  1646. for (i = 0; i < self->max_rx_urb; i++) {
  1647. if (self->rx_urb[i] != NULL)
  1648. usb_submit_urb(self->rx_urb[i], GFP_KERNEL);
  1649. }
  1650. netif_device_attach(self->netdev);
  1651. return 0;
  1652. }
  1653. #endif
  1654. /*------------------------------------------------------------------*/
  1655. /*
  1656. * USB device callbacks
  1657. */
  1658. static struct usb_driver irda_driver = {
  1659. .name = "irda-usb",
  1660. .probe = irda_usb_probe,
  1661. .disconnect = irda_usb_disconnect,
  1662. .id_table = dongles,
  1663. #ifdef CONFIG_PM
  1664. .suspend = irda_usb_suspend,
  1665. .resume = irda_usb_resume,
  1666. #endif
  1667. };
  1668. module_usb_driver(irda_driver);
  1669. /*
  1670. * Module parameters
  1671. */
  1672. module_param(qos_mtt_bits, int, 0);
  1673. MODULE_PARM_DESC(qos_mtt_bits, "Minimum Turn Time");
  1674. MODULE_AUTHOR("Roman Weissgaerber <weissg@vienna.at>, Dag Brattli <dag@brattli.net>, Jean Tourrilhes <jt@hpl.hp.com> and Nick Fedchik <nick@fedchik.org.ua>");
  1675. MODULE_DESCRIPTION("IrDA-USB Dongle Driver");
  1676. MODULE_LICENSE("GPL");