net/mlx5: use Netlink to add/remove MAC addresses
[dpdk.git] / drivers / net / mlx5 / mlx5_mac.c
index ba54c05..0fb4a3e 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright 2015 6WIND S.A.
- * Copyright 2015 Mellanox.
+ * Copyright 2015 Mellanox Technologies, Ltd
  */
 
 #include <stddef.h>
@@ -67,14 +67,20 @@ mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[ETHER_ADDR_LEN])
 void
 mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
 {
+       struct priv *priv = dev->data->dev_private;
+       const int vf = priv->config.vf;
+       int ret;
+
        assert(index < MLX5_MAX_MAC_ADDRESSES);
+       if (vf)
+               mlx5_nl_mac_addr_remove(dev, &dev->data->mac_addrs[index],
+                                       index);
        memset(&dev->data->mac_addrs[index], 0, sizeof(struct ether_addr));
        if (!dev->data->promiscuous) {
-               int ret = mlx5_traffic_restart(dev);
-
+               ret = mlx5_traffic_restart(dev);
                if (ret)
-                       ERROR("%p cannot remove mac address: %s", (void *)dev,
-                             strerror(rte_errno));
+                       DRV_LOG(ERR, "port %u cannot restart traffic: %s",
+                               dev->data->port_id, strerror(rte_errno));
        }
 }
 
@@ -97,6 +103,8 @@ int
 mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
                  uint32_t index, uint32_t vmdq __rte_unused)
 {
+       struct priv *priv = dev->data->dev_private;
+       const int vf = priv->config.vf;
        unsigned int i;
 
        assert(index < MLX5_MAX_MAC_ADDRESSES);
@@ -111,6 +119,12 @@ mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
                rte_errno = EADDRINUSE;
                return -rte_errno;
        }
+       if (vf) {
+               int ret = mlx5_nl_mac_addr_add(dev, mac, index);
+
+               if (ret)
+                       return ret;
+       }
        dev->data->mac_addrs[index] = *mac;
        if (!dev->data->promiscuous)
                return mlx5_traffic_restart(dev);
@@ -130,8 +144,11 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 {
        int ret;
 
-       DEBUG("%p: setting primary MAC address", (void *)dev);
+       DRV_LOG(DEBUG, "port %u setting primary MAC address",
+               dev->data->port_id);
+
        ret = mlx5_mac_addr_add(dev, mac_addr, 0, 0);
        if (ret)
-               ERROR("cannot set mac address: %s", strerror(rte_errno));
+               DRV_LOG(ERR, "port %u cannot set mac address: %s",
+                       dev->data->port_id, strerror(rte_errno));
 }