mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 1/3] Bluetooth: btintel_pcie: Add yoyo configuration for trigger tlv
@ 2026-12-02 10:04 Ajay KV
  2026-12-02 10:04 ` [PATCH v1 2/3] Bluetooth: btintel_pcie: Collect dump regions from yoyo region TLVs Ajay KV
  2026-12-02 10:04 ` [PATCH v1 3/3] Bluetooth: btintel_pcie: Dispatch yoyo triggers at timepoints Ajay KV
  0 siblings, 2 replies; 3+ messages in thread
From: Ajay KV @ 2026-12-02 10:04 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: chandrashekar.devegowda, kiran.k, linux-kernel, luiz.dentz,
	marcel, stable, chethan.tumkur.narayan, lakshmipathi.k, Ajay KV

This patch enables TLV-based debug configuration for Trigger TLV
Type.

A Trigger TLV binds a timepoint to a 64-bit bitmask of debug region
IDs. It collects nothing by itself: it records which regions a dump
should contain when the matching timepoint is reached. Looking the
trigger up and acting on its region mask is done by a later patch.

Only the timepoint, trigger reason, and region mask are kept at
runtime. The on-disk structure still declares every field, because
it defines the wire layout and drives the fixed-size length check.
Occurrence limit, ignore consecutive duration, delayed dumping,
stop dump limit, trigger policy mask and firmware reset mode are
not supported in phase 1.

A duplicate timepoint replaces the earlier entry, since lookup returns
the first match and a later entry would otherwise sit unreachable
behind it. A domain or version mismatch skips the record and keeps
parsing the rest of the file.

This patch contains :
 - Handling of TLV parser/validation for Trigger TLV.
 - Add configuration into trigger list in yoyo context
 - Look up the trigger configured for a timepoint

Signed-off-by: Ajay KV <ajay.k.v@intel.com>
---
 drivers/bluetooth/btintel_pcie_debug.c | 98 ++++++++++++++++++++++++++
 drivers/bluetooth/btintel_pcie_debug.h | 51 +++++++++++++-
 2 files changed, 148 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btintel_pcie_debug.c b/drivers/bluetooth/btintel_pcie_debug.c
index fb18e18c0b76..9dc380ec9c6b 100644
--- a/drivers/bluetooth/btintel_pcie_debug.c
+++ b/drivers/bluetooth/btintel_pcie_debug.c
@@ -702,6 +702,67 @@ static int btintel_pcie_yoyo_parse_hcmd(struct btintel_pcie_yoyo_ctx *ctx,
 	return 0;
 }
 
