DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/2] User-space Ethtool
@ 2015-05-29 13:15 Liang-Min Larry Wang
  2015-05-29 13:15 ` [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address Liang-Min Larry Wang
  2015-05-29 13:15 ` [dpdk-dev] [PATCH 2/2] ethtool: add new library to provide ethtool-alike APIs Liang-Min Larry Wang
  0 siblings, 2 replies; 16+ messages in thread
From: Liang-Min Larry Wang @ 2015-05-29 13:15 UTC (permalink / raw)
  To: dev; +Cc: aharton, bruce.richardson, Liang-Min Larry Wang

This implementation is designed to provide a familar interface for applications that rely on kernel-space driver to support ethtool_op and net_device_op for device management. The initial implementation focuses on ops that can be implemented through existing netdev APIs. More ops will be supported in latter release.


Liang-Min Larry Wang (2):
  ethdev: add api to set default mac address
  ethtool: add new library to provide ethtool-alike APIs

 MAINTAINERS                                |   4 +
 config/common_linuxapp                     |   5 +
 lib/Makefile                               |   1 +
 lib/librte_ether/rte_ethdev.c              |  26 +++
 lib/librte_ether/rte_ethdev.h              |  14 ++
 lib/librte_ether/rte_ether_version.map     |   1 +
 lib/librte_ethtool/Makefile                |  56 +++++++
 lib/librte_ethtool/rte_ethtool.c           | 155 +++++++++++++++++
 lib/librte_ethtool/rte_ethtool.h           | 257 +++++++++++++++++++++++++++++
 lib/librte_ethtool/rte_ethtool_version.map |  18 ++
 mk/rte.app.mk                              |   1 +
 11 files changed, 538 insertions(+)
 create mode 100644 lib/librte_ethtool/Makefile
 create mode 100644 lib/librte_ethtool/rte_ethtool.c
 create mode 100644 lib/librte_ethtool/rte_ethtool.h
 create mode 100644 lib/librte_ethtool/rte_ethtool_version.map

-- 
2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-05-29 13:15 [dpdk-dev] [PATCH 0/2] User-space Ethtool Liang-Min Larry Wang
@ 2015-05-29 13:15 ` Liang-Min Larry Wang
  2015-05-29 15:20   ` Stephen Hemminger
  2015-05-29 13:15 ` [dpdk-dev] [PATCH 2/2] ethtool: add new library to provide ethtool-alike APIs Liang-Min Larry Wang
  1 sibling, 1 reply; 16+ messages in thread
From: Liang-Min Larry Wang @ 2015-05-29 13:15 UTC (permalink / raw)
  To: dev; +Cc: aharton, bruce.richardson, Liang-Min Larry Wang

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(+)

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: *;
 };
-- 
2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH 2/2] ethtool: add new library to provide ethtool-alike APIs
  2015-05-29 13:15 [dpdk-dev] [PATCH 0/2] User-space Ethtool Liang-Min Larry Wang
  2015-05-29 13:15 ` [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address Liang-Min Larry Wang
@ 2015-05-29 13:15 ` Liang-Min Larry Wang
  2015-05-29 15:22   ` Stephen Hemminger
  1 sibling, 1 reply; 16+ messages in thread
From: Liang-Min Larry Wang @ 2015-05-29 13:15 UTC (permalink / raw)
  To: dev; +Cc: aharton, bruce.richardson, Liang-Min Larry Wang

adding a new library based upon ethdev APIs to provide API's that bear
the same functionality as ethtool_ops (linux/ethtool.h) and net_device_ops
(linux/netdevice.h).

Signed-off-by: Liang-Min Larry Wang <liang-min.wang@intel.com>
---
 MAINTAINERS                                |   4 +
 config/common_linuxapp                     |   5 +
 lib/Makefile                               |   1 +
 lib/librte_ethtool/Makefile                |  56 +++++++
 lib/librte_ethtool/rte_ethtool.c           | 155 +++++++++++++++++
 lib/librte_ethtool/rte_ethtool.h           | 257 +++++++++++++++++++++++++++++
 lib/librte_ethtool/rte_ethtool_version.map |  18 ++
 mk/rte.app.mk                              |   1 +
 8 files changed, 497 insertions(+)
 create mode 100644 lib/librte_ethtool/Makefile
 create mode 100644 lib/librte_ethtool/rte_ethtool.c
 create mode 100644 lib/librte_ethtool/rte_ethtool.h
 create mode 100644 lib/librte_ethtool/rte_ethtool_version.map

diff --git a/MAINTAINERS b/MAINTAINERS
index 9362c19..b8b481f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -186,6 +186,10 @@ M: Thomas Monjalon <thomas.monjalon@6wind.com>
 F: lib/librte_ether/
 F: scripts/test-null.sh
 
+Ethtool API
+M: Liang-Min Larry Wang <liang-min.wang@intel.com>
+F: lib/librte_ethtool/
+
 
 Drivers
 -------
diff --git a/config/common_linuxapp b/config/common_linuxapp
index 0078dc9..f5759fd 100644
--- a/config/common_linuxapp
+++ b/config/common_linuxapp
@@ -129,6 +129,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile user-space ethtool library
+#
+CONFIG_RTE_LIBRTE_ETHTOOL=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
diff --git a/lib/Makefile b/lib/Makefile
index 5f480f9..a6c7375 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -41,6 +41,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer
 DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile
 DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline
 DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_ETHTOOL) += librte_ethtool
 DIRS-$(CONFIG_RTE_LIBRTE_VHOST) += librte_vhost
 DIRS-$(CONFIG_RTE_LIBRTE_HASH) += librte_hash
 DIRS-$(CONFIG_RTE_LIBRTE_LPM) += librte_lpm
