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> |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 19 | #include <linux/debugfs.h> |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 20 | #include <asm/unaligned.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 21 | |
| 22 | #include <net/bluetooth/bluetooth.h> |
| 23 | #include <net/bluetooth/hci_core.h> |
| 24 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 25 | #include "btintel.h" |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 26 | #include "btbcm.h" |
Carlo Caione | db33c77 | 2015-05-14 10:49:09 +0200 | [diff] [blame] | 27 | #include "btrtl.h" |
Sean Wang | 8c0d17b | 2021-10-19 05:30:12 +0800 | [diff] [blame] | 28 | #include "btmtk.h" |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 29 | |
Marcel Holtmann | 34dced9b | 2015-04-05 22:52:16 -0700 | [diff] [blame] | 30 | #define VERSION "0.8" |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 31 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 32 | static bool disable_scofix; |
| 33 | static bool force_scofix; |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 34 | static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND); |
Shailendra Verma | 917a333 | 2015-05-25 23:53:40 +0530 | [diff] [blame] | 35 | static bool reset = true; |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 36 | |
| 37 | static struct usb_driver btusb_driver; |
| 38 | |
| 39 | #define BTUSB_IGNORE 0x01 |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 40 | #define BTUSB_DIGIANSWER 0x02 |
| 41 | #define BTUSB_CSR 0x04 |
| 42 | #define BTUSB_SNIFFER 0x08 |
| 43 | #define BTUSB_BCM92035 0x10 |
| 44 | #define BTUSB_BROKEN_ISOC 0x20 |
| 45 | #define BTUSB_WRONG_SCO_MTU 0x40 |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 46 | #define BTUSB_ATH3012 0x80 |
Tedd Ho-Jeong An | 83f2daf | 2021-08-04 17:32:10 -0700 | [diff] [blame] | 47 | #define BTUSB_INTEL_COMBINED 0x100 |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 48 | #define BTUSB_INTEL_BOOT 0x200 |
| 49 | #define BTUSB_BCM_PATCHRAM 0x400 |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 50 | #define BTUSB_MARVELL 0x800 |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 51 | #define BTUSB_SWAVE 0x1000 |
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 |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 62 | #define BTUSB_QCA_WCN6855 0x1000000 |
Tedd Ho-Jeong An | 9565545 | 2022-01-06 16:34:54 -0800 | [diff] [blame] | 63 | #define BTUSB_INTEL_BROKEN_SHUTDOWN_LED 0x2000000 |
Tedd Ho-Jeong An | ea7c4c0 | 2021-08-04 17:32:12 -0700 | [diff] [blame] | 64 | #define BTUSB_INTEL_BROKEN_INITIAL_NCMD 0x4000000 |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 65 | |
Marcel Holtmann | 5426520 | 2013-10-11 07:46:18 -0700 | [diff] [blame] | 66 | static const struct usb_device_id btusb_table[] = { |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 67 | /* Generic Bluetooth USB device */ |
| 68 | { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, |
| 69 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 70 | /* Generic Bluetooth AMP device */ |
| 71 | { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info = BTUSB_AMP }, |
| 72 | |
Daniel Drake | d63b282 | 2015-07-17 11:12:25 -0600 | [diff] [blame] | 73 | /* Generic Bluetooth USB interface */ |
| 74 | { USB_INTERFACE_INFO(0xe0, 0x01, 0x01) }, |
| 75 | |
Henrik Rydberg | 1fa6535 | 2012-08-25 19:28:06 +0200 | [diff] [blame] | 76 | /* Apple-specific (Broadcom) devices */ |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 77 | { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01), |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 78 | .driver_info = BTUSB_BCM_APPLE | BTUSB_IFNUM_2 }, |
Henrik Rydberg | 1fa6535 | 2012-08-25 19:28:06 +0200 | [diff] [blame] | 79 | |
Cho, Yu-Chen | 178c059 | 2013-06-04 21:40:26 +0800 | [diff] [blame] | 80 | /* MediaTek MT76x0E */ |
| 81 | { USB_DEVICE(0x0e8d, 0x763f) }, |
| 82 | |
Oliver Neukum | c510eae | 2011-09-21 11:41:45 +0200 | [diff] [blame] | 83 | /* Broadcom SoftSailing reporting vendor specific */ |
Don Zickus | 2e8b5063 | 2012-03-28 16:41:11 -0400 | [diff] [blame] | 84 | { USB_DEVICE(0x0a5c, 0x21e1) }, |
Oliver Neukum | c510eae | 2011-09-21 11:41:45 +0200 | [diff] [blame] | 85 | |
Nobuhiro Iwamatsu | 3cd0197 | 2010-08-20 16:24:07 +0900 | [diff] [blame] | 86 | /* Apple MacBookPro 7,1 */ |
| 87 | { USB_DEVICE(0x05ac, 0x8213) }, |
| 88 | |
Cyril Lacoux | 0a79f67 | 2010-07-14 10:29:27 +0400 | [diff] [blame] | 89 | /* Apple iMac11,1 */ |
| 90 | { USB_DEVICE(0x05ac, 0x8215) }, |
| 91 | |
Nobuhiro Iwamatsu | 9c04715 | 2010-08-20 16:24:06 +0900 | [diff] [blame] | 92 | /* Apple MacBookPro6,2 */ |
| 93 | { USB_DEVICE(0x05ac, 0x8218) }, |
| 94 | |
Edgar (gimli) Hucek | 3e3ede7 | 2010-11-04 08:04:33 +0100 | [diff] [blame] | 95 | /* Apple MacBookAir3,1, MacBookAir3,2 */ |
| 96 | { USB_DEVICE(0x05ac, 0x821b) }, |
| 97 | |
Pieter-Augustijn Van Malleghem | a63b723 | 2011-09-07 02:28:10 -0400 | [diff] [blame] | 98 | /* Apple MacBookAir4,1 */ |
| 99 | { USB_DEVICE(0x05ac, 0x821f) }, |
| 100 | |
Marc-Antoine Perennou | 88d377b | 2011-03-24 14:51:21 -0300 | [diff] [blame] | 101 | /* Apple MacBookPro8,2 */ |
| 102 | { USB_DEVICE(0x05ac, 0x821a) }, |
| 103 | |
Jurgen Kramer | f78b6826 | 2011-09-04 18:01:42 +0200 | [diff] [blame] | 104 | /* Apple MacMini5,1 */ |
| 105 | { USB_DEVICE(0x05ac, 0x8281) }, |
| 106 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 107 | /* AVM BlueFRITZ! USB v2.0 */ |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 108 | { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 109 | |
| 110 | /* Bluetooth Ultraport Module from IBM */ |
| 111 | { USB_DEVICE(0x04bf, 0x030a) }, |
| 112 | |
| 113 | /* ALPS Modules with non-standard id */ |
| 114 | { USB_DEVICE(0x044e, 0x3001) }, |
| 115 | { USB_DEVICE(0x044e, 0x3002) }, |
| 116 | |
| 117 | /* Ericsson with non-standard id */ |
| 118 | { USB_DEVICE(0x0bdb, 0x1002) }, |
| 119 | |
| 120 | /* Canyon CN-BTU1 with HID interfaces */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 121 | { USB_DEVICE(0x0c10, 0x0000) }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 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 */ |
Rocky Liao | e99f38b | 2020-09-17 21:09:23 +0800 | [diff] [blame] | 257 | { USB_DEVICE(0x0cf3, 0x535b), .driver_info = BTUSB_QCA_ROME | |
| 258 | BTUSB_WIDEBAND_SPEECH }, |
| 259 | { USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME | |
| 260 | BTUSB_WIDEBAND_SPEECH }, |
| 261 | { USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME | |
| 262 | BTUSB_WIDEBAND_SPEECH }, |
| 263 | { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME | |
| 264 | BTUSB_WIDEBAND_SPEECH }, |
| 265 | { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME | |
| 266 | BTUSB_WIDEBAND_SPEECH }, |
| 267 | { USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME | |
| 268 | BTUSB_WIDEBAND_SPEECH }, |
| 269 | { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME | |
| 270 | BTUSB_WIDEBAND_SPEECH }, |
Daniel Lenski | 0324d19 | 2021-05-18 10:25:46 -0700 | [diff] [blame] | 271 | { USB_DEVICE(0x0cf3, 0xe500), .driver_info = BTUSB_QCA_ROME | |
| 272 | BTUSB_WIDEBAND_SPEECH }, |
Rocky Liao | e99f38b | 2020-09-17 21:09:23 +0800 | [diff] [blame] | 273 | { USB_DEVICE(0x0489, 0xe092), .driver_info = BTUSB_QCA_ROME | |
| 274 | BTUSB_WIDEBAND_SPEECH }, |
| 275 | { USB_DEVICE(0x0489, 0xe09f), .driver_info = BTUSB_QCA_ROME | |
| 276 | BTUSB_WIDEBAND_SPEECH }, |
| 277 | { USB_DEVICE(0x0489, 0xe0a2), .driver_info = BTUSB_QCA_ROME | |
| 278 | BTUSB_WIDEBAND_SPEECH }, |
| 279 | { USB_DEVICE(0x04ca, 0x3011), .driver_info = BTUSB_QCA_ROME | |
| 280 | BTUSB_WIDEBAND_SPEECH }, |
| 281 | { USB_DEVICE(0x04ca, 0x3015), .driver_info = BTUSB_QCA_ROME | |
| 282 | BTUSB_WIDEBAND_SPEECH }, |
| 283 | { USB_DEVICE(0x04ca, 0x3016), .driver_info = BTUSB_QCA_ROME | |
| 284 | BTUSB_WIDEBAND_SPEECH }, |
| 285 | { USB_DEVICE(0x04ca, 0x301a), .driver_info = BTUSB_QCA_ROME | |
| 286 | BTUSB_WIDEBAND_SPEECH }, |
| 287 | { USB_DEVICE(0x04ca, 0x3021), .driver_info = BTUSB_QCA_ROME | |
| 288 | BTUSB_WIDEBAND_SPEECH }, |
| 289 | { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA_ROME | |
| 290 | BTUSB_WIDEBAND_SPEECH }, |
| 291 | { USB_DEVICE(0x13d3, 0x3496), .driver_info = BTUSB_QCA_ROME | |
| 292 | BTUSB_WIDEBAND_SPEECH }, |
| 293 | { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA_ROME | |
| 294 | BTUSB_WIDEBAND_SPEECH }, |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 295 | |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 296 | /* QCA WCN6855 chipset */ |
| 297 | { USB_DEVICE(0x0cf3, 0xe600), .driver_info = BTUSB_QCA_WCN6855 | |
Michael Sun | acd5aea | 2021-07-23 17:17:31 -0700 | [diff] [blame] | 298 | BTUSB_WIDEBAND_SPEECH | |
| 299 | BTUSB_VALID_LE_STATES }, |
tjiang@codeaurora.org | 21a241b | 2021-11-16 19:02:16 +0800 | [diff] [blame] | 300 | { USB_DEVICE(0x0489, 0xe0cc), .driver_info = BTUSB_QCA_WCN6855 | |
| 301 | BTUSB_WIDEBAND_SPEECH | |
| 302 | BTUSB_VALID_LE_STATES }, |
| 303 | { USB_DEVICE(0x0489, 0xe0d6), .driver_info = BTUSB_QCA_WCN6855 | |
| 304 | BTUSB_WIDEBAND_SPEECH | |
| 305 | BTUSB_VALID_LE_STATES }, |
Zijun Hu | e8c4258 | 2021-12-03 18:01:37 +0800 | [diff] [blame] | 306 | { USB_DEVICE(0x0489, 0xe0e3), .driver_info = BTUSB_QCA_WCN6855 | |
| 307 | BTUSB_WIDEBAND_SPEECH | |
| 308 | BTUSB_VALID_LE_STATES }, |
Zijun Hu | d2666be | 2021-12-09 14:34:01 +0800 | [diff] [blame] | 309 | { USB_DEVICE(0x10ab, 0x9309), .driver_info = BTUSB_QCA_WCN6855 | |
| 310 | BTUSB_WIDEBAND_SPEECH | |
| 311 | BTUSB_VALID_LE_STATES }, |
| 312 | { USB_DEVICE(0x10ab, 0x9409), .driver_info = BTUSB_QCA_WCN6855 | |
| 313 | BTUSB_WIDEBAND_SPEECH | |
| 314 | BTUSB_VALID_LE_STATES }, |
Aaron Ma | 1cd563e | 2022-01-07 11:59:09 +0800 | [diff] [blame] | 315 | { USB_DEVICE(0x0489, 0xe0d0), .driver_info = BTUSB_QCA_WCN6855 | |
| 316 | BTUSB_WIDEBAND_SPEECH | |
| 317 | BTUSB_VALID_LE_STATES }, |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 318 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 319 | /* Broadcom BCM2035 */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 320 | { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 321 | { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 322 | { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 323 | |
| 324 | /* Broadcom BCM2045 */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 325 | { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 326 | { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | bdbef3d | 2008-09-23 00:16:35 +0200 | [diff] [blame] | 327 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 328 | /* IBM/Lenovo ThinkPad with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 329 | { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 330 | { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 331 | |
| 332 | /* HP laptop with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 333 | { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 334 | |
| 335 | /* Dell laptop with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 336 | { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 337 | |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 338 | /* Dell Wireless 370 and 410 devices */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 339 | { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 340 | { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 341 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 342 | /* Belkin F8T012 and F8T013 devices */ |
| 343 | { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 344 | { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 345 | |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 346 | /* Asus WL-BTD202 device */ |
| 347 | { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 348 | |
| 349 | /* Kensington Bluetooth USB adapter */ |
| 350 | { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 351 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 352 | /* RTX Telecom based adapters with buggy SCO support */ |
| 353 | { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC }, |
| 354 | { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC }, |
| 355 | |
| 356 | /* CONWISE Technology based adapters with buggy SCO support */ |
Szymon Janc | 418678b | 2016-09-01 17:22:37 +0200 | [diff] [blame] | 357 | { USB_DEVICE(0x0e5e, 0x6622), |
| 358 | .driver_info = BTUSB_BROKEN_ISOC | BTUSB_CW6622}, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 359 | |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 360 | /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */ |
Aleksei Volkov | 2eeac87 | 2015-06-08 12:02:10 +0300 | [diff] [blame] | 361 | { USB_DEVICE(0x1310, 0x0001), .driver_info = BTUSB_SWAVE }, |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 362 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 363 | /* Digianswer devices */ |
| 364 | { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER }, |
| 365 | { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE }, |
| 366 | |
| 367 | /* CSR BlueCore Bluetooth Sniffer */ |
Marcel Holtmann | 4f64fa8 | 2014-07-07 00:12:04 +0200 | [diff] [blame] | 368 | { USB_DEVICE(0x0a12, 0x0002), |
| 369 | .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 370 | |
| 371 | /* Frontline ComProbe Bluetooth Sniffer */ |
Marcel Holtmann | 4f64fa8 | 2014-07-07 00:12:04 +0200 | [diff] [blame] | 372 | { USB_DEVICE(0x16d3, 0x0002), |
| 373 | .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 374 | |
Marcel Holtmann | cb1ee89 | 2015-01-28 19:41:42 -0800 | [diff] [blame] | 375 | /* Marvell Bluetooth devices */ |
| 376 | { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL }, |
| 377 | { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL }, |
Amitkumar Karwar | 1165df0 | 2016-09-28 16:18:35 +0530 | [diff] [blame] | 378 | { USB_DEVICE(0x1286, 0x204e), .driver_info = BTUSB_MARVELL }, |
Marcel Holtmann | cb1ee89 | 2015-01-28 19:41:42 -0800 | [diff] [blame] | 379 | |
Marcel Holtmann | d0ac9eb | 2015-01-28 19:41:43 -0800 | [diff] [blame] | 380 | /* Intel Bluetooth devices */ |
Tedd Ho-Jeong An | 3df4dfb | 2021-08-04 17:32:16 -0700 | [diff] [blame] | 381 | { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_COMBINED }, |
| 382 | { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_COMBINED }, |
| 383 | { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_COMBINED }, |
| 384 | { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_COMBINED }, |
| 385 | { USB_DEVICE(0x8087, 0x0033), .driver_info = BTUSB_INTEL_COMBINED }, |
Marcel Holtmann | 407550f | 2015-02-22 15:41:18 -0800 | [diff] [blame] | 386 | { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, |
Tedd Ho-Jeong An | ea7c4c0 | 2021-08-04 17:32:12 -0700 | [diff] [blame] | 387 | { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL_COMBINED | |
Tedd Ho-Jeong An | 9565545 | 2022-01-06 16:34:54 -0800 | [diff] [blame] | 388 | BTUSB_INTEL_BROKEN_INITIAL_NCMD | |
| 389 | BTUSB_INTEL_BROKEN_SHUTDOWN_LED }, |
| 390 | { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL_COMBINED | |
| 391 | BTUSB_INTEL_BROKEN_SHUTDOWN_LED }, |
Tedd Ho-Jeong An | 3df4dfb | 2021-08-04 17:32:16 -0700 | [diff] [blame] | 392 | { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_COMBINED }, |
Tedd Ho-Jeong An | 9565545 | 2022-01-06 16:34:54 -0800 | [diff] [blame] | 393 | { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL_COMBINED | |
| 394 | BTUSB_INTEL_BROKEN_SHUTDOWN_LED }, |
Tedd Ho-Jeong An | 3df4dfb | 2021-08-04 17:32:16 -0700 | [diff] [blame] | 395 | { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_COMBINED }, |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 396 | |
Marcel Holtmann | d0ac9eb | 2015-01-28 19:41:43 -0800 | [diff] [blame] | 397 | /* Other Intel Bluetooth devices */ |
| 398 | { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01), |
| 399 | .driver_info = BTUSB_IGNORE }, |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 400 | |
Joseph Hwang | 33bfd94 | 2020-07-13 15:45:29 +0800 | [diff] [blame] | 401 | /* Realtek 8822CE Bluetooth devices */ |
| 402 | { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK | |
| 403 | BTUSB_WIDEBAND_SPEECH }, |
Larry Finger | 4d96d3b | 2021-06-01 14:04:18 -0500 | [diff] [blame] | 404 | { USB_DEVICE(0x0bda, 0xc822), .driver_info = BTUSB_REALTEK | |
| 405 | BTUSB_WIDEBAND_SPEECH }, |
Joseph Hwang | 33bfd94 | 2020-07-13 15:45:29 +0800 | [diff] [blame] | 406 | |
Max Chou | 0d484db | 2020-11-10 11:38:37 +0800 | [diff] [blame] | 407 | /* Realtek 8852AE Bluetooth devices */ |
| 408 | { USB_DEVICE(0x0bda, 0xc852), .driver_info = BTUSB_REALTEK | |
| 409 | BTUSB_WIDEBAND_SPEECH }, |
Larry Finger | 27fe097 | 2021-11-21 10:51:48 -0600 | [diff] [blame] | 410 | { USB_DEVICE(0x0bda, 0x385a), .driver_info = BTUSB_REALTEK | |
| 411 | BTUSB_WIDEBAND_SPEECH }, |
Larry Finger | d1dcbf6 | 2021-09-28 13:45:20 -0500 | [diff] [blame] | 412 | { USB_DEVICE(0x0bda, 0x4852), .driver_info = BTUSB_REALTEK | |
| 413 | BTUSB_WIDEBAND_SPEECH }, |
Max Chou | 9bba128 | 2021-09-01 15:48:45 +0800 | [diff] [blame] | 414 | { USB_DEVICE(0x04c5, 0x165c), .driver_info = BTUSB_REALTEK | |
| 415 | BTUSB_WIDEBAND_SPEECH }, |
Larry Finger | d1dcbf6 | 2021-09-28 13:45:20 -0500 | [diff] [blame] | 416 | { USB_DEVICE(0x04ca, 0x4006), .driver_info = BTUSB_REALTEK | |
| 417 | BTUSB_WIDEBAND_SPEECH }, |
Max Chou | 0d484db | 2020-11-10 11:38:37 +0800 | [diff] [blame] | 418 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 419 | /* Realtek Bluetooth devices */ |
| 420 | { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01), |
| 421 | .driver_info = BTUSB_REALTEK }, |
| 422 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 423 | /* MediaTek Bluetooth devices */ |
| 424 | { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01), |
mark-yw.chen | 27e554a | 2021-03-29 01:18:33 +0800 | [diff] [blame] | 425 | .driver_info = BTUSB_MEDIATEK | |
| 426 | BTUSB_WIDEBAND_SPEECH | |
| 427 | BTUSB_VALID_LE_STATES }, |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 428 | |
Chris Chiu | 3a567b9 | 2020-11-10 11:40:10 +0800 | [diff] [blame] | 429 | /* Additional MediaTek MT7615E Bluetooth devices */ |
| 430 | { USB_DEVICE(0x13d3, 0x3560), .driver_info = BTUSB_MEDIATEK}, |
| 431 | |
Forest Crossman | 3735682 | 2021-07-12 02:32:20 -0500 | [diff] [blame] | 432 | /* Additional MediaTek MT7668 Bluetooth devices */ |
| 433 | { USB_DEVICE(0x043e, 0x3109), .driver_info = BTUSB_MEDIATEK | |
| 434 | BTUSB_WIDEBAND_SPEECH | |
| 435 | BTUSB_VALID_LE_STATES }, |
| 436 | |
mark-yw.chen | 393dc5d | 2021-04-12 23:06:27 +0800 | [diff] [blame] | 437 | /* Additional MediaTek MT7921 Bluetooth devices */ |
| 438 | { USB_DEVICE(0x04ca, 0x3802), .driver_info = BTUSB_MEDIATEK | |
| 439 | BTUSB_WIDEBAND_SPEECH | |
| 440 | BTUSB_VALID_LE_STATES }, |
Wai Paulo Valerio Wang | 2cdff8c | 2021-07-08 04:00:59 +0800 | [diff] [blame] | 441 | { USB_DEVICE(0x13d3, 0x3563), .driver_info = BTUSB_MEDIATEK | |
| 442 | BTUSB_WIDEBAND_SPEECH | |
| 443 | BTUSB_VALID_LE_STATES }, |
mark-yw.chen | 15957ca | 2021-09-01 19:30:15 +0800 | [diff] [blame] | 444 | { USB_DEVICE(0x13d3, 0x3564), .driver_info = BTUSB_MEDIATEK | |
| 445 | BTUSB_WIDEBAND_SPEECH | |
| 446 | BTUSB_VALID_LE_STATES }, |
Aaron Ma | 64832df | 2021-07-23 01:17:18 +0800 | [diff] [blame] | 447 | { USB_DEVICE(0x0489, 0xe0cd), .driver_info = BTUSB_MEDIATEK | |
| 448 | BTUSB_WIDEBAND_SPEECH | |
| 449 | BTUSB_VALID_LE_STATES }, |
mark-yw.chen | 393dc5d | 2021-04-12 23:06:27 +0800 | [diff] [blame] | 450 | |
Aaron Ma | 6932627 | 2021-12-17 17:51:50 +0800 | [diff] [blame] | 451 | /* MediaTek MT7922A Bluetooth devices */ |
| 452 | { USB_DEVICE(0x0489, 0xe0d8), .driver_info = BTUSB_MEDIATEK | |
| 453 | BTUSB_WIDEBAND_SPEECH | |
| 454 | BTUSB_VALID_LE_STATES }, |
| 455 | { USB_DEVICE(0x0489, 0xe0d9), .driver_info = BTUSB_MEDIATEK | |
| 456 | BTUSB_WIDEBAND_SPEECH | |
| 457 | BTUSB_VALID_LE_STATES }, |
| 458 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 459 | /* Additional Realtek 8723AE Bluetooth devices */ |
| 460 | { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK }, |
| 461 | { USB_DEVICE(0x13d3, 0x3394), .driver_info = BTUSB_REALTEK }, |
| 462 | |
| 463 | /* Additional Realtek 8723BE Bluetooth devices */ |
| 464 | { USB_DEVICE(0x0489, 0xe085), .driver_info = BTUSB_REALTEK }, |
| 465 | { USB_DEVICE(0x0489, 0xe08b), .driver_info = BTUSB_REALTEK }, |
| 466 | { USB_DEVICE(0x13d3, 0x3410), .driver_info = BTUSB_REALTEK }, |
| 467 | { USB_DEVICE(0x13d3, 0x3416), .driver_info = BTUSB_REALTEK }, |
| 468 | { USB_DEVICE(0x13d3, 0x3459), .driver_info = BTUSB_REALTEK }, |
Dmitry Tunin | a81d72d | 2017-08-08 14:09:02 +0300 | [diff] [blame] | 469 | { USB_DEVICE(0x13d3, 0x3494), .driver_info = BTUSB_REALTEK }, |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 470 | |
Vicente Bergas | a41e079 | 2018-03-20 19:41:10 +0100 | [diff] [blame] | 471 | /* Additional Realtek 8723BU Bluetooth devices */ |
| 472 | { USB_DEVICE(0x7392, 0xa611), .driver_info = BTUSB_REALTEK }, |
| 473 | |
Jian-Hong Pan | 66d9975 | 2018-05-21 18:09:20 +0800 | [diff] [blame] | 474 | /* Additional Realtek 8723DE Bluetooth devices */ |
Jian-Hong Pan | 45ae68b | 2018-05-25 17:54:52 +0800 | [diff] [blame] | 475 | { USB_DEVICE(0x0bda, 0xb009), .driver_info = BTUSB_REALTEK }, |
Jian-Hong Pan | 66d9975 | 2018-05-21 18:09:20 +0800 | [diff] [blame] | 476 | { USB_DEVICE(0x2ff8, 0xb011), .driver_info = BTUSB_REALTEK }, |
| 477 | |
Nicholas Flintham | 4fd6d49 | 2021-09-30 09:22:39 +0100 | [diff] [blame] | 478 | /* Additional Realtek 8761B Bluetooth devices */ |
| 479 | { USB_DEVICE(0x2357, 0x0604), .driver_info = BTUSB_REALTEK | |
| 480 | BTUSB_WIDEBAND_SPEECH }, |
| 481 | |
Joakim Tjernlund | 3340438 | 2021-05-28 17:26:45 +0200 | [diff] [blame] | 482 | /* Additional Realtek 8761BU Bluetooth devices */ |
| 483 | { USB_DEVICE(0x0b05, 0x190e), .driver_info = BTUSB_REALTEK | |
| 484 | BTUSB_WIDEBAND_SPEECH }, |
| 485 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 486 | /* Additional Realtek 8821AE Bluetooth devices */ |
| 487 | { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK }, |
| 488 | { USB_DEVICE(0x13d3, 0x3414), .driver_info = BTUSB_REALTEK }, |
| 489 | { USB_DEVICE(0x13d3, 0x3458), .driver_info = BTUSB_REALTEK }, |
| 490 | { USB_DEVICE(0x13d3, 0x3461), .driver_info = BTUSB_REALTEK }, |
| 491 | { USB_DEVICE(0x13d3, 0x3462), .driver_info = BTUSB_REALTEK }, |
| 492 | |
Larry Finger | fed03fe | 2018-02-11 12:24:32 -0600 | [diff] [blame] | 493 | /* Additional Realtek 8822BE Bluetooth devices */ |
Artiom Vaskov | 1cd2fab | 2018-05-30 11:23:00 +0300 | [diff] [blame] | 494 | { USB_DEVICE(0x13d3, 0x3526), .driver_info = BTUSB_REALTEK }, |
Larry Finger | fed03fe | 2018-02-11 12:24:32 -0600 | [diff] [blame] | 495 | { USB_DEVICE(0x0b05, 0x185c), .driver_info = BTUSB_REALTEK }, |
| 496 | |
Jian-Hong Pan | 6d0762b | 2019-09-03 17:10:42 +0800 | [diff] [blame] | 497 | /* Additional Realtek 8822CE Bluetooth devices */ |
Max Chou | 73280f1 | 2020-11-05 18:54:48 +0800 | [diff] [blame] | 498 | { USB_DEVICE(0x04ca, 0x4005), .driver_info = BTUSB_REALTEK | |
| 499 | BTUSB_WIDEBAND_SPEECH }, |
| 500 | { USB_DEVICE(0x04c5, 0x161f), .driver_info = BTUSB_REALTEK | |
| 501 | BTUSB_WIDEBAND_SPEECH }, |
| 502 | { USB_DEVICE(0x0b05, 0x18ef), .driver_info = BTUSB_REALTEK | |
| 503 | BTUSB_WIDEBAND_SPEECH }, |
| 504 | { USB_DEVICE(0x13d3, 0x3548), .driver_info = BTUSB_REALTEK | |
| 505 | BTUSB_WIDEBAND_SPEECH }, |
| 506 | { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK | |
| 507 | BTUSB_WIDEBAND_SPEECH }, |
| 508 | { USB_DEVICE(0x13d3, 0x3553), .driver_info = BTUSB_REALTEK | |
| 509 | BTUSB_WIDEBAND_SPEECH }, |
| 510 | { USB_DEVICE(0x13d3, 0x3555), .driver_info = BTUSB_REALTEK | |
| 511 | BTUSB_WIDEBAND_SPEECH }, |
| 512 | { USB_DEVICE(0x2ff8, 0x3051), .driver_info = BTUSB_REALTEK | |
| 513 | BTUSB_WIDEBAND_SPEECH }, |
Julian Pidancet | f496297 | 2020-11-09 17:47:22 +0100 | [diff] [blame] | 514 | { USB_DEVICE(0x1358, 0xc123), .driver_info = BTUSB_REALTEK | |
| 515 | BTUSB_WIDEBAND_SPEECH }, |
Cadel Watson | 24d6a6d | 2020-11-19 16:16:25 +1100 | [diff] [blame] | 516 | { USB_DEVICE(0x0bda, 0xc123), .driver_info = BTUSB_REALTEK | |
| 517 | BTUSB_WIDEBAND_SPEECH }, |
Rasmus Moorats | 3edc578 | 2021-02-18 13:11:24 +0200 | [diff] [blame] | 518 | { USB_DEVICE(0x0cb5, 0xc547), .driver_info = BTUSB_REALTEK | |
| 519 | BTUSB_WIDEBAND_SPEECH }, |
Jian-Hong Pan | 6d0762b | 2019-09-03 17:10:42 +0800 | [diff] [blame] | 520 | |
Peter Poklop | 4481c07 | 2015-08-15 20:47:09 +0200 | [diff] [blame] | 521 | /* Silicon Wave based devices */ |
| 522 | { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE }, |
| 523 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 524 | { } /* Terminating entry */ |
| 525 | }; |
| 526 | |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 527 | /* The Bluetooth USB module build into some devices needs to be reset on resume, |
| 528 | * this is a problem with the platform (likely shutting off all power) not with |
| 529 | * the module itself. So we use a DMI list to match known broken platforms. |
| 530 | */ |
| 531 | static const struct dmi_system_id btusb_needs_reset_resume_table[] = { |
| 532 | { |
Kai-Heng Feng | 0c6e526 | 2018-03-01 13:42:52 +0800 | [diff] [blame] | 533 | /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */ |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 534 | .matches = { |
Kai-Heng Feng | 0c6e526 | 2018-03-01 13:42:52 +0800 | [diff] [blame] | 535 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 536 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 3060"), |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 537 | }, |
| 538 | }, |
Hans de Goede | 596b07a | 2018-04-26 20:52:06 +0200 | [diff] [blame] | 539 | { |
| 540 | /* Dell XPS 9360 (QCA ROME device 0cf3:e300) */ |
| 541 | .matches = { |
| 542 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 543 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"), |
| 544 | }, |
| 545 | }, |
Hans de Goede | 939bc6c | 2018-05-22 09:34:10 +0200 | [diff] [blame] | 546 | { |
| 547 | /* Dell Inspiron 5565 (QCA ROME device 0cf3:e009) */ |
| 548 | .matches = { |
| 549 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 550 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5565"), |
| 551 | }, |
| 552 | }, |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 553 | {} |
| 554 | }; |
| 555 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 556 | #define BTUSB_MAX_ISOC_FRAMES 10 |
| 557 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 558 | #define BTUSB_INTR_RUNNING 0 |
| 559 | #define BTUSB_BULK_RUNNING 1 |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 560 | #define BTUSB_ISOC_RUNNING 2 |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 561 | #define BTUSB_SUSPENDING 3 |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 562 | #define BTUSB_DID_ISO_RESUME 4 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 563 | #define BTUSB_BOOTLOADER 5 |
| 564 | #define BTUSB_DOWNLOADING 6 |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 565 | #define BTUSB_FIRMWARE_LOADED 7 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 566 | #define BTUSB_FIRMWARE_FAILED 8 |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 567 | #define BTUSB_BOOTING 9 |
Hans de Goede | 61f5ace | 2018-01-08 10:44:16 +0100 | [diff] [blame] | 568 | #define BTUSB_DIAG_RUNNING 10 |
| 569 | #define BTUSB_OOB_WAKE_ENABLED 11 |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 570 | #define BTUSB_HW_RESET_ACTIVE 12 |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 571 | #define BTUSB_TX_WAIT_VND_EVT 13 |
Max Chou | 8274db0 | 2021-08-17 11:03:12 +0800 | [diff] [blame] | 572 | #define BTUSB_WAKEUP_AUTOSUSPEND 14 |
Pauli Virtanen | 55981d3 | 2021-07-26 21:02:06 +0300 | [diff] [blame] | 573 | #define BTUSB_USE_ALT3_FOR_WBS 15 |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 574 | |
| 575 | struct btusb_data { |
| 576 | struct hci_dev *hdev; |
| 577 | struct usb_device *udev; |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 578 | struct usb_interface *intf; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 579 | struct usb_interface *isoc; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 580 | struct usb_interface *diag; |
Marcel Holtmann | 459232f | 2017-10-24 19:42:45 +0200 | [diff] [blame] | 581 | unsigned isoc_ifnum; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 582 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 583 | unsigned long flags; |
| 584 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 585 | bool poll_sync; |
| 586 | int intr_interval; |
| 587 | struct work_struct work; |
| 588 | struct work_struct waker; |
| 589 | struct delayed_work rx_work; |
| 590 | |
| 591 | struct sk_buff_head acl_q; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 592 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 593 | struct usb_anchor deferred; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 594 | struct usb_anchor tx_anchor; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 595 | int tx_in_flight; |
| 596 | spinlock_t txlock; |
| 597 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 598 | struct usb_anchor intr_anchor; |
| 599 | struct usb_anchor bulk_anchor; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 600 | struct usb_anchor isoc_anchor; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 601 | struct usb_anchor diag_anchor; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 602 | struct usb_anchor ctrl_anchor; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 603 | spinlock_t rxlock; |
| 604 | |
| 605 | struct sk_buff *evt_skb; |
| 606 | struct sk_buff *acl_skb; |
| 607 | struct sk_buff *sco_skb; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 608 | |
| 609 | struct usb_endpoint_descriptor *intr_ep; |
| 610 | struct usb_endpoint_descriptor *bulk_tx_ep; |
| 611 | struct usb_endpoint_descriptor *bulk_rx_ep; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 612 | struct usb_endpoint_descriptor *isoc_tx_ep; |
| 613 | struct usb_endpoint_descriptor *isoc_rx_ep; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 614 | struct usb_endpoint_descriptor *diag_tx_ep; |
| 615 | struct usb_endpoint_descriptor *diag_rx_ep; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 616 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 617 | struct gpio_desc *reset_gpio; |
| 618 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 619 | __u8 cmdreq_type; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 620 | __u8 cmdreq; |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 621 | |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 622 | unsigned int sco_num; |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 623 | unsigned int air_mode; |
| 624 | bool usb_alt6_packet_flow; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 625 | int isoc_altsetting; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 626 | int suspend_count; |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 627 | |
Marcel Holtmann | 97307f5 | 2015-01-12 13:51:10 -0800 | [diff] [blame] | 628 | int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb); |
mark-yw.chen | 0b10c8c | 2021-08-04 17:03:15 +0800 | [diff] [blame] | 629 | int (*recv_acl)(struct hci_dev *hdev, struct sk_buff *skb); |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 630 | 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] | 631 | |
| 632 | int (*setup_on_usb)(struct hci_dev *hdev); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 633 | |
| 634 | int oob_wake_irq; /* irq for out-of-band wake-on-bt */ |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 635 | unsigned cmd_timeout_cnt; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 636 | }; |
| 637 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 638 | static void btusb_intel_cmd_timeout(struct hci_dev *hdev) |
| 639 | { |
| 640 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 641 | struct gpio_desc *reset_gpio = data->reset_gpio; |
| 642 | |
| 643 | if (++data->cmd_timeout_cnt < 5) |
| 644 | return; |
| 645 | |
| 646 | if (!reset_gpio) { |
| 647 | bt_dev_err(hdev, "No way to reset. Ignoring and continuing"); |
| 648 | return; |
| 649 | } |
| 650 | |
| 651 | /* |
| 652 | * Toggle the hard reset line if the platform provides one. The reset |
| 653 | * is going to yank the device off the USB and then replug. So doing |
| 654 | * once is enough. The cleanup is handled correctly on the way out |
| 655 | * (standard USB disconnect), and the new device is detected cleanly |
| 656 | * and bound to the driver again like it should be. |
| 657 | */ |
| 658 | if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
| 659 | bt_dev_err(hdev, "last reset failed? Not resetting again"); |
| 660 | return; |
| 661 | } |
| 662 | |
| 663 | bt_dev_err(hdev, "Initiating HW reset via gpio"); |
Rajat Jain | 2de66bb8 | 2019-01-28 15:08:09 -0800 | [diff] [blame] | 664 | gpiod_set_value_cansleep(reset_gpio, 1); |
| 665 | msleep(100); |
| 666 | gpiod_set_value_cansleep(reset_gpio, 0); |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 667 | } |
| 668 | |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 669 | static void btusb_rtl_cmd_timeout(struct hci_dev *hdev) |
| 670 | { |
| 671 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 672 | struct gpio_desc *reset_gpio = data->reset_gpio; |
| 673 | |
| 674 | if (++data->cmd_timeout_cnt < 5) |
| 675 | return; |
| 676 | |
| 677 | if (!reset_gpio) { |
| 678 | bt_dev_err(hdev, "No gpio to reset Realtek device, ignoring"); |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | /* Toggle the hard reset line. The Realtek device is going to |
| 683 | * yank itself off the USB and then replug. The cleanup is handled |
| 684 | * correctly on the way out (standard USB disconnect), and the new |
| 685 | * device is detected cleanly and bound to the driver again like |
| 686 | * it should be. |
| 687 | */ |
| 688 | if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
| 689 | bt_dev_err(hdev, "last reset failed? Not resetting again"); |
| 690 | return; |
| 691 | } |
| 692 | |
| 693 | bt_dev_err(hdev, "Reset Realtek device via gpio"); |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 694 | gpiod_set_value_cansleep(reset_gpio, 1); |
Max Chou | 3468211 | 2019-11-27 11:01:07 +0800 | [diff] [blame] | 695 | msleep(200); |
| 696 | gpiod_set_value_cansleep(reset_gpio, 0); |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 697 | } |
| 698 | |
Abhishek Pandit-Subedi | 6933568 | 2020-06-24 11:11:44 -0700 | [diff] [blame] | 699 | static void btusb_qca_cmd_timeout(struct hci_dev *hdev) |
| 700 | { |
| 701 | struct btusb_data *data = hci_get_drvdata(hdev); |
tjiang@codeaurora.org | 24ff62a | 2021-09-16 16:41:06 +0800 | [diff] [blame] | 702 | struct gpio_desc *reset_gpio = data->reset_gpio; |
Abhishek Pandit-Subedi | 6933568 | 2020-06-24 11:11:44 -0700 | [diff] [blame] | 703 | int err; |
| 704 | |
| 705 | if (++data->cmd_timeout_cnt < 5) |
| 706 | return; |
| 707 | |
tjiang@codeaurora.org | 24ff62a | 2021-09-16 16:41:06 +0800 | [diff] [blame] | 708 | if (reset_gpio) { |
| 709 | bt_dev_err(hdev, "Reset qca device via bt_en gpio"); |
| 710 | |
| 711 | /* Toggle the hard reset line. The qca bt device is going to |
| 712 | * yank itself off the USB and then replug. The cleanup is handled |
| 713 | * correctly on the way out (standard USB disconnect), and the new |
| 714 | * device is detected cleanly and bound to the driver again like |
| 715 | * it should be. |
| 716 | */ |
| 717 | if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
| 718 | bt_dev_err(hdev, "last reset failed? Not resetting again"); |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | gpiod_set_value_cansleep(reset_gpio, 0); |
| 723 | msleep(200); |
| 724 | gpiod_set_value_cansleep(reset_gpio, 1); |
| 725 | |
| 726 | return; |
| 727 | } |
| 728 | |
Abhishek Pandit-Subedi | 6933568 | 2020-06-24 11:11:44 -0700 | [diff] [blame] | 729 | bt_dev_err(hdev, "Multiple cmd timeouts seen. Resetting usb device."); |
Abhishek Pandit-Subedi | b980d47 | 2020-06-25 16:26:27 -0700 | [diff] [blame] | 730 | /* This is not an unbalanced PM reference since the device will reset */ |
Abhishek Pandit-Subedi | 6933568 | 2020-06-24 11:11:44 -0700 | [diff] [blame] | 731 | err = usb_autopm_get_interface(data->intf); |
| 732 | if (!err) |
| 733 | usb_queue_reset_device(data->intf); |
| 734 | else |
| 735 | bt_dev_err(hdev, "Failed usb_autopm_get_interface with %d", err); |
| 736 | } |
| 737 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 738 | static inline void btusb_free_frags(struct btusb_data *data) |
| 739 | { |
| 740 | unsigned long flags; |
| 741 | |
| 742 | spin_lock_irqsave(&data->rxlock, flags); |
| 743 | |
| 744 | kfree_skb(data->evt_skb); |
| 745 | data->evt_skb = NULL; |
| 746 | |
| 747 | kfree_skb(data->acl_skb); |
| 748 | data->acl_skb = NULL; |
| 749 | |
| 750 | kfree_skb(data->sco_skb); |
| 751 | data->sco_skb = NULL; |
| 752 | |
| 753 | spin_unlock_irqrestore(&data->rxlock, flags); |
| 754 | } |
| 755 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 756 | static int btusb_recv_event(struct btusb_data *data, struct sk_buff *skb) |
| 757 | { |
| 758 | if (data->intr_interval) { |
| 759 | /* Trigger dequeue immediatelly if an event is received */ |
| 760 | schedule_delayed_work(&data->rx_work, 0); |
| 761 | } |
| 762 | |
| 763 | return data->recv_event(data->hdev, skb); |
| 764 | } |
| 765 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 766 | static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count) |
| 767 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 768 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 769 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 770 | int err = 0; |
| 771 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 772 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 773 | skb = data->evt_skb; |
| 774 | |
| 775 | while (count) { |
| 776 | int len; |
| 777 | |
| 778 | if (!skb) { |
| 779 | skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC); |
| 780 | if (!skb) { |
| 781 | err = -ENOMEM; |
| 782 | break; |
| 783 | } |
| 784 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 785 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
| 786 | hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 787 | } |
| 788 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 789 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 790 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 791 | |
| 792 | count -= len; |
| 793 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 794 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 795 | |
| 796 | if (skb->len == HCI_EVENT_HDR_SIZE) { |
| 797 | /* Complete event header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 798 | hci_skb_expect(skb) = hci_event_hdr(skb)->plen; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 799 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 800 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 801 | kfree_skb(skb); |
| 802 | skb = NULL; |
| 803 | |
| 804 | err = -EILSEQ; |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 809 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 810 | /* Complete frame */ |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 811 | btusb_recv_event(data, skb); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 812 | skb = NULL; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | data->evt_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 817 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 818 | |
| 819 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 820 | } |
| 821 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 822 | static int btusb_recv_acl(struct btusb_data *data, struct sk_buff *skb) |
| 823 | { |
| 824 | /* Only queue ACL packet if intr_interval is set as it means |
| 825 | * force_poll_sync has been enabled. |
| 826 | */ |
| 827 | if (!data->intr_interval) |
| 828 | return data->recv_acl(data->hdev, skb); |
| 829 | |
| 830 | skb_queue_tail(&data->acl_q, skb); |
| 831 | schedule_delayed_work(&data->rx_work, data->intr_interval); |
| 832 | |
| 833 | return 0; |
| 834 | } |
| 835 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 836 | static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count) |
| 837 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 838 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 839 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 840 | int err = 0; |
| 841 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 842 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 843 | skb = data->acl_skb; |
| 844 | |
| 845 | while (count) { |
| 846 | int len; |
| 847 | |
| 848 | if (!skb) { |
| 849 | skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); |
| 850 | if (!skb) { |
| 851 | err = -ENOMEM; |
| 852 | break; |
| 853 | } |
| 854 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 855 | hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT; |
| 856 | hci_skb_expect(skb) = HCI_ACL_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 857 | } |
| 858 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 859 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 860 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 861 | |
| 862 | count -= len; |
| 863 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 864 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 865 | |
| 866 | if (skb->len == HCI_ACL_HDR_SIZE) { |
| 867 | __le16 dlen = hci_acl_hdr(skb)->dlen; |
| 868 | |
| 869 | /* Complete ACL header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 870 | hci_skb_expect(skb) = __le16_to_cpu(dlen); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 871 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 872 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 873 | kfree_skb(skb); |
| 874 | skb = NULL; |
| 875 | |
| 876 | err = -EILSEQ; |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 881 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 882 | /* Complete frame */ |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 883 | btusb_recv_acl(data, skb); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 884 | skb = NULL; |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | data->acl_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 889 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 890 | |
| 891 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count) |
| 895 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 896 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 897 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 898 | int err = 0; |
| 899 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 900 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 901 | skb = data->sco_skb; |
| 902 | |
| 903 | while (count) { |
| 904 | int len; |
| 905 | |
| 906 | if (!skb) { |
| 907 | skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC); |
| 908 | if (!skb) { |
| 909 | err = -ENOMEM; |
| 910 | break; |
| 911 | } |
| 912 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 913 | hci_skb_pkt_type(skb) = HCI_SCODATA_PKT; |
| 914 | hci_skb_expect(skb) = HCI_SCO_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 915 | } |
| 916 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 917 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 918 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 919 | |
| 920 | count -= len; |
| 921 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 922 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 923 | |
| 924 | if (skb->len == HCI_SCO_HDR_SIZE) { |
| 925 | /* Complete SCO header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 926 | hci_skb_expect(skb) = hci_sco_hdr(skb)->dlen; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 927 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 928 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 929 | kfree_skb(skb); |
| 930 | skb = NULL; |
| 931 | |
| 932 | err = -EILSEQ; |
| 933 | break; |
| 934 | } |
| 935 | } |
| 936 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 937 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 938 | /* Complete frame */ |
| 939 | hci_recv_frame(data->hdev, skb); |
| 940 | skb = NULL; |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | data->sco_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 945 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 946 | |
| 947 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 948 | } |
| 949 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 950 | static void btusb_intr_complete(struct urb *urb) |
| 951 | { |
| 952 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 953 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 954 | int err; |
| 955 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 956 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 957 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 958 | |
| 959 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 960 | return; |
| 961 | |
| 962 | if (urb->status == 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 963 | hdev->stat.byte_rx += urb->actual_length; |
| 964 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 965 | if (btusb_recv_intr(data, urb->transfer_buffer, |
| 966 | urb->actual_length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 967 | bt_dev_err(hdev, "corrupted event packet"); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 968 | hdev->stat.err_rx++; |
| 969 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 970 | } else if (urb->status == -ENOENT) { |
| 971 | /* Avoid suspend failed when usb_kill_urb */ |
| 972 | return; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | if (!test_bit(BTUSB_INTR_RUNNING, &data->flags)) |
| 976 | return; |
| 977 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 978 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 979 | usb_anchor_urb(urb, &data->intr_anchor); |
| 980 | |
| 981 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 982 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 983 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 984 | * -ENODEV: device got disconnected |
| 985 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 986 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 987 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 988 | urb, -err); |
Benjamin Berg | c97a747 | 2021-12-03 15:59:02 +0100 | [diff] [blame] | 989 | if (err != -EPERM) |
| 990 | hci_cmd_sync_cancel(hdev, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 991 | usb_unanchor_urb(urb); |
| 992 | } |
| 993 | } |
| 994 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 995 | 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] | 996 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 997 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 998 | struct urb *urb; |
| 999 | unsigned char *buf; |
| 1000 | unsigned int pipe; |
| 1001 | int err, size; |
| 1002 | |
| 1003 | BT_DBG("%s", hdev->name); |
| 1004 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1005 | if (!data->intr_ep) |
| 1006 | return -ENODEV; |
| 1007 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1008 | urb = usb_alloc_urb(0, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1009 | if (!urb) |
| 1010 | return -ENOMEM; |
| 1011 | |
| 1012 | size = le16_to_cpu(data->intr_ep->wMaxPacketSize); |
| 1013 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1014 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1015 | if (!buf) { |
| 1016 | usb_free_urb(urb); |
| 1017 | return -ENOMEM; |
| 1018 | } |
| 1019 | |
| 1020 | pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress); |
| 1021 | |
| 1022 | usb_fill_int_urb(urb, data->udev, pipe, buf, size, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1023 | btusb_intr_complete, hdev, data->intr_ep->bInterval); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1024 | |
| 1025 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 1026 | |
| 1027 | usb_anchor_urb(urb, &data->intr_anchor); |
| 1028 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1029 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1030 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 1031 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1032 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1033 | urb, -err); |
Benjamin Berg | c97a747 | 2021-12-03 15:59:02 +0100 | [diff] [blame] | 1034 | if (err != -EPERM) |
| 1035 | hci_cmd_sync_cancel(hdev, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1036 | usb_unanchor_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1037 | } |
| 1038 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 1039 | /* Only initialize intr_interval if URB poll sync is enabled */ |
| 1040 | if (!data->poll_sync) |
| 1041 | goto done; |
| 1042 | |
| 1043 | /* The units are frames (milliseconds) for full and low speed devices, |
| 1044 | * and microframes (1/8 millisecond) for highspeed and SuperSpeed |
| 1045 | * devices. |
| 1046 | * |
| 1047 | * This is done once on open/resume so it shouldn't change even if |
| 1048 | * force_poll_sync changes. |
| 1049 | */ |
| 1050 | switch (urb->dev->speed) { |
| 1051 | case USB_SPEED_SUPER_PLUS: |
| 1052 | case USB_SPEED_SUPER: /* units are 125us */ |
| 1053 | data->intr_interval = usecs_to_jiffies(urb->interval * 125); |
| 1054 | break; |
| 1055 | default: |
| 1056 | data->intr_interval = msecs_to_jiffies(urb->interval); |
| 1057 | break; |
| 1058 | } |
| 1059 | |
| 1060 | done: |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1061 | usb_free_urb(urb); |
| 1062 | |
| 1063 | return err; |
| 1064 | } |
| 1065 | |
| 1066 | static void btusb_bulk_complete(struct urb *urb) |
| 1067 | { |
| 1068 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1069 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1070 | int err; |
| 1071 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1072 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1073 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1074 | |
| 1075 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1076 | return; |
| 1077 | |
| 1078 | if (urb->status == 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1079 | hdev->stat.byte_rx += urb->actual_length; |
| 1080 | |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 1081 | if (data->recv_bulk(data, urb->transfer_buffer, |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 1082 | urb->actual_length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1083 | bt_dev_err(hdev, "corrupted ACL packet"); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1084 | hdev->stat.err_rx++; |
| 1085 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 1086 | } else if (urb->status == -ENOENT) { |
| 1087 | /* Avoid suspend failed when usb_kill_urb */ |
| 1088 | return; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | if (!test_bit(BTUSB_BULK_RUNNING, &data->flags)) |
| 1092 | return; |
| 1093 | |
| 1094 | usb_anchor_urb(urb, &data->bulk_anchor); |
Oliver Neukum | 652fd78 | 2009-12-16 19:23:43 +0100 | [diff] [blame] | 1095 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1096 | |
| 1097 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 1098 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 1099 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 1100 | * -ENODEV: device got disconnected |
| 1101 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 1102 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1103 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 1104 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1105 | usb_unanchor_urb(urb); |
| 1106 | } |
| 1107 | } |
| 1108 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1109 | 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] | 1110 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1111 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1112 | struct urb *urb; |
| 1113 | unsigned char *buf; |
| 1114 | unsigned int pipe; |
Vikram Kandukuri | 290ba20 | 2009-07-02 14:31:59 +0530 | [diff] [blame] | 1115 | int err, size = HCI_MAX_FRAME_SIZE; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1116 | |
| 1117 | BT_DBG("%s", hdev->name); |
| 1118 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1119 | if (!data->bulk_rx_ep) |
| 1120 | return -ENODEV; |
| 1121 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1122 | urb = usb_alloc_urb(0, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1123 | if (!urb) |
| 1124 | return -ENOMEM; |
| 1125 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1126 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1127 | if (!buf) { |
| 1128 | usb_free_urb(urb); |
| 1129 | return -ENOMEM; |
| 1130 | } |
| 1131 | |
| 1132 | pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress); |
| 1133 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1134 | usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, |
| 1135 | btusb_bulk_complete, hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1136 | |
| 1137 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 1138 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1139 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1140 | usb_anchor_urb(urb, &data->bulk_anchor); |
| 1141 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1142 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1143 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 1144 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1145 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1146 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1147 | usb_unanchor_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | usb_free_urb(urb); |
| 1151 | |
| 1152 | return err; |
| 1153 | } |
| 1154 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1155 | static void btusb_isoc_complete(struct urb *urb) |
| 1156 | { |
| 1157 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1158 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1159 | int i, err; |
| 1160 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1161 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1162 | urb->actual_length); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1163 | |
| 1164 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1165 | return; |
| 1166 | |
| 1167 | if (urb->status == 0) { |
| 1168 | for (i = 0; i < urb->number_of_packets; i++) { |
| 1169 | unsigned int offset = urb->iso_frame_desc[i].offset; |
| 1170 | unsigned int length = urb->iso_frame_desc[i].actual_length; |
| 1171 | |
| 1172 | if (urb->iso_frame_desc[i].status) |
| 1173 | continue; |
| 1174 | |
| 1175 | hdev->stat.byte_rx += length; |
| 1176 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 1177 | if (btusb_recv_isoc(data, urb->transfer_buffer + offset, |
| 1178 | length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1179 | bt_dev_err(hdev, "corrupted SCO packet"); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1180 | hdev->stat.err_rx++; |
| 1181 | } |
| 1182 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 1183 | } else if (urb->status == -ENOENT) { |
| 1184 | /* Avoid suspend failed when usb_kill_urb */ |
| 1185 | return; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags)) |
| 1189 | return; |
| 1190 | |
| 1191 | usb_anchor_urb(urb, &data->isoc_anchor); |
| 1192 | |
| 1193 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 1194 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 1195 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 1196 | * -ENODEV: device got disconnected |
| 1197 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 1198 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1199 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 1200 | urb, -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1201 | usb_unanchor_urb(urb); |
| 1202 | } |
| 1203 | } |
| 1204 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1205 | static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len, |
| 1206 | int mtu, struct btusb_data *data) |
| 1207 | { |
| 1208 | int i, offset = 0; |
| 1209 | unsigned int interval; |
| 1210 | |
| 1211 | BT_DBG("len %d mtu %d", len, mtu); |
| 1212 | |
| 1213 | /* For mSBC ALT 6 setting the host will send the packet at continuous |
| 1214 | * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting |
| 1215 | * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets. |
| 1216 | * To maintain the rate we send 63bytes of usb packets alternatively for |
| 1217 | * 7ms and 8ms to maintain the rate as 7.5ms. |
| 1218 | */ |
| 1219 | if (data->usb_alt6_packet_flow) { |
| 1220 | interval = 7; |
| 1221 | data->usb_alt6_packet_flow = false; |
| 1222 | } else { |
| 1223 | interval = 6; |
| 1224 | data->usb_alt6_packet_flow = true; |
| 1225 | } |
| 1226 | |
| 1227 | for (i = 0; i < interval; i++) { |
| 1228 | urb->iso_frame_desc[i].offset = offset; |
| 1229 | urb->iso_frame_desc[i].length = offset; |
| 1230 | } |
| 1231 | |
| 1232 | if (len && i < BTUSB_MAX_ISOC_FRAMES) { |
| 1233 | urb->iso_frame_desc[i].offset = offset; |
| 1234 | urb->iso_frame_desc[i].length = len; |
| 1235 | i++; |
| 1236 | } |
| 1237 | |
| 1238 | urb->number_of_packets = i; |
| 1239 | } |
| 1240 | |
Jesper Juhl | 42b16b3 | 2011-01-17 00:09:38 +0100 | [diff] [blame] | 1241 | 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] | 1242 | { |
| 1243 | int i, offset = 0; |
| 1244 | |
| 1245 | BT_DBG("len %d mtu %d", len, mtu); |
| 1246 | |
| 1247 | for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu; |
| 1248 | i++, offset += mtu, len -= mtu) { |
| 1249 | urb->iso_frame_desc[i].offset = offset; |
| 1250 | urb->iso_frame_desc[i].length = mtu; |
| 1251 | } |
| 1252 | |
| 1253 | if (len && i < BTUSB_MAX_ISOC_FRAMES) { |
| 1254 | urb->iso_frame_desc[i].offset = offset; |
| 1255 | urb->iso_frame_desc[i].length = len; |
| 1256 | i++; |
| 1257 | } |
| 1258 | |
| 1259 | urb->number_of_packets = i; |
| 1260 | } |
| 1261 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1262 | 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] | 1263 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1264 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1265 | struct urb *urb; |
| 1266 | unsigned char *buf; |
| 1267 | unsigned int pipe; |
| 1268 | int err, size; |
| 1269 | |
| 1270 | BT_DBG("%s", hdev->name); |
| 1271 | |
| 1272 | if (!data->isoc_rx_ep) |
| 1273 | return -ENODEV; |
| 1274 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1275 | urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1276 | if (!urb) |
| 1277 | return -ENOMEM; |
| 1278 | |
| 1279 | size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) * |
| 1280 | BTUSB_MAX_ISOC_FRAMES; |
| 1281 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1282 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1283 | if (!buf) { |
| 1284 | usb_free_urb(urb); |
| 1285 | return -ENOMEM; |
| 1286 | } |
| 1287 | |
| 1288 | pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress); |
| 1289 | |
Bing Zhao | fa0fb93 | 2011-12-20 18:19:00 -0800 | [diff] [blame] | 1290 | 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] | 1291 | hdev, data->isoc_rx_ep->bInterval); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1292 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1293 | urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1294 | |
| 1295 | __fill_isoc_descriptor(urb, size, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1296 | le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize)); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1297 | |
| 1298 | usb_anchor_urb(urb, &data->isoc_anchor); |
| 1299 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1300 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1301 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 1302 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1303 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1304 | urb, -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1305 | usb_unanchor_urb(urb); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | usb_free_urb(urb); |
| 1309 | |
| 1310 | return err; |
| 1311 | } |
| 1312 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1313 | static void btusb_diag_complete(struct urb *urb) |
| 1314 | { |
| 1315 | struct hci_dev *hdev = urb->context; |
| 1316 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1317 | int err; |
| 1318 | |
| 1319 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1320 | urb->actual_length); |
| 1321 | |
| 1322 | if (urb->status == 0) { |
| 1323 | struct sk_buff *skb; |
| 1324 | |
| 1325 | skb = bt_skb_alloc(urb->actual_length, GFP_ATOMIC); |
| 1326 | if (skb) { |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 1327 | skb_put_data(skb, urb->transfer_buffer, |
| 1328 | urb->actual_length); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1329 | hci_recv_diag(hdev, skb); |
| 1330 | } |
| 1331 | } else if (urb->status == -ENOENT) { |
| 1332 | /* Avoid suspend failed when usb_kill_urb */ |
| 1333 | return; |
| 1334 | } |
| 1335 | |
| 1336 | if (!test_bit(BTUSB_DIAG_RUNNING, &data->flags)) |
| 1337 | return; |
| 1338 | |
| 1339 | usb_anchor_urb(urb, &data->diag_anchor); |
| 1340 | usb_mark_last_busy(data->udev); |
| 1341 | |
| 1342 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 1343 | if (err < 0) { |
| 1344 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 1345 | * -ENODEV: device got disconnected |
| 1346 | */ |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1347 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1348 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 1349 | urb, -err); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1350 | usb_unanchor_urb(urb); |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | static int btusb_submit_diag_urb(struct hci_dev *hdev, gfp_t mem_flags) |
| 1355 | { |
| 1356 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1357 | struct urb *urb; |
| 1358 | unsigned char *buf; |
| 1359 | unsigned int pipe; |
| 1360 | int err, size = HCI_MAX_FRAME_SIZE; |
| 1361 | |
| 1362 | BT_DBG("%s", hdev->name); |
| 1363 | |
| 1364 | if (!data->diag_rx_ep) |
| 1365 | return -ENODEV; |
| 1366 | |
| 1367 | urb = usb_alloc_urb(0, mem_flags); |
| 1368 | if (!urb) |
| 1369 | return -ENOMEM; |
| 1370 | |
| 1371 | buf = kmalloc(size, mem_flags); |
| 1372 | if (!buf) { |
| 1373 | usb_free_urb(urb); |
| 1374 | return -ENOMEM; |
| 1375 | } |
| 1376 | |
| 1377 | pipe = usb_rcvbulkpipe(data->udev, data->diag_rx_ep->bEndpointAddress); |
| 1378 | |
| 1379 | usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, |
| 1380 | btusb_diag_complete, hdev); |
| 1381 | |
| 1382 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 1383 | |
| 1384 | usb_mark_last_busy(data->udev); |
| 1385 | usb_anchor_urb(urb, &data->diag_anchor); |
| 1386 | |
| 1387 | err = usb_submit_urb(urb, mem_flags); |
| 1388 | if (err < 0) { |
| 1389 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1390 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1391 | urb, -err); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1392 | usb_unanchor_urb(urb); |
| 1393 | } |
| 1394 | |
| 1395 | usb_free_urb(urb); |
| 1396 | |
| 1397 | return err; |
| 1398 | } |
| 1399 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1400 | static void btusb_tx_complete(struct urb *urb) |
| 1401 | { |
| 1402 | struct sk_buff *skb = urb->context; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1403 | struct hci_dev *hdev = (struct hci_dev *)skb->dev; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1404 | struct btusb_data *data = hci_get_drvdata(hdev); |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1405 | unsigned long flags; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1406 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1407 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1408 | urb->actual_length); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1409 | |
| 1410 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1411 | goto done; |
| 1412 | |
Benjamin Berg | c97a747 | 2021-12-03 15:59:02 +0100 | [diff] [blame] | 1413 | if (!urb->status) { |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1414 | hdev->stat.byte_tx += urb->transfer_buffer_length; |
Benjamin Berg | c97a747 | 2021-12-03 15:59:02 +0100 | [diff] [blame] | 1415 | } else { |
| 1416 | if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT) |
| 1417 | hci_cmd_sync_cancel(hdev, -urb->status); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1418 | hdev->stat.err_tx++; |
Benjamin Berg | c97a747 | 2021-12-03 15:59:02 +0100 | [diff] [blame] | 1419 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1420 | |
| 1421 | done: |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1422 | spin_lock_irqsave(&data->txlock, flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1423 | data->tx_in_flight--; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1424 | spin_unlock_irqrestore(&data->txlock, flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1425 | |
| 1426 | kfree(urb->setup_packet); |
| 1427 | |
| 1428 | kfree_skb(skb); |
| 1429 | } |
| 1430 | |
| 1431 | static void btusb_isoc_tx_complete(struct urb *urb) |
| 1432 | { |
| 1433 | struct sk_buff *skb = urb->context; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1434 | struct hci_dev *hdev = (struct hci_dev *)skb->dev; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1435 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1436 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1437 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1438 | |
| 1439 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1440 | goto done; |
| 1441 | |
| 1442 | if (!urb->status) |
| 1443 | hdev->stat.byte_tx += urb->transfer_buffer_length; |
| 1444 | else |
| 1445 | hdev->stat.err_tx++; |
| 1446 | |
| 1447 | done: |
| 1448 | kfree(urb->setup_packet); |
| 1449 | |
| 1450 | kfree_skb(skb); |
| 1451 | } |
| 1452 | |
| 1453 | static int btusb_open(struct hci_dev *hdev) |
| 1454 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1455 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1456 | int err; |
| 1457 | |
| 1458 | BT_DBG("%s", hdev->name); |
| 1459 | |
Ethan Hsieh | c7e163f | 2016-10-07 12:06:42 +0800 | [diff] [blame] | 1460 | err = usb_autopm_get_interface(data->intf); |
| 1461 | if (err < 0) |
| 1462 | return err; |
| 1463 | |
Kim, Ben Young Tae | ace3198 | 2015-02-15 23:06:14 +0000 | [diff] [blame] | 1464 | /* Patching USB firmware files prior to starting any URBs of HCI path |
| 1465 | * It is more safe to use USB bulk channel for downloading USB patch |
| 1466 | */ |
| 1467 | if (data->setup_on_usb) { |
| 1468 | err = data->setup_on_usb(hdev); |
Marcel Holtmann | eb50042 | 2015-04-16 23:15:50 +0200 | [diff] [blame] | 1469 | if (err < 0) |
Oliver Neukum | 3d44a6f | 2019-11-14 16:01:18 +0100 | [diff] [blame] | 1470 | goto setup_fail; |
Kim, Ben Young Tae | ace3198 | 2015-02-15 23:06:14 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1473 | data->intf->needs_remote_wakeup = 1; |
| 1474 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1475 | if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1476 | goto done; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1477 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1478 | err = btusb_submit_intr_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1479 | if (err < 0) |
| 1480 | goto failed; |
| 1481 | |
| 1482 | err = btusb_submit_bulk_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1483 | if (err < 0) { |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1484 | usb_kill_anchored_urbs(&data->intr_anchor); |
| 1485 | goto failed; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1486 | } |
| 1487 | |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1488 | set_bit(BTUSB_BULK_RUNNING, &data->flags); |
| 1489 | btusb_submit_bulk_urb(hdev, GFP_KERNEL); |
| 1490 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1491 | if (data->diag) { |
| 1492 | if (!btusb_submit_diag_urb(hdev, GFP_KERNEL)) |
| 1493 | set_bit(BTUSB_DIAG_RUNNING, &data->flags); |
| 1494 | } |
| 1495 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1496 | done: |
| 1497 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1498 | return 0; |
| 1499 | |
| 1500 | failed: |
| 1501 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Oliver Neukum | 3d44a6f | 2019-11-14 16:01:18 +0100 | [diff] [blame] | 1502 | setup_fail: |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1503 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1504 | return err; |
| 1505 | } |
| 1506 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1507 | static void btusb_stop_traffic(struct btusb_data *data) |
| 1508 | { |
| 1509 | usb_kill_anchored_urbs(&data->intr_anchor); |
| 1510 | usb_kill_anchored_urbs(&data->bulk_anchor); |
| 1511 | usb_kill_anchored_urbs(&data->isoc_anchor); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1512 | usb_kill_anchored_urbs(&data->diag_anchor); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 1513 | usb_kill_anchored_urbs(&data->ctrl_anchor); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1514 | } |
| 1515 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1516 | static int btusb_close(struct hci_dev *hdev) |
| 1517 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1518 | struct btusb_data *data = hci_get_drvdata(hdev); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1519 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1520 | |
| 1521 | BT_DBG("%s", hdev->name); |
| 1522 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 1523 | cancel_delayed_work(&data->rx_work); |
Marcel Holtmann | e8c3c3d | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 1524 | cancel_work_sync(&data->work); |
Linus Torvalds | 404291a | 2009-11-11 13:32:29 -0800 | [diff] [blame] | 1525 | cancel_work_sync(&data->waker); |
Marcel Holtmann | e8c3c3d | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 1526 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 1527 | skb_queue_purge(&data->acl_q); |
| 1528 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1529 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1530 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1531 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1532 | clear_bit(BTUSB_DIAG_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1533 | |
| 1534 | btusb_stop_traffic(data); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 1535 | btusb_free_frags(data); |
| 1536 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1537 | err = usb_autopm_get_interface(data->intf); |
| 1538 | if (err < 0) |
Oliver Neukum | 7b8e2c1 | 2009-11-13 14:26:23 +0100 | [diff] [blame] | 1539 | goto failed; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1540 | |
| 1541 | data->intf->needs_remote_wakeup = 0; |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 1542 | |
| 1543 | /* Enable remote wake up for auto-suspend */ |
Max Chou | 8274db0 | 2021-08-17 11:03:12 +0800 | [diff] [blame] | 1544 | if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 1545 | data->intf->needs_remote_wakeup = 1; |
| 1546 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1547 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1548 | |
Oliver Neukum | 7b8e2c1 | 2009-11-13 14:26:23 +0100 | [diff] [blame] | 1549 | failed: |
| 1550 | usb_scuttle_anchored_urbs(&data->deferred); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1551 | return 0; |
| 1552 | } |
| 1553 | |
| 1554 | static int btusb_flush(struct hci_dev *hdev) |
| 1555 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1556 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1557 | |
| 1558 | BT_DBG("%s", hdev->name); |
| 1559 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 1560 | cancel_delayed_work(&data->rx_work); |
| 1561 | |
| 1562 | skb_queue_purge(&data->acl_q); |
| 1563 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1564 | usb_kill_anchored_urbs(&data->tx_anchor); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 1565 | btusb_free_frags(data); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1566 | |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1570 | 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] | 1571 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1572 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1573 | struct usb_ctrlrequest *dr; |
| 1574 | struct urb *urb; |
| 1575 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1576 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1577 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1578 | if (!urb) |
| 1579 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1580 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1581 | dr = kmalloc(sizeof(*dr), GFP_KERNEL); |
| 1582 | if (!dr) { |
| 1583 | usb_free_urb(urb); |
| 1584 | return ERR_PTR(-ENOMEM); |
| 1585 | } |
| 1586 | |
| 1587 | dr->bRequestType = data->cmdreq_type; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 1588 | dr->bRequest = data->cmdreq; |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1589 | dr->wIndex = 0; |
| 1590 | dr->wValue = 0; |
| 1591 | dr->wLength = __cpu_to_le16(skb->len); |
| 1592 | |
| 1593 | pipe = usb_sndctrlpipe(data->udev, 0x00); |
| 1594 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1595 | usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1596 | skb->data, skb->len, btusb_tx_complete, skb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1597 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1598 | skb->dev = (void *)hdev; |
Marcel Holtmann | 7bd8f09 | 2013-10-11 06:19:18 -0700 | [diff] [blame] | 1599 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1600 | return urb; |
| 1601 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1602 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1603 | static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb) |
| 1604 | { |
| 1605 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1606 | struct urb *urb; |
| 1607 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1608 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1609 | if (!data->bulk_tx_ep) |
| 1610 | return ERR_PTR(-ENODEV); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1611 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1612 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1613 | if (!urb) |
| 1614 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1615 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1616 | pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1617 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1618 | usb_fill_bulk_urb(urb, data->udev, pipe, |
| 1619 | skb->data, skb->len, btusb_tx_complete, skb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1620 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1621 | skb->dev = (void *)hdev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1622 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1623 | return urb; |
| 1624 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1625 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1626 | static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb) |
| 1627 | { |
| 1628 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1629 | struct urb *urb; |
| 1630 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1631 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1632 | if (!data->isoc_tx_ep) |
| 1633 | return ERR_PTR(-ENODEV); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1634 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1635 | urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL); |
| 1636 | if (!urb) |
| 1637 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1638 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1639 | pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1640 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1641 | usb_fill_int_urb(urb, data->udev, pipe, |
| 1642 | skb->data, skb->len, btusb_isoc_tx_complete, |
| 1643 | skb, data->isoc_tx_ep->bInterval); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1644 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1645 | urb->transfer_flags = URB_ISO_ASAP; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1646 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1647 | if (data->isoc_altsetting == 6) |
| 1648 | __fill_isoc_descriptor_msbc(urb, skb->len, |
| 1649 | le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize), |
| 1650 | data); |
| 1651 | else |
| 1652 | __fill_isoc_descriptor(urb, skb->len, |
| 1653 | le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1654 | skb->dev = (void *)hdev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1655 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1656 | return urb; |
| 1657 | } |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1658 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1659 | static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb) |
| 1660 | { |
| 1661 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1662 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1663 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1664 | usb_anchor_urb(urb, &data->tx_anchor); |
| 1665 | |
Johan Hedberg | e9753ef | 2014-09-14 08:49:34 +0300 | [diff] [blame] | 1666 | err = usb_submit_urb(urb, GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1667 | if (err < 0) { |
Paul Bolle | 5a9b80e | 2011-10-09 12:12:16 +0200 | [diff] [blame] | 1668 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1669 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1670 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1671 | kfree(urb->setup_packet); |
| 1672 | usb_unanchor_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1673 | } else { |
| 1674 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1675 | } |
| 1676 | |
Cong Wang | 54a8a79 | 2011-11-22 09:32:57 +0800 | [diff] [blame] | 1677 | usb_free_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1678 | return err; |
| 1679 | } |
| 1680 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1681 | static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb) |
| 1682 | { |
| 1683 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1684 | unsigned long flags; |
| 1685 | bool suspending; |
| 1686 | |
| 1687 | spin_lock_irqsave(&data->txlock, flags); |
| 1688 | suspending = test_bit(BTUSB_SUSPENDING, &data->flags); |
| 1689 | if (!suspending) |
| 1690 | data->tx_in_flight++; |
| 1691 | spin_unlock_irqrestore(&data->txlock, flags); |
| 1692 | |
| 1693 | if (!suspending) |
| 1694 | return submit_tx_urb(hdev, urb); |
| 1695 | |
| 1696 | usb_anchor_urb(urb, &data->deferred); |
| 1697 | schedule_work(&data->waker); |
| 1698 | |
| 1699 | usb_free_urb(urb); |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
| 1703 | static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb) |
| 1704 | { |
| 1705 | struct urb *urb; |
| 1706 | |
| 1707 | BT_DBG("%s", hdev->name); |
| 1708 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 1709 | switch (hci_skb_pkt_type(skb)) { |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1710 | case HCI_COMMAND_PKT: |
| 1711 | urb = alloc_ctrl_urb(hdev, skb); |
| 1712 | if (IS_ERR(urb)) |
| 1713 | return PTR_ERR(urb); |
| 1714 | |
| 1715 | hdev->stat.cmd_tx++; |
| 1716 | return submit_or_queue_tx_urb(hdev, urb); |
| 1717 | |
| 1718 | case HCI_ACLDATA_PKT: |
| 1719 | urb = alloc_bulk_urb(hdev, skb); |
| 1720 | if (IS_ERR(urb)) |
| 1721 | return PTR_ERR(urb); |
| 1722 | |
| 1723 | hdev->stat.acl_tx++; |
| 1724 | return submit_or_queue_tx_urb(hdev, urb); |
| 1725 | |
| 1726 | case HCI_SCODATA_PKT: |
| 1727 | if (hci_conn_num(hdev, SCO_LINK) < 1) |
| 1728 | return -ENODEV; |
| 1729 | |
| 1730 | urb = alloc_isoc_urb(hdev, skb); |
| 1731 | if (IS_ERR(urb)) |
| 1732 | return PTR_ERR(urb); |
| 1733 | |
| 1734 | hdev->stat.sco_tx++; |
| 1735 | return submit_tx_urb(hdev, urb); |
| 1736 | } |
| 1737 | |
| 1738 | return -EILSEQ; |
| 1739 | } |
| 1740 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1741 | static void btusb_notify(struct hci_dev *hdev, unsigned int evt) |
| 1742 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1743 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1744 | |
| 1745 | BT_DBG("%s evt %d", hdev->name, evt); |
| 1746 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1747 | if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) { |
| 1748 | data->sco_num = hci_conn_num(hdev, SCO_LINK); |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1749 | data->air_mode = evt; |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1750 | schedule_work(&data->work); |
Marcel Holtmann | a780efa | 2008-11-30 12:17:12 +0100 | [diff] [blame] | 1751 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1752 | } |
| 1753 | |
Jesper Juhl | 42b16b3 | 2011-01-17 00:09:38 +0100 | [diff] [blame] | 1754 | static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting) |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1755 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1756 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1757 | struct usb_interface *intf = data->isoc; |
| 1758 | struct usb_endpoint_descriptor *ep_desc; |
| 1759 | int i, err; |
| 1760 | |
| 1761 | if (!data->isoc) |
| 1762 | return -ENODEV; |
| 1763 | |
Marcel Holtmann | 459232f | 2017-10-24 19:42:45 +0200 | [diff] [blame] | 1764 | err = usb_set_interface(data->udev, data->isoc_ifnum, altsetting); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1765 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1766 | bt_dev_err(hdev, "setting interface failed (%d)", -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1767 | return err; |
| 1768 | } |
| 1769 | |
| 1770 | data->isoc_altsetting = altsetting; |
| 1771 | |
| 1772 | data->isoc_tx_ep = NULL; |
| 1773 | data->isoc_rx_ep = NULL; |
| 1774 | |
| 1775 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 1776 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 1777 | |
| 1778 | if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) { |
| 1779 | data->isoc_tx_ep = ep_desc; |
| 1780 | continue; |
| 1781 | } |
| 1782 | |
| 1783 | if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) { |
| 1784 | data->isoc_rx_ep = ep_desc; |
| 1785 | continue; |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | if (!data->isoc_tx_ep || !data->isoc_rx_ep) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1790 | bt_dev_err(hdev, "invalid SCO descriptors"); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1791 | return -ENODEV; |
| 1792 | } |
| 1793 | |
| 1794 | return 0; |
| 1795 | } |
| 1796 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1797 | static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts) |
| 1798 | { |
| 1799 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1800 | int err; |
| 1801 | |
| 1802 | if (data->isoc_altsetting != new_alts) { |
| 1803 | unsigned long flags; |
| 1804 | |
| 1805 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1806 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1807 | |
| 1808 | /* When isochronous alternate setting needs to be |
| 1809 | * changed, because SCO connection has been added |
| 1810 | * or removed, a packet fragment may be left in the |
| 1811 | * reassembling state. This could lead to wrongly |
| 1812 | * assembled fragments. |
| 1813 | * |
| 1814 | * Clear outstanding fragment when selecting a new |
| 1815 | * alternate setting. |
| 1816 | */ |
| 1817 | spin_lock_irqsave(&data->rxlock, flags); |
| 1818 | kfree_skb(data->sco_skb); |
| 1819 | data->sco_skb = NULL; |
| 1820 | spin_unlock_irqrestore(&data->rxlock, flags); |
| 1821 | |
| 1822 | err = __set_isoc_interface(hdev, new_alts); |
| 1823 | if (err < 0) |
| 1824 | return err; |
| 1825 | } |
| 1826 | |
| 1827 | if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
| 1828 | if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0) |
| 1829 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1830 | else |
| 1831 | btusb_submit_isoc_urb(hdev, GFP_KERNEL); |
| 1832 | } |
| 1833 | |
| 1834 | return 0; |
| 1835 | } |
| 1836 | |
| 1837 | static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data, |
| 1838 | int alt) |
| 1839 | { |
| 1840 | struct usb_interface *intf = data->isoc; |
| 1841 | int i; |
| 1842 | |
| 1843 | BT_DBG("Looking for Alt no :%d", alt); |
| 1844 | |
Sathish Narasimman | fcd156ee | 2020-04-08 10:57:03 +0530 | [diff] [blame] | 1845 | if (!intf) |
| 1846 | return NULL; |
| 1847 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1848 | for (i = 0; i < intf->num_altsetting; i++) { |
| 1849 | if (intf->altsetting[i].desc.bAlternateSetting == alt) |
| 1850 | return &intf->altsetting[i]; |
| 1851 | } |
| 1852 | |
| 1853 | return NULL; |
| 1854 | } |
| 1855 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1856 | static void btusb_work(struct work_struct *work) |
| 1857 | { |
| 1858 | struct btusb_data *data = container_of(work, struct btusb_data, work); |
| 1859 | struct hci_dev *hdev = data->hdev; |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1860 | int new_alts = 0; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1861 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1862 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1863 | if (data->sco_num > 0) { |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1864 | if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) { |
Oliver Neukum | 8efdd0c | 2011-02-11 13:00:06 +0100 | [diff] [blame] | 1865 | err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1866 | if (err < 0) { |
| 1867 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1868 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1869 | return; |
| 1870 | } |
| 1871 | |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1872 | set_bit(BTUSB_DID_ISO_RESUME, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1873 | } |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1874 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1875 | if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) { |
| 1876 | if (hdev->voice_setting & 0x0020) { |
| 1877 | static const int alts[3] = { 2, 4, 5 }; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1878 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1879 | new_alts = alts[data->sco_num - 1]; |
| 1880 | } else { |
| 1881 | new_alts = data->sco_num; |
| 1882 | } |
| 1883 | } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) { |
Trent Piepho | 517b693 | 2020-12-09 17:20:03 -0800 | [diff] [blame] | 1884 | /* Bluetooth USB spec recommends alt 6 (63 bytes), but |
| 1885 | * many adapters do not support it. Alt 1 appears to |
| 1886 | * work for all adapters that do not have alt 6, and |
Pauli Virtanen | 55981d3 | 2021-07-26 21:02:06 +0300 | [diff] [blame] | 1887 | * which work with WBS at all. Some devices prefer |
| 1888 | * alt 3 (HCI payload >= 60 Bytes let air packet |
| 1889 | * data satisfy 60 bytes), requiring |
| 1890 | * MTU >= 3 (packets) * 25 (size) - 3 (headers) = 72 |
| 1891 | * see also Core spec 5, vol 4, B 2.1.1 & Table 2.1. |
Trent Piepho | 517b693 | 2020-12-09 17:20:03 -0800 | [diff] [blame] | 1892 | */ |
Pauli Virtanen | 55981d3 | 2021-07-26 21:02:06 +0300 | [diff] [blame] | 1893 | if (btusb_find_altsetting(data, 6)) |
| 1894 | new_alts = 6; |
| 1895 | else if (btusb_find_altsetting(data, 3) && |
| 1896 | hdev->sco_mtu >= 72 && |
| 1897 | test_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags)) |
Hilda Wu | e848dbd | 2021-05-14 11:19:01 +0800 | [diff] [blame] | 1898 | new_alts = 3; |
Pauli Virtanen | 55981d3 | 2021-07-26 21:02:06 +0300 | [diff] [blame] | 1899 | else |
| 1900 | new_alts = 1; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1901 | } |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1902 | |
| 1903 | if (btusb_switch_alt_setting(hdev, new_alts) < 0) |
| 1904 | bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1905 | } else { |
| 1906 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1907 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1908 | |
| 1909 | __set_isoc_interface(hdev, 0); |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1910 | if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags)) |
Oliver Neukum | 8efdd0c | 2011-02-11 13:00:06 +0100 | [diff] [blame] | 1911 | usb_autopm_put_interface(data->isoc ? data->isoc : data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1912 | } |
| 1913 | } |
| 1914 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1915 | static void btusb_waker(struct work_struct *work) |
| 1916 | { |
| 1917 | struct btusb_data *data = container_of(work, struct btusb_data, waker); |
| 1918 | int err; |
| 1919 | |
| 1920 | err = usb_autopm_get_interface(data->intf); |
| 1921 | if (err < 0) |
| 1922 | return; |
| 1923 | |
| 1924 | usb_autopm_put_interface(data->intf); |
| 1925 | } |
| 1926 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 1927 | static void btusb_rx_work(struct work_struct *work) |
| 1928 | { |
| 1929 | struct btusb_data *data = container_of(work, struct btusb_data, |
| 1930 | rx_work.work); |
| 1931 | struct sk_buff *skb; |
| 1932 | |
| 1933 | /* Dequeue ACL data received during the interval */ |
| 1934 | while ((skb = skb_dequeue(&data->acl_q))) |
| 1935 | data->recv_acl(data->hdev, skb); |
| 1936 | } |
| 1937 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 1938 | static int btusb_setup_bcm92035(struct hci_dev *hdev) |
| 1939 | { |
| 1940 | struct sk_buff *skb; |
| 1941 | u8 val = 0x00; |
| 1942 | |
| 1943 | BT_DBG("%s", hdev->name); |
| 1944 | |
| 1945 | skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT); |
| 1946 | if (IS_ERR(skb)) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1947 | bt_dev_err(hdev, "BCM92035 command failed (%ld)", PTR_ERR(skb)); |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 1948 | else |
| 1949 | kfree_skb(skb); |
| 1950 | |
| 1951 | return 0; |
| 1952 | } |
| 1953 | |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1954 | static int btusb_setup_csr(struct hci_dev *hdev) |
| 1955 | { |
Hans de Goede | d74e0ae | 2020-12-05 16:02:00 +0100 | [diff] [blame] | 1956 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1957 | u16 bcdDevice = le16_to_cpu(data->udev->descriptor.bcdDevice); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1958 | struct hci_rp_read_local_version *rp; |
| 1959 | struct sk_buff *skb; |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 1960 | bool is_fake = false; |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 1961 | int ret; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1962 | |
| 1963 | BT_DBG("%s", hdev->name); |
| 1964 | |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1965 | skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL, |
| 1966 | HCI_INIT_TIMEOUT); |
| 1967 | if (IS_ERR(skb)) { |
| 1968 | int err = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1969 | bt_dev_err(hdev, "CSR: Local version failed (%d)", err); |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1970 | return err; |
| 1971 | } |
| 1972 | |
| 1973 | if (skb->len != sizeof(struct hci_rp_read_local_version)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1974 | bt_dev_err(hdev, "CSR: Local version length mismatch"); |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1975 | kfree_skb(skb); |
| 1976 | return -EIO; |
| 1977 | } |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1978 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1979 | rp = (struct hci_rp_read_local_version *)skb->data; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1980 | |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 1981 | /* Detect a wide host of Chinese controllers that aren't CSR. |
| 1982 | * |
| 1983 | * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891 |
| 1984 | * |
| 1985 | * The main thing they have in common is that these are really popular low-cost |
| 1986 | * options that support newer Bluetooth versions but rely on heavy VID/PID |
| 1987 | * squatting of this poor old Bluetooth 1.1 device. Even sold as such. |
| 1988 | * |
| 1989 | * We detect actual CSR devices by checking that the HCI manufacturer code |
| 1990 | * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and |
| 1991 | * HCI rev values always match. As they both store the firmware number. |
| 1992 | */ |
Johan Hedberg | 6cafcd9 | 2015-08-30 21:47:21 +0300 | [diff] [blame] | 1993 | if (le16_to_cpu(rp->manufacturer) != 10 || |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 1994 | le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver)) |
| 1995 | is_fake = true; |
| 1996 | |
| 1997 | /* Known legit CSR firmware build numbers and their supported BT versions: |
| 1998 | * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e |
| 1999 | * - 1.2 (0x2) -> 0x04d9, 0x0529 |
| 2000 | * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c |
| 2001 | * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External) |
| 2002 | * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb |
| 2003 | * |
| 2004 | * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that |
| 2005 | * support BT 1.1 only; so it's a dead giveaway when some |
| 2006 | * third-party BT 4.0 dongle reuses it. |
| 2007 | */ |
| 2008 | else if (le16_to_cpu(rp->lmp_subver) <= 0x034e && |
| 2009 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_1) |
| 2010 | is_fake = true; |
| 2011 | |
| 2012 | else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 && |
| 2013 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_2) |
| 2014 | is_fake = true; |
| 2015 | |
| 2016 | else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c && |
| 2017 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_0) |
| 2018 | is_fake = true; |
| 2019 | |
| 2020 | else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 && |
| 2021 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_1) |
| 2022 | is_fake = true; |
| 2023 | |
| 2024 | else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb && |
| 2025 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_4_0) |
| 2026 | is_fake = true; |
| 2027 | |
Hans de Goede | d74e0ae | 2020-12-05 16:02:00 +0100 | [diff] [blame] | 2028 | /* Other clones which beat all the above checks */ |
| 2029 | else if (bcdDevice == 0x0134 && |
| 2030 | le16_to_cpu(rp->lmp_subver) == 0x0c5c && |
| 2031 | le16_to_cpu(rp->hci_ver) == BLUETOOTH_VER_2_0) |
| 2032 | is_fake = true; |
| 2033 | |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 2034 | if (is_fake) { |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2035 | bt_dev_warn(hdev, "CSR: Unbranded CSR clone detected; adding workarounds and force-suspending once..."); |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 2036 | |
| 2037 | /* Generally these clones have big discrepancies between |
| 2038 | * advertised features and what's actually supported. |
| 2039 | * Probably will need to be expanded in the future; |
| 2040 | * without these the controller will lock up. |
| 2041 | */ |
| 2042 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
| 2043 | set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks); |
| 2044 | |
Marcel Holtmann | 9641d34 | 2015-06-07 10:01:01 +0200 | [diff] [blame] | 2045 | /* Clear the reset quirk since this is not an actual |
| 2046 | * early Bluetooth 1.1 device from CSR. |
| 2047 | */ |
| 2048 | clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 2049 | clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2050 | |
| 2051 | /* |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2052 | * Special workaround for these BT 4.0 chip clones, and potentially more: |
| 2053 | * |
| 2054 | * - 0x0134: a Barrot 8041a02 (HCI rev: 0x1012 sub: 0x0810) |
| 2055 | * - 0x7558: IC markings FR3191AHAL 749H15143 (HCI rev/sub-version: 0x0709) |
| 2056 | * |
| 2057 | * These controllers are really messed-up. |
| 2058 | * |
| 2059 | * 1. Their bulk RX endpoint will never report any data unless |
| 2060 | * the device was suspended at least once (yes, really). |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2061 | * 2. They will not wakeup when autosuspended and receiving data |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2062 | * on their bulk RX endpoint from e.g. a keyboard or mouse |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2063 | * (IOW remote-wakeup support is broken for the bulk endpoint). |
| 2064 | * |
| 2065 | * To fix 1. enable runtime-suspend, force-suspend the |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2066 | * HCI and then wake-it up by disabling runtime-suspend. |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2067 | * |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2068 | * To fix 2. clear the HCI's can_wake flag, this way the HCI |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2069 | * will still be autosuspended when it is not open. |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2070 | * |
| 2071 | * -- |
| 2072 | * |
| 2073 | * Because these are widespread problems we prefer generic solutions; so |
| 2074 | * apply this initialization quirk to every controller that gets here, |
| 2075 | * it should be harmless. The alternative is to not work at all. |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2076 | */ |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2077 | pm_runtime_allow(&data->udev->dev); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2078 | |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2079 | ret = pm_runtime_suspend(&data->udev->dev); |
| 2080 | if (ret >= 0) |
| 2081 | msleep(200); |
| 2082 | else |
| 2083 | bt_dev_err(hdev, "CSR: Failed to suspend the device for our Barrot 8041a02 receive-issue workaround"); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2084 | |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2085 | pm_runtime_forbid(&data->udev->dev); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2086 | |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2087 | device_set_wakeup_capable(&data->udev->dev, false); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 2088 | |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 2089 | /* Re-enable autosuspend if this was requested */ |
| 2090 | if (enable_autosuspend) |
| 2091 | usb_enable_autosuspend(data->udev); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 2092 | } |
| 2093 | |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 2094 | kfree_skb(skb); |
| 2095 | |
Marcel Holtmann | 9641d34 | 2015-06-07 10:01:01 +0200 | [diff] [blame] | 2096 | return 0; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 2097 | } |
| 2098 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2099 | static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode) |
| 2100 | { |
| 2101 | struct sk_buff *skb; |
| 2102 | struct hci_event_hdr *hdr; |
| 2103 | struct hci_ev_cmd_complete *evt; |
| 2104 | |
Jia-Ju Bai | cf07e34 | 2018-07-23 11:38:51 +0800 | [diff] [blame] | 2105 | skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2106 | if (!skb) |
| 2107 | return -ENOMEM; |
| 2108 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 2109 | hdr = skb_put(skb, sizeof(*hdr)); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2110 | hdr->evt = HCI_EV_CMD_COMPLETE; |
| 2111 | hdr->plen = sizeof(*evt) + 1; |
| 2112 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 2113 | evt = skb_put(skb, sizeof(*evt)); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2114 | evt->ncmd = 0x01; |
| 2115 | evt->opcode = cpu_to_le16(opcode); |
| 2116 | |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 2117 | skb_put_u8(skb, 0x00); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2118 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 2119 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2120 | |
| 2121 | return hci_recv_frame(hdev, skb); |
| 2122 | } |
| 2123 | |
| 2124 | static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer, |
| 2125 | int count) |
| 2126 | { |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 2127 | struct hci_dev *hdev = data->hdev; |
| 2128 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2129 | /* When the device is in bootloader mode, then it can send |
| 2130 | * events via the bulk endpoint. These events are treated the |
| 2131 | * same way as the ones received from the interrupt endpoint. |
| 2132 | */ |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 2133 | if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2134 | return btusb_recv_intr(data, buffer, count); |
| 2135 | |
| 2136 | return btusb_recv_bulk(data, buffer, count); |
| 2137 | } |
| 2138 | |
| 2139 | static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb) |
| 2140 | { |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 2141 | if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2142 | struct hci_event_hdr *hdr = (void *)skb->data; |
| 2143 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2144 | if (skb->len > HCI_EVENT_HDR_SIZE && hdr->evt == 0xff && |
| 2145 | hdr->plen > 0) { |
| 2146 | const void *ptr = skb->data + HCI_EVENT_HDR_SIZE + 1; |
| 2147 | unsigned int len = skb->len - HCI_EVENT_HDR_SIZE - 1; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2148 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2149 | switch (skb->data[2]) { |
| 2150 | case 0x02: |
| 2151 | /* When switching to the operational firmware |
| 2152 | * the device sends a vendor specific event |
| 2153 | * indicating that the bootup completed. |
| 2154 | */ |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 2155 | btintel_bootup(hdev, ptr, len); |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2156 | break; |
| 2157 | case 0x06: |
| 2158 | /* When the firmware loading completes the |
| 2159 | * device sends out a vendor specific event |
| 2160 | * indicating the result of the firmware |
| 2161 | * loading. |
| 2162 | */ |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 2163 | btintel_secure_send_result(hdev, ptr, len); |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2164 | break; |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2165 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2166 | } |
| 2167 | } |
| 2168 | |
| 2169 | return hci_recv_frame(hdev, skb); |
| 2170 | } |
| 2171 | |
| 2172 | static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) |
| 2173 | { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2174 | struct urb *urb; |
| 2175 | |
| 2176 | BT_DBG("%s", hdev->name); |
| 2177 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 2178 | switch (hci_skb_pkt_type(skb)) { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2179 | case HCI_COMMAND_PKT: |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 2180 | if (btintel_test_flag(hdev, INTEL_BOOTLOADER)) { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2181 | struct hci_command_hdr *cmd = (void *)skb->data; |
| 2182 | __u16 opcode = le16_to_cpu(cmd->opcode); |
| 2183 | |
| 2184 | /* When in bootloader mode and the command 0xfc09 |
| 2185 | * is received, it needs to be send down the |
| 2186 | * bulk endpoint. So allocate a bulk URB instead. |
| 2187 | */ |
| 2188 | if (opcode == 0xfc09) |
| 2189 | urb = alloc_bulk_urb(hdev, skb); |
| 2190 | else |
| 2191 | urb = alloc_ctrl_urb(hdev, skb); |
| 2192 | |
| 2193 | /* When the 0xfc01 command is issued to boot into |
| 2194 | * the operational firmware, it will actually not |
| 2195 | * send a command complete event. To keep the flow |
| 2196 | * control working inject that event here. |
| 2197 | */ |
| 2198 | if (opcode == 0xfc01) |
| 2199 | inject_cmd_complete(hdev, opcode); |
| 2200 | } else { |
| 2201 | urb = alloc_ctrl_urb(hdev, skb); |
| 2202 | } |
| 2203 | if (IS_ERR(urb)) |
| 2204 | return PTR_ERR(urb); |
| 2205 | |
| 2206 | hdev->stat.cmd_tx++; |
| 2207 | return submit_or_queue_tx_urb(hdev, urb); |
| 2208 | |
| 2209 | case HCI_ACLDATA_PKT: |
| 2210 | urb = alloc_bulk_urb(hdev, skb); |
| 2211 | if (IS_ERR(urb)) |
| 2212 | return PTR_ERR(urb); |
| 2213 | |
| 2214 | hdev->stat.acl_tx++; |
| 2215 | return submit_or_queue_tx_urb(hdev, urb); |
| 2216 | |
| 2217 | case HCI_SCODATA_PKT: |
| 2218 | if (hci_conn_num(hdev, SCO_LINK) < 1) |
| 2219 | return -ENODEV; |
| 2220 | |
| 2221 | urb = alloc_isoc_urb(hdev, skb); |
| 2222 | if (IS_ERR(urb)) |
| 2223 | return PTR_ERR(urb); |
| 2224 | |
| 2225 | hdev->stat.sco_tx++; |
| 2226 | return submit_tx_urb(hdev, urb); |
| 2227 | } |
| 2228 | |
| 2229 | return -EILSEQ; |
| 2230 | } |
| 2231 | |
mark-yw.chen | e947802 | 2021-08-04 17:06:47 +0800 | [diff] [blame] | 2232 | /* UHW CR mapping */ |
| 2233 | #define MTK_BT_MISC 0x70002510 |
| 2234 | #define MTK_BT_SUBSYS_RST 0x70002610 |
| 2235 | #define MTK_UDMA_INT_STA_BT 0x74000024 |
| 2236 | #define MTK_UDMA_INT_STA_BT1 0x74000308 |
| 2237 | #define MTK_BT_WDT_STATUS 0x740003A0 |
| 2238 | #define MTK_EP_RST_OPT 0x74011890 |
| 2239 | #define MTK_EP_RST_IN_OUT_OPT 0x00010001 |
| 2240 | #define MTK_BT_RST_DONE 0x00000100 |
| 2241 | #define MTK_BT_RESET_WAIT_MS 100 |
| 2242 | #define MTK_BT_RESET_NUM_TRIES 10 |
mark-yw.chen | 5a87679 | 2021-09-01 11:32:25 +0800 | [diff] [blame] | 2243 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2244 | static void btusb_mtk_wmt_recv(struct urb *urb) |
| 2245 | { |
| 2246 | struct hci_dev *hdev = urb->context; |
| 2247 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2248 | struct hci_event_hdr *hdr; |
| 2249 | struct sk_buff *skb; |
| 2250 | int err; |
| 2251 | |
| 2252 | if (urb->status == 0 && urb->actual_length > 0) { |
| 2253 | hdev->stat.byte_rx += urb->actual_length; |
| 2254 | |
| 2255 | /* WMT event shouldn't be fragmented and the size should be |
| 2256 | * less than HCI_WMT_MAX_EVENT_SIZE. |
| 2257 | */ |
| 2258 | skb = bt_skb_alloc(HCI_WMT_MAX_EVENT_SIZE, GFP_ATOMIC); |
| 2259 | if (!skb) { |
| 2260 | hdev->stat.err_rx++; |
Mark-YW.Chen | 60c6a63 | 2021-10-14 00:22:04 +0800 | [diff] [blame] | 2261 | kfree(urb->setup_packet); |
Jupeng Zhong | de71a6c | 2021-02-02 09:39:13 +0800 | [diff] [blame] | 2262 | return; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
| 2266 | skb_put_data(skb, urb->transfer_buffer, urb->actual_length); |
| 2267 | |
| 2268 | hdr = (void *)skb->data; |
| 2269 | /* Fix up the vendor event id with 0xff for vendor specific |
| 2270 | * instead of 0xe4 so that event send via monitoring socket can |
| 2271 | * be parsed properly. |
| 2272 | */ |
| 2273 | hdr->evt = 0xff; |
| 2274 | |
| 2275 | /* When someone waits for the WMT event, the skb is being cloned |
| 2276 | * and being processed the events from there then. |
| 2277 | */ |
| 2278 | if (test_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags)) { |
Johan Hovold | 22cc6b7 | 2019-11-28 19:24:27 +0100 | [diff] [blame] | 2279 | data->evt_skb = skb_clone(skb, GFP_ATOMIC); |
Jupeng Zhong | de71a6c | 2021-02-02 09:39:13 +0800 | [diff] [blame] | 2280 | if (!data->evt_skb) { |
| 2281 | kfree_skb(skb); |
Mark-YW.Chen | 60c6a63 | 2021-10-14 00:22:04 +0800 | [diff] [blame] | 2282 | kfree(urb->setup_packet); |
Jupeng Zhong | de71a6c | 2021-02-02 09:39:13 +0800 | [diff] [blame] | 2283 | return; |
| 2284 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | err = hci_recv_frame(hdev, skb); |
Jupeng Zhong | de71a6c | 2021-02-02 09:39:13 +0800 | [diff] [blame] | 2288 | if (err < 0) { |
| 2289 | kfree_skb(data->evt_skb); |
| 2290 | data->evt_skb = NULL; |
Mark-YW.Chen | 60c6a63 | 2021-10-14 00:22:04 +0800 | [diff] [blame] | 2291 | kfree(urb->setup_packet); |
Jupeng Zhong | de71a6c | 2021-02-02 09:39:13 +0800 | [diff] [blame] | 2292 | return; |
| 2293 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2294 | |
| 2295 | if (test_and_clear_bit(BTUSB_TX_WAIT_VND_EVT, |
| 2296 | &data->flags)) { |
| 2297 | /* Barrier to sync with other CPUs */ |
| 2298 | smp_mb__after_atomic(); |
| 2299 | wake_up_bit(&data->flags, |
| 2300 | BTUSB_TX_WAIT_VND_EVT); |
| 2301 | } |
Mark-YW.Chen | 60c6a63 | 2021-10-14 00:22:04 +0800 | [diff] [blame] | 2302 | kfree(urb->setup_packet); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2303 | return; |
| 2304 | } else if (urb->status == -ENOENT) { |
| 2305 | /* Avoid suspend failed when usb_kill_urb */ |
| 2306 | return; |
| 2307 | } |
| 2308 | |
| 2309 | usb_mark_last_busy(data->udev); |
| 2310 | |
| 2311 | /* The URB complete handler is still called with urb->actual_length = 0 |
| 2312 | * when the event is not available, so we should keep re-submitting |
| 2313 | * URB until WMT event returns, Also, It's necessary to wait some time |
| 2314 | * between the two consecutive control URBs to relax the target device |
| 2315 | * to generate the event. Otherwise, the WMT event cannot return from |
| 2316 | * the device successfully. |
| 2317 | */ |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 2318 | udelay(500); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2319 | |
| 2320 | usb_anchor_urb(urb, &data->ctrl_anchor); |
| 2321 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 2322 | if (err < 0) { |
Mark-YW.Chen | 60c6a63 | 2021-10-14 00:22:04 +0800 | [diff] [blame] | 2323 | kfree(urb->setup_packet); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2324 | /* -EPERM: urb is being killed; |
| 2325 | * -ENODEV: device got disconnected |
| 2326 | */ |
| 2327 | if (err != -EPERM && err != -ENODEV) |
| 2328 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 2329 | urb, -err); |
| 2330 | usb_unanchor_urb(urb); |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | static int btusb_mtk_submit_wmt_recv_urb(struct hci_dev *hdev) |
| 2335 | { |
| 2336 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2337 | struct usb_ctrlrequest *dr; |
| 2338 | unsigned char *buf; |
| 2339 | int err, size = 64; |
| 2340 | unsigned int pipe; |
| 2341 | struct urb *urb; |
| 2342 | |
| 2343 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 2344 | if (!urb) |
| 2345 | return -ENOMEM; |
| 2346 | |
| 2347 | dr = kmalloc(sizeof(*dr), GFP_KERNEL); |
| 2348 | if (!dr) { |
| 2349 | usb_free_urb(urb); |
| 2350 | return -ENOMEM; |
| 2351 | } |
| 2352 | |
| 2353 | dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_IN; |
| 2354 | dr->bRequest = 1; |
| 2355 | dr->wIndex = cpu_to_le16(0); |
| 2356 | dr->wValue = cpu_to_le16(48); |
| 2357 | dr->wLength = cpu_to_le16(size); |
| 2358 | |
| 2359 | buf = kmalloc(size, GFP_KERNEL); |
| 2360 | if (!buf) { |
| 2361 | kfree(dr); |
Dinghao Liu | d33fe77 | 2020-08-23 15:44:21 +0800 | [diff] [blame] | 2362 | usb_free_urb(urb); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2363 | return -ENOMEM; |
| 2364 | } |
| 2365 | |
| 2366 | pipe = usb_rcvctrlpipe(data->udev, 0); |
| 2367 | |
| 2368 | usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, |
| 2369 | buf, size, btusb_mtk_wmt_recv, hdev); |
| 2370 | |
| 2371 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 2372 | |
| 2373 | usb_anchor_urb(urb, &data->ctrl_anchor); |
| 2374 | err = usb_submit_urb(urb, GFP_KERNEL); |
| 2375 | if (err < 0) { |
| 2376 | if (err != -EPERM && err != -ENODEV) |
| 2377 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 2378 | urb, -err); |
| 2379 | usb_unanchor_urb(urb); |
| 2380 | } |
| 2381 | |
| 2382 | usb_free_urb(urb); |
| 2383 | |
| 2384 | return err; |
| 2385 | } |
| 2386 | |
| 2387 | static int btusb_mtk_hci_wmt_sync(struct hci_dev *hdev, |
| 2388 | struct btmtk_hci_wmt_params *wmt_params) |
| 2389 | { |
| 2390 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2391 | struct btmtk_hci_wmt_evt_funcc *wmt_evt_funcc; |
| 2392 | u32 hlen, status = BTMTK_WMT_INVALID; |
| 2393 | struct btmtk_hci_wmt_evt *wmt_evt; |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 2394 | struct btmtk_hci_wmt_cmd *wc; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2395 | struct btmtk_wmt_hdr *hdr; |
| 2396 | int err; |
| 2397 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2398 | /* Send the WMT command and wait until the WMT event returns */ |
| 2399 | hlen = sizeof(*hdr) + wmt_params->dlen; |
| 2400 | if (hlen > 255) |
| 2401 | return -EINVAL; |
| 2402 | |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 2403 | wc = kzalloc(hlen, GFP_KERNEL); |
| 2404 | if (!wc) |
| 2405 | return -ENOMEM; |
| 2406 | |
| 2407 | hdr = &wc->hdr; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2408 | hdr->dir = 1; |
| 2409 | hdr->op = wmt_params->op; |
| 2410 | hdr->dlen = cpu_to_le16(wmt_params->dlen + 1); |
| 2411 | hdr->flag = wmt_params->flag; |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 2412 | memcpy(wc->data, wmt_params->data, wmt_params->dlen); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2413 | |
| 2414 | set_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
| 2415 | |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 2416 | err = __hci_cmd_send(hdev, 0xfc6f, hlen, wc); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2417 | |
| 2418 | if (err < 0) { |
| 2419 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 2420 | goto err_free_wc; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2421 | } |
| 2422 | |
mark-yw.chen | 8454ed9 | 2021-04-12 23:06:26 +0800 | [diff] [blame] | 2423 | /* Submit control IN URB on demand to process the WMT event */ |
| 2424 | err = btusb_mtk_submit_wmt_recv_urb(hdev); |
| 2425 | if (err < 0) |
Muhammad Usama Anjum | 44e936d | 2021-04-13 22:52:08 +0500 | [diff] [blame] | 2426 | goto err_free_wc; |
mark-yw.chen | 8454ed9 | 2021-04-12 23:06:26 +0800 | [diff] [blame] | 2427 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2428 | /* The vendor specific WMT commands are all answered by a vendor |
| 2429 | * specific event and will have the Command Status or Command |
| 2430 | * Complete as with usual HCI command flow control. |
| 2431 | * |
| 2432 | * After sending the command, wait for BTUSB_TX_WAIT_VND_EVT |
| 2433 | * state to be cleared. The driver specific event receive routine |
| 2434 | * will clear that state and with that indicate completion of the |
| 2435 | * WMT command. |
| 2436 | */ |
| 2437 | err = wait_on_bit_timeout(&data->flags, BTUSB_TX_WAIT_VND_EVT, |
| 2438 | TASK_INTERRUPTIBLE, HCI_INIT_TIMEOUT); |
| 2439 | if (err == -EINTR) { |
| 2440 | bt_dev_err(hdev, "Execution of wmt command interrupted"); |
| 2441 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 2442 | goto err_free_wc; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | if (err) { |
| 2446 | bt_dev_err(hdev, "Execution of wmt command timed out"); |
| 2447 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 2448 | err = -ETIMEDOUT; |
| 2449 | goto err_free_wc; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | /* Parse and handle the return WMT event */ |
| 2453 | wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data; |
| 2454 | if (wmt_evt->whdr.op != hdr->op) { |
| 2455 | bt_dev_err(hdev, "Wrong op received %d expected %d", |
| 2456 | wmt_evt->whdr.op, hdr->op); |
| 2457 | err = -EIO; |
| 2458 | goto err_free_skb; |
| 2459 | } |
| 2460 | |
| 2461 | switch (wmt_evt->whdr.op) { |
| 2462 | case BTMTK_WMT_SEMAPHORE: |
| 2463 | if (wmt_evt->whdr.flag == 2) |
| 2464 | status = BTMTK_WMT_PATCH_UNDONE; |
| 2465 | else |
| 2466 | status = BTMTK_WMT_PATCH_DONE; |
| 2467 | break; |
| 2468 | case BTMTK_WMT_FUNC_CTRL: |
| 2469 | wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt; |
| 2470 | if (be16_to_cpu(wmt_evt_funcc->status) == 0x404) |
| 2471 | status = BTMTK_WMT_ON_DONE; |
| 2472 | else if (be16_to_cpu(wmt_evt_funcc->status) == 0x420) |
| 2473 | status = BTMTK_WMT_ON_PROGRESS; |
| 2474 | else |
| 2475 | status = BTMTK_WMT_ON_UNDONE; |
| 2476 | break; |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 2477 | case BTMTK_WMT_PATCH_DWNLD: |
| 2478 | if (wmt_evt->whdr.flag == 2) |
| 2479 | status = BTMTK_WMT_PATCH_DONE; |
| 2480 | else if (wmt_evt->whdr.flag == 1) |
| 2481 | status = BTMTK_WMT_PATCH_PROGRESS; |
| 2482 | else |
| 2483 | status = BTMTK_WMT_PATCH_UNDONE; |
| 2484 | break; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | if (wmt_params->status) |
| 2488 | *wmt_params->status = status; |
| 2489 | |
| 2490 | err_free_skb: |
| 2491 | kfree_skb(data->evt_skb); |
| 2492 | data->evt_skb = NULL; |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 2493 | err_free_wc: |
| 2494 | kfree(wc); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2495 | return err; |
| 2496 | } |
| 2497 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2498 | static int btusb_mtk_func_query(struct hci_dev *hdev) |
| 2499 | { |
| 2500 | struct btmtk_hci_wmt_params wmt_params; |
| 2501 | int status, err; |
| 2502 | u8 param = 0; |
| 2503 | |
| 2504 | /* Query whether the function is enabled */ |
| 2505 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 2506 | wmt_params.flag = 4; |
| 2507 | wmt_params.dlen = sizeof(param); |
| 2508 | wmt_params.data = ¶m; |
| 2509 | wmt_params.status = &status; |
| 2510 | |
| 2511 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 2512 | if (err < 0) { |
| 2513 | bt_dev_err(hdev, "Failed to query function status (%d)", err); |
| 2514 | return err; |
| 2515 | } |
| 2516 | |
| 2517 | return status; |
| 2518 | } |
| 2519 | |
mark-yw.chen | e947802 | 2021-08-04 17:06:47 +0800 | [diff] [blame] | 2520 | static int btusb_mtk_uhw_reg_write(struct btusb_data *data, u32 reg, u32 val) |
| 2521 | { |
| 2522 | struct hci_dev *hdev = data->hdev; |
| 2523 | int pipe, err; |
| 2524 | void *buf; |
| 2525 | |
| 2526 | buf = kzalloc(4, GFP_KERNEL); |
| 2527 | if (!buf) |
| 2528 | return -ENOMEM; |
| 2529 | |
| 2530 | put_unaligned_le32(val, buf); |
| 2531 | |
| 2532 | pipe = usb_sndctrlpipe(data->udev, 0); |
| 2533 | err = usb_control_msg(data->udev, pipe, 0x02, |
| 2534 | 0x5E, |
| 2535 | reg >> 16, reg & 0xffff, |
| 2536 | buf, 4, USB_CTRL_SET_TIMEOUT); |
| 2537 | if (err < 0) { |
| 2538 | bt_dev_err(hdev, "Failed to write uhw reg(%d)", err); |
| 2539 | goto err_free_buf; |
| 2540 | } |
| 2541 | |
| 2542 | err_free_buf: |
| 2543 | kfree(buf); |
| 2544 | |
| 2545 | return err; |
| 2546 | } |
| 2547 | |
| 2548 | static int btusb_mtk_uhw_reg_read(struct btusb_data *data, u32 reg, u32 *val) |
| 2549 | { |
| 2550 | struct hci_dev *hdev = data->hdev; |
| 2551 | int pipe, err; |
| 2552 | void *buf; |
| 2553 | |
| 2554 | buf = kzalloc(4, GFP_KERNEL); |
| 2555 | if (!buf) |
| 2556 | return -ENOMEM; |
| 2557 | |
| 2558 | pipe = usb_rcvctrlpipe(data->udev, 0); |
| 2559 | err = usb_control_msg(data->udev, pipe, 0x01, |
| 2560 | 0xDE, |
| 2561 | reg >> 16, reg & 0xffff, |
| 2562 | buf, 4, USB_CTRL_SET_TIMEOUT); |
| 2563 | if (err < 0) { |
| 2564 | bt_dev_err(hdev, "Failed to read uhw reg(%d)", err); |
| 2565 | goto err_free_buf; |
| 2566 | } |
| 2567 | |
| 2568 | *val = get_unaligned_le32(buf); |
| 2569 | bt_dev_dbg(hdev, "reg=%x, value=0x%08x", reg, *val); |
| 2570 | |
| 2571 | err_free_buf: |
| 2572 | kfree(buf); |
| 2573 | |
| 2574 | return err; |
| 2575 | } |
| 2576 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2577 | static int btusb_mtk_reg_read(struct btusb_data *data, u32 reg, u32 *val) |
| 2578 | { |
| 2579 | int pipe, err, size = sizeof(u32); |
| 2580 | void *buf; |
| 2581 | |
| 2582 | buf = kzalloc(size, GFP_KERNEL); |
| 2583 | if (!buf) |
| 2584 | return -ENOMEM; |
| 2585 | |
| 2586 | pipe = usb_rcvctrlpipe(data->udev, 0); |
| 2587 | err = usb_control_msg(data->udev, pipe, 0x63, |
| 2588 | USB_TYPE_VENDOR | USB_DIR_IN, |
| 2589 | reg >> 16, reg & 0xffff, |
| 2590 | buf, size, USB_CTRL_SET_TIMEOUT); |
| 2591 | if (err < 0) |
| 2592 | goto err_free_buf; |
| 2593 | |
| 2594 | *val = get_unaligned_le32(buf); |
| 2595 | |
| 2596 | err_free_buf: |
| 2597 | kfree(buf); |
| 2598 | |
| 2599 | return err; |
| 2600 | } |
| 2601 | |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 2602 | static int btusb_mtk_id_get(struct btusb_data *data, u32 reg, u32 *id) |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2603 | { |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 2604 | return btusb_mtk_reg_read(data, reg, id); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | static int btusb_mtk_setup(struct hci_dev *hdev) |
| 2608 | { |
| 2609 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2610 | struct btmtk_hci_wmt_params wmt_params; |
| 2611 | ktime_t calltime, delta, rettime; |
| 2612 | struct btmtk_tci_sleep tci_sleep; |
| 2613 | unsigned long long duration; |
| 2614 | struct sk_buff *skb; |
| 2615 | const char *fwname; |
| 2616 | int err, status; |
| 2617 | u32 dev_id; |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 2618 | char fw_bin_name[64]; |
mark-yw.chen | 201cf39 | 2021-02-23 14:27:40 +0800 | [diff] [blame] | 2619 | u32 fw_version = 0; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2620 | u8 param; |
| 2621 | |
| 2622 | calltime = ktime_get(); |
| 2623 | |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 2624 | err = btusb_mtk_id_get(data, 0x80000008, &dev_id); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2625 | if (err < 0) { |
| 2626 | bt_dev_err(hdev, "Failed to get device id (%d)", err); |
| 2627 | return err; |
| 2628 | } |
| 2629 | |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 2630 | if (!dev_id) { |
| 2631 | err = btusb_mtk_id_get(data, 0x70010200, &dev_id); |
| 2632 | if (err < 0) { |
| 2633 | bt_dev_err(hdev, "Failed to get device id (%d)", err); |
| 2634 | return err; |
| 2635 | } |
| 2636 | err = btusb_mtk_id_get(data, 0x80021004, &fw_version); |
| 2637 | if (err < 0) { |
| 2638 | bt_dev_err(hdev, "Failed to get fw version (%d)", err); |
| 2639 | return err; |
| 2640 | } |
| 2641 | } |
| 2642 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2643 | switch (dev_id) { |
Sean Wang | 9ce67c3 | 2019-06-02 08:02:49 +0800 | [diff] [blame] | 2644 | case 0x7663: |
| 2645 | fwname = FIRMWARE_MT7663; |
| 2646 | break; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2647 | case 0x7668: |
| 2648 | fwname = FIRMWARE_MT7668; |
| 2649 | break; |
mark-yw.chen | 09a19d6 | 2021-09-01 11:32:26 +0800 | [diff] [blame] | 2650 | case 0x7922: |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 2651 | case 0x7961: |
| 2652 | snprintf(fw_bin_name, sizeof(fw_bin_name), |
| 2653 | "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", |
| 2654 | dev_id & 0xffff, (fw_version & 0xff) + 1); |
Sean Wang | 8c0d17b | 2021-10-19 05:30:12 +0800 | [diff] [blame] | 2655 | err = btmtk_setup_firmware_79xx(hdev, fw_bin_name, |
| 2656 | btusb_mtk_hci_wmt_sync); |
Mark Chen | 00c0ee9 | 2021-12-07 01:33:42 +0800 | [diff] [blame] | 2657 | if (err < 0) { |
| 2658 | bt_dev_err(hdev, "Failed to set up firmware (%d)", err); |
| 2659 | return err; |
| 2660 | } |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 2661 | |
mark-yw.chen | e947802 | 2021-08-04 17:06:47 +0800 | [diff] [blame] | 2662 | /* It's Device EndPoint Reset Option Register */ |
| 2663 | btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, MTK_EP_RST_IN_OUT_OPT); |
| 2664 | |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 2665 | /* Enable Bluetooth protocol */ |
| 2666 | param = 1; |
| 2667 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 2668 | wmt_params.flag = 0; |
| 2669 | wmt_params.dlen = sizeof(param); |
| 2670 | wmt_params.data = ¶m; |
| 2671 | wmt_params.status = NULL; |
| 2672 | |
| 2673 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 2674 | if (err < 0) { |
| 2675 | bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
| 2676 | return err; |
| 2677 | } |
mark-yw.chen | 654e6f7 | 2021-08-02 20:59:41 +0800 | [diff] [blame] | 2678 | |
| 2679 | hci_set_msft_opcode(hdev, 0xFD30); |
mark-yw.chen | 28491d7 | 2021-11-05 02:26:05 +0800 | [diff] [blame] | 2680 | hci_set_aosp_capable(hdev); |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 2681 | goto done; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2682 | default: |
Jupeng Zhong | a297f56 | 2021-02-03 22:28:46 +0800 | [diff] [blame] | 2683 | bt_dev_err(hdev, "Unsupported hardware variant (%08x)", |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2684 | dev_id); |
| 2685 | return -ENODEV; |
| 2686 | } |
| 2687 | |
| 2688 | /* Query whether the firmware is already download */ |
| 2689 | wmt_params.op = BTMTK_WMT_SEMAPHORE; |
| 2690 | wmt_params.flag = 1; |
| 2691 | wmt_params.dlen = 0; |
| 2692 | wmt_params.data = NULL; |
| 2693 | wmt_params.status = &status; |
| 2694 | |
| 2695 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 2696 | if (err < 0) { |
| 2697 | bt_dev_err(hdev, "Failed to query firmware status (%d)", err); |
| 2698 | return err; |
| 2699 | } |
| 2700 | |
| 2701 | if (status == BTMTK_WMT_PATCH_DONE) { |
| 2702 | bt_dev_info(hdev, "firmware already downloaded"); |
| 2703 | goto ignore_setup_fw; |
| 2704 | } |
| 2705 | |
| 2706 | /* Setup a firmware which the device definitely requires */ |
Sean Wang | 8c0d17b | 2021-10-19 05:30:12 +0800 | [diff] [blame] | 2707 | err = btmtk_setup_firmware(hdev, fwname, |
| 2708 | btusb_mtk_hci_wmt_sync); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2709 | if (err < 0) |
| 2710 | return err; |
| 2711 | |
| 2712 | ignore_setup_fw: |
| 2713 | err = readx_poll_timeout(btusb_mtk_func_query, hdev, status, |
| 2714 | status < 0 || status != BTMTK_WMT_ON_PROGRESS, |
| 2715 | 2000, 5000000); |
| 2716 | /* -ETIMEDOUT happens */ |
| 2717 | if (err < 0) |
| 2718 | return err; |
| 2719 | |
| 2720 | /* The other errors happen in btusb_mtk_func_query */ |
| 2721 | if (status < 0) |
| 2722 | return status; |
| 2723 | |
| 2724 | if (status == BTMTK_WMT_ON_DONE) { |
| 2725 | bt_dev_info(hdev, "function already on"); |
| 2726 | goto ignore_func_on; |
| 2727 | } |
| 2728 | |
| 2729 | /* Enable Bluetooth protocol */ |
| 2730 | param = 1; |
| 2731 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 2732 | wmt_params.flag = 0; |
| 2733 | wmt_params.dlen = sizeof(param); |
| 2734 | wmt_params.data = ¶m; |
| 2735 | wmt_params.status = NULL; |
| 2736 | |
| 2737 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 2738 | if (err < 0) { |
| 2739 | bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
| 2740 | return err; |
| 2741 | } |
| 2742 | |
| 2743 | ignore_func_on: |
| 2744 | /* Apply the low power environment setup */ |
| 2745 | tci_sleep.mode = 0x5; |
| 2746 | tci_sleep.duration = cpu_to_le16(0x640); |
| 2747 | tci_sleep.host_duration = cpu_to_le16(0x640); |
| 2748 | tci_sleep.host_wakeup_pin = 0; |
| 2749 | tci_sleep.time_compensation = 0; |
| 2750 | |
| 2751 | skb = __hci_cmd_sync(hdev, 0xfc7a, sizeof(tci_sleep), &tci_sleep, |
| 2752 | HCI_INIT_TIMEOUT); |
| 2753 | if (IS_ERR(skb)) { |
| 2754 | err = PTR_ERR(skb); |
| 2755 | bt_dev_err(hdev, "Failed to apply low power setting (%d)", err); |
| 2756 | return err; |
| 2757 | } |
| 2758 | kfree_skb(skb); |
| 2759 | |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 2760 | done: |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 2761 | rettime = ktime_get(); |
| 2762 | delta = ktime_sub(rettime, calltime); |
| 2763 | duration = (unsigned long long)ktime_to_ns(delta) >> 10; |
| 2764 | |
| 2765 | bt_dev_info(hdev, "Device setup in %llu usecs", duration); |
| 2766 | |
| 2767 | return 0; |
| 2768 | } |
| 2769 | |
| 2770 | static int btusb_mtk_shutdown(struct hci_dev *hdev) |
| 2771 | { |
| 2772 | struct btmtk_hci_wmt_params wmt_params; |
| 2773 | u8 param = 0; |
| 2774 | int err; |
| 2775 | |
| 2776 | /* Disable the device */ |
| 2777 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 2778 | wmt_params.flag = 0; |
| 2779 | wmt_params.dlen = sizeof(param); |
| 2780 | wmt_params.data = ¶m; |
| 2781 | wmt_params.status = NULL; |
| 2782 | |
| 2783 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 2784 | if (err < 0) { |
| 2785 | bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
| 2786 | return err; |
| 2787 | } |
| 2788 | |
| 2789 | return 0; |
| 2790 | } |
| 2791 | |
mark-yw.chen | e947802 | 2021-08-04 17:06:47 +0800 | [diff] [blame] | 2792 | static void btusb_mtk_cmd_timeout(struct hci_dev *hdev) |
| 2793 | { |
| 2794 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2795 | u32 val; |
| 2796 | int err, retry = 0; |
| 2797 | |
| 2798 | /* It's MediaTek specific bluetooth reset mechanism via USB */ |
| 2799 | if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
| 2800 | bt_dev_err(hdev, "last reset failed? Not resetting again"); |
| 2801 | return; |
| 2802 | } |
| 2803 | |
| 2804 | err = usb_autopm_get_interface(data->intf); |
| 2805 | if (err < 0) |
| 2806 | return; |
| 2807 | |
| 2808 | btusb_stop_traffic(data); |
| 2809 | usb_kill_anchored_urbs(&data->tx_anchor); |
| 2810 | |
| 2811 | /* It's Device EndPoint Reset Option Register */ |
| 2812 | bt_dev_dbg(hdev, "Initiating reset mechanism via uhw"); |
| 2813 | btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, MTK_EP_RST_IN_OUT_OPT); |
| 2814 | btusb_mtk_uhw_reg_read(data, MTK_BT_WDT_STATUS, &val); |
| 2815 | |
| 2816 | /* Reset the bluetooth chip via USB interface. */ |
| 2817 | btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 1); |
| 2818 | btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT, 0x000000FF); |
| 2819 | btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT, &val); |
| 2820 | btusb_mtk_uhw_reg_write(data, MTK_UDMA_INT_STA_BT1, 0x000000FF); |
| 2821 | btusb_mtk_uhw_reg_read(data, MTK_UDMA_INT_STA_BT1, &val); |
| 2822 | /* MT7921 need to delay 20ms between toggle reset bit */ |
| 2823 | msleep(20); |
| 2824 | btusb_mtk_uhw_reg_write(data, MTK_BT_SUBSYS_RST, 0); |
| 2825 | btusb_mtk_uhw_reg_read(data, MTK_BT_SUBSYS_RST, &val); |
| 2826 | |
| 2827 | /* Poll the register until reset is completed */ |
| 2828 | do { |
| 2829 | btusb_mtk_uhw_reg_read(data, MTK_BT_MISC, &val); |
| 2830 | if (val & MTK_BT_RST_DONE) { |
| 2831 | bt_dev_dbg(hdev, "Bluetooth Reset Successfully"); |
| 2832 | break; |
| 2833 | } |
| 2834 | |
| 2835 | bt_dev_dbg(hdev, "Polling Bluetooth Reset CR"); |
| 2836 | retry++; |
| 2837 | msleep(MTK_BT_RESET_WAIT_MS); |
| 2838 | } while (retry < MTK_BT_RESET_NUM_TRIES); |
| 2839 | |
| 2840 | btusb_mtk_id_get(data, 0x70010200, &val); |
| 2841 | if (!val) |
| 2842 | bt_dev_err(hdev, "Can't get device id, subsys reset fail."); |
| 2843 | |
| 2844 | usb_queue_reset_device(data->intf); |
| 2845 | |
| 2846 | clear_bit(BTUSB_HW_RESET_ACTIVE, &data->flags); |
| 2847 | } |
| 2848 | |
mark-yw.chen | 0b10c8c | 2021-08-04 17:03:15 +0800 | [diff] [blame] | 2849 | static int btusb_recv_acl_mtk(struct hci_dev *hdev, struct sk_buff *skb) |
| 2850 | { |
| 2851 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2852 | u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle); |
| 2853 | |
| 2854 | switch (handle) { |
| 2855 | case 0xfc6f: /* Firmware dump from device */ |
| 2856 | /* When the firmware hangs, the device can no longer |
| 2857 | * suspend and thus disable auto-suspend. |
| 2858 | */ |
| 2859 | usb_disable_autosuspend(data->udev); |
mark-yw.chen | 146af22 | 2021-08-06 09:35:16 +0800 | [diff] [blame] | 2860 | fallthrough; |
mark-yw.chen | 0b10c8c | 2021-08-04 17:03:15 +0800 | [diff] [blame] | 2861 | case 0x05ff: /* Firmware debug logging 1 */ |
| 2862 | case 0x05fe: /* Firmware debug logging 2 */ |
| 2863 | return hci_recv_diag(hdev, skb); |
| 2864 | } |
| 2865 | |
| 2866 | return hci_recv_frame(hdev, skb); |
| 2867 | } |
| 2868 | |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 2869 | #ifdef CONFIG_PM |
| 2870 | /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */ |
| 2871 | static int marvell_config_oob_wake(struct hci_dev *hdev) |
| 2872 | { |
| 2873 | struct sk_buff *skb; |
| 2874 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2875 | struct device *dev = &data->udev->dev; |
| 2876 | u16 pin, gap, opcode; |
| 2877 | int ret; |
| 2878 | u8 cmd[5]; |
| 2879 | |
| 2880 | /* Move on if no wakeup pin specified */ |
| 2881 | if (of_property_read_u16(dev->of_node, "marvell,wakeup-pin", &pin) || |
| 2882 | of_property_read_u16(dev->of_node, "marvell,wakeup-gap-ms", &gap)) |
| 2883 | return 0; |
| 2884 | |
| 2885 | /* Vendor specific command to configure a GPIO as wake-up pin */ |
| 2886 | opcode = hci_opcode_pack(0x3F, 0x59); |
| 2887 | cmd[0] = opcode & 0xFF; |
| 2888 | cmd[1] = opcode >> 8; |
| 2889 | cmd[2] = 2; /* length of parameters that follow */ |
| 2890 | cmd[3] = pin; |
| 2891 | cmd[4] = gap; /* time in ms, for which wakeup pin should be asserted */ |
| 2892 | |
| 2893 | skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); |
| 2894 | if (!skb) { |
Joe Perches | d84fc2c | 2020-12-22 02:31:49 -0800 | [diff] [blame] | 2895 | bt_dev_err(hdev, "%s: No memory", __func__); |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 2896 | return -ENOMEM; |
| 2897 | } |
| 2898 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 2899 | skb_put_data(skb, cmd, sizeof(cmd)); |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 2900 | hci_skb_pkt_type(skb) = HCI_COMMAND_PKT; |
| 2901 | |
| 2902 | ret = btusb_send_frame(hdev, skb); |
| 2903 | if (ret) { |
Joe Perches | d84fc2c | 2020-12-22 02:31:49 -0800 | [diff] [blame] | 2904 | bt_dev_err(hdev, "%s: configuration failed", __func__); |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 2905 | kfree_skb(skb); |
| 2906 | return ret; |
| 2907 | } |
| 2908 | |
| 2909 | return 0; |
| 2910 | } |
| 2911 | #endif |
| 2912 | |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 2913 | static int btusb_set_bdaddr_marvell(struct hci_dev *hdev, |
| 2914 | const bdaddr_t *bdaddr) |
| 2915 | { |
| 2916 | struct sk_buff *skb; |
| 2917 | u8 buf[8]; |
| 2918 | long ret; |
| 2919 | |
| 2920 | buf[0] = 0xfe; |
| 2921 | buf[1] = sizeof(bdaddr_t); |
| 2922 | memcpy(buf + 2, bdaddr, sizeof(bdaddr_t)); |
| 2923 | |
| 2924 | skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT); |
| 2925 | if (IS_ERR(skb)) { |
| 2926 | ret = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2927 | bt_dev_err(hdev, "changing Marvell device address failed (%ld)", |
| 2928 | ret); |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 2929 | return ret; |
| 2930 | } |
| 2931 | kfree_skb(skb); |
| 2932 | |
| 2933 | return 0; |
| 2934 | } |
| 2935 | |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 2936 | static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev, |
| 2937 | const bdaddr_t *bdaddr) |
| 2938 | { |
| 2939 | struct sk_buff *skb; |
| 2940 | u8 buf[10]; |
| 2941 | long ret; |
| 2942 | |
| 2943 | buf[0] = 0x01; |
| 2944 | buf[1] = 0x01; |
| 2945 | buf[2] = 0x00; |
| 2946 | buf[3] = sizeof(bdaddr_t); |
| 2947 | memcpy(buf + 4, bdaddr, sizeof(bdaddr_t)); |
| 2948 | |
| 2949 | skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT); |
| 2950 | if (IS_ERR(skb)) { |
| 2951 | ret = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2952 | bt_dev_err(hdev, "Change address command failed (%ld)", ret); |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 2953 | return ret; |
| 2954 | } |
| 2955 | kfree_skb(skb); |
| 2956 | |
| 2957 | return 0; |
| 2958 | } |
| 2959 | |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 2960 | static int btusb_set_bdaddr_wcn6855(struct hci_dev *hdev, |
| 2961 | const bdaddr_t *bdaddr) |
| 2962 | { |
| 2963 | struct sk_buff *skb; |
| 2964 | u8 buf[6]; |
| 2965 | long ret; |
| 2966 | |
| 2967 | memcpy(buf, bdaddr, sizeof(bdaddr_t)); |
| 2968 | |
| 2969 | skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(buf), buf, |
| 2970 | HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT); |
| 2971 | if (IS_ERR(skb)) { |
| 2972 | ret = PTR_ERR(skb); |
| 2973 | bt_dev_err(hdev, "Change address command failed (%ld)", ret); |
| 2974 | return ret; |
| 2975 | } |
| 2976 | kfree_skb(skb); |
| 2977 | |
| 2978 | return 0; |
| 2979 | } |
| 2980 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2981 | #define QCA_DFU_PACKET_LEN 4096 |
| 2982 | |
| 2983 | #define QCA_GET_TARGET_VERSION 0x09 |
| 2984 | #define QCA_CHECK_STATUS 0x05 |
| 2985 | #define QCA_DFU_DOWNLOAD 0x01 |
| 2986 | |
| 2987 | #define QCA_SYSCFG_UPDATED 0x40 |
| 2988 | #define QCA_PATCH_UPDATED 0x80 |
| 2989 | #define QCA_DFU_TIMEOUT 3000 |
Tim Jiang | ef2862a | 2020-12-03 12:57:14 +0800 | [diff] [blame] | 2990 | #define QCA_FLAG_MULTI_NVM 0x80 |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2991 | |
Tim Jiang | d6cba4e | 2021-10-29 11:21:21 +0800 | [diff] [blame] | 2992 | #define WCN6855_2_0_RAM_VERSION_GF 0x400c1200 |
| 2993 | #define WCN6855_2_1_RAM_VERSION_GF 0x400c1211 |
| 2994 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2995 | struct qca_version { |
| 2996 | __le32 rom_version; |
| 2997 | __le32 patch_version; |
| 2998 | __le32 ram_version; |
tjiang@codeaurora.org | 741268a | 2021-11-16 12:48:49 +0800 | [diff] [blame] | 2999 | __u8 chip_id; |
| 3000 | __u8 platform_id; |
Tim Jiang | ef2862a | 2020-12-03 12:57:14 +0800 | [diff] [blame] | 3001 | __le16 flag; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3002 | __u8 reserved[4]; |
| 3003 | } __packed; |
| 3004 | |
| 3005 | struct qca_rampatch_version { |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3006 | __le16 rom_version_high; |
| 3007 | __le16 rom_version_low; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3008 | __le16 patch_version; |
| 3009 | } __packed; |
| 3010 | |
| 3011 | struct qca_device_info { |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3012 | u32 rom_version; |
| 3013 | u8 rampatch_hdr; /* length of header in rampatch */ |
| 3014 | u8 nvm_hdr; /* length of header in NVM */ |
| 3015 | u8 ver_offset; /* offset of version structure in rampatch */ |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3016 | }; |
| 3017 | |
| 3018 | static const struct qca_device_info qca_devices_table[] = { |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3019 | { 0x00000100, 20, 4, 8 }, /* Rome 1.0 */ |
| 3020 | { 0x00000101, 20, 4, 8 }, /* Rome 1.1 */ |
| 3021 | { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */ |
| 3022 | { 0x00000201, 28, 4, 16 }, /* Rome 2.1 */ |
| 3023 | { 0x00000300, 28, 4, 16 }, /* Rome 3.0 */ |
| 3024 | { 0x00000302, 28, 4, 16 }, /* Rome 3.2 */ |
| 3025 | { 0x00130100, 40, 4, 16 }, /* WCN6855 1.0 */ |
| 3026 | { 0x00130200, 40, 4, 16 }, /* WCN6855 2.0 */ |
Tim Jiang | d6cba4e | 2021-10-29 11:21:21 +0800 | [diff] [blame] | 3027 | { 0x00130201, 40, 4, 16 }, /* WCN6855 2.1 */ |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3028 | }; |
| 3029 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3030 | 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] | 3031 | void *data, u16 size) |
| 3032 | { |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3033 | int pipe, err; |
| 3034 | u8 *buf; |
| 3035 | |
| 3036 | buf = kmalloc(size, GFP_KERNEL); |
| 3037 | if (!buf) |
| 3038 | return -ENOMEM; |
| 3039 | |
| 3040 | /* Found some of USB hosts have IOT issues with ours so that we should |
| 3041 | * not wait until HCI layer is ready. |
| 3042 | */ |
| 3043 | pipe = usb_rcvctrlpipe(udev, 0); |
| 3044 | err = usb_control_msg(udev, pipe, request, USB_TYPE_VENDOR | USB_DIR_IN, |
| 3045 | 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); |
| 3046 | if (err < 0) { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3047 | 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] | 3048 | goto done; |
| 3049 | } |
| 3050 | |
| 3051 | memcpy(data, buf, size); |
| 3052 | |
| 3053 | done: |
| 3054 | kfree(buf); |
| 3055 | |
| 3056 | return err; |
| 3057 | } |
| 3058 | |
| 3059 | static int btusb_setup_qca_download_fw(struct hci_dev *hdev, |
| 3060 | const struct firmware *firmware, |
| 3061 | size_t hdr_size) |
| 3062 | { |
| 3063 | struct btusb_data *btdata = hci_get_drvdata(hdev); |
| 3064 | struct usb_device *udev = btdata->udev; |
| 3065 | size_t count, size, sent = 0; |
| 3066 | int pipe, len, err; |
| 3067 | u8 *buf; |
| 3068 | |
| 3069 | buf = kmalloc(QCA_DFU_PACKET_LEN, GFP_KERNEL); |
| 3070 | if (!buf) |
| 3071 | return -ENOMEM; |
| 3072 | |
| 3073 | count = firmware->size; |
| 3074 | |
| 3075 | size = min_t(size_t, count, hdr_size); |
| 3076 | memcpy(buf, firmware->data, size); |
| 3077 | |
| 3078 | /* USB patches should go down to controller through USB path |
| 3079 | * because binary format fits to go down through USB channel. |
| 3080 | * USB control path is for patching headers and USB bulk is for |
| 3081 | * patch body. |
| 3082 | */ |
| 3083 | pipe = usb_sndctrlpipe(udev, 0); |
| 3084 | err = usb_control_msg(udev, pipe, QCA_DFU_DOWNLOAD, USB_TYPE_VENDOR, |
| 3085 | 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); |
| 3086 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3087 | bt_dev_err(hdev, "Failed to send headers (%d)", err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3088 | goto done; |
| 3089 | } |
| 3090 | |
| 3091 | sent += size; |
| 3092 | count -= size; |
| 3093 | |
Tim Jiang | 4f00bfb | 2021-06-01 17:57:10 +0800 | [diff] [blame] | 3094 | /* ep2 need time to switch from function acl to function dfu, |
| 3095 | * so we add 20ms delay here. |
| 3096 | */ |
| 3097 | msleep(20); |
| 3098 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3099 | while (count) { |
| 3100 | size = min_t(size_t, count, QCA_DFU_PACKET_LEN); |
| 3101 | |
| 3102 | memcpy(buf, firmware->data + sent, size); |
| 3103 | |
| 3104 | pipe = usb_sndbulkpipe(udev, 0x02); |
| 3105 | err = usb_bulk_msg(udev, pipe, buf, size, &len, |
| 3106 | QCA_DFU_TIMEOUT); |
| 3107 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3108 | bt_dev_err(hdev, "Failed to send body at %zd of %zd (%d)", |
| 3109 | sent, firmware->size, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3110 | break; |
| 3111 | } |
| 3112 | |
| 3113 | if (size != len) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3114 | bt_dev_err(hdev, "Failed to get bulk buffer"); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3115 | err = -EILSEQ; |
| 3116 | break; |
| 3117 | } |
| 3118 | |
| 3119 | sent += size; |
| 3120 | count -= size; |
| 3121 | } |
| 3122 | |
| 3123 | done: |
| 3124 | kfree(buf); |
| 3125 | return err; |
| 3126 | } |
| 3127 | |
| 3128 | static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev, |
| 3129 | struct qca_version *ver, |
| 3130 | const struct qca_device_info *info) |
| 3131 | { |
| 3132 | struct qca_rampatch_version *rver; |
| 3133 | const struct firmware *fw; |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3134 | u32 ver_rom, ver_patch, rver_rom; |
| 3135 | u16 rver_rom_low, rver_rom_high, rver_patch; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3136 | char fwname[64]; |
| 3137 | int err; |
| 3138 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3139 | ver_rom = le32_to_cpu(ver->rom_version); |
| 3140 | ver_patch = le32_to_cpu(ver->patch_version); |
| 3141 | |
| 3142 | 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] | 3143 | |
| 3144 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 3145 | if (err) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3146 | bt_dev_err(hdev, "failed to request rampatch file: %s (%d)", |
| 3147 | fwname, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3148 | return err; |
| 3149 | } |
| 3150 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3151 | bt_dev_info(hdev, "using rampatch file: %s", fwname); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3152 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3153 | rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset); |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3154 | rver_rom_low = le16_to_cpu(rver->rom_version_low); |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3155 | rver_patch = le16_to_cpu(rver->patch_version); |
| 3156 | |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3157 | if (ver_rom & ~0xffffU) { |
| 3158 | rver_rom_high = le16_to_cpu(rver->rom_version_high); |
| 3159 | rver_rom = le32_to_cpu(rver_rom_high << 16 | rver_rom_low); |
| 3160 | } else { |
| 3161 | rver_rom = rver_rom_low; |
| 3162 | } |
| 3163 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3164 | bt_dev_info(hdev, "QCA: patch rome 0x%x build 0x%x, " |
| 3165 | "firmware rome 0x%x build 0x%x", |
| 3166 | rver_rom, rver_patch, ver_rom, ver_patch); |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3167 | |
| 3168 | if (rver_rom != ver_rom || rver_patch <= ver_patch) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3169 | 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] | 3170 | err = -EINVAL; |
| 3171 | goto done; |
| 3172 | } |
| 3173 | |
| 3174 | err = btusb_setup_qca_download_fw(hdev, fw, info->rampatch_hdr); |
| 3175 | |
| 3176 | done: |
| 3177 | release_firmware(fw); |
| 3178 | |
| 3179 | return err; |
| 3180 | } |
| 3181 | |
Tim Jiang | d6cba4e | 2021-10-29 11:21:21 +0800 | [diff] [blame] | 3182 | static void btusb_generate_qca_nvm_name(char *fwname, size_t max_size, |
| 3183 | const struct qca_version *ver) |
| 3184 | { |
| 3185 | u32 rom_version = le32_to_cpu(ver->rom_version); |
| 3186 | u16 flag = le16_to_cpu(ver->flag); |
| 3187 | |
| 3188 | if (((flag >> 8) & 0xff) == QCA_FLAG_MULTI_NVM) { |
tjiang@codeaurora.org | 741268a | 2021-11-16 12:48:49 +0800 | [diff] [blame] | 3189 | /* The board_id should be split into two bytes |
| 3190 | * The 1st byte is chip ID, and the 2nd byte is platform ID |
| 3191 | * For example, board ID 0x010A, 0x01 is platform ID. 0x0A is chip ID |
tjiang@codeaurora.org | 21a241b | 2021-11-16 19:02:16 +0800 | [diff] [blame] | 3192 | * we have several platforms, and platform IDs are continuously added |
tjiang@codeaurora.org | 741268a | 2021-11-16 12:48:49 +0800 | [diff] [blame] | 3193 | * Platform ID: |
| 3194 | * 0x00 is for Mobile |
| 3195 | * 0x01 is for X86 |
| 3196 | * 0x02 is for Automotive |
| 3197 | * 0x03 is for Consumer electronic |
| 3198 | */ |
| 3199 | u16 board_id = (ver->chip_id << 8) + ver->platform_id; |
Tim Jiang | d6cba4e | 2021-10-29 11:21:21 +0800 | [diff] [blame] | 3200 | const char *variant; |
| 3201 | |
| 3202 | switch (le32_to_cpu(ver->ram_version)) { |
| 3203 | case WCN6855_2_0_RAM_VERSION_GF: |
| 3204 | case WCN6855_2_1_RAM_VERSION_GF: |
| 3205 | variant = "_gf"; |
| 3206 | break; |
| 3207 | default: |
| 3208 | variant = ""; |
| 3209 | break; |
| 3210 | } |
| 3211 | |
| 3212 | if (board_id == 0) { |
| 3213 | snprintf(fwname, max_size, "qca/nvm_usb_%08x%s.bin", |
| 3214 | rom_version, variant); |
| 3215 | } else { |
| 3216 | snprintf(fwname, max_size, "qca/nvm_usb_%08x%s_%04x.bin", |
| 3217 | rom_version, variant, board_id); |
| 3218 | } |
| 3219 | } else { |
| 3220 | snprintf(fwname, max_size, "qca/nvm_usb_%08x.bin", |
| 3221 | rom_version); |
| 3222 | } |
| 3223 | |
| 3224 | } |
| 3225 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3226 | static int btusb_setup_qca_load_nvm(struct hci_dev *hdev, |
| 3227 | struct qca_version *ver, |
| 3228 | const struct qca_device_info *info) |
| 3229 | { |
| 3230 | const struct firmware *fw; |
| 3231 | char fwname[64]; |
| 3232 | int err; |
| 3233 | |
Tim Jiang | d6cba4e | 2021-10-29 11:21:21 +0800 | [diff] [blame] | 3234 | btusb_generate_qca_nvm_name(fwname, sizeof(fwname), ver); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3235 | |
| 3236 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 3237 | if (err) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3238 | bt_dev_err(hdev, "failed to request NVM file: %s (%d)", |
| 3239 | fwname, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3240 | return err; |
| 3241 | } |
| 3242 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3243 | bt_dev_info(hdev, "using NVM file: %s", fwname); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3244 | |
| 3245 | err = btusb_setup_qca_download_fw(hdev, fw, info->nvm_hdr); |
| 3246 | |
| 3247 | release_firmware(fw); |
| 3248 | |
| 3249 | return err; |
| 3250 | } |
| 3251 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3252 | /* identify the ROM version and check whether patches are needed */ |
| 3253 | static bool btusb_qca_need_patch(struct usb_device *udev) |
| 3254 | { |
| 3255 | struct qca_version ver; |
| 3256 | |
| 3257 | if (btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, |
| 3258 | sizeof(ver)) < 0) |
| 3259 | return false; |
| 3260 | /* only low ROM versions need patches */ |
| 3261 | return !(le32_to_cpu(ver.rom_version) & ~0xffffU); |
| 3262 | } |
| 3263 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3264 | static int btusb_setup_qca(struct hci_dev *hdev) |
| 3265 | { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3266 | struct btusb_data *btdata = hci_get_drvdata(hdev); |
| 3267 | struct usb_device *udev = btdata->udev; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3268 | const struct qca_device_info *info = NULL; |
| 3269 | struct qca_version ver; |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3270 | u32 ver_rom; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3271 | u8 status; |
| 3272 | int i, err; |
| 3273 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3274 | err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, |
Marcel Holtmann | eb50042 | 2015-04-16 23:15:50 +0200 | [diff] [blame] | 3275 | sizeof(ver)); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3276 | if (err < 0) |
| 3277 | return err; |
| 3278 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3279 | ver_rom = le32_to_cpu(ver.rom_version); |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3280 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3281 | for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) { |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 3282 | if (ver_rom == qca_devices_table[i].rom_version) |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3283 | info = &qca_devices_table[i]; |
| 3284 | } |
| 3285 | if (!info) { |
Hui Wang | 234f414 | 2021-02-08 13:02:37 +0800 | [diff] [blame] | 3286 | /* If the rom_version is not matched in the qca_devices_table |
| 3287 | * and the high ROM version is not zero, we assume this chip no |
| 3288 | * need to load the rampatch and nvm. |
| 3289 | */ |
| 3290 | if (ver_rom & ~0xffffU) |
| 3291 | return 0; |
| 3292 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3293 | 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] | 3294 | return -ENODEV; |
| 3295 | } |
| 3296 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3297 | 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] | 3298 | sizeof(status)); |
| 3299 | if (err < 0) |
| 3300 | return err; |
| 3301 | |
| 3302 | if (!(status & QCA_PATCH_UPDATED)) { |
| 3303 | err = btusb_setup_qca_load_rampatch(hdev, &ver, info); |
| 3304 | if (err < 0) |
| 3305 | return err; |
| 3306 | } |
| 3307 | |
Tim Jiang | ef2862a | 2020-12-03 12:57:14 +0800 | [diff] [blame] | 3308 | err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, |
| 3309 | sizeof(ver)); |
| 3310 | if (err < 0) |
| 3311 | return err; |
| 3312 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3313 | if (!(status & QCA_SYSCFG_UPDATED)) { |
| 3314 | err = btusb_setup_qca_load_nvm(hdev, &ver, info); |
| 3315 | if (err < 0) |
| 3316 | return err; |
| 3317 | } |
| 3318 | |
| 3319 | return 0; |
| 3320 | } |
| 3321 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3322 | static inline int __set_diag_interface(struct hci_dev *hdev) |
| 3323 | { |
| 3324 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3325 | struct usb_interface *intf = data->diag; |
| 3326 | int i; |
| 3327 | |
| 3328 | if (!data->diag) |
| 3329 | return -ENODEV; |
| 3330 | |
| 3331 | data->diag_tx_ep = NULL; |
| 3332 | data->diag_rx_ep = NULL; |
| 3333 | |
| 3334 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 3335 | struct usb_endpoint_descriptor *ep_desc; |
| 3336 | |
| 3337 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 3338 | |
| 3339 | if (!data->diag_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { |
| 3340 | data->diag_tx_ep = ep_desc; |
| 3341 | continue; |
| 3342 | } |
| 3343 | |
| 3344 | if (!data->diag_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { |
| 3345 | data->diag_rx_ep = ep_desc; |
| 3346 | continue; |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | if (!data->diag_tx_ep || !data->diag_rx_ep) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3351 | bt_dev_err(hdev, "invalid diagnostic descriptors"); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3352 | return -ENODEV; |
| 3353 | } |
| 3354 | |
| 3355 | return 0; |
| 3356 | } |
| 3357 | |
| 3358 | static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable) |
| 3359 | { |
| 3360 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3361 | struct sk_buff *skb; |
| 3362 | struct urb *urb; |
| 3363 | unsigned int pipe; |
| 3364 | |
| 3365 | if (!data->diag_tx_ep) |
| 3366 | return ERR_PTR(-ENODEV); |
| 3367 | |
| 3368 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 3369 | if (!urb) |
| 3370 | return ERR_PTR(-ENOMEM); |
| 3371 | |
| 3372 | skb = bt_skb_alloc(2, GFP_KERNEL); |
| 3373 | if (!skb) { |
| 3374 | usb_free_urb(urb); |
| 3375 | return ERR_PTR(-ENOMEM); |
| 3376 | } |
| 3377 | |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 3378 | skb_put_u8(skb, 0xf0); |
| 3379 | skb_put_u8(skb, enable); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3380 | |
| 3381 | pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress); |
| 3382 | |
| 3383 | usb_fill_bulk_urb(urb, data->udev, pipe, |
| 3384 | skb->data, skb->len, btusb_tx_complete, skb); |
| 3385 | |
| 3386 | skb->dev = (void *)hdev; |
| 3387 | |
| 3388 | return urb; |
| 3389 | } |
| 3390 | |
| 3391 | static int btusb_bcm_set_diag(struct hci_dev *hdev, bool enable) |
| 3392 | { |
| 3393 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3394 | struct urb *urb; |
| 3395 | |
| 3396 | if (!data->diag) |
| 3397 | return -ENODEV; |
| 3398 | |
| 3399 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 3400 | return -ENETDOWN; |
| 3401 | |
| 3402 | urb = alloc_diag_urb(hdev, enable); |
| 3403 | if (IS_ERR(urb)) |
| 3404 | return PTR_ERR(urb); |
| 3405 | |
| 3406 | return submit_or_queue_tx_urb(hdev, urb); |
| 3407 | } |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3408 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3409 | #ifdef CONFIG_PM |
| 3410 | static irqreturn_t btusb_oob_wake_handler(int irq, void *priv) |
| 3411 | { |
| 3412 | struct btusb_data *data = priv; |
| 3413 | |
| 3414 | pm_wakeup_event(&data->udev->dev, 0); |
Jeffy Chen | 017789f | 2017-02-24 14:24:29 +0800 | [diff] [blame] | 3415 | pm_system_wakeup(); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3416 | |
| 3417 | /* Disable only if not already disabled (keep it balanced) */ |
| 3418 | if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) { |
| 3419 | disable_irq_nosync(irq); |
| 3420 | disable_irq_wake(irq); |
| 3421 | } |
| 3422 | return IRQ_HANDLED; |
| 3423 | } |
| 3424 | |
| 3425 | static const struct of_device_id btusb_match_table[] = { |
| 3426 | { .compatible = "usb1286,204e" }, |
Brian Norris | 4c409af | 2019-02-22 14:53:43 -0800 | [diff] [blame] | 3427 | { .compatible = "usbcf3,e300" }, /* QCA6174A */ |
| 3428 | { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */ |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3429 | { } |
| 3430 | }; |
| 3431 | MODULE_DEVICE_TABLE(of, btusb_match_table); |
| 3432 | |
| 3433 | /* Use an oob wakeup pin? */ |
| 3434 | static int btusb_config_oob_wake(struct hci_dev *hdev) |
| 3435 | { |
| 3436 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3437 | struct device *dev = &data->udev->dev; |
| 3438 | int irq, ret; |
| 3439 | |
| 3440 | clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags); |
| 3441 | |
| 3442 | if (!of_match_device(btusb_match_table, dev)) |
| 3443 | return 0; |
| 3444 | |
| 3445 | /* Move on if no IRQ specified */ |
| 3446 | irq = of_irq_get_byname(dev->of_node, "wakeup"); |
| 3447 | if (irq <= 0) { |
| 3448 | bt_dev_dbg(hdev, "%s: no OOB Wakeup IRQ in DT", __func__); |
| 3449 | return 0; |
| 3450 | } |
| 3451 | |
Brian Norris | 771acc7 | 2019-04-09 11:49:17 -0700 | [diff] [blame] | 3452 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3453 | ret = devm_request_irq(&hdev->dev, irq, btusb_oob_wake_handler, |
| 3454 | 0, "OOB Wake-on-BT", data); |
| 3455 | if (ret) { |
| 3456 | bt_dev_err(hdev, "%s: IRQ request failed", __func__); |
| 3457 | return ret; |
| 3458 | } |
| 3459 | |
| 3460 | ret = device_init_wakeup(dev, true); |
| 3461 | if (ret) { |
| 3462 | bt_dev_err(hdev, "%s: failed to init_wakeup", __func__); |
| 3463 | return ret; |
| 3464 | } |
| 3465 | |
| 3466 | data->oob_wake_irq = irq; |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3467 | bt_dev_info(hdev, "OOB Wake-on-BT configured at IRQ %u", irq); |
| 3468 | return 0; |
| 3469 | } |
| 3470 | #endif |
| 3471 | |
Hans de Goede | fc54910 | 2018-04-27 11:26:43 +0200 | [diff] [blame] | 3472 | static void btusb_check_needs_reset_resume(struct usb_interface *intf) |
| 3473 | { |
| 3474 | if (dmi_check_system(btusb_needs_reset_resume_table)) |
| 3475 | interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; |
| 3476 | } |
| 3477 | |
Luiz Augusto von Dentz | 4539ca6 | 2021-10-01 13:22:31 -0700 | [diff] [blame] | 3478 | static bool btusb_wakeup(struct hci_dev *hdev) |
Abhishek Pandit-Subedi | b7d0bf1 | 2020-05-12 19:19:27 -0700 | [diff] [blame] | 3479 | { |
| 3480 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3481 | |
Luiz Augusto von Dentz | 4539ca6 | 2021-10-01 13:22:31 -0700 | [diff] [blame] | 3482 | return device_may_wakeup(&data->udev->dev); |
Abhishek Pandit-Subedi | b7d0bf1 | 2020-05-12 19:19:27 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Tim Jiang | 3b0d525 | 2020-12-18 18:12:11 +0800 | [diff] [blame] | 3485 | static int btusb_shutdown_qca(struct hci_dev *hdev) |
| 3486 | { |
| 3487 | struct sk_buff *skb; |
| 3488 | |
| 3489 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 3490 | if (IS_ERR(skb)) { |
| 3491 | bt_dev_err(hdev, "HCI reset during shutdown failed"); |
| 3492 | return PTR_ERR(skb); |
| 3493 | } |
| 3494 | kfree_skb(skb); |
| 3495 | |
| 3496 | return 0; |
| 3497 | } |
| 3498 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 3499 | static ssize_t force_poll_sync_read(struct file *file, char __user *user_buf, |
| 3500 | size_t count, loff_t *ppos) |
| 3501 | { |
| 3502 | struct btusb_data *data = file->private_data; |
| 3503 | char buf[3]; |
| 3504 | |
| 3505 | buf[0] = data->poll_sync ? 'Y' : 'N'; |
| 3506 | buf[1] = '\n'; |
| 3507 | buf[2] = '\0'; |
| 3508 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); |
| 3509 | } |
| 3510 | |
| 3511 | static ssize_t force_poll_sync_write(struct file *file, |
| 3512 | const char __user *user_buf, |
| 3513 | size_t count, loff_t *ppos) |
| 3514 | { |
| 3515 | struct btusb_data *data = file->private_data; |
| 3516 | bool enable; |
| 3517 | int err; |
| 3518 | |
| 3519 | err = kstrtobool_from_user(user_buf, count, &enable); |
| 3520 | if (err) |
| 3521 | return err; |
| 3522 | |
| 3523 | /* Only allow changes while the adapter is down */ |
| 3524 | if (test_bit(HCI_UP, &data->hdev->flags)) |
| 3525 | return -EPERM; |
| 3526 | |
| 3527 | if (data->poll_sync == enable) |
| 3528 | return -EALREADY; |
| 3529 | |
| 3530 | data->poll_sync = enable; |
| 3531 | |
| 3532 | return count; |
| 3533 | } |
| 3534 | |
| 3535 | static const struct file_operations force_poll_sync_fops = { |
| 3536 | .open = simple_open, |
| 3537 | .read = force_poll_sync_read, |
| 3538 | .write = force_poll_sync_write, |
| 3539 | .llseek = default_llseek, |
| 3540 | }; |
| 3541 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3542 | static int btusb_probe(struct usb_interface *intf, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 3543 | const struct usb_device_id *id) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3544 | { |
| 3545 | struct usb_endpoint_descriptor *ep_desc; |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3546 | struct gpio_desc *reset_gpio; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3547 | struct btusb_data *data; |
| 3548 | struct hci_dev *hdev; |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3549 | unsigned ifnum_base; |
Tedd Ho-Jeong An | 53492a6 | 2021-08-04 17:32:11 -0700 | [diff] [blame] | 3550 | int i, err, priv_size; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3551 | |
| 3552 | BT_DBG("intf %p id %p", intf, id); |
| 3553 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3554 | /* interface numbers are hardcoded in the spec */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3555 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) { |
| 3556 | if (!(id->driver_info & BTUSB_IFNUM_2)) |
| 3557 | return -ENODEV; |
| 3558 | if (intf->cur_altsetting->desc.bInterfaceNumber != 2) |
| 3559 | return -ENODEV; |
| 3560 | } |
| 3561 | |
| 3562 | ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3563 | |
| 3564 | if (!id->driver_info) { |
| 3565 | const struct usb_device_id *match; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 3566 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3567 | match = usb_match_id(intf, blacklist_table); |
| 3568 | if (match) |
| 3569 | id = match; |
| 3570 | } |
| 3571 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3572 | if (id->driver_info == BTUSB_IGNORE) |
| 3573 | return -ENODEV; |
| 3574 | |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 3575 | if (id->driver_info & BTUSB_ATH3012) { |
| 3576 | struct usb_device *udev = interface_to_usbdev(intf); |
| 3577 | |
| 3578 | /* Old firmware would otherwise let ath3k driver load |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 3579 | * patch and sysconfig files |
| 3580 | */ |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3581 | if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 && |
| 3582 | !btusb_qca_need_patch(udev)) |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 3583 | return -ENODEV; |
| 3584 | } |
| 3585 | |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 3586 | data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3587 | if (!data) |
| 3588 | return -ENOMEM; |
| 3589 | |
| 3590 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 3591 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 3592 | |
| 3593 | if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) { |
| 3594 | data->intr_ep = ep_desc; |
| 3595 | continue; |
| 3596 | } |
| 3597 | |
| 3598 | if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { |
| 3599 | data->bulk_tx_ep = ep_desc; |
| 3600 | continue; |
| 3601 | } |
| 3602 | |
| 3603 | if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { |
| 3604 | data->bulk_rx_ep = ep_desc; |
| 3605 | continue; |
| 3606 | } |
| 3607 | } |
| 3608 | |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 3609 | if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3610 | return -ENODEV; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3611 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 3612 | if (id->driver_info & BTUSB_AMP) { |
| 3613 | data->cmdreq_type = USB_TYPE_CLASS | 0x01; |
| 3614 | data->cmdreq = 0x2b; |
| 3615 | } else { |
| 3616 | data->cmdreq_type = USB_TYPE_CLASS; |
| 3617 | data->cmdreq = 0x00; |
| 3618 | } |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3619 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3620 | data->udev = interface_to_usbdev(intf); |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 3621 | data->intf = intf; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3622 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3623 | INIT_WORK(&data->work, btusb_work); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 3624 | INIT_WORK(&data->waker, btusb_waker); |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 3625 | INIT_DELAYED_WORK(&data->rx_work, btusb_rx_work); |
| 3626 | |
| 3627 | skb_queue_head_init(&data->acl_q); |
| 3628 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 3629 | init_usb_anchor(&data->deferred); |
| 3630 | init_usb_anchor(&data->tx_anchor); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 3631 | spin_lock_init(&data->txlock); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3632 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3633 | init_usb_anchor(&data->intr_anchor); |
| 3634 | init_usb_anchor(&data->bulk_anchor); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 3635 | init_usb_anchor(&data->isoc_anchor); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3636 | init_usb_anchor(&data->diag_anchor); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3637 | init_usb_anchor(&data->ctrl_anchor); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 3638 | spin_lock_init(&data->rxlock); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3639 | |
Tedd Ho-Jeong An | 53492a6 | 2021-08-04 17:32:11 -0700 | [diff] [blame] | 3640 | priv_size = 0; |
| 3641 | |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 3642 | data->recv_event = hci_recv_frame; |
| 3643 | data->recv_bulk = btusb_recv_bulk; |
| 3644 | |
Tedd Ho-Jeong An | 53492a6 | 2021-08-04 17:32:11 -0700 | [diff] [blame] | 3645 | if (id->driver_info & BTUSB_INTEL_COMBINED) { |
| 3646 | /* Allocate extra space for Intel device */ |
| 3647 | priv_size += sizeof(struct btintel_data); |
Tedd Ho-Jeong An | 53492a6 | 2021-08-04 17:32:11 -0700 | [diff] [blame] | 3648 | |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 3649 | /* Override the rx handlers */ |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 3650 | data->recv_event = btusb_recv_event_intel; |
| 3651 | data->recv_bulk = btusb_recv_bulk_intel; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 3652 | } |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 3653 | |
mark-yw.chen | 0b10c8c | 2021-08-04 17:03:15 +0800 | [diff] [blame] | 3654 | data->recv_acl = hci_recv_frame; |
| 3655 | |
Tedd Ho-Jeong An | 53492a6 | 2021-08-04 17:32:11 -0700 | [diff] [blame] | 3656 | hdev = hci_alloc_dev_priv(priv_size); |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 3657 | if (!hdev) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3658 | return -ENOMEM; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3659 | |
Marcel Holtmann | c13854c | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 3660 | hdev->bus = HCI_USB; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 3661 | hci_set_drvdata(hdev, data); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3662 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 3663 | if (id->driver_info & BTUSB_AMP) |
| 3664 | hdev->dev_type = HCI_AMP; |
| 3665 | else |
Marcel Holtmann | ca8bee5 | 2016-07-05 14:30:14 +0200 | [diff] [blame] | 3666 | hdev->dev_type = HCI_PRIMARY; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 3667 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3668 | data->hdev = hdev; |
| 3669 | |
| 3670 | SET_HCIDEV_DEV(hdev, &intf->dev); |
| 3671 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3672 | reset_gpio = gpiod_get_optional(&data->udev->dev, "reset", |
| 3673 | GPIOD_OUT_LOW); |
| 3674 | if (IS_ERR(reset_gpio)) { |
| 3675 | err = PTR_ERR(reset_gpio); |
| 3676 | goto out_free_dev; |
| 3677 | } else if (reset_gpio) { |
| 3678 | data->reset_gpio = reset_gpio; |
| 3679 | } |
| 3680 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 3681 | hdev->open = btusb_open; |
| 3682 | hdev->close = btusb_close; |
| 3683 | hdev->flush = btusb_flush; |
| 3684 | hdev->send = btusb_send_frame; |
| 3685 | hdev->notify = btusb_notify; |
Luiz Augusto von Dentz | 4539ca6 | 2021-10-01 13:22:31 -0700 | [diff] [blame] | 3686 | hdev->wakeup = btusb_wakeup; |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 3687 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3688 | #ifdef CONFIG_PM |
| 3689 | err = btusb_config_oob_wake(hdev); |
| 3690 | if (err) |
| 3691 | goto out_free_dev; |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 3692 | |
| 3693 | /* Marvell devices may need a specific chip configuration */ |
| 3694 | if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) { |
| 3695 | err = marvell_config_oob_wake(hdev); |
| 3696 | if (err) |
| 3697 | goto out_free_dev; |
| 3698 | } |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3699 | #endif |
Szymon Janc | 418678b | 2016-09-01 17:22:37 +0200 | [diff] [blame] | 3700 | if (id->driver_info & BTUSB_CW6622) |
| 3701 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
| 3702 | |
Marcel Holtmann | 6c9d435 | 2015-10-17 14:39:27 +0200 | [diff] [blame] | 3703 | if (id->driver_info & BTUSB_BCM2045) |
| 3704 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
| 3705 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 3706 | if (id->driver_info & BTUSB_BCM92035) |
| 3707 | hdev->setup = btusb_setup_bcm92035; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3708 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 3709 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && |
| 3710 | (id->driver_info & BTUSB_BCM_PATCHRAM)) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 3711 | hdev->manufacturer = 15; |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 3712 | hdev->setup = btbcm_setup_patchram; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3713 | hdev->set_diag = btusb_bcm_set_diag; |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 3714 | hdev->set_bdaddr = btbcm_set_bdaddr; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3715 | |
| 3716 | /* Broadcom LM_DIAG Interface numbers are hardcoded */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3717 | data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); |
Marcel Holtmann | abbaf50 | 2014-07-02 00:53:48 +0200 | [diff] [blame] | 3718 | } |
Petri Gynther | 10d4c67 | 2014-05-08 15:50:01 -0700 | [diff] [blame] | 3719 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 3720 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && |
| 3721 | (id->driver_info & BTUSB_BCM_APPLE)) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 3722 | hdev->manufacturer = 15; |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 3723 | hdev->setup = btbcm_setup_apple; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3724 | hdev->set_diag = btusb_bcm_set_diag; |
| 3725 | |
| 3726 | /* Broadcom LM_DIAG Interface numbers are hardcoded */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 3727 | data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3728 | } |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 3729 | |
Tedd Ho-Jeong An | 83f2daf | 2021-08-04 17:32:10 -0700 | [diff] [blame] | 3730 | /* Combined Intel Device setup to support multiple setup routine */ |
| 3731 | if (id->driver_info & BTUSB_INTEL_COMBINED) { |
| 3732 | err = btintel_configure_setup(hdev); |
| 3733 | if (err) |
| 3734 | goto out_free_dev; |
| 3735 | |
| 3736 | /* Transport specific configuration */ |
Tedd Ho-Jeong An | 019a1ca | 2021-08-04 17:32:15 -0700 | [diff] [blame] | 3737 | hdev->send = btusb_send_frame_intel; |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3738 | hdev->cmd_timeout = btusb_intel_cmd_timeout; |
Tedd Ho-Jeong An | 83f2daf | 2021-08-04 17:32:10 -0700 | [diff] [blame] | 3739 | |
Tedd Ho-Jeong An | ea7c4c0 | 2021-08-04 17:32:12 -0700 | [diff] [blame] | 3740 | if (id->driver_info & BTUSB_INTEL_BROKEN_INITIAL_NCMD) |
| 3741 | btintel_set_flag(hdev, INTEL_BROKEN_INITIAL_NCMD); |
Tedd Ho-Jeong An | 9565545 | 2022-01-06 16:34:54 -0800 | [diff] [blame] | 3742 | |
| 3743 | if (id->driver_info & BTUSB_INTEL_BROKEN_SHUTDOWN_LED) |
| 3744 | btintel_set_flag(hdev, INTEL_BROKEN_SHUTDOWN_LED); |
Marcel Holtmann | cb8d659 | 2014-07-02 11:25:25 +0200 | [diff] [blame] | 3745 | } |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 3746 | |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 3747 | if (id->driver_info & BTUSB_MARVELL) |
| 3748 | hdev->set_bdaddr = btusb_set_bdaddr_marvell; |
| 3749 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 3750 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) && |
| 3751 | (id->driver_info & BTUSB_MEDIATEK)) { |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3752 | hdev->setup = btusb_mtk_setup; |
| 3753 | hdev->shutdown = btusb_mtk_shutdown; |
| 3754 | hdev->manufacturer = 70; |
mark-yw.chen | e947802 | 2021-08-04 17:06:47 +0800 | [diff] [blame] | 3755 | hdev->cmd_timeout = btusb_mtk_cmd_timeout; |
Sean Wang | 8c0d17b | 2021-10-19 05:30:12 +0800 | [diff] [blame] | 3756 | hdev->set_bdaddr = btmtk_set_bdaddr; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3757 | set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); |
mark-yw.chen | 0b10c8c | 2021-08-04 17:03:15 +0800 | [diff] [blame] | 3758 | data->recv_acl = btusb_recv_acl_mtk; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3759 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3760 | |
Marcel Holtmann | 661cf88 | 2015-01-02 23:35:20 -0800 | [diff] [blame] | 3761 | if (id->driver_info & BTUSB_SWAVE) { |
| 3762 | set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks); |
Marcel Holtmann | d57dbe7 | 2014-12-26 04:42:33 +0100 | [diff] [blame] | 3763 | set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks); |
Marcel Holtmann | 661cf88 | 2015-01-02 23:35:20 -0800 | [diff] [blame] | 3764 | } |
Marcel Holtmann | d57dbe7 | 2014-12-26 04:42:33 +0100 | [diff] [blame] | 3765 | |
Marcel Holtmann | e4c534b | 2015-10-21 01:31:45 +0200 | [diff] [blame] | 3766 | if (id->driver_info & BTUSB_INTEL_BOOT) { |
| 3767 | hdev->manufacturer = 2; |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 3768 | set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); |
Marcel Holtmann | e4c534b | 2015-10-21 01:31:45 +0200 | [diff] [blame] | 3769 | } |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 3770 | |
Jakub Pawlowski | 79f0c87 | 2015-01-29 10:38:34 -0800 | [diff] [blame] | 3771 | if (id->driver_info & BTUSB_ATH3012) { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 3772 | data->setup_on_usb = btusb_setup_qca; |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 3773 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
Jakub Pawlowski | 3d50d51 | 2015-03-17 09:04:15 -0700 | [diff] [blame] | 3774 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Jakub Pawlowski | 79f0c87 | 2015-01-29 10:38:34 -0800 | [diff] [blame] | 3775 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
| 3776 | } |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 3777 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3778 | if (id->driver_info & BTUSB_QCA_ROME) { |
| 3779 | data->setup_on_usb = btusb_setup_qca; |
| 3780 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
Abhishek Pandit-Subedi | 6933568 | 2020-06-24 11:11:44 -0700 | [diff] [blame] | 3781 | hdev->cmd_timeout = btusb_qca_cmd_timeout; |
Vic Wei | 96e58d3 | 2018-03-28 08:28:47 -0700 | [diff] [blame] | 3782 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Hans de Goede | fc54910 | 2018-04-27 11:26:43 +0200 | [diff] [blame] | 3783 | btusb_check_needs_reset_resume(intf); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 3784 | } |
| 3785 | |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3786 | if (id->driver_info & BTUSB_QCA_WCN6855) { |
| 3787 | data->setup_on_usb = btusb_setup_qca; |
Tim Jiang | 3b0d525 | 2020-12-18 18:12:11 +0800 | [diff] [blame] | 3788 | hdev->shutdown = btusb_shutdown_qca; |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3789 | hdev->set_bdaddr = btusb_set_bdaddr_wcn6855; |
| 3790 | hdev->cmd_timeout = btusb_qca_cmd_timeout; |
| 3791 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Michael Sun | cbe6a04 | 2021-07-29 10:10:59 -0700 | [diff] [blame] | 3792 | hci_set_msft_opcode(hdev, 0xFD70); |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3793 | } |
| 3794 | |
Hilda Wu | 461f95f | 2020-06-30 21:09:40 +0800 | [diff] [blame] | 3795 | if (id->driver_info & BTUSB_AMP) { |
| 3796 | /* AMP controllers do not support SCO packets */ |
| 3797 | data->isoc = NULL; |
| 3798 | } else { |
| 3799 | /* Interface orders are hardcoded in the specification */ |
| 3800 | data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); |
| 3801 | data->isoc_ifnum = ifnum_base + 1; |
| 3802 | } |
| 3803 | |
Arnd Bergmann | 42d2209 | 2019-09-18 21:59:02 +0200 | [diff] [blame] | 3804 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) && |
| 3805 | (id->driver_info & BTUSB_REALTEK)) { |
Carlo Caione | db33c77 | 2015-05-14 10:49:09 +0200 | [diff] [blame] | 3806 | hdev->setup = btrtl_setup_realtek; |
Jian-Hong Pan | 7af3f558 | 2019-06-25 16:30:51 +0800 | [diff] [blame] | 3807 | hdev->shutdown = btrtl_shutdown_realtek; |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 3808 | hdev->cmd_timeout = btusb_rtl_cmd_timeout; |
Daniel Drake | 04b8c81 | 2015-05-21 08:23:50 -0600 | [diff] [blame] | 3809 | |
Max Chou | 8274db0 | 2021-08-17 11:03:12 +0800 | [diff] [blame] | 3810 | /* Realtek devices need to set remote wakeup on auto-suspend */ |
| 3811 | set_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags); |
Pauli Virtanen | 55981d3 | 2021-07-26 21:02:06 +0300 | [diff] [blame] | 3812 | set_bit(BTUSB_USE_ALT3_FOR_WBS, &data->flags); |
Daniel Drake | 04b8c81 | 2015-05-21 08:23:50 -0600 | [diff] [blame] | 3813 | } |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 3814 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3815 | if (!reset) |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 3816 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3817 | |
| 3818 | if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { |
| 3819 | if (!disable_scofix) |
| 3820 | set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks); |
| 3821 | } |
| 3822 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 3823 | if (id->driver_info & BTUSB_BROKEN_ISOC) |
| 3824 | data->isoc = NULL; |
| 3825 | |
Alain Michaud | 4b127bd | 2020-02-27 18:29:39 +0000 | [diff] [blame] | 3826 | if (id->driver_info & BTUSB_WIDEBAND_SPEECH) |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 3827 | set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks); |
Alain Michaud | 4b127bd | 2020-02-27 18:29:39 +0000 | [diff] [blame] | 3828 | |
Alain Michaud | aff8c48 | 2020-04-23 14:43:31 +0000 | [diff] [blame] | 3829 | if (id->driver_info & BTUSB_VALID_LE_STATES) |
| 3830 | set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks); |
| 3831 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3832 | if (id->driver_info & BTUSB_DIGIANSWER) { |
| 3833 | data->cmdreq_type = USB_TYPE_VENDOR; |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 3834 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | if (id->driver_info & BTUSB_CSR) { |
| 3838 | struct usb_device *udev = data->udev; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 3839 | u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3840 | |
| 3841 | /* Old firmware would otherwise execute USB reset */ |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 3842 | if (bcdDevice < 0x117) |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 3843 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 3844 | |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 3845 | /* This must be set first in case we disable it for fakes */ |
Jakub Pawlowski | 49c989a | 2015-03-17 09:04:17 -0700 | [diff] [blame] | 3846 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 3847 | |
| 3848 | /* Fake CSR devices with broken commands */ |
| 3849 | if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 && |
| 3850 | le16_to_cpu(udev->descriptor.idProduct) == 0x0001) |
| 3851 | hdev->setup = btusb_setup_csr; |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3852 | } |
| 3853 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3854 | if (id->driver_info & BTUSB_SNIFFER) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 3855 | struct usb_device *udev = data->udev; |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3856 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 3857 | /* New sniffer firmware has crippled HCI interface */ |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3858 | if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) |
| 3859 | set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); |
| 3860 | } |
| 3861 | |
Marcel Holtmann | 3a5ef20 | 2014-07-06 14:53:54 +0200 | [diff] [blame] | 3862 | if (id->driver_info & BTUSB_INTEL_BOOT) { |
| 3863 | /* A bug in the bootloader causes that interrupt interface is |
| 3864 | * only enabled after receiving SetInterface(0, AltSetting=0). |
| 3865 | */ |
| 3866 | err = usb_set_interface(data->udev, 0, 0); |
| 3867 | if (err < 0) { |
| 3868 | BT_ERR("failed to set interface 0, alt 0 %d", err); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 3869 | goto out_free_dev; |
Marcel Holtmann | 3a5ef20 | 2014-07-06 14:53:54 +0200 | [diff] [blame] | 3870 | } |
| 3871 | } |
| 3872 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 3873 | if (data->isoc) { |
| 3874 | err = usb_driver_claim_interface(&btusb_driver, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 3875 | data->isoc, data); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 3876 | if (err < 0) |
| 3877 | goto out_free_dev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 3878 | } |
| 3879 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 3880 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) { |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3881 | if (!usb_driver_claim_interface(&btusb_driver, |
| 3882 | data->diag, data)) |
| 3883 | __set_diag_interface(hdev); |
| 3884 | else |
| 3885 | data->diag = NULL; |
| 3886 | } |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3887 | |
Hans de Goede | 8959152 | 2021-04-09 15:58:50 +0200 | [diff] [blame] | 3888 | if (enable_autosuspend) |
| 3889 | usb_enable_autosuspend(data->udev); |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 3890 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3891 | err = hci_register_dev(hdev); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 3892 | if (err < 0) |
| 3893 | goto out_free_dev; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3894 | |
| 3895 | usb_set_intfdata(intf, data); |
| 3896 | |
Luiz Augusto von Dentz | 800fe5e | 2021-12-03 14:38:13 -0800 | [diff] [blame] | 3897 | debugfs_create_file("force_poll_sync", 0644, hdev->debugfs, data, |
| 3898 | &force_poll_sync_fops); |
| 3899 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3900 | return 0; |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 3901 | |
| 3902 | out_free_dev: |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3903 | if (data->reset_gpio) |
| 3904 | gpiod_put(data->reset_gpio); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 3905 | hci_free_dev(hdev); |
| 3906 | return err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | static void btusb_disconnect(struct usb_interface *intf) |
| 3910 | { |
| 3911 | struct btusb_data *data = usb_get_intfdata(intf); |
| 3912 | struct hci_dev *hdev; |
| 3913 | |
| 3914 | BT_DBG("intf %p", intf); |
| 3915 | |
| 3916 | if (!data) |
| 3917 | return; |
| 3918 | |
| 3919 | hdev = data->hdev; |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 3920 | usb_set_intfdata(data->intf, NULL); |
| 3921 | |
| 3922 | if (data->isoc) |
| 3923 | usb_set_intfdata(data->isoc, NULL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3924 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3925 | if (data->diag) |
| 3926 | usb_set_intfdata(data->diag, NULL); |
| 3927 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3928 | hci_unregister_dev(hdev); |
| 3929 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3930 | if (intf == data->intf) { |
| 3931 | if (data->isoc) |
| 3932 | usb_driver_release_interface(&btusb_driver, data->isoc); |
| 3933 | if (data->diag) |
| 3934 | usb_driver_release_interface(&btusb_driver, data->diag); |
| 3935 | } else if (intf == data->isoc) { |
| 3936 | if (data->diag) |
| 3937 | usb_driver_release_interface(&btusb_driver, data->diag); |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 3938 | usb_driver_release_interface(&btusb_driver, data->intf); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 3939 | } else if (intf == data->diag) { |
| 3940 | usb_driver_release_interface(&btusb_driver, data->intf); |
| 3941 | if (data->isoc) |
| 3942 | usb_driver_release_interface(&btusb_driver, data->isoc); |
| 3943 | } |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 3944 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3945 | if (data->oob_wake_irq) |
| 3946 | device_init_wakeup(&data->udev->dev, false); |
| 3947 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 3948 | if (data->reset_gpio) |
| 3949 | gpiod_put(data->reset_gpio); |
| 3950 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3951 | hci_free_dev(hdev); |
| 3952 | } |
| 3953 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 3954 | #ifdef CONFIG_PM |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 3955 | static int btusb_suspend(struct usb_interface *intf, pm_message_t message) |
| 3956 | { |
| 3957 | struct btusb_data *data = usb_get_intfdata(intf); |
| 3958 | |
| 3959 | BT_DBG("intf %p", intf); |
| 3960 | |
| 3961 | if (data->suspend_count++) |
| 3962 | return 0; |
| 3963 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 3964 | spin_lock_irq(&data->txlock); |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 3965 | if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) { |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 3966 | set_bit(BTUSB_SUSPENDING, &data->flags); |
| 3967 | spin_unlock_irq(&data->txlock); |
| 3968 | } else { |
| 3969 | spin_unlock_irq(&data->txlock); |
| 3970 | data->suspend_count--; |
| 3971 | return -EBUSY; |
| 3972 | } |
| 3973 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 3974 | cancel_work_sync(&data->work); |
| 3975 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 3976 | btusb_stop_traffic(data); |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 3977 | usb_kill_anchored_urbs(&data->tx_anchor); |
| 3978 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 3979 | if (data->oob_wake_irq && device_may_wakeup(&data->udev->dev)) { |
| 3980 | set_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags); |
| 3981 | enable_irq_wake(data->oob_wake_irq); |
| 3982 | enable_irq(data->oob_wake_irq); |
| 3983 | } |
| 3984 | |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 3985 | /* For global suspend, Realtek devices lose the loaded fw |
| 3986 | * in them. But for autosuspend, firmware should remain. |
| 3987 | * Actually, it depends on whether the usb host sends |
| 3988 | * set feature (enable wakeup) or not. |
| 3989 | */ |
Max Chou | 8274db0 | 2021-08-17 11:03:12 +0800 | [diff] [blame] | 3990 | if (test_bit(BTUSB_WAKEUP_AUTOSUSPEND, &data->flags)) { |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 3991 | if (PMSG_IS_AUTO(message) && |
| 3992 | device_can_wakeup(&data->udev->dev)) |
| 3993 | data->udev->do_remote_wakeup = 1; |
Max Chou | 8274db0 | 2021-08-17 11:03:12 +0800 | [diff] [blame] | 3994 | else if (!PMSG_IS_AUTO(message) && |
| 3995 | !device_may_wakeup(&data->udev->dev)) { |
| 3996 | data->udev->do_remote_wakeup = 0; |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 3997 | data->udev->reset_resume = 1; |
Max Chou | 8274db0 | 2021-08-17 11:03:12 +0800 | [diff] [blame] | 3998 | } |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 3999 | } |
| 4000 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4001 | return 0; |
| 4002 | } |
| 4003 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4004 | static void play_deferred(struct btusb_data *data) |
| 4005 | { |
| 4006 | struct urb *urb; |
| 4007 | int err; |
| 4008 | |
| 4009 | while ((urb = usb_get_from_anchor(&data->deferred))) { |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4010 | usb_anchor_urb(urb, &data->tx_anchor); |
| 4011 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4012 | err = usb_submit_urb(urb, GFP_ATOMIC); |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4013 | if (err < 0) { |
| 4014 | if (err != -EPERM && err != -ENODEV) |
| 4015 | BT_ERR("%s urb %p submission failed (%d)", |
| 4016 | data->hdev->name, urb, -err); |
| 4017 | kfree(urb->setup_packet); |
| 4018 | usb_unanchor_urb(urb); |
| 4019 | usb_free_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4020 | break; |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4021 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4022 | |
| 4023 | data->tx_in_flight++; |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4024 | usb_free_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4025 | } |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4026 | |
| 4027 | /* Cleanup the rest deferred urbs. */ |
| 4028 | while ((urb = usb_get_from_anchor(&data->deferred))) { |
| 4029 | kfree(urb->setup_packet); |
| 4030 | usb_free_urb(urb); |
| 4031 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4032 | } |
| 4033 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4034 | static int btusb_resume(struct usb_interface *intf) |
| 4035 | { |
| 4036 | struct btusb_data *data = usb_get_intfdata(intf); |
| 4037 | struct hci_dev *hdev = data->hdev; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4038 | int err = 0; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4039 | |
| 4040 | BT_DBG("intf %p", intf); |
| 4041 | |
| 4042 | if (--data->suspend_count) |
| 4043 | return 0; |
| 4044 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4045 | /* Disable only if not already disabled (keep it balanced) */ |
| 4046 | if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) { |
| 4047 | disable_irq(data->oob_wake_irq); |
| 4048 | disable_irq_wake(data->oob_wake_irq); |
| 4049 | } |
| 4050 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4051 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4052 | goto done; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4053 | |
| 4054 | if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) { |
| 4055 | err = btusb_submit_intr_urb(hdev, GFP_NOIO); |
| 4056 | if (err < 0) { |
| 4057 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4058 | goto failed; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4059 | } |
| 4060 | } |
| 4061 | |
| 4062 | if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) { |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 4063 | err = btusb_submit_bulk_urb(hdev, GFP_NOIO); |
| 4064 | if (err < 0) { |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4065 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4066 | goto failed; |
| 4067 | } |
| 4068 | |
| 4069 | btusb_submit_bulk_urb(hdev, GFP_NOIO); |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
| 4073 | if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0) |
| 4074 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 4075 | else |
| 4076 | btusb_submit_isoc_urb(hdev, GFP_NOIO); |
| 4077 | } |
| 4078 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4079 | spin_lock_irq(&data->txlock); |
| 4080 | play_deferred(data); |
| 4081 | clear_bit(BTUSB_SUSPENDING, &data->flags); |
| 4082 | spin_unlock_irq(&data->txlock); |
| 4083 | schedule_work(&data->work); |
| 4084 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4085 | return 0; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4086 | |
| 4087 | failed: |
| 4088 | usb_scuttle_anchored_urbs(&data->deferred); |
| 4089 | done: |
| 4090 | spin_lock_irq(&data->txlock); |
| 4091 | clear_bit(BTUSB_SUSPENDING, &data->flags); |
| 4092 | spin_unlock_irq(&data->txlock); |
| 4093 | |
| 4094 | return err; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4095 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4096 | #endif |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4097 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4098 | static struct usb_driver btusb_driver = { |
| 4099 | .name = "btusb", |
| 4100 | .probe = btusb_probe, |
| 4101 | .disconnect = btusb_disconnect, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4102 | #ifdef CONFIG_PM |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4103 | .suspend = btusb_suspend, |
| 4104 | .resume = btusb_resume, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4105 | #endif |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4106 | .id_table = btusb_table, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4107 | .supports_autosuspend = 1, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 4108 | .disable_hub_initiated_lpm = 1, |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4109 | }; |
| 4110 | |
Greg Kroah-Hartman | 93f1508 | 2011-11-18 09:47:34 -0800 | [diff] [blame] | 4111 | module_usb_driver(btusb_driver); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4112 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4113 | module_param(disable_scofix, bool, 0644); |
| 4114 | MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size"); |
| 4115 | |
| 4116 | module_param(force_scofix, bool, 0644); |
| 4117 | MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size"); |
| 4118 | |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 4119 | module_param(enable_autosuspend, bool, 0644); |
| 4120 | MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default"); |
| 4121 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4122 | module_param(reset, bool, 0644); |
| 4123 | MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); |
| 4124 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4125 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); |
| 4126 | MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION); |
| 4127 | MODULE_VERSION(VERSION); |
| 4128 | MODULE_LICENSE("GPL"); |