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