diff mbox

[API-NEXT,PATCHv4,05/11] linux-generic: pktio: implement odp_pktio_config()

Message ID 1461197655-23743-6-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer April 21, 2016, 12:14 a.m. UTC
From: Matias Elo <matias.elo@nokia.com>

Add default implementations for odp_pktio_config().

Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 .../linux-generic/include/odp_packet_io_internal.h |  3 +++
 platform/linux-generic/odp_packet_io.c             | 27 +++++++++++++++++-----
 platform/linux-generic/pktio/dpdk.c                |  1 +
 platform/linux-generic/pktio/ipc.c                 |  1 +
 platform/linux-generic/pktio/loop.c                |  1 +
 platform/linux-generic/pktio/netmap.c              |  1 +
 platform/linux-generic/pktio/pcap.c                |  1 +
 platform/linux-generic/pktio/socket.c              |  1 +
 platform/linux-generic/pktio/socket_mmap.c         |  1 +
 platform/linux-generic/pktio/tap.c                 |  1 +
 10 files changed, 32 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index ee7fc71..a807d13 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -131,6 +131,7 @@  struct pktio_entry {
 		STATE_STOPPED		/**< Same as OPENED, but only happens
 					after STARTED */
 	} state;
+	odp_pktio_config_t config;	/**< Device configuration */
 	classifier_t cls;		/**< classifier linked with this pktio*/
 	odp_pktio_stats_t stats;	/**< statistic counters for pktio */
 	enum {
@@ -197,6 +198,8 @@  typedef struct pktio_if_ops {
 	int (*link_status)(pktio_entry_t *pktio_entry);
 	int (*capability)(pktio_entry_t *pktio_entry,
 			  odp_pktio_capability_t *capa);
+	int (*config)(pktio_entry_t *pktio_entry,
+		      const odp_pktio_config_t *config);
 	int (*input_queues_config)(pktio_entry_t *pktio_entry,
 				   const odp_pktin_queue_param_t *param);
 	int (*output_queues_config)(pktio_entry_t *pktio_entry,
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index 2650124..c597e83 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -384,7 +384,9 @@  int odp_pktio_close(odp_pktio_t id)
 int odp_pktio_config(odp_pktio_t id, const odp_pktio_config_t *config)
 {
 	pktio_entry_t *entry;
+	odp_pktio_capability_t capa;
 	odp_pktio_config_t default_config;
+	int res = 0;
 
 	entry = get_pktio_entry(id);
 	if (!entry)
@@ -395,21 +397,34 @@  int odp_pktio_config(odp_pktio_t id, const odp_pktio_config_t *config)
 		config = &default_config;
 	}
 
-	/* Currently nothing is supported. Capability returns 0 for both bit
-	 * fields. */
-	if (config->pktin.all_bits != 0 ||
-	    config->pktout.all_bits != 0)
+	if (odp_pktio_capability(id, &capa))
+		return -1;
+
+	/* Check config for invalid values */
+	if (config->pktin.all_bits & ~capa.config.pktin.all_bits) {
+		ODP_ERR("Unsupported input configuration option\n");
 		return -1;
+	}
+	if (config->pktout.all_bits & ~capa.config.pktout.all_bits) {
+		ODP_ERR("Unsupported output configuration option\n");
+		return -1;
+	}
 
 	lock_entry(entry);
-	if (entry->s.state != STATE_STARTED) {
+	if (entry->s.state == STATE_STARTED) {
 		unlock_entry(entry);
+		ODP_DBG("pktio %s: not stopped\n", entry->s.name);
 		return -1;
 	}
 
+	entry->s.config = *config;
+
+	if (entry->s.ops->config)
+		res = entry->s.ops->config(entry, config);
+
 	unlock_entry(entry);
 
-	return 0;
+	return res;
 }
 
 int odp_pktio_start(odp_pktio_t id)
diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index ea7b925..83fb1ba 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -929,6 +929,7 @@  const pktio_if_ops_t dpdk_pktio_ops = {
 	.capability = dpdk_capability,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
+	.config = NULL,
 	.input_queues_config = dpdk_input_queues_config,
 	.output_queues_config = dpdk_output_queues_config
 };
diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c
index cd7e32f..18dbe15 100644
--- a/platform/linux-generic/pktio/ipc.c
+++ b/platform/linux-generic/pktio/ipc.c
@@ -728,4 +728,5 @@  const pktio_if_ops_t ipc_pktio_ops = {
 	.mac_get = ipc_mac_addr_get,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
+	.config = NULL
 };
diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c
index 396b769..2fc1381 100644
--- a/platform/linux-generic/pktio/loop.c
+++ b/platform/linux-generic/pktio/loop.c
@@ -186,6 +186,7 @@  const pktio_if_ops_t loopback_pktio_ops = {
 	.capability = NULL,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
+	.config = NULL,
 	.input_queues_config = NULL,
 	.output_queues_config = NULL,
 	.recv_queue = NULL,
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index c2a6b34..0b794a0 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -863,6 +863,7 @@  const pktio_if_ops_t netmap_pktio_ops = {
 	.capability = netmap_capability,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
+	.config = NULL,
 	.input_queues_config = netmap_input_queues_config,
 	.output_queues_config = netmap_output_queues_config,
 	.recv_queue = netmap_recv_queue,
diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c
index c8769f5..a47d2cc 100644
--- a/platform/linux-generic/pktio/pcap.c
+++ b/platform/linux-generic/pktio/pcap.c
@@ -409,6 +409,7 @@  const pktio_if_ops_t pcap_pktio_ops = {
 	.capability = NULL,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
+	.config = NULL,
 	.input_queues_config = NULL,
 	.output_queues_config = NULL,
 	.recv_queue = NULL,
diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c
index c5cbc2d..44f18c2 100644
--- a/platform/linux-generic/pktio/socket.c
+++ b/platform/linux-generic/pktio/socket.c
@@ -858,6 +858,7 @@  const pktio_if_ops_t sock_mmsg_pktio_ops = {
 	.capability = NULL,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
+	.config = NULL,
 	.input_queues_config = NULL,
 	.output_queues_config = NULL,
 	.recv_queue = NULL,
diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c
index 6d211ec..da0f7b7 100644
--- a/platform/linux-generic/pktio/socket_mmap.c
+++ b/platform/linux-generic/pktio/socket_mmap.c
@@ -627,6 +627,7 @@  const pktio_if_ops_t sock_mmap_pktio_ops = {
 	.capability = NULL,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
+	.config = NULL,
 	.input_queues_config = NULL,
 	.output_queues_config = NULL,
 	.recv_queue = NULL,
diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c
index abc49fa..e02d311 100644
--- a/platform/linux-generic/pktio/tap.c
+++ b/platform/linux-generic/pktio/tap.c
@@ -326,4 +326,5 @@  const pktio_if_ops_t tap_pktio_ops = {
 	.mac_get = tap_mac_addr_get,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
+	.config = NULL
 };