diff --git a/lib/librte_ethtool/Makefile b/lib/librte_ethtool/Makefile
new file mode 100644
index 0000000..1d981f6
--- /dev/null
+++ b/lib/librte_ethtool/Makefile
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_ethtool.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+EXPORT_MAP := rte_ethtool_version.map
+
+LIBABIVER := 1
+
+SRCS-y += rte_ethtool.c
+
+#
+# Export include files
+#
+SYMLINK-y-include += rte_ethtool.h
+
+# this lib depends upon:
+DEPDIRS-y += lib/librte_ether
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_ethtool/rte_ethtool.c b/lib/librte_ethtool/rte_ethtool.c
new file mode 100644
index 0000000..2ccf06f
--- /dev/null
+++ b/lib/librte_ethtool/rte_ethtool.c
@@ -0,0 +1,155 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <rte_version.h>
+#include <rte_ethdev.h>
+#include "rte_ethtool.h"
+
+int
+rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo)
+{
+	struct rte_eth_dev_info dev_info;
+
+	memset(&dev_info, 0, sizeof(dev_info));
+	rte_eth_dev_info_get(port_id, &dev_info);
+
+	snprintf(drvinfo->driver, sizeof(drvinfo->driver), "%s",
+		dev_info.driver_name);
+	snprintf(drvinfo->version, sizeof(drvinfo->version), "%s",
+		rte_version());
+	snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
+		"%04x:%02x:%02x.%x",
+		dev_info.pci_dev->addr.domain, dev_info.pci_dev->addr.bus,
+		dev_info.pci_dev->addr.devid, dev_info.pci_dev->addr.function);
+
+	drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
+	drvinfo->testinfo_len = 0;
+
+	return 0;
+}
+
+int
+rte_ethtool_get_link(uint8_t port_id)
+{
+	struct rte_eth_link link;
+
+	rte_eth_link_get(port_id, &link);
+	return link.link_status;
+}
+
+int
+rte_ethtool_net_open(uint8_t port_id)
+{
+	rte_eth_dev_stop(port_id);
+
+	return rte_eth_dev_start(port_id);
+}
+
+int
+rte_ethtool_net_stop(uint8_t port_id)
+{
+	rte_eth_dev_stop(port_id);
+
+	return 0;
+}
+
+int
+rte_ethtool_net_get_mac_addr(uint8_t port_id, struct ether_addr *addr)
+{
+	rte_eth_macaddr_get(port_id, addr);
+
+	return 0;
+}
+
+int
+rte_ethtool_net_set_mac_addr(uint8_t port_id, struct ether_addr *addr)
+{
+	return rte_eth_dev_default_mac_addr_set(port_id, addr);
+}
+
+int
+rte_ethtool_net_validate_addr(uint8_t port_id __rte_unused,
+	struct ether_addr *addr)
+{
+	return is_valid_assigned_ether_addr(addr);
+}
+
+int
+rte_ethtool_net_set_config(uint8_t port_id, void *config __rte_unused)
+{
+	struct rte_eth_link link;
+
+	memset(&link, 0, sizeof(link));
+	rte_eth_link_get(port_id, &link);
+	if (link.link_status == 1)
+		return -EINVAL;
+	return 0;
+}
+
+int
+rte_ethtool_net_change_mtu(uint8_t port_id, int mtu)
+{
+	return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu);
+}
+
+int
+rte_ethtool_net_get_stats64(uint8_t port_id, struct rte_eth_stats *stats)
+{
+	return rte_eth_stats_get(port_id, stats);
+}
+
+int
+rte_ethtool_net_vlan_rx_add_vid(uint8_t port_id, uint16_t vid)
+{
+	return rte_eth_dev_vlan_filter(port_id, vid, 1);
+}
+
+int
+rte_ethtool_net_vlan_rx_kill_vid(uint8_t port_id, uint16_t vid)
+{
+	return rte_eth_dev_vlan_filter(port_id, vid, 0);
+}
+
+int
+rte_ethtool_net_set_rx_mode(uint8_t port_id __rte_unused)
+{
+	/*
+	 * The set_rx_mode op is part of pmd driver start operation, and
+	 * the ethdev api maintains software configuration parameters and under-
+	 * line hardware states consistent, so no operation is needed for
+	 * rte_ethtool_net_set_rx_mode().
+	 */
+	return 0;
+}
diff --git a/lib/librte_ethtool/rte_ethtool.h b/lib/librte_ethtool/rte_ethtool.h
new file mode 100644
index 0000000..0488e8e
--- /dev/null
+++ b/lib/librte_ethtool/rte_ethtool.h
@@ -0,0 +1,257 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETHTOOL_H_
+#define _RTE_ETHTOOL_H_
+
+/*
+ * This new interface is designed to provide a user-space shim layer for
+ * Ethtool and Netdevice op API.
+ *
+ * rte_ethtool_get_driver:          ethtool_ops::get_driverinfo
+ * rte_ethtool_get_link:            ethtool_ops::get_link
+ *
+ * rte_ethtool_net_open:            net_device_ops::ndo_open
+ * rte_ethtool_net_stop:            net_device_ops::ndo_stop
+ * rte_ethtool_net_set_mac_addr:    net_device_ops::ndo_set_mac_address
+ * rte_ethtool_net_validate_addr:   net_device_ops::ndo_validate_addr
+ * rte_ethtool_net_set_config:      net_device_ops::ndo_set_config
+ * rte_ethtool_net_change_mtu:      net_device_ops::rte_net_change_mtu
+ * rte_ethtool_net_get_stats64:     net_device_ops::ndo_get_stats64
+ * rte_ethtool_net_vlan_rx_add_vid  net_device_ops::ndo_vlan_rx_add_vid
+ * rte_ethtool_net_vlan_rx_kill_vid net_device_ops::ndo_vlan_rx_kill_vid
+ * rte_ethtool_net_set_rx_mode      net_device_ops::ndo_set_rx_mode
+ *
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <rte_ethdev.h>
+#include <linux/ethtool.h>
+
+/**
+ * Retrieve the Ethernet device driver information according to attributes described by
+ * ethtool data structure, ethtool_drvinfo
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param drvinfo
+ *   A pointer to get driver information
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo);
+
+/**
+ * Retrieve the Ethernet device link status
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @return
+ *   - (1) if link up.
+ *   - (0) if link down.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_get_link(uint8_t port_id);
+
+/**
+ * Start the Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_open(uint8_t port_id);
+
+/**
+ * Stop the Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_stop(uint8_t port_id);
+
+/**
+ * Get the Ethernet device MAC address.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param addr
+ *	 MAC address of the Ethernet device.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_get_mac_addr(uint8_t port_id, struct ether_addr *addr);
+
+/**
+ * Setting the Ethernet device MAC address.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param addr
+ *	 The new MAC addr.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_set_mac_addr(uint8_t port_id, struct ether_addr *addr);
+
+/**
+ * Validate if the provided MAC address is valid unicast address
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param addr
+ *	 A pointer to a buffer (6-byte, 48bit) for the target MAC address
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_validate_addr(uint8_t port_id, struct ether_addr *addr);
+
+/**
+ * Setting the Ethernet device configuration.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param config
+ *	 A opintr to a configuration parameter.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_set_config(uint8_t port_id, void *config);
+
+/**
+ * Setting the Ethernet device maximum Tx unit.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param mtu
+ *	 New MTU
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_change_mtu(uint8_t port_id, int mtu);
+
+/**
+ * Retrieve the Ethernet device traffic statistics
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param stats
+ *	 A pointer to struct rte_eth_stats for statistics parameters
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_get_stats64(uint8_t port_id, struct rte_eth_stats *stats);
+
+/**
+ * Update the Ethernet device VLAN filter with new vid
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param vid
+ *	 A new VLAN id
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_vlan_rx_add_vid(uint8_t port_id, uint16_t vid);
+
+/**
+ * Remove VLAN id from Ethernet device.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param vid
+ *	 A new VLAN id
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_vlan_rx_kill_vid(uint8_t port_id, uint16_t vid);
+
+/**
+ * Setting the Ethernet device rx mode.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - others depends on the specific operations implementation.
+ */
+int rte_ethtool_net_set_rx_mode(uint8_t port_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_ETHTOOL_H_ */
diff --git a/lib/librte_ethtool/rte_ethtool_version.map b/lib/librte_ethtool/rte_ethtool_version.map
new file mode 100644
index 0000000..82fc0d3
--- /dev/null
+++ b/lib/librte_ethtool/rte_ethtool_version.map
@@ -0,0 +1,18 @@
+DPDK_2.0 {
+	global:
+
+	rte_ethtool_net_open;
+	rte_ethtool_net_stop;
+	rte_ethtool_net_get_mac_addr;
+	rte_ethtool_net_get_mac_addr;
+	rte_ethtool_net_validate_addr;
+	rte_ethtool_net_set_config;
+	rte_ethtool_net_change_mtu;
+	rte_ethtool_net_get_stats64;
+	rte_ethtool_net_vlan_rx_add_vid;
+	rte_ethtool_net_vlan_rx_kill_vid;
+	rte_ethtool_get_drvinfo;
+	rte_ethtool_get_link;
+
+	local: *;
+};
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index 1a2043a..86867a6 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -105,6 +105,7 @@ ifeq ($(CONFIG_RTE_BUILD_COMBINE_LIBS),n)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_KVARGS)         += -lrte_kvargs
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MBUF)           += -lrte_mbuf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
+_LDLIBS-$(CONFIG_RTE_LIBRTE_ETHTOOL)        += -lrte_ethtool
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ETHER)          += -lethdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MALLOC)         += -lrte_malloc
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
-- 
2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-05-29 13:15 ` [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address Liang-Min Larry Wang
@ 2015-05-29 15:20   ` Stephen Hemminger
  2015-05-29 18:21     ` Wang, Liang-min
  0 siblings, 1 reply; 16+ messages in thread
From: Stephen Hemminger @ 2015-05-29 15:20 UTC (permalink / raw)
  To: Liang-Min Larry Wang; +Cc: dev, aharton, bruce.richardson

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 2/2] ethtool: add new library to provide ethtool-alike APIs
  2015-05-29 13:15 ` [dpdk-dev] [PATCH 2/2] ethtool: add new library to provide ethtool-alike APIs Liang-Min Larry Wang
