4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <netinet/in.h>
41 #include <sys/ioctl.h>
42 #include <arpa/inet.h>
45 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
47 #pragma GCC diagnostic ignored "-Wpedantic"
49 #include <infiniband/verbs.h>
51 #pragma GCC diagnostic error "-Wpedantic"
54 #include <rte_ether.h>
55 #include <rte_ethdev.h>
56 #include <rte_common.h>
59 #include "mlx5_utils.h"
60 #include "mlx5_rxtx.h"
61 #include "mlx5_defs.h"
64 * Get MAC address by querying netdevice.
67 * Pointer to Ethernet device.
69 * MAC address output buffer.
72 * 0 on success, a negative errno value otherwise and rte_errno is set.
75 mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[ETHER_ADDR_LEN])
80 ret = mlx5_ifreq(dev, SIOCGIFHWADDR, &request);
83 memcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
88 * DPDK callback to remove a MAC address.
91 * Pointer to Ethernet device structure.
96 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
98 assert(index < MLX5_MAX_MAC_ADDRESSES);
99 memset(&dev->data->mac_addrs[index], 0, sizeof(struct ether_addr));
100 if (!dev->data->promiscuous) {
101 int ret = mlx5_traffic_restart(dev);
104 DRV_LOG(ERR, "port %u cannot remove mac address: %s",
105 dev->data->port_id, strerror(rte_errno));
110 * DPDK callback to add a MAC address.
113 * Pointer to Ethernet device structure.
115 * MAC address to register.
119 * VMDq pool index to associate address with (ignored).
122 * 0 on success, a negative errno value otherwise and rte_errno is set.
125 mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
126 uint32_t index, uint32_t vmdq __rte_unused)
130 assert(index < MLX5_MAX_MAC_ADDRESSES);
131 /* First, make sure this address isn't already configured. */
132 for (i = 0; (i != MLX5_MAX_MAC_ADDRESSES); ++i) {
133 /* Skip this index, it's going to be reconfigured. */
136 if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac)))
138 /* Address already configured elsewhere, return with error. */
139 rte_errno = EADDRINUSE;
142 dev->data->mac_addrs[index] = *mac;
143 if (!dev->data->promiscuous)
144 return mlx5_traffic_restart(dev);
149 * DPDK callback to set primary MAC address.
152 * Pointer to Ethernet device structure.
154 * MAC address to register.
157 mlx5_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
161 DRV_LOG(DEBUG, "port %u setting primary MAC address",
164 ret = mlx5_mac_addr_add(dev, mac_addr, 0, 0);
166 DRV_LOG(ERR, "port %u cannot set mac address: %s",
167 dev->data->port_id, strerror(rte_errno));