aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bluetooth
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/bluetooth')
-rw-r--r--drivers/bluetooth/bfusb.c316
-rw-r--r--drivers/bluetooth/hci_vhci.c97
2 files changed, 208 insertions, 205 deletions
diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 23f96213f4ac..efcc28ec9d9a 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -2,7 +2,7 @@
2 * 2 *
3 * AVM BlueFRITZ! USB driver 3 * AVM BlueFRITZ! USB driver
4 * 4 *
5 * Copyright (C) 2003 Marcel Holtmann <marcel@holtmann.org> 5 * Copyright (C) 2003-2006 Marcel Holtmann <marcel@holtmann.org>
6 * 6 *
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
@@ -59,7 +59,6 @@ static struct usb_device_id bfusb_table[] = {
59 59
60MODULE_DEVICE_TABLE(usb, bfusb_table); 60MODULE_DEVICE_TABLE(usb, bfusb_table);
61 61
62
63#define BFUSB_MAX_BLOCK_SIZE 256 62#define BFUSB_MAX_BLOCK_SIZE 256
64 63
65#define BFUSB_BLOCK_TIMEOUT 3000 64#define BFUSB_BLOCK_TIMEOUT 3000
@@ -70,7 +69,7 @@ MODULE_DEVICE_TABLE(usb, bfusb_table);
70#define BFUSB_MAX_BULK_TX 2 69#define BFUSB_MAX_BULK_TX 2
71#define BFUSB_MAX_BULK_RX 2 70#define BFUSB_MAX_BULK_RX 2
72 71
73struct bfusb { 72struct bfusb_data {
74 struct hci_dev *hdev; 73 struct hci_dev *hdev;
75 74
76 unsigned long state; 75 unsigned long state;
@@ -92,137 +91,136 @@ struct bfusb {
92 struct sk_buff_head completed_q; 91 struct sk_buff_head completed_q;
93}; 92};
94 93
95struct bfusb_scb { 94struct bfusb_data_scb {
96 struct urb *urb; 95 struct urb *urb;
97}; 96};
98 97
99static void bfusb_tx_complete(struct urb *urb, struct pt_regs *regs); 98static void bfusb_tx_complete(struct urb *urb, struct pt_regs *regs);
100static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs); 99static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs);
101 100
102static struct urb *bfusb_get_completed(struct bfusb *bfusb) 101static struct urb *bfusb_get_completed(struct bfusb_data *data)
103{ 102{
104 struct sk_buff *skb; 103 struct sk_buff *skb;
105 struct urb *urb = NULL; 104 struct urb *urb = NULL;
106 105
107 BT_DBG("bfusb %p", bfusb); 106 BT_DBG("bfusb %p", data);
108 107
109 skb = skb_dequeue(&bfusb->completed_q); 108 skb = skb_dequeue(&data->completed_q);
110 if (skb) { 109 if (skb) {
111 urb = ((struct bfusb_scb *) skb->cb)->urb; 110 urb = ((struct bfusb_data_scb *) skb->cb)->urb;
112 kfree_skb(skb); 111 kfree_skb(skb);
113 } 112 }
114 113
115 return urb; 114 return urb;
116} 115}
117 116
118static void bfusb_unlink_urbs(struct bfusb *bfusb) 117static void bfusb_unlink_urbs(struct bfusb_data *data)
119{ 118{
120 struct sk_buff *skb; 119 struct sk_buff *skb;
121 struct urb *urb; 120 struct urb *urb;
122 121
123 BT_DBG("bfusb %p", bfusb); 122 BT_DBG("bfusb %p", data);
124 123
125 while ((skb = skb_dequeue(&bfusb->pending_q))) { 124 while ((skb = skb_dequeue(&data->pending_q))) {
126 urb = ((struct bfusb_scb *) skb->cb)->urb; 125 urb = ((struct bfusb_data_scb *) skb->cb)->urb;
127 usb_kill_urb(urb); 126 usb_kill_urb(urb);
128 skb_queue_tail(&bfusb->completed_q, skb); 127 skb_queue_tail(&data->completed_q, skb);
129 } 128 }
130 129
131 while ((urb = bfusb_get_completed(bfusb))) 130 while ((urb = bfusb_get_completed(data)))
132 usb_free_urb(urb); 131 usb_free_urb(urb);
133} 132}
134 133
135 134static int bfusb_send_bulk(struct bfusb_data *data, struct sk_buff *skb)
136static int bfusb_send_bulk(struct bfusb *bfusb, struct sk_buff *skb)
137{ 135{
138 struct bfusb_scb *scb = (void *) skb->cb; 136 struct bfusb_data_scb *scb = (void *) skb->cb;
139 struct urb *urb = bfusb_get_completed(bfusb); 137 struct urb *urb = bfusb_get_completed(data);
140 int err, pipe; 138 int err, pipe;
141 139
142 BT_DBG("bfusb %p skb %p len %d", bfusb, skb, skb->len); 140 BT_DBG("bfusb %p skb %p len %d", data, skb, skb->len);
143 141
144 if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC))) 142 if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC)))
145 return -ENOMEM; 143 return -ENOMEM;
146 144
147 pipe = usb_sndbulkpipe(bfusb->udev, bfusb->bulk_out_ep); 145 pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
148 146
149 usb_fill_bulk_urb(urb, bfusb->udev, pipe, skb->data, skb->len, 147 usb_fill_bulk_urb(urb, data->udev, pipe, skb->data, skb->len,
150 bfusb_tx_complete, skb); 148 bfusb_tx_complete, skb);
151 149
152 scb->urb = urb; 150 scb->urb = urb;
153 151
154 skb_queue_tail(&bfusb->pending_q, skb); 152 skb_queue_tail(&data->pending_q, skb);
155 153
156 err = usb_submit_urb(urb, GFP_ATOMIC); 154 err = usb_submit_urb(urb, GFP_ATOMIC);
157 if (err) { 155 if (err) {
158 BT_ERR("%s bulk tx submit failed urb %p err %d", 156 BT_ERR("%s bulk tx submit failed urb %p err %d",
159 bfusb->hdev->name, urb, err); 157 data->hdev->name, urb, err);
160 skb_unlink(skb, &bfusb->pending_q); 158 skb_unlink(skb, &data->pending_q);
161 usb_free_urb(urb); 159 usb_free_urb(urb);
162 } else 160 } else
163 atomic_inc(&bfusb->pending_tx); 161 atomic_inc(&data->pending_tx);
164 162
165 return err; 163 return err;
166} 164}
167 165
168static void bfusb_tx_wakeup(struct bfusb *bfusb) 166static void bfusb_tx_wakeup(struct bfusb_data *data)
169{ 167{
170 struct sk_buff *skb; 168 struct sk_buff *skb;
171 169
172 BT_DBG("bfusb %p", bfusb); 170 BT_DBG("bfusb %p", data);
173 171
174 if (test_and_set_bit(BFUSB_TX_PROCESS, &bfusb->state)) { 172 if (test_and_set_bit(BFUSB_TX_PROCESS, &data->state)) {
175 set_bit(BFUSB_TX_WAKEUP, &bfusb->state); 173 set_bit(BFUSB_TX_WAKEUP, &data->state);
176 return; 174 return;
177 } 175 }
178 176
179 do { 177 do {
180 clear_bit(BFUSB_TX_WAKEUP, &bfusb->state); 178 clear_bit(BFUSB_TX_WAKEUP, &data->state);
181 179
182 while ((atomic_read(&bfusb->pending_tx) < BFUSB_MAX_BULK_TX) && 180 while ((atomic_read(&data->pending_tx) < BFUSB_MAX_BULK_TX) &&
183 (skb = skb_dequeue(&bfusb->transmit_q))) { 181 (skb = skb_dequeue(&data->transmit_q))) {
184 if (bfusb_send_bulk(bfusb, skb) < 0) { 182 if (bfusb_send_bulk(data, skb) < 0) {
185 skb_queue_head(&bfusb->transmit_q, skb); 183 skb_queue_head(&data->transmit_q, skb);
186 break; 184 break;
187 } 185 }
188 } 186 }
189 187
190 } while (test_bit(BFUSB_TX_WAKEUP, &bfusb->state)); 188 } while (test_bit(BFUSB_TX_WAKEUP, &data->state));
191 189
192 clear_bit(BFUSB_TX_PROCESS, &bfusb->state); 190 clear_bit(BFUSB_TX_PROCESS, &data->state);
193} 191}
194 192
195static void bfusb_tx_complete(struct urb *urb, struct pt_regs *regs) 193static void bfusb_tx_complete(struct urb *urb, struct pt_regs *regs)
196{ 194{
197 struct sk_buff *skb = (struct sk_buff *) urb->context; 195 struct sk_buff *skb = (struct sk_buff *) urb->context;
198 struct bfusb *bfusb = (struct bfusb *) skb->dev; 196 struct bfusb_data *data = (struct bfusb_data *) skb->dev;
199 197
200 BT_DBG("bfusb %p urb %p skb %p len %d", bfusb, urb, skb, skb->len); 198 BT_DBG("bfusb %p urb %p skb %p len %d", data, urb, skb, skb->len);
201 199
202 atomic_dec(&bfusb->pending_tx); 200 atomic_dec(&data->pending_tx);
203 201
204 if (!test_bit(HCI_RUNNING, &bfusb->hdev->flags)) 202 if (!test_bit(HCI_RUNNING, &data->hdev->flags))
205 return; 203 return;
206 204
207 if (!urb->status) 205 if (!urb->status)
208 bfusb->hdev->stat.byte_tx += skb->len; 206 data->hdev->stat.byte_tx += skb->len;
209 else 207 else
210 bfusb->hdev->stat.err_tx++; 208 data->hdev->stat.err_tx++;
211 209
212 read_lock(&bfusb->lock); 210 read_lock(&data->lock);
213 211
214 skb_unlink(skb, &bfusb->pending_q); 212 skb_unlink(skb, &data->pending_q);
215 skb_queue_tail(&bfusb->completed_q, skb); 213 skb_queue_tail(&data->completed_q, skb);
216 214
217 bfusb_tx_wakeup(bfusb); 215 bfusb_tx_wakeup(data);
218 216
219 read_unlock(&bfusb->lock); 217 read_unlock(&data->lock);
220} 218}
221 219
222 220
223static int bfusb_rx_submit(struct bfusb *bfusb, struct urb *urb) 221static int bfusb_rx_submit(struct bfusb_data *data, struct urb *urb)
224{ 222{
225 struct bfusb_scb *scb; 223 struct bfusb_data_scb *scb;
226 struct sk_buff *skb; 224 struct sk_buff *skb;
227 int err, pipe, size = HCI_MAX_FRAME_SIZE + 32; 225 int err, pipe, size = HCI_MAX_FRAME_SIZE + 32;
228 226
@@ -231,28 +229,29 @@ static int bfusb_rx_submit(struct bfusb *bfusb, struct urb *urb)
231 if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC))) 229 if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC)))
232 return -ENOMEM; 230 return -ENOMEM;
233 231
234 if (!(skb = bt_skb_alloc(size, GFP_ATOMIC))) { 232 skb = bt_skb_alloc(size, GFP_ATOMIC);
233 if (!skb) {
235 usb_free_urb(urb); 234 usb_free_urb(urb);
236 return -ENOMEM; 235 return -ENOMEM;
237 } 236 }
238 237
239 skb->dev = (void *) bfusb; 238 skb->dev = (void *) data;
240 239
241 scb = (struct bfusb_scb *) skb->cb; 240 scb = (struct bfusb_data_scb *) skb->cb;
242 scb->urb = urb; 241 scb->urb = urb;
243 242
244 pipe = usb_rcvbulkpipe(bfusb->udev, bfusb->bulk_in_ep); 243 pipe = usb_rcvbulkpipe(data->udev, data->bulk_in_ep);
245 244
246 usb_fill_bulk_urb(urb, bfusb->udev, pipe, skb->data, size, 245 usb_fill_bulk_urb(urb, data->udev, pipe, skb->data, size,
247 bfusb_rx_complete, skb); 246 bfusb_rx_complete, skb);
248 247
249 skb_queue_tail(&bfusb->pending_q, skb); 248 skb_queue_tail(&data->pending_q, skb);
250 249
251 err = usb_submit_urb(urb, GFP_ATOMIC); 250 err = usb_submit_urb(urb, GFP_ATOMIC);
252 if (err) { 251 if (err) {
253 BT_ERR("%s bulk rx submit failed urb %p err %d", 252 BT_ERR("%s bulk rx submit failed urb %p err %d",
254 bfusb->hdev->name, urb, err); 253 data->hdev->name, urb, err);
255 skb_unlink(skb, &bfusb->pending_q); 254 skb_unlink(skb, &data->pending_q);
256 kfree_skb(skb); 255 kfree_skb(skb);
257 usb_free_urb(urb); 256 usb_free_urb(urb);
258 } 257 }
@@ -260,15 +259,15 @@ static int bfusb_rx_submit(struct bfusb *bfusb, struct urb *urb)
260 return err; 259 return err;
261} 260}
262 261
263static inline int bfusb_recv_block(struct bfusb *bfusb, int hdr, unsigned char *data, int len) 262static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned char *buf, int len)
264{ 263{
265 BT_DBG("bfusb %p hdr 0x%02x data %p len %d", bfusb, hdr, data, len); 264 BT_DBG("bfusb %p hdr 0x%02x data %p len %d", data, hdr, buf, len);
266 265
267 if (hdr & 0x10) { 266 if (hdr & 0x10) {
268 BT_ERR("%s error in block", bfusb->hdev->name); 267 BT_ERR("%s error in block", data->hdev->name);
269 if (bfusb->reassembly) 268 if (data->reassembly)
270 kfree_skb(bfusb->reassembly); 269 kfree_skb(data->reassembly);
271 bfusb->reassembly = NULL; 270 data->reassembly = NULL;
272 return -EIO; 271 return -EIO;
273 } 272 }
274 273
@@ -277,46 +276,46 @@ static inline int bfusb_recv_block(struct bfusb *bfusb, int hdr, unsigned char *
277 unsigned char pkt_type; 276 unsigned char pkt_type;
278 int pkt_len = 0; 277 int pkt_len = 0;
279 278
280 if (bfusb->reassembly) { 279 if (data->reassembly) {
281 BT_ERR("%s unexpected start block", bfusb->hdev->name); 280 BT_ERR("%s unexpected start block", data->hdev->name);
282 kfree_skb(bfusb->reassembly); 281 kfree_skb(data->reassembly);
283 bfusb->reassembly = NULL; 282 data->reassembly = NULL;
284 } 283 }
285 284
286 if (len < 1) { 285 if (len < 1) {
287 BT_ERR("%s no packet type found", bfusb->hdev->name); 286 BT_ERR("%s no packet type found", data->hdev->name);
288 return -EPROTO; 287 return -EPROTO;
289 } 288 }
290 289
291 pkt_type = *data++; len--; 290 pkt_type = *buf++; len--;
292 291
293 switch (pkt_type) { 292 switch (pkt_type) {
294 case HCI_EVENT_PKT: 293 case HCI_EVENT_PKT:
295 if (len >= HCI_EVENT_HDR_SIZE) { 294 if (len >= HCI_EVENT_HDR_SIZE) {
296 struct hci_event_hdr *hdr = (struct hci_event_hdr *) data; 295 struct hci_event_hdr *hdr = (struct hci_event_hdr *) buf;
297 pkt_len = HCI_EVENT_HDR_SIZE + hdr->plen; 296 pkt_len = HCI_EVENT_HDR_SIZE + hdr->plen;
298 } else { 297 } else {
299 BT_ERR("%s event block is too short", bfusb->hdev->name); 298 BT_ERR("%s event block is too short", data->hdev->name);
300 return -EILSEQ; 299 return -EILSEQ;
301 } 300 }
302 break; 301 break;
303 302
304 case HCI_ACLDATA_PKT: 303 case HCI_ACLDATA_PKT:
305 if (len >= HCI_ACL_HDR_SIZE) { 304 if (len >= HCI_ACL_HDR_SIZE) {
306 struct hci_acl_hdr *hdr = (struct hci_acl_hdr *) data; 305 struct hci_acl_hdr *hdr = (struct hci_acl_hdr *) buf;
307 pkt_len = HCI_ACL_HDR_SIZE + __le16_to_cpu(hdr->dlen); 306 pkt_len = HCI_ACL_HDR_SIZE + __le16_to_cpu(hdr->dlen);
308 } else { 307 } else {
309 BT_ERR("%s data block is too short", bfusb->hdev->name); 308 BT_ERR("%s data block is too short", data->hdev->name);
310 return -EILSEQ; 309 return -EILSEQ;
311 } 310 }
312 break; 311 break;
313 312
314 case HCI_SCODATA_PKT: 313 case HCI_SCODATA_PKT:
315 if (len >= HCI_SCO_HDR_SIZE) { 314 if (len >= HCI_SCO_HDR_SIZE) {
316 struct hci_sco_hdr *hdr = (struct hci_sco_hdr *) data; 315 struct hci_sco_hdr *hdr = (struct hci_sco_hdr *) buf;
317 pkt_len = HCI_SCO_HDR_SIZE + hdr->dlen; 316 pkt_len = HCI_SCO_HDR_SIZE + hdr->dlen;
318 } else { 317 } else {
319 BT_ERR("%s audio block is too short", bfusb->hdev->name); 318 BT_ERR("%s audio block is too short", data->hdev->name);
320 return -EILSEQ; 319 return -EILSEQ;
321 } 320 }
322 break; 321 break;
@@ -324,27 +323,27 @@ static inline int bfusb_recv_block(struct bfusb *bfusb, int hdr, unsigned char *
324 323
325 skb = bt_skb_alloc(pkt_len, GFP_ATOMIC); 324 skb = bt_skb_alloc(pkt_len, GFP_ATOMIC);
326 if (!skb) { 325 if (!skb) {
327 BT_ERR("%s no memory for the packet", bfusb->hdev->name); 326 BT_ERR("%s no memory for the packet", data->hdev->name);
328 return -ENOMEM; 327 return -ENOMEM;
329 } 328 }
330 329
331 skb->dev = (void *) bfusb->hdev; 330 skb->dev = (void *) data->hdev;
332 bt_cb(skb)->pkt_type = pkt_type; 331 bt_cb(skb)->pkt_type = pkt_type;
333 332
334 bfusb->reassembly = skb; 333 data->reassembly = skb;
335 } else { 334 } else {
336 if (!bfusb->reassembly) { 335 if (!data->reassembly) {
337 BT_ERR("%s unexpected continuation block", bfusb->hdev->name); 336 BT_ERR("%s unexpected continuation block", data->hdev->name);
338 return -EIO; 337 return -EIO;
339 } 338 }
340 } 339 }
341 340
342 if (len > 0) 341 if (len > 0)
343 memcpy(skb_put(bfusb->reassembly, len), data, len); 342 memcpy(skb_put(data->reassembly, len), buf, len);
344 343
345 if (hdr & 0x08) { 344 if (hdr & 0x08) {
346 hci_recv_frame(bfusb->reassembly); 345 hci_recv_frame(data->reassembly);
347 bfusb->reassembly = NULL; 346 data->reassembly = NULL;
348 } 347 }
349 348
350 return 0; 349 return 0;
@@ -353,22 +352,22 @@ static inline int bfusb_recv_block(struct bfusb *bfusb, int hdr, unsigned char *
353static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs) 352static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs)
354{ 353{
355 struct sk_buff *skb = (struct sk_buff *) urb->context; 354 struct sk_buff *skb = (struct sk_buff *) urb->context;
356 struct bfusb *bfusb = (struct bfusb *) skb->dev; 355 struct bfusb_data *data = (struct bfusb_data *) skb->dev;
357 unsigned char *buf = urb->transfer_buffer; 356 unsigned char *buf = urb->transfer_buffer;
358 int count = urb->actual_length; 357 int count = urb->actual_length;
359 int err, hdr, len; 358 int err, hdr, len;
360 359
361 BT_DBG("bfusb %p urb %p skb %p len %d", bfusb, urb, skb, skb->len); 360 BT_DBG("bfusb %p urb %p skb %p len %d", bfusb, urb, skb, skb->len);
362 361
363 read_lock(&bfusb->lock); 362 read_lock(&data->lock);
364 363
365 if (!test_bit(HCI_RUNNING, &bfusb->hdev->flags)) 364 if (!test_bit(HCI_RUNNING, &data->hdev->flags))
366 goto unlock; 365 goto unlock;
367 366
368 if (urb->status || !count) 367 if (urb->status || !count)
369 goto resubmit; 368 goto resubmit;
370 369
371 bfusb->hdev->stat.byte_rx += count; 370 data->hdev->stat.byte_rx += count;
372 371
373 skb_put(skb, count); 372 skb_put(skb, count);
374 373
@@ -387,90 +386,89 @@ static void bfusb_rx_complete(struct urb *urb, struct pt_regs *regs)
387 386
388 if (count < len) { 387 if (count < len) {
389 BT_ERR("%s block extends over URB buffer ranges", 388 BT_ERR("%s block extends over URB buffer ranges",
390 bfusb->hdev->name); 389 data->hdev->name);
391 } 390 }
392 391
393 if ((hdr & 0xe1) == 0xc1) 392 if ((hdr & 0xe1) == 0xc1)
394 bfusb_recv_block(bfusb, hdr, buf, len); 393 bfusb_recv_block(data, hdr, buf, len);
395 394
396 count -= len; 395 count -= len;
397 buf += len; 396 buf += len;
398 } 397 }
399 398
400 skb_unlink(skb, &bfusb->pending_q); 399 skb_unlink(skb, &data->pending_q);
401 kfree_skb(skb); 400 kfree_skb(skb);
402 401
403 bfusb_rx_submit(bfusb, urb); 402 bfusb_rx_submit(data, urb);
404 403
405 read_unlock(&bfusb->lock); 404 read_unlock(&data->lock);
406 405
407 return; 406 return;
408 407
409resubmit: 408resubmit:
410 urb->dev = bfusb->udev; 409 urb->dev = data->udev;
411 410
412 err = usb_submit_urb(urb, GFP_ATOMIC); 411 err = usb_submit_urb(urb, GFP_ATOMIC);
413 if (err) { 412 if (err) {
414 BT_ERR("%s bulk resubmit failed urb %p err %d", 413 BT_ERR("%s bulk resubmit failed urb %p err %d",
415 bfusb->hdev->name, urb, err); 414 data->hdev->name, urb, err);
416 } 415 }
417 416
418unlock: 417unlock:
419 read_unlock(&bfusb->lock); 418 read_unlock(&data->lock);
420} 419}
421 420
422
423static int bfusb_open(struct hci_dev *hdev) 421static int bfusb_open(struct hci_dev *hdev)
424{ 422{
425 struct bfusb *bfusb = (struct bfusb *) hdev->driver_data; 423 struct bfusb_data *data = hdev->driver_data;
426 unsigned long flags; 424 unsigned long flags;
427 int i, err; 425 int i, err;
428 426
429 BT_DBG("hdev %p bfusb %p", hdev, bfusb); 427 BT_DBG("hdev %p bfusb %p", hdev, data);
430 428
431 if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) 429 if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
432 return 0; 430 return 0;
433 431
434 write_lock_irqsave(&bfusb->lock, flags); 432 write_lock_irqsave(&data->lock, flags);
435 433
436 err = bfusb_rx_submit(bfusb, NULL); 434 err = bfusb_rx_submit(data, NULL);
437 if (!err) { 435 if (!err) {
438 for (i = 1; i < BFUSB_MAX_BULK_RX; i++) 436 for (i = 1; i < BFUSB_MAX_BULK_RX; i++)
439 bfusb_rx_submit(bfusb, NULL); 437 bfusb_rx_submit(data, NULL);
440 } else { 438 } else {
441 clear_bit(HCI_RUNNING, &hdev->flags); 439 clear_bit(HCI_RUNNING, &hdev->flags);
442 } 440 }
443 441
444 write_unlock_irqrestore(&bfusb->lock, flags); 442 write_unlock_irqrestore(&data->lock, flags);
445 443
446 return err; 444 return err;
447} 445}
448 446
449static int bfusb_flush(struct hci_dev *hdev) 447static int bfusb_flush(struct hci_dev *hdev)
450{ 448{
451 struct bfusb *bfusb = (struct bfusb *) hdev->driver_data; 449 struct bfusb_data *data = hdev->driver_data;
452 450
453 BT_DBG("hdev %p bfusb %p", hdev, bfusb); 451 BT_DBG("hdev %p bfusb %p", hdev, data);
454 452
455 skb_queue_purge(&bfusb->transmit_q); 453 skb_queue_purge(&data->transmit_q);
456 454
457 return 0; 455 return 0;
458} 456}
459 457
460static int bfusb_close(struct hci_dev *hdev) 458static int bfusb_close(struct hci_dev *hdev)
461{ 459{
462 struct bfusb *bfusb = (struct bfusb *) hdev->driver_data; 460 struct bfusb_data *data = hdev->driver_data;
463 unsigned long flags; 461 unsigned long flags;
464 462
465 BT_DBG("hdev %p bfusb %p", hdev, bfusb); 463 BT_DBG("hdev %p bfusb %p", hdev, data);
466 464
467 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) 465 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
468 return 0; 466 return 0;
469 467
470 write_lock_irqsave(&bfusb->lock, flags); 468 write_lock_irqsave(&data->lock, flags);
471 write_unlock_irqrestore(&bfusb->lock, flags); 469 write_unlock_irqrestore(&data->lock, flags);
472 470
473 bfusb_unlink_urbs(bfusb); 471 bfusb_unlink_urbs(data);
474 bfusb_flush(hdev); 472 bfusb_flush(hdev);
475 473
476 return 0; 474 return 0;
@@ -479,7 +477,7 @@ static int bfusb_close(struct hci_dev *hdev)
479static int bfusb_send_frame(struct sk_buff *skb) 477static int bfusb_send_frame(struct sk_buff *skb)
480{ 478{
481 struct hci_dev *hdev = (struct hci_dev *) skb->dev; 479 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
482 struct bfusb *bfusb; 480 struct bfusb_data *data;
483 struct sk_buff *nskb; 481 struct sk_buff *nskb;
484 unsigned char buf[3]; 482 unsigned char buf[3];
485 int sent = 0, size, count; 483 int sent = 0, size, count;
@@ -494,7 +492,7 @@ static int bfusb_send_frame(struct sk_buff *skb)
494 if (!test_bit(HCI_RUNNING, &hdev->flags)) 492 if (!test_bit(HCI_RUNNING, &hdev->flags))
495 return -EBUSY; 493 return -EBUSY;
496 494
497 bfusb = (struct bfusb *) hdev->driver_data; 495 data = hdev->driver_data;
498 496
499 switch (bt_cb(skb)->pkt_type) { 497 switch (bt_cb(skb)->pkt_type) {
500 case HCI_COMMAND_PKT: 498 case HCI_COMMAND_PKT:
@@ -514,12 +512,13 @@ static int bfusb_send_frame(struct sk_buff *skb)
514 count = skb->len; 512 count = skb->len;
515 513
516 /* Max HCI frame size seems to be 1511 + 1 */ 514 /* Max HCI frame size seems to be 1511 + 1 */
517 if (!(nskb = bt_skb_alloc(count + 32, GFP_ATOMIC))) { 515 nskb = bt_skb_alloc(count + 32, GFP_ATOMIC);
516 if (!nskb) {
518 BT_ERR("Can't allocate memory for new packet"); 517 BT_ERR("Can't allocate memory for new packet");
519 return -ENOMEM; 518 return -ENOMEM;
520 } 519 }
521 520
522 nskb->dev = (void *) bfusb; 521 nskb->dev = (void *) data;
523 522
524 while (count) { 523 while (count) {
525 size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE); 524 size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE);
@@ -536,18 +535,18 @@ static int bfusb_send_frame(struct sk_buff *skb)
536 } 535 }
537 536
538 /* Don't send frame with multiple size of bulk max packet */ 537 /* Don't send frame with multiple size of bulk max packet */
539 if ((nskb->len % bfusb->bulk_pkt_size) == 0) { 538 if ((nskb->len % data->bulk_pkt_size) == 0) {
540 buf[0] = 0xdd; 539 buf[0] = 0xdd;
541 buf[1] = 0x00; 540 buf[1] = 0x00;
542 memcpy(skb_put(nskb, 2), buf, 2); 541 memcpy(skb_put(nskb, 2), buf, 2);
543 } 542 }
544 543
545 read_lock(&bfusb->lock); 544 read_lock(&data->lock);
546 545
547 skb_queue_tail(&bfusb->transmit_q, nskb); 546 skb_queue_tail(&data->transmit_q, nskb);
548 bfusb_tx_wakeup(bfusb); 547 bfusb_tx_wakeup(data);
549 548
550 read_unlock(&bfusb->lock); 549 read_unlock(&data->lock);
551 550
552 kfree_skb(skb); 551 kfree_skb(skb);
553 552
@@ -556,11 +555,11 @@ static int bfusb_send_frame(struct sk_buff *skb)
556 555
557static void bfusb_destruct(struct hci_dev *hdev) 556static void bfusb_destruct(struct hci_dev *hdev)
558{ 557{
559 struct bfusb *bfusb = (struct bfusb *) hdev->driver_data; 558 struct bfusb_data *data = hdev->driver_data;
560 559
561 BT_DBG("hdev %p bfusb %p", hdev, bfusb); 560 BT_DBG("hdev %p bfusb %p", hdev, data);
562 561
563 kfree(bfusb); 562 kfree(data);
564} 563}
565 564
566static int bfusb_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg) 565static int bfusb_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
@@ -568,25 +567,24 @@ static int bfusb_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg
568 return -ENOIOCTLCMD; 567 return -ENOIOCTLCMD;
569} 568}
570 569
571 570static int bfusb_load_firmware(struct bfusb_data *data, unsigned char *firmware, int count)
572static int bfusb_load_firmware(struct bfusb *bfusb, unsigned char *firmware, int count)
573{ 571{
574 unsigned char *buf; 572 unsigned char *buf;
575 int err, pipe, len, size, sent = 0; 573 int err, pipe, len, size, sent = 0;
576 574
577 BT_DBG("bfusb %p udev %p", bfusb, bfusb->udev); 575 BT_DBG("bfusb %p udev %p", data, data->udev);
578 576
579 BT_INFO("BlueFRITZ! USB loading firmware"); 577 BT_INFO("BlueFRITZ! USB loading firmware");
580 578
581 pipe = usb_sndctrlpipe(bfusb->udev, 0); 579 pipe = usb_sndctrlpipe(data->udev, 0);
582 580
583 if (usb_control_msg(bfusb->udev, pipe, USB_REQ_SET_CONFIGURATION, 581 if (usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
584 0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) { 582 0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) {
585 BT_ERR("Can't change to loading configuration"); 583 BT_ERR("Can't change to loading configuration");
586 return -EBUSY; 584 return -EBUSY;
587 } 585 }
588 586
589 bfusb->udev->toggle[0] = bfusb->udev->toggle[1] = 0; 587 data->udev->toggle[0] = data->udev->toggle[1] = 0;
590 588
591 buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_ATOMIC); 589 buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_ATOMIC);
592 if (!buf) { 590 if (!buf) {
@@ -594,14 +592,14 @@ static int bfusb_load_firmware(struct bfusb *bfusb, unsigned char *firmware, int
594 return -ENOMEM; 592 return -ENOMEM;
595 } 593 }
596 594
597 pipe = usb_sndbulkpipe(bfusb->udev, bfusb->bulk_out_ep); 595 pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
598 596
599 while (count) { 597 while (count) {
600 size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE + 3); 598 size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE + 3);
601 599
602 memcpy(buf, firmware + sent, size); 600 memcpy(buf, firmware + sent, size);
603 601
604 err = usb_bulk_msg(bfusb->udev, pipe, buf, size, 602 err = usb_bulk_msg(data->udev, pipe, buf, size,
605 &len, BFUSB_BLOCK_TIMEOUT); 603 &len, BFUSB_BLOCK_TIMEOUT);
606 604
607 if (err || (len != size)) { 605 if (err || (len != size)) {
@@ -613,21 +611,23 @@ static int bfusb_load_firmware(struct bfusb *bfusb, unsigned char *firmware, int
613 count -= size; 611 count -= size;
614 } 612 }
615 613
616 if ((err = usb_bulk_msg(bfusb->udev, pipe, NULL, 0, 614 err = usb_bulk_msg(data->udev, pipe, NULL, 0,
617 &len, BFUSB_BLOCK_TIMEOUT)) < 0) { 615 &len, BFUSB_BLOCK_TIMEOUT);
616 if (err < 0) {
618 BT_ERR("Error in null packet request"); 617 BT_ERR("Error in null packet request");
619 goto error; 618 goto error;
620 } 619 }
621 620
622 pipe = usb_sndctrlpipe(bfusb->udev, 0); 621 pipe = usb_sndctrlpipe(data->udev, 0);
623 622
624 if ((err = usb_control_msg(bfusb->udev, pipe, USB_REQ_SET_CONFIGURATION, 623 err = usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
625 0, 2, 0, NULL, 0, USB_CTRL_SET_TIMEOUT)) < 0) { 624 0, 2, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
625 if (err < 0) {
626 BT_ERR("Can't change to running configuration"); 626 BT_ERR("Can't change to running configuration");
627 goto error; 627 goto error;
628 } 628 }
629 629
630 bfusb->udev->toggle[0] = bfusb->udev->toggle[1] = 0; 630 data->udev->toggle[0] = data->udev->toggle[1] = 0;
631 631
632 BT_INFO("BlueFRITZ! USB device ready"); 632 BT_INFO("BlueFRITZ! USB device ready");
633 633
@@ -637,9 +637,9 @@ static int bfusb_load_firmware(struct bfusb *bfusb, unsigned char *firmware, int
637error: 637error:
638 kfree(buf); 638 kfree(buf);
639 639
640 pipe = usb_sndctrlpipe(bfusb->udev, 0); 640 pipe = usb_sndctrlpipe(data->udev, 0);
641 641
642 usb_control_msg(bfusb->udev, pipe, USB_REQ_SET_CONFIGURATION, 642 usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
643 0, 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 643 0, 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
644 644
645 return err; 645 return err;
@@ -652,7 +652,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
652 struct usb_host_endpoint *bulk_out_ep; 652 struct usb_host_endpoint *bulk_out_ep;
653 struct usb_host_endpoint *bulk_in_ep; 653 struct usb_host_endpoint *bulk_in_ep;
654 struct hci_dev *hdev; 654 struct hci_dev *hdev;
655 struct bfusb *bfusb; 655 struct bfusb_data *data;
656 656
657 BT_DBG("intf %p id %p", intf, id); 657 BT_DBG("intf %p id %p", intf, id);
658 658
@@ -672,23 +672,24 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
672 } 672 }
673 673
674 /* Initialize control structure and load firmware */ 674 /* Initialize control structure and load firmware */
675 if (!(bfusb = kzalloc(sizeof(struct bfusb), GFP_KERNEL))) { 675 data = kzalloc(sizeof(struct bfusb_data), GFP_KERNEL);
676 if (!data) {
676 BT_ERR("Can't allocate memory for control structure"); 677 BT_ERR("Can't allocate memory for control structure");
677 goto done; 678 goto done;
678 } 679 }
679 680
680 bfusb->udev = udev; 681 data->udev = udev;
681 bfusb->bulk_in_ep = bulk_in_ep->desc.bEndpointAddress; 682 data->bulk_in_ep = bulk_in_ep->desc.bEndpointAddress;
682 bfusb->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress; 683 data->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress;
683 bfusb->bulk_pkt_size = le16_to_cpu(bulk_out_ep->desc.wMaxPacketSize); 684 data->bulk_pkt_size = le16_to_cpu(bulk_out_ep->desc.wMaxPacketSize);
684 685
685 rwlock_init(&bfusb->lock); 686 rwlock_init(&data->lock);
686 687
687 bfusb->reassembly = NULL; 688 data->reassembly = NULL;
688 689
689 skb_queue_head_init(&bfusb->transmit_q); 690 skb_queue_head_init(&data->transmit_q);
690 skb_queue_head_init(&bfusb->pending_q); 691 skb_queue_head_init(&data->pending_q);
691 skb_queue_head_init(&bfusb->completed_q); 692 skb_queue_head_init(&data->completed_q);
692 693
693 if (request_firmware(&firmware, "bfubase.frm", &udev->dev) < 0) { 694 if (request_firmware(&firmware, "bfubase.frm", &udev->dev) < 0) {
694 BT_ERR("Firmware request failed"); 695 BT_ERR("Firmware request failed");
@@ -697,7 +698,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
697 698
698 BT_DBG("firmware data %p size %d", firmware->data, firmware->size); 699 BT_DBG("firmware data %p size %d", firmware->data, firmware->size);
699 700
700 if (bfusb_load_firmware(bfusb, firmware->data, firmware->size) < 0) { 701 if (bfusb_load_firmware(data, firmware->data, firmware->size) < 0) {
701 BT_ERR("Firmware loading failed"); 702 BT_ERR("Firmware loading failed");
702 goto release; 703 goto release;
703 } 704 }
@@ -711,10 +712,10 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
711 goto error; 712 goto error;
712 } 713 }
713 714
714 bfusb->hdev = hdev; 715 data->hdev = hdev;
715 716
716 hdev->type = HCI_USB; 717 hdev->type = HCI_USB;
717 hdev->driver_data = bfusb; 718 hdev->driver_data = data;
718 SET_HCIDEV_DEV(hdev, &intf->dev); 719 SET_HCIDEV_DEV(hdev, &intf->dev);
719 720
720 hdev->open = bfusb_open; 721 hdev->open = bfusb_open;
@@ -732,7 +733,7 @@ static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *i
732 goto error; 733 goto error;
733 } 734 }
734 735
735 usb_set_intfdata(intf, bfusb); 736 usb_set_intfdata(intf, data);
736 737
737 return 0; 738 return 0;
738 739
@@ -740,7 +741,7 @@ release:
740 release_firmware(firmware); 741 release_firmware(firmware);
741 742
742error: 743error:
743 kfree(bfusb); 744 kfree(data);
744 745
745done: 746done:
746 return -EIO; 747 return -EIO;
@@ -748,8 +749,8 @@ done:
748 749
749static void bfusb_disconnect(struct usb_interface *intf) 750static void bfusb_disconnect(struct usb_interface *intf)
750{ 751{
751 struct bfusb *bfusb = usb_get_intfdata(intf); 752 struct bfusb_data *data = usb_get_intfdata(intf);
752 struct hci_dev *hdev = bfusb->hdev; 753 struct hci_dev *hdev = data->hdev;
753 754
754 BT_DBG("intf %p", intf); 755 BT_DBG("intf %p", intf);
755 756
@@ -779,7 +780,8 @@ static int __init bfusb_init(void)
779 780
780 BT_INFO("BlueFRITZ! USB driver ver %s", VERSION); 781 BT_INFO("BlueFRITZ! USB driver ver %s", VERSION);
781 782
782 if ((err = usb_register(&bfusb_driver)) < 0) 783 err = usb_register(&bfusb_driver);
784 if (err < 0)
783 BT_ERR("Failed to register BlueFRITZ! USB driver"); 785 BT_ERR("Failed to register BlueFRITZ! USB driver");
784 786
785 return err; 787 return err;
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index aac67a3a6019..fc2130f1776a 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -2,9 +2,9 @@
2 * 2 *
3 * Bluetooth virtual HCI driver 3 * Bluetooth virtual HCI driver
4 * 4 *
5 * Copyright (C) 2000-2001 Qualcomm Incorporated 5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> 6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org> 7 * Copyright (C) 2004-2006 Marcel Holtmann <marcel@holtmann.org>
8 * 8 *
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
@@ -72,21 +72,21 @@ static int vhci_open_dev(struct hci_dev *hdev)
72 72
73static int vhci_close_dev(struct hci_dev *hdev) 73static int vhci_close_dev(struct hci_dev *hdev)
74{ 74{
75 struct vhci_data *vhci = hdev->driver_data; 75 struct vhci_data *data = hdev->driver_data;
76 76
77 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) 77 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
78 return 0; 78 return 0;
79 79
80 skb_queue_purge(&vhci->readq); 80 skb_queue_purge(&data->readq);
81 81
82 return 0; 82 return 0;
83} 83}
84 84
85static int vhci_flush(struct hci_dev *hdev) 85static int vhci_flush(struct hci_dev *hdev)
86{ 86{
87 struct vhci_data *vhci = hdev->driver_data; 87 struct vhci_data *data = hdev->driver_data;
88 88
89 skb_queue_purge(&vhci->readq); 89 skb_queue_purge(&data->readq);
90 90
91 return 0; 91 return 0;
92} 92}
@@ -94,7 +94,7 @@ static int vhci_flush(struct hci_dev *hdev)
94static int vhci_send_frame(struct sk_buff *skb) 94static int vhci_send_frame(struct sk_buff *skb)
95{ 95{
96 struct hci_dev* hdev = (struct hci_dev *) skb->dev; 96 struct hci_dev* hdev = (struct hci_dev *) skb->dev;
97 struct vhci_data *vhci; 97 struct vhci_data *data;
98 98
99 if (!hdev) { 99 if (!hdev) {
100 BT_ERR("Frame for unknown HCI device (hdev=NULL)"); 100 BT_ERR("Frame for unknown HCI device (hdev=NULL)");
@@ -104,15 +104,15 @@ static int vhci_send_frame(struct sk_buff *skb)
104 if (!test_bit(HCI_RUNNING, &hdev->flags)) 104 if (!test_bit(HCI_RUNNING, &hdev->flags))
105 return -EBUSY; 105 return -EBUSY;
106 106
107 vhci = hdev->driver_data; 107 data = hdev->driver_data;
108 108
109 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); 109 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
110 skb_queue_tail(&vhci->readq, skb); 110 skb_queue_tail(&data->readq, skb);
111 111
112 if (vhci->flags & VHCI_FASYNC) 112 if (data->flags & VHCI_FASYNC)
113 kill_fasync(&vhci->fasync, SIGIO, POLL_IN); 113 kill_fasync(&data->fasync, SIGIO, POLL_IN);
114 114
115 wake_up_interruptible(&vhci->read_wait); 115 wake_up_interruptible(&data->read_wait);
116 116
117 return 0; 117 return 0;
118} 118}
@@ -122,7 +122,7 @@ static void vhci_destruct(struct hci_dev *hdev)
122 kfree(hdev->driver_data); 122 kfree(hdev->driver_data);
123} 123}
124 124
125static inline ssize_t vhci_get_user(struct vhci_data *vhci, 125static inline ssize_t vhci_get_user(struct vhci_data *data,
126 const char __user *buf, size_t count) 126 const char __user *buf, size_t count)
127{ 127{
128 struct sk_buff *skb; 128 struct sk_buff *skb;
@@ -139,7 +139,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci,
139 return -EFAULT; 139 return -EFAULT;
140 } 140 }
141 141
142 skb->dev = (void *) vhci->hdev; 142 skb->dev = (void *) data->hdev;
143 bt_cb(skb)->pkt_type = *((__u8 *) skb->data); 143 bt_cb(skb)->pkt_type = *((__u8 *) skb->data);
144 skb_pull(skb, 1); 144 skb_pull(skb, 1);
145 145
@@ -148,7 +148,7 @@ static inline ssize_t vhci_get_user(struct vhci_data *vhci,
148 return count; 148 return count;
149} 149}
150 150
151static inline ssize_t vhci_put_user(struct vhci_data *vhci, 151static inline ssize_t vhci_put_user(struct vhci_data *data,
152 struct sk_buff *skb, char __user *buf, int count) 152 struct sk_buff *skb, char __user *buf, int count)
153{ 153{
154 char __user *ptr = buf; 154 char __user *ptr = buf;
@@ -161,42 +161,43 @@ static inline ssize_t vhci_put_user(struct vhci_data *vhci,
161 161
162 total += len; 162 total += len;
163 163
164 vhci->hdev->stat.byte_tx += len; 164 data->hdev->stat.byte_tx += len;
165 165
166 switch (bt_cb(skb)->pkt_type) { 166 switch (bt_cb(skb)->pkt_type) {
167 case HCI_COMMAND_PKT: 167 case HCI_COMMAND_PKT:
168 vhci->hdev->stat.cmd_tx++; 168 data->hdev->stat.cmd_tx++;
169 break; 169 break;
170 170
171 case HCI_ACLDATA_PKT: 171 case HCI_ACLDATA_PKT:
172 vhci->hdev->stat.acl_tx++; 172 data->hdev->stat.acl_tx++;
173 break; 173 break;
174 174
175 case HCI_SCODATA_PKT: 175 case HCI_SCODATA_PKT:
176 vhci->hdev->stat.cmd_tx++; 176 data->hdev->stat.cmd_tx++;
177 break; 177 break;
178 }; 178 };
179 179
180 return total; 180 return total;
181} 181}
182 182
183static loff_t vhci_llseek(struct file * file, loff_t offset, int origin) 183static loff_t vhci_llseek(struct file *file, loff_t offset, int origin)
184{ 184{
185 return -ESPIPE; 185 return -ESPIPE;
186} 186}
187 187
188static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, loff_t *pos) 188static ssize_t vhci_read(struct file *file,
189 char __user *buf, size_t count, loff_t *pos)
189{ 190{
190 DECLARE_WAITQUEUE(wait, current); 191 DECLARE_WAITQUEUE(wait, current);
191 struct vhci_data *vhci = file->private_data; 192 struct vhci_data *data = file->private_data;
192 struct sk_buff *skb; 193 struct sk_buff *skb;
193 ssize_t ret = 0; 194 ssize_t ret = 0;
194 195
195 add_wait_queue(&vhci->read_wait, &wait); 196 add_wait_queue(&data->read_wait, &wait);
196 while (count) { 197 while (count) {
197 set_current_state(TASK_INTERRUPTIBLE); 198 set_current_state(TASK_INTERRUPTIBLE);
198 199
199 skb = skb_dequeue(&vhci->readq); 200 skb = skb_dequeue(&data->readq);
200 if (!skb) { 201 if (!skb) {
201 if (file->f_flags & O_NONBLOCK) { 202 if (file->f_flags & O_NONBLOCK) {
202 ret = -EAGAIN; 203 ret = -EAGAIN;
@@ -213,7 +214,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
213 } 214 }
214 215
215 if (access_ok(VERIFY_WRITE, buf, count)) 216 if (access_ok(VERIFY_WRITE, buf, count))
216 ret = vhci_put_user(vhci, skb, buf, count); 217 ret = vhci_put_user(data, skb, buf, count);
217 else 218 else
218 ret = -EFAULT; 219 ret = -EFAULT;
219 220
@@ -221,7 +222,7 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
221 break; 222 break;
222 } 223 }
223 set_current_state(TASK_RUNNING); 224 set_current_state(TASK_RUNNING);
224 remove_wait_queue(&vhci->read_wait, &wait); 225 remove_wait_queue(&data->read_wait, &wait);
225 226
226 return ret; 227 return ret;
227} 228}
@@ -229,21 +230,21 @@ static ssize_t vhci_read(struct file * file, char __user * buf, size_t count, lo
229static ssize_t vhci_write(struct file *file, 230static ssize_t vhci_write(struct file *file,
230 const char __user *buf, size_t count, loff_t *pos) 231 const char __user *buf, size_t count, loff_t *pos)
231{ 232{
232 struct vhci_data *vhci = file->private_data; 233 struct vhci_data *data = file->private_data;
233 234
234 if (!access_ok(VERIFY_READ, buf, count)) 235 if (!access_ok(VERIFY_READ, buf, count))
235 return -EFAULT; 236 return -EFAULT;
236 237
237 return vhci_get_user(vhci, buf, count); 238 return vhci_get_user(data, buf, count);
238} 239}
239 240
240static unsigned int vhci_poll(struct file *file, poll_table *wait) 241static unsigned int vhci_poll(struct file *file, poll_table *wait)
241{ 242{
242 struct vhci_data *vhci = file->private_data; 243 struct vhci_data *data = file->private_data;
243 244
244 poll_wait(file, &vhci->read_wait, wait); 245 poll_wait(file, &data->read_wait, wait);
245 246
246 if (!skb_queue_empty(&vhci->readq)) 247 if (!skb_queue_empty(&data->readq))
247 return POLLIN | POLLRDNORM; 248 return POLLIN | POLLRDNORM;
248 249
249 return POLLOUT | POLLWRNORM; 250 return POLLOUT | POLLWRNORM;
@@ -257,26 +258,26 @@ static int vhci_ioctl(struct inode *inode, struct file *file,
257 258
258static int vhci_open(struct inode *inode, struct file *file) 259static int vhci_open(struct inode *inode, struct file *file)
259{ 260{
260 struct vhci_data *vhci; 261 struct vhci_data *data;
261 struct hci_dev *hdev; 262 struct hci_dev *hdev;
262 263
263 vhci = kzalloc(sizeof(struct vhci_data), GFP_KERNEL); 264 data = kzalloc(sizeof(struct vhci_data), GFP_KERNEL);
264 if (!vhci) 265 if (!data)
265 return -ENOMEM; 266 return -ENOMEM;
266 267
267 skb_queue_head_init(&vhci->readq); 268 skb_queue_head_init(&data->readq);
268 init_waitqueue_head(&vhci->read_wait); 269 init_waitqueue_head(&data->read_wait);
269 270
270 hdev = hci_alloc_dev(); 271 hdev = hci_alloc_dev();
271 if (!hdev) { 272 if (!hdev) {
272 kfree(vhci); 273 kfree(data);
273 return -ENOMEM; 274 return -ENOMEM;
274 } 275 }
275 276
276 vhci->hdev = hdev; 277 data->hdev = hdev;
277 278
278 hdev->type = HCI_VHCI; 279 hdev->type = HCI_VHCI;
279 hdev->driver_data = vhci; 280 hdev->driver_data = data;
280 281
281 hdev->open = vhci_open_dev; 282 hdev->open = vhci_open_dev;
282 hdev->close = vhci_close_dev; 283 hdev->close = vhci_close_dev;
@@ -288,20 +289,20 @@ static int vhci_open(struct inode *inode, struct file *file)
288 289
289 if (hci_register_dev(hdev) < 0) { 290 if (hci_register_dev(hdev) < 0) {
290 BT_ERR("Can't register HCI device"); 291 BT_ERR("Can't register HCI device");
291 kfree(vhci); 292 kfree(data);
292 hci_free_dev(hdev); 293 hci_free_dev(hdev);
293 return -EBUSY; 294 return -EBUSY;
294 } 295 }
295 296
296 file->private_data = vhci; 297 file->private_data = data;
297 298
298 return nonseekable_open(inode, file); 299 return nonseekable_open(inode, file);
299} 300}
300 301
301static int vhci_release(struct inode *inode, struct file *file) 302static int vhci_release(struct inode *inode, struct file *file)
302{ 303{
303 struct vhci_data *vhci = file->private_data; 304 struct vhci_data *data = file->private_data;
304 struct hci_dev *hdev = vhci->hdev; 305 struct hci_dev *hdev = data->hdev;
305 306
306 if (hci_unregister_dev(hdev) < 0) { 307 if (hci_unregister_dev(hdev) < 0) {
307 BT_ERR("Can't unregister HCI device %s", hdev->name); 308 BT_ERR("Can't unregister HCI device %s", hdev->name);
@@ -316,17 +317,17 @@ static int vhci_release(struct inode *inode, struct file *file)
316 317
317static int vhci_fasync(int fd, struct file *file, int on) 318static int vhci_fasync(int fd, struct file *file, int on)
318{ 319{
319 struct vhci_data *vhci = file->private_data; 320 struct vhci_data *data = file->private_data;
320 int err; 321 int err;
321 322
322 err = fasync_helper(fd, file, on, &vhci->fasync); 323 err = fasync_helper(fd, file, on, &data->fasync);
323 if (err < 0) 324 if (err < 0)
324 return err; 325 return err;
325 326
326 if (on) 327 if (on)
327 vhci->flags |= VHCI_FASYNC; 328 data->flags |= VHCI_FASYNC;
328 else 329 else
329 vhci->flags &= ~VHCI_FASYNC; 330 data->flags &= ~VHCI_FASYNC;
330 331
331 return 0; 332 return 0;
332} 333}