@ 2015-05-29 15:22   ` Stephen Hemminger
  2015-05-29 18:17     ` Wang, Liang-min
  0 siblings, 1 reply; 16+ messages in thread
From: Stephen Hemminger @ 2015-05-29 15:22 UTC (permalink / raw)
  To: Liang-Min Larry Wang; +Cc: dev, aharton, bruce.richardson

On Fri, 29 May 2015 09:15:09 -0400
Liang-Min Larry Wang <liang-min.wang@intel.com> wrote:

> +	drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
> +	drvinfo->testinfo_len = 0;


Providing a hook to access more functionality is good and compatiablity
with old API's is helpful.  Too bad ethtool is kind of a clunky old
inflexible, and easily broken with changes. But that is not your fault.

Duplicating eth_stats in ethtool is not helpful.
This is actively discouraged for Linux device drivers.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 2/2] ethtool: add new library to provide ethtool-alike APIs
  2015-05-29 15:22   ` Stephen Hemminger
@ 2015-05-29 18:17     ` Wang, Liang-min
  0 siblings, 0 replies; 16+ messages in thread
From: Wang, Liang-min @ 2015-05-29 18:17 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, bruce.richardson


>On Fri, 29 May 2015 09:15:09 -0400
>Liang-Min Larry Wang <liang-min.wang@intel.com> wrote:
>
>> +	drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
> >+	drvinfo->testinfo_len = 0;
>
>
>Providing a hook to access more functionality is good and compatiablity with old API's is helpful.  Too bad ethtool is kind of a clunky old inflexible, and easily broken with changes. But >that is not your fault.
>
>Duplicating eth_stats in ethtool is not helpful.
>This is actively discouraged for Linux device drivers.

