1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
17 #include <sys/ioctl.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <linux/ethtool.h>
21 #include <linux/sockios.h>
27 #include <ethdev_driver.h>
28 #include <rte_bus_pci.h>
30 #include <rte_common.h>
31 #include <rte_interrupts.h>
32 #include <rte_malloc.h>
33 #include <rte_string_fns.h>
34 #include <rte_rwlock.h>
35 #include <rte_cycles.h>
37 #include <mlx5_glue.h>
38 #include <mlx5_devx_cmds.h>
39 #include <mlx5_common.h>
40 #include <mlx5_malloc.h>
43 #include "mlx5_rxtx.h"
44 #include "mlx5_utils.h"
46 /* Supported speed values found in /usr/include/linux/ethtool.h */
47 #ifndef HAVE_SUPPORTED_40000baseKR4_Full
48 #define SUPPORTED_40000baseKR4_Full (1 << 23)
50 #ifndef HAVE_SUPPORTED_40000baseCR4_Full
51 #define SUPPORTED_40000baseCR4_Full (1 << 24)
53 #ifndef HAVE_SUPPORTED_40000baseSR4_Full
54 #define SUPPORTED_40000baseSR4_Full (1 << 25)
56 #ifndef HAVE_SUPPORTED_40000baseLR4_Full
57 #define SUPPORTED_40000baseLR4_Full (1 << 26)
59 #ifndef HAVE_SUPPORTED_56000baseKR4_Full
60 #define SUPPORTED_56000baseKR4_Full (1 << 27)
62 #ifndef HAVE_SUPPORTED_56000baseCR4_Full
63 #define SUPPORTED_56000baseCR4_Full (1 << 28)
65 #ifndef HAVE_SUPPORTED_56000baseSR4_Full
66 #define SUPPORTED_56000baseSR4_Full (1 << 29)
68 #ifndef HAVE_SUPPORTED_56000baseLR4_Full
69 #define SUPPORTED_56000baseLR4_Full (1 << 30)
72 /* Add defines in case the running kernel is not the same as user headers. */
73 #ifndef ETHTOOL_GLINKSETTINGS
74 struct ethtool_link_settings {
83 uint8_t eth_tp_mdix_ctrl;
84 int8_t link_mode_masks_nwords;
86 uint32_t link_mode_masks[];
89 /* The kernel values can be found in /include/uapi/linux/ethtool.h */
90 #define ETHTOOL_GLINKSETTINGS 0x0000004c
91 #define ETHTOOL_LINK_MODE_1000baseT_Full_BIT 5
92 #define ETHTOOL_LINK_MODE_Autoneg_BIT 6
93 #define ETHTOOL_LINK_MODE_1000baseKX_Full_BIT 17
94 #define ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT 18
95 #define ETHTOOL_LINK_MODE_10000baseKR_Full_BIT 19
96 #define ETHTOOL_LINK_MODE_10000baseR_FEC_BIT 20
97 #define ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT 21
98 #define ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT 22
99 #define ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT 23
100 #define ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT 24
101 #define ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT 25
102 #define ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT 26
103 #define ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT 27
104 #define ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT 28
105 #define ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT 29
106 #define ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT 30
108 #ifndef HAVE_ETHTOOL_LINK_MODE_25G
109 #define ETHTOOL_LINK_MODE_25000baseCR_Full_BIT 31
110 #define ETHTOOL_LINK_MODE_25000baseKR_Full_BIT 32
111 #define ETHTOOL_LINK_MODE_25000baseSR_Full_BIT 33
113 #ifndef HAVE_ETHTOOL_LINK_MODE_50G
114 #define ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT 34
115 #define ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT 35
117 #ifndef HAVE_ETHTOOL_LINK_MODE_100G
118 #define ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT 36
119 #define ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT 37
120 #define ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT 38
121 #define ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT 39
123 #ifndef HAVE_ETHTOOL_LINK_MODE_200G
124 #define ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT 62
125 #define ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT 63
126 #define ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT 0 /* 64 - 64 */
127 #define ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT 1 /* 65 - 64 */
128 #define ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT 2 /* 66 - 64 */
131 /* Get interface index from SubFunction device name. */
133 mlx5_auxiliary_get_ifindex(const char *sf_name)
135 char if_name[IF_NAMESIZE] = { 0 };
137 if (mlx5_auxiliary_get_child_name(sf_name, "/net",
138 if_name, sizeof(if_name)) != 0)
140 return if_nametoindex(if_name);
144 * Get interface name from private structure.
146 * This is a port representor-aware version of mlx5_get_ifname_sysfs().
149 * Pointer to Ethernet device.
151 * Interface name output buffer.
154 * 0 on success, a negative errno value otherwise and rte_errno is set.
157 mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE])
159 struct mlx5_priv *priv = dev->data->dev_private;
160 unsigned int ifindex;
163 MLX5_ASSERT(priv->sh);
164 if (priv->master && priv->sh->bond.ifindex > 0) {
165 memcpy(ifname, priv->sh->bond.ifname, MLX5_NAMESIZE);
168 ifindex = mlx5_ifindex(dev);
170 if (!priv->representor)
171 return mlx5_get_ifname_sysfs(priv->sh->ibdev_path,
176 if (if_indextoname(ifindex, &(*ifname)[0]))
183 * Perform ifreq ioctl() on associated netdev ifname.
186 * Pointer to netdev name.
188 * Request number to pass to ioctl().
190 * Interface request structure output buffer.
193 * 0 on success, a negative errno value otherwise and rte_errno is set.
196 mlx5_ifreq_by_ifname(const char *ifname, int req, struct ifreq *ifr)
198 int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
205 rte_strscpy(ifr->ifr_name, ifname, sizeof(ifr->ifr_name));
206 ret = ioctl(sock, req, ifr);
219 * Perform ifreq ioctl() on associated Ethernet device.
222 * Pointer to Ethernet device.
224 * Request number to pass to ioctl().
226 * Interface request structure output buffer.
229 * 0 on success, a negative errno value otherwise and rte_errno is set.
232 mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr)
234 char ifname[sizeof(ifr->ifr_name)];
237 ret = mlx5_get_ifname(dev, &ifname);
240 return mlx5_ifreq_by_ifname(ifname, req, ifr);
247 * Pointer to Ethernet device.
249 * MTU value output buffer.
252 * 0 on success, a negative errno value otherwise and rte_errno is set.
255 mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu)
257 struct ifreq request;
258 int ret = mlx5_ifreq(dev, SIOCGIFMTU, &request);
262 *mtu = request.ifr_mtu;
270 * Pointer to Ethernet device.
275 * 0 on success, a negative errno value otherwise and rte_errno is set.
278 mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
280 struct ifreq request = { .ifr_mtu = mtu, };
282 return mlx5_ifreq(dev, SIOCSIFMTU, &request);
289 * Pointer to Ethernet device.
291 * Bitmask for flags that must remain untouched.
293 * Bitmask for flags to modify.
296 * 0 on success, a negative errno value otherwise and rte_errno is set.
299 mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, unsigned int flags)
301 struct ifreq request;
302 int ret = mlx5_ifreq(dev, SIOCGIFFLAGS, &request);
306 request.ifr_flags &= keep;
307 request.ifr_flags |= flags & ~keep;
308 return mlx5_ifreq(dev, SIOCSIFFLAGS, &request);
312 * Get device current raw clock counter
315 * Pointer to Ethernet device structure.
317 * Current raw clock counter of the device.
320 * 0 if the clock has correctly been read
321 * The value of errno in case of error
324 mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
326 struct mlx5_priv *priv = dev->data->dev_private;
327 struct ibv_context *ctx = priv->sh->cdev->ctx;
328 struct ibv_values_ex values;
331 values.comp_mask = IBV_VALUES_MASK_RAW_CLOCK;
332 err = mlx5_glue->query_rt_values_ex(ctx, &values);
334 DRV_LOG(WARNING, "Could not query the clock !");
337 *clock = values.raw_clock.tv_nsec;
342 * Retrieve the master device for representor in the same switch domain.
345 * Pointer to representor Ethernet device structure.
348 * Master device structure on success, NULL otherwise.
350 static struct rte_eth_dev *
351 mlx5_find_master_dev(struct rte_eth_dev *dev)
353 struct mlx5_priv *priv;
357 priv = dev->data->dev_private;
358 domain_id = priv->domain_id;
359 MLX5_ASSERT(priv->representor);
360 MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
361 struct mlx5_priv *opriv =
362 rte_eth_devices[port_id].data->dev_private;
365 opriv->domain_id == domain_id &&
366 opriv->sh == priv->sh)
367 return &rte_eth_devices[port_id];
373 * DPDK callback to retrieve physical link information.
376 * Pointer to Ethernet device structure.
378 * Storage for current link status.
381 * 0 on success, a negative errno value otherwise and rte_errno is set.
384 mlx5_link_update_unlocked_gset(struct rte_eth_dev *dev,
385 struct rte_eth_link *link)
387 struct mlx5_priv *priv = dev->data->dev_private;
388 struct ethtool_cmd edata = {
389 .cmd = ETHTOOL_GSET /* Deprecated since Linux v4.5. */
392 struct rte_eth_link dev_link;
396 ret = mlx5_ifreq(dev, SIOCGIFFLAGS, &ifr);
398 DRV_LOG(WARNING, "port %u ioctl(SIOCGIFFLAGS) failed: %s",
399 dev->data->port_id, strerror(rte_errno));
402 dev_link = (struct rte_eth_link) {
403 .link_status = ((ifr.ifr_flags & IFF_UP) &&
404 (ifr.ifr_flags & IFF_RUNNING)),
406 ifr = (struct ifreq) {
407 .ifr_data = (void *)&edata,
409 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
411 if (ret == -ENOTSUP && priv->representor) {
412 struct rte_eth_dev *master;
415 * For representors we can try to inherit link
416 * settings from the master device. Actually
417 * link settings do not make a lot of sense
418 * for representors due to missing physical
419 * link. The old kernel drivers supported
420 * emulated settings query for representors,
421 * the new ones do not, so we have to add
422 * this code for compatibility issues.
424 master = mlx5_find_master_dev(dev);
426 ifr = (struct ifreq) {
427 .ifr_data = (void *)&edata,
429 ret = mlx5_ifreq(master, SIOCETHTOOL, &ifr);
434 "port %u ioctl(SIOCETHTOOL,"
435 " ETHTOOL_GSET) failed: %s",
436 dev->data->port_id, strerror(rte_errno));
440 link_speed = ethtool_cmd_speed(&edata);
441 if (link_speed == -1)
442 dev_link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
444 dev_link.link_speed = link_speed;
445 priv->link_speed_capa = 0;
446 if (edata.supported & (SUPPORTED_1000baseT_Full |
447 SUPPORTED_1000baseKX_Full))
448 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_1G;
449 if (edata.supported & SUPPORTED_10000baseKR_Full)
450 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_10G;
451 if (edata.supported & (SUPPORTED_40000baseKR4_Full |
452 SUPPORTED_40000baseCR4_Full |
453 SUPPORTED_40000baseSR4_Full |
454 SUPPORTED_40000baseLR4_Full))
455 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_40G;
456 dev_link.link_duplex = ((edata.duplex == DUPLEX_HALF) ?
457 RTE_ETH_LINK_HALF_DUPLEX : RTE_ETH_LINK_FULL_DUPLEX);
458 dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
459 RTE_ETH_LINK_SPEED_FIXED);
465 * Retrieve physical link information (unlocked version using new ioctl).
468 * Pointer to Ethernet device structure.
470 * Storage for current link status.
473 * 0 on success, a negative errno value otherwise and rte_errno is set.
476 mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev,
477 struct rte_eth_link *link)
480 struct mlx5_priv *priv = dev->data->dev_private;
481 struct ethtool_link_settings gcmd = { .cmd = ETHTOOL_GLINKSETTINGS };
483 struct rte_eth_link dev_link;
484 struct rte_eth_dev *master = NULL;
488 ret = mlx5_ifreq(dev, SIOCGIFFLAGS, &ifr);
490 DRV_LOG(WARNING, "port %u ioctl(SIOCGIFFLAGS) failed: %s",
491 dev->data->port_id, strerror(rte_errno));
494 dev_link = (struct rte_eth_link) {
495 .link_status = ((ifr.ifr_flags & IFF_UP) &&
496 (ifr.ifr_flags & IFF_RUNNING)),
498 ifr = (struct ifreq) {
499 .ifr_data = (void *)&gcmd,
501 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
503 if (ret == -ENOTSUP && priv->representor) {
505 * For representors we can try to inherit link
506 * settings from the master device. Actually
507 * link settings do not make a lot of sense
508 * for representors due to missing physical
509 * link. The old kernel drivers supported
510 * emulated settings query for representors,
511 * the new ones do not, so we have to add
512 * this code for compatibility issues.
514 master = mlx5_find_master_dev(dev);
516 ifr = (struct ifreq) {
517 .ifr_data = (void *)&gcmd,
519 ret = mlx5_ifreq(master, SIOCETHTOOL, &ifr);
524 "port %u ioctl(SIOCETHTOOL,"
525 " ETHTOOL_GLINKSETTINGS) failed: %s",
526 dev->data->port_id, strerror(rte_errno));
530 gcmd.link_mode_masks_nwords = -gcmd.link_mode_masks_nwords;
532 alignas(struct ethtool_link_settings)
533 uint8_t data[offsetof(struct ethtool_link_settings, link_mode_masks) +
534 sizeof(uint32_t) * gcmd.link_mode_masks_nwords * 3];
535 struct ethtool_link_settings *ecmd = (void *)data;
538 ifr.ifr_data = (void *)ecmd;
539 ret = mlx5_ifreq(master ? master : dev, SIOCETHTOOL, &ifr);
542 "port %u ioctl(SIOCETHTOOL,"
543 "ETHTOOL_GLINKSETTINGS) failed: %s",
544 dev->data->port_id, strerror(rte_errno));
547 dev_link.link_speed = (ecmd->speed == UINT32_MAX) ?
548 RTE_ETH_SPEED_NUM_UNKNOWN : ecmd->speed;
549 sc = ecmd->link_mode_masks[0] |
550 ((uint64_t)ecmd->link_mode_masks[1] << 32);
551 priv->link_speed_capa = 0;
552 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_1000baseT_Full_BIT) |
553 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT)))
554 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_1G;
555 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT) |
556 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT) |
557 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_10000baseR_FEC_BIT)))
558 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_10G;
559 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT) |
560 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT)))
561 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_20G;
562 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT) |
563 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT) |
564 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT) |
565 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT)))
566 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_40G;
567 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT) |
568 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT) |
569 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT) |
570 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT)))
571 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_56G;
572 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_25000baseCR_Full_BIT) |
573 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_25000baseKR_Full_BIT) |
574 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_25000baseSR_Full_BIT)))
575 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_25G;
576 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT) |
577 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT)))
578 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_50G;
579 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT) |
580 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT) |
581 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT) |
582 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT)))
583 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_100G;
584 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT) |
585 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT)))
586 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_200G;
588 sc = ecmd->link_mode_masks[2] |
589 ((uint64_t)ecmd->link_mode_masks[3] << 32);
590 if (sc & (MLX5_BITSHIFT(ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT) |
592 (ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT) |
593 MLX5_BITSHIFT(ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT)))
594 priv->link_speed_capa |= RTE_ETH_LINK_SPEED_200G;
595 dev_link.link_duplex = ((ecmd->duplex == DUPLEX_HALF) ?
596 RTE_ETH_LINK_HALF_DUPLEX : RTE_ETH_LINK_FULL_DUPLEX);
597 dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
598 RTE_ETH_LINK_SPEED_FIXED);
604 * DPDK callback to retrieve physical link information.
607 * Pointer to Ethernet device structure.
608 * @param wait_to_complete
609 * Wait for request completion.
612 * 0 if link status was not updated, positive if it was, a negative errno
613 * value otherwise and rte_errno is set.
616 mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete)
619 struct rte_eth_link dev_link;
620 time_t start_time = time(NULL);
621 int retry = MLX5_GET_LINK_STATUS_RETRY_COUNT;
624 ret = mlx5_link_update_unlocked_gs(dev, &dev_link);
626 ret = mlx5_link_update_unlocked_gset(dev, &dev_link);
629 /* Handle wait to complete situation. */
630 if ((wait_to_complete || retry) && ret == -EAGAIN) {
631 if (abs((int)difftime(time(NULL), start_time)) <
632 MLX5_LINK_STATUS_TIMEOUT) {
639 } else if (ret < 0) {
642 } while (wait_to_complete || retry-- > 0);
643 ret = !!memcmp(&dev->data->dev_link, &dev_link,
644 sizeof(struct rte_eth_link));
645 dev->data->dev_link = dev_link;
650 * DPDK callback to get flow control status.
653 * Pointer to Ethernet device structure.
654 * @param[out] fc_conf
655 * Flow control output buffer.
658 * 0 on success, a negative errno value otherwise and rte_errno is set.
661 mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
664 struct ethtool_pauseparam ethpause = {
665 .cmd = ETHTOOL_GPAUSEPARAM
669 ifr.ifr_data = (void *)ðpause;
670 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
673 "port %u ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM) failed:"
675 dev->data->port_id, strerror(rte_errno));
678 fc_conf->autoneg = ethpause.autoneg;
679 if (ethpause.rx_pause && ethpause.tx_pause)
680 fc_conf->mode = RTE_ETH_FC_FULL;
681 else if (ethpause.rx_pause)
682 fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
683 else if (ethpause.tx_pause)
684 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
686 fc_conf->mode = RTE_ETH_FC_NONE;
691 * DPDK callback to modify flow control parameters.
694 * Pointer to Ethernet device structure.
696 * Flow control parameters.
699 * 0 on success, a negative errno value otherwise and rte_errno is set.
702 mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
705 struct ethtool_pauseparam ethpause = {
706 .cmd = ETHTOOL_SPAUSEPARAM
710 ifr.ifr_data = (void *)ðpause;
711 ethpause.autoneg = fc_conf->autoneg;
712 if (((fc_conf->mode & RTE_ETH_FC_FULL) == RTE_ETH_FC_FULL) ||
713 (fc_conf->mode & RTE_ETH_FC_RX_PAUSE))
714 ethpause.rx_pause = 1;
716 ethpause.rx_pause = 0;
718 if (((fc_conf->mode & RTE_ETH_FC_FULL) == RTE_ETH_FC_FULL) ||
719 (fc_conf->mode & RTE_ETH_FC_TX_PAUSE))
720 ethpause.tx_pause = 1;
722 ethpause.tx_pause = 0;
723 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
726 "port %u ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)"
728 dev->data->port_id, strerror(rte_errno));
735 * Handle asynchronous removal event for entire multiport device.
738 * Infiniband device shared context.
741 mlx5_dev_interrupt_device_fatal(struct mlx5_dev_ctx_shared *sh)
745 for (i = 0; i < sh->max_port; ++i) {
746 struct rte_eth_dev *dev;
748 if (sh->port[i].ih_port_id >= RTE_MAX_ETHPORTS) {
750 * Or not existing port either no
751 * handler installed for this port.
755 dev = &rte_eth_devices[sh->port[i].ih_port_id];
757 if (dev->data->dev_conf.intr_conf.rmv)
758 rte_eth_dev_callback_process
759 (dev, RTE_ETH_EVENT_INTR_RMV, NULL);
764 * Handle shared asynchronous events the NIC (removal event
765 * and link status change). Supports multiport IB device.
771 mlx5_dev_interrupt_handler(void *cb_arg)
773 struct mlx5_dev_ctx_shared *sh = cb_arg;
774 struct ibv_async_event event;
776 /* Read all message from the IB device and acknowledge them. */
778 struct rte_eth_dev *dev;
781 if (mlx5_glue->get_async_event(sh->cdev->ctx, &event))
783 /* Retrieve and check IB port index. */
784 tmp = (uint32_t)event.element.port_num;
785 if (!tmp && event.event_type == IBV_EVENT_DEVICE_FATAL) {
787 * The DEVICE_FATAL event is called once for
788 * entire device without port specifying.
789 * We should notify all existing ports.
791 mlx5_glue->ack_async_event(&event);
792 mlx5_dev_interrupt_device_fatal(sh);
795 MLX5_ASSERT(tmp && (tmp <= sh->max_port));
797 /* Unsupported device level event. */
798 mlx5_glue->ack_async_event(&event);
800 "unsupported common event (type %d)",
804 if (tmp > sh->max_port) {
805 /* Invalid IB port index. */
806 mlx5_glue->ack_async_event(&event);
808 "cannot handle an event (type %d)"
809 "due to invalid IB port index (%u)",
810 event.event_type, tmp);
813 if (sh->port[tmp - 1].ih_port_id >= RTE_MAX_ETHPORTS) {
814 /* No handler installed. */
815 mlx5_glue->ack_async_event(&event);
817 "cannot handle an event (type %d)"
818 "due to no handler installed for port %u",
819 event.event_type, tmp);
822 /* Retrieve ethernet device descriptor. */
823 tmp = sh->port[tmp - 1].ih_port_id;
824 dev = &rte_eth_devices[tmp];
826 if ((event.event_type == IBV_EVENT_PORT_ACTIVE ||
827 event.event_type == IBV_EVENT_PORT_ERR) &&
828 dev->data->dev_conf.intr_conf.lsc) {
829 mlx5_glue->ack_async_event(&event);
830 if (mlx5_link_update(dev, 0) == -EAGAIN) {
834 rte_eth_dev_callback_process
835 (dev, RTE_ETH_EVENT_INTR_LSC, NULL);
839 "port %u cannot handle an unknown event (type %d)",
840 dev->data->port_id, event.event_type);
841 mlx5_glue->ack_async_event(&event);
846 * Unregister callback handler safely. The handler may be active
847 * while we are trying to unregister it, in this case code -EAGAIN
848 * is returned by rte_intr_callback_unregister(). This routine checks
849 * the return code and tries to unregister handler again.
854 * pointer to callback routine
856 * opaque callback parameter
859 mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
860 rte_intr_callback_fn cb_fn, void *cb_arg)
863 * Try to reduce timeout management overhead by not calling
864 * the timer related routines on the first iteration. If the
865 * unregistering succeeds on first call there will be no
866 * timer calls at all.
874 ret = rte_intr_callback_unregister(handle, cb_fn, cb_arg);
877 if (ret != -EAGAIN) {
878 DRV_LOG(INFO, "failed to unregister interrupt"
879 " handler (error: %d)", ret);
884 struct timespec onems;
886 /* Wait one millisecond and try again. */
888 onems.tv_nsec = NS_PER_S / MS_PER_S;
889 nanosleep(&onems, 0);
890 /* Check whether one second elapsed. */
891 if ((rte_get_timer_cycles() - start) <= twait)
895 * We get the amount of timer ticks for one second.
896 * If this amount elapsed it means we spent one
897 * second in waiting. This branch is executed once
898 * on first iteration.
900 twait = rte_get_timer_hz();
904 * Timeout elapsed, show message (once a second) and retry.
905 * We have no other acceptable option here, if we ignore
906 * the unregistering return code the handler will not
907 * be unregistered, fd will be closed and we may get the
908 * crush. Hanging and messaging in the loop seems not to be
911 DRV_LOG(INFO, "Retrying to unregister interrupt handler");
912 start = rte_get_timer_cycles();
917 * Handle DEVX interrupts from the NIC.
918 * This function is probably called from the DPDK host thread.
924 mlx5_dev_interrupt_handler_devx(void *cb_arg)
926 #ifndef HAVE_IBV_DEVX_ASYNC
930 struct mlx5_dev_ctx_shared *sh = cb_arg;
932 struct mlx5dv_devx_async_cmd_hdr cmd_resp;
933 uint8_t buf[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
934 MLX5_ST_SZ_BYTES(traffic_counter) +
935 sizeof(struct mlx5dv_devx_async_cmd_hdr)];
937 uint8_t *buf = out.buf + sizeof(out.cmd_resp);
939 while (!mlx5_glue->devx_get_async_cmd_comp(sh->devx_comp,
942 mlx5_flow_async_pool_query_handle
943 (sh, (uint64_t)out.cmd_resp.wr_id,
944 mlx5_devx_get_out_command_status(buf));
945 #endif /* HAVE_IBV_DEVX_ASYNC */
949 * DPDK callback to bring the link DOWN.
952 * Pointer to Ethernet device structure.
955 * 0 on success, a negative errno value otherwise and rte_errno is set.
958 mlx5_set_link_down(struct rte_eth_dev *dev)
960 return mlx5_set_flags(dev, ~IFF_UP, ~IFF_UP);
964 * DPDK callback to bring the link UP.
967 * Pointer to Ethernet device structure.
970 * 0 on success, a negative errno value otherwise and rte_errno is set.
973 mlx5_set_link_up(struct rte_eth_dev *dev)
975 return mlx5_set_flags(dev, ~IFF_UP, IFF_UP);
979 * Check if mlx5 device was removed.
982 * Pointer to Ethernet device structure.
985 * 1 when device is removed, otherwise 0.
988 mlx5_is_removed(struct rte_eth_dev *dev)
990 struct ibv_device_attr device_attr;
991 struct mlx5_priv *priv = dev->data->dev_private;
993 if (mlx5_glue->query_device(priv->sh->cdev->ctx, &device_attr) == EIO)
999 * Analyze gathered port parameters via sysfs to recognize master
1000 * and representor devices for E-Switch configuration.
1002 * @param[in] device_dir
1003 * flag of presence of "device" directory under port device key.
1004 * @param[inout] switch_info
1005 * Port information, including port name as a number and port name
1006 * type if recognized
1009 * master and representor flags are set in switch_info according to
1010 * recognized parameters (if any).
1013 mlx5_sysfs_check_switch_info(bool device_dir,
1014 struct mlx5_switch_info *switch_info)
1016 switch (switch_info->name_type) {
1017 case MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN:
1019 * Name is not recognized, assume the master,
1020 * check the device directory presence.
1022 switch_info->master = device_dir;
1024 case MLX5_PHYS_PORT_NAME_TYPE_NOTSET:
1026 * Name is not set, this assumes the legacy naming
1027 * schema for master, just check if there is
1028 * a device directory.
1030 switch_info->master = device_dir;
1032 case MLX5_PHYS_PORT_NAME_TYPE_UPLINK:
1033 /* New uplink naming schema recognized. */
1034 switch_info->master = 1;
1036 case MLX5_PHYS_PORT_NAME_TYPE_LEGACY:
1037 /* Legacy representors naming schema. */
1038 switch_info->representor = !device_dir;
1040 case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
1042 case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
1044 case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
1045 /* New representors naming schema. */
1046 switch_info->representor = 1;
1049 switch_info->master = device_dir;
1055 * Get switch information associated with network interface.
1058 * Network interface index.
1060 * Switch information object, populated in case of success.
1063 * 0 on success, a negative errno value otherwise and rte_errno is set.
1066 mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info)
1068 char ifname[IF_NAMESIZE];
1069 char port_name[IF_NAMESIZE];
1071 struct mlx5_switch_info data = {
1074 .name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET,
1079 bool port_switch_id_set = false;
1080 bool device_dir = false;
1084 if (!if_indextoname(ifindex, ifname)) {
1089 MKSTR(phys_port_name, "/sys/class/net/%s/phys_port_name",
1091 MKSTR(phys_switch_id, "/sys/class/net/%s/phys_switch_id",
1093 MKSTR(pci_device, "/sys/class/net/%s/device",
1096 file = fopen(phys_port_name, "rb");
1098 ret = fscanf(file, "%" RTE_STR(IF_NAMESIZE) "s", port_name);
1101 mlx5_translate_port_name(port_name, &data);
1103 file = fopen(phys_switch_id, "rb");
1108 port_switch_id_set =
1109 fscanf(file, "%" SCNx64 "%c", &data.switch_id, &c) == 2 &&
1112 dir = opendir(pci_device);
1117 if (port_switch_id_set) {
1118 /* We have some E-Switch configuration. */
1119 mlx5_sysfs_check_switch_info(device_dir, &data);
1122 MLX5_ASSERT(!(data.master && data.representor));
1123 if (data.master && data.representor) {
1124 DRV_LOG(ERR, "ifindex %u device is recognized as master"
1125 " and as representor", ifindex);
1133 * Get bond information associated with network interface.
1136 * Network interface index of bond slave interface
1137 * @param[out] ifindex
1138 * Pointer to bond ifindex.
1139 * @param[out] ifname
1140 * Pointer to bond ifname.
1143 * 0 on success, a negative errno value otherwise and rte_errno is set.
1146 mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned int *ifindex,
1149 char name[IF_NAMESIZE];
1154 if (!if_indextoname(pf_ifindex, name) || !strlen(name)) {
1158 MKSTR(bond_if, "/sys/class/net/%s/master/ifindex", name);
1159 /* read bond ifindex */
1160 file = fopen(bond_if, "rb");
1165 ret = fscanf(file, "%u", &index);
1174 /* read bond device name from symbol link */
1176 if (!if_indextoname(index, ifname)) {
1185 * DPDK callback to retrieve plug-in module EEPROM information (type and size).
1188 * Pointer to Ethernet device structure.
1189 * @param[out] modinfo
1190 * Storage for plug-in module EEPROM information.
1193 * 0 on success, a negative errno value otherwise and rte_errno is set.
1196 mlx5_get_module_info(struct rte_eth_dev *dev,
1197 struct rte_eth_dev_module_info *modinfo)
1199 struct ethtool_modinfo info = {
1200 .cmd = ETHTOOL_GMODULEINFO,
1202 struct ifreq ifr = (struct ifreq) {
1203 .ifr_data = (void *)&info,
1208 DRV_LOG(WARNING, "missing argument, cannot get module info");
1212 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1214 DRV_LOG(WARNING, "port %u ioctl(SIOCETHTOOL) failed: %s",
1215 dev->data->port_id, strerror(rte_errno));
1218 modinfo->type = info.type;
1219 modinfo->eeprom_len = info.eeprom_len;
1224 * DPDK callback to retrieve plug-in module EEPROM data.
1227 * Pointer to Ethernet device structure.
1229 * Storage for plug-in module EEPROM data.
1232 * 0 on success, a negative errno value otherwise and rte_errno is set.
1234 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
1235 struct rte_dev_eeprom_info *info)
1237 struct ethtool_eeprom *eeprom;
1242 DRV_LOG(WARNING, "missing argument, cannot get module eeprom");
1246 eeprom = mlx5_malloc(MLX5_MEM_ZERO,
1247 (sizeof(struct ethtool_eeprom) + info->length), 0,
1250 DRV_LOG(WARNING, "port %u cannot allocate memory for "
1251 "eeprom data", dev->data->port_id);
1255 eeprom->cmd = ETHTOOL_GMODULEEEPROM;
1256 eeprom->offset = info->offset;
1257 eeprom->len = info->length;
1258 ifr = (struct ifreq) {
1259 .ifr_data = (void *)eeprom,
1261 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1263 DRV_LOG(WARNING, "port %u ioctl(SIOCETHTOOL) failed: %s",
1264 dev->data->port_id, strerror(rte_errno));
1266 rte_memcpy(info->data, eeprom->data, info->length);
1272 * Read device counters table.
1275 * Pointer to Ethernet device.
1277 * PF index in case of bonding device, -1 otherwise
1279 * Counters table output buffer.
1282 * 0 on success and stats is filled, negative errno value otherwise and
1286 _mlx5_os_read_dev_counters(struct rte_eth_dev *dev, int pf, uint64_t *stats)
1288 struct mlx5_priv *priv = dev->data->dev_private;
1289 struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
1292 unsigned int stats_sz = xstats_ctrl->stats_n * sizeof(uint64_t);
1293 unsigned char et_stat_buf[sizeof(struct ethtool_stats) + stats_sz];
1294 struct ethtool_stats *et_stats = (struct ethtool_stats *)et_stat_buf;
1297 et_stats->cmd = ETHTOOL_GSTATS;
1298 et_stats->n_stats = xstats_ctrl->stats_n;
1299 ifr.ifr_data = (caddr_t)et_stats;
1301 ret = mlx5_ifreq_by_ifname(priv->sh->bond.ports[pf].ifname,
1304 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1307 "port %u unable to read statistic values from device",
1308 dev->data->port_id);
1311 for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) {
1312 if (xstats_ctrl->info[i].dev)
1314 stats[i] += (uint64_t)
1315 et_stats->data[xstats_ctrl->dev_table_idx[i]];
1321 * Read device counters.
1324 * Pointer to Ethernet device.
1326 * Counters table output buffer.
1329 * 0 on success and stats is filled, negative errno value otherwise and
1333 mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats)
1335 struct mlx5_priv *priv = dev->data->dev_private;
1336 struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
1339 memset(stats, 0, sizeof(*stats) * xstats_ctrl->mlx5_stats_n);
1340 /* Read ifreq counters. */
1341 if (priv->master && priv->pf_bond >= 0) {
1342 /* Sum xstats from bonding device member ports. */
1343 for (i = 0; i < priv->sh->bond.n_port; i++) {
1344 ret = _mlx5_os_read_dev_counters(dev, i, stats);
1349 ret = _mlx5_os_read_dev_counters(dev, -1, stats);
1351 /* Read IB counters. */
1352 for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) {
1353 if (!xstats_ctrl->info[i].dev)
1355 ret = mlx5_os_read_dev_stat(priv, xstats_ctrl->info[i].ctr_name,
1357 /* return last xstats counter if fail to read. */
1359 xstats_ctrl->xstats[i] = stats[i];
1361 stats[i] = xstats_ctrl->xstats[i];
1367 * Query the number of statistics provided by ETHTOOL.
1370 * Pointer to Ethernet device.
1373 * Number of statistics on success, negative errno value otherwise and
1377 mlx5_os_get_stats_n(struct rte_eth_dev *dev)
1379 struct mlx5_priv *priv = dev->data->dev_private;
1380 struct ethtool_drvinfo drvinfo;
1384 drvinfo.cmd = ETHTOOL_GDRVINFO;
1385 ifr.ifr_data = (caddr_t)&drvinfo;
1386 if (priv->master && priv->pf_bond >= 0)
1388 ret = mlx5_ifreq_by_ifname(priv->sh->bond.ports[0].ifname,
1391 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1393 DRV_LOG(WARNING, "port %u unable to query number of statistics",
1394 dev->data->port_id);
1397 return drvinfo.n_stats;
1400 static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
1402 .dpdk_name = "rx_unicast_bytes",
1403 .ctr_name = "rx_vport_unicast_bytes",
1406 .dpdk_name = "rx_multicast_bytes",
1407 .ctr_name = "rx_vport_multicast_bytes",
1410 .dpdk_name = "rx_broadcast_bytes",
1411 .ctr_name = "rx_vport_broadcast_bytes",
1414 .dpdk_name = "rx_unicast_packets",
1415 .ctr_name = "rx_vport_unicast_packets",
1418 .dpdk_name = "rx_multicast_packets",
1419 .ctr_name = "rx_vport_multicast_packets",
1422 .dpdk_name = "rx_broadcast_packets",
1423 .ctr_name = "rx_vport_broadcast_packets",
1426 .dpdk_name = "tx_unicast_bytes",
1427 .ctr_name = "tx_vport_unicast_bytes",
1430 .dpdk_name = "tx_multicast_bytes",
1431 .ctr_name = "tx_vport_multicast_bytes",
1434 .dpdk_name = "tx_broadcast_bytes",
1435 .ctr_name = "tx_vport_broadcast_bytes",
1438 .dpdk_name = "tx_unicast_packets",
1439 .ctr_name = "tx_vport_unicast_packets",
1442 .dpdk_name = "tx_multicast_packets",
1443 .ctr_name = "tx_vport_multicast_packets",
1446 .dpdk_name = "tx_broadcast_packets",
1447 .ctr_name = "tx_vport_broadcast_packets",
1450 .dpdk_name = "rx_wqe_errors",
1451 .ctr_name = "rx_wqe_err",
1454 .dpdk_name = "rx_phy_crc_errors",
1455 .ctr_name = "rx_crc_errors_phy",
1458 .dpdk_name = "rx_phy_in_range_len_errors",
1459 .ctr_name = "rx_in_range_len_errors_phy",
1462 .dpdk_name = "rx_phy_symbol_errors",
1463 .ctr_name = "rx_symbol_err_phy",
1466 .dpdk_name = "tx_phy_errors",
1467 .ctr_name = "tx_errors_phy",
1470 .dpdk_name = "rx_out_of_buffer",
1471 .ctr_name = "out_of_buffer",
1475 .dpdk_name = "tx_phy_packets",
1476 .ctr_name = "tx_packets_phy",
1479 .dpdk_name = "rx_phy_packets",
1480 .ctr_name = "rx_packets_phy",
1483 .dpdk_name = "tx_phy_discard_packets",
1484 .ctr_name = "tx_discards_phy",
1487 .dpdk_name = "rx_phy_discard_packets",
1488 .ctr_name = "rx_discards_phy",
1491 .dpdk_name = "tx_phy_bytes",
1492 .ctr_name = "tx_bytes_phy",
1495 .dpdk_name = "rx_phy_bytes",
1496 .ctr_name = "rx_bytes_phy",
1498 /* Representor only */
1500 .dpdk_name = "rx_vport_packets",
1501 .ctr_name = "vport_rx_packets",
1504 .dpdk_name = "rx_vport_bytes",
1505 .ctr_name = "vport_rx_bytes",
1508 .dpdk_name = "tx_vport_packets",
1509 .ctr_name = "vport_tx_packets",
1512 .dpdk_name = "tx_vport_bytes",
1513 .ctr_name = "vport_tx_bytes",
1517 static const unsigned int xstats_n = RTE_DIM(mlx5_counters_init);
1520 * Init the structures to read device counters.
1523 * Pointer to Ethernet device.
1526 mlx5_os_stats_init(struct rte_eth_dev *dev)
1528 struct mlx5_priv *priv = dev->data->dev_private;
1529 struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
1530 struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
1534 struct ethtool_gstrings *strings = NULL;
1535 unsigned int dev_stats_n;
1536 unsigned int str_sz;
1539 /* So that it won't aggregate for each init. */
1540 xstats_ctrl->mlx5_stats_n = 0;
1541 ret = mlx5_os_get_stats_n(dev);
1543 DRV_LOG(WARNING, "port %u no extended statistics available",
1544 dev->data->port_id);
1548 /* Allocate memory to grab stat names and values. */
1549 str_sz = dev_stats_n * ETH_GSTRING_LEN;
1550 strings = (struct ethtool_gstrings *)
1551 mlx5_malloc(0, str_sz + sizeof(struct ethtool_gstrings), 0,
1554 DRV_LOG(WARNING, "port %u unable to allocate memory for xstats",
1555 dev->data->port_id);
1558 strings->cmd = ETHTOOL_GSTRINGS;
1559 strings->string_set = ETH_SS_STATS;
1560 strings->len = dev_stats_n;
1561 ifr.ifr_data = (caddr_t)strings;
1562 if (priv->master && priv->pf_bond >= 0)
1563 /* Bonding master. */
1564 ret = mlx5_ifreq_by_ifname(priv->sh->bond.ports[0].ifname,
1567 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1569 DRV_LOG(WARNING, "port %u unable to get statistic names",
1570 dev->data->port_id);
1573 for (i = 0; i != dev_stats_n; ++i) {
1574 const char *curr_string = (const char *)
1575 &strings->data[i * ETH_GSTRING_LEN];
1577 for (j = 0; j != xstats_n; ++j) {
1578 if (!strcmp(mlx5_counters_init[j].ctr_name,
1580 unsigned int idx = xstats_ctrl->mlx5_stats_n++;
1582 xstats_ctrl->dev_table_idx[idx] = i;
1583 xstats_ctrl->info[idx] = mlx5_counters_init[j];
1588 /* Add dev counters. */
1589 for (i = 0; i != xstats_n; ++i) {
1590 if (mlx5_counters_init[i].dev) {
1591 unsigned int idx = xstats_ctrl->mlx5_stats_n++;
1593 xstats_ctrl->info[idx] = mlx5_counters_init[i];
1594 xstats_ctrl->hw_stats[idx] = 0;
1597 MLX5_ASSERT(xstats_ctrl->mlx5_stats_n <= MLX5_MAX_XSTATS);
1598 xstats_ctrl->stats_n = dev_stats_n;
1599 /* Copy to base at first time. */
1600 ret = mlx5_os_read_dev_counters(dev, xstats_ctrl->base);
1602 DRV_LOG(ERR, "port %u cannot read device counters: %s",
1603 dev->data->port_id, strerror(rte_errno));
1604 mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base);
1605 stats_ctrl->imissed = 0;
1611 * Get MAC address by querying netdevice.
1614 * Pointer to Ethernet device.
1616 * MAC address output buffer.
1619 * 0 on success, a negative errno value otherwise and rte_errno is set.
1622 mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN])
1624 struct ifreq request;
1627 ret = mlx5_ifreq(dev, SIOCGIFHWADDR, &request);
1630 memcpy(mac, request.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
1635 * Query dropless_rq private flag value provided by ETHTOOL.
1638 * Pointer to Ethernet device.
1641 * - 0 on success, flag is not set.
1642 * - 1 on success, flag is set.
1643 * - negative errno value otherwise and rte_errno is set.
1645 int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev)
1648 struct ethtool_sset_info hdr;
1651 struct ethtool_drvinfo drvinfo;
1653 struct ethtool_gstrings *strings = NULL;
1654 struct ethtool_value flags;
1655 const int32_t flag_len = sizeof(flags.data) * CHAR_BIT;
1661 sset_info.hdr.cmd = ETHTOOL_GSSET_INFO;
1662 sset_info.hdr.reserved = 0;
1663 sset_info.hdr.sset_mask = 1ULL << ETH_SS_PRIV_FLAGS;
1664 ifr.ifr_data = (caddr_t)&sset_info;
1665 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1667 const uint32_t *sset_lengths = sset_info.hdr.data;
1669 len = sset_info.hdr.sset_mask ? sset_lengths[0] : 0;
1670 } else if (ret == -EOPNOTSUPP) {
1671 drvinfo.cmd = ETHTOOL_GDRVINFO;
1672 ifr.ifr_data = (caddr_t)&drvinfo;
1673 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1675 DRV_LOG(WARNING, "port %u cannot get the driver info",
1676 dev->data->port_id);
1679 len = *(uint32_t *)((char *)&drvinfo +
1680 offsetof(struct ethtool_drvinfo, n_priv_flags));
1682 DRV_LOG(WARNING, "port %u cannot get the sset info",
1683 dev->data->port_id);
1687 DRV_LOG(WARNING, "port %u does not have private flag",
1688 dev->data->port_id);
1689 rte_errno = EOPNOTSUPP;
1692 } else if (len > flag_len) {
1693 DRV_LOG(WARNING, "port %u maximal private flags number is %d",
1694 dev->data->port_id, flag_len);
1697 str_sz = ETH_GSTRING_LEN * len;
1698 strings = (struct ethtool_gstrings *)
1699 mlx5_malloc(0, str_sz + sizeof(struct ethtool_gstrings), 0,
1702 DRV_LOG(WARNING, "port %u unable to allocate memory for"
1703 " private flags", dev->data->port_id);
1708 strings->cmd = ETHTOOL_GSTRINGS;
1709 strings->string_set = ETH_SS_PRIV_FLAGS;
1711 ifr.ifr_data = (caddr_t)strings;
1712 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1714 DRV_LOG(WARNING, "port %u unable to get private flags strings",
1715 dev->data->port_id);
1718 for (i = 0; i < len; i++) {
1719 strings->data[(i + 1) * ETH_GSTRING_LEN - 1] = 0;
1720 if (!strcmp((const char *)strings->data + i * ETH_GSTRING_LEN,
1725 DRV_LOG(WARNING, "port %u does not support dropless_rq",
1726 dev->data->port_id);
1727 rte_errno = EOPNOTSUPP;
1731 flags.cmd = ETHTOOL_GPFLAGS;
1732 ifr.ifr_data = (caddr_t)&flags;
1733 ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
1735 DRV_LOG(WARNING, "port %u unable to get private flags status",
1736 dev->data->port_id);
1739 ret = !!(flags.data & (1U << i));