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_driver.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 * struct priv for the requested device.
69 * MAC address output buffer.
72 * 0 on success, -1 on failure and errno is set.
75 priv_get_mac(struct priv *priv, uint8_t (*mac)[ETHER_ADDR_LEN])
79 if (priv_ifreq(priv, SIOCGIFHWADDR, &request))
81 memcpy(mac, request.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
86 * DPDK callback to remove a MAC address.
89 * Pointer to Ethernet device structure.
94 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
96 assert(index < MLX5_MAX_MAC_ADDRESSES);
97 memset(&dev->data->mac_addrs[index], 0, sizeof(struct ether_addr));
98 if (!dev->data->promiscuous)
99 mlx5_traffic_restart(dev);
103 * DPDK callback to add a MAC address.
106 * Pointer to Ethernet device structure.
108 * MAC address to register.
112 * VMDq pool index to associate address with (ignored).
118 mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
119 uint32_t index, uint32_t vmdq)
125 assert(index < MLX5_MAX_MAC_ADDRESSES);
126 /* First, make sure this address isn't already configured. */
127 for (i = 0; (i != MLX5_MAX_MAC_ADDRESSES); ++i) {
128 /* Skip this index, it's going to be reconfigured. */
131 if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac)))
133 /* Address already configured elsewhere, return with error. */
136 dev->data->mac_addrs[index] = *mac;
137 if (!dev->data->promiscuous)
138 mlx5_traffic_restart(dev);
143 * DPDK callback to set primary MAC address.
146 * Pointer to Ethernet device structure.
148 * MAC address to register.
151 mlx5_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
153 DEBUG("%p: setting primary MAC address", (void *)dev);
154 mlx5_mac_addr_add(dev, mac_addr, 0, 0);