Bluetooth: btintel_pcie: Add yoyo support for config set TLV
Subsystems (2)
PATCH 1/3 Bluetooth: btintel_pcie: Add yoyo support for config set TLV
From: Ajaykv <[email protected]>
Add parsing of the YoYo CONFIG_SET TLV so that debug register configuration can be supplied through the external TLV file. Each CONFIG_SET TLV is validated, and its address/value pairs are stored in the config set list of the YoYo context.
At the configured timepoint, the stored pairs are written to the target memory region, with or without target access depending on the region type. Write failures are logged and do not stop normal Bluetooth bring-up. The stored pairs are freed when the device is removed.
--- drivers/bluetooth/btintel_pcie.c | 142 +++++++++++++++++++++++-- drivers/bluetooth/btintel_pcie.h | 1 + drivers/bluetooth/btintel_pcie_debug.c | 113 ++++++++++++++++++-- drivers/bluetooth/btintel_pcie_debug.h | 76 ++++++++++++- 4 files changed, 313 insertions(+), 19 deletions(-)
drivers/bluetooth/btintel_pcie.c +135 -7
@@ -927,6 +927,133 @@ static void btintel_pcie_release_mac_access(struct btintel_pcie_data *data) } } +static void +btintel_pcie_apply_yoyo_config_sets (struct btintel_pcie_data *data, +u32 time_point) +{ +struct btintel_pcie_yoyo_config_set *config_set; +resource_size_t bar0_len; +int ret; +u32 i; + +if (!data) +return ; + +/* Get the length of PCI BAR0 */ + bar0_len =pci_resource_len (data->pdev,0 ); + +if (!data->yoyo.enabled) +return ; + +list_for_each_entry (config_set, &data->yoyo.config_set_list, list) { +u32 pair_addr, addr, value; + +if (config_set->time_point != time_point) +continue ; + +switch (config_set->config_set_type) { +case BTINTEL_PCIE_CFGSET_CSR : +case BTINTEL_PCIE_CFGSET_PERIPH_MAC : +case BTINTEL_PCIE_CFGSET_DEVICE_MEM : +break ; +default : +BT_WARN ("YoYo: unknown/unsupported config_set type %u, skipping" , + config_set->config_set_type); +continue ; + } + +if (config_set->config_set_type ==BTINTEL_PCIE_CFGSET_PERIPH_MAC || + config_set->config_set_type ==BTINTEL_PCIE_CFGSET_DEVICE_MEM ) { + ret =btintel_pcie_get_mac_access (data); +if (ret) { +BT_WARN ("YoYo: MAC access failed for config set (%d), skipping" , + ret); +/* get_mac_access() asserts MAC_ACCESS_REQ before it +* polls, and leaves it set on timeout; drop it so the +* request bit is not leaked. +*/ +btintel_pcie_release_mac_access (data); +continue ; + } + } + +for (i =0 ; i < config_set->num_pairs; i++) { + pair_addr =get_unaligned_le32 (&config_set->pairs[i].address); + +/* Calculate the effective address by adding the address offset */ +if (check_add_overflow (pair_addr, config_set->addr_offset, &addr)) { +BT_WARN ("YoYo: config set address overflow (0x%08x + 0x%08x)" , + pair_addr, config_set->addr_offset); +continue ; + } + + value =get_unaligned_le32 (&config_set->pairs[i].value); + +switch (config_set->config_set_type) { +/* Direct Address Access (CSR) */ +case BTINTEL_PCIE_CFGSET_CSR : +/* Validate the effective address for CSR access (Direct Address) +* addr not aligned to 4 bytes or exceeds the BAR0 length +*/ +if ((addr & (sizeof (u32) -1 )) || + bar0_len <sizeof (u32) || + addr > bar0_len -sizeof (u32)) { +BT_WARN ("YoYo: bad CSR address 0x%08x for BAR0 length %llu" , + addr, (unsigned long long )bar0_len); +continue ; + } + +BT_DBG ("YoYo: CSR write [0x%08x] = 0x%08x" , addr, value); +btintel_pcie_wr_reg32 (data, addr, value); +break ; +/* Indirect Address Access (Peripheral MAC and Device Memory) */ +case BTINTEL_PCIE_CFGSET_PERIPH_MAC : +case BTINTEL_PCIE_CFGSET_DEVICE_MEM : +/* Validate the effective address for peripheral MAC and device +* memory access: addr not aligned to 4 bytes +*/ +if (!addr || (addr & (sizeof (u32) -1 ))) { +BT_WARN ("YoYo: bad indirect address 0x%08x for type %u" , + addr, config_set->config_set_type); +continue ; + } + +btintel_pcie_wr_reg32 (data, +BTINTEL_PCIE_PRPH_DEV_ADDR_REG , + addr); +btintel_pcie_wr_reg32 (data, +BTINTEL_PCIE_PRPH_DEV_WR_REG , + value); +BT_DBG ("YoYo: indirect write type %u addr 0x%08x value 0x%08x" , + config_set->config_set_type, addr, value); +break ; +default : +BT_WARN ("YoYo: unknown config_set type %u" , + config_set->config_set_type); +break ; + } + } + +if (config_set->config_set_type ==BTINTEL_PCIE_CFGSET_PERIPH_MAC || + config_set->config_set_type ==BTINTEL_PCIE_CFGSET_DEVICE_MEM ) +btintel_pcie_release_mac_access (data); + } +} + +static void btintel_pcie_yoyo_handle_timepoint (struct btintel_pcie_data *data, +enum btintel_pcie_dbg_timepoint tp) +{ +if (!data || !data->yoyo.enabled) +return ; + +if (tp <=BTINTEL_PCIE_TP_INVALID || tp >=BTINTEL_PCIE_TP_MAX_NUM ) { +BT_WARN ("YoYo: invalid timepoint %u" , tp); +return ; + } + +btintel_pcie_apply_yoyo_config_sets (data, tp); +} +static struct scatterlist *btintel_pcie_alloc_sgtable (ssize_t size) {int nents;
@@ -1617,6 +1744,9 @@ static int btintel_pcie_enable_bt(struct btintel_pcie_data *data)BT_INFO ("%s: Mac Init: Wait on Alive Interrupt" ,btintel_pcie_dev_name (data)); +/* EARLY Timepoint Handler */ +btintel_pcie_yoyo_handle_timepoint (data,BTINTEL_PCIE_TP_EARLY ); +btintel_pcie_set_reg_bits (data,BTINTEL_PCIE_CSR_FUNC_CTRL_REG ,BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_INIT );
@@ -4751,7 +4881,8 @@ static int btintel_pcie_probe(struct pci_dev *pdev,if (data->enable_ini) { err =btintel_pcie_yoyo_load_and_parse (&data->yoyo, &pdev->dev);if (err) { -BT_WARN ("YoYo is not configured (%d)" , err); +BT_WARN ("YoYo (BDF - %s): yoyo is not configured (%d)" , +pci_name (pdev), err);btintel_pcie_yoyo_cleanup (&data->yoyo); } }
@@ -4830,12 +4961,6 @@ static void btintel_pcie_remove(struct pci_dev *pdev)if (current_work () != &data->reset_work)disable_work_sync (&data->reset_work); -btintel_pcie_mask_hw_rfkill (data); -btintel_pcie_synchronize_irqs (data); -disable_delayed_work_sync (&data->hw_rfkill_work); - -btintel_pcie_yoyo_cleanup (&data->yoyo); -btintel_pcie_disable_interrupts (data);btintel_pcie_synchronize_irqs (data);
@@ -4854,6 +4979,9 @@ static void btintel_pcie_remove(struct pci_dev *pdev)btintel_pcie_release_hdev (data); +/* Cleanup YoYo debug framework */ +btintel_pcie_yoyo_cleanup (&data->yoyo); +destroy_workqueue (data->dump_workqueue);destroy_workqueue (data->workqueue);
drivers/bluetooth/btintel_pcie.h +1 -0
@@ -27,6 +27,7 @@#define BTINTEL_PCIE_CSR_MBOX_4_REG (BTINTEL_PCIE_CSR_BASE + 0x17C)#define BTINTEL_PCIE_CSR_MBOX_STATUS_REG (BTINTEL_PCIE_CSR_BASE + 0x180)#define BTINTEL_PCIE_PRPH_DEV_ADDR_REG (BTINTEL_PCIE_CSR_BASE + 0x440) +#define BTINTEL_PCIE_PRPH_DEV_WR_REG (BTINTEL_PCIE_CSR_BASE + 0x454)#define BTINTEL_PCIE_PRPH_DEV_RD_REG (BTINTEL_PCIE_CSR_BASE + 0x458)#define BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR (BTINTEL_PCIE_CSR_BASE + 0x460)
drivers/bluetooth/btintel_pcie_debug.c +105 -8
172 lines not on this page · raw message
drivers/bluetooth/btintel_pcie_debug.h +72 -4
115 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 2/3 Bluetooth: btintel_pcie: Add yoyo configuration for debug region
From: Ajaykv <[email protected]>
Add parsing of the YoYo DEBUG_REGION TLV. A region TLV defines a named, addressable debug region and registers it by region ID; it does not trigger a dump by itself. A later trigger TLV selects regions through a 64-bit region ID mask, and the dump for each selected region is dispatched based on its stored region type.
Each region TLV is validated for domain, version, region ID, region type, address list and size. Invalid entries are skipped with a warning. Valid regions are stored in the region list of the YoYo context, replacing any existing entry with the same region ID, and are freed when the YoYo context is cleaned up.
--- drivers/bluetooth/btintel_pcie_debug.c | 144 +++++++++++++++++++++++++ drivers/bluetooth/btintel_pcie_debug.h | 133 +++++++++++++++++++++++ 2 files changed, 277 insertions(+)
drivers/bluetooth/btintel_pcie_debug.c +144 -0
@@ -503,6 +503,140 @@ static int btintel_pcie_yoyo_parse_config_set(struct btintel_pcie_yoyo_ctx *ctx,return 0 ; } +static int btintel_pcie_yoyo_parse_region (struct btintel_pcie_yoyo_ctx *ctx, +const struct btintel_pcie_tlv_region *tlv, +u32 len) +{ +struct btintel_pcie_yoyo_region *old_region, *region, *tmp; +u32 addr_count =0 , addr_offset =0 , domain, version; +u32 addr_bytes, alloc_id, size; +u16 region_id; + +if (len <sizeof (*tlv) -sizeof (struct btintel_pcie_tlv_hdr )) { +BT_WARN ("YoYo: region tlv is too short or Invalid" ); +return -EBADMSG ; + } + + domain =get_unaligned_le32 (&tlv->dbg_hdr.domain); + version =get_unaligned_le32 (&tlv->dbg_hdr.tlv_data_version); +if (domain !=BTINTEL_PCIE_DOMAIN_BT || + version !=BTINTEL_PCIE_REGION_TLV_VERSION ) { +BT_WARN ("YoYo: unsupported region domain/version (%u/%u), skipping" , + domain, version); +return 0 ; + } + + region_id =get_unaligned_le16 (&tlv->region_id); +if (region_id >BTINTEL_PCIE_REGION_ID_MAX ) { +BT_WARN ("YoYo: invalid region_id %u, skipping" , region_id); +return 0 ; + } + +if (tlv->region_type <=BTINTEL_PCIE_REGION_INVALID || + tlv->region_type >=BTINTEL_PCIE_REGION_TYPE_MAX ) { +BT_WARN ("YoYo: invalid region type %u, skipping" , tlv->region_type); +return 0 ; + } + +/* Any trailing bytes after the fixed region structure are an address +* list, regardless of region type, mirroring the reference parser. +*/ + addr_offset =sizeof (*tlv) -sizeof (struct btintel_pcie_tlv_hdr ); + addr_bytes = len - addr_offset; +if (addr_bytes %sizeof (__le32)) { +BT_WARN ("YoYo: invalid region addr_bytes length %u" , addr_bytes); +return 0 ; + } + + addr_count = addr_bytes /sizeof (__le32); + +/* Types without a size field default to a valid dword size. */ + size =sizeof (u32); +switch (tlv->region_type) { +case BTINTEL_PCIE_REGION_DEVICE_MEM : + size =get_unaligned_le32 (&tlv->conf_params.dev_addr.size_bytes); + fallthrough; +case BTINTEL_PCIE_REGION_PERIPH_MAC : +case BTINTEL_PCIE_REGION_CSR : +if (!addr_count) { +BT_WARN ("YoYo: region id=%u type=%u has no addresses, skipping" , + region_id, tlv->region_type); +return 0 ; + } +break ; +case BTINTEL_PCIE_REGION_DRAM_BUF : + alloc_id =get_unaligned_le32 (&tlv->conf_params.dram_alloc_id); +if (alloc_id <BTINTEL_PCIE_ALLOC_ID_DBGC1 || + alloc_id >BTINTEL_PCIE_ALLOC_ID_DBGC3 ) { +BT_WARN ("YoYo: region id=%u invalid dram alloc id %u, skipping" , + region_id, alloc_id); +return 0 ; + } +break ; +case BTINTEL_PCIE_REGION_INTERNAL_BUF : + size =get_unaligned_le32 (&tlv->conf_params.internal_buf.size_bytes); +break ; +case BTINTEL_PCIE_REGION_SPECIAL_DEV_MEM : + size =get_unaligned_le32 (&tlv->conf_params.special_dev_addr.size_bytes); +break ; +default : +break ; + } + +if (!size || size %sizeof (u32)) { +BT_WARN ("YoYo: region id=%u type=%u invalid size %u, skipping" , + region_id, tlv->region_type, size); +return 0 ; + } + + region =kzalloc (sizeof (*region),GFP_KERNEL ); +if (!region) +return -ENOMEM ; + + region->region_id = region_id; + region->dump_policy =get_unaligned_le16 (&tlv->region_dump_policy); + region->type = tlv->region_type; + region->sub_type = tlv->region_sub_type; + region->sub_type_ver = tlv->region_sub_type_ver; +memcpy (region->name, tlv->region_name,BTINTEL_PCIE_REGION_NAME_LEN ); +memcpy (®ion->conf, &tlv->conf_params,sizeof (region->conf)); + +if (addr_count) { +const u8 *addr_data = (const u8 *)tlv + +sizeof (struct btintel_pcie_tlv_hdr ) + addr_offset; +u32 i; + + region->addrs =kmalloc_array (addr_count,sizeof (*region->addrs), +GFP_KERNEL ); +if (!region->addrs) { +kfree (region); +return -ENOMEM ; + } + +for (i =0 ; i < addr_count; i++) + region->addrs[i] =get_unaligned_le32 (addr_data + + i *sizeof (__le32)); + } + region->num_addrs = addr_count; + +/* Swap into list if duplicate region_id exists, otherwise append */ +list_for_each_entry_safe (old_region, tmp, &ctx->region_list, list) { +if (old_region->region_id == region_id) { +list_replace (&old_region->list, ®ion->list); +kfree (old_region->addrs); +kfree (old_region); + goto out; + } + } + +list_add_tail (®ion->list, &ctx->region_list); + +out: +BT_DBG ("YoYo: region id=%u type=%u name='%.32s'" , + region->region_id, region->type, region->name); +return 0 ; +} +/* * Parse the optional YoYo firmware TLV stream and validate each record. * This is the entry point for the runtime debug configuration payload.
@@ -547,6 +681,8 @@ static int btintel_pcie_yoyo_parse_tlv_buffer(struct btintel_pcie_yoyo_ctx *ctx, ret =btintel_pcie_yoyo_parse_config_set (ctx, (const void *)tlv, len);break ;case BTINTEL_PCIE_TLV_TYPE_DBG_REGION : + ret =btintel_pcie_yoyo_parse_region (ctx, (const void *)tlv, len); +break ;case BTINTEL_PCIE_TLV_TYPE_DBG_TRIGGER :case BTINTEL_PCIE_TLV_TYPE_DBG_HCMD :case BTINTEL_PCIE_TLV_TYPE_DBG_PRESET_OVERRIDE :
@@ -611,6 +747,7 @@ EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_init);void btintel_pcie_yoyo_cleanup (struct btintel_pcie_yoyo_ctx *ctx) {struct btintel_pcie_yoyo_config_set *config_set, *config_tmp; +struct btintel_pcie_yoyo_region *region, *region_tmp;if (!ctx)return ;
@@ -627,6 +764,13 @@ void btintel_pcie_yoyo_cleanup(struct btintel_pcie_yoyo_ctx *ctx)kfree (config_set->pairs);kfree (config_set); } + +list_for_each_entry_safe (region, region_tmp, &ctx->region_list, list) { +list_del (®ion->list); +kfree (region->addrs); +kfree (region); + } + }EXPORT_SYMBOL_GPL (btintel_pcie_yoyo_cleanup);
drivers/bluetooth/btintel_pcie_debug.h +133 -0
163 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 3/3 Bluetooth: btintel_pcie: Add yoyo configuration for Hci cmd Tlvs
In reply to Ajay KVFrom: Ajaykv <[email protected]>
Add parsing of the YoYo HCI command TLV so that HCI commands can be sent to the controller through the external TLV file. Each TLV is validated for domain, version, timepoint and command length. Only the ALIVE timepoint is supported, and periodic commands are skipped with a warning. Valid commands are stored in the HCI command list of the YoYo context and are freed when the YoYo context is cleaned up.
When the ALIVE timepoint is reached after setup, the stored commands are sent in order. A command is skipped if its parameter length does not match the TLV payload. Sending stops if the device is halted, in recovery, in D3 or unregistering, or if a command fails because of a timeout or a lost device. Other command failures are logged and do not stop normal Bluetooth bring-up.
--- drivers/bluetooth/btintel_pcie.c | 96 ++++++++++++++++++++++++++ drivers/bluetooth/btintel_pcie_debug.c | 75 +++++++++++++++++++- drivers/bluetooth/btintel_pcie_debug.h | 46 ++++++++++-- 3 files changed, 212 insertions(+), 5 deletions(-)
drivers/bluetooth/btintel_pcie.c +96 -0
@@ -657,6 +657,8 @@ static inline void btintel_pcie_dump_debug_registers(struct hci_dev *hdev)hci_recv_diag (hdev, skb); } +static inline bool btintel_pcie_in_d3 (struct btintel_pcie_data *data); +static int btintel_pcie_send_sync (struct btintel_pcie_data *data,struct sk_buff *skb,u32 pkt_type,u16 opcode) {
@@ -927,6 +929,90 @@ static void btintel_pcie_release_mac_access(struct btintel_pcie_data *data) } } +/* btintel_yoyo_send_hcmds - Send all HCMDs configured for a timepoint */ +static void btintel_pcie_yoyo_send_hcmds (struct btintel_pcie_data *data, +enum btintel_pcie_dbg_timepoint tp) +{ +struct btintel_pcie_yoyo_hcmd *hcmd; +struct sk_buff *skb; +u8 plen; +u16 opcode; + +if (!data) +return ; + +/* Held across __hci_cmd_sync() so cleanup cannot free entries in use */ +mutex_lock (&data->yoyo.lock); +if (!data->yoyo.enabled || !data->hdev) { +mutex_unlock (&data->yoyo.lock); +return ; + } + +list_for_each_entry (hcmd, &data->yoyo.hcmd_list, list) { +long err; + +if (hcmd->time_point != tp) +continue ; + +/* Stop if device state changed or driver is shutting down */ +if (test_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags) || +test_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , &data->flags) || +btintel_pcie_in_d3 (data) || +hci_dev_test_flag (data->hdev,HCI_UNREGISTER )) +break ; + +if (hcmd->cmd_len <3 ) { +bt_dev_warn (data->hdev,"YoYo: hci command too short (%u bytes)" , + hcmd->cmd_len); +continue ; + } + + opcode =get_unaligned_le16 (hcmd->cmd_data); + plen = hcmd->cmd_data[2 ]; + +if (plen != hcmd->cmd_len -3 ) { +bt_dev_warn (data->hdev, +"YoYo: hci command 0x%04x plen %u does not match tlv payload %u" , + opcode, plen, hcmd->cmd_len -3 ); +continue ; + } + +bt_dev_dbg (data->hdev,"YoYo: sending hci command, opcode=0x%04x len=%u at tp=%u" , + opcode, plen, tp); + + skb =__hci_cmd_sync (data->hdev, opcode, plen, + hcmd->cmd_data +3 , +HCI_CMD_TIMEOUT ); +/* HCI Err 0x11 corresponds to errno -95 (UNSUPPORTED) +* HCI Err 0x12 corresponds to errno -22 (INVAL) +* HCI Err 0x16 corresponds to errno -16 (EBUSY/CMD DISALLOWED) +*/ +if (IS_ERR (skb)) { + err =PTR_ERR (skb); + +/* Command completed with Command Status (0x0F) */ +if (err == -ENODATA ) +continue ; + +bt_dev_dbg (data->hdev,"YoYo: hci command 0x%04x failed: %ld" , + opcode, err); +/* A timeout already made the HCI core run hdev->reset +* and start device recovery; stop issuing debug +* commands instead of adding more timeouts to it. +*/ +if (err == -ETIMEDOUT || err == -ENODEV || + err == -EHOSTDOWN || err == -EINTR ) +break ; + }else { +bt_dev_dbg (data->hdev,"YoYo: hci command 0x%04x completed successfully" , + opcode); +kfree_skb (skb); + } + } + +mutex_unlock (&data->yoyo.lock); +} +static void btintel_pcie_apply_yoyo_config_sets (struct btintel_pcie_data *data,u32 time_point)
@@ -1046,11 +1132,16 @@ static void btintel_pcie_yoyo_handle_timepoint(struct btintel_pcie_data *data,if (!data || !data->yoyo.enabled)return ; +BT_DBG ("YoYo: Handling timepoint %u" , tp); +if (tp <=BTINTEL_PCIE_TP_INVALID || tp >=BTINTEL_PCIE_TP_MAX_NUM ) {BT_WARN ("YoYo: invalid timepoint %u" , tp);return ; } +/* PRE-DUMP phase: send HCMDs and apply config sets */ +btintel_pcie_yoyo_send_hcmds (data, tp); +btintel_pcie_apply_yoyo_config_sets (data, tp); }
@@ -4265,9 +4356,14 @@ static int btintel_pcie_setup(struct hci_dev *hdev)if (btintel_pcie_fatal_err_testmode_active (data))set_bit (BTINTEL_PCIE_FATAL_ERR_POST_SETUP_PENDING , &data->flags);set_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags); +set_bit (BTINTEL_PCIE_HW_RFKILL_STATE_CHECK , &data->flags);btintel_pcie_unmask_hw_rfkill (data);btintel_delayed_hw_rfkill (data, true); + +/* Notify YoYo: device is alive and operational */ +btintel_pcie_yoyo_handle_timepoint (data, +BTINTEL_PCIE_TP_AFTER_ALIVE ); }return err; }
drivers/bluetooth/btintel_pcie_debug.c +74 -1
110 lines not on this page · raw message
drivers/bluetooth/btintel_pcie_debug.h +42 -4
88 lines not on this page · raw message
Signature · 1 line
2.53.0