Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5367958pxj; Wed, 26 May 2021 08:58:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxz3+QwtRtkscCa14mp7/5q8nPc+BAU+4muvM0Anwm/JhKFVSiyOXiUgU0m2lA51wOQmJn X-Received: by 2002:a17:906:2844:: with SMTP id s4mr3470018ejc.263.1622044718307; Wed, 26 May 2021 08:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622044718; cv=none; d=google.com; s=arc-20160816; b=CY3I5LkOzu1PE1InQHbkQ23cVcmtWEXE9f6pkYfoz1VBZmLzOjw35x/i30m7QyCylz LeWHZRz07UzFwIIfDI/5mlt9+yItujot6HWFlbI00tunnp9RMoFL29NIIig0OkaurYOe mncYH8rOpvoExUrilc60vn2MD0sUBCxLs2pObKccXI+yHx0rXcpWySC8vmdYQCZVAQBf 1dPadnOVXnHuHmvQCo/yLcwkaKPlm3lkRU3wLAhc1rfMLOITcfiKZ+F+bMkx3JyiNrre nWFD0CQw7bgSgP23nWdec1UEAV8wZC/35b0Z6KoZxFZxIo0Jsp7VvrG59+QXdWtCsREh 1eRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lAyfz0g8Plbi7kl2/qWxwrQa4loQgORCPJ4RIFO8J1g=; b=nmbc1byUHo3+n16H6FTRHu36n6USwAgo4ryNejzYMoKP1l+AdRwr4kdQmGDHaCcVq+ bjDRbQ1+4xexsqSGcm7xy6RDHUZEl5qFCXv0Y7xlJiUFN+CLzYzblV9tNUE+0bHcl8z+ oj0MNl9qTrFuU15aS/xAsVbiB9TJaurJBdSEd7tk2vXBfla19489CEEvfuF+WnUubH7i HF2xAJ8o8Ch/eruQNrdb4Y5WUGO1Nc4k96Y46W0Ircj9t9uLUKlntBBvGavgshW76F9C IiOneJivQyDTinnXY+Gtukae0eF8tqS9hEyahj6tJkYwJ+XVwFuP9XITo7Zt1+mqM2DQ YVVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b="W/PWmDxD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=marvell.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zm10si753855ejb.739.2021.05.26.08.58.15; Wed, 26 May 2021 08:58:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b="W/PWmDxD"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235405AbhEZP6j (ORCPT + 99 others); Wed, 26 May 2021 11:58:39 -0400 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:38844 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232769AbhEZP6i (ORCPT ); Wed, 26 May 2021 11:58:38 -0400 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QFt4Lg003138; Wed, 26 May 2021 08:57:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=lAyfz0g8Plbi7kl2/qWxwrQa4loQgORCPJ4RIFO8J1g=; b=W/PWmDxDAEX3dWFTKlqGc4t0ErKEgfDSFipLdDgVJNnGwIbUpN4vxrqFpU0xQXC6hePs 8V6bsbRiL99DR6OiWaumKdQx49zMORXJUq3oROysdTBJj++C5Zb5I9N1HpMN6A7iJyru DRBYeuYVztpLR2z1xjdnYiJW8BYa1PHz8V2r3KdEwfxe9NMLG0vIxbV18X6wbSi5ZiWc 71AHOrMMUiatnlZ9beuyd6lq+ios2I9PBLGFEJaSlSpm3MSWNwEaAJxhni1O1UVcgrnf ehiRD1LGLj2RKyP1+kPJzSDkCDbiyzer82rB7ZosxfBo9n8ikmUQW2MGQQMg4cVK0Mex Yg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com with ESMTP id 38spf38tnb-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 08:57:06 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 26 May 2021 08:57:05 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 26 May 2021 08:57:05 -0700 Received: from hyd1584.marvell.com (unknown [10.29.37.82]) by maili.marvell.com (Postfix) with ESMTP id E88FF3F703F; Wed, 26 May 2021 08:57:02 -0700 (PDT) From: George Cherian To: , CC: , , , Subject: [net-next PATCH 2/5] octeontx2-af: load NPC profile via firmware database Date: Wed, 26 May 2021 21:26:53 +0530 Message-ID: <20210526155656.2689892-3-george.cherian@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210526155656.2689892-1-george.cherian@marvell.com> References: <20210526155656.2689892-1-george.cherian@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: -0B5Eg7Ekp4nT3nJE_rWwW3dsslhsdR6 X-Proofpoint-ORIG-GUID: -0B5Eg7Ekp4nT3nJE_rWwW3dsslhsdR6 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_10:2021-05-26,2021-05-26 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Harman Kalra Currently NPC profile (KPU + MKEX) can be loaded using firmware binary in filesystem scheme. Enhancing the functionality to load NPC profile image from system firmware database. It uses the same technique as used for loading MKEX profile. Firstly firmware binary in kernel is checked for a valid image else tries to load NPC profile from firmware database and at last uses default profile if no proper image found. Signed-off-by: Harman Kalra Signed-off-by: Sunil Kovvuri Goutham Signed-off-by: George Cherian --- .../net/ethernet/marvell/octeontx2/af/rvu.h | 1 + .../ethernet/marvell/octeontx2/af/rvu_npc.c | 113 +++++++++++++++--- 2 files changed, 99 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h index fb142520e309..74ed929f101b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h @@ -442,6 +442,7 @@ struct rvu { struct rvu_fwdata *fwdata; void *kpu_fwdata; size_t kpu_fwdata_sz; + void __iomem *kpu_prfl_addr; /* NPC KPU data */ struct npc_kpu_profile_adapter kpu; diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c index 254b768155cd..61df80cfed1a 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c @@ -1134,6 +1134,30 @@ static void npc_program_mkex_profile(struct rvu *rvu, int blkaddr, } } +static int npc_fwdb_prfl_img_map(struct rvu *rvu, void __iomem **prfl_img_addr, + u64 *size) +{ + u64 prfl_addr, prfl_sz; + + if (!rvu->fwdata) + return -EINVAL; + + prfl_addr = rvu->fwdata->mcam_addr; + prfl_sz = rvu->fwdata->mcam_sz; + + if (!prfl_addr || !prfl_sz) + return -EINVAL; + + *prfl_img_addr = ioremap_wc(prfl_addr, prfl_sz); + if (!(*prfl_img_addr)) + return -ENOMEM; + + *size = prfl_sz; + + return 0; +} + +/* strtoull of "mkexprof" with base:36 */ #define MKEX_END_SIGN 0xdeadbeef static void npc_load_mkex_profile(struct rvu *rvu, int blkaddr, @@ -1142,26 +1166,20 @@ static void npc_load_mkex_profile(struct rvu *rvu, int blkaddr, struct device *dev = &rvu->pdev->dev; struct npc_mcam_kex *mcam_kex; void *mkex_prfl_addr = NULL; - u64 prfl_addr, prfl_sz; + u64 prfl_sz; + int ret; /* If user not selected mkex profile */ if (rvu->kpu_fwdata_sz || !strncmp(mkex_profile, def_pfl_name, MKEX_NAME_LEN)) goto program_mkex; - if (!rvu->fwdata) - goto program_mkex; - prfl_addr = rvu->fwdata->mcam_addr; - prfl_sz = rvu->fwdata->mcam_sz; - - if (!prfl_addr || !prfl_sz) - goto program_mkex; - - mkex_prfl_addr = memremap(prfl_addr, prfl_sz, MEMREMAP_WC); - if (!mkex_prfl_addr) + /* Setting up the mapping for mkex profile image */ + ret = npc_fwdb_prfl_img_map(rvu, &mkex_prfl_addr, &prfl_sz); + if (ret < 0) goto program_mkex; - mcam_kex = (struct npc_mcam_kex *)mkex_prfl_addr; + mcam_kex = (struct npc_mcam_kex __force *)mkex_prfl_addr; while (((s64)prfl_sz > 0) && (mcam_kex->mkex_sign != MKEX_END_SIGN)) { /* Compare with mkex mod_param name string */ @@ -1386,6 +1404,40 @@ static int npc_apply_custom_kpu(struct rvu *rvu, return 0; } +static int npc_load_kpu_profile_fwdb(struct rvu *rvu, const char *kpu_profile) +{ + struct npc_kpu_profile_fwdata *kpu_fw = NULL; + u64 prfl_sz; + int ret; + + /* Setting up the mapping for NPC profile image */ + ret = npc_fwdb_prfl_img_map(rvu, &rvu->kpu_prfl_addr, &prfl_sz); + if (ret < 0) + return ret; + + rvu->kpu_fwdata = + (struct npc_kpu_profile_fwdata __force *)rvu->kpu_prfl_addr; + rvu->kpu_fwdata_sz = prfl_sz; + + kpu_fw = rvu->kpu_fwdata; + if (le64_to_cpu(kpu_fw->signature) == KPU_SIGN && + !strncmp(kpu_fw->name, kpu_profile, KPU_NAME_LEN)) { + dev_info(rvu->dev, "Loading KPU profile from firmware db: %s\n", + kpu_profile); + return 0; + } + + /* Cleaning up if KPU profile image from fwdata is not valid. */ + if (rvu->kpu_prfl_addr) { + iounmap(rvu->kpu_prfl_addr); + rvu->kpu_prfl_addr = NULL; + rvu->kpu_fwdata_sz = 0; + rvu->kpu_fwdata = NULL; + } + + return -EINVAL; +} + static void npc_load_kpu_profile(struct rvu *rvu) { struct npc_kpu_profile_adapter *profile = &rvu->kpu; @@ -1398,19 +1450,47 @@ static void npc_load_kpu_profile(struct rvu *rvu) /* First prepare default KPU, then we'll customize top entries. */ npc_prepare_default_kpu(profile); - dev_info(rvu->dev, "Loading KPU profile from firmware: %s\n", - kpu_profile); + /* Order of preceedence for load loading NPC profile (high to low) + * Firmware binary in filesystem. + * Firmware database method. + * Default KPU profile. + */ if (!request_firmware(&fw, kpu_profile, rvu->dev)) { + dev_info(rvu->dev, "Loading KPU profile from firmware: %s\n", + kpu_profile); rvu->kpu_fwdata = kzalloc(fw->size, GFP_KERNEL); if (rvu->kpu_fwdata) { memcpy(rvu->kpu_fwdata, fw->data, fw->size); rvu->kpu_fwdata_sz = fw->size; } release_firmware(fw); + goto program_kpu; } +load_image_fwdb: + /* Loading the KPU profile using firmware database */ + if (npc_load_kpu_profile_fwdb(rvu, kpu_profile)) + goto revert_to_default; + +program_kpu: /* Apply profile customization if firmware was loaded. */ if (!rvu->kpu_fwdata_sz || npc_apply_custom_kpu(rvu, profile)) { + /* If image from firmware filesystem fails to load or invalid + * retry with firmware database method. + */ + if (rvu->kpu_fwdata || rvu->kpu_fwdata_sz) { + /* Loading image from firmware database failed. */ + if (rvu->kpu_prfl_addr) { + iounmap(rvu->kpu_prfl_addr); + rvu->kpu_prfl_addr = NULL; + } else { + kfree(rvu->kpu_fwdata); + } + rvu->kpu_fwdata = NULL; + rvu->kpu_fwdata_sz = 0; + goto load_image_fwdb; + } + dev_warn(rvu->dev, "Can't load KPU profile %s. Using default.\n", kpu_profile); @@ -1765,7 +1845,10 @@ void rvu_npc_freemem(struct rvu *rvu) kfree(pkind->rsrc.bmap); kfree(mcam->counters.bmap); - kfree(rvu->kpu_fwdata); + if (rvu->kpu_prfl_addr) + iounmap(rvu->kpu_prfl_addr); + else + kfree(rvu->kpu_fwdata); mutex_destroy(&mcam->lock); } -- 2.25.1