xref: /dpdk/drivers/net/mlx5/rte_pmd_mlx5.h (revision 3dfa78770ed53c376df2da7c2bd997e0b2d33cd1)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4 
5 #ifndef RTE_PMD_PRIVATE_MLX5_H_
6 #define RTE_PMD_PRIVATE_MLX5_H_
7 
8 #include <rte_compat.h>
9 
10 /**
11  * @file
12  * MLX5 public header.
13  *
14  * This interface provides the ability to support private PMD
15  * dynamic flags.
16  */
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #define RTE_PMD_MLX5_FINE_GRANULARITY_INLINE "mlx5_fine_granularity_inline"
23 
24 /**
25  * Returns the dynamic flags name, that are supported.
26  *
27  * @param[out] names
28  *   Array that is used to return the supported dynamic flags names.
29  * @param[in] n
30  *   The number of elements in the names array.
31  *
32  * @return
33  *   The number of dynamic flags that were copied if not negative.
34  *   Otherwise:
35  *   - ENOMEM - not enough entries in the array
36  *   - EINVAL - invalid array entry
37  */
38 __rte_experimental
39 int rte_pmd_mlx5_get_dyn_flag_names(char *names[], unsigned int n);
40 
41 #define RTE_PMD_MLX5_DOMAIN_BIT_NIC_RX	(1 << 0) /**< NIC RX domain bit mask. */
42 #define RTE_PMD_MLX5_DOMAIN_BIT_NIC_TX	(1 << 1) /**< NIC TX domain bit mask. */
43 #define RTE_PMD_MLX5_DOMAIN_BIT_FDB	(1 << 2) /**< FDB (TX + RX) domain bit mask. */
44 
45 /**
46  * Synchronize the flows to make them take effort on hardware.
47  * It only supports DR flows now. For DV and Verbs flows, there is no need to
48  * call this function, and a success will return directly in case of Verbs.
49  *
50  * @param[in] port_id
51  *   The port identifier of the Ethernet device.
52  * @param[in] domains
53  *   Refer to "/usr/include/infiniband/mlx5dv.h".
54  *   Bitmask of domains in which the synchronization will be done.
55  *   RTE_PMD_MLX5_DOMAIN_BIT_* macros are used to specify the domains.
56  *   An ADD or OR operation could be used to synchronize flows in more than
57  *   one domain per call.
58  *
59  * @return
60  *   - (0) if successful.
61  *   - Negative value if an error.
62  */
63 __rte_experimental
64 int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains);
65 
66 /**
67  * External Rx queue rte_flow index minimal value.
68  */
69 #define RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN (UINT16_MAX - 1000 + 1)
70 
71 /**
72  * External Tx queue rte_flow index minimal value.
73  */
74 #define MLX5_EXTERNAL_TX_QUEUE_ID_MIN (UINT16_MAX - 1000 + 1)
75 
76 /**
77  * Tag level to set the linear hash index.
78  */
79 #define RTE_PMD_MLX5_LINEAR_HASH_TAG_INDEX 255
80 
81 /**
82  * Update mapping between rte_flow queue index (16 bits) and HW queue index (32
83  * bits) for RxQs which is created outside the PMD.
84  *
85  * @param[in] port_id
86  *   The port identifier of the Ethernet device.
87  * @param[in] dpdk_idx
88  *   Queue index in rte_flow.
89  * @param[in] hw_idx
90  *   Queue index in hardware.
91  *
92  * @return
93  *   0 on success, a negative errno value otherwise and rte_errno is set.
94  *   Possible values for rte_errno:
95  *   - EEXIST - a mapping with the same rte_flow index already exists.
96  *   - EINVAL - invalid rte_flow index, out of range.
97  *   - ENODEV - there is no Ethernet device for this port id.
98  *   - ENOTSUP - the port doesn't support external RxQ.
99  */
100 __rte_experimental
101 int rte_pmd_mlx5_external_rx_queue_id_map(uint16_t port_id, uint16_t dpdk_idx,
102 					  uint32_t hw_idx);
103 
104 /**
105  * Remove mapping between rte_flow queue index (16 bits) and HW queue index (32
106  * bits) for RxQs which is created outside the PMD.
107  *
108  * @param[in] port_id
109  *   The port identifier of the Ethernet device.
110  * @param[in] dpdk_idx
111  *   Queue index in rte_flow.
112  *
113  * @return
114  *   0 on success, a negative errno value otherwise and rte_errno is set.
115  *   Possible values for rte_errno:
116  *   - EINVAL - invalid index, out of range, still referenced or doesn't exist.
117  *   - ENODEV - there is no Ethernet device for this port id.
118  *   - ENOTSUP - the port doesn't support external RxQ.
119  */
120 __rte_experimental
121 int rte_pmd_mlx5_external_rx_queue_id_unmap(uint16_t port_id,
122 					    uint16_t dpdk_idx);
123 
124 /**
125  * Update mapping between rte_flow Tx queue index (16 bits) and HW queue index (32
126  * bits) for TxQs which is created outside the PMD.
127  *
128  * @param[in] port_id
129  *   The port identifier of the Ethernet device.
130  * @param[in] dpdk_idx
131  *   Queue index in rte_flow.
132  * @param[in] hw_idx
133  *   Queue index in hardware.
134  *
135  * @return
136  *   0 on success, a negative errno value otherwise and rte_errno is set.
137  *   Possible values for rte_errno:
138  *   - EEXIST - a mapping with the same rte_flow index already exists.
139  *   - EINVAL - invalid rte_flow index, out of range.
140  *   - ENODEV - there is no Ethernet device for this port id.
141  *   - ENOTSUP - the port doesn't support external TxQ.
142  */
143 __rte_experimental
144 int rte_pmd_mlx5_external_tx_queue_id_map(uint16_t port_id, uint16_t dpdk_idx,
145 					  uint32_t hw_idx);
146 
147 /**
148  * Remove mapping between rte_flow Tx queue index (16 bits) and HW queue index (32
149  * bits) for TxQs which is created outside the PMD.
150  *
151  * @param[in] port_id
152  *   The port identifier of the Ethernet device.
153  * @param[in] dpdk_idx
154  *   Queue index in rte_flow.
155  *
156  * @return
157  *   0 on success, a negative errno value otherwise and rte_errno is set.
158  *   Possible values for rte_errno:
159  *   - EINVAL - invalid index, out of range, still referenced or doesn't exist.
160  *   - ENODEV - there is no Ethernet device for this port id.
161  *   - ENOTSUP - the port doesn't support external TxQ.
162  */
163 __rte_experimental
164 int rte_pmd_mlx5_external_tx_queue_id_unmap(uint16_t port_id,
165 					    uint16_t dpdk_idx);
166 
167 /**
168  * The rate of the host port shaper will be updated directly at the next
169  * available descriptor threshold event to the rate that comes with this flag set;
170  * set rate 0 to disable this rate update.
171  * Unset this flag to update the rate of the host port shaper directly in
172  * the API call; use rate 0 to disable the current shaper.
173  */
174 #define RTE_PMD_MLX5_HOST_SHAPER_FLAG_AVAIL_THRESH_TRIGGERED 0
175 
176 /**
177  * Configure a HW shaper to limit Tx rate for a host port.
178  * The configuration will affect all the ethdev ports belonging to
179  * the same rte_device.
180  *
181  * @param[in] port_id
182  *   The port identifier of the Ethernet device.
183  * @param[in] rate
184  *   Unit is 100Mbps, setting the rate to 0 disables the shaper.
185  * @param[in] flags
186  *   Host shaper flags (see RTE_PMD_MLX5_HOST_SHAPER_FLAG_*).
187  * @return
188  *   0 : operation success.
189  *   Otherwise:
190  *   - ENOENT - no ibdev interface.
191  *   - EBUSY  - the register access unit is busy.
192  *   - EIO    - the register access command meets IO error.
193  */
194 __rte_experimental
195 int rte_pmd_mlx5_host_shaper_config(int port_id, uint8_t rate, uint32_t flags);
196 
197 /**
198  * Enable traffic for external SQ.
199  *
200  * @param[in] port_id
201  *   The port identifier of the Ethernet device.
202  * @param[in] sq_num
203  *   SQ HW number.
204  *
205  * @return
206  *   0 on success, a negative errno value otherwise and rte_errno is set.
207  *   Possible values for rte_errno:
208  *   - EINVAL - invalid sq_number or port type.
209  *   - ENODEV - there is no Ethernet device for this port id.
210  */
211 __rte_experimental
212 int rte_pmd_mlx5_external_sq_enable(uint16_t port_id, uint32_t sq_num);
213 
214 /* MLX5 flow engine mode definition for live migration. */
215 enum rte_pmd_mlx5_flow_engine_mode {
216 	RTE_PMD_MLX5_FLOW_ENGINE_MODE_ACTIVE, /* active means high priority, effective in HW. */
217 	RTE_PMD_MLX5_FLOW_ENGINE_MODE_STANDBY, /* standby mode with lower priority flow rules. */
218 };
219 
220 /**
221  * When set on the flow engine of a standby process, ingress flow rules will be effective
222  * in active and standby processes, so the ingress traffic may be duplicated.
223  */
224 #define RTE_PMD_MLX5_FLOW_ENGINE_FLAG_STANDBY_DUP_INGRESS      RTE_BIT32(0)
225 
226 /**
227  * @warning
228  * @b EXPERIMENTAL: this API may change without prior notice
229  *
230  * Set the flow engine mode of the process to active or standby,
231  * affecting network traffic handling.
232  *
233  * If one device does not support this operation or fails,
234  * the whole operation is failed and rolled back.
235  *
236  * It is forbidden to have multiple flow engines with the same mode
237  * unless only one of them is configured to handle the traffic.
238  *
239  * The application's flow engine is active by default.
240  * The configuration from the active flow engine is effective immediately
241  * while the configuration from the standby flow engine is queued by hardware.
242  * When configuring the device from a standby flow engine,
243  * it has no effect except for below situations:
244  *   - traffic not handled by the active flow engine configuration
245  *   - no active flow engine
246  *
247  * When flow engine of a process is changed from a standby to an active mode,
248  * all preceding configurations that are queued by hardware
249  * should become effective immediately.
250  * Before mode transition, all the traffic handling configurations
251  * set by the active flow engine should be flushed first.
252  *
253  * In summary, the operations are expected to happen in this order
254  * in "old" and "new" applications:
255  *   device: already configured by the old application
256  *   new:    start as active
257  *   new:    probe the same device
258  *   new:    set as standby
259  *   new:    configure the device
260  *   device: has configurations from old and new applications
261  *   old:    clear its device configuration
262  *   device: has only 1 configuration from new application
263  *   new:    set as active
264  *   device: downtime for connecting all to the new application
265  *   old:    shutdown
266  *
267  * @param mode
268  *   The desired mode (see rte_pmd_mlx5_flow_engine_mode).
269  * @param flags
270  *   Mode specific flags (see RTE_PMD_MLX5_FLOW_ENGINE_FLAG_*).
271  * @return
272  *   Positive value on success, -rte_errno value on error:
273  *   - (> 0) Number of switched devices.
274  *   - (-EINVAL) if error happen and rollback internally.
275  *   - (-EPERM) if operation failed and can't recover.
276  */
277 __rte_experimental
278 int rte_pmd_mlx5_flow_engine_set_mode(enum rte_pmd_mlx5_flow_engine_mode mode, uint32_t flags);
279 
280 /**
281  * User configuration structure using to create parser for single GENEVE TLV option.
282  */
283 struct rte_pmd_mlx5_geneve_tlv {
284 	/**
285 	 * The class of the GENEVE TLV option.
286 	 * Relevant only when 'match_on_class_mode' is 1.
287 	 */
288 	rte_be16_t option_class;
289 	/**
290 	 * The type of the GENEVE TLV option.
291 	 * This field is the identifier of the option.
292 	 */
293 	uint8_t option_type;
294 	/**
295 	 * The length of the GENEVE TLV option data excluding the option header
296 	 * in DW granularity.
297 	 */
298 	uint8_t option_len;
299 	/**
300 	 * Indicator about class field role in this option:
301 	 *  0 - class is ignored.
302 	 *  1 - class is fixed (the class defines the option along with the type).
303 	 *  2 - class matching per flow.
304 	 */
305 	uint8_t match_on_class_mode;
306 	/**
307 	 * The offset of the first sample in DW granularity.
308 	 * This offset is relative to first of option data.
309 	 * The 'match_data_mask' corresponds to option data since this offset.
310 	 */
311 	uint8_t offset;
312 	/**
313 	 * The number of DW to sample.
314 	 * This field describes the length of 'match_data_mask' in DW
315 	 * granularity.
316 	 */
317 	uint8_t sample_len;
318 	/**
319 	 * Array of DWs which each bit marks if this bit should be sampled.
320 	 * Each nonzero DW consumes one DW from maximum 7 DW in total.
321 	 */
322 	rte_be32_t *match_data_mask;
323 };
324 
325 /**
326  * Creates GENEVE TLV parser for the selected port.
327  * This function must be called before first use of GENEVE option.
328  *
329  * This API is port oriented, but the configuration is done once for all ports
330  * under the same physical device. Each port should call this API before using
331  * GENEVE OPT item, but it must use the same options in the same order inside
332  * the list.
333  *
334  * Each physical device has 7 DWs for GENEVE TLV options. Each nonzero element
335  * in 'match_data_mask' array consumes one DW, and choosing matchable mode for
336  * class consumes additional one.
337  * Calling this API for second port under same physical device doesn't consume
338  * more DW, it uses same configuration.
339  *
340  * @param[in] port_id
341  *   The port identifier of the Ethernet device.
342  * @param[in] tlv_list
343  *   A list of GENEVE TLV options to create parser for them.
344  * @param[in] nb_options
345  *   The number of options in TLV list.
346  *
347  * @return
348  *   A pointer to TLV handle on success, NULL otherwise and rte_errno is set.
349  *   Possible values for rte_errno:
350  *   - ENOMEM - not enough memory to create GENEVE TLV parser.
351  *   - EEXIST - this port already has GENEVE TLV parser or another port under
352  *              same physical device has already prepared a different parser.
353  *   - EINVAL - invalid GENEVE TLV requested.
354  *   - ENODEV - there is no Ethernet device for this port id.
355  *   - ENOTSUP - the port doesn't support GENEVE TLV parsing.
356  */
357 __rte_experimental
358 void *
359 rte_pmd_mlx5_create_geneve_tlv_parser(uint16_t port_id,
360 				      const struct rte_pmd_mlx5_geneve_tlv tlv_list[],
361 				      uint8_t nb_options);
362 
363 /**
364  * Destroy GENEVE TLV parser for the selected port.
365  * This function must be called after last use of GENEVE option and before port
366  * closing.
367  *
368  * @param[in] handle
369  *   Handle for the GENEVE TLV parser object to be destroyed.
370  *
371  * @return
372  *   0 on success, a negative errno value otherwise and rte_errno is set.
373  *   Possible values for rte_errno:
374  *   - EINVAL - invalid handle.
375  *   - ENOENT - there is no valid GENEVE TLV parser in this handle.
376  *   - EBUSY - one of options is in used by template table.
377  */
378 __rte_experimental
379 int
380 rte_pmd_mlx5_destroy_geneve_tlv_parser(void *handle);
381 
382 /**
383  * Dump Rx Queue Context for a given port/queue
384  *
385  * @param[in] port_id
386  *   Port ID
387  * @param[in] queue_id
388  *   Queue ID
389  * @param[in] filename
390  *   Name of file to dump the Rx Queue Context
391  *
392  * @return
393  *   0 for success, non-zero value depending on failure type
394  */
395 
396 __rte_experimental
397 int
398 rte_pmd_mlx5_rxq_dump_contexts(uint16_t port_id, uint16_t queue_id, const char *filename);
399 
400 /**
401  * Dump Tx Queue Context for a given port/queue
402  *
403  * @param[in] port_id
404  *   Port ID
405  * @param[in] queue_id
406  *   Queue ID
407  * @param[in] filename
408  *   Name of file to dump the Tx Queue Context
409  *
410  * @return
411  *   0 for success, non-zero value depending on failure type
412  */
413 
414 __rte_experimental
415 int
416 rte_pmd_mlx5_txq_dump_contexts(uint16_t port_id, uint16_t queue_id, const char *filename);
417 
418 #ifdef __cplusplus
419 }
420 #endif
421 
422 #endif /* RTE_PMD_PRIVATE_MLX5_H_ */
423