1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Bluetooth support for Intel devices
6 * Copyright (C) 2015 Intel Corporation
9 #include <linux/module.h>
10 #include <linux/firmware.h>
11 #include <linux/regmap.h>
12 #include <linux/acpi.h>
13 #include <asm/unaligned.h>
15 #include <net/bluetooth/bluetooth.h>
16 #include <net/bluetooth/hci_core.h>
22 #define BDADDR_INTEL (&(bdaddr_t){{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
23 #define RSA_HEADER_LEN 644
24 #define CSS_HEADER_OFFSET 8
25 #define ECDSA_OFFSET 644
26 #define ECDSA_HEADER_LEN 320
28 #define BTINTEL_PPAG_NAME "PPAG"
30 /* structure to store the PPAG data read from ACPI table */
38 #define CMD_WRITE_BOOT_PARAMS 0xfc0e
39 struct cmd_write_boot_params {
47 const char *driver_name;
52 int btintel_check_bdaddr(struct hci_dev *hdev)
54 struct hci_rp_read_bd_addr *bda;
57 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
60 int err = PTR_ERR(skb);
61 bt_dev_err(hdev, "Reading Intel device address failed (%d)",
66 if (skb->len != sizeof(*bda)) {
67 bt_dev_err(hdev, "Intel device address length mismatch");
72 bda = (struct hci_rp_read_bd_addr *)skb->data;
74 /* For some Intel based controllers, the default Bluetooth device
75 * address 00:03:19:9E:8B:00 can be found. These controllers are
76 * fully operational, but have the danger of duplicate addresses
77 * and that in turn can cause problems with Bluetooth operation.
79 if (!bacmp(&bda->bdaddr, BDADDR_INTEL)) {
80 bt_dev_err(hdev, "Found Intel default device address (%pMR)",
82 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
89 EXPORT_SYMBOL_GPL(btintel_check_bdaddr);
91 int btintel_enter_mfg(struct hci_dev *hdev)
93 static const u8 param[] = { 0x01, 0x00 };
96 skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT);
98 bt_dev_err(hdev, "Entering manufacturer mode failed (%ld)",
106 EXPORT_SYMBOL_GPL(btintel_enter_mfg);
108 int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched)
110 u8 param[] = { 0x00, 0x00 };
113 /* The 2nd command parameter specifies the manufacturing exit method:
114 * 0x00: Just disable the manufacturing mode (0x00).
115 * 0x01: Disable manufacturing mode and reset with patches deactivated.
116 * 0x02: Disable manufacturing mode and reset with patches activated.
119 param[1] |= patched ? 0x02 : 0x01;
121 skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT);
123 bt_dev_err(hdev, "Exiting manufacturer mode failed (%ld)",
131 EXPORT_SYMBOL_GPL(btintel_exit_mfg);
133 int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
138 skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT);
141 bt_dev_err(hdev, "Changing Intel device address failed (%d)",
149 EXPORT_SYMBOL_GPL(btintel_set_bdaddr);
151 static int btintel_set_event_mask(struct hci_dev *hdev, bool debug)
153 u8 mask[8] = { 0x87, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
160 skb = __hci_cmd_sync(hdev, 0xfc52, 8, mask, HCI_INIT_TIMEOUT);
163 bt_dev_err(hdev, "Setting Intel event mask failed (%d)", err);
171 int btintel_set_diag(struct hci_dev *hdev, bool enable)
187 skb = __hci_cmd_sync(hdev, 0xfc43, 3, param, HCI_INIT_TIMEOUT);
192 bt_dev_err(hdev, "Changing Intel diagnostic mode failed (%d)",
199 btintel_set_event_mask(hdev, enable);
202 EXPORT_SYMBOL_GPL(btintel_set_diag);
204 static int btintel_set_diag_mfg(struct hci_dev *hdev, bool enable)
208 err = btintel_enter_mfg(hdev);
212 ret = btintel_set_diag(hdev, enable);
214 err = btintel_exit_mfg(hdev, false, false);
221 static int btintel_set_diag_combined(struct hci_dev *hdev, bool enable)
225 /* Legacy ROM device needs to be in the manufacturer mode to apply
228 * This flag is set after reading the Intel version.
230 if (btintel_test_flag(hdev, INTEL_ROM_LEGACY))
231 ret = btintel_set_diag_mfg(hdev, enable);
233 ret = btintel_set_diag(hdev, enable);
238 static void btintel_hw_error(struct hci_dev *hdev, u8 code)
243 bt_dev_err(hdev, "Hardware error 0x%2.2x", code);
245 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
247 bt_dev_err(hdev, "Reset after hardware error failed (%ld)",
253 skb = __hci_cmd_sync(hdev, 0xfc22, 1, &type, HCI_INIT_TIMEOUT);
255 bt_dev_err(hdev, "Retrieving Intel exception info failed (%ld)",
260 if (skb->len != 13) {
261 bt_dev_err(hdev, "Exception info size mismatch");
266 bt_dev_err(hdev, "Exception info %s", (char *)(skb->data + 1));
271 int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver)
275 /* The hardware platform number has a fixed value of 0x37 and
276 * for now only accept this single value.
278 if (ver->hw_platform != 0x37) {
279 bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)",
284 /* Check for supported iBT hardware variants of this firmware
287 * This check has been put in place to ensure correct forward
288 * compatibility options when newer hardware variants come along.
290 switch (ver->hw_variant) {
291 case 0x07: /* WP - Legacy ROM */
292 case 0x08: /* StP - Legacy ROM */
301 bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)",
306 switch (ver->fw_variant) {
308 variant = "Legacy ROM 2.5";
311 variant = "Bootloader";
314 variant = "Legacy ROM 2.x";
317 variant = "Firmware";
320 bt_dev_err(hdev, "Unsupported firmware variant(%02x)", ver->fw_variant);
324 coredump_info.hw_variant = ver->hw_variant;
325 coredump_info.fw_build_num = ver->fw_build_num;
327 bt_dev_info(hdev, "%s revision %u.%u build %u week %u %u",
328 variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f,
329 ver->fw_build_num, ver->fw_build_ww,
330 2000 + ver->fw_build_yy);
334 EXPORT_SYMBOL_GPL(btintel_version_info);
336 static int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen,
341 u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen;
343 cmd_param[0] = fragment_type;
344 memcpy(cmd_param + 1, param, fragment_len);
346 skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1,
347 cmd_param, HCI_INIT_TIMEOUT);
353 plen -= fragment_len;
354 param += fragment_len;
360 int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name)
362 const struct firmware *fw;
367 err = request_firmware_direct(&fw, ddc_name, &hdev->dev);
369 bt_dev_err(hdev, "Failed to load Intel DDC file %s (%d)",
374 bt_dev_info(hdev, "Found Intel DDC parameters: %s", ddc_name);
378 /* DDC file contains one or more DDC structure which has
379 * Length (1 byte), DDC ID (2 bytes), and DDC value (Length - 2).
381 while (fw->size > fw_ptr - fw->data) {
382 u8 cmd_plen = fw_ptr[0] + sizeof(u8);
384 skb = __hci_cmd_sync(hdev, 0xfc8b, cmd_plen, fw_ptr,
387 bt_dev_err(hdev, "Failed to send Intel_Write_DDC (%ld)",
389 release_firmware(fw);
397 release_firmware(fw);
399 bt_dev_info(hdev, "Applying Intel DDC parameters completed");
403 EXPORT_SYMBOL_GPL(btintel_load_ddc_config);
405 int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug)
409 err = btintel_enter_mfg(hdev);
413 ret = btintel_set_event_mask(hdev, debug);
415 err = btintel_exit_mfg(hdev, false, false);
421 EXPORT_SYMBOL_GPL(btintel_set_event_mask_mfg);
423 int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver)
427 skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_CMD_TIMEOUT);
429 bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
434 if (skb->len != sizeof(*ver)) {
435 bt_dev_err(hdev, "Intel version event size mismatch");
440 memcpy(ver, skb->data, sizeof(*ver));
446 EXPORT_SYMBOL_GPL(btintel_read_version);
448 static int btintel_version_info_tlv(struct hci_dev *hdev,
449 struct intel_version_tlv *version)
453 /* The hardware platform number has a fixed value of 0x37 and
454 * for now only accept this single value.
456 if (INTEL_HW_PLATFORM(version->cnvi_bt) != 0x37) {
457 bt_dev_err(hdev, "Unsupported Intel hardware platform (0x%2x)",
458 INTEL_HW_PLATFORM(version->cnvi_bt));
462 /* Check for supported iBT hardware variants of this firmware
465 * This check has been put in place to ensure correct forward
466 * compatibility options when newer hardware variants come along.
468 switch (INTEL_HW_VARIANT(version->cnvi_bt)) {
471 case 0x19: /* Slr-F */
475 bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%x)",
476 INTEL_HW_VARIANT(version->cnvi_bt));
480 switch (version->img_type) {
482 variant = "Bootloader";
483 /* It is required that every single firmware fragment is acknowledged
484 * with a command complete event. If the boot parameters indicate
485 * that this bootloader does not send them, then abort the setup.
487 if (version->limited_cce != 0x00) {
488 bt_dev_err(hdev, "Unsupported Intel firmware loading method (0x%x)",
489 version->limited_cce);
493 /* Secure boot engine type should be either 1 (ECDSA) or 0 (RSA) */
494 if (version->sbe_type > 0x01) {
495 bt_dev_err(hdev, "Unsupported Intel secure boot engine type (0x%x)",
500 bt_dev_info(hdev, "Device revision is %u", version->dev_rev_id);
501 bt_dev_info(hdev, "Secure boot is %s",
502 version->secure_boot ? "enabled" : "disabled");
503 bt_dev_info(hdev, "OTP lock is %s",
504 version->otp_lock ? "enabled" : "disabled");
505 bt_dev_info(hdev, "API lock is %s",
506 version->api_lock ? "enabled" : "disabled");
507 bt_dev_info(hdev, "Debug lock is %s",
508 version->debug_lock ? "enabled" : "disabled");
509 bt_dev_info(hdev, "Minimum firmware build %u week %u %u",
510 version->min_fw_build_nn, version->min_fw_build_cw,
511 2000 + version->min_fw_build_yy);
514 variant = "Firmware";
517 bt_dev_err(hdev, "Unsupported image type(%02x)", version->img_type);
521 coredump_info.hw_variant = INTEL_HW_VARIANT(version->cnvi_bt);
522 coredump_info.fw_build_num = version->build_num;
524 bt_dev_info(hdev, "%s timestamp %u.%u buildtype %u build %u", variant,
525 2000 + (version->timestamp >> 8), version->timestamp & 0xff,
526 version->build_type, version->build_num);
531 static int btintel_parse_version_tlv(struct hci_dev *hdev,
532 struct intel_version_tlv *version,
535 /* Consume Command Complete Status field */
538 /* Event parameters contatin multiple TLVs. Read each of them
539 * and only keep the required data. Also, it use existing legacy
540 * version field like hw_platform, hw_variant, and fw_variant
541 * to keep the existing setup flow
544 struct intel_tlv *tlv;
546 /* Make sure skb has a minimum length of the header */
547 if (skb->len < sizeof(*tlv))
550 tlv = (struct intel_tlv *)skb->data;
552 /* Make sure skb has a enough data */
553 if (skb->len < tlv->len + sizeof(*tlv))
557 case INTEL_TLV_CNVI_TOP:
558 version->cnvi_top = get_unaligned_le32(tlv->val);
560 case INTEL_TLV_CNVR_TOP:
561 version->cnvr_top = get_unaligned_le32(tlv->val);
563 case INTEL_TLV_CNVI_BT:
564 version->cnvi_bt = get_unaligned_le32(tlv->val);
566 case INTEL_TLV_CNVR_BT:
567 version->cnvr_bt = get_unaligned_le32(tlv->val);
569 case INTEL_TLV_DEV_REV_ID:
570 version->dev_rev_id = get_unaligned_le16(tlv->val);
572 case INTEL_TLV_IMAGE_TYPE:
573 version->img_type = tlv->val[0];
575 case INTEL_TLV_TIME_STAMP:
576 /* If image type is Operational firmware (0x03), then
577 * running FW Calendar Week and Year information can
578 * be extracted from Timestamp information
580 version->min_fw_build_cw = tlv->val[0];
581 version->min_fw_build_yy = tlv->val[1];
582 version->timestamp = get_unaligned_le16(tlv->val);
584 case INTEL_TLV_BUILD_TYPE:
585 version->build_type = tlv->val[0];
587 case INTEL_TLV_BUILD_NUM:
588 /* If image type is Operational firmware (0x03), then
589 * running FW build number can be extracted from the
592 version->min_fw_build_nn = tlv->val[0];
593 version->build_num = get_unaligned_le32(tlv->val);
595 case INTEL_TLV_SECURE_BOOT:
596 version->secure_boot = tlv->val[0];
598 case INTEL_TLV_OTP_LOCK:
599 version->otp_lock = tlv->val[0];
601 case INTEL_TLV_API_LOCK:
602 version->api_lock = tlv->val[0];
604 case INTEL_TLV_DEBUG_LOCK:
605 version->debug_lock = tlv->val[0];
607 case INTEL_TLV_MIN_FW:
608 version->min_fw_build_nn = tlv->val[0];
609 version->min_fw_build_cw = tlv->val[1];
610 version->min_fw_build_yy = tlv->val[2];
612 case INTEL_TLV_LIMITED_CCE:
613 version->limited_cce = tlv->val[0];
615 case INTEL_TLV_SBE_TYPE:
616 version->sbe_type = tlv->val[0];
618 case INTEL_TLV_OTP_BDADDR:
619 memcpy(&version->otp_bd_addr, tlv->val,
623 /* Ignore rest of information */
626 /* consume the current tlv and move to next*/
627 skb_pull(skb, tlv->len + sizeof(*tlv));
633 static int btintel_read_version_tlv(struct hci_dev *hdev,
634 struct intel_version_tlv *version)
637 const u8 param[1] = { 0xFF };
642 skb = __hci_cmd_sync(hdev, 0xfc05, 1, param, HCI_CMD_TIMEOUT);
644 bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
650 bt_dev_err(hdev, "Intel Read Version command failed (%02x)",
656 btintel_parse_version_tlv(hdev, version, skb);
662 /* ------- REGMAP IBT SUPPORT ------- */
664 #define IBT_REG_MODE_8BIT 0x00
665 #define IBT_REG_MODE_16BIT 0x01
666 #define IBT_REG_MODE_32BIT 0x02
668 struct regmap_ibt_context {
669 struct hci_dev *hdev;
674 struct ibt_cp_reg_access {
681 struct ibt_rp_reg_access {
687 static int regmap_ibt_read(void *context, const void *addr, size_t reg_size,
688 void *val, size_t val_size)
690 struct regmap_ibt_context *ctx = context;
691 struct ibt_cp_reg_access cp;
692 struct ibt_rp_reg_access *rp;
696 if (reg_size != sizeof(__le32))
701 cp.mode = IBT_REG_MODE_8BIT;
704 cp.mode = IBT_REG_MODE_16BIT;
707 cp.mode = IBT_REG_MODE_32BIT;
713 /* regmap provides a little-endian formatted addr */
714 cp.addr = *(__le32 *)addr;
717 bt_dev_dbg(ctx->hdev, "Register (0x%x) read", le32_to_cpu(cp.addr));
719 skb = hci_cmd_sync(ctx->hdev, ctx->op_read, sizeof(cp), &cp,
723 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error (%d)",
724 le32_to_cpu(cp.addr), err);
728 if (skb->len != sizeof(*rp) + val_size) {
729 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error, bad len",
730 le32_to_cpu(cp.addr));
735 rp = (struct ibt_rp_reg_access *)skb->data;
737 if (rp->addr != cp.addr) {
738 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error, bad addr",
739 le32_to_cpu(rp->addr));
744 memcpy(val, rp->data, val_size);
751 static int regmap_ibt_gather_write(void *context,
752 const void *addr, size_t reg_size,
753 const void *val, size_t val_size)
755 struct regmap_ibt_context *ctx = context;
756 struct ibt_cp_reg_access *cp;
758 int plen = sizeof(*cp) + val_size;
762 if (reg_size != sizeof(__le32))
767 mode = IBT_REG_MODE_8BIT;
770 mode = IBT_REG_MODE_16BIT;
773 mode = IBT_REG_MODE_32BIT;
779 cp = kmalloc(plen, GFP_KERNEL);
783 /* regmap provides a little-endian formatted addr/value */
784 cp->addr = *(__le32 *)addr;
787 memcpy(&cp->data, val, val_size);
789 bt_dev_dbg(ctx->hdev, "Register (0x%x) write", le32_to_cpu(cp->addr));
791 skb = hci_cmd_sync(ctx->hdev, ctx->op_write, plen, cp, HCI_CMD_TIMEOUT);
794 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) write error (%d)",
795 le32_to_cpu(cp->addr), err);
805 static int regmap_ibt_write(void *context, const void *data, size_t count)
807 /* data contains register+value, since we only support 32bit addr,
808 * minimum data size is 4 bytes.
810 if (WARN_ONCE(count < 4, "Invalid register access"))
813 return regmap_ibt_gather_write(context, data, 4, data + 4, count - 4);
816 static void regmap_ibt_free_context(void *context)
821 static const struct regmap_bus regmap_ibt = {
822 .read = regmap_ibt_read,
823 .write = regmap_ibt_write,
824 .gather_write = regmap_ibt_gather_write,
825 .free_context = regmap_ibt_free_context,
826 .reg_format_endian_default = REGMAP_ENDIAN_LITTLE,
827 .val_format_endian_default = REGMAP_ENDIAN_LITTLE,
830 /* Config is the same for all register regions */
831 static const struct regmap_config regmap_ibt_cfg = {
832 .name = "btintel_regmap",
837 struct regmap *btintel_regmap_init(struct hci_dev *hdev, u16 opcode_read,
840 struct regmap_ibt_context *ctx;
842 bt_dev_info(hdev, "regmap: Init R%x-W%x region", opcode_read,
845 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
847 return ERR_PTR(-ENOMEM);
849 ctx->op_read = opcode_read;
850 ctx->op_write = opcode_write;
853 return regmap_init(&hdev->dev, ®map_ibt, ctx, ®map_ibt_cfg);
855 EXPORT_SYMBOL_GPL(btintel_regmap_init);
857 int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param)
859 struct intel_reset params = { 0x00, 0x01, 0x00, 0x01, 0x00000000 };
862 params.boot_param = cpu_to_le32(boot_param);
864 skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(params), ¶ms,
867 bt_dev_err(hdev, "Failed to send Intel Reset command");
875 EXPORT_SYMBOL_GPL(btintel_send_intel_reset);
877 int btintel_read_boot_params(struct hci_dev *hdev,
878 struct intel_boot_params *params)
882 skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT);
884 bt_dev_err(hdev, "Reading Intel boot parameters failed (%ld)",
889 if (skb->len != sizeof(*params)) {
890 bt_dev_err(hdev, "Intel boot parameters size mismatch");
895 memcpy(params, skb->data, sizeof(*params));
899 if (params->status) {
900 bt_dev_err(hdev, "Intel boot parameters command failed (%02x)",
902 return -bt_to_errno(params->status);
905 bt_dev_info(hdev, "Device revision is %u",
906 le16_to_cpu(params->dev_revid));
908 bt_dev_info(hdev, "Secure boot is %s",
909 params->secure_boot ? "enabled" : "disabled");
911 bt_dev_info(hdev, "OTP lock is %s",
912 params->otp_lock ? "enabled" : "disabled");
914 bt_dev_info(hdev, "API lock is %s",
915 params->api_lock ? "enabled" : "disabled");
917 bt_dev_info(hdev, "Debug lock is %s",
918 params->debug_lock ? "enabled" : "disabled");
920 bt_dev_info(hdev, "Minimum firmware build %u week %u %u",
921 params->min_fw_build_nn, params->min_fw_build_cw,
922 2000 + params->min_fw_build_yy);
926 EXPORT_SYMBOL_GPL(btintel_read_boot_params);
928 static int btintel_sfi_rsa_header_secure_send(struct hci_dev *hdev,
929 const struct firmware *fw)
933 /* Start the firmware download transaction with the Init fragment
934 * represented by the 128 bytes of CSS header.
936 err = btintel_secure_send(hdev, 0x00, 128, fw->data);
938 bt_dev_err(hdev, "Failed to send firmware header (%d)", err);
942 /* Send the 256 bytes of public key information from the firmware
943 * as the PKey fragment.
945 err = btintel_secure_send(hdev, 0x03, 256, fw->data + 128);
947 bt_dev_err(hdev, "Failed to send firmware pkey (%d)", err);
951 /* Send the 256 bytes of signature information from the firmware
952 * as the Sign fragment.
954 err = btintel_secure_send(hdev, 0x02, 256, fw->data + 388);
956 bt_dev_err(hdev, "Failed to send firmware signature (%d)", err);
964 static int btintel_sfi_ecdsa_header_secure_send(struct hci_dev *hdev,
965 const struct firmware *fw)
969 /* Start the firmware download transaction with the Init fragment
970 * represented by the 128 bytes of CSS header.
972 err = btintel_secure_send(hdev, 0x00, 128, fw->data + 644);
974 bt_dev_err(hdev, "Failed to send firmware header (%d)", err);
978 /* Send the 96 bytes of public key information from the firmware
979 * as the PKey fragment.
981 err = btintel_secure_send(hdev, 0x03, 96, fw->data + 644 + 128);
983 bt_dev_err(hdev, "Failed to send firmware pkey (%d)", err);
987 /* Send the 96 bytes of signature information from the firmware
988 * as the Sign fragment
990 err = btintel_secure_send(hdev, 0x02, 96, fw->data + 644 + 224);
992 bt_dev_err(hdev, "Failed to send firmware signature (%d)",
999 static int btintel_download_firmware_payload(struct hci_dev *hdev,
1000 const struct firmware *fw,
1007 fw_ptr = fw->data + offset;
1011 while (fw_ptr - fw->data < fw->size) {
1012 struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len);
1014 frag_len += sizeof(*cmd) + cmd->plen;
1016 /* The parameter length of the secure send command requires
1017 * a 4 byte alignment. It happens so that the firmware file
1018 * contains proper Intel_NOP commands to align the fragments
1021 * Send set of commands with 4 byte alignment from the
1022 * firmware data buffer as a single Data fragement.
1024 if (!(frag_len % 4)) {
1025 err = btintel_secure_send(hdev, 0x01, frag_len, fw_ptr);
1028 "Failed to send firmware data (%d)",
1042 static bool btintel_firmware_version(struct hci_dev *hdev,
1043 u8 num, u8 ww, u8 yy,
1044 const struct firmware *fw,
1051 while (fw_ptr - fw->data < fw->size) {
1052 struct hci_command_hdr *cmd = (void *)(fw_ptr);
1054 /* Each SKU has a different reset parameter to use in the
1055 * HCI_Intel_Reset command and it is embedded in the firmware
1056 * data. So, instead of using static value per SKU, check
1057 * the firmware data and save it for later use.
1059 if (le16_to_cpu(cmd->opcode) == CMD_WRITE_BOOT_PARAMS) {
1060 struct cmd_write_boot_params *params;
1062 params = (void *)(fw_ptr + sizeof(*cmd));
1064 *boot_addr = le32_to_cpu(params->boot_addr);
1066 bt_dev_info(hdev, "Boot Address: 0x%x", *boot_addr);
1068 bt_dev_info(hdev, "Firmware Version: %u-%u.%u",
1069 params->fw_build_num, params->fw_build_ww,
1070 params->fw_build_yy);
1072 return (num == params->fw_build_num &&
1073 ww == params->fw_build_ww &&
1074 yy == params->fw_build_yy);
1077 fw_ptr += sizeof(*cmd) + cmd->plen;
1083 int btintel_download_firmware(struct hci_dev *hdev,
1084 struct intel_version *ver,
1085 const struct firmware *fw,
1090 /* SfP and WsP don't seem to update the firmware version on file
1091 * so version checking is currently not possible.
1093 switch (ver->hw_variant) {
1094 case 0x0b: /* SfP */
1095 case 0x0c: /* WsP */
1096 /* Skip version checking */
1100 /* Skip download if firmware has the same version */
1101 if (btintel_firmware_version(hdev, ver->fw_build_num,
1102 ver->fw_build_ww, ver->fw_build_yy,
1104 bt_dev_info(hdev, "Firmware already loaded");
1105 /* Return -EALREADY to indicate that the firmware has
1106 * already been loaded.
1112 /* The firmware variant determines if the device is in bootloader
1113 * mode or is running operational firmware. The value 0x06 identifies
1114 * the bootloader and the value 0x23 identifies the operational
1117 * If the firmware version has changed that means it needs to be reset
1118 * to bootloader when operational so the new firmware can be loaded.
1120 if (ver->fw_variant == 0x23)
1123 err = btintel_sfi_rsa_header_secure_send(hdev, fw);
1127 return btintel_download_firmware_payload(hdev, fw, RSA_HEADER_LEN);
1129 EXPORT_SYMBOL_GPL(btintel_download_firmware);
1131 static int btintel_download_fw_tlv(struct hci_dev *hdev,
1132 struct intel_version_tlv *ver,
1133 const struct firmware *fw, u32 *boot_param,
1134 u8 hw_variant, u8 sbe_type)
1139 /* Skip download if firmware has the same version */
1140 if (btintel_firmware_version(hdev, ver->min_fw_build_nn,
1141 ver->min_fw_build_cw,
1142 ver->min_fw_build_yy,
1144 bt_dev_info(hdev, "Firmware already loaded");
1145 /* Return -EALREADY to indicate that firmware has
1146 * already been loaded.
1151 /* The firmware variant determines if the device is in bootloader
1152 * mode or is running operational firmware. The value 0x01 identifies
1153 * the bootloader and the value 0x03 identifies the operational
1156 * If the firmware version has changed that means it needs to be reset
1157 * to bootloader when operational so the new firmware can be loaded.
1159 if (ver->img_type == 0x03)
1162 /* iBT hardware variants 0x0b, 0x0c, 0x11, 0x12, 0x13, 0x14 support
1163 * only RSA secure boot engine. Hence, the corresponding sfi file will
1164 * have RSA header of 644 bytes followed by Command Buffer.
1166 * iBT hardware variants 0x17, 0x18 onwards support both RSA and ECDSA
1167 * secure boot engine. As a result, the corresponding sfi file will
1168 * have RSA header of 644, ECDSA header of 320 bytes followed by
1171 * CSS Header byte positions 0x08 to 0x0B represent the CSS Header
1172 * version: RSA(0x00010000) , ECDSA (0x00020000)
1174 css_header_ver = get_unaligned_le32(fw->data + CSS_HEADER_OFFSET);
1175 if (css_header_ver != 0x00010000) {
1176 bt_dev_err(hdev, "Invalid CSS Header version");
1180 if (hw_variant <= 0x14) {
1181 if (sbe_type != 0x00) {
1182 bt_dev_err(hdev, "Invalid SBE type for hardware variant (%d)",
1187 err = btintel_sfi_rsa_header_secure_send(hdev, fw);
1191 err = btintel_download_firmware_payload(hdev, fw, RSA_HEADER_LEN);
1194 } else if (hw_variant >= 0x17) {
1195 /* Check if CSS header for ECDSA follows the RSA header */
1196 if (fw->data[ECDSA_OFFSET] != 0x06)
1199 /* Check if the CSS Header version is ECDSA(0x00020000) */
1200 css_header_ver = get_unaligned_le32(fw->data + ECDSA_OFFSET + CSS_HEADER_OFFSET);
1201 if (css_header_ver != 0x00020000) {
1202 bt_dev_err(hdev, "Invalid CSS Header version");
1206 if (sbe_type == 0x00) {
1207 err = btintel_sfi_rsa_header_secure_send(hdev, fw);
1211 err = btintel_download_firmware_payload(hdev, fw,
1212 RSA_HEADER_LEN + ECDSA_HEADER_LEN);
1215 } else if (sbe_type == 0x01) {
1216 err = btintel_sfi_ecdsa_header_secure_send(hdev, fw);
1220 err = btintel_download_firmware_payload(hdev, fw,
1221 RSA_HEADER_LEN + ECDSA_HEADER_LEN);
1229 static void btintel_reset_to_bootloader(struct hci_dev *hdev)
1231 struct intel_reset params;
1232 struct sk_buff *skb;
1234 /* Send Intel Reset command. This will result in
1235 * re-enumeration of BT controller.
1237 * Intel Reset parameter description:
1238 * reset_type : 0x00 (Soft reset),
1240 * patch_enable : 0x00 (Do not enable),
1242 * ddc_reload : 0x00 (Do not reload),
1244 * boot_option: 0x00 (Current image),
1245 * 0x01 (Specified boot address)
1246 * boot_param: Boot address
1249 params.reset_type = 0x01;
1250 params.patch_enable = 0x01;
1251 params.ddc_reload = 0x01;
1252 params.boot_option = 0x00;
1253 params.boot_param = cpu_to_le32(0x00000000);
1255 skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(params),
1256 ¶ms, HCI_INIT_TIMEOUT);
1258 bt_dev_err(hdev, "FW download error recovery failed (%ld)",
1262 bt_dev_info(hdev, "Intel reset sent to retry FW download");
1265 /* Current Intel BT controllers(ThP/JfP) hold the USB reset
1266 * lines for 2ms when it receives Intel Reset in bootloader mode.
1267 * Whereas, the upcoming Intel BT controllers will hold USB reset
1268 * for 150ms. To keep the delay generic, 150ms is chosen here.
1273 static int btintel_read_debug_features(struct hci_dev *hdev,
1274 struct intel_debug_features *features)
1276 struct sk_buff *skb;
1279 /* Intel controller supports two pages, each page is of 128-bit
1280 * feature bit mask. And each bit defines specific feature support
1282 skb = __hci_cmd_sync(hdev, 0xfca6, sizeof(page_no), &page_no,
1285 bt_dev_err(hdev, "Reading supported features failed (%ld)",
1287 return PTR_ERR(skb);
1290 if (skb->len != (sizeof(features->page1) + 3)) {
1291 bt_dev_err(hdev, "Supported features event size mismatch");
1296 memcpy(features->page1, skb->data + 3, sizeof(features->page1));
1298 /* Read the supported features page2 if required in future.
1304 static acpi_status btintel_ppag_callback(acpi_handle handle, u32 lvl, void *data,
1309 struct btintel_ppag *ppag = data;
1310 union acpi_object *p, *elements;
1311 struct acpi_buffer string = {ACPI_ALLOCATE_BUFFER, NULL};
1312 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
1313 struct hci_dev *hdev = ppag->hdev;
1315 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
1316 if (ACPI_FAILURE(status)) {
1317 bt_dev_warn(hdev, "PPAG-BT: ACPI Failure: %s", acpi_format_exception(status));
1321 len = strlen(string.pointer);
1322 if (len < strlen(BTINTEL_PPAG_NAME)) {
1323 kfree(string.pointer);
1327 if (strncmp((char *)string.pointer + len - 4, BTINTEL_PPAG_NAME, 4)) {
1328 kfree(string.pointer);
1331 kfree(string.pointer);
1333 status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
1334 if (ACPI_FAILURE(status)) {
1335 ppag->status = status;
1336 bt_dev_warn(hdev, "PPAG-BT: ACPI Failure: %s", acpi_format_exception(status));
1341 ppag = (struct btintel_ppag *)data;
1343 if (p->type != ACPI_TYPE_PACKAGE || p->package.count != 2) {
1344 kfree(buffer.pointer);
1345 bt_dev_warn(hdev, "PPAG-BT: Invalid object type: %d or package count: %d",
1346 p->type, p->package.count);
1347 ppag->status = AE_ERROR;
1351 elements = p->package.elements;
1353 /* PPAG table is located at element[1] */
1356 ppag->domain = (u32)p->package.elements[0].integer.value;
1357 ppag->mode = (u32)p->package.elements[1].integer.value;
1358 ppag->status = AE_OK;
1359 kfree(buffer.pointer);
1360 return AE_CTRL_TERMINATE;
1363 static int btintel_set_debug_features(struct hci_dev *hdev,
1364 const struct intel_debug_features *features)
1366 u8 mask[11] = { 0x0a, 0x92, 0x02, 0x7f, 0x00, 0x00, 0x00, 0x00,
1368 u8 period[5] = { 0x04, 0x91, 0x02, 0x05, 0x00 };
1369 u8 trace_enable = 0x02;
1370 struct sk_buff *skb;
1373 bt_dev_warn(hdev, "Debug features not read");
1377 if (!(features->page1[0] & 0x3f)) {
1378 bt_dev_info(hdev, "Telemetry exception format not supported");
1382 skb = __hci_cmd_sync(hdev, 0xfc8b, 11, mask, HCI_INIT_TIMEOUT);
1384 bt_dev_err(hdev, "Setting Intel telemetry ddc write event mask failed (%ld)",
1386 return PTR_ERR(skb);
1390 skb = __hci_cmd_sync(hdev, 0xfc8b, 5, period, HCI_INIT_TIMEOUT);
1392 bt_dev_err(hdev, "Setting periodicity for link statistics traces failed (%ld)",
1394 return PTR_ERR(skb);
1398 skb = __hci_cmd_sync(hdev, 0xfca1, 1, &trace_enable, HCI_INIT_TIMEOUT);
1400 bt_dev_err(hdev, "Enable tracing of link statistics events failed (%ld)",
1402 return PTR_ERR(skb);
1406 bt_dev_info(hdev, "set debug features: trace_enable 0x%02x mask 0x%02x",
1407 trace_enable, mask[3]);
1412 static int btintel_reset_debug_features(struct hci_dev *hdev,
1413 const struct intel_debug_features *features)
1415 u8 mask[11] = { 0x0a, 0x92, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1417 u8 trace_enable = 0x00;
1418 struct sk_buff *skb;
1421 bt_dev_warn(hdev, "Debug features not read");
1425 if (!(features->page1[0] & 0x3f)) {
1426 bt_dev_info(hdev, "Telemetry exception format not supported");
1430 /* Should stop the trace before writing ddc event mask. */
1431 skb = __hci_cmd_sync(hdev, 0xfca1, 1, &trace_enable, HCI_INIT_TIMEOUT);
1433 bt_dev_err(hdev, "Stop tracing of link statistics events failed (%ld)",
1435 return PTR_ERR(skb);
1439 skb = __hci_cmd_sync(hdev, 0xfc8b, 11, mask, HCI_INIT_TIMEOUT);
1441 bt_dev_err(hdev, "Setting Intel telemetry ddc write event mask failed (%ld)",
1443 return PTR_ERR(skb);
1447 bt_dev_info(hdev, "reset debug features: trace_enable 0x%02x mask 0x%02x",
1448 trace_enable, mask[3]);
1453 int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
1455 struct intel_debug_features features;
1458 bt_dev_dbg(hdev, "enable %d", enable);
1460 /* Read the Intel supported features and if new exception formats
1461 * supported, need to load the additional DDC config to enable.
1463 err = btintel_read_debug_features(hdev, &features);
1467 /* Set or reset the debug features. */
1469 err = btintel_set_debug_features(hdev, &features);
1471 err = btintel_reset_debug_features(hdev, &features);
1475 EXPORT_SYMBOL_GPL(btintel_set_quality_report);
1477 static void btintel_coredump(struct hci_dev *hdev)
1479 struct sk_buff *skb;
1481 skb = __hci_cmd_sync(hdev, 0xfc4e, 0, NULL, HCI_CMD_TIMEOUT);
1483 bt_dev_err(hdev, "Coredump failed (%ld)", PTR_ERR(skb));
1490 static void btintel_dmp_hdr(struct hci_dev *hdev, struct sk_buff *skb)
1494 snprintf(buf, sizeof(buf), "Controller Name: 0x%X\n",
1495 coredump_info.hw_variant);
1496 skb_put_data(skb, buf, strlen(buf));
1498 snprintf(buf, sizeof(buf), "Firmware Version: 0x%X\n",
1499 coredump_info.fw_build_num);
1500 skb_put_data(skb, buf, strlen(buf));
1502 snprintf(buf, sizeof(buf), "Driver: %s\n", coredump_info.driver_name);
1503 skb_put_data(skb, buf, strlen(buf));
1505 snprintf(buf, sizeof(buf), "Vendor: Intel\n");
1506 skb_put_data(skb, buf, strlen(buf));
1509 static int btintel_register_devcoredump_support(struct hci_dev *hdev)
1511 struct intel_debug_features features;
1514 err = btintel_read_debug_features(hdev, &features);
1516 bt_dev_info(hdev, "Error reading debug features");
1520 if (!(features.page1[0] & 0x3f)) {
1521 bt_dev_dbg(hdev, "Telemetry exception format not supported");
1525 hci_devcd_register(hdev, btintel_coredump, btintel_dmp_hdr, NULL);
1530 static const struct firmware *btintel_legacy_rom_get_fw(struct hci_dev *hdev,
1531 struct intel_version *ver)
1533 const struct firmware *fw;
1537 snprintf(fwname, sizeof(fwname),
1538 "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq",
1539 ver->hw_platform, ver->hw_variant, ver->hw_revision,
1540 ver->fw_variant, ver->fw_revision, ver->fw_build_num,
1541 ver->fw_build_ww, ver->fw_build_yy);
1543 ret = request_firmware(&fw, fwname, &hdev->dev);
1545 if (ret == -EINVAL) {
1546 bt_dev_err(hdev, "Intel firmware file request failed (%d)",
1551 bt_dev_err(hdev, "failed to open Intel firmware file: %s (%d)",
1554 /* If the correct firmware patch file is not found, use the
1555 * default firmware patch file instead
1557 snprintf(fwname, sizeof(fwname), "intel/ibt-hw-%x.%x.bseq",
1558 ver->hw_platform, ver->hw_variant);
1559 if (request_firmware(&fw, fwname, &hdev->dev) < 0) {
1560 bt_dev_err(hdev, "failed to open default fw file: %s",
1566 bt_dev_info(hdev, "Intel Bluetooth firmware file: %s", fwname);
1571 static int btintel_legacy_rom_patching(struct hci_dev *hdev,
1572 const struct firmware *fw,
1573 const u8 **fw_ptr, int *disable_patch)
1575 struct sk_buff *skb;
1576 struct hci_command_hdr *cmd;
1577 const u8 *cmd_param;
1578 struct hci_event_hdr *evt = NULL;
1579 const u8 *evt_param = NULL;
1580 int remain = fw->size - (*fw_ptr - fw->data);
1582 /* The first byte indicates the types of the patch command or event.
1583 * 0x01 means HCI command and 0x02 is HCI event. If the first bytes
1584 * in the current firmware buffer doesn't start with 0x01 or
1585 * the size of remain buffer is smaller than HCI command header,
1586 * the firmware file is corrupted and it should stop the patching
1589 if (remain > HCI_COMMAND_HDR_SIZE && *fw_ptr[0] != 0x01) {
1590 bt_dev_err(hdev, "Intel fw corrupted: invalid cmd read");
1596 cmd = (struct hci_command_hdr *)(*fw_ptr);
1597 *fw_ptr += sizeof(*cmd);
1598 remain -= sizeof(*cmd);
1600 /* Ensure that the remain firmware data is long enough than the length
1601 * of command parameter. If not, the firmware file is corrupted.
1603 if (remain < cmd->plen) {
1604 bt_dev_err(hdev, "Intel fw corrupted: invalid cmd len");
1608 /* If there is a command that loads a patch in the firmware
1609 * file, then enable the patch upon success, otherwise just
1610 * disable the manufacturer mode, for example patch activation
1611 * is not required when the default firmware patch file is used
1612 * because there are no patch data to load.
1614 if (*disable_patch && le16_to_cpu(cmd->opcode) == 0xfc8e)
1617 cmd_param = *fw_ptr;
1618 *fw_ptr += cmd->plen;
1619 remain -= cmd->plen;
1621 /* This reads the expected events when the above command is sent to the
1622 * device. Some vendor commands expects more than one events, for
1623 * example command status event followed by vendor specific event.
1624 * For this case, it only keeps the last expected event. so the command
1625 * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of
1626 * last expected event.
1628 while (remain > HCI_EVENT_HDR_SIZE && *fw_ptr[0] == 0x02) {
1632 evt = (struct hci_event_hdr *)(*fw_ptr);
1633 *fw_ptr += sizeof(*evt);
1634 remain -= sizeof(*evt);
1636 if (remain < evt->plen) {
1637 bt_dev_err(hdev, "Intel fw corrupted: invalid evt len");
1641 evt_param = *fw_ptr;
1642 *fw_ptr += evt->plen;
1643 remain -= evt->plen;
1646 /* Every HCI commands in the firmware file has its correspond event.
1647 * If event is not found or remain is smaller than zero, the firmware
1648 * file is corrupted.
1650 if (!evt || !evt_param || remain < 0) {
1651 bt_dev_err(hdev, "Intel fw corrupted: invalid evt read");
1655 skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cmd->opcode), cmd->plen,
1656 cmd_param, evt->evt, HCI_INIT_TIMEOUT);
1658 bt_dev_err(hdev, "sending Intel patch command (0x%4.4x) failed (%ld)",
1659 cmd->opcode, PTR_ERR(skb));
1660 return PTR_ERR(skb);
1663 /* It ensures that the returned event matches the event data read from
1664 * the firmware file. At fist, it checks the length and then
1665 * the contents of the event.
1667 if (skb->len != evt->plen) {
1668 bt_dev_err(hdev, "mismatch event length (opcode 0x%4.4x)",
1669 le16_to_cpu(cmd->opcode));
1674 if (memcmp(skb->data, evt_param, evt->plen)) {
1675 bt_dev_err(hdev, "mismatch event parameter (opcode 0x%4.4x)",
1676 le16_to_cpu(cmd->opcode));
1685 static int btintel_legacy_rom_setup(struct hci_dev *hdev,
1686 struct intel_version *ver)
1688 const struct firmware *fw;
1690 int disable_patch, err;
1691 struct intel_version new_ver;
1693 BT_DBG("%s", hdev->name);
1695 /* fw_patch_num indicates the version of patch the device currently
1696 * have. If there is no patch data in the device, it is always 0x00.
1697 * So, if it is other than 0x00, no need to patch the device again.
1699 if (ver->fw_patch_num) {
1701 "Intel device is already patched. patch num: %02x",
1706 /* Opens the firmware patch file based on the firmware version read
1707 * from the controller. If it fails to open the matching firmware
1708 * patch file, it tries to open the default firmware patch file.
1709 * If no patch file is found, allow the device to operate without
1712 fw = btintel_legacy_rom_get_fw(hdev, ver);
1717 /* Enable the manufacturer mode of the controller.
1718 * Only while this mode is enabled, the driver can download the
1719 * firmware patch data and configuration parameters.
1721 err = btintel_enter_mfg(hdev);
1723 release_firmware(fw);
1729 /* The firmware data file consists of list of Intel specific HCI
1730 * commands and its expected events. The first byte indicates the
1731 * type of the message, either HCI command or HCI event.
1733 * It reads the command and its expected event from the firmware file,
1734 * and send to the controller. Once __hci_cmd_sync_ev() returns,
1735 * the returned event is compared with the event read from the firmware
1736 * file and it will continue until all the messages are downloaded to
1739 * Once the firmware patching is completed successfully,
1740 * the manufacturer mode is disabled with reset and activating the
1743 * If the firmware patching fails, the manufacturer mode is
1744 * disabled with reset and deactivating the patch.
1746 * If the default patch file is used, no reset is done when disabling
1749 while (fw->size > fw_ptr - fw->data) {
1752 ret = btintel_legacy_rom_patching(hdev, fw, &fw_ptr,
1755 goto exit_mfg_deactivate;
1758 release_firmware(fw);
1761 goto exit_mfg_disable;
1763 /* Patching completed successfully and disable the manufacturer mode
1764 * with reset and activate the downloaded firmware patches.
1766 err = btintel_exit_mfg(hdev, true, true);
1770 /* Need build number for downloaded fw patches in
1771 * every power-on boot
1773 err = btintel_read_version(hdev, &new_ver);
1777 bt_dev_info(hdev, "Intel BT fw patch 0x%02x completed & activated",
1778 new_ver.fw_patch_num);
1783 /* Disable the manufacturer mode without reset */
1784 err = btintel_exit_mfg(hdev, false, false);
1788 bt_dev_info(hdev, "Intel firmware patch completed");
1792 exit_mfg_deactivate:
1793 release_firmware(fw);
1795 /* Patching failed. Disable the manufacturer mode with reset and
1796 * deactivate the downloaded firmware patches.
1798 err = btintel_exit_mfg(hdev, true, false);
1802 bt_dev_info(hdev, "Intel firmware patch completed and deactivated");
1805 /* Set the event mask for Intel specific vendor events. This enables
1806 * a few extra events that are useful during general operation.
1808 btintel_set_event_mask_mfg(hdev, false);
1810 btintel_check_bdaddr(hdev);
1815 static int btintel_download_wait(struct hci_dev *hdev, ktime_t calltime, int msec)
1817 ktime_t delta, rettime;
1818 unsigned long long duration;
1821 btintel_set_flag(hdev, INTEL_FIRMWARE_LOADED);
1823 bt_dev_info(hdev, "Waiting for firmware download to complete");
1825 err = btintel_wait_on_flag_timeout(hdev, INTEL_DOWNLOADING,
1827 msecs_to_jiffies(msec));
1828 if (err == -EINTR) {
1829 bt_dev_err(hdev, "Firmware loading interrupted");
1834 bt_dev_err(hdev, "Firmware loading timeout");
1838 if (btintel_test_flag(hdev, INTEL_FIRMWARE_FAILED)) {
1839 bt_dev_err(hdev, "Firmware loading failed");
1843 rettime = ktime_get();
1844 delta = ktime_sub(rettime, calltime);
1845 duration = (unsigned long long)ktime_to_ns(delta) >> 10;
1847 bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration);
1852 static int btintel_boot_wait(struct hci_dev *hdev, ktime_t calltime, int msec)
1854 ktime_t delta, rettime;
1855 unsigned long long duration;
1858 bt_dev_info(hdev, "Waiting for device to boot");
1860 err = btintel_wait_on_flag_timeout(hdev, INTEL_BOOTING,
1862 msecs_to_jiffies(msec));
1863 if (err == -EINTR) {
1864 bt_dev_err(hdev, "Device boot interrupted");
1869 bt_dev_err(hdev, "Device boot timeout");
1873 rettime = ktime_get();
1874 delta = ktime_sub(rettime, calltime);
1875 duration = (unsigned long long) ktime_to_ns(delta) >> 10;
1877 bt_dev_info(hdev, "Device booted in %llu usecs", duration);
1882 static int btintel_boot(struct hci_dev *hdev, u32 boot_addr)
1887 calltime = ktime_get();
1889 btintel_set_flag(hdev, INTEL_BOOTING);
1891 err = btintel_send_intel_reset(hdev, boot_addr);
1893 bt_dev_err(hdev, "Intel Soft Reset failed (%d)", err);
1894 btintel_reset_to_bootloader(hdev);
1898 /* The bootloader will not indicate when the device is ready. This
1899 * is done by the operational firmware sending bootup notification.
1901 * Booting into operational firmware should not take longer than
1902 * 1 second. However if that happens, then just fail the setup
1903 * since something went wrong.
1905 err = btintel_boot_wait(hdev, calltime, 1000);
1906 if (err == -ETIMEDOUT)
1907 btintel_reset_to_bootloader(hdev);
1912 static int btintel_get_fw_name(struct intel_version *ver,
1913 struct intel_boot_params *params,
1914 char *fw_name, size_t len,
1917 switch (ver->hw_variant) {
1918 case 0x0b: /* SfP */
1919 case 0x0c: /* WsP */
1920 snprintf(fw_name, len, "intel/ibt-%u-%u.%s",
1922 le16_to_cpu(params->dev_revid),
1925 case 0x11: /* JfP */
1926 case 0x12: /* ThP */
1927 case 0x13: /* HrP */
1928 case 0x14: /* CcP */
1929 snprintf(fw_name, len, "intel/ibt-%u-%u-%u.%s",
1942 static int btintel_download_fw(struct hci_dev *hdev,
1943 struct intel_version *ver,
1944 struct intel_boot_params *params,
1947 const struct firmware *fw;
1952 if (!ver || !params)
1955 /* The firmware variant determines if the device is in bootloader
1956 * mode or is running operational firmware. The value 0x06 identifies
1957 * the bootloader and the value 0x23 identifies the operational
1960 * When the operational firmware is already present, then only
1961 * the check for valid Bluetooth device address is needed. This
1962 * determines if the device will be added as configured or
1963 * unconfigured controller.
1965 * It is not possible to use the Secure Boot Parameters in this
1966 * case since that command is only available in bootloader mode.
1968 if (ver->fw_variant == 0x23) {
1969 btintel_clear_flag(hdev, INTEL_BOOTLOADER);
1970 btintel_check_bdaddr(hdev);
1972 /* SfP and WsP don't seem to update the firmware version on file
1973 * so version checking is currently possible.
1975 switch (ver->hw_variant) {
1976 case 0x0b: /* SfP */
1977 case 0x0c: /* WsP */
1981 /* Proceed to download to check if the version matches */
1985 /* Read the secure boot parameters to identify the operating
1986 * details of the bootloader.
1988 err = btintel_read_boot_params(hdev, params);
1992 /* It is required that every single firmware fragment is acknowledged
1993 * with a command complete event. If the boot parameters indicate
1994 * that this bootloader does not send them, then abort the setup.
1996 if (params->limited_cce != 0x00) {
1997 bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)",
1998 params->limited_cce);
2002 /* If the OTP has no valid Bluetooth device address, then there will
2003 * also be no valid address for the operational firmware.
2005 if (!bacmp(¶ms->otp_bdaddr, BDADDR_ANY)) {
2006 bt_dev_info(hdev, "No device address configured");
2007 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
2011 /* With this Intel bootloader only the hardware variant and device
2012 * revision information are used to select the right firmware for SfP
2015 * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi.
2017 * Currently the supported hardware variants are:
2018 * 11 (0x0b) for iBT3.0 (LnP/SfP)
2019 * 12 (0x0c) for iBT3.5 (WsP)
2021 * For ThP/JfP and for future SKU's, the FW name varies based on HW
2022 * variant, HW revision and FW revision, as these are dependent on CNVi
2023 * and RF Combination.
2025 * 17 (0x11) for iBT3.5 (JfP)
2026 * 18 (0x12) for iBT3.5 (ThP)
2028 * The firmware file name for these will be
2029 * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
2032 err = btintel_get_fw_name(ver, params, fwname, sizeof(fwname), "sfi");
2034 if (!btintel_test_flag(hdev, INTEL_BOOTLOADER)) {
2035 /* Firmware has already been loaded */
2036 btintel_set_flag(hdev, INTEL_FIRMWARE_LOADED);
2040 bt_dev_err(hdev, "Unsupported Intel firmware naming");
2044 err = firmware_request_nowarn(&fw, fwname, &hdev->dev);
2046 if (!btintel_test_flag(hdev, INTEL_BOOTLOADER)) {
2047 /* Firmware has already been loaded */
2048 btintel_set_flag(hdev, INTEL_FIRMWARE_LOADED);
2052 bt_dev_err(hdev, "Failed to load Intel firmware file %s (%d)",
2057 bt_dev_info(hdev, "Found device firmware: %s", fwname);
2059 if (fw->size < 644) {
2060 bt_dev_err(hdev, "Invalid size of firmware file (%zu)",
2066 calltime = ktime_get();
2068 btintel_set_flag(hdev, INTEL_DOWNLOADING);
2070 /* Start firmware downloading and get boot parameter */
2071 err = btintel_download_firmware(hdev, ver, fw, boot_param);
2073 if (err == -EALREADY) {
2074 /* Firmware has already been loaded */
2075 btintel_set_flag(hdev, INTEL_FIRMWARE_LOADED);
2080 /* When FW download fails, send Intel Reset to retry
2083 btintel_reset_to_bootloader(hdev);
2087 /* Before switching the device into operational mode and with that
2088 * booting the loaded firmware, wait for the bootloader notification
2089 * that all fragments have been successfully received.
2091 * When the event processing receives the notification, then the
2092 * INTEL_DOWNLOADING flag will be cleared.
2094 * The firmware loading should not take longer than 5 seconds
2095 * and thus just timeout if that happens and fail the setup
2098 err = btintel_download_wait(hdev, calltime, 5000);
2099 if (err == -ETIMEDOUT)
2100 btintel_reset_to_bootloader(hdev);
2103 release_firmware(fw);
2107 static int btintel_bootloader_setup(struct hci_dev *hdev,
2108 struct intel_version *ver)
2110 struct intel_version new_ver;
2111 struct intel_boot_params params;
2116 BT_DBG("%s", hdev->name);
2118 /* Set the default boot parameter to 0x0 and it is updated to
2119 * SKU specific boot parameter after reading Intel_Write_Boot_Params
2120 * command while downloading the firmware.
2122 boot_param = 0x00000000;
2124 btintel_set_flag(hdev, INTEL_BOOTLOADER);
2126 err = btintel_download_fw(hdev, ver, ¶ms, &boot_param);
2130 /* controller is already having an operational firmware */
2131 if (ver->fw_variant == 0x23)
2134 err = btintel_boot(hdev, boot_param);
2138 btintel_clear_flag(hdev, INTEL_BOOTLOADER);
2140 err = btintel_get_fw_name(ver, ¶ms, ddcname,
2141 sizeof(ddcname), "ddc");
2144 bt_dev_err(hdev, "Unsupported Intel firmware naming");
2146 /* Once the device is running in operational mode, it needs to
2147 * apply the device configuration (DDC) parameters.
2149 * The device can work without DDC parameters, so even if it
2150 * fails to load the file, no need to fail the setup.
2152 btintel_load_ddc_config(hdev, ddcname);
2155 hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
2157 /* Read the Intel version information after loading the FW */
2158 err = btintel_read_version(hdev, &new_ver);
2162 btintel_version_info(hdev, &new_ver);
2165 /* Set the event mask for Intel specific vendor events. This enables
2166 * a few extra events that are useful during general operation. It
2167 * does not enable any debugging related events.
2169 * The device will function correctly without these events enabled
2170 * and thus no need to fail the setup.
2172 btintel_set_event_mask(hdev, false);
2177 static void btintel_get_fw_name_tlv(const struct intel_version_tlv *ver,
2178 char *fw_name, size_t len,
2181 /* The firmware file name for new generation controllers will be
2182 * ibt-<cnvi_top type+cnvi_top step>-<cnvr_top type+cnvr_top step>
2184 snprintf(fw_name, len, "intel/ibt-%04x-%04x.%s",
2185 INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver->cnvi_top),
2186 INTEL_CNVX_TOP_STEP(ver->cnvi_top)),
2187 INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver->cnvr_top),
2188 INTEL_CNVX_TOP_STEP(ver->cnvr_top)),
2192 static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev,
2193 struct intel_version_tlv *ver,
2196 const struct firmware *fw;
2201 if (!ver || !boot_param)
2204 /* The firmware variant determines if the device is in bootloader
2205 * mode or is running operational firmware. The value 0x03 identifies
2206 * the bootloader and the value 0x23 identifies the operational
2209 * When the operational firmware is already present, then only
2210 * the check for valid Bluetooth device address is needed. This
2211 * determines if the device will be added as configured or
2212 * unconfigured controller.
2214 * It is not possible to use the Secure Boot Parameters in this
2215 * case since that command is only available in bootloader mode.
2217 if (ver->img_type == 0x03) {
2218 btintel_clear_flag(hdev, INTEL_BOOTLOADER);
2219 btintel_check_bdaddr(hdev);
2222 * Check for valid bd address in boot loader mode. Device
2223 * will be marked as unconfigured if empty bd address is
2226 if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
2227 bt_dev_info(hdev, "No device address configured");
2228 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
2232 btintel_get_fw_name_tlv(ver, fwname, sizeof(fwname), "sfi");
2233 err = firmware_request_nowarn(&fw, fwname, &hdev->dev);
2235 if (!btintel_test_flag(hdev, INTEL_BOOTLOADER)) {
2236 /* Firmware has already been loaded */
2237 btintel_set_flag(hdev, INTEL_FIRMWARE_LOADED);
2241 bt_dev_err(hdev, "Failed to load Intel firmware file %s (%d)",
2247 bt_dev_info(hdev, "Found device firmware: %s", fwname);
2249 if (fw->size < 644) {
2250 bt_dev_err(hdev, "Invalid size of firmware file (%zu)",
2256 calltime = ktime_get();
2258 btintel_set_flag(hdev, INTEL_DOWNLOADING);
2260 /* Start firmware downloading and get boot parameter */
2261 err = btintel_download_fw_tlv(hdev, ver, fw, boot_param,
2262 INTEL_HW_VARIANT(ver->cnvi_bt),
2265 if (err == -EALREADY) {
2266 /* Firmware has already been loaded */
2267 btintel_set_flag(hdev, INTEL_FIRMWARE_LOADED);
2272 /* When FW download fails, send Intel Reset to retry
2275 btintel_reset_to_bootloader(hdev);
2279 /* Before switching the device into operational mode and with that
2280 * booting the loaded firmware, wait for the bootloader notification
2281 * that all fragments have been successfully received.
2283 * When the event processing receives the notification, then the
2284 * BTUSB_DOWNLOADING flag will be cleared.
2286 * The firmware loading should not take longer than 5 seconds
2287 * and thus just timeout if that happens and fail the setup
2290 err = btintel_download_wait(hdev, calltime, 5000);
2291 if (err == -ETIMEDOUT)
2292 btintel_reset_to_bootloader(hdev);
2295 release_firmware(fw);
2299 static int btintel_get_codec_config_data(struct hci_dev *hdev,
2300 __u8 link, struct bt_codec *codec,
2301 __u8 *ven_len, __u8 **ven_data)
2305 if (!ven_data || !ven_len)
2311 if (link != ESCO_LINK) {
2312 bt_dev_err(hdev, "Invalid link type(%u)", link);
2316 *ven_data = kmalloc(sizeof(__u8), GFP_KERNEL);
2322 /* supports only CVSD and mSBC offload codecs */
2323 switch (codec->id) {
2332 bt_dev_err(hdev, "Invalid codec id(%u)", codec->id);
2335 /* codec and its capabilities are pre-defined to ids
2336 * preset id = 0x00 represents CVSD codec with sampling rate 8K
2337 * preset id = 0x01 represents mSBC codec with sampling rate 16K
2339 *ven_len = sizeof(__u8);
2348 static int btintel_get_data_path_id(struct hci_dev *hdev, __u8 *data_path_id)
2350 /* Intel uses 1 as data path id for all the usecases */
2355 static int btintel_configure_offload(struct hci_dev *hdev)
2357 struct sk_buff *skb;
2359 struct intel_offload_use_cases *use_cases;
2361 skb = __hci_cmd_sync(hdev, 0xfc86, 0, NULL, HCI_INIT_TIMEOUT);
2363 bt_dev_err(hdev, "Reading offload use cases failed (%ld)",
2365 return PTR_ERR(skb);
2368 if (skb->len < sizeof(*use_cases)) {
2373 use_cases = (void *)skb->data;
2375 if (use_cases->status) {
2376 err = -bt_to_errno(skb->data[0]);
2380 if (use_cases->preset[0] & 0x03) {
2381 hdev->get_data_path_id = btintel_get_data_path_id;
2382 hdev->get_codec_config_data = btintel_get_codec_config_data;
2389 static void btintel_set_ppag(struct hci_dev *hdev, struct intel_version_tlv *ver)
2391 struct btintel_ppag ppag;
2392 struct sk_buff *skb;
2393 struct btintel_loc_aware_reg ppag_cmd;
2396 /* PPAG is not supported if CRF is HrP2, Jfp2, JfP1 */
2397 switch (ver->cnvr_top & 0xFFF) {
2398 case 0x504: /* Hrp2 */
2399 case 0x202: /* Jfp2 */
2400 case 0x201: /* Jfp1 */
2404 handle = ACPI_HANDLE(GET_HCIDEV_DEV(hdev));
2406 bt_dev_info(hdev, "No support for BT device in ACPI firmware");
2410 memset(&ppag, 0, sizeof(ppag));
2413 ppag.status = AE_NOT_FOUND;
2414 acpi_walk_namespace(ACPI_TYPE_PACKAGE, handle, 1, NULL,
2415 btintel_ppag_callback, &ppag, NULL);
2417 if (ACPI_FAILURE(ppag.status)) {
2418 if (ppag.status == AE_NOT_FOUND) {
2419 bt_dev_dbg(hdev, "PPAG-BT: ACPI entry not found");
2425 if (ppag.domain != 0x12) {
2426 bt_dev_warn(hdev, "PPAG-BT: domain is not bluetooth");
2430 /* PPAG mode, BIT0 = 0 Disabled, BIT0 = 1 Enabled */
2431 if (!(ppag.mode & BIT(0))) {
2432 bt_dev_dbg(hdev, "PPAG-BT: disabled");
2436 ppag_cmd.mcc = cpu_to_le32(0);
2437 ppag_cmd.sel = cpu_to_le32(0); /* 0 - Enable , 1 - Disable, 2 - Testing mode */
2438 ppag_cmd.delta = cpu_to_le32(0);
2439 skb = __hci_cmd_sync(hdev, 0xfe19, sizeof(ppag_cmd), &ppag_cmd, HCI_CMD_TIMEOUT);
2441 bt_dev_warn(hdev, "Failed to send PPAG Enable (%ld)", PTR_ERR(skb));
2447 static int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
2448 struct intel_version_tlv *ver)
2453 struct intel_version_tlv new_ver;
2455 bt_dev_dbg(hdev, "");
2457 /* Set the default boot parameter to 0x0 and it is updated to
2458 * SKU specific boot parameter after reading Intel_Write_Boot_Params
2459 * command while downloading the firmware.
2461 boot_param = 0x00000000;
2463 btintel_set_flag(hdev, INTEL_BOOTLOADER);
2465 err = btintel_prepare_fw_download_tlv(hdev, ver, &boot_param);
2469 /* check if controller is already having an operational firmware */
2470 if (ver->img_type == 0x03)
2473 err = btintel_boot(hdev, boot_param);
2477 btintel_clear_flag(hdev, INTEL_BOOTLOADER);
2479 btintel_get_fw_name_tlv(ver, ddcname, sizeof(ddcname), "ddc");
2480 /* Once the device is running in operational mode, it needs to
2481 * apply the device configuration (DDC) parameters.
2483 * The device can work without DDC parameters, so even if it
2484 * fails to load the file, no need to fail the setup.
2486 btintel_load_ddc_config(hdev, ddcname);
2488 /* Read supported use cases and set callbacks to fetch datapath id */
2489 btintel_configure_offload(hdev);
2491 hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
2493 /* Set PPAG feature */
2494 btintel_set_ppag(hdev, ver);
2496 /* Read the Intel version information after loading the FW */
2497 err = btintel_read_version_tlv(hdev, &new_ver);
2501 btintel_version_info_tlv(hdev, &new_ver);
2504 /* Set the event mask for Intel specific vendor events. This enables
2505 * a few extra events that are useful during general operation. It
2506 * does not enable any debugging related events.
2508 * The device will function correctly without these events enabled
2509 * and thus no need to fail the setup.
2511 btintel_set_event_mask(hdev, false);
2516 static void btintel_set_msft_opcode(struct hci_dev *hdev, u8 hw_variant)
2518 switch (hw_variant) {
2519 /* Legacy bootloader devices that supports MSFT Extension */
2520 case 0x11: /* JfP */
2521 case 0x12: /* ThP */
2522 case 0x13: /* HrP */
2523 case 0x14: /* CcP */
2524 /* All Intel new genration controllers support the Microsoft vendor
2525 * extension are using 0xFC1E for VsMsftOpCode.
2531 hci_set_msft_opcode(hdev, 0xFC1E);
2539 static int btintel_setup_combined(struct hci_dev *hdev)
2541 const u8 param[1] = { 0xFF };
2542 struct intel_version ver;
2543 struct intel_version_tlv ver_tlv;
2544 struct sk_buff *skb;
2547 BT_DBG("%s", hdev->name);
2549 /* The some controllers have a bug with the first HCI command sent to it
2550 * returning number of completed commands as zero. This would stall the
2551 * command processing in the Bluetooth core.
2553 * As a workaround, send HCI Reset command first which will reset the
2554 * number of completed commands and allow normal command processing
2557 * Regarding the INTEL_BROKEN_SHUTDOWN_LED flag, these devices maybe
2558 * in the SW_RFKILL ON state as a workaround of fixing LED issue during
2559 * the shutdown() procedure, and once the device is in SW_RFKILL ON
2560 * state, the only way to exit out of it is sending the HCI_Reset
2563 if (btintel_test_flag(hdev, INTEL_BROKEN_INITIAL_NCMD) ||
2564 btintel_test_flag(hdev, INTEL_BROKEN_SHUTDOWN_LED)) {
2565 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL,
2569 "sending initial HCI reset failed (%ld)",
2571 return PTR_ERR(skb);
2576 /* Starting from TyP device, the command parameter and response are
2577 * changed even though the OCF for HCI_Intel_Read_Version command
2578 * remains same. The legacy devices can handle even if the
2579 * command has a parameter and returns a correct version information.
2580 * So, it uses new format to support both legacy and new format.
2582 skb = __hci_cmd_sync(hdev, 0xfc05, 1, param, HCI_CMD_TIMEOUT);
2584 bt_dev_err(hdev, "Reading Intel version command failed (%ld)",
2586 return PTR_ERR(skb);
2589 /* Check the status */
2591 bt_dev_err(hdev, "Intel Read Version command failed (%02x)",
2597 /* Apply the common HCI quirks for Intel device */
2598 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
2599 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
2600 set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks);
2602 /* Set up the quality report callback for Intel devices */
2603 hdev->set_quality_report = btintel_set_quality_report;
2605 /* For Legacy device, check the HW platform value and size */
2606 if (skb->len == sizeof(ver) && skb->data[1] == 0x37) {
2607 bt_dev_dbg(hdev, "Read the legacy Intel version information");
2609 memcpy(&ver, skb->data, sizeof(ver));
2611 /* Display version information */
2612 btintel_version_info(hdev, &ver);
2614 /* Check for supported iBT hardware variants of this firmware
2617 * This check has been put in place to ensure correct forward
2618 * compatibility options when newer hardware variants come
2621 switch (ver.hw_variant) {
2623 case 0x08: /* StP */
2624 /* Legacy ROM product */
2625 btintel_set_flag(hdev, INTEL_ROM_LEGACY);
2627 /* Apply the device specific HCI quirks
2629 * WBS for SdP - For the Legacy ROM products, only SdP
2630 * supports the WBS. But the version information is not
2631 * enough to use here because the StP2 and SdP have same
2632 * hw_variant and fw_variant. So, this flag is set by
2633 * the transport driver (btusb) based on the HW info
2636 if (!btintel_test_flag(hdev,
2637 INTEL_ROM_LEGACY_NO_WBS_SUPPORT))
2638 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED,
2640 if (ver.hw_variant == 0x08 && ver.fw_variant == 0x22)
2641 set_bit(HCI_QUIRK_VALID_LE_STATES,
2644 err = btintel_legacy_rom_setup(hdev, &ver);
2646 case 0x0b: /* SfP */
2647 case 0x11: /* JfP */
2648 case 0x12: /* ThP */
2649 case 0x13: /* HrP */
2650 case 0x14: /* CcP */
2651 set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
2653 case 0x0c: /* WsP */
2654 /* Apply the device specific HCI quirks
2656 * All Legacy bootloader devices support WBS
2658 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED,
2661 /* Setup MSFT Extension support */
2662 btintel_set_msft_opcode(hdev, ver.hw_variant);
2664 err = btintel_bootloader_setup(hdev, &ver);
2665 btintel_register_devcoredump_support(hdev);
2668 bt_dev_err(hdev, "Unsupported Intel hw variant (%u)",
2676 /* memset ver_tlv to start with clean state as few fields are exclusive
2677 * to bootloader mode and are not populated in operational mode
2679 memset(&ver_tlv, 0, sizeof(ver_tlv));
2680 /* For TLV type device, parse the tlv data */
2681 err = btintel_parse_version_tlv(hdev, &ver_tlv, skb);
2683 bt_dev_err(hdev, "Failed to parse TLV version information");
2687 if (INTEL_HW_PLATFORM(ver_tlv.cnvi_bt) != 0x37) {
2688 bt_dev_err(hdev, "Unsupported Intel hardware platform (0x%2x)",
2689 INTEL_HW_PLATFORM(ver_tlv.cnvi_bt));
2694 /* Check for supported iBT hardware variants of this firmware
2697 * This check has been put in place to ensure correct forward
2698 * compatibility options when newer hardware variants come
2701 switch (INTEL_HW_VARIANT(ver_tlv.cnvi_bt)) {
2702 case 0x11: /* JfP */
2703 case 0x12: /* ThP */
2704 case 0x13: /* HrP */
2705 case 0x14: /* CcP */
2706 /* Some legacy bootloader devices starting from JfP,
2707 * the operational firmware supports both old and TLV based
2708 * HCI_Intel_Read_Version command based on the command
2711 * For upgrading firmware case, the TLV based version cannot
2712 * be used because the firmware filename for legacy bootloader
2713 * is based on the old format.
2715 * Also, it is not easy to convert TLV based version from the
2716 * legacy version format.
2718 * So, as a workaround for those devices, use the legacy
2719 * HCI_Intel_Read_Version to get the version information and
2720 * run the legacy bootloader setup.
2722 err = btintel_read_version(hdev, &ver);
2726 /* Apply the device specific HCI quirks
2728 * All Legacy bootloader devices support WBS
2730 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks);
2732 /* Set Valid LE States quirk */
2733 set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
2735 /* Setup MSFT Extension support */
2736 btintel_set_msft_opcode(hdev, ver.hw_variant);
2738 err = btintel_bootloader_setup(hdev, &ver);
2739 btintel_register_devcoredump_support(hdev);
2745 /* Display version information of TLV type */
2746 btintel_version_info_tlv(hdev, &ver_tlv);
2748 /* Apply the device specific HCI quirks for TLV based devices
2750 * All TLV based devices support WBS
2752 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED, &hdev->quirks);
2754 /* Apply LE States quirk from solar onwards */
2755 set_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks);
2757 /* Setup MSFT Extension support */
2758 btintel_set_msft_opcode(hdev,
2759 INTEL_HW_VARIANT(ver_tlv.cnvi_bt));
2761 err = btintel_bootloader_setup_tlv(hdev, &ver_tlv);
2762 btintel_register_devcoredump_support(hdev);
2765 bt_dev_err(hdev, "Unsupported Intel hw variant (%u)",
2766 INTEL_HW_VARIANT(ver_tlv.cnvi_bt));
2777 static int btintel_shutdown_combined(struct hci_dev *hdev)
2779 struct sk_buff *skb;
2782 /* Send HCI Reset to the controller to stop any BT activity which
2783 * were triggered. This will help to save power and maintain the
2784 * sync b/w Host and controller
2786 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
2788 bt_dev_err(hdev, "HCI reset during shutdown failed");
2789 return PTR_ERR(skb);
2794 /* Some platforms have an issue with BT LED when the interface is
2795 * down or BT radio is turned off, which takes 5 seconds to BT LED
2796 * goes off. As a workaround, sends HCI_Intel_SW_RFKILL to put the
2797 * device in the RFKILL ON state which turns off the BT LED immediately.
2799 if (btintel_test_flag(hdev, INTEL_BROKEN_SHUTDOWN_LED)) {
2800 skb = __hci_cmd_sync(hdev, 0xfc3f, 0, NULL, HCI_INIT_TIMEOUT);
2803 bt_dev_err(hdev, "turning off Intel device LED failed");
2812 int btintel_configure_setup(struct hci_dev *hdev, const char *driver_name)
2814 hdev->manufacturer = 2;
2815 hdev->setup = btintel_setup_combined;
2816 hdev->shutdown = btintel_shutdown_combined;
2817 hdev->hw_error = btintel_hw_error;
2818 hdev->set_diag = btintel_set_diag_combined;
2819 hdev->set_bdaddr = btintel_set_bdaddr;
2821 coredump_info.driver_name = driver_name;
2825 EXPORT_SYMBOL_GPL(btintel_configure_setup);
2827 void btintel_bootup(struct hci_dev *hdev, const void *ptr, unsigned int len)
2829 const struct intel_bootup *evt = ptr;
2831 if (len != sizeof(*evt))
2834 if (btintel_test_and_clear_flag(hdev, INTEL_BOOTING))
2835 btintel_wake_up_flag(hdev, INTEL_BOOTING);
2837 EXPORT_SYMBOL_GPL(btintel_bootup);
2839 void btintel_secure_send_result(struct hci_dev *hdev,
2840 const void *ptr, unsigned int len)
2842 const struct intel_secure_send_result *evt = ptr;
2844 if (len != sizeof(*evt))
2848 btintel_set_flag(hdev, INTEL_FIRMWARE_FAILED);
2850 if (btintel_test_and_clear_flag(hdev, INTEL_DOWNLOADING) &&
2851 btintel_test_flag(hdev, INTEL_FIRMWARE_LOADED))
2852 btintel_wake_up_flag(hdev, INTEL_DOWNLOADING);
2854 EXPORT_SYMBOL_GPL(btintel_secure_send_result);
2856 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
2857 MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
2858 MODULE_VERSION(VERSION);
2859 MODULE_LICENSE("GPL");
2860 MODULE_FIRMWARE("intel/ibt-11-5.sfi");
2861 MODULE_FIRMWARE("intel/ibt-11-5.ddc");
2862 MODULE_FIRMWARE("intel/ibt-12-16.sfi");
2863 MODULE_FIRMWARE("intel/ibt-12-16.ddc");