Commit 55ed7d4d1469eafbe3ad7e8fcd44f5af27845a81

Authored by AceLan Kao
Committed by Gustavo Padovan
1 parent 6c0c331e4c

Bluetooth: Add support for Atheros [04ca:3005]

Add another vendor specific ID for Atheros AR3012 device.
This chip is wrapped by Lite-On Technology Corp.

output of usb-devices:
T:  Bus=04 Lev=01 Prnt=01 Port=03 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 1.10 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=04ca ProdID=3005 Rev=00.02
S:  Manufacturer=Atheros Communications
S:  Product=Bluetooth USB Host Controller
S:  SerialNumber=Alaska Day 2006
C:  #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
I:  If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
Signed-off-by: Gustavo Padovan <gustavo@padovan.org>

Showing 2 changed files with 3 additions and 0 deletions Inline Diff

drivers/bluetooth/ath3k.c
1 /* 1 /*
2 * Copyright (c) 2008-2009 Atheros Communications Inc. 2 * Copyright (c) 2008-2009 Atheros Communications Inc.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or 6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. 7 * (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * 17 *
18 */ 18 */
19 19
20 20
21 #include <linux/module.h> 21 #include <linux/module.h>
22 #include <linux/kernel.h> 22 #include <linux/kernel.h>
23 #include <linux/init.h> 23 #include <linux/init.h>
24 #include <linux/slab.h> 24 #include <linux/slab.h>
25 #include <linux/types.h> 25 #include <linux/types.h>
26 #include <linux/errno.h> 26 #include <linux/errno.h>
27 #include <linux/device.h> 27 #include <linux/device.h>
28 #include <linux/firmware.h> 28 #include <linux/firmware.h>
29 #include <linux/usb.h> 29 #include <linux/usb.h>
30 #include <net/bluetooth/bluetooth.h> 30 #include <net/bluetooth/bluetooth.h>
31 31
32 #define VERSION "1.0" 32 #define VERSION "1.0"
33 #define ATH3K_FIRMWARE "ath3k-1.fw" 33 #define ATH3K_FIRMWARE "ath3k-1.fw"
34 34
35 #define ATH3K_DNLOAD 0x01 35 #define ATH3K_DNLOAD 0x01
36 #define ATH3K_GETSTATE 0x05 36 #define ATH3K_GETSTATE 0x05
37 #define ATH3K_SET_NORMAL_MODE 0x07 37 #define ATH3K_SET_NORMAL_MODE 0x07
38 #define ATH3K_GETVERSION 0x09 38 #define ATH3K_GETVERSION 0x09
39 #define USB_REG_SWITCH_VID_PID 0x0a 39 #define USB_REG_SWITCH_VID_PID 0x0a
40 40
41 #define ATH3K_MODE_MASK 0x3F 41 #define ATH3K_MODE_MASK 0x3F
42 #define ATH3K_NORMAL_MODE 0x0E 42 #define ATH3K_NORMAL_MODE 0x0E
43 43
44 #define ATH3K_PATCH_UPDATE 0x80 44 #define ATH3K_PATCH_UPDATE 0x80
45 #define ATH3K_SYSCFG_UPDATE 0x40 45 #define ATH3K_SYSCFG_UPDATE 0x40
46 46
47 #define ATH3K_XTAL_FREQ_26M 0x00 47 #define ATH3K_XTAL_FREQ_26M 0x00
48 #define ATH3K_XTAL_FREQ_40M 0x01 48 #define ATH3K_XTAL_FREQ_40M 0x01
49 #define ATH3K_XTAL_FREQ_19P2 0x02 49 #define ATH3K_XTAL_FREQ_19P2 0x02
50 #define ATH3K_NAME_LEN 0xFF 50 #define ATH3K_NAME_LEN 0xFF
51 51
52 struct ath3k_version { 52 struct ath3k_version {
53 unsigned int rom_version; 53 unsigned int rom_version;
54 unsigned int build_version; 54 unsigned int build_version;
55 unsigned int ram_version; 55 unsigned int ram_version;
56 unsigned char ref_clock; 56 unsigned char ref_clock;
57 unsigned char reserved[0x07]; 57 unsigned char reserved[0x07];
58 }; 58 };
59 59
60 static struct usb_device_id ath3k_table[] = { 60 static struct usb_device_id ath3k_table[] = {
61 /* Atheros AR3011 */ 61 /* Atheros AR3011 */
62 { USB_DEVICE(0x0CF3, 0x3000) }, 62 { USB_DEVICE(0x0CF3, 0x3000) },
63 63
64 /* Atheros AR3011 with sflash firmware*/ 64 /* Atheros AR3011 with sflash firmware*/
65 { USB_DEVICE(0x0CF3, 0x3002) }, 65 { USB_DEVICE(0x0CF3, 0x3002) },
66 { USB_DEVICE(0x13d3, 0x3304) }, 66 { USB_DEVICE(0x13d3, 0x3304) },
67 { USB_DEVICE(0x0930, 0x0215) }, 67 { USB_DEVICE(0x0930, 0x0215) },
68 { USB_DEVICE(0x0489, 0xE03D) }, 68 { USB_DEVICE(0x0489, 0xE03D) },
69 69
70 /* Atheros AR9285 Malbec with sflash firmware */ 70 /* Atheros AR9285 Malbec with sflash firmware */
71 { USB_DEVICE(0x03F0, 0x311D) }, 71 { USB_DEVICE(0x03F0, 0x311D) },
72 72
73 /* Atheros AR3012 with sflash firmware*/ 73 /* Atheros AR3012 with sflash firmware*/
74 { USB_DEVICE(0x0CF3, 0x3004) }, 74 { USB_DEVICE(0x0CF3, 0x3004) },
75 { USB_DEVICE(0x0CF3, 0x311D) }, 75 { USB_DEVICE(0x0CF3, 0x311D) },
76 { USB_DEVICE(0x13d3, 0x3375) }, 76 { USB_DEVICE(0x13d3, 0x3375) },
77 { USB_DEVICE(0x04CA, 0x3005) },
77 78
78 /* Atheros AR5BBU12 with sflash firmware */ 79 /* Atheros AR5BBU12 with sflash firmware */
79 { USB_DEVICE(0x0489, 0xE02C) }, 80 { USB_DEVICE(0x0489, 0xE02C) },
80 81
81 { } /* Terminating entry */ 82 { } /* Terminating entry */
82 }; 83 };
83 84
84 MODULE_DEVICE_TABLE(usb, ath3k_table); 85 MODULE_DEVICE_TABLE(usb, ath3k_table);
85 86
86 #define BTUSB_ATH3012 0x80 87 #define BTUSB_ATH3012 0x80
87 /* This table is to load patch and sysconfig files 88 /* This table is to load patch and sysconfig files
88 * for AR3012 */ 89 * for AR3012 */
89 static struct usb_device_id ath3k_blist_tbl[] = { 90 static struct usb_device_id ath3k_blist_tbl[] = {
90 91
91 /* Atheros AR3012 with sflash firmware*/ 92 /* Atheros AR3012 with sflash firmware*/
92 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, 93 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
93 { USB_DEVICE(0x0cf3, 0x311D), .driver_info = BTUSB_ATH3012 }, 94 { USB_DEVICE(0x0cf3, 0x311D), .driver_info = BTUSB_ATH3012 },
94 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 95 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
96 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
95 97
96 { } /* Terminating entry */ 98 { } /* Terminating entry */
97 }; 99 };
98 100
99 #define USB_REQ_DFU_DNLOAD 1 101 #define USB_REQ_DFU_DNLOAD 1
100 #define BULK_SIZE 4096 102 #define BULK_SIZE 4096
101 #define FW_HDR_SIZE 20 103 #define FW_HDR_SIZE 20
102 104
103 static int ath3k_load_firmware(struct usb_device *udev, 105 static int ath3k_load_firmware(struct usb_device *udev,
104 const struct firmware *firmware) 106 const struct firmware *firmware)
105 { 107 {
106 u8 *send_buf; 108 u8 *send_buf;
107 int err, pipe, len, size, sent = 0; 109 int err, pipe, len, size, sent = 0;
108 int count = firmware->size; 110 int count = firmware->size;
109 111
110 BT_DBG("udev %p", udev); 112 BT_DBG("udev %p", udev);
111 113
112 pipe = usb_sndctrlpipe(udev, 0); 114 pipe = usb_sndctrlpipe(udev, 0);
113 115
114 send_buf = kmalloc(BULK_SIZE, GFP_KERNEL); 116 send_buf = kmalloc(BULK_SIZE, GFP_KERNEL);
115 if (!send_buf) { 117 if (!send_buf) {
116 BT_ERR("Can't allocate memory chunk for firmware"); 118 BT_ERR("Can't allocate memory chunk for firmware");
117 return -ENOMEM; 119 return -ENOMEM;
118 } 120 }
119 121
120 memcpy(send_buf, firmware->data, 20); 122 memcpy(send_buf, firmware->data, 20);
121 if ((err = usb_control_msg(udev, pipe, 123 if ((err = usb_control_msg(udev, pipe,
122 USB_REQ_DFU_DNLOAD, 124 USB_REQ_DFU_DNLOAD,
123 USB_TYPE_VENDOR, 0, 0, 125 USB_TYPE_VENDOR, 0, 0,
124 send_buf, 20, USB_CTRL_SET_TIMEOUT)) < 0) { 126 send_buf, 20, USB_CTRL_SET_TIMEOUT)) < 0) {
125 BT_ERR("Can't change to loading configuration err"); 127 BT_ERR("Can't change to loading configuration err");
126 goto error; 128 goto error;
127 } 129 }
128 sent += 20; 130 sent += 20;
129 count -= 20; 131 count -= 20;
130 132
131 while (count) { 133 while (count) {
132 size = min_t(uint, count, BULK_SIZE); 134 size = min_t(uint, count, BULK_SIZE);
133 pipe = usb_sndbulkpipe(udev, 0x02); 135 pipe = usb_sndbulkpipe(udev, 0x02);
134 memcpy(send_buf, firmware->data + sent, size); 136 memcpy(send_buf, firmware->data + sent, size);
135 137
136 err = usb_bulk_msg(udev, pipe, send_buf, size, 138 err = usb_bulk_msg(udev, pipe, send_buf, size,
137 &len, 3000); 139 &len, 3000);
138 140
139 if (err || (len != size)) { 141 if (err || (len != size)) {
140 BT_ERR("Error in firmware loading err = %d," 142 BT_ERR("Error in firmware loading err = %d,"
141 "len = %d, size = %d", err, len, size); 143 "len = %d, size = %d", err, len, size);
142 goto error; 144 goto error;
143 } 145 }
144 146
145 sent += size; 147 sent += size;
146 count -= size; 148 count -= size;
147 } 149 }
148 150
149 error: 151 error:
150 kfree(send_buf); 152 kfree(send_buf);
151 return err; 153 return err;
152 } 154 }
153 155
154 static int ath3k_get_state(struct usb_device *udev, unsigned char *state) 156 static int ath3k_get_state(struct usb_device *udev, unsigned char *state)
155 { 157 {
156 int pipe = 0; 158 int pipe = 0;
157 159
158 pipe = usb_rcvctrlpipe(udev, 0); 160 pipe = usb_rcvctrlpipe(udev, 0);
159 return usb_control_msg(udev, pipe, ATH3K_GETSTATE, 161 return usb_control_msg(udev, pipe, ATH3K_GETSTATE,
160 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, 162 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
161 state, 0x01, USB_CTRL_SET_TIMEOUT); 163 state, 0x01, USB_CTRL_SET_TIMEOUT);
162 } 164 }
163 165
164 static int ath3k_get_version(struct usb_device *udev, 166 static int ath3k_get_version(struct usb_device *udev,
165 struct ath3k_version *version) 167 struct ath3k_version *version)
166 { 168 {
167 int pipe = 0; 169 int pipe = 0;
168 170
169 pipe = usb_rcvctrlpipe(udev, 0); 171 pipe = usb_rcvctrlpipe(udev, 0);
170 return usb_control_msg(udev, pipe, ATH3K_GETVERSION, 172 return usb_control_msg(udev, pipe, ATH3K_GETVERSION,
171 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, version, 173 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, version,
172 sizeof(struct ath3k_version), 174 sizeof(struct ath3k_version),
173 USB_CTRL_SET_TIMEOUT); 175 USB_CTRL_SET_TIMEOUT);
174 } 176 }
175 177
176 static int ath3k_load_fwfile(struct usb_device *udev, 178 static int ath3k_load_fwfile(struct usb_device *udev,
177 const struct firmware *firmware) 179 const struct firmware *firmware)
178 { 180 {
179 u8 *send_buf; 181 u8 *send_buf;
180 int err, pipe, len, size, count, sent = 0; 182 int err, pipe, len, size, count, sent = 0;
181 int ret; 183 int ret;
182 184
183 count = firmware->size; 185 count = firmware->size;
184 186
185 send_buf = kmalloc(BULK_SIZE, GFP_KERNEL); 187 send_buf = kmalloc(BULK_SIZE, GFP_KERNEL);
186 if (!send_buf) { 188 if (!send_buf) {
187 BT_ERR("Can't allocate memory chunk for firmware"); 189 BT_ERR("Can't allocate memory chunk for firmware");
188 return -ENOMEM; 190 return -ENOMEM;
189 } 191 }
190 192
191 size = min_t(uint, count, FW_HDR_SIZE); 193 size = min_t(uint, count, FW_HDR_SIZE);
192 memcpy(send_buf, firmware->data, size); 194 memcpy(send_buf, firmware->data, size);
193 195
194 pipe = usb_sndctrlpipe(udev, 0); 196 pipe = usb_sndctrlpipe(udev, 0);
195 ret = usb_control_msg(udev, pipe, ATH3K_DNLOAD, 197 ret = usb_control_msg(udev, pipe, ATH3K_DNLOAD,
196 USB_TYPE_VENDOR, 0, 0, send_buf, 198 USB_TYPE_VENDOR, 0, 0, send_buf,
197 size, USB_CTRL_SET_TIMEOUT); 199 size, USB_CTRL_SET_TIMEOUT);
198 if (ret < 0) { 200 if (ret < 0) {
199 BT_ERR("Can't change to loading configuration err"); 201 BT_ERR("Can't change to loading configuration err");
200 kfree(send_buf); 202 kfree(send_buf);
201 return ret; 203 return ret;
202 } 204 }
203 205
204 sent += size; 206 sent += size;
205 count -= size; 207 count -= size;
206 208
207 while (count) { 209 while (count) {
208 size = min_t(uint, count, BULK_SIZE); 210 size = min_t(uint, count, BULK_SIZE);
209 pipe = usb_sndbulkpipe(udev, 0x02); 211 pipe = usb_sndbulkpipe(udev, 0x02);
210 212
211 memcpy(send_buf, firmware->data + sent, size); 213 memcpy(send_buf, firmware->data + sent, size);
212 214
213 err = usb_bulk_msg(udev, pipe, send_buf, size, 215 err = usb_bulk_msg(udev, pipe, send_buf, size,
214 &len, 3000); 216 &len, 3000);
215 if (err || (len != size)) { 217 if (err || (len != size)) {
216 BT_ERR("Error in firmware loading err = %d," 218 BT_ERR("Error in firmware loading err = %d,"
217 "len = %d, size = %d", err, len, size); 219 "len = %d, size = %d", err, len, size);
218 kfree(send_buf); 220 kfree(send_buf);
219 return err; 221 return err;
220 } 222 }
221 sent += size; 223 sent += size;
222 count -= size; 224 count -= size;
223 } 225 }
224 226
225 kfree(send_buf); 227 kfree(send_buf);
226 return 0; 228 return 0;
227 } 229 }
228 230
229 static int ath3k_switch_pid(struct usb_device *udev) 231 static int ath3k_switch_pid(struct usb_device *udev)
230 { 232 {
231 int pipe = 0; 233 int pipe = 0;
232 234
233 pipe = usb_sndctrlpipe(udev, 0); 235 pipe = usb_sndctrlpipe(udev, 0);
234 return usb_control_msg(udev, pipe, USB_REG_SWITCH_VID_PID, 236 return usb_control_msg(udev, pipe, USB_REG_SWITCH_VID_PID,
235 USB_TYPE_VENDOR, 0, 0, 237 USB_TYPE_VENDOR, 0, 0,
236 NULL, 0, USB_CTRL_SET_TIMEOUT); 238 NULL, 0, USB_CTRL_SET_TIMEOUT);
237 } 239 }
238 240
239 static int ath3k_set_normal_mode(struct usb_device *udev) 241 static int ath3k_set_normal_mode(struct usb_device *udev)
240 { 242 {
241 unsigned char fw_state; 243 unsigned char fw_state;
242 int pipe = 0, ret; 244 int pipe = 0, ret;
243 245
244 ret = ath3k_get_state(udev, &fw_state); 246 ret = ath3k_get_state(udev, &fw_state);
245 if (ret < 0) { 247 if (ret < 0) {
246 BT_ERR("Can't get state to change to normal mode err"); 248 BT_ERR("Can't get state to change to normal mode err");
247 return ret; 249 return ret;
248 } 250 }
249 251
250 if ((fw_state & ATH3K_MODE_MASK) == ATH3K_NORMAL_MODE) { 252 if ((fw_state & ATH3K_MODE_MASK) == ATH3K_NORMAL_MODE) {
251 BT_DBG("firmware was already in normal mode"); 253 BT_DBG("firmware was already in normal mode");
252 return 0; 254 return 0;
253 } 255 }
254 256
255 pipe = usb_sndctrlpipe(udev, 0); 257 pipe = usb_sndctrlpipe(udev, 0);
256 return usb_control_msg(udev, pipe, ATH3K_SET_NORMAL_MODE, 258 return usb_control_msg(udev, pipe, ATH3K_SET_NORMAL_MODE,
257 USB_TYPE_VENDOR, 0, 0, 259 USB_TYPE_VENDOR, 0, 0,
258 NULL, 0, USB_CTRL_SET_TIMEOUT); 260 NULL, 0, USB_CTRL_SET_TIMEOUT);
259 } 261 }
260 262
261 static int ath3k_load_patch(struct usb_device *udev) 263 static int ath3k_load_patch(struct usb_device *udev)
262 { 264 {
263 unsigned char fw_state; 265 unsigned char fw_state;
264 char filename[ATH3K_NAME_LEN] = {0}; 266 char filename[ATH3K_NAME_LEN] = {0};
265 const struct firmware *firmware; 267 const struct firmware *firmware;
266 struct ath3k_version fw_version, pt_version; 268 struct ath3k_version fw_version, pt_version;
267 int ret; 269 int ret;
268 270
269 ret = ath3k_get_state(udev, &fw_state); 271 ret = ath3k_get_state(udev, &fw_state);
270 if (ret < 0) { 272 if (ret < 0) {
271 BT_ERR("Can't get state to change to load ram patch err"); 273 BT_ERR("Can't get state to change to load ram patch err");
272 return ret; 274 return ret;
273 } 275 }
274 276
275 if (fw_state & ATH3K_PATCH_UPDATE) { 277 if (fw_state & ATH3K_PATCH_UPDATE) {
276 BT_DBG("Patch was already downloaded"); 278 BT_DBG("Patch was already downloaded");
277 return 0; 279 return 0;
278 } 280 }
279 281
280 ret = ath3k_get_version(udev, &fw_version); 282 ret = ath3k_get_version(udev, &fw_version);
281 if (ret < 0) { 283 if (ret < 0) {
282 BT_ERR("Can't get version to change to load ram patch err"); 284 BT_ERR("Can't get version to change to load ram patch err");
283 return ret; 285 return ret;
284 } 286 }
285 287
286 snprintf(filename, ATH3K_NAME_LEN, "ar3k/AthrBT_0x%08x.dfu", 288 snprintf(filename, ATH3K_NAME_LEN, "ar3k/AthrBT_0x%08x.dfu",
287 fw_version.rom_version); 289 fw_version.rom_version);
288 290
289 ret = request_firmware(&firmware, filename, &udev->dev); 291 ret = request_firmware(&firmware, filename, &udev->dev);
290 if (ret < 0) { 292 if (ret < 0) {
291 BT_ERR("Patch file not found %s", filename); 293 BT_ERR("Patch file not found %s", filename);
292 return ret; 294 return ret;
293 } 295 }
294 296
295 pt_version.rom_version = *(int *)(firmware->data + firmware->size - 8); 297 pt_version.rom_version = *(int *)(firmware->data + firmware->size - 8);
296 pt_version.build_version = *(int *) 298 pt_version.build_version = *(int *)
297 (firmware->data + firmware->size - 4); 299 (firmware->data + firmware->size - 4);
298 300
299 if ((pt_version.rom_version != fw_version.rom_version) || 301 if ((pt_version.rom_version != fw_version.rom_version) ||
300 (pt_version.build_version <= fw_version.build_version)) { 302 (pt_version.build_version <= fw_version.build_version)) {
301 BT_ERR("Patch file version did not match with firmware"); 303 BT_ERR("Patch file version did not match with firmware");
302 release_firmware(firmware); 304 release_firmware(firmware);
303 return -EINVAL; 305 return -EINVAL;
304 } 306 }
305 307
306 ret = ath3k_load_fwfile(udev, firmware); 308 ret = ath3k_load_fwfile(udev, firmware);
307 release_firmware(firmware); 309 release_firmware(firmware);
308 310
309 return ret; 311 return ret;
310 } 312 }
311 313
312 static int ath3k_load_syscfg(struct usb_device *udev) 314 static int ath3k_load_syscfg(struct usb_device *udev)
313 { 315 {
314 unsigned char fw_state; 316 unsigned char fw_state;
315 char filename[ATH3K_NAME_LEN] = {0}; 317 char filename[ATH3K_NAME_LEN] = {0};
316 const struct firmware *firmware; 318 const struct firmware *firmware;
317 struct ath3k_version fw_version; 319 struct ath3k_version fw_version;
318 int clk_value, ret; 320 int clk_value, ret;
319 321
320 ret = ath3k_get_state(udev, &fw_state); 322 ret = ath3k_get_state(udev, &fw_state);
321 if (ret < 0) { 323 if (ret < 0) {
322 BT_ERR("Can't get state to change to load configration err"); 324 BT_ERR("Can't get state to change to load configration err");
323 return -EBUSY; 325 return -EBUSY;
324 } 326 }
325 327
326 ret = ath3k_get_version(udev, &fw_version); 328 ret = ath3k_get_version(udev, &fw_version);
327 if (ret < 0) { 329 if (ret < 0) {
328 BT_ERR("Can't get version to change to load ram patch err"); 330 BT_ERR("Can't get version to change to load ram patch err");
329 return ret; 331 return ret;
330 } 332 }
331 333
332 switch (fw_version.ref_clock) { 334 switch (fw_version.ref_clock) {
333 335
334 case ATH3K_XTAL_FREQ_26M: 336 case ATH3K_XTAL_FREQ_26M:
335 clk_value = 26; 337 clk_value = 26;
336 break; 338 break;
337 case ATH3K_XTAL_FREQ_40M: 339 case ATH3K_XTAL_FREQ_40M:
338 clk_value = 40; 340 clk_value = 40;
339 break; 341 break;
340 case ATH3K_XTAL_FREQ_19P2: 342 case ATH3K_XTAL_FREQ_19P2:
341 clk_value = 19; 343 clk_value = 19;
342 break; 344 break;
343 default: 345 default:
344 clk_value = 0; 346 clk_value = 0;
345 break; 347 break;
346 } 348 }
347 349
348 snprintf(filename, ATH3K_NAME_LEN, "ar3k/ramps_0x%08x_%d%s", 350 snprintf(filename, ATH3K_NAME_LEN, "ar3k/ramps_0x%08x_%d%s",
349 fw_version.rom_version, clk_value, ".dfu"); 351 fw_version.rom_version, clk_value, ".dfu");
350 352
351 ret = request_firmware(&firmware, filename, &udev->dev); 353 ret = request_firmware(&firmware, filename, &udev->dev);
352 if (ret < 0) { 354 if (ret < 0) {
353 BT_ERR("Configuration file not found %s", filename); 355 BT_ERR("Configuration file not found %s", filename);
354 return ret; 356 return ret;
355 } 357 }
356 358
357 ret = ath3k_load_fwfile(udev, firmware); 359 ret = ath3k_load_fwfile(udev, firmware);
358 release_firmware(firmware); 360 release_firmware(firmware);
359 361
360 return ret; 362 return ret;
361 } 363 }
362 364
363 static int ath3k_probe(struct usb_interface *intf, 365 static int ath3k_probe(struct usb_interface *intf,
364 const struct usb_device_id *id) 366 const struct usb_device_id *id)
365 { 367 {
366 const struct firmware *firmware; 368 const struct firmware *firmware;
367 struct usb_device *udev = interface_to_usbdev(intf); 369 struct usb_device *udev = interface_to_usbdev(intf);
368 int ret; 370 int ret;
369 371
370 BT_DBG("intf %p id %p", intf, id); 372 BT_DBG("intf %p id %p", intf, id);
371 373
372 if (intf->cur_altsetting->desc.bInterfaceNumber != 0) 374 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
373 return -ENODEV; 375 return -ENODEV;
374 376
375 /* match device ID in ath3k blacklist table */ 377 /* match device ID in ath3k blacklist table */
376 if (!id->driver_info) { 378 if (!id->driver_info) {
377 const struct usb_device_id *match; 379 const struct usb_device_id *match;
378 match = usb_match_id(intf, ath3k_blist_tbl); 380 match = usb_match_id(intf, ath3k_blist_tbl);
379 if (match) 381 if (match)
380 id = match; 382 id = match;
381 } 383 }
382 384
383 /* load patch and sysconfig files for AR3012 */ 385 /* load patch and sysconfig files for AR3012 */
384 if (id->driver_info & BTUSB_ATH3012) { 386 if (id->driver_info & BTUSB_ATH3012) {
385 387
386 /* New firmware with patch and sysconfig files already loaded */ 388 /* New firmware with patch and sysconfig files already loaded */
387 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x0001) 389 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x0001)
388 return -ENODEV; 390 return -ENODEV;
389 391
390 ret = ath3k_load_patch(udev); 392 ret = ath3k_load_patch(udev);
391 if (ret < 0) { 393 if (ret < 0) {
392 BT_ERR("Loading patch file failed"); 394 BT_ERR("Loading patch file failed");
393 return ret; 395 return ret;
394 } 396 }
395 ret = ath3k_load_syscfg(udev); 397 ret = ath3k_load_syscfg(udev);
396 if (ret < 0) { 398 if (ret < 0) {
397 BT_ERR("Loading sysconfig file failed"); 399 BT_ERR("Loading sysconfig file failed");
398 return ret; 400 return ret;
399 } 401 }
400 ret = ath3k_set_normal_mode(udev); 402 ret = ath3k_set_normal_mode(udev);
401 if (ret < 0) { 403 if (ret < 0) {
402 BT_ERR("Set normal mode failed"); 404 BT_ERR("Set normal mode failed");
403 return ret; 405 return ret;
404 } 406 }
405 ath3k_switch_pid(udev); 407 ath3k_switch_pid(udev);
406 return 0; 408 return 0;
407 } 409 }
408 410
409 ret = request_firmware(&firmware, ATH3K_FIRMWARE, &udev->dev); 411 ret = request_firmware(&firmware, ATH3K_FIRMWARE, &udev->dev);
410 if (ret < 0) { 412 if (ret < 0) {
411 if (ret == -ENOENT) 413 if (ret == -ENOENT)
412 BT_ERR("Firmware file \"%s\" not found", 414 BT_ERR("Firmware file \"%s\" not found",
413 ATH3K_FIRMWARE); 415 ATH3K_FIRMWARE);
414 else 416 else
415 BT_ERR("Firmware file \"%s\" request failed (err=%d)", 417 BT_ERR("Firmware file \"%s\" request failed (err=%d)",
416 ATH3K_FIRMWARE, ret); 418 ATH3K_FIRMWARE, ret);
417 return ret; 419 return ret;
418 } 420 }
419 421
420 ret = ath3k_load_firmware(udev, firmware); 422 ret = ath3k_load_firmware(udev, firmware);
421 release_firmware(firmware); 423 release_firmware(firmware);
422 424
423 return ret; 425 return ret;
424 } 426 }
425 427
426 static void ath3k_disconnect(struct usb_interface *intf) 428 static void ath3k_disconnect(struct usb_interface *intf)
427 { 429 {
428 BT_DBG("ath3k_disconnect intf %p", intf); 430 BT_DBG("ath3k_disconnect intf %p", intf);
429 } 431 }
430 432
431 static struct usb_driver ath3k_driver = { 433 static struct usb_driver ath3k_driver = {
432 .name = "ath3k", 434 .name = "ath3k",
433 .probe = ath3k_probe, 435 .probe = ath3k_probe,
434 .disconnect = ath3k_disconnect, 436 .disconnect = ath3k_disconnect,
435 .id_table = ath3k_table, 437 .id_table = ath3k_table,
436 }; 438 };
437 439
438 module_usb_driver(ath3k_driver); 440 module_usb_driver(ath3k_driver);
439 441
440 MODULE_AUTHOR("Atheros Communications"); 442 MODULE_AUTHOR("Atheros Communications");
441 MODULE_DESCRIPTION("Atheros AR30xx firmware driver"); 443 MODULE_DESCRIPTION("Atheros AR30xx firmware driver");
442 MODULE_VERSION(VERSION); 444 MODULE_VERSION(VERSION);
443 MODULE_LICENSE("GPL"); 445 MODULE_LICENSE("GPL");
444 MODULE_FIRMWARE(ATH3K_FIRMWARE); 446 MODULE_FIRMWARE(ATH3K_FIRMWARE);
445 447
drivers/bluetooth/btusb.c
1 /* 1 /*
2 * 2 *
3 * Generic Bluetooth USB driver 3 * Generic Bluetooth USB driver
4 * 4 *
5 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org> 5 * Copyright (C) 2005-2008 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
9 * it under the terms of the GNU General Public License as published by 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 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 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 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 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * 21 *
22 */ 22 */
23 23
24 #include <linux/kernel.h> 24 #include <linux/kernel.h>
25 #include <linux/module.h> 25 #include <linux/module.h>
26 #include <linux/init.h> 26 #include <linux/init.h>
27 #include <linux/slab.h> 27 #include <linux/slab.h>
28 #include <linux/types.h> 28 #include <linux/types.h>
29 #include <linux/sched.h> 29 #include <linux/sched.h>
30 #include <linux/errno.h> 30 #include <linux/errno.h>
31 #include <linux/skbuff.h> 31 #include <linux/skbuff.h>
32 32
33 #include <linux/usb.h> 33 #include <linux/usb.h>
34 34
35 #include <net/bluetooth/bluetooth.h> 35 #include <net/bluetooth/bluetooth.h>
36 #include <net/bluetooth/hci_core.h> 36 #include <net/bluetooth/hci_core.h>
37 37
38 #define VERSION "0.6" 38 #define VERSION "0.6"
39 39
40 static bool ignore_dga; 40 static bool ignore_dga;
41 static bool ignore_csr; 41 static bool ignore_csr;
42 static bool ignore_sniffer; 42 static bool ignore_sniffer;
43 static bool disable_scofix; 43 static bool disable_scofix;
44 static bool force_scofix; 44 static bool force_scofix;
45 45
46 static bool reset = 1; 46 static bool reset = 1;
47 47
48 static struct usb_driver btusb_driver; 48 static struct usb_driver btusb_driver;
49 49
50 #define BTUSB_IGNORE 0x01 50 #define BTUSB_IGNORE 0x01
51 #define BTUSB_DIGIANSWER 0x02 51 #define BTUSB_DIGIANSWER 0x02
52 #define BTUSB_CSR 0x04 52 #define BTUSB_CSR 0x04
53 #define BTUSB_SNIFFER 0x08 53 #define BTUSB_SNIFFER 0x08
54 #define BTUSB_BCM92035 0x10 54 #define BTUSB_BCM92035 0x10
55 #define BTUSB_BROKEN_ISOC 0x20 55 #define BTUSB_BROKEN_ISOC 0x20
56 #define BTUSB_WRONG_SCO_MTU 0x40 56 #define BTUSB_WRONG_SCO_MTU 0x40
57 #define BTUSB_ATH3012 0x80 57 #define BTUSB_ATH3012 0x80
58 58
59 static struct usb_device_id btusb_table[] = { 59 static struct usb_device_id btusb_table[] = {
60 /* Generic Bluetooth USB device */ 60 /* Generic Bluetooth USB device */
61 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, 61 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
62 62
63 /* Broadcom SoftSailing reporting vendor specific */ 63 /* Broadcom SoftSailing reporting vendor specific */
64 { USB_DEVICE(0x05ac, 0x21e1) }, 64 { USB_DEVICE(0x05ac, 0x21e1) },
65 65
66 /* Apple MacBookPro 7,1 */ 66 /* Apple MacBookPro 7,1 */
67 { USB_DEVICE(0x05ac, 0x8213) }, 67 { USB_DEVICE(0x05ac, 0x8213) },
68 68
69 /* Apple iMac11,1 */ 69 /* Apple iMac11,1 */
70 { USB_DEVICE(0x05ac, 0x8215) }, 70 { USB_DEVICE(0x05ac, 0x8215) },
71 71
72 /* Apple MacBookPro6,2 */ 72 /* Apple MacBookPro6,2 */
73 { USB_DEVICE(0x05ac, 0x8218) }, 73 { USB_DEVICE(0x05ac, 0x8218) },
74 74
75 /* Apple MacBookAir3,1, MacBookAir3,2 */ 75 /* Apple MacBookAir3,1, MacBookAir3,2 */
76 { USB_DEVICE(0x05ac, 0x821b) }, 76 { USB_DEVICE(0x05ac, 0x821b) },
77 77
78 /* Apple MacBookAir4,1 */ 78 /* Apple MacBookAir4,1 */
79 { USB_DEVICE(0x05ac, 0x821f) }, 79 { USB_DEVICE(0x05ac, 0x821f) },
80 80
81 /* Apple MacBookPro8,2 */ 81 /* Apple MacBookPro8,2 */
82 { USB_DEVICE(0x05ac, 0x821a) }, 82 { USB_DEVICE(0x05ac, 0x821a) },
83 83
84 /* Apple MacMini5,1 */ 84 /* Apple MacMini5,1 */
85 { USB_DEVICE(0x05ac, 0x8281) }, 85 { USB_DEVICE(0x05ac, 0x8281) },
86 86
87 /* AVM BlueFRITZ! USB v2.0 */ 87 /* AVM BlueFRITZ! USB v2.0 */
88 { USB_DEVICE(0x057c, 0x3800) }, 88 { USB_DEVICE(0x057c, 0x3800) },
89 89
90 /* Bluetooth Ultraport Module from IBM */ 90 /* Bluetooth Ultraport Module from IBM */
91 { USB_DEVICE(0x04bf, 0x030a) }, 91 { USB_DEVICE(0x04bf, 0x030a) },
92 92
93 /* ALPS Modules with non-standard id */ 93 /* ALPS Modules with non-standard id */
94 { USB_DEVICE(0x044e, 0x3001) }, 94 { USB_DEVICE(0x044e, 0x3001) },
95 { USB_DEVICE(0x044e, 0x3002) }, 95 { USB_DEVICE(0x044e, 0x3002) },
96 96
97 /* Ericsson with non-standard id */ 97 /* Ericsson with non-standard id */
98 { USB_DEVICE(0x0bdb, 0x1002) }, 98 { USB_DEVICE(0x0bdb, 0x1002) },
99 99
100 /* Canyon CN-BTU1 with HID interfaces */ 100 /* Canyon CN-BTU1 with HID interfaces */
101 { USB_DEVICE(0x0c10, 0x0000) }, 101 { USB_DEVICE(0x0c10, 0x0000) },
102 102
103 /* Broadcom BCM20702A0 */ 103 /* Broadcom BCM20702A0 */
104 { USB_DEVICE(0x0a5c, 0x21e3) }, 104 { USB_DEVICE(0x0a5c, 0x21e3) },
105 { USB_DEVICE(0x0a5c, 0x21e6) }, 105 { USB_DEVICE(0x0a5c, 0x21e6) },
106 { USB_DEVICE(0x0a5c, 0x21e8) }, 106 { USB_DEVICE(0x0a5c, 0x21e8) },
107 { USB_DEVICE(0x0a5c, 0x21f3) }, 107 { USB_DEVICE(0x0a5c, 0x21f3) },
108 { USB_DEVICE(0x413c, 0x8197) }, 108 { USB_DEVICE(0x413c, 0x8197) },
109 109
110 { } /* Terminating entry */ 110 { } /* Terminating entry */
111 }; 111 };
112 112
113 MODULE_DEVICE_TABLE(usb, btusb_table); 113 MODULE_DEVICE_TABLE(usb, btusb_table);
114 114
115 static struct usb_device_id blacklist_table[] = { 115 static struct usb_device_id blacklist_table[] = {
116 /* CSR BlueCore devices */ 116 /* CSR BlueCore devices */
117 { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR }, 117 { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
118 118
119 /* Broadcom BCM2033 without firmware */ 119 /* Broadcom BCM2033 without firmware */
120 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE }, 120 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
121 121
122 /* Atheros 3011 with sflash firmware */ 122 /* Atheros 3011 with sflash firmware */
123 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE }, 123 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
124 { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE }, 124 { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE },
125 { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE }, 125 { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE },
126 { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE }, 126 { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE },
127 127
128 /* Atheros AR9285 Malbec with sflash firmware */ 128 /* Atheros AR9285 Malbec with sflash firmware */
129 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE }, 129 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
130 130
131 /* Atheros 3012 with sflash firmware */ 131 /* Atheros 3012 with sflash firmware */
132 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, 132 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
133 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 }, 133 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
134 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 134 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
135 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
135 136
136 /* Atheros AR5BBU12 with sflash firmware */ 137 /* Atheros AR5BBU12 with sflash firmware */
137 { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE }, 138 { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
138 139
139 /* Broadcom BCM2035 */ 140 /* Broadcom BCM2035 */
140 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, 141 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
141 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU }, 142 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
142 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 }, 143 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
143 144
144 /* Broadcom BCM2045 */ 145 /* Broadcom BCM2045 */
145 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU }, 146 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
146 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU }, 147 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
147 148
148 /* IBM/Lenovo ThinkPad with Broadcom chip */ 149 /* IBM/Lenovo ThinkPad with Broadcom chip */
149 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU }, 150 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
150 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU }, 151 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
151 152
152 /* HP laptop with Broadcom chip */ 153 /* HP laptop with Broadcom chip */
153 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU }, 154 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
154 155
155 /* Dell laptop with Broadcom chip */ 156 /* Dell laptop with Broadcom chip */
156 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU }, 157 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
157 158
158 /* Dell Wireless 370 and 410 devices */ 159 /* Dell Wireless 370 and 410 devices */
159 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU }, 160 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
160 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU }, 161 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
161 162
162 /* Belkin F8T012 and F8T013 devices */ 163 /* Belkin F8T012 and F8T013 devices */
163 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU }, 164 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
164 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU }, 165 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
165 166
166 /* Asus WL-BTD202 device */ 167 /* Asus WL-BTD202 device */
167 { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU }, 168 { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
168 169
169 /* Kensington Bluetooth USB adapter */ 170 /* Kensington Bluetooth USB adapter */
170 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU }, 171 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
171 172
172 /* RTX Telecom based adapters with buggy SCO support */ 173 /* RTX Telecom based adapters with buggy SCO support */
173 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC }, 174 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
174 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC }, 175 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
175 176
176 /* CONWISE Technology based adapters with buggy SCO support */ 177 /* CONWISE Technology based adapters with buggy SCO support */
177 { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC }, 178 { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
178 179
179 /* Digianswer devices */ 180 /* Digianswer devices */
180 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER }, 181 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
181 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE }, 182 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
182 183
183 /* CSR BlueCore Bluetooth Sniffer */ 184 /* CSR BlueCore Bluetooth Sniffer */
184 { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER }, 185 { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER },
185 186
186 /* Frontline ComProbe Bluetooth Sniffer */ 187 /* Frontline ComProbe Bluetooth Sniffer */
187 { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER }, 188 { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
188 189
189 { } /* Terminating entry */ 190 { } /* Terminating entry */
190 }; 191 };
191 192
192 #define BTUSB_MAX_ISOC_FRAMES 10 193 #define BTUSB_MAX_ISOC_FRAMES 10
193 194
194 #define BTUSB_INTR_RUNNING 0 195 #define BTUSB_INTR_RUNNING 0
195 #define BTUSB_BULK_RUNNING 1 196 #define BTUSB_BULK_RUNNING 1
196 #define BTUSB_ISOC_RUNNING 2 197 #define BTUSB_ISOC_RUNNING 2
197 #define BTUSB_SUSPENDING 3 198 #define BTUSB_SUSPENDING 3
198 #define BTUSB_DID_ISO_RESUME 4 199 #define BTUSB_DID_ISO_RESUME 4
199 200
200 struct btusb_data { 201 struct btusb_data {
201 struct hci_dev *hdev; 202 struct hci_dev *hdev;
202 struct usb_device *udev; 203 struct usb_device *udev;
203 struct usb_interface *intf; 204 struct usb_interface *intf;
204 struct usb_interface *isoc; 205 struct usb_interface *isoc;
205 206
206 spinlock_t lock; 207 spinlock_t lock;
207 208
208 unsigned long flags; 209 unsigned long flags;
209 210
210 struct work_struct work; 211 struct work_struct work;
211 struct work_struct waker; 212 struct work_struct waker;
212 213
213 struct usb_anchor tx_anchor; 214 struct usb_anchor tx_anchor;
214 struct usb_anchor intr_anchor; 215 struct usb_anchor intr_anchor;
215 struct usb_anchor bulk_anchor; 216 struct usb_anchor bulk_anchor;
216 struct usb_anchor isoc_anchor; 217 struct usb_anchor isoc_anchor;
217 struct usb_anchor deferred; 218 struct usb_anchor deferred;
218 int tx_in_flight; 219 int tx_in_flight;
219 spinlock_t txlock; 220 spinlock_t txlock;
220 221
221 struct usb_endpoint_descriptor *intr_ep; 222 struct usb_endpoint_descriptor *intr_ep;
222 struct usb_endpoint_descriptor *bulk_tx_ep; 223 struct usb_endpoint_descriptor *bulk_tx_ep;
223 struct usb_endpoint_descriptor *bulk_rx_ep; 224 struct usb_endpoint_descriptor *bulk_rx_ep;
224 struct usb_endpoint_descriptor *isoc_tx_ep; 225 struct usb_endpoint_descriptor *isoc_tx_ep;
225 struct usb_endpoint_descriptor *isoc_rx_ep; 226 struct usb_endpoint_descriptor *isoc_rx_ep;
226 227
227 __u8 cmdreq_type; 228 __u8 cmdreq_type;
228 229
229 unsigned int sco_num; 230 unsigned int sco_num;
230 int isoc_altsetting; 231 int isoc_altsetting;
231 int suspend_count; 232 int suspend_count;
232 }; 233 };
233 234
234 static int inc_tx(struct btusb_data *data) 235 static int inc_tx(struct btusb_data *data)
235 { 236 {
236 unsigned long flags; 237 unsigned long flags;
237 int rv; 238 int rv;
238 239
239 spin_lock_irqsave(&data->txlock, flags); 240 spin_lock_irqsave(&data->txlock, flags);
240 rv = test_bit(BTUSB_SUSPENDING, &data->flags); 241 rv = test_bit(BTUSB_SUSPENDING, &data->flags);
241 if (!rv) 242 if (!rv)
242 data->tx_in_flight++; 243 data->tx_in_flight++;
243 spin_unlock_irqrestore(&data->txlock, flags); 244 spin_unlock_irqrestore(&data->txlock, flags);
244 245
245 return rv; 246 return rv;
246 } 247 }
247 248
248 static void btusb_intr_complete(struct urb *urb) 249 static void btusb_intr_complete(struct urb *urb)
249 { 250 {
250 struct hci_dev *hdev = urb->context; 251 struct hci_dev *hdev = urb->context;
251 struct btusb_data *data = hci_get_drvdata(hdev); 252 struct btusb_data *data = hci_get_drvdata(hdev);
252 int err; 253 int err;
253 254
254 BT_DBG("%s urb %p status %d count %d", hdev->name, 255 BT_DBG("%s urb %p status %d count %d", hdev->name,
255 urb, urb->status, urb->actual_length); 256 urb, urb->status, urb->actual_length);
256 257
257 if (!test_bit(HCI_RUNNING, &hdev->flags)) 258 if (!test_bit(HCI_RUNNING, &hdev->flags))
258 return; 259 return;
259 260
260 if (urb->status == 0) { 261 if (urb->status == 0) {
261 hdev->stat.byte_rx += urb->actual_length; 262 hdev->stat.byte_rx += urb->actual_length;
262 263
263 if (hci_recv_fragment(hdev, HCI_EVENT_PKT, 264 if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
264 urb->transfer_buffer, 265 urb->transfer_buffer,
265 urb->actual_length) < 0) { 266 urb->actual_length) < 0) {
266 BT_ERR("%s corrupted event packet", hdev->name); 267 BT_ERR("%s corrupted event packet", hdev->name);
267 hdev->stat.err_rx++; 268 hdev->stat.err_rx++;
268 } 269 }
269 } 270 }
270 271
271 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags)) 272 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
272 return; 273 return;
273 274
274 usb_mark_last_busy(data->udev); 275 usb_mark_last_busy(data->udev);
275 usb_anchor_urb(urb, &data->intr_anchor); 276 usb_anchor_urb(urb, &data->intr_anchor);
276 277
277 err = usb_submit_urb(urb, GFP_ATOMIC); 278 err = usb_submit_urb(urb, GFP_ATOMIC);
278 if (err < 0) { 279 if (err < 0) {
279 /* -EPERM: urb is being killed; 280 /* -EPERM: urb is being killed;
280 * -ENODEV: device got disconnected */ 281 * -ENODEV: device got disconnected */
281 if (err != -EPERM && err != -ENODEV) 282 if (err != -EPERM && err != -ENODEV)
282 BT_ERR("%s urb %p failed to resubmit (%d)", 283 BT_ERR("%s urb %p failed to resubmit (%d)",
283 hdev->name, urb, -err); 284 hdev->name, urb, -err);
284 usb_unanchor_urb(urb); 285 usb_unanchor_urb(urb);
285 } 286 }
286 } 287 }
287 288
288 static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags) 289 static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
289 { 290 {
290 struct btusb_data *data = hci_get_drvdata(hdev); 291 struct btusb_data *data = hci_get_drvdata(hdev);
291 struct urb *urb; 292 struct urb *urb;
292 unsigned char *buf; 293 unsigned char *buf;
293 unsigned int pipe; 294 unsigned int pipe;
294 int err, size; 295 int err, size;
295 296
296 BT_DBG("%s", hdev->name); 297 BT_DBG("%s", hdev->name);
297 298
298 if (!data->intr_ep) 299 if (!data->intr_ep)
299 return -ENODEV; 300 return -ENODEV;
300 301
301 urb = usb_alloc_urb(0, mem_flags); 302 urb = usb_alloc_urb(0, mem_flags);
302 if (!urb) 303 if (!urb)
303 return -ENOMEM; 304 return -ENOMEM;
304 305
305 size = le16_to_cpu(data->intr_ep->wMaxPacketSize); 306 size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
306 307
307 buf = kmalloc(size, mem_flags); 308 buf = kmalloc(size, mem_flags);
308 if (!buf) { 309 if (!buf) {
309 usb_free_urb(urb); 310 usb_free_urb(urb);
310 return -ENOMEM; 311 return -ENOMEM;
311 } 312 }
312 313
313 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress); 314 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
314 315
315 usb_fill_int_urb(urb, data->udev, pipe, buf, size, 316 usb_fill_int_urb(urb, data->udev, pipe, buf, size,
316 btusb_intr_complete, hdev, 317 btusb_intr_complete, hdev,
317 data->intr_ep->bInterval); 318 data->intr_ep->bInterval);
318 319
319 urb->transfer_flags |= URB_FREE_BUFFER; 320 urb->transfer_flags |= URB_FREE_BUFFER;
320 321
321 usb_anchor_urb(urb, &data->intr_anchor); 322 usb_anchor_urb(urb, &data->intr_anchor);
322 323
323 err = usb_submit_urb(urb, mem_flags); 324 err = usb_submit_urb(urb, mem_flags);
324 if (err < 0) { 325 if (err < 0) {
325 if (err != -EPERM && err != -ENODEV) 326 if (err != -EPERM && err != -ENODEV)
326 BT_ERR("%s urb %p submission failed (%d)", 327 BT_ERR("%s urb %p submission failed (%d)",
327 hdev->name, urb, -err); 328 hdev->name, urb, -err);
328 usb_unanchor_urb(urb); 329 usb_unanchor_urb(urb);
329 } 330 }
330 331
331 usb_free_urb(urb); 332 usb_free_urb(urb);
332 333
333 return err; 334 return err;
334 } 335 }
335 336
336 static void btusb_bulk_complete(struct urb *urb) 337 static void btusb_bulk_complete(struct urb *urb)
337 { 338 {
338 struct hci_dev *hdev = urb->context; 339 struct hci_dev *hdev = urb->context;
339 struct btusb_data *data = hci_get_drvdata(hdev); 340 struct btusb_data *data = hci_get_drvdata(hdev);
340 int err; 341 int err;
341 342
342 BT_DBG("%s urb %p status %d count %d", hdev->name, 343 BT_DBG("%s urb %p status %d count %d", hdev->name,
343 urb, urb->status, urb->actual_length); 344 urb, urb->status, urb->actual_length);
344 345
345 if (!test_bit(HCI_RUNNING, &hdev->flags)) 346 if (!test_bit(HCI_RUNNING, &hdev->flags))
346 return; 347 return;
347 348
348 if (urb->status == 0) { 349 if (urb->status == 0) {
349 hdev->stat.byte_rx += urb->actual_length; 350 hdev->stat.byte_rx += urb->actual_length;
350 351
351 if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT, 352 if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
352 urb->transfer_buffer, 353 urb->transfer_buffer,
353 urb->actual_length) < 0) { 354 urb->actual_length) < 0) {
354 BT_ERR("%s corrupted ACL packet", hdev->name); 355 BT_ERR("%s corrupted ACL packet", hdev->name);
355 hdev->stat.err_rx++; 356 hdev->stat.err_rx++;
356 } 357 }
357 } 358 }
358 359
359 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags)) 360 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
360 return; 361 return;
361 362
362 usb_anchor_urb(urb, &data->bulk_anchor); 363 usb_anchor_urb(urb, &data->bulk_anchor);
363 usb_mark_last_busy(data->udev); 364 usb_mark_last_busy(data->udev);
364 365
365 err = usb_submit_urb(urb, GFP_ATOMIC); 366 err = usb_submit_urb(urb, GFP_ATOMIC);
366 if (err < 0) { 367 if (err < 0) {
367 /* -EPERM: urb is being killed; 368 /* -EPERM: urb is being killed;
368 * -ENODEV: device got disconnected */ 369 * -ENODEV: device got disconnected */
369 if (err != -EPERM && err != -ENODEV) 370 if (err != -EPERM && err != -ENODEV)
370 BT_ERR("%s urb %p failed to resubmit (%d)", 371 BT_ERR("%s urb %p failed to resubmit (%d)",
371 hdev->name, urb, -err); 372 hdev->name, urb, -err);
372 usb_unanchor_urb(urb); 373 usb_unanchor_urb(urb);
373 } 374 }
374 } 375 }
375 376
376 static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags) 377 static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
377 { 378 {
378 struct btusb_data *data = hci_get_drvdata(hdev); 379 struct btusb_data *data = hci_get_drvdata(hdev);
379 struct urb *urb; 380 struct urb *urb;
380 unsigned char *buf; 381 unsigned char *buf;
381 unsigned int pipe; 382 unsigned int pipe;
382 int err, size = HCI_MAX_FRAME_SIZE; 383 int err, size = HCI_MAX_FRAME_SIZE;
383 384
384 BT_DBG("%s", hdev->name); 385 BT_DBG("%s", hdev->name);
385 386
386 if (!data->bulk_rx_ep) 387 if (!data->bulk_rx_ep)
387 return -ENODEV; 388 return -ENODEV;
388 389
389 urb = usb_alloc_urb(0, mem_flags); 390 urb = usb_alloc_urb(0, mem_flags);
390 if (!urb) 391 if (!urb)
391 return -ENOMEM; 392 return -ENOMEM;
392 393
393 buf = kmalloc(size, mem_flags); 394 buf = kmalloc(size, mem_flags);
394 if (!buf) { 395 if (!buf) {
395 usb_free_urb(urb); 396 usb_free_urb(urb);
396 return -ENOMEM; 397 return -ENOMEM;
397 } 398 }
398 399
399 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress); 400 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
400 401
401 usb_fill_bulk_urb(urb, data->udev, pipe, 402 usb_fill_bulk_urb(urb, data->udev, pipe,
402 buf, size, btusb_bulk_complete, hdev); 403 buf, size, btusb_bulk_complete, hdev);
403 404
404 urb->transfer_flags |= URB_FREE_BUFFER; 405 urb->transfer_flags |= URB_FREE_BUFFER;
405 406
406 usb_mark_last_busy(data->udev); 407 usb_mark_last_busy(data->udev);
407 usb_anchor_urb(urb, &data->bulk_anchor); 408 usb_anchor_urb(urb, &data->bulk_anchor);
408 409
409 err = usb_submit_urb(urb, mem_flags); 410 err = usb_submit_urb(urb, mem_flags);
410 if (err < 0) { 411 if (err < 0) {
411 if (err != -EPERM && err != -ENODEV) 412 if (err != -EPERM && err != -ENODEV)
412 BT_ERR("%s urb %p submission failed (%d)", 413 BT_ERR("%s urb %p submission failed (%d)",
413 hdev->name, urb, -err); 414 hdev->name, urb, -err);
414 usb_unanchor_urb(urb); 415 usb_unanchor_urb(urb);
415 } 416 }
416 417
417 usb_free_urb(urb); 418 usb_free_urb(urb);
418 419
419 return err; 420 return err;
420 } 421 }
421 422
422 static void btusb_isoc_complete(struct urb *urb) 423 static void btusb_isoc_complete(struct urb *urb)
423 { 424 {
424 struct hci_dev *hdev = urb->context; 425 struct hci_dev *hdev = urb->context;
425 struct btusb_data *data = hci_get_drvdata(hdev); 426 struct btusb_data *data = hci_get_drvdata(hdev);
426 int i, err; 427 int i, err;
427 428
428 BT_DBG("%s urb %p status %d count %d", hdev->name, 429 BT_DBG("%s urb %p status %d count %d", hdev->name,
429 urb, urb->status, urb->actual_length); 430 urb, urb->status, urb->actual_length);
430 431
431 if (!test_bit(HCI_RUNNING, &hdev->flags)) 432 if (!test_bit(HCI_RUNNING, &hdev->flags))
432 return; 433 return;
433 434
434 if (urb->status == 0) { 435 if (urb->status == 0) {
435 for (i = 0; i < urb->number_of_packets; i++) { 436 for (i = 0; i < urb->number_of_packets; i++) {
436 unsigned int offset = urb->iso_frame_desc[i].offset; 437 unsigned int offset = urb->iso_frame_desc[i].offset;
437 unsigned int length = urb->iso_frame_desc[i].actual_length; 438 unsigned int length = urb->iso_frame_desc[i].actual_length;
438 439
439 if (urb->iso_frame_desc[i].status) 440 if (urb->iso_frame_desc[i].status)
440 continue; 441 continue;
441 442
442 hdev->stat.byte_rx += length; 443 hdev->stat.byte_rx += length;
443 444
444 if (hci_recv_fragment(hdev, HCI_SCODATA_PKT, 445 if (hci_recv_fragment(hdev, HCI_SCODATA_PKT,
445 urb->transfer_buffer + offset, 446 urb->transfer_buffer + offset,
446 length) < 0) { 447 length) < 0) {
447 BT_ERR("%s corrupted SCO packet", hdev->name); 448 BT_ERR("%s corrupted SCO packet", hdev->name);
448 hdev->stat.err_rx++; 449 hdev->stat.err_rx++;
449 } 450 }
450 } 451 }
451 } 452 }
452 453
453 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags)) 454 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
454 return; 455 return;
455 456
456 usb_anchor_urb(urb, &data->isoc_anchor); 457 usb_anchor_urb(urb, &data->isoc_anchor);
457 458
458 err = usb_submit_urb(urb, GFP_ATOMIC); 459 err = usb_submit_urb(urb, GFP_ATOMIC);
459 if (err < 0) { 460 if (err < 0) {
460 /* -EPERM: urb is being killed; 461 /* -EPERM: urb is being killed;
461 * -ENODEV: device got disconnected */ 462 * -ENODEV: device got disconnected */
462 if (err != -EPERM && err != -ENODEV) 463 if (err != -EPERM && err != -ENODEV)
463 BT_ERR("%s urb %p failed to resubmit (%d)", 464 BT_ERR("%s urb %p failed to resubmit (%d)",
464 hdev->name, urb, -err); 465 hdev->name, urb, -err);
465 usb_unanchor_urb(urb); 466 usb_unanchor_urb(urb);
466 } 467 }
467 } 468 }
468 469
469 static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu) 470 static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
470 { 471 {
471 int i, offset = 0; 472 int i, offset = 0;
472 473
473 BT_DBG("len %d mtu %d", len, mtu); 474 BT_DBG("len %d mtu %d", len, mtu);
474 475
475 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu; 476 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
476 i++, offset += mtu, len -= mtu) { 477 i++, offset += mtu, len -= mtu) {
477 urb->iso_frame_desc[i].offset = offset; 478 urb->iso_frame_desc[i].offset = offset;
478 urb->iso_frame_desc[i].length = mtu; 479 urb->iso_frame_desc[i].length = mtu;
479 } 480 }
480 481
481 if (len && i < BTUSB_MAX_ISOC_FRAMES) { 482 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
482 urb->iso_frame_desc[i].offset = offset; 483 urb->iso_frame_desc[i].offset = offset;
483 urb->iso_frame_desc[i].length = len; 484 urb->iso_frame_desc[i].length = len;
484 i++; 485 i++;
485 } 486 }
486 487
487 urb->number_of_packets = i; 488 urb->number_of_packets = i;
488 } 489 }
489 490
490 static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags) 491 static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
491 { 492 {
492 struct btusb_data *data = hci_get_drvdata(hdev); 493 struct btusb_data *data = hci_get_drvdata(hdev);
493 struct urb *urb; 494 struct urb *urb;
494 unsigned char *buf; 495 unsigned char *buf;
495 unsigned int pipe; 496 unsigned int pipe;
496 int err, size; 497 int err, size;
497 498
498 BT_DBG("%s", hdev->name); 499 BT_DBG("%s", hdev->name);
499 500
500 if (!data->isoc_rx_ep) 501 if (!data->isoc_rx_ep)
501 return -ENODEV; 502 return -ENODEV;
502 503
503 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags); 504 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
504 if (!urb) 505 if (!urb)
505 return -ENOMEM; 506 return -ENOMEM;
506 507
507 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) * 508 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
508 BTUSB_MAX_ISOC_FRAMES; 509 BTUSB_MAX_ISOC_FRAMES;
509 510
510 buf = kmalloc(size, mem_flags); 511 buf = kmalloc(size, mem_flags);
511 if (!buf) { 512 if (!buf) {
512 usb_free_urb(urb); 513 usb_free_urb(urb);
513 return -ENOMEM; 514 return -ENOMEM;
514 } 515 }
515 516
516 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress); 517 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
517 518
518 usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete, 519 usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete,
519 hdev, data->isoc_rx_ep->bInterval); 520 hdev, data->isoc_rx_ep->bInterval);
520 521
521 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP; 522 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
522 523
523 __fill_isoc_descriptor(urb, size, 524 __fill_isoc_descriptor(urb, size,
524 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize)); 525 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
525 526
526 usb_anchor_urb(urb, &data->isoc_anchor); 527 usb_anchor_urb(urb, &data->isoc_anchor);
527 528
528 err = usb_submit_urb(urb, mem_flags); 529 err = usb_submit_urb(urb, mem_flags);
529 if (err < 0) { 530 if (err < 0) {
530 if (err != -EPERM && err != -ENODEV) 531 if (err != -EPERM && err != -ENODEV)
531 BT_ERR("%s urb %p submission failed (%d)", 532 BT_ERR("%s urb %p submission failed (%d)",
532 hdev->name, urb, -err); 533 hdev->name, urb, -err);
533 usb_unanchor_urb(urb); 534 usb_unanchor_urb(urb);
534 } 535 }
535 536
536 usb_free_urb(urb); 537 usb_free_urb(urb);
537 538
538 return err; 539 return err;
539 } 540 }
540 541
541 static void btusb_tx_complete(struct urb *urb) 542 static void btusb_tx_complete(struct urb *urb)
542 { 543 {
543 struct sk_buff *skb = urb->context; 544 struct sk_buff *skb = urb->context;
544 struct hci_dev *hdev = (struct hci_dev *) skb->dev; 545 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
545 struct btusb_data *data = hci_get_drvdata(hdev); 546 struct btusb_data *data = hci_get_drvdata(hdev);
546 547
547 BT_DBG("%s urb %p status %d count %d", hdev->name, 548 BT_DBG("%s urb %p status %d count %d", hdev->name,
548 urb, urb->status, urb->actual_length); 549 urb, urb->status, urb->actual_length);
549 550
550 if (!test_bit(HCI_RUNNING, &hdev->flags)) 551 if (!test_bit(HCI_RUNNING, &hdev->flags))
551 goto done; 552 goto done;
552 553
553 if (!urb->status) 554 if (!urb->status)
554 hdev->stat.byte_tx += urb->transfer_buffer_length; 555 hdev->stat.byte_tx += urb->transfer_buffer_length;
555 else 556 else
556 hdev->stat.err_tx++; 557 hdev->stat.err_tx++;
557 558
558 done: 559 done:
559 spin_lock(&data->txlock); 560 spin_lock(&data->txlock);
560 data->tx_in_flight--; 561 data->tx_in_flight--;
561 spin_unlock(&data->txlock); 562 spin_unlock(&data->txlock);
562 563
563 kfree(urb->setup_packet); 564 kfree(urb->setup_packet);
564 565
565 kfree_skb(skb); 566 kfree_skb(skb);
566 } 567 }
567 568
568 static void btusb_isoc_tx_complete(struct urb *urb) 569 static void btusb_isoc_tx_complete(struct urb *urb)
569 { 570 {
570 struct sk_buff *skb = urb->context; 571 struct sk_buff *skb = urb->context;
571 struct hci_dev *hdev = (struct hci_dev *) skb->dev; 572 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
572 573
573 BT_DBG("%s urb %p status %d count %d", hdev->name, 574 BT_DBG("%s urb %p status %d count %d", hdev->name,
574 urb, urb->status, urb->actual_length); 575 urb, urb->status, urb->actual_length);
575 576
576 if (!test_bit(HCI_RUNNING, &hdev->flags)) 577 if (!test_bit(HCI_RUNNING, &hdev->flags))
577 goto done; 578 goto done;
578 579
579 if (!urb->status) 580 if (!urb->status)
580 hdev->stat.byte_tx += urb->transfer_buffer_length; 581 hdev->stat.byte_tx += urb->transfer_buffer_length;
581 else 582 else
582 hdev->stat.err_tx++; 583 hdev->stat.err_tx++;
583 584
584 done: 585 done:
585 kfree(urb->setup_packet); 586 kfree(urb->setup_packet);
586 587
587 kfree_skb(skb); 588 kfree_skb(skb);
588 } 589 }
589 590
590 static int btusb_open(struct hci_dev *hdev) 591 static int btusb_open(struct hci_dev *hdev)
591 { 592 {
592 struct btusb_data *data = hci_get_drvdata(hdev); 593 struct btusb_data *data = hci_get_drvdata(hdev);
593 int err; 594 int err;
594 595
595 BT_DBG("%s", hdev->name); 596 BT_DBG("%s", hdev->name);
596 597
597 err = usb_autopm_get_interface(data->intf); 598 err = usb_autopm_get_interface(data->intf);
598 if (err < 0) 599 if (err < 0)
599 return err; 600 return err;
600 601
601 data->intf->needs_remote_wakeup = 1; 602 data->intf->needs_remote_wakeup = 1;
602 603
603 if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) 604 if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
604 goto done; 605 goto done;
605 606
606 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) 607 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
607 goto done; 608 goto done;
608 609
609 err = btusb_submit_intr_urb(hdev, GFP_KERNEL); 610 err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
610 if (err < 0) 611 if (err < 0)
611 goto failed; 612 goto failed;
612 613
613 err = btusb_submit_bulk_urb(hdev, GFP_KERNEL); 614 err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
614 if (err < 0) { 615 if (err < 0) {
615 usb_kill_anchored_urbs(&data->intr_anchor); 616 usb_kill_anchored_urbs(&data->intr_anchor);
616 goto failed; 617 goto failed;
617 } 618 }
618 619
619 set_bit(BTUSB_BULK_RUNNING, &data->flags); 620 set_bit(BTUSB_BULK_RUNNING, &data->flags);
620 btusb_submit_bulk_urb(hdev, GFP_KERNEL); 621 btusb_submit_bulk_urb(hdev, GFP_KERNEL);
621 622
622 done: 623 done:
623 usb_autopm_put_interface(data->intf); 624 usb_autopm_put_interface(data->intf);
624 return 0; 625 return 0;
625 626
626 failed: 627 failed:
627 clear_bit(BTUSB_INTR_RUNNING, &data->flags); 628 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
628 clear_bit(HCI_RUNNING, &hdev->flags); 629 clear_bit(HCI_RUNNING, &hdev->flags);
629 usb_autopm_put_interface(data->intf); 630 usb_autopm_put_interface(data->intf);
630 return err; 631 return err;
631 } 632 }
632 633
633 static void btusb_stop_traffic(struct btusb_data *data) 634 static void btusb_stop_traffic(struct btusb_data *data)
634 { 635 {
635 usb_kill_anchored_urbs(&data->intr_anchor); 636 usb_kill_anchored_urbs(&data->intr_anchor);
636 usb_kill_anchored_urbs(&data->bulk_anchor); 637 usb_kill_anchored_urbs(&data->bulk_anchor);
637 usb_kill_anchored_urbs(&data->isoc_anchor); 638 usb_kill_anchored_urbs(&data->isoc_anchor);
638 } 639 }
639 640
640 static int btusb_close(struct hci_dev *hdev) 641 static int btusb_close(struct hci_dev *hdev)
641 { 642 {
642 struct btusb_data *data = hci_get_drvdata(hdev); 643 struct btusb_data *data = hci_get_drvdata(hdev);
643 int err; 644 int err;
644 645
645 BT_DBG("%s", hdev->name); 646 BT_DBG("%s", hdev->name);
646 647
647 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) 648 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
648 return 0; 649 return 0;
649 650
650 cancel_work_sync(&data->work); 651 cancel_work_sync(&data->work);
651 cancel_work_sync(&data->waker); 652 cancel_work_sync(&data->waker);
652 653
653 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 654 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
654 clear_bit(BTUSB_BULK_RUNNING, &data->flags); 655 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
655 clear_bit(BTUSB_INTR_RUNNING, &data->flags); 656 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
656 657
657 btusb_stop_traffic(data); 658 btusb_stop_traffic(data);
658 err = usb_autopm_get_interface(data->intf); 659 err = usb_autopm_get_interface(data->intf);
659 if (err < 0) 660 if (err < 0)
660 goto failed; 661 goto failed;
661 662
662 data->intf->needs_remote_wakeup = 0; 663 data->intf->needs_remote_wakeup = 0;
663 usb_autopm_put_interface(data->intf); 664 usb_autopm_put_interface(data->intf);
664 665
665 failed: 666 failed:
666 usb_scuttle_anchored_urbs(&data->deferred); 667 usb_scuttle_anchored_urbs(&data->deferred);
667 return 0; 668 return 0;
668 } 669 }
669 670
670 static int btusb_flush(struct hci_dev *hdev) 671 static int btusb_flush(struct hci_dev *hdev)
671 { 672 {
672 struct btusb_data *data = hci_get_drvdata(hdev); 673 struct btusb_data *data = hci_get_drvdata(hdev);
673 674
674 BT_DBG("%s", hdev->name); 675 BT_DBG("%s", hdev->name);
675 676
676 usb_kill_anchored_urbs(&data->tx_anchor); 677 usb_kill_anchored_urbs(&data->tx_anchor);
677 678
678 return 0; 679 return 0;
679 } 680 }
680 681
681 static int btusb_send_frame(struct sk_buff *skb) 682 static int btusb_send_frame(struct sk_buff *skb)
682 { 683 {
683 struct hci_dev *hdev = (struct hci_dev *) skb->dev; 684 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
684 struct btusb_data *data = hci_get_drvdata(hdev); 685 struct btusb_data *data = hci_get_drvdata(hdev);
685 struct usb_ctrlrequest *dr; 686 struct usb_ctrlrequest *dr;
686 struct urb *urb; 687 struct urb *urb;
687 unsigned int pipe; 688 unsigned int pipe;
688 int err; 689 int err;
689 690
690 BT_DBG("%s", hdev->name); 691 BT_DBG("%s", hdev->name);
691 692
692 if (!test_bit(HCI_RUNNING, &hdev->flags)) 693 if (!test_bit(HCI_RUNNING, &hdev->flags))
693 return -EBUSY; 694 return -EBUSY;
694 695
695 switch (bt_cb(skb)->pkt_type) { 696 switch (bt_cb(skb)->pkt_type) {
696 case HCI_COMMAND_PKT: 697 case HCI_COMMAND_PKT:
697 urb = usb_alloc_urb(0, GFP_ATOMIC); 698 urb = usb_alloc_urb(0, GFP_ATOMIC);
698 if (!urb) 699 if (!urb)
699 return -ENOMEM; 700 return -ENOMEM;
700 701
701 dr = kmalloc(sizeof(*dr), GFP_ATOMIC); 702 dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
702 if (!dr) { 703 if (!dr) {
703 usb_free_urb(urb); 704 usb_free_urb(urb);
704 return -ENOMEM; 705 return -ENOMEM;
705 } 706 }
706 707
707 dr->bRequestType = data->cmdreq_type; 708 dr->bRequestType = data->cmdreq_type;
708 dr->bRequest = 0; 709 dr->bRequest = 0;
709 dr->wIndex = 0; 710 dr->wIndex = 0;
710 dr->wValue = 0; 711 dr->wValue = 0;
711 dr->wLength = __cpu_to_le16(skb->len); 712 dr->wLength = __cpu_to_le16(skb->len);
712 713
713 pipe = usb_sndctrlpipe(data->udev, 0x00); 714 pipe = usb_sndctrlpipe(data->udev, 0x00);
714 715
715 usb_fill_control_urb(urb, data->udev, pipe, (void *) dr, 716 usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
716 skb->data, skb->len, btusb_tx_complete, skb); 717 skb->data, skb->len, btusb_tx_complete, skb);
717 718
718 hdev->stat.cmd_tx++; 719 hdev->stat.cmd_tx++;
719 break; 720 break;
720 721
721 case HCI_ACLDATA_PKT: 722 case HCI_ACLDATA_PKT:
722 if (!data->bulk_tx_ep) 723 if (!data->bulk_tx_ep)
723 return -ENODEV; 724 return -ENODEV;
724 725
725 urb = usb_alloc_urb(0, GFP_ATOMIC); 726 urb = usb_alloc_urb(0, GFP_ATOMIC);
726 if (!urb) 727 if (!urb)
727 return -ENOMEM; 728 return -ENOMEM;
728 729
729 pipe = usb_sndbulkpipe(data->udev, 730 pipe = usb_sndbulkpipe(data->udev,
730 data->bulk_tx_ep->bEndpointAddress); 731 data->bulk_tx_ep->bEndpointAddress);
731 732
732 usb_fill_bulk_urb(urb, data->udev, pipe, 733 usb_fill_bulk_urb(urb, data->udev, pipe,
733 skb->data, skb->len, btusb_tx_complete, skb); 734 skb->data, skb->len, btusb_tx_complete, skb);
734 735
735 hdev->stat.acl_tx++; 736 hdev->stat.acl_tx++;
736 break; 737 break;
737 738
738 case HCI_SCODATA_PKT: 739 case HCI_SCODATA_PKT:
739 if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1) 740 if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1)
740 return -ENODEV; 741 return -ENODEV;
741 742
742 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC); 743 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);
743 if (!urb) 744 if (!urb)
744 return -ENOMEM; 745 return -ENOMEM;
745 746
746 pipe = usb_sndisocpipe(data->udev, 747 pipe = usb_sndisocpipe(data->udev,
747 data->isoc_tx_ep->bEndpointAddress); 748 data->isoc_tx_ep->bEndpointAddress);
748 749
749 usb_fill_int_urb(urb, data->udev, pipe, 750 usb_fill_int_urb(urb, data->udev, pipe,
750 skb->data, skb->len, btusb_isoc_tx_complete, 751 skb->data, skb->len, btusb_isoc_tx_complete,
751 skb, data->isoc_tx_ep->bInterval); 752 skb, data->isoc_tx_ep->bInterval);
752 753
753 urb->transfer_flags = URB_ISO_ASAP; 754 urb->transfer_flags = URB_ISO_ASAP;
754 755
755 __fill_isoc_descriptor(urb, skb->len, 756 __fill_isoc_descriptor(urb, skb->len,
756 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); 757 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
757 758
758 hdev->stat.sco_tx++; 759 hdev->stat.sco_tx++;
759 goto skip_waking; 760 goto skip_waking;
760 761
761 default: 762 default:
762 return -EILSEQ; 763 return -EILSEQ;
763 } 764 }
764 765
765 err = inc_tx(data); 766 err = inc_tx(data);
766 if (err) { 767 if (err) {
767 usb_anchor_urb(urb, &data->deferred); 768 usb_anchor_urb(urb, &data->deferred);
768 schedule_work(&data->waker); 769 schedule_work(&data->waker);
769 err = 0; 770 err = 0;
770 goto done; 771 goto done;
771 } 772 }
772 773
773 skip_waking: 774 skip_waking:
774 usb_anchor_urb(urb, &data->tx_anchor); 775 usb_anchor_urb(urb, &data->tx_anchor);
775 776
776 err = usb_submit_urb(urb, GFP_ATOMIC); 777 err = usb_submit_urb(urb, GFP_ATOMIC);
777 if (err < 0) { 778 if (err < 0) {
778 if (err != -EPERM && err != -ENODEV) 779 if (err != -EPERM && err != -ENODEV)
779 BT_ERR("%s urb %p submission failed (%d)", 780 BT_ERR("%s urb %p submission failed (%d)",
780 hdev->name, urb, -err); 781 hdev->name, urb, -err);
781 kfree(urb->setup_packet); 782 kfree(urb->setup_packet);
782 usb_unanchor_urb(urb); 783 usb_unanchor_urb(urb);
783 } else { 784 } else {
784 usb_mark_last_busy(data->udev); 785 usb_mark_last_busy(data->udev);
785 } 786 }
786 787
787 done: 788 done:
788 usb_free_urb(urb); 789 usb_free_urb(urb);
789 return err; 790 return err;
790 } 791 }
791 792
792 static void btusb_notify(struct hci_dev *hdev, unsigned int evt) 793 static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
793 { 794 {
794 struct btusb_data *data = hci_get_drvdata(hdev); 795 struct btusb_data *data = hci_get_drvdata(hdev);
795 796
796 BT_DBG("%s evt %d", hdev->name, evt); 797 BT_DBG("%s evt %d", hdev->name, evt);
797 798
798 if (hdev->conn_hash.sco_num != data->sco_num) { 799 if (hdev->conn_hash.sco_num != data->sco_num) {
799 data->sco_num = hdev->conn_hash.sco_num; 800 data->sco_num = hdev->conn_hash.sco_num;
800 schedule_work(&data->work); 801 schedule_work(&data->work);
801 } 802 }
802 } 803 }
803 804
804 static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting) 805 static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
805 { 806 {
806 struct btusb_data *data = hci_get_drvdata(hdev); 807 struct btusb_data *data = hci_get_drvdata(hdev);
807 struct usb_interface *intf = data->isoc; 808 struct usb_interface *intf = data->isoc;
808 struct usb_endpoint_descriptor *ep_desc; 809 struct usb_endpoint_descriptor *ep_desc;
809 int i, err; 810 int i, err;
810 811
811 if (!data->isoc) 812 if (!data->isoc)
812 return -ENODEV; 813 return -ENODEV;
813 814
814 err = usb_set_interface(data->udev, 1, altsetting); 815 err = usb_set_interface(data->udev, 1, altsetting);
815 if (err < 0) { 816 if (err < 0) {
816 BT_ERR("%s setting interface failed (%d)", hdev->name, -err); 817 BT_ERR("%s setting interface failed (%d)", hdev->name, -err);
817 return err; 818 return err;
818 } 819 }
819 820
820 data->isoc_altsetting = altsetting; 821 data->isoc_altsetting = altsetting;
821 822
822 data->isoc_tx_ep = NULL; 823 data->isoc_tx_ep = NULL;
823 data->isoc_rx_ep = NULL; 824 data->isoc_rx_ep = NULL;
824 825
825 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { 826 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
826 ep_desc = &intf->cur_altsetting->endpoint[i].desc; 827 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
827 828
828 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) { 829 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
829 data->isoc_tx_ep = ep_desc; 830 data->isoc_tx_ep = ep_desc;
830 continue; 831 continue;
831 } 832 }
832 833
833 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) { 834 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
834 data->isoc_rx_ep = ep_desc; 835 data->isoc_rx_ep = ep_desc;
835 continue; 836 continue;
836 } 837 }
837 } 838 }
838 839
839 if (!data->isoc_tx_ep || !data->isoc_rx_ep) { 840 if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
840 BT_ERR("%s invalid SCO descriptors", hdev->name); 841 BT_ERR("%s invalid SCO descriptors", hdev->name);
841 return -ENODEV; 842 return -ENODEV;
842 } 843 }
843 844
844 return 0; 845 return 0;
845 } 846 }
846 847
847 static void btusb_work(struct work_struct *work) 848 static void btusb_work(struct work_struct *work)
848 { 849 {
849 struct btusb_data *data = container_of(work, struct btusb_data, work); 850 struct btusb_data *data = container_of(work, struct btusb_data, work);
850 struct hci_dev *hdev = data->hdev; 851 struct hci_dev *hdev = data->hdev;
851 int err; 852 int err;
852 853
853 if (hdev->conn_hash.sco_num > 0) { 854 if (hdev->conn_hash.sco_num > 0) {
854 if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) { 855 if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
855 err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf); 856 err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
856 if (err < 0) { 857 if (err < 0) {
857 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 858 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
858 usb_kill_anchored_urbs(&data->isoc_anchor); 859 usb_kill_anchored_urbs(&data->isoc_anchor);
859 return; 860 return;
860 } 861 }
861 862
862 set_bit(BTUSB_DID_ISO_RESUME, &data->flags); 863 set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
863 } 864 }
864 if (data->isoc_altsetting != 2) { 865 if (data->isoc_altsetting != 2) {
865 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 866 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
866 usb_kill_anchored_urbs(&data->isoc_anchor); 867 usb_kill_anchored_urbs(&data->isoc_anchor);
867 868
868 if (__set_isoc_interface(hdev, 2) < 0) 869 if (__set_isoc_interface(hdev, 2) < 0)
869 return; 870 return;
870 } 871 }
871 872
872 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { 873 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
873 if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0) 874 if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
874 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 875 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
875 else 876 else
876 btusb_submit_isoc_urb(hdev, GFP_KERNEL); 877 btusb_submit_isoc_urb(hdev, GFP_KERNEL);
877 } 878 }
878 } else { 879 } else {
879 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 880 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
880 usb_kill_anchored_urbs(&data->isoc_anchor); 881 usb_kill_anchored_urbs(&data->isoc_anchor);
881 882
882 __set_isoc_interface(hdev, 0); 883 __set_isoc_interface(hdev, 0);
883 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags)) 884 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
884 usb_autopm_put_interface(data->isoc ? data->isoc : data->intf); 885 usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
885 } 886 }
886 } 887 }
887 888
888 static void btusb_waker(struct work_struct *work) 889 static void btusb_waker(struct work_struct *work)
889 { 890 {
890 struct btusb_data *data = container_of(work, struct btusb_data, waker); 891 struct btusb_data *data = container_of(work, struct btusb_data, waker);
891 int err; 892 int err;
892 893
893 err = usb_autopm_get_interface(data->intf); 894 err = usb_autopm_get_interface(data->intf);
894 if (err < 0) 895 if (err < 0)
895 return; 896 return;
896 897
897 usb_autopm_put_interface(data->intf); 898 usb_autopm_put_interface(data->intf);
898 } 899 }
899 900
900 static int btusb_probe(struct usb_interface *intf, 901 static int btusb_probe(struct usb_interface *intf,
901 const struct usb_device_id *id) 902 const struct usb_device_id *id)
902 { 903 {
903 struct usb_endpoint_descriptor *ep_desc; 904 struct usb_endpoint_descriptor *ep_desc;
904 struct btusb_data *data; 905 struct btusb_data *data;
905 struct hci_dev *hdev; 906 struct hci_dev *hdev;
906 int i, err; 907 int i, err;
907 908
908 BT_DBG("intf %p id %p", intf, id); 909 BT_DBG("intf %p id %p", intf, id);
909 910
910 /* interface numbers are hardcoded in the spec */ 911 /* interface numbers are hardcoded in the spec */
911 if (intf->cur_altsetting->desc.bInterfaceNumber != 0) 912 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
912 return -ENODEV; 913 return -ENODEV;
913 914
914 if (!id->driver_info) { 915 if (!id->driver_info) {
915 const struct usb_device_id *match; 916 const struct usb_device_id *match;
916 match = usb_match_id(intf, blacklist_table); 917 match = usb_match_id(intf, blacklist_table);
917 if (match) 918 if (match)
918 id = match; 919 id = match;
919 } 920 }
920 921
921 if (id->driver_info == BTUSB_IGNORE) 922 if (id->driver_info == BTUSB_IGNORE)
922 return -ENODEV; 923 return -ENODEV;
923 924
924 if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER) 925 if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER)
925 return -ENODEV; 926 return -ENODEV;
926 927
927 if (ignore_csr && id->driver_info & BTUSB_CSR) 928 if (ignore_csr && id->driver_info & BTUSB_CSR)
928 return -ENODEV; 929 return -ENODEV;
929 930
930 if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER) 931 if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER)
931 return -ENODEV; 932 return -ENODEV;
932 933
933 if (id->driver_info & BTUSB_ATH3012) { 934 if (id->driver_info & BTUSB_ATH3012) {
934 struct usb_device *udev = interface_to_usbdev(intf); 935 struct usb_device *udev = interface_to_usbdev(intf);
935 936
936 /* Old firmware would otherwise let ath3k driver load 937 /* Old firmware would otherwise let ath3k driver load
937 * patch and sysconfig files */ 938 * patch and sysconfig files */
938 if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001) 939 if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001)
939 return -ENODEV; 940 return -ENODEV;
940 } 941 }
941 942
942 data = kzalloc(sizeof(*data), GFP_KERNEL); 943 data = kzalloc(sizeof(*data), GFP_KERNEL);
943 if (!data) 944 if (!data)
944 return -ENOMEM; 945 return -ENOMEM;
945 946
946 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { 947 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
947 ep_desc = &intf->cur_altsetting->endpoint[i].desc; 948 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
948 949
949 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) { 950 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
950 data->intr_ep = ep_desc; 951 data->intr_ep = ep_desc;
951 continue; 952 continue;
952 } 953 }
953 954
954 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { 955 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
955 data->bulk_tx_ep = ep_desc; 956 data->bulk_tx_ep = ep_desc;
956 continue; 957 continue;
957 } 958 }
958 959
959 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { 960 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
960 data->bulk_rx_ep = ep_desc; 961 data->bulk_rx_ep = ep_desc;
961 continue; 962 continue;
962 } 963 }
963 } 964 }
964 965
965 if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) { 966 if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
966 kfree(data); 967 kfree(data);
967 return -ENODEV; 968 return -ENODEV;
968 } 969 }
969 970
970 data->cmdreq_type = USB_TYPE_CLASS; 971 data->cmdreq_type = USB_TYPE_CLASS;
971 972
972 data->udev = interface_to_usbdev(intf); 973 data->udev = interface_to_usbdev(intf);
973 data->intf = intf; 974 data->intf = intf;
974 975
975 spin_lock_init(&data->lock); 976 spin_lock_init(&data->lock);
976 977
977 INIT_WORK(&data->work, btusb_work); 978 INIT_WORK(&data->work, btusb_work);
978 INIT_WORK(&data->waker, btusb_waker); 979 INIT_WORK(&data->waker, btusb_waker);
979 spin_lock_init(&data->txlock); 980 spin_lock_init(&data->txlock);
980 981
981 init_usb_anchor(&data->tx_anchor); 982 init_usb_anchor(&data->tx_anchor);
982 init_usb_anchor(&data->intr_anchor); 983 init_usb_anchor(&data->intr_anchor);
983 init_usb_anchor(&data->bulk_anchor); 984 init_usb_anchor(&data->bulk_anchor);
984 init_usb_anchor(&data->isoc_anchor); 985 init_usb_anchor(&data->isoc_anchor);
985 init_usb_anchor(&data->deferred); 986 init_usb_anchor(&data->deferred);
986 987
987 hdev = hci_alloc_dev(); 988 hdev = hci_alloc_dev();
988 if (!hdev) { 989 if (!hdev) {
989 kfree(data); 990 kfree(data);
990 return -ENOMEM; 991 return -ENOMEM;
991 } 992 }
992 993
993 hdev->bus = HCI_USB; 994 hdev->bus = HCI_USB;
994 hci_set_drvdata(hdev, data); 995 hci_set_drvdata(hdev, data);
995 996
996 data->hdev = hdev; 997 data->hdev = hdev;
997 998
998 SET_HCIDEV_DEV(hdev, &intf->dev); 999 SET_HCIDEV_DEV(hdev, &intf->dev);
999 1000
1000 hdev->open = btusb_open; 1001 hdev->open = btusb_open;
1001 hdev->close = btusb_close; 1002 hdev->close = btusb_close;
1002 hdev->flush = btusb_flush; 1003 hdev->flush = btusb_flush;
1003 hdev->send = btusb_send_frame; 1004 hdev->send = btusb_send_frame;
1004 hdev->notify = btusb_notify; 1005 hdev->notify = btusb_notify;
1005 1006
1006 /* Interface numbers are hardcoded in the specification */ 1007 /* Interface numbers are hardcoded in the specification */
1007 data->isoc = usb_ifnum_to_if(data->udev, 1); 1008 data->isoc = usb_ifnum_to_if(data->udev, 1);
1008 1009
1009 if (!reset) 1010 if (!reset)
1010 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 1011 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
1011 1012
1012 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { 1013 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
1013 if (!disable_scofix) 1014 if (!disable_scofix)
1014 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks); 1015 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
1015 } 1016 }
1016 1017
1017 if (id->driver_info & BTUSB_BROKEN_ISOC) 1018 if (id->driver_info & BTUSB_BROKEN_ISOC)
1018 data->isoc = NULL; 1019 data->isoc = NULL;
1019 1020
1020 if (id->driver_info & BTUSB_DIGIANSWER) { 1021 if (id->driver_info & BTUSB_DIGIANSWER) {
1021 data->cmdreq_type = USB_TYPE_VENDOR; 1022 data->cmdreq_type = USB_TYPE_VENDOR;
1022 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 1023 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
1023 } 1024 }
1024 1025
1025 if (id->driver_info & BTUSB_CSR) { 1026 if (id->driver_info & BTUSB_CSR) {
1026 struct usb_device *udev = data->udev; 1027 struct usb_device *udev = data->udev;
1027 1028
1028 /* Old firmware would otherwise execute USB reset */ 1029 /* Old firmware would otherwise execute USB reset */
1029 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117) 1030 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117)
1030 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 1031 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
1031 } 1032 }
1032 1033
1033 if (id->driver_info & BTUSB_SNIFFER) { 1034 if (id->driver_info & BTUSB_SNIFFER) {
1034 struct usb_device *udev = data->udev; 1035 struct usb_device *udev = data->udev;
1035 1036
1036 /* New sniffer firmware has crippled HCI interface */ 1037 /* New sniffer firmware has crippled HCI interface */
1037 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) 1038 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
1038 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); 1039 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
1039 1040
1040 data->isoc = NULL; 1041 data->isoc = NULL;
1041 } 1042 }
1042 1043
1043 if (id->driver_info & BTUSB_BCM92035) { 1044 if (id->driver_info & BTUSB_BCM92035) {
1044 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 }; 1045 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
1045 struct sk_buff *skb; 1046 struct sk_buff *skb;
1046 1047
1047 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); 1048 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
1048 if (skb) { 1049 if (skb) {
1049 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd)); 1050 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
1050 skb_queue_tail(&hdev->driver_init, skb); 1051 skb_queue_tail(&hdev->driver_init, skb);
1051 } 1052 }
1052 } 1053 }
1053 1054
1054 if (data->isoc) { 1055 if (data->isoc) {
1055 err = usb_driver_claim_interface(&btusb_driver, 1056 err = usb_driver_claim_interface(&btusb_driver,
1056 data->isoc, data); 1057 data->isoc, data);
1057 if (err < 0) { 1058 if (err < 0) {
1058 hci_free_dev(hdev); 1059 hci_free_dev(hdev);
1059 kfree(data); 1060 kfree(data);
1060 return err; 1061 return err;
1061 } 1062 }
1062 } 1063 }
1063 1064
1064 err = hci_register_dev(hdev); 1065 err = hci_register_dev(hdev);
1065 if (err < 0) { 1066 if (err < 0) {
1066 hci_free_dev(hdev); 1067 hci_free_dev(hdev);
1067 kfree(data); 1068 kfree(data);
1068 return err; 1069 return err;
1069 } 1070 }
1070 1071
1071 usb_set_intfdata(intf, data); 1072 usb_set_intfdata(intf, data);
1072 1073
1073 return 0; 1074 return 0;
1074 } 1075 }
1075 1076
1076 static void btusb_disconnect(struct usb_interface *intf) 1077 static void btusb_disconnect(struct usb_interface *intf)
1077 { 1078 {
1078 struct btusb_data *data = usb_get_intfdata(intf); 1079 struct btusb_data *data = usb_get_intfdata(intf);
1079 struct hci_dev *hdev; 1080 struct hci_dev *hdev;
1080 1081
1081 BT_DBG("intf %p", intf); 1082 BT_DBG("intf %p", intf);
1082 1083
1083 if (!data) 1084 if (!data)
1084 return; 1085 return;
1085 1086
1086 hdev = data->hdev; 1087 hdev = data->hdev;
1087 usb_set_intfdata(data->intf, NULL); 1088 usb_set_intfdata(data->intf, NULL);
1088 1089
1089 if (data->isoc) 1090 if (data->isoc)
1090 usb_set_intfdata(data->isoc, NULL); 1091 usb_set_intfdata(data->isoc, NULL);
1091 1092
1092 hci_unregister_dev(hdev); 1093 hci_unregister_dev(hdev);
1093 1094
1094 if (intf == data->isoc) 1095 if (intf == data->isoc)
1095 usb_driver_release_interface(&btusb_driver, data->intf); 1096 usb_driver_release_interface(&btusb_driver, data->intf);
1096 else if (data->isoc) 1097 else if (data->isoc)
1097 usb_driver_release_interface(&btusb_driver, data->isoc); 1098 usb_driver_release_interface(&btusb_driver, data->isoc);
1098 1099
1099 hci_free_dev(hdev); 1100 hci_free_dev(hdev);
1100 kfree(data); 1101 kfree(data);
1101 } 1102 }
1102 1103
1103 #ifdef CONFIG_PM 1104 #ifdef CONFIG_PM
1104 static int btusb_suspend(struct usb_interface *intf, pm_message_t message) 1105 static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
1105 { 1106 {
1106 struct btusb_data *data = usb_get_intfdata(intf); 1107 struct btusb_data *data = usb_get_intfdata(intf);
1107 1108
1108 BT_DBG("intf %p", intf); 1109 BT_DBG("intf %p", intf);
1109 1110
1110 if (data->suspend_count++) 1111 if (data->suspend_count++)
1111 return 0; 1112 return 0;
1112 1113
1113 spin_lock_irq(&data->txlock); 1114 spin_lock_irq(&data->txlock);
1114 if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) { 1115 if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
1115 set_bit(BTUSB_SUSPENDING, &data->flags); 1116 set_bit(BTUSB_SUSPENDING, &data->flags);
1116 spin_unlock_irq(&data->txlock); 1117 spin_unlock_irq(&data->txlock);
1117 } else { 1118 } else {
1118 spin_unlock_irq(&data->txlock); 1119 spin_unlock_irq(&data->txlock);
1119 data->suspend_count--; 1120 data->suspend_count--;
1120 return -EBUSY; 1121 return -EBUSY;
1121 } 1122 }
1122 1123
1123 cancel_work_sync(&data->work); 1124 cancel_work_sync(&data->work);
1124 1125
1125 btusb_stop_traffic(data); 1126 btusb_stop_traffic(data);
1126 usb_kill_anchored_urbs(&data->tx_anchor); 1127 usb_kill_anchored_urbs(&data->tx_anchor);
1127 1128
1128 return 0; 1129 return 0;
1129 } 1130 }
1130 1131
1131 static void play_deferred(struct btusb_data *data) 1132 static void play_deferred(struct btusb_data *data)
1132 { 1133 {
1133 struct urb *urb; 1134 struct urb *urb;
1134 int err; 1135 int err;
1135 1136
1136 while ((urb = usb_get_from_anchor(&data->deferred))) { 1137 while ((urb = usb_get_from_anchor(&data->deferred))) {
1137 err = usb_submit_urb(urb, GFP_ATOMIC); 1138 err = usb_submit_urb(urb, GFP_ATOMIC);
1138 if (err < 0) 1139 if (err < 0)
1139 break; 1140 break;
1140 1141
1141 data->tx_in_flight++; 1142 data->tx_in_flight++;
1142 } 1143 }
1143 usb_scuttle_anchored_urbs(&data->deferred); 1144 usb_scuttle_anchored_urbs(&data->deferred);
1144 } 1145 }
1145 1146
1146 static int btusb_resume(struct usb_interface *intf) 1147 static int btusb_resume(struct usb_interface *intf)
1147 { 1148 {
1148 struct btusb_data *data = usb_get_intfdata(intf); 1149 struct btusb_data *data = usb_get_intfdata(intf);
1149 struct hci_dev *hdev = data->hdev; 1150 struct hci_dev *hdev = data->hdev;
1150 int err = 0; 1151 int err = 0;
1151 1152
1152 BT_DBG("intf %p", intf); 1153 BT_DBG("intf %p", intf);
1153 1154
1154 if (--data->suspend_count) 1155 if (--data->suspend_count)
1155 return 0; 1156 return 0;
1156 1157
1157 if (!test_bit(HCI_RUNNING, &hdev->flags)) 1158 if (!test_bit(HCI_RUNNING, &hdev->flags))
1158 goto done; 1159 goto done;
1159 1160
1160 if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) { 1161 if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
1161 err = btusb_submit_intr_urb(hdev, GFP_NOIO); 1162 err = btusb_submit_intr_urb(hdev, GFP_NOIO);
1162 if (err < 0) { 1163 if (err < 0) {
1163 clear_bit(BTUSB_INTR_RUNNING, &data->flags); 1164 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
1164 goto failed; 1165 goto failed;
1165 } 1166 }
1166 } 1167 }
1167 1168
1168 if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) { 1169 if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
1169 err = btusb_submit_bulk_urb(hdev, GFP_NOIO); 1170 err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
1170 if (err < 0) { 1171 if (err < 0) {
1171 clear_bit(BTUSB_BULK_RUNNING, &data->flags); 1172 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
1172 goto failed; 1173 goto failed;
1173 } 1174 }
1174 1175
1175 btusb_submit_bulk_urb(hdev, GFP_NOIO); 1176 btusb_submit_bulk_urb(hdev, GFP_NOIO);
1176 } 1177 }
1177 1178
1178 if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) { 1179 if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
1179 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0) 1180 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
1180 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 1181 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1181 else 1182 else
1182 btusb_submit_isoc_urb(hdev, GFP_NOIO); 1183 btusb_submit_isoc_urb(hdev, GFP_NOIO);
1183 } 1184 }
1184 1185
1185 spin_lock_irq(&data->txlock); 1186 spin_lock_irq(&data->txlock);
1186 play_deferred(data); 1187 play_deferred(data);
1187 clear_bit(BTUSB_SUSPENDING, &data->flags); 1188 clear_bit(BTUSB_SUSPENDING, &data->flags);
1188 spin_unlock_irq(&data->txlock); 1189 spin_unlock_irq(&data->txlock);
1189 schedule_work(&data->work); 1190 schedule_work(&data->work);
1190 1191
1191 return 0; 1192 return 0;
1192 1193
1193 failed: 1194 failed:
1194 usb_scuttle_anchored_urbs(&data->deferred); 1195 usb_scuttle_anchored_urbs(&data->deferred);
1195 done: 1196 done:
1196 spin_lock_irq(&data->txlock); 1197 spin_lock_irq(&data->txlock);
1197 clear_bit(BTUSB_SUSPENDING, &data->flags); 1198 clear_bit(BTUSB_SUSPENDING, &data->flags);
1198 spin_unlock_irq(&data->txlock); 1199 spin_unlock_irq(&data->txlock);
1199 1200
1200 return err; 1201 return err;
1201 } 1202 }
1202 #endif 1203 #endif
1203 1204
1204 static struct usb_driver btusb_driver = { 1205 static struct usb_driver btusb_driver = {
1205 .name = "btusb", 1206 .name = "btusb",
1206 .probe = btusb_probe, 1207 .probe = btusb_probe,
1207 .disconnect = btusb_disconnect, 1208 .disconnect = btusb_disconnect,
1208 #ifdef CONFIG_PM 1209 #ifdef CONFIG_PM
1209 .suspend = btusb_suspend, 1210 .suspend = btusb_suspend,
1210 .resume = btusb_resume, 1211 .resume = btusb_resume,
1211 #endif 1212 #endif
1212 .id_table = btusb_table, 1213 .id_table = btusb_table,
1213 .supports_autosuspend = 1, 1214 .supports_autosuspend = 1,
1214 }; 1215 };
1215 1216
1216 module_usb_driver(btusb_driver); 1217 module_usb_driver(btusb_driver);
1217 1218
1218 module_param(ignore_dga, bool, 0644); 1219 module_param(ignore_dga, bool, 0644);
1219 MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001"); 1220 MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
1220 1221
1221 module_param(ignore_csr, bool, 0644); 1222 module_param(ignore_csr, bool, 0644);
1222 MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001"); 1223 MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
1223 1224
1224 module_param(ignore_sniffer, bool, 0644); 1225 module_param(ignore_sniffer, bool, 0644);
1225 MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002"); 1226 MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
1226 1227
1227 module_param(disable_scofix, bool, 0644); 1228 module_param(disable_scofix, bool, 0644);
1228 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size"); 1229 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
1229 1230
1230 module_param(force_scofix, bool, 0644); 1231 module_param(force_scofix, bool, 0644);
1231 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size"); 1232 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
1232 1233
1233 module_param(reset, bool, 0644); 1234 module_param(reset, bool, 0644);
1234 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); 1235 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
1235 1236
1236 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); 1237 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
1237 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION); 1238 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
1238 MODULE_VERSION(VERSION); 1239 MODULE_VERSION(VERSION);
1239 MODULE_LICENSE("GPL"); 1240 MODULE_LICENSE("GPL");
1240 1241