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 708FA460D9; Wed, 22 Jan 2025 02:48:30 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D54B140651; Wed, 22 Jan 2025 02:48:22 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2100.outbound.protection.outlook.com [40.107.244.100]) by mails.dpdk.org (Postfix) with ESMTP id D0A22402A9 for ; Wed, 22 Jan 2025 02:48:18 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=agMTkXX2LW0u4TdH3OaRec8To/ADOceY5tzFH7CeOcPaA7xXjGxFUKA2kdaM84moX5tAPUmIbgT1mfIP4GKngYJ1NFRHfI92gjlo+4rhl71xyzbCMISKdQrCTG3P5Ky+1wFHtuswY4tvrEc6RkpZJZH3pfXltXcuEe4PDUxxh5sdrIYk1Q3lc+wn1MLrdg5DUOQX8aesrq9W6b9xQdMsUHK3SYpPmqbHaKV9YfxfhQoC5gnCYiGtXpFNMN/ME/3etUHzIthZRfG6QOtVuxOTBEX9smkR0E6IrRMHMPbWBOczdF6s3vieAUg4UsAMTB5jux0abRnxpUG76ue44wGOXQ== 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=DL/t4o5hr3ub/bI0o+oa8FH73YHG4XNQ8RLe2S+nlL4=; b=tnTFIKuizsqPJ2NKcE0mzrMFfgBTZGwXxkAwiZKoWKJ4j4eq5vccRAVCpva7kxXOBfwpOGPcxWh6ep5XMaAb/tqijl5kDh14MP+Tihb2NGmhTiBrTvoul6t//rzHkx20r2LSlDG6mlkXmmQkiw0PG9u2l/w/7y8KkCge2yeBj2j8u5pgel1y3KxHSZyuynBjUUnAX8/gnyAOKAWcFpgK8EH79ek/rEBnYTJVCNZGs6zsho+U3khBttlAOMAHc+YT5RgoEauljh38AGh/1LWr6wnbC24DypUuehXRDhTthEDfbitJc/gG+UC0ilFCXV2INqoCDppxhI6p3b86ZkQlEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DL/t4o5hr3ub/bI0o+oa8FH73YHG4XNQ8RLe2S+nlL4=; b=Hmvv0j44EyhEYwvU7xCl97YiaWGg/Ugx/x7UDewe5UwG85ZxqiaT1w2BmWmbTs5OLHNYh/MarRp/K2AgyacjzzX/KxvBtz/20vTlqYFuZWKufsT14o+IMxsxLcszMhnI1/PYRDWaCUpkejjWcRMHrGsJC8GcCOT2pFJP6528PRs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by CH3PR13MB6625.namprd13.prod.outlook.com (2603:10b6:610:1df::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.20; Wed, 22 Jan 2025 01:48:17 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::b900:5f05:766f:833]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::b900:5f05:766f:833%6]) with mapi id 15.20.8356.017; Wed, 22 Jan 2025 01:48:17 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , Long Wu , Peng Zhang Subject: [PATCH 2/2] net/nfp: support load firmware for card without DDR Date: Wed, 22 Jan 2025 09:47:51 +0800 Message-ID: <20250122014751.1706413-3-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250122014751.1706413-1-chaoyong.he@corigine.com> References: <20250122014751.1706413-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SGXP274CA0023.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::35) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|CH3PR13MB6625:EE_ X-MS-Office365-Filtering-Correlation-Id: 48965b7d-3b72-4251-022a-08dd3a86d78b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Z7BeZPsk9xGETFKg7va5yUQuqe0tkGSUnqrpBdd4AwMPOGTxiHm2+pQyoqac?= =?us-ascii?Q?cJ0NW328rpsmF+iSTwq+1U3jb9mpWXsN7M+2J/M7QUzgvRZEXQWzqYY5GuWA?= =?us-ascii?Q?q1NaMY+fAkxv5mNqO9Gl1QLEnJusQRpmgXQNT7C/+SFT9HZMSlO5BKP7KXgH?= =?us-ascii?Q?XBfo7wblO9sR+EIIwIjr+JluGsn2cBUXffbhXy5krQUCj7/Cb3KxSNqobcL+?= =?us-ascii?Q?s5wSOhwaiy4LIvT1BXdyRc6beaf02oHhbo5XoGwRMR8UUGELIjmzuHPXbmu0?= =?us-ascii?Q?tXazHkRAhA/X80nloz68MExRufw/2C0fYUM6/KBm1ebLRqTIzmY0L9KI/wSH?= =?us-ascii?Q?gK0tzz2za20EgT1RLl29TVxEh4AcQTAIm2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NRBmMDWEh7GgMN9ijrPTOZZejpodbJar5tDBkm17+B6Sq2kOGhUJxq?= =?us-ascii?Q?6hoDvlB+a1HrL1CwpFo/LwBD5WtkqHiidU68zw1mF3rcX+ZEQg0deDHsvSg+?= =?us-ascii?Q?GtDI0erlxXZ1WOHJx4hIL239obOUf+xHg3+V7G/vRyl1LfuMRuO1b1YIpDUV?= =?us-ascii?Q?fI1pot4TPyC9XdLBHbgvq4qyrfwxiU5l?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?TuIsskuGLzPr5qj7tmgOHsv5ro7yCxccBujNDpcytJAug/yk2406uvkqvxOj?= =?us-ascii?Q?+8EJvyD5Wfu1cQEHbctMyYDOFzo7ntF6jl4EqGg8n9w70tSAwN/NwKlz3aIw?= =?us-ascii?Q?isUb5zF1ZPwgWSWb0a7q23czfpDOVoRZQ8JFuteUPpBZthjPlSPUakklRh3/?= =?us-ascii?Q?0TpQ9heRyiN1qnPjVW9sABGfywhytk89xq0EHbYoD4HwOSVb1uCo0TlHWPfv?= =?us-ascii?Q?9E5g31PmoP2YMN5C/RQUxPvq+SHGybJ+Xv4MWaQgoTPIa6ZhKwl9h4ppwwkg?= =?us-ascii?Q?hgJCsqiYu8SwkEtmWp1K/jvhJnPn6YXyifknjTv+L8NKRaEEDTrTKsoxhqWz?= =?us-ascii?Q?XUvY0dm2arAm/SPT+GchHW7fC5N6rH7FLbr/0uvMio3Y6fRe9WEQD16HWPo6?= =?us-ascii?Q?IHTOqfZY5w2CDmfhUdPEjrOGbEJ7kJTtxCQCUEeA53S4pF4ChfTVm3AK6HPF?= =?us-ascii?Q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v7XRKOoZPw588MXlxoZ+qrPXbz/?= =?us-ascii?Q?mw0w5wp8eHBS3c15vZvytB8pKYWa74PalN2djOePhIgH8b8oo3sADE+OgXYn?= =?us-ascii?Q?dncrazirqGb0LRVjOcd/96d3ONBrv1/dpmM1vlT2NUtDG+a1e9c0eBP25DRs?= =?us-ascii?Q?ILmK1h2NKgP60MVMUudZVFYy3IPi3oSPl+DvPa/aNWAlatMFw9tvCwfeXi4+?= =?us-ascii?Q?L4GABoU/hat2k+SLzNL5JZwBGebZll0g3NgR7lCwLSNVA7c815BTyOH7hOKf?= =?us-ascii?Q?iw=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48965b7d-3b72-4251-022a-08dd3a86d78b X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2025 01:48:17.4268 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LSa+tYjV+6gtqsEvML2NOdTw/QBP5SbhbDULU1qobcSXXh8RfobHi74WllDiViAsjbLvHYGDuYT39/cUqxipQXDp6yHWjORHZ62hogeZU7Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR13MB6625 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 The original logic don't support load firmware for cards which has no DDR, add the related logic to make it can load firmware successfully. Signed-off-by: Chaoyong He Reviewed-by: Long Wu Reviewed-by: Peng Zhang --- drivers/net/nfp/nfpcore/nfp_nsp.c | 131 +++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 3 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_nsp.c b/drivers/net/nfp/nfpcore/nfp_nsp.c index 9837b3354b..dd212a6d7c 100644 --- a/drivers/net/nfp/nfpcore/nfp_nsp.c +++ b/drivers/net/nfp/nfpcore/nfp_nsp.c @@ -37,9 +37,12 @@ #define NSP_DFLT_BUFFER_ADDRESS GENMASK_ULL(39, 0) #define NSP_DFLT_BUFFER_CONFIG 0x20 +#define NSP_DFLT_BUFFER_DMA_CHUNK_ORDER GENMASK_ULL(63, 58) #define NSP_DFLT_BUFFER_SIZE_4KB GENMASK_ULL(15, 8) #define NSP_DFLT_BUFFER_SIZE_MB GENMASK_ULL(7, 0) +#define NFP_CAP_CMD_DMA_SG 0x28 + #define NSP_MAGIC 0xab10 /* @@ -85,6 +88,18 @@ enum nfp_nsp_cmd { SPCODE_DEV_ACTIVATE = 29, /* Activate hardware for multiple pfs case */ }; +struct nfp_nsp_dma_desc { + rte_le32_t size; + rte_le32_t reserved; + rte_le64_t addr; +}; + +struct nfp_nsp_dma_buf { + rte_le32_t chunk_cnt; + rte_le32_t reserved[3]; + struct nfp_nsp_dma_desc descs[]; +}; + static const struct { uint32_t code; const char *msg; @@ -502,6 +517,109 @@ nfp_nsp_command_buf_def(struct nfp_nsp *nsp, return ret; } +static int +nfp_nsp_command_buf_dma_sg(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg, + size_t max_size, + size_t chunk_order) +{ + int ret; + void *chunks; + uint32_t nseg; + size_t total_len; + size_t chunk_size; + rte_iova_t buf_dma; + rte_iova_t chunks_dma; + struct nfp_nsp_dma_buf *buf; + struct nfp_nsp_dma_desc *descs; + + chunk_size = RTE_BIT64(chunk_order); + nseg = DIV_ROUND_UP(max_size, chunk_size); + + /* Malloc memory */ + total_len = sizeof(struct nfp_nsp_dma_buf) + + nseg * sizeof(struct nfp_nsp_dma_desc) + + nseg * chunk_size; + buf = rte_zmalloc(NULL, total_len, 0); + buf_dma = rte_malloc_virt2iova(buf); + + /* Populate struct nfp_nsp_dma_buf */ + buf->chunk_cnt = rte_cpu_to_le_32(nseg); + + /* Init start pointer of sections */ + descs = (void *)((char *)buf + sizeof(struct nfp_nsp_dma_buf)); + chunks = (char *)descs + nseg * sizeof(struct nfp_nsp_dma_desc); + chunks_dma = buf_dma + sizeof(struct nfp_nsp_dma_buf) + + nseg * sizeof(struct nfp_nsp_dma_desc); + + /* Copy in_arg*/ + rte_memcpy(chunks, arg->in_buf, arg->in_size); + + /* Populate struct nfp_nsp_dma_desc */ + for (uint32_t i = 0; i < nseg; i++) { + descs[i].size = rte_cpu_to_le_32(chunk_size); + descs[i].addr = rte_cpu_to_le_64(chunks_dma + i * chunk_size); + } + descs[nseg - 1].size = rte_cpu_to_le_32(max_size - chunk_size * (nseg - 1)); + + /* Send to nsp */ + arg->arg.dma = true; + arg->arg.buf = buf_dma; + ret = nfp_nsp_command_real(nsp, &arg->arg); + if (ret < 0) { + PMD_DRV_LOG(ERR, "NSP: SG DMA failed for command 0x%04x: %d", + arg->arg.code, ret); + goto free_exit; + } + + /* Copy out_arg */ + if (arg->out_buf != NULL && arg->out_size > 0) + rte_memcpy(arg->out_buf, chunks, arg->out_size); + +free_exit: + rte_free(buf); + + return ret; +} + +#define NFP_PAGE_SHIFT 12UL + +static int +nfp_nsp_command_buf_dma(struct nfp_nsp *nsp, + struct nfp_nsp_command_buf_arg *arg, + size_t max_size, + size_t dma_order) +{ + int err; + bool sg_ok; + uint64_t reg; + size_t buf_order; + size_t chunk_order; + struct nfp_cpp *cpp = nsp->cpp; + + err = nfp_cpp_readq(cpp, nfp_resource_cpp_id(nsp->res), + nfp_resource_address(nsp->res) + NFP_CAP_CMD_DMA_SG, + ®); + if (err < 0) + return err; + + sg_ok = reg & RTE_BIT64(arg->arg.code - 1); + if (!sg_ok) { + buf_order = rte_log2_u64(max_size); + if (buf_order > dma_order) { + PMD_DRV_LOG(ERR, "NSP: non-SG DMA for command 0x%04x fail", + arg->arg.code); + return -ENOMEM; + } + + chunk_order = buf_order; + } else { + chunk_order = RTE_MIN(dma_order, NFP_PAGE_SHIFT); + } + + return nfp_nsp_command_buf_dma_sg(nsp, arg, max_size, chunk_order); +} + #define SZ_1M 0x00100000 #define SZ_4K 0x00001000 @@ -513,6 +631,7 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, size_t size; uint64_t reg; size_t max_size; + size_t dma_order; struct nfp_cpp *cpp = nsp->cpp; if (nsp->ver.minor < 13) { @@ -530,13 +649,19 @@ nfp_nsp_command_buf(struct nfp_nsp *nsp, max_size = RTE_MAX(arg->in_size, arg->out_size); size = FIELD_GET(NSP_DFLT_BUFFER_SIZE_MB, reg) * SZ_1M + FIELD_GET(NSP_DFLT_BUFFER_SIZE_4KB, reg) * SZ_4K; - if (size < max_size) { + dma_order = FIELD_GET(NSP_DFLT_BUFFER_DMA_CHUNK_ORDER, reg); + + if (size >= max_size) { + err = nfp_nsp_command_buf_def(nsp, arg); + } else if (dma_order != 0) { + err = nfp_nsp_command_buf_dma(nsp, arg, max_size, dma_order); + } else { PMD_DRV_LOG(ERR, "NSP: default buffer too small for command %#04x (%zu < %zu).", arg->arg.code, size, max_size); - return -EINVAL; + err = -EINVAL; } - return nfp_nsp_command_buf_def(nsp, arg); + return err; } int -- 2.43.5