+static int btintel_pcie_yoyo_parse_trigger(struct btintel_pcie_yoyo_ctx *ctx,
+					   const struct btintel_pcie_tlv_trigger *tlv,
+					   u32 len)
+{
+	u32 fixed_size = sizeof(*tlv) - sizeof(struct btintel_pcie_tlv_hdr);
+	struct btintel_pcie_yoyo_trigger *old_trigger, *trigger;
+	u32 domain, time_point, version;
+
+	if (len < fixed_size) {
+		BT_WARN("YoYo: trigger 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_TRIGGER_TLV_VERSION) {
+		BT_WARN("YoYo: unsupported trigger domain/version (%u/%u), skipping",
+			domain, version);
+		return 0;
+	}
+
+	time_point = get_unaligned_le32(&tlv->time_point);
+	if (time_point <= BTINTEL_PCIE_TP_INVALID ||
+	    time_point >= BTINTEL_PCIE_TP_MAX_NUM) {
+		BT_WARN("YoYo: invalid trigger timepoint %u, skipping",
+			time_point);
+		return 0;
+	}
+
+	trigger = kzalloc_obj(*trigger, GFP_KERNEL);
+	if (!trigger)
+		return -ENOMEM;
+
+	/* Phase 1 consumes only the timepoint, trigger_reason, and the region
+	 * mask. Remaining TLV fields stay unparsed.
+	 */
+	trigger->time_point = time_point;
+	trigger->trigger_reason = get_unaligned_le32(&tlv->trigger_reason);
+	trigger->regions_mask[0] = get_unaligned_le32(&tlv->regions_list_mask[0]);
+	trigger->regions_mask[1] = get_unaligned_le32(&tlv->regions_list_mask[1]);
+
+	BT_DBG("YoYo: trigger tp=%u reason=%u regions=0x%08x%08x",
+	       trigger->time_point, trigger->trigger_reason,
+	       trigger->regions_mask[1], trigger->regions_mask[0]);
+
+	/* Lookup returns the first match, so a later duplicate must replace
+	 * the earlier entry rather than sit unreachable behind it.
+	 */
+	list_for_each_entry(old_trigger, &ctx->trigger_list, list) {
+		if (old_trigger->time_point == time_point) {
+			list_replace(&old_trigger->list, &trigger->list);
+			kfree(old_trigger);
+			return 0;
+		}
+	}
+
+	list_add_tail(&trigger->list, &ctx->trigger_list);
+	return 0;
+}
+
 /*
  * Parse the optional YoYo firmware TLV stream and validate each record.
  * This is the entry point for the runtime debug configuration payload.
@@ -752,6 +813,8 @@ static int btintel_pcie_yoyo_parse_tlv_buffer(struct btintel_pcie_yoyo_ctx *ctx,
 			ret = btintel_pcie_yoyo_parse_hcmd(ctx, (const void *)tlv, len);
 			break;
 		case BTINTEL_PCIE_TLV_TYPE_DBG_TRIGGER:
+			ret = btintel_pcie_yoyo_parse_trigger(ctx, (const void *)tlv, len);
+			break;
 		case BTINTEL_PCIE_TLV_TYPE_DBG_PRESET_OVERRIDE:
 			BT_DBG("YoYo: valid tlv type 0x%x len=%u", type, len);
 			break;
@@ -811,6 +874,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_trigger *trigger, *trigger_tmp;
 	struct btintel_pcie_yoyo_region *region, *region_tmp;
 	struct btintel_pcie_yoyo_hcmd *hcmd, *hcmd_tmp;
 
@@ -842,6 +906,12 @@ void btintel_pcie_yoyo_cleanup(struct btintel_pcie_yoyo_ctx *ctx)
 		kfree(hcmd->cmd_data);
 		kfree(hcmd);
 	}
+
+	list_for_each_entry_safe(trigger, trigger_tmp, &ctx->trigger_list, list) {
+		list_del(&trigger->list);
+		kfree(trigger);
+	}
+
 	mutex_unlock(&ctx->lock);
 }
 EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_cleanup);
@@ -903,6 +973,34 @@ int btintel_pcie_yoyo_load_and_parse(struct btintel_pcie_yoyo_ctx *ctx,
 }
 EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_load_and_parse);
 
+/**
+ * btintel_pcie_yoyo_find_trigger - Look up the trigger configured for a timepoint
+ * @ctx: YoYo context holding the parsed trigger list
+ * @tp: timepoint to resolve
+ *
+ * Caller must hold @ctx->lock to serialize against btintel_pcie_yoyo_cleanup()
+ * and ensure the returned pointer remains valid during use.
+ *
+ * Return: the first matching trigger, or NULL when none is configured or YoYo
+ * is disabled.
+ */
+const struct btintel_pcie_yoyo_trigger *
+btintel_pcie_yoyo_find_trigger(struct btintel_pcie_yoyo_ctx *ctx,
+			       enum btintel_pcie_dbg_timepoint tp)
+{
+	struct btintel_pcie_yoyo_trigger *t;
+
+	if (!ctx || !ctx->enabled)
+		return NULL;
+
+	list_for_each_entry(t, &ctx->trigger_list, list) {
+		if (t->time_point == tp)
+			return t;
+	}
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_find_trigger);
+
 /**
  * btintel_pcie_yoyo_get_buf_alloc - Query buffer allocation config for a DBGC
  * @ctx: YoYo context
diff --git a/drivers/bluetooth/btintel_pcie_debug.h b/drivers/bluetooth/btintel_pcie_debug.h
index 6882895de18d..9d5ed7729fe8 100644
--- a/drivers/bluetooth/btintel_pcie_debug.h
+++ b/drivers/bluetooth/btintel_pcie_debug.h
@@ -63,6 +63,7 @@ bool btintel_pcie_fatal_err_testmode_active(struct btintel_pcie_data *data);
 #define BTINTEL_PCIE_CONFIG_SET_TLV_VERSION	1
 #define BTINTEL_PCIE_REGION_TLV_VERSION		3
 #define BTINTEL_PCIE_HCMD_TLV_VERSION		1
+#define BTINTEL_PCIE_TRIGGER_TLV_VERSION	1
 
 /* Debug Info TLV */
 #define BTINTEL_PCIE_CONFIG_NAME_LEN		64
@@ -76,6 +77,7 @@ bool btintel_pcie_fatal_err_testmode_active(struct btintel_pcie_data *data);
 /* Region Tlv */
 #define BTINTEL_PCIE_REGION_ID_MAX		63
 #define BTINTEL_PCIE_REGION_NAME_LEN		32
+#define BTINTEL_PCIE_REGION_LIST_SIZE		2
 
 enum btintel_pcie_image_tlv_type {
 	BTINTEL_PCIE_IMAGE_TLV_TYPE_EXTERNAL	= 0x1,
@@ -354,7 +356,42 @@ struct btintel_pcie_tlv_hcmd {
 	u8     cmd_data[];
 } __packed;
 
-/* Parsed buffer allocation entry in the YoYo context */
+/*
+ * struct btintel_pcie_tlv_trigger - YoYo debug trigger TLV
+ * @hdr: Common TLV type and payload length
+ * @dbg_hdr: Debug TLV version and domain
+ * @time_point: Timepoint at which to evaluate this trigger
+ * @trigger_reason: Reason code for the trigger
+ * @trigger_policy_mask: Policy flags controlling trigger matching and overrides
+ * @dump_delay_usec: Delay in microseconds before dump collection
+ * @occurrences_limit: Maximum number of times this trigger may fire
+ * @stop_dump_limit: Limit of dump collections before stopping
+ * @ignore_consec_usec: Minimum elapsed time in microseconds between firings
+ * @reset_fw_mode: Firmware reset mode after trigger
+ * @multi_dut_trigger: Multi-DUT trigger flag
+ * @regions_list_mask: Bitmask of debug region IDs to collect
+ * @data: Optional variable-length timepoint-specific trigger data
+ *
+ * Describes a debug trigger in the packed firmware TLV. Multi-byte fields
+ * are stored in little-endian format.
+ */
+struct btintel_pcie_tlv_trigger {
+	struct btintel_pcie_tlv_hdr hdr;
+	struct btintel_pcie_dbg_hdr dbg_hdr;
+	__le32 time_point;
+	__le32 trigger_reason;
+	__le32 trigger_policy_mask;
+	__le32 dump_delay_usec;
+	__le32 occurrences_limit;
+	__le32 stop_dump_limit;
+	__le32 ignore_consec_usec;
+	__le32 reset_fw_mode;
+	__le32 multi_dut_trigger;
+	__le32 regions_list_mask[BTINTEL_PCIE_REGION_LIST_SIZE];
+	__le32 data[];
+} __packed;
+
+/* Parsed buffer allocation entry in yoyo ctx */
 struct btintel_pcie_buf_alloc {
 	u32	alloc_id;
 	u32	buf_location;
@@ -397,6 +434,14 @@ struct btintel_pcie_yoyo_hcmd {
 	u8			*cmd_data;
 };
 
+/* Parsed trigger entry */
+struct btintel_pcie_yoyo_trigger {
+	struct list_head	list;
+	u32			time_point;
+	u32			trigger_reason;
+	u32			regions_mask[BTINTEL_PCIE_REGION_LIST_SIZE];
+};
+
 /*
  * struct btintel_pcie_yoyo_ctx - Runtime state for YoYo debug configuration
  * @enabled: Whether the loaded YoYo configuration passed validation
@@ -437,4 +482,8 @@ int  btintel_pcie_yoyo_load_and_parse(struct btintel_pcie_yoyo_ctx *ctx,
 const struct btintel_pcie_buf_alloc *
 btintel_pcie_yoyo_get_buf_alloc(struct btintel_pcie_yoyo_ctx *ctx, u32 alloc_id);
 
+const struct btintel_pcie_yoyo_trigger *
+btintel_pcie_yoyo_find_trigger(struct btintel_pcie_yoyo_ctx *ctx,
+			       enum btintel_pcie_dbg_timepoint tp);
+
 #endif /* __BTINTEL_PCIE_DEBUG_H__ */
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 2/3] Bluetooth: btintel_pcie: Collect dump regions from yoyo region TLVs
  2026-12-02 10:04 [PATCH v1 1/3] Bluetooth: btintel_pcie: Add yoyo configuration for trigger tlv Ajay KV
@ 2026-12-02 10:04 ` Ajay KV
  2026-12-02 10:04 ` [PATCH v1 3/3] Bluetooth: btintel_pcie: Dispatch yoyo triggers at timepoints Ajay KV
  1 sibling, 0 replies; 3+ messages in thread
From: Ajay KV @ 2026-12-02 10:04 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: chandrashekar.devegowda, kiran.k, linux-kernel, luiz.dentz,
	marcel, stable, chethan.tumkur.narayan, lakshmipathi.k, Ajay KV

The yoyo configuration declares the debug regions to collect through
Region TLVs, which are parsed and stored but not yet used by the
dump. With yoyo enabled, the coredump now collects those regions
instead of the built-in set.

Device memory regions are read through target access. DRAM regions
resolve their allocation ID to its DBGC buffers, copied once even
when several regions name the same allocation.

The built-in DRAM monitors are collected only when yoyo is disabled,
so a configuration declaring none collects no DBGC buffers, as on
Windows. A fixed region is skipped when a Region TLV claims its ID,
unless the dump path cannot emit that region type.

Region sizes from the file are capped so they cannot wrap the dump
allocation, and unaligned device memory regions are skipped.
Selecting regions by trigger follows in the next patch.

Signed-off-by: Ajay KV <ajay.k.v@intel.com>
---
 drivers/bluetooth/btintel_pcie.c       | 291 ++++++++++++++++++-------
 drivers/bluetooth/btintel_pcie.h       |  19 +-
 drivers/bluetooth/btintel_pcie_debug.c |  34 +++
 drivers/bluetooth/btintel_pcie_debug.h |  16 ++
 4 files changed, 269 insertions(+), 91 deletions(-)

diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c
index e033bfed589a..3d4ce6f1f1ba 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -1295,8 +1295,9 @@ btintel_pcie_dump_dram_monitor(struct btintel_pcie_data *data,
 		   "allocation=%u wr_ptr_status=0x%08x write_ptr=0x%06x cur_frag=%u wrap_ctr=0x%08x",
 		   allocation_id, wr_ptr_status, write_ptr, cur_frag, wrap_ctr);
 
-	return btintel_pcie_dump_dram(list, count, buf_size, bufs, write_ptr,
-				      wrap_ctr, cur_frag, region_id, name);
+	return btintel_pcie_dump_dram(list, count, buf_size, bufs,
+				      write_ptr, wrap_ctr, cur_frag, region_id,
+				      name);
 }
 
 static int btintel_pcie_dump_target_region(struct btintel_pcie_data *data,
@@ -1332,6 +1333,13 @@ static int btintel_pcie_dump_target_region(struct btintel_pcie_data *data,
 	}
 
 	/* Align to 4 bytes - target access reads 32-bit words */
+	if (!IS_ALIGNED(addr_start, sizeof(u32))) {
+		bt_dev_warn(data->hdev,
+			    "Skipping dump region %s: addr_start 0x%08x is not 4-byte aligned",
+			    name, addr_start);
+		return 1;
+	}
+
 	size = round_down(size, sizeof(u32));
 	if (!size) {
 		bt_dev_warn(data->hdev,
@@ -1444,6 +1452,9 @@ static int btintel_pcie_dump_smem_monitor_region(struct btintel_pcie_data *data,
 		dest += sizeof(tempdata);
 	}
 
+	bt_dev_dbg(data->hdev, "dumped smem region %u (%s) size=%u",
+		   region_id, name, size);
+
 	list_add_tail(&entry->list, list);
 	return 0;
 }
@@ -1550,50 +1561,157 @@ static bool btintel_pcie_is_mdbgc_supported(struct btintel_pcie_data *data)
 		data->pdev->device == BTINTEL_PCIE_DEVICE_ID_PTL_FMP2;
 }
 
+/* Built-in DRAM monitor regions, dumped only when yoyo is disabled. An
+ * enabled configuration declares the DRAM regions it wants, as on Windows.
+ */
+static const struct btintel_pcie_dram_monitor {
+	u32		alloc_id;
+	u32		region_id;
+	const char	*name;
+} dram_monitors[] = {
+	{ BTINTEL_PCIE_ALLOC_ID_DBGC1, BTINTEL_PCIE_INI_ID_DRAM_MONITOR1, "monitor" },
+	{ BTINTEL_PCIE_ALLOC_ID_DBGC2, BTINTEL_PCIE_INI_ID_DRAM_MONITOR2, "monitor2" },
+	{ BTINTEL_PCIE_ALLOC_ID_DBGC3, BTINTEL_PCIE_INI_ID_DRAM_MONITOR3, "monitor3" },
+};
+
+/* Resolves @alloc_id to its allocated DBGC buffers. Returns false when the ID
+ * is not one this SKU allocates.
+ */
+static bool btintel_pcie_get_dbgc_buf_set(struct btintel_pcie_data *data,
+					  u32 alloc_id,
+					  struct btintel_pcie_dbgc_buf_set *set)
+{
+	if (!btintel_pcie_is_mdbgc_supported(data)) {
+		if (alloc_id != BTINTEL_PCIE_ALLOC_ID_DBGC1)
+			return false;
+
+		set->bufs = data->dbgc.bufs;
+		set->count = data->dbgc.count;
+		set->buf_size = data->dbgc.buf_size;
+		set->allocation_id = BTINTEL_PCIE_MDBGC_ALLOCATIONID_1;
+		return true;
+	}
+
+	switch (alloc_id) {
+	case BTINTEL_PCIE_ALLOC_ID_DBGC1:
+		set->bufs = data->mdbgc.buf1;
+		set->count = data->mdbgc.buf1_count;
+		set->buf_size = data->mdbgc.buf1_size;
+		set->allocation_id = BTINTEL_PCIE_MDBGC_ALLOCATIONID_1;
+		return true;
+	case BTINTEL_PCIE_ALLOC_ID_DBGC2:
+		set->bufs = data->mdbgc.buf2;
+		set->count = data->mdbgc.buf2_count;
+		set->buf_size = data->mdbgc.buf2_size;
+		set->allocation_id = BTINTEL_PCIE_MDBGC_ALLOCATIONID_2;
+		return true;
+	case BTINTEL_PCIE_ALLOC_ID_DBGC3:
+		set->bufs = data->mdbgc.buf3;
+		set->count = data->mdbgc.buf3_count;
+		set->buf_size = data->mdbgc.buf3_size;
+		set->allocation_id = BTINTEL_PCIE_MDBGC_ALLOCATIONID_3;
+		return true;
+	default:
+		return false;
+	}
+}
+
 static void btintel_pcie_dump_mem_range(struct btintel_pcie_data *data,
 					struct list_head *list, u32 region_id,
 					const char *name, u32 addr_start,
 					u32 region_size, u64 *regions_mask)
 {
-	if (!region_size)
+	if (!region_size ||
+	    btintel_pcie_yoyo_region_configured(&data->yoyo, region_id)) {
 		return;
+	}
+
+	bt_dev_dbg(data->hdev, "dumping region %u (%s) size=%u",
+		   region_id, name, region_size);
 
 	if (!btintel_pcie_dump_target_region(data, list, region_id, name,
 					     addr_start, region_size))
 		*regions_mask |= BIT_ULL(region_id);
 }
 
+static int btintel_pcie_yoyo_dump_region(struct btintel_pcie_data *data,
+					 struct list_head *list,
+					 struct btintel_pcie_yoyo_region *region,
+					 u32 status_reg, u32 wrap_reg)
+{
+	char name[BTINTEL_PCIE_REGION_NAME_LEN + 1];
+	struct btintel_pcie_dbgc_buf_set set;
+	u32 addr_offset, addr_start, alloc_id, size;
+
+	memcpy(name, region->name, BTINTEL_PCIE_REGION_NAME_LEN);
+	name[BTINTEL_PCIE_REGION_NAME_LEN] = '\0';
+
+	switch (region->type) {
+	case BTINTEL_PCIE_REGION_DEVICE_MEM:
+		if (!region->num_addrs || !region->addrs) {
+			bt_dev_warn(data->hdev,
+				    "YoYo: device-memory region %u has no address",
+				    region->region_id);
+			return -ENOENT;
+		}
+
+		size = get_unaligned_le32(&region->conf.dev_addr.size_bytes);
+		addr_offset = get_unaligned_le32(&region->conf.dev_addr.addr_offset);
+
+		if (check_add_overflow(region->addrs[0], addr_offset,
+				       &addr_start)) {
+			bt_dev_warn(data->hdev,
+				    "YoYo: region %u address 0x%08x + offset 0x%08x overflows",
+				    region->region_id, region->addrs[0],
+				    addr_offset);
+			return -EINVAL;
+		}
+
+		return btintel_pcie_dump_target_region(data, list, region->region_id,
+						      name, addr_start, size);
+	case BTINTEL_PCIE_REGION_DRAM_BUF:
+		alloc_id = get_unaligned_le32(&region->conf.dram_alloc_id);
+		if (!btintel_pcie_get_dbgc_buf_set(data, alloc_id, &set)) {
+			bt_dev_warn(data->hdev,
+				    "YoYo: invalid DRAM allocation ID %u for region %u",
+				    alloc_id, region->region_id);
+			return -EINVAL;
+		}
+
+		return btintel_pcie_dump_dram_monitor(data, list, set.count,
+						      set.buf_size, set.bufs,
+						      status_reg, wrap_reg,
+						      set.allocation_id,
+						      region->region_id, name);
+	default:
+		bt_dev_warn(data->hdev,
+			    "YoYo: unsupported region type %u for region %u",
+			    region->type, region->region_id);
+		return -EOPNOTSUPP;
+	}
+}
+
 static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 {
-	struct btintel_pcie_dbgc *dbgc = NULL;
-	struct btintel_pcie_mdbgc *mdbgc = NULL;
 	struct btintel_pcie_dump_mem_info *dump_info = &data->dump_info;
 	struct hci_dev *hdev = data->hdev;
 	struct btintel_pcie_dump_entry *entry;
 	struct btintel_pcie_dump_file_hdr *file_hdr;
+	struct btintel_pcie_yoyo_region *region;
 	struct scatterlist *sg_dump_data;
 	u32 status_reg, wrap_reg;
+	u32 dumped_dram_allocs = 0;
+	u32 alloc_id;
 	u64 regions_mask = 0;
 	u8 hw_variant;
 	u32 file_len;
-	u8 count;
-	u32 buf_size;
 	int ret;
+	u32 i;
 	LIST_HEAD(dump_list);
 
 	if (!IS_ENABLED(CONFIG_DEV_COREDUMP))
 		return -EOPNOTSUPP;
 
-	if (btintel_pcie_is_mdbgc_supported(data)) {
-		mdbgc = &data->mdbgc;
-		count = mdbgc->buf1_count;
-		buf_size = mdbgc->buf1_size;
-	} else {
-		dbgc = &data->dbgc;
-		count = dbgc->count;
-		buf_size = dbgc->buf_size;
-	}
-
 	hw_variant = INTEL_HW_VARIANT(data->cnvi);
 
 	if (hw_variant == BTINTEL_HWID_BZRI ||
@@ -1610,73 +1728,86 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 		return -EINVAL;
 	}
 
-	if (btintel_pcie_is_mdbgc_supported(data)) {
-		ret = btintel_pcie_dump_dram_monitor(data, &dump_list,
-						     mdbgc->buf1_count,
-						     mdbgc->buf1_size,
-						     mdbgc->buf1, status_reg,
-						     wrap_reg,
-						     BTINTEL_PCIE_MDBGC_ALLOCATIONID_1,
-						     BTINTEL_PCIE_INI_ID_DRAM_MONITOR1,
-						     "monitor");
-		if (!ret)
-			regions_mask |=
-				BIT_ULL(BTINTEL_PCIE_INI_ID_DRAM_MONITOR1);
-		else if (ret != -ENOENT)
-			bt_dev_warn(hdev, "Failed to dump DRAM buf1: %d", ret);
-
-		ret = btintel_pcie_dump_dram_monitor(data, &dump_list,
-						     mdbgc->buf2_count,
-						     mdbgc->buf2_size,
-						     mdbgc->buf2, status_reg,
-						     wrap_reg,
-						     BTINTEL_PCIE_MDBGC_ALLOCATIONID_2,
-						     BTINTEL_PCIE_INI_ID_DRAM_MONITOR2,
-						     "monitor2");
-		if (!ret)
-			regions_mask |=
-				BIT_ULL(BTINTEL_PCIE_INI_ID_DRAM_MONITOR2);
-		else if (ret != -ENOENT)
-			bt_dev_warn(hdev, "Failed to dump DRAM buf2: %d", ret);
-
-		ret = btintel_pcie_dump_dram_monitor(data, &dump_list,
-						     mdbgc->buf3_count,
-						     mdbgc->buf3_size,
-						     mdbgc->buf3, status_reg,
-						     wrap_reg,
-						     BTINTEL_PCIE_MDBGC_ALLOCATIONID_3,
-						     BTINTEL_PCIE_INI_ID_DRAM_MONITOR3,
-						     "monitor3");
-		if (!ret)
-			regions_mask |=
-				BIT_ULL(BTINTEL_PCIE_INI_ID_DRAM_MONITOR3);
-		else if (ret != -ENOENT)
-			bt_dev_warn(hdev, "Failed to dump DRAM buf3: %d", ret);
+	/* Collect the debug regions into a devcoredump. With YoYo enabled the
+	 * REGION TLVs declare them, otherwise the built-in DRAM monitors are
+	 * used.
+	 */
+	if (data->yoyo.enabled) {
+		list_for_each_entry(region, &data->yoyo.region_list, list) {
+			alloc_id = 0;
+			/* Several regions may name the same allocation; copy
+			 * its buffers once.
+			 */
+			if (region->type == BTINTEL_PCIE_REGION_DRAM_BUF) {
+				alloc_id = get_unaligned_le32(&region->conf.dram_alloc_id);
+
+				if (alloc_id < BTINTEL_PCIE_ALLOC_ID_MAX &&
+				    dumped_dram_allocs & BIT(alloc_id))
+					continue;
+			}
+
+			ret = btintel_pcie_yoyo_dump_region(data, &dump_list,
+							    region, status_reg,
+							    wrap_reg);
+			if (!ret) {
+				regions_mask |= BIT_ULL(region->region_id);
+				if (alloc_id)
+					dumped_dram_allocs |= BIT(alloc_id);
+			} else if (ret < 0 && ret != -ENOENT && ret != -EOPNOTSUPP) {
+				bt_dev_warn(hdev,
+					    "YoYo: failed to dump region %u: %d",
+					    region->region_id, ret);
+			}
+
+			bt_dev_dbg(hdev, "YoYo: region %u type=%u dump ret=%d",
+				   region->region_id, region->type, ret);
+		}
 	} else {
-		ret = btintel_pcie_dump_dram_monitor(data, &dump_list, count,
-						     buf_size, dbgc->bufs,
-						     status_reg,
-						     wrap_reg,
-						     BTINTEL_PCIE_MDBGC_ALLOCATIONID_1,
-						     BTINTEL_PCIE_INI_ID_DRAM_MONITOR1,
-						     "monitor");
-		if (!ret)
-			regions_mask |=
-				BIT_ULL(BTINTEL_PCIE_INI_ID_DRAM_MONITOR1);
-		else
-			bt_dev_warn(hdev,
-				    "Failed to dump DRAM region: %d", ret);
+		/* Legacy DRAM monitors. YoYo declares its own via REGION TLVs,
+		 * so this runs instead of the loop above, as on Windows.
+		 * get_dbgc_buf_set() resolves only the allocations this SKU
+		 * has, so single-DBGC skips DBGC2 and DBGC3.
+		 */
+		for (i = 0; i < ARRAY_SIZE(dram_monitors); i++) {
+			const struct btintel_pcie_dram_monitor *mon = &dram_monitors[i];
+			struct btintel_pcie_dbgc_buf_set set;
+
+			if (!btintel_pcie_get_dbgc_buf_set(data, mon->alloc_id, &set))
+				continue;
+
+			ret = btintel_pcie_dump_dram_monitor(data, &dump_list,
+							     set.count,
+							     set.buf_size,
+							     set.bufs,
+							     status_reg, wrap_reg,
+							     set.allocation_id,
+							     mon->region_id,
+							     mon->name);
+			if (!ret)
+				regions_mask |= BIT_ULL(mon->region_id);
+			else if (ret != -ENOENT)
+				bt_dev_warn(hdev, "Failed to dump %s: %d",
+					    mon->name, ret);
+
+			bt_dev_dbg(hdev, "builtin region %u (%s) dump ret=%d",
+				   mon->region_id, mon->name, ret);
+		}
 	}
 
 	if (dump_info->smem_size &&
-	    !btintel_pcie_dump_smem_monitor_region(data, &dump_list,
-						   BTINTEL_PCIE_INI_ID_SMEM,
-						   "monitor_smem",
-						   dump_info->smem_addr_start,
-						   dump_info->smem_size))
-		regions_mask |= BIT_ULL(BTINTEL_PCIE_INI_ID_SMEM);
-
-	if (dump_info->exception_dump_addr && dump_info->exception_dump_len) {
+	    !btintel_pcie_yoyo_region_configured(&data->yoyo,
+						 BTINTEL_PCIE_INI_ID_SMEM)) {
+		if (!btintel_pcie_dump_smem_monitor_region(data, &dump_list,
+							   BTINTEL_PCIE_INI_ID_SMEM,
+							   "monitor_smem",
+							   dump_info->smem_addr_start,
+							   dump_info->smem_size))
+			regions_mask |= BIT_ULL(BTINTEL_PCIE_INI_ID_SMEM);
+	}
+
+	if (dump_info->exception_dump_addr && dump_info->exception_dump_len &&
+	    !btintel_pcie_yoyo_region_configured(&data->yoyo,
+						 BTINTEL_PCIE_INI_ID_EXCEPTION_EVT)) {
 		ret = btintel_pcie_dump_target_region(data, &dump_list,
 						      BTINTEL_PCIE_INI_ID_EXCEPTION_EVT,
 						      "EXCEPTION_EVT_BUFFER",
diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h
index 97267a7e9762..1dd32ea64fc4 100644
--- a/drivers/bluetooth/btintel_pcie.h
+++ b/drivers/bluetooth/btintel_pcie.h
@@ -529,6 +529,14 @@ struct btintel_pcie_mdbgc {
 	struct data_buf *buf3;
 };
 
+/* DBGC buffer set resolved from a YoYo allocation ID */
+struct btintel_pcie_dbgc_buf_set {
+	struct data_buf	*bufs;
+	u8		count;
+	u32		buf_size;
+	u8		allocation_id;
+};
+
 struct btintel_pcie_dump_mem_info {
 	u32	exception_dump_addr;
 	u32	exception_dump_len;
@@ -591,17 +599,6 @@ struct btintel_pcie_dump_range {
 #define BTINTEL_PCIE_INI_REGION_DRAM_BUFFER	3
 #define BTINTEL_PCIE_INI_REGION_DEVICE_MEMORY	9
 
-/* INI region IDs - used in dump header region_id field and regions_mask */
-#define BTINTEL_PCIE_INI_ID_EXCEPTION_EVT	7
-#define BTINTEL_PCIE_INI_ID_SMEM		15
-#define BTINTEL_PCIE_INI_ID_DCCM		39
-#define BTINTEL_PCIE_INI_ID_SDS			40
-#define BTINTEL_PCIE_INI_ID_SDS_IOSF		41
-#define BTINTEL_PCIE_INI_ID_ECL			42
-#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR3	61
-#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR2	62
-#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR1	63
-
 /*
  * INI (Intel INI debug infrastructure) style dump data TLV - wraps each dump
  * region. INI is the iwlwifi firmware debug format used by the unified decoder.
diff --git a/drivers/bluetooth/btintel_pcie_debug.c b/drivers/bluetooth/btintel_pcie_debug.c
index 9dc380ec9c6b..8a7d884f9a0e 100644
--- a/drivers/bluetooth/btintel_pcie_debug.c
+++ b/drivers/bluetooth/btintel_pcie_debug.c
@@ -593,6 +593,13 @@ static int btintel_pcie_yoyo_parse_region(struct btintel_pcie_yoyo_ctx *ctx,
 		return 0;
 	}
 
+	/* An unbounded size from the file would wrap the dump allocation size */
+	if (size > BTINTEL_PCIE_YOYO_REGION_MAX_SIZE) {
+		BT_WARN("YoYo: region id=%u size %u exceeds cap %u, skipping",
+			region_id, size, BTINTEL_PCIE_YOYO_REGION_MAX_SIZE);
+		return 0;
+	}
+
 	region = kzalloc(sizeof(*region), GFP_KERNEL);
 	if (!region)
 		return -ENOMEM;
@@ -1001,6 +1008,33 @@ btintel_pcie_yoyo_find_trigger(struct btintel_pcie_yoyo_ctx *ctx,
 }
 EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_find_trigger);
 
+/* Region types the dump path can emit. The parser accepts every type the
+ * file may carry, so a region of any other type must not claim its ID.
+ */
+static bool btintel_pcie_yoyo_region_dumpable(const struct btintel_pcie_yoyo_region *region)
+{
+	return region->type == BTINTEL_PCIE_REGION_DEVICE_MEM ||
+	       region->type == BTINTEL_PCIE_REGION_DRAM_BUF;
+}
+
+/* Check if a region TLV claims region_id */
+bool btintel_pcie_yoyo_region_configured(struct btintel_pcie_yoyo_ctx *ctx,
+					 u32 region_id)
+{
+	struct btintel_pcie_yoyo_region *region;
+
+	if (!ctx || !ctx->enabled)
+		return false;
+
+	list_for_each_entry(region, &ctx->region_list, list) {
+		if (region->region_id == region_id)
+			return btintel_pcie_yoyo_region_dumpable(region);
+	}
+
+	return false;
+}
+EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_region_configured);
+
 /**
  * btintel_pcie_yoyo_get_buf_alloc - Query buffer allocation config for a DBGC
  * @ctx: YoYo context
diff --git a/drivers/bluetooth/btintel_pcie_debug.h b/drivers/bluetooth/btintel_pcie_debug.h
index 9d5ed7729fe8..9fae4f5eb67b 100644
--- a/drivers/bluetooth/btintel_pcie_debug.h
+++ b/drivers/bluetooth/btintel_pcie_debug.h
@@ -78,6 +78,19 @@ bool btintel_pcie_fatal_err_testmode_active(struct btintel_pcie_data *data);
 #define BTINTEL_PCIE_REGION_ID_MAX		63
 #define BTINTEL_PCIE_REGION_NAME_LEN		32
 #define BTINTEL_PCIE_REGION_LIST_SIZE		2
+/* Mirrors BTINTEL_PCIE_REGION_MAX_SIZE, bounds dump allocation */
+#define BTINTEL_PCIE_YOYO_REGION_MAX_SIZE	(1 * 1024 * 1024)
+
+/* INI region IDs - used in dump header region_id field and regions_mask */
+#define BTINTEL_PCIE_INI_ID_EXCEPTION_EVT	7
+#define BTINTEL_PCIE_INI_ID_SMEM		15
+#define BTINTEL_PCIE_INI_ID_DCCM		39
+#define BTINTEL_PCIE_INI_ID_SDS			40
+#define BTINTEL_PCIE_INI_ID_SDS_IOSF		41
+#define BTINTEL_PCIE_INI_ID_ECL			42
+#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR3	61
+#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR2	62
+#define BTINTEL_PCIE_INI_ID_DRAM_MONITOR1	63
 
 enum btintel_pcie_image_tlv_type {
 	BTINTEL_PCIE_IMAGE_TLV_TYPE_EXTERNAL	= 0x1,
@@ -486,4 +499,7 @@ const struct btintel_pcie_yoyo_trigger *
 btintel_pcie_yoyo_find_trigger(struct btintel_pcie_yoyo_ctx *ctx,
 			       enum btintel_pcie_dbg_timepoint tp);
 
+bool btintel_pcie_yoyo_region_configured(struct btintel_pcie_yoyo_ctx *ctx,
+					 u32 region_id);
+
 #endif /* __BTINTEL_PCIE_DEBUG_H__ */
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 3/3] Bluetooth: btintel_pcie: Dispatch yoyo triggers at timepoints
  2026-12-02 10:04 [PATCH v1 1/3] Bluetooth: btintel_pcie: Add yoyo configuration for trigger tlv Ajay KV
  2026-12-02 10:04 ` [PATCH v1 2/3] Bluetooth: btintel_pcie: Collect dump regions from yoyo region TLVs Ajay KV
@ 2026-12-02 10:04 ` Ajay KV
  1 sibling, 0 replies; 3+ messages in thread
From: Ajay KV @ 2026-12-02 10:04 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: chandrashekar.devegowda, kiran.k, linux-kernel, luiz.dentz,
	marcel, stable, chethan.tumkur.narayan, lakshmipathi.k, Ajay KV

Trigger TLVs are parsed and stored but never acted on. Resolve the
trigger configured for the timepoint a dump is taken at, and use its
region mask to select which declared regions the dump collects.

The coredump worker stages the mask and the dump latches it once, so
no timepoint can leave a mask behind for an unrelated dump. A dump
without a matching trigger still collects every region. A firmware
smart trigger with no trigger configured collects only the DBGC
buffers, and on a firmware assert the fixed regions are collected
even when the mask leaves them out.

Firmware smart trigger dumps now report their own reason code instead
of the firmware assert one, even without a yoyo configuration, so a
routine notification is not collected as an assert.

D3 entry sends the D3 start commands and, if a trigger is configured
for it, flushes the DBGC through the user trigger doorbell while the
device is still reachable, before the firmware trigger interrupt is
masked. Only a real power-off does this, since S0ix enters D3 on
every runtime idle. The doorbell request carries the timepoint it is
dumped under. D3 end commands are sent on resume and after setup,
which a power-off resume reaches through FLR.

Occurrence limit, ignore consecutive duration, delayed dumping, stop
dump limit, trigger policy mask and firmware reset mode are not
supported.

Signed-off-by: Ajay KV <ajay.k.v@intel.com>
---
 drivers/bluetooth/btintel_pcie.c       | 350 ++++++++++++++++++++++---
 drivers/bluetooth/btintel_pcie.h       |   7 +
 drivers/bluetooth/btintel_pcie_debug.c | 104 +++++++-
 drivers/bluetooth/btintel_pcie_debug.h |  51 ++--
 4 files changed, 451 insertions(+), 61 deletions(-)

diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c
index 3d4ce6f1f1ba..5ca7dd07dff5 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -92,8 +92,13 @@ struct btintel_pcie_dev_recovery {
 #define BTINTEL_PCIE_MAGIC_NUM	0xA5A5A5A5
 
 #define BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER	0x17A2
+#define BTINTEL_PCIE_TRIGGER_REASON_D0_EXIT		0x1B94
+#define BTINTEL_PCIE_TRIGGER_REASON_FW_SOFT_TRIG	0x1B9E
 #define BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT		0x1E61
 
+/* Wait for the firmware to answer the D3 entry (D3_START) dump doorbell */
+#define BTINTEL_PCIE_D3_COREDUMP_TIMEOUT_MS	2000
+
 #define BTINTEL_PCIE_RESET_WINDOW_SECS		5
 #define BTINTEL_PCIE_FLR_MAX_RETRY	1
 
@@ -919,9 +924,11 @@ static void btintel_pcie_release_mac_access(struct btintel_pcie_data *data)
 
 /* btintel_pcie_yoyo_send_hcmds - Send all HCI commands configured for a timepoint */
 static void btintel_pcie_yoyo_send_hcmds(struct btintel_pcie_data *data,
-					 enum btintel_pcie_dbg_timepoint tp)
+					 enum btintel_pcie_dbg_timepoint tp,
+					 bool req_locked)
 {
 	struct btintel_pcie_yoyo_hcmd *hcmd;
+	struct hci_dev *hdev;
 	struct sk_buff *skb;
 	u8 plen;
 	u16 opcode;
@@ -929,11 +936,39 @@ static void btintel_pcie_yoyo_send_hcmds(struct btintel_pcie_data *data,
 	if (!data)
 		return;
 
+	hdev = data->hdev;
+	if (!hdev)
+		return;
+
+	/* __hci_cmd_sync() requires req_lock, taken before yoyo.lock to match
+	 * the order setup established. Suspend and resume do not hold it, so
+	 * take it only when the timepoint has commands to send.
+	 */
+	if (!req_locked) {
+		bool found = false;
+
+		mutex_lock(&data->yoyo.lock);
+		if (data->yoyo.enabled) {
+			list_for_each_entry(hcmd, &data->yoyo.hcmd_list, list) {
+				if (hcmd->time_point == tp) {
+					found = true;
+					break;
+				}
+			}
+		}
+		mutex_unlock(&data->yoyo.lock);
+
+		if (!found)
+			return;
+
+		hci_req_sync_lock(hdev);
+	}
+
 	/* Held across __hci_cmd_sync() so cleanup cannot free entries in use */
 	mutex_lock(&data->yoyo.lock);
-	if (!data->yoyo.enabled || !data->hdev) {
+	if (!data->yoyo.enabled) {
 		mutex_unlock(&data->yoyo.lock);
-		return;
+		goto unlock;
 	}
 
 	list_for_each_entry(hcmd, &data->yoyo.hcmd_list, list) {
@@ -996,6 +1031,9 @@ static void btintel_pcie_yoyo_send_hcmds(struct btintel_pcie_data *data,
 	}
 
 	mutex_unlock(&data->yoyo.lock);
+unlock:
+	if (!req_locked)
+		hci_req_sync_unlock(hdev);
 }
 
 static void
@@ -1113,23 +1151,77 @@ btintel_pcie_apply_yoyo_config_sets(struct btintel_pcie_data *data,
 	}
 }
 
+/*
+ * Resolve the trigger configured for @tp and stage its region mask for the
+ * dump that follows.
+ */
+static void btintel_pcie_yoyo_handle_trigger(struct btintel_pcie_data *data,
+					     enum btintel_pcie_dbg_timepoint tp)
+{
+	const struct btintel_pcie_yoyo_trigger *trigger;
+	u32 mask[BTINTEL_PCIE_REGION_LIST_SIZE];
+
+	/* These two collect no dump, so a mask staged here would be latched by
+	 * an unrelated later dump. Any new non-dumping timepoint belongs here.
+	 */
+	if (tp == BTINTEL_PCIE_TP_EARLY || tp == BTINTEL_PCIE_TP_AFTER_ALIVE)
+		return;
+
+	/* Taken under the lock, which is also where cleanup clears it */
+	mutex_lock(&data->yoyo.lock);
+	if (!data->yoyo.enabled) {
+		mutex_unlock(&data->yoyo.lock);
+		return;
+	}
+
+	trigger = btintel_pcie_yoyo_find_trigger(&data->yoyo, tp);
+	if (trigger) {
+		mask[0] = trigger->regions_mask[0];
+		mask[1] = trigger->regions_mask[1];
+		BT_DBG("YoYo: trigger fired tp=%u regions=0x%08x%08x",
+		       tp, mask[1], mask[0]);
+	} else if (tp == BTINTEL_PCIE_TP_FW_RSP_OR_NOTIF) {
+		/* An unconfigured smart trigger collects the DBGC buffers and
+		 * nothing else. Leaving the mask unstaged would instead make
+		 * btintel_pcie_yoyo_region_active() read it as "no trigger,
+		 * dump all" and evacuate every fixed region on a routine
+		 * firmware notification.
+		 */
+		btintel_pcie_yoyo_get_dram_regions_mask(&data->yoyo, mask);
+		BT_DBG("YoYo: no smart trigger configured, dbgc regions=0x%08x%08x",
+		       mask[1], mask[0]);
+	} else {
+		mutex_unlock(&data->yoyo.lock);
+		BT_DBG("YoYo: No trigger for TP (%u)", tp);
+		return;
+	}
+
+	data->yoyo.active_regions_mask[0] = mask[0];
+	data->yoyo.active_regions_mask[1] = mask[1];
+	data->yoyo.active_regions_valid = true;
+
+	mutex_unlock(&data->yoyo.lock);
+}
+
 static void btintel_pcie_yoyo_handle_timepoint(struct btintel_pcie_data *data,
 					       enum btintel_pcie_dbg_timepoint tp)
 {
 	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;
 	}
 
+	BT_DBG("YoYo: timepoint %s (%u) enter", btintel_pcie_yoyo_tp_str(tp), tp);
+
 	/* PRE-DUMP phase: send HCMDs and apply config sets */
-	btintel_pcie_yoyo_send_hcmds(data, tp);
+	btintel_pcie_yoyo_send_hcmds(data, tp, true);
 
 	btintel_pcie_apply_yoyo_config_sets(data, tp);
+
+	BT_DBG("YoYo: timepoint %s (%u) done", btintel_pcie_yoyo_tp_str(tp), tp);
 }
 
 static struct scatterlist *btintel_pcie_alloc_sgtable(ssize_t size)
@@ -1487,10 +1579,18 @@ static int btintel_pcie_dump_info(struct btintel_pcie_data *data,
 	    BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT)
 		dump->time_point =
 			cpu_to_le32(BTINTEL_PCIE_TIME_POINT_FW_ASSERT);
+	else if (data->dmp_hdr.trigger_reason ==
+		 BTINTEL_PCIE_TRIGGER_REASON_FW_SOFT_TRIG)
+		dump->time_point =
+			cpu_to_le32(BTINTEL_PCIE_TIME_POINT_FW_RSP_OR_NOTIF);
 	else if (data->dmp_hdr.trigger_reason ==
 		 BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER)
 		dump->time_point =
 			cpu_to_le32(BTINTEL_PCIE_TIME_POINT_USER_TRIGGER);
+	else if (data->dmp_hdr.trigger_reason ==
+		 BTINTEL_PCIE_TRIGGER_REASON_D0_EXIT)
+		dump->time_point =
+			cpu_to_le32(BTINTEL_PCIE_TIME_POINT_HOST_D3_START);
 
 	dump->hw_type = cpu_to_le32(INTEL_CNVX_TOP_TYPE(data->dmp_hdr.cnvi_top));
 	dump->hw_step = cpu_to_le32(INTEL_CNVX_TOP_STEP(data->dmp_hdr.cnvi_top));
@@ -1619,9 +1719,11 @@ static bool btintel_pcie_get_dbgc_buf_set(struct btintel_pcie_data *data,
 static void btintel_pcie_dump_mem_range(struct btintel_pcie_data *data,
 					struct list_head *list, u32 region_id,
 					const char *name, u32 addr_start,
-					u32 region_size, u64 *regions_mask)
+					u32 region_size, const u32 *dump_regions,
+					u64 *regions_mask)
 {
 	if (!region_size ||
+	    !btintel_pcie_yoyo_region_active(dump_regions, region_id) ||
 	    btintel_pcie_yoyo_region_configured(&data->yoyo, region_id)) {
 		return;
 	}
@@ -1695,9 +1797,13 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 {
 	struct btintel_pcie_dump_mem_info *dump_info = &data->dump_info;
 	struct hci_dev *hdev = data->hdev;
+	struct device *dump_dev = &hdev->dev;
 	struct btintel_pcie_dump_entry *entry;
 	struct btintel_pcie_dump_file_hdr *file_hdr;
 	struct btintel_pcie_yoyo_region *region;
+	u32 mask_buf[BTINTEL_PCIE_REGION_LIST_SIZE];
+	const u32 *dump_regions = NULL;
+	const u32 *fixed_regions;
 	struct scatterlist *sg_dump_data;
 	u32 status_reg, wrap_reg;
 	u32 dumped_dram_allocs = 0;
@@ -1712,6 +1818,33 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 	if (!IS_ENABLED(CONFIG_DEV_COREDUMP))
 		return -EOPNOTSUPP;
 
+	/* Latch the staged mask once so every region decision below sees the
+	 * same trigger, even if another timepoint fires during this dump. The
+	 * staging is consumed here, so a later dump that never staged a mask
+	 * falls back to dump-all instead of inheriting this one.
+	 */
+	mutex_lock(&data->yoyo.lock);
+	if (data->yoyo.active_regions_valid) {
+		memcpy(mask_buf, data->yoyo.active_regions_mask,
+		       sizeof(mask_buf));
+		data->yoyo.active_regions_valid = false;
+		dump_regions = mask_buf;
+	}
+	mutex_unlock(&data->yoyo.lock);
+
+	/* On an assert the fixed regions are the primary evidence, so they are
+	 * collected regardless of the trigger mask, as on Windows.
+	 */
+	fixed_regions = dump_regions;
+	if (data->dmp_hdr.trigger_reason == BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT)
+		fixed_regions = NULL;
+
+	if (dump_regions)
+		bt_dev_dbg(hdev, "YoYo: dump start: trigger mask=0x%08x%08x",
+			   dump_regions[1], dump_regions[0]);
+	else
+		bt_dev_dbg(hdev, "YoYo: dump start: no trigger, dump all");
+
 	hw_variant = INTEL_HW_VARIANT(data->cnvi);
 
 	if (hw_variant == BTINTEL_HWID_BZRI ||
@@ -1728,12 +1861,22 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 		return -EINVAL;
 	}
 
-	/* Collect the debug regions into a devcoredump. With YoYo enabled the
-	 * REGION TLVs declare them, otherwise the built-in DRAM monitors are
-	 * used.
+	/* Collect the enabled debug regions into a devcoredump.
+	 *   YoYo off                     -> dump all (legacy)
+	 *   YoYo on, no trigger for TP   -> dump all
+	 *   YoYo on, mask non-zero       -> dump only the masked regions
+	 *   YoYo on, mask all-zero       -> dump nothing
 	 */
 	if (data->yoyo.enabled) {
 		list_for_each_entry(region, &data->yoyo.region_list, list) {
+			const u32 *mask =
+				btintel_pcie_yoyo_is_fixed_region(region->region_id) ?
+				fixed_regions : dump_regions;
+
+			if (!btintel_pcie_yoyo_region_active(mask,
+							     region->region_id))
+				continue;
+
 			alloc_id = 0;
 			/* Several regions may name the same allocation; copy
 			 * its buffers once.
@@ -1795,6 +1938,8 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 	}
 
 	if (dump_info->smem_size &&
+	    btintel_pcie_yoyo_region_active(fixed_regions,
+					    BTINTEL_PCIE_INI_ID_SMEM) &&
 	    !btintel_pcie_yoyo_region_configured(&data->yoyo,
 						 BTINTEL_PCIE_INI_ID_SMEM)) {
 		if (!btintel_pcie_dump_smem_monitor_region(data, &dump_list,
@@ -1806,6 +1951,8 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 	}
 
 	if (dump_info->exception_dump_addr && dump_info->exception_dump_len &&
+	    btintel_pcie_yoyo_region_active(fixed_regions,
+					    BTINTEL_PCIE_INI_ID_EXCEPTION_EVT) &&
 	    !btintel_pcie_yoyo_region_configured(&data->yoyo,
 						 BTINTEL_PCIE_INI_ID_EXCEPTION_EVT)) {
 		ret = btintel_pcie_dump_target_region(data, &dump_list,
@@ -1821,25 +1968,32 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 				    BTINTEL_PCIE_INI_ID_DCCM, "DCCM",
 				    dump_info->dccm_addr_start,
 				    dump_info->dccm_size,
-				    &regions_mask);
+				    fixed_regions, &regions_mask);
 
 	btintel_pcie_dump_mem_range(data, &dump_list,
 				    BTINTEL_PCIE_INI_ID_SDS, "SDS",
 				    dump_info->sds_start_addr_start,
 				    dump_info->sds_start_size,
-				    &regions_mask);
+				    fixed_regions, &regions_mask);
 
 	btintel_pcie_dump_mem_range(data, &dump_list,
 				    BTINTEL_PCIE_INI_ID_SDS_IOSF, "SDS_IOSF",
 				    dump_info->sds_iosf_data_addr_start,
 				    dump_info->sds_iosf_data_size,
-				    &regions_mask);
+				    fixed_regions, &regions_mask);
 
 	btintel_pcie_dump_mem_range(data, &dump_list,
 				    BTINTEL_PCIE_INI_ID_ECL, "ECL_REGION",
 				    dump_info->ecl_addr_start,
 				    dump_info->ecl_size,
-				    &regions_mask);
+				    fixed_regions, &regions_mask);
+
+	/* A trigger that selected no region has nothing to report */
+	if (dump_regions && !regions_mask) {
+		bt_dev_dbg(hdev, "YoYo: trigger selected no region, no dump");
+		btintel_pcie_dump_list_free(&dump_list);
+		return 0;
+	}
 
 	ret = btintel_pcie_dump_info(data, &dump_list, regions_mask);
 	if (ret) {
@@ -1871,8 +2025,15 @@ static int btintel_pcie_read_debug_regions(struct btintel_pcie_data *data)
 			offs += entry->size;
 		}
 
+		/* A D3 entry dump is read only after resume, when the restore
+		 * path has re-registered hdev; attach it to the PCI device so
+		 * it does not pin the old hci index.
+		 */
+		if (data->dmp_hdr.yoyo_timepoint == BTINTEL_PCIE_TP_HOST_D3_START)
+			dump_dev = &data->pdev->dev;
+
 		bt_dev_dbg(hdev, "triggering dev_coredumpsg()");
-		dev_coredumpsg(&hdev->dev, sg_dump_data, file_len, GFP_KERNEL);
+		dev_coredumpsg(dump_dev, sg_dump_data, file_len, GFP_KERNEL);
 	} else {
 		bt_dev_err(hdev, "Failed to allocate scatter-gather table for coredump");
 		ret = -ENOMEM;
@@ -1893,7 +2054,7 @@ static void btintel_pcie_dump_traces(struct hci_dev *hdev)
 		bt_dev_err(hdev, "Failed to get mac access: (%d)", ret);
 		btintel_pcie_release_mac_access(data);
 		mutex_unlock(&data->mac_access_lock);
-		return;
+		goto discard_regions;
 	}
 
 	ret = btintel_pcie_read_debug_regions(data);
@@ -1903,6 +2064,12 @@ static void btintel_pcie_dump_traces(struct hci_dev *hdev)
 
 	if (ret)
 		bt_dev_err(hdev, "Failed to dump traces: (%d)", ret);
+
+discard_regions:
+
+	mutex_lock(&data->yoyo.lock);
+	data->yoyo.active_regions_valid = false;
+	mutex_unlock(&data->yoyo.lock);
 }
 
 static bool btintel_pcie_is_blazariw(struct pci_dev *pdev)
@@ -2962,12 +3129,13 @@ static int btintel_pcie_dump_fwtrigger_event(struct btintel_pcie_data *data)
  * consumes it.
  */
 static bool btintel_pcie_queue_coredump(struct btintel_pcie_data *data,
-					u16 trigger_reason)
+					u16 trigger_reason, u32 yoyo_tp)
 {
 	if (test_and_set_bit(BTINTEL_PCIE_COREDUMP_INPROGRESS, &data->flags))
 		return false;
 
 	data->dmp_hdr.trigger_reason = trigger_reason;
+	data->dmp_hdr.yoyo_timepoint = yoyo_tp;
 
 	if (queue_work(data->dump_workqueue, &data->coredump_work))
 		return true;
@@ -2996,9 +3164,24 @@ static bool btintel_pcie_consume_user_dump(struct btintel_pcie_data *data)
 		return false;
 
 	cancel_delayed_work(&data->user_dump_work);
+	wake_up(&data->user_dump_wait_q);
 	return true;
 }
 
+/* Queue the dump a consumed doorbell request asked for. D3 entry borrows the
+ * user-trigger doorbell, so its dump carries the D3 reason and timepoint.
+ */
+static bool btintel_pcie_queue_user_dump(struct btintel_pcie_data *data)
+{
+	u32 tp = READ_ONCE(data->user_dump_tp);
+	u16 reason = BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER;
+
+	if (tp == BTINTEL_PCIE_TP_HOST_D3_START)
+		reason = BTINTEL_PCIE_TRIGGER_REASON_D0_EXIT;
+
+	return btintel_pcie_queue_coredump(data, reason, tp);
+}
+
 static void btintel_pcie_msix_fw_trigger_handler(struct btintel_pcie_data *data)
 {
 	bt_dev_dbg(data->hdev, "Received firmware smart trigger cause");
@@ -3047,8 +3230,7 @@ static void btintel_pcie_msix_fw_trigger_handler(struct btintel_pcie_data *data)
 	 * fwtrigger_work and release the guard here.
 	 */
 	if (btintel_pcie_consume_user_dump(data)) {
-		if (!btintel_pcie_queue_coredump(data,
-						 BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER))
+		if (!btintel_pcie_queue_user_dump(data))
 			bt_dev_warn(data->hdev,
 				    "user-triggered dump dropped: coredump not queued");
 		clear_bit(BTINTEL_PCIE_FWTRIGGER_DUMP_INPROGRESS, &data->flags);
@@ -3060,7 +3242,8 @@ static void btintel_pcie_msix_fw_trigger_handler(struct btintel_pcie_data *data)
 		return;
 	}
 
-	btintel_pcie_queue_coredump(data, BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT);
+	btintel_pcie_queue_coredump(data, BTINTEL_PCIE_TRIGGER_REASON_FW_SOFT_TRIG,
+				    BTINTEL_PCIE_TP_FW_RSP_OR_NOTIF);
 }
 
 static void btintel_pcie_msix_hw_exp_handler(struct btintel_pcie_data *data)
@@ -3082,7 +3265,8 @@ static void btintel_pcie_msix_hw_exp_handler(struct btintel_pcie_data *data)
 	 * on the ordered @dump_workqueue (preserves the original
 	 * coredump-then-hwexp ordering).
 	 */
-	btintel_pcie_queue_coredump(data, BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT);
+	btintel_pcie_queue_coredump(data, BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT,
+				    BTINTEL_PCIE_TP_FW_ASSERT);
 
 	queue_work(data->dump_workqueue, &data->hwexp_work);
 }
@@ -3108,6 +3292,11 @@ static void btintel_pcie_coredump_worker(struct work_struct *work)
 		goto out;
 	}
 
+	/* Stage the region mask of the trigger configured for this dump's
+	 * timepoint. Dump timepoints carry no HCI commands or config sets.
+	 */
+	btintel_pcie_yoyo_handle_trigger(data, data->dmp_hdr.yoyo_timepoint);
+
 	btintel_pcie_dump_traces(data->hdev);
 	/* 0 means no dump yet, so never store it */
 	atomic64_set(&data->last_dump_jiffies64, get_jiffies_64() ?: 1);
@@ -3174,9 +3363,10 @@ static void btintel_pcie_user_dump_worker(struct work_struct *work)
 	    !test_and_clear_bit(BTINTEL_PCIE_USER_TRIGGERED_DUMP, &data->flags))
 		return;
 
+	wake_up(&data->user_dump_wait_q);
+
 	if (btintel_pcie_dump_rate_limited(data) ||
-	    !btintel_pcie_queue_coredump(data,
-					 BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER)) {
+	    !btintel_pcie_queue_user_dump(data)) {
 		bt_dev_warn(data->hdev,
 			    "DBGC flush doorbell timed out, dump dropped: busy or rate-limited");
 		return;
@@ -4463,6 +4653,12 @@ static int btintel_pcie_setup(struct hci_dev *hdev)
 		/* Once per setup, before the HCI init reset, as on Windows */
 		btintel_pcie_yoyo_handle_timepoint(data,
 						   BTINTEL_PCIE_TP_AFTER_ALIVE);
+
+		/* A power-off resume reaches the device through FLR and setup,
+		 * so D3_END commands are sent here as well as on resume.
+		 */
+		btintel_pcie_yoyo_send_hcmds(data, BTINTEL_PCIE_TP_HOST_D3_END,
+					     true);
 	}
 	return err;
 }
@@ -5030,6 +5226,8 @@ static int btintel_pcie_probe(struct pci_dev *pdev,
 	init_waitqueue_head(&data->rfkill_wait_q);
 	data->rfkill_wait_done = false;
 
+	init_waitqueue_head(&data->user_dump_wait_q);
+
 	data->workqueue = alloc_ordered_workqueue(KBUILD_MODNAME, WQ_HIGHPRI);
 	if (!data->workqueue)
 		return -ENOMEM;
@@ -5265,7 +5463,8 @@ static void btintel_pcie_user_dump_req_worker(struct work_struct *work)
 	 */
 	if (test_bit(BTINTEL_PCIE_CORE_HALTED, &data->flags)) {
 		btintel_pcie_queue_coredump(data,
-					    BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER);
+					    BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER,
+					    BTINTEL_PCIE_TP_USER_TRIGGER);
 		return;
 	}
 
@@ -5283,6 +5482,9 @@ static void btintel_pcie_user_dump_req_worker(struct work_struct *work)
 	 * the user-dump reason. This is rare and does not affect the dump
 	 * contents.
 	 */
+	WRITE_ONCE(data->user_dump_tp, BTINTEL_PCIE_TP_USER_TRIGGER);
+	/* Order the label before the flag the interrupt handler consumes */
+	smp_mb__before_atomic();
 	set_bit(BTINTEL_PCIE_USER_TRIGGERED_DUMP, &data->flags);
 	if (!queue_delayed_work(data->dump_workqueue, &data->user_dump_work,
 				secs_to_jiffies(BTINTEL_PCIE_USER_DUMP_TIMEOUT_SEC))) {
@@ -5399,6 +5601,71 @@ static int btintel_pcie_set_dxstate(struct btintel_pcie_data *data, u32 dxstate)
 	return -EBUSY;
 }
 
+/* Run the D3_START actions while the controller is still in D0: send its HCI
+ * commands, then flush the DBGC through the user-trigger doorbell if a D3_START
+ * trigger is configured. The suspend path that follows drains the dump.
+ */
+static void btintel_pcie_yoyo_at_d3_entry(struct btintel_pcie_data *data)
+{
+	bool have_trigger;
+
+	if (!data->yoyo.enabled || !btintel_pcie_fw_operational(data) ||
+	    test_bit(BTINTEL_PCIE_CORE_HALTED, &data->flags))
+		return;
+
+	bt_dev_dbg(data->hdev, "YoYo: handle D3 entry timepoint");
+
+	/* A queued sysfs request or the timeout of an earlier one would
+	 * compete for the doorbell and the label; suspend drops both anyway.
+	 */
+	cancel_work_sync(&data->user_dump_req_work);
+	cancel_delayed_work_sync(&data->user_dump_work);
+
+	btintel_pcie_yoyo_send_hcmds(data, BTINTEL_PCIE_TP_HOST_D3_START, false);
+
+	mutex_lock(&data->yoyo.lock);
+	have_trigger = !!btintel_pcie_yoyo_find_trigger(&data->yoyo,
+							BTINTEL_PCIE_TP_HOST_D3_START);
+	mutex_unlock(&data->yoyo.lock);
+
+	if (!have_trigger || btintel_pcie_dbg_to_wifi(data))
+		return;
+
+	/* An HCMD timeout above may have halted the core or started recovery */
+	if (!btintel_pcie_fw_operational(data) ||
+	    test_bit(BTINTEL_PCIE_CORE_HALTED, &data->flags))
+		return;
+
+	if (btintel_pcie_dump_rate_limited(data)) {
+		bt_dev_warn(data->hdev, "YoYo: D3 entry dump skipped, rate-limited");
+		return;
+	}
+
+	if (test_bit(BTINTEL_PCIE_COREDUMP_INPROGRESS, &data->flags) ||
+	    test_bit(BTINTEL_PCIE_FWTRIGGER_DUMP_INPROGRESS, &data->flags) ||
+	    test_bit(BTINTEL_PCIE_USER_TRIGGERED_DUMP, &data->flags)) {
+		bt_dev_warn(data->hdev,
+			    "YoYo: D3 entry dump skipped, collection already in progress");
+		return;
+	}
+
+	WRITE_ONCE(data->user_dump_tp, BTINTEL_PCIE_TP_HOST_D3_START);
+	/* Order the label before the flag the interrupt handler consumes */
+	smp_mb__before_atomic();
+	set_bit(BTINTEL_PCIE_USER_TRIGGERED_DUMP, &data->flags);
+
+	btintel_pcie_trigger_fw_dump_collect(data);
+
+	/* No timeout worker is armed; suspend drops an unanswered request */
+	if (!wait_event_timeout(data->user_dump_wait_q,
+				!test_bit(BTINTEL_PCIE_USER_TRIGGERED_DUMP,
+					  &data->flags),
+				msecs_to_jiffies(BTINTEL_PCIE_D3_COREDUMP_TIMEOUT_MS)))
+		bt_dev_warn(data->hdev,
+			    "YoYo: D3 entry dump not acknowledged within %d ms",
+			    BTINTEL_PCIE_D3_COREDUMP_TIMEOUT_MS);
+}
+
 static int btintel_pcie_suspend_late(struct device *dev, pm_message_t mesg)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -5409,6 +5676,20 @@ static int btintel_pcie_suspend_late(struct device *dev, pm_message_t mesg)
 
 	data = pci_get_drvdata(pdev);
 
+	/* S0ix (s2idle) uses D3_HOT; S3, freeze and hibernate use D3_COLD. */
+	if (mesg.event == PM_EVENT_SUSPEND &&
+	    pm_suspend_target_state == PM_SUSPEND_TO_IDLE)
+		dxstate = BTINTEL_PCIE_STATE_D3_HOT;
+	else
+		dxstate = BTINTEL_PCIE_STATE_D3_COLD;
+
+	/* The D3_START dump is answered through the firmware trigger
+	 * interrupt, so it runs before that is masked. S0ix enters D3 on every
+	 * runtime idle, so only a real power-off collects it.
+	 */
+	if (dxstate == BTINTEL_PCIE_STATE_D3_COLD)
+		btintel_pcie_yoyo_at_d3_entry(data);
+
 	btintel_pcie_mask_hw_rfkill(data);
 	btintel_pcie_mask_fwtrig(data);
 	btintel_pcie_synchronize_irqs(data);
@@ -5424,13 +5705,6 @@ static int btintel_pcie_suspend_late(struct device *dev, pm_message_t mesg)
 	flush_work(&data->fwtrigger_work);
 	flush_work(&data->coredump_work);
 
-	/* S0ix (s2idle) uses D3_HOT; S3, freeze and hibernate use D3_COLD. */
-	if (mesg.event == PM_EVENT_SUSPEND &&
-	    pm_suspend_target_state == PM_SUSPEND_TO_IDLE)
-		dxstate = BTINTEL_PCIE_STATE_D3_HOT;
-	else
-		dxstate = BTINTEL_PCIE_STATE_D3_COLD;
-
 	if (data->log_mask & BTINTEL_PCIE_LOG_SX)
 		bt_dev_info(data->hdev,
 			    "Sx suspend: event=%s(0x%x) dxstate=%u",
@@ -5523,6 +5797,17 @@ static int btintel_pcie_resume_event(struct device *dev, pm_message_t mesg)
 		bt_dev_dbg(data->hdev,
 			   "device entered into d0 state from d3 in %lld us",
 			   ktime_to_us(ktime_get() - start));
+		/* Freeze resumes here without re-running setup(), which is
+		 * where the other D0-entry paths send this timepoint. S0ix never
+		 * sent D3_START, so it gets no D3_END either. The event is part
+		 * of the test because pm_suspend_target_state is stale on thaw.
+		 */
+		if (test_bit(BTINTEL_PCIE_SETUP_DONE, &data->flags) &&
+		    !(mesg.event == PM_EVENT_RESUME &&
+		      pm_suspend_target_state == PM_SUSPEND_TO_IDLE))
+			btintel_pcie_yoyo_send_hcmds(data,
+						     BTINTEL_PCIE_TP_HOST_D3_END,
+						     false);
 		return err;
 	}
 
@@ -5537,7 +5822,8 @@ static int btintel_pcie_resume_event(struct device *dev, pm_message_t mesg)
 			btintel_pcie_in_device_halt(data)) {
 		bt_dev_err(data->hdev, "Controller in error state for D0 entry");
 		btintel_pcie_queue_coredump(data,
-					    BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT);
+					    BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT,
+					    BTINTEL_PCIE_TP_FW_ASSERT);
 		set_bit(BTINTEL_PCIE_CORE_HALTED, &data->flags);
 		btintel_pcie_request_reset(data, BTINTEL_PCIE_IOSF_PRR_FLR);
 	}
diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h
index 1dd32ea64fc4..8a0a2b47b8d8 100644
--- a/drivers/bluetooth/btintel_pcie.h
+++ b/drivers/bluetooth/btintel_pcie.h
@@ -575,6 +575,7 @@ struct btintel_pcie_dump_header {
 	u32		write_ptr;
 	u32		wrap_ctr;
 	u16		trigger_reason;
+	u32		yoyo_timepoint;
 	int		state;
 };
 
@@ -674,7 +675,9 @@ struct btintel_pcie_error_dump_data {
 
 /* Time point values matching iwl_fw_ini_time_point for fwdump parser */
 #define BTINTEL_PCIE_TIME_POINT_FW_ASSERT	4
+#define BTINTEL_PCIE_TIME_POINT_FW_RSP_OR_NOTIF	8
 #define BTINTEL_PCIE_TIME_POINT_USER_TRIGGER	9
+#define BTINTEL_PCIE_TIME_POINT_HOST_D3_START	16
 
 /*
  * Dump info struct - single TLV containing all metadata.
@@ -754,6 +757,8 @@ struct btintel_pcie_ini_dump_info {
  * @txq: TX Queue struct
  * @rxq: RX Queue struct
  * @alive_intr_ctxt: Alive interrupt context
+ * @user_dump_tp: Timepoint the pending doorbell request is dumped under
+ * @user_dump_wait_q: Woken when the pending doorbell request is consumed
  */
 struct btintel_pcie_data {
 	struct pci_dev	*pdev;
@@ -821,6 +826,8 @@ struct btintel_pcie_data {
 	struct work_struct	mbox_work;
 	struct delayed_work	user_dump_work;
 	struct work_struct	user_dump_req_work;
+	u32			user_dump_tp;
+	wait_queue_head_t	user_dump_wait_q;
 
 	struct dma_pool	*dma_pool;
 	dma_addr_t	dma_p_addr;
diff --git a/drivers/bluetooth/btintel_pcie_debug.c b/drivers/bluetooth/btintel_pcie_debug.c
index 8a7d884f9a0e..24dbe087a3dd 100644
--- a/drivers/bluetooth/btintel_pcie_debug.c
+++ b/drivers/bluetooth/btintel_pcie_debug.c
@@ -670,7 +670,9 @@ static int btintel_pcie_yoyo_parse_hcmd(struct btintel_pcie_yoyo_ctx *ctx,
 	}
 
 	time_point = get_unaligned_le32(&tlv->time_point);
-	if (time_point != BTINTEL_PCIE_TP_AFTER_ALIVE) {
+	if (time_point != BTINTEL_PCIE_TP_AFTER_ALIVE &&
+	    time_point != BTINTEL_PCIE_TP_HOST_D3_START &&
+	    time_point != BTINTEL_PCIE_TP_HOST_D3_END) {
 		BT_WARN("YoYo: skipping hcmd for timepoint %u", time_point);
 		return 0;
 	}
@@ -919,6 +921,9 @@ void btintel_pcie_yoyo_cleanup(struct btintel_pcie_yoyo_ctx *ctx)
 		kfree(trigger);
 	}
 
+	ctx->active_regions_valid = false;
+	memset(ctx->active_regions_mask, 0, sizeof(ctx->active_regions_mask));
+
 	mutex_unlock(&ctx->lock);
 }
 EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_cleanup);
@@ -980,17 +985,7 @@ int btintel_pcie_yoyo_load_and_parse(struct btintel_pcie_yoyo_ctx *ctx,
 }
 EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_load_and_parse);
 
-/**
- * btintel_pcie_yoyo_find_trigger - Look up the trigger configured for a timepoint
- * @ctx: YoYo context holding the parsed trigger list
- * @tp: timepoint to resolve
- *
- * Caller must hold @ctx->lock to serialize against btintel_pcie_yoyo_cleanup()
- * and ensure the returned pointer remains valid during use.
- *
- * Return: the first matching trigger, or NULL when none is configured or YoYo
- * is disabled.
- */
+/* Look up the trigger configured for a timepoint */
 const struct btintel_pcie_yoyo_trigger *
 btintel_pcie_yoyo_find_trigger(struct btintel_pcie_yoyo_ctx *ctx,
 			       enum btintel_pcie_dbg_timepoint tp)
@@ -1008,6 +1003,30 @@ btintel_pcie_yoyo_find_trigger(struct btintel_pcie_yoyo_ctx *ctx,
 }
 EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_find_trigger);
 
+/* select the configured DBGC regions */
+void btintel_pcie_yoyo_get_dram_regions_mask(struct btintel_pcie_yoyo_ctx *ctx,
+					     u32 *mask)
+{
+	struct btintel_pcie_yoyo_region *region;
+
+	mask[0] = 0;
+	mask[1] = 0;
+
+	if (!ctx || !ctx->enabled)
+		return;
+
+	list_for_each_entry(region, &ctx->region_list, list) {
+		if (region->type != BTINTEL_PCIE_REGION_DRAM_BUF)
+			continue;
+
+		if (region->region_id >= BTINTEL_PCIE_REGION_LIST_SIZE * 32)
+			continue;
+
+		mask[region->region_id / 32] |= BIT(region->region_id % 32);
+	}
+}
+EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_get_dram_regions_mask);
+
 /* Region types the dump path can emit. The parser accepts every type the
  * file may carry, so a region of any other type must not claim its ID.
  */
