1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
12 #include <netinet/in.h>
13 #include <sys/ioctl.h>
14 #include <arpa/inet.h>
17 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
19 #pragma GCC diagnostic ignored "-Wpedantic"
21 #include <infiniband/verbs.h>
23 #pragma GCC diagnostic error "-Wpedantic"
26 #include <rte_ether.h>
27 #include <rte_ethdev_driver.h>
28 #include <rte_common.h>
31 #include "mlx5_utils.h"
32 #include "mlx5_rxtx.h"
33 #include "mlx5_defs.h"
36 * Get MAC address by querying netdevice.
39 * Pointer to Ethernet device.
41 * MAC address output buffer.
44 * 0 on success, a negative errno value otherwise and rte_errno is set.
47 mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[ETHER_ADDR_LEN])
52 ret = mlx5_ifreq(dev, SIOCGIFHWADDR, &request);
55 memcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
60 * DPDK callback to remove a MAC address.
63 * Pointer to Ethernet device structure.
68 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
70 struct priv *priv = dev->data->dev_private;
71 const int vf = priv->config.vf;
74 if (index >= MLX5_MAX_MAC_ADDRESSES)
76 if (is_zero_ether_addr(&dev->data->mac_addrs[index]))
79 mlx5_nl_mac_addr_remove(dev, &dev->data->mac_addrs[index],
81 memset(&dev->data->mac_addrs[index], 0, sizeof(struct ether_addr));
82 if (!dev->data->promiscuous) {
83 ret = mlx5_traffic_restart(dev);
85 DRV_LOG(ERR, "port %u cannot restart traffic: %s",
86 dev->data->port_id, strerror(rte_errno));
91 * DPDK callback to add a MAC address.
94 * Pointer to Ethernet device structure.
96 * MAC address to register.
100 * VMDq pool index to associate address with (ignored).
103 * 0 on success, a negative errno value otherwise and rte_errno is set.
106 mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
107 uint32_t index, uint32_t vmdq __rte_unused)
109 struct priv *priv = dev->data->dev_private;
110 const int vf = priv->config.vf;
113 if (index >= MLX5_MAX_MAC_ADDRESSES) {
117 if (is_zero_ether_addr(mac)) {
121 /* First, make sure this address isn't already configured. */
122 for (i = 0; (i != MLX5_MAX_MAC_ADDRESSES); ++i) {
123 /* Skip this index, it's going to be reconfigured. */
126 if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac)))
128 /* Address already configured elsewhere, return with error. */
129 rte_errno = EADDRINUSE;
133 int ret = mlx5_nl_mac_addr_add(dev, mac, index);
138 dev->data->mac_addrs[index] = *mac;
139 if (!dev->data->promiscuous)
140 return mlx5_traffic_restart(dev);
145 * DPDK callback to set primary MAC address.
148 * Pointer to Ethernet device structure.
150 * MAC address to register.
153 * 0 on success, a negative errno value otherwise and rte_errno is set.
156 mlx5_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
158 DRV_LOG(DEBUG, "port %u setting primary MAC address",
160 return mlx5_mac_addr_add(dev, mac_addr, 0, 0);