Skip to contentSkip to conversation

Add MT7921 SDIO Bluetooth support

PATCH Superseded [email protected] 3 participants 13 messages Oct 8, 2021 – Oct 10, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#2 lore raw

PATCH 2/10 Bluetooth: btmtksido: rely on BT_MTK module

In reply to [email protected]

From: Sean Wang <[email protected]>

Rely on btmtk module to reduce duplicated code

---
 drivers/bluetooth/Kconfig     |   1 +
 drivers/bluetooth/btmtk.h     |   3 +
 drivers/bluetooth/btmtksdio.c | 192 +++++-----------------------------
 3 files changed, 28 insertions(+), 168 deletions(-)
drivers/bluetooth/Kconfig +1 -0
index 24c3aea4a7d6..36380e618ba4 100644
@@ -388,6 +388,7 @@ config BT_ATH3K
 config BT_MTKSDIO
 	tristate "MediaTek HCI SDIO driver"
 	depends on MMC
+	select BT_MTK
 	help
 	  MediaTek Bluetooth HCI SDIO driver.
 	  This driver is required if you want to use MediaTek Bluetooth
drivers/bluetooth/btmtk.h +3 -0
index 87c25c6cf969..18f43c641b3b 100644
@@ -9,6 +9,9 @@
 
 enum {
 	BTMTK_WMT_PATCH_DWNLD = 0x1,
+	BTMTK_WMT_TEST = 0x2,
+	BTMTK_WMT_WAKEUP = 0x3,
+	BTMTK_WMT_HIF = 0x4,
 	BTMTK_WMT_FUNC_CTRL = 0x6,
 	BTMTK_WMT_RST = 0x7,
 	BTMTK_WMT_SEMAPHORE = 0x17,
drivers/bluetooth/btmtksdio.c +24 -168

307 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#1 lore raw

PATCH 1/10 Bluetooth: mediatek: add BT_MTK module

In reply to [email protected]

From: Sean Wang <[email protected]>

Add BT_MTK module that is a preliminary patch to introduce mt7921s support to share the logic betweem btusb and btmtksdio.

---
 drivers/bluetooth/Kconfig  |   5 +
 drivers/bluetooth/Makefile |   1 +
 drivers/bluetooth/btmtk.c  | 288 ++++++++++++++++++++++++++++++++
 drivers/bluetooth/btmtk.h  |  97 +++++++++++
 drivers/bluetooth/btusb.c  | 331 +------------------------------------
 5 files changed, 397 insertions(+), 325 deletions(-)
 create mode 100644 drivers/bluetooth/btmtk.c
 create mode 100644 drivers/bluetooth/btmtk.h
drivers/bluetooth/Kconfig +5 -0
index 851842372c9b..24c3aea4a7d6 100644
@@ -19,6 +19,10 @@ config BT_QCA
 	tristate
 	select FW_LOADER
 
+config BT_MTK
+	tristate
+	select FW_LOADER
+
 config BT_HCIBTUSB
 	tristate "HCI USB driver"
 	depends on USB
@@ -55,6 +59,7 @@ config BT_HCIBTUSB_BCM
 config BT_HCIBTUSB_MTK
 	bool "MediaTek protocol support"
 	depends on BT_HCIBTUSB
+	select BT_MTK
 	default n
 	help
 	  The MediaTek protocol support enables firmware download
drivers/bluetooth/Makefile +1 -0
index 16286ea2655d..3321a8aea4a0 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_BT_QCOMSMD)	+= btqcomsmd.o
 obj-$(CONFIG_BT_BCM)		+= btbcm.o
 obj-$(CONFIG_BT_RTL)		+= btrtl.o
 obj-$(CONFIG_BT_QCA)		+= btqca.o
+obj-$(CONFIG_BT_MTK)		+= btmtk.o
 
 obj-$(CONFIG_BT_VIRTIO)		+= virtio_bt.o
 
drivers/bluetooth/btmtk.c new file +288 -0

288 lines not on this page · raw message

drivers/bluetooth/btmtk.h new file +97 -0

97 lines not on this page · raw message

drivers/bluetooth/btusb.c +6 -325

373 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#4 lore raw

