Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2020 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #include <stddef.h>
6 : : #include <errno.h>
7 : : #include <stdbool.h>
8 : : #include <string.h>
9 : : #include <stdint.h>
10 : : #include <sys/queue.h>
11 : :
12 : : #include <rte_malloc.h>
13 : : #include <rte_common.h>
14 : : #include <rte_eal_paging.h>
15 : :
16 : : #include <mlx5_glue.h>
17 : : #include <mlx5_devx_cmds.h>
18 : : #include <mlx5_common_devx.h>
19 : : #include <mlx5_malloc.h>
20 : :
21 : : #include "mlx5.h"
22 : : #include "mlx5_common_os.h"
23 : : #include "mlx5_tx.h"
24 : : #include "mlx5_rx.h"
25 : : #include "mlx5_utils.h"
26 : : #include "mlx5_devx.h"
27 : : #include "mlx5_flow.h"
28 : : #include "mlx5_flow_os.h"
29 : :
30 : : /**
31 : : * Validate given external queue's port is valid or not.
32 : : *
33 : : * @param[in] port_id
34 : : * The port identifier of the Ethernet device.
35 : : *
36 : : * @return
37 : : * 0 on success, non-0 otherwise
38 : : */
39 : : int
40 : 0 : mlx5_devx_extq_port_validate(uint16_t port_id)
41 : : {
42 : : struct rte_eth_dev *dev;
43 : : struct mlx5_priv *priv;
44 : :
45 [ # # ]: 0 : if (rte_eth_dev_is_valid_port(port_id) < 0) {
46 : 0 : DRV_LOG(ERR, "There is no Ethernet device for port %u.",
47 : : port_id);
48 : 0 : rte_errno = ENODEV;
49 : 0 : return -rte_errno;
50 : : }
51 : : dev = &rte_eth_devices[port_id];
52 : 0 : priv = dev->data->dev_private;
53 [ # # # # ]: 0 : if (!mlx5_imported_pd_and_ctx(priv->sh->cdev)) {
54 : 0 : DRV_LOG(ERR, "Port %u "
55 : : "external queue isn't supported on local PD and CTX.",
56 : : port_id);
57 : 0 : rte_errno = ENOTSUP;
58 : 0 : return -rte_errno;
59 : : }
60 [ # # ]: 0 : if (!mlx5_devx_obj_ops_en(priv->sh)) {
61 : 0 : DRV_LOG(ERR,
62 : : "Port %u external queue isn't supported by Verbs API.",
63 : : port_id);
64 : 0 : rte_errno = ENOTSUP;
65 : 0 : return -rte_errno;
66 : : }
67 : : return 0;
68 : : }
69 : :
70 : : /**
71 : : * Modify RQ vlan stripping offload
72 : : *
73 : : * @param rxq
74 : : * Rx queue.
75 : : * @param on
76 : : * Enable/disable VLAN stripping.
77 : : *
78 : : * @return
79 : : * 0 on success, non-0 otherwise
80 : : */
81 : : static int
82 [ # # ]: 0 : mlx5_rxq_obj_modify_rq_vlan_strip(struct mlx5_rxq_priv *rxq, int on)
83 : : {
84 : : struct mlx5_devx_modify_rq_attr rq_attr;
85 : :
86 : : memset(&rq_attr, 0, sizeof(rq_attr));
87 : 0 : rq_attr.rq_state = MLX5_RQC_STATE_RDY;
88 : 0 : rq_attr.state = MLX5_RQC_STATE_RDY;
89 : 0 : rq_attr.vsd = (on ? 0 : 1);
90 : 0 : rq_attr.modify_bitmask = MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD;
91 [ # # ]: 0 : if (rxq->ctrl->is_hairpin)
92 : 0 : return mlx5_devx_cmd_modify_rq(rxq->ctrl->obj->rq, &rq_attr);
93 : 0 : return mlx5_devx_cmd_modify_rq(rxq->devx_rq.rq, &rq_attr);
94 : : }
95 : :
96 : : /**
97 : : * Modify the q counter of a given RQ
98 : : *
99 : : * @param rxq
100 : : * Rx queue.
101 : : * @param counter_set_id
102 : : * Q counter id to set
103 : : *
104 : : * @return
105 : : * 0 on success, non-0 otherwise
106 : : */
107 : : static int
108 : 0 : mlx5_rxq_obj_modify_counter(struct mlx5_rxq_priv *rxq, uint32_t counter_set_id)
109 : : {
110 : : struct mlx5_devx_modify_rq_attr rq_attr;
111 : :
112 : : memset(&rq_attr, 0, sizeof(rq_attr));
113 : 0 : rq_attr.rq_state = MLX5_RQC_STATE_RDY;
114 : 0 : rq_attr.state = MLX5_RQC_STATE_RDY;
115 : 0 : rq_attr.counter_set_id = counter_set_id;
116 : 0 : rq_attr.modify_bitmask = MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID;
117 : 0 : return mlx5_devx_cmd_modify_rq(rxq->ctrl->obj->rq, &rq_attr);
118 : : }
119 : :
120 : : /**
121 : : * Modify RQ using DevX API.
122 : : *
123 : : * @param rxq
124 : : * DevX rx queue.
125 : : * @param type
126 : : * Type of change queue state.
127 : : *
128 : : * @return
129 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
130 : : */
131 : : int
132 [ # # # # : 0 : mlx5_devx_modify_rq(struct mlx5_rxq_priv *rxq, uint8_t type)
# # ]
133 : : {
134 : : struct mlx5_devx_modify_rq_attr rq_attr;
135 : :
136 : : memset(&rq_attr, 0, sizeof(rq_attr));
137 [ # # # # : 0 : switch (type) {
# # ]
138 : 0 : case MLX5_RXQ_MOD_ERR2RST:
139 : 0 : rq_attr.rq_state = MLX5_RQC_STATE_ERR;
140 : : rq_attr.state = MLX5_RQC_STATE_RST;
141 : 0 : break;
142 : 0 : case MLX5_RXQ_MOD_RST2RDY:
143 : : rq_attr.rq_state = MLX5_RQC_STATE_RST;
144 : 0 : rq_attr.state = MLX5_RQC_STATE_RDY;
145 [ # # ]: 0 : if (rxq->lwm) {
146 : 0 : rq_attr.modify_bitmask |=
147 : : MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_WQ_LWM;
148 : 0 : rq_attr.lwm = rxq->lwm;
149 : : }
150 : : break;
151 : 0 : case MLX5_RXQ_MOD_RDY2ERR:
152 : 0 : rq_attr.rq_state = MLX5_RQC_STATE_RDY;
153 : 0 : rq_attr.state = MLX5_RQC_STATE_ERR;
154 : 0 : break;
155 : 0 : case MLX5_RXQ_MOD_RDY2RST:
156 : 0 : rq_attr.rq_state = MLX5_RQC_STATE_RDY;
157 : : rq_attr.state = MLX5_RQC_STATE_RST;
158 : 0 : break;
159 : 0 : case MLX5_RXQ_MOD_RDY2RDY:
160 : 0 : rq_attr.rq_state = MLX5_RQC_STATE_RDY;
161 : 0 : rq_attr.state = MLX5_RQC_STATE_RDY;
162 : 0 : rq_attr.modify_bitmask |= MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_WQ_LWM;
163 : 0 : rq_attr.lwm = rxq->lwm;
164 : 0 : break;
165 : : default:
166 : : break;
167 : : }
168 [ # # ]: 0 : if (rxq->ctrl->is_hairpin)
169 : 0 : return mlx5_devx_cmd_modify_rq(rxq->ctrl->obj->rq, &rq_attr);
170 : 0 : return mlx5_devx_cmd_modify_rq(rxq->devx_rq.rq, &rq_attr);
171 : : }
172 : :
173 : : /**
174 : : * Modify SQ using DevX API.
175 : : *
176 : : * @param txq_obj
177 : : * DevX Tx queue object.
178 : : * @param type
179 : : * Type of change queue state.
180 : : * @param dev_port
181 : : * Unnecessary.
182 : : *
183 : : * @return
184 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
185 : : */
186 : : int
187 : 0 : mlx5_txq_devx_modify(struct mlx5_txq_obj *obj, enum mlx5_txq_modify_type type,
188 : : uint8_t dev_port)
189 : : {
190 : 0 : struct mlx5_devx_modify_sq_attr msq_attr = { 0 };
191 : : int ret;
192 : :
193 [ # # ]: 0 : if (type != MLX5_TXQ_MOD_RST2RDY) {
194 : : /* Change queue state to reset. */
195 [ # # ]: 0 : if (type == MLX5_TXQ_MOD_ERR2RDY)
196 : 0 : msq_attr.sq_state = MLX5_SQC_STATE_ERR;
197 : : else
198 : 0 : msq_attr.sq_state = MLX5_SQC_STATE_RDY;
199 : : msq_attr.state = MLX5_SQC_STATE_RST;
200 : 0 : ret = mlx5_devx_cmd_modify_sq(obj->sq_obj.sq, &msq_attr);
201 [ # # ]: 0 : if (ret) {
202 : 0 : DRV_LOG(ERR, "Cannot change the Tx SQ state to RESET"
203 : : " %s", strerror(errno));
204 : 0 : rte_errno = errno;
205 : 0 : return ret;
206 : : }
207 : : }
208 [ # # ]: 0 : if (type != MLX5_TXQ_MOD_RDY2RST) {
209 : : /* Change queue state to ready. */
210 : 0 : msq_attr.sq_state = MLX5_SQC_STATE_RST;
211 : 0 : msq_attr.state = MLX5_SQC_STATE_RDY;
212 : 0 : ret = mlx5_devx_cmd_modify_sq(obj->sq_obj.sq, &msq_attr);
213 [ # # ]: 0 : if (ret) {
214 : 0 : DRV_LOG(ERR, "Cannot change the Tx SQ state to READY"
215 : : " %s", strerror(errno));
216 : 0 : rte_errno = errno;
217 : 0 : return ret;
218 : : }
219 : : }
220 : : /*
221 : : * The dev_port variable is relevant only in Verbs API, and there is a
222 : : * pointer that points to this function and a parallel function in verbs
223 : : * intermittently, so they should have the same parameters.
224 : : */
225 : : (void)dev_port;
226 : : return 0;
227 : : }
228 : :
229 : : /**
230 : : * Release an Rx DevX queue object.
231 : : *
232 : : * @param rxq
233 : : * DevX Rx queue.
234 : : */
235 : : static void
236 : 0 : mlx5_rxq_devx_obj_release(struct mlx5_rxq_priv *rxq)
237 : : {
238 : 0 : struct mlx5_rxq_obj *rxq_obj = rxq->ctrl->obj;
239 : :
240 [ # # ]: 0 : if (rxq_obj == NULL)
241 : : return;
242 [ # # ]: 0 : if (rxq_obj->rxq_ctrl->is_hairpin) {
243 [ # # ]: 0 : if (rxq_obj->rq == NULL)
244 : : return;
245 : 0 : mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RDY2RST);
246 : 0 : claim_zero(mlx5_devx_cmd_destroy(rxq_obj->rq));
247 : : } else {
248 [ # # ]: 0 : if (rxq->devx_rq.rq == NULL)
249 : : return;
250 : 0 : mlx5_devx_rq_destroy(&rxq->devx_rq);
251 [ # # # # ]: 0 : if (rxq->devx_rq.rmp != NULL && rxq->devx_rq.rmp->ref_cnt > 0)
252 : : return;
253 : 0 : mlx5_devx_cq_destroy(&rxq_obj->cq_obj);
254 : : memset(&rxq_obj->cq_obj, 0, sizeof(rxq_obj->cq_obj));
255 [ # # ]: 0 : if (rxq_obj->devx_channel) {
256 : : mlx5_os_devx_destroy_event_channel
257 : : (rxq_obj->devx_channel);
258 : 0 : rxq_obj->devx_channel = NULL;
259 : : }
260 : : }
261 : 0 : rxq->ctrl->started = false;
262 : : }
263 : :
264 : : /**
265 : : * Get event for an Rx DevX queue object.
266 : : *
267 : : * @param rxq_obj
268 : : * DevX Rx queue object.
269 : : *
270 : : * @return
271 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
272 : : */
273 : : static int
274 : 0 : mlx5_rx_devx_get_event(struct mlx5_rxq_obj *rxq_obj)
275 : : {
276 : : #ifdef HAVE_IBV_DEVX_EVENT
277 : : union {
278 : : struct mlx5dv_devx_async_event_hdr event_resp;
279 : : uint8_t buf[sizeof(struct mlx5dv_devx_async_event_hdr) + 128];
280 : : } out;
281 : 0 : int ret = mlx5_glue->devx_get_event(rxq_obj->devx_channel,
282 : : &out.event_resp,
283 : : sizeof(out.buf));
284 : :
285 [ # # ]: 0 : if (ret < 0) {
286 : 0 : rte_errno = errno;
287 : 0 : return -rte_errno;
288 : : }
289 [ # # ]: 0 : if (out.event_resp.cookie != (uint64_t)(uintptr_t)rxq_obj->cq_obj.cq) {
290 : 0 : rte_errno = EINVAL;
291 : 0 : return -rte_errno;
292 : : }
293 : : return 0;
294 : : #else
295 : : (void)rxq_obj;
296 : : rte_errno = ENOTSUP;
297 : : return -rte_errno;
298 : : #endif /* HAVE_IBV_DEVX_EVENT */
299 : : }
300 : :
301 : : /**
302 : : * Get LWM event for shared context, return the correct port/rxq for this event.
303 : : *
304 : : * @param priv
305 : : * Mlx5_priv object.
306 : : * @param rxq_idx [out]
307 : : * Which rxq gets this event.
308 : : * @param port_id [out]
309 : : * Which port gets this event.
310 : : *
311 : : * @return
312 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
313 : : */
314 : : static int
315 : 0 : mlx5_rx_devx_get_event_lwm(struct mlx5_priv *priv, int *rxq_idx, int *port_id)
316 : : {
317 : : #ifdef HAVE_IBV_DEVX_EVENT
318 : : union {
319 : : struct mlx5dv_devx_async_event_hdr event_resp;
320 : : uint8_t buf[sizeof(struct mlx5dv_devx_async_event_hdr) + 128];
321 : : } out;
322 : : int ret;
323 : :
324 : : memset(&out, 0, sizeof(out));
325 : 0 : ret = mlx5_glue->devx_get_event(priv->sh->devx_channel_lwm,
326 : : &out.event_resp,
327 : : sizeof(out.buf));
328 [ # # ]: 0 : if (ret < 0) {
329 : 0 : rte_errno = errno;
330 : 0 : DRV_LOG(WARNING, "%s err\n", __func__);
331 : 0 : return -rte_errno;
332 : : }
333 : 0 : *port_id = (((uint32_t)out.event_resp.cookie) >>
334 : 0 : LWM_COOKIE_PORTID_OFFSET) & LWM_COOKIE_PORTID_MASK;
335 : 0 : *rxq_idx = (((uint32_t)out.event_resp.cookie) >>
336 : 0 : LWM_COOKIE_RXQID_OFFSET) & LWM_COOKIE_RXQID_MASK;
337 : 0 : return 0;
338 : : #else
339 : : (void)priv;
340 : : (void)rxq_idx;
341 : : (void)port_id;
342 : : rte_errno = ENOTSUP;
343 : : return -rte_errno;
344 : : #endif /* HAVE_IBV_DEVX_EVENT */
345 : : }
346 : :
347 : : /**
348 : : * Create a RQ object using DevX.
349 : : *
350 : : * @param rxq
351 : : * Pointer to Rx queue.
352 : : *
353 : : * @return
354 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
355 : : */
356 : : static int
357 : 0 : mlx5_rxq_create_devx_rq_resources(struct mlx5_rxq_priv *rxq)
358 : : {
359 : 0 : struct mlx5_priv *priv = rxq->priv;
360 : 0 : struct mlx5_common_device *cdev = priv->sh->cdev;
361 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
362 : : struct mlx5_rxq_data *rxq_data = &rxq->ctrl->rxq;
363 : 0 : struct mlx5_devx_create_rq_attr rq_attr = { 0 };
364 : 0 : uint16_t log_desc_n = rxq_data->elts_n - rxq_data->sges_n;
365 : : uint32_t wqe_size, log_wqe_size;
366 : :
367 : : /* Fill RQ attributes. */
368 : : rq_attr.mem_rq_type = MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE;
369 : 0 : rq_attr.flush_in_error_en = 1;
370 : 0 : rq_attr.vsd = (rxq_data->vlan_strip) ? 0 : 1;
371 : 0 : rq_attr.cqn = rxq_ctrl->obj->cq_obj.cq->id;
372 : 0 : rq_attr.scatter_fcs = (rxq_data->crc_present) ? 1 : 0;
373 [ # # ]: 0 : rq_attr.ts_format =
374 [ # # ]: 0 : mlx5_ts_format_conv(cdev->config.hca_attr.rq_ts_format);
375 : : /* Fill WQ attributes for this RQ. */
376 [ # # ]: 0 : if (mlx5_rxq_mprq_enabled(rxq_data)) {
377 : 0 : rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ;
378 : : /*
379 : : * Number of strides in each WQE:
380 : : * 512*2^single_wqe_log_num_of_strides.
381 : : */
382 : 0 : rq_attr.wq_attr.single_wqe_log_num_of_strides =
383 : 0 : rxq_data->log_strd_num -
384 : : MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES;
385 : : /* Stride size = (2^single_stride_log_num_of_bytes)*64B. */
386 : 0 : rq_attr.wq_attr.single_stride_log_num_of_bytes =
387 : 0 : rxq_data->log_strd_sz -
388 : : MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES;
389 : : wqe_size = sizeof(struct mlx5_wqe_mprq);
390 : : } else {
391 : 0 : rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
392 : : wqe_size = sizeof(struct mlx5_wqe_data_seg);
393 : : }
394 : 0 : log_wqe_size = log2above(wqe_size) + rxq_data->sges_n;
395 : 0 : wqe_size = 1 << log_wqe_size; /* round up power of two.*/
396 : 0 : rq_attr.wq_attr.log_wq_stride = log_wqe_size;
397 : 0 : rq_attr.wq_attr.log_wq_sz = log_desc_n;
398 : 0 : rq_attr.wq_attr.end_padding_mode = priv->config.hw_padding ?
399 : 0 : MLX5_WQ_END_PAD_MODE_ALIGN :
400 : : MLX5_WQ_END_PAD_MODE_NONE;
401 : 0 : rq_attr.wq_attr.pd = cdev->pdn;
402 : 0 : rq_attr.counter_set_id = priv->counter_set_id;
403 : 0 : rq_attr.delay_drop_en = rxq_data->delay_drop;
404 [ # # ]: 0 : rq_attr.user_index = rte_cpu_to_be_16(priv->dev_data->port_id);
405 [ # # ]: 0 : if (rxq_data->shared) /* Create RMP based RQ. */
406 : 0 : rxq->devx_rq.rmp = &rxq_ctrl->obj->devx_rmp;
407 : : /* Create RQ using DevX API. */
408 : 0 : return mlx5_devx_rq_create(cdev->ctx, &rxq->devx_rq, wqe_size,
409 : 0 : log_desc_n, &rq_attr, rxq_ctrl->socket);
410 : : }
411 : :
412 : : /**
413 : : * Create a DevX CQ object for an Rx queue.
414 : : *
415 : : * @param rxq
416 : : * Pointer to Rx queue.
417 : : *
418 : : * @return
419 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
420 : : */
421 : : static int
422 : 0 : mlx5_rxq_create_devx_cq_resources(struct mlx5_rxq_priv *rxq)
423 : : {
424 : : struct mlx5_devx_cq *cq_obj = 0;
425 : 0 : struct mlx5_devx_cq_attr cq_attr = { 0 };
426 : 0 : struct mlx5_priv *priv = rxq->priv;
427 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
428 : 0 : uint16_t port_id = priv->dev_data->port_id;
429 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
430 : 0 : struct mlx5_rxq_data *rxq_data = &rxq_ctrl->rxq;
431 : 0 : unsigned int cqe_n = mlx5_rxq_cqe_num(rxq_data);
432 : : uint32_t log_cqe_n;
433 : 0 : uint16_t event_nums[1] = { 0 };
434 : : int ret = 0;
435 : :
436 [ # # ]: 0 : if (rxq_ctrl->started)
437 : : return 0;
438 [ # # # # ]: 0 : if (priv->config.cqe_comp && !rxq_data->hw_timestamp &&
439 : : !rxq_data->lro) {
440 : 0 : cq_attr.cqe_comp_en = 1u;
441 : 0 : cq_attr.cqe_comp_layout = priv->config.enh_cqe_comp;
442 : 0 : rxq_data->cqe_comp_layout = cq_attr.cqe_comp_layout;
443 : 0 : rxq_data->mcqe_format = priv->config.cqe_comp_fmt;
444 : 0 : rxq_data->byte_mask = UINT32_MAX;
445 [ # # # # : 0 : switch (priv->config.cqe_comp_fmt) {
# ]
446 : 0 : case MLX5_CQE_RESP_FORMAT_HASH:
447 : : /* fallthrough */
448 : : case MLX5_CQE_RESP_FORMAT_CSUM:
449 : : /*
450 : : * Select CSUM miniCQE format only for non-vectorized
451 : : * MPRQ Rx burst, use HASH miniCQE format for others.
452 : : */
453 [ # # # # ]: 0 : if (mlx5_rxq_check_vec_support(rxq_data) < 0 &&
454 : : mlx5_rxq_mprq_enabled(rxq_data))
455 : 0 : cq_attr.mini_cqe_res_format =
456 : : MLX5_CQE_RESP_FORMAT_CSUM_STRIDX;
457 : : else
458 : 0 : cq_attr.mini_cqe_res_format =
459 : : MLX5_CQE_RESP_FORMAT_HASH;
460 : 0 : rxq_data->mcqe_format = cq_attr.mini_cqe_res_format;
461 : 0 : break;
462 : 0 : case MLX5_CQE_RESP_FORMAT_FTAG_STRIDX:
463 : 0 : rxq_data->byte_mask = MLX5_LEN_WITH_MARK_MASK;
464 : : /* fallthrough */
465 : 0 : case MLX5_CQE_RESP_FORMAT_CSUM_STRIDX:
466 : 0 : cq_attr.mini_cqe_res_format = priv->config.cqe_comp_fmt;
467 : 0 : break;
468 : 0 : case MLX5_CQE_RESP_FORMAT_L34H_STRIDX:
469 : 0 : cq_attr.mini_cqe_res_format = 0;
470 : 0 : cq_attr.mini_cqe_res_format_ext = 1;
471 : 0 : break;
472 : : }
473 : 0 : DRV_LOG(DEBUG,
474 : : "Port %u Rx CQE compression is enabled, format %d.",
475 : : port_id, priv->config.cqe_comp_fmt);
476 : : /*
477 : : * For vectorized Rx, it must not be doubled in order to
478 : : * make cq_ci and rq_ci aligned.
479 : : */
480 [ # # ]: 0 : if (mlx5_rxq_check_vec_support(rxq_data) < 0)
481 : 0 : cqe_n *= 2;
482 [ # # # # ]: 0 : } else if (priv->config.cqe_comp && rxq_data->hw_timestamp) {
483 : 0 : DRV_LOG(DEBUG,
484 : : "Port %u Rx CQE compression is disabled for HW timestamp.",
485 : : port_id);
486 [ # # # # ]: 0 : } else if (priv->config.cqe_comp && rxq_data->lro) {
487 : 0 : DRV_LOG(DEBUG,
488 : : "Port %u Rx CQE compression is disabled for LRO.",
489 : : port_id);
490 : : }
491 [ # # ]: 0 : cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(sh->rx_uar.obj);
492 : : log_cqe_n = log2above(cqe_n);
493 : : /* Create CQ using DevX API. */
494 : 0 : ret = mlx5_devx_cq_create(sh->cdev->ctx, &rxq_ctrl->obj->cq_obj,
495 : : log_cqe_n, &cq_attr, sh->numa_node);
496 [ # # ]: 0 : if (ret)
497 : : return ret;
498 : 0 : cq_obj = &rxq_ctrl->obj->cq_obj;
499 : 0 : rxq_data->cqes = (volatile struct mlx5_cqe (*)[])
500 : 0 : (uintptr_t)cq_obj->cqes;
501 : 0 : rxq_data->cq_db = cq_obj->db_rec;
502 : 0 : rxq_data->uar_data = sh->rx_uar.cq_db;
503 : 0 : rxq_data->cqe_n = log_cqe_n;
504 : 0 : rxq_data->cqn = cq_obj->cq->id;
505 : 0 : rxq_data->cq_ci = 0;
506 [ # # ]: 0 : if (rxq_ctrl->obj->devx_channel) {
507 : 0 : ret = mlx5_os_devx_subscribe_devx_event
508 : : (rxq_ctrl->obj->devx_channel,
509 : : cq_obj->cq->obj,
510 : : sizeof(event_nums),
511 : : event_nums,
512 : : (uint64_t)(uintptr_t)cq_obj->cq);
513 [ # # ]: 0 : if (ret) {
514 : 0 : DRV_LOG(ERR, "Fail to subscribe CQ to event channel.");
515 : 0 : ret = errno;
516 : 0 : mlx5_devx_cq_destroy(cq_obj);
517 : : memset(cq_obj, 0, sizeof(*cq_obj));
518 : 0 : rte_errno = ret;
519 : 0 : return -ret;
520 : : }
521 : : }
522 : : return 0;
523 : : }
524 : :
525 : :
526 : : /**
527 : : * Create the Rx hairpin queue object.
528 : : *
529 : : * @param rxq
530 : : * Pointer to Rx queue.
531 : : *
532 : : * @return
533 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
534 : : */
535 : : static int
536 : 0 : mlx5_rxq_obj_hairpin_new(struct mlx5_rxq_priv *rxq)
537 : : {
538 : 0 : uint16_t idx = rxq->idx;
539 : 0 : struct mlx5_priv *priv = rxq->priv;
540 : 0 : struct mlx5_hca_attr *hca_attr __rte_unused = &priv->sh->cdev->config.hca_attr;
541 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
542 : 0 : struct mlx5_devx_create_rq_attr unlocked_attr = { 0 };
543 : 0 : struct mlx5_devx_create_rq_attr locked_attr = { 0 };
544 : 0 : struct mlx5_rxq_obj *tmpl = rxq_ctrl->obj;
545 : : uint32_t max_wq_data;
546 : :
547 : : MLX5_ASSERT(rxq != NULL && rxq->ctrl != NULL && tmpl != NULL);
548 : 0 : tmpl->rxq_ctrl = rxq_ctrl;
549 : 0 : unlocked_attr.hairpin = 1;
550 : 0 : max_wq_data =
551 : 0 : priv->sh->cdev->config.hca_attr.log_max_hairpin_wq_data_sz;
552 : : /* Jumbo frames > 9KB should be supported, and more packets. */
553 [ # # ]: 0 : if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) {
554 [ # # ]: 0 : if (priv->config.log_hp_size > max_wq_data) {
555 : 0 : DRV_LOG(ERR, "Total data size %u power of 2 is "
556 : : "too large for hairpin.",
557 : : priv->config.log_hp_size);
558 : 0 : rte_errno = ERANGE;
559 : 0 : return -rte_errno;
560 : : }
561 : 0 : unlocked_attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size;
562 : : } else {
563 : 0 : unlocked_attr.wq_attr.log_hairpin_data_sz =
564 : : (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ?
565 : 0 : max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE;
566 : : }
567 : : /* Set the packets number to the maximum value for performance. */
568 : 0 : unlocked_attr.wq_attr.log_hairpin_num_packets =
569 : 0 : unlocked_attr.wq_attr.log_hairpin_data_sz -
570 : : MLX5_HAIRPIN_QUEUE_STRIDE;
571 : :
572 : :
573 : 0 : rxq_ctrl->rxq.delay_drop = priv->config.hp_delay_drop;
574 : 0 : unlocked_attr.delay_drop_en = priv->config.hp_delay_drop;
575 : : unlocked_attr.hairpin_data_buffer_type =
576 : : MLX5_RQC_HAIRPIN_DATA_BUFFER_TYPE_UNLOCKED_INTERNAL_BUFFER;
577 [ # # ]: 0 : if (rxq->hairpin_conf.use_locked_device_memory) {
578 : : /*
579 : : * It is assumed that configuration is verified against capabilities
580 : : * during queue setup.
581 : : */
582 : : MLX5_ASSERT(hca_attr->hairpin_data_buffer_locked);
583 : : rte_memcpy(&locked_attr, &unlocked_attr, sizeof(locked_attr));
584 : 0 : locked_attr.hairpin_data_buffer_type =
585 : : MLX5_RQC_HAIRPIN_DATA_BUFFER_TYPE_LOCKED_INTERNAL_BUFFER;
586 : 0 : tmpl->rq = mlx5_devx_cmd_create_rq(priv->sh->cdev->ctx, &locked_attr,
587 : 0 : rxq_ctrl->socket);
588 [ # # # # ]: 0 : if (!tmpl->rq && rxq->hairpin_conf.force_memory) {
589 : 0 : DRV_LOG(ERR, "Port %u Rx hairpin queue %u can't create RQ object"
590 : : " with locked memory buffer",
591 : : priv->dev_data->port_id, idx);
592 : 0 : return -rte_errno;
593 [ # # # # ]: 0 : } else if (!tmpl->rq && !rxq->hairpin_conf.force_memory) {
594 : 0 : DRV_LOG(WARNING, "Port %u Rx hairpin queue %u can't create RQ object"
595 : : " with locked memory buffer. Falling back to unlocked"
596 : : " device memory.",
597 : : priv->dev_data->port_id, idx);
598 : 0 : rte_errno = 0;
599 : 0 : goto create_rq_unlocked;
600 : : }
601 : 0 : goto create_rq_set_state;
602 : : }
603 : :
604 : 0 : create_rq_unlocked:
605 : 0 : tmpl->rq = mlx5_devx_cmd_create_rq(priv->sh->cdev->ctx, &unlocked_attr,
606 : 0 : rxq_ctrl->socket);
607 [ # # ]: 0 : if (!tmpl->rq) {
608 : 0 : DRV_LOG(ERR,
609 : : "Port %u Rx hairpin queue %u can't create rq object.",
610 : : priv->dev_data->port_id, idx);
611 : 0 : rte_errno = errno;
612 : 0 : return -rte_errno;
613 : : }
614 : 0 : create_rq_set_state:
615 : 0 : priv->dev_data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_HAIRPIN;
616 : 0 : return 0;
617 : : }
618 : :
619 : : /**
620 : : * Create the Rx queue DevX object.
621 : : *
622 : : * @param rxq
623 : : * Pointer to Rx queue.
624 : : *
625 : : * @return
626 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
627 : : */
628 : : static int
629 : 0 : mlx5_rxq_devx_obj_new(struct mlx5_rxq_priv *rxq)
630 : : {
631 : 0 : struct mlx5_priv *priv = rxq->priv;
632 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
633 : 0 : struct mlx5_rxq_data *rxq_data = &rxq_ctrl->rxq;
634 : 0 : struct mlx5_rxq_obj *tmpl = rxq_ctrl->obj;
635 : : int ret = 0;
636 : :
637 : : MLX5_ASSERT(rxq_data);
638 : : MLX5_ASSERT(tmpl);
639 [ # # ]: 0 : if (rxq_ctrl->is_hairpin)
640 : 0 : return mlx5_rxq_obj_hairpin_new(rxq);
641 : 0 : tmpl->rxq_ctrl = rxq_ctrl;
642 [ # # ]: 0 : if (rxq_ctrl->irq && !rxq_ctrl->started) {
643 : : int devx_ev_flag =
644 : : MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA;
645 : :
646 : 0 : tmpl->devx_channel = mlx5_os_devx_create_event_channel
647 : 0 : (priv->sh->cdev->ctx,
648 : : devx_ev_flag);
649 [ # # ]: 0 : if (!tmpl->devx_channel) {
650 : 0 : rte_errno = errno;
651 : 0 : DRV_LOG(ERR, "Failed to create event channel %d.",
652 : : rte_errno);
653 : 0 : goto error;
654 : : }
655 : 0 : tmpl->fd = mlx5_os_get_devx_channel_fd(tmpl->devx_channel);
656 : : }
657 : : /* Create CQ using DevX API. */
658 : 0 : ret = mlx5_rxq_create_devx_cq_resources(rxq);
659 [ # # ]: 0 : if (ret) {
660 : 0 : DRV_LOG(ERR, "Failed to create CQ.");
661 : 0 : goto error;
662 : : }
663 [ # # # # ]: 0 : if (!rxq_data->shared || !rxq_ctrl->started)
664 : 0 : rxq_data->delay_drop = priv->config.std_delay_drop;
665 : : /* Create RQ using DevX API. */
666 : 0 : ret = mlx5_rxq_create_devx_rq_resources(rxq);
667 [ # # ]: 0 : if (ret) {
668 : 0 : DRV_LOG(ERR, "Port %u Rx queue %u RQ creation failure.",
669 : : priv->dev_data->port_id, rxq->idx);
670 : 0 : rte_errno = ENOMEM;
671 : 0 : goto error;
672 : : }
673 : : /* Change queue state to ready. */
674 : 0 : ret = mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RST2RDY);
675 [ # # ]: 0 : if (ret)
676 : 0 : goto error;
677 [ # # ]: 0 : if (!rxq_data->shared) {
678 : 0 : rxq_data->wqes = (void *)(uintptr_t)rxq->devx_rq.wq.umem_buf;
679 : 0 : rxq_data->rq_db = (uint32_t *)(uintptr_t)rxq->devx_rq.wq.db_rec;
680 [ # # ]: 0 : } else if (!rxq_ctrl->started) {
681 : 0 : rxq_data->wqes = (void *)(uintptr_t)tmpl->devx_rmp.wq.umem_buf;
682 : 0 : rxq_data->rq_db =
683 : 0 : (uint32_t *)(uintptr_t)tmpl->devx_rmp.wq.db_rec;
684 : : }
685 [ # # ]: 0 : if (!rxq_ctrl->started) {
686 [ # # ]: 0 : if (mlx5_rxq_initialize(rxq_data)) {
687 : 0 : DRV_LOG(ERR, "Port %u Rx queue %u RQ initialization failure.",
688 : : priv->dev_data->port_id, rxq->idx);
689 : 0 : rte_errno = ENOMEM;
690 : 0 : goto error;
691 : : }
692 : 0 : rxq_ctrl->wqn = rxq->devx_rq.rq->id;
693 : : }
694 : 0 : priv->dev_data->rx_queue_state[rxq->idx] = RTE_ETH_QUEUE_STATE_STARTED;
695 : 0 : return 0;
696 : 0 : error:
697 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
698 : 0 : mlx5_rxq_devx_obj_release(rxq);
699 : 0 : rte_errno = ret; /* Restore rte_errno. */
700 : 0 : return -rte_errno;
701 : : }
702 : :
703 : : /**
704 : : * Prepare RQT attribute structure for DevX RQT API.
705 : : *
706 : : * @param dev
707 : : * Pointer to Ethernet device.
708 : : * @param log_n
709 : : * Log of number of queues in the array.
710 : : * @param queues
711 : : * List of RX queue indices or NULL, in which case
712 : : * the attribute will be filled by drop queue ID.
713 : : * @param queues_n
714 : : * Size of @p queues array or 0 if it is NULL.
715 : : * @param ind_tbl
716 : : * DevX indirection table object.
717 : : *
718 : : * @return
719 : : * The RQT attr object initialized, NULL otherwise and rte_errno is set.
720 : : */
721 : : static struct mlx5_devx_rqt_attr *
722 : 0 : mlx5_devx_ind_table_create_rqt_attr(struct rte_eth_dev *dev,
723 : : const unsigned int log_n,
724 : : const uint16_t *queues,
725 : : const uint32_t queues_n)
726 : : {
727 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
728 : : struct mlx5_devx_rqt_attr *rqt_attr = NULL;
729 : 0 : const unsigned int rqt_n = 1 << log_n;
730 : : unsigned int i, j;
731 : :
732 : 0 : rqt_attr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt_attr) +
733 : : rqt_n * sizeof(uint32_t), 0, SOCKET_ID_ANY);
734 [ # # ]: 0 : if (!rqt_attr) {
735 : 0 : DRV_LOG(ERR, "Port %u cannot allocate RQT resources.",
736 : : dev->data->port_id);
737 : 0 : rte_errno = ENOMEM;
738 : 0 : return NULL;
739 : : }
740 : 0 : rqt_attr->rqt_max_size = priv->sh->dev_cap.ind_table_max_size;
741 : 0 : rqt_attr->rqt_actual_size = rqt_n;
742 [ # # ]: 0 : if (queues == NULL) {
743 [ # # ]: 0 : for (i = 0; i < rqt_n; i++)
744 : 0 : rqt_attr->rq_list[i] =
745 : 0 : priv->drop_queue.rxq->devx_rq.rq->id;
746 : : return rqt_attr;
747 : : }
748 [ # # ]: 0 : for (i = 0; i != queues_n; ++i) {
749 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[i])) {
750 : : struct mlx5_external_q *ext_rxq =
751 : 0 : mlx5_ext_rxq_get(dev, queues[i]);
752 : :
753 : 0 : rqt_attr->rq_list[i] = ext_rxq->hw_id;
754 : : } else {
755 : : struct mlx5_rxq_priv *rxq =
756 : 0 : mlx5_rxq_get(dev, queues[i]);
757 : :
758 : : MLX5_ASSERT(rxq != NULL);
759 [ # # ]: 0 : if (rxq->ctrl->is_hairpin)
760 : 0 : rqt_attr->rq_list[i] = rxq->ctrl->obj->rq->id;
761 : : else
762 : 0 : rqt_attr->rq_list[i] = rxq->devx_rq.rq->id;
763 : : }
764 : : }
765 : : MLX5_ASSERT(i > 0);
766 [ # # ]: 0 : for (j = 0; i != rqt_n; ++j, ++i)
767 : 0 : rqt_attr->rq_list[i] = rqt_attr->rq_list[j];
768 : : return rqt_attr;
769 : : }
770 : :
771 : : /**
772 : : * Create RQT using DevX API as a filed of indirection table.
773 : : *
774 : : * @param dev
775 : : * Pointer to Ethernet device.
776 : : * @param log_n
777 : : * Log of number of queues in the array.
778 : : * @param ind_tbl
779 : : * DevX indirection table object.
780 : : *
781 : : * @return
782 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
783 : : */
784 : : static int
785 : 0 : mlx5_devx_ind_table_new(struct rte_eth_dev *dev, const unsigned int log_n,
786 : : struct mlx5_ind_table_obj *ind_tbl)
787 : : {
788 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
789 : : struct mlx5_devx_rqt_attr *rqt_attr = NULL;
790 [ # # ]: 0 : const uint16_t *queues = dev->data->dev_started ? ind_tbl->queues :
791 : : NULL;
792 : :
793 : : MLX5_ASSERT(ind_tbl);
794 : 0 : rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n, queues,
795 : : ind_tbl->queues_n);
796 [ # # ]: 0 : if (!rqt_attr)
797 : 0 : return -rte_errno;
798 : 0 : ind_tbl->rqt = mlx5_devx_cmd_create_rqt(priv->sh->cdev->ctx, rqt_attr);
799 : 0 : mlx5_free(rqt_attr);
800 [ # # ]: 0 : if (!ind_tbl->rqt) {
801 : 0 : DRV_LOG(ERR, "Port %u cannot create DevX RQT.",
802 : : dev->data->port_id);
803 : 0 : rte_errno = errno;
804 : 0 : return -rte_errno;
805 : : }
806 : : return 0;
807 : : }
808 : :
809 : : /**
810 : : * Modify RQT using DevX API as a filed of indirection table.
811 : : *
812 : : * @param dev
813 : : * Pointer to Ethernet device.
814 : : * @param log_n
815 : : * Log of number of queues in the array.
816 : : * @param ind_tbl
817 : : * DevX indirection table object.
818 : : *
819 : : * @return
820 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
821 : : */
822 : : static int
823 : 0 : mlx5_devx_ind_table_modify(struct rte_eth_dev *dev, const unsigned int log_n,
824 : : const uint16_t *queues, const uint32_t queues_n,
825 : : struct mlx5_ind_table_obj *ind_tbl)
826 : : {
827 : : int ret = 0;
828 : : struct mlx5_devx_rqt_attr *rqt_attr = NULL;
829 : :
830 : : MLX5_ASSERT(ind_tbl);
831 : 0 : rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n,
832 : : queues,
833 : : queues_n);
834 [ # # ]: 0 : if (!rqt_attr)
835 : 0 : return -rte_errno;
836 : 0 : ret = mlx5_devx_cmd_modify_rqt(ind_tbl->rqt, rqt_attr);
837 : 0 : mlx5_free(rqt_attr);
838 [ # # ]: 0 : if (ret)
839 : 0 : DRV_LOG(ERR, "Port %u cannot modify DevX RQT.",
840 : : dev->data->port_id);
841 : : return ret;
842 : : }
843 : :
844 : : /**
845 : : * Destroy the DevX RQT object.
846 : : *
847 : : * @param ind_table
848 : : * Indirection table to release.
849 : : */
850 : : static void
851 : 0 : mlx5_devx_ind_table_destroy(struct mlx5_ind_table_obj *ind_tbl)
852 : : {
853 : 0 : claim_zero(mlx5_devx_cmd_destroy(ind_tbl->rqt));
854 : 0 : }
855 : :
856 : : /**
857 : : * Set TIR attribute struct with relevant input values.
858 : : *
859 : : * @param[in] dev
860 : : * Pointer to Ethernet device.
861 : : * @param[in] rss_key
862 : : * RSS key for the Rx hash queue.
863 : : * @param[in] hash_fields
864 : : * Verbs protocol hash field to make the RSS on.
865 : : * @param[in] ind_tbl
866 : : * Indirection table for TIR. If table queues array is NULL,
867 : : * a TIR for drop queue is assumed.
868 : : * @param[in] tunnel
869 : : * Tunnel type.
870 : : * @param[out] tir_attr
871 : : * Parameters structure for TIR creation/modification.
872 : : *
873 : : * @return
874 : : * The Verbs/DevX object initialised index, 0 otherwise and rte_errno is set.
875 : : */
876 : : static void
877 : 0 : mlx5_devx_tir_attr_set(struct rte_eth_dev *dev, const uint8_t *rss_key,
878 : : uint64_t hash_fields,
879 : : const struct mlx5_ind_table_obj *ind_tbl,
880 : : int tunnel, bool symmetric_hash_function,
881 : : struct mlx5_devx_tir_attr *tir_attr)
882 : : {
883 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
884 : : bool is_hairpin;
885 : : bool lro = false;
886 : : uint32_t i;
887 : :
888 : : /* NULL queues designate drop queue. */
889 [ # # ]: 0 : if (ind_tbl->queues == NULL) {
890 : 0 : is_hairpin = priv->drop_queue.rxq->ctrl->is_hairpin;
891 [ # # # # ]: 0 : } else if (mlx5_is_external_rxq(dev, ind_tbl->queues[0])) {
892 : : /* External RxQ supports neither Hairpin nor LRO. */
893 : : is_hairpin = false;
894 : : } else {
895 : 0 : is_hairpin = mlx5_rxq_is_hairpin(dev, ind_tbl->queues[0]);
896 : : lro = true;
897 : : /* Enable TIR LRO only if all the queues were configured for. */
898 [ # # ]: 0 : for (i = 0; i < ind_tbl->queues_n; ++i) {
899 : : struct mlx5_rxq_data *rxq_i =
900 : 0 : mlx5_rxq_data_get(dev, ind_tbl->queues[i]);
901 : :
902 [ # # # # ]: 0 : if (rxq_i != NULL && !rxq_i->lro) {
903 : : lro = false;
904 : : break;
905 : : }
906 : : }
907 : : }
908 : : memset(tir_attr, 0, sizeof(*tir_attr));
909 : 0 : tir_attr->disp_type = MLX5_TIRC_DISP_TYPE_INDIRECT;
910 : 0 : tir_attr->rx_hash_fn = MLX5_RX_HASH_FN_TOEPLITZ;
911 : 0 : tir_attr->tunneled_offload_en = !!tunnel;
912 : 0 : tir_attr->rx_hash_symmetric = symmetric_hash_function;
913 : : /* If needed, translate hash_fields bitmap to PRM format. */
914 [ # # ]: 0 : if (hash_fields) {
915 : : struct mlx5_rx_hash_field_select *rx_hash_field_select =
916 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
917 : 0 : hash_fields & IBV_RX_HASH_INNER ?
918 [ # # ]: 0 : &tir_attr->rx_hash_field_selector_inner :
919 : : #endif
920 : : &tir_attr->rx_hash_field_selector_outer;
921 : : /* 1 bit: 0: IPv4, 1: IPv6. */
922 : 0 : rx_hash_field_select->l3_prot_type =
923 : 0 : !!(hash_fields & MLX5_IPV6_IBV_RX_HASH);
924 : : /* 1 bit: 0: TCP, 1: UDP. */
925 : 0 : rx_hash_field_select->l4_prot_type =
926 : 0 : !!(hash_fields & MLX5_UDP_IBV_RX_HASH);
927 : : /* Bitmask which sets which fields to use in RX Hash. */
928 : 0 : rx_hash_field_select->selected_fields =
929 : 0 : ((!!(hash_fields & MLX5_L3_SRC_IBV_RX_HASH)) <<
930 : 0 : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_SRC_IP) |
931 [ # # ]: 0 : (!!(hash_fields & MLX5_L3_DST_IBV_RX_HASH)) <<
932 : 0 : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_DST_IP |
933 [ # # ]: 0 : (!!(hash_fields & MLX5_L4_SRC_IBV_RX_HASH)) <<
934 : 0 : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_SPORT |
935 [ # # ]: 0 : (!!(hash_fields & MLX5_L4_DST_IBV_RX_HASH)) <<
936 : 0 : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_DPORT |
937 : 0 : (!!(hash_fields & IBV_RX_HASH_IPSEC_SPI)) <<
938 : : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_IPSEC_SPI;
939 : : }
940 [ # # ]: 0 : if (is_hairpin)
941 : 0 : tir_attr->transport_domain = priv->sh->td->id;
942 : : else
943 : 0 : tir_attr->transport_domain = priv->sh->tdn;
944 [ # # ]: 0 : memcpy(tir_attr->rx_hash_toeplitz_key, rss_key, MLX5_RSS_HASH_KEY_LEN);
945 : 0 : tir_attr->indirect_table = ind_tbl->rqt->id;
946 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode)
947 : 0 : tir_attr->self_lb_block = MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST;
948 [ # # ]: 0 : if (lro) {
949 : : MLX5_ASSERT(priv->sh->config.lro_allowed);
950 : 0 : tir_attr->lro_timeout_period_usecs = priv->config.lro_timeout;
951 : 0 : tir_attr->lro_max_msg_sz =
952 : 0 : priv->max_lro_msg_size / MLX5_LRO_SEG_CHUNK_SIZE;
953 : 0 : tir_attr->lro_enable_mask =
954 : : MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
955 : : MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO;
956 : : }
957 : 0 : }
958 : :
959 : : /**
960 : : * Create an Rx Hash queue.
961 : : *
962 : : * @param dev
963 : : * Pointer to Ethernet device.
964 : : * @param hrxq
965 : : * Pointer to Rx Hash queue.
966 : : * @param tunnel
967 : : * Tunnel type.
968 : : *
969 : : * @return
970 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
971 : : */
972 : : static int
973 : 0 : mlx5_devx_hrxq_new(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
974 : : int tunnel __rte_unused)
975 : : {
976 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
977 : 0 : struct mlx5_devx_tir_attr tir_attr = {0};
978 : : int err;
979 : :
980 : 0 : mlx5_devx_tir_attr_set(dev, hrxq->rss_key, hrxq->hash_fields,
981 : 0 : hrxq->ind_table, tunnel, hrxq->symmetric_hash_function,
982 : : &tir_attr);
983 : 0 : hrxq->tir = mlx5_devx_cmd_create_tir(priv->sh->cdev->ctx, &tir_attr);
984 [ # # ]: 0 : if (!hrxq->tir) {
985 : 0 : DRV_LOG(ERR, "Port %u cannot create DevX TIR.",
986 : : dev->data->port_id);
987 : 0 : rte_errno = errno;
988 : 0 : goto error;
989 : : }
990 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
991 : : #ifdef HAVE_MLX5_HWS_SUPPORT
992 [ # # ]: 0 : if (hrxq->hws_flags) {
993 : 0 : hrxq->action = mlx5dr_action_create_dest_tir
994 : : (priv->dr_ctx,
995 : : (struct mlx5dr_devx_obj *)hrxq->tir, hrxq->hws_flags, true);
996 [ # # ]: 0 : if (!hrxq->action)
997 : 0 : goto error;
998 : : return 0;
999 : : }
1000 : : #endif
1001 : : if (mlx5_flow_os_create_flow_action_dest_devx_tir(hrxq->tir,
1002 : : &hrxq->action)) {
1003 : 0 : rte_errno = errno;
1004 : 0 : goto error;
1005 : : }
1006 : : #endif
1007 : : return 0;
1008 : 0 : error:
1009 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
1010 [ # # ]: 0 : if (hrxq->tir)
1011 : 0 : claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
1012 : 0 : rte_errno = err; /* Restore rte_errno. */
1013 : 0 : return -rte_errno;
1014 : : }
1015 : :
1016 : : /**
1017 : : * Destroy a DevX TIR object.
1018 : : *
1019 : : * @param hrxq
1020 : : * Hash Rx queue to release its tir.
1021 : : */
1022 : : static void
1023 : 0 : mlx5_devx_tir_destroy(struct mlx5_hrxq *hrxq)
1024 : : {
1025 : 0 : claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
1026 : 0 : }
1027 : :
1028 : : /**
1029 : : * Modify an Rx Hash queue configuration.
1030 : : *
1031 : : * @param dev
1032 : : * Pointer to Ethernet device.
1033 : : * @param hrxq
1034 : : * Hash Rx queue to modify.
1035 : : * @param rss_key
1036 : : * RSS key for the Rx hash queue.
1037 : : * @param hash_fields
1038 : : * Verbs protocol hash field to make the RSS on.
1039 : : * @param[in] ind_tbl
1040 : : * Indirection table for TIR.
1041 : : *
1042 : : * @return
1043 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1044 : : */
1045 : : static int
1046 : 0 : mlx5_devx_hrxq_modify(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
1047 : : const uint8_t *rss_key,
1048 : : uint64_t hash_fields,
1049 : : bool symmetric_hash_function,
1050 : : const struct mlx5_ind_table_obj *ind_tbl)
1051 : : {
1052 : 0 : struct mlx5_devx_modify_tir_attr modify_tir = {0};
1053 : :
1054 : : /*
1055 : : * untested for modification fields:
1056 : : * - rx_hash_fn set hard-coded in hrxq_new(),
1057 : : * - lro_xxx not set after rxq setup
1058 : : */
1059 [ # # ]: 0 : if (ind_tbl != hrxq->ind_table)
1060 : 0 : modify_tir.modify_bitmask |=
1061 : : MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_INDIRECT_TABLE;
1062 [ # # ]: 0 : if (hash_fields != hrxq->hash_fields ||
1063 [ # # ]: 0 : symmetric_hash_function != hrxq->symmetric_hash_function ||
1064 [ # # ]: 0 : memcmp(hrxq->rss_key, rss_key, MLX5_RSS_HASH_KEY_LEN))
1065 : 0 : modify_tir.modify_bitmask |=
1066 : : MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_HASH;
1067 : 0 : mlx5_devx_tir_attr_set(dev, rss_key, hash_fields, ind_tbl,
1068 : : 0, /* N/A - tunnel modification unsupported */
1069 : : symmetric_hash_function,
1070 : : &modify_tir.tir);
1071 : 0 : modify_tir.tirn = hrxq->tir->id;
1072 [ # # ]: 0 : if (mlx5_devx_cmd_modify_tir(hrxq->tir, &modify_tir)) {
1073 : 0 : DRV_LOG(ERR, "port %u cannot modify DevX TIR",
1074 : : dev->data->port_id);
1075 : 0 : rte_errno = errno;
1076 : 0 : return -rte_errno;
1077 : : }
1078 : : return 0;
1079 : : }
1080 : :
1081 : : /**
1082 : : * Create a DevX drop Rx queue.
1083 : : *
1084 : : * @param dev
1085 : : * Pointer to Ethernet device.
1086 : : *
1087 : : * @return
1088 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1089 : : */
1090 : : static int
1091 : 0 : mlx5_rxq_devx_obj_drop_create(struct rte_eth_dev *dev)
1092 : : {
1093 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1094 : 0 : int socket_id = dev->device->numa_node;
1095 : : struct mlx5_rxq_priv *rxq;
1096 : : struct mlx5_rxq_ctrl *rxq_ctrl = NULL;
1097 : : struct mlx5_rxq_obj *rxq_obj = NULL;
1098 : : int ret;
1099 : :
1100 : : /*
1101 : : * Initialize dummy control structures.
1102 : : * They are required to hold pointers for cleanup
1103 : : * and are only accessible via drop queue DevX objects.
1104 : : */
1105 [ # # # # ]: 0 : rxq = mlx5_malloc_numa_tolerant(MLX5_MEM_ZERO, sizeof(*rxq), 0, socket_id);
1106 [ # # ]: 0 : if (rxq == NULL) {
1107 : 0 : DRV_LOG(ERR, "Port %u could not allocate drop queue private",
1108 : : dev->data->port_id);
1109 : 0 : rte_errno = ENOMEM;
1110 : 0 : goto error;
1111 : : }
1112 [ # # # # ]: 0 : rxq_ctrl = mlx5_malloc_numa_tolerant(MLX5_MEM_ZERO, sizeof(*rxq_ctrl),
1113 : : 0, socket_id);
1114 [ # # ]: 0 : if (rxq_ctrl == NULL) {
1115 : 0 : DRV_LOG(ERR, "Port %u could not allocate drop queue control",
1116 : : dev->data->port_id);
1117 : 0 : rte_errno = ENOMEM;
1118 : 0 : goto error;
1119 : : }
1120 [ # # # # ]: 0 : rxq_obj = mlx5_malloc_numa_tolerant(MLX5_MEM_ZERO, sizeof(*rxq_obj), 0, socket_id);
1121 [ # # ]: 0 : if (rxq_obj == NULL) {
1122 : 0 : DRV_LOG(ERR, "Port %u could not allocate drop queue object",
1123 : : dev->data->port_id);
1124 : 0 : rte_errno = ENOMEM;
1125 : 0 : goto error;
1126 : : }
1127 : : /* set the CPU socket ID where the rxq_ctrl was allocated */
1128 : 0 : rxq_ctrl->socket = socket_id;
1129 : 0 : rxq_obj->rxq_ctrl = rxq_ctrl;
1130 : 0 : rxq_ctrl->is_hairpin = false;
1131 : 0 : rxq_ctrl->sh = priv->sh;
1132 : 0 : rxq_ctrl->obj = rxq_obj;
1133 : 0 : rxq->ctrl = rxq_ctrl;
1134 : 0 : rxq->priv = priv;
1135 [ # # ]: 0 : LIST_INSERT_HEAD(&rxq_ctrl->owners, rxq, owner_entry);
1136 : : /* Create CQ using DevX API. */
1137 : 0 : ret = mlx5_rxq_create_devx_cq_resources(rxq);
1138 [ # # ]: 0 : if (ret != 0) {
1139 : 0 : DRV_LOG(ERR, "Port %u drop queue CQ creation failed.",
1140 : : dev->data->port_id);
1141 : 0 : goto error;
1142 : : }
1143 : 0 : rxq_ctrl->rxq.delay_drop = 0;
1144 : : /* Create RQ using DevX API. */
1145 : 0 : ret = mlx5_rxq_create_devx_rq_resources(rxq);
1146 [ # # ]: 0 : if (ret != 0) {
1147 : 0 : DRV_LOG(ERR, "Port %u drop queue RQ creation failed.",
1148 : : dev->data->port_id);
1149 : 0 : rte_errno = ENOMEM;
1150 : 0 : goto error;
1151 : : }
1152 : : /* Change queue state to ready. */
1153 : 0 : ret = mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RST2RDY);
1154 [ # # ]: 0 : if (ret != 0)
1155 : 0 : goto error;
1156 : : /* Initialize drop queue. */
1157 : 0 : priv->drop_queue.rxq = rxq;
1158 : 0 : return 0;
1159 : 0 : error:
1160 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
1161 [ # # # # ]: 0 : if (rxq != NULL && rxq->devx_rq.rq != NULL)
1162 : 0 : mlx5_devx_rq_destroy(&rxq->devx_rq);
1163 [ # # ]: 0 : if (rxq_obj != NULL) {
1164 [ # # ]: 0 : if (rxq_obj->cq_obj.cq != NULL)
1165 : 0 : mlx5_devx_cq_destroy(&rxq_obj->cq_obj);
1166 [ # # ]: 0 : if (rxq_obj->devx_channel)
1167 : : mlx5_os_devx_destroy_event_channel
1168 : : (rxq_obj->devx_channel);
1169 : 0 : mlx5_free(rxq_obj);
1170 : : }
1171 [ # # ]: 0 : if (rxq_ctrl != NULL)
1172 : 0 : mlx5_free(rxq_ctrl);
1173 [ # # ]: 0 : if (rxq != NULL)
1174 : 0 : mlx5_free(rxq);
1175 : 0 : rte_errno = ret; /* Restore rte_errno. */
1176 : 0 : return -rte_errno;
1177 : : }
1178 : :
1179 : : /**
1180 : : * Release drop Rx queue resources.
1181 : : *
1182 : : * @param dev
1183 : : * Pointer to Ethernet device.
1184 : : */
1185 : : static void
1186 : 0 : mlx5_rxq_devx_obj_drop_release(struct rte_eth_dev *dev)
1187 : : {
1188 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1189 : 0 : struct mlx5_rxq_priv *rxq = priv->drop_queue.rxq;
1190 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
1191 : :
1192 : 0 : mlx5_rxq_devx_obj_release(rxq);
1193 : 0 : mlx5_free(rxq_ctrl->obj);
1194 : 0 : mlx5_free(rxq_ctrl);
1195 : 0 : mlx5_free(rxq);
1196 : 0 : priv->drop_queue.rxq = NULL;
1197 : 0 : }
1198 : :
1199 : : /**
1200 : : * Release a drop hash Rx queue.
1201 : : *
1202 : : * @param dev
1203 : : * Pointer to Ethernet device.
1204 : : */
1205 : : static void
1206 : 0 : mlx5_devx_drop_action_destroy(struct rte_eth_dev *dev)
1207 : : {
1208 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1209 : 0 : struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq;
1210 : :
1211 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
1212 [ # # ]: 0 : if (hrxq->action != NULL)
1213 : : mlx5_flow_os_destroy_flow_action(hrxq->action);
1214 : : #endif
1215 [ # # ]: 0 : if (hrxq->tir != NULL)
1216 : : mlx5_devx_tir_destroy(hrxq);
1217 [ # # ]: 0 : if (hrxq->ind_table->ind_table != NULL)
1218 : : mlx5_devx_ind_table_destroy(hrxq->ind_table);
1219 [ # # ]: 0 : if (priv->drop_queue.rxq->devx_rq.rq != NULL)
1220 : 0 : mlx5_rxq_devx_obj_drop_release(dev);
1221 : 0 : }
1222 : :
1223 : : /**
1224 : : * Create a DevX drop action for Rx Hash queue.
1225 : : *
1226 : : * @param dev
1227 : : * Pointer to Ethernet device.
1228 : : *
1229 : : * @return
1230 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1231 : : */
1232 : : static int
1233 : 0 : mlx5_devx_drop_action_create(struct rte_eth_dev *dev)
1234 : : {
1235 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1236 : 0 : struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq;
1237 : : int ret;
1238 : :
1239 : 0 : ret = mlx5_rxq_devx_obj_drop_create(dev);
1240 [ # # ]: 0 : if (ret != 0) {
1241 : 0 : DRV_LOG(ERR, "Cannot create drop RX queue");
1242 : 0 : return ret;
1243 : : }
1244 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1245 : : return 0;
1246 : : /* hrxq->ind_table queues are NULL, drop RX queue ID will be used */
1247 : 0 : ret = mlx5_devx_ind_table_new(dev, 0, hrxq->ind_table);
1248 [ # # ]: 0 : if (ret != 0) {
1249 : 0 : DRV_LOG(ERR, "Cannot create drop hash RX queue indirection table");
1250 : 0 : goto error;
1251 : : }
1252 : 0 : ret = mlx5_devx_hrxq_new(dev, hrxq, /* tunnel */ false);
1253 [ # # ]: 0 : if (ret != 0) {
1254 : 0 : DRV_LOG(ERR, "Cannot create drop hash RX queue");
1255 : 0 : goto error;
1256 : : }
1257 : : return 0;
1258 : 0 : error:
1259 : 0 : mlx5_devx_drop_action_destroy(dev);
1260 : 0 : return ret;
1261 : : }
1262 : :
1263 : : /**
1264 : : * Select TXQ TIS number.
1265 : : *
1266 : : * @param dev
1267 : : * Pointer to Ethernet device.
1268 : : * @param queue_idx
1269 : : * Queue index in DPDK Tx queue array.
1270 : : *
1271 : : * @return
1272 : : * > 0 on success, a negative errno value otherwise.
1273 : : */
1274 : : static uint32_t
1275 : 0 : mlx5_get_txq_tis_num(struct rte_eth_dev *dev, uint16_t queue_idx)
1276 : : {
1277 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1278 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[queue_idx];
1279 : : int tis_idx = 0;
1280 : :
1281 [ # # ]: 0 : if (priv->sh->bond.n_port) {
1282 [ # # ]: 0 : if (txq_data->tx_aggr_affinity) {
1283 : 0 : tis_idx = txq_data->tx_aggr_affinity;
1284 [ # # ]: 0 : } else if (priv->sh->lag.affinity_mode == MLX5_LAG_MODE_TIS) {
1285 : 0 : tis_idx = (priv->lag_affinity_idx + queue_idx) %
1286 : 0 : priv->sh->bond.n_port + 1;
1287 : 0 : DRV_LOG(INFO, "port %d txq %d gets affinity %d and maps to PF %d.",
1288 : : dev->data->port_id, queue_idx, tis_idx,
1289 : : priv->sh->lag.tx_remap_affinity[tis_idx - 1]);
1290 : : }
1291 : : }
1292 : : MLX5_ASSERT(priv->sh->tis[tis_idx]);
1293 : 0 : return priv->sh->tis[tis_idx]->id;
1294 : : }
1295 : :
1296 : : /**
1297 : : * Create the Tx hairpin queue object.
1298 : : *
1299 : : * @param dev
1300 : : * Pointer to Ethernet device.
1301 : : * @param idx
1302 : : * Queue index in DPDK Tx queue array.
1303 : : *
1304 : : * @return
1305 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1306 : : */
1307 : : static int
1308 : 0 : mlx5_txq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx)
1309 : : {
1310 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1311 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
1312 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1313 : : struct mlx5_txq_ctrl *txq_ctrl =
1314 : 0 : container_of(txq_data, struct mlx5_txq_ctrl, txq);
1315 : 0 : struct mlx5_devx_create_sq_attr dev_mem_attr = { 0 };
1316 : 0 : struct mlx5_devx_create_sq_attr host_mem_attr = { 0 };
1317 : 0 : struct mlx5_txq_obj *tmpl = txq_ctrl->obj;
1318 : : void *umem_buf = NULL;
1319 : : void *umem_obj = NULL;
1320 : : uint32_t max_wq_data;
1321 : :
1322 : : MLX5_ASSERT(txq_data);
1323 : : MLX5_ASSERT(tmpl);
1324 : 0 : tmpl->txq_ctrl = txq_ctrl;
1325 : 0 : dev_mem_attr.hairpin = 1;
1326 : 0 : dev_mem_attr.tis_lst_sz = 1;
1327 : 0 : dev_mem_attr.tis_num = mlx5_get_txq_tis_num(dev, idx);
1328 : 0 : max_wq_data =
1329 : 0 : priv->sh->cdev->config.hca_attr.log_max_hairpin_wq_data_sz;
1330 : : /* Jumbo frames > 9KB should be supported, and more packets. */
1331 [ # # ]: 0 : if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) {
1332 [ # # ]: 0 : if (priv->config.log_hp_size > max_wq_data) {
1333 : 0 : DRV_LOG(ERR, "Total data size %u power of 2 is "
1334 : : "too large for hairpin.",
1335 : : priv->config.log_hp_size);
1336 : 0 : rte_errno = ERANGE;
1337 : 0 : return -rte_errno;
1338 : : }
1339 : 0 : dev_mem_attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size;
1340 : : } else {
1341 : 0 : dev_mem_attr.wq_attr.log_hairpin_data_sz =
1342 : : (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ?
1343 : 0 : max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE;
1344 : : }
1345 : : /* Set the packets number to the maximum value for performance. */
1346 : 0 : dev_mem_attr.wq_attr.log_hairpin_num_packets =
1347 : 0 : dev_mem_attr.wq_attr.log_hairpin_data_sz -
1348 : : MLX5_HAIRPIN_QUEUE_STRIDE;
1349 : 0 : dev_mem_attr.hairpin_wq_buffer_type = MLX5_SQC_HAIRPIN_WQ_BUFFER_TYPE_INTERNAL_BUFFER;
1350 [ # # ]: 0 : if (txq_ctrl->hairpin_conf.use_rte_memory) {
1351 : : uint32_t umem_size;
1352 : : uint32_t umem_dbrec;
1353 : 0 : size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
1354 : :
1355 [ # # ]: 0 : if (alignment == (size_t)-1) {
1356 : 0 : DRV_LOG(ERR, "Failed to get WQE buf alignment.");
1357 : 0 : rte_errno = ENOMEM;
1358 : 0 : return -rte_errno;
1359 : : }
1360 : : /*
1361 : : * It is assumed that configuration is verified against capabilities
1362 : : * during queue setup.
1363 : : */
1364 : : MLX5_ASSERT(hca_attr->hairpin_sq_wq_in_host_mem);
1365 : : MLX5_ASSERT(hca_attr->hairpin_sq_wqe_bb_size > 0);
1366 : : rte_memcpy(&host_mem_attr, &dev_mem_attr, sizeof(host_mem_attr));
1367 : 0 : umem_size = MLX5_WQE_SIZE *
1368 : 0 : (size_t)RTE_BIT32(host_mem_attr.wq_attr.log_hairpin_num_packets);
1369 : 0 : umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE);
1370 : 0 : umem_size += MLX5_DBR_SIZE;
1371 : 0 : umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size,
1372 : 0 : alignment, priv->sh->numa_node);
1373 [ # # # # ]: 0 : if (umem_buf == NULL && txq_ctrl->hairpin_conf.force_memory) {
1374 : 0 : DRV_LOG(ERR, "Failed to allocate memory for hairpin TX queue");
1375 : 0 : rte_errno = ENOMEM;
1376 : 0 : return -rte_errno;
1377 [ # # # # ]: 0 : } else if (umem_buf == NULL && !txq_ctrl->hairpin_conf.force_memory) {
1378 : 0 : DRV_LOG(WARNING, "Failed to allocate memory for hairpin TX queue."
1379 : : " Falling back to TX queue located on the device.");
1380 : 0 : goto create_sq_on_device;
1381 : : }
1382 : 0 : umem_obj = mlx5_os_umem_reg(priv->sh->cdev->ctx,
1383 : : (void *)(uintptr_t)umem_buf,
1384 : : umem_size,
1385 : : IBV_ACCESS_LOCAL_WRITE);
1386 [ # # # # ]: 0 : if (umem_obj == NULL && txq_ctrl->hairpin_conf.force_memory) {
1387 : 0 : DRV_LOG(ERR, "Failed to register UMEM for hairpin TX queue");
1388 : 0 : mlx5_free(umem_buf);
1389 : 0 : return -rte_errno;
1390 [ # # # # ]: 0 : } else if (umem_obj == NULL && !txq_ctrl->hairpin_conf.force_memory) {
1391 : 0 : DRV_LOG(WARNING, "Failed to register UMEM for hairpin TX queue."
1392 : : " Falling back to TX queue located on the device.");
1393 : 0 : rte_errno = 0;
1394 : 0 : mlx5_free(umem_buf);
1395 : 0 : goto create_sq_on_device;
1396 : : }
1397 : 0 : host_mem_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
1398 [ # # ]: 0 : host_mem_attr.wq_attr.wq_umem_valid = 1;
1399 : 0 : host_mem_attr.wq_attr.wq_umem_id = mlx5_os_get_umem_id(umem_obj);
1400 : 0 : host_mem_attr.wq_attr.wq_umem_offset = 0;
1401 : 0 : host_mem_attr.wq_attr.dbr_umem_valid = 1;
1402 : 0 : host_mem_attr.wq_attr.dbr_umem_id = host_mem_attr.wq_attr.wq_umem_id;
1403 : 0 : host_mem_attr.wq_attr.dbr_addr = umem_dbrec;
1404 : 0 : host_mem_attr.wq_attr.log_wq_stride = rte_log2_u32(MLX5_WQE_SIZE);
1405 : 0 : host_mem_attr.wq_attr.log_wq_sz =
1406 : 0 : host_mem_attr.wq_attr.log_hairpin_num_packets *
1407 : 0 : hca_attr->hairpin_sq_wqe_bb_size;
1408 : 0 : host_mem_attr.wq_attr.log_wq_pg_sz = MLX5_LOG_PAGE_SIZE;
1409 : 0 : host_mem_attr.hairpin_wq_buffer_type = MLX5_SQC_HAIRPIN_WQ_BUFFER_TYPE_HOST_MEMORY;
1410 : 0 : tmpl->sq = mlx5_devx_cmd_create_sq(priv->sh->cdev->ctx, &host_mem_attr);
1411 [ # # # # ]: 0 : if (!tmpl->sq && txq_ctrl->hairpin_conf.force_memory) {
1412 : 0 : DRV_LOG(ERR,
1413 : : "Port %u tx hairpin queue %u can't create SQ object.",
1414 : : dev->data->port_id, idx);
1415 : : claim_zero(mlx5_os_umem_dereg(umem_obj));
1416 : 0 : mlx5_free(umem_buf);
1417 : 0 : return -rte_errno;
1418 [ # # # # ]: 0 : } else if (!tmpl->sq && !txq_ctrl->hairpin_conf.force_memory) {
1419 : 0 : DRV_LOG(WARNING,
1420 : : "Port %u tx hairpin queue %u failed to allocate SQ object"
1421 : : " using host memory. Falling back to TX queue located"
1422 : : " on the device",
1423 : : dev->data->port_id, idx);
1424 : 0 : rte_errno = 0;
1425 : : claim_zero(mlx5_os_umem_dereg(umem_obj));
1426 : 0 : mlx5_free(umem_buf);
1427 : 0 : goto create_sq_on_device;
1428 : : }
1429 : 0 : tmpl->umem_buf_wq_buffer = umem_buf;
1430 : 0 : tmpl->umem_obj_wq_buffer = umem_obj;
1431 : 0 : return 0;
1432 : : }
1433 : :
1434 : 0 : create_sq_on_device:
1435 : 0 : tmpl->sq = mlx5_devx_cmd_create_sq(priv->sh->cdev->ctx, &dev_mem_attr);
1436 [ # # ]: 0 : if (!tmpl->sq) {
1437 : 0 : DRV_LOG(ERR,
1438 : : "Port %u tx hairpin queue %u can't create SQ object.",
1439 : : dev->data->port_id, idx);
1440 : 0 : rte_errno = errno;
1441 : 0 : return -rte_errno;
1442 : : }
1443 : : return 0;
1444 : : }
1445 : :
1446 : : #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H)
1447 : : /**
1448 : : * Destroy the Tx queue DevX object.
1449 : : *
1450 : : * @param txq_obj
1451 : : * Txq object to destroy.
1452 : : */
1453 : : static void
1454 : 0 : mlx5_txq_release_devx_resources(struct mlx5_txq_obj *txq_obj)
1455 : : {
1456 : 0 : mlx5_devx_sq_destroy(&txq_obj->sq_obj);
1457 : : memset(&txq_obj->sq_obj, 0, sizeof(txq_obj->sq_obj));
1458 : 0 : mlx5_devx_cq_destroy(&txq_obj->cq_obj);
1459 : : memset(&txq_obj->cq_obj, 0, sizeof(txq_obj->cq_obj));
1460 : 0 : }
1461 : :
1462 : : /**
1463 : : * Create a SQ object and its resources using DevX.
1464 : : *
1465 : : * @param dev
1466 : : * Pointer to Ethernet device.
1467 : : * @param idx
1468 : : * Queue index in DPDK Tx queue array.
1469 : : * @param[in] log_desc_n
1470 : : * Log of number of descriptors in queue.
1471 : : *
1472 : : * @return
1473 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1474 : : */
1475 : : static int
1476 : 0 : mlx5_txq_create_devx_sq_resources(struct rte_eth_dev *dev, uint16_t idx,
1477 : : uint16_t log_desc_n)
1478 : : {
1479 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1480 : 0 : struct mlx5_common_device *cdev = priv->sh->cdev;
1481 : : struct mlx5_uar *uar = &priv->sh->tx_uar;
1482 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1483 : : struct mlx5_txq_ctrl *txq_ctrl =
1484 : 0 : container_of(txq_data, struct mlx5_txq_ctrl, txq);
1485 : 0 : struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
1486 : 0 : struct mlx5_devx_create_sq_attr sq_attr = {
1487 : : .flush_in_error_en = 1,
1488 : 0 : .allow_multi_pkt_send_wqe = !!priv->config.mps,
1489 : 0 : .min_wqe_inline_mode = cdev->config.hca_attr.vport_inline_mode,
1490 : 0 : .allow_swp = !!priv->sh->dev_cap.swp,
1491 : 0 : .cqn = txq_obj->cq_obj.cq->id,
1492 : : .tis_lst_sz = 1,
1493 : : .wq_attr = (struct mlx5_devx_wq_attr){
1494 : 0 : .pd = cdev->pdn,
1495 : 0 : .uar_page = mlx5_os_get_devx_uar_page_id(uar->obj),
1496 : : },
1497 : : .ts_format =
1498 : 0 : mlx5_ts_format_conv(cdev->config.hca_attr.sq_ts_format),
1499 [ # # ]: 0 : .tis_num = mlx5_get_txq_tis_num(dev, idx),
1500 : : };
1501 : 0 : uint32_t db_start = priv->consec_tx_mem.sq_total_size + priv->consec_tx_mem.cq_total_size;
1502 : : int ret;
1503 : :
1504 : : /* Create Send Queue object with DevX. */
1505 [ # # ]: 0 : if (priv->sh->config.txq_mem_algn) {
1506 : 0 : sq_attr.umem = priv->consec_tx_mem.umem;
1507 : 0 : sq_attr.umem_obj = priv->consec_tx_mem.umem_obj;
1508 : 0 : sq_attr.q_off = priv->consec_tx_mem.sq_cur_off;
1509 : 0 : sq_attr.db_off = db_start + (2 * idx) * MLX5_DBR_SIZE;
1510 : 0 : sq_attr.q_len = txq_data->sq_mem_len;
1511 : : }
1512 : 0 : ret = mlx5_devx_sq_create(cdev->ctx, &txq_obj->sq_obj,
1513 : : log_desc_n, &sq_attr, priv->sh->numa_node);
1514 [ # # # # ]: 0 : if (!ret && priv->sh->config.txq_mem_algn)
1515 : 0 : priv->consec_tx_mem.sq_cur_off += txq_data->sq_mem_len;
1516 : 0 : return ret;
1517 : : }
1518 : : #endif
1519 : :
1520 : : /**
1521 : : * Create the Tx queue DevX object.
1522 : : *
1523 : : * @param dev
1524 : : * Pointer to Ethernet device.
1525 : : * @param idx
1526 : : * Queue index in DPDK Tx queue array.
1527 : : *
1528 : : * @return
1529 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1530 : : */
1531 : : int
1532 : 0 : mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx)
1533 : : {
1534 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1535 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1536 : : struct mlx5_txq_ctrl *txq_ctrl =
1537 : 0 : container_of(txq_data, struct mlx5_txq_ctrl, txq);
1538 : :
1539 [ # # ]: 0 : if (txq_ctrl->is_hairpin)
1540 : 0 : return mlx5_txq_obj_hairpin_new(dev, idx);
1541 : : #if !defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) && defined(HAVE_INFINIBAND_VERBS_H)
1542 : : DRV_LOG(ERR, "Port %u Tx queue %u cannot create with DevX, no UAR.",
1543 : : dev->data->port_id, idx);
1544 : : rte_errno = ENOMEM;
1545 : : return -rte_errno;
1546 : : #else
1547 : 0 : struct mlx5_proc_priv *ppriv = MLX5_PROC_PRIV(PORT_ID(priv));
1548 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
1549 : 0 : struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
1550 : 0 : struct mlx5_devx_cq_attr cq_attr = {
1551 [ # # ]: 0 : .uar_page_id = mlx5_os_get_devx_uar_page_id(sh->tx_uar.obj),
1552 : : };
1553 : : uint32_t cqe_n, log_desc_n;
1554 : : uint32_t wqe_n, wqe_size;
1555 : : int ret = 0;
1556 : 0 : uint32_t db_start = priv->consec_tx_mem.sq_total_size + priv->consec_tx_mem.cq_total_size;
1557 : :
1558 : : MLX5_ASSERT(txq_data);
1559 : : MLX5_ASSERT(txq_obj);
1560 : : MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
1561 : : MLX5_ASSERT(ppriv);
1562 : 0 : txq_obj->txq_ctrl = txq_ctrl;
1563 : 0 : txq_obj->dev = dev;
1564 : : if (__rte_trace_point_fp_is_enabled() &&
1565 : : txq_data->offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP)
1566 : : cqe_n = UINT16_MAX / 2 - 1;
1567 : : else
1568 : 0 : cqe_n = (1UL << txq_data->elts_n) / MLX5_TX_COMP_THRESH +
1569 : 0 : 1 + MLX5_TX_COMP_THRESH_INLINE_DIV;
1570 : : log_desc_n = log2above(cqe_n);
1571 : 0 : cqe_n = 1UL << log_desc_n;
1572 [ # # ]: 0 : if (cqe_n > UINT16_MAX) {
1573 : 0 : DRV_LOG(ERR, "Port %u Tx queue %u requests to many CQEs %u.",
1574 : : dev->data->port_id, txq_data->idx, cqe_n);
1575 : 0 : rte_errno = EINVAL;
1576 : 0 : return 0;
1577 : : }
1578 [ # # ]: 0 : if (priv->sh->config.txq_mem_algn) {
1579 : 0 : cq_attr.umem = priv->consec_tx_mem.umem;
1580 : 0 : cq_attr.umem_obj = priv->consec_tx_mem.umem_obj;
1581 : 0 : cq_attr.q_off = priv->consec_tx_mem.cq_cur_off;
1582 : 0 : cq_attr.db_off = db_start + (2 * idx + 1) * MLX5_DBR_SIZE;
1583 : 0 : cq_attr.q_len = txq_data->cq_mem_len;
1584 : : }
1585 : : /* Create completion queue object with DevX. */
1586 : 0 : ret = mlx5_devx_cq_create(sh->cdev->ctx, &txq_obj->cq_obj, log_desc_n,
1587 : : &cq_attr, priv->sh->numa_node);
1588 [ # # ]: 0 : if (ret) {
1589 : 0 : DRV_LOG(ERR, "Port %u Tx queue %u CQ creation failure.",
1590 : : dev->data->port_id, idx);
1591 : 0 : goto error;
1592 : : }
1593 : 0 : txq_data->cqe_n = log_desc_n;
1594 : 0 : txq_data->cqe_s = cqe_n;
1595 : 0 : txq_data->cqe_m = txq_data->cqe_s - 1;
1596 : 0 : txq_data->cqes = txq_obj->cq_obj.cqes;
1597 : 0 : txq_data->cq_ci = 0;
1598 : 0 : txq_data->cq_pi = 0;
1599 : 0 : txq_data->cq_db = txq_obj->cq_obj.db_rec;
1600 : 0 : *txq_data->cq_db = 0;
1601 : : /*
1602 : : * Adjust the amount of WQEs depending on inline settings.
1603 : : * The number of descriptors should be enough to handle
1604 : : * the specified number of packets. If queue is being created
1605 : : * with Verbs the rdma-core does queue size adjustment
1606 : : * internally in the mlx5_calc_sq_size(), we do the same
1607 : : * for the queue being created with DevX at this point.
1608 : : */
1609 : 0 : wqe_size = txq_data->tso_en ?
1610 [ # # ]: 0 : RTE_ALIGN(txq_ctrl->max_tso_header, MLX5_WSEG_SIZE) : 0;
1611 : 0 : wqe_size += sizeof(struct mlx5_wqe_cseg) +
1612 : : sizeof(struct mlx5_wqe_eseg) +
1613 : : sizeof(struct mlx5_wqe_dseg);
1614 [ # # ]: 0 : if (txq_data->inlen_send)
1615 : 0 : wqe_size = RTE_MAX(wqe_size, sizeof(struct mlx5_wqe_cseg) +
1616 : : sizeof(struct mlx5_wqe_eseg) +
1617 : : RTE_ALIGN(txq_data->inlen_send +
1618 : : sizeof(uint32_t),
1619 : : MLX5_WSEG_SIZE));
1620 : 0 : wqe_size = RTE_ALIGN(wqe_size, MLX5_WQE_SIZE) / MLX5_WQE_SIZE;
1621 : : /* Create Send Queue object with DevX. */
1622 : 0 : wqe_n = RTE_MIN((1UL << txq_data->elts_n) * wqe_size,
1623 : : (uint32_t)mlx5_dev_get_max_wq_size(priv->sh));
1624 : : log_desc_n = log2above(wqe_n);
1625 : 0 : ret = mlx5_txq_create_devx_sq_resources(dev, idx, log_desc_n);
1626 [ # # ]: 0 : if (ret) {
1627 : 0 : DRV_LOG(ERR, "Port %u Tx queue %u SQ creation failure.",
1628 : : dev->data->port_id, idx);
1629 : 0 : rte_errno = errno;
1630 : 0 : goto error;
1631 : : }
1632 : : /* Create the Work Queue. */
1633 : 0 : txq_data->wqe_n = log_desc_n;
1634 : 0 : txq_data->wqe_s = 1 << txq_data->wqe_n;
1635 : 0 : txq_data->wqe_m = txq_data->wqe_s - 1;
1636 : 0 : txq_data->wqes = (struct mlx5_wqe *)(uintptr_t)txq_obj->sq_obj.wqes;
1637 : 0 : txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s;
1638 : 0 : txq_data->wqe_ci = 0;
1639 : 0 : txq_data->wqe_pi = 0;
1640 : 0 : txq_data->wqe_comp = 0;
1641 : 0 : txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV;
1642 : 0 : txq_data->qp_db = &txq_obj->sq_obj.db_rec[MLX5_SND_DBR];
1643 : 0 : *txq_data->qp_db = 0;
1644 : 0 : txq_data->qp_num_8s = txq_obj->sq_obj.sq->id << 8;
1645 : 0 : txq_data->db_heu = sh->cdev->config.dbnc == MLX5_SQ_DB_HEURISTIC;
1646 : 0 : txq_data->db_nc = sh->tx_uar.dbnc;
1647 [ # # # # ]: 0 : txq_data->wait_on_time = !!(!sh->config.tx_pp &&
1648 : : sh->cdev->config.hca_attr.wait_on_time);
1649 : : /* Change Send Queue state to Ready-to-Send. */
1650 : 0 : ret = mlx5_txq_devx_modify(txq_obj, MLX5_TXQ_MOD_RST2RDY, 0);
1651 [ # # ]: 0 : if (ret) {
1652 : 0 : rte_errno = errno;
1653 : 0 : DRV_LOG(ERR,
1654 : : "Port %u Tx queue %u SQ state to SQC_STATE_RDY failed.",
1655 : : dev->data->port_id, idx);
1656 : 0 : goto error;
1657 : : }
1658 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1659 : : /*
1660 : : * If using DevX need to query and store TIS transport domain value.
1661 : : * This is done once per port.
1662 : : * Will use this value on Rx, when creating matching TIR.
1663 : : */
1664 [ # # ]: 0 : if (!priv->sh->tdn)
1665 : 0 : priv->sh->tdn = priv->sh->td->id;
1666 : : #endif
1667 : 0 : txq_ctrl->uar_mmap_offset =
1668 [ # # ]: 0 : mlx5_os_get_devx_uar_mmap_offset(sh->tx_uar.obj);
1669 [ # # ]: 0 : if (priv->sh->config.txq_mem_algn)
1670 : 0 : priv->consec_tx_mem.cq_cur_off += txq_data->cq_mem_len;
1671 : 0 : ppriv->uar_table[txq_data->idx] = sh->tx_uar.bf_db;
1672 : 0 : dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
1673 : 0 : return 0;
1674 : 0 : error:
1675 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
1676 : 0 : mlx5_txq_release_devx_resources(txq_obj);
1677 : 0 : rte_errno = ret; /* Restore rte_errno. */
1678 : 0 : return -rte_errno;
1679 : : #endif
1680 : : }
1681 : :
1682 : : /**
1683 : : * Release an Tx DevX queue object.
1684 : : *
1685 : : * @param txq_obj
1686 : : * DevX Tx queue object.
1687 : : */
1688 : : void
1689 : 0 : mlx5_txq_devx_obj_release(struct mlx5_txq_obj *txq_obj)
1690 : : {
1691 : : MLX5_ASSERT(txq_obj);
1692 [ # # ]: 0 : if (txq_obj->txq_ctrl->is_hairpin) {
1693 [ # # ]: 0 : if (txq_obj->sq) {
1694 : 0 : claim_zero(mlx5_devx_cmd_destroy(txq_obj->sq));
1695 : 0 : txq_obj->sq = NULL;
1696 : : }
1697 [ # # ]: 0 : if (txq_obj->tis)
1698 : 0 : claim_zero(mlx5_devx_cmd_destroy(txq_obj->tis));
1699 [ # # ]: 0 : if (txq_obj->umem_obj_wq_buffer) {
1700 : : claim_zero(mlx5_os_umem_dereg(txq_obj->umem_obj_wq_buffer));
1701 : 0 : txq_obj->umem_obj_wq_buffer = NULL;
1702 : : }
1703 [ # # ]: 0 : if (txq_obj->umem_buf_wq_buffer) {
1704 : 0 : mlx5_free(txq_obj->umem_buf_wq_buffer);
1705 : 0 : txq_obj->umem_buf_wq_buffer = NULL;
1706 : : }
1707 : : #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H)
1708 : : } else {
1709 : 0 : mlx5_txq_release_devx_resources(txq_obj);
1710 : : #endif
1711 : : }
1712 : 0 : }
1713 : :
1714 : : struct mlx5_obj_ops devx_obj_ops = {
1715 : : .rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_rq_vlan_strip,
1716 : : .rxq_obj_modify_counter_set_id = mlx5_rxq_obj_modify_counter,
1717 : : .rxq_obj_new = mlx5_rxq_devx_obj_new,
1718 : : .rxq_event_get = mlx5_rx_devx_get_event,
1719 : : .rxq_obj_modify = mlx5_devx_modify_rq,
1720 : : .rxq_obj_release = mlx5_rxq_devx_obj_release,
1721 : : .rxq_event_get_lwm = mlx5_rx_devx_get_event_lwm,
1722 : : .ind_table_new = mlx5_devx_ind_table_new,
1723 : : .ind_table_modify = mlx5_devx_ind_table_modify,
1724 : : .ind_table_destroy = mlx5_devx_ind_table_destroy,
1725 : : .hrxq_new = mlx5_devx_hrxq_new,
1726 : : .hrxq_destroy = mlx5_devx_tir_destroy,
1727 : : .hrxq_modify = mlx5_devx_hrxq_modify,
1728 : : .drop_action_create = mlx5_devx_drop_action_create,
1729 : : .drop_action_destroy = mlx5_devx_drop_action_destroy,
1730 : : .txq_obj_new = mlx5_txq_devx_obj_new,
1731 : : .txq_obj_modify = mlx5_txq_devx_modify,
1732 : : .txq_obj_release = mlx5_txq_devx_obj_release,
1733 : : .lb_dummy_queue_create = NULL,
1734 : : .lb_dummy_queue_release = NULL,
1735 : : };
|