Linux bluetooth development
 help / color / mirror / Atom feed
From: Kiran K <kiran.k@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: chethan.tumkur.narayan@intel.com,
	chandrashekar.devegowda@intel.com, Kiran K <kiran.k@intel.com>
Subject: [PATCH v1 2/7] Bluetooth: btintel_pcie: Add TX/RX packet dumps under LOG_MASK
Date: Thu, 29 Oct 2026 15:23:39 +0530	[thread overview]
Message-ID: <20261029095344.3989729-2-kiran.k@intel.com> (raw)
In-Reply-To: <20261029095344.3989729-1-kiran.k@intel.com>

Log a one-line summary (packet type, opcode/event/handle, length) and a
hex dump of every HCI packet sent and received, gated independently by
BTINTEL_PCIE_DUMP_TX (bit 0) and BTINTEL_PCIE_DUMP_RX (bit 1).

Prefix the hex dump with the device name via a btintel_pcie_hex_dump()
helper, falling back to the PCI device name when hdev is not yet
registered so early messages do not print "null".

Assisted-by: Copilot:Claude Opus 4.7
Signed-off-by: Kiran K <kiran.k@intel.com>
---
 drivers/bluetooth/btintel_pcie.c | 73 ++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c
index a25f4d866f57..6fdffda6a1a8 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -32,6 +32,8 @@
 #define VERSION "0.1"
 
 /* Runtime diagnostic logging bits loaded from LOG_MASK in the debug INI. */
+#define BTINTEL_PCIE_DUMP_TX		BIT(0)
+#define BTINTEL_PCIE_DUMP_RX		BIT(1)
 
 #define BTINTEL_PCI_DEVICE(dev, subdev)	\
 	.vendor = PCI_VENDOR_ID_INTEL,	\
@@ -198,6 +200,42 @@ static inline char *btintel_pcie_alivectxt_state2str(u32 alive_intr_ctxt)
 	}
 }
 
+/* Returns hdev name once registered, else the PCI device name so that
+ * logs emitted before hci_register_dev() do not show "null".
+ */
+static const char *btintel_pcie_dev_name(struct btintel_pcie_data *data)
+{
+	return data->hdev ? data->hdev->name : dev_name(&data->pdev->dev);
+}
+
+/* Hex dump with "Bluetooth: <dev>: <tag> " prefix */
+static void btintel_pcie_hex_dump(struct btintel_pcie_data *data,
+				  const char *tag, const void *buf, size_t len)
+{
+	char prefix[64];
+
+	snprintf(prefix, sizeof(prefix), "Bluetooth: %s: %s ",
+		 btintel_pcie_dev_name(data), tag);
+	print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET, 16, 1, buf, len,
+		       false);
+}
+
+static const char * const btintel_pcie_pkt_type_table[] = {
+	[HCI_COMMAND_PKT] = "CMD",
+	[HCI_ACLDATA_PKT] = "ACL",
+	[HCI_SCODATA_PKT] = "SCO",
+	[HCI_EVENT_PKT] = "EVT",
+	[HCI_ISODATA_PKT] = "ISO",
+};
+
+static const char *btintel_pcie_pkt_type_str(u8 pkt_type)
+{
+	if (pkt_type < ARRAY_SIZE(btintel_pcie_pkt_type_table) &&
+	    btintel_pcie_pkt_type_table[pkt_type])
+		return btintel_pcie_pkt_type_table[pkt_type];
+	return "UNK";
+}
+
 /* Returns true when firmware traces are routed to the WiFi DBGC. In that
  * mode the host must not allocate DBGC buffers and must not publish their
  * addresses in the context info.
@@ -2454,6 +2492,23 @@ static int btintel_pcie_recv_frame(struct btintel_pcie_data *data,
 	hdev->stat.byte_rx += plen;
 	skb_trim(skb, plen);
 
+	if (data->log_mask & BTINTEL_PCIE_DUMP_RX) {
+		if (pkt_type == HCI_EVENT_PKT)
+			bt_dev_info(hdev, "RX %s evt=0x%02x len=%u",
+				    btintel_pcie_pkt_type_str(pkt_type),
+				    ((struct hci_event_hdr *)skb->data)->evt,
+				    plen);
+		else if (pkt_type == HCI_ACLDATA_PKT)
+			bt_dev_info(hdev, "RX %s handle=0x%04x len=%u",
+				    btintel_pcie_pkt_type_str(pkt_type),
+				    le16_to_cpu(hci_acl_hdr(skb)->handle) & 0x0fff,
+				    plen);
+		else
+			bt_dev_info(hdev, "RX %s len=%u",
+				    btintel_pcie_pkt_type_str(pkt_type), plen);
+		btintel_pcie_hex_dump(data, "[RX]", skb->data, skb->len);
+	}
+
 	if (pcie_pkt_type == BTINTEL_PCIE_HCI_EVT_PKT)
 		ret = btintel_pcie_recv_event(hdev, skb);
 	else
@@ -3665,6 +3720,24 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev,
 		return -EILSEQ;
 	}
 
+	if (data->log_mask & BTINTEL_PCIE_DUMP_TX) {
+		if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT)
+			bt_dev_info(hdev, "TX %s opcode=0x%04x len=%u",
+				    btintel_pcie_pkt_type_str(hci_skb_pkt_type(skb)),
+				    opcode, skb->len);
+		else if (hci_skb_pkt_type(skb) == HCI_ACLDATA_PKT &&
+			 skb->len >= HCI_ACL_HDR_SIZE)
+			bt_dev_info(hdev, "TX %s handle=0x%04x len=%u",
+				    btintel_pcie_pkt_type_str(hci_skb_pkt_type(skb)),
+				    le16_to_cpu(hci_acl_hdr(skb)->handle) & 0x0fff,
+				    skb->len);
+		else
+			bt_dev_info(hdev, "TX %s len=%u",
+				    btintel_pcie_pkt_type_str(hci_skb_pkt_type(skb)),
+				    skb->len);
+		btintel_pcie_hex_dump(data, "[TX]", skb->data, skb->len);
+	}
+
 	ret = btintel_pcie_send_sync(data, skb, type, opcode);
 	if (ret) {
 		hdev->stat.err_tx++;
-- 
2.54.0


  reply	other threads:[~2026-10-29  9:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29  9:53 [PATCH v1 1/7] Bluetooth: btintel_pcie: Add LOG_MASK parsing from debug INI Kiran K
2026-10-29  9:53 ` Kiran K [this message]
2026-10-29  9:53 ` [PATCH v1 3/7] Bluetooth: btintel_pcie: Add alive interrupt logging under LOG_MASK Kiran K
2026-10-29  9:53 ` [PATCH v1 4/7] Bluetooth: btintel_pcie: Add Sx transition " Kiran K
2026-10-29  9:53 ` [PATCH v1 5/7] Bluetooth: btintel_pcie: Add MAC access " Kiran K
2026-10-29  9:53 ` [PATCH v1 6/7] Bluetooth: btintel_pcie: Add target memory read " Kiran K
2026-10-29  9:53 ` [PATCH v1 7/7] Bluetooth: btintel_pcie: Gate mailbox logging behind LOG_MASK Kiran K
2026-10-29 14:52 ` [v1,1/7] Bluetooth: btintel_pcie: Add LOG_MASK parsing from debug INI bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261029095344.3989729-2-kiran.k@intel.com \
    --to=kiran.k@intel.com \
    --cc=chandrashekar.devegowda@intel.com \
    --cc=chethan.tumkur.narayan@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox