Across a number of drivers, the same code is used for initializing the
"mbuf_initializer" value inside the rx queue structure for use with the
vector drivers. Since the rx queue structures are (currently) different
across the drivers, we cannot just move a single copy of the function to
a common location. Instead, we create a dedicated function which just
creates the mbuf initializer for a particular port.

In creating this function, we can shorten it vs the original versions by
initializing the mbuf fields as they are defined, rather than
afterwards. We can also remove the use of the barrier and temporary
uintptr_t variable, because the mbuf has been reworked so that
rearm_data is a proper single-element array in a union.

Across ixgbe, i40e, iavf and i40e, we can call this function to
initialize the rxq data, replacing the "*_rxq_vec_setup_default"
functions. Only the i40e was slightly different, having an extra
assignment in it, to set the "sse" flag (even in case of neon and
altivec paths). This assignment was just duplicated to the calling sites
for simplicity and to keep existing behaviour.

Signed-off-by: Bruce Richardson <bruce.richard...@intel.com>
---
 drivers/net/intel/common/rx.h                 | 13 +++++++++++++
 .../net/intel/i40e/i40e_rxtx_vec_altivec.c    |  4 +++-
 drivers/net/intel/i40e/i40e_rxtx_vec_common.h | 19 -------------------
 drivers/net/intel/i40e/i40e_rxtx_vec_neon.c   |  4 +++-
 drivers/net/intel/i40e/i40e_rxtx_vec_sse.c    |  4 +++-
 drivers/net/intel/iavf/iavf_rxtx_vec_common.h | 18 ------------------
 drivers/net/intel/iavf/iavf_rxtx_vec_neon.c   |  3 ++-
 drivers/net/intel/iavf/iavf_rxtx_vec_sse.c    |  3 ++-
 drivers/net/intel/ice/ice_rxtx_vec_common.h   | 18 ------------------
 drivers/net/intel/ice/ice_rxtx_vec_sse.c      |  3 ++-
 .../net/intel/ixgbe/ixgbe_rxtx_vec_common.h   | 18 ------------------
 drivers/net/intel/ixgbe/ixgbe_rxtx_vec_neon.c |  3 ++-
 drivers/net/intel/ixgbe/ixgbe_rxtx_vec_sse.c  |  3 ++-
 13 files changed, 32 insertions(+), 81 deletions(-)

diff --git a/drivers/net/intel/common/rx.h b/drivers/net/intel/common/rx.h
index 5bd2fea7e3..ca0485875c 100644
--- a/drivers/net/intel/common/rx.h
+++ b/drivers/net/intel/common/rx.h
@@ -76,4 +76,17 @@ ci_rx_reassemble_packets(struct rte_mbuf **rx_bufs, uint16_t 
nb_bufs, uint8_t *s
        return pkt_idx;
 }
 
+static inline uint64_t
+ci_rxq_mbuf_initializer(uint16_t port_id)
+{
+       struct rte_mbuf mb_def = {
+               .nb_segs = 1,
+               .data_off = RTE_PKTMBUF_HEADROOM,
+               .port = port_id,
+       };
+       rte_mbuf_refcnt_set(&mb_def, 1);
+
+       return mb_def.rearm_data[0];
+}
+
 #endif /* _COMMON_INTEL_RX_H_ */
diff --git a/drivers/net/intel/i40e/i40e_rxtx_vec_altivec.c 
b/drivers/net/intel/i40e/i40e_rxtx_vec_altivec.c
index b6900a3e15..e8046b5ce5 100644
--- a/drivers/net/intel/i40e/i40e_rxtx_vec_altivec.c
+++ b/drivers/net/intel/i40e/i40e_rxtx_vec_altivec.c
@@ -621,7 +621,9 @@ i40e_rx_queue_release_mbufs_vec(struct i40e_rx_queue *rxq)
 int __rte_cold
 i40e_rxq_vec_setup(struct i40e_rx_queue *rxq)
 {
-       return i40e_rxq_vec_setup_default(rxq);
+       rxq->rx_using_sse = 1;
+       rxq->mbuf_initializer = ci_rxq_mbuf_initializer(rxq->port_id);
+       return 0;
 }
 
 int __rte_cold
diff --git a/drivers/net/intel/i40e/i40e_rxtx_vec_common.h 
b/drivers/net/intel/i40e/i40e_rxtx_vec_common.h
index 4d9d9f669d..445aad3ca8 100644
--- a/drivers/net/intel/i40e/i40e_rxtx_vec_common.h
+++ b/drivers/net/intel/i40e/i40e_rxtx_vec_common.h
@@ -54,25 +54,6 @@ _i40e_rx_queue_release_mbufs_vec(struct i40e_rx_queue *rxq)
        memset(rxq->sw_ring, 0, sizeof(rxq->sw_ring[0]) * rxq->nb_rx_desc);
 }
 
