1 /*****************************************************************************
5 * Description: IrDA-USB Driver
7 * Author: Dag Brattli <dag@brattli.net>
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>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *****************************************************************************/
33 * As of kernel 2.5.20, this is the state of compliance and testing of
34 * this driver (irda-usb) with regards to the USB low level drivers...
36 * This driver has been tested SUCCESSFULLY with the following drivers :
37 * o usb-uhci-hcd (For Intel/Via USB controllers)
38 * o uhci-hcd (Alternate/JE driver for Intel/Via USB controllers)
39 * o ohci-hcd (For other USB controllers)
41 * This driver has NOT been tested with the following drivers :
42 * o ehci-hcd (USB 2.0 controllers)
44 * Note that all HCD drivers do URB_ZERO_PACKET and timeout properly,
45 * so we don't have to worry about that anymore.
46 * One common problem is the failure to set the address on the dongle,
47 * but this happens before the driver gets loaded...
52 /*------------------------------------------------------------------*/
54 #include <linux/module.h>
55 #include <linux/moduleparam.h>
56 #include <linux/kernel.h>
57 #include <linux/types.h>
58 #include <linux/init.h>
59 #include <linux/skbuff.h>
60 #include <linux/netdevice.h>
61 #include <linux/slab.h>
62 #include <linux/rtnetlink.h>
63 #include <linux/usb.h>
67 /*------------------------------------------------------------------*/
69 static int qos_mtt_bits = 0;
71 /* These are the currently known IrDA USB dongles. Add new dongles here */
72 static struct usb_device_id dongles[] = {
73 /* ACTiSYS Corp., ACT-IR2000U FIR-USB Adapter */
74 { USB_DEVICE(0x9c4, 0x011), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
75 /* Look like ACTiSYS, Report : IBM Corp., IBM UltraPort IrDA */
76 { USB_DEVICE(0x4428, 0x012), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
77 /* KC Technology Inc., KC-180 USB IrDA Device */
78 { USB_DEVICE(0x50f, 0x180), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
79 /* Extended Systems, Inc., XTNDAccess IrDA USB (ESI-9685) */
80 { USB_DEVICE(0x8e9, 0x100), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
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, },
91 * Devices based on the SigmaTel chipset (0x66f, 0x4200) are not designed
92 * using the "USB-IrDA specification" (yes, there exist such a thing), and
93 * therefore not supported by this driver (don't add them above).
94 * There is a Linux driver, stir4200, that support those USB devices.
98 MODULE_DEVICE_TABLE(usb, dongles);
100 /*------------------------------------------------------------------*/
102 static struct irda_class_desc *irda_usb_find_class_desc(struct usb_interface *intf);
103 static void irda_usb_disconnect(struct usb_interface *intf);
104 static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self);
105 static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *dev);
106 static int irda_usb_open(struct irda_usb_cb *self);
107 static void irda_usb_close(struct irda_usb_cb *self);
108 static void speed_bulk_callback(struct urb *urb, struct pt_regs *regs);
109 static void write_bulk_callback(struct urb *urb, struct pt_regs *regs);
110 static void irda_usb_receive(struct urb *urb, struct pt_regs *regs);
111 static int irda_usb_net_open(struct net_device *dev);
112 static int irda_usb_net_close(struct net_device *dev);
113 static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
114 static void irda_usb_net_timeout(struct net_device *dev);
115 static struct net_device_stats *irda_usb_net_get_stats(struct net_device *dev);
117 /************************ TRANSMIT ROUTINES ************************/
119 * Receive packets from the IrDA stack and send them on the USB pipe.
120 * Handle speed change, timeout and lot's of ugliness...
123 /*------------------------------------------------------------------*/
125 * Function irda_usb_build_header(self, skb, header)
127 * Builds USB-IrDA outbound header
129 * When we send an IrDA frame over an USB pipe, we add to it a 1 byte
130 * header. This function create this header with the proper values.
132 * Important note : the USB-IrDA spec 1.0 say very clearly in chapter 5.4.2.2
133 * that the setting of the link speed and xbof number in this outbound header
134 * should be applied *AFTER* the frame has been sent.
135 * Unfortunately, some devices are not compliant with that... It seems that
136 * reading the spec is far too difficult...
139 static void irda_usb_build_header(struct irda_usb_cb *self,
143 /* Set the negotiated link speed */
144 if (self->new_speed != -1) {
145 /* Hum... Ugly hack :-(
146 * Some device are not compliant with the spec and change
147 * parameters *before* sending the frame. - Jean II
149 if ((self->capability & IUC_SPEED_BUG) &&
150 (!force) && (self->speed != -1)) {
151 /* No speed and xbofs change here
152 * (we'll do it later in the write callback) */
153 IRDA_DEBUG(2, "%s(), not changing speed yet\n", __FUNCTION__);
158 IRDA_DEBUG(2, "%s(), changing speed to %d\n", __FUNCTION__, self->new_speed);
159 self->speed = self->new_speed;
160 /* We will do ` self->new_speed = -1; ' in the completion
161 * handler just in case the current URB fail - Jean II */
163 switch (self->speed) {
165 *header = SPEED_2400;
169 *header = SPEED_9600;
172 *header = SPEED_19200;
175 *header = SPEED_38400;
178 *header = SPEED_57600;
181 *header = SPEED_115200;
184 *header = SPEED_576000;
187 *header = SPEED_1152000;
190 *header = SPEED_4000000;
198 /* Set the negotiated additional XBOFS */
199 if (self->new_xbofs != -1) {
200 IRDA_DEBUG(2, "%s(), changing xbofs to %d\n", __FUNCTION__, self->new_xbofs);
201 self->xbofs = self->new_xbofs;
202 /* We will do ` self->new_xbofs = -1; ' in the completion
203 * handler just in case the current URB fail - Jean II */
205 switch (self->xbofs) {
210 case 24: /* USB spec 1.0 says 24 */
217 case 5: /* Bug in IrLAP spec? (should be 6) */
237 /*------------------------------------------------------------------*/
239 * Send a command to change the speed of the dongle
240 * Need to be called with spinlock on.
242 static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
248 IRDA_DEBUG(2, "%s(), speed=%d, xbofs=%d\n", __FUNCTION__,
249 self->new_speed, self->new_xbofs);
251 /* Grab the speed URB */
252 urb = self->speed_urb;
253 if (urb->status != 0) {
254 IRDA_WARNING("%s(), URB still in use!\n", __FUNCTION__);
258 /* Allocate the fake frame */
259 frame = self->speed_buff;
261 /* Set the new speed and xbofs in this fake frame */
262 irda_usb_build_header(self, frame, 1);
264 /* Submit the 0 length IrDA frame to trigger new speed settings */
265 usb_fill_bulk_urb(urb, self->usbdev,
266 usb_sndbulkpipe(self->usbdev, self->bulk_out_ep),
267 frame, IRDA_USB_SPEED_MTU,
268 speed_bulk_callback, self);
269 urb->transfer_buffer_length = USB_IRDA_HEADER;
270 urb->transfer_flags = 0;
272 /* Irq disabled -> GFP_ATOMIC */
273 if ((ret = usb_submit_urb(urb, GFP_ATOMIC))) {
274 IRDA_WARNING("%s(), failed Speed URB\n", __FUNCTION__);
278 /*------------------------------------------------------------------*/
281 * Now, we can only get called for the speed URB.
283 static void speed_bulk_callback(struct urb *urb, struct pt_regs *regs)
285 struct irda_usb_cb *self = urb->context;
287 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
289 /* We should always have a context */
290 IRDA_ASSERT(self != NULL, return;);
291 /* We should always be called for the speed URB */
292 IRDA_ASSERT(urb == self->speed_urb, return;);
294 /* Check for timeout and other USB nasties */
295 if (urb->status != 0) {
296 /* I get a lot of -ECONNABORTED = -103 here - Jean II */
297 IRDA_DEBUG(0, "%s(), URB complete status %d, transfer_flags 0x%04X\n", __FUNCTION__, urb->status, urb->transfer_flags);
299 /* Don't do anything here, that might confuse the USB layer.
300 * Instead, we will wait for irda_usb_net_timeout(), the
301 * network layer watchdog, to fix the situation.
303 /* A reset of the dongle might be welcomed here - Jean II */
307 /* urb is now available */
308 //urb->status = 0; -> tested above
310 /* New speed and xbof is now commited in hardware */
311 self->new_speed = -1;
312 self->new_xbofs = -1;
314 /* Allow the stack to send more packets */
315 netif_wake_queue(self->netdev);
318 /*------------------------------------------------------------------*/
320 * Send an IrDA frame to the USB dongle (for transmission)
322 static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
324 struct irda_usb_cb *self = netdev->priv;
325 struct urb *urb = self->tx_urb;
330 int err = 1; /* Failed */
332 IRDA_DEBUG(4, "%s() on %s\n", __FUNCTION__, netdev->name);
334 netif_stop_queue(netdev);
336 /* Protect us from USB callbacks, net watchdog and else. */
337 spin_lock_irqsave(&self->lock, flags);
339 /* Check if the device is still there.
340 * We need to check self->present under the spinlock because
341 * of irda_usb_disconnect() is synchronous - Jean II */
342 if (!self->present) {
343 IRDA_DEBUG(0, "%s(), Device is gone...\n", __FUNCTION__);
347 /* Check if we need to change the number of xbofs */
348 xbofs = irda_get_next_xbofs(skb);
349 if ((xbofs != self->xbofs) && (xbofs != -1)) {
350 self->new_xbofs = xbofs;
353 /* Check if we need to change the speed */
354 speed = irda_get_next_speed(skb);
355 if ((speed != self->speed) && (speed != -1)) {
356 /* Set the desired speed */
357 self->new_speed = speed;
359 /* Check for empty frame */
361 /* IrLAP send us an empty frame to make us change the
362 * speed. Changing speed with the USB adapter is in
363 * fact sending an empty frame to the adapter, so we
364 * could just let the present function do its job.
365 * However, we would wait for min turn time,
366 * do an extra memcpy and increment packet counters...
368 irda_usb_change_speed_xbofs(self);
369 netdev->trans_start = jiffies;
370 /* Will netif_wake_queue() in callback */
371 err = 0; /* No error */
376 if (urb->status != 0) {
377 IRDA_WARNING("%s(), URB still in use!\n", __FUNCTION__);
381 /* Make sure there is room for IrDA-USB header. The actual
382 * allocation will be done lower in skb_push().
383 * Also, we don't use directly skb_cow(), because it require
384 * headroom >= 16, which force unnecessary copies - Jean II */
385 if (skb_headroom(skb) < USB_IRDA_HEADER) {
386 IRDA_DEBUG(0, "%s(), Insuficient skb headroom.\n", __FUNCTION__);
387 if (skb_cow(skb, USB_IRDA_HEADER)) {
388 IRDA_WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__);
393 /* Change setting for next frame */
394 irda_usb_build_header(self, skb_push(skb, USB_IRDA_HEADER), 0);
396 /* FIXME: Make macro out of this one */
397 ((struct irda_skb_cb *)skb->cb)->context = self;
399 usb_fill_bulk_urb(urb, self->usbdev,
400 usb_sndbulkpipe(self->usbdev, self->bulk_out_ep),
401 skb->data, IRDA_SKB_MAX_MTU,
402 write_bulk_callback, skb);
403 urb->transfer_buffer_length = skb->len;
404 /* This flag (URB_ZERO_PACKET) indicates that what we send is not
405 * a continuous stream of data but separate packets.
406 * In this case, the USB layer will insert an empty USB frame (TD)
407 * after each of our packets that is exact multiple of the frame size.
408 * This is how the dongle will detect the end of packet - Jean II */
409 urb->transfer_flags = URB_ZERO_PACKET;
411 /* Generate min turn time. FIXME: can we do better than this? */
412 /* Trying to a turnaround time at this level is trying to measure
413 * processor clock cycle with a wrist-watch, approximate at best...
415 * What we know is the last time we received a frame over USB.
416 * Due to latency over USB that depend on the USB load, we don't
417 * know when this frame was received over IrDA (a few ms before ?)
418 * Then, same story for our outgoing frame...
420 * In theory, the USB dongle is supposed to handle the turnaround
421 * by itself (spec 1.0, chater 4, page 6). Who knows ??? That's
422 * why this code is enabled only for dongles that doesn't meet
425 if (self->capability & IUC_NO_TURN) {
426 mtt = irda_get_mtt(skb);
429 do_gettimeofday(&self->now);
430 diff = self->now.tv_usec - self->stamp.tv_usec;
431 #ifdef IU_USB_MIN_RTT
432 /* Factor in USB delays -> Get rid of udelay() that
433 * would be lost in the noise - Jean II */
434 diff += IU_USB_MIN_RTT;
435 #endif /* IU_USB_MIN_RTT */
436 /* If the usec counter did wraparound, the diff will
437 * go negative (tv_usec is a long), so we need to
438 * correct it by one second. Jean II */
442 /* Check if the mtt is larger than the time we have
443 * already used by all the protocol processing
455 /* Ask USB to send the packet - Irq disabled -> GFP_ATOMIC */
456 if ((res = usb_submit_urb(urb, GFP_ATOMIC))) {
457 IRDA_WARNING("%s(), failed Tx URB\n", __FUNCTION__);
458 self->stats.tx_errors++;
459 /* Let USB recover : We will catch that in the watchdog */
460 /*netif_start_queue(netdev);*/
462 /* Increment packet stats */
463 self->stats.tx_packets++;
464 self->stats.tx_bytes += skb->len;
466 netdev->trans_start = jiffies;
468 spin_unlock_irqrestore(&self->lock, flags);
473 /* Drop silently the skb and exit */
475 spin_unlock_irqrestore(&self->lock, flags);
476 return err; /* Usually 1 */
479 /*------------------------------------------------------------------*/
481 * Note : this function will be called only for tx_urb...
483 static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
486 struct sk_buff *skb = urb->context;
487 struct irda_usb_cb *self = ((struct irda_skb_cb *) skb->cb)->context;
489 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
491 /* We should always have a context */
492 IRDA_ASSERT(self != NULL, return;);
493 /* We should always be called for the speed URB */
494 IRDA_ASSERT(urb == self->tx_urb, return;);
496 /* Free up the skb */
497 dev_kfree_skb_any(skb);
500 /* Check for timeout and other USB nasties */
501 if (urb->status != 0) {
502 /* I get a lot of -ECONNABORTED = -103 here - Jean II */
503 IRDA_DEBUG(0, "%s(), URB complete status %d, transfer_flags 0x%04X\n", __FUNCTION__, urb->status, urb->transfer_flags);
505 /* Don't do anything here, that might confuse the USB layer,
506 * and we could go in recursion and blow the kernel stack...
507 * Instead, we will wait for irda_usb_net_timeout(), the
508 * network layer watchdog, to fix the situation.
510 /* A reset of the dongle might be welcomed here - Jean II */
514 /* urb is now available */
515 //urb->status = 0; -> tested above
517 /* Make sure we read self->present properly */
518 spin_lock_irqsave(&self->lock, flags);
520 /* If the network is closed, stop everything */
521 if ((!self->netopen) || (!self->present)) {
522 IRDA_DEBUG(0, "%s(), Network is gone...\n", __FUNCTION__);
523 spin_unlock_irqrestore(&self->lock, flags);
527 /* If changes to speed or xbofs is pending... */
528 if ((self->new_speed != -1) || (self->new_xbofs != -1)) {
529 if ((self->new_speed != self->speed) ||
530 (self->new_xbofs != self->xbofs)) {
531 /* We haven't changed speed yet (because of
532 * IUC_SPEED_BUG), so do it now - Jean II */
533 IRDA_DEBUG(1, "%s(), Changing speed now...\n", __FUNCTION__);
534 irda_usb_change_speed_xbofs(self);
536 /* New speed and xbof is now commited in hardware */
537 self->new_speed = -1;
538 self->new_xbofs = -1;
539 /* Done, waiting for next packet */
540 netif_wake_queue(self->netdev);
543 /* Otherwise, allow the stack to send more packets */
544 netif_wake_queue(self->netdev);
546 spin_unlock_irqrestore(&self->lock, flags);
549 /*------------------------------------------------------------------*/
551 * Watchdog timer from the network layer.
552 * After a predetermined timeout, if we don't give confirmation that
553 * the packet has been sent (i.e. no call to netif_wake_queue()),
554 * the network layer will call this function.
555 * Note that URB that we submit have also a timeout. When the URB timeout
556 * expire, the normal URB callback is called (write_bulk_callback()).
558 static void irda_usb_net_timeout(struct net_device *netdev)
561 struct irda_usb_cb *self = netdev->priv;
563 int done = 0; /* If we have made any progress */
565 IRDA_DEBUG(0, "%s(), Network layer thinks we timed out!\n", __FUNCTION__);
566 IRDA_ASSERT(self != NULL, return;);
568 /* Protect us from USB callbacks, net Tx and else. */
569 spin_lock_irqsave(&self->lock, flags);
571 /* self->present *MUST* be read under spinlock */
572 if (!self->present) {
573 IRDA_WARNING("%s(), device not present!\n", __FUNCTION__);
574 netif_stop_queue(netdev);
575 spin_unlock_irqrestore(&self->lock, flags);
579 /* Check speed URB */
580 urb = self->speed_urb;
581 if (urb->status != 0) {
582 IRDA_DEBUG(0, "%s: Speed change timed out, urb->status=%d, urb->transfer_flags=0x%04X\n", netdev->name, urb->status, urb->transfer_flags);
584 switch (urb->status) {
587 /* Note : above will *NOT* call netif_wake_queue()
588 * in completion handler, we will come back here.
592 case -ECONNABORTED: /* -103 */
593 case -ECONNRESET: /* -104 */
594 case -ETIMEDOUT: /* -110 */
595 case -ENOENT: /* -2 (urb unlinked by us) */
596 default: /* ??? - Play safe */
598 netif_wake_queue(self->netdev);
606 if (urb->status != 0) {
607 struct sk_buff *skb = urb->context;
609 IRDA_DEBUG(0, "%s: Tx timed out, urb->status=%d, urb->transfer_flags=0x%04X\n", netdev->name, urb->status, urb->transfer_flags);
611 /* Increase error count */
612 self->stats.tx_errors++;
614 #ifdef IU_BUG_KICK_TIMEOUT
615 /* Can't be a bad idea to reset the speed ;-) - Jean II */
616 if(self->new_speed == -1)
617 self->new_speed = self->speed;
618 if(self->new_xbofs == -1)
619 self->new_xbofs = self->xbofs;
620 irda_usb_change_speed_xbofs(self);
621 #endif /* IU_BUG_KICK_TIMEOUT */
623 switch (urb->status) {
626 /* Note : above will *NOT* call netif_wake_queue()
627 * in completion handler, because urb->status will
628 * be -ENOENT. We will fix that at the next watchdog,
629 * leaving more time to USB to recover...
633 case -ECONNABORTED: /* -103 */
634 case -ECONNRESET: /* -104 */
635 case -ETIMEDOUT: /* -110 */
636 case -ENOENT: /* -2 (urb unlinked by us) */
637 default: /* ??? - Play safe */
639 dev_kfree_skb_any(skb);
643 netif_wake_queue(self->netdev);
648 spin_unlock_irqrestore(&self->lock, flags);
650 /* Maybe we need a reset */
651 /* Note : Some drivers seem to use a usb_set_interface() when they
652 * need to reset the hardware. Hum...
658 /************************* RECEIVE ROUTINES *************************/
660 * Receive packets from the USB layer stack and pass them to the IrDA stack.
661 * Try to work around USB failures...
666 * Some of you may have noticed that most dongle have an interrupt in pipe
667 * that we don't use. Here is the little secret...
668 * When we hang a Rx URB on the bulk in pipe, it generates some USB traffic
669 * in every USB frame. This is unnecessary overhead.
670 * The interrupt in pipe will generate an event every time a packet is
671 * received. Reading an interrupt pipe adds minimal overhead, but has some
673 * If we are connected (speed != 9600), we want to minimise latency, so
674 * we just always hang the Rx URB and ignore the interrupt.
675 * If we are not connected (speed == 9600), there is usually no Rx traffic,
676 * and we want to minimise the USB overhead. In this case we should wait
677 * on the interrupt pipe and hang the Rx URB only when an interrupt is
682 /*------------------------------------------------------------------*/
684 * Submit a Rx URB to the USB layer to handle reception of a frame
685 * Mostly called by the completion callback of the previous URB.
689 static void irda_usb_submit(struct irda_usb_cb *self, struct sk_buff *skb, struct urb *urb)
691 struct irda_skb_cb *cb;
694 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
696 /* This should never happen */
697 IRDA_ASSERT(skb != NULL, return;);
698 IRDA_ASSERT(urb != NULL, return;);
700 /* Save ourselves in the skb */
701 cb = (struct irda_skb_cb *) skb->cb;
704 /* Reinitialize URB */
705 usb_fill_bulk_urb(urb, self->usbdev,
706 usb_rcvbulkpipe(self->usbdev, self->bulk_in_ep),
707 skb->data, skb->truesize,
708 irda_usb_receive, skb);
709 /* Note : unlink *must* be synchronous because of the code in
710 * irda_usb_net_close() -> free the skb - Jean II */
713 /* Can be called from irda_usb_receive (irq handler) -> GFP_ATOMIC */
714 ret = usb_submit_urb(urb, GFP_ATOMIC);
716 /* If this ever happen, we are in deep s***.
717 * Basically, the Rx path will stop... */
718 IRDA_WARNING("%s(), Failed to submit Rx URB %d\n",
723 /*------------------------------------------------------------------*/
725 * Function irda_usb_receive(urb)
727 * Called by the USB subsystem when a frame has been received
730 static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
732 struct sk_buff *skb = (struct sk_buff *) urb->context;
733 struct irda_usb_cb *self;
734 struct irda_skb_cb *cb;
735 struct sk_buff *newskb;
736 struct sk_buff *dataskb;
739 IRDA_DEBUG(2, "%s(), len=%d\n", __FUNCTION__, urb->actual_length);
742 cb = (struct irda_skb_cb *) skb->cb;
743 IRDA_ASSERT(cb != NULL, return;);
744 self = (struct irda_usb_cb *) cb->context;
745 IRDA_ASSERT(self != NULL, return;);
747 /* If the network is closed or the device gone, stop everything */
748 if ((!self->netopen) || (!self->present)) {
749 IRDA_DEBUG(0, "%s(), Network is gone!\n", __FUNCTION__);
750 /* Don't re-submit the URB : will stall the Rx path */
754 /* Check the status */
755 if (urb->status != 0) {
756 switch (urb->status) {
758 self->stats.rx_errors++;
759 self->stats.rx_crc_errors++;
761 case -ECONNRESET: /* -104 */
762 IRDA_DEBUG(0, "%s(), Connection Reset (-104), transfer_flags 0x%04X \n", __FUNCTION__, urb->transfer_flags);
763 /* uhci_cleanup_unlink() is going to kill the Rx
764 * URB just after we return. No problem, at this
765 * point the URB will be idle ;-) - Jean II */
768 IRDA_DEBUG(0, "%s(), RX status %d,transfer_flags 0x%04X \n", __FUNCTION__, urb->status, urb->transfer_flags);
774 /* Check for empty frames */
775 if (urb->actual_length <= USB_IRDA_HEADER) {
776 IRDA_WARNING("%s(), empty frame!\n", __FUNCTION__);
781 * Remember the time we received this frame, so we can
782 * reduce the min turn time a bit since we will know
783 * how much time we have used for protocol processing
785 do_gettimeofday(&self->stamp);
787 /* Check if we need to copy the data to a new skb or not.
788 * For most frames, we use ZeroCopy and pass the already
789 * allocated skb up the stack.
790 * If the frame is small, it is more efficient to copy it
791 * to save memory (copy will be fast anyway - that's
792 * called Rx-copy-break). Jean II */
793 docopy = (urb->actual_length < IRDA_RX_COPY_THRESHOLD);
795 /* Allocate a new skb */
796 newskb = dev_alloc_skb(docopy ? urb->actual_length : IRDA_SKB_MAX_MTU);
798 self->stats.rx_dropped++;
799 /* We could deliver the current skb, but this would stall
800 * the Rx path. Better drop the packet... Jean II */
804 /* Make sure IP header get aligned (IrDA header is 5 bytes) */
805 /* But IrDA-USB header is 1 byte. Jean II */
806 //skb_reserve(newskb, USB_IRDA_HEADER - 1);
809 /* Copy packet, so we can recycle the original */
810 memcpy(newskb->data, skb->data, urb->actual_length);
811 /* Deliver this new skb */
813 /* And hook the old skb to the URB
814 * Note : we don't need to "clean up" the old skb,
815 * as we never touched it. Jean II */
817 /* We are using ZeroCopy. Deliver old skb */
819 /* And hook the new skb to the URB */
823 /* Set proper length on skb & remove USB-IrDA header */
824 skb_put(dataskb, urb->actual_length);
825 skb_pull(dataskb, USB_IRDA_HEADER);
827 /* Ask the networking layer to queue the packet for the IrDA stack */
828 dataskb->dev = self->netdev;
829 dataskb->mac.raw = dataskb->data;
830 dataskb->protocol = htons(ETH_P_IRDA);
833 /* Keep stats up to date */
834 self->stats.rx_bytes += dataskb->len;
835 self->stats.rx_packets++;
836 self->netdev->last_rx = jiffies;
839 /* Note : at this point, the URB we've just received (urb)
840 * is still referenced by the USB layer. For example, if we
841 * have received a -ECONNRESET, uhci_cleanup_unlink() will
842 * continue to process it (in fact, cleaning it up).
843 * If we were to submit this URB, disaster would ensue.
844 * Therefore, we submit our idle URB, and put this URB in our
847 /* Note : with this scheme, we could submit the idle URB before
848 * processing the Rx URB. Another time... Jean II */
850 /* Submit the idle URB to replace the URB we've just received */
851 irda_usb_submit(self, skb, self->idle_rx_urb);
852 /* Recycle Rx URB : Now, the idle URB is the present one */
854 self->idle_rx_urb = urb;
857 /*------------------------------------------------------------------*/
859 * Callbak from IrDA layer. IrDA wants to know if we have
860 * started receiving anything.
862 static int irda_usb_is_receiving(struct irda_usb_cb *self)
864 /* Note : because of the way UHCI works, it's almost impossible
865 * to get this info. The Controller DMA directly to memory and
866 * signal only when the whole frame is finished. To know if the
867 * first TD of the URB has been filled or not seems hard work...
869 * The other solution would be to use the "receiving" command
870 * on the default decriptor with a usb_control_msg(), but that
871 * would add USB traffic and would return result only in the
872 * next USB frame (~1ms).
874 * I've been told that current dongles send status info on their
875 * interrupt endpoint, and that's what the Windows driver uses
876 * to know this info. Unfortunately, this is not yet in the spec...
881 return 0; /* For now */
884 /********************** IRDA DEVICE CALLBACKS **********************/
886 * Main calls from the IrDA/Network subsystem.
887 * Mostly registering a new irda-usb device and removing it....
888 * We only deal with the IrDA side of the business, the USB side will
889 * be dealt with below...
893 /*------------------------------------------------------------------*/
895 * Function irda_usb_net_open (dev)
897 * Network device is taken up. Usually this is done by "ifconfig irda0 up"
899 * Note : don't mess with self->netopen - Jean II
901 static int irda_usb_net_open(struct net_device *netdev)
903 struct irda_usb_cb *self;
907 IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
909 IRDA_ASSERT(netdev != NULL, return -1;);
910 self = (struct irda_usb_cb *) netdev->priv;
911 IRDA_ASSERT(self != NULL, return -1;);
913 /* Can only open the device if it's there */
915 IRDA_WARNING("%s(), device not present!\n", __FUNCTION__);
919 /* Initialise default speed and xbofs value
920 * (IrLAP will change that soon) */
923 self->new_speed = -1;
924 self->new_xbofs = -1;
926 /* To do *before* submitting Rx urbs and starting net Tx queue
931 * Now that everything should be initialized properly,
932 * Open new IrLAP layer instance to take care of us...
933 * Note : will send immediately a speed change...
935 sprintf(hwname, "usb#%d", self->usbdev->devnum);
936 self->irlap = irlap_open(netdev, &self->qos, hwname);
937 IRDA_ASSERT(self->irlap != NULL, return -1;);
939 /* Allow IrLAP to send data to us */
940 netif_start_queue(netdev);
942 /* We submit all the Rx URB except for one that we keep idle.
943 * Need to be initialised before submitting other USBs, because
944 * in some cases as soon as we submit the URBs the USB layer
945 * will trigger a dummy receive - Jean II */
946 self->idle_rx_urb = self->rx_urb[IU_MAX_ACTIVE_RX_URBS];
947 self->idle_rx_urb->context = NULL;
949 /* Now that we can pass data to IrLAP, allow the USB layer
950 * to send us some data... */
951 for (i = 0; i < IU_MAX_ACTIVE_RX_URBS; i++) {
952 struct sk_buff *skb = dev_alloc_skb(IRDA_SKB_MAX_MTU);
954 /* If this ever happen, we are in deep s***.
955 * Basically, we can't start the Rx path... */
956 IRDA_WARNING("%s(), Failed to allocate Rx skb\n",
960 //skb_reserve(newskb, USB_IRDA_HEADER - 1);
961 irda_usb_submit(self, skb, self->rx_urb[i]);
964 /* Ready to play !!! */
968 /*------------------------------------------------------------------*/
970 * Function irda_usb_net_close (self)
972 * Network device is taken down. Usually this is done by
973 * "ifconfig irda0 down"
975 static int irda_usb_net_close(struct net_device *netdev)
977 struct irda_usb_cb *self;
980 IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
982 IRDA_ASSERT(netdev != NULL, return -1;);
983 self = (struct irda_usb_cb *) netdev->priv;
984 IRDA_ASSERT(self != NULL, return -1;);
986 /* Clear this flag *before* unlinking the urbs and *before*
987 * stopping the network Tx queue - Jean II */
990 /* Stop network Tx queue */
991 netif_stop_queue(netdev);
993 /* Deallocate all the Rx path buffers (URBs and skb) */
994 for (i = 0; i < IU_MAX_RX_URBS; i++) {
995 struct urb *urb = self->rx_urb[i];
996 struct sk_buff *skb = (struct sk_buff *) urb->context;
997 /* Cancel the receive command */
999 /* The skb is ours, free it */
1002 urb->context = NULL;
1005 /* Cancel Tx and speed URB - need to be synchronous to avoid races */
1006 usb_kill_urb(self->tx_urb);
1007 usb_kill_urb(self->speed_urb);
1009 /* Stop and remove instance of IrLAP */
1011 irlap_close(self->irlap);
1017 /*------------------------------------------------------------------*/
1019 * IOCTLs : Extra out-of-band network commands...
1021 static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1023 unsigned long flags;
1024 struct if_irda_req *irq = (struct if_irda_req *) rq;
1025 struct irda_usb_cb *self;
1028 IRDA_ASSERT(dev != NULL, return -1;);
1030 IRDA_ASSERT(self != NULL, return -1;);
1032 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
1035 case SIOCSBANDWIDTH: /* Set bandwidth */
1036 if (!capable(CAP_NET_ADMIN))
1038 /* Protect us from USB callbacks, net watchdog and else. */
1039 spin_lock_irqsave(&self->lock, flags);
1040 /* Check if the device is still there */
1042 /* Set the desired speed */
1043 self->new_speed = irq->ifr_baudrate;
1044 irda_usb_change_speed_xbofs(self);
1046 spin_unlock_irqrestore(&self->lock, flags);
1048 case SIOCSMEDIABUSY: /* Set media busy */
1049 if (!capable(CAP_NET_ADMIN))
1051 /* Check if the IrDA stack is still there */
1053 irda_device_set_media_busy(self->netdev, TRUE);
1055 case SIOCGRECEIVING: /* Check if we are receiving right now */
1056 irq->ifr_receiving = irda_usb_is_receiving(self);
1065 /*------------------------------------------------------------------*/
1067 * Get device stats (for /proc/net/dev and ifconfig)
1069 static struct net_device_stats *irda_usb_net_get_stats(struct net_device *dev)
1071 struct irda_usb_cb *self = dev->priv;
1072 return &self->stats;
1075 /********************* IRDA CONFIG SUBROUTINES *********************/
1077 * Various subroutines dealing with IrDA and network stuff we use to
1078 * configure and initialise each irda-usb instance.
1079 * These functions are used below in the main calls of the driver...
1082 /*------------------------------------------------------------------*/
1084 * Set proper values in the IrDA QOS structure
1086 static inline void irda_usb_init_qos(struct irda_usb_cb *self)
1088 struct irda_class_desc *desc;
1090 IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
1092 desc = self->irda_desc;
1094 /* Initialize QoS for this device */
1095 irda_init_max_qos_capabilies(&self->qos);
1097 /* See spec section 7.2 for meaning.
1098 * Values are little endian (as most USB stuff), the IrDA stack
1099 * use it in native order (see parameters.c). - Jean II */
1100 self->qos.baud_rate.bits = le16_to_cpu(desc->wBaudRate);
1101 self->qos.min_turn_time.bits = desc->bmMinTurnaroundTime;
1102 self->qos.additional_bofs.bits = desc->bmAdditionalBOFs;
1103 self->qos.window_size.bits = desc->bmWindowSize;
1104 self->qos.data_size.bits = desc->bmDataSize;
1106 IRDA_DEBUG(0, "%s(), dongle says speed=0x%X, size=0x%X, window=0x%X, bofs=0x%X, turn=0x%X\n",
1107 __FUNCTION__, self->qos.baud_rate.bits, self->qos.data_size.bits, self->qos.window_size.bits, self->qos.additional_bofs.bits, self->qos.min_turn_time.bits);
1109 /* Don't always trust what the dongle tell us */
1110 if(self->capability & IUC_SIR_ONLY)
1111 self->qos.baud_rate.bits &= 0x00ff;
1112 if(self->capability & IUC_SMALL_PKT)
1113 self->qos.data_size.bits = 0x07;
1114 if(self->capability & IUC_NO_WINDOW)
1115 self->qos.window_size.bits = 0x01;
1116 if(self->capability & IUC_MAX_WINDOW)
1117 self->qos.window_size.bits = 0x7f;
1118 if(self->capability & IUC_MAX_XBOFS)
1119 self->qos.additional_bofs.bits = 0x01;
1122 /* Module parameter can override the rx window size */
1124 self->qos.min_turn_time.bits = qos_mtt_bits;
1127 * Note : most of those values apply only for the receive path,
1128 * the transmit path will be set differently - Jean II
1130 irda_qos_bits_to_value(&self->qos);
1133 /*------------------------------------------------------------------*/
1135 * Initialise the network side of the irda-usb instance
1136 * Called when a new USB instance is registered in irda_usb_probe()
1138 static inline int irda_usb_open(struct irda_usb_cb *self)
1140 struct net_device *netdev = self->netdev;
1142 IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
1144 irda_usb_init_qos(self);
1146 /* Override the network functions we need to use */
1147 netdev->hard_start_xmit = irda_usb_hard_xmit;
1148 netdev->tx_timeout = irda_usb_net_timeout;
1149 netdev->watchdog_timeo = 250*HZ/1000; /* 250 ms > USB timeout */
1150 netdev->open = irda_usb_net_open;
1151 netdev->stop = irda_usb_net_close;
1152 netdev->get_stats = irda_usb_net_get_stats;
1153 netdev->do_ioctl = irda_usb_net_ioctl;
1155 return register_netdev(netdev);
1158 /*------------------------------------------------------------------*/
1160 * Cleanup the network side of the irda-usb instance
1161 * Called when a USB instance is removed in irda_usb_disconnect()
1163 static inline void irda_usb_close(struct irda_usb_cb *self)
1165 IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
1167 /* Remove netdevice */
1168 unregister_netdev(self->netdev);
1170 /* Remove the speed buffer */
1171 if (self->speed_buff != NULL) {
1172 kfree(self->speed_buff);
1173 self->speed_buff = NULL;
1177 /********************** USB CONFIG SUBROUTINES **********************/
1179 * Various subroutines dealing with USB stuff we use to configure and
1180 * initialise each irda-usb instance.
1181 * These functions are used below in the main calls of the driver...
1184 /*------------------------------------------------------------------*/
1186 * Function irda_usb_parse_endpoints(dev, ifnum)
1188 * Parse the various endpoints and find the one we need.
1190 * The endpoint are the pipes used to communicate with the USB device.
1191 * The spec defines 2 endpoints of type bulk transfer, one in, and one out.
1192 * These are used to pass frames back and forth with the dongle.
1193 * Most dongle have also an interrupt endpoint, that will be probably
1194 * documented in the next spec...
1196 static inline int irda_usb_parse_endpoints(struct irda_usb_cb *self, struct usb_host_endpoint *endpoint, int ennum)
1198 int i; /* Endpoint index in table */
1200 /* Init : no endpoints */
1201 self->bulk_in_ep = 0;
1202 self->bulk_out_ep = 0;
1203 self->bulk_int_ep = 0;
1205 /* Let's look at all those endpoints */
1206 for(i = 0; i < ennum; i++) {
1207 /* All those variables will get optimised by the compiler,
1208 * so let's aim for clarity... - Jean II */
1209 __u8 ep; /* Endpoint address */
1210 __u8 dir; /* Endpoint direction */
1211 __u8 attr; /* Endpoint attribute */
1212 __u16 psize; /* Endpoint max packet size in bytes */
1214 /* Get endpoint address, direction and attribute */
1215 ep = endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
1216 dir = endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK;
1217 attr = endpoint[i].desc.bmAttributes;
1218 psize = le16_to_cpu(endpoint[i].desc.wMaxPacketSize);
1220 /* Is it a bulk endpoint ??? */
1221 if(attr == USB_ENDPOINT_XFER_BULK) {
1222 /* We need to find an IN and an OUT */
1223 if(dir == USB_DIR_IN) {
1224 /* This is our Rx endpoint */
1225 self->bulk_in_ep = ep;
1227 /* This is our Tx endpoint */
1228 self->bulk_out_ep = ep;
1229 self->bulk_out_mtu = psize;
1232 if((attr == USB_ENDPOINT_XFER_INT) &&
1233 (dir == USB_DIR_IN)) {
1234 /* This is our interrupt endpoint */
1235 self->bulk_int_ep = ep;
1237 IRDA_ERROR("%s(), Unrecognised endpoint %02X.\n", __FUNCTION__, ep);
1242 IRDA_DEBUG(0, "%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n",
1243 __FUNCTION__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep);
1244 /* Should be 8, 16, 32 or 64 bytes */
1245 IRDA_ASSERT(self->bulk_out_mtu == 64, ;);
1247 return((self->bulk_in_ep != 0) && (self->bulk_out_ep != 0));
1250 #ifdef IU_DUMP_CLASS_DESC
1251 /*------------------------------------------------------------------*/
1253 * Function usb_irda_dump_class_desc(desc)
1255 * Prints out the contents of the IrDA class descriptor
1258 static inline void irda_usb_dump_class_desc(struct irda_class_desc *desc)
1260 /* Values are little endian */
1261 printk("bLength=%x\n", desc->bLength);
1262 printk("bDescriptorType=%x\n", desc->bDescriptorType);
1263 printk("bcdSpecRevision=%x\n", le16_to_cpu(desc->bcdSpecRevision));
1264 printk("bmDataSize=%x\n", desc->bmDataSize);
1265 printk("bmWindowSize=%x\n", desc->bmWindowSize);
1266 printk("bmMinTurnaroundTime=%d\n", desc->bmMinTurnaroundTime);
1267 printk("wBaudRate=%x\n", le16_to_cpu(desc->wBaudRate));
1268 printk("bmAdditionalBOFs=%x\n", desc->bmAdditionalBOFs);
1269 printk("bIrdaRateSniff=%x\n", desc->bIrdaRateSniff);
1270 printk("bMaxUnicastList=%x\n", desc->bMaxUnicastList);
1272 #endif /* IU_DUMP_CLASS_DESC */
1274 /*------------------------------------------------------------------*/
1276 * Function irda_usb_find_class_desc(intf)
1278 * Returns instance of IrDA class descriptor, or NULL if not found
1280 * The class descriptor is some extra info that IrDA USB devices will
1281 * offer to us, describing their IrDA characteristics. We will use that in
1282 * irda_usb_init_qos()
1284 static inline struct irda_class_desc *irda_usb_find_class_desc(struct usb_interface *intf)
1286 struct usb_device *dev = interface_to_usbdev (intf);
1287 struct irda_class_desc *desc;
1290 desc = kmalloc(sizeof (*desc), GFP_KERNEL);
1293 memset(desc, 0, sizeof(*desc));
1295 /* USB-IrDA class spec 1.0:
1296 * 6.1.3: Standard "Get Descriptor" Device Request is not
1297 * appropriate to retrieve class-specific descriptor
1298 * 6.2.5: Class Specific "Get Class Descriptor" Interface Request
1299 * is mandatory and returns the USB-IrDA class descriptor
1302 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0),
1303 IU_REQ_GET_CLASS_DESC,
1304 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1305 0, intf->altsetting->desc.bInterfaceNumber, desc,
1306 sizeof(*desc), 500);
1308 IRDA_DEBUG(1, "%s(), ret=%d\n", __FUNCTION__, ret);
1309 if (ret < sizeof(*desc)) {
1310 IRDA_WARNING("usb-irda: class_descriptor read %s (%d)\n",
1311 (ret<0) ? "failed" : "too short", ret);
1313 else if (desc->bDescriptorType != USB_DT_IRDA) {
1314 IRDA_WARNING("usb-irda: bad class_descriptor type\n");
1317 #ifdef IU_DUMP_CLASS_DESC
1318 irda_usb_dump_class_desc(desc);
1319 #endif /* IU_DUMP_CLASS_DESC */
1327 /*********************** USB DEVICE CALLBACKS ***********************/
1329 * Main calls from the USB subsystem.
1330 * Mostly registering a new irda-usb device and removing it....
1333 /*------------------------------------------------------------------*/
1335 * This routine is called by the USB subsystem for each new device
1336 * in the system. We need to check if the device is ours, and in
1337 * this case start handling it.
1338 * The USB layer protect us from reentrancy (via BKL), so we don't need
1339 * to spinlock in there... Jean II
1341 static int irda_usb_probe(struct usb_interface *intf,
1342 const struct usb_device_id *id)
1344 struct net_device *net;
1345 struct usb_device *dev = interface_to_usbdev(intf);
1346 struct irda_usb_cb *self = NULL;
1347 struct usb_host_interface *interface;
1348 struct irda_class_desc *irda_desc;
1350 int i; /* Driver instance index / Rx URB index */
1352 /* Note : the probe make sure to call us only for devices that
1353 * matches the list of dongle (top of the file). So, we
1354 * don't need to check if the dongle is really ours.
1357 IRDA_MESSAGE("IRDA-USB found at address %d, Vendor: %x, Product: %x\n",
1358 dev->devnum, le16_to_cpu(dev->descriptor.idVendor),
1359 le16_to_cpu(dev->descriptor.idProduct));
1361 net = alloc_irdadev(sizeof(*self));
1365 SET_MODULE_OWNER(net);
1366 SET_NETDEV_DEV(net, &intf->dev);
1369 spin_lock_init(&self->lock);
1371 /* Create all of the needed urbs */
1372 for (i = 0; i < IU_MAX_RX_URBS; i++) {
1373 self->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
1374 if (!self->rx_urb[i]) {
1378 self->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
1379 if (!self->tx_urb) {
1382 self->speed_urb = usb_alloc_urb(0, GFP_KERNEL);
1383 if (!self->speed_urb) {
1387 /* Is this really necessary? (no, except maybe for broken devices) */
1388 if (usb_reset_configuration (dev) < 0) {
1389 err("reset_configuration failed");
1394 /* Is this really necessary? */
1395 /* Note : some driver do hardcode the interface number, some others
1396 * specify an alternate, but very few driver do like this.
1398 ret = usb_set_interface(dev, intf->altsetting->desc.bInterfaceNumber, 0);
1399 IRDA_DEBUG(1, "usb-irda: set interface %d result %d\n", intf->altsetting->desc.bInterfaceNumber, ret);
1403 case -EPIPE: /* -EPIPE = -32 */
1404 /* Martin Diehl says if we get a -EPIPE we should
1405 * be fine and we don't need to do a usb_clear_halt().
1407 IRDA_DEBUG(0, "%s(), Received -EPIPE, ignoring...\n", __FUNCTION__);
1410 IRDA_DEBUG(0, "%s(), Unknown error %d\n", __FUNCTION__, ret);
1415 /* Find our endpoints */
1416 interface = intf->cur_altsetting;
1417 if(!irda_usb_parse_endpoints(self, interface->endpoint,
1418 interface->desc.bNumEndpoints)) {
1419 IRDA_ERROR("%s(), Bogus endpoints...\n", __FUNCTION__);
1424 /* Find IrDA class descriptor */
1425 irda_desc = irda_usb_find_class_desc(intf);
1427 if (irda_desc == NULL)
1430 self->irda_desc = irda_desc;
1433 self->capability = id->driver_info;
1435 self->usbintf = intf;
1437 /* Allocate the buffer for speed changes */
1438 /* Don't change this buffer size and allocation without doing
1439 * some heavy and complete testing. Don't ask why :-(
1441 self->speed_buff = (char *) kmalloc(IRDA_USB_SPEED_MTU, GFP_KERNEL);
1442 if (self->speed_buff == NULL)
1445 memset(self->speed_buff, 0, IRDA_USB_SPEED_MTU);
1447 ret = irda_usb_open(self);
1451 IRDA_MESSAGE("IrDA: Registered device %s\n", net->name);
1452 usb_set_intfdata(intf, self);
1456 kfree(self->speed_buff);
1458 /* Free all urbs that we may have created */
1459 usb_free_urb(self->speed_urb);
1461 usb_free_urb(self->tx_urb);
1463 for (i = 0; i < IU_MAX_RX_URBS; i++) {
1464 if (self->rx_urb[i])
1465 usb_free_urb(self->rx_urb[i]);
1472 /*------------------------------------------------------------------*/
1474 * The current irda-usb device is removed, the USB layer tell us
1475 * to shut it down...
1476 * One of the constraints is that when we exit this function,
1477 * we cannot use the usb_device no more. Gone. Destroyed. kfree().
1478 * Most other subsystem allow you to destroy the instance at a time
1479 * when it's convenient to you, to postpone it to a later date, but
1480 * not the USB subsystem.
1481 * So, we must make bloody sure that everything gets deactivated.
1484 static void irda_usb_disconnect(struct usb_interface *intf)
1486 unsigned long flags;
1487 struct irda_usb_cb *self = usb_get_intfdata(intf);
1490 IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
1492 usb_set_intfdata(intf, NULL);
1496 /* Make sure that the Tx path is not executing. - Jean II */
1497 spin_lock_irqsave(&self->lock, flags);
1499 /* Oups ! We are not there any more.
1500 * This will stop/desactivate the Tx path. - Jean II */
1503 /* We need to have irq enabled to unlink the URBs. That's OK,
1504 * at this point the Tx path is gone - Jean II */
1505 spin_unlock_irqrestore(&self->lock, flags);
1507 /* Hum... Check if networking is still active (avoid races) */
1508 if((self->netopen) || (self->irlap)) {
1509 /* Accept no more transmissions */
1510 /*netif_device_detach(self->netdev);*/
1511 netif_stop_queue(self->netdev);
1512 /* Stop all the receive URBs */
1513 for (i = 0; i < IU_MAX_RX_URBS; i++)
1514 usb_kill_urb(self->rx_urb[i]);
1515 /* Cancel Tx and speed URB.
1516 * Toggle flags to make sure it's synchronous. */
1517 usb_kill_urb(self->tx_urb);
1518 usb_kill_urb(self->speed_urb);
1521 /* Cleanup the device stuff */
1522 irda_usb_close(self);
1523 /* No longer attached to USB bus */
1524 self->usbdev = NULL;
1525 self->usbintf = NULL;
1527 /* Clean up our urbs */
1528 for (i = 0; i < IU_MAX_RX_URBS; i++)
1529 usb_free_urb(self->rx_urb[i]);
1530 /* Clean up Tx and speed URB */
1531 usb_free_urb(self->tx_urb);
1532 usb_free_urb(self->speed_urb);
1534 /* Free self and network device */
1535 free_netdev(self->netdev);
1536 IRDA_DEBUG(0, "%s(), USB IrDA Disconnected\n", __FUNCTION__);
1539 /*------------------------------------------------------------------*/
1541 * USB device callbacks
1543 static struct usb_driver irda_driver = {
1544 .owner = THIS_MODULE,
1546 .probe = irda_usb_probe,
1547 .disconnect = irda_usb_disconnect,
1548 .id_table = dongles,
1551 /************************* MODULE CALLBACKS *************************/
1553 * Deal with module insertion/removal
1554 * Mostly tell USB about our existence
1557 /*------------------------------------------------------------------*/
1561 static int __init usb_irda_init(void)
1565 ret = usb_register(&irda_driver);
1569 IRDA_MESSAGE("USB IrDA support registered\n");
1572 module_init(usb_irda_init);
1574 /*------------------------------------------------------------------*/
1578 static void __exit usb_irda_cleanup(void)
1580 /* Deregister the driver and remove all pending instances */
1581 usb_deregister(&irda_driver);
1583 module_exit(usb_irda_cleanup);
1585 /*------------------------------------------------------------------*/
1589 module_param(qos_mtt_bits, int, 0);
1590 MODULE_PARM_DESC(qos_mtt_bits, "Minimum Turn Time");
1591 MODULE_AUTHOR("Roman Weissgaerber <weissg@vienna.at>, Dag Brattli <dag@brattli.net> and Jean Tourrilhes <jt@hpl.hp.com>");
1592 MODULE_DESCRIPTION("IrDA-USB Dongle Driver");
1593 MODULE_LICENSE("GPL");