linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf
@ 2022-01-13  8:23 sean.wang
  2022-01-13  8:23 ` [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support sean.wang
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: sean.wang @ 2022-01-13  8:23 UTC (permalink / raw)
  To: nbd, lorenzo.bianconi
  Cc: sean.wang, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang,
	Mark-YW.Chen, Deren.Wu, km.lin, jenhao.yang, robin.chiu,
	Eddie.Chen, ch.yeh, posh.sun, ted.huang, Eric.Liang,
	Stella.Chang, Tom.Chou, steve.lee, jsiuda, frankgor, jemele,
	abhishekpandit, shawnku, linux-wireless, linux-mediatek

From: Sean Wang <sean.wang@mediatek.com>

We don't have to create a separate sdio.xmit_buf buffer for each queue.
Instead, we just need to create one, reuse it across all queues to reduce
memory consumption further.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt76.h        |  2 +-
 drivers/net/wireless/mediatek/mt76/mt7615/sdio.c | 15 ++++++---------
 drivers/net/wireless/mediatek/mt76/mt7921/sdio.c | 15 ++++++---------
 drivers/net/wireless/mediatek/mt76/sdio_txrx.c   | 15 ++++++---------
 4 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 14f60fcb6a34..4029a2217397 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -507,7 +507,7 @@ struct mt76_sdio {
 
 	struct work_struct stat_work;
 
-	u8 *xmit_buf[IEEE80211_NUM_ACS + 2];
+	u8 *xmit_buf;
 
 	struct sdio_func *func;
 	void *intr_data;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
index 71162befdae8..554160b0ea9a 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
@@ -101,7 +101,7 @@ static int mt7663s_probe(struct sdio_func *func,
 	struct ieee80211_ops *ops;
 	struct mt7615_dev *dev;
 	struct mt76_dev *mdev;
-	int i, ret;
+	int ret;
 
 	ops = devm_kmemdup(&func->dev, &mt7615_ops, sizeof(mt7615_ops),
 			   GFP_KERNEL);
@@ -140,14 +140,11 @@ static int mt7663s_probe(struct sdio_func *func,
 		goto error;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(mdev->sdio.xmit_buf); i++) {
-		mdev->sdio.xmit_buf[i] = devm_kmalloc(mdev->dev,
-						      MT76S_XMIT_BUF_SZ,
-						      GFP_KERNEL);
-		if (!mdev->sdio.xmit_buf[i]) {
-			ret = -ENOMEM;
-			goto error;
-		}
+	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, MT76S_XMIT_BUF_SZ,
+					   GFP_KERNEL);
+	if (!mdev->sdio.xmit_buf) {
+		ret = -ENOMEM;
+		goto error;
 	}
 
 	ret = mt76s_alloc_rx_queue(mdev, MT_RXQ_MAIN);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
index 743b63f66efa..c58c14e28430 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
@@ -121,7 +121,7 @@ static int mt7921s_probe(struct sdio_func *func,
 
 	struct mt7921_dev *dev;
 	struct mt76_dev *mdev;
-	int ret, i;
+	int ret;
 
 	mdev = mt76_alloc_device(&func->dev, sizeof(*dev), &mt7921_ops,
 				 &drv_ops);
@@ -154,14 +154,11 @@ static int mt7921s_probe(struct sdio_func *func,
 		goto error;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(mdev->sdio.xmit_buf); i++) {
-		mdev->sdio.xmit_buf[i] = devm_kmalloc(mdev->dev,
-						      MT76S_XMIT_BUF_SZ,
-						      GFP_KERNEL);
-		if (!mdev->sdio.xmit_buf[i]) {
-			ret = -ENOMEM;
-			goto error;
-		}
+	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, MT76S_XMIT_BUF_SZ,
+					   GFP_KERNEL);
+	if (!mdev->sdio.xmit_buf) {
+		ret = -ENOMEM;
+		goto error;
 	}
 
 	ret = mt76s_alloc_rx_queue(mdev, MT_RXQ_MAIN);
diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
index 488ad7734d85..a04cd2444247 100644
--- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
+++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
@@ -229,12 +229,11 @@ static int __mt76s_xmit_queue(struct mt76_dev *dev, u8 *data, int len)
 
 static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
 {
-	int qid, err, nframes = 0, len = 0, pse_sz = 0, ple_sz = 0;
+	int err, nframes = 0, len = 0, pse_sz = 0, ple_sz = 0;
 	bool mcu = q == dev->q_mcu[MT_MCUQ_WM];
 	struct mt76_sdio *sdio = &dev->sdio;
 	u8 pad;
 
-	qid = mcu ? ARRAY_SIZE(sdio->xmit_buf) - 1 : q->qid;
 	while (q->first != q->head) {
 		struct mt76_queue_entry *e = &q->entry[q->first];
 		struct sk_buff *iter;
@@ -262,20 +261,18 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
 					&ple_sz))
 			break;
 
-		memcpy(sdio->xmit_buf[qid] + len, e->skb->data,
-		       skb_headlen(e->skb));
+		memcpy(sdio->xmit_buf + len, e->skb->data, skb_headlen(e->skb));
 		len += skb_headlen(e->skb);
 		nframes++;
 
 		skb_walk_frags(e->skb, iter) {
-			memcpy(sdio->xmit_buf[qid] + len, iter->data,
-			       iter->len);
+			memcpy(sdio->xmit_buf + len, iter->data, iter->len);
 			len += iter->len;
 			nframes++;
 		}
 
 		if (unlikely(pad)) {
-			memset(sdio->xmit_buf[qid] + len, 0, pad);
+			memset(sdio->xmit_buf + len, 0, pad);
 			len += pad;
 		}
 next:
@@ -284,8 +281,8 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
 	}
 
 	if (nframes) {
-		memset(sdio->xmit_buf[qid] + len, 0, 4);
-		err = __mt76s_xmit_queue(dev, sdio->xmit_buf[qid], len + 4);
+		memset(sdio->xmit_buf + len, 0, 4);
+		err = __mt76s_xmit_queue(dev, sdio->xmit_buf, len + 4);
 		if (err)
 			return err;
 	}
-- 
2.25.1


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

* [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support
  2022-01-13  8:23 [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf sean.wang
@ 2022-01-13  8:23 ` sean.wang
  2022-01-13  9:09   ` Lorenzo Bianconi
  2022-01-13  8:23 ` [PATCH 3/3] mt76: mt7921s: run sleep mode by default sean.wang
  2022-01-13  9:09 ` [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf Lorenzo Bianconi
  2 siblings, 1 reply; 7+ messages in thread
From: sean.wang @ 2022-01-13  8:23 UTC (permalink / raw)
  To: nbd, lorenzo.bianconi
  Cc: sean.wang, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang,
	Mark-YW.Chen, Deren.Wu, km.lin, jenhao.yang, robin.chiu,
	Eddie.Chen, ch.yeh, posh.sun, ted.huang, Eric.Liang,
	Stella.Chang, Tom.Chou, steve.lee, jsiuda, frankgor, jemele,
	abhishekpandit, shawnku, linux-wireless, linux-mediatek,
	Deren Wu

From: Deren Wu <deren.wu@mediatek.com>

We should take it into account the actual the host and the device MMC
capability to determine what the appropriate xmit_buf_size can be.

Both MT7921S and MT7663 can support up to Tx FIFO size of 0x3fe00 which
means the device can receive 511 blocks of block size 512 in a row from
the host. So if the driver aggregates the frames as many as possible the
the device can support, we can merge multiple MMC requests into a single
one to get rid of the overhead of the handling and synchronizing in those
unnecessary MMC requests and reduce the SDIO lock contention with the
Bluetooth concurrent traffic and finally to have the higher bus
utilization with less idle cycle.

With the patch, it is helpful for WiFi to have steady throughput
performance especially while running Bluetooth concurrently.

Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt76.h        |  4 +++-
 drivers/net/wireless/mediatek/mt76/mt7615/sdio.c |  3 ++-
 drivers/net/wireless/mediatek/mt76/mt7921/sdio.c |  3 ++-
 drivers/net/wireless/mediatek/mt76/sdio.c        | 13 +++++++++++++
 drivers/net/wireless/mediatek/mt76/sdio_txrx.c   |  2 +-
 5 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 4029a2217397..8703ecd6396f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -497,7 +497,7 @@ struct mt76_usb {
 	} mcu;
 };
 
-#define MT76S_XMIT_BUF_SZ	(16 * PAGE_SIZE)
+#define MT76S_XMIT_BUF_SZ	0x3fe00
 #define MT76S_NUM_TX_ENTRIES	256
 #define MT76S_NUM_RX_ENTRIES	512
 struct mt76_sdio {
@@ -508,6 +508,7 @@ struct mt76_sdio {
 	struct work_struct stat_work;
 
 	u8 *xmit_buf;
+	u32 xmit_buf_sz;
 
 	struct sdio_func *func;
 	void *intr_data;
@@ -1280,6 +1281,7 @@ void mt76u_queues_deinit(struct mt76_dev *dev);
 
 int mt76s_init(struct mt76_dev *dev, struct sdio_func *func,
 	       const struct mt76_bus_ops *bus_ops);
+u32 mt76s_get_xmit_buf_sz(struct mt76_dev *dev, u32 dev_xmit_sz);
 int mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid);
 int mt76s_alloc_tx(struct mt76_dev *dev);
 void mt76s_deinit(struct mt76_dev *dev);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
index 554160b0ea9a..ed778b635391 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
@@ -140,7 +140,8 @@ static int mt7663s_probe(struct sdio_func *func,
 		goto error;
 	}
 
-	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, MT76S_XMIT_BUF_SZ,
+	mdev->sdio.xmit_buf_sz = mt76s_get_xmit_buf_sz(mdev, MT76S_XMIT_BUF_SZ);
+	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, mdev->sdio.xmit_buf_sz,
 					   GFP_KERNEL);
 	if (!mdev->sdio.xmit_buf) {
 		ret = -ENOMEM;
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
index c58c14e28430..6e5d9e9459ad 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
@@ -154,7 +154,8 @@ static int mt7921s_probe(struct sdio_func *func,
 		goto error;
 	}
 
-	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, MT76S_XMIT_BUF_SZ,
+	mdev->sdio.xmit_buf_sz = mt76s_get_xmit_buf_sz(mdev, MT76S_XMIT_BUF_SZ);
+	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, mdev->sdio.xmit_buf_sz,
 					   GFP_KERNEL);
 	if (!mdev->sdio.xmit_buf) {
 		ret = -ENOMEM;
diff --git a/drivers/net/wireless/mediatek/mt76/sdio.c b/drivers/net/wireless/mediatek/mt76/sdio.c
index 54f72d215948..bd0027152026 100644
--- a/drivers/net/wireless/mediatek/mt76/sdio.c
+++ b/drivers/net/wireless/mediatek/mt76/sdio.c
@@ -12,6 +12,8 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mmc/sdio_func.h>
+#include <linux/mmc/card.h>
+#include <linux/mmc/host.h>
 #include <linux/sched.h>
 #include <linux/kthread.h>
 
@@ -299,6 +301,17 @@ int mt76s_hw_init(struct mt76_dev *dev, struct sdio_func *func, int hw_ver)
 }
 EXPORT_SYMBOL_GPL(mt76s_hw_init);
 
+u32 mt76s_get_xmit_buf_sz(struct mt76_dev *dev, u32 dev_max_len)
+{
+	struct sdio_func *func = dev->sdio.func;
+	u32 host_max_len = min_t(u32, func->card->host->max_req_size,
+				 func->cur_blksize *
+				 func->card->host->max_blk_count);
+
+	return min_t(u32, host_max_len, dev_max_len);
+}
+EXPORT_SYMBOL_GPL(mt76s_get_xmit_buf_sz);
+
 int mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid)
 {
 	struct mt76_queue *q = &dev->q_rx[qid];
diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
index a04cd2444247..9fcf507e09bd 100644
--- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
+++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
@@ -254,7 +254,7 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
 		}
 
 		pad = roundup(e->skb->len, 4) - e->skb->len;
-		if (len + e->skb->len + pad + 4 > MT76S_XMIT_BUF_SZ)
+		if (len + e->skb->len + pad + 4 > dev->sdio.xmit_buf_sz)
 			break;
 
 		if (mt76s_tx_pick_quota(sdio, mcu, e->buf_sz, &pse_sz,
-- 
2.25.1


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

* [PATCH 3/3] mt76: mt7921s: run sleep mode by default
  2022-01-13  8:23 [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf sean.wang
  2022-01-13  8:23 ` [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support sean.wang
@ 2022-01-13  8:23 ` sean.wang
  2022-01-13  9:03   ` Lorenzo Bianconi
  2022-01-13  9:09 ` [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf Lorenzo Bianconi
  2 siblings, 1 reply; 7+ messages in thread
From: sean.wang @ 2022-01-13  8:23 UTC (permalink / raw)
  To: nbd, lorenzo.bianconi
  Cc: sean.wang, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang,
	Mark-YW.Chen, Deren.Wu, km.lin, jenhao.yang, robin.chiu,
	Eddie.Chen, ch.yeh, posh.sun, ted.huang, Eric.Liang,
	Stella.Chang, Tom.Chou, steve.lee, jsiuda, frankgor, jemele,
	abhishekpandit, shawnku, linux-wireless, linux-mediatek

From: Sean Wang <sean.wang@mediatek.com>

Apply sleep mode by default to reduce power consumption as possible.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt7921/init.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
index ad59ef9839dc..0166a5503aef 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
@@ -226,12 +226,8 @@ int mt7921_register_device(struct mt7921_dev *dev)
 	dev->pm.idle_timeout = MT7921_PM_TIMEOUT;
 	dev->pm.stats.last_wake_event = jiffies;
 	dev->pm.stats.last_doze_event = jiffies;
-
-	/* TODO: mt7921s run sleep mode on default  */
-	if (mt76_is_mmio(&dev->mt76)) {
-		dev->pm.enable = true;
-		dev->pm.ds_enable = true;
-	}
+	dev->pm.enable = true;
+	dev->pm.ds_enable = true;
 
 	if (mt76_is_sdio(&dev->mt76))
 		hw->extra_tx_headroom += MT_SDIO_TXD_SIZE + MT_SDIO_HDR_SIZE;
-- 
2.25.1


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

* Re: [PATCH 3/3] mt76: mt7921s: run sleep mode by default
  2022-01-13  8:23 ` [PATCH 3/3] mt76: mt7921s: run sleep mode by default sean.wang
@ 2022-01-13  9:03   ` Lorenzo Bianconi
  0 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Bianconi @ 2022-01-13  9:03 UTC (permalink / raw)
  To: sean.wang
  Cc: nbd, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang, Mark-YW.Chen,
	Deren.Wu, km.lin, jenhao.yang, robin.chiu, Eddie.Chen, ch.yeh,
	posh.sun, ted.huang, Eric.Liang, Stella.Chang, Tom.Chou,
	steve.lee, jsiuda, frankgor, jemele, abhishekpandit, shawnku,
	linux-wireless, linux-mediatek

[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]

> From: Sean Wang <sean.wang@mediatek.com>
> 
> Apply sleep mode by default to reduce power consumption as possible.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt7921/init.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/init.c b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
> index ad59ef9839dc..0166a5503aef 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/init.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/init.c
> @@ -226,12 +226,8 @@ int mt7921_register_device(struct mt7921_dev *dev)
>  	dev->pm.idle_timeout = MT7921_PM_TIMEOUT;
>  	dev->pm.stats.last_wake_event = jiffies;
>  	dev->pm.stats.last_doze_event = jiffies;
> -
> -	/* TODO: mt7921s run sleep mode on default  */
> -	if (mt76_is_mmio(&dev->mt76)) {
> -		dev->pm.enable = true;
> -		dev->pm.ds_enable = true;
> -	}
> +	dev->pm.enable = true;
> +	dev->pm.ds_enable = true;

cool :)
can you please rebase this patch ontop of the following one?
Regards,
Lorenzo

https://patchwork.kernel.org/project/linux-wireless/patch/f6ad709b1a64152b5955e71b7eef9f9c4c7f127e.1641893305.git.lorenzo@kernel.org/

>  
>  	if (mt76_is_sdio(&dev->mt76))
>  		hw->extra_tx_headroom += MT_SDIO_TXD_SIZE + MT_SDIO_HDR_SIZE;
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf
  2022-01-13  8:23 [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf sean.wang
  2022-01-13  8:23 ` [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support sean.wang
  2022-01-13  8:23 ` [PATCH 3/3] mt76: mt7921s: run sleep mode by default sean.wang
@ 2022-01-13  9:09 ` Lorenzo Bianconi
  2 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Bianconi @ 2022-01-13  9:09 UTC (permalink / raw)
  To: sean.wang
  Cc: nbd, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang, Mark-YW.Chen,
	Deren.Wu, km.lin, jenhao.yang, robin.chiu, Eddie.Chen, ch.yeh,
	posh.sun, ted.huang, Eric.Liang, Stella.Chang, Tom.Chou,
	steve.lee, jsiuda, frankgor, jemele, abhishekpandit, shawnku,
	linux-wireless, linux-mediatek

[-- Attachment #1: Type: text/plain, Size: 5527 bytes --]

> From: Sean Wang <sean.wang@mediatek.com>
> 
> We don't have to create a separate sdio.xmit_buf buffer for each queue.
> Instead, we just need to create one, reuse it across all queues to reduce
> memory consumption further.
> 
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt76.h        |  2 +-
>  drivers/net/wireless/mediatek/mt76/mt7615/sdio.c | 15 ++++++---------
>  drivers/net/wireless/mediatek/mt76/mt7921/sdio.c | 15 ++++++---------
>  drivers/net/wireless/mediatek/mt76/sdio_txrx.c   | 15 ++++++---------
>  4 files changed, 19 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index 14f60fcb6a34..4029a2217397 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -507,7 +507,7 @@ struct mt76_sdio {
>  
>  	struct work_struct stat_work;
>  
> -	u8 *xmit_buf[IEEE80211_NUM_ACS + 2];
> +	u8 *xmit_buf;
>  
>  	struct sdio_func *func;
>  	void *intr_data;
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
> index 71162befdae8..554160b0ea9a 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
> @@ -101,7 +101,7 @@ static int mt7663s_probe(struct sdio_func *func,
>  	struct ieee80211_ops *ops;
>  	struct mt7615_dev *dev;
>  	struct mt76_dev *mdev;
> -	int i, ret;
> +	int ret;
>  
>  	ops = devm_kmemdup(&func->dev, &mt7615_ops, sizeof(mt7615_ops),
>  			   GFP_KERNEL);
> @@ -140,14 +140,11 @@ static int mt7663s_probe(struct sdio_func *func,
>  		goto error;
>  	}
>  
> -	for (i = 0; i < ARRAY_SIZE(mdev->sdio.xmit_buf); i++) {
> -		mdev->sdio.xmit_buf[i] = devm_kmalloc(mdev->dev,
> -						      MT76S_XMIT_BUF_SZ,
> -						      GFP_KERNEL);
> -		if (!mdev->sdio.xmit_buf[i]) {
> -			ret = -ENOMEM;
> -			goto error;
> -		}
> +	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, MT76S_XMIT_BUF_SZ,
> +					   GFP_KERNEL);
> +	if (!mdev->sdio.xmit_buf) {
> +		ret = -ENOMEM;
> +		goto error;
>  	}

I guess we can move buffer allocation in mt76s_init() and remove duplicated
code in mt7663/mt7921.

Reagards,
Lorenzo

>  
>  	ret = mt76s_alloc_rx_queue(mdev, MT_RXQ_MAIN);
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
> index 743b63f66efa..c58c14e28430 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
> @@ -121,7 +121,7 @@ static int mt7921s_probe(struct sdio_func *func,
>  
>  	struct mt7921_dev *dev;
>  	struct mt76_dev *mdev;
> -	int ret, i;
> +	int ret;
>  
>  	mdev = mt76_alloc_device(&func->dev, sizeof(*dev), &mt7921_ops,
>  				 &drv_ops);
> @@ -154,14 +154,11 @@ static int mt7921s_probe(struct sdio_func *func,
>  		goto error;
>  	}
>  
> -	for (i = 0; i < ARRAY_SIZE(mdev->sdio.xmit_buf); i++) {
> -		mdev->sdio.xmit_buf[i] = devm_kmalloc(mdev->dev,
> -						      MT76S_XMIT_BUF_SZ,
> -						      GFP_KERNEL);
> -		if (!mdev->sdio.xmit_buf[i]) {
> -			ret = -ENOMEM;
> -			goto error;
> -		}
> +	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, MT76S_XMIT_BUF_SZ,
> +					   GFP_KERNEL);
> +	if (!mdev->sdio.xmit_buf) {
> +		ret = -ENOMEM;
> +		goto error;
>  	}
>  
>  	ret = mt76s_alloc_rx_queue(mdev, MT_RXQ_MAIN);
> diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> index 488ad7734d85..a04cd2444247 100644
> --- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> +++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> @@ -229,12 +229,11 @@ static int __mt76s_xmit_queue(struct mt76_dev *dev, u8 *data, int len)
>  
>  static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
>  {
> -	int qid, err, nframes = 0, len = 0, pse_sz = 0, ple_sz = 0;
> +	int err, nframes = 0, len = 0, pse_sz = 0, ple_sz = 0;
>  	bool mcu = q == dev->q_mcu[MT_MCUQ_WM];
>  	struct mt76_sdio *sdio = &dev->sdio;
>  	u8 pad;
>  
> -	qid = mcu ? ARRAY_SIZE(sdio->xmit_buf) - 1 : q->qid;
>  	while (q->first != q->head) {
>  		struct mt76_queue_entry *e = &q->entry[q->first];
>  		struct sk_buff *iter;
> @@ -262,20 +261,18 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
>  					&ple_sz))
>  			break;
>  
> -		memcpy(sdio->xmit_buf[qid] + len, e->skb->data,
> -		       skb_headlen(e->skb));
> +		memcpy(sdio->xmit_buf + len, e->skb->data, skb_headlen(e->skb));
>  		len += skb_headlen(e->skb);
>  		nframes++;
>  
>  		skb_walk_frags(e->skb, iter) {
> -			memcpy(sdio->xmit_buf[qid] + len, iter->data,
> -			       iter->len);
> +			memcpy(sdio->xmit_buf + len, iter->data, iter->len);
>  			len += iter->len;
>  			nframes++;
>  		}
>  
>  		if (unlikely(pad)) {
> -			memset(sdio->xmit_buf[qid] + len, 0, pad);
> +			memset(sdio->xmit_buf + len, 0, pad);
>  			len += pad;
>  		}
>  next:
> @@ -284,8 +281,8 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
>  	}
>  
>  	if (nframes) {
> -		memset(sdio->xmit_buf[qid] + len, 0, 4);
> -		err = __mt76s_xmit_queue(dev, sdio->xmit_buf[qid], len + 4);
> +		memset(sdio->xmit_buf + len, 0, 4);
> +		err = __mt76s_xmit_queue(dev, sdio->xmit_buf, len + 4);
>  		if (err)
>  			return err;
>  	}
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support
  2022-01-13  8:23 ` [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support sean.wang
@ 2022-01-13  9:09   ` Lorenzo Bianconi
  0 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Bianconi @ 2022-01-13  9:09 UTC (permalink / raw)
  To: sean.wang
  Cc: nbd, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang, Mark-YW.Chen,
	Deren.Wu, km.lin, jenhao.yang, robin.chiu, Eddie.Chen, ch.yeh,
	posh.sun, ted.huang, Eric.Liang, Stella.Chang, Tom.Chou,
	steve.lee, jsiuda, frankgor, jemele, abhishekpandit, shawnku,
	linux-wireless, linux-mediatek

[-- Attachment #1: Type: text/plain, Size: 5812 bytes --]

> From: Deren Wu <deren.wu@mediatek.com>
> 
> We should take it into account the actual the host and the device MMC
> capability to determine what the appropriate xmit_buf_size can be.
> 
> Both MT7921S and MT7663 can support up to Tx FIFO size of 0x3fe00 which
> means the device can receive 511 blocks of block size 512 in a row from
> the host. So if the driver aggregates the frames as many as possible the
> the device can support, we can merge multiple MMC requests into a single
> one to get rid of the overhead of the handling and synchronizing in those
> unnecessary MMC requests and reduce the SDIO lock contention with the
> Bluetooth concurrent traffic and finally to have the higher bus
> utilization with less idle cycle.
> 
> With the patch, it is helpful for WiFi to have steady throughput
> performance especially while running Bluetooth concurrently.
> 
> Co-developed-by: Sean Wang <sean.wang@mediatek.com>
> Signed-off-by: Sean Wang <sean.wang@mediatek.com>
> Signed-off-by: Deren Wu <deren.wu@mediatek.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt76.h        |  4 +++-
>  drivers/net/wireless/mediatek/mt76/mt7615/sdio.c |  3 ++-
>  drivers/net/wireless/mediatek/mt76/mt7921/sdio.c |  3 ++-
>  drivers/net/wireless/mediatek/mt76/sdio.c        | 13 +++++++++++++
>  drivers/net/wireless/mediatek/mt76/sdio_txrx.c   |  2 +-
>  5 files changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index 4029a2217397..8703ecd6396f 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -497,7 +497,7 @@ struct mt76_usb {
>  	} mcu;
>  };
>  
> -#define MT76S_XMIT_BUF_SZ	(16 * PAGE_SIZE)
> +#define MT76S_XMIT_BUF_SZ	0x3fe00
>  #define MT76S_NUM_TX_ENTRIES	256
>  #define MT76S_NUM_RX_ENTRIES	512
>  struct mt76_sdio {
> @@ -508,6 +508,7 @@ struct mt76_sdio {
>  	struct work_struct stat_work;
>  
>  	u8 *xmit_buf;
> +	u32 xmit_buf_sz;
>  
>  	struct sdio_func *func;
>  	void *intr_data;
> @@ -1280,6 +1281,7 @@ void mt76u_queues_deinit(struct mt76_dev *dev);
>  
>  int mt76s_init(struct mt76_dev *dev, struct sdio_func *func,
>  	       const struct mt76_bus_ops *bus_ops);
> +u32 mt76s_get_xmit_buf_sz(struct mt76_dev *dev, u32 dev_xmit_sz);
>  int mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid);
>  int mt76s_alloc_tx(struct mt76_dev *dev);
>  void mt76s_deinit(struct mt76_dev *dev);
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
> index 554160b0ea9a..ed778b635391 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7615/sdio.c
> @@ -140,7 +140,8 @@ static int mt7663s_probe(struct sdio_func *func,
>  		goto error;
>  	}
>  
> -	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, MT76S_XMIT_BUF_SZ,
> +	mdev->sdio.xmit_buf_sz = mt76s_get_xmit_buf_sz(mdev, MT76S_XMIT_BUF_SZ);
> +	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, mdev->sdio.xmit_buf_sz,
>  					   GFP_KERNEL);
>  	if (!mdev->sdio.xmit_buf) {
>  		ret = -ENOMEM;
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
> index c58c14e28430..6e5d9e9459ad 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c
> @@ -154,7 +154,8 @@ static int mt7921s_probe(struct sdio_func *func,
>  		goto error;
>  	}
>  
> -	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, MT76S_XMIT_BUF_SZ,
> +	mdev->sdio.xmit_buf_sz = mt76s_get_xmit_buf_sz(mdev, MT76S_XMIT_BUF_SZ);
> +	mdev->sdio.xmit_buf = devm_kmalloc(mdev->dev, mdev->sdio.xmit_buf_sz,
>  					   GFP_KERNEL);
>  	if (!mdev->sdio.xmit_buf) {
>  		ret = -ENOMEM;
> diff --git a/drivers/net/wireless/mediatek/mt76/sdio.c b/drivers/net/wireless/mediatek/mt76/sdio.c
> index 54f72d215948..bd0027152026 100644
> --- a/drivers/net/wireless/mediatek/mt76/sdio.c
> +++ b/drivers/net/wireless/mediatek/mt76/sdio.c
> @@ -12,6 +12,8 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/mmc/sdio_func.h>
> +#include <linux/mmc/card.h>
> +#include <linux/mmc/host.h>
>  #include <linux/sched.h>
>  #include <linux/kthread.h>
>  
> @@ -299,6 +301,17 @@ int mt76s_hw_init(struct mt76_dev *dev, struct sdio_func *func, int hw_ver)
>  }
>  EXPORT_SYMBOL_GPL(mt76s_hw_init);
>  
> +u32 mt76s_get_xmit_buf_sz(struct mt76_dev *dev, u32 dev_max_len)
> +{
> +	struct sdio_func *func = dev->sdio.func;
> +	u32 host_max_len = min_t(u32, func->card->host->max_req_size,
> +				 func->cur_blksize *
> +				 func->card->host->max_blk_count);
> +
> +	return min_t(u32, host_max_len, dev_max_len);
> +}
> +EXPORT_SYMBOL_GPL(mt76s_get_xmit_buf_sz);

I think we can squash this patch with the previous one and move the code above
in mt76s_init(). Agree?

Regards,
Lorenzo

> +
>  int mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid)
>  {
>  	struct mt76_queue *q = &dev->q_rx[qid];
> diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> index a04cd2444247..9fcf507e09bd 100644
> --- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> +++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> @@ -254,7 +254,7 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
>  		}
>  
>  		pad = roundup(e->skb->len, 4) - e->skb->len;
> -		if (len + e->skb->len + pad + 4 > MT76S_XMIT_BUF_SZ)
> +		if (len + e->skb->len + pad + 4 > dev->sdio.xmit_buf_sz)
>  			break;
>  
>  		if (mt76s_tx_pick_quota(sdio, mcu, e->buf_sz, &pse_sz,
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support
       [not found] <Yd/sYYP1XJ3J8RuR@lore-desk--annotate>
@ 2022-01-13 22:43 ` sean.wang
  0 siblings, 0 replies; 7+ messages in thread
From: sean.wang @ 2022-01-13 22:43 UTC (permalink / raw)
  To: lorenzo.bianconi
  Cc: nbd, sean.wang, Soul.Huang, YN.Chen, Leon.Yen, Eric-SY.Chang,
	Mark-YW.Chen, Deren.Wu, km.lin, jenhao.yang, robin.chiu,
	Eddie.Chen, ch.yeh, posh.sun, ted.huang, Eric.Liang,
	Stella.Chang, Tom.Chou, steve.lee, jsiuda, frankgor, jemele,
	abhishekpandit, shawnku, linux-wireless, linux-mediatek

From: Sean Wang <sean.wang@mediatek.com>

<snip>
>> @@ -299,6 +301,17 @@ int mt76s_hw_init(struct mt76_dev *dev, struct
>> sdio_func *func, int hw_ver)  }  EXPORT_SYMBOL_GPL(mt76s_hw_init);
>>
>> +u32 mt76s_get_xmit_buf_sz(struct mt76_dev *dev, u32 dev_max_len) {
>> +	struct sdio_func *func = dev->sdio.func;
>> +	u32 host_max_len = min_t(u32, func->card->host->max_req_size,
>> +				 func->cur_blksize *
>> +				 func->card->host->max_blk_count);
>> +
>> +	return min_t(u32, host_max_len, dev_max_len); }
>> +EXPORT_SYMBOL_GPL(mt76s_get_xmit_buf_sz);
>
>I think we can squash this patch with the previous one and move the code above in mt76s_init(). Agree?

these comments you have in the patchset all look fine to me, I will post v2 soon.

	Sean
>
>Regards,
>Lorenzo
>
>> +
>>  int mt76s_alloc_rx_queue(struct mt76_dev *dev, enum mt76_rxq_id qid)
>> {
>>	struct mt76_queue *q = &dev->q_rx[qid]; diff --git
>> a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
>> b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
>> index a04cd2444247..9fcf507e09bd 100644
>> --- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
>> +++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
>> @@ -254,7 +254,7 @@ static int mt76s_tx_run_queue(struct mt76_dev *dev, struct mt76_queue *q)
>>		}
>>
>>		pad = roundup(e->skb->len, 4) - e->skb->len;
>> -		if (len + e->skb->len + pad + 4 > MT76S_XMIT_BUF_SZ)
>> +		if (len + e->skb->len + pad + 4 > dev->sdio.xmit_buf_sz)
>>			break;
>>
>>		if (mt76s_tx_pick_quota(sdio, mcu, e->buf_sz, &pse_sz,
>> --
>> 2.25.1
>>
>

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

end of thread, other threads:[~2022-01-13 22:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13  8:23 [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf sean.wang
2022-01-13  8:23 ` [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support sean.wang
2022-01-13  9:09   ` Lorenzo Bianconi
2022-01-13  8:23 ` [PATCH 3/3] mt76: mt7921s: run sleep mode by default sean.wang
2022-01-13  9:03   ` Lorenzo Bianconi
2022-01-13  9:09 ` [PATCH 1/3] mt76: sdio: remove those unnecessary buffers in sdio.xmit_buf Lorenzo Bianconi
     [not found] <Yd/sYYP1XJ3J8RuR@lore-desk--annotate>
2022-01-13 22:43 ` [PATCH 2/3] mt76: sdio: honor the largest Tx buffer the hardware can support sean.wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).