Skip to contentSkip to conversation

Bluetooth: btintel_pcie: Setup buffers for firmware traces

PATCH Superseded Kiran K 3 participants 9 messages Feb 21, 2025 – Feb 25, 2025 Bluetooth drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kiran K

author
#0 lore raw

PATCH v2 1/4 Bluetooth: btintel_pcie: Setup buffers for firmware traces

This patch allocates the host memory which is used by controller to dump the firmware traces. The memory needs to be shared with controller via context information.

---
v1 -> v2:
No change

 drivers/bluetooth/btintel_pcie.c | 89 ++++++++++++++++++++++++++++++++
 drivers/bluetooth/btintel_pcie.h | 32 ++++++++++++
 2 files changed, 121 insertions(+)
drivers/bluetooth/btintel_pcie.c +89 -0
index b8b241a92bf9..11e2b805c7cc 100644
@@ -49,6 +49,8 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);
 #define BTINTEL_PCIE_HCI_EVT_PKT	0x00000004
 #define BTINTEL_PCIE_HCI_ISO_PKT	0x00000005
 
+ #define BTINTEL_PCIE_MAGIC_NUM    0xA5A5A5A5
+
 /* Alive interrupt context */
 enum {
 	BTINTEL_PCIE_ROM,
@@ -60,6 +62,83 @@ enum {
 	BTINTEL_PCIE_D3
 };
 
+/* Structure for dbgc fragment buffer
+ * @buf_addr_lsb: LSB of the buffer's physical address
+ * @buf_addr_msb: MSB of the buffer's physical address
+ * @buf_size: Total size of the buffer
+ */
+struct btintel_pcie_dbgc_ctxt_buf {
+	u32	buf_addr_lsb;
+	u32	buf_addr_msb;
+	u32	buf_size;
+};
+
+/* Structure for dbgc fragment
+ * @magic_num: 0XA5A5A5A5
+ * @ver: For Driver-FW compatibility
+ * @total_size: Total size of the payload debug info
+ * @num_buf: Num of allocated debug bufs
+ * @bufs: All buffer's addresses and sizes
+ */
+struct btintel_pcie_dbgc_ctxt {
+	u32	magic_num;
+	u32     ver;
+	u32     total_size;
+	u32     num_buf;
+	struct btintel_pcie_dbgc_ctxt_buf bufs[BTINTEL_PCIE_DBGC_BUFFER_COUNT];
+};
+
+/* This function initializes the memory for DBGC buffers and formats the
+ * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and
+ * size as the payload
+ */
+static int btintel_pcie_setup_dbgc(struct btintel_pcie_data *data)
+{
+	struct btintel_pcie_dbgc_ctxt db_frag;
+	struct data_buf *buf;
+	int i;
+
+	data->dbgc.count = BTINTEL_PCIE_DBGC_BUFFER_COUNT;
+	data->dbgc.bufs = devm_kcalloc(&data->pdev->dev, data->dbgc.count,
+				       sizeof(*buf), GFP_KERNEL);
+	if (!data->dbgc.bufs)
+		return -ENOMEM;
+
+	data->dbgc.buf_v_addr = dmam_alloc_coherent(&data->pdev->dev,
+						    data->dbgc.count *
+						    BTINTEL_PCIE_DBGC_BUFFER_SIZE,
+						    &data->dbgc.buf_p_addr,
+						    GFP_KERNEL | __GFP_NOWARN);
+	if (!data->dbgc.buf_v_addr)
+		return -ENOMEM;
+
+	data->dbgc.frag_v_addr = dmam_alloc_coherent(&data->pdev->dev,
+						     sizeof(struct btintel_pcie_dbgc_ctxt),
+						     &data->dbgc.frag_p_addr,
+						     GFP_KERNEL | __GFP_NOWARN);
+	if (!data->dbgc.frag_v_addr)
+		return -ENOMEM;
+
+	data->dbgc.frag_size = sizeof(struct btintel_pcie_dbgc_ctxt);
+
+	db_frag.magic_num = BTINTEL_PCIE_MAGIC_NUM;
+	db_frag.ver = BTINTEL_PCIE_DBGC_FRAG_VERSION;
+	db_frag.total_size = BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE;
+	db_frag.num_buf = BTINTEL_PCIE_DBGC_FRAG_BUFFER_COUNT;
+
+	for (i = 0; i < data->dbgc.count; i++) {
+		buf = &data->dbgc.bufs[i];
+		buf->data_p_addr = data->dbgc.buf_p_addr + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE;
+		buf->data = data->dbgc.buf_v_addr + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE;
+		db_frag.bufs[i].buf_addr_lsb = (u32)(buf->data_p_addr & 0xffffffff);
+		db_frag.bufs[i].buf_addr_msb = (u32)((buf->data_p_addr >> 32) & 0xffffffff);
+		db_frag.bufs[i].buf_size = BTINTEL_PCIE_DBGC_BUFFER_SIZE;
+	}
+
+	memcpy(data->dbgc.frag_v_addr, &db_frag, sizeof(db_frag));
+	return 0;
+}
+
 static inline void ipc_print_ia_ring(struct hci_dev *hdev, struct ia *ia,
 				     u16 queue_num)
 {
@@ -1008,6 +1087,11 @@ static void btintel_pcie_init_ci(struct btintel_pcie_data *data,
 	ci->addr_urbdq1 = data->rxq.urbd1s_p_addr;
 	ci->num_urbdq1 = data->rxq.count;
 	ci->urbdq_db_vec = BTINTEL_PCIE_RXQ_NUM;
+
+	ci->dbg_output_mode = 0x01;
+	ci->dbgc_addr = data->dbgc.frag_p_addr;
+	ci->dbgc_size = data->dbgc.frag_size;
+	ci->dbg_preset = 0x00;
 }
 
 static void btintel_pcie_free_txq_bufs(struct btintel_pcie_data *data,
@@ -1220,6 +1304,11 @@ static int btintel_pcie_alloc(struct btintel_pcie_data *data)
 	/* Setup Index Array */
 	btintel_pcie_setup_ia(data, p_addr, v_addr, &data->ia);
 
+	/* Setup data buffers for dbgc */
+	err = btintel_pcie_setup_dbgc(data);
+	if (err)
+		goto exit_error_txq;
+
 	/* Setup Context Information */
 	p_addr += sizeof(u16) * BTINTEL_PCIE_NUM_QUEUES * 4;
 	v_addr += sizeof(u16) * BTINTEL_PCIE_NUM_QUEUES * 4;
drivers/bluetooth/btintel_pcie.h +32 -0
index f9aada0543c4..b9d32393002b 100644
@@ -48,6 +48,21 @@
 #define BTINTEL_PCIE_CSR_MSIX_IVAR_BASE		(BTINTEL_PCIE_CSR_MSIX_BASE + 0x0880)
 #define BTINTEL_PCIE_CSR_MSIX_IVAR(cause)	(BTINTEL_PCIE_CSR_MSIX_IVAR_BASE + (cause))
 
+/* The DRAM buffer count, each buffer size, and
+ * fragment buffer size
+ */
+#define BTINTEL_PCIE_DBGC_BUFFER_COUNT		16
+#define BTINTEL_PCIE_DBGC_BUFFER_SIZE		(256 * 1024) /* 256 KB */
+
+#define BTINTEL_PCIE_DBGC_FRAG_VERSION		1
+#define BTINTEL_PCIE_DBGC_FRAG_BUFFER_COUNT	BTINTEL_PCIE_DBGC_BUFFER_COUNT
+
+/* Magic number(4), version(4), size of payload length(4) */
+#define BTINTEL_PCIE_DBGC_FRAG_HEADER_SIZE	12
+
+/* Num of alloc Dbg buff (4) + (LSB(4), MSB(4), Size(4)) for each buffer */
+#define BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE	196
+
 /* Causes for the FH register interrupts */
 enum msix_fh_int_causes {
 	BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0	= BIT(0),	/* cause 0 */
@@ -325,6 +340,22 @@ struct rxq {
 	struct data_buf	*bufs;
 };
 
+/* Structure for DRAM Buffer
+ * @count: Number of descriptors
+ * @buf: Array of data_buf structure
+ */
+struct btintel_pcie_dbgc {
+	u16		count;
+
+	void		*frag_v_addr;
+	dma_addr_t	frag_p_addr;
+	u16		frag_size;
+
+	dma_addr_t	buf_p_addr;
+	void		*buf_v_addr;
+	struct data_buf *bufs;
+};
+
 /* struct btintel_pcie_data
  * @pdev: pci device
  * @hdev: hdev device
@@ -405,6 +436,7 @@ struct btintel_pcie_data {
 	struct txq	txq;
 	struct rxq	rxq;
 	u32	alive_intr_ctxt;
+	struct btintel_pcie_dbgc	dbgc;
 };
 
 static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data,
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 2/4 Bluetooth: btintel_pcie: Read hardware exception data

On hardware error, controller writes hardware error event and optional vendor specific hci events in device memory in TLV format and raises MSIX interrupt. Driver reads the device memory and passes the events to the stack for further processing.

---
v1 --> v2:
- Add comments for the delay added in MAC for target acess
- Add comment for having a seperate work item to read exception events
- Add hci interface name while logging expception event in dmesg.

 drivers/bluetooth/btintel.h      |   1 +
 drivers/bluetooth/btintel_pcie.c | 226 ++++++++++++++++++++++++++++++-
 drivers/bluetooth/btintel_pcie.h |  23 ++++
 3 files changed, 249 insertions(+), 1 deletion(-)
drivers/bluetooth/btintel.h +1 -0
index 19530ea14905..4c21e69887a3 100644
@@ -190,6 +190,7 @@ enum {
 struct btintel_data {
 	DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS);
 	int (*acpi_reset_method)(struct hci_dev *hdev);
+	u32	cnvi_top;
 };
 
 #define btintel_set_flag(hdev, nr)					\
drivers/bluetooth/btintel_pcie.c +225 -1

286 lines not on this page · raw message

drivers/bluetooth/btintel_pcie.h +23 -0
index b9d32393002b..98902fd4fc96 100644
@@ -16,6 +16,8 @@
 #define BTINTEL_PCIE_CSR_CI_ADDR_LSB_REG	(BTINTEL_PCIE_CSR_BASE + 0x118)
 #define BTINTEL_PCIE_CSR_CI_ADDR_MSB_REG	(BTINTEL_PCIE_CSR_BASE + 0x11C)
 #define BTINTEL_PCIE_CSR_IMG_RESPONSE_REG	(BTINTEL_PCIE_CSR_BASE + 0x12C)
+#define BTINTEL_PCIE_PRPH_DEV_ADDR_REG		(BTINTEL_PCIE_CSR_BASE + 0x440)
+#define BTINTEL_PCIE_PRPH_DEV_RD_REG		(BTINTEL_PCIE_CSR_BASE + 0x458)
 #define BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR	(BTINTEL_PCIE_CSR_BASE + 0x460)
 
 /* BTINTEL_PCIE_CSR Function Control Register */
@@ -23,6 +25,12 @@
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT		(BIT(6))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_INIT		(BIT(7))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS	(BIT(20))
+
+#define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ	(BIT(21))
+/* Stop MAC Access disconnection request */
+#define BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS	(BIT(22))
+#define BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ		(BIT(23))
+
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_STS	(BIT(28))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_DISCON	(BIT(29))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_SW_RESET		(BIT(31))
@@ -72,6 +80,7 @@ enum msix_fh_int_causes {
 /* Causes for the HW register interrupts */
 enum msix_hw_int_causes {
 	BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0	= BIT(0),	/* cause 32 */
+	BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP	= BIT(3),	/* cause 35 */
 };
 
 /* PCIe device states
@@ -84,6 +93,11 @@ enum {
 	BTINTEL_PCIE_STATE_D3_HOT = 2,
 	BTINTEL_PCIE_STATE_D3_COLD = 3,
 };
+
+enum {
+	BTINTEL_PCIE_HWEXP_INPROGRESS,
+};
+
 #define BTINTEL_PCIE_MSIX_NON_AUTO_CLEAR_CAUSE	BIT(7)
 
 /* Minimum and Maximum number of MSI-X Vector
@@ -437,6 +451,7 @@ struct btintel_pcie_data {
 	struct rxq	rxq;
 	u32	alive_intr_ctxt;
 	struct btintel_pcie_dbgc	dbgc;
+	struct work_struct	hwexp_work;
 };
 
 static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data,
@@ -476,3 +491,11 @@ static inline void btintel_pcie_clr_reg_bits(struct btintel_pcie_data *data,
 	r &= ~bits;
 	iowrite32(r, data->base_addr + offset);
 }
+
+static inline u32 btintel_pcie_rd_dev_mem(struct btintel_pcie_data *data,
+					  u32 addr)
+{
+	btintel_pcie_wr_reg32(data, BTINTEL_PCIE_PRPH_DEV_ADDR_REG, addr);
+	return btintel_pcie_rd_reg32(data, BTINTEL_PCIE_PRPH_DEV_RD_REG);
+}
+
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 2/4] Bluetooth: btintel_pcie: Read hardware exception data

Hi Kiran,

Quoted 144 lines · Kiran K

On hardware error, controller writes hardware error event and optional vendor specific hci events in device memory in TLV format and raises MSIX interrupt. Driver reads the device memory and passes the events to the stack for further processing.

---
v1 --> v2:
- Add comments for the delay added in MAC for target acess
- Add comment for having a seperate work item to read exception events
- Add hci interface name while logging expception event in dmesg.

 drivers/bluetooth/btintel.h      |   1 +
 drivers/bluetooth/btintel_pcie.c | 226 ++++++++++++++++++++++++++++++-
 drivers/bluetooth/btintel_pcie.h |  23 ++++
 3 files changed, 249 insertions(+), 1 deletion(-)
drivers/bluetooth/btintel.h +1 -0
index 19530ea14905..4c21e69887a3 100644
@@ -190,6 +190,7 @@ enum {
 struct btintel_data {
        DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS);
        int (*acpi_reset_method)(struct hci_dev *hdev);
+       u32     cnvi_top;
 };
 
 #define btintel_set_flag(hdev, nr)                                     \
drivers/bluetooth/btintel_pcie.c +90 -0
index 11e2b805c7cc..f93ddd2fdb01 100644
@@ -51,6 +51,14 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);
 
  #define BTINTEL_PCIE_MAGIC_NUM    0xA5A5A5A5
 
+#define BTINTEL_PCIE_BLZR_HWEXP_SIZE           1024
+#define BTINTEL_PCIE_BLZR_HWEXP_DMP_ADDR       0xB00A7C00
+
+#define BTINTEL_PCIE_SCP_HWEXP_SIZE            4096
+#define BTINTEL_PCIE_SCP_HWEXP_DMP_ADDR                0xB030F800
+
+#define BTINTEL_PCIE_MAGIC_NUM 0xA5A5A5A5
+
 /* Alive interrupt context */
 enum {
        BTINTEL_PCIE_ROM,
@@ -353,6 +361,64 @@ static int btintel_pcie_reset_bt(struct btintel_pcie_data *data)
        return reg == 0 ? 0 : -ENODEV;
 }
 
+static void btintel_pcie_mac_init(struct btintel_pcie_data *data)
+{
+       u32 reg;
+
+       /* Set MAC_INIT bit to start primary bootloader */
+       reg = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG);
+       reg &= ~(BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_INIT |
+                       BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_DISCON |
+                       BTINTEL_PCIE_CSR_FUNC_CTRL_SW_RESET);
+       reg |= (BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_ENA |
+                       BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT);
+       btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG, reg);
+}
+
+static int btintel_pcie_get_mac_access(struct btintel_pcie_data *data)
+{
+       u32 reg;
+       int retry = 15;
+
+       reg = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG);
+
+       reg |= BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS;
+       reg |= BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ;
+       if ((reg & BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS) == 0)
+               reg |= BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ;
+
+       btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG, reg);
+
+       do {
+               reg = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG);
+               if (reg & BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS)
+                       return 0;
+               /* Need delay here for Target Access harwdware to settle down*/
+               usleep_range(1000, 1200);
+
+       } while (--retry > 0);
+
+       return -ETIME;
+}
+
+static void btintel_pcie_release_mac_access(struct btintel_pcie_data *data)
+{
+       u32 reg;
+
+       reg = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG);
+
+       if (reg & BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ)
+               reg &= ~BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ;
+
+       if (reg & BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS)
+               reg &= ~BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS;
+
+       if (reg & BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ)
+               reg &= ~BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ;
+
+       btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG, reg);
+}
+
 /* This function enables BT function by setting BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT bit in
  * BTINTEL_PCIE_CSR_FUNC_CTRL_REG register and wait for MSI-X with
  * BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0.
@@ -473,6 +539,140 @@ static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt)
        }
 }
 
+static int btintel_pcie_read_device_mem(struct btintel_pcie_data *data,
+                                       void *buf, u32 dev_addr, int len)
+{
+       int err;
+       u32 *val = buf;
+
+       /* Get device mac access */
+       err = btintel_pcie_get_mac_access(data);
+       if (err) {
+               bt_dev_err(data->hdev, "Failed to get mac access %d", err);
+               return err;
+       }
+
+       for (; len > 0; len -= 4, dev_addr += 4, val++)
+               *val = btintel_pcie_rd_dev_mem(data, dev_addr);
+
+       btintel_pcie_release_mac_access(data);
+
+       return 0;
+}
+
+static void btintel_pcie_dump_hwexp(struct btintel_pcie_data *data)
+{
+       struct btintel_data *intel_data = hci_get_priv(data->hdev);

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) · line 575

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+       int len, err, offset, pending;
+       struct sk_buff *skb;
+       u8 *buf, prefix[64];
+       u32 addr, val;
+
+       struct tlv {
+               u8      type;
+               u16     len;
+               u8      val[];
+       } __packed;

