[v3,15/25] drivers: move queue logic to common module

Message ID 20231026064324.177531-16-chaoyong.he@corigine.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series add the NFP vDPA PMD |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He Oct. 26, 2023, 6:43 a.m. UTC
  Move the queue enable/disable logic to the common library.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/common/nfp/nfp_common.c  | 49 ++++++++++++++++++++++++++++++++
 drivers/common/nfp/nfp_common.h  |  7 +++++
 drivers/common/nfp/version.map   |  2 ++
 drivers/net/nfp/nfp_net_common.c | 38 ++-----------------------
 4 files changed, 61 insertions(+), 35 deletions(-)
  

Patch

diff --git a/drivers/common/nfp/nfp_common.c b/drivers/common/nfp/nfp_common.c
index 1a98326980..4c94c9d59a 100644
--- a/drivers/common/nfp/nfp_common.c
+++ b/drivers/common/nfp/nfp_common.c
@@ -175,3 +175,52 @@  nfp_write_mac(struct nfp_hw *hw,
 	nn_writew(rte_cpu_to_be_16(mac1),
 			hw->ctrl_bar + NFP_NET_CFG_MACADDR + 6);
 }
+
+void
+nfp_enable_queues(struct nfp_hw *hw,
+		uint16_t nb_rx_queues,
+		uint16_t nb_tx_queues)
+{
+	int i;
+	uint64_t enabled_queues;
+
+	/* Enabling the required TX queues in the device */
+	enabled_queues = 0;
+	for (i = 0; i < nb_tx_queues; i++)
+		enabled_queues |= (1 << i);
+
+	nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, enabled_queues);
+
+	/* Enabling the required RX queues in the device */
+	enabled_queues = 0;
+	for (i = 0; i < nb_rx_queues; i++)
+		enabled_queues |= (1 << i);
+
+	nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
+}
+
+void
+nfp_disable_queues(struct nfp_hw *hw)
+{
+	int ret;
+	uint32_t update;
+	uint32_t new_ctrl;
+
+	nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, 0);
+	nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, 0);
+
+	new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_ENABLE;
+	update = NFP_NET_CFG_UPDATE_GEN |
+			NFP_NET_CFG_UPDATE_RING |
+			NFP_NET_CFG_UPDATE_MSIX;
+
+	if ((hw->cap & NFP_NET_CFG_CTRL_RINGCFG) != 0)
+		new_ctrl &= ~NFP_NET_CFG_CTRL_RINGCFG;
+
+	/* If an error when reconfig we avoid to change hw state */
+	ret = nfp_reconfig(hw, new_ctrl, update);
+	if (ret < 0)
+		return;
+
+	hw->ctrl = new_ctrl;
+}
diff --git a/drivers/common/nfp/nfp_common.h b/drivers/common/nfp/nfp_common.h
index 5615cde6af..7597d4090b 100644
--- a/drivers/common/nfp/nfp_common.h
+++ b/drivers/common/nfp/nfp_common.h
@@ -229,4 +229,11 @@  void nfp_read_mac(struct nfp_hw *hw);
 __rte_internal
 void nfp_write_mac(struct nfp_hw *hw, uint8_t *mac);
 
+__rte_internal
+void nfp_enable_queues(struct nfp_hw *hw, uint16_t nb_rx_queues,
+		uint16_t nb_tx_queues);
+
+__rte_internal
+void nfp_disable_queues(struct nfp_hw *hw);
+
 #endif/* __NFP_COMMON_H__ */
diff --git a/drivers/common/nfp/version.map b/drivers/common/nfp/version.map
index f6a54a97cd..c1e03d8b8d 100644
--- a/drivers/common/nfp/version.map
+++ b/drivers/common/nfp/version.map
@@ -8,6 +8,8 @@  INTERNAL {
 	nfp_reconfig_real;
 	nfp_read_mac;
 	nfp_write_mac;
+	nfp_enable_queues;
+	nfp_disable_queues;
 
 	local: *;
 };
diff --git a/drivers/net/nfp/nfp_net_common.c b/drivers/net/nfp/nfp_net_common.c
index 711532b466..090feb0e39 100644
--- a/drivers/net/nfp/nfp_net_common.c
+++ b/drivers/net/nfp/nfp_net_common.c
@@ -327,54 +327,22 @@  nfp_net_enable_rxvlan_cap(struct nfp_net_hw *hw,
 void
 nfp_net_enable_queues(struct rte_eth_dev *dev)
 {
-	uint16_t i;
 	struct nfp_net_hw *hw;
-	uint64_t enabled_queues;
 
 	hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-	/* Enabling the required TX queues in the device */
-	enabled_queues = 0;
-	for (i = 0; i < dev->data->nb_tx_queues; i++)
-		enabled_queues |= (1 << i);
-
-	nn_cfg_writeq(&hw->super, NFP_NET_CFG_TXRS_ENABLE, enabled_queues);
-
-	/* Enabling the required RX queues in the device */
-	enabled_queues = 0;
-	for (i = 0; i < dev->data->nb_rx_queues; i++)
-		enabled_queues |= (1 << i);
-
-	nn_cfg_writeq(&hw->super, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
+	nfp_enable_queues(&hw->super, dev->data->nb_rx_queues,
+			dev->data->nb_tx_queues);
 }
 
 void
 nfp_net_disable_queues(struct rte_eth_dev *dev)
 {
-	uint32_t update;
-	uint32_t new_ctrl;
-	struct nfp_hw *hw;
 	struct nfp_net_hw *net_hw;
 
 	net_hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-	hw = &net_hw->super;
-
-	nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, 0);
-	nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, 0);
-
-	new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_ENABLE;
-	update = NFP_NET_CFG_UPDATE_GEN |
-			NFP_NET_CFG_UPDATE_RING |
-			NFP_NET_CFG_UPDATE_MSIX;
-
-	if ((hw->cap & NFP_NET_CFG_CTRL_RINGCFG) != 0)
-		new_ctrl &= ~NFP_NET_CFG_CTRL_RINGCFG;
 
-	/* If an error when reconfig we avoid to change hw state */
-	if (nfp_reconfig(hw, new_ctrl, update) != 0)
-		return;
-
-	hw->ctrl = new_ctrl;
+	nfp_disable_queues(&net_hw->super);
 }
 
 void