Bluetooth: btintel: Add support to configure TX power
Subsystems (2)
PATCH 1/1 Bluetooth: btintel: Add support to configure TX power
BRDS - Bluetooth Regulatory Domain Specific absorption rate
-----------------------------------------------------------
Bluetooth has regulatory limitations which prohibit or allow usage of certain bands or channels as well as limiting Tx power. The Tx power values can be configured in ACPI table. This patch reads ACPI entry of Bluetooth SAR and configures the controller accordingly.
--- drivers/bluetooth/btintel.c | 229 ++++++++++++++++++++++++++++++++++++ drivers/bluetooth/btintel.h | 18 +++ 2 files changed, 247 insertions(+)
drivers/bluetooth/btintel.c +229 -0
@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/firmware.h> #include <linux/regmap.h> +#include <linux/acpi.h> #include <asm/unaligned.h> #include <net/bluetooth/bluetooth.h>
@@ -32,6 +33,9 @@ struct cmd_write_boot_params {u8 fw_build_yy; } __packed; +#define BTINTEL_SAR_NAME "BRDS" +#define BTINTEL_SAR_PREFIX "\\_SB_.PC00.XHCI.RHUB" +int btintel_check_bdaddr (struct hci_dev *hdev) {struct hci_rp_read_bd_addr *bda;
@@ -2250,6 +2254,228 @@ static int btintel_configure_offload(struct hci_dev *hdev)return err; } +static acpi_status btintel_sar_callback (acpi_handle handle,u32 lvl,void *data, +void **ret) +{ +acpi_status status; +int len; +struct btintel_sar *sar; +union acpi_object *p, *elements; +struct acpi_buffer string = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; + + status =acpi_get_name (handle,ACPI_FULL_PATHNAME , &string); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + +if (strncmp (BTINTEL_SAR_PREFIX , string.pointer, +strlen (BTINTEL_SAR_PREFIX ))) { +kfree (string.pointer); +return AE_OK ; + } + + len =strlen (string.pointer); +if (strncmp ((char *)string.pointer + len -4 ,BTINTEL_SAR_NAME ,4 )) { +kfree (string.pointer); +return AE_OK ; + } +kfree (string.pointer); + + status =acpi_evaluate_object (handle,NULL ,NULL , &buffer); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + + p = buffer.pointer; + sar = data; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=2 ) { +kfree (buffer.pointer); +BT_DBG ("Invalid object type or package count" ); +return AE_ERROR ; + } + + elements = p->package.elements; + +/* SAR table is located at element[1] */ + p = &elements[1 ]; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=8 ) { +kfree (buffer.pointer); +return AE_ERROR ; + } + + sar->domain = (u8 )p->package.elements[0 ].integer.value; + sar->type = (u8 )p->package.elements[1 ].integer.value; + sar->br = (u32 )p->package.elements[2 ].integer.value; + sar->edr2 = (u32 )p->package.elements[3 ].integer.value; + sar->edr3 = (u32 )p->package.elements[4 ].integer.value; + sar->le = (u32 )p->package.elements[5 ].integer.value; + sar->le_2mhz = (u32 )p->package.elements[6 ].integer.value; + sar->le_lr = (u32 )p->package.elements[7 ].integer.value; +kfree (buffer.pointer); +return AE_CTRL_TERMINATE ; +} + +static void btintel_send_sar_ddc (struct hci_dev *hdev,void *data,u8 len) +{ +struct sk_buff *skb; + + skb =__hci_cmd_sync (hdev,0xfc8b , len, data,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_warn (hdev,"Failed to send Intel Write SAR DDC (%ld)" ,PTR_ERR (skb)); +return ; + } +kfree_skb (skb); +} + +static int btintel_set_legacy_sar (struct hci_dev *hdev,struct btintel_sar *sar) +{ +struct btintel_cp_ddc_write *cmd; +u8 buffer[64 ]; + +if (!sar) +return -EINVAL ; + + cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0131 ); + cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0132 ); + cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0137 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0138 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013b ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013c ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + +return 0 ; +} + +static int btintel_set_mutual_sar (struct hci_dev *hdev,struct btintel_sar *sar) +{ +u8 buffer[64 ]; +struct btintel_cp_ddc_write *cmd; +u8 enable[1 ] = {1 }; +struct sk_buff *skb; + +if (!sar) +return -EINVAL ; + + cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019e ); +if (!(sar->le_2mhz &BIT (7 ))) + cmd->data[0 ] =0x01 ; +else + cmd->data[0 ] =0x00 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019f ); + cmd->data[0 ] = sar->le_lr; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a0 ); + cmd->data[0 ] = sar->br; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a1 ); + cmd->data[0 ] = sar->edr2; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a2 ); + cmd->data[0 ] = sar->edr3; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a3 ); + cmd->data[0 ] = sar->le; +btintel_send_sar_ddc (hdev, cmd,4 ); + + skb =__hci_cmd_sync (hdev,0xfe25 ,1 , enable,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_warn (hdev,"Failed to send Intel SAR Enable (%ld)" ,PTR_ERR (skb)); +return PTR_ERR (skb); + } +kfree_skb (skb); + +return 0 ; +} + +static int btintel_set_specific_absorption_rate (struct hci_dev *hdev, +struct intel_version_tlv *ver) +{ +acpi_status status; +struct btintel_sar sar; + +switch (ver->cnvr_top &0xfff ) { +case 0x810 :/* MsP */ +break ; +default : +return 0 ; + } + +memset (&sar,0 ,sizeof (sar)); + + status =acpi_walk_namespace (ACPI_TYPE_METHOD ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX ,NULL , + btintel_sar_callback, &sar,NULL ); + +if (ACPI_FAILURE (status)) +return -1 ; + +if (sar.domain !=0x12 ) +return -1 ; + +/* No need to configure controller if Bluetooth SAR is disabled in BIOS +*/ +if (!sar.type) +return 0 ; + +if (sar.type ==1 ) { +bt_dev_info (hdev,"Applying both legacy and mutual Bluetooth SAR" ); +btintel_set_legacy_sar (hdev, &sar); +btintel_set_mutual_sar (hdev, &sar); + } +return 0 ; +} +static int btintel_bootloader_setup_tlv (struct hci_dev *hdev,struct intel_version_tlv *ver) {
@@ -2294,6 +2520,9 @@ static int btintel_bootloader_setup_tlv(struct hci_dev *hdev,/* Read supported use cases and set callbacks to fetch datapath id */ btintel_configure_offload (hdev); +/* Set Specific Absorption Rate */ +btintel_set_specific_absorption_rate (hdev, ver); +hci_dev_clear_flag (hdev,HCI_QUALITY_REPORT );/* Read the Intel version information after loading the FW */
drivers/bluetooth/btintel.h +18 -0
@@ -137,6 +137,24 @@ struct intel_offload_use_cases {__u8 preset[8 ]; } __packed; +/* structure to store the data read from ACPI table */ +struct btintel_sar { +u8 domain; +u8 type; +u32 br; +u32 edr2; +u32 edr3; +u32 le; +u32 le_2mhz; +u32 le_lr; +}; + +struct btintel_cp_ddc_write { +u8 len; +__le16 id; +u8 data[0 ]; +} __packed; +#define INTEL_HW_PLATFORM (cnvx_bt) ((u8)(((cnvx_bt) & 0x0000ff00) >> 8))#define INTEL_HW_VARIANT (cnvx_bt) ((u8)(((cnvx_bt) & 0x003f0000) >> 16))#define INTEL_CNVX_TOP_TYPE (cnvx_top) ((cnvx_top) & 0x00000fff)
Signature · 1 line
2.17.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=630327
---Test result---
Test Summary:
CheckPatch PASS 1.91 seconds GitLint PASS 1.00 seconds SubjectPrefix PASS 0.82 seconds BuildKernel PASS 31.71 seconds BuildKernel32 PASS 28.41 seconds Incremental Build with patchesPASS 38.53 seconds TestRunner: Setup PASS 473.64 seconds TestRunner: l2cap-tester PASS 16.07 seconds TestRunner: bnep-tester PASS 6.37 seconds TestRunner: mgmt-tester PASS 106.73 seconds TestRunner: rfcomm-tester PASS 8.30 seconds TestRunner: sco-tester PASS 8.07 seconds TestRunner: smp-tester PASS 7.94 seconds TestRunner: userchan-tester PASS 6.61 seconds
---
Regards,
Linux Bluetooth
[Cc: +linux-acpi to check for best practices in ACPI table handling]
Dear Kiran,
Am 08.04.22 um 10:06 schrieb Kiran K:
Thank you for the patch. Maybe as commit message summary:
Support to configure TX power using BRDS ACPI table
Quoted 2 lines
BRDS - Bluetooth Regulatory Domain Specific absorption rate
-----------------------------------------------------------
Why this header? Integrate the long table name into the message below.
Quoted 5 lines
Bluetooth has regulatory limitations which prohibit or allow usage of certain bands or channels as well as limiting Tx power. The Tx power values can be configured in ACPI table. This patch reads ACPI entry of Bluetooth SAR and configures the controller accordingly.
It’d be great if you elaborated a little on the implementation? For example, what is the legacy SAR needed for?
How did you test this? What device and firmware providing the BRDS table? Maybe even paste the ASL table here as an example.
Quoted 30 lines
Signed-off-by Kiran K <[email protected]>Signed-off-by Seema S <[email protected]>--- drivers/bluetooth/btintel.c | 229 ++++++++++++++++++++++++++++++++++++ drivers/bluetooth/btintel.h | 18 +++ 2 files changed, 247 insertions(+)drivers/bluetooth/btintel.c +4
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/firmware.h> #include <linux/regmap.h> +#include <linux/acpi.h> #include <asm/unaligned.h> #include <net/bluetooth/bluetooth.h> @@ -32,6 +33,9 @@ struct cmd_write_boot_params {u8 fw_build_yy; } __packed; +#define BTINTEL_SAR_NAME "BRDS" +#define BTINTEL_SAR_PREFIX "\\_SB_.PC00.XHCI.RHUB" +int btintel_check_bdaddr (struct hci_dev *hdev) {struct hci_rp_read_bd_addr *bda;
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2261
Quoted 8 lines
drivers/bluetooth/btintel.c +5
-0@@ -2250,6 +2254,228 @@ static int btintel_configure_offload(struct hci_dev *hdev)return err; } +static acpi_status btintel_sar_callback (acpi_handle handle,u32 lvl,void *data, +void **ret) +{ +acpi_status status; +int len;
size_t
Quoted 26 lines
drivers/bluetooth/btintel.c +26
-0+struct btintel_sar *sar; +union acpi_object *p, *elements; +struct acpi_buffer string = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; + + status =acpi_get_name (handle,ACPI_FULL_PATHNAME , &string); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + +if (strncmp (BTINTEL_SAR_PREFIX , string.pointer, +strlen (BTINTEL_SAR_PREFIX ))) { +kfree (string.pointer); +return AE_OK ; + } + + len =strlen (string.pointer); +if (strncmp ((char *)string.pointer + len -4 ,BTINTEL_SAR_NAME ,4 )) { +kfree (string.pointer); +return AE_OK ; + } +kfree (string.pointer); + + status =acpi_evaluate_object (handle,NULL ,NULL , &buffer); +if (ACPI_FAILURE (status)) {
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2297
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + + p = buffer.pointer; + sar = data; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=2 ) { +kfree (buffer.pointer); +BT_DBG ("Invalid object type or package count" );
Please add the variable values to the debug line.
Quoted 16 lines
drivers/bluetooth/btintel.c +16
-0+return AE_ERROR ; + } + + elements = p->package.elements; + +/* SAR table is located at element[1] */ + p = &elements[1 ]; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=8 ) { +kfree (buffer.pointer); +return AE_ERROR ; + } + + sar->domain = (u8 )p->package.elements[0 ].integer.value; + sar->type = (u8 )p->package.elements[1 ].integer.value; + sar->br = (u32 )p->package.elements[2 ].integer.value;
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2323
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+ sar->edr2 = (u32 )p->package.elements[3 ].integer.value; + sar->edr3 = (u32 )p->package.elements[4 ].integer.value; + sar->le = (u32 )p->package.elements[5 ].integer.value; + sar->le_2mhz = (u32 )p->package.elements[6 ].integer.value; + sar->le_lr = (u32 )p->package.elements[7 ].integer.value; +kfree (buffer.pointer); +return AE_CTRL_TERMINATE ; +} + +static void btintel_send_sar_ddc (struct hci_dev *hdev,void *data,u8 len)
Use native type for len? unsigned int?
Quoted 5 lines
drivers/bluetooth/btintel.c +5
-0+{ +struct sk_buff *skb; + + skb =__hci_cmd_sync (hdev,0xfc8b , len, data,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) {
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2338
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+bt_dev_warn (hdev,"Failed to send Intel Write SAR DDC (%ld)" ,PTR_ERR (skb)); +return ; + } +kfree_skb (skb); +} + +static int btintel_set_legacy_sar (struct hci_dev *hdev,struct btintel_sar *sar) +{ +struct btintel_cp_ddc_write *cmd; +u8 buffer[64 ];
Don’t try to align with tabs?
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2346
Quoted 8 lines
drivers/bluetooth/btintel.c +8
-0+ +if (!sar) +return -EINVAL ; + + cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0131 );
Add names for the command id’s?
Quoted 47 lines
drivers/bluetooth/btintel.c +47
-0+ cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0132 ); + cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0137 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0138 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013b ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013c ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + +return 0 ; +} + +static int btintel_set_mutual_sar (struct hci_dev *hdev,struct btintel_sar *sar) +{ +u8 buffer[64 ]; +struct btintel_cp_ddc_write *cmd; +u8 enable[1 ] = {1 }; +struct sk_buff *skb; + +if (!sar)
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2403
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+return -EINVAL ; + + cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019e ); +if (!(sar->le_2mhz &BIT (7 ))) + cmd->data[0 ] =0x01 ; +else + cmd->data[0 ] =0x00 ;
Use ternary operator?
Quoted 54 lines
drivers/bluetooth/btintel.c +54
-0+btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019f ); + cmd->data[0 ] = sar->le_lr; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a0 ); + cmd->data[0 ] = sar->br; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a1 ); + cmd->data[0 ] = sar->edr2; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a2 ); + cmd->data[0 ] = sar->edr3; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a3 ); + cmd->data[0 ] = sar->le; +btintel_send_sar_ddc (hdev, cmd,4 ); + + skb =__hci_cmd_sync (hdev,0xfe25 ,1 , enable,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_warn (hdev,"Failed to send Intel SAR Enable (%ld)" ,PTR_ERR (skb)); +return PTR_ERR (skb); + } +kfree_skb (skb); + +return 0 ; +} + +static int btintel_set_specific_absorption_rate (struct hci_dev *hdev, +struct intel_version_tlv *ver) +{ +acpi_status status; +struct btintel_sar sar; + +switch (ver->cnvr_top &0xfff ) { +case 0x810 :/* MsP */ +break ; +default : +return 0 ; + } + +memset (&sar,0 ,sizeof (sar)); + + status = acpi_walk_namespace(ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX, NULL,
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2467
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+ btintel_sar_callback, &sar, NULL); + +if (ACPI_FAILURE (status)) +return -1 ; + +if (sar.domain !=0x12 ) +return -1 ; + +/* No need to configure controller if Bluetooth SAR is disabled in BIOS +*/
Put it on the line above?
Quoted 32 lines
drivers/bluetooth/btintel.c +14
-0+if (!sar.type) +return 0 ; + +if (sar.type ==1 ) { +bt_dev_info (hdev,"Applying both legacy and mutual Bluetooth SAR" ); +btintel_set_legacy_sar (hdev, &sar); +btintel_set_mutual_sar (hdev, &sar); + } +return 0 ; +} +static int btintel_bootloader_setup_tlv (struct hci_dev *hdev,struct intel_version_tlv *ver) {@@ -2294,6 +2520,9 @@ static int btintel_bootloader_setup_tlv(struct hci_dev *hdev,/* Read supported use cases and set callbacks to fetch datapath id */ btintel_configure_offload (hdev); +/* Set Specific Absorption Rate */ +btintel_set_specific_absorption_rate (hdev, ver); +hci_dev_clear_flag (hdev,HCI_QUALITY_REPORT );/* Read the Intel version information after loading the FW */ drivers/bluetooth/btintel.h +0
-0@@ -137,6 +137,24 @@ struct intel_offload_use_cases {__u8 preset[8 ]; } __packed;
drivers/bluetooth/btintel.h struct intel_offload_use_cases { · line 149
Quoted 10 lines
drivers/bluetooth/btintel.h +10
-0+/* structure to store the data read from ACPI table */ +struct btintel_sar { +u8 domain; +u8 type; +u32 br; +u32 edr2; +u32 edr3; +u32 le; +u32 le_2mhz; +u32 le_lr;
Can’t native types be used?
Quoted 11 lines
drivers/bluetooth/btintel.h +8
-0+}; + +struct btintel_cp_ddc_write { +u8 len; +__le16 id; +u8 data[0 ]; +} __packed; +#define INTEL_HW_PLATFORM (cnvx_bt) ((u8)(((cnvx_bt) & 0x0000ff00) >> 8))#define INTEL_HW_VARIANT (cnvx_bt) ((u8)(((cnvx_bt) & 0x003f0000) >> 16))#define INTEL_CNVX_TOP_TYPE (cnvx_top) ((cnvx_top) & 0x00000fff)
Hi Paul,
Sorry for the delay. Thanks for your valuable comments.
Quoted 19 lines
-----Original Message-----
From: Paul Menzel <[email protected]>
Sent: Saturday, April 9, 2022 12:53 PM
To: K, Kiran <[email protected]>
Cc: [email protected]; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; Sreemantha, Seema <[email protected]>; [email protected]
Subject: Re: [PATCH v1] Bluetooth: btintel: Add support to configure TX power[Cc: +linux-acpi to check for best practices in ACPI table handling]
Dear Kiran,
Am 08.04.22 um 10:06 schrieb Kiran K:
Quoted 9 lines
Thank you for the patch. Maybe as commit message summary:
Support to configure TX power using BRDS ACPI table
Quoted 2 lines
BRDS - Bluetooth Regulatory Domain Specific absorption rate
-----------------------------------------------------------Why this header? Integrate the long table name into the message below.
Ack.
Quoted 6 lines
Quoted 5 lines
Bluetooth has regulatory limitations which prohibit or allow usage of certain bands or channels as well as limiting Tx power. The Tx power values can be configured in ACPI table. This patch reads ACPI entry of Bluetooth SAR and configures the controller accordingly.
Quoted 6 lines
It’d be great if you elaborated a little on the implementation? For example, what is the legacy SAR needed for?
How did you test this? What device and firmware providing the BRDS table? Maybe even paste the ASL table here as an example.
Ack. I will update the commit message with details in v2 version of patch.
Quoted 35 lines
Quoted 4 lines
Signed-off-by Kiran K <[email protected]>Signed-off-by Seema S <[email protected]>--- drivers/bluetooth/btintel.c | 229++++++++++++++++++++++++++++++++++++
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct
Quoted 26 lines
drivers/bluetooth/btintel.h | 18 +++ 2 files changed, 247 insertions(+)drivers/bluetooth/btintel.c +1
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/firmware.h> #include <linux/regmap.h> +#include <linux/acpi.h> #include <asm/unaligned.h> #include <net/bluetooth/bluetooth.h> @@ -32,6 +33,9 @@ struct
cmd_write_boot_params{
u8fw_build_yy;
}__packed;drivers/bluetooth/btintel.c +3
-0+#define BTINTEL_SAR_NAME "BRDS" +#define BTINTEL_SAR_PREFIX "\\_SB_.PC00.XHCI.RHUB" +int btintel_check_bdaddr (struct hci_dev *hdev) {struct hci_rp_read_bd_addr *bda;@@ -2250,6 +2254,228 @@ static int btintel_configure_offload(struct
hci_dev*hdev)Quoted 3 lines
drivers/bluetooth/btintel.c +0
-0return err; }
Quoted 8 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct · line 2257
Quoted 1 line
drivers/bluetooth/btintel.c +1
-0+static acpi_status btintel_sar_callback(acpi_handle handle, u32 lvl, void*data,
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2261
Quoted 4 lines
drivers/bluetooth/btintel.c +4
-0+ void **ret) +{ +acpi_status status; +int len;
size_t
Ack.
Quoted 31 lines
Quoted 31 lines
drivers/bluetooth/btintel.c +30
-0+struct btintel_sar *sar; +union acpi_object *p, *elements; +struct acpi_buffer string = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; + + status =acpi_get_name (handle,ACPI_FULL_PATHNAME , &string); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + +if (strncmp (BTINTEL_SAR_PREFIX , string.pointer, +strlen (BTINTEL_SAR_PREFIX ))) { +kfree (string.pointer); +return AE_OK ; + } + + len =strlen (string.pointer); +if (strncmp ((char *)string.pointer + len -4 ,BTINTEL_SAR_NAME ,4 )) { +kfree (string.pointer); +return AE_OK ; + } +kfree (string.pointer); + + status =acpi_evaluate_object (handle,NULL ,NULL , &buffer); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } +
Quoted 9 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2297
Quoted 6 lines
drivers/bluetooth/btintel.c +6
-0+ p = buffer.pointer; + sar = data; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=2 ) { +kfree (buffer.pointer); +BT_DBG ("Invalid object type or package count" );Please add the variable values to the debug line.
Ack.
Quoted 21 lines
Quoted 21 lines
drivers/bluetooth/btintel.c +21
-0+return AE_ERROR ; + } + + elements = p->package.elements; + +/* SAR table is located at element[1] */ + p = &elements[1 ]; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=8 ) { +kfree (buffer.pointer); +return AE_ERROR ; + } + + sar->domain = (u8 )p->package.elements[0 ].integer.value; + sar->type = (u8 )p->package.elements[1 ].integer.value; + sar->br = (u32 )p->package.elements[2 ].integer.value; + sar->edr2 = (u32 )p->package.elements[3 ].integer.value; + sar->edr3 = (u32 )p->package.elements[4 ].integer.value; + sar->le = (u32 )p->package.elements[5 ].integer.value; + sar->le_2mhz = (u32 )p->package.elements[6 ].integer.value; + sar->le_lr = (u32 )p->package.elements[7 ].integer.value;
Quoted 9 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 6 lines
drivers/bluetooth/btintel.c +6
-0+kfree (buffer.pointer); +return AE_CTRL_TERMINATE ; +} + +static void btintel_send_sar_ddc (struct hci_dev *hdev,void *data,u8 +len)Use native type for
len?unsigned int?
Ack.
Quoted 7 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 6 lines
drivers/bluetooth/btintel.c +6
-0+{ +struct sk_buff *skb; + + skb =__hci_cmd_sync (hdev,0xfc8b , len, data,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { + bt_dev_warn(hdev, "Failed to send Intel Write SAR DDC(%ld)",
PTR_ERR(skb));
Quoted 12 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2338
Quoted 9 lines
drivers/bluetooth/btintel.c +9
-0+return ; + } +kfree_skb (skb); +} + +static int btintel_set_legacy_sar (struct hci_dev *hdev,struct +btintel_sar *sar) { +struct btintel_cp_ddc_write *cmd; +u8 buffer[64 ];Don’t try to align with tabs?
Ack.
Quoted 11 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2346
Quoted 8 lines
drivers/bluetooth/btintel.c +8
-0+ +if (!sar) +return -EINVAL ; + + cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0131 );Add names for the command id’s?
Ack.
Quoted 51 lines
Quoted 51 lines
drivers/bluetooth/btintel.c +51
-0+ cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0132 ); + cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0137 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0138 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013b ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013c ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + +return 0 ; +} + +static int btintel_set_mutual_sar (struct hci_dev *hdev,struct +btintel_sar *sar) { +u8 buffer[64 ]; +struct btintel_cp_ddc_write *cmd; +u8 enable[1 ] = {1 }; +struct sk_buff *skb; + +if (!sar) +return -EINVAL ; + + cmd = (void *)buffer; +
Quoted 8 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2403
Quoted 6 lines
drivers/bluetooth/btintel.c +6
-0+ cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019e ); +if (!(sar->le_2mhz &BIT (7 ))) + cmd->data[0 ] =0x01 ; +else + cmd->data[0 ] =0x00 ;Use ternary operator?
Ack.
Quoted 67 lines
Quoted 21 lines
drivers/bluetooth/btintel.c +20
-0+btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019f ); + cmd->data[0 ] = sar->le_lr; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a0 ); + cmd->data[0 ] = sar->br; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a1 ); + cmd->data[0 ] = sar->edr2; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a2 ); + cmd->data[0 ] = sar->edr3;drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a3 ); + cmd->data[0 ] = sar->le; +btintel_send_sar_ddc (hdev, cmd,4 ); + + skb =__hci_cmd_sync (hdev,0xfe25 ,1 , enable,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { + bt_dev_warn(hdev, "Failed to send Intel SAR Enable (%ld)",
PTR_ERR(skb));Quoted 13 lines
drivers/bluetooth/btintel.c +13
-0+return PTR_ERR (skb); + } +kfree_skb (skb); + +return 0 ; +} + +static int btintel_set_specific_absorption_rate (struct hci_dev *hdev, +struct intel_version_tlv *ver) +{ +acpi_status status; +struct btintel_sar sar; +drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+switch (ver->cnvr_top &0xfff ) { +case 0x810 :/* MsP */ +break ; +default : +return 0 ; + } + +memset (&sar,0 ,sizeof (sar)); + + status = acpi_walk_namespace(ACPI_TYPE_METHOD,
ACPI_ROOT_OBJECT,drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+ACPI_UINT32_MAX ,NULL , + btintel_sar_callback, &sar, NULL); + +if (ACPI_FAILURE (status)) +return -1 ; + +if (sar.domain !=0x12 ) +return -1 ; + +/* No need to configure controller if Bluetooth SAR is disabled in BIOS
Quoted 4 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2467
Quoted 1 line
drivers/bluetooth/btintel.c +1
-0+*/ Put it on the line above?
Ack.
Quoted 34 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 5 lines
drivers/bluetooth/btintel.c +5
-0+if (!sar.type) +return 0 ; + +if (sar.type ==1 ) { + bt_dev_info(hdev, "Applying both legacy and mutualBluetooth SAR");
drivers/bluetooth/btintel.c static int btintel_bootloader_setup_tlv(struct
Quoted 10 lines
drivers/bluetooth/btintel.c +6
-0+btintel_set_legacy_sar (hdev, &sar); +btintel_set_mutual_sar (hdev, &sar); + } +return 0 ; +} +static int btintel_bootloader_setup_tlv (struct hci_dev *hdev,struct intel_version_tlv *ver) {@@ -2294,6 +2520,9 @@ static int btintel_bootloader_setup_tlv(struct
hci_dev*hdev,Quoted 17 lines
drivers/bluetooth/btintel.c +3
-1/* Read supported use cases and set callbacks to fetch datapath id */ btintel_configure_offload (hdev); +/* Set Specific Absorption Rate */ +btintel_set_specific_absorption_rate (hdev, ver); +hci_dev_clear_flag (hdev,HCI_QUALITY_REPORT );/* Read the Intel version information after loading the FW */ diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.hindex
e0060e58573c..7aa58fb7b02a100644drivers/bluetooth/btintel.h +0
-0@@ -137,6 +137,24 @@ struct intel_offload_use_cases {__u8 preset[8 ]; } __packed;
Quoted 12 lines
drivers/bluetooth/btintel.h struct intel_offload_use_cases { · line 149
Quoted 10 lines
drivers/bluetooth/btintel.h +10
-0+/* structure to store the data read from ACPI table */ struct +btintel_sar { +u8 domain; +u8 type; +u32 br; +u32 edr2; +u32 edr3; +u32 le; +u32 le_2mhz; +u32 le_lr;Can’t native types be used?
No. some fields size is 4 bytes.
Quoted 11 lines
drivers/bluetooth/btintel.h struct intel_offload_use_cases {
Quoted 10 lines
drivers/bluetooth/btintel.h +8
-0+}; + +struct btintel_cp_ddc_write { +u8 len; +__le16 id; +u8 data[0 ]; +} __packed; +#define INTEL_HW_PLATFORM (cnvx_bt) ((u8)(((cnvx_bt) &
0x0000ff00) >> 8))
Quoted 3 lines
drivers/bluetooth/btintel.h struct intel_offload_use_cases { · line 159
Quoted 1 line
drivers/bluetooth/btintel.h +0
-0#define INTEL_HW_VARIANT (cnvx_bt) ((u8)(((cnvx_bt) &
0x003f0000) >> 16))Quoted 1 line
drivers/bluetooth/btintel.h +0
-0#define INTEL_CNVX_TOP_TYPE (cnvx_top) ((cnvx_top) & 0x00000fff)
Thanks,
Kiran
Luiz Augusto von Dentz
maintainerHi Kiran,
Quoted 8 lines · Kiran K
BRDS - Bluetooth Regulatory Domain Specific absorption rate
-----------------------------------------------------------Bluetooth has regulatory limitations which prohibit or allow usage of certain bands or channels as well as limiting Tx power. The Tx power values can be configured in ACPI table. This patch reads ACPI entry of Bluetooth SAR and configures the controller accordingly.
It should be great to have a trace example of the commands in use, so if we can have btmon decoding these to show what is being sent that way we can also debug if something goes wrong.
Quoted 108 lines
Signed-off-by Kiran K <[email protected]>Signed-off-by Seema S <[email protected]>--- drivers/bluetooth/btintel.c | 229 ++++++++++++++++++++++++++++++++++++ drivers/bluetooth/btintel.h | 18 +++ 2 files changed, 247 insertions(+)drivers/bluetooth/btintel.c +79
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/firmware.h> #include <linux/regmap.h> +#include <linux/acpi.h> #include <asm/unaligned.h> #include <net/bluetooth/bluetooth.h> @@ -32,6 +33,9 @@ struct cmd_write_boot_params {u8 fw_build_yy; } __packed; +#define BTINTEL_SAR_NAME "BRDS" +#define BTINTEL_SAR_PREFIX "\\_SB_.PC00.XHCI.RHUB" +int btintel_check_bdaddr (struct hci_dev *hdev) {struct hci_rp_read_bd_addr *bda;@@ -2250,6 +2254,228 @@ static int btintel_configure_offload(struct hci_dev *hdev)return err; } +static acpi_status btintel_sar_callback (acpi_handle handle,u32 lvl,void *data, +void **ret) +{ +acpi_status status; +int len; +struct btintel_sar *sar; +union acpi_object *p, *elements; +struct acpi_buffer string = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; + + status =acpi_get_name (handle,ACPI_FULL_PATHNAME , &string); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + +if (strncmp (BTINTEL_SAR_PREFIX , string.pointer, +strlen (BTINTEL_SAR_PREFIX ))) { +kfree (string.pointer); +return AE_OK ; + } + + len =strlen (string.pointer); +if (strncmp ((char *)string.pointer + len -4 ,BTINTEL_SAR_NAME ,4 )) { +kfree (string.pointer); +return AE_OK ; + } +kfree (string.pointer); + + status =acpi_evaluate_object (handle,NULL ,NULL , &buffer); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + + p = buffer.pointer; + sar = data; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=2 ) { +kfree (buffer.pointer); +BT_DBG ("Invalid object type or package count" ); +return AE_ERROR ; + } + + elements = p->package.elements; + +/* SAR table is located at element[1] */ + p = &elements[1 ]; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=8 ) { +kfree (buffer.pointer); +return AE_ERROR ; + } + + sar->domain = (u8 )p->package.elements[0 ].integer.value; + sar->type = (u8 )p->package.elements[1 ].integer.value; + sar->br = (u32 )p->package.elements[2 ].integer.value; + sar->edr2 = (u32 )p->package.elements[3 ].integer.value; + sar->edr3 = (u32 )p->package.elements[4 ].integer.value; + sar->le = (u32 )p->package.elements[5 ].integer.value; + sar->le_2mhz = (u32 )p->package.elements[6 ].integer.value; + sar->le_lr = (u32 )p->package.elements[7 ].integer.value; +kfree (buffer.pointer); +return AE_CTRL_TERMINATE ; +} + +static void btintel_send_sar_ddc (struct hci_dev *hdev,void *data,u8 len) +{ +struct sk_buff *skb; + + skb =__hci_cmd_sync (hdev,0xfc8b , len, data,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_warn (hdev,"Failed to send Intel Write SAR DDC (%ld)" ,PTR_ERR (skb)); +return ; + }
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2341
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+kfree_skb (skb); +} + +static int btintel_set_legacy_sar (struct hci_dev *hdev,struct btintel_sar *sar) +{ +struct btintel_cp_ddc_write *cmd; +u8 buffer[64 ]; + +if (!sar) +return -EINVAL ;
Add a memset to 0 as this may trigger uninitialized errors in the likes of static analyzers.
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2348
Quoted 6 lines
drivers/bluetooth/btintel.c +6
-0+ cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0131 ); + cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 );
We should probably handle the errors when sending these commands and don't continue, also perhaps it would be better to have each command in its own function with a proper name indicating what it is doing.
Quoted 46 lines
drivers/bluetooth/btintel.c +46
-0+ + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0132 ); + cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0137 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0138 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013b ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013c ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + +return 0 ; +} + +static int btintel_set_mutual_sar (struct hci_dev *hdev,struct btintel_sar *sar) +{ +u8 buffer[64 ]; +struct btintel_cp_ddc_write *cmd; +u8 enable[1 ] = {1 }; +struct sk_buff *skb; + +if (!sar) +return -EINVAL ;
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2404
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+ + cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019e ); +if (!(sar->le_2mhz &BIT (7 ))) + cmd->data[0 ] =0x01 ; +else + cmd->data[0 ] =0x00 ; +btintel_send_sar_ddc (hdev, cmd,4 );
Ditto as above.
Quoted 95 lines
drivers/bluetooth/btintel.c +76
-0+ cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019f ); + cmd->data[0 ] = sar->le_lr; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a0 ); + cmd->data[0 ] = sar->br; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a1 ); + cmd->data[0 ] = sar->edr2; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a2 ); + cmd->data[0 ] = sar->edr3; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a3 ); + cmd->data[0 ] = sar->le; +btintel_send_sar_ddc (hdev, cmd,4 ); + + skb =__hci_cmd_sync (hdev,0xfe25 ,1 , enable,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { +bt_dev_warn (hdev,"Failed to send Intel SAR Enable (%ld)" ,PTR_ERR (skb)); +return PTR_ERR (skb); + } +kfree_skb (skb); + +return 0 ; +} + +static int btintel_set_specific_absorption_rate (struct hci_dev *hdev, +struct intel_version_tlv *ver) +{ +acpi_status status; +struct btintel_sar sar; + +switch (ver->cnvr_top &0xfff ) { +case 0x810 :/* MsP */ +break ; +default : +return 0 ; + } + +memset (&sar,0 ,sizeof (sar)); + + status =acpi_walk_namespace (ACPI_TYPE_METHOD ,ACPI_ROOT_OBJECT , +ACPI_UINT32_MAX ,NULL , + btintel_sar_callback, &sar,NULL ); + +if (ACPI_FAILURE (status)) +return -1 ; + +if (sar.domain !=0x12 ) +return -1 ; + +/* No need to configure controller if Bluetooth SAR is disabled in BIOS +*/ +if (!sar.type) +return 0 ; + +if (sar.type ==1 ) { +bt_dev_info (hdev,"Applying both legacy and mutual Bluetooth SAR" ); +btintel_set_legacy_sar (hdev, &sar); +btintel_set_mutual_sar (hdev, &sar); + } +return 0 ; +} +static int btintel_bootloader_setup_tlv (struct hci_dev *hdev,struct intel_version_tlv *ver) {@@ -2294,6 +2520,9 @@ static int btintel_bootloader_setup_tlv(struct hci_dev *hdev,/* Read supported use cases and set callbacks to fetch datapath id */ btintel_configure_offload (hdev); +/* Set Specific Absorption Rate */ +btintel_set_specific_absorption_rate (hdev, ver); +hci_dev_clear_flag (hdev,HCI_QUALITY_REPORT );/* Read the Intel version information after loading the FW */ drivers/bluetooth/btintel.h +1
-0@@ -137,6 +137,24 @@ struct intel_offload_use_cases {__u8 preset[8 ]; } __packed; +/* structure to store the data read from ACPI table */
drivers/bluetooth/btintel.h struct intel_offload_use_cases { · line 150
Quoted 10 lines
drivers/bluetooth/btintel.h +10
-0+struct btintel_sar { +u8 domain; +u8 type; +u32 br; +u32 edr2; +u32 edr3; +u32 le; +u32 le_2mhz; +u32 le_lr; +};
The above should also be using __packed, also for data packets the multibyte field shall tell what is the expected endianness so given the id below is using __le16 I assume the fields above shall be __le32.
Quoted 12 lines
drivers/bluetooth/btintel.h +6
-1+struct btintel_cp_ddc_write { +u8 len; +__le16 id; +u8 data[0 ]; +} __packed; +#define INTEL_HW_PLATFORM (cnvx_bt) ((u8)(((cnvx_bt) & 0x0000ff00) >> 8))#define INTEL_HW_VARIANT (cnvx_bt) ((u8)(((cnvx_bt) & 0x003f0000) >> 16))#define INTEL_CNVX_TOP_TYPE (cnvx_top) ((cnvx_top) & 0x00000fff) --2.17.1
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 18 lines
-----Original Message-----
From: Luiz Augusto von Dentz <[email protected]>
Sent: Tuesday, April 12, 2022 12:15 AM
To: K, Kiran <[email protected]>
Cc: [email protected]; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; Sreemantha, Seema <[email protected]>
Subject: Re: [PATCH v1] Bluetooth: btintel: Add support to configure TX powerHi Kiran,
Quoted 4 lines · Kiran K
BRDS - Bluetooth Regulatory Domain Specific absorption rate
-----------------------------------------------------------
Quoted 9 lines
Quoted 4 lines
Bluetooth has regulatory limitations which prohibit or allow usage of certain bands or channels as well as limiting Tx power. The Tx power values can be configured in ACPI table. This patch reads ACPI entry of Bluetooth SAR and configures the controller accordingly.
It should be great to have a trace example of the commands in use, so if we can have btmon decoding these to show what is being sent that way we can also debug if something goes wrong.
Ack. I will add decoding of ddc commands to btmon and submit a separate patch.
Quoted 107 lines
Quoted 31 lines
Signed-off-by Kiran K <[email protected]>Signed-off-by Seema S <[email protected]>--- drivers/bluetooth/btintel.c | 229 ++++++++++++++++++++++++++++++++++++ drivers/bluetooth/btintel.h | 18 +++ 2 files changed, 247 insertions(+)drivers/bluetooth/btintel.c +4
-0@@ -9,6 +9,7 @@#include <linux/module.h> #include <linux/firmware.h> #include <linux/regmap.h> +#include <linux/acpi.h> #include <asm/unaligned.h> #include <net/bluetooth/bluetooth.h> @@ -32,6 +33,9 @@ struct cmd_write_boot_params {u8 fw_build_yy; } __packed; +#define BTINTEL_SAR_NAME "BRDS" +#define BTINTEL_SAR_PREFIX "\\_SB_.PC00.XHCI.RHUB" +int btintel_check_bdaddr (struct hci_dev *hdev) { struct hci_rp_read_bd_addr *bda; @@ -2250,6 +2254,228 @@static int btintel_configure_offload (struct hci_dev *hdev)return err;Quoted 3 lines
}
+static
acpi_statusbtintel_sar_callback(acpi_handle handle, u32 lvl, void*data,
Quoted 61 lines
drivers/bluetooth/btintel.c +61
-0+ void **ret) { +acpi_status status; +int len; +struct btintel_sar *sar; +union acpi_object *p, *elements; +struct acpi_buffer string = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; + + status =acpi_get_name (handle,ACPI_FULL_PATHNAME , &string); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + +if (strncmp (BTINTEL_SAR_PREFIX , string.pointer, +strlen (BTINTEL_SAR_PREFIX ))) { +kfree (string.pointer); +return AE_OK ; + } + + len =strlen (string.pointer); +if (strncmp ((char *)string.pointer + len -4 ,BTINTEL_SAR_NAME ,4 )) { +kfree (string.pointer); +return AE_OK ; + } +kfree (string.pointer); + + status =acpi_evaluate_object (handle,NULL ,NULL , &buffer); +if (ACPI_FAILURE (status)) { +BT_DBG ("ACPI Failure: %s" ,acpi_format_exception (status)); +return status; + } + + p = buffer.pointer; + sar = data; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=2 ) { +kfree (buffer.pointer); +BT_DBG ("Invalid object type or package count" ); +return AE_ERROR ; + } + + elements = p->package.elements; + +/* SAR table is located at element[1] */ + p = &elements[1 ]; + +if (p->type !=ACPI_TYPE_PACKAGE || p->package.count !=8 ) { +kfree (buffer.pointer); +return AE_ERROR ; + } + + sar->domain = (u8 )p->package.elements[0 ].integer.value; + sar->type = (u8 )p->package.elements[1 ].integer.value; + sar->br = (u32 )p->package.elements[2 ].integer.value; + sar->edr2 = (u32 )p->package.elements[3 ].integer.value; + sar->edr3 = (u32 )p->package.elements[4 ].integer.value; + sar->le = (u32 )p->package.elements[5 ].integer.value; + sar->le_2mhz = (u32 )p->package.elements[6 ].integer.value; + sar->le_lr = (u32 )p->package.elements[7 ].integer.value; +kfree (buffer.pointer);drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+return AE_CTRL_TERMINATE ; +} + +static void btintel_send_sar_ddc (struct hci_dev *hdev,void *data,u8 +len) { +struct sk_buff *skb; + + skb =__hci_cmd_sync (hdev,0xfc8b , len, data,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { + bt_dev_warn(hdev, "Failed to send Intel Write SAR DDC (%ld)",
PTR_ERR(skb));
Quoted 16 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2341
Quoted 12 lines
drivers/bluetooth/btintel.c +12
-0+return ; + } +kfree_skb (skb); +} + +static int btintel_set_legacy_sar (struct hci_dev *hdev,struct +btintel_sar *sar) { +struct btintel_cp_ddc_write *cmd; +u8 buffer[64 ]; + +if (!sar) +return -EINVAL ;Add a memset to 0 as this may trigger uninitialized errors in the likes of static analyzers.
Ack.
Quoted 11 lines
drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2348
Quoted 6 lines
drivers/bluetooth/btintel.c +6
-0+ cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0131 ); + cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 );We should probably handle the errors when sending these commands and don't continue, also perhaps it would be better to have each command in its own function with a proper name indicating what it is doing.
The command structure is same for all the commands. To address one of Paul's comment, need to define marcos for command id. Let me know if this is OK.
Quoted 183 lines
Quoted 46 lines
drivers/bluetooth/btintel.c +46
-0+ + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x0132 ); + cmd->data[0 ] = sar->br >>3 ; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0137 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x0138 ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013b ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + + cmd->len =5 ; + cmd->id =cpu_to_le16 (0x013c ); + cmd->data[0 ] = sar->br >>3 ; + cmd->data[1 ] = sar->edr2 >>3 ; + cmd->data[2 ] = sar->edr3 >>3 ; +btintel_send_sar_ddc (hdev, cmd,6 ); + +return 0 ; +} + +static int btintel_set_mutual_sar (struct hci_dev *hdev,struct +btintel_sar *sar) { +u8 buffer[64 ]; +struct btintel_cp_ddc_write *cmd; +u8 enable[1 ] = {1 }; +struct sk_buff *skb; + +if (!sar) +return -EINVAL ;drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev) · line 2404
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+ + cmd = (void *)buffer; + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019e ); +if (!(sar->le_2mhz &BIT (7 ))) + cmd->data[0 ] =0x01 ; +else + cmd->data[0 ] =0x00 ; +btintel_send_sar_ddc (hdev, cmd,4 );Ditto as above.
Quoted 18 lines
drivers/bluetooth/btintel.c +18
-0+ cmd->len =3 ; + cmd->id =cpu_to_le16 (0x019f ); + cmd->data[0 ] = sar->le_lr; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a0 ); + cmd->data[0 ] = sar->br; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a1 ); + cmd->data[0 ] = sar->edr2; +btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a2 ); + cmd->data[0 ] = sar->edr3;drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+btintel_send_sar_ddc (hdev, cmd,4 ); + + cmd->len =3 ; + cmd->id =cpu_to_le16 (0x01a3 ); + cmd->data[0 ] = sar->le; +btintel_send_sar_ddc (hdev, cmd,4 ); + + skb =__hci_cmd_sync (hdev,0xfe25 ,1 , enable,HCI_CMD_TIMEOUT ); +if (IS_ERR (skb)) { + bt_dev_warn(hdev, "Failed to send Intel SAR Enable (%ld)",
PTR_ERR(skb));Quoted 13 lines
drivers/bluetooth/btintel.c +13
-0+return PTR_ERR (skb); + } +kfree_skb (skb); + +return 0 ; +} + +static int btintel_set_specific_absorption_rate (struct hci_dev *hdev, +struct +intel_version_tlv *ver) { +acpi_status status; +struct btintel_sar sar; +drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+switch (ver->cnvr_top &0xfff ) { +case 0x810 :/* MsP */ +break ; +default : +return 0 ; + } + +memset (&sar,0 ,sizeof (sar)); + + status = acpi_walk_namespace(ACPI_TYPE_METHOD,
ACPI_ROOT_OBJECT,Quoted 7 lines
drivers/bluetooth/btintel.c +7
-0+ACPI_UINT32_MAX ,NULL , + btintel_sar_callback, &sar, + NULL); + +if (ACPI_FAILURE (status)) +return -1 ; +drivers/bluetooth/btintel.c static int btintel_configure_offload(struct hci_dev *hdev)
Quoted 10 lines
drivers/bluetooth/btintel.c +10
-0+if (sar.domain !=0x12 ) +return -1 ; + +/* No need to configure controller if Bluetooth SAR is disabled in BIOS +*/ +if (!sar.type) +return 0 ; + +if (sar.type ==1 ) { + bt_dev_info(hdev, "Applying both legacy and mutual BluetoothSAR");
Quoted 28 lines
drivers/bluetooth/btintel.c +6
-0+btintel_set_legacy_sar (hdev, &sar); +btintel_set_mutual_sar (hdev, &sar); + } +return 0 ; +} +static int btintel_bootloader_setup_tlv (struct hci_dev *hdev,struct intel_version_tlv *ver){ @@ -2294,6 +2520,9 @@ static int btintel_bootloader_setup_tlv(struct
hci_dev*hdev,/* Read supported use cases and set callbacks to fetch datapath id */ btintel_configure_offload(hdev);drivers/bluetooth/btintel.c +3
-0+/* Set Specific Absorption Rate */ +btintel_set_specific_absorption_rate (hdev, ver); +hci_dev_clear_flag (hdev,HCI_QUALITY_REPORT );/* Read the Intel version information after loading the FW */ drivers/bluetooth/btintel.h +1
-0@@ -137,6 +137,24 @@ struct intel_offload_use_cases {__u8 preset[8 ]; } __packed; +/* structure to store the data read from ACPI table */ structdrivers/bluetooth/btintel.h struct intel_offload_use_cases { · line 150
Quoted 10 lines
drivers/bluetooth/btintel.h +10
-0+btintel_sar { +u8 domain; +u8 type; +u32 br; +u32 edr2; +u32 edr3; +u32 le; +u32 le_2mhz; +u32 le_lr; +};The above should also be using
__packed, also for data packets the multibyte field shall tell what is the expected endianness so given the id below is using__le16I assume the fields above shall be__le32.Quoted 10 lines
drivers/bluetooth/btintel.h +6
-0+struct btintel_cp_ddc_write { +u8 len; +__le16 id; +u8 data[0 ]; +} __packed; +#define INTEL_HW_PLATFORM (cnvx_bt) ((u8)(((cnvx_bt) & 0x0000ff00) > 8))#define INTEL_HW_VARIANT (cnvx_bt) ((u8)(((cnvx_bt) & 0x003f0000)Quoted 1 line
16))
Quoted 8 lines
Quoted 4 lines
#define
INTEL_CNVX_TOP_TYPE(cnvx_top)((cnvx_top) &0x00000fff)
--
2.17.1--
Luiz Augusto von Dentz
Thanks,
Kiran