This format seems different from intel_tlv, is this intentional? This should really be part of btintel.c though alongside the likes of btintel_diagnostics.

Quoted 43 lines
drivers/bluetooth/btintel_pcie.c +43 -0
+
+       struct tlv *tlv;
+
+       switch (intel_data->cnvi_top & 0xfff) {
+       case BTINTEL_CNVI_BLAZARI:
+       case BTINTEL_CNVI_BLAZARIW:
+               /* only from step B0 onwards */
+               if (INTEL_CNVX_TOP_STEP(intel_data->cnvi_top) != 0x01)
+                       return;
+               len = BTINTEL_PCIE_BLZR_HWEXP_SIZE; /* exception data length */
+               addr = BTINTEL_PCIE_BLZR_HWEXP_DMP_ADDR;
+       break;
+       case BTINTEL_CNVI_SCP:
+               len = BTINTEL_PCIE_SCP_HWEXP_SIZE;
+               addr = BTINTEL_PCIE_SCP_HWEXP_DMP_ADDR;
+       break;
+       default:
+               bt_dev_err(data->hdev, "Unsupported cnvi 0x%8.8x", intel_data->cnvi_top);
+               return;
+       }
+
+       buf = kzalloc(len, GFP_KERNEL);
+       if (!buf)
+               goto exit_on_error;
+
+       btintel_pcie_mac_init(data);
+
+       err = btintel_pcie_read_device_mem(data, buf, addr, len);
+       if (err)
+               goto exit_on_error;
+
+       val = get_unaligned_le32(buf);
+       if (val != BTINTEL_PCIE_MAGIC_NUM) {
+               bt_dev_err(data->hdev, "Invalid exception dump signature: 0x%8.8x",
+                          val);
+               goto exit_on_error;
+       }
+
+       snprintf(prefix, sizeof(prefix), "Bluetooth: %s: ", bt_dev_name(data->hdev));
+
+       offset = 4;
+       do {
+               pending = len - offset;

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) · line 628

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+               if (pending < sizeof(*tlv))
+                       break;
+               tlv = (struct tlv *)(buf + offset);
+
+               /* If type == 0, then there are no more TLVs to be parsed */
+               if (!tlv->type) {
+                       bt_dev_dbg(data->hdev, "Invalid TLV type 0");
+                       break;
+               }
+               tlv->len = le16_to_cpu((__force __le16)tlv->len);