@@ -1035,6 +1054,67 @@ bool btintel_pcie_yoyo_region_configured(struct btintel_pcie_yoyo_ctx *ctx,
 }
 EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_region_configured);
 
+/*
+ * Check if a region should be dumped.
+ * A NULL dump_regions means no trigger was latched and dump all.
+ * A non-NULL all-zero mask is a trigger that selected nothing, and collects no region.
+ * ex: DRAM_MONITOR3 (DBGC3): word 1 and bit 29 : (mask[1] & 0x20000000)
+ */
+bool btintel_pcie_yoyo_region_active(const u32 *dump_regions, u32 region_id)
+{
+	u32 word = region_id / 32;
+	u32 bit = region_id % 32;
+
+	/* If no trigger was latched, consider the region active by default */
+	if (!dump_regions)
+		return true;
+
+	return !!(dump_regions[word] & BIT(bit));
+}
+EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_region_active);
+
+/* Regions the firmware reports through the mailbox TLVs. On an assert these
+ * are the primary evidence, so they are collected regardless of the trigger
+ * mask, whether the definition comes from a REGION TLV or the mailbox.
+ */
+bool btintel_pcie_yoyo_is_fixed_region(u32 region_id)
+{
+	switch (region_id) {
+	case BTINTEL_PCIE_INI_ID_EXCEPTION_EVT:
+	case BTINTEL_PCIE_INI_ID_SMEM:
+	case BTINTEL_PCIE_INI_ID_DCCM:
+	case BTINTEL_PCIE_INI_ID_SDS:
+	case BTINTEL_PCIE_INI_ID_SDS_IOSF:
+	case BTINTEL_PCIE_INI_ID_ECL:
+		return true;
+	default:
+		return false;
+	}
+}
+EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_is_fixed_region);
+
+/* convert timepoint enum to string */
+const char *btintel_pcie_yoyo_tp_str(enum btintel_pcie_dbg_timepoint tp)
+{
+	switch (tp) {
+	case BTINTEL_PCIE_TP_EARLY:			return "EARLY";
+	case BTINTEL_PCIE_TP_AFTER_ALIVE:		return "AFTER_ALIVE";
+	case BTINTEL_PCIE_TP_FW_ASSERT:			return "FW_ASSERT";
+	case BTINTEL_PCIE_TP_FW_HW_ERROR:		return "FW_HW_ERROR";
+	case BTINTEL_PCIE_TP_FW_RSP_OR_NOTIF:		return "FW_RSP_OR_NOTIF";
+	case BTINTEL_PCIE_TP_USER_TRIGGER:		return "USER_TRIGGER";
+	case BTINTEL_PCIE_TP_PERIODIC:			return "PERIODIC";
+	case BTINTEL_PCIE_TP_HOST_ASSERT:		return "HOST_ASSERT";
+	case BTINTEL_PCIE_TP_HOST_ALIVE_TIMEOUT:	return "HOST_ALIVE_TIMEOUT";
+	case BTINTEL_PCIE_TP_HOST_DEVICE_ENABLE:	return "HOST_DEVICE_ENABLE";
+	case BTINTEL_PCIE_TP_HOST_DEVICE_DISABLE:	return "HOST_DEVICE_DISABLE";
+	case BTINTEL_PCIE_TP_HOST_D3_START:		return "HOST_D3_START";
+	case BTINTEL_PCIE_TP_HOST_D3_END:		return "HOST_D3_END";
+	default:					return "UNKNOWN";
+	}
+}
+EXPORT_SYMBOL_GPL(btintel_pcie_yoyo_tp_str);
+
 /**
  * btintel_pcie_yoyo_get_buf_alloc - Query buffer allocation config for a DBGC
  * @ctx: YoYo context
diff --git a/drivers/bluetooth/btintel_pcie_debug.h b/drivers/bluetooth/btintel_pcie_debug.h
index 9fae4f5eb67b..6b34e60f3dac 100644
--- a/drivers/bluetooth/btintel_pcie_debug.h
+++ b/drivers/bluetooth/btintel_pcie_debug.h
@@ -129,25 +129,24 @@ enum btintel_pcie_dbg_config_set_type {
 	BTINTEL_PCIE_CFGSET_MAX,
 };
 
-/* Types of Timepoints */
+/* Types of Timepoints. Numbering follows FW_TLV_DEBUG_TIME_POINT_API_E, as
+ * the values are matched against the time_point field of the TLVs.
+ */
 enum btintel_pcie_dbg_timepoint {
 	BTINTEL_PCIE_TP_INVALID			= 0,
 	BTINTEL_PCIE_TP_EARLY			= 1,
 	BTINTEL_PCIE_TP_AFTER_ALIVE		= 2,
-	BTINTEL_PCIE_TP_POST_INIT		= 3,
-	BTINTEL_PCIE_TP_FW_ASSERT		= 4,
-	BTINTEL_PCIE_TP_FW_HW_ERROR		= 5,
-	BTINTEL_PCIE_TP_FW_TFD_Q_HANG		= 6,
-	BTINTEL_PCIE_TP_FW_DHC_NOTIF		= 7,
-	BTINTEL_PCIE_TP_FW_RSP_OR_NOTIF		= 8,
-	BTINTEL_PCIE_TP_USER_TRIGGER		= 9,
-	BTINTEL_PCIE_TP_PERIODIC		= 10,
-	BTINTEL_PCIE_TP_RESERVED		= 11,
-	BTINTEL_PCIE_TP_HOST_ASSERT		= 12,
-	BTINTEL_PCIE_TP_HOST_ALIVE_TIMEOUT	= 13,
-	BTINTEL_PCIE_TP_HOST_DEVICE_DISABLE	= 15,
-	BTINTEL_PCIE_TP_HOST_D3_START		= 16,
-	BTINTEL_PCIE_TP_HOST_D3_END		= 17,
+	BTINTEL_PCIE_TP_FW_ASSERT		= 3,
+	BTINTEL_PCIE_TP_FW_HW_ERROR		= 4,
+	BTINTEL_PCIE_TP_FW_RSP_OR_NOTIF		= 5,
+	BTINTEL_PCIE_TP_USER_TRIGGER		= 6,
+	BTINTEL_PCIE_TP_PERIODIC		= 7,
+	BTINTEL_PCIE_TP_HOST_ASSERT		= 8,
+	BTINTEL_PCIE_TP_HOST_ALIVE_TIMEOUT	= 9,
+	BTINTEL_PCIE_TP_HOST_DEVICE_ENABLE	= 10,
+	BTINTEL_PCIE_TP_HOST_DEVICE_DISABLE	= 11,
+	BTINTEL_PCIE_TP_HOST_D3_START		= 12,
+	BTINTEL_PCIE_TP_HOST_D3_END		= 13,
 	BTINTEL_PCIE_TP_MAX_NUM,
 };
 
