Added info structure so that application can request pktio
device name and various configuration parameters.

Harmonized usage of pktio parameter 'name' instead of 'dev'.

Signed-off-by: Petri Savolainen <[email protected]>
---
 include/odp/api/spec/packet_io.h                   | 35 +++++++++++++++--
 .../linux-generic/include/odp_packet_io_internal.h |  3 +-
 platform/linux-generic/odp_packet_io.c             | 45 +++++++++++++++-------
 platform/linux-generic/pktio/pktio_common.c        |  2 +-
 4 files changed, 66 insertions(+), 19 deletions(-)

diff --git a/include/odp/api/spec/packet_io.h b/include/odp/api/spec/packet_io.h
index b63bd3f..699b3c8 100644
--- a/include/odp/api/spec/packet_io.h
+++ b/include/odp/api/spec/packet_io.h
@@ -227,7 +227,7 @@ typedef struct odp_pktio_capability_t {
  * specified otherwise, any interface level configuration must not be changed
  * when the interface is active (between start and stop calls).
  *
- * @param dev    Packet IO device name
+ * @param name   Packet IO device name
  * @param pool   Default pool from which to allocate storage for packets
  *               received over this interface, must be of type ODP_POOL_PACKET
  * @param param  Packet IO parameters
@@ -248,7 +248,7 @@ typedef struct odp_pktio_capability_t {
  *
  * @see odp_pktio_start(), odp_pktio_stop(), odp_pktio_close()
  */
-odp_pktio_t odp_pktio_open(const char *dev, odp_pool_t pool,
+odp_pktio_t odp_pktio_open(const char *name, odp_pool_t pool,
                           const odp_pktio_param_t *param);
 
 /**
@@ -422,12 +422,12 @@ int odp_pktio_close(odp_pktio_t pktio);
 /**
  * Return a packet IO handle for an already open device
  *
- * @param dev Packet IO device name
+ * @param name   Packet IO device name
  *
  * @return Packet IO handle
  * @retval ODP_PKTIO_INVALID on failure
  */
-odp_pktio_t odp_pktio_lookup(const char *dev);
+odp_pktio_t odp_pktio_lookup(const char *name);
 
 /**
  * Receive packets directly from an interface
@@ -706,6 +706,33 @@ void odp_pktio_print(odp_pktio_t pktio);
 int odp_pktio_link_status(odp_pktio_t pktio);
 
 /**
+ * Packet IO information
+ */
+typedef struct odp_pktio_info_t {
+       const char       *name;  /**< Packet IO device name */
+       odp_pool_t        pool;  /**< Packet pool */
+       odp_pktio_param_t param; /**< Packet IO parameters */
+} odp_pktio_info_t;
+
+/**
+ * Retrieve information about a pktio
+ *
+ * Fills in packet IO information structure with current parameter values.
+ * May be called any time with a valid pktio handle. The call is not
+ * synchronized with configuration changing calls. The application should
+ * ensure that it does not simultaneously change the configuration and retrieve
+ * it with this call. The call is not intended for fast path use. The info
+ * structure is written only on success.
+ *
+ * @param      pktio   Packet IO handle
+ * @param[out] info    Pointer to packet IO info struct for output
+ *
+ * @retval  0 on success
+ * @retval <0 on failure
+ */
+int odp_pktio_info(odp_pktio_t pktio, odp_pktio_info_t *info);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h 
b/platform/linux-generic/include/odp_packet_io_internal.h
index 03128f1..d3d33ee 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -137,7 +137,8 @@ struct pktio_entry {
        } stats_type;
        char name[PKTIO_NAME_LEN];      /**< name of pktio provided to
                                           pktio_open() */
-       odp_pktio_t id;
+
+       odp_pool_t pool;
        odp_pktio_param_t param;
 
        /* Storage for queue handles
diff --git a/platform/linux-generic/odp_packet_io.c 
b/platform/linux-generic/odp_packet_io.c
index a8c1d87..aa1fb8d 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -172,7 +172,7 @@ static int free_pktio_entry(odp_pktio_t id)
        return 0;
 }
 
-static odp_pktio_t setup_pktio_entry(const char *dev, odp_pool_t pool,
+static odp_pktio_t setup_pktio_entry(const char *name, odp_pool_t pool,
                                     const odp_pktio_param_t *param)
 {
        odp_pktio_t id;
@@ -180,10 +180,10 @@ static odp_pktio_t setup_pktio_entry(const char *dev, 
odp_pool_t pool,
        int ret = -1;
        int pktio_if;
 
-       if (strlen(dev) >= PKTIO_NAME_LEN - 1) {
+       if (strlen(name) >= PKTIO_NAME_LEN - 1) {
                /* ioctl names limitation */
                ODP_ERR("pktio name %s is too big, limit is %d bytes\n",
-                       dev, PKTIO_NAME_LEN - 1);
+                       name, PKTIO_NAME_LEN - 1);
                return ODP_PKTIO_INVALID;
        }
 
@@ -198,16 +198,17 @@ static odp_pktio_t setup_pktio_entry(const char *dev, 
odp_pool_t pool,
        if (!pktio_entry)
                return ODP_PKTIO_INVALID;
 
+       pktio_entry->s.pool = pool;
        memcpy(&pktio_entry->s.param, param, sizeof(odp_pktio_param_t));
-       pktio_entry->s.id = id;
+       pktio_entry->s.handle = id;
 
        for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) {
-               ret = pktio_if_ops[pktio_if]->open(id, pktio_entry, dev, pool);
+               ret = pktio_if_ops[pktio_if]->open(id, pktio_entry, name, pool);
 
                if (!ret) {
                        pktio_entry->s.ops = pktio_if_ops[pktio_if];
                        ODP_DBG("%s uses %s\n",
-                               dev, pktio_if_ops[pktio_if]->name);
+                               name, pktio_if_ops[pktio_if]->name);
                        break;
                }
        }
