Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * Generic Bluetooth USB driver |
| 5 | * |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 6 | * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 9 | #include <linux/dmi.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 10 | #include <linux/module.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 11 | #include <linux/usb.h> |
Hans de Goede | 61f5ace | 2018-01-08 10:44:16 +0100 | [diff] [blame] | 12 | #include <linux/usb/quirks.h> |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 13 | #include <linux/firmware.h> |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 14 | #include <linux/iopoll.h> |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 15 | #include <linux/of_device.h> |
| 16 | #include <linux/of_irq.h> |
Jeffy Chen | 017789f | 2017-02-24 14:24:29 +0800 | [diff] [blame] | 17 | #include <linux/suspend.h> |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 18 | #include <linux/gpio/consumer.h> |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 19 | #include <asm/unaligned.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 20 | |
| 21 | #include <net/bluetooth/bluetooth.h> |
| 22 | #include <net/bluetooth/hci_core.h> |
| 23 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 24 | #include "btintel.h" |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 25 | #include "btbcm.h" |
Carlo Caione | db33c77 | 2015-05-14 10:49:09 +0200 | [diff] [blame] | 26 | #include "btrtl.h" |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 27 | |
Marcel Holtmann | 34dced9b | 2015-04-05 22:52:16 -0700 | [diff] [blame] | 28 | #define VERSION "0.8" |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 29 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 30 | static bool disable_scofix; |
| 31 | static bool force_scofix; |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 32 | static bool enable_autosuspend = IS_ENABLED(CONFIG_BT_HCIBTUSB_AUTOSUSPEND); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 33 | |
Shailendra Verma | 917a333 | 2015-05-25 23:53:40 +0530 | [diff] [blame] | 34 | static bool reset = true; |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 35 | |
| 36 | static struct usb_driver btusb_driver; |
| 37 | |
| 38 | #define BTUSB_IGNORE 0x01 |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 39 | #define BTUSB_DIGIANSWER 0x02 |
| 40 | #define BTUSB_CSR 0x04 |
| 41 | #define BTUSB_SNIFFER 0x08 |
| 42 | #define BTUSB_BCM92035 0x10 |
| 43 | #define BTUSB_BROKEN_ISOC 0x20 |
| 44 | #define BTUSB_WRONG_SCO_MTU 0x40 |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 45 | #define BTUSB_ATH3012 0x80 |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 46 | #define BTUSB_INTEL 0x100 |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 47 | #define BTUSB_INTEL_BOOT 0x200 |
| 48 | #define BTUSB_BCM_PATCHRAM 0x400 |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 49 | #define BTUSB_MARVELL 0x800 |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 50 | #define BTUSB_SWAVE 0x1000 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 51 | #define BTUSB_INTEL_NEW 0x2000 |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 52 | #define BTUSB_AMP 0x4000 |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 53 | #define BTUSB_QCA_ROME 0x8000 |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 54 | #define BTUSB_BCM_APPLE 0x10000 |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 55 | #define BTUSB_REALTEK 0x20000 |
Marcel Holtmann | 6c9d435 | 2015-10-17 14:39:27 +0200 | [diff] [blame] | 56 | #define BTUSB_BCM2045 0x40000 |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 57 | #define BTUSB_IFNUM_2 0x80000 |
Szymon Janc | 418678b | 2016-09-01 17:22:37 +0200 | [diff] [blame] | 58 | #define BTUSB_CW6622 0x100000 |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 59 | #define BTUSB_MEDIATEK 0x200000 |
Alain Michaud | 3e4e3f7 | 2020-02-27 18:29:37 +0000 | [diff] [blame] | 60 | #define BTUSB_WIDEBAND_SPEECH 0x400000 |
Alain Michaud | 22091585 | 2020-04-23 14:43:27 +0000 | [diff] [blame] | 61 | #define BTUSB_VALID_LE_STATES 0x800000 |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 62 | #define BTUSB_QCA_WCN6855 0x1000000 |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 63 | #define BTUSB_INTEL_NEWGEN 0x2000000 |
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 */ |
Alain Michaud | 3e4e3f7 | 2020-02-27 18:29:37 +0000 | [diff] [blame] | 362 | { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_NEW | |
Alain Michaud | aff8c48 | 2020-04-23 14:43:31 +0000 | [diff] [blame] | 363 | BTUSB_WIDEBAND_SPEECH | |
| 364 | BTUSB_VALID_LE_STATES }, |
Alain Michaud | 3e4e3f7 | 2020-02-27 18:29:37 +0000 | [diff] [blame] | 365 | { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_NEW | |
| 366 | BTUSB_WIDEBAND_SPEECH }, |
| 367 | { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_NEW | |
| 368 | BTUSB_WIDEBAND_SPEECH }, |
Kiran K | 10c2423 | 2020-11-19 17:09:43 +0530 | [diff] [blame] | 369 | { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_NEWGEN | |
Raghuram Hegde | 875e16759 | 2020-05-11 16:40:40 +0530 | [diff] [blame] | 370 | BTUSB_WIDEBAND_SPEECH}, |
Kiran K | f01bb2a | 2021-01-05 08:32:29 +0530 | [diff] [blame] | 371 | { USB_DEVICE(0x8087, 0x0033), .driver_info = BTUSB_INTEL_NEWGEN | |
Michael Sun | acd5aea | 2021-07-23 17:17:31 -0700 | [diff] [blame] | 372 | BTUSB_WIDEBAND_SPEECH | |
| 373 | BTUSB_VALID_LE_STATES }, |
Marcel Holtmann | 407550f | 2015-02-22 15:41:18 -0800 | [diff] [blame] | 374 | { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 375 | { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL }, |
Tedd Ho-Jeong An | ef4e5e4 | 2013-11-12 13:10:58 -0800 | [diff] [blame] | 376 | { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL }, |
Alain Michaud | 3e4e3f7 | 2020-02-27 18:29:37 +0000 | [diff] [blame] | 377 | { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW | |
| 378 | BTUSB_WIDEBAND_SPEECH }, |
| 379 | { USB_DEVICE(0x8087, 0x0aa7), .driver_info = BTUSB_INTEL | |
| 380 | BTUSB_WIDEBAND_SPEECH }, |
| 381 | { USB_DEVICE(0x8087, 0x0aaa), .driver_info = BTUSB_INTEL_NEW | |
Alain Michaud | aff8c48 | 2020-04-23 14:43:31 +0000 | [diff] [blame] | 382 | BTUSB_WIDEBAND_SPEECH | |
| 383 | BTUSB_VALID_LE_STATES }, |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 384 | |
Marcel Holtmann | d0ac9eb | 2015-01-28 19:41:43 -0800 | [diff] [blame] | 385 | /* Other Intel Bluetooth devices */ |
| 386 | { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01), |
| 387 | .driver_info = BTUSB_IGNORE }, |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 388 | |
Joseph Hwang | 33bfd94 | 2020-07-13 15:45:29 +0800 | [diff] [blame] | 389 | /* Realtek 8822CE Bluetooth devices */ |
| 390 | { USB_DEVICE(0x0bda, 0xb00c), .driver_info = BTUSB_REALTEK | |
| 391 | BTUSB_WIDEBAND_SPEECH }, |
Larry Finger | 4d96d3b | 2021-06-01 14:04:18 -0500 | [diff] [blame] | 392 | { USB_DEVICE(0x0bda, 0xc822), .driver_info = BTUSB_REALTEK | |
| 393 | BTUSB_WIDEBAND_SPEECH }, |
Joseph Hwang | 33bfd94 | 2020-07-13 15:45:29 +0800 | [diff] [blame] | 394 | |
Max Chou | 0d484db | 2020-11-10 11:38:37 +0800 | [diff] [blame] | 395 | /* Realtek 8852AE Bluetooth devices */ |
| 396 | { USB_DEVICE(0x0bda, 0xc852), .driver_info = BTUSB_REALTEK | |
| 397 | BTUSB_WIDEBAND_SPEECH }, |
| 398 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 399 | /* Realtek Bluetooth devices */ |
| 400 | { USB_VENDOR_AND_INTERFACE_INFO(0x0bda, 0xe0, 0x01, 0x01), |
| 401 | .driver_info = BTUSB_REALTEK }, |
| 402 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 403 | /* MediaTek Bluetooth devices */ |
| 404 | { USB_VENDOR_AND_INTERFACE_INFO(0x0e8d, 0xe0, 0x01, 0x01), |
mark-yw.chen | 27e554a | 2021-03-29 01:18:33 +0800 | [diff] [blame] | 405 | .driver_info = BTUSB_MEDIATEK | |
| 406 | BTUSB_WIDEBAND_SPEECH | |
| 407 | BTUSB_VALID_LE_STATES }, |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 408 | |
Chris Chiu | 3a567b9 | 2020-11-10 11:40:10 +0800 | [diff] [blame] | 409 | /* Additional MediaTek MT7615E Bluetooth devices */ |
| 410 | { USB_DEVICE(0x13d3, 0x3560), .driver_info = BTUSB_MEDIATEK}, |
| 411 | |
Forest Crossman | 3735682 | 2021-07-12 02:32:20 -0500 | [diff] [blame] | 412 | /* Additional MediaTek MT7668 Bluetooth devices */ |
| 413 | { USB_DEVICE(0x043e, 0x3109), .driver_info = BTUSB_MEDIATEK | |
| 414 | BTUSB_WIDEBAND_SPEECH | |
| 415 | BTUSB_VALID_LE_STATES }, |
| 416 | |
mark-yw.chen | 393dc5d | 2021-04-12 23:06:27 +0800 | [diff] [blame] | 417 | /* Additional MediaTek MT7921 Bluetooth devices */ |
| 418 | { USB_DEVICE(0x04ca, 0x3802), .driver_info = BTUSB_MEDIATEK | |
| 419 | BTUSB_WIDEBAND_SPEECH | |
| 420 | BTUSB_VALID_LE_STATES }, |
Wai Paulo Valerio Wang | 2cdff8c | 2021-07-08 04:00:59 +0800 | [diff] [blame] | 421 | { USB_DEVICE(0x13d3, 0x3563), .driver_info = BTUSB_MEDIATEK | |
| 422 | BTUSB_WIDEBAND_SPEECH | |
| 423 | BTUSB_VALID_LE_STATES }, |
Aaron Ma | 64832df | 2021-07-23 01:17:18 +0800 | [diff] [blame] | 424 | { USB_DEVICE(0x0489, 0xe0cd), .driver_info = BTUSB_MEDIATEK | |
| 425 | BTUSB_WIDEBAND_SPEECH | |
| 426 | BTUSB_VALID_LE_STATES }, |
mark-yw.chen | 393dc5d | 2021-04-12 23:06:27 +0800 | [diff] [blame] | 427 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 428 | /* Additional Realtek 8723AE Bluetooth devices */ |
| 429 | { USB_DEVICE(0x0930, 0x021d), .driver_info = BTUSB_REALTEK }, |
| 430 | { USB_DEVICE(0x13d3, 0x3394), .driver_info = BTUSB_REALTEK }, |
| 431 | |
| 432 | /* Additional Realtek 8723BE Bluetooth devices */ |
| 433 | { USB_DEVICE(0x0489, 0xe085), .driver_info = BTUSB_REALTEK }, |
| 434 | { USB_DEVICE(0x0489, 0xe08b), .driver_info = BTUSB_REALTEK }, |
| 435 | { USB_DEVICE(0x13d3, 0x3410), .driver_info = BTUSB_REALTEK }, |
| 436 | { USB_DEVICE(0x13d3, 0x3416), .driver_info = BTUSB_REALTEK }, |
| 437 | { USB_DEVICE(0x13d3, 0x3459), .driver_info = BTUSB_REALTEK }, |
Dmitry Tunin | a81d72d | 2017-08-08 14:09:02 +0300 | [diff] [blame] | 438 | { USB_DEVICE(0x13d3, 0x3494), .driver_info = BTUSB_REALTEK }, |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 439 | |
Vicente Bergas | a41e079 | 2018-03-20 19:41:10 +0100 | [diff] [blame] | 440 | /* Additional Realtek 8723BU Bluetooth devices */ |
| 441 | { USB_DEVICE(0x7392, 0xa611), .driver_info = BTUSB_REALTEK }, |
| 442 | |
Jian-Hong Pan | 66d9975 | 2018-05-21 18:09:20 +0800 | [diff] [blame] | 443 | /* Additional Realtek 8723DE Bluetooth devices */ |
Jian-Hong Pan | 45ae68b | 2018-05-25 17:54:52 +0800 | [diff] [blame] | 444 | { USB_DEVICE(0x0bda, 0xb009), .driver_info = BTUSB_REALTEK }, |
Jian-Hong Pan | 66d9975 | 2018-05-21 18:09:20 +0800 | [diff] [blame] | 445 | { USB_DEVICE(0x2ff8, 0xb011), .driver_info = BTUSB_REALTEK }, |
| 446 | |
Joakim Tjernlund | 3340438 | 2021-05-28 17:26:45 +0200 | [diff] [blame] | 447 | /* Additional Realtek 8761BU Bluetooth devices */ |
| 448 | { USB_DEVICE(0x0b05, 0x190e), .driver_info = BTUSB_REALTEK | |
| 449 | BTUSB_WIDEBAND_SPEECH }, |
| 450 | |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 451 | /* Additional Realtek 8821AE Bluetooth devices */ |
| 452 | { USB_DEVICE(0x0b05, 0x17dc), .driver_info = BTUSB_REALTEK }, |
| 453 | { USB_DEVICE(0x13d3, 0x3414), .driver_info = BTUSB_REALTEK }, |
| 454 | { USB_DEVICE(0x13d3, 0x3458), .driver_info = BTUSB_REALTEK }, |
| 455 | { USB_DEVICE(0x13d3, 0x3461), .driver_info = BTUSB_REALTEK }, |
| 456 | { USB_DEVICE(0x13d3, 0x3462), .driver_info = BTUSB_REALTEK }, |
| 457 | |
Larry Finger | fed03fe | 2018-02-11 12:24:32 -0600 | [diff] [blame] | 458 | /* Additional Realtek 8822BE Bluetooth devices */ |
Artiom Vaskov | 1cd2fab | 2018-05-30 11:23:00 +0300 | [diff] [blame] | 459 | { USB_DEVICE(0x13d3, 0x3526), .driver_info = BTUSB_REALTEK }, |
Larry Finger | fed03fe | 2018-02-11 12:24:32 -0600 | [diff] [blame] | 460 | { USB_DEVICE(0x0b05, 0x185c), .driver_info = BTUSB_REALTEK }, |
| 461 | |
Jian-Hong Pan | 6d0762b | 2019-09-03 17:10:42 +0800 | [diff] [blame] | 462 | /* Additional Realtek 8822CE Bluetooth devices */ |
Max Chou | 73280f1 | 2020-11-05 18:54:48 +0800 | [diff] [blame] | 463 | { USB_DEVICE(0x04ca, 0x4005), .driver_info = BTUSB_REALTEK | |
| 464 | BTUSB_WIDEBAND_SPEECH }, |
| 465 | { USB_DEVICE(0x04c5, 0x161f), .driver_info = BTUSB_REALTEK | |
| 466 | BTUSB_WIDEBAND_SPEECH }, |
| 467 | { USB_DEVICE(0x0b05, 0x18ef), .driver_info = BTUSB_REALTEK | |
| 468 | BTUSB_WIDEBAND_SPEECH }, |
| 469 | { USB_DEVICE(0x13d3, 0x3548), .driver_info = BTUSB_REALTEK | |
| 470 | BTUSB_WIDEBAND_SPEECH }, |
| 471 | { USB_DEVICE(0x13d3, 0x3549), .driver_info = BTUSB_REALTEK | |
| 472 | BTUSB_WIDEBAND_SPEECH }, |
| 473 | { USB_DEVICE(0x13d3, 0x3553), .driver_info = BTUSB_REALTEK | |
| 474 | BTUSB_WIDEBAND_SPEECH }, |
| 475 | { USB_DEVICE(0x13d3, 0x3555), .driver_info = BTUSB_REALTEK | |
| 476 | BTUSB_WIDEBAND_SPEECH }, |
| 477 | { USB_DEVICE(0x2ff8, 0x3051), .driver_info = BTUSB_REALTEK | |
| 478 | BTUSB_WIDEBAND_SPEECH }, |
Julian Pidancet | f496297 | 2020-11-09 17:47:22 +0100 | [diff] [blame] | 479 | { USB_DEVICE(0x1358, 0xc123), .driver_info = BTUSB_REALTEK | |
| 480 | BTUSB_WIDEBAND_SPEECH }, |
Cadel Watson | 24d6a6d | 2020-11-19 16:16:25 +1100 | [diff] [blame] | 481 | { USB_DEVICE(0x0bda, 0xc123), .driver_info = BTUSB_REALTEK | |
| 482 | BTUSB_WIDEBAND_SPEECH }, |
Rasmus Moorats | 3edc578 | 2021-02-18 13:11:24 +0200 | [diff] [blame] | 483 | { USB_DEVICE(0x0cb5, 0xc547), .driver_info = BTUSB_REALTEK | |
| 484 | BTUSB_WIDEBAND_SPEECH }, |
Jian-Hong Pan | 6d0762b | 2019-09-03 17:10:42 +0800 | [diff] [blame] | 485 | |
Peter Poklop | 4481c07 | 2015-08-15 20:47:09 +0200 | [diff] [blame] | 486 | /* Silicon Wave based devices */ |
| 487 | { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE }, |
| 488 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 489 | { } /* Terminating entry */ |
| 490 | }; |
| 491 | |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 492 | /* The Bluetooth USB module build into some devices needs to be reset on resume, |
| 493 | * this is a problem with the platform (likely shutting off all power) not with |
| 494 | * the module itself. So we use a DMI list to match known broken platforms. |
| 495 | */ |
| 496 | static const struct dmi_system_id btusb_needs_reset_resume_table[] = { |
| 497 | { |
Kai-Heng Feng | 0c6e526 | 2018-03-01 13:42:52 +0800 | [diff] [blame] | 498 | /* Dell OptiPlex 3060 (QCA ROME device 0cf3:e007) */ |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 499 | .matches = { |
Kai-Heng Feng | 0c6e526 | 2018-03-01 13:42:52 +0800 | [diff] [blame] | 500 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 501 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 3060"), |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 502 | }, |
| 503 | }, |
Hans de Goede | 596b07a | 2018-04-26 20:52:06 +0200 | [diff] [blame] | 504 | { |
| 505 | /* Dell XPS 9360 (QCA ROME device 0cf3:e300) */ |
| 506 | .matches = { |
| 507 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 508 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS 13 9360"), |
| 509 | }, |
| 510 | }, |
Hans de Goede | 939bc6c | 2018-05-22 09:34:10 +0200 | [diff] [blame] | 511 | { |
| 512 | /* Dell Inspiron 5565 (QCA ROME device 0cf3:e009) */ |
| 513 | .matches = { |
| 514 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 515 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5565"), |
| 516 | }, |
| 517 | }, |
Hans de Goede | 1fdb926 | 2018-02-20 09:06:18 +0100 | [diff] [blame] | 518 | {} |
| 519 | }; |
| 520 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 521 | #define BTUSB_MAX_ISOC_FRAMES 10 |
| 522 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 523 | #define BTUSB_INTR_RUNNING 0 |
| 524 | #define BTUSB_BULK_RUNNING 1 |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 525 | #define BTUSB_ISOC_RUNNING 2 |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 526 | #define BTUSB_SUSPENDING 3 |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 527 | #define BTUSB_DID_ISO_RESUME 4 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 528 | #define BTUSB_BOOTLOADER 5 |
| 529 | #define BTUSB_DOWNLOADING 6 |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 530 | #define BTUSB_FIRMWARE_LOADED 7 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 531 | #define BTUSB_FIRMWARE_FAILED 8 |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 532 | #define BTUSB_BOOTING 9 |
Hans de Goede | 61f5ace | 2018-01-08 10:44:16 +0100 | [diff] [blame] | 533 | #define BTUSB_DIAG_RUNNING 10 |
| 534 | #define BTUSB_OOB_WAKE_ENABLED 11 |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 535 | #define BTUSB_HW_RESET_ACTIVE 12 |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 536 | #define BTUSB_TX_WAIT_VND_EVT 13 |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 537 | #define BTUSB_WAKEUP_DISABLE 14 |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 538 | |
| 539 | struct btusb_data { |
| 540 | struct hci_dev *hdev; |
| 541 | struct usb_device *udev; |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 542 | struct usb_interface *intf; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 543 | struct usb_interface *isoc; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 544 | struct usb_interface *diag; |
Marcel Holtmann | 459232f | 2017-10-24 19:42:45 +0200 | [diff] [blame] | 545 | unsigned isoc_ifnum; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 546 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 547 | unsigned long flags; |
| 548 | |
| 549 | struct work_struct work; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 550 | struct work_struct waker; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 551 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 552 | struct usb_anchor deferred; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 553 | struct usb_anchor tx_anchor; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 554 | int tx_in_flight; |
| 555 | spinlock_t txlock; |
| 556 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 557 | struct usb_anchor intr_anchor; |
| 558 | struct usb_anchor bulk_anchor; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 559 | struct usb_anchor isoc_anchor; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 560 | struct usb_anchor diag_anchor; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 561 | struct usb_anchor ctrl_anchor; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 562 | spinlock_t rxlock; |
| 563 | |
| 564 | struct sk_buff *evt_skb; |
| 565 | struct sk_buff *acl_skb; |
| 566 | struct sk_buff *sco_skb; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 567 | |
| 568 | struct usb_endpoint_descriptor *intr_ep; |
| 569 | struct usb_endpoint_descriptor *bulk_tx_ep; |
| 570 | struct usb_endpoint_descriptor *bulk_rx_ep; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 571 | struct usb_endpoint_descriptor *isoc_tx_ep; |
| 572 | struct usb_endpoint_descriptor *isoc_rx_ep; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 573 | struct usb_endpoint_descriptor *diag_tx_ep; |
| 574 | struct usb_endpoint_descriptor *diag_rx_ep; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 575 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 576 | struct gpio_desc *reset_gpio; |
| 577 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 578 | __u8 cmdreq_type; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 579 | __u8 cmdreq; |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 580 | |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 581 | unsigned int sco_num; |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 582 | unsigned int air_mode; |
| 583 | bool usb_alt6_packet_flow; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 584 | int isoc_altsetting; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 585 | int suspend_count; |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 586 | |
Marcel Holtmann | 97307f5 | 2015-01-12 13:51:10 -0800 | [diff] [blame] | 587 | int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb); |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 588 | 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] | 589 | |
| 590 | int (*setup_on_usb)(struct hci_dev *hdev); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 591 | |
| 592 | int oob_wake_irq; /* irq for out-of-band wake-on-bt */ |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 593 | unsigned cmd_timeout_cnt; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 594 | }; |
| 595 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 596 | static void btusb_intel_cmd_timeout(struct hci_dev *hdev) |
| 597 | { |
| 598 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 599 | struct gpio_desc *reset_gpio = data->reset_gpio; |
| 600 | |
| 601 | if (++data->cmd_timeout_cnt < 5) |
| 602 | return; |
| 603 | |
| 604 | if (!reset_gpio) { |
| 605 | bt_dev_err(hdev, "No way to reset. Ignoring and continuing"); |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | /* |
| 610 | * Toggle the hard reset line if the platform provides one. The reset |
| 611 | * is going to yank the device off the USB and then replug. So doing |
| 612 | * once is enough. The cleanup is handled correctly on the way out |
| 613 | * (standard USB disconnect), and the new device is detected cleanly |
| 614 | * and bound to the driver again like it should be. |
| 615 | */ |
| 616 | if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
| 617 | bt_dev_err(hdev, "last reset failed? Not resetting again"); |
| 618 | return; |
| 619 | } |
| 620 | |
| 621 | bt_dev_err(hdev, "Initiating HW reset via gpio"); |
Rajat Jain | 2de66bb8 | 2019-01-28 15:08:09 -0800 | [diff] [blame] | 622 | gpiod_set_value_cansleep(reset_gpio, 1); |
| 623 | msleep(100); |
| 624 | gpiod_set_value_cansleep(reset_gpio, 0); |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 625 | } |
| 626 | |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 627 | static void btusb_rtl_cmd_timeout(struct hci_dev *hdev) |
| 628 | { |
| 629 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 630 | struct gpio_desc *reset_gpio = data->reset_gpio; |
| 631 | |
| 632 | if (++data->cmd_timeout_cnt < 5) |
| 633 | return; |
| 634 | |
| 635 | if (!reset_gpio) { |
| 636 | bt_dev_err(hdev, "No gpio to reset Realtek device, ignoring"); |
| 637 | return; |
| 638 | } |
| 639 | |
| 640 | /* Toggle the hard reset line. The Realtek device is going to |
| 641 | * yank itself off the USB and then replug. The cleanup is handled |
| 642 | * correctly on the way out (standard USB disconnect), and the new |
| 643 | * device is detected cleanly and bound to the driver again like |
| 644 | * it should be. |
| 645 | */ |
| 646 | if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { |
| 647 | bt_dev_err(hdev, "last reset failed? Not resetting again"); |
| 648 | return; |
| 649 | } |
| 650 | |
| 651 | bt_dev_err(hdev, "Reset Realtek device via gpio"); |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 652 | gpiod_set_value_cansleep(reset_gpio, 1); |
Max Chou | 3468211 | 2019-11-27 11:01:07 +0800 | [diff] [blame] | 653 | msleep(200); |
| 654 | gpiod_set_value_cansleep(reset_gpio, 0); |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 655 | } |
| 656 | |
Abhishek Pandit-Subedi | 6933568 | 2020-06-24 11:11:44 -0700 | [diff] [blame] | 657 | static void btusb_qca_cmd_timeout(struct hci_dev *hdev) |
| 658 | { |
| 659 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 660 | int err; |
| 661 | |
| 662 | if (++data->cmd_timeout_cnt < 5) |
| 663 | return; |
| 664 | |
| 665 | bt_dev_err(hdev, "Multiple cmd timeouts seen. Resetting usb device."); |
Abhishek Pandit-Subedi | b980d47 | 2020-06-25 16:26:27 -0700 | [diff] [blame] | 666 | /* 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] | 667 | err = usb_autopm_get_interface(data->intf); |
| 668 | if (!err) |
| 669 | usb_queue_reset_device(data->intf); |
| 670 | else |
| 671 | bt_dev_err(hdev, "Failed usb_autopm_get_interface with %d", err); |
| 672 | } |
| 673 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 674 | static inline void btusb_free_frags(struct btusb_data *data) |
| 675 | { |
| 676 | unsigned long flags; |
| 677 | |
| 678 | spin_lock_irqsave(&data->rxlock, flags); |
| 679 | |
| 680 | kfree_skb(data->evt_skb); |
| 681 | data->evt_skb = NULL; |
| 682 | |
| 683 | kfree_skb(data->acl_skb); |
| 684 | data->acl_skb = NULL; |
| 685 | |
| 686 | kfree_skb(data->sco_skb); |
| 687 | data->sco_skb = NULL; |
| 688 | |
| 689 | spin_unlock_irqrestore(&data->rxlock, flags); |
| 690 | } |
| 691 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 692 | static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count) |
| 693 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 694 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 695 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 696 | int err = 0; |
| 697 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 698 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 699 | skb = data->evt_skb; |
| 700 | |
| 701 | while (count) { |
| 702 | int len; |
| 703 | |
| 704 | if (!skb) { |
| 705 | skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC); |
| 706 | if (!skb) { |
| 707 | err = -ENOMEM; |
| 708 | break; |
| 709 | } |
| 710 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 711 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
| 712 | hci_skb_expect(skb) = HCI_EVENT_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 713 | } |
| 714 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 715 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 716 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 717 | |
| 718 | count -= len; |
| 719 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 720 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 721 | |
| 722 | if (skb->len == HCI_EVENT_HDR_SIZE) { |
| 723 | /* Complete event header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 724 | hci_skb_expect(skb) = hci_event_hdr(skb)->plen; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 725 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 726 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 727 | kfree_skb(skb); |
| 728 | skb = NULL; |
| 729 | |
| 730 | err = -EILSEQ; |
| 731 | break; |
| 732 | } |
| 733 | } |
| 734 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 735 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 736 | /* Complete frame */ |
Marcel Holtmann | 97307f5 | 2015-01-12 13:51:10 -0800 | [diff] [blame] | 737 | data->recv_event(data->hdev, skb); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 738 | skb = NULL; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | data->evt_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 743 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 744 | |
| 745 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count) |
| 749 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 750 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 751 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 752 | int err = 0; |
| 753 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 754 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 755 | skb = data->acl_skb; |
| 756 | |
| 757 | while (count) { |
| 758 | int len; |
| 759 | |
| 760 | if (!skb) { |
| 761 | skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); |
| 762 | if (!skb) { |
| 763 | err = -ENOMEM; |
| 764 | break; |
| 765 | } |
| 766 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 767 | hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT; |
| 768 | hci_skb_expect(skb) = HCI_ACL_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 769 | } |
| 770 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 771 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 772 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 773 | |
| 774 | count -= len; |
| 775 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 776 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 777 | |
| 778 | if (skb->len == HCI_ACL_HDR_SIZE) { |
| 779 | __le16 dlen = hci_acl_hdr(skb)->dlen; |
| 780 | |
| 781 | /* Complete ACL header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 782 | hci_skb_expect(skb) = __le16_to_cpu(dlen); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 783 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 784 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 785 | kfree_skb(skb); |
| 786 | skb = NULL; |
| 787 | |
| 788 | err = -EILSEQ; |
| 789 | break; |
| 790 | } |
| 791 | } |
| 792 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 793 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 794 | /* Complete frame */ |
| 795 | hci_recv_frame(data->hdev, skb); |
| 796 | skb = NULL; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | data->acl_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 801 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 802 | |
| 803 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count) |
| 807 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 808 | struct sk_buff *skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 809 | unsigned long flags; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 810 | int err = 0; |
| 811 | |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 812 | spin_lock_irqsave(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 813 | skb = data->sco_skb; |
| 814 | |
| 815 | while (count) { |
| 816 | int len; |
| 817 | |
| 818 | if (!skb) { |
| 819 | skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC); |
| 820 | if (!skb) { |
| 821 | err = -ENOMEM; |
| 822 | break; |
| 823 | } |
| 824 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 825 | hci_skb_pkt_type(skb) = HCI_SCODATA_PKT; |
| 826 | hci_skb_expect(skb) = HCI_SCO_HDR_SIZE; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 827 | } |
| 828 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 829 | len = min_t(uint, hci_skb_expect(skb), count); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 830 | skb_put_data(skb, buffer, len); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 831 | |
| 832 | count -= len; |
| 833 | buffer += len; |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 834 | hci_skb_expect(skb) -= len; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 835 | |
| 836 | if (skb->len == HCI_SCO_HDR_SIZE) { |
| 837 | /* Complete SCO header */ |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 838 | hci_skb_expect(skb) = hci_sco_hdr(skb)->dlen; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 839 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 840 | if (skb_tailroom(skb) < hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 841 | kfree_skb(skb); |
| 842 | skb = NULL; |
| 843 | |
| 844 | err = -EILSEQ; |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 849 | if (!hci_skb_expect(skb)) { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 850 | /* Complete frame */ |
| 851 | hci_recv_frame(data->hdev, skb); |
| 852 | skb = NULL; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | data->sco_skb = skb; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 857 | spin_unlock_irqrestore(&data->rxlock, flags); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 858 | |
| 859 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 860 | } |
| 861 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 862 | static void btusb_intr_complete(struct urb *urb) |
| 863 | { |
| 864 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 865 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 866 | int err; |
| 867 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 868 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 869 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 870 | |
| 871 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 872 | return; |
| 873 | |
| 874 | if (urb->status == 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 875 | hdev->stat.byte_rx += urb->actual_length; |
| 876 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 877 | if (btusb_recv_intr(data, urb->transfer_buffer, |
| 878 | urb->actual_length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 879 | bt_dev_err(hdev, "corrupted event packet"); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 880 | hdev->stat.err_rx++; |
| 881 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 882 | } else if (urb->status == -ENOENT) { |
| 883 | /* Avoid suspend failed when usb_kill_urb */ |
| 884 | return; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | if (!test_bit(BTUSB_INTR_RUNNING, &data->flags)) |
| 888 | return; |
| 889 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 890 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 891 | usb_anchor_urb(urb, &data->intr_anchor); |
| 892 | |
| 893 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 894 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 895 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 896 | * -ENODEV: device got disconnected |
| 897 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 898 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 899 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 900 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 901 | usb_unanchor_urb(urb); |
| 902 | } |
| 903 | } |
| 904 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 905 | 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] | 906 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 907 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 908 | struct urb *urb; |
| 909 | unsigned char *buf; |
| 910 | unsigned int pipe; |
| 911 | int err, size; |
| 912 | |
| 913 | BT_DBG("%s", hdev->name); |
| 914 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 915 | if (!data->intr_ep) |
| 916 | return -ENODEV; |
| 917 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 918 | urb = usb_alloc_urb(0, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 919 | if (!urb) |
| 920 | return -ENOMEM; |
| 921 | |
| 922 | size = le16_to_cpu(data->intr_ep->wMaxPacketSize); |
| 923 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 924 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 925 | if (!buf) { |
| 926 | usb_free_urb(urb); |
| 927 | return -ENOMEM; |
| 928 | } |
| 929 | |
| 930 | pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress); |
| 931 | |
| 932 | usb_fill_int_urb(urb, data->udev, pipe, buf, size, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 933 | btusb_intr_complete, hdev, data->intr_ep->bInterval); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 934 | |
| 935 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 936 | |
| 937 | usb_anchor_urb(urb, &data->intr_anchor); |
| 938 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 939 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 940 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 941 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 942 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 943 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 944 | usb_unanchor_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | usb_free_urb(urb); |
| 948 | |
| 949 | return err; |
| 950 | } |
| 951 | |
| 952 | static void btusb_bulk_complete(struct urb *urb) |
| 953 | { |
| 954 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 955 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 956 | int err; |
| 957 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 958 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 959 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 960 | |
| 961 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 962 | return; |
| 963 | |
| 964 | if (urb->status == 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 965 | hdev->stat.byte_rx += urb->actual_length; |
| 966 | |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 967 | if (data->recv_bulk(data, urb->transfer_buffer, |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 968 | urb->actual_length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 969 | bt_dev_err(hdev, "corrupted ACL packet"); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 970 | hdev->stat.err_rx++; |
| 971 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 972 | } else if (urb->status == -ENOENT) { |
| 973 | /* Avoid suspend failed when usb_kill_urb */ |
| 974 | return; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | if (!test_bit(BTUSB_BULK_RUNNING, &data->flags)) |
| 978 | return; |
| 979 | |
| 980 | usb_anchor_urb(urb, &data->bulk_anchor); |
Oliver Neukum | 652fd78 | 2009-12-16 19:23:43 +0100 | [diff] [blame] | 981 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 982 | |
| 983 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 984 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 985 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 986 | * -ENODEV: device got disconnected |
| 987 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 988 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 989 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 990 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 991 | usb_unanchor_urb(urb); |
| 992 | } |
| 993 | } |
| 994 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 995 | static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 996 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 997 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 998 | struct urb *urb; |
| 999 | unsigned char *buf; |
| 1000 | unsigned int pipe; |
Vikram Kandukuri | 290ba20 | 2009-07-02 14:31:59 +0530 | [diff] [blame] | 1001 | int err, size = HCI_MAX_FRAME_SIZE; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1002 | |
| 1003 | BT_DBG("%s", hdev->name); |
| 1004 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1005 | if (!data->bulk_rx_ep) |
| 1006 | return -ENODEV; |
| 1007 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1008 | urb = usb_alloc_urb(0, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1009 | if (!urb) |
| 1010 | return -ENOMEM; |
| 1011 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1012 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1013 | if (!buf) { |
| 1014 | usb_free_urb(urb); |
| 1015 | return -ENOMEM; |
| 1016 | } |
| 1017 | |
| 1018 | pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress); |
| 1019 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1020 | usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, |
| 1021 | btusb_bulk_complete, hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1022 | |
| 1023 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 1024 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1025 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1026 | usb_anchor_urb(urb, &data->bulk_anchor); |
| 1027 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1028 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1029 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 1030 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1031 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1032 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1033 | usb_unanchor_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | usb_free_urb(urb); |
| 1037 | |
| 1038 | return err; |
| 1039 | } |
| 1040 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1041 | static void btusb_isoc_complete(struct urb *urb) |
| 1042 | { |
| 1043 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1044 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1045 | int i, err; |
| 1046 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1047 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1048 | urb->actual_length); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1049 | |
| 1050 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1051 | return; |
| 1052 | |
| 1053 | if (urb->status == 0) { |
| 1054 | for (i = 0; i < urb->number_of_packets; i++) { |
| 1055 | unsigned int offset = urb->iso_frame_desc[i].offset; |
| 1056 | unsigned int length = urb->iso_frame_desc[i].actual_length; |
| 1057 | |
| 1058 | if (urb->iso_frame_desc[i].status) |
| 1059 | continue; |
| 1060 | |
| 1061 | hdev->stat.byte_rx += length; |
| 1062 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 1063 | if (btusb_recv_isoc(data, urb->transfer_buffer + offset, |
| 1064 | length) < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1065 | bt_dev_err(hdev, "corrupted SCO packet"); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1066 | hdev->stat.err_rx++; |
| 1067 | } |
| 1068 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 1069 | } else if (urb->status == -ENOENT) { |
| 1070 | /* Avoid suspend failed when usb_kill_urb */ |
| 1071 | return; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags)) |
| 1075 | return; |
| 1076 | |
| 1077 | usb_anchor_urb(urb, &data->isoc_anchor); |
| 1078 | |
| 1079 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 1080 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 1081 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 1082 | * -ENODEV: device got disconnected |
| 1083 | */ |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 1084 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1085 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 1086 | urb, -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1087 | usb_unanchor_urb(urb); |
| 1088 | } |
| 1089 | } |
| 1090 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1091 | static inline void __fill_isoc_descriptor_msbc(struct urb *urb, int len, |
| 1092 | int mtu, struct btusb_data *data) |
| 1093 | { |
| 1094 | int i, offset = 0; |
| 1095 | unsigned int interval; |
| 1096 | |
| 1097 | BT_DBG("len %d mtu %d", len, mtu); |
| 1098 | |
| 1099 | /* For mSBC ALT 6 setting the host will send the packet at continuous |
| 1100 | * flow. As per core spec 5, vol 4, part B, table 2.1. For ALT setting |
| 1101 | * 6 the HCI PACKET INTERVAL should be 7.5ms for every usb packets. |
| 1102 | * To maintain the rate we send 63bytes of usb packets alternatively for |
| 1103 | * 7ms and 8ms to maintain the rate as 7.5ms. |
| 1104 | */ |
| 1105 | if (data->usb_alt6_packet_flow) { |
| 1106 | interval = 7; |
| 1107 | data->usb_alt6_packet_flow = false; |
| 1108 | } else { |
| 1109 | interval = 6; |
| 1110 | data->usb_alt6_packet_flow = true; |
| 1111 | } |
| 1112 | |
| 1113 | for (i = 0; i < interval; i++) { |
| 1114 | urb->iso_frame_desc[i].offset = offset; |
| 1115 | urb->iso_frame_desc[i].length = offset; |
| 1116 | } |
| 1117 | |
| 1118 | if (len && i < BTUSB_MAX_ISOC_FRAMES) { |
| 1119 | urb->iso_frame_desc[i].offset = offset; |
| 1120 | urb->iso_frame_desc[i].length = len; |
| 1121 | i++; |
| 1122 | } |
| 1123 | |
| 1124 | urb->number_of_packets = i; |
| 1125 | } |
| 1126 | |
Jesper Juhl | 42b16b3 | 2011-01-17 00:09:38 +0100 | [diff] [blame] | 1127 | 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] | 1128 | { |
| 1129 | int i, offset = 0; |
| 1130 | |
| 1131 | BT_DBG("len %d mtu %d", len, mtu); |
| 1132 | |
| 1133 | for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu; |
| 1134 | i++, offset += mtu, len -= mtu) { |
| 1135 | urb->iso_frame_desc[i].offset = offset; |
| 1136 | urb->iso_frame_desc[i].length = mtu; |
| 1137 | } |
| 1138 | |
| 1139 | if (len && i < BTUSB_MAX_ISOC_FRAMES) { |
| 1140 | urb->iso_frame_desc[i].offset = offset; |
| 1141 | urb->iso_frame_desc[i].length = len; |
| 1142 | i++; |
| 1143 | } |
| 1144 | |
| 1145 | urb->number_of_packets = i; |
| 1146 | } |
| 1147 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1148 | 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] | 1149 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1150 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1151 | struct urb *urb; |
| 1152 | unsigned char *buf; |
| 1153 | unsigned int pipe; |
| 1154 | int err, size; |
| 1155 | |
| 1156 | BT_DBG("%s", hdev->name); |
| 1157 | |
| 1158 | if (!data->isoc_rx_ep) |
| 1159 | return -ENODEV; |
| 1160 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1161 | urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1162 | if (!urb) |
| 1163 | return -ENOMEM; |
| 1164 | |
| 1165 | size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) * |
| 1166 | BTUSB_MAX_ISOC_FRAMES; |
| 1167 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1168 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1169 | if (!buf) { |
| 1170 | usb_free_urb(urb); |
| 1171 | return -ENOMEM; |
| 1172 | } |
| 1173 | |
| 1174 | pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress); |
| 1175 | |
Bing Zhao | fa0fb93 | 2011-12-20 18:19:00 -0800 | [diff] [blame] | 1176 | 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] | 1177 | hdev, data->isoc_rx_ep->bInterval); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1178 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1179 | urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1180 | |
| 1181 | __fill_isoc_descriptor(urb, size, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1182 | le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize)); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1183 | |
| 1184 | usb_anchor_urb(urb, &data->isoc_anchor); |
| 1185 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1186 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1187 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 1188 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1189 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1190 | urb, -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1191 | usb_unanchor_urb(urb); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | usb_free_urb(urb); |
| 1195 | |
| 1196 | return err; |
| 1197 | } |
| 1198 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1199 | static void btusb_diag_complete(struct urb *urb) |
| 1200 | { |
| 1201 | struct hci_dev *hdev = urb->context; |
| 1202 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1203 | int err; |
| 1204 | |
| 1205 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1206 | urb->actual_length); |
| 1207 | |
| 1208 | if (urb->status == 0) { |
| 1209 | struct sk_buff *skb; |
| 1210 | |
| 1211 | skb = bt_skb_alloc(urb->actual_length, GFP_ATOMIC); |
| 1212 | if (skb) { |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 1213 | skb_put_data(skb, urb->transfer_buffer, |
| 1214 | urb->actual_length); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1215 | hci_recv_diag(hdev, skb); |
| 1216 | } |
| 1217 | } else if (urb->status == -ENOENT) { |
| 1218 | /* Avoid suspend failed when usb_kill_urb */ |
| 1219 | return; |
| 1220 | } |
| 1221 | |
| 1222 | if (!test_bit(BTUSB_DIAG_RUNNING, &data->flags)) |
| 1223 | return; |
| 1224 | |
| 1225 | usb_anchor_urb(urb, &data->diag_anchor); |
| 1226 | usb_mark_last_busy(data->udev); |
| 1227 | |
| 1228 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 1229 | if (err < 0) { |
| 1230 | /* -EPERM: urb is being killed; |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 1231 | * -ENODEV: device got disconnected |
| 1232 | */ |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1233 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1234 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 1235 | urb, -err); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1236 | usb_unanchor_urb(urb); |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | static int btusb_submit_diag_urb(struct hci_dev *hdev, gfp_t mem_flags) |
| 1241 | { |
| 1242 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1243 | struct urb *urb; |
| 1244 | unsigned char *buf; |
| 1245 | unsigned int pipe; |
| 1246 | int err, size = HCI_MAX_FRAME_SIZE; |
| 1247 | |
| 1248 | BT_DBG("%s", hdev->name); |
| 1249 | |
| 1250 | if (!data->diag_rx_ep) |
| 1251 | return -ENODEV; |
| 1252 | |
| 1253 | urb = usb_alloc_urb(0, mem_flags); |
| 1254 | if (!urb) |
| 1255 | return -ENOMEM; |
| 1256 | |
| 1257 | buf = kmalloc(size, mem_flags); |
| 1258 | if (!buf) { |
| 1259 | usb_free_urb(urb); |
| 1260 | return -ENOMEM; |
| 1261 | } |
| 1262 | |
| 1263 | pipe = usb_rcvbulkpipe(data->udev, data->diag_rx_ep->bEndpointAddress); |
| 1264 | |
| 1265 | usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, |
| 1266 | btusb_diag_complete, hdev); |
| 1267 | |
| 1268 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 1269 | |
| 1270 | usb_mark_last_busy(data->udev); |
| 1271 | usb_anchor_urb(urb, &data->diag_anchor); |
| 1272 | |
| 1273 | err = usb_submit_urb(urb, mem_flags); |
| 1274 | if (err < 0) { |
| 1275 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1276 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1277 | urb, -err); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1278 | usb_unanchor_urb(urb); |
| 1279 | } |
| 1280 | |
| 1281 | usb_free_urb(urb); |
| 1282 | |
| 1283 | return err; |
| 1284 | } |
| 1285 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1286 | static void btusb_tx_complete(struct urb *urb) |
| 1287 | { |
| 1288 | struct sk_buff *skb = urb->context; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1289 | struct hci_dev *hdev = (struct hci_dev *)skb->dev; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1290 | struct btusb_data *data = hci_get_drvdata(hdev); |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1291 | unsigned long flags; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1292 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1293 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1294 | urb->actual_length); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1295 | |
| 1296 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1297 | goto done; |
| 1298 | |
| 1299 | if (!urb->status) |
| 1300 | hdev->stat.byte_tx += urb->transfer_buffer_length; |
| 1301 | else |
| 1302 | hdev->stat.err_tx++; |
| 1303 | |
| 1304 | done: |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1305 | spin_lock_irqsave(&data->txlock, flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1306 | data->tx_in_flight--; |
Sebastian Andrzej Siewior | a5e50d5 | 2018-06-19 23:56:57 +0200 | [diff] [blame] | 1307 | spin_unlock_irqrestore(&data->txlock, flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1308 | |
| 1309 | kfree(urb->setup_packet); |
| 1310 | |
| 1311 | kfree_skb(skb); |
| 1312 | } |
| 1313 | |
| 1314 | static void btusb_isoc_tx_complete(struct urb *urb) |
| 1315 | { |
| 1316 | struct sk_buff *skb = urb->context; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1317 | struct hci_dev *hdev = (struct hci_dev *)skb->dev; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1318 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1319 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 1320 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1321 | |
| 1322 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1323 | goto done; |
| 1324 | |
| 1325 | if (!urb->status) |
| 1326 | hdev->stat.byte_tx += urb->transfer_buffer_length; |
| 1327 | else |
| 1328 | hdev->stat.err_tx++; |
| 1329 | |
| 1330 | done: |
| 1331 | kfree(urb->setup_packet); |
| 1332 | |
| 1333 | kfree_skb(skb); |
| 1334 | } |
| 1335 | |
| 1336 | static int btusb_open(struct hci_dev *hdev) |
| 1337 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1338 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1339 | int err; |
| 1340 | |
| 1341 | BT_DBG("%s", hdev->name); |
| 1342 | |
Ethan Hsieh | c7e163f | 2016-10-07 12:06:42 +0800 | [diff] [blame] | 1343 | err = usb_autopm_get_interface(data->intf); |
| 1344 | if (err < 0) |
| 1345 | return err; |
| 1346 | |
Kim, Ben Young Tae | ace3198 | 2015-02-15 23:06:14 +0000 | [diff] [blame] | 1347 | /* Patching USB firmware files prior to starting any URBs of HCI path |
| 1348 | * It is more safe to use USB bulk channel for downloading USB patch |
| 1349 | */ |
| 1350 | if (data->setup_on_usb) { |
| 1351 | err = data->setup_on_usb(hdev); |
Marcel Holtmann | eb50042 | 2015-04-16 23:15:50 +0200 | [diff] [blame] | 1352 | if (err < 0) |
Oliver Neukum | 3d44a6f | 2019-11-14 16:01:18 +0100 | [diff] [blame] | 1353 | goto setup_fail; |
Kim, Ben Young Tae | ace3198 | 2015-02-15 23:06:14 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1356 | data->intf->needs_remote_wakeup = 1; |
| 1357 | |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 1358 | /* Disable device remote wakeup when host is suspended |
| 1359 | * For Realtek chips, global suspend without |
| 1360 | * SET_FEATURE (DEVICE_REMOTE_WAKEUP) can save more power in device. |
| 1361 | */ |
| 1362 | if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) |
| 1363 | device_wakeup_disable(&data->udev->dev); |
| 1364 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1365 | if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1366 | goto done; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1367 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1368 | err = btusb_submit_intr_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1369 | if (err < 0) |
| 1370 | goto failed; |
| 1371 | |
| 1372 | err = btusb_submit_bulk_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1373 | if (err < 0) { |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1374 | usb_kill_anchored_urbs(&data->intr_anchor); |
| 1375 | goto failed; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1376 | } |
| 1377 | |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1378 | set_bit(BTUSB_BULK_RUNNING, &data->flags); |
| 1379 | btusb_submit_bulk_urb(hdev, GFP_KERNEL); |
| 1380 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1381 | if (data->diag) { |
| 1382 | if (!btusb_submit_diag_urb(hdev, GFP_KERNEL)) |
| 1383 | set_bit(BTUSB_DIAG_RUNNING, &data->flags); |
| 1384 | } |
| 1385 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1386 | done: |
| 1387 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1388 | return 0; |
| 1389 | |
| 1390 | failed: |
| 1391 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Oliver Neukum | 3d44a6f | 2019-11-14 16:01:18 +0100 | [diff] [blame] | 1392 | setup_fail: |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1393 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1394 | return err; |
| 1395 | } |
| 1396 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1397 | static void btusb_stop_traffic(struct btusb_data *data) |
| 1398 | { |
| 1399 | usb_kill_anchored_urbs(&data->intr_anchor); |
| 1400 | usb_kill_anchored_urbs(&data->bulk_anchor); |
| 1401 | usb_kill_anchored_urbs(&data->isoc_anchor); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1402 | usb_kill_anchored_urbs(&data->diag_anchor); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 1403 | usb_kill_anchored_urbs(&data->ctrl_anchor); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1404 | } |
| 1405 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1406 | static int btusb_close(struct hci_dev *hdev) |
| 1407 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1408 | struct btusb_data *data = hci_get_drvdata(hdev); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1409 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1410 | |
| 1411 | BT_DBG("%s", hdev->name); |
| 1412 | |
Marcel Holtmann | e8c3c3d | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 1413 | cancel_work_sync(&data->work); |
Linus Torvalds | 404291a | 2009-11-11 13:32:29 -0800 | [diff] [blame] | 1414 | cancel_work_sync(&data->waker); |
Marcel Holtmann | e8c3c3d | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 1415 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1416 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1417 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1418 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 1419 | clear_bit(BTUSB_DIAG_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1420 | |
| 1421 | btusb_stop_traffic(data); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 1422 | btusb_free_frags(data); |
| 1423 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1424 | err = usb_autopm_get_interface(data->intf); |
| 1425 | if (err < 0) |
Oliver Neukum | 7b8e2c1 | 2009-11-13 14:26:23 +0100 | [diff] [blame] | 1426 | goto failed; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1427 | |
| 1428 | data->intf->needs_remote_wakeup = 0; |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 1429 | |
| 1430 | /* Enable remote wake up for auto-suspend */ |
| 1431 | if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) |
| 1432 | data->intf->needs_remote_wakeup = 1; |
| 1433 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1434 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1435 | |
Oliver Neukum | 7b8e2c1 | 2009-11-13 14:26:23 +0100 | [diff] [blame] | 1436 | failed: |
| 1437 | usb_scuttle_anchored_urbs(&data->deferred); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1438 | return 0; |
| 1439 | } |
| 1440 | |
| 1441 | static int btusb_flush(struct hci_dev *hdev) |
| 1442 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1443 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1444 | |
| 1445 | BT_DBG("%s", hdev->name); |
| 1446 | |
| 1447 | usb_kill_anchored_urbs(&data->tx_anchor); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 1448 | btusb_free_frags(data); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1453 | 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] | 1454 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1455 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1456 | struct usb_ctrlrequest *dr; |
| 1457 | struct urb *urb; |
| 1458 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1459 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1460 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1461 | if (!urb) |
| 1462 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1463 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1464 | dr = kmalloc(sizeof(*dr), GFP_KERNEL); |
| 1465 | if (!dr) { |
| 1466 | usb_free_urb(urb); |
| 1467 | return ERR_PTR(-ENOMEM); |
| 1468 | } |
| 1469 | |
| 1470 | dr->bRequestType = data->cmdreq_type; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 1471 | dr->bRequest = data->cmdreq; |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1472 | dr->wIndex = 0; |
| 1473 | dr->wValue = 0; |
| 1474 | dr->wLength = __cpu_to_le16(skb->len); |
| 1475 | |
| 1476 | pipe = usb_sndctrlpipe(data->udev, 0x00); |
| 1477 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1478 | usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1479 | skb->data, skb->len, btusb_tx_complete, skb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1480 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1481 | skb->dev = (void *)hdev; |
Marcel Holtmann | 7bd8f09 | 2013-10-11 06:19:18 -0700 | [diff] [blame] | 1482 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1483 | return urb; |
| 1484 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1485 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1486 | static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb) |
| 1487 | { |
| 1488 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1489 | struct urb *urb; |
| 1490 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1491 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1492 | if (!data->bulk_tx_ep) |
| 1493 | return ERR_PTR(-ENODEV); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1494 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1495 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1496 | if (!urb) |
| 1497 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1498 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1499 | pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1500 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1501 | usb_fill_bulk_urb(urb, data->udev, pipe, |
| 1502 | skb->data, skb->len, btusb_tx_complete, skb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1503 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1504 | skb->dev = (void *)hdev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1505 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1506 | return urb; |
| 1507 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1508 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1509 | static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb) |
| 1510 | { |
| 1511 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1512 | struct urb *urb; |
| 1513 | unsigned int pipe; |
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 | if (!data->isoc_tx_ep) |
| 1516 | return ERR_PTR(-ENODEV); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1517 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1518 | urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL); |
| 1519 | if (!urb) |
| 1520 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1521 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1522 | pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1523 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1524 | usb_fill_int_urb(urb, data->udev, pipe, |
| 1525 | skb->data, skb->len, btusb_isoc_tx_complete, |
| 1526 | skb, data->isoc_tx_ep->bInterval); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1527 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1528 | urb->transfer_flags = URB_ISO_ASAP; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1529 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1530 | if (data->isoc_altsetting == 6) |
| 1531 | __fill_isoc_descriptor_msbc(urb, skb->len, |
| 1532 | le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize), |
| 1533 | data); |
| 1534 | else |
| 1535 | __fill_isoc_descriptor(urb, skb->len, |
| 1536 | le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1537 | skb->dev = (void *)hdev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1538 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1539 | return urb; |
| 1540 | } |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1541 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1542 | static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb) |
| 1543 | { |
| 1544 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1545 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1546 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1547 | usb_anchor_urb(urb, &data->tx_anchor); |
| 1548 | |
Johan Hedberg | e9753ef | 2014-09-14 08:49:34 +0300 | [diff] [blame] | 1549 | err = usb_submit_urb(urb, GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1550 | if (err < 0) { |
Paul Bolle | 5a9b80e | 2011-10-09 12:12:16 +0200 | [diff] [blame] | 1551 | if (err != -EPERM && err != -ENODEV) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1552 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 1553 | urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1554 | kfree(urb->setup_packet); |
| 1555 | usb_unanchor_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1556 | } else { |
| 1557 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1558 | } |
| 1559 | |
Cong Wang | 54a8a79 | 2011-11-22 09:32:57 +0800 | [diff] [blame] | 1560 | usb_free_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1561 | return err; |
| 1562 | } |
| 1563 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1564 | static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb) |
| 1565 | { |
| 1566 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1567 | unsigned long flags; |
| 1568 | bool suspending; |
| 1569 | |
| 1570 | spin_lock_irqsave(&data->txlock, flags); |
| 1571 | suspending = test_bit(BTUSB_SUSPENDING, &data->flags); |
| 1572 | if (!suspending) |
| 1573 | data->tx_in_flight++; |
| 1574 | spin_unlock_irqrestore(&data->txlock, flags); |
| 1575 | |
| 1576 | if (!suspending) |
| 1577 | return submit_tx_urb(hdev, urb); |
| 1578 | |
| 1579 | usb_anchor_urb(urb, &data->deferred); |
| 1580 | schedule_work(&data->waker); |
| 1581 | |
| 1582 | usb_free_urb(urb); |
| 1583 | return 0; |
| 1584 | } |
| 1585 | |
| 1586 | static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb) |
| 1587 | { |
| 1588 | struct urb *urb; |
| 1589 | |
| 1590 | BT_DBG("%s", hdev->name); |
| 1591 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 1592 | switch (hci_skb_pkt_type(skb)) { |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1593 | case HCI_COMMAND_PKT: |
| 1594 | urb = alloc_ctrl_urb(hdev, skb); |
| 1595 | if (IS_ERR(urb)) |
| 1596 | return PTR_ERR(urb); |
| 1597 | |
| 1598 | hdev->stat.cmd_tx++; |
| 1599 | return submit_or_queue_tx_urb(hdev, urb); |
| 1600 | |
| 1601 | case HCI_ACLDATA_PKT: |
| 1602 | urb = alloc_bulk_urb(hdev, skb); |
| 1603 | if (IS_ERR(urb)) |
| 1604 | return PTR_ERR(urb); |
| 1605 | |
| 1606 | hdev->stat.acl_tx++; |
| 1607 | return submit_or_queue_tx_urb(hdev, urb); |
| 1608 | |
| 1609 | case HCI_SCODATA_PKT: |
| 1610 | if (hci_conn_num(hdev, SCO_LINK) < 1) |
| 1611 | return -ENODEV; |
| 1612 | |
| 1613 | urb = alloc_isoc_urb(hdev, skb); |
| 1614 | if (IS_ERR(urb)) |
| 1615 | return PTR_ERR(urb); |
| 1616 | |
| 1617 | hdev->stat.sco_tx++; |
| 1618 | return submit_tx_urb(hdev, urb); |
| 1619 | } |
| 1620 | |
| 1621 | return -EILSEQ; |
| 1622 | } |
| 1623 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1624 | static void btusb_notify(struct hci_dev *hdev, unsigned int evt) |
| 1625 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1626 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1627 | |
| 1628 | BT_DBG("%s evt %d", hdev->name, evt); |
| 1629 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1630 | if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) { |
| 1631 | data->sco_num = hci_conn_num(hdev, SCO_LINK); |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1632 | data->air_mode = evt; |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1633 | schedule_work(&data->work); |
Marcel Holtmann | a780efa | 2008-11-30 12:17:12 +0100 | [diff] [blame] | 1634 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1635 | } |
| 1636 | |
Jesper Juhl | 42b16b3 | 2011-01-17 00:09:38 +0100 | [diff] [blame] | 1637 | static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting) |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1638 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1639 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1640 | struct usb_interface *intf = data->isoc; |
| 1641 | struct usb_endpoint_descriptor *ep_desc; |
| 1642 | int i, err; |
| 1643 | |
| 1644 | if (!data->isoc) |
| 1645 | return -ENODEV; |
| 1646 | |
Marcel Holtmann | 459232f | 2017-10-24 19:42:45 +0200 | [diff] [blame] | 1647 | err = usb_set_interface(data->udev, data->isoc_ifnum, altsetting); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1648 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1649 | bt_dev_err(hdev, "setting interface failed (%d)", -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1650 | return err; |
| 1651 | } |
| 1652 | |
| 1653 | data->isoc_altsetting = altsetting; |
| 1654 | |
| 1655 | data->isoc_tx_ep = NULL; |
| 1656 | data->isoc_rx_ep = NULL; |
| 1657 | |
| 1658 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 1659 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 1660 | |
| 1661 | if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) { |
| 1662 | data->isoc_tx_ep = ep_desc; |
| 1663 | continue; |
| 1664 | } |
| 1665 | |
| 1666 | if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) { |
| 1667 | data->isoc_rx_ep = ep_desc; |
| 1668 | continue; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | if (!data->isoc_tx_ep || !data->isoc_rx_ep) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1673 | bt_dev_err(hdev, "invalid SCO descriptors"); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1674 | return -ENODEV; |
| 1675 | } |
| 1676 | |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1680 | static int btusb_switch_alt_setting(struct hci_dev *hdev, int new_alts) |
| 1681 | { |
| 1682 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1683 | int err; |
| 1684 | |
| 1685 | if (data->isoc_altsetting != new_alts) { |
| 1686 | unsigned long flags; |
| 1687 | |
| 1688 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1689 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1690 | |
| 1691 | /* When isochronous alternate setting needs to be |
| 1692 | * changed, because SCO connection has been added |
| 1693 | * or removed, a packet fragment may be left in the |
| 1694 | * reassembling state. This could lead to wrongly |
| 1695 | * assembled fragments. |
| 1696 | * |
| 1697 | * Clear outstanding fragment when selecting a new |
| 1698 | * alternate setting. |
| 1699 | */ |
| 1700 | spin_lock_irqsave(&data->rxlock, flags); |
| 1701 | kfree_skb(data->sco_skb); |
| 1702 | data->sco_skb = NULL; |
| 1703 | spin_unlock_irqrestore(&data->rxlock, flags); |
| 1704 | |
| 1705 | err = __set_isoc_interface(hdev, new_alts); |
| 1706 | if (err < 0) |
| 1707 | return err; |
| 1708 | } |
| 1709 | |
| 1710 | if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
| 1711 | if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0) |
| 1712 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1713 | else |
| 1714 | btusb_submit_isoc_urb(hdev, GFP_KERNEL); |
| 1715 | } |
| 1716 | |
| 1717 | return 0; |
| 1718 | } |
| 1719 | |
| 1720 | static struct usb_host_interface *btusb_find_altsetting(struct btusb_data *data, |
| 1721 | int alt) |
| 1722 | { |
| 1723 | struct usb_interface *intf = data->isoc; |
| 1724 | int i; |
| 1725 | |
| 1726 | BT_DBG("Looking for Alt no :%d", alt); |
| 1727 | |
Sathish Narasimman | fcd156ee | 2020-04-08 10:57:03 +0530 | [diff] [blame] | 1728 | if (!intf) |
| 1729 | return NULL; |
| 1730 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1731 | for (i = 0; i < intf->num_altsetting; i++) { |
| 1732 | if (intf->altsetting[i].desc.bAlternateSetting == alt) |
| 1733 | return &intf->altsetting[i]; |
| 1734 | } |
| 1735 | |
| 1736 | return NULL; |
| 1737 | } |
| 1738 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1739 | static void btusb_work(struct work_struct *work) |
| 1740 | { |
| 1741 | struct btusb_data *data = container_of(work, struct btusb_data, work); |
| 1742 | struct hci_dev *hdev = data->hdev; |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1743 | int new_alts = 0; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1744 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1745 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1746 | if (data->sco_num > 0) { |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1747 | if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) { |
Oliver Neukum | 8efdd0c | 2011-02-11 13:00:06 +0100 | [diff] [blame] | 1748 | err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1749 | if (err < 0) { |
| 1750 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1751 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1752 | return; |
| 1753 | } |
| 1754 | |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1755 | set_bit(BTUSB_DID_ISO_RESUME, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1756 | } |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1757 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1758 | if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_CVSD) { |
| 1759 | if (hdev->voice_setting & 0x0020) { |
| 1760 | static const int alts[3] = { 2, 4, 5 }; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1761 | |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1762 | new_alts = alts[data->sco_num - 1]; |
| 1763 | } else { |
| 1764 | new_alts = data->sco_num; |
| 1765 | } |
| 1766 | } else if (data->air_mode == HCI_NOTIFY_ENABLE_SCO_TRANSP) { |
Trent Piepho | 517b693 | 2020-12-09 17:20:03 -0800 | [diff] [blame] | 1767 | /* Bluetooth USB spec recommends alt 6 (63 bytes), but |
| 1768 | * many adapters do not support it. Alt 1 appears to |
| 1769 | * work for all adapters that do not have alt 6, and |
| 1770 | * which work with WBS at all. |
| 1771 | */ |
| 1772 | new_alts = btusb_find_altsetting(data, 6) ? 6 : 1; |
Hilda Wu | e848dbd | 2021-05-14 11:19:01 +0800 | [diff] [blame] | 1773 | /* Because mSBC frames do not need to be aligned to the |
| 1774 | * SCO packet boundary. If support the Alt 3, use the |
| 1775 | * Alt 3 for HCI payload >= 60 Bytes let air packet |
| 1776 | * data satisfy 60 bytes. |
| 1777 | */ |
| 1778 | if (new_alts == 1 && btusb_find_altsetting(data, 3)) |
| 1779 | new_alts = 3; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1780 | } |
Sathish Narasimman | baac627 | 2020-04-03 21:43:59 +0200 | [diff] [blame] | 1781 | |
| 1782 | if (btusb_switch_alt_setting(hdev, new_alts) < 0) |
| 1783 | bt_dev_err(hdev, "set USB alt:(%d) failed!", new_alts); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1784 | } else { |
| 1785 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1786 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1787 | |
| 1788 | __set_isoc_interface(hdev, 0); |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1789 | if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags)) |
Oliver Neukum | 8efdd0c | 2011-02-11 13:00:06 +0100 | [diff] [blame] | 1790 | usb_autopm_put_interface(data->isoc ? data->isoc : data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1794 | static void btusb_waker(struct work_struct *work) |
| 1795 | { |
| 1796 | struct btusb_data *data = container_of(work, struct btusb_data, waker); |
| 1797 | int err; |
| 1798 | |
| 1799 | err = usb_autopm_get_interface(data->intf); |
| 1800 | if (err < 0) |
| 1801 | return; |
| 1802 | |
| 1803 | usb_autopm_put_interface(data->intf); |
| 1804 | } |
| 1805 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 1806 | static int btusb_setup_bcm92035(struct hci_dev *hdev) |
| 1807 | { |
| 1808 | struct sk_buff *skb; |
| 1809 | u8 val = 0x00; |
| 1810 | |
| 1811 | BT_DBG("%s", hdev->name); |
| 1812 | |
| 1813 | skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT); |
| 1814 | if (IS_ERR(skb)) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1815 | bt_dev_err(hdev, "BCM92035 command failed (%ld)", PTR_ERR(skb)); |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 1816 | else |
| 1817 | kfree_skb(skb); |
| 1818 | |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1822 | static int btusb_setup_csr(struct hci_dev *hdev) |
| 1823 | { |
Hans de Goede | d74e0ae | 2020-12-05 16:02:00 +0100 | [diff] [blame] | 1824 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1825 | u16 bcdDevice = le16_to_cpu(data->udev->descriptor.bcdDevice); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1826 | struct hci_rp_read_local_version *rp; |
| 1827 | struct sk_buff *skb; |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 1828 | bool is_fake = false; |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 1829 | int ret; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1830 | |
| 1831 | BT_DBG("%s", hdev->name); |
| 1832 | |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1833 | skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL, |
| 1834 | HCI_INIT_TIMEOUT); |
| 1835 | if (IS_ERR(skb)) { |
| 1836 | int err = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1837 | bt_dev_err(hdev, "CSR: Local version failed (%d)", err); |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1838 | return err; |
| 1839 | } |
| 1840 | |
| 1841 | if (skb->len != sizeof(struct hci_rp_read_local_version)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1842 | bt_dev_err(hdev, "CSR: Local version length mismatch"); |
Marcel Holtmann | 7cd84d7 | 2015-06-07 10:01:02 +0200 | [diff] [blame] | 1843 | kfree_skb(skb); |
| 1844 | return -EIO; |
| 1845 | } |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1846 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1847 | rp = (struct hci_rp_read_local_version *)skb->data; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1848 | |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 1849 | /* Detect a wide host of Chinese controllers that aren't CSR. |
| 1850 | * |
| 1851 | * Known fake bcdDevices: 0x0100, 0x0134, 0x1915, 0x2520, 0x7558, 0x8891 |
| 1852 | * |
| 1853 | * The main thing they have in common is that these are really popular low-cost |
| 1854 | * options that support newer Bluetooth versions but rely on heavy VID/PID |
| 1855 | * squatting of this poor old Bluetooth 1.1 device. Even sold as such. |
| 1856 | * |
| 1857 | * We detect actual CSR devices by checking that the HCI manufacturer code |
| 1858 | * is Cambridge Silicon Radio (10) and ensuring that LMP sub-version and |
| 1859 | * HCI rev values always match. As they both store the firmware number. |
| 1860 | */ |
Johan Hedberg | 6cafcd9 | 2015-08-30 21:47:21 +0300 | [diff] [blame] | 1861 | if (le16_to_cpu(rp->manufacturer) != 10 || |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 1862 | le16_to_cpu(rp->hci_rev) != le16_to_cpu(rp->lmp_subver)) |
| 1863 | is_fake = true; |
| 1864 | |
| 1865 | /* Known legit CSR firmware build numbers and their supported BT versions: |
| 1866 | * - 1.1 (0x1) -> 0x0073, 0x020d, 0x033c, 0x034e |
| 1867 | * - 1.2 (0x2) -> 0x04d9, 0x0529 |
| 1868 | * - 2.0 (0x3) -> 0x07a6, 0x07ad, 0x0c5c |
| 1869 | * - 2.1 (0x4) -> 0x149c, 0x1735, 0x1899 (0x1899 is a BlueCore4-External) |
| 1870 | * - 4.0 (0x6) -> 0x1d86, 0x2031, 0x22bb |
| 1871 | * |
| 1872 | * e.g. Real CSR dongles with LMP subversion 0x73 are old enough that |
| 1873 | * support BT 1.1 only; so it's a dead giveaway when some |
| 1874 | * third-party BT 4.0 dongle reuses it. |
| 1875 | */ |
| 1876 | else if (le16_to_cpu(rp->lmp_subver) <= 0x034e && |
| 1877 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_1) |
| 1878 | is_fake = true; |
| 1879 | |
| 1880 | else if (le16_to_cpu(rp->lmp_subver) <= 0x0529 && |
| 1881 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_1_2) |
| 1882 | is_fake = true; |
| 1883 | |
| 1884 | else if (le16_to_cpu(rp->lmp_subver) <= 0x0c5c && |
| 1885 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_0) |
| 1886 | is_fake = true; |
| 1887 | |
| 1888 | else if (le16_to_cpu(rp->lmp_subver) <= 0x1899 && |
| 1889 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_2_1) |
| 1890 | is_fake = true; |
| 1891 | |
| 1892 | else if (le16_to_cpu(rp->lmp_subver) <= 0x22bb && |
| 1893 | le16_to_cpu(rp->hci_ver) > BLUETOOTH_VER_4_0) |
| 1894 | is_fake = true; |
| 1895 | |
Hans de Goede | d74e0ae | 2020-12-05 16:02:00 +0100 | [diff] [blame] | 1896 | /* Other clones which beat all the above checks */ |
| 1897 | else if (bcdDevice == 0x0134 && |
| 1898 | le16_to_cpu(rp->lmp_subver) == 0x0c5c && |
| 1899 | le16_to_cpu(rp->hci_ver) == BLUETOOTH_VER_2_0) |
| 1900 | is_fake = true; |
| 1901 | |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 1902 | if (is_fake) { |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1903 | 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] | 1904 | |
| 1905 | /* Generally these clones have big discrepancies between |
| 1906 | * advertised features and what's actually supported. |
| 1907 | * Probably will need to be expanded in the future; |
| 1908 | * without these the controller will lock up. |
| 1909 | */ |
| 1910 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
| 1911 | set_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks); |
| 1912 | |
Marcel Holtmann | 9641d34 | 2015-06-07 10:01:01 +0200 | [diff] [blame] | 1913 | /* Clear the reset quirk since this is not an actual |
| 1914 | * early Bluetooth 1.1 device from CSR. |
| 1915 | */ |
| 1916 | clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 1917 | clear_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 1918 | |
| 1919 | /* |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1920 | * Special workaround for these BT 4.0 chip clones, and potentially more: |
| 1921 | * |
| 1922 | * - 0x0134: a Barrot 8041a02 (HCI rev: 0x1012 sub: 0x0810) |
| 1923 | * - 0x7558: IC markings FR3191AHAL 749H15143 (HCI rev/sub-version: 0x0709) |
| 1924 | * |
| 1925 | * These controllers are really messed-up. |
| 1926 | * |
| 1927 | * 1. Their bulk RX endpoint will never report any data unless |
| 1928 | * the device was suspended at least once (yes, really). |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 1929 | * 2. They will not wakeup when autosuspended and receiving data |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1930 | * 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] | 1931 | * (IOW remote-wakeup support is broken for the bulk endpoint). |
| 1932 | * |
| 1933 | * To fix 1. enable runtime-suspend, force-suspend the |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1934 | * HCI and then wake-it up by disabling runtime-suspend. |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 1935 | * |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1936 | * 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] | 1937 | * will still be autosuspended when it is not open. |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1938 | * |
| 1939 | * -- |
| 1940 | * |
| 1941 | * Because these are widespread problems we prefer generic solutions; so |
| 1942 | * apply this initialization quirk to every controller that gets here, |
| 1943 | * 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] | 1944 | */ |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1945 | pm_runtime_allow(&data->udev->dev); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 1946 | |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1947 | ret = pm_runtime_suspend(&data->udev->dev); |
| 1948 | if (ret >= 0) |
| 1949 | msleep(200); |
| 1950 | else |
| 1951 | 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] | 1952 | |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1953 | pm_runtime_forbid(&data->udev->dev); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 1954 | |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1955 | device_set_wakeup_capable(&data->udev->dev, false); |
Hans de Goede | 0671c066 | 2020-12-05 16:02:01 +0100 | [diff] [blame] | 1956 | |
Ismael Ferreras Morezuelas | f4292e2 | 2021-07-17 01:21:43 +0200 | [diff] [blame] | 1957 | /* Re-enable autosuspend if this was requested */ |
| 1958 | if (enable_autosuspend) |
| 1959 | usb_enable_autosuspend(data->udev); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1960 | } |
| 1961 | |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1962 | kfree_skb(skb); |
| 1963 | |
Marcel Holtmann | 9641d34 | 2015-06-07 10:01:01 +0200 | [diff] [blame] | 1964 | return 0; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1965 | } |
| 1966 | |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1967 | static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1968 | struct intel_version *ver) |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1969 | { |
| 1970 | const struct firmware *fw; |
| 1971 | char fwname[64]; |
| 1972 | int ret; |
| 1973 | |
| 1974 | snprintf(fwname, sizeof(fwname), |
| 1975 | "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq", |
| 1976 | ver->hw_platform, ver->hw_variant, ver->hw_revision, |
| 1977 | ver->fw_variant, ver->fw_revision, ver->fw_build_num, |
| 1978 | ver->fw_build_ww, ver->fw_build_yy); |
| 1979 | |
| 1980 | ret = request_firmware(&fw, fwname, &hdev->dev); |
| 1981 | if (ret < 0) { |
| 1982 | if (ret == -EINVAL) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1983 | bt_dev_err(hdev, "Intel firmware file request failed (%d)", |
| 1984 | ret); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1985 | return NULL; |
| 1986 | } |
| 1987 | |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1988 | bt_dev_err(hdev, "failed to open Intel firmware file: %s (%d)", |
| 1989 | fwname, ret); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1990 | |
| 1991 | /* If the correct firmware patch file is not found, use the |
| 1992 | * default firmware patch file instead |
| 1993 | */ |
| 1994 | snprintf(fwname, sizeof(fwname), "intel/ibt-hw-%x.%x.bseq", |
| 1995 | ver->hw_platform, ver->hw_variant); |
| 1996 | if (request_firmware(&fw, fwname, &hdev->dev) < 0) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 1997 | bt_dev_err(hdev, "failed to open default fw file: %s", |
| 1998 | fwname); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1999 | return NULL; |
| 2000 | } |
| 2001 | } |
| 2002 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2003 | bt_dev_info(hdev, "Intel Bluetooth firmware file: %s", fwname); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2004 | |
| 2005 | return fw; |
| 2006 | } |
| 2007 | |
| 2008 | static int btusb_setup_intel_patching(struct hci_dev *hdev, |
| 2009 | const struct firmware *fw, |
| 2010 | const u8 **fw_ptr, int *disable_patch) |
| 2011 | { |
| 2012 | struct sk_buff *skb; |
| 2013 | struct hci_command_hdr *cmd; |
| 2014 | const u8 *cmd_param; |
| 2015 | struct hci_event_hdr *evt = NULL; |
| 2016 | const u8 *evt_param = NULL; |
| 2017 | int remain = fw->size - (*fw_ptr - fw->data); |
| 2018 | |
| 2019 | /* The first byte indicates the types of the patch command or event. |
| 2020 | * 0x01 means HCI command and 0x02 is HCI event. If the first bytes |
| 2021 | * in the current firmware buffer doesn't start with 0x01 or |
| 2022 | * the size of remain buffer is smaller than HCI command header, |
| 2023 | * the firmware file is corrupted and it should stop the patching |
| 2024 | * process. |
| 2025 | */ |
| 2026 | if (remain > HCI_COMMAND_HDR_SIZE && *fw_ptr[0] != 0x01) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2027 | bt_dev_err(hdev, "Intel fw corrupted: invalid cmd read"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2028 | return -EINVAL; |
| 2029 | } |
| 2030 | (*fw_ptr)++; |
| 2031 | remain--; |
| 2032 | |
| 2033 | cmd = (struct hci_command_hdr *)(*fw_ptr); |
| 2034 | *fw_ptr += sizeof(*cmd); |
| 2035 | remain -= sizeof(*cmd); |
| 2036 | |
| 2037 | /* Ensure that the remain firmware data is long enough than the length |
| 2038 | * of command parameter. If not, the firmware file is corrupted. |
| 2039 | */ |
| 2040 | if (remain < cmd->plen) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2041 | bt_dev_err(hdev, "Intel fw corrupted: invalid cmd len"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2042 | return -EFAULT; |
| 2043 | } |
| 2044 | |
| 2045 | /* If there is a command that loads a patch in the firmware |
| 2046 | * file, then enable the patch upon success, otherwise just |
| 2047 | * disable the manufacturer mode, for example patch activation |
| 2048 | * is not required when the default firmware patch file is used |
| 2049 | * because there are no patch data to load. |
| 2050 | */ |
| 2051 | if (*disable_patch && le16_to_cpu(cmd->opcode) == 0xfc8e) |
| 2052 | *disable_patch = 0; |
| 2053 | |
| 2054 | cmd_param = *fw_ptr; |
| 2055 | *fw_ptr += cmd->plen; |
| 2056 | remain -= cmd->plen; |
| 2057 | |
| 2058 | /* This reads the expected events when the above command is sent to the |
| 2059 | * device. Some vendor commands expects more than one events, for |
| 2060 | * example command status event followed by vendor specific event. |
| 2061 | * For this case, it only keeps the last expected event. so the command |
| 2062 | * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of |
| 2063 | * last expected event. |
| 2064 | */ |
| 2065 | while (remain > HCI_EVENT_HDR_SIZE && *fw_ptr[0] == 0x02) { |
| 2066 | (*fw_ptr)++; |
| 2067 | remain--; |
| 2068 | |
| 2069 | evt = (struct hci_event_hdr *)(*fw_ptr); |
| 2070 | *fw_ptr += sizeof(*evt); |
| 2071 | remain -= sizeof(*evt); |
| 2072 | |
| 2073 | if (remain < evt->plen) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2074 | bt_dev_err(hdev, "Intel fw corrupted: invalid evt len"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2075 | return -EFAULT; |
| 2076 | } |
| 2077 | |
| 2078 | evt_param = *fw_ptr; |
| 2079 | *fw_ptr += evt->plen; |
| 2080 | remain -= evt->plen; |
| 2081 | } |
| 2082 | |
| 2083 | /* Every HCI commands in the firmware file has its correspond event. |
| 2084 | * If event is not found or remain is smaller than zero, the firmware |
| 2085 | * file is corrupted. |
| 2086 | */ |
| 2087 | if (!evt || !evt_param || remain < 0) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2088 | bt_dev_err(hdev, "Intel fw corrupted: invalid evt read"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2089 | return -EFAULT; |
| 2090 | } |
| 2091 | |
| 2092 | skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cmd->opcode), cmd->plen, |
| 2093 | cmd_param, evt->evt, HCI_INIT_TIMEOUT); |
| 2094 | if (IS_ERR(skb)) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2095 | bt_dev_err(hdev, "sending Intel patch command (0x%4.4x) failed (%ld)", |
| 2096 | cmd->opcode, PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 2097 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | /* It ensures that the returned event matches the event data read from |
| 2101 | * the firmware file. At fist, it checks the length and then |
| 2102 | * the contents of the event. |
| 2103 | */ |
| 2104 | if (skb->len != evt->plen) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2105 | bt_dev_err(hdev, "mismatch event length (opcode 0x%4.4x)", |
| 2106 | le16_to_cpu(cmd->opcode)); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2107 | kfree_skb(skb); |
| 2108 | return -EFAULT; |
| 2109 | } |
| 2110 | |
| 2111 | if (memcmp(skb->data, evt_param, evt->plen)) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2112 | bt_dev_err(hdev, "mismatch event parameter (opcode 0x%4.4x)", |
| 2113 | le16_to_cpu(cmd->opcode)); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2114 | kfree_skb(skb); |
| 2115 | return -EFAULT; |
| 2116 | } |
| 2117 | kfree_skb(skb); |
| 2118 | |
| 2119 | return 0; |
| 2120 | } |
| 2121 | |
| 2122 | static int btusb_setup_intel(struct hci_dev *hdev) |
| 2123 | { |
| 2124 | struct sk_buff *skb; |
| 2125 | const struct firmware *fw; |
| 2126 | const u8 *fw_ptr; |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2127 | int disable_patch, err; |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2128 | struct intel_version ver; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2129 | |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2130 | BT_DBG("%s", hdev->name); |
| 2131 | |
| 2132 | /* The controller has a bug with the first HCI command sent to it |
| 2133 | * returning number of completed commands as zero. This would stall the |
| 2134 | * command processing in the Bluetooth core. |
| 2135 | * |
| 2136 | * As a workaround, send HCI Reset command first which will reset the |
| 2137 | * number of completed commands and allow normal command processing |
| 2138 | * from now on. |
| 2139 | */ |
| 2140 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 2141 | if (IS_ERR(skb)) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2142 | bt_dev_err(hdev, "sending initial HCI reset command failed (%ld)", |
| 2143 | PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 2144 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2145 | } |
| 2146 | kfree_skb(skb); |
| 2147 | |
| 2148 | /* Read Intel specific controller version first to allow selection of |
| 2149 | * which firmware file to load. |
| 2150 | * |
| 2151 | * The returned information are hardware variant and revision plus |
| 2152 | * firmware variant, revision and build number. |
| 2153 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2154 | err = btintel_read_version(hdev, &ver); |
| 2155 | if (err) |
| 2156 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2157 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2158 | bt_dev_info(hdev, "read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x", |
| 2159 | ver.hw_platform, ver.hw_variant, ver.hw_revision, |
| 2160 | ver.fw_variant, ver.fw_revision, ver.fw_build_num, |
| 2161 | ver.fw_build_ww, ver.fw_build_yy, ver.fw_patch_num); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2162 | |
| 2163 | /* fw_patch_num indicates the version of patch the device currently |
| 2164 | * have. If there is no patch data in the device, it is always 0x00. |
Minjune Kim | 5075eda | 2015-08-27 13:21:52 +0900 | [diff] [blame] | 2165 | * So, if it is other than 0x00, no need to patch the device again. |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2166 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2167 | if (ver.fw_patch_num) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2168 | bt_dev_info(hdev, "Intel device is already patched. " |
| 2169 | "patch num: %02x", ver.fw_patch_num); |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2170 | goto complete; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | /* Opens the firmware patch file based on the firmware version read |
| 2174 | * from the controller. If it fails to open the matching firmware |
| 2175 | * patch file, it tries to open the default firmware patch file. |
| 2176 | * If no patch file is found, allow the device to operate without |
| 2177 | * a patch. |
| 2178 | */ |
Loic Poulain | 6c483de | 2015-12-06 16:18:34 +0100 | [diff] [blame] | 2179 | fw = btusb_setup_intel_get_fw(hdev, &ver); |
| 2180 | if (!fw) |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2181 | goto complete; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2182 | fw_ptr = fw->data; |
| 2183 | |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2184 | /* Enable the manufacturer mode of the controller. |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2185 | * Only while this mode is enabled, the driver can download the |
| 2186 | * firmware patch data and configuration parameters. |
| 2187 | */ |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2188 | err = btintel_enter_mfg(hdev); |
| 2189 | if (err) { |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2190 | release_firmware(fw); |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2191 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2194 | disable_patch = 1; |
| 2195 | |
| 2196 | /* The firmware data file consists of list of Intel specific HCI |
| 2197 | * commands and its expected events. The first byte indicates the |
| 2198 | * type of the message, either HCI command or HCI event. |
| 2199 | * |
| 2200 | * It reads the command and its expected event from the firmware file, |
| 2201 | * and send to the controller. Once __hci_cmd_sync_ev() returns, |
| 2202 | * the returned event is compared with the event read from the firmware |
| 2203 | * file and it will continue until all the messages are downloaded to |
| 2204 | * the controller. |
| 2205 | * |
| 2206 | * Once the firmware patching is completed successfully, |
| 2207 | * the manufacturer mode is disabled with reset and activating the |
| 2208 | * downloaded patch. |
| 2209 | * |
| 2210 | * If the firmware patching fails, the manufacturer mode is |
| 2211 | * disabled with reset and deactivating the patch. |
| 2212 | * |
| 2213 | * If the default patch file is used, no reset is done when disabling |
| 2214 | * the manufacturer. |
| 2215 | */ |
| 2216 | while (fw->size > fw_ptr - fw->data) { |
| 2217 | int ret; |
| 2218 | |
| 2219 | ret = btusb_setup_intel_patching(hdev, fw, &fw_ptr, |
| 2220 | &disable_patch); |
| 2221 | if (ret < 0) |
| 2222 | goto exit_mfg_deactivate; |
| 2223 | } |
| 2224 | |
| 2225 | release_firmware(fw); |
| 2226 | |
| 2227 | if (disable_patch) |
| 2228 | goto exit_mfg_disable; |
| 2229 | |
| 2230 | /* Patching completed successfully and disable the manufacturer mode |
| 2231 | * with reset and activate the downloaded firmware patches. |
| 2232 | */ |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2233 | err = btintel_exit_mfg(hdev, true, true); |
| 2234 | if (err) |
| 2235 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2236 | |
Sukumar Ghorai | 905d7b1 | 2020-03-16 11:37:18 +0530 | [diff] [blame] | 2237 | /* Need build number for downloaded fw patches in |
| 2238 | * every power-on boot |
| 2239 | */ |
| 2240 | err = btintel_read_version(hdev, &ver); |
| 2241 | if (err) |
| 2242 | return err; |
| 2243 | bt_dev_info(hdev, "Intel BT fw patch 0x%02x completed & activated", |
| 2244 | ver.fw_patch_num); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2245 | |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2246 | goto complete; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2247 | |
| 2248 | exit_mfg_disable: |
| 2249 | /* Disable the manufacturer mode without reset */ |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2250 | err = btintel_exit_mfg(hdev, false, false); |
| 2251 | if (err) |
| 2252 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2253 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2254 | bt_dev_info(hdev, "Intel firmware patch completed"); |
Marcel Holtmann | 40cb098 | 2014-07-02 12:06:45 +0200 | [diff] [blame] | 2255 | |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2256 | goto complete; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2257 | |
| 2258 | exit_mfg_deactivate: |
| 2259 | release_firmware(fw); |
| 2260 | |
| 2261 | /* Patching failed. Disable the manufacturer mode with reset and |
| 2262 | * deactivate the downloaded firmware patches. |
| 2263 | */ |
Loic Poulain | 28dc4b9 | 2015-12-03 16:10:22 +0100 | [diff] [blame] | 2264 | err = btintel_exit_mfg(hdev, true, false); |
| 2265 | if (err) |
| 2266 | return err; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2267 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2268 | bt_dev_info(hdev, "Intel firmware patch completed and deactivated"); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2269 | |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2270 | complete: |
| 2271 | /* Set the event mask for Intel specific vendor events. This enables |
| 2272 | * a few extra events that are useful during general operation. |
| 2273 | */ |
| 2274 | btintel_set_event_mask_mfg(hdev, false); |
| 2275 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 2276 | btintel_check_bdaddr(hdev); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2277 | return 0; |
| 2278 | } |
| 2279 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2280 | static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode) |
| 2281 | { |
| 2282 | struct sk_buff *skb; |
| 2283 | struct hci_event_hdr *hdr; |
| 2284 | struct hci_ev_cmd_complete *evt; |
| 2285 | |
Jia-Ju Bai | cf07e34 | 2018-07-23 11:38:51 +0800 | [diff] [blame] | 2286 | skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_KERNEL); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2287 | if (!skb) |
| 2288 | return -ENOMEM; |
| 2289 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 2290 | hdr = skb_put(skb, sizeof(*hdr)); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2291 | hdr->evt = HCI_EV_CMD_COMPLETE; |
| 2292 | hdr->plen = sizeof(*evt) + 1; |
| 2293 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 2294 | evt = skb_put(skb, sizeof(*evt)); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2295 | evt->ncmd = 0x01; |
| 2296 | evt->opcode = cpu_to_le16(opcode); |
| 2297 | |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 2298 | skb_put_u8(skb, 0x00); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2299 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 2300 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2301 | |
| 2302 | return hci_recv_frame(hdev, skb); |
| 2303 | } |
| 2304 | |
| 2305 | static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer, |
| 2306 | int count) |
| 2307 | { |
| 2308 | /* When the device is in bootloader mode, then it can send |
| 2309 | * events via the bulk endpoint. These events are treated the |
| 2310 | * same way as the ones received from the interrupt endpoint. |
| 2311 | */ |
| 2312 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) |
| 2313 | return btusb_recv_intr(data, buffer, count); |
| 2314 | |
| 2315 | return btusb_recv_bulk(data, buffer, count); |
| 2316 | } |
| 2317 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2318 | static void btusb_intel_bootup(struct btusb_data *data, const void *ptr, |
| 2319 | unsigned int len) |
| 2320 | { |
| 2321 | const struct intel_bootup *evt = ptr; |
| 2322 | |
| 2323 | if (len != sizeof(*evt)) |
| 2324 | return; |
| 2325 | |
Andrea Parri | dff6d59 | 2018-11-27 12:22:25 +0100 | [diff] [blame] | 2326 | if (test_and_clear_bit(BTUSB_BOOTING, &data->flags)) |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2327 | wake_up_bit(&data->flags, BTUSB_BOOTING); |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | static void btusb_intel_secure_send_result(struct btusb_data *data, |
| 2331 | const void *ptr, unsigned int len) |
| 2332 | { |
| 2333 | const struct intel_secure_send_result *evt = ptr; |
| 2334 | |
| 2335 | if (len != sizeof(*evt)) |
| 2336 | return; |
| 2337 | |
| 2338 | if (evt->result) |
| 2339 | set_bit(BTUSB_FIRMWARE_FAILED, &data->flags); |
| 2340 | |
| 2341 | if (test_and_clear_bit(BTUSB_DOWNLOADING, &data->flags) && |
Andrea Parri | dff6d59 | 2018-11-27 12:22:25 +0100 | [diff] [blame] | 2342 | test_bit(BTUSB_FIRMWARE_LOADED, &data->flags)) |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2343 | wake_up_bit(&data->flags, BTUSB_DOWNLOADING); |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2346 | static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb) |
| 2347 | { |
| 2348 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2349 | |
| 2350 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 2351 | struct hci_event_hdr *hdr = (void *)skb->data; |
| 2352 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2353 | if (skb->len > HCI_EVENT_HDR_SIZE && hdr->evt == 0xff && |
| 2354 | hdr->plen > 0) { |
| 2355 | const void *ptr = skb->data + HCI_EVENT_HDR_SIZE + 1; |
| 2356 | unsigned int len = skb->len - HCI_EVENT_HDR_SIZE - 1; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2357 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame] | 2358 | switch (skb->data[2]) { |
| 2359 | case 0x02: |
| 2360 | /* When switching to the operational firmware |
| 2361 | * the device sends a vendor specific event |
| 2362 | * indicating that the bootup completed. |
| 2363 | */ |
| 2364 | btusb_intel_bootup(data, ptr, len); |
| 2365 | break; |
| 2366 | case 0x06: |
| 2367 | /* When the firmware loading completes the |
| 2368 | * device sends out a vendor specific event |
| 2369 | * indicating the result of the firmware |
| 2370 | * loading. |
| 2371 | */ |
| 2372 | btusb_intel_secure_send_result(data, ptr, len); |
| 2373 | break; |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2374 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | return hci_recv_frame(hdev, skb); |
| 2379 | } |
| 2380 | |
| 2381 | static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) |
| 2382 | { |
| 2383 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2384 | struct urb *urb; |
| 2385 | |
| 2386 | BT_DBG("%s", hdev->name); |
| 2387 | |
Marcel Holtmann | 618e8bc | 2015-11-05 07:33:56 +0100 | [diff] [blame] | 2388 | switch (hci_skb_pkt_type(skb)) { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2389 | case HCI_COMMAND_PKT: |
| 2390 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 2391 | struct hci_command_hdr *cmd = (void *)skb->data; |
| 2392 | __u16 opcode = le16_to_cpu(cmd->opcode); |
| 2393 | |
| 2394 | /* When in bootloader mode and the command 0xfc09 |
| 2395 | * is received, it needs to be send down the |
| 2396 | * bulk endpoint. So allocate a bulk URB instead. |
| 2397 | */ |
| 2398 | if (opcode == 0xfc09) |
| 2399 | urb = alloc_bulk_urb(hdev, skb); |
| 2400 | else |
| 2401 | urb = alloc_ctrl_urb(hdev, skb); |
| 2402 | |
| 2403 | /* When the 0xfc01 command is issued to boot into |
| 2404 | * the operational firmware, it will actually not |
| 2405 | * send a command complete event. To keep the flow |
| 2406 | * control working inject that event here. |
| 2407 | */ |
| 2408 | if (opcode == 0xfc01) |
| 2409 | inject_cmd_complete(hdev, opcode); |
| 2410 | } else { |
| 2411 | urb = alloc_ctrl_urb(hdev, skb); |
| 2412 | } |
| 2413 | if (IS_ERR(urb)) |
| 2414 | return PTR_ERR(urb); |
| 2415 | |
| 2416 | hdev->stat.cmd_tx++; |
| 2417 | return submit_or_queue_tx_urb(hdev, urb); |
| 2418 | |
| 2419 | case HCI_ACLDATA_PKT: |
| 2420 | urb = alloc_bulk_urb(hdev, skb); |
| 2421 | if (IS_ERR(urb)) |
| 2422 | return PTR_ERR(urb); |
| 2423 | |
| 2424 | hdev->stat.acl_tx++; |
| 2425 | return submit_or_queue_tx_urb(hdev, urb); |
| 2426 | |
| 2427 | case HCI_SCODATA_PKT: |
| 2428 | if (hci_conn_num(hdev, SCO_LINK) < 1) |
| 2429 | return -ENODEV; |
| 2430 | |
| 2431 | urb = alloc_isoc_urb(hdev, skb); |
| 2432 | if (IS_ERR(urb)) |
| 2433 | return PTR_ERR(urb); |
| 2434 | |
| 2435 | hdev->stat.sco_tx++; |
| 2436 | return submit_tx_urb(hdev, urb); |
| 2437 | } |
| 2438 | |
| 2439 | return -EILSEQ; |
| 2440 | } |
| 2441 | |
Luiz Augusto von Dentz | 9b16bfb | 2021-03-23 11:58:57 -0700 | [diff] [blame] | 2442 | static int btusb_setup_intel_new_get_fw_name(struct intel_version *ver, |
Raghuram Hegde | 2da711bc | 2018-12-19 11:42:18 +0530 | [diff] [blame] | 2443 | struct intel_boot_params *params, |
| 2444 | char *fw_name, size_t len, |
| 2445 | const char *suffix) |
| 2446 | { |
| 2447 | switch (ver->hw_variant) { |
| 2448 | case 0x0b: /* SfP */ |
| 2449 | case 0x0c: /* WsP */ |
| 2450 | snprintf(fw_name, len, "intel/ibt-%u-%u.%s", |
| 2451 | le16_to_cpu(ver->hw_variant), |
| 2452 | le16_to_cpu(params->dev_revid), |
| 2453 | suffix); |
| 2454 | break; |
| 2455 | case 0x11: /* JfP */ |
| 2456 | case 0x12: /* ThP */ |
| 2457 | case 0x13: /* HrP */ |
| 2458 | case 0x14: /* CcP */ |
| 2459 | snprintf(fw_name, len, "intel/ibt-%u-%u-%u.%s", |
| 2460 | le16_to_cpu(ver->hw_variant), |
| 2461 | le16_to_cpu(ver->hw_revision), |
| 2462 | le16_to_cpu(ver->fw_revision), |
| 2463 | suffix); |
| 2464 | break; |
| 2465 | default: |
Luiz Augusto von Dentz | 9b16bfb | 2021-03-23 11:58:57 -0700 | [diff] [blame] | 2466 | return -EINVAL; |
Raghuram Hegde | 2da711bc | 2018-12-19 11:42:18 +0530 | [diff] [blame] | 2467 | } |
Luiz Augusto von Dentz | 9b16bfb | 2021-03-23 11:58:57 -0700 | [diff] [blame] | 2468 | |
| 2469 | return 0; |
Raghuram Hegde | 2da711bc | 2018-12-19 11:42:18 +0530 | [diff] [blame] | 2470 | } |
| 2471 | |
Kiran K | 9a93b8b | 2020-11-19 17:09:41 +0530 | [diff] [blame] | 2472 | static void btusb_setup_intel_newgen_get_fw_name(const struct intel_version_tlv *ver_tlv, |
| 2473 | char *fw_name, size_t len, |
| 2474 | const char *suffix) |
| 2475 | { |
| 2476 | /* The firmware file name for new generation controllers will be |
| 2477 | * ibt-<cnvi_top type+cnvi_top step>-<cnvr_top type+cnvr_top step> |
| 2478 | */ |
| 2479 | snprintf(fw_name, len, "intel/ibt-%04x-%04x.%s", |
| 2480 | INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver_tlv->cnvi_top), |
| 2481 | INTEL_CNVX_TOP_STEP(ver_tlv->cnvi_top)), |
| 2482 | INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver_tlv->cnvr_top), |
| 2483 | INTEL_CNVX_TOP_STEP(ver_tlv->cnvr_top)), |
| 2484 | suffix); |
| 2485 | } |
| 2486 | |
Luiz Augusto von Dentz | 21e31c6 | 2021-03-23 11:59:00 -0700 | [diff] [blame] | 2487 | static int btusb_download_wait(struct hci_dev *hdev, ktime_t calltime, int msec) |
| 2488 | { |
| 2489 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2490 | ktime_t delta, rettime; |
| 2491 | unsigned long long duration; |
| 2492 | int err; |
| 2493 | |
| 2494 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
| 2495 | |
| 2496 | bt_dev_info(hdev, "Waiting for firmware download to complete"); |
| 2497 | |
| 2498 | err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING, |
| 2499 | TASK_INTERRUPTIBLE, |
| 2500 | msecs_to_jiffies(msec)); |
| 2501 | if (err == -EINTR) { |
| 2502 | bt_dev_err(hdev, "Firmware loading interrupted"); |
| 2503 | return err; |
| 2504 | } |
| 2505 | |
| 2506 | if (err) { |
| 2507 | bt_dev_err(hdev, "Firmware loading timeout"); |
| 2508 | return -ETIMEDOUT; |
| 2509 | } |
| 2510 | |
| 2511 | if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) { |
| 2512 | bt_dev_err(hdev, "Firmware loading failed"); |
| 2513 | return -ENOEXEC; |
| 2514 | } |
| 2515 | |
| 2516 | rettime = ktime_get(); |
| 2517 | delta = ktime_sub(rettime, calltime); |
| 2518 | duration = (unsigned long long)ktime_to_ns(delta) >> 10; |
| 2519 | |
| 2520 | bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration); |
| 2521 | |
| 2522 | return 0; |
| 2523 | } |
| 2524 | |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2525 | static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev, |
| 2526 | struct intel_version_tlv *ver, |
| 2527 | u32 *boot_param) |
| 2528 | { |
| 2529 | const struct firmware *fw; |
| 2530 | char fwname[64]; |
| 2531 | int err; |
| 2532 | struct btusb_data *data = hci_get_drvdata(hdev); |
Luiz Augusto von Dentz | 21e31c6 | 2021-03-23 11:59:00 -0700 | [diff] [blame] | 2533 | ktime_t calltime; |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2534 | |
| 2535 | if (!ver || !boot_param) |
| 2536 | return -EINVAL; |
| 2537 | |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2538 | /* The firmware variant determines if the device is in bootloader |
| 2539 | * mode or is running operational firmware. The value 0x03 identifies |
| 2540 | * the bootloader and the value 0x23 identifies the operational |
| 2541 | * firmware. |
| 2542 | * |
| 2543 | * When the operational firmware is already present, then only |
| 2544 | * the check for valid Bluetooth device address is needed. This |
| 2545 | * determines if the device will be added as configured or |
| 2546 | * unconfigured controller. |
| 2547 | * |
| 2548 | * It is not possible to use the Secure Boot Parameters in this |
| 2549 | * case since that command is only available in bootloader mode. |
| 2550 | */ |
| 2551 | if (ver->img_type == 0x03) { |
| 2552 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
| 2553 | btintel_check_bdaddr(hdev); |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2554 | } |
| 2555 | |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2556 | /* If the OTP has no valid Bluetooth device address, then there will |
| 2557 | * also be no valid address for the operational firmware. |
| 2558 | */ |
| 2559 | if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) { |
| 2560 | bt_dev_info(hdev, "No device address configured"); |
| 2561 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); |
| 2562 | } |
| 2563 | |
| 2564 | btusb_setup_intel_newgen_get_fw_name(ver, fwname, sizeof(fwname), "sfi"); |
Luiz Augusto von Dentz | 1f14a62 | 2021-04-30 16:05:01 -0700 | [diff] [blame] | 2565 | err = firmware_request_nowarn(&fw, fwname, &hdev->dev); |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2566 | if (err < 0) { |
Luiz Augusto von Dentz | 1f14a62 | 2021-04-30 16:05:01 -0700 | [diff] [blame] | 2567 | if (!test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 2568 | /* Firmware has already been loaded */ |
| 2569 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
| 2570 | return 0; |
| 2571 | } |
| 2572 | |
Kiran K | 62acbbb | 2021-03-08 16:44:54 +0530 | [diff] [blame] | 2573 | bt_dev_err(hdev, "Failed to load Intel firmware file %s (%d)", |
| 2574 | fwname, err); |
Luiz Augusto von Dentz | 1f14a62 | 2021-04-30 16:05:01 -0700 | [diff] [blame] | 2575 | |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2576 | return err; |
| 2577 | } |
| 2578 | |
| 2579 | bt_dev_info(hdev, "Found device firmware: %s", fwname); |
| 2580 | |
| 2581 | if (fw->size < 644) { |
| 2582 | bt_dev_err(hdev, "Invalid size of firmware file (%zu)", |
| 2583 | fw->size); |
| 2584 | err = -EBADF; |
| 2585 | goto done; |
| 2586 | } |
| 2587 | |
Luiz Augusto von Dentz | 21e31c6 | 2021-03-23 11:59:00 -0700 | [diff] [blame] | 2588 | calltime = ktime_get(); |
| 2589 | |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2590 | set_bit(BTUSB_DOWNLOADING, &data->flags); |
| 2591 | |
| 2592 | /* Start firmware downloading and get boot parameter */ |
Luiz Augusto von Dentz | ac05654 | 2021-03-23 11:58:56 -0700 | [diff] [blame] | 2593 | err = btintel_download_firmware_newgen(hdev, ver, fw, boot_param, |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2594 | INTEL_HW_VARIANT(ver->cnvi_bt), |
| 2595 | ver->sbe_type); |
| 2596 | if (err < 0) { |
Luiz Augusto von Dentz | ac05654 | 2021-03-23 11:58:56 -0700 | [diff] [blame] | 2597 | if (err == -EALREADY) { |
| 2598 | /* Firmware has already been loaded */ |
| 2599 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
| 2600 | err = 0; |
| 2601 | goto done; |
| 2602 | } |
| 2603 | |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2604 | /* When FW download fails, send Intel Reset to retry |
| 2605 | * FW download. |
| 2606 | */ |
| 2607 | btintel_reset_to_bootloader(hdev); |
| 2608 | goto done; |
| 2609 | } |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2610 | |
| 2611 | /* Before switching the device into operational mode and with that |
| 2612 | * booting the loaded firmware, wait for the bootloader notification |
| 2613 | * that all fragments have been successfully received. |
| 2614 | * |
| 2615 | * When the event processing receives the notification, then the |
| 2616 | * BTUSB_DOWNLOADING flag will be cleared. |
| 2617 | * |
| 2618 | * The firmware loading should not take longer than 5 seconds |
| 2619 | * and thus just timeout if that happens and fail the setup |
| 2620 | * of this device. |
| 2621 | */ |
Luiz Augusto von Dentz | 21e31c6 | 2021-03-23 11:59:00 -0700 | [diff] [blame] | 2622 | err = btusb_download_wait(hdev, calltime, 5000); |
| 2623 | if (err == -ETIMEDOUT) |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2624 | btintel_reset_to_bootloader(hdev); |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2625 | |
| 2626 | done: |
| 2627 | release_firmware(fw); |
| 2628 | return err; |
| 2629 | } |
| 2630 | |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2631 | static int btusb_intel_download_firmware(struct hci_dev *hdev, |
| 2632 | struct intel_version *ver, |
Kiran K | dc45d37 | 2020-08-26 15:24:32 +0530 | [diff] [blame] | 2633 | struct intel_boot_params *params, |
| 2634 | u32 *boot_param) |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2635 | { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2636 | const struct firmware *fw; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2637 | char fwname[64]; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2638 | int err; |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2639 | struct btusb_data *data = hci_get_drvdata(hdev); |
Luiz Augusto von Dentz | 21e31c6 | 2021-03-23 11:59:00 -0700 | [diff] [blame] | 2640 | ktime_t calltime; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2641 | |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2642 | if (!ver || !params) |
| 2643 | return -EINVAL; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2644 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2645 | /* The firmware variant determines if the device is in bootloader |
| 2646 | * mode or is running operational firmware. The value 0x06 identifies |
| 2647 | * the bootloader and the value 0x23 identifies the operational |
| 2648 | * firmware. |
| 2649 | * |
| 2650 | * When the operational firmware is already present, then only |
| 2651 | * the check for valid Bluetooth device address is needed. This |
| 2652 | * determines if the device will be added as configured or |
| 2653 | * unconfigured controller. |
| 2654 | * |
| 2655 | * It is not possible to use the Secure Boot Parameters in this |
| 2656 | * case since that command is only available in bootloader mode. |
| 2657 | */ |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2658 | if (ver->fw_variant == 0x23) { |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2659 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 2660 | btintel_check_bdaddr(hdev); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2661 | |
Luiz Augusto von Dentz | 9b16bfb | 2021-03-23 11:58:57 -0700 | [diff] [blame] | 2662 | /* SfP and WsP don't seem to update the firmware version on file |
| 2663 | * so version checking is currently possible. |
| 2664 | */ |
| 2665 | switch (ver->hw_variant) { |
| 2666 | case 0x0b: /* SfP */ |
| 2667 | case 0x0c: /* WsP */ |
| 2668 | return 0; |
| 2669 | } |
| 2670 | |
| 2671 | /* Proceed to download to check if the version matches */ |
| 2672 | goto download; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2673 | } |
| 2674 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2675 | /* Read the secure boot parameters to identify the operating |
| 2676 | * details of the bootloader. |
| 2677 | */ |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2678 | err = btintel_read_boot_params(hdev, params); |
Tedd Ho-Jeong An | faf174d | 2018-01-24 09:19:20 -0800 | [diff] [blame] | 2679 | if (err) |
| 2680 | return err; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2681 | |
| 2682 | /* It is required that every single firmware fragment is acknowledged |
| 2683 | * with a command complete event. If the boot parameters indicate |
| 2684 | * that this bootloader does not send them, then abort the setup. |
| 2685 | */ |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2686 | if (params->limited_cce != 0x00) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2687 | bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)", |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2688 | params->limited_cce); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2689 | return -EINVAL; |
| 2690 | } |
| 2691 | |
| 2692 | /* If the OTP has no valid Bluetooth device address, then there will |
| 2693 | * also be no valid address for the operational firmware. |
| 2694 | */ |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2695 | if (!bacmp(¶ms->otp_bdaddr, BDADDR_ANY)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2696 | bt_dev_info(hdev, "No device address configured"); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2697 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); |
| 2698 | } |
| 2699 | |
Luiz Augusto von Dentz | 9b16bfb | 2021-03-23 11:58:57 -0700 | [diff] [blame] | 2700 | download: |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2701 | /* With this Intel bootloader only the hardware variant and device |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2702 | * revision information are used to select the right firmware for SfP |
| 2703 | * and WsP. |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2704 | * |
Tedd Ho-Jeong An | 230b04a | 2016-06-28 08:56:39 -0700 | [diff] [blame] | 2705 | * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi. |
| 2706 | * |
| 2707 | * Currently the supported hardware variants are: |
| 2708 | * 11 (0x0b) for iBT3.0 (LnP/SfP) |
| 2709 | * 12 (0x0c) for iBT3.5 (WsP) |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2710 | * |
| 2711 | * For ThP/JfP and for future SKU's, the FW name varies based on HW |
| 2712 | * variant, HW revision and FW revision, as these are dependent on CNVi |
| 2713 | * and RF Combination. |
| 2714 | * |
Tedd Ho-Jeong An | 86a6129 | 2017-05-01 13:35:12 -0700 | [diff] [blame] | 2715 | * 17 (0x11) for iBT3.5 (JfP) |
| 2716 | * 18 (0x12) for iBT3.5 (ThP) |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2717 | * |
| 2718 | * The firmware file name for these will be |
| 2719 | * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi. |
| 2720 | * |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2721 | */ |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2722 | err = btusb_setup_intel_new_get_fw_name(ver, params, fwname, |
Raghuram Hegde | 2da711bc | 2018-12-19 11:42:18 +0530 | [diff] [blame] | 2723 | sizeof(fwname), "sfi"); |
Luiz Augusto von Dentz | 9b16bfb | 2021-03-23 11:58:57 -0700 | [diff] [blame] | 2724 | if (err < 0) { |
Luiz Augusto von Dentz | 1f14a62 | 2021-04-30 16:05:01 -0700 | [diff] [blame] | 2725 | if (!test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 2726 | /* Firmware has already been loaded */ |
| 2727 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
| 2728 | return 0; |
| 2729 | } |
| 2730 | |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2731 | bt_dev_err(hdev, "Unsupported Intel firmware naming"); |
Jaya P G | af3715e | 2017-10-30 11:01:22 +0100 | [diff] [blame] | 2732 | return -EINVAL; |
| 2733 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2734 | |
Luiz Augusto von Dentz | 1f14a62 | 2021-04-30 16:05:01 -0700 | [diff] [blame] | 2735 | err = firmware_request_nowarn(&fw, fwname, &hdev->dev); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2736 | if (err < 0) { |
Luiz Augusto von Dentz | 1f14a62 | 2021-04-30 16:05:01 -0700 | [diff] [blame] | 2737 | if (!test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 2738 | /* Firmware has already been loaded */ |
| 2739 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
| 2740 | return 0; |
| 2741 | } |
| 2742 | |
Kiran K | 62acbbb | 2021-03-08 16:44:54 +0530 | [diff] [blame] | 2743 | bt_dev_err(hdev, "Failed to load Intel firmware file %s (%d)", |
| 2744 | fwname, err); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2745 | return err; |
| 2746 | } |
| 2747 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2748 | bt_dev_info(hdev, "Found device firmware: %s", fwname); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2749 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2750 | if (fw->size < 644) { |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 2751 | bt_dev_err(hdev, "Invalid size of firmware file (%zu)", |
| 2752 | fw->size); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2753 | err = -EBADF; |
| 2754 | goto done; |
| 2755 | } |
| 2756 | |
Luiz Augusto von Dentz | 21e31c6 | 2021-03-23 11:59:00 -0700 | [diff] [blame] | 2757 | calltime = ktime_get(); |
| 2758 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2759 | set_bit(BTUSB_DOWNLOADING, &data->flags); |
| 2760 | |
Tedd Ho-Jeong An | fbbe83c | 2018-01-24 09:19:21 -0800 | [diff] [blame] | 2761 | /* Start firmware downloading and get boot parameter */ |
Luiz Augusto von Dentz | ac05654 | 2021-03-23 11:58:56 -0700 | [diff] [blame] | 2762 | err = btintel_download_firmware(hdev, ver, fw, boot_param); |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2763 | if (err < 0) { |
Luiz Augusto von Dentz | ac05654 | 2021-03-23 11:58:56 -0700 | [diff] [blame] | 2764 | if (err == -EALREADY) { |
| 2765 | /* Firmware has already been loaded */ |
| 2766 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
| 2767 | err = 0; |
| 2768 | goto done; |
| 2769 | } |
| 2770 | |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2771 | /* When FW download fails, send Intel Reset to retry |
| 2772 | * FW download. |
| 2773 | */ |
| 2774 | btintel_reset_to_bootloader(hdev); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2775 | goto done; |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2776 | } |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2777 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2778 | /* Before switching the device into operational mode and with that |
| 2779 | * booting the loaded firmware, wait for the bootloader notification |
| 2780 | * that all fragments have been successfully received. |
| 2781 | * |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2782 | * When the event processing receives the notification, then the |
| 2783 | * BTUSB_DOWNLOADING flag will be cleared. |
| 2784 | * |
| 2785 | * The firmware loading should not take longer than 5 seconds |
| 2786 | * and thus just timeout if that happens and fail the setup |
| 2787 | * of this device. |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2788 | */ |
Luiz Augusto von Dentz | 21e31c6 | 2021-03-23 11:59:00 -0700 | [diff] [blame] | 2789 | err = btusb_download_wait(hdev, calltime, 5000); |
| 2790 | if (err == -ETIMEDOUT) |
Amit K Bag | b9a2562 | 2019-10-17 13:52:29 +0530 | [diff] [blame] | 2791 | btintel_reset_to_bootloader(hdev); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2792 | |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2793 | done: |
| 2794 | release_firmware(fw); |
| 2795 | return err; |
| 2796 | } |
| 2797 | |
Luiz Augusto von Dentz | 604b3cf | 2021-03-23 11:59:01 -0700 | [diff] [blame] | 2798 | static int btusb_boot_wait(struct hci_dev *hdev, ktime_t calltime, int msec) |
| 2799 | { |
| 2800 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2801 | ktime_t delta, rettime; |
| 2802 | unsigned long long duration; |
| 2803 | int err; |
| 2804 | |
| 2805 | bt_dev_info(hdev, "Waiting for device to boot"); |
| 2806 | |
| 2807 | err = wait_on_bit_timeout(&data->flags, BTUSB_BOOTING, |
| 2808 | TASK_INTERRUPTIBLE, |
| 2809 | msecs_to_jiffies(msec)); |
| 2810 | if (err == -EINTR) { |
| 2811 | bt_dev_err(hdev, "Device boot interrupted"); |
| 2812 | return -EINTR; |
| 2813 | } |
| 2814 | |
| 2815 | if (err) { |
| 2816 | bt_dev_err(hdev, "Device boot timeout"); |
| 2817 | return -ETIMEDOUT; |
| 2818 | } |
| 2819 | |
| 2820 | rettime = ktime_get(); |
| 2821 | delta = ktime_sub(rettime, calltime); |
| 2822 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; |
| 2823 | |
| 2824 | bt_dev_info(hdev, "Device booted in %llu usecs", duration); |
| 2825 | |
| 2826 | return 0; |
| 2827 | } |
| 2828 | |
| 2829 | static int btusb_intel_boot(struct hci_dev *hdev, u32 boot_addr) |
| 2830 | { |
| 2831 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2832 | ktime_t calltime; |
| 2833 | int err; |
| 2834 | |
| 2835 | calltime = ktime_get(); |
| 2836 | |
| 2837 | set_bit(BTUSB_BOOTING, &data->flags); |
| 2838 | |
| 2839 | err = btintel_send_intel_reset(hdev, boot_addr); |
| 2840 | if (err) { |
| 2841 | bt_dev_err(hdev, "Intel Soft Reset failed (%d)", err); |
| 2842 | btintel_reset_to_bootloader(hdev); |
| 2843 | return err; |
| 2844 | } |
| 2845 | |
| 2846 | /* The bootloader will not indicate when the device is ready. This |
| 2847 | * is done by the operational firmware sending bootup notification. |
| 2848 | * |
| 2849 | * Booting into operational firmware should not take longer than |
| 2850 | * 1 second. However if that happens, then just fail the setup |
| 2851 | * since something went wrong. |
| 2852 | */ |
| 2853 | err = btusb_boot_wait(hdev, calltime, 1000); |
| 2854 | if (err == -ETIMEDOUT) |
| 2855 | btintel_reset_to_bootloader(hdev); |
| 2856 | |
| 2857 | return err; |
| 2858 | } |
| 2859 | |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2860 | static int btusb_setup_intel_new(struct hci_dev *hdev) |
| 2861 | { |
| 2862 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2863 | struct intel_version ver; |
| 2864 | struct intel_boot_params params; |
| 2865 | u32 boot_param; |
| 2866 | char ddcname[64]; |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2867 | int err; |
| 2868 | struct intel_debug_features features; |
| 2869 | |
| 2870 | BT_DBG("%s", hdev->name); |
| 2871 | |
| 2872 | /* Set the default boot parameter to 0x0 and it is updated to |
| 2873 | * SKU specific boot parameter after reading Intel_Write_Boot_Params |
| 2874 | * command while downloading the firmware. |
| 2875 | */ |
| 2876 | boot_param = 0x00000000; |
| 2877 | |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2878 | /* Read the Intel version information to determine if the device |
| 2879 | * is in bootloader mode or if it already has operational firmware |
| 2880 | * loaded. |
| 2881 | */ |
| 2882 | err = btintel_read_version(hdev, &ver); |
| 2883 | if (err) { |
| 2884 | bt_dev_err(hdev, "Intel Read version failed (%d)", err); |
| 2885 | btintel_reset_to_bootloader(hdev); |
| 2886 | return err; |
| 2887 | } |
| 2888 | |
Luiz Augusto von Dentz | d68903d | 2021-03-23 11:58:59 -0700 | [diff] [blame] | 2889 | err = btintel_version_info(hdev, &ver); |
| 2890 | if (err) |
| 2891 | return err; |
| 2892 | |
Kiran K | dc45d37 | 2020-08-26 15:24:32 +0530 | [diff] [blame] | 2893 | err = btusb_intel_download_firmware(hdev, &ver, ¶ms, &boot_param); |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2894 | if (err) |
| 2895 | return err; |
| 2896 | |
| 2897 | /* controller is already having an operational firmware */ |
| 2898 | if (ver.fw_variant == 0x23) |
| 2899 | goto finish; |
| 2900 | |
Luiz Augusto von Dentz | 604b3cf | 2021-03-23 11:59:01 -0700 | [diff] [blame] | 2901 | err = btusb_intel_boot(hdev, boot_param); |
| 2902 | if (err) |
Tedd Ho-Jeong An | e5889af | 2018-01-24 09:19:18 -0800 | [diff] [blame] | 2903 | return err; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2904 | |
| 2905 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
| 2906 | |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2907 | err = btusb_setup_intel_new_get_fw_name(&ver, ¶ms, ddcname, |
| 2908 | sizeof(ddcname), "ddc"); |
| 2909 | |
Luiz Augusto von Dentz | 9b16bfb | 2021-03-23 11:58:57 -0700 | [diff] [blame] | 2910 | if (err < 0) { |
Kiran K | 5ea7c81 | 2020-06-25 00:04:32 +0530 | [diff] [blame] | 2911 | bt_dev_err(hdev, "Unsupported Intel firmware naming"); |
| 2912 | } else { |
| 2913 | /* Once the device is running in operational mode, it needs to |
| 2914 | * apply the device configuration (DDC) parameters. |
| 2915 | * |
| 2916 | * The device can work without DDC parameters, so even if it |
| 2917 | * fails to load the file, no need to fail the setup. |
| 2918 | */ |
| 2919 | btintel_load_ddc_config(hdev, ddcname); |
| 2920 | } |
Tedd Ho-Jeong An | 52cc916 | 2015-06-12 16:20:05 -0700 | [diff] [blame] | 2921 | |
Chethan T N | d74abe2 | 2020-06-08 17:57:46 +0530 | [diff] [blame] | 2922 | /* Read the Intel supported features and if new exception formats |
| 2923 | * supported, need to load the additional DDC config to enable. |
| 2924 | */ |
Jun Miao | 20a831f | 2021-07-09 21:46:25 +0800 | [diff] [blame] | 2925 | err = btintel_read_debug_features(hdev, &features); |
| 2926 | if (!err) { |
| 2927 | /* Set DDC mask for available debug features */ |
| 2928 | btintel_set_debug_features(hdev, &features); |
| 2929 | } |
Chethan T N | c453b10 | 2020-06-08 17:57:47 +0530 | [diff] [blame] | 2930 | |
Marcel Holtmann | 7fd673b | 2020-04-03 21:44:02 +0200 | [diff] [blame] | 2931 | /* Read the Intel version information after loading the FW */ |
| 2932 | err = btintel_read_version(hdev, &ver); |
| 2933 | if (err) |
| 2934 | return err; |
| 2935 | |
| 2936 | btintel_version_info(hdev, &ver); |
| 2937 | |
| 2938 | finish: |
Miao-chen Chou | fc04590 | 2020-04-03 21:44:03 +0200 | [diff] [blame] | 2939 | /* All Intel controllers that support the Microsoft vendor |
| 2940 | * extension are using 0xFC1E for VsMsftOpCode. |
| 2941 | */ |
| 2942 | switch (ver.hw_variant) { |
Miao-chen Chou | 7a45bcb | 2020-12-17 14:53:19 -0800 | [diff] [blame] | 2943 | case 0x11: /* JfP */ |
Miao-chen Chou | fc04590 | 2020-04-03 21:44:03 +0200 | [diff] [blame] | 2944 | case 0x12: /* ThP */ |
Miao-chen Chou | 7a45bcb | 2020-12-17 14:53:19 -0800 | [diff] [blame] | 2945 | case 0x13: /* HrP */ |
| 2946 | case 0x14: /* CcP */ |
Miao-chen Chou | fc04590 | 2020-04-03 21:44:03 +0200 | [diff] [blame] | 2947 | hci_set_msft_opcode(hdev, 0xFC1E); |
| 2948 | break; |
| 2949 | } |
| 2950 | |
Marcel Holtmann | 213445b | 2015-10-21 02:45:19 +0200 | [diff] [blame] | 2951 | /* Set the event mask for Intel specific vendor events. This enables |
| 2952 | * a few extra events that are useful during general operation. It |
| 2953 | * does not enable any debugging related events. |
| 2954 | * |
| 2955 | * The device will function correctly without these events enabled |
| 2956 | * and thus no need to fail the setup. |
| 2957 | */ |
| 2958 | btintel_set_event_mask(hdev, false); |
| 2959 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2960 | return 0; |
| 2961 | } |
| 2962 | |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 2963 | static int btusb_setup_intel_newgen(struct hci_dev *hdev) |
| 2964 | { |
| 2965 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 2966 | u32 boot_param; |
| 2967 | char ddcname[64]; |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 2968 | int err; |
| 2969 | struct intel_debug_features features; |
| 2970 | struct intel_version_tlv version; |
| 2971 | |
| 2972 | bt_dev_dbg(hdev, ""); |
| 2973 | |
| 2974 | /* Set the default boot parameter to 0x0 and it is updated to |
| 2975 | * SKU specific boot parameter after reading Intel_Write_Boot_Params |
| 2976 | * command while downloading the firmware. |
| 2977 | */ |
| 2978 | boot_param = 0x00000000; |
| 2979 | |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 2980 | /* Read the Intel version information to determine if the device |
| 2981 | * is in bootloader mode or if it already has operational firmware |
| 2982 | * loaded. |
| 2983 | */ |
| 2984 | err = btintel_read_version_tlv(hdev, &version); |
| 2985 | if (err) { |
| 2986 | bt_dev_err(hdev, "Intel Read version failed (%d)", err); |
| 2987 | btintel_reset_to_bootloader(hdev); |
| 2988 | return err; |
| 2989 | } |
| 2990 | |
Luiz Augusto von Dentz | 0a460d8 | 2021-03-23 11:58:58 -0700 | [diff] [blame] | 2991 | err = btintel_version_info_tlv(hdev, &version); |
| 2992 | if (err) |
| 2993 | return err; |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 2994 | |
Kiran K | 3f43a37 | 2020-11-19 17:09:42 +0530 | [diff] [blame] | 2995 | err = btusb_intel_download_firmware_newgen(hdev, &version, &boot_param); |
| 2996 | if (err) |
| 2997 | return err; |
| 2998 | |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 2999 | /* check if controller is already having an operational firmware */ |
| 3000 | if (version.img_type == 0x03) |
| 3001 | goto finish; |
| 3002 | |
Luiz Augusto von Dentz | 604b3cf | 2021-03-23 11:59:01 -0700 | [diff] [blame] | 3003 | err = btusb_intel_boot(hdev, boot_param); |
| 3004 | if (err) |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 3005 | return err; |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 3006 | |
| 3007 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
| 3008 | |
Kiran K | 9a93b8b | 2020-11-19 17:09:41 +0530 | [diff] [blame] | 3009 | btusb_setup_intel_newgen_get_fw_name(&version, ddcname, sizeof(ddcname), |
| 3010 | "ddc"); |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 3011 | /* Once the device is running in operational mode, it needs to |
| 3012 | * apply the device configuration (DDC) parameters. |
| 3013 | * |
| 3014 | * The device can work without DDC parameters, so even if it |
| 3015 | * fails to load the file, no need to fail the setup. |
| 3016 | */ |
| 3017 | btintel_load_ddc_config(hdev, ddcname); |
| 3018 | |
| 3019 | /* Read the Intel supported features and if new exception formats |
| 3020 | * supported, need to load the additional DDC config to enable. |
| 3021 | */ |
Jun Miao | 20a831f | 2021-07-09 21:46:25 +0800 | [diff] [blame] | 3022 | err = btintel_read_debug_features(hdev, &features); |
| 3023 | if (!err) { |
| 3024 | /* Set DDC mask for available debug features */ |
| 3025 | btintel_set_debug_features(hdev, &features); |
| 3026 | } |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 3027 | |
| 3028 | /* Read the Intel version information after loading the FW */ |
| 3029 | err = btintel_read_version_tlv(hdev, &version); |
| 3030 | if (err) |
| 3031 | return err; |
| 3032 | |
| 3033 | btintel_version_info_tlv(hdev, &version); |
| 3034 | |
| 3035 | finish: |
Chethan T N | f283f47 | 2021-07-29 09:43:21 -0700 | [diff] [blame] | 3036 | /* All Intel new genration controllers support the Microsoft vendor |
| 3037 | * extension are using 0xFC1E for VsMsftOpCode. |
| 3038 | */ |
| 3039 | switch (INTEL_HW_VARIANT(version.cnvi_bt)) { |
| 3040 | case 0x17: |
| 3041 | case 0x18: |
| 3042 | case 0x19: |
| 3043 | hci_set_msft_opcode(hdev, 0xFC1E); |
| 3044 | break; |
| 3045 | } |
| 3046 | |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 3047 | /* Set the event mask for Intel specific vendor events. This enables |
| 3048 | * a few extra events that are useful during general operation. It |
| 3049 | * does not enable any debugging related events. |
| 3050 | * |
| 3051 | * The device will function correctly without these events enabled |
| 3052 | * and thus no need to fail the setup. |
| 3053 | */ |
| 3054 | btintel_set_event_mask(hdev, false); |
| 3055 | |
| 3056 | return 0; |
| 3057 | } |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 3058 | static int btusb_shutdown_intel(struct hci_dev *hdev) |
| 3059 | { |
| 3060 | struct sk_buff *skb; |
| 3061 | long ret; |
| 3062 | |
Amit K Bag | 1313bcc | 2018-08-03 12:43:20 +0530 | [diff] [blame] | 3063 | /* In the shutdown sequence where Bluetooth is turned off followed |
| 3064 | * by WiFi being turned off, turning WiFi back on causes issue with |
| 3065 | * the RF calibration. |
| 3066 | * |
| 3067 | * To ensure that any RF activity has been stopped, issue HCI Reset |
| 3068 | * command to clear all ongoing activity including advertising, |
| 3069 | * scanning etc. |
| 3070 | */ |
| 3071 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 3072 | if (IS_ERR(skb)) { |
| 3073 | ret = PTR_ERR(skb); |
| 3074 | bt_dev_err(hdev, "HCI reset during shutdown failed"); |
| 3075 | return ret; |
| 3076 | } |
| 3077 | kfree_skb(skb); |
| 3078 | |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 3079 | /* Some platforms have an issue with BT LED when the interface is |
| 3080 | * down or BT radio is turned off, which takes 5 seconds to BT LED |
| 3081 | * goes off. This command turns off the BT LED immediately. |
| 3082 | */ |
| 3083 | skb = __hci_cmd_sync(hdev, 0xfc3f, 0, NULL, HCI_INIT_TIMEOUT); |
| 3084 | if (IS_ERR(skb)) { |
| 3085 | ret = PTR_ERR(skb); |
Marcel Holtmann | 85418fe | 2018-08-03 11:20:49 +0200 | [diff] [blame] | 3086 | bt_dev_err(hdev, "turning off Intel device LED failed"); |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 3087 | return ret; |
| 3088 | } |
| 3089 | kfree_skb(skb); |
| 3090 | |
| 3091 | return 0; |
| 3092 | } |
| 3093 | |
Raghuram Hegde | 017a01c | 2019-01-29 17:54:48 +0530 | [diff] [blame] | 3094 | static int btusb_shutdown_intel_new(struct hci_dev *hdev) |
| 3095 | { |
| 3096 | struct sk_buff *skb; |
| 3097 | |
| 3098 | /* Send HCI Reset to the controller to stop any BT activity which |
| 3099 | * were triggered. This will help to save power and maintain the |
| 3100 | * sync b/w Host and controller |
| 3101 | */ |
| 3102 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 3103 | if (IS_ERR(skb)) { |
| 3104 | bt_dev_err(hdev, "HCI reset during shutdown failed"); |
| 3105 | return PTR_ERR(skb); |
| 3106 | } |
| 3107 | kfree_skb(skb); |
| 3108 | |
| 3109 | return 0; |
| 3110 | } |
| 3111 | |
Sean Wang | 9ce67c3 | 2019-06-02 08:02:49 +0800 | [diff] [blame] | 3112 | #define FIRMWARE_MT7663 "mediatek/mt7663pr2h.bin" |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3113 | #define FIRMWARE_MT7668 "mediatek/mt7668pr2h.bin" |
| 3114 | |
| 3115 | #define HCI_WMT_MAX_EVENT_SIZE 64 |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3116 | /* It is for mt79xx download rom patch*/ |
| 3117 | #define MTK_FW_ROM_PATCH_HEADER_SIZE 32 |
| 3118 | #define MTK_FW_ROM_PATCH_GD_SIZE 64 |
| 3119 | #define MTK_FW_ROM_PATCH_SEC_MAP_SIZE 64 |
| 3120 | #define MTK_SEC_MAP_COMMON_SIZE 12 |
| 3121 | #define MTK_SEC_MAP_NEED_SEND_SIZE 52 |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3122 | |
| 3123 | enum { |
| 3124 | BTMTK_WMT_PATCH_DWNLD = 0x1, |
| 3125 | BTMTK_WMT_FUNC_CTRL = 0x6, |
| 3126 | BTMTK_WMT_RST = 0x7, |
| 3127 | BTMTK_WMT_SEMAPHORE = 0x17, |
| 3128 | }; |
| 3129 | |
| 3130 | enum { |
| 3131 | BTMTK_WMT_INVALID, |
| 3132 | BTMTK_WMT_PATCH_UNDONE, |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 3133 | BTMTK_WMT_PATCH_PROGRESS, |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3134 | BTMTK_WMT_PATCH_DONE, |
| 3135 | BTMTK_WMT_ON_UNDONE, |
| 3136 | BTMTK_WMT_ON_DONE, |
| 3137 | BTMTK_WMT_ON_PROGRESS, |
| 3138 | }; |
| 3139 | |
| 3140 | struct btmtk_wmt_hdr { |
| 3141 | u8 dir; |
| 3142 | u8 op; |
| 3143 | __le16 dlen; |
| 3144 | u8 flag; |
| 3145 | } __packed; |
| 3146 | |
| 3147 | struct btmtk_hci_wmt_cmd { |
| 3148 | struct btmtk_wmt_hdr hdr; |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3149 | u8 data[]; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3150 | } __packed; |
| 3151 | |
| 3152 | struct btmtk_hci_wmt_evt { |
| 3153 | struct hci_event_hdr hhdr; |
| 3154 | struct btmtk_wmt_hdr whdr; |
| 3155 | } __packed; |
| 3156 | |
| 3157 | struct btmtk_hci_wmt_evt_funcc { |
| 3158 | struct btmtk_hci_wmt_evt hwhdr; |
| 3159 | __be16 status; |
| 3160 | } __packed; |
| 3161 | |
| 3162 | struct btmtk_tci_sleep { |
| 3163 | u8 mode; |
| 3164 | __le16 duration; |
| 3165 | __le16 host_duration; |
| 3166 | u8 host_wakeup_pin; |
| 3167 | u8 time_compensation; |
| 3168 | } __packed; |
| 3169 | |
| 3170 | struct btmtk_hci_wmt_params { |
| 3171 | u8 op; |
| 3172 | u8 flag; |
| 3173 | u16 dlen; |
| 3174 | const void *data; |
| 3175 | u32 *status; |
| 3176 | }; |
| 3177 | |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3178 | struct btmtk_patch_header { |
| 3179 | u8 datetime[16]; |
| 3180 | u8 platform[4]; |
| 3181 | __le16 hwver; |
| 3182 | __le16 swver; |
| 3183 | __le32 magicnum; |
| 3184 | } __packed; |
| 3185 | |
| 3186 | struct btmtk_global_desc { |
| 3187 | __le32 patch_ver; |
| 3188 | __le32 sub_sys; |
| 3189 | __le32 feature_opt; |
| 3190 | __le32 section_num; |
| 3191 | } __packed; |
| 3192 | |
| 3193 | struct btmtk_section_map { |
| 3194 | __le32 sectype; |
| 3195 | __le32 secoffset; |
| 3196 | __le32 secsize; |
| 3197 | union { |
| 3198 | __le32 u4SecSpec[13]; |
| 3199 | struct { |
| 3200 | __le32 dlAddr; |
| 3201 | __le32 dlsize; |
| 3202 | __le32 seckeyidx; |
| 3203 | __le32 alignlen; |
| 3204 | __le32 sectype; |
| 3205 | __le32 dlmodecrctype; |
| 3206 | __le32 crc; |
| 3207 | __le32 reserved[6]; |
| 3208 | } bin_info_spec; |
| 3209 | }; |
| 3210 | } __packed; |
| 3211 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3212 | static void btusb_mtk_wmt_recv(struct urb *urb) |
| 3213 | { |
| 3214 | struct hci_dev *hdev = urb->context; |
| 3215 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3216 | struct hci_event_hdr *hdr; |
| 3217 | struct sk_buff *skb; |
| 3218 | int err; |
| 3219 | |
| 3220 | if (urb->status == 0 && urb->actual_length > 0) { |
| 3221 | hdev->stat.byte_rx += urb->actual_length; |
| 3222 | |
| 3223 | /* WMT event shouldn't be fragmented and the size should be |
| 3224 | * less than HCI_WMT_MAX_EVENT_SIZE. |
| 3225 | */ |
| 3226 | skb = bt_skb_alloc(HCI_WMT_MAX_EVENT_SIZE, GFP_ATOMIC); |
| 3227 | if (!skb) { |
| 3228 | hdev->stat.err_rx++; |
Jupeng Zhong | de71a6c | 2021-02-02 09:39:13 +0800 | [diff] [blame] | 3229 | return; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | hci_skb_pkt_type(skb) = HCI_EVENT_PKT; |
| 3233 | skb_put_data(skb, urb->transfer_buffer, urb->actual_length); |
| 3234 | |
| 3235 | hdr = (void *)skb->data; |
| 3236 | /* Fix up the vendor event id with 0xff for vendor specific |
| 3237 | * instead of 0xe4 so that event send via monitoring socket can |
| 3238 | * be parsed properly. |
| 3239 | */ |
| 3240 | hdr->evt = 0xff; |
| 3241 | |
| 3242 | /* When someone waits for the WMT event, the skb is being cloned |
| 3243 | * and being processed the events from there then. |
| 3244 | */ |
| 3245 | if (test_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags)) { |
Johan Hovold | 22cc6b7 | 2019-11-28 19:24:27 +0100 | [diff] [blame] | 3246 | data->evt_skb = skb_clone(skb, GFP_ATOMIC); |
Jupeng Zhong | de71a6c | 2021-02-02 09:39:13 +0800 | [diff] [blame] | 3247 | if (!data->evt_skb) { |
| 3248 | kfree_skb(skb); |
| 3249 | return; |
| 3250 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | err = hci_recv_frame(hdev, skb); |
Jupeng Zhong | de71a6c | 2021-02-02 09:39:13 +0800 | [diff] [blame] | 3254 | if (err < 0) { |
| 3255 | kfree_skb(data->evt_skb); |
| 3256 | data->evt_skb = NULL; |
| 3257 | return; |
| 3258 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3259 | |
| 3260 | if (test_and_clear_bit(BTUSB_TX_WAIT_VND_EVT, |
| 3261 | &data->flags)) { |
| 3262 | /* Barrier to sync with other CPUs */ |
| 3263 | smp_mb__after_atomic(); |
| 3264 | wake_up_bit(&data->flags, |
| 3265 | BTUSB_TX_WAIT_VND_EVT); |
| 3266 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3267 | return; |
| 3268 | } else if (urb->status == -ENOENT) { |
| 3269 | /* Avoid suspend failed when usb_kill_urb */ |
| 3270 | return; |
| 3271 | } |
| 3272 | |
| 3273 | usb_mark_last_busy(data->udev); |
| 3274 | |
| 3275 | /* The URB complete handler is still called with urb->actual_length = 0 |
| 3276 | * when the event is not available, so we should keep re-submitting |
| 3277 | * URB until WMT event returns, Also, It's necessary to wait some time |
| 3278 | * between the two consecutive control URBs to relax the target device |
| 3279 | * to generate the event. Otherwise, the WMT event cannot return from |
| 3280 | * the device successfully. |
| 3281 | */ |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 3282 | udelay(500); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3283 | |
| 3284 | usb_anchor_urb(urb, &data->ctrl_anchor); |
| 3285 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 3286 | if (err < 0) { |
| 3287 | /* -EPERM: urb is being killed; |
| 3288 | * -ENODEV: device got disconnected |
| 3289 | */ |
| 3290 | if (err != -EPERM && err != -ENODEV) |
| 3291 | bt_dev_err(hdev, "urb %p failed to resubmit (%d)", |
| 3292 | urb, -err); |
| 3293 | usb_unanchor_urb(urb); |
| 3294 | } |
| 3295 | } |
| 3296 | |
| 3297 | static int btusb_mtk_submit_wmt_recv_urb(struct hci_dev *hdev) |
| 3298 | { |
| 3299 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3300 | struct usb_ctrlrequest *dr; |
| 3301 | unsigned char *buf; |
| 3302 | int err, size = 64; |
| 3303 | unsigned int pipe; |
| 3304 | struct urb *urb; |
| 3305 | |
| 3306 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 3307 | if (!urb) |
| 3308 | return -ENOMEM; |
| 3309 | |
| 3310 | dr = kmalloc(sizeof(*dr), GFP_KERNEL); |
| 3311 | if (!dr) { |
| 3312 | usb_free_urb(urb); |
| 3313 | return -ENOMEM; |
| 3314 | } |
| 3315 | |
| 3316 | dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_IN; |
| 3317 | dr->bRequest = 1; |
| 3318 | dr->wIndex = cpu_to_le16(0); |
| 3319 | dr->wValue = cpu_to_le16(48); |
| 3320 | dr->wLength = cpu_to_le16(size); |
| 3321 | |
| 3322 | buf = kmalloc(size, GFP_KERNEL); |
| 3323 | if (!buf) { |
| 3324 | kfree(dr); |
Dinghao Liu | d33fe77 | 2020-08-23 15:44:21 +0800 | [diff] [blame] | 3325 | usb_free_urb(urb); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3326 | return -ENOMEM; |
| 3327 | } |
| 3328 | |
| 3329 | pipe = usb_rcvctrlpipe(data->udev, 0); |
| 3330 | |
| 3331 | usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, |
| 3332 | buf, size, btusb_mtk_wmt_recv, hdev); |
| 3333 | |
| 3334 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 3335 | |
| 3336 | usb_anchor_urb(urb, &data->ctrl_anchor); |
| 3337 | err = usb_submit_urb(urb, GFP_KERNEL); |
| 3338 | if (err < 0) { |
| 3339 | if (err != -EPERM && err != -ENODEV) |
| 3340 | bt_dev_err(hdev, "urb %p submission failed (%d)", |
| 3341 | urb, -err); |
| 3342 | usb_unanchor_urb(urb); |
| 3343 | } |
| 3344 | |
| 3345 | usb_free_urb(urb); |
| 3346 | |
| 3347 | return err; |
| 3348 | } |
| 3349 | |
| 3350 | static int btusb_mtk_hci_wmt_sync(struct hci_dev *hdev, |
| 3351 | struct btmtk_hci_wmt_params *wmt_params) |
| 3352 | { |
| 3353 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3354 | struct btmtk_hci_wmt_evt_funcc *wmt_evt_funcc; |
| 3355 | u32 hlen, status = BTMTK_WMT_INVALID; |
| 3356 | struct btmtk_hci_wmt_evt *wmt_evt; |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3357 | struct btmtk_hci_wmt_cmd *wc; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3358 | struct btmtk_wmt_hdr *hdr; |
| 3359 | int err; |
| 3360 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3361 | /* Send the WMT command and wait until the WMT event returns */ |
| 3362 | hlen = sizeof(*hdr) + wmt_params->dlen; |
| 3363 | if (hlen > 255) |
| 3364 | return -EINVAL; |
| 3365 | |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3366 | wc = kzalloc(hlen, GFP_KERNEL); |
| 3367 | if (!wc) |
| 3368 | return -ENOMEM; |
| 3369 | |
| 3370 | hdr = &wc->hdr; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3371 | hdr->dir = 1; |
| 3372 | hdr->op = wmt_params->op; |
| 3373 | hdr->dlen = cpu_to_le16(wmt_params->dlen + 1); |
| 3374 | hdr->flag = wmt_params->flag; |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3375 | memcpy(wc->data, wmt_params->data, wmt_params->dlen); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3376 | |
| 3377 | set_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
| 3378 | |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3379 | err = __hci_cmd_send(hdev, 0xfc6f, hlen, wc); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3380 | |
| 3381 | if (err < 0) { |
| 3382 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3383 | goto err_free_wc; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3384 | } |
| 3385 | |
mark-yw.chen | 8454ed9 | 2021-04-12 23:06:26 +0800 | [diff] [blame] | 3386 | /* Submit control IN URB on demand to process the WMT event */ |
| 3387 | err = btusb_mtk_submit_wmt_recv_urb(hdev); |
| 3388 | if (err < 0) |
Muhammad Usama Anjum | 44e936d | 2021-04-13 22:52:08 +0500 | [diff] [blame] | 3389 | goto err_free_wc; |
mark-yw.chen | 8454ed9 | 2021-04-12 23:06:26 +0800 | [diff] [blame] | 3390 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3391 | /* The vendor specific WMT commands are all answered by a vendor |
| 3392 | * specific event and will have the Command Status or Command |
| 3393 | * Complete as with usual HCI command flow control. |
| 3394 | * |
| 3395 | * After sending the command, wait for BTUSB_TX_WAIT_VND_EVT |
| 3396 | * state to be cleared. The driver specific event receive routine |
| 3397 | * will clear that state and with that indicate completion of the |
| 3398 | * WMT command. |
| 3399 | */ |
| 3400 | err = wait_on_bit_timeout(&data->flags, BTUSB_TX_WAIT_VND_EVT, |
| 3401 | TASK_INTERRUPTIBLE, HCI_INIT_TIMEOUT); |
| 3402 | if (err == -EINTR) { |
| 3403 | bt_dev_err(hdev, "Execution of wmt command interrupted"); |
| 3404 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3405 | goto err_free_wc; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | if (err) { |
| 3409 | bt_dev_err(hdev, "Execution of wmt command timed out"); |
| 3410 | clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3411 | err = -ETIMEDOUT; |
| 3412 | goto err_free_wc; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | /* Parse and handle the return WMT event */ |
| 3416 | wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data; |
| 3417 | if (wmt_evt->whdr.op != hdr->op) { |
| 3418 | bt_dev_err(hdev, "Wrong op received %d expected %d", |
| 3419 | wmt_evt->whdr.op, hdr->op); |
| 3420 | err = -EIO; |
| 3421 | goto err_free_skb; |
| 3422 | } |
| 3423 | |
| 3424 | switch (wmt_evt->whdr.op) { |
| 3425 | case BTMTK_WMT_SEMAPHORE: |
| 3426 | if (wmt_evt->whdr.flag == 2) |
| 3427 | status = BTMTK_WMT_PATCH_UNDONE; |
| 3428 | else |
| 3429 | status = BTMTK_WMT_PATCH_DONE; |
| 3430 | break; |
| 3431 | case BTMTK_WMT_FUNC_CTRL: |
| 3432 | wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt; |
| 3433 | if (be16_to_cpu(wmt_evt_funcc->status) == 0x404) |
| 3434 | status = BTMTK_WMT_ON_DONE; |
| 3435 | else if (be16_to_cpu(wmt_evt_funcc->status) == 0x420) |
| 3436 | status = BTMTK_WMT_ON_PROGRESS; |
| 3437 | else |
| 3438 | status = BTMTK_WMT_ON_UNDONE; |
| 3439 | break; |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3440 | case BTMTK_WMT_PATCH_DWNLD: |
| 3441 | if (wmt_evt->whdr.flag == 2) |
| 3442 | status = BTMTK_WMT_PATCH_DONE; |
| 3443 | else if (wmt_evt->whdr.flag == 1) |
| 3444 | status = BTMTK_WMT_PATCH_PROGRESS; |
| 3445 | else |
| 3446 | status = BTMTK_WMT_PATCH_UNDONE; |
| 3447 | break; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | if (wmt_params->status) |
| 3451 | *wmt_params->status = status; |
| 3452 | |
| 3453 | err_free_skb: |
| 3454 | kfree_skb(data->evt_skb); |
| 3455 | data->evt_skb = NULL; |
Arnd Bergmann | 1088814 | 2021-02-04 16:47:07 +0100 | [diff] [blame] | 3456 | err_free_wc: |
| 3457 | kfree(wc); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3458 | return err; |
| 3459 | } |
| 3460 | |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3461 | static int btusb_mtk_setup_firmware_79xx(struct hci_dev *hdev, const char *fwname) |
| 3462 | { |
| 3463 | struct btmtk_hci_wmt_params wmt_params; |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3464 | struct btmtk_global_desc *globaldesc = NULL; |
| 3465 | struct btmtk_section_map *sectionmap; |
| 3466 | const struct firmware *fw; |
| 3467 | const u8 *fw_ptr; |
| 3468 | const u8 *fw_bin_ptr; |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3469 | int err, dlen, i, status; |
| 3470 | u8 flag, first_block, retry; |
| 3471 | u32 section_num, dl_size, section_offset; |
| 3472 | u8 cmd[64]; |
| 3473 | |
| 3474 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 3475 | if (err < 0) { |
| 3476 | bt_dev_err(hdev, "Failed to load firmware file (%d)", err); |
| 3477 | return err; |
| 3478 | } |
| 3479 | |
| 3480 | fw_ptr = fw->data; |
| 3481 | fw_bin_ptr = fw_ptr; |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3482 | globaldesc = (struct btmtk_global_desc *)(fw_ptr + MTK_FW_ROM_PATCH_HEADER_SIZE); |
mark-yw.chen | 201cf39 | 2021-02-23 14:27:40 +0800 | [diff] [blame] | 3483 | section_num = le32_to_cpu(globaldesc->section_num); |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3484 | |
| 3485 | for (i = 0; i < section_num; i++) { |
| 3486 | first_block = 1; |
| 3487 | fw_ptr = fw_bin_ptr; |
| 3488 | sectionmap = (struct btmtk_section_map *)(fw_ptr + MTK_FW_ROM_PATCH_HEADER_SIZE + |
| 3489 | MTK_FW_ROM_PATCH_GD_SIZE + MTK_FW_ROM_PATCH_SEC_MAP_SIZE * i); |
| 3490 | |
mark-yw.chen | 201cf39 | 2021-02-23 14:27:40 +0800 | [diff] [blame] | 3491 | section_offset = le32_to_cpu(sectionmap->secoffset); |
| 3492 | dl_size = le32_to_cpu(sectionmap->bin_info_spec.dlsize); |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3493 | |
| 3494 | if (dl_size > 0) { |
| 3495 | retry = 20; |
| 3496 | while (retry > 0) { |
| 3497 | cmd[0] = 0; /* 0 means legacy dl mode. */ |
| 3498 | memcpy(cmd + 1, |
| 3499 | fw_ptr + MTK_FW_ROM_PATCH_HEADER_SIZE + |
| 3500 | MTK_FW_ROM_PATCH_GD_SIZE + MTK_FW_ROM_PATCH_SEC_MAP_SIZE * i + |
| 3501 | MTK_SEC_MAP_COMMON_SIZE, |
| 3502 | MTK_SEC_MAP_NEED_SEND_SIZE + 1); |
| 3503 | |
| 3504 | wmt_params.op = BTMTK_WMT_PATCH_DWNLD; |
| 3505 | wmt_params.status = &status; |
| 3506 | wmt_params.flag = 0; |
| 3507 | wmt_params.dlen = MTK_SEC_MAP_NEED_SEND_SIZE + 1; |
| 3508 | wmt_params.data = &cmd; |
| 3509 | |
| 3510 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3511 | if (err < 0) { |
| 3512 | bt_dev_err(hdev, "Failed to send wmt patch dwnld (%d)", |
| 3513 | err); |
| 3514 | goto err_release_fw; |
| 3515 | } |
| 3516 | |
| 3517 | if (status == BTMTK_WMT_PATCH_UNDONE) { |
| 3518 | break; |
| 3519 | } else if (status == BTMTK_WMT_PATCH_PROGRESS) { |
| 3520 | msleep(100); |
| 3521 | retry--; |
| 3522 | } else if (status == BTMTK_WMT_PATCH_DONE) { |
| 3523 | goto next_section; |
| 3524 | } else { |
| 3525 | bt_dev_err(hdev, "Failed wmt patch dwnld status (%d)", |
| 3526 | status); |
| 3527 | goto err_release_fw; |
| 3528 | } |
| 3529 | } |
| 3530 | |
| 3531 | fw_ptr += section_offset; |
| 3532 | wmt_params.op = BTMTK_WMT_PATCH_DWNLD; |
| 3533 | wmt_params.status = NULL; |
| 3534 | |
| 3535 | while (dl_size > 0) { |
| 3536 | dlen = min_t(int, 250, dl_size); |
| 3537 | if (first_block == 1) { |
| 3538 | flag = 1; |
| 3539 | first_block = 0; |
| 3540 | } else if (dl_size - dlen <= 0) { |
| 3541 | flag = 3; |
| 3542 | } else { |
| 3543 | flag = 2; |
| 3544 | } |
| 3545 | |
| 3546 | wmt_params.flag = flag; |
| 3547 | wmt_params.dlen = dlen; |
| 3548 | wmt_params.data = fw_ptr; |
| 3549 | |
| 3550 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3551 | if (err < 0) { |
| 3552 | bt_dev_err(hdev, "Failed to send wmt patch dwnld (%d)", |
| 3553 | err); |
| 3554 | goto err_release_fw; |
| 3555 | } |
| 3556 | |
| 3557 | dl_size -= dlen; |
| 3558 | fw_ptr += dlen; |
| 3559 | } |
| 3560 | } |
| 3561 | next_section: |
| 3562 | continue; |
| 3563 | } |
| 3564 | /* Wait a few moments for firmware activation done */ |
| 3565 | usleep_range(100000, 120000); |
| 3566 | |
| 3567 | err_release_fw: |
| 3568 | release_firmware(fw); |
| 3569 | |
| 3570 | return err; |
| 3571 | } |
| 3572 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3573 | static int btusb_mtk_setup_firmware(struct hci_dev *hdev, const char *fwname) |
| 3574 | { |
| 3575 | struct btmtk_hci_wmt_params wmt_params; |
| 3576 | const struct firmware *fw; |
| 3577 | const u8 *fw_ptr; |
| 3578 | size_t fw_size; |
| 3579 | int err, dlen; |
Sean Wang | f645125 | 2020-06-19 19:52:01 +0000 | [diff] [blame] | 3580 | u8 flag, param; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3581 | |
| 3582 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 3583 | if (err < 0) { |
| 3584 | bt_dev_err(hdev, "Failed to load firmware file (%d)", err); |
| 3585 | return err; |
| 3586 | } |
| 3587 | |
Sean Wang | f645125 | 2020-06-19 19:52:01 +0000 | [diff] [blame] | 3588 | /* Power on data RAM the firmware relies on. */ |
| 3589 | param = 1; |
| 3590 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 3591 | wmt_params.flag = 3; |
| 3592 | wmt_params.dlen = sizeof(param); |
| 3593 | wmt_params.data = ¶m; |
| 3594 | wmt_params.status = NULL; |
| 3595 | |
| 3596 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3597 | if (err < 0) { |
| 3598 | bt_dev_err(hdev, "Failed to power on data RAM (%d)", err); |
Jing Xiangfeng | d1e9d23 | 2020-11-17 10:59:17 +0800 | [diff] [blame] | 3599 | goto err_release_fw; |
Sean Wang | f645125 | 2020-06-19 19:52:01 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3602 | fw_ptr = fw->data; |
| 3603 | fw_size = fw->size; |
| 3604 | |
| 3605 | /* The size of patch header is 30 bytes, should be skip */ |
Wei Yongjun | 5ee6310 | 2019-07-10 06:12:22 +0000 | [diff] [blame] | 3606 | if (fw_size < 30) { |
| 3607 | err = -EINVAL; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3608 | goto err_release_fw; |
Wei Yongjun | 5ee6310 | 2019-07-10 06:12:22 +0000 | [diff] [blame] | 3609 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3610 | |
| 3611 | fw_size -= 30; |
| 3612 | fw_ptr += 30; |
| 3613 | flag = 1; |
| 3614 | |
| 3615 | wmt_params.op = BTMTK_WMT_PATCH_DWNLD; |
| 3616 | wmt_params.status = NULL; |
| 3617 | |
| 3618 | while (fw_size > 0) { |
| 3619 | dlen = min_t(int, 250, fw_size); |
| 3620 | |
Jupeng Zhong | a297f56 | 2021-02-03 22:28:46 +0800 | [diff] [blame] | 3621 | /* Tell device the position in sequence */ |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3622 | if (fw_size - dlen <= 0) |
| 3623 | flag = 3; |
| 3624 | else if (fw_size < fw->size - 30) |
| 3625 | flag = 2; |
| 3626 | |
| 3627 | wmt_params.flag = flag; |
| 3628 | wmt_params.dlen = dlen; |
| 3629 | wmt_params.data = fw_ptr; |
| 3630 | |
| 3631 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3632 | if (err < 0) { |
| 3633 | bt_dev_err(hdev, "Failed to send wmt patch dwnld (%d)", |
| 3634 | err); |
| 3635 | goto err_release_fw; |
| 3636 | } |
| 3637 | |
| 3638 | fw_size -= dlen; |
| 3639 | fw_ptr += dlen; |
| 3640 | } |
| 3641 | |
| 3642 | wmt_params.op = BTMTK_WMT_RST; |
| 3643 | wmt_params.flag = 4; |
| 3644 | wmt_params.dlen = 0; |
| 3645 | wmt_params.data = NULL; |
| 3646 | wmt_params.status = NULL; |
| 3647 | |
| 3648 | /* Activate funciton the firmware providing to */ |
| 3649 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3650 | if (err < 0) { |
| 3651 | bt_dev_err(hdev, "Failed to send wmt rst (%d)", err); |
Colin Ian King | 3168c19 | 2019-11-29 17:36:35 +0000 | [diff] [blame] | 3652 | goto err_release_fw; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | /* Wait a few moments for firmware activation done */ |
| 3656 | usleep_range(10000, 12000); |
| 3657 | |
| 3658 | err_release_fw: |
| 3659 | release_firmware(fw); |
| 3660 | |
| 3661 | return err; |
| 3662 | } |
| 3663 | |
| 3664 | static int btusb_mtk_func_query(struct hci_dev *hdev) |
| 3665 | { |
| 3666 | struct btmtk_hci_wmt_params wmt_params; |
| 3667 | int status, err; |
| 3668 | u8 param = 0; |
| 3669 | |
| 3670 | /* Query whether the function is enabled */ |
| 3671 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 3672 | wmt_params.flag = 4; |
| 3673 | wmt_params.dlen = sizeof(param); |
| 3674 | wmt_params.data = ¶m; |
| 3675 | wmt_params.status = &status; |
| 3676 | |
| 3677 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3678 | if (err < 0) { |
| 3679 | bt_dev_err(hdev, "Failed to query function status (%d)", err); |
| 3680 | return err; |
| 3681 | } |
| 3682 | |
| 3683 | return status; |
| 3684 | } |
| 3685 | |
| 3686 | static int btusb_mtk_reg_read(struct btusb_data *data, u32 reg, u32 *val) |
| 3687 | { |
| 3688 | int pipe, err, size = sizeof(u32); |
| 3689 | void *buf; |
| 3690 | |
| 3691 | buf = kzalloc(size, GFP_KERNEL); |
| 3692 | if (!buf) |
| 3693 | return -ENOMEM; |
| 3694 | |
| 3695 | pipe = usb_rcvctrlpipe(data->udev, 0); |
| 3696 | err = usb_control_msg(data->udev, pipe, 0x63, |
| 3697 | USB_TYPE_VENDOR | USB_DIR_IN, |
| 3698 | reg >> 16, reg & 0xffff, |
| 3699 | buf, size, USB_CTRL_SET_TIMEOUT); |
| 3700 | if (err < 0) |
| 3701 | goto err_free_buf; |
| 3702 | |
| 3703 | *val = get_unaligned_le32(buf); |
| 3704 | |
| 3705 | err_free_buf: |
| 3706 | kfree(buf); |
| 3707 | |
| 3708 | return err; |
| 3709 | } |
| 3710 | |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 3711 | 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] | 3712 | { |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 3713 | return btusb_mtk_reg_read(data, reg, id); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | static int btusb_mtk_setup(struct hci_dev *hdev) |
| 3717 | { |
| 3718 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3719 | struct btmtk_hci_wmt_params wmt_params; |
| 3720 | ktime_t calltime, delta, rettime; |
| 3721 | struct btmtk_tci_sleep tci_sleep; |
| 3722 | unsigned long long duration; |
| 3723 | struct sk_buff *skb; |
| 3724 | const char *fwname; |
| 3725 | int err, status; |
| 3726 | u32 dev_id; |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3727 | char fw_bin_name[64]; |
mark-yw.chen | 201cf39 | 2021-02-23 14:27:40 +0800 | [diff] [blame] | 3728 | u32 fw_version = 0; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3729 | u8 param; |
| 3730 | |
| 3731 | calltime = ktime_get(); |
| 3732 | |
Mark Chen | 48c1330 | 2021-02-02 18:26:17 +0800 | [diff] [blame] | 3733 | err = btusb_mtk_id_get(data, 0x80000008, &dev_id); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3734 | if (err < 0) { |
| 3735 | bt_dev_err(hdev, "Failed to get device id (%d)", err); |
| 3736 | return err; |
| 3737 | } |
| 3738 | |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3739 | if (!dev_id) { |
| 3740 | err = btusb_mtk_id_get(data, 0x70010200, &dev_id); |
| 3741 | if (err < 0) { |
| 3742 | bt_dev_err(hdev, "Failed to get device id (%d)", err); |
| 3743 | return err; |
| 3744 | } |
| 3745 | err = btusb_mtk_id_get(data, 0x80021004, &fw_version); |
| 3746 | if (err < 0) { |
| 3747 | bt_dev_err(hdev, "Failed to get fw version (%d)", err); |
| 3748 | return err; |
| 3749 | } |
| 3750 | } |
| 3751 | |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3752 | switch (dev_id) { |
Sean Wang | 9ce67c3 | 2019-06-02 08:02:49 +0800 | [diff] [blame] | 3753 | case 0x7663: |
| 3754 | fwname = FIRMWARE_MT7663; |
| 3755 | break; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3756 | case 0x7668: |
| 3757 | fwname = FIRMWARE_MT7668; |
| 3758 | break; |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3759 | case 0x7961: |
| 3760 | snprintf(fw_bin_name, sizeof(fw_bin_name), |
| 3761 | "mediatek/BT_RAM_CODE_MT%04x_1_%x_hdr.bin", |
| 3762 | dev_id & 0xffff, (fw_version & 0xff) + 1); |
| 3763 | err = btusb_mtk_setup_firmware_79xx(hdev, fw_bin_name); |
| 3764 | |
| 3765 | /* Enable Bluetooth protocol */ |
| 3766 | param = 1; |
| 3767 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 3768 | wmt_params.flag = 0; |
| 3769 | wmt_params.dlen = sizeof(param); |
| 3770 | wmt_params.data = ¶m; |
| 3771 | wmt_params.status = NULL; |
| 3772 | |
| 3773 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3774 | if (err < 0) { |
| 3775 | bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
| 3776 | return err; |
| 3777 | } |
mark-yw.chen | 654e6f7 | 2021-08-02 20:59:41 +0800 | [diff] [blame^] | 3778 | |
| 3779 | hci_set_msft_opcode(hdev, 0xFD30); |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3780 | goto done; |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3781 | default: |
Jupeng Zhong | a297f56 | 2021-02-03 22:28:46 +0800 | [diff] [blame] | 3782 | bt_dev_err(hdev, "Unsupported hardware variant (%08x)", |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3783 | dev_id); |
| 3784 | return -ENODEV; |
| 3785 | } |
| 3786 | |
| 3787 | /* Query whether the firmware is already download */ |
| 3788 | wmt_params.op = BTMTK_WMT_SEMAPHORE; |
| 3789 | wmt_params.flag = 1; |
| 3790 | wmt_params.dlen = 0; |
| 3791 | wmt_params.data = NULL; |
| 3792 | wmt_params.status = &status; |
| 3793 | |
| 3794 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3795 | if (err < 0) { |
| 3796 | bt_dev_err(hdev, "Failed to query firmware status (%d)", err); |
| 3797 | return err; |
| 3798 | } |
| 3799 | |
| 3800 | if (status == BTMTK_WMT_PATCH_DONE) { |
| 3801 | bt_dev_info(hdev, "firmware already downloaded"); |
| 3802 | goto ignore_setup_fw; |
| 3803 | } |
| 3804 | |
| 3805 | /* Setup a firmware which the device definitely requires */ |
| 3806 | err = btusb_mtk_setup_firmware(hdev, fwname); |
| 3807 | if (err < 0) |
| 3808 | return err; |
| 3809 | |
| 3810 | ignore_setup_fw: |
| 3811 | err = readx_poll_timeout(btusb_mtk_func_query, hdev, status, |
| 3812 | status < 0 || status != BTMTK_WMT_ON_PROGRESS, |
| 3813 | 2000, 5000000); |
| 3814 | /* -ETIMEDOUT happens */ |
| 3815 | if (err < 0) |
| 3816 | return err; |
| 3817 | |
| 3818 | /* The other errors happen in btusb_mtk_func_query */ |
| 3819 | if (status < 0) |
| 3820 | return status; |
| 3821 | |
| 3822 | if (status == BTMTK_WMT_ON_DONE) { |
| 3823 | bt_dev_info(hdev, "function already on"); |
| 3824 | goto ignore_func_on; |
| 3825 | } |
| 3826 | |
| 3827 | /* Enable Bluetooth protocol */ |
| 3828 | param = 1; |
| 3829 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 3830 | wmt_params.flag = 0; |
| 3831 | wmt_params.dlen = sizeof(param); |
| 3832 | wmt_params.data = ¶m; |
| 3833 | wmt_params.status = NULL; |
| 3834 | |
| 3835 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3836 | if (err < 0) { |
| 3837 | bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
| 3838 | return err; |
| 3839 | } |
| 3840 | |
| 3841 | ignore_func_on: |
| 3842 | /* Apply the low power environment setup */ |
| 3843 | tci_sleep.mode = 0x5; |
| 3844 | tci_sleep.duration = cpu_to_le16(0x640); |
| 3845 | tci_sleep.host_duration = cpu_to_le16(0x640); |
| 3846 | tci_sleep.host_wakeup_pin = 0; |
| 3847 | tci_sleep.time_compensation = 0; |
| 3848 | |
| 3849 | skb = __hci_cmd_sync(hdev, 0xfc7a, sizeof(tci_sleep), &tci_sleep, |
| 3850 | HCI_INIT_TIMEOUT); |
| 3851 | if (IS_ERR(skb)) { |
| 3852 | err = PTR_ERR(skb); |
| 3853 | bt_dev_err(hdev, "Failed to apply low power setting (%d)", err); |
| 3854 | return err; |
| 3855 | } |
| 3856 | kfree_skb(skb); |
| 3857 | |
Mark Chen | fc342c4 | 2021-02-02 18:26:18 +0800 | [diff] [blame] | 3858 | done: |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3859 | rettime = ktime_get(); |
| 3860 | delta = ktime_sub(rettime, calltime); |
| 3861 | duration = (unsigned long long)ktime_to_ns(delta) >> 10; |
| 3862 | |
| 3863 | bt_dev_info(hdev, "Device setup in %llu usecs", duration); |
| 3864 | |
| 3865 | return 0; |
| 3866 | } |
| 3867 | |
| 3868 | static int btusb_mtk_shutdown(struct hci_dev *hdev) |
| 3869 | { |
| 3870 | struct btmtk_hci_wmt_params wmt_params; |
| 3871 | u8 param = 0; |
| 3872 | int err; |
| 3873 | |
| 3874 | /* Disable the device */ |
| 3875 | wmt_params.op = BTMTK_WMT_FUNC_CTRL; |
| 3876 | wmt_params.flag = 0; |
| 3877 | wmt_params.dlen = sizeof(param); |
| 3878 | wmt_params.data = ¶m; |
| 3879 | wmt_params.status = NULL; |
| 3880 | |
| 3881 | err = btusb_mtk_hci_wmt_sync(hdev, &wmt_params); |
| 3882 | if (err < 0) { |
| 3883 | bt_dev_err(hdev, "Failed to send wmt func ctrl (%d)", err); |
| 3884 | return err; |
| 3885 | } |
| 3886 | |
| 3887 | return 0; |
| 3888 | } |
| 3889 | |
Sean Wang | 9ce67c3 | 2019-06-02 08:02:49 +0800 | [diff] [blame] | 3890 | MODULE_FIRMWARE(FIRMWARE_MT7663); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3891 | MODULE_FIRMWARE(FIRMWARE_MT7668); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 3892 | |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 3893 | #ifdef CONFIG_PM |
| 3894 | /* Configure an out-of-band gpio as wake-up pin, if specified in device tree */ |
| 3895 | static int marvell_config_oob_wake(struct hci_dev *hdev) |
| 3896 | { |
| 3897 | struct sk_buff *skb; |
| 3898 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 3899 | struct device *dev = &data->udev->dev; |
| 3900 | u16 pin, gap, opcode; |
| 3901 | int ret; |
| 3902 | u8 cmd[5]; |
| 3903 | |
| 3904 | /* Move on if no wakeup pin specified */ |
| 3905 | if (of_property_read_u16(dev->of_node, "marvell,wakeup-pin", &pin) || |
| 3906 | of_property_read_u16(dev->of_node, "marvell,wakeup-gap-ms", &gap)) |
| 3907 | return 0; |
| 3908 | |
| 3909 | /* Vendor specific command to configure a GPIO as wake-up pin */ |
| 3910 | opcode = hci_opcode_pack(0x3F, 0x59); |
| 3911 | cmd[0] = opcode & 0xFF; |
| 3912 | cmd[1] = opcode >> 8; |
| 3913 | cmd[2] = 2; /* length of parameters that follow */ |
| 3914 | cmd[3] = pin; |
| 3915 | cmd[4] = gap; /* time in ms, for which wakeup pin should be asserted */ |
| 3916 | |
| 3917 | skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); |
| 3918 | if (!skb) { |
Joe Perches | d84fc2c | 2020-12-22 02:31:49 -0800 | [diff] [blame] | 3919 | bt_dev_err(hdev, "%s: No memory", __func__); |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 3920 | return -ENOMEM; |
| 3921 | } |
| 3922 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 3923 | skb_put_data(skb, cmd, sizeof(cmd)); |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 3924 | hci_skb_pkt_type(skb) = HCI_COMMAND_PKT; |
| 3925 | |
| 3926 | ret = btusb_send_frame(hdev, skb); |
| 3927 | if (ret) { |
Joe Perches | d84fc2c | 2020-12-22 02:31:49 -0800 | [diff] [blame] | 3928 | bt_dev_err(hdev, "%s: configuration failed", __func__); |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 3929 | kfree_skb(skb); |
| 3930 | return ret; |
| 3931 | } |
| 3932 | |
| 3933 | return 0; |
| 3934 | } |
| 3935 | #endif |
| 3936 | |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 3937 | static int btusb_set_bdaddr_marvell(struct hci_dev *hdev, |
| 3938 | const bdaddr_t *bdaddr) |
| 3939 | { |
| 3940 | struct sk_buff *skb; |
| 3941 | u8 buf[8]; |
| 3942 | long ret; |
| 3943 | |
| 3944 | buf[0] = 0xfe; |
| 3945 | buf[1] = sizeof(bdaddr_t); |
| 3946 | memcpy(buf + 2, bdaddr, sizeof(bdaddr_t)); |
| 3947 | |
| 3948 | skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT); |
| 3949 | if (IS_ERR(skb)) { |
| 3950 | ret = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3951 | bt_dev_err(hdev, "changing Marvell device address failed (%ld)", |
| 3952 | ret); |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 3953 | return ret; |
| 3954 | } |
| 3955 | kfree_skb(skb); |
| 3956 | |
| 3957 | return 0; |
| 3958 | } |
| 3959 | |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 3960 | static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev, |
| 3961 | const bdaddr_t *bdaddr) |
| 3962 | { |
| 3963 | struct sk_buff *skb; |
| 3964 | u8 buf[10]; |
| 3965 | long ret; |
| 3966 | |
| 3967 | buf[0] = 0x01; |
| 3968 | buf[1] = 0x01; |
| 3969 | buf[2] = 0x00; |
| 3970 | buf[3] = sizeof(bdaddr_t); |
| 3971 | memcpy(buf + 4, bdaddr, sizeof(bdaddr_t)); |
| 3972 | |
| 3973 | skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT); |
| 3974 | if (IS_ERR(skb)) { |
| 3975 | ret = PTR_ERR(skb); |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3976 | bt_dev_err(hdev, "Change address command failed (%ld)", ret); |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 3977 | return ret; |
| 3978 | } |
| 3979 | kfree_skb(skb); |
| 3980 | |
| 3981 | return 0; |
| 3982 | } |
| 3983 | |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 3984 | static int btusb_set_bdaddr_wcn6855(struct hci_dev *hdev, |
| 3985 | const bdaddr_t *bdaddr) |
| 3986 | { |
| 3987 | struct sk_buff *skb; |
| 3988 | u8 buf[6]; |
| 3989 | long ret; |
| 3990 | |
| 3991 | memcpy(buf, bdaddr, sizeof(bdaddr_t)); |
| 3992 | |
| 3993 | skb = __hci_cmd_sync_ev(hdev, 0xfc14, sizeof(buf), buf, |
| 3994 | HCI_EV_CMD_COMPLETE, HCI_INIT_TIMEOUT); |
| 3995 | if (IS_ERR(skb)) { |
| 3996 | ret = PTR_ERR(skb); |
| 3997 | bt_dev_err(hdev, "Change address command failed (%ld)", ret); |
| 3998 | return ret; |
| 3999 | } |
| 4000 | kfree_skb(skb); |
| 4001 | |
| 4002 | return 0; |
| 4003 | } |
| 4004 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4005 | #define QCA_DFU_PACKET_LEN 4096 |
| 4006 | |
| 4007 | #define QCA_GET_TARGET_VERSION 0x09 |
| 4008 | #define QCA_CHECK_STATUS 0x05 |
| 4009 | #define QCA_DFU_DOWNLOAD 0x01 |
| 4010 | |
| 4011 | #define QCA_SYSCFG_UPDATED 0x40 |
| 4012 | #define QCA_PATCH_UPDATED 0x80 |
| 4013 | #define QCA_DFU_TIMEOUT 3000 |
Tim Jiang | ef2862a | 2020-12-03 12:57:14 +0800 | [diff] [blame] | 4014 | #define QCA_FLAG_MULTI_NVM 0x80 |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4015 | |
| 4016 | struct qca_version { |
| 4017 | __le32 rom_version; |
| 4018 | __le32 patch_version; |
| 4019 | __le32 ram_version; |
Tim Jiang | ef2862a | 2020-12-03 12:57:14 +0800 | [diff] [blame] | 4020 | __le16 board_id; |
| 4021 | __le16 flag; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4022 | __u8 reserved[4]; |
| 4023 | } __packed; |
| 4024 | |
| 4025 | struct qca_rampatch_version { |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 4026 | __le16 rom_version_high; |
| 4027 | __le16 rom_version_low; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4028 | __le16 patch_version; |
| 4029 | } __packed; |
| 4030 | |
| 4031 | struct qca_device_info { |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 4032 | u32 rom_version; |
| 4033 | u8 rampatch_hdr; /* length of header in rampatch */ |
| 4034 | u8 nvm_hdr; /* length of header in NVM */ |
| 4035 | u8 ver_offset; /* offset of version structure in rampatch */ |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4036 | }; |
| 4037 | |
| 4038 | static const struct qca_device_info qca_devices_table[] = { |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 4039 | { 0x00000100, 20, 4, 8 }, /* Rome 1.0 */ |
| 4040 | { 0x00000101, 20, 4, 8 }, /* Rome 1.1 */ |
| 4041 | { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */ |
| 4042 | { 0x00000201, 28, 4, 16 }, /* Rome 2.1 */ |
| 4043 | { 0x00000300, 28, 4, 16 }, /* Rome 3.0 */ |
| 4044 | { 0x00000302, 28, 4, 16 }, /* Rome 3.2 */ |
| 4045 | { 0x00130100, 40, 4, 16 }, /* WCN6855 1.0 */ |
| 4046 | { 0x00130200, 40, 4, 16 }, /* WCN6855 2.0 */ |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4047 | }; |
| 4048 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4049 | 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] | 4050 | void *data, u16 size) |
| 4051 | { |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4052 | int pipe, err; |
| 4053 | u8 *buf; |
| 4054 | |
| 4055 | buf = kmalloc(size, GFP_KERNEL); |
| 4056 | if (!buf) |
| 4057 | return -ENOMEM; |
| 4058 | |
| 4059 | /* Found some of USB hosts have IOT issues with ours so that we should |
| 4060 | * not wait until HCI layer is ready. |
| 4061 | */ |
| 4062 | pipe = usb_rcvctrlpipe(udev, 0); |
| 4063 | err = usb_control_msg(udev, pipe, request, USB_TYPE_VENDOR | USB_DIR_IN, |
| 4064 | 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); |
| 4065 | if (err < 0) { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4066 | 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] | 4067 | goto done; |
| 4068 | } |
| 4069 | |
| 4070 | memcpy(data, buf, size); |
| 4071 | |
| 4072 | done: |
| 4073 | kfree(buf); |
| 4074 | |
| 4075 | return err; |
| 4076 | } |
| 4077 | |
| 4078 | static int btusb_setup_qca_download_fw(struct hci_dev *hdev, |
| 4079 | const struct firmware *firmware, |
| 4080 | size_t hdr_size) |
| 4081 | { |
| 4082 | struct btusb_data *btdata = hci_get_drvdata(hdev); |
| 4083 | struct usb_device *udev = btdata->udev; |
| 4084 | size_t count, size, sent = 0; |
| 4085 | int pipe, len, err; |
| 4086 | u8 *buf; |
| 4087 | |
| 4088 | buf = kmalloc(QCA_DFU_PACKET_LEN, GFP_KERNEL); |
| 4089 | if (!buf) |
| 4090 | return -ENOMEM; |
| 4091 | |
| 4092 | count = firmware->size; |
| 4093 | |
| 4094 | size = min_t(size_t, count, hdr_size); |
| 4095 | memcpy(buf, firmware->data, size); |
| 4096 | |
| 4097 | /* USB patches should go down to controller through USB path |
| 4098 | * because binary format fits to go down through USB channel. |
| 4099 | * USB control path is for patching headers and USB bulk is for |
| 4100 | * patch body. |
| 4101 | */ |
| 4102 | pipe = usb_sndctrlpipe(udev, 0); |
| 4103 | err = usb_control_msg(udev, pipe, QCA_DFU_DOWNLOAD, USB_TYPE_VENDOR, |
| 4104 | 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); |
| 4105 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4106 | bt_dev_err(hdev, "Failed to send headers (%d)", err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4107 | goto done; |
| 4108 | } |
| 4109 | |
| 4110 | sent += size; |
| 4111 | count -= size; |
| 4112 | |
Tim Jiang | 4f00bfb | 2021-06-01 17:57:10 +0800 | [diff] [blame] | 4113 | /* ep2 need time to switch from function acl to function dfu, |
| 4114 | * so we add 20ms delay here. |
| 4115 | */ |
| 4116 | msleep(20); |
| 4117 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4118 | while (count) { |
| 4119 | size = min_t(size_t, count, QCA_DFU_PACKET_LEN); |
| 4120 | |
| 4121 | memcpy(buf, firmware->data + sent, size); |
| 4122 | |
| 4123 | pipe = usb_sndbulkpipe(udev, 0x02); |
| 4124 | err = usb_bulk_msg(udev, pipe, buf, size, &len, |
| 4125 | QCA_DFU_TIMEOUT); |
| 4126 | if (err < 0) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4127 | bt_dev_err(hdev, "Failed to send body at %zd of %zd (%d)", |
| 4128 | sent, firmware->size, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4129 | break; |
| 4130 | } |
| 4131 | |
| 4132 | if (size != len) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4133 | bt_dev_err(hdev, "Failed to get bulk buffer"); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4134 | err = -EILSEQ; |
| 4135 | break; |
| 4136 | } |
| 4137 | |
| 4138 | sent += size; |
| 4139 | count -= size; |
| 4140 | } |
| 4141 | |
| 4142 | done: |
| 4143 | kfree(buf); |
| 4144 | return err; |
| 4145 | } |
| 4146 | |
| 4147 | static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev, |
| 4148 | struct qca_version *ver, |
| 4149 | const struct qca_device_info *info) |
| 4150 | { |
| 4151 | struct qca_rampatch_version *rver; |
| 4152 | const struct firmware *fw; |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 4153 | u32 ver_rom, ver_patch, rver_rom; |
| 4154 | u16 rver_rom_low, rver_rom_high, rver_patch; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4155 | char fwname[64]; |
| 4156 | int err; |
| 4157 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 4158 | ver_rom = le32_to_cpu(ver->rom_version); |
| 4159 | ver_patch = le32_to_cpu(ver->patch_version); |
| 4160 | |
| 4161 | 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] | 4162 | |
| 4163 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 4164 | if (err) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4165 | bt_dev_err(hdev, "failed to request rampatch file: %s (%d)", |
| 4166 | fwname, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4167 | return err; |
| 4168 | } |
| 4169 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4170 | bt_dev_info(hdev, "using rampatch file: %s", fwname); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4171 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 4172 | rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset); |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 4173 | rver_rom_low = le16_to_cpu(rver->rom_version_low); |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 4174 | rver_patch = le16_to_cpu(rver->patch_version); |
| 4175 | |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 4176 | if (ver_rom & ~0xffffU) { |
| 4177 | rver_rom_high = le16_to_cpu(rver->rom_version_high); |
| 4178 | rver_rom = le32_to_cpu(rver_rom_high << 16 | rver_rom_low); |
| 4179 | } else { |
| 4180 | rver_rom = rver_rom_low; |
| 4181 | } |
| 4182 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4183 | bt_dev_info(hdev, "QCA: patch rome 0x%x build 0x%x, " |
| 4184 | "firmware rome 0x%x build 0x%x", |
| 4185 | rver_rom, rver_patch, ver_rom, ver_patch); |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 4186 | |
| 4187 | if (rver_rom != ver_rom || rver_patch <= ver_patch) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4188 | 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] | 4189 | err = -EINVAL; |
| 4190 | goto done; |
| 4191 | } |
| 4192 | |
| 4193 | err = btusb_setup_qca_download_fw(hdev, fw, info->rampatch_hdr); |
| 4194 | |
| 4195 | done: |
| 4196 | release_firmware(fw); |
| 4197 | |
| 4198 | return err; |
| 4199 | } |
| 4200 | |
| 4201 | static int btusb_setup_qca_load_nvm(struct hci_dev *hdev, |
| 4202 | struct qca_version *ver, |
| 4203 | const struct qca_device_info *info) |
| 4204 | { |
| 4205 | const struct firmware *fw; |
| 4206 | char fwname[64]; |
| 4207 | int err; |
| 4208 | |
Tim Jiang | ef2862a | 2020-12-03 12:57:14 +0800 | [diff] [blame] | 4209 | if (((ver->flag >> 8) & 0xff) == QCA_FLAG_MULTI_NVM) { |
Tim Jiang | ca17a5c | 2021-06-01 17:57:25 +0800 | [diff] [blame] | 4210 | /* if boardid equal 0, use default nvm without surfix */ |
| 4211 | if (le16_to_cpu(ver->board_id) == 0x0) { |
| 4212 | snprintf(fwname, sizeof(fwname), "qca/nvm_usb_%08x.bin", |
| 4213 | le32_to_cpu(ver->rom_version)); |
| 4214 | } else { |
| 4215 | snprintf(fwname, sizeof(fwname), "qca/nvm_usb_%08x_%04x.bin", |
| 4216 | le32_to_cpu(ver->rom_version), |
| 4217 | le16_to_cpu(ver->board_id)); |
| 4218 | } |
Tim Jiang | ef2862a | 2020-12-03 12:57:14 +0800 | [diff] [blame] | 4219 | } else { |
| 4220 | snprintf(fwname, sizeof(fwname), "qca/nvm_usb_%08x.bin", |
| 4221 | le32_to_cpu(ver->rom_version)); |
| 4222 | } |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4223 | |
| 4224 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 4225 | if (err) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4226 | bt_dev_err(hdev, "failed to request NVM file: %s (%d)", |
| 4227 | fwname, err); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4228 | return err; |
| 4229 | } |
| 4230 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4231 | bt_dev_info(hdev, "using NVM file: %s", fwname); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4232 | |
| 4233 | err = btusb_setup_qca_download_fw(hdev, fw, info->nvm_hdr); |
| 4234 | |
| 4235 | release_firmware(fw); |
| 4236 | |
| 4237 | return err; |
| 4238 | } |
| 4239 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4240 | /* identify the ROM version and check whether patches are needed */ |
| 4241 | static bool btusb_qca_need_patch(struct usb_device *udev) |
| 4242 | { |
| 4243 | struct qca_version ver; |
| 4244 | |
| 4245 | if (btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, |
| 4246 | sizeof(ver)) < 0) |
| 4247 | return false; |
| 4248 | /* only low ROM versions need patches */ |
| 4249 | return !(le32_to_cpu(ver.rom_version) & ~0xffffU); |
| 4250 | } |
| 4251 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4252 | static int btusb_setup_qca(struct hci_dev *hdev) |
| 4253 | { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4254 | struct btusb_data *btdata = hci_get_drvdata(hdev); |
| 4255 | struct usb_device *udev = btdata->udev; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4256 | const struct qca_device_info *info = NULL; |
| 4257 | struct qca_version ver; |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 4258 | u32 ver_rom; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4259 | u8 status; |
| 4260 | int i, err; |
| 4261 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4262 | err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, |
Marcel Holtmann | eb50042 | 2015-04-16 23:15:50 +0200 | [diff] [blame] | 4263 | sizeof(ver)); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4264 | if (err < 0) |
| 4265 | return err; |
| 4266 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 4267 | ver_rom = le32_to_cpu(ver.rom_version); |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4268 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4269 | for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) { |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 4270 | if (ver_rom == qca_devices_table[i].rom_version) |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4271 | info = &qca_devices_table[i]; |
| 4272 | } |
| 4273 | if (!info) { |
Hui Wang | 234f414 | 2021-02-08 13:02:37 +0800 | [diff] [blame] | 4274 | /* If the rom_version is not matched in the qca_devices_table |
| 4275 | * and the high ROM version is not zero, we assume this chip no |
| 4276 | * need to load the rampatch and nvm. |
| 4277 | */ |
| 4278 | if (ver_rom & ~0xffffU) |
| 4279 | return 0; |
| 4280 | |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4281 | 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] | 4282 | return -ENODEV; |
| 4283 | } |
| 4284 | |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4285 | 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] | 4286 | sizeof(status)); |
| 4287 | if (err < 0) |
| 4288 | return err; |
| 4289 | |
| 4290 | if (!(status & QCA_PATCH_UPDATED)) { |
| 4291 | err = btusb_setup_qca_load_rampatch(hdev, &ver, info); |
| 4292 | if (err < 0) |
| 4293 | return err; |
| 4294 | } |
| 4295 | |
Tim Jiang | ef2862a | 2020-12-03 12:57:14 +0800 | [diff] [blame] | 4296 | err = btusb_qca_send_vendor_req(udev, QCA_GET_TARGET_VERSION, &ver, |
| 4297 | sizeof(ver)); |
| 4298 | if (err < 0) |
| 4299 | return err; |
| 4300 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4301 | if (!(status & QCA_SYSCFG_UPDATED)) { |
| 4302 | err = btusb_setup_qca_load_nvm(hdev, &ver, info); |
| 4303 | if (err < 0) |
| 4304 | return err; |
| 4305 | } |
| 4306 | |
| 4307 | return 0; |
| 4308 | } |
| 4309 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4310 | static inline int __set_diag_interface(struct hci_dev *hdev) |
| 4311 | { |
| 4312 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 4313 | struct usb_interface *intf = data->diag; |
| 4314 | int i; |
| 4315 | |
| 4316 | if (!data->diag) |
| 4317 | return -ENODEV; |
| 4318 | |
| 4319 | data->diag_tx_ep = NULL; |
| 4320 | data->diag_rx_ep = NULL; |
| 4321 | |
| 4322 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 4323 | struct usb_endpoint_descriptor *ep_desc; |
| 4324 | |
| 4325 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 4326 | |
| 4327 | if (!data->diag_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { |
| 4328 | data->diag_tx_ep = ep_desc; |
| 4329 | continue; |
| 4330 | } |
| 4331 | |
| 4332 | if (!data->diag_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { |
| 4333 | data->diag_rx_ep = ep_desc; |
| 4334 | continue; |
| 4335 | } |
| 4336 | } |
| 4337 | |
| 4338 | if (!data->diag_tx_ep || !data->diag_rx_ep) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4339 | bt_dev_err(hdev, "invalid diagnostic descriptors"); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4340 | return -ENODEV; |
| 4341 | } |
| 4342 | |
| 4343 | return 0; |
| 4344 | } |
| 4345 | |
| 4346 | static struct urb *alloc_diag_urb(struct hci_dev *hdev, bool enable) |
| 4347 | { |
| 4348 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 4349 | struct sk_buff *skb; |
| 4350 | struct urb *urb; |
| 4351 | unsigned int pipe; |
| 4352 | |
| 4353 | if (!data->diag_tx_ep) |
| 4354 | return ERR_PTR(-ENODEV); |
| 4355 | |
| 4356 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 4357 | if (!urb) |
| 4358 | return ERR_PTR(-ENOMEM); |
| 4359 | |
| 4360 | skb = bt_skb_alloc(2, GFP_KERNEL); |
| 4361 | if (!skb) { |
| 4362 | usb_free_urb(urb); |
| 4363 | return ERR_PTR(-ENOMEM); |
| 4364 | } |
| 4365 | |
Johannes Berg | 634fef6 | 2017-06-16 14:29:24 +0200 | [diff] [blame] | 4366 | skb_put_u8(skb, 0xf0); |
| 4367 | skb_put_u8(skb, enable); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4368 | |
| 4369 | pipe = usb_sndbulkpipe(data->udev, data->diag_tx_ep->bEndpointAddress); |
| 4370 | |
| 4371 | usb_fill_bulk_urb(urb, data->udev, pipe, |
| 4372 | skb->data, skb->len, btusb_tx_complete, skb); |
| 4373 | |
| 4374 | skb->dev = (void *)hdev; |
| 4375 | |
| 4376 | return urb; |
| 4377 | } |
| 4378 | |
| 4379 | static int btusb_bcm_set_diag(struct hci_dev *hdev, bool enable) |
| 4380 | { |
| 4381 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 4382 | struct urb *urb; |
| 4383 | |
| 4384 | if (!data->diag) |
| 4385 | return -ENODEV; |
| 4386 | |
| 4387 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 4388 | return -ENETDOWN; |
| 4389 | |
| 4390 | urb = alloc_diag_urb(hdev, enable); |
| 4391 | if (IS_ERR(urb)) |
| 4392 | return PTR_ERR(urb); |
| 4393 | |
| 4394 | return submit_or_queue_tx_urb(hdev, urb); |
| 4395 | } |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4396 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4397 | #ifdef CONFIG_PM |
| 4398 | static irqreturn_t btusb_oob_wake_handler(int irq, void *priv) |
| 4399 | { |
| 4400 | struct btusb_data *data = priv; |
| 4401 | |
| 4402 | pm_wakeup_event(&data->udev->dev, 0); |
Jeffy Chen | 017789f | 2017-02-24 14:24:29 +0800 | [diff] [blame] | 4403 | pm_system_wakeup(); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4404 | |
| 4405 | /* Disable only if not already disabled (keep it balanced) */ |
| 4406 | if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) { |
| 4407 | disable_irq_nosync(irq); |
| 4408 | disable_irq_wake(irq); |
| 4409 | } |
| 4410 | return IRQ_HANDLED; |
| 4411 | } |
| 4412 | |
| 4413 | static const struct of_device_id btusb_match_table[] = { |
| 4414 | { .compatible = "usb1286,204e" }, |
Brian Norris | 4c409af | 2019-02-22 14:53:43 -0800 | [diff] [blame] | 4415 | { .compatible = "usbcf3,e300" }, /* QCA6174A */ |
| 4416 | { .compatible = "usb4ca,301a" }, /* QCA6174A (Lite-On) */ |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4417 | { } |
| 4418 | }; |
| 4419 | MODULE_DEVICE_TABLE(of, btusb_match_table); |
| 4420 | |
| 4421 | /* Use an oob wakeup pin? */ |
| 4422 | static int btusb_config_oob_wake(struct hci_dev *hdev) |
| 4423 | { |
| 4424 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 4425 | struct device *dev = &data->udev->dev; |
| 4426 | int irq, ret; |
| 4427 | |
| 4428 | clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags); |
| 4429 | |
| 4430 | if (!of_match_device(btusb_match_table, dev)) |
| 4431 | return 0; |
| 4432 | |
| 4433 | /* Move on if no IRQ specified */ |
| 4434 | irq = of_irq_get_byname(dev->of_node, "wakeup"); |
| 4435 | if (irq <= 0) { |
| 4436 | bt_dev_dbg(hdev, "%s: no OOB Wakeup IRQ in DT", __func__); |
| 4437 | return 0; |
| 4438 | } |
| 4439 | |
Brian Norris | 771acc7 | 2019-04-09 11:49:17 -0700 | [diff] [blame] | 4440 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4441 | ret = devm_request_irq(&hdev->dev, irq, btusb_oob_wake_handler, |
| 4442 | 0, "OOB Wake-on-BT", data); |
| 4443 | if (ret) { |
| 4444 | bt_dev_err(hdev, "%s: IRQ request failed", __func__); |
| 4445 | return ret; |
| 4446 | } |
| 4447 | |
| 4448 | ret = device_init_wakeup(dev, true); |
| 4449 | if (ret) { |
| 4450 | bt_dev_err(hdev, "%s: failed to init_wakeup", __func__); |
| 4451 | return ret; |
| 4452 | } |
| 4453 | |
| 4454 | data->oob_wake_irq = irq; |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4455 | bt_dev_info(hdev, "OOB Wake-on-BT configured at IRQ %u", irq); |
| 4456 | return 0; |
| 4457 | } |
| 4458 | #endif |
| 4459 | |
Hans de Goede | fc54910 | 2018-04-27 11:26:43 +0200 | [diff] [blame] | 4460 | static void btusb_check_needs_reset_resume(struct usb_interface *intf) |
| 4461 | { |
| 4462 | if (dmi_check_system(btusb_needs_reset_resume_table)) |
| 4463 | interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; |
| 4464 | } |
| 4465 | |
Abhishek Pandit-Subedi | b7d0bf1 | 2020-05-12 19:19:27 -0700 | [diff] [blame] | 4466 | static bool btusb_prevent_wake(struct hci_dev *hdev) |
| 4467 | { |
| 4468 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 4469 | |
Abhishek Pandit-Subedi | 34a6865 | 2020-06-24 11:24:30 -0700 | [diff] [blame] | 4470 | if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) |
| 4471 | return true; |
| 4472 | |
Abhishek Pandit-Subedi | b7d0bf1 | 2020-05-12 19:19:27 -0700 | [diff] [blame] | 4473 | return !device_may_wakeup(&data->udev->dev); |
| 4474 | } |
| 4475 | |
Tim Jiang | 3b0d525 | 2020-12-18 18:12:11 +0800 | [diff] [blame] | 4476 | static int btusb_shutdown_qca(struct hci_dev *hdev) |
| 4477 | { |
| 4478 | struct sk_buff *skb; |
| 4479 | |
| 4480 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 4481 | if (IS_ERR(skb)) { |
| 4482 | bt_dev_err(hdev, "HCI reset during shutdown failed"); |
| 4483 | return PTR_ERR(skb); |
| 4484 | } |
| 4485 | kfree_skb(skb); |
| 4486 | |
| 4487 | return 0; |
| 4488 | } |
| 4489 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4490 | static int btusb_probe(struct usb_interface *intf, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 4491 | const struct usb_device_id *id) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4492 | { |
| 4493 | struct usb_endpoint_descriptor *ep_desc; |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 4494 | struct gpio_desc *reset_gpio; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4495 | struct btusb_data *data; |
| 4496 | struct hci_dev *hdev; |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 4497 | unsigned ifnum_base; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4498 | int i, err; |
| 4499 | |
| 4500 | BT_DBG("intf %p id %p", intf, id); |
| 4501 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4502 | /* interface numbers are hardcoded in the spec */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 4503 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) { |
| 4504 | if (!(id->driver_info & BTUSB_IFNUM_2)) |
| 4505 | return -ENODEV; |
| 4506 | if (intf->cur_altsetting->desc.bInterfaceNumber != 2) |
| 4507 | return -ENODEV; |
| 4508 | } |
| 4509 | |
| 4510 | ifnum_base = intf->cur_altsetting->desc.bInterfaceNumber; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4511 | |
| 4512 | if (!id->driver_info) { |
| 4513 | const struct usb_device_id *match; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 4514 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4515 | match = usb_match_id(intf, blacklist_table); |
| 4516 | if (match) |
| 4517 | id = match; |
| 4518 | } |
| 4519 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4520 | if (id->driver_info == BTUSB_IGNORE) |
| 4521 | return -ENODEV; |
| 4522 | |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 4523 | if (id->driver_info & BTUSB_ATH3012) { |
| 4524 | struct usb_device *udev = interface_to_usbdev(intf); |
| 4525 | |
| 4526 | /* Old firmware would otherwise let ath3k driver load |
Derek Robson | d98422c | 2017-07-22 13:47:07 +1200 | [diff] [blame] | 4527 | * patch and sysconfig files |
| 4528 | */ |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4529 | if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001 && |
| 4530 | !btusb_qca_need_patch(udev)) |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 4531 | return -ENODEV; |
| 4532 | } |
| 4533 | |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 4534 | data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4535 | if (!data) |
| 4536 | return -ENOMEM; |
| 4537 | |
| 4538 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 4539 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 4540 | |
| 4541 | if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) { |
| 4542 | data->intr_ep = ep_desc; |
| 4543 | continue; |
| 4544 | } |
| 4545 | |
| 4546 | if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { |
| 4547 | data->bulk_tx_ep = ep_desc; |
| 4548 | continue; |
| 4549 | } |
| 4550 | |
| 4551 | if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { |
| 4552 | data->bulk_rx_ep = ep_desc; |
| 4553 | continue; |
| 4554 | } |
| 4555 | } |
| 4556 | |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 4557 | if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4558 | return -ENODEV; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4559 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 4560 | if (id->driver_info & BTUSB_AMP) { |
| 4561 | data->cmdreq_type = USB_TYPE_CLASS | 0x01; |
| 4562 | data->cmdreq = 0x2b; |
| 4563 | } else { |
| 4564 | data->cmdreq_type = USB_TYPE_CLASS; |
| 4565 | data->cmdreq = 0x00; |
| 4566 | } |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 4567 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4568 | data->udev = interface_to_usbdev(intf); |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 4569 | data->intf = intf; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4570 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4571 | INIT_WORK(&data->work, btusb_work); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4572 | INIT_WORK(&data->waker, btusb_waker); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 4573 | init_usb_anchor(&data->deferred); |
| 4574 | init_usb_anchor(&data->tx_anchor); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4575 | spin_lock_init(&data->txlock); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4576 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4577 | init_usb_anchor(&data->intr_anchor); |
| 4578 | init_usb_anchor(&data->bulk_anchor); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 4579 | init_usb_anchor(&data->isoc_anchor); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4580 | init_usb_anchor(&data->diag_anchor); |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 4581 | init_usb_anchor(&data->ctrl_anchor); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 4582 | spin_lock_init(&data->rxlock); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4583 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 4584 | if (id->driver_info & BTUSB_INTEL_NEW) { |
| 4585 | data->recv_event = btusb_recv_event_intel; |
| 4586 | data->recv_bulk = btusb_recv_bulk_intel; |
| 4587 | set_bit(BTUSB_BOOTLOADER, &data->flags); |
| 4588 | } else { |
| 4589 | data->recv_event = hci_recv_frame; |
| 4590 | data->recv_bulk = btusb_recv_bulk; |
| 4591 | } |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 4592 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4593 | hdev = hci_alloc_dev(); |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 4594 | if (!hdev) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4595 | return -ENOMEM; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4596 | |
Marcel Holtmann | c13854c | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 4597 | hdev->bus = HCI_USB; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 4598 | hci_set_drvdata(hdev, data); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4599 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 4600 | if (id->driver_info & BTUSB_AMP) |
| 4601 | hdev->dev_type = HCI_AMP; |
| 4602 | else |
Marcel Holtmann | ca8bee5 | 2016-07-05 14:30:14 +0200 | [diff] [blame] | 4603 | hdev->dev_type = HCI_PRIMARY; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 4604 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4605 | data->hdev = hdev; |
| 4606 | |
| 4607 | SET_HCIDEV_DEV(hdev, &intf->dev); |
| 4608 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 4609 | reset_gpio = gpiod_get_optional(&data->udev->dev, "reset", |
| 4610 | GPIOD_OUT_LOW); |
| 4611 | if (IS_ERR(reset_gpio)) { |
| 4612 | err = PTR_ERR(reset_gpio); |
| 4613 | goto out_free_dev; |
| 4614 | } else if (reset_gpio) { |
| 4615 | data->reset_gpio = reset_gpio; |
| 4616 | } |
| 4617 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 4618 | hdev->open = btusb_open; |
| 4619 | hdev->close = btusb_close; |
| 4620 | hdev->flush = btusb_flush; |
| 4621 | hdev->send = btusb_send_frame; |
| 4622 | hdev->notify = btusb_notify; |
Abhishek Pandit-Subedi | b7d0bf1 | 2020-05-12 19:19:27 -0700 | [diff] [blame] | 4623 | hdev->prevent_wake = btusb_prevent_wake; |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 4624 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4625 | #ifdef CONFIG_PM |
| 4626 | err = btusb_config_oob_wake(hdev); |
| 4627 | if (err) |
| 4628 | goto out_free_dev; |
Rajat Jain | a4ccc9e | 2017-02-01 14:24:10 -0800 | [diff] [blame] | 4629 | |
| 4630 | /* Marvell devices may need a specific chip configuration */ |
| 4631 | if (id->driver_info & BTUSB_MARVELL && data->oob_wake_irq) { |
| 4632 | err = marvell_config_oob_wake(hdev); |
| 4633 | if (err) |
| 4634 | goto out_free_dev; |
| 4635 | } |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4636 | #endif |
Szymon Janc | 418678b | 2016-09-01 17:22:37 +0200 | [diff] [blame] | 4637 | if (id->driver_info & BTUSB_CW6622) |
| 4638 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
| 4639 | |
Marcel Holtmann | 6c9d435 | 2015-10-17 14:39:27 +0200 | [diff] [blame] | 4640 | if (id->driver_info & BTUSB_BCM2045) |
| 4641 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); |
| 4642 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 4643 | if (id->driver_info & BTUSB_BCM92035) |
| 4644 | hdev->setup = btusb_setup_bcm92035; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4645 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 4646 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && |
| 4647 | (id->driver_info & BTUSB_BCM_PATCHRAM)) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 4648 | hdev->manufacturer = 15; |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 4649 | hdev->setup = btbcm_setup_patchram; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4650 | hdev->set_diag = btusb_bcm_set_diag; |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 4651 | hdev->set_bdaddr = btbcm_set_bdaddr; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4652 | |
| 4653 | /* Broadcom LM_DIAG Interface numbers are hardcoded */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 4654 | data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); |
Marcel Holtmann | abbaf50 | 2014-07-02 00:53:48 +0200 | [diff] [blame] | 4655 | } |
Petri Gynther | 10d4c67 | 2014-05-08 15:50:01 -0700 | [diff] [blame] | 4656 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 4657 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && |
| 4658 | (id->driver_info & BTUSB_BCM_APPLE)) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 4659 | hdev->manufacturer = 15; |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 4660 | hdev->setup = btbcm_setup_apple; |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4661 | hdev->set_diag = btusb_bcm_set_diag; |
| 4662 | |
| 4663 | /* Broadcom LM_DIAG Interface numbers are hardcoded */ |
Marcel Holtmann | 22f8e9d | 2015-10-20 00:53:33 +0200 | [diff] [blame] | 4664 | data->diag = usb_ifnum_to_if(data->udev, ifnum_base + 2); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4665 | } |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 4666 | |
Marcel Holtmann | cb8d659 | 2014-07-02 11:25:25 +0200 | [diff] [blame] | 4667 | if (id->driver_info & BTUSB_INTEL) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 4668 | hdev->manufacturer = 2; |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 4669 | hdev->setup = btusb_setup_intel; |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 4670 | hdev->shutdown = btusb_shutdown_intel; |
Marcel Holtmann | 3e24767 | 2015-10-17 16:00:28 +0200 | [diff] [blame] | 4671 | hdev->set_diag = btintel_set_diag_mfg; |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 4672 | hdev->set_bdaddr = btintel_set_bdaddr; |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 4673 | hdev->cmd_timeout = btusb_intel_cmd_timeout; |
Jakub Pawlowski | c33fb9b | 2015-01-30 18:55:58 -0800 | [diff] [blame] | 4674 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
Jakub Pawlowski | c115484 | 2015-03-17 09:04:16 -0700 | [diff] [blame] | 4675 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Marcel Holtmann | 3e24767 | 2015-10-17 16:00:28 +0200 | [diff] [blame] | 4676 | set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); |
Marcel Holtmann | cb8d659 | 2014-07-02 11:25:25 +0200 | [diff] [blame] | 4677 | } |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 4678 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 4679 | if (id->driver_info & BTUSB_INTEL_NEW) { |
Marcel Holtmann | 49a5f78 | 2015-10-20 02:30:48 +0200 | [diff] [blame] | 4680 | hdev->manufacturer = 2; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 4681 | hdev->send = btusb_send_frame_intel; |
| 4682 | hdev->setup = btusb_setup_intel_new; |
Raghuram Hegde | 017a01c | 2019-01-29 17:54:48 +0530 | [diff] [blame] | 4683 | hdev->shutdown = btusb_shutdown_intel_new; |
Marcel Holtmann | eeb6abe | 2015-07-05 14:37:39 +0200 | [diff] [blame] | 4684 | hdev->hw_error = btintel_hw_error; |
Marcel Holtmann | 6d2e50d | 2015-10-09 14:42:08 +0200 | [diff] [blame] | 4685 | hdev->set_diag = btintel_set_diag; |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 4686 | hdev->set_bdaddr = btintel_set_bdaddr; |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 4687 | hdev->cmd_timeout = btusb_intel_cmd_timeout; |
Marcel Holtmann | b970c5b | 2015-02-01 23:57:18 -0800 | [diff] [blame] | 4688 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
Justin TerAvest | f778502 | 2018-09-25 11:04:57 -0600 | [diff] [blame] | 4689 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Marcel Holtmann | d8270fb | 2015-10-17 16:00:27 +0200 | [diff] [blame] | 4690 | set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 4691 | } |
| 4692 | |
Kiran K | 0a3c1d4 | 2020-11-19 17:09:40 +0530 | [diff] [blame] | 4693 | if (id->driver_info & BTUSB_INTEL_NEWGEN) { |
| 4694 | hdev->manufacturer = 2; |
| 4695 | hdev->send = btusb_send_frame_intel; |
| 4696 | hdev->setup = btusb_setup_intel_newgen; |
| 4697 | hdev->shutdown = btusb_shutdown_intel_new; |
| 4698 | hdev->hw_error = btintel_hw_error; |
| 4699 | hdev->set_diag = btintel_set_diag; |
| 4700 | hdev->set_bdaddr = btintel_set_bdaddr; |
| 4701 | hdev->cmd_timeout = btusb_intel_cmd_timeout; |
| 4702 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
| 4703 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
| 4704 | set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks); |
| 4705 | |
| 4706 | data->recv_event = btusb_recv_event_intel; |
| 4707 | data->recv_bulk = btusb_recv_bulk_intel; |
| 4708 | set_bit(BTUSB_BOOTLOADER, &data->flags); |
| 4709 | } |
| 4710 | |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 4711 | if (id->driver_info & BTUSB_MARVELL) |
| 4712 | hdev->set_bdaddr = btusb_set_bdaddr_marvell; |
| 4713 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 4714 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_MTK) && |
| 4715 | (id->driver_info & BTUSB_MEDIATEK)) { |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 4716 | hdev->setup = btusb_mtk_setup; |
| 4717 | hdev->shutdown = btusb_mtk_shutdown; |
| 4718 | hdev->manufacturer = 70; |
| 4719 | set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks); |
| 4720 | } |
Sean Wang | a1c49c43 | 2019-06-02 08:02:48 +0800 | [diff] [blame] | 4721 | |
Marcel Holtmann | 661cf88 | 2015-01-02 23:35:20 -0800 | [diff] [blame] | 4722 | if (id->driver_info & BTUSB_SWAVE) { |
| 4723 | set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks); |
Marcel Holtmann | d57dbe7 | 2014-12-26 04:42:33 +0100 | [diff] [blame] | 4724 | set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks); |
Marcel Holtmann | 661cf88 | 2015-01-02 23:35:20 -0800 | [diff] [blame] | 4725 | } |
Marcel Holtmann | d57dbe7 | 2014-12-26 04:42:33 +0100 | [diff] [blame] | 4726 | |
Marcel Holtmann | e4c534b | 2015-10-21 01:31:45 +0200 | [diff] [blame] | 4727 | if (id->driver_info & BTUSB_INTEL_BOOT) { |
| 4728 | hdev->manufacturer = 2; |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 4729 | set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); |
Marcel Holtmann | e4c534b | 2015-10-21 01:31:45 +0200 | [diff] [blame] | 4730 | } |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 4731 | |
Jakub Pawlowski | 79f0c87 | 2015-01-29 10:38:34 -0800 | [diff] [blame] | 4732 | if (id->driver_info & BTUSB_ATH3012) { |
Takashi Iwai | 803cdb8 | 2018-05-21 22:34:52 +0200 | [diff] [blame] | 4733 | data->setup_on_usb = btusb_setup_qca; |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 4734 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
Jakub Pawlowski | 3d50d51 | 2015-03-17 09:04:15 -0700 | [diff] [blame] | 4735 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Jakub Pawlowski | 79f0c87 | 2015-01-29 10:38:34 -0800 | [diff] [blame] | 4736 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
| 4737 | } |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 4738 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4739 | if (id->driver_info & BTUSB_QCA_ROME) { |
| 4740 | data->setup_on_usb = btusb_setup_qca; |
| 4741 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
Abhishek Pandit-Subedi | 6933568 | 2020-06-24 11:11:44 -0700 | [diff] [blame] | 4742 | hdev->cmd_timeout = btusb_qca_cmd_timeout; |
Vic Wei | 96e58d3 | 2018-03-28 08:28:47 -0700 | [diff] [blame] | 4743 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Hans de Goede | fc54910 | 2018-04-27 11:26:43 +0200 | [diff] [blame] | 4744 | btusb_check_needs_reset_resume(intf); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 4745 | } |
| 4746 | |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 4747 | if (id->driver_info & BTUSB_QCA_WCN6855) { |
| 4748 | data->setup_on_usb = btusb_setup_qca; |
Tim Jiang | 3b0d525 | 2020-12-18 18:12:11 +0800 | [diff] [blame] | 4749 | hdev->shutdown = btusb_shutdown_qca; |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 4750 | hdev->set_bdaddr = btusb_set_bdaddr_wcn6855; |
| 4751 | hdev->cmd_timeout = btusb_qca_cmd_timeout; |
| 4752 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Michael Sun | cbe6a04 | 2021-07-29 10:10:59 -0700 | [diff] [blame] | 4753 | hci_set_msft_opcode(hdev, 0xFD70); |
Rocky Liao | b40f58b | 2020-09-29 12:23:51 +0800 | [diff] [blame] | 4754 | } |
| 4755 | |
Hilda Wu | 461f95f | 2020-06-30 21:09:40 +0800 | [diff] [blame] | 4756 | if (id->driver_info & BTUSB_AMP) { |
| 4757 | /* AMP controllers do not support SCO packets */ |
| 4758 | data->isoc = NULL; |
| 4759 | } else { |
| 4760 | /* Interface orders are hardcoded in the specification */ |
| 4761 | data->isoc = usb_ifnum_to_if(data->udev, ifnum_base + 1); |
| 4762 | data->isoc_ifnum = ifnum_base + 1; |
| 4763 | } |
| 4764 | |
Arnd Bergmann | 42d2209 | 2019-09-18 21:59:02 +0200 | [diff] [blame] | 4765 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_RTL) && |
| 4766 | (id->driver_info & BTUSB_REALTEK)) { |
Carlo Caione | db33c77 | 2015-05-14 10:49:09 +0200 | [diff] [blame] | 4767 | hdev->setup = btrtl_setup_realtek; |
Jian-Hong Pan | 7af3f558 | 2019-06-25 16:30:51 +0800 | [diff] [blame] | 4768 | hdev->shutdown = btrtl_shutdown_realtek; |
Alex Lu | d7ef0d1 | 2019-09-05 10:36:31 +0800 | [diff] [blame] | 4769 | hdev->cmd_timeout = btusb_rtl_cmd_timeout; |
Daniel Drake | 04b8c81 | 2015-05-21 08:23:50 -0600 | [diff] [blame] | 4770 | |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 4771 | /* Realtek devices lose their updated firmware over global |
| 4772 | * suspend that means host doesn't send SET_FEATURE |
| 4773 | * (DEVICE_REMOTE_WAKEUP) |
Daniel Drake | 04b8c81 | 2015-05-21 08:23:50 -0600 | [diff] [blame] | 4774 | */ |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 4775 | set_bit(BTUSB_WAKEUP_DISABLE, &data->flags); |
Daniel Drake | 04b8c81 | 2015-05-21 08:23:50 -0600 | [diff] [blame] | 4776 | } |
Daniel Drake | a2698a9 | 2015-04-16 14:09:55 -0600 | [diff] [blame] | 4777 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 4778 | if (!reset) |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 4779 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4780 | |
| 4781 | if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { |
| 4782 | if (!disable_scofix) |
| 4783 | set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks); |
| 4784 | } |
| 4785 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 4786 | if (id->driver_info & BTUSB_BROKEN_ISOC) |
| 4787 | data->isoc = NULL; |
| 4788 | |
Alain Michaud | 4b127bd | 2020-02-27 18:29:39 +0000 | [diff] [blame] | 4789 | if (id->driver_info & BTUSB_WIDEBAND_SPEECH) |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 4790 | set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks); |
Alain Michaud | 4b127bd | 2020-02-27 18:29:39 +0000 | [diff] [blame] | 4791 | |
Alain Michaud | aff8c48 | 2020-04-23 14:43:31 +0000 | [diff] [blame] | 4792 | if (id->driver_info & BTUSB_VALID_LE_STATES) |
| 4793 | set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks); |
| 4794 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 4795 | if (id->driver_info & BTUSB_DIGIANSWER) { |
| 4796 | data->cmdreq_type = USB_TYPE_VENDOR; |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 4797 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | if (id->driver_info & BTUSB_CSR) { |
| 4801 | struct usb_device *udev = data->udev; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 4802 | u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 4803 | |
| 4804 | /* Old firmware would otherwise execute USB reset */ |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 4805 | if (bcdDevice < 0x117) |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 4806 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 4807 | |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 4808 | /* This must be set first in case we disable it for fakes */ |
Jakub Pawlowski | 49c989a | 2015-03-17 09:04:17 -0700 | [diff] [blame] | 4809 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Ismael Ferreras Morezuelas | cde1a8a | 2020-07-26 23:12:28 +0200 | [diff] [blame] | 4810 | |
| 4811 | /* Fake CSR devices with broken commands */ |
| 4812 | if (le16_to_cpu(udev->descriptor.idVendor) == 0x0a12 && |
| 4813 | le16_to_cpu(udev->descriptor.idProduct) == 0x0001) |
| 4814 | hdev->setup = btusb_setup_csr; |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 4815 | } |
| 4816 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4817 | if (id->driver_info & BTUSB_SNIFFER) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 4818 | struct usb_device *udev = data->udev; |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4819 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 4820 | /* New sniffer firmware has crippled HCI interface */ |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 4821 | if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) |
| 4822 | set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); |
| 4823 | } |
| 4824 | |
Marcel Holtmann | 3a5ef20 | 2014-07-06 14:53:54 +0200 | [diff] [blame] | 4825 | if (id->driver_info & BTUSB_INTEL_BOOT) { |
| 4826 | /* A bug in the bootloader causes that interrupt interface is |
| 4827 | * only enabled after receiving SetInterface(0, AltSetting=0). |
| 4828 | */ |
| 4829 | err = usb_set_interface(data->udev, 0, 0); |
| 4830 | if (err < 0) { |
| 4831 | BT_ERR("failed to set interface 0, alt 0 %d", err); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4832 | goto out_free_dev; |
Marcel Holtmann | 3a5ef20 | 2014-07-06 14:53:54 +0200 | [diff] [blame] | 4833 | } |
| 4834 | } |
| 4835 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 4836 | if (data->isoc) { |
| 4837 | err = usb_driver_claim_interface(&btusb_driver, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 4838 | data->isoc, data); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4839 | if (err < 0) |
| 4840 | goto out_free_dev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 4841 | } |
| 4842 | |
Marcel Holtmann | c0a21a5 | 2019-09-27 08:48:58 +0200 | [diff] [blame] | 4843 | if (IS_ENABLED(CONFIG_BT_HCIBTUSB_BCM) && data->diag) { |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4844 | if (!usb_driver_claim_interface(&btusb_driver, |
| 4845 | data->diag, data)) |
| 4846 | __set_diag_interface(hdev); |
| 4847 | else |
| 4848 | data->diag = NULL; |
| 4849 | } |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4850 | |
Hans de Goede | 8959152 | 2021-04-09 15:58:50 +0200 | [diff] [blame] | 4851 | if (enable_autosuspend) |
| 4852 | usb_enable_autosuspend(data->udev); |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 4853 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4854 | err = hci_register_dev(hdev); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4855 | if (err < 0) |
| 4856 | goto out_free_dev; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4857 | |
| 4858 | usb_set_intfdata(intf, data); |
| 4859 | |
| 4860 | return 0; |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4861 | |
| 4862 | out_free_dev: |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 4863 | if (data->reset_gpio) |
| 4864 | gpiod_put(data->reset_gpio); |
Rajat Jain | 10ab133 | 2017-02-01 14:24:08 -0800 | [diff] [blame] | 4865 | hci_free_dev(hdev); |
| 4866 | return err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | static void btusb_disconnect(struct usb_interface *intf) |
| 4870 | { |
| 4871 | struct btusb_data *data = usb_get_intfdata(intf); |
| 4872 | struct hci_dev *hdev; |
| 4873 | |
| 4874 | BT_DBG("intf %p", intf); |
| 4875 | |
| 4876 | if (!data) |
| 4877 | return; |
| 4878 | |
| 4879 | hdev = data->hdev; |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 4880 | usb_set_intfdata(data->intf, NULL); |
| 4881 | |
| 4882 | if (data->isoc) |
| 4883 | usb_set_intfdata(data->isoc, NULL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4884 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4885 | if (data->diag) |
| 4886 | usb_set_intfdata(data->diag, NULL); |
| 4887 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4888 | hci_unregister_dev(hdev); |
| 4889 | |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4890 | if (intf == data->intf) { |
| 4891 | if (data->isoc) |
| 4892 | usb_driver_release_interface(&btusb_driver, data->isoc); |
| 4893 | if (data->diag) |
| 4894 | usb_driver_release_interface(&btusb_driver, data->diag); |
| 4895 | } else if (intf == data->isoc) { |
| 4896 | if (data->diag) |
| 4897 | usb_driver_release_interface(&btusb_driver, data->diag); |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 4898 | usb_driver_release_interface(&btusb_driver, data->intf); |
Marcel Holtmann | 9d08f50 | 2015-10-08 20:23:08 +0200 | [diff] [blame] | 4899 | } else if (intf == data->diag) { |
| 4900 | usb_driver_release_interface(&btusb_driver, data->intf); |
| 4901 | if (data->isoc) |
| 4902 | usb_driver_release_interface(&btusb_driver, data->isoc); |
| 4903 | } |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 4904 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4905 | if (data->oob_wake_irq) |
| 4906 | device_init_wakeup(&data->udev->dev, false); |
| 4907 | |
Rajat Jain | dc786b2 | 2019-01-24 15:28:14 -0800 | [diff] [blame] | 4908 | if (data->reset_gpio) |
| 4909 | gpiod_put(data->reset_gpio); |
| 4910 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 4911 | hci_free_dev(hdev); |
| 4912 | } |
| 4913 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4914 | #ifdef CONFIG_PM |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4915 | static int btusb_suspend(struct usb_interface *intf, pm_message_t message) |
| 4916 | { |
| 4917 | struct btusb_data *data = usb_get_intfdata(intf); |
| 4918 | |
| 4919 | BT_DBG("intf %p", intf); |
| 4920 | |
| 4921 | if (data->suspend_count++) |
| 4922 | return 0; |
| 4923 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4924 | spin_lock_irq(&data->txlock); |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 4925 | if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) { |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4926 | set_bit(BTUSB_SUSPENDING, &data->flags); |
| 4927 | spin_unlock_irq(&data->txlock); |
| 4928 | } else { |
| 4929 | spin_unlock_irq(&data->txlock); |
| 4930 | data->suspend_count--; |
| 4931 | return -EBUSY; |
| 4932 | } |
| 4933 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4934 | cancel_work_sync(&data->work); |
| 4935 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4936 | btusb_stop_traffic(data); |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4937 | usb_kill_anchored_urbs(&data->tx_anchor); |
| 4938 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 4939 | if (data->oob_wake_irq && device_may_wakeup(&data->udev->dev)) { |
| 4940 | set_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags); |
| 4941 | enable_irq_wake(data->oob_wake_irq); |
| 4942 | enable_irq(data->oob_wake_irq); |
| 4943 | } |
| 4944 | |
Alex Lu | 9e45524 | 2019-08-14 20:02:52 +0800 | [diff] [blame] | 4945 | /* For global suspend, Realtek devices lose the loaded fw |
| 4946 | * in them. But for autosuspend, firmware should remain. |
| 4947 | * Actually, it depends on whether the usb host sends |
| 4948 | * set feature (enable wakeup) or not. |
| 4949 | */ |
| 4950 | if (test_bit(BTUSB_WAKEUP_DISABLE, &data->flags)) { |
| 4951 | if (PMSG_IS_AUTO(message) && |
| 4952 | device_can_wakeup(&data->udev->dev)) |
| 4953 | data->udev->do_remote_wakeup = 1; |
| 4954 | else if (!PMSG_IS_AUTO(message)) |
| 4955 | data->udev->reset_resume = 1; |
| 4956 | } |
| 4957 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4958 | return 0; |
| 4959 | } |
| 4960 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4961 | static void play_deferred(struct btusb_data *data) |
| 4962 | { |
| 4963 | struct urb *urb; |
| 4964 | int err; |
| 4965 | |
| 4966 | while ((urb = usb_get_from_anchor(&data->deferred))) { |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4967 | usb_anchor_urb(urb, &data->tx_anchor); |
| 4968 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4969 | err = usb_submit_urb(urb, GFP_ATOMIC); |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4970 | if (err < 0) { |
| 4971 | if (err != -EPERM && err != -ENODEV) |
| 4972 | BT_ERR("%s urb %p submission failed (%d)", |
| 4973 | data->hdev->name, urb, -err); |
| 4974 | kfree(urb->setup_packet); |
| 4975 | usb_unanchor_urb(urb); |
| 4976 | usb_free_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4977 | break; |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4978 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4979 | |
| 4980 | data->tx_in_flight++; |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4981 | usb_free_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4982 | } |
Jeffy Chen | 19cfe91 | 2017-07-20 18:53:50 +0800 | [diff] [blame] | 4983 | |
| 4984 | /* Cleanup the rest deferred urbs. */ |
| 4985 | while ((urb = usb_get_from_anchor(&data->deferred))) { |
| 4986 | kfree(urb->setup_packet); |
| 4987 | usb_free_urb(urb); |
| 4988 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4989 | } |
| 4990 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4991 | static int btusb_resume(struct usb_interface *intf) |
| 4992 | { |
| 4993 | struct btusb_data *data = usb_get_intfdata(intf); |
| 4994 | struct hci_dev *hdev = data->hdev; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 4995 | int err = 0; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 4996 | |
| 4997 | BT_DBG("intf %p", intf); |
| 4998 | |
| 4999 | if (--data->suspend_count) |
| 5000 | return 0; |
| 5001 | |
Rajat Jain | fd913ef | 2017-02-01 14:24:09 -0800 | [diff] [blame] | 5002 | /* Disable only if not already disabled (keep it balanced) */ |
| 5003 | if (test_and_clear_bit(BTUSB_OOB_WAKE_ENABLED, &data->flags)) { |
| 5004 | disable_irq(data->oob_wake_irq); |
| 5005 | disable_irq_wake(data->oob_wake_irq); |
| 5006 | } |
| 5007 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5008 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5009 | goto done; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5010 | |
| 5011 | if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) { |
| 5012 | err = btusb_submit_intr_urb(hdev, GFP_NOIO); |
| 5013 | if (err < 0) { |
| 5014 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5015 | goto failed; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) { |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 5020 | err = btusb_submit_bulk_urb(hdev, GFP_NOIO); |
| 5021 | if (err < 0) { |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5022 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5023 | goto failed; |
| 5024 | } |
| 5025 | |
| 5026 | btusb_submit_bulk_urb(hdev, GFP_NOIO); |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
| 5030 | if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0) |
| 5031 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 5032 | else |
| 5033 | btusb_submit_isoc_urb(hdev, GFP_NOIO); |
| 5034 | } |
| 5035 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5036 | spin_lock_irq(&data->txlock); |
| 5037 | play_deferred(data); |
| 5038 | clear_bit(BTUSB_SUSPENDING, &data->flags); |
| 5039 | spin_unlock_irq(&data->txlock); |
| 5040 | schedule_work(&data->work); |
| 5041 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5042 | return 0; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5043 | |
| 5044 | failed: |
| 5045 | usb_scuttle_anchored_urbs(&data->deferred); |
| 5046 | done: |
| 5047 | spin_lock_irq(&data->txlock); |
| 5048 | clear_bit(BTUSB_SUSPENDING, &data->flags); |
| 5049 | spin_unlock_irq(&data->txlock); |
| 5050 | |
| 5051 | return err; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5052 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5053 | #endif |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5054 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 5055 | static struct usb_driver btusb_driver = { |
| 5056 | .name = "btusb", |
| 5057 | .probe = btusb_probe, |
| 5058 | .disconnect = btusb_disconnect, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5059 | #ifdef CONFIG_PM |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 5060 | .suspend = btusb_suspend, |
| 5061 | .resume = btusb_resume, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5062 | #endif |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 5063 | .id_table = btusb_table, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 5064 | .supports_autosuspend = 1, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 5065 | .disable_hub_initiated_lpm = 1, |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 5066 | }; |
| 5067 | |
Greg Kroah-Hartman | 93f1508 | 2011-11-18 09:47:34 -0800 | [diff] [blame] | 5068 | module_usb_driver(btusb_driver); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 5069 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 5070 | module_param(disable_scofix, bool, 0644); |
| 5071 | MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size"); |
| 5072 | |
| 5073 | module_param(force_scofix, bool, 0644); |
| 5074 | MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size"); |
| 5075 | |
Hans de Goede | eff2d68 | 2017-11-13 14:44:16 +0100 | [diff] [blame] | 5076 | module_param(enable_autosuspend, bool, 0644); |
| 5077 | MODULE_PARM_DESC(enable_autosuspend, "Enable USB autosuspend by default"); |
| 5078 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 5079 | module_param(reset, bool, 0644); |
| 5080 | MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); |
| 5081 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 5082 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); |
| 5083 | MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION); |
| 5084 | MODULE_VERSION(VERSION); |
| 5085 | MODULE_LICENSE("GPL"); |