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