1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * 4 * Generic Bluetooth USB driver 5 * 6 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org> 7 */ 8 9 #include <linux/dmi.h> 10 #include <linux/module.h> 11 #include <linux/usb.h> 12 #include <linux/usb/quirks.h> 13 #include <linux/firmware.h> 14 #include <linux/iopoll.h> 15 #include <linux/of_device.h> 16 #include <linux/of_irq.h> 17 #include <linux/suspend.h> 18 #include <linux/gpio/consumer.h> 19 #include <linux/debugfs.h> 20 #include <linux/unaligned.h> 21 22 #include <net/bluetooth/bluetooth.h> 23 #include <net/bluetooth/hci_core.h> 24 #include <net/bluetooth/hci_drv.h> 25 26 #include "btintel.h" 27 #include "btbcm.h" 28 #include "btrtl.h" 29 #include "btmtk.h" 30 31 #define VERSION "0.8" 32 33 static bool disable_scofix; 34 static bool force_scofix; 35 static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND); 36 static bool enable_poll_sync = IS_ENABLED(CONFIG_BT_HCIBTUSB_POLL_SYNC); 37 static bool reset = true; 38 39 static struct usb_driver btusb_driver; 40 41 #define BTUSB_IGNORE BIT(0) 42 #define BTUSB_DIGIANSWER BIT(1) 43 #define BTUSB_CSR BIT(2) 44 #define BTUSB_SNIFFER BIT(3) 45 #define BTUSB_BCM92035 BIT(4) 46 #define BTUSB_BROKEN_ISOC BIT(5) 47 #define BTUSB_WRONG_SCO_MTU BIT(6) 48 #define BTUSB_ATH3012 BIT(7) 49 #define BTUSB_INTEL_COMBINED BIT(8) 50 #define BTUSB_INTEL_BOOT BIT(9) 51 #define BTUSB_BCM_PATCHRAM BIT(10) 52 #define BTUSB_MARVELL BIT(11) 53 #define BTUSB_SWAVE BIT(12) 54 #define BTUSB_AMP BIT(13) 55 #define BTUSB_QCA_ROME BIT(14) 56 #define BTUSB_BCM_APPLE BIT(15) 57 #define BTUSB_REALTEK BIT(16) 58 #define BTUSB_BCM2045 BIT(17) 59 #define BTUSB_IFNUM_2 BIT(18) 60 #define BTUSB_CW6622 BIT(19) 61 #define BTUSB_MEDIATEK BIT(20) 62 #define BTUSB_WIDEBAND_SPEECH BIT(21) 63 #define BTUSB_INVALID_LE_STATES BIT(22) 64 #define BTUSB_QCA_WCN6855 BIT(23) 65 #define BTUSB_INTEL_BROKEN_SHUTDOWN_LED BIT(24) 66 #define BTUSB_INTEL_BROKEN_INITIAL_NCMD BIT(25) 67 #define BTUSB_INTEL_NO_WBS_SUPPORT BIT(26) 68 #define BTUSB_ACTIONS_SEMI BIT(27) 69 #define BTUSB_BARROT BIT(28) 70 #define BTUSB_BROKEN_EXT_SCAN BIT(29) 71 72 static const struct usb_device_id btusb_table[] = { 73 /* Generic Bluetooth USB device */ 74 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, 75 76 /* Generic Bluetooth AMP device */ 77 { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info = BTUSB_AMP }, 78 79 /* Generic Bluetooth USB interface */ 80 { USB_INTERFACE_INFO(0xe0, 0x01, 0x01) }, 81 82 /* Apple-specific (Broadcom) devices */ 83 { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01), 84 .driver_info = BTUSB_BCM_APPLE | BTUSB_IFNUM_2 }, 85 86 /* MediaTek MT76x0E */ 87 { USB_DEVICE(0x0e8d, 0x763f) }, 88 89 /* Broadcom SoftSailing reporting vendor specific */ 90 { USB_DEVICE(0x0a5c, 0x21e1) }, 91 92 /* Apple MacBookPro 7,1 */ 93 { USB_DEVICE(0x05ac, 0x8213) }, 94 95 /* Apple iMac11,1 */ 96 { USB_DEVICE(0x05ac, 0x8215) }, 97 98 /* Apple MacBookPro6,2 */ 99 { USB_DEVICE(0x05ac, 0x8218) }, 100 101 /* Apple MacBookAir3,1, MacBookAir3,2 */ 102 { USB_DEVICE(0x05ac, 0x821b) }, 103 104 /* Apple MacBookAir4,1 */ 105 { USB_DEVICE(0x05ac, 0x821f) }, 106 107 /* Apple MacBookPro8,2 */ 108 { USB_DEVICE(0x05ac, 0x821a) }, 109 110 /* Apple MacMini5,1 */ 111 { USB_DEVICE(0x05ac, 0x8281) }, 112 113 /* AVM BlueFRITZ! USB v2.0 */ 114 { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE }, 115 116 /* Bluetooth Ultraport Module from IBM */ 117 { USB_DEVICE(0x04bf, 0x030a) }, 118 119 /* ALPS Modules with non-standard id */ 120 { USB_DEVICE(0x044e, 0x3001) }, 121 { USB_DEVICE(0x044e, 0x3002) }, 122 123 /* Ericsson with non-standard id */ 124 { USB_DEVICE(0x0bdb, 0x1002) }, 125 126 /* Canyon CN-BTU1 with HID interfaces */ 127 { USB_DEVICE(0x0c10, 0x0000) }, 128 129 /* Broadcom BCM20702B0 (Dynex/Insignia) */ 130 { USB_DEVICE(0x19ff, 0x0239), .driver_info = BTUSB_BCM_PATCHRAM }, 131 132 /* Broadcom BCM43142A0 (Foxconn/Lenovo) */ 133 { USB_VENDOR_AND_INTERFACE_INFO(0x105b, 0xff, 0x01, 0x01), 134 .driver_info = BTUSB_BCM_PATCHRAM }, 135 136 /* Broadcom BCM920703 (HTC Vive) */ 137 { USB_VENDOR_AND_INTERFACE_INFO(0x0bb4, 0xff, 0x01, 0x01), 138 .driver_info = BTUSB_BCM_PATCHRAM }, 139 140 /* Foxconn - Hon Hai */ 141 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01), 142 .driver_info = BTUSB_BCM_PATCHRAM }, 143 144 /* Lite-On Technology - Broadcom based */ 145 { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01), 146 .driver_info = BTUSB_BCM_PATCHRAM }, 147 148 /* Broadcom devices with vendor specific id */ 149 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01), 150 .driver_info = BTUSB_BCM_PATCHRAM }, 151 152 /* ASUSTek Computer - Broadcom based */ 153 { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01), 154 .driver_info = BTUSB_BCM_PATCHRAM }, 155 156 /* Belkin F8065bf - Broadcom based */ 157 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01), 158 .driver_info = BTUSB_BCM_PATCHRAM }, 159 160 /* IMC Networks - Broadcom based */ 161 { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01), 162 .driver_info = BTUSB_BCM_PATCHRAM }, 163 164 /* Dell Computer - Broadcom based */ 165 { USB_VENDOR_AND_INTERFACE_INFO(0x413c, 0xff, 0x01, 0x01), 166 .driver_info = BTUSB_BCM_PATCHRAM }, 167 168 /* Toshiba Corp - Broadcom based */ 169 { USB_VENDOR_AND_INTERFACE_INFO(0x0930, 0xff, 0x01, 0x01), 170 .driver_info = BTUSB_BCM_PATCHRAM }, 171 172 /* Intel Bluetooth USB Bootloader (RAM module) */ 173 { USB_DEVICE(0x8087, 0x0a5a), 174 .driver_info = BTUSB_INTEL_BOOT | BTUSB_BROKEN_ISOC }, 175 176 { } /* Terminating entry */ 177 }; 178 179 MODULE_DEVICE_TABLE(usb, btusb_table); 180 181 static const struct usb_device_id quirks_table[] = { 182 /* CSR BlueCore devices */ 183 { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR }, 184 185 /* Broadcom BCM2033 without firmware */ 186 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE }, 187 188 /* Broadcom BCM2045 devices */ 189 { USB_DEVICE(0x0a5c, 0x2045), .driver_info = BTUSB_BCM2045 }, 190 191 /* Atheros 3011 with sflash firmware */ 192 { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE }, 193 { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE }, 194 { USB_DEVICE(0x04f2, 0xaff1), .driver_info = BTUSB_IGNORE }, 195 { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE }, 196 { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE }, 197 { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE }, 198 { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE }, 199 200 /* Atheros AR9285 Malbec with sflash firmware */ 201 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE }, 202 203 /* Atheros 3012 with sflash firmware */ 204 { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 }, 205 { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 }, 206 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 }, 207 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 }, 208 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 }, 209 { USB_DEVICE(0x0489, 0xe076), .driver_info = BTUSB_ATH3012 }, 210 { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 }, 211 { USB_DEVICE(0x0489, 0xe095), .driver_info = BTUSB_ATH3012 }, 212 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 }, 213 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 }, 214 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 }, 215 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 }, 216 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 }, 217 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 }, 218 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 }, 219 { USB_DEVICE(0x04ca, 0x300d), .driver_info = BTUSB_ATH3012 }, 220 { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 }, 221 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 }, 222 { USB_DEVICE(0x04ca, 0x3014), .driver_info = BTUSB_ATH3012 }, 223 { USB_DEVICE(0x04ca, 0x3018), .driver_info = BTUSB_ATH3012 }, 224 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 }, 225 { USB_DEVICE(0x0930, 0x021c), .driver_info = BTUSB_ATH3012 }, 226 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 }, 227 { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 }, 228 { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 }, 229 { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 }, 230 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, 231 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 }, 232 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 }, 233 { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 }, 234 { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 }, 235 { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 }, 236 { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 }, 237 { USB_DEVICE(0x0cf3, 0x817b), .driver_info = BTUSB_ATH3012 }, 238 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 }, 239 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 }, 240 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 }, 241 { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 }, 242 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 }, 243 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 244 { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 }, 245 { USB_DEVICE(0x13d3, 0x3395), .driver_info = BTUSB_ATH3012 }, 246 { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 }, 247 { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 }, 248 { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 }, 249 { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 }, 250 { USB_DEVICE(0x13d3, 0x3472), .driver_info = BTUSB_ATH3012 }, 251 { USB_DEVICE(0x13d3, 0x3474), .driver_info = BTUSB_ATH3012 }, 252 { USB_DEVICE(0x13d3, 0x3487), .driver_info = BTUSB_ATH3012 }, 253 { USB_DEVICE(0x13d3, 0x3490), .driver_info = BTUSB_ATH3012 }, 254 255 /* Atheros AR5BBU12 with sflash firmware */ 256 { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE }, 257 258 /* Atheros AR5BBU12 with sflash firmware */ 259 { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 }, 260 { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, 261 262 /* QCA ROME chipset */ 263 { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME | 264 BTUSB_WIDEBAND_SPEECH }, 265 { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME | 266 BTUSB_WIDEBAND_SPEECH }, 267 { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME | 268 BTUSB_WIDEBAND_SPEECH }, 269 { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME | 270 BTUSB_WIDEBAND_SPEECH }, 271 { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME | 272 BTUSB_WIDEBAND_SPEECH }, 273 { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME | 274 BTUSB_WIDEBAND_SPEECH }, 275 { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME | 276 BTUSB_WIDEBAND_SPEECH }, 277 { USB_DEVICE(0x0cf3, 0xe500), .driver_info = BTUSB_QCA_ROME | 278 BTUSB_WIDEBAND_SPEECH }, 279 { USB_DEVICE(0x0489, 0xe092), .driver_info = BTUSB_QCA_ROME | 280 BTUSB_WIDEBAND_SPEECH }, 281 { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME | 282 BTUSB_WIDEBAND_SPEECH }, 283 { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME | 284 BTUSB_WIDEBAND_SPEECH }, 285 { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME | 286 BTUSB_WIDEBAND_SPEECH }, 287 { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME | 288 BTUSB_WIDEBAND_SPEECH }, 289 { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME | 290 BTUSB_WIDEBAND_SPEECH }, 291 { USB_DEVICE(0x04ca, 0x301a), .driver_info = BTUSB_QCA_ROME | 292 BTUSB_WIDEBAND_SPEECH }, 293 { USB_DEVICE(0x04ca, 0x3021), .driver_info = BTUSB_QCA_ROME | 294 BTUSB_WIDEBAND_SPEECH }, 295 { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA_ROME | 296 BTUSB_WIDEBAND_SPEECH }, 297 { USB_DEVICE(0x13d3, 0x3496), .driver_info = BTUSB_QCA_ROME | 298 BTUSB_WIDEBAND_SPEECH }, 299 { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA_ROME | 300 BTUSB_WIDEBAND_SPEECH }, 301 { USB_DEVICE(0x13d3, 0x3503), .driver_info = BTUSB_QCA_ROME | 302 BTUSB_WIDEBAND_SPEECH }, 303 304 /* QCA WCN6855 chipset */ 305 { USB_DEVICE(0x0489, 0xe0c7), .driver_info = BTUSB_QCA_WCN6855 | 306 BTUSB_WIDEBAND_SPEECH }, 307 { USB_DEVICE(0x0489, 0xe0c9), .driver_info = BTUSB_QCA_WCN6855 | 308 BTUSB_WIDEBAND_SPEECH }, 309 { USB_DEVICE(0x0489, 0xe0ca), .driver_info = BTUSB_QCA_WCN6855 | 310 BTUSB_WIDEBAND_SPEECH }, 311 { USB_DEVICE(0x0489, 0xe0cb), .driver_info = BTUSB_QCA_WCN6855 | 312 BTUSB_WIDEBAND_SPEECH }, 313 { USB_DEVICE(0x0489, 0xe0cc), .driver_info = BTUSB_QCA_WCN6855 | 314 BTUSB_WIDEBAND_SPEECH }, 315 { USB_DEVICE(0x0489, 0xe0ce), .driver_info = BTUSB_QCA_WCN6855 | 316 BTUSB_WIDEBAND_SPEECH }, 317 { USB_DEVICE(0x0489, 0xe0d0), .driver_info = BTUSB_QCA_WCN6855 | 318 BTUSB_WIDEBAND_SPEECH }, 319 { USB_DEVICE(0x0489, 0xe0d6), .driver_info = BTUSB_QCA_WCN6855 | 320 BTUSB_WIDEBAND_SPEECH }, 321 { USB_DEVICE(0x0489, 0xe0de), .driver_info = BTUSB_QCA_WCN6855 | 322 BTUSB_WIDEBAND_SPEECH }, 323 { USB_DEVICE(0x0489, 0xe0df), .driver_info = BTUSB_QCA_WCN6855 | 324 BTUSB_WIDEBAND_SPEECH }, 325 { USB_DEVICE(0x0489, 0xe0e1), .driver_info = BTUSB_QCA_WCN6855 | 326 BTUSB_WIDEBAND_SPEECH }, 327 { USB_DEVICE(0x0489, 0xe0e3), .driver_info = BTUSB_QCA_WCN6855 | 328 BTUSB_WIDEBAND_SPEECH }, 329 { USB_DEVICE(0x0489, 0xe0ea), .driver_info = BTUSB_QCA_WCN6855 | 330 BTUSB_WIDEBAND_SPEECH }, 331 { USB_DEVICE(0x0489, 0xe0ec), .driver_info = BTUSB_QCA_WCN6855 | 332 BTUSB_WIDEBAND_SPEECH }, 333 { USB_DEVICE(0x04ca, 0x3022), .driver_info = BTUSB_QCA_WCN6855 | 334 BTUSB_WIDEBAND_SPEECH }, 335 { USB_DEVICE(0x04ca, 0x3023), .driver_info = BTUSB_QCA_WCN6855 | 336 BTUSB_WIDEBAND_SPEECH }, 337 { USB_DEVICE(0x04ca, 0x3024), .driver_info = BTUSB_QCA_WCN6855 | 338 BTUSB_WIDEBAND_SPEECH }, 339 { USB_DEVICE(0x04ca, 0x3a22), .driver_info = BTUSB_QCA_WCN6855 | 340 BTUSB_WIDEBAND_SPEECH }, 341 { USB_DEVICE(0x04ca, 0x3a24), .driver_info = BTUSB_QCA_WCN6855 | 342 BTUSB_WIDEBAND_SPEECH }, 343 { USB_DEVICE(0x04ca, 0x3a26), .driver_info = BTUSB_QCA_WCN6855 | 344 BTUSB_WIDEBAND_SPEECH }, 345 { USB_DEVICE(0x04ca, 0x3a27), .driver_info = BTUSB_QCA_WCN6855 | 346 BTUSB_WIDEBAND_SPEECH }, 347 { USB_DEVICE(0x0cf3, 0xe600), .driver_info = BTUSB_QCA_WCN6855 | 348 BTUSB_WIDEBAND_SPEECH }, 349 { USB_DEVICE(0x10ab, 0x9108), .driver_info = BTUSB_QCA_WCN6855 | 350 BTUSB_WIDEBAND_SPEECH }, 351 { USB_DEVICE(0x10ab, 0x9109), .driver_info = BTUSB_QCA_WCN6855 | 352 BTUSB_WIDEBAND_SPEECH }, 353 { USB_DEVICE(0x10ab, 0x9208), .driver_info = BTUSB_QCA_WCN6855 | 354 BTUSB_WIDEBAND_SPEECH }, 355 { USB_DEVICE(0x10ab, 0x9209), .driver_info = BTUSB_QCA_WCN6855 | 356 BTUSB_WIDEBAND_SPEECH }, 357 { USB_DEVICE(0x10ab, 0x9308), .driver_info = BTUSB_QCA_WCN6855 | 358 BTUSB_WIDEBAND_SPEECH }, 359 { USB_DEVICE(0x10ab, 0x9309), .driver_info = BTUSB_QCA_WCN6855 | 360 BTUSB_WIDEBAND_SPEECH }, 361 { USB_DEVICE(0x10ab, 0x9408), .driver_info = BTUSB_QCA_WCN6855 | 362 BTUSB_WIDEBAND_SPEECH }, 363 { USB_DEVICE(0x10ab, 0x9409), .driver_info = BTUSB_QCA_WCN6855 | 364 BTUSB_WIDEBAND_SPEECH }, 365 { USB_DEVICE(0x10ab, 0x9508), .driver_info = BTUSB_QCA_WCN6855 | 366 BTUSB_WIDEBAND_SPEECH }, 367 { USB_DEVICE(0x10ab, 0x9509), .driver_info = BTUSB_QCA_WCN6855 | 368 BTUSB_WIDEBAND_SPEECH }, 369 { USB_DEVICE(0x10ab, 0x9608), .driver_info = BTUSB_QCA_WCN6855 | 370 BTUSB_WIDEBAND_SPEECH }, 371 { USB_DEVICE(0x10ab, 0x9609), .driver_info = BTUSB_QCA_WCN6855 | 372 BTUSB_WIDEBAND_SPEECH }, 373 { USB_DEVICE(0x10ab, 0x9f09), .driver_info = BTUSB_QCA_WCN6855 | 374 BTUSB_WIDEBAND_SPEECH }, 375 { USB_DEVICE(0x28de, 0x1401), .driver_info = BTUSB_QCA_WCN6855 | 376 BTUSB_WIDEBAND_SPEECH }, 377 378 /* QCA WCN785x chipset */ 379 { USB_DEVICE(0x0cf3, 0xe700), .driver_info = BTUSB_QCA_WCN6855 | 380 BTUSB_WIDEBAND_SPEECH }, 381 { USB_DEVICE(0x0489, 0xe0fc), .driver_info = BTUSB_QCA_WCN6855 | 382 BTUSB_WIDEBAND_SPEECH }, 383 { USB_DEVICE(0x0489, 0xe0f3), .driver_info = BTUSB_QCA_WCN6855 | 384 BTUSB_WIDEBAND_SPEECH }, 385 { USB_DEVICE(0x0489, 0xe100), .driver_info = BTUSB_QCA_WCN6855 | 386 BTUSB_WIDEBAND_SPEECH }, 387 { USB_DEVICE(0x0489, 0xe103), .driver_info = BTUSB_QCA_WCN6855 | 388 BTUSB_WIDEBAND_SPEECH }, 389 { USB_DEVICE(0x0489, 0xe10a), .driver_info = BTUSB_QCA_WCN6855 | 390 BTUSB_WIDEBAND_SPEECH }, 391 { USB_DEVICE(0x0489, 0xe10d), .driver_info = BTUSB_QCA_WCN6855 | 392 BTUSB_WIDEBAND_SPEECH }, 393 { USB_DEVICE(0x0489, 0xe11b), .driver_info = BTUSB_QCA_WCN6855 | 394 BTUSB_WIDEBAND_SPEECH }, 395 { USB_DEVICE(0x0489, 0xe11c), .driver_info = BTUSB_QCA_WCN6855 | 396 BTUSB_WIDEBAND_SPEECH }, 397 { USB_DEVICE(0x0489, 0xe11f), .driver_info = BTUSB_QCA_WCN6855 | 398 BTUSB_WIDEBAND_SPEECH }, 399 { USB_DEVICE(0x0489, 0xe141), .driver_info = BTUSB_QCA_WCN6855 | 400 BTUSB_WIDEBAND_SPEECH }, 401 { USB_DEVICE(0x0489, 0xe14a), .driver_info = BTUSB_QCA_WCN6855 | 402 BTUSB_WIDEBAND_SPEECH }, 403 { USB_DEVICE(0x0489, 0xe14b), .driver_info = BTUSB_QCA_WCN6855 | 404 BTUSB_WIDEBAND_SPEECH }, 405 { USB_DEVICE(0x0489, 0xe14d), .driver_info = BTUSB_QCA_WCN6855 | 406 BTUSB_WIDEBAND_SPEECH }, 407 { USB_DEVICE(0x13d3, 0x3623), .driver_info = BTUSB_QCA_WCN6855 | 408 BTUSB_WIDEBAND_SPEECH }, 409 { USB_DEVICE(0x13d3, 0x3624), .driver_info = BTUSB_QCA_WCN6855 | 410 BTUSB_WIDEBAND_SPEECH }, 411 { USB_DEVICE(0x2c7c, 0x0130), .driver_info = BTUSB_QCA_WCN6855 | 412 BTUSB_WIDEBAND_SPEECH }, 413 { USB_DEVICE(0x2c7c, 0x0131), .driver_info = BTUSB_QCA_WCN6855 | 414 BTUSB_WIDEBAND_SPEECH }, 415 { USB_DEVICE(0x2c7c, 0x0132), .driver_info = BTUSB_QCA_WCN6855 | 416 BTUSB_WIDEBAND_SPEECH }, 417 418 /* Broadcom BCM2035 */ 419 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 }, 420 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU }, 421 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, 422 423 /* Broadcom BCM2045 */ 424 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU }, 425 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU }, 426 427 /* IBM/Lenovo ThinkPad with Broadcom chip */ 428 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU }, 429 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU }, 430 431 /* HP laptop with Broadcom chip */ 432 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU }, 433 434 /* Dell laptop with Broadcom chip */ 435 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU }, 436 437 /* Dell Wireless 370 and 410 devices */ 438 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU }, 439 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU }, 440 441 /* Belkin F8T012 and F8T013 devices */ 442 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU }, 443 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU }, 444 445 /* Asus WL-BTD202 device */ 446 { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU }, 447 448 /* Kensington Bluetooth USB adapter */ 449 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU }, 450 451 /* RTX Telecom based adapters with buggy SCO support */ 452 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC }, 453 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC }, 454 455 /* CONWISE Technology based adapters with buggy SCO support */ 456 { USB_DEVICE(0x0e5e, 0x6622), 457 .driver_info = BTUSB_BROKEN_ISOC | BTUSB_CW6622}, 458 459 /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */ 460 { USB_DEVICE(0x1310, 0x0001), .driver_info = BTUSB_SWAVE }, 461 462 /* Digianswer devices */ 463 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER }, 464 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE }, 465 466 /* CSR BlueCore Bluetooth Sniffer */ 467 { USB_DEVICE(0x0a12, 0x0002), 468 .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC }, 469 470 /* Frontline ComProbe Bluetooth Sniffer */ 471 { USB_DEVICE(0x16d3, 0x0002), 472 .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC }, 473 474 /* Marvell Bluetooth devices */ 475 { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL }, 476 { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL }, 477 { USB_DEVICE(0x1286, 0x204e), .driver_info = BTUSB_MARVELL }, 478 479 /* Intel Bluetooth devices */ 480 { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_COMBINED }, 481 { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_COMBINED }, 482 { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_COMBINED }, 483 { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_COMBINED }, 484 { USB_DEVICE(0x8087, 0x0033), .driver_info = BTUSB_INTEL_COMBINED }, 485 { USB_DEVICE(0x8087, 0x0035), .driver_info = BTUSB_INTEL_COMBINED }, 486 { USB_DEVICE(0x8087, 0x0036), .driver_info = BTUSB_INTEL_COMBINED }, 487 { USB_DEVICE(0x8087, 0x0037), .driver_info = BTUSB_INTEL_COMBINED }, 488 { USB_DEVICE(0x8087, 0x0038), .driver_info = BTUSB_INTEL_COMBINED }, 489 { USB_DEVICE(0x8087, 0x0039), .driver_info = BTUSB_INTEL_COMBINED }, 490 { USB_DEVICE(0x8087, 0x0040), .driver_info = BTUSB_INTEL_COMBINED }, /* Lizard Peak 2 */ 491 { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, 492 { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED | 493 BTUSB_INTEL_NO_WBS_SUPPORT | 494 BTUSB_INTEL_BROKEN_INITIAL_NCMD | 495 BTUSB_INTEL_BROKEN_SHUTDOWN_LED }, 496 { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL_COMBINED | 497 BTUSB_INTEL_NO_WBS_SUPPORT | 498 BTUSB_INTEL_BROKEN_SHUTDOWN_LED }, 499 { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_COMBINED }, 500 { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL_COMBINED | 501 BTUSB_INTEL_BROKEN_SHUTDOWN_LED }, 502 { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_COMBINED }, 503 504 /* Other Intel Bluetooth devices */ 505 { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01), 506 .driver_info = BTUSB_IGNORE }, 507 508 /* Realtek 8821CE Bluetooth devices */ 509 { USB_DEVICE(0x13d3, 0x3529), .driver_info = BTUSB_REALTEK | 510 BTUSB_WIDEBAND_SPEECH }, 511 { USB_DEVICE(0x13d3, 0x3533), .driver_info = BTUSB_REALTEK | 512 BTUSB_WIDEBAND_SPEECH }, 513 514 /* Realtek 8822CE Bluetooth devices */ 515 { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK | 516 BTUSB_WIDEBAND_SPEECH }, 517 { USB_DEVICE(0x0bda, 0xc822), .driver_info = BTUSB_REALTEK | 518 BTUSB_WIDEBAND_SPEECH }, 519 520 /* Realtek 8822CU Bluetooth devices */ 521 { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK | 522 BTUSB_WIDEBAND_SPEECH }, 523 524 /* Realtek 8851BE Bluetooth devices */ 525 { USB_DEVICE(0x0bda, 0xb850), .driver_info = BTUSB_REALTEK }, 526 { USB_DEVICE(0x13d3, 0x3600), .driver_info = BTUSB_REALTEK }, 527 { USB_DEVICE(0x13d3, 0x3601), .driver_info = BTUSB_REALTEK }, 528 { USB_DEVICE(0x0489, 0xe112), .driver_info = BTUSB_REALTEK | 529 BTUSB_WIDEBAND_SPEECH }, 530 531 /* Realtek 8851BU Bluetooth devices */ 532 { USB_DEVICE(0x3625, 0x010b), .driver_info = BTUSB_REALTEK | 533 BTUSB_WIDEBAND_SPEECH }, 534 { USB_DEVICE(0x2001, 0x332a), .driver_info = BTUSB_REALTEK | 535 BTUSB_WIDEBAND_SPEECH }, 536 { USB_DEVICE(0x7392, 0xe611), .driver_info = BTUSB_REALTEK | 537 BTUSB_WIDEBAND_SPEECH }, 538 { USB_DEVICE(0x2c4e, 0x0128), .driver_info = BTUSB_REALTEK | 539 BTUSB_WIDEBAND_SPEECH }, 540 541 /* Realtek 8852AE Bluetooth devices */ 542 { USB_DEVICE(0x0bda, 0x2852), .driver_info = BTUSB_REALTEK | 543 BTUSB_WIDEBAND_SPEECH }, 544 { USB_DEVICE(0x0bda, 0xc852), .driver_info = BTUSB_REALTEK | 545 BTUSB_WIDEBAND_SPEECH }, 546 { USB_DEVICE(0x0bda, 0x385a), .driver_info = BTUSB_REALTEK | 547 BTUSB_WIDEBAND_SPEECH }, 548 { USB_DEVICE(0x0bda, 0x4852), .driver_info = BTUSB_REALTEK | 549 BTUSB_WIDEBAND_SPEECH }, 550 { USB_DEVICE(0x04c5, 0x165c), .driver_info = BTUSB_REALTEK | 551 BTUSB_WIDEBAND_SPEECH }, 552 { USB_DEVICE(0x04ca, 0x4006), .driver_info = BTUSB_REALTEK | 553 BTUSB_WIDEBAND_SPEECH }, 554 { USB_DEVICE(0x0cb8, 0xc549), .driver_info = BTUSB_REALTEK | 555 BTUSB_WIDEBAND_SPEECH }, 556 557 /* Realtek 8852CE Bluetooth devices */ 558 { USB_DEVICE(0x04ca, 0x4007), .driver_info = BTUSB_REALTEK | 559 BTUSB_WIDEBAND_SPEECH }, 560 { USB_DEVICE(0x04c5, 0x1675), .driver_info = BTUSB_REALTEK | 561 BTUSB_WIDEBAND_SPEECH }, 562 { USB_DEVICE(0x0cb8, 0xc558), .driver_info = BTUSB_REALTEK | 563 BTUSB_WIDEBAND_SPEECH }, 564 { USB_DEVICE(0x13d3, 0x3587), .driver_info = BTUSB_REALTEK | 565 BTUSB_WIDEBAND_SPEECH }, 566 { USB_DEVICE(0x13d3, 0x3586), .driver_info = BTUSB_REALTEK | 567 BTUSB_WIDEBAND_SPEECH }, 568 { USB_DEVICE(0x13d3, 0x3592), .driver_info = BTUSB_REALTEK | 569 BTUSB_WIDEBAND_SPEECH }, 570 { USB_DEVICE(0x13d3, 0x3612), .driver_info = BTUSB_REALTEK | 571 BTUSB_WIDEBAND_SPEECH }, 572 { USB_DEVICE(0x0489, 0xe122), .driver_info = BTUSB_REALTEK | 573 BTUSB_WIDEBAND_SPEECH }, 574 575 /* Realtek 8852BE Bluetooth devices */ 576 { USB_DEVICE(0x0cb8, 0xc559), .driver_info = BTUSB_REALTEK | 577 BTUSB_WIDEBAND_SPEECH }, 578 { USB_DEVICE(0x0bda, 0x4853), .driver_info = BTUSB_REALTEK | 579 BTUSB_WIDEBAND_SPEECH }, 580 { USB_DEVICE(0x0bda, 0x887b), .driver_info = BTUSB_REALTEK | 581 BTUSB_WIDEBAND_SPEECH }, 582 { USB_DEVICE(0x0bda, 0xb85b), .driver_info = BTUSB_REALTEK | 583 BTUSB_WIDEBAND_SPEECH }, 584 { USB_DEVICE(0x13d3, 0x3570), .driver_info = BTUSB_REALTEK | 585 BTUSB_WIDEBAND_SPEECH }, 586 { USB_DEVICE(0x13d3, 0x3571), .driver_info = BTUSB_REALTEK | 587 BTUSB_WIDEBAND_SPEECH }, 588 { USB_DEVICE(0x13d3, 0x3572), .driver_info = BTUSB_REALTEK | 589 BTUSB_WIDEBAND_SPEECH }, 590 { USB_DEVICE(0x13d3, 0x3591), .driver_info = BTUSB_REALTEK | 591 BTUSB_WIDEBAND_SPEECH }, 592 { USB_DEVICE(0x0489, 0xe123), .driver_info = BTUSB_REALTEK | 593 BTUSB_WIDEBAND_SPEECH }, 594 { USB_DEVICE(0x0489, 0xe125), .driver_info = BTUSB_REALTEK | 595 BTUSB_WIDEBAND_SPEECH }, 596 597 /* Realtek 8852BT/8852BE-VT Bluetooth devices */ 598 { USB_DEVICE(0x0bda, 0x8520), .driver_info = BTUSB_REALTEK | 599 BTUSB_WIDEBAND_SPEECH }, 600 { USB_DEVICE(0x0489, 0xe12f), .driver_info = BTUSB_REALTEK | 601 BTUSB_WIDEBAND_SPEECH }, 602 { USB_DEVICE(0x13d3, 0x3618), .driver_info = BTUSB_REALTEK | 603 BTUSB_WIDEBAND_SPEECH }, 604 { USB_DEVICE(0x13d3, 0x3619), .driver_info = BTUSB_REALTEK | 605 BTUSB_WIDEBAND_SPEECH }, 606 607 /* Realtek 8922AE Bluetooth devices */ 608 { USB_DEVICE(0x0bda, 0x8922), .driver_info = BTUSB_REALTEK | 609 BTUSB_WIDEBAND_SPEECH }, 610 { USB_DEVICE(0x0bda, 0xd922), .driver_info = BTUSB_REALTEK | 611 BTUSB_WIDEBAND_SPEECH }, 612 { USB_DEVICE(0x0bda, 0xd923), .driver_info = BTUSB_REALTEK | 613 BTUSB_WIDEBAND_SPEECH }, 614 { USB_DEVICE(0x13d3, 0x3617), .driver_info = BTUSB_REALTEK | 615 BTUSB_WIDEBAND_SPEECH }, 616 { USB_DEVICE(0x13d3, 0x3616), .driver_info = BTUSB_REALTEK | 617 BTUSB_WIDEBAND_SPEECH }, 618 { USB_DEVICE(0x0489, 0xe130), .driver_info = BTUSB_REALTEK | 619 BTUSB_WIDEBAND_SPEECH }, 620 621 /* Realtek 8761BU Bluetooth devices */ 622 { USB_DEVICE(0x0bda, 0xa728), .driver_info = BTUSB_REALTEK | 623 BTUSB_BROKEN_EXT_SCAN }, 624 625 /* Realtek Bluetooth devices */ 626 { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01), 627 .driver_info = BTUSB_REALTEK }, 628 629 /* MediaTek Bluetooth devices */ 630 { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01), 631 .driver_info = BTUSB_MEDIATEK | 632 BTUSB_WIDEBAND_SPEECH }, 633 634 /* Additional MediaTek MT7615E Bluetooth devices */ 635 { USB_DEVICE(0x13d3, 0x3560), .driver_info = BTUSB_MEDIATEK}, 636 637 /* Additional MediaTek MT7663 Bluetooth devices */ 638 { USB_DEVICE(0x043e, 0x310c), .driver_info = BTUSB_MEDIATEK | 639 BTUSB_WIDEBAND_SPEECH }, 640 { USB_DEVICE(0x04ca, 0x3801), .driver_info = BTUSB_MEDIATEK | 641 BTUSB_WIDEBAND_SPEECH }, 642 643 /* Additional MediaTek MT7668 Bluetooth devices */ 644 { USB_DEVICE(0x043e, 0x3109), .driver_info = BTUSB_MEDIATEK | 645 BTUSB_WIDEBAND_SPEECH }, 646 647 /* Additional MediaTek MT7920 Bluetooth devices */ 648 { USB_DEVICE(0x0489, 0xe134), .driver_info = BTUSB_MEDIATEK | 649 BTUSB_WIDEBAND_SPEECH }, 650 { USB_DEVICE(0x0489, 0xe135), .driver_info = BTUSB_MEDIATEK | 651 BTUSB_WIDEBAND_SPEECH }, 652 { USB_DEVICE(0x13d3, 0x3620), .driver_info = BTUSB_MEDIATEK | 653 BTUSB_WIDEBAND_SPEECH }, 654 { USB_DEVICE(0x13d3, 0x3621), .driver_info = BTUSB_MEDIATEK | 655 BTUSB_WIDEBAND_SPEECH }, 656 { USB_DEVICE(0x13d3, 0x3622), .driver_info = BTUSB_MEDIATEK | 657 BTUSB_WIDEBAND_SPEECH }, 658 { USB_DEVICE(0x0489, 0xe158), .driver_info = BTUSB_MEDIATEK | 659 BTUSB_WIDEBAND_SPEECH }, 660 661 /* Additional MediaTek MT7921 Bluetooth devices */ 662 { USB_DEVICE(0x0489, 0xe0c8), .driver_info = BTUSB_MEDIATEK | 663 BTUSB_WIDEBAND_SPEECH }, 664 { USB_DEVICE(0x0489, 0xe0cd), .driver_info = BTUSB_MEDIATEK | 665 BTUSB_WIDEBAND_SPEECH }, 666 { USB_DEVICE(0x0489, 0xe0e0), .driver_info = BTUSB_MEDIATEK | 667 BTUSB_WIDEBAND_SPEECH }, 668 { USB_DEVICE(0x0489, 0xe0f2), .driver_info = BTUSB_MEDIATEK | 669 BTUSB_WIDEBAND_SPEECH }, 670 { USB_DEVICE(0x04ca, 0x3802), .driver_info = BTUSB_MEDIATEK | 671 BTUSB_WIDEBAND_SPEECH }, 672 { USB_DEVICE(0x0e8d, 0x0608), .driver_info = BTUSB_MEDIATEK | 673 BTUSB_WIDEBAND_SPEECH }, 674 { USB_DEVICE(0x13d3, 0x3563), .driver_info = BTUSB_MEDIATEK | 675 BTUSB_WIDEBAND_SPEECH }, 676 { USB_DEVICE(0x13d3, 0x3564), .driver_info = BTUSB_MEDIATEK | 677 BTUSB_WIDEBAND_SPEECH }, 678 { USB_DEVICE(0x13d3, 0x3567), .driver_info = BTUSB_MEDIATEK | 679 BTUSB_WIDEBAND_SPEECH }, 680 { USB_DEVICE(0x13d3, 0x3576), .driver_info = BTUSB_MEDIATEK | 681 BTUSB_WIDEBAND_SPEECH }, 682 { USB_DEVICE(0x13d3, 0x3578), .driver_info = BTUSB_MEDIATEK | 683 BTUSB_WIDEBAND_SPEECH }, 684 { USB_DEVICE(0x13d3, 0x3583), .driver_info = BTUSB_MEDIATEK | 685 BTUSB_WIDEBAND_SPEECH }, 686 { USB_DEVICE(0x13d3, 0x3606), .driver_info = BTUSB_MEDIATEK | 687 BTUSB_WIDEBAND_SPEECH }, 688 /* MediaTek MT7902 Bluetooth devices */ 689 { USB_DEVICE(0x0489, 0xe156), .driver_info = BTUSB_MEDIATEK | 690 BTUSB_WIDEBAND_SPEECH }, 691 { USB_DEVICE(0x0e8d, 0x1ede), .driver_info = BTUSB_MEDIATEK | 692 BTUSB_WIDEBAND_SPEECH }, 693 { USB_DEVICE(0x13d3, 0x3579), .driver_info = BTUSB_MEDIATEK | 694 BTUSB_WIDEBAND_SPEECH }, 695 { USB_DEVICE(0x13d3, 0x3580), .driver_info = BTUSB_MEDIATEK | 696 BTUSB_WIDEBAND_SPEECH }, 697 { USB_DEVICE(0x13d3, 0x3594), .driver_info = BTUSB_MEDIATEK | 698 BTUSB_WIDEBAND_SPEECH }, 699 { USB_DEVICE(0x13d3, 0x3596), .driver_info = BTUSB_MEDIATEK | 700 BTUSB_WIDEBAND_SPEECH }, 701 /* MediaTek MT7922 Bluetooth devices */ 702 { USB_DEVICE(0x13d3, 0x3585), .driver_info = BTUSB_MEDIATEK | 703 BTUSB_WIDEBAND_SPEECH }, 704 { USB_DEVICE(0x13d3, 0x3610), .driver_info = BTUSB_MEDIATEK | 705 BTUSB_WIDEBAND_SPEECH }, 706 707 /* MediaTek MT7922A Bluetooth devices */ 708 { USB_DEVICE(0x0489, 0xe0d8), .driver_info = BTUSB_MEDIATEK | 709 BTUSB_WIDEBAND_SPEECH }, 710 { USB_DEVICE(0x0489, 0xe0d9), .driver_info = BTUSB_MEDIATEK | 711 BTUSB_WIDEBAND_SPEECH }, 712 { USB_DEVICE(0x0489, 0xe0e2), .driver_info = BTUSB_MEDIATEK | 713 BTUSB_WIDEBAND_SPEECH }, 714 { USB_DEVICE(0x0489, 0xe0e4), .driver_info = BTUSB_MEDIATEK | 715 BTUSB_WIDEBAND_SPEECH }, 716 { USB_DEVICE(0x0489, 0xe0f1), .driver_info = BTUSB_MEDIATEK | 717 BTUSB_WIDEBAND_SPEECH }, 718 { USB_DEVICE(0x0489, 0xe0f2), .driver_info = BTUSB_MEDIATEK | 719 BTUSB_WIDEBAND_SPEECH }, 720 { USB_DEVICE(0x0489, 0xe0f5), .driver_info = BTUSB_MEDIATEK | 721 BTUSB_WIDEBAND_SPEECH }, 722 { USB_DEVICE(0x0489, 0xe0f6), .driver_info = BTUSB_MEDIATEK | 723 BTUSB_WIDEBAND_SPEECH }, 724 { USB_DEVICE(0x0489, 0xe102), .driver_info = BTUSB_MEDIATEK | 725 BTUSB_WIDEBAND_SPEECH }, 726 { USB_DEVICE(0x0489, 0xe11d), .driver_info = BTUSB_MEDIATEK | 727 BTUSB_WIDEBAND_SPEECH }, 728 { USB_DEVICE(0x0489, 0xe152), .driver_info = BTUSB_MEDIATEK | 729 BTUSB_WIDEBAND_SPEECH }, 730 { USB_DEVICE(0x0489, 0xe153), .driver_info = BTUSB_MEDIATEK | 731 BTUSB_WIDEBAND_SPEECH }, 732 { USB_DEVICE(0x0489, 0xe170), .driver_info = BTUSB_MEDIATEK | 733 BTUSB_WIDEBAND_SPEECH }, 734 { USB_DEVICE(0x0489, 0xe174), .driver_info = BTUSB_MEDIATEK | 735 BTUSB_WIDEBAND_SPEECH }, 736 { USB_DEVICE(0x04ca, 0x3804), .driver_info = BTUSB_MEDIATEK | 737 BTUSB_WIDEBAND_SPEECH }, 738 { USB_DEVICE(0x04ca, 0x3807), .driver_info = BTUSB_MEDIATEK | 739 BTUSB_WIDEBAND_SPEECH }, 740 { USB_DEVICE(0x04ca, 0x38e4), .driver_info = BTUSB_MEDIATEK | 741 BTUSB_WIDEBAND_SPEECH }, 742 { USB_DEVICE(0x0e8d, 0x223c), .driver_info = BTUSB_MEDIATEK | 743 BTUSB_WIDEBAND_SPEECH }, 744 { USB_DEVICE(0x13d3, 0x3568), .driver_info = BTUSB_MEDIATEK | 745 BTUSB_WIDEBAND_SPEECH }, 746 { USB_DEVICE(0x13d3, 0x3584), .driver_info = BTUSB_MEDIATEK | 747 BTUSB_WIDEBAND_SPEECH }, 748 { USB_DEVICE(0x13d3, 0x3605), .driver_info = BTUSB_MEDIATEK | 749 BTUSB_WIDEBAND_SPEECH }, 750 { USB_DEVICE(0x13d3, 0x3607), .driver_info = BTUSB_MEDIATEK | 751 BTUSB_WIDEBAND_SPEECH }, 752 { USB_DEVICE(0x13d3, 0x3614), .driver_info = BTUSB_MEDIATEK | 753 BTUSB_WIDEBAND_SPEECH }, 754 { USB_DEVICE(0x13d3, 0x3615), .driver_info = BTUSB_MEDIATEK | 755 BTUSB_WIDEBAND_SPEECH }, 756 { USB_DEVICE(0x13d3, 0x3633), .driver_info = BTUSB_MEDIATEK | 757 BTUSB_WIDEBAND_SPEECH }, 758 { USB_DEVICE(0x35f5, 0x7922), .driver_info = BTUSB_MEDIATEK | 759 BTUSB_WIDEBAND_SPEECH }, 760 761 /* Additional MediaTek MT7925 Bluetooth devices */ 762 { USB_DEVICE(0x0489, 0xe111), .driver_info = BTUSB_MEDIATEK | 763 BTUSB_WIDEBAND_SPEECH }, 764 { USB_DEVICE(0x0489, 0xe113), .driver_info = BTUSB_MEDIATEK | 765 BTUSB_WIDEBAND_SPEECH }, 766 { USB_DEVICE(0x0489, 0xe118), .driver_info = BTUSB_MEDIATEK | 767 BTUSB_WIDEBAND_SPEECH }, 768 { USB_DEVICE(0x0489, 0xe11e), .driver_info = BTUSB_MEDIATEK | 769 BTUSB_WIDEBAND_SPEECH }, 770 { USB_DEVICE(0x0489, 0xe124), .driver_info = BTUSB_MEDIATEK | 771 BTUSB_WIDEBAND_SPEECH }, 772 { USB_DEVICE(0x0489, 0xe139), .driver_info = BTUSB_MEDIATEK | 773 BTUSB_WIDEBAND_SPEECH }, 774 { USB_DEVICE(0x0489, 0xe13a), .driver_info = BTUSB_MEDIATEK | 775 BTUSB_WIDEBAND_SPEECH }, 776 { USB_DEVICE(0x0489, 0xe0fa), .driver_info = BTUSB_MEDIATEK | 777 BTUSB_WIDEBAND_SPEECH }, 778 { USB_DEVICE(0x0489, 0xe10f), .driver_info = BTUSB_MEDIATEK | 779 BTUSB_WIDEBAND_SPEECH }, 780 { USB_DEVICE(0x0489, 0xe110), .driver_info = BTUSB_MEDIATEK | 781 BTUSB_WIDEBAND_SPEECH }, 782 { USB_DEVICE(0x0489, 0xe116), .driver_info = BTUSB_MEDIATEK | 783 BTUSB_WIDEBAND_SPEECH }, 784 { USB_DEVICE(0x13d3, 0x3588), .driver_info = BTUSB_MEDIATEK | 785 BTUSB_WIDEBAND_SPEECH }, 786 { USB_DEVICE(0x0489, 0xe14e), .driver_info = BTUSB_MEDIATEK | 787 BTUSB_WIDEBAND_SPEECH }, 788 { USB_DEVICE(0x0489, 0xe14f), .driver_info = BTUSB_MEDIATEK | 789 BTUSB_WIDEBAND_SPEECH }, 790 { USB_DEVICE(0x0489, 0xe150), .driver_info = BTUSB_MEDIATEK | 791 BTUSB_WIDEBAND_SPEECH }, 792 { USB_DEVICE(0x0489, 0xe151), .driver_info = BTUSB_MEDIATEK | 793 BTUSB_WIDEBAND_SPEECH }, 794 { USB_DEVICE(0x0e8d, 0x8c38), .driver_info = BTUSB_MEDIATEK | 795 BTUSB_WIDEBAND_SPEECH }, 796 { USB_DEVICE(0x13d3, 0x3602), .driver_info = BTUSB_MEDIATEK | 797 BTUSB_WIDEBAND_SPEECH }, 798 { USB_DEVICE(0x13d3, 0x3603), .driver_info = BTUSB_MEDIATEK | 799 BTUSB_WIDEBAND_SPEECH }, 800 { USB_DEVICE(0x13d3, 0x3604), .driver_info = BTUSB_MEDIATEK | 801 BTUSB_WIDEBAND_SPEECH }, 802 { USB_DEVICE(0x13d3, 0x3608), .driver_info = BTUSB_MEDIATEK | 803 BTUSB_WIDEBAND_SPEECH }, 804 { USB_DEVICE(0x13d3, 0x3609), .driver_info = BTUSB_MEDIATEK | 805 BTUSB_WIDEBAND_SPEECH }, 806 { USB_DEVICE(0x13d3, 0x3613), .driver_info = BTUSB_MEDIATEK | 807 BTUSB_WIDEBAND_SPEECH }, 808 { USB_DEVICE(0x13d3, 0x3625), .driver_info = BTUSB_MEDIATEK | 809 BTUSB_WIDEBAND_SPEECH }, 810 { USB_DEVICE(0x13d3, 0x3627), .driver_info = BTUSB_MEDIATEK | 811 BTUSB_WIDEBAND_SPEECH }, 812 { USB_DEVICE(0x13d3, 0x3628), .driver_info = BTUSB_MEDIATEK | 813 BTUSB_WIDEBAND_SPEECH }, 814 { USB_DEVICE(0x13d3, 0x3630), .driver_info = BTUSB_MEDIATEK | 815 BTUSB_WIDEBAND_SPEECH }, 816 { USB_DEVICE(0x2c7c, 0x7009), .driver_info = BTUSB_MEDIATEK | 817 BTUSB_WIDEBAND_SPEECH }, 818 819 /* Additional Realtek 8723AE Bluetooth devices */ 820 { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK }, 821 { USB_DEVICE(0x13d3, 0x3394), .driver_info = BTUSB_REALTEK }, 822 823 /* Additional Realtek 8723BE Bluetooth devices */ 824 { USB_DEVICE(0x0489, 0xe085), .driver_info = BTUSB_REALTEK }, 825 { USB_DEVICE(0x0489, 0xe08b), .driver_info = BTUSB_REALTEK }, 826 { USB_DEVICE(0x04f2, 0xb49f), .driver_info = BTUSB_REALTEK }, 827 { USB_DEVICE(0x13d3, 0x3410), .driver_info = BTUSB_REALTEK }, 828 { USB_DEVICE(0x13d3, 0x3416), .driver_info = BTUSB_REALTEK }, 829 { USB_DEVICE(0x13d3, 0x3459), .driver_info = BTUSB_REALTEK }, 830 { USB_DEVICE(0x13d3, 0x3494), .driver_info = BTUSB_REALTEK }, 831 832 /* Additional Realtek 8723BU Bluetooth devices */ 833 { USB_DEVICE(0x7392, 0xa611), .driver_info = BTUSB_REALTEK }, 834 { USB_DEVICE(0x2c0a, 0x8761), .driver_info = BTUSB_REALTEK }, 835 836 /* Additional Realtek 8723DE Bluetooth devices */ 837 { USB_DEVICE(0x0bda, 0xb009), .driver_info = BTUSB_REALTEK }, 838 { USB_DEVICE(0x2ff8, 0xb011), .driver_info = BTUSB_REALTEK }, 839 840 /* Additional Realtek 8761BUV Bluetooth devices */ 841 { USB_DEVICE(0x2c4e, 0x0115), .driver_info = BTUSB_REALTEK | 842 BTUSB_WIDEBAND_SPEECH }, 843 { USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK | 844 BTUSB_WIDEBAND_SPEECH }, 845 { USB_DEVICE(0x2357, 0x0607), .driver_info = BTUSB_REALTEK | 846 BTUSB_WIDEBAND_SPEECH }, 847 { USB_DEVICE(0x0b05, 0x190e), .driver_info = BTUSB_REALTEK | 848 BTUSB_WIDEBAND_SPEECH }, 849 { USB_DEVICE(0x2550, 0x8761), .driver_info = BTUSB_REALTEK | 850 BTUSB_WIDEBAND_SPEECH }, 851 { USB_DEVICE(0x0bda, 0x8771), .driver_info = BTUSB_REALTEK | 852 BTUSB_WIDEBAND_SPEECH }, 853 { USB_DEVICE(0x6655, 0x8771), .driver_info = BTUSB_REALTEK | 854 BTUSB_WIDEBAND_SPEECH }, 855 { USB_DEVICE(0x7392, 0xc611), .driver_info = BTUSB_REALTEK | 856 BTUSB_WIDEBAND_SPEECH }, 857 { USB_DEVICE(0x2b89, 0x8761), .driver_info = BTUSB_REALTEK | 858 BTUSB_WIDEBAND_SPEECH }, 859 { USB_DEVICE(0x2b89, 0x6275), .driver_info = BTUSB_REALTEK | 860 BTUSB_WIDEBAND_SPEECH }, 861 { USB_DEVICE(0x37ad, 0x0600), .driver_info = BTUSB_REALTEK | 862 BTUSB_WIDEBAND_SPEECH }, 863 864 /* Additional Realtek 8761CU Bluetooth devices */ 865 { USB_DEVICE(0x0b05, 0x1bef), .driver_info = BTUSB_REALTEK | 866 BTUSB_WIDEBAND_SPEECH }, 867 { USB_DEVICE(0x0b05, 0x1d70), .driver_info = BTUSB_REALTEK | 868 BTUSB_WIDEBAND_SPEECH }, 869 870 /* Additional Realtek 8821AE Bluetooth devices */ 871 { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK }, 872 { USB_DEVICE(0x13d3, 0x3414), .driver_info = BTUSB_REALTEK }, 873 { USB_DEVICE(0x13d3, 0x3458), .driver_info = BTUSB_REALTEK }, 874 { USB_DEVICE(0x13d3, 0x3461), .driver_info = BTUSB_REALTEK }, 875 { USB_DEVICE(0x13d3, 0x3462), .driver_info = BTUSB_REALTEK }, 876 877 /* Additional Realtek 8822BE Bluetooth devices */ 878 { USB_DEVICE(0x13d3, 0x3526), .driver_info = BTUSB_REALTEK }, 879 { USB_DEVICE(0x0b05, 0x185c), .driver_info = BTUSB_REALTEK }, 880 881 /* Additional Realtek 8822CE Bluetooth devices */ 882 { USB_DEVICE(0x04ca, 0x4005), .driver_info = BTUSB_REALTEK | 883 BTUSB_WIDEBAND_SPEECH }, 884 { USB_DEVICE(0x04c5, 0x161f), .driver_info = BTUSB_REALTEK | 885 BTUSB_WIDEBAND_SPEECH }, 886 { USB_DEVICE(0x0b05, 0x18ef), .driver_info = BTUSB_REALTEK | 887 BTUSB_WIDEBAND_SPEECH }, 888 { USB_DEVICE(0x13d3, 0x3548), .driver_info = BTUSB_REALTEK | 889 BTUSB_WIDEBAND_SPEECH }, 890 { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK | 891 BTUSB_WIDEBAND_SPEECH }, 892 { USB_DEVICE(0x13d3, 0x3553), .driver_info = BTUSB_REALTEK | 893 BTUSB_WIDEBAND_SPEECH }, 894 { USB_DEVICE(0x13d3, 0x3555), .driver_info = BTUSB_REALTEK | 895 BTUSB_WIDEBAND_SPEECH }, 896 { USB_DEVICE(0x2ff8, 0x3051), .driver_info = BTUSB_REALTEK | 897 BTUSB_WIDEBAND_SPEECH }, 898 { USB_DEVICE(0x1358, 0xc123), .driver_info = BTUSB_REALTEK | 899 BTUSB_WIDEBAND_SPEECH }, 900 { USB_DEVICE(0x0bda, 0xc123), .driver_info = BTUSB_REALTEK | 901 BTUSB_WIDEBAND_SPEECH }, 902 { USB_DEVICE(0x1357, 0xc123), .driver_info = BTUSB_REALTEK | 903 BTUSB_WIDEBAND_SPEECH }, 904 { USB_DEVICE(0x0cb5, 0xc547), .driver_info = BTUSB_REALTEK | 905 BTUSB_WIDEBAND_SPEECH }, 906 907 /* Barrot Technology Bluetooth devices */ 908 { USB_DEVICE(0x33fa, 0x0010), .driver_info = BTUSB_BARROT }, 909 { USB_DEVICE(0x33fa, 0x0012), .driver_info = BTUSB_BARROT }, 910 911 /* Actions Semiconductor ATS2851 based devices */ 912 { USB_DEVICE(0x10d7, 0xb012), .driver_info = BTUSB_ACTIONS_SEMI }, 913 914 /* Silicon Wave based devices */ 915 { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE }, 916 917 { } /* Terminating entry */ 918 }; 919 920 /* The Bluetooth USB module build into some devices needs to be reset on resume, 921 * this is a problem with the platform (likely shutting off all power) not with 922 * the module itself. So we use a DMI list to match known broken platforms. 923 */ 924 static const struct dmi_system_id btusb_needs_reset_resume_table[] = { 925 { 926 /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */ 927 .matches = { 928 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 929 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 3060"), 930 }, 931 }, 932 { 933 /* Dell XPS 9360 (QCA ROME device 0cf3:e300) */ 934 .matches = { 935 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 936 DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"), 937 }, 938 }, 939 { 940 /* Dell Inspiron 5565 (QCA ROME device 0cf3:e009) */ 941 .matches = { 942 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 943 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5565"), 944 }, 945 }, 946 {} 947 }; 948 949 struct qca_dump_info { 950 /* fields for dump collection */ 951 u16 id_vendor; 952 u16 id_product; 953 u32 fw_version; 954 u32 controller_id; 955 u32 ram_dump_size; 956 u16 ram_dump_seqno; 957 }; 958 959 struct btqca_data { 960 struct qca_dump_info qca_dump; 961 }; 962 963 #define BTUSB_MAX_ISOC_FRAMES 10 964 965 #define BTUSB_INTR_RUNNING 0 966 #define BTUSB_BULK_RUNNING 1 967 #define BTUSB_ISOC_RUNNING 2 968 #define BTUSB_SUSPENDING 3 969 #define BTUSB_DID_ISO_RESUME 4 970 #define BTUSB_BOOTLOADER 5 971 #define BTUSB_DOWNLOADING 6 972 #define BTUSB_FIRMWARE_LOADED 7 973 #define BTUSB_FIRMWARE_FAILED 8 974 #define BTUSB_BOOTING 9 975 #define BTUSB_DIAG_RUNNING 10 976 #define BTUSB_OOB_WAKE_ENABLED 11 977 #define BTUSB_HW_RESET_ACTIVE 12 978 #define BTUSB_TX_WAIT_VND_EVT 13 979 #define BTUSB_WAKEUP_AUTOSUSPEND 14 980 #define BTUSB_USE_ALT3_FOR_WBS 15 981 #define BTUSB_ALT6_CONTINUOUS_TX 16 982 #define BTUSB_HW_SSR_ACTIVE 17 983 984 struct btusb_data { 985 struct hci_dev *hdev; 986 struct usb_device *udev; 987 struct usb_interface *intf; 988 struct usb_interface *isoc; 989 struct usb_interface *diag; 990 unsigned isoc_ifnum; 991 992 unsigned long flags; 993 994 bool poll_sync; 995 int intr_interval; 996 struct work_struct work; 997 struct work_struct waker; 998 struct delayed_work rx_work; 999 1000 struct sk_buff_head acl_q; 1001 1002 struct usb_anchor deferred; 1003 struct usb_anchor tx_anchor; 1004 int tx_in_flight; 1005 spinlock_t txlock; 1006 1007 struct usb_anchor intr_anchor; 1008 struct usb_anchor bulk_anchor; 1009 struct usb_anchor isoc_anchor; 1010 struct usb_anchor diag_anchor; 1011 struct usb_anchor ctrl_anchor; 1012 spinlock_t rxlock; 1013 1014 struct sk_buff *evt_skb; 1015 struct sk_buff *acl_skb; 1016 struct sk_buff *sco_skb; 1017 1018 struct usb_endpoint_descriptor *intr_ep; 1019 struct usb_endpoint_descriptor *bulk_tx_ep; 1020 struct usb_endpoint_descriptor *bulk_rx_ep; 1021 struct usb_endpoint_descriptor *isoc_tx_ep; 1022 struct usb_endpoint_descriptor *isoc_rx_ep; 1023 struct usb_endpoint_descriptor *diag_tx_ep; 1024 struct usb_endpoint_descriptor *diag_rx_ep; 1025 1026 struct gpio_desc *reset_gpio; 1027 1028 __u8 cmdreq_type; 1029 __u8 cmdreq; 1030 1031 unsigned int sco_num; 1032 unsigned int air_mode; 1033 bool usb_alt6_packet_flow; 1034 int isoc_altsetting; 1035 int suspend_count; 1036 const struct usb_device_id *match_id; 1037 1038 int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb); 1039 int (*recv_acl)(struct hci_dev *hdev, struct sk_buff *skb); 1040 int (*recv_bulk)(struct btusb_data *data, void *buffer, int count); 1041 1042 int (*setup_on_usb)(struct hci_dev *hdev); 1043 1044 int (*suspend)(struct hci_dev *hdev); 1045 int (*resume)(struct hci_dev *hdev); 1046 int (*disconnect)(struct hci_dev *hdev); 1047 1048 int oob_wake_irq; /* irq for out-of-band wake-on-bt */ 1049 }; 1050 1051 static void btusb_reset(struct hci_dev *hdev) 1052 { 1053 struct btusb_data *data; 1054 int err; 1055 1056 data = hci_get_drvdata(hdev); 1057 /* This is not an unbalanced PM reference since the device will reset */ 1058 err = usb_autopm_get_interface(data->intf); 1059 if (err) { 1060 bt_dev_err(hdev, "Failed usb_autopm_get_interface: %d", err); 1061 return; 1062 } 1063 1064 bt_dev_err(hdev, "Resetting usb device."); 1065 usb_queue_reset_device(data->intf); 1066 } 1067 1068 static void btusb_intel_reset(struct hci_dev *hdev) 1069 { 1070 struct btusb_data *data = hci_get_drvdata(hdev); 1071 struct gpio_desc *reset_gpio = data->reset_gpio; 1072 struct btintel_data *intel_data = hci_get_priv(hdev); 1073 1074 if (intel_data->acpi_reset_method) { 1075 if (test_and_set_bit(INTEL_ACPI_RESET_ACTIVE, intel_data->flags)) { 1076 bt_dev_err(hdev, "acpi: last reset failed ? Not resetting again"); 1077 return; 1078 } 1079 1080 bt_dev_err(hdev, "Initiating acpi reset method"); 1081 /* If ACPI reset method fails, lets try with legacy GPIO 1082 * toggling 1083 */ 1084 if (!intel_data->acpi_reset_method(hdev)) { 1085 return; 1086 } 1087 } 1088 1089 if (!reset_gpio) { 1090 btusb_reset(hdev); 1091 return; 1092 } 1093 1094 /* 1095 * Toggle the hard reset line if the platform provides one. The reset 1096 * is going to yank the device off the USB and then replug. So doing 1097 * once is enough. The cleanup is handled correctly on the way out 1098 * (standard USB disconnect), and the new device is detected cleanly 1099 * and bound to the driver again like it should be. 1100 */ 1101 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { 1102 bt_dev_err(hdev, "last reset failed? Not resetting again"); 1103 return; 1104 } 1105 1106 bt_dev_err(hdev, "Initiating HW reset via gpio"); 1107 gpiod_set_value_cansleep(reset_gpio, 1); 1108 msleep(100); 1109 gpiod_set_value_cansleep(reset_gpio, 0); 1110 } 1111 1112 #define RTK_DEVCOREDUMP_CODE_MEMDUMP 0x01 1113 #define RTK_DEVCOREDUMP_CODE_HW_ERR 0x02 1114 #define RTK_DEVCOREDUMP_CODE_CMD_TIMEOUT 0x03 1115 1116 #define RTK_SUB_EVENT_CODE_COREDUMP 0x34 1117 1118 struct rtk_dev_coredump_hdr { 1119 u8 type; 1120 u8 code; 1121 u8 reserved[2]; 1122 } __packed; 1123 1124 static inline void btusb_rtl_alloc_devcoredump(struct hci_dev *hdev, 1125 struct rtk_dev_coredump_hdr *hdr, u8 *buf, u32 len) 1126 { 1127 struct sk_buff *skb; 1128 1129 skb = alloc_skb(len + sizeof(*hdr), GFP_ATOMIC); 1130 if (!skb) 1131 return; 1132 1133 skb_put_data(skb, hdr, sizeof(*hdr)); 1134 if (len) 1135 skb_put_data(skb, buf, len); 1136 1137 if (!hci_devcd_init(hdev, skb->len)) { 1138 hci_devcd_append(hdev, skb); 1139 hci_devcd_complete(hdev); 1140 } else { 1141 bt_dev_err(hdev, "RTL: Failed to generate devcoredump"); 1142 kfree_skb(skb); 1143 } 1144 } 1145 1146 static void btusb_rtl_reset(struct hci_dev *hdev) 1147 { 1148 struct btusb_data *data = hci_get_drvdata(hdev); 1149 struct gpio_desc *reset_gpio = data->reset_gpio; 1150 struct rtk_dev_coredump_hdr hdr = { 1151 .type = RTK_DEVCOREDUMP_CODE_CMD_TIMEOUT, 1152 }; 1153 1154 btusb_rtl_alloc_devcoredump(hdev, &hdr, NULL, 0); 1155 1156 if (!reset_gpio) { 1157 btusb_reset(hdev); 1158 return; 1159 } 1160 1161 /* Toggle the hard reset line. The Realtek device is going to 1162 * yank itself off the USB and then replug. The cleanup is handled 1163 * correctly on the way out (standard USB disconnect), and the new 1164 * device is detected cleanly and bound to the driver again like 1165 * it should be. 1166 */ 1167 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { 1168 bt_dev_err(hdev, "last reset failed? Not resetting again"); 1169 return; 1170 } 1171 1172 bt_dev_err(hdev, "Reset Realtek device via gpio"); 1173 gpiod_set_value_cansleep(reset_gpio, 1); 1174 msleep(200); 1175 gpiod_set_value_cansleep(reset_gpio, 0); 1176 } 1177 1178 static void btusb_rtl_hw_error(struct hci_dev *hdev, u8 code) 1179 { 1180 struct rtk_dev_coredump_hdr hdr = { 1181 .type = RTK_DEVCOREDUMP_CODE_HW_ERR, 1182 .code = code, 1183 }; 1184 1185 bt_dev_err(hdev, "RTL: hw err, trigger devcoredump (%d)", code); 1186 1187 btusb_rtl_alloc_devcoredump(hdev, &hdr, NULL, 0); 1188 } 1189 1190 static void btusb_qca_reset(struct hci_dev *hdev) 1191 { 1192 struct btusb_data *data = hci_get_drvdata(hdev); 1193 struct gpio_desc *reset_gpio = data->reset_gpio; 1194 1195 if (test_bit(BTUSB_HW_SSR_ACTIVE, &data->flags)) { 1196 bt_dev_info(hdev, "Ramdump in progress, defer reset"); 1197 return; 1198 } 1199 1200 if (reset_gpio) { 1201 bt_dev_err(hdev, "Reset qca device via bt_en gpio"); 1202 1203 /* Toggle the hard reset line. The qca bt device is going to 1204 * yank itself off the USB and then replug. The cleanup is handled 1205 * correctly on the way out (standard USB disconnect), and the new 1206 * device is detected cleanly and bound to the driver again like 1207 * it should be. 1208 */ 1209 if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { 1210 bt_dev_err(hdev, "last reset failed? Not resetting again"); 1211 return; 1212 } 1213 1214 gpiod_set_value_cansleep(reset_gpio, 0); 1215 msleep(200); 1216 gpiod_set_value_cansleep(reset_gpio, 1); 1217 1218 return; 1219 } 1220 1221 btusb_reset(hdev); 1222 } 1223 1224 static u8 btusb_classify_qca_pkt_type(struct hci_dev *hdev, struct sk_buff *skb) 1225 { 1226 /* Some Qualcomm controllers, e.g., QCNFA765 with WCN6855 chip, send debug 1227 * packets as ACL frames with connection handle 0x2EDC. These are not real 1228 * ACL packets and should be reclassified as HCI_DIAG_PKT to prevent 1229 * "ACL packet for unknown connection handle 3804" errors. 1230 */ 1231 if (skb->len >= 2) { 1232 u16 handle = get_unaligned_le16(skb->data); 1233 1234 if (handle == 0x2EDC) 1235 return HCI_DIAG_PKT; 1236 } 1237 1238 /* Use default packet type for other packets */ 1239 return hci_skb_pkt_type(skb); 1240 } 1241 1242 static inline void btusb_free_frags(struct btusb_data *data) 1243 { 1244 unsigned long flags; 1245 1246 spin_lock_irqsave(&data->rxlock, flags); 1247 1248 dev_kfree_skb_irq(data->evt_skb); 1249 data->evt_skb = NULL; 1250 1251 dev_kfree_skb_irq(data->acl_skb); 1252 data->acl_skb = NULL; 1253 1254 dev_kfree_skb_irq(data->sco_skb); 1255 data->sco_skb = NULL; 1256 1257 spin_unlock_irqrestore(&data->rxlock, flags); 1258 } 1259 1260 static int btusb_recv_event(struct hci_dev *hdev, struct sk_buff *skb) 1261 { 1262 struct btusb_data *data = hci_get_drvdata(hdev); 1263 1264 if (data->intr_interval) { 1265 /* Trigger dequeue immediately if an event is received */ 1266 schedule_delayed_work(&data->rx_work, 0); 1267 } 1268 1269 return data->recv_event(hdev, skb); 1270 } 1271 1272 static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count) 1273 { 1274 struct sk_buff *skb; 1275 unsigned long flags; 1276 int err = 0; 1277 1278 spin_lock_irqsave(&data->rxlock, flags); 1279 skb = data->evt_skb; 1280 1281 while (count) { 1282 int len; 1283 1284 if (!skb) { 1285 skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC); 1286 if (!skb) { 1287 err = -ENOMEM; 1288 break; 1289 } 1290 1291 hci_skb_pkt_type(skb) = HCI_EVENT_PKT; 1292 hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE; 1293 } 1294 1295 len = min_t(uint, hci_skb_expect(skb), count); 1296 skb_put_data(skb, buffer, len); 1297 1298 count -= len; 1299 buffer += len; 1300 hci_skb_expect(skb) -= len; 1301 1302 if (skb->len == HCI_EVENT_HDR_SIZE) { 1303 /* Complete event header */ 1304 hci_skb_expect(skb) = hci_event_hdr(skb)->plen; 1305 1306 if (skb_tailroom(skb) < hci_skb_expect(skb)) { 1307 kfree_skb(skb); 1308 skb = NULL; 1309 1310 err = -EILSEQ; 1311 break; 1312 } 1313 } 1314 1315 if (!hci_skb_expect(skb)) { 1316 /* Each chunk should correspond to at least 1 or more 1317 * events so if there are still bytes left that doesn't 1318 * constitute a new event this is likely a bug in the 1319 * controller. 1320 */ 1321 if (count && count < HCI_EVENT_HDR_SIZE) { 1322 bt_dev_warn(data->hdev, 1323 "Unexpected continuation: %d bytes", 1324 count); 1325 count = 0; 1326 } 1327 1328 /* Complete frame */ 1329 btusb_recv_event(data->hdev, skb); 1330 skb = NULL; 1331 } 1332 } 1333 1334 data->evt_skb = skb; 1335 spin_unlock_irqrestore(&data->rxlock, flags); 1336 1337 return err; 1338 } 1339 1340 static int btusb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) 1341 { 1342 struct btusb_data *data = hci_get_drvdata(hdev); 1343 1344 /* Only queue ACL packet if intr_interval is set as it means 1345 * force_poll_sync has been enabled. 1346 */ 1347 if (!data->intr_interval) 1348 return data->recv_acl(hdev, skb); 1349 1350 skb_queue_tail(&data->acl_q, skb); 1351 schedule_delayed_work(&data->rx_work, data->intr_interval); 1352 1353 return 0; 1354 } 1355 1356 static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count) 1357 { 1358 struct sk_buff *skb; 1359 unsigned long flags; 1360 int err = 0; 1361 1362 spin_lock_irqsave(&data->rxlock, flags); 1363 skb = data->acl_skb; 1364 1365 while (count) { 1366 int len; 1367 1368 if (!skb) { 1369 skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); 1370 if (!skb) { 1371 err = -ENOMEM; 1372 break; 1373 } 1374 1375 hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT; 1376 hci_skb_expect(skb) = HCI_ACL_HDR_SIZE; 1377 } 1378 1379 len = min_t(uint, hci_skb_expect(skb), count); 1380 skb_put_data(skb, buffer, len); 1381 1382 count -= len; 1383 buffer += len; 1384 hci_skb_expect(skb) -= len; 1385 1386 if (skb->len == HCI_ACL_HDR_SIZE) { 1387 /* Complete ACL header */ 1388 hci_skb_expect(skb) = hci_acl_dlen(skb); 1389 1390 if (skb_tailroom(skb) < hci_skb_expect(skb)) { 1391 kfree_skb(skb); 1392 skb = NULL; 1393 1394 err = -EILSEQ; 1395 break; 1396 } 1397 } 1398 1399 if (!hci_skb_expect(skb)) { 1400 /* Complete frame */ 1401 btusb_recv_acl(data->hdev, skb); 1402 skb = NULL; 1403 } 1404 } 1405 1406 data->acl_skb = skb; 1407 spin_unlock_irqrestore(&data->rxlock, flags); 1408 1409 return err; 1410 } 1411 1412 static bool btusb_validate_sco_handle(struct hci_dev *hdev, 1413 struct hci_sco_hdr *hdr) 1414 { 1415 __u16 handle; 1416 1417 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) 1418 // Can't validate, userspace controls everything. 1419 return true; 1420 1421 /* 1422 * USB isochronous transfers are not designed to be reliable and may 1423 * lose fragments. When this happens, the next first fragment 1424 * encountered might actually be a continuation fragment. 1425 * Validate the handle to detect it and drop it, or else the upper 1426 * layer will get garbage for a while. 1427 */ 1428 1429 handle = hci_handle(__le16_to_cpu(hdr->handle)); 1430 1431 switch (hci_conn_lookup_type(hdev, handle)) { 1432 case SCO_LINK: 1433 case ESCO_LINK: 1434 return true; 1435 default: 1436 return false; 1437 } 1438 } 1439 1440 static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count) 1441 { 1442 struct sk_buff *skb; 1443 unsigned long flags; 1444 int err = 0; 1445 1446 spin_lock_irqsave(&data->rxlock, flags); 1447 skb = data->sco_skb; 1448 1449 while (count) { 1450 int len; 1451 1452 if (!skb) { 1453 skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC); 1454 if (!skb) { 1455 err = -ENOMEM; 1456 break; 1457 } 1458 1459 hci_skb_pkt_type(skb) = HCI_SCODATA_PKT; 1460 hci_skb_expect(skb) = HCI_SCO_HDR_SIZE; 1461 } 1462 1463 len = min_t(uint, hci_skb_expect(skb), count); 1464 skb_put_data(skb, buffer, len); 1465 1466 count -= len; 1467 buffer += len; 1468 hci_skb_expect(skb) -= len; 1469 1470 if (skb->len == HCI_SCO_HDR_SIZE) { 1471 /* Complete SCO header */ 1472 struct hci_sco_hdr *hdr = hci_sco_hdr(skb); 1473 1474 hci_skb_expect(skb) = hdr->dlen; 1475 1476 if (skb_tailroom(skb) < hci_skb_expect(skb) || 1477 !btusb_validate_sco_handle(data->hdev, hdr)) { 1478 kfree_skb(skb); 1479 skb = NULL; 1480 1481 err = -EILSEQ; 1482 break; 1483 } 1484 } 1485 1486 if (!hci_skb_expect(skb)) { 1487 /* Complete frame */ 1488 hci_recv_frame(data->hdev, skb); 1489 skb = NULL; 1490 } 1491 } 1492 1493 data->sco_skb = skb; 1494 spin_unlock_irqrestore(&data->rxlock, flags); 1495 1496 return err; 1497 } 1498 1499 static void btusb_intr_complete(struct urb *urb) 1500 { 1501 struct hci_dev *hdev = urb->context; 1502 struct btusb_data *data = hci_get_drvdata(hdev); 1503 int err; 1504 1505 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, 1506 urb->actual_length); 1507 1508 if (!test_bit(HCI_RUNNING, &hdev->flags)) 1509 return; 1510 1511 if (urb->status == 0) { 1512 hdev->stat.byte_rx += urb->actual_length; 1513 1514 if (btusb_recv_intr(data, urb->transfer_buffer, 1515 urb->actual_length) < 0) { 1516 bt_dev_err(hdev, "corrupted event packet"); 1517 hdev->stat.err_rx++; 1518 } 1519 } else if (urb->status == -ENOENT) { 1520 /* Avoid suspend failed when usb_kill_urb */ 1521 return; 1522 } 1523 1524 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags)) 1525 return; 1526 1527 usb_mark_last_busy(data->udev); 1528 usb_anchor_urb(urb, &data->intr_anchor); 1529 1530 err = usb_submit_urb(urb, GFP_ATOMIC); 1531 if (err < 0) { 1532 /* -EPERM: urb is being killed; 1533 * -ENODEV: device got disconnected 1534 */ 1535 if (err != -EPERM && err != -ENODEV) 1536 bt_dev_err(hdev, "urb %p failed to resubmit (%d)", 1537 urb, -err); 1538 if (err != -EPERM) 1539 hci_cmd_sync_cancel(hdev, -err); 1540 usb_unanchor_urb(urb); 1541 } 1542 } 1543 1544 static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags) 1545 { 1546 struct btusb_data *data = hci_get_drvdata(hdev); 1547 struct urb *urb; 1548 unsigned char *buf; 1549 unsigned int pipe; 1550 int err, size; 1551 1552 BT_DBG("%s", hdev->name); 1553 1554 if (!data->intr_ep) 1555 return -ENODEV; 1556 1557 urb = usb_alloc_urb(0, mem_flags); 1558 if (!urb) 1559 return -ENOMEM; 1560 1561 if (le16_to_cpu(data->udev->descriptor.idVendor) == 0x0a12 && 1562 le16_to_cpu(data->udev->descriptor.idProduct) == 0x0001) 1563 /* Fake CSR devices don't seem to support sort-transter */ 1564 size = le16_to_cpu(data->intr_ep->wMaxPacketSize); 1565 else 1566 /* Use maximum HCI Event size so the USB stack handles 1567 * ZPL/short-transfer automatically. 1568 */ 1569 size = HCI_MAX_EVENT_SIZE; 1570 1571 buf = kmalloc(size, mem_flags); 1572 if (!buf) { 1573 usb_free_urb(urb); 1574 return -ENOMEM; 1575 } 1576 1577 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress); 1578 1579 usb_fill_int_urb(urb, data->udev, pipe, buf, size, 1580 btusb_intr_complete, hdev, data->intr_ep->bInterval); 1581 1582 urb->transfer_flags |= URB_FREE_BUFFER; 1583 1584 usb_anchor_urb(urb, &data->intr_anchor); 1585 1586 err = usb_submit_urb(urb, mem_flags); 1587 if (err < 0) { 1588 if (err != -EPERM && err != -ENODEV) 1589 bt_dev_err(hdev, "urb %p submission failed (%d)", 1590 urb, -err); 1591 if (err != -EPERM) 1592 hci_cmd_sync_cancel(hdev, -err); 1593 usb_unanchor_urb(urb); 1594 } 1595 1596 /* Only initialize intr_interval if URB poll sync is enabled */ 1597 if (!data->poll_sync) 1598 goto done; 1599 1600 /* The units are frames (milliseconds) for full and low speed devices, 1601 * and microframes (1/8 millisecond) for highspeed and SuperSpeed 1602 * devices. 1603 * 1604 * This is done once on open/resume so it shouldn't change even if 1605 * force_poll_sync changes. 1606 */ 1607 switch (urb->dev->speed) { 1608 case USB_SPEED_SUPER_PLUS: 1609 case USB_SPEED_SUPER: /* units are 125us */ 1610 data->intr_interval = usecs_to_jiffies(urb->interval * 125); 1611 break; 1612 default: 1613 data->intr_interval = msecs_to_jiffies(urb->interval); 1614 break; 1615 } 1616 1617 done: 1618 usb_free_urb(urb); 1619 1620 return err; 1621 } 1622 1623 static void btusb_bulk_complete(struct urb *urb) 1624 { 1625 struct hci_dev *hdev = urb->context; 1626 struct btusb_data *data = hci_get_drvdata(hdev); 1627 int err; 1628 1629 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, 1630 urb->actual_length); 1631 1632 if (!test_bit(HCI_RUNNING, &hdev->flags)) 1633 return; 1634 1635 if (urb->status == 0) { 1636 hdev->stat.byte_rx += urb->actual_length; 1637 1638 if (data->recv_bulk(data, urb->transfer_buffer, 1639 urb->actual_length) < 0) { 1640 bt_dev_err(hdev, "corrupted ACL packet"); 1641 hdev->stat.err_rx++; 1642 } 1643 } else if (urb->status == -ENOENT) { 1644 /* Avoid suspend failed when usb_kill_urb */ 1645 return; 1646 } 1647 1648 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags)) 1649 return; 1650 1651 usb_anchor_urb(urb, &data->bulk_anchor); 1652 usb_mark_last_busy(data->udev); 1653 1654 err = usb_submit_urb(urb, GFP_ATOMIC); 1655 if (err < 0) { 1656 /* -EPERM: urb is being killed; 1657 * -ENODEV: device got disconnected 1658 */ 1659 if (err != -EPERM && err != -ENODEV) 1660 bt_dev_err(hdev, "urb %p failed to resubmit (%d)", 1661 urb, -err); 1662 usb_unanchor_urb(urb); 1663 } 1664 } 1665 1666 static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags) 1667 { 1668 struct btusb_data *data = hci_get_drvdata(hdev); 1669 struct urb *urb; 1670 unsigned char *buf; 1671 unsigned int pipe; 1672 int err, size = HCI_MAX_FRAME_SIZE; 1673 1674 BT_DBG("%s", hdev->name); 1675 1676 if (!data->bulk_rx_ep) 1677 return -ENODEV; 1678 1679 urb = usb_alloc_urb(0, mem_flags); 1680 if (!urb) 1681 return -ENOMEM; 1682 1683 buf = kmalloc(size, mem_flags); 1684 if (!buf) { 1685 usb_free_urb(urb); 1686 return -ENOMEM; 1687 } 1688 1689 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress); 1690 1691 usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, 1692 btusb_bulk_complete, hdev); 1693 1694 urb->transfer_flags |= URB_FREE_BUFFER; 1695 1696 usb_mark_last_busy(data->udev); 1697 usb_anchor_urb(urb, &data->bulk_anchor); 1698 1699 err = usb_submit_urb(urb, mem_flags); 1700 if (err < 0) { 1701 if (err != -EPERM && err != -ENODEV) 1702 bt_dev_err(hdev, "urb %p submission failed (%d)", 1703 urb, -err); 1704 usb_unanchor_urb(urb); 1705 } 1706 1707 usb_free_urb(urb); 1708 1709 return err; 1710 } 1711 1712 static void btusb_isoc_complete(struct urb *urb) 1713 { 1714 struct hci_dev *hdev = urb->context; 1715 struct btusb_data *data = hci_get_drvdata(hdev); 1716 int i, err; 1717 1718 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, 1719 urb->actual_length); 1720 1721 if (!test_bit(HCI_RUNNING, &hdev->flags)) 1722 return; 1723 1724 if (urb->status == 0) { 1725 for (i = 0; i < urb->number_of_packets; i++) { 1726 unsigned int offset = urb->iso_frame_desc[i].offset; 1727 unsigned int length = urb->iso_frame_desc[i].actual_length; 1728 1729 if (urb->iso_frame_desc[i].status) 1730 continue; 1731 1732 hdev->stat.byte_rx += length; 1733 1734 if (btusb_recv_isoc(data, urb->transfer_buffer + offset, 1735 length) < 0) { 1736 bt_dev_err(hdev, "corrupted SCO packet"); 1737 hdev->stat.err_rx++; 1738 } 1739 } 1740 } else if (urb->status == -ENOENT) { 1741 /* Avoid suspend failed when usb_kill_urb */ 1742 return; 1743 } 1744 1745 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags)) 1746 return; 1747 1748 usb_anchor_urb(urb, &data->isoc_anchor); 1749 1750 err = usb_submit_urb(urb, GFP_ATOMIC); 1751 if (err < 0) { 1752 /* -EPERM: urb is being killed; 1753 * -ENODEV: device got disconnected 1754 */ 1755 if (err != -EPERM && err != -ENODEV) 1756 bt_dev_err(hdev, "urb %p failed to resubmit (%d)", 1757 urb, -err); 1758 usb_unanchor_urb(urb); 1759 } 1760 } 1761 1762 static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len, 1763 int mtu, struct btusb_data *data) 1764 { 1765 int i = 0, offset = 0; 1766 unsigned int interval; 1767 1768 BT_DBG("len %d mtu %d", len, mtu); 1769 1770 /* For mSBC ALT 6 settings some chips need to transmit the data 1771 * continuously without the zero length of USB packets. 1772 */ 1773 if (test_bit(BTUSB_ALT6_CONTINUOUS_TX, &data->flags)) 1774 goto ignore_usb_alt6_packet_flow; 1775 1776 /* For mSBC ALT 6 setting the host will send the packet at continuous 1777 * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting 1778 * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets. 1779 * To maintain the rate we send 63bytes of usb packets alternatively for 1780 * 7ms and 8ms to maintain the rate as 7.5ms. 1781 */ 1782 if (data->usb_alt6_packet_flow) { 1783 interval = 7; 1784 data->usb_alt6_packet_flow = false; 1785 } else { 1786 interval = 6; 1787 data->usb_alt6_packet_flow = true; 1788 } 1789 1790 for (i = 0; i < interval; i++) { 1791 urb->iso_frame_desc[i].offset = offset; 1792 urb->iso_frame_desc[i].length = offset; 1793 } 1794 1795 ignore_usb_alt6_packet_flow: 1796 if (len && i < BTUSB_MAX_ISOC_FRAMES) { 1797 urb->iso_frame_desc[i].offset = offset; 1798 urb->iso_frame_desc[i].length = len; 1799 i++; 1800 } 1801 1802 urb->number_of_packets = i; 1803 } 1804 1805 static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu) 1806 { 1807 int i, offset = 0; 1808 1809 BT_DBG("len %d mtu %d", len, mtu); 1810 1811 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu; 1812 i++, offset += mtu, len -= mtu) { 1813 urb->iso_frame_desc[i].offset = offset; 1814 urb->iso_frame_desc[i].length = mtu; 1815 } 1816 1817 if (len && i < BTUSB_MAX_ISOC_FRAMES) { 1818 urb->iso_frame_desc[i].offset = offset; 1819 urb->iso_frame_desc[i].length = len; 1820 i++; 1821 } 1822 1823 urb->number_of_packets = i; 1824 } 1825 1826 static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags) 1827 { 1828 struct btusb_data *data = hci_get_drvdata(hdev); 1829 struct urb *urb; 1830 unsigned char *buf; 1831 unsigned int pipe; 1832 int err, size; 1833 1834 BT_DBG("%s", hdev->name); 1835 1836 if (!data->isoc_rx_ep) 1837 return -ENODEV; 1838 1839 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags); 1840 if (!urb) 1841 return -ENOMEM; 1842 1843 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) * 1844 BTUSB_MAX_ISOC_FRAMES; 1845 1846 buf = kmalloc(size, mem_flags); 1847 if (!buf) { 1848 usb_free_urb(urb); 1849 return -ENOMEM; 1850 } 1851 1852 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress); 1853 1854 usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete, 1855 hdev, data->isoc_rx_ep->bInterval); 1856 1857 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP; 1858 1859 __fill_isoc_descriptor(urb, size, 1860 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize)); 1861 1862 usb_anchor_urb(urb, &data->isoc_anchor); 1863 1864 err = usb_submit_urb(urb, mem_flags); 1865 if (err < 0) { 1866 if (err != -EPERM && err != -ENODEV) 1867 bt_dev_err(hdev, "urb %p submission failed (%d)", 1868 urb, -err); 1869 usb_unanchor_urb(urb); 1870 } 1871 1872 usb_free_urb(urb); 1873 1874 return err; 1875 } 1876 1877 static void btusb_diag_complete(struct urb *urb) 1878 { 1879 struct hci_dev *hdev = urb->context; 1880 struct btusb_data *data = hci_get_drvdata(hdev); 1881 int err; 1882 1883 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, 1884 urb->actual_length); 1885 1886 if (urb->status == 0) { 1887 struct sk_buff *skb; 1888 1889 skb = bt_skb_alloc(urb->actual_length, GFP_ATOMIC); 1890 if (skb) { 1891 skb_put_data(skb, urb->transfer_buffer, 1892 urb->actual_length); 1893 hci_recv_diag(hdev, skb); 1894 } 1895 } else if (urb->status == -ENOENT) { 1896 /* Avoid suspend failed when usb_kill_urb */ 1897 return; 1898 } 1899 1900 if (!test_bit(BTUSB_DIAG_RUNNING, &data->flags)) 1901 return; 1902 1903 usb_anchor_urb(urb, &data->diag_anchor); 1904 usb_mark_last_busy(data->udev); 1905 1906 err = usb_submit_urb(urb, GFP_ATOMIC); 1907 if (err < 0) { 1908 /* -EPERM: urb is being killed; 1909 * -ENODEV: device got disconnected 1910 */ 1911 if (err != -EPERM && err != -ENODEV) 1912 bt_dev_err(hdev, "urb %p failed to resubmit (%d)", 1913 urb, -err); 1914 usb_unanchor_urb(urb); 1915 } 1916 } 1917 1918 static int btusb_submit_diag_urb(struct hci_dev *hdev, gfp_t mem_flags) 1919 { 1920 struct btusb_data *data = hci_get_drvdata(hdev); 1921 struct urb *urb; 1922 unsigned char *buf; 1923 unsigned int pipe; 1924 int err, size = HCI_MAX_FRAME_SIZE; 1925 1926 BT_DBG("%s", hdev->name); 1927 1928 if (!data->diag_rx_ep) 1929 return -ENODEV; 1930 1931 urb = usb_alloc_urb(0, mem_flags); 1932 if (!urb) 1933 return -ENOMEM; 1934 1935 buf = kmalloc(size, mem_flags); 1936 if (!buf) { 1937 usb_free_urb(urb); 1938 return -ENOMEM; 1939 } 1940 1941 pipe = usb_rcvbulkpipe(data->udev, data->diag_rx_ep->bEndpointAddress); 1942 1943 usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, 1944 btusb_diag_complete, hdev); 1945 1946 urb->transfer_flags |= URB_FREE_BUFFER; 1947 1948 usb_mark_last_busy(data->udev); 1949 usb_anchor_urb(urb, &data->diag_anchor); 1950 1951 err = usb_submit_urb(urb, mem_flags); 1952 if (err < 0) { 1953 if (err != -EPERM && err != -ENODEV) 1954 bt_dev_err(hdev, "urb %p submission failed (%d)", 1955 urb, -err); 1956 usb_unanchor_urb(urb); 1957 } 1958 1959 usb_free_urb(urb); 1960 1961 return err; 1962 } 1963 1964 static void btusb_tx_complete(struct urb *urb) 1965 { 1966 struct sk_buff *skb = urb->context; 1967 struct hci_dev *hdev = (struct hci_dev *)skb->dev; 1968 struct btusb_data *data = hci_get_drvdata(hdev); 1969 unsigned long flags; 1970 1971 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, 1972 urb->actual_length); 1973 1974 if (!test_bit(HCI_RUNNING, &hdev->flags)) 1975 goto done; 1976 1977 if (!urb->status) { 1978 hdev->stat.byte_tx += urb->transfer_buffer_length; 1979 } else { 1980 if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT) 1981 hci_cmd_sync_cancel(hdev, -urb->status); 1982 hdev->stat.err_tx++; 1983 } 1984 1985 done: 1986 spin_lock_irqsave(&data->txlock, flags); 1987 data->tx_in_flight--; 1988 spin_unlock_irqrestore(&data->txlock, flags); 1989 1990 kfree(urb->setup_packet); 1991 1992 kfree_skb(skb); 1993 } 1994 1995 static void btusb_isoc_tx_complete(struct urb *urb) 1996 { 1997 struct sk_buff *skb = urb->context; 1998 struct hci_dev *hdev = (struct hci_dev *)skb->dev; 1999 2000 BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, 2001 urb->actual_length); 2002 2003 if (!test_bit(HCI_RUNNING, &hdev->flags)) 2004 goto done; 2005 2006 if (!urb->status) 2007 hdev->stat.byte_tx += urb->transfer_buffer_length; 2008 else 2009 hdev->stat.err_tx++; 2010 2011 done: 2012 kfree(urb->setup_packet); 2013 2014 kfree_skb(skb); 2015 } 2016 2017 static int btusb_open(struct hci_dev *hdev) 2018 { 2019 struct btusb_data *data = hci_get_drvdata(hdev); 2020 int err; 2021 2022 BT_DBG("%s", hdev->name); 2023 2024 err = usb_autopm_get_interface(data->intf); 2025 if (err < 0) 2026 return err; 2027 2028 /* Patching USB firmware files prior to starting any URBs of HCI path 2029 * It is more safe to use USB bulk channel for downloading USB patch 2030 */ 2031 if (data->setup_on_usb) { 2032 err = data->setup_on_usb(hdev); 2033 if (err < 0) 2034 goto setup_fail; 2035 } 2036 2037 data->intf->needs_remote_wakeup = 1; 2038 2039 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) 2040 goto done; 2041 2042 err = btusb_submit_intr_urb(hdev, GFP_KERNEL); 2043 if (err < 0) 2044 goto failed; 2045 2046 err = btusb_submit_bulk_urb(hdev, GFP_KERNEL); 2047 if (err < 0) { 2048 usb_kill_anchored_urbs(&data->intr_anchor); 2049 goto failed; 2050 } 2051 2052 set_bit(BTUSB_BULK_RUNNING, &data->flags); 2053 btusb_submit_bulk_urb(hdev, GFP_KERNEL); 2054 2055 if (data->diag) { 2056 if (!btusb_submit_diag_urb(hdev, GFP_KERNEL)) 2057 set_bit(BTUSB_DIAG_RUNNING, &data->flags); 2058 } 2059 2060 done: 2061 usb_autopm_put_interface(data->intf); 2062 return 0; 2063 2064 failed: 2065 clear_bit(BTUSB_INTR_RUNNING, &data->flags); 2066 setup_fail: 2067 usb_autopm_put_interface(data->intf); 2068 return err; 2069 } 2070 2071 static void btusb_stop_traffic(struct btusb_data *data) 2072 { 2073 usb_kill_anchored_urbs(&data->intr_anchor); 2074 usb_kill_anchored_urbs(&data->bulk_anchor); 2075 usb_kill_anchored_urbs(&data->isoc_anchor); 2076 usb_kill_anchored_urbs(&data->diag_anchor); 2077 usb_kill_anchored_urbs(&data->ctrl_anchor); 2078 } 2079 2080 static void btusb_prepare_reset(struct hci_dev *hdev) 2081 { 2082 struct btusb_data *data = hci_get_drvdata(hdev); 2083 2084 btusb_stop_traffic(data); 2085 usb_kill_anchored_urbs(&data->tx_anchor); 2086 } 2087 2088 static int btusb_close(struct hci_dev *hdev) 2089 { 2090 struct btusb_data *data = hci_get_drvdata(hdev); 2091 int err; 2092 2093 BT_DBG("%s", hdev->name); 2094 2095 cancel_delayed_work(&data->rx_work); 2096 cancel_work_sync(&data->work); 2097 cancel_work_sync(&data->waker); 2098 2099 skb_queue_purge(&data->acl_q); 2100 2101 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 2102 clear_bit(BTUSB_BULK_RUNNING, &data->flags); 2103 clear_bit(BTUSB_INTR_RUNNING, &data->flags); 2104 clear_bit(BTUSB_DIAG_RUNNING, &data->flags); 2105 2106 btusb_stop_traffic(data); 2107 btusb_free_frags(data); 2108 2109 err = usb_autopm_get_interface(data->intf); 2110 if (err < 0) 2111 goto failed; 2112 2113 data->intf->needs_remote_wakeup = 0; 2114 2115 /* Enable remote wake up for auto-suspend */ 2116 if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) 2117 data->intf->needs_remote_wakeup = 1; 2118 2119 usb_autopm_put_interface(data->intf); 2120 2121 failed: 2122 usb_scuttle_anchored_urbs(&data->deferred); 2123 return 0; 2124 } 2125 2126 static int btusb_flush(struct hci_dev *hdev) 2127 { 2128 struct btusb_data *data = hci_get_drvdata(hdev); 2129 2130 BT_DBG("%s", hdev->name); 2131 2132 cancel_delayed_work(&data->rx_work); 2133 2134 skb_queue_purge(&data->acl_q); 2135 2136 usb_kill_anchored_urbs(&data->tx_anchor); 2137 btusb_free_frags(data); 2138 2139 return 0; 2140 } 2141 2142 static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb) 2143 { 2144 struct btusb_data *data = hci_get_drvdata(hdev); 2145 struct usb_ctrlrequest *dr; 2146 struct urb *urb; 2147 unsigned int pipe; 2148 2149 urb = usb_alloc_urb(0, GFP_KERNEL); 2150 if (!urb) 2151 return ERR_PTR(-ENOMEM); 2152 2153 dr = kmalloc_obj(*dr); 2154 if (!dr) { 2155 usb_free_urb(urb); 2156 return ERR_PTR(-ENOMEM); 2157 } 2158 2159 dr->bRequestType = data->cmdreq_type; 2160 dr->bRequest = data->cmdreq; 2161 dr->wIndex = 0; 2162 dr->wValue = 0; 2163 dr->wLength = __cpu_to_le16(skb->len); 2164 2165 pipe = usb_sndctrlpipe(data->udev, 0x00); 2166 2167 usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, 2168 skb->data, skb->len, btusb_tx_complete, skb); 2169 2170 skb->dev = (void *)hdev; 2171 2172 return urb; 2173 } 2174 2175 static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb) 2176 { 2177 struct btusb_data *data = hci_get_drvdata(hdev); 2178 struct urb *urb; 2179 unsigned int pipe; 2180 2181 if (!data->bulk_tx_ep) 2182 return ERR_PTR(-ENODEV); 2183 2184 urb = usb_alloc_urb(0, GFP_KERNEL); 2185 if (!urb) 2186 return ERR_PTR(-ENOMEM); 2187 2188 pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); 2189 2190 usb_fill_bulk_urb(urb, data->udev, pipe, 2191 skb->data, skb->len, btusb_tx_complete, skb); 2192 2193 skb->dev = (void *)hdev; 2194 2195 return urb; 2196 } 2197 2198 static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb) 2199 { 2200 struct btusb_data *data = hci_get_drvdata(hdev); 2201 struct urb *urb; 2202 unsigned int pipe; 2203 2204 if (!data->isoc_tx_ep) 2205 return ERR_PTR(-ENODEV); 2206 2207 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL); 2208 if (!urb) 2209 return ERR_PTR(-ENOMEM); 2210 2211 pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress); 2212 2213 usb_fill_int_urb(urb, data->udev, pipe, 2214 skb->data, skb->len, btusb_isoc_tx_complete, 2215 skb, data->isoc_tx_ep->bInterval); 2216 2217 urb->transfer_flags = URB_ISO_ASAP; 2218 2219 if (data->isoc_altsetting == 6) 2220 __fill_isoc_descriptor_msbc(urb, skb->len, 2221 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize), 2222 data); 2223 else 2224 __fill_isoc_descriptor(urb, skb->len, 2225 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); 2226 skb->dev = (void *)hdev; 2227 2228 return urb; 2229 } 2230 2231 static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb) 2232 { 2233 struct btusb_data *data = hci_get_drvdata(hdev); 2234 int err; 2235 2236 usb_anchor_urb(urb, &data->tx_anchor); 2237 2238 err = usb_submit_urb(urb, GFP_KERNEL); 2239 if (err < 0) { 2240 if (err != -EPERM && err != -ENODEV) 2241 bt_dev_err(hdev, "urb %p submission failed (%d)", 2242 urb, -err); 2243 kfree(urb->setup_packet); 2244 usb_unanchor_urb(urb); 2245 } else { 2246 usb_mark_last_busy(data->udev); 2247 } 2248 2249 usb_free_urb(urb); 2250 return err; 2251 } 2252 2253 static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb) 2254 { 2255 struct btusb_data *data = hci_get_drvdata(hdev); 2256 unsigned long flags; 2257 bool suspending; 2258 2259 spin_lock_irqsave(&data->txlock, flags); 2260 suspending = test_bit(BTUSB_SUSPENDING, &data->flags); 2261 if (!suspending) 2262 data->tx_in_flight++; 2263 spin_unlock_irqrestore(&data->txlock, flags); 2264 2265 if (!suspending) 2266 return submit_tx_urb(hdev, urb); 2267 2268 usb_anchor_urb(urb, &data->deferred); 2269 schedule_work(&data->waker); 2270 2271 usb_free_urb(urb); 2272 return 0; 2273 } 2274 2275 static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb) 2276 { 2277 struct urb *urb; 2278 2279 BT_DBG("%s", hdev->name); 2280 2281 switch (hci_skb_pkt_type(skb)) { 2282 case HCI_COMMAND_PKT: 2283 urb = alloc_ctrl_urb(hdev, skb); 2284 if (IS_ERR(urb)) 2285 return PTR_ERR(urb); 2286 2287 hdev->stat.cmd_tx++; 2288 return submit_or_queue_tx_urb(hdev, urb); 2289 2290 case HCI_ACLDATA_PKT: 2291 urb = alloc_bulk_urb(hdev, skb); 2292 if (IS_ERR(urb)) 2293 return PTR_ERR(urb); 2294 2295 hdev->stat.acl_tx++; 2296 return submit_or_queue_tx_urb(hdev, urb); 2297 2298 case HCI_SCODATA_PKT: 2299 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && 2300 hci_conn_num(hdev, SCO_LINK) < 1) 2301 return -ENODEV; 2302 2303 urb = alloc_isoc_urb(hdev, skb); 2304 if (IS_ERR(urb)) 2305 return PTR_ERR(urb); 2306 2307 hdev->stat.sco_tx++; 2308 return submit_tx_urb(hdev, urb); 2309 2310 case HCI_ISODATA_PKT: 2311 urb = alloc_bulk_urb(hdev, skb); 2312 if (IS_ERR(urb)) 2313 return PTR_ERR(urb); 2314 2315 return submit_or_queue_tx_urb(hdev, urb); 2316 } 2317 2318 return -EILSEQ; 2319 } 2320 2321 static void btusb_notify(struct hci_dev *hdev, unsigned int evt) 2322 { 2323 struct btusb_data *data = hci_get_drvdata(hdev); 2324 2325 BT_DBG("%s evt %d", hdev->name, evt); 2326 2327 if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) { 2328 data->sco_num = hci_conn_num(hdev, SCO_LINK); 2329 data->air_mode = evt; 2330 schedule_work(&data->work); 2331 } 2332 } 2333 2334 static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting) 2335 { 2336 struct btusb_data *data = hci_get_drvdata(hdev); 2337 struct usb_interface *intf = data->isoc; 2338 struct usb_endpoint_descriptor *ep_desc; 2339 int i, err; 2340 2341 if (!data->isoc) 2342 return -ENODEV; 2343 2344 err = usb_set_interface(data->udev, data->isoc_ifnum, altsetting); 2345 if (err < 0) { 2346 bt_dev_err(hdev, "setting interface failed (%d)", -err); 2347 return err; 2348 } 2349 2350 data->isoc_altsetting = altsetting; 2351 2352 data->isoc_tx_ep = NULL; 2353 data->isoc_rx_ep = NULL; 2354 2355 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { 2356 ep_desc = &intf->cur_altsetting->endpoint[i].desc; 2357 2358 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) { 2359 data->isoc_tx_ep = ep_desc; 2360 continue; 2361 } 2362 2363 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) { 2364 data->isoc_rx_ep = ep_desc; 2365 continue; 2366 } 2367 } 2368 2369 if (!data->isoc_tx_ep || !data->isoc_rx_ep) { 2370 bt_dev_err(hdev, "invalid SCO descriptors"); 2371 return -ENODEV; 2372 } 2373 2374 return 0; 2375 } 2376 2377 static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts) 2378 { 2379 struct btusb_data *data = hci_get_drvdata(hdev); 2380 int err; 2381 2382 if (data->isoc_altsetting != new_alts) { 2383 unsigned long flags; 2384 2385 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 2386 usb_kill_anchored_urbs(&data->isoc_anchor); 2387 2388 /* When isochronous alternate setting needs to be 2389 * changed, because SCO connection has been added 2390 * or removed, a packet fragment may be left in the 2391 * reassembling state. This could lead to wrongly 2392 * assembled fragments. 2393 * 2394 * Clear outstanding fragment when selecting a new 2395 * alternate setting. 2396 */ 2397 spin_lock_irqsave(&data->rxlock, flags); 2398 dev_kfree_skb_irq(data->sco_skb); 2399 data->sco_skb = NULL; 2400 spin_unlock_irqrestore(&data->rxlock, flags); 2401 2402 err = __set_isoc_interface(hdev, new_alts); 2403 if (err < 0) 2404 return err; 2405 } 2406 2407 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { 2408 if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0) 2409 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 2410 else 2411 btusb_submit_isoc_urb(hdev, GFP_KERNEL); 2412 } 2413 2414 return 0; 2415 } 2416 2417 static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data, 2418 int alt) 2419 { 2420 struct usb_interface *intf = data->isoc; 2421 int i; 2422 2423 BT_DBG("Looking for Alt no :%d", alt); 2424 2425 if (!intf) 2426 return NULL; 2427 2428 for (i = 0; i < intf->num_altsetting; i++) { 2429 if (intf->altsetting[i].desc.bAlternateSetting == alt) 2430 return &intf->altsetting[i]; 2431 } 2432 2433 return NULL; 2434 } 2435 2436 static void btusb_work(struct work_struct *work) 2437 { 2438 struct btusb_data *data = container_of(work, struct btusb_data, work); 2439 struct hci_dev *hdev = data->hdev; 2440 int new_alts = 0; 2441 int err; 2442 2443 if (data->sco_num > 0) { 2444 if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) { 2445 err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf); 2446 if (err < 0) { 2447 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 2448 usb_kill_anchored_urbs(&data->isoc_anchor); 2449 return; 2450 } 2451 2452 set_bit(BTUSB_DID_ISO_RESUME, &data->flags); 2453 } 2454 2455 if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) { 2456 if (hdev->voice_setting & 0x0020) { 2457 static const int alts[3] = { 2, 4, 5 }; 2458 unsigned int sco_idx; 2459 2460 sco_idx = min_t(unsigned int, data->sco_num - 1, 2461 ARRAY_SIZE(alts) - 1); 2462 new_alts = alts[sco_idx]; 2463 } else { 2464 new_alts = data->sco_num; 2465 } 2466 } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) { 2467 /* Bluetooth USB spec recommends alt 6 (63 bytes), but 2468 * many adapters do not support it. Alt 1 appears to 2469 * work for all adapters that do not have alt 6, and 2470 * which work with WBS at all. Some devices prefer 2471 * alt 3 (HCI payload >= 60 Bytes let air packet 2472 * data satisfy 60 bytes), requiring 2473 * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72 2474 * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1. 2475 */ 2476 if (btusb_find_altsetting(data, 6)) 2477 new_alts = 6; 2478 else if (btusb_find_altsetting(data, 3) && 2479 hdev->sco_mtu >= 72 && 2480 test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags)) 2481 new_alts = 3; 2482 else 2483 new_alts = 1; 2484 } 2485 2486 if (btusb_switch_alt_setting(hdev, new_alts) < 0) 2487 bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts); 2488 } else { 2489 usb_kill_anchored_urbs(&data->isoc_anchor); 2490 2491 if (test_and_clear_bit(BTUSB_ISOC_RUNNING, &data->flags)) 2492 __set_isoc_interface(hdev, 0); 2493 2494 if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags)) 2495 usb_autopm_put_interface(data->isoc ? data->isoc : data->intf); 2496 } 2497 } 2498 2499 static void btusb_waker(struct work_struct *work) 2500 { 2501 struct btusb_data *data = container_of(work, struct btusb_data, waker); 2502 int err; 2503 2504 err = usb_autopm_get_interface(data->intf); 2505 if (err < 0) 2506 return; 2507 2508 usb_autopm_put_interface(data->intf); 2509 } 2510 2511 static void btusb_rx_work(struct work_struct *work) 2512 { 2513 struct btusb_data *data = container_of(work, struct btusb_data, 2514 rx_work.work); 2515 struct sk_buff *skb; 2516 2517 /* Dequeue ACL data received during the interval */ 2518 while ((skb = skb_dequeue(&data->acl_q))) 2519 data->recv_acl(data->hdev, skb); 2520 } 2521 2522 static int btusb_setup_bcm92035(struct hci_dev *hdev) 2523 { 2524 struct sk_buff *skb; 2525 u8 val = 0x00; 2526 2527 BT_DBG("%s", hdev->name); 2528 2529 skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT); 2530 if (IS_ERR(skb)) 2531 bt_dev_err(hdev, "BCM92035 command failed (%ld)", PTR_ERR(skb)); 2532 else 2533 kfree_skb(skb); 2534 2535 return 0; 2536 } 2537 2538 static int btusb_setup_csr(struct hci_dev *hdev) 2539 { 2540 struct btusb_data *data = hci_get_drvdata(hdev); 2541 u16 bcdDevice = le16_to_cpu(data->udev->descriptor.bcdDevice); 2542 struct hci_rp_read_local_version *rp; 2543 struct sk_buff *skb; 2544 bool is_fake = false; 2545 int ret; 2546 2547 BT_DBG("%s", hdev->name); 2548 2549 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL, 2550 HCI_INIT_TIMEOUT); 2551 if (IS_ERR(skb)) { 2552 int err = PTR_ERR(skb); 2553 2554 bt_dev_err(hdev, "CSR: Local version failed (%d)", err); 2555 return err; 2556 } 2557 2558 rp = skb_pull_data(skb, sizeof(*rp)); 2559 if (!rp) { 2560 bt_dev_err(hdev, "CSR: Local version length mismatch"); 2561 kfree_skb(skb); 2562 return -EIO; 2563 } 2564 2565 bt_dev_info(hdev, "CSR: Setting up dongle with HCI ver=%u rev=%04x", 2566 rp->hci_ver, le16_to_cpu(rp->hci_rev)); 2567 2568 bt_dev_info(hdev, "LMP ver=%u subver=%04x; manufacturer=%u", 2569 rp->lmp_ver, le16_to_cpu(rp->lmp_subver), 2570 le16_to_cpu(rp->manufacturer)); 2571 2572 /* Detect a wide host of Chinese controllers that aren't CSR. 2573 * 2574 * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891 2575 * 2576 * The main thing they have in common is that these are really popular low-cost 2577 * options that support newer Bluetooth versions but rely on heavy VID/PID 2578 * squatting of this poor old Bluetooth 1.1 device. Even sold as such. 2579 * 2580 * We detect actual CSR devices by checking that the HCI manufacturer code 2581 * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and 2582 * HCI rev values always match. As they both store the firmware number. 2583 */ 2584 if (le16_to_cpu(rp->manufacturer) != 10 || 2585 le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver)) 2586 is_fake = true; 2587 2588 /* Known legit CSR firmware build numbers and their supported BT versions: 2589 * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e 2590 * - 1.2 (0x2) -> 0x04d9, 0x0529 2591 * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c 2592 * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External) 2593 * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb 2594 * 2595 * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that 2596 * support BT 1.1 only; so it's a dead giveaway when some 2597 * third-party BT 4.0 dongle reuses it. 2598 */ 2599 else if (le16_to_cpu(rp->lmp_subver) <= 0x034e && 2600 rp->hci_ver > BLUETOOTH_VER_1_1) 2601 is_fake = true; 2602 2603 else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 && 2604 rp->hci_ver > BLUETOOTH_VER_1_2) 2605 is_fake = true; 2606 2607 else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c && 2608 rp->hci_ver > BLUETOOTH_VER_2_0) 2609 is_fake = true; 2610 2611 else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 && 2612 rp->hci_ver > BLUETOOTH_VER_2_1) 2613 is_fake = true; 2614 2615 else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb && 2616 rp->hci_ver > BLUETOOTH_VER_4_0) 2617 is_fake = true; 2618 2619 /* Other clones which beat all the above checks */ 2620 else if (bcdDevice == 0x0134 && 2621 le16_to_cpu(rp->lmp_subver) == 0x0c5c && 2622 rp->hci_ver == BLUETOOTH_VER_2_0) 2623 is_fake = true; 2624 2625 if (is_fake) { 2626 bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds and force-suspending once..."); 2627 2628 /* Generally these clones have big discrepancies between 2629 * advertised features and what's actually supported. 2630 * Probably will need to be expanded in the future; 2631 * without these the controller will lock up. 2632 */ 2633 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_STORED_LINK_KEY); 2634 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ERR_DATA_REPORTING); 2635 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL); 2636 hci_set_quirk(hdev, HCI_QUIRK_NO_SUSPEND_NOTIFIER); 2637 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_READ_VOICE_SETTING); 2638 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_READ_PAGE_SCAN_TYPE); 2639 2640 /* Clear the reset quirk since this is not an actual 2641 * early Bluetooth 1.1 device from CSR. 2642 */ 2643 hci_clear_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE); 2644 hci_clear_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY); 2645 2646 /* 2647 * Special workaround for these BT 4.0 chip clones, and potentially more: 2648 * 2649 * - 0x0134: a Barrot 8041a02 (HCI rev: 0x0810 sub: 0x1012) 2650 * - 0x7558: IC markings FR3191AHAL 749H15143 (HCI rev/sub-version: 0x0709) 2651 * 2652 * These controllers are really messed-up. 2653 * 2654 * 1. Their bulk RX endpoint will never report any data unless 2655 * the device was suspended at least once (yes, really). 2656 * 2. They will not wakeup when autosuspended and receiving data 2657 * on their bulk RX endpoint from e.g. a keyboard or mouse 2658 * (IOW remote-wakeup support is broken for the bulk endpoint). 2659 * 2660 * To fix 1. enable runtime-suspend, force-suspend the 2661 * HCI and then wake-it up by disabling runtime-suspend. 2662 * 2663 * To fix 2. clear the HCI's can_wake flag, this way the HCI 2664 * will still be autosuspended when it is not open. 2665 * 2666 * -- 2667 * 2668 * Because these are widespread problems we prefer generic solutions; so 2669 * apply this initialization quirk to every controller that gets here, 2670 * it should be harmless. The alternative is to not work at all. 2671 */ 2672 pm_runtime_allow(&data->udev->dev); 2673 2674 ret = pm_runtime_suspend(&data->udev->dev); 2675 if (ret >= 0) 2676 msleep(200); 2677 else 2678 bt_dev_warn(hdev, "CSR: Couldn't suspend the device for our Barrot 8041a02 receive-issue workaround"); 2679 2680 pm_runtime_forbid(&data->udev->dev); 2681 2682 device_set_wakeup_capable(&data->udev->dev, false); 2683 2684 /* Re-enable autosuspend if this was requested */ 2685 if (enable_autosuspend) 2686 usb_enable_autosuspend(data->udev); 2687 } 2688 2689 kfree_skb(skb); 2690 2691 return 0; 2692 } 2693 2694 static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode) 2695 { 2696 struct sk_buff *skb; 2697 struct hci_event_hdr *hdr; 2698 struct hci_ev_cmd_complete *evt; 2699 2700 skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL); 2701 if (!skb) 2702 return -ENOMEM; 2703 2704 hdr = skb_put(skb, sizeof(*hdr)); 2705 hdr->evt = HCI_EV_CMD_COMPLETE; 2706 hdr->plen = sizeof(*evt) + 1; 2707 2708 evt = skb_put(skb, sizeof(*evt)); 2709 evt->ncmd = 0x01; 2710 evt->opcode = cpu_to_le16(opcode); 2711 2712 skb_put_u8(skb, 0x00); 2713 2714 hci_skb_pkt_type(skb) = HCI_EVENT_PKT; 2715 2716 return hci_recv_frame(hdev, skb); 2717 } 2718 2719 static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer, 2720 int count) 2721 { 2722 struct hci_dev *hdev = data->hdev; 2723 2724 /* When the device is in bootloader mode, then it can send 2725 * events via the bulk endpoint. These events are treated the 2726 * same way as the ones received from the interrupt endpoint. 2727 */ 2728 if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) 2729 return btusb_recv_intr(data, buffer, count); 2730 2731 return btusb_recv_bulk(data, buffer, count); 2732 } 2733 2734 static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) 2735 { 2736 struct urb *urb; 2737 2738 BT_DBG("%s", hdev->name); 2739 2740 switch (hci_skb_pkt_type(skb)) { 2741 case HCI_COMMAND_PKT: 2742 if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) { 2743 struct hci_command_hdr *cmd = (void *)skb->data; 2744 __u16 opcode = le16_to_cpu(cmd->opcode); 2745 2746 /* When in bootloader mode and the command 0xfc09 2747 * is received, it needs to be send down the 2748 * bulk endpoint. So allocate a bulk URB instead. 2749 */ 2750 if (opcode == 0xfc09) 2751 urb = alloc_bulk_urb(hdev, skb); 2752 else 2753 urb = alloc_ctrl_urb(hdev, skb); 2754 2755 /* When the BTINTEL_HCI_OP_RESET command is issued to 2756 * boot into the operational firmware, it will actually 2757 * not send a command complete event. To keep the flow 2758 * control working inject that event here. 2759 */ 2760 if (opcode == BTINTEL_HCI_OP_RESET) 2761 inject_cmd_complete(hdev, opcode); 2762 } else { 2763 urb = alloc_ctrl_urb(hdev, skb); 2764 } 2765 if (IS_ERR(urb)) 2766 return PTR_ERR(urb); 2767 2768 hdev->stat.cmd_tx++; 2769 return submit_or_queue_tx_urb(hdev, urb); 2770 2771 case HCI_ACLDATA_PKT: 2772 urb = alloc_bulk_urb(hdev, skb); 2773 if (IS_ERR(urb)) 2774 return PTR_ERR(urb); 2775 2776 hdev->stat.acl_tx++; 2777 return submit_or_queue_tx_urb(hdev, urb); 2778 2779 case HCI_SCODATA_PKT: 2780 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && 2781 hci_conn_num(hdev, SCO_LINK) < 1) 2782 return -ENODEV; 2783 2784 urb = alloc_isoc_urb(hdev, skb); 2785 if (IS_ERR(urb)) 2786 return PTR_ERR(urb); 2787 2788 hdev->stat.sco_tx++; 2789 return submit_tx_urb(hdev, urb); 2790 2791 case HCI_ISODATA_PKT: 2792 urb = alloc_bulk_urb(hdev, skb); 2793 if (IS_ERR(urb)) 2794 return PTR_ERR(urb); 2795 2796 return submit_or_queue_tx_urb(hdev, urb); 2797 } 2798 2799 return -EILSEQ; 2800 } 2801 2802 static int btusb_setup_realtek(struct hci_dev *hdev) 2803 { 2804 struct btusb_data *data = hci_get_drvdata(hdev); 2805 int ret; 2806 2807 ret = btrtl_setup_realtek(hdev); 2808 2809 if (btrealtek_test_flag(data->hdev, REALTEK_ALT6_CONTINUOUS_TX_CHIP)) 2810 set_bit(BTUSB_ALT6_CONTINUOUS_TX, &data->flags); 2811 2812 return ret; 2813 } 2814 2815 static int btusb_recv_event_realtek(struct hci_dev *hdev, struct sk_buff *skb) 2816 { 2817 if (skb->len >= HCI_EVENT_HDR_SIZE + 1 && 2818 skb->data[0] == HCI_EV_VENDOR && 2819 skb->data[2] == RTK_SUB_EVENT_CODE_COREDUMP) { 2820 struct rtk_dev_coredump_hdr hdr = { 2821 .code = RTK_DEVCOREDUMP_CODE_MEMDUMP, 2822 }; 2823 2824 bt_dev_dbg(hdev, "RTL: received coredump vendor evt, len %u", 2825 skb->len); 2826 2827 btusb_rtl_alloc_devcoredump(hdev, &hdr, skb->data, skb->len); 2828 kfree_skb(skb); 2829 2830 return 0; 2831 } 2832 2833 return hci_recv_frame(hdev, skb); 2834 } 2835 2836 static void btusb_mtk_claim_iso_intf(struct btusb_data *data) 2837 { 2838 struct btmtk_data *btmtk_data; 2839 int err; 2840 2841 if (!data->hdev) 2842 return; 2843 2844 btmtk_data = hci_get_priv(data->hdev); 2845 if (!btmtk_data) 2846 return; 2847 2848 if (!btmtk_data->isopkt_intf) { 2849 bt_dev_err(data->hdev, "Can't claim NULL iso interface"); 2850 return; 2851 } 2852 2853 /* 2854 * The function usb_driver_claim_interface() is documented to need 2855 * locks held if it's not called from a probe routine. The code here 2856 * is called from the hci_power_on workqueue, so grab the lock. 2857 */ 2858 device_lock(&btmtk_data->isopkt_intf->dev); 2859 err = usb_driver_claim_interface(&btusb_driver, 2860 btmtk_data->isopkt_intf, data); 2861 device_unlock(&btmtk_data->isopkt_intf->dev); 2862 if (err < 0) { 2863 btmtk_data->isopkt_intf = NULL; 2864 bt_dev_err(data->hdev, "Failed to claim iso interface: %d", err); 2865 return; 2866 } 2867 2868 set_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags); 2869 init_usb_anchor(&btmtk_data->isopkt_anchor); 2870 } 2871 2872 static void btusb_mtk_release_iso_intf(struct hci_dev *hdev) 2873 { 2874 struct btmtk_data *btmtk_data; 2875 2876 if (!hdev) 2877 return; 2878 2879 btmtk_data = hci_get_priv(hdev); 2880 if (!btmtk_data) 2881 return; 2882 2883 if (test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) { 2884 usb_kill_anchored_urbs(&btmtk_data->isopkt_anchor); 2885 clear_bit(BTMTK_ISOPKT_RUNNING, &btmtk_data->flags); 2886 2887 if (btmtk_data->isopkt_skb) { 2888 dev_kfree_skb_irq(btmtk_data->isopkt_skb); 2889 btmtk_data->isopkt_skb = NULL; 2890 } 2891 2892 if (btmtk_data->isopkt_intf) { 2893 usb_set_intfdata(btmtk_data->isopkt_intf, NULL); 2894 usb_driver_release_interface(&btusb_driver, 2895 btmtk_data->isopkt_intf); 2896 btmtk_data->isopkt_intf = NULL; 2897 } 2898 } 2899 2900 clear_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags); 2901 } 2902 2903 static int btusb_mtk_disconnect(struct hci_dev *hdev) 2904 { 2905 /* This function describes the specific additional steps taken by MediaTek 2906 * when Bluetooth usb driver's resume function is called. 2907 */ 2908 btusb_mtk_release_iso_intf(hdev); 2909 2910 return 0; 2911 } 2912 2913 static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) 2914 { 2915 struct btusb_data *data = hci_get_drvdata(hdev); 2916 struct btmtk_data *btmtk_data = hci_get_priv(hdev); 2917 int err; 2918 2919 /* It's MediaTek specific bluetooth reset mechanism via USB */ 2920 if (test_and_set_bit(BTMTK_HW_RESET_ACTIVE, &btmtk_data->flags)) { 2921 bt_dev_err(hdev, "last reset failed? Not resetting again"); 2922 return -EBUSY; 2923 } 2924 2925 err = usb_autopm_get_interface(data->intf); 2926 if (err < 0) 2927 return err; 2928 2929 /* Release MediaTek ISO data interface */ 2930 btusb_mtk_release_iso_intf(hdev); 2931 2932 btusb_prepare_reset(hdev); 2933 2934 /* Toggle the hard reset line. The MediaTek device is going to 2935 * yank itself off the USB and then replug. The cleanup is handled 2936 * correctly on the way out (standard USB disconnect), and the new 2937 * device is detected cleanly and bound to the driver again like 2938 * it should be. 2939 */ 2940 if (data->reset_gpio) { 2941 gpiod_set_value_cansleep(data->reset_gpio, 1); 2942 msleep(200); 2943 gpiod_set_value_cansleep(data->reset_gpio, 0); 2944 return 0; 2945 } 2946 2947 err = btmtk_usb_subsys_reset(hdev, btmtk_data->dev_id); 2948 2949 usb_queue_reset_device(data->intf); 2950 clear_bit(BTMTK_HW_RESET_ACTIVE, &btmtk_data->flags); 2951 2952 return err; 2953 } 2954 2955 static int btusb_send_frame_mtk(struct hci_dev *hdev, struct sk_buff *skb) 2956 { 2957 struct urb *urb; 2958 2959 BT_DBG("%s", hdev->name); 2960 2961 if (hci_skb_pkt_type(skb) == HCI_ISODATA_PKT) { 2962 urb = alloc_mtk_intr_urb(hdev, skb, btusb_tx_complete); 2963 if (IS_ERR(urb)) 2964 return PTR_ERR(urb); 2965 2966 return submit_or_queue_tx_urb(hdev, urb); 2967 } else { 2968 return btusb_send_frame(hdev, skb); 2969 } 2970 } 2971 2972 static int btusb_mtk_setup(struct hci_dev *hdev) 2973 { 2974 struct btusb_data *data = hci_get_drvdata(hdev); 2975 struct btmtk_data *btmtk_data = hci_get_priv(hdev); 2976 2977 /* MediaTek WMT vendor cmd requiring below USB resources to 2978 * complete the handshake. 2979 */ 2980 btmtk_data->drv_name = btusb_driver.name; 2981 btmtk_data->intf = data->intf; 2982 btmtk_data->udev = data->udev; 2983 btmtk_data->ctrl_anchor = &data->ctrl_anchor; 2984 btmtk_data->reset_sync = btusb_mtk_reset; 2985 2986 /* Claim ISO data interface and endpoint */ 2987 if (!test_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags)) { 2988 btmtk_data->isopkt_intf = usb_ifnum_to_if(data->udev, MTK_ISO_IFNUM); 2989 btusb_mtk_claim_iso_intf(data); 2990 } 2991 2992 return btmtk_usb_setup(hdev); 2993 } 2994 2995 static int btusb_mtk_shutdown(struct hci_dev *hdev) 2996 { 2997 int ret; 2998 2999 ret = btmtk_usb_shutdown(hdev); 3000 3001 /* Release MediaTek iso interface after shutdown */ 3002 btusb_mtk_release_iso_intf(hdev); 3003 3004 return ret; 3005 } 3006 3007 #ifdef CONFIG_PM 3008 /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */ 3009 static int marvell_config_oob_wake(struct hci_dev *hdev) 3010 { 3011 struct sk_buff *skb; 3012 struct btusb_data *data = hci_get_drvdata(hdev); 3013 struct device *dev = &data->udev->dev; 3014 u16 pin, gap, opcode; 3015 int ret; 3016 u8 cmd[5]; 3017 3018 /* Move on if no wakeup pin specified */ 3019 if (of_property_read_u16(dev->of_node, "marvell,wakeup-pin", &pin) || 3020 of_property_read_u16(dev->of_node, "marvell,wakeup-gap-ms", &gap)) 3021 return 0; 3022 3023 /* Vendor specific command to configure a GPIO as wake-up pin */ 3024 opcode = hci_opcode_pack(0x3F, 0x59); 3025 cmd[0] = opcode & 0xFF; 3026 cmd[1] = opcode >> 8; 3027 cmd[2] = 2; /* length of parameters that follow */ 3028 cmd[3] = pin; 3029 cmd[4] = gap; /* time in ms, for which wakeup pin should be asserted */ 3030 3031 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); 3032 if (!skb) { 3033 bt_dev_err(hdev, "%s: No memory", __func__); 3034 return -ENOMEM; 3035 } 3036 3037 skb_put_data(skb, cmd, sizeof(cmd)); 3038 hci_skb_pkt_type(skb) = HCI_COMMAND_PKT; 3039 3040 ret = btusb_send_frame(hdev, skb); 3041 if (ret) { 3042 bt_dev_err(hdev, "%s: configuration failed", __func__); 3043 kfree_skb(skb); 3044 return ret; 3045 } 3046 3047 return 0; 3048 } 3049 #else 3050 static inline int marvell_config_oob_wake(struct hci_dev *hdev) 3051 { 3052 return 0; 3053 } 3054 #endif 3055 3056 static int btusb_set_bdaddr_marvell(struct hci_dev *hdev, 3057 const bdaddr_t *bdaddr) 3058 { 3059 struct sk_buff *skb; 3060 u8 buf[8]; 3061 long ret; 3062 3063 buf[0] = 0xfe; 3064 buf[1] = sizeof(bdaddr_t); 3065 memcpy(buf + 2, bdaddr, sizeof(bdaddr_t)); 3066 3067 skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT); 3068 if (IS_ERR(skb)) { 3069 ret = PTR_ERR(skb); 3070 bt_dev_err(hdev, "changing Marvell device address failed (%ld)", 3071 ret); 3072 return ret; 3073 } 3074 kfree_skb(skb); 3075 3076 return 0; 3077 } 3078 3079 static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev, 3080 const bdaddr_t *bdaddr) 3081 { 3082 struct sk_buff *skb; 3083 u8 buf[10]; 3084 long ret; 3085 3086 buf[0] = 0x01; 3087 buf[1] = 0x01; 3088 buf[2] = 0x00; 3089 buf[3] = sizeof(bdaddr_t); 3090 memcpy(buf + 4, bdaddr, sizeof(bdaddr_t)); 3091 3092 skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT); 3093 if (IS_ERR(skb)) { 3094 ret = PTR_ERR(skb); 3095 bt_dev_err(hdev, "Change address command failed (%ld)", ret); 3096 return ret; 3097 } 3098 kfree_skb(skb); 3099 3100 return 0; 3101 } 3102 3103 static int btusb_set_bdaddr_wcn6855(struct hci_dev *hdev, 3104 const bdaddr_t *bdaddr) 3105 { 3106 bdaddr_t bdaddr_swapped; 3107 struct sk_buff *skb; 3108 long ret; 3109 3110 baswap(&bdaddr_swapped, bdaddr); 3111 3112 skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(bdaddr_swapped), 3113 &bdaddr_swapped, HCI_EV_CMD_COMPLETE, 3114 HCI_INIT_TIMEOUT); 3115 if (IS_ERR(skb)) { 3116 ret = PTR_ERR(skb); 3117 bt_dev_err(hdev, "Change address command failed (%ld)", ret); 3118 return ret; 3119 } 3120 kfree_skb(skb); 3121 3122 return 0; 3123 } 3124 3125 #define QCA_MEMDUMP_ACL_HANDLE 0x2EDD 3126 #define QCA_MEMDUMP_SIZE_MAX 0x100000 3127 #define QCA_MEMDUMP_VSE_CLASS 0x01 3128 #define QCA_MEMDUMP_MSG_TYPE 0x08 3129 #define QCA_MEMDUMP_PKT_SIZE 248 3130 #define QCA_LAST_SEQUENCE_NUM 0xffff 3131 3132 struct qca_dump_hdr { 3133 u8 vse_class; 3134 u8 msg_type; 3135 __le16 seqno; 3136 u8 reserved; 3137 union { 3138 u8 data[0]; 3139 struct { 3140 __le32 ram_dump_size; 3141 u8 data0[0]; 3142 } __packed; 3143 }; 3144 } __packed; 3145 3146 3147 static void btusb_dump_hdr_qca(struct hci_dev *hdev, struct sk_buff *skb) 3148 { 3149 char buf[128]; 3150 struct btqca_data *btqca_data = hci_get_priv(hdev); 3151 struct qca_dump_info *qca_dump_ptr = &btqca_data->qca_dump; 3152 3153 snprintf(buf, sizeof(buf), "Controller Name: 0x%x\n", 3154 qca_dump_ptr->controller_id); 3155 skb_put_data(skb, buf, strlen(buf)); 3156 3157 snprintf(buf, sizeof(buf), "Firmware Version: 0x%x\n", 3158 qca_dump_ptr->fw_version); 3159 skb_put_data(skb, buf, strlen(buf)); 3160 3161 snprintf(buf, sizeof(buf), "Driver: %s\nVendor: qca\n", 3162 btusb_driver.name); 3163 skb_put_data(skb, buf, strlen(buf)); 3164 3165 snprintf(buf, sizeof(buf), "VID: 0x%x\nPID:0x%x\n", 3166 qca_dump_ptr->id_vendor, qca_dump_ptr->id_product); 3167 skb_put_data(skb, buf, strlen(buf)); 3168 3169 snprintf(buf, sizeof(buf), "Lmp Subversion: 0x%x\n", 3170 hdev->lmp_subver); 3171 skb_put_data(skb, buf, strlen(buf)); 3172 } 3173 3174 static void btusb_coredump_qca(struct hci_dev *hdev) 3175 { 3176 int err; 3177 static const u8 param[] = { 0x26 }; 3178 3179 err = __hci_cmd_send(hdev, 0xfc0c, 1, param); 3180 if (err < 0) 3181 bt_dev_err(hdev, "%s: triggle crash failed (%d)", __func__, err); 3182 } 3183 3184 /* Return: 0 on success, negative errno on failure. */ 3185 static int handle_dump_pkt_qca(struct hci_dev *hdev, struct sk_buff *skb) 3186 { 3187 int ret = 0; 3188 unsigned int skip = 0; 3189 u8 pkt_type; 3190 u16 seqno; 3191 u32 dump_size; 3192 3193 struct qca_dump_hdr *dump_hdr; 3194 struct btusb_data *btdata = hci_get_drvdata(hdev); 3195 struct btqca_data *btqca_data = hci_get_priv(hdev); 3196 struct qca_dump_info *qca_dump_ptr = &btqca_data->qca_dump; 3197 struct usb_device *udev = btdata->udev; 3198 3199 pkt_type = hci_skb_pkt_type(skb); 3200 skip = sizeof(struct hci_event_hdr); 3201 if (pkt_type == HCI_ACLDATA_PKT) 3202 skip += sizeof(struct hci_acl_hdr); 3203 3204 skb_pull(skb, skip); 3205 dump_hdr = (struct qca_dump_hdr *)skb->data; 3206 3207 seqno = le16_to_cpu(dump_hdr->seqno); 3208 if (seqno == 0) { 3209 set_bit(BTUSB_HW_SSR_ACTIVE, &btdata->flags); 3210 dump_size = le32_to_cpu(dump_hdr->ram_dump_size); 3211 if (!dump_size || (dump_size > QCA_MEMDUMP_SIZE_MAX)) { 3212 ret = -EILSEQ; 3213 bt_dev_err(hdev, "Invalid memdump size(%u)", 3214 dump_size); 3215 goto out; 3216 } 3217 3218 ret = hci_devcd_init(hdev, dump_size); 3219 if (ret < 0) { 3220 bt_dev_err(hdev, "memdump init error(%d)", ret); 3221 goto out; 3222 } 3223 3224 qca_dump_ptr->ram_dump_size = dump_size; 3225 qca_dump_ptr->ram_dump_seqno = 0; 3226 3227 skb_pull(skb, offsetof(struct qca_dump_hdr, data0)); 3228 3229 usb_disable_autosuspend(udev); 3230 bt_dev_info(hdev, "%s memdump size(%u)\n", 3231 (pkt_type == HCI_ACLDATA_PKT) ? "ACL" : "event", 3232 dump_size); 3233 } else { 3234 skb_pull(skb, offsetof(struct qca_dump_hdr, data)); 3235 } 3236 3237 if (!qca_dump_ptr->ram_dump_size) { 3238 ret = -EINVAL; 3239 bt_dev_err(hdev, "memdump is not active"); 3240 goto out; 3241 } 3242 3243 if ((seqno > qca_dump_ptr->ram_dump_seqno + 1) && seqno != QCA_LAST_SEQUENCE_NUM) { 3244 dump_size = QCA_MEMDUMP_PKT_SIZE * (seqno - qca_dump_ptr->ram_dump_seqno - 1); 3245 hci_devcd_append_pattern(hdev, 0x0, dump_size); 3246 bt_dev_err(hdev, 3247 "expected memdump seqno(%u) is not received(%u)\n", 3248 qca_dump_ptr->ram_dump_seqno, seqno); 3249 qca_dump_ptr->ram_dump_seqno = seqno; 3250 kfree_skb(skb); 3251 return ret; 3252 } 3253 3254 hci_devcd_append(hdev, skb); 3255 qca_dump_ptr->ram_dump_seqno++; 3256 if (seqno == QCA_LAST_SEQUENCE_NUM) { 3257 bt_dev_info(hdev, 3258 "memdump done: pkts(%u), total(%u)\n", 3259 qca_dump_ptr->ram_dump_seqno, qca_dump_ptr->ram_dump_size); 3260 3261 hci_devcd_complete(hdev); 3262 goto out; 3263 } 3264 return ret; 3265 3266 out: 3267 if (qca_dump_ptr->ram_dump_size) 3268 usb_enable_autosuspend(udev); 3269 qca_dump_ptr->ram_dump_size = 0; 3270 qca_dump_ptr->ram_dump_seqno = 0; 3271 clear_bit(BTUSB_HW_SSR_ACTIVE, &btdata->flags); 3272 3273 if (ret < 0) 3274 kfree_skb(skb); 3275 return ret; 3276 } 3277 3278 /* Return: true if the ACL packet is a dump packet, false otherwise. */ 3279 static bool acl_pkt_is_dump_qca(struct hci_dev *hdev, struct sk_buff *skb) 3280 { 3281 struct hci_event_hdr *event_hdr; 3282 struct hci_acl_hdr *acl_hdr; 3283 struct qca_dump_hdr *dump_hdr; 3284 struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC); 3285 bool is_dump = false; 3286 3287 if (!clone) 3288 return false; 3289 3290 acl_hdr = skb_pull_data(clone, sizeof(*acl_hdr)); 3291 if (!acl_hdr || (le16_to_cpu(acl_hdr->handle) != QCA_MEMDUMP_ACL_HANDLE)) 3292 goto out; 3293 3294 event_hdr = skb_pull_data(clone, sizeof(*event_hdr)); 3295 if (!event_hdr || event_hdr->evt != HCI_EV_VENDOR) 3296 goto out; 3297 3298 dump_hdr = skb_pull_data(clone, sizeof(*dump_hdr)); 3299 if (!dump_hdr || (dump_hdr->vse_class != QCA_MEMDUMP_VSE_CLASS) || 3300 (dump_hdr->msg_type != QCA_MEMDUMP_MSG_TYPE)) 3301 goto out; 3302 3303 is_dump = true; 3304 out: 3305 consume_skb(clone); 3306 return is_dump; 3307 } 3308 3309 /* Return: true if the event packet is a dump packet, false otherwise. */ 3310 static bool evt_pkt_is_dump_qca(struct hci_dev *hdev, struct sk_buff *skb) 3311 { 3312 struct hci_event_hdr *event_hdr; 3313 struct qca_dump_hdr *dump_hdr; 3314 struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC); 3315 bool is_dump = false; 3316 3317 if (!clone) 3318 return false; 3319 3320 event_hdr = skb_pull_data(clone, sizeof(*event_hdr)); 3321 if (!event_hdr || event_hdr->evt != HCI_EV_VENDOR) 3322 goto out; 3323 3324 dump_hdr = skb_pull_data(clone, sizeof(*dump_hdr)); 3325 if (!dump_hdr || (dump_hdr->vse_class != QCA_MEMDUMP_VSE_CLASS) || 3326 (dump_hdr->msg_type != QCA_MEMDUMP_MSG_TYPE)) 3327 goto out; 3328 3329 is_dump = true; 3330 out: 3331 consume_skb(clone); 3332 return is_dump; 3333 } 3334 3335 static int btusb_recv_acl_qca(struct hci_dev *hdev, struct sk_buff *skb) 3336 { 3337 if (acl_pkt_is_dump_qca(hdev, skb)) 3338 return handle_dump_pkt_qca(hdev, skb); 3339 return hci_recv_frame(hdev, skb); 3340 } 3341 3342 static int btusb_recv_evt_qca(struct hci_dev *hdev, struct sk_buff *skb) 3343 { 3344 if (evt_pkt_is_dump_qca(hdev, skb)) 3345 return handle_dump_pkt_qca(hdev, skb); 3346 return hci_recv_frame(hdev, skb); 3347 } 3348 3349 3350 #define QCA_DFU_PACKET_LEN 4096 3351 3352 #define QCA_GET_TARGET_VERSION 0x09 3353 #define QCA_CHECK_STATUS 0x05 3354 #define QCA_DFU_DOWNLOAD 0x01 3355 3356 #define QCA_SYSCFG_UPDATED 0x40 3357 #define QCA_PATCH_UPDATED 0x80 3358 #define QCA_DFU_TIMEOUT 3000 3359 #define QCA_FLAG_MULTI_NVM 0x80 3360 #define QCA_BT_RESET_WAIT_MS 100 3361 3362 #define WCN6855_2_0_RAM_VERSION_GF 0x400c1200 3363 #define WCN6855_2_1_RAM_VERSION_GF 0x400c1211 3364 3365 struct qca_version { 3366 __le32 rom_version; 3367 __le32 patch_version; 3368 __le32 ram_version; 3369 __u8 chip_id; 3370 __u8 platform_id; 3371 __le16 flag; 3372 __u8 reserved[4]; 3373 } __packed; 3374 3375 struct qca_rampatch_version { 3376 __le16 rom_version_high; 3377 __le16 rom_version_low; 3378 __le16 patch_version; 3379 } __packed; 3380 3381 struct qca_device_info { 3382 u32 rom_version; 3383 u8 rampatch_hdr; /* length of header in rampatch */ 3384 u8 nvm_hdr; /* length of header in NVM */ 3385 u8 ver_offset; /* offset of version structure in rampatch */ 3386 }; 3387 3388 struct qca_custom_firmware { 3389 u32 rom_version; 3390 u16 board_id; 3391 const char *subdirectory; 3392 }; 3393 3394 static const struct qca_device_info qca_devices_table[] = { 3395 { 0x00000100, 20, 4, 8 }, /* Rome 1.0 */ 3396 { 0x00000101, 20, 4, 8 }, /* Rome 1.1 */ 3397 { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */ 3398 { 0x00000201, 28, 4, 16 }, /* Rome 2.1 */ 3399 { 0x00000300, 28, 4, 16 }, /* Rome 3.0 */ 3400 { 0x00000302, 28, 4, 16 }, /* Rome 3.2 */ 3401 { 0x00130100, 40, 4, 16 }, /* WCN6855 1.0 */ 3402 { 0x00130200, 40, 4, 16 }, /* WCN6855 2.0 */ 3403 { 0x00130201, 40, 4, 16 }, /* WCN6855 2.1 */ 3404 { 0x00190200, 40, 4, 16 }, /* WCN785x 2.0 */ 3405 }; 3406 3407 static const struct qca_custom_firmware qca_custom_btfws[] = { 3408 { 0x00130201, 0x030A, "QCA2066" }, 3409 { 0x00130201, 0x030B, "QCA2066" }, 3410 { }, 3411 }; 3412 3413 static u16 qca_extract_board_id(const struct qca_version *ver) 3414 { 3415 u16 flag = le16_to_cpu(ver->flag); 3416 u16 board_id = 0; 3417 3418 if (((flag >> 8) & 0xff) == QCA_FLAG_MULTI_NVM) { 3419 /* The board_id should be split into two bytes 3420 * The 1st byte is chip ID, and the 2nd byte is platform ID 3421 * For example, board ID 0x010A, 0x01 is platform ID. 0x0A is chip ID 3422 * we have several platforms, and platform IDs are continuously added 3423 * Platform ID: 3424 * 0x00 is for Mobile 3425 * 0x01 is for X86 3426 * 0x02 is for Automotive 3427 * 0x03 is for Consumer electronic 3428 */ 3429 board_id = (ver->chip_id << 8) + ver->platform_id; 3430 } 3431 3432 /* Take 0xffff as invalid board ID */ 3433 if (board_id == 0xffff) 3434 board_id = 0; 3435 3436 return board_id; 3437 } 3438 3439 static const char *qca_get_fw_subdirectory(const struct qca_version *ver) 3440 { 3441 const struct qca_custom_firmware *ptr; 3442 u32 rom_ver; 3443 u16 board_id; 3444 3445 rom_ver = le32_to_cpu(ver->rom_version); 3446 board_id = qca_extract_board_id(ver); 3447 if (!board_id) 3448 return NULL; 3449 3450 for (ptr = qca_custom_btfws; ptr->rom_version; ptr++) { 3451 if (ptr->rom_version == rom_ver && 3452 ptr->board_id == board_id) 3453 return ptr->subdirectory; 3454 } 3455 3456 return NULL; 3457 } 3458 3459 static int btusb_qca_send_vendor_req(struct usb_device *udev, u8 request, 3460 void *data, u16 size) 3461 { 3462 int err; 3463 3464 /* Found some of USB hosts have IOT issues with ours so that we should 3465 * not wait until HCI layer is ready. 3466 */ 3467 err = usb_control_msg_recv(udev, 0, request, USB_TYPE_VENDOR | USB_DIR_IN, 3468 0, 0, data, size, USB_CTRL_GET_TIMEOUT, 3469 GFP_KERNEL); 3470 if (err) 3471 dev_err(&udev->dev, "Failed to access otp area (%d)", err); 3472 3473 return err; 3474 } 3475 3476 static int btusb_setup_qca_download_fw(struct hci_dev *hdev, 3477 const struct firmware *firmware, 3478 size_t hdr_size) 3479 { 3480 struct btusb_data *btdata = hci_get_drvdata(hdev); 3481 struct usb_device *udev = btdata->udev; 3482 size_t count, size, sent = 0; 3483 int pipe, len, err; 3484 u8 *buf; 3485 3486 buf = kmalloc(QCA_DFU_PACKET_LEN, GFP_KERNEL); 3487 if (!buf) 3488 return -ENOMEM; 3489 3490 count = firmware->size; 3491 3492 size = min_t(size_t, count, hdr_size); 3493 memcpy(buf, firmware->data, size); 3494 3495 /* USB patches should go down to controller through USB path 3496 * because binary format fits to go down through USB channel. 3497 * USB control path is for patching headers and USB bulk is for 3498 * patch body. 3499 */ 3500 pipe = usb_sndctrlpipe(udev, 0); 3501 err = usb_control_msg(udev, pipe, QCA_DFU_DOWNLOAD, USB_TYPE_VENDOR, 3502 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); 3503 if (err < 0) { 3504 bt_dev_err(hdev, "Failed to send headers (%d)", err); 3505 goto done; 3506 } 3507 3508 sent += size; 3509 count -= size; 3510 3511 /* ep2 need time to switch from function acl to function dfu, 3512 * so we add 20ms delay here. 3513 */ 3514 msleep(20); 3515 3516 while (count) { 3517 size = min_t(size_t, count, QCA_DFU_PACKET_LEN); 3518 3519 memcpy(buf, firmware->data + sent, size); 3520 3521 pipe = usb_sndbulkpipe(udev, 0x02); 3522 err = usb_bulk_msg(udev, pipe, buf, size, &len, 3523 QCA_DFU_TIMEOUT); 3524 if (err < 0) { 3525 bt_dev_err(hdev, "Failed to send body at %zd of %zd (%d)", 3526 sent, firmware->size, err); 3527 break; 3528 } 3529 3530 if (size != len) { 3531 bt_dev_err(hdev, "Failed to get bulk buffer"); 3532 err = -EILSEQ; 3533 break; 3534 } 3535 3536 sent += size; 3537 count -= size; 3538 } 3539 3540 done: 3541 kfree(buf); 3542 return err; 3543 } 3544 3545 static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev, 3546 struct qca_version *ver, 3547 const struct qca_device_info *info) 3548 { 3549 struct qca_rampatch_version *rver; 3550 const struct firmware *fw; 3551 const char *fw_subdir; 3552 u32 ver_rom, ver_patch, rver_rom; 3553 u16 rver_rom_low, rver_rom_high, rver_patch; 3554 char fwname[80]; 3555 int err; 3556 3557 ver_rom = le32_to_cpu(ver->rom_version); 3558 ver_patch = le32_to_cpu(ver->patch_version); 3559 3560 fw_subdir = qca_get_fw_subdirectory(ver); 3561 if (fw_subdir) 3562 snprintf(fwname, sizeof(fwname), "qca/%s/rampatch_usb_%08x.bin", 3563 fw_subdir, ver_rom); 3564 else 3565 snprintf(fwname, sizeof(fwname), "qca/rampatch_usb_%08x.bin", 3566 ver_rom); 3567 3568 err = request_firmware(&fw, fwname, &hdev->dev); 3569 if (err) { 3570 bt_dev_err(hdev, "failed to request rampatch file: %s (%d)", 3571 fwname, err); 3572 return err; 3573 } 3574 3575 bt_dev_info(hdev, "using rampatch file: %s", fwname); 3576 3577 rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset); 3578 rver_rom_low = le16_to_cpu(rver->rom_version_low); 3579 rver_patch = le16_to_cpu(rver->patch_version); 3580 3581 if (ver_rom & ~0xffffU) { 3582 rver_rom_high = le16_to_cpu(rver->rom_version_high); 3583 rver_rom = rver_rom_high << 16 | rver_rom_low; 3584 } else { 3585 rver_rom = rver_rom_low; 3586 } 3587 3588 bt_dev_info(hdev, "QCA: patch rome 0x%x build 0x%x, " 3589 "firmware rome 0x%x build 0x%x", 3590 rver_rom, rver_patch, ver_rom, ver_patch); 3591 3592 /* Allow rampatch when the patch version equals the firmware version. 3593 * A firmware download may be aborted by a transient USB error (e.g. 3594 * disconnect) after the controller updates version info but before 3595 * completion. 3596 * Allowing equal versions enables re-flashing during recovery. 3597 */ 3598 if (rver_rom != ver_rom || rver_patch < ver_patch) { 3599 bt_dev_err(hdev, "rampatch file version did not match with firmware"); 3600 err = -EINVAL; 3601 goto done; 3602 } 3603 3604 err = btusb_setup_qca_download_fw(hdev, fw, info->rampatch_hdr); 3605 3606 done: 3607 release_firmware(fw); 3608 3609 return err; 3610 } 3611 3612 static void btusb_generate_qca_nvm_name(char *fwname, size_t max_size, 3613 const struct qca_version *ver) 3614 { 3615 u32 rom_version = le32_to_cpu(ver->rom_version); 3616 const char *variant, *fw_subdir; 3617 int len; 3618 u16 board_id; 3619 3620 fw_subdir = qca_get_fw_subdirectory(ver); 3621 board_id = qca_extract_board_id(ver); 3622 3623 switch (le32_to_cpu(ver->ram_version)) { 3624 case WCN6855_2_0_RAM_VERSION_GF: 3625 case WCN6855_2_1_RAM_VERSION_GF: 3626 variant = "_gf"; 3627 break; 3628 default: 3629 variant = NULL; 3630 break; 3631 } 3632 3633 if (fw_subdir) 3634 len = snprintf(fwname, max_size, "qca/%s/nvm_usb_%08x", 3635 fw_subdir, rom_version); 3636 else 3637 len = snprintf(fwname, max_size, "qca/nvm_usb_%08x", 3638 rom_version); 3639 if (variant) 3640 len += snprintf(fwname + len, max_size - len, "%s", variant); 3641 if (board_id) 3642 len += snprintf(fwname + len, max_size - len, "_%04x", board_id); 3643 len += snprintf(fwname + len, max_size - len, ".bin"); 3644 } 3645 3646 static int btusb_setup_qca_load_nvm(struct hci_dev *hdev, 3647 struct qca_version *ver, 3648 const struct qca_device_info *info) 3649 { 3650 const struct firmware *fw; 3651 char fwname[80]; 3652 int err; 3653 3654 btusb_generate_qca_nvm_name(fwname, sizeof(fwname), ver); 3655 3656 err = request_firmware(&fw, fwname, &hdev->dev); 3657 if (err) { 3658 bt_dev_err(hdev, "failed to request NVM file: %s (%d)", 3659 fwname, err); 3660 return err; 3661 } 3662 3663 bt_dev_info(hdev, "using NVM file: %s", fwname); 3664 3665 err = btusb_setup_qca_download_fw(hdev, fw, info->nvm_hdr); 3666 3667 release_firmware(fw); 3668 3669 return err; 3670 } 3671 3672 /* identify the ROM version and check whether patches are needed */ 3673 static bool btusb_qca_need_patch(struct usb_device *udev) 3674 { 3675 struct qca_version ver; 3676 3677 if (btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, 3678 sizeof(ver))) 3679 return false; 3680 /* only low ROM versions need patches */ 3681 return !(le32_to_cpu(ver.rom_version) & ~0xffffU); 3682 } 3683 3684 static int btusb_setup_qca(struct hci_dev *hdev) 3685 { 3686 struct btusb_data *btdata = hci_get_drvdata(hdev); 3687 struct usb_device *udev = btdata->udev; 3688 const struct qca_device_info *info = NULL; 3689 struct qca_version ver; 3690 u32 ver_rom; 3691 u8 status; 3692 int i, err; 3693 3694 err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, 3695 sizeof(ver)); 3696 if (err) 3697 return err; 3698 3699 ver_rom = le32_to_cpu(ver.rom_version); 3700 3701 for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) { 3702 if (ver_rom == qca_devices_table[i].rom_version) 3703 info = &qca_devices_table[i]; 3704 } 3705 if (!info) { 3706 /* If the rom_version is not matched in the qca_devices_table 3707 * and the high ROM version is not zero, we assume this chip no 3708 * need to load the rampatch and nvm. 3709 */ 3710 if (ver_rom & ~0xffffU) 3711 return 0; 3712 3713 bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom); 3714 return -ENODEV; 3715 } 3716 3717 err = btusb_qca_send_vendor_req(udev, QCA_CHECK_STATUS, &status, 3718 sizeof(status)); 3719 if (err) 3720 return err; 3721 3722 if (!(status & QCA_PATCH_UPDATED)) { 3723 err = btusb_setup_qca_load_rampatch(hdev, &ver, info); 3724 if (err < 0) 3725 return err; 3726 } 3727 3728 err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, 3729 sizeof(ver)); 3730 if (err) 3731 return err; 3732 3733 if (btdata->match_id->driver_info & BTUSB_QCA_WCN6855) { 3734 struct btqca_data *btqca_data = hci_get_priv(hdev); 3735 3736 btqca_data->qca_dump.fw_version = le32_to_cpu(ver.patch_version); 3737 btqca_data->qca_dump.controller_id = le32_to_cpu(ver.rom_version); 3738 } 3739 3740 if (!(status & QCA_SYSCFG_UPDATED)) { 3741 err = btusb_setup_qca_load_nvm(hdev, &ver, info); 3742 if (err < 0) 3743 return err; 3744 3745 /* WCN6855 2.1 and later will reset to apply firmware downloaded here, so 3746 * wait ~100ms for reset Done then go ahead, otherwise, it maybe 3747 * cause potential enable failure. 3748 */ 3749 if (info->rom_version >= 0x00130201) 3750 msleep(QCA_BT_RESET_WAIT_MS); 3751 } 3752 3753 /* Mark HCI_OP_ENHANCED_SETUP_SYNC_CONN as broken as it doesn't seem to 3754 * work with the likes of HSP/HFP mSBC. 3755 */ 3756 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN); 3757 3758 return 0; 3759 } 3760 3761 static inline int __set_diag_interface(struct hci_dev *hdev) 3762 { 3763 struct btusb_data *data = hci_get_drvdata(hdev); 3764 struct usb_interface *intf = data->diag; 3765 int ret; 3766 3767 if (!data->diag) 3768 return -ENODEV; 3769 3770 ret = usb_find_common_endpoints(intf->cur_altsetting, &data->diag_rx_ep, 3771 &data->diag_tx_ep, NULL, NULL); 3772 if (ret) { 3773 bt_dev_err(hdev, "invalid diagnostic descriptors"); 3774 return -ENODEV; 3775 } 3776 3777 return 0; 3778 } 3779 3780 static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable) 3781 { 3782 struct btusb_data *data = hci_get_drvdata(hdev); 3783 struct sk_buff *skb; 3784 struct urb *urb; 3785 unsigned int pipe; 3786 3787 if (!data->diag_tx_ep) 3788 return ERR_PTR(-ENODEV); 3789 3790 urb = usb_alloc_urb(0, GFP_KERNEL); 3791 if (!urb) 3792 return ERR_PTR(-ENOMEM); 3793 3794 skb = bt_skb_alloc(2, GFP_KERNEL); 3795 if (!skb) { 3796 usb_free_urb(urb); 3797 return ERR_PTR(-ENOMEM); 3798 } 3799 3800 skb_put_u8(skb, 0xf0); 3801 skb_put_u8(skb, enable); 3802 3803 pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress); 3804 3805 usb_fill_bulk_urb(urb, data->udev, pipe, 3806 skb->data, skb->len, btusb_tx_complete, skb); 3807 3808 skb->dev = (void *)hdev; 3809 3810 return urb; 3811 } 3812 3813 static int btusb_bcm_set_diag(struct hci_dev *hdev, bool enable) 3814 { 3815 struct btusb_data *data = hci_get_drvdata(hdev); 3816 struct urb *urb; 3817 3818 if (!data->diag) 3819 return -ENODEV; 3820 3821 if (!test_bit(HCI_RUNNING, &hdev->flags)) 3822 return -ENETDOWN; 3823 3824 urb = alloc_diag_urb(hdev, enable); 3825 if (IS_ERR(urb)) 3826 return PTR_ERR(urb); 3827 3828 return submit_or_queue_tx_urb(hdev, urb); 3829 } 3830 3831 #ifdef CONFIG_PM 3832 static irqreturn_t btusb_oob_wake_handler(int irq, void *priv) 3833 { 3834 struct btusb_data *data = priv; 3835 3836 pm_wakeup_event(&data->udev->dev, 0); 3837 pm_system_wakeup(); 3838 3839 /* Disable only if not already disabled (keep it balanced) */ 3840 if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) { 3841 disable_irq_nosync(irq); 3842 disable_irq_wake(irq); 3843 } 3844 return IRQ_HANDLED; 3845 } 3846 3847 static const struct of_device_id btusb_match_table[] = { 3848 { .compatible = "usb1286,204e" }, 3849 { .compatible = "usbcf3,e300" }, /* QCA6174A */ 3850 { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */ 3851 { } 3852 }; 3853 MODULE_DEVICE_TABLE(of, btusb_match_table); 3854 3855 /* Use an oob wakeup pin? */ 3856 static int btusb_config_oob_wake(struct hci_dev *hdev) 3857 { 3858 struct btusb_data *data = hci_get_drvdata(hdev); 3859 struct device *dev = &data->udev->dev; 3860 int irq, ret; 3861 3862 clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags); 3863 3864 if (!of_match_device(btusb_match_table, dev)) 3865 return 0; 3866 3867 /* Move on if no IRQ specified */ 3868 irq = of_irq_get_byname(dev->of_node, "wakeup"); 3869 if (irq <= 0) { 3870 bt_dev_dbg(hdev, "%s: no OOB Wakeup IRQ in DT", __func__); 3871 return 0; 3872 } 3873 3874 irq_set_status_flags(irq, IRQ_NOAUTOEN); 3875 ret = request_irq(irq, btusb_oob_wake_handler, 0, "OOB Wake-on-BT", data); 3876 if (ret) { 3877 bt_dev_err(hdev, "%s: IRQ request failed", __func__); 3878 return ret; 3879 } 3880 3881 ret = device_init_wakeup(dev, true); 3882 if (ret) { 3883 bt_dev_err(hdev, "%s: failed to init_wakeup", __func__); 3884 goto err_free_irq; 3885 } 3886 3887 data->oob_wake_irq = irq; 3888 bt_dev_info(hdev, "OOB Wake-on-BT configured at IRQ %u", irq); 3889 3890 return 0; 3891 3892 err_free_irq: 3893 free_irq(irq, data); 3894 3895 return ret; 3896 } 3897 #else 3898 static inline int btusb_config_oob_wake(struct hci_dev *hdev) 3899 { 3900 return 0; 3901 } 3902 #endif 3903 3904 static void btusb_check_needs_reset_resume(struct usb_interface *intf) 3905 { 3906 if (dmi_check_system(btusb_needs_reset_resume_table)) 3907 interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; 3908 } 3909 3910 static bool btusb_wakeup(struct hci_dev *hdev) 3911 { 3912 struct btusb_data *data = hci_get_drvdata(hdev); 3913 3914 return device_may_wakeup(&data->udev->dev); 3915 } 3916 3917 static int btusb_shutdown_qca(struct hci_dev *hdev) 3918 { 3919 int err; 3920 3921 err = __hci_reset_sync(hdev); 3922 if (err) 3923 bt_dev_err(hdev, "HCI reset during shutdown failed"); 3924 3925 return err; 3926 } 3927 3928 static ssize_t force_poll_sync_read(struct file *file, char __user *user_buf, 3929 size_t count, loff_t *ppos) 3930 { 3931 struct btusb_data *data = file->private_data; 3932 char buf[3]; 3933 3934 buf[0] = data->poll_sync ? 'Y' : 'N'; 3935 buf[1] = '\n'; 3936 buf[2] = '\0'; 3937 return simple_read_from_buffer(user_buf, count, ppos, buf, 2); 3938 } 3939 3940 static ssize_t force_poll_sync_write(struct file *file, 3941 const char __user *user_buf, 3942 size_t count, loff_t *ppos) 3943 { 3944 struct btusb_data *data = file->private_data; 3945 bool enable; 3946 int err; 3947 3948 err = kstrtobool_from_user(user_buf, count, &enable); 3949 if (err) 3950 return err; 3951 3952 /* Only allow changes while the adapter is down */ 3953 if (test_bit(HCI_UP, &data->hdev->flags)) 3954 return -EPERM; 3955 3956 if (data->poll_sync == enable) 3957 return -EALREADY; 3958 3959 data->poll_sync = enable; 3960 3961 return count; 3962 } 3963 3964 static const struct file_operations force_poll_sync_fops = { 3965 .owner = THIS_MODULE, 3966 .open = simple_open, 3967 .read = force_poll_sync_read, 3968 .write = force_poll_sync_write, 3969 .llseek = default_llseek, 3970 }; 3971 3972 #define BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS \ 3973 hci_opcode_pack(HCI_DRV_OGF_DRIVER_SPECIFIC, 0x0000) 3974 #define BTUSB_HCI_DRV_SUPPORTED_ALTSETTINGS_SIZE 0 3975 struct btusb_hci_drv_rp_supported_altsettings { 3976 __u8 num; 3977 __u8 altsettings[]; 3978 } __packed; 3979 3980 #define BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING \ 3981 hci_opcode_pack(HCI_DRV_OGF_DRIVER_SPECIFIC, 0x0001) 3982 #define BTUSB_HCI_DRV_SWITCH_ALTSETTING_SIZE 1 3983 struct btusb_hci_drv_cmd_switch_altsetting { 3984 __u8 altsetting; 3985 } __packed; 3986 3987 static const struct { 3988 u16 opcode; 3989 const char *desc; 3990 } btusb_hci_drv_supported_commands[] = { 3991 /* Common commands */ 3992 { HCI_DRV_OP_READ_INFO, "Read Info" }, 3993 3994 /* Driver specific commands */ 3995 { BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS, "Supported Altsettings" }, 3996 { BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING, "Switch Altsetting" }, 3997 }; 3998 static int btusb_hci_drv_read_info(struct hci_dev *hdev, void *data, 3999 u16 data_len) 4000 { 4001 struct hci_drv_rp_read_info *rp; 4002 size_t rp_size; 4003 int err, i; 4004 u16 opcode, num_supported_commands = 4005 ARRAY_SIZE(btusb_hci_drv_supported_commands); 4006 4007 rp_size = sizeof(*rp) + num_supported_commands * 2; 4008 4009 rp = kmalloc(rp_size, GFP_KERNEL); 4010 if (!rp) 4011 return -ENOMEM; 4012 4013 strscpy_pad(rp->driver_name, btusb_driver.name); 4014 4015 rp->num_supported_commands = cpu_to_le16(num_supported_commands); 4016 for (i = 0; i < num_supported_commands; i++) { 4017 opcode = btusb_hci_drv_supported_commands[i].opcode; 4018 bt_dev_info(hdev, 4019 "Supported HCI Drv command (0x%02x|0x%04x): %s", 4020 hci_opcode_ogf(opcode), 4021 hci_opcode_ocf(opcode), 4022 btusb_hci_drv_supported_commands[i].desc); 4023 rp->supported_commands[i] = cpu_to_le16(opcode); 4024 } 4025 4026 err = hci_drv_cmd_complete(hdev, HCI_DRV_OP_READ_INFO, 4027 HCI_DRV_STATUS_SUCCESS, rp, rp_size); 4028 4029 kfree(rp); 4030 return err; 4031 } 4032 4033 static int btusb_hci_drv_supported_altsettings(struct hci_dev *hdev, void *data, 4034 u16 data_len) 4035 { 4036 struct btusb_data *drvdata = hci_get_drvdata(hdev); 4037 struct btusb_hci_drv_rp_supported_altsettings *rp; 4038 size_t rp_size; 4039 int err; 4040 u8 i; 4041 4042 /* There are at most 7 alt (0 - 6) */ 4043 rp = kmalloc(sizeof(*rp) + 7, GFP_KERNEL); 4044 if (!rp) 4045 return -ENOMEM; 4046 4047 rp->num = 0; 4048 if (!drvdata->isoc) 4049 goto done; 4050 4051 for (i = 0; i <= 6; i++) { 4052 if (btusb_find_altsetting(drvdata, i)) 4053 rp->altsettings[rp->num++] = i; 4054 } 4055 4056 done: 4057 rp_size = sizeof(*rp) + rp->num; 4058 4059 err = hci_drv_cmd_complete(hdev, BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS, 4060 HCI_DRV_STATUS_SUCCESS, rp, rp_size); 4061 kfree(rp); 4062 return err; 4063 } 4064 4065 static int btusb_hci_drv_switch_altsetting(struct hci_dev *hdev, void *data, 4066 u16 data_len) 4067 { 4068 struct btusb_hci_drv_cmd_switch_altsetting *cmd = data; 4069 u8 status; 4070 4071 if (cmd->altsetting > 6) { 4072 status = HCI_DRV_STATUS_INVALID_PARAMETERS; 4073 } else { 4074 if (btusb_switch_alt_setting(hdev, cmd->altsetting)) 4075 status = HCI_DRV_STATUS_UNSPECIFIED_ERROR; 4076 else 4077 status = HCI_DRV_STATUS_SUCCESS; 4078 } 4079 4080 return hci_drv_cmd_status(hdev, BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING, 4081 status); 4082 } 4083 4084 static const struct hci_drv_handler btusb_hci_drv_common_handlers[] = { 4085 { btusb_hci_drv_read_info, HCI_DRV_READ_INFO_SIZE }, 4086 }; 4087 4088 static const struct hci_drv_handler btusb_hci_drv_specific_handlers[] = { 4089 { btusb_hci_drv_supported_altsettings, 4090 BTUSB_HCI_DRV_SUPPORTED_ALTSETTINGS_SIZE }, 4091 { btusb_hci_drv_switch_altsetting, 4092 BTUSB_HCI_DRV_SWITCH_ALTSETTING_SIZE }, 4093 }; 4094 4095 static struct hci_drv btusb_hci_drv = { 4096 .common_handler_count = ARRAY_SIZE(btusb_hci_drv_common_handlers), 4097 .common_handlers = btusb_hci_drv_common_handlers, 4098 .specific_handler_count = ARRAY_SIZE(btusb_hci_drv_specific_handlers), 4099 .specific_handlers = btusb_hci_drv_specific_handlers, 4100 }; 4101 4102 static int btusb_probe(struct usb_interface *intf, 4103 const struct usb_device_id *id) 4104 { 4105 struct gpio_desc *reset_gpio; 4106 struct btusb_data *data; 4107 struct hci_dev *hdev; 4108 unsigned ifnum_base; 4109 int err, priv_size = 0; 4110 4111 BT_DBG("intf %p id %p", intf, id); 4112 4113 if ((id->driver_info & BTUSB_IFNUM_2) && 4114 (intf->cur_altsetting->desc.bInterfaceNumber != 0) && 4115 (intf->cur_altsetting->desc.bInterfaceNumber != 2)) 4116 return -ENODEV; 4117 4118 ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber; 4119 4120 if (!id->driver_info) { 4121 const struct usb_device_id *match; 4122 4123 match = usb_match_id(intf, quirks_table); 4124 if (match) 4125 id = match; 4126 } 4127 4128 if (id->driver_info & BTUSB_IGNORE) 4129 return -ENODEV; 4130 4131 if (id->driver_info & BTUSB_ATH3012) { 4132 struct usb_device *udev = interface_to_usbdev(intf); 4133 4134 /* Old firmware would otherwise let ath3k driver load 4135 * patch and sysconfig files 4136 */ 4137 if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 && 4138 !btusb_qca_need_patch(udev)) 4139 return -ENODEV; 4140 } 4141 4142 data = kzalloc_obj(*data); 4143 if (!data) 4144 return -ENOMEM; 4145 4146 data->match_id = id; 4147 err = usb_find_common_endpoints(intf->cur_altsetting, &data->bulk_rx_ep, 4148 &data->bulk_tx_ep, &data->intr_ep, NULL); 4149 if (err) 4150 goto err_free_data; 4151 4152 if (id->driver_info & BTUSB_AMP) { 4153 data->cmdreq_type = USB_TYPE_CLASS | 0x01; 4154 data->cmdreq = 0x2b; 4155 } else { 4156 data->cmdreq_type = USB_TYPE_CLASS; 4157 data->cmdreq = 0x00; 4158 } 4159 4160 data->udev = interface_to_usbdev(intf); 4161 data->intf = intf; 4162 4163 INIT_WORK(&data->work, btusb_work); 4164 INIT_WORK(&data->waker, btusb_waker); 4165 INIT_DELAYED_WORK(&data->rx_work, btusb_rx_work); 4166 4167 skb_queue_head_init(&data->acl_q); 4168 4169 init_usb_anchor(&data->deferred); 4170 init_usb_anchor(&data->tx_anchor); 4171 spin_lock_init(&data->txlock); 4172 4173 init_usb_anchor(&data->intr_anchor); 4174 init_usb_anchor(&data->bulk_anchor); 4175 init_usb_anchor(&data->isoc_anchor); 4176 init_usb_anchor(&data->diag_anchor); 4177 init_usb_anchor(&data->ctrl_anchor); 4178 spin_lock_init(&data->rxlock); 4179 4180 data->recv_event = hci_recv_frame; 4181 data->recv_bulk = btusb_recv_bulk; 4182 4183 if (id->driver_info & BTUSB_INTEL_COMBINED) { 4184 /* Allocate extra space for Intel device */ 4185 priv_size += sizeof(struct btintel_data); 4186 4187 /* Override the rx handlers */ 4188 data->recv_event = btintel_recv_event; 4189 data->recv_bulk = btusb_recv_bulk_intel; 4190 } else if (id->driver_info & BTUSB_REALTEK) { 4191 /* Allocate extra space for Realtek device */ 4192 priv_size += sizeof(struct btrealtek_data); 4193 4194 data->recv_event = btusb_recv_event_realtek; 4195 } else if (id->driver_info & BTUSB_MEDIATEK) { 4196 /* Allocate extra space for Mediatek device */ 4197 priv_size += sizeof(struct btmtk_data); 4198 } else if (id->driver_info & BTUSB_QCA_WCN6855) { 4199 /* Allocate extra space for QCA WCN6855 device */ 4200 priv_size += sizeof(struct btqca_data); 4201 } 4202 4203 data->recv_acl = hci_recv_frame; 4204 4205 hdev = hci_alloc_dev_priv(priv_size); 4206 if (!hdev) { 4207 err = -ENOMEM; 4208 goto err_free_data; 4209 } 4210 4211 hdev->bus = HCI_USB; 4212 hci_set_drvdata(hdev, data); 4213 4214 data->hdev = hdev; 4215 4216 SET_HCIDEV_DEV(hdev, &intf->dev); 4217 4218 reset_gpio = gpiod_get_optional(&data->udev->dev, "reset", 4219 GPIOD_OUT_LOW); 4220 if (IS_ERR(reset_gpio)) { 4221 err = PTR_ERR(reset_gpio); 4222 goto err_free_hdev; 4223 } else if (reset_gpio) { 4224 data->reset_gpio = reset_gpio; 4225 } 4226 4227 hdev->open = btusb_open; 4228 hdev->close = btusb_close; 4229 hdev->flush = btusb_flush; 4230 hdev->send = btusb_send_frame; 4231 hdev->notify = btusb_notify; 4232 hdev->wakeup = btusb_wakeup; 4233 hdev->hci_drv = &btusb_hci_drv; 4234 4235 err = btusb_config_oob_wake(hdev); 4236 if (err) 4237 goto err_put_reset; 4238 4239 /* Marvell devices may need a specific chip configuration */ 4240 if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) { 4241 err = marvell_config_oob_wake(hdev); 4242 if (err) 4243 goto err_disable_wakeup; 4244 } 4245 4246 if (id->driver_info & BTUSB_CW6622) 4247 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_STORED_LINK_KEY); 4248 4249 if (id->driver_info & BTUSB_BCM2045) 4250 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_STORED_LINK_KEY); 4251 4252 if (id->driver_info & BTUSB_BCM92035) 4253 hdev->setup = btusb_setup_bcm92035; 4254 4255 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && 4256 (id->driver_info & BTUSB_BCM_PATCHRAM)) { 4257 hdev->manufacturer = 15; 4258 hdev->setup = btbcm_setup_patchram; 4259 hdev->set_diag = btusb_bcm_set_diag; 4260 hdev->set_bdaddr = btbcm_set_bdaddr; 4261 4262 /* Broadcom LM_DIAG Interface numbers are hardcoded */ 4263 data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); 4264 } 4265 4266 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && 4267 (id->driver_info & BTUSB_BCM_APPLE)) { 4268 hdev->manufacturer = 15; 4269 hdev->setup = btbcm_setup_apple; 4270 hdev->set_diag = btusb_bcm_set_diag; 4271 4272 /* Broadcom LM_DIAG Interface numbers are hardcoded */ 4273 data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); 4274 } 4275 4276 /* Combined Intel Device setup to support multiple setup routine */ 4277 if (id->driver_info & BTUSB_INTEL_COMBINED) { 4278 err = btintel_configure_setup(hdev, btusb_driver.name); 4279 if (err) 4280 goto err_kill_tx_urbs; 4281 4282 /* Transport specific configuration */ 4283 hdev->send = btusb_send_frame_intel; 4284 hdev->reset = btusb_intel_reset; 4285 4286 if (id->driver_info & BTUSB_INTEL_NO_WBS_SUPPORT) 4287 btintel_set_flag(hdev, INTEL_ROM_LEGACY_NO_WBS_SUPPORT); 4288 4289 if (id->driver_info & BTUSB_INTEL_BROKEN_INITIAL_NCMD) 4290 btintel_set_flag(hdev, INTEL_BROKEN_INITIAL_NCMD); 4291 4292 if (id->driver_info & BTUSB_INTEL_BROKEN_SHUTDOWN_LED) 4293 btintel_set_flag(hdev, INTEL_BROKEN_SHUTDOWN_LED); 4294 } 4295 4296 if (id->driver_info & BTUSB_MARVELL) 4297 hdev->set_bdaddr = btusb_set_bdaddr_marvell; 4298 4299 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) && 4300 (id->driver_info & BTUSB_MEDIATEK)) { 4301 hdev->setup = btusb_mtk_setup; 4302 hdev->shutdown = btusb_mtk_shutdown; 4303 hdev->manufacturer = 70; 4304 hdev->reset = btmtk_reset_sync; 4305 hdev->set_bdaddr = btmtk_set_bdaddr; 4306 hdev->send = btusb_send_frame_mtk; 4307 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN); 4308 hci_set_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP); 4309 data->recv_acl = btmtk_usb_recv_acl; 4310 data->recv_event = btmtk_recv_event; 4311 data->suspend = btmtk_usb_suspend; 4312 data->resume = btmtk_usb_resume; 4313 data->disconnect = btusb_mtk_disconnect; 4314 } 4315 4316 if (id->driver_info & BTUSB_SWAVE) { 4317 hci_set_quirk(hdev, HCI_QUIRK_FIXUP_INQUIRY_MODE); 4318 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_LOCAL_COMMANDS); 4319 } 4320 4321 if (id->driver_info & BTUSB_INTEL_BOOT) { 4322 hdev->manufacturer = 2; 4323 hci_set_quirk(hdev, HCI_QUIRK_RAW_DEVICE); 4324 } 4325 4326 if (id->driver_info & BTUSB_ATH3012) { 4327 data->setup_on_usb = btusb_setup_qca; 4328 hdev->set_bdaddr = btusb_set_bdaddr_ath3012; 4329 hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY); 4330 hci_set_quirk(hdev, HCI_QUIRK_STRICT_DUPLICATE_FILTER); 4331 } 4332 4333 if (id->driver_info & BTUSB_QCA_ROME) { 4334 data->setup_on_usb = btusb_setup_qca; 4335 hdev->shutdown = btusb_shutdown_qca; 4336 hdev->set_bdaddr = btusb_set_bdaddr_ath3012; 4337 hdev->reset = btusb_qca_reset; 4338 hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY); 4339 btusb_check_needs_reset_resume(intf); 4340 } 4341 4342 if (id->driver_info & BTUSB_QCA_WCN6855) { 4343 struct btqca_data *btqca_data = hci_get_priv(hdev); 4344 4345 btqca_data->qca_dump.id_vendor = id->idVendor; 4346 btqca_data->qca_dump.id_product = id->idProduct; 4347 data->recv_event = btusb_recv_evt_qca; 4348 data->recv_acl = btusb_recv_acl_qca; 4349 hci_devcd_register(hdev, btusb_coredump_qca, btusb_dump_hdr_qca, NULL); 4350 data->setup_on_usb = btusb_setup_qca; 4351 hdev->classify_pkt_type = btusb_classify_qca_pkt_type; 4352 hdev->shutdown = btusb_shutdown_qca; 4353 hdev->set_bdaddr = btusb_set_bdaddr_wcn6855; 4354 hdev->reset = btusb_qca_reset; 4355 hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY); 4356 hci_set_msft_opcode(hdev, 0xFD70); 4357 } 4358 4359 if (id->driver_info & BTUSB_AMP) { 4360 /* AMP controllers do not support SCO packets */ 4361 data->isoc = NULL; 4362 } else { 4363 /* Interface orders are hardcoded in the specification */ 4364 data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); 4365 data->isoc_ifnum = ifnum_base + 1; 4366 } 4367 4368 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) && 4369 (id->driver_info & BTUSB_REALTEK)) { 4370 btrtl_set_driver_name(hdev, btusb_driver.name); 4371 hdev->setup = btusb_setup_realtek; 4372 hdev->shutdown = btrtl_shutdown_realtek; 4373 hdev->reset = btusb_rtl_reset; 4374 hdev->hw_error = btusb_rtl_hw_error; 4375 4376 /* Realtek devices need to set remote wakeup on auto-suspend */ 4377 set_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags); 4378 set_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags); 4379 } 4380 4381 if (id->driver_info & BTUSB_ACTIONS_SEMI) { 4382 /* Support is advertised, but not implemented */ 4383 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ERR_DATA_REPORTING); 4384 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER); 4385 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT); 4386 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_EXT_SCAN); 4387 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_READ_ENC_KEY_SIZE); 4388 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_EXT_CREATE_CONN); 4389 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_WRITE_AUTH_PAYLOAD_TIMEOUT); 4390 } 4391 4392 if (!reset) 4393 hci_set_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE); 4394 4395 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { 4396 if (!disable_scofix) 4397 hci_set_quirk(hdev, HCI_QUIRK_FIXUP_BUFFER_SIZE); 4398 } 4399 4400 if (id->driver_info & BTUSB_BROKEN_ISOC) 4401 data->isoc = NULL; 4402 4403 if (id->driver_info & BTUSB_WIDEBAND_SPEECH) 4404 hci_set_quirk(hdev, HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED); 4405 4406 if (id->driver_info & BTUSB_INVALID_LE_STATES) 4407 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_LE_STATES); 4408 4409 if (id->driver_info & BTUSB_BROKEN_EXT_SCAN) 4410 hci_set_quirk(hdev, HCI_QUIRK_BROKEN_EXT_SCAN); 4411 4412 if (id->driver_info & BTUSB_DIGIANSWER) { 4413 data->cmdreq_type = USB_TYPE_VENDOR; 4414 hci_set_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE); 4415 } 4416 4417 if (id->driver_info & BTUSB_CSR) { 4418 struct usb_device *udev = data->udev; 4419 u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); 4420 4421 /* Old firmware would otherwise execute USB reset */ 4422 if (bcdDevice < 0x117) 4423 hci_set_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE); 4424 4425 /* This must be set first in case we disable it for fakes */ 4426 hci_set_quirk(hdev, HCI_QUIRK_SIMULTANEOUS_DISCOVERY); 4427 4428 /* Fake CSR devices with broken commands */ 4429 if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 && 4430 le16_to_cpu(udev->descriptor.idProduct) == 0x0001) 4431 hdev->setup = btusb_setup_csr; 4432 } 4433 4434 if (id->driver_info & BTUSB_SNIFFER) { 4435 struct usb_device *udev = data->udev; 4436 4437 /* New sniffer firmware has crippled HCI interface */ 4438 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) 4439 hci_set_quirk(hdev, HCI_QUIRK_RAW_DEVICE); 4440 } 4441 4442 if (id->driver_info & BTUSB_INTEL_BOOT) { 4443 /* A bug in the bootloader causes that interrupt interface is 4444 * only enabled after receiving SetInterface(0, AltSetting=0). 4445 */ 4446 err = usb_set_interface(data->udev, 0, 0); 4447 if (err < 0) { 4448 BT_ERR("failed to set interface 0, alt 0 %d", err); 4449 goto err_kill_tx_urbs; 4450 } 4451 } 4452 4453 if (data->isoc) { 4454 err = usb_driver_claim_interface(&btusb_driver, 4455 data->isoc, data); 4456 if (err < 0) 4457 goto err_kill_tx_urbs; 4458 } 4459 4460 if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) { 4461 if (!usb_driver_claim_interface(&btusb_driver, 4462 data->diag, data)) 4463 __set_diag_interface(hdev); 4464 else 4465 data->diag = NULL; 4466 } 4467 4468 if (enable_autosuspend) 4469 usb_enable_autosuspend(data->udev); 4470 4471 data->poll_sync = enable_poll_sync; 4472 4473 err = hci_register_dev(hdev); 4474 if (err < 0) 4475 goto err_release_siblings; 4476 4477 usb_set_intfdata(intf, data); 4478 4479 debugfs_create_file("force_poll_sync", 0644, hdev->debugfs, data, 4480 &force_poll_sync_fops); 4481 4482 return 0; 4483 4484 err_release_siblings: 4485 if (data->diag) { 4486 usb_set_intfdata(data->diag, NULL); 4487 usb_driver_release_interface(&btusb_driver, data->diag); 4488 } 4489 if (data->isoc) { 4490 usb_set_intfdata(data->isoc, NULL); 4491 usb_driver_release_interface(&btusb_driver, data->isoc); 4492 } 4493 err_kill_tx_urbs: 4494 usb_kill_anchored_urbs(&data->tx_anchor); 4495 err_disable_wakeup: 4496 if (data->oob_wake_irq) { 4497 device_init_wakeup(&data->udev->dev, false); 4498 free_irq(data->oob_wake_irq, data); 4499 } 4500 err_put_reset: 4501 if (data->reset_gpio) 4502 gpiod_put(data->reset_gpio); 4503 err_free_hdev: 4504 hci_free_dev(hdev); 4505 err_free_data: 4506 kfree(data); 4507 4508 return err; 4509 } 4510 4511 static void btusb_disconnect(struct usb_interface *intf) 4512 { 4513 struct btusb_data *data = usb_get_intfdata(intf); 4514 struct hci_dev *hdev; 4515 4516 BT_DBG("intf %p", intf); 4517 4518 if (!data) 4519 return; 4520 4521 hdev = data->hdev; 4522 usb_set_intfdata(data->intf, NULL); 4523 4524 if (data->isoc) 4525 usb_set_intfdata(data->isoc, NULL); 4526 4527 if (data->diag) 4528 usb_set_intfdata(data->diag, NULL); 4529 4530 if (data->disconnect) 4531 data->disconnect(hdev); 4532 4533 hci_unregister_dev(hdev); 4534 4535 if (data->oob_wake_irq) { 4536 device_init_wakeup(&data->udev->dev, false); 4537 free_irq(data->oob_wake_irq, data); 4538 } 4539 4540 if (data->reset_gpio) 4541 gpiod_put(data->reset_gpio); 4542 4543 if (intf == data->intf) { 4544 if (data->isoc) 4545 usb_driver_release_interface(&btusb_driver, data->isoc); 4546 if (data->diag) 4547 usb_driver_release_interface(&btusb_driver, data->diag); 4548 } else if (intf == data->isoc) { 4549 if (data->diag) 4550 usb_driver_release_interface(&btusb_driver, data->diag); 4551 usb_driver_release_interface(&btusb_driver, data->intf); 4552 } else if (intf == data->diag) { 4553 if (data->isoc) 4554 usb_driver_release_interface(&btusb_driver, data->isoc); 4555 usb_driver_release_interface(&btusb_driver, data->intf); 4556 } 4557 4558 hci_free_dev(hdev); 4559 kfree(data); 4560 } 4561 4562 static int btusb_suspend(struct usb_interface *intf, pm_message_t message) 4563 { 4564 struct btusb_data *data = usb_get_intfdata(intf); 4565 4566 BT_DBG("intf %p", intf); 4567 4568 /* Don't auto-suspend if there are connections or discovery in 4569 * progress; external suspend calls shall never fail. 4570 */ 4571 if (PMSG_IS_AUTO(message) && 4572 (hci_conn_count(data->hdev) || hci_discovery_active(data->hdev))) 4573 return -EBUSY; 4574 4575 if (data->suspend_count++) 4576 return 0; 4577 4578 spin_lock_irq(&data->txlock); 4579 if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) { 4580 set_bit(BTUSB_SUSPENDING, &data->flags); 4581 spin_unlock_irq(&data->txlock); 4582 } else { 4583 spin_unlock_irq(&data->txlock); 4584 data->suspend_count--; 4585 return -EBUSY; 4586 } 4587 4588 cancel_work_sync(&data->work); 4589 4590 if (data->suspend) 4591 data->suspend(data->hdev); 4592 4593 btusb_stop_traffic(data); 4594 usb_kill_anchored_urbs(&data->tx_anchor); 4595 4596 if (data->oob_wake_irq && device_may_wakeup(&data->udev->dev)) { 4597 set_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags); 4598 enable_irq_wake(data->oob_wake_irq); 4599 enable_irq(data->oob_wake_irq); 4600 } 4601 4602 /* For global suspend, Realtek devices lose the loaded fw 4603 * in them. But for autosuspend, firmware should remain. 4604 * Actually, it depends on whether the usb host sends 4605 * set feature (enable wakeup) or not. 4606 */ 4607 if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) { 4608 if (PMSG_IS_AUTO(message) && 4609 device_can_wakeup(&data->udev->dev)) 4610 data->udev->do_remote_wakeup = 1; 4611 else if (!PMSG_IS_AUTO(message) && 4612 !device_may_wakeup(&data->udev->dev)) { 4613 data->udev->do_remote_wakeup = 0; 4614 data->udev->reset_resume = 1; 4615 } 4616 } 4617 4618 return 0; 4619 } 4620 4621 static void play_deferred(struct btusb_data *data) 4622 { 4623 struct urb *urb; 4624 int err; 4625 4626 while ((urb = usb_get_from_anchor(&data->deferred))) { 4627 usb_anchor_urb(urb, &data->tx_anchor); 4628 4629 err = usb_submit_urb(urb, GFP_ATOMIC); 4630 if (err < 0) { 4631 if (err != -EPERM && err != -ENODEV) 4632 BT_ERR("%s urb %p submission failed (%d)", 4633 data->hdev->name, urb, -err); 4634 kfree(urb->setup_packet); 4635 usb_unanchor_urb(urb); 4636 usb_free_urb(urb); 4637 break; 4638 } 4639 4640 data->tx_in_flight++; 4641 usb_free_urb(urb); 4642 } 4643 4644 /* Cleanup the rest deferred urbs. */ 4645 while ((urb = usb_get_from_anchor(&data->deferred))) { 4646 kfree(urb->setup_packet); 4647 usb_free_urb(urb); 4648 } 4649 } 4650 4651 static int btusb_resume(struct usb_interface *intf) 4652 { 4653 struct btusb_data *data = usb_get_intfdata(intf); 4654 struct hci_dev *hdev = data->hdev; 4655 int err = 0; 4656 4657 BT_DBG("intf %p", intf); 4658 4659 if (--data->suspend_count) 4660 return 0; 4661 4662 /* Disable only if not already disabled (keep it balanced) */ 4663 if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) { 4664 disable_irq(data->oob_wake_irq); 4665 disable_irq_wake(data->oob_wake_irq); 4666 } 4667 4668 if (!test_bit(HCI_RUNNING, &hdev->flags)) 4669 goto done; 4670 4671 if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) { 4672 err = btusb_submit_intr_urb(hdev, GFP_NOIO); 4673 if (err < 0) { 4674 clear_bit(BTUSB_INTR_RUNNING, &data->flags); 4675 goto failed; 4676 } 4677 } 4678 4679 if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) { 4680 err = btusb_submit_bulk_urb(hdev, GFP_NOIO); 4681 if (err < 0) { 4682 clear_bit(BTUSB_BULK_RUNNING, &data->flags); 4683 goto failed; 4684 } 4685 4686 btusb_submit_bulk_urb(hdev, GFP_NOIO); 4687 } 4688 4689 if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) { 4690 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0) 4691 clear_bit(BTUSB_ISOC_RUNNING, &data->flags); 4692 else 4693 btusb_submit_isoc_urb(hdev, GFP_NOIO); 4694 } 4695 4696 if (data->resume) 4697 data->resume(hdev); 4698 4699 spin_lock_irq(&data->txlock); 4700 play_deferred(data); 4701 clear_bit(BTUSB_SUSPENDING, &data->flags); 4702 spin_unlock_irq(&data->txlock); 4703 schedule_work(&data->work); 4704 4705 return 0; 4706 4707 failed: 4708 usb_scuttle_anchored_urbs(&data->deferred); 4709 done: 4710 spin_lock_irq(&data->txlock); 4711 clear_bit(BTUSB_SUSPENDING, &data->flags); 4712 spin_unlock_irq(&data->txlock); 4713 4714 return err; 4715 } 4716 4717 #ifdef CONFIG_DEV_COREDUMP 4718 static void btusb_coredump(struct device *dev) 4719 { 4720 struct btusb_data *data = dev_get_drvdata(dev); 4721 struct hci_dev *hdev = data->hdev; 4722 4723 if (hdev->dump.coredump) 4724 hdev->dump.coredump(hdev); 4725 } 4726 #endif 4727 4728 static struct usb_driver btusb_driver = { 4729 .name = "btusb", 4730 .probe = btusb_probe, 4731 .disconnect = btusb_disconnect, 4732 .suspend = pm_ptr(btusb_suspend), 4733 .resume = pm_ptr(btusb_resume), 4734 .id_table = btusb_table, 4735 .supports_autosuspend = 1, 4736 .disable_hub_initiated_lpm = 1, 4737 4738 #ifdef CONFIG_DEV_COREDUMP 4739 .driver = { 4740 .coredump = btusb_coredump, 4741 }, 4742 #endif 4743 }; 4744 4745 module_usb_driver(btusb_driver); 4746 4747 module_param(disable_scofix, bool, 0644); 4748 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size"); 4749 4750 module_param(force_scofix, bool, 0644); 4751 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size"); 4752 4753 module_param(enable_autosuspend, bool, 0644); 4754 MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default"); 4755 4756 module_param(reset, bool, 0644); 4757 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); 4758 4759 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); 4760 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION); 4761 MODULE_VERSION(VERSION); 4762 MODULE_LICENSE("GPL"); 4763