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 <asm/unaligned.h>
14 #include <net/bluetooth/bluetooth.h>
15 #include <net/bluetooth/hci_core.h>
21 #define BDADDR_INTEL (&(bdaddr_t){{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
22 #define RSA_HEADER_LEN 644
23 #define CSS_HEADER_OFFSET 8
24 #define ECDSA_OFFSET 644
25 #define ECDSA_HEADER_LEN 320
27 #define CMD_WRITE_BOOT_PARAMS 0xfc0e
28 struct cmd_write_boot_params {
35 int btintel_check_bdaddr(struct hci_dev *hdev)
37 struct hci_rp_read_bd_addr *bda;
40 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
43 int err = PTR_ERR(skb);
44 bt_dev_err(hdev, "Reading Intel device address failed (%d)",
49 if (skb->len != sizeof(*bda)) {
50 bt_dev_err(hdev, "Intel device address length mismatch");
55 bda = (struct hci_rp_read_bd_addr *)skb->data;
57 /* For some Intel based controllers, the default Bluetooth device
58 * address 00:03:19:9E:8B:00 can be found. These controllers are
59 * fully operational, but have the danger of duplicate addresses
60 * and that in turn can cause problems with Bluetooth operation.
62 if (!bacmp(&bda->bdaddr, BDADDR_INTEL)) {
63 bt_dev_err(hdev, "Found Intel default device address (%pMR)",
65 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
72 EXPORT_SYMBOL_GPL(btintel_check_bdaddr);
74 int btintel_enter_mfg(struct hci_dev *hdev)
76 static const u8 param[] = { 0x01, 0x00 };
79 skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT);
81 bt_dev_err(hdev, "Entering manufacturer mode failed (%ld)",
89 EXPORT_SYMBOL_GPL(btintel_enter_mfg);
91 int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched)
93 u8 param[] = { 0x00, 0x00 };
96 /* The 2nd command parameter specifies the manufacturing exit method:
97 * 0x00: Just disable the manufacturing mode (0x00).
98 * 0x01: Disable manufacturing mode and reset with patches deactivated.
99 * 0x02: Disable manufacturing mode and reset with patches activated.
102 param[1] |= patched ? 0x02 : 0x01;
104 skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT);
106 bt_dev_err(hdev, "Exiting manufacturer mode failed (%ld)",
114 EXPORT_SYMBOL_GPL(btintel_exit_mfg);
116 int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
121 skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT);
124 bt_dev_err(hdev, "Changing Intel device address failed (%d)",
132 EXPORT_SYMBOL_GPL(btintel_set_bdaddr);
134 int btintel_set_diag(struct hci_dev *hdev, bool enable)
150 skb = __hci_cmd_sync(hdev, 0xfc43, 3, param, HCI_INIT_TIMEOUT);
155 bt_dev_err(hdev, "Changing Intel diagnostic mode failed (%d)",
162 btintel_set_event_mask(hdev, enable);
165 EXPORT_SYMBOL_GPL(btintel_set_diag);
167 int btintel_set_diag_mfg(struct hci_dev *hdev, bool enable)
171 err = btintel_enter_mfg(hdev);
175 ret = btintel_set_diag(hdev, enable);
177 err = btintel_exit_mfg(hdev, false, false);
183 EXPORT_SYMBOL_GPL(btintel_set_diag_mfg);
185 void btintel_hw_error(struct hci_dev *hdev, u8 code)
190 bt_dev_err(hdev, "Hardware error 0x%2.2x", code);
192 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
194 bt_dev_err(hdev, "Reset after hardware error failed (%ld)",
200 skb = __hci_cmd_sync(hdev, 0xfc22, 1, &type, HCI_INIT_TIMEOUT);
202 bt_dev_err(hdev, "Retrieving Intel exception info failed (%ld)",
207 if (skb->len != 13) {
208 bt_dev_err(hdev, "Exception info size mismatch");
213 bt_dev_err(hdev, "Exception info %s", (char *)(skb->data + 1));
217 EXPORT_SYMBOL_GPL(btintel_hw_error);
219 int btintel_version_info(struct hci_dev *hdev, struct intel_version *ver)
223 /* The hardware platform number has a fixed value of 0x37 and
224 * for now only accept this single value.
226 if (ver->hw_platform != 0x37) {
227 bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)",
232 /* Check for supported iBT hardware variants of this firmware
235 * This check has been put in place to ensure correct forward
236 * compatibility options when newer hardware variants come along.
238 switch (ver->hw_variant) {
247 bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)",
252 switch (ver->fw_variant) {
254 variant = "Bootloader";
257 variant = "Firmware";
260 bt_dev_err(hdev, "Unsupported firmware variant(%02x)", ver->fw_variant);
264 bt_dev_info(hdev, "%s revision %u.%u build %u week %u %u",
265 variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f,
266 ver->fw_build_num, ver->fw_build_ww,
267 2000 + ver->fw_build_yy);
271 EXPORT_SYMBOL_GPL(btintel_version_info);
273 int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen,
278 u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen;
280 cmd_param[0] = fragment_type;
281 memcpy(cmd_param + 1, param, fragment_len);
283 skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1,
284 cmd_param, HCI_INIT_TIMEOUT);
290 plen -= fragment_len;
291 param += fragment_len;
296 EXPORT_SYMBOL_GPL(btintel_secure_send);
298 int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name)
300 const struct firmware *fw;
305 err = request_firmware_direct(&fw, ddc_name, &hdev->dev);
307 bt_dev_err(hdev, "Failed to load Intel DDC file %s (%d)",
312 bt_dev_info(hdev, "Found Intel DDC parameters: %s", ddc_name);
316 /* DDC file contains one or more DDC structure which has
317 * Length (1 byte), DDC ID (2 bytes), and DDC value (Length - 2).
319 while (fw->size > fw_ptr - fw->data) {
320 u8 cmd_plen = fw_ptr[0] + sizeof(u8);
322 skb = __hci_cmd_sync(hdev, 0xfc8b, cmd_plen, fw_ptr,
325 bt_dev_err(hdev, "Failed to send Intel_Write_DDC (%ld)",
327 release_firmware(fw);
335 release_firmware(fw);
337 bt_dev_info(hdev, "Applying Intel DDC parameters completed");
341 EXPORT_SYMBOL_GPL(btintel_load_ddc_config);
343 int btintel_set_event_mask(struct hci_dev *hdev, bool debug)
345 u8 mask[8] = { 0x87, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
352 skb = __hci_cmd_sync(hdev, 0xfc52, 8, mask, HCI_INIT_TIMEOUT);
355 bt_dev_err(hdev, "Setting Intel event mask failed (%d)", err);
362 EXPORT_SYMBOL_GPL(btintel_set_event_mask);
364 int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug)
368 err = btintel_enter_mfg(hdev);
372 ret = btintel_set_event_mask(hdev, debug);
374 err = btintel_exit_mfg(hdev, false, false);
380 EXPORT_SYMBOL_GPL(btintel_set_event_mask_mfg);
382 int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver)
386 skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_CMD_TIMEOUT);
388 bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
393 if (skb->len != sizeof(*ver)) {
394 bt_dev_err(hdev, "Intel version event size mismatch");
399 memcpy(ver, skb->data, sizeof(*ver));
405 EXPORT_SYMBOL_GPL(btintel_read_version);
407 int btintel_version_info_tlv(struct hci_dev *hdev, struct intel_version_tlv *version)
411 /* The hardware platform number has a fixed value of 0x37 and
412 * for now only accept this single value.
414 if (INTEL_HW_PLATFORM(version->cnvi_bt) != 0x37) {
415 bt_dev_err(hdev, "Unsupported Intel hardware platform (0x%2x)",
416 INTEL_HW_PLATFORM(version->cnvi_bt));
420 /* Check for supported iBT hardware variants of this firmware
423 * This check has been put in place to ensure correct forward
424 * compatibility options when newer hardware variants come along.
426 switch (INTEL_HW_VARIANT(version->cnvi_bt)) {
429 case 0x19: /* Slr-F */
432 bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%x)",
433 INTEL_HW_VARIANT(version->cnvi_bt));
437 switch (version->img_type) {
439 variant = "Bootloader";
440 /* It is required that every single firmware fragment is acknowledged
441 * with a command complete event. If the boot parameters indicate
442 * that this bootloader does not send them, then abort the setup.
444 if (version->limited_cce != 0x00) {
445 bt_dev_err(hdev, "Unsupported Intel firmware loading method (0x%x)",
446 version->limited_cce);
450 /* Secure boot engine type should be either 1 (ECDSA) or 0 (RSA) */
451 if (version->sbe_type > 0x01) {
452 bt_dev_err(hdev, "Unsupported Intel secure boot engine type (0x%x)",
457 bt_dev_info(hdev, "Device revision is %u", version->dev_rev_id);
458 bt_dev_info(hdev, "Secure boot is %s",
459 version->secure_boot ? "enabled" : "disabled");
460 bt_dev_info(hdev, "OTP lock is %s",
461 version->otp_lock ? "enabled" : "disabled");
462 bt_dev_info(hdev, "API lock is %s",
463 version->api_lock ? "enabled" : "disabled");
464 bt_dev_info(hdev, "Debug lock is %s",
465 version->debug_lock ? "enabled" : "disabled");
466 bt_dev_info(hdev, "Minimum firmware build %u week %u %u",
467 version->min_fw_build_nn, version->min_fw_build_cw,
468 2000 + version->min_fw_build_yy);
471 variant = "Firmware";
474 bt_dev_err(hdev, "Unsupported image type(%02x)", version->img_type);
478 bt_dev_info(hdev, "%s timestamp %u.%u buildtype %u build %u", variant,
479 2000 + (version->timestamp >> 8), version->timestamp & 0xff,
480 version->build_type, version->build_num);
484 EXPORT_SYMBOL_GPL(btintel_version_info_tlv);
486 int btintel_read_version_tlv(struct hci_dev *hdev, struct intel_version_tlv *version)
489 const u8 param[1] = { 0xFF };
494 skb = __hci_cmd_sync(hdev, 0xfc05, 1, param, HCI_CMD_TIMEOUT);
496 bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
502 bt_dev_err(hdev, "Intel Read Version command failed (%02x)",
508 /* Consume Command Complete Status field */
511 /* Event parameters contatin multiple TLVs. Read each of them
512 * and only keep the required data. Also, it use existing legacy
513 * version field like hw_platform, hw_variant, and fw_variant
514 * to keep the existing setup flow
517 struct intel_tlv *tlv;
519 tlv = (struct intel_tlv *)skb->data;
521 case INTEL_TLV_CNVI_TOP:
522 version->cnvi_top = get_unaligned_le32(tlv->val);
524 case INTEL_TLV_CNVR_TOP:
525 version->cnvr_top = get_unaligned_le32(tlv->val);
527 case INTEL_TLV_CNVI_BT:
528 version->cnvi_bt = get_unaligned_le32(tlv->val);
530 case INTEL_TLV_CNVR_BT:
531 version->cnvr_bt = get_unaligned_le32(tlv->val);
533 case INTEL_TLV_DEV_REV_ID:
534 version->dev_rev_id = get_unaligned_le16(tlv->val);
536 case INTEL_TLV_IMAGE_TYPE:
537 version->img_type = tlv->val[0];
539 case INTEL_TLV_TIME_STAMP:
540 /* If image type is Operational firmware (0x03), then
541 * running FW Calendar Week and Year information can
542 * be extracted from Timestamp information
544 version->min_fw_build_cw = tlv->val[0];
545 version->min_fw_build_yy = tlv->val[1];
546 version->timestamp = get_unaligned_le16(tlv->val);
548 case INTEL_TLV_BUILD_TYPE:
549 version->build_type = tlv->val[0];
551 case INTEL_TLV_BUILD_NUM:
552 /* If image type is Operational firmware (0x03), then
553 * running FW build number can be extracted from the
556 version->min_fw_build_nn = tlv->val[0];
557 version->build_num = get_unaligned_le32(tlv->val);
559 case INTEL_TLV_SECURE_BOOT:
560 version->secure_boot = tlv->val[0];
562 case INTEL_TLV_OTP_LOCK:
563 version->otp_lock = tlv->val[0];
565 case INTEL_TLV_API_LOCK:
566 version->api_lock = tlv->val[0];
568 case INTEL_TLV_DEBUG_LOCK:
569 version->debug_lock = tlv->val[0];
571 case INTEL_TLV_MIN_FW:
572 version->min_fw_build_nn = tlv->val[0];
573 version->min_fw_build_cw = tlv->val[1];
574 version->min_fw_build_yy = tlv->val[2];
576 case INTEL_TLV_LIMITED_CCE:
577 version->limited_cce = tlv->val[0];
579 case INTEL_TLV_SBE_TYPE:
580 version->sbe_type = tlv->val[0];
582 case INTEL_TLV_OTP_BDADDR:
583 memcpy(&version->otp_bd_addr, tlv->val, tlv->len);
586 /* Ignore rest of information */
589 /* consume the current tlv and move to next*/
590 skb_pull(skb, tlv->len + sizeof(*tlv));
596 EXPORT_SYMBOL_GPL(btintel_read_version_tlv);
598 /* ------- REGMAP IBT SUPPORT ------- */
600 #define IBT_REG_MODE_8BIT 0x00
601 #define IBT_REG_MODE_16BIT 0x01
602 #define IBT_REG_MODE_32BIT 0x02
604 struct regmap_ibt_context {
605 struct hci_dev *hdev;
610 struct ibt_cp_reg_access {
617 struct ibt_rp_reg_access {
623 static int regmap_ibt_read(void *context, const void *addr, size_t reg_size,
624 void *val, size_t val_size)
626 struct regmap_ibt_context *ctx = context;
627 struct ibt_cp_reg_access cp;
628 struct ibt_rp_reg_access *rp;
632 if (reg_size != sizeof(__le32))
637 cp.mode = IBT_REG_MODE_8BIT;
640 cp.mode = IBT_REG_MODE_16BIT;
643 cp.mode = IBT_REG_MODE_32BIT;
649 /* regmap provides a little-endian formatted addr */
650 cp.addr = *(__le32 *)addr;
653 bt_dev_dbg(ctx->hdev, "Register (0x%x) read", le32_to_cpu(cp.addr));
655 skb = hci_cmd_sync(ctx->hdev, ctx->op_read, sizeof(cp), &cp,
659 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error (%d)",
660 le32_to_cpu(cp.addr), err);
664 if (skb->len != sizeof(*rp) + val_size) {
665 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error, bad len",
666 le32_to_cpu(cp.addr));
671 rp = (struct ibt_rp_reg_access *)skb->data;
673 if (rp->addr != cp.addr) {
674 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error, bad addr",
675 le32_to_cpu(rp->addr));
680 memcpy(val, rp->data, val_size);
687 static int regmap_ibt_gather_write(void *context,
688 const void *addr, size_t reg_size,
689 const void *val, size_t val_size)
691 struct regmap_ibt_context *ctx = context;
692 struct ibt_cp_reg_access *cp;
694 int plen = sizeof(*cp) + val_size;
698 if (reg_size != sizeof(__le32))
703 mode = IBT_REG_MODE_8BIT;
706 mode = IBT_REG_MODE_16BIT;
709 mode = IBT_REG_MODE_32BIT;
715 cp = kmalloc(plen, GFP_KERNEL);
719 /* regmap provides a little-endian formatted addr/value */
720 cp->addr = *(__le32 *)addr;
723 memcpy(&cp->data, val, val_size);
725 bt_dev_dbg(ctx->hdev, "Register (0x%x) write", le32_to_cpu(cp->addr));
727 skb = hci_cmd_sync(ctx->hdev, ctx->op_write, plen, cp, HCI_CMD_TIMEOUT);
730 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) write error (%d)",
731 le32_to_cpu(cp->addr), err);
741 static int regmap_ibt_write(void *context, const void *data, size_t count)
743 /* data contains register+value, since we only support 32bit addr,
744 * minimum data size is 4 bytes.
746 if (WARN_ONCE(count < 4, "Invalid register access"))
749 return regmap_ibt_gather_write(context, data, 4, data + 4, count - 4);
752 static void regmap_ibt_free_context(void *context)
757 static struct regmap_bus regmap_ibt = {
758 .read = regmap_ibt_read,
759 .write = regmap_ibt_write,
760 .gather_write = regmap_ibt_gather_write,
761 .free_context = regmap_ibt_free_context,
762 .reg_format_endian_default = REGMAP_ENDIAN_LITTLE,
763 .val_format_endian_default = REGMAP_ENDIAN_LITTLE,
766 /* Config is the same for all register regions */
767 static const struct regmap_config regmap_ibt_cfg = {
768 .name = "btintel_regmap",
773 struct regmap *btintel_regmap_init(struct hci_dev *hdev, u16 opcode_read,
776 struct regmap_ibt_context *ctx;
778 bt_dev_info(hdev, "regmap: Init R%x-W%x region", opcode_read,
781 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
783 return ERR_PTR(-ENOMEM);
785 ctx->op_read = opcode_read;
786 ctx->op_write = opcode_write;
789 return regmap_init(&hdev->dev, ®map_ibt, ctx, ®map_ibt_cfg);
791 EXPORT_SYMBOL_GPL(btintel_regmap_init);
793 int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param)
795 struct intel_reset params = { 0x00, 0x01, 0x00, 0x01, 0x00000000 };
798 params.boot_param = cpu_to_le32(boot_param);
800 skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(params), ¶ms,
803 bt_dev_err(hdev, "Failed to send Intel Reset command");
811 EXPORT_SYMBOL_GPL(btintel_send_intel_reset);
813 int btintel_read_boot_params(struct hci_dev *hdev,
814 struct intel_boot_params *params)
818 skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT);
820 bt_dev_err(hdev, "Reading Intel boot parameters failed (%ld)",
825 if (skb->len != sizeof(*params)) {
826 bt_dev_err(hdev, "Intel boot parameters size mismatch");
831 memcpy(params, skb->data, sizeof(*params));
835 if (params->status) {
836 bt_dev_err(hdev, "Intel boot parameters command failed (%02x)",
838 return -bt_to_errno(params->status);
841 bt_dev_info(hdev, "Device revision is %u",
842 le16_to_cpu(params->dev_revid));
844 bt_dev_info(hdev, "Secure boot is %s",
845 params->secure_boot ? "enabled" : "disabled");
847 bt_dev_info(hdev, "OTP lock is %s",
848 params->otp_lock ? "enabled" : "disabled");
850 bt_dev_info(hdev, "API lock is %s",
851 params->api_lock ? "enabled" : "disabled");
853 bt_dev_info(hdev, "Debug lock is %s",
854 params->debug_lock ? "enabled" : "disabled");
856 bt_dev_info(hdev, "Minimum firmware build %u week %u %u",
857 params->min_fw_build_nn, params->min_fw_build_cw,
858 2000 + params->min_fw_build_yy);
862 EXPORT_SYMBOL_GPL(btintel_read_boot_params);
864 static int btintel_sfi_rsa_header_secure_send(struct hci_dev *hdev,
865 const struct firmware *fw)
869 /* Start the firmware download transaction with the Init fragment
870 * represented by the 128 bytes of CSS header.
872 err = btintel_secure_send(hdev, 0x00, 128, fw->data);
874 bt_dev_err(hdev, "Failed to send firmware header (%d)", err);
878 /* Send the 256 bytes of public key information from the firmware
879 * as the PKey fragment.
881 err = btintel_secure_send(hdev, 0x03, 256, fw->data + 128);
883 bt_dev_err(hdev, "Failed to send firmware pkey (%d)", err);
887 /* Send the 256 bytes of signature information from the firmware
888 * as the Sign fragment.
890 err = btintel_secure_send(hdev, 0x02, 256, fw->data + 388);
892 bt_dev_err(hdev, "Failed to send firmware signature (%d)", err);
900 static int btintel_sfi_ecdsa_header_secure_send(struct hci_dev *hdev,
901 const struct firmware *fw)
905 /* Start the firmware download transaction with the Init fragment
906 * represented by the 128 bytes of CSS header.
908 err = btintel_secure_send(hdev, 0x00, 128, fw->data + 644);
910 bt_dev_err(hdev, "Failed to send firmware header (%d)", err);
914 /* Send the 96 bytes of public key information from the firmware
915 * as the PKey fragment.
917 err = btintel_secure_send(hdev, 0x03, 96, fw->data + 644 + 128);
919 bt_dev_err(hdev, "Failed to send firmware pkey (%d)", err);
923 /* Send the 96 bytes of signature information from the firmware
924 * as the Sign fragment
926 err = btintel_secure_send(hdev, 0x02, 96, fw->data + 644 + 224);
928 bt_dev_err(hdev, "Failed to send firmware signature (%d)",
935 static int btintel_download_firmware_payload(struct hci_dev *hdev,
936 const struct firmware *fw,
943 fw_ptr = fw->data + offset;
947 while (fw_ptr - fw->data < fw->size) {
948 struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len);
950 frag_len += sizeof(*cmd) + cmd->plen;
952 /* The parameter length of the secure send command requires
953 * a 4 byte alignment. It happens so that the firmware file
954 * contains proper Intel_NOP commands to align the fragments
957 * Send set of commands with 4 byte alignment from the
958 * firmware data buffer as a single Data fragement.
960 if (!(frag_len % 4)) {
961 err = btintel_secure_send(hdev, 0x01, frag_len, fw_ptr);
964 "Failed to send firmware data (%d)",
978 static bool btintel_firmware_version(struct hci_dev *hdev,
979 u8 num, u8 ww, u8 yy,
980 const struct firmware *fw,
987 while (fw_ptr - fw->data < fw->size) {
988 struct hci_command_hdr *cmd = (void *)(fw_ptr);
990 /* Each SKU has a different reset parameter to use in the
991 * HCI_Intel_Reset command and it is embedded in the firmware
992 * data. So, instead of using static value per SKU, check
993 * the firmware data and save it for later use.
995 if (le16_to_cpu(cmd->opcode) == CMD_WRITE_BOOT_PARAMS) {
996 struct cmd_write_boot_params *params;
998 params = (void *)(fw_ptr + sizeof(*cmd));
1000 bt_dev_info(hdev, "Boot Address: 0x%x",
1001 le32_to_cpu(params->boot_addr));
1003 bt_dev_info(hdev, "Firmware Version: %u-%u.%u",
1004 params->fw_build_num, params->fw_build_ww,
1005 params->fw_build_yy);
1007 return (num == params->fw_build_num &&
1008 ww == params->fw_build_ww &&
1009 yy == params->fw_build_yy);
1012 fw_ptr += sizeof(*cmd) + cmd->plen;
1018 int btintel_download_firmware(struct hci_dev *hdev,
1019 struct intel_version *ver,
1020 const struct firmware *fw,
1025 /* SfP and WsP don't seem to update the firmware version on file
1026 * so version checking is currently not possible.
1028 switch (ver->hw_variant) {
1029 case 0x0b: /* SfP */
1030 case 0x0c: /* WsP */
1031 /* Skip version checking */
1034 /* Skip reading firmware file version in bootloader mode */
1035 if (ver->fw_variant == 0x06)
1038 /* Skip download if firmware has the same version */
1039 if (btintel_firmware_version(hdev, ver->fw_build_num,
1040 ver->fw_build_ww, ver->fw_build_yy,
1042 bt_dev_info(hdev, "Firmware already loaded");
1043 /* Return -EALREADY to indicate that the firmware has
1044 * already been loaded.
1050 /* The firmware variant determines if the device is in bootloader
1051 * mode or is running operational firmware. The value 0x06 identifies
1052 * the bootloader and the value 0x23 identifies the operational
1055 * If the firmware version has changed that means it needs to be reset
1056 * to bootloader when operational so the new firmware can be loaded.
1058 if (ver->fw_variant == 0x23)
1061 err = btintel_sfi_rsa_header_secure_send(hdev, fw);
1065 return btintel_download_firmware_payload(hdev, fw, RSA_HEADER_LEN);
1067 EXPORT_SYMBOL_GPL(btintel_download_firmware);
1069 int btintel_download_firmware_newgen(struct hci_dev *hdev,
1070 struct intel_version_tlv *ver,
1071 const struct firmware *fw, u32 *boot_param,
1072 u8 hw_variant, u8 sbe_type)
1077 /* Skip reading firmware file version in bootloader mode */
1078 if (ver->img_type != 0x01) {
1079 /* Skip download if firmware has the same version */
1080 if (btintel_firmware_version(hdev, ver->min_fw_build_nn,
1081 ver->min_fw_build_cw,
1082 ver->min_fw_build_yy,
1084 bt_dev_info(hdev, "Firmware already loaded");
1085 /* Return -EALREADY to indicate that firmware has
1086 * already been loaded.
1092 /* The firmware variant determines if the device is in bootloader
1093 * mode or is running operational firmware. The value 0x01 identifies
1094 * the bootloader and the value 0x03 identifies the operational
1097 * If the firmware version has changed that means it needs to be reset
1098 * to bootloader when operational so the new firmware can be loaded.
1100 if (ver->img_type == 0x03)
1103 /* iBT hardware variants 0x0b, 0x0c, 0x11, 0x12, 0x13, 0x14 support
1104 * only RSA secure boot engine. Hence, the corresponding sfi file will
1105 * have RSA header of 644 bytes followed by Command Buffer.
1107 * iBT hardware variants 0x17, 0x18 onwards support both RSA and ECDSA
1108 * secure boot engine. As a result, the corresponding sfi file will
1109 * have RSA header of 644, ECDSA header of 320 bytes followed by
1112 * CSS Header byte positions 0x08 to 0x0B represent the CSS Header
1113 * version: RSA(0x00010000) , ECDSA (0x00020000)
1115 css_header_ver = get_unaligned_le32(fw->data + CSS_HEADER_OFFSET);
1116 if (css_header_ver != 0x00010000) {
1117 bt_dev_err(hdev, "Invalid CSS Header version");
1121 if (hw_variant <= 0x14) {
1122 if (sbe_type != 0x00) {
1123 bt_dev_err(hdev, "Invalid SBE type for hardware variant (%d)",
1128 err = btintel_sfi_rsa_header_secure_send(hdev, fw);
1132 err = btintel_download_firmware_payload(hdev, fw, RSA_HEADER_LEN);
1135 } else if (hw_variant >= 0x17) {
1136 /* Check if CSS header for ECDSA follows the RSA header */
1137 if (fw->data[ECDSA_OFFSET] != 0x06)
1140 /* Check if the CSS Header version is ECDSA(0x00020000) */
1141 css_header_ver = get_unaligned_le32(fw->data + ECDSA_OFFSET + CSS_HEADER_OFFSET);
1142 if (css_header_ver != 0x00020000) {
1143 bt_dev_err(hdev, "Invalid CSS Header version");
1147 if (sbe_type == 0x00) {
1148 err = btintel_sfi_rsa_header_secure_send(hdev, fw);
1152 err = btintel_download_firmware_payload(hdev, fw,
1153 RSA_HEADER_LEN + ECDSA_HEADER_LEN);
1156 } else if (sbe_type == 0x01) {
1157 err = btintel_sfi_ecdsa_header_secure_send(hdev, fw);
1161 err = btintel_download_firmware_payload(hdev, fw,
1162 RSA_HEADER_LEN + ECDSA_HEADER_LEN);
1169 EXPORT_SYMBOL_GPL(btintel_download_firmware_newgen);
1171 void btintel_reset_to_bootloader(struct hci_dev *hdev)
1173 struct intel_reset params;
1174 struct sk_buff *skb;
1176 /* Send Intel Reset command. This will result in
1177 * re-enumeration of BT controller.
1179 * Intel Reset parameter description:
1180 * reset_type : 0x00 (Soft reset),
1182 * patch_enable : 0x00 (Do not enable),
1184 * ddc_reload : 0x00 (Do not reload),
1186 * boot_option: 0x00 (Current image),
1187 * 0x01 (Specified boot address)
1188 * boot_param: Boot address
1191 params.reset_type = 0x01;
1192 params.patch_enable = 0x01;
1193 params.ddc_reload = 0x01;
1194 params.boot_option = 0x00;
1195 params.boot_param = cpu_to_le32(0x00000000);
1197 skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(params),
1198 ¶ms, HCI_INIT_TIMEOUT);
1200 bt_dev_err(hdev, "FW download error recovery failed (%ld)",
1204 bt_dev_info(hdev, "Intel reset sent to retry FW download");
1207 /* Current Intel BT controllers(ThP/JfP) hold the USB reset
1208 * lines for 2ms when it receives Intel Reset in bootloader mode.
1209 * Whereas, the upcoming Intel BT controllers will hold USB reset
1210 * for 150ms. To keep the delay generic, 150ms is chosen here.
1214 EXPORT_SYMBOL_GPL(btintel_reset_to_bootloader);
1216 int btintel_read_debug_features(struct hci_dev *hdev,
1217 struct intel_debug_features *features)
1219 struct sk_buff *skb;
1222 /* Intel controller supports two pages, each page is of 128-bit
1223 * feature bit mask. And each bit defines specific feature support
1225 skb = __hci_cmd_sync(hdev, 0xfca6, sizeof(page_no), &page_no,
1228 bt_dev_err(hdev, "Reading supported features failed (%ld)",
1230 return PTR_ERR(skb);
1233 if (skb->len != (sizeof(features->page1) + 3)) {
1234 bt_dev_err(hdev, "Supported features event size mismatch");
1239 memcpy(features->page1, skb->data + 3, sizeof(features->page1));
1241 /* Read the supported features page2 if required in future.
1246 EXPORT_SYMBOL_GPL(btintel_read_debug_features);
1248 int btintel_set_debug_features(struct hci_dev *hdev,
1249 const struct intel_debug_features *features)
1251 u8 mask[11] = { 0x0a, 0x92, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00,
1253 struct sk_buff *skb;
1258 if (!(features->page1[0] & 0x3f)) {
1259 bt_dev_info(hdev, "Telemetry exception format not supported");
1263 skb = __hci_cmd_sync(hdev, 0xfc8b, 11, mask, HCI_INIT_TIMEOUT);
1265 bt_dev_err(hdev, "Setting Intel telemetry ddc write event mask failed (%ld)",
1267 return PTR_ERR(skb);
1273 EXPORT_SYMBOL_GPL(btintel_set_debug_features);
1276 MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
1277 MODULE_VERSION(VERSION);
1278 MODULE_LICENSE("GPL");
1279 MODULE_FIRMWARE("intel/ibt-11-5.sfi");
1280 MODULE_FIRMWARE("intel/ibt-11-5.ddc");
1281 MODULE_FIRMWARE("intel/ibt-12-16.sfi");
1282 MODULE_FIRMWARE("intel/ibt-12-16.ddc");