From patchwork Wed Oct 28 19:29:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 55713 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp137203lbr; Wed, 28 Oct 2015 12:31:34 -0700 (PDT) X-Received: by 10.50.97.37 with SMTP id dx5mr5404891igb.14.1446060694011; Wed, 28 Oct 2015 12:31:34 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id m1si22955992igd.83.2015.10.28.12.31.33; Wed, 28 Oct 2015 12:31:33 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 469A262012; Wed, 28 Oct 2015 19:31:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id DA49361FF1; Wed, 28 Oct 2015 19:29:34 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 34C4661FE4; Wed, 28 Oct 2015 19:29:28 +0000 (UTC) Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by lists.linaro.org (Postfix) with ESMTPS id 4AF1E61A06 for ; Wed, 28 Oct 2015 19:29:25 +0000 (UTC) Received: by wicll6 with SMTP id ll6so210160762wic.0 for ; Wed, 28 Oct 2015 12:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=CFagfMVzVOp9etbADKv2Yobii0noTppmUUfNmGDUEBQ=; b=Szh050M3EIEFRQnRjFOShXFLIFgKRtazQ4p+n+YQramXJGqqwP3hYORrxzO/XY6j+r G0NHlJntZWGKVcIgJBeOyurBTUqRvRAu/MnW+/VQzp3rnbXLUT+kc3GMYHfxYxkbLT8y peU7Xbl9AUTknddYt9+BG9a0D20A99aXbqWmeOhD/J28JVwBUcGgeJ3+7biC7wBYVJ6s Nvlel9sntyHoVe7TBBKP0QPt+T8IkhD3AtEKrEaS9S5Ba9kMV/TJW+yNBR/hHoopA+9k OxIG8xCU4JRTgn2IzUml4Y8b9W24BDKJ5sI2wtTdkjQ6rqRuAUi6/Cs3J+qgKyO5qbZM N3Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=CFagfMVzVOp9etbADKv2Yobii0noTppmUUfNmGDUEBQ=; b=YtBn9LhruUysxqXDisPAg0o2SB/T/3gBbCyXlMpg7EmMhg+zoSx12+eFmbd7u+ErUq /url3+U2yZqO5HjblzWz43MGjatF4sMbJiZYGfPGVQa8B2doKi01qTsgAY+/cubKUC7o fmqUHGQ+9YKoP3+fl3o8OS9v1XiY0HDwWxv6Y0XkNkxBhLfDm2lAoF9VhbxWdBvCLHwA c6azpxbNaYrBT9Kgh4TXzG0ngR2eGfzG/w/Pscnc+fjrXGvZujYr28XPrxLFArR9P51F gGqJTRy2FY9V8Zd8EmkLLIEvXF5QKSKxT7YYvbodNwIs4DhD5VI0t/AlLwPvtS+vA3qe MW2g== X-Gm-Message-State: ALoCoQn/LC6flNi3XMk2j5cMXLTB3lF7VC6tAV3ucA8GZAZsNdz4ab07PAQnesHqTe30dSujB8pW X-Received: by 10.180.10.233 with SMTP id l9mr4462300wib.7.1446060564560; Wed, 28 Oct 2015 12:29:24 -0700 (PDT) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id h4sm31286154wjx.41.2015.10.28.12.29.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Oct 2015 12:29:24 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Wed, 28 Oct 2015 19:29:05 +0000 Message-Id: <1446060551-21029-4-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1446060551-21029-1-git-send-email-stuart.haslam@linaro.org> References: <1446060551-21029-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 3/9] linux-generic: pktio: support using netmap: prefix X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" The netmap API requires interface names to be prefixed with "netmap:", the pktio code will do that automatically, e.g. odp_pktio_open("eth0") becomes nm_open("netmap:eth0"). But it will append the netmap: even if the original name already has that prefix, so odp_pktio_open("netmap:eth0") fails. It's useful to be able to explicitly use the netmap interface, especially when testing, if you don't want fallback to other pktio types. Signed-off-by: Stuart Haslam --- platform/linux-generic/include/odp_packet_netmap.h | 2 ++ platform/linux-generic/pktio/netmap.c | 26 +++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_packet_netmap.h index 0577dfe..7caa92f 100644 --- a/platform/linux-generic/include/odp_packet_netmap.h +++ b/platform/linux-generic/include/odp_packet_netmap.h @@ -10,6 +10,7 @@ #include #include +#include /** 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 ifname[IF_NAMESIZE]; /**< interface name to be used in ioctl */ } pkt_netmap_t; #endif diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index 67ff95e..5378586 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -47,8 +47,7 @@ static int netmap_do_ioctl(pktio_entry_t *pktio_entry, unsigned long cmd, int fd = pkt_nm->sockfd; memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", - pktio_entry->s.name); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", pkt_nm->ifname); switch (cmd) { case SIOCSIFFLAGS: @@ -107,7 +106,8 @@ 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: */ + char nmname[IF_NAMESIZE + 7]; /* netmap: */ + const char *prefix; int err; int sockfd; int i; @@ -129,20 +129,30 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, odp_buffer_pool_headroom(pool) - odp_buffer_pool_tailroom(pool); + /* allow interface to be opened with or without the netmap: prefix */ snprintf(pktio_entry->s.name, sizeof(pktio_entry->s.name), "%s", netdev); - snprintf(ifname, sizeof(ifname), "netmap:%s", netdev); + + if (strncmp(netdev, "netmap:", 7) == 0) { + netdev += 7; + prefix = ""; + } else { + prefix = "netmap:"; + } + + snprintf(pkt_nm->ifname, sizeof(pkt_nm->ifname), "%s", netdev); + snprintf(nmname, sizeof(nmname), "%s%s", prefix, pktio_entry->s.name); if (mmap_desc.mem == NULL) - pkt_nm->rx_desc = nm_open(ifname, NULL, NETMAP_NO_TX_POLL, + pkt_nm->rx_desc = nm_open(nmname, NULL, NETMAP_NO_TX_POLL, NULL); else - pkt_nm->rx_desc = nm_open(ifname, NULL, NETMAP_NO_TX_POLL | + pkt_nm->rx_desc = nm_open(nmname, 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); + pkt_nm->tx_desc = nm_open(nmname, 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); + ODP_ERR("nm_open(%s) failed\n", nmname); goto error; }