Added initial version of odp_pktio_start() to netmap. Removed unnecessary global mmap_desc variable.
Signed-off-by: Matias Elo <matias....@nokia.com> --- platform/linux-generic/include/odp_packet_netmap.h | 2 + platform/linux-generic/pktio/netmap.c | 59 ++++++++++++---------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_packet_netmap.h index 0577dfe..84bea65 100644 --- a/platform/linux-generic/include/odp_packet_netmap.h +++ b/platform/linux-generic/include/odp_packet_netmap.h @@ -10,6 +10,7 @@ #include <odp/pool.h> #include <linux/if_ether.h> +#include <net/if.h> /** Packet socket using netmap mmaped rings for both Rx and Tx */ typedef struct { @@ -20,6 +21,7 @@ typedef struct { uint32_t if_flags; /**< interface flags */ int sockfd; /**< control socket */ unsigned char if_mac[ETH_ALEN]; /**< eth mac address */ + char nm_name[IF_NAMESIZE + 7]; /**< netmap:<ifname> */ } pkt_netmap_t; #endif diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index c4db4b5..fa20c6e 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -24,10 +24,6 @@ #define NETMAP_WITH_LIBS #include <net/netmap_user.h> -static struct nm_desc mmap_desc; /** Used to store the mmap address; - filled in first time, used for - subsequent calls to nm_open */ - #define NM_OPEN_RETRIES 5 #define NM_INJECT_RETRIES 10 @@ -83,10 +79,8 @@ static int netmap_close(pktio_entry_t *pktio_entry) { pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; - if (pkt_nm->rx_desc != NULL) { + if (pkt_nm->rx_desc != NULL) nm_close(pkt_nm->rx_desc); - mmap_desc.mem = NULL; - } if (pkt_nm->tx_desc != NULL) nm_close(pkt_nm->tx_desc); @@ -101,11 +95,10 @@ static int netmap_close(pktio_entry_t *pktio_entry) static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *netdev, odp_pool_t pool) { - char ifname[IFNAMSIZ + 7]; /* netmap:<ifname> */ int err; int sockfd; - int i; pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + struct nm_desc *desc; if (getenv("ODP_PKTIO_DISABLE_NETMAP")) return -1; @@ -125,25 +118,16 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, snprintf(pktio_entry->s.name, sizeof(pktio_entry->s.name), "%s", netdev); - snprintf(ifname, sizeof(ifname), "netmap:%s", netdev); + snprintf(pkt_nm->nm_name, sizeof(pkt_nm->nm_name), "netmap:%s", + netdev); - if (mmap_desc.mem == NULL) - pkt_nm->rx_desc = nm_open(ifname, NULL, NETMAP_NO_TX_POLL, - NULL); - else - pkt_nm->rx_desc = nm_open(ifname, NULL, NETMAP_NO_TX_POLL | - NM_OPEN_NO_MMAP, &mmap_desc); - pkt_nm->tx_desc = nm_open(ifname, NULL, NM_OPEN_NO_MMAP, &mmap_desc); - - if (pkt_nm->rx_desc == NULL || pkt_nm->tx_desc == NULL) { - ODP_ERR("nm_open(%s) failed\n", ifname); + /* Dummy open here to check if netmap module is available */ + desc = nm_open(pkt_nm->nm_name, NULL, 0, NULL); + if (desc == NULL) { + ODP_ERR("nm_open(%s) failed\n", pkt_nm->nm_name); goto error; } - - if (mmap_desc.mem == NULL) { - mmap_desc.mem = pkt_nm->rx_desc->mem; - mmap_desc.memsize = pkt_nm->rx_desc->memsize; - } + nm_close(desc); sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) { @@ -162,6 +146,29 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, if (err) goto error; + return 0; + +error: + netmap_close(pktio_entry); + return -1; +} + +static int netmap_start(pktio_entry_t *pktio_entry) +{ + pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + int err; + unsigned i; + const char *ifname = pkt_nm->nm_name; + + pkt_nm->rx_desc = nm_open(ifname, NULL, NETMAP_NO_TX_POLL, NULL); + pkt_nm->tx_desc = nm_open(ifname, NULL, NM_OPEN_NO_MMAP, + pkt_nm->rx_desc); + + if (pkt_nm->rx_desc == NULL || pkt_nm->tx_desc == NULL) { + ODP_ERR("nm_open(%s) failed\n", ifname); + goto error; + } + /* Wait for the link to come up */ for (i = 0; i < NM_OPEN_RETRIES; i++) { err = netmap_do_ioctl(pktio_entry, SIOCETHTOOL, ETHTOOL_GLINK); @@ -340,7 +347,7 @@ const pktio_if_ops_t netmap_pktio_ops = { .term = NULL, .open = netmap_open, .close = netmap_close, - .start = NULL, + .start = netmap_start, .stop = NULL, .recv = netmap_recv, .send = netmap_send, -- 1.9.1 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp