patch-2_6_7-vs1_9_1_12
[linux-2.6.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 /* Class, SubClass, and Protocol codes that describe a Bluetooth device */
27 #define HCI_DEV_CLASS           0xe0    /* Wireless class */
28 #define HCI_DEV_SUBCLASS        0x01    /* RF subclass */
29 #define HCI_DEV_PROTOCOL        0x01    /* Bluetooth programming protocol */
30
31 #define HCI_CTRL_REQ            0x20
32 #define HCI_DIGI_REQ            0x40
33
34 #define HCI_IGNORE              0x01
35 #define HCI_RESET               0x02
36 #define HCI_DIGIANSWER          0x04
37 #define HCI_BROKEN_ISOC         0x08
38
39 #define HCI_MAX_IFACE_NUM       3
40
41 #define HCI_MAX_BULK_TX         4
42 #define HCI_MAX_BULK_RX         1
43
44 #define HCI_MAX_ISOC_RX         2
45 #define HCI_MAX_ISOC_TX         2
46
47 #define HCI_MAX_ISOC_FRAMES     10
48
49 struct _urb_queue {
50         struct list_head head;
51         spinlock_t       lock;
52 };
53
54 struct _urb {
55         struct list_head  list;
56         struct _urb_queue *queue;
57         int               type;
58         void              *priv;
59         struct urb        urb;
60 };
61
62 struct _urb *_urb_alloc(int isoc, int gfp);
63
64 static inline void _urb_free(struct _urb *_urb)
65 {
66         kfree(_urb);
67 }
68
69 static inline void _urb_queue_init(struct _urb_queue *q)
70 {
71         INIT_LIST_HEAD(&q->head);
72         spin_lock_init(&q->lock);
73 }
74
75 static inline void _urb_queue_head(struct _urb_queue *q, struct _urb *_urb)
76 {
77         unsigned long flags;
78         spin_lock_irqsave(&q->lock, flags);
79         list_add(&_urb->list, &q->head); _urb->queue = q;
80         spin_unlock_irqrestore(&q->lock, flags);
81 }
82
83 static inline void _urb_queue_tail(struct _urb_queue *q, struct _urb *_urb)
84 {
85         unsigned long flags;
86         spin_lock_irqsave(&q->lock, flags);
87         list_add_tail(&_urb->list, &q->head); _urb->queue = q;
88         spin_unlock_irqrestore(&q->lock, flags);
89 }
90
91 static inline void _urb_unlink(struct _urb *_urb)
92 {
93         struct _urb_queue *q = _urb->queue;
94         unsigned long flags;
95         if (q) {
96                 spin_lock_irqsave(&q->lock, flags);
97                 list_del(&_urb->list); _urb->queue = NULL;
98                 spin_unlock_irqrestore(&q->lock, flags);
99         }
100 }
101
102 struct _urb *_urb_dequeue(struct _urb_queue *q);
103
104 struct hci_usb {
105         struct hci_dev          *hdev;
106
107         unsigned long           state;
108         
109         struct usb_device       *udev;
110         
111         struct usb_host_endpoint        *bulk_in_ep;
112         struct usb_host_endpoint        *bulk_out_ep;
113         struct usb_host_endpoint        *intr_in_ep;
114
115         struct usb_interface            *isoc_iface;
116         struct usb_host_endpoint        *isoc_out_ep;
117         struct usb_host_endpoint        *isoc_in_ep;
118
119         __u8                    ctrl_req;
120
121         struct sk_buff_head     transmit_q[4];
122         struct sk_buff          *reassembly[4];         /* Reassembly buffers */
123
124         rwlock_t                completion_lock;
125
126         atomic_t                pending_tx[4];          /* Number of pending requests */
127         struct _urb_queue       pending_q[4];           /* Pending requests */
128         struct _urb_queue       completed_q[4];         /* Completed requests */
129 };
130
131 /* States  */
132 #define HCI_USB_TX_PROCESS      1
133 #define HCI_USB_TX_WAKEUP       2