LCOV - code coverage report
Current view: top level - drivers/net/mlx5 - mlx5_rx.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 95 0.0 %
Date: 2025-04-03 19:37:06 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 144 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2021 6WIND S.A.
       3                 :            :  * Copyright 2021 Mellanox Technologies, Ltd
       4                 :            :  */
       5                 :            : 
       6                 :            : #ifndef RTE_PMD_MLX5_RX_H_
       7                 :            : #define RTE_PMD_MLX5_RX_H_
       8                 :            : 
       9                 :            : #include <stdint.h>
      10                 :            : #include <sys/queue.h>
      11                 :            : 
      12                 :            : #include <rte_mbuf.h>
      13                 :            : #include <rte_mempool.h>
      14                 :            : #include <rte_common.h>
      15                 :            : #include <rte_spinlock.h>
      16                 :            : 
      17                 :            : #include <mlx5_common_mr.h>
      18                 :            : 
      19                 :            : #include "mlx5.h"
      20                 :            : #include "mlx5_autoconf.h"
      21                 :            : #include "rte_pmd_mlx5.h"
      22                 :            : 
      23                 :            : /* Support tunnel matching. */
      24                 :            : #define MLX5_FLOW_TUNNEL 10
      25                 :            : 
      26                 :            : #define RXQ_PORT(rxq_ctrl) LIST_FIRST(&(rxq_ctrl)->owners)->priv
      27                 :            : #define RXQ_DEV(rxq_ctrl) ETH_DEV(RXQ_PORT(rxq_ctrl))
      28                 :            : #define RXQ_PORT_ID(rxq_ctrl) PORT_ID(RXQ_PORT(rxq_ctrl))
      29                 :            : 
      30                 :            : /* First entry must be NULL for comparison. */
      31                 :            : #define mlx5_mr_btree_len(bt) ((bt)->len - 1)
      32                 :            : 
      33                 :            : struct mlx5_rxq_stat {
      34                 :            :         int id;
      35                 :            :         uint64_t count;
      36                 :            :         struct mlx5_stat_counter_ctrl ctrl;
      37                 :            : };
      38                 :            : 
      39                 :            : struct mlx5_rxq_stats {
      40                 :            : #ifdef MLX5_PMD_SOFT_COUNTERS
      41                 :            :         uint64_t ipackets; /**< Total of successfully received packets. */
      42                 :            :         uint64_t ibytes; /**< Total of successfully received bytes. */
      43                 :            : #endif
      44                 :            :         uint64_t idropped; /**< Total of packets dropped when RX ring full. */
      45                 :            :         uint64_t rx_nombuf; /**< Total of RX mbuf allocation failures. */
      46                 :            :         struct mlx5_rxq_stat oobs; /**< Total of hairpin queue out of buffers. */
      47                 :            : };
      48                 :            : 
      49                 :            : /* store statistics names and its offset in stats structure  */
      50                 :            : struct mlx5_xstats_name_off {
      51                 :            :         char name[RTE_ETH_XSTATS_NAME_SIZE];
      52                 :            :         unsigned int offset;
      53                 :            : };
      54                 :            : 
      55                 :            : struct mlx5_rq_stats {
      56                 :            :         /** Total number of hairpin queue packets received that are dropped. */
      57                 :            :         uint64_t q_oobs[RTE_ETHDEV_QUEUE_STAT_CNTRS];
      58                 :            : };
      59                 :            : 
      60                 :            : /* Compressed CQE context. */
      61                 :            : struct rxq_zip {
      62                 :            :         uint16_t cqe_cnt; /* Number of CQEs. */
      63                 :            :         uint16_t ai; /* Array index. */
      64                 :            :         uint32_t ca; /* Current array index. */
      65                 :            :         uint32_t na; /* Next array index. */
      66                 :            :         uint32_t cq_ci; /* The next CQE. */
      67                 :            : };
      68                 :            : 
      69                 :            : /* Get pointer to the first stride. */
      70                 :            : #define mlx5_mprq_buf_addr(ptr, strd_n) (RTE_PTR_ADD((ptr), \
      71                 :            :                                 sizeof(struct mlx5_mprq_buf) + \
      72                 :            :                                 (strd_n) * \
      73                 :            :                                 sizeof(struct rte_mbuf_ext_shared_info) + \
      74                 :            :                                 RTE_PKTMBUF_HEADROOM))
      75                 :            : 
      76                 :            : #define MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES 6
      77                 :            : #define MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES 9
      78                 :            : 
      79                 :            : enum mlx5_rxq_err_state {
      80                 :            :         MLX5_RXQ_ERR_STATE_NO_ERROR = 0,
      81                 :            :         MLX5_RXQ_ERR_STATE_NEED_RESET,
      82                 :            :         MLX5_RXQ_ERR_STATE_NEED_READY,
      83                 :            :         MLX5_RXQ_ERR_STATE_IGNORE,
      84                 :            : };
      85                 :            : 
      86                 :            : enum mlx5_rqx_code {
      87                 :            :         MLX5_RXQ_CODE_EXIT = 0,
      88                 :            :         MLX5_RXQ_CODE_NOMBUF,
      89                 :            :         MLX5_RXQ_CODE_DROPPED,
      90                 :            : };
      91                 :            : 
      92                 :            : struct mlx5_eth_rxseg {
      93                 :            :         struct rte_mempool *mp; /**< Memory pool to allocate segment from. */
      94                 :            :         uint16_t length; /**< Segment data length, configures split point. */
      95                 :            :         uint16_t offset; /**< Data offset from beginning of mbuf data buffer. */
      96                 :            :         uint32_t reserved; /**< Reserved field. */
      97                 :            : };
      98                 :            : 
      99                 :            : /* RX queue descriptor. */
     100                 :            : struct __rte_cache_aligned mlx5_rxq_data {
     101                 :            :         unsigned int csum:1; /* Enable checksum offloading. */
     102                 :            :         unsigned int hw_timestamp:1; /* Enable HW timestamp. */
     103                 :            :         unsigned int rt_timestamp:1; /* Realtime timestamp format. */
     104                 :            :         unsigned int vlan_strip:1; /* Enable VLAN stripping. */
     105                 :            :         unsigned int crc_present:1; /* CRC must be subtracted. */
     106                 :            :         unsigned int sges_n:3; /* Log 2 of SGEs (max buffers per packet). */
     107                 :            :         unsigned int cqe_n:4; /* Log 2 of CQ elements. */
     108                 :            :         unsigned int elts_n:4; /* Log 2 of Mbufs. */
     109                 :            :         unsigned int rss_hash:1; /* RSS hash result is enabled. */
     110                 :            :         unsigned int mark:1; /* Marked flow available on the queue. */
     111                 :            :         unsigned int log_strd_num:5; /* Log 2 of the number of stride. */
     112                 :            :         unsigned int log_strd_sz:4; /* Log 2 of stride size. */
     113                 :            :         unsigned int strd_shift_en:1; /* Enable 2bytes shift on a stride. */
     114                 :            :         unsigned int err_state:2; /* enum mlx5_rxq_err_state. */
     115                 :            :         unsigned int strd_scatter_en:1; /* Scattered packets from a stride. */
     116                 :            :         unsigned int lro:1; /* Enable LRO. */
     117                 :            :         unsigned int dynf_meta:1; /* Dynamic metadata is configured. */
     118                 :            :         unsigned int mcqe_format:3; /* CQE compression format. */
     119                 :            :         unsigned int shared:1; /* Shared RXQ. */
     120                 :            :         unsigned int delay_drop:1; /* Enable delay drop. */
     121                 :            :         unsigned int cqe_comp_layout:1; /* CQE Compression Layout*/
     122                 :            :         uint16_t port_id;
     123                 :            :         volatile uint32_t *rq_db;
     124                 :            :         volatile uint32_t *cq_db;
     125                 :            :         uint32_t elts_ci;
     126                 :            :         uint32_t rq_ci;
     127                 :            :         uint16_t consumed_strd; /* Number of consumed strides in WQE. */
     128                 :            :         uint32_t rq_pi;
     129                 :            :         uint32_t cq_ci:24;
     130                 :            :         uint16_t rq_repl_thresh; /* Threshold for buffer replenishment. */
     131                 :            :         uint32_t byte_mask;
     132                 :            :         union {
     133                 :            :                 struct rxq_zip zip; /* Compressed context. */
     134                 :            :                 uint16_t decompressed;
     135                 :            :                 /* Number of ready mbufs decompressed from the CQ. */
     136                 :            :         };
     137                 :            :         struct mlx5_mr_ctrl mr_ctrl; /* MR control descriptor. */
     138                 :            :         uint16_t mprq_max_memcpy_len; /* Maximum size of packet to memcpy. */
     139                 :            :         volatile void *wqes;
     140                 :            :         volatile struct mlx5_cqe(*cqes)[];
     141                 :            :         struct mlx5_cqe title_cqe; /* Title CQE for CQE compression. */
     142                 :            :         struct rte_mbuf *(*elts)[];
     143                 :            :         struct rte_mbuf title_pkt; /* Title packet for CQE compression. */
     144                 :            :         struct mlx5_mprq_buf *(*mprq_bufs)[];
     145                 :            :         struct rte_mempool *mp;
     146                 :            :         struct rte_mempool *mprq_mp; /* Mempool for Multi-Packet RQ. */
     147                 :            :         struct mlx5_mprq_buf *mprq_repl; /* Stashed mbuf for replenish. */
     148                 :            :         struct mlx5_dev_ctx_shared *sh; /* Shared context. */
     149                 :            :         uint16_t idx; /* Queue index. */
     150                 :            :         struct mlx5_rxq_stats stats;
     151                 :            :         struct mlx5_rxq_stats stats_reset; /* stats on last reset. */
     152                 :            :         rte_xmm_t mbuf_initializer; /* Default rearm/flags for vectorized Rx. */
     153                 :            :         struct rte_mbuf fake_mbuf; /* elts padding for vectorized Rx. */
     154                 :            :         struct mlx5_uar_data uar_data; /* CQ doorbell. */
     155                 :            :         uint32_t cqn; /* CQ number. */
     156                 :            :         uint8_t cq_arm_sn; /* CQ arm seq number. */
     157                 :            :         uint64_t mark_flag; /* ol_flags to set with marks. */
     158                 :            :         uint32_t tunnel; /* Tunnel information. */
     159                 :            :         int timestamp_offset; /* Dynamic mbuf field for timestamp. */
     160                 :            :         uint64_t timestamp_rx_flag; /* Dynamic mbuf flag for timestamp. */
     161                 :            :         uint64_t flow_meta_mask;
     162                 :            :         int32_t flow_meta_offset;
     163                 :            :         uint32_t flow_meta_port_mask;
     164                 :            :         uint32_t rxseg_n; /* Number of split segment descriptions. */
     165                 :            :         struct mlx5_eth_rxseg rxseg[MLX5_MAX_RXQ_NSEG];
     166                 :            :         /* Buffer split segment descriptions - sizes, offsets, pools. */
     167                 :            : };
     168                 :            : 
     169                 :            : /* RX queue control descriptor. */
     170                 :            : struct mlx5_rxq_ctrl {
     171                 :            :         struct mlx5_rxq_data rxq; /* Data path structure. */
     172                 :            :         LIST_ENTRY(mlx5_rxq_ctrl) next; /* Pointer to the next element. */
     173                 :            :         LIST_HEAD(priv, mlx5_rxq_priv) owners; /* Owner rxq list. */
     174                 :            :         struct mlx5_rxq_obj *obj; /* Verbs/DevX elements. */
     175                 :            :         struct mlx5_dev_ctx_shared *sh; /* Shared context. */
     176                 :            :         bool is_hairpin; /* Whether RxQ type is Hairpin. */
     177                 :            :         unsigned int socket; /* CPU socket ID for allocations. */
     178                 :            :         LIST_ENTRY(mlx5_rxq_ctrl) share_entry; /* Entry in shared RXQ list. */
     179                 :            :         RTE_ATOMIC(int32_t) ctrl_ref; /* Reference counter. */
     180                 :            :         uint32_t share_group; /* Group ID of shared RXQ. */
     181                 :            :         uint16_t share_qid; /* Shared RxQ ID in group. */
     182                 :            :         unsigned int started:1; /* Whether (shared) RXQ has been started. */
     183                 :            :         unsigned int irq:1; /* Whether IRQ is enabled. */
     184                 :            :         uint32_t flow_tunnels_n[MLX5_FLOW_TUNNEL]; /* Tunnels counters. */
     185                 :            :         uint32_t wqn; /* WQ number. */
     186                 :            :         uint32_t rxseg_n; /* Number of split segment descriptions. */
     187                 :            :         struct rte_eth_rxseg_split rxseg[MLX5_MAX_RXQ_NSEG];
     188                 :            :         /* Saved original buffer split segment configuration. */
     189                 :            :         uint16_t dump_file_n; /* Number of dump files. */
     190                 :            : };
     191                 :            : 
     192                 :            : /* RX queue private data. */
     193                 :            : struct mlx5_rxq_priv {
     194                 :            :         uint16_t idx; /* Queue index. */
     195                 :            :         RTE_ATOMIC(uint32_t) refcnt; /* Reference counter. */
     196                 :            :         struct mlx5_rxq_ctrl *ctrl; /* Shared Rx Queue. */
     197                 :            :         LIST_ENTRY(mlx5_rxq_priv) owner_entry; /* Entry in shared rxq_ctrl. */
     198                 :            :         struct mlx5_priv *priv; /* Back pointer to private data. */
     199                 :            :         struct mlx5_devx_rq devx_rq;
     200                 :            :         struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
     201                 :            :         uint32_t hairpin_status; /* Hairpin binding status. */
     202                 :            :         uint32_t lwm:16;
     203                 :            :         uint32_t lwm_event_pending:1;
     204                 :            :         uint32_t lwm_devx_subscribed:1;
     205                 :            :         struct mlx5_devx_obj *q_counter; /* DevX hairpin queue counter object. */
     206                 :            : };
     207                 :            : 
     208                 :            : /* mlx5_rxq.c */
     209                 :            : 
     210                 :            : extern uint8_t rss_hash_default_key[];
     211                 :            : 
     212                 :            : unsigned int mlx5_rxq_cqe_num(struct mlx5_rxq_data *rxq_data);
     213                 :            : int mlx5_mprq_free_mp(struct rte_eth_dev *dev);
     214                 :            : int mlx5_mprq_alloc_mp(struct rte_eth_dev *dev);
     215                 :            : int mlx5_rx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id);
     216                 :            : int mlx5_rx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id);
     217                 :            : int mlx5_rx_queue_start_primary(struct rte_eth_dev *dev, uint16_t queue_id);
     218                 :            : int mlx5_rx_queue_stop_primary(struct rte_eth_dev *dev, uint16_t queue_id);
     219                 :            : int mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
     220                 :            :                         unsigned int socket, const struct rte_eth_rxconf *conf,
     221                 :            :                         struct rte_mempool *mp);
     222                 :            : int mlx5_rx_hairpin_queue_setup
     223                 :            :         (struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
     224                 :            :          const struct rte_eth_hairpin_conf *hairpin_conf);
     225                 :            : void mlx5_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
     226                 :            : int mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev);
     227                 :            : void mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev);
     228                 :            : int mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
     229                 :            : int mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
     230                 :            : int mlx5_rxq_obj_verify(struct rte_eth_dev *dev);
     231                 :            : void mlx5_q_counters_destroy(struct rte_eth_dev *dev);
     232                 :            : struct mlx5_rxq_ctrl *mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx,
     233                 :            :                                    uint16_t desc, unsigned int socket,
     234                 :            :                                    const struct rte_eth_rxconf *conf,
     235                 :            :                                    const struct rte_eth_rxseg_split *rx_seg,
     236                 :            :                                    uint16_t n_seg, bool is_extmem);
     237                 :            : struct mlx5_rxq_ctrl *mlx5_rxq_hairpin_new
     238                 :            :         (struct rte_eth_dev *dev, struct mlx5_rxq_priv *rxq, uint16_t desc,
     239                 :            :          const struct rte_eth_hairpin_conf *hairpin_conf);
     240                 :            : struct mlx5_rxq_priv *mlx5_rxq_ref(struct rte_eth_dev *dev, uint16_t idx);
     241                 :            : uint32_t mlx5_rxq_deref(struct rte_eth_dev *dev, uint16_t idx);
     242                 :            : struct mlx5_rxq_priv *mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx);
     243                 :            : struct mlx5_rxq_ctrl *mlx5_rxq_ctrl_get(struct rte_eth_dev *dev, uint16_t idx);
     244                 :            : struct mlx5_rxq_data *mlx5_rxq_data_get(struct rte_eth_dev *dev, uint16_t idx);
     245                 :            : struct mlx5_external_q *mlx5_ext_rxq_ref(struct rte_eth_dev *dev,
     246                 :            :                                            uint16_t idx);
     247                 :            : uint32_t mlx5_ext_rxq_deref(struct rte_eth_dev *dev, uint16_t idx);
     248                 :            : struct mlx5_external_q *mlx5_ext_rxq_get(struct rte_eth_dev *dev,
     249                 :            :                                            uint16_t idx);
     250                 :            : int mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx);
     251                 :            : int mlx5_rxq_verify(struct rte_eth_dev *dev);
     252                 :            : int mlx5_ext_rxq_verify(struct rte_eth_dev *dev);
     253                 :            : int rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl);
     254                 :            : int mlx5_ind_table_obj_verify(struct rte_eth_dev *dev);
     255                 :            : struct mlx5_ind_table_obj *mlx5_ind_table_obj_get(struct rte_eth_dev *dev,
     256                 :            :                                                   const uint16_t *queues,
     257                 :            :                                                   uint32_t queues_n);
     258                 :            : struct mlx5_ind_table_obj *mlx5_ind_table_obj_new(struct rte_eth_dev *dev,
     259                 :            :                                                   const uint16_t *queues,
     260                 :            :                                                   uint32_t queues_n,
     261                 :            :                                                   bool standalone,
     262                 :            :                                                   bool ref_qs);
     263                 :            : int mlx5_ind_table_obj_release(struct rte_eth_dev *dev,
     264                 :            :                                struct mlx5_ind_table_obj *ind_tbl,
     265                 :            :                                bool deref_rxqs);
     266                 :            : int mlx5_ind_table_obj_setup(struct rte_eth_dev *dev,
     267                 :            :                              struct mlx5_ind_table_obj *ind_tbl,
     268                 :            :                              bool ref_qs);
     269                 :            : int mlx5_ind_table_obj_modify(struct rte_eth_dev *dev,
     270                 :            :                               struct mlx5_ind_table_obj *ind_tbl,
     271                 :            :                               uint16_t *queues, const uint32_t queues_n,
     272                 :            :                               bool standalone,
     273                 :            :                               bool ref_new_qs, bool deref_old_qs);
     274                 :            : int mlx5_ind_table_obj_attach(struct rte_eth_dev *dev,
     275                 :            :                               struct mlx5_ind_table_obj *ind_tbl);
     276                 :            : int mlx5_ind_table_obj_detach(struct rte_eth_dev *dev,
     277                 :            :                               struct mlx5_ind_table_obj *ind_tbl);
     278                 :            : struct mlx5_list_entry *mlx5_hrxq_create_cb(void *tool_ctx, void *cb_ctx);
     279                 :            : int mlx5_hrxq_match_cb(void *tool_ctx, struct mlx5_list_entry *entry,
     280                 :            :                        void *cb_ctx);
     281                 :            : void mlx5_hrxq_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry);
     282                 :            : struct mlx5_list_entry *mlx5_hrxq_clone_cb(void *tool_ctx,
     283                 :            :                                            struct mlx5_list_entry *entry,
     284                 :            :                                            void *cb_ctx __rte_unused);
     285                 :            : void mlx5_hrxq_clone_free_cb(void *tool_ctx __rte_unused,
     286                 :            :                              struct mlx5_list_entry *entry);
     287                 :            : struct mlx5_hrxq *mlx5_hrxq_get(struct rte_eth_dev *dev,
     288                 :            :                        struct mlx5_flow_rss_desc *rss_desc);
     289                 :            : int mlx5_hrxq_obj_release(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq);
     290                 :            : int mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hxrq_idx);
     291                 :            : uint32_t mlx5_hrxq_verify(struct rte_eth_dev *dev);
     292                 :            : bool mlx5_rxq_is_hairpin(struct rte_eth_dev *dev, uint16_t idx);
     293                 :            : const struct rte_eth_hairpin_conf *mlx5_rxq_get_hairpin_conf
     294                 :            :         (struct rte_eth_dev *dev, uint16_t idx);
     295                 :            : struct mlx5_hrxq *mlx5_drop_action_create(struct rte_eth_dev *dev);
     296                 :            : void mlx5_drop_action_destroy(struct rte_eth_dev *dev);
     297                 :            : uint64_t mlx5_get_rx_port_offloads(void);
     298                 :            : uint64_t mlx5_get_rx_queue_offloads(struct rte_eth_dev *dev);
     299                 :            : void mlx5_rxq_timestamp_set(struct rte_eth_dev *dev);
     300                 :            : int mlx5_hrxq_modify(struct rte_eth_dev *dev, uint32_t hxrq_idx,
     301                 :            :                      const uint8_t *rss_key, uint32_t rss_key_len,
     302                 :            :                      uint64_t hash_fields, bool symmetric_hash_function,
     303                 :            :                      const uint16_t *queues, uint32_t queues_n);
     304                 :            : 
     305                 :            : /* mlx5_rx.c */
     306                 :            : 
     307                 :            : uint16_t mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n);
     308                 :            : void mlx5_rxq_initialize(struct mlx5_rxq_data *rxq);
     309                 :            : __rte_noinline int mlx5_rx_err_handle(struct mlx5_rxq_data *rxq, uint8_t vec,
     310                 :            :                                       uint16_t err_n, uint16_t *skip_cnt);
     311                 :            : void mlx5_mprq_buf_free(struct mlx5_mprq_buf *buf);
     312                 :            : uint16_t mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts,
     313                 :            :                             uint16_t pkts_n);
     314                 :            : int mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset);
     315                 :            : uint32_t mlx5_rx_queue_count(void *rx_queue);
     316                 :            : void mlx5_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
     317                 :            :                        struct rte_eth_rxq_info *qinfo);
     318                 :            : int mlx5_rx_burst_mode_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
     319                 :            :                            struct rte_eth_burst_mode *mode);
     320                 :            : int mlx5_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc);
     321                 :            : void mlx5_dev_interrupt_handler_lwm(void *args);
     322                 :            : int mlx5_rx_queue_lwm_set(struct rte_eth_dev *dev, uint16_t rx_queue_id,
     323                 :            :                           uint8_t lwm);
     324                 :            : int mlx5_rx_queue_lwm_query(struct rte_eth_dev *dev, uint16_t *rx_queue_id,
     325                 :            :                             uint8_t *lwm);
     326                 :            : 
     327                 :            : /* Vectorized version of mlx5_rx.c */
     328                 :            : int mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq_data);
     329                 :            : int mlx5_check_vec_rx_support(struct rte_eth_dev *dev);
     330                 :            : uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,
     331                 :            :                            uint16_t pkts_n);
     332                 :            : uint16_t mlx5_rx_burst_mprq_vec(void *dpdk_rxq, struct rte_mbuf **pkts,
     333                 :            :                                 uint16_t pkts_n);
     334                 :            : 
     335                 :            : static int mlx5_rxq_mprq_enabled(struct mlx5_rxq_data *rxq);
     336                 :            : 
     337                 :            : /**
     338                 :            :  * Query LKey for an address on Rx. No need to flush local caches
     339                 :            :  * as the Rx mempool database entries are valid for the lifetime of the queue.
     340                 :            :  *
     341                 :            :  * @param rxq
     342                 :            :  *   Pointer to Rx queue structure.
     343                 :            :  * @param addr
     344                 :            :  *   Address to search.
     345                 :            :  *
     346                 :            :  * @return
     347                 :            :  *   Searched LKey on success, UINT32_MAX on no match.
     348                 :            :  *   This function always succeeds on valid input.
     349                 :            :  */
     350                 :            : static __rte_always_inline uint32_t
     351                 :            : mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr)
     352                 :            : {
     353                 :          0 :         struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl;
     354                 :            :         struct rte_mempool *mp;
     355                 :            :         uint32_t lkey;
     356                 :            : 
     357                 :            :         /* Linear search on MR cache array. */
     358   [ #  #  #  #  :          0 :         lkey = mlx5_mr_lookup_lkey(mr_ctrl->cache, &mr_ctrl->mru,
                   #  # ]
     359                 :            :                                    MLX5_MR_CACHE_N, addr);
     360   [ #  #  #  #  :          0 :         if (likely(lkey != UINT32_MAX))
                   #  # ]
     361                 :            :                 return lkey;
     362                 :          0 :         mp = mlx5_rxq_mprq_enabled(rxq) ? rxq->mprq_mp : rxq->mp;
     363                 :          0 :         return mlx5_mr_mempool2mr_bh(mr_ctrl, mp, addr);
     364                 :            : }
     365                 :            : 
     366                 :            : /**
     367                 :            :  * Query LKey from a packet buffer for Rx. No need to flush local caches
     368                 :            :  * as the Rx mempool database entries are valid for the lifetime of the queue.
     369                 :            :  *
     370                 :            :  * @param rxq
     371                 :            :  *   Pointer to Rx queue structure.
     372                 :            :  * @param mb
     373                 :            :  *   Buffer to search the address of.
     374                 :            :  *
     375                 :            :  * @return
     376                 :            :  *   Searched LKey on success, UINT32_MAX on no match.
     377                 :            :  *   This function always succeeds on valid input.
     378                 :            :  */
     379                 :            : static __rte_always_inline uint32_t
     380                 :            : mlx5_rx_mb2mr(struct mlx5_rxq_data *rxq, struct rte_mbuf *mb)
     381                 :            : {
     382                 :          0 :         struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl;
     383                 :          0 :         uintptr_t addr = (uintptr_t)mb->buf_addr;
     384                 :            :         uint32_t lkey;
     385                 :            : 
     386                 :            :         /* Linear search on MR cache array. */
     387   [ #  #  #  # ]:          0 :         lkey = mlx5_mr_lookup_lkey(mr_ctrl->cache, &mr_ctrl->mru,
     388                 :            :                                    MLX5_MR_CACHE_N, addr);
     389   [ #  #  #  # ]:          0 :         if (likely(lkey != UINT32_MAX))
     390                 :            :                 return lkey;
     391                 :            :         /* Slower search in the mempool database on miss. */
     392                 :          0 :         return mlx5_mr_mempool2mr_bh(mr_ctrl, mb->pool, addr);
     393                 :            : }
     394                 :            : 
     395                 :            : /**
     396                 :            :  * Set timestamp in mbuf dynamic field.
     397                 :            :  *
     398                 :            :  * @param mbuf
     399                 :            :  *   Structure to write into.
     400                 :            :  * @param offset
     401                 :            :  *   Dynamic field offset in mbuf structure.
     402                 :            :  * @param timestamp
     403                 :            :  *   Value to write.
     404                 :            :  */
     405                 :            : static __rte_always_inline void
     406                 :            : mlx5_timestamp_set(struct rte_mbuf *mbuf, int offset,
     407                 :            :                 rte_mbuf_timestamp_t timestamp)
     408                 :            : {
     409                 :          0 :         *RTE_MBUF_DYNFIELD(mbuf, offset, rte_mbuf_timestamp_t *) = timestamp;
     410                 :          0 : }
     411                 :            : 
     412                 :            : /**
     413                 :            :  * Replace MPRQ buffer.
     414                 :            :  *
     415                 :            :  * @param rxq
     416                 :            :  *   Pointer to Rx queue structure.
     417                 :            :  * @param rq_idx
     418                 :            :  *   RQ index to replace.
     419                 :            :  */
     420                 :            : static __rte_always_inline void
     421                 :            : mprq_buf_replace(struct mlx5_rxq_data *rxq, uint16_t rq_idx)
     422                 :            : {
     423                 :          0 :         const uint32_t strd_n = RTE_BIT32(rxq->log_strd_num);
     424                 :          0 :         struct mlx5_mprq_buf *rep = rxq->mprq_repl;
     425                 :            :         volatile struct mlx5_wqe_data_seg *wqe =
     426                 :          0 :                 &((volatile struct mlx5_wqe_mprq *)rxq->wqes)[rq_idx].dseg;
     427                 :          0 :         struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[rq_idx];
     428                 :            :         void *addr;
     429                 :            : 
     430   [ #  #  #  # ]:          0 :         if (rte_atomic_load_explicit(&buf->refcnt, rte_memory_order_relaxed) > 1) {
     431                 :            :                 MLX5_ASSERT(rep != NULL);
     432                 :            :                 /* Replace MPRQ buf. */
     433                 :          0 :                 (*rxq->mprq_bufs)[rq_idx] = rep;
     434                 :            :                 /* Replace WQE. */
     435                 :          0 :                 addr = mlx5_mprq_buf_addr(rep, strd_n);
     436                 :          0 :                 wqe->addr = rte_cpu_to_be_64((uintptr_t)addr);
     437                 :            :                 /* If there's only one MR, no need to replace LKey in WQE. */
     438   [ #  #  #  # ]:          0 :                 if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
     439                 :          0 :                         wqe->lkey = mlx5_rx_addr2mr(rxq, (uintptr_t)addr);
     440                 :            :                 /* Stash a mbuf for next replacement. */
     441   [ #  #  #  #  :          0 :                 if (likely(!rte_mempool_get(rxq->mprq_mp, (void **)&rep)))
             #  #  #  # ]
     442                 :          0 :                         rxq->mprq_repl = rep;
     443                 :            :                 else
     444                 :          0 :                         rxq->mprq_repl = NULL;
     445                 :            :                 /* Release the old buffer. */
     446                 :          0 :                 mlx5_mprq_buf_free(buf);
     447   [ #  #  #  # ]:          0 :         } else if (unlikely(rxq->mprq_repl == NULL)) {
     448                 :            :                 struct mlx5_mprq_buf *rep;
     449                 :            : 
     450                 :            :                 /*
     451                 :            :                  * Currently, the MPRQ mempool is out of buffer
     452                 :            :                  * and doing memcpy regardless of the size of Rx
     453                 :            :                  * packet. Retry allocation to get back to
     454                 :            :                  * normal.
     455                 :            :                  */
     456   [ #  #  #  #  :          0 :                 if (!rte_mempool_get(rxq->mprq_mp, (void **)&rep))
             #  #  #  # ]
     457                 :          0 :                         rxq->mprq_repl = rep;
     458                 :            :         }
     459                 :            : }
     460                 :            : 
     461                 :            : /**
     462                 :            :  * Attach or copy MPRQ buffer content to a packet.
     463                 :            :  *
     464                 :            :  * @param rxq
     465                 :            :  *   Pointer to Rx queue structure.
     466                 :            :  * @param pkt
     467                 :            :  *   Pointer to a packet to fill.
     468                 :            :  * @param len
     469                 :            :  *   Packet length.
     470                 :            :  * @param buf
     471                 :            :  *   Pointer to a MPRQ buffer to take the data from.
     472                 :            :  * @param strd_idx
     473                 :            :  *   Stride index to start from.
     474                 :            :  * @param strd_cnt
     475                 :            :  *   Number of strides to consume.
     476                 :            :  */
     477                 :            : static __rte_always_inline enum mlx5_rqx_code
     478                 :            : mprq_buf_to_pkt(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt, uint32_t len,
     479                 :            :                 struct mlx5_mprq_buf *buf, uint16_t strd_idx, uint16_t strd_cnt)
     480                 :            : {
     481                 :          0 :         const uint32_t strd_n = RTE_BIT32(rxq->log_strd_num);
     482                 :          0 :         const uint16_t strd_sz = RTE_BIT32(rxq->log_strd_sz);
     483                 :          0 :         const uint16_t strd_shift =
     484                 :          0 :                 MLX5_MPRQ_STRIDE_SHIFT_BYTE * rxq->strd_shift_en;
     485                 :          0 :         const int32_t hdrm_overlap =
     486                 :          0 :                 len + RTE_PKTMBUF_HEADROOM - strd_cnt * strd_sz;
     487                 :          0 :         const uint32_t offset = strd_idx * strd_sz + strd_shift;
     488                 :          0 :         void *addr = RTE_PTR_ADD(mlx5_mprq_buf_addr(buf, strd_n), offset);
     489                 :            : 
     490                 :            :         /*
     491                 :            :          * Memcpy packets to the target mbuf if:
     492                 :            :          * - The size of packet is smaller than mprq_max_memcpy_len.
     493                 :            :          * - Out of buffer in the Mempool for Multi-Packet RQ.
     494                 :            :          * - The packet's stride overlaps a headroom and scatter is off.
     495                 :            :          */
     496         [ #  # ]:          0 :         if (len <= rxq->mprq_max_memcpy_len ||
     497   [ #  #  #  # ]:          0 :             rxq->mprq_repl == NULL ||
     498         [ #  # ]:          0 :             (hdrm_overlap > 0 && !rxq->strd_scatter_en)) {
     499         [ #  # ]:          0 :                 if (likely(len <=
     500                 :            :                            (uint32_t)(pkt->buf_len - RTE_PKTMBUF_HEADROOM))) {
     501         [ #  # ]:          0 :                         rte_memcpy(rte_pktmbuf_mtod(pkt, void *),
     502                 :            :                                    addr, len);
     503                 :          0 :                         DATA_LEN(pkt) = len;
     504         [ #  # ]:          0 :                 } else if (rxq->strd_scatter_en) {
     505                 :            :                         struct rte_mbuf *prev = pkt;
     506                 :          0 :                         uint32_t seg_len = RTE_MIN(len, (uint32_t)
     507                 :            :                                 (pkt->buf_len - RTE_PKTMBUF_HEADROOM));
     508                 :          0 :                         uint32_t rem_len = len - seg_len;
     509                 :            : 
     510         [ #  # ]:          0 :                         rte_memcpy(rte_pktmbuf_mtod(pkt, void *),
     511                 :            :                                    addr, seg_len);
     512                 :          0 :                         DATA_LEN(pkt) = seg_len;
     513         [ #  # ]:          0 :                         while (rem_len) {
     514                 :            :                                 struct rte_mbuf *next =
     515                 :          0 :                                         rte_pktmbuf_alloc(rxq->mp);
     516                 :            : 
     517         [ #  # ]:          0 :                                 if (unlikely(next == NULL))
     518                 :            :                                         return MLX5_RXQ_CODE_NOMBUF;
     519                 :          0 :                                 NEXT(prev) = next;
     520                 :          0 :                                 SET_DATA_OFF(next, 0);
     521                 :          0 :                                 addr = RTE_PTR_ADD(addr, seg_len);
     522                 :          0 :                                 seg_len = RTE_MIN(rem_len, (uint32_t)
     523                 :            :                                         (next->buf_len - RTE_PKTMBUF_HEADROOM));
     524                 :          0 :                                 rte_memcpy
     525         [ #  # ]:          0 :                                         (rte_pktmbuf_mtod(next, void *),
     526                 :            :                                          addr, seg_len);
     527                 :          0 :                                 DATA_LEN(next) = seg_len;
     528                 :          0 :                                 rem_len -= seg_len;
     529                 :            :                                 prev = next;
     530                 :          0 :                                 ++NB_SEGS(pkt);
     531                 :            :                         }
     532                 :            :                 } else {
     533                 :            :                         return MLX5_RXQ_CODE_DROPPED;
     534                 :            :                 }
     535                 :            :         } else {
     536                 :            :                 rte_iova_t buf_iova;
     537                 :            :                 struct rte_mbuf_ext_shared_info *shinfo;
     538                 :          0 :                 uint16_t buf_len = strd_cnt * strd_sz;
     539                 :            :                 void *buf_addr;
     540                 :            : 
     541                 :            :                 /* Increment the refcnt of the whole chunk. */
     542                 :          0 :                 rte_atomic_fetch_add_explicit(&buf->refcnt, 1, rte_memory_order_relaxed);
     543                 :            :                 MLX5_ASSERT(rte_atomic_load_explicit(&buf->refcnt,
     544                 :            :                             rte_memory_order_relaxed) <= strd_n + 1);
     545                 :          0 :                 buf_addr = RTE_PTR_SUB(addr, RTE_PKTMBUF_HEADROOM);
     546                 :            :                 /*
     547                 :            :                  * MLX5 device doesn't use iova but it is necessary in a
     548                 :            :                  * case where the Rx packet is transmitted via a
     549                 :            :                  * different PMD.
     550                 :            :                  */
     551                 :          0 :                 buf_iova = rte_mempool_virt2iova(buf) +
     552                 :          0 :                            RTE_PTR_DIFF(buf_addr, buf);
     553                 :          0 :                 shinfo = &buf->shinfos[strd_idx];
     554                 :          0 :                 rte_mbuf_ext_refcnt_set(shinfo, 1);
     555                 :            :                 /*
     556                 :            :                  * RTE_MBUF_F_EXTERNAL will be set to pkt->ol_flags when
     557                 :            :                  * attaching the stride to mbuf and more offload flags
     558                 :            :                  * will be added below by calling rxq_cq_to_mbuf().
     559                 :            :                  * Other fields will be overwritten.
     560                 :            :                  */
     561                 :            :                 rte_pktmbuf_attach_extbuf(pkt, buf_addr, buf_iova,
     562                 :            :                                           buf_len, shinfo);
     563                 :            :                 /* Set mbuf head-room. */
     564                 :          0 :                 SET_DATA_OFF(pkt, RTE_PKTMBUF_HEADROOM);
     565                 :            :                 MLX5_ASSERT(pkt->ol_flags & RTE_MBUF_F_EXTERNAL);
     566                 :            :                 MLX5_ASSERT(rte_pktmbuf_tailroom(pkt) >=
     567                 :            :                         len - (hdrm_overlap > 0 ? hdrm_overlap : 0));
     568                 :          0 :                 DATA_LEN(pkt) = len;
     569                 :            :                 /*
     570                 :            :                  * Copy the last fragment of a packet (up to headroom
     571                 :            :                  * size bytes) in case there is a stride overlap with
     572                 :            :                  * a next packet's headroom. Allocate a separate mbuf
     573                 :            :                  * to store this fragment and link it. Scatter is on.
     574                 :            :                  */
     575         [ #  # ]:          0 :                 if (hdrm_overlap > 0) {
     576                 :            :                         MLX5_ASSERT(rxq->strd_scatter_en);
     577                 :            :                         struct rte_mbuf *seg =
     578                 :          0 :                                 rte_pktmbuf_alloc(rxq->mp);
     579                 :            : 
     580         [ #  # ]:          0 :                         if (unlikely(seg == NULL))
     581                 :            :                                 return MLX5_RXQ_CODE_NOMBUF;
     582                 :          0 :                         SET_DATA_OFF(seg, 0);
     583                 :          0 :                         rte_memcpy(rte_pktmbuf_mtod(seg, void *),
     584         [ #  # ]:          0 :                                 RTE_PTR_ADD(addr, len - hdrm_overlap),
     585                 :            :                                 hdrm_overlap);
     586                 :          0 :                         DATA_LEN(seg) = hdrm_overlap;
     587                 :          0 :                         DATA_LEN(pkt) = len - hdrm_overlap;
     588                 :          0 :                         NEXT(pkt) = seg;
     589                 :          0 :                         NB_SEGS(pkt) = 2;
     590                 :            :                 }
     591                 :            :         }
     592                 :            :         return MLX5_RXQ_CODE_EXIT;
     593                 :            : }
     594                 :            : 
     595                 :            : /**
     596                 :            :  * Check whether Multi-Packet RQ can be enabled for the device.
     597                 :            :  *
     598                 :            :  * @param dev
     599                 :            :  *   Pointer to Ethernet device.
     600                 :            :  *
     601                 :            :  * @return
     602                 :            :  *   1 if supported, negative errno value if not.
     603                 :            :  */
     604                 :            : static __rte_always_inline int
     605                 :            : mlx5_check_mprq_support(struct rte_eth_dev *dev)
     606                 :            : {
     607                 :            :         struct mlx5_priv *priv = dev->data->dev_private;
     608                 :            : 
     609   [ #  #  #  # ]:          0 :         if (priv->config.mprq.enabled &&
     610   [ #  #  #  # ]:          0 :             priv->rxqs_n >= priv->config.mprq.min_rxqs_num)
     611                 :            :                 return 1;
     612                 :            :         return -ENOTSUP;
     613                 :            : }
     614                 :            : 
     615                 :            : /**
     616                 :            :  * Check whether Multi-Packet RQ is enabled for the Rx queue.
     617                 :            :  *
     618                 :            :  *  @param rxq
     619                 :            :  *     Pointer to receive queue structure.
     620                 :            :  *
     621                 :            :  * @return
     622                 :            :  *   0 if disabled, otherwise enabled.
     623                 :            :  */
     624                 :            : static __rte_always_inline int
     625                 :            : mlx5_rxq_mprq_enabled(struct mlx5_rxq_data *rxq)
     626                 :            : {
     627   [ #  #  #  #  :          0 :         return rxq->log_strd_num > 0;
          #  #  #  #  #  
                #  #  # ]
     628                 :            : }
     629                 :            : 
     630                 :            : /**
     631                 :            :  * Check whether Multi-Packet RQ is enabled for the device.
     632                 :            :  *
     633                 :            :  * @param dev
     634                 :            :  *   Pointer to Ethernet device.
     635                 :            :  *
     636                 :            :  * @return
     637                 :            :  *   0 if disabled, otherwise enabled.
     638                 :            :  */
     639                 :            : static __rte_always_inline int
     640                 :            : mlx5_mprq_enabled(struct rte_eth_dev *dev)
     641                 :            : {
     642   [ #  #  #  # ]:          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     643                 :            :         uint32_t i;
     644                 :            :         uint16_t n = 0;
     645                 :            :         uint16_t n_ibv = 0;
     646                 :            : 
     647                 :            :         if (mlx5_check_mprq_support(dev) < 0)
     648                 :            :                 return 0;
     649                 :            :         /* All the configured queues should be enabled. */
     650   [ #  #  #  # ]:          0 :         for (i = 0; i < priv->rxqs_n; ++i) {
     651                 :          0 :                 struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
     652                 :            : 
     653   [ #  #  #  #  :          0 :                 if (rxq_ctrl == NULL || rxq_ctrl->is_hairpin)
             #  #  #  # ]
     654                 :          0 :                         continue;
     655                 :          0 :                 n_ibv++;
     656   [ #  #  #  # ]:          0 :                 if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
     657                 :          0 :                         ++n;
     658                 :            :         }
     659                 :            :         /* Multi-Packet RQ can't be partially configured. */
     660                 :            :         MLX5_ASSERT(n == 0 || n == n_ibv);
     661   [ #  #  #  # ]:          0 :         return n == n_ibv;
     662                 :            : }
     663                 :            : 
     664                 :            : /**
     665                 :            :  * Check whether given RxQ is external.
     666                 :            :  *
     667                 :            :  * @param dev
     668                 :            :  *   Pointer to Ethernet device.
     669                 :            :  * @param queue_idx
     670                 :            :  *   Rx queue index.
     671                 :            :  *
     672                 :            :  * @return
     673                 :            :  *   True if is external RxQ, otherwise false.
     674                 :            :  */
     675                 :            : static __rte_always_inline bool
     676                 :            : mlx5_is_external_rxq(struct rte_eth_dev *dev, uint16_t queue_idx)
     677                 :            : {
     678                 :          0 :         struct mlx5_priv *priv = dev->data->dev_private;
     679                 :            :         struct mlx5_external_q *rxq;
     680                 :            : 
     681   [ #  #  #  #  :          0 :         if (!priv->ext_rxqs || queue_idx < RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN)
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     682                 :            :                 return false;
     683                 :          0 :         rxq = &priv->ext_rxqs[queue_idx - RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN];
     684   [ #  #  #  #  :          0 :         return !!rte_atomic_load_explicit(&rxq->refcnt, rte_memory_order_relaxed);
             #  #  #  # ]
     685                 :            : }
     686                 :            : 
     687                 :            : #define LWM_COOKIE_RXQID_OFFSET 0
     688                 :            : #define LWM_COOKIE_RXQID_MASK 0xffff
     689                 :            : #define LWM_COOKIE_PORTID_OFFSET 16
     690                 :            : #define LWM_COOKIE_PORTID_MASK 0xffff
     691                 :            : 
     692                 :            : #endif /* RTE_PMD_MLX5_RX_H_ */

Generated by: LCOV version 1.14