PATCH 4/10 Bluetooth: btmtksdio: explicitly set WHISR as write-1-clear

In reply to [email protected]

From: Sean Wang <[email protected]>

That is a preliminary patch to introduce mt7921s support.

Explicitly set WHISR as write-1-clear method to all devices that is the expected behavior the driver rely on.

---
 drivers/bluetooth/btmtksdio.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/bluetooth/btmtksdio.c +8 -3
index 77d1c4ac582d..57126a95e292 100644
@@ -487,8 +487,8 @@ static void btmtksdio_interrupt(struct sdio_func *func)
 static int btmtksdio_open(struct hci_dev *hdev)
 {
 	struct btmtksdio_dev *bdev = hci_get_drvdata(hdev);
+	u32 status, val;
 	int err;
-	u32 status;
 
 	sdio_claim_host(bdev->func);
 
@@ -533,8 +533,13 @@ static int btmtksdio_open(struct hci_dev *hdev)
 	if (err < 0)
 		goto err_release_irq;
 
-	/* Setup write-1-clear for CHISR register */
-	sdio_writel(bdev->func, C_INT_CLR_CTRL, MTK_REG_CHCR, &err);
+	/* Explitly set write-1-clear method */
+	val = sdio_readl(bdev->func, MTK_REG_CHCR, &err);
+	if (err < 0)
+		goto err_release_irq;
+
+	val |= C_INT_CLR_CTRL;
+	sdio_writel(bdev->func, val, MTK_REG_CHCR, &err);
 	if (err < 0)
 		goto err_release_irq;
 
Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#5 lore raw

PATCH 5/10 Bluetooth: btmtksdio: move interrupt service to work

In reply to [email protected]

From: Sean Wang <[email protected]>

btmtksdio belongs to WIFI/BT combo chip that would serve two radios in one sdio_irq so that we have to move interrupt service to worker to ensure ISR as short as possible.

The worker would serve the both Tx and Rx in a batch to effectively reduce many interrupts to the host and to avoid excessive sdio lock contention between various context (even from WiFi driver) and help to be more efficient to complete command/event transation.

---
 drivers/bluetooth/btmtksdio.c | 132 ++++++++++++++++------------------
 1 file changed, 63 insertions(+), 69 deletions(-)
drivers/bluetooth/btmtksdio.c +63 -69
index 57126a95e292..f712b52e5797 100644
@@ -98,7 +98,7 @@ struct btmtksdio_dev {
 	struct sdio_func *func;
 	struct device *dev;
 
-	struct work_struct tx_work;
+	struct work_struct txrx_work;
 	unsigned long tx_state;
 	struct sk_buff_head txq;
 
@@ -249,32 +249,6 @@ static u32 btmtksdio_drv_own_query(struct btmtksdio_dev *bdev)
 	return sdio_readl(bdev->func, MTK_REG_CHLPCR, NULL);
 }
 
-static void btmtksdio_tx_work(struct work_struct *work)
-{
-	struct btmtksdio_dev *bdev = container_of(work, struct btmtksdio_dev,
-						  tx_work);
-	struct sk_buff *skb;
-	int err;
-
-	pm_runtime_get_sync(bdev->dev);
-
-	sdio_claim_host(bdev->func);
-
-	while ((skb = skb_dequeue(&bdev->txq))) {
-		err = btmtksdio_tx_packet(bdev, skb);
-		if (err < 0) {
-			bdev->hdev->stat.err_tx++;
-			skb_queue_head(&bdev->txq, skb);
-			break;
-		}
-	}
-
-	sdio_release_host(bdev->func);
-
-	pm_runtime_mark_last_busy(bdev->dev);
-	pm_runtime_put_autosuspend(bdev->dev);
-}
-
 static int btmtksdio_recv_event(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct btmtksdio_dev *bdev = hci_get_drvdata(hdev);
@@ -425,63 +399,81 @@ static int btmtksdio_rx_packet(struct btmtksdio_dev *bdev, u16 rx_size)
 	return err;
 }
 
-static void btmtksdio_interrupt(struct sdio_func *func)
+static void btmtksdio_txrx_work(struct work_struct *work)
 {
-	struct btmtksdio_dev *bdev = sdio_get_drvdata(func);
+	struct btmtksdio_dev *bdev = container_of(work, struct btmtksdio_dev,
+						  txrx_work);
+	unsigned long txrx_timeout;
+	struct sk_buff *skb;
 	u32 int_status;
 	u16 rx_size;
-
-	/* It is required that the host gets ownership from the device before
-	 * accessing any register, however, if SDIO host is not being released,
-	 * a potential deadlock probably happens in a circular wait between SDIO
-	 * IRQ work and PM runtime work. So, we have to explicitly release SDIO
-	 * host here and claim again after the PM runtime work is all done.
-	 */
-	sdio_release_host(bdev->func);
+	int err;
 
 	pm_runtime_get_sync(bdev->dev);
 
 	sdio_claim_host(bdev->func);
 
 	/* Disable interrupt */
-	sdio_writel(func, C_INT_EN_CLR, MTK_REG_CHLPCR, NULL);
+	sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, 0);
 
-	int_status = sdio_readl(func, MTK_REG_CHISR, NULL);
+	while ((skb = skb_dequeue(&bdev->txq))) {
+		err = btmtksdio_tx_packet(bdev, skb);
+		if (err < 0) {
+			bdev->hdev->stat.err_tx++;
+			skb_queue_head(&bdev->txq, skb);
+			break;
+		}
+	}
 
-	/* Ack an interrupt as soon as possible before any operation on
-	 * hardware.
-	 *
-	 * Note that we don't ack any status during operations to avoid race
-	 * condition between the host and the device such as it's possible to
-	 * mistakenly ack RX_DONE for the next packet and then cause interrupts
-	 * not be raised again but there is still pending data in the hardware
-	 * FIFO.
-	 */
-	sdio_writel(func, int_status, MTK_REG_CHISR, NULL);
+	txrx_timeout = jiffies + 5 * HZ;
+
+	do {
+		int_status = sdio_readl(bdev->func, MTK_REG_CHISR, NULL);
+
+		/* Ack an interrupt as soon as possible before any operation on
+		 * hardware.
+		 *
+		 * Note that we don't ack any status during operations to avoid race
+		 * condition between the host and the device such as it's possible to
+		 * mistakenly ack RX_DONE for the next packet and then cause interrupts
+		 * not be raised again but there is still pending data in the hardware
+		 * FIFO.
+		 */
+		sdio_writel(bdev->func, int_status, MTK_REG_CHISR, NULL);
+
+		if (int_status & FW_OWN_BACK_INT)
+			bt_dev_dbg(bdev->hdev, "Get fw own back");
+
+		if (int_status & TX_EMPTY)
+			schedule_work(&bdev->txrx_work);
+		else if (unlikely(int_status & TX_FIFO_OVERFLOW))
+			bt_dev_warn(bdev->hdev, "Tx fifo overflow");
+
+		if (int_status & RX_DONE_INT) {
+			rx_size = (int_status & RX_PKT_LEN) >> 16;
+			if (btmtksdio_rx_packet(bdev, rx_size) < 0)
+				bdev->hdev->stat.err_rx++;
+		}
 
-	if (unlikely(!int_status))
-		bt_dev_err(bdev->hdev, "CHISR is 0");
+	} while (int_status || time_is_before_jiffies(txrx_timeout));
 
-	if (int_status & FW_OWN_BACK_INT)
-		bt_dev_dbg(bdev->hdev, "Get fw own back");
+	/* Enable interrupt */
+	sdio_writel(bdev->func, C_INT_EN_SET, MTK_REG_CHLPCR, 0);
 
-	if (int_status & TX_EMPTY)
-		schedule_work(&bdev->tx_work);
-	else if (unlikely(int_status & TX_FIFO_OVERFLOW))
-		bt_dev_warn(bdev->hdev, "Tx fifo overflow");
+	sdio_release_host(bdev->func);
 
-	if (int_status & RX_DONE_INT) {
-		rx_size = (int_status & RX_PKT_LEN) >> 16;
+	pm_runtime_mark_last_busy(bdev->dev);
+	pm_runtime_put_autosuspend(bdev->dev);
+}
 
-		if (btmtksdio_rx_packet(bdev, rx_size) < 0)
-			bdev->hdev->stat.err_rx++;
-	}
+static void btmtksdio_interrupt(struct sdio_func *func)
+{
+	struct btmtksdio_dev *bdev = sdio_get_drvdata(func);
 
-	/* Enable interrupt */
-	sdio_writel(func, C_INT_EN_SET, MTK_REG_CHLPCR, NULL);
+	/* Disable interrupt */
+	sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, 0);
 