-static inline int
-i40e_rxq_vec_setup_default(struct i40e_rx_queue *rxq)
-{
-       uintptr_t p;
-       struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */
-
-       mb_def.nb_segs = 1;
-       mb_def.data_off = RTE_PKTMBUF_HEADROOM;
-       mb_def.port = rxq->port_id;
-       rte_mbuf_refcnt_set(&mb_def, 1);
-
-       /* prevent compiler reordering: rearm_data covers previous fields */
-       rte_compiler_barrier();
-       p = (uintptr_t)&mb_def.rearm_data;
-       rxq->mbuf_initializer = *(uint64_t *)p;
-       rxq->rx_using_sse = 1;
-       return 0;
-}
-
 static inline int
 i40e_rx_vec_dev_conf_condition_check_default(struct rte_eth_dev *dev)
 {
diff --git a/drivers/net/intel/i40e/i40e_rxtx_vec_neon.c 
b/drivers/net/intel/i40e/i40e_rxtx_vec_neon.c
index b398d66154..1c7e9bf1fa 100644
--- a/drivers/net/intel/i40e/i40e_rxtx_vec_neon.c
+++ b/drivers/net/intel/i40e/i40e_rxtx_vec_neon.c
@@ -749,7 +749,9 @@ i40e_rx_queue_release_mbufs_vec(struct i40e_rx_queue *rxq)
 int __rte_cold
 i40e_rxq_vec_setup(struct i40e_rx_queue *rxq)
 {
-       return i40e_rxq_vec_setup_default(rxq);
+       rxq->rx_using_sse = 1;
+       rxq->mbuf_initializer = ci_rxq_mbuf_initializer(rxq->port_id);
+       return 0;
 }
 
 int __rte_cold
diff --git a/drivers/net/intel/i40e/i40e_rxtx_vec_sse.c 
b/drivers/net/intel/i40e/i40e_rxtx_vec_sse.c
index 90c57e59d0..42255a20af 100644
--- a/drivers/net/intel/i40e/i40e_rxtx_vec_sse.c
+++ b/drivers/net/intel/i40e/i40e_rxtx_vec_sse.c
@@ -767,7 +767,9 @@ i40e_rx_queue_release_mbufs_vec(struct i40e_rx_queue *rxq)
 int __rte_cold
 i40e_rxq_vec_setup(struct i40e_rx_queue *rxq)
 {
-       return i40e_rxq_vec_setup_default(rxq);
+       rxq->rx_using_sse = 1;
+       rxq->mbuf_initializer = ci_rxq_mbuf_initializer(rxq->port_id);
+       return 0;
 }
 
 int __rte_cold
diff --git a/drivers/net/intel/iavf/iavf_rxtx_vec_common.h 
b/drivers/net/intel/iavf/iavf_rxtx_vec_common.h
index 777fb1ce14..859df52b4b 100644
--- a/drivers/net/intel/iavf/iavf_rxtx_vec_common.h
+++ b/drivers/net/intel/iavf/iavf_rxtx_vec_common.h
@@ -54,24 +54,6 @@ _iavf_rx_queue_release_mbufs_vec(struct iavf_rx_queue *rxq)
        memset(rxq->sw_ring, 0, sizeof(rxq->sw_ring[0]) * rxq->nb_rx_desc);
 }
 
-static inline int
-iavf_rxq_vec_setup_default(struct iavf_rx_queue *rxq)
-{
-       uintptr_t p;
-       struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */
-
-       mb_def.nb_segs = 1;
-       mb_def.data_off = RTE_PKTMBUF_HEADROOM;
-       mb_def.port = rxq->port_id;
-       rte_mbuf_refcnt_set(&mb_def, 1);
-
-       /* prevent compiler reordering: rearm_data covers previous fields */
-       rte_compiler_barrier();
-       p = (uintptr_t)&mb_def.rearm_data;
-       rxq->mbuf_initializer = *(uint64_t *)p;
-       return 0;
-}
-
 static inline int
 iavf_rx_vec_queue_default(struct iavf_rx_queue *rxq)
 {
diff --git a/drivers/net/intel/iavf/iavf_rxtx_vec_neon.c 
b/drivers/net/intel/iavf/iavf_rxtx_vec_neon.c
index 04be574683..56685ac02e 100644
--- a/drivers/net/intel/iavf/iavf_rxtx_vec_neon.c
+++ b/drivers/net/intel/iavf/iavf_rxtx_vec_neon.c
@@ -407,7 +407,8 @@ int __rte_cold
 iavf_rxq_vec_setup(struct iavf_rx_queue *rxq)
 {
        rxq->ops = &neon_vec_rxq_ops;
-       return iavf_rxq_vec_setup_default(rxq);
+       rxq->mbuf_initializer = ci_rxq_mbuf_initializer(rxq->port_id);
+       return 0;
 }
 
 int __rte_cold
diff --git a/drivers/net/intel/iavf/iavf_rxtx_vec_sse.c 
b/drivers/net/intel/iavf/iavf_rxtx_vec_sse.c
index 21d5bfd309..210ec9e690 100644
--- a/drivers/net/intel/iavf/iavf_rxtx_vec_sse.c
+++ b/drivers/net/intel/iavf/iavf_rxtx_vec_sse.c
@@ -1469,7 +1469,8 @@ int __rte_cold
 iavf_rxq_vec_setup(struct iavf_rx_queue *rxq)
 {
        rxq->rel_mbufs_type = IAVF_REL_MBUFS_SSE_VEC;
-       return iavf_rxq_vec_setup_default(rxq);
+       rxq->mbuf_initializer = ci_rxq_mbuf_initializer(rxq->port_id);
+       return 0;
 }
 
 int __rte_cold
diff --git a/drivers/net/intel/ice/ice_rxtx_vec_common.h 
b/drivers/net/intel/ice/ice_rxtx_vec_common.h
index 9bd7c2cbf6..2ea7ef8486 100644
--- a/drivers/net/intel/ice/ice_rxtx_vec_common.h
+++ b/drivers/net/intel/ice/ice_rxtx_vec_common.h
@@ -55,24 +55,6 @@ _ice_rx_queue_release_mbufs_vec(struct ice_rx_queue *rxq)
        memset(rxq->sw_ring, 0, sizeof(rxq->sw_ring[0]) * rxq->nb_rx_desc);
 }
 
