From patchwork Tue Sep 19 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: 112963 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4396579qgf; Mon, 18 Sep 2017 20:00:52 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCGCGT0yCWr5LURikCIIjGKwXhBVckQ1qXT8/jHn7Ms0mC8c5OKiTSzj22LC7MjC8IrK2k6 X-Received: by 10.200.16.6 with SMTP id z6mr14462005qti.267.1505790052201; Mon, 18 Sep 2017 20:00:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790052; cv=none; d=google.com; s=arc-20160816; b=EPUTKn70A7HdLBuws4rl8y4Nqs4OUsIAdDHa+8b8fWKIg92WDxzQduQfuq5W20Akj6 f/GQZbiTOD1Lez28hQhImXtqd19QnQoKN5v9BfaCbmAE1G2vmS8DfN5zetebxNYzHaan SDHakIqWG0ntUyFANFQxM5Vl5HLF2zFGRpHw6HIFtcuJ2+GOIUi7hAEQIaPqg/NNhUXd /0/UpNLq7UfIkmE+2KAeZ1njlSXXb2iknf+g7wRZpFTOGvD+1+qoOdhRjgwbDA7Ior9X 8aWYNSDj1EGjVdM0uh9TBo0NjDOXsJ1GM/bgj3nKt4Ee0mHS/n5H85xuMv7wPLIQK2rJ PiEg== 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=OKsuMOlJ/kUvf5nxKbln+8nL3z4z/OP6ZfAXPS3zWIo=; b=0vwbD3+hO/PkqQprJVK9gOhyIC7GJaEqmEeXc7R7g6lpxK81hdkkoFZoMl+KNyw5UR AizEzCGElFl0/XT30rlcBejs+Wm5qF7taLoRFmUOOUfZIujr0SlSbK4OZ1RjCpXZazWM JLp4Das4NCW7HI/fs9iILC1iSj2WH6XZSPnCPO4mDeuLbmZddJc9nTXy+bUuX4oAT8XN bfBTI4n10ha/i2H9mAtXyK1lTVM/h5M8i1XRDA4pl5ovZeSxfwKsv2HDTRqEgIe4CJ+G ZPYv9pskenUaoED87xriHPL0YgKxbQwZy+XrwTPUfT3hkEwEIoItX3EsEYgQlEaz7lRJ kWGQ== 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 3si912864qtp.421.2017.09.18.20.00.51; Mon, 18 Sep 2017 20:00:52 -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 1C40B62876; Tue, 19 Sep 2017 03:00:51 +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 4B95861D9B; Tue, 19 Sep 2017 03:00:40 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id BC2B561D9B; Tue, 19 Sep 2017 03:00:36 +0000 (UTC) Received: from forward103o.mail.yandex.net (forward103o.mail.yandex.net [37.140.190.177]) by lists.linaro.org (Postfix) with ESMTPS id 1FEED61D00 for ; Tue, 19 Sep 2017 03:00:34 +0000 (UTC) Received: from mxback4j.mail.yandex.net (mxback4j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10d]) by forward103o.mail.yandex.net (Yandex) with ESMTP id 8F211588448B for ; Tue, 19 Sep 2017 06:00:32 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback4j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id vF8FBUXF6H-0W3WaX3D; Tue, 19 Sep 2017 06:00:32 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0VRKrsWb; Tue, 19 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: Tue, 19 Sep 2017 06:00:15 +0300 Message-Id: <1505790024-16070-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 1/10] framework: modular: extern SUBSYSTEM_FOREACH_TEMPLATE X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Static SUBSYSTEM_FOREACH_TEMPLATE constraints the functions to be instantiated in the source files which invoke them, this causes code scatter shoots. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Kevin Wang Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ frameworks/modular/odp_module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/modular/odp_module.h b/frameworks/modular/odp_module.h index 1a9e178c3..59f67c8d4 100644 --- a/frameworks/modular/odp_module.h +++ b/frameworks/modular/odp_module.h @@ -206,7 +206,7 @@ struct odp_module_base { * subsystem and invoke init_global method for each. */ #define ODP_SUBSYSTEM_FOREACH_TEMPLATE(subs, method, print) \ -static int odp_ ## subs ##_## method(bool continue_on_errors) \ +int odp_ ## subs ##_## method(bool continue_on_errors) \ { \ int result = 0; \ ODP_MODULE_CLASS(subs) * mod = NULL; \ From patchwork Tue Sep 19 03:00:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112964 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4397882qgf; Mon, 18 Sep 2017 20:02:32 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDEakl8ISl6u2maeu9Vf2m3nA4ErfUKfFENgXgyC3ZkfQqHIEmoG6jzdbqn51T2X8vElwwn X-Received: by 10.200.4.169 with SMTP id s41mr47548925qtg.132.1505790152052; Mon, 18 Sep 2017 20:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790152; cv=none; d=google.com; s=arc-20160816; b=ApUO7X4/asYSGcxf6fyHQQ6k7IZyS+Z+QDHBo5Fu39krkKAY7UmYM19OCYcAqdfurt C5z4+rlc+fzCTsB2qdgsVv4q/OPnQzzIMuzMUtSvpqk+Wzrzz8tGr2nRbpuBtxG4ZBsk HEHlpcn8wE1fEtDfBEYwCpDtO0XAESDTRPN4hjsXA0dG0sDcBEWYvyqm6a+99pa93h42 EeY4Xol9XLgxI5OHE0iIS3kpFtM+1bZIPrF9Wrdd/K6WUtVYosrEaN/28jukVad/XM00 w+fJ/GbOPWa7XD8ptsD1/D3ZWS6wBCa3OL3SKyr5H4807DpbNhDn5pRG1dXZOFKJ9T/W PA3A== 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=TEPyCE2luaqCagNzEF4TV9uaLEhlK1A0ppewtAkbwME=; b=qq8Nx5TQW0j58u5ya7JtPXhuC0j3qB/zuKcmmER03mPOHzwqiTi75ucSTJkwcu0Bn1 FFIVGU9zVDzCTRtGFKMtKdRHWeIy5OWyPDd2cE6JUCA9AYlAYvSTcLdALwWdJDO0mxiW LWHW4KZEe/s2qkr+w3U4wyBrrTemE5KmbtK0Ir9iFySyijQGCy48QqFYaPxHHrfo00FS cG2M9gtzOIpYESrAtDL9jq1e5h5fYuRkpVjtwpFLMDhsuiJVby4REslcoZ2EV/B62grJ MjfVVn9Lt882KGia+hc1HG0JpLvTOpIh7O//3/Yc4rX12daoi/PSKyiGfSGLPs1XnrXe qe8Q== 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 f2si3454736qtl.481.2017.09.18.20.02.31; Mon, 18 Sep 2017 20:02:32 -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 8C0BD62D1B; Tue, 19 Sep 2017 03:02:31 +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 1D7E861D00; Tue, 19 Sep 2017 03:00:49 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0975661D00; Tue, 19 Sep 2017 03:00:39 +0000 (UTC) Received: from forward101j.mail.yandex.net (forward101j.mail.yandex.net [5.45.198.241]) by lists.linaro.org (Postfix) with ESMTPS id D317760F1D for ; Tue, 19 Sep 2017 03:00:34 +0000 (UTC) Received: from mxback9g.mail.yandex.net (mxback9g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:170]) by forward101j.mail.yandex.net (Yandex) with ESMTP id 31D361243987 for ; Tue, 19 Sep 2017 06:00:33 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback9g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id A7OZYHArW8-0XcG6Uqj; Tue, 19 Sep 2017 06:00:33 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0WRii3xi; Tue, 19 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: Tue, 19 Sep 2017 06:00:16 +0300 Message-Id: <1505790024-16070-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 2/10] example: l2fwd_simple: disable socket pktios X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He l2fwd_simple_run.sh waits 1 second to allow test application to forward more than 10 packets. It works in case pktios are listed statically and pcap takes precedence over socket pktios. But with dynamically registered pktios the order was not guaranteed and socket pktios may take precedence over pcap pktio, which spent more time in open operation and caused this test failed. Disable the socket pktios since they mistakenly take too long time in open operation, future code refactory should solve the problem thoroughly. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Kevin Wang Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ example/l2fwd_simple/l2fwd_simple_run.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/example/l2fwd_simple/l2fwd_simple_run.sh b/example/l2fwd_simple/l2fwd_simple_run.sh index 130a3a848..0c464f70c 100755 --- a/example/l2fwd_simple/l2fwd_simple_run.sh +++ b/example/l2fwd_simple/l2fwd_simple_run.sh @@ -6,6 +6,11 @@ # SPDX-License-Identifier: BSD-3-Clause # +# Disable socket pktios since their open operations +# mistakenly take too long time +export ODP_PKTIO_DISABLE_SOCKET_MMSG=1 +export ODP_PKTIO_DISABLE_SOCKET_MMAP=1 + PCAP_IN=`find . ${TEST_DIR} $(dirname $0) -name udp64.pcap -print -quit` echo "using PCAP_IN = ${PCAP_IN}" From patchwork Tue Sep 19 03:00:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112967 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4400411qgf; Mon, 18 Sep 2017 20:05:52 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAGhThhq7A6fTB1rE4OspOhL4JjiDjSUNvMaiNVJUXFFlaUEcCYYAJvmMcrtvMACWOm8gdN X-Received: by 10.233.239.69 with SMTP id d66mr22938042qkg.296.1505790352244; Mon, 18 Sep 2017 20:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790352; cv=none; d=google.com; s=arc-20160816; b=yqPmrW13r24BAe542lbKojK7wlR9ElTsdHS19smNjlHh3yyQS5mnNv77vB3e6Nq2jH ZBOYhKx6BLGmbIfkdhZAFCIEIEh7kIAoE8mqFrrQEgrIDLb5fc6d2kRDlDNAFqe+50Mj obdQfb1ufBTOfqI9dam9ZNr1zpepdS8g1EwpR7lXGhz7ZATWYVYgielmvVjI4m0X0qKu 5RncQjzB4S5iVDMedpbmO9SRc5ztbiHomy8EZs3pJYv/9FnqI8m5FzI30aF3pWaW9mEu rPIkqH7tT1Ws6zrSCx/WNtK+PTxYdHFMVH4Vdc5VoL0wuHz2tR7pPCl9X/+B2rv98+XL eJhg== 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=Dy+8OB8FN2lbVoiD65Yw7z6XG8/DR6iTnTRUq7FR0bE=; b=SwQ1VX37Y+J/PP7lStAJ+K0aWltQcRuLASdW9t+8s1iT1BB9FcPO6TEOH+g+cch1yp FuSPkdMTIr75FIOlep59JIkla95XEwn7ny2tvu5Z5a/a9qlJLk7ZEi9FfLmoSnR+E89b oN42wqeLrFwhpnwA+IahhPOZhnLUDDjXc90LIQtIuuY37NcnCR3OW0OFHonQfCEDJhAI imtx9QZozuK919T/1qSaqexrjTVWSLxy34AijlcgUPh4AeRlngTtF/6A2Z6EOszTJ3M+ s/CXIlDZVsS0G6rPZw3rrgnNwHTQ8WoFHs+ViwY/hGYhYTTmXJcTGtmWPmmvcloEbctC YQpA== 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 l52si8568642qtb.162.2017.09.18.20.05.51; Mon, 18 Sep 2017 20:05:52 -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 CB44A62CFA; Tue, 19 Sep 2017 03:05:51 +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 3D67F62C7E; Tue, 19 Sep 2017 03:01:13 +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 1D83361D00; Tue, 19 Sep 2017 03:00:48 +0000 (UTC) Received: from forward103o.mail.yandex.net (forward103o.mail.yandex.net [37.140.190.177]) by lists.linaro.org (Postfix) with ESMTPS id 9258A61D9A for ; Tue, 19 Sep 2017 03:00:35 +0000 (UTC) Received: from mxback7o.mail.yandex.net (mxback7o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::21]) by forward103o.mail.yandex.net (Yandex) with ESMTP id 840F4588448B for ; Tue, 19 Sep 2017 06:00:34 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback7o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id XkaUJxxB2v-0YYKWhGn; Tue, 19 Sep 2017 06:00:34 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0XRixwOR; Tue, 19 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: Tue, 19 Sep 2017 06:00:17 +0300 Message-Id: <1505790024-16070-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 3/10] linux-gen: pktio: apply modular framework X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Apply modular framework to the pktio ops registration, convert the static array for impls registration into a dynamic and extensible modularization manner. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Kevin Wang Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ platform/linux-dpdk/Makefile.am | 2 + .../linux-dpdk/include/odp_packet_io_internal.h | 49 ++----------- platform/linux-dpdk/odp_packet_dpdk.c | 39 +++++++---- platform/linux-dpdk/pktio/subsystem.c | 33 +++++++++ platform/linux-generic/Makefile.am | 3 +- .../linux-generic/include/odp_packet_io_internal.h | 59 ++-------------- .../include/odp_pktio_ops_subsystem.h | 81 ++++++++++++++++++++++ platform/linux-generic/odp_packet_io.c | 57 ++++----------- platform/linux-generic/pktio/dpdk.c | 34 ++++++--- platform/linux-generic/pktio/io_ops.c | 31 --------- platform/linux-generic/pktio/ipc.c | 43 +++++++++--- platform/linux-generic/pktio/loop.c | 31 ++++++--- platform/linux-generic/pktio/netmap.c | 37 +++++++--- platform/linux-generic/pktio/pcap.c | 33 +++++++-- platform/linux-generic/pktio/socket.c | 31 ++++++--- platform/linux-generic/pktio/socket_mmap.c | 31 ++++++--- platform/linux-generic/pktio/subsystem.c | 58 ++++++++++++++++ platform/linux-generic/pktio/tap.c | 38 +++++++--- 18 files changed, 435 insertions(+), 255 deletions(-) create mode 100644 platform/linux-dpdk/pktio/subsystem.c create mode 100644 platform/linux-generic/include/odp_pktio_ops_subsystem.h delete mode 100644 platform/linux-generic/pktio/io_ops.c create mode 100644 platform/linux-generic/pktio/subsystem.c diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 587d4836f..83931d27a 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -189,6 +189,7 @@ noinst_HEADERS = \ ${top_srcdir}/platform/linux-generic/include/odp_internal.h \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_internal.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ @@ -242,6 +243,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ ../linux-generic/odp_name_table.c \ odp_packet.c \ odp_packet_dpdk.c \ + pktio/subsystem.c \ odp_packet_flags.c \ ../linux-generic/odp_packet_io.c \ ../linux-generic/pktio/loop.c \ diff --git a/platform/linux-dpdk/include/odp_packet_io_internal.h b/platform/linux-dpdk/include/odp_packet_io_internal.h index 14b6a8d3b..fde172fc5 100644 --- a/platform/linux-dpdk/include/odp_packet_io_internal.h +++ b/platform/linux-dpdk/include/odp_packet_io_internal.h @@ -31,13 +31,16 @@ extern "C" { #include #include +/* Forward declaration */ +typedef union pktio_entry_u pktio_entry_t; +#include + #define PKTIO_NAME_LEN 256 #define PKTIN_INVALID ((odp_pktin_queue_t) {ODP_PKTIO_INVALID, 0}) #define PKTOUT_INVALID ((odp_pktout_queue_t) {ODP_PKTIO_INVALID, 0}) /* Forward declaration */ -struct pktio_if_ops; struct pkt_dpdk_t; typedef struct { @@ -63,7 +66,7 @@ typedef struct { } pkt_dpdk_t; struct pktio_entry { - const struct pktio_if_ops *ops; /**< Implementation specific methods */ + const pktio_ops_module_t *ops; /**< Implementation specific methods */ /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ @@ -116,50 +119,16 @@ struct pktio_entry { } out_queue[PKTIO_MAX_QUEUES]; }; -typedef union { +union pktio_entry_u { struct pktio_entry s; uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(struct pktio_entry))]; -} pktio_entry_t; +}; typedef struct { odp_spinlock_t lock; pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; } pktio_table_t; -typedef struct pktio_if_ops { - const char *name; - void (*print)(pktio_entry_t *pktio_entry); - int (*init_global)(void); - int (*init_local)(void); - int (*term)(void); - int (*open)(odp_pktio_t pktio, pktio_entry_t *pktio_entry, - const char *devname, odp_pool_t pool); - int (*close)(pktio_entry_t *pktio_entry); - int (*start)(pktio_entry_t *pktio_entry); - int (*stop)(pktio_entry_t *pktio_entry); - int (*stats)(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats); - int (*stats_reset)(pktio_entry_t *pktio_entry); - uint64_t (*pktin_ts_res)(pktio_entry_t *pktio_entry); - odp_time_t (*pktin_ts_from_ns)(pktio_entry_t *pktio_entry, uint64_t ns); - int (*recv)(pktio_entry_t *entry, int index, odp_packet_t packets[], - int num); - int (*send)(pktio_entry_t *entry, int index, - const odp_packet_t packets[], int num); - uint32_t (*mtu_get)(pktio_entry_t *pktio_entry); - int (*promisc_mode_set)(pktio_entry_t *pktio_entry, int enable); - int (*promisc_mode_get)(pktio_entry_t *pktio_entry); - int (*mac_get)(pktio_entry_t *pktio_entry, void *mac_addr); - int (*link_status)(pktio_entry_t *pktio_entry); - int (*capability)(pktio_entry_t *pktio_entry, - odp_pktio_capability_t *capa); - int (*config)(pktio_entry_t *pktio_entry, - const odp_pktio_config_t *config); - int (*input_queues_config)(pktio_entry_t *pktio_entry, - const odp_pktin_queue_param_t *param); - int (*output_queues_config)(pktio_entry_t *pktio_entry, - const odp_pktout_queue_param_t *p); -} pktio_if_ops_t; - extern void *pktio_entry_ptr[]; static inline int pktio_to_id(odp_pktio_t pktio) @@ -203,10 +172,6 @@ int single_recv_queue(pktio_entry_t *entry, int index, odp_packet_t packets[], int single_send_queue(pktio_entry_t *entry, int index, const odp_packet_t packets[], int num); -extern const pktio_if_ops_t loopback_pktio_ops; -extern const pktio_if_ops_t dpdk_pktio_ops; -extern const pktio_if_ops_t * const pktio_if_ops[]; - int pktin_poll(int pktio_index, int num_queue, int index[]); void pktio_stop_finalize(int pktio_index); diff --git a/platform/linux-dpdk/odp_packet_dpdk.c b/platform/linux-dpdk/odp_packet_dpdk.c index d808f130f..214116b76 100644 --- a/platform/linux-dpdk/odp_packet_dpdk.c +++ b/platform/linux-dpdk/odp_packet_dpdk.c @@ -32,18 +32,11 @@ #include #include -/* Ops for all implementation of pktio. - * Order matters. The first implementation to setup successfully - * will be picked. - * Array must be NULL terminated */ -const pktio_if_ops_t * const pktio_if_ops[] = { - &loopback_pktio_ops, - &dpdk_pktio_ops, - NULL -}; - pktio_table_t *pktio_tbl; +/* Forward declaration */ +static pktio_ops_module_t dpdk_pktio_ops; + static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry); /* Test if s has only digits or not. Dpdk pktio uses only digits.*/ @@ -686,12 +679,15 @@ static int stats_reset_pkt_dpdk(pktio_entry_t *pktio_entry) return 0; } -const pktio_if_ops_t dpdk_pktio_ops = { - .name = "odp-dpdk", +static pktio_ops_module_t dpdk_pktio_ops = { + .base = { + .name = "dpdk", + .init_local = NULL, + .init_global = NULL, + .term_local = NULL, + .term_global = NULL, + }, .print = NULL, - .init_global = NULL, - .init_local = NULL, - .term = NULL, .open = setup_pkt_dpdk, .close = close_pkt_dpdk, .start = start_pkt_dpdk, @@ -712,3 +708,16 @@ const pktio_if_ops_t dpdk_pktio_ops = { .recv = recv_pkt_dpdk, .send = send_pkt_dpdk }; + +ODP_MODULE_CONSTRUCTOR(dpdk_pktio_ops) +{ + odp_module_constructor(&dpdk_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &dpdk_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_dpdk_pktio_ops = 0; + diff --git a/platform/linux-dpdk/pktio/subsystem.c b/platform/linux-dpdk/pktio/subsystem.c new file mode 100644 index 000000000..4ff15c814 --- /dev/null +++ b/platform/linux-dpdk/pktio/subsystem.c @@ -0,0 +1,33 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +#define SUBSYSTEM_VERSION 0x00010000UL +ODP_SUBSYSTEM_DEFINE(pktio_ops, "packet IO operations", SUBSYSTEM_VERSION); + +/* Instantiate init and term functions */ +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_global, ODP_ERR) +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_local, ODP_ERR) +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, term_global, ODP_ABORT) + +/* Temporary variable to enable link modules, + * will remove in Makefile scheme changes. + */ +extern int enable_link_dpdk_pktio_ops; +extern int enable_link_loopback_pktio_ops; + +ODP_SUBSYSTEM_CONSTRUCTOR(pktio_ops) +{ + odp_subsystem_constructor(pktio_ops); + + /* Further initialization per subsystem */ + enable_link_dpdk_pktio_ops = 1; + enable_link_loopback_pktio_ops = 1; +} diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index cbbefa4e6..ff08a6ef4 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -191,6 +191,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ + ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ ${srcdir}/include/odp_pool_subsystem.h \ @@ -262,7 +263,7 @@ __LIB__libodp_linux_la_SOURCES = \ odp_packet_flags.c \ odp_packet_io.c \ pktio/ethtool.c \ - pktio/io_ops.c \ + pktio/subsystem.c \ pktio/ipc.c \ pktio/pktio_common.c \ pktio/loop.c \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index dc049f467..589148400 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -36,6 +36,10 @@ extern "C" { #include #include +/* Forward declaration */ +typedef union pktio_entry_u pktio_entry_t; +#include + #define PKTIO_NAME_LEN 256 #define PKTIN_INVALID ((odp_pktin_queue_t) {ODP_PKTIO_INVALID, 0}) @@ -47,9 +51,6 @@ extern "C" { * requested number of packets were not handled. */ #define SOCK_ERR_REPORT(e) (e != EAGAIN && e != EWOULDBLOCK && e != EINTR) -/* Forward declaration */ -struct pktio_if_ops; - typedef struct { odp_queue_t loopq; /**< loopback queue for "loop" device */ odp_bool_t promisc; /**< promiscuous mode state */ @@ -109,7 +110,7 @@ typedef struct { } _ipc_pktio_t; struct pktio_entry { - const struct pktio_if_ops *ops; /**< Implementation specific methods */ + const pktio_ops_module_t *ops; /**< Implementation specific methods */ /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ @@ -177,50 +178,16 @@ struct pktio_entry { } out_queue[PKTIO_MAX_QUEUES]; }; -typedef union { +union pktio_entry_u { struct pktio_entry s; uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(struct pktio_entry))]; -} pktio_entry_t; +}; typedef struct { odp_spinlock_t lock; pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; } pktio_table_t; -typedef struct pktio_if_ops { - const char *name; - void (*print)(pktio_entry_t *pktio_entry); - int (*init_global)(void); - int (*init_local)(void); - int (*term)(void); - int (*open)(odp_pktio_t pktio, pktio_entry_t *pktio_entry, - const char *devname, odp_pool_t pool); - int (*close)(pktio_entry_t *pktio_entry); - int (*start)(pktio_entry_t *pktio_entry); - int (*stop)(pktio_entry_t *pktio_entry); - int (*stats)(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats); - int (*stats_reset)(pktio_entry_t *pktio_entry); - uint64_t (*pktin_ts_res)(pktio_entry_t *pktio_entry); - odp_time_t (*pktin_ts_from_ns)(pktio_entry_t *pktio_entry, uint64_t ns); - int (*recv)(pktio_entry_t *entry, int index, odp_packet_t packets[], - int num); - int (*send)(pktio_entry_t *entry, int index, - const odp_packet_t packets[], int num); - uint32_t (*mtu_get)(pktio_entry_t *pktio_entry); - int (*promisc_mode_set)(pktio_entry_t *pktio_entry, int enable); - int (*promisc_mode_get)(pktio_entry_t *pktio_entry); - int (*mac_get)(pktio_entry_t *pktio_entry, void *mac_addr); - int (*link_status)(pktio_entry_t *pktio_entry); - int (*capability)(pktio_entry_t *pktio_entry, - odp_pktio_capability_t *capa); - int (*config)(pktio_entry_t *pktio_entry, - const odp_pktio_config_t *config); - int (*input_queues_config)(pktio_entry_t *pktio_entry, - const odp_pktin_queue_param_t *param); - int (*output_queues_config)(pktio_entry_t *pktio_entry, - const odp_pktout_queue_param_t *p); -} pktio_if_ops_t; - extern void *pktio_entry_ptr[]; static inline int pktio_to_id(odp_pktio_t pktio) @@ -252,18 +219,6 @@ static inline void pktio_cls_enabled_set(pktio_entry_t *entry, int ena) entry->s.cls_enabled = ena; } -extern const pktio_if_ops_t netmap_pktio_ops; -extern const pktio_if_ops_t dpdk_pktio_ops; -extern const pktio_if_ops_t sock_mmsg_pktio_ops; -extern const pktio_if_ops_t sock_mmap_pktio_ops; -extern const pktio_if_ops_t loopback_pktio_ops; -#ifdef HAVE_PCAP -extern const pktio_if_ops_t pcap_pktio_ops; -#endif -extern const pktio_if_ops_t tap_pktio_ops; -extern const pktio_if_ops_t ipc_pktio_ops; -extern const pktio_if_ops_t * const pktio_if_ops[]; - int sysfs_stats(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats); int sock_stats_fd(pktio_entry_t *pktio_entry, diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h new file mode 100644 index 000000000..ff497a2ac --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -0,0 +1,81 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_SUBSYSTEM_H_ +#define ODP_PKTIO_OPS_SUBSYSTEM_H_ + +#include +#include + +/* ODP packet IO operations subsystem declaration */ +ODP_SUBSYSTEM_DECLARE(pktio_ops); + +/* Subsystem APIs declarations */ +ODP_SUBSYSTEM_API(pktio_ops, int, open, odp_pktio_t, + pktio_entry_t *, const char *, odp_pool_t); +ODP_SUBSYSTEM_API(pktio_ops, int, close, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, start, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, stop, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, stats, pktio_entry_t *, + odp_pktio_stats_t *stats); +ODP_SUBSYSTEM_API(pktio_ops, int, stats_reset, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, uint64_t, pktin_ts_res, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, odp_time_t, pktin_ts_from_ns, + pktio_entry_t *, uint64_t ns); +ODP_SUBSYSTEM_API(pktio_ops, int, recv, pktio_entry_t *, + int index, odp_packet_t packets[], int count); +ODP_SUBSYSTEM_API(pktio_ops, int, send, pktio_entry_t *, + int index, const odp_packet_t packets[], int count); +ODP_SUBSYSTEM_API(pktio_ops, uint32_t, mtu_get, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, promisc_mode_set, + pktio_entry_t *, int enable); +ODP_SUBSYSTEM_API(pktio_ops, int, promisc_mode_get, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, mac_get, pktio_entry_t *, void *); +ODP_SUBSYSTEM_API(pktio_ops, int, link_status, pktio_entry_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, capability, pktio_entry_t *, + odp_pktio_capability_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, config, pktio_entry_t *, + const odp_pktio_config_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, input_queues_config, + pktio_entry_t *, const odp_pktin_queue_param_t *); +ODP_SUBSYSTEM_API(pktio_ops, int, output_queues_config, + pktio_entry_t *, const odp_pktout_queue_param_t *); +ODP_SUBSYSTEM_API(pktio_ops, void, print, pktio_entry_t *); + +/* Declare subsystem init and term routines */ +ODP_SUBSYSTEM_API(pktio_ops, int, init_global, bool); +ODP_SUBSYSTEM_API(pktio_ops, int, init_local, bool); +ODP_SUBSYSTEM_API(pktio_ops, int, term_global, bool); +ODP_SUBSYSTEM_API(pktio_ops, int, term_local, bool); + +typedef ODP_MODULE_CLASS(pktio_ops) { + odp_module_base_t base; + + odp_api_proto(pktio_ops, open) open; + odp_api_proto(pktio_ops, close) close; + odp_api_proto(pktio_ops, start) start; + odp_api_proto(pktio_ops, stop) stop; + odp_api_proto(pktio_ops, stats) stats; + odp_api_proto(pktio_ops, stats_reset) stats_reset; + odp_api_proto(pktio_ops, pktin_ts_res) pktin_ts_res; + odp_api_proto(pktio_ops, pktin_ts_from_ns) pktin_ts_from_ns; + odp_api_proto(pktio_ops, recv) recv; + odp_api_proto(pktio_ops, send) send; + odp_api_proto(pktio_ops, mtu_get) mtu_get; + odp_api_proto(pktio_ops, promisc_mode_set) promisc_mode_set; + odp_api_proto(pktio_ops, promisc_mode_get) promisc_mode_get; + odp_api_proto(pktio_ops, mac_get) mac_get; + odp_api_proto(pktio_ops, link_status) link_status; + odp_api_proto(pktio_ops, capability) capability; + odp_api_proto(pktio_ops, config) config; + odp_api_proto(pktio_ops, input_queues_config) input_queues_config; + odp_api_proto(pktio_ops, output_queues_config) output_queues_config; + odp_api_proto(pktio_ops, print) print; +} pktio_ops_module_t; + +#endif diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index e78c712e4..d8dcc45da 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -51,7 +51,6 @@ int odp_pktio_init_global(void) pktio_entry_t *pktio_entry; int i; odp_shm_t shm; - int pktio_if; shm = odp_shm_reserve("odp_pktio_entries", sizeof(pktio_table_t), @@ -76,32 +75,12 @@ int odp_pktio_init_global(void) pktio_entry_ptr[i] = pktio_entry; } - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - if (pktio_if_ops[pktio_if]->init_global) - if (pktio_if_ops[pktio_if]->init_global()) { - ODP_ERR("failed to initialized pktio type %d", - pktio_if); - return -1; - } - } - - return 0; + return odp_pktio_ops_init_global(true); } int odp_pktio_init_local(void) { - int pktio_if; - - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - if (pktio_if_ops[pktio_if]->init_local) - if (pktio_if_ops[pktio_if]->init_local()) { - ODP_ERR("failed to initialized pktio type %d", - pktio_if); - return -1; - } - } - - return 0; + return odp_pktio_ops_init_local(true); } static inline int is_free(pktio_entry_t *entry) @@ -181,8 +160,7 @@ static odp_pktio_t setup_pktio_entry(const char *name, odp_pool_t pool, { odp_pktio_t hdl; pktio_entry_t *pktio_entry; - int ret = -1; - int pktio_if; + pktio_ops_module_t *mod; if (strlen(name) >= PKTIO_NAME_LEN - 1) { /* ioctl names limitation */ @@ -202,25 +180,24 @@ static odp_pktio_t setup_pktio_entry(const char *name, odp_pool_t pool, if (!pktio_entry) return ODP_PKTIO_INVALID; + pktio_entry->s.ops = NULL; /* Reset stale ops */ pktio_entry->s.pool = pool; memcpy(&pktio_entry->s.param, param, sizeof(odp_pktio_param_t)); pktio_entry->s.handle = hdl; odp_pktio_config_init(&pktio_entry->s.config); - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - ret = pktio_if_ops[pktio_if]->open(hdl, pktio_entry, name, - pool); - - if (!ret) { - pktio_entry->s.ops = pktio_if_ops[pktio_if]; - ODP_DBG("%s uses %s\n", - name, pktio_if_ops[pktio_if]->name); + odp_subsystem_lock(read, pktio_ops); + odp_subsystem_foreach_module(pktio_ops, mod) { + if (0 == mod->open(hdl, pktio_entry, name, pool)) { + pktio_entry->s.ops = mod; + ODP_DBG("%s uses %s\n", name, mod->base.name); break; } } + odp_subsystem_unlock(read, pktio_ops); - if (ret != 0) { + if (pktio_entry->s.ops == NULL) { pktio_entry->s.state = PKTIO_STATE_FREE; hdl = ODP_PKTIO_INVALID; ODP_ERR("Unable to init any I/O type.\n"); @@ -913,7 +890,7 @@ int odp_pktio_info(odp_pktio_t hdl, odp_pktio_info_t *info) memset(info, 0, sizeof(odp_pktio_info_t)); info->name = entry->s.name; - info->drv_name = entry->s.ops->name; + info->drv_name = entry->s.ops->base.name; info->pool = entry->s.pool; memcpy(&info->param, &entry->s.param, sizeof(odp_pktio_param_t)); @@ -988,7 +965,7 @@ void odp_pktio_print(odp_pktio_t hdl) len += snprintf(&str[len], n - len, " name %s\n", entry->s.name); len += snprintf(&str[len], n - len, - " type %s\n", entry->s.ops->name); + " type %s\n", entry->s.ops->base.name); len += snprintf(&str[len], n - len, " state %s\n", entry->s.state == PKTIO_STATE_STARTED ? "start" : @@ -1030,7 +1007,6 @@ int odp_pktio_term_global(void) { int ret = 0; int i; - int pktio_if; for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; ++i) { pktio_entry_t *pktio_entry; @@ -1056,12 +1032,7 @@ int odp_pktio_term_global(void) unlock_entry(pktio_entry); } - for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { - if (pktio_if_ops[pktio_if]->term) - if (pktio_if_ops[pktio_if]->term()) - ODP_ABORT("failed to terminate pktio type %d", - pktio_if); - } + ret = odp_pktio_ops_term_global(false); ret = odp_shm_free(odp_shm_lookup("odp_pktio_entries")); if (ret != 0) diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index 9e3e583da..e72a76371 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -1290,30 +1290,46 @@ static int dpdk_stats_reset(pktio_entry_t *pktio_entry) return 0; } -const pktio_if_ops_t dpdk_pktio_ops = { - .name = "dpdk", - .init_global = dpdk_pktio_init_global, - .init_local = dpdk_pktio_init_local, - .term = NULL, +static pktio_ops_module_t dpdk_pktio_ops = { + .base = { + .name = "dpdk", + .init_local = dpdk_pktio_init_local, + .init_global = dpdk_pktio_init_global, + .term_local = NULL, + .term_global = NULL, + }, .open = dpdk_open, .close = dpdk_close, .start = dpdk_start, .stop = dpdk_stop, .stats = dpdk_stats, .stats_reset = dpdk_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = dpdk_recv, .send = dpdk_send, - .link_status = dpdk_link_status, .mtu_get = dpdk_mtu_get, .promisc_mode_set = dpdk_promisc_mode_set, .promisc_mode_get = dpdk_promisc_mode_get, .mac_get = dpdk_mac_addr_get, + .link_status = dpdk_link_status, .capability = dpdk_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = dpdk_input_queues_config, - .output_queues_config = dpdk_output_queues_config + .output_queues_config = dpdk_output_queues_config, + .print = NULL, }; +ODP_MODULE_CONSTRUCTOR(dpdk_pktio_ops) +{ + odp_module_constructor(&dpdk_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &dpdk_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_dpdk_pktio_ops = 0; + #endif /* ODP_PKTIO_DPDK */ diff --git a/platform/linux-generic/pktio/io_ops.c b/platform/linux-generic/pktio/io_ops.c deleted file mode 100644 index fbf30ca7a..000000000 --- a/platform/linux-generic/pktio/io_ops.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (c) 2013, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include - -/* Ops for all implementation of pktio. - * Order matters. The first implementation to setup successfully - * will be picked. - * Array must be NULL terminated */ -const pktio_if_ops_t * const pktio_if_ops[] = { - &loopback_pktio_ops, -#ifdef ODP_PKTIO_DPDK - &dpdk_pktio_ops, -#endif -#ifdef ODP_NETMAP - &netmap_pktio_ops, -#endif -#ifdef HAVE_PCAP - &pcap_pktio_ops, -#endif -#ifdef _ODP_PKTIO_IPC - &ipc_pktio_ops, -#endif - &tap_pktio_ops, - &sock_mmap_pktio_ops, - &sock_mmsg_pktio_ops, - NULL -}; diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 8c7db84e6..984f0ab44 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -771,23 +771,44 @@ static int ipc_pktio_init_global(void) return 0; } -const pktio_if_ops_t ipc_pktio_ops = { - .name = "ipc", - .print = NULL, - .init_global = ipc_pktio_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t ipc_pktio_ops = { + .base = { + .name = "ipc", + .init_local = NULL, + .term_local = NULL, + .init_global = ipc_pktio_init_global, + .term_global = NULL, + }, .open = ipc_pktio_open, .close = ipc_close, - .recv = ipc_pktio_recv, - .send = ipc_pktio_send, .start = ipc_start, .stop = ipc_stop, + .stats = NULL, + .stats_reset = NULL, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, + .recv = ipc_pktio_recv, + .send = ipc_pktio_send, .mtu_get = ipc_mtu_get, .promisc_mode_set = NULL, .promisc_mode_get = NULL, .mac_get = ipc_mac_addr_get, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, - .config = NULL + .link_status = NULL, + .capability = NULL, + .config = NULL, + .input_queues_config = NULL, + .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(ipc_pktio_ops) +{ + odp_module_constructor(&ipc_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &ipc_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_ipc_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index c825393ac..39718a892 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -251,18 +251,22 @@ static int loop_init_global(void) return 0; } -const pktio_if_ops_t loopback_pktio_ops = { - .name = "loop", - .print = NULL, - .init_global = loop_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t loopback_pktio_ops = { + .base = { + .name = "loopback", + .init_local = NULL, + .term_local = NULL, + .init_global = loop_init_global, + .term_global = NULL, + }, .open = loopback_open, .close = loopback_close, .start = NULL, .stop = NULL, .stats = loopback_stats, .stats_reset = loopback_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = loopback_recv, .send = loopback_send, .mtu_get = loopback_mtu_get, @@ -271,9 +275,20 @@ const pktio_if_ops_t loopback_pktio_ops = { .mac_get = loopback_mac_addr_get, .link_status = loopback_link_status, .capability = loopback_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = NULL, .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(loopback_pktio_ops) +{ + odp_module_constructor(&loopback_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &loopback_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_loopback_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index 928bb00af..c75f8be97 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -943,31 +943,46 @@ static int netmap_init_global(void) return 0; } -const pktio_if_ops_t netmap_pktio_ops = { - .name = "netmap", - .print = netmap_print, - .init_global = netmap_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t netmap_pktio_ops = { + .base = { + .name = "netmap", + .init_local = NULL, + .term_local = NULL, + .init_global = netmap_init_global, + .term_global = NULL, + }, .open = netmap_open, .close = netmap_close, .start = netmap_start, .stop = netmap_stop, - .link_status = netmap_link_status, .stats = netmap_stats, .stats_reset = netmap_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, + .recv = netmap_recv, + .send = netmap_send, .mtu_get = netmap_mtu_get, .promisc_mode_set = netmap_promisc_mode_set, .promisc_mode_get = netmap_promisc_mode_get, .mac_get = netmap_mac_addr_get, + .link_status = netmap_link_status, .capability = netmap_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = netmap_input_queues_config, .output_queues_config = netmap_output_queues_config, - .recv = netmap_recv, - .send = netmap_send + .print = netmap_print, }; +ODP_MODULE_CONSTRUCTOR(netmap_pktio_ops) +{ + odp_module_constructor(&netmap_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &netmap_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_netmap_pktio_ops = 0; + #endif /* ODP_NETMAP */ diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index a467b6402..98f810898 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -423,25 +423,44 @@ static int pcapif_init_global(void) return 0; } -const pktio_if_ops_t pcap_pktio_ops = { - .name = "pcap", - .print = NULL, - .init_global = pcapif_init_global, - .init_local = NULL, +static pktio_ops_module_t pcap_pktio_ops = { + .base = { + .name = "pcap", + .init_local = NULL, + .term_local = NULL, + .init_global = pcapif_init_global, + .term_global = NULL, + }, .open = pcapif_init, .close = pcapif_close, + .start = NULL, + .stop = NULL, .stats = pcapif_stats, .stats_reset = pcapif_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = pcapif_recv_pkt, .send = pcapif_send_pkt, .mtu_get = pcapif_mtu_get, .promisc_mode_set = pcapif_promisc_mode_set, .promisc_mode_get = pcapif_promisc_mode_get, .mac_get = pcapif_mac_addr_get, + .link_status = NULL, .capability = pcapif_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = NULL, .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(pcap_pktio_ops) +{ + odp_module_constructor(&pcap_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &pcap_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_pcap_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index a383adc6a..8b8ccf033 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -853,18 +853,22 @@ static int sock_init_global(void) return 0; } -const pktio_if_ops_t sock_mmsg_pktio_ops = { - .name = "socket", - .print = NULL, - .init_global = sock_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t socket_pktio_ops = { + .base = { + .name = "socket", + .init_local = NULL, + .term_local = NULL, + .init_global = sock_init_global, + .term_global = NULL, + }, .open = sock_mmsg_open, .close = sock_close, .start = NULL, .stop = NULL, .stats = sock_stats, .stats_reset = sock_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = sock_mmsg_recv, .send = sock_mmsg_send, .mtu_get = sock_mtu_get, @@ -873,9 +877,20 @@ const pktio_if_ops_t sock_mmsg_pktio_ops = { .mac_get = sock_mac_addr_get, .link_status = sock_link_status, .capability = sock_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = NULL, .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(socket_pktio_ops) +{ + odp_module_constructor(&socket_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &socket_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_socket_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 6fc4b4ccf..0a27316f2 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -710,18 +710,22 @@ static int sock_mmap_init_global(void) return 0; } -const pktio_if_ops_t sock_mmap_pktio_ops = { - .name = "socket_mmap", - .print = NULL, - .init_global = sock_mmap_init_global, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t socket_mmap_pktio_ops = { + .base = { + .name = "socket mmap", + .init_local = NULL, + .term_local = NULL, + .init_global = sock_mmap_init_global, + .term_global = NULL, + }, .open = sock_mmap_open, .close = sock_mmap_close, .start = NULL, .stop = NULL, .stats = sock_mmap_stats, .stats_reset = sock_mmap_stats_reset, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = sock_mmap_recv, .send = sock_mmap_send, .mtu_get = sock_mmap_mtu_get, @@ -730,9 +734,20 @@ const pktio_if_ops_t sock_mmap_pktio_ops = { .mac_get = sock_mmap_mac_addr_get, .link_status = sock_mmap_link_status, .capability = sock_mmap_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, .config = NULL, .input_queues_config = NULL, .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(socket_mmap_pktio_ops) +{ + odp_module_constructor(&socket_mmap_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &socket_mmap_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_socket_mmap_pktio_ops = 0; diff --git a/platform/linux-generic/pktio/subsystem.c b/platform/linux-generic/pktio/subsystem.c new file mode 100644 index 000000000..fbcf22d77 --- /dev/null +++ b/platform/linux-generic/pktio/subsystem.c @@ -0,0 +1,58 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +#define SUBSYSTEM_VERSION 0x00010000UL +ODP_SUBSYSTEM_DEFINE(pktio_ops, "packet IO operations", SUBSYSTEM_VERSION); + +/* Instantiate init and term functions */ +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_global, ODP_ERR) +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, init_local, ODP_ERR) +ODP_SUBSYSTEM_FOREACH_TEMPLATE(pktio_ops, term_global, ODP_ABORT) + +/* Temporary variable to enable link modules, + * will remove in Makefile scheme changes. + */ +#ifdef ODP_PKTIO_DPDK +extern int enable_link_dpdk_pktio_ops; +#endif +extern int enable_link_ipc_pktio_ops; +extern int enable_link_loopback_pktio_ops; +#ifdef ODP_NETMAP +extern int enable_link_netmap_pktio_ops; +#endif +#ifdef HAVE_PCAP +extern int enable_link_pcap_pktio_ops; +#endif +extern int enable_link_socket_pktio_ops; +extern int enable_link_socket_mmap_pktio_ops; +extern int enable_link_tap_pktio_ops; + +ODP_SUBSYSTEM_CONSTRUCTOR(pktio_ops) +{ + odp_subsystem_constructor(pktio_ops); + + /* Further initialization per subsystem */ + +#ifdef ODP_PKTIO_DPDK + enable_link_dpdk_pktio_ops = 1; +#endif + enable_link_ipc_pktio_ops = 1; + enable_link_loopback_pktio_ops = 1; +#ifdef ODP_NETMAP + enable_link_netmap_pktio_ops = 1; +#endif +#ifdef HAVE_PCAP + enable_link_pcap_pktio_ops = 1; +#endif + enable_link_socket_pktio_ops = 1; + enable_link_socket_mmap_pktio_ops = 1; + enable_link_tap_pktio_ops = 1; +} diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index 650c12a77..bfe412390 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -373,24 +373,44 @@ static int tap_capability(pktio_entry_t *pktio_entry ODP_UNUSED, return 0; } -const pktio_if_ops_t tap_pktio_ops = { - .name = "tap", - .print = NULL, - .init_global = NULL, - .init_local = NULL, - .term = NULL, +static pktio_ops_module_t tap_pktio_ops = { + .base = { + .name = "tap", + .init_local = NULL, + .term_local = NULL, + .init_global = NULL, + .term_global = NULL, + }, .open = tap_pktio_open, .close = tap_pktio_close, .start = NULL, .stop = NULL, + .stats = NULL, + .stats_reset = NULL, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, .recv = tap_pktio_recv, .send = tap_pktio_send, .mtu_get = tap_mtu_get, .promisc_mode_set = tap_promisc_mode_set, .promisc_mode_get = tap_promisc_mode_get, .mac_get = tap_mac_addr_get, + .link_status = NULL, .capability = tap_capability, - .pktin_ts_res = NULL, - .pktin_ts_from_ns = NULL, - .config = NULL + .config = NULL, + .input_queues_config = NULL, + .output_queues_config = NULL, + .print = NULL, }; + +ODP_MODULE_CONSTRUCTOR(tap_pktio_ops) +{ + odp_module_constructor(&tap_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &tap_pktio_ops); +} + +/* Temporary variable to enable link this module, + * will remove in Makefile scheme changes. + */ +int enable_link_tap_pktio_ops = 0; From patchwork Tue Sep 19 03:00:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112965 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4398435qgf; Mon, 18 Sep 2017 20:03:13 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDIDdKyOKzFVb3D4yYFqt3lj2gJuJqZuiaRqavPaR7AxQwLiQo34QQI10d4qB2AAIxj5cGX X-Received: by 10.55.165.202 with SMTP id o193mr1912198qke.291.1505790193874; Mon, 18 Sep 2017 20:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790193; cv=none; d=google.com; s=arc-20160816; b=Etwt/tI61Kq+JCPu7GDtsV0Ea2bcohQIWZE+pMW2GLMyf7GU4UJRAvpbehZAUIcnuK HB4keo72Sn9hapKz7OGwc44SEPkiteCGpLH3ubhlE98297Zz+msQcC476eKKtN8IlLy4 G5G7ZOAixoTm+J6CpMwlAM3qBIJgT7bEPDlljxTiP+ThVwp5WoMKI0n+RiiPi4TCDGMT sdRKt7bcgqJj/4fxCoi7ohOnWauPgSYPjQfCzX4z8H90GVP7PGXZqBCyeP0ds5egUYdG AVSLHddjFF+L7nQ7C+vnxWn/sofwXhgYrU8+YRSDke9WUBGvPUqC+lA1T/4CF5pXxxaG 0cLQ== 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=iRXZgq2XYOSyLsCLj8s6xhpjXyAOsTfR/fzhADxwkAc=; b=saSmBjf9C6cfFXXcJKP5/plKx8zBYz+WybjlCesmCPkCdSP3+/Y8z/+cCg7ISuOFXw VD+ZwY4NIjrSlXM6UZiLVhT8nOq+SU5RZOun1+TVPdpcGJB+ir7A3elh8SZ3T1XppxG9 f9bmqkaPILaiVwdcUadzXkX8M8eMNsqwTMRf3RFINvNyswBKGvJtAPLag2u+Lt5Mudl+ tLOt+cx8JsJ/CVQAXfUSH06j//SUKH3LqUr6BEzMk39kX+kR6SMh/u0nmnqt2f67kNeG A4lIsvEyP47cdySVtLNPgw4w9F8rJ2GTrjVO8szsNSe3aMk3PkgTZEcqTY3FxX+zfzkT 714Q== 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 t186si7895594qkh.178.2017.09.18.20.03.13; Mon, 18 Sep 2017 20:03:13 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 9020E62D29; Tue, 19 Sep 2017 03:03:13 +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 6811D62AE7; Tue, 19 Sep 2017 03:00:55 +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 E5D9761E64; Tue, 19 Sep 2017 03:00:42 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id 70DC160F42 for ; Tue, 19 Sep 2017 03:00:37 +0000 (UTC) Received: from mxback10g.mail.yandex.net (mxback10g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:171]) by forward102j.mail.yandex.net (Yandex) with ESMTP id 3540A5602429 for ; Tue, 19 Sep 2017 06:00:36 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback10g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id xcbBhHW3L3-0Zai8jjC; Tue, 19 Sep 2017 06:00:36 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0YRiR0HV; Tue, 19 Sep 2017 06:00:34 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 19 Sep 2017 06:00:18 +0300 Message-Id: <1505790024-16070-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 4/10] linux-gen: pktio: loopback: minor code refactory X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Rename the source as loopback.c, move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ platform/linux-dpdk/Makefile.am | 3 ++- platform/linux-dpdk/include/odp_packet_io_internal.h | 7 +------ platform/linux-generic/Makefile.am | 3 ++- platform/linux-generic/include/odp_packet_io_internal.h | 7 +------ platform/linux-generic/include/odp_pktio_ops_loopback.h | 17 +++++++++++++++++ .../linux-generic/include/odp_pktio_ops_subsystem.h | 13 +++++++++++++ platform/linux-generic/pktio/{loop.c => loopback.c} | 14 +++++++------- 7 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 platform/linux-generic/include/odp_pktio_ops_loopback.h rename platform/linux-generic/pktio/{loop.c => loopback.c} (94%) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 83931d27a..4d5dff5d1 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -190,6 +190,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_loopback.h \ ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ @@ -246,7 +247,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ pktio/subsystem.c \ odp_packet_flags.c \ ../linux-generic/odp_packet_io.c \ - ../linux-generic/pktio/loop.c \ + ../linux-generic/pktio/loopback.c \ ../linux-generic/odp_pkt_queue.c \ pool/dpdk.c \ ../linux-generic/odp_queue.c \ diff --git a/platform/linux-dpdk/include/odp_packet_io_internal.h b/platform/linux-dpdk/include/odp_packet_io_internal.h index fde172fc5..ba388c9c2 100644 --- a/platform/linux-dpdk/include/odp_packet_io_internal.h +++ b/platform/linux-dpdk/include/odp_packet_io_internal.h @@ -43,11 +43,6 @@ typedef union pktio_entry_u pktio_entry_t; /* Forward declaration */ struct pkt_dpdk_t; -typedef struct { - odp_queue_t loopq; /**< loopback queue for "loop" device */ - odp_bool_t promisc; /**< promiscuous mode state */ -} pkt_loop_t; - /** Packet socket using dpdk mmaped rings for both Rx and Tx */ typedef struct { odp_pktio_capability_t capa; /**< interface capabilities */ @@ -67,13 +62,13 @@ typedef struct { struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ + pktio_ops_data_t ops_data; /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ union { - pkt_loop_t pkt_loop; /**< Using loopback for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK API for IO */ }; enum { diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index ff08a6ef4..1aaea84f7 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -191,6 +191,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ + ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ @@ -266,7 +267,7 @@ __LIB__libodp_linux_la_SOURCES = \ pktio/subsystem.c \ pktio/ipc.c \ pktio/pktio_common.c \ - pktio/loop.c \ + pktio/loopback.c \ pktio/netmap.c \ pktio/dpdk.c \ pktio/socket.c \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 589148400..893fa1144 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -51,11 +51,6 @@ typedef union pktio_entry_u pktio_entry_t; * requested number of packets were not handled. */ #define SOCK_ERR_REPORT(e) (e != EAGAIN && e != EWOULDBLOCK && e != EINTR) -typedef struct { - odp_queue_t loopq; /**< loopback queue for "loop" device */ - odp_bool_t promisc; /**< promiscuous mode state */ -} pkt_loop_t; - #ifdef HAVE_PCAP typedef struct { char *fname_rx; /**< name of pcap file for rx */ @@ -111,13 +106,13 @@ typedef struct { struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ + pktio_ops_data_t ops_data; /**< IO operation specific data */ /* These two locks together lock the whole pktio device */ odp_ticketlock_t rxl; /**< RX ticketlock */ odp_ticketlock_t txl; /**< TX ticketlock */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ union { - pkt_loop_t pkt_loop; /**< Using loopback for IO */ pkt_sock_t pkt_sock; /**< using socket API for IO */ pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap * API for IO */ diff --git a/platform/linux-generic/include/odp_pktio_ops_loopback.h b/platform/linux-generic/include/odp_pktio_ops_loopback.h new file mode 100644 index 000000000..932459472 --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_loopback.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_LOOPBACK_H_ +#define ODP_PKTIO_OPS_LOOPBACK_H_ + +typedef struct { + odp_queue_t loopq; /**< loopback queue for "loop" device */ + odp_bool_t promisc; /**< promiscuous mode state */ +} pktio_ops_loopback_data_t; + +#endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index ff497a2ac..7b90ed3d3 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -78,4 +78,17 @@ typedef ODP_MODULE_CLASS(pktio_ops) { odp_api_proto(pktio_ops, print) print; } pktio_ops_module_t; +/* All implementations of this subsystem */ +#include + +/* Per implementation private data + * TODO: refactory each implementation to hide it internally + */ +typedef union { + pktio_ops_loopback_data_t loopback; +} pktio_ops_data_t; + +/* Extract pktio ops data from pktio entry structure */ +#define ops_data(mod) s.ops_data.mod + #endif diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loopback.c similarity index 94% rename from platform/linux-generic/pktio/loop.c rename to platform/linux-generic/pktio/loopback.c index 39718a892..0c572338f 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loopback.c @@ -35,10 +35,10 @@ static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, snprintf(loopq_name, sizeof(loopq_name), "%" PRIu64 "-pktio_loopq", odp_pktio_to_u64(id)); - pktio_entry->s.pkt_loop.loopq = + pktio_entry->ops_data(loopback).loopq = odp_queue_create(loopq_name, NULL); - if (pktio_entry->s.pkt_loop.loopq == ODP_QUEUE_INVALID) + if (pktio_entry->ops_data(loopback).loopq == ODP_QUEUE_INVALID) return -1; loopback_stats_reset(pktio_entry); @@ -48,7 +48,7 @@ static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, static int loopback_close(pktio_entry_t *pktio_entry) { - return odp_queue_destroy(pktio_entry->s.pkt_loop.loopq); + return odp_queue_destroy(pktio_entry->ops_data(loopback).loopq); } static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, @@ -70,7 +70,7 @@ static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_ticketlock_lock(&pktio_entry->s.rxl); - queue = queue_fn->from_ext(pktio_entry->s.pkt_loop.loopq); + queue = queue_fn->from_ext(pktio_entry->ops_data(loopback).loopq); nbr = queue_fn->deq_multi(queue, hdr_tbl, len); if (pktio_entry->s.config.pktin.bit.ts_all || @@ -170,7 +170,7 @@ static int loopback_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_ticketlock_lock(&pktio_entry->s.txl); - queue = queue_fn->from_ext(pktio_entry->s.pkt_loop.loopq); + queue = queue_fn->from_ext(pktio_entry->ops_data(loopback).loopq); ret = queue_fn->enq_multi(queue, hdr_tbl, len); if (ret > 0) { @@ -223,13 +223,13 @@ static int loopback_capability(pktio_entry_t *pktio_entry ODP_UNUSED, static int loopback_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - pktio_entry->s.pkt_loop.promisc = enable; + pktio_entry->ops_data(loopback).promisc = enable; return 0; } static int loopback_promisc_mode_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_loop.promisc ? 1 : 0; + return pktio_entry->ops_data(loopback).promisc ? 1 : 0; } static int loopback_stats(pktio_entry_t *pktio_entry, From patchwork Tue Sep 19 03:00:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112968 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4402261qgf; Mon, 18 Sep 2017 20:08:33 -0700 (PDT) X-Google-Smtp-Source: AOwi7QB8tVlwH2SRytxE7gA7FCZrq3FDRXvzOMJ/cGtsY2qxiP+l8pLzn/SsrYjk4DUJr1wMuaqo X-Received: by 10.36.182.5 with SMTP id g5mr315874itf.35.1505790513754; Mon, 18 Sep 2017 20:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790513; cv=none; d=google.com; s=arc-20160816; b=BnzPQYcpiqk/sYKlzD8JD6EnoZSEWL3m2kcRnU6WtNmuiSYvx8j/Xs/f8gUUOE5Jk1 kIjdM4EQIHCol5oUrD24W9GF8cQweJwMcULFg1RXAsy2gMTS8jMybvnMOieH+RkIJkY1 Tlr6e/IGbXH+ut6fxdX0FDWxS4+qhiNdXzJ1QhSl+CpyGU8Idc705lAE6QUr/5oCHDjw WUAO8AVhAhF14+mgeUw2vI2c8/iIn5xXk+RMNnPQg/QedsB4lqIhTw1sN3V8RjNj/eN/ zlyrRRLAoXPAkFWkVU3wLfzRlMhf5/z3neUzzJL0/b7E1GVePydMHPrW5gHMiFLqmuXc jo1A== 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=deMQlLYM04R8FygWqPezkYcZkTw7K6AFsZMNlmK7Xnw=; b=ak4StP/WO16I7z0EJi9y8Z2Q9FPuhkIr9jDBoQRvVeIvui/U8JHgZLTsWPuwtQKU7I yHuojqR2nh1MIBMaUwSFnnSKOf+1xDugsoWBYF0XPKwT9b50vlalmVzuefC62u5ZALKq 2tt96qgRXGwKF9kqyXsH/P37lSkfIFwuj4CCe22lmAZYJvU80Y/TmPMZe8dUVApVgfpY PjqlpgSYn327wJmWBUrGdJzn54q/+PTFyWBo+efkz6lX1jIbeQpjmr/7UTpfXmPsKBu5 SQgFZRuuQY9h3bROnzobwypq8o1w79tvYEKei+wkj2lEdsVwg6qZPbIWP0dQbASvrV0t mBfg== 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 o82si6972566ioi.26.2017.09.18.20.08.33; Mon, 18 Sep 2017 20:08:33 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 1DF38635D3; Tue, 19 Sep 2017 03:08:33 +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 9928160F34; Tue, 19 Sep 2017 03:01:26 +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 3BEC162AE6; Tue, 19 Sep 2017 03:00:50 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id 66D6A60EA6 for ; Tue, 19 Sep 2017 03:00:38 +0000 (UTC) Received: from mxback6j.mail.yandex.net (mxback6j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10f]) by forward106o.mail.yandex.net (Yandex) with ESMTP id 1F99A7847B3 for ; Tue, 19 Sep 2017 06:00:37 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback6j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 060CE7yt95-0bx0DQg8; Tue, 19 Sep 2017 06:00:37 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0aR8QsqK; Tue, 19 Sep 2017 06:00:36 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 19 Sep 2017 06:00:19 +0300 Message-Id: <1505790024-16070-6-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 5/10] linux-gen: pktio: ipc: minor code refactory X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ platform/linux-dpdk/Makefile.am | 2 +- platform/linux-generic/Makefile.am | 2 +- .../linux-generic/include/odp_packet_io_internal.h | 39 ----- .../include/odp_packet_io_ipc_internal.h | 48 ------ platform/linux-generic/include/odp_pktio_ops_ipc.h | 91 ++++++++++ .../include/odp_pktio_ops_subsystem.h | 2 + platform/linux-generic/odp_packet_io.c | 1 - platform/linux-generic/pktio/ipc.c | 185 +++++++++++---------- 8 files changed, 190 insertions(+), 180 deletions(-) delete mode 100644 platform/linux-generic/include/odp_packet_io_ipc_internal.h create mode 100644 platform/linux-generic/include/odp_pktio_ops_ipc.h diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 4d5dff5d1..9ebf2ea14 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -189,12 +189,12 @@ noinst_HEADERS = \ ${top_srcdir}/platform/linux-generic/include/odp_internal.h \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_internal.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_ipc.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_loopback.h \ ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ - ${top_srcdir}/platform/linux-generic/include/odp_packet_io_ipc_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_packet_io_ring_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_packet_socket.h \ ${top_srcdir}/platform/linux-generic/include/odp_pkt_queue_internal.h \ diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 1aaea84f7..dd8767b2f 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -185,12 +185,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ - ${srcdir}/include/odp_packet_io_ipc_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ ${srcdir}/include/odp_packet_netmap.h \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ + ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 893fa1144..8d3c3ddff 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -66,44 +66,6 @@ typedef struct { } pkt_pcap_t; #endif -typedef struct { - /* TX */ - struct { - _ring_t *send; /**< ODP ring for IPC msg packets - indexes transmitted to shared - memory */ - _ring_t *free; /**< ODP ring for IPC msg packets - indexes already processed by remote - process */ - } tx; - /* RX */ - struct { - _ring_t *recv; /**< ODP ring for IPC msg packets - indexes received from shared - memory (from remote process) */ - _ring_t *free; /**< odp ring for ipc msg packets - indexes already processed by - current process */ - _ring_t *cache; /**< local cache to keep packet order right */ - } rx; /* slave */ - void *pool_base; /**< Remote pool base addr */ - void *pool_mdata_base; /**< Remote pool mdata base addr */ - uint64_t pkt_size; /**< Packet size in remote pool */ - odp_pool_t pool; /**< Pool of main process */ - enum { - PKTIO_TYPE_IPC_MASTER = 0, /**< Master is the process which - creates shm */ - PKTIO_TYPE_IPC_SLAVE /**< Slave is the process which - connects to shm */ - } type; /**< define if it's master or slave process */ - odp_atomic_u32_t ready; /**< 1 - pktio is ready and can recv/send - packet, 0 - not yet ready */ - void *pinfo; - odp_shm_t pinfo_shm; - odp_shm_t remote_pool_shm; /**< shm of remote pool get with - _ipc_map_remote_pool() */ -} _ipc_pktio_t; - struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ pktio_ops_data_t ops_data; /**< IO operation specific data */ @@ -122,7 +84,6 @@ struct pktio_entry { pkt_pcap_t pkt_pcap; /**< Using pcap for IO */ #endif pkt_tap_t pkt_tap; /**< using TAP for IO */ - _ipc_pktio_t ipc; /**< IPC pktio data */ }; enum { /* Not allocated */ diff --git a/platform/linux-generic/include/odp_packet_io_ipc_internal.h b/platform/linux-generic/include/odp_packet_io_ipc_internal.h deleted file mode 100644 index 9d8943a6c..000000000 --- a/platform/linux-generic/include/odp_packet_io_ipc_internal.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (c) 2015, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -/* IPC packet I/O over shared memory ring */ -#include - -/* number of odp buffers in odp ring queue */ -#define PKTIO_IPC_ENTRIES 4096 - -/* that struct is exported to shared memory, so that processes can find - * each other. - */ -struct pktio_info { - struct { - /* number of buffer*/ - int num; - /* size of packet/segment in remote pool */ - uint32_t block_size; - char pool_name[ODP_POOL_NAME_LEN]; - /* 1 if master finished creation of all shared objects */ - int init_done; - } master; - struct { - void *base_addr; - uint32_t block_size; - char pool_name[ODP_POOL_NAME_LEN]; - /* pid of the slave process written to shm and - * used by master to look up memory created by - * slave - */ - int pid; - int init_done; - } slave; -} ODP_PACKED; diff --git a/platform/linux-generic/include/odp_pktio_ops_ipc.h b/platform/linux-generic/include/odp_pktio_ops_ipc.h new file mode 100644 index 000000000..5903ef9b8 --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_ipc.h @@ -0,0 +1,91 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_IPC_H_ +#define ODP_PKTIO_OPS_IPC_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +/* IPC packet I/O over shared memory ring */ +#include + +/* number of odp buffers in odp ring queue */ +#define PKTIO_IPC_ENTRIES 4096 + +/* that struct is exported to shared memory, so that processes can find + * each other. + */ +struct pktio_info { + struct { + /* number of buffer*/ + int num; + /* size of packet/segment in remote pool */ + uint32_t block_size; + char pool_name[ODP_POOL_NAME_LEN]; + /* 1 if master finished creation of all shared objects */ + int init_done; + } master; + struct { + void *base_addr; + uint32_t block_size; + char pool_name[ODP_POOL_NAME_LEN]; + /* pid of the slave process written to shm and + * used by master to look up memory created by + * slave + */ + int pid; + int init_done; + } slave; +} ODP_PACKED; + +typedef struct { + /* TX */ + struct { + _ring_t *send; /**< ODP ring for IPC msg packets + indexes transmitted to shared + memory */ + _ring_t *free; /**< ODP ring for IPC msg packets + indexes already processed by remote + process */ + } tx; + /* RX */ + struct { + _ring_t *recv; /**< ODP ring for IPC msg packets + indexes received from shared + memory (from remote process) */ + _ring_t *free; /**< odp ring for ipc msg packets + indexes already processed by + current process */ + _ring_t *cache; /**< local cache to keep packet order right */ + } rx; /* slave */ + void *pool_base; /**< Remote pool base addr */ + void *pool_mdata_base; /**< Remote pool mdata base addr */ + uint64_t pkt_size; /**< Packet size in remote pool */ + odp_pool_t pool; /**< Pool of main process */ + enum { + PKTIO_TYPE_IPC_MASTER = 0, /**< Master is the process which + creates shm */ + PKTIO_TYPE_IPC_SLAVE /**< Slave is the process which + connects to shm */ + } type; /**< define if it's master or slave process */ + odp_atomic_u32_t ready; /**< 1 - pktio is ready and can recv/send + packet, 0 - not yet ready */ + void *pinfo; + odp_shm_t pinfo_shm; + odp_shm_t remote_pool_shm; /**< shm of remote pool get with + _ipc_map_remote_pool() */ +} pktio_ops_ipc_data_t; + +#endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 7b90ed3d3..650b36648 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -79,12 +79,14 @@ typedef ODP_MODULE_CLASS(pktio_ops) { } pktio_ops_module_t; /* All implementations of this subsystem */ +#include #include /* Per implementation private data * TODO: refactory each implementation to hide it internally */ typedef union { + pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; } pktio_ops_data_t; diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index d8dcc45da..6a19394a5 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index 984f0ab44..14cd86eb7 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -3,7 +3,6 @@ * * SPDX-License-Identifier: BSD-3-Clause */ -#include #include #include #include @@ -43,7 +42,7 @@ static const char *_ipc_odp_buffer_pool_shm_name(odp_pool_t pool_hdl) static int _ipc_master_start(pktio_entry_t *pktio_entry) { - struct pktio_info *pinfo = pktio_entry->s.ipc.pinfo; + struct pktio_info *pinfo = pktio_entry->ops_data(ipc).pinfo; odp_shm_t shm; if (pinfo->slave.init_done == 0) @@ -57,11 +56,11 @@ static int _ipc_master_start(pktio_entry_t *pktio_entry) return -1; } - pktio_entry->s.ipc.remote_pool_shm = shm; - pktio_entry->s.ipc.pool_base = odp_shm_addr(shm); - pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm); + pktio_entry->ops_data(ipc).remote_pool_shm = shm; + pktio_entry->ops_data(ipc).pool_base = odp_shm_addr(shm); + pktio_entry->ops_data(ipc).pool_mdata_base = (char *)odp_shm_addr(shm); - odp_atomic_store_u32(&pktio_entry->s.ipc.ready, 1); + odp_atomic_store_u32(&pktio_entry->ops_data(ipc).ready, 1); IPC_ODP_DBG("%s started.\n", pktio_entry->s.name); return 0; @@ -88,62 +87,62 @@ static int _ipc_init_master(pktio_entry_t *pktio_entry, * to be processed packets ring. */ snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_prod", dev); - pktio_entry->s.ipc.tx.send = _ring_create(ipc_shm_name, + pktio_entry->ops_data(ipc).tx.send = _ring_create(ipc_shm_name, PKTIO_IPC_ENTRIES, _RING_SHM_PROC | _RING_NO_LIST); - if (!pktio_entry->s.ipc.tx.send) { + if (!pktio_entry->ops_data(ipc).tx.send) { ODP_ERR("pid %d unable to create ipc ring %s name\n", getpid(), ipc_shm_name); return -1; } ODP_DBG("Created IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.tx.send), - _ring_free_count(pktio_entry->s.ipc.tx.send)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).tx.send), + _ring_free_count(pktio_entry->ops_data(ipc).tx.send)); /* generate name in shm like ipc_pktio_p for * already processed packets */ snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_cons", dev); - pktio_entry->s.ipc.tx.free = _ring_create(ipc_shm_name, + pktio_entry->ops_data(ipc).tx.free = _ring_create(ipc_shm_name, PKTIO_IPC_ENTRIES, _RING_SHM_PROC | _RING_NO_LIST); - if (!pktio_entry->s.ipc.tx.free) { + if (!pktio_entry->ops_data(ipc).tx.free) { ODP_ERR("pid %d unable to create ipc ring %s name\n", getpid(), ipc_shm_name); goto free_m_prod; } ODP_DBG("Created IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.tx.free), - _ring_free_count(pktio_entry->s.ipc.tx.free)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).tx.free), + _ring_free_count(pktio_entry->ops_data(ipc).tx.free)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_prod", dev); - pktio_entry->s.ipc.rx.recv = _ring_create(ipc_shm_name, + pktio_entry->ops_data(ipc).rx.recv = _ring_create(ipc_shm_name, PKTIO_IPC_ENTRIES, _RING_SHM_PROC | _RING_NO_LIST); - if (!pktio_entry->s.ipc.rx.recv) { + if (!pktio_entry->ops_data(ipc).rx.recv) { ODP_ERR("pid %d unable to create ipc ring %s name\n", getpid(), ipc_shm_name); goto free_m_cons; } ODP_DBG("Created IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.rx.recv), - _ring_free_count(pktio_entry->s.ipc.rx.recv)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).rx.recv), + _ring_free_count(pktio_entry->ops_data(ipc).rx.recv)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", dev); - pktio_entry->s.ipc.rx.free = _ring_create(ipc_shm_name, + pktio_entry->ops_data(ipc).rx.free = _ring_create(ipc_shm_name, PKTIO_IPC_ENTRIES, _RING_SHM_PROC | _RING_NO_LIST); - if (!pktio_entry->s.ipc.rx.free) { + if (!pktio_entry->ops_data(ipc).rx.free) { ODP_ERR("pid %d unable to create ipc ring %s name\n", getpid(), ipc_shm_name); goto free_s_prod; } ODP_DBG("Created IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.rx.free), - _ring_free_count(pktio_entry->s.ipc.rx.free)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).rx.free), + _ring_free_count(pktio_entry->ops_data(ipc).rx.free)); /* Set up pool name for remote info */ - pinfo = pktio_entry->s.ipc.pinfo; + pinfo = pktio_entry->ops_data(ipc).pinfo; pool_name = _ipc_odp_buffer_pool_shm_name(pool_hdl); if (strlen(pool_name) > ODP_POOL_NAME_LEN) { ODP_ERR("pid %d ipc pool name %s is too big %d\n", @@ -156,7 +155,7 @@ static int _ipc_init_master(pktio_entry_t *pktio_entry, pinfo->slave.pid = 0; pinfo->slave.init_done = 0; - pktio_entry->s.ipc.pool = pool_hdl; + pktio_entry->ops_data(ipc).pool = pool_hdl; ODP_DBG("Pre init... DONE.\n"); pinfo->master.init_done = 1; @@ -225,7 +224,7 @@ static int _ipc_init_slave(const char *dev, if (strlen(dev) > (ODP_POOL_NAME_LEN - sizeof("_slave_r"))) ODP_ABORT("too big ipc name\n"); - pktio_entry->s.ipc.pool = pool; + pktio_entry->ops_data(ipc).pool = pool; return 0; } @@ -246,61 +245,61 @@ static int _ipc_slave_start(pktio_entry_t *pktio_entry) sprintf(dev, "ipc:%s", tail); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_prod", dev); - pktio_entry->s.ipc.rx.recv = _ipc_shm_map(ipc_shm_name, pid); - if (!pktio_entry->s.ipc.rx.recv) { + pktio_entry->ops_data(ipc).rx.recv = _ipc_shm_map(ipc_shm_name, pid); + if (!pktio_entry->ops_data(ipc).rx.recv) { ODP_DBG("pid %d unable to find ipc ring %s name\n", getpid(), dev); sleep(1); return -1; } ODP_DBG("Connected IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.rx.recv), - _ring_free_count(pktio_entry->s.ipc.rx.recv)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).rx.recv), + _ring_free_count(pktio_entry->ops_data(ipc).rx.recv)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_m_cons", dev); - pktio_entry->s.ipc.rx.free = _ipc_shm_map(ipc_shm_name, pid); - if (!pktio_entry->s.ipc.rx.free) { + pktio_entry->ops_data(ipc).rx.free = _ipc_shm_map(ipc_shm_name, pid); + if (!pktio_entry->ops_data(ipc).rx.free) { ODP_ERR("pid %d unable to find ipc ring %s name\n", getpid(), dev); goto free_m_prod; } ODP_DBG("Connected IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.rx.free), - _ring_free_count(pktio_entry->s.ipc.rx.free)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).rx.free), + _ring_free_count(pktio_entry->ops_data(ipc).rx.free)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_prod", dev); - pktio_entry->s.ipc.tx.send = _ipc_shm_map(ipc_shm_name, pid); - if (!pktio_entry->s.ipc.tx.send) { + pktio_entry->ops_data(ipc).tx.send = _ipc_shm_map(ipc_shm_name, pid); + if (!pktio_entry->ops_data(ipc).tx.send) { ODP_ERR("pid %d unable to find ipc ring %s name\n", getpid(), dev); goto free_m_cons; } ODP_DBG("Connected IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.tx.send), - _ring_free_count(pktio_entry->s.ipc.tx.send)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).tx.send), + _ring_free_count(pktio_entry->ops_data(ipc).tx.send)); snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", dev); - pktio_entry->s.ipc.tx.free = _ipc_shm_map(ipc_shm_name, pid); - if (!pktio_entry->s.ipc.tx.free) { + pktio_entry->ops_data(ipc).tx.free = _ipc_shm_map(ipc_shm_name, pid); + if (!pktio_entry->ops_data(ipc).tx.free) { ODP_ERR("pid %d unable to find ipc ring %s name\n", getpid(), dev); goto free_s_prod; } ODP_DBG("Connected IPC ring: %s, count %d, free %d\n", - ipc_shm_name, _ring_count(pktio_entry->s.ipc.tx.free), - _ring_free_count(pktio_entry->s.ipc.tx.free)); + ipc_shm_name, _ring_count(pktio_entry->ops_data(ipc).tx.free), + _ring_free_count(pktio_entry->ops_data(ipc).tx.free)); /* Get info about remote pool */ - pinfo = pktio_entry->s.ipc.pinfo; + pinfo = pktio_entry->ops_data(ipc).pinfo; shm = _ipc_map_remote_pool(pinfo->master.pool_name, pid); - pktio_entry->s.ipc.remote_pool_shm = shm; - pktio_entry->s.ipc.pool_mdata_base = (char *)odp_shm_addr(shm); - pktio_entry->s.ipc.pkt_size = pinfo->master.block_size; + pktio_entry->ops_data(ipc).remote_pool_shm = shm; + pktio_entry->ops_data(ipc).pool_mdata_base = (char *)odp_shm_addr(shm); + pktio_entry->ops_data(ipc).pkt_size = pinfo->master.block_size; - _ipc_export_pool(pinfo, pktio_entry->s.ipc.pool); + _ipc_export_pool(pinfo, pktio_entry->ops_data(ipc).pool); - odp_atomic_store_u32(&pktio_entry->s.ipc.ready, 1); + odp_atomic_store_u32(&pktio_entry->ops_data(ipc).ready, 1); pinfo->slave.init_done = 1; ODP_DBG("%s started.\n", pktio_entry->s.name); @@ -339,15 +338,15 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, if (strncmp(dev, "ipc", 3)) return -1; - odp_atomic_init_u32(&pktio_entry->s.ipc.ready, 0); + odp_atomic_init_u32(&pktio_entry->ops_data(ipc).ready, 0); - pktio_entry->s.ipc.rx.cache = _ring_create("ipc_rx_cache", + pktio_entry->ops_data(ipc).rx.cache = _ring_create("ipc_rx_cache", PKTIO_IPC_ENTRIES, _RING_NO_LIST); /* Shared info about remote pktio */ if (sscanf(dev, "ipc:%d:%s", &pid, tail) == 2) { - pktio_entry->s.ipc.type = PKTIO_TYPE_IPC_SLAVE; + pktio_entry->ops_data(ipc).type = PKTIO_TYPE_IPC_SLAVE; snprintf(name, sizeof(name), "ipc:%s_info", tail); IPC_ODP_DBG("lookup for name %s for pid %d\n", name, pid); @@ -360,12 +359,12 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, odp_shm_free(shm); return -1; } - pktio_entry->s.ipc.pinfo = pinfo; - pktio_entry->s.ipc.pinfo_shm = shm; + pktio_entry->ops_data(ipc).pinfo = pinfo; + pktio_entry->ops_data(ipc).pinfo_shm = shm; ODP_DBG("process %d is slave\n", getpid()); ret = _ipc_init_slave(name, pktio_entry, pool); } else { - pktio_entry->s.ipc.type = PKTIO_TYPE_IPC_MASTER; + pktio_entry->ops_data(ipc).type = PKTIO_TYPE_IPC_MASTER; snprintf(name, sizeof(name), "%s_info", dev); shm = odp_shm_reserve(name, sizeof(struct pktio_info), ODP_CACHE_LINE_SIZE, @@ -378,8 +377,8 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, pinfo = odp_shm_addr(shm); pinfo->master.init_done = 0; pinfo->master.pool_name[0] = 0; - pktio_entry->s.ipc.pinfo = pinfo; - pktio_entry->s.ipc.pinfo_shm = shm; + pktio_entry->ops_data(ipc).pinfo = pinfo; + pktio_entry->ops_data(ipc).pinfo_shm = shm; ODP_DBG("process %d is master\n", getpid()); ret = _ipc_init_master(pktio_entry, dev, pool); } @@ -399,7 +398,7 @@ static void _ipc_free_ring_packets(pktio_entry_t *pktio_entry, _ring_t *r) if (!r) return; - pool = pool_entry_from_hdl(pktio_entry->s.ipc.pool); + pool = pool_entry_from_hdl(pktio_entry->ops_data(ipc).pool); addr = odp_shm_addr(pool->shm); rbuf_p = (void *)&offsets; @@ -433,16 +432,16 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, uint32_t ready; int pkts_ring; - ready = odp_atomic_load_u32(&pktio_entry->s.ipc.ready); + ready = odp_atomic_load_u32(&pktio_entry->ops_data(ipc).ready); if (odp_unlikely(!ready)) { IPC_ODP_DBG("start pktio is missing before usage?\n"); return 0; } - _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.free); + _ipc_free_ring_packets(pktio_entry, pktio_entry->ops_data(ipc).tx.free); /* rx from cache */ - r = pktio_entry->s.ipc.rx.cache; + r = pktio_entry->ops_data(ipc).rx.cache; pkts = _ring_mc_dequeue_burst(r, ipcbufs_p, len); if (odp_unlikely(pkts < 0)) ODP_ABORT("internal error dequeue\n"); @@ -450,7 +449,7 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, /* rx from other app */ if (pkts == 0) { ipcbufs_p = (void *)&offsets[0]; - r = pktio_entry->s.ipc.rx.recv; + r = pktio_entry->ops_data(ipc).rx.recv; pkts = _ring_mc_dequeue_burst(r, ipcbufs_p, len); if (odp_unlikely(pkts < 0)) ODP_ABORT("internal error dequeue\n"); @@ -468,10 +467,10 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, uint64_t data_pool_off; void *rmt_data_ptr; - phdr = (void *)((uint8_t *)pktio_entry->s.ipc.pool_mdata_base + - offsets[i]); + phdr = (void *)((uint8_t *)pktio_entry-> + ops_data(ipc).pool_mdata_base + offsets[i]); - pool = pktio_entry->s.ipc.pool; + pool = pktio_entry->ops_data(ipc).pool; if (odp_unlikely(pool == ODP_POOL_INVALID)) ODP_ABORT("invalid pool"); @@ -496,11 +495,11 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, if (odp_unlikely(!pkt_data)) ODP_ABORT("unable to map pkt_data ipc_slave %d\n", (PKTIO_TYPE_IPC_SLAVE == - pktio_entry->s.ipc.type)); + pktio_entry->ops_data(ipc).type)); /* Copy packet data from shared pool to local pool. */ - rmt_data_ptr = (uint8_t *)pktio_entry->s.ipc.pool_mdata_base + - data_pool_off; + rmt_data_ptr = (uint8_t *)pktio_entry-> + ops_data(ipc).pool_mdata_base + data_pool_off; memcpy(pkt_data, rmt_data_ptr, phdr->frame_len); /* Copy packets L2, L3 parsed offsets and size */ @@ -519,7 +518,7 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, /* put back to rx ring dequed but not processed packets*/ if (pkts != i) { ipcbufs_p = (void *)&offsets[i]; - r_p = pktio_entry->s.ipc.rx.cache; + r_p = pktio_entry->ops_data(ipc).rx.cache; pkts_ring = _ring_mp_enqueue_burst(r_p, ipcbufs_p, pkts - i); if (pkts_ring != (pkts - i)) @@ -534,7 +533,7 @@ static int ipc_pktio_recv_lockless(pktio_entry_t *pktio_entry, pkts = i; /* Now tell other process that we no longer need that buffers.*/ - r_p = pktio_entry->s.ipc.rx.free; + r_p = pktio_entry->ops_data(ipc).rx.free; repeat: @@ -582,7 +581,7 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, void **rbuf_p; int ret; int i; - uint32_t ready = odp_atomic_load_u32(&pktio_entry->s.ipc.ready); + uint32_t ready = odp_atomic_load_u32(&pktio_entry->ops_data(ipc).ready); odp_packet_t pkt_table_mapped[len]; /**< Ready to send packet has to be * in memory mapped pool. */ uintptr_t offsets[len]; @@ -590,14 +589,15 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, if (odp_unlikely(!ready)) return 0; - _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.free); + _ipc_free_ring_packets(pktio_entry, pktio_entry->ops_data(ipc).tx.free); /* Copy packets to shm shared pool if they are in different * pool, or if they are references (we can't share across IPC). */ for (i = 0; i < len; i++) { odp_packet_t pkt = pkt_table[i]; - pool_t *ipc_pool = pool_entry_from_hdl(pktio_entry->s.ipc.pool); + pool_t *ipc_pool = pool_entry_from_hdl( + pktio_entry->ops_data(ipc).pool); odp_packet_hdr_t *pkt_hdr; pool_t *pool; @@ -608,7 +608,8 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, odp_packet_has_ref(pkt)) { odp_packet_t newpkt; - newpkt = odp_packet_copy(pkt, pktio_entry->s.ipc.pool); + newpkt = odp_packet_copy( + pkt, pktio_entry->ops_data(ipc).pool); if (newpkt == ODP_PACKET_INVALID) ODP_ABORT("Unable to copy packet\n"); @@ -640,18 +641,19 @@ static int ipc_pktio_send_lockless(pktio_entry_t *pktio_entry, odp_packet_to_u64(pkt), odp_pool_to_u64(pool_hdl), pkt_hdr, pkt_hdr->buf_hdr.ipc_data_offset, offsets[i], odp_shm_addr(pool->shm), - odp_shm_addr(pool_entry_from_hdl( - pktio_entry->s.ipc.pool)->shm)); + odp_shm_addr(pool_entry_from_hdl(pktio_entry-> + ops_data(ipc).pool)->shm)); } /* Put packets to ring to be processed by other process. */ rbuf_p = (void *)&offsets[0]; - r = pktio_entry->s.ipc.tx.send; + r = pktio_entry->ops_data(ipc).tx.send; ret = _ring_mp_enqueue_burst(r, rbuf_p, len); if (odp_unlikely(ret < 0)) { ODP_ERR("pid %d odp_ring_mp_enqueue_bulk fail, ipc_slave %d, ret %d\n", getpid(), - (PKTIO_TYPE_IPC_SLAVE == pktio_entry->s.ipc.type), + (PKTIO_TYPE_IPC_SLAVE == + pktio_entry->ops_data(ipc).type), ret); ODP_ERR("odp_ring_full: %d, odp_ring_count %d, _ring_free_count %d\n", _ring_full(r), _ring_count(r), @@ -691,14 +693,15 @@ static int ipc_mac_addr_get(pktio_entry_t *pktio_entry ODP_UNUSED, static int ipc_start(pktio_entry_t *pktio_entry) { - uint32_t ready = odp_atomic_load_u32(&pktio_entry->s.ipc.ready); + uint32_t ready = odp_atomic_load_u32( + &pktio_entry->ops_data(ipc).ready); if (ready) { ODP_ABORT("%s Already started\n", pktio_entry->s.name); return -1; } - if (pktio_entry->s.ipc.type == PKTIO_TYPE_IPC_MASTER) + if (pktio_entry->ops_data(ipc).type == PKTIO_TYPE_IPC_MASTER) return _ipc_master_start(pktio_entry); else return _ipc_slave_start(pktio_entry); @@ -708,20 +711,22 @@ static int ipc_stop(pktio_entry_t *pktio_entry) { unsigned tx_send = 0, tx_free = 0; - odp_atomic_store_u32(&pktio_entry->s.ipc.ready, 0); + odp_atomic_store_u32(&pktio_entry->ops_data(ipc).ready, 0); - if (pktio_entry->s.ipc.tx.send) - _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.send); + if (pktio_entry->ops_data(ipc).tx.send) + _ipc_free_ring_packets(pktio_entry, + pktio_entry->ops_data(ipc).tx.send); /* other process can transfer packets from one ring to * other, use delay here to free that packets. */ sleep(1); - if (pktio_entry->s.ipc.tx.free) - _ipc_free_ring_packets(pktio_entry, pktio_entry->s.ipc.tx.free); - - if (pktio_entry->s.ipc.tx.send) - tx_send = _ring_count(pktio_entry->s.ipc.tx.send); - if (pktio_entry->s.ipc.tx.free) - tx_free = _ring_count(pktio_entry->s.ipc.tx.free); + if (pktio_entry->ops_data(ipc).tx.free) + _ipc_free_ring_packets(pktio_entry, + pktio_entry->ops_data(ipc).tx.free); + + if (pktio_entry->ops_data(ipc).tx.send) + tx_send = _ring_count(pktio_entry->ops_data(ipc).tx.send); + if (pktio_entry->ops_data(ipc).tx.free) + tx_free = _ring_count(pktio_entry->ops_data(ipc).tx.free); if (tx_send | tx_free) { ODP_DBG("IPC rings: tx send %d tx free %d\n", tx_send, tx_free); @@ -740,7 +745,7 @@ static int ipc_close(pktio_entry_t *pktio_entry) ipc_stop(pktio_entry); - odp_shm_free(pktio_entry->s.ipc.remote_pool_shm); + odp_shm_free(pktio_entry->ops_data(ipc).remote_pool_shm); if (sscanf(dev, "ipc:%d:%s", &pid, tail) == 2) snprintf(name, sizeof(name), "ipc:%s", tail); @@ -748,7 +753,7 @@ static int ipc_close(pktio_entry_t *pktio_entry) snprintf(name, sizeof(name), "%s", dev); /* unlink this pktio info for both master and slave */ - odp_shm_free(pktio_entry->s.ipc.pinfo_shm); + odp_shm_free(pktio_entry->ops_data(ipc).pinfo_shm); /* destroy rings */ snprintf(ipc_shm_name, sizeof(ipc_shm_name), "%s_s_cons", name); From patchwork Tue Sep 19 03:00:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112966 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4399332qgf; Mon, 18 Sep 2017 20:04:26 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCDia7TtugpmRCqz89uj6hsaJ57R33XCwvEIWN0aS6q8cSkggLKoTZMk2oSSWLWEh/5LdrK X-Received: by 10.200.25.183 with SMTP id u52mr50770948qtj.102.1505790266019; Mon, 18 Sep 2017 20:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790266; cv=none; d=google.com; s=arc-20160816; b=cTJ9u/i01n3cvARi7NxmgfQ9S56+1I14L0ihJrkyl06Jlryl9sGkmp5C13jg3c9KpT G3PpsVv7pkng+hFXrSgWyEIgDvgWuJ5fwVdPnCb4TtNAlS6jN4jWmzNvHAKNycaGiqp4 VSDoWhbixfuuUPswfrnY15/U16tV58BxNPMkUsTAy7lQ9089VCo7tLOLzgHSR2gi5VNT ogZKwgruTirLuFl//b6ILaEhwCkeRkDFVDYRXwvoLYV6nbKgmmnvzBho5k4RSsKqXj7c VhHCC23GVahaqody6oQrz16H1DDcn08Ld91EV1Lk4uPLpAwkIVa1LdAQCPok5SgH+Xml 7cng== 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=Y/JThUvZMIanQ4ApcncV6SLph1BOLagp2pNa9K6ZL0Q=; b=zm07TRpOFi2CzZdqweIBg84QiwYb40K08ZA9e/szGl9/uoDriKdJPOL4zrHg0Q0G/S WfT4zE5Z5NyFAFKLvq9LR8w5mVmc15P5AYLPTm0S+CO45Q+ESXt79s06ayx5iIfEkiEM qi06t6dnbxjsi9DP6RPy7enEPKdGr5yXSsY6fUalfeToqLW2N+mnjjmh8ceBrh7ZVZzF 1TChXICRb6CcsF8VfuKMFvxJL7uvO4pteHio5cwe+023hDtTVYs6UYCl47oyDYFLAD0b FrWpqhaQYeXB7xaHhEZFgNgRciaxsP75FVHBPz1ma1o0qXHExndjdiPWx1IQQ/EFJre4 TZ4g== 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 v2si8479191qtb.9.2017.09.18.20.04.25; Mon, 18 Sep 2017 20:04:26 -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 AC15462D0C; Tue, 19 Sep 2017 03:04:25 +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.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id AB1AF61E02; Tue, 19 Sep 2017 03:01:02 +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 E9BEF62875; Tue, 19 Sep 2017 03:00:46 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id 5F98A60F1D for ; Tue, 19 Sep 2017 03:00:39 +0000 (UTC) Received: from mxback2j.mail.yandex.net (mxback2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10b]) by forward104j.mail.yandex.net (Yandex) with ESMTP id BEA8243E6E for ; Tue, 19 Sep 2017 06:00:37 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Xm9qvfEtDr-0bT4ZdpC; Tue, 19 Sep 2017 06:00:37 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0bRKhEum; Tue, 19 Sep 2017 06:00:37 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 19 Sep 2017 06:00:20 +0300 Message-Id: <1505790024-16070-7-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 6/10] linux-gen: pktio: netmap: minor code refactory X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ platform/linux-generic/Makefile.am | 2 +- .../linux-generic/include/odp_packet_io_internal.h | 2 - ...{odp_packet_netmap.h => odp_pktio_ops_netmap.h} | 6 +- .../include/odp_pktio_ops_subsystem.h | 2 + platform/linux-generic/pktio/netmap.c | 89 ++++++++++++---------- 5 files changed, 56 insertions(+), 45 deletions(-) rename platform/linux-generic/include/{odp_packet_netmap.h => odp_pktio_ops_netmap.h} (96%) diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index dd8767b2f..1e05c2c50 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -186,12 +186,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ - ${srcdir}/include/odp_packet_netmap.h \ ${srcdir}/include/odp_packet_dpdk.h \ ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ + ${srcdir}/include/odp_pktio_ops_netmap.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 8d3c3ddff..af826b7e7 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -32,7 +32,6 @@ extern "C" { #define PKTIO_MAX_QUEUES 64 #include -#include #include #include @@ -78,7 +77,6 @@ struct pktio_entry { pkt_sock_t pkt_sock; /**< using socket API for IO */ pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap * API for IO */ - pkt_netmap_t pkt_nm; /**< using netmap API for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ #ifdef HAVE_PCAP pkt_pcap_t pkt_pcap; /**< Using pcap for IO */ diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_pktio_ops_netmap.h similarity index 96% rename from platform/linux-generic/include/odp_packet_netmap.h rename to platform/linux-generic/include/odp_pktio_ops_netmap.h index a6f68d569..35592d85f 100644 --- a/platform/linux-generic/include/odp_packet_netmap.h +++ b/platform/linux-generic/include/odp_pktio_ops_netmap.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_NETMAP_H -#define ODP_PACKET_NETMAP_H +#ifndef ODP_PKTIO_OPS_NETMAP_H_ +#define ODP_PKTIO_OPS_NETMAP_H_ #include #include @@ -63,6 +63,6 @@ typedef struct { netmap_ring_t rx_desc_ring[PKTIO_MAX_QUEUES]; /** mapping of pktout queues to netmap tx descriptors */ netmap_ring_t tx_desc_ring[PKTIO_MAX_QUEUES]; -} pkt_netmap_t; +} pktio_ops_netmap_data_t; #endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 650b36648..b1b735ced 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -81,6 +81,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { /* All implementations of this subsystem */ #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -88,6 +89,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { typedef union { pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; + pktio_ops_netmap_data_t netmap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index c75f8be97..accac61c6 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -46,15 +45,16 @@ static int netmap_stats_reset(pktio_entry_t *pktio_entry); static int netmap_do_ioctl(pktio_entry_t *pktio_entry, unsigned long cmd, int subcmd) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); struct ethtool_value eval; struct ifreq ifr; int err; int fd = pkt_nm->sockfd; memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", - pktio_entry->s.pkt_nm.if_name); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), + "%s", pkt_nm->if_name); switch (cmd) { case SIOCSIFFLAGS: @@ -133,7 +133,8 @@ static inline void map_netmap_rings(netmap_ring_t *rings, static int netmap_input_queues_config(pktio_entry_t *pktio_entry, const odp_pktin_queue_param_t *p) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); odp_pktin_mode_t mode = pktio_entry->s.param.in_mode; unsigned num_queues = p->num_queues; odp_bool_t lockless; @@ -146,8 +147,7 @@ static int netmap_input_queues_config(pktio_entry_t *pktio_entry, lockless = (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE); if (p->hash_enable && num_queues > 1) { - if (rss_conf_set_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name, + if (rss_conf_set_fd(pkt_nm->sockfd, pkt_nm->if_name, &p->hash_proto)) { ODP_ERR("Failed to configure input hash\n"); return -1; @@ -162,7 +162,8 @@ static int netmap_input_queues_config(pktio_entry_t *pktio_entry, static int netmap_output_queues_config(pktio_entry_t *pktio_entry, const odp_pktout_queue_param_t *p) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); pkt_nm->lockless_tx = (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE); @@ -179,7 +180,8 @@ static int netmap_output_queues_config(pktio_entry_t *pktio_entry, static inline void netmap_close_descriptors(pktio_entry_t *pktio_entry) { int i, j; - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); for (i = 0; i < PKTIO_MAX_QUEUES; i++) { for (j = 0; j < NM_MAX_DESC; j++) { @@ -202,7 +204,8 @@ static inline void netmap_close_descriptors(pktio_entry_t *pktio_entry) static int netmap_close(pktio_entry_t *pktio_entry) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); netmap_close_descriptors(pktio_entry); @@ -216,11 +219,11 @@ static int netmap_close(pktio_entry_t *pktio_entry) static int netmap_link_status(pktio_entry_t *pktio_entry) { - if (pktio_entry->s.pkt_nm.is_virtual) + if (pktio_entry->ops_data(netmap).is_virtual) return 1; - return link_status_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name); + return link_status_fd(pktio_entry->ops_data(netmap).sockfd, + pktio_entry->ops_data(netmap).if_name); } /** @@ -247,12 +250,12 @@ static inline int netmap_wait_for_link(pktio_entry_t *pktio_entry) * until the opposing end's interface comes back up again. In * this case without the additional sleep pktio validation * tests fail. */ - if (!pktio_entry->s.pkt_nm.is_virtual) + if (!pktio_entry->ops_data(netmap).is_virtual) sleep(1); if (ret == 1) return 1; } - ODP_DBG("%s link is down\n", pktio_entry->s.pkt_nm.if_name); + ODP_DBG("%s link is down\n", pktio_entry->ops_data(netmap).if_name); return 0; } @@ -263,7 +266,8 @@ static inline int netmap_wait_for_link(pktio_entry_t *pktio_entry) */ static void netmap_init_capability(pktio_entry_t *pktio_entry) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); odp_pktio_capability_t *capa = &pkt_nm->capa; memset(&pkt_nm->capa, 0, sizeof(odp_pktio_capability_t)); @@ -330,7 +334,8 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *prefix; uint32_t mtu; uint32_t buf_size; - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); struct nm_desc *desc; struct netmap_ring *ring; odp_pktin_hash_proto_t hash_proto; @@ -407,7 +412,7 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, /* Use either interface MTU (+ ethernet header length) or netmap buffer * size as MTU, whichever is smaller. */ - mtu = mtu_get_fd(pktio_entry->s.pkt_nm.sockfd, pkt_nm->if_name); + mtu = mtu_get_fd(pkt_nm->sockfd, pkt_nm->if_name); if (mtu == 0) { ODP_ERR("Unable to read interface MTU\n"); goto error; @@ -432,7 +437,7 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, goto error; /* netmap uses only ethtool to get statistics counters */ - err = ethtool_stats_get_fd(pktio_entry->s.pkt_nm.sockfd, + err = ethtool_stats_get_fd(pkt_nm->sockfd, pkt_nm->if_name, &cur_stats); if (err) { ODP_ERR("netmap pktio %s does not support statistics counters\n", @@ -453,7 +458,8 @@ static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, static int netmap_start(pktio_entry_t *pktio_entry) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); netmap_ring_t *desc_ring; struct nm_desc *desc_ptr; unsigned i; @@ -610,7 +616,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, odp_time_t *ts) { odp_packet_t pkt; - odp_pool_t pool = pktio_entry->s.pkt_nm.pool; + odp_pool_t pool = pktio_entry->ops_data(netmap).pool; odp_packet_hdr_t *pkt_hdr; odp_packet_hdr_t parsed_hdr; int i; @@ -618,7 +624,7 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, int alloc_len; /* Allocate maximum sized packets */ - alloc_len = pktio_entry->s.pkt_nm.mtu; + alloc_len = pktio_entry->ops_data(netmap).mtu; num = packet_alloc_multi(pool, alloc_len, pkt_tbl, slot_num); @@ -631,9 +637,10 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, odp_prefetch(slot.buf); - if (odp_unlikely(len > pktio_entry->s.pkt_nm.max_frame_len)) { + if (odp_unlikely(len > pktio_entry-> + ops_data(netmap).max_frame_len)) { ODP_ERR("RX: frame too big %" PRIu16 " %zu!\n", len, - pktio_entry->s.pkt_nm.max_frame_len); + pktio_entry->ops_data(netmap).max_frame_len); goto fail; } @@ -729,7 +736,8 @@ static int netmap_recv(pktio_entry_t *pktio_entry, int index, odp_packet_t pkt_table[], int num) { struct nm_desc *desc; - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); unsigned first_desc_id = pkt_nm->rx_desc_ring[index].s.first; unsigned last_desc_id = pkt_nm->rx_desc_ring[index].s.last; unsigned desc_id; @@ -782,7 +790,8 @@ static int netmap_recv(pktio_entry_t *pktio_entry, int index, static int netmap_send(pktio_entry_t *pktio_entry, int index, const odp_packet_t pkt_table[], int num) { - pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm; + pktio_ops_netmap_data_t *pkt_nm = + &pktio_entry->ops_data(netmap); struct pollfd polld; struct nm_desc *desc; struct netmap_ring *ring; @@ -857,40 +866,42 @@ static int netmap_send(pktio_entry_t *pktio_entry, int index, static int netmap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_entry->s.pkt_nm.if_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->ops_data(netmap).if_mac, ETH_ALEN); return ETH_ALEN; } static uint32_t netmap_mtu_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_nm.mtu; + return pktio_entry->ops_data(netmap).mtu; } static int netmap_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - if (pktio_entry->s.pkt_nm.is_virtual) { + if (pktio_entry->ops_data(netmap).is_virtual) { __odp_errno = ENOTSUP; return -1; } - return promisc_mode_set_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name, enable); + return promisc_mode_set_fd( + pktio_entry->ops_data(netmap).sockfd, + pktio_entry->ops_data(netmap).if_name, enable); } static int netmap_promisc_mode_get(pktio_entry_t *pktio_entry) { - if (pktio_entry->s.pkt_nm.is_virtual) + if (pktio_entry->ops_data(netmap).is_virtual) return 0; - return promisc_mode_get_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name); + return promisc_mode_get_fd( + pktio_entry->ops_data(netmap).sockfd, + pktio_entry->ops_data(netmap).if_name); } static int netmap_capability(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa) { - *capa = pktio_entry->s.pkt_nm.capa; + *capa = pktio_entry->ops_data(netmap).capa; return 0; } @@ -904,7 +915,7 @@ static int netmap_stats(pktio_entry_t *pktio_entry, return sock_stats_fd(pktio_entry, stats, - pktio_entry->s.pkt_nm.sockfd); + pktio_entry->ops_data(netmap).sockfd); } static int netmap_stats_reset(pktio_entry_t *pktio_entry) @@ -916,15 +927,15 @@ static int netmap_stats_reset(pktio_entry_t *pktio_entry) } return sock_stats_reset_fd(pktio_entry, - pktio_entry->s.pkt_nm.sockfd); + pktio_entry->ops_data(netmap).sockfd); } static void netmap_print(pktio_entry_t *pktio_entry) { odp_pktin_hash_proto_t hash_proto; - if (rss_conf_get_fd(pktio_entry->s.pkt_nm.sockfd, - pktio_entry->s.pkt_nm.if_name, &hash_proto)) + if (rss_conf_get_fd(pktio_entry->ops_data(netmap).sockfd, + pktio_entry->ops_data(netmap).if_name, &hash_proto)) rss_conf_print(&hash_proto); } From patchwork Tue Sep 19 03:00:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112969 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4403725qgf; Mon, 18 Sep 2017 20:10:41 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCjOApD3j1ESLd8HSlbnTuZ/f7eAtXHko6CJlg27gSRyhXRLuX0ubFOGhCeB3FqF4PJny+0 X-Received: by 10.200.55.228 with SMTP id e33mr55081833qtc.170.1505790641847; Mon, 18 Sep 2017 20:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790641; cv=none; d=google.com; s=arc-20160816; b=xp/okUzHYGHMwF2lC816+8W9zMmvbIqcRduv1+5qxlurmB+VvrDzwTXekkLnV+D/cK q1zeZjh4KTIMxkQsCoP4uFkkea02XRevCpw6Hcbm6R4uAhWwMfTr0WXFgebqlZjm1Ss+ dPFbHHdyBov0MXeCSe2fMCwSDawgRhmXfX7+OfdaAMzLFqkjm/+kz/lNKaqsC4I6Gbtp XWk+DPTIs9VgESLZLssaJvUhIiWp91GoWdXZx++X07f52g3nWQL2HvaQQlqHU66a/1qT QKN7QTLLrp3R5w8AUWZK3ZvK7PDNzzeFxPhNi3c8X3Vx6lqCwm7x0kBk3ReKLe5s8N14 nO0Q== 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=HfMBpDx5+irZsvHjWim9aCHy96ypArK5ZaITvnYXuJ0=; b=VsNvkhhlbg9KpKTdulrjWuEEr4mSo3jHNftri4zGTvEIEaW8RxpEHjnl/k99PcH9Yb TrxbSu1N6Yzkn7iQefVIfi5Jis6LxWZ8RcRETSrmbYRraVBtB4M2lSE73yB8yzLuqgZx dqGcegaa2EgNRSqdJr9Alcd+LJ34ZbSaqnIOB+pjb4HFjqVzW76x+fv5+NcyKDvt884U SK2U4rdZEDRs2p+BbPXNSZA5Y/n/OSpRtZqX6pz0+hItnJHDQQ7TxWoj0kWBRRZMLQVp pDLY1ggJ/Pg4B/eyskLXnyLwhmFgYT8LLhYxRrcwHr4I7Df0pahTo+jgTT2VPUcQp211 m8/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 s62si8141771qkd.449.2017.09.18.20.10.41; Mon, 18 Sep 2017 20:10: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 6781D63CB3; Tue, 19 Sep 2017 03:10:41 +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 E67F060802; Tue, 19 Sep 2017 03:01:31 +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 8D5DE62AE6; Tue, 19 Sep 2017 03:00:50 +0000 (UTC) Received: from forward105p.mail.yandex.net (forward105p.mail.yandex.net [77.88.28.108]) by lists.linaro.org (Postfix) with ESMTPS id 079DF61CBE for ; Tue, 19 Sep 2017 03:00:40 +0000 (UTC) Received: from mxback8o.mail.yandex.net (mxback8o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::22]) by forward105p.mail.yandex.net (Yandex) with ESMTP id 785714084B5E for ; Tue, 19 Sep 2017 06:00:38 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback8o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 04qLJUo1FB-0cpSFxoo; Tue, 19 Sep 2017 06:00:38 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0bR8s3gC; Tue, 19 Sep 2017 06:00:37 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 19 Sep 2017 06:00:21 +0300 Message-Id: <1505790024-16070-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 7/10] linux-gen: pktio: pcap: minor code refactory X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ platform/linux-generic/Makefile.am | 1 + .../linux-generic/include/odp_packet_io_internal.h | 18 ------------- .../linux-generic/include/odp_pktio_ops_pcap.h | 25 ++++++++++++++++++ .../include/odp_pktio_ops_subsystem.h | 2 ++ platform/linux-generic/pktio/pcap.c | 30 +++++++++++++--------- 5 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 platform/linux-generic/include/odp_pktio_ops_pcap.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 1e05c2c50..78283c019 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -192,6 +192,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ + ${srcdir}/include/odp_pktio_ops_pcap.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index af826b7e7..a3890091f 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -50,21 +50,6 @@ typedef union pktio_entry_u pktio_entry_t; * requested number of packets were not handled. */ #define SOCK_ERR_REPORT(e) (e != EAGAIN && e != EWOULDBLOCK && e != EINTR) -#ifdef HAVE_PCAP -typedef struct { - char *fname_rx; /**< name of pcap file for rx */ - char *fname_tx; /**< name of pcap file for tx */ - void *rx; /**< rx pcap handle */ - void *tx; /**< tx pcap handle */ - void *tx_dump; /**< tx pcap dumper handle */ - odp_pool_t pool; /**< rx pool */ - unsigned char *buf; /**< per-pktio temp buffer */ - int loops; /**< number of times to loop rx pcap */ - int loop_cnt; /**< number of loops completed */ - odp_bool_t promisc; /**< promiscuous mode state */ -} pkt_pcap_t; -#endif - struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ pktio_ops_data_t ops_data; /**< IO operation specific data */ @@ -78,9 +63,6 @@ struct pktio_entry { pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap * API for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ -#ifdef HAVE_PCAP - pkt_pcap_t pkt_pcap; /**< Using pcap for IO */ -#endif pkt_tap_t pkt_tap; /**< using TAP for IO */ }; enum { diff --git a/platform/linux-generic/include/odp_pktio_ops_pcap.h b/platform/linux-generic/include/odp_pktio_ops_pcap.h new file mode 100644 index 000000000..6911710c4 --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_pcap.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_PCAP_H_ +#define ODP_PKTIO_OPS_PCAP_H_ + +typedef struct { + char *fname_rx; /**< name of pcap file for rx */ + char *fname_tx; /**< name of pcap file for tx */ + void *rx; /**< rx pcap handle */ + void *tx; /**< tx pcap handle */ + void *tx_dump; /**< tx pcap dumper handle */ + odp_pool_t pool; /**< rx pool */ + unsigned char *buf; /**< per-pktio temp buffer */ + int loops; /**< number of times to loop rx pcap */ + int loop_cnt; /**< number of loops completed */ + odp_bool_t promisc; /**< promiscuous mode state */ +} pktio_ops_pcap_data_t; + +#endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index b1b735ced..fc461be79 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -82,6 +82,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { #include #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -90,6 +91,7 @@ typedef union { pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; pktio_ops_netmap_data_t netmap; + pktio_ops_pcap_data_t pcap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index 98f810898..b54501ed2 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -51,7 +51,8 @@ static const char pcap_mac[] = {0x02, 0xe9, 0x34, 0x80, 0x73, 0x04}; static int pcapif_stats_reset(pktio_entry_t *pktio_entry); -static int _pcapif_parse_devname(pkt_pcap_t *pcap, const char *devname) +static int _pcapif_parse_devname( + pktio_ops_pcap_data_t *pcap, const char *devname) { char *tok; char in[PKTIO_NAME_LEN]; @@ -80,7 +81,7 @@ static int _pcapif_parse_devname(pkt_pcap_t *pcap, const char *devname) return 0; } -static int _pcapif_init_rx(pkt_pcap_t *pcap) +static int _pcapif_init_rx(pktio_ops_pcap_data_t *pcap) { char errbuf[PCAP_ERRBUF_SIZE]; int linktype; @@ -101,7 +102,7 @@ static int _pcapif_init_rx(pkt_pcap_t *pcap) return 0; } -static int _pcapif_init_tx(pkt_pcap_t *pcap) +static int _pcapif_init_tx(pktio_ops_pcap_data_t *pcap) { pcap_t *tx = pcap->rx; @@ -136,10 +137,11 @@ static int _pcapif_init_tx(pkt_pcap_t *pcap) static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *devname, odp_pool_t pool) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); int ret; - memset(pcap, 0, sizeof(pkt_pcap_t)); + memset(pcap, 0, sizeof(pktio_ops_pcap_data_t)); pcap->loop_cnt = 1; pcap->loops = 1; pcap->pool = pool; @@ -163,7 +165,8 @@ static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, static int pcapif_close(pktio_entry_t *pktio_entry) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); if (pcap->tx_dump) pcap_dump_close(pcap->tx_dump); @@ -181,7 +184,7 @@ static int pcapif_close(pktio_entry_t *pktio_entry) return 0; } -static int _pcapif_reopen(pkt_pcap_t *pcap) +static int _pcapif_reopen(pktio_ops_pcap_data_t *pcap) { char errbuf[PCAP_ERRBUF_SIZE]; @@ -210,7 +213,8 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_packet_t pkt; odp_packet_hdr_t *pkt_hdr; uint32_t pkt_len; - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); odp_time_t ts_val; odp_time_t *ts = NULL; @@ -270,7 +274,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, return i; } -static int _pcapif_dump_pkt(pkt_pcap_t *pcap, odp_packet_t pkt) +static int _pcapif_dump_pkt(pktio_ops_pcap_data_t *pcap, odp_packet_t pkt) { struct pcap_pkthdr hdr; @@ -293,7 +297,8 @@ static int _pcapif_dump_pkt(pkt_pcap_t *pcap, odp_packet_t pkt) static int pcapif_send_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, const odp_packet_t pkts[], int len) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); int i; odp_ticketlock_lock(&pktio_entry->s.txl); @@ -361,7 +366,8 @@ static int pcapif_promisc_mode_set(pktio_entry_t *pktio_entry, { char filter_exp[64] = {0}; struct bpf_program bpf; - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); if (!pcap->rx) { pcap->promisc = enable; @@ -401,7 +407,7 @@ static int pcapif_promisc_mode_set(pktio_entry_t *pktio_entry, static int pcapif_promisc_mode_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_pcap.promisc; + return pktio_entry->ops_data(pcap).promisc; } static int pcapif_stats_reset(pktio_entry_t *pktio_entry) From patchwork Tue Sep 19 03:00:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112970 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4406235qgf; Mon, 18 Sep 2017 20:14:20 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBTb96Rt96PXqdFnDQ8gAcx26J7Dk/jIxkxVxBmw5mzHLZH0RZbT/Fkgl1BeQhp0QojzGxR X-Received: by 10.107.137.213 with SMTP id t82mr25155473ioi.289.1505790860767; Mon, 18 Sep 2017 20:14:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790860; cv=none; d=google.com; s=arc-20160816; b=pkfeZ8tzmIynCMw3nMKiCvpAxjh7sxAFm+dVDnOKR0YZpTS4RBK9nIAH2mwuZT58hl saCd64H2jSCL+dYw2C9uoxvUGc3zYP0eJT0R5SMRnTP6XB2gCqLtwjcHxuWF3kYnBFbD 21miHRFr763TrXN/fcCjT2potUnTuHHCn+lQ3MuKN0xijTjZ5gwUFA5YjUZwOmZb8IiV 5tdgJE7OBw1q+1PN+LvBCg2/hcoXw8mvF1ydRmR7O4o2y5BnrOwQCkcCwytG/7zQ43Hn fuZHeClPIVTD60qYYV6G/NqbJ+AXCnUflhfB4l1NC5EfA9sDu7UE0mXFHL9OoQPbJxAU ep6Q== 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=4LapPI41V6NogDxxaDR3MgAgJ1C1nbzNSkSesOJEqhI=; b=DT2URbZLTcgAWmNKrPTD22RuIFhdjw1r/l2vKNQ5lcr5WZnnGdyABqXHlW5ST1sFsp hDkopR+Pww/1pMu3qAqvrZxJ1eA5FEUgn2BHLUshTAmB7QBb8BFCf16TMl2e0g//iiln bu6X3lJFFhYsDXFNQPFMbfOWx8y/bFg3lxMTVG/9Yc4p9T360Ycpn1o+3okqgUcJebP1 sQF0HyapPhGEh1PsEEFPvcn1hwLsvo3qv9yLNpAtpS59dwtawUVT/jk6hgigdhG1xmWq 3wWRq5pmxIsr64p6rj/AgX3Aw/rhC0ZrhGmD+fai+FcUvsm/UdQfeDGrPXzIpe2/Au4Y 50aQ== 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 f10si7232935iod.140.2017.09.18.20.14.20; Mon, 18 Sep 2017 20:14:20 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id F168A62D08; Tue, 19 Sep 2017 03:14: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.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id A83D262DF9; Tue, 19 Sep 2017 03:01:56 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1DD0462C62; Tue, 19 Sep 2017 03:01:19 +0000 (UTC) Received: from forward104j.mail.yandex.net (forward104j.mail.yandex.net [5.45.198.247]) by lists.linaro.org (Postfix) with ESMTPS id 5AD6C61DE2 for ; Tue, 19 Sep 2017 03:00:40 +0000 (UTC) Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward104j.mail.yandex.net (Yandex) with ESMTP id 581BA40EE2 for ; Tue, 19 Sep 2017 06:00:39 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id WvAcSOKTim-0dK47JNP; Tue, 19 Sep 2017 06:00:39 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0cRW2wr0; Tue, 19 Sep 2017 06:00:38 +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: Tue, 19 Sep 2017 06:00:22 +0300 Message-Id: <1505790024-16070-9-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 8/10] linux-gen: pktio: socket: minor code refactory X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Rename implementation specific data structure and its dedicated header file to accommodate uniformed name scheme. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ platform/linux-dpdk/Makefile.am | 2 +- platform/linux-generic/Makefile.am | 2 +- .../linux-generic/include/odp_packet_io_internal.h | 4 -- ...{odp_packet_socket.h => odp_pktio_ops_socket.h} | 8 ++-- .../include/odp_pktio_ops_subsystem.h | 3 ++ platform/linux-generic/odp_packet_io.c | 1 - platform/linux-generic/pktio/ethtool.c | 2 +- platform/linux-generic/pktio/netmap.c | 1 - platform/linux-generic/pktio/socket.c | 30 ++++++++------- platform/linux-generic/pktio/socket_mmap.c | 45 ++++++++++++---------- platform/linux-generic/pktio/tap.c | 1 - 11 files changed, 51 insertions(+), 48 deletions(-) rename platform/linux-generic/include/{odp_packet_socket.h => odp_pktio_ops_socket.h} (96%) diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am index 9ebf2ea14..9d32defd5 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -191,12 +191,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_ipc.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ + ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_socket.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_loopback.h \ ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_errno_define.h \ ${top_srcdir}/platform/linux-generic/include/odp_packet_io_ring_internal.h \ - ${top_srcdir}/platform/linux-generic/include/odp_packet_socket.h \ ${top_srcdir}/platform/linux-generic/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_pool_subsystem.h \ diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 78283c019..b3ee86c67 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -187,12 +187,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ ${srcdir}/include/odp_packet_dpdk.h \ - ${srcdir}/include/odp_packet_socket.h \ ${srcdir}/include/odp_packet_tap.h \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ ${srcdir}/include/odp_pktio_ops_pcap.h \ + ${srcdir}/include/odp_pktio_ops_socket.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index a3890091f..f58ef8721 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -31,7 +31,6 @@ extern "C" { #include #define PKTIO_MAX_QUEUES 64 -#include #include #include @@ -59,9 +58,6 @@ struct pktio_entry { int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ union { - pkt_sock_t pkt_sock; /**< using socket API for IO */ - pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap - * API for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ pkt_tap_t pkt_tap; /**< using TAP for IO */ }; diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_pktio_ops_socket.h similarity index 96% rename from platform/linux-generic/include/odp_packet_socket.h rename to platform/linux-generic/include/odp_pktio_ops_socket.h index 0e61f6f0c..32c49c08e 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_pktio_ops_socket.h @@ -5,8 +5,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_SOCKET_H -#define ODP_PACKET_SOCKET_H +#ifndef ODP_PKTIO_OPS_SOCKET_H_ +#define ODP_PKTIO_OPS_SOCKET_H_ #include #include @@ -42,7 +42,7 @@ typedef struct { odp_pool_t pool; /**< pool to alloc packets from */ uint32_t mtu; /**< maximum transmission unit */ unsigned char if_mac[ETH_ALEN]; /**< IF eth mac addr */ -} pkt_sock_t; +} pktio_ops_socket_data_t; /** packet mmap ring */ struct ring { @@ -79,7 +79,7 @@ typedef struct { unsigned char if_mac[ETH_ALEN]; struct sockaddr_ll ll; int fanout; -} pkt_sock_mmap_t; +} pktio_ops_socket_mmap_data_t; static inline void ethaddr_copy(unsigned char mac_dst[], unsigned char mac_src[]) diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index fc461be79..952d9be55 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -83,6 +83,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { #include #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -92,6 +93,8 @@ typedef union { pktio_ops_loopback_data_t loopback; pktio_ops_netmap_data_t netmap; pktio_ops_pcap_data_t pcap; + pktio_ops_socket_data_t socket; + pktio_ops_socket_mmap_data_t mmap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 6a19394a5..e023df130 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/platform/linux-generic/pktio/ethtool.c b/platform/linux-generic/pktio/ethtool.c index d8f9e12cb..ed2875c5b 100644 --- a/platform/linux-generic/pktio/ethtool.c +++ b/platform/linux-generic/pktio/ethtool.c @@ -13,8 +13,8 @@ #include #include -#include #include +#include static struct ethtool_gstrings *get_stringset(int fd, struct ifreq *ifr) { diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index accac61c6..07d6d9e9b 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index 8b8ccf033..c7c3c5a8c 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include @@ -455,7 +454,9 @@ void rss_conf_print(const odp_pktin_hash_proto_t *hash_proto) */ static int sock_close(pktio_entry_t *pktio_entry) { - pkt_sock_t *pkt_sock = &pktio_entry->s.pkt_sock; + pktio_ops_socket_data_t *pkt_sock = + &pktio_entry->ops_data(socket); + if (pkt_sock->sockfd != -1 && close(pkt_sock->sockfd) != 0) { __odp_errno = errno; ODP_ERR("close(sockfd): %s\n", strerror(errno)); @@ -477,7 +478,8 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, struct ifreq ethreq; struct sockaddr_ll sa_ll; char shm_name[ODP_SHM_NAME_LEN]; - pkt_sock_t *pkt_sock = &pktio_entry->s.pkt_sock; + pktio_ops_socket_data_t *pkt_sock = + &pktio_entry->ops_data(socket); odp_pktio_stats_t cur_stats; /* Init pktio entry */ @@ -530,7 +532,7 @@ static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev, goto error; } - err = ethtool_stats_get_fd(pktio_entry->s.pkt_sock.sockfd, + err = ethtool_stats_get_fd(pkt_sock->sockfd, pktio_entry->s.name, &cur_stats); if (err != 0) { @@ -601,7 +603,8 @@ static uint32_t _rx_pkt_to_iovec(odp_packet_t pkt, static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_packet_t pkt_table[], int len) { - pkt_sock_t *pkt_sock = &pktio_entry->s.pkt_sock; + pktio_ops_socket_data_t *pkt_sock = + &pktio_entry->ops_data(socket); odp_pool_t pool = pkt_sock->pool; odp_time_t ts_val; odp_time_t *ts = NULL; @@ -716,7 +719,8 @@ static uint32_t _tx_pkt_to_iovec(odp_packet_t pkt, static int sock_mmsg_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, const odp_packet_t pkt_table[], int len) { - pkt_sock_t *pkt_sock = &pktio_entry->s.pkt_sock; + pktio_ops_socket_data_t *pkt_sock = + &pktio_entry->ops_data(socket); struct mmsghdr msgvec[len]; struct iovec iovecs[len][MAX_SEGS]; int ret; @@ -762,7 +766,7 @@ static int sock_mmsg_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, */ static uint32_t sock_mtu_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_sock.mtu; + return pktio_entry->ops_data(socket).mtu; } /* @@ -771,7 +775,7 @@ static uint32_t sock_mtu_get(pktio_entry_t *pktio_entry) static int sock_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_entry->s.pkt_sock.if_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->ops_data(socket).if_mac, ETH_ALEN); return ETH_ALEN; } @@ -781,7 +785,7 @@ static int sock_mac_addr_get(pktio_entry_t *pktio_entry, static int sock_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - return promisc_mode_set_fd(pktio_entry->s.pkt_sock.sockfd, + return promisc_mode_set_fd(pktio_entry->ops_data(socket).sockfd, pktio_entry->s.name, enable); } @@ -790,13 +794,13 @@ static int sock_promisc_mode_set(pktio_entry_t *pktio_entry, */ static int sock_promisc_mode_get(pktio_entry_t *pktio_entry) { - return promisc_mode_get_fd(pktio_entry->s.pkt_sock.sockfd, + return promisc_mode_get_fd(pktio_entry->ops_data(socket).sockfd, pktio_entry->s.name); } static int sock_link_status(pktio_entry_t *pktio_entry) { - return link_status_fd(pktio_entry->s.pkt_sock.sockfd, + return link_status_fd(pktio_entry->ops_data(socket).sockfd, pktio_entry->s.name); } @@ -825,7 +829,7 @@ static int sock_stats(pktio_entry_t *pktio_entry, return sock_stats_fd(pktio_entry, stats, - pktio_entry->s.pkt_sock.sockfd); + pktio_entry->ops_data(socket).sockfd); } static int sock_stats_reset(pktio_entry_t *pktio_entry) @@ -837,7 +841,7 @@ static int sock_stats_reset(pktio_entry_t *pktio_entry) } return sock_stats_reset_fd(pktio_entry, - pktio_entry->s.pkt_sock.sockfd); + pktio_entry->ops_data(socket).sockfd); } static int sock_init_global(void) diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 0a27316f2..9054a835c 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -37,8 +36,8 @@ static int disable_pktio; /** !0 this pktio disabled, 0 enabled */ -static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t *const pkt_sock, - int sock_group_idx) +static int set_pkt_sock_fanout_mmap( + pktio_ops_socket_mmap_data_t *const pkt_sock, int sock_group_idx) { int sockfd = pkt_sock->sockfd; int val; @@ -144,7 +143,7 @@ static uint8_t *pkt_mmap_vlan_insert(uint8_t *l2_hdr_ptr, } static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry, - pkt_sock_mmap_t *pkt_sock, + pktio_ops_socket_mmap_data_t *pkt_sock, odp_packet_t pkt_table[], unsigned len, unsigned char if_mac[]) { @@ -411,7 +410,7 @@ static int mmap_setup_ring(int sock, struct ring *ring, int type, return 0; } -static int mmap_sock(pkt_sock_mmap_t *pkt_sock) +static int mmap_sock(pktio_ops_socket_mmap_data_t *pkt_sock) { int i; int sock = pkt_sock->sockfd; @@ -455,14 +454,15 @@ static int mmap_sock(pkt_sock_mmap_t *pkt_sock) return 0; } -static int mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock) +static int mmap_unmap_sock(pktio_ops_socket_mmap_data_t *pkt_sock) { free(pkt_sock->rx_ring.rd); free(pkt_sock->tx_ring.rd); return munmap(pkt_sock->mmap_base, pkt_sock->mmap_len); } -static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, const char *netdev) +static int mmap_bind_sock(pktio_ops_socket_mmap_data_t *pkt_sock, + const char *netdev) { int ret; @@ -486,7 +486,8 @@ static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, const char *netdev) static int sock_mmap_close(pktio_entry_t *entry) { - pkt_sock_mmap_t *const pkt_sock = &entry->s.pkt_sock_mmap; + pktio_ops_socket_mmap_data_t + *const pkt_sock = &entry->ops_data(mmap); int ret; ret = mmap_unmap_sock(pkt_sock); @@ -515,7 +516,8 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, if (disable_pktio) return -1; - pkt_sock_mmap_t *const pkt_sock = &pktio_entry->s.pkt_sock_mmap; + pktio_ops_socket_mmap_data_t + *const pkt_sock = &pktio_entry->ops_data(mmap); int fanout = 1; /* Init pktio entry */ @@ -570,7 +572,7 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, goto error; } - ret = ethtool_stats_get_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + ret = ethtool_stats_get_fd(pkt_sock->sockfd, pktio_entry->s.name, &cur_stats); if (ret != 0) { @@ -586,8 +588,7 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry->s.stats_type = STATS_ETHTOOL; } - ret = sock_stats_reset_fd(pktio_entry, - pktio_entry->s.pkt_sock_mmap.sockfd); + ret = sock_stats_reset_fd(pktio_entry, pkt_sock->sockfd); if (ret != 0) goto error; @@ -601,7 +602,8 @@ static int sock_mmap_open(odp_pktio_t id ODP_UNUSED, static int sock_mmap_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_packet_t pkt_table[], int len) { - pkt_sock_mmap_t *const pkt_sock = &pktio_entry->s.pkt_sock_mmap; + pktio_ops_socket_mmap_data_t + *const pkt_sock = &pktio_entry->ops_data(mmap); int ret; odp_ticketlock_lock(&pktio_entry->s.rxl); @@ -616,7 +618,8 @@ static int sock_mmap_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, const odp_packet_t pkt_table[], int len) { int ret; - pkt_sock_mmap_t *const pkt_sock = &pktio_entry->s.pkt_sock_mmap; + pktio_ops_socket_mmap_data_t + *const pkt_sock = &pktio_entry->ops_data(mmap); odp_ticketlock_lock(&pktio_entry->s.txl); ret = pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring, @@ -628,32 +631,32 @@ static int sock_mmap_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED, static uint32_t sock_mmap_mtu_get(pktio_entry_t *pktio_entry) { - return mtu_get_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + return mtu_get_fd(pktio_entry->ops_data(mmap).sockfd, pktio_entry->s.name); } static int sock_mmap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_entry->s.pkt_sock_mmap.if_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->ops_data(mmap).if_mac, ETH_ALEN); return ETH_ALEN; } static int sock_mmap_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - return promisc_mode_set_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + return promisc_mode_set_fd(pktio_entry->ops_data(mmap).sockfd, pktio_entry->s.name, enable); } static int sock_mmap_promisc_mode_get(pktio_entry_t *pktio_entry) { - return promisc_mode_get_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + return promisc_mode_get_fd(pktio_entry->ops_data(mmap).sockfd, pktio_entry->s.name); } static int sock_mmap_link_status(pktio_entry_t *pktio_entry) { - return link_status_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + return link_status_fd(pktio_entry->ops_data(mmap).sockfd, pktio_entry->s.name); } @@ -682,7 +685,7 @@ static int sock_mmap_stats(pktio_entry_t *pktio_entry, return sock_stats_fd(pktio_entry, stats, - pktio_entry->s.pkt_sock_mmap.sockfd); + pktio_entry->ops_data(mmap).sockfd); } static int sock_mmap_stats_reset(pktio_entry_t *pktio_entry) @@ -694,7 +697,7 @@ static int sock_mmap_stats_reset(pktio_entry_t *pktio_entry) } return sock_stats_reset_fd(pktio_entry, - pktio_entry->s.pkt_sock_mmap.sockfd); + pktio_entry->ops_data(mmap).sockfd); } static int sock_mmap_init_global(void) diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index bfe412390..a5c15e11e 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -40,7 +40,6 @@ #include #include -#include #include #include #include From patchwork Tue Sep 19 03:00:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112971 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4407130qgf; Mon, 18 Sep 2017 20:15:42 -0700 (PDT) X-Google-Smtp-Source: AOwi7QA8KCTWKf67mqBBZxaN3xsK09nsij0JdHa7D+CoFiRKuJvUVvb7RNv4Fetkn6EoLgzG0KrF X-Received: by 10.55.152.198 with SMTP id a189mr20833281qke.190.1505790942528; Mon, 18 Sep 2017 20:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505790942; cv=none; d=google.com; s=arc-20160816; b=vL3jcqs/diY5YXzIBD9Avhb+v+syLdJyRUUh/+azPXWCEe0wWVBTkqznSnfPUhBXOf vq1XDxkck7P6cRwWV1lR1PBDLcUNC+uvpU9KWFjHDrbf22ZfrYRIiYFTzfZtah+/G/JW fHkkFJ2CTdIJRG4r6X5ixsKMvRR79DsbrDGbpCvkgmamosaNvE9rNhGkBScfBICVjjaQ kIk6F8hyp487g4v1HIAcoWaN/zE4soFQTqDr6Wmz6eMVJToJl64B5OgeACqGoJLry//C STjta8zI15j4K50GiSvrbkYlvnZcsah1GMRqXfJDXYBBsPEnZzvKRXndG3vbBaYNT37P Z9oA== 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=VCCdw96I3nWpjgtnrf52FMcZXMFVtW4O6FuFBkolSck=; b=wPOIkK20afauXOGcmsRWkX7uHvPMOhJdr1wXeXeZKWSy7WxDEfWzDmNz3UGzdBjGmt L8s6xhk0DmqyYW8CFaA6I1Nk5wMLETA7Bxqk9kbtcomQJzrchpmsNdrLMPz6pA+uayHN 7NVahFd/mPrK+OHBdf+0rbmAcdm/K5QaAmuyFmdknNVU6TgPN3YqsL279qgfpMe/VoLg UoViZvZiPlP1J9UrPWhp6lxCirqVhIHt/NWlgUXHwVTRgWUt8lEDEI9eSFz5FYqlV8rW MC9m+spllL5Y5aq+1makIxeyP0KdnowXzk2ogFo/Ll/fkQuNeKKKAC/JI6tRbcQRyic+ 6oLw== 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 c3si1111486qtk.381.2017.09.18.20.15.42; Mon, 18 Sep 2017 20:15:42 -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 1E25662D19; Tue, 19 Sep 2017 03:15:42 +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 0234C62F1C; Tue, 19 Sep 2017 03:02:01 +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 DEC4F60D6B; Tue, 19 Sep 2017 03:01:31 +0000 (UTC) Received: from forward106p.mail.yandex.net (forward106p.mail.yandex.net [77.88.28.109]) by lists.linaro.org (Postfix) with ESMTPS id 6ECCB61E03 for ; Tue, 19 Sep 2017 03:00:41 +0000 (UTC) Received: from mxback6j.mail.yandex.net (mxback6j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10f]) by forward106p.mail.yandex.net (Yandex) with ESMTP id DBB8A2D81BBE for ; Tue, 19 Sep 2017 06:00:39 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback6j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id CIA2mVMU9T-0dx8uAOf; Tue, 19 Sep 2017 06:00:39 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0dRKUVow; Tue, 19 Sep 2017 06:00:39 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 19 Sep 2017 06:00:23 +0300 Message-Id: <1505790024-16070-10-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 9/10] linux-gen: pktio: tap: minor code refactory X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Rename implementation specific data structure and its dedicated header file to accommodate uniformed name scheme. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ platform/linux-generic/Makefile.am | 2 +- .../linux-generic/include/odp_packet_io_internal.h | 2 -- .../include/odp_pktio_ops_subsystem.h | 2 ++ .../{odp_packet_tap.h => odp_pktio_ops_tap.h} | 6 +++--- platform/linux-generic/pktio/tap.c | 22 +++++++++++----------- 5 files changed, 17 insertions(+), 17 deletions(-) rename platform/linux-generic/include/{odp_packet_tap.h => odp_pktio_ops_tap.h} (85%) diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index b3ee86c67..6261cf0a6 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -187,12 +187,12 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ ${srcdir}/include/odp_packet_dpdk.h \ - ${srcdir}/include/odp_packet_tap.h \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ ${srcdir}/include/odp_pktio_ops_pcap.h \ ${srcdir}/include/odp_pktio_ops_socket.h \ + ${srcdir}/include/odp_pktio_ops_tap.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index f58ef8721..7c2833fc6 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -31,7 +31,6 @@ extern "C" { #include #define PKTIO_MAX_QUEUES 64 -#include #include /* Forward declaration */ @@ -59,7 +58,6 @@ struct pktio_entry { odp_pktio_t handle; /**< pktio handle */ union { pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ - pkt_tap_t pkt_tap; /**< using TAP for IO */ }; enum { /* Not allocated */ diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 952d9be55..5c01e34f6 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -84,6 +84,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { #include #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -95,6 +96,7 @@ typedef union { pktio_ops_pcap_data_t pcap; pktio_ops_socket_data_t socket; pktio_ops_socket_mmap_data_t mmap; + pktio_ops_tap_data_t tap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/include/odp_packet_tap.h b/platform/linux-generic/include/odp_pktio_ops_tap.h similarity index 85% rename from platform/linux-generic/include/odp_packet_tap.h rename to platform/linux-generic/include/odp_pktio_ops_tap.h index a90bfbce0..e8e2e270e 100644 --- a/platform/linux-generic/include/odp_packet_tap.h +++ b/platform/linux-generic/include/odp_pktio_ops_tap.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_TAP_H_ -#define ODP_PACKET_TAP_H_ +#ifndef ODP_PACKET_OPS_TAP_H_ +#define ODP_PACKET_OPS_TAP_H_ #include @@ -16,6 +16,6 @@ typedef struct { unsigned char if_mac[ETH_ALEN]; /**< MAC address of pktio side (not a MAC address of kernel interface)*/ odp_pool_t pool; /**< pool to alloc packets from */ -} pkt_tap_t; +} pktio_ops_tap_data_t; #endif diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index a5c15e11e..090e51b66 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -63,7 +63,7 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, int fd, skfd, flags; uint32_t mtu; struct ifreq ifr; - pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + pktio_ops_tap_data_t *tap = &pktio_entry->ops_data(tap); if (strncmp(devname, "tap:", 4) != 0) return -1; @@ -163,7 +163,7 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, static int tap_pktio_close(pktio_entry_t *pktio_entry) { int ret = 0; - pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + pktio_ops_tap_data_t *tap = &pktio_entry->ops_data(tap); if (tap->fd != -1 && close(tap->fd) != 0) { __odp_errno = errno; @@ -190,13 +190,13 @@ static odp_packet_t pack_odp_pkt(pktio_entry_t *pktio_entry, const void *data, if (pktio_cls_enabled(pktio_entry)) { if (cls_classify_packet(pktio_entry, data, len, len, - &pktio_entry->s.pkt_tap.pool, + &pktio_entry->ops_data(tap).pool, &parsed_hdr)) { return ODP_PACKET_INVALID; } } - num = packet_alloc_multi(pktio_entry->s.pkt_tap.pool, len, &pkt, 1); + num = packet_alloc_multi(pktio_entry->ops_data(tap).pool, len, &pkt, 1); if (num != 1) return ODP_PACKET_INVALID; @@ -227,7 +227,7 @@ static int tap_pktio_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, ssize_t retval; int i; uint8_t buf[BUF_SIZE]; - pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + pktio_ops_tap_data_t *tap = &pktio_entry->ops_data(tap); odp_time_t ts_val; odp_time_t *ts = NULL; @@ -267,7 +267,7 @@ static int tap_pktio_send_lockless(pktio_entry_t *pktio_entry, int i, n; uint32_t pkt_len; uint8_t buf[BUF_SIZE]; - pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + pktio_ops_tap_data_t *tap = &pktio_entry->ops_data(tap); for (i = 0; i < len; i++) { pkt_len = odp_packet_len(pkts[i]); @@ -330,10 +330,10 @@ static uint32_t tap_mtu_get(pktio_entry_t *pktio_entry) { uint32_t ret; - ret = mtu_get_fd(pktio_entry->s.pkt_tap.skfd, + ret = mtu_get_fd(pktio_entry->ops_data(tap).skfd, pktio_entry->s.name + 4); if (ret > 0) - pktio_entry->s.pkt_tap.mtu = ret; + pktio_entry->ops_data(tap).mtu = ret; return ret; } @@ -341,19 +341,19 @@ static uint32_t tap_mtu_get(pktio_entry_t *pktio_entry) static int tap_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - return promisc_mode_set_fd(pktio_entry->s.pkt_tap.skfd, + return promisc_mode_set_fd(pktio_entry->ops_data(tap).skfd, pktio_entry->s.name + 4, enable); } static int tap_promisc_mode_get(pktio_entry_t *pktio_entry) { - return promisc_mode_get_fd(pktio_entry->s.pkt_tap.skfd, + return promisc_mode_get_fd(pktio_entry->ops_data(tap).skfd, pktio_entry->s.name + 4); } static int tap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_entry->s.pkt_tap.if_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->ops_data(tap).if_mac, ETH_ALEN); return ETH_ALEN; } From patchwork Tue Sep 19 03:00:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112972 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4407869qgf; Mon, 18 Sep 2017 20:16:48 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBZNW9GEr/n6x5fAJuWtCf169Q095am2v+g4fcpaXRIRa8Fe143u/KpphprziAmC8lXiSjn X-Received: by 10.36.214.130 with SMTP id o124mr406578itg.51.1505791008458; Mon, 18 Sep 2017 20:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505791008; cv=none; d=google.com; s=arc-20160816; b=nHpzIDQU48tA6bUWSFWIPAyYuS0PxT0TQq44ZhLpJNDH92NEzra6BNlCCvmYJ0CVx7 BT2HetLC9J3zkLVIi6RbMapbx+aID1oDPd4jt65eweMoKMwmbWtpQhZYMyRlri5xiyAi C4/vEnHwzsSiUW/i8emFxMmqM2iDq/O8SaJj1ICUmOeIkjZZjKbACwsRAQkzvsYNs+aO cDdH67YkDxJDY+ZitSr5QmoH50vwkcytAc2Rz4AaHzuZz4I16HuIRMz5gESb4R+lPCwG P9aX3CuPYQLGaQ+1Iifnc3n4hjgmIbR1iX1MlF5JohyTL8fjbq44mZk5g9WXSw2jqfLB diwA== 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=Zde70hyUDBFqAsxcuvDdUVdc2O8WxQASA9Tyi+09Gls=; b=dB/jAt/Nm6WEOCavJ5cc8cthW7fUuTBVoAwkZn4Im+q5xMhf7mM/kPVgFHJWRYZhZd OqLdkutRHQl2kwqUkYVurfOVDeMLwwxH7hjwn/7hG1YjJCtXCmbnwq/AJGngXSRa/c5V QgWROYvAxFoLB2tJzl/1NOKBh9PbWcXb7PrtFDewx9wh4iZpmyxjkLmWiHm/jo3RAymM QD1sCliwwYNzuBy4+ju2pD7yHhhWf9RRN1SZjGYG1JPICqy6Y0YKoeQufgp+CQUlD+aP 3VNDq2B+3RbYGVDnyyNOMidd+n643ZSFNi1cAr9DxhAtAWkdcetxrk21ClNZG9Uc+an3 hbJA== 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 74si7112996ioq.395.2017.09.18.20.16.47; Mon, 18 Sep 2017 20:16:48 -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 C77E362875; Tue, 19 Sep 2017 03:16:47 +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 52D1463574; Tue, 19 Sep 2017 03:02:11 +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 7DEC061E19; Tue, 19 Sep 2017 03:01:45 +0000 (UTC) Received: from forward101p.mail.yandex.net (forward101p.mail.yandex.net [77.88.28.101]) by lists.linaro.org (Postfix) with ESMTPS id DE4E661E19 for ; Tue, 19 Sep 2017 03:00:41 +0000 (UTC) Received: from mxback3g.mail.yandex.net (mxback3g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:164]) by forward101p.mail.yandex.net (Yandex) with ESMTP id AEE736A8265D for ; Tue, 19 Sep 2017 06:00:40 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback3g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id UXJccIvWvf-0ejma8Kj; Tue, 19 Sep 2017 06:00:40 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id X7vK4VOjbe-0dRiPeHj; Tue, 19 Sep 2017 06:00:39 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Tue, 19 Sep 2017 06:00:24 +0300 Message-Id: <1505790024-16070-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> References: <1505790024-16070-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v4 10/10] linux-gen: pktio: dpdk: minor code refactory X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Rename implementation specific data structure and move its dedicated header file to impl local, decouple it from pktio_entry_t data structure. Signed-off-by: Yi He Signed-off-by: Balakrishna Garapati Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: 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: 407fcfe1baad9b95b5374f13221abdf50b8d6089 **/ 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 9d32defd5..f0d731213 100644 --- a/platform/linux-dpdk/Makefile.am +++ b/platform/linux-dpdk/Makefile.am @@ -187,7 +187,7 @@ noinst_HEADERS = \ ${top_srcdir}/platform/linux-generic/include/odp_crypto_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_forward_typedefs_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_internal.h \ - ${srcdir}/include/odp_packet_dpdk.h \ + ${srcdir}/pktio/dpdk.h \ ${srcdir}/include/odp_packet_internal.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_ipc.h \ ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \ @@ -243,7 +243,7 @@ __LIB__libodp_dpdk_la_SOURCES = \ ../linux-generic/odp_ipsec.c \ ../linux-generic/odp_name_table.c \ odp_packet.c \ - odp_packet_dpdk.c \ + pktio/dpdk.c \ pktio/subsystem.c \ odp_packet_flags.c \ ../linux-generic/odp_packet_io.c \ diff --git a/platform/linux-dpdk/include/odp_packet_io_internal.h b/platform/linux-dpdk/include/odp_packet_io_internal.h index ba388c9c2..ec1d0c213 100644 --- a/platform/linux-dpdk/include/odp_packet_io_internal.h +++ b/platform/linux-dpdk/include/odp_packet_io_internal.h @@ -29,7 +29,7 @@ extern "C" { #define PKTIO_MAX_QUEUES 64 #include -#include +#include /* Forward declaration */ typedef union pktio_entry_u pktio_entry_t; @@ -40,26 +40,6 @@ typedef union pktio_entry_u pktio_entry_t; #define PKTIN_INVALID ((odp_pktin_queue_t) {ODP_PKTIO_INVALID, 0}) #define PKTOUT_INVALID ((odp_pktout_queue_t) {ODP_PKTIO_INVALID, 0}) -/* Forward declaration */ -struct pkt_dpdk_t; - -/** Packet socket using dpdk mmaped rings for both Rx and Tx */ -typedef struct { - odp_pktio_capability_t capa; /**< interface capabilities */ - - /********************************/ - char ifname[32]; - uint8_t min_rx_burst; - uint8_t portid; - odp_bool_t vdev_sysc_promisc; /**< promiscuous mode defined with - system call */ - odp_pktin_hash_proto_t hash; /**< Packet input hash protocol */ - odp_bool_t lockless_rx; /**< no locking for rx */ - odp_bool_t lockless_tx; /**< no locking for tx */ - odp_ticketlock_t rx_lock[PKTIO_MAX_QUEUES]; /**< RX queue locks */ - odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES]; /**< TX queue locks */ -} pkt_dpdk_t; - struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ pktio_ops_data_t ops_data; @@ -68,9 +48,6 @@ struct pktio_entry { odp_ticketlock_t txl; /**< TX ticketlock */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ - union { - pkt_dpdk_t pkt_dpdk; /**< using DPDK API for IO */ - }; enum { /* Not allocated */ PKTIO_STATE_FREE = 0, diff --git a/platform/linux-dpdk/odp_init.c b/platform/linux-dpdk/odp_init.c index cd7abce65..0a6eb4695 100644 --- a/platform/linux-dpdk/odp_init.c +++ b/platform/linux-dpdk/odp_init.c @@ -5,13 +5,13 @@ */ #include -#include #include #include #include #include #include #include +#include #include #include #include diff --git a/platform/linux-dpdk/odp_packet_dpdk.c b/platform/linux-dpdk/pktio/dpdk.c similarity index 86% rename from platform/linux-dpdk/odp_packet_dpdk.c rename to platform/linux-dpdk/pktio/dpdk.c index 214116b76..0dda05a69 100644 --- a/platform/linux-dpdk/odp_packet_dpdk.c +++ b/platform/linux-dpdk/pktio/dpdk.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -39,6 +39,18 @@ static pktio_ops_module_t dpdk_pktio_ops; static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry); +static inline pktio_ops_dpdk_data_t * + __retrieve_op_data(pktio_entry_t *pktio) +{ + return (pktio_ops_dpdk_data_t *)(pktio->ops_data(dpdk)); +} + +static inline void __release_op_data(pktio_entry_t *pktio) +{ + free(pktio->ops_data(dpdk)); + pktio->ops_data(dpdk) = NULL; +} + /* Test if s has only digits or not. Dpdk pktio uses only digits.*/ static int _dpdk_netdev_is_valid(const char *s) { @@ -95,6 +107,8 @@ static void _dpdk_print_port_mac(uint8_t portid) static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, const odp_pktin_queue_param_t *p) { + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_pktin_mode_t mode = pktio_entry->s.param.in_mode; /** @@ -102,19 +116,19 @@ static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, * at a time polls a queue */ if (mode == ODP_PKTIN_MODE_SCHED || p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) - pktio_entry->s.pkt_dpdk.lockless_rx = 1; + pkt_dpdk->lockless_rx = 1; else - pktio_entry->s.pkt_dpdk.lockless_rx = 0; + pkt_dpdk->lockless_rx = 0; if (p->hash_enable && p->num_queues > 1) { - pktio_entry->s.pkt_dpdk.hash = p->hash_proto; + pkt_dpdk->hash = p->hash_proto; } else { - pktio_entry->s.pkt_dpdk.hash.proto.ipv4_udp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv4_tcp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv4 = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6_udp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6_tcp = 1; - pktio_entry->s.pkt_dpdk.hash.proto.ipv6 = 1; + pkt_dpdk->hash.proto.ipv4_udp = 1; + pkt_dpdk->hash.proto.ipv4_tcp = 1; + pkt_dpdk->hash.proto.ipv4 = 1; + pkt_dpdk->hash.proto.ipv6_udp = 1; + pkt_dpdk->hash.proto.ipv6_tcp = 1; + pkt_dpdk->hash.proto.ipv6 = 1; } return 0; @@ -123,7 +137,8 @@ static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, static int output_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, const odp_pktout_queue_param_t *p) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) pkt_dpdk->lockless_tx = 1; @@ -133,12 +148,14 @@ static int output_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry, return 0; } -static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_entry, - const char *netdev, odp_pool_t pool ODP_UNUSED) +static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, + pktio_entry_t *pktio_entry, + const char *netdev, + odp_pool_t pool ODP_UNUSED) { uint8_t portid = 0; struct rte_eth_dev_info dev_info; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = NULL; int i; if (!_dpdk_netdev_is_valid(netdev)) { @@ -147,6 +164,14 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_ent return -1; } + pktio_entry->ops_data(dpdk) = malloc(sizeof(pktio_ops_dpdk_data_t)); + pkt_dpdk = __retrieve_op_data(pktio_entry); + + if (odp_unlikely(pkt_dpdk == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct"); + return -1; + } + portid = atoi(netdev); pkt_dpdk->portid = portid; memset(&dev_info, 0, sizeof(struct rte_eth_dev_info)); @@ -176,17 +201,21 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_ent static int close_pkt_dpdk(pktio_entry_t *pktio_entry) { - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (pktio_entry->s.state == PKTIO_STATE_STOPPED) rte_eth_dev_close(pkt_dpdk->portid); + + __release_op_data(pktio_entry); return 0; } static int start_pkt_dpdk(pktio_entry_t *pktio_entry) { int ret, i; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint8_t portid = pkt_dpdk->portid; int sid = rte_eth_dev_socket_id(pkt_dpdk->portid); int socket_id = sid < 0 ? 0 : sid; @@ -294,7 +323,9 @@ static int start_pkt_dpdk(pktio_entry_t *pktio_entry) static int stop_pkt_dpdk(pktio_entry_t *pktio_entry) { - rte_eth_dev_stop(pktio_entry->s.pkt_dpdk.portid); + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_dev_stop(pkt_dpdk->portid); return 0; } @@ -335,16 +366,15 @@ static void _odp_pktio_send_completion(pktio_entry_t *pktio_entry) odp_ticketlock_unlock(&entry->s.txl); } } - - return; } static int recv_pkt_dpdk(pktio_entry_t *pktio_entry, int index, odp_packet_t pkt_table[], int len) { uint16_t nb_rx, i; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_packet_t *saved_pkt_table; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; uint8_t min = pkt_dpdk->min_rx_burst; odp_time_t ts_val; odp_time_t *ts = NULL; @@ -459,7 +489,8 @@ static int send_pkt_dpdk(pktio_entry_t *pktio_entry, int index, const odp_packet_t pkt_table[], int len) { int pkts; - pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); if (!pkt_dpdk->lockless_tx) odp_ticketlock_lock(&pkt_dpdk->tx_lock[index]); @@ -511,10 +542,12 @@ static uint32_t _dpdk_vdev_mtu(uint8_t port_id) static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry) { + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint16_t mtu = 0; int ret; - ret = rte_eth_dev_get_mtu(pktio_entry->s.pkt_dpdk.portid, &mtu); + ret = rte_eth_dev_get_mtu(pkt_dpdk->portid, &mtu); if (ret < 0) return 0; @@ -522,7 +555,7 @@ static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry) * try to use system call if dpdk cannot get mtu value. */ if (mtu == 0) - mtu = _dpdk_vdev_mtu(pktio_entry->s.pkt_dpdk.portid); + mtu = _dpdk_vdev_mtu(pkt_dpdk->portid); return mtu; } @@ -570,13 +603,16 @@ static int _dpdk_vdev_promisc_mode_set(uint8_t port_id, int enable) static int promisc_mode_set_pkt_dpdk(pktio_entry_t *pktio_entry, int enable) { - uint8_t portid = pktio_entry->s.pkt_dpdk.portid; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + uint8_t portid = pkt_dpdk->portid; + if (enable) rte_eth_promiscuous_enable(portid); else rte_eth_promiscuous_disable(portid); - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) { + if (pkt_dpdk->vdev_sysc_promisc) { int ret = _dpdk_vdev_promisc_mode_set(portid, enable); if (ret < 0) ODP_DBG("vdev promisc mode fail\n"); @@ -605,23 +641,27 @@ static int _dpdk_vdev_promisc_mode(uint8_t port_id) if (ifr.ifr_flags & IFF_PROMISC) { ODP_DBG("promisc is 1\n"); return 1; - } else - return 0; + } + return 0; } static int promisc_mode_get_pkt_dpdk(pktio_entry_t *pktio_entry) { - uint8_t portid = pktio_entry->s.pkt_dpdk.portid; - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + uint8_t portid = pkt_dpdk->portid; + + if (pkt_dpdk->vdev_sysc_promisc) return _dpdk_vdev_promisc_mode(portid); else return rte_eth_promiscuous_get(portid); - } static int mac_get_pkt_dpdk(pktio_entry_t *pktio_entry, void *mac_addr) { - rte_eth_macaddr_get(pktio_entry->s.pkt_dpdk.portid, + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_macaddr_get(pkt_dpdk->portid, (struct ether_addr *)mac_addr); return ETH_ALEN; } @@ -630,14 +670,18 @@ static int mac_get_pkt_dpdk(pktio_entry_t *pktio_entry, void *mac_addr) static int capability_pkt_dpdk(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa) { - *capa = pktio_entry->s.pkt_dpdk.capa; + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + *capa = pkt_dpdk->capa; return 0; } static int link_status_pkt_dpdk(pktio_entry_t *pktio_entry) { + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); struct rte_eth_link link; - rte_eth_link_get(pktio_entry->s.pkt_dpdk.portid, &link); + rte_eth_link_get(pkt_dpdk->portid, &link); return link.link_status; } @@ -657,25 +701,28 @@ static void stats_convert(struct rte_eth_stats *rte_stats, static int stats_pkt_dpdk(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats) { + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); int ret; struct rte_eth_stats rte_stats; - ret = rte_eth_stats_get(pktio_entry->s.pkt_dpdk.portid, &rte_stats); + ret = rte_eth_stats_get(pkt_dpdk->portid, &rte_stats); if (ret == 0) { stats_convert(&rte_stats, stats); return 0; - } else { - if (ret > 0) - return -ret; - else - return ret; } + + if (ret > 0) + return -ret; + return ret; } static int stats_reset_pkt_dpdk(pktio_entry_t *pktio_entry) { - rte_eth_stats_reset(pktio_entry->s.pkt_dpdk.portid); + const pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); + rte_eth_stats_reset(pkt_dpdk->portid); return 0; } diff --git a/platform/linux-dpdk/include/odp_packet_dpdk.h b/platform/linux-dpdk/pktio/dpdk.h similarity index 59% rename from platform/linux-dpdk/include/odp_packet_dpdk.h rename to platform/linux-dpdk/pktio/dpdk.h index 495d5e6f1..064c5d8ce 100644 --- a/platform/linux-dpdk/include/odp_packet_dpdk.h +++ b/platform/linux-dpdk/pktio/dpdk.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_DPDK_H -#define ODP_PACKET_DPDK_H +#ifndef ODP_PKTIO_OPS_DPDK_H_ +#define ODP_PKTIO_OPS_DPDK_H_ #include #include @@ -46,4 +46,21 @@ #define RTE_TEST_RX_DESC_DEFAULT 128 #define RTE_TEST_TX_DESC_DEFAULT 512 +/** Packet socket using dpdk mmaped rings for both Rx and Tx */ +typedef struct { + odp_pktio_capability_t capa; /**< interface capabilities */ + + /********************************/ + char ifname[32]; + uint8_t min_rx_burst; + uint8_t portid; + odp_bool_t vdev_sysc_promisc; /**< promiscuous mode defined with + system call */ + odp_pktin_hash_proto_t hash; /**< Packet input hash protocol */ + odp_bool_t lockless_rx; /**< no locking for rx */ + odp_bool_t lockless_tx; /**< no locking for tx */ + odp_ticketlock_t rx_lock[PKTIO_MAX_QUEUES]; /**< RX queue locks */ + odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES]; /**< TX queue locks */ +} pktio_ops_dpdk_data_t; + #endif diff --git a/platform/linux-dpdk/pool/dpdk.c b/platform/linux-dpdk/pool/dpdk.c index 499bea127..0e1dfde70 100644 --- a/platform/linux-dpdk/pool/dpdk.c +++ b/platform/linux-dpdk/pool/dpdk.c @@ -26,7 +26,7 @@ #include /* for DPDK */ -#include +#include #ifdef POOL_USE_TICKETLOCK #include diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 6261cf0a6..5503535e4 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -186,7 +186,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_ring_internal.h \ - ${srcdir}/include/odp_packet_dpdk.h \ + ${srcdir}/pktio/dpdk.h \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ @@ -267,7 +267,7 @@ __LIB__libodp_linux_la_SOURCES = \ pktio/ethtool.c \ pktio/subsystem.c \ pktio/ipc.c \ - pktio/pktio_common.c \ + pktio/common.c \ pktio/loopback.c \ pktio/netmap.c \ pktio/dpdk.c \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 7c2833fc6..9fe9aeaa7 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -31,8 +31,6 @@ extern "C" { #include #define PKTIO_MAX_QUEUES 64 -#include - /* Forward declaration */ typedef union pktio_entry_u pktio_entry_t; #include @@ -56,9 +54,6 @@ struct pktio_entry { odp_ticketlock_t txl; /**< TX ticketlock */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ - union { - pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ - }; enum { /* Not allocated */ PKTIO_STATE_FREE = 0, diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index 5c01e34f6..7a915b82c 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -90,6 +90,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { * TODO: refactory each implementation to hide it internally */ typedef union { + void *dpdk; pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; pktio_ops_netmap_data_t netmap; diff --git a/platform/linux-generic/pktio/pktio_common.c b/platform/linux-generic/pktio/common.c similarity index 100% rename from platform/linux-generic/pktio/pktio_common.c rename to platform/linux-generic/pktio/common.c diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index e72a76371..511c77783 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -20,9 +20,9 @@ #include #include -#include #include +#include #include #include @@ -32,6 +32,18 @@ #include #include +static inline pktio_ops_dpdk_data_t * + __retrieve_op_data(pktio_entry_t *pktio) +{ + return (pktio_ops_dpdk_data_t *)(pktio->ops_data(dpdk)); +} + +static inline void __release_op_data(pktio_entry_t *pktio) +{ + free(pktio->ops_data(dpdk)); + pktio->ops_data(dpdk) = NULL; +} + #if ODP_DPDK_ZERO_COPY ODP_STATIC_ASSERT(CONFIG_PACKET_HEADROOM == RTE_PKTMBUF_HEADROOM, "ODP and DPDK headroom sizes not matching!"); @@ -310,10 +322,10 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, int i, j; int nb_pkts = 0; int alloc_len, num; - odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool; + odp_pool_t pool = __retrieve_op_data(pktio_entry)->pool; /* Allocate maximum sized packets */ - alloc_len = pktio_entry->s.pkt_dpdk.data_room; + alloc_len = __retrieve_op_data(pktio_entry)->data_room; num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num); if (num != mbuf_num) { @@ -385,7 +397,8 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry, struct rte_mbuf *mbuf_table[], const odp_packet_t pkt_table[], uint16_t num) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); int i, j; char *data; uint16_t pkt_len; @@ -430,7 +443,7 @@ static inline int mbuf_to_pkt_zero(pktio_entry_t *pktio_entry, void *data; int i; int nb_pkts = 0; - odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool; + odp_pool_t pool = __retrieve_op_data(pktio_entry)->pool; for (i = 0; i < mbuf_num; i++) { odp_packet_hdr_t parsed_hdr; @@ -487,7 +500,8 @@ static inline int pkt_to_mbuf_zero(pktio_entry_t *pktio_entry, const odp_packet_t pkt_table[], uint16_t num, uint16_t *seg_count) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); int i; *seg_count = 0; @@ -562,7 +576,8 @@ static uint32_t dpdk_vdev_mtu_get(uint8_t port_id) static uint32_t dpdk_mtu_get(pktio_entry_t *pktio_entry) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint32_t mtu = 0; if (rte_eth_dev_get_mtu(pkt_dpdk->port_id, (uint16_t *)&mtu)) @@ -655,7 +670,8 @@ static void rss_conf_to_hash_proto(struct rte_eth_rss_conf *rss_conf, static int dpdk_setup_port(pktio_entry_t *pktio_entry) { int ret; - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); struct rte_eth_rss_conf rss_conf; /* Always set some hash functions to enable DPDK RSS hash calculation */ @@ -697,7 +713,8 @@ static int dpdk_setup_port(pktio_entry_t *pktio_entry) static int dpdk_close(pktio_entry_t *pktio_entry) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); unsigned idx; unsigned i, j; @@ -715,6 +732,7 @@ static int dpdk_close(pktio_entry_t *pktio_entry) if (!ODP_DPDK_ZERO_COPY) rte_mempool_free(pkt_dpdk->pkt_pool); + __release_op_data(pktio_entry); return 0; } @@ -860,9 +878,9 @@ static int dpdk_input_queues_config(pktio_entry_t *pktio_entry, lockless = 0; if (p->hash_enable && p->num_queues > 1) - pktio_entry->s.pkt_dpdk.hash = p->hash_proto; + __retrieve_op_data(pktio_entry)->hash = p->hash_proto; - pktio_entry->s.pkt_dpdk.lockless_rx = lockless; + __retrieve_op_data(pktio_entry)->lockless_rx = lockless; return 0; } @@ -870,7 +888,8 @@ static int dpdk_input_queues_config(pktio_entry_t *pktio_entry, static int dpdk_output_queues_config(pktio_entry_t *pktio_entry, const odp_pktout_queue_param_t *p) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_bool_t lockless; if (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE) @@ -886,7 +905,8 @@ static int dpdk_output_queues_config(pktio_entry_t *pktio_entry, static void dpdk_init_capability(pktio_entry_t *pktio_entry, struct rte_eth_dev_info *dev_info) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); odp_pktio_capability_t *capa = &pkt_dpdk->capa; memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); @@ -909,7 +929,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, const char *netdev, odp_pool_t pool) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = NULL; struct rte_eth_dev_info dev_info; struct rte_mempool *pkt_pool; char pool_name[RTE_MEMPOOL_NAMESIZE]; @@ -937,6 +957,14 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, dpdk_initialized = 1; } + pktio_entry->ops_data(dpdk) = malloc(sizeof(pktio_ops_dpdk_data_t)); + pkt_dpdk = __retrieve_op_data(pktio_entry); + + if (odp_unlikely(pkt_dpdk == NULL)) { + ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct"); + return -1; + } + /* Init pktio entry */ memset(pkt_dpdk, 0, sizeof(*pkt_dpdk)); @@ -945,6 +973,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, if (rte_eth_dev_count() == 0) { ODP_ERR("No DPDK ports found\n"); + __release_op_data(pktio_entry); return -1; } @@ -953,6 +982,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, mtu = dpdk_mtu_get(pktio_entry); if (mtu == 0) { ODP_ERR("Failed to read interface MTU\n"); + __release_op_data(pktio_entry); return -1; } pkt_dpdk->mtu = mtu + _ODP_ETHHDR_LEN; @@ -989,6 +1019,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, } if (pkt_pool == NULL) { ODP_ERR("Cannot init mbuf packet pool\n"); + __release_op_data(pktio_entry); return -1; } @@ -1013,7 +1044,8 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED, static int dpdk_start(pktio_entry_t *pktio_entry) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint8_t port_id = pkt_dpdk->port_id; int ret; unsigned i; @@ -1064,7 +1096,7 @@ static int dpdk_start(pktio_entry_t *pktio_entry) static int dpdk_stop(pktio_entry_t *pktio_entry) { - rte_eth_dev_stop(pktio_entry->s.pkt_dpdk.port_id); + rte_eth_dev_stop(__retrieve_op_data(pktio_entry)->port_id); return 0; } @@ -1072,7 +1104,8 @@ static int dpdk_stop(pktio_entry_t *pktio_entry) static int dpdk_recv(pktio_entry_t *pktio_entry, int index, odp_packet_t pkt_table[], int num) { - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); pkt_cache_t *rx_cache = &pkt_dpdk->rx_cache[index]; odp_time_t ts_val; odp_time_t *ts = NULL; @@ -1104,7 +1137,7 @@ static int dpdk_recv(pktio_entry_t *pktio_entry, int index, } else if ((unsigned)num < pkt_dpdk->min_rx_burst) { struct rte_mbuf *new_mbufs[pkt_dpdk->min_rx_burst]; - nb_rx = rte_eth_rx_burst(pktio_entry->s.pkt_dpdk.port_id, index, + nb_rx = rte_eth_rx_burst(pkt_dpdk->port_id, index, new_mbufs, pkt_dpdk->min_rx_burst); rx_cache->s.idx = 0; for (i = 0; i < nb_rx; i++) { @@ -1119,7 +1152,7 @@ static int dpdk_recv(pktio_entry_t *pktio_entry, int index, nb_rx = RTE_MIN(num, nb_rx); } else { - nb_rx = rte_eth_rx_burst(pktio_entry->s.pkt_dpdk.port_id, index, + nb_rx = rte_eth_rx_burst(pkt_dpdk->port_id, index, rx_mbufs, num); } @@ -1147,7 +1180,8 @@ static int dpdk_send(pktio_entry_t *pktio_entry, int index, const odp_packet_t pkt_table[], int num) { struct rte_mbuf *tx_mbufs[num]; - pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk; + pktio_ops_dpdk_data_t *pkt_dpdk = + __retrieve_op_data(pktio_entry); uint16_t seg_count = 0; int tx_pkts; int i; @@ -1210,16 +1244,16 @@ static int dpdk_send(pktio_entry_t *pktio_entry, int index, static int dpdk_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - rte_eth_macaddr_get(pktio_entry->s.pkt_dpdk.port_id, + rte_eth_macaddr_get(__retrieve_op_data(pktio_entry)->port_id, (struct ether_addr *)mac_addr); return ETH_ALEN; } static int dpdk_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) { - uint8_t port_id = pktio_entry->s.pkt_dpdk.port_id; + uint8_t port_id = __retrieve_op_data(pktio_entry)->port_id; - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) + if (__retrieve_op_data(pktio_entry)->vdev_sysc_promisc) return dpdk_vdev_promisc_mode_set(port_id, enable); if (enable) @@ -1232,9 +1266,9 @@ static int dpdk_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable) static int dpdk_promisc_mode_get(pktio_entry_t *pktio_entry) { - uint8_t port_id = pktio_entry->s.pkt_dpdk.port_id; + uint8_t port_id = __retrieve_op_data(pktio_entry)->port_id; - if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) + if (__retrieve_op_data(pktio_entry)->vdev_sysc_promisc) return dpdk_vdev_promisc_mode_get(port_id); else return rte_eth_promiscuous_get(port_id); @@ -1243,7 +1277,7 @@ static int dpdk_promisc_mode_get(pktio_entry_t *pktio_entry) static int dpdk_capability(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa) { - *capa = pktio_entry->s.pkt_dpdk.capa; + *capa = __retrieve_op_data(pktio_entry)->capa; return 0; } @@ -1253,7 +1287,8 @@ static int dpdk_link_status(pktio_entry_t *pktio_entry) memset(&link, 0, sizeof(struct rte_eth_link)); - rte_eth_link_get_nowait(pktio_entry->s.pkt_dpdk.port_id, &link); + rte_eth_link_get_nowait( + __retrieve_op_data(pktio_entry)->port_id, &link); return link.link_status; } @@ -1275,7 +1310,8 @@ static int dpdk_stats(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats) int ret; struct rte_eth_stats rte_stats; - ret = rte_eth_stats_get(pktio_entry->s.pkt_dpdk.port_id, &rte_stats); + ret = rte_eth_stats_get( + __retrieve_op_data(pktio_entry)->port_id, &rte_stats); if (ret == 0) { stats_convert(&rte_stats, stats); @@ -1286,7 +1322,7 @@ static int dpdk_stats(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats) static int dpdk_stats_reset(pktio_entry_t *pktio_entry) { - rte_eth_stats_reset(pktio_entry->s.pkt_dpdk.port_id); + rte_eth_stats_reset(__retrieve_op_data(pktio_entry)->port_id); return 0; } diff --git a/platform/linux-generic/include/odp_packet_dpdk.h b/platform/linux-generic/pktio/dpdk.h similarity index 96% rename from platform/linux-generic/include/odp_packet_dpdk.h rename to platform/linux-generic/pktio/dpdk.h index 5d80d84a3..7495b5965 100644 --- a/platform/linux-generic/include/odp_packet_dpdk.h +++ b/platform/linux-generic/pktio/dpdk.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef ODP_PACKET_DPDK_H -#define ODP_PACKET_DPDK_H +#ifndef ODP_PKTIO_OPS_DPDK_H_ +#define ODP_PKTIO_OPS_DPDK_H_ #include #include @@ -63,6 +63,6 @@ typedef struct { odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES]; /**< TX queue locks */ /** cache for storing extra RX packets */ pkt_cache_t rx_cache[PKTIO_MAX_QUEUES]; -} pkt_dpdk_t; +} pktio_ops_dpdk_data_t; #endif