[net-next v1] net: wwan: t7xx: Parameterize data plane RX BAT and FAG count

Jinjian Song posted 1 patch 7 months, 1 week ago
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 12 +++++-------
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h |  3 +++
drivers/net/wwan/t7xx/t7xx_pci.c           | 10 ++++++++++
3 files changed, 18 insertions(+), 7 deletions(-)
[net-next v1] net: wwan: t7xx: Parameterize data plane RX BAT and FAG count
Posted by Jinjian Song 7 months, 1 week ago
The DMA buffer for data plane RX is currently fixed, being parameterized
to allow configuration.

Signed-off-by: Jinjian Song <jinjian.song@fibocom.com>
---
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 12 +++++-------
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h |  3 +++
 drivers/net/wwan/t7xx/t7xx_pci.c           | 10 ++++++++++
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
index 6a7a26085fc7..7848e470432c 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
@@ -49,9 +49,7 @@
 #include "t7xx_netdev.h"
 #include "t7xx_pci.h"
 
-#define DPMAIF_BAT_COUNT		8192
-#define DPMAIF_FRG_COUNT		4814
-#define DPMAIF_PIT_COUNT		(DPMAIF_BAT_COUNT * 2)
+#define DPMAIF_PIT_COUNT		(dpmaif_bat_count * 2)
 
 #define DPMAIF_BAT_CNT_THRESHOLD	30
 #define DPMAIF_PIT_CNT_THRESHOLD	60
