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 C2B2C45AAF; Fri, 4 Oct 2024 17:15:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E84A742EC9; Fri, 4 Oct 2024 17:09:20 +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 66A2342E46 for ; Fri, 4 Oct 2024 17:08:46 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2105.outbound.protection.outlook.com [104.47.17.105]) by mx-outbound8-201.eu-central-1a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 04 Oct 2024 15:08:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X/+/F3g7rkTwIxpMISXiNzLXaATUVvQY2LYizKHc+DIkGxCz9bMHkZhWD/QfSq9sOR9BZxIAbjgQcbb0uHmp+kVaw5uBqJABoEC2Y6AeS/upKC32/rMhr3hmAwN1/O9C46bd5W4fEBFgIBSsTXdjMJwU/1nzOuV7lal4znmX2zXnoi8e607946o0mLm9myvGMRKj2XXqfwrD3TvxZzKaxlHjk9ouFh2FJ85y40DOZBRHLKfRVRm3ibgyQ1af/rPO0AeCw8pdlnHrUPyFkM00Cvdla3sNhSAnyj6JxR3YsIOcaxxfJaNXjMKXS2LqB6E2Fhx0oaG6UTlL1+H+cbkDmA== 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=gP+CsQyMFKN5vX+US+RL6kHP8GNX61Kp7azZRdsvbmtw3QGBOcxxq/6NhVxiMVr5VdyuXI3NmoCj4gIMgS+Dv0yCFTZKxKtpZdw+TfUaxhi7EYd12rc3i0o7IORXyKL83hrmTpuVdmZaTqsLPvL91ThCgIxR7/H4nvfZ9I813/GdQ8ruwDSB6BME99PxCIRGl/boo/qeZOw/gWoeOiiu88TzCbu4Bm6oQMoRECzqpifElpIpZ20izu8Qa8bqwdivf/2FKFmeTCCzvtUhTV0c1/LIUjCubXBLv6dUKqPLbADyGZHAU/F4Gs3g0rL97ZJ/lPaUPE8tuN5P5Tn0Brweng== 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=MSPQPRhnSyo2BCwwNJotIVjuM4UIuOCvJN0/lMBkIKaa5DzOBGD9bV9MKx4e1j4kGeXyubeEvpKGMJWxHLTFdcMX9dPtRUSo4AeC5FZ8UFWX4pD9G1OYVb6QGaq8sFaJo0h2hM2nJcQiWKzwcPrF2xP8MBJMVvA2qpDTGV8Rf7Y= Received: from AM0PR02CA0021.eurprd02.prod.outlook.com (2603:10a6:208:3e::34) by VI0P190MB2083.EURP190.PROD.OUTLOOK.COM (2603:10a6:800:24a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.18; Fri, 4 Oct 2024 15:08:41 +0000 Received: from AMS0EPF000001AC.eurprd05.prod.outlook.com (2603:10a6:208:3e:cafe::5a) by AM0PR02CA0021.outlook.office365.com (2603:10a6:208:3e::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16 via Frontend Transport; Fri, 4 Oct 2024 15:08:41 +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 AMS0EPF000001AC.mail.protection.outlook.com (10.167.16.152) with Microsoft SMTP Server id 15.20.7918.13 via Frontend Transport; Fri, 4 Oct 2024 15:08:41 +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 14/14] net/ntnic: add functions for retrieving and managing packets Date: Fri, 4 Oct 2024 17:07:39 +0200 Message-ID: <20241004150749.261020-53-sil-plv@napatech.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20241004150749.261020-1-sil-plv@napatech.com> References: <20241004150749.261020-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: AMS0EPF000001AC:EE_|VI0P190MB2083:EE_ X-MS-Office365-Filtering-Correlation-Id: e9d5184d-bfd0-4cb3-d51b-08dce4866ee7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X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ExRcDluSGphaXZtWllyUzlpUnk5MFNzTzVGQXFPQjFUUUYzRnlLVFpIY3NQ?= =?utf-8?B?YWlNcVF6Nm9CRU5sTzFZVHROQXVlcTdxZTQ1RTlOTjRrenF3TTl4NVN0MjFm?= =?utf-8?Q?ZPVhTtBr5QRJK?= 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)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 1NdJbAj/BrLYERJi/EiTzJjv95S4fOlc0cQT1YWO780I3u59ethDwaqrtKocNIHI6x6ndJ92JQAvZhJbQnae4oI/55oD6hxjxHFtwPEoZLcknkD+Ywsb6PMJziVdNEWKZxVNRLfNJwUPEOnVITCFTaCVwxZ1ohNnhHgxEHNO+tL3Ujf5k9opvSu00wtUmZ/nzoOZ9+zpVPBwA32VpDejch3rwmuFk4K9GqJ95FQ9MHpgs+2c+fES0cqdSb31MnKbZXEWdCa+1IMURMjUVtwpufH+QaL9Nao0sr5nY8sia7y4gvh3fLpW6s7nswOXs3FJRxfSqGFXyGhNAsXkzkXZC852Ra/RLegOIFGYkFqwiFn19TXxVg9AuWZ6Uc10ZAyx3K7VYJqY8cJIUJXT1MnqU97gSzFkON8mhuw+Iq9T2D+GCM4UJXaAIGm0kehkvuZEg8Mn9YXm0WSScaCRnjTnlRnzIo4vSeFB9n+0MgVyxMgOrEUhIA5H9SoK3h67/PACj41jKHah5ry4AjcnZ87UuPfWJZjUos0GZ1ugKrVO372Co3Op0YnY5fN40mlZE/Qa9K51j7VdayvFRfvnS6W3+6yVb/EoLhAgQZoxDzyz9FSPc027xLRVVmaR8Wnam6CZnbBSxBiPI/x6W7St3pTmEA== X-OriginatorOrg: napatech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2024 15:08:41.5330 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e9d5184d-bfd0-4cb3-d51b-08dce4866ee7 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: AMS0EPF000001AC.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0P190MB2083 X-BESS-ID: 1728054525-302249-12643-31697-1 X-BESS-VER: 2019.1_20240924.1654 X-BESS-Apparent-Source-IP: 104.47.17.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.259494 [from cloudscan23-246.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