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