1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
12 #include <rte_ether.h>
13 #include <ethdev_driver.h>
14 #include <rte_common.h>
16 #include "mlx5_defs.h"
18 #include "mlx5_utils.h"
19 #include "mlx5_rxtx.h"
22 * Remove a MAC address from the internal array.
25 * Pointer to Ethernet device structure.
30 mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
32 MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
33 if (rte_is_zero_ether_addr(&dev->data->mac_addrs[index]))
35 mlx5_os_mac_addr_remove(dev, index);
36 memset(&dev->data->mac_addrs[index], 0, sizeof(struct rte_ether_addr));
40 * Adds a MAC address to the internal array.
43 * Pointer to Ethernet device structure.
45 * MAC address to register.
50 * 0 on success, a negative errno value otherwise and rte_errno is set.
53 mlx5_internal_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
59 MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
60 if (rte_is_zero_ether_addr(mac)) {
64 /* First, make sure this address isn't already configured. */
65 for (i = 0; (i != MLX5_MAX_MAC_ADDRESSES); ++i) {
66 /* Skip this index, it's going to be reconfigured. */
69 if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac)))
71 /* Address already configured elsewhere, return with error. */
72 rte_errno = EADDRINUSE;
75 ret = mlx5_os_mac_addr_add(dev, mac, index);
79 dev->data->mac_addrs[index] = *mac;
84 * DPDK callback to remove a MAC address.
87 * Pointer to Ethernet device structure.
92 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
96 if (index >= MLX5_MAX_UC_MAC_ADDRESSES)
98 mlx5_internal_mac_addr_remove(dev, index);
99 if (!dev->data->promiscuous) {
100 ret = mlx5_traffic_restart(dev);
102 DRV_LOG(ERR, "port %u cannot restart traffic: %s",
103 dev->data->port_id, strerror(rte_errno));
108 * DPDK callback to add a MAC address.
111 * Pointer to Ethernet device structure.
113 * MAC address to register.
117 * VMDq pool index to associate address with (ignored).
120 * 0 on success, a negative errno value otherwise and rte_errno is set.
123 mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
124 uint32_t index, uint32_t vmdq __rte_unused)
128 if (index >= MLX5_MAX_UC_MAC_ADDRESSES) {
132 ret = mlx5_internal_mac_addr_add(dev, mac, index);
135 if (!dev->data->promiscuous)
136 return mlx5_traffic_restart(dev);
141 * DPDK callback to set primary MAC address.
144 * Pointer to Ethernet device structure.
146 * MAC address to register.
149 * 0 on success, a negative errno value otherwise and rte_errno is set.
152 mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
155 struct mlx5_priv *priv = dev->data->dev_private;
156 struct mlx5_priv *pf_priv;
159 * Configuring the VF instead of its representor,
160 * need to skip the special case of HPF on Bluefield.
162 if (priv->representor && !mlx5_is_hpf(dev) && !mlx5_is_sf_repr(dev)) {
163 DRV_LOG(DEBUG, "VF represented by port %u setting primary MAC address",
165 if (priv->pf_bond >= 0) {
166 /* Bonding, get owner PF ifindex from shared data. */
167 return mlx5_os_vf_mac_addr_modify
169 priv->sh->bond.ports[priv->pf_bond].ifindex,
171 MLX5_REPRESENTOR_REPR(priv->representor_id));
173 RTE_ETH_FOREACH_DEV_SIBLING(port_id, dev->data->port_id) {
174 pf_priv = rte_eth_devices[port_id].data->dev_private;
175 if (pf_priv->master == 1)
176 return mlx5_os_vf_mac_addr_modify
177 (priv, pf_priv->if_index, mac_addr,
178 MLX5_REPRESENTOR_REPR
179 (priv->representor_id));
181 rte_errno = -ENOTSUP;
185 DRV_LOG(DEBUG, "port %u setting primary MAC address",
187 return mlx5_mac_addr_add(dev, mac_addr, 0, 0);
191 * DPDK callback to set multicast addresses list.
193 * @see rte_eth_dev_set_mc_addr_list()
196 mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
197 struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
202 if (nb_mc_addr >= MLX5_MAX_MC_MAC_ADDRESSES) {
206 for (i = MLX5_MAX_UC_MAC_ADDRESSES; i != MLX5_MAX_MAC_ADDRESSES; ++i)
207 mlx5_internal_mac_addr_remove(dev, i);
208 i = MLX5_MAX_UC_MAC_ADDRESSES;
209 while (nb_mc_addr--) {
210 ret = mlx5_internal_mac_addr_add(dev, mc_addr_set++, i++);
214 if (!dev->data->promiscuous)
215 return mlx5_traffic_restart(dev);