From patchwork Fri Jan 22 18:48:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 60179 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp27764lbb; Fri, 22 Jan 2016 10:50:59 -0800 (PST) X-Received: by 10.107.130.90 with SMTP id e87mr5841636iod.77.1453488658977; Fri, 22 Jan 2016 10:50:58 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id rs9si6734494igb.104.2016.01.22.10.50.58; Fri, 22 Jan 2016 10:50:58 -0800 (PST) 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 Received: by lists.linaro.org (Postfix, from userid 109) id DD6BE61902; Fri, 22 Jan 2016 18:50:57 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=JouPk5Ia; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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 D21D261959; Fri, 22 Jan 2016 18:48:43 +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 9F3A06193B; Fri, 22 Jan 2016 18:48:27 +0000 (UTC) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by lists.linaro.org (Postfix) with ESMTPS id A09B2617EA for ; Fri, 22 Jan 2016 18:48:22 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id 123so25520553wmz.0 for ; Fri, 22 Jan 2016 10:48:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=9TqJ9xp9TcnrC1x88kwn6OGRcV32sujRV98Np4f36+w=; b=JouPk5Ian3de8VxwqRxwW3IG99CPW7VL1hhS6HeUTL4aqWtWPpWHJ3333p7UWql61L /40b79lzIUUFYn77ltANdMI3bRIb0VKxijhBj/5Yd/erD3HQmEoUncgleuKlswgII2+Z hF1PYIVFTNBRysoqpG+25SjXj1eDRbgkN1MtA= 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=9TqJ9xp9TcnrC1x88kwn6OGRcV32sujRV98Np4f36+w=; b=hENrrAM4rrHYb8GY4gUnM0kXHN+jelZMEKjFKkZ7/qpISiru8eNQnHCdG6PkGFJTXO KJ2t9whxriW16+A4ewutMVNSmWsyk5hD6gmE4IhjyMeUa3VvYOM9EK453soHQNAjrd3s MqLV0KQZ7aRnS2M/ktFHcC1Jq9R7U1wgzAVp1gM55EUZna/X/+FxHi91V38UvjLCmgxU VxKEkGAEGYtdIU6ptUltcpItBLtypgDqhv6nYCMtGtkym7X6LewLjBVCI+3cXtBAlsBB VB6wH+xJF+bARWCZiyUp8aPDAbGw2089biF8H9elOKHWTPHRS0o+ZqRO7vsMmnGaBVig MZeg== X-Gm-Message-State: AG10YOQcQuCYxM0vCnlcrAErA1EYijcJY/xzOo9hYnoIEcZ2x26jekXJPRlNPi7NPU2IxXDQbKc= X-Received: by 10.28.156.213 with SMTP id f204mr4957362wme.57.1453488501846; Fri, 22 Jan 2016 10:48:21 -0800 (PST) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::1]) by smtp.gmail.com with ESMTPSA id p9sm7085262wjy.41.2016.01.22.10.48.21 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jan 2016 10:48:21 -0800 (PST) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Fri, 22 Jan 2016 18:48:03 +0000 Message-Id: <1453488486-12176-3-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1453488486-12176-1-git-send-email-stuart.haslam@linaro.org> References: <1453488486-12176-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 2/5] 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 774e813..f15ffff 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -42,8 +42,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: @@ -102,7 +101,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; @@ -124,20 +124,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; }