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