-	pm_runtime_mark_last_busy(bdev->dev);
-	pm_runtime_put_autosuspend(bdev->dev);
+	schedule_work(&bdev->txrx_work);
 }
 
 static int btmtksdio_open(struct hci_dev *hdev)
@@ -583,6 +575,8 @@ static int btmtksdio_close(struct hci_dev *hdev)
 
 	sdio_release_irq(bdev->func);
 
+	cancel_work_sync(&bdev->txrx_work);
+
 	/* Return ownership to the device */
 	sdio_writel(bdev->func, C_FW_OWN_REQ_SET, MTK_REG_CHLPCR, NULL);
 
@@ -604,7 +598,7 @@ static int btmtksdio_flush(struct hci_dev *hdev)
 
 	skb_queue_purge(&bdev->txq);
 
-	cancel_work_sync(&bdev->tx_work);
+	cancel_work_sync(&bdev->txrx_work);
 
 	return 0;
 }
@@ -795,7 +789,7 @@ static int btmtksdio_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
 
 	skb_queue_tail(&bdev->txq, skb);
 
-	schedule_work(&bdev->tx_work);
+	schedule_work(&bdev->txrx_work);
 
 	return 0;
 }
@@ -818,7 +812,7 @@ static int btmtksdio_probe(struct sdio_func *func,
 	bdev->dev = &func->dev;
 	bdev->func = func;
 
-	INIT_WORK(&bdev->tx_work, btmtksdio_tx_work);
+	INIT_WORK(&bdev->txrx_work, btmtksdio_txrx_work);
 	skb_queue_head_init(&bdev->txq);
 
 	/* Initialize and register HCI device */
Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#6 lore raw

PATCH 6/10 Bluetooth: btmtksdio: update register CSDIOCSR operation

In reply to [email protected]

From: Sean Wang <[email protected]>

That is a preliminary patch to introduce mt7921s support.

Update register CSDIOCSR operation that is suggested from the vendor driver and is compatible to the all devices.

---
 drivers/bluetooth/btmtksdio.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/bluetooth/btmtksdio.c +6 -2
index f712b52e5797..3381c8844902 100644
@@ -520,8 +520,12 @@ static int btmtksdio_open(struct hci_dev *hdev)
 	/* SDIO CMD 5 allows the SDIO device back to idle state an
 	 * synchronous interrupt is supported in SDIO 4-bit mode
 	 */
-	sdio_writel(bdev->func, SDIO_INT_CTL | SDIO_RE_INIT_EN,
-		    MTK_REG_CSDIOCSR, &err);
+	val = sdio_readl(bdev->func, MTK_REG_CSDIOCSR, &err);
+	if (err < 0)
+		goto err_release_irq;
+
+	val |= SDIO_INT_CTL;
+	sdio_writel(bdev->func, val, MTK_REG_CSDIOCSR, &err);
 	if (err < 0)
 		goto err_release_irq;
 
Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#7 lore raw

PATCH 7/10 Bluetooth: btmtksdio: use register CRPLR to read packet length

In reply to [email protected]

From: Sean Wang <[email protected]>

That is a preliminary patch to introduce mt7921s support.

Use the register CRPLR to read packet length to make all the devices share the common logic.

---
 drivers/bluetooth/btmtksdio.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/bluetooth/btmtksdio.c +5 -4
index 3381c8844902..f816a7cb0a74 100644
@@ -83,6 +83,8 @@ MODULE_DEVICE_TABLE(sdio, btmtksdio_table);
 
 #define MTK_REG_CRDR		0x1c
 
+#define MTK_REG_CRPLR		0x24
+
 #define MTK_SDIO_BLOCK_SIZE	256
 
 #define BTMTKSDIO_TX_WAIT_VND_EVT	1
@@ -404,9 +406,8 @@ static void btmtksdio_txrx_work(struct work_struct *work)
 	struct btmtksdio_dev *bdev = container_of(work, struct btmtksdio_dev,
 						  txrx_work);
 	unsigned long txrx_timeout;
+	u32 int_status, rx_size;
 	struct sk_buff *skb;
-	u32 int_status;
-	u16 rx_size;
 	int err;
 
 	pm_runtime_get_sync(bdev->dev);
@@ -450,11 +451,11 @@ static void btmtksdio_txrx_work(struct work_struct *work)
 			bt_dev_warn(bdev->hdev, "Tx fifo overflow");
 
 		if (int_status & RX_DONE_INT) {
-			rx_size = (int_status & RX_PKT_LEN) >> 16;
+			rx_size = sdio_readl(bdev->func, MTK_REG_CRPLR, NULL);
+			rx_size = (rx_size & RX_PKT_LEN) >> 16;
 			if (btmtksdio_rx_packet(bdev, rx_size) < 0)
 				bdev->hdev->stat.err_rx++;
 		}
-
 	} while (int_status || time_is_before_jiffies(txrx_timeout));
 
 	/* Enable interrupt */
Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#10 lore raw

