diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2015-01-27 00:33:48 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2015-01-28 15:25:50 -0500 |
commit | cda0dd7809f89e8d7f88335690d84b8482d33111 (patch) | |
tree | 0a45c9257a790e9d60ff0da0090efe3091fdc64b /drivers/bluetooth/btusb.c | |
parent | d049f4e513e861167361b06c7ca85f9e872c8cde (diff) |
Bluetooth: btusb: Add firmware loading for Intel Snowfield Peak devices
The Intel Snowfield Peak devices do not come with Bluetooth firmware
loaded and thus require a full download of the operational Bluetooth
firmware when the device is connected via USB.
Snowfield Peak devices start with a bootloader mode that only accepts
a very limited set of HCI commands. The supported commands are enough
to identify the hardware and select the right firmware to load.
Previous patches to the btusb driver allow overwriting the handling
for bulk receive endpoint packets and HCI events processing. The
firmware loading makes heavy use of these new internal callbacks.
This patch also introduces additional internal states to track if the
device is in bootloader or operational mode. This allows for correct
feedback about the firmware loading procedure.
Output from /sys/kernel/debug/usb/devices for this device:
T: Bus=02 Lev=02 Prnt=02 Port=05 Cnt=01 Dev#= 3 Spd=12 MxCh= 0
D: Ver= 2.01 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs= 1
P: Vendor=8087 ProdID=0a2b Rev= 0.01
C:* #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA
I:* If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E: Ad=81(I) Atr=03(Int.) MxPS= 64 Ivl=1ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E: Ad=03(O) Atr=01(Isoc) MxPS= 0 Ivl=1ms
E: Ad=83(I) Atr=01(Isoc) MxPS= 0 Ivl=1ms
I: If#= 1 Alt= 1 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E: Ad=03(O) Atr=01(Isoc) MxPS= 9 Ivl=1ms
E: Ad=83(I) Atr=01(Isoc) MxPS= 9 Ivl=1ms
I: If#= 1 Alt= 2 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E: Ad=03(O) Atr=01(Isoc) MxPS= 17 Ivl=1ms
E: Ad=83(I) Atr=01(Isoc) MxPS= 17 Ivl=1ms
I: If#= 1 Alt= 3 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E: Ad=03(O) Atr=01(Isoc) MxPS= 25 Ivl=1ms
E: Ad=83(I) Atr=01(Isoc) MxPS= 25 Ivl=1ms
I: If#= 1 Alt= 4 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E: Ad=03(O) Atr=01(Isoc) MxPS= 33 Ivl=1ms
E: Ad=83(I) Atr=01(Isoc) MxPS= 33 Ivl=1ms
I: If#= 1 Alt= 5 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
E: Ad=03(O) Atr=01(Isoc) MxPS= 49 Ivl=1ms
E: Ad=83(I) Atr=01(Isoc) MxPS= 49 Ivl=1ms
Based-on-patch-by: Tedd Ho-Jeong An <tedd.an@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'drivers/bluetooth/btusb.c')
-rw-r--r-- | drivers/bluetooth/btusb.c | 571 |
1 files changed, 568 insertions, 3 deletions
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 2901e703809d..4fac6927ee11 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include <net/bluetooth/bluetooth.h> | 28 | #include <net/bluetooth/bluetooth.h> |
29 | #include <net/bluetooth/hci_core.h> | 29 | #include <net/bluetooth/hci_core.h> |
30 | 30 | ||
31 | #define VERSION "0.6" | 31 | #define VERSION "0.7" |
32 | 32 | ||
33 | static bool disable_scofix; | 33 | static bool disable_scofix; |
34 | static bool force_scofix; | 34 | static bool force_scofix; |
@@ -50,6 +50,7 @@ static struct usb_driver btusb_driver; | |||
50 | #define BTUSB_BCM_PATCHRAM 0x400 | 50 | #define BTUSB_BCM_PATCHRAM 0x400 |
51 | #define BTUSB_MARVELL 0x800 | 51 | #define BTUSB_MARVELL 0x800 |
52 | #define BTUSB_SWAVE 0x1000 | 52 | #define BTUSB_SWAVE 0x1000 |
53 | #define BTUSB_INTEL_NEW 0x2000 | ||
53 | 54 | ||
54 | static const struct usb_device_id btusb_table[] = { | 55 | static const struct usb_device_id btusb_table[] = { |
55 | /* Generic Bluetooth USB device */ | 56 | /* Generic Bluetooth USB device */ |
@@ -261,6 +262,7 @@ static const struct usb_device_id blacklist_table[] = { | |||
261 | /* Intel Bluetooth device */ | 262 | /* Intel Bluetooth device */ |
262 | { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL }, | 263 | { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL }, |
263 | { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL }, | 264 | { USB_DEVICE(0x8087, 0x0a2a), .driver_info = BTUSB_INTEL }, |
265 | { USB_DEVICE(0x8087, 0x0a2b), .driver_info = BTUSB_INTEL_NEW }, | ||
264 | 266 | ||
265 | /* Marvell device */ | 267 | /* Marvell device */ |
266 | { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL }, | 268 | { USB_DEVICE(0x1286, 0x2044), .driver_info = BTUSB_MARVELL }, |
@@ -276,6 +278,10 @@ static const struct usb_device_id blacklist_table[] = { | |||
276 | #define BTUSB_ISOC_RUNNING 2 | 278 | #define BTUSB_ISOC_RUNNING 2 |
277 | #define BTUSB_SUSPENDING 3 | 279 | #define BTUSB_SUSPENDING 3 |
278 | #define BTUSB_DID_ISO_RESUME 4 | 280 | #define BTUSB_DID_ISO_RESUME 4 |
281 | #define BTUSB_BOOTLOADER 5 | ||
282 | #define BTUSB_DOWNLOADING 6 | ||
283 | #define BTUSB_BOOTING 7 | ||
284 | #define BTUSB_FIRMWARE_FAILED 8 | ||
279 | 285 | ||
280 | struct btusb_data { | 286 | struct btusb_data { |
281 | struct hci_dev *hdev; | 287 | struct hci_dev *hdev; |
@@ -1300,6 +1306,26 @@ struct intel_version { | |||
1300 | u8 fw_patch_num; | 1306 | u8 fw_patch_num; |
1301 | } __packed; | 1307 | } __packed; |
1302 | 1308 | ||
1309 | struct intel_boot_params { | ||
1310 | __u8 status; | ||
1311 | __u8 otp_format; | ||
1312 | __u8 otp_content; | ||
1313 | __u8 otp_patch; | ||
1314 | __le16 dev_revid; | ||
1315 | __u8 secure_boot; | ||
1316 | __u8 key_from_hdr; | ||
1317 | __u8 key_type; | ||
1318 | __u8 otp_lock; | ||
1319 | __u8 api_lock; | ||
1320 | __u8 debug_lock; | ||
1321 | bdaddr_t otp_bdaddr; | ||
1322 | __u8 min_fw_build_nn; | ||
1323 | __u8 min_fw_build_cw; | ||
1324 | __u8 min_fw_build_yy; | ||
1325 | __u8 limited_cce; | ||
1326 | __u8 unlocked_state; | ||
1327 | } __packed; | ||
1328 | |||
1303 | static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev, | 1329 | static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev, |
1304 | struct intel_version *ver) | 1330 | struct intel_version *ver) |
1305 | { | 1331 | { |
@@ -1708,6 +1734,533 @@ exit_mfg_deactivate: | |||
1708 | return 0; | 1734 | return 0; |
1709 | } | 1735 | } |
1710 | 1736 | ||
1737 | static int inject_cmd_complete(struct hci_dev *hdev, __u16 opcode) | ||
1738 | { | ||
1739 | struct sk_buff *skb; | ||
1740 | struct hci_event_hdr *hdr; | ||
1741 | struct hci_ev_cmd_complete *evt; | ||
1742 | |||
1743 | skb = bt_skb_alloc(sizeof(*hdr) + sizeof(*evt) + 1, GFP_ATOMIC); | ||
1744 | if (!skb) | ||
1745 | return -ENOMEM; | ||
1746 | |||
1747 | hdr = (struct hci_event_hdr *)skb_put(skb, sizeof(*hdr)); | ||
1748 | hdr->evt = HCI_EV_CMD_COMPLETE; | ||
1749 | hdr->plen = sizeof(*evt) + 1; | ||
1750 | |||
1751 | evt = (struct hci_ev_cmd_complete *)skb_put(skb, sizeof(*evt)); | ||
1752 | evt->ncmd = 0x01; | ||
1753 | evt->opcode = cpu_to_le16(opcode); | ||
1754 | |||
1755 | *skb_put(skb, 1) = 0x00; | ||
1756 | |||
1757 | bt_cb(skb)->pkt_type = HCI_EVENT_PKT; | ||
1758 | |||
1759 | return hci_recv_frame(hdev, skb); | ||
1760 | } | ||
1761 | |||
1762 | static int btusb_recv_bulk_intel(struct btusb_data *data, void *buffer, | ||
1763 | int count) | ||
1764 | { | ||
1765 | /* When the device is in bootloader mode, then it can send | ||
1766 | * events via the bulk endpoint. These events are treated the | ||
1767 | * same way as the ones received from the interrupt endpoint. | ||
1768 | */ | ||
1769 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) | ||
1770 | return btusb_recv_intr(data, buffer, count); | ||
1771 | |||
1772 | return btusb_recv_bulk(data, buffer, count); | ||
1773 | } | ||
1774 | |||
1775 | static int btusb_recv_event_intel(struct hci_dev *hdev, struct sk_buff *skb) | ||
1776 | { | ||
1777 | struct btusb_data *data = hci_get_drvdata(hdev); | ||
1778 | |||
1779 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) { | ||
1780 | struct hci_event_hdr *hdr = (void *)skb->data; | ||
1781 | |||
1782 | /* When the firmware loading completes the device sends | ||
1783 | * out a vendor specific event indicating the result of | ||
1784 | * the firmware loading. | ||
1785 | */ | ||
1786 | if (skb->len == 7 && hdr->evt == 0xff && hdr->plen == 0x05 && | ||
1787 | skb->data[2] == 0x06) { | ||
1788 | if (skb->data[3] != 0x00) | ||
1789 | test_bit(BTUSB_FIRMWARE_FAILED, &data->flags); | ||
1790 | |||
1791 | if (test_and_clear_bit(BTUSB_DOWNLOADING, &data->flags)) | ||
1792 | wake_up_interruptible(&hdev->req_wait_q); | ||
1793 | } | ||
1794 | |||
1795 | /* When switching to the operational firmware the device | ||
1796 | * sends a vendor specific event indicating that the bootup | ||
1797 | * completed. | ||
1798 | */ | ||
1799 | if (skb->len == 9 && hdr->evt == 0xff && hdr->plen == 0x07 && | ||
1800 | skb->data[2] == 0x02) { | ||
1801 | if (test_and_clear_bit(BTUSB_BOOTING, &data->flags)) | ||
1802 | wake_up_interruptible(&hdev->req_wait_q); | ||
1803 | } | ||
1804 | } | ||
1805 | |||
1806 | return hci_recv_frame(hdev, skb); | ||
1807 | } | ||
1808 | |||
1809 | static int btusb_send_frame_intel(struct hci_dev *hdev, struct sk_buff *skb) | ||
1810 | { | ||
1811 | struct btusb_data *data = hci_get_drvdata(hdev); | ||
1812 | struct urb *urb; | ||
1813 | |||
1814 | BT_DBG("%s", hdev->name); | ||
1815 | |||
1816 | if (!test_bit(HCI_RUNNING, &hdev->flags)) | ||
1817 | return -EBUSY; | ||
1818 | |||
1819 | switch (bt_cb(skb)->pkt_type) { | ||
1820 | case HCI_COMMAND_PKT: | ||
1821 | if (test_bit(BTUSB_BOOTLOADER, &data->flags)) { | ||
1822 | struct hci_command_hdr *cmd = (void *)skb->data; | ||
1823 | __u16 opcode = le16_to_cpu(cmd->opcode); | ||
1824 | |||
1825 | /* When in bootloader mode and the command 0xfc09 | ||
1826 | * is received, it needs to be send down the | ||
1827 | * bulk endpoint. So allocate a bulk URB instead. | ||
1828 | */ | ||
1829 | if (opcode == 0xfc09) | ||
1830 | urb = alloc_bulk_urb(hdev, skb); | ||
1831 | else | ||
1832 | urb = alloc_ctrl_urb(hdev, skb); | ||
1833 | |||
1834 | /* When the 0xfc01 command is issued to boot into | ||
1835 | * the operational firmware, it will actually not | ||
1836 | * send a command complete event. To keep the flow | ||
1837 | * control working inject that event here. | ||
1838 | */ | ||
1839 | if (opcode == 0xfc01) | ||
1840 | inject_cmd_complete(hdev, opcode); | ||
1841 | } else { | ||
1842 | urb = alloc_ctrl_urb(hdev, skb); | ||
1843 | } | ||
1844 | if (IS_ERR(urb)) | ||
1845 | return PTR_ERR(urb); | ||
1846 | |||
1847 | hdev->stat.cmd_tx++; | ||
1848 | return submit_or_queue_tx_urb(hdev, urb); | ||
1849 | |||
1850 | case HCI_ACLDATA_PKT: | ||
1851 | urb = alloc_bulk_urb(hdev, skb); | ||
1852 | if (IS_ERR(urb)) | ||
1853 | return PTR_ERR(urb); | ||
1854 | |||
1855 | hdev->stat.acl_tx++; | ||
1856 | return submit_or_queue_tx_urb(hdev, urb); | ||
1857 | |||
1858 | case HCI_SCODATA_PKT: | ||
1859 | if (hci_conn_num(hdev, SCO_LINK) < 1) | ||
1860 | return -ENODEV; | ||
1861 | |||
1862 | urb = alloc_isoc_urb(hdev, skb); | ||
1863 | if (IS_ERR(urb)) | ||
1864 | return PTR_ERR(urb); | ||
1865 | |||
1866 | hdev->stat.sco_tx++; | ||
1867 | return submit_tx_urb(hdev, urb); | ||
1868 | } | ||
1869 | |||
1870 | return -EILSEQ; | ||
1871 | } | ||
1872 | |||
1873 | static int btusb_intel_secure_send(struct hci_dev *hdev, u8 fragment_type, | ||
1874 | u32 plen, const void *param) | ||
1875 | { | ||
1876 | while (plen > 0) { | ||
1877 | struct sk_buff *skb; | ||
1878 | u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen; | ||
1879 | |||
1880 | cmd_param[0] = fragment_type; | ||
1881 | memcpy(cmd_param + 1, param, fragment_len); | ||
1882 | |||
1883 | skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1, | ||
1884 | cmd_param, HCI_INIT_TIMEOUT); | ||
1885 | if (IS_ERR(skb)) | ||
1886 | return PTR_ERR(skb); | ||
1887 | |||
1888 | kfree_skb(skb); | ||
1889 | |||
1890 | plen -= fragment_len; | ||
1891 | param += fragment_len; | ||
1892 | } | ||
1893 | |||
1894 | return 0; | ||
1895 | } | ||
1896 | |||
1897 | static void btusb_intel_version_info(struct hci_dev *hdev, | ||
1898 | struct intel_version *ver) | ||
1899 | { | ||
1900 | const char *variant; | ||
1901 | |||
1902 | switch (ver->fw_variant) { | ||
1903 | case 0x06: | ||
1904 | variant = "Bootloader"; | ||
1905 | break; | ||
1906 | case 0x23: | ||
1907 | variant = "Firmware"; | ||
1908 | break; | ||
1909 | default: | ||
1910 | return; | ||
1911 | } | ||
1912 | |||
1913 | BT_INFO("%s: %s revision %u.%u build %u week %u %u", hdev->name, | ||
1914 | variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f, | ||
1915 | ver->fw_build_num, ver->fw_build_ww, 2000 + ver->fw_build_yy); | ||
1916 | } | ||
1917 | |||
1918 | static int btusb_setup_intel_new(struct hci_dev *hdev) | ||
1919 | { | ||
1920 | static const u8 reset_param[] = { 0x00, 0x01, 0x00, 0x01, | ||
1921 | 0x00, 0x08, 0x04, 0x00 }; | ||
1922 | struct btusb_data *data = hci_get_drvdata(hdev); | ||
1923 | struct sk_buff *skb; | ||
1924 | struct intel_version *ver; | ||
1925 | struct intel_boot_params *params; | ||
1926 | const struct firmware *fw; | ||
1927 | const u8 *fw_ptr; | ||
1928 | char fwname[64]; | ||
1929 | ktime_t calltime, delta, rettime; | ||
1930 | unsigned long long duration; | ||
1931 | int err; | ||
1932 | |||
1933 | BT_DBG("%s", hdev->name); | ||
1934 | |||
1935 | calltime = ktime_get(); | ||
1936 | |||
1937 | /* Read the Intel version information to determine if the device | ||
1938 | * is in bootloader mode or if it already has operational firmware | ||
1939 | * loaded. | ||
1940 | */ | ||
1941 | skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT); | ||
1942 | if (IS_ERR(skb)) { | ||
1943 | BT_ERR("%s: Reading Intel version information failed (%ld)", | ||
1944 | hdev->name, PTR_ERR(skb)); | ||
1945 | return PTR_ERR(skb); | ||
1946 | } | ||
1947 | |||
1948 | if (skb->len != sizeof(*ver)) { | ||
1949 | BT_ERR("%s: Intel version event size mismatch", hdev->name); | ||
1950 | kfree_skb(skb); | ||
1951 | return -EILSEQ; | ||
1952 | } | ||
1953 | |||
1954 | ver = (struct intel_version *)skb->data; | ||
1955 | if (ver->status) { | ||
1956 | BT_ERR("%s: Intel version command failure (%02x)", | ||
1957 | hdev->name, ver->status); | ||
1958 | err = -bt_to_errno(ver->status); | ||
1959 | kfree_skb(skb); | ||
1960 | return err; | ||
1961 | } | ||
1962 | |||
1963 | /* The hardware platform number has a fixed value of 0x37 and | ||
1964 | * for now only accept this single value. | ||
1965 | */ | ||
1966 | if (ver->hw_platform != 0x37) { | ||
1967 | BT_ERR("%s: Unsupported Intel hardware platform (%u)", | ||
1968 | hdev->name, ver->hw_platform); | ||
1969 | kfree_skb(skb); | ||
1970 | return -EINVAL; | ||
1971 | } | ||
1972 | |||
1973 | /* At the moment only the hardware variant iBT 3.0 (LnP/SfP) is | ||
1974 | * supported by this firmware loading method. This check has been | ||
1975 | * put in place to ensure correct forward compatibility options | ||
1976 | * when newer hardware variants come along. | ||
1977 | */ | ||
1978 | if (ver->hw_variant != 0x0b) { | ||
1979 | BT_ERR("%s: Unsupported Intel hardware variant (%u)", | ||
1980 | hdev->name, ver->hw_variant); | ||
1981 | kfree_skb(skb); | ||
1982 | return -EINVAL; | ||
1983 | } | ||
1984 | |||
1985 | btusb_intel_version_info(hdev, ver); | ||
1986 | |||
1987 | /* The firmware variant determines if the device is in bootloader | ||
1988 | * mode or is running operational firmware. The value 0x06 identifies | ||
1989 | * the bootloader and the value 0x23 identifies the operational | ||
1990 | * firmware. | ||
1991 | * | ||
1992 | * When the operational firmware is already present, then only | ||
1993 | * the check for valid Bluetooth device address is needed. This | ||
1994 | * determines if the device will be added as configured or | ||
1995 | * unconfigured controller. | ||
1996 | * | ||
1997 | * It is not possible to use the Secure Boot Parameters in this | ||
1998 | * case since that command is only available in bootloader mode. | ||
1999 | */ | ||
2000 | if (ver->fw_variant == 0x23) { | ||
2001 | kfree_skb(skb); | ||
2002 | clear_bit(BTUSB_BOOTLOADER, &data->flags); | ||
2003 | btusb_check_bdaddr_intel(hdev); | ||
2004 | return 0; | ||
2005 | } | ||
2006 | |||
2007 | /* If the device is not in bootloader mode, then the only possible | ||
2008 | * choice is to return an error and abort the device initialization. | ||
2009 | */ | ||
2010 | if (ver->fw_variant != 0x06) { | ||
2011 | BT_ERR("%s: Unsupported Intel firmware variant (%u)", | ||
2012 | hdev->name, ver->fw_variant); | ||
2013 | kfree_skb(skb); | ||
2014 | return -ENODEV; | ||
2015 | } | ||
2016 | |||
2017 | kfree_skb(skb); | ||
2018 | |||
2019 | /* Read the secure boot parameters to identify the operating | ||
2020 | * details of the bootloader. | ||
2021 | */ | ||
2022 | skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT); | ||
2023 | if (IS_ERR(skb)) { | ||
2024 | BT_ERR("%s: Reading Intel boot parameters failed (%ld)", | ||
2025 | hdev->name, PTR_ERR(skb)); | ||
2026 | return PTR_ERR(skb); | ||
2027 | } | ||
2028 | |||
2029 | if (skb->len != sizeof(*params)) { | ||
2030 | BT_ERR("%s: Intel boot parameters size mismatch", hdev->name); | ||
2031 | kfree_skb(skb); | ||
2032 | return -EILSEQ; | ||
2033 | } | ||
2034 | |||
2035 | params = (struct intel_boot_params *)skb->data; | ||
2036 | if (params->status) { | ||
2037 | BT_ERR("%s: Intel boot parameters command failure (%02x)", | ||
2038 | hdev->name, params->status); | ||
2039 | err = -bt_to_errno(params->status); | ||
2040 | kfree_skb(skb); | ||
2041 | return err; | ||
2042 | } | ||
2043 | |||
2044 | BT_INFO("%s: Device revision is %u", hdev->name, | ||
2045 | le16_to_cpu(params->dev_revid)); | ||
2046 | |||
2047 | BT_INFO("%s: Secure boot is %s", hdev->name, | ||
2048 | params->secure_boot ? "enabled" : "disabled"); | ||
2049 | |||
2050 | BT_INFO("%s: Minimum firmware build %u week %u %u", hdev->name, | ||
2051 | params->min_fw_build_nn, params->min_fw_build_cw, | ||
2052 | 2000 + params->min_fw_build_yy); | ||
2053 | |||
2054 | /* It is required that every single firmware fragment is acknowledged | ||
2055 | * with a command complete event. If the boot parameters indicate | ||
2056 | * that this bootloader does not send them, then abort the setup. | ||
2057 | */ | ||
2058 | if (params->limited_cce != 0x00) { | ||
2059 | BT_ERR("%s: Unsupported Intel firmware loading method (%u)", | ||
2060 | hdev->name, params->limited_cce); | ||
2061 | kfree_skb(skb); | ||
2062 | return -EINVAL; | ||
2063 | } | ||
2064 | |||
2065 | /* If the OTP has no valid Bluetooth device address, then there will | ||
2066 | * also be no valid address for the operational firmware. | ||
2067 | */ | ||
2068 | if (!bacmp(¶ms->otp_bdaddr, BDADDR_ANY)) { | ||
2069 | BT_INFO("%s: No device address configured", hdev->name); | ||
2070 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); | ||
2071 | } | ||
2072 | |||
2073 | /* With this Intel bootloader only the hardware variant and device | ||
2074 | * revision information are used to select the right firmware. | ||
2075 | * | ||
2076 | * Currently this bootloader support is limited to hardware variant | ||
2077 | * iBT 3.0 (LnP/SfP) which is identified by the value 11 (0x0b). | ||
2078 | */ | ||
2079 | snprintf(fwname, sizeof(fwname), "intel/ibt-11-%u.sfi", | ||
2080 | le16_to_cpu(params->dev_revid)); | ||
2081 | |||
2082 | err = request_firmware(&fw, fwname, &hdev->dev); | ||
2083 | if (err < 0) { | ||
2084 | BT_ERR("%s: Failed to load Intel firmware file (%d)", | ||
2085 | hdev->name, err); | ||
2086 | kfree_skb(skb); | ||
2087 | return err; | ||
2088 | } | ||
2089 | |||
2090 | BT_INFO("%s: Found device firmware: %s", hdev->name, fwname); | ||
2091 | |||
2092 | kfree_skb(skb); | ||
2093 | |||
2094 | if (fw->size < 644) { | ||
2095 | BT_ERR("%s: Invalid size of firmware file (%zu)", | ||
2096 | hdev->name, fw->size); | ||
2097 | err = -EBADF; | ||
2098 | goto done; | ||
2099 | } | ||
2100 | |||
2101 | set_bit(BTUSB_DOWNLOADING, &data->flags); | ||
2102 | |||
2103 | /* Start the firmware download transaction with the Init fragment | ||
2104 | * represented by the 128 bytes of CSS header. | ||
2105 | */ | ||
2106 | err = btusb_intel_secure_send(hdev, 0x00, 128, fw->data); | ||
2107 | if (err < 0) { | ||
2108 | BT_ERR("%s: Failed to send firmware header (%d)", | ||
2109 | hdev->name, err); | ||
2110 | goto done; | ||
2111 | } | ||
2112 | |||
2113 | /* Send the 256 bytes of public key information from the firmware | ||
2114 | * as the PKey fragment. | ||
2115 | */ | ||
2116 | err = btusb_intel_secure_send(hdev, 0x03, 256, fw->data + 128); | ||
2117 | if (err < 0) { | ||
2118 | BT_ERR("%s: Failed to send firmware public key (%d)", | ||
2119 | hdev->name, err); | ||
2120 | goto done; | ||
2121 | } | ||
2122 | |||
2123 | /* Send the 256 bytes of signature information from the firmware | ||
2124 | * as the Sign fragment. | ||
2125 | */ | ||
2126 | err = btusb_intel_secure_send(hdev, 0x02, 256, fw->data + 388); | ||
2127 | if (err < 0) { | ||
2128 | BT_ERR("%s: Failed to send firmware signature (%d)", | ||
2129 | hdev->name, err); | ||
2130 | goto done; | ||
2131 | } | ||
2132 | |||
2133 | fw_ptr = fw->data + 644; | ||
2134 | |||
2135 | while (fw_ptr - fw->data < fw->size) { | ||
2136 | struct hci_command_hdr *cmd = (void *)fw_ptr; | ||
2137 | u8 cmd_len; | ||
2138 | |||
2139 | cmd_len = sizeof(*cmd) + cmd->plen; | ||
2140 | |||
2141 | /* Send each command from the firmware data buffer as | ||
2142 | * a single Data fragment. | ||
2143 | */ | ||
2144 | err = btusb_intel_secure_send(hdev, 0x01, cmd_len, fw_ptr); | ||
2145 | if (err < 0) { | ||
2146 | BT_ERR("%s: Failed to send firmware data (%d)", | ||
2147 | hdev->name, err); | ||
2148 | goto done; | ||
2149 | } | ||
2150 | |||
2151 | fw_ptr += cmd_len; | ||
2152 | } | ||
2153 | |||
2154 | /* Before switching the device into operational mode and with that | ||
2155 | * booting the loaded firmware, wait for the bootloader notification | ||
2156 | * that all fragments have been successfully received. | ||
2157 | * | ||
2158 | * When the event processing receives the notification, then this | ||
2159 | * flag will be cleared. So just in case that happens really quickly, | ||
2160 | * check it first before adding the wait queue. | ||
2161 | */ | ||
2162 | if (test_bit(BTUSB_DOWNLOADING, &data->flags)) { | ||
2163 | DECLARE_WAITQUEUE(wait, current); | ||
2164 | signed long timeout; | ||
2165 | |||
2166 | BT_INFO("%s: Waiting for firmware download to complete", | ||
2167 | hdev->name); | ||
2168 | |||
2169 | add_wait_queue(&hdev->req_wait_q, &wait); | ||
2170 | set_current_state(TASK_INTERRUPTIBLE); | ||
2171 | |||
2172 | /* The firmware loading should not take longer than 5 seconds | ||
2173 | * and thus just timeout if that happens and fail the setup | ||
2174 | * of this device. | ||
2175 | */ | ||
2176 | timeout = schedule_timeout(msecs_to_jiffies(5000)); | ||
2177 | |||
2178 | remove_wait_queue(&hdev->req_wait_q, &wait); | ||
2179 | |||
2180 | if (signal_pending(current)) { | ||
2181 | BT_ERR("%s: Firmware loading interrupted", hdev->name); | ||
2182 | err = -EINTR; | ||
2183 | goto done; | ||
2184 | } | ||
2185 | |||
2186 | if (!timeout) { | ||
2187 | BT_ERR("%s: Firmware loading timeout", hdev->name); | ||
2188 | err = -ETIMEDOUT; | ||
2189 | goto done; | ||
2190 | } | ||
2191 | } | ||
2192 | |||
2193 | if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) { | ||
2194 | BT_ERR("%s: Firmware loading failed", hdev->name); | ||
2195 | err = -ENOEXEC; | ||
2196 | goto done; | ||
2197 | } | ||
2198 | |||
2199 | rettime = ktime_get(); | ||
2200 | delta = ktime_sub(rettime, calltime); | ||
2201 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; | ||
2202 | |||
2203 | BT_INFO("%s: Firmware loaded in %llu usecs", hdev->name, duration); | ||
2204 | |||
2205 | done: | ||
2206 | release_firmware(fw); | ||
2207 | |||
2208 | if (err < 0) | ||
2209 | return err; | ||
2210 | |||
2211 | calltime = ktime_get(); | ||
2212 | |||
2213 | set_bit(BTUSB_BOOTING, &data->flags); | ||
2214 | |||
2215 | skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(reset_param), reset_param, | ||
2216 | HCI_INIT_TIMEOUT); | ||
2217 | if (IS_ERR(skb)) | ||
2218 | return PTR_ERR(skb); | ||
2219 | |||
2220 | kfree_skb(skb); | ||
2221 | |||
2222 | /* The bootloader will not indicate when the device is ready. This | ||
2223 | * is done by the operational firmware sending bootup notification. | ||
2224 | */ | ||
2225 | if (test_bit(BTUSB_BOOTING, &data->flags)) { | ||
2226 | DECLARE_WAITQUEUE(wait, current); | ||
2227 | signed long timeout; | ||
2228 | |||
2229 | BT_INFO("%s: Waiting for device to boot", hdev->name); | ||
2230 | |||
2231 | add_wait_queue(&hdev->req_wait_q, &wait); | ||
2232 | set_current_state(TASK_INTERRUPTIBLE); | ||
2233 | |||
2234 | /* Booting into operational firmware should not take | ||
2235 | * longer than 1 second. However if that happens, then | ||
2236 | * just fail the setup since something went wrong. | ||
2237 | */ | ||
2238 | timeout = schedule_timeout(msecs_to_jiffies(1000)); | ||
2239 | |||
2240 | remove_wait_queue(&hdev->req_wait_q, &wait); | ||
2241 | |||
2242 | if (signal_pending(current)) { | ||
2243 | BT_ERR("%s: Device boot interrupted", hdev->name); | ||
2244 | return -EINTR; | ||
2245 | } | ||
2246 | |||
2247 | if (!timeout) { | ||
2248 | BT_ERR("%s: Device boot timeout", hdev->name); | ||
2249 | return -ETIMEDOUT; | ||
2250 | } | ||
2251 | } | ||
2252 | |||
2253 | rettime = ktime_get(); | ||
2254 | delta = ktime_sub(rettime, calltime); | ||
2255 | duration = (unsigned long long) ktime_to_ns(delta) >> 10; | ||
2256 | |||
2257 | BT_INFO("%s: Device booted in %llu usecs", hdev->name, duration); | ||
2258 | |||
2259 | clear_bit(BTUSB_BOOTLOADER, &data->flags); | ||
2260 | |||
2261 | return 0; | ||
2262 | } | ||
2263 | |||
1711 | static int btusb_set_bdaddr_intel(struct hci_dev *hdev, const bdaddr_t *bdaddr) | 2264 | static int btusb_set_bdaddr_intel(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
1712 | { | 2265 | { |
1713 | struct sk_buff *skb; | 2266 | struct sk_buff *skb; |
@@ -2054,8 +2607,14 @@ static int btusb_probe(struct usb_interface *intf, | |||
2054 | init_usb_anchor(&data->isoc_anchor); | 2607 | init_usb_anchor(&data->isoc_anchor); |
2055 | spin_lock_init(&data->rxlock); | 2608 | spin_lock_init(&data->rxlock); |
2056 | 2609 | ||
2057 | data->recv_event = hci_recv_frame; | 2610 | if (id->driver_info & BTUSB_INTEL_NEW) { |
2058 | data->recv_bulk = btusb_recv_bulk; | 2611 | data->recv_event = btusb_recv_event_intel; |
2612 | data->recv_bulk = btusb_recv_bulk_intel; | ||
2613 | set_bit(BTUSB_BOOTLOADER, &data->flags); | ||
2614 | } else { | ||
2615 | data->recv_event = hci_recv_frame; | ||
2616 | data->recv_bulk = btusb_recv_bulk; | ||
2617 | } | ||
2059 | 2618 | ||
2060 | hdev = hci_alloc_dev(); | 2619 | hdev = hci_alloc_dev(); |
2061 | if (!hdev) | 2620 | if (!hdev) |
@@ -2088,6 +2647,12 @@ static int btusb_probe(struct usb_interface *intf, | |||
2088 | hdev->set_bdaddr = btusb_set_bdaddr_intel; | 2647 | hdev->set_bdaddr = btusb_set_bdaddr_intel; |
2089 | } | 2648 | } |
2090 | 2649 | ||
2650 | if (id->driver_info & BTUSB_INTEL_NEW) { | ||
2651 | hdev->send = btusb_send_frame_intel; | ||
2652 | hdev->setup = btusb_setup_intel_new; | ||
2653 | hdev->set_bdaddr = btusb_set_bdaddr_intel; | ||
2654 | } | ||
2655 | |||
2091 | if (id->driver_info & BTUSB_MARVELL) | 2656 | if (id->driver_info & BTUSB_MARVELL) |
2092 | hdev->set_bdaddr = btusb_set_bdaddr_marvell; | 2657 | hdev->set_bdaddr = btusb_set_bdaddr_marvell; |
2093 | 2658 | ||