(I have a typo of David's email, and I corrected it in this email)
This new library is designed to support ethtool alike interface, some of the implementation will be just a placeholder. The rte_ethtool_net_get_stats64 is designed as a place holder to support net_device_ops::ndo_get_stats64. For the legacy support, it is required to provide # of statistic parameters are supported, so caller can allocate right size of buffer to get statistic from device driver.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-05-29 15:20   ` Stephen Hemminger
@ 2015-05-29 18:21     ` Wang, Liang-min
  0 siblings, 0 replies; 16+ messages in thread
From: Wang, Liang-min @ 2015-05-29 18:21 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, bruce.richardson


>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.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-06-02 14:51       ` Stephen Hemminger
@ 2015-06-02 15:07         ` Wang, Liang-min
  0 siblings, 0 replies; 16+ messages in thread
From: Wang, Liang-min @ 2015-06-02 15:07 UTC (permalink / raw)
  To: Stephen Hemminger, Thomas Monjalon; +Cc: dev


>On Tue, 02 Jun 2015 14:23:22 +0200
>Thomas Monjalon <thomas.monjalon@6wind.com> wrote:

>> 2015-06-02 10:52, Ananyev, Konstantin:
> >> From: Wang, Liang-min
> > >>  int
> > >>+rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct 
> > >> +ether_addr *addr) {
> > >> +	struct rte_eth_dev *dev;
> > >> +
> > >> +	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_set, -ENOTSUP);
> > >> +
> > >> +	return (*dev->dev_ops->mac_addr_set)(dev, addr); }
> >> 
> >> As I can see mac_addr_set() is implemented now only for virtio.
> >> Which means that for all Intel HW your new 
> >> rte_eth_dev_default_mac_addr_set()
> >> would not work right now?
> >> Probably rte_eth_dev_default_mac_addr_set() should combine both approaches:
> >> If mac_addr_set() is implemented by dev, then use it, otherwise try 
> >> to use addr_remove()/addr_add() (as your first version did)?
> >> Konstantin     
>> 
>> Not sure it is a good idea to use remove/add to set the default unicast mac address.
>> It would be clearer to add comments to remove/add functions to specify 
>> that they don't apply to the default adress but only to secondary 
>> ones. Then use the same logic for both API and driver ops.
>> It is the responsibility of the driver implementation to use common 
>> functions for default_set and remove/add functions.

>Only vmxnet3 and virtio need special treatment. virtio is already covered.
>Here is patch for vmxnet3. We have used this for several releases.

To be consistent with implementation of ethdev API, rte_eth_macaddr_get, should mac_addr_set ops in both virtio and vmxnet3 update
 dev->data->mac_addrs[0]. So, the mac_addr_set and mac_addr_get are consistent.

>From eef188102338c5687b9075d468eabbe87693b075 Mon Sep 17 00:00:00 2001
>From: Stephen Hemminger <stephen@networkplumber.org>
>Date: Tue, 2 Jun 2015 07:49:53 -0700
>Subject: [PATCH] vmxnet3: support setting primary MAC address
>
>This allows setting primary MAC address on VMXNET3.
>
>Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>---
> drivers/net/vmxnet3/vmxnet3_ethdev.c | 45 +++++++++++++++++++++++++-----------
> 1 file changed, 31 insertions(+), 14 deletions(-)
>
>diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
>index 1685ce4..6515f74 100644
>--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
>+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
>@@ -85,6 +85,9 @@ static void vmxnet3_dev_stats_get(struct rte_eth_dev *dev,
> 				struct rte_eth_stats *stats);
> static void vmxnet3_dev_info_get(struct rte_eth_dev *dev,
> 				struct rte_eth_dev_info *dev_info);
>+static void vmxnet3_mac_addr_set(struct rte_eth_dev *dev,
>+				 struct ether_addr *mac_addr);
>+
> #if PROCESS_SYS_EVENTS == 1
> static void vmxnet3_process_events(struct vmxnet3_hw *);  #endif @@ -110,6 +113,7 @@ static const struct eth_dev_ops vmxnet3_eth_dev_ops = {
> 	.allmulticast_disable = vmxnet3_dev_allmulticast_disable,
> 	.link_update          = vmxnet3_dev_link_update,
> 	.stats_get            = vmxnet3_dev_stats_get,
>+	.mac_addr_set	      = vmxnet3_mac_addr_set,
> 	.dev_infos_get        = vmxnet3_dev_info_get,
> 	.rx_queue_setup       = vmxnet3_dev_rx_queue_setup,
> 	.rx_queue_release     = vmxnet3_dev_rx_queue_release,
>@@ -359,6 +363,23 @@ vmxnet3_dev_configure(struct rte_eth_dev *dev)
> 	return 0;
> }
> 
>+static void
>+vmxnet3_write_mac(struct vmxnet3_hw *hw, const uint8_t *addr) {
>+	uint32_t val;
>+
>+	PMD_INIT_LOG(DEBUG,
>+		     "Writing MAC Address : %02x:%02x:%02x:%02x:%02x:%02x",
>+		     addr[0], addr[1], addr[2],
>+		     addr[3], addr[4], addr[5]);
>+
>+	val = *(const uint32_t *)addr;
>+	VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACL, val);
>+
>+	val = (addr[5] << 8) | addr[4];
>+	VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACH, val); }
>+
> static int
> vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)  { @@ -366,8 +387,7 @@ vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)
> 	struct vmxnet3_hw *hw = dev->data->dev_private;
> 	Vmxnet3_DriverShared *shared = hw->shared;
> 	Vmxnet3_DSDevRead *devRead = &shared->devRead;
>-	uint32_t *mac_ptr;
>-	uint32_t val, i;
>+	uint32_t i;
> 	int ret;
> 
> 	shared->magic = VMXNET3_REV1_MAGIC;
>@@ -459,18 +479,7 @@ vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)
> 			return ret;
> 	}
> 
>-	PMD_INIT_LOG(DEBUG,
>-		     "Writing MAC Address : %02x:%02x:%02x:%02x:%02x:%02x",
>-		     hw->perm_addr[0], hw->perm_addr[1], hw->perm_addr[2],
>-		     hw->perm_addr[3], hw->perm_addr[4], hw->perm_addr[5]);
>-
>-	/* Write MAC Address back to device */
>-	mac_ptr = (uint32_t *)hw->perm_addr;
>-	val = *mac_ptr;
>-	VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACL, val);
>-
>-	val = (hw->perm_addr[5] << 8) | hw->perm_addr[4];
>-	VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACH, val);
>+	vmxnet3_write_mac(hw, hw->perm_addr);
> 
> 	return VMXNET3_SUCCESS;
> }
>@@ -645,6 +654,14 @@ vmxnet3_dev_info_get(__attribute__((unused))struct rte_eth_dev *dev, struct rte_
> 	dev_info->flow_type_rss_offloads = VMXNET3_RSS_OFFLOAD_ALL;  }
> 
>+static void
>+vmxnet3_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr 
>+*mac_addr) {
>+	struct vmxnet3_hw *hw = dev->data->dev_private;
>+
>+	vmxnet3_write_mac(hw, mac_addr->addr_bytes); }
>+
>/* return 0 means link status changed, -1 means not changed */  static int  vmxnet3_dev_link_update(struct rte_eth_dev *dev, __attribute__((unused)) int wait_to_complete)
--
2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-06-02 12:23     ` Thomas Monjalon
@ 2015-06-02 14:51       ` Stephen Hemminger
  2015-06-02 15:07         ` Wang, Liang-min
  0 siblings, 1 reply; 16+ messages in thread
From: Stephen Hemminger @ 2015-06-02 14:51 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Wang, Liang-min

On Tue, 02 Jun 2015 14:23:22 +0200
Thomas Monjalon <thomas.monjalon@6wind.com> wrote:

> 2015-06-02 10:52, Ananyev, Konstantin:
> > From: Wang, Liang-min  
> > >  int
> > > +rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
> > > +{
> > > +	struct rte_eth_dev *dev;
> > > +
> > > +	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_set, -ENOTSUP);
> > > +
> > > +	return (*dev->dev_ops->mac_addr_set)(dev, addr);
> > > +}  
> > 
> > As I can see mac_addr_set() is implemented now only for virtio.
> > Which means that for all Intel HW your new rte_eth_dev_default_mac_addr_set()
> > would not work right now?
> > Probably rte_eth_dev_default_mac_addr_set() should combine both approaches:
> > If mac_addr_set() is implemented by dev, then use it, otherwise try to use addr_remove()/addr_add()
> > (as your first version did)?
> > Konstantin     
> 
> Not sure it is a good idea to use remove/add to set the default unicast mac address.
> It would be clearer to add comments to remove/add functions to specify that
> they don't apply to the default adress but only to secondary ones. Then use
> the same logic for both API and driver ops.
> It is the responsibility of the driver implementation to use common functions
> for default_set and remove/add functions.

