Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Generic Bluetooth USB driver |
| 4 | * |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 5 | * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 6 | * |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 24 | #include <linux/module.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 25 | #include <linux/usb.h> |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 26 | #include <linux/firmware.h> |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 27 | |
| 28 | #include <net/bluetooth/bluetooth.h> |
| 29 | #include <net/bluetooth/hci_core.h> |
| 30 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 31 | #include "btintel.h" |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 32 | #include "btbcm.h" |
| 33 | |
Marcel Holtmann | 34dced9b | 2015-04-05 22:52:16 -0700 | [diff] [blame] | 34 | #define VERSION "0.8" |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 35 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 36 | static bool disable_scofix; |
| 37 | static bool force_scofix; |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 38 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 39 | static bool reset = 1; |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 40 | |
| 41 | static struct usb_driver btusb_driver; |
| 42 | |
| 43 | #define BTUSB_IGNORE 0x01 |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 44 | #define BTUSB_DIGIANSWER 0x02 |
| 45 | #define BTUSB_CSR 0x04 |
| 46 | #define BTUSB_SNIFFER 0x08 |
| 47 | #define BTUSB_BCM92035 0x10 |
| 48 | #define BTUSB_BROKEN_ISOC 0x20 |
| 49 | #define BTUSB_WRONG_SCO_MTU 0x40 |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 50 | #define BTUSB_ATH3012 0x80 |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 51 | #define BTUSB_INTEL 0x100 |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 52 | #define BTUSB_INTEL_BOOT 0x200 |
| 53 | #define BTUSB_BCM_PATCHRAM 0x400 |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 54 | #define BTUSB_MARVELL 0x800 |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 55 | #define BTUSB_SWAVE 0x1000 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 56 | #define BTUSB_INTEL_NEW 0x2000 |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 57 | #define BTUSB_AMP 0x4000 |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 58 | #define BTUSB_QCA_ROME 0x8000 |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 59 | #define BTUSB_BCM_APPLE 0x10000 |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 60 | |
Marcel Holtmann | 5426520 | 2013-10-11 07:46:18 -0700 | [diff] [blame] | 61 | static const struct usb_device_id btusb_table[] = { |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 62 | /* Generic Bluetooth USB device */ |
| 63 | { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, |
| 64 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 65 | /* Generic Bluetooth AMP device */ |
| 66 | { USB_DEVICE_INFO(0xe0, 0x01, 0x04), .driver_info = BTUSB_AMP }, |
| 67 | |
Henrik Rydberg | 1fa6535 | 2012-08-25 19:28:06 +0200 | [diff] [blame] | 68 | /* Apple-specific (Broadcom) devices */ |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 69 | { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01), |
| 70 | .driver_info = BTUSB_BCM_APPLE }, |
Henrik Rydberg | 1fa6535 | 2012-08-25 19:28:06 +0200 | [diff] [blame] | 71 | |
Cho, Yu-Chen | 178c059 | 2013-06-04 21:40:26 +0800 | [diff] [blame] | 72 | /* MediaTek MT76x0E */ |
| 73 | { USB_DEVICE(0x0e8d, 0x763f) }, |
| 74 | |
Oliver Neukum | c510eae | 2011-09-21 11:41:45 +0200 | [diff] [blame] | 75 | /* Broadcom SoftSailing reporting vendor specific */ |
Don Zickus | 2e8b5063 | 2012-03-28 16:41:11 -0400 | [diff] [blame] | 76 | { USB_DEVICE(0x0a5c, 0x21e1) }, |
Oliver Neukum | c510eae | 2011-09-21 11:41:45 +0200 | [diff] [blame] | 77 | |
Nobuhiro Iwamatsu | 3cd0197 | 2010-08-20 16:24:07 +0900 | [diff] [blame] | 78 | /* Apple MacBookPro 7,1 */ |
| 79 | { USB_DEVICE(0x05ac, 0x8213) }, |
| 80 | |
Cyril Lacoux | 0a79f67 | 2010-07-14 10:29:27 +0400 | [diff] [blame] | 81 | /* Apple iMac11,1 */ |
| 82 | { USB_DEVICE(0x05ac, 0x8215) }, |
| 83 | |
Nobuhiro Iwamatsu | 9c04715 | 2010-08-20 16:24:06 +0900 | [diff] [blame] | 84 | /* Apple MacBookPro6,2 */ |
| 85 | { USB_DEVICE(0x05ac, 0x8218) }, |
| 86 | |
Edgar (gimli) Hucek | 3e3ede7 | 2010-11-04 08:04:33 +0100 | [diff] [blame] | 87 | /* Apple MacBookAir3,1, MacBookAir3,2 */ |
| 88 | { USB_DEVICE(0x05ac, 0x821b) }, |
| 89 | |
Pieter-Augustijn Van Malleghem | a63b723 | 2011-09-07 02:28:10 -0400 | [diff] [blame] | 90 | /* Apple MacBookAir4,1 */ |
| 91 | { USB_DEVICE(0x05ac, 0x821f) }, |
| 92 | |
Marc-Antoine Perennou | 88d377b | 2011-03-24 14:51:21 -0300 | [diff] [blame] | 93 | /* Apple MacBookPro8,2 */ |
| 94 | { USB_DEVICE(0x05ac, 0x821a) }, |
| 95 | |
Jurgen Kramer | f78b6826 | 2011-09-04 18:01:42 +0200 | [diff] [blame] | 96 | /* Apple MacMini5,1 */ |
| 97 | { USB_DEVICE(0x05ac, 0x8281) }, |
| 98 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 99 | /* AVM BlueFRITZ! USB v2.0 */ |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 100 | { USB_DEVICE(0x057c, 0x3800), .driver_info = BTUSB_SWAVE }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 101 | |
| 102 | /* Bluetooth Ultraport Module from IBM */ |
| 103 | { USB_DEVICE(0x04bf, 0x030a) }, |
| 104 | |
| 105 | /* ALPS Modules with non-standard id */ |
| 106 | { USB_DEVICE(0x044e, 0x3001) }, |
| 107 | { USB_DEVICE(0x044e, 0x3002) }, |
| 108 | |
| 109 | /* Ericsson with non-standard id */ |
| 110 | { USB_DEVICE(0x0bdb, 0x1002) }, |
| 111 | |
| 112 | /* Canyon CN-BTU1 with HID interfaces */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 113 | { USB_DEVICE(0x0c10, 0x0000) }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 114 | |
Wen-chien Jesse Sung | d13431c | 2011-11-08 14:30:22 +0800 | [diff] [blame] | 115 | /* Broadcom BCM20702A0 */ |
| 116 | { USB_DEVICE(0x413c, 0x8197) }, |
| 117 | |
Marcel Holtmann | d049f4e | 2015-01-26 20:35:32 -0800 | [diff] [blame] | 118 | /* Broadcom BCM20702B0 (Dynex/Insignia) */ |
| 119 | { USB_DEVICE(0x19ff, 0x0239), .driver_info = BTUSB_BCM_PATCHRAM }, |
| 120 | |
Steven Harms | 9851403 | 2012-04-13 14:45:55 -0400 | [diff] [blame] | 121 | /* Foxconn - Hon Hai */ |
Heinrich Siebmanns | 6029ddc | 2014-12-03 19:32:22 +0100 | [diff] [blame] | 122 | { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01), |
| 123 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Steven Harms | 9851403 | 2012-04-13 14:45:55 -0400 | [diff] [blame] | 124 | |
Matej Dubovy | 8f0c304 | 2015-02-02 18:50:14 +0100 | [diff] [blame] | 125 | /* Lite-On Technology - Broadcom based */ |
| 126 | { USB_VENDOR_AND_INTERFACE_INFO(0x04ca, 0xff, 0x01, 0x01), |
| 127 | .driver_info = BTUSB_BCM_PATCHRAM }, |
| 128 | |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 129 | /* Broadcom devices with vendor specific id */ |
Petri Gynther | 10d4c67 | 2014-05-08 15:50:01 -0700 | [diff] [blame] | 130 | { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01), |
| 131 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Gustavo Padovan | 92c385f | 2012-08-06 15:36:49 -0300 | [diff] [blame] | 132 | |
Marcel Holtmann | c2aef6e | 2014-07-21 14:02:33 +0200 | [diff] [blame] | 133 | /* ASUSTek Computer - Broadcom based */ |
Rick Dunn | 9a5abdaa | 2015-01-17 05:29:12 +0100 | [diff] [blame] | 134 | { USB_VENDOR_AND_INTERFACE_INFO(0x0b05, 0xff, 0x01, 0x01), |
| 135 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Marcel Holtmann | c2aef6e | 2014-07-21 14:02:33 +0200 | [diff] [blame] | 136 | |
Ken O'Brien | 5bcecf3 | 2013-09-21 19:14:43 +0100 | [diff] [blame] | 137 | /* Belkin F8065bf - Broadcom based */ |
Marcel Holtmann | 6331c68 | 2015-03-27 15:11:41 -0700 | [diff] [blame] | 138 | { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01), |
| 139 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Ken O'Brien | 5bcecf3 | 2013-09-21 19:14:43 +0100 | [diff] [blame] | 140 | |
Jurgen Kramer | 9113bfd | 2014-02-15 12:01:09 +0100 | [diff] [blame] | 141 | /* IMC Networks - Broadcom based */ |
Marcel Holtmann | 6331c68 | 2015-03-27 15:11:41 -0700 | [diff] [blame] | 142 | { USB_VENDOR_AND_INTERFACE_INFO(0x13d3, 0xff, 0x01, 0x01), |
| 143 | .driver_info = BTUSB_BCM_PATCHRAM }, |
Jurgen Kramer | 9113bfd | 2014-02-15 12:01:09 +0100 | [diff] [blame] | 144 | |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 145 | /* Intel Bluetooth USB Bootloader (RAM module) */ |
Marcel Holtmann | d92f2df | 2014-07-06 14:53:55 +0200 | [diff] [blame] | 146 | { USB_DEVICE(0x8087, 0x0a5a), |
| 147 | .driver_info = BTUSB_INTEL_BOOT | BTUSB_BROKEN_ISOC }, |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 148 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 149 | { } /* Terminating entry */ |
| 150 | }; |
| 151 | |
| 152 | MODULE_DEVICE_TABLE(usb, btusb_table); |
| 153 | |
Marcel Holtmann | 5426520 | 2013-10-11 07:46:18 -0700 | [diff] [blame] | 154 | static const struct usb_device_id blacklist_table[] = { |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 155 | /* CSR BlueCore devices */ |
| 156 | { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR }, |
| 157 | |
| 158 | /* Broadcom BCM2033 without firmware */ |
| 159 | { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE }, |
| 160 | |
Bala Shanmugam | be93112 | 2010-11-26 17:35:46 +0530 | [diff] [blame] | 161 | /* Atheros 3011 with sflash firmware */ |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 162 | { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE }, |
| 163 | { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE }, |
Alexander Ploumistos | 2eeff0b | 2015-02-13 21:05:11 +0200 | [diff] [blame] | 164 | { USB_DEVICE(0x04f2, 0xaff1), .driver_info = BTUSB_IGNORE }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 165 | { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE }, |
Bala Shanmugam | be93112 | 2010-11-26 17:35:46 +0530 | [diff] [blame] | 166 | { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE }, |
Marek Vasut | 6eda541 | 2012-06-08 14:32:50 +0200 | [diff] [blame] | 167 | { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE }, |
Andy Ross | 2a7bccc | 2011-05-09 16:11:16 -0700 | [diff] [blame] | 168 | { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE }, |
Bala Shanmugam | be93112 | 2010-11-26 17:35:46 +0530 | [diff] [blame] | 169 | |
Cho, Yu-Chen | 509e786 | 2011-01-26 17:10:59 +0800 | [diff] [blame] | 170 | /* Atheros AR9285 Malbec with sflash firmware */ |
| 171 | { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE }, |
| 172 | |
Bala Shanmugam | d9f51b5 | 2011-02-11 15:38:53 +0530 | [diff] [blame] | 173 | /* Atheros 3012 with sflash firmware */ |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 174 | { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 }, |
| 175 | { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 }, |
| 176 | { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 }, |
| 177 | { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 }, |
| 178 | { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 }, |
Anantha Krishnan | 4b552bc | 2014-10-06 16:31:49 +0530 | [diff] [blame] | 179 | { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 180 | { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 }, |
| 181 | { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 }, |
| 182 | { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 }, |
| 183 | { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 }, |
Mohammed Habibulla | 1fb4e09 | 2014-04-17 11:37:13 -0700 | [diff] [blame] | 184 | { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 185 | { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 }, |
| 186 | { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 }, |
Janne Heikkinen | 134d3b3 | 2014-12-09 07:44:51 +0200 | [diff] [blame] | 187 | { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 188 | { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 }, |
| 189 | { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 }, |
Vincent Zwanenburg | 89d2975 | 2014-08-08 12:33:56 +0100 | [diff] [blame] | 190 | { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | a735f9e | 2014-02-18 18:26:20 +0200 | [diff] [blame] | 191 | { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 }, |
Ming Lei | d66629c | 2013-03-15 11:00:39 +0800 | [diff] [blame] | 192 | { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 }, |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 193 | { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, |
Sunguk Lee | 94a32d10 | 2013-03-12 04:41:58 +0900 | [diff] [blame] | 194 | { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 }, |
Cho, Yu-Chen | 07c0ea8 | 2012-03-14 22:01:21 +0200 | [diff] [blame] | 195 | { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 }, |
Oliver Neukum | b131237 | 2014-01-16 15:37:11 +0100 | [diff] [blame] | 196 | { USB_DEVICE(0x0cf3, 0x311e), .driver_info = BTUSB_ATH3012 }, |
Oliver Neukum | 1e56f1e | 2014-01-16 16:02:58 +0100 | [diff] [blame] | 197 | { USB_DEVICE(0x0cf3, 0x311f), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 198 | { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 }, |
Ming Lei | ebaf579 | 2013-03-18 23:45:11 +0800 | [diff] [blame] | 199 | { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 200 | { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 }, |
AceLan Kao | ac71311 | 2012-04-19 14:53:45 +0800 | [diff] [blame] | 201 | { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 }, |
Peng Chen | 0a3658c | 2013-08-30 17:41:40 +0800 | [diff] [blame] | 202 | { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 203 | { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 }, |
| 204 | { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, |
AceLan Kao | eed307e | 2012-12-11 11:41:20 +0800 | [diff] [blame] | 205 | { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 }, |
Sujith Manoharan | 5b77a1f | 2013-07-15 09:29:03 +0530 | [diff] [blame] | 206 | { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 3bb30a7c | 2014-11-25 20:19:52 +0300 | [diff] [blame] | 207 | { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 }, |
Dmitry Tunin | 033efa9 | 2015-01-18 00:16:51 +0300 | [diff] [blame] | 208 | { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 }, |
Anantha Krishnan | fa2f139 | 2014-07-08 19:25:08 +0530 | [diff] [blame] | 209 | { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 }, |
Bala Shanmugam | d9f51b5 | 2011-02-11 15:38:53 +0530 | [diff] [blame] | 210 | |
Cho, Yu-Chen | e9036e3 | 2011-02-15 10:20:07 +0800 | [diff] [blame] | 211 | /* Atheros AR5BBU12 with sflash firmware */ |
| 212 | { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE }, |
| 213 | |
Michael Gruetzner | 85d5972 | 2012-05-02 22:33:40 +0200 | [diff] [blame] | 214 | /* Atheros AR5BBU12 with sflash firmware */ |
Yevgeniy Melnichuk | bc21fde | 2012-08-07 19:48:10 +0530 | [diff] [blame] | 215 | { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 216 | { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 }, |
Michael Gruetzner | 85d5972 | 2012-05-02 22:33:40 +0200 | [diff] [blame] | 217 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 218 | /* QCA ROME chipset */ |
Marcel Holtmann | c9e4447 | 2015-03-16 23:56:04 -0700 | [diff] [blame] | 219 | { USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME }, |
| 220 | { USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME }, |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 221 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 222 | /* Broadcom BCM2035 */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 223 | { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 }, |
Andy Shevchenko | 0b88006 | 2014-02-18 18:26:19 +0200 | [diff] [blame] | 224 | { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 225 | { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 226 | |
| 227 | /* Broadcom BCM2045 */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 228 | { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 229 | { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | bdbef3d | 2008-09-23 00:16:35 +0200 | [diff] [blame] | 230 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 231 | /* IBM/Lenovo ThinkPad with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 232 | { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 233 | { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 234 | |
| 235 | /* HP laptop with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 236 | { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 237 | |
| 238 | /* Dell laptop with Broadcom chip */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 239 | { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 240 | |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 241 | /* Dell Wireless 370 and 410 devices */ |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 242 | { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 243 | { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 244 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 245 | /* Belkin F8T012 and F8T013 devices */ |
| 246 | { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 247 | { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 248 | |
Marcel Holtmann | 5ddd4a6 | 2008-11-30 12:17:27 +0100 | [diff] [blame] | 249 | /* Asus WL-BTD202 device */ |
| 250 | { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 251 | |
| 252 | /* Kensington Bluetooth USB adapter */ |
| 253 | { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU }, |
| 254 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 255 | /* RTX Telecom based adapters with buggy SCO support */ |
| 256 | { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC }, |
| 257 | { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC }, |
| 258 | |
| 259 | /* CONWISE Technology based adapters with buggy SCO support */ |
| 260 | { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC }, |
| 261 | |
Marcel Holtmann | 4fcef8e | 2015-01-01 17:34:37 -0800 | [diff] [blame] | 262 | /* Roper Class 1 Bluetooth Dongle (Silicon Wave based) */ |
| 263 | { USB_DEVICE(0x1300, 0x0001), .driver_info = BTUSB_SWAVE }, |
| 264 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 265 | /* Digianswer devices */ |
| 266 | { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER }, |
| 267 | { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE }, |
| 268 | |
| 269 | /* CSR BlueCore Bluetooth Sniffer */ |
Marcel Holtmann | 4f64fa8 | 2014-07-07 00:12:04 +0200 | [diff] [blame] | 270 | { USB_DEVICE(0x0a12, 0x0002), |
| 271 | .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 272 | |
| 273 | /* Frontline ComProbe Bluetooth Sniffer */ |
Marcel Holtmann | 4f64fa8 | 2014-07-07 00:12:04 +0200 | [diff] [blame] | 274 | { USB_DEVICE(0x16d3, 0x0002), |
| 275 | .driver_info = BTUSB_SNIFFER | BTUSB_BROKEN_ISOC }, |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 276 | |
Marcel Holtmann | cb1ee89 | 2015-01-28 19:41:42 -0800 | [diff] [blame] | 277 | /* Marvell Bluetooth devices */ |
| 278 | { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL }, |
| 279 | { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL }, |
| 280 | |
Marcel Holtmann | d0ac9eb | 2015-01-28 19:41:43 -0800 | [diff] [blame] | 281 | /* Intel Bluetooth devices */ |
Marcel Holtmann | 407550f | 2015-02-22 15:41:18 -0800 | [diff] [blame] | 282 | { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 283 | { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL }, |
Tedd Ho-Jeong An | ef4e5e4 | 2013-11-12 13:10:58 -0800 | [diff] [blame] | 284 | { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL }, |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 285 | { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW }, |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 286 | |
Marcel Holtmann | d0ac9eb | 2015-01-28 19:41:43 -0800 | [diff] [blame] | 287 | /* Other Intel Bluetooth devices */ |
| 288 | { USB_VENDOR_AND_INTERFACE_INFO(0x8087, 0xe0, 0x01, 0x01), |
| 289 | .driver_info = BTUSB_IGNORE }, |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 290 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 291 | { } /* Terminating entry */ |
| 292 | }; |
| 293 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 294 | #define BTUSB_MAX_ISOC_FRAMES 10 |
| 295 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 296 | #define BTUSB_INTR_RUNNING 0 |
| 297 | #define BTUSB_BULK_RUNNING 1 |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 298 | #define BTUSB_ISOC_RUNNING 2 |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 299 | #define BTUSB_SUSPENDING 3 |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 300 | #define BTUSB_DID_ISO_RESUME 4 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 301 | #define BTUSB_BOOTLOADER 5 |
| 302 | #define BTUSB_DOWNLOADING 6 |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 303 | #define BTUSB_FIRMWARE_LOADED 7 |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 304 | #define BTUSB_FIRMWARE_FAILED 8 |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 305 | #define BTUSB_BOOTING 9 |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 306 | |
| 307 | struct btusb_data { |
| 308 | struct hci_dev *hdev; |
| 309 | struct usb_device *udev; |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 310 | struct usb_interface *intf; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 311 | struct usb_interface *isoc; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 312 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 313 | unsigned long flags; |
| 314 | |
| 315 | struct work_struct work; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 316 | struct work_struct waker; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 317 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 318 | struct usb_anchor deferred; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 319 | struct usb_anchor tx_anchor; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 320 | int tx_in_flight; |
| 321 | spinlock_t txlock; |
| 322 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 323 | struct usb_anchor intr_anchor; |
| 324 | struct usb_anchor bulk_anchor; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 325 | struct usb_anchor isoc_anchor; |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 326 | spinlock_t rxlock; |
| 327 | |
| 328 | struct sk_buff *evt_skb; |
| 329 | struct sk_buff *acl_skb; |
| 330 | struct sk_buff *sco_skb; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 331 | |
| 332 | struct usb_endpoint_descriptor *intr_ep; |
| 333 | struct usb_endpoint_descriptor *bulk_tx_ep; |
| 334 | struct usb_endpoint_descriptor *bulk_rx_ep; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 335 | struct usb_endpoint_descriptor *isoc_tx_ep; |
| 336 | struct usb_endpoint_descriptor *isoc_rx_ep; |
| 337 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 338 | __u8 cmdreq_type; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 339 | __u8 cmdreq; |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 340 | |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 341 | unsigned int sco_num; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 342 | int isoc_altsetting; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 343 | int suspend_count; |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 344 | |
Marcel Holtmann | 97307f5 | 2015-01-12 13:51:10 -0800 | [diff] [blame] | 345 | int (*recv_event)(struct hci_dev *hdev, struct sk_buff *skb); |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 346 | 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] | 347 | |
| 348 | int (*setup_on_usb)(struct hci_dev *hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 349 | }; |
| 350 | |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 351 | static inline void btusb_free_frags(struct btusb_data *data) |
| 352 | { |
| 353 | unsigned long flags; |
| 354 | |
| 355 | spin_lock_irqsave(&data->rxlock, flags); |
| 356 | |
| 357 | kfree_skb(data->evt_skb); |
| 358 | data->evt_skb = NULL; |
| 359 | |
| 360 | kfree_skb(data->acl_skb); |
| 361 | data->acl_skb = NULL; |
| 362 | |
| 363 | kfree_skb(data->sco_skb); |
| 364 | data->sco_skb = NULL; |
| 365 | |
| 366 | spin_unlock_irqrestore(&data->rxlock, flags); |
| 367 | } |
| 368 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 369 | static int btusb_recv_intr(struct btusb_data *data, void *buffer, int count) |
| 370 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 371 | struct sk_buff *skb; |
| 372 | int err = 0; |
| 373 | |
| 374 | spin_lock(&data->rxlock); |
| 375 | skb = data->evt_skb; |
| 376 | |
| 377 | while (count) { |
| 378 | int len; |
| 379 | |
| 380 | if (!skb) { |
| 381 | skb = bt_skb_alloc(HCI_MAX_EVENT_SIZE, GFP_ATOMIC); |
| 382 | if (!skb) { |
| 383 | err = -ENOMEM; |
| 384 | break; |
| 385 | } |
| 386 | |
| 387 | bt_cb(skb)->pkt_type = HCI_EVENT_PKT; |
| 388 | bt_cb(skb)->expect = HCI_EVENT_HDR_SIZE; |
| 389 | } |
| 390 | |
| 391 | len = min_t(uint, bt_cb(skb)->expect, count); |
| 392 | memcpy(skb_put(skb, len), buffer, len); |
| 393 | |
| 394 | count -= len; |
| 395 | buffer += len; |
| 396 | bt_cb(skb)->expect -= len; |
| 397 | |
| 398 | if (skb->len == HCI_EVENT_HDR_SIZE) { |
| 399 | /* Complete event header */ |
| 400 | bt_cb(skb)->expect = hci_event_hdr(skb)->plen; |
| 401 | |
| 402 | if (skb_tailroom(skb) < bt_cb(skb)->expect) { |
| 403 | kfree_skb(skb); |
| 404 | skb = NULL; |
| 405 | |
| 406 | err = -EILSEQ; |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | if (bt_cb(skb)->expect == 0) { |
| 412 | /* Complete frame */ |
Marcel Holtmann | 97307f5 | 2015-01-12 13:51:10 -0800 | [diff] [blame] | 413 | data->recv_event(data->hdev, skb); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 414 | skb = NULL; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | data->evt_skb = skb; |
| 419 | spin_unlock(&data->rxlock); |
| 420 | |
| 421 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static int btusb_recv_bulk(struct btusb_data *data, void *buffer, int count) |
| 425 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 426 | struct sk_buff *skb; |
| 427 | int err = 0; |
| 428 | |
| 429 | spin_lock(&data->rxlock); |
| 430 | skb = data->acl_skb; |
| 431 | |
| 432 | while (count) { |
| 433 | int len; |
| 434 | |
| 435 | if (!skb) { |
| 436 | skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); |
| 437 | if (!skb) { |
| 438 | err = -ENOMEM; |
| 439 | break; |
| 440 | } |
| 441 | |
| 442 | bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT; |
| 443 | bt_cb(skb)->expect = HCI_ACL_HDR_SIZE; |
| 444 | } |
| 445 | |
| 446 | len = min_t(uint, bt_cb(skb)->expect, count); |
| 447 | memcpy(skb_put(skb, len), buffer, len); |
| 448 | |
| 449 | count -= len; |
| 450 | buffer += len; |
| 451 | bt_cb(skb)->expect -= len; |
| 452 | |
| 453 | if (skb->len == HCI_ACL_HDR_SIZE) { |
| 454 | __le16 dlen = hci_acl_hdr(skb)->dlen; |
| 455 | |
| 456 | /* Complete ACL header */ |
| 457 | bt_cb(skb)->expect = __le16_to_cpu(dlen); |
| 458 | |
| 459 | if (skb_tailroom(skb) < bt_cb(skb)->expect) { |
| 460 | kfree_skb(skb); |
| 461 | skb = NULL; |
| 462 | |
| 463 | err = -EILSEQ; |
| 464 | break; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | if (bt_cb(skb)->expect == 0) { |
| 469 | /* Complete frame */ |
| 470 | hci_recv_frame(data->hdev, skb); |
| 471 | skb = NULL; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | data->acl_skb = skb; |
| 476 | spin_unlock(&data->rxlock); |
| 477 | |
| 478 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static int btusb_recv_isoc(struct btusb_data *data, void *buffer, int count) |
| 482 | { |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 483 | struct sk_buff *skb; |
| 484 | int err = 0; |
| 485 | |
| 486 | spin_lock(&data->rxlock); |
| 487 | skb = data->sco_skb; |
| 488 | |
| 489 | while (count) { |
| 490 | int len; |
| 491 | |
| 492 | if (!skb) { |
| 493 | skb = bt_skb_alloc(HCI_MAX_SCO_SIZE, GFP_ATOMIC); |
| 494 | if (!skb) { |
| 495 | err = -ENOMEM; |
| 496 | break; |
| 497 | } |
| 498 | |
| 499 | bt_cb(skb)->pkt_type = HCI_SCODATA_PKT; |
| 500 | bt_cb(skb)->expect = HCI_SCO_HDR_SIZE; |
| 501 | } |
| 502 | |
| 503 | len = min_t(uint, bt_cb(skb)->expect, count); |
| 504 | memcpy(skb_put(skb, len), buffer, len); |
| 505 | |
| 506 | count -= len; |
| 507 | buffer += len; |
| 508 | bt_cb(skb)->expect -= len; |
| 509 | |
| 510 | if (skb->len == HCI_SCO_HDR_SIZE) { |
| 511 | /* Complete SCO header */ |
| 512 | bt_cb(skb)->expect = hci_sco_hdr(skb)->dlen; |
| 513 | |
| 514 | if (skb_tailroom(skb) < bt_cb(skb)->expect) { |
| 515 | kfree_skb(skb); |
| 516 | skb = NULL; |
| 517 | |
| 518 | err = -EILSEQ; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | if (bt_cb(skb)->expect == 0) { |
| 524 | /* Complete frame */ |
| 525 | hci_recv_frame(data->hdev, skb); |
| 526 | skb = NULL; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | data->sco_skb = skb; |
| 531 | spin_unlock(&data->rxlock); |
| 532 | |
| 533 | return err; |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 534 | } |
| 535 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 536 | static void btusb_intr_complete(struct urb *urb) |
| 537 | { |
| 538 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 539 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 540 | int err; |
| 541 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 542 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 543 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 544 | |
| 545 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 546 | return; |
| 547 | |
| 548 | if (urb->status == 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 549 | hdev->stat.byte_rx += urb->actual_length; |
| 550 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 551 | if (btusb_recv_intr(data, urb->transfer_buffer, |
| 552 | urb->actual_length) < 0) { |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 553 | BT_ERR("%s corrupted event packet", hdev->name); |
| 554 | hdev->stat.err_rx++; |
| 555 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 556 | } else if (urb->status == -ENOENT) { |
| 557 | /* Avoid suspend failed when usb_kill_urb */ |
| 558 | return; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | if (!test_bit(BTUSB_INTR_RUNNING, &data->flags)) |
| 562 | return; |
| 563 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 564 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 565 | usb_anchor_urb(urb, &data->intr_anchor); |
| 566 | |
| 567 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 568 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 569 | /* -EPERM: urb is being killed; |
| 570 | * -ENODEV: device got disconnected */ |
| 571 | if (err != -EPERM && err != -ENODEV) |
Stefan Seyfried | 61faddf | 2010-11-30 21:49:08 +0100 | [diff] [blame] | 572 | BT_ERR("%s urb %p failed to resubmit (%d)", |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 573 | hdev->name, urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 574 | usb_unanchor_urb(urb); |
| 575 | } |
| 576 | } |
| 577 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 578 | 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] | 579 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 580 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 581 | struct urb *urb; |
| 582 | unsigned char *buf; |
| 583 | unsigned int pipe; |
| 584 | int err, size; |
| 585 | |
| 586 | BT_DBG("%s", hdev->name); |
| 587 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 588 | if (!data->intr_ep) |
| 589 | return -ENODEV; |
| 590 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 591 | urb = usb_alloc_urb(0, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 592 | if (!urb) |
| 593 | return -ENOMEM; |
| 594 | |
| 595 | size = le16_to_cpu(data->intr_ep->wMaxPacketSize); |
| 596 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 597 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 598 | if (!buf) { |
| 599 | usb_free_urb(urb); |
| 600 | return -ENOMEM; |
| 601 | } |
| 602 | |
| 603 | pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress); |
| 604 | |
| 605 | usb_fill_int_urb(urb, data->udev, pipe, buf, size, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 606 | btusb_intr_complete, hdev, data->intr_ep->bInterval); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 607 | |
| 608 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 609 | |
| 610 | usb_anchor_urb(urb, &data->intr_anchor); |
| 611 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 612 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 613 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 614 | if (err != -EPERM && err != -ENODEV) |
| 615 | BT_ERR("%s urb %p submission failed (%d)", |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 616 | hdev->name, urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 617 | usb_unanchor_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | usb_free_urb(urb); |
| 621 | |
| 622 | return err; |
| 623 | } |
| 624 | |
| 625 | static void btusb_bulk_complete(struct urb *urb) |
| 626 | { |
| 627 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 628 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 629 | int err; |
| 630 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 631 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 632 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 633 | |
| 634 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 635 | return; |
| 636 | |
| 637 | if (urb->status == 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 638 | hdev->stat.byte_rx += urb->actual_length; |
| 639 | |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 640 | if (data->recv_bulk(data, urb->transfer_buffer, |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 641 | urb->actual_length) < 0) { |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 642 | BT_ERR("%s corrupted ACL packet", hdev->name); |
| 643 | hdev->stat.err_rx++; |
| 644 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 645 | } else if (urb->status == -ENOENT) { |
| 646 | /* Avoid suspend failed when usb_kill_urb */ |
| 647 | return; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | if (!test_bit(BTUSB_BULK_RUNNING, &data->flags)) |
| 651 | return; |
| 652 | |
| 653 | usb_anchor_urb(urb, &data->bulk_anchor); |
Oliver Neukum | 652fd78 | 2009-12-16 19:23:43 +0100 | [diff] [blame] | 654 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 655 | |
| 656 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 657 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 658 | /* -EPERM: urb is being killed; |
| 659 | * -ENODEV: device got disconnected */ |
| 660 | if (err != -EPERM && err != -ENODEV) |
Stefan Seyfried | 61faddf | 2010-11-30 21:49:08 +0100 | [diff] [blame] | 661 | BT_ERR("%s urb %p failed to resubmit (%d)", |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 662 | hdev->name, urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 663 | usb_unanchor_urb(urb); |
| 664 | } |
| 665 | } |
| 666 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 667 | 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] | 668 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 669 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 670 | struct urb *urb; |
| 671 | unsigned char *buf; |
| 672 | unsigned int pipe; |
Vikram Kandukuri | 290ba20 | 2009-07-02 14:31:59 +0530 | [diff] [blame] | 673 | int err, size = HCI_MAX_FRAME_SIZE; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 674 | |
| 675 | BT_DBG("%s", hdev->name); |
| 676 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 677 | if (!data->bulk_rx_ep) |
| 678 | return -ENODEV; |
| 679 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 680 | urb = usb_alloc_urb(0, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 681 | if (!urb) |
| 682 | return -ENOMEM; |
| 683 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 684 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 685 | if (!buf) { |
| 686 | usb_free_urb(urb); |
| 687 | return -ENOMEM; |
| 688 | } |
| 689 | |
| 690 | pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress); |
| 691 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 692 | usb_fill_bulk_urb(urb, data->udev, pipe, buf, size, |
| 693 | btusb_bulk_complete, hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 694 | |
| 695 | urb->transfer_flags |= URB_FREE_BUFFER; |
| 696 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 697 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 698 | usb_anchor_urb(urb, &data->bulk_anchor); |
| 699 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 700 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 701 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 702 | if (err != -EPERM && err != -ENODEV) |
| 703 | BT_ERR("%s urb %p submission failed (%d)", |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 704 | hdev->name, urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 705 | usb_unanchor_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | usb_free_urb(urb); |
| 709 | |
| 710 | return err; |
| 711 | } |
| 712 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 713 | static void btusb_isoc_complete(struct urb *urb) |
| 714 | { |
| 715 | struct hci_dev *hdev = urb->context; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 716 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 717 | int i, err; |
| 718 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 719 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 720 | urb->actual_length); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 721 | |
| 722 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 723 | return; |
| 724 | |
| 725 | if (urb->status == 0) { |
| 726 | for (i = 0; i < urb->number_of_packets; i++) { |
| 727 | unsigned int offset = urb->iso_frame_desc[i].offset; |
| 728 | unsigned int length = urb->iso_frame_desc[i].actual_length; |
| 729 | |
| 730 | if (urb->iso_frame_desc[i].status) |
| 731 | continue; |
| 732 | |
| 733 | hdev->stat.byte_rx += length; |
| 734 | |
Marcel Holtmann | 1ffa4ad | 2014-09-16 05:33:33 +0200 | [diff] [blame] | 735 | if (btusb_recv_isoc(data, urb->transfer_buffer + offset, |
| 736 | length) < 0) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 737 | BT_ERR("%s corrupted SCO packet", hdev->name); |
| 738 | hdev->stat.err_rx++; |
| 739 | } |
| 740 | } |
Champion Chen | 85560c4 | 2014-09-06 14:06:08 -0500 | [diff] [blame] | 741 | } else if (urb->status == -ENOENT) { |
| 742 | /* Avoid suspend failed when usb_kill_urb */ |
| 743 | return; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags)) |
| 747 | return; |
| 748 | |
| 749 | usb_anchor_urb(urb, &data->isoc_anchor); |
| 750 | |
| 751 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 752 | if (err < 0) { |
Paul Bolle | 4935f1c | 2011-08-09 17:16:28 +0200 | [diff] [blame] | 753 | /* -EPERM: urb is being killed; |
| 754 | * -ENODEV: device got disconnected */ |
| 755 | if (err != -EPERM && err != -ENODEV) |
Stefan Seyfried | 61faddf | 2010-11-30 21:49:08 +0100 | [diff] [blame] | 756 | BT_ERR("%s urb %p failed to resubmit (%d)", |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 757 | hdev->name, urb, -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 758 | usb_unanchor_urb(urb); |
| 759 | } |
| 760 | } |
| 761 | |
Jesper Juhl | 42b16b3 | 2011-01-17 00:09:38 +0100 | [diff] [blame] | 762 | 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] | 763 | { |
| 764 | int i, offset = 0; |
| 765 | |
| 766 | BT_DBG("len %d mtu %d", len, mtu); |
| 767 | |
| 768 | for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu; |
| 769 | i++, offset += mtu, len -= mtu) { |
| 770 | urb->iso_frame_desc[i].offset = offset; |
| 771 | urb->iso_frame_desc[i].length = mtu; |
| 772 | } |
| 773 | |
| 774 | if (len && i < BTUSB_MAX_ISOC_FRAMES) { |
| 775 | urb->iso_frame_desc[i].offset = offset; |
| 776 | urb->iso_frame_desc[i].length = len; |
| 777 | i++; |
| 778 | } |
| 779 | |
| 780 | urb->number_of_packets = i; |
| 781 | } |
| 782 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 783 | 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] | 784 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 785 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 786 | struct urb *urb; |
| 787 | unsigned char *buf; |
| 788 | unsigned int pipe; |
| 789 | int err, size; |
| 790 | |
| 791 | BT_DBG("%s", hdev->name); |
| 792 | |
| 793 | if (!data->isoc_rx_ep) |
| 794 | return -ENODEV; |
| 795 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 796 | urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 797 | if (!urb) |
| 798 | return -ENOMEM; |
| 799 | |
| 800 | size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) * |
| 801 | BTUSB_MAX_ISOC_FRAMES; |
| 802 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 803 | buf = kmalloc(size, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 804 | if (!buf) { |
| 805 | usb_free_urb(urb); |
| 806 | return -ENOMEM; |
| 807 | } |
| 808 | |
| 809 | pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress); |
| 810 | |
Bing Zhao | fa0fb93 | 2011-12-20 18:19:00 -0800 | [diff] [blame] | 811 | 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] | 812 | hdev, data->isoc_rx_ep->bInterval); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 813 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 814 | urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 815 | |
| 816 | __fill_isoc_descriptor(urb, size, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 817 | le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize)); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 818 | |
| 819 | usb_anchor_urb(urb, &data->isoc_anchor); |
| 820 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 821 | err = usb_submit_urb(urb, mem_flags); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 822 | if (err < 0) { |
Paul Bolle | d4b8d1c | 2011-10-09 12:12:22 +0200 | [diff] [blame] | 823 | if (err != -EPERM && err != -ENODEV) |
| 824 | BT_ERR("%s urb %p submission failed (%d)", |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 825 | hdev->name, urb, -err); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 826 | usb_unanchor_urb(urb); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | usb_free_urb(urb); |
| 830 | |
| 831 | return err; |
| 832 | } |
| 833 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 834 | static void btusb_tx_complete(struct urb *urb) |
| 835 | { |
| 836 | struct sk_buff *skb = urb->context; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 837 | struct hci_dev *hdev = (struct hci_dev *)skb->dev; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 838 | struct btusb_data *data = hci_get_drvdata(hdev); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 839 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 840 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 841 | urb->actual_length); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 842 | |
| 843 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 844 | goto done; |
| 845 | |
| 846 | if (!urb->status) |
| 847 | hdev->stat.byte_tx += urb->transfer_buffer_length; |
| 848 | else |
| 849 | hdev->stat.err_tx++; |
| 850 | |
| 851 | done: |
| 852 | spin_lock(&data->txlock); |
| 853 | data->tx_in_flight--; |
| 854 | spin_unlock(&data->txlock); |
| 855 | |
| 856 | kfree(urb->setup_packet); |
| 857 | |
| 858 | kfree_skb(skb); |
| 859 | } |
| 860 | |
| 861 | static void btusb_isoc_tx_complete(struct urb *urb) |
| 862 | { |
| 863 | struct sk_buff *skb = urb->context; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 864 | struct hci_dev *hdev = (struct hci_dev *)skb->dev; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 865 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 866 | BT_DBG("%s urb %p status %d count %d", hdev->name, urb, urb->status, |
| 867 | urb->actual_length); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 868 | |
| 869 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 870 | goto done; |
| 871 | |
| 872 | if (!urb->status) |
| 873 | hdev->stat.byte_tx += urb->transfer_buffer_length; |
| 874 | else |
| 875 | hdev->stat.err_tx++; |
| 876 | |
| 877 | done: |
| 878 | kfree(urb->setup_packet); |
| 879 | |
| 880 | kfree_skb(skb); |
| 881 | } |
| 882 | |
| 883 | static int btusb_open(struct hci_dev *hdev) |
| 884 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 885 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 886 | int err; |
| 887 | |
| 888 | BT_DBG("%s", hdev->name); |
| 889 | |
Kim, Ben Young Tae | ace3198 | 2015-02-15 23:06:14 +0000 | [diff] [blame] | 890 | /* Patching USB firmware files prior to starting any URBs of HCI path |
| 891 | * It is more safe to use USB bulk channel for downloading USB patch |
| 892 | */ |
| 893 | if (data->setup_on_usb) { |
| 894 | err = data->setup_on_usb(hdev); |
| 895 | if (err <0) |
| 896 | return err; |
| 897 | } |
| 898 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 899 | err = usb_autopm_get_interface(data->intf); |
| 900 | if (err < 0) |
| 901 | return err; |
| 902 | |
| 903 | data->intf->needs_remote_wakeup = 1; |
| 904 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 905 | if (test_and_set_bit(HCI_RUNNING, &hdev->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 906 | goto done; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 907 | |
| 908 | if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 909 | goto done; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 910 | |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 911 | err = btusb_submit_intr_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 912 | if (err < 0) |
| 913 | goto failed; |
| 914 | |
| 915 | err = btusb_submit_bulk_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 916 | if (err < 0) { |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 917 | usb_kill_anchored_urbs(&data->intr_anchor); |
| 918 | goto failed; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 921 | set_bit(BTUSB_BULK_RUNNING, &data->flags); |
| 922 | btusb_submit_bulk_urb(hdev, GFP_KERNEL); |
| 923 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 924 | done: |
| 925 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 926 | return 0; |
| 927 | |
| 928 | failed: |
| 929 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
| 930 | clear_bit(HCI_RUNNING, &hdev->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 931 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 932 | return err; |
| 933 | } |
| 934 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 935 | static void btusb_stop_traffic(struct btusb_data *data) |
| 936 | { |
| 937 | usb_kill_anchored_urbs(&data->intr_anchor); |
| 938 | usb_kill_anchored_urbs(&data->bulk_anchor); |
| 939 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 940 | } |
| 941 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 942 | static int btusb_close(struct hci_dev *hdev) |
| 943 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 944 | struct btusb_data *data = hci_get_drvdata(hdev); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 945 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 946 | |
| 947 | BT_DBG("%s", hdev->name); |
| 948 | |
| 949 | if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) |
| 950 | return 0; |
| 951 | |
Marcel Holtmann | e8c3c3d | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 952 | cancel_work_sync(&data->work); |
Linus Torvalds | 404291a | 2009-11-11 13:32:29 -0800 | [diff] [blame] | 953 | cancel_work_sync(&data->waker); |
Marcel Holtmann | e8c3c3d | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 954 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 955 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 956 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 957 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 958 | |
| 959 | btusb_stop_traffic(data); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 960 | btusb_free_frags(data); |
| 961 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 962 | err = usb_autopm_get_interface(data->intf); |
| 963 | if (err < 0) |
Oliver Neukum | 7b8e2c1 | 2009-11-13 14:26:23 +0100 | [diff] [blame] | 964 | goto failed; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 965 | |
| 966 | data->intf->needs_remote_wakeup = 0; |
| 967 | usb_autopm_put_interface(data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 968 | |
Oliver Neukum | 7b8e2c1 | 2009-11-13 14:26:23 +0100 | [diff] [blame] | 969 | failed: |
| 970 | usb_scuttle_anchored_urbs(&data->deferred); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 971 | return 0; |
| 972 | } |
| 973 | |
| 974 | static int btusb_flush(struct hci_dev *hdev) |
| 975 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 976 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 977 | |
| 978 | BT_DBG("%s", hdev->name); |
| 979 | |
| 980 | usb_kill_anchored_urbs(&data->tx_anchor); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 981 | btusb_free_frags(data); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 986 | 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] | 987 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 988 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 989 | struct usb_ctrlrequest *dr; |
| 990 | struct urb *urb; |
| 991 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 992 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 993 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 994 | if (!urb) |
| 995 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 996 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 997 | dr = kmalloc(sizeof(*dr), GFP_KERNEL); |
| 998 | if (!dr) { |
| 999 | usb_free_urb(urb); |
| 1000 | return ERR_PTR(-ENOMEM); |
| 1001 | } |
| 1002 | |
| 1003 | dr->bRequestType = data->cmdreq_type; |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 1004 | dr->bRequest = data->cmdreq; |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1005 | dr->wIndex = 0; |
| 1006 | dr->wValue = 0; |
| 1007 | dr->wLength = __cpu_to_le16(skb->len); |
| 1008 | |
| 1009 | pipe = usb_sndctrlpipe(data->udev, 0x00); |
| 1010 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1011 | usb_fill_control_urb(urb, data->udev, pipe, (void *)dr, |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1012 | skb->data, skb->len, btusb_tx_complete, skb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1013 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1014 | skb->dev = (void *)hdev; |
Marcel Holtmann | 7bd8f09 | 2013-10-11 06:19:18 -0700 | [diff] [blame] | 1015 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1016 | return urb; |
| 1017 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1018 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1019 | static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb) |
| 1020 | { |
| 1021 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1022 | struct urb *urb; |
| 1023 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1024 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1025 | if (!data->bulk_tx_ep) |
| 1026 | return ERR_PTR(-ENODEV); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1027 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1028 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1029 | if (!urb) |
| 1030 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1031 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1032 | pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1033 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1034 | usb_fill_bulk_urb(urb, data->udev, pipe, |
| 1035 | skb->data, skb->len, btusb_tx_complete, skb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1036 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1037 | skb->dev = (void *)hdev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1038 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1039 | return urb; |
| 1040 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1041 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1042 | static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb) |
| 1043 | { |
| 1044 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1045 | struct urb *urb; |
| 1046 | unsigned int pipe; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1047 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1048 | if (!data->isoc_tx_ep) |
| 1049 | return ERR_PTR(-ENODEV); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1050 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1051 | urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL); |
| 1052 | if (!urb) |
| 1053 | return ERR_PTR(-ENOMEM); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1054 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1055 | pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1056 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1057 | usb_fill_int_urb(urb, data->udev, pipe, |
| 1058 | skb->data, skb->len, btusb_isoc_tx_complete, |
| 1059 | skb, data->isoc_tx_ep->bInterval); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1060 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1061 | urb->transfer_flags = URB_ISO_ASAP; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1062 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1063 | __fill_isoc_descriptor(urb, skb->len, |
| 1064 | le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize)); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1065 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1066 | skb->dev = (void *)hdev; |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1067 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1068 | return urb; |
| 1069 | } |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1070 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1071 | static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb) |
| 1072 | { |
| 1073 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1074 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1075 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1076 | usb_anchor_urb(urb, &data->tx_anchor); |
| 1077 | |
Johan Hedberg | e9753ef | 2014-09-14 08:49:34 +0300 | [diff] [blame] | 1078 | err = usb_submit_urb(urb, GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1079 | if (err < 0) { |
Paul Bolle | 5a9b80e | 2011-10-09 12:12:16 +0200 | [diff] [blame] | 1080 | if (err != -EPERM && err != -ENODEV) |
| 1081 | BT_ERR("%s urb %p submission failed (%d)", |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1082 | hdev->name, urb, -err); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1083 | kfree(urb->setup_packet); |
| 1084 | usb_unanchor_urb(urb); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1085 | } else { |
| 1086 | usb_mark_last_busy(data->udev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1087 | } |
| 1088 | |
Cong Wang | 54a8a79 | 2011-11-22 09:32:57 +0800 | [diff] [blame] | 1089 | usb_free_urb(urb); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1090 | return err; |
| 1091 | } |
| 1092 | |
Marcel Holtmann | 047b2ec | 2014-09-14 09:11:06 +0200 | [diff] [blame] | 1093 | static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb) |
| 1094 | { |
| 1095 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1096 | unsigned long flags; |
| 1097 | bool suspending; |
| 1098 | |
| 1099 | spin_lock_irqsave(&data->txlock, flags); |
| 1100 | suspending = test_bit(BTUSB_SUSPENDING, &data->flags); |
| 1101 | if (!suspending) |
| 1102 | data->tx_in_flight++; |
| 1103 | spin_unlock_irqrestore(&data->txlock, flags); |
| 1104 | |
| 1105 | if (!suspending) |
| 1106 | return submit_tx_urb(hdev, urb); |
| 1107 | |
| 1108 | usb_anchor_urb(urb, &data->deferred); |
| 1109 | schedule_work(&data->waker); |
| 1110 | |
| 1111 | usb_free_urb(urb); |
| 1112 | return 0; |
| 1113 | } |
| 1114 | |
| 1115 | static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb) |
| 1116 | { |
| 1117 | struct urb *urb; |
| 1118 | |
| 1119 | BT_DBG("%s", hdev->name); |
| 1120 | |
| 1121 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1122 | return -EBUSY; |
| 1123 | |
| 1124 | switch (bt_cb(skb)->pkt_type) { |
| 1125 | case HCI_COMMAND_PKT: |
| 1126 | urb = alloc_ctrl_urb(hdev, skb); |
| 1127 | if (IS_ERR(urb)) |
| 1128 | return PTR_ERR(urb); |
| 1129 | |
| 1130 | hdev->stat.cmd_tx++; |
| 1131 | return submit_or_queue_tx_urb(hdev, urb); |
| 1132 | |
| 1133 | case HCI_ACLDATA_PKT: |
| 1134 | urb = alloc_bulk_urb(hdev, skb); |
| 1135 | if (IS_ERR(urb)) |
| 1136 | return PTR_ERR(urb); |
| 1137 | |
| 1138 | hdev->stat.acl_tx++; |
| 1139 | return submit_or_queue_tx_urb(hdev, urb); |
| 1140 | |
| 1141 | case HCI_SCODATA_PKT: |
| 1142 | if (hci_conn_num(hdev, SCO_LINK) < 1) |
| 1143 | return -ENODEV; |
| 1144 | |
| 1145 | urb = alloc_isoc_urb(hdev, skb); |
| 1146 | if (IS_ERR(urb)) |
| 1147 | return PTR_ERR(urb); |
| 1148 | |
| 1149 | hdev->stat.sco_tx++; |
| 1150 | return submit_tx_urb(hdev, urb); |
| 1151 | } |
| 1152 | |
| 1153 | return -EILSEQ; |
| 1154 | } |
| 1155 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1156 | static void btusb_notify(struct hci_dev *hdev, unsigned int evt) |
| 1157 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1158 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1159 | |
| 1160 | BT_DBG("%s evt %d", hdev->name, evt); |
| 1161 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1162 | if (hci_conn_num(hdev, SCO_LINK) != data->sco_num) { |
| 1163 | data->sco_num = hci_conn_num(hdev, SCO_LINK); |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 1164 | schedule_work(&data->work); |
Marcel Holtmann | a780efa | 2008-11-30 12:17:12 +0100 | [diff] [blame] | 1165 | } |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1166 | } |
| 1167 | |
Jesper Juhl | 42b16b3 | 2011-01-17 00:09:38 +0100 | [diff] [blame] | 1168 | static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting) |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1169 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 1170 | struct btusb_data *data = hci_get_drvdata(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1171 | struct usb_interface *intf = data->isoc; |
| 1172 | struct usb_endpoint_descriptor *ep_desc; |
| 1173 | int i, err; |
| 1174 | |
| 1175 | if (!data->isoc) |
| 1176 | return -ENODEV; |
| 1177 | |
| 1178 | err = usb_set_interface(data->udev, 1, altsetting); |
| 1179 | if (err < 0) { |
| 1180 | BT_ERR("%s setting interface failed (%d)", hdev->name, -err); |
| 1181 | return err; |
| 1182 | } |
| 1183 | |
| 1184 | data->isoc_altsetting = altsetting; |
| 1185 | |
| 1186 | data->isoc_tx_ep = NULL; |
| 1187 | data->isoc_rx_ep = NULL; |
| 1188 | |
| 1189 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 1190 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 1191 | |
| 1192 | if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) { |
| 1193 | data->isoc_tx_ep = ep_desc; |
| 1194 | continue; |
| 1195 | } |
| 1196 | |
| 1197 | if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) { |
| 1198 | data->isoc_rx_ep = ep_desc; |
| 1199 | continue; |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | if (!data->isoc_tx_ep || !data->isoc_rx_ep) { |
| 1204 | BT_ERR("%s invalid SCO descriptors", hdev->name); |
| 1205 | return -ENODEV; |
| 1206 | } |
| 1207 | |
| 1208 | return 0; |
| 1209 | } |
| 1210 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1211 | static void btusb_work(struct work_struct *work) |
| 1212 | { |
| 1213 | struct btusb_data *data = container_of(work, struct btusb_data, work); |
| 1214 | struct hci_dev *hdev = data->hdev; |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1215 | int new_alts; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1216 | int err; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1217 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1218 | if (data->sco_num > 0) { |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1219 | if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) { |
Oliver Neukum | 8efdd0c | 2011-02-11 13:00:06 +0100 | [diff] [blame] | 1220 | err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1221 | if (err < 0) { |
| 1222 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1223 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1224 | return; |
| 1225 | } |
| 1226 | |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1227 | set_bit(BTUSB_DID_ISO_RESUME, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1228 | } |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1229 | |
| 1230 | if (hdev->voice_setting & 0x0020) { |
| 1231 | static const int alts[3] = { 2, 4, 5 }; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1232 | |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1233 | new_alts = alts[data->sco_num - 1]; |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1234 | } else { |
Marcel Holtmann | 014f7bc | 2013-10-10 09:47:55 -0700 | [diff] [blame] | 1235 | new_alts = data->sco_num; |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | if (data->isoc_altsetting != new_alts) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1239 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1240 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1241 | |
Mikel Astiz | f4001d2 | 2012-04-11 08:48:51 +0200 | [diff] [blame] | 1242 | if (__set_isoc_interface(hdev, new_alts) < 0) |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1243 | return; |
| 1244 | } |
| 1245 | |
| 1246 | if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1247 | if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0) |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1248 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1249 | else |
Marcel Holtmann | 2eda66f | 2008-11-30 12:17:10 +0100 | [diff] [blame] | 1250 | btusb_submit_isoc_urb(hdev, GFP_KERNEL); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 1251 | } |
| 1252 | } else { |
| 1253 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 1254 | usb_kill_anchored_urbs(&data->isoc_anchor); |
| 1255 | |
| 1256 | __set_isoc_interface(hdev, 0); |
Gustavo F. Padovan | 08b8b6c | 2010-07-16 17:20:33 -0300 | [diff] [blame] | 1257 | if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags)) |
Oliver Neukum | 8efdd0c | 2011-02-11 13:00:06 +0100 | [diff] [blame] | 1258 | usb_autopm_put_interface(data->isoc ? data->isoc : data->intf); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 1262 | static void btusb_waker(struct work_struct *work) |
| 1263 | { |
| 1264 | struct btusb_data *data = container_of(work, struct btusb_data, waker); |
| 1265 | int err; |
| 1266 | |
| 1267 | err = usb_autopm_get_interface(data->intf); |
| 1268 | if (err < 0) |
| 1269 | return; |
| 1270 | |
| 1271 | usb_autopm_put_interface(data->intf); |
| 1272 | } |
| 1273 | |
Daniel Drake | 6576fe4 | 2015-02-23 18:16:47 -0600 | [diff] [blame] | 1274 | static struct sk_buff *btusb_read_local_version(struct hci_dev *hdev) |
| 1275 | { |
| 1276 | struct sk_buff *skb; |
| 1277 | |
| 1278 | skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL, |
| 1279 | HCI_INIT_TIMEOUT); |
| 1280 | if (IS_ERR(skb)) { |
| 1281 | BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)", |
| 1282 | hdev->name, PTR_ERR(skb)); |
| 1283 | return skb; |
| 1284 | } |
| 1285 | |
| 1286 | if (skb->len != sizeof(struct hci_rp_read_local_version)) { |
| 1287 | BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch", |
| 1288 | hdev->name); |
| 1289 | kfree_skb(skb); |
| 1290 | return ERR_PTR(-EIO); |
| 1291 | } |
| 1292 | |
| 1293 | return skb; |
| 1294 | } |
| 1295 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 1296 | static int btusb_setup_bcm92035(struct hci_dev *hdev) |
| 1297 | { |
| 1298 | struct sk_buff *skb; |
| 1299 | u8 val = 0x00; |
| 1300 | |
| 1301 | BT_DBG("%s", hdev->name); |
| 1302 | |
| 1303 | skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT); |
| 1304 | if (IS_ERR(skb)) |
| 1305 | BT_ERR("BCM92035 command failed (%ld)", -PTR_ERR(skb)); |
| 1306 | else |
| 1307 | kfree_skb(skb); |
| 1308 | |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1312 | static int btusb_setup_csr(struct hci_dev *hdev) |
| 1313 | { |
| 1314 | struct hci_rp_read_local_version *rp; |
| 1315 | struct sk_buff *skb; |
| 1316 | int ret; |
| 1317 | |
| 1318 | BT_DBG("%s", hdev->name); |
| 1319 | |
Daniel Drake | 6576fe4 | 2015-02-23 18:16:47 -0600 | [diff] [blame] | 1320 | skb = btusb_read_local_version(hdev); |
| 1321 | if (IS_ERR(skb)) |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1322 | return -PTR_ERR(skb); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1323 | |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1324 | rp = (struct hci_rp_read_local_version *)skb->data; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 1325 | |
| 1326 | if (!rp->status) { |
| 1327 | if (le16_to_cpu(rp->manufacturer) != 10) { |
| 1328 | /* Clear the reset quirk since this is not an actual |
| 1329 | * early Bluetooth 1.1 device from CSR. |
| 1330 | */ |
| 1331 | clear_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
| 1332 | |
| 1333 | /* These fake CSR controllers have all a broken |
| 1334 | * stored link key handling and so just disable it. |
| 1335 | */ |
| 1336 | set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, |
| 1337 | &hdev->quirks); |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | ret = -bt_to_errno(rp->status); |
| 1342 | |
| 1343 | kfree_skb(skb); |
| 1344 | |
| 1345 | return ret; |
| 1346 | } |
| 1347 | |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1348 | 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] | 1349 | struct intel_version *ver) |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1350 | { |
| 1351 | const struct firmware *fw; |
| 1352 | char fwname[64]; |
| 1353 | int ret; |
| 1354 | |
| 1355 | snprintf(fwname, sizeof(fwname), |
| 1356 | "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq", |
| 1357 | ver->hw_platform, ver->hw_variant, ver->hw_revision, |
| 1358 | ver->fw_variant, ver->fw_revision, ver->fw_build_num, |
| 1359 | ver->fw_build_ww, ver->fw_build_yy); |
| 1360 | |
| 1361 | ret = request_firmware(&fw, fwname, &hdev->dev); |
| 1362 | if (ret < 0) { |
| 1363 | if (ret == -EINVAL) { |
| 1364 | BT_ERR("%s Intel firmware file request failed (%d)", |
| 1365 | hdev->name, ret); |
| 1366 | return NULL; |
| 1367 | } |
| 1368 | |
| 1369 | BT_ERR("%s failed to open Intel firmware file: %s(%d)", |
| 1370 | hdev->name, fwname, ret); |
| 1371 | |
| 1372 | /* If the correct firmware patch file is not found, use the |
| 1373 | * default firmware patch file instead |
| 1374 | */ |
| 1375 | snprintf(fwname, sizeof(fwname), "intel/ibt-hw-%x.%x.bseq", |
| 1376 | ver->hw_platform, ver->hw_variant); |
| 1377 | if (request_firmware(&fw, fwname, &hdev->dev) < 0) { |
| 1378 | BT_ERR("%s failed to open default Intel fw file: %s", |
| 1379 | hdev->name, fwname); |
| 1380 | return NULL; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | BT_INFO("%s: Intel Bluetooth firmware file: %s", hdev->name, fwname); |
| 1385 | |
| 1386 | return fw; |
| 1387 | } |
| 1388 | |
| 1389 | static int btusb_setup_intel_patching(struct hci_dev *hdev, |
| 1390 | const struct firmware *fw, |
| 1391 | const u8 **fw_ptr, int *disable_patch) |
| 1392 | { |
| 1393 | struct sk_buff *skb; |
| 1394 | struct hci_command_hdr *cmd; |
| 1395 | const u8 *cmd_param; |
| 1396 | struct hci_event_hdr *evt = NULL; |
| 1397 | const u8 *evt_param = NULL; |
| 1398 | int remain = fw->size - (*fw_ptr - fw->data); |
| 1399 | |
| 1400 | /* The first byte indicates the types of the patch command or event. |
| 1401 | * 0x01 means HCI command and 0x02 is HCI event. If the first bytes |
| 1402 | * in the current firmware buffer doesn't start with 0x01 or |
| 1403 | * the size of remain buffer is smaller than HCI command header, |
| 1404 | * the firmware file is corrupted and it should stop the patching |
| 1405 | * process. |
| 1406 | */ |
| 1407 | if (remain > HCI_COMMAND_HDR_SIZE && *fw_ptr[0] != 0x01) { |
| 1408 | BT_ERR("%s Intel fw corrupted: invalid cmd read", hdev->name); |
| 1409 | return -EINVAL; |
| 1410 | } |
| 1411 | (*fw_ptr)++; |
| 1412 | remain--; |
| 1413 | |
| 1414 | cmd = (struct hci_command_hdr *)(*fw_ptr); |
| 1415 | *fw_ptr += sizeof(*cmd); |
| 1416 | remain -= sizeof(*cmd); |
| 1417 | |
| 1418 | /* Ensure that the remain firmware data is long enough than the length |
| 1419 | * of command parameter. If not, the firmware file is corrupted. |
| 1420 | */ |
| 1421 | if (remain < cmd->plen) { |
| 1422 | BT_ERR("%s Intel fw corrupted: invalid cmd len", hdev->name); |
| 1423 | return -EFAULT; |
| 1424 | } |
| 1425 | |
| 1426 | /* If there is a command that loads a patch in the firmware |
| 1427 | * file, then enable the patch upon success, otherwise just |
| 1428 | * disable the manufacturer mode, for example patch activation |
| 1429 | * is not required when the default firmware patch file is used |
| 1430 | * because there are no patch data to load. |
| 1431 | */ |
| 1432 | if (*disable_patch && le16_to_cpu(cmd->opcode) == 0xfc8e) |
| 1433 | *disable_patch = 0; |
| 1434 | |
| 1435 | cmd_param = *fw_ptr; |
| 1436 | *fw_ptr += cmd->plen; |
| 1437 | remain -= cmd->plen; |
| 1438 | |
| 1439 | /* This reads the expected events when the above command is sent to the |
| 1440 | * device. Some vendor commands expects more than one events, for |
| 1441 | * example command status event followed by vendor specific event. |
| 1442 | * For this case, it only keeps the last expected event. so the command |
| 1443 | * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of |
| 1444 | * last expected event. |
| 1445 | */ |
| 1446 | while (remain > HCI_EVENT_HDR_SIZE && *fw_ptr[0] == 0x02) { |
| 1447 | (*fw_ptr)++; |
| 1448 | remain--; |
| 1449 | |
| 1450 | evt = (struct hci_event_hdr *)(*fw_ptr); |
| 1451 | *fw_ptr += sizeof(*evt); |
| 1452 | remain -= sizeof(*evt); |
| 1453 | |
| 1454 | if (remain < evt->plen) { |
| 1455 | BT_ERR("%s Intel fw corrupted: invalid evt len", |
| 1456 | hdev->name); |
| 1457 | return -EFAULT; |
| 1458 | } |
| 1459 | |
| 1460 | evt_param = *fw_ptr; |
| 1461 | *fw_ptr += evt->plen; |
| 1462 | remain -= evt->plen; |
| 1463 | } |
| 1464 | |
| 1465 | /* Every HCI commands in the firmware file has its correspond event. |
| 1466 | * If event is not found or remain is smaller than zero, the firmware |
| 1467 | * file is corrupted. |
| 1468 | */ |
| 1469 | if (!evt || !evt_param || remain < 0) { |
| 1470 | BT_ERR("%s Intel fw corrupted: invalid evt read", hdev->name); |
| 1471 | return -EFAULT; |
| 1472 | } |
| 1473 | |
| 1474 | skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cmd->opcode), cmd->plen, |
| 1475 | cmd_param, evt->evt, HCI_INIT_TIMEOUT); |
| 1476 | if (IS_ERR(skb)) { |
| 1477 | BT_ERR("%s sending Intel patch command (0x%4.4x) failed (%ld)", |
| 1478 | hdev->name, cmd->opcode, PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1479 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /* It ensures that the returned event matches the event data read from |
| 1483 | * the firmware file. At fist, it checks the length and then |
| 1484 | * the contents of the event. |
| 1485 | */ |
| 1486 | if (skb->len != evt->plen) { |
| 1487 | BT_ERR("%s mismatch event length (opcode 0x%4.4x)", hdev->name, |
| 1488 | le16_to_cpu(cmd->opcode)); |
| 1489 | kfree_skb(skb); |
| 1490 | return -EFAULT; |
| 1491 | } |
| 1492 | |
| 1493 | if (memcmp(skb->data, evt_param, evt->plen)) { |
| 1494 | BT_ERR("%s mismatch event parameter (opcode 0x%4.4x)", |
| 1495 | hdev->name, le16_to_cpu(cmd->opcode)); |
| 1496 | kfree_skb(skb); |
| 1497 | return -EFAULT; |
| 1498 | } |
| 1499 | kfree_skb(skb); |
| 1500 | |
| 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | static int btusb_setup_intel(struct hci_dev *hdev) |
| 1505 | { |
| 1506 | struct sk_buff *skb; |
| 1507 | const struct firmware *fw; |
| 1508 | const u8 *fw_ptr; |
| 1509 | int disable_patch; |
| 1510 | struct intel_version *ver; |
| 1511 | |
| 1512 | const u8 mfg_enable[] = { 0x01, 0x00 }; |
| 1513 | const u8 mfg_disable[] = { 0x00, 0x00 }; |
| 1514 | const u8 mfg_reset_deactivate[] = { 0x00, 0x01 }; |
| 1515 | const u8 mfg_reset_activate[] = { 0x00, 0x02 }; |
| 1516 | |
| 1517 | BT_DBG("%s", hdev->name); |
| 1518 | |
| 1519 | /* The controller has a bug with the first HCI command sent to it |
| 1520 | * returning number of completed commands as zero. This would stall the |
| 1521 | * command processing in the Bluetooth core. |
| 1522 | * |
| 1523 | * As a workaround, send HCI Reset command first which will reset the |
| 1524 | * number of completed commands and allow normal command processing |
| 1525 | * from now on. |
| 1526 | */ |
| 1527 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 1528 | if (IS_ERR(skb)) { |
| 1529 | BT_ERR("%s sending initial HCI reset command failed (%ld)", |
| 1530 | hdev->name, PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1531 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1532 | } |
| 1533 | kfree_skb(skb); |
| 1534 | |
| 1535 | /* Read Intel specific controller version first to allow selection of |
| 1536 | * which firmware file to load. |
| 1537 | * |
| 1538 | * The returned information are hardware variant and revision plus |
| 1539 | * firmware variant, revision and build number. |
| 1540 | */ |
| 1541 | skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT); |
| 1542 | if (IS_ERR(skb)) { |
| 1543 | BT_ERR("%s reading Intel fw version command failed (%ld)", |
| 1544 | hdev->name, PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1545 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | if (skb->len != sizeof(*ver)) { |
| 1549 | BT_ERR("%s Intel version event length mismatch", hdev->name); |
| 1550 | kfree_skb(skb); |
| 1551 | return -EIO; |
| 1552 | } |
| 1553 | |
| 1554 | ver = (struct intel_version *)skb->data; |
| 1555 | if (ver->status) { |
| 1556 | BT_ERR("%s Intel fw version event failed (%02x)", hdev->name, |
| 1557 | ver->status); |
| 1558 | kfree_skb(skb); |
| 1559 | return -bt_to_errno(ver->status); |
| 1560 | } |
| 1561 | |
| 1562 | BT_INFO("%s: read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x", |
| 1563 | hdev->name, ver->hw_platform, ver->hw_variant, |
| 1564 | ver->hw_revision, ver->fw_variant, ver->fw_revision, |
| 1565 | ver->fw_build_num, ver->fw_build_ww, ver->fw_build_yy, |
| 1566 | ver->fw_patch_num); |
| 1567 | |
| 1568 | /* fw_patch_num indicates the version of patch the device currently |
| 1569 | * have. If there is no patch data in the device, it is always 0x00. |
| 1570 | * So, if it is other than 0x00, no need to patch the deivce again. |
| 1571 | */ |
| 1572 | if (ver->fw_patch_num) { |
| 1573 | BT_INFO("%s: Intel device is already patched. patch num: %02x", |
| 1574 | hdev->name, ver->fw_patch_num); |
| 1575 | kfree_skb(skb); |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 1576 | btintel_check_bdaddr(hdev); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | /* Opens the firmware patch file based on the firmware version read |
| 1581 | * from the controller. If it fails to open the matching firmware |
| 1582 | * patch file, it tries to open the default firmware patch file. |
| 1583 | * If no patch file is found, allow the device to operate without |
| 1584 | * a patch. |
| 1585 | */ |
| 1586 | fw = btusb_setup_intel_get_fw(hdev, ver); |
| 1587 | if (!fw) { |
| 1588 | kfree_skb(skb); |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 1589 | btintel_check_bdaddr(hdev); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1590 | return 0; |
| 1591 | } |
| 1592 | fw_ptr = fw->data; |
| 1593 | |
| 1594 | /* This Intel specific command enables the manufacturer mode of the |
| 1595 | * controller. |
| 1596 | * |
| 1597 | * Only while this mode is enabled, the driver can download the |
| 1598 | * firmware patch data and configuration parameters. |
| 1599 | */ |
| 1600 | skb = __hci_cmd_sync(hdev, 0xfc11, 2, mfg_enable, HCI_INIT_TIMEOUT); |
| 1601 | if (IS_ERR(skb)) { |
| 1602 | BT_ERR("%s entering Intel manufacturer mode failed (%ld)", |
| 1603 | hdev->name, PTR_ERR(skb)); |
| 1604 | release_firmware(fw); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1605 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | if (skb->data[0]) { |
| 1609 | u8 evt_status = skb->data[0]; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 1610 | |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1611 | BT_ERR("%s enable Intel manufacturer mode event failed (%02x)", |
| 1612 | hdev->name, evt_status); |
| 1613 | kfree_skb(skb); |
| 1614 | release_firmware(fw); |
| 1615 | return -bt_to_errno(evt_status); |
| 1616 | } |
| 1617 | kfree_skb(skb); |
| 1618 | |
| 1619 | disable_patch = 1; |
| 1620 | |
| 1621 | /* The firmware data file consists of list of Intel specific HCI |
| 1622 | * commands and its expected events. The first byte indicates the |
| 1623 | * type of the message, either HCI command or HCI event. |
| 1624 | * |
| 1625 | * It reads the command and its expected event from the firmware file, |
| 1626 | * and send to the controller. Once __hci_cmd_sync_ev() returns, |
| 1627 | * the returned event is compared with the event read from the firmware |
| 1628 | * file and it will continue until all the messages are downloaded to |
| 1629 | * the controller. |
| 1630 | * |
| 1631 | * Once the firmware patching is completed successfully, |
| 1632 | * the manufacturer mode is disabled with reset and activating the |
| 1633 | * downloaded patch. |
| 1634 | * |
| 1635 | * If the firmware patching fails, the manufacturer mode is |
| 1636 | * disabled with reset and deactivating the patch. |
| 1637 | * |
| 1638 | * If the default patch file is used, no reset is done when disabling |
| 1639 | * the manufacturer. |
| 1640 | */ |
| 1641 | while (fw->size > fw_ptr - fw->data) { |
| 1642 | int ret; |
| 1643 | |
| 1644 | ret = btusb_setup_intel_patching(hdev, fw, &fw_ptr, |
| 1645 | &disable_patch); |
| 1646 | if (ret < 0) |
| 1647 | goto exit_mfg_deactivate; |
| 1648 | } |
| 1649 | |
| 1650 | release_firmware(fw); |
| 1651 | |
| 1652 | if (disable_patch) |
| 1653 | goto exit_mfg_disable; |
| 1654 | |
| 1655 | /* Patching completed successfully and disable the manufacturer mode |
| 1656 | * with reset and activate the downloaded firmware patches. |
| 1657 | */ |
| 1658 | skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_reset_activate), |
| 1659 | mfg_reset_activate, HCI_INIT_TIMEOUT); |
| 1660 | if (IS_ERR(skb)) { |
| 1661 | BT_ERR("%s exiting Intel manufacturer mode failed (%ld)", |
| 1662 | hdev->name, PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1663 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1664 | } |
| 1665 | kfree_skb(skb); |
| 1666 | |
| 1667 | BT_INFO("%s: Intel Bluetooth firmware patch completed and activated", |
| 1668 | hdev->name); |
| 1669 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 1670 | btintel_check_bdaddr(hdev); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1671 | return 0; |
| 1672 | |
| 1673 | exit_mfg_disable: |
| 1674 | /* Disable the manufacturer mode without reset */ |
| 1675 | skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_disable), mfg_disable, |
| 1676 | HCI_INIT_TIMEOUT); |
| 1677 | if (IS_ERR(skb)) { |
| 1678 | BT_ERR("%s exiting Intel manufacturer mode failed (%ld)", |
| 1679 | hdev->name, PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1680 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1681 | } |
| 1682 | kfree_skb(skb); |
| 1683 | |
| 1684 | BT_INFO("%s: Intel Bluetooth firmware patch completed", hdev->name); |
Marcel Holtmann | 40cb098 | 2014-07-02 12:06:45 +0200 | [diff] [blame] | 1685 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 1686 | btintel_check_bdaddr(hdev); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1687 | return 0; |
| 1688 | |
| 1689 | exit_mfg_deactivate: |
| 1690 | release_firmware(fw); |
| 1691 | |
| 1692 | /* Patching failed. Disable the manufacturer mode with reset and |
| 1693 | * deactivate the downloaded firmware patches. |
| 1694 | */ |
| 1695 | skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_reset_deactivate), |
| 1696 | mfg_reset_deactivate, HCI_INIT_TIMEOUT); |
| 1697 | if (IS_ERR(skb)) { |
| 1698 | BT_ERR("%s exiting Intel manufacturer mode failed (%ld)", |
| 1699 | hdev->name, PTR_ERR(skb)); |
Adam Lee | d9c78e9 | 2013-07-10 10:02:12 +0800 | [diff] [blame] | 1700 | return PTR_ERR(skb); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1701 | } |
| 1702 | kfree_skb(skb); |
| 1703 | |
| 1704 | BT_INFO("%s: Intel Bluetooth firmware patch completed and deactivated", |
| 1705 | hdev->name); |
| 1706 | |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 1707 | btintel_check_bdaddr(hdev); |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 1708 | return 0; |
| 1709 | } |
| 1710 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 1711 | static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode) |
| 1712 | { |
| 1713 | struct sk_buff *skb; |
| 1714 | struct hci_event_hdr *hdr; |
| 1715 | struct hci_ev_cmd_complete *evt; |
| 1716 | |
| 1717 | skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_ATOMIC); |
| 1718 | if (!skb) |
| 1719 | return -ENOMEM; |
| 1720 | |
| 1721 | hdr = (struct hci_event_hdr *)skb_put(skb, sizeof(*hdr)); |
| 1722 | hdr->evt = HCI_EV_CMD_COMPLETE; |
| 1723 | hdr->plen = sizeof(*evt) + 1; |
| 1724 | |
| 1725 | evt = (struct hci_ev_cmd_complete *)skb_put(skb, sizeof(*evt)); |
| 1726 | evt->ncmd = 0x01; |
| 1727 | evt->opcode = cpu_to_le16(opcode); |
| 1728 | |
| 1729 | *skb_put(skb, 1) = 0x00; |
| 1730 | |
| 1731 | bt_cb(skb)->pkt_type = HCI_EVENT_PKT; |
| 1732 | |
| 1733 | return hci_recv_frame(hdev, skb); |
| 1734 | } |
| 1735 | |
| 1736 | static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer, |
| 1737 | int count) |
| 1738 | { |
| 1739 | /* When the device is in bootloader mode, then it can send |
| 1740 | * events via the bulk endpoint. These events are treated the |
| 1741 | * same way as the ones received from the interrupt endpoint. |
| 1742 | */ |
| 1743 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) |
| 1744 | return btusb_recv_intr(data, buffer, count); |
| 1745 | |
| 1746 | return btusb_recv_bulk(data, buffer, count); |
| 1747 | } |
| 1748 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame^] | 1749 | static void btusb_intel_bootup(struct btusb_data *data, const void *ptr, |
| 1750 | unsigned int len) |
| 1751 | { |
| 1752 | const struct intel_bootup *evt = ptr; |
| 1753 | |
| 1754 | if (len != sizeof(*evt)) |
| 1755 | return; |
| 1756 | |
| 1757 | if (test_and_clear_bit(BTUSB_BOOTING, &data->flags)) { |
| 1758 | smp_mb__after_atomic(); |
| 1759 | wake_up_bit(&data->flags, BTUSB_BOOTING); |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | static void btusb_intel_secure_send_result(struct btusb_data *data, |
| 1764 | const void *ptr, unsigned int len) |
| 1765 | { |
| 1766 | const struct intel_secure_send_result *evt = ptr; |
| 1767 | |
| 1768 | if (len != sizeof(*evt)) |
| 1769 | return; |
| 1770 | |
| 1771 | if (evt->result) |
| 1772 | set_bit(BTUSB_FIRMWARE_FAILED, &data->flags); |
| 1773 | |
| 1774 | if (test_and_clear_bit(BTUSB_DOWNLOADING, &data->flags) && |
| 1775 | test_bit(BTUSB_FIRMWARE_LOADED, &data->flags)) { |
| 1776 | smp_mb__after_atomic(); |
| 1777 | wake_up_bit(&data->flags, BTUSB_DOWNLOADING); |
| 1778 | } |
| 1779 | } |
| 1780 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 1781 | static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb) |
| 1782 | { |
| 1783 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1784 | |
| 1785 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 1786 | struct hci_event_hdr *hdr = (void *)skb->data; |
| 1787 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame^] | 1788 | if (skb->len > HCI_EVENT_HDR_SIZE && hdr->evt == 0xff && |
| 1789 | hdr->plen > 0) { |
| 1790 | const void *ptr = skb->data + HCI_EVENT_HDR_SIZE + 1; |
| 1791 | unsigned int len = skb->len - HCI_EVENT_HDR_SIZE - 1; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 1792 | |
Marcel Holtmann | ccd6da2 | 2015-04-09 00:35:19 -0700 | [diff] [blame^] | 1793 | switch (skb->data[2]) { |
| 1794 | case 0x02: |
| 1795 | /* When switching to the operational firmware |
| 1796 | * the device sends a vendor specific event |
| 1797 | * indicating that the bootup completed. |
| 1798 | */ |
| 1799 | btusb_intel_bootup(data, ptr, len); |
| 1800 | break; |
| 1801 | case 0x06: |
| 1802 | /* When the firmware loading completes the |
| 1803 | * device sends out a vendor specific event |
| 1804 | * indicating the result of the firmware |
| 1805 | * loading. |
| 1806 | */ |
| 1807 | btusb_intel_secure_send_result(data, ptr, len); |
| 1808 | break; |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 1809 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | return hci_recv_frame(hdev, skb); |
| 1814 | } |
| 1815 | |
| 1816 | static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) |
| 1817 | { |
| 1818 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1819 | struct urb *urb; |
| 1820 | |
| 1821 | BT_DBG("%s", hdev->name); |
| 1822 | |
| 1823 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
| 1824 | return -EBUSY; |
| 1825 | |
| 1826 | switch (bt_cb(skb)->pkt_type) { |
| 1827 | case HCI_COMMAND_PKT: |
| 1828 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) { |
| 1829 | struct hci_command_hdr *cmd = (void *)skb->data; |
| 1830 | __u16 opcode = le16_to_cpu(cmd->opcode); |
| 1831 | |
| 1832 | /* When in bootloader mode and the command 0xfc09 |
| 1833 | * is received, it needs to be send down the |
| 1834 | * bulk endpoint. So allocate a bulk URB instead. |
| 1835 | */ |
| 1836 | if (opcode == 0xfc09) |
| 1837 | urb = alloc_bulk_urb(hdev, skb); |
| 1838 | else |
| 1839 | urb = alloc_ctrl_urb(hdev, skb); |
| 1840 | |
| 1841 | /* When the 0xfc01 command is issued to boot into |
| 1842 | * the operational firmware, it will actually not |
| 1843 | * send a command complete event. To keep the flow |
| 1844 | * control working inject that event here. |
| 1845 | */ |
| 1846 | if (opcode == 0xfc01) |
| 1847 | inject_cmd_complete(hdev, opcode); |
| 1848 | } else { |
| 1849 | urb = alloc_ctrl_urb(hdev, skb); |
| 1850 | } |
| 1851 | if (IS_ERR(urb)) |
| 1852 | return PTR_ERR(urb); |
| 1853 | |
| 1854 | hdev->stat.cmd_tx++; |
| 1855 | return submit_or_queue_tx_urb(hdev, urb); |
| 1856 | |
| 1857 | case HCI_ACLDATA_PKT: |
| 1858 | urb = alloc_bulk_urb(hdev, skb); |
| 1859 | if (IS_ERR(urb)) |
| 1860 | return PTR_ERR(urb); |
| 1861 | |
| 1862 | hdev->stat.acl_tx++; |
| 1863 | return submit_or_queue_tx_urb(hdev, urb); |
| 1864 | |
| 1865 | case HCI_SCODATA_PKT: |
| 1866 | if (hci_conn_num(hdev, SCO_LINK) < 1) |
| 1867 | return -ENODEV; |
| 1868 | |
| 1869 | urb = alloc_isoc_urb(hdev, skb); |
| 1870 | if (IS_ERR(urb)) |
| 1871 | return PTR_ERR(urb); |
| 1872 | |
| 1873 | hdev->stat.sco_tx++; |
| 1874 | return submit_tx_urb(hdev, urb); |
| 1875 | } |
| 1876 | |
| 1877 | return -EILSEQ; |
| 1878 | } |
| 1879 | |
| 1880 | static int btusb_intel_secure_send(struct hci_dev *hdev, u8 fragment_type, |
| 1881 | u32 plen, const void *param) |
| 1882 | { |
| 1883 | while (plen > 0) { |
| 1884 | struct sk_buff *skb; |
| 1885 | u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen; |
| 1886 | |
| 1887 | cmd_param[0] = fragment_type; |
| 1888 | memcpy(cmd_param + 1, param, fragment_len); |
| 1889 | |
| 1890 | skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1, |
| 1891 | cmd_param, HCI_INIT_TIMEOUT); |
| 1892 | if (IS_ERR(skb)) |
| 1893 | return PTR_ERR(skb); |
| 1894 | |
| 1895 | kfree_skb(skb); |
| 1896 | |
| 1897 | plen -= fragment_len; |
| 1898 | param += fragment_len; |
| 1899 | } |
| 1900 | |
| 1901 | return 0; |
| 1902 | } |
| 1903 | |
| 1904 | static void btusb_intel_version_info(struct hci_dev *hdev, |
| 1905 | struct intel_version *ver) |
| 1906 | { |
| 1907 | const char *variant; |
| 1908 | |
| 1909 | switch (ver->fw_variant) { |
| 1910 | case 0x06: |
| 1911 | variant = "Bootloader"; |
| 1912 | break; |
| 1913 | case 0x23: |
| 1914 | variant = "Firmware"; |
| 1915 | break; |
| 1916 | default: |
| 1917 | return; |
| 1918 | } |
| 1919 | |
| 1920 | BT_INFO("%s: %s revision %u.%u build %u week %u %u", hdev->name, |
| 1921 | variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f, |
| 1922 | ver->fw_build_num, ver->fw_build_ww, 2000 + ver->fw_build_yy); |
| 1923 | } |
| 1924 | |
| 1925 | static int btusb_setup_intel_new(struct hci_dev *hdev) |
| 1926 | { |
| 1927 | static const u8 reset_param[] = { 0x00, 0x01, 0x00, 0x01, |
| 1928 | 0x00, 0x08, 0x04, 0x00 }; |
| 1929 | struct btusb_data *data = hci_get_drvdata(hdev); |
| 1930 | struct sk_buff *skb; |
| 1931 | struct intel_version *ver; |
| 1932 | struct intel_boot_params *params; |
| 1933 | const struct firmware *fw; |
| 1934 | const u8 *fw_ptr; |
| 1935 | char fwname[64]; |
| 1936 | ktime_t calltime, delta, rettime; |
| 1937 | unsigned long long duration; |
| 1938 | int err; |
| 1939 | |
| 1940 | BT_DBG("%s", hdev->name); |
| 1941 | |
| 1942 | calltime = ktime_get(); |
| 1943 | |
| 1944 | /* Read the Intel version information to determine if the device |
| 1945 | * is in bootloader mode or if it already has operational firmware |
| 1946 | * loaded. |
| 1947 | */ |
| 1948 | skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT); |
| 1949 | if (IS_ERR(skb)) { |
| 1950 | BT_ERR("%s: Reading Intel version information failed (%ld)", |
| 1951 | hdev->name, PTR_ERR(skb)); |
| 1952 | return PTR_ERR(skb); |
| 1953 | } |
| 1954 | |
| 1955 | if (skb->len != sizeof(*ver)) { |
| 1956 | BT_ERR("%s: Intel version event size mismatch", hdev->name); |
| 1957 | kfree_skb(skb); |
| 1958 | return -EILSEQ; |
| 1959 | } |
| 1960 | |
| 1961 | ver = (struct intel_version *)skb->data; |
| 1962 | if (ver->status) { |
| 1963 | BT_ERR("%s: Intel version command failure (%02x)", |
| 1964 | hdev->name, ver->status); |
| 1965 | err = -bt_to_errno(ver->status); |
| 1966 | kfree_skb(skb); |
| 1967 | return err; |
| 1968 | } |
| 1969 | |
| 1970 | /* The hardware platform number has a fixed value of 0x37 and |
| 1971 | * for now only accept this single value. |
| 1972 | */ |
| 1973 | if (ver->hw_platform != 0x37) { |
| 1974 | BT_ERR("%s: Unsupported Intel hardware platform (%u)", |
| 1975 | hdev->name, ver->hw_platform); |
| 1976 | kfree_skb(skb); |
| 1977 | return -EINVAL; |
| 1978 | } |
| 1979 | |
| 1980 | /* At the moment only the hardware variant iBT 3.0 (LnP/SfP) is |
| 1981 | * supported by this firmware loading method. This check has been |
| 1982 | * put in place to ensure correct forward compatibility options |
| 1983 | * when newer hardware variants come along. |
| 1984 | */ |
| 1985 | if (ver->hw_variant != 0x0b) { |
| 1986 | BT_ERR("%s: Unsupported Intel hardware variant (%u)", |
| 1987 | hdev->name, ver->hw_variant); |
| 1988 | kfree_skb(skb); |
| 1989 | return -EINVAL; |
| 1990 | } |
| 1991 | |
| 1992 | btusb_intel_version_info(hdev, ver); |
| 1993 | |
| 1994 | /* The firmware variant determines if the device is in bootloader |
| 1995 | * mode or is running operational firmware. The value 0x06 identifies |
| 1996 | * the bootloader and the value 0x23 identifies the operational |
| 1997 | * firmware. |
| 1998 | * |
| 1999 | * When the operational firmware is already present, then only |
| 2000 | * the check for valid Bluetooth device address is needed. This |
| 2001 | * determines if the device will be added as configured or |
| 2002 | * unconfigured controller. |
| 2003 | * |
| 2004 | * It is not possible to use the Secure Boot Parameters in this |
| 2005 | * case since that command is only available in bootloader mode. |
| 2006 | */ |
| 2007 | if (ver->fw_variant == 0x23) { |
| 2008 | kfree_skb(skb); |
| 2009 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 2010 | btintel_check_bdaddr(hdev); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2011 | return 0; |
| 2012 | } |
| 2013 | |
| 2014 | /* If the device is not in bootloader mode, then the only possible |
| 2015 | * choice is to return an error and abort the device initialization. |
| 2016 | */ |
| 2017 | if (ver->fw_variant != 0x06) { |
| 2018 | BT_ERR("%s: Unsupported Intel firmware variant (%u)", |
| 2019 | hdev->name, ver->fw_variant); |
| 2020 | kfree_skb(skb); |
| 2021 | return -ENODEV; |
| 2022 | } |
| 2023 | |
| 2024 | kfree_skb(skb); |
| 2025 | |
| 2026 | /* Read the secure boot parameters to identify the operating |
| 2027 | * details of the bootloader. |
| 2028 | */ |
| 2029 | skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT); |
| 2030 | if (IS_ERR(skb)) { |
| 2031 | BT_ERR("%s: Reading Intel boot parameters failed (%ld)", |
| 2032 | hdev->name, PTR_ERR(skb)); |
| 2033 | return PTR_ERR(skb); |
| 2034 | } |
| 2035 | |
| 2036 | if (skb->len != sizeof(*params)) { |
| 2037 | BT_ERR("%s: Intel boot parameters size mismatch", hdev->name); |
| 2038 | kfree_skb(skb); |
| 2039 | return -EILSEQ; |
| 2040 | } |
| 2041 | |
| 2042 | params = (struct intel_boot_params *)skb->data; |
| 2043 | if (params->status) { |
| 2044 | BT_ERR("%s: Intel boot parameters command failure (%02x)", |
| 2045 | hdev->name, params->status); |
| 2046 | err = -bt_to_errno(params->status); |
| 2047 | kfree_skb(skb); |
| 2048 | return err; |
| 2049 | } |
| 2050 | |
| 2051 | BT_INFO("%s: Device revision is %u", hdev->name, |
| 2052 | le16_to_cpu(params->dev_revid)); |
| 2053 | |
| 2054 | BT_INFO("%s: Secure boot is %s", hdev->name, |
| 2055 | params->secure_boot ? "enabled" : "disabled"); |
| 2056 | |
| 2057 | BT_INFO("%s: Minimum firmware build %u week %u %u", hdev->name, |
| 2058 | params->min_fw_build_nn, params->min_fw_build_cw, |
| 2059 | 2000 + params->min_fw_build_yy); |
| 2060 | |
| 2061 | /* It is required that every single firmware fragment is acknowledged |
| 2062 | * with a command complete event. If the boot parameters indicate |
| 2063 | * that this bootloader does not send them, then abort the setup. |
| 2064 | */ |
| 2065 | if (params->limited_cce != 0x00) { |
| 2066 | BT_ERR("%s: Unsupported Intel firmware loading method (%u)", |
| 2067 | hdev->name, params->limited_cce); |
| 2068 | kfree_skb(skb); |
| 2069 | return -EINVAL; |
| 2070 | } |
| 2071 | |
| 2072 | /* If the OTP has no valid Bluetooth device address, then there will |
| 2073 | * also be no valid address for the operational firmware. |
| 2074 | */ |
| 2075 | if (!bacmp(¶ms->otp_bdaddr, BDADDR_ANY)) { |
| 2076 | BT_INFO("%s: No device address configured", hdev->name); |
| 2077 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); |
| 2078 | } |
| 2079 | |
| 2080 | /* With this Intel bootloader only the hardware variant and device |
| 2081 | * revision information are used to select the right firmware. |
| 2082 | * |
| 2083 | * Currently this bootloader support is limited to hardware variant |
| 2084 | * iBT 3.0 (LnP/SfP) which is identified by the value 11 (0x0b). |
| 2085 | */ |
| 2086 | snprintf(fwname, sizeof(fwname), "intel/ibt-11-%u.sfi", |
| 2087 | le16_to_cpu(params->dev_revid)); |
| 2088 | |
| 2089 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 2090 | if (err < 0) { |
| 2091 | BT_ERR("%s: Failed to load Intel firmware file (%d)", |
| 2092 | hdev->name, err); |
| 2093 | kfree_skb(skb); |
| 2094 | return err; |
| 2095 | } |
| 2096 | |
| 2097 | BT_INFO("%s: Found device firmware: %s", hdev->name, fwname); |
| 2098 | |
| 2099 | kfree_skb(skb); |
| 2100 | |
| 2101 | if (fw->size < 644) { |
| 2102 | BT_ERR("%s: Invalid size of firmware file (%zu)", |
| 2103 | hdev->name, fw->size); |
| 2104 | err = -EBADF; |
| 2105 | goto done; |
| 2106 | } |
| 2107 | |
| 2108 | set_bit(BTUSB_DOWNLOADING, &data->flags); |
| 2109 | |
| 2110 | /* Start the firmware download transaction with the Init fragment |
| 2111 | * represented by the 128 bytes of CSS header. |
| 2112 | */ |
| 2113 | err = btusb_intel_secure_send(hdev, 0x00, 128, fw->data); |
| 2114 | if (err < 0) { |
| 2115 | BT_ERR("%s: Failed to send firmware header (%d)", |
| 2116 | hdev->name, err); |
| 2117 | goto done; |
| 2118 | } |
| 2119 | |
| 2120 | /* Send the 256 bytes of public key information from the firmware |
| 2121 | * as the PKey fragment. |
| 2122 | */ |
| 2123 | err = btusb_intel_secure_send(hdev, 0x03, 256, fw->data + 128); |
| 2124 | if (err < 0) { |
| 2125 | BT_ERR("%s: Failed to send firmware public key (%d)", |
| 2126 | hdev->name, err); |
| 2127 | goto done; |
| 2128 | } |
| 2129 | |
| 2130 | /* Send the 256 bytes of signature information from the firmware |
| 2131 | * as the Sign fragment. |
| 2132 | */ |
| 2133 | err = btusb_intel_secure_send(hdev, 0x02, 256, fw->data + 388); |
| 2134 | if (err < 0) { |
| 2135 | BT_ERR("%s: Failed to send firmware signature (%d)", |
| 2136 | hdev->name, err); |
| 2137 | goto done; |
| 2138 | } |
| 2139 | |
| 2140 | fw_ptr = fw->data + 644; |
| 2141 | |
| 2142 | while (fw_ptr - fw->data < fw->size) { |
| 2143 | struct hci_command_hdr *cmd = (void *)fw_ptr; |
| 2144 | u8 cmd_len; |
| 2145 | |
| 2146 | cmd_len = sizeof(*cmd) + cmd->plen; |
| 2147 | |
| 2148 | /* Send each command from the firmware data buffer as |
| 2149 | * a single Data fragment. |
| 2150 | */ |
| 2151 | err = btusb_intel_secure_send(hdev, 0x01, cmd_len, fw_ptr); |
| 2152 | if (err < 0) { |
| 2153 | BT_ERR("%s: Failed to send firmware data (%d)", |
| 2154 | hdev->name, err); |
| 2155 | goto done; |
| 2156 | } |
| 2157 | |
| 2158 | fw_ptr += cmd_len; |
| 2159 | } |
| 2160 | |
Marcel Holtmann | ce6bb92 | 2015-01-28 01:58:40 -0800 | [diff] [blame] | 2161 | set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); |
| 2162 | |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2163 | BT_INFO("%s: Waiting for firmware download to complete", hdev->name); |
| 2164 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2165 | /* Before switching the device into operational mode and with that |
| 2166 | * booting the loaded firmware, wait for the bootloader notification |
| 2167 | * that all fragments have been successfully received. |
| 2168 | * |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2169 | * When the event processing receives the notification, then the |
| 2170 | * BTUSB_DOWNLOADING flag will be cleared. |
| 2171 | * |
| 2172 | * The firmware loading should not take longer than 5 seconds |
| 2173 | * and thus just timeout if that happens and fail the setup |
| 2174 | * of this device. |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2175 | */ |
Johan Hedberg | 129a769 | 2015-02-14 09:33:35 +0200 | [diff] [blame] | 2176 | err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING, |
| 2177 | TASK_INTERRUPTIBLE, |
| 2178 | msecs_to_jiffies(5000)); |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2179 | if (err == 1) { |
| 2180 | BT_ERR("%s: Firmware loading interrupted", hdev->name); |
| 2181 | err = -EINTR; |
| 2182 | goto done; |
| 2183 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2184 | |
Johan Hedberg | a087a98 | 2015-01-30 10:58:54 +0200 | [diff] [blame] | 2185 | if (err) { |
| 2186 | BT_ERR("%s: Firmware loading timeout", hdev->name); |
| 2187 | err = -ETIMEDOUT; |
| 2188 | goto done; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) { |
| 2192 | BT_ERR("%s: Firmware loading failed", hdev->name); |
| 2193 | err = -ENOEXEC; |
| 2194 | goto done; |
| 2195 | } |
| 2196 | |
| 2197 | rettime = ktime_get(); |
| 2198 | delta = ktime_sub(rettime, calltime); |
| 2199 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; |
| 2200 | |
| 2201 | BT_INFO("%s: Firmware loaded in %llu usecs", hdev->name, duration); |
| 2202 | |
| 2203 | done: |
| 2204 | release_firmware(fw); |
| 2205 | |
| 2206 | if (err < 0) |
| 2207 | return err; |
| 2208 | |
| 2209 | calltime = ktime_get(); |
| 2210 | |
| 2211 | set_bit(BTUSB_BOOTING, &data->flags); |
| 2212 | |
| 2213 | skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(reset_param), reset_param, |
| 2214 | HCI_INIT_TIMEOUT); |
| 2215 | if (IS_ERR(skb)) |
| 2216 | return PTR_ERR(skb); |
| 2217 | |
| 2218 | kfree_skb(skb); |
| 2219 | |
| 2220 | /* The bootloader will not indicate when the device is ready. This |
| 2221 | * is done by the operational firmware sending bootup notification. |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2222 | * |
| 2223 | * Booting into operational firmware should not take longer than |
| 2224 | * 1 second. However if that happens, then just fail the setup |
| 2225 | * since something went wrong. |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2226 | */ |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2227 | BT_INFO("%s: Waiting for device to boot", hdev->name); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2228 | |
Johan Hedberg | 129a769 | 2015-02-14 09:33:35 +0200 | [diff] [blame] | 2229 | err = wait_on_bit_timeout(&data->flags, BTUSB_BOOTING, |
| 2230 | TASK_INTERRUPTIBLE, |
| 2231 | msecs_to_jiffies(1000)); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2232 | |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2233 | if (err == 1) { |
| 2234 | BT_ERR("%s: Device boot interrupted", hdev->name); |
| 2235 | return -EINTR; |
| 2236 | } |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2237 | |
Johan Hedberg | fad7097 | 2015-01-30 10:58:55 +0200 | [diff] [blame] | 2238 | if (err) { |
| 2239 | BT_ERR("%s: Device boot timeout", hdev->name); |
| 2240 | return -ETIMEDOUT; |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | rettime = ktime_get(); |
| 2244 | delta = ktime_sub(rettime, calltime); |
| 2245 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; |
| 2246 | |
| 2247 | BT_INFO("%s: Device booted in %llu usecs", hdev->name, duration); |
| 2248 | |
| 2249 | clear_bit(BTUSB_BOOTLOADER, &data->flags); |
| 2250 | |
| 2251 | return 0; |
| 2252 | } |
| 2253 | |
Marcel Holtmann | 385a768 | 2015-01-28 11:09:56 -0800 | [diff] [blame] | 2254 | static void btusb_hw_error_intel(struct hci_dev *hdev, u8 code) |
| 2255 | { |
| 2256 | struct sk_buff *skb; |
| 2257 | u8 type = 0x00; |
| 2258 | |
| 2259 | BT_ERR("%s: Hardware error 0x%2.2x", hdev->name, code); |
| 2260 | |
| 2261 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 2262 | if (IS_ERR(skb)) { |
| 2263 | BT_ERR("%s: Reset after hardware error failed (%ld)", |
| 2264 | hdev->name, PTR_ERR(skb)); |
| 2265 | return; |
| 2266 | } |
| 2267 | kfree_skb(skb); |
| 2268 | |
| 2269 | skb = __hci_cmd_sync(hdev, 0xfc22, 1, &type, HCI_INIT_TIMEOUT); |
| 2270 | if (IS_ERR(skb)) { |
| 2271 | BT_ERR("%s: Retrieving Intel exception info failed (%ld)", |
| 2272 | hdev->name, PTR_ERR(skb)); |
| 2273 | return; |
| 2274 | } |
| 2275 | |
| 2276 | if (skb->len != 13) { |
| 2277 | BT_ERR("%s: Exception info size mismatch", hdev->name); |
| 2278 | kfree_skb(skb); |
| 2279 | return; |
| 2280 | } |
| 2281 | |
| 2282 | if (skb->data[0] != 0x00) { |
| 2283 | BT_ERR("%s: Exception info command failure (%02x)", |
| 2284 | hdev->name, skb->data[0]); |
| 2285 | kfree_skb(skb); |
| 2286 | return; |
| 2287 | } |
| 2288 | |
| 2289 | BT_ERR("%s: Exception info %s", hdev->name, (char *)(skb->data + 1)); |
| 2290 | |
| 2291 | kfree_skb(skb); |
| 2292 | } |
| 2293 | |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 2294 | static int btusb_shutdown_intel(struct hci_dev *hdev) |
| 2295 | { |
| 2296 | struct sk_buff *skb; |
| 2297 | long ret; |
| 2298 | |
| 2299 | /* Some platforms have an issue with BT LED when the interface is |
| 2300 | * down or BT radio is turned off, which takes 5 seconds to BT LED |
| 2301 | * goes off. This command turns off the BT LED immediately. |
| 2302 | */ |
| 2303 | skb = __hci_cmd_sync(hdev, 0xfc3f, 0, NULL, HCI_INIT_TIMEOUT); |
| 2304 | if (IS_ERR(skb)) { |
| 2305 | ret = PTR_ERR(skb); |
| 2306 | BT_ERR("%s: turning off Intel device LED failed (%ld)", |
| 2307 | hdev->name, ret); |
| 2308 | return ret; |
| 2309 | } |
| 2310 | kfree_skb(skb); |
| 2311 | |
| 2312 | return 0; |
| 2313 | } |
| 2314 | |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 2315 | static int btusb_set_bdaddr_marvell(struct hci_dev *hdev, |
| 2316 | const bdaddr_t *bdaddr) |
| 2317 | { |
| 2318 | struct sk_buff *skb; |
| 2319 | u8 buf[8]; |
| 2320 | long ret; |
| 2321 | |
| 2322 | buf[0] = 0xfe; |
| 2323 | buf[1] = sizeof(bdaddr_t); |
| 2324 | memcpy(buf + 2, bdaddr, sizeof(bdaddr_t)); |
| 2325 | |
| 2326 | skb = __hci_cmd_sync(hdev, 0xfc22, sizeof(buf), buf, HCI_INIT_TIMEOUT); |
| 2327 | if (IS_ERR(skb)) { |
| 2328 | ret = PTR_ERR(skb); |
| 2329 | BT_ERR("%s: changing Marvell device address failed (%ld)", |
| 2330 | hdev->name, ret); |
| 2331 | return ret; |
| 2332 | } |
| 2333 | kfree_skb(skb); |
| 2334 | |
| 2335 | return 0; |
| 2336 | } |
| 2337 | |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 2338 | static int btusb_set_bdaddr_ath3012(struct hci_dev *hdev, |
| 2339 | const bdaddr_t *bdaddr) |
| 2340 | { |
| 2341 | struct sk_buff *skb; |
| 2342 | u8 buf[10]; |
| 2343 | long ret; |
| 2344 | |
| 2345 | buf[0] = 0x01; |
| 2346 | buf[1] = 0x01; |
| 2347 | buf[2] = 0x00; |
| 2348 | buf[3] = sizeof(bdaddr_t); |
| 2349 | memcpy(buf + 4, bdaddr, sizeof(bdaddr_t)); |
| 2350 | |
| 2351 | skb = __hci_cmd_sync(hdev, 0xfc0b, sizeof(buf), buf, HCI_INIT_TIMEOUT); |
| 2352 | if (IS_ERR(skb)) { |
| 2353 | ret = PTR_ERR(skb); |
| 2354 | BT_ERR("%s: Change address command failed (%ld)", |
| 2355 | hdev->name, ret); |
| 2356 | return ret; |
| 2357 | } |
| 2358 | kfree_skb(skb); |
| 2359 | |
| 2360 | return 0; |
| 2361 | } |
| 2362 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2363 | #define QCA_DFU_PACKET_LEN 4096 |
| 2364 | |
| 2365 | #define QCA_GET_TARGET_VERSION 0x09 |
| 2366 | #define QCA_CHECK_STATUS 0x05 |
| 2367 | #define QCA_DFU_DOWNLOAD 0x01 |
| 2368 | |
| 2369 | #define QCA_SYSCFG_UPDATED 0x40 |
| 2370 | #define QCA_PATCH_UPDATED 0x80 |
| 2371 | #define QCA_DFU_TIMEOUT 3000 |
| 2372 | |
| 2373 | struct qca_version { |
| 2374 | __le32 rom_version; |
| 2375 | __le32 patch_version; |
| 2376 | __le32 ram_version; |
| 2377 | __le32 ref_clock; |
| 2378 | __u8 reserved[4]; |
| 2379 | } __packed; |
| 2380 | |
| 2381 | struct qca_rampatch_version { |
| 2382 | __le16 rom_version; |
| 2383 | __le16 patch_version; |
| 2384 | } __packed; |
| 2385 | |
| 2386 | struct qca_device_info { |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 2387 | u32 rom_version; |
| 2388 | u8 rampatch_hdr; /* length of header in rampatch */ |
| 2389 | u8 nvm_hdr; /* length of header in NVM */ |
| 2390 | u8 ver_offset; /* offset of version structure in rampatch */ |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2391 | }; |
| 2392 | |
| 2393 | static const struct qca_device_info qca_devices_table[] = { |
| 2394 | { 0x00000100, 20, 4, 10 }, /* Rome 1.0 */ |
| 2395 | { 0x00000101, 20, 4, 10 }, /* Rome 1.1 */ |
| 2396 | { 0x00000201, 28, 4, 18 }, /* Rome 2.1 */ |
| 2397 | { 0x00000300, 28, 4, 18 }, /* Rome 3.0 */ |
| 2398 | { 0x00000302, 28, 4, 18 }, /* Rome 3.2 */ |
| 2399 | }; |
| 2400 | |
| 2401 | static int btusb_qca_send_vendor_req(struct hci_dev *hdev, u8 request, |
| 2402 | void *data, u16 size) |
| 2403 | { |
| 2404 | struct btusb_data *btdata = hci_get_drvdata(hdev); |
| 2405 | struct usb_device *udev = btdata->udev; |
| 2406 | int pipe, err; |
| 2407 | u8 *buf; |
| 2408 | |
| 2409 | buf = kmalloc(size, GFP_KERNEL); |
| 2410 | if (!buf) |
| 2411 | return -ENOMEM; |
| 2412 | |
| 2413 | /* Found some of USB hosts have IOT issues with ours so that we should |
| 2414 | * not wait until HCI layer is ready. |
| 2415 | */ |
| 2416 | pipe = usb_rcvctrlpipe(udev, 0); |
| 2417 | err = usb_control_msg(udev, pipe, request, USB_TYPE_VENDOR | USB_DIR_IN, |
| 2418 | 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); |
| 2419 | if (err < 0) { |
| 2420 | BT_ERR("%s: Failed to access otp area (%d)", hdev->name, err); |
| 2421 | goto done; |
| 2422 | } |
| 2423 | |
| 2424 | memcpy(data, buf, size); |
| 2425 | |
| 2426 | done: |
| 2427 | kfree(buf); |
| 2428 | |
| 2429 | return err; |
| 2430 | } |
| 2431 | |
| 2432 | static int btusb_setup_qca_download_fw(struct hci_dev *hdev, |
| 2433 | const struct firmware *firmware, |
| 2434 | size_t hdr_size) |
| 2435 | { |
| 2436 | struct btusb_data *btdata = hci_get_drvdata(hdev); |
| 2437 | struct usb_device *udev = btdata->udev; |
| 2438 | size_t count, size, sent = 0; |
| 2439 | int pipe, len, err; |
| 2440 | u8 *buf; |
| 2441 | |
| 2442 | buf = kmalloc(QCA_DFU_PACKET_LEN, GFP_KERNEL); |
| 2443 | if (!buf) |
| 2444 | return -ENOMEM; |
| 2445 | |
| 2446 | count = firmware->size; |
| 2447 | |
| 2448 | size = min_t(size_t, count, hdr_size); |
| 2449 | memcpy(buf, firmware->data, size); |
| 2450 | |
| 2451 | /* USB patches should go down to controller through USB path |
| 2452 | * because binary format fits to go down through USB channel. |
| 2453 | * USB control path is for patching headers and USB bulk is for |
| 2454 | * patch body. |
| 2455 | */ |
| 2456 | pipe = usb_sndctrlpipe(udev, 0); |
| 2457 | err = usb_control_msg(udev, pipe, QCA_DFU_DOWNLOAD, USB_TYPE_VENDOR, |
| 2458 | 0, 0, buf, size, USB_CTRL_SET_TIMEOUT); |
| 2459 | if (err < 0) { |
| 2460 | BT_ERR("%s: Failed to send headers (%d)", hdev->name, err); |
| 2461 | goto done; |
| 2462 | } |
| 2463 | |
| 2464 | sent += size; |
| 2465 | count -= size; |
| 2466 | |
| 2467 | while (count) { |
| 2468 | size = min_t(size_t, count, QCA_DFU_PACKET_LEN); |
| 2469 | |
| 2470 | memcpy(buf, firmware->data + sent, size); |
| 2471 | |
| 2472 | pipe = usb_sndbulkpipe(udev, 0x02); |
| 2473 | err = usb_bulk_msg(udev, pipe, buf, size, &len, |
| 2474 | QCA_DFU_TIMEOUT); |
| 2475 | if (err < 0) { |
| 2476 | BT_ERR("%s: Failed to send body at %zd of %zd (%d)", |
| 2477 | hdev->name, sent, firmware->size, err); |
| 2478 | break; |
| 2479 | } |
| 2480 | |
| 2481 | if (size != len) { |
| 2482 | BT_ERR("%s: Failed to get bulk buffer", hdev->name); |
| 2483 | err = -EILSEQ; |
| 2484 | break; |
| 2485 | } |
| 2486 | |
| 2487 | sent += size; |
| 2488 | count -= size; |
| 2489 | } |
| 2490 | |
| 2491 | done: |
| 2492 | kfree(buf); |
| 2493 | return err; |
| 2494 | } |
| 2495 | |
| 2496 | static int btusb_setup_qca_load_rampatch(struct hci_dev *hdev, |
| 2497 | struct qca_version *ver, |
| 2498 | const struct qca_device_info *info) |
| 2499 | { |
| 2500 | struct qca_rampatch_version *rver; |
| 2501 | const struct firmware *fw; |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 2502 | u32 ver_rom, ver_patch; |
| 2503 | u16 rver_rom, rver_patch; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2504 | char fwname[64]; |
| 2505 | int err; |
| 2506 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 2507 | ver_rom = le32_to_cpu(ver->rom_version); |
| 2508 | ver_patch = le32_to_cpu(ver->patch_version); |
| 2509 | |
| 2510 | 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] | 2511 | |
| 2512 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 2513 | if (err) { |
| 2514 | BT_ERR("%s: failed to request rampatch file: %s (%d)", |
| 2515 | hdev->name, fwname, err); |
| 2516 | return err; |
| 2517 | } |
| 2518 | |
| 2519 | BT_INFO("%s: using rampatch file: %s", hdev->name, fwname); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2520 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 2521 | rver = (struct qca_rampatch_version *)(fw->data + info->ver_offset); |
| 2522 | rver_rom = le16_to_cpu(rver->rom_version); |
| 2523 | rver_patch = le16_to_cpu(rver->patch_version); |
| 2524 | |
| 2525 | BT_INFO("%s: QCA: patch rome 0x%x build 0x%x, firmware rome 0x%x " |
| 2526 | "build 0x%x", hdev->name, rver_rom, rver_patch, ver_rom, |
| 2527 | ver_patch); |
| 2528 | |
| 2529 | if (rver_rom != ver_rom || rver_patch <= ver_patch) { |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2530 | BT_ERR("%s: rampatch file version did not match with firmware", |
| 2531 | hdev->name); |
| 2532 | err = -EINVAL; |
| 2533 | goto done; |
| 2534 | } |
| 2535 | |
| 2536 | err = btusb_setup_qca_download_fw(hdev, fw, info->rampatch_hdr); |
| 2537 | |
| 2538 | done: |
| 2539 | release_firmware(fw); |
| 2540 | |
| 2541 | return err; |
| 2542 | } |
| 2543 | |
| 2544 | static int btusb_setup_qca_load_nvm(struct hci_dev *hdev, |
| 2545 | struct qca_version *ver, |
| 2546 | const struct qca_device_info *info) |
| 2547 | { |
| 2548 | const struct firmware *fw; |
| 2549 | char fwname[64]; |
| 2550 | int err; |
| 2551 | |
| 2552 | snprintf(fwname, sizeof(fwname), "qca/nvm_usb_%08x.bin", |
| 2553 | le32_to_cpu(ver->rom_version)); |
| 2554 | |
| 2555 | err = request_firmware(&fw, fwname, &hdev->dev); |
| 2556 | if (err) { |
| 2557 | BT_ERR("%s: failed to request NVM file: %s (%d)", |
| 2558 | hdev->name, fwname, err); |
| 2559 | return err; |
| 2560 | } |
| 2561 | |
| 2562 | BT_INFO("%s: using NVM file: %s", hdev->name, fwname); |
| 2563 | |
| 2564 | err = btusb_setup_qca_download_fw(hdev, fw, info->nvm_hdr); |
| 2565 | |
| 2566 | release_firmware(fw); |
| 2567 | |
| 2568 | return err; |
| 2569 | } |
| 2570 | |
| 2571 | static int btusb_setup_qca(struct hci_dev *hdev) |
| 2572 | { |
| 2573 | const struct qca_device_info *info = NULL; |
| 2574 | struct qca_version ver; |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 2575 | u32 ver_rom; |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2576 | u8 status; |
| 2577 | int i, err; |
| 2578 | |
| 2579 | err = btusb_qca_send_vendor_req(hdev, QCA_GET_TARGET_VERSION, &ver, |
| 2580 | sizeof(ver)); |
| 2581 | if (err < 0) |
| 2582 | return err; |
| 2583 | |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 2584 | ver_rom = le32_to_cpu(ver.rom_version); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2585 | for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) { |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 2586 | if (ver_rom == qca_devices_table[i].rom_version) |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2587 | info = &qca_devices_table[i]; |
| 2588 | } |
| 2589 | if (!info) { |
| 2590 | BT_ERR("%s: don't support firmware rome 0x%x", hdev->name, |
Kim, Ben Young Tae | bf906b3 | 2015-03-10 23:34:58 +0000 | [diff] [blame] | 2591 | ver_rom); |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2592 | return -ENODEV; |
| 2593 | } |
| 2594 | |
| 2595 | err = btusb_qca_send_vendor_req(hdev, QCA_CHECK_STATUS, &status, |
| 2596 | sizeof(status)); |
| 2597 | if (err < 0) |
| 2598 | return err; |
| 2599 | |
| 2600 | if (!(status & QCA_PATCH_UPDATED)) { |
| 2601 | err = btusb_setup_qca_load_rampatch(hdev, &ver, info); |
| 2602 | if (err < 0) |
| 2603 | return err; |
| 2604 | } |
| 2605 | |
| 2606 | if (!(status & QCA_SYSCFG_UPDATED)) { |
| 2607 | err = btusb_setup_qca_load_nvm(hdev, &ver, info); |
| 2608 | if (err < 0) |
| 2609 | return err; |
| 2610 | } |
| 2611 | |
| 2612 | return 0; |
| 2613 | } |
| 2614 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2615 | static int btusb_probe(struct usb_interface *intf, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 2616 | const struct usb_device_id *id) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2617 | { |
| 2618 | struct usb_endpoint_descriptor *ep_desc; |
| 2619 | struct btusb_data *data; |
| 2620 | struct hci_dev *hdev; |
| 2621 | int i, err; |
| 2622 | |
| 2623 | BT_DBG("intf %p id %p", intf, id); |
| 2624 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 2625 | /* interface numbers are hardcoded in the spec */ |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2626 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) |
| 2627 | return -ENODEV; |
| 2628 | |
| 2629 | if (!id->driver_info) { |
| 2630 | const struct usb_device_id *match; |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 2631 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2632 | match = usb_match_id(intf, blacklist_table); |
| 2633 | if (match) |
| 2634 | id = match; |
| 2635 | } |
| 2636 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 2637 | if (id->driver_info == BTUSB_IGNORE) |
| 2638 | return -ENODEV; |
| 2639 | |
Steven.Li | 2d25f8b | 2011-07-01 14:02:36 +0800 | [diff] [blame] | 2640 | if (id->driver_info & BTUSB_ATH3012) { |
| 2641 | struct usb_device *udev = interface_to_usbdev(intf); |
| 2642 | |
| 2643 | /* Old firmware would otherwise let ath3k driver load |
| 2644 | * patch and sysconfig files */ |
| 2645 | if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001) |
| 2646 | return -ENODEV; |
| 2647 | } |
| 2648 | |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 2649 | data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2650 | if (!data) |
| 2651 | return -ENOMEM; |
| 2652 | |
| 2653 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 2654 | ep_desc = &intf->cur_altsetting->endpoint[i].desc; |
| 2655 | |
| 2656 | if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) { |
| 2657 | data->intr_ep = ep_desc; |
| 2658 | continue; |
| 2659 | } |
| 2660 | |
| 2661 | if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) { |
| 2662 | data->bulk_tx_ep = ep_desc; |
| 2663 | continue; |
| 2664 | } |
| 2665 | |
| 2666 | if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) { |
| 2667 | data->bulk_rx_ep = ep_desc; |
| 2668 | continue; |
| 2669 | } |
| 2670 | } |
| 2671 | |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 2672 | if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2673 | return -ENODEV; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2674 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 2675 | if (id->driver_info & BTUSB_AMP) { |
| 2676 | data->cmdreq_type = USB_TYPE_CLASS | 0x01; |
| 2677 | data->cmdreq = 0x2b; |
| 2678 | } else { |
| 2679 | data->cmdreq_type = USB_TYPE_CLASS; |
| 2680 | data->cmdreq = 0x00; |
| 2681 | } |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 2682 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2683 | data->udev = interface_to_usbdev(intf); |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 2684 | data->intf = intf; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2685 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2686 | INIT_WORK(&data->work, btusb_work); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2687 | INIT_WORK(&data->waker, btusb_waker); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 2688 | init_usb_anchor(&data->deferred); |
| 2689 | init_usb_anchor(&data->tx_anchor); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2690 | spin_lock_init(&data->txlock); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2691 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2692 | init_usb_anchor(&data->intr_anchor); |
| 2693 | init_usb_anchor(&data->bulk_anchor); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 2694 | init_usb_anchor(&data->isoc_anchor); |
Marcel Holtmann | 803b583 | 2014-09-16 08:00:29 +0200 | [diff] [blame] | 2695 | spin_lock_init(&data->rxlock); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2696 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2697 | if (id->driver_info & BTUSB_INTEL_NEW) { |
| 2698 | data->recv_event = btusb_recv_event_intel; |
| 2699 | data->recv_bulk = btusb_recv_bulk_intel; |
| 2700 | set_bit(BTUSB_BOOTLOADER, &data->flags); |
| 2701 | } else { |
| 2702 | data->recv_event = hci_recv_frame; |
| 2703 | data->recv_bulk = btusb_recv_bulk; |
| 2704 | } |
Marcel Holtmann | 2cbd3f5 | 2014-11-03 05:16:07 +0100 | [diff] [blame] | 2705 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2706 | hdev = hci_alloc_dev(); |
Sachin Kamat | 98921db | 2012-07-27 12:38:39 +0530 | [diff] [blame] | 2707 | if (!hdev) |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2708 | return -ENOMEM; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2709 | |
Marcel Holtmann | c13854c | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 2710 | hdev->bus = HCI_USB; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 2711 | hci_set_drvdata(hdev, data); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2712 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 2713 | if (id->driver_info & BTUSB_AMP) |
| 2714 | hdev->dev_type = HCI_AMP; |
| 2715 | else |
| 2716 | hdev->dev_type = HCI_BREDR; |
| 2717 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2718 | data->hdev = hdev; |
| 2719 | |
| 2720 | SET_HCIDEV_DEV(hdev, &intf->dev); |
| 2721 | |
Marcel Holtmann | 9f8f962 | 2013-04-10 08:11:35 -0700 | [diff] [blame] | 2722 | hdev->open = btusb_open; |
| 2723 | hdev->close = btusb_close; |
| 2724 | hdev->flush = btusb_flush; |
| 2725 | hdev->send = btusb_send_frame; |
| 2726 | hdev->notify = btusb_notify; |
| 2727 | |
| 2728 | if (id->driver_info & BTUSB_BCM92035) |
| 2729 | hdev->setup = btusb_setup_bcm92035; |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2730 | |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 2731 | #ifdef CONFIG_BT_HCIBTUSB_BCM |
Marcel Holtmann | abbaf50 | 2014-07-02 00:53:48 +0200 | [diff] [blame] | 2732 | if (id->driver_info & BTUSB_BCM_PATCHRAM) { |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 2733 | hdev->setup = btbcm_setup_patchram; |
Marcel Holtmann | 1df1f59 | 2015-04-05 22:52:11 -0700 | [diff] [blame] | 2734 | hdev->set_bdaddr = btbcm_set_bdaddr; |
Marcel Holtmann | abbaf50 | 2014-07-02 00:53:48 +0200 | [diff] [blame] | 2735 | } |
Petri Gynther | 10d4c67 | 2014-05-08 15:50:01 -0700 | [diff] [blame] | 2736 | |
Marcel Holtmann | 941521e | 2015-04-05 22:52:15 -0700 | [diff] [blame] | 2737 | if (id->driver_info & BTUSB_BCM_APPLE) |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 2738 | hdev->setup = btbcm_setup_apple; |
Marcel Holtmann | c2bfb10 | 2015-04-05 22:52:14 -0700 | [diff] [blame] | 2739 | #endif |
Marcel Holtmann | 17b2772 | 2015-03-22 15:52:38 +0100 | [diff] [blame] | 2740 | |
Marcel Holtmann | cb8d659 | 2014-07-02 11:25:25 +0200 | [diff] [blame] | 2741 | if (id->driver_info & BTUSB_INTEL) { |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2742 | hdev->setup = btusb_setup_intel; |
Tedd Ho-Jeong An | bfbd45e | 2015-02-13 09:20:52 -0800 | [diff] [blame] | 2743 | hdev->shutdown = btusb_shutdown_intel; |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 2744 | hdev->set_bdaddr = btintel_set_bdaddr; |
Jakub Pawlowski | c33fb9b | 2015-01-30 18:55:58 -0800 | [diff] [blame] | 2745 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
Jakub Pawlowski | c115484 | 2015-03-17 09:04:16 -0700 | [diff] [blame] | 2746 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Marcel Holtmann | cb8d659 | 2014-07-02 11:25:25 +0200 | [diff] [blame] | 2747 | } |
Tedd Ho-Jeong An | dffd30e | 2013-04-19 09:57:43 -0700 | [diff] [blame] | 2748 | |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2749 | if (id->driver_info & BTUSB_INTEL_NEW) { |
| 2750 | hdev->send = btusb_send_frame_intel; |
| 2751 | hdev->setup = btusb_setup_intel_new; |
Marcel Holtmann | 385a768 | 2015-01-28 11:09:56 -0800 | [diff] [blame] | 2752 | hdev->hw_error = btusb_hw_error_intel; |
Marcel Holtmann | 4185a0f | 2015-04-06 00:52:12 -0700 | [diff] [blame] | 2753 | hdev->set_bdaddr = btintel_set_bdaddr; |
Marcel Holtmann | b970c5b | 2015-02-01 23:57:18 -0800 | [diff] [blame] | 2754 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
Marcel Holtmann | cda0dd7 | 2015-01-26 21:33:48 -0800 | [diff] [blame] | 2755 | } |
| 2756 | |
Amitkumar Karwar | ae8df49 | 2014-07-18 14:47:06 -0700 | [diff] [blame] | 2757 | if (id->driver_info & BTUSB_MARVELL) |
| 2758 | hdev->set_bdaddr = btusb_set_bdaddr_marvell; |
| 2759 | |
Marcel Holtmann | 661cf88 | 2015-01-02 23:35:20 -0800 | [diff] [blame] | 2760 | if (id->driver_info & BTUSB_SWAVE) { |
| 2761 | set_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks); |
Marcel Holtmann | d57dbe7 | 2014-12-26 04:42:33 +0100 | [diff] [blame] | 2762 | set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks); |
Marcel Holtmann | 661cf88 | 2015-01-02 23:35:20 -0800 | [diff] [blame] | 2763 | } |
Marcel Holtmann | d57dbe7 | 2014-12-26 04:42:33 +0100 | [diff] [blame] | 2764 | |
Marcel Holtmann | 40df783 | 2014-07-06 13:29:58 +0200 | [diff] [blame] | 2765 | if (id->driver_info & BTUSB_INTEL_BOOT) |
| 2766 | set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); |
| 2767 | |
Jakub Pawlowski | 79f0c87 | 2015-01-29 10:38:34 -0800 | [diff] [blame] | 2768 | if (id->driver_info & BTUSB_ATH3012) { |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 2769 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
Jakub Pawlowski | 3d50d51 | 2015-03-17 09:04:15 -0700 | [diff] [blame] | 2770 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Jakub Pawlowski | 79f0c87 | 2015-01-29 10:38:34 -0800 | [diff] [blame] | 2771 | set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); |
| 2772 | } |
Toshi Kikuchi | 5859223 | 2014-12-12 10:58:05 -0800 | [diff] [blame] | 2773 | |
Kim, Ben Young Tae | 3267c88 | 2015-02-15 23:07:33 +0000 | [diff] [blame] | 2774 | if (id->driver_info & BTUSB_QCA_ROME) { |
| 2775 | data->setup_on_usb = btusb_setup_qca; |
| 2776 | hdev->set_bdaddr = btusb_set_bdaddr_ath3012; |
| 2777 | } |
| 2778 | |
Marcel Holtmann | 893ba54 | 2015-01-28 20:27:34 -0800 | [diff] [blame] | 2779 | if (id->driver_info & BTUSB_AMP) { |
| 2780 | /* AMP controllers do not support SCO packets */ |
| 2781 | data->isoc = NULL; |
| 2782 | } else { |
| 2783 | /* Interface numbers are hardcoded in the specification */ |
| 2784 | data->isoc = usb_ifnum_to_if(data->udev, 1); |
| 2785 | } |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 2786 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 2787 | if (!reset) |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 2788 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 2789 | |
| 2790 | if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { |
| 2791 | if (!disable_scofix) |
| 2792 | set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks); |
| 2793 | } |
| 2794 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 2795 | if (id->driver_info & BTUSB_BROKEN_ISOC) |
| 2796 | data->isoc = NULL; |
| 2797 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 2798 | if (id->driver_info & BTUSB_DIGIANSWER) { |
| 2799 | data->cmdreq_type = USB_TYPE_VENDOR; |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 2800 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | if (id->driver_info & BTUSB_CSR) { |
| 2804 | struct usb_device *udev = data->udev; |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 2805 | u16 bcdDevice = le16_to_cpu(udev->descriptor.bcdDevice); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 2806 | |
| 2807 | /* Old firmware would otherwise execute USB reset */ |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 2808 | if (bcdDevice < 0x117) |
Szymon Janc | a6c511c | 2012-05-23 12:35:46 +0200 | [diff] [blame] | 2809 | set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); |
Marcel Holtmann | 81cac64 | 2014-01-03 03:02:36 -0800 | [diff] [blame] | 2810 | |
| 2811 | /* Fake CSR devices with broken commands */ |
| 2812 | if (bcdDevice <= 0x100) |
| 2813 | hdev->setup = btusb_setup_csr; |
Jakub Pawlowski | 49c989a | 2015-03-17 09:04:17 -0700 | [diff] [blame] | 2814 | |
| 2815 | set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks); |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 2816 | } |
| 2817 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 2818 | if (id->driver_info & BTUSB_SNIFFER) { |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 2819 | struct usb_device *udev = data->udev; |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 2820 | |
Marcel Holtmann | 7a9d402 | 2008-11-30 12:17:26 +0100 | [diff] [blame] | 2821 | /* New sniffer firmware has crippled HCI interface */ |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 2822 | if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997) |
| 2823 | set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); |
| 2824 | } |
| 2825 | |
Marcel Holtmann | 3a5ef20 | 2014-07-06 14:53:54 +0200 | [diff] [blame] | 2826 | if (id->driver_info & BTUSB_INTEL_BOOT) { |
| 2827 | /* A bug in the bootloader causes that interrupt interface is |
| 2828 | * only enabled after receiving SetInterface(0, AltSetting=0). |
| 2829 | */ |
| 2830 | err = usb_set_interface(data->udev, 0, 0); |
| 2831 | if (err < 0) { |
| 2832 | BT_ERR("failed to set interface 0, alt 0 %d", err); |
| 2833 | hci_free_dev(hdev); |
| 2834 | return err; |
| 2835 | } |
| 2836 | } |
| 2837 | |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 2838 | if (data->isoc) { |
| 2839 | err = usb_driver_claim_interface(&btusb_driver, |
Marcel Holtmann | 89e7533 | 2014-09-16 04:44:50 +0200 | [diff] [blame] | 2840 | data->isoc, data); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 2841 | if (err < 0) { |
| 2842 | hci_free_dev(hdev); |
Marcel Holtmann | 9bfa35f | 2008-08-18 13:23:52 +0200 | [diff] [blame] | 2843 | return err; |
| 2844 | } |
| 2845 | } |
| 2846 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2847 | err = hci_register_dev(hdev); |
| 2848 | if (err < 0) { |
| 2849 | hci_free_dev(hdev); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2850 | return err; |
| 2851 | } |
| 2852 | |
| 2853 | usb_set_intfdata(intf, data); |
| 2854 | |
| 2855 | return 0; |
| 2856 | } |
| 2857 | |
| 2858 | static void btusb_disconnect(struct usb_interface *intf) |
| 2859 | { |
| 2860 | struct btusb_data *data = usb_get_intfdata(intf); |
| 2861 | struct hci_dev *hdev; |
| 2862 | |
| 2863 | BT_DBG("intf %p", intf); |
| 2864 | |
| 2865 | if (!data) |
| 2866 | return; |
| 2867 | |
| 2868 | hdev = data->hdev; |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 2869 | usb_set_intfdata(data->intf, NULL); |
| 2870 | |
| 2871 | if (data->isoc) |
| 2872 | usb_set_intfdata(data->isoc, NULL); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2873 | |
| 2874 | hci_unregister_dev(hdev); |
| 2875 | |
Marcel Holtmann | 5fbcd26 | 2008-09-23 00:16:36 +0200 | [diff] [blame] | 2876 | if (intf == data->isoc) |
| 2877 | usb_driver_release_interface(&btusb_driver, data->intf); |
| 2878 | else if (data->isoc) |
| 2879 | usb_driver_release_interface(&btusb_driver, data->isoc); |
| 2880 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2881 | hci_free_dev(hdev); |
| 2882 | } |
| 2883 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2884 | #ifdef CONFIG_PM |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2885 | static int btusb_suspend(struct usb_interface *intf, pm_message_t message) |
| 2886 | { |
| 2887 | struct btusb_data *data = usb_get_intfdata(intf); |
| 2888 | |
| 2889 | BT_DBG("intf %p", intf); |
| 2890 | |
| 2891 | if (data->suspend_count++) |
| 2892 | return 0; |
| 2893 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2894 | spin_lock_irq(&data->txlock); |
Alan Stern | 5b1b0b8 | 2011-08-19 23:49:48 +0200 | [diff] [blame] | 2895 | if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) { |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2896 | set_bit(BTUSB_SUSPENDING, &data->flags); |
| 2897 | spin_unlock_irq(&data->txlock); |
| 2898 | } else { |
| 2899 | spin_unlock_irq(&data->txlock); |
| 2900 | data->suspend_count--; |
| 2901 | return -EBUSY; |
| 2902 | } |
| 2903 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2904 | cancel_work_sync(&data->work); |
| 2905 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2906 | btusb_stop_traffic(data); |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2907 | usb_kill_anchored_urbs(&data->tx_anchor); |
| 2908 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2909 | return 0; |
| 2910 | } |
| 2911 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2912 | static void play_deferred(struct btusb_data *data) |
| 2913 | { |
| 2914 | struct urb *urb; |
| 2915 | int err; |
| 2916 | |
| 2917 | while ((urb = usb_get_from_anchor(&data->deferred))) { |
| 2918 | err = usb_submit_urb(urb, GFP_ATOMIC); |
| 2919 | if (err < 0) |
| 2920 | break; |
| 2921 | |
| 2922 | data->tx_in_flight++; |
| 2923 | } |
| 2924 | usb_scuttle_anchored_urbs(&data->deferred); |
| 2925 | } |
| 2926 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2927 | static int btusb_resume(struct usb_interface *intf) |
| 2928 | { |
| 2929 | struct btusb_data *data = usb_get_intfdata(intf); |
| 2930 | struct hci_dev *hdev = data->hdev; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2931 | int err = 0; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2932 | |
| 2933 | BT_DBG("intf %p", intf); |
| 2934 | |
| 2935 | if (--data->suspend_count) |
| 2936 | return 0; |
| 2937 | |
| 2938 | if (!test_bit(HCI_RUNNING, &hdev->flags)) |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2939 | goto done; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2940 | |
| 2941 | if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) { |
| 2942 | err = btusb_submit_intr_urb(hdev, GFP_NOIO); |
| 2943 | if (err < 0) { |
| 2944 | clear_bit(BTUSB_INTR_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2945 | goto failed; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) { |
Marcel Holtmann | 43c2e57 | 2009-02-04 17:41:38 +0100 | [diff] [blame] | 2950 | err = btusb_submit_bulk_urb(hdev, GFP_NOIO); |
| 2951 | if (err < 0) { |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2952 | clear_bit(BTUSB_BULK_RUNNING, &data->flags); |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2953 | goto failed; |
| 2954 | } |
| 2955 | |
| 2956 | btusb_submit_bulk_urb(hdev, GFP_NOIO); |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) { |
| 2960 | if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0) |
| 2961 | clear_bit(BTUSB_ISOC_RUNNING, &data->flags); |
| 2962 | else |
| 2963 | btusb_submit_isoc_urb(hdev, GFP_NOIO); |
| 2964 | } |
| 2965 | |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2966 | spin_lock_irq(&data->txlock); |
| 2967 | play_deferred(data); |
| 2968 | clear_bit(BTUSB_SUSPENDING, &data->flags); |
| 2969 | spin_unlock_irq(&data->txlock); |
| 2970 | schedule_work(&data->work); |
| 2971 | |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2972 | return 0; |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2973 | |
| 2974 | failed: |
| 2975 | usb_scuttle_anchored_urbs(&data->deferred); |
| 2976 | done: |
| 2977 | spin_lock_irq(&data->txlock); |
| 2978 | clear_bit(BTUSB_SUSPENDING, &data->flags); |
| 2979 | spin_unlock_irq(&data->txlock); |
| 2980 | |
| 2981 | return err; |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2982 | } |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2983 | #endif |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2984 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2985 | static struct usb_driver btusb_driver = { |
| 2986 | .name = "btusb", |
| 2987 | .probe = btusb_probe, |
| 2988 | .disconnect = btusb_disconnect, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2989 | #ifdef CONFIG_PM |
Marcel Holtmann | 6a88adf | 2008-11-30 12:17:14 +0100 | [diff] [blame] | 2990 | .suspend = btusb_suspend, |
| 2991 | .resume = btusb_resume, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2992 | #endif |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2993 | .id_table = btusb_table, |
Oliver Neukum | 7bee549 | 2009-08-24 23:44:59 +0200 | [diff] [blame] | 2994 | .supports_autosuspend = 1, |
Sarah Sharp | e1f12eb | 2012-04-23 10:08:51 -0700 | [diff] [blame] | 2995 | .disable_hub_initiated_lpm = 1, |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2996 | }; |
| 2997 | |
Greg Kroah-Hartman | 93f1508 | 2011-11-18 09:47:34 -0800 | [diff] [blame] | 2998 | module_usb_driver(btusb_driver); |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 2999 | |
Marcel Holtmann | cfeb414 | 2008-08-07 22:26:56 +0200 | [diff] [blame] | 3000 | module_param(disable_scofix, bool, 0644); |
| 3001 | MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size"); |
| 3002 | |
| 3003 | module_param(force_scofix, bool, 0644); |
| 3004 | MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size"); |
| 3005 | |
| 3006 | module_param(reset, bool, 0644); |
| 3007 | MODULE_PARM_DESC(reset, "Send HCI reset command on initialization"); |
| 3008 | |
Marcel Holtmann | 5e23b92 | 2007-10-20 14:12:34 +0200 | [diff] [blame] | 3009 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); |
| 3010 | MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION); |
| 3011 | MODULE_VERSION(VERSION); |
| 3012 | MODULE_LICENSE("GPL"); |