update atp870u driver to 0.78 from D-Link source
[linux-2.4.git] / drivers / bluetooth / hci_usb.h
1 /* 
2    HCI USB driver for Linux Bluetooth protocol stack (BlueZ)
3    Copyright (C) 2000-2001 Qualcomm Incorporated
4    Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
5
6    Copyright (C) 2003 Maxim Krasnyansky <maxk@qualcomm.com>
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License version 2 as
10    published by the Free Software Foundation;
11
12    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
13    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
15    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
16    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 
17    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
18    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
19    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
21    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 
22    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 
23    SOFTWARE IS DISCLAIMED.
24 */
25
26 /*
27  * $Id: hci_usb.h,v 1.2 2002/03/18 19:10:04 maxk Exp $
28  */
29
30 #ifdef __KERNEL__
31
32 /* Class, SubClass, and Protocol codes that describe a Bluetooth device */
33 #define HCI_DEV_CLASS        0xe0       /* Wireless class */
34 #define HCI_DEV_SUBCLASS     0x01       /* RF subclass */
35 #define HCI_DEV_PROTOCOL     0x01       /* Bluetooth programming protocol */
36
37 #define HCI_CTRL_REQ         0x20
38 #define HCI_DIGI_REQ         0x40
39
40 #define HCI_IGNORE           0x01
41 #define HCI_RESET            0x02
42 #define HCI_DIGIANSWER       0x04
43 #define HCI_BROKEN_ISOC      0x08
44
45 #define HCI_MAX_IFACE_NUM       3 
46
47 #define HCI_MAX_BULK_TX         4
48 #define HCI_MAX_BULK_RX         1
49
50 #define HCI_MAX_ISOC_RX         2
51 #define HCI_MAX_ISOC_TX         2
52
53 #define HCI_MAX_ISOC_FRAMES     10
54
55 struct _urb_queue {
56         struct list_head head;
57         spinlock_t       lock;
58 };
59
60 struct _urb {
61         struct list_head  list;
62         struct _urb_queue *queue;
63         int               type;
64         void              *priv;
65         struct urb        urb;
66 };
67
68 struct _urb *_urb_alloc(int isoc, int gfp);
69
70 static inline void _urb_free(struct _urb *_urb)
71 {
72         kfree(_urb);
73 }
74
75 static inline void _urb_queue_init(struct _urb_queue *q)
76 {
77         INIT_LIST_HEAD(&q->head);
78         spin_lock_init(&q->lock);
79 }
80
81 static inline void _urb_queue_head(struct _urb_queue *q, struct _urb *_urb)
82 {
83         unsigned long flags;
84         spin_lock_irqsave(&q->lock, flags);
85         list_add(&_urb->list, &q->head); _urb->queue = q;
86         spin_unlock_irqrestore(&q->lock, flags);
87 }
88
89 static inline void _urb_queue_tail(struct _urb_queue *q, struct _urb *_urb)
90 {
91         unsigned long flags;
92         spin_lock_irqsave(&q->lock, flags);
93         list_add_tail(&_urb->list, &q->head); _urb->queue = q;
94         spin_unlock_irqrestore(&q->lock, flags);
95 }
96
97 static inline void _urb_unlink(struct _urb *_urb)
98 {
99         struct _urb_queue *q = _urb->queue;
100         unsigned long flags;
101         if (q) {
102                 spin_lock_irqsave(&q->lock, flags);
103                 list_del(&_urb->list); _urb->queue = NULL;
104                 spin_unlock_irqrestore(&q->lock, flags);
105         }
106 }
107
108 struct _urb *_urb_dequeue(struct _urb_queue *q);
109
110 #ifndef container_of
111 #define container_of(ptr, type, member) ({                      \
112                         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
113                                 (type *)( (char *)__mptr - offsetof(type,member) );})
114 #endif
115
116 struct hci_usb {
117         struct hci_dev          hdev;
118
119         unsigned long           state;
120         
121         struct usb_device       *udev;
122         
123         struct usb_endpoint_descriptor  *bulk_in_ep;
124         struct usb_endpoint_descriptor  *bulk_out_ep;
125         struct usb_endpoint_descriptor  *intr_in_ep;
126
127         struct usb_interface            *isoc_iface;
128         struct usb_endpoint_descriptor  *isoc_out_ep;
129         struct usb_endpoint_descriptor  *isoc_in_ep;
130
131         __u8                    ctrl_req;
132
133         struct sk_buff_head     transmit_q[4];
134         struct sk_buff          *reassembly[4]; // Reassembly buffers
135
136         rwlock_t                completion_lock;
137
138         atomic_t                pending_tx[4];  // Number of pending requests 
139         struct _urb_queue       pending_q[4];   // Pending requests
140         struct _urb_queue       completed_q[4]; // Completed requests
141 };
142
143 /* States  */
144 #define HCI_USB_TX_PROCESS      1
145 #define HCI_USB_TX_WAKEUP       2
146
147 #endif /* __KERNEL__ */