All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junlong Wang <wang.junlong1@zte.com.cn>
To: stephen@networkplumber.org
Cc: dev@dpdk.org, Junlong Wang <wang.junlong1@zte.com.cn>
Subject: [PATCH v3 2/5] net/zxdh: optimize alloc queue resources
Date: Sat, 31 Jan 2026 14:22:05 +0800	[thread overview]
Message-ID: <20260131062208.2445121-3-wang.junlong1@zte.com.cn> (raw)
In-Reply-To: <20260131062208.2445121-1-wang.junlong1@zte.com.cn>


[-- Attachment #1.1.1: Type: text/plain, Size: 7293 bytes --]

optimized alloc queue resources,
alloc queue resources during a hardware lock get and release period.

Signed-off-by: Junlong Wang <wang.junlong1@zte.com.cn>
---
 drivers/net/zxdh/zxdh_common.c | 75 ++++++----------------------------
 drivers/net/zxdh/zxdh_common.h |  2 +-
 drivers/net/zxdh/zxdh_ethdev.c | 24 +++++++----
 drivers/net/zxdh/zxdh_pci.h    |  2 +
 4 files changed, 31 insertions(+), 72 deletions(-)

diff --git a/drivers/net/zxdh/zxdh_common.c b/drivers/net/zxdh/zxdh_common.c
index ce53ee8a05..31ac34b450 100644
--- a/drivers/net/zxdh/zxdh_common.c
+++ b/drivers/net/zxdh/zxdh_common.c
@@ -354,76 +354,25 @@ zxdh_write_comm_reg(uint64_t pci_comm_cfg_baseaddr, uint32_t reg, uint32_t val)
 	*((volatile uint32_t *)(pci_comm_cfg_baseaddr + reg)) = val;
 }
 
-static int32_t
-zxdh_common_table_write(struct zxdh_hw *hw, uint8_t field,
-			void *buff, uint16_t buff_size)
-{
-	struct zxdh_pci_bar_msg desc;
-	struct zxdh_msg_recviver_mem msg_rsp;
-	int32_t ret = 0;
-
-	if (!hw->msg_chan_init) {
-		PMD_DRV_LOG(ERR, "Bar messages channel not initialized");
-		return -1;
-	}
-	if (buff_size != 0 && buff == NULL) {
-		PMD_DRV_LOG(ERR, "Buff is invalid");
-		return -1;
-	}
-
-	ret = zxdh_fill_common_msg(hw, &desc, ZXDH_COMMON_TABLE_WRITE,
-					field, buff, buff_size);
-
-	if (ret != 0) {
-		PMD_DRV_LOG(ERR, "Failed to fill common msg");
-		return ret;
-	}
-
-	ret = zxdh_send_command(hw, &desc, ZXDH_BAR_MODULE_TBL, &msg_rsp);
-	if (ret != 0)
-		goto free_msg_data;
-
-	ret = zxdh_common_rsp_check(&msg_rsp, NULL, 0);
-	if (ret != 0)
-		goto free_rsp_data;
-
-free_rsp_data:
-	rte_free(msg_rsp.recv_buffer);
-free_msg_data:
-	rte_free(desc.payload_addr);
-	return ret;
-}
-
 int32_t
