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