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>
15 #include <rte_ether.h>
16 #include <rte_ethdev_driver.h>
17 #include <rte_common.h>
19 #include "mlx5_defs.h"
21 #include "mlx5_utils.h"
22 #include "mlx5_rxtx.h"
25 * Remove a MAC address from the internal array.
28 * Pointer to Ethernet device structure.
33 mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
35 MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
36 if (rte_is_zero_ether_addr(&dev->data->mac_addrs[index]))
38 mlx5_os_mac_addr_remove(dev, index);
39 memset(&dev->data->mac_addrs[index], 0, sizeof(struct rte_ether_addr));
43 * Adds a MAC address to the internal array.
46 * Pointer to Ethernet device structure.
48 * MAC address to register.
53 * 0 on success, a negative errno value otherwise and rte_errno is set.
56 mlx5_internal_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
62 MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES);
63 if (rte_is_zero_ether_addr(mac)) {
67 /* First, make sure this address isn't already configured. */
68 for (i = 0; (i != MLX5_MAX_MAC_ADDRESSES); ++i) {
69 /* Skip this index, it's going to be reconfigured. */
72 if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac)))
74 /* Address already configured elsewhere, return with error. */
75 rte_errno = EADDRINUSE;
78 ret = mlx5_os_mac_addr_add(dev, mac, index);
82 dev->data->mac_addrs[index] = *mac;
87 * DPDK callback to remove a MAC address.
90 * Pointer to Ethernet device structure.
95 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
99 if (index >= MLX5_MAX_UC_MAC_ADDRESSES)
101 mlx5_internal_mac_addr_remove(dev, index);
102 if (!dev->data->promiscuous) {
103 ret = mlx5_traffic_restart(dev);
105 DRV_LOG(ERR, "port %u cannot restart traffic: %s",
106 dev->data->port_id, strerror(rte_errno));
111 * DPDK callback to add a MAC address.
114 * Pointer to Ethernet device structure.
116 * MAC address to register.
120 * VMDq pool index to associate address with (ignored).
123 * 0 on success, a negative errno value otherwise and rte_errno is set.
126 mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
127 uint32_t index, uint32_t vmdq __rte_unused)
131 if (index >= MLX5_MAX_UC_MAC_ADDRESSES) {
135 ret = mlx5_internal_mac_addr_add(dev, mac, index);
138 if (!dev->data->promiscuous)
139 return mlx5_traffic_restart(dev);
144 * DPDK callback to set primary MAC address.
147 * Pointer to Ethernet device structure.
149 * MAC address to register.
152 * 0 on success, a negative errno value otherwise and rte_errno is set.
155 mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
158 struct mlx5_priv *priv = dev->data->dev_private;
161 * Configuring the VF instead of its representor,
162 * need to skip the special case of HPF on Bluefield.
164 if (priv->representor && priv->representor_id >= 0) {
165 DRV_LOG(DEBUG, "VF represented by port %u setting primary MAC address",
167 RTE_ETH_FOREACH_DEV_SIBLING(port_id, dev->data->port_id) {
168 priv = rte_eth_devices[port_id].data->dev_private;
169 if (priv->master == 1) {
170 priv = dev->data->dev_private;
171 return mlx5_os_vf_mac_addr_modify
173 mlx5_ifindex(&rte_eth_devices[port_id]),
174 mac_addr, priv->representor_id);
177 rte_errno = -ENOTSUP;
181 DRV_LOG(DEBUG, "port %u setting primary MAC address",
183 return mlx5_mac_addr_add(dev, mac_addr, 0, 0);
187 * DPDK callback to set multicast addresses list.
189 * @see rte_eth_dev_set_mc_addr_list()
192 mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
193 struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
198 if (nb_mc_addr >= MLX5_MAX_MC_MAC_ADDRESSES) {
202 for (i = MLX5_MAX_UC_MAC_ADDRESSES; i != MLX5_MAX_MAC_ADDRESSES; ++i)
203 mlx5_internal_mac_addr_remove(dev, i);
204 i = MLX5_MAX_UC_MAC_ADDRESSES;
205 while (nb_mc_addr--) {
206 ret = mlx5_internal_mac_addr_add(dev, mc_addr_set++, i++);
210 if (!dev->data->promiscuous)
211 return mlx5_traffic_restart(dev);