blob: a0ca9c1fe1962838f3b253483e4d5edcf341cc84 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*****************************************************************************
2 *
3 * Filename: irda-usb.h
Samuel Ortiz137dc022006-04-05 22:39:14 -07004 * Version: 0.10
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Description: IrDA-USB Driver
6 * Status: Experimental
7 * Author: Dag Brattli <dag@brattli.net>
8 *
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>
Samuel Ortiz137dc022006-04-05 22:39:14 -070012 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 *
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#include <linux/time.h>
33
34#include <net/irda/irda.h>
35#include <net/irda/irda_device.h> /* struct irlap_cb */
36
37#define RX_COPY_THRESHOLD 200
38#define IRDA_USB_MAX_MTU 2051
39#define IRDA_USB_SPEED_MTU 64 /* Weird, but work like this */
40
41/* Maximum number of active URB on the Rx path
42 * This is the amount of buffers the we keep between the USB harware and the
43 * IrDA stack.
44 *
45 * Note : the network layer does also queue the packets between us and the
46 * IrDA stack, and is actually pretty fast and efficient in doing that.
47 * Therefore, we don't need to have a large number of URBs, and we can
48 * perfectly live happy with only one. We certainly don't need to keep the
49 * full IrTTP window around here...
50 * I repeat for those who have trouble to understand : 1 URB is plenty
51 * good enough to handle back-to-back (brickwalled) frames. I tried it,
52 * it works (it's the hardware that has trouble doing it).
53 *
54 * Having 2 URBs would allow the USB stack to process one URB while we take
55 * care of the other and then swap the URBs...
56 * On the other hand, increasing the number of URB will have penalities
57 * in term of latency and will interact with the link management in IrLAP...
58 * Jean II */
59#define IU_MAX_ACTIVE_RX_URBS 1 /* Don't touch !!! */
60
61/* When a Rx URB is passed back to us, we can't reuse it immediately,
62 * because it may still be referenced by the USB layer. Therefore we
63 * need to keep one extra URB in the Rx path.
64 * Jean II */
65#define IU_MAX_RX_URBS (IU_MAX_ACTIVE_RX_URBS + 1)
66
67/* Various ugly stuff to try to workaround generic problems */
68/* Send speed command in case of timeout, just for trying to get things sane */
69#define IU_BUG_KICK_TIMEOUT
70/* Show the USB class descriptor */
71#undef IU_DUMP_CLASS_DESC
72/* Assume a minimum round trip latency for USB transfer (in us)...
73 * USB transfer are done in the next USB slot if there is no traffic
74 * (1/19 msec) and is done at 12 Mb/s :
75 * Waiting for slot + tx = (53us + 16us) * 2 = 137us minimum.
76 * Rx notification will only be done at the end of the USB frame period :
77 * OHCI : frame period = 1ms
78 * UHCI : frame period = 1ms, but notification can take 2 or 3 ms :-(
79 * EHCI : frame period = 125us */
80#define IU_USB_MIN_RTT 500 /* This should be safe in most cases */
81
82/* Inbound header */
83#define MEDIA_BUSY 0x80
84
Samuel Ortiz137dc022006-04-05 22:39:14 -070085#define SPEED_2400 0x01
86#define SPEED_9600 0x02
87#define SPEED_19200 0x03
88#define SPEED_38400 0x04
89#define SPEED_57600 0x05
90#define SPEED_115200 0x06
91#define SPEED_576000 0x07
92#define SPEED_1152000 0x08
93#define SPEED_4000000 0x09
94#define SPEED_16000000 0x0a
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/* Basic capabilities */
97#define IUC_DEFAULT 0x00 /* Basic device compliant with 1.0 spec */
98/* Main bugs */
99#define IUC_SPEED_BUG 0x01 /* Device doesn't set speed after the frame */
100#define IUC_NO_WINDOW 0x02 /* Device doesn't behave with big Rx window */
101#define IUC_NO_TURN 0x04 /* Device doesn't do turnaround by itself */
102/* Not currently used */
103#define IUC_SIR_ONLY 0x08 /* Device doesn't behave at FIR speeds */
104#define IUC_SMALL_PKT 0x10 /* Device doesn't behave with big Rx packets */
105#define IUC_MAX_WINDOW 0x20 /* Device underestimate the Rx window */
106#define IUC_MAX_XBOFS 0x40 /* Device need more xbofs than advertised */
Nick Fedchik8ef80ae2006-06-11 20:56:02 -0700107#define IUC_STIR421X 0x80 /* SigmaTel 4210/4220/4116 VFIR */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109/* USB class definitions */
Samuel Ortiz137dc022006-04-05 22:39:14 -0700110#define USB_IRDA_HEADER 0x01
111#define USB_CLASS_IRDA 0x02 /* USB_CLASS_APP_SPEC subclass */
112#define USB_DT_IRDA 0x21
Nick Fedchik8ef80ae2006-06-11 20:56:02 -0700113#define USB_IRDA_STIR421X_HEADER 0x03
114#define IU_SIGMATEL_MAX_RX_URBS (IU_MAX_ACTIVE_RX_URBS + \
115 USB_IRDA_STIR421X_HEADER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117struct irda_class_desc {
118 __u8 bLength;
119 __u8 bDescriptorType;
Al Virof6c2fb52008-05-21 06:32:11 +0100120 __le16 bcdSpecRevision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 __u8 bmDataSize;
122 __u8 bmWindowSize;
123 __u8 bmMinTurnaroundTime;
Al Virof6c2fb52008-05-21 06:32:11 +0100124 __le16 wBaudRate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 __u8 bmAdditionalBOFs;
126 __u8 bIrdaRateSniff;
127 __u8 bMaxUnicastList;
128} __attribute__ ((packed));
129
130/* class specific interface request to get the IrDA-USB class descriptor
131 * (6.2.5, USB-IrDA class spec 1.0) */
132
133#define IU_REQ_GET_CLASS_DESC 0x06
Samuel Ortiz137dc022006-04-05 22:39:14 -0700134#define STIR421X_MAX_PATCH_DOWNLOAD_SIZE 1023
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136struct irda_usb_cb {
137 struct irda_class_desc *irda_desc;
138 struct usb_device *usbdev; /* init: probe_irda */
139 struct usb_interface *usbintf; /* init: probe_irda */
140 int netopen; /* Device is active for network */
141 int present; /* Device is present on the bus */
142 __u32 capability; /* Capability of the hardware */
143 __u8 bulk_in_ep; /* Rx Endpoint assignments */
144 __u8 bulk_out_ep; /* Tx Endpoint assignments */
145 __u16 bulk_out_mtu; /* Max Tx packet size in bytes */
146 __u8 bulk_int_ep; /* Interrupt Endpoint assignments */
147
Samuel Ortiz137dc022006-04-05 22:39:14 -0700148 __u8 max_rx_urb;
149 struct urb **rx_urb; /* URBs used to receive data frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 struct urb *idle_rx_urb; /* Pointer to idle URB in Rx path */
151 struct urb *tx_urb; /* URB used to send data frames */
152 struct urb *speed_urb; /* URB used to send speed commands */
153
154 struct net_device *netdev; /* Yes! we are some kind of netdev. */
155 struct net_device_stats stats;
156 struct irlap_cb *irlap; /* The link layer we are binded to */
157 struct qos_info qos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 char *speed_buff; /* Buffer for speed changes */
Samuel Ortiz3958fb32007-01-15 19:37:25 -0800159 char *tx_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 struct timeval stamp;
162 struct timeval now;
163
Jean Tourrilhes669d32a22006-02-19 22:28:25 -0800164 spinlock_t lock; /* For serializing Tx operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 __u16 xbofs; /* Current xbofs setting */
167 __s16 new_xbofs; /* xbofs we need to set */
168 __u32 speed; /* Current speed */
169 __s32 new_speed; /* speed we need to set */
Jean Tourrilhes669d32a22006-02-19 22:28:25 -0800170
Samuel Ortiz137dc022006-04-05 22:39:14 -0700171 __u8 header_length; /* USB-IrDA frame header size */
172 int needspatch; /* device needs firmware patch */
173
Jean Tourrilhes669d32a22006-02-19 22:28:25 -0800174 struct timer_list rx_defer_timer; /* Wait for Rx error to clear */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175};
176