1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
11 #include <netinet/in.h>
12 #include <sys/ioctl.h>
13 #include <arpa/inet.h>
16 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
18 #pragma GCC diagnostic ignored "-Wpedantic"
20 #include <infiniband/verbs.h>
22 #pragma GCC diagnostic error "-Wpedantic"
25 #include <rte_ether.h>
26 #include <rte_ethdev_driver.h>
27 #include <rte_common.h>
29 #include "mlx5_defs.h"
31 #include "mlx5_utils.h"
32 #include "mlx5_rxtx.h"
35 * Remove a MAC address from the internal array.
38 * Pointer to Ethernet device structure.
43 mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
45 MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
46 if (rte_is_zero_ether_addr(&dev->data->mac_addrs[index]))
48 mlx5_os_mac_addr_remove(dev, index);
49 memset(&dev->data->mac_addrs[index], 0, sizeof(struct rte_ether_addr));
53 * Adds a MAC address to the internal array.
56 * Pointer to Ethernet device structure.
58 * MAC address to register.
63 * 0 on success, a negative errno value otherwise and rte_errno is set.
66 mlx5_internal_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
72 MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
73 if (rte_is_zero_ether_addr(mac)) {
77 /* First, make sure this address isn't already configured. */
78 for (i = 0; (i != MLX5_MAX_MAC_ADDRESSES); ++i) {
79 /* Skip this index, it's going to be reconfigured. */
82 if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac)))
84 /* Address already configured elsewhere, return with error. */
85 rte_errno = EADDRINUSE;
88 ret = mlx5_os_mac_addr_add(dev, mac, index);
92 dev->data->mac_addrs[index] = *mac;
97 * DPDK callback to remove a MAC address.
100 * Pointer to Ethernet device structure.
105 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
109 if (index >= MLX5_MAX_UC_MAC_ADDRESSES)
111 mlx5_internal_mac_addr_remove(dev, index);
112 if (!dev->data->promiscuous) {
113 ret = mlx5_traffic_restart(dev);
115 DRV_LOG(ERR, "port %u cannot restart traffic: %s",
116 dev->data->port_id, strerror(rte_errno));
121 * DPDK callback to add a MAC address.
124 * Pointer to Ethernet device structure.
126 * MAC address to register.
130 * VMDq pool index to associate address with (ignored).
133 * 0 on success, a negative errno value otherwise and rte_errno is set.
136 mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
137 uint32_t index, uint32_t vmdq __rte_unused)
141 if (index >= MLX5_MAX_UC_MAC_ADDRESSES) {
145 ret = mlx5_internal_mac_addr_add(dev, mac, index);
148 if (!dev->data->promiscuous)
149 return mlx5_traffic_restart(dev);
154 * DPDK callback to set primary MAC address.
157 * Pointer to Ethernet device structure.
159 * MAC address to register.
162 * 0 on success, a negative errno value otherwise and rte_errno is set.
165 mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
168 struct mlx5_priv *priv = dev->data->dev_private;
170 /* Configuring the VF instead of its representor. */
171 if (priv->representor) {
172 DRV_LOG(DEBUG, "VF represented by port %u setting primary MAC address",
174 RTE_ETH_FOREACH_DEV_SIBLING(port_id, dev->data->port_id) {
175 priv = rte_eth_devices[port_id].data->dev_private;
176 if (priv->master == 1) {
177 priv = dev->data->dev_private;
178 return mlx5_os_vf_mac_addr_modify
180 mlx5_ifindex(&rte_eth_devices[port_id]),
181 mac_addr, priv->representor_id);
184 rte_errno = -ENOTSUP;
188 DRV_LOG(DEBUG, "port %u setting primary MAC address",
190 return mlx5_mac_addr_add(dev, mac_addr, 0, 0);
194 * DPDK callback to set multicast addresses list.
196 * @see rte_eth_dev_set_mc_addr_list()
199 mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
200 struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
205 if (nb_mc_addr >= MLX5_MAX_MC_MAC_ADDRESSES) {
209 for (i = MLX5_MAX_UC_MAC_ADDRESSES; i != MLX5_MAX_MAC_ADDRESSES; ++i)
210 mlx5_internal_mac_addr_remove(dev, i);
211 i = MLX5_MAX_UC_MAC_ADDRESSES;
212 while (nb_mc_addr--) {
213 ret = mlx5_internal_mac_addr_add(dev, mc_addr_set++, i++);
217 if (!dev->data->promiscuous)
218 return mlx5_traffic_restart(dev);