diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-22 22:22:33 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-22 22:22:33 -0400 |
commit | f09cc910fe3af7e63298105bc0482653eb534c3c (patch) | |
tree | a09dca8a3d033352edff6cb1d911f3cd0e980f1f /drivers | |
parent | 8b0eaccab4584ace24d233214bfee3cb50e49a60 (diff) | |
parent | ea2c47b42f12dadbad9d879fb6df102b9003ab82 (diff) |
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
* 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6: (30 commits)
[IPSEC] IPV6: Fix to add tunnel mode SA correctly.
[NET]: Cut off the queue_mapping field from sk_buff
[NET]: Hide the queue_mapping field inside netif_subqueue_stopped
[NET]: Make and use skb_get_queue_mapping
[NET]: Use the skb_set_queue_mapping where appropriate
[INET]: Use MODULE_ALIAS_NET_PF_PROTO_TYPE where possible.
[INET]: Let inet_diag and friends autoload
[NIU]: Cleanup PAGE_SIZE checks a bit
[NET]: Fix SKB_WITH_OVERHEAD calculation
[ATM]: Fix clip module reload crash.
[TG3]: Update version to 3.85
[TG3]: PCI command adjustment
[TG3]: Add management FW version to ethtool report
[TG3]: Add 5723 support
[Bluetooth] Convert RFCOMM to use kthread API
[Bluetooth] Add constant for Bluetooth socket options level
[Bluetooth] Add support for handling simple eSCO links
[Bluetooth] Add address and channel attribute to RFCOMM TTY device
[Bluetooth] Fix wrong argument in debug code of HIDP
[Bluetooth] Add generic driver for Bluetooth USB devices
...
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/bluetooth/Kconfig | 35 | ||||
-rw-r--r-- | drivers/bluetooth/Makefile | 4 | ||||
-rw-r--r-- | drivers/bluetooth/bluecard_cs.c | 5 | ||||
-rw-r--r-- | drivers/bluetooth/bpa10x.c | 624 | ||||
-rw-r--r-- | drivers/bluetooth/bt3c_cs.c | 5 | ||||
-rw-r--r-- | drivers/bluetooth/btsdio.c | 406 | ||||
-rw-r--r-- | drivers/bluetooth/btuart_cs.c | 5 | ||||
-rw-r--r-- | drivers/bluetooth/btusb.c | 564 | ||||
-rw-r--r-- | drivers/bluetooth/dtl1_cs.c | 5 | ||||
-rw-r--r-- | drivers/bluetooth/hci_bcsp.c | 3 | ||||
-rw-r--r-- | drivers/bluetooth/hci_ldisc.c | 8 | ||||
-rw-r--r-- | drivers/bluetooth/hci_ll.c | 531 | ||||
-rw-r--r-- | drivers/bluetooth/hci_uart.h | 8 | ||||
-rw-r--r-- | drivers/net/cpmac.c | 2 | ||||
-rw-r--r-- | drivers/net/niu.c | 34 | ||||
-rw-r--r-- | drivers/net/tg3.c | 95 | ||||
-rw-r--r-- | drivers/net/tg3.h | 11 |
17 files changed, 1912 insertions, 433 deletions
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index b9fbe6e7f9ae..075598e1c502 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig | |||
@@ -22,6 +22,30 @@ config BT_HCIUSB_SCO | |||
22 | 22 | ||
23 | Say Y here to compile support for SCO over HCI USB. | 23 | Say Y here to compile support for SCO over HCI USB. |
24 | 24 | ||
25 | config BT_HCIBTUSB | ||
26 | tristate "HCI USB driver (alternate version)" | ||
27 | depends on USB && EXPERIMENTAL && BT_HCIUSB=n | ||
28 | help | ||
29 | Bluetooth HCI USB driver. | ||
30 | This driver is required if you want to use Bluetooth devices with | ||
31 | USB interface. | ||
32 | |||
33 | This driver is still experimental and has no SCO support. | ||
34 | |||
35 | Say Y here to compile support for Bluetooth USB devices into the | ||
36 | kernel or say M to compile it as module (btusb). | ||
37 | |||
38 | config BT_HCIBTSDIO | ||
39 | tristate "HCI SDIO driver" | ||
40 | depends on MMC | ||
41 | help | ||
42 | Bluetooth HCI SDIO driver. | ||
43 | This driver is required if you want to use Bluetooth device with | ||
44 | SDIO interface. | ||
45 | |||
46 | Say Y here to compile support for Bluetooth SDIO devices into the | ||
47 | kernel or say M to compile it as module (btsdio). | ||
48 | |||
25 | config BT_HCIUART | 49 | config BT_HCIUART |
26 | tristate "HCI UART driver" | 50 | tristate "HCI UART driver" |
27 | help | 51 | help |
@@ -55,6 +79,17 @@ config BT_HCIUART_BCSP | |||
55 | 79 | ||
56 | Say Y here to compile support for HCI BCSP protocol. | 80 | Say Y here to compile support for HCI BCSP protocol. |
57 | 81 | ||
82 | config BT_HCIUART_LL | ||
83 | bool "HCILL protocol support" | ||
84 | depends on BT_HCIUART | ||
85 | help | ||
86 | HCILL (HCI Low Level) is a serial protocol for communication | ||
87 | between Bluetooth device and host. This protocol is required for | ||
88 | serial Bluetooth devices that are based on Texas Instruments' | ||
89 | BRF chips. | ||
90 | |||
91 | Say Y here to compile support for HCILL protocol. | ||
92 | |||
58 | config BT_HCIBCM203X | 93 | config BT_HCIBCM203X |
59 | tristate "HCI BCM203x USB driver" | 94 | tristate "HCI BCM203x USB driver" |
60 | depends on USB | 95 | depends on USB |
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index 08c10e178e02..77444afbf107 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile | |||
@@ -13,7 +13,11 @@ obj-$(CONFIG_BT_HCIBT3C) += bt3c_cs.o | |||
13 | obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o | 13 | obj-$(CONFIG_BT_HCIBLUECARD) += bluecard_cs.o |
14 | obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o | 14 | obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o |
15 | 15 | ||
16 | obj-$(CONFIG_BT_HCIBTUSB) += btusb.o | ||
17 | obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o | ||
18 | |||
16 | hci_uart-y := hci_ldisc.o | 19 | hci_uart-y := hci_ldisc.o |
17 | hci_uart-$(CONFIG_BT_HCIUART_H4) += hci_h4.o | 20 | hci_uart-$(CONFIG_BT_HCIUART_H4) += hci_h4.o |
18 | hci_uart-$(CONFIG_BT_HCIUART_BCSP) += hci_bcsp.o | 21 | hci_uart-$(CONFIG_BT_HCIUART_BCSP) += hci_bcsp.o |
22 | hci_uart-$(CONFIG_BT_HCIUART_LL) += hci_ll.o | ||
19 | hci_uart-objs := $(hci_uart-y) | 23 | hci_uart-objs := $(hci_uart-y) |
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c index 851de4d5b7de..bcf57927b7a8 100644 --- a/drivers/bluetooth/bluecard_cs.c +++ b/drivers/bluetooth/bluecard_cs.c | |||
@@ -503,10 +503,7 @@ static irqreturn_t bluecard_interrupt(int irq, void *dev_inst) | |||
503 | unsigned int iobase; | 503 | unsigned int iobase; |
504 | unsigned char reg; | 504 | unsigned char reg; |
505 | 505 | ||
506 | if (!info || !info->hdev) { | 506 | BUG_ON(!info->hdev); |
507 | BT_ERR("Call of irq %d for unknown device", irq); | ||
508 | return IRQ_NONE; | ||
509 | } | ||
510 | 507 | ||
511 | if (!test_bit(CARD_READY, &(info->hw_state))) | 508 | if (!test_bit(CARD_READY, &(info->hw_state))) |
512 | return IRQ_HANDLED; | 509 | return IRQ_HANDLED; |
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c index e8ebd5d3de86..1375b5345a0a 100644 --- a/drivers/bluetooth/bpa10x.c +++ b/drivers/bluetooth/bpa10x.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * | 2 | * |
3 | * Digianswer Bluetooth USB driver | 3 | * Digianswer Bluetooth USB driver |
4 | * | 4 | * |
5 | * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org> | 5 | * Copyright (C) 2004-2007 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 |
@@ -21,13 +21,14 @@ | |||
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/module.h> | ||
25 | |||
26 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/module.h> | ||
27 | #include <linux/init.h> | 26 | #include <linux/init.h> |
28 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
29 | #include <linux/types.h> | 28 | #include <linux/types.h> |
29 | #include <linux/sched.h> | ||
30 | #include <linux/errno.h> | 30 | #include <linux/errno.h> |
31 | #include <linux/skbuff.h> | ||
31 | 32 | ||
32 | #include <linux/usb.h> | 33 | #include <linux/usb.h> |
33 | 34 | ||
@@ -39,7 +40,7 @@ | |||
39 | #define BT_DBG(D...) | 40 | #define BT_DBG(D...) |
40 | #endif | 41 | #endif |
41 | 42 | ||
42 | #define VERSION "0.8" | 43 | #define VERSION "0.9" |
43 | 44 | ||
44 | static int ignore = 0; | 45 | static int ignore = 0; |
45 | 46 | ||
@@ -52,393 +53,285 @@ static struct usb_device_id bpa10x_table[] = { | |||
52 | 53 | ||
53 | MODULE_DEVICE_TABLE(usb, bpa10x_table); | 54 | MODULE_DEVICE_TABLE(usb, bpa10x_table); |
54 | 55 | ||
55 | #define BPA10X_CMD_EP 0x00 | ||
56 | #define BPA10X_EVT_EP 0x81 | ||
57 | #define BPA10X_TX_EP 0x02 | ||
58 | #define BPA10X_RX_EP 0x82 | ||
59 | |||
60 | #define BPA10X_CMD_BUF_SIZE 252 | ||
61 | #define BPA10X_EVT_BUF_SIZE 16 | ||
62 | #define BPA10X_TX_BUF_SIZE 384 | ||
63 | #define BPA10X_RX_BUF_SIZE 384 | ||
64 | |||
65 | struct bpa10x_data { | 56 | struct bpa10x_data { |
66 | struct hci_dev *hdev; | 57 | struct hci_dev *hdev; |
67 | struct usb_device *udev; | 58 | struct usb_device *udev; |
68 | 59 | ||
69 | rwlock_t lock; | 60 | struct usb_anchor tx_anchor; |
61 | struct usb_anchor rx_anchor; | ||
70 | 62 | ||
71 | struct sk_buff_head cmd_queue; | 63 | struct sk_buff *rx_skb[2]; |
72 | struct urb *cmd_urb; | ||
73 | struct urb *evt_urb; | ||
74 | struct sk_buff *evt_skb; | ||
75 | unsigned int evt_len; | ||
76 | |||
77 | struct sk_buff_head tx_queue; | ||
78 | struct urb *tx_urb; | ||
79 | struct urb *rx_urb; | ||
80 | }; | 64 | }; |
81 | 65 | ||
82 | #define HCI_VENDOR_HDR_SIZE 5 | 66 | #define HCI_VENDOR_HDR_SIZE 5 |
83 | 67 | ||
84 | struct hci_vendor_hdr { | 68 | struct hci_vendor_hdr { |
85 | __u8 type; | 69 | __u8 type; |
86 | __le16 snum; | 70 | __le16 snum; |
87 | __le16 dlen; | 71 | __le16 dlen; |
88 | } __attribute__ ((packed)); | 72 | } __attribute__ ((packed)); |
89 | 73 | ||
90 | static void bpa10x_recv_bulk(struct bpa10x_data *data, unsigned char *buf, int count) | 74 | static int bpa10x_recv(struct hci_dev *hdev, int queue, void *buf, int count) |
91 | { | 75 | { |
92 | struct hci_acl_hdr *ah; | 76 | struct bpa10x_data *data = hdev->driver_data; |
93 | struct hci_sco_hdr *sh; | 77 | |
94 | struct hci_vendor_hdr *vh; | 78 | BT_DBG("%s queue %d buffer %p count %d", hdev->name, |
95 | struct sk_buff *skb; | 79 | queue, buf, count); |
96 | int len; | 80 | |
81 | if (queue < 0 || queue > 1) | ||
82 | return -EILSEQ; | ||
83 | |||
84 | hdev->stat.byte_rx += count; | ||
97 | 85 | ||
98 | while (count) { | 86 | while (count) { |
99 | switch (*buf++) { | 87 | struct sk_buff *skb = data->rx_skb[queue]; |
100 | case HCI_ACLDATA_PKT: | 88 | struct { __u8 type; int expect; } *scb; |
101 | ah = (struct hci_acl_hdr *) buf; | 89 | int type, len = 0; |
102 | len = HCI_ACL_HDR_SIZE + __le16_to_cpu(ah->dlen); | ||
103 | skb = bt_skb_alloc(len, GFP_ATOMIC); | ||
104 | if (skb) { | ||
105 | memcpy(skb_put(skb, len), buf, len); | ||
106 | skb->dev = (void *) data->hdev; | ||
107 | bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT; | ||
108 | hci_recv_frame(skb); | ||
109 | } | ||
110 | break; | ||
111 | 90 | ||
112 | case HCI_SCODATA_PKT: | 91 | if (!skb) { |
113 | sh = (struct hci_sco_hdr *) buf; | 92 | /* Start of the frame */ |
114 | len = HCI_SCO_HDR_SIZE + sh->dlen; | 93 | |
115 | skb = bt_skb_alloc(len, GFP_ATOMIC); | 94 | type = *((__u8 *) buf); |
116 | if (skb) { | 95 | count--; buf++; |
117 | memcpy(skb_put(skb, len), buf, len); | 96 | |
118 | skb->dev = (void *) data->hdev; | 97 | switch (type) { |
119 | bt_cb(skb)->pkt_type = HCI_SCODATA_PKT; | 98 | case HCI_EVENT_PKT: |
120 | hci_recv_frame(skb); | 99 | if (count >= HCI_EVENT_HDR_SIZE) { |
100 | struct hci_event_hdr *h = buf; | ||
101 | len = HCI_EVENT_HDR_SIZE + h->plen; | ||
102 | } else | ||
103 | return -EILSEQ; | ||
104 | break; | ||
105 | |||
106 | case HCI_ACLDATA_PKT: | ||
107 | if (count >= HCI_ACL_HDR_SIZE) { | ||
108 | struct hci_acl_hdr *h = buf; | ||
109 | len = HCI_ACL_HDR_SIZE + | ||
110 | __le16_to_cpu(h->dlen); | ||
111 | } else | ||
112 | return -EILSEQ; | ||
113 | break; | ||
114 | |||
115 | case HCI_SCODATA_PKT: | ||
116 | if (count >= HCI_SCO_HDR_SIZE) { | ||
117 | struct hci_sco_hdr *h = buf; | ||
118 | len = HCI_SCO_HDR_SIZE + h->dlen; | ||
119 | } else | ||
120 | return -EILSEQ; | ||
121 | break; | ||
122 | |||
123 | case HCI_VENDOR_PKT: | ||
124 | if (count >= HCI_VENDOR_HDR_SIZE) { | ||
125 | struct hci_vendor_hdr *h = buf; | ||
126 | len = HCI_VENDOR_HDR_SIZE + | ||
127 | __le16_to_cpu(h->dlen); | ||
128 | } else | ||
129 | return -EILSEQ; | ||
130 | break; | ||
121 | } | 131 | } |
122 | break; | ||
123 | 132 | ||
124 | case HCI_VENDOR_PKT: | ||
125 | vh = (struct hci_vendor_hdr *) buf; | ||
126 | len = HCI_VENDOR_HDR_SIZE + __le16_to_cpu(vh->dlen); | ||
127 | skb = bt_skb_alloc(len, GFP_ATOMIC); | 133 | skb = bt_skb_alloc(len, GFP_ATOMIC); |
128 | if (skb) { | 134 | if (!skb) { |
129 | memcpy(skb_put(skb, len), buf, len); | 135 | BT_ERR("%s no memory for packet", hdev->name); |
130 | skb->dev = (void *) data->hdev; | 136 | return -ENOMEM; |
131 | bt_cb(skb)->pkt_type = HCI_VENDOR_PKT; | ||
132 | hci_recv_frame(skb); | ||
133 | } | 137 | } |
134 | break; | ||
135 | |||
136 | default: | ||
137 | len = count - 1; | ||
138 | break; | ||
139 | } | ||
140 | 138 | ||
141 | buf += len; | 139 | skb->dev = (void *) hdev; |
142 | count -= (len + 1); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | static int bpa10x_recv_event(struct bpa10x_data *data, unsigned char *buf, int size) | ||
147 | { | ||
148 | BT_DBG("data %p buf %p size %d", data, buf, size); | ||
149 | 140 | ||
150 | if (data->evt_skb) { | 141 | data->rx_skb[queue] = skb; |
151 | struct sk_buff *skb = data->evt_skb; | ||
152 | 142 | ||
153 | memcpy(skb_put(skb, size), buf, size); | 143 | scb = (void *) skb->cb; |
144 | scb->type = type; | ||
145 | scb->expect = len; | ||
146 | } else { | ||
147 | /* Continuation */ | ||
154 | 148 | ||
155 | if (skb->len == data->evt_len) { | 149 | scb = (void *) skb->cb; |
156 | data->evt_skb = NULL; | 150 | len = scb->expect; |
157 | data->evt_len = 0; | ||
158 | hci_recv_frame(skb); | ||
159 | } | ||
160 | } else { | ||
161 | struct sk_buff *skb; | ||
162 | struct hci_event_hdr *hdr; | ||
163 | unsigned char pkt_type; | ||
164 | int pkt_len = 0; | ||
165 | |||
166 | if (size < HCI_EVENT_HDR_SIZE + 1) { | ||
167 | BT_ERR("%s event packet block with size %d is too short", | ||
168 | data->hdev->name, size); | ||
169 | return -EILSEQ; | ||
170 | } | 151 | } |
171 | 152 | ||
172 | pkt_type = *buf++; | 153 | len = min(len, count); |
173 | size--; | ||
174 | |||
175 | if (pkt_type != HCI_EVENT_PKT) { | ||
176 | BT_ERR("%s unexpected event packet start byte 0x%02x", | ||
177 | data->hdev->name, pkt_type); | ||
178 | return -EPROTO; | ||
179 | } | ||
180 | 154 | ||
181 | hdr = (struct hci_event_hdr *) buf; | 155 | memcpy(skb_put(skb, len), buf, len); |
182 | pkt_len = HCI_EVENT_HDR_SIZE + hdr->plen; | ||
183 | 156 | ||
184 | skb = bt_skb_alloc(pkt_len, GFP_ATOMIC); | 157 | scb->expect -= len; |
185 | if (!skb) { | ||
186 | BT_ERR("%s no memory for new event packet", | ||
187 | data->hdev->name); | ||
188 | return -ENOMEM; | ||
189 | } | ||
190 | 158 | ||
191 | skb->dev = (void *) data->hdev; | 159 | if (scb->expect == 0) { |
192 | bt_cb(skb)->pkt_type = pkt_type; | 160 | /* Complete frame */ |
193 | 161 | ||
194 | memcpy(skb_put(skb, size), buf, size); | 162 | data->rx_skb[queue] = NULL; |
195 | 163 | ||
196 | if (pkt_len == size) { | 164 | bt_cb(skb)->pkt_type = scb->type; |
197 | hci_recv_frame(skb); | 165 | hci_recv_frame(skb); |
198 | } else { | ||
199 | data->evt_skb = skb; | ||
200 | data->evt_len = pkt_len; | ||
201 | } | 166 | } |
167 | |||
168 | count -= len; buf += len; | ||
202 | } | 169 | } |
203 | 170 | ||
204 | return 0; | 171 | return 0; |
205 | } | 172 | } |
206 | 173 | ||
207 | static void bpa10x_wakeup(struct bpa10x_data *data) | 174 | static void bpa10x_tx_complete(struct urb *urb) |
208 | { | 175 | { |
209 | struct urb *urb; | 176 | struct sk_buff *skb = urb->context; |
210 | struct sk_buff *skb; | 177 | struct hci_dev *hdev = (struct hci_dev *) skb->dev; |
211 | int err; | ||
212 | 178 | ||
213 | BT_DBG("data %p", data); | 179 | BT_DBG("%s urb %p status %d count %d", hdev->name, |
180 | urb, urb->status, urb->actual_length); | ||
214 | 181 | ||
215 | urb = data->cmd_urb; | 182 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
216 | if (urb->status == -EINPROGRESS) | 183 | goto done; |
217 | skb = NULL; | 184 | |
185 | if (!urb->status) | ||
186 | hdev->stat.byte_tx += urb->transfer_buffer_length; | ||
218 | else | 187 | else |
219 | skb = skb_dequeue(&data->cmd_queue); | 188 | hdev->stat.err_tx++; |
220 | 189 | ||
221 | if (skb) { | 190 | done: |
222 | struct usb_ctrlrequest *cr; | 191 | kfree(urb->setup_packet); |
223 | 192 | ||
224 | if (skb->len > BPA10X_CMD_BUF_SIZE) { | 193 | kfree_skb(skb); |
225 | BT_ERR("%s command packet with size %d is too big", | 194 | } |
226 | data->hdev->name, skb->len); | 195 | |
227 | kfree_skb(skb); | 196 | static void bpa10x_rx_complete(struct urb *urb) |
228 | return; | 197 | { |
229 | } | 198 | struct hci_dev *hdev = urb->context; |
199 | struct bpa10x_data *data = hdev->driver_data; | ||
200 | int err; | ||
230 | 201 | ||
231 | cr = (struct usb_ctrlrequest *) urb->setup_packet; | 202 | BT_DBG("%s urb %p status %d count %d", hdev->name, |
232 | cr->wLength = __cpu_to_le16(skb->len); | 203 | urb, urb->status, urb->actual_length); |
233 | 204 | ||
234 | skb_copy_from_linear_data(skb, urb->transfer_buffer, skb->len); | 205 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
235 | urb->transfer_buffer_length = skb->len; | 206 | return; |
236 | 207 | ||
237 | err = usb_submit_urb(urb, GFP_ATOMIC); | 208 | if (urb->status == 0) { |
238 | if (err < 0 && err != -ENODEV) { | 209 | if (bpa10x_recv(hdev, usb_pipebulk(urb->pipe), |
239 | BT_ERR("%s submit failed for command urb %p with error %d", | 210 | urb->transfer_buffer, |
240 | data->hdev->name, urb, err); | 211 | urb->actual_length) < 0) { |
241 | skb_queue_head(&data->cmd_queue, skb); | 212 | BT_ERR("%s corrupted event packet", hdev->name); |
242 | } else | 213 | hdev->stat.err_rx++; |
243 | kfree_skb(skb); | 214 | } |
244 | } | 215 | } |
245 | 216 | ||
246 | urb = data->tx_urb; | 217 | usb_anchor_urb(urb, &data->rx_anchor); |
247 | if (urb->status == -EINPROGRESS) | 218 | |
248 | skb = NULL; | 219 | err = usb_submit_urb(urb, GFP_ATOMIC); |
249 | else | 220 | if (err < 0) { |
250 | skb = skb_dequeue(&data->tx_queue); | 221 | BT_ERR("%s urb %p failed to resubmit (%d)", |
251 | 222 | hdev->name, urb, -err); | |
252 | if (skb) { | 223 | usb_unanchor_urb(urb); |
253 | skb_copy_from_linear_data(skb, urb->transfer_buffer, skb->len); | ||
254 | urb->transfer_buffer_length = skb->len; | ||
255 | |||
256 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
257 | if (err < 0 && err != -ENODEV) { | ||
258 | BT_ERR("%s submit failed for command urb %p with error %d", | ||
259 | data->hdev->name, urb, err); | ||
260 | skb_queue_head(&data->tx_queue, skb); | ||
261 | } else | ||
262 | kfree_skb(skb); | ||
263 | } | 224 | } |
264 | } | 225 | } |
265 | 226 | ||
266 | static void bpa10x_complete(struct urb *urb) | 227 | static inline int bpa10x_submit_intr_urb(struct hci_dev *hdev) |
267 | { | 228 | { |
268 | struct bpa10x_data *data = urb->context; | 229 | struct bpa10x_data *data = hdev->driver_data; |
269 | unsigned char *buf = urb->transfer_buffer; | 230 | struct urb *urb; |
270 | int err, count = urb->actual_length; | 231 | unsigned char *buf; |
232 | unsigned int pipe; | ||
233 | int err, size = 16; | ||
271 | 234 | ||
272 | BT_DBG("data %p urb %p buf %p count %d", data, urb, buf, count); | 235 | BT_DBG("%s", hdev->name); |
273 | 236 | ||
274 | read_lock(&data->lock); | 237 | urb = usb_alloc_urb(0, GFP_KERNEL); |
238 | if (!urb) | ||
239 | return -ENOMEM; | ||
275 | 240 | ||
276 | if (!test_bit(HCI_RUNNING, &data->hdev->flags)) | 241 | buf = kmalloc(size, GFP_KERNEL); |
277 | goto unlock; | 242 | if (!buf) { |
243 | usb_free_urb(urb); | ||
244 | return -ENOMEM; | ||
245 | } | ||
278 | 246 | ||
279 | if (urb->status < 0 || !count) | 247 | pipe = usb_rcvintpipe(data->udev, 0x81); |
280 | goto resubmit; | ||
281 | 248 | ||
282 | if (usb_pipein(urb->pipe)) { | 249 | usb_fill_int_urb(urb, data->udev, pipe, buf, size, |
283 | data->hdev->stat.byte_rx += count; | 250 | bpa10x_rx_complete, hdev, 1); |
284 | 251 | ||
285 | if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) | 252 | urb->transfer_flags |= URB_FREE_BUFFER; |
286 | bpa10x_recv_event(data, buf, count); | ||
287 | 253 | ||
288 | if (usb_pipetype(urb->pipe) == PIPE_BULK) | 254 | usb_anchor_urb(urb, &data->rx_anchor); |
289 | bpa10x_recv_bulk(data, buf, count); | ||
290 | } else { | ||
291 | data->hdev->stat.byte_tx += count; | ||
292 | 255 | ||
293 | bpa10x_wakeup(data); | 256 | err = usb_submit_urb(urb, GFP_KERNEL); |
257 | if (err < 0) { | ||
258 | BT_ERR("%s urb %p submission failed (%d)", | ||
259 | hdev->name, urb, -err); | ||
260 | usb_unanchor_urb(urb); | ||
261 | kfree(buf); | ||
294 | } | 262 | } |
295 | 263 | ||
296 | resubmit: | 264 | usb_free_urb(urb); |
297 | if (usb_pipein(urb->pipe)) { | ||
298 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
299 | if (err < 0 && err != -ENODEV) { | ||
300 | BT_ERR("%s urb %p type %d resubmit status %d", | ||
301 | data->hdev->name, urb, usb_pipetype(urb->pipe), err); | ||
302 | } | ||
303 | } | ||
304 | 265 | ||
305 | unlock: | 266 | return err; |
306 | read_unlock(&data->lock); | ||
307 | } | 267 | } |
308 | 268 | ||
309 | static inline struct urb *bpa10x_alloc_urb(struct usb_device *udev, unsigned int pipe, | 269 | static inline int bpa10x_submit_bulk_urb(struct hci_dev *hdev) |
310 | size_t size, gfp_t flags, void *data) | ||
311 | { | 270 | { |
271 | struct bpa10x_data *data = hdev->driver_data; | ||
312 | struct urb *urb; | 272 | struct urb *urb; |
313 | struct usb_ctrlrequest *cr; | ||
314 | unsigned char *buf; | 273 | unsigned char *buf; |
274 | unsigned int pipe; | ||
275 | int err, size = 64; | ||
315 | 276 | ||
316 | BT_DBG("udev %p data %p", udev, data); | 277 | BT_DBG("%s", hdev->name); |
317 | 278 | ||
318 | urb = usb_alloc_urb(0, flags); | 279 | urb = usb_alloc_urb(0, GFP_KERNEL); |
319 | if (!urb) | 280 | if (!urb) |
320 | return NULL; | 281 | return -ENOMEM; |
321 | 282 | ||
322 | buf = kmalloc(size, flags); | 283 | buf = kmalloc(size, GFP_KERNEL); |
323 | if (!buf) { | 284 | if (!buf) { |
324 | usb_free_urb(urb); | 285 | usb_free_urb(urb); |
325 | return NULL; | 286 | return -ENOMEM; |
326 | } | 287 | } |
327 | 288 | ||
328 | switch (usb_pipetype(pipe)) { | 289 | pipe = usb_rcvbulkpipe(data->udev, 0x82); |
329 | case PIPE_CONTROL: | ||
330 | cr = kmalloc(sizeof(*cr), flags); | ||
331 | if (!cr) { | ||
332 | kfree(buf); | ||
333 | usb_free_urb(urb); | ||
334 | return NULL; | ||
335 | } | ||
336 | 290 | ||
337 | cr->bRequestType = USB_TYPE_VENDOR; | 291 | usb_fill_bulk_urb(urb, data->udev, pipe, |
338 | cr->bRequest = 0; | 292 | buf, size, bpa10x_rx_complete, hdev); |
339 | cr->wIndex = 0; | ||
340 | cr->wValue = 0; | ||
341 | cr->wLength = __cpu_to_le16(0); | ||
342 | 293 | ||
343 | usb_fill_control_urb(urb, udev, pipe, (void *) cr, buf, 0, bpa10x_complete, data); | 294 | urb->transfer_flags |= URB_FREE_BUFFER; |
344 | break; | ||
345 | 295 | ||
346 | case PIPE_INTERRUPT: | 296 | usb_anchor_urb(urb, &data->rx_anchor); |
347 | usb_fill_int_urb(urb, udev, pipe, buf, size, bpa10x_complete, data, 1); | ||
348 | break; | ||
349 | 297 | ||
350 | case PIPE_BULK: | 298 | err = usb_submit_urb(urb, GFP_KERNEL); |
351 | usb_fill_bulk_urb(urb, udev, pipe, buf, size, bpa10x_complete, data); | 299 | if (err < 0) { |
352 | break; | 300 | BT_ERR("%s urb %p submission failed (%d)", |
353 | 301 | hdev->name, urb, -err); | |
354 | default: | 302 | usb_unanchor_urb(urb); |
355 | kfree(buf); | 303 | kfree(buf); |
356 | usb_free_urb(urb); | ||
357 | return NULL; | ||
358 | } | 304 | } |
359 | 305 | ||
360 | return urb; | ||
361 | } | ||
362 | |||
363 | static inline void bpa10x_free_urb(struct urb *urb) | ||
364 | { | ||
365 | BT_DBG("urb %p", urb); | ||
366 | |||
367 | if (!urb) | ||
368 | return; | ||
369 | |||
370 | kfree(urb->setup_packet); | ||
371 | kfree(urb->transfer_buffer); | ||
372 | |||
373 | usb_free_urb(urb); | 306 | usb_free_urb(urb); |
307 | |||
308 | return err; | ||
374 | } | 309 | } |
375 | 310 | ||
376 | static int bpa10x_open(struct hci_dev *hdev) | 311 | static int bpa10x_open(struct hci_dev *hdev) |
377 | { | 312 | { |
378 | struct bpa10x_data *data = hdev->driver_data; | 313 | struct bpa10x_data *data = hdev->driver_data; |
379 | struct usb_device *udev = data->udev; | ||
380 | unsigned long flags; | ||
381 | int err; | 314 | int err; |
382 | 315 | ||
383 | BT_DBG("hdev %p data %p", hdev, data); | 316 | BT_DBG("%s", hdev->name); |
384 | 317 | ||
385 | if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) | 318 | if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) |
386 | return 0; | 319 | return 0; |
387 | 320 | ||
388 | data->cmd_urb = bpa10x_alloc_urb(udev, usb_sndctrlpipe(udev, BPA10X_CMD_EP), | 321 | err = bpa10x_submit_intr_urb(hdev); |
389 | BPA10X_CMD_BUF_SIZE, GFP_KERNEL, data); | 322 | if (err < 0) |
390 | if (!data->cmd_urb) { | 323 | goto error; |
391 | err = -ENOMEM; | ||
392 | goto done; | ||
393 | } | ||
394 | |||
395 | data->evt_urb = bpa10x_alloc_urb(udev, usb_rcvintpipe(udev, BPA10X_EVT_EP), | ||
396 | BPA10X_EVT_BUF_SIZE, GFP_KERNEL, data); | ||
397 | if (!data->evt_urb) { | ||
398 | bpa10x_free_urb(data->cmd_urb); | ||
399 | err = -ENOMEM; | ||
400 | goto done; | ||
401 | } | ||
402 | |||
403 | data->rx_urb = bpa10x_alloc_urb(udev, usb_rcvbulkpipe(udev, BPA10X_RX_EP), | ||
404 | BPA10X_RX_BUF_SIZE, GFP_KERNEL, data); | ||
405 | if (!data->rx_urb) { | ||
406 | bpa10x_free_urb(data->evt_urb); | ||
407 | bpa10x_free_urb(data->cmd_urb); | ||
408 | err = -ENOMEM; | ||
409 | goto done; | ||
410 | } | ||
411 | |||
412 | data->tx_urb = bpa10x_alloc_urb(udev, usb_sndbulkpipe(udev, BPA10X_TX_EP), | ||
413 | BPA10X_TX_BUF_SIZE, GFP_KERNEL, data); | ||
414 | if (!data->rx_urb) { | ||
415 | bpa10x_free_urb(data->rx_urb); | ||
416 | bpa10x_free_urb(data->evt_urb); | ||
417 | bpa10x_free_urb(data->cmd_urb); | ||
418 | err = -ENOMEM; | ||
419 | goto done; | ||
420 | } | ||
421 | 324 | ||
422 | write_lock_irqsave(&data->lock, flags); | 325 | err = bpa10x_submit_bulk_urb(hdev); |
326 | if (err < 0) | ||
327 | goto error; | ||
423 | 328 | ||
424 | err = usb_submit_urb(data->evt_urb, GFP_ATOMIC); | 329 | return 0; |
425 | if (err < 0) { | ||
426 | BT_ERR("%s submit failed for event urb %p with error %d", | ||
427 | data->hdev->name, data->evt_urb, err); | ||
428 | } else { | ||
429 | err = usb_submit_urb(data->rx_urb, GFP_ATOMIC); | ||
430 | if (err < 0) { | ||
431 | BT_ERR("%s submit failed for rx urb %p with error %d", | ||
432 | data->hdev->name, data->evt_urb, err); | ||
433 | usb_kill_urb(data->evt_urb); | ||
434 | } | ||
435 | } | ||
436 | 330 | ||
437 | write_unlock_irqrestore(&data->lock, flags); | 331 | error: |
332 | usb_kill_anchored_urbs(&data->rx_anchor); | ||
438 | 333 | ||
439 | done: | 334 | clear_bit(HCI_RUNNING, &hdev->flags); |
440 | if (err < 0) | ||
441 | clear_bit(HCI_RUNNING, &hdev->flags); | ||
442 | 335 | ||
443 | return err; | 336 | return err; |
444 | } | 337 | } |
@@ -446,27 +339,13 @@ done: | |||
446 | static int bpa10x_close(struct hci_dev *hdev) | 339 | static int bpa10x_close(struct hci_dev *hdev) |
447 | { | 340 | { |
448 | struct bpa10x_data *data = hdev->driver_data; | 341 | struct bpa10x_data *data = hdev->driver_data; |
449 | unsigned long flags; | ||
450 | 342 | ||
451 | BT_DBG("hdev %p data %p", hdev, data); | 343 | BT_DBG("%s", hdev->name); |
452 | 344 | ||
453 | if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) | 345 | if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) |
454 | return 0; | 346 | return 0; |
455 | 347 | ||
456 | write_lock_irqsave(&data->lock, flags); | 348 | usb_kill_anchored_urbs(&data->rx_anchor); |
457 | |||
458 | skb_queue_purge(&data->cmd_queue); | ||
459 | usb_kill_urb(data->cmd_urb); | ||
460 | usb_kill_urb(data->evt_urb); | ||
461 | usb_kill_urb(data->rx_urb); | ||
462 | usb_kill_urb(data->tx_urb); | ||
463 | |||
464 | write_unlock_irqrestore(&data->lock, flags); | ||
465 | |||
466 | bpa10x_free_urb(data->cmd_urb); | ||
467 | bpa10x_free_urb(data->evt_urb); | ||
468 | bpa10x_free_urb(data->rx_urb); | ||
469 | bpa10x_free_urb(data->tx_urb); | ||
470 | 349 | ||
471 | return 0; | 350 | return 0; |
472 | } | 351 | } |
@@ -475,9 +354,9 @@ static int bpa10x_flush(struct hci_dev *hdev) | |||
475 | { | 354 | { |
476 | struct bpa10x_data *data = hdev->driver_data; | 355 | struct bpa10x_data *data = hdev->driver_data; |
477 | 356 | ||
478 | BT_DBG("hdev %p data %p", hdev, data); | 357 | BT_DBG("%s", hdev->name); |
479 | 358 | ||
480 | skb_queue_purge(&data->cmd_queue); | 359 | usb_kill_anchored_urbs(&data->tx_anchor); |
481 | 360 | ||
482 | return 0; | 361 | return 0; |
483 | } | 362 | } |
@@ -485,45 +364,78 @@ static int bpa10x_flush(struct hci_dev *hdev) | |||
485 | static int bpa10x_send_frame(struct sk_buff *skb) | 364 | static int bpa10x_send_frame(struct sk_buff *skb) |
486 | { | 365 | { |
487 | struct hci_dev *hdev = (struct hci_dev *) skb->dev; | 366 | struct hci_dev *hdev = (struct hci_dev *) skb->dev; |
488 | struct bpa10x_data *data; | 367 | struct bpa10x_data *data = hdev->driver_data; |
489 | 368 | struct usb_ctrlrequest *dr; | |
490 | BT_DBG("hdev %p skb %p type %d len %d", hdev, skb, bt_cb(skb)->pkt_type, skb->len); | 369 | struct urb *urb; |
370 | unsigned int pipe; | ||
371 | int err; | ||
491 | 372 | ||
492 | if (!hdev) { | 373 | BT_DBG("%s", hdev->name); |
493 | BT_ERR("Frame for unknown HCI device"); | ||
494 | return -ENODEV; | ||
495 | } | ||
496 | 374 | ||
497 | if (!test_bit(HCI_RUNNING, &hdev->flags)) | 375 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
498 | return -EBUSY; | 376 | return -EBUSY; |
499 | 377 | ||
500 | data = hdev->driver_data; | 378 | urb = usb_alloc_urb(0, GFP_ATOMIC); |
379 | if (!urb) | ||
380 | return -ENOMEM; | ||
501 | 381 | ||
502 | /* Prepend skb with frame type */ | 382 | /* Prepend skb with frame type */ |
503 | memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); | 383 | *skb_push(skb, 1) = bt_cb(skb)->pkt_type; |
504 | 384 | ||
505 | switch (bt_cb(skb)->pkt_type) { | 385 | switch (bt_cb(skb)->pkt_type) { |
506 | case HCI_COMMAND_PKT: | 386 | case HCI_COMMAND_PKT: |
387 | dr = kmalloc(sizeof(*dr), GFP_ATOMIC); | ||
388 | if (!dr) { | ||
389 | usb_free_urb(urb); | ||
390 | return -ENOMEM; | ||
391 | } | ||
392 | |||
393 | dr->bRequestType = USB_TYPE_VENDOR; | ||
394 | dr->bRequest = 0; | ||
395 | dr->wIndex = 0; | ||
396 | dr->wValue = 0; | ||
397 | dr->wLength = __cpu_to_le16(skb->len); | ||
398 | |||
399 | pipe = usb_sndctrlpipe(data->udev, 0x00); | ||
400 | |||
401 | usb_fill_control_urb(urb, data->udev, pipe, (void *) dr, | ||
402 | skb->data, skb->len, bpa10x_tx_complete, skb); | ||
403 | |||
507 | hdev->stat.cmd_tx++; | 404 | hdev->stat.cmd_tx++; |
508 | skb_queue_tail(&data->cmd_queue, skb); | ||
509 | break; | 405 | break; |
510 | 406 | ||
511 | case HCI_ACLDATA_PKT: | 407 | case HCI_ACLDATA_PKT: |
408 | pipe = usb_sndbulkpipe(data->udev, 0x02); | ||
409 | |||
410 | usb_fill_bulk_urb(urb, data->udev, pipe, | ||
411 | skb->data, skb->len, bpa10x_tx_complete, skb); | ||
412 | |||
512 | hdev->stat.acl_tx++; | 413 | hdev->stat.acl_tx++; |
513 | skb_queue_tail(&data->tx_queue, skb); | ||
514 | break; | 414 | break; |
515 | 415 | ||
516 | case HCI_SCODATA_PKT: | 416 | case HCI_SCODATA_PKT: |
417 | pipe = usb_sndbulkpipe(data->udev, 0x02); | ||
418 | |||
419 | usb_fill_bulk_urb(urb, data->udev, pipe, | ||
420 | skb->data, skb->len, bpa10x_tx_complete, skb); | ||
421 | |||
517 | hdev->stat.sco_tx++; | 422 | hdev->stat.sco_tx++; |
518 | skb_queue_tail(&data->tx_queue, skb); | ||
519 | break; | 423 | break; |
520 | }; | ||
521 | 424 | ||
522 | read_lock(&data->lock); | 425 | default: |
426 | return -EILSEQ; | ||
427 | } | ||
428 | |||
429 | usb_anchor_urb(urb, &data->tx_anchor); | ||
523 | 430 | ||
524 | bpa10x_wakeup(data); | 431 | err = usb_submit_urb(urb, GFP_ATOMIC); |
432 | if (err < 0) { | ||
433 | BT_ERR("%s urb %p submission failed", hdev->name, urb); | ||
434 | kfree(urb->setup_packet); | ||
435 | usb_unanchor_urb(urb); | ||
436 | } | ||
525 | 437 | ||
526 | read_unlock(&data->lock); | 438 | usb_free_urb(urb); |
527 | 439 | ||
528 | return 0; | 440 | return 0; |
529 | } | 441 | } |
@@ -532,16 +444,17 @@ static void bpa10x_destruct(struct hci_dev *hdev) | |||
532 | { | 444 | { |
533 | struct bpa10x_data *data = hdev->driver_data; | 445 | struct bpa10x_data *data = hdev->driver_data; |
534 | 446 | ||
535 | BT_DBG("hdev %p data %p", hdev, data); | 447 | BT_DBG("%s", hdev->name); |
536 | 448 | ||
449 | kfree(data->rx_skb[0]); | ||
450 | kfree(data->rx_skb[1]); | ||
537 | kfree(data); | 451 | kfree(data); |
538 | } | 452 | } |
539 | 453 | ||
540 | static int bpa10x_probe(struct usb_interface *intf, const struct usb_device_id *id) | 454 | static int bpa10x_probe(struct usb_interface *intf, const struct usb_device_id *id) |
541 | { | 455 | { |
542 | struct usb_device *udev = interface_to_usbdev(intf); | ||
543 | struct hci_dev *hdev; | ||
544 | struct bpa10x_data *data; | 456 | struct bpa10x_data *data; |
457 | struct hci_dev *hdev; | ||
545 | int err; | 458 | int err; |
546 | 459 | ||
547 | BT_DBG("intf %p id %p", intf, id); | 460 | BT_DBG("intf %p id %p", intf, id); |
@@ -549,48 +462,43 @@ static int bpa10x_probe(struct usb_interface *intf, const struct usb_device_id * | |||
549 | if (ignore) | 462 | if (ignore) |
550 | return -ENODEV; | 463 | return -ENODEV; |
551 | 464 | ||
552 | if (intf->cur_altsetting->desc.bInterfaceNumber > 0) | 465 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) |
553 | return -ENODEV; | 466 | return -ENODEV; |
554 | 467 | ||
555 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 468 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
556 | if (!data) { | 469 | if (!data) |
557 | BT_ERR("Can't allocate data structure"); | ||
558 | return -ENOMEM; | 470 | return -ENOMEM; |
559 | } | ||
560 | |||
561 | data->udev = udev; | ||
562 | 471 | ||
563 | rwlock_init(&data->lock); | 472 | data->udev = interface_to_usbdev(intf); |
564 | 473 | ||
565 | skb_queue_head_init(&data->cmd_queue); | 474 | init_usb_anchor(&data->tx_anchor); |
566 | skb_queue_head_init(&data->tx_queue); | 475 | init_usb_anchor(&data->rx_anchor); |
567 | 476 | ||
568 | hdev = hci_alloc_dev(); | 477 | hdev = hci_alloc_dev(); |
569 | if (!hdev) { | 478 | if (!hdev) { |
570 | BT_ERR("Can't allocate HCI device"); | ||
571 | kfree(data); | 479 | kfree(data); |
572 | return -ENOMEM; | 480 | return -ENOMEM; |
573 | } | 481 | } |
574 | 482 | ||
575 | data->hdev = hdev; | ||
576 | |||
577 | hdev->type = HCI_USB; | 483 | hdev->type = HCI_USB; |
578 | hdev->driver_data = data; | 484 | hdev->driver_data = data; |
485 | |||
486 | data->hdev = hdev; | ||
487 | |||
579 | SET_HCIDEV_DEV(hdev, &intf->dev); | 488 | SET_HCIDEV_DEV(hdev, &intf->dev); |
580 | 489 | ||
581 | hdev->open = bpa10x_open; | 490 | hdev->open = bpa10x_open; |
582 | hdev->close = bpa10x_close; | 491 | hdev->close = bpa10x_close; |
583 | hdev->flush = bpa10x_flush; | 492 | hdev->flush = bpa10x_flush; |
584 | hdev->send = bpa10x_send_frame; | 493 | hdev->send = bpa10x_send_frame; |
585 | hdev->destruct = bpa10x_destruct; | 494 | hdev->destruct = bpa10x_destruct; |
586 | 495 | ||
587 | hdev->owner = THIS_MODULE; | 496 | hdev->owner = THIS_MODULE; |
588 | 497 | ||
589 | err = hci_register_dev(hdev); | 498 | err = hci_register_dev(hdev); |
590 | if (err < 0) { | 499 | if (err < 0) { |
591 | BT_ERR("Can't register HCI device"); | ||
592 | kfree(data); | ||
593 | hci_free_dev(hdev); | 500 | hci_free_dev(hdev); |
501 | kfree(data); | ||
594 | return err; | 502 | return err; |
595 | } | 503 | } |
596 | 504 | ||
@@ -602,19 +510,17 @@ static int bpa10x_probe(struct usb_interface *intf, const struct usb_device_id * | |||
602 | static void bpa10x_disconnect(struct usb_interface *intf) | 510 | static void bpa10x_disconnect(struct usb_interface *intf) |
603 | { | 511 | { |
604 | struct bpa10x_data *data = usb_get_intfdata(intf); | 512 | struct bpa10x_data *data = usb_get_intfdata(intf); |
605 | struct hci_dev *hdev = data->hdev; | ||
606 | 513 | ||
607 | BT_DBG("intf %p", intf); | 514 | BT_DBG("intf %p", intf); |
608 | 515 | ||
609 | if (!hdev) | 516 | if (!data) |
610 | return; | 517 | return; |
611 | 518 | ||
612 | usb_set_intfdata(intf, NULL); | 519 | usb_set_intfdata(intf, NULL); |
613 | 520 | ||
614 | if (hci_unregister_dev(hdev) < 0) | 521 | hci_unregister_dev(data->hdev); |
615 | BT_ERR("Can't unregister HCI device %s", hdev->name); | ||
616 | 522 | ||
617 | hci_free_dev(hdev); | 523 | hci_free_dev(data->hdev); |
618 | } | 524 | } |
619 | 525 | ||
620 | static struct usb_driver bpa10x_driver = { | 526 | static struct usb_driver bpa10x_driver = { |
@@ -626,15 +532,9 @@ static struct usb_driver bpa10x_driver = { | |||
626 | 532 | ||
627 | static int __init bpa10x_init(void) | 533 | static int __init bpa10x_init(void) |
628 | { | 534 | { |
629 | int err; | ||
630 | |||
631 | BT_INFO("Digianswer Bluetooth USB driver ver %s", VERSION); | 535 | BT_INFO("Digianswer Bluetooth USB driver ver %s", VERSION); |
632 | 536 | ||
633 | err = usb_register(&bpa10x_driver); | 537 | return usb_register(&bpa10x_driver); |
634 | if (err < 0) | ||
635 | BT_ERR("Failed to register USB driver"); | ||
636 | |||
637 | return err; | ||
638 | } | 538 | } |
639 | 539 | ||
640 | static void __exit bpa10x_exit(void) | 540 | static void __exit bpa10x_exit(void) |
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c index 39516074636b..a18f9b8c9e12 100644 --- a/drivers/bluetooth/bt3c_cs.c +++ b/drivers/bluetooth/bt3c_cs.c | |||
@@ -344,10 +344,7 @@ static irqreturn_t bt3c_interrupt(int irq, void *dev_inst) | |||
344 | unsigned int iobase; | 344 | unsigned int iobase; |
345 | int iir; | 345 | int iir; |
346 | 346 | ||
347 | if (!info || !info->hdev) { | 347 | BUG_ON(!info->hdev); |
348 | BT_ERR("Call of irq %d for unknown device", irq); | ||
349 | return IRQ_NONE; | ||
350 | } | ||
351 | 348 | ||
352 | iobase = info->p_dev->io.BasePort1; | 349 | iobase = info->p_dev->io.BasePort1; |
353 | 350 | ||
diff --git a/drivers/bluetooth/btsdio.c b/drivers/bluetooth/btsdio.c new file mode 100644 index 000000000000..b786f6187902 --- /dev/null +++ b/drivers/bluetooth/btsdio.c | |||
@@ -0,0 +1,406 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Generic Bluetooth SDIO driver | ||
4 | * | ||
5 | * Copyright (C) 2007 Cambridge Silicon Radio Ltd. | ||
6 | * Copyright (C) 2007 Marcel Holtmann <marcel@holtmann.org> | ||
7 | * | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/sched.h> | ||
31 | #include <linux/errno.h> | ||
32 | #include <linux/skbuff.h> | ||
33 | |||
34 | #include <linux/mmc/sdio_ids.h> | ||
35 | #include <linux/mmc/sdio_func.h> | ||
36 | |||
37 | #include <net/bluetooth/bluetooth.h> | ||
38 | #include <net/bluetooth/hci_core.h> | ||
39 | |||
40 | #ifndef CONFIG_BT_HCIBTSDIO_DEBUG | ||
41 | #undef BT_DBG | ||
42 | #define BT_DBG(D...) | ||
43 | #endif | ||
44 | |||
45 | #define VERSION "0.1" | ||
46 | |||
47 | static const struct sdio_device_id btsdio_table[] = { | ||
48 | /* Generic Bluetooth Type-A SDIO device */ | ||
49 | { SDIO_DEVICE_CLASS(SDIO_CLASS_BT_A) }, | ||
50 | |||
51 | /* Generic Bluetooth Type-B SDIO device */ | ||
52 | { SDIO_DEVICE_CLASS(SDIO_CLASS_BT_B) }, | ||
53 | |||
54 | { } /* Terminating entry */ | ||
55 | }; | ||
56 | |||
57 | MODULE_DEVICE_TABLE(sdio, btsdio_table); | ||
58 | |||
59 | struct btsdio_data { | ||
60 | struct hci_dev *hdev; | ||
61 | struct sdio_func *func; | ||
62 | |||
63 | struct work_struct work; | ||
64 | |||
65 | struct sk_buff_head txq; | ||
66 | }; | ||
67 | |||
68 | #define REG_RDAT 0x00 /* Receiver Data */ | ||
69 | #define REG_TDAT 0x00 /* Transmitter Data */ | ||
70 | #define REG_PC_RRT 0x10 /* Read Packet Control */ | ||
71 | #define REG_PC_WRT 0x11 /* Write Packet Control */ | ||
72 | #define REG_RTC_STAT 0x12 /* Retry Control Status */ | ||
73 | #define REG_RTC_SET 0x12 /* Retry Control Set */ | ||
74 | #define REG_INTRD 0x13 /* Interrupt Indication */ | ||
75 | #define REG_CL_INTRD 0x13 /* Interrupt Clear */ | ||
76 | #define REG_EN_INTRD 0x14 /* Interrupt Enable */ | ||
77 | #define REG_MD_STAT 0x20 /* Bluetooth Mode Status */ | ||
78 | |||
79 | static int btsdio_tx_packet(struct btsdio_data *data, struct sk_buff *skb) | ||
80 | { | ||
81 | int err; | ||
82 | |||
83 | BT_DBG("%s", data->hdev->name); | ||
84 | |||
85 | /* Prepend Type-A header */ | ||
86 | skb_push(skb, 4); | ||
87 | skb->data[0] = (skb->len & 0x0000ff); | ||
88 | skb->data[1] = (skb->len & 0x00ff00) >> 8; | ||
89 | skb->data[2] = (skb->len & 0xff0000) >> 16; | ||
90 | skb->data[3] = bt_cb(skb)->pkt_type; | ||
91 | |||
92 | err = sdio_writesb(data->func, REG_TDAT, skb->data, skb->len); | ||
93 | if (err < 0) { | ||
94 | sdio_writeb(data->func, 0x01, REG_PC_WRT, NULL); | ||
95 | return err; | ||
96 | } | ||
97 | |||
98 | data->hdev->stat.byte_tx += skb->len; | ||
99 | |||
100 | kfree_skb(skb); | ||
101 | |||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static void btsdio_work(struct work_struct *work) | ||
106 | { | ||
107 | struct btsdio_data *data = container_of(work, struct btsdio_data, work); | ||
108 | struct sk_buff *skb; | ||
109 | int err; | ||
110 | |||
111 | BT_DBG("%s", data->hdev->name); | ||
112 | |||
113 | sdio_claim_host(data->func); | ||
114 | |||
115 | while ((skb = skb_dequeue(&data->txq))) { | ||
116 | err = btsdio_tx_packet(data, skb); | ||
117 | if (err < 0) { | ||
118 | data->hdev->stat.err_tx++; | ||
119 | skb_queue_head(&data->txq, skb); | ||
120 | break; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | sdio_release_host(data->func); | ||
125 | } | ||
126 | |||
127 | static int btsdio_rx_packet(struct btsdio_data *data) | ||
128 | { | ||
129 | u8 hdr[4] __attribute__ ((aligned(4))); | ||
130 | struct sk_buff *skb; | ||
131 | int err, len; | ||
132 | |||
133 | BT_DBG("%s", data->hdev->name); | ||
134 | |||
135 | err = sdio_readsb(data->func, hdr, REG_RDAT, 4); | ||
136 | if (err < 0) | ||
137 | return err; | ||
138 | |||
139 | len = hdr[0] | (hdr[1] << 8) | (hdr[2] << 16); | ||
140 | if (len < 4 || len > 65543) | ||
141 | return -EILSEQ; | ||
142 | |||
143 | skb = bt_skb_alloc(len - 4, GFP_KERNEL); | ||
144 | if (!skb) { | ||
145 | /* Out of memory. Prepare a read retry and just | ||
146 | * return with the expectation that the next time | ||
147 | * we're called we'll have more memory. */ | ||
148 | return -ENOMEM; | ||
149 | } | ||
150 | |||
151 | skb_put(skb, len - 4); | ||
152 | |||
153 | err = sdio_readsb(data->func, skb->data, REG_RDAT, len - 4); | ||
154 | if (err < 0) { | ||
155 | kfree(skb); | ||
156 | return err; | ||
157 | } | ||
158 | |||
159 | data->hdev->stat.byte_rx += len; | ||
160 | |||
161 | skb->dev = (void *) data->hdev; | ||
162 | bt_cb(skb)->pkt_type = hdr[3]; | ||
163 | |||
164 | err = hci_recv_frame(skb); | ||
165 | if (err < 0) { | ||
166 | kfree(skb); | ||
167 | return err; | ||
168 | } | ||
169 | |||
170 | sdio_writeb(data->func, 0x00, REG_PC_RRT, NULL); | ||
171 | |||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static void btsdio_interrupt(struct sdio_func *func) | ||
176 | { | ||
177 | struct btsdio_data *data = sdio_get_drvdata(func); | ||
178 | int intrd; | ||
179 | |||
180 | BT_DBG("%s", data->hdev->name); | ||
181 | |||
182 | intrd = sdio_readb(func, REG_INTRD, NULL); | ||
183 | if (intrd & 0x01) { | ||
184 | sdio_writeb(func, 0x01, REG_CL_INTRD, NULL); | ||
185 | |||
186 | if (btsdio_rx_packet(data) < 0) { | ||
187 | data->hdev->stat.err_rx++; | ||
188 | sdio_writeb(data->func, 0x01, REG_PC_RRT, NULL); | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | |||
193 | static int btsdio_open(struct hci_dev *hdev) | ||
194 | { | ||
195 | struct btsdio_data *data = hdev->driver_data; | ||
196 | int err; | ||
197 | |||
198 | BT_DBG("%s", hdev->name); | ||
199 | |||
200 | if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) | ||
201 | return 0; | ||
202 | |||
203 | sdio_claim_host(data->func); | ||
204 | |||
205 | err = sdio_enable_func(data->func); | ||
206 | if (err < 0) { | ||
207 | clear_bit(HCI_RUNNING, &hdev->flags); | ||
208 | goto release; | ||
209 | } | ||
210 | |||
211 | err = sdio_claim_irq(data->func, btsdio_interrupt); | ||
212 | if (err < 0) { | ||
213 | sdio_disable_func(data->func); | ||
214 | clear_bit(HCI_RUNNING, &hdev->flags); | ||
215 | goto release; | ||
216 | } | ||
217 | |||
218 | if (data->func->class == SDIO_CLASS_BT_B) | ||
219 | sdio_writeb(data->func, 0x00, REG_MD_STAT, NULL); | ||
220 | |||
221 | sdio_writeb(data->func, 0x01, REG_EN_INTRD, NULL); | ||
222 | |||
223 | release: | ||
224 | sdio_release_host(data->func); | ||
225 | |||
226 | return err; | ||
227 | } | ||
228 | |||
229 | static int btsdio_close(struct hci_dev *hdev) | ||
230 | { | ||
231 | struct btsdio_data *data = hdev->driver_data; | ||
232 | |||
233 | BT_DBG("%s", hdev->name); | ||
234 | |||
235 | if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) | ||
236 | return 0; | ||
237 | |||
238 | sdio_claim_host(data->func); | ||
239 | |||
240 | sdio_writeb(data->func, 0x00, REG_EN_INTRD, NULL); | ||
241 | |||
242 | sdio_release_irq(data->func); | ||
243 | sdio_disable_func(data->func); | ||
244 | |||
245 | sdio_release_host(data->func); | ||
246 | |||
247 | return 0; | ||
248 | } | ||
249 | |||
250 | static int btsdio_flush(struct hci_dev *hdev) | ||
251 | { | ||
252 | struct btsdio_data *data = hdev->driver_data; | ||
253 | |||
254 | BT_DBG("%s", hdev->name); | ||
255 | |||
256 | skb_queue_purge(&data->txq); | ||
257 | |||
258 | return 0; | ||
259 | } | ||
260 | |||
261 | static int btsdio_send_frame(struct sk_buff *skb) | ||
262 | { | ||
263 | struct hci_dev *hdev = (struct hci_dev *) skb->dev; | ||
264 | struct btsdio_data *data = hdev->driver_data; | ||
265 | |||
266 | BT_DBG("%s", hdev->name); | ||
267 | |||
268 | if (!test_bit(HCI_RUNNING, &hdev->flags)) | ||
269 | return -EBUSY; | ||
270 | |||
271 | switch (bt_cb(skb)->pkt_type) { | ||
272 | case HCI_COMMAND_PKT: | ||
273 | hdev->stat.cmd_tx++; | ||
274 | break; | ||
275 | |||
276 | case HCI_ACLDATA_PKT: | ||
277 | hdev->stat.acl_tx++; | ||
278 | break; | ||
279 | |||
280 | case HCI_SCODATA_PKT: | ||
281 | hdev->stat.sco_tx++; | ||
282 | break; | ||
283 | |||
284 | default: | ||
285 | return -EILSEQ; | ||
286 | } | ||
287 | |||
288 | skb_queue_tail(&data->txq, skb); | ||
289 | |||
290 | schedule_work(&data->work); | ||
291 | |||
292 | return 0; | ||
293 | } | ||
294 | |||
295 | static void btsdio_destruct(struct hci_dev *hdev) | ||
296 | { | ||
297 | struct btsdio_data *data = hdev->driver_data; | ||
298 | |||
299 | BT_DBG("%s", hdev->name); | ||
300 | |||
301 | kfree(data); | ||
302 | } | ||
303 | |||
304 | static int btsdio_probe(struct sdio_func *func, | ||
305 | const struct sdio_device_id *id) | ||
306 | { | ||
307 | struct btsdio_data *data; | ||
308 | struct hci_dev *hdev; | ||
309 | struct sdio_func_tuple *tuple = func->tuples; | ||
310 | int err; | ||
311 | |||
312 | BT_DBG("func %p id %p class 0x%04x", func, id, func->class); | ||
313 | |||
314 | while (tuple) { | ||
315 | BT_DBG("code 0x%x size %d", tuple->code, tuple->size); | ||
316 | tuple = tuple->next; | ||
317 | } | ||
318 | |||
319 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
320 | if (!data) | ||
321 | return -ENOMEM; | ||
322 | |||
323 | data->func = func; | ||
324 | |||
325 | INIT_WORK(&data->work, btsdio_work); | ||
326 | |||
327 | skb_queue_head_init(&data->txq); | ||
328 | |||
329 | hdev = hci_alloc_dev(); | ||
330 | if (!hdev) { | ||
331 | kfree(data); | ||
332 | return -ENOMEM; | ||
333 | } | ||
334 | |||
335 | hdev->type = HCI_SDIO; | ||
336 | hdev->driver_data = data; | ||
337 | |||
338 | data->hdev = hdev; | ||
339 | |||
340 | SET_HCIDEV_DEV(hdev, &func->dev); | ||
341 | |||
342 | hdev->open = btsdio_open; | ||
343 | hdev->close = btsdio_close; | ||
344 | hdev->flush = btsdio_flush; | ||
345 | hdev->send = btsdio_send_frame; | ||
346 | hdev->destruct = btsdio_destruct; | ||
347 | |||
348 | hdev->owner = THIS_MODULE; | ||
349 | |||
350 | err = hci_register_dev(hdev); | ||
351 | if (err < 0) { | ||
352 | hci_free_dev(hdev); | ||
353 | kfree(data); | ||
354 | return err; | ||
355 | } | ||
356 | |||
357 | sdio_set_drvdata(func, data); | ||
358 | |||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | static void btsdio_remove(struct sdio_func *func) | ||
363 | { | ||
364 | struct btsdio_data *data = sdio_get_drvdata(func); | ||
365 | struct hci_dev *hdev; | ||
366 | |||
367 | BT_DBG("func %p", func); | ||
368 | |||
369 | if (!data) | ||
370 | return; | ||
371 | |||
372 | hdev = data->hdev; | ||
373 | |||
374 | sdio_set_drvdata(func, NULL); | ||
375 | |||
376 | hci_unregister_dev(hdev); | ||
377 | |||
378 | hci_free_dev(hdev); | ||
379 | } | ||
380 | |||
381 | static struct sdio_driver btsdio_driver = { | ||
382 | .name = "btsdio", | ||
383 | .probe = btsdio_probe, | ||
384 | .remove = btsdio_remove, | ||
385 | .id_table = btsdio_table, | ||
386 | }; | ||
387 | |||
388 | static int __init btsdio_init(void) | ||
389 | { | ||
390 | BT_INFO("Generic Bluetooth SDIO driver ver %s", VERSION); | ||
391 | |||
392 | return sdio_register_driver(&btsdio_driver); | ||
393 | } | ||
394 | |||
395 | static void __exit btsdio_exit(void) | ||
396 | { | ||
397 | sdio_unregister_driver(&btsdio_driver); | ||
398 | } | ||
399 | |||
400 | module_init(btsdio_init); | ||
401 | module_exit(btsdio_exit); | ||
402 | |||
403 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); | ||
404 | MODULE_DESCRIPTION("Generic Bluetooth SDIO driver ver " VERSION); | ||
405 | MODULE_VERSION(VERSION); | ||
406 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c index d7d2ea0d86a1..08f48d577aba 100644 --- a/drivers/bluetooth/btuart_cs.c +++ b/drivers/bluetooth/btuart_cs.c | |||
@@ -294,10 +294,7 @@ static irqreturn_t btuart_interrupt(int irq, void *dev_inst) | |||
294 | int boguscount = 0; | 294 | int boguscount = 0; |
295 | int iir, lsr; | 295 | int iir, lsr; |
296 | 296 | ||
297 | if (!info || !info->hdev) { | 297 | BUG_ON(!info->hdev); |
298 | BT_ERR("Call of irq %d for unknown device", irq); | ||
299 | return IRQ_NONE; | ||
300 | } | ||
301 | 298 | ||
302 | iobase = info->p_dev->io.BasePort1; | 299 | iobase = info->p_dev->io.BasePort1; |
303 | 300 | ||
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c new file mode 100644 index 000000000000..12e108914f19 --- /dev/null +++ b/drivers/bluetooth/btusb.c | |||
@@ -0,0 +1,564 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Generic Bluetooth USB driver | ||
4 | * | ||
5 | * Copyright (C) 2005-2007 Marcel Holtmann <marcel@holtmann.org> | ||
6 | * | ||
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 as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <linux/types.h> | ||
29 | #include <linux/sched.h> | ||
30 | #include <linux/errno.h> | ||
31 | #include <linux/skbuff.h> | ||
32 | |||
33 | #include <linux/usb.h> | ||
34 | |||
35 | #include <net/bluetooth/bluetooth.h> | ||
36 | #include <net/bluetooth/hci_core.h> | ||
37 | |||
38 | //#define CONFIG_BT_HCIBTUSB_DEBUG | ||
39 | #ifndef CONFIG_BT_HCIBTUSB_DEBUG | ||
40 | #undef BT_DBG | ||
41 | #define BT_DBG(D...) | ||
42 | #endif | ||
43 | |||
44 | #define VERSION "0.1" | ||
45 | |||
46 | static struct usb_device_id btusb_table[] = { | ||
47 | /* Generic Bluetooth USB device */ | ||
48 | { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, | ||
49 | |||
50 | { } /* Terminating entry */ | ||
51 | }; | ||
52 | |||
53 | MODULE_DEVICE_TABLE(usb, btusb_table); | ||
54 | |||
55 | static struct usb_device_id blacklist_table[] = { | ||
56 | { } /* Terminating entry */ | ||
57 | }; | ||
58 | |||
59 | #define BTUSB_INTR_RUNNING 0 | ||
60 | #define BTUSB_BULK_RUNNING 1 | ||
61 | |||
62 | struct btusb_data { | ||
63 | struct hci_dev *hdev; | ||
64 | struct usb_device *udev; | ||
65 | |||
66 | spinlock_t lock; | ||
67 | |||
68 | unsigned long flags; | ||
69 | |||
70 | struct work_struct work; | ||
71 | |||
72 | struct usb_anchor tx_anchor; | ||
73 | struct usb_anchor intr_anchor; | ||
74 | struct usb_anchor bulk_anchor; | ||
75 | |||
76 | struct usb_endpoint_descriptor *intr_ep; | ||
77 | struct usb_endpoint_descriptor *bulk_tx_ep; | ||
78 | struct usb_endpoint_descriptor *bulk_rx_ep; | ||
79 | }; | ||
80 | |||
81 | static void btusb_intr_complete(struct urb *urb) | ||
82 | { | ||
83 | struct hci_dev *hdev = urb->context; | ||
84 | struct btusb_data *data = hdev->driver_data; | ||
85 | int err; | ||
86 | |||
87 | BT_DBG("%s urb %p status %d count %d", hdev->name, | ||
88 | urb, urb->status, urb->actual_length); | ||
89 | |||
90 | if (!test_bit(HCI_RUNNING, &hdev->flags)) | ||
91 | return; | ||
92 | |||
93 | if (urb->status == 0) { | ||
94 | if (hci_recv_fragment(hdev, HCI_EVENT_PKT, | ||
95 | urb->transfer_buffer, | ||
96 | urb->actual_length) < 0) { | ||
97 | BT_ERR("%s corrupted event packet", hdev->name); | ||
98 | hdev->stat.err_rx++; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | if (!test_bit(BTUSB_INTR_RUNNING, &data->flags)) | ||
103 | return; | ||
104 | |||
105 | usb_anchor_urb(urb, &data->intr_anchor); | ||
106 | |||
107 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
108 | if (err < 0) { | ||
109 | BT_ERR("%s urb %p failed to resubmit (%d)", | ||
110 | hdev->name, urb, -err); | ||
111 | usb_unanchor_urb(urb); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | static inline int btusb_submit_intr_urb(struct hci_dev *hdev) | ||
116 | { | ||
117 | struct btusb_data *data = hdev->driver_data; | ||
118 | struct urb *urb; | ||
119 | unsigned char *buf; | ||
120 | unsigned int pipe; | ||
121 | int err, size; | ||
122 | |||
123 | BT_DBG("%s", hdev->name); | ||
124 | |||
125 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
126 | if (!urb) | ||
127 | return -ENOMEM; | ||
128 | |||
129 | size = le16_to_cpu(data->intr_ep->wMaxPacketSize); | ||
130 | |||
131 | buf = kmalloc(size, GFP_ATOMIC); | ||
132 | if (!buf) { | ||
133 | usb_free_urb(urb); | ||
134 | return -ENOMEM; | ||
135 | } | ||
136 | |||
137 | pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress); | ||
138 | |||
139 | usb_fill_int_urb(urb, data->udev, pipe, buf, size, | ||
140 | btusb_intr_complete, hdev, | ||
141 | data->intr_ep->bInterval); | ||
142 | |||
143 | urb->transfer_flags |= URB_FREE_BUFFER; | ||
144 | |||
145 | usb_anchor_urb(urb, &data->intr_anchor); | ||
146 | |||
147 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
148 | if (err < 0) { | ||
149 | BT_ERR("%s urb %p submission failed (%d)", | ||
150 | hdev->name, urb, -err); | ||
151 | usb_unanchor_urb(urb); | ||
152 | kfree(buf); | ||
153 | } | ||
154 | |||
155 | usb_free_urb(urb); | ||
156 | |||
157 | return err; | ||
158 | } | ||
159 | |||
160 | static void btusb_bulk_complete(struct urb *urb) | ||
161 | { | ||
162 | struct hci_dev *hdev = urb->context; | ||
163 | struct btusb_data *data = hdev->driver_data; | ||
164 | int err; | ||
165 | |||
166 | BT_DBG("%s urb %p status %d count %d", hdev->name, | ||
167 | urb, urb->status, urb->actual_length); | ||
168 | |||
169 | if (!test_bit(HCI_RUNNING, &hdev->flags)) | ||
170 | return; | ||
171 | |||
172 | if (urb->status == 0) { | ||
173 | if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT, | ||
174 | urb->transfer_buffer, | ||
175 | urb->actual_length) < 0) { | ||
176 | BT_ERR("%s corrupted ACL packet", hdev->name); | ||
177 | hdev->stat.err_rx++; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | if (!test_bit(BTUSB_BULK_RUNNING, &data->flags)) | ||
182 | return; | ||
183 | |||
184 | usb_anchor_urb(urb, &data->bulk_anchor); | ||
185 | |||
186 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
187 | if (err < 0) { | ||
188 | BT_ERR("%s urb %p failed to resubmit (%d)", | ||
189 | hdev->name, urb, -err); | ||
190 | usb_unanchor_urb(urb); | ||
191 | } | ||
192 | } | ||
193 | |||
194 | static inline int btusb_submit_bulk_urb(struct hci_dev *hdev) | ||
195 | { | ||
196 | struct btusb_data *data = hdev->driver_data; | ||
197 | struct urb *urb; | ||
198 | unsigned char *buf; | ||
199 | unsigned int pipe; | ||
200 | int err, size; | ||
201 | |||
202 | BT_DBG("%s", hdev->name); | ||
203 | |||
204 | urb = usb_alloc_urb(0, GFP_KERNEL); | ||
205 | if (!urb) | ||
206 | return -ENOMEM; | ||
207 | |||
208 | size = le16_to_cpu(data->bulk_rx_ep->wMaxPacketSize); | ||
209 | |||
210 | buf = kmalloc(size, GFP_KERNEL); | ||
211 | if (!buf) { | ||
212 | usb_free_urb(urb); | ||
213 | return -ENOMEM; | ||
214 | } | ||
215 | |||
216 | pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress); | ||
217 | |||
218 | usb_fill_bulk_urb(urb, data->udev, pipe, | ||
219 | buf, size, btusb_bulk_complete, hdev); | ||
220 | |||
221 | urb->transfer_flags |= URB_FREE_BUFFER; | ||
222 | |||
223 | usb_anchor_urb(urb, &data->bulk_anchor); | ||
224 | |||
225 | err = usb_submit_urb(urb, GFP_KERNEL); | ||
226 | if (err < 0) { | ||
227 | BT_ERR("%s urb %p submission failed (%d)", | ||
228 | hdev->name, urb, -err); | ||
229 | usb_unanchor_urb(urb); | ||
230 | kfree(buf); | ||
231 | } | ||
232 | |||
233 | usb_free_urb(urb); | ||
234 | |||
235 | return err; | ||
236 | } | ||
237 | |||
238 | static void btusb_tx_complete(struct urb *urb) | ||
239 | { | ||
240 | struct sk_buff *skb = urb->context; | ||
241 | struct hci_dev *hdev = (struct hci_dev *) skb->dev; | ||
242 | |||
243 | BT_DBG("%s urb %p status %d count %d", hdev->name, | ||
244 | urb, urb->status, urb->actual_length); | ||
245 | |||
246 | if (!test_bit(HCI_RUNNING, &hdev->flags)) | ||
247 | goto done; | ||
248 | |||
249 | if (!urb->status) | ||
250 | hdev->stat.byte_tx += urb->transfer_buffer_length; | ||
251 | else | ||
252 | hdev->stat.err_tx++; | ||
253 | |||
254 | done: | ||
255 | kfree(urb->setup_packet); | ||
256 | |||
257 | kfree_skb(skb); | ||
258 | } | ||
259 | |||
260 | static int btusb_open(struct hci_dev *hdev) | ||
261 | { | ||
262 | struct btusb_data *data = hdev->driver_data; | ||
263 | int err; | ||
264 | |||
265 | BT_DBG("%s", hdev->name); | ||
266 | |||
267 | if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) | ||
268 | return 0; | ||
269 | |||
270 | if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) | ||
271 | return 0; | ||
272 | |||
273 | err = btusb_submit_intr_urb(hdev); | ||
274 | if (err < 0) { | ||
275 | clear_bit(BTUSB_INTR_RUNNING, &hdev->flags); | ||
276 | clear_bit(HCI_RUNNING, &hdev->flags); | ||
277 | } | ||
278 | |||
279 | return err; | ||
280 | } | ||
281 | |||
282 | static int btusb_close(struct hci_dev *hdev) | ||
283 | { | ||
284 | struct btusb_data *data = hdev->driver_data; | ||
285 | |||
286 | BT_DBG("%s", hdev->name); | ||
287 | |||
288 | if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) | ||
289 | return 0; | ||
290 | |||
291 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); | ||
292 | usb_kill_anchored_urbs(&data->bulk_anchor); | ||
293 | |||
294 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); | ||
295 | usb_kill_anchored_urbs(&data->intr_anchor); | ||
296 | |||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | static int btusb_flush(struct hci_dev *hdev) | ||
301 | { | ||
302 | struct btusb_data *data = hdev->driver_data; | ||
303 | |||
304 | BT_DBG("%s", hdev->name); | ||
305 | |||
306 | usb_kill_anchored_urbs(&data->tx_anchor); | ||
307 | |||
308 | return 0; | ||
309 | } | ||
310 | |||
311 | static int btusb_send_frame(struct sk_buff *skb) | ||
312 | { | ||
313 | struct hci_dev *hdev = (struct hci_dev *) skb->dev; | ||
314 | struct btusb_data *data = hdev->driver_data; | ||
315 | struct usb_ctrlrequest *dr; | ||
316 | struct urb *urb; | ||
317 | unsigned int pipe; | ||
318 | int err; | ||
319 | |||
320 | BT_DBG("%s", hdev->name); | ||
321 | |||
322 | if (!test_bit(HCI_RUNNING, &hdev->flags)) | ||
323 | return -EBUSY; | ||
324 | |||
325 | switch (bt_cb(skb)->pkt_type) { | ||
326 | case HCI_COMMAND_PKT: | ||
327 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
328 | if (!urb) | ||
329 | return -ENOMEM; | ||
330 | |||
331 | dr = kmalloc(sizeof(*dr), GFP_ATOMIC); | ||
332 | if (!dr) { | ||
333 | usb_free_urb(urb); | ||
334 | return -ENOMEM; | ||
335 | } | ||
336 | |||
337 | dr->bRequestType = USB_TYPE_CLASS; | ||
338 | dr->bRequest = 0; | ||
339 | dr->wIndex = 0; | ||
340 | dr->wValue = 0; | ||
341 | dr->wLength = __cpu_to_le16(skb->len); | ||
342 | |||
343 | pipe = usb_sndctrlpipe(data->udev, 0x00); | ||
344 | |||
345 | usb_fill_control_urb(urb, data->udev, pipe, (void *) dr, | ||
346 | skb->data, skb->len, btusb_tx_complete, skb); | ||
347 | |||
348 | hdev->stat.cmd_tx++; | ||
349 | break; | ||
350 | |||
351 | case HCI_ACLDATA_PKT: | ||
352 | urb = usb_alloc_urb(0, GFP_ATOMIC); | ||
353 | if (!urb) | ||
354 | return -ENOMEM; | ||
355 | |||
356 | pipe = usb_sndbulkpipe(data->udev, | ||
357 | data->bulk_tx_ep->bEndpointAddress); | ||
358 | |||
359 | usb_fill_bulk_urb(urb, data->udev, pipe, | ||
360 | skb->data, skb->len, btusb_tx_complete, skb); | ||
361 | |||
362 | hdev->stat.acl_tx++; | ||
363 | break; | ||
364 | |||
365 | case HCI_SCODATA_PKT: | ||
366 | hdev->stat.sco_tx++; | ||
367 | kfree_skb(skb); | ||
368 | return 0; | ||
369 | |||
370 | default: | ||
371 | return -EILSEQ; | ||
372 | } | ||
373 | |||
374 | usb_anchor_urb(urb, &data->tx_anchor); | ||
375 | |||
376 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
377 | if (err < 0) { | ||
378 | BT_ERR("%s urb %p submission failed", hdev->name, urb); | ||
379 | kfree(urb->setup_packet); | ||
380 | usb_unanchor_urb(urb); | ||
381 | } | ||
382 | |||
383 | usb_free_urb(urb); | ||
384 | |||
385 | return err; | ||
386 | } | ||
387 | |||
388 | static void btusb_destruct(struct hci_dev *hdev) | ||
389 | { | ||
390 | struct btusb_data *data = hdev->driver_data; | ||
391 | |||
392 | BT_DBG("%s", hdev->name); | ||
393 | |||
394 | kfree(data); | ||
395 | } | ||
396 | |||
397 | static void btusb_notify(struct hci_dev *hdev, unsigned int evt) | ||
398 | { | ||
399 | struct btusb_data *data = hdev->driver_data; | ||
400 | |||
401 | BT_DBG("%s evt %d", hdev->name, evt); | ||
402 | |||
403 | if (evt == HCI_NOTIFY_CONN_ADD || evt == HCI_NOTIFY_CONN_DEL) | ||
404 | schedule_work(&data->work); | ||
405 | } | ||
406 | |||
407 | static void btusb_work(struct work_struct *work) | ||
408 | { | ||
409 | struct btusb_data *data = container_of(work, struct btusb_data, work); | ||
410 | struct hci_dev *hdev = data->hdev; | ||
411 | |||
412 | if (hdev->conn_hash.acl_num == 0) { | ||
413 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); | ||
414 | usb_kill_anchored_urbs(&data->bulk_anchor); | ||
415 | return; | ||
416 | } | ||
417 | |||
418 | if (!test_and_set_bit(BTUSB_BULK_RUNNING, &data->flags)) { | ||
419 | if (btusb_submit_bulk_urb(hdev) < 0) | ||
420 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); | ||
421 | else | ||
422 | btusb_submit_bulk_urb(hdev); | ||
423 | } | ||
424 | } | ||
425 | |||
426 | static int btusb_probe(struct usb_interface *intf, | ||
427 | const struct usb_device_id *id) | ||
428 | { | ||
429 | struct usb_endpoint_descriptor *ep_desc; | ||
430 | struct btusb_data *data; | ||
431 | struct hci_dev *hdev; | ||
432 | int i, err; | ||
433 | |||
434 | BT_DBG("intf %p id %p", intf, id); | ||
435 | |||
436 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) | ||
437 | return -ENODEV; | ||
438 | |||
439 | if (!id->driver_info) { | ||
440 | const struct usb_device_id *match; | ||
441 | match = usb_match_id(intf, blacklist_table); | ||
442 | if (match) | ||
443 | id = match; | ||
444 | } | ||
445 | |||
446 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
447 | if (!data) | ||
448 | return -ENOMEM; | ||
449 | |||
450 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { | ||
451 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; | ||
452 | |||
453 | if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) { | ||
454 | data->intr_ep = ep_desc; | ||
455 | continue; | ||
456 | } | ||
457 | |||
458 | if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { | ||
459 | data->bulk_tx_ep = ep_desc; | ||
460 | continue; | ||
461 | } | ||
462 | |||
463 | if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { | ||
464 | data->bulk_rx_ep = ep_desc; | ||
465 | continue; | ||
466 | } | ||
467 | } | ||
468 | |||
469 | if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) { | ||
470 | kfree(data); | ||
471 | return -ENODEV; | ||
472 | } | ||
473 | |||
474 | data->udev = interface_to_usbdev(intf); | ||
475 | |||
476 | spin_lock_init(&data->lock); | ||
477 | |||
478 | INIT_WORK(&data->work, btusb_work); | ||
479 | |||
480 | init_usb_anchor(&data->tx_anchor); | ||
481 | init_usb_anchor(&data->intr_anchor); | ||
482 | init_usb_anchor(&data->bulk_anchor); | ||
483 | |||
484 | hdev = hci_alloc_dev(); | ||
485 | if (!hdev) { | ||
486 | kfree(data); | ||
487 | return -ENOMEM; | ||
488 | } | ||
489 | |||
490 | hdev->type = HCI_USB; | ||
491 | hdev->driver_data = data; | ||
492 | |||
493 | data->hdev = hdev; | ||
494 | |||
495 | SET_HCIDEV_DEV(hdev, &intf->dev); | ||
496 | |||
497 | hdev->open = btusb_open; | ||
498 | hdev->close = btusb_close; | ||
499 | hdev->flush = btusb_flush; | ||
500 | hdev->send = btusb_send_frame; | ||
501 | hdev->destruct = btusb_destruct; | ||
502 | hdev->notify = btusb_notify; | ||
503 | |||
504 | hdev->owner = THIS_MODULE; | ||
505 | |||
506 | set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks); | ||
507 | |||
508 | err = hci_register_dev(hdev); | ||
509 | if (err < 0) { | ||
510 | hci_free_dev(hdev); | ||
511 | kfree(data); | ||
512 | return err; | ||
513 | } | ||
514 | |||
515 | usb_set_intfdata(intf, data); | ||
516 | |||
517 | return 0; | ||
518 | } | ||
519 | |||
520 | static void btusb_disconnect(struct usb_interface *intf) | ||
521 | { | ||
522 | struct btusb_data *data = usb_get_intfdata(intf); | ||
523 | struct hci_dev *hdev; | ||
524 | |||
525 | BT_DBG("intf %p", intf); | ||
526 | |||
527 | if (!data) | ||
528 | return; | ||
529 | |||
530 | hdev = data->hdev; | ||
531 | |||
532 | usb_set_intfdata(intf, NULL); | ||
533 | |||
534 | hci_unregister_dev(hdev); | ||
535 | |||
536 | hci_free_dev(hdev); | ||
537 | } | ||
538 | |||
539 | static struct usb_driver btusb_driver = { | ||
540 | .name = "btusb", | ||
541 | .probe = btusb_probe, | ||
542 | .disconnect = btusb_disconnect, | ||
543 | .id_table = btusb_table, | ||
544 | }; | ||
545 | |||
546 | static int __init btusb_init(void) | ||
547 | { | ||
548 | BT_INFO("Generic Bluetooth USB driver ver %s", VERSION); | ||
549 | |||
550 | return usb_register(&btusb_driver); | ||
551 | } | ||
552 | |||
553 | static void __exit btusb_exit(void) | ||
554 | { | ||
555 | usb_deregister(&btusb_driver); | ||
556 | } | ||
557 | |||
558 | module_init(btusb_init); | ||
559 | module_exit(btusb_exit); | ||
560 | |||
561 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); | ||
562 | MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION); | ||
563 | MODULE_VERSION(VERSION); | ||
564 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c index 7f9c54b9964a..dae45cdf02b2 100644 --- a/drivers/bluetooth/dtl1_cs.c +++ b/drivers/bluetooth/dtl1_cs.c | |||
@@ -298,10 +298,7 @@ static irqreturn_t dtl1_interrupt(int irq, void *dev_inst) | |||
298 | int boguscount = 0; | 298 | int boguscount = 0; |
299 | int iir, lsr; | 299 | int iir, lsr; |
300 | 300 | ||
301 | if (!info || !info->hdev) { | 301 | BUG_ON(!info->hdev); |
302 | BT_ERR("Call of irq %d for unknown device", irq); | ||
303 | return IRQ_NONE; | ||
304 | } | ||
305 | 302 | ||
306 | iobase = info->p_dev->io.BasePort1; | 303 | iobase = info->p_dev->io.BasePort1; |
307 | 304 | ||
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c index d66064ccb31c..696f7528f022 100644 --- a/drivers/bluetooth/hci_bcsp.c +++ b/drivers/bluetooth/hci_bcsp.c | |||
@@ -237,7 +237,8 @@ static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data, | |||
237 | if (hciextn && chan == 5) { | 237 | if (hciextn && chan == 5) { |
238 | struct hci_command_hdr *hdr = (struct hci_command_hdr *) data; | 238 | struct hci_command_hdr *hdr = (struct hci_command_hdr *) data; |
239 | 239 | ||
240 | if (hci_opcode_ogf(__le16_to_cpu(hdr->opcode)) == OGF_VENDOR_CMD) { | 240 | /* Vendor specific commands */ |
241 | if (hci_opcode_ogf(__le16_to_cpu(hdr->opcode)) == 0x3f) { | ||
241 | u8 desc = *(data + HCI_COMMAND_HDR_SIZE); | 242 | u8 desc = *(data + HCI_COMMAND_HDR_SIZE); |
242 | if ((desc & 0xf0) == 0xc0) { | 243 | if ((desc & 0xf0) == 0xc0) { |
243 | data += HCI_COMMAND_HDR_SIZE + 1; | 244 | data += HCI_COMMAND_HDR_SIZE + 1; |
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index 6055b9c0ac0f..e68821d074b0 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c | |||
@@ -549,7 +549,10 @@ static int __init hci_uart_init(void) | |||
549 | #ifdef CONFIG_BT_HCIUART_BCSP | 549 | #ifdef CONFIG_BT_HCIUART_BCSP |
550 | bcsp_init(); | 550 | bcsp_init(); |
551 | #endif | 551 | #endif |
552 | 552 | #ifdef CONFIG_BT_HCIUART_LL | |
553 | ll_init(); | ||
554 | #endif | ||
555 | |||
553 | return 0; | 556 | return 0; |
554 | } | 557 | } |
555 | 558 | ||
@@ -563,6 +566,9 @@ static void __exit hci_uart_exit(void) | |||
563 | #ifdef CONFIG_BT_HCIUART_BCSP | 566 | #ifdef CONFIG_BT_HCIUART_BCSP |
564 | bcsp_deinit(); | 567 | bcsp_deinit(); |
565 | #endif | 568 | #endif |
569 | #ifdef CONFIG_BT_HCIUART_LL | ||
570 | ll_deinit(); | ||
571 | #endif | ||
566 | 572 | ||
567 | /* Release tty registration of line discipline */ | 573 | /* Release tty registration of line discipline */ |
568 | if ((err = tty_unregister_ldisc(N_HCI))) | 574 | if ((err = tty_unregister_ldisc(N_HCI))) |
diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c new file mode 100644 index 000000000000..8c3e62a17b4a --- /dev/null +++ b/drivers/bluetooth/hci_ll.c | |||
@@ -0,0 +1,531 @@ | |||
1 | /* | ||
2 | * Texas Instruments' Bluetooth HCILL UART protocol | ||
3 | * | ||
4 | * HCILL (HCI Low Level) is a Texas Instruments' power management | ||
5 | * protocol extension to H4. | ||
6 | * | ||
7 | * Copyright (C) 2007 Texas Instruments, Inc. | ||
8 | * | ||
9 | * Written by Ohad Ben-Cohen <ohad@bencohen.org> | ||
10 | * | ||
11 | * Acknowledgements: | ||
12 | * This file is based on hci_h4.c, which was written | ||
13 | * by Maxim Krasnyansky and Marcel Holtmann. | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or modify | ||
16 | * it under the terms of the GNU General Public License version 2 | ||
17 | * as published by the Free Software Foundation | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #include <linux/module.h> | ||
31 | #include <linux/kernel.h> | ||
32 | |||
33 | #include <linux/init.h> | ||
34 | #include <linux/sched.h> | ||
35 | #include <linux/types.h> | ||
36 | #include <linux/fcntl.h> | ||
37 | #include <linux/interrupt.h> | ||
38 | #include <linux/ptrace.h> | ||
39 | #include <linux/poll.h> | ||
40 | |||
41 | #include <linux/slab.h> | ||
42 | #include <linux/tty.h> | ||
43 | #include <linux/errno.h> | ||
44 | #include <linux/string.h> | ||
45 | #include <linux/signal.h> | ||
46 | #include <linux/ioctl.h> | ||
47 | #include <linux/skbuff.h> | ||
48 | |||
49 | #include <net/bluetooth/bluetooth.h> | ||
50 | #include <net/bluetooth/hci_core.h> | ||
51 | |||
52 | #include "hci_uart.h" | ||
53 | |||
54 | /* HCILL commands */ | ||
55 | #define HCILL_GO_TO_SLEEP_IND 0x30 | ||
56 | #define HCILL_GO_TO_SLEEP_ACK 0x31 | ||
57 | #define HCILL_WAKE_UP_IND 0x32 | ||
58 | #define HCILL_WAKE_UP_ACK 0x33 | ||
59 | |||
60 | /* HCILL receiver States */ | ||
61 | #define HCILL_W4_PACKET_TYPE 0 | ||
62 | #define HCILL_W4_EVENT_HDR 1 | ||
63 | #define HCILL_W4_ACL_HDR 2 | ||
64 | #define HCILL_W4_SCO_HDR 3 | ||
65 | #define HCILL_W4_DATA 4 | ||
66 | |||
67 | /* HCILL states */ | ||
68 | enum hcill_states_e { | ||
69 | HCILL_ASLEEP, | ||
70 | HCILL_ASLEEP_TO_AWAKE, | ||
71 | HCILL_AWAKE, | ||
72 | HCILL_AWAKE_TO_ASLEEP | ||
73 | }; | ||
74 | |||
75 | struct hcill_cmd { | ||
76 | u8 cmd; | ||
77 | } __attribute__((packed)); | ||
78 | |||
79 | struct ll_struct { | ||
80 | unsigned long rx_state; | ||
81 | unsigned long rx_count; | ||
82 | struct sk_buff *rx_skb; | ||
83 | struct sk_buff_head txq; | ||
84 | spinlock_t hcill_lock; /* HCILL state lock */ | ||
85 | unsigned long hcill_state; /* HCILL power state */ | ||
86 | struct sk_buff_head tx_wait_q; /* HCILL wait queue */ | ||
87 | }; | ||
88 | |||
89 | /* | ||
90 | * Builds and sends an HCILL command packet. | ||
91 | * These are very simple packets with only 1 cmd byte | ||
92 | */ | ||
93 | static int send_hcill_cmd(u8 cmd, struct hci_uart *hu) | ||
94 | { | ||
95 | int err = 0; | ||
96 | struct sk_buff *skb = NULL; | ||
97 | struct ll_struct *ll = hu->priv; | ||
98 | struct hcill_cmd *hcill_packet; | ||
99 | |||
100 | BT_DBG("hu %p cmd 0x%x", hu, cmd); | ||
101 | |||
102 | /* allocate packet */ | ||
103 | skb = bt_skb_alloc(1, GFP_ATOMIC); | ||
104 | if (!skb) { | ||
105 | BT_ERR("cannot allocate memory for HCILL packet"); | ||
106 | err = -ENOMEM; | ||
107 | goto out; | ||
108 | } | ||
109 | |||
110 | /* prepare packet */ | ||
111 | hcill_packet = (struct hcill_cmd *) skb_put(skb, 1); | ||
112 | hcill_packet->cmd = cmd; | ||
113 | skb->dev = (void *) hu->hdev; | ||
114 | |||
115 | /* send packet */ | ||
116 | skb_queue_tail(&ll->txq, skb); | ||
117 | out: | ||
118 | return err; | ||
119 | } | ||
120 | |||
121 | /* Initialize protocol */ | ||
122 | static int ll_open(struct hci_uart *hu) | ||
123 | { | ||
124 | struct ll_struct *ll; | ||
125 | |||
126 | BT_DBG("hu %p", hu); | ||
127 | |||
128 | ll = kzalloc(sizeof(*ll), GFP_ATOMIC); | ||
129 | if (!ll) | ||
130 | return -ENOMEM; | ||
131 | |||
132 | skb_queue_head_init(&ll->txq); | ||
133 | skb_queue_head_init(&ll->tx_wait_q); | ||
134 | spin_lock_init(&ll->hcill_lock); | ||
135 | |||
136 | ll->hcill_state = HCILL_AWAKE; | ||
137 | |||
138 | hu->priv = ll; | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | /* Flush protocol data */ | ||
144 | static int ll_flush(struct hci_uart *hu) | ||
145 | { | ||
146 | struct ll_struct *ll = hu->priv; | ||
147 | |||
148 | BT_DBG("hu %p", hu); | ||
149 | |||
150 | skb_queue_purge(&ll->tx_wait_q); | ||
151 | skb_queue_purge(&ll->txq); | ||
152 | |||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | /* Close protocol */ | ||
157 | static int ll_close(struct hci_uart *hu) | ||
158 | { | ||
159 | struct ll_struct *ll = hu->priv; | ||
160 | |||
161 | BT_DBG("hu %p", hu); | ||
162 | |||
163 | skb_queue_purge(&ll->tx_wait_q); | ||
164 | skb_queue_purge(&ll->txq); | ||
165 | |||
166 | if (ll->rx_skb) | ||
167 | kfree_skb(ll->rx_skb); | ||
168 | |||
169 | hu->priv = NULL; | ||
170 | |||
171 | kfree(ll); | ||
172 | |||
173 | return 0; | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * internal function, which does common work of the device wake up process: | ||
178 | * 1. places all pending packets (waiting in tx_wait_q list) in txq list. | ||
179 | * 2. changes internal state to HCILL_AWAKE. | ||
180 | * Note: assumes that hcill_lock spinlock is taken, | ||
181 | * shouldn't be called otherwise! | ||
182 | */ | ||
183 | static void __ll_do_awake(struct ll_struct *ll) | ||
184 | { | ||
185 | struct sk_buff *skb = NULL; | ||
186 | |||
187 | while ((skb = skb_dequeue(&ll->tx_wait_q))) | ||
188 | skb_queue_tail(&ll->txq, skb); | ||
189 | |||
190 | ll->hcill_state = HCILL_AWAKE; | ||
191 | } | ||
192 | |||
193 | /* | ||
194 | * Called upon a wake-up-indication from the device | ||
195 | */ | ||
196 | static void ll_device_want_to_wakeup(struct hci_uart *hu) | ||
197 | { | ||
198 | unsigned long flags; | ||
199 | struct ll_struct *ll = hu->priv; | ||
200 | |||
201 | BT_DBG("hu %p", hu); | ||
202 | |||
203 | /* lock hcill state */ | ||
204 | spin_lock_irqsave(&ll->hcill_lock, flags); | ||
205 | |||
206 | switch (ll->hcill_state) { | ||
207 | case HCILL_ASLEEP: | ||
208 | /* acknowledge device wake up */ | ||
209 | if (send_hcill_cmd(HCILL_WAKE_UP_ACK, hu) < 0) { | ||
210 | BT_ERR("cannot acknowledge device wake up"); | ||
211 | goto out; | ||
212 | } | ||
213 | break; | ||
214 | case HCILL_ASLEEP_TO_AWAKE: | ||
215 | /* | ||
216 | * this state means that a wake-up-indication | ||
217 | * is already on its way to the device, | ||
218 | * and will serve as the required wake-up-ack | ||
219 | */ | ||
220 | BT_DBG("dual wake-up-indication"); | ||
221 | break; | ||
222 | default: | ||
223 | /* any other state are illegal */ | ||
224 | BT_ERR("received HCILL_WAKE_UP_IND in state %ld", ll->hcill_state); | ||
225 | break; | ||
226 | } | ||
227 | |||
228 | /* send pending packets and change state to HCILL_AWAKE */ | ||
229 | __ll_do_awake(ll); | ||
230 | |||
231 | out: | ||
232 | spin_unlock_irqrestore(&ll->hcill_lock, flags); | ||
233 | |||
234 | /* actually send the packets */ | ||
235 | hci_uart_tx_wakeup(hu); | ||
236 | } | ||
237 | |||
238 | /* | ||
239 | * Called upon a sleep-indication from the device | ||
240 | */ | ||
241 | static void ll_device_want_to_sleep(struct hci_uart *hu) | ||
242 | { | ||
243 | unsigned long flags; | ||
244 | struct ll_struct *ll = hu->priv; | ||
245 | |||
246 | BT_DBG("hu %p", hu); | ||
247 | |||
248 | /* lock hcill state */ | ||
249 | spin_lock_irqsave(&ll->hcill_lock, flags); | ||
250 | |||
251 | /* sanity check */ | ||
252 | if (ll->hcill_state != HCILL_AWAKE) | ||
253 | BT_ERR("ERR: HCILL_GO_TO_SLEEP_IND in state %ld", ll->hcill_state); | ||
254 | |||
255 | /* acknowledge device sleep */ | ||
256 | if (send_hcill_cmd(HCILL_GO_TO_SLEEP_ACK, hu) < 0) { | ||
257 | BT_ERR("cannot acknowledge device sleep"); | ||
258 | goto out; | ||
259 | } | ||
260 | |||
261 | /* update state */ | ||
262 | ll->hcill_state = HCILL_ASLEEP; | ||
263 | |||
264 | out: | ||
265 | spin_unlock_irqrestore(&ll->hcill_lock, flags); | ||
266 | |||
267 | /* actually send the sleep ack packet */ | ||
268 | hci_uart_tx_wakeup(hu); | ||
269 | } | ||
270 | |||
271 | /* | ||
272 | * Called upon wake-up-acknowledgement from the device | ||
273 | */ | ||
274 | static void ll_device_woke_up(struct hci_uart *hu) | ||
275 | { | ||
276 | unsigned long flags; | ||
277 | struct ll_struct *ll = hu->priv; | ||
278 | |||
279 | BT_DBG("hu %p", hu); | ||
280 | |||
281 | /* lock hcill state */ | ||
282 | spin_lock_irqsave(&ll->hcill_lock, flags); | ||
283 | |||
284 | /* sanity check */ | ||
285 | if (ll->hcill_state != HCILL_ASLEEP_TO_AWAKE) | ||
286 | BT_ERR("received HCILL_WAKE_UP_ACK in state %ld", ll->hcill_state); | ||
287 | |||
288 | /* send pending packets and change state to HCILL_AWAKE */ | ||
289 | __ll_do_awake(ll); | ||
290 | |||
291 | spin_unlock_irqrestore(&ll->hcill_lock, flags); | ||
292 | |||
293 | /* actually send the packets */ | ||
294 | hci_uart_tx_wakeup(hu); | ||
295 | } | ||
296 | |||
297 | /* Enqueue frame for transmittion (padding, crc, etc) */ | ||
298 | /* may be called from two simultaneous tasklets */ | ||
299 | static int ll_enqueue(struct hci_uart *hu, struct sk_buff *skb) | ||
300 | { | ||
301 | unsigned long flags = 0; | ||
302 | struct ll_struct *ll = hu->priv; | ||
303 | |||
304 | BT_DBG("hu %p skb %p", hu, skb); | ||
305 | |||
306 | /* Prepend skb with frame type */ | ||
307 | memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); | ||
308 | |||
309 | /* lock hcill state */ | ||
310 | spin_lock_irqsave(&ll->hcill_lock, flags); | ||
311 | |||
312 | /* act according to current state */ | ||
313 | switch (ll->hcill_state) { | ||
314 | case HCILL_AWAKE: | ||
315 | BT_DBG("device awake, sending normally"); | ||
316 | skb_queue_tail(&ll->txq, skb); | ||
317 | break; | ||
318 | case HCILL_ASLEEP: | ||
319 | BT_DBG("device asleep, waking up and queueing packet"); | ||
320 | /* save packet for later */ | ||
321 | skb_queue_tail(&ll->tx_wait_q, skb); | ||
322 | /* awake device */ | ||
323 | if (send_hcill_cmd(HCILL_WAKE_UP_IND, hu) < 0) { | ||
324 | BT_ERR("cannot wake up device"); | ||
325 | break; | ||
326 | } | ||
327 | ll->hcill_state = HCILL_ASLEEP_TO_AWAKE; | ||
328 | break; | ||
329 | case HCILL_ASLEEP_TO_AWAKE: | ||
330 | BT_DBG("device waking up, queueing packet"); | ||
331 | /* transient state; just keep packet for later */ | ||
332 | skb_queue_tail(&ll->tx_wait_q, skb); | ||
333 | break; | ||
334 | default: | ||
335 | BT_ERR("illegal hcill state: %ld (losing packet)", ll->hcill_state); | ||
336 | kfree_skb(skb); | ||
337 | break; | ||
338 | } | ||
339 | |||
340 | spin_unlock_irqrestore(&ll->hcill_lock, flags); | ||
341 | |||
342 | return 0; | ||
343 | } | ||
344 | |||
345 | static inline int ll_check_data_len(struct ll_struct *ll, int len) | ||
346 | { | ||
347 | register int room = skb_tailroom(ll->rx_skb); | ||
348 | |||
349 | BT_DBG("len %d room %d", len, room); | ||
350 | |||
351 | if (!len) { | ||
352 | hci_recv_frame(ll->rx_skb); | ||
353 | } else if (len > room) { | ||
354 | BT_ERR("Data length is too large"); | ||
355 | kfree_skb(ll->rx_skb); | ||
356 | } else { | ||
357 | ll->rx_state = HCILL_W4_DATA; | ||
358 | ll->rx_count = len; | ||
359 | return len; | ||
360 | } | ||
361 | |||
362 | ll->rx_state = HCILL_W4_PACKET_TYPE; | ||
363 | ll->rx_skb = NULL; | ||
364 | ll->rx_count = 0; | ||
365 | |||
366 | return 0; | ||
367 | } | ||
368 | |||
369 | /* Recv data */ | ||
370 | static int ll_recv(struct hci_uart *hu, void *data, int count) | ||
371 | { | ||
372 | struct ll_struct *ll = hu->priv; | ||
373 | register char *ptr; | ||
374 | struct hci_event_hdr *eh; | ||
375 | struct hci_acl_hdr *ah; | ||
376 | struct hci_sco_hdr *sh; | ||
377 | register int len, type, dlen; | ||
378 | |||
379 | BT_DBG("hu %p count %d rx_state %ld rx_count %ld", hu, count, ll->rx_state, ll->rx_count); | ||
380 | |||
381 | ptr = data; | ||
382 | while (count) { | ||
383 | if (ll->rx_count) { | ||
384 | len = min_t(unsigned int, ll->rx_count, count); | ||
385 | memcpy(skb_put(ll->rx_skb, len), ptr, len); | ||
386 | ll->rx_count -= len; count -= len; ptr += len; | ||
387 | |||
388 | if (ll->rx_count) | ||
389 | continue; | ||
390 | |||
391 | switch (ll->rx_state) { | ||
392 | case HCILL_W4_DATA: | ||
393 | BT_DBG("Complete data"); | ||
394 | hci_recv_frame(ll->rx_skb); | ||
395 | |||
396 | ll->rx_state = HCILL_W4_PACKET_TYPE; | ||
397 | ll->rx_skb = NULL; | ||
398 | continue; | ||
399 | |||
400 | case HCILL_W4_EVENT_HDR: | ||
401 | eh = (struct hci_event_hdr *) ll->rx_skb->data; | ||
402 | |||
403 | BT_DBG("Event header: evt 0x%2.2x plen %d", eh->evt, eh->plen); | ||
404 | |||
405 | ll_check_data_len(ll, eh->plen); | ||
406 | continue; | ||
407 | |||
408 | case HCILL_W4_ACL_HDR: | ||
409 | ah = (struct hci_acl_hdr *) ll->rx_skb->data; | ||
410 | dlen = __le16_to_cpu(ah->dlen); | ||
411 | |||
412 | BT_DBG("ACL header: dlen %d", dlen); | ||
413 | |||
414 | ll_check_data_len(ll, dlen); | ||
415 | continue; | ||
416 | |||
417 | case HCILL_W4_SCO_HDR: | ||
418 | sh = (struct hci_sco_hdr *) ll->rx_skb->data; | ||
419 | |||
420 | BT_DBG("SCO header: dlen %d", sh->dlen); | ||
421 | |||
422 | ll_check_data_len(ll, sh->dlen); | ||
423 | continue; | ||
424 | } | ||
425 | } | ||
426 | |||
427 | /* HCILL_W4_PACKET_TYPE */ | ||
428 | switch (*ptr) { | ||
429 | case HCI_EVENT_PKT: | ||
430 | BT_DBG("Event packet"); | ||
431 | ll->rx_state = HCILL_W4_EVENT_HDR; | ||
432 | ll->rx_count = HCI_EVENT_HDR_SIZE; | ||
433 | type = HCI_EVENT_PKT; | ||
434 | break; | ||
435 | |||
436 | case HCI_ACLDATA_PKT: | ||
437 | BT_DBG("ACL packet"); | ||
438 | ll->rx_state = HCILL_W4_ACL_HDR; | ||
439 | ll->rx_count = HCI_ACL_HDR_SIZE; | ||
440 | type = HCI_ACLDATA_PKT; | ||
441 | break; | ||
442 | |||
443 | case HCI_SCODATA_PKT: | ||
444 | BT_DBG("SCO packet"); | ||
445 | ll->rx_state = HCILL_W4_SCO_HDR; | ||
446 | ll->rx_count = HCI_SCO_HDR_SIZE; | ||
447 | type = HCI_SCODATA_PKT; | ||
448 | break; | ||
449 | |||
450 | /* HCILL signals */ | ||
451 | case HCILL_GO_TO_SLEEP_IND: | ||
452 | BT_DBG("HCILL_GO_TO_SLEEP_IND packet"); | ||
453 | ll_device_want_to_sleep(hu); | ||
454 | ptr++; count--; | ||
455 | continue; | ||
456 | |||
457 | case HCILL_GO_TO_SLEEP_ACK: | ||
458 | /* shouldn't happen */ | ||
459 | BT_ERR("received HCILL_GO_TO_SLEEP_ACK (in state %ld)", ll->hcill_state); | ||
460 | ptr++; count--; | ||
461 | continue; | ||
462 | |||
463 | case HCILL_WAKE_UP_IND: | ||
464 | BT_DBG("HCILL_WAKE_UP_IND packet"); | ||
465 | ll_device_want_to_wakeup(hu); | ||
466 | ptr++; count--; | ||
467 | continue; | ||
468 | |||
469 | case HCILL_WAKE_UP_ACK: | ||
470 | BT_DBG("HCILL_WAKE_UP_ACK packet"); | ||
471 | ll_device_woke_up(hu); | ||
472 | ptr++; count--; | ||
473 | continue; | ||
474 | |||
475 | default: | ||
476 | BT_ERR("Unknown HCI packet type %2.2x", (__u8)*ptr); | ||
477 | hu->hdev->stat.err_rx++; | ||
478 | ptr++; count--; | ||
479 | continue; | ||
480 | }; | ||
481 | |||
482 | ptr++; count--; | ||
483 | |||
484 | /* Allocate packet */ | ||
485 | ll->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); | ||
486 | if (!ll->rx_skb) { | ||
487 | BT_ERR("Can't allocate mem for new packet"); | ||
488 | ll->rx_state = HCILL_W4_PACKET_TYPE; | ||
489 | ll->rx_count = 0; | ||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | ll->rx_skb->dev = (void *) hu->hdev; | ||
494 | bt_cb(ll->rx_skb)->pkt_type = type; | ||
495 | } | ||
496 | |||
497 | return count; | ||
498 | } | ||
499 | |||
500 | static struct sk_buff *ll_dequeue(struct hci_uart *hu) | ||
501 | { | ||
502 | struct ll_struct *ll = hu->priv; | ||
503 | return skb_dequeue(&ll->txq); | ||
504 | } | ||
505 | |||
506 | static struct hci_uart_proto llp = { | ||
507 | .id = HCI_UART_LL, | ||
508 | .open = ll_open, | ||
509 | .close = ll_close, | ||
510 | .recv = ll_recv, | ||
511 | .enqueue = ll_enqueue, | ||
512 | .dequeue = ll_dequeue, | ||
513 | .flush = ll_flush, | ||
514 | }; | ||
515 | |||
516 | int ll_init(void) | ||
517 | { | ||
518 | int err = hci_uart_register_proto(&llp); | ||
519 | |||
520 | if (!err) | ||
521 | BT_INFO("HCILL protocol initialized"); | ||
522 | else | ||
523 | BT_ERR("HCILL protocol registration failed"); | ||
524 | |||
525 | return err; | ||
526 | } | ||
527 | |||
528 | int ll_deinit(void) | ||
529 | { | ||
530 | return hci_uart_unregister_proto(&llp); | ||
531 | } | ||
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h index 1097ce72393f..50113db06b9f 100644 --- a/drivers/bluetooth/hci_uart.h +++ b/drivers/bluetooth/hci_uart.h | |||
@@ -33,12 +33,13 @@ | |||
33 | #define HCIUARTGETDEVICE _IOR('U', 202, int) | 33 | #define HCIUARTGETDEVICE _IOR('U', 202, int) |
34 | 34 | ||
35 | /* UART protocols */ | 35 | /* UART protocols */ |
36 | #define HCI_UART_MAX_PROTO 4 | 36 | #define HCI_UART_MAX_PROTO 5 |
37 | 37 | ||
38 | #define HCI_UART_H4 0 | 38 | #define HCI_UART_H4 0 |
39 | #define HCI_UART_BCSP 1 | 39 | #define HCI_UART_BCSP 1 |
40 | #define HCI_UART_3WIRE 2 | 40 | #define HCI_UART_3WIRE 2 |
41 | #define HCI_UART_H4DS 3 | 41 | #define HCI_UART_H4DS 3 |
42 | #define HCI_UART_LL 4 | ||
42 | 43 | ||
43 | struct hci_uart; | 44 | struct hci_uart; |
44 | 45 | ||
@@ -85,3 +86,8 @@ int h4_deinit(void); | |||
85 | int bcsp_init(void); | 86 | int bcsp_init(void); |
86 | int bcsp_deinit(void); | 87 | int bcsp_deinit(void); |
87 | #endif | 88 | #endif |
89 | |||
90 | #ifdef CONFIG_BT_HCIUART_LL | ||
91 | int ll_init(void); | ||
92 | int ll_deinit(void); | ||
93 | #endif | ||
diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c index ed53aaab4c02..ae419736158e 100644 --- a/drivers/net/cpmac.c +++ b/drivers/net/cpmac.c | |||
@@ -471,7 +471,7 @@ static int cpmac_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
471 | } | 471 | } |
472 | 472 | ||
473 | len = max(skb->len, ETH_ZLEN); | 473 | len = max(skb->len, ETH_ZLEN); |
474 | queue = skb->queue_mapping; | 474 | queue = skb_get_queue_mapping(skb); |
475 | #ifdef CONFIG_NETDEVICES_MULTIQUEUE | 475 | #ifdef CONFIG_NETDEVICES_MULTIQUEUE |
476 | netif_stop_subqueue(dev, queue); | 476 | netif_stop_subqueue(dev, queue); |
477 | #else | 477 | #else |
diff --git a/drivers/net/niu.c b/drivers/net/niu.c index ed1f9bbb2a32..112ab079ce7d 100644 --- a/drivers/net/niu.c +++ b/drivers/net/niu.c | |||
@@ -3103,31 +3103,12 @@ static int niu_alloc_tx_ring_info(struct niu *np, | |||
3103 | 3103 | ||
3104 | static void niu_size_rbr(struct niu *np, struct rx_ring_info *rp) | 3104 | static void niu_size_rbr(struct niu *np, struct rx_ring_info *rp) |
3105 | { | 3105 | { |
3106 | u16 bs; | 3106 | u16 bss; |
3107 | 3107 | ||
3108 | switch (PAGE_SIZE) { | 3108 | bss = min(PAGE_SHIFT, 15); |
3109 | case 4 * 1024: | ||
3110 | case 8 * 1024: | ||
3111 | case 16 * 1024: | ||
3112 | case 32 * 1024: | ||
3113 | rp->rbr_block_size = PAGE_SIZE; | ||
3114 | rp->rbr_blocks_per_page = 1; | ||
3115 | break; | ||
3116 | 3109 | ||
3117 | default: | 3110 | rp->rbr_block_size = 1 << bss; |
3118 | if (PAGE_SIZE % (32 * 1024) == 0) | 3111 | rp->rbr_blocks_per_page = 1 << (PAGE_SHIFT-bss); |
3119 | bs = 32 * 1024; | ||
3120 | else if (PAGE_SIZE % (16 * 1024) == 0) | ||
3121 | bs = 16 * 1024; | ||
3122 | else if (PAGE_SIZE % (8 * 1024) == 0) | ||
3123 | bs = 8 * 1024; | ||
3124 | else if (PAGE_SIZE % (4 * 1024) == 0) | ||
3125 | bs = 4 * 1024; | ||
3126 | else | ||
3127 | BUG(); | ||
3128 | rp->rbr_block_size = bs; | ||
3129 | rp->rbr_blocks_per_page = PAGE_SIZE / bs; | ||
3130 | } | ||
3131 | 3112 | ||
3132 | rp->rbr_sizes[0] = 256; | 3113 | rp->rbr_sizes[0] = 256; |
3133 | rp->rbr_sizes[1] = 1024; | 3114 | rp->rbr_sizes[1] = 1024; |
@@ -7902,12 +7883,7 @@ static int __init niu_init(void) | |||
7902 | { | 7883 | { |
7903 | int err = 0; | 7884 | int err = 0; |
7904 | 7885 | ||
7905 | BUILD_BUG_ON((PAGE_SIZE < 4 * 1024) || | 7886 | BUILD_BUG_ON(PAGE_SIZE < 4 * 1024); |
7906 | ((PAGE_SIZE > 32 * 1024) && | ||
7907 | ((PAGE_SIZE % (32 * 1024)) != 0 && | ||
7908 | (PAGE_SIZE % (16 * 1024)) != 0 && | ||
7909 | (PAGE_SIZE % (8 * 1024)) != 0 && | ||
7910 | (PAGE_SIZE % (4 * 1024)) != 0))); | ||
7911 | 7887 | ||
7912 | niu_debug = netif_msg_init(debug, NIU_MSG_DEFAULT); | 7888 | niu_debug = netif_msg_init(debug, NIU_MSG_DEFAULT); |
7913 | 7889 | ||
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index 014dc2cfe4d6..09440d783e65 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c | |||
@@ -64,8 +64,8 @@ | |||
64 | 64 | ||
65 | #define DRV_MODULE_NAME "tg3" | 65 | #define DRV_MODULE_NAME "tg3" |
66 | #define PFX DRV_MODULE_NAME ": " | 66 | #define PFX DRV_MODULE_NAME ": " |
67 | #define DRV_MODULE_VERSION "3.84" | 67 | #define DRV_MODULE_VERSION "3.85" |
68 | #define DRV_MODULE_RELDATE "October 12, 2007" | 68 | #define DRV_MODULE_RELDATE "October 18, 2007" |
69 | 69 | ||
70 | #define TG3_DEF_MAC_MODE 0 | 70 | #define TG3_DEF_MAC_MODE 0 |
71 | #define TG3_DEF_RX_MODE 0 | 71 | #define TG3_DEF_RX_MODE 0 |
@@ -200,6 +200,7 @@ static struct pci_device_id tg3_pci_tbl[] = { | |||
200 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, | 200 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
201 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, | 201 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
202 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, | 202 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
203 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, | ||
203 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, | 204 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
204 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, | 205 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
205 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, | 206 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
@@ -5028,10 +5029,7 @@ static int tg3_poll_fw(struct tg3 *tp) | |||
5028 | /* Save PCI command register before chip reset */ | 5029 | /* Save PCI command register before chip reset */ |
5029 | static void tg3_save_pci_state(struct tg3 *tp) | 5030 | static void tg3_save_pci_state(struct tg3 *tp) |
5030 | { | 5031 | { |
5031 | u32 val; | 5032 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
5032 | |||
5033 | pci_read_config_dword(tp->pdev, TG3PCI_COMMAND, &val); | ||
5034 | tp->pci_cmd = val; | ||
5035 | } | 5033 | } |
5036 | 5034 | ||
5037 | /* Restore PCI state after chip reset */ | 5035 | /* Restore PCI state after chip reset */ |
@@ -5054,7 +5052,7 @@ static void tg3_restore_pci_state(struct tg3 *tp) | |||
5054 | PCISTATE_ALLOW_APE_SHMEM_WR; | 5052 | PCISTATE_ALLOW_APE_SHMEM_WR; |
5055 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); | 5053 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
5056 | 5054 | ||
5057 | pci_write_config_dword(tp->pdev, TG3PCI_COMMAND, tp->pci_cmd); | 5055 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
5058 | 5056 | ||
5059 | if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { | 5057 | if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { |
5060 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, | 5058 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
@@ -10820,9 +10818,24 @@ out_not_found: | |||
10820 | strcpy(tp->board_part_number, "none"); | 10818 | strcpy(tp->board_part_number, "none"); |
10821 | } | 10819 | } |
10822 | 10820 | ||
10821 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) | ||
10822 | { | ||
10823 | u32 val; | ||
10824 | |||
10825 | if (tg3_nvram_read_swab(tp, offset, &val) || | ||
10826 | (val & 0xfc000000) != 0x0c000000 || | ||
10827 | tg3_nvram_read_swab(tp, offset + 4, &val) || | ||
10828 | val != 0) | ||
10829 | return 0; | ||
10830 | |||
10831 | return 1; | ||
10832 | } | ||
10833 | |||
10823 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) | 10834 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
10824 | { | 10835 | { |
10825 | u32 val, offset, start; | 10836 | u32 val, offset, start; |
10837 | u32 ver_offset; | ||
10838 | int i, bcnt; | ||
10826 | 10839 | ||
10827 | if (tg3_nvram_read_swab(tp, 0, &val)) | 10840 | if (tg3_nvram_read_swab(tp, 0, &val)) |
10828 | return; | 10841 | return; |
@@ -10835,29 +10848,71 @@ static void __devinit tg3_read_fw_ver(struct tg3 *tp) | |||
10835 | return; | 10848 | return; |
10836 | 10849 | ||
10837 | offset = tg3_nvram_logical_addr(tp, offset); | 10850 | offset = tg3_nvram_logical_addr(tp, offset); |
10838 | if (tg3_nvram_read_swab(tp, offset, &val)) | 10851 | |
10852 | if (!tg3_fw_img_is_valid(tp, offset) || | ||
10853 | tg3_nvram_read_swab(tp, offset + 8, &ver_offset)) | ||
10839 | return; | 10854 | return; |
10840 | 10855 | ||
10841 | if ((val & 0xfc000000) == 0x0c000000) { | 10856 | offset = offset + ver_offset - start; |
10842 | u32 ver_offset, addr; | 10857 | for (i = 0; i < 16; i += 4) { |
10843 | int i; | 10858 | if (tg3_nvram_read(tp, offset + i, &val)) |
10859 | return; | ||
10844 | 10860 | ||
10845 | if (tg3_nvram_read_swab(tp, offset + 4, &val) || | 10861 | val = le32_to_cpu(val); |
10846 | tg3_nvram_read_swab(tp, offset + 8, &ver_offset)) | 10862 | memcpy(tp->fw_ver + i, &val, 4); |
10863 | } | ||
10864 | |||
10865 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || | ||
10866 | (tp->tg3_flags & TG3_FLG3_ENABLE_APE)) | ||
10867 | return; | ||
10868 | |||
10869 | for (offset = TG3_NVM_DIR_START; | ||
10870 | offset < TG3_NVM_DIR_END; | ||
10871 | offset += TG3_NVM_DIRENT_SIZE) { | ||
10872 | if (tg3_nvram_read_swab(tp, offset, &val)) | ||
10847 | return; | 10873 | return; |
10848 | 10874 | ||
10849 | if (val != 0) | 10875 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
10876 | break; | ||
10877 | } | ||
10878 | |||
10879 | if (offset == TG3_NVM_DIR_END) | ||
10880 | return; | ||
10881 | |||
10882 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | ||
10883 | start = 0x08000000; | ||
10884 | else if (tg3_nvram_read_swab(tp, offset - 4, &start)) | ||
10885 | return; | ||
10886 | |||
10887 | if (tg3_nvram_read_swab(tp, offset + 4, &offset) || | ||
10888 | !tg3_fw_img_is_valid(tp, offset) || | ||
10889 | tg3_nvram_read_swab(tp, offset + 8, &val)) | ||
10890 | return; | ||
10891 | |||
10892 | offset += val - start; | ||
10893 | |||
10894 | bcnt = strlen(tp->fw_ver); | ||
10895 | |||
10896 | tp->fw_ver[bcnt++] = ','; | ||
10897 | tp->fw_ver[bcnt++] = ' '; | ||
10898 | |||
10899 | for (i = 0; i < 4; i++) { | ||
10900 | if (tg3_nvram_read(tp, offset, &val)) | ||
10850 | return; | 10901 | return; |
10851 | 10902 | ||
10852 | addr = offset + ver_offset - start; | 10903 | val = le32_to_cpu(val); |
10853 | for (i = 0; i < 16; i += 4) { | 10904 | offset += sizeof(val); |
10854 | if (tg3_nvram_read(tp, addr + i, &val)) | ||
10855 | return; | ||
10856 | 10905 | ||
10857 | val = cpu_to_le32(val); | 10906 | if (bcnt > TG3_VER_SIZE - sizeof(val)) { |
10858 | memcpy(tp->fw_ver + i, &val, 4); | 10907 | memcpy(&tp->fw_ver[bcnt], &val, TG3_VER_SIZE - bcnt); |
10908 | break; | ||
10859 | } | 10909 | } |
10910 | |||
10911 | memcpy(&tp->fw_ver[bcnt], &val, sizeof(val)); | ||
10912 | bcnt += sizeof(val); | ||
10860 | } | 10913 | } |
10914 | |||
10915 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; | ||
10861 | } | 10916 | } |
10862 | 10917 | ||
10863 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); | 10918 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); |
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h index 6dbdad2b8f88..1d5b2a3dd29d 100644 --- a/drivers/net/tg3.h +++ b/drivers/net/tg3.h | |||
@@ -1540,6 +1540,12 @@ | |||
1540 | #define TG3_EEPROM_MAGIC_HW 0xabcd | 1540 | #define TG3_EEPROM_MAGIC_HW 0xabcd |
1541 | #define TG3_EEPROM_MAGIC_HW_MSK 0xffff | 1541 | #define TG3_EEPROM_MAGIC_HW_MSK 0xffff |
1542 | 1542 | ||
1543 | #define TG3_NVM_DIR_START 0x18 | ||
1544 | #define TG3_NVM_DIR_END 0x78 | ||
1545 | #define TG3_NVM_DIRENT_SIZE 0xc | ||
1546 | #define TG3_NVM_DIRTYPE_SHIFT 24 | ||
1547 | #define TG3_NVM_DIRTYPE_ASFINI 1 | ||
1548 | |||
1543 | /* 32K Window into NIC internal memory */ | 1549 | /* 32K Window into NIC internal memory */ |
1544 | #define NIC_SRAM_WIN_BASE 0x00008000 | 1550 | #define NIC_SRAM_WIN_BASE 0x00008000 |
1545 | 1551 | ||
@@ -2415,10 +2421,11 @@ struct tg3 { | |||
2415 | #define PHY_REV_BCM5411_X0 0x1 /* Found on Netgear GA302T */ | 2421 | #define PHY_REV_BCM5411_X0 0x1 /* Found on Netgear GA302T */ |
2416 | 2422 | ||
2417 | u32 led_ctrl; | 2423 | u32 led_ctrl; |
2418 | u32 pci_cmd; | 2424 | u16 pci_cmd; |
2419 | 2425 | ||
2420 | char board_part_number[24]; | 2426 | char board_part_number[24]; |
2421 | char fw_ver[16]; | 2427 | #define TG3_VER_SIZE 32 |
2428 | char fw_ver[TG3_VER_SIZE]; | ||
2422 | u32 nic_sram_data_cfg; | 2429 | u32 nic_sram_data_cfg; |
2423 | u32 pci_clock_ctrl; | 2430 | u32 pci_clock_ctrl; |
2424 | struct pci_dev *pdev_peer; | 2431 | struct pci_dev *pdev_peer; |