PATCH 10/10 Bluetooth: btmtksdio: add MT7921s Bluetooth support

In reply to [email protected]

From: Sean Wang <[email protected]>

add MT7921s Bluetooth support

---
 drivers/bluetooth/btmtk.h     |   1 +
 drivers/bluetooth/btmtksdio.c | 141 ++++++++++++++++++++++++++++++++--
 2 files changed, 134 insertions(+), 8 deletions(-)
drivers/bluetooth/btmtk.h +1 -0
index 18f43c641b3b..d6913657d552 100644
@@ -14,6 +14,7 @@ enum {
 	BTMTK_WMT_HIF = 0x4,
 	BTMTK_WMT_FUNC_CTRL = 0x6,
 	BTMTK_WMT_RST = 0x7,
+	BTMTK_WMT_REGISTER = 0x8,
 	BTMTK_WMT_SEMAPHORE = 0x17,
 };
 
drivers/bluetooth/btmtksdio.c +133 -8

192 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#0 lore raw

cover Add MT7921 SDIO Bluetooth support

From: Sean Wang <[email protected]>

The patchset adds the MT7921 SDIO (MT7921s) Blutooth support to btmtksdio driver, which basically are made up of 3 parts.

PART 1: patch 1-3 to create btmtk module to rely on

These are preliminary patches for MT7921s driver to move the common firmware download procedure and the common functions from MT7921u to btmtk module to make MT7921u, MT7921s and other devices can share with to reduce the unnecessary duplicated code being created.