Weird, why not use le16 in the declaration?

Quoted 9 lines
drivers/bluetooth/btintel_pcie.c +9 -0
+               offset += sizeof(*tlv);
+               pending = len - offset;
+               if (tlv->len > pending)
+                       break;
+
+               offset += tlv->len;
+
+                /* Only TLVs of type == 1 are HCI events, no need to process other
+                 * TLVs

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) · line 647

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+                 */
+               if (tlv->type != 1)
+                       continue;
+
+               bt_dev_dbg(data->hdev, "TLV packet length: %u", tlv->len);
+               if (tlv->len > HCI_MAX_EVENT_SIZE)
+                       break;
+               skb = bt_skb_alloc(tlv->len, GFP_KERNEL);
+               if (!skb)
+                       goto exit_on_error;

If we are going to create an skb then perhaps we should create it earlier and then use its function to part the tlv (e.g. skb_pull_data, etc).

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) · line 660

Quoted 13 lines
drivers/bluetooth/btintel_pcie.c +13 -0
+               hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
+               skb_put_data(skb, tlv->val, tlv->len);
+
+               /* copy Intel specific pcie packet type */
+               val = BTINTEL_PCIE_HCI_EVT_PKT;
+               memcpy(skb_push(skb, BTINTEL_PCIE_HCI_TYPE_LEN), &val,
+                      BTINTEL_PCIE_HCI_TYPE_LEN);
+
+               print_hex_dump(KERN_DEBUG, prefix, DUMP_PREFIX_OFFSET, 16, 1,
+                              tlv->val, tlv->len, false);
+
+               skb_queue_tail(&data->rx_skb_q, skb);
+               queue_work(data->workqueue, &data->rx_work);

So all this exercise was just to create an skb out of the data and then again trigger rx_work? I don't think it is worth adding a work just to do that, especially since if there is an exception then the rx_work will probably not be doing anything until the recovery kicks in.

Quoted 24 lines
drivers/bluetooth/btintel_pcie.c +17 -0
+       } while (offset < len);
+
+exit_on_error:
+       kfree(buf);
+}
+
+static void btintel_pcie_hwexp_work(struct work_struct *work)
+{
+       struct btintel_pcie_data *data = container_of(work,
+                                       struct btintel_pcie_data, hwexp_work);
+       btintel_pcie_dump_hwexp(data);
+
+       clear_bit(BTINTEL_PCIE_HWEXP_INPROGRESS, &data->flags);
+}
+
 /* This function handles the MSI-X interrupt for gp0 cause (bit 0 in
  * BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES) which is sent for boot stage and image response.
  */
@@ -794,6 +994,20 @@ static int btintel_pcie_recv_frame(struct btintel_pcie_data *data,
        return ret;
 }
 
