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