On 10/22/2015 14:40, Matias Elo wrote:
Netmap interface takes a few seconds to become active after
setup. This caused several test applications to fail.
Check link status at the end of netmap_open() to fix this.

Signed-off-by: Matias Elo <matias....@nokia.com>
---

v2:
   - Rebased to master
   - The other end of a directly attached loopback cable may come up after a
     small delay. Sleep once after link is detected to enable running validation
     tests with directly attached loopback cable. (Stuart Haslam)

  platform/linux-generic/pktio/netmap.c | 20 +++++++++++++++++---
  1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/platform/linux-generic/pktio/netmap.c 
b/platform/linux-generic/pktio/netmap.c
index ab4667e..0dfe511 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -28,6 +28,7 @@ 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
struct dispatch_args {
@@ -70,6 +71,10 @@ static int netmap_do_ioctl(pktio_entry_t *pktio_entry, 
unsigned long cmd,
                pkt_nm->if_flags = (ifr.ifr_flags << 16) |
                        (0xffff & ifr.ifr_flags);
                break;
+       case SIOCETHTOOL:
+               if (subcmd == ETHTOOL_GLINK)
+                       return !eval.data;
+               break;
        default:
                break;
        }
@@ -84,9 +89,10 @@ static int netmap_close(pktio_entry_t *pktio_entry)
  {
        pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
- if (pkt_nm->desc != NULL)
+       if (pkt_nm->desc != NULL) {
                nm_close(pkt_nm->desc);
-
+               mmap_desc.mem = NULL;
+       }
        if (pkt_nm->sockfd != -1 && close(pkt_nm->sockfd) != 0) {
                __odp_errno = errno;
                ODP_ERR("close(sockfd): %s\n", strerror(errno));
@@ -101,6 +107,7 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, 
pktio_entry_t *pktio_entry,
        char ifname[IFNAMSIZ + 7]; /* netmap:<ifname> */
        int err;
        int sockfd;
+       int i;
        pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
if (getenv("ODP_PKTIO_DISABLE_NETMAP"))
@@ -155,7 +162,14 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, 
pktio_entry_t *pktio_entry,
        if (err)
                goto error;
- return 0;
+       /* Wait for the link to come up */
+       for (i = 0; i < NM_OPEN_RETRIES; i++) {
+               err = netmap_do_ioctl(pktio_entry, SIOCETHTOOL, ETHTOOL_GLINK);
+               sleep(1);
+               if (err == 0)
+                       return 0;

why sleep() is between err check with return?

Maxim.
+       }
+       ODP_ERR("%s didn't come up\n", pktio_entry->s.name);
error:
        netmap_close(pktio_entry);

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

Reply via email to