Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * Generic Bluetooth USB driver |
| 5 | * |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 6 | * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 9 | #include <linux/dmi.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 10 | #include <linux/module.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 11 | #include <linux/usb.h> |
Hans de Goede | 61f5ace | 2018-01-08 10:44:16 +0100 | [diff] [blame] | 12 | #include <linux/usb/quirks.h> |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 13 | #include <linux/firmware.h> |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 14 | #include <linux/iopoll.h> |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 15 | #include <linux/of_device.h> |
| 16 | #include <linux/of_irq.h> |
Jeffy Chen | 017789f | 2017-02-24 14:24:29 +0800 | [diff] [blame] | 17 | #include <linux/suspend.h> |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 18 | #include <linux/gpio/consumer.h> |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 19 | #include <asm/unaligned.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 20 | |
| 21 | #include <net/bluetooth/bluetooth.h> |
| 22 | #include <net/bluetooth/hci_core.h> |
| 23 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 24 | #include "btintel.h" |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 25 | #include "btbcm.h" |
Carlo Caione | db33c77 | 2015-05-14 10:49:09 +0200 | [diff] [blame] | 26 | #include "btrtl.h" |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 27 | |
Marcel Holtmann | 34dced9b | 2015-04-05 22:52:16 -0700 | [diff] [blame] | 28 | #define VERSION "0.8" |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 29 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 30 | static bool disable_scofix; |
| 31 | static bool force_scofix; |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 32 | static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 33 | |
Shailendra Verma | 917a333 | 2015-05-25 23:53:40 +0530 | [diff] [blame] | 34 | static bool reset = true; |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 35 | |
| 36 | static struct usb_driver btusb_driver; |
| 37 | |
| 38 | #define BTUSB_IGNORE 0x01 |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 39 | #define BTUSB_DIGIANSWER 0x02 |
| 40 | #define BTUSB_CSR 0x04 |
| 41 | #define BTUSB_SNIFFER 0x08 |
| 42 | #define BTUSB_BCM92035 0x10 |
| 43 | #define BTUSB_BROKEN_ISOC 0x20 |
| 44 | #define BTUSB_WRONG_SCO_MTU 0x40 |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 45 | #define BTUSB_ATH3012 0x80 |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 46 | #define BTUSB_INTEL 0x100 |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 47 | #define BTUSB_INTEL_BOOT 0x200 |
| 48 | #define BTUSB_BCM_PATCHRAM 0x400 |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 49 | #define BTUSB_MARVELL 0x800 |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 50 | #define BTUSB_SWAVE 0x1000 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 51 | #define BTUSB_INTEL_NEW 0x2000 |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 52 | #define BTUSB_AMP 0x4000 |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 53 | #define BTUSB_QCA_ROME 0x8000 |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 54 | #define BTUSB_BCM_APPLE 0x10000 |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 55 | #define BTUSB_REALTEK 0x20000 |
Marcel Holtmann | 6c9d435 | 2015-10-17 14:39:27 +0200 | [diff] [blame] | 56 | #define BTUSB_BCM2045 0x40000 |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 57 | #define BTUSB_IFNUM_2 0x80000 |
Szymon Janc | 418678b | 2016-09-01 17:22:37 +0200 | [diff] [blame] | 58 | #define BTUSB_CW6622 0x100000 |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 59 | #define BTUSB_MEDIATEK 0x200000 |
Alain Michaud | 3e4e3f7 | 2020-02-27 18:29:37 +0000 | [diff] [blame] | 60 | #define BTUSB_WIDEBAND_SPEECH 0x400000 |
Alain Michaud | 22091585 | 2020-04-23 14:43:27 +0000 | [diff] [blame] | 61 | #define BTUSB_VALID_LE_STATES 0x800000 |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 62 | |
Marcel Holtmann | 5426520 | 2013-10-11 07:46:18 -0700 | [diff] [blame] | 63 | static const struct usb_device_id btusb_table[] = { |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 64 | /* Generic Bluetooth USB device */ |
| 65 | { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, |
| 66 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 67 | /* Generic Bluetooth AMP device */ |
| 68 | { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info = BTUSB_AMP }, |
| 69 | |
Daniel Drake | d63b282 | 2015-07-17 11:12:25 -0600 | [diff] [blame] | 70 | /* Generic Bluetooth USB interface */ |
| 71 | { USB_INTERFACE_INFO(0xe0, 0x01, 0x01) }, |
| 72 | |
Henrik Rydberg | 1fa6535 | 2012-08-25 19:28:06 +0200 | [diff] [blame] | 73 | /* Apple-specific (Broadcom) devices */ |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 74 | { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01), |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 75 | .driver_info = BTUSB_BCM_APPLE | BTUSB_IFNUM_2 }, |
Henrik Rydberg | 1fa6535 | 2012-08-25 19:28:06 +0200 | [diff] [blame] | 76 | |
Cho, Yu-Chen | 178c059 | 2013-06-04 21:40:26 +0800 | [diff] [blame] | 77 | /* MediaTek MT76x0E */ |
| 78 | { USB_DEVICE(0x0e8d, 0x763f) }, |
| 79 | |
Oliver Neukum | c510eae | 2011-09-21 11:41:45 +0200 | [diff] [blame] | 80 | /* Broadcom SoftSailing reporting vendor specific */ |
Don Zickus | 2e8b5063 | 2012-03-28 16:41:11 -0400 | [diff] [blame] | 81 | { USB_DEVICE(0x0a5c, 0x21e1) }, |
Oliver Neukum | c510eae | 2011-09-21 11:41:45 +0200 | [diff] [blame] | 82 | |
Nobuhiro Iwamatsu | 3cd0197 | 2010-08-20 16:24:07 +0900 | [diff] [blame] | 83 | /* Apple MacBookPro 7,1 */ |
| 84 | { USB_DEVICE(0x05ac, 0x8213) }, |
| 85 | |
Cyril Lacoux | 0a79f67 | 2010-07-14 10:29:27 +0400 | [diff] [blame] | 86 | /* Apple iMac11,1 */ |
| 87 | { USB_DEVICE(0x05ac, 0x8215) }, |
| 88 | |
Nobuhiro Iwamatsu | 9c04715 | 2010-08-20 16:24:06 +0900 | [diff] [blame] | 89 | /* Apple MacBookPro6,2 */ |
| 90 | { USB_DEVICE(0x05ac, 0x8218) }, |
| 91 | |
Edgar (gimli) Hucek | 3e3ede7 | 2010-11-04 08:04:33 +0100 | [diff] [blame] | 92 | /* Apple MacBookAir3,1, MacBookAir3,2 */ |
| 93 | { USB_DEVICE(0x05ac, 0x821b) }, |
| 94 | |
Pieter-Augustijn Van Malleghem | a63b723 | 2011-09-07 02:28:10 -0400 | [diff] [blame] | 95 | /* Apple MacBookAir4,1 */ |
| 96 | { USB_DEVICE(0x05ac, 0x821f) }, |
| 97 | |
Marc-Antoine Perennou | 88d377b | 2011-03-24 14:51:21 -0300 | [diff] [blame] | 98 | /* Apple MacBookPro8,2 */ |
| 99 | { USB_DEVICE(0x05ac, 0x821a) }, |
| 100 | |
Jurgen Kramer | f78b6826 | 2011-09-04 18:01:42 +0200 | [diff] [blame] | 101 | /* Apple MacMini5,1 */ |
| 102 | { USB_DEVICE(0x05ac, 0x8281) }, |
| 103 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 104 | /* AVM BlueFRITZ! USB v2.0 */ |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 105 | { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 106 | |
| 107 | /* Bluetooth Ultraport Module from IBM */ |
| 108 | { USB_DEVICE(0x04bf, 0x030a) }, |
| 109 | |
| 110 | /* ALPS Modules with non-standard id */ |
| 111 | { USB_DEVICE(0x044e, 0x3001) }, |
| 112 | { USB_DEVICE(0x044e, 0x3002) }, |
| 113 | |
| 114 | /* Ericsson with non-standard id */ |
| 115 | { USB_DEVICE(0x0bdb, 0x1002) }, |
| 116 | |
| 117 | /* Canyon CN-BTU1 with HID interfaces */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 118 | { USB_DEVICE(0x0c10, 0x0000) }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 119 | |
Wen-chien Jesse Sung | d13431c | 2011-11-08 14:30:22 +0800 | [diff] [blame] | 120 | /* Broadcom BCM20702A0 */ |
| 121 | { USB_DEVICE(0x413c, 0x8197) }, |
| 122 | |
Marcel Holtmann | d049f4e | 2015-01-26 20:35:32 -0800 | [diff] [blame] | 123 | /* Broadcom BCM20702B0 (Dynex/Insignia) */ |
| 124 | { USB_DEVICE(0x19ff, 0x0239), .driver_info = BTUSB_BCM_PATCHRAM }, |
| 125 | |
Santtu Rekilä | 2faf71c | 2015-10-05 15:45:27 +0300 | [diff] [blame] | 126 | /* Broadcom BCM43142A0 (Foxconn/Lenovo) */ |
Dmitry Tunin | 628c26b | 2017-07-06 14:41:13 +0300 | [diff] [blame] | 127 | { USB_VENDOR_AND_INTERFACE_INFO(0x105b, 0xff, 0x01, 0x01), |
| 128 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Santtu Rekilä | 2faf71c | 2015-10-05 15:45:27 +0300 | [diff] [blame] | 129 | |
Christoph Haag | a57bac4 | 2017-02-10 14:02:45 +0100 | [diff] [blame] | 130 | /* Broadcom BCM920703 (HTC Vive) */ |
| 131 | { USB_VENDOR_AND_INTERFACE_INFO(0x0bb4, 0xff, 0x01, 0x01), |
| 132 | .driver_info = BTUSB_BCM_PATCHRAM }, |
| 133 | |
Steven Harms | 9851403 | 2012-04-13 14:45:55 -0400 | [diff] [blame] | 134 | /* Foxconn - Hon Hai */ |
Heinrich Siebmanns | 6029ddc | 2014-12-03 19:32:22 +0100 | [diff] [blame] | 135 | { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01), |
| 136 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Steven Harms | 9851403 | 2012-04-13 14:45:55 -0400 | [diff] [blame] | 137 | |
Matej Dubovy | 8f0c304 | 2015-02-02 18:50:14 +0100 | [diff] [blame] | 138 | /* Lite-On Technology - Broadcom based */ |
| 139 | { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01), |
| 140 | .driver_info = BTUSB_BCM_PATCHRAM }, |
| 141 | |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 142 | /* Broadcom devices with vendor specific id */ |
Petri Gynther | 10d4c67 | 2014-05-08 15:50:01 -0700 | [diff] [blame] | 143 | { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01), |
| 144 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Gustavo Padovan | 92c385f | 2012-08-06 15:36:49 -0300 | [diff] [blame] | 145 | |
Marcel Holtmann | c2aef6e | 2014-07-21 14:02:33 +0200 | [diff] [blame] | 146 | /* ASUSTek Computer - Broadcom based */ |
Rick Dunn | 9a5abdaa | 2015-01-17 05:29:12 +0100 | [diff] [blame] | 147 | { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01), |
| 148 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Marcel Holtmann | c2aef6e | 2014-07-21 14:02:33 +0200 | [diff] [blame] | 149 | |
Ken O'Brien | 5bcecf3 | 2013-09-21 19:14:43 +0100 | [diff] [blame] | 150 | /* Belkin F8065bf - Broadcom based */ |
Marcel Holtmann | 6331c68 | 2015-03-27 15:11:41 -0700 | [diff] [blame] | 151 | { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01), |
| 152 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Ken O'Brien | 5bcecf3 | 2013-09-21 19:14:43 +0100 | [diff] [blame] | 153 | |
Jurgen Kramer | 9113bfd | 2014-02-15 12:01:09 +0100 | [diff] [blame] | 154 | /* IMC Networks - Broadcom based */ |
Marcel Holtmann | 6331c68 | 2015-03-27 15:11:41 -0700 | [diff] [blame] | 155 | { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01), |
| 156 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Jurgen Kramer | 9113bfd | 2014-02-15 12:01:09 +0100 | [diff] [blame] | 157 | |
Wen-chien Jesse Sung | fdfddc6 | 2017-01-10 15:41:13 +0800 | [diff] [blame] | 158 | /* Dell Computer - Broadcom based */ |
| 159 | { USB_VENDOR_AND_INTERFACE_INFO(0x413c, 0xff, 0x01, 0x01), |
| 160 | .driver_info = BTUSB_BCM_PATCHRAM }, |
| 161 | |
Dmitry Tunin | 1623d0b | 2015-12-05 14:09:36 +0300 | [diff] [blame] | 162 | /* Toshiba Corp - Broadcom based */ |
| 163 | { USB_VENDOR_AND_INTERFACE_INFO(0x0930, 0xff, 0x01, 0x01), |
| 164 | .driver_info = BTUSB_BCM_PATCHRAM }, |
| 165 | |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 166 | /* Intel Bluetooth USB Bootloader (RAM module) */ |
Marcel Holtmann | d92f2df | 2014-07-06 14:53:55 +0200 | [diff] [blame] | 167 | { USB_DEVICE(0x8087, 0x0a5a), |
| 168 | .driver_info = BTUSB_INTEL_BOOT | BTUSB_BROKEN_ISOC }, |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 169 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 170 | { } /* Terminating entry */ |
| 171 | }; |
| 172 | |
| 173 | MODULE_DEVICE_TABLE(usb, btusb_table); |
| 174 | |
Marcel Holtmann | 5426520 | 2013-10-11 07:46:18 -0700 | [diff] [blame] | 175 | static const struct usb_device_id blacklist_table[] = { |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 176 | /* CSR BlueCore devices */ |
| 177 | { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR }, |
| 178 | |
| 179 | /* Broadcom BCM2033 without firmware */ |
| 180 | { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE }, |
| 181 | |
Marcel Holtmann | 6c9d435 | 2015-10-17 14:39:27 +0200 | [diff] [blame] | 182 | /* Broadcom BCM2045 devices */ |
| 183 | { USB_DEVICE(0x0a5c, 0x2045), .driver_info = BTUSB_BCM2045 }, |
| 184 | |
Bala Shanmugam | be93112 | 2010-11-26 17:35:46 +0530 | [diff] [blame] | 185 | /* Atheros 3011 with sflash firmware */ |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 186 | { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE }, |
| 187 | { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE }, |
Alexander Ploumistos | 2eeff0b | 2015-02-13 21:05:11 +0200 | [diff] [blame] | 188 | { USB_DEVICE(0x04f2, 0xaff1), .driver_info = BTUSB_IGNORE }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 189 | { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE }, |
Bala Shanmugam | be93112 | 2010-11-26 17:35:46 +0530 | [diff] [blame] | 190 | { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE }, |
Marek Vasut | 6eda541 | 2012-06-08 14:32:50 +0200 | [diff] [blame] | 191 | { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE }, |
Andy Ross | 2a7bccc | 2011-05-09 16:11:16 -0700 | [diff] [blame] | 192 | { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE }, |
Bala Shanmugam | be93112 | 2010-11-26 17:35:46 +0530 | [diff] [blame] | 193 | |
Cho, Yu-Chen | 509e786 | 2011-01-26 17:10:59 +0800 | [diff] [blame] | 194 | /* Atheros AR9285 Malbec with sflash firmware */ |
| 195 | { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE }, |
| 196 | |
Bala Shanmugam | d9f51b5 | 2011-02-11 15:38:53 +0530 | [diff] [blame] | 197 | /* Atheros 3012 with sflash firmware */ |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 198 | { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 }, |
| 199 | { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 }, |
| 200 | { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 }, |
| 201 | { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 }, |
| 202 | { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 692c062 | 2015-06-06 20:25:40 +0300 | [diff] [blame] | 203 | { USB_DEVICE(0x0489, 0xe076), .driver_info = BTUSB_ATH3012 }, |
Anantha Krishnan | 4b552bc | 2014-10-06 16:31:49 +0530 | [diff] [blame] | 204 | { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 28c971d | 2016-02-10 00:49:11 +0300 | [diff] [blame] | 205 | { USB_DEVICE(0x0489, 0xe095), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 206 | { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 }, |
| 207 | { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 }, |
| 208 | { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 }, |
| 209 | { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 }, |
Mohammed Habibulla | 1fb4e09 | 2014-04-17 11:37:13 -0700 | [diff] [blame] | 210 | { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 211 | { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 }, |
| 212 | { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 7e730c7f | 2015-06-18 20:41:51 +0300 | [diff] [blame] | 213 | { USB_DEVICE(0x04ca, 0x300d), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | ec0810d | 2015-05-02 13:36:58 +0300 | [diff] [blame] | 214 | { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 }, |
Janne Heikkinen | 134d3b3 | 2014-12-09 07:44:51 +0200 | [diff] [blame] | 215 | { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 81d9044 | 2016-02-28 11:04:06 +0300 | [diff] [blame] | 216 | { USB_DEVICE(0x04ca, 0x3014), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 441ad62 | 2017-01-05 13:19:53 +0300 | [diff] [blame] | 217 | { USB_DEVICE(0x04ca, 0x3018), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 218 | { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | cd355ff | 2015-10-05 19:29:33 +0300 | [diff] [blame] | 219 | { USB_DEVICE(0x0930, 0x021c), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 220 | { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 }, |
Vincent Zwanenburg | 89d2975 | 2014-08-08 12:33:56 +0100 | [diff] [blame] | 221 | { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | a735f9e | 2014-02-18 18:26:20 +0200 | [diff] [blame] | 222 | { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 }, |
Ming Lei | d66629c | 2013-03-15 11:00:39 +0800 | [diff] [blame] | 223 | { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 }, |
Hans de Goede | 544a591 | 2018-04-26 14:18:19 +0200 | [diff] [blame] | 224 | { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, |
Sunguk Lee | 94a32d10 | 2013-03-12 04:41:58 +0900 | [diff] [blame] | 225 | { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 }, |
Cho, Yu-Chen | 07c0ea8 | 2012-03-14 22:01:21 +0200 | [diff] [blame] | 226 | { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 }, |
Oliver Neukum | b131237 | 2014-01-16 15:37:11 +0100 | [diff] [blame] | 227 | { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 }, |
Oliver Neukum | 1e56f1e | 2014-01-16 16:02:58 +0100 | [diff] [blame] | 228 | { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 229 | { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 }, |
Ming Lei | ebaf579 | 2013-03-18 23:45:11 +0800 | [diff] [blame] | 230 | { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 18e0afa | 2015-10-16 11:45:26 +0300 | [diff] [blame] | 231 | { USB_DEVICE(0x0cf3, 0x817b), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 232 | { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 }, |
AceLan Kao | ac71311 | 2012-04-19 14:53:45 +0800 | [diff] [blame] | 233 | { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 }, |
Peng Chen | 0a3658c | 2013-08-30 17:41:40 +0800 | [diff] [blame] | 234 | { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 }, |
Wen-chien Jesse Sung | ca79f23 | 2015-05-13 11:39:24 +0800 | [diff] [blame] | 235 | { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 236 | { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 }, |
| 237 | { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, |
AceLan Kao | eed307e | 2012-12-11 11:41:20 +0800 | [diff] [blame] | 238 | { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 609574e | 2016-02-10 15:33:17 +0300 | [diff] [blame] | 239 | { USB_DEVICE(0x13d3, 0x3395), .driver_info = BTUSB_ATH3012 }, |
Sujith Manoharan | 5b77a1f | 2013-07-15 09:29:03 +0530 | [diff] [blame] | 240 | { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 3bb30a7c | 2014-11-25 20:19:52 +0300 | [diff] [blame] | 241 | { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 033efa9 | 2015-01-18 00:16:51 +0300 | [diff] [blame] | 242 | { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 }, |
Anantha Krishnan | fa2f139 | 2014-07-08 19:25:08 +0530 | [diff] [blame] | 243 | { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 75c6aca | 2016-03-04 01:32:19 +0300 | [diff] [blame] | 244 | { USB_DEVICE(0x13d3, 0x3472), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 0d0cef6 | 2015-06-06 20:29:25 +0300 | [diff] [blame] | 245 | { USB_DEVICE(0x13d3, 0x3474), .driver_info = BTUSB_ATH3012 }, |
Lauro Costa | 72f9f8b | 2016-05-09 17:36:11 -0300 | [diff] [blame] | 246 | { USB_DEVICE(0x13d3, 0x3487), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 12d8689 | 2016-07-12 01:35:18 +0300 | [diff] [blame] | 247 | { USB_DEVICE(0x13d3, 0x3490), .driver_info = BTUSB_ATH3012 }, |
Bala Shanmugam | d9f51b5 | 2011-02-11 15:38:53 +0530 | [diff] [blame] | 248 | |
Cho, Yu-Chen | e9036e3 | 2011-02-15 10:20:07 +0800 | [diff] [blame] | 249 | /* Atheros AR5BBU12 with sflash firmware */ |
| 250 | { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE }, |
| 251 | |
Michael Gruetzner | 85d5972 | 2012-05-02 22:33:40 +0200 | [diff] [blame] | 252 | /* Atheros AR5BBU12 with sflash firmware */ |
Yevgeniy Melnichuk | bc21fde | 2012-08-07 19:48:10 +0530 | [diff] [blame] | 253 | { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 254 | { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, |
Michael Gruetzner | 85d5972 | 2012-05-02 22:33:40 +0200 | [diff] [blame] | 255 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 256 | /* QCA ROME chipset */ |
Owen Lin | 1411a26 | 2018-10-18 04:37:57 +0000 | [diff] [blame] | 257 | { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME }, |
Wen-chien Jesse Sung | 2054111 | 2015-05-13 11:39:25 +0800 | [diff] [blame] | 258 | { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME }, |
Kai-Heng Feng | 9351993 | 2016-08-16 12:50:06 +0800 | [diff] [blame] | 259 | { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME }, |
AceLan Kao | e5a49ee | 2018-01-02 10:41:11 +0800 | [diff] [blame] | 260 | { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME }, |
Marcel Holtmann | c9e4447 | 2015-03-16 23:56:04 -0700 | [diff] [blame] | 261 | { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME }, |
Gabriel | 1eef1c3 | 2017-02-20 12:32:22 -0500 | [diff] [blame] | 262 | { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME }, |
Marcel Holtmann | c9e4447 | 2015-03-16 23:56:04 -0700 | [diff] [blame] | 263 | { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME }, |
Yvain THONNART | 47ca589 | 2016-06-11 15:43:30 +0200 | [diff] [blame] | 264 | { USB_DEVICE(0x0489, 0xe092), .driver_info = BTUSB_QCA_ROME }, |
Bartosz Chronowski | 858ff38 | 2017-10-26 10:22:43 +0200 | [diff] [blame] | 265 | { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME }, |
Shih-Yuan Lee (FourDollars) | 06e41d8 | 2017-06-14 14:42:00 +0800 | [diff] [blame] | 266 | { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME }, |
Dmitry Tunin | 1144a4e | 2016-09-21 19:13:08 +0300 | [diff] [blame] | 267 | { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME }, |
Ioan Moldovan | 0a03f98 | 2017-08-28 18:09:39 +0300 | [diff] [blame] | 268 | { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME }, |
Brian Norris | d829b9e | 2017-07-31 17:59:39 -0700 | [diff] [blame] | 269 | { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME }, |
Vic Wei | d666fc5 | 2018-04-23 15:17:07 -0700 | [diff] [blame] | 270 | { USB_DEVICE(0x04ca, 0x301a), .driver_info = BTUSB_QCA_ROME }, |
Rocky Liao | 19220f3 | 2020-01-06 14:07:44 +0800 | [diff] [blame] | 271 | { USB_DEVICE(0x04ca, 0x3021), .driver_info = BTUSB_QCA_ROME }, |
João Paulo Rechi Vita | 44d34af | 2019-05-23 13:32:01 -0700 | [diff] [blame] | 272 | { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA_ROME }, |
João Paulo Rechi Vita | df2445b | 2018-04-27 10:09:58 -0700 | [diff] [blame] | 273 | { USB_DEVICE(0x13d3, 0x3496), .driver_info = BTUSB_QCA_ROME }, |
João Paulo Rechi Vita | 881cec4 | 2019-05-23 13:32:02 -0700 | [diff] [blame] | 274 | { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA_ROME }, |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 275 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 276 | /* Broadcom BCM2035 */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 277 | { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 278 | { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 279 | { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 280 | |
| 281 | /* Broadcom BCM2045 */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 282 | { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 283 | { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | bdbef3d | 2008-09-23 00:16:35 +0200 | [diff] [blame] | 284 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 285 | /* IBM/Lenovo ThinkPad with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 286 | { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 287 | { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 288 | |
| 289 | /* HP laptop with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 290 | { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 291 | |
| 292 | /* Dell laptop with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 293 | { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 294 | |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 295 | /* Dell Wireless 370 and 410 devices */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 296 | { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 297 | { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 298 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 299 | /* Belkin F8T012 and F8T013 devices */ |
| 300 | { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 301 | { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 302 | |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 303 | /* Asus WL-BTD202 device */ |
| 304 | { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 305 | |
| 306 | /* Kensington Bluetooth USB adapter */ |
| 307 | { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 308 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 309 | /* RTX Telecom based adapters with buggy SCO support */ |
| 310 | { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC }, |
| 311 | { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC }, |
| 312 | |
| 313 | /* CONWISE Technology based adapters with buggy SCO support */ |
Szymon Janc | 418678b | 2016-09-01 17:22:37 +0200 | [diff] [blame] | 314 | { USB_DEVICE(0x0e5e, 0x6622), |
| 315 | .driver_info = BTUSB_BROKEN_ISOC | BTUSB_CW6622}, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 316 | |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 317 | /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */ |
Aleksei Volkov | 2eeac87 | 2015-06-08 12:02:10 +0300 | [diff] [blame] | 318 | { USB_DEVICE(0x1310, 0x0001), .driver_info = BTUSB_SWAVE }, |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 319 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 320 | /* Digianswer devices */ |
| 321 | { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER }, |
| 322 | { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE }, |
| 323 | |
| 324 | /* CSR BlueCore Bluetooth Sniffer */ |
Marcel Holtmann | 4f64fa8 | 2014-07-07 00:12:04 +0200 | [diff] [blame] | 325 | { USB_DEVICE(0x0a12, 0x0002), |
| 326 | .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 327 | |
| 328 | /* Frontline ComProbe Bluetooth Sniffer */ |
Marcel Holtmann | 4f64fa8 | 2014-07-07 00:12:04 +0200 | [diff] [blame] | 329 | { USB_DEVICE(0x16d3, 0x0002), |
| 330 | .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 331 | |
Marcel Holtmann | cb1ee89 | 2015-01-28 19:41:42 -0800 | [diff] [blame] | 332 | /* Marvell Bluetooth devices */ |
| 333 | { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL }, |
| 334 | { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL }, |
Amitkumar Karwar | 1165df0 | 2016-09-28 16:18:35 +0530 | [diff] [blame] | 335 | { USB_DEVICE(0x1286, 0x204e), .driver_info = BTUSB_MARVELL }, |
Marcel Holtmann | cb1ee89 | 2015-01-28 19:41:42 -0800 | [diff] [blame] | 336 | |
Marcel Holtmann | d0ac9eb | 2015-01-28 19:41:43 -0800 | [diff] [blame] | 337 | /* Intel Bluetooth devices */ |
Alain Michaud | 3e4e3f7 | 2020-02-27 18:29:37 +0000 | [diff] [blame] | 338 | { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_NEW | |
Alain Michaud | aff8c48 | 2020-04-23 14:43:31 +0000 | [diff] [blame^] | 339 | BTUSB_WIDEBAND_SPEECH | |
| 340 | BTUSB_VALID_LE_STATES }, |
Alain Michaud | 3e4e3f7 | 2020-02-27 18:29:37 +0000 | [diff] [blame] | 341 | { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_NEW | |
| 342 | BTUSB_WIDEBAND_SPEECH }, |
| 343 | { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_NEW | |
| 344 | BTUSB_WIDEBAND_SPEECH }, |
Marcel Holtmann | 407550f | 2015-02-22 15:41:18 -0800 | [diff] [blame] | 345 | { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 346 | { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL }, |
Tedd Ho-Jeong An | ef4e5e4 | 2013-11-12 13:10:58 -0800 | [diff] [blame] | 347 | { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL }, |
Alain Michaud | 3e4e3f7 | 2020-02-27 18:29:37 +0000 | [diff] [blame] | 348 | { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW | |
| 349 | BTUSB_WIDEBAND_SPEECH }, |
| 350 | { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL | |
| 351 | BTUSB_WIDEBAND_SPEECH }, |
| 352 | { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_NEW | |
Alain Michaud | aff8c48 | 2020-04-23 14:43:31 +0000 | [diff] [blame^] | 353 | BTUSB_WIDEBAND_SPEECH | |
| 354 | BTUSB_VALID_LE_STATES }, |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 355 | |
Marcel Holtmann | d0ac9eb | 2015-01-28 19:41:43 -0800 | [diff] [blame] | 356 | /* Other Intel Bluetooth devices */ |
| 357 | { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01), |
| 358 | .driver_info = BTUSB_IGNORE }, |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 359 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 360 | /* Realtek Bluetooth devices */ |
| 361 | { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01), |
| 362 | .driver_info = BTUSB_REALTEK }, |
| 363 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 364 | /* MediaTek Bluetooth devices */ |
| 365 | { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01), |
| 366 | .driver_info = BTUSB_MEDIATEK }, |
| 367 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 368 | /* Additional Realtek 8723AE Bluetooth devices */ |
| 369 | { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK }, |
| 370 | { USB_DEVICE(0x13d3, 0x3394), .driver_info = BTUSB_REALTEK }, |
| 371 | |
| 372 | /* Additional Realtek 8723BE Bluetooth devices */ |
| 373 | { USB_DEVICE(0x0489, 0xe085), .driver_info = BTUSB_REALTEK }, |
| 374 | { USB_DEVICE(0x0489, 0xe08b), .driver_info = BTUSB_REALTEK }, |
| 375 | { USB_DEVICE(0x13d3, 0x3410), .driver_info = BTUSB_REALTEK }, |
| 376 | { USB_DEVICE(0x13d3, 0x3416), .driver_info = BTUSB_REALTEK }, |
| 377 | { USB_DEVICE(0x13d3, 0x3459), .driver_info = BTUSB_REALTEK }, |
Dmitry Tunin | a81d72d | 2017-08-08 14:09:02 +0300 | [diff] [blame] | 378 | { USB_DEVICE(0x13d3, 0x3494), .driver_info = BTUSB_REALTEK }, |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 379 | |
Vicente Bergas | a41e079 | 2018-03-20 19:41:10 +0100 | [diff] [blame] | 380 | /* Additional Realtek 8723BU Bluetooth devices */ |
| 381 | { USB_DEVICE(0x7392, 0xa611), .driver_info = BTUSB_REALTEK }, |
| 382 | |
Jian-Hong Pan | 66d9975 | 2018-05-21 18:09:20 +0800 | [diff] [blame] | 383 | /* Additional Realtek 8723DE Bluetooth devices */ |
Jian-Hong Pan | 45ae68b | 2018-05-25 17:54:52 +0800 | [diff] [blame] | 384 | { USB_DEVICE(0x0bda, 0xb009), .driver_info = BTUSB_REALTEK }, |
Jian-Hong Pan | 66d9975 | 2018-05-21 18:09:20 +0800 | [diff] [blame] | 385 | { USB_DEVICE(0x2ff8, 0xb011), .driver_info = BTUSB_REALTEK }, |
| 386 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 387 | /* Additional Realtek 8821AE Bluetooth devices */ |
| 388 | { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK }, |
| 389 | { USB_DEVICE(0x13d3, 0x3414), .driver_info = BTUSB_REALTEK }, |
| 390 | { USB_DEVICE(0x13d3, 0x3458), .driver_info = BTUSB_REALTEK }, |
| 391 | { USB_DEVICE(0x13d3, 0x3461), .driver_info = BTUSB_REALTEK }, |
| 392 | { USB_DEVICE(0x13d3, 0x3462), .driver_info = BTUSB_REALTEK }, |
| 393 | |
Larry Finger | fed03fe | 2018-02-11 12:24:32 -0600 | [diff] [blame] | 394 | /* Additional Realtek 8822BE Bluetooth devices */ |
Artiom Vaskov | 1cd2fab | 2018-05-30 11:23:00 +0300 | [diff] [blame] | 395 | { USB_DEVICE(0x13d3, 0x3526), .driver_info = BTUSB_REALTEK }, |
Larry Finger | fed03fe | 2018-02-11 12:24:32 -0600 | [diff] [blame] | 396 | { USB_DEVICE(0x0b05, 0x185c), .driver_info = BTUSB_REALTEK }, |
| 397 | |
Jian-Hong Pan | 6d0762b | 2019-09-03 17:10:42 +0800 | [diff] [blame] | 398 | /* Additional Realtek 8822CE Bluetooth devices */ |
| 399 | { USB_DEVICE(0x04ca, 0x4005), .driver_info = BTUSB_REALTEK }, |
Sergey Shatunov | eb3939e3 | 2020-02-08 23:53:15 +0800 | [diff] [blame] | 400 | { USB_DEVICE(0x13d3, 0x3548), .driver_info = BTUSB_REALTEK }, |
Jian-Hong Pan | 6d0762b | 2019-09-03 17:10:42 +0800 | [diff] [blame] | 401 | |
Peter Poklop | 4481c07 | 2015-08-15 20:47:09 +0200 | [diff] [blame] | 402 | /* Silicon Wave based devices */ |
| 403 | { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE }, |
| 404 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 405 | { } /* Terminating entry */ |
| 406 | }; |
| 407 | |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 408 | /* The Bluetooth USB module build into some devices needs to be reset on resume, |
| 409 | * this is a problem with the platform (likely shutting off all power) not with |
| 410 | * the module itself. So we use a DMI list to match known broken platforms. |
| 411 | */ |
| 412 | static const struct dmi_system_id btusb_needs_reset_resume_table[] = { |
| 413 | { |
Kai-Heng Feng | 0c6e526 | 2018-03-01 13:42:52 +0800 | [diff] [blame] | 414 | /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */ |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 415 | .matches = { |
Kai-Heng Feng | 0c6e526 | 2018-03-01 13:42:52 +0800 | [diff] [blame] | 416 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 417 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 3060"), |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 418 | }, |
| 419 | }, |
Hans de Goede | 596b07a | 2018-04-26 20:52:06 +0200 | [diff] [blame] | 420 | { |
| 421 | /* Dell XPS 9360 (QCA ROME device 0cf3:e300) */ |
| 422 | .matches = { |
| 423 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 424 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"), |
| 425 | }, |
| 426 | }, |
Hans de Goede | 939bc6c | 2018-05-22 09:34:10 +0200 | [diff] [blame] | 427 | { |
| 428 | /* Dell Inspiron 5565 (QCA ROME device 0cf3:e009) */ |
| 429 | .matches = { |
| 430 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 431 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5565"), |
| 432 | }, |
| 433 | }, |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 434 | {} |
| 435 | }; |
| 436 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 437 | #define BTUSB_MAX_ISOC_FRAMES 10 |
| 438 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 439 | #define BTUSB_INTR_RUNNING 0 |
| 440 | #define BTUSB_BULK_RUNNING 1 |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 441 | #define BTUSB_ISOC_RUNNING 2 |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 442 | #define BTUSB_SUSPENDING 3 |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 443 | #define BTUSB_DID_ISO_RESUME 4 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 444 | #define BTUSB_BOOTLOADER 5 |
| 445 | #define BTUSB_DOWNLOADING 6 |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 446 | #define BTUSB_FIRMWARE_LOADED 7 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 447 | #define BTUSB_FIRMWARE_FAILED 8 |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 448 | #define BTUSB_BOOTING 9 |
Hans de Goede | 61f5ace | 2018-01-08 10:44:16 +0100 | [diff] [blame] | 449 | #define BTUSB_DIAG_RUNNING 10 |
| 450 | #define BTUSB_OOB_WAKE_ENABLED 11 |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 451 | #define BTUSB_HW_RESET_ACTIVE 12 |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 452 | #define BTUSB_TX_WAIT_VND_EVT 13 |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 453 | #define BTUSB_WAKEUP_DISABLE 14 |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 454 | |
| 455 | struct btusb_data { |
| 456 | struct hci_dev *hdev; |
| 457 | struct usb_device *udev; |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 458 | struct usb_interface *intf; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 459 | struct usb_interface *isoc; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 460 | struct usb_interface *diag; |
Marcel Holtmann | 459232f | 2017-10-24 19:42:45 +0200 | [diff] [blame] | 461 | unsigned isoc_ifnum; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 462 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 463 | unsigned long flags; |
| 464 | |
| 465 | struct work_struct work; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 466 | struct work_struct waker; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 467 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 468 | struct usb_anchor deferred; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 469 | struct usb_anchor tx_anchor; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 470 | int tx_in_flight; |
| 471 | spinlock_t txlock; |
| 472 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 473 | struct usb_anchor intr_anchor; |
| 474 | struct usb_anchor bulk_anchor; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 475 | struct usb_anchor isoc_anchor; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 476 | struct usb_anchor diag_anchor; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 477 | struct usb_anchor ctrl_anchor; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 478 | spinlock_t rxlock; |
| 479 | |
| 480 | struct sk_buff *evt_skb; |
| 481 | struct sk_buff *acl_skb; |
| 482 | struct sk_buff *sco_skb; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 483 | |
| 484 | struct usb_endpoint_descriptor *intr_ep; |
| 485 | struct usb_endpoint_descriptor *bulk_tx_ep; |
| 486 | struct usb_endpoint_descriptor *bulk_rx_ep; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 487 | struct usb_endpoint_descriptor *isoc_tx_ep; |
| 488 | struct usb_endpoint_descriptor *isoc_rx_ep; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 489 | struct usb_endpoint_descriptor *diag_tx_ep; |
| 490 | struct usb_endpoint_descriptor *diag_rx_ep; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 491 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 492 | struct gpio_desc *reset_gpio; |
| 493 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 494 | __u8 cmdreq_type; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 495 | __u8 cmdreq; |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 496 | |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 497 | unsigned int sco_num; |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 498 | unsigned int air_mode; |
| 499 | bool usb_alt6_packet_flow; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 500 | int isoc_altsetting; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 501 | int suspend_count; |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 502 | |
Marcel Holtmann | 97307f5 | 2015-01-12 13:51:10 -0800 | [diff] [blame] | 503 | int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb); |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 504 | int (*recv_bulk)(struct btusb_data *data, void *buffer, int count); |
Kim, Ben Young Tae | ace3198 | 2015-02-15 23:06:14 +0000 | [diff] [blame] | 505 | |
| 506 | int (*setup_on_usb)(struct hci_dev *hdev); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 507 | |
| 508 | int oob_wake_irq; /* irq for out-of-band wake-on-bt */ |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 509 | unsigned cmd_timeout_cnt; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 510 | }; |
| 511 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 512 | |
| 513 | static void btusb_intel_cmd_timeout(struct hci_dev *hdev) |
| 514 | { |
| 515 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 516 | struct gpio_desc *reset_gpio = data->reset_gpio; |
| 517 | |
| 518 | if (++data->cmd_timeout_cnt < 5) |
| 519 | return; |
| 520 | |
| 521 | if (!reset_gpio) { |
| 522 | bt_dev_err(hdev, "No way to reset. Ignoring and continuing"); |
| 523 | return; |
| 524 | } |
| 525 | |
| 526 | /* |
| 527 | * Toggle the hard reset line if the platform provides one. The reset |
| 528 | * is going to yank the device off the USB and then replug. So doing |
| 529 | * once is enough. The cleanup is handled correctly on the way out |
| 530 | * (standard USB disconnect), and the new device is detected cleanly |
| 531 | * and bound to the driver again like it should be. |
| 532 | */ |
| 533 | if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
| 534 | bt_dev_err(hdev, "last reset failed? Not resetting again"); |
| 535 | return; |
| 536 | } |
| 537 | |
| 538 | bt_dev_err(hdev, "Initiating HW reset via gpio"); |
Rajat Jain | 2de66bb8 | 2019-01-28 15:08:09 -0800 | [diff] [blame] | 539 | gpiod_set_value_cansleep(reset_gpio, 1); |
| 540 | msleep(100); |
| 541 | gpiod_set_value_cansleep(reset_gpio, 0); |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 542 | } |
| 543 | |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 544 | static void btusb_rtl_cmd_timeout(struct hci_dev *hdev) |
| 545 | { |
| 546 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 547 | struct gpio_desc *reset_gpio = data->reset_gpio; |
| 548 | |
| 549 | if (++data->cmd_timeout_cnt < 5) |
| 550 | return; |
| 551 | |
| 552 | if (!reset_gpio) { |
| 553 | bt_dev_err(hdev, "No gpio to reset Realtek device, ignoring"); |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | /* Toggle the hard reset line. The Realtek device is going to |
| 558 | * yank itself off the USB and then replug. The cleanup is handled |
| 559 | * correctly on the way out (standard USB disconnect), and the new |
| 560 | * device is detected cleanly and bound to the driver again like |
| 561 | * it should be. |
| 562 | */ |
| 563 | if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
| 564 | bt_dev_err(hdev, "last reset failed? Not resetting again"); |
| 565 | return; |
| 566 | } |
| 567 | |
| 568 | bt_dev_err(hdev, "Reset Realtek device via gpio"); |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 569 | gpiod_set_value_cansleep(reset_gpio, 1); |
Max Chou | 3468211 | 2019-11-27 11:01:07 +0800 | [diff] [blame] | 570 | msleep(200); |
| 571 | gpiod_set_value_cansleep(reset_gpio, 0); |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 572 | } |
| 573 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 574 | static inline void btusb_free_frags(struct btusb_data *data) |
| 575 | { |
| 576 | unsigned long flags; |
| 577 | |
| 578 | spin_lock_irqsave(&data->rxlock, flags); |
| 579 | |
| 580 | kfree_skb(data->evt_skb); |
| 581 | data->evt_skb = NULL; |
| 582 | |
| 583 | kfree_skb(data->acl_skb); |
| 584 | data->acl_skb = NULL; |
| 585 | |
| 586 | kfree_skb(data->sco_skb); |
| 587 | data->sco_skb = NULL; |
| 588 | |
| 589 | spin_unlock_irqrestore(&data->rxlock, flags); |
| 590 | } |
| 591 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 592 | static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count) |
| 593 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 594 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 595 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 596 | int err = 0; |
| 597 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 598 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 599 | skb = data->evt_skb; |
| 600 | |
| 601 | while (count) { |
| 602 | int len; |
| 603 | |
| 604 | if (!skb) { |
| 605 | skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC); |
| 606 | if (!skb) { |
| 607 | err = -ENOMEM; |
| 608 | break; |
| 609 | } |
| 610 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 611 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
| 612 | hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 613 | } |
| 614 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 615 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 616 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 617 | |
| 618 | count -= len; |
| 619 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 620 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 621 | |
| 622 | if (skb->len == HCI_EVENT_HDR_SIZE) { |
| 623 | /* Complete event header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 624 | hci_skb_expect(skb) = hci_event_hdr(skb)->plen; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 625 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 626 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 627 | kfree_skb(skb); |
| 628 | skb = NULL; |
| 629 | |
| 630 | err = -EILSEQ; |
| 631 | break; |
| 632 | } |
| 633 | } |
| 634 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 635 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 636 | /* Complete frame */ |
Marcel Holtmann | 97307f5 | 2015-01-12 13:51:10 -0800 | [diff] [blame] | 637 | data->recv_event(data->hdev, skb); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 638 | skb = NULL; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | data->evt_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 643 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 644 | |
| 645 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count) |
| 649 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 650 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 651 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 652 | int err = 0; |
| 653 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 654 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 655 | skb = data->acl_skb; |
| 656 | |
| 657 | while (count) { |
| 658 | int len; |
| 659 | |
| 660 | if (!skb) { |
| 661 | skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); |
| 662 | if (!skb) { |
| 663 | err = -ENOMEM; |
| 664 | break; |
| 665 | } |
| 666 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 667 | hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT; |
| 668 | hci_skb_expect(skb) = HCI_ACL_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 669 | } |
| 670 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 671 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 672 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 673 | |
| 674 | count -= len; |
| 675 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 676 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 677 | |
| 678 | if (skb->len == HCI_ACL_HDR_SIZE) { |
| 679 | __le16 dlen = hci_acl_hdr(skb)->dlen; |
| 680 | |
| 681 | /* Complete ACL header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 682 | hci_skb_expect(skb) = __le16_to_cpu(dlen); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 683 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 684 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 685 | kfree_skb(skb); |
| 686 | skb = NULL; |
| 687 | |
| 688 | err = -EILSEQ; |
| 689 | break; |
| 690 | } |
| 691 | } |
| 692 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 693 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 694 | /* Complete frame */ |
| 695 | hci_recv_frame(data->hdev, skb); |
| 696 | skb = NULL; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | data->acl_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 701 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 702 | |
| 703 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count) |
| 707 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 708 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 709 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 710 | int err = 0; |
| 711 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 712 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 713 | skb = data->sco_skb; |
| 714 | |
| 715 | while (count) { |
| 716 | int len; |
| 717 | |
| 718 | if (!skb) { |
| 719 | skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC); |
| 720 | if (!skb) { |
| 721 | err = -ENOMEM; |
| 722 | break; |
| 723 | } |
| 724 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 725 | hci_skb_pkt_type(skb) = HCI_SCODATA_PKT; |
| 726 | hci_skb_expect(skb) = HCI_SCO_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 727 | } |
| 728 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 729 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 730 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 731 | |
| 732 | count -= len; |
| 733 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 734 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 735 | |
| 736 | if (skb->len == HCI_SCO_HDR_SIZE) { |
| 737 | /* Complete SCO header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 738 | hci_skb_expect(skb) = hci_sco_hdr(skb)->dlen; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 739 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 740 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 741 | kfree_skb(skb); |
| 742 | skb = NULL; |
| 743 | |
| 744 | err = -EILSEQ; |
| 745 | break; |
| 746 | } |
| 747 | } |
| 748 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 749 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 750 | /* Complete frame */ |
| 751 | hci_recv_frame(data->hdev, skb); |
| 752 | skb = NULL; |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | data->sco_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 757 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 758 | |
| 759 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 760 | } |
| 761 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 762 | static void btusb_intr_complete(struct urb *urb) |
| 763 | { |
| 764 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 765 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 766 | int err; |
| 767 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 768 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 769 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 770 | |
| 771 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 772 | return; |
| 773 | |
| 774 | if (urb->status == 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 775 | hdev->stat.byte_rx += urb->actual_length; |
| 776 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 777 | if (btusb_recv_intr(data, urb->transfer_buffer, |
| 778 | urb->actual_length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 779 | bt_dev_err(hdev, "corrupted event packet"); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 780 | hdev->stat.err_rx++; |
| 781 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 782 | } else if (urb->status == -ENOENT) { |
| 783 | /* Avoid suspend failed when usb_kill_urb */ |
| 784 | return; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | if (!test_bit(BTUSB_INTR_RUNNING, &data->flags)) |
| 788 | return; |
| 789 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 790 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 791 | usb_anchor_urb(urb, &data->intr_anchor); |
| 792 | |
| 793 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 794 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 795 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 796 | * -ENODEV: device got disconnected |
| 797 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 798 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 799 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 800 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 801 | usb_unanchor_urb(urb); |
| 802 | } |
| 803 | } |
| 804 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 805 | static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 806 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 807 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 808 | struct urb *urb; |
| 809 | unsigned char *buf; |
| 810 | unsigned int pipe; |
| 811 | int err, size; |
| 812 | |
| 813 | BT_DBG("%s", hdev->name); |
| 814 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 815 | if (!data->intr_ep) |
| 816 | return -ENODEV; |
| 817 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 818 | urb = usb_alloc_urb(0, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 819 | if (!urb) |
| 820 | return -ENOMEM; |
| 821 | |
| 822 | size = le16_to_cpu(data->intr_ep->wMaxPacketSize); |
| 823 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 824 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 825 | if (!buf) { |
| 826 | usb_free_urb(urb); |
| 827 | return -ENOMEM; |
| 828 | } |
| 829 | |
| 830 | pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress); |
| 831 | |
| 832 | usb_fill_int_urb(urb, data->udev, pipe, buf, size, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 833 | btusb_intr_complete, hdev, data->intr_ep->bInterval); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 834 | |
| 835 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 836 | |
| 837 | usb_anchor_urb(urb, &data->intr_anchor); |
| 838 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 839 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 840 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 841 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 842 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 843 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 844 | usb_unanchor_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | usb_free_urb(urb); |
| 848 | |
| 849 | return err; |
| 850 | } |
| 851 | |
| 852 | static void btusb_bulk_complete(struct urb *urb) |
| 853 | { |
| 854 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 855 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 856 | int err; |
| 857 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 858 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 859 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 860 | |
| 861 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 862 | return; |
| 863 | |
| 864 | if (urb->status == 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 865 | hdev->stat.byte_rx += urb->actual_length; |
| 866 | |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 867 | if (data->recv_bulk(data, urb->transfer_buffer, |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 868 | urb->actual_length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 869 | bt_dev_err(hdev, "corrupted ACL packet"); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 870 | hdev->stat.err_rx++; |
| 871 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 872 | } else if (urb->status == -ENOENT) { |
| 873 | /* Avoid suspend failed when usb_kill_urb */ |
| 874 | return; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | if (!test_bit(BTUSB_BULK_RUNNING, &data->flags)) |
| 878 | return; |
| 879 | |
| 880 | usb_anchor_urb(urb, &data->bulk_anchor); |
Oliver Neukum | 652fd78 | 2009-12-16 19:23:43 +0100 | [diff] [blame] | 881 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 882 | |
| 883 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 884 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 885 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 886 | * -ENODEV: device got disconnected |
| 887 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 888 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 889 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 890 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 891 | usb_unanchor_urb(urb); |
| 892 | } |
| 893 | } |
| 894 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 895 | static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 896 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 897 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 898 | struct urb *urb; |
| 899 | unsigned char *buf; |
| 900 | unsigned int pipe; |
Vikram Kandukuri | 290ba20 | 2009-07-02 14:31:59 +0530 | [diff] [blame] | 901 | int err, size = HCI_MAX_FRAME_SIZE; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 902 | |
| 903 | BT_DBG("%s", hdev->name); |
| 904 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 905 | if (!data->bulk_rx_ep) |
| 906 | return -ENODEV; |
| 907 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 908 | urb = usb_alloc_urb(0, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 909 | if (!urb) |
| 910 | return -ENOMEM; |
| 911 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 912 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 913 | if (!buf) { |
| 914 | usb_free_urb(urb); |
| 915 | return -ENOMEM; |
| 916 | } |
| 917 | |
| 918 | pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress); |
| 919 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 920 | usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, |
| 921 | btusb_bulk_complete, hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 922 | |
| 923 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 924 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 925 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 926 | usb_anchor_urb(urb, &data->bulk_anchor); |
| 927 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 928 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 929 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 930 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 931 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 932 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 933 | usb_unanchor_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | usb_free_urb(urb); |
| 937 | |
| 938 | return err; |
| 939 | } |
| 940 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 941 | static void btusb_isoc_complete(struct urb *urb) |
| 942 | { |
| 943 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 944 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 945 | int i, err; |
| 946 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 947 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 948 | urb->actual_length); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 949 | |
| 950 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 951 | return; |
| 952 | |
| 953 | if (urb->status == 0) { |
| 954 | for (i = 0; i < urb->number_of_packets; i++) { |
| 955 | unsigned int offset = urb->iso_frame_desc[i].offset; |
| 956 | unsigned int length = urb->iso_frame_desc[i].actual_length; |
| 957 | |
| 958 | if (urb->iso_frame_desc[i].status) |
| 959 | continue; |
| 960 | |
| 961 | hdev->stat.byte_rx += length; |
| 962 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 963 | if (btusb_recv_isoc(data, urb->transfer_buffer + offset, |
| 964 | length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 965 | bt_dev_err(hdev, "corrupted SCO packet"); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 966 | hdev->stat.err_rx++; |
| 967 | } |
| 968 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 969 | } else if (urb->status == -ENOENT) { |
| 970 | /* Avoid suspend failed when usb_kill_urb */ |
| 971 | return; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags)) |
| 975 | return; |
| 976 | |
| 977 | usb_anchor_urb(urb, &data->isoc_anchor); |
| 978 | |
| 979 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 980 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 981 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 982 | * -ENODEV: device got disconnected |
| 983 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 984 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 985 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 986 | urb, -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 987 | usb_unanchor_urb(urb); |
| 988 | } |
| 989 | } |
| 990 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 991 | static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len, |
| 992 | int mtu, struct btusb_data *data) |
| 993 | { |
| 994 | int i, offset = 0; |
| 995 | unsigned int interval; |
| 996 | |
| 997 | BT_DBG("len %d mtu %d", len, mtu); |
| 998 | |
| 999 | /* For mSBC ALT 6 setting the host will send the packet at continuous |
| 1000 | * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting |
| 1001 | * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets. |
| 1002 | * To maintain the rate we send 63bytes of usb packets alternatively for |
| 1003 | * 7ms and 8ms to maintain the rate as 7.5ms. |
| 1004 | */ |
| 1005 | if (data->usb_alt6_packet_flow) { |
| 1006 | interval = 7; |
| 1007 | data->usb_alt6_packet_flow = false; |
| 1008 | } else { |
| 1009 | interval = 6; |
| 1010 | data->usb_alt6_packet_flow = true; |
| 1011 | } |
| 1012 | |
| 1013 | for (i = 0; i < interval; i++) { |
| 1014 | urb->iso_frame_desc[i].offset = offset; |
| 1015 | urb->iso_frame_desc[i].length = offset; |
| 1016 | } |
| 1017 | |
| 1018 | if (len && i < BTUSB_MAX_ISOC_FRAMES) { |
| 1019 | urb->iso_frame_desc[i].offset = offset; |
| 1020 | urb->iso_frame_desc[i].length = len; |
| 1021 | i++; |
| 1022 | } |
| 1023 | |
| 1024 | urb->number_of_packets = i; |
| 1025 | } |
| 1026 | |
Jesper Juhl | 42b16b3 | 2011-01-17 00:09:38 +0100 | [diff] [blame] | 1027 | static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu) |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1028 | { |
| 1029 | int i, offset = 0; |
| 1030 | |
| 1031 | BT_DBG("len %d mtu %d", len, mtu); |
| 1032 | |
| 1033 | for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu; |
| 1034 | i++, offset += mtu, len -= mtu) { |
| 1035 | urb->iso_frame_desc[i].offset = offset; |
| 1036 | urb->iso_frame_desc[i].length = mtu; |
| 1037 | } |
| 1038 | |
| 1039 | if (len && i < BTUSB_MAX_ISOC_FRAMES) { |
| 1040 | urb->iso_frame_desc[i].offset = offset; |
| 1041 | urb->iso_frame_desc[i].length = len; |
| 1042 | i++; |
| 1043 | } |
| 1044 | |
| 1045 | urb->number_of_packets = i; |
| 1046 | } |
| 1047 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1048 | static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags) |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1049 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1050 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1051 | struct urb *urb; |
| 1052 | unsigned char *buf; |
| 1053 | unsigned int pipe; |
| 1054 | int err, size; |
| 1055 | |
| 1056 | BT_DBG("%s", hdev->name); |
| 1057 | |
| 1058 | if (!data->isoc_rx_ep) |
| 1059 | return -ENODEV; |
| 1060 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1061 | urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1062 | if (!urb) |
| 1063 | return -ENOMEM; |
| 1064 | |
| 1065 | size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) * |
| 1066 | BTUSB_MAX_ISOC_FRAMES; |
| 1067 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1068 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1069 | if (!buf) { |
| 1070 | usb_free_urb(urb); |
| 1071 | return -ENOMEM; |
| 1072 | } |
| 1073 | |
| 1074 | pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress); |
| 1075 | |
Bing Zhao | fa0fb93 | 2011-12-20 18:19:00 -0800 | [diff] [blame] | 1076 | usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1077 | hdev, data->isoc_rx_ep->bInterval); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1078 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1079 | urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1080 | |
| 1081 | __fill_isoc_descriptor(urb, size, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1082 | le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize)); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1083 | |
| 1084 | usb_anchor_urb(urb, &data->isoc_anchor); |
| 1085 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1086 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1087 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 1088 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1089 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1090 | urb, -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1091 | usb_unanchor_urb(urb); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | usb_free_urb(urb); |
| 1095 | |
| 1096 | return err; |
| 1097 | } |
| 1098 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1099 | static void btusb_diag_complete(struct urb *urb) |
| 1100 | { |
| 1101 | struct hci_dev *hdev = urb->context; |
| 1102 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1103 | int err; |
| 1104 | |
| 1105 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1106 | urb->actual_length); |
| 1107 | |
| 1108 | if (urb->status == 0) { |
| 1109 | struct sk_buff *skb; |
| 1110 | |
| 1111 | skb = bt_skb_alloc(urb->actual_length, GFP_ATOMIC); |
| 1112 | if (skb) { |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 1113 | skb_put_data(skb, urb->transfer_buffer, |
| 1114 | urb->actual_length); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1115 | hci_recv_diag(hdev, skb); |
| 1116 | } |
| 1117 | } else if (urb->status == -ENOENT) { |
| 1118 | /* Avoid suspend failed when usb_kill_urb */ |
| 1119 | return; |
| 1120 | } |
| 1121 | |
| 1122 | if (!test_bit(BTUSB_DIAG_RUNNING, &data->flags)) |
| 1123 | return; |
| 1124 | |
| 1125 | usb_anchor_urb(urb, &data->diag_anchor); |
| 1126 | usb_mark_last_busy(data->udev); |
| 1127 | |
| 1128 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 1129 | if (err < 0) { |
| 1130 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 1131 | * -ENODEV: device got disconnected |
| 1132 | */ |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1133 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1134 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 1135 | urb, -err); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1136 | usb_unanchor_urb(urb); |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | static int btusb_submit_diag_urb(struct hci_dev *hdev, gfp_t mem_flags) |
| 1141 | { |
| 1142 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1143 | struct urb *urb; |
| 1144 | unsigned char *buf; |
| 1145 | unsigned int pipe; |
| 1146 | int err, size = HCI_MAX_FRAME_SIZE; |
| 1147 | |
| 1148 | BT_DBG("%s", hdev->name); |
| 1149 | |
| 1150 | if (!data->diag_rx_ep) |
| 1151 | return -ENODEV; |
| 1152 | |
| 1153 | urb = usb_alloc_urb(0, mem_flags); |
| 1154 | if (!urb) |
| 1155 | return -ENOMEM; |
| 1156 | |
| 1157 | buf = kmalloc(size, mem_flags); |
| 1158 | if (!buf) { |
| 1159 | usb_free_urb(urb); |
| 1160 | return -ENOMEM; |
| 1161 | } |
| 1162 | |
| 1163 | pipe = usb_rcvbulkpipe(data->udev, data->diag_rx_ep->bEndpointAddress); |
| 1164 | |
| 1165 | usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, |
| 1166 | btusb_diag_complete, hdev); |
| 1167 | |
| 1168 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 1169 | |
| 1170 | usb_mark_last_busy(data->udev); |
| 1171 | usb_anchor_urb(urb, &data->diag_anchor); |
| 1172 | |
| 1173 | err = usb_submit_urb(urb, mem_flags); |
| 1174 | if (err < 0) { |
| 1175 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1176 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1177 | urb, -err); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1178 | usb_unanchor_urb(urb); |
| 1179 | } |
| 1180 | |
| 1181 | usb_free_urb(urb); |
| 1182 | |
| 1183 | return err; |
| 1184 | } |
| 1185 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1186 | static void btusb_tx_complete(struct urb *urb) |
| 1187 | { |
| 1188 | struct sk_buff *skb = urb->context; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1189 | struct hci_dev *hdev = (struct hci_dev *)skb->dev; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1190 | struct btusb_data *data = hci_get_drvdata(hdev); |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1191 | unsigned long flags; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1192 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1193 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1194 | urb->actual_length); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1195 | |
| 1196 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1197 | goto done; |
| 1198 | |
| 1199 | if (!urb->status) |
| 1200 | hdev->stat.byte_tx += urb->transfer_buffer_length; |
| 1201 | else |
| 1202 | hdev->stat.err_tx++; |
| 1203 | |
| 1204 | done: |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1205 | spin_lock_irqsave(&data->txlock, flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1206 | data->tx_in_flight--; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1207 | spin_unlock_irqrestore(&data->txlock, flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1208 | |
| 1209 | kfree(urb->setup_packet); |
| 1210 | |
| 1211 | kfree_skb(skb); |
| 1212 | } |
| 1213 | |
| 1214 | static void btusb_isoc_tx_complete(struct urb *urb) |
| 1215 | { |
| 1216 | struct sk_buff *skb = urb->context; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1217 | struct hci_dev *hdev = (struct hci_dev *)skb->dev; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1218 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1219 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1220 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1221 | |
| 1222 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1223 | goto done; |
| 1224 | |
| 1225 | if (!urb->status) |
| 1226 | hdev->stat.byte_tx += urb->transfer_buffer_length; |
| 1227 | else |
| 1228 | hdev->stat.err_tx++; |
| 1229 | |
| 1230 | done: |
| 1231 | kfree(urb->setup_packet); |
| 1232 | |
| 1233 | kfree_skb(skb); |
| 1234 | } |
| 1235 | |
| 1236 | static int btusb_open(struct hci_dev *hdev) |
| 1237 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1238 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1239 | int err; |
| 1240 | |
| 1241 | BT_DBG("%s", hdev->name); |
| 1242 | |
Ethan Hsieh | c7e163f | 2016-10-07 12:06:42 +0800 | [diff] [blame] | 1243 | err = usb_autopm_get_interface(data->intf); |
| 1244 | if (err < 0) |
| 1245 | return err; |
| 1246 | |
Kim, Ben Young Tae | ace3198 | 2015-02-15 23:06:14 +0000 | [diff] [blame] | 1247 | /* Patching USB firmware files prior to starting any URBs of HCI path |
| 1248 | * It is more safe to use USB bulk channel for downloading USB patch |
| 1249 | */ |
| 1250 | if (data->setup_on_usb) { |
| 1251 | err = data->setup_on_usb(hdev); |
Marcel Holtmann | eb50042 | 2015-04-16 23:15:50 +0200 | [diff] [blame] | 1252 | if (err < 0) |
Oliver Neukum | 3d44a6f | 2019-11-14 16:01:18 +0100 | [diff] [blame] | 1253 | goto setup_fail; |
Kim, Ben Young Tae | ace3198 | 2015-02-15 23:06:14 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1256 | data->intf->needs_remote_wakeup = 1; |
| 1257 | |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 1258 | /* Disable device remote wakeup when host is suspended |
| 1259 | * For Realtek chips, global suspend without |
| 1260 | * SET_FEATURE (DEVICE_REMOTE_WAKEUP) can save more power in device. |
| 1261 | */ |
| 1262 | if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) |
| 1263 | device_wakeup_disable(&data->udev->dev); |
| 1264 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1265 | if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1266 | goto done; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1267 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1268 | err = btusb_submit_intr_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1269 | if (err < 0) |
| 1270 | goto failed; |
| 1271 | |
| 1272 | err = btusb_submit_bulk_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1273 | if (err < 0) { |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1274 | usb_kill_anchored_urbs(&data->intr_anchor); |
| 1275 | goto failed; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1276 | } |
| 1277 | |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1278 | set_bit(BTUSB_BULK_RUNNING, &data->flags); |
| 1279 | btusb_submit_bulk_urb(hdev, GFP_KERNEL); |
| 1280 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1281 | if (data->diag) { |
| 1282 | if (!btusb_submit_diag_urb(hdev, GFP_KERNEL)) |
| 1283 | set_bit(BTUSB_DIAG_RUNNING, &data->flags); |
| 1284 | } |
| 1285 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1286 | done: |
| 1287 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1288 | return 0; |
| 1289 | |
| 1290 | failed: |
| 1291 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Oliver Neukum | 3d44a6f | 2019-11-14 16:01:18 +0100 | [diff] [blame] | 1292 | setup_fail: |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1293 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1294 | return err; |
| 1295 | } |
| 1296 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1297 | static void btusb_stop_traffic(struct btusb_data *data) |
| 1298 | { |
| 1299 | usb_kill_anchored_urbs(&data->intr_anchor); |
| 1300 | usb_kill_anchored_urbs(&data->bulk_anchor); |
| 1301 | usb_kill_anchored_urbs(&data->isoc_anchor); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1302 | usb_kill_anchored_urbs(&data->diag_anchor); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 1303 | usb_kill_anchored_urbs(&data->ctrl_anchor); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1304 | } |
| 1305 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1306 | static int btusb_close(struct hci_dev *hdev) |
| 1307 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1308 | struct btusb_data *data = hci_get_drvdata(hdev); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1309 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1310 | |
| 1311 | BT_DBG("%s", hdev->name); |
| 1312 | |
Marcel Holtmann | e8c3c3d | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 1313 | cancel_work_sync(&data->work); |
Linus Torvalds | 404291a | 2009-11-11 13:32:29 -0800 | [diff] [blame] | 1314 | cancel_work_sync(&data->waker); |
Marcel Holtmann | e8c3c3d | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 1315 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1316 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1317 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1318 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1319 | clear_bit(BTUSB_DIAG_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1320 | |
| 1321 | btusb_stop_traffic(data); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 1322 | btusb_free_frags(data); |
| 1323 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1324 | err = usb_autopm_get_interface(data->intf); |
| 1325 | if (err < 0) |
Oliver Neukum | 7b8e2c1 | 2009-11-13 14:26:23 +0100 | [diff] [blame] | 1326 | goto failed; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1327 | |
| 1328 | data->intf->needs_remote_wakeup = 0; |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 1329 | |
| 1330 | /* Enable remote wake up for auto-suspend */ |
| 1331 | if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) |
| 1332 | data->intf->needs_remote_wakeup = 1; |
| 1333 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1334 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1335 | |
Oliver Neukum | 7b8e2c1 | 2009-11-13 14:26:23 +0100 | [diff] [blame] | 1336 | failed: |
| 1337 | usb_scuttle_anchored_urbs(&data->deferred); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1338 | return 0; |
| 1339 | } |
| 1340 | |
| 1341 | static int btusb_flush(struct hci_dev *hdev) |
| 1342 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1343 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1344 | |
| 1345 | BT_DBG("%s", hdev->name); |
| 1346 | |
| 1347 | usb_kill_anchored_urbs(&data->tx_anchor); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 1348 | btusb_free_frags(data); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1349 | |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1353 | static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1354 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1355 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1356 | struct usb_ctrlrequest *dr; |
| 1357 | struct urb *urb; |
| 1358 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1359 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1360 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1361 | if (!urb) |
| 1362 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1363 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1364 | dr = kmalloc(sizeof(*dr), GFP_KERNEL); |
| 1365 | if (!dr) { |
| 1366 | usb_free_urb(urb); |
| 1367 | return ERR_PTR(-ENOMEM); |
| 1368 | } |
| 1369 | |
| 1370 | dr->bRequestType = data->cmdreq_type; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 1371 | dr->bRequest = data->cmdreq; |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1372 | dr->wIndex = 0; |
| 1373 | dr->wValue = 0; |
| 1374 | dr->wLength = __cpu_to_le16(skb->len); |
| 1375 | |
| 1376 | pipe = usb_sndctrlpipe(data->udev, 0x00); |
| 1377 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1378 | usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1379 | skb->data, skb->len, btusb_tx_complete, skb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1380 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1381 | skb->dev = (void *)hdev; |
Marcel Holtmann | 7bd8f09 | 2013-10-11 06:19:18 -0700 | [diff] [blame] | 1382 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1383 | return urb; |
| 1384 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1385 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1386 | static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb) |
| 1387 | { |
| 1388 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1389 | struct urb *urb; |
| 1390 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1391 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1392 | if (!data->bulk_tx_ep) |
| 1393 | return ERR_PTR(-ENODEV); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1394 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1395 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1396 | if (!urb) |
| 1397 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1398 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1399 | pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1400 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1401 | usb_fill_bulk_urb(urb, data->udev, pipe, |
| 1402 | skb->data, skb->len, btusb_tx_complete, skb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1403 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1404 | skb->dev = (void *)hdev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1405 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1406 | return urb; |
| 1407 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1408 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1409 | static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb) |
| 1410 | { |
| 1411 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1412 | struct urb *urb; |
| 1413 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1414 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1415 | if (!data->isoc_tx_ep) |
| 1416 | return ERR_PTR(-ENODEV); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1417 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1418 | urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL); |
| 1419 | if (!urb) |
| 1420 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1421 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1422 | pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1423 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1424 | usb_fill_int_urb(urb, data->udev, pipe, |
| 1425 | skb->data, skb->len, btusb_isoc_tx_complete, |
| 1426 | skb, data->isoc_tx_ep->bInterval); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1427 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1428 | urb->transfer_flags = URB_ISO_ASAP; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1429 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1430 | if (data->isoc_altsetting == 6) |
| 1431 | __fill_isoc_descriptor_msbc(urb, skb->len, |
| 1432 | le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize), |
| 1433 | data); |
| 1434 | else |
| 1435 | __fill_isoc_descriptor(urb, skb->len, |
| 1436 | le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1437 | skb->dev = (void *)hdev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1438 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1439 | return urb; |
| 1440 | } |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1441 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1442 | static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb) |
| 1443 | { |
| 1444 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1445 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1446 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1447 | usb_anchor_urb(urb, &data->tx_anchor); |
| 1448 | |
Johan Hedberg | e9753ef | 2014-09-14 08:49:34 +0300 | [diff] [blame] | 1449 | err = usb_submit_urb(urb, GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1450 | if (err < 0) { |
Paul Bolle | 5a9b80e | 2011-10-09 12:12:16 +0200 | [diff] [blame] | 1451 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1452 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1453 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1454 | kfree(urb->setup_packet); |
| 1455 | usb_unanchor_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1456 | } else { |
| 1457 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1458 | } |
| 1459 | |
Cong Wang | 54a8a79 | 2011-11-22 09:32:57 +0800 | [diff] [blame] | 1460 | usb_free_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1461 | return err; |
| 1462 | } |
| 1463 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1464 | static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb) |
| 1465 | { |
| 1466 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1467 | unsigned long flags; |
| 1468 | bool suspending; |
| 1469 | |
| 1470 | spin_lock_irqsave(&data->txlock, flags); |
| 1471 | suspending = test_bit(BTUSB_SUSPENDING, &data->flags); |
| 1472 | if (!suspending) |
| 1473 | data->tx_in_flight++; |
| 1474 | spin_unlock_irqrestore(&data->txlock, flags); |
| 1475 | |
| 1476 | if (!suspending) |
| 1477 | return submit_tx_urb(hdev, urb); |
| 1478 | |
| 1479 | usb_anchor_urb(urb, &data->deferred); |
| 1480 | schedule_work(&data->waker); |
| 1481 | |
| 1482 | usb_free_urb(urb); |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
| 1486 | static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb) |
| 1487 | { |
| 1488 | struct urb *urb; |
| 1489 | |
| 1490 | BT_DBG("%s", hdev->name); |
| 1491 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 1492 | switch (hci_skb_pkt_type(skb)) { |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1493 | case HCI_COMMAND_PKT: |
| 1494 | urb = alloc_ctrl_urb(hdev, skb); |
| 1495 | if (IS_ERR(urb)) |
| 1496 | return PTR_ERR(urb); |
| 1497 | |
| 1498 | hdev->stat.cmd_tx++; |
| 1499 | return submit_or_queue_tx_urb(hdev, urb); |
| 1500 | |
| 1501 | case HCI_ACLDATA_PKT: |
| 1502 | urb = alloc_bulk_urb(hdev, skb); |
| 1503 | if (IS_ERR(urb)) |
| 1504 | return PTR_ERR(urb); |
| 1505 | |
| 1506 | hdev->stat.acl_tx++; |
| 1507 | return submit_or_queue_tx_urb(hdev, urb); |
| 1508 | |
| 1509 | case HCI_SCODATA_PKT: |
| 1510 | if (hci_conn_num(hdev, SCO_LINK) < 1) |
| 1511 | return -ENODEV; |
| 1512 | |
| 1513 | urb = alloc_isoc_urb(hdev, skb); |
| 1514 | if (IS_ERR(urb)) |
| 1515 | return PTR_ERR(urb); |
| 1516 | |
| 1517 | hdev->stat.sco_tx++; |
| 1518 | return submit_tx_urb(hdev, urb); |
| 1519 | } |
| 1520 | |
| 1521 | return -EILSEQ; |
| 1522 | } |
| 1523 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1524 | static void btusb_notify(struct hci_dev *hdev, unsigned int evt) |
| 1525 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1526 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1527 | |
| 1528 | BT_DBG("%s evt %d", hdev->name, evt); |
| 1529 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1530 | if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) { |
| 1531 | data->sco_num = hci_conn_num(hdev, SCO_LINK); |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1532 | data->air_mode = evt; |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1533 | schedule_work(&data->work); |
Marcel Holtmann | a780efa | 2008-11-30 12:17:12 +0100 | [diff] [blame] | 1534 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1535 | } |
| 1536 | |
Jesper Juhl | 42b16b3 | 2011-01-17 00:09:38 +0100 | [diff] [blame] | 1537 | static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting) |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1538 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1539 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1540 | struct usb_interface *intf = data->isoc; |
| 1541 | struct usb_endpoint_descriptor *ep_desc; |
| 1542 | int i, err; |
| 1543 | |
| 1544 | if (!data->isoc) |
| 1545 | return -ENODEV; |
| 1546 | |
Marcel Holtmann | 459232f | 2017-10-24 19:42:45 +0200 | [diff] [blame] | 1547 | err = usb_set_interface(data->udev, data->isoc_ifnum, altsetting); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1548 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1549 | bt_dev_err(hdev, "setting interface failed (%d)", -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1550 | return err; |
| 1551 | } |
| 1552 | |
| 1553 | data->isoc_altsetting = altsetting; |
| 1554 | |
| 1555 | data->isoc_tx_ep = NULL; |
| 1556 | data->isoc_rx_ep = NULL; |
| 1557 | |
| 1558 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 1559 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 1560 | |
| 1561 | if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) { |
| 1562 | data->isoc_tx_ep = ep_desc; |
| 1563 | continue; |
| 1564 | } |
| 1565 | |
| 1566 | if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) { |
| 1567 | data->isoc_rx_ep = ep_desc; |
| 1568 | continue; |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | if (!data->isoc_tx_ep || !data->isoc_rx_ep) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1573 | bt_dev_err(hdev, "invalid SCO descriptors"); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1574 | return -ENODEV; |
| 1575 | } |
| 1576 | |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1580 | static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts) |
| 1581 | { |
| 1582 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1583 | int err; |
| 1584 | |
| 1585 | if (data->isoc_altsetting != new_alts) { |
| 1586 | unsigned long flags; |
| 1587 | |
| 1588 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1589 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1590 | |
| 1591 | /* When isochronous alternate setting needs to be |
| 1592 | * changed, because SCO connection has been added |
| 1593 | * or removed, a packet fragment may be left in the |
| 1594 | * reassembling state. This could lead to wrongly |
| 1595 | * assembled fragments. |
| 1596 | * |
| 1597 | * Clear outstanding fragment when selecting a new |
| 1598 | * alternate setting. |
| 1599 | */ |
| 1600 | spin_lock_irqsave(&data->rxlock, flags); |
| 1601 | kfree_skb(data->sco_skb); |
| 1602 | data->sco_skb = NULL; |
| 1603 | spin_unlock_irqrestore(&data->rxlock, flags); |
| 1604 | |
| 1605 | err = __set_isoc_interface(hdev, new_alts); |
| 1606 | if (err < 0) |
| 1607 | return err; |
| 1608 | } |
| 1609 | |
| 1610 | if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
| 1611 | if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0) |
| 1612 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1613 | else |
| 1614 | btusb_submit_isoc_urb(hdev, GFP_KERNEL); |
| 1615 | } |
| 1616 | |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data, |
| 1621 | int alt) |
| 1622 | { |
| 1623 | struct usb_interface *intf = data->isoc; |
| 1624 | int i; |
| 1625 | |
| 1626 | BT_DBG("Looking for Alt no :%d", alt); |
| 1627 | |
Sathish Narasimman | fcd156ee | 2020-04-08 10:57:03 +0530 | [diff] [blame] | 1628 | if (!intf) |
| 1629 | return NULL; |
| 1630 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1631 | for (i = 0; i < intf->num_altsetting; i++) { |
| 1632 | if (intf->altsetting[i].desc.bAlternateSetting == alt) |
| 1633 | return &intf->altsetting[i]; |
| 1634 | } |
| 1635 | |
| 1636 | return NULL; |
| 1637 | } |
| 1638 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1639 | static void btusb_work(struct work_struct *work) |
| 1640 | { |
| 1641 | struct btusb_data *data = container_of(work, struct btusb_data, work); |
| 1642 | struct hci_dev *hdev = data->hdev; |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1643 | int new_alts = 0; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1644 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1645 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1646 | if (data->sco_num > 0) { |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1647 | if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) { |
Oliver Neukum | 8efdd0c | 2011-02-11 13:00:06 +0100 | [diff] [blame] | 1648 | err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1649 | if (err < 0) { |
| 1650 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1651 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1652 | return; |
| 1653 | } |
| 1654 | |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1655 | set_bit(BTUSB_DID_ISO_RESUME, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1656 | } |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1657 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1658 | if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) { |
| 1659 | if (hdev->voice_setting & 0x0020) { |
| 1660 | static const int alts[3] = { 2, 4, 5 }; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1661 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1662 | new_alts = alts[data->sco_num - 1]; |
| 1663 | } else { |
| 1664 | new_alts = data->sco_num; |
| 1665 | } |
| 1666 | } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) { |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1667 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1668 | data->usb_alt6_packet_flow = true; |
Kuba Pawlak | f6fc86f | 2015-10-28 15:18:05 +0100 | [diff] [blame] | 1669 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1670 | /* Check if Alt 6 is supported for Transparent audio */ |
| 1671 | if (btusb_find_altsetting(data, 6)) |
| 1672 | new_alts = 6; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1673 | else |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1674 | bt_dev_err(hdev, "Device does not support ALT setting 6"); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1675 | } |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1676 | |
| 1677 | if (btusb_switch_alt_setting(hdev, new_alts) < 0) |
| 1678 | bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1679 | } else { |
| 1680 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1681 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1682 | |
| 1683 | __set_isoc_interface(hdev, 0); |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1684 | if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags)) |
Oliver Neukum | 8efdd0c | 2011-02-11 13:00:06 +0100 | [diff] [blame] | 1685 | usb_autopm_put_interface(data->isoc ? data->isoc : data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1689 | static void btusb_waker(struct work_struct *work) |
| 1690 | { |
| 1691 | struct btusb_data *data = container_of(work, struct btusb_data, waker); |
| 1692 | int err; |
| 1693 | |
| 1694 | err = usb_autopm_get_interface(data->intf); |
| 1695 | if (err < 0) |
| 1696 | return; |
| 1697 | |
| 1698 | usb_autopm_put_interface(data->intf); |
| 1699 | } |
| 1700 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 1701 | static int btusb_setup_bcm92035(struct hci_dev *hdev) |
| 1702 | { |
| 1703 | struct sk_buff *skb; |
| 1704 | u8 val = 0x00; |
| 1705 | |
| 1706 | BT_DBG("%s", hdev->name); |
| 1707 | |
| 1708 | skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT); |
| 1709 | if (IS_ERR(skb)) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1710 | bt_dev_err(hdev, "BCM92035 command failed (%ld)", PTR_ERR(skb)); |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 1711 | else |
| 1712 | kfree_skb(skb); |
| 1713 | |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1717 | static int btusb_setup_csr(struct hci_dev *hdev) |
| 1718 | { |
| 1719 | struct hci_rp_read_local_version *rp; |
| 1720 | struct sk_buff *skb; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1721 | |
| 1722 | BT_DBG("%s", hdev->name); |
| 1723 | |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1724 | skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL, |
| 1725 | HCI_INIT_TIMEOUT); |
| 1726 | if (IS_ERR(skb)) { |
| 1727 | int err = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1728 | bt_dev_err(hdev, "CSR: Local version failed (%d)", err); |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1729 | return err; |
| 1730 | } |
| 1731 | |
| 1732 | if (skb->len != sizeof(struct hci_rp_read_local_version)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1733 | bt_dev_err(hdev, "CSR: Local version length mismatch"); |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1734 | kfree_skb(skb); |
| 1735 | return -EIO; |
| 1736 | } |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1737 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1738 | rp = (struct hci_rp_read_local_version *)skb->data; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1739 | |
Johan Hedberg | 6cafcd9 | 2015-08-30 21:47:21 +0300 | [diff] [blame] | 1740 | /* Detect controllers which aren't real CSR ones. */ |
| 1741 | if (le16_to_cpu(rp->manufacturer) != 10 || |
| 1742 | le16_to_cpu(rp->lmp_subver) == 0x0c5c) { |
Marcel Holtmann | 9641d34 | 2015-06-07 10:01:01 +0200 | [diff] [blame] | 1743 | /* Clear the reset quirk since this is not an actual |
| 1744 | * early Bluetooth 1.1 device from CSR. |
| 1745 | */ |
| 1746 | clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1747 | |
Marcel Holtmann | 9641d34 | 2015-06-07 10:01:01 +0200 | [diff] [blame] | 1748 | /* These fake CSR controllers have all a broken |
| 1749 | * stored link key handling and so just disable it. |
| 1750 | */ |
| 1751 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1752 | } |
| 1753 | |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1754 | kfree_skb(skb); |
| 1755 | |
Marcel Holtmann | 9641d34 | 2015-06-07 10:01:01 +0200 | [diff] [blame] | 1756 | return 0; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1757 | } |
| 1758 | |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1759 | static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1760 | struct intel_version *ver) |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1761 | { |
| 1762 | const struct firmware *fw; |
| 1763 | char fwname[64]; |
| 1764 | int ret; |
| 1765 | |
| 1766 | snprintf(fwname, sizeof(fwname), |
| 1767 | "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq", |
| 1768 | ver->hw_platform, ver->hw_variant, ver->hw_revision, |
| 1769 | ver->fw_variant, ver->fw_revision, ver->fw_build_num, |
| 1770 | ver->fw_build_ww, ver->fw_build_yy); |
| 1771 | |
| 1772 | ret = request_firmware(&fw, fwname, &hdev->dev); |
| 1773 | if (ret < 0) { |
| 1774 | if (ret == -EINVAL) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1775 | bt_dev_err(hdev, "Intel firmware file request failed (%d)", |
| 1776 | ret); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1777 | return NULL; |
| 1778 | } |
| 1779 | |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1780 | bt_dev_err(hdev, "failed to open Intel firmware file: %s (%d)", |
| 1781 | fwname, ret); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1782 | |
| 1783 | /* If the correct firmware patch file is not found, use the |
| 1784 | * default firmware patch file instead |
| 1785 | */ |
| 1786 | snprintf(fwname, sizeof(fwname), "intel/ibt-hw-%x.%x.bseq", |
| 1787 | ver->hw_platform, ver->hw_variant); |
| 1788 | if (request_firmware(&fw, fwname, &hdev->dev) < 0) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1789 | bt_dev_err(hdev, "failed to open default fw file: %s", |
| 1790 | fwname); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1791 | return NULL; |
| 1792 | } |
| 1793 | } |
| 1794 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1795 | bt_dev_info(hdev, "Intel Bluetooth firmware file: %s", fwname); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1796 | |
| 1797 | return fw; |
| 1798 | } |
| 1799 | |
| 1800 | static int btusb_setup_intel_patching(struct hci_dev *hdev, |
| 1801 | const struct firmware *fw, |
| 1802 | const u8 **fw_ptr, int *disable_patch) |
| 1803 | { |
| 1804 | struct sk_buff *skb; |
| 1805 | struct hci_command_hdr *cmd; |
| 1806 | const u8 *cmd_param; |
| 1807 | struct hci_event_hdr *evt = NULL; |
| 1808 | const u8 *evt_param = NULL; |
| 1809 | int remain = fw->size - (*fw_ptr - fw->data); |
| 1810 | |
| 1811 | /* The first byte indicates the types of the patch command or event. |
| 1812 | * 0x01 means HCI command and 0x02 is HCI event. If the first bytes |
| 1813 | * in the current firmware buffer doesn't start with 0x01 or |
| 1814 | * the size of remain buffer is smaller than HCI command header, |
| 1815 | * the firmware file is corrupted and it should stop the patching |
| 1816 | * process. |
| 1817 | */ |
| 1818 | if (remain > HCI_COMMAND_HDR_SIZE && *fw_ptr[0] != 0x01) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1819 | bt_dev_err(hdev, "Intel fw corrupted: invalid cmd read"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1820 | return -EINVAL; |
| 1821 | } |
| 1822 | (*fw_ptr)++; |
| 1823 | remain--; |
| 1824 | |
| 1825 | cmd = (struct hci_command_hdr *)(*fw_ptr); |
| 1826 | *fw_ptr += sizeof(*cmd); |
| 1827 | remain -= sizeof(*cmd); |
| 1828 | |
| 1829 | /* Ensure that the remain firmware data is long enough than the length |
| 1830 | * of command parameter. If not, the firmware file is corrupted. |
| 1831 | */ |
| 1832 | if (remain < cmd->plen) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1833 | bt_dev_err(hdev, "Intel fw corrupted: invalid cmd len"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1834 | return -EFAULT; |
| 1835 | } |
| 1836 | |
| 1837 | /* If there is a command that loads a patch in the firmware |
| 1838 | * file, then enable the patch upon success, otherwise just |
| 1839 | * disable the manufacturer mode, for example patch activation |
| 1840 | * is not required when the default firmware patch file is used |
| 1841 | * because there are no patch data to load. |
| 1842 | */ |
| 1843 | if (*disable_patch && le16_to_cpu(cmd->opcode) == 0xfc8e) |
| 1844 | *disable_patch = 0; |
| 1845 | |
| 1846 | cmd_param = *fw_ptr; |
| 1847 | *fw_ptr += cmd->plen; |
| 1848 | remain -= cmd->plen; |
| 1849 | |
| 1850 | /* This reads the expected events when the above command is sent to the |
| 1851 | * device. Some vendor commands expects more than one events, for |
| 1852 | * example command status event followed by vendor specific event. |
| 1853 | * For this case, it only keeps the last expected event. so the command |
| 1854 | * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of |
| 1855 | * last expected event. |
| 1856 | */ |
| 1857 | while (remain > HCI_EVENT_HDR_SIZE && *fw_ptr[0] == 0x02) { |
| 1858 | (*fw_ptr)++; |
| 1859 | remain--; |
| 1860 | |
| 1861 | evt = (struct hci_event_hdr *)(*fw_ptr); |
| 1862 | *fw_ptr += sizeof(*evt); |
| 1863 | remain -= sizeof(*evt); |
| 1864 | |
| 1865 | if (remain < evt->plen) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1866 | bt_dev_err(hdev, "Intel fw corrupted: invalid evt len"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1867 | return -EFAULT; |
| 1868 | } |
| 1869 | |
| 1870 | evt_param = *fw_ptr; |
| 1871 | *fw_ptr += evt->plen; |
| 1872 | remain -= evt->plen; |
| 1873 | } |
| 1874 | |
| 1875 | /* Every HCI commands in the firmware file has its correspond event. |
| 1876 | * If event is not found or remain is smaller than zero, the firmware |
| 1877 | * file is corrupted. |
| 1878 | */ |
| 1879 | if (!evt || !evt_param || remain < 0) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1880 | bt_dev_err(hdev, "Intel fw corrupted: invalid evt read"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1881 | return -EFAULT; |
| 1882 | } |
| 1883 | |
| 1884 | skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cmd->opcode), cmd->plen, |
| 1885 | cmd_param, evt->evt, HCI_INIT_TIMEOUT); |
| 1886 | if (IS_ERR(skb)) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1887 | bt_dev_err(hdev, "sending Intel patch command (0x%4.4x) failed (%ld)", |
| 1888 | cmd->opcode, PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1889 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | /* It ensures that the returned event matches the event data read from |
| 1893 | * the firmware file. At fist, it checks the length and then |
| 1894 | * the contents of the event. |
| 1895 | */ |
| 1896 | if (skb->len != evt->plen) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1897 | bt_dev_err(hdev, "mismatch event length (opcode 0x%4.4x)", |
| 1898 | le16_to_cpu(cmd->opcode)); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1899 | kfree_skb(skb); |
| 1900 | return -EFAULT; |
| 1901 | } |
| 1902 | |
| 1903 | if (memcmp(skb->data, evt_param, evt->plen)) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1904 | bt_dev_err(hdev, "mismatch event parameter (opcode 0x%4.4x)", |
| 1905 | le16_to_cpu(cmd->opcode)); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1906 | kfree_skb(skb); |
| 1907 | return -EFAULT; |
| 1908 | } |
| 1909 | kfree_skb(skb); |
| 1910 | |
| 1911 | return 0; |
| 1912 | } |
| 1913 | |
| 1914 | static int btusb_setup_intel(struct hci_dev *hdev) |
| 1915 | { |
| 1916 | struct sk_buff *skb; |
| 1917 | const struct firmware *fw; |
| 1918 | const u8 *fw_ptr; |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 1919 | int disable_patch, err; |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 1920 | struct intel_version ver; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1921 | |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1922 | BT_DBG("%s", hdev->name); |
| 1923 | |
| 1924 | /* The controller has a bug with the first HCI command sent to it |
| 1925 | * returning number of completed commands as zero. This would stall the |
| 1926 | * command processing in the Bluetooth core. |
| 1927 | * |
| 1928 | * As a workaround, send HCI Reset command first which will reset the |
| 1929 | * number of completed commands and allow normal command processing |
| 1930 | * from now on. |
| 1931 | */ |
| 1932 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 1933 | if (IS_ERR(skb)) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1934 | bt_dev_err(hdev, "sending initial HCI reset command failed (%ld)", |
| 1935 | PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1936 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1937 | } |
| 1938 | kfree_skb(skb); |
| 1939 | |
| 1940 | /* Read Intel specific controller version first to allow selection of |
| 1941 | * which firmware file to load. |
| 1942 | * |
| 1943 | * The returned information are hardware variant and revision plus |
| 1944 | * firmware variant, revision and build number. |
| 1945 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 1946 | err = btintel_read_version(hdev, &ver); |
| 1947 | if (err) |
| 1948 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1949 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1950 | bt_dev_info(hdev, "read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x", |
| 1951 | ver.hw_platform, ver.hw_variant, ver.hw_revision, |
| 1952 | ver.fw_variant, ver.fw_revision, ver.fw_build_num, |
| 1953 | ver.fw_build_ww, ver.fw_build_yy, ver.fw_patch_num); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1954 | |
| 1955 | /* fw_patch_num indicates the version of patch the device currently |
| 1956 | * have. If there is no patch data in the device, it is always 0x00. |
Minjune Kim | 5075eda | 2015-08-27 13:21:52 +0900 | [diff] [blame] | 1957 | * So, if it is other than 0x00, no need to patch the device again. |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1958 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 1959 | if (ver.fw_patch_num) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1960 | bt_dev_info(hdev, "Intel device is already patched. " |
| 1961 | "patch num: %02x", ver.fw_patch_num); |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 1962 | goto complete; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /* Opens the firmware patch file based on the firmware version read |
| 1966 | * from the controller. If it fails to open the matching firmware |
| 1967 | * patch file, it tries to open the default firmware patch file. |
| 1968 | * If no patch file is found, allow the device to operate without |
| 1969 | * a patch. |
| 1970 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 1971 | fw = btusb_setup_intel_get_fw(hdev, &ver); |
| 1972 | if (!fw) |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 1973 | goto complete; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1974 | fw_ptr = fw->data; |
| 1975 | |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 1976 | /* Enable the manufacturer mode of the controller. |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1977 | * Only while this mode is enabled, the driver can download the |
| 1978 | * firmware patch data and configuration parameters. |
| 1979 | */ |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 1980 | err = btintel_enter_mfg(hdev); |
| 1981 | if (err) { |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1982 | release_firmware(fw); |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 1983 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1986 | disable_patch = 1; |
| 1987 | |
| 1988 | /* The firmware data file consists of list of Intel specific HCI |
| 1989 | * commands and its expected events. The first byte indicates the |
| 1990 | * type of the message, either HCI command or HCI event. |
| 1991 | * |
| 1992 | * It reads the command and its expected event from the firmware file, |
| 1993 | * and send to the controller. Once __hci_cmd_sync_ev() returns, |
| 1994 | * the returned event is compared with the event read from the firmware |
| 1995 | * file and it will continue until all the messages are downloaded to |
| 1996 | * the controller. |
| 1997 | * |
| 1998 | * Once the firmware patching is completed successfully, |
| 1999 | * the manufacturer mode is disabled with reset and activating the |
| 2000 | * downloaded patch. |
| 2001 | * |
| 2002 | * If the firmware patching fails, the manufacturer mode is |
| 2003 | * disabled with reset and deactivating the patch. |
| 2004 | * |
| 2005 | * If the default patch file is used, no reset is done when disabling |
| 2006 | * the manufacturer. |
| 2007 | */ |
| 2008 | while (fw->size > fw_ptr - fw->data) { |
| 2009 | int ret; |
| 2010 | |
| 2011 | ret = btusb_setup_intel_patching(hdev, fw, &fw_ptr, |
| 2012 | &disable_patch); |
| 2013 | if (ret < 0) |
| 2014 | goto exit_mfg_deactivate; |
| 2015 | } |
| 2016 | |
| 2017 | release_firmware(fw); |
| 2018 | |
| 2019 | if (disable_patch) |
| 2020 | goto exit_mfg_disable; |
| 2021 | |
| 2022 | /* Patching completed successfully and disable the manufacturer mode |
| 2023 | * with reset and activate the downloaded firmware patches. |
| 2024 | */ |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2025 | err = btintel_exit_mfg(hdev, true, true); |
| 2026 | if (err) |
| 2027 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2028 | |
Sukumar Ghorai | 905d7b1 | 2020-03-16 11:37:18 +0530 | [diff] [blame] | 2029 | /* Need build number for downloaded fw patches in |
| 2030 | * every power-on boot |
| 2031 | */ |
| 2032 | err = btintel_read_version(hdev, &ver); |
| 2033 | if (err) |
| 2034 | return err; |
| 2035 | bt_dev_info(hdev, "Intel BT fw patch 0x%02x completed & activated", |
| 2036 | ver.fw_patch_num); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2037 | |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2038 | goto complete; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2039 | |
| 2040 | exit_mfg_disable: |
| 2041 | /* Disable the manufacturer mode without reset */ |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2042 | err = btintel_exit_mfg(hdev, false, false); |
| 2043 | if (err) |
| 2044 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2045 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2046 | bt_dev_info(hdev, "Intel firmware patch completed"); |
Marcel Holtmann | 40cb098 | 2014-07-02 12:06:45 +0200 | [diff] [blame] | 2047 | |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2048 | goto complete; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2049 | |
| 2050 | exit_mfg_deactivate: |
| 2051 | release_firmware(fw); |
| 2052 | |
| 2053 | /* Patching failed. Disable the manufacturer mode with reset and |
| 2054 | * deactivate the downloaded firmware patches. |
| 2055 | */ |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2056 | err = btintel_exit_mfg(hdev, true, false); |
| 2057 | if (err) |
| 2058 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2059 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2060 | bt_dev_info(hdev, "Intel firmware patch completed and deactivated"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2061 | |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2062 | complete: |
| 2063 | /* Set the event mask for Intel specific vendor events. This enables |
| 2064 | * a few extra events that are useful during general operation. |
| 2065 | */ |
| 2066 | btintel_set_event_mask_mfg(hdev, false); |
| 2067 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 2068 | btintel_check_bdaddr(hdev); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2069 | return 0; |
| 2070 | } |
| 2071 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2072 | static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode) |
| 2073 | { |
| 2074 | struct sk_buff *skb; |
| 2075 | struct hci_event_hdr *hdr; |
| 2076 | struct hci_ev_cmd_complete *evt; |
| 2077 | |
Jia-Ju Bai | cf07e34 | 2018-07-23 11:38:51 +0800 | [diff] [blame] | 2078 | skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2079 | if (!skb) |
| 2080 | return -ENOMEM; |
| 2081 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 2082 | hdr = skb_put(skb, sizeof(*hdr)); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2083 | hdr->evt = HCI_EV_CMD_COMPLETE; |
| 2084 | hdr->plen = sizeof(*evt) + 1; |
| 2085 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 2086 | evt = skb_put(skb, sizeof(*evt)); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2087 | evt->ncmd = 0x01; |
| 2088 | evt->opcode = cpu_to_le16(opcode); |
| 2089 | |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 2090 | skb_put_u8(skb, 0x00); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2091 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 2092 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2093 | |
| 2094 | return hci_recv_frame(hdev, skb); |
| 2095 | } |
| 2096 | |
| 2097 | static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer, |
| 2098 | int count) |
| 2099 | { |
| 2100 | /* When the device is in bootloader mode, then it can send |
| 2101 | * events via the bulk endpoint. These events are treated the |
| 2102 | * same way as the ones received from the interrupt endpoint. |
| 2103 | */ |
| 2104 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) |
| 2105 | return btusb_recv_intr(data, buffer, count); |
| 2106 | |
| 2107 | return btusb_recv_bulk(data, buffer, count); |
| 2108 | } |
| 2109 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2110 | static void btusb_intel_bootup(struct btusb_data *data, const void *ptr, |
| 2111 | unsigned int len) |
| 2112 | { |
| 2113 | const struct intel_bootup *evt = ptr; |
| 2114 | |
| 2115 | if (len != sizeof(*evt)) |
| 2116 | return; |
| 2117 | |
Andrea Parri | dff6d59 | 2018-11-27 12:22:25 +0100 | [diff] [blame] | 2118 | if (test_and_clear_bit(BTUSB_BOOTING, &data->flags)) |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2119 | wake_up_bit(&data->flags, BTUSB_BOOTING); |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | static void btusb_intel_secure_send_result(struct btusb_data *data, |
| 2123 | const void *ptr, unsigned int len) |
| 2124 | { |
| 2125 | const struct intel_secure_send_result *evt = ptr; |
| 2126 | |
| 2127 | if (len != sizeof(*evt)) |
| 2128 | return; |
| 2129 | |
| 2130 | if (evt->result) |
| 2131 | set_bit(BTUSB_FIRMWARE_FAILED, &data->flags); |
| 2132 | |
| 2133 | if (test_and_clear_bit(BTUSB_DOWNLOADING, &data->flags) && |
Andrea Parri | dff6d59 | 2018-11-27 12:22:25 +0100 | [diff] [blame] | 2134 | test_bit(BTUSB_FIRMWARE_LOADED, &data->flags)) |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2135 | wake_up_bit(&data->flags, BTUSB_DOWNLOADING); |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2138 | static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb) |
| 2139 | { |
| 2140 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2141 | |
| 2142 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 2143 | struct hci_event_hdr *hdr = (void *)skb->data; |
| 2144 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2145 | if (skb->len > HCI_EVENT_HDR_SIZE && hdr->evt == 0xff && |
| 2146 | hdr->plen > 0) { |
| 2147 | const void *ptr = skb->data + HCI_EVENT_HDR_SIZE + 1; |
| 2148 | unsigned int len = skb->len - HCI_EVENT_HDR_SIZE - 1; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2149 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2150 | switch (skb->data[2]) { |
| 2151 | case 0x02: |
| 2152 | /* When switching to the operational firmware |
| 2153 | * the device sends a vendor specific event |
| 2154 | * indicating that the bootup completed. |
| 2155 | */ |
| 2156 | btusb_intel_bootup(data, ptr, len); |
| 2157 | break; |
| 2158 | case 0x06: |
| 2159 | /* When the firmware loading completes the |
| 2160 | * device sends out a vendor specific event |
| 2161 | * indicating the result of the firmware |
| 2162 | * loading. |
| 2163 | */ |
| 2164 | btusb_intel_secure_send_result(data, ptr, len); |
| 2165 | break; |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2166 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | return hci_recv_frame(hdev, skb); |
| 2171 | } |
| 2172 | |
| 2173 | static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) |
| 2174 | { |
| 2175 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2176 | struct urb *urb; |
| 2177 | |
| 2178 | BT_DBG("%s", hdev->name); |
| 2179 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 2180 | switch (hci_skb_pkt_type(skb)) { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2181 | case HCI_COMMAND_PKT: |
| 2182 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 2183 | struct hci_command_hdr *cmd = (void *)skb->data; |
| 2184 | __u16 opcode = le16_to_cpu(cmd->opcode); |
| 2185 | |
| 2186 | /* When in bootloader mode and the command 0xfc09 |
| 2187 | * is received, it needs to be send down the |
| 2188 | * bulk endpoint. So allocate a bulk URB instead. |
| 2189 | */ |
| 2190 | if (opcode == 0xfc09) |
| 2191 | urb = alloc_bulk_urb(hdev, skb); |
| 2192 | else |
| 2193 | urb = alloc_ctrl_urb(hdev, skb); |
| 2194 | |
| 2195 | /* When the 0xfc01 command is issued to boot into |
| 2196 | * the operational firmware, it will actually not |
| 2197 | * send a command complete event. To keep the flow |
| 2198 | * control working inject that event here. |
| 2199 | */ |
| 2200 | if (opcode == 0xfc01) |
| 2201 | inject_cmd_complete(hdev, opcode); |
| 2202 | } else { |
| 2203 | urb = alloc_ctrl_urb(hdev, skb); |
| 2204 | } |
| 2205 | if (IS_ERR(urb)) |
| 2206 | return PTR_ERR(urb); |
| 2207 | |
| 2208 | hdev->stat.cmd_tx++; |
| 2209 | return submit_or_queue_tx_urb(hdev, urb); |
| 2210 | |
| 2211 | case HCI_ACLDATA_PKT: |
| 2212 | urb = alloc_bulk_urb(hdev, skb); |
| 2213 | if (IS_ERR(urb)) |
| 2214 | return PTR_ERR(urb); |
| 2215 | |
| 2216 | hdev->stat.acl_tx++; |
| 2217 | return submit_or_queue_tx_urb(hdev, urb); |
| 2218 | |
| 2219 | case HCI_SCODATA_PKT: |
| 2220 | if (hci_conn_num(hdev, SCO_LINK) < 1) |
| 2221 | return -ENODEV; |
| 2222 | |
| 2223 | urb = alloc_isoc_urb(hdev, skb); |
| 2224 | if (IS_ERR(urb)) |
| 2225 | return PTR_ERR(urb); |
| 2226 | |
| 2227 | hdev->stat.sco_tx++; |
| 2228 | return submit_tx_urb(hdev, urb); |
| 2229 | } |
| 2230 | |
| 2231 | return -EILSEQ; |
| 2232 | } |
| 2233 | |
Raghuram Hegde | 2da711bc | 2018-12-19 11:42:18 +0530 | [diff] [blame] | 2234 | static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver, |
| 2235 | struct intel_boot_params *params, |
| 2236 | char *fw_name, size_t len, |
| 2237 | const char *suffix) |
| 2238 | { |
| 2239 | switch (ver->hw_variant) { |
| 2240 | case 0x0b: /* SfP */ |
| 2241 | case 0x0c: /* WsP */ |
| 2242 | snprintf(fw_name, len, "intel/ibt-%u-%u.%s", |
| 2243 | le16_to_cpu(ver->hw_variant), |
| 2244 | le16_to_cpu(params->dev_revid), |
| 2245 | suffix); |
| 2246 | break; |
| 2247 | case 0x11: /* JfP */ |
| 2248 | case 0x12: /* ThP */ |
| 2249 | case 0x13: /* HrP */ |
| 2250 | case 0x14: /* CcP */ |
| 2251 | snprintf(fw_name, len, "intel/ibt-%u-%u-%u.%s", |
| 2252 | le16_to_cpu(ver->hw_variant), |
| 2253 | le16_to_cpu(ver->hw_revision), |
| 2254 | le16_to_cpu(ver->fw_revision), |
| 2255 | suffix); |
| 2256 | break; |
| 2257 | default: |
| 2258 | return false; |
| 2259 | } |
| 2260 | return true; |
| 2261 | } |
| 2262 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2263 | static int btusb_setup_intel_new(struct hci_dev *hdev) |
| 2264 | { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2265 | struct btusb_data *data = hci_get_drvdata(hdev); |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2266 | struct intel_version ver; |
Tedd Ho-Jeong An | faf174d | 2018-01-24 09:19:20 -0800 | [diff] [blame] | 2267 | struct intel_boot_params params; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2268 | const struct firmware *fw; |
Tedd Ho-Jeong An | e5889af | 2018-01-24 09:19:18 -0800 | [diff] [blame] | 2269 | u32 boot_param; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2270 | char fwname[64]; |
| 2271 | ktime_t calltime, delta, rettime; |
| 2272 | unsigned long long duration; |
| 2273 | int err; |
| 2274 | |
| 2275 | BT_DBG("%s", hdev->name); |
| 2276 | |
Tedd Ho-Jeong An | 04d729b | 2018-01-24 09:19:19 -0800 | [diff] [blame] | 2277 | /* Set the default boot parameter to 0x0 and it is updated to |
| 2278 | * SKU specific boot parameter after reading Intel_Write_Boot_Params |
| 2279 | * command while downloading the firmware. |
| 2280 | */ |
| 2281 | boot_param = 0x00000000; |
Tedd Ho-Jeong An | e5889af | 2018-01-24 09:19:18 -0800 | [diff] [blame] | 2282 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2283 | calltime = ktime_get(); |
| 2284 | |
| 2285 | /* Read the Intel version information to determine if the device |
| 2286 | * is in bootloader mode or if it already has operational firmware |
| 2287 | * loaded. |
| 2288 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2289 | err = btintel_read_version(hdev, &ver); |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2290 | if (err) { |
| 2291 | bt_dev_err(hdev, "Intel Read version failed (%d)", err); |
| 2292 | btintel_reset_to_bootloader(hdev); |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2293 | return err; |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2294 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2295 | |
| 2296 | /* The hardware platform number has a fixed value of 0x37 and |
| 2297 | * for now only accept this single value. |
| 2298 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2299 | if (ver.hw_platform != 0x37) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2300 | bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)", |
| 2301 | ver.hw_platform); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2302 | return -EINVAL; |
| 2303 | } |
| 2304 | |
Tedd Ho-Jeong An | 9268834 | 2017-03-06 15:38:26 -0800 | [diff] [blame] | 2305 | /* Check for supported iBT hardware variants of this firmware |
| 2306 | * loading method. |
Tedd Ho-Jeong An | a0af53b | 2016-05-06 11:53:46 -0700 | [diff] [blame] | 2307 | * |
| 2308 | * This check has been put in place to ensure correct forward |
| 2309 | * compatibility options when newer hardware variants come along. |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2310 | */ |
Tedd Ho-Jeong An | 9268834 | 2017-03-06 15:38:26 -0800 | [diff] [blame] | 2311 | switch (ver.hw_variant) { |
| 2312 | case 0x0b: /* SfP */ |
| 2313 | case 0x0c: /* WsP */ |
Tedd Ho-Jeong An | 86a6129 | 2017-05-01 13:35:12 -0700 | [diff] [blame] | 2314 | case 0x11: /* JfP */ |
Marcel Holtmann | de76614 | 2017-03-06 15:38:28 -0800 | [diff] [blame] | 2315 | case 0x12: /* ThP */ |
Tedd Ho-Jeong An | 1ce0cec | 2018-02-05 14:20:36 -0800 | [diff] [blame] | 2316 | case 0x13: /* HrP */ |
Raghuram Hegde | 2da711bc | 2018-12-19 11:42:18 +0530 | [diff] [blame] | 2317 | case 0x14: /* CcP */ |
Tedd Ho-Jeong An | 9268834 | 2017-03-06 15:38:26 -0800 | [diff] [blame] | 2318 | break; |
| 2319 | default: |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2320 | bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)", |
| 2321 | ver.hw_variant); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2322 | return -EINVAL; |
| 2323 | } |
| 2324 | |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2325 | btintel_version_info(hdev, &ver); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2326 | |
| 2327 | /* The firmware variant determines if the device is in bootloader |
| 2328 | * mode or is running operational firmware. The value 0x06 identifies |
| 2329 | * the bootloader and the value 0x23 identifies the operational |
| 2330 | * firmware. |
| 2331 | * |
| 2332 | * When the operational firmware is already present, then only |
| 2333 | * the check for valid Bluetooth device address is needed. This |
| 2334 | * determines if the device will be added as configured or |
| 2335 | * unconfigured controller. |
| 2336 | * |
| 2337 | * It is not possible to use the Secure Boot Parameters in this |
| 2338 | * case since that command is only available in bootloader mode. |
| 2339 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2340 | if (ver.fw_variant == 0x23) { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2341 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 2342 | btintel_check_bdaddr(hdev); |
Marcel Holtmann | 7fd673b | 2020-04-03 21:44:02 +0200 | [diff] [blame] | 2343 | goto finish; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | /* If the device is not in bootloader mode, then the only possible |
| 2347 | * choice is to return an error and abort the device initialization. |
| 2348 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2349 | if (ver.fw_variant != 0x06) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2350 | bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)", |
| 2351 | ver.fw_variant); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2352 | return -ENODEV; |
| 2353 | } |
| 2354 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2355 | /* Read the secure boot parameters to identify the operating |
| 2356 | * details of the bootloader. |
| 2357 | */ |
Tedd Ho-Jeong An | faf174d | 2018-01-24 09:19:20 -0800 | [diff] [blame] | 2358 | err = btintel_read_boot_params(hdev, ¶ms); |
| 2359 | if (err) |
| 2360 | return err; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2361 | |
| 2362 | /* It is required that every single firmware fragment is acknowledged |
| 2363 | * with a command complete event. If the boot parameters indicate |
| 2364 | * that this bootloader does not send them, then abort the setup. |
| 2365 | */ |
Tedd Ho-Jeong An | faf174d | 2018-01-24 09:19:20 -0800 | [diff] [blame] | 2366 | if (params.limited_cce != 0x00) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2367 | bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)", |
| 2368 | params.limited_cce); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2369 | return -EINVAL; |
| 2370 | } |
| 2371 | |
| 2372 | /* If the OTP has no valid Bluetooth device address, then there will |
| 2373 | * also be no valid address for the operational firmware. |
| 2374 | */ |
Tedd Ho-Jeong An | faf174d | 2018-01-24 09:19:20 -0800 | [diff] [blame] | 2375 | if (!bacmp(¶ms.otp_bdaddr, BDADDR_ANY)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2376 | bt_dev_info(hdev, "No device address configured"); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2377 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); |
| 2378 | } |
| 2379 | |
| 2380 | /* With this Intel bootloader only the hardware variant and device |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2381 | * revision information are used to select the right firmware for SfP |
| 2382 | * and WsP. |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2383 | * |
Tedd Ho-Jeong An | 230b04a | 2016-06-28 08:56:39 -0700 | [diff] [blame] | 2384 | * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi. |
| 2385 | * |
| 2386 | * Currently the supported hardware variants are: |
| 2387 | * 11 (0x0b) for iBT3.0 (LnP/SfP) |
| 2388 | * 12 (0x0c) for iBT3.5 (WsP) |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2389 | * |
| 2390 | * For ThP/JfP and for future SKU's, the FW name varies based on HW |
| 2391 | * variant, HW revision and FW revision, as these are dependent on CNVi |
| 2392 | * and RF Combination. |
| 2393 | * |
Tedd Ho-Jeong An | 86a6129 | 2017-05-01 13:35:12 -0700 | [diff] [blame] | 2394 | * 17 (0x11) for iBT3.5 (JfP) |
| 2395 | * 18 (0x12) for iBT3.5 (ThP) |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2396 | * |
| 2397 | * The firmware file name for these will be |
| 2398 | * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi. |
| 2399 | * |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2400 | */ |
Raghuram Hegde | 2da711bc | 2018-12-19 11:42:18 +0530 | [diff] [blame] | 2401 | err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, fwname, |
| 2402 | sizeof(fwname), "sfi"); |
| 2403 | if (!err) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2404 | bt_dev_err(hdev, "Unsupported Intel firmware naming"); |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2405 | return -EINVAL; |
| 2406 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2407 | |
| 2408 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 2409 | if (err < 0) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2410 | bt_dev_err(hdev, "Failed to load Intel firmware file (%d)", err); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2411 | return err; |
| 2412 | } |
| 2413 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2414 | bt_dev_info(hdev, "Found device firmware: %s", fwname); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2415 | |
Tedd Ho-Jeong An | 52cc916 | 2015-06-12 16:20:05 -0700 | [diff] [blame] | 2416 | /* Save the DDC file name for later use to apply once the firmware |
| 2417 | * downloading is done. |
| 2418 | */ |
Raghuram Hegde | 2da711bc | 2018-12-19 11:42:18 +0530 | [diff] [blame] | 2419 | err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, fwname, |
| 2420 | sizeof(fwname), "ddc"); |
| 2421 | if (!err) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2422 | bt_dev_err(hdev, "Unsupported Intel firmware naming"); |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2423 | return -EINVAL; |
| 2424 | } |
Tedd Ho-Jeong An | 52cc916 | 2015-06-12 16:20:05 -0700 | [diff] [blame] | 2425 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2426 | if (fw->size < 644) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2427 | bt_dev_err(hdev, "Invalid size of firmware file (%zu)", |
| 2428 | fw->size); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2429 | err = -EBADF; |
| 2430 | goto done; |
| 2431 | } |
| 2432 | |
| 2433 | set_bit(BTUSB_DOWNLOADING, &data->flags); |
| 2434 | |
Tedd Ho-Jeong An | fbbe83c | 2018-01-24 09:19:21 -0800 | [diff] [blame] | 2435 | /* Start firmware downloading and get boot parameter */ |
| 2436 | err = btintel_download_firmware(hdev, fw, &boot_param); |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2437 | if (err < 0) { |
| 2438 | /* When FW download fails, send Intel Reset to retry |
| 2439 | * FW download. |
| 2440 | */ |
| 2441 | btintel_reset_to_bootloader(hdev); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2442 | goto done; |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2443 | } |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 2444 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
| 2445 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2446 | bt_dev_info(hdev, "Waiting for firmware download to complete"); |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2447 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2448 | /* Before switching the device into operational mode and with that |
| 2449 | * booting the loaded firmware, wait for the bootloader notification |
| 2450 | * that all fragments have been successfully received. |
| 2451 | * |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2452 | * When the event processing receives the notification, then the |
| 2453 | * BTUSB_DOWNLOADING flag will be cleared. |
| 2454 | * |
| 2455 | * The firmware loading should not take longer than 5 seconds |
| 2456 | * and thus just timeout if that happens and fail the setup |
| 2457 | * of this device. |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2458 | */ |
Johan Hedberg | 129a769 | 2015-02-14 09:33:35 +0200 | [diff] [blame] | 2459 | err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING, |
| 2460 | TASK_INTERRUPTIBLE, |
| 2461 | msecs_to_jiffies(5000)); |
Bart Van Assche | f0a70a0 | 2016-08-11 16:02:44 -0700 | [diff] [blame] | 2462 | if (err == -EINTR) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2463 | bt_dev_err(hdev, "Firmware loading interrupted"); |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2464 | goto done; |
| 2465 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2466 | |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2467 | if (err) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2468 | bt_dev_err(hdev, "Firmware loading timeout"); |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2469 | err = -ETIMEDOUT; |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2470 | btintel_reset_to_bootloader(hdev); |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2471 | goto done; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2475 | bt_dev_err(hdev, "Firmware loading failed"); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2476 | err = -ENOEXEC; |
| 2477 | goto done; |
| 2478 | } |
| 2479 | |
| 2480 | rettime = ktime_get(); |
| 2481 | delta = ktime_sub(rettime, calltime); |
| 2482 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; |
| 2483 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2484 | bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2485 | |
| 2486 | done: |
| 2487 | release_firmware(fw); |
| 2488 | |
| 2489 | if (err < 0) |
| 2490 | return err; |
| 2491 | |
| 2492 | calltime = ktime_get(); |
| 2493 | |
| 2494 | set_bit(BTUSB_BOOTING, &data->flags); |
| 2495 | |
Tedd Ho-Jeong An | e5889af | 2018-01-24 09:19:18 -0800 | [diff] [blame] | 2496 | err = btintel_send_intel_reset(hdev, boot_param); |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2497 | if (err) { |
| 2498 | bt_dev_err(hdev, "Intel Soft Reset failed (%d)", err); |
| 2499 | btintel_reset_to_bootloader(hdev); |
Tedd Ho-Jeong An | e5889af | 2018-01-24 09:19:18 -0800 | [diff] [blame] | 2500 | return err; |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2501 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2502 | |
| 2503 | /* The bootloader will not indicate when the device is ready. This |
| 2504 | * is done by the operational firmware sending bootup notification. |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2505 | * |
| 2506 | * Booting into operational firmware should not take longer than |
| 2507 | * 1 second. However if that happens, then just fail the setup |
| 2508 | * since something went wrong. |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2509 | */ |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2510 | bt_dev_info(hdev, "Waiting for device to boot"); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2511 | |
Johan Hedberg | 129a769 | 2015-02-14 09:33:35 +0200 | [diff] [blame] | 2512 | err = wait_on_bit_timeout(&data->flags, BTUSB_BOOTING, |
| 2513 | TASK_INTERRUPTIBLE, |
| 2514 | msecs_to_jiffies(1000)); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2515 | |
Bart Van Assche | f0a70a0 | 2016-08-11 16:02:44 -0700 | [diff] [blame] | 2516 | if (err == -EINTR) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2517 | bt_dev_err(hdev, "Device boot interrupted"); |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2518 | return -EINTR; |
| 2519 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2520 | |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2521 | if (err) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2522 | bt_dev_err(hdev, "Device boot timeout"); |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2523 | btintel_reset_to_bootloader(hdev); |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2524 | return -ETIMEDOUT; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | rettime = ktime_get(); |
| 2528 | delta = ktime_sub(rettime, calltime); |
| 2529 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; |
| 2530 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2531 | bt_dev_info(hdev, "Device booted in %llu usecs", duration); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2532 | |
| 2533 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
| 2534 | |
Tedd Ho-Jeong An | 52cc916 | 2015-06-12 16:20:05 -0700 | [diff] [blame] | 2535 | /* Once the device is running in operational mode, it needs to apply |
| 2536 | * the device configuration (DDC) parameters. |
| 2537 | * |
| 2538 | * The device can work without DDC parameters, so even if it fails |
| 2539 | * to load the file, no need to fail the setup. |
| 2540 | */ |
Loic Poulain | e924d3d | 2015-09-04 17:54:36 +0200 | [diff] [blame] | 2541 | btintel_load_ddc_config(hdev, fwname); |
Tedd Ho-Jeong An | 52cc916 | 2015-06-12 16:20:05 -0700 | [diff] [blame] | 2542 | |
Marcel Holtmann | 7fd673b | 2020-04-03 21:44:02 +0200 | [diff] [blame] | 2543 | /* Read the Intel version information after loading the FW */ |
| 2544 | err = btintel_read_version(hdev, &ver); |
| 2545 | if (err) |
| 2546 | return err; |
| 2547 | |
| 2548 | btintel_version_info(hdev, &ver); |
| 2549 | |
| 2550 | finish: |
Miao-chen Chou | fc04590 | 2020-04-03 21:44:03 +0200 | [diff] [blame] | 2551 | /* All Intel controllers that support the Microsoft vendor |
| 2552 | * extension are using 0xFC1E for VsMsftOpCode. |
| 2553 | */ |
| 2554 | switch (ver.hw_variant) { |
| 2555 | case 0x12: /* ThP */ |
| 2556 | hci_set_msft_opcode(hdev, 0xFC1E); |
| 2557 | break; |
| 2558 | } |
| 2559 | |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2560 | /* Set the event mask for Intel specific vendor events. This enables |
| 2561 | * a few extra events that are useful during general operation. It |
| 2562 | * does not enable any debugging related events. |
| 2563 | * |
| 2564 | * The device will function correctly without these events enabled |
| 2565 | * and thus no need to fail the setup. |
| 2566 | */ |
| 2567 | btintel_set_event_mask(hdev, false); |
| 2568 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2569 | return 0; |
| 2570 | } |
| 2571 | |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 2572 | static int btusb_shutdown_intel(struct hci_dev *hdev) |
| 2573 | { |
| 2574 | struct sk_buff *skb; |
| 2575 | long ret; |
| 2576 | |
Amit K Bag | 1313bcc | 2018-08-03 12:43:20 +0530 | [diff] [blame] | 2577 | /* In the shutdown sequence where Bluetooth is turned off followed |
| 2578 | * by WiFi being turned off, turning WiFi back on causes issue with |
| 2579 | * the RF calibration. |
| 2580 | * |
| 2581 | * To ensure that any RF activity has been stopped, issue HCI Reset |
| 2582 | * command to clear all ongoing activity including advertising, |
| 2583 | * scanning etc. |
| 2584 | */ |
| 2585 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 2586 | if (IS_ERR(skb)) { |
| 2587 | ret = PTR_ERR(skb); |
| 2588 | bt_dev_err(hdev, "HCI reset during shutdown failed"); |
| 2589 | return ret; |
| 2590 | } |
| 2591 | kfree_skb(skb); |
| 2592 | |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 2593 | /* Some platforms have an issue with BT LED when the interface is |
| 2594 | * down or BT radio is turned off, which takes 5 seconds to BT LED |
| 2595 | * goes off. This command turns off the BT LED immediately. |
| 2596 | */ |
| 2597 | skb = __hci_cmd_sync(hdev, 0xfc3f, 0, NULL, HCI_INIT_TIMEOUT); |
| 2598 | if (IS_ERR(skb)) { |
| 2599 | ret = PTR_ERR(skb); |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2600 | bt_dev_err(hdev, "turning off Intel device LED failed"); |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 2601 | return ret; |
| 2602 | } |
| 2603 | kfree_skb(skb); |
| 2604 | |
| 2605 | return 0; |
| 2606 | } |
| 2607 | |
Raghuram Hegde | 017a01c | 2019-01-29 17:54:48 +0530 | [diff] [blame] | 2608 | static int btusb_shutdown_intel_new(struct hci_dev *hdev) |
| 2609 | { |
| 2610 | struct sk_buff *skb; |
| 2611 | |
| 2612 | /* Send HCI Reset to the controller to stop any BT activity which |
| 2613 | * were triggered. This will help to save power and maintain the |
| 2614 | * sync b/w Host and controller |
| 2615 | */ |
| 2616 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 2617 | if (IS_ERR(skb)) { |
| 2618 | bt_dev_err(hdev, "HCI reset during shutdown failed"); |
| 2619 | return PTR_ERR(skb); |
| 2620 | } |
| 2621 | kfree_skb(skb); |
| 2622 | |
| 2623 | return 0; |
| 2624 | } |
| 2625 | |
Sean Wang | 9ce67c3 | 2019-06-02 08:02:49 +0800 | [diff] [blame] | 2626 | #define FIRMWARE_MT7663 "mediatek/mt7663pr2h.bin" |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2627 | #define FIRMWARE_MT7668 "mediatek/mt7668pr2h.bin" |
| 2628 | |
| 2629 | #define HCI_WMT_MAX_EVENT_SIZE 64 |
| 2630 | |
| 2631 | enum { |
| 2632 | BTMTK_WMT_PATCH_DWNLD = 0x1, |
| 2633 | BTMTK_WMT_FUNC_CTRL = 0x6, |
| 2634 | BTMTK_WMT_RST = 0x7, |
| 2635 | BTMTK_WMT_SEMAPHORE = 0x17, |
| 2636 | }; |
| 2637 | |
| 2638 | enum { |
| 2639 | BTMTK_WMT_INVALID, |
| 2640 | BTMTK_WMT_PATCH_UNDONE, |
| 2641 | BTMTK_WMT_PATCH_DONE, |
| 2642 | BTMTK_WMT_ON_UNDONE, |
| 2643 | BTMTK_WMT_ON_DONE, |
| 2644 | BTMTK_WMT_ON_PROGRESS, |
| 2645 | }; |
| 2646 | |
| 2647 | struct btmtk_wmt_hdr { |
| 2648 | u8 dir; |
| 2649 | u8 op; |
| 2650 | __le16 dlen; |
| 2651 | u8 flag; |
| 2652 | } __packed; |
| 2653 | |
| 2654 | struct btmtk_hci_wmt_cmd { |
| 2655 | struct btmtk_wmt_hdr hdr; |
| 2656 | u8 data[256]; |
| 2657 | } __packed; |
| 2658 | |
| 2659 | struct btmtk_hci_wmt_evt { |
| 2660 | struct hci_event_hdr hhdr; |
| 2661 | struct btmtk_wmt_hdr whdr; |
| 2662 | } __packed; |
| 2663 | |
| 2664 | struct btmtk_hci_wmt_evt_funcc { |
| 2665 | struct btmtk_hci_wmt_evt hwhdr; |
| 2666 | __be16 status; |
| 2667 | } __packed; |
| 2668 | |
| 2669 | struct btmtk_tci_sleep { |
| 2670 | u8 mode; |
| 2671 | __le16 duration; |
| 2672 | __le16 host_duration; |
| 2673 | u8 host_wakeup_pin; |
| 2674 | u8 time_compensation; |
| 2675 | } __packed; |
| 2676 | |
| 2677 | struct btmtk_hci_wmt_params { |
| 2678 | u8 op; |
| 2679 | u8 flag; |
| 2680 | u16 dlen; |
| 2681 | const void *data; |
| 2682 | u32 *status; |
| 2683 | }; |
| 2684 | |
| 2685 | static void btusb_mtk_wmt_recv(struct urb *urb) |
| 2686 | { |
| 2687 | struct hci_dev *hdev = urb->context; |
| 2688 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2689 | struct hci_event_hdr *hdr; |
| 2690 | struct sk_buff *skb; |
| 2691 | int err; |
| 2692 | |
| 2693 | if (urb->status == 0 && urb->actual_length > 0) { |
| 2694 | hdev->stat.byte_rx += urb->actual_length; |
| 2695 | |
| 2696 | /* WMT event shouldn't be fragmented and the size should be |
| 2697 | * less than HCI_WMT_MAX_EVENT_SIZE. |
| 2698 | */ |
| 2699 | skb = bt_skb_alloc(HCI_WMT_MAX_EVENT_SIZE, GFP_ATOMIC); |
| 2700 | if (!skb) { |
| 2701 | hdev->stat.err_rx++; |
| 2702 | goto err_out; |
| 2703 | } |
| 2704 | |
| 2705 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
| 2706 | skb_put_data(skb, urb->transfer_buffer, urb->actual_length); |
| 2707 | |
| 2708 | hdr = (void *)skb->data; |
| 2709 | /* Fix up the vendor event id with 0xff for vendor specific |
| 2710 | * instead of 0xe4 so that event send via monitoring socket can |
| 2711 | * be parsed properly. |
| 2712 | */ |
| 2713 | hdr->evt = 0xff; |
| 2714 | |
| 2715 | /* When someone waits for the WMT event, the skb is being cloned |
| 2716 | * and being processed the events from there then. |
| 2717 | */ |
| 2718 | if (test_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags)) { |
Johan Hovold | 22cc6b7 | 2019-11-28 19:24:27 +0100 | [diff] [blame] | 2719 | data->evt_skb = skb_clone(skb, GFP_ATOMIC); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2720 | if (!data->evt_skb) |
| 2721 | goto err_out; |
| 2722 | } |
| 2723 | |
| 2724 | err = hci_recv_frame(hdev, skb); |
| 2725 | if (err < 0) |
| 2726 | goto err_free_skb; |
| 2727 | |
| 2728 | if (test_and_clear_bit(BTUSB_TX_WAIT_VND_EVT, |
| 2729 | &data->flags)) { |
| 2730 | /* Barrier to sync with other CPUs */ |
| 2731 | smp_mb__after_atomic(); |
| 2732 | wake_up_bit(&data->flags, |
| 2733 | BTUSB_TX_WAIT_VND_EVT); |
| 2734 | } |
| 2735 | err_out: |
| 2736 | return; |
| 2737 | err_free_skb: |
| 2738 | kfree_skb(data->evt_skb); |
| 2739 | data->evt_skb = NULL; |
| 2740 | return; |
| 2741 | } else if (urb->status == -ENOENT) { |
| 2742 | /* Avoid suspend failed when usb_kill_urb */ |
| 2743 | return; |
| 2744 | } |
| 2745 | |
| 2746 | usb_mark_last_busy(data->udev); |
| 2747 | |
| 2748 | /* The URB complete handler is still called with urb->actual_length = 0 |
| 2749 | * when the event is not available, so we should keep re-submitting |
| 2750 | * URB until WMT event returns, Also, It's necessary to wait some time |
| 2751 | * between the two consecutive control URBs to relax the target device |
| 2752 | * to generate the event. Otherwise, the WMT event cannot return from |
| 2753 | * the device successfully. |
| 2754 | */ |
| 2755 | udelay(100); |
| 2756 | |
| 2757 | usb_anchor_urb(urb, &data->ctrl_anchor); |
| 2758 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 2759 | if (err < 0) { |
| 2760 | /* -EPERM: urb is being killed; |
| 2761 | * -ENODEV: device got disconnected |
| 2762 | */ |
| 2763 | if (err != -EPERM && err != -ENODEV) |
| 2764 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 2765 | urb, -err); |
| 2766 | usb_unanchor_urb(urb); |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | static int btusb_mtk_submit_wmt_recv_urb(struct hci_dev *hdev) |
| 2771 | { |
| 2772 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2773 | struct usb_ctrlrequest *dr; |
| 2774 | unsigned char *buf; |
| 2775 | int err, size = 64; |
| 2776 | unsigned int pipe; |
| 2777 | struct urb *urb; |
| 2778 | |
| 2779 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 2780 | if (!urb) |
| 2781 | return -ENOMEM; |
| 2782 | |
| 2783 | dr = kmalloc(sizeof(*dr), GFP_KERNEL); |
| 2784 | if (!dr) { |
| 2785 | usb_free_urb(urb); |
| 2786 | return -ENOMEM; |
| 2787 | } |
| 2788 | |
| 2789 | dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_IN; |
| 2790 | dr->bRequest = 1; |
| 2791 | dr->wIndex = cpu_to_le16(0); |
| 2792 | dr->wValue = cpu_to_le16(48); |
| 2793 | dr->wLength = cpu_to_le16(size); |
| 2794 | |
| 2795 | buf = kmalloc(size, GFP_KERNEL); |
| 2796 | if (!buf) { |
| 2797 | kfree(dr); |
| 2798 | return -ENOMEM; |
| 2799 | } |
| 2800 | |
| 2801 | pipe = usb_rcvctrlpipe(data->udev, 0); |
| 2802 | |
| 2803 | usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, |
| 2804 | buf, size, btusb_mtk_wmt_recv, hdev); |
| 2805 | |
| 2806 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 2807 | |
| 2808 | usb_anchor_urb(urb, &data->ctrl_anchor); |
| 2809 | err = usb_submit_urb(urb, GFP_KERNEL); |
| 2810 | if (err < 0) { |
| 2811 | if (err != -EPERM && err != -ENODEV) |
| 2812 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 2813 | urb, -err); |
| 2814 | usb_unanchor_urb(urb); |
| 2815 | } |
| 2816 | |
| 2817 | usb_free_urb(urb); |
| 2818 | |
| 2819 | return err; |
| 2820 | } |
| 2821 | |
| 2822 | static int btusb_mtk_hci_wmt_sync(struct hci_dev *hdev, |
| 2823 | struct btmtk_hci_wmt_params *wmt_params) |
| 2824 | { |
| 2825 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2826 | struct btmtk_hci_wmt_evt_funcc *wmt_evt_funcc; |
| 2827 | u32 hlen, status = BTMTK_WMT_INVALID; |
| 2828 | struct btmtk_hci_wmt_evt *wmt_evt; |
| 2829 | struct btmtk_hci_wmt_cmd wc; |
| 2830 | struct btmtk_wmt_hdr *hdr; |
| 2831 | int err; |
| 2832 | |
| 2833 | /* Submit control IN URB on demand to process the WMT event */ |
| 2834 | err = btusb_mtk_submit_wmt_recv_urb(hdev); |
| 2835 | if (err < 0) |
| 2836 | return err; |
| 2837 | |
| 2838 | /* Send the WMT command and wait until the WMT event returns */ |
| 2839 | hlen = sizeof(*hdr) + wmt_params->dlen; |
| 2840 | if (hlen > 255) |
| 2841 | return -EINVAL; |
| 2842 | |
| 2843 | hdr = (struct btmtk_wmt_hdr *)&wc; |
| 2844 | hdr->dir = 1; |
| 2845 | hdr->op = wmt_params->op; |
| 2846 | hdr->dlen = cpu_to_le16(wmt_params->dlen + 1); |
| 2847 | hdr->flag = wmt_params->flag; |
| 2848 | memcpy(wc.data, wmt_params->data, wmt_params->dlen); |
| 2849 | |
| 2850 | set_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
| 2851 | |
| 2852 | err = __hci_cmd_send(hdev, 0xfc6f, hlen, &wc); |
| 2853 | |
| 2854 | if (err < 0) { |
| 2855 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
| 2856 | return err; |
| 2857 | } |
| 2858 | |
| 2859 | /* The vendor specific WMT commands are all answered by a vendor |
| 2860 | * specific event and will have the Command Status or Command |
| 2861 | * Complete as with usual HCI command flow control. |
| 2862 | * |
| 2863 | * After sending the command, wait for BTUSB_TX_WAIT_VND_EVT |
| 2864 | * state to be cleared. The driver specific event receive routine |
| 2865 | * will clear that state and with that indicate completion of the |
| 2866 | * WMT command. |
| 2867 | */ |
| 2868 | err = wait_on_bit_timeout(&data->flags, BTUSB_TX_WAIT_VND_EVT, |
| 2869 | TASK_INTERRUPTIBLE, HCI_INIT_TIMEOUT); |
| 2870 | if (err == -EINTR) { |
| 2871 | bt_dev_err(hdev, "Execution of wmt command interrupted"); |
| 2872 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
| 2873 | return err; |
| 2874 | } |
| 2875 | |
| 2876 | if (err) { |
| 2877 | bt_dev_err(hdev, "Execution of wmt command timed out"); |
| 2878 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
| 2879 | return -ETIMEDOUT; |
| 2880 | } |
| 2881 | |
| 2882 | /* Parse and handle the return WMT event */ |
| 2883 | wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data; |
| 2884 | if (wmt_evt->whdr.op != hdr->op) { |
| 2885 | bt_dev_err(hdev, "Wrong op received %d expected %d", |
| 2886 | wmt_evt->whdr.op, hdr->op); |
| 2887 | err = -EIO; |
| 2888 | goto err_free_skb; |
| 2889 | } |
| 2890 | |
| 2891 | switch (wmt_evt->whdr.op) { |
| 2892 | case BTMTK_WMT_SEMAPHORE: |
| 2893 | if (wmt_evt->whdr.flag == 2) |
| 2894 | status = BTMTK_WMT_PATCH_UNDONE; |
| 2895 | else |
| 2896 | status = BTMTK_WMT_PATCH_DONE; |
| 2897 | break; |
| 2898 | case BTMTK_WMT_FUNC_CTRL: |
| 2899 | wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt; |
| 2900 | if (be16_to_cpu(wmt_evt_funcc->status) == 0x404) |
| 2901 | status = BTMTK_WMT_ON_DONE; |
| 2902 | else if (be16_to_cpu(wmt_evt_funcc->status) == 0x420) |
| 2903 | status = BTMTK_WMT_ON_PROGRESS; |
| 2904 | else |
| 2905 | status = BTMTK_WMT_ON_UNDONE; |
| 2906 | break; |
| 2907 | } |
| 2908 | |
| 2909 | if (wmt_params->status) |
| 2910 | *wmt_params->status = status; |
| 2911 | |
| 2912 | err_free_skb: |
| 2913 | kfree_skb(data->evt_skb); |
| 2914 | data->evt_skb = NULL; |
| 2915 | |
| 2916 | return err; |
| 2917 | } |
| 2918 | |
| 2919 | static int btusb_mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) |
| 2920 | { |
| 2921 | struct btmtk_hci_wmt_params wmt_params; |
| 2922 | const struct firmware *fw; |
| 2923 | const u8 *fw_ptr; |
| 2924 | size_t fw_size; |
| 2925 | int err, dlen; |
| 2926 | u8 flag; |
| 2927 | |
| 2928 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 2929 | if (err < 0) { |
| 2930 | bt_dev_err(hdev, "Failed to load firmware file (%d)", err); |
| 2931 | return err; |
| 2932 | } |
| 2933 | |
| 2934 | fw_ptr = fw->data; |
| 2935 | fw_size = fw->size; |
| 2936 | |
| 2937 | /* The size of patch header is 30 bytes, should be skip */ |
Wei Yongjun | 5ee6310 | 2019-07-10 06:12:22 +0000 | [diff] [blame] | 2938 | if (fw_size < 30) { |
| 2939 | err = -EINVAL; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2940 | goto err_release_fw; |
Wei Yongjun | 5ee6310 | 2019-07-10 06:12:22 +0000 | [diff] [blame] | 2941 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2942 | |
| 2943 | fw_size -= 30; |
| 2944 | fw_ptr += 30; |
| 2945 | flag = 1; |
| 2946 | |
| 2947 | wmt_params.op = BTMTK_WMT_PATCH_DWNLD; |
| 2948 | wmt_params.status = NULL; |
| 2949 | |
| 2950 | while (fw_size > 0) { |
| 2951 | dlen = min_t(int, 250, fw_size); |
| 2952 | |
| 2953 | /* Tell deivice the position in sequence */ |
| 2954 | if (fw_size - dlen <= 0) |
| 2955 | flag = 3; |
| 2956 | else if (fw_size < fw->size - 30) |
| 2957 | flag = 2; |
| 2958 | |
| 2959 | wmt_params.flag = flag; |
| 2960 | wmt_params.dlen = dlen; |
| 2961 | wmt_params.data = fw_ptr; |
| 2962 | |
| 2963 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 2964 | if (err < 0) { |
| 2965 | bt_dev_err(hdev, "Failed to send wmt patch dwnld (%d)", |
| 2966 | err); |
| 2967 | goto err_release_fw; |
| 2968 | } |
| 2969 | |
| 2970 | fw_size -= dlen; |
| 2971 | fw_ptr += dlen; |
| 2972 | } |
| 2973 | |
| 2974 | wmt_params.op = BTMTK_WMT_RST; |
| 2975 | wmt_params.flag = 4; |
| 2976 | wmt_params.dlen = 0; |
| 2977 | wmt_params.data = NULL; |
| 2978 | wmt_params.status = NULL; |
| 2979 | |
| 2980 | /* Activate funciton the firmware providing to */ |
| 2981 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 2982 | if (err < 0) { |
| 2983 | bt_dev_err(hdev, "Failed to send wmt rst (%d)", err); |
Colin Ian King | 3168c19 | 2019-11-29 17:36:35 +0000 | [diff] [blame] | 2984 | goto err_release_fw; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | /* Wait a few moments for firmware activation done */ |
| 2988 | usleep_range(10000, 12000); |
| 2989 | |
| 2990 | err_release_fw: |
| 2991 | release_firmware(fw); |
| 2992 | |
| 2993 | return err; |
| 2994 | } |
| 2995 | |
| 2996 | static int btusb_mtk_func_query(struct hci_dev *hdev) |
| 2997 | { |
| 2998 | struct btmtk_hci_wmt_params wmt_params; |
| 2999 | int status, err; |
| 3000 | u8 param = 0; |
| 3001 | |
| 3002 | /* Query whether the function is enabled */ |
| 3003 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 3004 | wmt_params.flag = 4; |
| 3005 | wmt_params.dlen = sizeof(param); |
| 3006 | wmt_params.data = ¶m; |
| 3007 | wmt_params.status = &status; |
| 3008 | |
| 3009 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3010 | if (err < 0) { |
| 3011 | bt_dev_err(hdev, "Failed to query function status (%d)", err); |
| 3012 | return err; |
| 3013 | } |
| 3014 | |
| 3015 | return status; |
| 3016 | } |
| 3017 | |
| 3018 | static int btusb_mtk_reg_read(struct btusb_data *data, u32 reg, u32 *val) |
| 3019 | { |
| 3020 | int pipe, err, size = sizeof(u32); |
| 3021 | void *buf; |
| 3022 | |
| 3023 | buf = kzalloc(size, GFP_KERNEL); |
| 3024 | if (!buf) |
| 3025 | return -ENOMEM; |
| 3026 | |
| 3027 | pipe = usb_rcvctrlpipe(data->udev, 0); |
| 3028 | err = usb_control_msg(data->udev, pipe, 0x63, |
| 3029 | USB_TYPE_VENDOR | USB_DIR_IN, |
| 3030 | reg >> 16, reg & 0xffff, |
| 3031 | buf, size, USB_CTRL_SET_TIMEOUT); |
| 3032 | if (err < 0) |
| 3033 | goto err_free_buf; |
| 3034 | |
| 3035 | *val = get_unaligned_le32(buf); |
| 3036 | |
| 3037 | err_free_buf: |
| 3038 | kfree(buf); |
| 3039 | |
| 3040 | return err; |
| 3041 | } |
| 3042 | |
| 3043 | static int btusb_mtk_id_get(struct btusb_data *data, u32 *id) |
| 3044 | { |
| 3045 | return btusb_mtk_reg_read(data, 0x80000008, id); |
| 3046 | } |
| 3047 | |
| 3048 | static int btusb_mtk_setup(struct hci_dev *hdev) |
| 3049 | { |
| 3050 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3051 | struct btmtk_hci_wmt_params wmt_params; |
| 3052 | ktime_t calltime, delta, rettime; |
| 3053 | struct btmtk_tci_sleep tci_sleep; |
| 3054 | unsigned long long duration; |
| 3055 | struct sk_buff *skb; |
| 3056 | const char *fwname; |
| 3057 | int err, status; |
| 3058 | u32 dev_id; |
| 3059 | u8 param; |
| 3060 | |
| 3061 | calltime = ktime_get(); |
| 3062 | |
| 3063 | err = btusb_mtk_id_get(data, &dev_id); |
| 3064 | if (err < 0) { |
| 3065 | bt_dev_err(hdev, "Failed to get device id (%d)", err); |
| 3066 | return err; |
| 3067 | } |
| 3068 | |
| 3069 | switch (dev_id) { |
Sean Wang | 9ce67c3 | 2019-06-02 08:02:49 +0800 | [diff] [blame] | 3070 | case 0x7663: |
| 3071 | fwname = FIRMWARE_MT7663; |
| 3072 | break; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3073 | case 0x7668: |
| 3074 | fwname = FIRMWARE_MT7668; |
| 3075 | break; |
| 3076 | default: |
| 3077 | bt_dev_err(hdev, "Unsupported support hardware variant (%08x)", |
| 3078 | dev_id); |
| 3079 | return -ENODEV; |
| 3080 | } |
| 3081 | |
| 3082 | /* Query whether the firmware is already download */ |
| 3083 | wmt_params.op = BTMTK_WMT_SEMAPHORE; |
| 3084 | wmt_params.flag = 1; |
| 3085 | wmt_params.dlen = 0; |
| 3086 | wmt_params.data = NULL; |
| 3087 | wmt_params.status = &status; |
| 3088 | |
| 3089 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3090 | if (err < 0) { |
| 3091 | bt_dev_err(hdev, "Failed to query firmware status (%d)", err); |
| 3092 | return err; |
| 3093 | } |
| 3094 | |
| 3095 | if (status == BTMTK_WMT_PATCH_DONE) { |
| 3096 | bt_dev_info(hdev, "firmware already downloaded"); |
| 3097 | goto ignore_setup_fw; |
| 3098 | } |
| 3099 | |
| 3100 | /* Setup a firmware which the device definitely requires */ |
| 3101 | err = btusb_mtk_setup_firmware(hdev, fwname); |
| 3102 | if (err < 0) |
| 3103 | return err; |
| 3104 | |
| 3105 | ignore_setup_fw: |
| 3106 | err = readx_poll_timeout(btusb_mtk_func_query, hdev, status, |
| 3107 | status < 0 || status != BTMTK_WMT_ON_PROGRESS, |
| 3108 | 2000, 5000000); |
| 3109 | /* -ETIMEDOUT happens */ |
| 3110 | if (err < 0) |
| 3111 | return err; |
| 3112 | |
| 3113 | /* The other errors happen in btusb_mtk_func_query */ |
| 3114 | if (status < 0) |
| 3115 | return status; |
| 3116 | |
| 3117 | if (status == BTMTK_WMT_ON_DONE) { |
| 3118 | bt_dev_info(hdev, "function already on"); |
| 3119 | goto ignore_func_on; |
| 3120 | } |
| 3121 | |
| 3122 | /* Enable Bluetooth protocol */ |
| 3123 | param = 1; |
| 3124 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 3125 | wmt_params.flag = 0; |
| 3126 | wmt_params.dlen = sizeof(param); |
| 3127 | wmt_params.data = ¶m; |
| 3128 | wmt_params.status = NULL; |
| 3129 | |
| 3130 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3131 | if (err < 0) { |
| 3132 | bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
| 3133 | return err; |
| 3134 | } |
| 3135 | |
| 3136 | ignore_func_on: |
| 3137 | /* Apply the low power environment setup */ |
| 3138 | tci_sleep.mode = 0x5; |
| 3139 | tci_sleep.duration = cpu_to_le16(0x640); |
| 3140 | tci_sleep.host_duration = cpu_to_le16(0x640); |
| 3141 | tci_sleep.host_wakeup_pin = 0; |
| 3142 | tci_sleep.time_compensation = 0; |
| 3143 | |
| 3144 | skb = __hci_cmd_sync(hdev, 0xfc7a, sizeof(tci_sleep), &tci_sleep, |
| 3145 | HCI_INIT_TIMEOUT); |
| 3146 | if (IS_ERR(skb)) { |
| 3147 | err = PTR_ERR(skb); |
| 3148 | bt_dev_err(hdev, "Failed to apply low power setting (%d)", err); |
| 3149 | return err; |
| 3150 | } |
| 3151 | kfree_skb(skb); |
| 3152 | |
| 3153 | rettime = ktime_get(); |
| 3154 | delta = ktime_sub(rettime, calltime); |
| 3155 | duration = (unsigned long long)ktime_to_ns(delta) >> 10; |
| 3156 | |
| 3157 | bt_dev_info(hdev, "Device setup in %llu usecs", duration); |
| 3158 | |
| 3159 | return 0; |
| 3160 | } |
| 3161 | |
| 3162 | static int btusb_mtk_shutdown(struct hci_dev *hdev) |
| 3163 | { |
| 3164 | struct btmtk_hci_wmt_params wmt_params; |
| 3165 | u8 param = 0; |
| 3166 | int err; |
| 3167 | |
| 3168 | /* Disable the device */ |
| 3169 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 3170 | wmt_params.flag = 0; |
| 3171 | wmt_params.dlen = sizeof(param); |
| 3172 | wmt_params.data = ¶m; |
| 3173 | wmt_params.status = NULL; |
| 3174 | |
| 3175 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3176 | if (err < 0) { |
| 3177 | bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
| 3178 | return err; |
| 3179 | } |
| 3180 | |
| 3181 | return 0; |
| 3182 | } |
| 3183 | |
Sean Wang | 9ce67c3 | 2019-06-02 08:02:49 +0800 | [diff] [blame] | 3184 | MODULE_FIRMWARE(FIRMWARE_MT7663); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3185 | MODULE_FIRMWARE(FIRMWARE_MT7668); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3186 | |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 3187 | #ifdef CONFIG_PM |
| 3188 | /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */ |
| 3189 | static int marvell_config_oob_wake(struct hci_dev *hdev) |
| 3190 | { |
| 3191 | struct sk_buff *skb; |
| 3192 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3193 | struct device *dev = &data->udev->dev; |
| 3194 | u16 pin, gap, opcode; |
| 3195 | int ret; |
| 3196 | u8 cmd[5]; |
| 3197 | |
| 3198 | /* Move on if no wakeup pin specified */ |
| 3199 | if (of_property_read_u16(dev->of_node, "marvell,wakeup-pin", &pin) || |
| 3200 | of_property_read_u16(dev->of_node, "marvell,wakeup-gap-ms", &gap)) |
| 3201 | return 0; |
| 3202 | |
| 3203 | /* Vendor specific command to configure a GPIO as wake-up pin */ |
| 3204 | opcode = hci_opcode_pack(0x3F, 0x59); |
| 3205 | cmd[0] = opcode & 0xFF; |
| 3206 | cmd[1] = opcode >> 8; |
| 3207 | cmd[2] = 2; /* length of parameters that follow */ |
| 3208 | cmd[3] = pin; |
| 3209 | cmd[4] = gap; /* time in ms, for which wakeup pin should be asserted */ |
| 3210 | |
| 3211 | skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); |
| 3212 | if (!skb) { |
| 3213 | bt_dev_err(hdev, "%s: No memory\n", __func__); |
| 3214 | return -ENOMEM; |
| 3215 | } |
| 3216 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 3217 | skb_put_data(skb, cmd, sizeof(cmd)); |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 3218 | hci_skb_pkt_type(skb) = HCI_COMMAND_PKT; |
| 3219 | |
| 3220 | ret = btusb_send_frame(hdev, skb); |
| 3221 | if (ret) { |
| 3222 | bt_dev_err(hdev, "%s: configuration failed\n", __func__); |
| 3223 | kfree_skb(skb); |
| 3224 | return ret; |
| 3225 | } |
| 3226 | |
| 3227 | return 0; |
| 3228 | } |
| 3229 | #endif |
| 3230 | |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 3231 | static int btusb_set_bdaddr_marvell(struct hci_dev *hdev, |
| 3232 | const bdaddr_t *bdaddr) |
| 3233 | { |
| 3234 | struct sk_buff *skb; |
| 3235 | u8 buf[8]; |
| 3236 | long ret; |
| 3237 | |
| 3238 | buf[0] = 0xfe; |
| 3239 | buf[1] = sizeof(bdaddr_t); |
| 3240 | memcpy(buf + 2, bdaddr, sizeof(bdaddr_t)); |
| 3241 | |
| 3242 | skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT); |
| 3243 | if (IS_ERR(skb)) { |
| 3244 | ret = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3245 | bt_dev_err(hdev, "changing Marvell device address failed (%ld)", |
| 3246 | ret); |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 3247 | return ret; |
| 3248 | } |
| 3249 | kfree_skb(skb); |
| 3250 | |
| 3251 | return 0; |
| 3252 | } |
| 3253 | |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 3254 | static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev, |
| 3255 | const bdaddr_t *bdaddr) |
| 3256 | { |
| 3257 | struct sk_buff *skb; |
| 3258 | u8 buf[10]; |
| 3259 | long ret; |
| 3260 | |
| 3261 | buf[0] = 0x01; |
| 3262 | buf[1] = 0x01; |
| 3263 | buf[2] = 0x00; |
| 3264 | buf[3] = sizeof(bdaddr_t); |
| 3265 | memcpy(buf + 4, bdaddr, sizeof(bdaddr_t)); |
| 3266 | |
| 3267 | skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT); |
| 3268 | if (IS_ERR(skb)) { |
| 3269 | ret = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3270 | bt_dev_err(hdev, "Change address command failed (%ld)", ret); |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 3271 | return ret; |
| 3272 | } |
| 3273 | kfree_skb(skb); |
| 3274 | |
| 3275 | return 0; |
| 3276 | } |
| 3277 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3278 | #define QCA_DFU_PACKET_LEN 4096 |
| 3279 | |
| 3280 | #define QCA_GET_TARGET_VERSION 0x09 |
| 3281 | #define QCA_CHECK_STATUS 0x05 |
| 3282 | #define QCA_DFU_DOWNLOAD 0x01 |
| 3283 | |
| 3284 | #define QCA_SYSCFG_UPDATED 0x40 |
| 3285 | #define QCA_PATCH_UPDATED 0x80 |
| 3286 | #define QCA_DFU_TIMEOUT 3000 |
| 3287 | |
| 3288 | struct qca_version { |
| 3289 | __le32 rom_version; |
| 3290 | __le32 patch_version; |
| 3291 | __le32 ram_version; |
| 3292 | __le32 ref_clock; |
| 3293 | __u8 reserved[4]; |
| 3294 | } __packed; |
| 3295 | |
| 3296 | struct qca_rampatch_version { |
| 3297 | __le16 rom_version; |
| 3298 | __le16 patch_version; |
| 3299 | } __packed; |
| 3300 | |
| 3301 | struct qca_device_info { |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3302 | u32 rom_version; |
| 3303 | u8 rampatch_hdr; /* length of header in rampatch */ |
| 3304 | u8 nvm_hdr; /* length of header in NVM */ |
| 3305 | u8 ver_offset; /* offset of version structure in rampatch */ |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3306 | }; |
| 3307 | |
| 3308 | static const struct qca_device_info qca_devices_table[] = { |
| 3309 | { 0x00000100, 20, 4, 10 }, /* Rome 1.0 */ |
| 3310 | { 0x00000101, 20, 4, 10 }, /* Rome 1.1 */ |
Chan-yeol Park | 7f6e636 | 2015-05-21 11:24:27 +0900 | [diff] [blame] | 3311 | { 0x00000200, 28, 4, 18 }, /* Rome 2.0 */ |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3312 | { 0x00000201, 28, 4, 18 }, /* Rome 2.1 */ |
| 3313 | { 0x00000300, 28, 4, 18 }, /* Rome 3.0 */ |
| 3314 | { 0x00000302, 28, 4, 18 }, /* Rome 3.2 */ |
| 3315 | }; |
| 3316 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3317 | static int btusb_qca_send_vendor_req(struct usb_device *udev, u8 request, |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3318 | void *data, u16 size) |
| 3319 | { |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3320 | int pipe, err; |
| 3321 | u8 *buf; |
| 3322 | |
| 3323 | buf = kmalloc(size, GFP_KERNEL); |
| 3324 | if (!buf) |
| 3325 | return -ENOMEM; |
| 3326 | |
| 3327 | /* Found some of USB hosts have IOT issues with ours so that we should |
| 3328 | * not wait until HCI layer is ready. |
| 3329 | */ |
| 3330 | pipe = usb_rcvctrlpipe(udev, 0); |
| 3331 | err = usb_control_msg(udev, pipe, request, USB_TYPE_VENDOR | USB_DIR_IN, |
| 3332 | 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); |
| 3333 | if (err < 0) { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3334 | dev_err(&udev->dev, "Failed to access otp area (%d)", err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3335 | goto done; |
| 3336 | } |
| 3337 | |
| 3338 | memcpy(data, buf, size); |
| 3339 | |
| 3340 | done: |
| 3341 | kfree(buf); |
| 3342 | |
| 3343 | return err; |
| 3344 | } |
| 3345 | |
| 3346 | static int btusb_setup_qca_download_fw(struct hci_dev *hdev, |
| 3347 | const struct firmware *firmware, |
| 3348 | size_t hdr_size) |
| 3349 | { |
| 3350 | struct btusb_data *btdata = hci_get_drvdata(hdev); |
| 3351 | struct usb_device *udev = btdata->udev; |
| 3352 | size_t count, size, sent = 0; |
| 3353 | int pipe, len, err; |
| 3354 | u8 *buf; |
| 3355 | |
| 3356 | buf = kmalloc(QCA_DFU_PACKET_LEN, GFP_KERNEL); |
| 3357 | if (!buf) |
| 3358 | return -ENOMEM; |
| 3359 | |
| 3360 | count = firmware->size; |
| 3361 | |
| 3362 | size = min_t(size_t, count, hdr_size); |
| 3363 | memcpy(buf, firmware->data, size); |
| 3364 | |
| 3365 | /* USB patches should go down to controller through USB path |
| 3366 | * because binary format fits to go down through USB channel. |
| 3367 | * USB control path is for patching headers and USB bulk is for |
| 3368 | * patch body. |
| 3369 | */ |
| 3370 | pipe = usb_sndctrlpipe(udev, 0); |
| 3371 | err = usb_control_msg(udev, pipe, QCA_DFU_DOWNLOAD, USB_TYPE_VENDOR, |
| 3372 | 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); |
| 3373 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3374 | bt_dev_err(hdev, "Failed to send headers (%d)", err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3375 | goto done; |
| 3376 | } |
| 3377 | |
| 3378 | sent += size; |
| 3379 | count -= size; |
| 3380 | |
| 3381 | while (count) { |
| 3382 | size = min_t(size_t, count, QCA_DFU_PACKET_LEN); |
| 3383 | |
| 3384 | memcpy(buf, firmware->data + sent, size); |
| 3385 | |
| 3386 | pipe = usb_sndbulkpipe(udev, 0x02); |
| 3387 | err = usb_bulk_msg(udev, pipe, buf, size, &len, |
| 3388 | QCA_DFU_TIMEOUT); |
| 3389 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3390 | bt_dev_err(hdev, "Failed to send body at %zd of %zd (%d)", |
| 3391 | sent, firmware->size, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3392 | break; |
| 3393 | } |
| 3394 | |
| 3395 | if (size != len) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3396 | bt_dev_err(hdev, "Failed to get bulk buffer"); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3397 | err = -EILSEQ; |
| 3398 | break; |
| 3399 | } |
| 3400 | |
| 3401 | sent += size; |
| 3402 | count -= size; |
| 3403 | } |
| 3404 | |
| 3405 | done: |
| 3406 | kfree(buf); |
| 3407 | return err; |
| 3408 | } |
| 3409 | |
| 3410 | static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev, |
| 3411 | struct qca_version *ver, |
| 3412 | const struct qca_device_info *info) |
| 3413 | { |
| 3414 | struct qca_rampatch_version *rver; |
| 3415 | const struct firmware *fw; |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3416 | u32 ver_rom, ver_patch; |
| 3417 | u16 rver_rom, rver_patch; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3418 | char fwname[64]; |
| 3419 | int err; |
| 3420 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3421 | ver_rom = le32_to_cpu(ver->rom_version); |
| 3422 | ver_patch = le32_to_cpu(ver->patch_version); |
| 3423 | |
| 3424 | snprintf(fwname, sizeof(fwname), "qca/rampatch_usb_%08x.bin", ver_rom); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3425 | |
| 3426 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 3427 | if (err) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3428 | bt_dev_err(hdev, "failed to request rampatch file: %s (%d)", |
| 3429 | fwname, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3430 | return err; |
| 3431 | } |
| 3432 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3433 | bt_dev_info(hdev, "using rampatch file: %s", fwname); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3434 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3435 | rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset); |
| 3436 | rver_rom = le16_to_cpu(rver->rom_version); |
| 3437 | rver_patch = le16_to_cpu(rver->patch_version); |
| 3438 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3439 | bt_dev_info(hdev, "QCA: patch rome 0x%x build 0x%x, " |
| 3440 | "firmware rome 0x%x build 0x%x", |
| 3441 | rver_rom, rver_patch, ver_rom, ver_patch); |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3442 | |
| 3443 | if (rver_rom != ver_rom || rver_patch <= ver_patch) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3444 | bt_dev_err(hdev, "rampatch file version did not match with firmware"); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3445 | err = -EINVAL; |
| 3446 | goto done; |
| 3447 | } |
| 3448 | |
| 3449 | err = btusb_setup_qca_download_fw(hdev, fw, info->rampatch_hdr); |
| 3450 | |
| 3451 | done: |
| 3452 | release_firmware(fw); |
| 3453 | |
| 3454 | return err; |
| 3455 | } |
| 3456 | |
| 3457 | static int btusb_setup_qca_load_nvm(struct hci_dev *hdev, |
| 3458 | struct qca_version *ver, |
| 3459 | const struct qca_device_info *info) |
| 3460 | { |
| 3461 | const struct firmware *fw; |
| 3462 | char fwname[64]; |
| 3463 | int err; |
| 3464 | |
| 3465 | snprintf(fwname, sizeof(fwname), "qca/nvm_usb_%08x.bin", |
| 3466 | le32_to_cpu(ver->rom_version)); |
| 3467 | |
| 3468 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 3469 | if (err) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3470 | bt_dev_err(hdev, "failed to request NVM file: %s (%d)", |
| 3471 | fwname, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3472 | return err; |
| 3473 | } |
| 3474 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3475 | bt_dev_info(hdev, "using NVM file: %s", fwname); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3476 | |
| 3477 | err = btusb_setup_qca_download_fw(hdev, fw, info->nvm_hdr); |
| 3478 | |
| 3479 | release_firmware(fw); |
| 3480 | |
| 3481 | return err; |
| 3482 | } |
| 3483 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3484 | /* identify the ROM version and check whether patches are needed */ |
| 3485 | static bool btusb_qca_need_patch(struct usb_device *udev) |
| 3486 | { |
| 3487 | struct qca_version ver; |
| 3488 | |
| 3489 | if (btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, |
| 3490 | sizeof(ver)) < 0) |
| 3491 | return false; |
| 3492 | /* only low ROM versions need patches */ |
| 3493 | return !(le32_to_cpu(ver.rom_version) & ~0xffffU); |
| 3494 | } |
| 3495 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3496 | static int btusb_setup_qca(struct hci_dev *hdev) |
| 3497 | { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3498 | struct btusb_data *btdata = hci_get_drvdata(hdev); |
| 3499 | struct usb_device *udev = btdata->udev; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3500 | const struct qca_device_info *info = NULL; |
| 3501 | struct qca_version ver; |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3502 | u32 ver_rom; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3503 | u8 status; |
| 3504 | int i, err; |
| 3505 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3506 | err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, |
Marcel Holtmann | eb50042 | 2015-04-16 23:15:50 +0200 | [diff] [blame] | 3507 | sizeof(ver)); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3508 | if (err < 0) |
| 3509 | return err; |
| 3510 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3511 | ver_rom = le32_to_cpu(ver.rom_version); |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3512 | /* Don't care about high ROM versions */ |
| 3513 | if (ver_rom & ~0xffffU) |
| 3514 | return 0; |
| 3515 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3516 | for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) { |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3517 | if (ver_rom == qca_devices_table[i].rom_version) |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3518 | info = &qca_devices_table[i]; |
| 3519 | } |
| 3520 | if (!info) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3521 | bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3522 | return -ENODEV; |
| 3523 | } |
| 3524 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3525 | err = btusb_qca_send_vendor_req(udev, QCA_CHECK_STATUS, &status, |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3526 | sizeof(status)); |
| 3527 | if (err < 0) |
| 3528 | return err; |
| 3529 | |
| 3530 | if (!(status & QCA_PATCH_UPDATED)) { |
| 3531 | err = btusb_setup_qca_load_rampatch(hdev, &ver, info); |
| 3532 | if (err < 0) |
| 3533 | return err; |
| 3534 | } |
| 3535 | |
| 3536 | if (!(status & QCA_SYSCFG_UPDATED)) { |
| 3537 | err = btusb_setup_qca_load_nvm(hdev, &ver, info); |
| 3538 | if (err < 0) |
| 3539 | return err; |
| 3540 | } |
| 3541 | |
| 3542 | return 0; |
| 3543 | } |
| 3544 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3545 | static inline int __set_diag_interface(struct hci_dev *hdev) |
| 3546 | { |
| 3547 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3548 | struct usb_interface *intf = data->diag; |
| 3549 | int i; |
| 3550 | |
| 3551 | if (!data->diag) |
| 3552 | return -ENODEV; |
| 3553 | |
| 3554 | data->diag_tx_ep = NULL; |
| 3555 | data->diag_rx_ep = NULL; |
| 3556 | |
| 3557 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 3558 | struct usb_endpoint_descriptor *ep_desc; |
| 3559 | |
| 3560 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 3561 | |
| 3562 | if (!data->diag_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { |
| 3563 | data->diag_tx_ep = ep_desc; |
| 3564 | continue; |
| 3565 | } |
| 3566 | |
| 3567 | if (!data->diag_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { |
| 3568 | data->diag_rx_ep = ep_desc; |
| 3569 | continue; |
| 3570 | } |
| 3571 | } |
| 3572 | |
| 3573 | if (!data->diag_tx_ep || !data->diag_rx_ep) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3574 | bt_dev_err(hdev, "invalid diagnostic descriptors"); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3575 | return -ENODEV; |
| 3576 | } |
| 3577 | |
| 3578 | return 0; |
| 3579 | } |
| 3580 | |
| 3581 | static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable) |
| 3582 | { |
| 3583 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3584 | struct sk_buff *skb; |
| 3585 | struct urb *urb; |
| 3586 | unsigned int pipe; |
| 3587 | |
| 3588 | if (!data->diag_tx_ep) |
| 3589 | return ERR_PTR(-ENODEV); |
| 3590 | |
| 3591 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 3592 | if (!urb) |
| 3593 | return ERR_PTR(-ENOMEM); |
| 3594 | |
| 3595 | skb = bt_skb_alloc(2, GFP_KERNEL); |
| 3596 | if (!skb) { |
| 3597 | usb_free_urb(urb); |
| 3598 | return ERR_PTR(-ENOMEM); |
| 3599 | } |
| 3600 | |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 3601 | skb_put_u8(skb, 0xf0); |
| 3602 | skb_put_u8(skb, enable); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3603 | |
| 3604 | pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress); |
| 3605 | |
| 3606 | usb_fill_bulk_urb(urb, data->udev, pipe, |
| 3607 | skb->data, skb->len, btusb_tx_complete, skb); |
| 3608 | |
| 3609 | skb->dev = (void *)hdev; |
| 3610 | |
| 3611 | return urb; |
| 3612 | } |
| 3613 | |
| 3614 | static int btusb_bcm_set_diag(struct hci_dev *hdev, bool enable) |
| 3615 | { |
| 3616 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3617 | struct urb *urb; |
| 3618 | |
| 3619 | if (!data->diag) |
| 3620 | return -ENODEV; |
| 3621 | |
| 3622 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 3623 | return -ENETDOWN; |
| 3624 | |
| 3625 | urb = alloc_diag_urb(hdev, enable); |
| 3626 | if (IS_ERR(urb)) |
| 3627 | return PTR_ERR(urb); |
| 3628 | |
| 3629 | return submit_or_queue_tx_urb(hdev, urb); |
| 3630 | } |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3631 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3632 | #ifdef CONFIG_PM |
| 3633 | static irqreturn_t btusb_oob_wake_handler(int irq, void *priv) |
| 3634 | { |
| 3635 | struct btusb_data *data = priv; |
| 3636 | |
| 3637 | pm_wakeup_event(&data->udev->dev, 0); |
Jeffy Chen | 017789f | 2017-02-24 14:24:29 +0800 | [diff] [blame] | 3638 | pm_system_wakeup(); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3639 | |
| 3640 | /* Disable only if not already disabled (keep it balanced) */ |
| 3641 | if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) { |
| 3642 | disable_irq_nosync(irq); |
| 3643 | disable_irq_wake(irq); |
| 3644 | } |
| 3645 | return IRQ_HANDLED; |
| 3646 | } |
| 3647 | |
| 3648 | static const struct of_device_id btusb_match_table[] = { |
| 3649 | { .compatible = "usb1286,204e" }, |
Brian Norris | 4c409af | 2019-02-22 14:53:43 -0800 | [diff] [blame] | 3650 | { .compatible = "usbcf3,e300" }, /* QCA6174A */ |
| 3651 | { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */ |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3652 | { } |
| 3653 | }; |
| 3654 | MODULE_DEVICE_TABLE(of, btusb_match_table); |
| 3655 | |
| 3656 | /* Use an oob wakeup pin? */ |
| 3657 | static int btusb_config_oob_wake(struct hci_dev *hdev) |
| 3658 | { |
| 3659 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3660 | struct device *dev = &data->udev->dev; |
| 3661 | int irq, ret; |
| 3662 | |
| 3663 | clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags); |
| 3664 | |
| 3665 | if (!of_match_device(btusb_match_table, dev)) |
| 3666 | return 0; |
| 3667 | |
| 3668 | /* Move on if no IRQ specified */ |
| 3669 | irq = of_irq_get_byname(dev->of_node, "wakeup"); |
| 3670 | if (irq <= 0) { |
| 3671 | bt_dev_dbg(hdev, "%s: no OOB Wakeup IRQ in DT", __func__); |
| 3672 | return 0; |
| 3673 | } |
| 3674 | |
Brian Norris | 771acc7 | 2019-04-09 11:49:17 -0700 | [diff] [blame] | 3675 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3676 | ret = devm_request_irq(&hdev->dev, irq, btusb_oob_wake_handler, |
| 3677 | 0, "OOB Wake-on-BT", data); |
| 3678 | if (ret) { |
| 3679 | bt_dev_err(hdev, "%s: IRQ request failed", __func__); |
| 3680 | return ret; |
| 3681 | } |
| 3682 | |
| 3683 | ret = device_init_wakeup(dev, true); |
| 3684 | if (ret) { |
| 3685 | bt_dev_err(hdev, "%s: failed to init_wakeup", __func__); |
| 3686 | return ret; |
| 3687 | } |
| 3688 | |
| 3689 | data->oob_wake_irq = irq; |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3690 | bt_dev_info(hdev, "OOB Wake-on-BT configured at IRQ %u", irq); |
| 3691 | return 0; |
| 3692 | } |
| 3693 | #endif |
| 3694 | |
Hans de Goede | fc54910 | 2018-04-27 11:26:43 +0200 | [diff] [blame] | 3695 | static void btusb_check_needs_reset_resume(struct usb_interface *intf) |
| 3696 | { |
| 3697 | if (dmi_check_system(btusb_needs_reset_resume_table)) |
| 3698 | interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; |
| 3699 | } |
| 3700 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3701 | static int btusb_probe(struct usb_interface *intf, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 3702 | const struct usb_device_id *id) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3703 | { |
| 3704 | struct usb_endpoint_descriptor *ep_desc; |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3705 | struct gpio_desc *reset_gpio; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3706 | struct btusb_data *data; |
| 3707 | struct hci_dev *hdev; |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3708 | unsigned ifnum_base; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3709 | int i, err; |
| 3710 | |
| 3711 | BT_DBG("intf %p id %p", intf, id); |
| 3712 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3713 | /* interface numbers are hardcoded in the spec */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3714 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) { |
| 3715 | if (!(id->driver_info & BTUSB_IFNUM_2)) |
| 3716 | return -ENODEV; |
| 3717 | if (intf->cur_altsetting->desc.bInterfaceNumber != 2) |
| 3718 | return -ENODEV; |
| 3719 | } |
| 3720 | |
| 3721 | ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3722 | |
| 3723 | if (!id->driver_info) { |
| 3724 | const struct usb_device_id *match; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 3725 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3726 | match = usb_match_id(intf, blacklist_table); |
| 3727 | if (match) |
| 3728 | id = match; |
| 3729 | } |
| 3730 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3731 | if (id->driver_info == BTUSB_IGNORE) |
| 3732 | return -ENODEV; |
| 3733 | |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 3734 | if (id->driver_info & BTUSB_ATH3012) { |
| 3735 | struct usb_device *udev = interface_to_usbdev(intf); |
| 3736 | |
| 3737 | /* Old firmware would otherwise let ath3k driver load |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 3738 | * patch and sysconfig files |
| 3739 | */ |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3740 | if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 && |
| 3741 | !btusb_qca_need_patch(udev)) |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 3742 | return -ENODEV; |
| 3743 | } |
| 3744 | |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 3745 | data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3746 | if (!data) |
| 3747 | return -ENOMEM; |
| 3748 | |
| 3749 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 3750 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 3751 | |
| 3752 | if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) { |
| 3753 | data->intr_ep = ep_desc; |
| 3754 | continue; |
| 3755 | } |
| 3756 | |
| 3757 | if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { |
| 3758 | data->bulk_tx_ep = ep_desc; |
| 3759 | continue; |
| 3760 | } |
| 3761 | |
| 3762 | if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { |
| 3763 | data->bulk_rx_ep = ep_desc; |
| 3764 | continue; |
| 3765 | } |
| 3766 | } |
| 3767 | |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 3768 | if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3769 | return -ENODEV; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3770 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 3771 | if (id->driver_info & BTUSB_AMP) { |
| 3772 | data->cmdreq_type = USB_TYPE_CLASS | 0x01; |
| 3773 | data->cmdreq = 0x2b; |
| 3774 | } else { |
| 3775 | data->cmdreq_type = USB_TYPE_CLASS; |
| 3776 | data->cmdreq = 0x00; |
| 3777 | } |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3778 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3779 | data->udev = interface_to_usbdev(intf); |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 3780 | data->intf = intf; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3781 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3782 | INIT_WORK(&data->work, btusb_work); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 3783 | INIT_WORK(&data->waker, btusb_waker); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 3784 | init_usb_anchor(&data->deferred); |
| 3785 | init_usb_anchor(&data->tx_anchor); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 3786 | spin_lock_init(&data->txlock); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3787 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3788 | init_usb_anchor(&data->intr_anchor); |
| 3789 | init_usb_anchor(&data->bulk_anchor); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 3790 | init_usb_anchor(&data->isoc_anchor); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3791 | init_usb_anchor(&data->diag_anchor); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3792 | init_usb_anchor(&data->ctrl_anchor); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 3793 | spin_lock_init(&data->rxlock); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3794 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 3795 | if (id->driver_info & BTUSB_INTEL_NEW) { |
| 3796 | data->recv_event = btusb_recv_event_intel; |
| 3797 | data->recv_bulk = btusb_recv_bulk_intel; |
| 3798 | set_bit(BTUSB_BOOTLOADER, &data->flags); |
| 3799 | } else { |
| 3800 | data->recv_event = hci_recv_frame; |
| 3801 | data->recv_bulk = btusb_recv_bulk; |
| 3802 | } |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 3803 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3804 | hdev = hci_alloc_dev(); |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 3805 | if (!hdev) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3806 | return -ENOMEM; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3807 | |
Marcel Holtmann | c13854c | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 3808 | hdev->bus = HCI_USB; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 3809 | hci_set_drvdata(hdev, data); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3810 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 3811 | if (id->driver_info & BTUSB_AMP) |
| 3812 | hdev->dev_type = HCI_AMP; |
| 3813 | else |
Marcel Holtmann | ca8bee5 | 2016-07-05 14:30:14 +0200 | [diff] [blame] | 3814 | hdev->dev_type = HCI_PRIMARY; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 3815 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3816 | data->hdev = hdev; |
| 3817 | |
| 3818 | SET_HCIDEV_DEV(hdev, &intf->dev); |
| 3819 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3820 | reset_gpio = gpiod_get_optional(&data->udev->dev, "reset", |
| 3821 | GPIOD_OUT_LOW); |
| 3822 | if (IS_ERR(reset_gpio)) { |
| 3823 | err = PTR_ERR(reset_gpio); |
| 3824 | goto out_free_dev; |
| 3825 | } else if (reset_gpio) { |
| 3826 | data->reset_gpio = reset_gpio; |
| 3827 | } |
| 3828 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 3829 | hdev->open = btusb_open; |
| 3830 | hdev->close = btusb_close; |
| 3831 | hdev->flush = btusb_flush; |
| 3832 | hdev->send = btusb_send_frame; |
| 3833 | hdev->notify = btusb_notify; |
| 3834 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3835 | #ifdef CONFIG_PM |
| 3836 | err = btusb_config_oob_wake(hdev); |
| 3837 | if (err) |
| 3838 | goto out_free_dev; |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 3839 | |
| 3840 | /* Marvell devices may need a specific chip configuration */ |
| 3841 | if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) { |
| 3842 | err = marvell_config_oob_wake(hdev); |
| 3843 | if (err) |
| 3844 | goto out_free_dev; |
| 3845 | } |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3846 | #endif |
Szymon Janc | 418678b | 2016-09-01 17:22:37 +0200 | [diff] [blame] | 3847 | if (id->driver_info & BTUSB_CW6622) |
| 3848 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
| 3849 | |
Marcel Holtmann | 6c9d435 | 2015-10-17 14:39:27 +0200 | [diff] [blame] | 3850 | if (id->driver_info & BTUSB_BCM2045) |
| 3851 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
| 3852 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 3853 | if (id->driver_info & BTUSB_BCM92035) |
| 3854 | hdev->setup = btusb_setup_bcm92035; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3855 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 3856 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && |
| 3857 | (id->driver_info & BTUSB_BCM_PATCHRAM)) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 3858 | hdev->manufacturer = 15; |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 3859 | hdev->setup = btbcm_setup_patchram; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3860 | hdev->set_diag = btusb_bcm_set_diag; |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 3861 | hdev->set_bdaddr = btbcm_set_bdaddr; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3862 | |
| 3863 | /* Broadcom LM_DIAG Interface numbers are hardcoded */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3864 | data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); |
Marcel Holtmann | abbaf50 | 2014-07-02 00:53:48 +0200 | [diff] [blame] | 3865 | } |
Petri Gynther | 10d4c67 | 2014-05-08 15:50:01 -0700 | [diff] [blame] | 3866 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 3867 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && |
| 3868 | (id->driver_info & BTUSB_BCM_APPLE)) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 3869 | hdev->manufacturer = 15; |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 3870 | hdev->setup = btbcm_setup_apple; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3871 | hdev->set_diag = btusb_bcm_set_diag; |
| 3872 | |
| 3873 | /* Broadcom LM_DIAG Interface numbers are hardcoded */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3874 | data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3875 | } |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 3876 | |
Marcel Holtmann | cb8d659 | 2014-07-02 11:25:25 +0200 | [diff] [blame] | 3877 | if (id->driver_info & BTUSB_INTEL) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 3878 | hdev->manufacturer = 2; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 3879 | hdev->setup = btusb_setup_intel; |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 3880 | hdev->shutdown = btusb_shutdown_intel; |
Marcel Holtmann | 3e24767 | 2015-10-17 16:00:28 +0200 | [diff] [blame] | 3881 | hdev->set_diag = btintel_set_diag_mfg; |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 3882 | hdev->set_bdaddr = btintel_set_bdaddr; |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3883 | hdev->cmd_timeout = btusb_intel_cmd_timeout; |
Jakub Pawlowski | c33fb9b | 2015-01-30 18:55:58 -0800 | [diff] [blame] | 3884 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
Jakub Pawlowski | c115484 | 2015-03-17 09:04:16 -0700 | [diff] [blame] | 3885 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Marcel Holtmann | 3e24767 | 2015-10-17 16:00:28 +0200 | [diff] [blame] | 3886 | set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); |
Marcel Holtmann | cb8d659 | 2014-07-02 11:25:25 +0200 | [diff] [blame] | 3887 | } |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 3888 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 3889 | if (id->driver_info & BTUSB_INTEL_NEW) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 3890 | hdev->manufacturer = 2; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 3891 | hdev->send = btusb_send_frame_intel; |
| 3892 | hdev->setup = btusb_setup_intel_new; |
Raghuram Hegde | 017a01c | 2019-01-29 17:54:48 +0530 | [diff] [blame] | 3893 | hdev->shutdown = btusb_shutdown_intel_new; |
Marcel Holtmann | eeb6abe | 2015-07-05 14:37:39 +0200 | [diff] [blame] | 3894 | hdev->hw_error = btintel_hw_error; |
Marcel Holtmann | 6d2e50d | 2015-10-09 14:42:08 +0200 | [diff] [blame] | 3895 | hdev->set_diag = btintel_set_diag; |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 3896 | hdev->set_bdaddr = btintel_set_bdaddr; |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3897 | hdev->cmd_timeout = btusb_intel_cmd_timeout; |
Marcel Holtmann | b970c5b | 2015-02-01 23:57:18 -0800 | [diff] [blame] | 3898 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
Justin TerAvest | f778502 | 2018-09-25 11:04:57 -0600 | [diff] [blame] | 3899 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Marcel Holtmann | d8270fb | 2015-10-17 16:00:27 +0200 | [diff] [blame] | 3900 | set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 3901 | } |
| 3902 | |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 3903 | if (id->driver_info & BTUSB_MARVELL) |
| 3904 | hdev->set_bdaddr = btusb_set_bdaddr_marvell; |
| 3905 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 3906 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) && |
| 3907 | (id->driver_info & BTUSB_MEDIATEK)) { |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3908 | hdev->setup = btusb_mtk_setup; |
| 3909 | hdev->shutdown = btusb_mtk_shutdown; |
| 3910 | hdev->manufacturer = 70; |
| 3911 | set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); |
| 3912 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3913 | |
Marcel Holtmann | 661cf88 | 2015-01-02 23:35:20 -0800 | [diff] [blame] | 3914 | if (id->driver_info & BTUSB_SWAVE) { |
| 3915 | set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks); |
Marcel Holtmann | d57dbe7 | 2014-12-26 04:42:33 +0100 | [diff] [blame] | 3916 | set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks); |
Marcel Holtmann | 661cf88 | 2015-01-02 23:35:20 -0800 | [diff] [blame] | 3917 | } |
Marcel Holtmann | d57dbe7 | 2014-12-26 04:42:33 +0100 | [diff] [blame] | 3918 | |
Marcel Holtmann | e4c534b | 2015-10-21 01:31:45 +0200 | [diff] [blame] | 3919 | if (id->driver_info & BTUSB_INTEL_BOOT) { |
| 3920 | hdev->manufacturer = 2; |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 3921 | set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); |
Marcel Holtmann | e4c534b | 2015-10-21 01:31:45 +0200 | [diff] [blame] | 3922 | } |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 3923 | |
Jakub Pawlowski | 79f0c87 | 2015-01-29 10:38:34 -0800 | [diff] [blame] | 3924 | if (id->driver_info & BTUSB_ATH3012) { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3925 | data->setup_on_usb = btusb_setup_qca; |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 3926 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
Jakub Pawlowski | 3d50d51 | 2015-03-17 09:04:15 -0700 | [diff] [blame] | 3927 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Jakub Pawlowski | 79f0c87 | 2015-01-29 10:38:34 -0800 | [diff] [blame] | 3928 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
| 3929 | } |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 3930 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3931 | if (id->driver_info & BTUSB_QCA_ROME) { |
| 3932 | data->setup_on_usb = btusb_setup_qca; |
| 3933 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
Vic Wei | 96e58d3 | 2018-03-28 08:28:47 -0700 | [diff] [blame] | 3934 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Hans de Goede | fc54910 | 2018-04-27 11:26:43 +0200 | [diff] [blame] | 3935 | btusb_check_needs_reset_resume(intf); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3936 | } |
| 3937 | |
Arnd Bergmann | 42d2209 | 2019-09-18 21:59:02 +0200 | [diff] [blame] | 3938 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) && |
| 3939 | (id->driver_info & BTUSB_REALTEK)) { |
Carlo Caione | db33c77 | 2015-05-14 10:49:09 +0200 | [diff] [blame] | 3940 | hdev->setup = btrtl_setup_realtek; |
Jian-Hong Pan | 7af3f558 | 2019-06-25 16:30:51 +0800 | [diff] [blame] | 3941 | hdev->shutdown = btrtl_shutdown_realtek; |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 3942 | hdev->cmd_timeout = btusb_rtl_cmd_timeout; |
Daniel Drake | 04b8c81 | 2015-05-21 08:23:50 -0600 | [diff] [blame] | 3943 | |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 3944 | /* Realtek devices lose their updated firmware over global |
| 3945 | * suspend that means host doesn't send SET_FEATURE |
| 3946 | * (DEVICE_REMOTE_WAKEUP) |
Daniel Drake | 04b8c81 | 2015-05-21 08:23:50 -0600 | [diff] [blame] | 3947 | */ |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 3948 | set_bit(BTUSB_WAKEUP_DISABLE, &data->flags); |
Kai-Heng Feng | 7ecacaf | 2019-12-05 17:07:01 +0800 | [diff] [blame] | 3949 | |
| 3950 | err = usb_autopm_get_interface(intf); |
| 3951 | if (err < 0) |
| 3952 | goto out_free_dev; |
Daniel Drake | 04b8c81 | 2015-05-21 08:23:50 -0600 | [diff] [blame] | 3953 | } |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 3954 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 3955 | if (id->driver_info & BTUSB_AMP) { |
| 3956 | /* AMP controllers do not support SCO packets */ |
| 3957 | data->isoc = NULL; |
| 3958 | } else { |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3959 | /* Interface orders are hardcoded in the specification */ |
| 3960 | data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); |
Marcel Holtmann | 459232f | 2017-10-24 19:42:45 +0200 | [diff] [blame] | 3961 | data->isoc_ifnum = ifnum_base + 1; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 3962 | } |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 3963 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3964 | if (!reset) |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 3965 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3966 | |
| 3967 | if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { |
| 3968 | if (!disable_scofix) |
| 3969 | set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks); |
| 3970 | } |
| 3971 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 3972 | if (id->driver_info & BTUSB_BROKEN_ISOC) |
| 3973 | data->isoc = NULL; |
| 3974 | |
Alain Michaud | 4b127bd | 2020-02-27 18:29:39 +0000 | [diff] [blame] | 3975 | if (id->driver_info & BTUSB_WIDEBAND_SPEECH) |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 3976 | set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks); |
Alain Michaud | 4b127bd | 2020-02-27 18:29:39 +0000 | [diff] [blame] | 3977 | |
Alain Michaud | aff8c48 | 2020-04-23 14:43:31 +0000 | [diff] [blame^] | 3978 | if (id->driver_info & BTUSB_VALID_LE_STATES) |
| 3979 | set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks); |
| 3980 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3981 | if (id->driver_info & BTUSB_DIGIANSWER) { |
| 3982 | data->cmdreq_type = USB_TYPE_VENDOR; |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 3983 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | if (id->driver_info & BTUSB_CSR) { |
| 3987 | struct usb_device *udev = data->udev; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 3988 | u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3989 | |
| 3990 | /* Old firmware would otherwise execute USB reset */ |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 3991 | if (bcdDevice < 0x117) |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 3992 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 3993 | |
| 3994 | /* Fake CSR devices with broken commands */ |
Johan Hedberg | 6cafcd9 | 2015-08-30 21:47:21 +0300 | [diff] [blame] | 3995 | if (bcdDevice <= 0x100 || bcdDevice == 0x134) |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 3996 | hdev->setup = btusb_setup_csr; |
Jakub Pawlowski | 49c989a | 2015-03-17 09:04:17 -0700 | [diff] [blame] | 3997 | |
| 3998 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3999 | } |
| 4000 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4001 | if (id->driver_info & BTUSB_SNIFFER) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 4002 | struct usb_device *udev = data->udev; |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4003 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 4004 | /* New sniffer firmware has crippled HCI interface */ |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4005 | if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) |
| 4006 | set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); |
| 4007 | } |
| 4008 | |
Marcel Holtmann | 3a5ef20 | 2014-07-06 14:53:54 +0200 | [diff] [blame] | 4009 | if (id->driver_info & BTUSB_INTEL_BOOT) { |
| 4010 | /* A bug in the bootloader causes that interrupt interface is |
| 4011 | * only enabled after receiving SetInterface(0, AltSetting=0). |
| 4012 | */ |
| 4013 | err = usb_set_interface(data->udev, 0, 0); |
| 4014 | if (err < 0) { |
| 4015 | BT_ERR("failed to set interface 0, alt 0 %d", err); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4016 | goto out_free_dev; |
Marcel Holtmann | 3a5ef20 | 2014-07-06 14:53:54 +0200 | [diff] [blame] | 4017 | } |
| 4018 | } |
| 4019 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 4020 | if (data->isoc) { |
| 4021 | err = usb_driver_claim_interface(&btusb_driver, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 4022 | data->isoc, data); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4023 | if (err < 0) |
| 4024 | goto out_free_dev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 4025 | } |
| 4026 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 4027 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) { |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4028 | if (!usb_driver_claim_interface(&btusb_driver, |
| 4029 | data->diag, data)) |
| 4030 | __set_diag_interface(hdev); |
| 4031 | else |
| 4032 | data->diag = NULL; |
| 4033 | } |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4034 | |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 4035 | if (enable_autosuspend) |
| 4036 | usb_enable_autosuspend(data->udev); |
| 4037 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4038 | err = hci_register_dev(hdev); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4039 | if (err < 0) |
| 4040 | goto out_free_dev; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4041 | |
| 4042 | usb_set_intfdata(intf, data); |
| 4043 | |
| 4044 | return 0; |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4045 | |
| 4046 | out_free_dev: |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 4047 | if (data->reset_gpio) |
| 4048 | gpiod_put(data->reset_gpio); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4049 | hci_free_dev(hdev); |
| 4050 | return err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | static void btusb_disconnect(struct usb_interface *intf) |
| 4054 | { |
| 4055 | struct btusb_data *data = usb_get_intfdata(intf); |
| 4056 | struct hci_dev *hdev; |
| 4057 | |
| 4058 | BT_DBG("intf %p", intf); |
| 4059 | |
| 4060 | if (!data) |
| 4061 | return; |
| 4062 | |
| 4063 | hdev = data->hdev; |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 4064 | usb_set_intfdata(data->intf, NULL); |
| 4065 | |
| 4066 | if (data->isoc) |
| 4067 | usb_set_intfdata(data->isoc, NULL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4068 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4069 | if (data->diag) |
| 4070 | usb_set_intfdata(data->diag, NULL); |
| 4071 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4072 | hci_unregister_dev(hdev); |
| 4073 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4074 | if (intf == data->intf) { |
| 4075 | if (data->isoc) |
| 4076 | usb_driver_release_interface(&btusb_driver, data->isoc); |
| 4077 | if (data->diag) |
| 4078 | usb_driver_release_interface(&btusb_driver, data->diag); |
| 4079 | } else if (intf == data->isoc) { |
| 4080 | if (data->diag) |
| 4081 | usb_driver_release_interface(&btusb_driver, data->diag); |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 4082 | usb_driver_release_interface(&btusb_driver, data->intf); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4083 | } else if (intf == data->diag) { |
| 4084 | usb_driver_release_interface(&btusb_driver, data->intf); |
| 4085 | if (data->isoc) |
| 4086 | usb_driver_release_interface(&btusb_driver, data->isoc); |
| 4087 | } |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 4088 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4089 | if (data->oob_wake_irq) |
| 4090 | device_init_wakeup(&data->udev->dev, false); |
| 4091 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 4092 | if (data->reset_gpio) |
| 4093 | gpiod_put(data->reset_gpio); |
| 4094 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4095 | hci_free_dev(hdev); |
| 4096 | } |
| 4097 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4098 | #ifdef CONFIG_PM |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4099 | static int btusb_suspend(struct usb_interface *intf, pm_message_t message) |
| 4100 | { |
| 4101 | struct btusb_data *data = usb_get_intfdata(intf); |
| 4102 | |
| 4103 | BT_DBG("intf %p", intf); |
| 4104 | |
| 4105 | if (data->suspend_count++) |
| 4106 | return 0; |
| 4107 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4108 | spin_lock_irq(&data->txlock); |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 4109 | if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) { |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4110 | set_bit(BTUSB_SUSPENDING, &data->flags); |
| 4111 | spin_unlock_irq(&data->txlock); |
| 4112 | } else { |
| 4113 | spin_unlock_irq(&data->txlock); |
| 4114 | data->suspend_count--; |
| 4115 | return -EBUSY; |
| 4116 | } |
| 4117 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4118 | cancel_work_sync(&data->work); |
| 4119 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4120 | btusb_stop_traffic(data); |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4121 | usb_kill_anchored_urbs(&data->tx_anchor); |
| 4122 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4123 | if (data->oob_wake_irq && device_may_wakeup(&data->udev->dev)) { |
| 4124 | set_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags); |
| 4125 | enable_irq_wake(data->oob_wake_irq); |
| 4126 | enable_irq(data->oob_wake_irq); |
| 4127 | } |
| 4128 | |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 4129 | /* For global suspend, Realtek devices lose the loaded fw |
| 4130 | * in them. But for autosuspend, firmware should remain. |
| 4131 | * Actually, it depends on whether the usb host sends |
| 4132 | * set feature (enable wakeup) or not. |
| 4133 | */ |
| 4134 | if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) { |
| 4135 | if (PMSG_IS_AUTO(message) && |
| 4136 | device_can_wakeup(&data->udev->dev)) |
| 4137 | data->udev->do_remote_wakeup = 1; |
| 4138 | else if (!PMSG_IS_AUTO(message)) |
| 4139 | data->udev->reset_resume = 1; |
| 4140 | } |
| 4141 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4142 | return 0; |
| 4143 | } |
| 4144 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4145 | static void play_deferred(struct btusb_data *data) |
| 4146 | { |
| 4147 | struct urb *urb; |
| 4148 | int err; |
| 4149 | |
| 4150 | while ((urb = usb_get_from_anchor(&data->deferred))) { |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4151 | usb_anchor_urb(urb, &data->tx_anchor); |
| 4152 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4153 | err = usb_submit_urb(urb, GFP_ATOMIC); |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4154 | if (err < 0) { |
| 4155 | if (err != -EPERM && err != -ENODEV) |
| 4156 | BT_ERR("%s urb %p submission failed (%d)", |
| 4157 | data->hdev->name, urb, -err); |
| 4158 | kfree(urb->setup_packet); |
| 4159 | usb_unanchor_urb(urb); |
| 4160 | usb_free_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4161 | break; |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4162 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4163 | |
| 4164 | data->tx_in_flight++; |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4165 | usb_free_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4166 | } |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4167 | |
| 4168 | /* Cleanup the rest deferred urbs. */ |
| 4169 | while ((urb = usb_get_from_anchor(&data->deferred))) { |
| 4170 | kfree(urb->setup_packet); |
| 4171 | usb_free_urb(urb); |
| 4172 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4173 | } |
| 4174 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4175 | static int btusb_resume(struct usb_interface *intf) |
| 4176 | { |
| 4177 | struct btusb_data *data = usb_get_intfdata(intf); |
| 4178 | struct hci_dev *hdev = data->hdev; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4179 | int err = 0; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4180 | |
| 4181 | BT_DBG("intf %p", intf); |
| 4182 | |
| 4183 | if (--data->suspend_count) |
| 4184 | return 0; |
| 4185 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4186 | /* Disable only if not already disabled (keep it balanced) */ |
| 4187 | if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) { |
| 4188 | disable_irq(data->oob_wake_irq); |
| 4189 | disable_irq_wake(data->oob_wake_irq); |
| 4190 | } |
| 4191 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4192 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4193 | goto done; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4194 | |
| 4195 | if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) { |
| 4196 | err = btusb_submit_intr_urb(hdev, GFP_NOIO); |
| 4197 | if (err < 0) { |
| 4198 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4199 | goto failed; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4200 | } |
| 4201 | } |
| 4202 | |
| 4203 | if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) { |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 4204 | err = btusb_submit_bulk_urb(hdev, GFP_NOIO); |
| 4205 | if (err < 0) { |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4206 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4207 | goto failed; |
| 4208 | } |
| 4209 | |
| 4210 | btusb_submit_bulk_urb(hdev, GFP_NOIO); |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
| 4214 | if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0) |
| 4215 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 4216 | else |
| 4217 | btusb_submit_isoc_urb(hdev, GFP_NOIO); |
| 4218 | } |
| 4219 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4220 | spin_lock_irq(&data->txlock); |
| 4221 | play_deferred(data); |
| 4222 | clear_bit(BTUSB_SUSPENDING, &data->flags); |
| 4223 | spin_unlock_irq(&data->txlock); |
| 4224 | schedule_work(&data->work); |
| 4225 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4226 | return 0; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4227 | |
| 4228 | failed: |
| 4229 | usb_scuttle_anchored_urbs(&data->deferred); |
| 4230 | done: |
| 4231 | spin_lock_irq(&data->txlock); |
| 4232 | clear_bit(BTUSB_SUSPENDING, &data->flags); |
| 4233 | spin_unlock_irq(&data->txlock); |
| 4234 | |
| 4235 | return err; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4236 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4237 | #endif |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4238 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4239 | static struct usb_driver btusb_driver = { |
| 4240 | .name = "btusb", |
| 4241 | .probe = btusb_probe, |
| 4242 | .disconnect = btusb_disconnect, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4243 | #ifdef CONFIG_PM |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4244 | .suspend = btusb_suspend, |
| 4245 | .resume = btusb_resume, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4246 | #endif |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4247 | .id_table = btusb_table, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4248 | .supports_autosuspend = 1, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 4249 | .disable_hub_initiated_lpm = 1, |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4250 | }; |
| 4251 | |
Greg Kroah-Hartman | 93f1508 | 2011-11-18 09:47:34 -0800 | [diff] [blame] | 4252 | module_usb_driver(btusb_driver); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4253 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4254 | module_param(disable_scofix, bool, 0644); |
| 4255 | MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size"); |
| 4256 | |
| 4257 | module_param(force_scofix, bool, 0644); |
| 4258 | MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size"); |
| 4259 | |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 4260 | module_param(enable_autosuspend, bool, 0644); |
| 4261 | MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default"); |
| 4262 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4263 | module_param(reset, bool, 0644); |
| 4264 | MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); |
| 4265 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4266 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); |
| 4267 | MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION); |
| 4268 | MODULE_VERSION(VERSION); |
| 4269 | MODULE_LICENSE("GPL"); |