net/nfp: use a single struct eth_dev_ops
cover net/nfp: use a single struct eth_dev_ops
Hi all,
This small series aims to reduce code duplication by using a single shared struct eth_dev_ops for NFDk and NFD3.
Patch 1/2 is a small bug fix that suck in when adding support for NFP3800 where the error code is not correctly propagated.
Patch 2/2 is do the real work by merging the two existing structs and adding the small glue in the setup step that differenced them.
Jin Liu (2):
net/nfp: fix return value of nfp card init function net/nfp: optimize ethdev struct
drivers/net/nfp/nfp_ethdev.c | 38 ++++----------------------------- drivers/net/nfp/nfp_ethdev_vf.c | 36 +++---------------------------- drivers/net/nfp/nfp_rxtx.c | 33 ++++++++++++++++++++++++++-- drivers/net/nfp/nfp_rxtx.h | 5 +---- 4 files changed, 39 insertions(+), 73 deletions(-)
Signature · 1 line
2.37.3
PATCH 1/2 net/nfp: fix return value of nfp card init function
From: Jin Liu <[email protected]>
The return value of 'nfp_pf_init' function is variable ret, but there is one statement, if error occurs, assign error num to variable err, it is incorrect, fixed it.
--- drivers/net/nfp/nfp_ethdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/nfp_ethdev.c +1 -1
@@ -924,7 +924,7 @@ nfp_pf_init(struct rte_pci_device *pci_dev)break ;default :PMD_INIT_LOG (ERR ,"nfp_net: no device ID matching" ); - err = -ENODEV ; + ret = -ENODEV ; goto ctrl_area_cleanup; }
Signature · 1 line
2.37.3
PATCH 2/2 net/nfp: optimize ethdev struct
In reply to Niklas SöderlundFrom: Jin Liu <[email protected]>
Before, use two variables to represent the ethdev structure for firmware with NFDk and NFD3, but only a few field values differ between the two variables. Now use one variable only, and to distinguish different firmware versions in specific functions.
--- drivers/net/nfp/nfp_ethdev.c | 36 +++------------------------------ drivers/net/nfp/nfp_ethdev_vf.c | 36 +++------------------------------ drivers/net/nfp/nfp_rxtx.c | 33 ++++++++++++++++++++++++++++-- drivers/net/nfp/nfp_rxtx.h | 5 +---- 4 files changed, 38 insertions(+), 72 deletions(-)
drivers/net/nfp/nfp_ethdev.c +3 -33
@@ -313,7 +313,7 @@ nfp_net_close(struct rte_eth_dev *dev) }/* Initialise and register driver with DPDK Application */ -static const struct eth_dev_ops nfp_net_nfd3_eth_dev_ops = { +static const struct eth_dev_ops nfp_net_eth_dev_ops = { .dev_configure = nfp_net_configure, .dev_start = nfp_net_start, .dev_stop = nfp_net_stop,
@@ -336,36 +336,7 @@ static const struct eth_dev_ops nfp_net_nfd3_eth_dev_ops = { .rss_hash_conf_get = nfp_net_rss_hash_conf_get, .rx_queue_setup = nfp_net_rx_queue_setup, .rx_queue_release = nfp_net_rx_queue_release, - .tx_queue_setup = nfp_net_nfd3_tx_queue_setup, - .tx_queue_release = nfp_net_tx_queue_release, - .rx_queue_intr_enable = nfp_rx_queue_intr_enable, - .rx_queue_intr_disable = nfp_rx_queue_intr_disable, -}; - -static const struct eth_dev_ops nfp_net_nfdk_eth_dev_ops = { - .dev_configure = nfp_net_configure, - .dev_start = nfp_net_start, - .dev_stop = nfp_net_stop, - .dev_set_link_up = nfp_net_set_link_up, - .dev_set_link_down = nfp_net_set_link_down, - .dev_close = nfp_net_close, - .promiscuous_enable = nfp_net_promisc_enable, - .promiscuous_disable = nfp_net_promisc_disable, - .link_update = nfp_net_link_update, - .stats_get = nfp_net_stats_get, - .stats_reset = nfp_net_stats_reset, - .dev_infos_get = nfp_net_infos_get, - .dev_supported_ptypes_get = nfp_net_supported_ptypes_get, - .mtu_set = nfp_net_dev_mtu_set, - .mac_addr_set = nfp_net_set_mac_addr, - .vlan_offload_set = nfp_net_vlan_offload_set, - .reta_update = nfp_net_reta_update, - .reta_query = nfp_net_reta_query, - .rss_hash_update = nfp_net_rss_hash_update, - .rss_hash_conf_get = nfp_net_rss_hash_conf_get, - .rx_queue_setup = nfp_net_rx_queue_setup, - .rx_queue_release = nfp_net_rx_queue_release, - .tx_queue_setup = nfp_net_nfdk_tx_queue_setup, + .tx_queue_setup = nfp_net_tx_queue_setup, .tx_queue_release = nfp_net_tx_queue_release, .rx_queue_intr_enable = nfp_rx_queue_intr_enable, .rx_queue_intr_disable = nfp_rx_queue_intr_disable,
@@ -376,7 +347,6 @@ nfp_net_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev) {switch (NFD_CFG_CLASS_VER_of (hw->ver)) {case NFP_NET_CFG_VERSION_DP_NFD3 : - eth_dev->dev_ops = &nfp_net_nfd3_eth_dev_ops; eth_dev->tx_pkt_burst = &nfp_net_nfd3_xmit_pkts;break ;case NFP_NET_CFG_VERSION_DP_NFDK :
@@ -385,7 +355,6 @@ nfp_net_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev) NFD_CFG_MAJOR_VERSION_of(hw->ver));return -EINVAL ; } - eth_dev->dev_ops = &nfp_net_nfdk_eth_dev_ops; eth_dev->tx_pkt_burst = &nfp_net_nfdk_xmit_pkts;break ;default :
@@ -393,6 +362,7 @@ nfp_net_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev)return -EINVAL ; } + eth_dev->dev_ops = &nfp_net_eth_dev_ops; eth_dev->rx_queue_count = nfp_net_rx_queue_count; eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
drivers/net/nfp/nfp_ethdev_vf.c +3 -33
@@ -218,7 +218,7 @@ nfp_netvf_close(struct rte_eth_dev *dev) }/* Initialise and register VF driver with DPDK Application */ -static const struct eth_dev_ops nfp_netvf_nfd3_eth_dev_ops = { +static const struct eth_dev_ops nfp_netvf_eth_dev_ops = { .dev_configure = nfp_net_configure, .dev_start = nfp_netvf_start, .dev_stop = nfp_netvf_stop,
@@ -241,36 +241,7 @@ static const struct eth_dev_ops nfp_netvf_nfd3_eth_dev_ops = { .rss_hash_conf_get = nfp_net_rss_hash_conf_get, .rx_queue_setup = nfp_net_rx_queue_setup, .rx_queue_release = nfp_net_rx_queue_release, - .tx_queue_setup = nfp_net_nfd3_tx_queue_setup, - .tx_queue_release = nfp_net_tx_queue_release, - .rx_queue_intr_enable = nfp_rx_queue_intr_enable, - .rx_queue_intr_disable = nfp_rx_queue_intr_disable, -}; - -static const struct eth_dev_ops nfp_netvf_nfdk_eth_dev_ops = { - .dev_configure = nfp_net_configure, - .dev_start = nfp_netvf_start, - .dev_stop = nfp_netvf_stop, - .dev_set_link_up = nfp_netvf_set_link_up, - .dev_set_link_down = nfp_netvf_set_link_down, - .dev_close = nfp_netvf_close, - .promiscuous_enable = nfp_net_promisc_enable, - .promiscuous_disable = nfp_net_promisc_disable, - .link_update = nfp_net_link_update, - .stats_get = nfp_net_stats_get, - .stats_reset = nfp_net_stats_reset, - .dev_infos_get = nfp_net_infos_get, - .dev_supported_ptypes_get = nfp_net_supported_ptypes_get, - .mtu_set = nfp_net_dev_mtu_set, - .mac_addr_set = nfp_net_set_mac_addr, - .vlan_offload_set = nfp_net_vlan_offload_set, - .reta_update = nfp_net_reta_update, - .reta_query = nfp_net_reta_query, - .rss_hash_update = nfp_net_rss_hash_update, - .rss_hash_conf_get = nfp_net_rss_hash_conf_get, - .rx_queue_setup = nfp_net_rx_queue_setup, - .rx_queue_release = nfp_net_rx_queue_release, - .tx_queue_setup = nfp_net_nfdk_tx_queue_setup, + .tx_queue_setup = nfp_net_tx_queue_setup, .tx_queue_release = nfp_net_tx_queue_release, .rx_queue_intr_enable = nfp_rx_queue_intr_enable, .rx_queue_intr_disable = nfp_rx_queue_intr_disable,
@@ -281,7 +252,6 @@ nfp_netvf_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev) {switch (NFD_CFG_CLASS_VER_of (hw->ver)) {case NFP_NET_CFG_VERSION_DP_NFD3 : - eth_dev->dev_ops = &nfp_netvf_nfd3_eth_dev_ops; eth_dev->tx_pkt_burst = &nfp_net_nfd3_xmit_pkts;break ;case NFP_NET_CFG_VERSION_DP_NFDK :
@@ -290,7 +260,6 @@ nfp_netvf_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev) NFD_CFG_MAJOR_VERSION_of(hw->ver));return -EINVAL ; } - eth_dev->dev_ops = &nfp_netvf_nfdk_eth_dev_ops; eth_dev->tx_pkt_burst = &nfp_net_nfdk_xmit_pkts;break ;default :
@@ -298,6 +267,7 @@ nfp_netvf_ethdev_ops_mount(struct nfp_net_hw *hw, struct rte_eth_dev *eth_dev)return -EINVAL ; } + eth_dev->dev_ops = &nfp_netvf_eth_dev_ops; eth_dev->rx_queue_count = nfp_net_rx_queue_count; eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
drivers/net/nfp/nfp_rxtx.c +31 -2
@@ -657,7 +657,7 @@ nfp_net_reset_tx_queue(struct nfp_net_txq *txq) txq->rd_p =0 ; } -int +static int nfp_net_nfd3_tx_queue_setup (struct rte_eth_dev *dev,uint16_t queue_idx,uint16_t nb_desc,unsigned int socket_id,const struct rte_eth_txconf *tx_conf)
@@ -991,7 +991,7 @@ nfp_net_nfd3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkreturn i; } -int +static int nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx, uint16_t nb_desc,
@@ -1108,6 +1108,35 @@ nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev,return 0 ; } +int +nfp_net_tx_queue_setup (struct rte_eth_dev *dev, +uint16_t queue_idx, +uint16_t nb_desc, +unsigned int socket_id, +const struct rte_eth_txconf *tx_conf) +{ +struct nfp_net_hw *hw; + + hw =NFP_NET_DEV_PRIVATE_TO_HW (dev->data->dev_private); + +switch (NFD_CFG_CLASS_VER_of (hw->ver)) { +case NFP_NET_CFG_VERSION_DP_NFD3 : +return nfp_net_nfd3_tx_queue_setup (dev, queue_idx, + nb_desc, socket_id, tx_conf); +case NFP_NET_CFG_VERSION_DP_NFDK : +if (NFD_CFG_MAJOR_VERSION_of (hw->ver) <5 ) { +PMD_DRV_LOG (ERR ,"NFDK must use ABI 5 or newer, found: %d" , +NFD_CFG_MAJOR_VERSION_of (hw->ver)); +return -EINVAL ; + } +return nfp_net_nfdk_tx_queue_setup (dev, queue_idx, + nb_desc, socket_id, tx_conf); +default : +PMD_DRV_LOG (ERR ,"The version of firmware is not correct." ); +return -EINVAL ; + } +} +static inline uint32_t nfp_net_nfdk_free_tx_desc (struct nfp_net_txq *txq) {
drivers/net/nfp/nfp_rxtx.h +1 -4
@@ -342,12 +342,9 @@ int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx, struct rte_mempool *mp);void nfp_net_tx_queue_release (struct rte_eth_dev *dev,uint16_t queue_idx);void nfp_net_reset_tx_queue (struct nfp_net_txq *txq); -int nfp_net_nfd3_tx_queue_setup (struct rte_eth_dev *dev,uint16_t queue_idx, -uint16_t nb_desc,unsigned int socket_id, -const struct rte_eth_txconf *tx_conf);uint16_t nfp_net_nfd3_xmit_pkts (void *tx_queue,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); -int nfp_net_nfdk_tx_queue_setup(struct rte_eth_dev *dev, +int nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx, uint16_t nb_desc, unsigned int socket_id,
Signature · 1 line
2.37.3
Quoted 8 lines · Niklas Söderlund
Hi all,
This small series aims to reduce code duplication by using a single shared struct
eth_dev_opsfor NFDk and NFD3.Patch 1/2 is a small bug fix that suck in when adding support for NFP3800 where the error code is not correctly propagated.
Quoted 7 lines
Patch 2/2 is do the real work by merging the two existing structs and adding the small glue in the setup step that differenced them.
Jin Liu (2):
net/nfp: fix return value of nfp card init function net/nfp: optimize ethdev struct
Series applied to dpdk-next-net/main, thanks.