From patchwork Mon Oct 13 15:27:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 38678 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0DA9420973 for ; Mon, 13 Oct 2014 15:34:38 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id ge10sf4366774lab.1 for ; Mon, 13 Oct 2014 08:34:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=9fXuNm3qrv7E9PU7+3N+QETYCoac05SMVC9QBCrzXWo=; b=QtRaJcLO8cKcZLzFbureVj7z5UL3yCbA7u6ngyWORCSfbwY7Ez0wexDW2UparKRQ7A YIjGzOEljMOjoPGkLhjZkInBFH4jo1pCkq647Wh5EWQrqkdH2JkfQs6BQ/oQGNO+T3vr QKlh6fEzPuGxh2398tAoJLGWe44BPtb/p0tv3jTAFm+6AjrBaynqypIm74gTQ/1yVj9T eYVO/EdnF/SXik40NtsdOWKBAQY9aYueL4aa8YGhUT3De6Lc2gX225IBy8CpMVKXH3tz QPx1LsIGYpKUVk+B3wQIcqrtFdfm8XoP+Qpp4n4+AnRPpW60Y8GMbs2v7bIJ1E+LLQ9b uAfA== X-Gm-Message-State: ALoCoQl1kYyCZI2toeP7f7LA8b4YDhSklPvf65zNN0oZEVoGYwpW1bAkLutaQFBocO81WbtWmAgh X-Received: by 10.112.198.226 with SMTP id jf2mr4141168lbc.1.1413214477779; Mon, 13 Oct 2014 08:34:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.5.43 with SMTP id cj11ls21990lad.85.gmail; Mon, 13 Oct 2014 08:34:37 -0700 (PDT) X-Received: by 10.112.161.234 with SMTP id xv10mr3773597lbb.96.1413214477624; Mon, 13 Oct 2014 08:34:37 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com [209.85.215.44]) by mx.google.com with ESMTPS id j2si22674983lbv.86.2014.10.13.08.34.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 08:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id hs14so6917634lab.17 for ; Mon, 13 Oct 2014 08:34:37 -0700 (PDT) X-Received: by 10.112.52.165 with SMTP id u5mr4346560lbo.80.1413214477505; Mon, 13 Oct 2014 08:34:37 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp235989lbz; Mon, 13 Oct 2014 08:34:36 -0700 (PDT) X-Received: by 10.140.95.84 with SMTP id h78mr9855849qge.72.1413214475958; Mon, 13 Oct 2014 08:34:35 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id w38si25434510qgw.25.2014.10.13.08.34.35 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 13 Oct 2014 08:34:35 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xdhdq-0002iu-0Q; Mon, 13 Oct 2014 15:34:34 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xdhdj-0002ga-KK for lng-odp@lists.linaro.org; Mon, 13 Oct 2014 15:34:27 +0000 Received: by mail-la0-f42.google.com with SMTP id mk6so6952711lab.29 for ; Mon, 13 Oct 2014 08:34:21 -0700 (PDT) X-Received: by 10.152.7.100 with SMTP id i4mr10950562laa.55.1413214053250; Mon, 13 Oct 2014 08:27:33 -0700 (PDT) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id uc6sm2684671lac.27.2014.10.13.08.27.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 08:27:32 -0700 (PDT) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Mon, 13 Oct 2014 18:27:23 +0300 Message-Id: <1413214043-4864-3-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1413214043-4864-1-git-send-email-ciprian.barbu@linaro.org> References: <1413214043-4864-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH NETMAP 2/2] linux-generic: Remove netmap related code X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Ciprian Barbu --- configure.ac | 21 - platform/linux-generic/Makefile.am | 5 - .../linux-generic/include/api/odp_pktio_netmap.h | 39 -- .../linux-generic/include/api/odp_pktio_types.h | 12 - .../linux-generic/include/odp_packet_io_internal.h | 6 - platform/linux-generic/include/odp_packet_netmap.h | 67 --- platform/linux-generic/odp_packet_io.c | 44 -- platform/linux-generic/odp_packet_netmap.c | 453 --------------------- 8 files changed, 647 deletions(-) delete mode 100644 platform/linux-generic/include/api/odp_pktio_netmap.h delete mode 100644 platform/linux-generic/include/odp_packet_netmap.h delete mode 100644 platform/linux-generic/odp_packet_netmap.c diff --git a/configure.ac b/configure.ac index 220f89a..4401bde 100644 --- a/configure.ac +++ b/configure.ac @@ -63,27 +63,6 @@ AC_SUBST(SDK_INSTALL_PATH) AM_CONDITIONAL([SDK_INSTALL_PATH_], [test "x${SDK_INSTALL_PATH_}" = "x1"]) ########################################################################## -# Enable/disable netmap support -########################################################################## -AC_ARG_ENABLE([netmap], - [ --enable-netmap Enable/disable netmap], - [if test x$enableval = xyes; then - netmap_support=yes - ODP_CFLAGS="$ODP_CFLAGS -DODP_HAVE_NETMAP=1" - fi]) - -AC_ARG_WITH([netmap-path], -AC_HELP_STRING([--with-netmap-path=DIR Path to netmap libs and headers], - [(or in the default path if not specified).]), -[NETMAP_PATH=$withval netmap_support=yes -AM_CFLAGS="$AM_CFLAGS -I$NETMAP_PATH/sys" -ODP_CFLAGS="$ODP_CFLAGS -DODP_HAVE_NETMAP=1" -],[ AC_MSG_WARN([Netmap not found - continuing without netmap support]) -]) - -AM_CONDITIONAL([ODP_NETMAP_ENABLED], [test x$netmap_support = xyes ]) - -########################################################################## # Enable/disable ODP_DEBUG_PRINT ########################################################################## ODP_DEBUG=1 diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 25c82ea..bf6cd10 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -37,7 +37,6 @@ include_HEADERS = \ $(top_srcdir)/platform/linux-generic/include/api/odp_timer.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_version.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_pktio_types.h \ - $(top_srcdir)/platform/linux-generic/include/api/odp_pktio_netmap.h \ $(top_srcdir)/platform/linux-generic/include/api/odp_pktio_socket.h subdirheadersdir = $(includedir)/helper @@ -74,7 +73,3 @@ __LIB__libodp_la_SOURCES = \ odp_time.c \ odp_timer.c -if ODP_NETMAP_ENABLED -__LIB__libodp_la_SOURCES += \ - odp_packet_netmap.c -endif diff --git a/platform/linux-generic/include/api/odp_pktio_netmap.h b/platform/linux-generic/include/api/odp_pktio_netmap.h deleted file mode 100644 index 294a13d..0000000 --- a/platform/linux-generic/include/api/odp_pktio_netmap.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/** - * @file - * - * ODP packet input/output netmap - */ - -#ifndef ODP_PKTIO_NETMAP_H -#define ODP_PKTIO_NETMAP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define ODP_NETMAP_MODE_HW 0 /**< Netmap mode in hardware */ -#define ODP_NETMAP_MODE_SW 1 /**< Netmap mode in software */ - -/** - * Netmap parameters - */ -typedef struct { - odp_pktio_type_t type; /**< Packet IO type */ - int netmap_mode; /**< Netmap Mode */ - uint16_t ringid; /**< Ring identifiers */ -} netmap_params_t; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/platform/linux-generic/include/api/odp_pktio_types.h b/platform/linux-generic/include/api/odp_pktio_types.h index 54ce459..ab8e3da 100644 --- a/platform/linux-generic/include/api/odp_pktio_types.h +++ b/platform/linux-generic/include/api/odp_pktio_types.h @@ -17,11 +17,6 @@ extern "C" { #endif -/* We should ensure that future enum values will never overlap, otherwise - * applications that want netmap suport might get in trouble if the odp lib - * was not built with netmap support and there are more types define below - */ - /** * Packet IO types */ @@ -29,13 +24,9 @@ typedef enum { ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1, ODP_PKTIO_TYPE_SOCKET_MMSG, ODP_PKTIO_TYPE_SOCKET_MMAP, - ODP_PKTIO_TYPE_NETMAP, } odp_pktio_type_t; #include -#ifdef ODP_HAVE_NETMAP -#include -#endif /** * Packet IO parameters @@ -43,9 +34,6 @@ typedef enum { typedef union odp_pktio_params_t { odp_pktio_type_t type; /**< Packet IO type */ socket_params_t sock_params; /**< Socket parameter */ -#ifdef ODP_HAVE_NETMAP - netmap_params_t nm_params; -#endif } odp_pktio_params_t; #ifdef __cplusplus diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 881cc5f..7ba72df 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -20,9 +20,6 @@ extern "C" { #include #include -#ifdef ODP_HAVE_NETMAP -#include -#endif struct pktio_entry { odp_spinlock_t lock; /**< entry spinlock */ @@ -32,9 +29,6 @@ struct pktio_entry { odp_pktio_params_t params; /**< pktio parameters */ pkt_sock_t pkt_sock; /**< using socket API for IO */ pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap API for IO */ -#ifdef ODP_HAVE_NETMAP - pkt_netmap_t pkt_nm; /**< using netmap API for IO */ -#endif }; typedef union { diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_packet_netmap.h deleted file mode 100644 index 1ab50d0..0000000 --- a/platform/linux-generic/include/odp_packet_netmap.h +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef ODP_PACKET_NETMAP_H -#define ODP_PACKET_NETMAP_H - -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include - -#define ODP_NETMAP_MODE_HW 0 -#define ODP_NETMAP_MODE_SW 1 - -#define NETMAP_BLOCKING_IO - -/** Packet socket using netmap mmaped rings for both Rx and Tx */ -typedef struct { - odp_buffer_pool_t pool; - size_t max_frame_len; /**< max frame len = buf_size - sizeof(pkt_hdr) */ - size_t frame_offset; /**< frame start offset from start of pkt buf */ - size_t buf_size; /**< size of buffer payload in 'pool' */ - int netmap_mode; - struct nm_desc_t *nm_desc; - uint32_t begin; - uint32_t end; - struct netmap_ring *rxring; - struct netmap_ring *txring; - odp_queue_t tx_access; /* Used for exclusive access to send packets */ - uint32_t if_flags; - char ifname[32]; -} pkt_netmap_t; - -/** - * Configure an interface to work in netmap mode - */ -int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, - odp_buffer_pool_t pool, netmap_params_t *nm_params); - -/** - * Switch interface from netmap mode to normal mode - */ -int close_pkt_netmap(pkt_netmap_t * const pkt_nm); - -/** - * Receive packets using netmap - */ -int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], - unsigned len); - -/** - * Send packets using netmap - */ -int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], - unsigned len); -#endif diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 06d8935..6ef87df 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -13,9 +13,6 @@ #include #include #include -#ifdef ODP_HAVE_NETMAP -#include -#endif #include #include #include @@ -23,9 +20,6 @@ #include #include -#ifdef ODP_HAVE_NETMAP -#include -#endif #include @@ -127,11 +121,6 @@ static void init_pktio_entry(pktio_entry_t *entry, odp_pktio_params_t *params) memset(&entry->s.pkt_sock_mmap, 0, sizeof(entry->s.pkt_sock_mmap)); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - memset(&entry->s.pkt_nm, 0, sizeof(entry->s.pkt_nm)); - break; -#endif default: ODP_ERR("Packet I/O type not supported. Please recompile\n"); break; @@ -192,11 +181,6 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool, case ODP_PKTIO_TYPE_SOCKET_MMAP: ODP_DBG("Allocating socket pktio\n"); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - ODP_DBG("Allocating netmap pktio\n"); - break; -#endif default: ODP_ERR("Invalid pktio type: %02x\n", params->type); return ODP_PKTIO_INVALID; @@ -230,18 +214,6 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool, id = ODP_PKTIO_INVALID; } break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - - res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev, - pool, ¶ms->nm_params); - if (res == -1) { - close_pkt_netmap(&pktio_entry->s.pkt_nm); - free_pktio_entry(id); - id = ODP_PKTIO_INVALID; - } - break; -#endif default: free_pktio_entry(id); id = ODP_PKTIO_INVALID; @@ -272,11 +244,6 @@ int odp_pktio_close(odp_pktio_t id) case ODP_PKTIO_TYPE_SOCKET_MMAP: res = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - res = close_pkt_netmap(&entry->s.pkt_nm); - break; -#endif default: break; res |= free_pktio_entry(id); @@ -323,11 +290,6 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, pkt_table, len); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - pkts = recv_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table, len); - break; -#endif default: pkts = -1; break; @@ -365,12 +327,6 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len) pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, pkt_table, len); break; -#ifdef ODP_HAVE_NETMAP - case ODP_PKTIO_TYPE_NETMAP: - pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, - pkt_table, len); - break; -#endif default: pkts = -1; } diff --git a/platform/linux-generic/odp_packet_netmap.c b/platform/linux-generic/odp_packet_netmap.c deleted file mode 100644 index 524492d..0000000 --- a/platform/linux-generic/odp_packet_netmap.c +++ /dev/null @@ -1,453 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * Copyright (c) 2013, Nokia Solutions and Networks - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* - * NETMAP I/O code inspired by the pkt-gen example application in netmap by: - * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved. - * Copyright (C) 2013-2014 Universita` di Pisa. All rights reserved. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include -#include - -#define NETMAP_WITH_LIBS -#include - -/** Eth buffer start offset from u32-aligned address to make sure the following - * header (e.g. IP) starts at a 32-bit aligned address. - */ -#define ETHBUF_OFFSET (ODP_ALIGN_ROUNDUP(ODPH_ETHHDR_LEN, sizeof(uint32_t)) \ - - ODPH_ETHHDR_LEN) - -/** Round up buffer address to get a properly aliged eth buffer, i.e. aligned - * so that the next header always starts at a 32bit aligned address. - */ -#define ETHBUF_ALIGN(buf_ptr) ((uint8_t *)ODP_ALIGN_ROUNDUP_PTR((buf_ptr), \ - sizeof(uint32_t)) + ETHBUF_OFFSET) - -#define ETH_PROMISC 1 /* TODO: maybe this should be exported to the user */ -#define WAITLINK_TMO 2 -#define POLL_TMO 50 - -static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd, - int subcmd) -{ - struct ethtool_value eval; - struct ifreq ifr; - int error; - int fd; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - ODP_ERR("Error: cannot get device control socket\n"); - return -1; - } - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, pkt_nm->ifname, sizeof(ifr.ifr_name)); - - switch (cmd) { - case SIOCSIFFLAGS: - ifr.ifr_flags = pkt_nm->if_flags & 0xffff; - break; - case SIOCETHTOOL: - eval.cmd = subcmd; - eval.data = 0; - ifr.ifr_data = (caddr_t)&eval; - break; - default: - break; - } - error = ioctl(fd, cmd, &ifr); - if (error) - goto done; - - switch (cmd) { - case SIOCGIFFLAGS: - pkt_nm->if_flags = (ifr.ifr_flags << 16) | - (0xffff & ifr.ifr_flags); - ODP_DBG("flags are 0x%x\n", pkt_nm->if_flags); - break; - default: - break; - } -done: - close(fd); - if (error) - ODP_ERR("ioctl err %d %lu: %s\n", error, cmd, strerror(errno)); - - return error; -} - -int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, - odp_buffer_pool_t pool, netmap_params_t *nm_params) -{ - char qname[ODP_QUEUE_NAME_LEN]; - char ifname[32]; - odp_packet_t pkt; - odp_buffer_t token; - uint8_t *pkt_buf; - uint16_t ringid; - uint8_t *l2_hdr; - int ret; - - if (pool == ODP_BUFFER_POOL_INVALID) - return -1; - pkt_nm->pool = pool; - - pkt = odph_packet_alloc(pool); - if (!odph_packet_is_valid(pkt)) - return -1; - - pkt_buf = odp_packet_buf_addr(pkt); - l2_hdr = ETHBUF_ALIGN(pkt_buf); - /* Store eth buffer offset for buffers from this pool */ - pkt_nm->frame_offset = (uintptr_t)l2_hdr - (uintptr_t)pkt_buf; - /* pkt buffer size */ - pkt_nm->buf_size = odph_packet_buf_size(pkt); - /* max frame len taking into account the l2-offset */ - pkt_nm->max_frame_len = pkt_nm->buf_size - pkt_nm->frame_offset; - /* save netmap_mode for later use */ - pkt_nm->netmap_mode = nm_params->netmap_mode; - - odph_packet_free(pkt); - - if (nm_params->netmap_mode == ODP_NETMAP_MODE_SW) - ringid = NETMAP_SW_RING; - else - ringid = nm_params->ringid; - - strncpy(pkt_nm->ifname, netdev, sizeof(pkt_nm->ifname)); - snprintf(ifname, sizeof(ifname), "netmap:%s", netdev); - pkt_nm->nm_desc = nm_open(ifname, NULL, ringid, 0); - - if (pkt_nm->nm_desc == NULL) { - ODP_ERR("Error opening nm interface: %s\n", strerror(errno)); - return -1; - } - - ODP_DBG("thread %d mode %s mmap addr %p\n", - odp_thread_id(), - nm_params->netmap_mode == ODP_NETMAP_MODE_SW ? "SW" : "HW", - pkt_nm->nm_desc->mem); - - if (nm_params->netmap_mode == ODP_NETMAP_MODE_SW) { - pkt_nm->begin = pkt_nm->nm_desc->req.nr_rx_rings; - pkt_nm->end = pkt_nm->begin + 1; - pkt_nm->rxring = NETMAP_RXRING(pkt_nm->nm_desc->nifp, - pkt_nm->nm_desc->req.nr_rx_rings); - pkt_nm->txring = NETMAP_TXRING(pkt_nm->nm_desc->nifp, - pkt_nm->nm_desc->req.nr_tx_rings); - } else if (nm_params->ringid & NETMAP_HW_RING) { - pkt_nm->begin = nm_params->ringid & NETMAP_RING_MASK; - pkt_nm->end = pkt_nm->begin + 1; - pkt_nm->rxring = NETMAP_RXRING(pkt_nm->nm_desc->nifp, - pkt_nm->begin); - pkt_nm->txring = NETMAP_TXRING(pkt_nm->nm_desc->nifp, - pkt_nm->begin); - } else { - pkt_nm->begin = 0; - pkt_nm->end = pkt_nm->nm_desc->req.nr_rx_rings; - pkt_nm->rxring = NETMAP_RXRING(pkt_nm->nm_desc->nifp, 0); - pkt_nm->txring = NETMAP_TXRING(pkt_nm->nm_desc->nifp, 0); - } - - /* Set TX checksumming if hardware rings */ - if (nm_params->netmap_mode == ODP_NETMAP_MODE_HW) { - ret = nm_do_ioctl(pkt_nm, SIOCGIFFLAGS, 0); - if (ret) - return ret; - if ((pkt_nm->if_flags & IFF_UP) == 0) { - ODP_DBG("%s is down, bringing up...\n", pkt_nm->ifname); - pkt_nm->if_flags |= IFF_UP; - } - if (ETH_PROMISC) { - pkt_nm->if_flags |= IFF_PROMISC; - nm_do_ioctl(pkt_nm, SIOCSIFFLAGS, 0); - } - ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_SGSO); - if (ret) - ODP_DBG("ETHTOOL_SGSO not supported\n"); - - ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_STSO); - if (ret) - ODP_DBG("ETHTOOL_STSO not supported\n"); - /* TODO: This seems to cause the app to not receive frames - * first time it is launched after netmap driver is inserted. - * Should be investigated further. - */ - /* - nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_SRXCSUM); - */ - ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_STXCSUM); - if (ret) - ODP_DBG("ETHTOOL_STXCSUM not supported\n"); - } - - /* Set up the TX access queue */ - snprintf(qname, sizeof(qname), "%s:%s-pktio_tx_access", netdev, - nm_params->netmap_mode == ODP_NETMAP_MODE_SW ? "SW" : "HW"); - pkt_nm->tx_access = odp_queue_create(qname, ODP_QUEUE_TYPE_POLL, NULL); - if (pkt_nm->tx_access == ODP_QUEUE_INVALID) { - ODP_ERR("Error: pktio queue creation failed\n"); - return -1; - } - token = odp_buffer_alloc(pool); - if (!odp_buffer_is_valid(token)) { - ODP_ERR("Error: token creation failed\n"); - return -1; - } - - odp_queue_enq(pkt_nm->tx_access, token); - - ODP_DBG("Wait for link to come up\n"); - sleep(WAITLINK_TMO); - ODP_DBG("Done\n"); - - return 0; -} - -int close_pkt_netmap(pkt_netmap_t * const pkt_nm) -{ - if (pkt_nm->nm_desc != NULL) { - nm_close(pkt_nm->nm_desc); - pkt_nm->nm_desc = NULL; - } - - return 0; -} - -int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], - unsigned len) -{ - struct netmap_ring *rxring = pkt_nm->rxring; - int fd; - unsigned nb_rx = 0; - uint32_t limit, rx; - uint32_t ringid = pkt_nm->begin; - odp_packet_t pkt = ODP_PACKET_INVALID; -#ifdef NETMAP_BLOCKING_IO - struct pollfd fds[1]; - int ret; -#endif - - fd = pkt_nm->nm_desc->fd; -#ifdef NETMAP_BLOCKING_IO - fds[0].fd = fd; - fds[0].events = POLLIN; -#endif - - while (nb_rx < len) { -#ifdef NETMAP_BLOCKING_IO - ret = poll(&fds[0], 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - break; -#else - ioctl(fd, NIOCRXSYNC, NULL); -#endif - - /* Find first ring not empty */ - while (nm_ring_empty(rxring)) { - ringid++; - - /* Return to scheduler if no more data to meet the - requested amount (len) */ - if (ringid == pkt_nm->end) { - ODP_DBG("No more data on the wire\n"); - break; - } - - rxring = NETMAP_RXRING(pkt_nm->nm_desc->nifp, ringid); - } - - limit = len - nb_rx; - if (nm_ring_space(rxring) < limit) - limit = nm_ring_space(rxring); - - ODP_DBG("receiving %d frames out of %u\n", limit, len); - - for (rx = 0; rx < limit; rx++) { - struct netmap_slot *rslot; - char *p; - uint16_t frame_len; - uint8_t *pkt_buf; - uint8_t *l2_hdr; - uint32_t cur; - - if (odp_likely(pkt == ODP_PACKET_INVALID)) { - pkt = odph_packet_alloc(pkt_nm->pool); - if (odp_unlikely(pkt == ODP_PACKET_INVALID)) - break; - } - - cur = rxring->cur; - rslot = &rxring->slot[cur]; - p = NETMAP_BUF(rxring, rslot->buf_idx); - frame_len = rslot->len; - - rxring->head = nm_ring_next(rxring, cur); - rxring->cur = rxring->head; - - pkt_buf = odp_packet_buf_addr(pkt); - l2_hdr = pkt_buf + pkt_nm->frame_offset; - - if (frame_len > pkt_nm->max_frame_len) { - ODP_ERR("RX: frame too big %u %lu!\n", - frame_len, pkt_nm->max_frame_len); - /* drop the frame, reuse pkt next interation */ - continue; - } - if (odp_unlikely(frame_len < ODPH_ETH_LEN_MIN)) { - if (odp_unlikely(pkt_nm->netmap_mode != - ODP_NETMAP_MODE_SW)) { - ODP_ERR("RX: Frame truncated: %u\n", - (unsigned)frame_len); - continue; - } - memset(l2_hdr + frame_len, 0, - ODPH_ETH_LEN_MIN - frame_len); - frame_len = ODPH_ETH_LEN_MIN; - } - - /* For now copy the data in the mbuf, - worry about zero-copy later */ - memcpy(l2_hdr, p, frame_len); - - /* Initialize, parse and set packet header data */ - odp_packet_init(pkt); - odp_packet_parse(pkt, frame_len, pkt_nm->frame_offset); - - pkt_table[nb_rx] = pkt; - pkt = ODP_PACKET_INVALID; - nb_rx++; - } - - if (odp_unlikely(pkt == ODP_PACKET_INVALID)) - break; - } - - if (odp_unlikely(pkt != ODP_PACKET_INVALID)) - odp_buffer_free((odp_buffer_t) pkt); - - if (nb_rx) - ODP_DBG("<=== rcvd %03u frames from netmap adapter\n", nb_rx); - - return nb_rx; -} - -int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], - unsigned len) -{ - struct netmap_ring *txring = pkt_nm->txring; - int fd; - unsigned nb_tx = 0; - uint32_t limit, tx; - uint32_t ringid = pkt_nm->begin; - odp_packet_t pkt; - odp_buffer_t token; - -#ifdef NETMAP_BLOCKING_IO - struct pollfd fds[2]; - int ret; -#endif - - fd = pkt_nm->nm_desc->fd; -#ifdef NETMAP_BLOCKING_IO - fds[0].fd = fd; - fds[0].events = POLLOUT; -#endif - - token = odp_queue_deq(pkt_nm->tx_access); - - while (nb_tx < len) { -#ifdef NETMAP_BLOCKING_IO - ret = poll(&fds[0], 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - break; -#else - ioctl(fd, NIOCTXSYNC, NULL); -#endif - - /* Find first ring not empty */ - while (nm_ring_empty(txring)) { - ringid++; - - /* Return to scheduler if no more space to meet the - requested amount (len) */ - if (ringid == pkt_nm->end) { - ODP_DBG("No more space in TX rings\n"); - break; - } - - txring = NETMAP_TXRING(pkt_nm->nm_desc->nifp, ringid); - } - - limit = len - nb_tx; - if (nm_ring_space(txring) < limit) - limit = nm_ring_space(txring); - - ODP_DBG("Sending %d packets out of %d to netmap %p %u\n", - limit, len, txring, txring->cur); - - for (tx = 0; tx < limit; tx++) { - struct netmap_slot *tslot; - size_t frame_len; - uint32_t cur; - uint8_t *frame; - void *txbuf; - - cur = txring->cur; - tslot = &txring->slot[cur]; - txbuf = NETMAP_BUF(txring, tslot->buf_idx); - - pkt = pkt_table[nb_tx]; - frame = odp_packet_start(pkt); - frame_len = odp_packet_get_len(pkt); - - memcpy(txbuf, frame, frame_len); - tslot->len = frame_len; - txring->head = nm_ring_next(txring, cur); - txring->cur = txring->head; - nb_tx++; - } - } - - odp_queue_enq(pkt_nm->tx_access, token); - -#ifndef NETMAP_BLOCKING_IO - ioctl(fd, NIOCTXSYNC, NULL); -#endif - - if (nb_tx) - ODP_DBG("===> sent %03u frames to netmap adapter\n", nb_tx); - - for (tx = 0; tx < len; tx++) - odph_packet_free(pkt_table[tx]); - - return nb_tx; -}