xref: /dpdk/drivers/net/mlx5/mlx5_rxtx_vec.h (revision 7d6bf6b866b8c25ec06539b3eeed1db4f785577c)
18fd92a66SOlivier Matz /* SPDX-License-Identifier: BSD-3-Clause
25bfc9fc1SYongseok Koh  * Copyright 2017 6WIND S.A.
35feecc57SShahaf Shuler  * Copyright 2017 Mellanox Technologies, Ltd
45bfc9fc1SYongseok Koh  */
55bfc9fc1SYongseok Koh 
65bfc9fc1SYongseok Koh #ifndef RTE_PMD_MLX5_RXTX_VEC_H_
75bfc9fc1SYongseok Koh #define RTE_PMD_MLX5_RXTX_VEC_H_
85bfc9fc1SYongseok Koh 
95bfc9fc1SYongseok Koh #include <rte_common.h>
105bfc9fc1SYongseok Koh #include <rte_mbuf.h>
115bfc9fc1SYongseok Koh 
125bfc9fc1SYongseok Koh #include "mlx5_autoconf.h"
135bfc9fc1SYongseok Koh #include "mlx5_prm.h"
145bfc9fc1SYongseok Koh 
15dbccb4cdSShahaf Shuler /* HW checksum offload capabilities of vectorized Tx. */
16dbccb4cdSShahaf Shuler #define MLX5_VEC_TX_CKSUM_OFFLOAD_CAP \
17dbccb4cdSShahaf Shuler 	(DEV_TX_OFFLOAD_IPV4_CKSUM | \
18dbccb4cdSShahaf Shuler 	 DEV_TX_OFFLOAD_UDP_CKSUM | \
19dbccb4cdSShahaf Shuler 	 DEV_TX_OFFLOAD_TCP_CKSUM | \
20dbccb4cdSShahaf Shuler 	 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)
21dbccb4cdSShahaf Shuler 
22dbccb4cdSShahaf Shuler /* HW offload capabilities of vectorized Tx. */
23dbccb4cdSShahaf Shuler #define MLX5_VEC_TX_OFFLOAD_CAP \
24dbccb4cdSShahaf Shuler 	(MLX5_VEC_TX_CKSUM_OFFLOAD_CAP | \
25dbccb4cdSShahaf Shuler 	 DEV_TX_OFFLOAD_MULTI_SEGS)
26dbccb4cdSShahaf Shuler 
275bfc9fc1SYongseok Koh /*
285bfc9fc1SYongseok Koh  * Compile time sanity check for vectorized functions.
295bfc9fc1SYongseok Koh  */
305bfc9fc1SYongseok Koh 
315bfc9fc1SYongseok Koh #define S_ASSERT_RTE_MBUF(s) \
325bfc9fc1SYongseok Koh 	static_assert(s, "A field of struct rte_mbuf is changed")
335bfc9fc1SYongseok Koh #define S_ASSERT_MLX5_CQE(s) \
345bfc9fc1SYongseok Koh 	static_assert(s, "A field of struct mlx5_cqe is changed")
355bfc9fc1SYongseok Koh 
365bfc9fc1SYongseok Koh /* rxq_cq_decompress_v() */
375bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, pkt_len) ==
385bfc9fc1SYongseok Koh 		  offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
395bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, data_len) ==
405bfc9fc1SYongseok Koh 		  offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
415bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, hash) ==
425bfc9fc1SYongseok Koh 		  offsetof(struct rte_mbuf, rx_descriptor_fields1) + 12);
435bfc9fc1SYongseok Koh 
445bfc9fc1SYongseok Koh /* rxq_cq_to_ptype_oflags_v() */
455bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, ol_flags) ==
465bfc9fc1SYongseok Koh 		  offsetof(struct rte_mbuf, rearm_data) + 8);
475bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, rearm_data) ==
485bfc9fc1SYongseok Koh 		  RTE_ALIGN(offsetof(struct rte_mbuf, rearm_data), 16));
495bfc9fc1SYongseok Koh 
505bfc9fc1SYongseok Koh /* rxq_burst_v() */
515bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, pkt_len) ==
525bfc9fc1SYongseok Koh 		  offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
535bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, data_len) ==
545bfc9fc1SYongseok Koh 		  offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
55570acdb1SYongseok Koh #if (RTE_CACHE_LINE_SIZE == 128)
56570acdb1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, pkt_info) == 64);
57570acdb1SYongseok Koh #else
585bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, pkt_info) == 0);
59570acdb1SYongseok Koh #endif
605bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, rx_hash_res) ==
615bfc9fc1SYongseok Koh 		  offsetof(struct mlx5_cqe, pkt_info) + 12);
625bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, rsvd1) +
635bfc9fc1SYongseok Koh 		  sizeof(((struct mlx5_cqe *)0)->rsvd1) ==
645bfc9fc1SYongseok Koh 		  offsetof(struct mlx5_cqe, hdr_type_etc));
655bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, vlan_info) ==
665bfc9fc1SYongseok Koh 		  offsetof(struct mlx5_cqe, hdr_type_etc) + 2);
675bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, rsvd2) +
685bfc9fc1SYongseok Koh 		  sizeof(((struct mlx5_cqe *)0)->rsvd2) ==
695bfc9fc1SYongseok Koh 		  offsetof(struct mlx5_cqe, byte_cnt));
705bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, sop_drop_qpn) ==
715bfc9fc1SYongseok Koh 		  RTE_ALIGN(offsetof(struct mlx5_cqe, sop_drop_qpn), 8));
725bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, op_own) ==
735bfc9fc1SYongseok Koh 		  offsetof(struct mlx5_cqe, sop_drop_qpn) + 7);
745bfc9fc1SYongseok Koh 
753c2ddbd4SYongseok Koh /**
763c2ddbd4SYongseok Koh  * Replenish buffers for RX in bulk.
773c2ddbd4SYongseok Koh  *
783c2ddbd4SYongseok Koh  * @param rxq
793c2ddbd4SYongseok Koh  *   Pointer to RX queue structure.
803c2ddbd4SYongseok Koh  * @param n
813c2ddbd4SYongseok Koh  *   Number of buffers to be replenished.
823c2ddbd4SYongseok Koh  */
833c2ddbd4SYongseok Koh static inline void
843c2ddbd4SYongseok Koh mlx5_rx_replenish_bulk_mbuf(struct mlx5_rxq_data *rxq, uint16_t n)
853c2ddbd4SYongseok Koh {
863c2ddbd4SYongseok Koh 	const uint16_t q_n = 1 << rxq->elts_n;
873c2ddbd4SYongseok Koh 	const uint16_t q_mask = q_n - 1;
8803e0868bSYongseok Koh 	uint16_t elts_idx = rxq->rq_ci & q_mask;
893c2ddbd4SYongseok Koh 	struct rte_mbuf **elts = &(*rxq->elts)[elts_idx];
90*7d6bf6b8SYongseok Koh 	volatile struct mlx5_wqe_data_seg *wq =
91*7d6bf6b8SYongseok Koh 		&((volatile struct mlx5_wqe_data_seg *)rxq->wqes)[elts_idx];
923c2ddbd4SYongseok Koh 	unsigned int i;
933c2ddbd4SYongseok Koh 
943c2ddbd4SYongseok Koh 	assert(n >= MLX5_VPMD_RXQ_RPLNSH_THRESH);
953c2ddbd4SYongseok Koh 	assert(n <= (uint16_t)(q_n - (rxq->rq_ci - rxq->rq_pi)));
963c2ddbd4SYongseok Koh 	assert(MLX5_VPMD_RXQ_RPLNSH_THRESH > MLX5_VPMD_DESCS_PER_LOOP);
973c2ddbd4SYongseok Koh 	/* Not to cross queue end. */
983c2ddbd4SYongseok Koh 	n = RTE_MIN(n - MLX5_VPMD_DESCS_PER_LOOP, q_n - elts_idx);
993c2ddbd4SYongseok Koh 	if (rte_mempool_get_bulk(rxq->mp, (void *)elts, n) < 0) {
1003c2ddbd4SYongseok Koh 		rxq->stats.rx_nombuf += n;
1013c2ddbd4SYongseok Koh 		return;
1023c2ddbd4SYongseok Koh 	}
103974f1e7eSYongseok Koh 	for (i = 0; i < n; ++i) {
1043c2ddbd4SYongseok Koh 		wq[i].addr = rte_cpu_to_be_64((uintptr_t)elts[i]->buf_addr +
1053c2ddbd4SYongseok Koh 					      RTE_PKTMBUF_HEADROOM);
106974f1e7eSYongseok Koh 		/* If there's only one MR, no need to replace LKey in WQE. */
107974f1e7eSYongseok Koh 		if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
108974f1e7eSYongseok Koh 			wq[i].lkey = mlx5_rx_mb2mr(rxq, elts[i]);
109974f1e7eSYongseok Koh 	}
1103c2ddbd4SYongseok Koh 	rxq->rq_ci += n;
11103e0868bSYongseok Koh 	/* Prevent overflowing into consumed mbufs. */
11203e0868bSYongseok Koh 	elts_idx = rxq->rq_ci & q_mask;
11303e0868bSYongseok Koh 	for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i)
11403e0868bSYongseok Koh 		(*rxq->elts)[elts_idx + i] = &rxq->fake_mbuf;
1154fe7f662SYongseok Koh 	rte_cio_wmb();
1163c2ddbd4SYongseok Koh 	*rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
1173c2ddbd4SYongseok Koh }
1183c2ddbd4SYongseok Koh 
1195bfc9fc1SYongseok Koh #endif /* RTE_PMD_MLX5_RXTX_VEC_H_ */
120