* [PATCH] net/nfp: break out function to initialize device information
@ 2023-06-16 8:14 Chaoyong He
2023-06-21 17:52 ` Ferruh Yigit
0 siblings, 1 reply; 2+ messages in thread
From: Chaoyong He @ 2023-06-16 8:14 UTC (permalink / raw)
To: dev; +Cc: oss-drivers, niklas.soderlund, Peng Zhang, Chaoyong He
From: Peng Zhang <peng.zhang@corigine.com>
The basic logic is the same for PF, VF and representor port.
Split out the initializing device information logics into a
helper function to reduce code duplication.
Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed by: Long Wu <long.wu@corigine.com>
---
drivers/net/nfp/flower/nfp_flower.c | 36 +++-------------------
drivers/net/nfp/nfp_common.c | 46 ++++++++++++++++++++++++++++
drivers/net/nfp/nfp_common.h | 1 +
drivers/net/nfp/nfp_ethdev.c | 39 +++---------------------
drivers/net/nfp/nfp_ethdev_vf.c | 47 ++---------------------------
5 files changed, 58 insertions(+), 111 deletions(-)
diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c
index 53ee936f4c..11783ef273 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -338,26 +338,21 @@ nfp_flower_pf_xmit_pkts(void *tx_queue,
static int
nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type)
{
+ int err;
uint32_t start_q;
uint64_t rx_bar_off;
uint64_t tx_bar_off;
- const int stride = 4;
struct nfp_pf_dev *pf_dev;
struct rte_pci_device *pci_dev;
pf_dev = hw->pf_dev;
pci_dev = hw->pf_dev->pci_dev;
- hw->device_id = pci_dev->id.device_id;
- hw->vendor_id = pci_dev->id.vendor_id;
- hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
- hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
-
PMD_INIT_LOG(DEBUG, "%s vNIC ctrl bar: %p", vnic_type, hw->ctrl_bar);
- /* Read the number of available rx/tx queues from hardware */
- hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
- hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
+ err = nfp_net_common_init(pci_dev, hw);
+ if (err != 0)
+ return err;
/* Work out where in the BAR the queues start */
start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
@@ -368,31 +363,8 @@ nfp_flower_init_vnic_common(struct nfp_net_hw *hw, const char *vnic_type)
hw->tx_bar = pf_dev->hw_queues + tx_bar_off;
hw->rx_bar = pf_dev->hw_queues + rx_bar_off;
- /* Get some of the read-only fields from the config BAR */
- nfp_net_cfg_read_version(hw);
- if (!nfp_net_is_valid_nfd_version(hw->ver))
- return -EINVAL;
-
- hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
- nfp_net_init_metadata_format(hw);
-
- hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
/* Set the current MTU to the maximum supported */
hw->mtu = hw->max_mtu;
- hw->flbufsz = DEFAULT_FLBUF_SIZE;
-
- if (nfp_net_check_dma_mask(hw, pci_dev->name) != 0)
- return -ENODEV;
-
- /* read the Rx offset configured from firmware */
- if (hw->ver.major < 2)
- hw->rx_offset = NFP_NET_RX_OFFSET;
- else
- hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
-
- hw->ctrl = 0;
- hw->stride_rx = stride;
- hw->stride_tx = stride;
/* Reuse cfg queue setup function */
nfp_net_cfg_queue_setup(hw);
diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index 18f974d0e4..5092e5869d 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -1321,6 +1321,52 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
return 0;
}
+int
+nfp_net_common_init(struct rte_pci_device *pci_dev,
+ struct nfp_net_hw *hw)
+{
+ const int stride = 4;
+
+ hw->device_id = pci_dev->id.device_id;
+ hw->vendor_id = pci_dev->id.vendor_id;
+ hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
+ hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
+
+ hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
+ hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
+ if (hw->max_rx_queues == 0 || hw->max_tx_queues == 0) {
+ PMD_INIT_LOG(ERR, "Device %s can not be used, there are no valid queue "
+ "pairs for use", pci_dev->name);
+ return -ENODEV;
+ }
+
+ nfp_net_cfg_read_version(hw);
+ if (!nfp_net_is_valid_nfd_version(hw->ver))
+ return -EINVAL;
+
+ if (nfp_net_check_dma_mask(hw, pci_dev->name) != 0)
+ return -ENODEV;
+
+ /* Get some of the read-only fields from the config BAR */
+ hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
+ hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
+ hw->flbufsz = DEFAULT_FLBUF_SIZE;
+
+ nfp_net_init_metadata_format(hw);
+
+ /* read the Rx offset configured from firmware */
+ if (hw->ver.major < 2)
+ hw->rx_offset = NFP_NET_RX_OFFSET;
+ else
+ hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
+
+ hw->ctrl = 0;
+ hw->stride_rx = stride;
+ hw->stride_tx = stride;
+
+ return 0;
+}
+
const uint32_t *
nfp_net_supported_ptypes_get(struct rte_eth_dev *dev)
{
diff --git a/drivers/net/nfp/nfp_common.h b/drivers/net/nfp/nfp_common.h
index acb34535c5..1ce51d44d4 100644
--- a/drivers/net/nfp/nfp_common.h
+++ b/drivers/net/nfp/nfp_common.h
@@ -375,6 +375,7 @@ nfp_pci_queue(struct rte_pci_device *pdev, uint16_t queue)
int nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, uint32_t update);
int nfp_net_ext_reconfig(struct nfp_net_hw *hw, uint32_t ctrl_ext, uint32_t update);
int nfp_net_configure(struct rte_eth_dev *dev);
+int nfp_net_common_init(struct rte_pci_device *pci_dev, struct nfp_net_hw *hw);
void nfp_net_log_device_information(const struct nfp_net_hw *hw);
void nfp_net_enable_queues(struct rte_eth_dev *dev);
void nfp_net_disable_queues(struct rte_eth_dev *dev);
diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 0ccb543f14..e3ff3d8087 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -499,8 +499,8 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
uint64_t rx_bar_off = 0;
uint64_t tx_bar_off = 0;
uint32_t start_q;
- int stride = 4;
int port = 0;
+ int err;
PMD_INIT_FUNC_TRACE();
@@ -529,15 +529,6 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
rte_eth_copy_pci_info(eth_dev, pci_dev);
- hw->device_id = pci_dev->id.device_id;
- hw->vendor_id = pci_dev->id.vendor_id;
- hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
- hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
-
- PMD_INIT_LOG(DEBUG, "nfp_net: device (%u:%u) %u:%u:%u:%u",
- pci_dev->id.vendor_id, pci_dev->id.device_id,
- pci_dev->addr.domain, pci_dev->addr.bus,
- pci_dev->addr.devid, pci_dev->addr.function);
hw->ctrl_bar = pci_dev->mem_resource[0].addr;
if (hw->ctrl_bar == NULL) {
@@ -569,17 +560,12 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
PMD_INIT_LOG(DEBUG, "MAC stats: %p", hw->mac_stats);
- nfp_net_cfg_read_version(hw);
- if (!nfp_net_is_valid_nfd_version(hw->ver))
- return -EINVAL;
-
- if (nfp_net_check_dma_mask(hw, pci_dev->name) != 0)
- return -ENODEV;
+ err = nfp_net_common_init(pci_dev, hw);
+ if (err != 0)
+ return err;
nfp_net_ethdev_ops_mount(hw, eth_dev);
- hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
- hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
hw->eth_xstats_base = rte_malloc("rte_eth_xstat", sizeof(struct rte_eth_xstat) *
nfp_net_xstats_size(eth_dev), 0);
if (hw->eth_xstats_base == NULL) {
@@ -615,29 +601,12 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
hw->ctrl_bar, hw->tx_bar, hw->rx_bar);
nfp_net_cfg_queue_setup(hw);
-
- /* Get some of the read-only fields from the config BAR */
- hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
- hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
hw->mtu = RTE_ETHER_MTU;
- hw->flbufsz = DEFAULT_FLBUF_SIZE;
/* VLAN insertion is incompatible with LSOv2 */
if (hw->cap & NFP_NET_CFG_CTRL_LSO2)
hw->cap &= ~NFP_NET_CFG_CTRL_TXVLAN;
- nfp_net_init_metadata_format(hw);
-
- if (hw->ver.major < 2)
- hw->rx_offset = NFP_NET_RX_OFFSET;
- else
- hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
-
- hw->ctrl = 0;
-
- hw->stride_rx = stride;
- hw->stride_tx = stride;
-
nfp_net_log_device_information(hw);
/* Initializing spinlock for reconfigs */
diff --git a/drivers/net/nfp/nfp_ethdev_vf.c b/drivers/net/nfp/nfp_ethdev_vf.c
index f971bb8903..019bc3b9be 100644
--- a/drivers/net/nfp/nfp_ethdev_vf.c
+++ b/drivers/net/nfp/nfp_ethdev_vf.c
@@ -267,7 +267,6 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev)
uint64_t tx_bar_off = 0, rx_bar_off = 0;
uint32_t start_q;
- int stride = 4;
int port = 0;
int err;
@@ -286,12 +285,9 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev)
PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
- nfp_net_cfg_read_version(hw);
- if (!nfp_net_is_valid_nfd_version(hw->ver))
- return -EINVAL;
-
- if (nfp_net_check_dma_mask(hw, pci_dev->name) != 0)
- return -ENODEV;
+ err = nfp_net_common_init(pci_dev, hw);
+ if (err != 0)
+ return err;
nfp_netvf_ethdev_ops_mount(hw, eth_dev);
@@ -301,26 +297,6 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev)
rte_eth_copy_pci_info(eth_dev, pci_dev);
- hw->device_id = pci_dev->id.device_id;
- hw->vendor_id = pci_dev->id.vendor_id;
- hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
- hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
-
- PMD_INIT_LOG(DEBUG, "nfp_net: device (%u:%u) %u:%u:%u:%u",
- pci_dev->id.vendor_id, pci_dev->id.device_id,
- pci_dev->addr.domain, pci_dev->addr.bus,
- pci_dev->addr.devid, pci_dev->addr.function);
-
- hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
- hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
- if (hw->max_rx_queues == 0 || hw->max_tx_queues == 0) {
- PMD_DRV_LOG(ERR,
- "Device %s can not be used, there are no valid queue "
- "pairs for use, please try to generate less VFs",
- pci_dev->name);
- return -ENODEV;
- }
-
hw->eth_xstats_base = rte_malloc("rte_eth_xstat", sizeof(struct rte_eth_xstat) *
nfp_net_xstats_size(eth_dev), 0);
if (hw->eth_xstats_base == NULL) {
@@ -356,29 +332,12 @@ nfp_netvf_init(struct rte_eth_dev *eth_dev)
hw->ctrl_bar, hw->tx_bar, hw->rx_bar);
nfp_net_cfg_queue_setup(hw);
-
- /* Get some of the read-only fields from the config BAR */
- hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
- hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
hw->mtu = RTE_ETHER_MTU;
- hw->flbufsz = DEFAULT_FLBUF_SIZE;
/* VLAN insertion is incompatible with LSOv2 */
if (hw->cap & NFP_NET_CFG_CTRL_LSO2)
hw->cap &= ~NFP_NET_CFG_CTRL_TXVLAN;
- nfp_net_init_metadata_format(hw);
-
- if (hw->ver.major < 2)
- hw->rx_offset = NFP_NET_RX_OFFSET;
- else
- hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
-
- hw->ctrl = 0;
-
- hw->stride_rx = stride;
- hw->stride_tx = stride;
-
nfp_net_log_device_information(hw);
/* Initializing spinlock for reconfigs */
--
2.39.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] net/nfp: break out function to initialize device information
2023-06-16 8:14 [PATCH] net/nfp: break out function to initialize device information Chaoyong He
@ 2023-06-21 17:52 ` Ferruh Yigit
0 siblings, 0 replies; 2+ messages in thread
From: Ferruh Yigit @ 2023-06-21 17:52 UTC (permalink / raw)
To: Chaoyong He, dev; +Cc: oss-drivers, niklas.soderlund, Peng Zhang
On 6/16/2023 9:14 AM, Chaoyong He wrote:
> From: Peng Zhang <peng.zhang@corigine.com>
>
> The basic logic is the same for PF, VF and representor port.
> Split out the initializing device information logics into a
> helper function to reduce code duplication.
>
> Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
> Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
> Reviewed by: Long Wu <long.wu@corigine.com>
>
Applied to dpdk-next-net/main, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-21 17:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 8:14 [PATCH] net/nfp: break out function to initialize device information Chaoyong He
2023-06-21 17:52 ` Ferruh Yigit
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).