@@ -279,7 +277,7 @@ static int t7xx_frag_bat_cur_bid_check(struct dpmaif_rx_queue *rxq,
 	struct dpmaif_bat_request *bat_frag = rxq->bat_frag;
 	struct dpmaif_bat_page *bat_page;
 
-	if (cur_bid >= DPMAIF_FRG_COUNT)
+	if (cur_bid >= dpmaif_frg_count)
 		return -EINVAL;
 
 	bat_page = bat_frag->bat_skb + cur_bid;
@@ -448,7 +446,7 @@ static int t7xx_bat_cur_bid_check(struct dpmaif_rx_queue *rxq, const unsigned in
 	struct dpmaif_bat_skb *bat_skb = rxq->bat_req->bat_skb;
 
 	bat_skb += cur_bid;
-	if (cur_bid >= DPMAIF_BAT_COUNT || !bat_skb->skb)
+	if (cur_bid >= dpmaif_bat_count || !bat_skb->skb)
 		return -EINVAL;
 
 	return 0;
@@ -944,11 +942,11 @@ int t7xx_dpmaif_bat_alloc(const struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_b
 
 	if (buf_type == BAT_TYPE_FRAG) {
 		sw_buf_size = sizeof(struct dpmaif_bat_page);
-		bat_req->bat_size_cnt = DPMAIF_FRG_COUNT;
+		bat_req->bat_size_cnt = dpmaif_frg_count;
 		bat_req->pkt_buf_sz = DPMAIF_HW_FRG_PKTBUF;
 	} else {
 		sw_buf_size = sizeof(struct dpmaif_bat_skb);
-		bat_req->bat_size_cnt = DPMAIF_BAT_COUNT;
+		bat_req->bat_size_cnt = dpmaif_bat_count;
 		bat_req->pkt_buf_sz = DPMAIF_HW_BAT_PKTBUF;
 	}
 
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h
index f4e1b69ad426..4709770fc489 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h
@@ -22,6 +22,9 @@
 
 #include "t7xx_hif_dpmaif.h"
 
+extern uint dpmaif_bat_count;
+extern uint dpmaif_frg_count;
+
 #define NETIF_MASK		GENMASK(4, 0)
 
 #define PKT_TYPE_IP4		0
diff --git a/drivers/net/wwan/t7xx/t7xx_pci.c b/drivers/net/wwan/t7xx/t7xx_pci.c
index 8bf63f2dcbbf..021a05b49225 100644
--- a/drivers/net/wwan/t7xx/t7xx_pci.c
+++ b/drivers/net/wwan/t7xx/t7xx_pci.c
@@ -28,6 +28,7 @@
 #include <linux/jiffies.h>
 #include <linux/list.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/mutex.h>
 #include <linux/pci.h>
 #include <linux/pm.h>
@@ -54,6 +55,15 @@
 #define PM_RESOURCE_POLL_TIMEOUT_US	10000
 #define PM_RESOURCE_POLL_STEP_US	100
 
+uint dpmaif_bat_count = 8192;
+uint dpmaif_frg_count = 4814;
+
+module_param(dpmaif_bat_count, uint, 0644);
+MODULE_PARM_DESC(dpmaif_bat_count, "BAT entry count");
+
+module_param(dpmaif_frg_count, uint, 0644);
+MODULE_PARM_DESC(dpmaif_frg_count, "FRG entry count");
+
 static const char * const t7xx_mode_names[] = {
 	[T7XX_UNKNOWN] = "unknown",
 	[T7XX_READY] = "ready",
-- 
2.34.1
Re: [net-next v1] net: wwan: t7xx: Parameterize data plane RX BAT and FAG count
Posted by Jakub Kicinski 7 months, 1 week ago
On Wed, 14 May 2025 18:47:28 +0800 Jinjian Song wrote:
> The DMA buffer for data plane RX is currently fixed, being parameterized
> to allow configuration.

Module parameters are discouraged, they are pretty poor as an API since
they apply to all devices in the system. Can you describe what "frg"
and "bat" are ? One of the existing APIs likely covers them.
Please also describe the scope (are they per netdev or some sort of
device level params)?
-- 
pw-bot: cr
Re: [net-next v1] net: wwan: t7xx: Parameterize data plane RX BAT and FAG count
Posted by Jakub Kicinski 7 months, 1 week ago
On Fri, 16 May 2025 11:46:57 +0800 Jinjian Song wrote:
> >Module parameters are discouraged, they are pretty poor as an API since
> >they apply to all devices in the system. Can you describe what "frg"
> >and "bat" are ? One of the existing APIs likely covers them.
> >Please also describe the scope (are they per netdev or some sort of
> >device level params)?  
> 
> MTK t7xx data plane hardware use BAT (Buffer Address Table) and FRG (Fragment) BAT
> to describle and manager RX buffer, these buffers will apply for a fixed size after
> the driver probe, and accompany the life cycle of the driver.
> 
> On some platforms, especially those that use swiotlb to manager buffers, without
> changing the buffer pool provided by swiotlb, it's needed to adjust the buffers
> used by the driver to meet the requirements.
> So parameterize these buffers applicable to the MTK t7xx driver to facilitate
> different platforms to work with different configurations. 

Have you looked at
https://docs.kernel.org/networking/ethtool-netlink.html#rings-set 
?
Re: [net-next v1] net: wwan: t7xx: Parameterize data plane RX BAT and FAG count
Posted by Jakub Kicinski 7 months ago
On Tue, 20 May 2025 10:59:34 +0800 Jinjian Song wrote:
>   If it's not feasible to directly add parameters for configuring this RX buffer(BAT/FAG) to 
> the mtk_t7xx driver, would it be allowed to add aparameter for a default configuration 
> ratio (1/2, 1/4)? Or is it not recommended to use driver parameters for mtk_t7xx driver.

Looks into devlink params then
Re: [net-next v1] net: wwan: t7xx: Parameterize data plane RX BAT and FAG count
Posted by Jakub Kicinski 6 months, 2 weeks ago
On Wed,  4 Jun 2025 17:17:22 +0800 Jinjian Song wrote:
> The parameters are used by data plane to request RX DMA buffers for the entrire lifetime of
> the driver, so it's best to determine them at the driver load time. Adjusting them after the
> driver has been probed could introduce complex issues (e.g., the DMA buffers may already be
> in use for communication when the parameters are changed. While devlink appears to support
> parameter configuration via driver reload and runtime adjustment, both of these occur after
> the driver has been probed, which doesn't seem very friendly to the overall logic.

no.