From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 98FB4A0A0A; Tue, 23 Mar 2021 20:07:53 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53C674014D; Tue, 23 Mar 2021 20:07:53 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 51D6540143 for ; Tue, 23 Mar 2021 20:07:51 +0100 (CET) IronPort-SDR: Vjp31+JCCqSYxM/DIPrdKDE2unjpWkny9Cca14LQA32aOLNI/QJM9IEOyUq8v2Ez/5p6ZI7Wc7 40oRZl5GqPJw== X-IronPort-AV: E=McAfee;i="6000,8403,9932"; a="190645183" X-IronPort-AV: E=Sophos;i="5.81,272,1610438400"; d="scan'208";a="190645183" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2021 12:07:50 -0700 IronPort-SDR: qeRqS4G94YF6gV8v+vMAkk7Qy3Rqdeapuezac7ExdPmaU29OyvP9Hj8UemS+DO21AtbFG1qwWd rG4pw2m9br0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,272,1610438400"; d="scan'208";a="415123373" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga008.jf.intel.com with ESMTP; 23 Mar 2021 12:07:50 -0700 Received: from fmsmsx608.amr.corp.intel.com (10.18.126.88) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Tue, 23 Mar 2021 12:07:49 -0700 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx608.amr.corp.intel.com (10.18.126.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Tue, 23 Mar 2021 12:07:49 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2 via Frontend Transport; Tue, 23 Mar 2021 12:07:49 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.170) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2106.2; Tue, 23 Mar 2021 12:07:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E1KCZ5JUCggkaGZsBnlHP5phck/JqNZK8y/gvKNzxY3zPzFdSzvA5cvmKBmqVVQYxFr0rJ6M6KZ54Sb3/16QiJcQmpSWPlDj8WN0296AClNCQR/HqUBP9FU93kPyvNVs8+7OsLEh3KC1F7FwQwj8GMLm1uC7NgswmalP7Pnxm38Xv/6p2tf74gGQf4RGjvNZQ2i4Mg4U5KE2Lr0YyfnCvDalJAt8A8NXCUCG+20MOuUDr9pD707NMH+mtQihvElW3PqfmvMpLHiG8Nak3Uz2GYfj4jU/5hV5pkxnFxtWUP/U+ArZgSPLk3XPf5mYuUv5rh+gVaAYr3TO5TDQ8KMDbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NtaaPf3niMQCt7eawzYQhD/nUadiZc01tvOSargw2cY=; b=kn2uwPLUXbzakTa7JFc+PVPEwJMRFffPNHoPCtFzdWTqvANj6htQZR6GbvhNVU6787T7FWAl8vqJTUOZLe9m41LJE76YaFEfu6C3LxmDyAqCMO/kw6g3CmxvaVd+soPy08Na2vFVVQmYRv9PErrRcVMaN2zRXFDI//GB3KSnMBjHNMkaSYzCGvxxYn7kss/cc81rt8Z5YA5Wwya6wr4nAzmBHGeW0RtLAk60i+zhCDGKiGuvhyb/LLxWluU77pdqD23uPWgBpeMTeEkAmwSKVBFBHpsj9A7007SwjeS8RggFYfnBWork+d3EcT9DEOO64dOE6C7aHiAqX6d6IH02KQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NtaaPf3niMQCt7eawzYQhD/nUadiZc01tvOSargw2cY=; b=emSd8SW17J+sCZ9AVFSWLp1Nxz5PrGO+8Kp3L1m1dtt52O81QF8CxRsdjPYfrPykORY6ah9yXu4Q9UT9x815DI3a3nWtSouuLt9Al/HQWX/JpqxgWoqp4Z1Pzgb+AwXhlFfGyBR9PgdojI4CtE6Uu29TSdpc8T1RexpbjY+xHrQ= Received: from BYAPR11MB3077.namprd11.prod.outlook.com (2603:10b6:a03:90::14) by BYAPR11MB3288.namprd11.prod.outlook.com (2603:10b6:a03:7e::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.23; Tue, 23 Mar 2021 19:07:47 +0000 Received: from BYAPR11MB3077.namprd11.prod.outlook.com ([fe80::6cc9:d566:d792:5ab2]) by BYAPR11MB3077.namprd11.prod.outlook.com ([fe80::6cc9:d566:d792:5ab2%5]) with mapi id 15.20.3955.027; Tue, 23 Mar 2021 19:07:47 +0000 From: "P, Venkata Suresh Kumar" To: "dev@dpdk.org" CC: "Dumitrescu, Cristian" , "Khangar, Churchill" , "Jangra, Yogesh" Thread-Topic: [PATCH v3] port: add file descriptor SWX port Thread-Index: AQHXIBbi49xhHxiDlEeKhSxsI6DNdKqR7n/g Date: Tue, 23 Mar 2021 19:07:47 +0000 Message-ID: References: <1616526221-48927-1-git-send-email-venkata.suresh.kumar.p@intel.com> In-Reply-To: <1616526221-48927-1-git-send-email-venkata.suresh.kumar.p@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-reaction: no-action dlp-product: dlpe-windows authentication-results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=intel.com; x-originating-ip: [123.201.249.98] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 35c9d8ec-9c4d-482b-b9f2-08d8ee2ef238 x-ms-traffictypediagnostic: BYAPR11MB3288: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:275; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: O9m5lKkQo+nQ0xEeL54G4ffUPQfB/jP1QEFZf6o0B2yamRgIOZWJly/tuZ5+B4PW9JkOgieZivkcIfMbE4/qLfN0k7YtPJAzTtkjGxXpsj0rJ8UQavEjASu6jde7xFf8qKHUGGvpQZnfOxnqj84ZwralC55Obeogu930iYaV1iPgZqgU9UZeyY3TgllDkoRuZ/HOct8PML3iFTPADjZAikzqgWvc8eWuBoIOG6AfAf3uhxA7GxoxL63umxSK1QxzrgBSI9tVckIfmWR4PcsR5zRED5du1n5moOfHGwg9i/GoF79pYNP3P6zhf31CvHZAHn/Z1W1oJNrCRddy07Kdx2N3e01cn4mlOrVSYDfaOOpZPhv5jesdzN4jUEJJEAFaVM3idsm+/w/yUtnY6wxqr+Dc7g6HHOFS7PEvNiV8mK1VORPnzZm6y15akHBy7834GBhxZ5WEkRZZKFrfHa9qTIIdtWVpkOVbJXmwg8W+kPmxMa3OU4458e6x2sh+PIzaOdq3OWQZh8P11/8daBvgK7sI5pHm9QVDZOw2TicBHnPERHJtZRTKfn7KI6uZecnVS8hlXFuPA9fcjNsVjP4fy2WHxJWk7xXvPOBDIpzSsIyxcwY3ty/9chlqYznZSutPsr8xA9Qc7M7ox2Bviahu9DhNukQLHsdEMpko1yHbelE= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB3077.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(136003)(376002)(396003)(39860400002)(346002)(66946007)(38100700001)(9686003)(64756008)(76116006)(6916009)(316002)(66556008)(66476007)(66446008)(55016002)(30864003)(83380400001)(2906002)(71200400001)(33656002)(4326008)(107886003)(86362001)(478600001)(6506007)(7696005)(52536014)(5660300002)(8936002)(53546011)(26005)(186003)(8676002)(54906003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?W9f9yLyHHKrcfz9GZ/hZJl9Qxdkyct3j343htI5SQV3rRsvwyn9WWRa/cKyn?= =?us-ascii?Q?FC97K3bUnTBw+nrQ2vEA69poOsaatTx7WyUSZrArE69FxWLlx98LoGgUyUgI?= =?us-ascii?Q?ITgBfUHltjcALKONY+Mou8ePgu621oMfmy2Sbmjdca82cu/aORvp3AdJmZLr?= =?us-ascii?Q?JNOEwMavuAMA0usWnMf9dQTeNN4GGOGP7xQbr7uJqjw4Beq3hZ2Nv2lG8/MQ?= =?us-ascii?Q?6qNDDpCHFNdz/1d8DVuSZp8g8KnfUsZXKDz5HcVM7MAqT/0K5KJSRxVLpA/x?= =?us-ascii?Q?ISmQd2min/cwZ3j1jadWOn3pLQK3ml5boLRCO5mcioDy6noHQ2bkdZn+PPKh?= =?us-ascii?Q?Y5acFSia1DiZPh+1CuiVLb/+5MnQQDSdTjOGz/Ak6P4pBtReOnez/cwqyYcb?= =?us-ascii?Q?E90LbJO+6CKOOEe5cIbAcvXJYd3D1xhkZJlT0zuby1sKkDIdeKRShajr6x8A?= =?us-ascii?Q?MhPigMD2ipckaFciqQEn7uUINjhn34u/WaP0sDTYXOqIKwFi2phtqO8l8nXO?= =?us-ascii?Q?kN2GYtYzKGKvfVXsEPdqB7Gnoq5tjubAN/ccByRwE62jMjhOYDahNza2F7Cm?= =?us-ascii?Q?CjY3OR49FeHFFQikGHsJmbdMpemh8vI0SAG/ozhME3x/WU14Kc95OAoKMXtA?= =?us-ascii?Q?SbzQQk6/TmanaF3DXTc/hNFNKHMo6luSXIr+5195IkrkTDsB2qtV99Wrp51X?= =?us-ascii?Q?lPbKq6+NgpTfdJf7B8OuQc1o6CwO3LtyvYowuz55My1MUzts6msB2+S2ZZ3u?= =?us-ascii?Q?RWFzuUpNjWFHxbIBbArzhfUjuMMBI7yMYogMQQBTpQISUWRh6mpa+8Bi+TWa?= =?us-ascii?Q?vgeVHU6ufGV/vBUi+BVLpmbL5gjoB7Uxq5OWjT46JWMQSb3R06vwKXIFhU+D?= =?us-ascii?Q?wZcUMR+/l5o4AnCyzx5FN3TiGFZPseLZfwxatZYrgg4O2WIm6mk29IR9lEjJ?= =?us-ascii?Q?2T7ImdMqrhUSckuawe0naYtCc/9xUXIO8VjVXc6xq2bUdBqrTFm9p+pe3mR7?= =?us-ascii?Q?3zFh3PlbL5PZepxMHlm0GJi4q5voKthOozmDvw7S+Zilu23wGqoaFn3rh1GS?= =?us-ascii?Q?z3z3iY8wAXBLKwRSQCaEbkfTgw6PmrSMu67AIrdruMmMMwGKW1AvSaeh3j2v?= =?us-ascii?Q?cWwTJN9aYmn+Vu8zoayF6gV3h5YbND34QYIqyDkrz4L9xxk7mAsl5QuaSHQY?= =?us-ascii?Q?J/nceZQDQ0Elp4hd920PBEisQx7jezsdidyZDIi4uzo6N0WeqLcmVIQ7Rxnp?= =?us-ascii?Q?u1nRb1Qsn16jNoAwc1cyGaigE5lRZWr+eVAtAEhvD9X6Qa6fe9pukf7p8Lu6?= =?us-ascii?Q?H54ViXXepw4ZpOHHv+oaJwFl?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3077.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35c9d8ec-9c4d-482b-b9f2-08d8ee2ef238 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Mar 2021 19:07:47.1552 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 1/L2N2IvCej5wPCWpPWImGW9asZMwAzGm3NUn4U/QZaEYojP9gajYiMdpECAojxiYaITJTymZvT0MxtppGaBkDBH1vDS1vktZ9anY1BoTrlZtdAAUKsNKH/Mi3ZIL9HD X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3288 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v3] port: add file descriptor SWX port X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Self NACK, as V2" was just applied. No significant changes. Thanks & Regards, Suresh. -----Original Message----- From: P, Venkata Suresh Kumar =20 Sent: Wednesday, March 24, 2021 12:34 AM To: dev@dpdk.org Cc: Dumitrescu, Cristian ; P, Venkata Suresh= Kumar ; Khangar, Churchill ; Jangra, Yogesh Subject: [PATCH v3] port: add file descriptor SWX port Add the file descriptor input/output port type for the SWX pipeline. File descriptor port type provides interface with the kernel network stack.= Example file descriptor port is TAP device. Signed-off-by: Venkata Suresh Kumar P Signed-off-by: Churchill Khangar Acked-by: Cristian Dumitrescu --- doc/api/doxy-api-index.md | 1 + examples/pipeline/cli.c | 141 +++++++++++++++++- examples/pipeline/obj.c | 110 ++++++++++++++ examples/pipeline/obj.h | 18 +++ lib/librte_port/meson.build | 2 + lib/librte_port/rte_swx_port_fd.c | 298 ++++++++++++++++++++++++++++++++++= ++++ lib/librte_port/rte_swx_port_fd.h | 57 ++++++++ lib/librte_port/version.map | 2 + 8 files changed, 627 insertions(+), 2 deletions(-) create mode 100644 lib= /librte_port/rte_swx_port_fd.c create mode 100644 lib/librte_port/rte_swx_= port_fd.h diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index be= fc9bc..715204b 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -186,6 +186,7 @@ The public API headers are grouped by topics: * SWX port: [port] (@ref rte_swx_port.h), [ethdev] (@ref rte_swx_port_ethdev.h), + [fd] (@ref rte_swx_port_fd.h), [ring] (@ref rte_swx_port_ring.h), [src/sink] (@ref rte_swx_port_source_sink.h) * SWX table: diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index cacfb2= 8..f620c2f 100644 --- a/examples/pipeline/cli.c +++ b/examples/pipeline/cli.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include =20 @@ -493,6 +494,32 @@ } } =20 +static const char cmd_tap_help[] =3D +"tap \n"; + +static void +cmd_tap(char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size, + void *obj) +{ + struct tap *tap; + char *name; + + if (n_tokens < 2) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + name =3D tokens[1]; + + tap =3D tap_create(obj, name); + if (tap =3D=3D NULL) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + static const char cmd_pipeline_create_help[] =3D "pipeline create \n"; =20 @@ -530,7 +557,8 @@ "pipeline port in \n" " link rxq bsz \n" " ring bsz \n" -" | source \n"; +" | source \n" +" | tap mempool mtu bsz \n"; =20 static void cmd_pipeline_port_in(char **tokens, @@ -678,6 +706,68 @@ port_id, "source", ¶ms); + } else if (strcmp(tokens[t0], "tap") =3D=3D 0) { + struct rte_swx_port_fd_reader_params params; + struct tap *tap; + struct mempool *mp; + + if (n_tokens < t0 + 8) { + snprintf(out, out_size, MSG_ARG_MISMATCH, + "pipeline port in tap"); + return; + } + + tap =3D tap_find(obj, tokens[t0 + 1]); + if (!tap) { + snprintf(out, out_size, MSG_ARG_INVALID, + "tap_name"); + return; + } + params.fd =3D tap->fd; + + if (strcmp(tokens[t0 + 2], "mempool") !=3D 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, + "mempool"); + return; + } + + mp =3D mempool_find(obj, tokens[t0 + 3]); + if (!mp) { + snprintf(out, out_size, MSG_ARG_INVALID, + "mempool_name"); + return; + } + params.mempool =3D mp->m; + + if (strcmp(tokens[t0 + 4], "mtu") !=3D 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, + "mtu"); + return; + } + + if (parser_read_uint32(¶ms.mtu, tokens[t0 + 5]) !=3D 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "mtu"); + return; + } + + if (strcmp(tokens[t0 + 6], "bsz") !=3D 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); + return; + } + + if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 7])) { + snprintf(out, out_size, MSG_ARG_INVALID, + "burst_size"); + return; + } + + t0 +=3D 8; + + status =3D rte_swx_pipeline_port_in_config(p->p, + port_id, + "fd", + ¶ms); + } else { snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); return; @@ -698,7 +788,8 @@ "pipeline port out \n" " link txq bsz \n" " ring bsz \n" -" | sink | none\n"; +" | sink | none\n" +" | tap bsz \n"; =20 static void cmd_pipeline_port_out(char **tokens, @@ -832,6 +923,41 @@ port_id, "sink", ¶ms); + } else if (strcmp(tokens[t0], "tap") =3D=3D 0) { + struct rte_swx_port_fd_writer_params params; + struct tap *tap; + + if (n_tokens < t0 + 4) { + snprintf(out, out_size, MSG_ARG_MISMATCH, + "pipeline port out tap"); + return; + } + + tap =3D tap_find(obj, tokens[t0 + 1]); + if (!tap) { + snprintf(out, out_size, MSG_ARG_INVALID, + "tap_name"); + return; + } + params.fd =3D tap->fd; + + if (strcmp(tokens[t0 + 2], "bsz") !=3D 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz"); + return; + } + + if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) { + snprintf(out, out_size, MSG_ARG_INVALID, + "burst_size"); + return; + } + + t0 +=3D 4; + + status =3D rte_swx_pipeline_port_out_config(p->p, + port_id, + "fd", + ¶ms); } else { snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]); return; @@ -1303,6 +1429,7 @@ "List of commands:\n" "\tmempool\n" "\tlink\n" + "\ttap\n" "\tpipeline create\n" "\tpipeline port in\n" "\tpipeline port out\n" @@ -1329,6 +1456,11 @@ return; } =20 + if (strcmp(tokens[0], "tap") =3D=3D 0) { + snprintf(out, out_size, "\n%s\n", cmd_tap_help); + return; + } + if ((strcmp(tokens[0], "pipeline") =3D=3D 0) && (n_tokens =3D=3D 2) && (strcmp(tokens[1], "create") =3D=3D 0)) { snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help); @@ -1434,6 = +1566,11 @@ return; } =20 + if (strcmp(tokens[0], "tap") =3D=3D 0) { + cmd_tap(tokens, n_tokens, out, out_size, obj); + return; + } + if (strcmp(tokens[0], "pipeline") =3D=3D 0) { if ((n_tokens >=3D 3) && (strcmp(tokens[2], "create") =3D=3D 0)) { diff --git a/examples/pipelin= e/obj.c b/examples/pipeline/obj.c index 154d832..6cfb52a 100644 --- a/examples/pipeline/obj.c +++ b/examples/pipeline/obj.c @@ -4,11 +4,20 @@ =20 #include #include +#include +#ifdef RTE_EXEC_ENV_LINUX +#include +#include +#endif +#include +#include +#include =20 #include #include #include #include +#include #include #include #include @@ -33,6 +42,11 @@ TAILQ_HEAD(ring_list, ring); =20 /* + * tap + */ +TAILQ_HEAD(tap_list, tap); + +/* * pipeline */ TAILQ_HEAD(pipeline_list, pipeline); @@ -45,6 +59,7 @@ struct obj { struct link_list link_list; struct ring_list ring_list; struct pipeline_list pipeline_list; + struct tap_list tap_list; }; =20 /* @@ -422,6 +437,88 @@ struct ring * } =20 /* + * tap + */ +#define TAP_DEV "/dev/net/tun" + +struct tap * +tap_find(struct obj *obj, const char *name) { + struct tap *tap; + + if (!obj || !name) + return NULL; + + TAILQ_FOREACH(tap, &obj->tap_list, node) + if (strcmp(tap->name, name) =3D=3D 0) + return tap; + + return NULL; +} + +struct tap * +tap_next(struct obj *obj, struct tap *tap) { + return (tap =3D=3D NULL) ? + TAILQ_FIRST(&obj->tap_list) : TAILQ_NEXT(tap, node); } + +#ifndef RTE_EXEC_ENV_LINUX + +struct tap * +tap_create(struct obj *obj __rte_unused, const char *name __rte_unused)=20 +{ + return NULL; +} + +#else + +struct tap * +tap_create(struct obj *obj, const char *name) { + struct tap *tap; + struct ifreq ifr; + int fd, status; + + /* Check input params */ + if ((name =3D=3D NULL) || + tap_find(obj, name)) + return NULL; + + /* Resource create */ + fd =3D open(TAP_DEV, O_RDWR | O_NONBLOCK); + if (fd < 0) + return NULL; + + memset(&ifr, 0, sizeof(ifr)); + ifr.ifr_flags =3D IFF_TAP | IFF_NO_PI; /* No packet information */ + strlcpy(ifr.ifr_name, name, IFNAMSIZ); + + status =3D ioctl(fd, TUNSETIFF, (void *) &ifr); + if (status < 0) { + close(fd); + return NULL; + } + + /* Node allocation */ + tap =3D calloc(1, sizeof(struct tap)); + if (tap =3D=3D NULL) { + close(fd); + return NULL; + } + /* Node fill in */ + strlcpy(tap->name, name, sizeof(tap->name)); + tap->fd =3D fd; + + /* Node add to list */ + TAILQ_INSERT_TAIL(&obj->tap_list, tap, node); + + return tap; +} + +#endif + +/* * pipeline */ #ifndef PIPELINE_MSGQ_SIZE @@ -483,6 +580,18 @@ struct pipeline * if (status) goto error; =20 + status =3D rte_swx_pipeline_port_in_type_register(p, + "fd", + &rte_swx_port_fd_reader_ops); + if (status) + goto error; + + status =3D rte_swx_pipeline_port_out_type_register(p, + "fd", + &rte_swx_port_fd_writer_ops); + if (status) + goto error; + status =3D rte_swx_pipeline_table_type_register(p, "exact", RTE_SWX_TABLE_MATCH_EXACT, @@ -541,6 +650,7 @@ struct obj * TAILQ_INIT(&obj->link_list); TAILQ_INIT(&obj->ring_list); TAILQ_INIT(&obj->pipeline_list); + TAILQ_INIT(&obj->tap_list); =20 return obj; } diff --git a/examples/pipeline/obj.h b/examples/pipeline/obj.h index 1aab2a= 3..b921610 100644 --- a/examples/pipeline/obj.h +++ b/examples/pipeline/obj.h @@ -126,6 +126,24 @@ struct ring * ring_find(struct obj *obj, const char *name); =20 /* + * tap + */ +struct tap { + TAILQ_ENTRY(tap) node; + char name[NAME_SIZE]; + int fd; +}; + +struct tap * +tap_find(struct obj *obj, const char *name); + +struct tap * +tap_next(struct obj *obj, struct tap *tap); + +struct tap * +tap_create(struct obj *obj, const char *name); + +/* * pipeline */ struct pipeline { diff --git a/lib/librte_port/meson.build b/lib/librte_port/meson.build inde= x 9fcd62c..435b64a 100644 --- a/lib/librte_port/meson.build +++ b/lib/librte_port/meson.build @@ -12,6 +12,7 @@ sources =3D files( 'rte_port_sym_crypto.c', 'rte_port_eventdev.c', 'rte_swx_port_ethdev.c', + 'rte_swx_port_fd.c', 'rte_swx_port_ring.c', 'rte_swx_port_source_sink.c', ) @@ -28,6 +29,7 @@ headers =3D files( 'rte_port_eventdev.h', 'rte_swx_port.h', 'rte_swx_port_ethdev.h', + 'rte_swx_port_fd.h', 'rte_swx_port_ring.h', 'rte_swx_port_source_sink.h', ) diff --git a/lib/librte_port/rte_swx_port_fd.c b/lib/librte_port/rte_swx_po= rt_fd.c new file mode 100644 index 0000000..bb03bb3 --- /dev/null +++ b/lib/librte_port/rte_swx_port_fd.c @@ -0,0 +1,298 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2021 Intel Corporation + */ +#include +#include +#include + +#include +#include +#include + +#include "rte_swx_port_fd.h" + +#ifndef TRACE_LEVEL +#define TRACE_LEVEL 0 +#endif + +#if TRACE_LEVEL +#define TRACE(...) printf(__VA_ARGS__) +#else +#define TRACE(...) +#endif + +/* + * FD Reader + */ +struct reader { + struct { + int fd; + uint32_t mtu; + uint32_t burst_size; + struct rte_mempool *mempool; + } params; + + struct rte_swx_port_in_stats stats; + struct rte_mbuf **pkts; + uint32_t n_pkts; + uint32_t pos; +}; + +static void * +reader_create(void *args) +{ + struct rte_swx_port_fd_reader_params *conf =3D args; + struct reader *p; + + /* Check input parameters. */ + if (!conf || conf->fd < 0 || conf->mtu =3D=3D 0 || !conf->mempool) + return NULL; + + /* Memory allocation. */ + p =3D calloc(1, sizeof(struct reader)); + if (!p) + return NULL; + + p->pkts =3D calloc(conf->burst_size, sizeof(struct rte_mbuf *)); + if (!p->pkts) { + free(p); + return NULL; + } + + /* Initialization. */ + p->params.fd =3D conf->fd; + p->params.mtu =3D conf->mtu; + p->params.burst_size =3D conf->burst_size; + p->params.mempool =3D conf->mempool; + + return p; +} + +static void +reader_free(void *port) +{ + struct reader *p =3D port; + uint32_t i; + + if (!p) + return; + + for (i =3D 0; i < p->n_pkts; i++) + rte_pktmbuf_free(p->pkts[i]); + + free(p->pkts); + free(p); +} + +static int +reader_pkt_rx(void *port, struct rte_swx_pkt *pkt) { + struct reader *p =3D port; + struct rte_mbuf *m; + void *pkt_data; + ssize_t n_bytes; + uint32_t i, j; + + if (p->n_pkts =3D=3D p->pos) { + if (rte_pktmbuf_alloc_bulk(p->params.mempool, p->pkts, p->params.burst_s= ize) !=3D 0) + return 0; + + for (i =3D 0; i < p->params.burst_size; i++) { + m =3D p->pkts[i]; + pkt_data =3D rte_pktmbuf_mtod(m, void *); + n_bytes =3D read(p->params.fd, pkt_data, (size_t) p->params.mtu); + + if (n_bytes <=3D 0) + break; + + m->data_len =3D n_bytes; + m->pkt_len =3D n_bytes; + + p->stats.n_pkts++; + p->stats.n_bytes +=3D n_bytes; + } + + for (j =3D i; j < p->params.burst_size; j++) + rte_pktmbuf_free(p->pkts[j]); + + p->n_pkts =3D i; + p->pos =3D 0; + + if (!p->n_pkts) + return 0; + } + + m =3D p->pkts[p->pos++]; + pkt->handle =3D m; + pkt->pkt =3D m->buf_addr; + pkt->offset =3D m->data_off; + pkt->length =3D m->pkt_len; + + TRACE("[FD %u] Pkt %d (%u bytes at offset %u)\n", + (uint32_t)p->params.fd, + p->pos - 1, + pkt->length, + pkt->offset); + + if (TRACE_LEVEL) + rte_hexdump(stdout, NULL, + &((uint8_t *)m->buf_addr)[m->data_off], m->data_len); + + return 1; +} + +static void +reader_stats_read(void *port, struct rte_swx_port_in_stats *stats) { + struct reader *p =3D port; + + *stats =3D p->stats; +} + +/* + * FD Writer + */ +struct writer { + struct { + int fd; + uint32_t mtu; + uint32_t burst_size; + struct rte_mempool *mempool; + } params; + + struct rte_swx_port_out_stats stats; + struct rte_mbuf **pkts; + uint32_t n_pkts; +}; + +static void * +writer_create(void *args) +{ + struct rte_swx_port_fd_writer_params *conf =3D args; + struct writer *p; + + /* Check input parameters. */ + if (!conf) + return NULL; + + /* Memory allocation. */ + p =3D calloc(1, sizeof(struct writer)); + if (!p) + return NULL; + + + p->pkts =3D calloc(conf->burst_size, sizeof(struct rte_mbuf *)); + if (!p->pkts) { + free(p); + return NULL; + } + + /* Initialization. */ + p->params.fd =3D conf->fd; + p->params.burst_size =3D conf->burst_size; + + return p; +} + +static void +__writer_flush(struct writer *p) +{ + struct rte_mbuf *pkt; + void *pkt_data; + size_t n_bytes; + ssize_t ret; + uint32_t i; + + for (i =3D 0; i < p->n_pkts; i++) { + pkt =3D p->pkts[i]; + pkt_data =3D rte_pktmbuf_mtod(pkt, void*); + n_bytes =3D rte_pktmbuf_data_len(pkt); + + ret =3D write(p->params.fd, pkt_data, n_bytes); + if (ret < 0) + break; + } + + TRACE("[FD %u] %u packets out\n", + (uint32_t)p->params.fd, + p->n_pkts); + + rte_pktmbuf_free_bulk(p->pkts, p->n_pkts); + + p->n_pkts =3D 0; +} + +static void +writer_pkt_tx(void *port, struct rte_swx_pkt *pkt) { + struct writer *p =3D port; + struct rte_mbuf *m =3D pkt->handle; + + TRACE("[FD %u] Pkt %u (%u bytes at offset %u)\n", + (uint32_t)p->params.fd, + p->n_pkts - 1, + pkt->length, + pkt->offset); + + if (TRACE_LEVEL) + rte_hexdump(stdout, NULL, &pkt->pkt[pkt->offset], pkt->length); + + m->pkt_len =3D pkt->length; + m->data_len =3D (uint16_t)pkt->length; + m->data_off =3D (uint16_t)pkt->offset; + + p->stats.n_pkts++; + p->stats.n_bytes +=3D pkt->length; + + p->pkts[p->n_pkts++] =3D m; + if (p->n_pkts =3D=3D p->params.burst_size) + __writer_flush(p); +} + +static void +writer_flush(void *port) +{ + struct writer *p =3D port; + + if (p->n_pkts) + __writer_flush(p); +} + +static void +writer_free(void *port) +{ + struct writer *p =3D port; + + if (!p) + return; + + writer_flush(p); + free(p->pkts); + free(p); +} + +static void +writer_stats_read(void *port, struct rte_swx_port_out_stats *stats) { + struct writer *p =3D port; + + *stats =3D p->stats; +} + +/* + * Summary of port operations + */ +struct rte_swx_port_in_ops rte_swx_port_fd_reader_ops =3D { + .create =3D reader_create, + .free =3D reader_free, + .pkt_rx =3D reader_pkt_rx, + .stats_read =3D reader_stats_read, +}; + +struct rte_swx_port_out_ops rte_swx_port_fd_writer_ops =3D { + .create =3D writer_create, + .free =3D writer_free, + .pkt_tx =3D writer_pkt_tx, + .flush =3D writer_flush, + .stats_read =3D writer_stats_read, +}; diff --git a/lib/librte_port/rte_swx_port_fd.h b/lib/librte_port/rte_swx_po= rt_fd.h new file mode 100644 index 0000000..ecf3349 --- /dev/null +++ b/lib/librte_port/rte_swx_port_fd.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2021 Intel Corporation + */ + +#ifndef __INCLUDE_RTE_SWX_PORT_FD_H__ +#define __INCLUDE_RTE_SWX_PORT_FD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * RTE SWX FD Input and Output Ports + * + ***/ +#include + +#include + +#include "rte_swx_port.h" + +/** fd_reader port parameters */ +struct rte_swx_port_fd_reader_params { + /** File descriptor. Must be valid and opened in non-blocking mode. */ + int fd; + + /** Maximum Transfer Unit (MTU) */ + uint32_t mtu; + + /** Pre-initialized buffer pool */ + struct rte_mempool *mempool; + + /** RX burst size */ + uint32_t burst_size; +}; + +/** fd_reader port operations */ +extern struct rte_swx_port_in_ops rte_swx_port_fd_reader_ops; + +/** fd_writer port parameters */ +struct rte_swx_port_fd_writer_params { + /** File descriptor. Must be valid and opened in non-blocking mode. */ + int fd; + + /** TX burst size */ + uint32_t burst_size; +}; + +/** fd_writer port operations */ +extern struct rte_swx_port_out_ops rte_swx_port_fd_writer_ops; + +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_RTE_SWX_PORT_FD_H__ */ diff --git a/lib/librte_port/version.map b/lib/librte_port/version.map inde= x e6f35e6..70922e1 100644 --- a/lib/librte_port/version.map +++ b/lib/librte_port/version.map @@ -46,6 +46,8 @@ EXPERIMENTAL { rte_swx_port_source_ops; =20 # added in 21.05 + rte_swx_port_fd_reader_ops; + rte_swx_port_fd_writer_ops; rte_swx_port_ring_reader_ops; rte_swx_port_ring_writer_ops; }; -- 1.8.3.1