Only vmxnet3 and virtio need special treatment. virtio is already covered.
Here is patch for vmxnet3. We have used this for several releases.


From eef188102338c5687b9075d468eabbe87693b075 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <stephen@networkplumber.org>
Date: Tue, 2 Jun 2015 07:49:53 -0700
Subject: [PATCH] vmxnet3: support setting primary MAC address

This allows setting primary MAC address on VMXNET3.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 45 +++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index 1685ce4..6515f74 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -85,6 +85,9 @@ static void vmxnet3_dev_stats_get(struct rte_eth_dev *dev,
 				struct rte_eth_stats *stats);
 static void vmxnet3_dev_info_get(struct rte_eth_dev *dev,
 				struct rte_eth_dev_info *dev_info);
+static void vmxnet3_mac_addr_set(struct rte_eth_dev *dev,
+				 struct ether_addr *mac_addr);
+
 #if PROCESS_SYS_EVENTS == 1
 static void vmxnet3_process_events(struct vmxnet3_hw *);
 #endif
@@ -110,6 +113,7 @@ static const struct eth_dev_ops vmxnet3_eth_dev_ops = {
 	.allmulticast_disable = vmxnet3_dev_allmulticast_disable,
 	.link_update          = vmxnet3_dev_link_update,
 	.stats_get            = vmxnet3_dev_stats_get,
+	.mac_addr_set	      = vmxnet3_mac_addr_set,
 	.dev_infos_get        = vmxnet3_dev_info_get,
 	.rx_queue_setup       = vmxnet3_dev_rx_queue_setup,
 	.rx_queue_release     = vmxnet3_dev_rx_queue_release,
@@ -359,6 +363,23 @@ vmxnet3_dev_configure(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static void
+vmxnet3_write_mac(struct vmxnet3_hw *hw, const uint8_t *addr)
+{
+	uint32_t val;
+
+	PMD_INIT_LOG(DEBUG,
+		     "Writing MAC Address : %02x:%02x:%02x:%02x:%02x:%02x",
+		     addr[0], addr[1], addr[2],
+		     addr[3], addr[4], addr[5]);
+
+	val = *(const uint32_t *)addr;
+	VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACL, val);
+
+	val = (addr[5] << 8) | addr[4];
+	VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACH, val);
+}
+
 static int
 vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)
 {
@@ -366,8 +387,7 @@ vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)
 	struct vmxnet3_hw *hw = dev->data->dev_private;
 	Vmxnet3_DriverShared *shared = hw->shared;
 	Vmxnet3_DSDevRead *devRead = &shared->devRead;