@@ -218,11 +219,10 @@ static odp_pktio_t setup_pktio_entry(const char *dev, 
odp_pool_t pool,
                ODP_ERR("Unable to init any I/O type.\n");
        } else {
                snprintf(pktio_entry->s.name,
-                        sizeof(pktio_entry->s.name), "%s", dev);
+                        sizeof(pktio_entry->s.name), "%s", name);
                pktio_entry->s.state = STATE_STOP;
        }
 
-       pktio_entry->s.handle = id;
        unlock_entry(pktio_entry);
 
        return id;
@@ -241,14 +241,14 @@ static int pool_type_is_packet(odp_pool_t pool)
        return pool_info.params.type == ODP_POOL_PACKET;
 }
 
-odp_pktio_t odp_pktio_open(const char *dev, odp_pool_t pool,
+odp_pktio_t odp_pktio_open(const char *name, odp_pool_t pool,
                           const odp_pktio_param_t *param)
 {
        odp_pktio_t id;
 
        ODP_ASSERT(pool_type_is_packet(pool));
 
-       id = odp_pktio_lookup(dev);
+       id = odp_pktio_lookup(name);
        if (id != ODP_PKTIO_INVALID) {
                /* interface is already open */
                __odp_errno = EEXIST;
@@ -256,7 +256,7 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_pool_t pool,
        }
 
        odp_spinlock_lock(&pktio_tbl->lock);
-       id = setup_pktio_entry(dev, pool, param);
+       id = setup_pktio_entry(name, pool, param);
        odp_spinlock_unlock(&pktio_tbl->lock);
 
        return id;
@@ -382,7 +382,7 @@ int odp_pktio_stop(odp_pktio_t id)
        return res;
 }
 
-odp_pktio_t odp_pktio_lookup(const char *dev)
+odp_pktio_t odp_pktio_lookup(const char *name)
 {
        odp_pktio_t id = ODP_PKTIO_INVALID;
        pktio_entry_t *entry;
@@ -398,7 +398,7 @@ odp_pktio_t odp_pktio_lookup(const char *dev)
                lock_entry(entry);
 
                if (!is_free(entry) &&
-                   strncmp(entry->s.name, dev, sizeof(entry->s.name)) == 0)
+                   strncmp(entry->s.name, name, sizeof(entry->s.name)) == 0)
                        id = _odp_cast_scalar(odp_pktio_t, i);
 
                unlock_entry(entry);
@@ -876,6 +876,25 @@ void odp_pktout_queue_param_init(odp_pktout_queue_param_t 
*param)
        param->op_mode = ODP_PKTIO_OP_MT;
 }
 
+int odp_pktio_info(odp_pktio_t id, odp_pktio_info_t *info)
+{
+       pktio_entry_t *entry;
+
+       entry = get_pktio_entry(id);
+
+       if (entry == NULL) {
+               ODP_DBG("pktio entry %d does not exist\n", id);
+               return -1;
+       }
+
+       memset(info, 0, sizeof(odp_pktio_info_t));
+       info->name = entry->s.name;
+       info->pool = entry->s.pool;
+       memcpy(&info->param, &entry->s.param, sizeof(odp_pktio_param_t));
+
+       return 0;
+}
+
 void odp_pktio_print(odp_pktio_t id)
 {
        pktio_entry_t *entry;
diff --git a/platform/linux-generic/pktio/pktio_common.c 
b/platform/linux-generic/pktio/pktio_common.c
index 1adc5f2..c568da3 100644
--- a/platform/linux-generic/pktio/pktio_common.c
+++ b/platform/linux-generic/pktio/pktio_common.c
@@ -34,7 +34,7 @@ int _odp_packet_cls_enq(pktio_entry_t *pktio_entry,
                return 0;
 
        copy_packet_parser_metadata(&pkt_hdr, odp_packet_hdr(pkt));
-       odp_packet_hdr(pkt)->input = pktio_entry->s.id;
+       odp_packet_hdr(pkt)->input = pktio_entry->s.handle;
 
        if (odp_packet_copydata_in(pkt, 0, buf_len, base) != 0) {
                odp_packet_free(pkt);
-- 
2.7.1

_______________________________________________
lng-odp mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to