diff mbox series

[ovs-dev,v3,1/2] netdev-dpdk: Add ability to set MAC address.

Message ID ae488205285f5a68c6235131b3574521816227ac.1600269208.git.grive@u256.net
State New
Headers show
Series netdev-dpdk: support changing VF MAC | expand

Commit Message

Gaƫtan Rivet Sept. 16, 2020, 3:17 p.m. UTC
From: Ilya Maximets <i.maximets@ovn.org>

It is possible to set the MAC address of DPDK ports by calling
rte_eth_dev_default_mac_addr_set().  OvS does not actually call
this function for non-internal ports, but the implementation is
exposed to be used in a later commit.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Gaetan Rivet <grive@u256.net>
---
 lib/netdev-dpdk.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 18c4adcc7..4ef7f78a6 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2909,19 +2909,45 @@  netdev_dpdk_eth_send(struct netdev *netdev, int qid,
     return 0;
 }
 
+static int
+netdev_dpdk_set_etheraddr__(struct netdev_dpdk *dev, const struct eth_addr mac)
+    OVS_REQUIRES(dev->mutex)
+{
+    int err = 0;
+
+    if (dev->type == DPDK_DEV_ETH) {
+        struct rte_ether_addr ea;
+
+        memcpy(ea.addr_bytes, mac.ea, ETH_ADDR_LEN);
+        err = -rte_eth_dev_default_mac_addr_set(dev->port_id, &ea);
+    }
+    if (!err) {
+        dev->hwaddr = mac;
+    } else {
+        VLOG_WARN("%s: Failed to set requested mac("ETH_ADDR_FMT"): %s",
+                  netdev_get_name(&dev->up), ETH_ADDR_ARGS(mac),
+                  rte_strerror(err));
+    }
+
+    return err;
+}
+
 static int
 netdev_dpdk_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
 {
     struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+    int err = 0;
 
     ovs_mutex_lock(&dev->mutex);
     if (!eth_addr_equals(dev->hwaddr, mac)) {
-        dev->hwaddr = mac;
-        netdev_change_seq_changed(netdev);
+        err = netdev_dpdk_set_etheraddr__(dev, mac);
+        if (!err) {
+            netdev_change_seq_changed(netdev);
+        }
     }
     ovs_mutex_unlock(&dev->mutex);
 
-    return 0;
+    return err;
 }
 
 static int