summaryrefslogtreecommitdiff
path: root/lib/librte_ethdev
diff options
context:
space:
mode:
authorThomas Monjalon <thomas@monjalon.net>2018-10-22 15:15:30 +0200
committerFerruh Yigit <ferruh.yigit@intel.com>2018-10-26 22:14:06 +0200
commitc10cdce180a6ac535dc420376f115ca4ac44aead (patch)
tree42b5fd30a07a999cf7c5cb69fa263940afec268e /lib/librte_ethdev
parenta7d3c6271d558e881e3ba1304e9f8683aca944e4 (diff)
downloaddpdk-next-eventdev-c10cdce180a6ac535dc420376f115ca4ac44aead.zip
dpdk-next-eventdev-c10cdce180a6ac535dc420376f115ca4ac44aead.tar.gz
dpdk-next-eventdev-c10cdce180a6ac535dc420376f115ca4ac44aead.tar.xz
ethdev: support MAC address as iterator filter
The MAC addresses of a port can be matched with devargs. As the conflict between rte_ether.h and netinet/ether.h is not resolved, the MAC parsing is done with a rte_cmdline function. As a result, cmdline library becomes a dependency of ethdev. Signed-off-by: Thomas Monjalon <thomas@monjalon.net> Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
Diffstat (limited to 'lib/librte_ethdev')
-rw-r--r--lib/librte_ethdev/Makefile2
-rw-r--r--lib/librte_ethdev/meson.build2
-rw-r--r--lib/librte_ethdev/rte_class_eth.c36
3 files changed, 38 insertions, 2 deletions
diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile
index e27bcd5..3e27ae4 100644
--- a/lib/librte_ethdev/Makefile
+++ b/lib/librte_ethdev/Makefile
@@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)
LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring
-LDLIBS += -lrte_mbuf -lrte_kvargs
+LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline
EXPORT_MAP := rte_ethdev_version.map
diff --git a/lib/librte_ethdev/meson.build b/lib/librte_ethdev/meson.build
index 6783013..a4d8502 100644
--- a/lib/librte_ethdev/meson.build
+++ b/lib/librte_ethdev/meson.build
@@ -26,4 +26,4 @@ headers = files('rte_ethdev.h',
'rte_tm.h',
'rte_tm_driver.h')
-deps += ['net', 'kvargs']
+deps += ['net', 'kvargs', 'cmdline']
diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c
index fca7fe4..16b47c3 100644
--- a/lib/librte_ethdev/rte_class_eth.c
+++ b/lib/librte_ethdev/rte_class_eth.c
@@ -4,6 +4,7 @@
#include <string.h>
+#include <cmdline_parse_etheraddr.h>
#include <rte_class.h>
#include <rte_compat.h>
#include <rte_errno.h>
@@ -16,11 +17,13 @@
#include "ethdev_private.h"
enum eth_params {
+ RTE_ETH_PARAM_MAC,
RTE_ETH_PARAM_REPRESENTOR,
RTE_ETH_PARAM_MAX,
};
static const char * const eth_params_keys[] = {
+ [RTE_ETH_PARAM_MAC] = "mac",
[RTE_ETH_PARAM_REPRESENTOR] = "representor",
[RTE_ETH_PARAM_MAX] = NULL,
};
@@ -37,6 +40,33 @@ struct eth_dev_match_arg {
})
static int
+eth_mac_cmp(const char *key __rte_unused,
+ const char *value, void *opaque)
+{
+ int ret;
+ struct ether_addr mac;
+ const struct rte_eth_dev_data *data = opaque;
+ struct rte_eth_dev_info dev_info;
+ uint32_t index;
+
+ /* Parse devargs MAC address. */
+ /*
+ * cannot use ether_aton_r(value, &mac)
+ * because of include conflict with rte_ether.h
+ */
+ ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac));
+ if (ret < 0)
+ return -1; /* invalid devargs value */
+
+ /* Return 0 if devargs MAC is matching one of the device MACs. */
+ rte_eth_dev_info_get(data->port_id, &dev_info);
+ for (index = 0; index < dev_info.max_mac_addrs; index++)
+ if (is_same_ether_addr(&mac, &data->mac_addrs[index]))
+ return 0;
+ return -1; /* no match */
+}
+
+static int
eth_representor_cmp(const char *key __rte_unused,
const char *value, void *opaque)
{
@@ -86,6 +116,12 @@ eth_dev_match(const struct rte_eth_dev *edev,
return 0;
ret = rte_kvargs_process(kvlist,
+ eth_params_keys[RTE_ETH_PARAM_MAC],
+ eth_mac_cmp, edev->data);
+ if (ret != 0)
+ return -1;
+
+ ret = rte_kvargs_process(kvlist,
eth_params_keys[RTE_ETH_PARAM_REPRESENTOR],
eth_representor_cmp, edev->data);
if (ret != 0)