From patchwork Fri Sep 26 15:19:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 38005 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DBDC620F2E for ; Fri, 26 Sep 2014 15:22:40 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id gi9sf2461430lab.10 for ; Fri, 26 Sep 2014 08:22:39 -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=+b15mDVhPCOKE8YasuVKR04sPkI8m/yZZv/v08URVNc=; b=k5LswkRrBA0WH3RqAHNOU45n5p0zukDd5vJU/rwLXjqkEapMFn/N0/vrA5rQiX/fSP +I7UDiVUqDM9SvSxyND1nzBZQrXJH8M0YRB94aTi2GOP/JAIw4No25qaxUIWVa4Pkv35 x0uwg+Ww8sfDSxFsO092MgciKRVjMpHF9JI86qvomHK0owzaOm5tY4h+N7mZv0bUTW5i wtcucVtHGknNfQsnKzR7DzDHzcqLaiYpKoaV8dVWYukGS82vsAnPdqyDz9E6MrwW8w9z sMTR6hCS3q00jcjMF404fUaxtkn9dAG7LSIE2fvrNsvJZxJ1G72XVFlA1z1Ad2lm5uQd Jt7g== X-Gm-Message-State: ALoCoQmSXxTw8qPyZ18CedZEEM5rGhbMT4hFEGm/aX/y6bcHJy5LPjk5ol5+J7j9kkmSLoCEx9Z+ X-Received: by 10.112.190.102 with SMTP id gp6mr2700020lbc.10.1411744958206; Fri, 26 Sep 2014 08:22:38 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.201 with SMTP id p9ls382663lae.15.gmail; Fri, 26 Sep 2014 08:22:38 -0700 (PDT) X-Received: by 10.152.23.99 with SMTP id l3mr21067177laf.39.1411744958044; Fri, 26 Sep 2014 08:22:38 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com [209.85.217.175]) by mx.google.com with ESMTPS id z8si1121184lbf.132.2014.09.26.08.22.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Sep 2014 08:22:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id w7so9193392lbi.34 for ; Fri, 26 Sep 2014 08:22:37 -0700 (PDT) X-Received: by 10.112.76.6 with SMTP id g6mr20076329lbw.22.1411744957567; Fri, 26 Sep 2014 08:22: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.130.169 with SMTP id of9csp80762lbb; Fri, 26 Sep 2014 08:22:34 -0700 (PDT) X-Received: by 10.140.22.177 with SMTP id 46mr33415288qgn.35.1411744844536; Fri, 26 Sep 2014 08:20:44 -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 c44si4527671qgd.93.2014.09.26.08.20.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 26 Sep 2014 08:20:44 -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 1XXXK6-00048L-2b; Fri, 26 Sep 2014 15:20:42 +0000 Received: from mail-la0-f46.google.com ([209.85.215.46]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XXXJX-00047D-Uu for lng-odp@lists.linaro.org; Fri, 26 Sep 2014 15:20:08 +0000 Received: by mail-la0-f46.google.com with SMTP id gi9so4416544lab.19 for ; Fri, 26 Sep 2014 08:20:02 -0700 (PDT) X-Received: by 10.112.75.233 with SMTP id f9mr3419693lbw.102.1411744801962; Fri, 26 Sep 2014 08:20:01 -0700 (PDT) Received: from localhost.localdomain ([81.200.0.212]) by mx.google.com with ESMTPSA id x5sm1979656lad.30.2014.09.26.08.20.00 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Sep 2014 08:20:00 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 26 Sep 2014 19:19:44 +0400 Message-Id: <1411744784-2309-4-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1411744784-2309-1-git-send-email-maxim.uvarov@linaro.org> References: <1411744784-2309-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 3/3] git split: delete netmap 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: maxim.uvarov@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.217.175 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 netmap will be developed and supported in different git repo: https://git.linaro.org/lng/odp-netmap.git netmap will be separate odp platform. Signed-off-by: Maxim Uvarov --- configure.ac | 22 -- example/Makefile.am | 2 +- example/packet_netmap/Makefile.am | 8 - example/packet_netmap/odp_pktio_netmap.c | 587 ----------------------------- platform/linux-generic/Makefile.am | 6 - platform/linux-generic/odp_packet_io.c | 39 -- platform/linux-generic/odp_packet_netmap.c | 453 ---------------------- 7 files changed, 1 insertion(+), 1116 deletions(-) delete mode 100644 example/packet_netmap/Makefile.am delete mode 100644 example/packet_netmap/odp_pktio_netmap.c delete mode 100644 platform/linux-generic/odp_packet_netmap.c diff --git a/configure.ac b/configure.ac index 296c9c5..46eaec1 100644 --- a/configure.ac +++ b/configure.ac @@ -61,27 +61,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 @@ -156,7 +135,6 @@ AC_CONFIG_FILES([Makefile example/l2fwd/Makefile example/odp_example/Makefile example/packet/Makefile - example/packet_netmap/Makefile example/timer/Makefile test/Makefile test/api_test/Makefile diff --git a/example/Makefile.am b/example/Makefile.am index 72663b9..b2a22a3 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1 +1 @@ -SUBDIRS = generator ipsec l2fwd odp_example packet packet_netmap timer +SUBDIRS = generator ipsec l2fwd odp_example packet timer diff --git a/example/packet_netmap/Makefile.am b/example/packet_netmap/Makefile.am deleted file mode 100644 index 5a5913c..0000000 --- a/example/packet_netmap/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -include $(top_srcdir)/example/Makefile.inc - -if ODP_NETMAP_ENABLED -bin_PROGRAMS = odp_pktio_netmap -odp_pktio_netmap_LDFLAGS = $(AM_LDFLAGS) -static -endif - -dist_odp_pktio_netmap_SOURCES = odp_pktio_netmap.c diff --git a/example/packet_netmap/odp_pktio_netmap.c b/example/packet_netmap/odp_pktio_netmap.c deleted file mode 100644 index c65cc93..0000000 --- a/example/packet_netmap/odp_pktio_netmap.c +++ /dev/null @@ -1,587 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/** - * @file - * - * ODP basic packet IO loopback test application - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -/** @def MAX_WORKERS - * @brief Maximum number of worker threads - */ -#define MAX_WORKERS 32 - -/** @def MAX_IFS - * @brief Maximum number of netmap interfaces - */ -#define MAX_IFS 16 - -/** @def SHM_PKT_POOL_SIZE - * @brief Size of the shared memory block - */ -#define SHM_PKT_POOL_SIZE (512*2048) - -/** @def SHM_PKT_POOL_BUF_SIZE - * @brief Buffer size of the packet pool buffer - */ -#define SHM_PKT_POOL_BUF_SIZE 1856 - -/** @def MAX_PKT_BURST - * @brief Maximum number of packet bursts - */ -#define MAX_PKT_BURST 16 - -/** @def PKTIO_MODE_SOCK - * @brief PKTIO is set in socket mode - */ -#define PKTIO_MODE_SOCK 0 - -/** @def PKTIO_MODE_NETMAP - * @brief PKTIO is set in netmap mode - */ -#define PKTIO_MODE_NETMAP 1 - -/** Get rid of path in filename - only for unix-type paths using '/' */ -#define NO_PATH(file_name) (strrchr((file_name), '/') ? \ - strrchr((file_name), '/') + 1 : (file_name)) - -/** - * Interface parameters obatained from app arguments - */ -typedef struct { - char if_name[32]; /**< Interface name */ - int pktio_mode; /**< Socket mode or netmap mode */ -} if_info_t; - -/** - * Parsed command line application arguments - */ -typedef struct { - int if_count; /**< Number of interfaces to be used */ - if_info_t *ifs; /**< Array of interface config options */ - odp_buffer_pool_t pool; /**< Buffer pool for packet IO */ -} appl_args_t; - -/** - * Thread specific arguments - * In this netmap example, there is a thread polling a network interface - * and another thread polling the ring that is used by the software stack - * to send packets to the same network interface. Each of the two threads - * needs to know which is the output queue corresponding to the other thread - * to be able to pass packets between the stack and the nic. This queue is - * defined by bridge_q below. - */ -typedef struct { - odp_pktio_t pktio; /**< ODP packet IO handler */ - odp_buffer_pool_t pool; /**< Buffer pool for packet IO */ - char *pktio_dev; /**< Interface name to use */ - int netmap_mode; /**< Either poll the hardware rings or the - rings associated with the host stack */ - odp_queue_t bridge_q; /**< Connect the network stack with the NIC */ -} pktio_info_t; - -/** - * Grouping of both parsed CL args and thread specific args - alloc together - */ -typedef struct { - /** Application (parsed) arguments */ - appl_args_t appl; - /** pktio entries: one for SW ring and one for HW ring */ - pktio_info_t pktios[2 * MAX_IFS]; - /** TODO: find a way to associate private data with pktios */ - /** Lookup table: find pktio_info_t based on pktio id */ - pktio_info_t *pktio_lt[ODP_CONFIG_PKTIO_ENTRIES]; -} args_t; - -/** Global pointer to args */ -static args_t *args; - -/* helper funcs */ -static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len); -static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len); -static void parse_args(int argc, char *argv[], appl_args_t *appl_args); -static void print_info(char *progname, appl_args_t *appl_args); -static void usage(char *progname); - -/** - * Packet IO loopback worker thread using ODP queues - * - * @param arg thread arguments of type 'thread_args_t *' - */ -static void *pktio_queue_thread(void *arg) -{ - int thr; - odp_buffer_pool_t pkt_pool; - odp_packet_t pkt; - odp_buffer_t buf; - unsigned long pkt_cnt = 0; - unsigned long err_cnt = 0; - - (void)arg; - - thr = odp_thread_id(); - printf("Pktio thread [%02i] starts\n", thr); - - /* Lookup the packet pool */ - pkt_pool = odp_buffer_pool_lookup("packet_pool"); - if (pkt_pool == ODP_BUFFER_POOL_INVALID) { - ODP_ERR(" [%02i] Error: pkt_pool not found\n", thr); - return NULL; - } - - /* Loop packets */ - for (;;) { - odp_pktio_t pktio_tmp; - odp_queue_t outq_def; - pktio_info_t *pktio_info; - - /* Use schedule to get buf from any input queue */ - buf = odp_schedule(NULL, ODP_SCHED_WAIT); - - pkt = odp_packet_from_buffer(buf); - - /* Drop packets with errors */ - if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) { - ODP_ERR("Drop frame - err_cnt:%lu\n", ++err_cnt); - continue; - } - - pktio_tmp = odp_pktio_get_input(pkt); - if (pktio_tmp == ODP_PKTIO_INVALID) { - ODP_ERR("[%02i] Error: invalid pktio\n", thr); - return NULL; - } - - outq_def = odp_pktio_outq_getdef(pktio_tmp); - - if (outq_def == ODP_QUEUE_INVALID) { - ODP_ERR(" [%02i] Error: def output-Q query\n", - thr); - return NULL; - } - - /* Lookup the thread associated with the entry */ - pktio_info = args->pktio_lt[pktio_tmp]; - - /* Send back packets arrived on physical interface */ - if (pktio_info->netmap_mode == ODP_NETMAP_MODE_HW) { - odp_packet_t pkt_copy; - - pkt_copy = odph_packet_alloc(pkt_pool); - - if (odp_packet_copy(pkt_copy, pkt) != 0) { - ODP_ERR("Packet copy failed!\n"); - odph_packet_free(pkt_copy); - } else { - swap_pkt_addrs(&pkt_copy, 1); - odp_queue_enq(outq_def, - odp_buffer_from_packet(pkt_copy)); - } - } - - odp_queue_enq(pktio_info->bridge_q, buf); - - /* Print packet counts every once in a while */ - if (odp_unlikely(pkt_cnt++ % 100000 == 0)) { - printf(" [%02i] pkt_cnt:%lu\n", thr, pkt_cnt); - fflush(NULL); - } - } - -/* unreachable */ -} - -/** - * ODP packet example main function - */ -int main(int argc, char *argv[]) -{ - odph_linux_pthread_t thread_tbl[MAX_WORKERS]; - odp_buffer_pool_t pool; - int thr_id; - int num_workers; - void *pool_base; - odp_shm_t shm; - int i; - - /* Init ODP before calling anything else */ - if (odp_init_global()) { - ODP_ERR("Error: ODP global init failed.\n"); - exit(EXIT_FAILURE); - } - - /* Reserve memory for args from shared mem */ - shm = odp_shm_reserve("shm_args", sizeof(args_t), - ODP_CACHE_LINE_SIZE, 0); - args = odp_shm_addr(shm); - if (args == NULL) { - ODP_ERR("Error: shared mem alloc failed.\n"); - exit(EXIT_FAILURE); - } - memset(args, 0, sizeof(*args)); - - /* Parse and store the application arguments */ - parse_args(argc, argv, &args->appl); - - /* Print both system and application information */ - print_info(NO_PATH(argv[0]), &args->appl); - - num_workers = odp_sys_core_count(); - if (num_workers > MAX_WORKERS) - num_workers = MAX_WORKERS; - - /* Init this thread */ - thr_id = odp_thread_create(0); - odp_init_local(thr_id); - - /* Create packet pool */ - shm = odp_shm_reserve("shm_packet_pool", - SHM_PKT_POOL_SIZE, ODP_CACHE_LINE_SIZE, 0); - pool_base = odp_shm_addr(shm); - if (pool_base == NULL) { - ODP_ERR("Error: packet pool mem alloc failed.\n"); - exit(EXIT_FAILURE); - } - - pool = odp_buffer_pool_create("packet_pool", pool_base, - SHM_PKT_POOL_SIZE, - SHM_PKT_POOL_BUF_SIZE, - ODP_CACHE_LINE_SIZE, - ODP_BUFFER_TYPE_PACKET); - if (pool == ODP_BUFFER_POOL_INVALID) { - ODP_ERR("Error: packet pool create failed.\n"); - exit(EXIT_FAILURE); - } - odp_buffer_pool_print(pool); - - for (i = 0; i < 2 * args->appl.if_count; ++i) { - odp_pktio_params_t params; - netmap_params_t *nm_params = ¶ms.nm_params; - char inq_name[ODP_QUEUE_NAME_LEN]; - odp_queue_t inq_def; - odp_queue_param_t qparam; - odp_pktio_t pktio; - int ret; - - /* Create a pktio polling the hardware rings and one that polls - * the software ring associated with the physical interface - */ - - args->pktios[i].pktio_dev = args->appl.ifs[i / 2].if_name; - memset(nm_params, 0, sizeof(*nm_params)); - nm_params->type = ODP_PKTIO_TYPE_NETMAP; - if (i % 2) { - nm_params->netmap_mode = ODP_NETMAP_MODE_SW; - nm_params->ringid = 0; - } else { - nm_params->netmap_mode = ODP_NETMAP_MODE_HW; - nm_params->ringid = 0; - } - pktio = odp_pktio_open(args->pktios[i].pktio_dev, - pool, ¶ms); - /* Open a packet IO instance for this thread */ - if (pktio == ODP_PKTIO_INVALID) { - ODP_ERR(" [%02i] Err: pktio create\n", i); - return -1; - } - - args->pktios[i].pktio = pktio; - args->pktios[i].pool = pool; - args->pktios[i].netmap_mode = nm_params->netmap_mode; - /* Save pktio_info in the lookup table */ - args->pktio_lt[pktio] = &args->pktios[i]; - /* - * Create and set the default INPUT queue associated with the - * 'pktio' resource - */ - qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; - qparam.sched.sync = ODP_SCHED_SYNC_NONE; - qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; - snprintf(inq_name, sizeof(inq_name), "%i-pktio_inq_def", - (int)pktio); - inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0'; - - inq_def = odp_queue_create(inq_name, ODP_QUEUE_TYPE_PKTIN, - &qparam); - if (inq_def == ODP_QUEUE_INVALID) { - ODP_ERR(" [%02i] Err: pktio q create\n", i); - return -1; - } - - ret = odp_pktio_inq_setdef(pktio, inq_def); - if (ret != 0) { - ODP_ERR(" [%02i] Err: default input-Q setup\n" - , i); - return -1; - } - - printf(" [%02i] created pktio:%02i, queue mode\n" - " default pktio%02i-INPUT queue:%u\n", - i, pktio, pktio, inq_def); - - /* Prepare for bridging: set bridge_q queue ids */ - if (i % 2) { - odp_pktio_t pktio_bridge; - odp_queue_t outq_def; - - pktio_bridge = args->pktios[i-1].pktio; - outq_def = odp_pktio_outq_getdef(pktio_bridge); - args->pktios[i].bridge_q = outq_def; - - pktio_bridge = args->pktios[i].pktio; - outq_def = odp_pktio_outq_getdef(pktio_bridge); - args->pktios[i-1].bridge_q = outq_def; - } - } - - memset(thread_tbl, 0, sizeof(thread_tbl)); - for (i = 0; i < num_workers; ++i) { - - /* - * Create threads one-by-one instead of all-at-once, - * because each thread might get different arguments - */ - odph_linux_pthread_create(&thread_tbl[i], 1, i, - pktio_queue_thread, NULL); - } - - /* Master thread waits for other threads to exit */ - odph_linux_pthread_join(thread_tbl, num_workers); - - printf("Exit\n\n"); - - return 0; -} - -/** - * Drop packets which input parsing marked as containing errors. - * - * Frees packets with error and modifies pkt_tbl[] to only contain packets with - * no detected errors. - * - * @param pkt_tbl Array of packet - * @param len Length of pkt_tbl[] - * - * @return Number of packets with no detected error - */ -static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len) -{ - odp_packet_t pkt; - unsigned pkt_cnt = len; - unsigned i, j; - - for (i = 0, j = 0; i < len; ++i) { - pkt = pkt_tbl[i]; - - if (odp_unlikely(odp_packet_error(pkt))) { - odph_packet_free(pkt); /* Drop */ - pkt_cnt--; - } else if (odp_unlikely(i != j++)) { - pkt_tbl[j-1] = pkt; - } - } - - return pkt_cnt; -} - -/** - * Swap eth src<->dst and IP src<->dst addresses - * - * @param pkt_tbl Array of packets - * @param len Length of pkt_tbl[] - */ -static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len) -{ - odp_packet_t pkt; - odph_ethhdr_t *eth; - odph_ethaddr_t tmp_addr; - odph_ipv4hdr_t *ip; - uint32be_t ip_tmp_addr; /* tmp ip addr */ - unsigned i; - - for (i = 0; i < len; ++i) { - pkt = pkt_tbl[i]; - if (odp_packet_inflag_eth(pkt)) { - eth = (odph_ethhdr_t *)odp_packet_l2(pkt); - - tmp_addr = eth->dst; - eth->dst = eth->src; - eth->src = tmp_addr; - - if (odp_packet_inflag_ipv4(pkt)) { - /* IPv4 */ - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); - - ip_tmp_addr = ip->src_addr; - ip->src_addr = ip->dst_addr; - ip->dst_addr = ip_tmp_addr; - } - } - } -} - -/** - * Parse and store the command line arguments - * - * @param argc argument count - * @param argv[] argument vector - * @param appl_args Store application arguments here - */ -static void parse_args(int argc, char *argv[], appl_args_t *appl_args) -{ - int opt; - int long_index; - char *names, *str, *token, *save; - size_t len; - int i; - static struct option longopts[] = { - {"interface", required_argument, NULL, 'i'}, /* return 'i' */ - {"help", no_argument, NULL, 'h'}, /* return 'h' */ - {NULL, 0, NULL, 0} - }; - - while (1) { - opt = getopt_long(argc, argv, "+i:h", longopts, &long_index); - - if (opt == -1) - break; /* No more options */ - - switch (opt) { - /* parse packet-io interface names */ - case 'i': - len = strlen(optarg); - if (len == 0) { - usage(argv[0]); - exit(EXIT_FAILURE); - } - len += 1; /* add room for '\0' */ - - names = malloc(len); - if (names == NULL) { - usage(argv[0]); - exit(EXIT_FAILURE); - } - - /* count the number of tokens separated by ',' */ - strcpy(names, optarg); - for (str = names, i = 0;; str = NULL, i++) { - token = strtok_r(str, ",", &save); - if (token == NULL) - break; - } - appl_args->if_count = i; - - if (appl_args->if_count == 0) { - usage(argv[0]); - exit(EXIT_FAILURE); - } - - /* allocate storage for the if names */ - appl_args->ifs = - calloc(appl_args->if_count, sizeof(if_info_t)); - - /* store the if names (reset names string) */ - strcpy(names, optarg); - for (str = names, i = 0;; str = NULL, i++) { - token = strtok_r(str, ",", &save); - if (token == NULL) - break; - strncpy(appl_args->ifs[i].if_name, token, - sizeof(appl_args->ifs[i].if_name)); - appl_args->ifs[i].pktio_mode = - PKTIO_MODE_NETMAP; - } - break; - - case 'h': - usage(argv[0]); - exit(EXIT_SUCCESS); - break; - - default: - break; - } - } - - if (appl_args->if_count == 0) { - usage(argv[0]); - exit(EXIT_FAILURE); - } - - optind = 1; /* reset 'extern optind' from the getopt lib */ -} - -/** - * Print system and application info - */ -static void print_info(char *progname, appl_args_t *appl_args) -{ - int i; - - printf("\n" - "ODP system info\n" - "---------------\n" - "ODP API version: %s\n" - "CPU model: %s\n" - "CPU freq (hz): %"PRIu64"\n" - "Cache line size: %i\n" - "Core count: %i\n" - "\n", - odp_version_api_str(), odp_sys_cpu_model_str(), odp_sys_cpu_hz(), - odp_sys_cache_line_size(), odp_sys_core_count() - ); - printf("Running ODP appl: \"%s\"\n" - "-----------------\n" - "IF-count: %i\n" - "Using IFs: ", - progname, appl_args->if_count); - for (i = 0; i < appl_args->if_count; ++i) - printf(" %s", appl_args->ifs[i].if_name); - printf("\n" - "Mode: "); - printf("\n\n"); - fflush(NULL); -} - -/** - * Prinf usage information - */ -static void usage(char *progname) -{ - printf("\n" - "Usage: %s OPTIONS\n" - " E.g. %s -i eth1,eth2,eth3\n" - "\n" - "OpenDataPlane example application.\n" - "\n" - "Mandatory OPTIONS:\n" - " -i, --interface Eth interfaces (comma-separated, no spaces)\n" - "\n" - "Optional OPTIONS\n" - " -h, --help Display help and exit.\n" - "\n", NO_PATH(progname), NO_PATH(progname) - ); -} diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 25c82ea..5b3c879 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 @@ -73,8 +72,3 @@ __LIB__libodp_la_SOURCES = \ odp_ticketlock.c \ 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/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 06d8935..c06653f 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 @@ -192,11 +186,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 +219,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 +249,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 +295,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 +332,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; -}