-zxdh_datach_set(struct rte_eth_dev *dev)
+zxdh_datach_set(struct rte_eth_dev *dev, uint16_t ph_chno)
 {
 	struct zxdh_hw *hw = dev->data->dev_private;
-	uint16_t nr_vq = hw->rx_qnum + hw->tx_qnum;
-	uint16_t buff_size = (nr_vq % ZXDH_QUEUES_NUM_MAX + 1) * sizeof(uint16_t);
-	int ret = 0;
-	uint16_t *pdata, i;
-
-	void *buff = rte_zmalloc(NULL, buff_size, 0);
+	uint64_t addr = 0;
+	uint64_t pcieid_addr = 0;
 
-	if (unlikely(buff == NULL)) {
-		PMD_DRV_LOG(ERR, "Failed to allocate buff");
+	if (ph_chno >= ZXDH_QUEUES_PCIEID_SIZE) {
+		PMD_DRV_LOG(ERR, "ph_chno is greater than %08x", ph_chno);
 		return -ENOMEM;
 	}
 
-	pdata = (uint16_t *)buff;
-	*pdata++ = nr_vq;
-	for (i = 0; i < hw->rx_qnum; i++)
-		*(pdata + i) = hw->channel_context[i * 2].ph_chno;
-	for (i = 0; i < hw->tx_qnum; i++)
-		*(pdata + hw->rx_qnum + i) = hw->channel_context[i * 2 + 1].ph_chno;
-	ret = zxdh_common_table_write(hw, ZXDH_COMMON_FIELD_DATACH, (void *)buff, buff_size);
-
-	if (ret != 0)
-		PMD_DRV_LOG(ERR, "Failed to setup data channel of common table. code:%d", ret);
-	hw->queue_set_flag = 1;
-	rte_free(buff);
-
-	return ret;
+	pcieid_addr =
+		*((volatile uint64_t *)(hw->bar_addr[ZXDH_BAR0_INDEX] + ZXDH_QUEUES_PCIEID_ADDR));
+	addr = hw->bar_addr[ZXDH_BAR0_INDEX] + pcieid_addr + (ph_chno << 1);
+	*((volatile uint16_t *)(addr)) = hw->pcie_id;
+	PMD_DRV_LOG(DEBUG, "addr %lx pcie_id %04x, pcieid_addr %lx lch %d",
+		addr, hw->pcie_id, pcieid_addr, ph_chno);
+	return 0;
 }
 
 bool
diff --git a/drivers/net/zxdh/zxdh_common.h b/drivers/net/zxdh/zxdh_common.h
index 6d78ae0273..bbc6bed1df 100644
--- a/drivers/net/zxdh/zxdh_common.h
+++ b/drivers/net/zxdh/zxdh_common.h
@@ -125,7 +125,7 @@ void zxdh_release_lock(struct zxdh_hw *hw);
 int32_t zxdh_timedlock(struct zxdh_hw *hw, uint32_t us);
 uint32_t zxdh_read_comm_reg(uint64_t pci_comm_cfg_baseaddr, uint32_t reg);
 void zxdh_write_comm_reg(uint64_t pci_comm_cfg_baseaddr, uint32_t reg, uint32_t val);
-int32_t zxdh_datach_set(struct rte_eth_dev *dev);
+int32_t zxdh_datach_set(struct rte_eth_dev *dev, uint16_t ph_chno);
 
 bool zxdh_rx_offload_enabled(struct zxdh_hw *hw);
 bool zxdh_tx_offload_enabled(struct zxdh_hw *hw);
diff --git a/drivers/net/zxdh/zxdh_ethdev.c b/drivers/net/zxdh/zxdh_ethdev.c
index 80b992d4ad..2fc2d78aff 100644
--- a/drivers/net/zxdh/zxdh_ethdev.c
+++ b/drivers/net/zxdh/zxdh_ethdev.c
@@ -520,6 +520,9 @@ zxdh_get_available_channel(struct rte_eth_dev *dev, uint8_t queue_type)
 	uint32_t res_bit = (total_queue_num + inval_bit) % 32;
 	uint32_t vq_reg_num = (total_queue_num + inval_bit) / 32 + (res_bit ? 1 : 0);
 	int32_t ret = 0;
+	uint32_t addr = 0;
+	uint32_t var = 0;
+	int32_t ph_chno = 0;
 
 	ret = zxdh_timedlock(hw, 1000);
 	if (ret) {
@@ -528,15 +531,14 @@ zxdh_get_available_channel(struct rte_eth_dev *dev, uint8_t queue_type)
 	}
 
 	for (phy_vq_reg = 0; phy_vq_reg < vq_reg_num; phy_vq_reg++) {
-		uint32_t addr = ZXDH_QUERES_SHARE_BASE +
-		(phy_vq_reg + phy_vq_reg_oft) * sizeof(uint32_t);
-		uint32_t var = zxdh_read_bar_reg(dev, ZXDH_BAR0_INDEX, addr);
+		addr = ZXDH_QUERES_SHARE_BASE +
+			(phy_vq_reg + phy_vq_reg_oft) * sizeof(uint32_t);
+		var = zxdh_read_bar_reg(dev, ZXDH_BAR0_INDEX, addr);
 		if (phy_vq_reg == 0) {
 			for (j = (inval_bit + base); j < 32; j += 2) {
 				/* Got the available channel & update COI table */
 				if ((var & (1 << j)) == 0) {
 					var |= (1 << j);
-					zxdh_write_bar_reg(dev, ZXDH_BAR0_INDEX, addr, var);
 					done = 1;
 					break;
 				}
@@ -548,7 +550,6 @@ zxdh_get_available_channel(struct rte_eth_dev *dev, uint8_t queue_type)
 				/* Got the available channel & update COI table */
 				if ((var & (1 << j)) == 0) {
 					var |= (1 << j);
-					zxdh_write_bar_reg(dev, ZXDH_BAR0_INDEX, addr, var);
 					done = 1;
 					break;
 				}
@@ -560,7 +561,6 @@ zxdh_get_available_channel(struct rte_eth_dev *dev, uint8_t queue_type)
 				/* Got the available channel & update COI table */
 				if ((var & (1 << j)) == 0) {
 					var |= (1 << j);
-					zxdh_write_bar_reg(dev, ZXDH_BAR0_INDEX, addr, var);
 					done = 1;
 					break;
 				}
@@ -570,6 +570,16 @@ zxdh_get_available_channel(struct rte_eth_dev *dev, uint8_t queue_type)
 		}
 	}
 
+	if (done) {
+		ph_chno = (phy_vq_reg + phy_vq_reg_oft) * 32 + j;
+		if (zxdh_datach_set(dev, ph_chno) != 0) {
+			zxdh_release_lock(hw);
+			PMD_DRV_LOG(ERR, "zxdh_datach_set queue pcie addr failed");
+			return -1;
+		}
+		zxdh_write_bar_reg(dev, ZXDH_BAR0_INDEX, addr, var);
+	}
+
 	zxdh_release_lock(hw);
 	/* check for no channel condition */
 	if (done != 1) {
@@ -1333,8 +1343,6 @@ static int32_t zxdh_reconfig_queues(struct rte_eth_dev *dev)
 	if (ret < 0)
 		return ret;
 
-	zxdh_datach_set(dev);
-
 	if (zxdh_configure_intr(dev) < 0) {
 		PMD_DRV_LOG(ERR, "Failed to configure interrupt");
 		zxdh_free_queues(dev);
diff --git a/drivers/net/zxdh/zxdh_pci.h b/drivers/net/zxdh/zxdh_pci.h
index a1834f6615..d0f4ff6398 100644
--- a/drivers/net/zxdh/zxdh_pci.h
+++ b/drivers/net/zxdh/zxdh_pci.h
@@ -65,6 +65,8 @@ enum zxdh_msix_status {
 #define ZXDH_CONFIG_STATUS_DEV_NEED_RESET  0x40
 #define ZXDH_CONFIG_STATUS_FAILED          0x80
 #define ZXDH_PCI_QUEUE_ADDR_SHIFT          12
+#define ZXDH_QUEUES_PCIEID_ADDR            0x1BF8
+#define ZXDH_QUEUES_PCIEID_SIZE            4096
 
 struct __rte_packed_begin zxdh_net_config {
 	/* The config defining mac address (if ZXDH_NET_F_MAC) */
-- 
2.27.0

[-- Attachment #1.1.2: Type: text/html , Size: 17600 bytes --]

  parent reply	other threads:[~2026-01-31  6:45 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-20  6:15 [PATCH v1 0/5] net/zxdh: add support some new features Junlong Wang
2025-12-20  6:15 ` [PATCH v1 1/5] net/zxdh: add support for modifying queue depth Junlong Wang
2025-12-31 19:15   ` Stephen Hemminger
2025-12-20  6:15 ` [PATCH v1 2/5] net/zxdh: optimize alloc queue resources Junlong Wang
2025-12-20  6:15 ` [PATCH v1 3/5] net/zxdh: add support set link speed get autoneg stats Junlong Wang
2025-12-21 16:57   ` Stephen Hemminger
2025-12-31 19:23   ` Stephen Hemminger
2025-12-31 19:24   ` Stephen Hemminger
2025-12-31 19:27   ` Stephen Hemminger
2025-12-20  6:15 ` [PATCH v1 4/5] net/zxdh: add support primary/secondary process Junlong Wang
2025-12-21 17:00   ` Stephen Hemminger
2025-12-23 10:55   ` Junlong Wang
2025-12-23 17:54   ` Stephen Hemminger
2025-12-20  6:15 ` [PATCH v1 5/5] net/zxdh: add support GENEVE TSO and Rx outer UDP chksum Junlong Wang
2026-01-05  7:16 ` [PATCH v2 0/5] net/zxdh: add support some new features Junlong Wang
2026-01-05  7:16   ` [PATCH v2 1/5] net/zxdh: add support for modifying queue depth Junlong Wang
2026-01-05  7:16   ` [PATCH v2 2/5] net/zxdh: optimize alloc queue resources Junlong Wang
2026-01-05  7:16   ` [PATCH v2 3/5] net/zxdh: add support set link speed get autoneg stats Junlong Wang
2026-01-05  7:16   ` [PATCH v2 4/5] net/zxdh: add support primary/secondary process Junlong Wang
2026-01-05  7:16   ` [PATCH v2 5/5] net/zxdh: add support GENEVE TSO and Rx outer chksum Junlong Wang
2026-01-12  0:32   ` [PATCH v2 0/5] net/zxdh: add support some new features Stephen Hemminger
2026-01-31  6:22   ` [PATCH v3 " Junlong Wang
2026-01-31  6:22     ` [PATCH v3 1/5] net/zxdh: add support for modifying queue depth Junlong Wang
2026-01-31  6:22     ` Junlong Wang [this message]
2026-01-31  6:22     ` [PATCH v3 3/5] net/zxdh: add link speed set and autoneg get support Junlong Wang
2026-01-31  6:22     ` [PATCH v3 4/5] net/zxdh: add support for primary/secondary process Junlong Wang
2026-01-31  6:22     ` [PATCH v3 5/5] net/zxdh: add support for GENEVE TSO and Rx outer checksum Junlong Wang
2026-03-18  2:21       ` [v3, " Junlong Wang
2026-03-18 10:16         ` Thomas Monjalon
2026-03-18 10:54           ` Thomas Monjalon
2026-03-19  5:53       ` Junlong Wang
2026-03-19  9:27         ` Thomas Monjalon
2026-01-31 18:11     ` [PATCH v3 0/5] net/zxdh: add support some new features Stephen Hemminger
2026-02-02 19:45     ` Stephen Hemminger
2026-02-03  1:43     ` [v3,0/5] " Junlong Wang

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=20260131062208.2445121-3-wang.junlong1@zte.com.cn \
    --to=wang.junlong1@zte.com.cn \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.