-static inline int
-ice_rxq_vec_setup_default(struct ice_rx_queue *rxq)
-{
-       uintptr_t p;
-       struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */
-
-       mb_def.nb_segs = 1;
-       mb_def.data_off = RTE_PKTMBUF_HEADROOM;
-       mb_def.port = rxq->port_id;
-       rte_mbuf_refcnt_set(&mb_def, 1);
-
-       /* prevent compiler reordering: rearm_data covers previous fields */
-       rte_compiler_barrier();
-       p = (uintptr_t)&mb_def.rearm_data;
-       rxq->mbuf_initializer = *(uint64_t *)p;
-       return 0;
-}
-
 #define ICE_TX_NO_VECTOR_FLAGS (                       \
                RTE_ETH_TX_OFFLOAD_MULTI_SEGS |         \
                RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |   \
diff --git a/drivers/net/intel/ice/ice_rxtx_vec_sse.c 
b/drivers/net/intel/ice/ice_rxtx_vec_sse.c
index 73e3e9eb54..d723017c2c 100644
--- a/drivers/net/intel/ice/ice_rxtx_vec_sse.c
+++ b/drivers/net/intel/ice/ice_rxtx_vec_sse.c
@@ -789,7 +789,8 @@ ice_rxq_vec_setup(struct ice_rx_queue *rxq)
                return -1;
 
        rxq->rx_rel_mbufs = _ice_rx_queue_release_mbufs_vec;
-       return ice_rxq_vec_setup_default(rxq);
+       rxq->mbuf_initializer = ci_rxq_mbuf_initializer(rxq->port_id);
+       return 0;
 }
 
 int __rte_cold
diff --git a/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_common.h 
b/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_common.h
index 4ac61a8d3b..d9ff7fafe5 100644
--- a/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_common.h
+++ b/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_common.h
@@ -143,24 +143,6 @@ _ixgbe_reset_tx_queue_vec(struct ci_tx_queue *txq)
        memset(txq->ctx_cache, 0, IXGBE_CTX_NUM * sizeof(struct 
ixgbe_advctx_info));
 }
 
-static inline int
-ixgbe_rxq_vec_setup_default(struct ixgbe_rx_queue *rxq)
-{
-       uintptr_t p;
-       struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */
-
-       mb_def.nb_segs = 1;
-       mb_def.data_off = RTE_PKTMBUF_HEADROOM;
-       mb_def.port = rxq->port_id;
-       rte_mbuf_refcnt_set(&mb_def, 1);
-
-       /* prevent compiler reordering: rearm_data covers previous fields */
-       rte_compiler_barrier();
-       p = (uintptr_t)&mb_def.rearm_data;
-       rxq->mbuf_initializer = *(uint64_t *)p;
-       return 0;
-}
-
 static inline int
 ixgbe_txq_vec_setup_default(struct ci_tx_queue *txq,
                            const struct ixgbe_txq_ops *txq_ops)
diff --git a/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_neon.c 
b/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_neon.c
index f879f6fa9a..e832f66e42 100644
--- a/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_neon.c
+++ b/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_neon.c
@@ -659,7 +659,8 @@ static const struct ixgbe_txq_ops vec_txq_ops = {
 int __rte_cold
 ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
 {
-       return ixgbe_rxq_vec_setup_default(rxq);
+       rxq->mbuf_initializer = ci_rxq_mbuf_initializer(rxq->port_id);
+       return 0;
 }
 
 int __rte_cold
diff --git a/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_sse.c 
b/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_sse.c
index 915358e16b..f384b4b0e4 100644
--- a/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_sse.c
+++ b/drivers/net/intel/ixgbe/ixgbe_rxtx_vec_sse.c
@@ -782,7 +782,8 @@ static const struct ixgbe_txq_ops vec_txq_ops = {
 int __rte_cold
 ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
 {
-       return ixgbe_rxq_vec_setup_default(rxq);
+       rxq->mbuf_initializer = ci_rxq_mbuf_initializer(rxq->port_id);
+       return 0;
 }
 
 int __rte_cold
-- 
2.43.0

Reply via email to