[dpdk-dev,1/2] ethdev: add api to set default mac address

Message ID 1432905309-912-2-git-send-email-liang-min.wang@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Liang-Min Larry Wang May 29, 2015, 1:15 p.m. UTC
  add a new api: rte_eth_dev_default_mac_addr_set to
support changing default mac address of a NIC

Signed-off-by: Liang-Min Larry Wang <liang-min.wang@intel.com>
---
 lib/librte_ether/rte_ethdev.c          | 26 ++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.h          | 14 ++++++++++++++
 lib/librte_ether/rte_ether_version.map |  1 +
 3 files changed, 41 insertions(+)
  

Comments

Stephen Hemminger May 29, 2015, 3:20 p.m. UTC | #1
On Fri, 29 May 2015 09:15:08 -0400
Liang-Min Larry Wang <liang-min.wang@intel.com> wrote:

>  }
>  
>  int
> +rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
> +{
> +	struct rte_eth_dev *dev;
> +	const int index = 0;
> +	const uint32_t pool = 0;
> +
> +	if (!rte_eth_dev_is_valid_port(port_id)) {
> +		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
> +		return -ENODEV;
> +	}
> +
> +	dev = &rte_eth_devices[port_id];
> +	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
> +	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
> +
> +	/* Update NIC default MAC address*/
> +	(*dev->dev_ops->mac_addr_remove)(dev, index);
> +	(*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
> +
> +	/* Update default address in NIC data structure */
> +	ether_addr_copy(addr, &dev->data->mac_addrs[index]);
> +
> +	return 0;
> +}
> +

No. this won't work. for some devices.

Please use mac_addr_set hook added in recent DPDK
  
Liang-Min Larry Wang May 29, 2015, 6:21 p.m. UTC | #2
>On Fri, 29 May 2015 09:15:08 -0400
>Liang-Min Larry Wang <liang-min.wang@intel.com> wrote:
>
>>  }
> > 
>>  int
>> +rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr 
>> +*addr) {
>> +	struct rte_eth_dev *dev;
>> +	const int index = 0;
>> +	const uint32_t pool = 0;
>> +
>> +	if (!rte_eth_dev_is_valid_port(port_id)) {
>> +		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
>> +		return -ENODEV;
>> +	}
>> +
>> +	dev = &rte_eth_devices[port_id];
>> +	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
>> +	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
>> +
>> +	/* Update NIC default MAC address*/
>> +	(*dev->dev_ops->mac_addr_remove)(dev, index);
>> +	(*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
>> +
>> +	/* Update default address in NIC data structure */
>> +	ether_addr_copy(addr, &dev->data->mac_addrs[index]);
>> +
>> +	return 0;
>> +}
>> +
>
>No. this won't work. for some devices.
>
>Please use mac_addr_set hook added in recent DPDK

I tested over ixgbe and igb, and both work. As for your concern, it's legit. I will take your suggestion and make modification.
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 024fe8b..850b83c 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2752,6 +2752,32 @@  rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
 }
 
 int
+rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
+{
+	struct rte_eth_dev *dev;
+	const int index = 0;
+	const uint32_t pool = 0;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
+		return -ENODEV;
+	}
+
+	dev = &rte_eth_devices[port_id];
+	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
+
+	/* Update NIC default MAC address*/
+	(*dev->dev_ops->mac_addr_remove)(dev, index);
+	(*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
+
+	/* Update default address in NIC data structure */
+	ether_addr_copy(addr, &dev->data->mac_addrs[index]);
+
+	return 0;
+}
+
+int
 rte_eth_dev_set_vf_rxmode(uint8_t port_id,  uint16_t vf,
 				uint16_t rx_mode, uint8_t on)
 {
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 16dbe00..5f07e0d 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -2982,6 +2982,20 @@  int rte_eth_dev_mac_addr_add(uint8_t port, struct ether_addr *mac_addr,
 int rte_eth_dev_mac_addr_remove(uint8_t port, struct ether_addr *mac_addr);
 
 /**
+ * Set the default MAC address.
+ *
+ * @param port
+ *   The port identifier of the Ethernet device.
+ * @param mac_addr
+ *   New default MAC address.
+ * @return
+ *   - (0) if successful, or *mac_addr* didn't exist.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port* invalid.
+ */
+int rte_eth_dev_default_mac_addr_set(uint8_t port, struct ether_addr *mac_addr);
+
+/**
  * Update Redirection Table(RETA) of Receive Side Scaling of Ethernet device.
  *
  * @param port
diff --git a/lib/librte_ether/rte_ether_version.map b/lib/librte_ether/rte_ether_version.map
index a2d25a6..2dbbaa7 100644
--- a/lib/librte_ether/rte_ether_version.map
+++ b/lib/librte_ether/rte_ether_version.map
@@ -102,6 +102,7 @@  DPDK_2.0 {
 	rte_eth_tx_queue_setup;
 	rte_eth_xstats_get;
 	rte_eth_xstats_reset;
+	rte_eth_dev_default_mac_addr_set;
 
 	local: *;
 };