+static void btintel_pcie_msix_hw_exp_handler(struct btintel_pcie_data *data)
+{

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_recv_frame(struct btintel_pcie_data *data, · line 1008

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+       bt_dev_err(data->hdev, "Received hw exception interrupt");
+       if (test_and_set_bit(BTINTEL_PCIE_HWEXP_INPROGRESS, &data->flags))
+               return;
+       /* Unlike usb products, there will be no hardware event sent by
+        * controller on exception. Instead, controller writes the hardware error
+        * event along with optional debug events in devie memory and halts. Driver
+        * shall read the events from device memory, construct skbs and push
+        * to rx_work item for further processing.
+        */
+       queue_work(data->workqueue, &data->hwexp_work);

So this is in an interrupt context, right? In that case we probably can't process it directly, but I don't think it would be a problem to process it on rx_work/btintel_pcie_rx_work since you can use BTINTEL_PCIE_HWEXP_INPROGRESS to check that there is a exception to be processed.

Quoted 129 lines
drivers/bluetooth/btintel_pcie.c +13 -1
+}
+
 static void btintel_pcie_rx_work(struct work_struct *work)
 {
        struct btintel_pcie_data *data = container_of(work,
@@ -920,6 +1134,10 @@ static irqreturn_t btintel_pcie_irq_msix_handler(int irq, void *dev_id)
                return IRQ_NONE;
        }
 
+       /* This interrupt is raised when there is an hardware exception */
+       if (intr_hw & BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP)
+               btintel_pcie_msix_hw_exp_handler(data);
+
        /* This interrupt is triggered by the firmware after updating
         * boot_stage register and image_response register
         */
@@ -1000,7 +1218,8 @@ struct btintel_pcie_causes_list {
 static struct btintel_pcie_causes_list causes_list[] = {
        { BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0,    BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK,      0x00 },
        { BTINTEL_PCIE_MSIX_FH_INT_CAUSES_1,    BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK,      0x01 },
-       { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0, BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK,       0x20 },
+       { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0,  BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK,      0x20 },
+       { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP, BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK,     0x23 },
 };
 
 /* This function configures the interrupt masks for both HW_INT_CAUSES and
@@ -1482,6 +1701,7 @@ static void btintel_pcie_release_hdev(struct btintel_pcie_data *data)
 
 static int btintel_pcie_setup_internal(struct hci_dev *hdev)
 {
+       struct btintel_data *data = hci_get_priv(hdev);
        const u8 param[1] = { 0xFF };
        struct intel_version_tlv ver_tlv;
        struct sk_buff *skb;
@@ -1520,6 +1740,7 @@ static int btintel_pcie_setup_internal(struct hci_dev *hdev)
                goto exit_error;
        }
 
+       data->cnvi_top = ver_tlv.cnvi_top;
        switch (INTEL_HW_PLATFORM(ver_tlv.cnvi_bt)) {
        case 0x37:
                break;
@@ -1667,6 +1888,8 @@ static int btintel_pcie_probe(struct pci_dev *pdev,
        skb_queue_head_init(&data->rx_skb_q);
        INIT_WORK(&data->rx_work, btintel_pcie_rx_work);
 
+       INIT_WORK(&data->hwexp_work, btintel_pcie_hwexp_work);
+
        data->boot_stage_cache = 0x00;
        data->img_resp_cache = 0x00;
 
@@ -1731,6 +1954,7 @@ static void btintel_pcie_remove(struct pci_dev *pdev)
        btintel_pcie_release_hdev(data);
 
        flush_work(&data->rx_work);
+       flush_work(&data->hwexp_work);
 
        destroy_workqueue(data->workqueue);
 
drivers/bluetooth/btintel_pcie.h +23 -1
index b9d32393002b..98902fd4fc96 100644
@@ -16,6 +16,8 @@
 #define BTINTEL_PCIE_CSR_CI_ADDR_LSB_REG       (BTINTEL_PCIE_CSR_BASE + 0x118)
 #define BTINTEL_PCIE_CSR_CI_ADDR_MSB_REG       (BTINTEL_PCIE_CSR_BASE + 0x11C)
 #define BTINTEL_PCIE_CSR_IMG_RESPONSE_REG      (BTINTEL_PCIE_CSR_BASE + 0x12C)
+#define BTINTEL_PCIE_PRPH_DEV_ADDR_REG         (BTINTEL_PCIE_CSR_BASE + 0x440)
+#define BTINTEL_PCIE_PRPH_DEV_RD_REG           (BTINTEL_PCIE_CSR_BASE + 0x458)
 #define BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR       (BTINTEL_PCIE_CSR_BASE + 0x460)
 
 /* BTINTEL_PCIE_CSR Function Control Register */
@@ -23,6 +25,12 @@
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT            (BIT(6))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_INIT           (BIT(7))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS      (BIT(20))
+
+#define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ      (BIT(21))
+/* Stop MAC Access disconnection request */
+#define BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS (BIT(22))
+#define BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ                (BIT(23))
+
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_STS      (BIT(28))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_DISCON   (BIT(29))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_SW_RESET            (BIT(31))
@@ -72,6 +80,7 @@ enum msix_fh_int_causes {
 /* Causes for the HW register interrupts */
 enum msix_hw_int_causes {
        BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0     = BIT(0),       /* cause 32 */
+       BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP   = BIT(3),       /* cause 35 */
 };
 
 /* PCIe device states
@@ -84,6 +93,11 @@ enum {
        BTINTEL_PCIE_STATE_D3_HOT = 2,
        BTINTEL_PCIE_STATE_D3_COLD = 3,
 };
+
+enum {
+       BTINTEL_PCIE_HWEXP_INPROGRESS,
+};
+
 #define BTINTEL_PCIE_MSIX_NON_AUTO_CLEAR_CAUSE BIT(7)
 
 /* Minimum and Maximum number of MSI-X Vector
@@ -437,6 +451,7 @@ struct btintel_pcie_data {
        struct rxq      rxq;
        u32     alive_intr_ctxt;
        struct btintel_pcie_dbgc        dbgc;
+       struct work_struct      hwexp_work;
 };
 
 static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data,
@@ -476,3 +491,11 @@ static inline void btintel_pcie_clr_reg_bits(struct btintel_pcie_data *data,
        r &= ~bits;
        iowrite32(r, data->base_addr + offset);
 }
+
+static inline u32 btintel_pcie_rd_dev_mem(struct btintel_pcie_data *data,
+                                         u32 addr)
+{
+       btintel_pcie_wr_reg32(data, BTINTEL_PCIE_PRPH_DEV_ADDR_REG, addr);
+       return btintel_pcie_rd_reg32(data, BTINTEL_PCIE_PRPH_DEV_RD_REG);
+}
+
--

2.43.0

Signature · 1 line
Luiz Augusto von Dentz
author
#3 lore raw

RE: [PATCH v2 2/4] Bluetooth: btintel_pcie: Read hardware exception data

Hi Luiz,

Quoted 162 lines

Subject: Re: [PATCH v2 2/4] Bluetooth: btintel_pcie: Read hardware exception data

Hi Kiran,

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_reset_bt(struct

Quoted 54 lines · Kiran K

On hardware error, controller writes hardware error event and optional vendor specific hci events in device memory in TLV format and raises MSIX interrupt. Driver reads the device memory and passes the events to the stack for further processing.

---
v1 --> v2:
- Add comments for the delay added in MAC for target acess
- Add comment for having a seperate work item to read exception events
- Add hci interface name while logging expception event in dmesg.

 drivers/bluetooth/btintel.h      |   1 +
 drivers/bluetooth/btintel_pcie.c | 226
++++++++++++++++++++++++++++++-  drivers/bluetooth/btintel_pcie.h |
23 ++++
 3 files changed, 249 insertions(+), 1 deletion(-)
drivers/bluetooth/btintel.h +1 -0
index 19530ea14905..4c21e69887a3 100644
@@ -190,6 +190,7 @@ enum {
 struct btintel_data {
        DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS);
        int (*acpi_reset_method)(struct hci_dev *hdev);
+       u32     cnvi_top;
 };
 
 #define btintel_set_flag(hdev, nr)                                     \
drivers/bluetooth/btintel_pcie.c +8 -0
index 11e2b805c7cc..f93ddd2fdb01 100644
@@ -51,6 +51,14 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);
 
  #define BTINTEL_PCIE_MAGIC_NUM    0xA5A5A5A5
 
+#define BTINTEL_PCIE_BLZR_HWEXP_SIZE           1024
+#define BTINTEL_PCIE_BLZR_HWEXP_DMP_ADDR       0xB00A7C00
+
+#define BTINTEL_PCIE_SCP_HWEXP_SIZE            4096
+#define BTINTEL_PCIE_SCP_HWEXP_DMP_ADDR                0xB030F800
+
+#define BTINTEL_PCIE_MAGIC_NUM 0xA5A5A5A5
+
 /* Alive interrupt context */
 enum {
        BTINTEL_PCIE_ROM,
@@ -353,6 +361,64 @@ static int btintel_pcie_reset_bt(struct

btintel_pcie_data *data)

Quoted 23 lines
drivers/bluetooth/btintel_pcie.c +21 -0
        return reg == 0 ? 0 : -ENODEV;  }
 
+static void btintel_pcie_mac_init(struct btintel_pcie_data *data) {
+       u32 reg;
+
+       /* Set MAC_INIT bit to start primary bootloader */
+       reg = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG);
+       reg &= ~(BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_INIT |
+                       BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_DISCON |
+                       BTINTEL_PCIE_CSR_FUNC_CTRL_SW_RESET);
+       reg |= (BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_ENA |
+                       BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT);
+       btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG,
+reg); }
+
+static int btintel_pcie_get_mac_access(struct btintel_pcie_data
+*data) {
+       u32 reg;
+       int retry = 15;
+
+       reg = btintel_pcie_rd_reg32(data,
+ BTINTEL_PCIE_CSR_FUNC_CTRL_REG);
+

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_reset_bt(struct btintel_pcie_data *data)

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+       reg |= BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS;
+       reg |= BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ;
+       if ((reg & BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS) == 0)
+               reg |= BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ;
+
+       btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG,
+ reg);
+
+       do {
+               reg = btintel_pcie_rd_reg32(data,

BTINTEL_PCIE_CSR_FUNC_CTRL_REG);

Quoted 21 lines
drivers/bluetooth/btintel_pcie.c +21 -0
+               if (reg & BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS)
+                       return 0;
+               /* Need delay here for Target Access harwdware to settle down*/
+               usleep_range(1000, 1200);
+
+       } while (--retry > 0);
+
+       return -ETIME;
+}
+
+static void btintel_pcie_release_mac_access(struct btintel_pcie_data
+*data) {
+       u32 reg;
+
+       reg = btintel_pcie_rd_reg32(data,
+ BTINTEL_PCIE_CSR_FUNC_CTRL_REG);
+
+       if (reg & BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ)
+               reg &= ~BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ;
+
+       if (reg & BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS)

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_reset_bt(struct btintel_pcie_data *data)

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +9 -0
+               reg &=
+ ~BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS;
+
+       if (reg & BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ)
+               reg &= ~BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ;
+
+       btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_FUNC_CTRL_REG,
+reg); }
+
 /* This function enables BT function by setting

BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT bit in

drivers/bluetooth/btintel_pcie.c static inline char

Quoted 3 lines
drivers/bluetooth/btintel_pcie.c +0 -0
  * BTINTEL_PCIE_CSR_FUNC_CTRL_REG register and wait for MSI-X with
  * BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0.
@@ -473,6 +539,140 @@ static inline char

*btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt)

Quoted 31 lines
drivers/bluetooth/btintel_pcie.c +28 -0
        }
 }
 
+static int btintel_pcie_read_device_mem(struct btintel_pcie_data *data,
+                                       void *buf, u32 dev_addr, int
+len) {
+       int err;
+       u32 *val = buf;
+
+       /* Get device mac access */
+       err = btintel_pcie_get_mac_access(data);
+       if (err) {
+               bt_dev_err(data->hdev, "Failed to get mac access %d", err);
+               return err;
+       }
+
+       for (; len > 0; len -= 4, dev_addr += 4, val++)
+               *val = btintel_pcie_rd_dev_mem(data, dev_addr);
+
+       btintel_pcie_release_mac_access(data);
+
+       return 0;
+}
+
+static void btintel_pcie_dump_hwexp(struct btintel_pcie_data *data) {
+       struct btintel_data *intel_data = hci_get_priv(data->hdev);
+       int len, err, offset, pending;
+       struct sk_buff *skb;
+       u8 *buf, prefix[64];
+       u32 addr, val;
+
Quoted 8 lines

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) · line 575

Quoted 5 lines
drivers/bluetooth/btintel_pcie.c +5 -0
+       struct tlv {
+               u8      type;
+               u16     len;
+               u8      val[];
+       } __packed;

This format seems different from intel_tlv, is this intentional? This should really be part of btintel.c though alongside the likes of btintel_diagnostics.

This is intentional. The length filed defined here is of size u16 and the one defined in btintel.h is u8.
u16 is used here as the there an non HCI events related to debug whose size is more than 256 bytes.

Quoted 51 lines
Quoted 26 lines
drivers/bluetooth/btintel_pcie.c +24 -0
+
+       struct tlv *tlv;
+
+       switch (intel_data->cnvi_top & 0xfff) {
+       case BTINTEL_CNVI_BLAZARI:
+       case BTINTEL_CNVI_BLAZARIW:
+               /* only from step B0 onwards */
+               if (INTEL_CNVX_TOP_STEP(intel_data->cnvi_top) != 0x01)
+                       return;
+               len = BTINTEL_PCIE_BLZR_HWEXP_SIZE; /* exception data length */
+               addr = BTINTEL_PCIE_BLZR_HWEXP_DMP_ADDR;
+       break;
+       case BTINTEL_CNVI_SCP:
+               len = BTINTEL_PCIE_SCP_HWEXP_SIZE;
+               addr = BTINTEL_PCIE_SCP_HWEXP_DMP_ADDR;
+       break;
+       default:
+               bt_dev_err(data->hdev, "Unsupported cnvi 0x%8.8x", intel_data-
 cnvi_top);
+               return;
+       }
+
+       buf = kzalloc(len, GFP_KERNEL);
+       if (!buf)
+               goto exit_on_error;

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt)

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+
+       btintel_pcie_mac_init(data);
+
+       err = btintel_pcie_read_device_mem(data, buf, addr, len);
+       if (err)
+               goto exit_on_error;
+
+       val = get_unaligned_le32(buf);
+       if (val != BTINTEL_PCIE_MAGIC_NUM) {
+               bt_dev_err(data->hdev, "Invalid exception dump signature:

0x%8.8x",

Quoted 14 lines
drivers/bluetooth/btintel_pcie.c +14 -0
+                          val);
+               goto exit_on_error;
+       }
+
+       snprintf(prefix, sizeof(prefix), "Bluetooth: %s: ",
+ bt_dev_name(data->hdev));
+
+       offset = 4;
+       do {
+               pending = len - offset;
+               if (pending < sizeof(*tlv))
+                       break;
+               tlv = (struct tlv *)(buf + offset);
+
Quoted 8 lines

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) · line 628

Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +6 -0
+               /* If type == 0, then there are no more TLVs to be parsed */
+               if (!tlv->type) {
+                       bt_dev_dbg(data->hdev, "Invalid TLV type 0");
+                       break;
+               }
+               tlv->len = le16_to_cpu((__force __le16)tlv->len);

Weird, why not use le16 in the declaration?

Ack.

Quoted 15 lines
Quoted 15 lines
drivers/bluetooth/btintel_pcie.c +14 -0
+               offset += sizeof(*tlv);
+               pending = len - offset;
+               if (tlv->len > pending)
+                       break;
+
+               offset += tlv->len;
+
+                /* Only TLVs of type == 1 are HCI events, no need to process other
+                 * TLVs
+                 */
+               if (tlv->type != 1)
+                       continue;
+
+               bt_dev_dbg(data->hdev, "TLV packet length: %u", tlv->len);
Quoted 8 lines

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) · line 647

