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