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 127b4f1e6bSMatan Azrad #include <mlx5_prm.h> 137b4f1e6bSMatan Azrad 145bfc9fc1SYongseok Koh #include "mlx5_autoconf.h" 155bfc9fc1SYongseok Koh 16*b8dc6b0eSVu Pham #include "mlx5_mr.h" 17*b8dc6b0eSVu Pham 18dbccb4cdSShahaf Shuler /* HW checksum offload capabilities of vectorized Tx. */ 19dbccb4cdSShahaf Shuler #define MLX5_VEC_TX_CKSUM_OFFLOAD_CAP \ 20dbccb4cdSShahaf Shuler (DEV_TX_OFFLOAD_IPV4_CKSUM | \ 21dbccb4cdSShahaf Shuler DEV_TX_OFFLOAD_UDP_CKSUM | \ 22dbccb4cdSShahaf Shuler DEV_TX_OFFLOAD_TCP_CKSUM | \ 23dbccb4cdSShahaf Shuler DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) 24dbccb4cdSShahaf Shuler 255bfc9fc1SYongseok Koh /* 265bfc9fc1SYongseok Koh * Compile time sanity check for vectorized functions. 275bfc9fc1SYongseok Koh */ 285bfc9fc1SYongseok Koh 295bfc9fc1SYongseok Koh #define S_ASSERT_RTE_MBUF(s) \ 305bfc9fc1SYongseok Koh static_assert(s, "A field of struct rte_mbuf is changed") 315bfc9fc1SYongseok Koh #define S_ASSERT_MLX5_CQE(s) \ 325bfc9fc1SYongseok Koh static_assert(s, "A field of struct mlx5_cqe is changed") 335bfc9fc1SYongseok Koh 345bfc9fc1SYongseok Koh /* rxq_cq_decompress_v() */ 355bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, pkt_len) == 365bfc9fc1SYongseok Koh offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4); 375bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, data_len) == 385bfc9fc1SYongseok Koh offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8); 395bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, hash) == 405bfc9fc1SYongseok Koh offsetof(struct rte_mbuf, rx_descriptor_fields1) + 12); 415bfc9fc1SYongseok Koh 425bfc9fc1SYongseok Koh /* rxq_cq_to_ptype_oflags_v() */ 435bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, ol_flags) == 445bfc9fc1SYongseok Koh offsetof(struct rte_mbuf, rearm_data) + 8); 455bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, rearm_data) == 465bfc9fc1SYongseok Koh RTE_ALIGN(offsetof(struct rte_mbuf, rearm_data), 16)); 475bfc9fc1SYongseok Koh 485bfc9fc1SYongseok Koh /* rxq_burst_v() */ 495bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, pkt_len) == 505bfc9fc1SYongseok Koh offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4); 515bfc9fc1SYongseok Koh S_ASSERT_RTE_MBUF(offsetof(struct rte_mbuf, data_len) == 525bfc9fc1SYongseok Koh offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8); 53570acdb1SYongseok Koh #if (RTE_CACHE_LINE_SIZE == 128) 54570acdb1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, pkt_info) == 64); 55570acdb1SYongseok Koh #else 565bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, pkt_info) == 0); 57570acdb1SYongseok Koh #endif 585bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, rx_hash_res) == 595bfc9fc1SYongseok Koh offsetof(struct mlx5_cqe, pkt_info) + 12); 608b8f7994SMatan Azrad S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, rsvd1) + 11 == 615bfc9fc1SYongseok Koh offsetof(struct mlx5_cqe, hdr_type_etc)); 625bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, vlan_info) == 635bfc9fc1SYongseok Koh offsetof(struct mlx5_cqe, hdr_type_etc) + 2); 648b8f7994SMatan Azrad S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, lro_num_seg) + 12 == 655bfc9fc1SYongseok Koh offsetof(struct mlx5_cqe, byte_cnt)); 665bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, sop_drop_qpn) == 675bfc9fc1SYongseok Koh RTE_ALIGN(offsetof(struct mlx5_cqe, sop_drop_qpn), 8)); 685bfc9fc1SYongseok Koh S_ASSERT_MLX5_CQE(offsetof(struct mlx5_cqe, op_own) == 695bfc9fc1SYongseok Koh offsetof(struct mlx5_cqe, sop_drop_qpn) + 7); 705bfc9fc1SYongseok Koh 713c2ddbd4SYongseok Koh /** 723c2ddbd4SYongseok Koh * Replenish buffers for RX in bulk. 733c2ddbd4SYongseok Koh * 743c2ddbd4SYongseok Koh * @param rxq 753c2ddbd4SYongseok Koh * Pointer to RX queue structure. 763c2ddbd4SYongseok Koh * @param n 773c2ddbd4SYongseok Koh * Number of buffers to be replenished. 783c2ddbd4SYongseok Koh */ 793c2ddbd4SYongseok Koh static inline void 803c2ddbd4SYongseok Koh mlx5_rx_replenish_bulk_mbuf(struct mlx5_rxq_data *rxq, uint16_t n) 813c2ddbd4SYongseok Koh { 823c2ddbd4SYongseok Koh const uint16_t q_n = 1 << rxq->elts_n; 833c2ddbd4SYongseok Koh const uint16_t q_mask = q_n - 1; 8403e0868bSYongseok Koh uint16_t elts_idx = rxq->rq_ci & q_mask; 853c2ddbd4SYongseok Koh struct rte_mbuf **elts = &(*rxq->elts)[elts_idx]; 867d6bf6b8SYongseok Koh volatile struct mlx5_wqe_data_seg *wq = 877d6bf6b8SYongseok Koh &((volatile struct mlx5_wqe_data_seg *)rxq->wqes)[elts_idx]; 883c2ddbd4SYongseok Koh unsigned int i; 893c2ddbd4SYongseok Koh 908e46d4e1SAlexander Kozyrev MLX5_ASSERT(n >= MLX5_VPMD_RXQ_RPLNSH_THRESH(q_n)); 918e46d4e1SAlexander Kozyrev MLX5_ASSERT(n <= (uint16_t)(q_n - (rxq->rq_ci - rxq->rq_pi))); 928e46d4e1SAlexander Kozyrev MLX5_ASSERT(MLX5_VPMD_RXQ_RPLNSH_THRESH(q_n) > 938e46d4e1SAlexander Kozyrev MLX5_VPMD_DESCS_PER_LOOP); 943c2ddbd4SYongseok Koh /* Not to cross queue end. */ 953c2ddbd4SYongseok Koh n = RTE_MIN(n - MLX5_VPMD_DESCS_PER_LOOP, q_n - elts_idx); 963c2ddbd4SYongseok Koh if (rte_mempool_get_bulk(rxq->mp, (void *)elts, n) < 0) { 973c2ddbd4SYongseok Koh rxq->stats.rx_nombuf += n; 983c2ddbd4SYongseok Koh return; 993c2ddbd4SYongseok Koh } 100974f1e7eSYongseok Koh for (i = 0; i < n; ++i) { 1019c55c6bdSYongseok Koh void *buf_addr; 10212d468a6SYongseok Koh 1039c55c6bdSYongseok Koh /* 104bdb8e5b1SViacheslav Ovsiienko * In order to support the mbufs with external attached 105bdb8e5b1SViacheslav Ovsiienko * data buffer we should use the buf_addr pointer instead of 106bdb8e5b1SViacheslav Ovsiienko * rte_mbuf_buf_addr(). It touches the mbuf itself and may 107bdb8e5b1SViacheslav Ovsiienko * impact the performance. 1089c55c6bdSYongseok Koh */ 1099c55c6bdSYongseok Koh buf_addr = elts[i]->buf_addr; 11012d468a6SYongseok Koh wq[i].addr = rte_cpu_to_be_64((uintptr_t)buf_addr + 1113c2ddbd4SYongseok Koh RTE_PKTMBUF_HEADROOM); 112974f1e7eSYongseok Koh /* If there's only one MR, no need to replace LKey in WQE. */ 113974f1e7eSYongseok Koh if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1)) 114974f1e7eSYongseok Koh wq[i].lkey = mlx5_rx_mb2mr(rxq, elts[i]); 115974f1e7eSYongseok Koh } 1163c2ddbd4SYongseok Koh rxq->rq_ci += n; 11703e0868bSYongseok Koh /* Prevent overflowing into consumed mbufs. */ 11803e0868bSYongseok Koh elts_idx = rxq->rq_ci & q_mask; 11903e0868bSYongseok Koh for (i = 0; i < MLX5_VPMD_DESCS_PER_LOOP; ++i) 12003e0868bSYongseok Koh (*rxq->elts)[elts_idx + i] = &rxq->fake_mbuf; 1214fe7f662SYongseok Koh rte_cio_wmb(); 1223c2ddbd4SYongseok Koh *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci); 1233c2ddbd4SYongseok Koh } 1243c2ddbd4SYongseok Koh 1255bfc9fc1SYongseok Koh #endif /* RTE_PMD_MLX5_RXTX_VEC_H_ */ 126