Quoted 5 lines
drivers/bluetooth/btintel_pcie.c +5 -0
+               if (tlv->len > HCI_MAX_EVENT_SIZE)
+                       break;
+               skb = bt_skb_alloc(tlv->len, GFP_KERNEL);
+               if (!skb)
+                       goto exit_on_error;

If we are going to create an skb then perhaps we should create it earlier and then use its function to part the tlv (e.g. skb_pull_data, etc).

Not sure if I got this one correctly. The device memory can contain multiple HCI events and driver creates skb for each of the TLV.

Quoted 16 lines

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt)

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +9 -0
+               hci_skb_pkt_type(skb) = HCI_EVENT_PKT;
+               skb_put_data(skb, tlv->val, tlv->len);
+
+               /* copy Intel specific pcie packet type */
+               val = BTINTEL_PCIE_HCI_EVT_PKT;
+               memcpy(skb_push(skb, BTINTEL_PCIE_HCI_TYPE_LEN), &val,
+                      BTINTEL_PCIE_HCI_TYPE_LEN);
+
+               print_hex_dump(KERN_DEBUG, prefix, DUMP_PREFIX_OFFSET, 16,

1,

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt) · line 660

Quoted 4 lines
drivers/bluetooth/btintel_pcie.c +4 -0
+                              tlv->val, tlv->len, false);
+
+               skb_queue_tail(&data->rx_skb_q, skb);
+               queue_work(data->workqueue, &data->rx_work);
Quoted 4 lines

So all this exercise was just to create an skb out of the data and then again trigger rx_work? I don't think it is worth adding a work just to do that, especially since if there is an exception then the rx_work will probably not be doing anything until the recovery kicks in.

Ack.

Quoted 37 lines
Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +5 -0
+       } while (offset < len);
+
+exit_on_error:
+       kfree(buf);
+}

drivers/bluetooth/btintel_pcie.c static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt)

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +8 -0
+
+static void btintel_pcie_hwexp_work(struct work_struct *work) {
+       struct btintel_pcie_data *data = container_of(work,
+                                       struct btintel_pcie_data, hwexp_work);
+       btintel_pcie_dump_hwexp(data);
+
+       clear_bit(BTINTEL_PCIE_HWEXP_INPROGRESS, &data->flags); }
+
 /* This function handles the MSI-X interrupt for gp0 cause (bit 0 in
  * BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES) which is sent for boot stage

and image response.

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_recv_frame(struct

Quoted 2 lines
drivers/bluetooth/btintel_pcie.c +0 -0
  */
