1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2020 Xilinx, Inc.
4 * Copyright(c) 2017-2019 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;
31 /** Datapath receive queue descriptor number limitations */
32 struct sfc_dp_rx_hw_limits {
33 unsigned int rxq_max_entries;
34 unsigned int rxq_min_entries;
35 unsigned int evq_max_entries;
36 unsigned int evq_min_entries;
40 * Datapath receive queue creation information.
42 * The structure is used just to pass information from control path to
43 * datapath. It could be just function arguments, but it would be hardly
46 struct sfc_dp_rx_qcreate_info {
47 /** Memory pool to allocate Rx buffer from */
48 struct rte_mempool *refill_mb_pool;
49 /** Maximum number of pushed Rx descriptors in the queue */
50 unsigned int max_fill_level;
51 /** Minimum number of unused Rx descriptors to do refill */
52 unsigned int refill_threshold;
54 * Usable mbuf data space in accordance with alignment and
55 * padding requirements imposed by HW.
57 unsigned int buf_size;
60 * Maximum number of Rx descriptors completed in one Rx event.
61 * Just for sanity checks if datapath would like to do.
63 unsigned int batch_max;
65 /** Pseudo-header size */
66 unsigned int prefix_size;
68 /** Receive queue flags initializer */
70 #define SFC_RXQ_FLAG_RSS_HASH 0x1
73 unsigned int rxq_entries;
74 /** DMA-mapped Rx descriptors ring */
77 /** Event queue index in hardware */
78 unsigned int evq_hw_index;
79 /** Associated event queue size */
80 unsigned int evq_entries;
81 /** Hardware event ring */
84 /** The queue index in hardware (required to push right doorbell) */
85 unsigned int hw_index;
87 * Virtual address of the memory-mapped BAR to push Rx refill
90 volatile void *mem_bar;
91 /** VI window size shift */
92 unsigned int vi_window_shift;
96 * Get Rx datapath specific device info.
98 * @param dev_info Device info to be adjusted
100 typedef void (sfc_dp_rx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
103 * Test if an Rx datapath supports specific mempool ops.
105 * @param pool The name of the pool operations to test.
107 * @return Check status.
108 * @retval 0 Best mempool ops choice.
109 * @retval 1 Mempool ops are supported.
110 * @retval -ENOTSUP Mempool ops not supported.
112 typedef int (sfc_dp_rx_pool_ops_supported_t)(const char *pool);
115 * Get size of receive and event queue rings by the number of Rx
116 * descriptors and mempool configuration.
118 * @param nb_rx_desc Number of Rx descriptors
119 * @param mb_pool mbuf pool with Rx buffers
120 * @param rxq_entries Location for number of Rx ring entries
121 * @param evq_entries Location for number of event ring entries
122 * @param rxq_max_fill_level Location for maximum Rx ring fill level
124 * @return 0 or positive errno.
126 typedef int (sfc_dp_rx_qsize_up_rings_t)(uint16_t nb_rx_desc,
127 struct sfc_dp_rx_hw_limits *limits,
128 struct rte_mempool *mb_pool,
129 unsigned int *rxq_entries,
130 unsigned int *evq_entries,
131 unsigned int *rxq_max_fill_level);
134 * Allocate and initialize datapath receive queue.
136 * @param port_id The port identifier
137 * @param queue_id The queue identifier
138 * @param pci_addr PCI function address
139 * @param socket_id Socket identifier to allocate memory
140 * @param info Receive queue information
141 * @param dp_rxqp Location for generic datapath receive queue pointer
143 * @return 0 or positive errno.
145 typedef int (sfc_dp_rx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
146 const struct rte_pci_addr *pci_addr,
148 const struct sfc_dp_rx_qcreate_info *info,
149 struct sfc_dp_rxq **dp_rxqp);
152 * Free resources allocated for datapath recevie queue.
154 typedef void (sfc_dp_rx_qdestroy_t)(struct sfc_dp_rxq *dp_rxq);
157 * Receive queue start callback.
159 * It handovers EvQ to the datapath.
161 typedef int (sfc_dp_rx_qstart_t)(struct sfc_dp_rxq *dp_rxq,
162 unsigned int evq_read_ptr);
165 * Receive queue stop function called before flush.
167 typedef void (sfc_dp_rx_qstop_t)(struct sfc_dp_rxq *dp_rxq,
168 unsigned int *evq_read_ptr);
171 * Receive event handler used during queue flush only.
173 typedef bool (sfc_dp_rx_qrx_ev_t)(struct sfc_dp_rxq *dp_rxq, unsigned int id);
176 * Packed stream receive event handler used during queue flush only.
178 typedef bool (sfc_dp_rx_qrx_ps_ev_t)(struct sfc_dp_rxq *dp_rxq,
182 * Receive queue purge function called after queue flush.
184 * Should be used to free unused recevie buffers.
186 typedef void (sfc_dp_rx_qpurge_t)(struct sfc_dp_rxq *dp_rxq);
188 /** Get packet types recognized/classified */
189 typedef const uint32_t * (sfc_dp_rx_supported_ptypes_get_t)(
190 uint32_t tunnel_encaps);
192 /** Get number of pending Rx descriptors */
193 typedef unsigned int (sfc_dp_rx_qdesc_npending_t)(struct sfc_dp_rxq *dp_rxq);
195 /** Check Rx descriptor status */
196 typedef int (sfc_dp_rx_qdesc_status_t)(struct sfc_dp_rxq *dp_rxq,
198 /** Enable Rx interrupts */
199 typedef int (sfc_dp_rx_intr_enable_t)(struct sfc_dp_rxq *dp_rxq);
201 /** Disable Rx interrupts */
202 typedef int (sfc_dp_rx_intr_disable_t)(struct sfc_dp_rxq *dp_rxq);
204 /** Receive datapath definition */
208 unsigned int features;
209 #define SFC_DP_RX_FEAT_MULTI_PROCESS 0x1
210 #define SFC_DP_RX_FEAT_FLOW_FLAG 0x2
211 #define SFC_DP_RX_FEAT_FLOW_MARK 0x4
212 #define SFC_DP_RX_FEAT_INTR 0x8
214 * Rx offload capabilities supported by the datapath on device
215 * level only if HW/FW supports it.
217 uint64_t dev_offload_capa;
219 * Rx offload capabilities supported by the datapath per-queue
220 * if HW/FW supports it.
222 uint64_t queue_offload_capa;
223 sfc_dp_rx_get_dev_info_t *get_dev_info;
224 sfc_dp_rx_pool_ops_supported_t *pool_ops_supported;
225 sfc_dp_rx_qsize_up_rings_t *qsize_up_rings;
226 sfc_dp_rx_qcreate_t *qcreate;
227 sfc_dp_rx_qdestroy_t *qdestroy;
228 sfc_dp_rx_qstart_t *qstart;
229 sfc_dp_rx_qstop_t *qstop;
230 sfc_dp_rx_qrx_ev_t *qrx_ev;
231 sfc_dp_rx_qrx_ps_ev_t *qrx_ps_ev;
232 sfc_dp_rx_qpurge_t *qpurge;
233 sfc_dp_rx_supported_ptypes_get_t *supported_ptypes_get;
234 sfc_dp_rx_qdesc_npending_t *qdesc_npending;
235 sfc_dp_rx_qdesc_status_t *qdesc_status;
236 sfc_dp_rx_intr_enable_t *intr_enable;
237 sfc_dp_rx_intr_disable_t *intr_disable;
238 eth_rx_burst_t pkt_burst;
241 static inline struct sfc_dp_rx *
242 sfc_dp_find_rx_by_name(struct sfc_dp_list *head, const char *name)
244 struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_RX, name);
246 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
249 static inline struct sfc_dp_rx *
250 sfc_dp_find_rx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
252 struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_RX, avail_caps);
254 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
257 static inline uint64_t
258 sfc_dp_rx_offload_capa(const struct sfc_dp_rx *dp_rx)
260 return dp_rx->dev_offload_capa | dp_rx->queue_offload_capa;
263 /** Get Rx datapath ops by the datapath RxQ handle */
264 const struct sfc_dp_rx *sfc_dp_rx_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq);
266 extern struct sfc_dp_rx sfc_efx_rx;
267 extern struct sfc_dp_rx sfc_ef10_rx;
268 extern struct sfc_dp_rx sfc_ef10_essb_rx;
273 #endif /* _SFC_DP_RX_H */