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 : mlx5_rxq_initialize(rxq_data);
687 : 0 : rxq_ctrl->wqn = rxq->devx_rq.rq->id;
688 : : }
689 : 0 : priv->dev_data->rx_queue_state[rxq->idx] = RTE_ETH_QUEUE_STATE_STARTED;
690 : 0 : return 0;
691 : 0 : error:
692 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
693 : 0 : mlx5_rxq_devx_obj_release(rxq);
694 : 0 : rte_errno = ret; /* Restore rte_errno. */
695 : 0 : return -rte_errno;
696 : : }
697 : :
698 : : /**
699 : : * Prepare RQT attribute structure for DevX RQT API.
700 : : *
701 : : * @param dev
702 : : * Pointer to Ethernet device.
703 : : * @param log_n
704 : : * Log of number of queues in the array.
705 : : * @param queues
706 : : * List of RX queue indices or NULL, in which case
707 : : * the attribute will be filled by drop queue ID.
708 : : * @param queues_n
709 : : * Size of @p queues array or 0 if it is NULL.
710 : : * @param ind_tbl
711 : : * DevX indirection table object.
712 : : *
713 : : * @return
714 : : * The RQT attr object initialized, NULL otherwise and rte_errno is set.
715 : : */
716 : : static struct mlx5_devx_rqt_attr *
717 : 0 : mlx5_devx_ind_table_create_rqt_attr(struct rte_eth_dev *dev,
718 : : const unsigned int log_n,
719 : : const uint16_t *queues,
720 : : const uint32_t queues_n)
721 : : {
722 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
723 : : struct mlx5_devx_rqt_attr *rqt_attr = NULL;
724 : 0 : const unsigned int rqt_n = 1 << log_n;
725 : : unsigned int i, j;
726 : :
727 : 0 : rqt_attr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt_attr) +
728 : : rqt_n * sizeof(uint32_t), 0, SOCKET_ID_ANY);
729 [ # # ]: 0 : if (!rqt_attr) {
730 : 0 : DRV_LOG(ERR, "Port %u cannot allocate RQT resources.",
731 : : dev->data->port_id);
732 : 0 : rte_errno = ENOMEM;
733 : 0 : return NULL;
734 : : }
735 : 0 : rqt_attr->rqt_max_size = priv->sh->dev_cap.ind_table_max_size;
736 : 0 : rqt_attr->rqt_actual_size = rqt_n;
737 [ # # ]: 0 : if (queues == NULL) {
738 [ # # ]: 0 : for (i = 0; i < rqt_n; i++)
739 : 0 : rqt_attr->rq_list[i] =
740 : 0 : priv->drop_queue.rxq->devx_rq.rq->id;
741 : : return rqt_attr;
742 : : }
743 [ # # ]: 0 : for (i = 0; i != queues_n; ++i) {
744 [ # # # # ]: 0 : if (mlx5_is_external_rxq(dev, queues[i])) {
745 : : struct mlx5_external_q *ext_rxq =
746 : 0 : mlx5_ext_rxq_get(dev, queues[i]);
747 : :
748 : 0 : rqt_attr->rq_list[i] = ext_rxq->hw_id;
749 : : } else {
750 : : struct mlx5_rxq_priv *rxq =
751 : 0 : mlx5_rxq_get(dev, queues[i]);
752 : :
753 : : MLX5_ASSERT(rxq != NULL);
754 [ # # ]: 0 : if (rxq->ctrl->is_hairpin)
755 : 0 : rqt_attr->rq_list[i] = rxq->ctrl->obj->rq->id;
756 : : else
757 : 0 : rqt_attr->rq_list[i] = rxq->devx_rq.rq->id;
758 : : }
759 : : }
760 : : MLX5_ASSERT(i > 0);
761 [ # # ]: 0 : for (j = 0; i != rqt_n; ++j, ++i)
762 : 0 : rqt_attr->rq_list[i] = rqt_attr->rq_list[j];
763 : : return rqt_attr;
764 : : }
765 : :
766 : : /**
767 : : * Create RQT using DevX API as a filed of indirection table.
768 : : *
769 : : * @param dev
770 : : * Pointer to Ethernet device.
771 : : * @param log_n
772 : : * Log of number of queues in the array.
773 : : * @param ind_tbl
774 : : * DevX indirection table object.
775 : : *
776 : : * @return
777 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
778 : : */
779 : : static int
780 : 0 : mlx5_devx_ind_table_new(struct rte_eth_dev *dev, const unsigned int log_n,
781 : : struct mlx5_ind_table_obj *ind_tbl)
782 : : {
783 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
784 : : struct mlx5_devx_rqt_attr *rqt_attr = NULL;
785 [ # # ]: 0 : const uint16_t *queues = dev->data->dev_started ? ind_tbl->queues :
786 : : NULL;
787 : :
788 : : MLX5_ASSERT(ind_tbl);
789 : 0 : rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n, queues,
790 : : ind_tbl->queues_n);
791 [ # # ]: 0 : if (!rqt_attr)
792 : 0 : return -rte_errno;
793 : 0 : ind_tbl->rqt = mlx5_devx_cmd_create_rqt(priv->sh->cdev->ctx, rqt_attr);
794 : 0 : mlx5_free(rqt_attr);
795 [ # # ]: 0 : if (!ind_tbl->rqt) {
796 : 0 : DRV_LOG(ERR, "Port %u cannot create DevX RQT.",
797 : : dev->data->port_id);
798 : 0 : rte_errno = errno;
799 : 0 : return -rte_errno;
800 : : }
801 : : return 0;
802 : : }
803 : :
804 : : /**
805 : : * Modify RQT using DevX API as a filed of indirection table.
806 : : *
807 : : * @param dev
808 : : * Pointer to Ethernet device.
809 : : * @param log_n
810 : : * Log of number of queues in the array.
811 : : * @param ind_tbl
812 : : * DevX indirection table object.
813 : : *
814 : : * @return
815 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
816 : : */
817 : : static int
818 : 0 : mlx5_devx_ind_table_modify(struct rte_eth_dev *dev, const unsigned int log_n,
819 : : const uint16_t *queues, const uint32_t queues_n,
820 : : struct mlx5_ind_table_obj *ind_tbl)
821 : : {
822 : : int ret = 0;
823 : : struct mlx5_devx_rqt_attr *rqt_attr = NULL;
824 : :
825 : : MLX5_ASSERT(ind_tbl);
826 : 0 : rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n,
827 : : queues,
828 : : queues_n);
829 [ # # ]: 0 : if (!rqt_attr)
830 : 0 : return -rte_errno;
831 : 0 : ret = mlx5_devx_cmd_modify_rqt(ind_tbl->rqt, rqt_attr);
832 : 0 : mlx5_free(rqt_attr);
833 [ # # ]: 0 : if (ret)
834 : 0 : DRV_LOG(ERR, "Port %u cannot modify DevX RQT.",
835 : : dev->data->port_id);
836 : : return ret;
837 : : }
838 : :
839 : : /**
840 : : * Destroy the DevX RQT object.
841 : : *
842 : : * @param ind_table
843 : : * Indirection table to release.
844 : : */
845 : : static void
846 : 0 : mlx5_devx_ind_table_destroy(struct mlx5_ind_table_obj *ind_tbl)
847 : : {
848 : 0 : claim_zero(mlx5_devx_cmd_destroy(ind_tbl->rqt));
849 : 0 : }
850 : :
851 : : /**
852 : : * Set TIR attribute struct with relevant input values.
853 : : *
854 : : * @param[in] dev
855 : : * Pointer to Ethernet device.
856 : : * @param[in] rss_key
857 : : * RSS key for the Rx hash queue.
858 : : * @param[in] hash_fields
859 : : * Verbs protocol hash field to make the RSS on.
860 : : * @param[in] ind_tbl
861 : : * Indirection table for TIR. If table queues array is NULL,
862 : : * a TIR for drop queue is assumed.
863 : : * @param[in] tunnel
864 : : * Tunnel type.
865 : : * @param[out] tir_attr
866 : : * Parameters structure for TIR creation/modification.
867 : : *
868 : : * @return
869 : : * The Verbs/DevX object initialised index, 0 otherwise and rte_errno is set.
870 : : */
871 : : static void
872 : 0 : mlx5_devx_tir_attr_set(struct rte_eth_dev *dev, const uint8_t *rss_key,
873 : : uint64_t hash_fields,
874 : : const struct mlx5_ind_table_obj *ind_tbl,
875 : : int tunnel, bool symmetric_hash_function,
876 : : struct mlx5_devx_tir_attr *tir_attr)
877 : : {
878 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
879 : : bool is_hairpin;
880 : : bool lro = false;
881 : : uint32_t i;
882 : :
883 : : /* NULL queues designate drop queue. */
884 [ # # ]: 0 : if (ind_tbl->queues == NULL) {
885 : 0 : is_hairpin = priv->drop_queue.rxq->ctrl->is_hairpin;
886 [ # # # # ]: 0 : } else if (mlx5_is_external_rxq(dev, ind_tbl->queues[0])) {
887 : : /* External RxQ supports neither Hairpin nor LRO. */
888 : : is_hairpin = false;
889 : : } else {
890 : 0 : is_hairpin = mlx5_rxq_is_hairpin(dev, ind_tbl->queues[0]);
891 : : lro = true;
892 : : /* Enable TIR LRO only if all the queues were configured for. */
893 [ # # ]: 0 : for (i = 0; i < ind_tbl->queues_n; ++i) {
894 : : struct mlx5_rxq_data *rxq_i =
895 : 0 : mlx5_rxq_data_get(dev, ind_tbl->queues[i]);
896 : :
897 [ # # # # ]: 0 : if (rxq_i != NULL && !rxq_i->lro) {
898 : : lro = false;
899 : : break;
900 : : }
901 : : }
902 : : }
903 : : memset(tir_attr, 0, sizeof(*tir_attr));
904 : 0 : tir_attr->disp_type = MLX5_TIRC_DISP_TYPE_INDIRECT;
905 : 0 : tir_attr->rx_hash_fn = MLX5_RX_HASH_FN_TOEPLITZ;
906 : 0 : tir_attr->tunneled_offload_en = !!tunnel;
907 : 0 : tir_attr->rx_hash_symmetric = symmetric_hash_function;
908 : : /* If needed, translate hash_fields bitmap to PRM format. */
909 [ # # ]: 0 : if (hash_fields) {
910 : : struct mlx5_rx_hash_field_select *rx_hash_field_select =
911 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
912 : 0 : hash_fields & IBV_RX_HASH_INNER ?
913 [ # # ]: 0 : &tir_attr->rx_hash_field_selector_inner :
914 : : #endif
915 : : &tir_attr->rx_hash_field_selector_outer;
916 : : /* 1 bit: 0: IPv4, 1: IPv6. */
917 : 0 : rx_hash_field_select->l3_prot_type =
918 : 0 : !!(hash_fields & MLX5_IPV6_IBV_RX_HASH);
919 : : /* 1 bit: 0: TCP, 1: UDP. */
920 : 0 : rx_hash_field_select->l4_prot_type =
921 : 0 : !!(hash_fields & MLX5_UDP_IBV_RX_HASH);
922 : : /* Bitmask which sets which fields to use in RX Hash. */
923 : 0 : rx_hash_field_select->selected_fields =
924 : 0 : ((!!(hash_fields & MLX5_L3_SRC_IBV_RX_HASH)) <<
925 : 0 : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_SRC_IP) |
926 [ # # ]: 0 : (!!(hash_fields & MLX5_L3_DST_IBV_RX_HASH)) <<
927 : 0 : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_DST_IP |
928 [ # # ]: 0 : (!!(hash_fields & MLX5_L4_SRC_IBV_RX_HASH)) <<
929 : 0 : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_SPORT |
930 [ # # ]: 0 : (!!(hash_fields & MLX5_L4_DST_IBV_RX_HASH)) <<
931 : 0 : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_DPORT |
932 : 0 : (!!(hash_fields & IBV_RX_HASH_IPSEC_SPI)) <<
933 : : MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_IPSEC_SPI;
934 : : }
935 [ # # ]: 0 : if (is_hairpin)
936 : 0 : tir_attr->transport_domain = priv->sh->td->id;
937 : : else
938 : 0 : tir_attr->transport_domain = priv->sh->tdn;
939 [ # # ]: 0 : memcpy(tir_attr->rx_hash_toeplitz_key, rss_key, MLX5_RSS_HASH_KEY_LEN);
940 : 0 : tir_attr->indirect_table = ind_tbl->rqt->id;
941 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode)
942 : 0 : tir_attr->self_lb_block = MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST;
943 [ # # ]: 0 : if (lro) {
944 : : MLX5_ASSERT(priv->sh->config.lro_allowed);
945 : 0 : tir_attr->lro_timeout_period_usecs = priv->config.lro_timeout;
946 : 0 : tir_attr->lro_max_msg_sz =
947 : 0 : priv->max_lro_msg_size / MLX5_LRO_SEG_CHUNK_SIZE;
948 : 0 : tir_attr->lro_enable_mask =
949 : : MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
950 : : MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO;
951 : : }
952 : 0 : }
953 : :
954 : : /**
955 : : * Create an Rx Hash queue.
956 : : *
957 : : * @param dev
958 : : * Pointer to Ethernet device.
959 : : * @param hrxq
960 : : * Pointer to Rx Hash queue.
961 : : * @param tunnel
962 : : * Tunnel type.
963 : : *
964 : : * @return
965 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
966 : : */
967 : : static int
968 : 0 : mlx5_devx_hrxq_new(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
969 : : int tunnel __rte_unused)
970 : : {
971 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
972 : 0 : struct mlx5_devx_tir_attr tir_attr = {0};
973 : : int err;
974 : :
975 : 0 : mlx5_devx_tir_attr_set(dev, hrxq->rss_key, hrxq->hash_fields,
976 : 0 : hrxq->ind_table, tunnel, hrxq->symmetric_hash_function,
977 : : &tir_attr);
978 : 0 : hrxq->tir = mlx5_devx_cmd_create_tir(priv->sh->cdev->ctx, &tir_attr);
979 [ # # ]: 0 : if (!hrxq->tir) {
980 : 0 : DRV_LOG(ERR, "Port %u cannot create DevX TIR.",
981 : : dev->data->port_id);
982 : 0 : rte_errno = errno;
983 : 0 : goto error;
984 : : }
985 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
986 : : #ifdef HAVE_MLX5_HWS_SUPPORT
987 [ # # ]: 0 : if (hrxq->hws_flags) {
988 : 0 : hrxq->action = mlx5dr_action_create_dest_tir
989 : : (priv->dr_ctx,
990 : : (struct mlx5dr_devx_obj *)hrxq->tir, hrxq->hws_flags, true);
991 [ # # ]: 0 : if (!hrxq->action)
992 : 0 : goto error;
993 : : return 0;
994 : : }
995 : : #endif
996 : : if (mlx5_flow_os_create_flow_action_dest_devx_tir(hrxq->tir,
997 : : &hrxq->action)) {
998 : 0 : rte_errno = errno;
999 : 0 : goto error;
1000 : : }
1001 : : #endif
1002 : : return 0;
1003 : 0 : error:
1004 : 0 : err = rte_errno; /* Save rte_errno before cleanup. */
1005 [ # # ]: 0 : if (hrxq->tir)
1006 : 0 : claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
1007 : 0 : rte_errno = err; /* Restore rte_errno. */
1008 : 0 : return -rte_errno;
1009 : : }
1010 : :
1011 : : /**
1012 : : * Destroy a DevX TIR object.
1013 : : *
1014 : : * @param hrxq
1015 : : * Hash Rx queue to release its tir.
1016 : : */
1017 : : static void
1018 : 0 : mlx5_devx_tir_destroy(struct mlx5_hrxq *hrxq)
1019 : : {
1020 : 0 : claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
1021 : 0 : }
1022 : :
1023 : : /**
1024 : : * Modify an Rx Hash queue configuration.
1025 : : *
1026 : : * @param dev
1027 : : * Pointer to Ethernet device.
1028 : : * @param hrxq
1029 : : * Hash Rx queue to modify.
1030 : : * @param rss_key
1031 : : * RSS key for the Rx hash queue.
1032 : : * @param hash_fields
1033 : : * Verbs protocol hash field to make the RSS on.
1034 : : * @param[in] ind_tbl
1035 : : * Indirection table for TIR.
1036 : : *
1037 : : * @return
1038 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1039 : : */
1040 : : static int
1041 : 0 : mlx5_devx_hrxq_modify(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
1042 : : const uint8_t *rss_key,
1043 : : uint64_t hash_fields,
1044 : : bool symmetric_hash_function,
1045 : : const struct mlx5_ind_table_obj *ind_tbl)
1046 : : {
1047 : 0 : struct mlx5_devx_modify_tir_attr modify_tir = {0};
1048 : :
1049 : : /*
1050 : : * untested for modification fields:
1051 : : * - rx_hash_fn set hard-coded in hrxq_new(),
1052 : : * - lro_xxx not set after rxq setup
1053 : : */
1054 [ # # ]: 0 : if (ind_tbl != hrxq->ind_table)
1055 : 0 : modify_tir.modify_bitmask |=
1056 : : MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_INDIRECT_TABLE;
1057 [ # # ]: 0 : if (hash_fields != hrxq->hash_fields ||
1058 [ # # ]: 0 : symmetric_hash_function != hrxq->symmetric_hash_function ||
1059 [ # # ]: 0 : memcmp(hrxq->rss_key, rss_key, MLX5_RSS_HASH_KEY_LEN))
1060 : 0 : modify_tir.modify_bitmask |=
1061 : : MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_HASH;
1062 : 0 : mlx5_devx_tir_attr_set(dev, rss_key, hash_fields, ind_tbl,
1063 : : 0, /* N/A - tunnel modification unsupported */
1064 : : symmetric_hash_function,
1065 : : &modify_tir.tir);
1066 : 0 : modify_tir.tirn = hrxq->tir->id;
1067 [ # # ]: 0 : if (mlx5_devx_cmd_modify_tir(hrxq->tir, &modify_tir)) {
1068 : 0 : DRV_LOG(ERR, "port %u cannot modify DevX TIR",
1069 : : dev->data->port_id);
1070 : 0 : rte_errno = errno;
1071 : 0 : return -rte_errno;
1072 : : }
1073 : : return 0;
1074 : : }
1075 : :
1076 : : /**
1077 : : * Create a DevX drop Rx queue.
1078 : : *
1079 : : * @param dev
1080 : : * Pointer to Ethernet device.
1081 : : *
1082 : : * @return
1083 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1084 : : */
1085 : : static int
1086 : 0 : mlx5_rxq_devx_obj_drop_create(struct rte_eth_dev *dev)
1087 : : {
1088 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1089 : 0 : int socket_id = dev->device->numa_node;
1090 : : struct mlx5_rxq_priv *rxq;
1091 : : struct mlx5_rxq_ctrl *rxq_ctrl = NULL;
1092 : : struct mlx5_rxq_obj *rxq_obj = NULL;
1093 : : int ret;
1094 : :
1095 : : /*
1096 : : * Initialize dummy control structures.
1097 : : * They are required to hold pointers for cleanup
1098 : : * and are only accessible via drop queue DevX objects.
1099 : : */
1100 [ # # # # ]: 0 : rxq = mlx5_malloc_numa_tolerant(MLX5_MEM_ZERO, sizeof(*rxq), 0, socket_id);
1101 [ # # ]: 0 : if (rxq == NULL) {
1102 : 0 : DRV_LOG(ERR, "Port %u could not allocate drop queue private",
1103 : : dev->data->port_id);
1104 : 0 : rte_errno = ENOMEM;
1105 : 0 : goto error;
1106 : : }
1107 [ # # # # ]: 0 : rxq_ctrl = mlx5_malloc_numa_tolerant(MLX5_MEM_ZERO, sizeof(*rxq_ctrl),
1108 : : 0, socket_id);
1109 [ # # ]: 0 : if (rxq_ctrl == NULL) {
1110 : 0 : DRV_LOG(ERR, "Port %u could not allocate drop queue control",
1111 : : dev->data->port_id);
1112 : 0 : rte_errno = ENOMEM;
1113 : 0 : goto error;
1114 : : }
1115 [ # # # # ]: 0 : rxq_obj = mlx5_malloc_numa_tolerant(MLX5_MEM_ZERO, sizeof(*rxq_obj), 0, socket_id);
1116 [ # # ]: 0 : if (rxq_obj == NULL) {
1117 : 0 : DRV_LOG(ERR, "Port %u could not allocate drop queue object",
1118 : : dev->data->port_id);
1119 : 0 : rte_errno = ENOMEM;
1120 : 0 : goto error;
1121 : : }
1122 : : /* set the CPU socket ID where the rxq_ctrl was allocated */
1123 : 0 : rxq_ctrl->socket = socket_id;
1124 : 0 : rxq_obj->rxq_ctrl = rxq_ctrl;
1125 : 0 : rxq_ctrl->is_hairpin = false;
1126 : 0 : rxq_ctrl->sh = priv->sh;
1127 : 0 : rxq_ctrl->obj = rxq_obj;
1128 : 0 : rxq->ctrl = rxq_ctrl;
1129 : 0 : rxq->priv = priv;
1130 [ # # ]: 0 : LIST_INSERT_HEAD(&rxq_ctrl->owners, rxq, owner_entry);
1131 : : /* Create CQ using DevX API. */
1132 : 0 : ret = mlx5_rxq_create_devx_cq_resources(rxq);
1133 [ # # ]: 0 : if (ret != 0) {
1134 : 0 : DRV_LOG(ERR, "Port %u drop queue CQ creation failed.",
1135 : : dev->data->port_id);
1136 : 0 : goto error;
1137 : : }
1138 : 0 : rxq_ctrl->rxq.delay_drop = 0;
1139 : : /* Create RQ using DevX API. */
1140 : 0 : ret = mlx5_rxq_create_devx_rq_resources(rxq);
1141 [ # # ]: 0 : if (ret != 0) {
1142 : 0 : DRV_LOG(ERR, "Port %u drop queue RQ creation failed.",
1143 : : dev->data->port_id);
1144 : 0 : rte_errno = ENOMEM;
1145 : 0 : goto error;
1146 : : }
1147 : : /* Change queue state to ready. */
1148 : 0 : ret = mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RST2RDY);
1149 [ # # ]: 0 : if (ret != 0)
1150 : 0 : goto error;
1151 : : /* Initialize drop queue. */
1152 : 0 : priv->drop_queue.rxq = rxq;
1153 : 0 : return 0;
1154 : 0 : error:
1155 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
1156 [ # # # # ]: 0 : if (rxq != NULL && rxq->devx_rq.rq != NULL)
1157 : 0 : mlx5_devx_rq_destroy(&rxq->devx_rq);
1158 [ # # ]: 0 : if (rxq_obj != NULL) {
1159 [ # # ]: 0 : if (rxq_obj->cq_obj.cq != NULL)
1160 : 0 : mlx5_devx_cq_destroy(&rxq_obj->cq_obj);
1161 [ # # ]: 0 : if (rxq_obj->devx_channel)
1162 : : mlx5_os_devx_destroy_event_channel
1163 : : (rxq_obj->devx_channel);
1164 : 0 : mlx5_free(rxq_obj);
1165 : : }
1166 [ # # ]: 0 : if (rxq_ctrl != NULL)
1167 : 0 : mlx5_free(rxq_ctrl);
1168 [ # # ]: 0 : if (rxq != NULL)
1169 : 0 : mlx5_free(rxq);
1170 : 0 : rte_errno = ret; /* Restore rte_errno. */
1171 : 0 : return -rte_errno;
1172 : : }
1173 : :
1174 : : /**
1175 : : * Release drop Rx queue resources.
1176 : : *
1177 : : * @param dev
1178 : : * Pointer to Ethernet device.
1179 : : */
1180 : : static void
1181 : 0 : mlx5_rxq_devx_obj_drop_release(struct rte_eth_dev *dev)
1182 : : {
1183 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1184 : 0 : struct mlx5_rxq_priv *rxq = priv->drop_queue.rxq;
1185 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl;
1186 : :
1187 : 0 : mlx5_rxq_devx_obj_release(rxq);
1188 : 0 : mlx5_free(rxq_ctrl->obj);
1189 : 0 : mlx5_free(rxq_ctrl);
1190 : 0 : mlx5_free(rxq);
1191 : 0 : priv->drop_queue.rxq = NULL;
1192 : 0 : }
1193 : :
1194 : : /**
1195 : : * Release a drop hash Rx queue.
1196 : : *
1197 : : * @param dev
1198 : : * Pointer to Ethernet device.
1199 : : */
1200 : : static void
1201 : 0 : mlx5_devx_drop_action_destroy(struct rte_eth_dev *dev)
1202 : : {
1203 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1204 : 0 : struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq;
1205 : :
1206 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
1207 [ # # ]: 0 : if (hrxq->action != NULL)
1208 : : mlx5_flow_os_destroy_flow_action(hrxq->action);
1209 : : #endif
1210 [ # # ]: 0 : if (hrxq->tir != NULL)
1211 : : mlx5_devx_tir_destroy(hrxq);
1212 [ # # ]: 0 : if (hrxq->ind_table->ind_table != NULL)
1213 : : mlx5_devx_ind_table_destroy(hrxq->ind_table);
1214 [ # # ]: 0 : if (priv->drop_queue.rxq->devx_rq.rq != NULL)
1215 : 0 : mlx5_rxq_devx_obj_drop_release(dev);
1216 : 0 : }
1217 : :
1218 : : /**
1219 : : * Create a DevX drop action for Rx Hash queue.
1220 : : *
1221 : : * @param dev
1222 : : * Pointer to Ethernet device.
1223 : : *
1224 : : * @return
1225 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1226 : : */
1227 : : static int
1228 : 0 : mlx5_devx_drop_action_create(struct rte_eth_dev *dev)
1229 : : {
1230 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1231 : 0 : struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq;
1232 : : int ret;
1233 : :
1234 : 0 : ret = mlx5_rxq_devx_obj_drop_create(dev);
1235 [ # # ]: 0 : if (ret != 0) {
1236 : 0 : DRV_LOG(ERR, "Cannot create drop RX queue");
1237 : 0 : return ret;
1238 : : }
1239 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1240 : : return 0;
1241 : : /* hrxq->ind_table queues are NULL, drop RX queue ID will be used */
1242 : 0 : ret = mlx5_devx_ind_table_new(dev, 0, hrxq->ind_table);
1243 [ # # ]: 0 : if (ret != 0) {
1244 : 0 : DRV_LOG(ERR, "Cannot create drop hash RX queue indirection table");
1245 : 0 : goto error;
1246 : : }
1247 : 0 : ret = mlx5_devx_hrxq_new(dev, hrxq, /* tunnel */ false);
1248 [ # # ]: 0 : if (ret != 0) {
1249 : 0 : DRV_LOG(ERR, "Cannot create drop hash RX queue");
1250 : 0 : goto error;
1251 : : }
1252 : : return 0;
1253 : 0 : error:
1254 : 0 : mlx5_devx_drop_action_destroy(dev);
1255 : 0 : return ret;
1256 : : }
1257 : :
1258 : : /**
1259 : : * Select TXQ TIS number.
1260 : : *
1261 : : * @param dev
1262 : : * Pointer to Ethernet device.
1263 : : * @param queue_idx
1264 : : * Queue index in DPDK Tx queue array.
1265 : : *
1266 : : * @return
1267 : : * > 0 on success, a negative errno value otherwise.
1268 : : */
1269 : : static uint32_t
1270 : 0 : mlx5_get_txq_tis_num(struct rte_eth_dev *dev, uint16_t queue_idx)
1271 : : {
1272 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1273 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[queue_idx];
1274 : : int tis_idx = 0;
1275 : :
1276 [ # # ]: 0 : if (priv->sh->bond.n_port) {
1277 [ # # ]: 0 : if (txq_data->tx_aggr_affinity) {
1278 : 0 : tis_idx = txq_data->tx_aggr_affinity;
1279 [ # # ]: 0 : } else if (priv->sh->lag.affinity_mode == MLX5_LAG_MODE_TIS) {
1280 : 0 : tis_idx = (priv->lag_affinity_idx + queue_idx) %
1281 : 0 : priv->sh->bond.n_port + 1;
1282 : 0 : DRV_LOG(INFO, "port %d txq %d gets affinity %d and maps to PF %d.",
1283 : : dev->data->port_id, queue_idx, tis_idx,
1284 : : priv->sh->lag.tx_remap_affinity[tis_idx - 1]);
1285 : : }
1286 : : }
1287 : : MLX5_ASSERT(priv->sh->tis[tis_idx]);
1288 : 0 : return priv->sh->tis[tis_idx]->id;
1289 : : }
1290 : :
1291 : : /**
1292 : : * Create the Tx hairpin queue object.
1293 : : *
1294 : : * @param dev
1295 : : * Pointer to Ethernet device.
1296 : : * @param idx
1297 : : * Queue index in DPDK Tx queue array.
1298 : : *
1299 : : * @return
1300 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1301 : : */
1302 : : static int
1303 : 0 : mlx5_txq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx)
1304 : : {
1305 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1306 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
1307 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1308 : : struct mlx5_txq_ctrl *txq_ctrl =
1309 : 0 : container_of(txq_data, struct mlx5_txq_ctrl, txq);
1310 : 0 : struct mlx5_devx_create_sq_attr dev_mem_attr = { 0 };
1311 : 0 : struct mlx5_devx_create_sq_attr host_mem_attr = { 0 };
1312 : 0 : struct mlx5_txq_obj *tmpl = txq_ctrl->obj;
1313 : : void *umem_buf = NULL;
1314 : : void *umem_obj = NULL;
1315 : : uint32_t max_wq_data;
1316 : :
1317 : : MLX5_ASSERT(txq_data);
1318 : : MLX5_ASSERT(tmpl);
1319 : 0 : tmpl->txq_ctrl = txq_ctrl;
1320 : 0 : dev_mem_attr.hairpin = 1;
1321 : 0 : dev_mem_attr.tis_lst_sz = 1;
1322 : 0 : dev_mem_attr.tis_num = mlx5_get_txq_tis_num(dev, idx);
1323 : 0 : max_wq_data =
1324 : 0 : priv->sh->cdev->config.hca_attr.log_max_hairpin_wq_data_sz;
1325 : : /* Jumbo frames > 9KB should be supported, and more packets. */
1326 [ # # ]: 0 : if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) {
1327 [ # # ]: 0 : if (priv->config.log_hp_size > max_wq_data) {
1328 : 0 : DRV_LOG(ERR, "Total data size %u power of 2 is "
1329 : : "too large for hairpin.",
1330 : : priv->config.log_hp_size);
1331 : 0 : rte_errno = ERANGE;
1332 : 0 : return -rte_errno;
1333 : : }
1334 : 0 : dev_mem_attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size;
1335 : : } else {
1336 : 0 : dev_mem_attr.wq_attr.log_hairpin_data_sz =
1337 : : (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ?
1338 : 0 : max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE;
1339 : : }
1340 : : /* Set the packets number to the maximum value for performance. */
1341 : 0 : dev_mem_attr.wq_attr.log_hairpin_num_packets =
1342 : 0 : dev_mem_attr.wq_attr.log_hairpin_data_sz -
1343 : : MLX5_HAIRPIN_QUEUE_STRIDE;
1344 : 0 : dev_mem_attr.hairpin_wq_buffer_type = MLX5_SQC_HAIRPIN_WQ_BUFFER_TYPE_INTERNAL_BUFFER;
1345 [ # # ]: 0 : if (txq_ctrl->hairpin_conf.use_rte_memory) {
1346 : : uint32_t umem_size;
1347 : : uint32_t umem_dbrec;
1348 : 0 : size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
1349 : :
1350 [ # # ]: 0 : if (alignment == (size_t)-1) {
1351 : 0 : DRV_LOG(ERR, "Failed to get WQE buf alignment.");
1352 : 0 : rte_errno = ENOMEM;
1353 : 0 : return -rte_errno;
1354 : : }
1355 : : /*
1356 : : * It is assumed that configuration is verified against capabilities
1357 : : * during queue setup.
1358 : : */
1359 : : MLX5_ASSERT(hca_attr->hairpin_sq_wq_in_host_mem);
1360 : : MLX5_ASSERT(hca_attr->hairpin_sq_wqe_bb_size > 0);
1361 : : rte_memcpy(&host_mem_attr, &dev_mem_attr, sizeof(host_mem_attr));
1362 : 0 : umem_size = MLX5_WQE_SIZE *
1363 : 0 : (size_t)RTE_BIT32(host_mem_attr.wq_attr.log_hairpin_num_packets);
1364 : 0 : umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE);
1365 : 0 : umem_size += MLX5_DBR_SIZE;
1366 : 0 : umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size,
1367 : 0 : alignment, priv->sh->numa_node);
1368 [ # # # # ]: 0 : if (umem_buf == NULL && txq_ctrl->hairpin_conf.force_memory) {
1369 : 0 : DRV_LOG(ERR, "Failed to allocate memory for hairpin TX queue");
1370 : 0 : rte_errno = ENOMEM;
1371 : 0 : return -rte_errno;
1372 [ # # # # ]: 0 : } else if (umem_buf == NULL && !txq_ctrl->hairpin_conf.force_memory) {
1373 : 0 : DRV_LOG(WARNING, "Failed to allocate memory for hairpin TX queue."
1374 : : " Falling back to TX queue located on the device.");
1375 : 0 : goto create_sq_on_device;
1376 : : }
1377 : 0 : umem_obj = mlx5_os_umem_reg(priv->sh->cdev->ctx,
1378 : : (void *)(uintptr_t)umem_buf,
1379 : : umem_size,
1380 : : IBV_ACCESS_LOCAL_WRITE);
1381 [ # # # # ]: 0 : if (umem_obj == NULL && txq_ctrl->hairpin_conf.force_memory) {
1382 : 0 : DRV_LOG(ERR, "Failed to register UMEM for hairpin TX queue");
1383 : 0 : mlx5_free(umem_buf);
1384 : 0 : return -rte_errno;
1385 [ # # # # ]: 0 : } else if (umem_obj == NULL && !txq_ctrl->hairpin_conf.force_memory) {
1386 : 0 : DRV_LOG(WARNING, "Failed to register UMEM for hairpin TX queue."
1387 : : " Falling back to TX queue located on the device.");
1388 : 0 : rte_errno = 0;
1389 : 0 : mlx5_free(umem_buf);
1390 : 0 : goto create_sq_on_device;
1391 : : }
1392 : 0 : host_mem_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
1393 [ # # ]: 0 : host_mem_attr.wq_attr.wq_umem_valid = 1;
1394 : 0 : host_mem_attr.wq_attr.wq_umem_id = mlx5_os_get_umem_id(umem_obj);
1395 : 0 : host_mem_attr.wq_attr.wq_umem_offset = 0;
1396 : 0 : host_mem_attr.wq_attr.dbr_umem_valid = 1;
1397 : 0 : host_mem_attr.wq_attr.dbr_umem_id = host_mem_attr.wq_attr.wq_umem_id;
1398 : 0 : host_mem_attr.wq_attr.dbr_addr = umem_dbrec;
1399 : 0 : host_mem_attr.wq_attr.log_wq_stride = rte_log2_u32(MLX5_WQE_SIZE);
1400 : 0 : host_mem_attr.wq_attr.log_wq_sz =
1401 : 0 : host_mem_attr.wq_attr.log_hairpin_num_packets *
1402 : 0 : hca_attr->hairpin_sq_wqe_bb_size;
1403 : 0 : host_mem_attr.wq_attr.log_wq_pg_sz = MLX5_LOG_PAGE_SIZE;
1404 : 0 : host_mem_attr.hairpin_wq_buffer_type = MLX5_SQC_HAIRPIN_WQ_BUFFER_TYPE_HOST_MEMORY;
1405 : 0 : tmpl->sq = mlx5_devx_cmd_create_sq(priv->sh->cdev->ctx, &host_mem_attr);
1406 [ # # # # ]: 0 : if (!tmpl->sq && txq_ctrl->hairpin_conf.force_memory) {
1407 : 0 : DRV_LOG(ERR,
1408 : : "Port %u tx hairpin queue %u can't create SQ object.",
1409 : : dev->data->port_id, idx);
1410 : : claim_zero(mlx5_os_umem_dereg(umem_obj));
1411 : 0 : mlx5_free(umem_buf);
1412 : 0 : return -rte_errno;
1413 [ # # # # ]: 0 : } else if (!tmpl->sq && !txq_ctrl->hairpin_conf.force_memory) {
1414 : 0 : DRV_LOG(WARNING,
1415 : : "Port %u tx hairpin queue %u failed to allocate SQ object"
1416 : : " using host memory. Falling back to TX queue located"
1417 : : " on the device",
1418 : : dev->data->port_id, idx);
1419 : 0 : rte_errno = 0;
1420 : : claim_zero(mlx5_os_umem_dereg(umem_obj));
1421 : 0 : mlx5_free(umem_buf);
1422 : 0 : goto create_sq_on_device;
1423 : : }
1424 : 0 : tmpl->umem_buf_wq_buffer = umem_buf;
1425 : 0 : tmpl->umem_obj_wq_buffer = umem_obj;
1426 : 0 : return 0;
1427 : : }
1428 : :
1429 : 0 : create_sq_on_device:
1430 : 0 : tmpl->sq = mlx5_devx_cmd_create_sq(priv->sh->cdev->ctx, &dev_mem_attr);
1431 [ # # ]: 0 : if (!tmpl->sq) {
1432 : 0 : DRV_LOG(ERR,
1433 : : "Port %u tx hairpin queue %u can't create SQ object.",
1434 : : dev->data->port_id, idx);
1435 : 0 : rte_errno = errno;
1436 : 0 : return -rte_errno;
1437 : : }
1438 : : return 0;
1439 : : }
1440 : :
1441 : : #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H)
1442 : : /**
1443 : : * Destroy the Tx queue DevX object.
1444 : : *
1445 : : * @param txq_obj
1446 : : * Txq object to destroy.
1447 : : */
1448 : : static void
1449 : 0 : mlx5_txq_release_devx_resources(struct mlx5_txq_obj *txq_obj)
1450 : : {
1451 : 0 : mlx5_devx_sq_destroy(&txq_obj->sq_obj);
1452 : : memset(&txq_obj->sq_obj, 0, sizeof(txq_obj->sq_obj));
1453 : 0 : mlx5_devx_cq_destroy(&txq_obj->cq_obj);
1454 : : memset(&txq_obj->cq_obj, 0, sizeof(txq_obj->cq_obj));
1455 : 0 : }
1456 : :
1457 : : /**
1458 : : * Create a SQ object and its resources using DevX.
1459 : : *
1460 : : * @param dev
1461 : : * Pointer to Ethernet device.
1462 : : * @param idx
1463 : : * Queue index in DPDK Tx queue array.
1464 : : * @param[in] log_desc_n
1465 : : * Log of number of descriptors in queue.
1466 : : *
1467 : : * @return
1468 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1469 : : */
1470 : : static int
1471 : 0 : mlx5_txq_create_devx_sq_resources(struct rte_eth_dev *dev, uint16_t idx,
1472 : : uint16_t log_desc_n)
1473 : : {
1474 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1475 : 0 : struct mlx5_common_device *cdev = priv->sh->cdev;
1476 : : struct mlx5_uar *uar = &priv->sh->tx_uar;
1477 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1478 : : struct mlx5_txq_ctrl *txq_ctrl =
1479 : 0 : container_of(txq_data, struct mlx5_txq_ctrl, txq);
1480 : 0 : struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
1481 : 0 : struct mlx5_devx_create_sq_attr sq_attr = {
1482 : : .flush_in_error_en = 1,
1483 : 0 : .allow_multi_pkt_send_wqe = !!priv->config.mps,
1484 : 0 : .min_wqe_inline_mode = cdev->config.hca_attr.vport_inline_mode,
1485 : 0 : .allow_swp = !!priv->sh->dev_cap.swp,
1486 : 0 : .cqn = txq_obj->cq_obj.cq->id,
1487 : : .tis_lst_sz = 1,
1488 : : .wq_attr = (struct mlx5_devx_wq_attr){
1489 : 0 : .pd = cdev->pdn,
1490 : 0 : .uar_page = mlx5_os_get_devx_uar_page_id(uar->obj),
1491 : : },
1492 : : .ts_format =
1493 : 0 : mlx5_ts_format_conv(cdev->config.hca_attr.sq_ts_format),
1494 [ # # ]: 0 : .tis_num = mlx5_get_txq_tis_num(dev, idx),
1495 : : };
1496 : 0 : uint32_t db_start = priv->consec_tx_mem.sq_total_size + priv->consec_tx_mem.cq_total_size;
1497 : : int ret;
1498 : :
1499 : : /* Create Send Queue object with DevX. */
1500 [ # # ]: 0 : if (priv->sh->config.txq_mem_algn) {
1501 : 0 : sq_attr.umem = priv->consec_tx_mem.umem;
1502 : 0 : sq_attr.umem_obj = priv->consec_tx_mem.umem_obj;
1503 : 0 : sq_attr.q_off = priv->consec_tx_mem.sq_cur_off;
1504 : 0 : sq_attr.db_off = db_start + (2 * idx) * MLX5_DBR_SIZE;
1505 : 0 : sq_attr.q_len = txq_data->sq_mem_len;
1506 : : }
1507 : 0 : ret = mlx5_devx_sq_create(cdev->ctx, &txq_obj->sq_obj,
1508 : : log_desc_n, &sq_attr, priv->sh->numa_node);
1509 [ # # # # ]: 0 : if (!ret && priv->sh->config.txq_mem_algn)
1510 : 0 : priv->consec_tx_mem.sq_cur_off += txq_data->sq_mem_len;
1511 : 0 : return ret;
1512 : : }
1513 : : #endif
1514 : :
1515 : : /**
1516 : : * Create the Tx queue DevX object.
1517 : : *
1518 : : * @param dev
1519 : : * Pointer to Ethernet device.
1520 : : * @param idx
1521 : : * Queue index in DPDK Tx queue array.
1522 : : *
1523 : : * @return
1524 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1525 : : */
1526 : : int
1527 : 0 : mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx)
1528 : : {
1529 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1530 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1531 : : struct mlx5_txq_ctrl *txq_ctrl =
1532 : 0 : container_of(txq_data, struct mlx5_txq_ctrl, txq);
1533 : :
1534 [ # # ]: 0 : if (txq_ctrl->is_hairpin)
1535 : 0 : return mlx5_txq_obj_hairpin_new(dev, idx);
1536 : : #if !defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) && defined(HAVE_INFINIBAND_VERBS_H)
1537 : : DRV_LOG(ERR, "Port %u Tx queue %u cannot create with DevX, no UAR.",
1538 : : dev->data->port_id, idx);
1539 : : rte_errno = ENOMEM;
1540 : : return -rte_errno;
1541 : : #else
1542 : 0 : struct mlx5_proc_priv *ppriv = MLX5_PROC_PRIV(PORT_ID(priv));
1543 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
1544 : 0 : struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
1545 : 0 : struct mlx5_devx_cq_attr cq_attr = {
1546 [ # # ]: 0 : .uar_page_id = mlx5_os_get_devx_uar_page_id(sh->tx_uar.obj),
1547 : : };
1548 : : uint32_t cqe_n, log_desc_n;
1549 : : uint32_t wqe_n, wqe_size;
1550 : : int ret = 0;
1551 : 0 : uint32_t db_start = priv->consec_tx_mem.sq_total_size + priv->consec_tx_mem.cq_total_size;
1552 : :
1553 : : MLX5_ASSERT(txq_data);
1554 : : MLX5_ASSERT(txq_obj);
1555 : : MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
1556 : : MLX5_ASSERT(ppriv);
1557 : 0 : txq_obj->txq_ctrl = txq_ctrl;
1558 : 0 : txq_obj->dev = dev;
1559 : : if (__rte_trace_point_fp_is_enabled() &&
1560 : : txq_data->offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP)
1561 : : cqe_n = UINT16_MAX / 2 - 1;
1562 : : else
1563 : 0 : cqe_n = (1UL << txq_data->elts_n) / MLX5_TX_COMP_THRESH +
1564 : 0 : 1 + MLX5_TX_COMP_THRESH_INLINE_DIV;
1565 : : log_desc_n = log2above(cqe_n);
1566 : 0 : cqe_n = 1UL << log_desc_n;
1567 [ # # ]: 0 : if (cqe_n > UINT16_MAX) {
1568 : 0 : DRV_LOG(ERR, "Port %u Tx queue %u requests to many CQEs %u.",
1569 : : dev->data->port_id, txq_data->idx, cqe_n);
1570 : 0 : rte_errno = EINVAL;
1571 : 0 : return 0;
1572 : : }
1573 [ # # ]: 0 : if (priv->sh->config.txq_mem_algn) {
1574 : 0 : cq_attr.umem = priv->consec_tx_mem.umem;
1575 : 0 : cq_attr.umem_obj = priv->consec_tx_mem.umem_obj;
1576 : 0 : cq_attr.q_off = priv->consec_tx_mem.cq_cur_off;
1577 : 0 : cq_attr.db_off = db_start + (2 * idx + 1) * MLX5_DBR_SIZE;
1578 : 0 : cq_attr.q_len = txq_data->cq_mem_len;
1579 : : }
1580 : : /* Create completion queue object with DevX. */
1581 : 0 : ret = mlx5_devx_cq_create(sh->cdev->ctx, &txq_obj->cq_obj, log_desc_n,
1582 : : &cq_attr, priv->sh->numa_node);
1583 [ # # ]: 0 : if (ret) {
1584 : 0 : DRV_LOG(ERR, "Port %u Tx queue %u CQ creation failure.",
1585 : : dev->data->port_id, idx);
1586 : 0 : goto error;
1587 : : }
1588 : 0 : txq_data->cqe_n = log_desc_n;
1589 : 0 : txq_data->cqe_s = cqe_n;
1590 : 0 : txq_data->cqe_m = txq_data->cqe_s - 1;
1591 : 0 : txq_data->cqes = txq_obj->cq_obj.cqes;
1592 : 0 : txq_data->cq_ci = 0;
1593 : 0 : txq_data->cq_pi = 0;
1594 : 0 : txq_data->cq_db = txq_obj->cq_obj.db_rec;
1595 : 0 : *txq_data->cq_db = 0;
1596 : : /*
1597 : : * Adjust the amount of WQEs depending on inline settings.
1598 : : * The number of descriptors should be enough to handle
1599 : : * the specified number of packets. If queue is being created
1600 : : * with Verbs the rdma-core does queue size adjustment
1601 : : * internally in the mlx5_calc_sq_size(), we do the same
1602 : : * for the queue being created with DevX at this point.
1603 : : */
1604 : 0 : wqe_size = txq_data->tso_en ?
1605 [ # # ]: 0 : RTE_ALIGN(txq_ctrl->max_tso_header, MLX5_WSEG_SIZE) : 0;
1606 : 0 : wqe_size += sizeof(struct mlx5_wqe_cseg) +
1607 : : sizeof(struct mlx5_wqe_eseg) +
1608 : : sizeof(struct mlx5_wqe_dseg);
1609 [ # # ]: 0 : if (txq_data->inlen_send)
1610 : 0 : wqe_size = RTE_MAX(wqe_size, sizeof(struct mlx5_wqe_cseg) +
1611 : : sizeof(struct mlx5_wqe_eseg) +
1612 : : RTE_ALIGN(txq_data->inlen_send +
1613 : : sizeof(uint32_t),
1614 : : MLX5_WSEG_SIZE));
1615 : 0 : wqe_size = RTE_ALIGN(wqe_size, MLX5_WQE_SIZE) / MLX5_WQE_SIZE;
1616 : : /* Create Send Queue object with DevX. */
1617 : 0 : wqe_n = RTE_MIN((1UL << txq_data->elts_n) * wqe_size,
1618 : : (uint32_t)mlx5_dev_get_max_wq_size(priv->sh));
1619 : : log_desc_n = log2above(wqe_n);
1620 : 0 : ret = mlx5_txq_create_devx_sq_resources(dev, idx, log_desc_n);
1621 [ # # ]: 0 : if (ret) {
1622 : 0 : DRV_LOG(ERR, "Port %u Tx queue %u SQ creation failure.",
1623 : : dev->data->port_id, idx);
1624 : 0 : rte_errno = errno;
1625 : 0 : goto error;
1626 : : }
1627 : : /* Create the Work Queue. */
1628 : 0 : txq_data->wqe_n = log_desc_n;
1629 : 0 : txq_data->wqe_s = 1 << txq_data->wqe_n;
1630 : 0 : txq_data->wqe_m = txq_data->wqe_s - 1;
1631 : 0 : txq_data->wqes = (struct mlx5_wqe *)(uintptr_t)txq_obj->sq_obj.wqes;
1632 : 0 : txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s;
1633 : 0 : txq_data->wqe_ci = 0;
1634 : 0 : txq_data->wqe_pi = 0;
1635 : 0 : txq_data->wqe_comp = 0;
1636 : 0 : txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV;
1637 : 0 : txq_data->qp_db = &txq_obj->sq_obj.db_rec[MLX5_SND_DBR];
1638 : 0 : *txq_data->qp_db = 0;
1639 : 0 : txq_data->qp_num_8s = txq_obj->sq_obj.sq->id << 8;
1640 : 0 : txq_data->db_heu = sh->cdev->config.dbnc == MLX5_SQ_DB_HEURISTIC;
1641 : 0 : txq_data->db_nc = sh->tx_uar.dbnc;
1642 [ # # # # ]: 0 : txq_data->wait_on_time = !!(!sh->config.tx_pp &&
1643 : : sh->cdev->config.hca_attr.wait_on_time);
1644 : : /* Change Send Queue state to Ready-to-Send. */
1645 : 0 : ret = mlx5_txq_devx_modify(txq_obj, MLX5_TXQ_MOD_RST2RDY, 0);
1646 [ # # ]: 0 : if (ret) {
1647 : 0 : rte_errno = errno;
1648 : 0 : DRV_LOG(ERR,
1649 : : "Port %u Tx queue %u SQ state to SQC_STATE_RDY failed.",
1650 : : dev->data->port_id, idx);
1651 : 0 : goto error;
1652 : : }
1653 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1654 : : /*
1655 : : * If using DevX need to query and store TIS transport domain value.
1656 : : * This is done once per port.
1657 : : * Will use this value on Rx, when creating matching TIR.
1658 : : */
1659 [ # # ]: 0 : if (!priv->sh->tdn)
1660 : 0 : priv->sh->tdn = priv->sh->td->id;
1661 : : #endif
1662 : 0 : txq_ctrl->uar_mmap_offset =
1663 [ # # ]: 0 : mlx5_os_get_devx_uar_mmap_offset(sh->tx_uar.obj);
1664 [ # # ]: 0 : if (priv->sh->config.txq_mem_algn)
1665 : 0 : priv->consec_tx_mem.cq_cur_off += txq_data->cq_mem_len;
1666 : 0 : ppriv->uar_table[txq_data->idx] = sh->tx_uar.bf_db;
1667 : 0 : dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
1668 : 0 : return 0;
1669 : 0 : error:
1670 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
1671 : 0 : mlx5_txq_release_devx_resources(txq_obj);
1672 : 0 : rte_errno = ret; /* Restore rte_errno. */
1673 : 0 : return -rte_errno;
1674 : : #endif
1675 : : }
1676 : :
1677 : : /**
1678 : : * Release an Tx DevX queue object.
1679 : : *
1680 : : * @param txq_obj
1681 : : * DevX Tx queue object.
1682 : : */
1683 : : void
1684 : 0 : mlx5_txq_devx_obj_release(struct mlx5_txq_obj *txq_obj)
1685 : : {
1686 : : MLX5_ASSERT(txq_obj);
1687 [ # # ]: 0 : if (txq_obj->txq_ctrl->is_hairpin) {
1688 [ # # ]: 0 : if (txq_obj->sq) {
1689 : 0 : claim_zero(mlx5_devx_cmd_destroy(txq_obj->sq));
1690 : 0 : txq_obj->sq = NULL;
1691 : : }
1692 [ # # ]: 0 : if (txq_obj->tis)
1693 : 0 : claim_zero(mlx5_devx_cmd_destroy(txq_obj->tis));
1694 [ # # ]: 0 : if (txq_obj->umem_obj_wq_buffer) {
1695 : : claim_zero(mlx5_os_umem_dereg(txq_obj->umem_obj_wq_buffer));
1696 : 0 : txq_obj->umem_obj_wq_buffer = NULL;
1697 : : }
1698 [ # # ]: 0 : if (txq_obj->umem_buf_wq_buffer) {
1699 : 0 : mlx5_free(txq_obj->umem_buf_wq_buffer);
1700 : 0 : txq_obj->umem_buf_wq_buffer = NULL;
1701 : : }
1702 : : #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H)
1703 : : } else {
1704 : 0 : mlx5_txq_release_devx_resources(txq_obj);
1705 : : #endif
1706 : : }
1707 : 0 : }
1708 : :
1709 : : struct mlx5_obj_ops devx_obj_ops = {
1710 : : .rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_rq_vlan_strip,
1711 : : .rxq_obj_modify_counter_set_id = mlx5_rxq_obj_modify_counter,
1712 : : .rxq_obj_new = mlx5_rxq_devx_obj_new,
1713 : : .rxq_event_get = mlx5_rx_devx_get_event,
1714 : : .rxq_obj_modify = mlx5_devx_modify_rq,
1715 : : .rxq_obj_release = mlx5_rxq_devx_obj_release,
1716 : : .rxq_event_get_lwm = mlx5_rx_devx_get_event_lwm,
1717 : : .ind_table_new = mlx5_devx_ind_table_new,
1718 : : .ind_table_modify = mlx5_devx_ind_table_modify,
1719 : : .ind_table_destroy = mlx5_devx_ind_table_destroy,
1720 : : .hrxq_new = mlx5_devx_hrxq_new,
1721 : : .hrxq_destroy = mlx5_devx_tir_destroy,
1722 : : .hrxq_modify = mlx5_devx_hrxq_modify,
1723 : : .drop_action_create = mlx5_devx_drop_action_create,
1724 : : .drop_action_destroy = mlx5_devx_drop_action_destroy,
1725 : : .txq_obj_new = mlx5_txq_devx_obj_new,
1726 : : .txq_obj_modify = mlx5_txq_devx_modify,
1727 : : .txq_obj_release = mlx5_txq_devx_obj_release,
1728 : : .lb_dummy_queue_create = NULL,
1729 : : .lb_dummy_queue_release = NULL,
1730 : : };
|