Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2015 6WIND S.A.
3 : : * Copyright 2015 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stddef.h>
7 : : #include <unistd.h>
8 : : #include <string.h>
9 : : #include <stdint.h>
10 : : #include <stdlib.h>
11 : : #include <errno.h>
12 : :
13 : : #include <ethdev_driver.h>
14 : : #include <bus_pci_driver.h>
15 : : #include <rte_mbuf.h>
16 : : #include <rte_common.h>
17 : : #include <rte_interrupts.h>
18 : : #include <rte_malloc.h>
19 : : #include <rte_string_fns.h>
20 : : #include <rte_rwlock.h>
21 : : #include <rte_cycles.h>
22 : :
23 : : #include <mlx5_malloc.h>
24 : :
25 : : #include "mlx5_rxtx.h"
26 : : #include "mlx5_rx.h"
27 : : #include "mlx5_tx.h"
28 : : #include "mlx5_autoconf.h"
29 : : #include "mlx5_devx.h"
30 : : #include "rte_pmd_mlx5.h"
31 : :
32 : : /**
33 : : * Get the interface index from device name.
34 : : *
35 : : * @param[in] dev
36 : : * Pointer to Ethernet device.
37 : : *
38 : : * @return
39 : : * Nonzero interface index on success, zero otherwise and rte_errno is set.
40 : : */
41 : : unsigned int
42 : 0 : mlx5_ifindex(const struct rte_eth_dev *dev)
43 : : {
44 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
45 : : unsigned int ifindex;
46 : :
47 : : MLX5_ASSERT(priv);
48 : : MLX5_ASSERT(priv->if_index);
49 [ # # # # ]: 0 : if (priv->master && priv->sh->bond.ifindex > 0)
50 : : ifindex = priv->sh->bond.ifindex;
51 : : else
52 : 0 : ifindex = priv->if_index;
53 [ # # ]: 0 : if (!ifindex)
54 : 0 : rte_errno = ENXIO;
55 : 0 : return ifindex;
56 : : }
57 : :
58 : : /**
59 : : * DPDK callback for Ethernet device configuration.
60 : : *
61 : : * @param dev
62 : : * Pointer to Ethernet device structure.
63 : : *
64 : : * @return
65 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
66 : : */
67 : : int
68 : 0 : mlx5_dev_configure(struct rte_eth_dev *dev)
69 : : {
70 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
71 : 0 : unsigned int rxqs_n = dev->data->nb_rx_queues;
72 : 0 : unsigned int txqs_n = dev->data->nb_tx_queues;
73 : : const uint8_t use_app_rss_key =
74 : 0 : !!dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key;
75 : : int ret = 0;
76 : :
77 [ # # ]: 0 : if (use_app_rss_key &&
78 [ # # ]: 0 : (dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key_len !=
79 : : MLX5_RSS_HASH_KEY_LEN)) {
80 : 0 : DRV_LOG(ERR, "port %u RSS key len must be %s Bytes long",
81 : : dev->data->port_id, RTE_STR(MLX5_RSS_HASH_KEY_LEN));
82 : 0 : rte_errno = EINVAL;
83 : 0 : return -rte_errno;
84 : : }
85 : 0 : priv->rss_conf.rss_key = mlx5_realloc(priv->rss_conf.rss_key,
86 : : MLX5_MEM_RTE,
87 : : MLX5_RSS_HASH_KEY_LEN, 0,
88 : : SOCKET_ID_ANY);
89 [ # # ]: 0 : if (!priv->rss_conf.rss_key) {
90 : 0 : DRV_LOG(ERR, "port %u cannot allocate RSS hash key memory (%u)",
91 : : dev->data->port_id, rxqs_n);
92 : 0 : rte_errno = ENOMEM;
93 : 0 : return -rte_errno;
94 : : }
95 : :
96 [ # # ]: 0 : if ((dev->data->dev_conf.txmode.offloads &
97 [ # # ]: 0 : RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) &&
98 : 0 : rte_mbuf_dyn_tx_timestamp_register(NULL, NULL) != 0) {
99 : 0 : DRV_LOG(ERR, "port %u cannot register Tx timestamp field/flag",
100 : : dev->data->port_id);
101 : 0 : return -rte_errno;
102 : : }
103 [ # # ]: 0 : memcpy(priv->rss_conf.rss_key,
104 : : use_app_rss_key ?
105 : 0 : dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key :
106 : : mlx5_rss_hash_default_key,
107 : : MLX5_RSS_HASH_KEY_LEN);
108 : 0 : priv->rss_conf.rss_key_len = MLX5_RSS_HASH_KEY_LEN;
109 : 0 : priv->rss_conf.rss_hf = dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
110 : 0 : priv->rxq_privs = mlx5_realloc(priv->rxq_privs,
111 : : MLX5_MEM_RTE | MLX5_MEM_ZERO,
112 : : sizeof(void *) * rxqs_n, 0,
113 : : SOCKET_ID_ANY);
114 [ # # # # ]: 0 : if (rxqs_n && priv->rxq_privs == NULL) {
115 : 0 : DRV_LOG(ERR, "port %u cannot allocate rxq private data",
116 : : dev->data->port_id);
117 : 0 : rte_errno = ENOMEM;
118 : 0 : return -rte_errno;
119 : : }
120 : 0 : priv->txqs = (void *)dev->data->tx_queues;
121 [ # # ]: 0 : if (txqs_n != priv->txqs_n) {
122 : 0 : DRV_LOG(INFO, "port %u Tx queues number update: %u -> %u",
123 : : dev->data->port_id, priv->txqs_n, txqs_n);
124 : 0 : priv->txqs_n = txqs_n;
125 : : }
126 [ # # # # ]: 0 : if (priv->ext_txqs && txqs_n >= MLX5_EXTERNAL_TX_QUEUE_ID_MIN) {
127 : 0 : DRV_LOG(ERR, "port %u cannot handle this many Tx queues (%u), "
128 : : "the maximal number of internal Tx queues is %u",
129 : : dev->data->port_id, txqs_n,
130 : : MLX5_EXTERNAL_TX_QUEUE_ID_MIN - 1);
131 : 0 : rte_errno = EINVAL;
132 : 0 : return -rte_errno;
133 : : }
134 [ # # ]: 0 : if (rxqs_n > priv->sh->dev_cap.ind_table_max_size) {
135 : 0 : DRV_LOG(ERR, "port %u cannot handle this many Rx queues (%u)",
136 : : dev->data->port_id, rxqs_n);
137 : 0 : rte_errno = EINVAL;
138 : 0 : return -rte_errno;
139 : : }
140 [ # # # # ]: 0 : if (priv->ext_rxqs && rxqs_n >= RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN) {
141 : 0 : DRV_LOG(ERR, "port %u cannot handle this many Rx queues (%u), "
142 : : "the maximal number of internal Rx queues is %u",
143 : : dev->data->port_id, rxqs_n,
144 : : RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN - 1);
145 : 0 : rte_errno = EINVAL;
146 : 0 : return -rte_errno;
147 : : }
148 [ # # ]: 0 : if (rxqs_n != priv->rxqs_n) {
149 : 0 : DRV_LOG(INFO, "port %u Rx queues number update: %u -> %u",
150 : : dev->data->port_id, priv->rxqs_n, rxqs_n);
151 : 0 : priv->rxqs_n = rxqs_n;
152 : : }
153 : 0 : priv->skip_default_rss_reta = 0;
154 : 0 : ret = mlx5_proc_priv_init(dev);
155 [ # # ]: 0 : if (ret)
156 : : return ret;
157 : 0 : ret = mlx5_dev_set_mtu(dev, dev->data->mtu);
158 [ # # ]: 0 : if (ret) {
159 : 0 : DRV_LOG(ERR, "port %u failed to set MTU to %u", dev->data->port_id,
160 : : dev->data->mtu);
161 : 0 : return ret;
162 : : }
163 : : return 0;
164 : : }
165 : :
166 : : /**
167 : : * Configure default RSS reta.
168 : : *
169 : : * @param dev
170 : : * Pointer to Ethernet device structure.
171 : : *
172 : : * @return
173 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
174 : : */
175 : : int
176 : 0 : mlx5_dev_configure_rss_reta(struct rte_eth_dev *dev)
177 : : {
178 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
179 : 0 : unsigned int rxqs_n = dev->data->nb_rx_queues;
180 : : unsigned int i;
181 : : unsigned int j;
182 : : unsigned int reta_idx_n;
183 : : int ret = 0;
184 : : unsigned int *rss_queue_arr = NULL;
185 : : unsigned int rss_queue_n = 0;
186 : :
187 [ # # ]: 0 : if (priv->skip_default_rss_reta)
188 : : return ret;
189 : 0 : rss_queue_arr = mlx5_malloc(0, rxqs_n * sizeof(unsigned int), 0,
190 : : SOCKET_ID_ANY);
191 [ # # ]: 0 : if (!rss_queue_arr) {
192 : 0 : DRV_LOG(ERR, "port %u cannot allocate RSS queue list (%u)",
193 : : dev->data->port_id, rxqs_n);
194 : 0 : rte_errno = ENOMEM;
195 : 0 : return -rte_errno;
196 : : }
197 [ # # ]: 0 : for (i = 0, j = 0; i < rxqs_n; i++) {
198 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
199 : :
200 [ # # # # ]: 0 : if (rxq_ctrl && !rxq_ctrl->is_hairpin)
201 : 0 : rss_queue_arr[j++] = i;
202 : : }
203 : : rss_queue_n = j;
204 [ # # ]: 0 : if (rss_queue_n > priv->sh->dev_cap.ind_table_max_size) {
205 : 0 : DRV_LOG(ERR, "port %u cannot handle this many Rx queues (%u)",
206 : : dev->data->port_id, rss_queue_n);
207 : 0 : rte_errno = EINVAL;
208 : 0 : mlx5_free(rss_queue_arr);
209 : 0 : return -rte_errno;
210 : : }
211 : 0 : DRV_LOG(INFO, "port %u Rx queues number update: %u -> %u",
212 : : dev->data->port_id, priv->rxqs_n, rxqs_n);
213 : 0 : priv->rxqs_n = rxqs_n;
214 : : /*
215 : : * If the requested number of RX queues is not a power of two,
216 : : * use the maximum indirection table size for better balancing.
217 : : * The result is always rounded to the next power of two.
218 : : */
219 [ # # ]: 0 : reta_idx_n = (1 << log2above((rss_queue_n & (rss_queue_n - 1)) ?
220 : 0 : priv->sh->dev_cap.ind_table_max_size :
221 : : rss_queue_n));
222 : 0 : ret = mlx5_rss_reta_index_resize(dev, reta_idx_n);
223 [ # # ]: 0 : if (ret) {
224 : 0 : mlx5_free(rss_queue_arr);
225 : 0 : return ret;
226 : : }
227 : : /*
228 : : * When the number of RX queues is not a power of two,
229 : : * the remaining table entries are padded with reused WQs
230 : : * and hashes are not spread uniformly.
231 : : */
232 [ # # ]: 0 : for (i = 0, j = 0; (i != reta_idx_n); ++i) {
233 : 0 : (*priv->reta_idx)[i] = rss_queue_arr[j];
234 [ # # ]: 0 : if (++j == rss_queue_n)
235 : : j = 0;
236 : : }
237 : 0 : mlx5_free(rss_queue_arr);
238 : 0 : return ret;
239 : : }
240 : :
241 : : /**
242 : : * Sets default tuning parameters.
243 : : *
244 : : * @param dev
245 : : * Pointer to Ethernet device.
246 : : * @param[out] info
247 : : * Info structure output buffer.
248 : : */
249 : : static void
250 : 0 : mlx5_set_default_params(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
251 : : {
252 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
253 : :
254 : : /* Minimum CPU utilization. */
255 : 0 : info->default_rxportconf.ring_size = 256;
256 : 0 : info->default_txportconf.ring_size = 256;
257 : 0 : info->default_rxportconf.burst_size = MLX5_RX_DEFAULT_BURST;
258 : 0 : info->default_txportconf.burst_size = MLX5_TX_DEFAULT_BURST;
259 [ # # ]: 0 : if (priv->link_speed_capa >> rte_bsf32(RTE_ETH_LINK_SPEED_100G)) {
260 : : /* if supports at least 100G */
261 : 0 : info->default_rxportconf.nb_queues = 16;
262 : 0 : info->default_txportconf.nb_queues = 16;
263 [ # # ]: 0 : if (dev->data->nb_rx_queues > 2 ||
264 [ # # ]: 0 : dev->data->nb_tx_queues > 2) {
265 : : /* Max Throughput. */
266 : 0 : info->default_rxportconf.ring_size = 2048;
267 : 0 : info->default_txportconf.ring_size = 2048;
268 : : }
269 : : } else {
270 : 0 : info->default_rxportconf.nb_queues = 8;
271 : 0 : info->default_txportconf.nb_queues = 8;
272 [ # # ]: 0 : if (dev->data->nb_rx_queues > 2 ||
273 [ # # ]: 0 : dev->data->nb_tx_queues > 2) {
274 : : /* Max Throughput. */
275 : 0 : info->default_rxportconf.ring_size = 4096;
276 : 0 : info->default_txportconf.ring_size = 4096;
277 : : }
278 : : }
279 : 0 : }
280 : :
281 : : /**
282 : : * Sets tx mbuf limiting parameters.
283 : : *
284 : : * @param dev
285 : : * Pointer to Ethernet device.
286 : : * @param[out] info
287 : : * Info structure output buffer.
288 : : */
289 : : static void
290 : : mlx5_set_txlimit_params(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
291 : : {
292 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
293 : : struct mlx5_port_config *config = &priv->config;
294 : : unsigned int inlen;
295 : : uint16_t nb_max;
296 : :
297 [ # # ]: 0 : inlen = (config->txq_inline_max == MLX5_ARG_UNSET) ?
298 : : MLX5_SEND_DEF_INLINE_LEN :
299 : : (unsigned int)config->txq_inline_max;
300 : : MLX5_ASSERT(config->txq_inline_min >= 0);
301 : 0 : inlen = RTE_MAX(inlen, (unsigned int)config->txq_inline_min);
302 : 0 : inlen = RTE_MIN(inlen, MLX5_WQE_SIZE_MAX +
303 : : MLX5_ESEG_MIN_INLINE_SIZE -
304 : : MLX5_WQE_CSEG_SIZE -
305 : : MLX5_WQE_ESEG_SIZE -
306 : : MLX5_WQE_DSEG_SIZE * 2);
307 : 0 : nb_max = (MLX5_WQE_SIZE_MAX +
308 : : MLX5_ESEG_MIN_INLINE_SIZE -
309 : : MLX5_WQE_CSEG_SIZE -
310 : : MLX5_WQE_ESEG_SIZE -
311 : 0 : MLX5_WQE_DSEG_SIZE -
312 : 0 : inlen) / MLX5_WSEG_SIZE;
313 : 0 : info->tx_desc_lim.nb_seg_max = nb_max;
314 : 0 : info->tx_desc_lim.nb_mtu_seg_max = nb_max;
315 : : }
316 : :
317 : : /**
318 : : * Get maximal work queue size in WQEs
319 : : *
320 : : * @param sh
321 : : * Pointer to the device shared context.
322 : : * @return
323 : : * Maximal number of WQEs in queue
324 : : */
325 : : uint16_t
326 : 0 : mlx5_dev_get_max_wq_size(struct mlx5_dev_ctx_shared *sh)
327 : : {
328 : : uint16_t max_wqe = MLX5_WQ_INDEX_MAX;
329 : :
330 [ # # ]: 0 : if (sh->cdev->config.devx) {
331 : : /* use HCA properties for DevX config */
332 : : MLX5_ASSERT(sh->cdev->config.hca_attr.log_max_wq_sz != 0);
333 : : MLX5_ASSERT(sh->cdev->config.hca_attr.log_max_wq_sz < MLX5_WQ_INDEX_WIDTH);
334 [ # # ]: 0 : if (sh->cdev->config.hca_attr.log_max_wq_sz != 0 &&
335 : : sh->cdev->config.hca_attr.log_max_wq_sz < MLX5_WQ_INDEX_WIDTH)
336 : 0 : max_wqe = 1u << sh->cdev->config.hca_attr.log_max_wq_sz;
337 : : } else {
338 : : /* use IB device capabilities */
339 : : MLX5_ASSERT(sh->dev_cap.max_qp_wr > 0);
340 : : MLX5_ASSERT((unsigned int)sh->dev_cap.max_qp_wr <= MLX5_WQ_INDEX_MAX);
341 [ # # ]: 0 : if (sh->dev_cap.max_qp_wr > 0 &&
342 : : (uint32_t)sh->dev_cap.max_qp_wr <= MLX5_WQ_INDEX_MAX)
343 : 0 : max_wqe = (uint16_t)sh->dev_cap.max_qp_wr;
344 : : }
345 : 0 : return max_wqe;
346 : : }
347 : :
348 : : /**
349 : : * DPDK callback to get information about the device.
350 : : *
351 : : * @param dev
352 : : * Pointer to Ethernet device structure.
353 : : * @param[out] info
354 : : * Info structure output buffer.
355 : : */
356 : : int
357 : 0 : mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
358 : : {
359 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
360 : : unsigned int max;
361 : : uint16_t max_wqe;
362 : :
363 : 0 : info->min_mtu = priv->min_mtu;
364 : 0 : info->max_mtu = priv->max_mtu;
365 : 0 : info->max_rx_pktlen = info->max_mtu + MLX5_ETH_OVERHEAD;
366 : : /* FIXME: we should ask the device for these values. */
367 : 0 : info->min_rx_bufsize = 32;
368 : 0 : info->max_lro_pkt_size = MLX5_MAX_LRO_SIZE;
369 : : /*
370 : : * Since we need one CQ per QP, the limit is the minimum number
371 : : * between the two values.
372 : : */
373 : 0 : max = RTE_MIN(priv->sh->dev_cap.max_cq, priv->sh->dev_cap.max_qp);
374 : : /* max_rx_queues is uint16_t. */
375 : 0 : max = RTE_MIN(max, (unsigned int)UINT16_MAX);
376 : 0 : info->max_rx_queues = max;
377 : 0 : info->max_tx_queues = max;
378 : 0 : info->max_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;
379 : 0 : info->rx_queue_offload_capa = mlx5_get_rx_queue_offloads(dev);
380 : 0 : info->rx_seg_capa.max_nseg = MLX5_MAX_RXQ_NSEG;
381 : 0 : info->rx_seg_capa.multi_pools = !priv->config.mprq.enabled;
382 : 0 : info->rx_seg_capa.offset_allowed = !priv->config.mprq.enabled;
383 : 0 : info->rx_seg_capa.offset_align_log2 = 0;
384 : 0 : info->rx_offload_capa = (mlx5_get_rx_port_offloads() |
385 : 0 : info->rx_queue_offload_capa);
386 : 0 : info->tx_offload_capa = mlx5_get_tx_port_offloads(dev);
387 : 0 : info->dev_capa = RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP;
388 : 0 : info->if_index = mlx5_ifindex(dev);
389 [ # # ]: 0 : info->reta_size = priv->reta_idx_n ?
390 : 0 : priv->reta_idx_n : priv->sh->dev_cap.ind_table_max_size;
391 : 0 : info->hash_key_size = MLX5_RSS_HASH_KEY_LEN;
392 : 0 : info->speed_capa = priv->link_speed_capa;
393 : 0 : info->flow_type_rss_offloads = ~MLX5_RSS_HF_MASK;
394 : 0 : mlx5_set_default_params(dev, info);
395 : : mlx5_set_txlimit_params(dev, info);
396 : 0 : max_wqe = mlx5_dev_get_max_wq_size(priv->sh);
397 : 0 : info->rx_desc_lim.nb_max = max_wqe;
398 : 0 : info->tx_desc_lim.nb_max = max_wqe;
399 [ # # ]: 0 : if (priv->sh->cdev->config.hca_attr.mem_rq_rmp &&
400 [ # # ]: 0 : priv->obj_ops.rxq_obj_new == mlx5_devx_obj_ops.rxq_obj_new)
401 : 0 : info->dev_capa |= RTE_ETH_DEV_CAPA_RXQ_SHARE;
402 : 0 : info->switch_info.name = dev->data->name;
403 : 0 : info->switch_info.domain_id = priv->domain_id;
404 : 0 : info->switch_info.port_id = priv->representor_id;
405 : 0 : info->switch_info.rx_domain = 0; /* No sub Rx domains. */
406 [ # # ]: 0 : if (priv->representor) {
407 : : uint16_t port_id;
408 : :
409 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
410 : 0 : struct mlx5_priv *opriv =
411 : 0 : rte_eth_devices[port_id].data->dev_private;
412 : :
413 [ # # # # ]: 0 : if (!opriv ||
414 : 0 : opriv->representor ||
415 [ # # ]: 0 : opriv->sh != priv->sh ||
416 [ # # ]: 0 : opriv->domain_id != priv->domain_id)
417 : : continue;
418 : : /*
419 : : * Override switch name with that of the master
420 : : * device.
421 : : */
422 : 0 : info->switch_info.name = opriv->dev_data->name;
423 : 0 : break;
424 : : }
425 : : }
426 : 0 : return 0;
427 : : }
428 : :
429 : : /**
430 : : * Calculate representor ID from port switch info.
431 : : *
432 : : * Uint16 representor ID bits definition:
433 : : * pf: 2
434 : : * type: 2
435 : : * vf/sf: 12
436 : : *
437 : : * @param info
438 : : * Port switch info.
439 : : * @param hpf_type
440 : : * Use this type if port is HPF.
441 : : *
442 : : * @return
443 : : * Encoded representor ID.
444 : : */
445 : : uint16_t
446 : 0 : mlx5_representor_id_encode(const struct mlx5_switch_info *info,
447 : : enum rte_eth_representor_type hpf_type)
448 : : {
449 : : enum rte_eth_representor_type type;
450 : 0 : uint16_t repr = info->port_name;
451 : 0 : int32_t pf = info->pf_num;
452 : :
453 [ # # # # ]: 0 : switch (info->name_type) {
454 : 0 : case MLX5_PHYS_PORT_NAME_TYPE_UPLINK:
455 [ # # ]: 0 : if (!info->representor)
456 : : return UINT16_MAX;
457 : : type = RTE_ETH_REPRESENTOR_PF;
458 : 0 : pf = info->mpesw_owner;
459 : 0 : break;
460 : : case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
461 : : type = RTE_ETH_REPRESENTOR_SF;
462 : : break;
463 : 0 : case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
464 : : type = hpf_type;
465 : : repr = UINT16_MAX;
466 : 0 : break;
467 : 0 : case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
468 : : default:
469 : : type = RTE_ETH_REPRESENTOR_VF;
470 : 0 : break;
471 : : }
472 : 0 : return MLX5_REPRESENTOR_ID(pf, type, repr);
473 : : }
474 : :
475 : : /**
476 : : * DPDK callback to get information about representor.
477 : : *
478 : : * Representor ID bits definition:
479 : : * vf/sf: 12
480 : : * type: 2
481 : : * pf: 2
482 : : *
483 : : * @param dev
484 : : * Pointer to Ethernet device structure.
485 : : * @param[out] info
486 : : * Nullable info structure output buffer.
487 : : *
488 : : * @return
489 : : * negative on error, or the number of representor ranges.
490 : : */
491 : : int
492 : 0 : mlx5_representor_info_get(struct rte_eth_dev *dev,
493 : : struct rte_eth_representor_info *info)
494 : : {
495 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
496 : : /* Representor types: PF, VF, HPF@VF, SF and HPF@SF, total 5. */
497 : : int n_type = RTE_ETH_REPRESENTOR_PF + 2; /* Maximal type + 2 for HPFs. */
498 : : int n_pf = 8; /* Maximal number of PFs. */
499 : : int i = 0, pf;
500 : : int n_entries;
501 : :
502 [ # # ]: 0 : if (info == NULL)
503 : 0 : goto out;
504 : :
505 : : n_entries = n_type * n_pf;
506 [ # # ]: 0 : if ((uint32_t)n_entries > info->nb_ranges_alloc)
507 : : n_entries = info->nb_ranges_alloc;
508 : :
509 : 0 : info->controller = 0;
510 [ # # ]: 0 : info->pf = 0;
511 [ # # ]: 0 : if (mlx5_is_port_on_mpesw_device(priv)) {
512 : 0 : info->pf = priv->mpesw_port;
513 [ # # ]: 0 : for (i = 0; i < n_pf; i++) {
514 : : /* PF range, both ports will show the same information. */
515 : 0 : info->ranges[i].type = RTE_ETH_REPRESENTOR_PF;
516 : 0 : info->ranges[i].controller = 0;
517 : 0 : info->ranges[i].pf = priv->mpesw_owner + i + 1;
518 : 0 : info->ranges[i].vf = 0;
519 : : /*
520 : : * The representor indexes should be the values set of "priv->mpesw_port".
521 : : * In the real case now, only 1 PF/UPLINK representor is supported.
522 : : * The port index will always be the value of "owner + 1".
523 : : */
524 : 0 : info->ranges[i].id_base =
525 : 0 : MLX5_REPRESENTOR_ID(priv->mpesw_owner,
526 : : info->ranges[i].type,
527 : : info->ranges[i].pf);
528 : 0 : info->ranges[i].id_end =
529 : : MLX5_REPRESENTOR_ID(priv->mpesw_owner,
530 : : info->ranges[i].type,
531 : : info->ranges[i].pf);
532 : 0 : snprintf(info->ranges[i].name,
533 : : sizeof(info->ranges[i].name),
534 : : "pf%d", info->ranges[i].pf);
535 : : }
536 [ # # ]: 0 : } else if (priv->pf_bond >= 0)
537 : 0 : info->pf = priv->pf_bond;
538 [ # # ]: 0 : for (pf = 0; pf < n_pf; ++pf) {
539 : : /* VF range. */
540 : 0 : info->ranges[i].type = RTE_ETH_REPRESENTOR_VF;
541 : 0 : info->ranges[i].controller = 0;
542 : 0 : info->ranges[i].pf = pf;
543 : 0 : info->ranges[i].vf = 0;
544 : 0 : info->ranges[i].id_base =
545 : 0 : MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, 0);
546 : 0 : info->ranges[i].id_end =
547 : 0 : MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, -1);
548 [ # # ]: 0 : snprintf(info->ranges[i].name,
549 : : sizeof(info->ranges[i].name), "pf%dvf", pf);
550 : 0 : i++;
551 [ # # ]: 0 : if (i == n_entries)
552 : : break;
553 : : /* HPF range of VF type. */
554 : 0 : info->ranges[i].type = RTE_ETH_REPRESENTOR_VF;
555 : 0 : info->ranges[i].controller = 0;
556 : 0 : info->ranges[i].pf = pf;
557 : 0 : info->ranges[i].vf = UINT16_MAX;
558 : 0 : info->ranges[i].id_base =
559 : : MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, -1);
560 : 0 : info->ranges[i].id_end =
561 : : MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, -1);
562 [ # # ]: 0 : snprintf(info->ranges[i].name,
563 : : sizeof(info->ranges[i].name), "pf%dvf", pf);
564 : 0 : i++;
565 [ # # ]: 0 : if (i == n_entries)
566 : : break;
567 : : /* SF range. */
568 : 0 : info->ranges[i].type = RTE_ETH_REPRESENTOR_SF;
569 : 0 : info->ranges[i].controller = 0;
570 : 0 : info->ranges[i].pf = pf;
571 : 0 : info->ranges[i].vf = 0;
572 : 0 : info->ranges[i].id_base =
573 : 0 : MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, 0);
574 : 0 : info->ranges[i].id_end =
575 : 0 : MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, -1);
576 [ # # ]: 0 : snprintf(info->ranges[i].name,
577 : : sizeof(info->ranges[i].name), "pf%dsf", pf);
578 : 0 : i++;
579 [ # # ]: 0 : if (i == n_entries)
580 : : break;
581 : : /* HPF range of SF type. */
582 : 0 : info->ranges[i].type = RTE_ETH_REPRESENTOR_SF;
583 : 0 : info->ranges[i].controller = 0;
584 : 0 : info->ranges[i].pf = pf;
585 : 0 : info->ranges[i].vf = UINT16_MAX;
586 : 0 : info->ranges[i].id_base =
587 : : MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, -1);
588 : 0 : info->ranges[i].id_end =
589 : : MLX5_REPRESENTOR_ID(pf, info->ranges[i].type, -1);
590 [ # # ]: 0 : snprintf(info->ranges[i].name,
591 : : sizeof(info->ranges[i].name), "pf%dsf", pf);
592 : 0 : i++;
593 [ # # ]: 0 : if (i == n_entries)
594 : : break;
595 : : }
596 : 0 : info->nb_ranges = i;
597 : 0 : out:
598 : 0 : return n_type * n_pf;
599 : : }
600 : :
601 : : /**
602 : : * Get firmware version of a device.
603 : : *
604 : : * @param dev
605 : : * Ethernet device port.
606 : : * @param fw_ver
607 : : * String output allocated by caller.
608 : : * @param fw_size
609 : : * Size of the output string, including terminating null byte.
610 : : *
611 : : * @return
612 : : * 0 on success, or the size of the non truncated string if too big.
613 : : */
614 : : int
615 : 0 : mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
616 : : {
617 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
618 : 0 : struct mlx5_dev_cap *attr = &priv->sh->dev_cap;
619 : 0 : size_t size = strnlen(attr->fw_ver, sizeof(attr->fw_ver)) + 1;
620 : :
621 [ # # ]: 0 : if (fw_size < size)
622 : 0 : return size;
623 [ # # ]: 0 : if (fw_ver != NULL)
624 : : strlcpy(fw_ver, attr->fw_ver, fw_size);
625 : : return 0;
626 : : }
627 : :
628 : : /**
629 : : * Get supported packet types.
630 : : *
631 : : * @param dev
632 : : * Pointer to Ethernet device structure.
633 : : *
634 : : * @return
635 : : * A pointer to the supported Packet types array.
636 : : */
637 : : const uint32_t *
638 : 0 : mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
639 : : {
640 : : static const uint32_t ptypes[] = {
641 : : /* refers to rxq_cq_to_pkt_type() */
642 : : RTE_PTYPE_L2_ETHER,
643 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
644 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
645 : : RTE_PTYPE_L4_NONFRAG,
646 : : RTE_PTYPE_L4_FRAG,
647 : : RTE_PTYPE_L4_TCP,
648 : : RTE_PTYPE_L4_UDP,
649 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
650 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
651 : : RTE_PTYPE_INNER_L4_NONFRAG,
652 : : RTE_PTYPE_INNER_L4_FRAG,
653 : : RTE_PTYPE_INNER_L4_TCP,
654 : : RTE_PTYPE_INNER_L4_UDP,
655 : : };
656 : :
657 [ # # # # ]: 0 : if (dev->rx_pkt_burst == mlx5_rx_burst ||
658 [ # # ]: 0 : dev->rx_pkt_burst == mlx5_rx_burst_out_of_order ||
659 [ # # ]: 0 : dev->rx_pkt_burst == mlx5_rx_burst_mprq ||
660 [ # # ]: 0 : dev->rx_pkt_burst == mlx5_rx_burst_vec ||
661 : : dev->rx_pkt_burst == mlx5_rx_burst_mprq_vec) {
662 : 0 : *no_of_elements = RTE_DIM(ptypes);
663 : 0 : return ptypes;
664 : : }
665 : : return NULL;
666 : : }
667 : :
668 : : /**
669 : : * DPDK callback to change the MTU.
670 : : *
671 : : * @param dev
672 : : * Pointer to Ethernet device structure.
673 : : * @param in_mtu
674 : : * New MTU.
675 : : *
676 : : * @return
677 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
678 : : */
679 : : int
680 : 0 : mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
681 : : {
682 : 0 : uint16_t kern_mtu = 0;
683 : : int ret;
684 : :
685 : 0 : ret = mlx5_get_mtu(dev, &kern_mtu);
686 [ # # ]: 0 : if (ret)
687 : : return ret;
688 : :
689 [ # # ]: 0 : if (kern_mtu == mtu) {
690 : 0 : DRV_LOG(DEBUG, "port %u adapter MTU was already set to %u",
691 : : dev->data->port_id, mtu);
692 : 0 : return 0;
693 : : }
694 : :
695 : : /* Set kernel interface MTU first. */
696 : 0 : ret = mlx5_set_mtu(dev, mtu);
697 [ # # ]: 0 : if (ret)
698 : : return ret;
699 : 0 : ret = mlx5_get_mtu(dev, &kern_mtu);
700 [ # # ]: 0 : if (ret)
701 : : return ret;
702 [ # # ]: 0 : if (kern_mtu == mtu) {
703 : 0 : DRV_LOG(DEBUG, "port %u adapter MTU set to %u",
704 : : dev->data->port_id, mtu);
705 : 0 : return 0;
706 : : }
707 : 0 : rte_errno = EAGAIN;
708 : 0 : return -rte_errno;
709 : : }
710 : :
711 : : /**
712 : : * Configure the RX function to use.
713 : : *
714 : : * @param dev
715 : : * Pointer to private data structure.
716 : : *
717 : : * @return
718 : : * Pointer to selected Rx burst function.
719 : : */
720 : : eth_rx_burst_t
721 [ # # ]: 0 : mlx5_select_rx_function(struct rte_eth_dev *dev)
722 : : {
723 : : eth_rx_burst_t rx_pkt_burst = mlx5_rx_burst;
724 : :
725 : : MLX5_ASSERT(dev != NULL);
726 [ # # ]: 0 : if (mlx5_shared_rq_enabled(dev)) {
727 : : rx_pkt_burst = mlx5_rx_burst_out_of_order;
728 : 0 : DRV_LOG(DEBUG, "port %u forced to use SPRQ"
729 : : " Rx function with Out-of-Order completions",
730 : : dev->data->port_id);
731 [ # # ]: 0 : } else if (mlx5_check_vec_rx_support(dev) > 0) {
732 [ # # ]: 0 : if (mlx5_mprq_enabled(dev)) {
733 : : rx_pkt_burst = mlx5_rx_burst_mprq_vec;
734 : 0 : DRV_LOG(DEBUG, "port %u selected vectorized"
735 : : " MPRQ Rx function", dev->data->port_id);
736 : : } else {
737 : : rx_pkt_burst = mlx5_rx_burst_vec;
738 : 0 : DRV_LOG(DEBUG, "port %u selected vectorized"
739 : : " SPRQ Rx function", dev->data->port_id);
740 : : }
741 [ # # ]: 0 : } else if (mlx5_mprq_enabled(dev)) {
742 : : rx_pkt_burst = mlx5_rx_burst_mprq;
743 : 0 : DRV_LOG(DEBUG, "port %u selected MPRQ Rx function",
744 : : dev->data->port_id);
745 : : } else {
746 : 0 : DRV_LOG(DEBUG, "port %u selected SPRQ Rx function",
747 : : dev->data->port_id);
748 : : }
749 : 0 : return rx_pkt_burst;
750 : : }
751 : :
752 : : /**
753 : : * Get the E-Switch parameters by port id.
754 : : *
755 : : * @param[in] port
756 : : * Device port id.
757 : : * @param[in] valid
758 : : * Device port id is valid, skip check. This flag is useful
759 : : * when trials are performed from probing and device is not
760 : : * flagged as valid yet (in attaching process).
761 : : * @param[out] es_domain_id
762 : : * E-Switch domain id.
763 : : * @param[out] es_port_id
764 : : * The port id of the port in the E-Switch.
765 : : *
766 : : * @return
767 : : * pointer to device private data structure containing data needed
768 : : * on success, NULL otherwise and rte_errno is set.
769 : : */
770 : : struct mlx5_priv *
771 : 0 : mlx5_port_to_eswitch_info(uint16_t port, bool valid)
772 : : {
773 : : struct rte_eth_dev *dev;
774 : : struct mlx5_priv *priv;
775 : :
776 [ # # ]: 0 : if (port >= RTE_MAX_ETHPORTS) {
777 : 0 : rte_errno = EINVAL;
778 : 0 : return NULL;
779 : : }
780 [ # # # # ]: 0 : if (!valid && !rte_eth_dev_is_valid_port(port)) {
781 : 0 : rte_errno = ENODEV;
782 : 0 : return NULL;
783 : : }
784 : 0 : dev = &rte_eth_devices[port];
785 : 0 : priv = dev->data->dev_private;
786 [ # # ]: 0 : if (!priv->sh->esw_mode) {
787 : 0 : rte_errno = EINVAL;
788 : 0 : return NULL;
789 : : }
790 : : return priv;
791 : : }
792 : :
793 : : /**
794 : : * Get the E-Switch parameters by device instance.
795 : : *
796 : : * @param[in] port
797 : : * Device port id.
798 : : * @param[out] es_domain_id
799 : : * E-Switch domain id.
800 : : * @param[out] es_port_id
801 : : * The port id of the port in the E-Switch.
802 : : *
803 : : * @return
804 : : * pointer to device private data structure containing data needed
805 : : * on success, NULL otherwise and rte_errno is set.
806 : : */
807 : : struct mlx5_priv *
808 : 0 : mlx5_dev_to_eswitch_info(struct rte_eth_dev *dev)
809 : : {
810 : : struct mlx5_priv *priv;
811 : :
812 : 0 : priv = dev->data->dev_private;
813 [ # # ]: 0 : if (!priv->sh->esw_mode) {
814 : 0 : rte_errno = EINVAL;
815 : 0 : return NULL;
816 : : }
817 : : return priv;
818 : : }
819 : :
820 : : /**
821 : : * DPDK callback to retrieve hairpin capabilities.
822 : : *
823 : : * @param dev
824 : : * Pointer to Ethernet device structure.
825 : : * @param[out] cap
826 : : * Storage for hairpin capability data.
827 : : *
828 : : * @return
829 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
830 : : */
831 : : int
832 : 0 : mlx5_hairpin_cap_get(struct rte_eth_dev *dev, struct rte_eth_hairpin_cap *cap)
833 : : {
834 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
835 : : struct mlx5_hca_attr *hca_attr;
836 : :
837 [ # # # # ]: 0 : if (!mlx5_devx_obj_ops_en(priv->sh)) {
838 : 0 : rte_errno = ENOTSUP;
839 : 0 : return -rte_errno;
840 : : }
841 : 0 : cap->max_nb_queues = UINT16_MAX;
842 : 0 : cap->max_rx_2_tx = 1;
843 : 0 : cap->max_tx_2_rx = 1;
844 : 0 : cap->max_nb_desc = 8192;
845 : : hca_attr = &priv->sh->cdev->config.hca_attr;
846 : 0 : cap->rx_cap.locked_device_memory = hca_attr->hairpin_data_buffer_locked;
847 : 0 : cap->rx_cap.rte_memory = 0;
848 : 0 : cap->tx_cap.locked_device_memory = 0;
849 : 0 : cap->tx_cap.rte_memory = hca_attr->hairpin_sq_wq_in_host_mem;
850 : 0 : return 0;
851 : : }
852 : :
853 : : /**
854 : : * Indicate to ethdev layer, what configuration must be restored.
855 : : *
856 : : * @param[in] dev
857 : : * Pointer to Ethernet device structure.
858 : : * @param[in] op
859 : : * Type of operation which might require.
860 : : * @param[out] flags
861 : : * Restore flags will be stored here.
862 : : */
863 : : uint64_t
864 : 0 : mlx5_get_restore_flags(__rte_unused struct rte_eth_dev *dev,
865 : : __rte_unused enum rte_eth_dev_operation op)
866 : : {
867 : : /* mlx5 PMD does not require any configuration restore. */
868 : 0 : return 0;
869 : : }
870 : :
871 : : /**
872 : : * Query minimum and maximum allowed MTU value on the device.
873 : : *
874 : : * This functions will always return valid MTU bounds.
875 : : * In case platform-specific implementation fails or current platform does not support it,
876 : : * the fallback default values will be used.
877 : : *
878 : : * @param[in] dev
879 : : * Pointer to Ethernet device
880 : : * @param[out] min_mtu
881 : : * Minimum MTU value output buffer.
882 : : * @param[out] max_mtu
883 : : * Maximum MTU value output buffer.
884 : : */
885 : : void
886 : 0 : mlx5_get_mtu_bounds(struct rte_eth_dev *dev, uint16_t *min_mtu, uint16_t *max_mtu)
887 : : {
888 : : int ret;
889 : :
890 : : MLX5_ASSERT(min_mtu != NULL);
891 : : MLX5_ASSERT(max_mtu != NULL);
892 : :
893 : 0 : ret = mlx5_os_get_mtu_bounds(dev, min_mtu, max_mtu);
894 [ # # ]: 0 : if (ret < 0) {
895 [ # # ]: 0 : if (ret != -ENOTSUP)
896 : 0 : DRV_LOG(INFO, "port %u failed to query MTU bounds, using fallback values",
897 : : dev->data->port_id);
898 : 0 : *min_mtu = MLX5_ETH_MIN_MTU;
899 : 0 : *max_mtu = MLX5_ETH_MAX_MTU;
900 : :
901 : : /* This function does not fail. Clear rte_errno. */
902 : 0 : rte_errno = 0;
903 : : }
904 : :
905 : 0 : DRV_LOG(INFO, "port %u minimum MTU is %u", dev->data->port_id, *min_mtu);
906 : 0 : DRV_LOG(INFO, "port %u maximum MTU is %u", dev->data->port_id, *max_mtu);
907 : 0 : }
|