-	uint32_t *mac_ptr;
-	uint32_t val, i;
+	uint32_t i;
 	int ret;
 
 	shared->magic = VMXNET3_REV1_MAGIC;
@@ -459,18 +479,7 @@ vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)
 			return ret;
 	}
 
-	PMD_INIT_LOG(DEBUG,
-		     "Writing MAC Address : %02x:%02x:%02x:%02x:%02x:%02x",
-		     hw->perm_addr[0], hw->perm_addr[1], hw->perm_addr[2],
-		     hw->perm_addr[3], hw->perm_addr[4], hw->perm_addr[5]);
-
-	/* Write MAC Address back to device */
-	mac_ptr = (uint32_t *)hw->perm_addr;
-	val = *mac_ptr;
-	VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACL, val);
-
-	val = (hw->perm_addr[5] << 8) | hw->perm_addr[4];
-	VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACH, val);
+	vmxnet3_write_mac(hw, hw->perm_addr);
 
 	return VMXNET3_SUCCESS;
 }
@@ -645,6 +654,14 @@ vmxnet3_dev_info_get(__attribute__((unused))struct rte_eth_dev *dev, struct rte_
 	dev_info->flow_type_rss_offloads = VMXNET3_RSS_OFFLOAD_ALL;
 }
 
+static void
+vmxnet3_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
+{
+	struct vmxnet3_hw *hw = dev->data->dev_private;
+
+	vmxnet3_write_mac(hw, mac_addr->addr_bytes);
+}
+
 /* return 0 means link status changed, -1 means not changed */
 static int
 vmxnet3_dev_link_update(struct rte_eth_dev *dev, __attribute__((unused)) int wait_to_complete)
-- 
2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-06-02 12:23     ` Wang, Liang-min
@ 2015-06-02 13:10       ` Ananyev, Konstantin
  0 siblings, 0 replies; 16+ messages in thread
From: Ananyev, Konstantin @ 2015-06-02 13:10 UTC (permalink / raw)
  To: Wang, Liang-min, dev



> -----Original Message-----
> From: Wang, Liang-min
> Sent: Tuesday, June 02, 2015 1:24 PM
> To: Ananyev, Konstantin; dev@dpdk.org
> Cc: Richardson, Bruce; dharton@cisco.com; agh@cisco.com
> Subject: RE: [PATCH 1/2] ethdev: add api to set default mac address
> 
> 
> >> -----Original Message-----
> >> From: Wang, Liang-min
> >> Sent: Friday, May 29, 2015 8:27 PM
> >> To: dev@dpdk.org
> >> Cc: Richardson, Bruce; Ananyev, Konstantin; dharton@cisco.com;
> > >agh@cisco.com; Wang, Liang-min
> >> Subject: [PATCH 1/2] ethdev: add api to set default mac address
> > >
> >> 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          | 16 ++++++++++++++++
> > > lib/librte_ether/rte_ethdev.h          | 14 ++++++++++++++
> >>  lib/librte_ether/rte_ether_version.map |  1 +
> >> 3 files changed, 31 insertions(+)
> >>
> >> diff --git a/lib/librte_ether/rte_ethdev.c
> >> b/lib/librte_ether/rte_ethdev.c index 024fe8b..96ee00e 100644
> >> --- a/lib/librte_ether/rte_ethdev.c
> >> +++ b/lib/librte_ether/rte_ethdev.c
> >> @@ -2752,6 +2752,22 @@ 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;
> >> +
> >> +	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_set, -ENOTSUP);
> >> +
> >> +	return (*dev->dev_ops->mac_addr_set)(dev, addr); }
> 
> 
> >As I can see mac_addr_set() is implemented now only for virtio.
> >Which means that for all Intel HW your new rte_eth_dev_default_mac_addr_set()
> >would not work right now?
> >Probably rte_eth_dev_default_mac_addr_set() should combine both approaches:
> >If mac_addr_set() is implemented by dev, then use it, otherwise try to use addr_remove()/addr_add() (as your first version did)?
> >Konstantin
> 
> The implementation of mac_addr_set() through mac_addr_remove() and mac_addr_add() is very creative, but it may not work for
> devices other than igb/ixgbe. I will release a patch latter to add hooks on igb and ixgbe(). Just want to keep this interface clean and not
> to be confined to igb/ixgbe characteristics.