@@ -794,6 +994,20 @@ static int btintel_pcie_recv_frame(struct

btintel_pcie_data *data,

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_recv_frame(struct btintel_pcie_data *data,

Quoted 11 lines
drivers/bluetooth/btintel_pcie.c +8 -0
        return ret;
 }
 
+static void btintel_pcie_msix_hw_exp_handler(struct btintel_pcie_data
+*data) {
+       bt_dev_err(data->hdev, "Received hw exception interrupt");
+       if (test_and_set_bit(BTINTEL_PCIE_HWEXP_INPROGRESS, &data->flags))
+               return;
+       /* Unlike usb products, there will be no hardware event sent by
+        * controller on exception. Instead, controller writes the hardware error
+        * event along with optional debug events in devie memory and halts.

Driver

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_recv_frame(struct btintel_pcie_data *data, · line 1008

Quoted 4 lines
drivers/bluetooth/btintel_pcie.c +4 -0
+        * shall read the events from device memory, construct skbs and push
+        * to rx_work item for further processing.
+        */
+       queue_work(data->workqueue, &data->hwexp_work);
Quoted 5 lines

So this is in an interrupt context, right? In that case we probably can't process it directly, but I don't think it would be a problem to process it on rx_work/btintel_pcie_rx_work since you can use BTINTEL_PCIE_HWEXP_INPROGRESS to check that there is a exception to be processed.

Yes. This is called in an interrupt context.

Quoted 135 lines

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_recv_frame(struct · line 1013

Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +3 -0
+}
+
 static void btintel_pcie_rx_work(struct work_struct *work)  {
        struct btintel_pcie_data *data = container_of(work, @@ -920,6
+1134,10 @@ static irqreturn_t btintel_pcie_irq_msix_handler(int irq, void

*dev_id)

drivers/bluetooth/btintel_pcie.c struct btintel_pcie_causes_list { static struct · line 1219

Quoted 13 lines
drivers/bluetooth/btintel_pcie.c +4 -0
                return IRQ_NONE;
        }
 
+       /* This interrupt is raised when there is an hardware exception */
+       if (intr_hw & BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP)
+               btintel_pcie_msix_hw_exp_handler(data);
+
        /* This interrupt is triggered by the firmware after updating
         * boot_stage register and image_response register
         */
@@ -1000,7 +1218,8 @@ struct btintel_pcie_causes_list {  static struct
 btintel_pcie_causes_list causes_list[] = {
        { BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0,

BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK, 0x00 },

drivers/bluetooth/btintel_pcie.c struct btintel_pcie_causes_list { static struct · line 1220

Quoted 1 line
drivers/bluetooth/btintel_pcie.c +0 -0
        { BTINTEL_PCIE_MSIX_FH_INT_CAUSES_1,

BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK, 0x01 },

drivers/bluetooth/btintel_pcie.c struct btintel_pcie_causes_list { static struct · line 1003

Quoted 1 line
drivers/bluetooth/btintel_pcie.c +0 -1
-       { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0,

BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK, 0x20 },

drivers/bluetooth/btintel_pcie.c struct btintel_pcie_causes_list { static struct · line 1221

Quoted 1 line
drivers/bluetooth/btintel_pcie.c +1 -0
+       { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0,

BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK, 0x20 },

drivers/bluetooth/btintel_pcie.c struct btintel_pcie_causes_list { static struct · line 1222

Quoted 1 line
drivers/bluetooth/btintel_pcie.c +1 -0
+       { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP,

BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK, 0x23 },

drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup_internal(struct hci_dev

Quoted 12 lines
drivers/bluetooth/btintel_pcie.c +0 -0
 };
 
 /* This function configures the interrupt masks for both

HW_INT_CAUSES and @@ -1482,6 +1701,7 @@ static void btintel_pcie_release_hdev(struct btintel_pcie_data *data)

static int btintel_pcie_setup_internal(struct hci_dev *hdev) {

drivers/bluetooth/btintel_pcie.c +1 -0
+       struct btintel_data *data = hci_get_priv(hdev);
        const u8 param[1] = { 0xFF };
        struct intel_version_tlv ver_tlv;
        struct sk_buff *skb;
@@ -1520,6 +1740,7 @@ static int btintel_pcie_setup_internal(struct hci_dev

*hdev)

drivers/bluetooth/btintel_pcie.c static void btintel_pcie_remove(struct pci_dev

Quoted 17 lines
drivers/bluetooth/btintel_pcie.c +3 -0
                goto exit_error;
        }
 
+       data->cnvi_top = ver_tlv.cnvi_top;
        switch (INTEL_HW_PLATFORM(ver_tlv.cnvi_bt)) {
        case 0x37:
                break;
@@ -1667,6 +1888,8 @@ static int btintel_pcie_probe(struct pci_dev *pdev,
        skb_queue_head_init(&data->rx_skb_q);
        INIT_WORK(&data->rx_work, btintel_pcie_rx_work);
 
+       INIT_WORK(&data->hwexp_work, btintel_pcie_hwexp_work);
+
        data->boot_stage_cache = 0x00;
        data->img_resp_cache = 0x00;
 
@@ -1731,6 +1954,7 @@ static void btintel_pcie_remove(struct pci_dev

*pdev)

Quoted 13 lines
drivers/bluetooth/btintel_pcie.c +1 -0
        btintel_pcie_release_hdev(data);
 
        flush_work(&data->rx_work);
+       flush_work(&data->hwexp_work);
 
        destroy_workqueue(data->workqueue);
 
drivers/bluetooth/btintel_pcie.h +0 -0
index b9d32393002b..98902fd4fc96 100644

drivers/bluetooth/btintel_pcie.h line 16

Quoted 1 line
drivers/bluetooth/btintel_pcie.h +0 -0
@@ -16,6 +16,8 @@
 #define BTINTEL_PCIE_CSR_CI_ADDR_LSB_REG       (BTINTEL_PCIE_CSR_BASE

+ 0x118)

drivers/bluetooth/btintel_pcie.h line 17

Quoted 1 line
drivers/bluetooth/btintel_pcie.h +0 -0
 #define BTINTEL_PCIE_CSR_CI_ADDR_MSB_REG

(BTINTEL_PCIE_CSR_BASE + 0x11C)

drivers/bluetooth/btintel_pcie.h line 18

Quoted 1 line
drivers/bluetooth/btintel_pcie.h +0 -0
 #define BTINTEL_PCIE_CSR_IMG_RESPONSE_REG

(BTINTEL_PCIE_CSR_BASE + 0x12C)

drivers/bluetooth/btintel_pcie.h line 19

Quoted 1 line
drivers/bluetooth/btintel_pcie.h +1 -0
+#define BTINTEL_PCIE_PRPH_DEV_ADDR_REG

(BTINTEL_PCIE_CSR_BASE + 0x440)

drivers/bluetooth/btintel_pcie.h line 20

Quoted 1 line
drivers/bluetooth/btintel_pcie.h +1 -0
+#define BTINTEL_PCIE_PRPH_DEV_RD_REG           (BTINTEL_PCIE_CSR_BASE

+ 0x458)

drivers/bluetooth/btintel_pcie.h line 21

Quoted 1 line
drivers/bluetooth/btintel_pcie.h +0 -0
 #define BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR

(BTINTEL_PCIE_CSR_BASE + 0x460)

Quoted 15 lines
drivers/bluetooth/btintel_pcie.h +0 -0
 /* BTINTEL_PCIE_CSR Function Control Register */ @@ -23,6 +25,12 @@
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT            (BIT(6))

#define BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_INIT (BIT(7))
#define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS (BIT(20))

drivers/bluetooth/btintel_pcie.h +6 -0
+
+#define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_REQ      (BIT(21))
+/* Stop MAC Access disconnection request */ #define
+BTINTEL_PCIE_CSR_FUNC_CTRL_STOP_MAC_ACCESS_DIS (BIT(22))
+#define BTINTEL_PCIE_CSR_FUNC_CTRL_XTAL_CLK_REQ                (BIT(23))
+
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_STS      (BIT(28))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_DISCON   (BIT(29))
 #define BTINTEL_PCIE_CSR_FUNC_CTRL_SW_RESET            (BIT(31))

drivers/bluetooth/btintel_pcie.h enum msix_fh_int_causes { · line 83

Quoted 4 lines
drivers/bluetooth/btintel_pcie.h +1 -0
@@ -72,6 +80,7 @@ enum msix_fh_int_causes {
 /* Causes for the HW register interrupts */  enum msix_hw_int_causes
 {
        BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0     = BIT(0),       /* cause 32 */
+       BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP   = BIT(3),       /* cause

35 */

Quoted 21 lines
drivers/bluetooth/btintel_pcie.h +5 -0
 };
 
 /* PCIe device states
@@ -84,6 +93,11 @@ enum {
        BTINTEL_PCIE_STATE_D3_HOT = 2,
        BTINTEL_PCIE_STATE_D3_COLD = 3,  };
+
+enum {
+       BTINTEL_PCIE_HWEXP_INPROGRESS, };
+
 #define BTINTEL_PCIE_MSIX_NON_AUTO_CLEAR_CAUSE BIT(7)
 
 /* Minimum and Maximum number of MSI-X Vector @@ -437,6 +451,7 @@
 struct btintel_pcie_data {
        struct rxq      rxq;
        u32     alive_intr_ctxt;
        struct btintel_pcie_dbgc        dbgc;
+       struct work_struct      hwexp_work;
 };
 
 static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data
Quoted 1 line

*data, @@ -476,3 +491,11 @@ static inline void

btintel_pcie_clr_reg_bits(struct btintel_pcie_data *data,

drivers/bluetooth/btintel_pcie.h static inline void btintel_pcie_clr_reg_bits(struct btintel_pcie_data *data,

Quoted 6 lines
        r &= ~bits;
        iowrite32(r, data->base_addr + offset);  }
drivers/bluetooth/btintel_pcie.h +4 -0
+
+static inline u32 btintel_pcie_rd_dev_mem(struct btintel_pcie_data *data,
+                                         u32 addr) {
+       btintel_pcie_wr_reg32(data, BTINTEL_PCIE_PRPH_DEV_ADDR_REG,

addr);

Quoted 11 lines
Quoted 7 lines
drivers/bluetooth/btintel_pcie.h +3 -1
+       return btintel_pcie_rd_reg32(data,
+BTINTEL_PCIE_PRPH_DEV_RD_REG); }
+
--

2.43.0

--
Luiz Augusto von Dentz

Thanks,
Kiran

author
#4 lore raw

PATCH v2 3/4 Bluetooth: btintel_pcie: Add support for device coredump

In reply to Kiran K

1. Driver registers device coredump callback
2. Dumps firmware traces as part of coredump

---
v1->v2:
No change

 drivers/bluetooth/btintel.h      |   1 -
 drivers/bluetooth/btintel_pcie.c | 272 ++++++++++++++++++++++++++++++-
 drivers/bluetooth/btintel_pcie.h |  39 +++++
 3 files changed, 305 insertions(+), 7 deletions(-)
drivers/bluetooth/btintel.h +0 -1
index 4c21e69887a3..19530ea14905 100644
@@ -190,7 +190,6 @@ enum {
 struct btintel_data {
 	DECLARE_BITMAP(flags, __INTEL_NUM_FLAGS);
 	int (*acpi_reset_method)(struct hci_dev *hdev);
-	u32	cnvi_top;
 };
 
 #define btintel_set_flag(hdev, nr)					\
drivers/bluetooth/btintel_pcie.c +266 -6

370 lines not on this page · raw message

drivers/bluetooth/btintel_pcie.h +39 -0
index 98902fd4fc96..c13f17100a74 100644
@@ -56,6 +56,15 @@
 #define BTINTEL_PCIE_CSR_MSIX_IVAR_BASE		(BTINTEL_PCIE_CSR_MSIX_BASE + 0x0880)
 #define BTINTEL_PCIE_CSR_MSIX_IVAR(cause)	(BTINTEL_PCIE_CSR_MSIX_IVAR_BASE + (cause))
 
+/* IOSF Debug Register */
+#define BTINTEL_PCIE_DBGC_BASE_ADDR			(0xf3800300)
+#define BTINTEL_PCIE_DBGC_CUR_DBGBUFF_STATUS		(BTINTEL_PCIE_DBGC_BASE_ADDR + 0x1C)
+#define BTINTEL_PCIE_DBGC_DBGBUFF_WRAP_ARND		(BTINTEL_PCIE_DBGC_BASE_ADDR + 0x2C)
+
+#define BTINTEL_PCIE_DBG_IDX_BIT_MASK		0x0F
+#define BTINTEL_PCIE_DBGC_DBG_BUF_IDX(data)	(((data) >> 24) & BTINTEL_PCIE_DBG_IDX_BIT_MASK)
+#define BTINTEL_PCIE_DBG_OFFSET_BIT_MASK	0xFFFFFF
+
 /* The DRAM buffer count, each buffer size, and
  * fragment buffer size
  */
@@ -96,6 +105,19 @@ enum {
 
 enum {
 	BTINTEL_PCIE_HWEXP_INPROGRESS,
+	BTINTEL_PCIE_COREDUMP_INPROGRESS
+};
+
+enum btintel_pcie_tlv_type {
+	BTINTEL_CNVI_BT,
+	BTINTEL_WRITE_PTR,
+	BTINTEL_WRAP_CTR,
+	BTINTEL_TRIGGER_REASON,
+	BTINTEL_FW_SHA,
+	BTINTEL_CNVR_TOP,
+	BTINTEL_CNVI_TOP,
+	BTINTEL_DUMP_TIME,
+	BTINTEL_FW_BUILD,
 };
 
 #define BTINTEL_PCIE_MSIX_NON_AUTO_CLEAR_CAUSE	BIT(7)
@@ -370,6 +392,21 @@ struct btintel_pcie_dbgc {
 	struct data_buf *bufs;
 };
 
+struct btintel_pcie_dump_header {
+	const char	*driver_name;
+	u32		cnvi_top;
+	u32		cnvr_top;
+	u16		fw_timestamp;
+	u8		fw_build_type;
+	u32		fw_build_num;
+	u32		fw_git_sha1;
+	u32		cnvi_bt;
+	u32		write_ptr;
+	u32		wrap_ctr;
+	u16		trigger_reason;
+	int		state;
+};
+
 /* struct btintel_pcie_data
  * @pdev: pci device
  * @hdev: hdev device
@@ -452,6 +489,8 @@ struct btintel_pcie_data {
 	u32	alive_intr_ctxt;
 	struct btintel_pcie_dbgc	dbgc;
 	struct work_struct	hwexp_work;
+	struct work_struct	coredump_work;
+	struct btintel_pcie_dump_header dmp_hdr;
 };
 
 static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data,
Signature · 1 line
2.43.0
author
#5 lore raw

PATCH v2 4/4 Bluetooth: btintel_pcie: Trigger device coredump on exception

In reply to Kiran K

Driver dumps device core dump on firmware exception.

---
v1->v2:
No change.

 drivers/bluetooth/btintel_pcie.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/bluetooth/btintel_pcie.c +2 -0
index 3a46ad7ec0ee..7db3a2979c9b 100644
@@ -60,6 +60,7 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);
 #define BTINTEL_PCIE_MAGIC_NUM	0xA5A5A5A5
 
 #define BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER	0x17A2
+#define BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT		0x1E61
 
 /* Alive interrupt context */
 enum {
@@ -1225,6 +1226,7 @@ static void btintel_pcie_do_firmware_dump(struct btintel_pcie_data *data, u16 tr
 static void btintel_pcie_msix_hw_exp_handler(struct btintel_pcie_data *data)
 {
 	bt_dev_err(data->hdev, "Received hw exception interrupt");
+	btintel_pcie_do_firmware_dump(data, BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT);
 	if (test_and_set_bit(BTINTEL_PCIE_HWEXP_INPROGRESS, &data->flags))
 		return;
 	/* Unlike usb products, there will be no hardware event sent by
Signature · 1 line
2.43.0
#6 lore raw
In reply to Kiran K

Hi Kiran,

Quoted 93 lines · Kiran K

This patch allocates the host memory which is used by controller to dump the firmware traces. The memory needs to be shared with controller via context information.

---
v1 -> v2:
No change

 drivers/bluetooth/btintel_pcie.c | 89 ++++++++++++++++++++++++++++++++
 drivers/bluetooth/btintel_pcie.h | 32 ++++++++++++
 2 files changed, 121 insertions(+)
drivers/bluetooth/btintel_pcie.c +62 -0
index b8b241a92bf9..11e2b805c7cc 100644
@@ -49,6 +49,8 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);
 #define BTINTEL_PCIE_HCI_EVT_PKT       0x00000004
 #define BTINTEL_PCIE_HCI_ISO_PKT       0x00000005
 
+ #define BTINTEL_PCIE_MAGIC_NUM    0xA5A5A5A5
+
 /* Alive interrupt context */
 enum {
        BTINTEL_PCIE_ROM,
@@ -60,6 +62,83 @@ enum {
        BTINTEL_PCIE_D3
 };
 
+/* Structure for dbgc fragment buffer
+ * @buf_addr_lsb: LSB of the buffer's physical address
+ * @buf_addr_msb: MSB of the buffer's physical address
+ * @buf_size: Total size of the buffer
+ */
+struct btintel_pcie_dbgc_ctxt_buf {
+       u32     buf_addr_lsb;
+       u32     buf_addr_msb;
+       u32     buf_size;
+};
+
+/* Structure for dbgc fragment
+ * @magic_num: 0XA5A5A5A5
+ * @ver: For Driver-FW compatibility
+ * @total_size: Total size of the payload debug info
+ * @num_buf: Num of allocated debug bufs
+ * @bufs: All buffer's addresses and sizes
+ */
+struct btintel_pcie_dbgc_ctxt {
+       u32     magic_num;
+       u32     ver;
+       u32     total_size;
+       u32     num_buf;
+       struct btintel_pcie_dbgc_ctxt_buf bufs[BTINTEL_PCIE_DBGC_BUFFER_COUNT];
+};
+
+/* This function initializes the memory for DBGC buffers and formats the
+ * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and
+ * size as the payload
+ */
+static int btintel_pcie_setup_dbgc(struct btintel_pcie_data *data)
+{
+       struct btintel_pcie_dbgc_ctxt db_frag;
+       struct data_buf *buf;
+       int i;
+
+       data->dbgc.count = BTINTEL_PCIE_DBGC_BUFFER_COUNT;
+       data->dbgc.bufs = devm_kcalloc(&data->pdev->dev, data->dbgc.count,
+                                      sizeof(*buf), GFP_KERNEL);
+       if (!data->dbgc.bufs)
+               return -ENOMEM;
+
+       data->dbgc.buf_v_addr = dmam_alloc_coherent(&data->pdev->dev,
+                                                   data->dbgc.count *
+                                                   BTINTEL_PCIE_DBGC_BUFFER_SIZE,
+                                                   &data->dbgc.buf_p_addr,
+                                                   GFP_KERNEL | __GFP_NOWARN);
+       if (!data->dbgc.buf_v_addr)
+               return -ENOMEM;
+
+       data->dbgc.frag_v_addr = dmam_alloc_coherent(&data->pdev->dev,
+                                                    sizeof(struct btintel_pcie_dbgc_ctxt),
+                                                    &data->dbgc.frag_p_addr,
+                                                    GFP_KERNEL | __GFP_NOWARN);
+       if (!data->dbgc.frag_v_addr)
+               return -ENOMEM;
+
+       data->dbgc.frag_size = sizeof(struct btintel_pcie_dbgc_ctxt);
+
+       db_frag.magic_num = BTINTEL_PCIE_MAGIC_NUM;

drivers/bluetooth/btintel_pcie.c enum { · line 134

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+       db_frag.ver = BTINTEL_PCIE_DBGC_FRAG_VERSION;
+       db_frag.total_size = BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE;
+       db_frag.num_buf = BTINTEL_PCIE_DBGC_FRAG_BUFFER_COUNT;
+
+       for (i = 0; i < data->dbgc.count; i++) {
+               buf = &data->dbgc.bufs[i];
+               buf->data_p_addr = data->dbgc.buf_p_addr + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE;
+               buf->data = data->dbgc.buf_v_addr + i * BTINTEL_PCIE_DBGC_BUFFER_SIZE;
+               db_frag.bufs[i].buf_addr_lsb = (u32)(buf->data_p_addr & 0xffffffff);
+               db_frag.bufs[i].buf_addr_msb = (u32)((buf->data_p_addr >> 32) & 0xffffffff);

If I recall it correctly the shift was causing build errors/warnings.

Quoted 95 lines
drivers/bluetooth/btintel_pcie.c +17 -0
+               db_frag.bufs[i].buf_size = BTINTEL_PCIE_DBGC_BUFFER_SIZE;
+       }
+
+       memcpy(data->dbgc.frag_v_addr, &db_frag, sizeof(db_frag));
+       return 0;
+}
+
 static inline void ipc_print_ia_ring(struct hci_dev *hdev, struct ia *ia,
                                     u16 queue_num)
 {
@@ -1008,6 +1087,11 @@ static void btintel_pcie_init_ci(struct btintel_pcie_data *data,
        ci->addr_urbdq1 = data->rxq.urbd1s_p_addr;
        ci->num_urbdq1 = data->rxq.count;
        ci->urbdq_db_vec = BTINTEL_PCIE_RXQ_NUM;
+
+       ci->dbg_output_mode = 0x01;
+       ci->dbgc_addr = data->dbgc.frag_p_addr;
+       ci->dbgc_size = data->dbgc.frag_size;
+       ci->dbg_preset = 0x00;
 }
 
 static void btintel_pcie_free_txq_bufs(struct btintel_pcie_data *data,
@@ -1220,6 +1304,11 @@ static int btintel_pcie_alloc(struct btintel_pcie_data *data)
        /* Setup Index Array */
        btintel_pcie_setup_ia(data, p_addr, v_addr, &data->ia);
 
+       /* Setup data buffers for dbgc */
+       err = btintel_pcie_setup_dbgc(data);
+       if (err)
+               goto exit_error_txq;
+
        /* Setup Context Information */
        p_addr += sizeof(u16) * BTINTEL_PCIE_NUM_QUEUES * 4;
        v_addr += sizeof(u16) * BTINTEL_PCIE_NUM_QUEUES * 4;
drivers/bluetooth/btintel_pcie.h +32 -1
index f9aada0543c4..b9d32393002b 100644
@@ -48,6 +48,21 @@
 #define BTINTEL_PCIE_CSR_MSIX_IVAR_BASE                (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0880)
 #define BTINTEL_PCIE_CSR_MSIX_IVAR(cause)      (BTINTEL_PCIE_CSR_MSIX_IVAR_BASE + (cause))
 
+/* The DRAM buffer count, each buffer size, and
+ * fragment buffer size
+ */
+#define BTINTEL_PCIE_DBGC_BUFFER_COUNT         16
+#define BTINTEL_PCIE_DBGC_BUFFER_SIZE          (256 * 1024) /* 256 KB */
+
+#define BTINTEL_PCIE_DBGC_FRAG_VERSION         1
+#define BTINTEL_PCIE_DBGC_FRAG_BUFFER_COUNT    BTINTEL_PCIE_DBGC_BUFFER_COUNT
+
+/* Magic number(4), version(4), size of payload length(4) */
+#define BTINTEL_PCIE_DBGC_FRAG_HEADER_SIZE     12
+
+/* Num of alloc Dbg buff (4) + (LSB(4), MSB(4), Size(4)) for each buffer */
+#define BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE    196
+
 /* Causes for the FH register interrupts */
 enum msix_fh_int_causes {
        BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0       = BIT(0),       /* cause 0 */
@@ -325,6 +340,22 @@ struct rxq {
        struct data_buf *bufs;
 };
 
+/* Structure for DRAM Buffer
+ * @count: Number of descriptors
+ * @buf: Array of data_buf structure
+ */
+struct btintel_pcie_dbgc {
+       u16             count;
+
+       void            *frag_v_addr;
+       dma_addr_t      frag_p_addr;
+       u16             frag_size;
+
+       dma_addr_t      buf_p_addr;
+       void            *buf_v_addr;
+       struct data_buf *bufs;
+};
+
 /* struct btintel_pcie_data
  * @pdev: pci device
  * @hdev: hdev device
@@ -405,6 +436,7 @@ struct btintel_pcie_data {
        struct txq      txq;
        struct rxq      rxq;
        u32     alive_intr_ctxt;
+       struct btintel_pcie_dbgc        dbgc;
 };
 
 static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data,
--

2.43.0

Signature · 1 line
Luiz Augusto von Dentz
author
#7 lore raw

Hi Luiz,

Quoted 109 lines

Subject: Re: [PATCH v2 1/4] Bluetooth: btintel_pcie: Setup buffers for firmware traces

Hi Kiran,

Quoted 92 lines · Kiran K

This patch allocates the host memory which is used by controller to dump the firmware traces. The memory needs to be shared with controller via context information.

---
v1 -> v2:
No change

 drivers/bluetooth/btintel_pcie.c | 89
++++++++++++++++++++++++++++++++  drivers/bluetooth/btintel_pcie.h |
32 ++++++++++++
 2 files changed, 121 insertions(+)
drivers/bluetooth/btintel_pcie.c +59 -0
index b8b241a92bf9..11e2b805c7cc 100644
@@ -49,6 +49,8 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);
 #define BTINTEL_PCIE_HCI_EVT_PKT       0x00000004
 #define BTINTEL_PCIE_HCI_ISO_PKT       0x00000005
 
+ #define BTINTEL_PCIE_MAGIC_NUM    0xA5A5A5A5
+
 /* Alive interrupt context */
 enum {
        BTINTEL_PCIE_ROM,
@@ -60,6 +62,83 @@ enum {
        BTINTEL_PCIE_D3
 };
 
+/* Structure for dbgc fragment buffer
+ * @buf_addr_lsb: LSB of the buffer's physical address
+ * @buf_addr_msb: MSB of the buffer's physical address
+ * @buf_size: Total size of the buffer  */ struct
+btintel_pcie_dbgc_ctxt_buf {
+       u32     buf_addr_lsb;
+       u32     buf_addr_msb;
+       u32     buf_size;
+};
+
+/* Structure for dbgc fragment
+ * @magic_num: 0XA5A5A5A5
+ * @ver: For Driver-FW compatibility
+ * @total_size: Total size of the payload debug info
+ * @num_buf: Num of allocated debug bufs
+ * @bufs: All buffer's addresses and sizes  */ struct
+btintel_pcie_dbgc_ctxt {
+       u32     magic_num;
+       u32     ver;
+       u32     total_size;
+       u32     num_buf;
+       struct btintel_pcie_dbgc_ctxt_buf
+bufs[BTINTEL_PCIE_DBGC_BUFFER_COUNT];
+};
+
+/* This function initializes the memory for DBGC buffers and formats
+the
+ * DBGC fragment which consists header info and DBGC buffer's LSB,
+MSB and
+ * size as the payload
+ */
+static int btintel_pcie_setup_dbgc(struct btintel_pcie_data *data) {
+       struct btintel_pcie_dbgc_ctxt db_frag;
+       struct data_buf *buf;
+       int i;
+
+       data->dbgc.count = BTINTEL_PCIE_DBGC_BUFFER_COUNT;
+       data->dbgc.bufs = devm_kcalloc(&data->pdev->dev, data->dbgc.count,
+                                      sizeof(*buf), GFP_KERNEL);
+       if (!data->dbgc.bufs)
+               return -ENOMEM;
+
+       data->dbgc.buf_v_addr = dmam_alloc_coherent(&data->pdev->dev,
+                                                   data->dbgc.count *
+                                                   BTINTEL_PCIE_DBGC_BUFFER_SIZE,
+                                                   &data->dbgc.buf_p_addr,
+                                                   GFP_KERNEL | __GFP_NOWARN);
+       if (!data->dbgc.buf_v_addr)
+               return -ENOMEM;
+
+       data->dbgc.frag_v_addr = dmam_alloc_coherent(&data->pdev->dev,
+                                                    sizeof(struct btintel_pcie_dbgc_ctxt),
+                                                    &data->dbgc.frag_p_addr,
+                                                    GFP_KERNEL | __GFP_NOWARN);
+       if (!data->dbgc.frag_v_addr)
+               return -ENOMEM;
+

drivers/bluetooth/btintel_pcie.c enum { · line 131

Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10 -0
+       data->dbgc.frag_size = sizeof(struct btintel_pcie_dbgc_ctxt);
+
+       db_frag.magic_num = BTINTEL_PCIE_MAGIC_NUM;
+       db_frag.ver = BTINTEL_PCIE_DBGC_FRAG_VERSION;
+       db_frag.total_size = BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE;
+       db_frag.num_buf = BTINTEL_PCIE_DBGC_FRAG_BUFFER_COUNT;
+
+       for (i = 0; i < data->dbgc.count; i++) {
+               buf = &data->dbgc.bufs[i];
+               buf->data_p_addr = data->dbgc.buf_p_addr + i *

BTINTEL_PCIE_DBGC_BUFFER_SIZE;

Quoted 7 lines

drivers/bluetooth/btintel_pcie.c enum { · line 132

Quoted 1 line
drivers/bluetooth/btintel_pcie.c +1 -0
+               buf->data = data->dbgc.buf_v_addr + i *

BTINTEL_PCIE_DBGC_BUFFER_SIZE;

drivers/bluetooth/btintel_pcie.c enum { · line 135

Quoted 3 lines
drivers/bluetooth/btintel_pcie.c +3 -0
+               db_frag.bufs[i].buf_addr_lsb = (u32)(buf->data_p_addr & 0xffffffff);
+               db_frag.bufs[i].buf_addr_msb = (u32)((buf->data_p_addr
+ >> 32) & 0xffffffff);

If I recall it correctly the shift was causing build errors/warnings.

I did run sparse and did not see any issue. Please let me know if there is a way to reproduce this issue.

Quoted 95 lines
Quoted 22 lines
drivers/bluetooth/btintel_pcie.c +13 -0
+               db_frag.bufs[i].buf_size = BTINTEL_PCIE_DBGC_BUFFER_SIZE;
+       }
+
+       memcpy(data->dbgc.frag_v_addr, &db_frag, sizeof(db_frag));
+       return 0;
+}
+
 static inline void ipc_print_ia_ring(struct hci_dev *hdev, struct ia *ia,
                                     u16 queue_num)  { @@ -1008,6
+1087,11 @@ static void btintel_pcie_init_ci(struct btintel_pcie_data *data,
        ci->addr_urbdq1 = data->rxq.urbd1s_p_addr;
        ci->num_urbdq1 = data->rxq.count;
        ci->urbdq_db_vec = BTINTEL_PCIE_RXQ_NUM;
+
+       ci->dbg_output_mode = 0x01;
+       ci->dbgc_addr = data->dbgc.frag_p_addr;
+       ci->dbgc_size = data->dbgc.frag_size;
+       ci->dbg_preset = 0x00;
 }
 
 static void btintel_pcie_free_txq_bufs(struct btintel_pcie_data
Quoted 1 line

*data, @@ -1220,6 +1304,11 @@ static int btintel_pcie_alloc(struct

btintel_pcie_data *data)

Quoted 17 lines
        /* Setup Index Array */
        btintel_pcie_setup_ia(data, p_addr, v_addr, &data->ia);
drivers/bluetooth/btintel_pcie.c +5 -1
+       /* Setup data buffers for dbgc */
+       err = btintel_pcie_setup_dbgc(data);
+       if (err)
+               goto exit_error_txq;
+
        /* Setup Context Information */
        p_addr += sizeof(u16) * BTINTEL_PCIE_NUM_QUEUES * 4;
        v_addr += sizeof(u16) * BTINTEL_PCIE_NUM_QUEUES * 4; diff
--git a/drivers/bluetooth/btintel_pcie.h

b/drivers/bluetooth/btintel_pcie.h
index f9aada0543c4..b9d32393002b 100644

drivers/bluetooth/btintel_pcie.h line 48

Quoted 1 line
drivers/bluetooth/btintel_pcie.h +0 -0
@@ -48,6 +48,21 @@
 #define BTINTEL_PCIE_CSR_MSIX_IVAR_BASE

(BTINTEL_PCIE_CSR_MSIX_BASE + 0x0880)

drivers/bluetooth/btintel_pcie.h line 49

Quoted 1 line
drivers/bluetooth/btintel_pcie.h +0 -0
 #define BTINTEL_PCIE_CSR_MSIX_IVAR(cause)

(BTINTEL_PCIE_CSR_MSIX_IVAR_BASE + (cause))

drivers/bluetooth/btintel_pcie.h

Quoted 9 lines
drivers/bluetooth/btintel_pcie.h +8 -0
+/* The DRAM buffer count, each buffer size, and
+ * fragment buffer size
+ */
+#define BTINTEL_PCIE_DBGC_BUFFER_COUNT         16
+#define BTINTEL_PCIE_DBGC_BUFFER_SIZE          (256 * 1024) /* 256 KB */
+
+#define BTINTEL_PCIE_DBGC_FRAG_VERSION         1
+#define BTINTEL_PCIE_DBGC_FRAG_BUFFER_COUNT

BTINTEL_PCIE_DBGC_BUFFER_COUNT

Quoted 40 lines
drivers/bluetooth/btintel_pcie.h +24 -0
+
+/* Magic number(4), version(4), size of payload length(4) */
+#define BTINTEL_PCIE_DBGC_FRAG_HEADER_SIZE     12
+
+/* Num of alloc Dbg buff (4) + (LSB(4), MSB(4), Size(4)) for each buffer */
+#define BTINTEL_PCIE_DBGC_FRAG_PAYLOAD_SIZE    196
+
 /* Causes for the FH register interrupts */  enum msix_fh_int_causes
 {
        BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0       = BIT(0),       /* cause 0 */
@@ -325,6 +340,22 @@ struct rxq {
        struct data_buf *bufs;
 };
 
+/* Structure for DRAM Buffer
+ * @count: Number of descriptors
+ * @buf: Array of data_buf structure
+ */
+struct btintel_pcie_dbgc {
+       u16             count;
+
+       void            *frag_v_addr;
+       dma_addr_t      frag_p_addr;
+       u16             frag_size;
+
+       dma_addr_t      buf_p_addr;
+       void            *buf_v_addr;
+       struct data_buf *bufs;
+};
+
 /* struct btintel_pcie_data
  * @pdev: pci device
  * @hdev: hdev device
@@ -405,6 +436,7 @@ struct btintel_pcie_data {
        struct txq      txq;
        struct rxq      rxq;
        u32     alive_intr_ctxt;
+       struct btintel_pcie_dbgc        dbgc;
 };
 
Quoted 10 lines
Quoted 6 lines
drivers/bluetooth/btintel_pcie.h +0 -0
 static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data

*data,
--
2.43.0

--
Luiz Augusto von Dentz

Thanks,
Kiran

#8 lore raw
In reply to Kiran K

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=936457

---Test result---

Test Summary:

CheckPatch                    PENDING   0.27 seconds
GitLint                       PENDING   0.23 seconds
SubjectPrefix                 PASS      6.39 seconds
BuildKernel                   PASS      24.20 seconds
CheckAllWarning               PASS      27.27 seconds
CheckSparse                   PASS      34.78 seconds
BuildKernel32                 PASS      23.91 seconds
TestRunnerSetup               PASS      429.61 seconds
TestRunner_l2cap-tester       PASS      22.93 seconds
TestRunner_iso-tester         PASS      29.43 seconds
TestRunner_bnep-tester        PASS      4.78 seconds
TestRunner_mgmt-tester        PASS      120.75 seconds
TestRunner_rfcomm-tester      PASS      8.44 seconds
TestRunner_sco-tester         PASS      9.76 seconds
TestRunner_ioctl-tester       PASS      8.35 seconds
TestRunner_mesh-tester        PASS      6.04 seconds
TestRunner_smp-tester         PASS      7.41 seconds
TestRunner_userchan-tester    PASS      5.05 seconds
IncrementalBuild              PENDING   0.37 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth