DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <shemming@brocade.com>
Subject: [dpdk-dev] [PATCH 5/6] ether: allow setting mac address
Date: Wed, 14 May 2014 11:55:32 -0700	[thread overview]
Message-ID: <20140514185750.257523699@networkplumber.org> (raw)
In-Reply-To: <20140514185527.771828962@networkplumber.org>

[-- Attachment #1: mac-addr-set.patch --]
[-- Type: text/plain, Size: 3233 bytes --]

Allow setting the default Ethernet address used on device.
The underlying drivers allow it but the DPDK was blocking any
attempts to change Ethernet address on device.

For most devices, this is just the same as filling in address
in mac address table entry 0, but for some devices this requires
special override.

Signed-off-by: Stephen Hemminger <shemming@brocade.com>


--- a/lib/librte_ether/rte_ethdev.h	2014-05-14 11:44:27.373014227 -0700
+++ b/lib/librte_ether/rte_ethdev.h	2014-05-14 11:44:27.373014227 -0700
@@ -982,6 +982,11 @@ typedef void (*eth_mac_addr_add_t)(struc
 				  struct ether_addr *mac_addr,
 				  uint32_t index,
 				  uint32_t vmdq);
+/**< @internal Change default MAC address */
+
+typedef void (*eth_mac_addr_set_t)(struct rte_eth_dev *dev,
+				   struct ether_addr *mac_addr);
+
 /**< @internal Set a MAC address into Receive Address Address Register */ 
 
 typedef int (*eth_uc_hash_table_set_t)(struct rte_eth_dev *dev,
@@ -1114,6 +1119,7 @@ struct eth_dev_ops {
 	priority_flow_ctrl_set_t   priority_flow_ctrl_set; /**< Setup priority flow control.*/
 	eth_mac_addr_remove_t      mac_addr_remove; /**< Remove MAC address */
 	eth_mac_addr_add_t         mac_addr_add;  /**< Add a MAC address */
+	eth_mac_addr_set_t	   mac_addr_set;  /**< Change default MAC address */
 	eth_uc_hash_table_set_t    uc_hash_table_set;  /**< Set Unicast Table Array */
 	eth_uc_all_hash_table_set_t uc_all_hash_table_set;  /**< Set Unicast hash bitmap */
 	eth_mirror_rule_set_t	   mirror_rule_set;  /**< Add a traffic mirror rule.*/
@@ -2538,6 +2544,21 @@ int rte_eth_dev_mac_addr_add(uint8_t por
 int rte_eth_dev_mac_addr_remove(uint8_t port, struct ether_addr *mac_addr);
 
 /**
+ * Change the default MAC address
+ *
+ * @param port
+ *   The port identifier of the Ethernet device.
+ * @param mac_addr
+ *   MAC address to remove.
+ * @return
+ *   - (0) if successfully added or *mac_addr" was already added.
+ *   - (-ENOTSUP) if hardware doesn't support this feature.
+ *   - (-ENODEV) if *port* is invalid.
+ *   - (-EINVAL) if MAC address is invalid.
+ */
+int rte_eth_dev_macaddr_set(uint8_t port, struct ether_addr *mac_addr);
+
+/**
  * Update Redirection Table(RETA) of Receive Side Scaling of Ethernet device.
  * 
  * @param port
--- a/lib/librte_ether/rte_ethdev.c	2014-05-14 11:44:27.373014227 -0700
+++ b/lib/librte_ether/rte_ethdev.c	2014-05-14 11:44:27.373014227 -0700
@@ -1059,6 +1059,33 @@ rte_eth_macaddr_get(uint8_t port_id, str
 }
 
 int
+rte_eth_dev_macaddr_set(uint8_t port_id, struct ether_addr *addr)
+{
+	struct rte_eth_dev *dev;
+
+	if (port_id >= nb_ports) {
+		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
+		return (-ENODEV);
+	}
+	if (is_zero_ether_addr(addr)) {
+		PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n", port_id);
+		return (-EINVAL);
+	}
+	dev = &rte_eth_devices[port_id];
+
+	if (*dev->dev_ops->mac_addr_set)
+		(*dev->dev_ops->mac_addr_set)(dev, addr);
+	else {
+		FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
+		(*dev->dev_ops->mac_addr_add)(dev, addr, 0, 0);
+	}
+
+	ether_addr_copy(addr, &dev->data->mac_addrs[0]);
+
+	return 0;
+}
+
+int
 rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
 {
 	struct rte_eth_dev *dev;

  parent reply	other threads:[~2014-05-14 18:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-14 18:55 [dpdk-dev] [PATCH 0/6] Ethernet driver enhancements Stephen Hemminger
2014-05-14 18:55 ` [dpdk-dev] [PATCH 1/6] Subjec: ethdev: add macro to cover all checksum flags Stephen Hemminger
2014-05-14 18:55 ` [dpdk-dev] [PATCH 2/6] Subjet: ethdev: add common code to atomicly access link Stephen Hemminger
2014-05-15  8:43   ` Ivan Boule
2014-05-14 18:55 ` [dpdk-dev] [PATCH 3/6] ixgbe: use eth_dev_{get,set}_link Stephen Hemminger
2014-05-14 18:55 ` [dpdk-dev] [PATCH 4/6] e1000: " Stephen Hemminger
2014-05-14 18:55 ` Stephen Hemminger [this message]
2014-05-15  9:04   ` [dpdk-dev] [PATCH 5/6] ether: allow setting mac address Ivan Boule
2014-05-21 15:24     ` Ivan Boule
2014-05-14 18:55 ` [dpdk-dev] [PATCH 6/6] vmxnet3: replace Intel driver Stephen Hemminger
2014-05-15 17:14   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140514185750.257523699@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=shemming@brocade.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).