Ok, if you think it would be more clean way - no objections from me.
Konstantin

> 
> > +
> > +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: *;
> >  };
> > --
> > 2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-06-02 10:52   ` Ananyev, Konstantin
  2015-06-02 12:23     ` Thomas Monjalon
@ 2015-06-02 12:23     ` Wang, Liang-min
  2015-06-02 13:10       ` Ananyev, Konstantin
  1 sibling, 1 reply; 16+ messages in thread
From: Wang, Liang-min @ 2015-06-02 12:23 UTC (permalink / raw)
  To: Ananyev, Konstantin, dev


>> -----Original Message-----
>> From: Wang, Liang-min
>> Sent: Friday, May 29, 2015 8:27 PM
>> To: dev@dpdk.org
>> Cc: Richardson, Bruce; Ananyev, Konstantin; dharton@cisco.com; 
> >agh@cisco.com; Wang, Liang-min
>> Subject: [PATCH 1/2] ethdev: add api to set default mac address
> >
>> 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          | 16 ++++++++++++++++
> > lib/librte_ether/rte_ethdev.h          | 14 ++++++++++++++
>>  lib/librte_ether/rte_ether_version.map |  1 +
>> 3 files changed, 31 insertions(+)
>>
>> diff --git a/lib/librte_ether/rte_ethdev.c 
>> b/lib/librte_ether/rte_ethdev.c index 024fe8b..96ee00e 100644
>> --- a/lib/librte_ether/rte_ethdev.c
>> +++ b/lib/librte_ether/rte_ethdev.c
>> @@ -2752,6 +2752,22 @@ 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;
>> +
>> +	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_set, -ENOTSUP);
>> +
>> +	return (*dev->dev_ops->mac_addr_set)(dev, addr); }


>As I can see mac_addr_set() is implemented now only for virtio.
>Which means that for all Intel HW your new rte_eth_dev_default_mac_addr_set()
>would not work right now?
>Probably rte_eth_dev_default_mac_addr_set() should combine both approaches:
>If mac_addr_set() is implemented by dev, then use it, otherwise try to use addr_remove()/addr_add() (as your first version did)?
>Konstantin   

The implementation of mac_addr_set() through mac_addr_remove() and mac_addr_add() is very creative, but it may not work for devices other than igb/ixgbe. I will release a patch latter to add hooks on igb and ixgbe(). Just want to keep this interface clean and not to be confined to igb/ixgbe characteristics.

> +
> +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: *;
>  };
> --
> 2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-06-02 10:52   ` Ananyev, Konstantin
@ 2015-06-02 12:23     ` Thomas Monjalon
  2015-06-02 14:51       ` Stephen Hemminger
  2015-06-02 12:23     ` Wang, Liang-min
  1 sibling, 1 reply; 16+ messages in thread
From: Thomas Monjalon @ 2015-06-02 12:23 UTC (permalink / raw)
  To: Ananyev, Konstantin; +Cc: dev, Wang, Liang-min

2015-06-02 10:52, Ananyev, Konstantin:
> From: Wang, Liang-min
> >  int
> > +rte_eth_dev_default_mac_addr_set(uint8_t port_id, struct ether_addr *addr)
> > +{
> > +	struct rte_eth_dev *dev;
> > +
> > +	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_set, -ENOTSUP);
> > +
> > +	return (*dev->dev_ops->mac_addr_set)(dev, addr);
> > +}
> 
> As I can see mac_addr_set() is implemented now only for virtio.
> Which means that for all Intel HW your new rte_eth_dev_default_mac_addr_set()
> would not work right now?
> Probably rte_eth_dev_default_mac_addr_set() should combine both approaches:
> If mac_addr_set() is implemented by dev, then use it, otherwise try to use addr_remove()/addr_add()
> (as your first version did)?
> Konstantin   

Not sure it is a good idea to use remove/add to set the default unicast mac address.
It would be clearer to add comments to remove/add functions to specify that
they don't apply to the default adress but only to secondary ones. Then use
the same logic for both API and driver ops.
It is the responsibility of the driver implementation to use common functions
for default_set and remove/add functions.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-05-29 19:26 ` [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address Liang-Min Larry Wang
@ 2015-06-02 10:52   ` Ananyev, Konstantin
  2015-06-02 12:23     ` Thomas Monjalon
  2015-06-02 12:23     ` Wang, Liang-min
  0 siblings, 2 replies; 16+ messages in thread
From: Ananyev, Konstantin @ 2015-06-02 10:52 UTC (permalink / raw)
  To: Wang, Liang-min, dev



