1 /*****************************************************************************
5 * Description: IrDA-USB Driver
7 * Author: Dag Brattli <dag@brattli.net>
9 * Copyright (C) 2001, Roman Weissgaerber <weissg@vienna.at>
10 * Copyright (C) 2000, 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 *****************************************************************************/
29 #include <linux/time.h>
31 #include <net/irda/irda.h>
32 #include <net/irda/irlap.h>
33 #include <net/irda/irda_device.h>
35 #define RX_COPY_THRESHOLD 200
36 #define IRDA_USB_MAX_MTU 2051
37 #define IRDA_USB_SPEED_MTU 64 /* Weird, but work like this */
39 /* Maximum number of active URB on the Rx path
40 * This is the amount of buffers the we keep between the USB harware and the
43 * Note : the network layer does also queue the packets between us and the
44 * IrDA stack, and is actually pretty fast and efficient in doing that.
45 * Therefore, we don't need to have a large number of URBs, and we can
46 * perfectly live happy with only one. We certainly don't need to keep the
47 * full IrTTP window around here...
48 * I repeat for those who have trouble to understand : 1 URB is plenty
49 * good enough to handle back-to-back (brickwalled) frames. I tried it,
50 * it works (it's the hardware that has trouble doing it).
52 * Having 2 URBs would allow the USB stack to process one URB while we take
53 * care of the other and then swap the URBs...
54 * On the other hand, increasing the number of URB will have penalities
55 * in term of latency and will interact with the link management in IrLAP...
57 #define IU_MAX_ACTIVE_RX_URBS 1 /* Don't touch !!! */
59 /* When a Rx URB is passed back to us, we can't reuse it immediately,
60 * because it may still be referenced by the USB layer. Therefore we
61 * need to keep one extra URB in the Rx path.
63 #define IU_MAX_RX_URBS (IU_MAX_ACTIVE_RX_URBS + 1)
65 /* Various ugly stuff to try to workaround generic problems */
66 /* Send speed command in case of timeout, just for trying to get things sane */
67 #define IU_BUG_KICK_TIMEOUT
68 /* Show the USB class descriptor */
69 #undef IU_DUMP_CLASS_DESC
70 /* Assume a minimum round trip latency for USB transfer (in us)...
71 * USB transfer are done in the next USB slot if there is no traffic
72 * (1/19 msec) and is done at 12 Mb/s :
73 * Waiting for slot + tx = (53us + 16us) * 2 = 137us minimum.
74 * Rx notification will only be done at the end of the USB frame period :
75 * OHCI : frame period = 1ms
76 * UHCI : frame period = 1ms, but notification can take 2 or 3 ms :-(
77 * EHCI : frame period = 125us */
78 #define IU_USB_MIN_RTT 500 /* This should be safe in most cases */
81 #define MEDIA_BUSY 0x80
83 #define SPEED_2400 0x01
84 #define SPEED_9600 0x02
85 #define SPEED_19200 0x03
86 #define SPEED_38400 0x04
87 #define SPEED_57600 0x05
88 #define SPEED_115200 0x06
89 #define SPEED_576000 0x07
90 #define SPEED_1152000 0x08
91 #define SPEED_4000000 0x09
93 /* Basic capabilities */
94 #define IUC_DEFAULT 0x00 /* Basic device compliant with 1.0 spec */
96 #define IUC_SPEED_BUG 0x01 /* Device doesn't set speed after the frame */
97 #define IUC_NO_WINDOW 0x02 /* Device doesn't behave with big Rx window */
98 #define IUC_NO_TURN 0x04 /* Device doesn't do turnaround by itself */
99 /* Not currently used */
100 #define IUC_SIR_ONLY 0x08 /* Device doesn't behave at FIR speeds */
101 #define IUC_SMALL_PKT 0x10 /* Device doesn't behave with big Rx packets */
102 #define IUC_MAX_WINDOW 0x20 /* Device underestimate the Rx window */
103 #define IUC_MAX_XBOFS 0x40 /* Device need more xbofs than advertised */
105 /* USB class definitions */
106 #define USB_IRDA_HEADER 0x01
107 #define USB_CLASS_IRDA 0x02 /* USB_CLASS_APP_SPEC subclass */
108 #define USB_DT_IRDA 0x21
110 struct irda_class_desc {
112 __u8 bDescriptorType;
113 __u16 bcdSpecRevision;
116 __u8 bmMinTurnaroundTime;
118 __u8 bmAdditionalBOFs;
120 __u8 bMaxUnicastList;
121 } __attribute__ ((packed));
123 /* class specific interface request to get the IrDA-USB class descriptor
124 * (6.2.5, USB-IrDA class spec 1.0) */
126 #define IU_REQ_GET_CLASS_DESC 0x06
129 struct irda_class_desc *irda_desc;
130 struct usb_device *usbdev; /* init: probe_irda */
131 unsigned int ifnum; /* Interface number of the USB dev. */
132 int netopen; /* Device is active for network */
133 int present; /* Device is present on the bus */
134 __u32 capability; /* Capability of the hardware */
135 __u8 bulk_in_ep; /* Rx Endpoint assignments */
136 __u8 bulk_out_ep; /* Tx Endpoint assignments */
137 __u16 bulk_out_mtu; /* Max Tx packet size in bytes */
138 __u8 bulk_int_ep; /* Interrupt Endpoint assignments */
140 wait_queue_head_t wait_q; /* for timeouts */
142 struct urb rx_urb[IU_MAX_RX_URBS]; /* URBs used to receive data frames */
143 struct urb *idle_rx_urb; /* Pointer to idle URB in Rx path */
144 struct urb tx_urb; /* URB used to send data frames */
145 struct urb speed_urb; /* URB used to send speed commands */
147 struct net_device *netdev; /* Yes! we are some kind of netdev. */
148 struct net_device_stats stats;
149 struct irlap_cb *irlap; /* The link layer we are binded to */
151 hashbin_t *tx_list; /* Queued transmit skb's */
152 char *speed_buff; /* Buffer for speed changes */
154 struct timeval stamp;
157 spinlock_t lock; /* For serializing operations */
159 __u16 xbofs; /* Current xbofs setting */
160 __s16 new_xbofs; /* xbofs we need to set */
161 __u32 speed; /* Current speed */
162 __s32 new_speed; /* speed we need to set */
163 __u32 flags; /* Interface flags */