1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2017-2018 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
13 #include <rte_mempool.h>
14 #include <rte_ethdev_driver.h>
23 * Generic receive queue information used on data path.
24 * It must be kept as small as it is possible since it is built into
25 * the structure used on datapath.
28 struct sfc_dp_queue dpq;
32 * Datapath receive queue creation information.
34 * The structure is used just to pass information from control path to
35 * datapath. It could be just function arguments, but it would be hardly
38 struct sfc_dp_rx_qcreate_info {
39 /** Memory pool to allocate Rx buffer from */
40 struct rte_mempool *refill_mb_pool;
41 /** Maximum number of pushed Rx descriptors in the queue */
42 unsigned int max_fill_level;
43 /** Minimum number of unused Rx descriptors to do refill */
44 unsigned int refill_threshold;
46 * Usable mbuf data space in accordance with alignment and
47 * padding requirements imposed by HW.
49 unsigned int buf_size;
52 * Maximum number of Rx descriptors completed in one Rx event.
53 * Just for sanity checks if datapath would like to do.
55 unsigned int batch_max;
57 /** Pseudo-header size */
58 unsigned int prefix_size;
60 /** Receive queue flags initializer */
62 #define SFC_RXQ_FLAG_RSS_HASH 0x1
65 unsigned int rxq_entries;
66 /** DMA-mapped Rx descriptors ring */
69 /** Associated event queue size */
70 unsigned int evq_entries;
71 /** Hardware event ring */
74 /** The queue index in hardware (required to push right doorbell) */
75 unsigned int hw_index;
77 * Virtual address of the memory-mapped BAR to push Rx refill
80 volatile void *mem_bar;
81 /** VI window size shift */
82 unsigned int vi_window_shift;
86 * Get Rx datapath specific device info.
88 * @param dev_info Device info to be adjusted
90 typedef void (sfc_dp_rx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
93 * Get size of receive and event queue rings by the number of Rx
94 * descriptors and mempool configuration.
96 * @param nb_rx_desc Number of Rx descriptors
97 * @param mb_pool mbuf pool with Rx buffers
98 * @param rxq_entries Location for number of Rx ring entries
99 * @param evq_entries Location for number of event ring entries
100 * @param rxq_max_fill_level Location for maximum Rx ring fill level
102 * @return 0 or positive errno.
104 typedef int (sfc_dp_rx_qsize_up_rings_t)(uint16_t nb_rx_desc,
105 struct rte_mempool *mb_pool,
106 unsigned int *rxq_entries,
107 unsigned int *evq_entries,
108 unsigned int *rxq_max_fill_level);
111 * Allocate and initialize datapath receive queue.
113 * @param port_id The port identifier
114 * @param queue_id The queue identifier
115 * @param pci_addr PCI function address
116 * @param socket_id Socket identifier to allocate memory
117 * @param info Receive queue information
118 * @param dp_rxqp Location for generic datapath receive queue pointer
120 * @return 0 or positive errno.
122 typedef int (sfc_dp_rx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
123 const struct rte_pci_addr *pci_addr,
125 const struct sfc_dp_rx_qcreate_info *info,
126 struct sfc_dp_rxq **dp_rxqp);
129 * Free resources allocated for datapath recevie queue.
131 typedef void (sfc_dp_rx_qdestroy_t)(struct sfc_dp_rxq *dp_rxq);
134 * Receive queue start callback.
136 * It handovers EvQ to the datapath.
138 typedef int (sfc_dp_rx_qstart_t)(struct sfc_dp_rxq *dp_rxq,
139 unsigned int evq_read_ptr);
142 * Receive queue stop function called before flush.
144 typedef void (sfc_dp_rx_qstop_t)(struct sfc_dp_rxq *dp_rxq,
145 unsigned int *evq_read_ptr);
148 * Receive event handler used during queue flush only.
150 typedef bool (sfc_dp_rx_qrx_ev_t)(struct sfc_dp_rxq *dp_rxq, unsigned int id);
153 * Packed stream receive event handler used during queue flush only.
155 typedef bool (sfc_dp_rx_qrx_ps_ev_t)(struct sfc_dp_rxq *dp_rxq,
159 * Receive queue purge function called after queue flush.
161 * Should be used to free unused recevie buffers.
163 typedef void (sfc_dp_rx_qpurge_t)(struct sfc_dp_rxq *dp_rxq);
165 /** Get packet types recognized/classified */
166 typedef const uint32_t * (sfc_dp_rx_supported_ptypes_get_t)(
167 uint32_t tunnel_encaps);
169 /** Get number of pending Rx descriptors */
170 typedef unsigned int (sfc_dp_rx_qdesc_npending_t)(struct sfc_dp_rxq *dp_rxq);
172 /** Check Rx descriptor status */
173 typedef int (sfc_dp_rx_qdesc_status_t)(struct sfc_dp_rxq *dp_rxq,
176 /** Receive datapath definition */
180 unsigned int features;
181 #define SFC_DP_RX_FEAT_SCATTER 0x1
182 #define SFC_DP_RX_FEAT_MULTI_PROCESS 0x2
183 #define SFC_DP_RX_FEAT_TUNNELS 0x4
184 sfc_dp_rx_get_dev_info_t *get_dev_info;
185 sfc_dp_rx_qsize_up_rings_t *qsize_up_rings;
186 sfc_dp_rx_qcreate_t *qcreate;
187 sfc_dp_rx_qdestroy_t *qdestroy;
188 sfc_dp_rx_qstart_t *qstart;
189 sfc_dp_rx_qstop_t *qstop;
190 sfc_dp_rx_qrx_ev_t *qrx_ev;
191 sfc_dp_rx_qrx_ps_ev_t *qrx_ps_ev;
192 sfc_dp_rx_qpurge_t *qpurge;
193 sfc_dp_rx_supported_ptypes_get_t *supported_ptypes_get;
194 sfc_dp_rx_qdesc_npending_t *qdesc_npending;
195 sfc_dp_rx_qdesc_status_t *qdesc_status;
196 eth_rx_burst_t pkt_burst;
199 static inline struct sfc_dp_rx *
200 sfc_dp_find_rx_by_name(struct sfc_dp_list *head, const char *name)
202 struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_RX, name);
204 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
207 static inline struct sfc_dp_rx *
208 sfc_dp_find_rx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
210 struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_RX, avail_caps);
212 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
215 extern struct sfc_dp_rx sfc_efx_rx;
216 extern struct sfc_dp_rx sfc_ef10_rx;
217 extern struct sfc_dp_rx sfc_ef10_essb_rx;
222 #endif /* _SFC_DP_RX_H */