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 38FDD45ACC; Sun, 6 Oct 2024 22:43:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CE2C140EE5; Sun, 6 Oct 2024 22:38:57 +0200 (CEST) Received: from egress-ip11a.ess.de.barracuda.com (egress-ip11a.ess.de.barracuda.com [18.184.203.234]) by mails.dpdk.org (Postfix) with ESMTP id 7CC7140DDC for ; Sun, 6 Oct 2024 22:38:15 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2105.outbound.protection.outlook.com [104.47.18.105]) by mx-outbound44-124.eu-central-1c.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 06 Oct 2024 20:38:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kDZXVBz1amgyFVVd8SP+Hi7KBJ1s/E/s3++m2BUxTqZUa6XdC5ZrjQOzurJ/4Jn8TALCkH38oDSzrh2m3hSg+KGrVXjxkZ8WTEwTQ5y08cNQwTv2UxB6Y6mMzcqDAjKCMabquQnFy25faDhQ7vghAuiEYThPAI267YRLQg5wQke1+smRnMp8i0si42VdLWjQW2tl86jGHOkhOJYewOtzvoVKN/md27/l4UefsAHZ0NSDgtw0hEHGRtTm4kYuT3qdWXmDiT1y8zJZKxuDknrsgYeZwksvRglAYuRNTlVDLQGtZLcmLWPEHwa5GCbt1Du36eD/KUFLIFZvN5ifUPUdog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iNPdASuL6qBckJbifg5qNXQgXTI3wWpwvKgwU9pntn0=; b=d6/zEmZ8vw0WxDTHejzIy2ce5mqf+/5Y1nX11/LkEi+RonQbjao/+CQdz5U4P1gtfyet6e+4sbcKi4WnFYwTFPh96hxhRz0diUQuVBke5+JKRxXSVXF0w/MPJ2RVSv/fwNnzmmtfZPXnfKqyw0wLnpnLk9BuhkKc4z/3cIBA9XTH11N4xUiZsy/HKM7MIALX21DcE/y8t67ZvEVt4R+F2RMk32BwsJW6B/eMuw8vApjWlEnC2BYGDTEZtva3zmuVMPyRWMzyy8wPg5e5gquf2ZAvxQBXhFT3juZwg22JXM+u31NIs+KtCA8O7bI/wElVu6K35fRjJ3sU/kd3igOtZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 178.72.21.4) smtp.rcpttodomain=dpdk.org smtp.mailfrom=napatech.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=napatech.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=napatech.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iNPdASuL6qBckJbifg5qNXQgXTI3wWpwvKgwU9pntn0=; b=SdNLIc9rM0xyfWLIkwU5QZSA4E5ct3M3HLgfr6CbEAr2zMI0I8oA/PZIKlE7e9feFAF5KnAKcUH91S07GyokPYrgC7V9mAFnD6yy8TZDnUgqKp+KeTzztuf6I9ouEcF6ADc+NkzOmseShixL0HzSAq3nYpLdK1ybDvdv3MvgHOo= Received: from AM6P191CA0017.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8b::30) by AM7P190MB0582.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:122::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.22; Sun, 6 Oct 2024 20:38:11 +0000 Received: from AMS0EPF00000190.eurprd05.prod.outlook.com (2603:10a6:209:8b:cafe::3a) by AM6P191CA0017.outlook.office365.com (2603:10a6:209:8b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.20 via Frontend Transport; Sun, 6 Oct 2024 20:38:11 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 178.72.21.4) smtp.mailfrom=napatech.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=napatech.com; Received-SPF: Fail (protection.outlook.com: domain of napatech.com does not designate 178.72.21.4 as permitted sender) receiver=protection.outlook.com; client-ip=178.72.21.4; helo=localhost.localdomain; Received: from localhost.localdomain (178.72.21.4) by AMS0EPF00000190.mail.protection.outlook.com (10.167.16.213) with Microsoft SMTP Server id 15.20.7918.13 via Frontend Transport; Sun, 6 Oct 2024 20:38:11 +0000 From: Serhii Iliushyk To: dev@dpdk.org Cc: mko-plv@napatech.com, sil-plv@napatech.com, ckm@napatech.com, andrew.rybchenko@oktetlabs.ru, ferruh.yigit@amd.com, Danylo Vodopianov Subject: [PATCH v1 50/50] net/ntnic: add functions for retrieving and managing packets Date: Sun, 6 Oct 2024 22:37:17 +0200 Message-ID: <20241006203728.330792-51-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241006203728.330792-1-sil-plv@napatech.com> References: <20241006203728.330792-1-sil-plv@napatech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF00000190:EE_|AM7P190MB0582:EE_ X-MS-Office365-Filtering-Correlation-Id: 9cb873c8-f109-477b-ace4-08dce646cb85 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: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IQ0swMEJpemhwbEZLaVNiRTQ2b0xh?= =?utf-8?B?UElSRmNrb2ZhU2o4elZHdE96OTM0VXZEUW9hMDBVdEtaSVprSGpxTXdJU0F4?= =?utf-8?Q?3NtsgLYgIAf4d?= X-Forefront-Antispam-Report: CIP:178.72.21.4; CTRY:DK; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:localhost.localdomain; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: lrDST8RBE/KrnyYhFV7RFX5F7rYcKLsV/4zagv3sgSvcTpDLHiy6jKacLSzoLY6PyWgS7TzzTmbU74gsj7X16yzRhGhFkDuxJOvS3OoNkCxvPwClX+AzgxqLeudBldRfi7iCOwaMp3qCIQ78EYaLuv0lnlTbgA0o+LJrGJnaOwsAY13Z/5PXirFLNFyGK9JofDF0mEEH2ZqJaXcjvAASREPVReBxmrcR2Gl5slQlLZOkJYWDIb3EAIzBVVK016ziNod2w6CH3zsC61ID7nYaurY5jmQnL3pk9+8Zm4JF1fa8gmpUe5U7KXAwS9bbZ8UNkbl1hkeK+aT6JJvcoMc81y96blZbujEKDr3TCwECqMc0MPPTvodZ5o0WNZqH/Mjo9RwAWFM6LVN8mwTOY8budWk8np4eTN8GpGaxsCIkYSgrg1MQ8MX7LdLOCgtDT6Afsq6rIKkS5JtskY2xpA8YOT9PFlom9/0xQ15ZdCPVWrUQrKuf7jNkNzkakLjSY6xfLO9PIHMWNIuj+v6yQ73b9Pg25kT88C+0x4TFYSuZUMMEMtbexJttsstPEuc4Sovre+qa8fjIwAs4leHP3OhhW9EPAw80goGlSDVnIOfbsee8lRMISteRDQVbhzbB2aZ/TNwCCARCNRekQaerU2NXxQ== X-OriginatorOrg: napatech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2024 20:38:11.4996 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9cb873c8-f109-477b-ace4-08dce646cb85 X-MS-Exchange-CrossTenant-Id: c4540d0b-728a-4233-9da5-9ea30c7ec3ed X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=c4540d0b-728a-4233-9da5-9ea30c7ec3ed; Ip=[178.72.21.4]; Helo=[localhost.localdomain] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF00000190.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7P190MB0582 X-BESS-ID: 1728247093-311388-7260-101896-2 X-BESS-VER: 2019.1_20240924.1654 X-BESS-Apparent-Source-IP: 104.47.18.105 X-BESS-Parts: H4sIAAAAAAACA4uuVkqtKFGyUioBkjpK+cVKVhaWpmZAVgZQ0MzQLCUl1cjE0i w1JdHA3NzM0MAy2dTAKMUkNc3Y0sJMqTYWAKIR8pxBAAAA X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.259547 [from cloudscan23-175.eu-central-1b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS113687 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 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 From: Danylo Vodopianov Implemented functionality for retrieving received packets from virtual queues, supporting both SPLIT_RING and PACKED_RING types. Updated sg_ops structure to include the new packet retrieval functions. Signed-off-by: Danylo Vodopianov --- doc/guides/nics/ntnic.rst | 44 ++++ drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c | 216 ++++++++++++++++++ 2 files changed, 260 insertions(+) diff --git a/doc/guides/nics/ntnic.rst b/doc/guides/nics/ntnic.rst index 7ac92c891c..9ac8098735 100644 --- a/doc/guides/nics/ntnic.rst +++ b/doc/guides/nics/ntnic.rst @@ -51,6 +51,50 @@ and they are also supported. If vfio-pci is not required, kernel version 4.18 is supported. +Configuration +------------- + +Command line arguments +~~~~~~~~~~~~~~~~~~~~~ + +Following standard DPDK command line arguments are used by the PMD: + + -a: Used to specifically define the NT adapter by PCI ID. + --iova-mode: Must be set to ‘pa’ for Physical Address mode. + +NTNIC specific arguments can be passed to the PMD in the PCI device parameter list:: + + ... -a 0000:03:00.0[{,}] + +The NTNIC specific argument format is:: + + .=[:] + +Multiple arguments for the same device are separated by ‘,’ comma. + can be a single value or a range. + + +- ``rxqs`` parameter [int] + + Specify number of RX queues to use. + + To specify number of RX queues:: + + -a ::00.0,rxqs=4,txqs=4 + + By default, the value is set to 1. + +- ``txqs`` parameter [int] + + Specify number of TX queues to use. + + To specify number of TX queues:: + + -a ::00.0,rxqs=4,txqs=4 + + By default, the value is set to 1. + + Logging and Debugging --------------------- diff --git a/drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c b/drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c index 6d7862791d..a5051891e8 100644 --- a/drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c +++ b/drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c @@ -58,6 +58,15 @@ } \ } while (0) +#define inc_used(vq, num) do { \ + struct nthw_virt_queue *temp_vq = (vq); \ + temp_vq->next_used += (num); \ + if (temp_vq->next_used >= temp_vq->queue_size) { \ + temp_vq->next_used -= temp_vq->queue_size; \ + temp_vq->used_wrap_count ^= 1; \ + } \ +} while (0) + struct __rte_aligned(8) virtq_avail { uint16_t flags; uint16_t idx; @@ -107,6 +116,10 @@ struct nthw_virt_queue { struct pvirtq_event_suppress *driver_event; struct pvirtq_event_suppress *device_event; struct pvirtq_desc *desc; + struct { + uint16_t next; + uint16_t num; + } outs; /* * when in-order release used Tx packets from FPGA it may collapse * into a batch. When getting new Tx buffers we may only need @@ -1097,6 +1110,107 @@ nthw_setup_mngd_tx_virt_queue(nthw_dbs_t *p_nthw_dbs, return NULL; } +static uint16_t nthw_get_rx_packets(struct nthw_virt_queue *rxvq, + uint16_t n, + struct nthw_received_packets *rp, + uint16_t *nb_pkts) +{ + uint16_t segs = 0; + uint16_t pkts = 0; + + if (rxvq->vq_type == SPLIT_RING) { + uint16_t i; + uint16_t entries_ready = (uint16_t)(rxvq->cached_idx - rxvq->used_idx); + + if (entries_ready < n) { + /* Look for more packets */ + rxvq->cached_idx = rxvq->p_used->idx; + entries_ready = (uint16_t)(rxvq->cached_idx - rxvq->used_idx); + + if (entries_ready == 0) { + *nb_pkts = 0; + return 0; + } + + if (n > entries_ready) + n = entries_ready; + } + + /* + * Give packets - make sure all packets are whole packets. + * Valid because queue_size is always 2^n + */ + const uint16_t queue_mask = (uint16_t)(rxvq->queue_size - 1); + const uint32_t buf_len = rxvq->p_desc[0].len; + + uint16_t used = rxvq->used_idx; + + for (i = 0; i < n; ++i) { + uint32_t id = rxvq->p_used->ring[used & queue_mask].id; + rp[i].addr = rxvq->p_virtual_addr[id].virt_addr; + rp[i].len = rxvq->p_used->ring[used & queue_mask].len; + + uint32_t pkt_len = ((struct _pkt_hdr_rx *)rp[i].addr)->cap_len; + + if (pkt_len > buf_len) { + /* segmented */ + int nbsegs = (pkt_len + buf_len - 1) / buf_len; + + if (((int)i + nbsegs) > n) { + /* don't have enough segments - break out */ + break; + } + + int ii; + + for (ii = 1; ii < nbsegs; ii++) { + ++i; + id = rxvq->p_used->ring[(used + ii) & queue_mask].id; + rp[i].addr = rxvq->p_virtual_addr[id].virt_addr; + rp[i].len = + rxvq->p_used->ring[(used + ii) & queue_mask].len; + } + + used += nbsegs; + + } else { + ++used; + } + + pkts++; + segs = i + 1; + } + + rxvq->used_idx = used; + + } else if (rxvq->vq_type == PACKED_RING) { + /* This requires in-order behavior from FPGA */ + int i; + + for (i = 0; i < n; i++) { + struct pvirtq_desc *desc = &rxvq->desc[rxvq->next_used]; + + uint16_t flags = desc->flags; + uint8_t avail = !!(flags & VIRTQ_DESC_F_AVAIL); + uint8_t used = !!(flags & VIRTQ_DESC_F_USED); + + if (avail != rxvq->used_wrap_count || used != rxvq->used_wrap_count) + break; + + rp[pkts].addr = rxvq->p_virtual_addr[desc->id].virt_addr; + rp[pkts].len = desc->len; + pkts++; + + inc_used(rxvq, 1); + } + + segs = pkts; + } + + *nb_pkts = pkts; + return segs; +} + /* * Put buffers back into Avail Ring */ @@ -1139,6 +1253,106 @@ static void nthw_release_rx_packets(struct nthw_virt_queue *rxvq, uint16_t n) } } +static uint16_t nthw_get_tx_packets(struct nthw_virt_queue *txvq, + uint16_t n, + uint16_t *first_idx, + struct nthw_cvirtq_desc *cvq, + struct nthw_memory_descriptor **p_virt_addr) +{ + int m = 0; + uint16_t queue_mask = + (uint16_t)(txvq->queue_size - 1); /* Valid because queue_size is always 2^n */ + *p_virt_addr = txvq->p_virtual_addr; + + if (txvq->vq_type == SPLIT_RING) { + cvq->s = txvq->p_desc; + cvq->vq_type = SPLIT_RING; + + *first_idx = txvq->tx_descr_avail_idx; + + uint16_t entries_used = + (uint16_t)((txvq->tx_descr_avail_idx - txvq->cached_idx) & queue_mask); + uint16_t entries_ready = (uint16_t)(txvq->queue_size - 1 - entries_used); + + vq_log_arg(txvq, + "ask %i: descrAvail %i, cachedidx %i, used: %i, ready %i used->idx %i\n", + n, txvq->tx_descr_avail_idx, txvq->cached_idx, entries_used, entries_ready, + txvq->p_used->idx); + + if (entries_ready < n) { + /* + * Look for more packets. + * Using the used_idx in the avail ring since they are held synchronous + * because of in-order + */ + txvq->cached_idx = + txvq->p_avail->ring[(txvq->p_used->idx - 1) & queue_mask]; + + vq_log_arg(txvq, "Update: get cachedidx %i (used_idx-1 %i)\n", + txvq->cached_idx, (txvq->p_used->idx - 1) & queue_mask); + entries_used = + (uint16_t)((txvq->tx_descr_avail_idx - txvq->cached_idx) + & queue_mask); + entries_ready = (uint16_t)(txvq->queue_size - 1 - entries_used); + vq_log_arg(txvq, "new used: %i, ready %i\n", entries_used, entries_ready); + + if (n > entries_ready) + n = entries_ready; + } + + } else if (txvq->vq_type == PACKED_RING) { + int i; + + cvq->p = txvq->desc; + cvq->vq_type = PACKED_RING; + + if (txvq->outs.num) { + *first_idx = txvq->outs.next; + uint16_t num = min(n, txvq->outs.num); + txvq->outs.next = (txvq->outs.next + num) & queue_mask; + txvq->outs.num -= num; + + if (n == num) + return n; + + m = num; + n -= num; + + } else { + *first_idx = txvq->next_used; + } + + /* iterate the ring - this requires in-order behavior from FPGA */ + for (i = 0; i < n; i++) { + struct pvirtq_desc *desc = &txvq->desc[txvq->next_used]; + + uint16_t flags = desc->flags; + uint8_t avail = !!(flags & VIRTQ_DESC_F_AVAIL); + uint8_t used = !!(flags & VIRTQ_DESC_F_USED); + + if (avail != txvq->used_wrap_count || used != txvq->used_wrap_count) { + n = i; + break; + } + + uint16_t incr = (desc->id - txvq->next_used) & queue_mask; + i += incr; + inc_used(txvq, incr + 1); + } + + if (i > n) { + int outs_num = i - n; + txvq->outs.next = (txvq->next_used - outs_num) & queue_mask; + txvq->outs.num = outs_num; + } + + } else { + return 0; + } + + return m + n; +} + static void nthw_release_tx_packets(struct nthw_virt_queue *txvq, uint16_t n, uint16_t n_segs[]) { int i; @@ -1200,7 +1414,9 @@ static struct sg_ops_s sg_ops = { .nthw_release_mngd_rx_virt_queue = nthw_release_mngd_rx_virt_queue, .nthw_setup_mngd_tx_virt_queue = nthw_setup_mngd_tx_virt_queue, .nthw_release_mngd_tx_virt_queue = nthw_release_mngd_tx_virt_queue, + .nthw_get_rx_packets = nthw_get_rx_packets, .nthw_release_rx_packets = nthw_release_rx_packets, + .nthw_get_tx_packets = nthw_get_tx_packets, .nthw_release_tx_packets = nthw_release_tx_packets, .nthw_virt_queue_init = nthw_virt_queue_init }; -- 2.45.0