@@ -466,7 +465,12 @@ struct btintel_pcie_yoyo_trigger {
  * @buf_alloc: Parsed buffer allocation entries
  * @num_buf_allocs: Number of parsed buffer allocation entries
  * @hdev: Associated HCI device; NULL until successful HCI registration
- * @lock: Serializes HCI command dispatch against YoYo cleanup
+ * @lock: Serializes parsed-list, staged-mask access
+ * and other concurrent access to the YoYo context
+ * @active_regions_mask: Region mask staged by the last fired trigger, consumed
+ *			 by the next dump
+ * @active_regions_valid: Whether @active_regions_mask holds a staged mask; a
+ *			  dump with no staged mask collects all regions
  *
  * Stores the validation state and parsed TLV data for the optional YoYo
  * firmware configuration.
@@ -481,8 +485,13 @@ struct btintel_pcie_yoyo_ctx {
 	struct btintel_pcie_buf_alloc buf_alloc[BTINTEL_PCIE_MAX_BUF_ALLOC];
 	int			 num_buf_allocs;
 	struct hci_dev		 *hdev;
-	/* Serializes HCI command dispatch against YoYo cleanup */
+	/* Guards enabled and the staged region mask. The parsed lists are
+	 * built at probe and freed only on the probe error path or in
+	 * remove(), after the dump workers are drained.
+	 */
 	struct mutex		 lock;
+	u32			 active_regions_mask[BTINTEL_PCIE_REGION_LIST_SIZE];
+	bool			 active_regions_valid;
 };
 
 int  btintel_pcie_yoyo_init(struct btintel_pcie_yoyo_ctx *ctx);
@@ -499,6 +508,14 @@ const struct btintel_pcie_yoyo_trigger *
 btintel_pcie_yoyo_find_trigger(struct btintel_pcie_yoyo_ctx *ctx,
 			       enum btintel_pcie_dbg_timepoint tp);
 
+void btintel_pcie_yoyo_get_dram_regions_mask(struct btintel_pcie_yoyo_ctx *ctx,
+					     u32 *mask);
+
+const char *btintel_pcie_yoyo_tp_str(enum btintel_pcie_dbg_timepoint tp);
+
+bool btintel_pcie_yoyo_region_active(const u32 *dump_regions, u32 region_id);
+bool btintel_pcie_yoyo_is_fixed_region(u32 region_id);
+
 bool btintel_pcie_yoyo_region_configured(struct btintel_pcie_yoyo_ctx *ctx,
 					 u32 region_id);
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-02 10:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 10:04 [PATCH v1 1/3] Bluetooth: btintel_pcie: Add yoyo configuration for trigger tlv Ajay KV
2026-12-02 10:04 ` [PATCH v1 2/3] Bluetooth: btintel_pcie: Collect dump regions from yoyo region TLVs Ajay KV
2026-12-02 10:04 ` [PATCH v1 3/3] Bluetooth: btintel_pcie: Dispatch yoyo triggers at timepoints Ajay KV

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®