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;
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;
38 * Datapath receive queue creation information.
40 * The structure is used just to pass information from control path to
41 * datapath. It could be just function arguments, but it would be hardly
44 struct sfc_dp_rx_qcreate_info {
45 /** Memory pool to allocate Rx buffer from */
46 struct rte_mempool *refill_mb_pool;
47 /** Maximum number of pushed Rx descriptors in the queue */
48 unsigned int max_fill_level;
49 /** Minimum number of unused Rx descriptors to do refill */
50 unsigned int refill_threshold;
52 * Usable mbuf data space in accordance with alignment and
53 * padding requirements imposed by HW.
55 unsigned int buf_size;
58 * Maximum number of Rx descriptors completed in one Rx event.
59 * Just for sanity checks if datapath would like to do.
61 unsigned int batch_max;
63 /** Pseudo-header size */
64 unsigned int prefix_size;
66 /** Receive queue flags initializer */
68 #define SFC_RXQ_FLAG_RSS_HASH 0x1
71 unsigned int rxq_entries;
72 /** DMA-mapped Rx descriptors ring */
75 /** Associated event queue size */
76 unsigned int evq_entries;
77 /** Hardware event ring */
80 /** The queue index in hardware (required to push right doorbell) */
81 unsigned int hw_index;
83 * Virtual address of the memory-mapped BAR to push Rx refill
86 volatile void *mem_bar;
87 /** VI window size shift */
88 unsigned int vi_window_shift;
92 * Get Rx datapath specific device info.
94 * @param dev_info Device info to be adjusted
96 typedef void (sfc_dp_rx_get_dev_info_t)(struct rte_eth_dev_info *dev_info);
99 * Test if an Rx datapath supports specific mempool ops.
101 * @param pool The name of the pool operations to test.
103 * @return Check status.
104 * @retval 0 Best mempool ops choice.
105 * @retval 1 Mempool ops are supported.
106 * @retval -ENOTSUP Mempool ops not supported.
108 typedef int (sfc_dp_rx_pool_ops_supported_t)(const char *pool);
111 * Get size of receive and event queue rings by the number of Rx
112 * descriptors and mempool configuration.
114 * @param nb_rx_desc Number of Rx descriptors
115 * @param mb_pool mbuf pool with Rx buffers
116 * @param rxq_entries Location for number of Rx ring entries
117 * @param evq_entries Location for number of event ring entries
118 * @param rxq_max_fill_level Location for maximum Rx ring fill level
120 * @return 0 or positive errno.
122 typedef int (sfc_dp_rx_qsize_up_rings_t)(uint16_t nb_rx_desc,
123 struct sfc_dp_rx_hw_limits *limits,
124 struct rte_mempool *mb_pool,
125 unsigned int *rxq_entries,
126 unsigned int *evq_entries,
127 unsigned int *rxq_max_fill_level);
130 * Allocate and initialize datapath receive queue.
132 * @param port_id The port identifier
133 * @param queue_id The queue identifier
134 * @param pci_addr PCI function address
135 * @param socket_id Socket identifier to allocate memory
136 * @param info Receive queue information
137 * @param dp_rxqp Location for generic datapath receive queue pointer
139 * @return 0 or positive errno.
141 typedef int (sfc_dp_rx_qcreate_t)(uint16_t port_id, uint16_t queue_id,
142 const struct rte_pci_addr *pci_addr,
144 const struct sfc_dp_rx_qcreate_info *info,
145 struct sfc_dp_rxq **dp_rxqp);
148 * Free resources allocated for datapath recevie queue.
150 typedef void (sfc_dp_rx_qdestroy_t)(struct sfc_dp_rxq *dp_rxq);
153 * Receive queue start callback.
155 * It handovers EvQ to the datapath.
157 typedef int (sfc_dp_rx_qstart_t)(struct sfc_dp_rxq *dp_rxq,
158 unsigned int evq_read_ptr);
161 * Receive queue stop function called before flush.
163 typedef void (sfc_dp_rx_qstop_t)(struct sfc_dp_rxq *dp_rxq,
164 unsigned int *evq_read_ptr);
167 * Receive event handler used during queue flush only.
169 typedef bool (sfc_dp_rx_qrx_ev_t)(struct sfc_dp_rxq *dp_rxq, unsigned int id);
172 * Packed stream receive event handler used during queue flush only.
174 typedef bool (sfc_dp_rx_qrx_ps_ev_t)(struct sfc_dp_rxq *dp_rxq,
178 * Receive queue purge function called after queue flush.
180 * Should be used to free unused recevie buffers.
182 typedef void (sfc_dp_rx_qpurge_t)(struct sfc_dp_rxq *dp_rxq);
184 /** Get packet types recognized/classified */
185 typedef const uint32_t * (sfc_dp_rx_supported_ptypes_get_t)(
186 uint32_t tunnel_encaps);
188 /** Get number of pending Rx descriptors */
189 typedef unsigned int (sfc_dp_rx_qdesc_npending_t)(struct sfc_dp_rxq *dp_rxq);
191 /** Check Rx descriptor status */
192 typedef int (sfc_dp_rx_qdesc_status_t)(struct sfc_dp_rxq *dp_rxq,
195 /** Receive datapath definition */
199 unsigned int features;
200 #define SFC_DP_RX_FEAT_SCATTER 0x1
201 #define SFC_DP_RX_FEAT_MULTI_PROCESS 0x2
202 #define SFC_DP_RX_FEAT_TUNNELS 0x4
203 #define SFC_DP_RX_FEAT_FLOW_FLAG 0x8
204 #define SFC_DP_RX_FEAT_FLOW_MARK 0x10
205 #define SFC_DP_RX_FEAT_CHECKSUM 0x20
206 sfc_dp_rx_get_dev_info_t *get_dev_info;
207 sfc_dp_rx_pool_ops_supported_t *pool_ops_supported;
208 sfc_dp_rx_qsize_up_rings_t *qsize_up_rings;
209 sfc_dp_rx_qcreate_t *qcreate;
210 sfc_dp_rx_qdestroy_t *qdestroy;
211 sfc_dp_rx_qstart_t *qstart;
212 sfc_dp_rx_qstop_t *qstop;
213 sfc_dp_rx_qrx_ev_t *qrx_ev;
214 sfc_dp_rx_qrx_ps_ev_t *qrx_ps_ev;
215 sfc_dp_rx_qpurge_t *qpurge;
216 sfc_dp_rx_supported_ptypes_get_t *supported_ptypes_get;
217 sfc_dp_rx_qdesc_npending_t *qdesc_npending;
218 sfc_dp_rx_qdesc_status_t *qdesc_status;
219 eth_rx_burst_t pkt_burst;
222 static inline struct sfc_dp_rx *
223 sfc_dp_find_rx_by_name(struct sfc_dp_list *head, const char *name)
225 struct sfc_dp *p = sfc_dp_find_by_name(head, SFC_DP_RX, name);
227 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
230 static inline struct sfc_dp_rx *
231 sfc_dp_find_rx_by_caps(struct sfc_dp_list *head, unsigned int avail_caps)
233 struct sfc_dp *p = sfc_dp_find_by_caps(head, SFC_DP_RX, avail_caps);
235 return (p == NULL) ? NULL : container_of(p, struct sfc_dp_rx, dp);
238 /** Get Rx datapath ops by the datapath RxQ handle */
239 const struct sfc_dp_rx *sfc_dp_rx_by_dp_rxq(const struct sfc_dp_rxq *dp_rxq);
241 extern struct sfc_dp_rx sfc_efx_rx;
242 extern struct sfc_dp_rx sfc_ef10_rx;
243 extern struct sfc_dp_rx sfc_ef10_essb_rx;
248 #endif /* _SFC_DP_RX_H */