PART 2: patch 4-8 to refactor btmtksdio prior to adding MT7921s

These are preliminary patches for MT7921s driver to refactor the current btmtksdio to make MT7921S is able to coexist with the devices the current driver can support with the generic code and improve the performance on packet transmitting and receving process.

PART 3: patch 9-10 to add specific MT7921s logic

Add the specific logic regarding to MT7921s bluetooth.

Mark-yw Chen (1):
Bluetooth: btmtksdio: transmit packet according to the status TX_EMPTY

Sean Wang (9):
Bluetooth: mediatek: add BT_MTK module
Bluetooth: btmtksido: rely on BT_MTK module
Bluetooth: btmtksdio: add .set_bdaddr support
Bluetooth: btmtksdio: explicitly set WHISR as write-1-clear
Bluetooth: btmtksdio: move interrupt service to work
Bluetooth: btmtksdio: update register CSDIOCSR operation
Bluetooth: btmtksdio: use register CRPLR to read packet length
mmc: add MT7921 SDIO identifiers for MediaTek Bluetooth devices
Bluetooth: btmtksdio: add MT7921s Bluetooth support

 drivers/bluetooth/Kconfig     |   6 +
 drivers/bluetooth/Makefile    |   1 +
 drivers/bluetooth/btmtk.c     | 288 ++++++++++++++++++++
 drivers/bluetooth/btmtk.h     | 101 +++++++
 drivers/bluetooth/btmtksdio.c | 496 +++++++++++++++++-----------------
 drivers/bluetooth/btusb.c     | 331 +----------------------
 include/linux/mmc/sdio_ids.h  |   1 +
 7 files changed, 647 insertions(+), 577 deletions(-)
 create mode 100644 drivers/bluetooth/btmtk.c
 create mode 100644 drivers/bluetooth/btmtk.h

