From patchwork Wed Sep 20 09:00:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113090 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp438703edb; Wed, 20 Sep 2017 02:01:40 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAovhZEFTVnR157BmN5p69j59hPUVlXpYoSiiRWhmGOKR/eNgWeu/nvgk8H0oT2TQtLWO2m X-Received: by 10.55.132.5 with SMTP id g5mr2118537qkd.228.1505898100791; Wed, 20 Sep 2017 02:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898100; cv=none; d=google.com; s=arc-20160816; b=w5uNgWYBJ8P2lpGs3BMqFaNMYJtnOXxSkp4EJrLKAhzLAFIK8tc3AcrQThY/XbbH8Z JUuFhZoQ4K93fEcEjEFF066gy/x7J0bKHYDttYkHNcl13c96gG8z5ZtZtlrvKLiLcoiC 2Ho/pRvRO6EtMlq3L0MXWL9O+XUx1WzAlP29xdJ/u0D8wzLzqoQwtRTuEifcUybVqw/X 0KWZIjAlA6abeSBaNeyUqiDPry4DvDEuEJwXWCAJc+IOi8L2egv6fLgQQI9+T2p5QVcX Q+5GRUZ+6O2768zVFrpa/Q3T8PzKsEvn8wkNxItmq2NeimafQs5XuFb1TRGqWI4M6DTS EMVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=GKot5x0coAORiqqOO8upAr7ROKnrXE7EyeFNeNH3CFU=; b=qRZgh+XgHT+Sezb3Hp7zDRmepOoc/9jxqK9FUxetDMSywNVQrwzwcUZLDBmir6l7CA 2QftGAJzGvoe5zQ2Atqcrb7dAXLVJzD7R/WFAb4Gsyuf5yLIZqaR1gSrOLSkq/BYCItS nyX517d0AR5T6QJUcqmbFXs4ARTStMe4J9gEC3oO86ZUQV8qiCQzstaSqSY+x2T5Q74o ChHTrNJqXj/vlgD8Fz+2A2MB+sjh2n6qhoNthoro5gfL2fHcAZg0GzTJ0cfUNTvLSfqF zcnHw0qzj0WxYXZAQeuWL6ABI72nb035v5oyVtSxmSFegJsPpOjvUGP9I6n0bJdeZ+qL M6OA== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g9si1474600qtf.204.2017.09.20.02.01.40; Wed, 20 Sep 2017 02:01:40 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 722DA60BDB; Wed, 20 Sep 2017 09:01:40 +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.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, 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 738A760C76; Wed, 20 Sep 2017 09:00:40 +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 A9E4B60C76; Wed, 20 Sep 2017 09:00:32 +0000 (UTC) Received: from forward102o.mail.yandex.net (forward102o.mail.yandex.net [37.140.190.182]) by lists.linaro.org (Postfix) with ESMTPS id 8124C60C0A for ; Wed, 20 Sep 2017 09:00:25 +0000 (UTC) Received: from mxback12j.mail.yandex.net (mxback12j.mail.yandex.net [IPv6:2a02:6b8:0:1619::87]) by forward102o.mail.yandex.net (Yandex) with ESMTP id CD7FE5A03D5D for ; Wed, 20 Sep 2017 12:00:23 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback12j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 6OCBD4xjQC-0NVGxhDE; Wed, 20 Sep 2017 12:00:23 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0MNqLD4d; Wed, 20 Sep 2017 12:00:22 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:05 +0300 Message-Id: <1505898014-18011-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 1/10] framework: modular: extern SUBSYSTEM_FOREACH_TEMPLATE 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Static SUBSYSTEM_FOREACH_TEMPLATE constraints the functions to be instantiated in the source files which invoke them, this causes code scatter shoots. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Kevin Wang Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ frameworks/modular/odp_module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/modular/odp_module.h b/frameworks/modular/odp_module.h index 1a9e178c3..59f67c8d4 100644 --- a/frameworks/modular/odp_module.h +++ b/frameworks/modular/odp_module.h @@ -206,7 +206,7 @@ struct odp_module_base { * subsystem and invoke init_global method for each. */ #define ODP_SUBSYSTEM_FOREACH_TEMPLATE(subs, method, print) \ -static int odp_ ## subs ##_## method(bool continue_on_errors) \ +int odp_ ## subs ##_## method(bool continue_on_errors) \ { \ int result = 0; \ ODP_MODULE_CLASS(subs) * mod = NULL; \ From patchwork Wed Sep 20 09:00:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113091 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp439572edb; Wed, 20 Sep 2017 02:02:27 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAz309zGwxIzchYnWj0TuONY1XAiY+2NcVHqftH25u86UxromCFgojuZUQGrCnR4NcdPlMq X-Received: by 10.237.62.58 with SMTP id l55mr3530025qtf.30.1505898147508; Wed, 20 Sep 2017 02:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898147; cv=none; d=google.com; s=arc-20160816; b=aHwPSOXeM31Kf+QtAvyhKmdadf1MJ1GoYivrvmv/uY9mTZ1StRmq9tYF+n64XU37L/ qYex6DrvRhxgtu+6yXwa5/qurGNIRHLe8ma9KxnPzLHIbjThroGK/flPpTLc1I/LbqTj RoQoLbQx+sGgWXMHoZDiIwLH+THwjBm5K/yEKsBgo9yhcTTSP/2lSHNzWvFSBGzfq2Or WyYZUXDqYKz2mY92TxUUFl9uTGVJXpEQOLRLga3mVZqr2qY3pvE/HMIVbFRuFziDijYv Q5BjVTV32V/iNiB4diM7n6b3kxEWFcGnMVbJJv8jH1rVdA4SZjnt1uRWAB8wg9hC9lm7 u4/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=478eZgyeD/x2oZE9ivwo2LhqfrXWiCpSu1e20SHiZts=; b=EVtJCnwMnx928iaIxvf46WrKZ4+jHLDg4pkaoUOS7lWVrGKwZurDnP7fdvW6+ZB2/W 723xApE7I8wMrITbJt9NoV/vJOEGNoEneTdLJLct14BsyuPTNk+6kpSiA6zxlxg0ee4W EvUE950XLYb1Sr64hkl0wViCNHPAmi3lAnXcpY4yoE/q+5Dq1NReZgNrFOy7iyMs2DXn 3+0hSvYbnrFjPDMVkwM+PQ/Nnh4VfE8ZDF9cPkcPjiUWDxpB/4Lf7ew3H+2nL+lqG0AK 7faLlAF++JlKMeqleNWxpdxino67zXV8aZr+qci2Gt7AC7av0Gplf0eubrEG+EWF3FrL F4ag== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id r18si1442989qtr.513.2017.09.20.02.02.27; Wed, 20 Sep 2017 02:02:27 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 2F68664456; Wed, 20 Sep 2017 09:02:27 +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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 D1D8E60C95; Wed, 20 Sep 2017 09:00:42 +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 6FD0F60C0A; Wed, 20 Sep 2017 09:00:33 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id 92B36608E0 for ; Wed, 20 Sep 2017 09:00:27 +0000 (UTC) Received: from mxback6g.mail.yandex.net (mxback6g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:167]) by forward102j.mail.yandex.net (Yandex) with ESMTP id 6DC955605AD5 for ; Wed, 20 Sep 2017 12:00:26 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback6g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id pcXWrIrcUT-0QnO9D29; Wed, 20 Sep 2017 12:00:26 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0QN4b5Zm; Wed, 20 Sep 2017 12:00:26 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:06 +0300 Message-Id: <1505898014-18011-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 2/10] example: l2fwd_simple: disable socket pktios 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He l2fwd_simple_run.sh waits 1 second to allow test application to forward more than 10 packets. It works in case pktios are listed statically and pcap takes precedence over socket pktios. But with dynamically registered pktios the order was not guaranteed and socket pktios may take precedence over pcap pktio, which spent more time in open operation and caused this test failed. Disable the socket pktios since they mistakenly take too long time in open operation, future code refactory should solve the problem thoroughly. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Kevin Wang Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ example/l2fwd_simple/l2fwd_simple_run.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/example/l2fwd_simple/l2fwd_simple_run.sh b/example/l2fwd_simple/l2fwd_simple_run.sh index 130a3a848..0c464f70c 100755 --- a/example/l2fwd_simple/l2fwd_simple_run.sh +++ b/example/l2fwd_simple/l2fwd_simple_run.sh @@ -6,6 +6,11 @@ # SPDX-License-Identifier: BSD-3-Clause # +# Disable socket pktios since their open operations +# mistakenly take too long time +export ODP_PKTIO_DISABLE_SOCKET_MMSG=1 +export ODP_PKTIO_DISABLE_SOCKET_MMAP=1 + PCAP_IN=`find . ${TEST_DIR} $(dirname $0) -name udp64.pcap -print -quit` echo "using PCAP_IN = ${PCAP_IN}" From patchwork Wed Sep 20 09:00:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113092 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp440730edb; Wed, 20 Sep 2017 02:03:39 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCxdUSFJJBitJ3jCMfzJIl929HXe0IzyHA6eCVWvgQM+GeWhWTO6oveSQFhm0n1YTaNZxa8 X-Received: by 10.200.51.211 with SMTP id d19mr6075853qtb.227.1505898219368; Wed, 20 Sep 2017 02:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898219; cv=none; d=google.com; s=arc-20160816; b=H4xybka/JrzzLyvskVwmopOPnPBRam1p6cwbcURooxE5MpZF+TzDt0kkgR4fQeNS/B k6MkEbqsOG6yNkCDGNunJwkG/1Zkf8kE6rleA6PFdK8JbolKq9xd3stQ83QdQauWwuqg c68zVdPIk2uEg7kXtZZb2ICqYOW8asSaqXU6vkPQMoVnUQTH6/gn+K3AQJn1BCsAEsDg DwlmK9EczoaTy82Tj2VkaOxCeApE5nqRRrgdb3u4H+9gYqMi7TFANrowRgKn1GreDdPv cvUcdQ2FMnqitIWYRY9H5lL5FcHi0FlKo6KuKyNxpGI47pADNEIv5ylh2ZbhQH9SAHUa pvUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=v528jYiarkw/P4XYI2WnnY9gUCAZXh+J1QRtCiPtFAs=; b=mK5B+5o+uuGXOuX75GsFp0uOsoHPwW4vyc0jexlXQyjcy4z5viYyrfmck4NTw2VyQf piD8bxm5nhAyoAEbCj9Lq0qqC/JhpBrqiKOPT/9lCsL1VbU+pVPMe2WqJ708t8DSwhjk bu3ay6MvanyRf+EMFIjcF7X7SXFL5R2zQxwiz9UVcj+4YoRgpgH0Z0s4nQHWECCFPv9P mhRWDfv1cLAXUM59old3Ww7Ow01zdpR8ZBO+Q2pUFOUurJmtsw9o1d7ueWNy2vDa5+cG ZbL9IA7OnWwpm3IFkM9lSf0+5fAvIocOzZppTEuq3llWG8Ns9Avf+XnvL3PzFuGNA9Cy +p7A== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s13si31548qks.343.2017.09.20.02.03.39; Wed, 20 Sep 2017 02:03:39 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id F40186446D; Wed, 20 Sep 2017 09:03:38 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 36E9E60DB3; Wed, 20 Sep 2017 09:00:53 +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 D7BB660BDB; Wed, 20 Sep 2017 09:00:35 +0000 (UTC) Received: from forward104p.mail.yandex.net (forward104p.mail.yandex.net [77.88.28.107]) by lists.linaro.org (Postfix) with ESMTPS id F1FC2607C8 for ; Wed, 20 Sep 2017 09:00:30 +0000 (UTC) Received: from mxback17j.mail.yandex.net (mxback17j.mail.yandex.net [IPv6:2a02:6b8:0:1619::93]) by forward104p.mail.yandex.net (Yandex) with ESMTP id F316B18250F for ; Wed, 20 Sep 2017 12:00:28 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback17j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id GtMZF9mSVX-0Sg4OOYh; Wed, 20 Sep 2017 12:00:28 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0RNqwt9Z; Wed, 20 Sep 2017 12:00:27 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:07 +0300 Message-Id: <1505898014-18011-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 3/10] linux-gen: pktio: apply modular framework 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Apply modular framework to the pktio ops registration, convert the static array for impls registration into a dynamic and extensible modularization manner. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Kevin Wang Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ platform/linux-dpdk/Makefile.am | 2 + .../linux-dpdk/include/odp_packet_io_internal.h | 49 ++----------- platform/linux-dpdk/odp_packet_dpdk.c | 39 +++++++---- platform/linux-dpdk/pktio/subsystem.c | 33 +++++++++ platform/linux-generic/Makefile.am | 3 +- .../linux-generic/include/odp_packet_io_internal.h | 59 ++-------------- .../include/odp_pktio_ops_subsystem.h | 81 ++++++++++++++++++++++ platform/linux-generic/odp_packet_io.c | 57 ++++----------- platform/linux-generic/pktio/dpdk.c | 34 ++++++--- platform/linux-generic/pktio/io_ops.c | 31 --------- platform/linux-generic/pktio/ipc.c | 43 +++++++++--- platform/linux-generic/pktio/loop.c | 31 ++++++--- platform/linux-generic/pktio/netmap.c | 37 +++++++--- platform/linux-generic/pktio/pcap.c | 33 +++++++-- platform/linux-generic/pktio/socket.c | 31 ++++++--- platform/linux-generic/pktio/socket_mmap.c | 31 ++++++--- platform/linux-generic/pktio/subsystem.c | 58 ++++++++++++++++ platform/linux-generic/pktio/tap.c | 38 +++++++--- 18 files changed, 435 insertions(+), 255 deletions(-) create mode 100644 platform/linux-dpdk/pktio/subsystem.c create mode 100644 platform/linux-generic/include/odp_pktio_ops_subsystem.h delete mode 100644 platform/linux-generic/pktio/io_ops.c create mode 100644 platform/linux-generic/pktio/subsystem.c diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 930865703..2ff44316e 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -190,6 +190,7 @@ noinst_HEADERS = \ ${top_srcdir}/platform/linux-generic/include/odp_internal.h \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_internal.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ @@ -244,6 +245,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ ../linux-generic/odp_name_table.c \ odp_packet.c \ odp_packet_dpdk.c \ + pktio/subsystem.c \ odp_packet_flags.c \ ../linux-generic/odp_packet_io.c \ ../linux-generic/pktio/loop.c \ diff --git a/platform/linux-dpdk/include/odp_packet_io_internal.h b/platform/linux-dpdk/include/odp_packet_io_internal.h index 14b6a8d3b..fde172fc5 100644 --- a/platform/linux-dpdk/include/odp_packet_io_internal.h +++ b/platform/linux-dpdk/include/odp_packet_io_internal.h @@ -31,13 +31,16 @@ extern "C" { #include #include +/* Forward declaration */ +typedef union pktio_entry_u pktio_entry_t; +#include + #define PKTIO_NAME_LEN 256 #define PKTIN_INVALID ((odp_pktin_queue_t) {ODP_PKTIO_INVALID, 0}) #define PKTOUT_INVALID ((odp_pktout_queue_t) {ODP_PKTIO_INVALID, 0}) /* Forward declaration */ -struct pktio_if_ops; struct pkt_dpdk_t; typedef struct { @@ -63,7 +66,7 @@ typedef struct { } pkt_dpdk_t; struct pktio_entry { - const struct pktio_if_ops *ops; /**< Implementation specific methods */ + const pktio_ops_module_t *ops; /**< Implementation specific methods */ /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ @@ -116,50 +119,16 @@ struct pktio_entry { } out_queue[PKTIO_MAX_QUEUES]; }; -typedef union { +union pktio_entry_u { struct pktio_entry s; uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(struct pktio_entry))]; -} pktio_entry_t; +}; typedef struct { odp_spinlock_t lock; pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; } pktio_table_t; -typedef struct pktio_if_ops { - const char *name; - void (*print)(pktio_entry_t *pktio_entry); - int (*init_global)(void); - int (*init_local)(void); - int (*term)(void); - int (*open)(odp_pktio_t pktio, pktio_entry_t *pktio_entry, - const char *devname, odp_pool_t pool); - int (*close)(pktio_entry_t *pktio_entry); - int (*start)(pktio_entry_t *pktio_entry); - int (*stop)(pktio_entry_t *pktio_entry); - int (*stats)(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats); - int (*stats_reset)(pktio_entry_t *pktio_entry); - uint64_t (*pktin_ts_res)(pktio_entry_t *pktio_entry); - odp_time_t (*pktin_ts_from_ns)(pktio_entry_t *pktio_entry, uint64_t ns); - int (*recv)(pktio_entry_t *entry, int index, odp_packet_t packets[], - int num); - int (*send)(pktio_entry_t *entry, int index, - const odp_packet_t packets[], int num); - uint32_t (*mtu_get)(pktio_entry_t *pktio_entry); - int (*promisc_mode_set)(pktio_entry_t *pktio_entry, int enable); - int (*promisc_mode_get)(pktio_entry_t *pktio_entry); - int (*mac_get)(pktio_entry_t *pktio_entry, void *mac_addr); - int (*link_status)(pktio_entry_t *pktio_entry); - int (*capability)(pktio_entry_t *pktio_entry, - odp_pktio_capability_t *capa); - int (*config)(pktio_entry_t *pktio_entry, - const odp_pktio_config_t *config); - int (*input_queues_config)(pktio_entry_t *pktio_entry, - const odp_pktin_queue_param_t *param); - int (*output_queues_config)(pktio_entry_t *pktio_entry, - const odp_pktout_queue_param_t *p); -} pktio_if_ops_t; - extern void *pktio_entry_ptr[]; static inline int pktio_to_id(odp_pktio_t pktio) @@ -203,10 +172,6 @@ int single_recv_queue(pktio_entry_t *entry, int index, odp_packet_t packets[], int single_send_queue(pktio_entry_t *entry, int index, const odp_packet_t packets[], int num); -extern const pktio_if_ops_t loopback_pktio_ops; -extern const pktio_if_ops_t dpdk_pktio_ops; -extern const pktio_if_ops_t * const pktio_if_ops[]; - int pktin_poll(int pktio_index, int num_queue, int index[]); void pktio_stop_finalize(int pktio_index); diff --git a/platform/linux-dpdk/odp_packet_dpdk.c b/platform/linux-dpdk/odp_packet_dpdk.c index d808f130f..b9b493efe 100644 --- a/platform/linux-dpdk/odp_packet_dpdk.c +++ b/platform/linux-dpdk/odp_packet_dpdk.c @@ -32,18 +32,11 @@ #include #include -/* Ops for all implementation of pktio. - * Order matters. The first implementation to setup successfully - * will be picked. - * Array must be NULL terminated */ -const pktio_if_ops_t * const pktio_if_ops[] = { - &loopback_pktio_ops, - &dpdk_pktio_ops, - NULL -}; - pktio_table_t *pktio_tbl; +/* Forward declaration */ +static pktio_ops_module_t dpdk_pktio_ops; + static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry); /* Test if s has only digits or not. Dpdk pktio uses only digits.*/ @@ -686,12 +679,15 @@ static int stats_reset_pkt_dpdk(pktio_entry_t *pktio_entry) return 0; } -const pktio_if_ops_t dpdk_pktio_ops = { - .name = "odp-dpdk", +static pktio_ops_module_t dpdk_pktio_ops = { + .base = { + .name = "odp-dpdk", + .init_local = NULL, + .init_global = NULL, + .term_local = NULL, + .term_global = NULL, + }, .print = NULL, - .init_global = NULL, - .init_local = NULL, - .term = NULL, .open = setup_pkt_dpdk, .close = close_pkt_dpdk, .start = start_pkt_dpdk, @@ -712,3 +708,16 @@ const pktio_if_ops_t dpdk_pktio_ops = { .recv = recv_pkt_dpdk, .send = send_pkt_dpdk }; + +ODP_MODULE_CONSTRUCTOR(dpdk_pktio_ops) +{ + odp_module_constructor(&dpdk_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &dpdk_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_dpdk_pktio_ops = 0; + diff --git a/platform/linux-dpdk/pktio/subsystem.c b/platform/linux-dpdk/pktio/subsystem.c new file mode 100644 index 000000000..4ff15c814 --- /dev/null +++ b/platform/linux-dpdk/pktio/subsystem.c @@ -0,0 +1,33 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +#define SUBSYSTEM_VERSION 0x00010000UL +ODP_SUBSYSTEM_DEFINE(pktio_ops, "packet IO operations", SUBSYSTEM_VERSION); + +/* Instantiate init and term functions */ +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_global, ODP_ERR) +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_local, ODP_ERR) +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, term_global, ODP_ABORT) + +/* Temporary variable to enable link modules, + * will remove in Makefile scheme changes. + */ +extern int enable_link_dpdk_pktio_ops; +extern int enable_link_loopback_pktio_ops; + +ODP_SUBSYSTEM_CONSTRUCTOR(pktio_ops) +{ + odp_subsystem_constructor(pktio_ops); + + /* Further initialization per subsystem */ + enable_link_dpdk_pktio_ops = 1; + enable_link_loopback_pktio_ops = 1; +} diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index c13d73b50..ad6f14450 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -191,6 +191,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ + ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_queue_subsystem.h \ ${srcdir}/include/odp_pool_internal.h \ @@ -263,7 +264,7 @@ __LIB__libodp_linux_la_SOURCES = \ odp_packet_flags.c \ odp_packet_io.c \ pktio/ethtool.c \ - pktio/io_ops.c \ + pktio/subsystem.c \ pktio/ipc.c \ pktio/pktio_common.c \ pktio/loop.c \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index dc049f467..589148400 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -36,6 +36,10 @@ extern "C" { #include #include +/* Forward declaration */ +typedef union pktio_entry_u pktio_entry_t; +#include + #define PKTIO_NAME_LEN 256 #define PKTIN_INVALID ((odp_pktin_queue_t) {ODP_PKTIO_INVALID, 0}) @@ -47,9 +51,6 @@ extern "C" { * requested number of packets were not handled. */ #define SOCK_ERR_REPORT(e) (e != EAGAIN && e != EWOULDBLOCK && e != EINTR) -/* Forward declaration */ -struct pktio_if_ops; - typedef struct { odp_queue_t loopq; /**< loopback queue for "loop" device */ odp_bool_t promisc; /**< promiscuous mode state */ @@ -109,7 +110,7 @@ typedef struct { } _ipc_pktio_t; struct pktio_entry { - const struct pktio_if_ops *ops; /**< Implementation specific methods */ + const pktio_ops_module_t *ops; /**< Implementation specific methods */ /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ @@ -177,50 +178,16 @@ struct pktio_entry { } out_queue[PKTIO_MAX_QUEUES]; }; -typedef union { +union pktio_entry_u { struct pktio_entry s; uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(struct pktio_entry))]; -} pktio_entry_t; +}; typedef struct { odp_spinlock_t lock; pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; } pktio_table_t; -typedef struct pktio_if_ops { - const char *name; - void (*print)(pktio_entry_t *pktio_entry); - int (*init_global)(void); - int (*init_local)(void); - int (*term)(void); - int (*open)(odp_pktio_t pktio, pktio_entry_t *pktio_entry, - const char *devname, odp_pool_t pool); - int (*close)(pktio_entry_t *pktio_entry); - int (*start)(pktio_entry_t *pktio_entry); - int (*stop)(pktio_entry_t *pktio_entry); - int (*stats)(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats); - int (*stats_reset)(pktio_entry_t *pktio_entry); - uint64_t (*pktin_ts_res)(pktio_entry_t *pktio_entry); - odp_time_t (*pktin_ts_from_ns)(pktio_entry_t *pktio_entry, uint64_t ns); - int (*recv)(pktio_entry_t *entry, int index, odp_packet_t packets[], - int num); - int (*send)(pktio_entry_t *entry, int index, - const odp_packet_t packets[], int num); - uint32_t (*mtu_get)(pktio_entry_t *pktio_entry); - int (*promisc_mode_set)(pktio_entry_t *pktio_entry, int enable); - int (*promisc_mode_get)(pktio_entry_t *pktio_entry); - int (*mac_get)(pktio_entry_t *pktio_entry, void *mac_addr); - int (*link_status)(pktio_entry_t *pktio_entry); - int (*capability)(pktio_entry_t *pktio_entry, - odp_pktio_capability_t *capa); - int (*config)(pktio_entry_t *pktio_entry, - const odp_pktio_config_t *config); - int (*input_queues_config)(pktio_entry_t *pktio_entry, - const odp_pktin_queue_param_t *param); - int (*output_queues_config)(pktio_entry_t *pktio_entry, - const odp_pktout_queue_param_t *p); -} pktio_if_ops_t; - extern void *pktio_entry_ptr[]; static inline int pktio_to_id(odp_pktio_t pktio) @@ -252,18 +219,6 @@ static inline void pktio_cls_enabled_set(pktio_entry_t *entry, int ena) entry->s.cls_enabled = ena; } -extern const pktio_if_ops_t netmap_pktio_ops; -extern const pktio_if_ops_t dpdk_pktio_ops; -extern const pktio_if_ops_t sock_mmsg_pktio_ops; -extern const pktio_if_ops_t sock_mmap_pktio_ops; -extern const pktio_if_ops_t loopback_pktio_ops; -#ifdef HAVE_PCAP -extern const pktio_if_ops_t pcap_pktio_ops; -#endif -extern const pktio_if_ops_t tap_pktio_ops; -extern const pktio_if_ops_t ipc_pktio_ops; -extern const pktio_if_ops_t * const pktio_if_ops[]; - int sysfs_stats(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats); int sock_stats_fd(pktio_entry_t *pktio_entry, diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h new file mode 100644 index 000000000..ff497a2ac --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -0,0 +1,81 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_SUBSYSTEM_H_ +#define ODP_PKTIO_OPS_SUBSYSTEM_H_ + +#include +#include + +/* ODP packet IO operations subsystem declaration */ +ODP_SUBSYSTEM_DECLARE(pktio_ops); + +/* Subsystem APIs declarations */ +ODP_SUBSYSTEM_API(pktio_ops, int, open, odp_pktio_t, + pktio_entry_t *, const char *, odp_pool_t); +ODP_SUBSYSTEM_API(pktio_ops, int, close, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, start, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, stop, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, stats, pktio_entry_t *, + odp_pktio_stats_t *stats); +ODP_SUBSYSTEM_API(pktio_ops, int, stats_reset, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, uint64_t, pktin_ts_res, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, odp_time_t, pktin_ts_from_ns, + pktio_entry_t *, uint64_t ns); +ODP_SUBSYSTEM_API(pktio_ops, int, recv, pktio_entry_t *, + int index, odp_packet_t packets[], int count); +ODP_SUBSYSTEM_API(pktio_ops, int, send, pktio_entry_t *, + int index, const odp_packet_t packets[], int count); +ODP_SUBSYSTEM_API(pktio_ops, uint32_t, mtu_get, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, promisc_mode_set, + pktio_entry_t *, int enable); +ODP_SUBSYSTEM_API(pktio_ops, int, promisc_mode_get, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, mac_get, pktio_entry_t *, void *); +ODP_SUBSYSTEM_API(pktio_ops, int, link_status, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, capability, pktio_entry_t *, + odp_pktio_capability_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, config, pktio_entry_t *, + const odp_pktio_config_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, input_queues_config, + pktio_entry_t *, const odp_pktin_queue_param_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, output_queues_config, + pktio_entry_t *, const odp_pktout_queue_param_t *); +ODP_SUBSYSTEM_API(pktio_ops, void, print, pktio_entry_t *); + +/* Declare subsystem init and term routines */ +ODP_SUBSYSTEM_API(pktio_ops, int, init_global, bool); +ODP_SUBSYSTEM_API(pktio_ops, int, init_local, bool); +ODP_SUBSYSTEM_API(pktio_ops, int, term_global, bool); +ODP_SUBSYSTEM_API(pktio_ops, int, term_local, bool); + +typedef ODP_MODULE_CLASS(pktio_ops) { + odp_module_base_t base; + + odp_api_proto(pktio_ops, open) open; + odp_api_proto(pktio_ops, close) close; + odp_api_proto(pktio_ops, start) start; + odp_api_proto(pktio_ops, stop) stop; + odp_api_proto(pktio_ops, stats) stats; + odp_api_proto(pktio_ops, stats_reset) stats_reset; + odp_api_proto(pktio_ops, pktin_ts_res) pktin_ts_res; + odp_api_proto(pktio_ops, pktin_ts_from_ns) pktin_ts_from_ns; + odp_api_proto(pktio_ops, recv) recv; + odp_api_proto(pktio_ops, send) send; + odp_api_proto(pktio_ops, mtu_get) mtu_get; + odp_api_proto(pktio_ops, promisc_mode_set) promisc_mode_set; + odp_api_proto(pktio_ops, promisc_mode_get) promisc_mode_get; + odp_api_proto(pktio_ops, mac_get) mac_get; + odp_api_proto(pktio_ops, link_status) link_status; + odp_api_proto(pktio_ops, capability) capability; + odp_api_proto(pktio_ops, config) config; + odp_api_proto(pktio_ops, input_queues_config) input_queues_config; + odp_api_proto(pktio_ops, output_queues_config) output_queues_config; + odp_api_proto(pktio_ops, print) print; +} pktio_ops_module_t; + +#endif diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index e78c712e4..d8dcc45da 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -51,7 +51,6 @@ int odp_pktio_init_global(void) pktio_entry_t *pktio_entry; int i; odp_shm_t shm; - int pktio_if; shm = odp_shm_reserve("odp_pktio_entries", sizeof(pktio_table_t), @@ -76,32 +75,12 @@ int odp_pktio_init_global(void) pktio_entry_ptr[i] = pktio_entry; } - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - if (pktio_if_ops[pktio_if]->init_global) - if (pktio_if_ops[pktio_if]->init_global()) { - ODP_ERR("failed to initialized pktio type %d", - pktio_if); - return -1; - } - } - - return 0; + return odp_pktio_ops_init_global(true); } int odp_pktio_init_local(void) { - int pktio_if; - - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - if (pktio_if_ops[pktio_if]->init_local) - if (pktio_if_ops[pktio_if]->init_local()) { - ODP_ERR("failed to initialized pktio type %d", - pktio_if); - return -1; - } - } - - return 0; + return odp_pktio_ops_init_local(true); } static inline int is_free(pktio_entry_t *entry) @@ -181,8 +160,7 @@ static odp_pktio_t setup_pktio_entry(const char *name, odp_pool_t pool, { odp_pktio_t hdl; pktio_entry_t *pktio_entry; - int ret = -1; - int pktio_if; + pktio_ops_module_t *mod; if (strlen(name) >= PKTIO_NAME_LEN - 1) { /* ioctl names limitation */ @@ -202,25 +180,24 @@ static odp_pktio_t setup_pktio_entry(const char *name, odp_pool_t pool, if (!pktio_entry) return ODP_PKTIO_INVALID; + pktio_entry->s.ops = NULL; /* Reset stale ops */ pktio_entry->s.pool = pool; memcpy(&pktio_entry->s.param, param, sizeof(odp_pktio_param_t)); pktio_entry->s.handle = hdl; odp_pktio_config_init(&pktio_entry->s.config); - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - ret = pktio_if_ops[pktio_if]->open(hdl, pktio_entry, name, - pool); - - if (!ret) { - pktio_entry->s.ops = pktio_if_ops[pktio_if]; - ODP_DBG("%s uses %s\n", - name, pktio_if_ops[pktio_if]->name); + odp_subsystem_lock(read, pktio_ops); + odp_subsystem_foreach_module(pktio_ops, mod) { + if (0 == mod->open(hdl, pktio_entry, name, pool)) { + pktio_entry->s.ops = mod; + ODP_DBG("%s uses %s\n", name, mod->base.name); break; } } + odp_subsystem_unlock(read, pktio_ops); - if (ret != 0) { + if (pktio_entry->s.ops == NULL) { pktio_entry->s.state = PKTIO_STATE_FREE; hdl = ODP_PKTIO_INVALID; ODP_ERR("Unable to init any I/O type.\n"); @@ -913,7 +890,7 @@ int odp_pktio_info(odp_pktio_t hdl, odp_pktio_info_t *info) memset(info, 0, sizeof(odp_pktio_info_t)); info->name = entry->s.name; - info->drv_name = entry->s.ops->name; + info->drv_name = entry->s.ops->base.name; info->pool = entry->s.pool; memcpy(&info->param, &entry->s.param, sizeof(odp_pktio_param_t)); @@ -988,7 +965,7 @@ void odp_pktio_print(odp_pktio_t hdl) len += snprintf(&str[len], n - len, " name %s\n", entry->s.name); len += snprintf(&str[len], n - len, - " type %s\n", entry->s.ops->name); + " type %s\n", entry->s.ops->base.name); len += snprintf(&str[len], n - len, " state %s\n", entry->s.state == PKTIO_STATE_STARTED ? "start" : @@ -1030,7 +1007,6 @@ int odp_pktio_term_global(void) { int ret = 0; int i; - int pktio_if; for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; ++i) { pktio_entry_t *pktio_entry; @@ -1056,12 +1032,7 @@ int odp_pktio_term_global(void) unlock_entry(pktio_entry); } - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - if (pktio_if_ops[pktio_if]->term) - if (pktio_if_ops[pktio_if]->term()) - ODP_ABORT("failed to terminate pktio type %d", - pktio_if); - } + ret = odp_pktio_ops_term_global(false); ret = odp_shm_free(odp_shm_lookup("odp_pktio_entries")); if (ret != 0) diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index 9e3e583da..e72a76371 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -1290,30 +1290,46 @@ static int dpdk_stats_reset(pktio_entry_t *pktio_entry) return 0; } -const pktio_if_ops_t dpdk_pktio_ops = { - .name = "dpdk", - .init_global = dpdk_pktio_init_global, - .init_local = dpdk_pktio_init_local, - .term = NULL, +static pktio_ops_module_t dpdk_pktio_ops = { + .base = { + .name = "dpdk", + .init_local = dpdk_pktio_init_local, + .init_global = dpdk_pktio_init_global, + .term_local = NULL, + .term_global = NULL, + }, .open = dpdk_open, .close = dpdk_close, .start = dpdk_start, .stop = dpdk_stop, .stats = dpdk_stats, .stats_reset = dpdk_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = dpdk_recv, .send = dpdk_send, - .link_status = dpdk_link_status, .mtu_get = dpdk_mtu_get, .promisc_mode_set = dpdk_promisc_mode_set, .promisc_mode_get = dpdk_promisc_mode_get, .mac_get = dpdk_mac_addr_get, + .link_status = dpdk_link_status, .capability = dpdk_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = dpdk_input_queues_config, - .output_queues_config = dpdk_output_queues_config + .output_queues_config = dpdk_output_queues_config, + .print = NULL, }; +ODP_MODULE_CONSTRUCTOR(dpdk_pktio_ops) +{ + odp_module_constructor(&dpdk_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &dpdk_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_dpdk_pktio_ops = 0; + #endif /* ODP_PKTIO_DPDK */ diff --git a/platform/linux-generic/pktio/io_ops.c b/platform/linux-generic/pktio/io_ops.c deleted file mode 100644 index fbf30ca7a..000000000 --- a/platform/linux-generic/pktio/io_ops.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include - -/* Ops for all implementation of pktio. - * Order matters. The first implementation to setup successfully - * will be picked. - * Array must be NULL terminated */ -const pktio_if_ops_t * const pktio_if_ops[] = { - &loopback_pktio_ops, -#ifdef ODP_PKTIO_DPDK - &dpdk_pktio_ops, -#endif -#ifdef ODP_NETMAP - &netmap_pktio_ops, -#endif -#ifdef HAVE_PCAP - &pcap_pktio_ops, -#endif -#ifdef _ODP_PKTIO_IPC - &ipc_pktio_ops, -#endif - &tap_pktio_ops, - &sock_mmap_pktio_ops, - &sock_mmsg_pktio_ops, - NULL -}; diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 8c7db84e6..984f0ab44 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -771,23 +771,44 @@ static int ipc_pktio_init_global(void) return 0; } -const pktio_if_ops_t ipc_pktio_ops = { - .name = "ipc", - .print = NULL, - .init_global = ipc_pktio_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t ipc_pktio_ops = { + .base = { + .name = "ipc", + .init_local = NULL, + .term_local = NULL, + .init_global = ipc_pktio_init_global, + .term_global = NULL, + }, .open = ipc_pktio_open, .close = ipc_close, - .recv = ipc_pktio_recv, - .send = ipc_pktio_send, .start = ipc_start, .stop = ipc_stop, + .stats = NULL, + .stats_reset = NULL, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, + .recv = ipc_pktio_recv, + .send = ipc_pktio_send, .mtu_get = ipc_mtu_get, .promisc_mode_set = NULL, .promisc_mode_get = NULL, .mac_get = ipc_mac_addr_get, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, - .config = NULL + .link_status = NULL, + .capability = NULL, + .config = NULL, + .input_queues_config = NULL, + .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(ipc_pktio_ops) +{ + odp_module_constructor(&ipc_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &ipc_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_ipc_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index c825393ac..3e6b41f80 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -251,18 +251,22 @@ static int loop_init_global(void) return 0; } -const pktio_if_ops_t loopback_pktio_ops = { - .name = "loop", - .print = NULL, - .init_global = loop_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t loopback_pktio_ops = { + .base = { + .name = "loop", + .init_local = NULL, + .term_local = NULL, + .init_global = loop_init_global, + .term_global = NULL, + }, .open = loopback_open, .close = loopback_close, .start = NULL, .stop = NULL, .stats = loopback_stats, .stats_reset = loopback_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = loopback_recv, .send = loopback_send, .mtu_get = loopback_mtu_get, @@ -271,9 +275,20 @@ const pktio_if_ops_t loopback_pktio_ops = { .mac_get = loopback_mac_addr_get, .link_status = loopback_link_status, .capability = loopback_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = NULL, .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(loopback_pktio_ops) +{ + odp_module_constructor(&loopback_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &loopback_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_loopback_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index 928bb00af..c75f8be97 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -943,31 +943,46 @@ static int netmap_init_global(void) return 0; } -const pktio_if_ops_t netmap_pktio_ops = { - .name = "netmap", - .print = netmap_print, - .init_global = netmap_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t netmap_pktio_ops = { + .base = { + .name = "netmap", + .init_local = NULL, + .term_local = NULL, + .init_global = netmap_init_global, + .term_global = NULL, + }, .open = netmap_open, .close = netmap_close, .start = netmap_start, .stop = netmap_stop, - .link_status = netmap_link_status, .stats = netmap_stats, .stats_reset = netmap_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, + .recv = netmap_recv, + .send = netmap_send, .mtu_get = netmap_mtu_get, .promisc_mode_set = netmap_promisc_mode_set, .promisc_mode_get = netmap_promisc_mode_get, .mac_get = netmap_mac_addr_get, + .link_status = netmap_link_status, .capability = netmap_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = netmap_input_queues_config, .output_queues_config = netmap_output_queues_config, - .recv = netmap_recv, - .send = netmap_send + .print = netmap_print, }; +ODP_MODULE_CONSTRUCTOR(netmap_pktio_ops) +{ + odp_module_constructor(&netmap_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &netmap_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_netmap_pktio_ops = 0; + #endif /* ODP_NETMAP */ diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index a467b6402..98f810898 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -423,25 +423,44 @@ static int pcapif_init_global(void) return 0; } -const pktio_if_ops_t pcap_pktio_ops = { - .name = "pcap", - .print = NULL, - .init_global = pcapif_init_global, - .init_local = NULL, +static pktio_ops_module_t pcap_pktio_ops = { + .base = { + .name = "pcap", + .init_local = NULL, + .term_local = NULL, + .init_global = pcapif_init_global, + .term_global = NULL, + }, .open = pcapif_init, .close = pcapif_close, + .start = NULL, + .stop = NULL, .stats = pcapif_stats, .stats_reset = pcapif_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = pcapif_recv_pkt, .send = pcapif_send_pkt, .mtu_get = pcapif_mtu_get, .promisc_mode_set = pcapif_promisc_mode_set, .promisc_mode_get = pcapif_promisc_mode_get, .mac_get = pcapif_mac_addr_get, + .link_status = NULL, .capability = pcapif_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = NULL, .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(pcap_pktio_ops) +{ + odp_module_constructor(&pcap_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &pcap_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_pcap_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index a383adc6a..8b8ccf033 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -853,18 +853,22 @@ static int sock_init_global(void) return 0; } -const pktio_if_ops_t sock_mmsg_pktio_ops = { - .name = "socket", - .print = NULL, - .init_global = sock_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t socket_pktio_ops = { + .base = { + .name = "socket", + .init_local = NULL, + .term_local = NULL, + .init_global = sock_init_global, + .term_global = NULL, + }, .open = sock_mmsg_open, .close = sock_close, .start = NULL, .stop = NULL, .stats = sock_stats, .stats_reset = sock_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = sock_mmsg_recv, .send = sock_mmsg_send, .mtu_get = sock_mtu_get, @@ -873,9 +877,20 @@ const pktio_if_ops_t sock_mmsg_pktio_ops = { .mac_get = sock_mac_addr_get, .link_status = sock_link_status, .capability = sock_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = NULL, .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(socket_pktio_ops) +{ + odp_module_constructor(&socket_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &socket_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_socket_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 6fc4b4ccf..82abd38db 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -710,18 +710,22 @@ static int sock_mmap_init_global(void) return 0; } -const pktio_if_ops_t sock_mmap_pktio_ops = { - .name = "socket_mmap", - .print = NULL, - .init_global = sock_mmap_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t socket_mmap_pktio_ops = { + .base = { + .name = "socket_mmap", + .init_local = NULL, + .term_local = NULL, + .init_global = sock_mmap_init_global, + .term_global = NULL, + }, .open = sock_mmap_open, .close = sock_mmap_close, .start = NULL, .stop = NULL, .stats = sock_mmap_stats, .stats_reset = sock_mmap_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = sock_mmap_recv, .send = sock_mmap_send, .mtu_get = sock_mmap_mtu_get, @@ -730,9 +734,20 @@ const pktio_if_ops_t sock_mmap_pktio_ops = { .mac_get = sock_mmap_mac_addr_get, .link_status = sock_mmap_link_status, .capability = sock_mmap_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = NULL, .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(socket_mmap_pktio_ops) +{ + odp_module_constructor(&socket_mmap_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &socket_mmap_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_socket_mmap_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/subsystem.c b/platform/linux-generic/pktio/subsystem.c new file mode 100644 index 000000000..fbcf22d77 --- /dev/null +++ b/platform/linux-generic/pktio/subsystem.c @@ -0,0 +1,58 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +#define SUBSYSTEM_VERSION 0x00010000UL +ODP_SUBSYSTEM_DEFINE(pktio_ops, "packet IO operations", SUBSYSTEM_VERSION); + +/* Instantiate init and term functions */ +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_global, ODP_ERR) +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_local, ODP_ERR) +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, term_global, ODP_ABORT) + +/* Temporary variable to enable link modules, + * will remove in Makefile scheme changes. + */ +#ifdef ODP_PKTIO_DPDK +extern int enable_link_dpdk_pktio_ops; +#endif +extern int enable_link_ipc_pktio_ops; +extern int enable_link_loopback_pktio_ops; +#ifdef ODP_NETMAP +extern int enable_link_netmap_pktio_ops; +#endif +#ifdef HAVE_PCAP +extern int enable_link_pcap_pktio_ops; +#endif +extern int enable_link_socket_pktio_ops; +extern int enable_link_socket_mmap_pktio_ops; +extern int enable_link_tap_pktio_ops; + +ODP_SUBSYSTEM_CONSTRUCTOR(pktio_ops) +{ + odp_subsystem_constructor(pktio_ops); + + /* Further initialization per subsystem */ + +#ifdef ODP_PKTIO_DPDK + enable_link_dpdk_pktio_ops = 1; +#endif + enable_link_ipc_pktio_ops = 1; + enable_link_loopback_pktio_ops = 1; +#ifdef ODP_NETMAP + enable_link_netmap_pktio_ops = 1; +#endif +#ifdef HAVE_PCAP + enable_link_pcap_pktio_ops = 1; +#endif + enable_link_socket_pktio_ops = 1; + enable_link_socket_mmap_pktio_ops = 1; + enable_link_tap_pktio_ops = 1; +} diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index 650c12a77..bfe412390 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -373,24 +373,44 @@ static int tap_capability(pktio_entry_t *pktio_entry ODP_UNUSED, return 0; } -const pktio_if_ops_t tap_pktio_ops = { - .name = "tap", - .print = NULL, - .init_global = NULL, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t tap_pktio_ops = { + .base = { + .name = "tap", + .init_local = NULL, + .term_local = NULL, + .init_global = NULL, + .term_global = NULL, + }, .open = tap_pktio_open, .close = tap_pktio_close, .start = NULL, .stop = NULL, + .stats = NULL, + .stats_reset = NULL, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = tap_pktio_recv, .send = tap_pktio_send, .mtu_get = tap_mtu_get, .promisc_mode_set = tap_promisc_mode_set, .promisc_mode_get = tap_promisc_mode_get, .mac_get = tap_mac_addr_get, + .link_status = NULL, .capability = tap_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, - .config = NULL + .config = NULL, + .input_queues_config = NULL, + .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(tap_pktio_ops) +{ + odp_module_constructor(&tap_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &tap_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_tap_pktio_ops = 0; From patchwork Wed Sep 20 09:00:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113096 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp449612edb; Wed, 20 Sep 2017 02:14:13 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAluNtoIABUQo5SJ/50+C4exlwyS1xrv7LzKv+/l8fZu3irDDCdrqlYxcNWJR6KVmPwCee2 X-Received: by 10.200.23.82 with SMTP id u18mr6520644qtk.68.1505898853115; Wed, 20 Sep 2017 02:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898853; cv=none; d=google.com; s=arc-20160816; b=Tkh2BXoMJkFDsIH5XntZpyfy4KFMCJGTwBS79B+6bOF1fmzrAZNkgisOEjlBMXu1Wh EFlolpz//eL2o7nMxtHNK+ojF516b6F9chL2as+Xh+KDNhWb67A2GDVw+/LKXj3r8nQ0 +G9QsS8SXIZwWMXrwx/12vSabDDJE3kstGzcDhfIofGQp5vOP36WVRPcisw7ZOQ/IGfk nqCk0dvssaQJ57gx5OFOm60SokAXw9s+9NnHqK1BFjz3uIeE3Prw2ReXv2MxEqeYdoME qtUZQ9ljRQei/Pbrl4wfrgHoirer9P+kQ+RksFTXfUfA8pX+e1e1RoJGDQQSAuACbqmj ySug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=Zc+QcmA/g33cU8zTxtBwbWg5uRKnWBn+T1lCRogApNs=; b=m+yTyovwrefcQ9fel476LDRSxxGPaq2IlG0xDLEiojisW54EH3cM4/cQf4DiBfcgT/ 6PvuE7BXlpxVleco7aQKYUTPGcVPsl2iLRP+JjKk5vBtu8j6l9/b4co7Ax8SZ+XZGuvJ TvXbsQwtDKKzqjRRdOYu8OWbwcJCiOqdq82daxBhm72vp4lZRUa2iymgFTpK2ZeslXfX TttZ0SUgQj4G5jP12ygH+KYJVvylIreDepKoY8iw6d/QSlICsBa5L3Tv7x+YNZTSvY++ ADdLKGgjYk1723vInCs8Bw/tdRV2CnJ+ZsGBwhqasDtDVYRnyYV8wBACXYiYGjZH4Pri /NdA== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id s28si1455991qth.411.2017.09.20.02.14.12; Wed, 20 Sep 2017 02:14:13 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id CC66C64488; Wed, 20 Sep 2017 09:14:12 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 5A83E64461; Wed, 20 Sep 2017 09:02:49 +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 F413262D7F; Wed, 20 Sep 2017 09:02:40 +0000 (UTC) Received: from forward100p.mail.yandex.net (forward100p.mail.yandex.net [77.88.28.100]) by lists.linaro.org (Postfix) with ESMTPS id EAD7962D7F for ; Wed, 20 Sep 2017 09:00:53 +0000 (UTC) Received: from mxback5g.mail.yandex.net (mxback5g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:166]) by forward100p.mail.yandex.net (Yandex) with ESMTP id 2BBF45104A87 for ; Wed, 20 Sep 2017 12:00:30 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback5g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 303YeJVKV4-0U4aDjXf; Wed, 20 Sep 2017 12:00:30 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0UNasG5H; Wed, 20 Sep 2017 12:00:30 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:08 +0300 Message-Id: <1505898014-18011-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 4/10] linux-gen: pktio: loopback: minor code refactory 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Rename the source as loopback.c, move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ platform/linux-dpdk/Makefile.am | 3 ++- platform/linux-dpdk/include/odp_packet_io_internal.h | 7 +------ platform/linux-generic/Makefile.am | 3 ++- platform/linux-generic/include/odp_packet_io_internal.h | 7 +------ platform/linux-generic/include/odp_pktio_ops_loopback.h | 17 +++++++++++++++++ .../linux-generic/include/odp_pktio_ops_subsystem.h | 13 +++++++++++++ platform/linux-generic/pktio/{loop.c => loopback.c} | 14 +++++++------- 7 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 platform/linux-generic/include/odp_pktio_ops_loopback.h rename platform/linux-generic/pktio/{loop.c => loopback.c} (94%) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 2ff44316e..9d13ec1ca 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -191,6 +191,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_loopback.h \ ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ @@ -248,7 +249,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ pktio/subsystem.c \ odp_packet_flags.c \ ../linux-generic/odp_packet_io.c \ - ../linux-generic/pktio/loop.c \ + ../linux-generic/pktio/loopback.c \ ../linux-generic/odp_pkt_queue.c \ pool/dpdk.c \ ../linux-generic/odp_queue_if.c \ diff --git a/platform/linux-dpdk/include/odp_packet_io_internal.h b/platform/linux-dpdk/include/odp_packet_io_internal.h index fde172fc5..ba388c9c2 100644 --- a/platform/linux-dpdk/include/odp_packet_io_internal.h +++ b/platform/linux-dpdk/include/odp_packet_io_internal.h @@ -43,11 +43,6 @@ typedef union pktio_entry_u pktio_entry_t; /* Forward declaration */ struct pkt_dpdk_t; -typedef struct { - odp_queue_t loopq; /**< loopback queue for "loop" device */ - odp_bool_t promisc; /**< promiscuous mode state */ -} pkt_loop_t; - /** Packet socket using dpdk mmaped rings for both Rx and Tx */ typedef struct { odp_pktio_capability_t capa; /**< interface capabilities */ @@ -67,13 +62,13 @@ typedef struct { struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ + pktio_ops_data_t ops_data; /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ union { - pkt_loop_t pkt_loop; /**< Using loopback for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK API for IO */ }; enum { diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index ad6f14450..68fc246ab 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -191,6 +191,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ + ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_queue_subsystem.h \ @@ -267,7 +268,7 @@ __LIB__libodp_linux_la_SOURCES = \ pktio/subsystem.c \ pktio/ipc.c \ pktio/pktio_common.c \ - pktio/loop.c \ + pktio/loopback.c \ pktio/netmap.c \ pktio/dpdk.c \ pktio/socket.c \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 589148400..893fa1144 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -51,11 +51,6 @@ typedef union pktio_entry_u pktio_entry_t; * requested number of packets were not handled. */ #define SOCK_ERR_REPORT(e) (e != EAGAIN && e != EWOULDBLOCK && e != EINTR) -typedef struct { - odp_queue_t loopq; /**< loopback queue for "loop" device */ - odp_bool_t promisc; /**< promiscuous mode state */ -} pkt_loop_t; - #ifdef HAVE_PCAP typedef struct { char *fname_rx; /**< name of pcap file for rx */ @@ -111,13 +106,13 @@ typedef struct { struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ + pktio_ops_data_t ops_data; /**< IO operation specific data */ /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ union { - pkt_loop_t pkt_loop; /**< Using loopback for IO */ pkt_sock_t pkt_sock; /**< using socket API for IO */ pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap * API for IO */ diff --git a/platform/linux-generic/include/odp_pktio_ops_loopback.h b/platform/linux-generic/include/odp_pktio_ops_loopback.h new file mode 100644 index 000000000..932459472 --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_loopback.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_LOOPBACK_H_ +#define ODP_PKTIO_OPS_LOOPBACK_H_ + +typedef struct { + odp_queue_t loopq; /**< loopback queue for "loop" device */ + odp_bool_t promisc; /**< promiscuous mode state */ +} pktio_ops_loopback_data_t; + +#endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index ff497a2ac..7b90ed3d3 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -78,4 +78,17 @@ typedef ODP_MODULE_CLASS(pktio_ops) { odp_api_proto(pktio_ops, print) print; } pktio_ops_module_t; +/* All implementations of this subsystem */ +#include + +/* Per implementation private data + * TODO: refactory each implementation to hide it internally + */ +typedef union { + pktio_ops_loopback_data_t loopback; +} pktio_ops_data_t; + +/* Extract pktio ops data from pktio entry structure */ +#define ops_data(mod) s.ops_data.mod + #endif diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loopback.c similarity index 94% rename from platform/linux-generic/pktio/loop.c rename to platform/linux-generic/pktio/loopback.c index 3e6b41f80..3d4c764ab 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loopback.c @@ -35,10 +35,10 @@ static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, snprintf(loopq_name, sizeof(loopq_name), "%" PRIu64 "-pktio_loopq", odp_pktio_to_u64(id)); - pktio_entry->s.pkt_loop.loopq = + pktio_entry->ops_data(loopback).loopq = odp_queue_create(loopq_name, NULL); - if (pktio_entry->s.pkt_loop.loopq == ODP_QUEUE_INVALID) + if (pktio_entry->ops_data(loopback).loopq == ODP_QUEUE_INVALID) return -1; loopback_stats_reset(pktio_entry); @@ -48,7 +48,7 @@ static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, static int loopback_close(pktio_entry_t *pktio_entry) { - return odp_queue_destroy(pktio_entry->s.pkt_loop.loopq); + return odp_queue_destroy(pktio_entry->ops_data(loopback).loopq); } static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, @@ -70,7 +70,7 @@ static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_ticketlock_lock(&pktio_entry->s.rxl); - queue = queue_fn->from_ext(pktio_entry->s.pkt_loop.loopq); + queue = queue_fn->from_ext(pktio_entry->ops_data(loopback).loopq); nbr = queue_fn->deq_multi(queue, hdr_tbl, len); if (pktio_entry->s.config.pktin.bit.ts_all || @@ -170,7 +170,7 @@ static int loopback_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_ticketlock_lock(&pktio_entry->s.txl); - queue = queue_fn->from_ext(pktio_entry->s.pkt_loop.loopq); + queue = queue_fn->from_ext(pktio_entry->ops_data(loopback).loopq); ret = queue_fn->enq_multi(queue, hdr_tbl, len); if (ret > 0) { @@ -223,13 +223,13 @@ static int loopback_capability(pktio_entry_t *pktio_entry ODP_UNUSED, static int loopback_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - pktio_entry->s.pkt_loop.promisc = enable; + pktio_entry->ops_data(loopback).promisc = enable; return 0; } static int loopback_promisc_mode_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_loop.promisc ? 1 : 0; + return pktio_entry->ops_data(loopback).promisc ? 1 : 0; } static int loopback_stats(pktio_entry_t *pktio_entry, From patchwork Wed Sep 20 09:00:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113093 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp444112edb; Wed, 20 Sep 2017 02:07:18 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDxIzeH57uIqLTxzHyxXXAfrcVaQ0Aiu5IaGqC6eBLkbqdtNNAC9mmQ7YrDg8reWX8MKnDU X-Received: by 10.200.52.173 with SMTP id w42mr6481124qtb.67.1505898438416; Wed, 20 Sep 2017 02:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898438; cv=none; d=google.com; s=arc-20160816; b=EefjIQKCUy3y/AfXX42CA3+R+/DqbBbcgCEi0PFPKai2TqSTtOcaOoHvt2rW3DmNTm heGGNeYkiyiSBule61r8teMD7ks2vexwCLch7msrcpOK1z+uZREgTbJ+KfN8SMgb923C Q3wbmvhKeSxm9Hxmf8TtCzwkBCGavvKGRxlwaHkiyJRE23tlMigqxySnss1xaRN4hDNf jSrn0K9bSsS4qCP5TCaNb2LAE98gqrHxp8AmWnCqXQInCfdQC2Bb7Cl0oiZJJn+TrU1F YGdm5Bw+1yruMWU6X4cKsH0aFzRj+TzxvOz1GJZic3sDPKzZHh51tjwB4bPeQa1OvY+A Oi8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=KAgMVe5AUZmNnryLXASRWLV4A9xSHmNxbygZdh8ihSc=; b=zg3peBTV72PCyTEJjer7zu8O6X9o9l8mwBFhXmh3MLjSYe1p49DHilsB56TKzopvCs RCglB03HodE3lHeo8DvUyB1Nn6SXoYvyXY2Dn9vUreXsYW9sro6UeprW+uUkyvVhkYAv 6jc5tj3jiYcC3QnIKsCHu6o7bukQ4OAMLt0f2Q5lmWVNm0AZhJPhinj9lXaPvgAVOP0L oz2QCA2hoyMRvQxXUnRnkAV7MbTFE6cz1fKxMrE39eM8cu49wr5lJkzEj9Twh7SVgwET W5im43Ksc0h1kDyPgRFeSn4g/AtPAa/RS++1xBY+LlK+rR4RthCvGn+v5zOtkUZDj85B hayQ== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n42si1426257qtc.308.2017.09.20.02.07.17; Wed, 20 Sep 2017 02:07:18 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id C659562ED2; Wed, 20 Sep 2017 09:07:17 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 5B31E62F1C; Wed, 20 Sep 2017 09:01:48 +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 94CF360BDB; Wed, 20 Sep 2017 09:01:43 +0000 (UTC) Received: from forward100o.mail.yandex.net (forward100o.mail.yandex.net [37.140.190.180]) by lists.linaro.org (Postfix) with ESMTPS id 57E3F607C8 for ; Wed, 20 Sep 2017 09:00:40 +0000 (UTC) Received: from mxback1g.mail.yandex.net (mxback1g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:162]) by forward100o.mail.yandex.net (Yandex) with ESMTP id 01FD52A20891 for ; Wed, 20 Sep 2017 12:00:39 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id POB4IvqwJJ-0WQmRCdB; Wed, 20 Sep 2017 12:00:32 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0VNu4mrR; Wed, 20 Sep 2017 12:00:31 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:09 +0300 Message-Id: <1505898014-18011-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 5/10] linux-gen: pktio: ipc: minor code refactory 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ platform/linux-dpdk/Makefile.am | 2 +- platform/linux-generic/Makefile.am | 2 +- .../linux-generic/include/odp_packet_io_internal.h | 39 ----- .../include/odp_packet_io_ipc_internal.h | 48 ------ platform/linux-generic/include/odp_pktio_ops_ipc.h | 91 ++++++++++ .../include/odp_pktio_ops_subsystem.h | 2 + platform/linux-generic/odp_packet_io.c | 1 - platform/linux-generic/pktio/ipc.c | 185 +++++++++++---------- 8 files changed, 190 insertions(+), 180 deletions(-) delete mode 100644 platform/linux-generic/include/odp_packet_io_ipc_internal.h create mode 100644 platform/linux-generic/include/odp_pktio_ops_ipc.h diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 9d13ec1ca..15c9fb446 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -190,12 +190,12 @@ noinst_HEADERS = \ ${top_srcdir}/platform/linux-generic/include/odp_internal.h \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_internal.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_ipc.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_loopback.h \ ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ - ${top_srcdir}/platform/linux-generic/include/odp_packet_io_ipc_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_packet_io_ring_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_packet_socket.h \ ${top_srcdir}/platform/linux-generic/include/odp_pkt_queue_internal.h \ diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 68fc246ab..5c4d02a3d 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -185,12 +185,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ - ${srcdir}/include/odp_packet_io_ipc_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ ${srcdir}/include/odp_packet_netmap.h \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ + ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 893fa1144..8d3c3ddff 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -66,44 +66,6 @@ typedef struct { } pkt_pcap_t; #endif -typedef struct { - /* TX */ - struct { - _ring_t *send; /**< ODP ring for IPC msg packets - indexes transmitted to shared - memory */ - _ring_t *free; /**< ODP ring for IPC msg packets - indexes already processed by remote - process */ - } tx; - /* RX */ - struct { - _ring_t *recv; /**< ODP ring for IPC msg packets - indexes received from shared - memory (from remote process) */ - _ring_t *free; /**< odp ring for ipc msg packets - indexes already processed by - current process */ - _ring_t *cache; /**< local cache to keep packet order right */ - } rx; /* slave */ - void *pool_base; /**< Remote pool base addr */ - void *pool_mdata_base; /**< Remote pool mdata base addr */ - uint64_t pkt_size; /**< Packet size in remote pool */ - odp_pool_t pool; /**< Pool of main process */ - enum { - PKTIO_TYPE_IPC_MASTER = 0, /**< Master is the process which - creates shm */ - PKTIO_TYPE_IPC_SLAVE /**< Slave is the process which - connects to shm */ - } type; /**< define if it's master or slave process */ - odp_atomic_u32_t ready; /**< 1 - pktio is ready and can recv/send - packet, 0 - not yet ready */ - void *pinfo; - odp_shm_t pinfo_shm; - odp_shm_t remote_pool_shm; /**< shm of remote pool get with - _ipc_map_remote_pool() */ -} _ipc_pktio_t; - struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ pktio_ops_data_t ops_data; /**< IO operation specific data */ @@ -122,7 +84,6 @@ struct pktio_entry { pkt_pcap_t pkt_pcap; /**< Using pcap for IO */ #endif pkt_tap_t pkt_tap; /**< using TAP for IO */ - _ipc_pktio_t ipc; /**< IPC pktio data */ }; enum { /* Not allocated */ diff --git a/platform/linux-generic/include/odp_packet_io_ipc_internal.h b/platform/linux-generic/include/odp_packet_io_ipc_internal.h deleted file mode 100644 index 9d8943a6c..000000000 --- a/platform/linux-generic/include/odp_packet_io_ipc_internal.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -/* IPC packet I/O over shared memory ring */ -#include - -/* number of odp buffers in odp ring queue */ -#define PKTIO_IPC_ENTRIES 4096 - -/* that struct is exported to shared memory, so that processes can find - * each other. - */ -struct pktio_info { - struct { - /* number of buffer*/ - int num; - /* size of packet/segment in remote pool */ - uint32_t block_size; - char pool_name[ODP_POOL_NAME_LEN]; - /* 1 if master finished creation of all shared objects */ - int init_done; - } master; - struct { - void *base_addr; - uint32_t block_size; - char pool_name[ODP_POOL_NAME_LEN]; - /* pid of the slave process written to shm and - * used by master to look up memory created by - * slave - */ - int pid; - int init_done; - } slave; -} ODP_PACKED; diff --git a/platform/linux-generic/include/odp_pktio_ops_ipc.h b/platform/linux-generic/include/odp_pktio_ops_ipc.h new file mode 100644 index 000000000..5903ef9b8 --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_ipc.h @@ -0,0 +1,91 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_IPC_H_ +#define ODP_PKTIO_OPS_IPC_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/* IPC packet I/O over shared memory ring */ +#include + +/* number of odp buffers in odp ring queue */ +#define PKTIO_IPC_ENTRIES 4096 + +/* that struct is exported to shared memory, so that processes can find + * each other. + */ +struct pktio_info { + struct { + /* number of buffer*/ + int num; + /* size of packet/segment in remote pool */ + uint32_t block_size; + char pool_name[ODP_POOL_NAME_LEN]; + /* 1 if master finished creation of all shared objects */ + int init_done; + } master; + struct { + void *base_addr; + uint32_t block_size; + char pool_name[ODP_POOL_NAME_LEN]; + /* pid of the slave process written to shm and + * used by master to look up memory created by + * slave + */ + int pid; + int init_done; + } slave; +} ODP_PACKED; + +typedef struct { + /* TX */ + struct { + _ring_t *send; /**< ODP ring for IPC msg packets + indexes transmitted to shared + memory */ + _ring_t *free; /**< ODP ring for IPC msg packets + indexes already processed by remote + process */ + } tx; + /* RX */ + struct { + _ring_t *recv; /**< ODP ring for IPC msg packets + indexes received from shared + memory (from remote process) */ + _ring_t *free; /**< odp ring for ipc msg packets + indexes already processed by + current process */ + _ring_t *cache; /**< local cache to keep packet order right */ + } rx; /* slave */ + void *pool_base; /**< Remote pool base addr */ + void *pool_mdata_base; /**< Remote pool mdata base addr */ + uint64_t pkt_size; /**< Packet size in remote pool */ + odp_pool_t pool; /**< Pool of main process */ + enum { + PKTIO_TYPE_IPC_MASTER = 0, /**< Master is the process which + creates shm */ + PKTIO_TYPE_IPC_SLAVE /**< Slave is the process which + connects to shm */ + } type; /**< define if it's master or slave process */ + odp_atomic_u32_t ready; /**< 1 - pktio is ready and can recv/send + packet, 0 - not yet ready */ + void *pinfo; + odp_shm_t pinfo_shm; + odp_shm_t remote_pool_shm; /**< shm of remote pool get with + _ipc_map_remote_pool() */ +} pktio_ops_ipc_data_t; + +#endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 7b90ed3d3..650b36648 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -79,12 +79,14 @@ typedef ODP_MODULE_CLASS(pktio_ops) { } pktio_ops_module_t; /* All implementations of this subsystem */ +#include #include /* Per implementation private data * TODO: refactory each implementation to hide it internally */ typedef union { + pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; } pktio_ops_data_t; diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index d8dcc45da..6a19394a5 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 984f0ab44..14cd86eb7 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -3,7 +3,6 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -#include #include #include #include @@ -43,7 +42,7 @@ static const char *_ipc_odp_buffer_pool_shm_name(odp_pool_t pool_hdl) static int _ipc_master_start(pktio_entry_t *pktio_entry) { - struct pktio_info *pinfo = pktio_entry->s.ipc.pinfo; + struct pktio_info *pinfo = pktio_entry->ops_data(ipc).pinfo; odp_shm_t shm; if (pinfo->slave.init_done == 0) @@ -57,11 +56,11 @@ static int _ipc_master_start(pktio_entry_t *pktio_entry) return -1; } - pktio_entry->s.ipc.remote_pool_shm = shm; - pktio_entry->s.ipc.pool_base = odp_shm_addr(shm); - pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm); + pktio_entry->ops_data(ipc).remote_pool_shm = shm; + pktio_entry->ops_data(ipc).pool_base = odp_shm_addr(shm); + pktio_entry->ops_data(ipc).pool_mdata_base = (char *)odp_shm_addr(shm); - odp_atomic_store_u32(&pktio_entry->s.ipc.ready, 1); + odp_atomic_store_u32(&pktio_entry->ops_data(ipc).ready, 1); IPC_ODP_DBG("%s started.\n", pktio_entry->s.name); return 0; @@ -88,62 +87,62 @@ static int _ipc_init_master(pktio_entry_t *pktio_entry, * to be processed packets ring. */ snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_prod", dev); - pktio_entry->s.ipc.tx.send = _ring_create(ipc_shm_name, + pktio_entry->ops_data(ipc).tx.send = _ring_create(ipc_shm_name, PKTIO_IPC_ENTRIES, _RING_SHM_PROC | _RING_NO_LIST); - if (!pktio_entry->s.ipc.tx.send) { + if (!pktio_entry->ops_data(ipc).tx.send) { ODP_ERR("pid %d unable to create ipc ring %s name\n", getpid(), ipc_shm_name); return -1; } ODP_DBG("Created IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.tx.send), - _ring_free_count(pktio_entry->s.ipc.tx.send)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).tx.send), + _ring_free_count(pktio_entry->ops_data(ipc).tx.send)); /* generate name in shm like ipc_pktio_p for * already processed packets */ snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_cons", dev); - pktio_entry->s.ipc.tx.free = _ring_create(ipc_shm_name, + pktio_entry->ops_data(ipc).tx.free = _ring_create(ipc_shm_name, PKTIO_IPC_ENTRIES, _RING_SHM_PROC | _RING_NO_LIST); - if (!pktio_entry->s.ipc.tx.free) { + if (!pktio_entry->ops_data(ipc).tx.free) { ODP_ERR("pid %d unable to create ipc ring %s name\n", getpid(), ipc_shm_name); goto free_m_prod; } ODP_DBG("Created IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.tx.free), - _ring_free_count(pktio_entry->s.ipc.tx.free)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).tx.free), + _ring_free_count(pktio_entry->ops_data(ipc).tx.free)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_prod", dev); - pktio_entry->s.ipc.rx.recv = _ring_create(ipc_shm_name, + pktio_entry->ops_data(ipc).rx.recv = _ring_create(ipc_shm_name, PKTIO_IPC_ENTRIES, _RING_SHM_PROC | _RING_NO_LIST); - if (!pktio_entry->s.ipc.rx.recv) { + if (!pktio_entry->ops_data(ipc).rx.recv) { ODP_ERR("pid %d unable to create ipc ring %s name\n", getpid(), ipc_shm_name); goto free_m_cons; } ODP_DBG("Created IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.rx.recv), - _ring_free_count(pktio_entry->s.ipc.rx.recv)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).rx.recv), + _ring_free_count(pktio_entry->ops_data(ipc).rx.recv)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", dev); - pktio_entry->s.ipc.rx.free = _ring_create(ipc_shm_name, + pktio_entry->ops_data(ipc).rx.free = _ring_create(ipc_shm_name, PKTIO_IPC_ENTRIES, _RING_SHM_PROC | _RING_NO_LIST); - if (!pktio_entry->s.ipc.rx.free) { + if (!pktio_entry->ops_data(ipc).rx.free) { ODP_ERR("pid %d unable to create ipc ring %s name\n", getpid(), ipc_shm_name); goto free_s_prod; } ODP_DBG("Created IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.rx.free), - _ring_free_count(pktio_entry->s.ipc.rx.free)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).rx.free), + _ring_free_count(pktio_entry->ops_data(ipc).rx.free)); /* Set up pool name for remote info */ - pinfo = pktio_entry->s.ipc.pinfo; + pinfo = pktio_entry->ops_data(ipc).pinfo; pool_name = _ipc_odp_buffer_pool_shm_name(pool_hdl); if (strlen(pool_name) > ODP_POOL_NAME_LEN) { ODP_ERR("pid %d ipc pool name %s is too big %d\n", @@ -156,7 +155,7 @@ static int _ipc_init_master(pktio_entry_t *pktio_entry, pinfo->slave.pid = 0; pinfo->slave.init_done = 0; - pktio_entry->s.ipc.pool = pool_hdl; + pktio_entry->ops_data(ipc).pool = pool_hdl; ODP_DBG("Pre init... DONE.\n"); pinfo->master.init_done = 1; @@ -225,7 +224,7 @@ static int _ipc_init_slave(const char *dev, if (strlen(dev) > (ODP_POOL_NAME_LEN - sizeof("_slave_r"))) ODP_ABORT("too big ipc name\n"); - pktio_entry->s.ipc.pool = pool; + pktio_entry->ops_data(ipc).pool = pool; return 0; } @@ -246,61 +245,61 @@ static int _ipc_slave_start(pktio_entry_t *pktio_entry) sprintf(dev, "ipc:%s", tail); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_prod", dev); - pktio_entry->s.ipc.rx.recv = _ipc_shm_map(ipc_shm_name, pid); - if (!pktio_entry->s.ipc.rx.recv) { + pktio_entry->ops_data(ipc).rx.recv = _ipc_shm_map(ipc_shm_name, pid); + if (!pktio_entry->ops_data(ipc).rx.recv) { ODP_DBG("pid %d unable to find ipc ring %s name\n", getpid(), dev); sleep(1); return -1; } ODP_DBG("Connected IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.rx.recv), - _ring_free_count(pktio_entry->s.ipc.rx.recv)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).rx.recv), + _ring_free_count(pktio_entry->ops_data(ipc).rx.recv)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_cons", dev); - pktio_entry->s.ipc.rx.free = _ipc_shm_map(ipc_shm_name, pid); - if (!pktio_entry->s.ipc.rx.free) { + pktio_entry->ops_data(ipc).rx.free = _ipc_shm_map(ipc_shm_name, pid); + if (!pktio_entry->ops_data(ipc).rx.free) { ODP_ERR("pid %d unable to find ipc ring %s name\n", getpid(), dev); goto free_m_prod; } ODP_DBG("Connected IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.rx.free), - _ring_free_count(pktio_entry->s.ipc.rx.free)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).rx.free), + _ring_free_count(pktio_entry->ops_data(ipc).rx.free)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_prod", dev); - pktio_entry->s.ipc.tx.send = _ipc_shm_map(ipc_shm_name, pid); - if (!pktio_entry->s.ipc.tx.send) { + pktio_entry->ops_data(ipc).tx.send = _ipc_shm_map(ipc_shm_name, pid); + if (!pktio_entry->ops_data(ipc).tx.send) { ODP_ERR("pid %d unable to find ipc ring %s name\n", getpid(), dev); goto free_m_cons; } ODP_DBG("Connected IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.tx.send), - _ring_free_count(pktio_entry->s.ipc.tx.send)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).tx.send), + _ring_free_count(pktio_entry->ops_data(ipc).tx.send)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", dev); - pktio_entry->s.ipc.tx.free = _ipc_shm_map(ipc_shm_name, pid); - if (!pktio_entry->s.ipc.tx.free) { + pktio_entry->ops_data(ipc).tx.free = _ipc_shm_map(ipc_shm_name, pid); + if (!pktio_entry->ops_data(ipc).tx.free) { ODP_ERR("pid %d unable to find ipc ring %s name\n", getpid(), dev); goto free_s_prod; } ODP_DBG("Connected IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.tx.free), - _ring_free_count(pktio_entry->s.ipc.tx.free)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).tx.free), + _ring_free_count(pktio_entry->ops_data(ipc).tx.free)); /* Get info about remote pool */ - pinfo = pktio_entry->s.ipc.pinfo; + pinfo = pktio_entry->ops_data(ipc).pinfo; shm = _ipc_map_remote_pool(pinfo->master.pool_name, pid); - pktio_entry->s.ipc.remote_pool_shm = shm; - pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm); - pktio_entry->s.ipc.pkt_size = pinfo->master.block_size; + pktio_entry->ops_data(ipc).remote_pool_shm = shm; + pktio_entry->ops_data(ipc).pool_mdata_base = (char *)odp_shm_addr(shm); + pktio_entry->ops_data(ipc).pkt_size = pinfo->master.block_size; - _ipc_export_pool(pinfo, pktio_entry->s.ipc.pool); + _ipc_export_pool(pinfo, pktio_entry->ops_data(ipc).pool); - odp_atomic_store_u32(&pktio_entry->s.ipc.ready, 1); + odp_atomic_store_u32(&pktio_entry->ops_data(ipc).ready, 1); pinfo->slave.init_done = 1; ODP_DBG("%s started.\n", pktio_entry->s.name); @@ -339,15 +338,15 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, if (strncmp(dev, "ipc", 3)) return -1; - odp_atomic_init_u32(&pktio_entry->s.ipc.ready, 0); + odp_atomic_init_u32(&pktio_entry->ops_data(ipc).ready, 0); - pktio_entry->s.ipc.rx.cache = _ring_create("ipc_rx_cache", + pktio_entry->ops_data(ipc).rx.cache = _ring_create("ipc_rx_cache", PKTIO_IPC_ENTRIES, _RING_NO_LIST); /* Shared info about remote pktio */ if (sscanf(dev, "ipc:%d:%s", &pid, tail) == 2) { - pktio_entry->s.ipc.type = PKTIO_TYPE_IPC_SLAVE; + pktio_entry->ops_data(ipc).type = PKTIO_TYPE_IPC_SLAVE; snprintf(name, sizeof(name), "ipc:%s_info", tail); IPC_ODP_DBG("lookup for name %s for pid %d\n", name, pid); @@ -360,12 +359,12 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, odp_shm_free(shm); return -1; } - pktio_entry->s.ipc.pinfo = pinfo; - pktio_entry->s.ipc.pinfo_shm = shm; + pktio_entry->ops_data(ipc).pinfo = pinfo; + pktio_entry->ops_data(ipc).pinfo_shm = shm; ODP_DBG("process %d is slave\n", getpid()); ret = _ipc_init_slave(name, pktio_entry, pool); } else { - pktio_entry->s.ipc.type = PKTIO_TYPE_IPC_MASTER; + pktio_entry->ops_data(ipc).type = PKTIO_TYPE_IPC_MASTER; snprintf(name, sizeof(name), "%s_info", dev); shm = odp_shm_reserve(name, sizeof(struct pktio_info), ODP_CACHE_LINE_SIZE, @@ -378,8 +377,8 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, pinfo = odp_shm_addr(shm); pinfo->master.init_done = 0; pinfo->master.pool_name[0] = 0; - pktio_entry->s.ipc.pinfo = pinfo; - pktio_entry->s.ipc.pinfo_shm = shm; + pktio_entry->ops_data(ipc).pinfo = pinfo; + pktio_entry->ops_data(ipc).pinfo_shm = shm; ODP_DBG("process %d is master\n", getpid()); ret = _ipc_init_master(pktio_entry, dev, pool); } @@ -399,7 +398,7 @@ static void _ipc_free_ring_packets(pktio_entry_t *pktio_entry, _ring_t *r) if (!r) return; - pool = pool_entry_from_hdl(pktio_entry->s.ipc.pool); + pool = pool_entry_from_hdl(pktio_entry->ops_data(ipc).pool); addr = odp_shm_addr(pool->shm); rbuf_p = (void *)&offsets; @@ -433,16 +432,16 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, uint32_t ready; int pkts_ring; - ready = odp_atomic_load_u32(&pktio_entry->s.ipc.ready); + ready = odp_atomic_load_u32(&pktio_entry->ops_data(ipc).ready); if (odp_unlikely(!ready)) { IPC_ODP_DBG("start pktio is missing before usage?\n"); return 0; } - _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.free); + _ipc_free_ring_packets(pktio_entry, pktio_entry->ops_data(ipc).tx.free); /* rx from cache */ - r = pktio_entry->s.ipc.rx.cache; + r = pktio_entry->ops_data(ipc).rx.cache; pkts = _ring_mc_dequeue_burst(r, ipcbufs_p, len); if (odp_unlikely(pkts < 0)) ODP_ABORT("internal error dequeue\n"); @@ -450,7 +449,7 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, /* rx from other app */ if (pkts == 0) { ipcbufs_p = (void *)&offsets[0]; - r = pktio_entry->s.ipc.rx.recv; + r = pktio_entry->ops_data(ipc).rx.recv; pkts = _ring_mc_dequeue_burst(r, ipcbufs_p, len); if (odp_unlikely(pkts < 0)) ODP_ABORT("internal error dequeue\n"); @@ -468,10 +467,10 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, uint64_t data_pool_off; void *rmt_data_ptr; - phdr = (void *)((uint8_t *)pktio_entry->s.ipc.pool_mdata_base + - offsets[i]); + phdr = (void *)((uint8_t *)pktio_entry-> + ops_data(ipc).pool_mdata_base + offsets[i]); - pool = pktio_entry->s.ipc.pool; + pool = pktio_entry->ops_data(ipc).pool; if (odp_unlikely(pool == ODP_POOL_INVALID)) ODP_ABORT("invalid pool"); @@ -496,11 +495,11 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, if (odp_unlikely(!pkt_data)) ODP_ABORT("unable to map pkt_data ipc_slave %d\n", (PKTIO_TYPE_IPC_SLAVE == - pktio_entry->s.ipc.type)); + pktio_entry->ops_data(ipc).type)); /* Copy packet data from shared pool to local pool. */ - rmt_data_ptr = (uint8_t *)pktio_entry->s.ipc.pool_mdata_base + - data_pool_off; + rmt_data_ptr = (uint8_t *)pktio_entry-> + ops_data(ipc).pool_mdata_base + data_pool_off; memcpy(pkt_data, rmt_data_ptr, phdr->frame_len); /* Copy packets L2, L3 parsed offsets and size */ @@ -519,7 +518,7 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, /* put back to rx ring dequed but not processed packets*/ if (pkts != i) { ipcbufs_p = (void *)&offsets[i]; - r_p = pktio_entry->s.ipc.rx.cache; + r_p = pktio_entry->ops_data(ipc).rx.cache; pkts_ring = _ring_mp_enqueue_burst(r_p, ipcbufs_p, pkts - i); if (pkts_ring != (pkts - i)) @@ -534,7 +533,7 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, pkts = i; /* Now tell other process that we no longer need that buffers.*/ - r_p = pktio_entry->s.ipc.rx.free; + r_p = pktio_entry->ops_data(ipc).rx.free; repeat: @@ -582,7 +581,7 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, void **rbuf_p; int ret; int i; - uint32_t ready = odp_atomic_load_u32(&pktio_entry->s.ipc.ready); + uint32_t ready = odp_atomic_load_u32(&pktio_entry->ops_data(ipc).ready); odp_packet_t pkt_table_mapped[len]; /**< Ready to send packet has to be * in memory mapped pool. */ uintptr_t offsets[len]; @@ -590,14 +589,15 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, if (odp_unlikely(!ready)) return 0; - _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.free); + _ipc_free_ring_packets(pktio_entry, pktio_entry->ops_data(ipc).tx.free); /* Copy packets to shm shared pool if they are in different * pool, or if they are references (we can't share across IPC). */ for (i = 0; i < len; i++) { odp_packet_t pkt = pkt_table[i]; - pool_t *ipc_pool = pool_entry_from_hdl(pktio_entry->s.ipc.pool); + pool_t *ipc_pool = pool_entry_from_hdl( + pktio_entry->ops_data(ipc).pool); odp_packet_hdr_t *pkt_hdr; pool_t *pool; @@ -608,7 +608,8 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, odp_packet_has_ref(pkt)) { odp_packet_t newpkt; - newpkt = odp_packet_copy(pkt, pktio_entry->s.ipc.pool); + newpkt = odp_packet_copy( + pkt, pktio_entry->ops_data(ipc).pool); if (newpkt == ODP_PACKET_INVALID) ODP_ABORT("Unable to copy packet\n"); @@ -640,18 +641,19 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, odp_packet_to_u64(pkt), odp_pool_to_u64(pool_hdl), pkt_hdr, pkt_hdr->buf_hdr.ipc_data_offset, offsets[i], odp_shm_addr(pool->shm), - odp_shm_addr(pool_entry_from_hdl( - pktio_entry->s.ipc.pool)->shm)); + odp_shm_addr(pool_entry_from_hdl(pktio_entry-> + ops_data(ipc).pool)->shm)); } /* Put packets to ring to be processed by other process. */ rbuf_p = (void *)&offsets[0]; - r = pktio_entry->s.ipc.tx.send; + r = pktio_entry->ops_data(ipc).tx.send; ret = _ring_mp_enqueue_burst(r, rbuf_p, len); if (odp_unlikely(ret < 0)) { ODP_ERR("pid %d odp_ring_mp_enqueue_bulk fail, ipc_slave %d, ret %d\n", getpid(), - (PKTIO_TYPE_IPC_SLAVE == pktio_entry->s.ipc.type), + (PKTIO_TYPE_IPC_SLAVE == + pktio_entry->ops_data(ipc).type), ret); ODP_ERR("odp_ring_full: %d, odp_ring_count %d, _ring_free_count %d\n", _ring_full(r), _ring_count(r), @@ -691,14 +693,15 @@ static int ipc_mac_addr_get(pktio_entry_t *pktio_entry ODP_UNUSED, static int ipc_start(pktio_entry_t *pktio_entry) { - uint32_t ready = odp_atomic_load_u32(&pktio_entry->s.ipc.ready); + uint32_t ready = odp_atomic_load_u32( + &pktio_entry->ops_data(ipc).ready); if (ready) { ODP_ABORT("%s Already started\n", pktio_entry->s.name); return -1; } - if (pktio_entry->s.ipc.type == PKTIO_TYPE_IPC_MASTER) + if (pktio_entry->ops_data(ipc).type == PKTIO_TYPE_IPC_MASTER) return _ipc_master_start(pktio_entry); else return _ipc_slave_start(pktio_entry); @@ -708,20 +711,22 @@ static int ipc_stop(pktio_entry_t *pktio_entry) { unsigned tx_send = 0, tx_free = 0; - odp_atomic_store_u32(&pktio_entry->s.ipc.ready, 0); + odp_atomic_store_u32(&pktio_entry->ops_data(ipc).ready, 0); - if (pktio_entry->s.ipc.tx.send) - _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.send); + if (pktio_entry->ops_data(ipc).tx.send) + _ipc_free_ring_packets(pktio_entry, + pktio_entry->ops_data(ipc).tx.send); /* other process can transfer packets from one ring to * other, use delay here to free that packets. */ sleep(1); - if (pktio_entry->s.ipc.tx.free) - _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.free); - - if (pktio_entry->s.ipc.tx.send) - tx_send = _ring_count(pktio_entry->s.ipc.tx.send); - if (pktio_entry->s.ipc.tx.free) - tx_free = _ring_count(pktio_entry->s.ipc.tx.free); + if (pktio_entry->ops_data(ipc).tx.free) + _ipc_free_ring_packets(pktio_entry, + pktio_entry->ops_data(ipc).tx.free); + + if (pktio_entry->ops_data(ipc).tx.send) + tx_send = _ring_count(pktio_entry->ops_data(ipc).tx.send); + if (pktio_entry->ops_data(ipc).tx.free) + tx_free = _ring_count(pktio_entry->ops_data(ipc).tx.free); if (tx_send | tx_free) { ODP_DBG("IPC rings: tx send %d tx free %d\n", tx_send, tx_free); @@ -740,7 +745,7 @@ static int ipc_close(pktio_entry_t *pktio_entry) ipc_stop(pktio_entry); - odp_shm_free(pktio_entry->s.ipc.remote_pool_shm); + odp_shm_free(pktio_entry->ops_data(ipc).remote_pool_shm); if (sscanf(dev, "ipc:%d:%s", &pid, tail) == 2) snprintf(name, sizeof(name), "ipc:%s", tail); @@ -748,7 +753,7 @@ static int ipc_close(pktio_entry_t *pktio_entry) snprintf(name, sizeof(name), "%s", dev); /* unlink this pktio info for both master and slave */ - odp_shm_free(pktio_entry->s.ipc.pinfo_shm); + odp_shm_free(pktio_entry->ops_data(ipc).pinfo_shm); /* destroy rings */ snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", name); From patchwork Wed Sep 20 09:00:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113094 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp446593edb; Wed, 20 Sep 2017 02:10:19 -0700 (PDT) X-Google-Smtp-Source: AOwi7QD51eRVD0z7VKlBY5z8yrU0YB91VC5+sirUcsCN2Cc5Lq1syw2D4TV4hH6jifF82d21vHpE X-Received: by 10.107.147.196 with SMTP id v187mr5837036iod.92.1505898619218; Wed, 20 Sep 2017 02:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898619; cv=none; d=google.com; s=arc-20160816; b=tfQYcF7HfrRLj8zZ3CaZc1BO0hJwcQufvsjjXPDw8cb41/3/PzdVJpwesTjzTmz1xs a69TqK/lrai2UW/P5oIDPyb3WJSqyfm4P5onEosZwiD7HKOjQYwmUwo319Z+hmY/8XEa a47YTi6qwdirLC3FsOP9zYuoP8nXA5eJDd42PNveOQNNFbrux27AkB2GPOfcw69tFtcO cMd1LlmJo9vKam6F/Gwp6kD/Wt/PJMm3o+X693vuoPABr8TSZKJt4e862EIrPZiigce3 qtdtPGnCnGiz9UCXhvMVLdPbbbRiBCi/irxZHsGF07E0I/NrELr1XhA9Z7Nej4cuztbC MQKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=BDNBGJdDXj74X2nsUs7pS2zNd257HE/QadsAqe9jq/I=; b=zqf7p7aiSuOviPcBys6jtyoLZduRR+I4WABDDtuKzvwDwfb/Kz2ai4fJbNUOUyZT6m HWDZNhrNcfYbjzL6KHC3Wh+LDzGPzUeat5d5kE7XF+q1FOnolZN9VZVFgb55dDG15G2y Tq7hwH+csq7SvElp4fg2fXooHBDLu//25Vv7EDa8BqNBJEgtiwFJyZjqOSpGAA0Ph9bZ qahiBvOfUUiebkSd1FWvBN6x5bIoYp5K05XO3MofgD8S0RcEe2E4OiYcwQN3hwXDqmcs ErMzM+ThWcxYIe0Zw8YUWiBi4Ka6TLPXVt/vT6Vy/6QQz8sVj8yHbCCJxw583VtvMF6W ek7g== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l75si1112121ioe.135.2017.09.20.02.10.18; Wed, 20 Sep 2017 02:10:19 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id A91CC64483; Wed, 20 Sep 2017 09:10:18 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 2025560D7F; Wed, 20 Sep 2017 09:02:22 +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 4AC7A636AA; Wed, 20 Sep 2017 09:02:12 +0000 (UTC) Received: from forward101p.mail.yandex.net (forward101p.mail.yandex.net [77.88.28.101]) by lists.linaro.org (Postfix) with ESMTPS id 4294E60D1F for ; Wed, 20 Sep 2017 09:00:45 +0000 (UTC) Received: from mxback16j.mail.yandex.net (mxback16j.mail.yandex.net [IPv6:2a02:6b8:0:1619::92]) by forward101p.mail.yandex.net (Yandex) with ESMTP id 6CED56A81E66 for ; Wed, 20 Sep 2017 12:00:43 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback16j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id kvElbE8IT2-0hXGtJCd; Wed, 20 Sep 2017 12:00:43 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0fNGtN0U; Wed, 20 Sep 2017 12:00:41 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:10 +0300 Message-Id: <1505898014-18011-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 6/10] linux-gen: pktio: netmap: minor code refactory 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ platform/linux-generic/Makefile.am | 2 +- .../linux-generic/include/odp_packet_io_internal.h | 2 - ...{odp_packet_netmap.h => odp_pktio_ops_netmap.h} | 6 +- .../include/odp_pktio_ops_subsystem.h | 2 + platform/linux-generic/pktio/netmap.c | 89 ++++++++++++---------- 5 files changed, 56 insertions(+), 45 deletions(-) rename platform/linux-generic/include/{odp_packet_netmap.h => odp_pktio_ops_netmap.h} (96%) diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 5c4d02a3d..7911a91f5 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -186,12 +186,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ - ${srcdir}/include/odp_packet_netmap.h \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ + ${srcdir}/include/odp_pktio_ops_netmap.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_queue_subsystem.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 8d3c3ddff..af826b7e7 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -32,7 +32,6 @@ extern "C" { #define PKTIO_MAX_QUEUES 64 #include -#include #include #include @@ -78,7 +77,6 @@ struct pktio_entry { pkt_sock_t pkt_sock; /**< using socket API for IO */ pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap * API for IO */ - pkt_netmap_t pkt_nm; /**< using netmap API for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ #ifdef HAVE_PCAP pkt_pcap_t pkt_pcap; /**< Using pcap for IO */ diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_pktio_ops_netmap.h similarity index 96% rename from platform/linux-generic/include/odp_packet_netmap.h rename to platform/linux-generic/include/odp_pktio_ops_netmap.h index a6f68d569..35592d85f 100644 --- a/platform/linux-generic/include/odp_packet_netmap.h +++ b/platform/linux-generic/include/odp_pktio_ops_netmap.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_NETMAP_H -#define ODP_PACKET_NETMAP_H +#ifndef ODP_PKTIO_OPS_NETMAP_H_ +#define ODP_PKTIO_OPS_NETMAP_H_ #include #include @@ -63,6 +63,6 @@ typedef struct { netmap_ring_t rx_desc_ring[PKTIO_MAX_QUEUES]; /** mapping of pktout queues to netmap tx descriptors */ netmap_ring_t tx_desc_ring[PKTIO_MAX_QUEUES]; -} pkt_netmap_t; +} pktio_ops_netmap_data_t; #endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 650b36648..b1b735ced 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -81,6 +81,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { /* All implementations of this subsystem */ #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -88,6 +89,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { typedef union { pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; + pktio_ops_netmap_data_t netmap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index c75f8be97..accac61c6 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -46,15 +45,16 @@ static int netmap_stats_reset(pktio_entry_t *pktio_entry); static int netmap_do_ioctl(pktio_entry_t *pktio_entry, unsigned long cmd, int subcmd) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); struct ethtool_value eval; struct ifreq ifr; int err; int fd = pkt_nm->sockfd; memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", - pktio_entry->s.pkt_nm.if_name); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), + "%s", pkt_nm->if_name); switch (cmd) { case SIOCSIFFLAGS: @@ -133,7 +133,8 @@ static inline void map_netmap_rings(netmap_ring_t *rings, static int netmap_input_queues_config(pktio_entry_t *pktio_entry, const odp_pktin_queue_param_t *p) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); odp_pktin_mode_t mode = pktio_entry->s.param.in_mode; unsigned num_queues = p->num_queues; odp_bool_t lockless; @@ -146,8 +147,7 @@ static int netmap_input_queues_config(pktio_entry_t *pktio_entry, lockless = (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE); if (p->hash_enable && num_queues > 1) { - if (rss_conf_set_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name, + if (rss_conf_set_fd(pkt_nm->sockfd, pkt_nm->if_name, &p->hash_proto)) { ODP_ERR("Failed to configure input hash\n"); return -1; @@ -162,7 +162,8 @@ static int netmap_input_queues_config(pktio_entry_t *pktio_entry, static int netmap_output_queues_config(pktio_entry_t *pktio_entry, const odp_pktout_queue_param_t *p) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); pkt_nm->lockless_tx = (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE); @@ -179,7 +180,8 @@ static int netmap_output_queues_config(pktio_entry_t *pktio_entry, static inline void netmap_close_descriptors(pktio_entry_t *pktio_entry) { int i, j; - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); for (i = 0; i < PKTIO_MAX_QUEUES; i++) { for (j = 0; j < NM_MAX_DESC; j++) { @@ -202,7 +204,8 @@ static inline void netmap_close_descriptors(pktio_entry_t *pktio_entry) static int netmap_close(pktio_entry_t *pktio_entry) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); netmap_close_descriptors(pktio_entry); @@ -216,11 +219,11 @@ static int netmap_close(pktio_entry_t *pktio_entry) static int netmap_link_status(pktio_entry_t *pktio_entry) { - if (pktio_entry->s.pkt_nm.is_virtual) + if (pktio_entry->ops_data(netmap).is_virtual) return 1; - return link_status_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name); + return link_status_fd(pktio_entry->ops_data(netmap).sockfd, + pktio_entry->ops_data(netmap).if_name); } /** @@ -247,12 +250,12 @@ static inline int netmap_wait_for_link(pktio_entry_t *pktio_entry) * until the opposing end's interface comes back up again. In * this case without the additional sleep pktio validation * tests fail. */ - if (!pktio_entry->s.pkt_nm.is_virtual) + if (!pktio_entry->ops_data(netmap).is_virtual) sleep(1); if (ret == 1) return 1; } - ODP_DBG("%s link is down\n", pktio_entry->s.pkt_nm.if_name); + ODP_DBG("%s link is down\n", pktio_entry->ops_data(netmap).if_name); return 0; } @@ -263,7 +266,8 @@ static inline int netmap_wait_for_link(pktio_entry_t *pktio_entry) */ static void netmap_init_capability(pktio_entry_t *pktio_entry) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); odp_pktio_capability_t *capa = &pkt_nm->capa; memset(&pkt_nm->capa, 0, sizeof(odp_pktio_capability_t)); @@ -330,7 +334,8 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *prefix; uint32_t mtu; uint32_t buf_size; - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); struct nm_desc *desc; struct netmap_ring *ring; odp_pktin_hash_proto_t hash_proto; @@ -407,7 +412,7 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, /* Use either interface MTU (+ ethernet header length) or netmap buffer * size as MTU, whichever is smaller. */ - mtu = mtu_get_fd(pktio_entry->s.pkt_nm.sockfd, pkt_nm->if_name); + mtu = mtu_get_fd(pkt_nm->sockfd, pkt_nm->if_name); if (mtu == 0) { ODP_ERR("Unable to read interface MTU\n"); goto error; @@ -432,7 +437,7 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, goto error; /* netmap uses only ethtool to get statistics counters */ - err = ethtool_stats_get_fd(pktio_entry->s.pkt_nm.sockfd, + err = ethtool_stats_get_fd(pkt_nm->sockfd, pkt_nm->if_name, &cur_stats); if (err) { ODP_ERR("netmap pktio %s does not support statistics counters\n", @@ -453,7 +458,8 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, static int netmap_start(pktio_entry_t *pktio_entry) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); netmap_ring_t *desc_ring; struct nm_desc *desc_ptr; unsigned i; @@ -610,7 +616,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, odp_time_t *ts) { odp_packet_t pkt; - odp_pool_t pool = pktio_entry->s.pkt_nm.pool; + odp_pool_t pool = pktio_entry->ops_data(netmap).pool; odp_packet_hdr_t *pkt_hdr; odp_packet_hdr_t parsed_hdr; int i; @@ -618,7 +624,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, int alloc_len; /* Allocate maximum sized packets */ - alloc_len = pktio_entry->s.pkt_nm.mtu; + alloc_len = pktio_entry->ops_data(netmap).mtu; num = packet_alloc_multi(pool, alloc_len, pkt_tbl, slot_num); @@ -631,9 +637,10 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, odp_prefetch(slot.buf); - if (odp_unlikely(len > pktio_entry->s.pkt_nm.max_frame_len)) { + if (odp_unlikely(len > pktio_entry-> + ops_data(netmap).max_frame_len)) { ODP_ERR("RX: frame too big %" PRIu16 " %zu!\n", len, - pktio_entry->s.pkt_nm.max_frame_len); + pktio_entry->ops_data(netmap).max_frame_len); goto fail; } @@ -729,7 +736,8 @@ static int netmap_recv(pktio_entry_t *pktio_entry, int index, odp_packet_t pkt_table[], int num) { struct nm_desc *desc; - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); unsigned first_desc_id = pkt_nm->rx_desc_ring[index].s.first; unsigned last_desc_id = pkt_nm->rx_desc_ring[index].s.last; unsigned desc_id; @@ -782,7 +790,8 @@ static int netmap_recv(pktio_entry_t *pktio_entry, int index, static int netmap_send(pktio_entry_t *pktio_entry, int index, const odp_packet_t pkt_table[], int num) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); struct pollfd polld; struct nm_desc *desc; struct netmap_ring *ring; @@ -857,40 +866,42 @@ static int netmap_send(pktio_entry_t *pktio_entry, int index, static int netmap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_entry->s.pkt_nm.if_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->ops_data(netmap).if_mac, ETH_ALEN); return ETH_ALEN; } static uint32_t netmap_mtu_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_nm.mtu; + return pktio_entry->ops_data(netmap).mtu; } static int netmap_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - if (pktio_entry->s.pkt_nm.is_virtual) { + if (pktio_entry->ops_data(netmap).is_virtual) { __odp_errno = ENOTSUP; return -1; } - return promisc_mode_set_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name, enable); + return promisc_mode_set_fd( + pktio_entry->ops_data(netmap).sockfd, + pktio_entry->ops_data(netmap).if_name, enable); } static int netmap_promisc_mode_get(pktio_entry_t *pktio_entry) { - if (pktio_entry->s.pkt_nm.is_virtual) + if (pktio_entry->ops_data(netmap).is_virtual) return 0; - return promisc_mode_get_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name); + return promisc_mode_get_fd( + pktio_entry->ops_data(netmap).sockfd, + pktio_entry->ops_data(netmap).if_name); } static int netmap_capability(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa) { - *capa = pktio_entry->s.pkt_nm.capa; + *capa = pktio_entry->ops_data(netmap).capa; return 0; } @@ -904,7 +915,7 @@ static int netmap_stats(pktio_entry_t *pktio_entry, return sock_stats_fd(pktio_entry, stats, - pktio_entry->s.pkt_nm.sockfd); + pktio_entry->ops_data(netmap).sockfd); } static int netmap_stats_reset(pktio_entry_t *pktio_entry) @@ -916,15 +927,15 @@ static int netmap_stats_reset(pktio_entry_t *pktio_entry) } return sock_stats_reset_fd(pktio_entry, - pktio_entry->s.pkt_nm.sockfd); + pktio_entry->ops_data(netmap).sockfd); } static void netmap_print(pktio_entry_t *pktio_entry) { odp_pktin_hash_proto_t hash_proto; - if (rss_conf_get_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name, &hash_proto)) + if (rss_conf_get_fd(pktio_entry->ops_data(netmap).sockfd, + pktio_entry->ops_data(netmap).if_name, &hash_proto)) rss_conf_print(&hash_proto); } From patchwork Wed Sep 20 09:00:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113097 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp449342edb; Wed, 20 Sep 2017 02:13:54 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCxMtWK/WxgsH9UM7r2yKMDwYavnVcE+fN1+4ZrgAdI/Z4QSUTzsQaN1ejf/kJM60/Xl8/O X-Received: by 10.55.43.234 with SMTP id r103mr6010271qkr.334.1505898695038; Wed, 20 Sep 2017 02:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898695; cv=none; d=google.com; s=arc-20160816; b=WRla9h/ImIcV+2DkoanuVkEgO3X3TuZmFjFDxwB3qKi+GhxnDK62/BDy9pXsqJzdlM K8HRapK0T7TrEdSdYnekNXRQhYcSuj6nQXn7XF22bZjGNrxwortZ+COJJQSX8cuQ14ov 8TZs0km3Dpy6cz7SgT/LkAEQeUjMLg6pRAgKhbtbic05Rn0Q/0QTpB3qaqIQmLZccoTu k/sdJbkeGAWnNBhwCrGQILiTp35Tb+fKRj4Zt3EV90OY/Mo1HeYuIETg+Eba2WZugFHf euaKLK75ebSEho5vwTHFOpurElkN97mhEF1F7ve+J1KhDML5pGph4COlrf0uP7mv7CPe R1sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=CTcnIYOggjhlMjrEVbihiW9wyXgfuuM6ZecOUPkoQxU=; b=xOrpJhsTJzP0mVI/ZsQpGmMGFojfS6KhGGd2yhKUxlMCd4Zpwa5u78ofGWRH/W3rXi m4cOqKn4i1AXj/3cVDr59bFzEUDfRfdwcZBzrwul2Eu0En9KWH7fSFGP5K4RRTtrfQEM mWhgDie81jwRRZxYZpbOBuyqowk+lS81NmO+TYeezYhoVo3bj1HR6zPD/kaS0ILnmWpq WV0LKGHD2yCGkROvySFXqg8HxTm7vgA5vMf5+v2AzZjstGh3U7FXFhchVTT9GpNSarAa 2zsc+7luu+Ny5quKDwEiVY2OiCKS9zlqcKfRjtDGXbZ3mXe4fOeSjO/lFFL7A03uRUh/ mXfg== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 143si1427582qke.445.2017.09.20.02.11.34; Wed, 20 Sep 2017 02:11:35 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id B12706092D; Wed, 20 Sep 2017 09:11:34 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 6F6D6636A2; Wed, 20 Sep 2017 09:02:30 +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 8E40163CB0; Wed, 20 Sep 2017 09:02:17 +0000 (UTC) Received: from forward101o.mail.yandex.net (forward101o.mail.yandex.net [37.140.190.181]) by lists.linaro.org (Postfix) with ESMTPS id 7C4E860D7F for ; Wed, 20 Sep 2017 09:00:47 +0000 (UTC) Received: from mxback8g.mail.yandex.net (mxback8g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:169]) by forward101o.mail.yandex.net (Yandex) with ESMTP id 417601344BB2 for ; Wed, 20 Sep 2017 12:00:44 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback8g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id khtgcdTn6T-0iZqWTib; Wed, 20 Sep 2017 12:00:44 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0hNGsYb8; Wed, 20 Sep 2017 12:00:43 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:11 +0300 Message-Id: <1505898014-18011-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 7/10] linux-gen: pktio: pcap: minor code refactory 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ platform/linux-generic/Makefile.am | 1 + .../linux-generic/include/odp_packet_io_internal.h | 18 -------------- .../linux-generic/include/odp_pktio_ops_pcap.h | 25 +++++++++++++++++++ .../include/odp_pktio_ops_subsystem.h | 2 ++ platform/linux-generic/pktio/pcap.c | 29 +++++++++++++--------- 5 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 platform/linux-generic/include/odp_pktio_ops_pcap.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 7911a91f5..53e103042 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -192,6 +192,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ + ${srcdir}/include/odp_pktio_ops_pcap.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_queue_subsystem.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index af826b7e7..a3890091f 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -50,21 +50,6 @@ typedef union pktio_entry_u pktio_entry_t; * requested number of packets were not handled. */ #define SOCK_ERR_REPORT(e) (e != EAGAIN && e != EWOULDBLOCK && e != EINTR) -#ifdef HAVE_PCAP -typedef struct { - char *fname_rx; /**< name of pcap file for rx */ - char *fname_tx; /**< name of pcap file for tx */ - void *rx; /**< rx pcap handle */ - void *tx; /**< tx pcap handle */ - void *tx_dump; /**< tx pcap dumper handle */ - odp_pool_t pool; /**< rx pool */ - unsigned char *buf; /**< per-pktio temp buffer */ - int loops; /**< number of times to loop rx pcap */ - int loop_cnt; /**< number of loops completed */ - odp_bool_t promisc; /**< promiscuous mode state */ -} pkt_pcap_t; -#endif - struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ pktio_ops_data_t ops_data; /**< IO operation specific data */ @@ -78,9 +63,6 @@ struct pktio_entry { pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap * API for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ -#ifdef HAVE_PCAP - pkt_pcap_t pkt_pcap; /**< Using pcap for IO */ -#endif pkt_tap_t pkt_tap; /**< using TAP for IO */ }; enum { diff --git a/platform/linux-generic/include/odp_pktio_ops_pcap.h b/platform/linux-generic/include/odp_pktio_ops_pcap.h new file mode 100644 index 000000000..6911710c4 --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_pcap.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_PCAP_H_ +#define ODP_PKTIO_OPS_PCAP_H_ + +typedef struct { + char *fname_rx; /**< name of pcap file for rx */ + char *fname_tx; /**< name of pcap file for tx */ + void *rx; /**< rx pcap handle */ + void *tx; /**< tx pcap handle */ + void *tx_dump; /**< tx pcap dumper handle */ + odp_pool_t pool; /**< rx pool */ + unsigned char *buf; /**< per-pktio temp buffer */ + int loops; /**< number of times to loop rx pcap */ + int loop_cnt; /**< number of loops completed */ + odp_bool_t promisc; /**< promiscuous mode state */ +} pktio_ops_pcap_data_t; + +#endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index b1b735ced..fc461be79 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -82,6 +82,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { #include #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -90,6 +91,7 @@ typedef union { pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; pktio_ops_netmap_data_t netmap; + pktio_ops_pcap_data_t pcap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index 98f810898..684c4e120 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -51,7 +51,8 @@ static const char pcap_mac[] = {0x02, 0xe9, 0x34, 0x80, 0x73, 0x04}; static int pcapif_stats_reset(pktio_entry_t *pktio_entry); -static int _pcapif_parse_devname(pkt_pcap_t *pcap, const char *devname) +static int _pcapif_parse_devname(pktio_ops_pcap_data_t *pcap, + const char *devname) { char *tok; char in[PKTIO_NAME_LEN]; @@ -80,7 +81,7 @@ static int _pcapif_parse_devname(pkt_pcap_t *pcap, const char *devname) return 0; } -static int _pcapif_init_rx(pkt_pcap_t *pcap) +static int _pcapif_init_rx(pktio_ops_pcap_data_t *pcap) { char errbuf[PCAP_ERRBUF_SIZE]; int linktype; @@ -101,7 +102,7 @@ static int _pcapif_init_rx(pkt_pcap_t *pcap) return 0; } -static int _pcapif_init_tx(pkt_pcap_t *pcap) +static int _pcapif_init_tx(pktio_ops_pcap_data_t *pcap) { pcap_t *tx = pcap->rx; @@ -136,10 +137,11 @@ static int _pcapif_init_tx(pkt_pcap_t *pcap) static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *devname, odp_pool_t pool) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); int ret; - memset(pcap, 0, sizeof(pkt_pcap_t)); + memset(pcap, 0, sizeof(pktio_ops_pcap_data_t)); pcap->loop_cnt = 1; pcap->loops = 1; pcap->pool = pool; @@ -163,7 +165,7 @@ static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, static int pcapif_close(pktio_entry_t *pktio_entry) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = &pktio_entry->ops_data(pcap); if (pcap->tx_dump) pcap_dump_close(pcap->tx_dump); @@ -181,7 +183,7 @@ static int pcapif_close(pktio_entry_t *pktio_entry) return 0; } -static int _pcapif_reopen(pkt_pcap_t *pcap) +static int _pcapif_reopen(pktio_ops_pcap_data_t *pcap) { char errbuf[PCAP_ERRBUF_SIZE]; @@ -210,7 +212,8 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_packet_t pkt; odp_packet_hdr_t *pkt_hdr; uint32_t pkt_len; - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); odp_time_t ts_val; odp_time_t *ts = NULL; @@ -270,7 +273,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, return i; } -static int _pcapif_dump_pkt(pkt_pcap_t *pcap, odp_packet_t pkt) +static int _pcapif_dump_pkt(pktio_ops_pcap_data_t *pcap, odp_packet_t pkt) { struct pcap_pkthdr hdr; @@ -293,7 +296,8 @@ static int _pcapif_dump_pkt(pkt_pcap_t *pcap, odp_packet_t pkt) static int pcapif_send_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, const odp_packet_t pkts[], int len) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); int i; odp_ticketlock_lock(&pktio_entry->s.txl); @@ -361,7 +365,8 @@ static int pcapif_promisc_mode_set(pktio_entry_t *pktio_entry, { char filter_exp[64] = {0}; struct bpf_program bpf; - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); if (!pcap->rx) { pcap->promisc = enable; @@ -401,7 +406,7 @@ static int pcapif_promisc_mode_set(pktio_entry_t *pktio_entry, static int pcapif_promisc_mode_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_pcap.promisc; + return pktio_entry->ops_data(pcap).promisc; } static int pcapif_stats_reset(pktio_entry_t *pktio_entry) From patchwork Wed Sep 20 09:00:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113095 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp448476edb; Wed, 20 Sep 2017 02:12:44 -0700 (PDT) X-Google-Smtp-Source: AOwi7QA6aGRmVoHiB6lOSLclLxVfAlgwk3mNAevmLDbVLxQZwUMksx2smQgfqsvWUF4HuGVam7gO X-Received: by 10.36.58.149 with SMTP id m143mr2184674itm.4.1505898763946; Wed, 20 Sep 2017 02:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898763; cv=none; d=google.com; s=arc-20160816; b=eozK7KFLfGc3sYavByx4wHORnPQdTACR8LxPTP/IwWdtO0y2ONVLU8q48UavJBpQqb gEMmyf0LdVch90TXi3Fj7wRkdcxeWjWQOD2zVmAKUxqy4hYNKOFlTaceD5X6qE7VwRbI x3CjQpd2oTvAP4XXYfXDhfnNZRp5+x/A2eEHV1eWnURTVYATuD/3ZyOu19VFH0JtQEWs gvtAlitpPj+qadLPzdHKzQ9+6NJYZ1Jn3htCNVi7kJYuOwug+IJGfJlF6euinh4vrScJ xjGIhhcPTAVgfZCqWmqB4ts+IBQ6/PngB4O6infbZpKBnRHdE3P4VsMgOrpul2jhby9+ bDIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=XmXwJaOY/z3i2CMcTOpgfu3Sykh0FT8qJgKvf4soqs4=; b=wtGVXlScQtRGP9JfaE7OmrD4ha56S52ryo3NCqXF1a7AdldMClGbNNMvw6fO6PXwnG YTw5FEd4nVptxqf3QEHCW0LzkO9u3gHCxgyx+QhzCJJDGvWQD3e3OeYqGYamtlYkgDU7 FGur9H6k948Cz5lNqt49hbIMfyFcueOg2p7pmZqjNf1Dw9nDMgfReq07v+gy524KEo6Y 4XEqWTfgYOm5vmDO1zpM7bbHrI+q9hheKcpBj5sIP3xskSrs9CL5YBqukANo/hsyZkcw j3n+9wRburfUyAZ9oG3bssmyEZd+rivc3U3iGdbouoQWdvkiXlLIEDxb2PJWBYW0Ufo/ XFFA== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g4si1185578iog.190.2017.09.20.02.12.43; Wed, 20 Sep 2017 02:12:43 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 4D5D864474; Wed, 20 Sep 2017 09:12:43 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 25F556445A; Wed, 20 Sep 2017 09:02:44 +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 157FF6445A; Wed, 20 Sep 2017 09:02:34 +0000 (UTC) Received: from forward101p.mail.yandex.net (forward101p.mail.yandex.net [77.88.28.101]) by lists.linaro.org (Postfix) with ESMTPS id 1275B608E0 for ; Wed, 20 Sep 2017 09:00:53 +0000 (UTC) Received: from mxback1g.mail.yandex.net (mxback1g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:162]) by forward101p.mail.yandex.net (Yandex) with ESMTP id 05F476A82637 for ; Wed, 20 Sep 2017 12:00:52 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id oGwWmHip9h-0jQCV7AE; Wed, 20 Sep 2017 12:00:45 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0jNaNK9Q; Wed, 20 Sep 2017 12:00:45 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:12 +0300 Message-Id: <1505898014-18011-9-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 8/10] linux-gen: pktio: socket: minor code refactory 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Rename implementation specific data structure and its dedicated header file to accommodate uniformed name scheme. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ platform/linux-dpdk/Makefile.am | 2 +- platform/linux-generic/Makefile.am | 2 +- .../linux-generic/include/odp_packet_io_internal.h | 4 -- ...{odp_packet_socket.h => odp_pktio_ops_socket.h} | 8 ++-- .../include/odp_pktio_ops_subsystem.h | 3 ++ platform/linux-generic/odp_packet_io.c | 1 - platform/linux-generic/pktio/ethtool.c | 2 +- platform/linux-generic/pktio/netmap.c | 1 - platform/linux-generic/pktio/socket.c | 30 ++++++++------- platform/linux-generic/pktio/socket_mmap.c | 45 ++++++++++++---------- platform/linux-generic/pktio/tap.c | 1 - 11 files changed, 51 insertions(+), 48 deletions(-) rename platform/linux-generic/include/{odp_packet_socket.h => odp_pktio_ops_socket.h} (96%) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 15c9fb446..3522f5cd0 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -192,12 +192,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_ipc.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_socket.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_loopback.h \ ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ ${top_srcdir}/platform/linux-generic/include/odp_packet_io_ring_internal.h \ - ${top_srcdir}/platform/linux-generic/include/odp_packet_socket.h \ ${top_srcdir}/platform/linux-generic/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_pool_subsystem.h \ diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 53e103042..0c0915a28 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -187,12 +187,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ ${srcdir}/include/odp_packet_dpdk.h \ - ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ ${srcdir}/include/odp_pktio_ops_pcap.h \ + ${srcdir}/include/odp_pktio_ops_socket.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_queue_subsystem.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index a3890091f..f58ef8721 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -31,7 +31,6 @@ extern "C" { #include #define PKTIO_MAX_QUEUES 64 -#include #include #include @@ -59,9 +58,6 @@ struct pktio_entry { int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ union { - pkt_sock_t pkt_sock; /**< using socket API for IO */ - pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap - * API for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ pkt_tap_t pkt_tap; /**< using TAP for IO */ }; diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_pktio_ops_socket.h similarity index 96% rename from platform/linux-generic/include/odp_packet_socket.h rename to platform/linux-generic/include/odp_pktio_ops_socket.h index 0e61f6f0c..32c49c08e 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_pktio_ops_socket.h @@ -5,8 +5,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_SOCKET_H -#define ODP_PACKET_SOCKET_H +#ifndef ODP_PKTIO_OPS_SOCKET_H_ +#define ODP_PKTIO_OPS_SOCKET_H_ #include #include @@ -42,7 +42,7 @@ typedef struct { odp_pool_t pool; /**< pool to alloc packets from */ uint32_t mtu; /**< maximum transmission unit */ unsigned char if_mac[ETH_ALEN]; /**< IF eth mac addr */ -} pkt_sock_t; +} pktio_ops_socket_data_t; /** packet mmap ring */ struct ring { @@ -79,7 +79,7 @@ typedef struct { unsigned char if_mac[ETH_ALEN]; struct sockaddr_ll ll; int fanout; -} pkt_sock_mmap_t; +} pktio_ops_socket_mmap_data_t; static inline void ethaddr_copy(unsigned char mac_dst[], unsigned char mac_src[]) diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index fc461be79..952d9be55 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -83,6 +83,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { #include #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -92,6 +93,8 @@ typedef union { pktio_ops_loopback_data_t loopback; pktio_ops_netmap_data_t netmap; pktio_ops_pcap_data_t pcap; + pktio_ops_socket_data_t socket; + pktio_ops_socket_mmap_data_t mmap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 6a19394a5..e023df130 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/platform/linux-generic/pktio/ethtool.c b/platform/linux-generic/pktio/ethtool.c index d8f9e12cb..ed2875c5b 100644 --- a/platform/linux-generic/pktio/ethtool.c +++ b/platform/linux-generic/pktio/ethtool.c @@ -13,8 +13,8 @@ #include #include -#include #include +#include static struct ethtool_gstrings *get_stringset(int fd, struct ifreq *ifr) { diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index accac61c6..07d6d9e9b 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index 8b8ccf033..c7c3c5a8c 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include @@ -455,7 +454,9 @@ void rss_conf_print(const odp_pktin_hash_proto_t *hash_proto) */ static int sock_close(pktio_entry_t *pktio_entry) { - pkt_sock_t *pkt_sock = &pktio_entry->s.pkt_sock; + pktio_ops_socket_data_t *pkt_sock = + &pktio_entry->ops_data(socket); + if (pkt_sock->sockfd != -1 && close(pkt_sock->sockfd) != 0) { __odp_errno = errno; ODP_ERR("close(sockfd): %s\n", strerror(errno)); @@ -477,7 +478,8 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, struct ifreq ethreq; struct sockaddr_ll sa_ll; char shm_name[ODP_SHM_NAME_LEN]; - pkt_sock_t *pkt_sock = &pktio_entry->s.pkt_sock; + pktio_ops_socket_data_t *pkt_sock = + &pktio_entry->ops_data(socket); odp_pktio_stats_t cur_stats; /* Init pktio entry */ @@ -530,7 +532,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, goto error; } - err = ethtool_stats_get_fd(pktio_entry->s.pkt_sock.sockfd, + err = ethtool_stats_get_fd(pkt_sock->sockfd, pktio_entry->s.name, &cur_stats); if (err != 0) { @@ -601,7 +603,8 @@ static uint32_t _rx_pkt_to_iovec(odp_packet_t pkt, static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_packet_t pkt_table[], int len) { - pkt_sock_t *pkt_sock = &pktio_entry->s.pkt_sock; + pktio_ops_socket_data_t *pkt_sock = + &pktio_entry->ops_data(socket); odp_pool_t pool = pkt_sock->pool; odp_time_t ts_val; odp_time_t *ts = NULL; @@ -716,7 +719,8 @@ static uint32_t _tx_pkt_to_iovec(odp_packet_t pkt, static int sock_mmsg_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, const odp_packet_t pkt_table[], int len) { - pkt_sock_t *pkt_sock = &pktio_entry->s.pkt_sock; + pktio_ops_socket_data_t *pkt_sock = + &pktio_entry->ops_data(socket); struct mmsghdr msgvec[len]; struct iovec iovecs[len][MAX_SEGS]; int ret; @@ -762,7 +766,7 @@ static int sock_mmsg_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, */ static uint32_t sock_mtu_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_sock.mtu; + return pktio_entry->ops_data(socket).mtu; } /* @@ -771,7 +775,7 @@ static uint32_t sock_mtu_get(pktio_entry_t *pktio_entry) static int sock_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_entry->s.pkt_sock.if_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->ops_data(socket).if_mac, ETH_ALEN); return ETH_ALEN; } @@ -781,7 +785,7 @@ static int sock_mac_addr_get(pktio_entry_t *pktio_entry, static int sock_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - return promisc_mode_set_fd(pktio_entry->s.pkt_sock.sockfd, + return promisc_mode_set_fd(pktio_entry->ops_data(socket).sockfd, pktio_entry->s.name, enable); } @@ -790,13 +794,13 @@ static int sock_promisc_mode_set(pktio_entry_t *pktio_entry, */ static int sock_promisc_mode_get(pktio_entry_t *pktio_entry) { - return promisc_mode_get_fd(pktio_entry->s.pkt_sock.sockfd, + return promisc_mode_get_fd(pktio_entry->ops_data(socket).sockfd, pktio_entry->s.name); } static int sock_link_status(pktio_entry_t *pktio_entry) { - return link_status_fd(pktio_entry->s.pkt_sock.sockfd, + return link_status_fd(pktio_entry->ops_data(socket).sockfd, pktio_entry->s.name); } @@ -825,7 +829,7 @@ static int sock_stats(pktio_entry_t *pktio_entry, return sock_stats_fd(pktio_entry, stats, - pktio_entry->s.pkt_sock.sockfd); + pktio_entry->ops_data(socket).sockfd); } static int sock_stats_reset(pktio_entry_t *pktio_entry) @@ -837,7 +841,7 @@ static int sock_stats_reset(pktio_entry_t *pktio_entry) } return sock_stats_reset_fd(pktio_entry, - pktio_entry->s.pkt_sock.sockfd); + pktio_entry->ops_data(socket).sockfd); } static int sock_init_global(void) diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 82abd38db..3dd03e66b 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -37,8 +36,8 @@ static int disable_pktio; /** !0 this pktio disabled, 0 enabled */ -static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t *const pkt_sock, - int sock_group_idx) +static int set_pkt_sock_fanout_mmap( + pktio_ops_socket_mmap_data_t *const pkt_sock, int sock_group_idx) { int sockfd = pkt_sock->sockfd; int val; @@ -144,7 +143,7 @@ static uint8_t *pkt_mmap_vlan_insert(uint8_t *l2_hdr_ptr, } static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry, - pkt_sock_mmap_t *pkt_sock, + pktio_ops_socket_mmap_data_t *pkt_sock, odp_packet_t pkt_table[], unsigned len, unsigned char if_mac[]) { @@ -411,7 +410,7 @@ static int mmap_setup_ring(int sock, struct ring *ring, int type, return 0; } -static int mmap_sock(pkt_sock_mmap_t *pkt_sock) +static int mmap_sock(pktio_ops_socket_mmap_data_t *pkt_sock) { int i; int sock = pkt_sock->sockfd; @@ -455,14 +454,15 @@ static int mmap_sock(pkt_sock_mmap_t *pkt_sock) return 0; } -static int mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock) +static int mmap_unmap_sock(pktio_ops_socket_mmap_data_t *pkt_sock) { free(pkt_sock->rx_ring.rd); free(pkt_sock->tx_ring.rd); return munmap(pkt_sock->mmap_base, pkt_sock->mmap_len); } -static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, const char *netdev) +static int mmap_bind_sock(pktio_ops_socket_mmap_data_t *pkt_sock, + const char *netdev) { int ret; @@ -486,7 +486,8 @@ static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, const char *netdev) static int sock_mmap_close(pktio_entry_t *entry) { - pkt_sock_mmap_t *const pkt_sock = &entry->s.pkt_sock_mmap; + pktio_ops_socket_mmap_data_t + *const pkt_sock = &entry->ops_data(mmap); int ret; ret = mmap_unmap_sock(pkt_sock); @@ -515,7 +516,8 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, if (disable_pktio) return -1; - pkt_sock_mmap_t *const pkt_sock = &pktio_entry->s.pkt_sock_mmap; + pktio_ops_socket_mmap_data_t + *const pkt_sock = &pktio_entry->ops_data(mmap); int fanout = 1; /* Init pktio entry */ @@ -570,7 +572,7 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, goto error; } - ret = ethtool_stats_get_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + ret = ethtool_stats_get_fd(pkt_sock->sockfd, pktio_entry->s.name, &cur_stats); if (ret != 0) { @@ -586,8 +588,7 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry->s.stats_type = STATS_ETHTOOL; } - ret = sock_stats_reset_fd(pktio_entry, - pktio_entry->s.pkt_sock_mmap.sockfd); + ret = sock_stats_reset_fd(pktio_entry, pkt_sock->sockfd); if (ret != 0) goto error; @@ -601,7 +602,8 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, static int sock_mmap_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_packet_t pkt_table[], int len) { - pkt_sock_mmap_t *const pkt_sock = &pktio_entry->s.pkt_sock_mmap; + pktio_ops_socket_mmap_data_t + *const pkt_sock = &pktio_entry->ops_data(mmap); int ret; odp_ticketlock_lock(&pktio_entry->s.rxl); @@ -616,7 +618,8 @@ static int sock_mmap_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, const odp_packet_t pkt_table[], int len) { int ret; - pkt_sock_mmap_t *const pkt_sock = &pktio_entry->s.pkt_sock_mmap; + pktio_ops_socket_mmap_data_t + *const pkt_sock = &pktio_entry->ops_data(mmap); odp_ticketlock_lock(&pktio_entry->s.txl); ret = pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring, @@ -628,32 +631,32 @@ static int sock_mmap_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, static uint32_t sock_mmap_mtu_get(pktio_entry_t *pktio_entry) { - return mtu_get_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + return mtu_get_fd(pktio_entry->ops_data(mmap).sockfd, pktio_entry->s.name); } static int sock_mmap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_entry->s.pkt_sock_mmap.if_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->ops_data(mmap).if_mac, ETH_ALEN); return ETH_ALEN; } static int sock_mmap_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - return promisc_mode_set_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + return promisc_mode_set_fd(pktio_entry->ops_data(mmap).sockfd, pktio_entry->s.name, enable); } static int sock_mmap_promisc_mode_get(pktio_entry_t *pktio_entry) { - return promisc_mode_get_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + return promisc_mode_get_fd(pktio_entry->ops_data(mmap).sockfd, pktio_entry->s.name); } static int sock_mmap_link_status(pktio_entry_t *pktio_entry) { - return link_status_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + return link_status_fd(pktio_entry->ops_data(mmap).sockfd, pktio_entry->s.name); } @@ -682,7 +685,7 @@ static int sock_mmap_stats(pktio_entry_t *pktio_entry, return sock_stats_fd(pktio_entry, stats, - pktio_entry->s.pkt_sock_mmap.sockfd); + pktio_entry->ops_data(mmap).sockfd); } static int sock_mmap_stats_reset(pktio_entry_t *pktio_entry) @@ -694,7 +697,7 @@ static int sock_mmap_stats_reset(pktio_entry_t *pktio_entry) } return sock_stats_reset_fd(pktio_entry, - pktio_entry->s.pkt_sock_mmap.sockfd); + pktio_entry->ops_data(mmap).sockfd); } static int sock_mmap_init_global(void) diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index bfe412390..a5c15e11e 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -40,7 +40,6 @@ #include #include -#include #include #include #include From patchwork Wed Sep 20 09:00:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113098 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp451225edb; Wed, 20 Sep 2017 02:16:20 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDaDm9psqPNTXn56ol6D5yDF3rL6oHrY6CCE7JBg7ea2MnD2AYYYbL6b6avkbb3WU9HPmg8 X-Received: by 10.55.215.67 with SMTP id m64mr6230420qki.315.1505898979920; Wed, 20 Sep 2017 02:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505898979; cv=none; d=google.com; s=arc-20160816; b=h7MeAqg7wVH0R4O9iZGnoT+lrEC+uY5FshoJ/MJtGLp97vNzKQp8IpIW1sreMKw1An G78UWKaDsK7ObiwhIPODzpqfG7DMW8aobRx+N8wqszLXzJ5DK0nQNdr9Ti/EH8X7NcoC bOGmOqCEh0S1jwJrcG9QUxBL+43OSMZJjBtvB/EDvMgHrn3AUNmJFbIHecr2IDGkce7K TV/m/C16pllZaYQTHWhdCy0ZppxhsJKgysh3GdZkOPM/yldpBbAp67iD5uYN3Tr8MPPV TJO5xSLjeTByfJ6lLUv0HTTY7NkLtwgniBwhzGftW7gvPxt2pmWOcZiIjP+2onbRzj49 xIJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=vDJ4s2taCTVpdGIsOXbAn1n63P2zwK88uO/XpoXVVkw=; b=VHGJGSDKzS+ChpjngPRqRvvbgzpEFjfYdBZOZrSkyNX5fRFOK+KqKzVI7jse0Abe73 dAsKTJAof3d07T4j0YpZIDe2NiCaOnShLMiSNFOUBQPKuNwdbhgP0U/J9FPElny6oWDD GtCdq+r9ANe+LLbwpTmufLUvaaWWqZN3U02/SYUw2vccokqa4ALQrqYIZQhJ8NjpQR3x pRP80w9CjD6g9z0XYy5ZGK2oSc1mFp2n37h3yxkqF+etmUGVgBD+t2PtLpONxjXe5aWp gZ5R8Y4ue7wImzIzL/agEZ/U8uRc+mtlr55hD1B+QIs3USeaGmGbm8h4hRrkFkj+Jz+L 4ATw== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id n16si1518476qtn.115.2017.09.20.02.16.19; Wed, 20 Sep 2017 02:16:19 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 802C36448B; Wed, 20 Sep 2017 09:16:19 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 E991360D3A; Wed, 20 Sep 2017 09:03:19 +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 20B6964460; Wed, 20 Sep 2017 09:03:12 +0000 (UTC) Received: from forward103p.mail.yandex.net (forward103p.mail.yandex.net [77.88.28.106]) by lists.linaro.org (Postfix) with ESMTPS id 2022B60C0A for ; Wed, 20 Sep 2017 09:00:55 +0000 (UTC) Received: from mxback2j.mail.yandex.net (mxback2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10b]) by forward103p.mail.yandex.net (Yandex) with ESMTP id B06B32183B55 for ; Wed, 20 Sep 2017 12:00:52 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id VdRpOkcpZR-0q5K3WWm; Wed, 20 Sep 2017 12:00:52 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0qNm237R; Wed, 20 Sep 2017 12:00:52 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:13 +0300 Message-Id: <1505898014-18011-10-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 9/10] linux-gen: pktio: tap: minor code refactory 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Rename implementation specific data structure and its dedicated header file to accommodate uniformed name scheme. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ platform/linux-generic/Makefile.am | 2 +- .../linux-generic/include/odp_packet_io_internal.h | 2 -- .../include/odp_pktio_ops_subsystem.h | 2 ++ .../{odp_packet_tap.h => odp_pktio_ops_tap.h} | 6 +++--- platform/linux-generic/pktio/tap.c | 22 +++++++++++----------- 5 files changed, 17 insertions(+), 17 deletions(-) rename platform/linux-generic/include/{odp_packet_tap.h => odp_pktio_ops_tap.h} (85%) diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 0c0915a28..b294dc4bb 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -187,12 +187,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ ${srcdir}/include/odp_packet_dpdk.h \ - ${srcdir}/include/odp_packet_tap.h \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ ${srcdir}/include/odp_pktio_ops_pcap.h \ ${srcdir}/include/odp_pktio_ops_socket.h \ + ${srcdir}/include/odp_pktio_ops_tap.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_queue_subsystem.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index f58ef8721..7c2833fc6 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -31,7 +31,6 @@ extern "C" { #include #define PKTIO_MAX_QUEUES 64 -#include #include /* Forward declaration */ @@ -59,7 +58,6 @@ struct pktio_entry { odp_pktio_t handle; /**< pktio handle */ union { pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ - pkt_tap_t pkt_tap; /**< using TAP for IO */ }; enum { /* Not allocated */ diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 952d9be55..5c01e34f6 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -84,6 +84,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { #include #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -95,6 +96,7 @@ typedef union { pktio_ops_pcap_data_t pcap; pktio_ops_socket_data_t socket; pktio_ops_socket_mmap_data_t mmap; + pktio_ops_tap_data_t tap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/include/odp_packet_tap.h b/platform/linux-generic/include/odp_pktio_ops_tap.h similarity index 85% rename from platform/linux-generic/include/odp_packet_tap.h rename to platform/linux-generic/include/odp_pktio_ops_tap.h index a90bfbce0..e8e2e270e 100644 --- a/platform/linux-generic/include/odp_packet_tap.h +++ b/platform/linux-generic/include/odp_pktio_ops_tap.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_TAP_H_ -#define ODP_PACKET_TAP_H_ +#ifndef ODP_PACKET_OPS_TAP_H_ +#define ODP_PACKET_OPS_TAP_H_ #include @@ -16,6 +16,6 @@ typedef struct { unsigned char if_mac[ETH_ALEN]; /**< MAC address of pktio side (not a MAC address of kernel interface)*/ odp_pool_t pool; /**< pool to alloc packets from */ -} pkt_tap_t; +} pktio_ops_tap_data_t; #endif diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index a5c15e11e..090e51b66 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -63,7 +63,7 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, int fd, skfd, flags; uint32_t mtu; struct ifreq ifr; - pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + pktio_ops_tap_data_t *tap = &pktio_entry->ops_data(tap); if (strncmp(devname, "tap:", 4) != 0) return -1; @@ -163,7 +163,7 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, static int tap_pktio_close(pktio_entry_t *pktio_entry) { int ret = 0; - pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + pktio_ops_tap_data_t *tap = &pktio_entry->ops_data(tap); if (tap->fd != -1 && close(tap->fd) != 0) { __odp_errno = errno; @@ -190,13 +190,13 @@ static odp_packet_t pack_odp_pkt(pktio_entry_t *pktio_entry, const void *data, if (pktio_cls_enabled(pktio_entry)) { if (cls_classify_packet(pktio_entry, data, len, len, - &pktio_entry->s.pkt_tap.pool, + &pktio_entry->ops_data(tap).pool, &parsed_hdr)) { return ODP_PACKET_INVALID; } } - num = packet_alloc_multi(pktio_entry->s.pkt_tap.pool, len, &pkt, 1); + num = packet_alloc_multi(pktio_entry->ops_data(tap).pool, len, &pkt, 1); if (num != 1) return ODP_PACKET_INVALID; @@ -227,7 +227,7 @@ static int tap_pktio_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, ssize_t retval; int i; uint8_t buf[BUF_SIZE]; - pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + pktio_ops_tap_data_t *tap = &pktio_entry->ops_data(tap); odp_time_t ts_val; odp_time_t *ts = NULL; @@ -267,7 +267,7 @@ static int tap_pktio_send_lockless(pktio_entry_t *pktio_entry, int i, n; uint32_t pkt_len; uint8_t buf[BUF_SIZE]; - pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + pktio_ops_tap_data_t *tap = &pktio_entry->ops_data(tap); for (i = 0; i < len; i++) { pkt_len = odp_packet_len(pkts[i]); @@ -330,10 +330,10 @@ static uint32_t tap_mtu_get(pktio_entry_t *pktio_entry) { uint32_t ret; - ret = mtu_get_fd(pktio_entry->s.pkt_tap.skfd, + ret = mtu_get_fd(pktio_entry->ops_data(tap).skfd, pktio_entry->s.name + 4); if (ret > 0) - pktio_entry->s.pkt_tap.mtu = ret; + pktio_entry->ops_data(tap).mtu = ret; return ret; } @@ -341,19 +341,19 @@ static uint32_t tap_mtu_get(pktio_entry_t *pktio_entry) static int tap_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - return promisc_mode_set_fd(pktio_entry->s.pkt_tap.skfd, + return promisc_mode_set_fd(pktio_entry->ops_data(tap).skfd, pktio_entry->s.name + 4, enable); } static int tap_promisc_mode_get(pktio_entry_t *pktio_entry) { - return promisc_mode_get_fd(pktio_entry->s.pkt_tap.skfd, + return promisc_mode_get_fd(pktio_entry->ops_data(tap).skfd, pktio_entry->s.name + 4); } static int tap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_entry->s.pkt_tap.if_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->ops_data(tap).if_mac, ETH_ALEN); return ETH_ALEN; } From patchwork Wed Sep 20 09:00:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 113099 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp452110edb; Wed, 20 Sep 2017 02:17:28 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDjRLVjb03g+ehbwUuowEh/lRv72ieNj6YW/5WziRUOil504UvypXDqgcFl7bt/RRHyToJY X-Received: by 10.55.164.12 with SMTP id n12mr6176561qke.246.1505899048810; Wed, 20 Sep 2017 02:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505899048; cv=none; d=google.com; s=arc-20160816; b=rlPKxqoYXi6TQoEOkIK9fO5KZGcv9CIVSO2mUKWpm8ze+z/Ubhlf7i/HF4y3J5dg10 CnizGTgTR4l0q+rt5+IxspMLj6IvgSgq8ZrqB6uDmH4jdlUPf/Ar4q39tTQMA4uRGNm1 XHC4kfqzQYUp2Pxj8Pnt7LyMqFiJuozDQ2onrUqscAH8jFkRfqYCjNlcuy7RFYifRo4D erOKOiO6rel/jJaCZfk8dhHa6kaXV052MJIaW6BUFhOafbvDhtpyOGLA2v0EA+HBKkU5 t11mbsPGjn+K2iFPnIkCCun7By1X0RjIVtQWE5zmFU7bEcrqZqNHJEJZOTXopjDv0ldx QKgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=nxbH/zIAdz8B14hlomlUreE9l8pX+4W7yhu0MzRxGeo=; b=eVYdPecFRGsE9OqPpWlbGaQnJ0Z4/jeWyYj9ACMnjXt8zypCimlyG52bDaPoo5PmUo mIVaIFTxTtqv9Ft+4nX7a3ymbbdzgbyPbr18+928vaCVnRQcfAEAK63ceA7BEEnY4N5d AoyBaX57jBFTOMZagL1os56xkVf0ch4cVV3Up5QUk1rXjGnnQkL3QlziH7ixVatjDB+W u8eYRutgxjf4Bt3uN4Qt7XxSu3DTqpeAiJJN2TyGNJp4q+fqNf5BfRZGg8RJfwMG4X+W DdTvsJVArPH0i+ssJ4QQptwdVRGdGPO+XTKv6EBNypXHECH3+dtMKGcpk0I08qQOg12z VJQg== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 53si1495527qty.157.2017.09.20.02.17.28; Wed, 20 Sep 2017 02:17:28 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 6B5DD6447F; Wed, 20 Sep 2017 09:17:28 +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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 BC1F464470; Wed, 20 Sep 2017 09:04: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 EA0AF60900; Wed, 20 Sep 2017 09:04:27 +0000 (UTC) Received: from forward103j.mail.yandex.net (forward103j.mail.yandex.net [5.45.198.246]) by lists.linaro.org (Postfix) with ESMTPS id BE95C60900 for ; Wed, 20 Sep 2017 09:01:33 +0000 (UTC) Received: from mxback1g.mail.yandex.net (mxback1g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:162]) by forward103j.mail.yandex.net (Yandex) with ESMTP id D229334C30D8 for ; Wed, 20 Sep 2017 12:00:59 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id WqhqLbeHQk-0rQqXxiB; Wed, 20 Sep 2017 12:00:53 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Dmm7iA3uiT-0qNuGm7R; Wed, 20 Sep 2017 12:00:52 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 20 Sep 2017 12:00:14 +0300 Message-Id: <1505898014-18011-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> References: <1505898014-18011-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v5 10/10] linux-gen: pktio: dpdk: minor code refactory 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Rename implementation specific data structure and move its dedicated header file to impl local, decouple it from pktio_entry_t data structure. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Bogdan Pricope Reviewed-by: Josep Puigdemont Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437 **/ platform/linux-dpdk/Makefile.am | 4 +- .../linux-dpdk/include/odp_packet_io_internal.h | 25 +--- platform/linux-dpdk/odp_init.c | 2 +- .../linux-dpdk/{odp_packet_dpdk.c => pktio/dpdk.c} | 127 ++++++++++++++------- .../{include/odp_packet_dpdk.h => pktio/dpdk.h} | 21 +++- platform/linux-dpdk/pool/dpdk.c | 2 +- platform/linux-generic/Makefile.am | 4 +- .../linux-generic/include/odp_packet_io_internal.h | 5 - .../include/odp_pktio_ops_subsystem.h | 1 + .../pktio/{pktio_common.c => common.c} | 0 platform/linux-generic/pktio/dpdk.c | 94 ++++++++++----- .../{include/odp_packet_dpdk.h => pktio/dpdk.h} | 6 +- 12 files changed, 182 insertions(+), 109 deletions(-) rename platform/linux-dpdk/{odp_packet_dpdk.c => pktio/dpdk.c} (86%) rename platform/linux-dpdk/{include/odp_packet_dpdk.h => pktio/dpdk.h} (59%) rename platform/linux-generic/pktio/{pktio_common.c => common.c} (100%) rename platform/linux-generic/{include/odp_packet_dpdk.h => pktio/dpdk.h} (96%) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 3522f5cd0..cb0d722d3 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -188,7 +188,7 @@ noinst_HEADERS = \ ${top_srcdir}/platform/linux-generic/include/odp_crypto_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_forward_typedefs_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_internal.h \ - ${srcdir}/include/odp_packet_dpdk.h \ + ${srcdir}/pktio/dpdk.h \ ${srcdir}/include/odp_packet_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_ipc.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ @@ -245,7 +245,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ ../linux-generic/odp_ipsec.c \ ../linux-generic/odp_name_table.c \ odp_packet.c \ - odp_packet_dpdk.c \ + pktio/dpdk.c \ pktio/subsystem.c \ odp_packet_flags.c \ ../linux-generic/odp_packet_io.c \ diff --git a/platform/linux-dpdk/include/odp_packet_io_internal.h b/platform/linux-dpdk/include/odp_packet_io_internal.h index ba388c9c2..ec1d0c213 100644 --- a/platform/linux-dpdk/include/odp_packet_io_internal.h +++ b/platform/linux-dpdk/include/odp_packet_io_internal.h @@ -29,7 +29,7 @@ extern "C" { #define PKTIO_MAX_QUEUES 64 #include -#include +#include /* Forward declaration */ typedef union pktio_entry_u pktio_entry_t; @@ -40,26 +40,6 @@ typedef union pktio_entry_u pktio_entry_t; #define PKTIN_INVALID ((odp_pktin_queue_t) {ODP_PKTIO_INVALID, 0}) #define PKTOUT_INVALID ((odp_pktout_queue_t) {ODP_PKTIO_INVALID, 0}) -/* Forward declaration */ -struct pkt_dpdk_t; - -/** Packet socket using dpdk mmaped rings for both Rx and Tx */ -typedef struct { - odp_pktio_capability_t capa; /**< interface capabilities */ - - /********************************/ - char ifname[32]; - uint8_t min_rx_burst; - uint8_t portid; - odp_bool_t vdev_sysc_promisc; /**< promiscuous mode defined with - system call */ - odp_pktin_hash_proto_t hash; /**< Packet input hash protocol */ - odp_bool_t lockless_rx; /**< no locking for rx */ - odp_bool_t lockless_tx; /**< no locking for tx */ - odp_ticketlock_t rx_lock[PKTIO_MAX_QUEUES]; /**< RX queue locks */ - odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES]; /**< TX queue locks */ -} pkt_dpdk_t; - struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ pktio_ops_data_t ops_data; @@ -68,9 +48,6 @@ struct pktio_entry { odp_ticketlock_t txl; /**< TX ticketlock */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ - union { - pkt_dpdk_t pkt_dpdk; /**< using DPDK API for IO */ - }; enum { /* Not allocated */ PKTIO_STATE_FREE = 0, diff --git a/platform/linux-dpdk/odp_init.c b/platform/linux-dpdk/odp_init.c index 737b53316..1d1c451ab 100644 --- a/platform/linux-dpdk/odp_init.c +++ b/platform/linux-dpdk/odp_init.c @@ -5,13 +5,13 @@ */ #include -#include #include #include #include #include #include #include +#include #include #include #include diff --git a/platform/linux-dpdk/odp_packet_dpdk.c b/platform/linux-dpdk/pktio/dpdk.c similarity index 86% rename from platform/linux-dpdk/odp_packet_dpdk.c rename to platform/linux-dpdk/pktio/dpdk.c index b9b493efe..d7a90197a 100644 --- a/platform/linux-dpdk/odp_packet_dpdk.c +++ b/platform/linux-dpdk/pktio/dpdk.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -39,6 +39,18 @@ static pktio_ops_module_t dpdk_pktio_ops; static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry); +static inline pktio_ops_dpdk_data_t * + __retrieve_op_data(pktio_entry_t *pktio) +{ + return (pktio_ops_dpdk_data_t *)(pktio->ops_data(dpdk)); +} + +static inline void __release_op_data(pktio_entry_t *pktio) +{ + free(pktio->ops_data(dpdk)); + pktio->ops_data(dpdk) = NULL; +} + /* Test if s has only digits or not. Dpdk pktio uses only digits.*/ static int _dpdk_netdev_is_valid(const char *s) { @@ -95,6 +107,8 @@ static void _dpdk_print_port_mac(uint8_t portid) static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, const odp_pktin_queue_param_t *p) { + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_pktin_mode_t mode = pktio_entry->s.param.in_mode; /** @@ -102,19 +116,19 @@ static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, * at a time polls a queue */ if (mode == ODP_PKTIN_MODE_SCHED || p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) - pktio_entry->s.pkt_dpdk.lockless_rx = 1; + pkt_dpdk->lockless_rx = 1; else - pktio_entry->s.pkt_dpdk.lockless_rx = 0; + pkt_dpdk->lockless_rx = 0; if (p->hash_enable && p->num_queues > 1) { - pktio_entry->s.pkt_dpdk.hash = p->hash_proto; + pkt_dpdk->hash = p->hash_proto; } else { - pktio_entry->s.pkt_dpdk.hash.proto.ipv4_udp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv4_tcp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv4 = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6_udp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6_tcp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6 = 1; + pkt_dpdk->hash.proto.ipv4_udp = 1; + pkt_dpdk->hash.proto.ipv4_tcp = 1; + pkt_dpdk->hash.proto.ipv4 = 1; + pkt_dpdk->hash.proto.ipv6_udp = 1; + pkt_dpdk->hash.proto.ipv6_tcp = 1; + pkt_dpdk->hash.proto.ipv6 = 1; } return 0; @@ -123,7 +137,8 @@ static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, static int output_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, const odp_pktout_queue_param_t *p) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) pkt_dpdk->lockless_tx = 1; @@ -133,12 +148,14 @@ static int output_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, return 0; } -static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_entry, - const char *netdev, odp_pool_t pool ODP_UNUSED) +static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, + pktio_entry_t *pktio_entry, + const char *netdev, + odp_pool_t pool ODP_UNUSED) { uint8_t portid = 0; struct rte_eth_dev_info dev_info; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = NULL; int i; if (!_dpdk_netdev_is_valid(netdev)) { @@ -147,6 +164,14 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_ent return -1; } + pktio_entry->ops_data(dpdk) = malloc(sizeof(pktio_ops_dpdk_data_t)); + pkt_dpdk = __retrieve_op_data(pktio_entry); + + if (odp_unlikely(pkt_dpdk == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct"); + return -1; + } + portid = atoi(netdev); pkt_dpdk->portid = portid; memset(&dev_info, 0, sizeof(struct rte_eth_dev_info)); @@ -176,17 +201,21 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_ent static int close_pkt_dpdk(pktio_entry_t *pktio_entry) { - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (pktio_entry->s.state == PKTIO_STATE_STOPPED) rte_eth_dev_close(pkt_dpdk->portid); + + __release_op_data(pktio_entry); return 0; } static int start_pkt_dpdk(pktio_entry_t *pktio_entry) { int ret, i; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint8_t portid = pkt_dpdk->portid; int sid = rte_eth_dev_socket_id(pkt_dpdk->portid); int socket_id = sid < 0 ? 0 : sid; @@ -294,7 +323,9 @@ static int start_pkt_dpdk(pktio_entry_t *pktio_entry) static int stop_pkt_dpdk(pktio_entry_t *pktio_entry) { - rte_eth_dev_stop(pktio_entry->s.pkt_dpdk.portid); + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_dev_stop(pkt_dpdk->portid); return 0; } @@ -335,16 +366,15 @@ static void _odp_pktio_send_completion(pktio_entry_t *pktio_entry) odp_ticketlock_unlock(&entry->s.txl); } } - - return; } static int recv_pkt_dpdk(pktio_entry_t *pktio_entry, int index, odp_packet_t pkt_table[], int len) { uint16_t nb_rx, i; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_packet_t *saved_pkt_table; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; uint8_t min = pkt_dpdk->min_rx_burst; odp_time_t ts_val; odp_time_t *ts = NULL; @@ -459,7 +489,8 @@ static int send_pkt_dpdk(pktio_entry_t *pktio_entry, int index, const odp_packet_t pkt_table[], int len) { int pkts; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (!pkt_dpdk->lockless_tx) odp_ticketlock_lock(&pkt_dpdk->tx_lock[index]); @@ -511,10 +542,12 @@ static uint32_t _dpdk_vdev_mtu(uint8_t port_id) static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry) { + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint16_t mtu = 0; int ret; - ret = rte_eth_dev_get_mtu(pktio_entry->s.pkt_dpdk.portid, &mtu); + ret = rte_eth_dev_get_mtu(pkt_dpdk->portid, &mtu); if (ret < 0) return 0; @@ -522,7 +555,7 @@ static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry) * try to use system call if dpdk cannot get mtu value. */ if (mtu == 0) - mtu = _dpdk_vdev_mtu(pktio_entry->s.pkt_dpdk.portid); + mtu = _dpdk_vdev_mtu(pkt_dpdk->portid); return mtu; } @@ -570,13 +603,16 @@ static int _dpdk_vdev_promisc_mode_set(uint8_t port_id, int enable) static int promisc_mode_set_pkt_dpdk(pktio_entry_t *pktio_entry, int enable) { - uint8_t portid = pktio_entry->s.pkt_dpdk.portid; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + uint8_t portid = pkt_dpdk->portid; + if (enable) rte_eth_promiscuous_enable(portid); else rte_eth_promiscuous_disable(portid); - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) { + if (pkt_dpdk->vdev_sysc_promisc) { int ret = _dpdk_vdev_promisc_mode_set(portid, enable); if (ret < 0) ODP_DBG("vdev promisc mode fail\n"); @@ -605,23 +641,27 @@ static int _dpdk_vdev_promisc_mode(uint8_t port_id) if (ifr.ifr_flags & IFF_PROMISC) { ODP_DBG("promisc is 1\n"); return 1; - } else - return 0; + } + return 0; } static int promisc_mode_get_pkt_dpdk(pktio_entry_t *pktio_entry) { - uint8_t portid = pktio_entry->s.pkt_dpdk.portid; - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + uint8_t portid = pkt_dpdk->portid; + + if (pkt_dpdk->vdev_sysc_promisc) return _dpdk_vdev_promisc_mode(portid); else return rte_eth_promiscuous_get(portid); - } static int mac_get_pkt_dpdk(pktio_entry_t *pktio_entry, void *mac_addr) { - rte_eth_macaddr_get(pktio_entry->s.pkt_dpdk.portid, + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_macaddr_get(pkt_dpdk->portid, (struct ether_addr *)mac_addr); return ETH_ALEN; } @@ -630,14 +670,18 @@ static int mac_get_pkt_dpdk(pktio_entry_t *pktio_entry, void *mac_addr) static int capability_pkt_dpdk(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa) { - *capa = pktio_entry->s.pkt_dpdk.capa; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + *capa = pkt_dpdk->capa; return 0; } static int link_status_pkt_dpdk(pktio_entry_t *pktio_entry) { + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); struct rte_eth_link link; - rte_eth_link_get(pktio_entry->s.pkt_dpdk.portid, &link); + rte_eth_link_get(pkt_dpdk->portid, &link); return link.link_status; } @@ -657,25 +701,28 @@ static void stats_convert(struct rte_eth_stats *rte_stats, static int stats_pkt_dpdk(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats) { + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); int ret; struct rte_eth_stats rte_stats; - ret = rte_eth_stats_get(pktio_entry->s.pkt_dpdk.portid, &rte_stats); + ret = rte_eth_stats_get(pkt_dpdk->portid, &rte_stats); if (ret == 0) { stats_convert(&rte_stats, stats); return 0; - } else { - if (ret > 0) - return -ret; - else - return ret; } + + if (ret > 0) + return -ret; + return ret; } static int stats_reset_pkt_dpdk(pktio_entry_t *pktio_entry) { - rte_eth_stats_reset(pktio_entry->s.pkt_dpdk.portid); + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_stats_reset(pkt_dpdk->portid); return 0; } diff --git a/platform/linux-dpdk/include/odp_packet_dpdk.h b/platform/linux-dpdk/pktio/dpdk.h similarity index 59% rename from platform/linux-dpdk/include/odp_packet_dpdk.h rename to platform/linux-dpdk/pktio/dpdk.h index 495d5e6f1..064c5d8ce 100644 --- a/platform/linux-dpdk/include/odp_packet_dpdk.h +++ b/platform/linux-dpdk/pktio/dpdk.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_DPDK_H -#define ODP_PACKET_DPDK_H +#ifndef ODP_PKTIO_OPS_DPDK_H_ +#define ODP_PKTIO_OPS_DPDK_H_ #include #include @@ -46,4 +46,21 @@ #define RTE_TEST_RX_DESC_DEFAULT 128 #define RTE_TEST_TX_DESC_DEFAULT 512 +/** Packet socket using dpdk mmaped rings for both Rx and Tx */ +typedef struct { + odp_pktio_capability_t capa; /**< interface capabilities */ + + /********************************/ + char ifname[32]; + uint8_t min_rx_burst; + uint8_t portid; + odp_bool_t vdev_sysc_promisc; /**< promiscuous mode defined with + system call */ + odp_pktin_hash_proto_t hash; /**< Packet input hash protocol */ + odp_bool_t lockless_rx; /**< no locking for rx */ + odp_bool_t lockless_tx; /**< no locking for tx */ + odp_ticketlock_t rx_lock[PKTIO_MAX_QUEUES]; /**< RX queue locks */ + odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES]; /**< TX queue locks */ +} pktio_ops_dpdk_data_t; + #endif diff --git a/platform/linux-dpdk/pool/dpdk.c b/platform/linux-dpdk/pool/dpdk.c index 6acc4e901..a9eca2f1c 100644 --- a/platform/linux-dpdk/pool/dpdk.c +++ b/platform/linux-dpdk/pool/dpdk.c @@ -26,7 +26,7 @@ #include /* for DPDK */ -#include +#include #ifdef POOL_USE_TICKETLOCK #include diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index b294dc4bb..7d1066f38 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -186,7 +186,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ - ${srcdir}/include/odp_packet_dpdk.h \ + ${srcdir}/pktio/dpdk.h \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ @@ -268,7 +268,7 @@ __LIB__libodp_linux_la_SOURCES = \ pktio/ethtool.c \ pktio/subsystem.c \ pktio/ipc.c \ - pktio/pktio_common.c \ + pktio/common.c \ pktio/loopback.c \ pktio/netmap.c \ pktio/dpdk.c \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 7c2833fc6..9fe9aeaa7 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -31,8 +31,6 @@ extern "C" { #include #define PKTIO_MAX_QUEUES 64 -#include - /* Forward declaration */ typedef union pktio_entry_u pktio_entry_t; #include @@ -56,9 +54,6 @@ struct pktio_entry { odp_ticketlock_t txl; /**< TX ticketlock */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ - union { - pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ - }; enum { /* Not allocated */ PKTIO_STATE_FREE = 0, diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 5c01e34f6..7a915b82c 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -90,6 +90,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { * TODO: refactory each implementation to hide it internally */ typedef union { + void *dpdk; pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; pktio_ops_netmap_data_t netmap; diff --git a/platform/linux-generic/pktio/pktio_common.c b/platform/linux-generic/pktio/common.c similarity index 100% rename from platform/linux-generic/pktio/pktio_common.c rename to platform/linux-generic/pktio/common.c diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index e72a76371..511c77783 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -20,9 +20,9 @@ #include #include -#include #include +#include #include #include @@ -32,6 +32,18 @@ #include #include +static inline pktio_ops_dpdk_data_t * + __retrieve_op_data(pktio_entry_t *pktio) +{ + return (pktio_ops_dpdk_data_t *)(pktio->ops_data(dpdk)); +} + +static inline void __release_op_data(pktio_entry_t *pktio) +{ + free(pktio->ops_data(dpdk)); + pktio->ops_data(dpdk) = NULL; +} + #if ODP_DPDK_ZERO_COPY ODP_STATIC_ASSERT(CONFIG_PACKET_HEADROOM == RTE_PKTMBUF_HEADROOM, "ODP and DPDK headroom sizes not matching!"); @@ -310,10 +322,10 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, int i, j; int nb_pkts = 0; int alloc_len, num; - odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool; + odp_pool_t pool = __retrieve_op_data(pktio_entry)->pool; /* Allocate maximum sized packets */ - alloc_len = pktio_entry->s.pkt_dpdk.data_room; + alloc_len = __retrieve_op_data(pktio_entry)->data_room; num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num); if (num != mbuf_num) { @@ -385,7 +397,8 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry, struct rte_mbuf *mbuf_table[], const odp_packet_t pkt_table[], uint16_t num) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); int i, j; char *data; uint16_t pkt_len; @@ -430,7 +443,7 @@ static inline int mbuf_to_pkt_zero(pktio_entry_t *pktio_entry, void *data; int i; int nb_pkts = 0; - odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool; + odp_pool_t pool = __retrieve_op_data(pktio_entry)->pool; for (i = 0; i < mbuf_num; i++) { odp_packet_hdr_t parsed_hdr; @@ -487,7 +500,8 @@ static inline int pkt_to_mbuf_zero(pktio_entry_t *pktio_entry, const odp_packet_t pkt_table[], uint16_t num, uint16_t *seg_count) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); int i; *seg_count = 0; @@ -562,7 +576,8 @@ static uint32_t dpdk_vdev_mtu_get(uint8_t port_id) static uint32_t dpdk_mtu_get(pktio_entry_t *pktio_entry) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint32_t mtu = 0; if (rte_eth_dev_get_mtu(pkt_dpdk->port_id, (uint16_t *)&mtu)) @@ -655,7 +670,8 @@ static void rss_conf_to_hash_proto(struct rte_eth_rss_conf *rss_conf, static int dpdk_setup_port(pktio_entry_t *pktio_entry) { int ret; - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); struct rte_eth_rss_conf rss_conf; /* Always set some hash functions to enable DPDK RSS hash calculation */ @@ -697,7 +713,8 @@ static int dpdk_setup_port(pktio_entry_t *pktio_entry) static int dpdk_close(pktio_entry_t *pktio_entry) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); unsigned idx; unsigned i, j; @@ -715,6 +732,7 @@ static int dpdk_close(pktio_entry_t *pktio_entry) if (!ODP_DPDK_ZERO_COPY) rte_mempool_free(pkt_dpdk->pkt_pool); + __release_op_data(pktio_entry); return 0; } @@ -860,9 +878,9 @@ static int dpdk_input_queues_config(pktio_entry_t *pktio_entry, lockless = 0; if (p->hash_enable && p->num_queues > 1) - pktio_entry->s.pkt_dpdk.hash = p->hash_proto; + __retrieve_op_data(pktio_entry)->hash = p->hash_proto; - pktio_entry->s.pkt_dpdk.lockless_rx = lockless; + __retrieve_op_data(pktio_entry)->lockless_rx = lockless; return 0; } @@ -870,7 +888,8 @@ static int dpdk_input_queues_config(pktio_entry_t *pktio_entry, static int dpdk_output_queues_config(pktio_entry_t *pktio_entry, const odp_pktout_queue_param_t *p) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_bool_t lockless; if (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) @@ -886,7 +905,8 @@ static int dpdk_output_queues_config(pktio_entry_t *pktio_entry, static void dpdk_init_capability(pktio_entry_t *pktio_entry, struct rte_eth_dev_info *dev_info) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_pktio_capability_t *capa = &pkt_dpdk->capa; memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); @@ -909,7 +929,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, const char *netdev, odp_pool_t pool) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = NULL; struct rte_eth_dev_info dev_info; struct rte_mempool *pkt_pool; char pool_name[RTE_MEMPOOL_NAMESIZE]; @@ -937,6 +957,14 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, dpdk_initialized = 1; } + pktio_entry->ops_data(dpdk) = malloc(sizeof(pktio_ops_dpdk_data_t)); + pkt_dpdk = __retrieve_op_data(pktio_entry); + + if (odp_unlikely(pkt_dpdk == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct"); + return -1; + } + /* Init pktio entry */ memset(pkt_dpdk, 0, sizeof(*pkt_dpdk)); @@ -945,6 +973,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, if (rte_eth_dev_count() == 0) { ODP_ERR("No DPDK ports found\n"); + __release_op_data(pktio_entry); return -1; } @@ -953,6 +982,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, mtu = dpdk_mtu_get(pktio_entry); if (mtu == 0) { ODP_ERR("Failed to read interface MTU\n"); + __release_op_data(pktio_entry); return -1; } pkt_dpdk->mtu = mtu + _ODP_ETHHDR_LEN; @@ -989,6 +1019,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, } if (pkt_pool == NULL) { ODP_ERR("Cannot init mbuf packet pool\n"); + __release_op_data(pktio_entry); return -1; } @@ -1013,7 +1044,8 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, static int dpdk_start(pktio_entry_t *pktio_entry) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint8_t port_id = pkt_dpdk->port_id; int ret; unsigned i; @@ -1064,7 +1096,7 @@ static int dpdk_start(pktio_entry_t *pktio_entry) static int dpdk_stop(pktio_entry_t *pktio_entry) { - rte_eth_dev_stop(pktio_entry->s.pkt_dpdk.port_id); + rte_eth_dev_stop(__retrieve_op_data(pktio_entry)->port_id); return 0; } @@ -1072,7 +1104,8 @@ static int dpdk_stop(pktio_entry_t *pktio_entry) static int dpdk_recv(pktio_entry_t *pktio_entry, int index, odp_packet_t pkt_table[], int num) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); pkt_cache_t *rx_cache = &pkt_dpdk->rx_cache[index]; odp_time_t ts_val; odp_time_t *ts = NULL; @@ -1104,7 +1137,7 @@ static int dpdk_recv(pktio_entry_t *pktio_entry, int index, } else if ((unsigned)num < pkt_dpdk->min_rx_burst) { struct rte_mbuf *new_mbufs[pkt_dpdk->min_rx_burst]; - nb_rx = rte_eth_rx_burst(pktio_entry->s.pkt_dpdk.port_id, index, + nb_rx = rte_eth_rx_burst(pkt_dpdk->port_id, index, new_mbufs, pkt_dpdk->min_rx_burst); rx_cache->s.idx = 0; for (i = 0; i < nb_rx; i++) { @@ -1119,7 +1152,7 @@ static int dpdk_recv(pktio_entry_t *pktio_entry, int index, nb_rx = RTE_MIN(num, nb_rx); } else { - nb_rx = rte_eth_rx_burst(pktio_entry->s.pkt_dpdk.port_id, index, + nb_rx = rte_eth_rx_burst(pkt_dpdk->port_id, index, rx_mbufs, num); } @@ -1147,7 +1180,8 @@ static int dpdk_send(pktio_entry_t *pktio_entry, int index, const odp_packet_t pkt_table[], int num) { struct rte_mbuf *tx_mbufs[num]; - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint16_t seg_count = 0; int tx_pkts; int i; @@ -1210,16 +1244,16 @@ static int dpdk_send(pktio_entry_t *pktio_entry, int index, static int dpdk_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - rte_eth_macaddr_get(pktio_entry->s.pkt_dpdk.port_id, + rte_eth_macaddr_get(__retrieve_op_data(pktio_entry)->port_id, (struct ether_addr *)mac_addr); return ETH_ALEN; } static int dpdk_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - uint8_t port_id = pktio_entry->s.pkt_dpdk.port_id; + uint8_t port_id = __retrieve_op_data(pktio_entry)->port_id; - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) + if (__retrieve_op_data(pktio_entry)->vdev_sysc_promisc) return dpdk_vdev_promisc_mode_set(port_id, enable); if (enable) @@ -1232,9 +1266,9 @@ static int dpdk_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) static int dpdk_promisc_mode_get(pktio_entry_t *pktio_entry) { - uint8_t port_id = pktio_entry->s.pkt_dpdk.port_id; + uint8_t port_id = __retrieve_op_data(pktio_entry)->port_id; - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) + if (__retrieve_op_data(pktio_entry)->vdev_sysc_promisc) return dpdk_vdev_promisc_mode_get(port_id); else return rte_eth_promiscuous_get(port_id); @@ -1243,7 +1277,7 @@ static int dpdk_promisc_mode_get(pktio_entry_t *pktio_entry) static int dpdk_capability(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa) { - *capa = pktio_entry->s.pkt_dpdk.capa; + *capa = __retrieve_op_data(pktio_entry)->capa; return 0; } @@ -1253,7 +1287,8 @@ static int dpdk_link_status(pktio_entry_t *pktio_entry) memset(&link, 0, sizeof(struct rte_eth_link)); - rte_eth_link_get_nowait(pktio_entry->s.pkt_dpdk.port_id, &link); + rte_eth_link_get_nowait( + __retrieve_op_data(pktio_entry)->port_id, &link); return link.link_status; } @@ -1275,7 +1310,8 @@ static int dpdk_stats(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats) int ret; struct rte_eth_stats rte_stats; - ret = rte_eth_stats_get(pktio_entry->s.pkt_dpdk.port_id, &rte_stats); + ret = rte_eth_stats_get( + __retrieve_op_data(pktio_entry)->port_id, &rte_stats); if (ret == 0) { stats_convert(&rte_stats, stats); @@ -1286,7 +1322,7 @@ static int dpdk_stats(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats) static int dpdk_stats_reset(pktio_entry_t *pktio_entry) { - rte_eth_stats_reset(pktio_entry->s.pkt_dpdk.port_id); + rte_eth_stats_reset(__retrieve_op_data(pktio_entry)->port_id); return 0; } diff --git a/platform/linux-generic/include/odp_packet_dpdk.h b/platform/linux-generic/pktio/dpdk.h similarity index 96% rename from platform/linux-generic/include/odp_packet_dpdk.h rename to platform/linux-generic/pktio/dpdk.h index 5d80d84a3..7495b5965 100644 --- a/platform/linux-generic/include/odp_packet_dpdk.h +++ b/platform/linux-generic/pktio/dpdk.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_DPDK_H -#define ODP_PACKET_DPDK_H +#ifndef ODP_PKTIO_OPS_DPDK_H_ +#define ODP_PKTIO_OPS_DPDK_H_ #include #include @@ -63,6 +63,6 @@ typedef struct { odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES]; /**< TX queue locks */ /** cache for storing extra RX packets */ pkt_cache_t rx_cache[PKTIO_MAX_QUEUES]; -} pkt_dpdk_t; +} pktio_ops_dpdk_data_t; #endif