Add dpdk_mtu_get(), dpdk_promisc_mode_set(),
dpdk_promisc_mode_get(), and dpdk_capability() functions.

Reviewed-by: Petri Savolainen <petri.savolai...@nokia.com>
Signed-off-by: Matias Elo <matias....@nokia.com>
---
 platform/linux-generic/include/odp_packet_dpdk.h |  1 +
 platform/linux-generic/pktio/dpdk.c              | 56 +++++++++++++++++++++---
 2 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/platform/linux-generic/include/odp_packet_dpdk.h 
b/platform/linux-generic/include/odp_packet_dpdk.h
index 5676f4c..6ebcb3e 100644
--- a/platform/linux-generic/include/odp_packet_dpdk.h
+++ b/platform/linux-generic/include/odp_packet_dpdk.h
@@ -35,6 +35,7 @@ typedef struct {
        struct rte_mempool *pkt_pool;     /**< DPDK packet pool */
        odp_pktio_capability_t  capa;     /**< interface capabilities */
        uint32_t data_room;               /**< maximum packet length */
+       uint16_t mtu;                     /**< maximum transmission unit */
        /** DPDK packet pool name (pktpool_<ifname>) */
        char pool_name[IF_NAMESIZE + 8];
        uint8_t port_id;                  /**< DPDK port identifier */
diff --git a/platform/linux-generic/pktio/dpdk.c 
b/platform/linux-generic/pktio/dpdk.c
index d7f0d24..ccb659a 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -273,9 +273,11 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
                     odp_pool_t pool)
 {
        pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       struct rte_eth_dev_info dev_info;
        struct rte_mempool *pkt_pool;
        odp_pool_info_t pool_info;
        uint16_t data_room;
+       uint16_t mtu;
 
        if (getenv("ODP_PKTIO_DISABLE_DPDK"))
                return -1;
@@ -314,6 +316,17 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
                return -1;
        }
 
+       memset(&dev_info, 0, sizeof(struct rte_eth_dev_info));
+       rte_eth_dev_info_get(pkt_dpdk->port_id, &dev_info);
+       pkt_dpdk->capa.max_input_queues = dev_info.max_rx_queues;
+       pkt_dpdk->capa.max_output_queues = dev_info.max_tx_queues;
+
+       if (rte_eth_dev_get_mtu(pktio_entry->s.pkt_dpdk.port_id, &mtu) != 0) {
+               ODP_ERR("Failed to read interface MTU\n");
+               return -1;
+       }
+       pkt_dpdk->mtu = mtu;
+
        /* Look for previously opened packet pool */
        pkt_pool = rte_mempool_lookup(pkt_dpdk->pool_name);
        if (pkt_pool == NULL)
@@ -483,6 +496,14 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry,
        uint16_t pkt_len;
 
        for (i = 0; i < num; i++) {
+               pkt_len = odp_packet_len(pkt_table[i]);
+
+               if (pkt_len > pkt_dpdk->mtu) {
+                       if (i == 0)
+                               __odp_errno = EMSGSIZE;
+                       break;
+               }
+
                mbuf_table[i] = rte_pktmbuf_alloc(pkt_dpdk->pkt_pool);
                if (mbuf_table[i] == NULL) {
                        ODP_ERR("Failed to alloc mbuf\n");
@@ -490,7 +511,6 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry,
                }
 
                rte_pktmbuf_reset(mbuf_table[i]);
-               pkt_len = odp_packet_len(pkt_table[i]);
 
                data = rte_pktmbuf_append(mbuf_table[i], pkt_len);
 
@@ -573,6 +593,32 @@ static int dpdk_mac_addr_get(pktio_entry_t *pktio_entry, 
void *mac_addr)
        return ETH_ALEN;
 }
 
+static int dpdk_mtu_get(pktio_entry_t *pktio_entry)
+{
+       return pktio_entry->s.pkt_dpdk.mtu;
+}
+
+static int dpdk_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable)
+{
+       if (enable)
+               rte_eth_promiscuous_enable(pktio_entry->s.pkt_dpdk.port_id);
+       else
+               rte_eth_promiscuous_disable(pktio_entry->s.pkt_dpdk.port_id);
+       return 0;
+}
+
+static int dpdk_promisc_mode_get(pktio_entry_t *pktio_entry)
+{
+       return rte_eth_promiscuous_get(pktio_entry->s.pkt_dpdk.port_id);
+}
+
+static int dpdk_capability(pktio_entry_t *pktio_entry,
+                          odp_pktio_capability_t *capa)
+{
+       *capa = pktio_entry->s.pkt_dpdk.capa;
+       return 0;
+}
+
 const pktio_if_ops_t dpdk_pktio_ops = {
        .name = "dpdk",
        .init = NULL,
@@ -586,11 +632,11 @@ const pktio_if_ops_t dpdk_pktio_ops = {
        .recv_queue = dpdk_recv_queue,
        .send_queue = dpdk_send_queue,
        .link_status = NULL,
-       .mtu_get = NULL,
-       .promisc_mode_set = NULL,
-       .promisc_mode_get = NULL,
+       .mtu_get = dpdk_mtu_get,
+       .promisc_mode_set = dpdk_promisc_mode_set,
+       .promisc_mode_get = dpdk_promisc_mode_get,
        .mac_get = dpdk_mac_addr_get,
-       .capability = NULL,
+       .capability = dpdk_capability,
        .input_queues_config = NULL,
        .output_queues_config = NULL,
        .in_queues = NULL,
-- 
1.9.1

_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to