From patchwork Thu Sep 14 03:00:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112495 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp265236qgf; Wed, 13 Sep 2017 20:02:24 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCHT+J2clwjAkqPjQB+yefjwrgMjftvh/3b6Bll3owkQXO8pFZN3dWR7heTWStLy88Nmwn9 X-Received: by 10.237.62.129 with SMTP id n1mr30032968qtf.39.1505358144471; Wed, 13 Sep 2017 20:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358144; cv=none; d=google.com; s=arc-20160816; b=mZrgvI7Lc1fo96DUMnEvJfRDeISbq6BLSc8Br0jgWG5vJgDWjIIMuXCOQRQeDTAY/U P2ZnVuaMfafto3anOyVPSs+vqHngAVOPk8OS0RhDUBjoMIshiad8u03DNwU5NMJ+2d2I zQRjk3hi00v2hS2II5DHR7r4BmVoFfGKHQK7GVdQwnmmqiDwC4JIQdEp3+jiY+XEmI+G LfrIZKksjYKN6czmNYAb7r78wVxmFsNYHOXRV5TgfV0bRrDz1FQ1TPb+TbqqC0mIiy4B G2msglSXbYUcM4J4dPnku47d1cxmibDLXjFSt2dPY/ycT3HqOJhPkvvUsnjGFX4Ueie8 UeDg== 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=Wj6HZnVUnGWHcqrMWllUEEN/UYNjCKkNHbIv19vCsO4=; b=u7Oe40ECD6tPJbxzxbSnup1PULhC/CoOwVQhknhLrHcF1ZqU6xk9txTm2iMLOIweWZ ElthoNkqFxJOs6TMezgS2vm+YcfuJHI90o9IMu/PTnTr3yMvHN0O8smgJcxDMZ9opxHE eTobDoB9AwyMMeOla+U/pa93sKTtC9OHbVWh2/i/t4VQmphYh4rLnCm4C60JGQG/uTtx n+8/ndT6czI8fyHv2Poirbprl9k3NlrxGJr/E5vUQlH0rFiVjsExPNPBEfwXFSBrcpHd DYcQRKbfujvVUen071g1tTfb4LV88v0xLBHV9KuLIlEBzz8biHVxx71fkXIbQYG93nqN akog== 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 d21si17326638qkh.197.2017.09.13.20.02.24; Wed, 13 Sep 2017 20:02:24 -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 19B7A63CB2; Thu, 14 Sep 2017 03:02:24 +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, RCVD_IN_MSPIKE_H4, 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 8ED83609C9; Thu, 14 Sep 2017 03:00:42 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B105260C0F; Thu, 14 Sep 2017 03:00:34 +0000 (UTC) Received: from forward100j.mail.yandex.net (forward100j.mail.yandex.net [5.45.198.240]) by lists.linaro.org (Postfix) with ESMTPS id C9312609DB for ; Thu, 14 Sep 2017 03:00:30 +0000 (UTC) Received: from mxback2o.mail.yandex.net (mxback2o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1c]) by forward100j.mail.yandex.net (Yandex) with ESMTP id 81E315D83562 for ; Thu, 14 Sep 2017 06:00:25 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback2o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id z5mGbmSYyd-0Pfi28xN; Thu, 14 Sep 2017 06:00:25 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0OOOFp6C; Thu, 14 Sep 2017 06:00:24 +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: Thu, 14 Sep 2017 06:00:05 +0300 Message-Id: <1505358015-27878-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 1a9e178c..59f67c8d 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 Thu Sep 14 03:00:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112494 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp264671qgf; Wed, 13 Sep 2017 20:01:36 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCMOmARVQQRd3EwgHOag0ScSpngHgMZFMBMPCJz+/9xZYsWL/N7Lzjwf5NtclbRwhxYp6hm X-Received: by 10.55.121.194 with SMTP id u185mr797053qkc.101.1505358096794; Wed, 13 Sep 2017 20:01:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358096; cv=none; d=google.com; s=arc-20160816; b=c+14M2y1ZmxI5eM1O6XzaRvne2qFyb6ACUr9QCpnZMGo6CWx0QK7uhribTKGi3gsO9 VbPKxAWQL1Ory9FZ3//9dLYttQ6doWy5bN9j5JC5UnMg6fRHsVhfK64SKjrSLuXJojtT bz77LbIiunbO9T2hx4TaxVm5Bc1xKU9Gd2ypPhGrysHMjiu93rN7XhvNzSz1MMWbDzfy KXs/LUt/liEJ7FThMe908TLLXCEMr5eRByGG4qOX+r+GKccETAsN8qT4XYUNiD/QnlZc Qo+EsOJuQnnrTCw7E5SzBK+lB8vXkwQq/dKQM77hHGMZnd9FpXHVsiBFgp1n9XxDASWv LBCQ== 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=1ZTecWb6H8YEDNQiAIDYbOuQ1wMpPy/a2hwV+1mMbTg=; b=aG7cE4xq0qegkGANO0Gyo0VbrxexG3CqgPqxMP1BFboL4VE3iQLeS3BC3QzMkmGmLA s7koeDVm4qcI1OWoAs24sCWTNx4sV7BzjeNu/jPdhQevYleq2w2eOuQFZzMlyxYndS1a 8WRT9N72c2EqGFPBbc1r3iEC1wAVxK0H0wlDrQPHDa4C1mNleq9EoBuVKVuvVOpcUGoD s2q7tNWtRU/CZyi+vwBp1WEDEZXYIgqi2j3wi8ZrfLkdhO7Hszz/giK7pOL4/P2x2esc WN1TwU8AQ9NJHIhgZt2OXymF1Aqfx76fHyZcMAiT967VYMC8BQt2bV/mMsicccKh+wIH Se7Q== 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 l11si16367064qtl.0.2017.09.13.20.01.36; Wed, 13 Sep 2017 20:01:36 -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 7B87A60B45; Thu, 14 Sep 2017 03:01:36 +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 9F76860BDB; Thu, 14 Sep 2017 03:00:34 +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 064B4609ED; Thu, 14 Sep 2017 03:00:29 +0000 (UTC) Received: from forward105j.mail.yandex.net (forward105j.mail.yandex.net [5.45.198.248]) by lists.linaro.org (Postfix) with ESMTPS id 9C150609DB for ; Thu, 14 Sep 2017 03:00:27 +0000 (UTC) Received: from mxback9o.mail.yandex.net (mxback9o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::23]) by forward105j.mail.yandex.net (Yandex) with ESMTP id 3437D185F7D for ; Thu, 14 Sep 2017 06:00:26 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback9o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 5NPJMFekVj-0QPOCqdE; Thu, 14 Sep 2017 06:00:26 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0POK3Njc; Thu, 14 Sep 2017 06:00:25 +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: Thu, 14 Sep 2017 06:00:06 +0300 Message-Id: <1505358015-27878-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 130a3a84..0c464f70 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 Thu Sep 14 03:00:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112497 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp266488qgf; Wed, 13 Sep 2017 20:04:19 -0700 (PDT) X-Google-Smtp-Source: AOwi7QD4opdkj+1x100gWogYcYlFIZMX1c55QyBwK72BF03K5RzPbEpKmKPlrWKSNNeID1J1GlkZ X-Received: by 10.200.36.244 with SMTP id t49mr27775177qtt.190.1505358259806; Wed, 13 Sep 2017 20:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358259; cv=none; d=google.com; s=arc-20160816; b=ci04NykMf8zvfgbINu59NkUDo9WIJ9yQH3BABuoimc1MUXi8tbX/b2mbfJoZsQxwwl 7Gp+zeOODWFv4RE0qBtBsDET6V3vV+yA5TLnYN67XavOPEU4oTsvzoNxll1Yu+3ZJKr/ o6H68AQgxVfAKxdYtHNiQQ94/u4bJQ+E6EqbzEBR5MP6BfRsz8PMOAyVDBIgRvuyV+c+ S/phROdKr6NOmBHhfu7W365Meask4omgqrFNV9bqSgR3GzXTI5Gl5gc6PfgYtMbqMM0W Pu+T/8TWzYHZ0tKGolDyomPQA8m7QpQI3vgY/DU3MauzxJLaEK3REudUWp1DdPrEEJ1o 1M6A== 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=FF83LiO3z1kC1p1bXDSNYrtZ70esgBRg7hIzl78+04Y=; b=cFmSU+WdGGz+w1loD0s0aogXyOtSxy7eczWHu8vDkFZEIgbRFZ3RQXImR+7W7wOh7x zJtldXwUFon9YBEFokLTB1TQP52tCU7ZDGC8BGRLxeLyTjRixE0rmLc9c3QCqUfwTyvv qP4LdV/DGO+v4924FFDWUN11KM6FLMg4R90uV+VYZRvPTsVigYPPDvFR3tXsMqsIvaP0 Dyrkd/yJi4UbNJV3WqcfDTvgMRGs/lK1nv0lsbD6kxjHXZpXNsonnHlKr+zvxFdpNBvt zIwLUY9apVHRG3TiImDsCzheATDCMS82+qvEBBlHrOfu08A+3VgOEE03TiXB4J7mW4NV o9EQ== 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 k9si17450020qkk.292.2017.09.13.20.04.19; Wed, 13 Sep 2017 20:04:19 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 7213E64469; Thu, 14 Sep 2017 03:04: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=-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 539B460C88; Thu, 14 Sep 2017 03:01:03 +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 AEFD060C1F; Thu, 14 Sep 2017 03:00:41 +0000 (UTC) Received: from forward103o.mail.yandex.net (forward103o.mail.yandex.net [37.140.190.177]) by lists.linaro.org (Postfix) with ESMTPS id DEA9B609C9 for ; Thu, 14 Sep 2017 03:00:28 +0000 (UTC) Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward103o.mail.yandex.net (Yandex) with ESMTP id 7B23E5880FCD for ; Thu, 14 Sep 2017 06:00:27 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id QHqruduAdj-0R3mZ9rj; Thu, 14 Sep 2017 06:00:27 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0QOaBQqb; Thu, 14 Sep 2017 06:00:26 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 14 Sep 2017 06:00:07 +0300 Message-Id: <1505358015-27878-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 587d4836..83931d27 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 14b6a8d3..fde172fc 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 d808f130..214116b7 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 00000000..4ff15c81 --- /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 cbbefa4e..ff08a6ef 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 dc049f46..58914840 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 00000000..ff497a2a --- /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 e78c712e..d8dcc45d 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 9e3e583d..e72a7637 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 fbf30ca7..00000000 --- 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 8c7db84e..984f0ab4 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 c825393a..39718a89 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 928bb00a..c75f8be9 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 a467b640..98f81089 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 a383adc6..8b8ccf03 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 6fc4b4cc..0a27316f 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 00000000..fbcf22d7 --- /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 650c12a7..bfe41239 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 Thu Sep 14 03:00:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112496 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp265652qgf; Wed, 13 Sep 2017 20:03:04 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBsLw0IbQWf/3OgYu7XsoX7lP7cTyzJ4GpSmgdpyE//Y7Yl5UJW/OeN43Rr9/Do+MJEolDp X-Received: by 10.200.43.79 with SMTP id 15mr29152902qtv.126.1505358184070; Wed, 13 Sep 2017 20:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358184; cv=none; d=google.com; s=arc-20160816; b=NkWRDJvJuHdPbqvfeFGRZW1CyAjxXkQERxShDp9Vs/Lv1ugSw2tLPgY3pK7xTZIa2p ck8/xvy4LVQZQSStHDjtdQP9Y921knFuj8VmVl29kCqO3VdurxrULEP7oewl0N0bYDPy +BmFRCBxyHmBYE97K5PvyWhoFZM7Jg35AbSCX8cW/gOrZEojHJTzM+sWRHWPWzOHKMVQ dd5VsENNoXY6e9lsXOSqHG44pp5fyTJR/kBY81E+yLM6Uf7x9gKgauyG9Llsr5catPlD tLfGpEtOcqZhNIDHV/L3CW/ynECahlAwafak5ITNuqUPaw1vwBlGoeAmgElM3nhqkbhH z+pA== 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=GvfQqNPmUtzREL4PxGYqJ7nRARZDtiUdZSJapk55iB0=; b=b+kaAYr+zetrBHLkc7i2phiv/wIu6/vg9dIx7/Ft1iYEjeb+DgP7k+TrPoHH3Jlhhw fn1rwK5hPrTyaomuQoh5b3vFInOmyY38YF6FJHorfec/j9YEqkhFRfUPyakQuemAncCi AaZ4sJqLLnQJu3gZRb9OqC3WAsLLtcU6RfkfNEcp/DQIAJj/YllJw0tHy6MW5FwO5GK1 KT3zMPCJ2dCHIChKUCnRiWzPNlYuemZBWzT4JlbGX2sG3B/hVQoNWtOf7OsTsjw6xnJU VRo0BkyCFdSf6zr9y8f4kKfYUa3tZ7sIc/VdU3cNLPc8vR1QsC9u8XsVWkxEKRv2NJIv eRiA== 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 q64si878919qkb.271.2017.09.13.20.03.03; Wed, 13 Sep 2017 20:03:04 -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 B5A8864455; Thu, 14 Sep 2017 03:03: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 E206F60D3D; Thu, 14 Sep 2017 03:00: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 65B2960C1E; Thu, 14 Sep 2017 03:00:36 +0000 (UTC) Received: from forward102p.mail.yandex.net (forward102p.mail.yandex.net [77.88.28.102]) by lists.linaro.org (Postfix) with ESMTPS id F192D609B2 for ; Thu, 14 Sep 2017 03:00:29 +0000 (UTC) Received: from mxback4o.mail.yandex.net (mxback4o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1e]) by forward102p.mail.yandex.net (Yandex) with ESMTP id 74C964305C4F for ; Thu, 14 Sep 2017 06:00:28 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback4o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id sLOKhntzTD-0SVKfK34; Thu, 14 Sep 2017 06:00:28 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0ROeENVf; Thu, 14 Sep 2017 06:00:27 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 14 Sep 2017 06:00:08 +0300 Message-Id: <1505358015-27878-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 83931d27..4d5dff5d 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 fde172fc..ba388c9c 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 ff08a6ef..1aaea84f 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 58914840..893fa114 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 00000000..93245947 --- /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 ff497a2a..7b90ed3d 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 39718a89..0c572338 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 Thu Sep 14 03:00:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112498 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp268386qgf; Wed, 13 Sep 2017 20:06:55 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDg2CQ2fiAnbgWHl2Ech26lWWM/GenMUGnJ93JCaaawFQFVQva0D/ALO6N714Q+sR5IX0RZ X-Received: by 10.55.195.129 with SMTP id r1mr725895qkl.287.1505358415741; Wed, 13 Sep 2017 20:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358415; cv=none; d=google.com; s=arc-20160816; b=SOtVFd9NBudFBdUzO8nHScrbJOi7LmJG9WefwgZPH3DRSGuCsKCvl+KUhUKwOPGA8n s+Wrwqxlshy7SGUspSixkLyYGrmExwJb4XOflK9N77SQ/YWPOoP5SJw9N/GpGlQgDUCe ZiIE9weJulzGYX2PtpafnD13aqJOHNJd5WYEZsq+Y5YELi6RbXatzliFYJA7DKE/VsR9 lKIPGTgg3G+33TyAABH4eNRvCr122nUkA3IvSwIqc0F6g5ReuZ0F8GmQF+TkmZWqxNZE ntFEeF060QyEVxp3gv1Rou8JhsVWujsD6tkpTGFR1h8sRu5niWtJnJP+HaeLx9yUwOzB 3ybA== 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=LtQCN42XyyB9GOCwEk1GyYF5xAOUhlIdjw2Q50acChY=; b=vMtx010PE8Q0o7dYB4YbwTjtbYsaHFjr06ufKrEOV8OdDLlas52XfANuEF8IsB8KvS f4ief8DoJIgCFfIfftBq6HcPGygVAr5IpsvXXLUI5yFB5uMVDduMAiaLzRi9Mcct0Aab cS3qtxk8qOQBVRFkPL7b5/pOQtuhLCS8qQY+4cd8oUh39EDO0kBx3KWuj7vzA00NXvgM iUpkNe5MMJ+IiRRFukxPXay0g9UBNmQNVduJzluflhfxac0jQonbXHZCN7b9e1HR1ftE cepIvWouaPwtUK7dj8z87LOUPvnOT1DI85sw5nr/pwNxI756wgnI8KHpg/NhwBOLfDbR ZX9w== 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 o1si15706252qkf.249.2017.09.13.20.06.55; Wed, 13 Sep 2017 20: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 4DCBC64487; Thu, 14 Sep 2017 03: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 C09006286D; Thu, 14 Sep 2017 03:01:14 +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 A329D60C48; Thu, 14 Sep 2017 03:00:45 +0000 (UTC) Received: from forward105p.mail.yandex.net (forward105p.mail.yandex.net [77.88.28.108]) by lists.linaro.org (Postfix) with ESMTPS id DA034609ED for ; Thu, 14 Sep 2017 03:00:30 +0000 (UTC) Received: from mxback4j.mail.yandex.net (mxback4j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10d]) by forward105p.mail.yandex.net (Yandex) with ESMTP id 725164082B12 for ; Thu, 14 Sep 2017 06:00:29 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback4j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id DQvUwrsKw2-0Tp8A2jp; Thu, 14 Sep 2017 06:00:29 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0SOiHmv8; Thu, 14 Sep 2017 06:00:28 +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: Thu, 14 Sep 2017 06:00:09 +0300 Message-Id: <1505358015-27878-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 4d5dff5d..9ebf2ea1 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 1aaea84f..dd8767b2 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 893fa114..8d3c3ddf 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 9d8943a6..00000000 --- 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 00000000..5903ef9b --- /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 7b90ed3d..650b3664 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 d8dcc45d..6a19394a 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 984f0ab4..14cd86eb 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 Thu Sep 14 03:00:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112500 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp272304qgf; Wed, 13 Sep 2017 20:12:22 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCNixZska71hd3QDSL+Sq9pfIiC1KLD2IFjBkjrAifgCyeoScLZEtviECvAPqGotlWFnN// X-Received: by 10.55.144.196 with SMTP id s187mr815286qkd.13.1505358742770; Wed, 13 Sep 2017 20:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358742; cv=none; d=google.com; s=arc-20160816; b=Yb3TdFGGZ0iDIEjy6D5kbGcik1uwZtX7LX7a6ItzXO5P886l6T8griITG4og52oyJw iIt+AVDXQwOVxNUgatkmSRCFPigLM9cqYdYg7kmohaVKWGqRquVr9eeK/SvOGtKX7ee1 R+OmQ5YL4iLhphRa2Vv/09XeRbeyykdDMhYNahCfzP251thK7K+CVZQUf84S9zOxY+qT Rg+U0gpfHT8LVUKIwvXH6CXQ3JpoAlMOBj3M9F9ZNNiuUdYKXiWLcJlcrmwlYoQZzPda D8/xJD8fpl/Jy+ab1n1mbvRcf/Ef/ygKMhqC4dVc1y/RhrK81VSQu6AIXBHlU4zvF0c1 GHDw== 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=bRp6U1tQM1Qjo4f6GbwVhv0waBdQB/BQgdFCt8fVvZ4=; b=uO673wj+moEqaARXfHqnBijB+Pcy0b/V5lNP2ElCNJKDjmmXxea0xz2t1fpaTVfGud /605PPMvJKlDmceOoAtt9sqwKNpgFl8tx3bFvJekhiBYUAqPHTLDIuasqzNQjlxY9KdL rOHYCcN5mu/urh4xTisPnMRfF+ysZcvtJoq9MpKg4Zp9zAVUZI5bx7/OS4UsW7SGNqVF dVCzbOGVlxl+xxMs6mTHkItPegTYnNKiFsgtjQc6wu+cDsu+WiVjopuMqDKaRssGFNo7 hPa1jjdxHgASItFGyPOAXH9rqXfx6hYdPgXgrHMifUx/ivUG86NtLXTNVlljvzuyQVxf SzdQ== 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 v55si7967qtv.38.2017.09.13.20.12.22; Wed, 13 Sep 2017 20:12:22 -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 686D5644B8; Thu, 14 Sep 2017 03:12:22 +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 4A9A062D32; Thu, 14 Sep 2017 03:01: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 F20F060B3F; Thu, 14 Sep 2017 03:01:32 +0000 (UTC) Received: from forward101j.mail.yandex.net (forward101j.mail.yandex.net [5.45.198.241]) by lists.linaro.org (Postfix) with ESMTPS id 3B97060B45 for ; Thu, 14 Sep 2017 03:00:32 +0000 (UTC) Received: from mxback9o.mail.yandex.net (mxback9o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::23]) by forward101j.mail.yandex.net (Yandex) with ESMTP id 46B651242300 for ; Thu, 14 Sep 2017 06:00:30 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback9o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id YZNVXJ6bNc-0UPOHcgS; Thu, 14 Sep 2017 06:00:30 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0TOK7sSo; Thu, 14 Sep 2017 06:00:29 +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: Thu, 14 Sep 2017 06:00:10 +0300 Message-Id: <1505358015-27878-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 dd8767b2..1e05c2c5 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 8d3c3ddf..af826b7e 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 a6f68d56..35592d85 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 650b3664..b1b735ce 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 c75f8be9..accac61c 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 Thu Sep 14 03:00:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112499 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp271487qgf; Wed, 13 Sep 2017 20:11:12 -0700 (PDT) X-Google-Smtp-Source: AOwi7QArh2sPYITeDneSvXBCu520q7xgIkks8O3C++6u5xgFCtzI+vbc5EQfJQ3wLVQfJjGR+uKP X-Received: by 10.55.72.215 with SMTP id v206mr828773qka.92.1505358671994; Wed, 13 Sep 2017 20:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358671; cv=none; d=google.com; s=arc-20160816; b=BNcS/MAfGAcXikCUiEE3+Xd1FKz7xNb5cuiE9jYis4/kmwpuizDyyBHoRoamuDZfS/ eth/j/32Xmd4RX5P9QuGvUq+JK7mjqfcnYEnma1NKB+O4+abA6z3FxmqzIPXobLjcX9o nRQ6Q2Y3+/o9004EDF8sQt7zOQAcAcT2ZiHLM2evOxSkpmrcvC8HVozTYpFvdIiPFIuz febFbYBDRRZx6N0McKK3aenMFMStXy6lPOn7e8kPwab3FzgSqWuKyAn1K4JBppKbxrRj RbUAdl/8UEVPQ2wv1mrMeAeumx9pjiPa62qHfp1qP5ApQfr1lRn0W8zvpgZvCiQpsbhL K1BA== 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=8mFgqZ7GblNMeRBm8C3X4YnjQXqI1Me5J/4CpTjx8c0=; b=g23IAFj4Rg9fKTaBnIOVaIrndguQTptXtRFEWulI3yTpWhtfr40dJgnsESddHoa5Op EFIZPDeSb9u2/cJ30E29N2LgAkNTl8ZMfzYBPbVtTKWzaKuz+QJHFFqxgao5QoqLjUPn JHP4+QVypeGtcP63fbpTokjuMhhvOKH+1W6BDzjFrICpJ8PE2eTuLFKJ2cFjqUF1VPJm dWTr6y/HzxkCSf/qAmU+V5xSul4t00uao/jNlHM86nM+sVVYdlLwiNhqVJg6YP+sU0C8 sNHdzaEKKsjd7QysE0ZdZgm3NoQaYbsyjK1iWhSIxaM6tu7MAGmKMwGUbLHbg6Ayx8+8 86Dg== 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 e31si16893032qtk.427.2017.09.13.20.11.11; Wed, 13 Sep 2017 20:11:11 -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 9CB9F62D0E; Thu, 14 Sep 2017 03:11:11 +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 EDBAB62C5C; Thu, 14 Sep 2017 03:01: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 C597462C5C; Thu, 14 Sep 2017 03:01:31 +0000 (UTC) Received: from forward104p.mail.yandex.net (forward104p.mail.yandex.net [77.88.28.107]) by lists.linaro.org (Postfix) with ESMTPS id 2B39460B3F for ; Thu, 14 Sep 2017 03:00:32 +0000 (UTC) Received: from mxback14j.mail.yandex.net (mxback14j.mail.yandex.net [IPv6:2a02:6b8:0:1619::90]) by forward104p.mail.yandex.net (Yandex) with ESMTP id E0C4D185D27 for ; Thu, 14 Sep 2017 06:00:30 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback14j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id o5RhBEDV9g-0UU41svs; Thu, 14 Sep 2017 06:00:30 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0UOKC3aN; Thu, 14 Sep 2017 06:00:30 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 14 Sep 2017 06:00:11 +0300 Message-Id: <1505358015-27878-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 1e05c2c5..78283c01 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 af826b7e..a3890091 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 00000000..6911710c --- /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 b1b735ce..fc461be7 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 98f81089..b54501ed 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 Thu Sep 14 03:00:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112501 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp273126qgf; Wed, 13 Sep 2017 20:13:41 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBbCMkRk2NGWg33+VHtDClAO5/8ARy73vbz5O+/4U1eV1/lnO5g2GomXralM7K334MY+owg X-Received: by 10.200.52.232 with SMTP id x37mr29880263qtb.85.1505358821023; Wed, 13 Sep 2017 20:13:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358821; cv=none; d=google.com; s=arc-20160816; b=LsNZ54+zRKuEf1/KIFqJ2L8R5ENIrCsmoxCja8NQyRoO7xij0grAsJbIUCdVXdyP/A LEA3nYluP8kGKQWD85lNAqxOV+3q/DT15ZeX69oXZBdaOK++JNVnKEBazPh4MkGTkDqg hxBrJyioZyxXCSO0zxtGorF7Xdf3YvB5NHc8IJqYUWG9Zg2vBd15eHhdcnD2Y2XdIl4j RtHY8ykog3CFpjN8KzvU8hU1OwLWybojvueyR2AIh//NtWHGQOP812b/UI5/rUeqJVLj vsuKBzjq3giefdqrR181qh/MUz5ehB0t/AbLDSrZwuE5XBqq4+e5bPSFhmytVO2JrqkH 7iHA== 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=tNJOeUbFEy3pjY6TBk3JM3n4qNomC3I+bsCOp/h6x6s=; b=cLVZktqjuUO8mj3oLn/JIa1e7keXQm/UwJ4gebpM4Lr3YTNDB8f6cbOrUd2w9D1fwp DCZp4hQeq09q+SdChJvAnTANuHWeBZ+cq4uLjBjhfTgjv4XAqKROzp+gmCMzMKv74USy IIFW0afKyl3hnUhqoarrsuDW+jWr49tPcd+kxjmGr73NZj+b2npztNpp3MloiSePoN1k Q9oHAqoxWRoN7wv9glFKPDDjzmZhn6TN59OhkPoYLJSszJNdryn6XLMgIDlLk5ETZq8j VHbhrJ8T0eUCUWYVWpEmWX8ZH2zsIKHE25AymBSF6Z0IMj6DFHrut0GZ6PjLHWAG5e1p eUmA== 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 b45si6041042qta.377.2017.09.13.20.13.40; Wed, 13 Sep 2017 20:13:41 -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 A49F0644BD; Thu, 14 Sep 2017 03:13:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-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 A122A63574; Thu, 14 Sep 2017 03:01:48 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id F024F60B3F; Thu, 14 Sep 2017 03:01:33 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id 7300B60B4E for ; Thu, 14 Sep 2017 03:00:33 +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 AE1C37843A9 for ; Thu, 14 Sep 2017 06:00:31 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback4g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 9nvcQfkFDI-0VnSgW0N; Thu, 14 Sep 2017 06:00:31 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0UOuUsd5; Thu, 14 Sep 2017 06: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: Thu, 14 Sep 2017 06:00:12 +0300 Message-Id: <1505358015-27878-9-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 9ebf2ea1..9d32defd 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 78283c01..b3ee86c6 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 a3890091..f58ef872 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 0e61f6f0..32c49c08 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 fc461be7..952d9be5 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 6a19394a..e023df13 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 d8f9e12c..ed2875c5 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 accac61c..07d6d9e9 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 8b8ccf03..c7c3c5a8 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 0a27316f..9054a835 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 bfe41239..a5c15e11 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 Thu Sep 14 03:00:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112502 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp274622qgf; Wed, 13 Sep 2017 20:16:05 -0700 (PDT) X-Google-Smtp-Source: AOwi7QANW50Pl93xu1Dz42lFvS5ueK31iwQnWIdV9xIdz1rVV0sfpHXEYRNdX7GSDh1fGUAWuhqQ X-Received: by 10.55.170.212 with SMTP id t203mr774477qke.292.1505358965231; Wed, 13 Sep 2017 20:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358965; cv=none; d=google.com; s=arc-20160816; b=WBPcO/y4vTuYeZ5w2GX03EjWQEPbSRiDnN/hr8SQxopGnzBoLfw4Zpyv+fs1YXSYBm Bczh1iHGYluQCRppbhdaSywzbA6Nj2AJcCEN+0TA3qXdGj9O5TMX/hiyeLQjx3sRjGZ1 eZTEHKmWnLwkXmaMZzHWm3zy1bNiZInWzTeC5mccUBGS6s3i94CFBqTwFYUjJXNgFqlD nbCH35YQFwlJeO4/GSCKspNhT9w0LD24NnDVPMNXWQbjgHNDFlL4J5fSncWSu3vUA3TT 5s29+LOoDzcRfpxlsQi0uDGYnyJcGdtz8XEHsBO4HXrz/zetcRi9FdrMMi1qmfUUk6Cg LjrA== 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=cfoYfGQp1mHBLkfJjOlmXnzoZKCU/Q/0KmMnND9JRek=; b=akrmKcwyE566AKD44Pn2svoI8P2V55/umwT5NO3Pt093dlIauP2pGK9Fy8lp3sE6g0 91EMycJaD5PMZ3A/BSF1R4XQfzIJ/CIr7Skem8Ywhl3BZq2Il2AuZJs43sS1Xb5HTwhP khrv6HLRUcfp+A0k1HTh1M6rK2JhcY2T9Oi1oqKepy6+kfTy1CzpcszQHwPpwBHk1MTC 5A1wjzsbXlaDfpytDzsH3PcOYV6N5mZTObOQpt8ur0fRECDx2WKmo+0FVeuXCtiyHtOU kf+9VuxGlR/KU2TFv23oOnEkEfM1Bpp6DSi7p/hjAvBJu2We2aW9oafjMBbDtRV5oWi4 8l/Q== 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 u64si15809829qkd.180.2017.09.13.20.16.04; Wed, 13 Sep 2017 20:16:05 -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 B6F8D644D0; Thu, 14 Sep 2017 03:16:04 +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 87DBD6351E; Thu, 14 Sep 2017 03:02:05 +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 37F506351E; Thu, 14 Sep 2017 03:01:58 +0000 (UTC) Received: from forward103j.mail.yandex.net (forward103j.mail.yandex.net [5.45.198.246]) by lists.linaro.org (Postfix) with ESMTPS id B5F7E60B4F for ; Thu, 14 Sep 2017 03:00:33 +0000 (UTC) Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward103j.mail.yandex.net (Yandex) with ESMTP id 4725634C6383 for ; Thu, 14 Sep 2017 06:00:32 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id smh1tFLlhz-0W3aeJJC; Thu, 14 Sep 2017 06:00:32 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0VOWArBQ; Thu, 14 Sep 2017 06: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: Thu, 14 Sep 2017 06:00:13 +0300 Message-Id: <1505358015-27878-10-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ 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 b3ee86c6..6261cf0a 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 f58ef872..7c2833fc 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 952d9be5..5c01e34f 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 a90bfbce..e8e2e270 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 a5c15e11..090e51b6 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 Thu Sep 14 03:00:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112503 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp275195qgf; Wed, 13 Sep 2017 20:17:06 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDRGT+GssR9jdrS94mWhTGpWzUJ2L2RQBfbFyIf5rT1+6X7iNbNEO/Zglh60KOd4qBkNewI X-Received: by 10.55.201.155 with SMTP id m27mr820294qkl.57.1505359026779; Wed, 13 Sep 2017 20:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505359026; cv=none; d=google.com; s=arc-20160816; b=HZXsys1f6n4e4SpbY8PwuJqFoxsqvr60NqKPayTPdpTci/2LtEApUuTUwclDDSz+0i bwDJiFThM0Q2Gp803xK16KqW294DmCvIJACWuLVIhljAW5zrKOFffQ+Qs+Todc0F/3b+ kesm9M1/ZPyoL65I5lHBQTPFeklo2zFCkoY+jeC9unXvMlkRXdYV2dWa7YCy2sMuOQLU woqDmKRHU8DISs2yVPWSxgEopAYJGmlDxz7OOaQzT5pFIszpEmhdwj1IPYoDWgGvseM5 LX++CpktyRhGtr1AjRJL3MAWjZ42RFu0CIeOXjROx1WpDvSyjuL2XrTYyUhHnIqOA2hh aSAQ== 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=AYCC2sUE8oIpedC2q5PX5KW3PBH8FXmM3RG0ezJ1ApU=; b=lDGljfH3FzDSM09N+U06w1wxzhxOYAzxXOp33rbEv/9ZF4DF8UtaEI9rcn5w2uiGEC tAQPDuOo/pM4o8zxzyI/0hIGlviXYGWDcC+vow2EDuyAny3+i0BB8E6+NCUAQ+8T6w3W pW4A7VdKxdTc4P+ictnDMdIv1TI/gk+eHUctluCqwu19xR9Hf00W/wYFAk5BNJGu/5jA HpLCEwPp72BqH4R1dkmuN9ynhRXjisUg9Kh64+iNJPfagu8/EF2ziWbJhVFYiz2tiLQR RhsS1iNVa1T6p521+3spLQf28pvslWtpyEtkCMZAlL4KLTjGFBUd2ZU65rmtDunbosGq XGRg== 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 r62si15931725qkc.117.2017.09.13.20.17.06; Wed, 13 Sep 2017 20:17:06 -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 62683644D4; Thu, 14 Sep 2017 03:17:06 +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 DFC486444B; Thu, 14 Sep 2017 03:02:21 +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 1435B6444A; Thu, 14 Sep 2017 03:02:09 +0000 (UTC) Received: from forward100o.mail.yandex.net (forward100o.mail.yandex.net [37.140.190.180]) by lists.linaro.org (Postfix) with ESMTPS id E628B609DB for ; Thu, 14 Sep 2017 03:00:34 +0000 (UTC) Received: from mxback3j.mail.yandex.net (mxback3j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10c]) by forward100o.mail.yandex.net (Yandex) with ESMTP id 7E7A42A2265E for ; Thu, 14 Sep 2017 06:00:33 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback3j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id tE7e2IY73O-0Xr8W94r; Thu, 14 Sep 2017 06:00:33 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0WOCbxrm; Thu, 14 Sep 2017 06: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: Thu, 14 Sep 2017 06:00:14 +0300 Message-Id: <1505358015-27878-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ platform/linux-dpdk/Makefile.am | 4 +- .../linux-dpdk/include/odp_packet_io_internal.h | 25 +--- platform/linux-dpdk/odp_init.c | 2 +- .../linux-dpdk/{odp_packet_dpdk.c => pktio/dpdk.c} | 127 ++++++++++++++------- .../{include/odp_packet_dpdk.h => pktio/dpdk.h} | 21 +++- platform/linux-dpdk/pool/dpdk.c | 2 +- platform/linux-generic/Makefile.am | 4 +- .../linux-generic/include/odp_packet_io_internal.h | 5 - .../include/odp_pktio_ops_subsystem.h | 1 + .../pktio/{pktio_common.c => common.c} | 0 platform/linux-generic/pktio/dpdk.c | 94 ++++++++++----- .../{include/odp_packet_dpdk.h => pktio/dpdk.h} | 6 +- 12 files changed, 182 insertions(+), 109 deletions(-) rename platform/linux-dpdk/{odp_packet_dpdk.c => pktio/dpdk.c} (86%) rename platform/linux-dpdk/{include/odp_packet_dpdk.h => pktio/dpdk.h} (59%) rename platform/linux-generic/pktio/{pktio_common.c => common.c} (100%) rename platform/linux-generic/{include/odp_packet_dpdk.h => pktio/dpdk.h} (96%) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 9d32defd..f0d73121 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 ba388c9c..ec1d0c21 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 cd7abce6..0a6eb469 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 214116b7..0dda05a6 100644 --- a/platform/linux-dpdk/odp_packet_dpdk.c +++ b/platform/linux-dpdk/pktio/dpdk.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -39,6 +39,18 @@ static pktio_ops_module_t dpdk_pktio_ops; static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry); +static inline pktio_ops_dpdk_data_t * + __retrieve_op_data(pktio_entry_t *pktio) +{ + return (pktio_ops_dpdk_data_t *)(pktio->ops_data(dpdk)); +} + +static inline void __release_op_data(pktio_entry_t *pktio) +{ + free(pktio->ops_data(dpdk)); + pktio->ops_data(dpdk) = NULL; +} + /* Test if s has only digits or not. Dpdk pktio uses only digits.*/ static int _dpdk_netdev_is_valid(const char *s) { @@ -95,6 +107,8 @@ static void _dpdk_print_port_mac(uint8_t portid) static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, const odp_pktin_queue_param_t *p) { + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_pktin_mode_t mode = pktio_entry->s.param.in_mode; /** @@ -102,19 +116,19 @@ static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, * at a time polls a queue */ if (mode == ODP_PKTIN_MODE_SCHED || p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) - pktio_entry->s.pkt_dpdk.lockless_rx = 1; + pkt_dpdk->lockless_rx = 1; else - pktio_entry->s.pkt_dpdk.lockless_rx = 0; + pkt_dpdk->lockless_rx = 0; if (p->hash_enable && p->num_queues > 1) { - pktio_entry->s.pkt_dpdk.hash = p->hash_proto; + pkt_dpdk->hash = p->hash_proto; } else { - pktio_entry->s.pkt_dpdk.hash.proto.ipv4_udp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv4_tcp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv4 = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6_udp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6_tcp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6 = 1; + pkt_dpdk->hash.proto.ipv4_udp = 1; + pkt_dpdk->hash.proto.ipv4_tcp = 1; + pkt_dpdk->hash.proto.ipv4 = 1; + pkt_dpdk->hash.proto.ipv6_udp = 1; + pkt_dpdk->hash.proto.ipv6_tcp = 1; + pkt_dpdk->hash.proto.ipv6 = 1; } return 0; @@ -123,7 +137,8 @@ static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, static int output_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, const odp_pktout_queue_param_t *p) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) pkt_dpdk->lockless_tx = 1; @@ -133,12 +148,14 @@ static int output_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, return 0; } -static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_entry, - const char *netdev, odp_pool_t pool ODP_UNUSED) +static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, + pktio_entry_t *pktio_entry, + const char *netdev, + odp_pool_t pool ODP_UNUSED) { uint8_t portid = 0; struct rte_eth_dev_info dev_info; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = NULL; int i; if (!_dpdk_netdev_is_valid(netdev)) { @@ -147,6 +164,14 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_ent return -1; } + pktio_entry->ops_data(dpdk) = malloc(sizeof(pktio_ops_dpdk_data_t)); + pkt_dpdk = __retrieve_op_data(pktio_entry); + + if (odp_unlikely(pkt_dpdk == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct"); + return -1; + } + portid = atoi(netdev); pkt_dpdk->portid = portid; memset(&dev_info, 0, sizeof(struct rte_eth_dev_info)); @@ -176,17 +201,21 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_ent static int close_pkt_dpdk(pktio_entry_t *pktio_entry) { - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (pktio_entry->s.state == PKTIO_STATE_STOPPED) rte_eth_dev_close(pkt_dpdk->portid); + + __release_op_data(pktio_entry); return 0; } static int start_pkt_dpdk(pktio_entry_t *pktio_entry) { int ret, i; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint8_t portid = pkt_dpdk->portid; int sid = rte_eth_dev_socket_id(pkt_dpdk->portid); int socket_id = sid < 0 ? 0 : sid; @@ -294,7 +323,9 @@ static int start_pkt_dpdk(pktio_entry_t *pktio_entry) static int stop_pkt_dpdk(pktio_entry_t *pktio_entry) { - rte_eth_dev_stop(pktio_entry->s.pkt_dpdk.portid); + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_dev_stop(pkt_dpdk->portid); return 0; } @@ -335,16 +366,15 @@ static void _odp_pktio_send_completion(pktio_entry_t *pktio_entry) odp_ticketlock_unlock(&entry->s.txl); } } - - return; } static int recv_pkt_dpdk(pktio_entry_t *pktio_entry, int index, odp_packet_t pkt_table[], int len) { uint16_t nb_rx, i; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_packet_t *saved_pkt_table; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; uint8_t min = pkt_dpdk->min_rx_burst; odp_time_t ts_val; odp_time_t *ts = NULL; @@ -459,7 +489,8 @@ static int send_pkt_dpdk(pktio_entry_t *pktio_entry, int index, const odp_packet_t pkt_table[], int len) { int pkts; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (!pkt_dpdk->lockless_tx) odp_ticketlock_lock(&pkt_dpdk->tx_lock[index]); @@ -511,10 +542,12 @@ static uint32_t _dpdk_vdev_mtu(uint8_t port_id) static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry) { + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint16_t mtu = 0; int ret; - ret = rte_eth_dev_get_mtu(pktio_entry->s.pkt_dpdk.portid, &mtu); + ret = rte_eth_dev_get_mtu(pkt_dpdk->portid, &mtu); if (ret < 0) return 0; @@ -522,7 +555,7 @@ static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry) * try to use system call if dpdk cannot get mtu value. */ if (mtu == 0) - mtu = _dpdk_vdev_mtu(pktio_entry->s.pkt_dpdk.portid); + mtu = _dpdk_vdev_mtu(pkt_dpdk->portid); return mtu; } @@ -570,13 +603,16 @@ static int _dpdk_vdev_promisc_mode_set(uint8_t port_id, int enable) static int promisc_mode_set_pkt_dpdk(pktio_entry_t *pktio_entry, int enable) { - uint8_t portid = pktio_entry->s.pkt_dpdk.portid; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + uint8_t portid = pkt_dpdk->portid; + if (enable) rte_eth_promiscuous_enable(portid); else rte_eth_promiscuous_disable(portid); - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) { + if (pkt_dpdk->vdev_sysc_promisc) { int ret = _dpdk_vdev_promisc_mode_set(portid, enable); if (ret < 0) ODP_DBG("vdev promisc mode fail\n"); @@ -605,23 +641,27 @@ static int _dpdk_vdev_promisc_mode(uint8_t port_id) if (ifr.ifr_flags & IFF_PROMISC) { ODP_DBG("promisc is 1\n"); return 1; - } else - return 0; + } + return 0; } static int promisc_mode_get_pkt_dpdk(pktio_entry_t *pktio_entry) { - uint8_t portid = pktio_entry->s.pkt_dpdk.portid; - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + uint8_t portid = pkt_dpdk->portid; + + if (pkt_dpdk->vdev_sysc_promisc) return _dpdk_vdev_promisc_mode(portid); else return rte_eth_promiscuous_get(portid); - } static int mac_get_pkt_dpdk(pktio_entry_t *pktio_entry, void *mac_addr) { - rte_eth_macaddr_get(pktio_entry->s.pkt_dpdk.portid, + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_macaddr_get(pkt_dpdk->portid, (struct ether_addr *)mac_addr); return ETH_ALEN; } @@ -630,14 +670,18 @@ static int mac_get_pkt_dpdk(pktio_entry_t *pktio_entry, void *mac_addr) static int capability_pkt_dpdk(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa) { - *capa = pktio_entry->s.pkt_dpdk.capa; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + *capa = pkt_dpdk->capa; return 0; } static int link_status_pkt_dpdk(pktio_entry_t *pktio_entry) { + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); struct rte_eth_link link; - rte_eth_link_get(pktio_entry->s.pkt_dpdk.portid, &link); + rte_eth_link_get(pkt_dpdk->portid, &link); return link.link_status; } @@ -657,25 +701,28 @@ static void stats_convert(struct rte_eth_stats *rte_stats, static int stats_pkt_dpdk(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats) { + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); int ret; struct rte_eth_stats rte_stats; - ret = rte_eth_stats_get(pktio_entry->s.pkt_dpdk.portid, &rte_stats); + ret = rte_eth_stats_get(pkt_dpdk->portid, &rte_stats); if (ret == 0) { stats_convert(&rte_stats, stats); return 0; - } else { - if (ret > 0) - return -ret; - else - return ret; } + + if (ret > 0) + return -ret; + return ret; } static int stats_reset_pkt_dpdk(pktio_entry_t *pktio_entry) { - rte_eth_stats_reset(pktio_entry->s.pkt_dpdk.portid); + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_stats_reset(pkt_dpdk->portid); return 0; } diff --git a/platform/linux-dpdk/include/odp_packet_dpdk.h b/platform/linux-dpdk/pktio/dpdk.h similarity index 59% rename from platform/linux-dpdk/include/odp_packet_dpdk.h rename to platform/linux-dpdk/pktio/dpdk.h index 495d5e6f..064c5d8c 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 499bea12..0e1dfde7 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 6261cf0a..5503535e 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 7c2833fc..9fe9aeaa 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 5c01e34f..7a915b82 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 e72a7637..511c7778 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 5d80d84a..7495b596 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 Thu Sep 14 03:00:15 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: 112504 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp276696qgf; Wed, 13 Sep 2017 20:19:27 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBMXcMxsIvZ9iSvR+bSbSvh1WCFI93nqsoSIcZX+2smK/tTYyR9C+BGW9FsqeibcA+A/Y0x X-Received: by 10.200.5.132 with SMTP id a4mr30468364qth.316.1505359167432; Wed, 13 Sep 2017 20:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505359167; cv=none; d=google.com; s=arc-20160816; b=ogVumd0oepwSNoSJzXBXo/ylW//Yfu5/wBjV8SKAr+J5J5ulPazSviOWh4nBlfChqP nG4CGroQrLAWdyBU99n4LTuJ7FmEDBdoHOtntiBRBzA99TQt6VwTCfn0/OfGL81cRedN b2la643OVyjgjSUYwlU8jR0lPNw02nZno3dKC/zdxQXWvEmh9mnp8wNr6zsMP90CXqHI K/YGIF7RPLvgQInzS1atWP+dvgRVUhZ7oz7K1oFSQTUrKPKO8YXcc36+VE0zLyIReXGc AuXBJvQ6pzLS2r6C37EBL7+JugAadg73ioPaxvF51iZf6rCOIHnH1X9rGlK4chPdICk4 lbcQ== 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=6HyeQZxHlbBG8qPz4uekhqzYRV+7ENGFUfGIT68EHvg=; b=v4FekTk6Pu79TEFzWZAwSgD4UcI5ruaM1GFozyzqWgpEb19G0l/QlUdutmJ5p510Cn bUY/42io4xs6AYj10aMZoBW0+EFSc3E7yV90WIMZAli8BgelJuosjALBCnNvRlckApoa JfUsoegEg6TnE2ZjBX2+FCJifEvf3MKMUnQcONY2vLV6gAJTNltR9WbqnD0ysYAxs4sx sM3Eq+s+URoqSOQcghdGhsBGVJVr5bC6jnMnylYCRdbS0FUjmiUoiLwwhNLjpSolAb3k NddVbmbkaPsqHJutTOHYQ1JkKjZVZXbaFiDPiJDRKLRv7hutYY+YaBPQlo1/ET0P6pdK 9fjA== 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 r30si16634954qtc.514.2017.09.13.20.19.27; Wed, 13 Sep 2017 20:19:27 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 0445F648D3; Thu, 14 Sep 2017 03:19:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, 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 667FE60A38; Thu, 14 Sep 2017 03: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 58B8963CB2; Thu, 14 Sep 2017 03:02:17 +0000 (UTC) Received: from forward105j.mail.yandex.net (forward105j.mail.yandex.net [5.45.198.248]) by lists.linaro.org (Postfix) with ESMTPS id E5A1460C0F for ; Thu, 14 Sep 2017 03:00:35 +0000 (UTC) Received: from mxback16j.mail.yandex.net (mxback16j.mail.yandex.net [IPv6:2a02:6b8:0:1619::92]) by forward105j.mail.yandex.net (Yandex) with ESMTP id C237918602E for ; Thu, 14 Sep 2017 06:00:34 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback16j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id vgPAG8QPks-0YxW5ijc; Thu, 14 Sep 2017 06:00:34 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0XOO6WWC; Thu, 14 Sep 2017 06: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: Thu, 14 Sep 2017 06:00:15 +0300 Message-Id: <1505358015-27878-12-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 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 Reviewed-by: Yi He 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: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ .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 52339b53..d8235bdf 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 428ecc82..ad3753ef 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 5503535e..50a30ac0 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 91fba1ea..ff7042b0 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 85d35f25..7862c657 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 cebf1028..00000000 --- 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 511c7778..00000000 --- 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 7495b596..00000000 --- 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 fbcf22d7..593ac916 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 8969f520..2ad3254a 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 4a143439..a9d0feee 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)