> -----Original Message-----
> From: Wang, Liang-min
> Sent: Friday, May 29, 2015 8:27 PM
> To: dev@dpdk.org
> Cc: Richardson, Bruce; Ananyev, Konstantin; dharton@cisco.com; agh@cisco.com; Wang, Liang-min
> Subject: [PATCH 1/2] ethdev: add api to set default mac address
> 
> 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          | 16 ++++++++++++++++
>  lib/librte_ether/rte_ethdev.h          | 14 ++++++++++++++
>  lib/librte_ether/rte_ether_version.map |  1 +
>  3 files changed, 31 insertions(+)
> 
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
> index 024fe8b..96ee00e 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -2752,6 +2752,22 @@ 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;
> +
> +	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_set, -ENOTSUP);
> +
> +	return (*dev->dev_ops->mac_addr_set)(dev, addr);
> +}


As I can see mac_addr_set() is implemented now only for virtio.
Which means that for all Intel HW your new rte_eth_dev_default_mac_addr_set()
would not work right now?
Probably rte_eth_dev_default_mac_addr_set() should combine both approaches:
If mac_addr_set() is implemented by dev, then use it, otherwise try to use addr_remove()/addr_add()
(as your first version did)?
Konstantin   


> +
> +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: *;
>  };
> --
> 2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-05-30  0:37 ` [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address Liang-Min Larry Wang
@ 2015-05-30  1:57   ` Andrew Harvey (agh)
  0 siblings, 0 replies; 16+ messages in thread
From: Andrew Harvey (agh) @ 2015-05-30  1:57 UTC (permalink / raw)
  To: Liang-Min Larry Wang, dev

On 5/29/15, 5:37 PM, "Liang-Min Larry Wang" <liang-min.wang@intel.com>
wrote:
>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          | 18 ++++++++++++++++++
> lib/librte_ether/rte_ethdev.h          | 14 ++++++++++++++
> lib/librte_ether/rte_ether_version.map |  1 +
> 3 files changed, 33 insertions(+)
>
>diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
>index 024fe8b..85ce72e 100644
>--- a/lib/librte_ether/rte_ethdev.c
>+++ b/lib/librte_ether/rte_ethdev.c
>@@ -2752,6 +2752,24 @@ 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;
>+
>+	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_set, -ENOTSUP);
>+
>+	(*dev->dev_ops->mac_addr_set)(dev, addr);
>+
>+	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: *;
> };
>-- 
>2.1.4

Acked-by: Andrew Harvey (agh) <agh@cisco.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-05-30  0:37 [dpdk-dev] [PATCH 0/2] User-space Ethtool Liang-Min Larry Wang
@ 2015-05-30  0:37 ` Liang-Min Larry Wang
  2015-05-30  1:57   ` Andrew Harvey (agh)
  0 siblings, 1 reply; 16+ messages in thread
From: Liang-Min Larry Wang @ 2015-05-30  0:37 UTC (permalink / raw)
  To: dev; +Cc: Liang-Min Larry Wang

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          | 18 ++++++++++++++++++
 lib/librte_ether/rte_ethdev.h          | 14 ++++++++++++++
 lib/librte_ether/rte_ether_version.map |  1 +
 3 files changed, 33 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 024fe8b..85ce72e 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2752,6 +2752,24 @@ 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;
+
+	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_set, -ENOTSUP);
+
+	(*dev->dev_ops->mac_addr_set)(dev, addr);
+
+	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: *;
 };
-- 
2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address
  2015-05-29 19:26 [dpdk-dev] [PATCH 0/2] User-space Ethtool Liang-Min Larry Wang
@ 2015-05-29 19:26 ` Liang-Min Larry Wang
  2015-06-02 10:52   ` Ananyev, Konstantin
  0 siblings, 1 reply; 16+ messages in thread
From: Liang-Min Larry Wang @ 2015-05-29 19:26 UTC (permalink / raw)
  To: dev; +Cc: Liang-Min Larry Wang

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          | 16 ++++++++++++++++
 lib/librte_ether/rte_ethdev.h          | 14 ++++++++++++++
 lib/librte_ether/rte_ether_version.map |  1 +
 3 files changed, 31 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 024fe8b..96ee00e 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2752,6 +2752,22 @@ 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;
+
+	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_set, -ENOTSUP);
+
+	return (*dev->dev_ops->mac_addr_set)(dev, addr);
+}
+
+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: *;
 };
-- 
2.1.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-06-02 15:08 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-29 13:15 [dpdk-dev] [PATCH 0/2] User-space Ethtool Liang-Min Larry Wang
2015-05-29 13:15 ` [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address Liang-Min Larry Wang
2015-05-29 15:20   ` Stephen Hemminger
2015-05-29 18:21     ` Wang, Liang-min
2015-05-29 13:15 ` [dpdk-dev] [PATCH 2/2] ethtool: add new library to provide ethtool-alike APIs Liang-Min Larry Wang
2015-05-29 15:22   ` Stephen Hemminger
2015-05-29 18:17     ` Wang, Liang-min
2015-05-29 19:26 [dpdk-dev] [PATCH 0/2] User-space Ethtool Liang-Min Larry Wang
2015-05-29 19:26 ` [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address Liang-Min Larry Wang
2015-06-02 10:52   ` Ananyev, Konstantin
2015-06-02 12:23     ` Thomas Monjalon
2015-06-02 14:51       ` Stephen Hemminger
2015-06-02 15:07         ` Wang, Liang-min
2015-06-02 12:23     ` Wang, Liang-min
2015-06-02 13:10       ` Ananyev, Konstantin
2015-05-30  0:37 [dpdk-dev] [PATCH 0/2] User-space Ethtool Liang-Min Larry Wang
2015-05-30  0:37 ` [dpdk-dev] [PATCH 1/2] ethdev: add api to set default mac address Liang-Min Larry Wang
2015-05-30  1:57   ` Andrew Harvey (agh)

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).