--
2.25.1

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#3 lore raw

PATCH 3/10 Bluetooth: btmtksdio: add .set_bdaddr support

From: Sean Wang <[email protected]>

add .set_bdaddr support

---
 drivers/bluetooth/btmtksdio.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/bluetooth/btmtksdio.c +2 -0
index 53682a4c2ced..77d1c4ac582d 100644
@@ -834,6 +834,8 @@ static int btmtksdio_probe(struct sdio_func *func,
 	hdev->setup    = btmtksdio_setup;
 	hdev->shutdown = btmtksdio_shutdown;
 	hdev->send     = btmtksdio_send_frame;
+	hdev->set_bdaddr = btmtk_set_bdaddr;
+
 	SET_HCIDEV_DEV(hdev, &func->dev);
 
 	hdev->manufacturer = 70;
Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#8 lore raw

PATCH 8/10 Bluetooth: btmtksdio: transmit packet according to the status TX_EMPTY

In reply to [email protected]

From: Mark-yw Chen <[email protected]>

Each packet should be sent out until the device emits the TX_EMPTY signal to the host, that is firmware people suggested to add to meet the actual firmware behavior and that is compatible among all the devices.

---
 drivers/bluetooth/btmtksdio.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/bluetooth/btmtksdio.c +15 -10
index f816a7cb0a74..3266c5d83cae 100644
@@ -103,6 +103,7 @@ struct btmtksdio_dev {
 	struct work_struct txrx_work;
 	unsigned long tx_state;
 	struct sk_buff_head txq;
+	bool hw_tx_ready;
 
 	struct sk_buff *evt_skb;
 
@@ -229,6 +230,7 @@ static int btmtksdio_tx_packet(struct btmtksdio_dev *bdev,
 	sdio_hdr->reserved = cpu_to_le16(0);
 	sdio_hdr->bt_type = hci_skb_pkt_type(skb);
 
+	bdev->hw_tx_ready = false;
 	err = sdio_writesb(bdev->func, MTK_REG_CTDR, skb->data,
 			   round_up(skb->len, MTK_SDIO_BLOCK_SIZE));
 	if (err < 0)
@@ -417,15 +419,6 @@ static void btmtksdio_txrx_work(struct work_struct *work)
 	/* Disable interrupt */
 	sdio_writel(bdev->func, C_INT_EN_CLR, MTK_REG_CHLPCR, 0);
 
-	while ((skb = skb_dequeue(&bdev->txq))) {
-		err = btmtksdio_tx_packet(bdev, skb);
-		if (err < 0) {
-			bdev->hdev->stat.err_tx++;
-			skb_queue_head(&bdev->txq, skb);
-			break;
-		}
-	}
-
 	txrx_timeout = jiffies + 5 * HZ;
 
 	do {
@@ -446,10 +439,21 @@ static void btmtksdio_txrx_work(struct work_struct *work)
 			bt_dev_dbg(bdev->hdev, "Get fw own back");
 
 		if (int_status & TX_EMPTY)
-			schedule_work(&bdev->txrx_work);
+			bdev->hw_tx_ready = true;
 		else if (unlikely(int_status & TX_FIFO_OVERFLOW))
 			bt_dev_warn(bdev->hdev, "Tx fifo overflow");
 
+		if (bdev->hw_tx_ready) {
+			skb = skb_dequeue(&bdev->txq);
+			if (skb) {
+				err = btmtksdio_tx_packet(bdev, skb);
+				if (err < 0) {
+					bdev->hdev->stat.err_tx++;
+					skb_queue_head(&bdev->txq, skb);
+				}
+			}
+		}
+
 		if (int_status & RX_DONE_INT) {
 			rx_size = sdio_readl(bdev->func, MTK_REG_CRPLR, NULL);
 			rx_size = (rx_size & RX_PKT_LEN) >> 16;
@@ -642,6 +646,7 @@ static int btmtksdio_setup(struct hci_dev *hdev)
 	u8 param = 0x1;
 
 	calltime = ktime_get();
+	bdev->hw_tx_ready = true;
 
 	/* Query whether the firmware is already download */
 	wmt_params.op = BTMTK_WMT_SEMAPHORE;
Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#9 lore raw

PATCH 9/10 mmc: add MT7921 SDIO identifiers for MediaTek Bluetooth devices

In reply to [email protected]

From: Sean Wang <[email protected]>

The MT7961 SDIO identifier for MediaTek Bluetooth devices were being referred in the MediaTek Bluetooth driver.

---
 include/linux/mmc/sdio_ids.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/mmc/sdio_ids.h +1 -0
index a85c9f0bd470..53f0efa0bccf 100644
@@ -105,6 +105,7 @@
 #define SDIO_VENDOR_ID_MEDIATEK			0x037a
 #define SDIO_DEVICE_ID_MEDIATEK_MT7663		0x7663
 #define SDIO_DEVICE_ID_MEDIATEK_MT7668		0x7668
+#define SDIO_DEVICE_ID_MEDIATEK_MT7961		0x7961
 
 #define SDIO_VENDOR_ID_MICROCHIP_WILC		0x0296
 #define SDIO_DEVICE_ID_MICROCHIP_WILC1000	0x5347
Signature · 7 lines
2.25.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#11 lore raw

Re: [PATCH v1 10/10] Bluetooth: btmtksdio: add MT7921s Bluetooth support

In reply to [email protected]

Hello!

Quoted 3 lines · On Saturday 09 October 2021 06:10:17 [email protected] wrote:

From: Sean Wang <[email protected]>

add MT7921s Bluetooth support

...

drivers/bluetooth/btmtksdio.c static const struct sdio_device_id btmtksdio_table[] = { · line 64

Quoted 2 lines
drivers/bluetooth/btmtksdio.c +2 -0
+	{SDIO_DEVICE(SDIO_VENDOR_ID_MEDIATEK, SDIO_DEVICE_ID_MEDIATEK_MT7961),
+	 .driver_data = (kernel_ulong_t)&mt7961_data },

You have there probably a typo (MT7921 vs MT7961).

#12 lore raw

Re: [PATCH v1 10/10] Bluetooth: btmtksdio: add MT7921s Bluetooth support

In reply to [email protected]
I love your patch! Perhaps something to improve:

Hi,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on next-20211008]
[cannot apply to linus/master bluetooth/master v5.15-rc4] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/sean-wang-mediatek-com/Add-MT7921-SDIO-Bluetooth-support/20211009-062620
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: riscv-randconfig-s031-20211010 (attached as .config)
compiler: riscv32-linux-gcc (GCC) 11.2.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/a6d87b17fbe3a647ea639749d3f264f7a0194b14
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review sean-wang-mediatek-com/Add-MT7921-SDIO-Bluetooth-support/20211009-062620
git checkout a6d87b17fbe3a647ea639749d3f264f7a0194b14
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=riscv SHELL=/bin/bash drivers/bluetooth/

If you fix the issue, kindly add following tag as appropriate

sparse warnings: (new ones prefixed by >>)

>> drivers/bluetooth/btmtksdio.c:218:34: sparse: sparse: cast to restricted __le32

drivers/bluetooth/btmtksdio.c:444:63: sparse: sparse: Using plain integer as NULL pointer drivers/bluetooth/btmtksdio.c:490:63: sparse: sparse: Using plain integer as NULL pointer drivers/bluetooth/btmtksdio.c:503:63: sparse: sparse: Using plain integer as NULL pointer

vim +218 drivers/bluetooth/btmtksdio.c

122
123 static int mtk_hci_wmt_sync(struct hci_dev *hdev,
124 struct btmtk_hci_wmt_params *wmt_params)
125 {
126 struct btmtksdio_dev *bdev = hci_get_drvdata(hdev);
127 struct btmtk_hci_wmt_evt_funcc *wmt_evt_funcc;
128 u32 hlen, status = BTMTK_WMT_INVALID;
129 struct btmtk_hci_wmt_evt *wmt_evt;
130 struct btmtk_hci_wmt_cmd *wc;
131 struct btmtk_wmt_hdr *hdr;
132 int err;
133
134 /* Send the WMT command and wait until the WMT event returns */
135 hlen = sizeof(*hdr) + wmt_params->dlen;
136 if (hlen > 255)
137 return -EINVAL;
138
139 wc = kzalloc(hlen, GFP_KERNEL);
140 if (!wc)
141 return -ENOMEM;
142
143 hdr = &wc->hdr;
144 hdr->dir = 1;
145 hdr->op = wmt_params->op;
146 hdr->dlen = cpu_to_le16(wmt_params->dlen + 1);
147 hdr->flag = wmt_params->flag;
148 memcpy(wc->data, wmt_params->data, wmt_params->dlen);
149
150 set_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state);
151
152 err = __hci_cmd_send(hdev, 0xfc6f, hlen, wc);
153 if (err < 0) {
154 clear_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state);
155 goto err_free_wc;
156 }
157
158 /* The vendor specific WMT commands are all answered by a vendor
159 * specific event and will not have the Command Status or Command
160 * Complete as with usual HCI command flow control.
161 *
162 * After sending the command, wait for BTMTKSDIO_TX_WAIT_VND_EVT
163 * state to be cleared. The driver specific event receive routine
164 * will clear that state and with that indicate completion of the
165 * WMT command.
166 */
167 err = wait_on_bit_timeout(&bdev->tx_state, BTMTKSDIO_TX_WAIT_VND_EVT,
168 TASK_INTERRUPTIBLE, HCI_INIT_TIMEOUT);
169 if (err == -EINTR) {
170 bt_dev_err(hdev, "Execution of wmt command interrupted");
171 clear_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state);
172 goto err_free_wc;
173 }
174
175 if (err) {
176 bt_dev_err(hdev, "Execution of wmt command timed out");
177 clear_bit(BTMTKSDIO_TX_WAIT_VND_EVT, &bdev->tx_state);
178 err = -ETIMEDOUT;
179 goto err_free_wc;
180 }
181
182 /* Parse and handle the return WMT event */
183 wmt_evt = (struct btmtk_hci_wmt_evt *)bdev->evt_skb->data;
184 if (wmt_evt->whdr.op != hdr->op) {
185 bt_dev_err(hdev, "Wrong op received %d expected %d",
186 wmt_evt->whdr.op, hdr->op);
187 err = -EIO;
188 goto err_free_skb;
189 }
190
191 switch (wmt_evt->whdr.op) {
192 case BTMTK_WMT_SEMAPHORE:
193 if (wmt_evt->whdr.flag == 2)
194 status = BTMTK_WMT_PATCH_UNDONE;
195 else
196 status = BTMTK_WMT_PATCH_DONE;
197 break;
198 case BTMTK_WMT_FUNC_CTRL:
199 wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt;
200 if (be16_to_cpu(wmt_evt_funcc->status) == 0x404)
201 status = BTMTK_WMT_ON_DONE;
202 else if (be16_to_cpu(wmt_evt_funcc->status) == 0x420)
203 status = BTMTK_WMT_ON_PROGRESS;
204 else
205 status = BTMTK_WMT_ON_UNDONE;
206 break;
207 case BTMTK_WMT_PATCH_DWNLD:
208 if (wmt_evt->whdr.flag == 2)
209 status = BTMTK_WMT_PATCH_DONE;
210 else if (wmt_evt->whdr.flag == 1)
211 status = BTMTK_WMT_PATCH_PROGRESS;
212 else
213 status = BTMTK_WMT_PATCH_UNDONE;
214 break;
215 case BTMTK_WMT_REGISTER:
216 if (bdev->evt_skb->len == 18) {
217 memcpy(&status, bdev->evt_skb->data + 14, sizeof(u32));

 > 218				status = le32_to_cpu(status);

219 }
220 break;
221 }
222
223 if (wmt_params->status)
224 *wmt_params->status = status;
225
226 err_free_skb:
227 kfree_skb(bdev->evt_skb);
228 bdev->evt_skb = NULL;
229 err_free_wc:
230 kfree(wc);
231
232 return err;
233 }
234

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org