From patchwork Wed Sep 13 10:00:16 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: 112421 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp766106edi; Wed, 13 Sep 2017 03:05:20 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDHt+fOIPzC7g6cEjcwF5IgBLtRHwqcxmKvWEv58KSDGCrm73uUj6DZT5VqgxWZDq+uEqD7 X-Received: by 10.55.71.19 with SMTP id u19mr22291939qka.160.1505297120131; Wed, 13 Sep 2017 03:05:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297120; cv=none; d=google.com; s=arc-20160816; b=YeJGGI5QdOV+d4/A3HOM++hTIEz2vXlIghbC4lgSnD6NWOfUgqWel/7BUncFmaZIH1 X/+iCNjjcG32uysLtx3ftzVm5xmcTlk0GLXbhIXwl4PWkW9fFgFwo+4zMSu62mfXEmZw VCknmUlHNiBoCBF1W+CNrUXih7GxFeWa/pb67vXGvEWntXqHQPS7afpsFbK/+1IHKGRJ /T96og+/DoAsk1FSDy6cLnwUy0szQWJqQuLEf0FFsiC7wQKzNhNgQeC6CJGq0gZ0Yxwb y4HPOlU7SbBSXKNsBbnlDDqlCpVJRMLJuOZh2RvsZyB9u+Ubd9qmrKRBwPm+T2yamP3X bNgA== 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=zomaVHN7t6UMnOe7FgyBGirDKGT2GIPXWFYktTI8UNs=; b=IYN1x9gVYmABF6PZIJN1YqPG/rIe1p3xhIZHN284+jwzFg1m4SMlMTO1ZswI68SXF8 Ajxkqx8w5eZAh138IpTdAwXGQXfw3X3HoxWHkOCFTQlhvQPCAnYv7uIcioJNRNuRJsV6 urpKCRbCfJMRrAXi2DOUcqr36StQpTB4GUKQY90bn6gEuVpSfdXBUA0JCbqqVQxOGVl1 +cyCm2WYLjkX00LHu2K/PKJehSJWBdkB0jhSFOZLWqiGrAZgbTQPZ40oTR8bJGkNsy+m QXsS0MrRf2pCU6UzOJZII0GBWxyVHPLKdM/1q1u0xhm5H2tcm3fbgAgrz9TirCS5Dtt4 8nwA== 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 x51si14076561qtx.491.2017.09.13.03.05.19; Wed, 13 Sep 2017 03:05:20 -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 B6DB662CF0; Wed, 13 Sep 2017 10:05: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 B57D762C59; Wed, 13 Sep 2017 10:02:10 +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 22CFE60810; Wed, 13 Sep 2017 10:02:06 +0000 (UTC) Received: from forward102o.mail.yandex.net (forward102o.mail.yandex.net [37.140.190.182]) by lists.linaro.org (Postfix) with ESMTPS id F0F9360C6A for ; Wed, 13 Sep 2017 10:00:32 +0000 (UTC) Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward102o.mail.yandex.net (Yandex) with ESMTP id 8A14E5A020F0 for ; Wed, 13 Sep 2017 13:00:31 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Mgb5yFsaSS-0VW8X157; Wed, 13 Sep 2017 13:00:31 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0Vuu6mr0; Wed, 13 Sep 2017 13: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, 13 Sep 2017 13:00:16 +0300 Message-Id: <1505296826-16698-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 1/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 13 10:00:17 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: 112422 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp766762edi; Wed, 13 Sep 2017 03:06:03 -0700 (PDT) X-Google-Smtp-Source: AOwi7QB0XWSUoeKoeC11b6aUJj0zUak3A0PrWQA6/VWHuKumVrNRN8AHdyr+jYTN83upa7+HAyfy X-Received: by 10.55.22.218 with SMTP id 87mr23818056qkw.248.1505297163778; Wed, 13 Sep 2017 03:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297163; cv=none; d=google.com; s=arc-20160816; b=u/pQwsMd+OlmczDC9KNsMvDXkbM11TKpBtZpLukiyqtl7k+gxZeU/HctR/bVcycL0D 25owRmH9Bj7Cu+Ceeb0MMpcHkoS8hQe5RcZ5DS/teefqKtUL4SZKLOkvlHpB6BQdIv39 e1CkQFiEOikfY3tRwdxMBfATI0wEBTEsf+EsRvHvcaVWcVcRheetKAMfzQb+m7eGUZVe iOjt17bPBTTo9hpU9M+ACzqIacDqvl9ke1u2PJfmufBjta7LP8Ou5jixtnzxM0eCDPFz JnrhhFt/jhGq25Qeako1e3Y5DVqarMEuFTkNV7xn7Mi/BCiSBjYiVakC7mz3EbiU/6QA OO9w== 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=bXSgd1PC0LWYUC4wjYPado3hBdFJ3QqbQRdv+672h6g=; b=EAC8qv0vv9aQe8OqY8AmUqgZXHtV3hbFzb9Kl4BEMDOHRS8sAhRxQgmr+btZzKKfvT Ku9hk5LFYlzXvaXxi0Wc+UvCGwBQ/Iy1LG6cLKV9zlHL7+OGUbQperddPrxA/eSPki5C 39D/gDNZyQyLEbFy4XTvPE6FbQALFpiAo2ipMgnr9HxEViL0chk5DubPYWAvQXoIEp2H uObJ0LlfAnFIt22Nz+D19V04YfoqZ7EdWrzxgvhBc2RTfySlRKSHaGzK8WwQZ9x4kPh4 /tsFTBS3wh5UO9kscujnrDKr+dCbkrLUlkpcVBNUdiwxx9dL8ozreSMNXwuv63zHjc2E whHw== 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 w1si14747149qtw.531.2017.09.13.03.06.03; Wed, 13 Sep 2017 03:06:03 -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 6D28861BC5; Wed, 13 Sep 2017 10:06:03 +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 4703F62C5D; Wed, 13 Sep 2017 10:02:16 +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 D36B660C88; Wed, 13 Sep 2017 10:02:13 +0000 (UTC) Received: from forward102o.mail.yandex.net (forward102o.mail.yandex.net [37.140.190.182]) by lists.linaro.org (Postfix) with ESMTPS id 4838A60C88 for ; Wed, 13 Sep 2017 10:00:33 +0000 (UTC) Received: from mxback13g.mail.yandex.net (mxback13g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:92]) by forward102o.mail.yandex.net (Yandex) with ESMTP id 3900F5A05240 for ; Wed, 13 Sep 2017 13:00:32 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback13g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id yezmNcpzpw-0Wv4J0o7; Wed, 13 Sep 2017 13:00:32 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0VuK4Tn1; Wed, 13 Sep 2017 13: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, 13 Sep 2017 13:00:17 +0300 Message-Id: <1505296826-16698-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 2/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 13 10:00:18 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: 112424 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp768882edi; Wed, 13 Sep 2017 03:08:24 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDhX98M/GaOcaG2TNaKOXz6p3zDpljQHhNlY8995MBAFznYAIrhbC3Kbai0dn0C/B3kgEV5 X-Received: by 10.233.223.66 with SMTP id t63mr24427815qkf.7.1505297303901; Wed, 13 Sep 2017 03:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297303; cv=none; d=google.com; s=arc-20160816; b=0mQUz3gs+u/LDoQXQol5Bsx+HwHg1ALi7G/RzakYJ3LPG8A4GfhI1vfCULnJM/8HRr xzVm26TqdA2tMgtSjLykP/nVcUBKFztRSrn/9s2gUVk7DA9CEbEqOqjeaUS3iMpkNb+l F1nK/QmYVKTwGsPPG8m9a4As1xhRaeh5QgdrJlX94SBRfirltuJP49RD352hJSKeO5ip Z/IMucKy5YtFOh4HKLwpPsgoh9rRNuhfkzXWE3Ep/4PHkZyyLl1oUhCOP80IU0akBKso HIoeUhf8+yRv0XcawMjAHPxgPl7Ou9nn1nLkWCxekcgQ5C69sltvRJr1usXBqjCSA/0A tNUA== 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=jAFVPQxt5EWvVnnablBKAcJ/aXt6lfXGpN4XEJX+baM=; b=wPbcRQJk7EngLa8qZ/VvGzWicAXEceTnHeI3a+mr2jPxBrobKFn1h8qTCbXMVycGos tqcU5SdpcCp8o+l59GCqI2iOB+2fzvcGhCCpDb9egNAXFWu06LT6ywYT30ppMZ9Cni3I 9+tdVcsRn+9wv/n9bD8wIyaBoyIap4SCr5HW5Sn2vu0knnnzydcwMxdOBLHa2L54Dx3F hpJ7SVKkLxjDSkOVkRWQXavBTRyMhU2jQmYE6Prakx/lC6V41sJgchok+ph8AJnoykOO YeTJufKNWsYLaGFjxKxRUMMzdPAIXixq+ImxSWh2dCe1hLgsOr712NtpsCg23zI8iV/P SWTg== 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 f34si13266673qtb.426.2017.09.13.03.08.23; Wed, 13 Sep 2017 03:08:23 -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 8DFD662AE5; Wed, 13 Sep 2017 10:08:23 +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 27F2860D89; Wed, 13 Sep 2017 10:02: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 5D6D362CED; Wed, 13 Sep 2017 10:02:30 +0000 (UTC) Received: from forward105o.mail.yandex.net (forward105o.mail.yandex.net [37.140.190.183]) by lists.linaro.org (Postfix) with ESMTPS id D947560D89 for ; Wed, 13 Sep 2017 10:00:35 +0000 (UTC) Received: from mxback16j.mail.yandex.net (mxback16j.mail.yandex.net [IPv6:2a02:6b8:0:1619::92]) by forward105o.mail.yandex.net (Yandex) with ESMTP id 9A6AA4443CAD for ; Wed, 13 Sep 2017 13:00:33 +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 XuWXqaXpT9-0XIeWMAU; Wed, 13 Sep 2017 13:00:33 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0WuKNp5s; Wed, 13 Sep 2017 13:00:32 +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, 13 Sep 2017 13:00:18 +0300 Message-Id: <1505296826-16698-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 3/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 587d4836f..83931d27a 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -189,6 +189,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 \ @@ -242,6 +243,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..214116b76 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 = "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 cbbefa4e6..ff08a6ef4 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_pool_internal.h \ ${srcdir}/include/odp_pool_subsystem.h \ @@ -262,7 +263,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..39718a892 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 = "loopback", + .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..0a27316f2 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 13 10:00:19 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: 112423 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp767549edi; Wed, 13 Sep 2017 03:06:56 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBNtzF0xDcuHBhIanFhbzLjys05SyUJE9xHWQ5DMI1h5pAWl4cRtQCf7KHkadHS+t5r3N4f X-Received: by 10.200.43.123 with SMTP id 56mr24111695qtv.15.1505297215943; Wed, 13 Sep 2017 03:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297215; cv=none; d=google.com; s=arc-20160816; b=r8mpNXttqZmUEpRkL6V6dNV29Riyq/dGMBKz6KdTSsu4pezvy+2Xox/T/WgvlfJZLz IkGBlJaqPmVqnb1IekZCxuQxEHGlL1UWQhfBfDHz3LBx+wMSxaeg1ndi7gGCnO6vqtXz Fiz36mouxW+uBVtAOrqd5VJe500+0LsyU4RgnqQlf3cSbOm2iKvN+GPO9Pc0KKT1e29j x8tzXvRy9q6WBuDNvpzsuQU6GfaY/CK1P5SeS3TEj9QIC/E4yoEREsTl0wBLR2+/kMyb GULaWA2C25uWGYof5xYTp0yP5x3Ly1BjoRi4cYFlgfbCP+Zw4O/gUMpL3f184NO+RV3u 18HQ== 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=oxLvtgQeEVOuJCh66Xr8oOqX4P0c2ckN+RINZvNENmw=; b=N5LH+7TUKJ4Hi5n9flKrPR6qGii2slb5RPj/7QdJr3NQkeAJVLPAm0rBXTB9HkICFI ZyUOCe7BLZoi6wsn2P4UUhcJsbvA+GAAC5pYidyB7vHn6MQz8kA1ZD2GkjZoA95mxbjK v2nliRAK4LDZ52eG4jWK0+UoMrqQRN24gTev68oUkKTPTmXfXNLTPmYbn8ErpbHTVJjF ABWVpMKfSTSTOJizNcNCMZVkCesDyDCMC/UJeEhLmeTKuEv/hkwX5NKvW3bL+OC14CSt roeceEP354Tk/XTUKyC7+kWqvp9a37ZjN+hGpib0PK4IM7zQ0bIJoZ/SXwk+7riqPr8t m8Yg== 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 t28si7873129qth.47.2017.09.13.03.06.55; Wed, 13 Sep 2017 03:06:55 -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 9498960EC3; Wed, 13 Sep 2017 10:06:55 +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 C7D0C62CFA; Wed, 13 Sep 2017 10:02:36 +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 8563362CF5; Wed, 13 Sep 2017 10:02:22 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id BA7CC60D25 for ; Wed, 13 Sep 2017 10:00:35 +0000 (UTC) Received: from mxback4g.mail.yandex.net (mxback4g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:165]) by forward106o.mail.yandex.net (Yandex) with ESMTP id 689F978363E for ; Wed, 13 Sep 2017 13:00:34 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback4g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id cnhhikNUBq-0YICD7lk; Wed, 13 Sep 2017 13:00:34 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0Xui3PM4; Wed, 13 Sep 2017 13:00:33 +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, 13 Sep 2017 13:00:19 +0300 Message-Id: <1505296826-16698-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 4/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 83931d27a..4d5dff5d1 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -190,6 +190,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 \ @@ -246,7 +247,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.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 ff08a6ef4..1aaea84f7 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_pool_internal.h \ @@ -266,7 +267,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 39718a892..0c572338f 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 13 10:00:20 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: 112425 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp770983edi; Wed, 13 Sep 2017 03:11:00 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBnkycJyJl/LhRMwD+dv8DgDWaL5tjsnF0+pwafoVeHd2CZc+hD2u7tq+OFQQSYx5bWouc+ X-Received: by 10.55.81.215 with SMTP id f206mr21970596qkb.188.1505297460406; Wed, 13 Sep 2017 03:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297460; cv=none; d=google.com; s=arc-20160816; b=yf4ils0c+7BvK3kTcX1hqIPQpHGHlMbgQPw9hak0DIRRjs5+FNqwYgDPQLvwbgHx9n KGSRzQkBm4ozycjDD9i2bs3UUQZdrgEQps8fLPHezj6wDcIBNVuZCu6uhVv7NYTf6gly q6Ee9UoE24AlvzjnPXIpwmzD52nVo1+sjyWPeJJrunrcAbjcFM7qV3dMvyMuNTgt6UhQ lSsOtx5uhGJ7sOfnRv9R+qIh35YIwe3PB6TWUwiKhaTauLVqXhHjfIUJjkcxesTzhOTZ V3OAywTpRCo25pk4/MJviCI9Krrcd/Q/iEMJwxY1MyyNhX9SijUe26/C+VkaRwmLzVYr Dfzg== 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=1U/1wIKjVut1gPMpRf1zhZ6sby/4xOJQgP7c4y4JfCU=; b=S3J698iJJ+GUTvj/2SZT4dYTUqskH9IVO6/Nh2iDzaRcjGNViFkrGoDsYrdfX2gF5m zpCemr9mRhZkYjfdlVaGvwtV/5Is1JKJ+I40ASY9wRkivToAu1yw1YZb4GxQU3MZelDo TVai2LoHeWBbRriqGqJO63D9bmv9Lr3XDKKiprrLOpfXoJn1vh+dajfuwzBnsN8bval2 Xb78H5uXfkFI6rdLi4fqsG3B0dTXqBtXt5kBEEcGeUpB+gEwGJdR3vCfVxP1m11QyjiN Jmu8sFdk9GBwhnD4Ms5mq4Kwl+wcGu3jLJH3wYe33RxLOOnDz1duOUAnhI+tzqiZMgRy BC1A== 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 41si13178934qtb.475.2017.09.13.03.11.00; Wed, 13 Sep 2017 03:11:00 -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 E44AA62AE5; Wed, 13 Sep 2017 10:10:59 +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 7DA1D62D0A; Wed, 13 Sep 2017 10:02:50 +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 49A6B60D25; Wed, 13 Sep 2017 10:02:33 +0000 (UTC) Received: from forward106j.mail.yandex.net (forward106j.mail.yandex.net [5.45.198.249]) by lists.linaro.org (Postfix) with ESMTPS id 92A7460EC3 for ; Wed, 13 Sep 2017 10:00:36 +0000 (UTC) Received: from mxback8j.mail.yandex.net (mxback8j.mail.yandex.net [IPv6:2a02:6b8:0:1619::111]) by forward106j.mail.yandex.net (Yandex) with ESMTP id 92AA71805831 for ; Wed, 13 Sep 2017 13:00:35 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback8j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id jNj8sPO0HX-0Z4aLhnb; Wed, 13 Sep 2017 13:00:35 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0Yu8po7L; Wed, 13 Sep 2017 13:00:34 +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, 13 Sep 2017 13:00:20 +0300 Message-Id: <1505296826-16698-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 5/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 4d5dff5d1..9ebf2ea14 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -189,12 +189,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 1aaea84f7..dd8767b2f 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 13 10:00:21 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: 112426 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp772864edi; Wed, 13 Sep 2017 03:13:16 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDWBskK9fJ78e0qzaE+OxSOFy/vNPWQO0ciSeE34uBdmQcQgbO2BqzX9BSVB2BiaBROlofj X-Received: by 10.200.55.228 with SMTP id e33mr26566609qtc.170.1505297596517; Wed, 13 Sep 2017 03:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297596; cv=none; d=google.com; s=arc-20160816; b=OfYZeaxGPymLKX4+IoV4dF4Nmds+gZzH09pn9KwQleQ8XI1FusYyMge6Rb3ywaQq0Y B5Wtu2v7RqTN6gWSlJWaWm1iTbVzgW+Ag6+V5BFckR3TaGH84WH3p0BdyIbt6XzDRrF0 D68KRfvh3+WVeq62a/WQdW4Jc1pgVPQ44x/R6BBR27jLpreHUpuKeXkhzgUF/xVK0Wvj 7fa2n5IZOrrFbngEvuRs4TSsVva2EJcMwBM1fb7ohk8w9spsc+FM/nIMhtOKX5d1gUDo 65+YcdJHNl1XjZgba5MDXJjjue11tTTUfmQf+37rQ+Il2ZnnSo3lFS+Dre7uJbgau4U1 7bzg== 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=eWKftdJkKuw7tFNEEACcVRvbjDvRN87vHkiHK75rvDU=; b=K8siY3HV6jk10a9WvfF4IKaH2UhMXyWraliBBafEcLfzfSEv7wbQMUl91XotQvQdGG D+7GRpkMf+OkwnNF86PWs1yw0iIUk8kvJjFkq4l5EPHE+0a0sxTTjoAR1mgp+1HaGLGd 0hTZezQVSvvGnn3VX/TfGXwoTLTe0Q0TZsSY0Gqi/bQvqORrstwSvcpZdXWp2VpYQMG0 2cOtymcNLXEFrpyVr5wx/5zUQ7q6RyQCpFaugfKJ7tAiMPvP640PGST6/v0ji0dLVvOz ZxRjM+s0zh7G3hPQoFytyV6A0aTPBsdcCi3i/na3fojkThyeA8UIBO+E1dUVNzsfVxMl sLKg== 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 30si3503157qtq.176.2017.09.13.03.13.16; Wed, 13 Sep 2017 03:13:16 -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 34DF962CE0; Wed, 13 Sep 2017 10:13:16 +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 C4FD562D19; Wed, 13 Sep 2017 10:02:56 +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 23CB962D08; Wed, 13 Sep 2017 10:02:49 +0000 (UTC) Received: from forward106p.mail.yandex.net (forward106p.mail.yandex.net [77.88.28.109]) by lists.linaro.org (Postfix) with ESMTPS id 18CD060C1F for ; Wed, 13 Sep 2017 10:00:40 +0000 (UTC) Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward106p.mail.yandex.net (Yandex) with ESMTP id 6E1BF2D85460 for ; Wed, 13 Sep 2017 13:00:36 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id X6tHfYN4mi-0aWW6Fnt; Wed, 13 Sep 2017 13:00:36 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0ZuWarYG; Wed, 13 Sep 2017 13:00:35 +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, 13 Sep 2017 13:00:21 +0300 Message-Id: <1505296826-16698-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 6/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 dd8767b2f..1e05c2c50 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_pool_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 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 13 10:00:22 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: 112427 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp773877edi; Wed, 13 Sep 2017 03:14:33 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAr0MLU+upGM1INs0sTKiJ4+jsZBJdSgyBR9MRh7BJ3tA0fa0s45VxMJI5ejbX6OCIu0o26 X-Received: by 10.200.24.214 with SMTP id o22mr24291930qtk.123.1505297673359; Wed, 13 Sep 2017 03:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297673; cv=none; d=google.com; s=arc-20160816; b=NL/Cbkpp3g+x2YkSYnLltTDu2xHNYqtwhD4sbw0CJacKLebBKaMIPPpp97+SK5TalQ fo+8p/9oalXBUBDFeJHxZLDHddXRvwmWM8PrAPA/iuGLi+gbAeNYuYRcnhJPN64zYkLS 65QBaTwpkC4PjYcW5e/ijEDHNt0zqd6UQwasHhbbentp9y19ap1kGWXwEMCjZvVz8Bws zrGyPXOkMn6PX6y/6/rFfeOT+QFW0vb+77shq4aAvBb8mCGp4LWPARiok7+fp6+rfjEl 4KoF+l671L09vTlmsw1k49IwuRIqcAXByXMpyrtw/t9TniMKOztxejCqwKIm5v+HozOk 6GOg== 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=cRmQwm4ykL9XPe29VrxJ814SGpHdk1IUwDUax492aSA=; b=iLIGRXorYhkVi18dzaXMAITUsLFRY3Uut8hOSpxjbfgWXEb1OTC6dTxGkZRRnxQMUi maqesKrxgE1NDk62us+ghEhdwIoFW+fhbzx6Ppl01vHXrKa5PKoA95+RDHeZJdQWIign mAGz6lrgOZ7JRVhuqo58GMzL8isCdmVPkbtG9ikXzF8aX3m2LER+vi6eELp80cJlnhjZ I++mAqQSxZQuYCddECh/Xrexb1JwnCEcjRr0o/bb1b9BcpjWP5gvNDQK+2zBfXVj3Tm4 H+/fibpQ0DTskoSEfCS34yCJinfIE2tUvTBSqCeZ1Gqc+skwT6hL5JjFSRhrgl3C4wb+ yNuw== 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 s87si1837297qks.40.2017.09.13.03.14.33; Wed, 13 Sep 2017 03:14:33 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id ECCAE62C60; Wed, 13 Sep 2017 10:14:32 +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 194AA62D20; Wed, 13 Sep 2017 10:03:00 +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 C1A5860D7A; Wed, 13 Sep 2017 10:02:51 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id C940E60D7A for ; Wed, 13 Sep 2017 10:00:38 +0000 (UTC) Received: from mxback10o.mail.yandex.net (mxback10o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::24]) by forward102j.mail.yandex.net (Yandex) with ESMTP id 53CB95604856 for ; Wed, 13 Sep 2017 13:00:37 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback10o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id e3oiUJ33yu-0aVWou5Q; Wed, 13 Sep 2017 13:00:37 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0au8hBJn; Wed, 13 Sep 2017 13:00:36 +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, 13 Sep 2017 13:00:22 +0300 Message-Id: <1505296826-16698-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 7/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 | 30 +++++++++++++--------- 5 files changed, 46 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 1e05c2c50..78283c019 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_pool_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 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..b54501ed2 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,8 @@ 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 +184,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 +213,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 +274,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 +297,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 +366,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 +407,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 13 10:00:23 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: 112429 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp775731edi; Wed, 13 Sep 2017 03:16:59 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAMpKCG+KmozT+t+maEhB8MVMeRUkbIjlZR39lXBFtSHX5AE6fLgNa5dBDTWC+bByrLb+R/ X-Received: by 10.233.221.199 with SMTP id r190mr24406466qkf.174.1505297819255; Wed, 13 Sep 2017 03:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297819; cv=none; d=google.com; s=arc-20160816; b=mnrjgPikaRfFX8NrI78+vtmfFhdkiwR79SFmo89p92PYjksWrI/+LAl72gxuaqxN/Y +hnSstdyOel6Vro3hLdkLIaPWfVWlY05aIeRelPxOaqHIVphn64se/PC+IglqAAJ0MLp DeEKxBAQ7tr3AGBEBGTDwuA48TLGd5Q/fSKEUwKn9mI4dl6WzCis4/nHj4b42QZ0m/1a ebMTOZf9P1ItSZ4tkyPttGzFX0EQRHB6Mx6SVZALmfDCIEuWhuYaQtg5TFUq6ORd/9tm AAkIXRDFsnktgOc1nmw6kCU/6JOXtX40eshSFY45tt8MnCcaCit9xTmSEw5ngghxQIsx /EHQ== 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=Ntkegn7cNycHHqpR88Cl08NwhHN0VP2s/oeMtueqmRM=; b=KrZtmGlOf/iYVDucjXmxgS/78yFCnMTaRbT9O2pNL90O5BShpN1ZQjmIZARvVju16P fW9Dxbk9f5AG+EMfUpnc5+GSMw0CGUDo3+rXiOD0iQagEPgmIvNZtVB7Tc/MAiJYOZ7b Q+mTUpOd0ZwquRRF/JVsafrZWMmurHwP8hSvWpfl7smV72rBLAJuga/O0dm4NXC+fbeo /I7SDTlMIdafpQlTcginS0LZQcOW8bp3ryfsdhzDoDTwaHNxHXLOtseQde/B2NCIE2LP z0gV1s5bDAfg4Vi979+uBVRLCDGcE0vEHCs/sC1S2NtlyV7DuysUdLvbMp5DmER7ILhN K0Kg== 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 125si9299384qkl.164.2017.09.13.03.16.59; Wed, 13 Sep 2017 03:16:59 -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 DEA3F62CFA; Wed, 13 Sep 2017 10:16:58 +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 A5AE662D1B; Wed, 13 Sep 2017 10:03:17 +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 4F09F62D20; Wed, 13 Sep 2017 10:02:59 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id 27FD261CBB for ; Wed, 13 Sep 2017 10:00:40 +0000 (UTC) Received: from mxback16j.mail.yandex.net (mxback16j.mail.yandex.net [IPv6:2a02:6b8:0:1619::92]) by forward102j.mail.yandex.net (Yandex) with ESMTP id E973A560327A for ; Wed, 13 Sep 2017 13:00:38 +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 HcoveHP8av-0cIaNagf; Wed, 13 Sep 2017 13:00:38 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0buW2rWS; Wed, 13 Sep 2017 13:00:37 +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, 13 Sep 2017 13:00:23 +0300 Message-Id: <1505296826-16698-9-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 8/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 9ebf2ea14..9d32defd5 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -191,12 +191,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 78283c019..b3ee86c67 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_pool_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 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 0a27316f2..9054a835c 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 13 10:00:24 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: 112428 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp774943edi; Wed, 13 Sep 2017 03:15:56 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAVRnYsOqWMsVFqZ5OKcaH0E4qhjO/OP+WSs1afqDF4rvHHn/vGKf4tII6eJg7HJJlHMVKW X-Received: by 10.200.53.168 with SMTP id k37mr24022337qtb.237.1505297755956; Wed, 13 Sep 2017 03:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505297755; cv=none; d=google.com; s=arc-20160816; b=eElp5xcq1IlxQwS9BTWdZSWcnVMsNmHtY9SlFVfF6wL1L765A1HUHaaTAvQObnsYwF hO4MMmS5lsa5lHZXoO675S4q/NAorYsmRQIuVoaTsmRnKfo236q4vJRNgHNQ8zv2QIZV Zf4jZuaYGSBciay0HmehIEPwIEWrYngAcdAJwQ5DsSSuI0ujXvRWOtq5IdZyzDkZDGfx ZHrNwToORFMbjeRxoVCcfDWCucl2USyVAoJYFZ9m1PTyMSdgnfQCydrIM3cUlljSAdDu kQwe8b2cLXMT+hGRojX9EbmQzJI2JWrW4wWP5Tut4sLZ40w0muVOsCzEtG/EXUPSSPOk bLkA== 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=T84b0imtLCpMYwbd+Wk/qzpWNfLwp4B2w8VH2LA19Ig=; b=o+Zkg730PmwGqazA3kPioxWttcWMH5SsywoxJQ6QNFtpKOpTRqwZxCoE/0j5okubY2 Uu8j9Nfm92SA37fvfeiq8fCLrv0C9K+MRqTTIvaLtg6gsTwUVlPjptGg+NsF+/DJgzoL vaq4T3r0VY6K7/GDi0+7hvc/bPoES3f/Q5AM+OvjmPRLTCfsSWshgdvCAMWiTk7dNzHj 9ci5wK06JGe3xxnR2Y274EggA3dtGsKLvWFQiDoy0yY8uR/q4Io4u240YzIxZ0m+TJVF 4Ez3JOPHgGhTuilqdOKL/fHRYmKwHnNaV9gbHlrQJuyHUWORoffpb6ulbzZS/jpSuQWA sQeQ== 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 17si1327355qtd.441.2017.09.13.03.15.55; Wed, 13 Sep 2017 03:15:55 -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 E3D1862CF5; Wed, 13 Sep 2017 10:15:54 +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 5809262DF4; Wed, 13 Sep 2017 10:03:06 +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 A0D2E62D11; Wed, 13 Sep 2017 10:02:56 +0000 (UTC) Received: from forward101j.mail.yandex.net (forward101j.mail.yandex.net [5.45.198.241]) by lists.linaro.org (Postfix) with ESMTPS id 371C161BC5 for ; Wed, 13 Sep 2017 10:00:41 +0000 (UTC) Received: from mxback7j.mail.yandex.net (mxback7j.mail.yandex.net [IPv6:2a02:6b8:0:1619::110]) by forward101j.mail.yandex.net (Yandex) with ESMTP id E64A51243F59 for ; Wed, 13 Sep 2017 13:00:39 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback7j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Ghz5AnMGnl-0d1mYTUZ; Wed, 13 Sep 2017 13:00:39 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0duuMSji; Wed, 13 Sep 2017 13:00:39 +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, 13 Sep 2017 13:00:24 +0300 Message-Id: <1505296826-16698-10-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 9/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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 b3ee86c67..6261cf0a6 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_pool_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 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 13 10:00:25 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: 112432 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp781106edi; Wed, 13 Sep 2017 03:24:18 -0700 (PDT) X-Google-Smtp-Source: AOwi7QD8Cy7HnPGZouhxK151/zlGvcvY1v/PL1eRS07J0xCpSXfalkC7G8GcAw2I1mxzN2UhIne3 X-Received: by 10.237.36.146 with SMTP id t18mr17321793qtc.17.1505298258439; Wed, 13 Sep 2017 03:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505298258; cv=none; d=google.com; s=arc-20160816; b=I6D8XKDJldP3cRt03iZaOw0k94uf5y5jE8T3hzQa19EhSCBV/CxZ3LOEqFI/Ijwaxl xMLmM8Dq7J+mh5Kp+FZxgQMSuxhuLEqGwEpM84TQHEhN4L+5TlRrHThPlRmiL+QsE8t3 cPEHlG0hG3ckdxWVkDu6I291br1ZS5mO34+UcADa3pslSAqupWeTBQta2JNKRieKKbpO PzHKn2Fd0Yt/QLMMrEv6ONHy4qJ3SqbJOttGgXKh7q71B8p+HfJla7Rxa75DYE5A1y9G wFm5RoEUfQ0LUuGaaMj2gVtSI1rStm8hadEpTwgCy1SenWXs7OjdFzf71RpIj2YX0V52 zbGw== 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=AhzbandgyFpbh5aZPO7xq14NAJj1TP5scBi6ZGuc+P4=; b=0jRDSax4vUmlEjwZ8/Z4CKE4EMp1XhoF/yNI6QWUDOxtnOCnZF34b4Vx/Fvd56YHs/ YknKzNk6echl3MESO6ip+ms/YCCzsmEbBo5w54ju788CAhBdmgsDasoINoP1w8io5Jna AjBlZSBP+RsTsxB9v2jr1Qfz6TeKrjTB8kl0rREwQuDJPIEVTSAh5GEJJmLyOc0KWgbp ieke0B7tHTHT4P8xc5VVsZlmAO/hQsnuGsnCJDJy0t1Aua9UpAjTfnSmfTXLpkUHW9u+ C932wEmSTpq8n9sE1NfKk9jzrA0BfnK9xdCOAENb4Mvq69Q9dYkGji7bw5uLBHqrFm17 vUHw== 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 g124si13546345qkf.406.2017.09.13.03.24.18; Wed, 13 Sep 2017 03:24: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 0DDC862D32; Wed, 13 Sep 2017 10:24: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,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 63DDD6351E; Wed, 13 Sep 2017 10:03: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 6D91762BE4; Wed, 13 Sep 2017 10:03:33 +0000 (UTC) Received: from forward100o.mail.yandex.net (forward100o.mail.yandex.net [37.140.190.180]) by lists.linaro.org (Postfix) with ESMTPS id D6EDC622F0 for ; Wed, 13 Sep 2017 10:00:41 +0000 (UTC) Received: from mxback7o.mail.yandex.net (mxback7o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::21]) by forward100o.mail.yandex.net (Yandex) with ESMTP id CCB6A2A2477A for ; Wed, 13 Sep 2017 13:00:40 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback7o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id wnqf4jMFzs-0ef0Xs0C; Wed, 13 Sep 2017 13:00:40 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0duW8UHH; Wed, 13 Sep 2017 13:00:40 +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, 13 Sep 2017 13:00:25 +0300 Message-Id: <1505296826-16698-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 10/11] 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: 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ 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} (54%) 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 9d32defd5..f0d731213 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -187,7 +187,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 \ @@ -243,7 +243,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 cd7abce65..0a6eb4695 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 214116b76..0dda05a69 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 54% rename from platform/linux-dpdk/include/odp_packet_dpdk.h rename to platform/linux-dpdk/pktio/dpdk.h index 495d5e6f1..34841cdec 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 499bea127..0e1dfde70 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 6261cf0a6..5503535e4 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 \ @@ -267,7 +267,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 From patchwork Wed Sep 13 10:00:26 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: 112431 Delivered-To: patch@linaro.org Received: by 10.80.202.13 with SMTP id d13csp778800edi; Wed, 13 Sep 2017 03:21:08 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBIJMiMA6C3/HrW5/KcW/yxRDPbhHW3A4+IxR2CplEfnC8ou8L02UsMy0ONRnlIQRJSmRdT X-Received: by 10.200.26.40 with SMTP id v37mr23935640qtj.93.1505298068692; Wed, 13 Sep 2017 03:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505298068; cv=none; d=google.com; s=arc-20160816; b=nk2IneAYI3kiFm8ZUQYfrINZ6Q2jQtRIaHVfm8Fz1JXiTBOuhn3QLzXgC2tgto5bB5 mWkLjzFyOtWIo/aGidRRQcyU5xkdbLn6nlmCGLK8st21XHSzV47VZDwSQ+qu58jqfQ2a lT59AB0rILFeCfmFeRVsCbstSRChh6KktVCB6OBoz0F5K8z9iSE4UrOLLWqv0EKem69Y SumEbtOFgx7Scu82XCE2ZX/BI8eep6IWmWQqILJt/M8y+nUqenUlchKXDGQw4muZIrl/ g4Qkyu/umTSUQUdW1nwb/+77dELB+pfvIM27lPuoI85dhOJ+bBmAaF4wDCWLWxlEepn+ o3zg== 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=d9fxpdm2HjV8VrqFVS1GnmD8ciLlUthq7QMNux56kyo=; b=qdhEtFiVqUxFNzqFW0JzRjZx4HYCEr3R4mqbbLZhpVivkvzGCDEoO+8MoaFOQC4QrW fjt5SD3mqJlz7ZErQ43lp8sip9cndabnf86Ox/sYDhZw6VHUIdB+W3+4trghbd65hGWj npBMtUD0KGV7JPn/7n3ERMZ36PyQ+CEs2kKHq21ABOiEe9rXLRipA0L7Blvz9MLKIxBh DZdF9BzIoE6gAH9pWRehZVYqqJdt3zT0ghWX5cFD4T5DqddaPJbdlhm+nkNZKZcy6zMC Dtkm+ewO7HCWCZr5DdvZxB+QA9k05gRkGzjh1QFAE75Fd7moDS9tBLjATyNb4bUJE1xf VoMQ== 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 f13si13029182qte.215.2017.09.13.03.21.08; Wed, 13 Sep 2017 03:21:08 -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 45B4B62D0E; Wed, 13 Sep 2017 10:21:08 +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, 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 0BE2562AE4; Wed, 13 Sep 2017 10:03: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 5A98362F1C; Wed, 13 Sep 2017 10:03:30 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id 12F2762BE4 for ; Wed, 13 Sep 2017 10:00:43 +0000 (UTC) Received: from mxback3g.mail.yandex.net (mxback3g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:164]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 0E198419B5 for ; Wed, 13 Sep 2017 13:00:42 +0300 (MSK) Received: from smtp4p.mail.yandex.net (smtp4p.mail.yandex.net [2a02:6b8:0:1402::15:6]) by mxback3g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id EfdYDisZ9C-0fj8cUgw; Wed, 13 Sep 2017 13:00:42 +0300 Received: by smtp4p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id rI47ysBqG0-0euWlrrP; Wed, 13 Sep 2017 13:00:40 +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, 13 Sep 2017 13:00:26 +0300 Message-Id: <1505296826-16698-12-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> References: <1505296826-16698-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v2 11/11] linux-generic: discard generic dpdk pktio 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: Balakrishna Garapati Signed-off-by: Balakrishna Garapati --- /** 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: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: ca3c52d51e6e80ba4bde91670d8b48a8a7ae1500 **/ .travis.yml | 7 +- platform/linux-dpdk/m4/configure.m4 | 1 - platform/linux-generic/Makefile.am | 3 - .../linux-generic/include/odp_packet_internal.h | 7 - platform/linux-generic/m4/configure.m4 | 1 - platform/linux-generic/m4/odp_dpdk.m4 | 64 - platform/linux-generic/pktio/dpdk.c | 1371 -------------------- platform/linux-generic/pktio/dpdk.h | 68 - platform/linux-generic/pktio/subsystem.c | 6 - test/linux-generic/Makefile.am | 3 - .../linux-generic/validation/api/pktio/Makefile.am | 3 - 11 files changed, 3 insertions(+), 1531 deletions(-) delete mode 100644 platform/linux-generic/m4/odp_dpdk.m4 delete mode 100644 platform/linux-generic/pktio/dpdk.c delete mode 100644 platform/linux-generic/pktio/dpdk.h diff --git a/.travis.yml b/.travis.yml index 52339b537..d8235bdff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,7 +70,6 @@ env: - CONF="--enable-schedule-sp" - CONF="--enable-schedule-iquery" - CONF="--enable-schedule-scalable" - - CONF="--enable-dpdk-zero-copy" before_install: @@ -153,7 +152,7 @@ install: script: - ./bootstrap - - ./configure --prefix=$HOME/odp-install --enable-test-cpp --enable-test-vald --enable-test-helper --enable-test-perf --enable-user-guides --enable-test-perf-proc --enable-test-example --with-dpdk-path=`pwd`/dpdk/${TARGET} --with-netmap-path=`pwd`/netmap --with-cunit-path=$HOME/cunit-install/$CROSS_ARCH $CONF + - ./configure --prefix=$HOME/odp-install --enable-test-cpp --enable-test-vald --enable-test-helper --enable-test-perf --enable-user-guides --enable-test-perf-proc --enable-test-example --with-netmap-path=`pwd`/netmap --with-cunit-path=$HOME/cunit-install/$CROSS_ARCH $CONF - make -j $(nproc) - mkdir /dev/shm/odp - sudo LD_LIBRARY_PATH="$HOME/cunit-install/$CROSS_ARCH/lib:$LD_LIBRARY_PATH" ODP_SHM_DIR=/dev/shm/odp make check @@ -230,7 +229,7 @@ jobs: compiler: gcc script: - ./bootstrap - - ./configure --prefix=$HOME/odp-install --enable-test-cpp --enable-test-vald --enable-test-helper --enable-test-perf --enable-user-guides --enable-test-perf-proc --enable-test-example --with-dpdk-path=`pwd`/dpdk/${TARGET} --with-netmap-path=`pwd`/netmap CFLAGS="-O0 -coverage" --with-cunit-path=$HOME/cunit-install/$CROSS_ARCH CXXFLAGS="-O0 -coverage" LDFLAGS="--coverage" + - ./configure --prefix=$HOME/odp-install --enable-test-cpp --enable-test-vald --enable-test-helper --enable-test-perf --enable-user-guides --enable-test-perf-proc --enable-test-example --with-netmap-path=`pwd`/netmap CFLAGS="-O0 -coverage" --with-cunit-path=$HOME/cunit-install/$CROSS_ARCH CXXFLAGS="-O0 -coverage" LDFLAGS="--coverage" - sudo LD_LIBRARY_PATH="$HOME/cunit-install/$CROSS_ARCH/lib:$LD_LIBRARY_PATH" PATH=${PATH//:\.\/node_modules\/\.bin/} make check - find . -type f -iname '*.[ch]' -not -path ".git/*" -execdir gcov {} \; ; bash <(curl -s https://codecov.io/bash) -X coveragepy - stage: test @@ -262,7 +261,7 @@ jobs: compiler: gcc script: - ./bootstrap - - ./configure --with-platform=linux-dpdk --enable-test-cpp --enable-test-vald --enable-test-helper --enable-test-perf --enable-user-guides --enable-test-perf-proc --enable-test-example --with-sdk-install-path=`pwd`/dpdk/${TARGET} --with-cunit-path=$HOME/cunit-install/$CROSS_ARCH $CONF + - ./configure --with-platform=linux-dpdk --enable-test-cpp --enable-test-vald --enable-test-helper --enable-test-perf --enable-user-guides --enable-test-perf-proc --enable-test-example --with-sdk-install-path=`pwd`/dpdk/${TARGET} --enable-debug-print --with-cunit-path=$HOME/cunit-install/$CROSS_ARCH $CONF - make -j $(nproc) - sudo LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" make check after_failure: diff --git a/platform/linux-dpdk/m4/configure.m4 b/platform/linux-dpdk/m4/configure.m4 index 428ecc82e..ad3753efd 100644 --- a/platform/linux-dpdk/m4/configure.m4 +++ b/platform/linux-dpdk/m4/configure.m4 @@ -80,7 +80,6 @@ AC_SUBST([ATOMIC_LIBS]) # linux-generic pktio at all. And DPDK has its own PCAP support anyway AM_CONDITIONAL([HAVE_PCAP], [false]) AM_CONDITIONAL([netmap_support], [false]) -AM_CONDITIONAL([PKTIO_DPDK], [false]) m4_include([platform/linux-dpdk/m4/odp_pthread.m4]) m4_include([platform/linux-dpdk/m4/odp_timer.m4]) m4_include([platform/linux-dpdk/m4/odp_openssl.m4]) diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 5503535e4..50a30ac07 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -186,7 +186,6 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.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 \ @@ -270,7 +269,6 @@ __LIB__libodp_linux_la_SOURCES = \ pktio/common.c \ pktio/loopback.c \ pktio/netmap.c \ - pktio/dpdk.c \ pktio/socket.c \ pktio/socket_mmap.c \ pktio/sysfs.c \ @@ -358,7 +356,6 @@ __LIB__libodp_linux_la_SOURCES += ../../frameworks/modular/odp_module.c __LIB__libodp_linux_la_LIBADD = $(ATOMIC_LIBS) __LIB__libodp_linux_la_LIBADD += $(OPENSSL_LIBS) -__LIB__libodp_linux_la_LIBADD += $(DPDK_LIBS) $(DPDK_PMDS) __LIB__libodp_linux_la_LIBADD += $(PTHREAD_LIBS) __LIB__libodp_linux_la_LIBADD += $(TIMER_LIBS) __LIB__libodp_linux_la_LIBADD += $(LIBCONFIG_LIBS) diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 91fba1eac..ff7042b05 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -152,13 +152,6 @@ typedef struct odp_packet_hdr_t { /* Result for crypto packet op */ odp_crypto_packet_result_t crypto_op_result; -#ifdef ODP_PKTIO_DPDK - /* Type of extra data */ - uint8_t extra_type; - /* Extra space for packet descriptors. E.g. DPDK mbuf */ - uint8_t extra[PKT_EXTRA_LEN] ODP_ALIGNED_CACHE; -#endif - /* Packet data storage */ uint8_t data[0]; } odp_packet_hdr_t; diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4 index 85d35f253..7862c6574 100644 --- a/platform/linux-generic/m4/configure.m4 +++ b/platform/linux-generic/m4/configure.m4 @@ -83,7 +83,6 @@ m4_include([platform/linux-generic/m4/odp_openssl.m4]) m4_include([platform/linux-generic/m4/odp_pcap.m4]) m4_include([platform/linux-generic/m4/odp_modules.m4]) m4_include([platform/linux-generic/m4/odp_netmap.m4]) -m4_include([platform/linux-generic/m4/odp_dpdk.m4]) m4_include([platform/linux-generic/m4/odp_schedule.m4]) AC_CONFIG_FILES([platform/linux-generic/Makefile diff --git a/platform/linux-generic/m4/odp_dpdk.m4 b/platform/linux-generic/m4/odp_dpdk.m4 deleted file mode 100644 index cebf10287..000000000 --- a/platform/linux-generic/m4/odp_dpdk.m4 +++ /dev/null @@ -1,64 +0,0 @@ -########################################################################## -# Enable DPDK support -########################################################################## -pktio_dpdk_support=no -AC_ARG_WITH([dpdk-path], -AC_HELP_STRING([--with-dpdk-path=DIR path to dpdk build directory]), - [DPDK_PATH="$withval" - DPDK_CPPFLAGS="-msse4.2 -isystem $DPDK_PATH/include" - pktio_dpdk_support=yes],[]) - -########################################################################## -# Enable zero-copy DPDK pktio -########################################################################## -zero_copy=0 -AC_ARG_ENABLE([dpdk-zero-copy], - [ --enable-dpdk-zero-copy enable experimental zero-copy DPDK pktio mode], - [if test x$enableval = xyes; then - zero_copy=1 - fi]) - -########################################################################## -# Save and set temporary compilation flags -########################################################################## -OLD_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="$DPDK_CPPFLAGS $CPPFLAGS" - -########################################################################## -# Check for DPDK availability -# -# DPDK pmd drivers are not linked unless the --whole-archive option is -# used. No spaces are allowed between the --whole-arhive flags. -########################################################################## -if test x$pktio_dpdk_support = xyes -then - AC_CHECK_HEADERS([rte_config.h], [], - [AC_MSG_FAILURE(["can't find DPDK header"])]) - - AS_VAR_SET([DPDK_PMDS], [-Wl,--whole-archive,]) - for filename in "$DPDK_PATH"/lib/librte_pmd_*.a; do - cur_driver=`basename "$filename" .a | sed -e 's/^lib//'` - # rte_pmd_nfp has external dependencies which break linking - if test "$cur_driver" = "rte_pmd_nfp"; then - echo "skip linking rte_pmd_nfp" - else - AS_VAR_APPEND([DPDK_PMDS], [-l$cur_driver,]) - fi - done - AS_VAR_APPEND([DPDK_PMDS], [--no-whole-archive]) - - ODP_CFLAGS="$ODP_CFLAGS -DODP_PKTIO_DPDK -DODP_DPDK_ZERO_COPY=$zero_copy" - DPDK_LIBS="-L$DPDK_PATH/lib -ldpdk -lpthread -ldl -lpcap -lm" - AC_SUBST([DPDK_CPPFLAGS]) - AC_SUBST([DPDK_LIBS]) - AC_SUBST([DPDK_PMDS]) -else - pktio_dpdk_support=no -fi - -########################################################################## -# Restore old saved variables -########################################################################## -CPPFLAGS=$OLD_CPPFLAGS - -AM_CONDITIONAL([PKTIO_DPDK], [test x$pktio_dpdk_support = xyes ]) diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c deleted file mode 100644 index 511c77783..000000000 --- a/platform/linux-generic/pktio/dpdk.c +++ /dev/null @@ -1,1371 +0,0 @@ -/* Copyright (c) 2016, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifdef ODP_PKTIO_DPDK - -#include - -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#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!"); -ODP_STATIC_ASSERT(PKT_EXTRA_LEN >= sizeof(struct rte_mbuf), - "DPDK rte_mbuf won't fit in odp_packet_hdr_t.extra!"); -#endif - -static int disable_pktio; /** !0 this pktio disabled, 0 enabled */ - -/* Has dpdk_pktio_init() been called */ -static odp_bool_t dpdk_initialized; - -#define MEMPOOL_OPS(hdl) \ -extern void mp_hdlr_init_##hdl(void) - -MEMPOOL_OPS(ops_mp_mc); -MEMPOOL_OPS(ops_sp_sc); -MEMPOOL_OPS(ops_mp_sc); -MEMPOOL_OPS(ops_sp_mc); -MEMPOOL_OPS(ops_stack); - -/* - * This function is not called from anywhere, it's only purpose is to make sure - * that if ODP and DPDK are statically linked to an application, the GCC - * constructors of mempool handlers are linked as well. Otherwise the linker - * would omit them. It's not an issue with dynamic linking. */ -void refer_constructors(void); -void refer_constructors(void) -{ - mp_hdlr_init_ops_mp_mc(); - mp_hdlr_init_ops_sp_sc(); - mp_hdlr_init_ops_mp_sc(); - mp_hdlr_init_ops_sp_mc(); - mp_hdlr_init_ops_stack(); -} - -/** - * Calculate valid cache size for DPDK packet pool - */ -static unsigned cache_size(uint32_t num) -{ - unsigned size = 0; - unsigned i; - - if (!RTE_MEMPOOL_CACHE_MAX_SIZE) - return 0; - - i = ceil((double)num / RTE_MEMPOOL_CACHE_MAX_SIZE); - i = RTE_MAX(i, 2UL); - for (; i <= (num / 2); ++i) - if ((num % i) == 0) { - size = num / i; - break; - } - if (odp_unlikely(size > RTE_MEMPOOL_CACHE_MAX_SIZE || - (uint32_t)size * 1.5 > num)) { - ODP_ERR("Cache size calc failure: %d\n", size); - size = 0; - } - - return size; -} - -static inline uint16_t mbuf_data_off(struct rte_mbuf *mbuf, - odp_packet_hdr_t *pkt_hdr) -{ - return (uint64_t)pkt_hdr->buf_hdr.seg[0].data - - (uint64_t)mbuf->buf_addr; -} - -/** - * Update mbuf - * - * Called always before rte_mbuf is passed to DPDK. - */ -static inline void mbuf_update(struct rte_mbuf *mbuf, odp_packet_hdr_t *pkt_hdr, - uint16_t pkt_len) -{ - mbuf->data_len = pkt_len; - mbuf->pkt_len = pkt_len; - mbuf->refcnt = 1; - - if (odp_unlikely(pkt_hdr->buf_hdr.base_data != - pkt_hdr->buf_hdr.seg[0].data)) - mbuf->data_off = mbuf_data_off(mbuf, pkt_hdr); -} - -/** - * Initialize mbuf - * - * Called once per ODP packet. - */ -static void mbuf_init(struct rte_mempool *mp, struct rte_mbuf *mbuf, - odp_packet_hdr_t *pkt_hdr) -{ - void *buf_addr = pkt_hdr->buf_hdr.base_data - RTE_PKTMBUF_HEADROOM; - - rte_mem_lock_page(buf_addr); - - memset(mbuf, 0, sizeof(struct rte_mbuf)); - - mbuf->priv_size = 0; - mbuf->buf_addr = buf_addr; - mbuf->buf_physaddr = rte_mem_virt2phy(buf_addr); - if (odp_unlikely(mbuf->buf_physaddr == RTE_BAD_PHYS_ADDR)) - ODP_ABORT("Failed to map virt addr to phy"); - - mbuf->buf_len = (uint16_t)rte_pktmbuf_data_room_size(mp); - mbuf->data_off = RTE_PKTMBUF_HEADROOM; - mbuf->pool = mp; - mbuf->refcnt = 1; - mbuf->nb_segs = 1; - mbuf->port = 0xff; - - /* Store ODP packet handle inside rte_mbuf */ - mbuf->userdata = packet_handle(pkt_hdr); - pkt_hdr->extra_type = PKT_EXTRA_TYPE_DPDK; -} - -/** - * Create custom DPDK packet pool - */ -static struct rte_mempool *mbuf_pool_create(const char *name, - pool_t *pool_entry) -{ - struct rte_mempool *mp; - struct rte_pktmbuf_pool_private mbp_priv; - unsigned elt_size; - unsigned num; - uint16_t data_room_size; - - num = pool_entry->num; - data_room_size = pool_entry->max_seg_len + CONFIG_PACKET_HEADROOM; - elt_size = sizeof(struct rte_mbuf) + (unsigned)data_room_size; - mbp_priv.mbuf_data_room_size = data_room_size; - mbp_priv.mbuf_priv_size = 0; - - mp = rte_mempool_create_empty(name, num, elt_size, cache_size(num), - sizeof(struct rte_pktmbuf_pool_private), - rte_socket_id(), 0); - if (mp == NULL) { - ODP_ERR("Failed to create empty DPDK packet pool\n"); - return NULL; - } - - if (rte_mempool_set_ops_byname(mp, "odp_pool", pool_entry)) { - ODP_ERR("Failed setting mempool operations\n"); - return NULL; - } - - rte_pktmbuf_pool_init(mp, &mbp_priv); - - if (rte_mempool_ops_alloc(mp)) { - ODP_ERR("Failed allocating mempool\n"); - return NULL; - } - - return mp; -} - -/* DPDK external memory pool operations */ - -static int pool_enqueue(struct rte_mempool *mp ODP_UNUSED, - void * const *obj_table, unsigned num) -{ - odp_packet_t pkt_tbl[num]; - unsigned i; - - if (odp_unlikely(num == 0)) - return 0; - - for (i = 0; i < num; i++) - pkt_tbl[i] = (odp_packet_t)((struct rte_mbuf *) - obj_table[i])->userdata; - - odp_packet_free_multi(pkt_tbl, num); - - return 0; -} - -static int pool_dequeue_bulk(struct rte_mempool *mp, void **obj_table, - unsigned num) -{ - odp_pool_t pool = (odp_pool_t)mp->pool_data; - pool_t *pool_entry = (pool_t *)mp->pool_config; - odp_packet_t packet_tbl[num]; - int pkts; - int i; - - pkts = packet_alloc_multi(pool, pool_entry->max_seg_len, packet_tbl, - num); - - if (odp_unlikely(pkts != (int)num)) { - if (pkts > 0) - odp_packet_free_multi(packet_tbl, pkts); - return -ENOENT; - } - - for (i = 0; i < pkts; i++) { - odp_packet_t pkt = packet_tbl[i]; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - struct rte_mbuf *mbuf = (struct rte_mbuf *) - (uintptr_t)pkt_hdr->extra; - if (pkt_hdr->extra_type != PKT_EXTRA_TYPE_DPDK) - mbuf_init(mp, mbuf, pkt_hdr); - obj_table[i] = mbuf; - } - - return 0; -} - -static int pool_alloc(struct rte_mempool *mp) -{ - pool_t *pool_entry = (pool_t *)mp->pool_config; - - mp->pool_data = pool_entry->pool_hdl; - mp->flags |= MEMPOOL_F_POOL_CREATED; - - return 0; -} - -static unsigned pool_get_count(const struct rte_mempool *mp) -{ - odp_pool_t pool = (odp_pool_t)mp->pool_data; - odp_pool_info_t info; - - if (odp_pool_info(pool, &info)) { - ODP_ERR("Failed to read pool info\n"); - return 0; - } - return info.params.pkt.num; -} - -static void pool_free(struct rte_mempool *mp) -{ - unsigned lcore_id; - - RTE_LCORE_FOREACH(lcore_id) { - struct rte_mempool_cache *cache; - - cache = rte_mempool_default_cache(mp, lcore_id); - if (cache != NULL) - rte_mempool_cache_flush(cache, mp); - } -} - -static void pool_destroy(void *pool) -{ - struct rte_mempool *mp = (struct rte_mempool *)pool; - - if (mp != NULL) - rte_mempool_free(mp); -} - -static struct rte_mempool_ops ops_stack = { - .name = "odp_pool", - .alloc = pool_alloc, - .free = pool_free, - .enqueue = pool_enqueue, - .dequeue = pool_dequeue_bulk, - .get_count = pool_get_count -}; - -MEMPOOL_REGISTER_OPS(ops_stack); - -static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, - odp_packet_t pkt_table[], - struct rte_mbuf *mbuf_table[], - uint16_t mbuf_num, odp_time_t *ts) -{ - odp_packet_t pkt; - odp_packet_hdr_t *pkt_hdr; - uint16_t pkt_len; - struct rte_mbuf *mbuf; - void *data; - int i, j; - int nb_pkts = 0; - int alloc_len, num; - odp_pool_t pool = __retrieve_op_data(pktio_entry)->pool; - - /* Allocate maximum sized packets */ - alloc_len = __retrieve_op_data(pktio_entry)->data_room; - - num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num); - if (num != mbuf_num) { - ODP_DBG("packet_alloc_multi() unable to allocate all packets: " - "%d/%" PRIu16 " allocated\n", num, mbuf_num); - for (i = num; i < mbuf_num; i++) - rte_pktmbuf_free(mbuf_table[i]); - } - - for (i = 0; i < num; i++) { - odp_packet_hdr_t parsed_hdr; - - mbuf = mbuf_table[i]; - if (odp_unlikely(mbuf->nb_segs != 1)) { - ODP_ERR("Segmented buffers not supported\n"); - goto fail; - } - - data = rte_pktmbuf_mtod(mbuf, char *); - odp_prefetch(data); - - pkt_len = rte_pktmbuf_pkt_len(mbuf); - - if (pktio_cls_enabled(pktio_entry)) { - if (cls_classify_packet(pktio_entry, - (const uint8_t *)data, - pkt_len, pkt_len, &pool, - &parsed_hdr)) - goto fail; - } - - pkt = pkt_table[i]; - pkt_hdr = odp_packet_hdr(pkt); - pull_tail(pkt_hdr, alloc_len - pkt_len); - - if (odp_packet_copy_from_mem(pkt, 0, pkt_len, data) != 0) - goto fail; - - pkt_hdr->input = pktio_entry->s.handle; - - if (pktio_cls_enabled(pktio_entry)) - copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); - else - packet_parse_layer(pkt_hdr, - pktio_entry->s.config.parser.layer); - - if (mbuf->ol_flags & PKT_RX_RSS_HASH) - odp_packet_flow_hash_set(pkt, mbuf->hash.rss); - - packet_set_ts(pkt_hdr, ts); - - pkt_table[nb_pkts++] = pkt; - - rte_pktmbuf_free(mbuf); - } - - return nb_pkts; - -fail: - odp_packet_free_multi(&pkt_table[i], num - i); - - for (j = i; j < num; j++) - rte_pktmbuf_free(mbuf_table[j]); - - return (i > 0 ? i : -1); -} - -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) -{ - pktio_ops_dpdk_data_t *pkt_dpdk = - __retrieve_op_data(pktio_entry); - int i, j; - char *data; - uint16_t pkt_len; - - if (odp_unlikely((rte_pktmbuf_alloc_bulk(pkt_dpdk->pkt_pool, - mbuf_table, num)))) { - ODP_ERR("Failed to alloc mbuf\n"); - return 0; - } - for (i = 0; i < num; i++) { - pkt_len = _odp_packet_len(pkt_table[i]); - - if (pkt_len > pkt_dpdk->mtu) { - if (i == 0) - __odp_errno = EMSGSIZE; - goto fail; - } - - /* Packet always fits in mbuf */ - data = rte_pktmbuf_append(mbuf_table[i], pkt_len); - - odp_packet_copy_to_mem(pkt_table[i], 0, pkt_len, data); - } - return i; - -fail: - for (j = i; j < num; j++) - rte_pktmbuf_free(mbuf_table[j]); - - return i; -} - -static inline int mbuf_to_pkt_zero(pktio_entry_t *pktio_entry, - odp_packet_t pkt_table[], - struct rte_mbuf *mbuf_table[], - uint16_t mbuf_num, odp_time_t *ts) -{ - odp_packet_t pkt; - odp_packet_hdr_t *pkt_hdr; - uint16_t pkt_len; - struct rte_mbuf *mbuf; - void *data; - int i; - int nb_pkts = 0; - odp_pool_t pool = __retrieve_op_data(pktio_entry)->pool; - - for (i = 0; i < mbuf_num; i++) { - odp_packet_hdr_t parsed_hdr; - - mbuf = mbuf_table[i]; - if (odp_unlikely(mbuf->nb_segs != 1)) { - ODP_ERR("Segmented buffers not supported\n"); - rte_pktmbuf_free(mbuf); - continue; - } - - data = rte_pktmbuf_mtod(mbuf, char *); - pkt_len = rte_pktmbuf_pkt_len(mbuf); - - pkt = (odp_packet_t)mbuf->userdata; - pkt_hdr = odp_packet_hdr(pkt); - - if (pktio_cls_enabled(pktio_entry)) { - if (cls_classify_packet(pktio_entry, - (const uint8_t *)data, - pkt_len, pkt_len, &pool, - &parsed_hdr)) - ODP_ERR("Unable to classify packet\n"); - rte_pktmbuf_free(mbuf); - continue; - } - - /* Init buffer segments. Currently, only single segment packets - * are supported. */ - pkt_hdr->buf_hdr.seg[0].data = data; - - packet_init(pkt_hdr, pkt_len); - pkt_hdr->input = pktio_entry->s.handle; - - if (pktio_cls_enabled(pktio_entry)) - copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); - else - packet_parse_layer(pkt_hdr, - pktio_entry->s.config.parser.layer); - - if (mbuf->ol_flags & PKT_RX_RSS_HASH) - odp_packet_flow_hash_set(pkt, mbuf->hash.rss); - - packet_set_ts(pkt_hdr, ts); - - pkt_table[nb_pkts++] = pkt; - } - - return nb_pkts; -} - -static inline int pkt_to_mbuf_zero(pktio_entry_t *pktio_entry, - struct rte_mbuf *mbuf_table[], - const odp_packet_t pkt_table[], uint16_t num, - uint16_t *seg_count) -{ - pktio_ops_dpdk_data_t *pkt_dpdk = - __retrieve_op_data(pktio_entry); - int i; - - *seg_count = 0; - - for (i = 0; i < num; i++) { - odp_packet_t pkt = pkt_table[i]; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - struct rte_mbuf *mbuf = (struct rte_mbuf *) - (uintptr_t)pkt_hdr->extra; - uint16_t pkt_len = odp_packet_len(pkt); - - if (odp_unlikely(pkt_len > pkt_dpdk->mtu)) - goto fail; - - if (odp_likely(pkt_hdr->buf_hdr.segcount == 1)) { - if (odp_unlikely(pkt_hdr->extra_type != - PKT_EXTRA_TYPE_DPDK)) - mbuf_init(pkt_dpdk->pkt_pool, mbuf, pkt_hdr); - - mbuf_update(mbuf, pkt_hdr, pkt_len); - } else { - /* Fall back to packet copy */ - if (odp_unlikely(pkt_to_mbuf(pktio_entry, &mbuf, - &pkt, 1) != 1)) - goto fail; - (*seg_count)++; - } - - mbuf_table[i] = mbuf; - } - return i; - -fail: - if (i == 0) - __odp_errno = EMSGSIZE; - return i; -} - -/* Test if s has only digits or not. Dpdk pktio uses only digits.*/ -static int dpdk_netdev_is_valid(const char *s) -{ - while (*s) { - if (!isdigit(*s)) - return 0; - s++; - } - return 1; -} - -static uint32_t dpdk_vdev_mtu_get(uint8_t port_id) -{ - struct rte_eth_dev_info dev_info; - struct ifreq ifr; - int sockfd; - uint32_t mtu; - - memset(&dev_info, 0, sizeof(struct rte_eth_dev_info)); - - rte_eth_dev_info_get(port_id, &dev_info); - if_indextoname(dev_info.if_index, ifr.ifr_name); - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd < 0) { - ODP_ERR("Failed to create control socket\n"); - return 0; - } - - mtu = mtu_get_fd(sockfd, ifr.ifr_name); - close(sockfd); - return mtu; -} - -static uint32_t dpdk_mtu_get(pktio_entry_t *pktio_entry) -{ - 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)) - return 0; - - /* Some DPDK PMD virtual devices do not support getting MTU size. - * Try to use system call if DPDK cannot get MTU value. - */ - if (mtu == 0) - mtu = dpdk_vdev_mtu_get(pkt_dpdk->port_id); - - /* Mbuf chaining not yet supported */ - if (pkt_dpdk->data_room && pkt_dpdk->data_room < mtu) - return pkt_dpdk->data_room; - - return mtu; -} - -static int dpdk_vdev_promisc_mode_get(uint8_t port_id) -{ - struct rte_eth_dev_info dev_info; - struct ifreq ifr; - int sockfd; - int mode; - - memset(&dev_info, 0, sizeof(struct rte_eth_dev_info)); - - rte_eth_dev_info_get(port_id, &dev_info); - if_indextoname(dev_info.if_index, ifr.ifr_name); - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd < 0) { - ODP_ERR("Failed to create control socket\n"); - return -1; - } - - mode = promisc_mode_get_fd(sockfd, ifr.ifr_name); - close(sockfd); - return mode; -} - -static int dpdk_vdev_promisc_mode_set(uint8_t port_id, int enable) -{ - struct rte_eth_dev_info dev_info; - struct ifreq ifr; - int sockfd; - int mode; - - memset(&dev_info, 0, sizeof(struct rte_eth_dev_info)); - - rte_eth_dev_info_get(port_id, &dev_info); - if_indextoname(dev_info.if_index, ifr.ifr_name); - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd < 0) { - ODP_ERR("Failed to create control socket\n"); - return -1; - } - - mode = promisc_mode_set_fd(sockfd, ifr.ifr_name, enable); - close(sockfd); - return mode; -} - -static void rss_conf_to_hash_proto(struct rte_eth_rss_conf *rss_conf, - const odp_pktin_hash_proto_t *hash_proto) -{ - memset(rss_conf, 0, sizeof(struct rte_eth_rss_conf)); - - if (hash_proto->proto.ipv4_udp) - rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP; - if (hash_proto->proto.ipv4_tcp) - rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP; - if (hash_proto->proto.ipv4) - rss_conf->rss_hf |= ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 | - ETH_RSS_NONFRAG_IPV4_OTHER; - if (hash_proto->proto.ipv6_udp) - rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP | - ETH_RSS_IPV6_UDP_EX; - if (hash_proto->proto.ipv6_tcp) - rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP | - ETH_RSS_IPV6_TCP_EX; - if (hash_proto->proto.ipv6) - rss_conf->rss_hf |= ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 | - ETH_RSS_NONFRAG_IPV6_OTHER | - ETH_RSS_IPV6_EX; - rss_conf->rss_key = NULL; -} - -static int dpdk_setup_port(pktio_entry_t *pktio_entry) -{ - int ret; - 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 */ - if (pkt_dpdk->hash.all_bits == 0) { - memset(&rss_conf, 0, sizeof(struct rte_eth_rss_conf)); - rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP | ETH_RSS_UDP; - } else { - rss_conf_to_hash_proto(&rss_conf, &pkt_dpdk->hash); - } - - struct rte_eth_conf port_conf = { - .rxmode = { - .mq_mode = ETH_MQ_RX_RSS, - .split_hdr_size = 0, - .header_split = 0, - .hw_ip_checksum = 0, - .hw_vlan_filter = 0, - .hw_strip_crc = 0, - .enable_scatter = 0, - }, - .rx_adv_conf = { - .rss_conf = rss_conf, - }, - .txmode = { - .mq_mode = ETH_MQ_TX_NONE, - }, - }; - - ret = rte_eth_dev_configure(pkt_dpdk->port_id, - pktio_entry->s.num_in_queue, - pktio_entry->s.num_out_queue, &port_conf); - if (ret < 0) { - ODP_ERR("Failed to setup device: err=%d, port=%" PRIu8 "\n", - ret, pkt_dpdk->port_id); - return -1; - } - return 0; -} - -static int dpdk_close(pktio_entry_t *pktio_entry) -{ - pktio_ops_dpdk_data_t *pkt_dpdk = - __retrieve_op_data(pktio_entry); - unsigned idx; - unsigned i, j; - - /* Free cache packets */ - for (i = 0; i < PKTIO_MAX_QUEUES; i++) { - idx = pkt_dpdk->rx_cache[i].s.idx; - - for (j = 0; j < pkt_dpdk->rx_cache[i].s.count; j++) - rte_pktmbuf_free(pkt_dpdk->rx_cache[i].s.pkt[idx++]); - } - - if (pktio_entry->s.state != PKTIO_STATE_OPENED) - rte_eth_dev_close(pkt_dpdk->port_id); - - if (!ODP_DPDK_ZERO_COPY) - rte_mempool_free(pkt_dpdk->pkt_pool); - - __release_op_data(pktio_entry); - return 0; -} - -static int dpdk_pktio_init(void) -{ - int dpdk_argc; - int i; - odp_cpumask_t mask; - char mask_str[ODP_CPUMASK_STR_SIZE]; - const char *cmdline; - int32_t masklen; - int mem_str_len; - int cmd_len; - cpu_set_t original_cpuset; - struct rte_config *cfg; - - /** - * DPDK init changes the affinity of the calling thread, so after it - * returns the original affinity is restored. Only the first active - * core is passed to rte_eal_init(), as the rest would be used for - * DPDK's special lcore threads, which are only available through - * rte_eal_[mp_]remote_launch(), but not through ODP API's. - * Nevertheless, odp_local_init() makes sure for the rest of - * the DPDK libraries ODP threads look like proper DPDK threads. - */ - CPU_ZERO(&original_cpuset); - i = pthread_getaffinity_np(pthread_self(), - sizeof(original_cpuset), &original_cpuset); - if (i != 0) { - ODP_ERR("Failed to read thread affinity: %d\n", i); - return -1; - } - - odp_cpumask_zero(&mask); - for (i = 0; i < CPU_SETSIZE; i++) { - if (CPU_ISSET(i, &original_cpuset)) { - odp_cpumask_set(&mask, i); - break; - } - } - masklen = odp_cpumask_to_str(&mask, mask_str, ODP_CPUMASK_STR_SIZE); - - if (masklen < 0) { - ODP_ERR("CPU mask error: d\n", masklen); - return -1; - } - - mem_str_len = snprintf(NULL, 0, "%d", DPDK_MEMORY_MB); - - cmdline = getenv("ODP_PKTIO_DPDK_PARAMS"); - if (cmdline == NULL) - cmdline = ""; - - /* masklen includes the terminating null as well */ - cmd_len = strlen("odpdpdk -c -m ") + masklen + mem_str_len + - strlen(cmdline) + strlen(" "); - - char full_cmd[cmd_len]; - - /* first argument is facility log, simply bind it to odpdpdk for now.*/ - cmd_len = snprintf(full_cmd, cmd_len, "odpdpdk -c %s -m %d %s", - mask_str, DPDK_MEMORY_MB, cmdline); - - for (i = 0, dpdk_argc = 1; i < cmd_len; ++i) { - if (isspace(full_cmd[i])) - ++dpdk_argc; - } - - char *dpdk_argv[dpdk_argc]; - - dpdk_argc = rte_strsplit(full_cmd, strlen(full_cmd), dpdk_argv, - dpdk_argc, ' '); - for (i = 0; i < dpdk_argc; ++i) - ODP_DBG("arg[%d]: %s\n", i, dpdk_argv[i]); - - i = rte_eal_init(dpdk_argc, dpdk_argv); - - if (i < 0) { - ODP_ERR("Cannot init the Intel DPDK EAL!\n"); - return -1; - } else if (i + 1 != dpdk_argc) { - ODP_DBG("Some DPDK args were not processed!\n"); - ODP_DBG("Passed: %d Consumed %d\n", dpdk_argc, i + 1); - } - ODP_DBG("rte_eal_init OK\n"); - - rte_set_log_level(RTE_LOG_WARNING); - - i = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), - &original_cpuset); - if (i) - ODP_ERR("Failed to reset thread affinity: %d\n", i); - - cfg = rte_eal_get_configuration(); - for (i = 0; i < RTE_MAX_LCORE; i++) - cfg->lcore_role[i] = ROLE_RTE; - - return 0; -} - -/* Placeholder for DPDK global init */ -static int dpdk_pktio_init_global(void) -{ - if (getenv("ODP_PKTIO_DISABLE_DPDK")) { - ODP_PRINT("PKTIO: dpdk pktio skipped," - " enabled export ODP_PKTIO_DISABLE_DPDK=1.\n"); - disable_pktio = 1; - } else { - ODP_PRINT("PKTIO: initialized dpdk pktio," - " use export ODP_PKTIO_DISABLE_DPDK=1 to disable.\n"); - } - return 0; -} - -static int dpdk_pktio_init_local(void) -{ - int cpu; - - cpu = sched_getcpu(); - if (cpu < 0) { - ODP_ERR("getcpu failed\n"); - return -1; - } - - RTE_PER_LCORE(_lcore_id) = cpu; - - return 0; -} - -static int dpdk_input_queues_config(pktio_entry_t *pktio_entry, - const odp_pktin_queue_param_t *p) -{ - odp_pktin_mode_t mode = pktio_entry->s.param.in_mode; - odp_bool_t lockless; - - /** - * Scheduler synchronizes input queue polls. Only single thread - * at a time polls a queue */ - if (mode == ODP_PKTIN_MODE_SCHED || - p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) - lockless = 1; - else - lockless = 0; - - if (p->hash_enable && p->num_queues > 1) - __retrieve_op_data(pktio_entry)->hash = p->hash_proto; - - __retrieve_op_data(pktio_entry)->lockless_rx = lockless; - - return 0; -} - -static int dpdk_output_queues_config(pktio_entry_t *pktio_entry, - const odp_pktout_queue_param_t *p) -{ - 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) - lockless = 1; - else - lockless = 0; - - pkt_dpdk->lockless_tx = lockless; - - return 0; -} - -static void dpdk_init_capability(pktio_entry_t *pktio_entry, - struct rte_eth_dev_info *dev_info) -{ - 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)); - memset(capa, 0, sizeof(odp_pktio_capability_t)); - - rte_eth_dev_info_get(pkt_dpdk->port_id, dev_info); - capa->max_input_queues = RTE_MIN(dev_info->max_rx_queues, - PKTIO_MAX_QUEUES); - capa->max_output_queues = RTE_MIN(dev_info->max_tx_queues, - PKTIO_MAX_QUEUES); - capa->set_op.op.promisc_mode = 1; - - odp_pktio_config_init(&capa->config); - capa->config.pktin.bit.ts_all = 1; - capa->config.pktin.bit.ts_ptp = 1; -} - -static int dpdk_open(odp_pktio_t id ODP_UNUSED, - pktio_entry_t *pktio_entry, - const char *netdev, - odp_pool_t pool) -{ - 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]; - uint16_t data_room; - uint32_t mtu; - int i; - pool_t *pool_entry; - - if (disable_pktio) - return -1; - - if (pool == ODP_POOL_INVALID) - return -1; - pool_entry = pool_entry_from_hdl(pool); - - if (!dpdk_netdev_is_valid(netdev)) { - ODP_ERR("Invalid dpdk netdev: %s\n", netdev); - return -1; - } - - /* Initialize DPDK here instead of odp_init_global() to enable running - * 'make check' without root privileges */ - if (dpdk_initialized == 0) { - dpdk_pktio_init(); - 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)); - - pkt_dpdk->pool = pool; - pkt_dpdk->port_id = atoi(netdev); - - if (rte_eth_dev_count() == 0) { - ODP_ERR("No DPDK ports found\n"); - __release_op_data(pktio_entry); - return -1; - } - - dpdk_init_capability(pktio_entry, &dev_info); - - 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; - - /* Some DPDK PMD virtual devices, like PCAP, do not support promisc - * mode change. Use system call for them. */ - rte_eth_promiscuous_enable(pkt_dpdk->port_id); - if (!rte_eth_promiscuous_get(pkt_dpdk->port_id)) - pkt_dpdk->vdev_sysc_promisc = 1; - rte_eth_promiscuous_disable(pkt_dpdk->port_id); - - if (!strcmp(dev_info.driver_name, "rte_ixgbe_pmd")) - pkt_dpdk->min_rx_burst = DPDK_IXGBE_MIN_RX_BURST; - else - pkt_dpdk->min_rx_burst = 0; - if (ODP_DPDK_ZERO_COPY) { - if (pool_entry->ext_desc != NULL) { - pkt_pool = (struct rte_mempool *)pool_entry->ext_desc; - } else { - snprintf(pool_name, sizeof(pool_name), - "pktpool_%" PRIu32 "", pool_entry->pool_idx); - pkt_pool = mbuf_pool_create(pool_name, - pool_entry); - pool_entry->ext_destroy = pool_destroy; - pool_entry->ext_desc = pkt_pool; - } - } else { - snprintf(pool_name, sizeof(pool_name), "pktpool_%s", netdev); - pkt_pool = rte_pktmbuf_pool_create(pool_name, - DPDK_NB_MBUF, - DPDK_MEMPOOL_CACHE_SIZE, 0, - DPDK_MBUF_BUF_SIZE, - rte_socket_id()); - } - if (pkt_pool == NULL) { - ODP_ERR("Cannot init mbuf packet pool\n"); - __release_op_data(pktio_entry); - return -1; - } - - pkt_dpdk->pkt_pool = pkt_pool; - - data_room = rte_pktmbuf_data_room_size(pkt_dpdk->pkt_pool) - - RTE_PKTMBUF_HEADROOM; - pkt_dpdk->data_room = RTE_MIN(pool_entry->max_seg_len, data_room); - - /* Mbuf chaining not yet supported */ - pkt_dpdk->mtu = RTE_MIN(pkt_dpdk->mtu, pkt_dpdk->data_room); - - for (i = 0; i < PKTIO_MAX_QUEUES; i++) { - odp_ticketlock_init(&pkt_dpdk->rx_lock[i]); - odp_ticketlock_init(&pkt_dpdk->tx_lock[i]); - } - - rte_eth_stats_reset(pkt_dpdk->port_id); - - return 0; -} - -static int dpdk_start(pktio_entry_t *pktio_entry) -{ - pktio_ops_dpdk_data_t *pkt_dpdk = - __retrieve_op_data(pktio_entry); - uint8_t port_id = pkt_dpdk->port_id; - int ret; - unsigned i; - - /* DPDK doesn't support nb_rx_q/nb_tx_q being 0 */ - if (!pktio_entry->s.num_in_queue) - pktio_entry->s.num_in_queue = 1; - if (!pktio_entry->s.num_out_queue) - pktio_entry->s.num_out_queue = 1; - - /* init port */ - if (dpdk_setup_port(pktio_entry)) { - ODP_ERR("Failed to configure device\n"); - return -1; - } - /* Init TX queues */ - for (i = 0; i < pktio_entry->s.num_out_queue; i++) { - ret = rte_eth_tx_queue_setup(port_id, i, DPDK_NM_TX_DESC, - rte_eth_dev_socket_id(port_id), - NULL); - if (ret < 0) { - ODP_ERR("Queue setup failed: err=%d, port=%" PRIu8 "\n", - ret, port_id); - return -1; - } - } - /* Init RX queues */ - for (i = 0; i < pktio_entry->s.num_in_queue; i++) { - ret = rte_eth_rx_queue_setup(port_id, i, DPDK_NM_RX_DESC, - rte_eth_dev_socket_id(port_id), - NULL, pkt_dpdk->pkt_pool); - if (ret < 0) { - ODP_ERR("Queue setup failed: err=%d, port=%" PRIu8 "\n", - ret, port_id); - return -1; - } - } - /* Start device */ - ret = rte_eth_dev_start(port_id); - if (ret < 0) { - ODP_ERR("Device start failed: err=%d, port=%" PRIu8 "\n", - ret, port_id); - return -1; - } - - return 0; -} - -static int dpdk_stop(pktio_entry_t *pktio_entry) -{ - rte_eth_dev_stop(__retrieve_op_data(pktio_entry)->port_id); - - return 0; -} - -static int dpdk_recv(pktio_entry_t *pktio_entry, int index, - odp_packet_t pkt_table[], int num) -{ - 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; - int nb_rx; - struct rte_mbuf *rx_mbufs[num]; - int i; - unsigned cache_idx; - - if (odp_unlikely(pktio_entry->s.state != PKTIO_STATE_STARTED)) - return 0; - - if (!pkt_dpdk->lockless_rx) - odp_ticketlock_lock(&pkt_dpdk->rx_lock[index]); - /** - * ixgbe_pmd has a minimum supported RX burst size ('min_rx_burst'). If - * 'num' < 'min_rx_burst', 'min_rx_burst' is used as rte_eth_rx_burst() - * argument and the possibly received extra packets are cached for the - * next dpdk_recv_queue() call to use. - * - * Either use cached packets or receive new ones. Not both during the - * same call. */ - if (rx_cache->s.count > 0) { - for (i = 0; i < num && rx_cache->s.count; i++) { - rx_mbufs[i] = rx_cache->s.pkt[rx_cache->s.idx]; - rx_cache->s.idx++; - rx_cache->s.count--; - } - nb_rx = i; - } 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(pkt_dpdk->port_id, index, - new_mbufs, pkt_dpdk->min_rx_burst); - rx_cache->s.idx = 0; - for (i = 0; i < nb_rx; i++) { - if (i < num) { - rx_mbufs[i] = new_mbufs[i]; - } else { - cache_idx = rx_cache->s.count; - rx_cache->s.pkt[cache_idx] = new_mbufs[i]; - rx_cache->s.count++; - } - } - nb_rx = RTE_MIN(num, nb_rx); - - } else { - nb_rx = rte_eth_rx_burst(pkt_dpdk->port_id, index, - rx_mbufs, num); - } - - if (!pkt_dpdk->lockless_rx) - odp_ticketlock_unlock(&pkt_dpdk->rx_lock[index]); - - if (nb_rx > 0) { - if (pktio_entry->s.config.pktin.bit.ts_all || - pktio_entry->s.config.pktin.bit.ts_ptp) { - ts_val = odp_time_global(); - ts = &ts_val; - } - if (ODP_DPDK_ZERO_COPY) - nb_rx = mbuf_to_pkt_zero(pktio_entry, pkt_table, - rx_mbufs, nb_rx, ts); - else - nb_rx = mbuf_to_pkt(pktio_entry, pkt_table, rx_mbufs, - nb_rx, ts); - } - - return nb_rx; -} - -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]; - pktio_ops_dpdk_data_t *pkt_dpdk = - __retrieve_op_data(pktio_entry); - uint16_t seg_count = 0; - int tx_pkts; - int i; - int mbufs; - - if (odp_unlikely(pktio_entry->s.state != PKTIO_STATE_STARTED)) - return 0; - - if (ODP_DPDK_ZERO_COPY) - mbufs = pkt_to_mbuf_zero(pktio_entry, tx_mbufs, pkt_table, num, - &seg_count); - else - mbufs = pkt_to_mbuf(pktio_entry, tx_mbufs, pkt_table, num); - - if (!pkt_dpdk->lockless_tx) - odp_ticketlock_lock(&pkt_dpdk->tx_lock[index]); - - tx_pkts = rte_eth_tx_burst(pkt_dpdk->port_id, index, - tx_mbufs, mbufs); - - if (!pkt_dpdk->lockless_tx) - odp_ticketlock_unlock(&pkt_dpdk->tx_lock[index]); - - if (ODP_DPDK_ZERO_COPY) { - /* Free copied segmented packets */ - if (odp_unlikely(seg_count)) { - uint16_t freed = 0; - - for (i = 0; i < mbufs && freed != seg_count; i++) { - odp_packet_t pkt = pkt_table[i]; - odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); - - if (pkt_hdr->buf_hdr.segcount > 1) { - if (odp_likely(i < tx_pkts)) - odp_packet_free(pkt); - else - rte_pktmbuf_free(tx_mbufs[i]); - freed++; - } - } - } - if (odp_unlikely(tx_pkts == 0 && __odp_errno != 0)) - return -1; - } else { - if (odp_unlikely(tx_pkts < mbufs)) { - for (i = tx_pkts; i < mbufs; i++) - rte_pktmbuf_free(tx_mbufs[i]); - } - - if (odp_unlikely(tx_pkts == 0)) { - if (__odp_errno != 0) - return -1; - } else { - odp_packet_free_multi(pkt_table, tx_pkts); - } - } - - return tx_pkts; -} - -static int dpdk_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) -{ - 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 = __retrieve_op_data(pktio_entry)->port_id; - - if (__retrieve_op_data(pktio_entry)->vdev_sysc_promisc) - return dpdk_vdev_promisc_mode_set(port_id, enable); - - if (enable) - rte_eth_promiscuous_enable(port_id); - else - rte_eth_promiscuous_disable(port_id); - - return 0; -} - -static int dpdk_promisc_mode_get(pktio_entry_t *pktio_entry) -{ - uint8_t port_id = __retrieve_op_data(pktio_entry)->port_id; - - 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); -} - -static int dpdk_capability(pktio_entry_t *pktio_entry, - odp_pktio_capability_t *capa) -{ - *capa = __retrieve_op_data(pktio_entry)->capa; - return 0; -} - -static int dpdk_link_status(pktio_entry_t *pktio_entry) -{ - struct rte_eth_link link; - - memset(&link, 0, sizeof(struct rte_eth_link)); - - rte_eth_link_get_nowait( - __retrieve_op_data(pktio_entry)->port_id, &link); - - return link.link_status; -} - -static void stats_convert(const struct rte_eth_stats *rte_stats, - odp_pktio_stats_t *stats) -{ - memset(stats, 0, sizeof(odp_pktio_stats_t)); - - stats->in_octets = rte_stats->ibytes; - stats->in_discards = rte_stats->imissed; - stats->in_errors = rte_stats->ierrors; - stats->out_octets = rte_stats->obytes; - stats->out_errors = rte_stats->oerrors; -} - -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( - __retrieve_op_data(pktio_entry)->port_id, &rte_stats); - - if (ret == 0) { - stats_convert(&rte_stats, stats); - return 0; - } - return -1; -} - -static int dpdk_stats_reset(pktio_entry_t *pktio_entry) -{ - rte_eth_stats_reset(__retrieve_op_data(pktio_entry)->port_id); - return 0; -} - -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, - .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, - .config = NULL, - .input_queues_config = dpdk_input_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/dpdk.h b/platform/linux-generic/pktio/dpdk.h deleted file mode 100644 index 7495b5965..000000000 --- a/platform/linux-generic/pktio/dpdk.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (c) 2016, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef ODP_PKTIO_OPS_DPDK_H_ -#define ODP_PKTIO_OPS_DPDK_H_ - -#include -#include -#include - -#include - -#ifdef ODP_PKTIO_DPDK -#include -#include - -#define DPDK_MEMORY_MB 512 -#define DPDK_NB_MBUF 16384 -#define DPDK_MBUF_BUF_SIZE RTE_MBUF_DEFAULT_BUF_SIZE -#define DPDK_MEMPOOL_CACHE_SIZE 64 -#define DPDK_NM_RX_DESC 128 -#define DPDK_NM_TX_DESC 512 - -ODP_STATIC_ASSERT((DPDK_NB_MBUF % DPDK_MEMPOOL_CACHE_SIZE == 0) && - (DPDK_MEMPOOL_CACHE_SIZE <= RTE_MEMPOOL_CACHE_MAX_SIZE) && - (DPDK_MEMPOOL_CACHE_SIZE <= DPDK_MBUF_BUF_SIZE * 10 / 15) - , "DPDK mempool cache size failure"); -#endif - -#define DPDK_IXGBE_MIN_RX_BURST 4 - -/** Cache for storing packets */ -struct pkt_cache_t { - /** array for storing extra RX packets */ - struct rte_mbuf *pkt[DPDK_IXGBE_MIN_RX_BURST]; - unsigned idx; /**< head of cache */ - unsigned count; /**< packets in cache */ -}; - -typedef union { - struct pkt_cache_t s; - uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(struct pkt_cache_t))]; -} pkt_cache_t ODP_ALIGNED_CACHE; - -/** Packet IO using DPDK interface */ -typedef struct { - odp_pool_t pool; /**< pool to alloc packets from */ - struct rte_mempool *pkt_pool; /**< DPDK packet pool */ - odp_pktio_capability_t capa; /**< interface capabilities */ - uint32_t data_room; /**< maximum packet length */ - uint16_t mtu; /**< maximum transmission unit */ - /** Use system call to get/set vdev promisc mode */ - odp_bool_t vdev_sysc_promisc; - uint8_t port_id; /**< DPDK port identifier */ - unsigned min_rx_burst; /**< minimum RX burst size */ - 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 */ - /** cache for storing extra RX packets */ - pkt_cache_t rx_cache[PKTIO_MAX_QUEUES]; -} pktio_ops_dpdk_data_t; - -#endif diff --git a/platform/linux-generic/pktio/subsystem.c b/platform/linux-generic/pktio/subsystem.c index fbcf22d77..593ac916c 100644 --- a/platform/linux-generic/pktio/subsystem.c +++ b/platform/linux-generic/pktio/subsystem.c @@ -20,9 +20,6 @@ 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 @@ -41,9 +38,6 @@ 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 diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am index 8969f5208..2ad3254a4 100644 --- a/test/linux-generic/Makefile.am +++ b/test/linux-generic/Makefile.am @@ -59,9 +59,6 @@ endif if netmap_support TESTS += validation/api/pktio/pktio_run_netmap.sh endif -if PKTIO_DPDK -TESTS += validation/api/pktio/pktio_run_dpdk.sh -endif TESTS += pktio_ipc/pktio_ipc_run.sh SUBDIRS += pktio_ipc else diff --git a/test/linux-generic/validation/api/pktio/Makefile.am b/test/linux-generic/validation/api/pktio/Makefile.am index 4a1434397..a9d0feeed 100644 --- a/test/linux-generic/validation/api/pktio/Makefile.am +++ b/test/linux-generic/validation/api/pktio/Makefile.am @@ -8,8 +8,5 @@ endif if netmap_support dist_check_SCRIPTS += pktio_run_netmap.sh endif -if PKTIO_DPDK -dist_check_SCRIPTS += pktio_run_dpdk.sh -endif test_SCRIPTS = $(dist_check_SCRIPTS)