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 <acpi/acpi_bus.h>
14 #include <linux/unaligned.h>
15 #include <linux/efi.h>
17 #include <net/bluetooth/bluetooth.h>
18 #include <net/bluetooth/hci_core.h>
24 #define BDADDR_INTEL (&(bdaddr_t){{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
25 #define RSA_HEADER_LEN 644
26 #define CSS_HEADER_OFFSET 8
27 #define ECDSA_OFFSET 644
28 #define ECDSA_HEADER_LEN 320
30 #define BTINTEL_EFI_DSBR L"UefiCnvCommonDSBR"
33 DSM_SET_WDISABLE2_DELAY
= 1,
34 DSM_SET_RESET_METHOD
= 3,
37 #define CMD_WRITE_BOOT_PARAMS 0xfc0e
38 struct cmd_write_boot_params
{
46 const char *driver_name
;
51 static const guid_t btintel_guid_dsm
=
52 GUID_INIT(0xaa10f4e0, 0x81ac, 0x4233,
53 0xab, 0xf6, 0x3b, 0x2a, 0xc5, 0x0e, 0x28, 0xd9);
55 int btintel_check_bdaddr(struct hci_dev
*hdev
)
57 struct hci_rp_read_bd_addr
*bda
;
60 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_BD_ADDR
, 0, NULL
,
63 int err
= PTR_ERR(skb
);
64 bt_dev_err(hdev
, "Reading Intel device address failed (%d)",
69 if (skb
->len
!= sizeof(*bda
)) {
70 bt_dev_err(hdev
, "Intel device address length mismatch");
75 bda
= (struct hci_rp_read_bd_addr
*)skb
->data
;
77 /* For some Intel based controllers, the default Bluetooth device
78 * address 00:03:19:9E:8B:00 can be found. These controllers are
79 * fully operational, but have the danger of duplicate addresses
80 * and that in turn can cause problems with Bluetooth operation.
82 if (!bacmp(&bda
->bdaddr
, BDADDR_INTEL
)) {
83 bt_dev_err(hdev
, "Found Intel default device address (%pMR)",
85 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
92 EXPORT_SYMBOL_GPL(btintel_check_bdaddr
);
94 int btintel_enter_mfg(struct hci_dev
*hdev
)
96 static const u8 param
[] = { 0x01, 0x00 };
99 skb
= __hci_cmd_sync(hdev
, 0xfc11, 2, param
, HCI_CMD_TIMEOUT
);
101 bt_dev_err(hdev
, "Entering manufacturer mode failed (%ld)",
109 EXPORT_SYMBOL_GPL(btintel_enter_mfg
);
111 int btintel_exit_mfg(struct hci_dev
*hdev
, bool reset
, bool patched
)
113 u8 param
[] = { 0x00, 0x00 };
116 /* The 2nd command parameter specifies the manufacturing exit method:
117 * 0x00: Just disable the manufacturing mode (0x00).
118 * 0x01: Disable manufacturing mode and reset with patches deactivated.
119 * 0x02: Disable manufacturing mode and reset with patches activated.
122 param
[1] |= patched
? 0x02 : 0x01;
124 skb
= __hci_cmd_sync(hdev
, 0xfc11, 2, param
, HCI_CMD_TIMEOUT
);
126 bt_dev_err(hdev
, "Exiting manufacturer mode failed (%ld)",
134 EXPORT_SYMBOL_GPL(btintel_exit_mfg
);
136 int btintel_set_bdaddr(struct hci_dev
*hdev
, const bdaddr_t
*bdaddr
)
141 skb
= __hci_cmd_sync(hdev
, 0xfc31, 6, bdaddr
, HCI_INIT_TIMEOUT
);
144 bt_dev_err(hdev
, "Changing Intel device address failed (%d)",
152 EXPORT_SYMBOL_GPL(btintel_set_bdaddr
);
154 static int btintel_set_event_mask(struct hci_dev
*hdev
, bool debug
)
156 u8 mask
[8] = { 0x87, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
163 skb
= __hci_cmd_sync(hdev
, 0xfc52, 8, mask
, HCI_INIT_TIMEOUT
);
166 bt_dev_err(hdev
, "Setting Intel event mask failed (%d)", err
);
174 int btintel_set_diag(struct hci_dev
*hdev
, bool enable
)
190 skb
= __hci_cmd_sync(hdev
, 0xfc43, 3, param
, HCI_INIT_TIMEOUT
);
195 bt_dev_err(hdev
, "Changing Intel diagnostic mode failed (%d)",
202 btintel_set_event_mask(hdev
, enable
);
205 EXPORT_SYMBOL_GPL(btintel_set_diag
);
207 static int btintel_set_diag_mfg(struct hci_dev
*hdev
, bool enable
)
211 err
= btintel_enter_mfg(hdev
);
215 ret
= btintel_set_diag(hdev
, enable
);
217 err
= btintel_exit_mfg(hdev
, false, false);
224 static int btintel_set_diag_combined(struct hci_dev
*hdev
, bool enable
)
228 /* Legacy ROM device needs to be in the manufacturer mode to apply
231 * This flag is set after reading the Intel version.
233 if (btintel_test_flag(hdev
, INTEL_ROM_LEGACY
))
234 ret
= btintel_set_diag_mfg(hdev
, enable
);
236 ret
= btintel_set_diag(hdev
, enable
);
241 void btintel_hw_error(struct hci_dev
*hdev
, u8 code
)
246 bt_dev_err(hdev
, "Hardware error 0x%2.2x", code
);
248 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
250 bt_dev_err(hdev
, "Reset after hardware error failed (%ld)",
256 skb
= __hci_cmd_sync(hdev
, 0xfc22, 1, &type
, HCI_INIT_TIMEOUT
);
258 bt_dev_err(hdev
, "Retrieving Intel exception info failed (%ld)",
263 if (skb
->len
!= 13) {
264 bt_dev_err(hdev
, "Exception info size mismatch");
269 bt_dev_err(hdev
, "Exception info %s", (char *)(skb
->data
+ 1));
273 EXPORT_SYMBOL_GPL(btintel_hw_error
);
275 int btintel_version_info(struct hci_dev
*hdev
, struct intel_version
*ver
)
279 /* The hardware platform number has a fixed value of 0x37 and
280 * for now only accept this single value.
282 if (ver
->hw_platform
!= 0x37) {
283 bt_dev_err(hdev
, "Unsupported Intel hardware platform (%u)",
288 /* Check for supported iBT hardware variants of this firmware
291 * This check has been put in place to ensure correct forward
292 * compatibility options when newer hardware variants come along.
294 switch (ver
->hw_variant
) {
295 case 0x07: /* WP - Legacy ROM */
296 case 0x08: /* StP - Legacy ROM */
305 bt_dev_err(hdev
, "Unsupported Intel hardware variant (%u)",
310 switch (ver
->fw_variant
) {
312 variant
= "Legacy ROM 2.5";
315 variant
= "Bootloader";
318 variant
= "Legacy ROM 2.x";
321 variant
= "Firmware";
324 bt_dev_err(hdev
, "Unsupported firmware variant(%02x)", ver
->fw_variant
);
328 coredump_info
.hw_variant
= ver
->hw_variant
;
329 coredump_info
.fw_build_num
= ver
->fw_build_num
;
331 bt_dev_info(hdev
, "%s revision %u.%u build %u week %u %u",
332 variant
, ver
->fw_revision
>> 4, ver
->fw_revision
& 0x0f,
333 ver
->fw_build_num
, ver
->fw_build_ww
,
334 2000 + ver
->fw_build_yy
);
338 EXPORT_SYMBOL_GPL(btintel_version_info
);
340 static int btintel_secure_send(struct hci_dev
*hdev
, u8 fragment_type
, u32 plen
,
345 u8 cmd_param
[253], fragment_len
= (plen
> 252) ? 252 : plen
;
347 cmd_param
[0] = fragment_type
;
348 memcpy(cmd_param
+ 1, param
, fragment_len
);
350 skb
= __hci_cmd_sync(hdev
, 0xfc09, fragment_len
+ 1,
351 cmd_param
, HCI_INIT_TIMEOUT
);
357 plen
-= fragment_len
;
358 param
+= fragment_len
;
364 int btintel_load_ddc_config(struct hci_dev
*hdev
, const char *ddc_name
)
366 const struct firmware
*fw
;
371 err
= request_firmware_direct(&fw
, ddc_name
, &hdev
->dev
);
373 bt_dev_err(hdev
, "Failed to load Intel DDC file %s (%d)",
378 bt_dev_info(hdev
, "Found Intel DDC parameters: %s", ddc_name
);
382 /* DDC file contains one or more DDC structure which has
383 * Length (1 byte), DDC ID (2 bytes), and DDC value (Length - 2).
385 while (fw
->size
> fw_ptr
- fw
->data
) {
386 u8 cmd_plen
= fw_ptr
[0] + sizeof(u8
);
388 skb
= __hci_cmd_sync(hdev
, 0xfc8b, cmd_plen
, fw_ptr
,
391 bt_dev_err(hdev
, "Failed to send Intel_Write_DDC (%ld)",
393 release_firmware(fw
);
401 release_firmware(fw
);
403 bt_dev_info(hdev
, "Applying Intel DDC parameters completed");
407 EXPORT_SYMBOL_GPL(btintel_load_ddc_config
);
409 int btintel_set_event_mask_mfg(struct hci_dev
*hdev
, bool debug
)
413 err
= btintel_enter_mfg(hdev
);
417 ret
= btintel_set_event_mask(hdev
, debug
);
419 err
= btintel_exit_mfg(hdev
, false, false);
425 EXPORT_SYMBOL_GPL(btintel_set_event_mask_mfg
);
427 int btintel_read_version(struct hci_dev
*hdev
, struct intel_version
*ver
)
431 skb
= __hci_cmd_sync(hdev
, 0xfc05, 0, NULL
, HCI_CMD_TIMEOUT
);
433 bt_dev_err(hdev
, "Reading Intel version information failed (%ld)",
438 if (!skb
|| skb
->len
!= sizeof(*ver
)) {
439 bt_dev_err(hdev
, "Intel version event size mismatch");
444 memcpy(ver
, skb
->data
, sizeof(*ver
));
450 EXPORT_SYMBOL_GPL(btintel_read_version
);
452 int btintel_version_info_tlv(struct hci_dev
*hdev
,
453 struct intel_version_tlv
*version
)
457 /* The hardware platform number has a fixed value of 0x37 and
458 * for now only accept this single value.
460 if (INTEL_HW_PLATFORM(version
->cnvi_bt
) != 0x37) {
461 bt_dev_err(hdev
, "Unsupported Intel hardware platform (0x%2x)",
462 INTEL_HW_PLATFORM(version
->cnvi_bt
));
466 /* Check for supported iBT hardware variants of this firmware
469 * This check has been put in place to ensure correct forward
470 * compatibility options when newer hardware variants come along.
472 switch (INTEL_HW_VARIANT(version
->cnvi_bt
)) {
475 case 0x19: /* Slr-F */
477 case 0x1c: /* Gale Peak (GaP) */
478 case 0x1d: /* BlazarU (BzrU) */
479 case 0x1e: /* BlazarI (Bzr) */
482 bt_dev_err(hdev
, "Unsupported Intel hardware variant (0x%x)",
483 INTEL_HW_VARIANT(version
->cnvi_bt
));
487 switch (version
->img_type
) {
488 case BTINTEL_IMG_BOOTLOADER
:
489 variant
= "Bootloader";
490 /* It is required that every single firmware fragment is acknowledged
491 * with a command complete event. If the boot parameters indicate
492 * that this bootloader does not send them, then abort the setup.
494 if (version
->limited_cce
!= 0x00) {
495 bt_dev_err(hdev
, "Unsupported Intel firmware loading method (0x%x)",
496 version
->limited_cce
);
500 /* Secure boot engine type should be either 1 (ECDSA) or 0 (RSA) */
501 if (version
->sbe_type
> 0x01) {
502 bt_dev_err(hdev
, "Unsupported Intel secure boot engine type (0x%x)",
507 bt_dev_info(hdev
, "Device revision is %u", version
->dev_rev_id
);
508 bt_dev_info(hdev
, "Secure boot is %s",
509 version
->secure_boot
? "enabled" : "disabled");
510 bt_dev_info(hdev
, "OTP lock is %s",
511 version
->otp_lock
? "enabled" : "disabled");
512 bt_dev_info(hdev
, "API lock is %s",
513 version
->api_lock
? "enabled" : "disabled");
514 bt_dev_info(hdev
, "Debug lock is %s",
515 version
->debug_lock
? "enabled" : "disabled");
516 bt_dev_info(hdev
, "Minimum firmware build %u week %u %u",
517 version
->min_fw_build_nn
, version
->min_fw_build_cw
,
518 2000 + version
->min_fw_build_yy
);
520 case BTINTEL_IMG_IML
:
521 variant
= "Intermediate loader";
524 variant
= "Firmware";
527 bt_dev_err(hdev
, "Unsupported image type(%02x)", version
->img_type
);
531 coredump_info
.hw_variant
= INTEL_HW_VARIANT(version
->cnvi_bt
);
532 coredump_info
.fw_build_num
= version
->build_num
;
534 bt_dev_info(hdev
, "%s timestamp %u.%u buildtype %u build %u", variant
,
535 2000 + (version
->timestamp
>> 8), version
->timestamp
& 0xff,
536 version
->build_type
, version
->build_num
);
537 if (version
->img_type
== BTINTEL_IMG_OP
)
538 bt_dev_info(hdev
, "Firmware SHA1: 0x%8.8x", version
->git_sha1
);
542 EXPORT_SYMBOL_GPL(btintel_version_info_tlv
);
544 int btintel_parse_version_tlv(struct hci_dev
*hdev
,
545 struct intel_version_tlv
*version
,
548 /* Consume Command Complete Status field */
551 /* Event parameters contatin multiple TLVs. Read each of them
552 * and only keep the required data. Also, it use existing legacy
553 * version field like hw_platform, hw_variant, and fw_variant
554 * to keep the existing setup flow
557 struct intel_tlv
*tlv
;
559 /* Make sure skb has a minimum length of the header */
560 if (skb
->len
< sizeof(*tlv
))
563 tlv
= (struct intel_tlv
*)skb
->data
;
565 /* Make sure skb has a enough data */
566 if (skb
->len
< tlv
->len
+ sizeof(*tlv
))
570 case INTEL_TLV_CNVI_TOP
:
571 version
->cnvi_top
= get_unaligned_le32(tlv
->val
);
573 case INTEL_TLV_CNVR_TOP
:
574 version
->cnvr_top
= get_unaligned_le32(tlv
->val
);
576 case INTEL_TLV_CNVI_BT
:
577 version
->cnvi_bt
= get_unaligned_le32(tlv
->val
);
579 case INTEL_TLV_CNVR_BT
:
580 version
->cnvr_bt
= get_unaligned_le32(tlv
->val
);
582 case INTEL_TLV_DEV_REV_ID
:
583 version
->dev_rev_id
= get_unaligned_le16(tlv
->val
);
585 case INTEL_TLV_IMAGE_TYPE
:
586 version
->img_type
= tlv
->val
[0];
588 case INTEL_TLV_TIME_STAMP
:
589 /* If image type is Operational firmware (0x03), then
590 * running FW Calendar Week and Year information can
591 * be extracted from Timestamp information
593 version
->min_fw_build_cw
= tlv
->val
[0];
594 version
->min_fw_build_yy
= tlv
->val
[1];
595 version
->timestamp
= get_unaligned_le16(tlv
->val
);
597 case INTEL_TLV_BUILD_TYPE
:
598 version
->build_type
= tlv
->val
[0];
600 case INTEL_TLV_BUILD_NUM
:
601 /* If image type is Operational firmware (0x03), then
602 * running FW build number can be extracted from the
605 version
->min_fw_build_nn
= tlv
->val
[0];
606 version
->build_num
= get_unaligned_le32(tlv
->val
);
608 case INTEL_TLV_SECURE_BOOT
:
609 version
->secure_boot
= tlv
->val
[0];
611 case INTEL_TLV_OTP_LOCK
:
612 version
->otp_lock
= tlv
->val
[0];
614 case INTEL_TLV_API_LOCK
:
615 version
->api_lock
= tlv
->val
[0];
617 case INTEL_TLV_DEBUG_LOCK
:
618 version
->debug_lock
= tlv
->val
[0];
620 case INTEL_TLV_MIN_FW
:
621 version
->min_fw_build_nn
= tlv
->val
[0];
622 version
->min_fw_build_cw
= tlv
->val
[1];
623 version
->min_fw_build_yy
= tlv
->val
[2];
625 case INTEL_TLV_LIMITED_CCE
:
626 version
->limited_cce
= tlv
->val
[0];
628 case INTEL_TLV_SBE_TYPE
:
629 version
->sbe_type
= tlv
->val
[0];
631 case INTEL_TLV_OTP_BDADDR
:
632 memcpy(&version
->otp_bd_addr
, tlv
->val
,
635 case INTEL_TLV_GIT_SHA1
:
636 version
->git_sha1
= get_unaligned_le32(tlv
->val
);
638 case INTEL_TLV_FW_ID
:
639 snprintf(version
->fw_id
, sizeof(version
->fw_id
),
643 /* Ignore rest of information */
646 /* consume the current tlv and move to next*/
647 skb_pull(skb
, tlv
->len
+ sizeof(*tlv
));
652 EXPORT_SYMBOL_GPL(btintel_parse_version_tlv
);
654 static int btintel_read_version_tlv(struct hci_dev
*hdev
,
655 struct intel_version_tlv
*version
)
658 const u8 param
[1] = { 0xFF };
663 skb
= __hci_cmd_sync(hdev
, 0xfc05, 1, param
, HCI_CMD_TIMEOUT
);
665 bt_dev_err(hdev
, "Reading Intel version information failed (%ld)",
671 bt_dev_err(hdev
, "Intel Read Version command failed (%02x)",
677 btintel_parse_version_tlv(hdev
, version
, skb
);
683 /* ------- REGMAP IBT SUPPORT ------- */
685 #define IBT_REG_MODE_8BIT 0x00
686 #define IBT_REG_MODE_16BIT 0x01
687 #define IBT_REG_MODE_32BIT 0x02
689 struct regmap_ibt_context
{
690 struct hci_dev
*hdev
;
695 struct ibt_cp_reg_access
{
702 struct ibt_rp_reg_access
{
708 static int regmap_ibt_read(void *context
, const void *addr
, size_t reg_size
,
709 void *val
, size_t val_size
)
711 struct regmap_ibt_context
*ctx
= context
;
712 struct ibt_cp_reg_access cp
;
713 struct ibt_rp_reg_access
*rp
;
717 if (reg_size
!= sizeof(__le32
))
722 cp
.mode
= IBT_REG_MODE_8BIT
;
725 cp
.mode
= IBT_REG_MODE_16BIT
;
728 cp
.mode
= IBT_REG_MODE_32BIT
;
734 /* regmap provides a little-endian formatted addr */
735 cp
.addr
= *(__le32
*)addr
;
738 bt_dev_dbg(ctx
->hdev
, "Register (0x%x) read", le32_to_cpu(cp
.addr
));
740 skb
= hci_cmd_sync(ctx
->hdev
, ctx
->op_read
, sizeof(cp
), &cp
,
744 bt_dev_err(ctx
->hdev
, "regmap: Register (0x%x) read error (%d)",
745 le32_to_cpu(cp
.addr
), err
);
749 if (skb
->len
!= sizeof(*rp
) + val_size
) {
750 bt_dev_err(ctx
->hdev
, "regmap: Register (0x%x) read error, bad len",
751 le32_to_cpu(cp
.addr
));
756 rp
= (struct ibt_rp_reg_access
*)skb
->data
;
758 if (rp
->addr
!= cp
.addr
) {
759 bt_dev_err(ctx
->hdev
, "regmap: Register (0x%x) read error, bad addr",
760 le32_to_cpu(rp
->addr
));
765 memcpy(val
, rp
->data
, val_size
);
772 static int regmap_ibt_gather_write(void *context
,
773 const void *addr
, size_t reg_size
,
774 const void *val
, size_t val_size
)
776 struct regmap_ibt_context
*ctx
= context
;
777 struct ibt_cp_reg_access
*cp
;
779 int plen
= sizeof(*cp
) + val_size
;
783 if (reg_size
!= sizeof(__le32
))
788 mode
= IBT_REG_MODE_8BIT
;
791 mode
= IBT_REG_MODE_16BIT
;
794 mode
= IBT_REG_MODE_32BIT
;
800 cp
= kmalloc(plen
, GFP_KERNEL
);
804 /* regmap provides a little-endian formatted addr/value */
805 cp
->addr
= *(__le32
*)addr
;
808 memcpy(&cp
->data
, val
, val_size
);
810 bt_dev_dbg(ctx
->hdev
, "Register (0x%x) write", le32_to_cpu(cp
->addr
));
812 skb
= hci_cmd_sync(ctx
->hdev
, ctx
->op_write
, plen
, cp
, HCI_CMD_TIMEOUT
);
815 bt_dev_err(ctx
->hdev
, "regmap: Register (0x%x) write error (%d)",
816 le32_to_cpu(cp
->addr
), err
);
826 static int regmap_ibt_write(void *context
, const void *data
, size_t count
)
828 /* data contains register+value, since we only support 32bit addr,
829 * minimum data size is 4 bytes.
831 if (WARN_ONCE(count
< 4, "Invalid register access"))
834 return regmap_ibt_gather_write(context
, data
, 4, data
+ 4, count
- 4);
837 static void regmap_ibt_free_context(void *context
)
842 static const struct regmap_bus regmap_ibt
= {
843 .read
= regmap_ibt_read
,
844 .write
= regmap_ibt_write
,
845 .gather_write
= regmap_ibt_gather_write
,
846 .free_context
= regmap_ibt_free_context
,
847 .reg_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
848 .val_format_endian_default
= REGMAP_ENDIAN_LITTLE
,
851 /* Config is the same for all register regions */
852 static const struct regmap_config regmap_ibt_cfg
= {
853 .name
= "btintel_regmap",
858 struct regmap
*btintel_regmap_init(struct hci_dev
*hdev
, u16 opcode_read
,
861 struct regmap_ibt_context
*ctx
;
863 bt_dev_info(hdev
, "regmap: Init R%x-W%x region", opcode_read
,
866 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL
);
868 return ERR_PTR(-ENOMEM
);
870 ctx
->op_read
= opcode_read
;
871 ctx
->op_write
= opcode_write
;
874 return regmap_init(&hdev
->dev
, ®map_ibt
, ctx
, ®map_ibt_cfg
);
876 EXPORT_SYMBOL_GPL(btintel_regmap_init
);
878 int btintel_send_intel_reset(struct hci_dev
*hdev
, u32 boot_param
)
880 struct intel_reset params
= { 0x00, 0x01, 0x00, 0x01, 0x00000000 };
883 params
.boot_param
= cpu_to_le32(boot_param
);
885 skb
= __hci_cmd_sync(hdev
, 0xfc01, sizeof(params
), ¶ms
,
888 bt_dev_err(hdev
, "Failed to send Intel Reset command");
896 EXPORT_SYMBOL_GPL(btintel_send_intel_reset
);
898 int btintel_read_boot_params(struct hci_dev
*hdev
,
899 struct intel_boot_params
*params
)
903 skb
= __hci_cmd_sync(hdev
, 0xfc0d, 0, NULL
, HCI_INIT_TIMEOUT
);
905 bt_dev_err(hdev
, "Reading Intel boot parameters failed (%ld)",
910 if (skb
->len
!= sizeof(*params
)) {
911 bt_dev_err(hdev
, "Intel boot parameters size mismatch");
916 memcpy(params
, skb
->data
, sizeof(*params
));
920 if (params
->status
) {
921 bt_dev_err(hdev
, "Intel boot parameters command failed (%02x)",
923 return -bt_to_errno(params
->status
);
926 bt_dev_info(hdev
, "Device revision is %u",
927 le16_to_cpu(params
->dev_revid
));
929 bt_dev_info(hdev
, "Secure boot is %s",
930 params
->secure_boot
? "enabled" : "disabled");
932 bt_dev_info(hdev
, "OTP lock is %s",
933 params
->otp_lock
? "enabled" : "disabled");
935 bt_dev_info(hdev
, "API lock is %s",
936 params
->api_lock
? "enabled" : "disabled");
938 bt_dev_info(hdev
, "Debug lock is %s",
939 params
->debug_lock
? "enabled" : "disabled");
941 bt_dev_info(hdev
, "Minimum firmware build %u week %u %u",
942 params
->min_fw_build_nn
, params
->min_fw_build_cw
,
943 2000 + params
->min_fw_build_yy
);
947 EXPORT_SYMBOL_GPL(btintel_read_boot_params
);
949 static int btintel_sfi_rsa_header_secure_send(struct hci_dev
*hdev
,
950 const struct firmware
*fw
)
954 /* Start the firmware download transaction with the Init fragment
955 * represented by the 128 bytes of CSS header.
957 err
= btintel_secure_send(hdev
, 0x00, 128, fw
->data
);
959 bt_dev_err(hdev
, "Failed to send firmware header (%d)", err
);
963 /* Send the 256 bytes of public key information from the firmware
964 * as the PKey fragment.
966 err
= btintel_secure_send(hdev
, 0x03, 256, fw
->data
+ 128);
968 bt_dev_err(hdev
, "Failed to send firmware pkey (%d)", err
);
972 /* Send the 256 bytes of signature information from the firmware
973 * as the Sign fragment.
975 err
= btintel_secure_send(hdev
, 0x02, 256, fw
->data
+ 388);
977 bt_dev_err(hdev
, "Failed to send firmware signature (%d)", err
);
985 static int btintel_sfi_ecdsa_header_secure_send(struct hci_dev
*hdev
,
986 const struct firmware
*fw
)
990 /* Start the firmware download transaction with the Init fragment
991 * represented by the 128 bytes of CSS header.
993 err
= btintel_secure_send(hdev
, 0x00, 128, fw
->data
+ 644);
995 bt_dev_err(hdev
, "Failed to send firmware header (%d)", err
);
999 /* Send the 96 bytes of public key information from the firmware
1000 * as the PKey fragment.
1002 err
= btintel_secure_send(hdev
, 0x03, 96, fw
->data
+ 644 + 128);
1004 bt_dev_err(hdev
, "Failed to send firmware pkey (%d)", err
);
1008 /* Send the 96 bytes of signature information from the firmware
1009 * as the Sign fragment
1011 err
= btintel_secure_send(hdev
, 0x02, 96, fw
->data
+ 644 + 224);
1013 bt_dev_err(hdev
, "Failed to send firmware signature (%d)",
1020 static int btintel_download_firmware_payload(struct hci_dev
*hdev
,
1021 const struct firmware
*fw
,
1028 fw_ptr
= fw
->data
+ offset
;
1032 while (fw_ptr
- fw
->data
< fw
->size
) {
1033 struct hci_command_hdr
*cmd
= (void *)(fw_ptr
+ frag_len
);
1035 frag_len
+= sizeof(*cmd
) + cmd
->plen
;
1037 /* The parameter length of the secure send command requires
1038 * a 4 byte alignment. It happens so that the firmware file
1039 * contains proper Intel_NOP commands to align the fragments
1042 * Send set of commands with 4 byte alignment from the
1043 * firmware data buffer as a single Data fragment.
1045 if (!(frag_len
% 4)) {
1046 err
= btintel_secure_send(hdev
, 0x01, frag_len
, fw_ptr
);
1049 "Failed to send firmware data (%d)",
1063 static bool btintel_firmware_version(struct hci_dev
*hdev
,
1064 u8 num
, u8 ww
, u8 yy
,
1065 const struct firmware
*fw
,
1072 while (fw_ptr
- fw
->data
< fw
->size
) {
1073 struct hci_command_hdr
*cmd
= (void *)(fw_ptr
);
1075 /* Each SKU has a different reset parameter to use in the
1076 * HCI_Intel_Reset command and it is embedded in the firmware
1077 * data. So, instead of using static value per SKU, check
1078 * the firmware data and save it for later use.
1080 if (le16_to_cpu(cmd
->opcode
) == CMD_WRITE_BOOT_PARAMS
) {
1081 struct cmd_write_boot_params
*params
;
1083 params
= (void *)(fw_ptr
+ sizeof(*cmd
));
1085 *boot_addr
= le32_to_cpu(params
->boot_addr
);
1087 bt_dev_info(hdev
, "Boot Address: 0x%x", *boot_addr
);
1089 bt_dev_info(hdev
, "Firmware Version: %u-%u.%u",
1090 params
->fw_build_num
, params
->fw_build_ww
,
1091 params
->fw_build_yy
);
1093 return (num
== params
->fw_build_num
&&
1094 ww
== params
->fw_build_ww
&&
1095 yy
== params
->fw_build_yy
);
1098 fw_ptr
+= sizeof(*cmd
) + cmd
->plen
;
1104 int btintel_download_firmware(struct hci_dev
*hdev
,
1105 struct intel_version
*ver
,
1106 const struct firmware
*fw
,
1111 /* SfP and WsP don't seem to update the firmware version on file
1112 * so version checking is currently not possible.
1114 switch (ver
->hw_variant
) {
1115 case 0x0b: /* SfP */
1116 case 0x0c: /* WsP */
1117 /* Skip version checking */
1121 /* Skip download if firmware has the same version */
1122 if (btintel_firmware_version(hdev
, ver
->fw_build_num
,
1123 ver
->fw_build_ww
, ver
->fw_build_yy
,
1125 bt_dev_info(hdev
, "Firmware already loaded");
1126 /* Return -EALREADY to indicate that the firmware has
1127 * already been loaded.
1133 /* The firmware variant determines if the device is in bootloader
1134 * mode or is running operational firmware. The value 0x06 identifies
1135 * the bootloader and the value 0x23 identifies the operational
1138 * If the firmware version has changed that means it needs to be reset
1139 * to bootloader when operational so the new firmware can be loaded.
1141 if (ver
->fw_variant
== 0x23)
1144 err
= btintel_sfi_rsa_header_secure_send(hdev
, fw
);
1148 return btintel_download_firmware_payload(hdev
, fw
, RSA_HEADER_LEN
);
1150 EXPORT_SYMBOL_GPL(btintel_download_firmware
);
1152 static int btintel_download_fw_tlv(struct hci_dev
*hdev
,
1153 struct intel_version_tlv
*ver
,
1154 const struct firmware
*fw
, u32
*boot_param
,
1155 u8 hw_variant
, u8 sbe_type
)
1160 /* Skip download if firmware has the same version */
1161 if (btintel_firmware_version(hdev
, ver
->min_fw_build_nn
,
1162 ver
->min_fw_build_cw
,
1163 ver
->min_fw_build_yy
,
1165 bt_dev_info(hdev
, "Firmware already loaded");
1166 /* Return -EALREADY to indicate that firmware has
1167 * already been loaded.
1172 /* The firmware variant determines if the device is in bootloader
1173 * mode or is running operational firmware. The value 0x01 identifies
1174 * the bootloader and the value 0x03 identifies the operational
1177 * If the firmware version has changed that means it needs to be reset
1178 * to bootloader when operational so the new firmware can be loaded.
1180 if (ver
->img_type
== BTINTEL_IMG_OP
)
1183 /* iBT hardware variants 0x0b, 0x0c, 0x11, 0x12, 0x13, 0x14 support
1184 * only RSA secure boot engine. Hence, the corresponding sfi file will
1185 * have RSA header of 644 bytes followed by Command Buffer.
1187 * iBT hardware variants 0x17, 0x18 onwards support both RSA and ECDSA
1188 * secure boot engine. As a result, the corresponding sfi file will
1189 * have RSA header of 644, ECDSA header of 320 bytes followed by
1192 * CSS Header byte positions 0x08 to 0x0B represent the CSS Header
1193 * version: RSA(0x00010000) , ECDSA (0x00020000)
1195 css_header_ver
= get_unaligned_le32(fw
->data
+ CSS_HEADER_OFFSET
);
1196 if (css_header_ver
!= 0x00010000) {
1197 bt_dev_err(hdev
, "Invalid CSS Header version");
1201 if (hw_variant
<= 0x14) {
1202 if (sbe_type
!= 0x00) {
1203 bt_dev_err(hdev
, "Invalid SBE type for hardware variant (%d)",
1208 err
= btintel_sfi_rsa_header_secure_send(hdev
, fw
);
1212 err
= btintel_download_firmware_payload(hdev
, fw
, RSA_HEADER_LEN
);
1215 } else if (hw_variant
>= 0x17) {
1216 /* Check if CSS header for ECDSA follows the RSA header */
1217 if (fw
->data
[ECDSA_OFFSET
] != 0x06)
1220 /* Check if the CSS Header version is ECDSA(0x00020000) */
1221 css_header_ver
= get_unaligned_le32(fw
->data
+ ECDSA_OFFSET
+ CSS_HEADER_OFFSET
);
1222 if (css_header_ver
!= 0x00020000) {
1223 bt_dev_err(hdev
, "Invalid CSS Header version");
1227 if (sbe_type
== 0x00) {
1228 err
= btintel_sfi_rsa_header_secure_send(hdev
, fw
);
1232 err
= btintel_download_firmware_payload(hdev
, fw
,
1233 RSA_HEADER_LEN
+ ECDSA_HEADER_LEN
);
1236 } else if (sbe_type
== 0x01) {
1237 err
= btintel_sfi_ecdsa_header_secure_send(hdev
, fw
);
1241 err
= btintel_download_firmware_payload(hdev
, fw
,
1242 RSA_HEADER_LEN
+ ECDSA_HEADER_LEN
);
1250 static void btintel_reset_to_bootloader(struct hci_dev
*hdev
)
1252 struct intel_reset params
;
1253 struct sk_buff
*skb
;
1255 /* PCIe transport uses shared hardware reset mechanism for recovery
1256 * which gets triggered in pcie *setup* function on error.
1258 if (hdev
->bus
== HCI_PCI
)
1261 /* Send Intel Reset command. This will result in
1262 * re-enumeration of BT controller.
1264 * Intel Reset parameter description:
1265 * reset_type : 0x00 (Soft reset),
1267 * patch_enable : 0x00 (Do not enable),
1269 * ddc_reload : 0x00 (Do not reload),
1271 * boot_option: 0x00 (Current image),
1272 * 0x01 (Specified boot address)
1273 * boot_param: Boot address
1277 params
.reset_type
= 0x01;
1278 params
.patch_enable
= 0x01;
1279 params
.ddc_reload
= 0x01;
1280 params
.boot_option
= 0x00;
1281 params
.boot_param
= cpu_to_le32(0x00000000);
1283 skb
= __hci_cmd_sync(hdev
, 0xfc01, sizeof(params
),
1284 ¶ms
, HCI_INIT_TIMEOUT
);
1286 bt_dev_err(hdev
, "FW download error recovery failed (%ld)",
1290 bt_dev_info(hdev
, "Intel reset sent to retry FW download");
1293 /* Current Intel BT controllers(ThP/JfP) hold the USB reset
1294 * lines for 2ms when it receives Intel Reset in bootloader mode.
1295 * Whereas, the upcoming Intel BT controllers will hold USB reset
1296 * for 150ms. To keep the delay generic, 150ms is chosen here.
1301 static int btintel_read_debug_features(struct hci_dev
*hdev
,
1302 struct intel_debug_features
*features
)
1304 struct sk_buff
*skb
;
1307 /* Intel controller supports two pages, each page is of 128-bit
1308 * feature bit mask. And each bit defines specific feature support
1310 skb
= __hci_cmd_sync(hdev
, 0xfca6, sizeof(page_no
), &page_no
,
1313 bt_dev_err(hdev
, "Reading supported features failed (%ld)",
1315 return PTR_ERR(skb
);
1318 if (skb
->len
!= (sizeof(features
->page1
) + 3)) {
1319 bt_dev_err(hdev
, "Supported features event size mismatch");
1324 memcpy(features
->page1
, skb
->data
+ 3, sizeof(features
->page1
));
1326 /* Read the supported features page2 if required in future.
1332 static int btintel_set_debug_features(struct hci_dev
*hdev
,
1333 const struct intel_debug_features
*features
)
1335 u8 mask
[11] = { 0x0a, 0x92, 0x02, 0x7f, 0x00, 0x00, 0x00, 0x00,
1337 u8 period
[5] = { 0x04, 0x91, 0x02, 0x05, 0x00 };
1338 u8 trace_enable
= 0x02;
1339 struct sk_buff
*skb
;
1342 bt_dev_warn(hdev
, "Debug features not read");
1346 if (!(features
->page1
[0] & 0x3f)) {
1347 bt_dev_info(hdev
, "Telemetry exception format not supported");
1351 skb
= __hci_cmd_sync(hdev
, 0xfc8b, 11, mask
, HCI_INIT_TIMEOUT
);
1353 bt_dev_err(hdev
, "Setting Intel telemetry ddc write event mask failed (%ld)",
1355 return PTR_ERR(skb
);
1359 skb
= __hci_cmd_sync(hdev
, 0xfc8b, 5, period
, HCI_INIT_TIMEOUT
);
1361 bt_dev_err(hdev
, "Setting periodicity for link statistics traces failed (%ld)",
1363 return PTR_ERR(skb
);
1367 skb
= __hci_cmd_sync(hdev
, 0xfca1, 1, &trace_enable
, HCI_INIT_TIMEOUT
);
1369 bt_dev_err(hdev
, "Enable tracing of link statistics events failed (%ld)",
1371 return PTR_ERR(skb
);
1375 bt_dev_info(hdev
, "set debug features: trace_enable 0x%02x mask 0x%02x",
1376 trace_enable
, mask
[3]);
1381 static int btintel_reset_debug_features(struct hci_dev
*hdev
,
1382 const struct intel_debug_features
*features
)
1384 u8 mask
[11] = { 0x0a, 0x92, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1386 u8 trace_enable
= 0x00;
1387 struct sk_buff
*skb
;
1390 bt_dev_warn(hdev
, "Debug features not read");
1394 if (!(features
->page1
[0] & 0x3f)) {
1395 bt_dev_info(hdev
, "Telemetry exception format not supported");
1399 /* Should stop the trace before writing ddc event mask. */
1400 skb
= __hci_cmd_sync(hdev
, 0xfca1, 1, &trace_enable
, HCI_INIT_TIMEOUT
);
1402 bt_dev_err(hdev
, "Stop tracing of link statistics events failed (%ld)",
1404 return PTR_ERR(skb
);
1408 skb
= __hci_cmd_sync(hdev
, 0xfc8b, 11, mask
, HCI_INIT_TIMEOUT
);
1410 bt_dev_err(hdev
, "Setting Intel telemetry ddc write event mask failed (%ld)",
1412 return PTR_ERR(skb
);
1416 bt_dev_info(hdev
, "reset debug features: trace_enable 0x%02x mask 0x%02x",
1417 trace_enable
, mask
[3]);
1422 int btintel_set_quality_report(struct hci_dev
*hdev
, bool enable
)
1424 struct intel_debug_features features
;
1427 bt_dev_dbg(hdev
, "enable %d", enable
);
1429 /* Read the Intel supported features and if new exception formats
1430 * supported, need to load the additional DDC config to enable.
1432 err
= btintel_read_debug_features(hdev
, &features
);
1436 /* Set or reset the debug features. */
1438 err
= btintel_set_debug_features(hdev
, &features
);
1440 err
= btintel_reset_debug_features(hdev
, &features
);
1444 EXPORT_SYMBOL_GPL(btintel_set_quality_report
);
1446 static void btintel_coredump(struct hci_dev
*hdev
)
1448 struct sk_buff
*skb
;
1450 skb
= __hci_cmd_sync(hdev
, 0xfc4e, 0, NULL
, HCI_CMD_TIMEOUT
);
1452 bt_dev_err(hdev
, "Coredump failed (%ld)", PTR_ERR(skb
));
1459 static void btintel_dmp_hdr(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1463 snprintf(buf
, sizeof(buf
), "Controller Name: 0x%X\n",
1464 coredump_info
.hw_variant
);
1465 skb_put_data(skb
, buf
, strlen(buf
));
1467 snprintf(buf
, sizeof(buf
), "Firmware Version: 0x%X\n",
1468 coredump_info
.fw_build_num
);
1469 skb_put_data(skb
, buf
, strlen(buf
));
1471 snprintf(buf
, sizeof(buf
), "Driver: %s\n", coredump_info
.driver_name
);
1472 skb_put_data(skb
, buf
, strlen(buf
));
1474 snprintf(buf
, sizeof(buf
), "Vendor: Intel\n");
1475 skb_put_data(skb
, buf
, strlen(buf
));
1478 static int btintel_register_devcoredump_support(struct hci_dev
*hdev
)
1480 struct intel_debug_features features
;
1483 err
= btintel_read_debug_features(hdev
, &features
);
1485 bt_dev_info(hdev
, "Error reading debug features");
1489 if (!(features
.page1
[0] & 0x3f)) {
1490 bt_dev_dbg(hdev
, "Telemetry exception format not supported");
1494 hci_devcd_register(hdev
, btintel_coredump
, btintel_dmp_hdr
, NULL
);
1499 static const struct firmware
*btintel_legacy_rom_get_fw(struct hci_dev
*hdev
,
1500 struct intel_version
*ver
)
1502 const struct firmware
*fw
;
1506 snprintf(fwname
, sizeof(fwname
),
1507 "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq",
1508 ver
->hw_platform
, ver
->hw_variant
, ver
->hw_revision
,
1509 ver
->fw_variant
, ver
->fw_revision
, ver
->fw_build_num
,
1510 ver
->fw_build_ww
, ver
->fw_build_yy
);
1512 ret
= request_firmware(&fw
, fwname
, &hdev
->dev
);
1514 if (ret
== -EINVAL
) {
1515 bt_dev_err(hdev
, "Intel firmware file request failed (%d)",
1520 bt_dev_err(hdev
, "failed to open Intel firmware file: %s (%d)",
1523 /* If the correct firmware patch file is not found, use the
1524 * default firmware patch file instead
1526 snprintf(fwname
, sizeof(fwname
), "intel/ibt-hw-%x.%x.bseq",
1527 ver
->hw_platform
, ver
->hw_variant
);
1528 if (request_firmware(&fw
, fwname
, &hdev
->dev
) < 0) {
1529 bt_dev_err(hdev
, "failed to open default fw file: %s",
1535 bt_dev_info(hdev
, "Intel Bluetooth firmware file: %s", fwname
);
1540 static int btintel_legacy_rom_patching(struct hci_dev
*hdev
,
1541 const struct firmware
*fw
,
1542 const u8
**fw_ptr
, int *disable_patch
)
1544 struct sk_buff
*skb
;
1545 struct hci_command_hdr
*cmd
;
1546 const u8
*cmd_param
;
1547 struct hci_event_hdr
*evt
= NULL
;
1548 const u8
*evt_param
= NULL
;
1549 int remain
= fw
->size
- (*fw_ptr
- fw
->data
);
1551 /* The first byte indicates the types of the patch command or event.
1552 * 0x01 means HCI command and 0x02 is HCI event. If the first bytes
1553 * in the current firmware buffer doesn't start with 0x01 or
1554 * the size of remain buffer is smaller than HCI command header,
1555 * the firmware file is corrupted and it should stop the patching
1558 if (remain
> HCI_COMMAND_HDR_SIZE
&& *fw_ptr
[0] != 0x01) {
1559 bt_dev_err(hdev
, "Intel fw corrupted: invalid cmd read");
1565 cmd
= (struct hci_command_hdr
*)(*fw_ptr
);
1566 *fw_ptr
+= sizeof(*cmd
);
1567 remain
-= sizeof(*cmd
);
1569 /* Ensure that the remain firmware data is long enough than the length
1570 * of command parameter. If not, the firmware file is corrupted.
1572 if (remain
< cmd
->plen
) {
1573 bt_dev_err(hdev
, "Intel fw corrupted: invalid cmd len");
1577 /* If there is a command that loads a patch in the firmware
1578 * file, then enable the patch upon success, otherwise just
1579 * disable the manufacturer mode, for example patch activation
1580 * is not required when the default firmware patch file is used
1581 * because there are no patch data to load.
1583 if (*disable_patch
&& le16_to_cpu(cmd
->opcode
) == 0xfc8e)
1586 cmd_param
= *fw_ptr
;
1587 *fw_ptr
+= cmd
->plen
;
1588 remain
-= cmd
->plen
;
1590 /* This reads the expected events when the above command is sent to the
1591 * device. Some vendor commands expects more than one events, for
1592 * example command status event followed by vendor specific event.
1593 * For this case, it only keeps the last expected event. so the command
1594 * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of
1595 * last expected event.
1597 while (remain
> HCI_EVENT_HDR_SIZE
&& *fw_ptr
[0] == 0x02) {
1601 evt
= (struct hci_event_hdr
*)(*fw_ptr
);
1602 *fw_ptr
+= sizeof(*evt
);
1603 remain
-= sizeof(*evt
);
1605 if (remain
< evt
->plen
) {
1606 bt_dev_err(hdev
, "Intel fw corrupted: invalid evt len");
1610 evt_param
= *fw_ptr
;
1611 *fw_ptr
+= evt
->plen
;
1612 remain
-= evt
->plen
;
1615 /* Every HCI commands in the firmware file has its correspond event.
1616 * If event is not found or remain is smaller than zero, the firmware
1617 * file is corrupted.
1619 if (!evt
|| !evt_param
|| remain
< 0) {
1620 bt_dev_err(hdev
, "Intel fw corrupted: invalid evt read");
1624 skb
= __hci_cmd_sync_ev(hdev
, le16_to_cpu(cmd
->opcode
), cmd
->plen
,
1625 cmd_param
, evt
->evt
, HCI_INIT_TIMEOUT
);
1627 bt_dev_err(hdev
, "sending Intel patch command (0x%4.4x) failed (%ld)",
1628 cmd
->opcode
, PTR_ERR(skb
));
1629 return PTR_ERR(skb
);
1632 /* It ensures that the returned event matches the event data read from
1633 * the firmware file. At fist, it checks the length and then
1634 * the contents of the event.
1636 if (skb
->len
!= evt
->plen
) {
1637 bt_dev_err(hdev
, "mismatch event length (opcode 0x%4.4x)",
1638 le16_to_cpu(cmd
->opcode
));
1643 if (memcmp(skb
->data
, evt_param
, evt
->plen
)) {
1644 bt_dev_err(hdev
, "mismatch event parameter (opcode 0x%4.4x)",
1645 le16_to_cpu(cmd
->opcode
));
1654 static int btintel_legacy_rom_setup(struct hci_dev
*hdev
,
1655 struct intel_version
*ver
)
1657 const struct firmware
*fw
;
1659 int disable_patch
, err
;
1660 struct intel_version new_ver
;
1662 BT_DBG("%s", hdev
->name
);
1664 /* fw_patch_num indicates the version of patch the device currently
1665 * have. If there is no patch data in the device, it is always 0x00.
1666 * So, if it is other than 0x00, no need to patch the device again.
1668 if (ver
->fw_patch_num
) {
1670 "Intel device is already patched. patch num: %02x",
1675 /* Opens the firmware patch file based on the firmware version read
1676 * from the controller. If it fails to open the matching firmware
1677 * patch file, it tries to open the default firmware patch file.
1678 * If no patch file is found, allow the device to operate without
1681 fw
= btintel_legacy_rom_get_fw(hdev
, ver
);
1686 /* Enable the manufacturer mode of the controller.
1687 * Only while this mode is enabled, the driver can download the
1688 * firmware patch data and configuration parameters.
1690 err
= btintel_enter_mfg(hdev
);
1692 release_firmware(fw
);
1698 /* The firmware data file consists of list of Intel specific HCI
1699 * commands and its expected events. The first byte indicates the
1700 * type of the message, either HCI command or HCI event.
1702 * It reads the command and its expected event from the firmware file,
1703 * and send to the controller. Once __hci_cmd_sync_ev() returns,
1704 * the returned event is compared with the event read from the firmware
1705 * file and it will continue until all the messages are downloaded to
1708 * Once the firmware patching is completed successfully,
1709 * the manufacturer mode is disabled with reset and activating the
1712 * If the firmware patching fails, the manufacturer mode is
1713 * disabled with reset and deactivating the patch.
1715 * If the default patch file is used, no reset is done when disabling
1718 while (fw
->size
> fw_ptr
- fw
->data
) {
1721 ret
= btintel_legacy_rom_patching(hdev
, fw
, &fw_ptr
,
1724 goto exit_mfg_deactivate
;
1727 release_firmware(fw
);
1730 goto exit_mfg_disable
;
1732 /* Patching completed successfully and disable the manufacturer mode
1733 * with reset and activate the downloaded firmware patches.
1735 err
= btintel_exit_mfg(hdev
, true, true);
1739 /* Need build number for downloaded fw patches in
1740 * every power-on boot
1742 err
= btintel_read_version(hdev
, &new_ver
);
1746 bt_dev_info(hdev
, "Intel BT fw patch 0x%02x completed & activated",
1747 new_ver
.fw_patch_num
);
1752 /* Disable the manufacturer mode without reset */
1753 err
= btintel_exit_mfg(hdev
, false, false);
1757 bt_dev_info(hdev
, "Intel firmware patch completed");
1761 exit_mfg_deactivate
:
1762 release_firmware(fw
);
1764 /* Patching failed. Disable the manufacturer mode with reset and
1765 * deactivate the downloaded firmware patches.
1767 err
= btintel_exit_mfg(hdev
, true, false);
1771 bt_dev_info(hdev
, "Intel firmware patch completed and deactivated");
1774 /* Set the event mask for Intel specific vendor events. This enables
1775 * a few extra events that are useful during general operation.
1777 btintel_set_event_mask_mfg(hdev
, false);
1779 btintel_check_bdaddr(hdev
);
1784 static int btintel_download_wait(struct hci_dev
*hdev
, ktime_t calltime
, int msec
)
1786 ktime_t delta
, rettime
;
1787 unsigned long long duration
;
1790 btintel_set_flag(hdev
, INTEL_FIRMWARE_LOADED
);
1792 bt_dev_info(hdev
, "Waiting for firmware download to complete");
1794 err
= btintel_wait_on_flag_timeout(hdev
, INTEL_DOWNLOADING
,
1796 msecs_to_jiffies(msec
));
1797 if (err
== -EINTR
) {
1798 bt_dev_err(hdev
, "Firmware loading interrupted");
1803 bt_dev_err(hdev
, "Firmware loading timeout");
1807 if (btintel_test_flag(hdev
, INTEL_FIRMWARE_FAILED
)) {
1808 bt_dev_err(hdev
, "Firmware loading failed");
1812 rettime
= ktime_get();
1813 delta
= ktime_sub(rettime
, calltime
);
1814 duration
= (unsigned long long)ktime_to_ns(delta
) >> 10;
1816 bt_dev_info(hdev
, "Firmware loaded in %llu usecs", duration
);
1821 static int btintel_boot_wait(struct hci_dev
*hdev
, ktime_t calltime
, int msec
)
1823 ktime_t delta
, rettime
;
1824 unsigned long long duration
;
1827 bt_dev_info(hdev
, "Waiting for device to boot");
1829 err
= btintel_wait_on_flag_timeout(hdev
, INTEL_BOOTING
,
1831 msecs_to_jiffies(msec
));
1832 if (err
== -EINTR
) {
1833 bt_dev_err(hdev
, "Device boot interrupted");
1838 bt_dev_err(hdev
, "Device boot timeout");
1842 rettime
= ktime_get();
1843 delta
= ktime_sub(rettime
, calltime
);
1844 duration
= (unsigned long long) ktime_to_ns(delta
) >> 10;
1846 bt_dev_info(hdev
, "Device booted in %llu usecs", duration
);
1851 static int btintel_boot_wait_d0(struct hci_dev
*hdev
, ktime_t calltime
,
1854 ktime_t delta
, rettime
;
1855 unsigned long long duration
;
1858 bt_dev_info(hdev
, "Waiting for device transition to d0");
1860 err
= btintel_wait_on_flag_timeout(hdev
, INTEL_WAIT_FOR_D0
,
1862 msecs_to_jiffies(msec
));
1863 if (err
== -EINTR
) {
1864 bt_dev_err(hdev
, "Device d0 move interrupted");
1869 bt_dev_err(hdev
, "Device d0 move 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 moved to D0 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
);
1890 btintel_set_flag(hdev
, INTEL_WAIT_FOR_D0
);
1892 err
= btintel_send_intel_reset(hdev
, boot_addr
);
1894 bt_dev_err(hdev
, "Intel Soft Reset failed (%d)", err
);
1895 btintel_reset_to_bootloader(hdev
);
1899 /* The bootloader will not indicate when the device is ready. This
1900 * is done by the operational firmware sending bootup notification.
1902 * Booting into operational firmware should not take longer than
1903 * 5 second. However if that happens, then just fail the setup
1904 * since something went wrong.
1906 err
= btintel_boot_wait(hdev
, calltime
, 5000);
1907 if (err
== -ETIMEDOUT
) {
1908 btintel_reset_to_bootloader(hdev
);
1912 if (hdev
->bus
== HCI_PCI
) {
1913 /* In case of PCIe, after receiving bootup event, driver performs
1914 * D0 entry by writing 0 to sleep control register (check
1915 * btintel_pcie_recv_event())
1916 * Firmware acks with alive interrupt indicating host is full ready to
1917 * perform BT operation. Lets wait here till INTEL_WAIT_FOR_D0
1920 calltime
= ktime_get();
1921 err
= btintel_boot_wait_d0(hdev
, calltime
, 2000);
1928 static int btintel_get_fw_name(struct intel_version
*ver
,
1929 struct intel_boot_params
*params
,
1930 char *fw_name
, size_t len
,
1933 switch (ver
->hw_variant
) {
1934 case 0x0b: /* SfP */
1935 case 0x0c: /* WsP */
1936 snprintf(fw_name
, len
, "intel/ibt-%u-%u.%s",
1938 le16_to_cpu(params
->dev_revid
),
1941 case 0x11: /* JfP */
1942 case 0x12: /* ThP */
1943 case 0x13: /* HrP */
1944 case 0x14: /* CcP */
1945 snprintf(fw_name
, len
, "intel/ibt-%u-%u-%u.%s",
1958 static int btintel_download_fw(struct hci_dev
*hdev
,
1959 struct intel_version
*ver
,
1960 struct intel_boot_params
*params
,
1963 const struct firmware
*fw
;
1968 if (!ver
|| !params
)
1971 /* The firmware variant determines if the device is in bootloader
1972 * mode or is running operational firmware. The value 0x06 identifies
1973 * the bootloader and the value 0x23 identifies the operational
1976 * When the operational firmware is already present, then only
1977 * the check for valid Bluetooth device address is needed. This
1978 * determines if the device will be added as configured or
1979 * unconfigured controller.
1981 * It is not possible to use the Secure Boot Parameters in this
1982 * case since that command is only available in bootloader mode.
1984 if (ver
->fw_variant
== 0x23) {
1985 btintel_clear_flag(hdev
, INTEL_BOOTLOADER
);
1986 btintel_check_bdaddr(hdev
);
1988 /* SfP and WsP don't seem to update the firmware version on file
1989 * so version checking is currently possible.
1991 switch (ver
->hw_variant
) {
1992 case 0x0b: /* SfP */
1993 case 0x0c: /* WsP */
1997 /* Proceed to download to check if the version matches */
2001 /* Read the secure boot parameters to identify the operating
2002 * details of the bootloader.
2004 err
= btintel_read_boot_params(hdev
, params
);
2008 /* It is required that every single firmware fragment is acknowledged
2009 * with a command complete event. If the boot parameters indicate
2010 * that this bootloader does not send them, then abort the setup.
2012 if (params
->limited_cce
!= 0x00) {
2013 bt_dev_err(hdev
, "Unsupported Intel firmware loading method (%u)",
2014 params
->limited_cce
);
2018 /* If the OTP has no valid Bluetooth device address, then there will
2019 * also be no valid address for the operational firmware.
2021 if (!bacmp(¶ms
->otp_bdaddr
, BDADDR_ANY
)) {
2022 bt_dev_info(hdev
, "No device address configured");
2023 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
2027 /* With this Intel bootloader only the hardware variant and device
2028 * revision information are used to select the right firmware for SfP
2031 * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi.
2033 * Currently the supported hardware variants are:
2034 * 11 (0x0b) for iBT3.0 (LnP/SfP)
2035 * 12 (0x0c) for iBT3.5 (WsP)
2037 * For ThP/JfP and for future SKU's, the FW name varies based on HW
2038 * variant, HW revision and FW revision, as these are dependent on CNVi
2039 * and RF Combination.
2041 * 17 (0x11) for iBT3.5 (JfP)
2042 * 18 (0x12) for iBT3.5 (ThP)
2044 * The firmware file name for these will be
2045 * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
2048 err
= btintel_get_fw_name(ver
, params
, fwname
, sizeof(fwname
), "sfi");
2050 if (!btintel_test_flag(hdev
, INTEL_BOOTLOADER
)) {
2051 /* Firmware has already been loaded */
2052 btintel_set_flag(hdev
, INTEL_FIRMWARE_LOADED
);
2056 bt_dev_err(hdev
, "Unsupported Intel firmware naming");
2060 err
= firmware_request_nowarn(&fw
, fwname
, &hdev
->dev
);
2062 if (!btintel_test_flag(hdev
, INTEL_BOOTLOADER
)) {
2063 /* Firmware has already been loaded */
2064 btintel_set_flag(hdev
, INTEL_FIRMWARE_LOADED
);
2068 bt_dev_err(hdev
, "Failed to load Intel firmware file %s (%d)",
2073 bt_dev_info(hdev
, "Found device firmware: %s", fwname
);
2075 if (fw
->size
< 644) {
2076 bt_dev_err(hdev
, "Invalid size of firmware file (%zu)",
2082 calltime
= ktime_get();
2084 btintel_set_flag(hdev
, INTEL_DOWNLOADING
);
2086 /* Start firmware downloading and get boot parameter */
2087 err
= btintel_download_firmware(hdev
, ver
, fw
, boot_param
);
2089 if (err
== -EALREADY
) {
2090 /* Firmware has already been loaded */
2091 btintel_set_flag(hdev
, INTEL_FIRMWARE_LOADED
);
2096 /* When FW download fails, send Intel Reset to retry
2099 btintel_reset_to_bootloader(hdev
);
2103 /* Before switching the device into operational mode and with that
2104 * booting the loaded firmware, wait for the bootloader notification
2105 * that all fragments have been successfully received.
2107 * When the event processing receives the notification, then the
2108 * INTEL_DOWNLOADING flag will be cleared.
2110 * The firmware loading should not take longer than 5 seconds
2111 * and thus just timeout if that happens and fail the setup
2114 err
= btintel_download_wait(hdev
, calltime
, 5000);
2115 if (err
== -ETIMEDOUT
)
2116 btintel_reset_to_bootloader(hdev
);
2119 release_firmware(fw
);
2123 static int btintel_bootloader_setup(struct hci_dev
*hdev
,
2124 struct intel_version
*ver
)
2126 struct intel_version new_ver
;
2127 struct intel_boot_params params
;
2132 BT_DBG("%s", hdev
->name
);
2134 /* Set the default boot parameter to 0x0 and it is updated to
2135 * SKU specific boot parameter after reading Intel_Write_Boot_Params
2136 * command while downloading the firmware.
2138 boot_param
= 0x00000000;
2140 btintel_set_flag(hdev
, INTEL_BOOTLOADER
);
2142 err
= btintel_download_fw(hdev
, ver
, ¶ms
, &boot_param
);
2146 /* controller is already having an operational firmware */
2147 if (ver
->fw_variant
== 0x23)
2150 err
= btintel_boot(hdev
, boot_param
);
2154 btintel_clear_flag(hdev
, INTEL_BOOTLOADER
);
2156 err
= btintel_get_fw_name(ver
, ¶ms
, ddcname
,
2157 sizeof(ddcname
), "ddc");
2160 bt_dev_err(hdev
, "Unsupported Intel firmware naming");
2162 /* Once the device is running in operational mode, it needs to
2163 * apply the device configuration (DDC) parameters.
2165 * The device can work without DDC parameters, so even if it
2166 * fails to load the file, no need to fail the setup.
2168 btintel_load_ddc_config(hdev
, ddcname
);
2171 hci_dev_clear_flag(hdev
, HCI_QUALITY_REPORT
);
2173 /* Read the Intel version information after loading the FW */
2174 err
= btintel_read_version(hdev
, &new_ver
);
2178 btintel_version_info(hdev
, &new_ver
);
2181 /* Set the event mask for Intel specific vendor events. This enables
2182 * a few extra events that are useful during general operation. It
2183 * does not enable any debugging related events.
2185 * The device will function correctly without these events enabled
2186 * and thus no need to fail the setup.
2188 btintel_set_event_mask(hdev
, false);
2193 static void btintel_get_fw_name_tlv(const struct intel_version_tlv
*ver
,
2194 char *fw_name
, size_t len
,
2200 cnvi
= INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver
->cnvi_top
),
2201 INTEL_CNVX_TOP_STEP(ver
->cnvi_top
));
2203 cnvr
= INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver
->cnvr_top
),
2204 INTEL_CNVX_TOP_STEP(ver
->cnvr_top
));
2206 /* Only Blazar product supports downloading of intermediate loader
2209 if (INTEL_HW_VARIANT(ver
->cnvi_bt
) >= 0x1e) {
2210 u8 zero
[BTINTEL_FWID_MAXLEN
];
2212 if (ver
->img_type
== BTINTEL_IMG_BOOTLOADER
) {
2213 format
= "intel/ibt-%04x-%04x-iml.%s";
2214 snprintf(fw_name
, len
, format
, cnvi
, cnvr
, suffix
);
2218 memset(zero
, 0, sizeof(zero
));
2220 /* ibt-<cnvi_top type+cnvi_top step>-<cnvr_top type+cnvr_top step-fw_id> */
2221 if (memcmp(ver
->fw_id
, zero
, sizeof(zero
))) {
2222 format
= "intel/ibt-%04x-%04x-%s.%s";
2223 snprintf(fw_name
, len
, format
, cnvi
, cnvr
,
2224 ver
->fw_id
, suffix
);
2227 /* If firmware id is not present, fallback to legacy naming
2231 /* Fallback to legacy naming convention for other controllers
2232 * ibt-<cnvi_top type+cnvi_top step>-<cnvr_top type+cnvr_top step>
2234 format
= "intel/ibt-%04x-%04x.%s";
2235 snprintf(fw_name
, len
, format
, cnvi
, cnvr
, suffix
);
2238 static void btintel_get_iml_tlv(const struct intel_version_tlv
*ver
,
2239 char *fw_name
, size_t len
,
2245 cnvi
= INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver
->cnvi_top
),
2246 INTEL_CNVX_TOP_STEP(ver
->cnvi_top
));
2248 cnvr
= INTEL_CNVX_TOP_PACK_SWAB(INTEL_CNVX_TOP_TYPE(ver
->cnvr_top
),
2249 INTEL_CNVX_TOP_STEP(ver
->cnvr_top
));
2251 format
= "intel/ibt-%04x-%04x-iml.%s";
2252 snprintf(fw_name
, len
, format
, cnvi
, cnvr
, suffix
);
2255 static int btintel_prepare_fw_download_tlv(struct hci_dev
*hdev
,
2256 struct intel_version_tlv
*ver
,
2259 const struct firmware
*fw
;
2264 if (!ver
|| !boot_param
)
2267 /* The firmware variant determines if the device is in bootloader
2268 * mode or is running operational firmware. The value 0x03 identifies
2269 * the bootloader and the value 0x23 identifies the operational
2272 * When the operational firmware is already present, then only
2273 * the check for valid Bluetooth device address is needed. This
2274 * determines if the device will be added as configured or
2275 * unconfigured controller.
2277 * It is not possible to use the Secure Boot Parameters in this
2278 * case since that command is only available in bootloader mode.
2280 if (ver
->img_type
== BTINTEL_IMG_OP
) {
2281 btintel_clear_flag(hdev
, INTEL_BOOTLOADER
);
2282 btintel_check_bdaddr(hdev
);
2285 * Check for valid bd address in boot loader mode. Device
2286 * will be marked as unconfigured if empty bd address is
2289 if (!bacmp(&ver
->otp_bd_addr
, BDADDR_ANY
)) {
2290 bt_dev_info(hdev
, "No device address configured");
2291 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
2295 if (ver
->img_type
== BTINTEL_IMG_OP
) {
2296 /* Controller running OP image. In case of FW downgrade,
2297 * FWID TLV may not be present and driver may attempt to load
2298 * firmware image which doesn't exist. Lets compare the version
2301 if (INTEL_HW_VARIANT(ver
->cnvi_bt
) >= 0x1e)
2302 btintel_get_iml_tlv(ver
, fwname
, sizeof(fwname
), "sfi");
2304 btintel_get_fw_name_tlv(ver
, fwname
, sizeof(fwname
), "sfi");
2306 btintel_get_fw_name_tlv(ver
, fwname
, sizeof(fwname
), "sfi");
2309 err
= firmware_request_nowarn(&fw
, fwname
, &hdev
->dev
);
2311 if (!btintel_test_flag(hdev
, INTEL_BOOTLOADER
)) {
2312 /* Firmware has already been loaded */
2313 btintel_set_flag(hdev
, INTEL_FIRMWARE_LOADED
);
2317 bt_dev_err(hdev
, "Failed to load Intel firmware file %s (%d)",
2323 bt_dev_info(hdev
, "Found device firmware: %s", fwname
);
2325 if (fw
->size
< 644) {
2326 bt_dev_err(hdev
, "Invalid size of firmware file (%zu)",
2332 calltime
= ktime_get();
2334 btintel_set_flag(hdev
, INTEL_DOWNLOADING
);
2336 /* Start firmware downloading and get boot parameter */
2337 err
= btintel_download_fw_tlv(hdev
, ver
, fw
, boot_param
,
2338 INTEL_HW_VARIANT(ver
->cnvi_bt
),
2341 if (err
== -EALREADY
) {
2342 /* Firmware has already been loaded */
2343 btintel_set_flag(hdev
, INTEL_FIRMWARE_LOADED
);
2348 /* When FW download fails, send Intel Reset to retry
2351 btintel_reset_to_bootloader(hdev
);
2355 /* Before switching the device into operational mode and with that
2356 * booting the loaded firmware, wait for the bootloader notification
2357 * that all fragments have been successfully received.
2359 * When the event processing receives the notification, then the
2360 * BTUSB_DOWNLOADING flag will be cleared.
2362 * The firmware loading should not take longer than 5 seconds
2363 * and thus just timeout if that happens and fail the setup
2366 err
= btintel_download_wait(hdev
, calltime
, 5000);
2367 if (err
== -ETIMEDOUT
)
2368 btintel_reset_to_bootloader(hdev
);
2371 release_firmware(fw
);
2375 static int btintel_get_codec_config_data(struct hci_dev
*hdev
,
2376 __u8 link
, struct bt_codec
*codec
,
2377 __u8
*ven_len
, __u8
**ven_data
)
2381 if (!ven_data
|| !ven_len
)
2387 if (link
!= ESCO_LINK
) {
2388 bt_dev_err(hdev
, "Invalid link type(%u)", link
);
2392 *ven_data
= kmalloc(sizeof(__u8
), GFP_KERNEL
);
2398 /* supports only CVSD and mSBC offload codecs */
2399 switch (codec
->id
) {
2408 bt_dev_err(hdev
, "Invalid codec id(%u)", codec
->id
);
2411 /* codec and its capabilities are pre-defined to ids
2412 * preset id = 0x00 represents CVSD codec with sampling rate 8K
2413 * preset id = 0x01 represents mSBC codec with sampling rate 16K
2415 *ven_len
= sizeof(__u8
);
2424 static int btintel_get_data_path_id(struct hci_dev
*hdev
, __u8
*data_path_id
)
2426 /* Intel uses 1 as data path id for all the usecases */
2431 static int btintel_configure_offload(struct hci_dev
*hdev
)
2433 struct sk_buff
*skb
;
2435 struct intel_offload_use_cases
*use_cases
;
2437 skb
= __hci_cmd_sync(hdev
, 0xfc86, 0, NULL
, HCI_INIT_TIMEOUT
);
2439 bt_dev_err(hdev
, "Reading offload use cases failed (%ld)",
2441 return PTR_ERR(skb
);
2444 if (skb
->len
< sizeof(*use_cases
)) {
2449 use_cases
= (void *)skb
->data
;
2451 if (use_cases
->status
) {
2452 err
= -bt_to_errno(skb
->data
[0]);
2456 if (use_cases
->preset
[0] & 0x03) {
2457 hdev
->get_data_path_id
= btintel_get_data_path_id
;
2458 hdev
->get_codec_config_data
= btintel_get_codec_config_data
;
2465 static void btintel_set_ppag(struct hci_dev
*hdev
, struct intel_version_tlv
*ver
)
2467 struct sk_buff
*skb
;
2468 struct hci_ppag_enable_cmd ppag_cmd
;
2470 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
2471 union acpi_object
*p
, *elements
;
2475 /* PPAG is not supported if CRF is HrP2, Jfp2, JfP1 */
2476 switch (ver
->cnvr_top
& 0xFFF) {
2477 case 0x504: /* Hrp2 */
2478 case 0x202: /* Jfp2 */
2479 case 0x201: /* Jfp1 */
2480 bt_dev_dbg(hdev
, "PPAG not supported for Intel CNVr (0x%3x)",
2481 ver
->cnvr_top
& 0xFFF);
2485 handle
= ACPI_HANDLE(GET_HCIDEV_DEV(hdev
));
2487 bt_dev_info(hdev
, "No support for BT device in ACPI firmware");
2491 status
= acpi_evaluate_object(handle
, "PPAG", NULL
, &buffer
);
2492 if (ACPI_FAILURE(status
)) {
2493 if (status
== AE_NOT_FOUND
) {
2494 bt_dev_dbg(hdev
, "PPAG-BT: ACPI entry not found");
2497 bt_dev_warn(hdev
, "PPAG-BT: ACPI Failure: %s", acpi_format_exception(status
));
2502 if (p
->type
!= ACPI_TYPE_PACKAGE
|| p
->package
.count
!= 2) {
2503 bt_dev_warn(hdev
, "PPAG-BT: Invalid object type: %d or package count: %d",
2504 p
->type
, p
->package
.count
);
2505 kfree(buffer
.pointer
);
2509 elements
= p
->package
.elements
;
2511 /* PPAG table is located at element[1] */
2514 domain
= (u32
)p
->package
.elements
[0].integer
.value
;
2515 mode
= (u32
)p
->package
.elements
[1].integer
.value
;
2516 kfree(buffer
.pointer
);
2518 if (domain
!= 0x12) {
2519 bt_dev_dbg(hdev
, "PPAG-BT: Bluetooth domain is disabled in ACPI firmware");
2524 * BIT 0 : 0 Disabled in EU
2526 * BIT 1 : 0 Disabled in China
2527 * 1 Enabled in China
2532 bt_dev_dbg(hdev
, "PPAG-BT: EU, China mode are disabled in BIOS");
2536 ppag_cmd
.ppag_enable_flags
= cpu_to_le32(mode
);
2538 skb
= __hci_cmd_sync(hdev
, INTEL_OP_PPAG_CMD
, sizeof(ppag_cmd
),
2539 &ppag_cmd
, HCI_CMD_TIMEOUT
);
2541 bt_dev_warn(hdev
, "Failed to send PPAG Enable (%ld)", PTR_ERR(skb
));
2544 bt_dev_info(hdev
, "PPAG-BT: Enabled (Mode %d)", mode
);
2548 static int btintel_acpi_reset_method(struct hci_dev
*hdev
)
2552 union acpi_object
*p
, *ref
;
2553 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
2555 status
= acpi_evaluate_object(ACPI_HANDLE(GET_HCIDEV_DEV(hdev
)), "_PRR", NULL
, &buffer
);
2556 if (ACPI_FAILURE(status
)) {
2557 bt_dev_err(hdev
, "Failed to run _PRR method");
2563 if (p
->package
.count
!= 1 || p
->type
!= ACPI_TYPE_PACKAGE
) {
2564 bt_dev_err(hdev
, "Invalid arguments");
2569 ref
= &p
->package
.elements
[0];
2570 if (ref
->type
!= ACPI_TYPE_LOCAL_REFERENCE
) {
2571 bt_dev_err(hdev
, "Invalid object type: 0x%x", ref
->type
);
2576 status
= acpi_evaluate_object(ref
->reference
.handle
, "_RST", NULL
, NULL
);
2577 if (ACPI_FAILURE(status
)) {
2578 bt_dev_err(hdev
, "Failed to run_RST method");
2584 kfree(buffer
.pointer
);
2588 static void btintel_set_dsm_reset_method(struct hci_dev
*hdev
,
2589 struct intel_version_tlv
*ver_tlv
)
2591 struct btintel_data
*data
= hci_get_priv(hdev
);
2592 acpi_handle handle
= ACPI_HANDLE(GET_HCIDEV_DEV(hdev
));
2593 u8 reset_payload
[4] = {0x01, 0x00, 0x01, 0x00};
2594 union acpi_object
*obj
, argv4
;
2596 RESET_TYPE_WDISABLE2
,
2600 handle
= ACPI_HANDLE(GET_HCIDEV_DEV(hdev
));
2603 bt_dev_dbg(hdev
, "No support for bluetooth device in ACPI firmware");
2607 if (!acpi_has_method(handle
, "_PRR")) {
2608 bt_dev_err(hdev
, "No support for _PRR ACPI method");
2612 switch (ver_tlv
->cnvi_top
& 0xfff) {
2613 case 0x910: /* GalePeak2 */
2614 reset_payload
[2] = RESET_TYPE_VSEC
;
2617 /* WDISABLE2 is the default reset method */
2618 reset_payload
[2] = RESET_TYPE_WDISABLE2
;
2620 if (!acpi_check_dsm(handle
, &btintel_guid_dsm
, 0,
2621 BIT(DSM_SET_WDISABLE2_DELAY
))) {
2622 bt_dev_err(hdev
, "No dsm support to set reset delay");
2625 argv4
.integer
.type
= ACPI_TYPE_INTEGER
;
2626 /* delay required to toggle BT power */
2627 argv4
.integer
.value
= 160;
2628 obj
= acpi_evaluate_dsm(handle
, &btintel_guid_dsm
, 0,
2629 DSM_SET_WDISABLE2_DELAY
, &argv4
);
2631 bt_dev_err(hdev
, "Failed to call dsm to set reset delay");
2637 bt_dev_info(hdev
, "DSM reset method type: 0x%02x", reset_payload
[2]);
2639 if (!acpi_check_dsm(handle
, &btintel_guid_dsm
, 0,
2640 DSM_SET_RESET_METHOD
)) {
2641 bt_dev_warn(hdev
, "No support for dsm to set reset method");
2644 argv4
.buffer
.type
= ACPI_TYPE_BUFFER
;
2645 argv4
.buffer
.length
= sizeof(reset_payload
);
2646 argv4
.buffer
.pointer
= reset_payload
;
2648 obj
= acpi_evaluate_dsm(handle
, &btintel_guid_dsm
, 0,
2649 DSM_SET_RESET_METHOD
, &argv4
);
2651 bt_dev_err(hdev
, "Failed to call dsm to set reset method");
2655 data
->acpi_reset_method
= btintel_acpi_reset_method
;
2658 #define BTINTEL_ISODATA_HANDLE_BASE 0x900
2660 static u8
btintel_classify_pkt_type(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2663 * Distinguish ISO data packets form ACL data packets
2664 * based on their connection handle value range.
2666 if (hci_skb_pkt_type(skb
) == HCI_ACLDATA_PKT
) {
2667 __u16 handle
= __le16_to_cpu(hci_acl_hdr(skb
)->handle
);
2669 if (hci_handle(handle
) >= BTINTEL_ISODATA_HANDLE_BASE
)
2670 return HCI_ISODATA_PKT
;
2673 return hci_skb_pkt_type(skb
);
2677 * UefiCnvCommonDSBR UEFI variable provides information from the OEM platforms
2678 * if they have replaced the BRI (Bluetooth Radio Interface) resistor to
2679 * overcome the potential STEP errors on their designs. Based on the
2680 * configauration, bluetooth firmware shall adjust the BRI response line drive
2681 * strength. The below structure represents DSBR data.
2687 * header - defines revision number of the structure
2688 * dsbr - defines drive strength BRI response
2690 * 0 - instructs bluetooth firmware to use default values
2691 * 1 - instructs bluetooth firmware to override default values
2695 * DSBR override values (only if bit0 is set. Default value is 0xF
2698 * Expected values for dsbr field:
2699 * 1. 0xF1 - indicates that the resistor on board is 33 Ohm
2700 * 2. 0x00 or 0xB1 - indicates that the resistor on board is 10 Ohm
2701 * 3. Non existing UEFI variable or invalid (none of the above) - indicates
2702 * that the resistor on board is 10 Ohm
2703 * Even if uefi variable is not present, driver shall send 0xfc0a command to
2704 * firmware to use default values.
2707 static int btintel_uefi_get_dsbr(u32
*dsbr_var
)
2709 struct btintel_dsbr
{
2714 efi_status_t status
;
2715 unsigned long data_size
= 0;
2716 efi_guid_t guid
= EFI_GUID(0xe65d8884, 0xd4af, 0x4b20, 0x8d, 0x03,
2717 0x77, 0x2e, 0xcc, 0x3d, 0xa5, 0x31);
2719 if (!IS_ENABLED(CONFIG_EFI
))
2722 if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE
))
2725 status
= efi
.get_variable(BTINTEL_EFI_DSBR
, &guid
, NULL
, &data_size
,
2728 if (status
!= EFI_BUFFER_TOO_SMALL
|| !data_size
)
2731 status
= efi
.get_variable(BTINTEL_EFI_DSBR
, &guid
, NULL
, &data_size
,
2734 if (status
!= EFI_SUCCESS
)
2737 *dsbr_var
= data
.dsbr
;
2741 static int btintel_set_dsbr(struct hci_dev
*hdev
, struct intel_version_tlv
*ver
)
2743 struct btintel_dsbr_cmd
{
2748 struct btintel_dsbr_cmd cmd
;
2749 struct sk_buff
*skb
;
2754 cnvi
= ver
->cnvi_top
& 0xfff;
2755 /* DSBR command needs to be sent for,
2756 * 1. BlazarI or BlazarIW + B0 step product in IML image.
2757 * 2. Gale Peak2 or BlazarU in OP image.
2761 case BTINTEL_CNVI_BLAZARI
:
2762 case BTINTEL_CNVI_BLAZARIW
:
2763 if (ver
->img_type
== BTINTEL_IMG_IML
&&
2764 INTEL_CNVX_TOP_STEP(ver
->cnvi_top
) == 0x01)
2767 case BTINTEL_CNVI_GAP
:
2768 case BTINTEL_CNVI_BLAZARU
:
2769 if (ver
->img_type
== BTINTEL_IMG_OP
&&
2770 hdev
->bus
== HCI_USB
)
2778 err
= btintel_uefi_get_dsbr(&dsbr
);
2780 bt_dev_dbg(hdev
, "Error reading efi: %ls (%d)",
2781 BTINTEL_EFI_DSBR
, err
);
2783 cmd
.enable
= dsbr
& BIT(0);
2784 cmd
.dsbr
= dsbr
>> 4 & 0xF;
2786 bt_dev_info(hdev
, "dsbr: enable: 0x%2.2x value: 0x%2.2x", cmd
.enable
,
2789 skb
= __hci_cmd_sync(hdev
, 0xfc0a, sizeof(cmd
), &cmd
, HCI_CMD_TIMEOUT
);
2791 return -bt_to_errno(PTR_ERR(skb
));
2793 status
= skb
->data
[0];
2797 return -bt_to_errno(status
);
2802 int btintel_bootloader_setup_tlv(struct hci_dev
*hdev
,
2803 struct intel_version_tlv
*ver
)
2808 struct intel_version_tlv new_ver
;
2810 bt_dev_dbg(hdev
, "");
2812 /* Set the default boot parameter to 0x0 and it is updated to
2813 * SKU specific boot parameter after reading Intel_Write_Boot_Params
2814 * command while downloading the firmware.
2816 boot_param
= 0x00000000;
2818 /* In case of PCIe, this function might get called multiple times with
2819 * same hdev instance if there is any error on firmware download.
2820 * Need to clear stale bits of previous firmware download attempt.
2822 for (int i
= 0; i
< __INTEL_NUM_FLAGS
; i
++)
2823 btintel_clear_flag(hdev
, i
);
2825 btintel_set_flag(hdev
, INTEL_BOOTLOADER
);
2827 err
= btintel_prepare_fw_download_tlv(hdev
, ver
, &boot_param
);
2831 /* check if controller is already having an operational firmware */
2832 if (ver
->img_type
== BTINTEL_IMG_OP
)
2835 err
= btintel_boot(hdev
, boot_param
);
2839 err
= btintel_read_version_tlv(hdev
, ver
);
2843 /* set drive strength of BRI response */
2844 err
= btintel_set_dsbr(hdev
, ver
);
2846 bt_dev_err(hdev
, "Failed to send dsbr command (%d)", err
);
2850 /* If image type returned is BTINTEL_IMG_IML, then controller supports
2851 * intermediate loader image
2853 if (ver
->img_type
== BTINTEL_IMG_IML
) {
2854 err
= btintel_prepare_fw_download_tlv(hdev
, ver
, &boot_param
);
2858 err
= btintel_boot(hdev
, boot_param
);
2863 btintel_clear_flag(hdev
, INTEL_BOOTLOADER
);
2865 btintel_get_fw_name_tlv(ver
, ddcname
, sizeof(ddcname
), "ddc");
2866 /* Once the device is running in operational mode, it needs to
2867 * apply the device configuration (DDC) parameters.
2869 * The device can work without DDC parameters, so even if it
2870 * fails to load the file, no need to fail the setup.
2872 btintel_load_ddc_config(hdev
, ddcname
);
2874 /* Read supported use cases and set callbacks to fetch datapath id */
2875 btintel_configure_offload(hdev
);
2877 hci_dev_clear_flag(hdev
, HCI_QUALITY_REPORT
);
2879 /* Set PPAG feature */
2880 btintel_set_ppag(hdev
, ver
);
2882 /* Read the Intel version information after loading the FW */
2883 err
= btintel_read_version_tlv(hdev
, &new_ver
);
2887 btintel_version_info_tlv(hdev
, &new_ver
);
2890 /* Set the event mask for Intel specific vendor events. This enables
2891 * a few extra events that are useful during general operation. It
2892 * does not enable any debugging related events.
2894 * The device will function correctly without these events enabled
2895 * and thus no need to fail the setup.
2897 btintel_set_event_mask(hdev
, false);
2901 EXPORT_SYMBOL_GPL(btintel_bootloader_setup_tlv
);
2903 void btintel_set_msft_opcode(struct hci_dev
*hdev
, u8 hw_variant
)
2905 switch (hw_variant
) {
2906 /* Legacy bootloader devices that supports MSFT Extension */
2907 case 0x11: /* JfP */
2908 case 0x12: /* ThP */
2909 case 0x13: /* HrP */
2910 case 0x14: /* CcP */
2911 /* All Intel new generation controllers support the Microsoft vendor
2912 * extension are using 0xFC1E for VsMsftOpCode.
2921 hci_set_msft_opcode(hdev
, 0xFC1E);
2928 EXPORT_SYMBOL_GPL(btintel_set_msft_opcode
);
2930 void btintel_print_fseq_info(struct hci_dev
*hdev
)
2932 struct sk_buff
*skb
;
2937 skb
= __hci_cmd_sync(hdev
, 0xfcb3, 0, NULL
, HCI_CMD_TIMEOUT
);
2939 bt_dev_dbg(hdev
, "Reading fseq status command failed (%ld)",
2944 if (skb
->len
< (sizeof(u32
) * 16 + 2)) {
2945 bt_dev_dbg(hdev
, "Malformed packet of length %u received",
2951 p
= skb_pull_data(skb
, 1);
2953 bt_dev_dbg(hdev
, "Failed to get fseq status (0x%2.2x)", *p
);
2958 p
= skb_pull_data(skb
, 1);
2964 str
= "Fatal error";
2967 str
= "Semaphore acquire error";
2970 str
= "Unknown error";
2975 bt_dev_err(hdev
, "Fseq status: %s (0x%2.2x)", str
, *p
);
2980 bt_dev_info(hdev
, "Fseq status: %s (0x%2.2x)", str
, *p
);
2982 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
2983 bt_dev_dbg(hdev
, "Reason: 0x%8.8x", val
);
2985 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
2986 bt_dev_dbg(hdev
, "Global version: 0x%8.8x", val
);
2988 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
2989 bt_dev_dbg(hdev
, "Installed version: 0x%8.8x", val
);
2992 skb_pull_data(skb
, 4);
2993 bt_dev_info(hdev
, "Fseq executed: %2.2u.%2.2u.%2.2u.%2.2u", p
[0], p
[1],
2997 skb_pull_data(skb
, 4);
2998 bt_dev_info(hdev
, "Fseq BT Top: %2.2u.%2.2u.%2.2u.%2.2u", p
[0], p
[1],
3001 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3002 bt_dev_dbg(hdev
, "Fseq Top init version: 0x%8.8x", val
);
3004 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3005 bt_dev_dbg(hdev
, "Fseq Cnvio init version: 0x%8.8x", val
);
3007 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3008 bt_dev_dbg(hdev
, "Fseq MBX Wifi file version: 0x%8.8x", val
);
3010 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3011 bt_dev_dbg(hdev
, "Fseq BT version: 0x%8.8x", val
);
3013 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3014 bt_dev_dbg(hdev
, "Fseq Top reset address: 0x%8.8x", val
);
3016 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3017 bt_dev_dbg(hdev
, "Fseq MBX timeout: 0x%8.8x", val
);
3019 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3020 bt_dev_dbg(hdev
, "Fseq MBX ack: 0x%8.8x", val
);
3022 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3023 bt_dev_dbg(hdev
, "Fseq CNVi id: 0x%8.8x", val
);
3025 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3026 bt_dev_dbg(hdev
, "Fseq CNVr id: 0x%8.8x", val
);
3028 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3029 bt_dev_dbg(hdev
, "Fseq Error handle: 0x%8.8x", val
);
3031 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3032 bt_dev_dbg(hdev
, "Fseq Magic noalive indication: 0x%8.8x", val
);
3034 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3035 bt_dev_dbg(hdev
, "Fseq OTP version: 0x%8.8x", val
);
3037 val
= get_unaligned_le32(skb_pull_data(skb
, 4));
3038 bt_dev_dbg(hdev
, "Fseq MBX otp version: 0x%8.8x", val
);
3042 EXPORT_SYMBOL_GPL(btintel_print_fseq_info
);
3044 static int btintel_setup_combined(struct hci_dev
*hdev
)
3046 const u8 param
[1] = { 0xFF };
3047 struct intel_version ver
;
3048 struct intel_version_tlv ver_tlv
;
3049 struct sk_buff
*skb
;
3052 BT_DBG("%s", hdev
->name
);
3054 /* The some controllers have a bug with the first HCI command sent to it
3055 * returning number of completed commands as zero. This would stall the
3056 * command processing in the Bluetooth core.
3058 * As a workaround, send HCI Reset command first which will reset the
3059 * number of completed commands and allow normal command processing
3062 * Regarding the INTEL_BROKEN_SHUTDOWN_LED flag, these devices maybe
3063 * in the SW_RFKILL ON state as a workaround of fixing LED issue during
3064 * the shutdown() procedure, and once the device is in SW_RFKILL ON
3065 * state, the only way to exit out of it is sending the HCI_Reset
3068 if (btintel_test_flag(hdev
, INTEL_BROKEN_INITIAL_NCMD
) ||
3069 btintel_test_flag(hdev
, INTEL_BROKEN_SHUTDOWN_LED
)) {
3070 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
,
3074 "sending initial HCI reset failed (%ld)",
3076 return PTR_ERR(skb
);
3081 /* Starting from TyP device, the command parameter and response are
3082 * changed even though the OCF for HCI_Intel_Read_Version command
3083 * remains same. The legacy devices can handle even if the
3084 * command has a parameter and returns a correct version information.
3085 * So, it uses new format to support both legacy and new format.
3087 skb
= __hci_cmd_sync(hdev
, 0xfc05, 1, param
, HCI_CMD_TIMEOUT
);
3089 bt_dev_err(hdev
, "Reading Intel version command failed (%ld)",
3091 return PTR_ERR(skb
);
3094 /* Check the status */
3096 bt_dev_err(hdev
, "Intel Read Version command failed (%02x)",
3102 /* Apply the common HCI quirks for Intel device */
3103 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
3104 set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY
, &hdev
->quirks
);
3105 set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG
, &hdev
->quirks
);
3107 /* Set up the quality report callback for Intel devices */
3108 hdev
->set_quality_report
= btintel_set_quality_report
;
3110 /* For Legacy device, check the HW platform value and size */
3111 if (skb
->len
== sizeof(ver
) && skb
->data
[1] == 0x37) {
3112 bt_dev_dbg(hdev
, "Read the legacy Intel version information");
3114 memcpy(&ver
, skb
->data
, sizeof(ver
));
3116 /* Display version information */
3117 btintel_version_info(hdev
, &ver
);
3119 /* Check for supported iBT hardware variants of this firmware
3122 * This check has been put in place to ensure correct forward
3123 * compatibility options when newer hardware variants come
3126 switch (ver
.hw_variant
) {
3128 case 0x08: /* StP */
3129 /* Legacy ROM product */
3130 btintel_set_flag(hdev
, INTEL_ROM_LEGACY
);
3132 /* Apply the device specific HCI quirks
3134 * WBS for SdP - For the Legacy ROM products, only SdP
3135 * supports the WBS. But the version information is not
3136 * enough to use here because the StP2 and SdP have same
3137 * hw_variant and fw_variant. So, this flag is set by
3138 * the transport driver (btusb) based on the HW info
3141 if (!btintel_test_flag(hdev
,
3142 INTEL_ROM_LEGACY_NO_WBS_SUPPORT
))
3143 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED
,
3146 err
= btintel_legacy_rom_setup(hdev
, &ver
);
3148 case 0x0b: /* SfP */
3149 case 0x11: /* JfP */
3150 case 0x12: /* ThP */
3151 case 0x13: /* HrP */
3152 case 0x14: /* CcP */
3154 case 0x0c: /* WsP */
3155 /* Apply the device specific HCI quirks
3157 * All Legacy bootloader devices support WBS
3159 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED
,
3162 /* These variants don't seem to support LE Coded PHY */
3163 set_bit(HCI_QUIRK_BROKEN_LE_CODED
, &hdev
->quirks
);
3165 /* Setup MSFT Extension support */
3166 btintel_set_msft_opcode(hdev
, ver
.hw_variant
);
3168 err
= btintel_bootloader_setup(hdev
, &ver
);
3169 btintel_register_devcoredump_support(hdev
);
3172 bt_dev_err(hdev
, "Unsupported Intel hw variant (%u)",
3177 hci_set_hw_info(hdev
,
3178 "INTEL platform=%u variant=%u revision=%u",
3179 ver
.hw_platform
, ver
.hw_variant
,
3185 /* memset ver_tlv to start with clean state as few fields are exclusive
3186 * to bootloader mode and are not populated in operational mode
3188 memset(&ver_tlv
, 0, sizeof(ver_tlv
));
3189 /* For TLV type device, parse the tlv data */
3190 err
= btintel_parse_version_tlv(hdev
, &ver_tlv
, skb
);
3192 bt_dev_err(hdev
, "Failed to parse TLV version information");
3196 if (INTEL_HW_PLATFORM(ver_tlv
.cnvi_bt
) != 0x37) {
3197 bt_dev_err(hdev
, "Unsupported Intel hardware platform (0x%2x)",
3198 INTEL_HW_PLATFORM(ver_tlv
.cnvi_bt
));
3203 /* Check for supported iBT hardware variants of this firmware
3206 * This check has been put in place to ensure correct forward
3207 * compatibility options when newer hardware variants come
3210 switch (INTEL_HW_VARIANT(ver_tlv
.cnvi_bt
)) {
3211 case 0x11: /* JfP */
3212 case 0x12: /* ThP */
3213 case 0x13: /* HrP */
3214 case 0x14: /* CcP */
3215 /* Some legacy bootloader devices starting from JfP,
3216 * the operational firmware supports both old and TLV based
3217 * HCI_Intel_Read_Version command based on the command
3220 * For upgrading firmware case, the TLV based version cannot
3221 * be used because the firmware filename for legacy bootloader
3222 * is based on the old format.
3224 * Also, it is not easy to convert TLV based version from the
3225 * legacy version format.
3227 * So, as a workaround for those devices, use the legacy
3228 * HCI_Intel_Read_Version to get the version information and
3229 * run the legacy bootloader setup.
3231 err
= btintel_read_version(hdev
, &ver
);
3235 /* Apply the device specific HCI quirks
3237 * All Legacy bootloader devices support WBS
3239 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED
, &hdev
->quirks
);
3241 /* These variants don't seem to support LE Coded PHY */
3242 set_bit(HCI_QUIRK_BROKEN_LE_CODED
, &hdev
->quirks
);
3244 /* Setup MSFT Extension support */
3245 btintel_set_msft_opcode(hdev
, ver
.hw_variant
);
3247 err
= btintel_bootloader_setup(hdev
, &ver
);
3248 btintel_register_devcoredump_support(hdev
);
3250 case 0x18: /* GfP2 */
3251 case 0x1c: /* GaP */
3252 /* Re-classify packet type for controllers with LE audio */
3253 hdev
->classify_pkt_type
= btintel_classify_pkt_type
;
3260 /* Display version information of TLV type */
3261 btintel_version_info_tlv(hdev
, &ver_tlv
);
3263 /* Apply the device specific HCI quirks for TLV based devices
3265 * All TLV based devices support WBS
3267 set_bit(HCI_QUIRK_WIDEBAND_SPEECH_SUPPORTED
, &hdev
->quirks
);
3269 /* Setup MSFT Extension support */
3270 btintel_set_msft_opcode(hdev
,
3271 INTEL_HW_VARIANT(ver_tlv
.cnvi_bt
));
3272 btintel_set_dsm_reset_method(hdev
, &ver_tlv
);
3274 err
= btintel_bootloader_setup_tlv(hdev
, &ver_tlv
);
3278 btintel_register_devcoredump_support(hdev
);
3279 btintel_print_fseq_info(hdev
);
3282 bt_dev_err(hdev
, "Unsupported Intel hw variant (%u)",
3283 INTEL_HW_VARIANT(ver_tlv
.cnvi_bt
));
3288 hci_set_hw_info(hdev
, "INTEL platform=%u variant=%u",
3289 INTEL_HW_PLATFORM(ver_tlv
.cnvi_bt
),
3290 INTEL_HW_VARIANT(ver_tlv
.cnvi_bt
));
3298 int btintel_shutdown_combined(struct hci_dev
*hdev
)
3300 struct sk_buff
*skb
;
3303 /* Send HCI Reset to the controller to stop any BT activity which
3304 * were triggered. This will help to save power and maintain the
3305 * sync b/w Host and controller
3307 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
3309 bt_dev_err(hdev
, "HCI reset during shutdown failed");
3310 return PTR_ERR(skb
);
3315 /* Some platforms have an issue with BT LED when the interface is
3316 * down or BT radio is turned off, which takes 5 seconds to BT LED
3317 * goes off. As a workaround, sends HCI_Intel_SW_RFKILL to put the
3318 * device in the RFKILL ON state which turns off the BT LED immediately.
3320 if (btintel_test_flag(hdev
, INTEL_BROKEN_SHUTDOWN_LED
)) {
3321 skb
= __hci_cmd_sync(hdev
, 0xfc3f, 0, NULL
, HCI_INIT_TIMEOUT
);
3324 bt_dev_err(hdev
, "turning off Intel device LED failed");
3332 EXPORT_SYMBOL_GPL(btintel_shutdown_combined
);
3334 int btintel_configure_setup(struct hci_dev
*hdev
, const char *driver_name
)
3336 hdev
->manufacturer
= 2;
3337 hdev
->setup
= btintel_setup_combined
;
3338 hdev
->shutdown
= btintel_shutdown_combined
;
3339 hdev
->hw_error
= btintel_hw_error
;
3340 hdev
->set_diag
= btintel_set_diag_combined
;
3341 hdev
->set_bdaddr
= btintel_set_bdaddr
;
3343 coredump_info
.driver_name
= driver_name
;
3347 EXPORT_SYMBOL_GPL(btintel_configure_setup
);
3349 int btintel_diagnostics(struct hci_dev
*hdev
, struct sk_buff
*skb
)
3351 struct intel_tlv
*tlv
= (void *)&skb
->data
[5];
3353 /* The first event is always an event type TLV */
3354 if (tlv
->type
!= INTEL_TLV_TYPE_ID
)
3357 switch (tlv
->val
[0]) {
3358 case INTEL_TLV_SYSTEM_EXCEPTION
:
3359 case INTEL_TLV_FATAL_EXCEPTION
:
3360 case INTEL_TLV_DEBUG_EXCEPTION
:
3361 case INTEL_TLV_TEST_EXCEPTION
:
3362 /* Generate devcoredump from exception */
3363 if (!hci_devcd_init(hdev
, skb
->len
)) {
3364 hci_devcd_append(hdev
, skb_clone(skb
, GFP_ATOMIC
));
3365 hci_devcd_complete(hdev
);
3367 bt_dev_err(hdev
, "Failed to generate devcoredump");
3371 bt_dev_err(hdev
, "Invalid exception type %02X", tlv
->val
[0]);
3375 return hci_recv_frame(hdev
, skb
);
3377 EXPORT_SYMBOL_GPL(btintel_diagnostics
);
3379 int btintel_recv_event(struct hci_dev
*hdev
, struct sk_buff
*skb
)
3381 struct hci_event_hdr
*hdr
= (void *)skb
->data
;
3382 const char diagnostics_hdr
[] = { 0x87, 0x80, 0x03 };
3384 if (skb
->len
> HCI_EVENT_HDR_SIZE
&& hdr
->evt
== 0xff &&
3386 const void *ptr
= skb
->data
+ HCI_EVENT_HDR_SIZE
+ 1;
3387 unsigned int len
= skb
->len
- HCI_EVENT_HDR_SIZE
- 1;
3389 if (btintel_test_flag(hdev
, INTEL_BOOTLOADER
)) {
3390 switch (skb
->data
[2]) {
3392 /* When switching to the operational firmware
3393 * the device sends a vendor specific event
3394 * indicating that the bootup completed.
3396 btintel_bootup(hdev
, ptr
, len
);
3400 /* When the firmware loading completes the
3401 * device sends out a vendor specific event
3402 * indicating the result of the firmware
3405 btintel_secure_send_result(hdev
, ptr
, len
);
3411 /* Handle all diagnostics events separately. May still call
3414 if (len
>= sizeof(diagnostics_hdr
) &&
3415 memcmp(&skb
->data
[2], diagnostics_hdr
,
3416 sizeof(diagnostics_hdr
)) == 0) {
3417 return btintel_diagnostics(hdev
, skb
);
3421 return hci_recv_frame(hdev
, skb
);
3423 EXPORT_SYMBOL_GPL(btintel_recv_event
);
3425 void btintel_bootup(struct hci_dev
*hdev
, const void *ptr
, unsigned int len
)
3427 const struct intel_bootup
*evt
= ptr
;
3429 if (len
!= sizeof(*evt
))
3432 if (btintel_test_and_clear_flag(hdev
, INTEL_BOOTING
))
3433 btintel_wake_up_flag(hdev
, INTEL_BOOTING
);
3435 EXPORT_SYMBOL_GPL(btintel_bootup
);
3437 void btintel_secure_send_result(struct hci_dev
*hdev
,
3438 const void *ptr
, unsigned int len
)
3440 const struct intel_secure_send_result
*evt
= ptr
;
3442 if (len
!= sizeof(*evt
))
3446 btintel_set_flag(hdev
, INTEL_FIRMWARE_FAILED
);
3448 if (btintel_test_and_clear_flag(hdev
, INTEL_DOWNLOADING
) &&
3449 btintel_test_flag(hdev
, INTEL_FIRMWARE_LOADED
))
3450 btintel_wake_up_flag(hdev
, INTEL_DOWNLOADING
);
3452 EXPORT_SYMBOL_GPL(btintel_secure_send_result
);
3454 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
3455 MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION
);
3456 MODULE_VERSION(VERSION
);
3457 MODULE_LICENSE("GPL");
3458 MODULE_FIRMWARE("intel/ibt-11-5.sfi");
3459 MODULE_FIRMWARE("intel/ibt-11-5.ddc");
3460 MODULE_FIRMWARE("intel/ibt-12-16.sfi");
3461 MODULE_FIRMWARE("intel/ibt-12-16.ddc");