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, ravindra@intel.com,
	Kiran K <kiran.k@intel.com>
Subject: [PATCH v1 2/3] Bluetooth: btintel_pcie: Serialize doorbell writes and target reads
Date: Mon, 23 Nov 2026 12:25:22 +0530	[thread overview]
Message-ID: <20261123065523.2769017-2-kiran.k@intel.com> (raw)
In-Reply-To: <20261123065523.2769017-1-kiran.k@intel.com>

The controller must not see an access to HBUS_TARG_WRPTR at the same
time as an access to the PRPH_DEV_ADDR/PRPH_DEV_RD register pair used
for target access. Posting an RX buffer or ringing the TX doorbell while
a target read is in flight can produce invalid mailbox values. The
address/data pair also has to stay together, since several works
(mbox, hwexp, fwtrigger, coredump) read device memory concurrently.

Add dev_mem_lock and take it inside btintel_pcie_rd_dev_mem() and the new
btintel_pcie_wr_dev_mem() and btintel_pcie_wr_wrptr() helpers. The YoYo
config set writes use the same lock.

The critical sections are only a few MMIO accesses and never sleep, so a
spinlock is sufficient.

Fixes: d572ea4b621c ("Bluetooth: btintel_pcie: sync mbox tlv parsing with GP0 alive interrupt")
Fixes: 68e0925f16c0 ("Bluetooth: btintel_pcie: Add yoyo support for config set TLV")
Assisted-by: Copilot:claude-sonnet-5.5
Signed-off-by: Kiran K <kiran.k@intel.com>
---
 drivers/bluetooth/btintel_pcie.c | 15 +++++++--------
 drivers/bluetooth/btintel_pcie.h | 33 +++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c
index d95127327c71..75f1724336ae 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -540,7 +540,7 @@ static void btintel_pcie_set_tx_db(struct btintel_pcie_data *data, u16 index)
 	val = index;
 	val |= (BTINTEL_PCIE_TX_DB_VEC << 16);
 
-	btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR, val);
+	btintel_pcie_wr_wrptr(data, val);
 }
 
 /* Copy the data to next(@tfd_index) data buffer and update the TFD(transfer
@@ -754,7 +754,7 @@ static void btintel_pcie_set_rx_db(struct btintel_pcie_data *data, u16 index)
 	val = index;
 	val |= (BTINTEL_PCIE_RX_DB_VEC << 16);
 
-	btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR, val);
+	btintel_pcie_wr_wrptr(data, val);
 }
 
 /* Update the FRBD (free buffer descriptor) with the @frbd_index and the
@@ -1075,7 +1075,10 @@ btintel_pcie_apply_yoyo_config_sets(struct btintel_pcie_data *data,
 				}
 
 				BT_DBG("YoYo: CSR write [0x%08x] = 0x%08x", addr, value);
+				/* addr may be PRPH_DEV_* or HBUS_TARG_WRPTR */
+				spin_lock(&data->dev_mem_lock);
 				btintel_pcie_wr_reg32(data, addr, value);
+				spin_unlock(&data->dev_mem_lock);
 				break;
 			/* Indirect Address Access (Peripheral MAC and Device Memory) */
 			case BTINTEL_PCIE_CFGSET_PERIPH_MAC:
@@ -1089,12 +1092,7 @@ btintel_pcie_apply_yoyo_config_sets(struct btintel_pcie_data *data,
 					continue;
 				}
 
-				btintel_pcie_wr_reg32(data,
-						      BTINTEL_PCIE_PRPH_DEV_ADDR_REG,
-						      addr);
-				btintel_pcie_wr_reg32(data,
-						      BTINTEL_PCIE_PRPH_DEV_WR_REG,
-						      value);
+				btintel_pcie_wr_dev_mem(data, addr, value);
 				BT_DBG("YoYo: indirect write type %u addr 0x%08x value 0x%08x",
 				       config_set->config_set_type, addr, value);
 				break;
@@ -4864,6 +4862,7 @@ static int btintel_pcie_probe(struct pci_dev *pdev,
 	spin_lock_init(&data->irq_lock);
 	spin_lock_init(&data->hci_rx_lock);
 	spin_lock_init(&data->ipc_lock);
+	spin_lock_init(&data->dev_mem_lock);
 	mutex_init(&data->rfkill_doorbell_lock);
 
 	init_waitqueue_head(&data->gp0_wait_q);
diff --git a/drivers/bluetooth/btintel_pcie.h b/drivers/bluetooth/btintel_pcie.h
index 6b7cf3819f25..124e837da94b 100644
--- a/drivers/bluetooth/btintel_pcie.h
+++ b/drivers/bluetooth/btintel_pcie.h
@@ -769,6 +769,10 @@ struct btintel_pcie_data {
 	spinlock_t	hci_rx_lock;
 	/* lock to serialize IPC control register updates */
 	spinlock_t	ipc_lock;
+	/* lock to serialize HBUS_TARG_WRPTR writes against the PRPH_DEV_ADDR/
+	 * PRPH_DEV_RD target access register pair. Never sleep while held.
+	 */
+	spinlock_t	dev_mem_lock;
 
 	void __iomem	*base_addr;
 
@@ -880,9 +884,36 @@ static inline void btintel_pcie_clr_reg_bits(struct btintel_pcie_data *data,
 	iowrite32(r, data->base_addr + offset);
 }
 
+/* Caller must hold MAC access. The address/data register pair is accessed
+ * under dev_mem_lock so that it neither overlaps a HBUS_TARG_WRPTR write nor
+ * interleaves with another reader.
+ */
 static inline u32 btintel_pcie_rd_dev_mem(struct btintel_pcie_data *data,
 					  u32 addr)
 {
+	u32 val;
+
+	spin_lock(&data->dev_mem_lock);
+	btintel_pcie_wr_reg32(data, BTINTEL_PCIE_PRPH_DEV_ADDR_REG, addr);
+	val = btintel_pcie_rd_reg32(data, BTINTEL_PCIE_PRPH_DEV_RD_REG);
+	spin_unlock(&data->dev_mem_lock);
+
+	return val;
+}
+
+static inline void btintel_pcie_wr_dev_mem(struct btintel_pcie_data *data,
+					  u32 addr, u32 val)
+{
+	spin_lock(&data->dev_mem_lock);
 	btintel_pcie_wr_reg32(data, BTINTEL_PCIE_PRPH_DEV_ADDR_REG, addr);
-	return btintel_pcie_rd_reg32(data, BTINTEL_PCIE_PRPH_DEV_RD_REG);
+	btintel_pcie_wr_reg32(data, BTINTEL_PCIE_PRPH_DEV_WR_REG, val);
+	spin_unlock(&data->dev_mem_lock);
+}
+
+static inline void btintel_pcie_wr_wrptr(struct btintel_pcie_data *data,
+					 u32 val)
+{
+	spin_lock(&data->dev_mem_lock);
+	btintel_pcie_wr_reg32(data, BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR, val);
+	spin_unlock(&data->dev_mem_lock);
 }
-- 
2.54.0


  reply	other threads:[~2026-11-23  6:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  6:55 [PATCH v1 1/3] Revert "Bluetooth: btintel_pcie: sync mbox tlv parsing with GP0 alive interrupt" Kiran K
2026-11-23  6:55 ` Kiran K [this message]
2026-11-23  6:55 ` [PATCH v1 3/3] Bluetooth: btintel_pcie: Serialize MAC access requests Kiran K

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=20261123065523.2769017-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 \
    --cc=ravindra@intel.com \
    /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