From patchwork Mon Sep 18 02:46:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chaoyong He X-Patchwork-Id: 131548 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0B1E9425C9; Mon, 18 Sep 2023 04:49:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 81E37410FD; Mon, 18 Sep 2023 04:47:43 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2110.outbound.protection.outlook.com [40.107.244.110]) by mails.dpdk.org (Postfix) with ESMTP id D016A40EF0 for ; Mon, 18 Sep 2023 04:47:37 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GB9kUQp6ddhW4bU80R7IlzVznPlywnGfXKxnX2LH2OvEwKCHZ2Ef07sCqTlg1cofNvXLhUEd+FkfkK3FwBz7jjwyvFWso+dZSyiRp6hlaEmGPiqn6ivtSZ/5tSARYbIlYp+lsH7vDweAxnOvWq+2kNguDu1Dm2Hz7NtW2mL4v0HgajAJ6C9fZcOv0ZrD7P+2rY/EPjCvEyohpr2ChtoTOCyhF7rg9xL35SNZlkcVRGzJfZ6IfCUEcGoJTG1rfB4KDo5UFjy/5joQ/nsGV09URO8Gubdqax/XKmaJiqbqcgEz4iek6wKK3fwJBESCPuQcKhBy/Y1+fzG0ih1sZt9MfA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OdpEP/UyAGqz4oxHPFVDbYOKsAIafOJKB5CG4krDax0=; b=l7Qsyfqub5hXF4fwLc4a2XNdglaq/2V5GE13C+Wm86crmYZQ8YJsNpEyD15pIhXCJHiEpaSSy+0exerDZKnZ3lAWfxo4HNWNR7r3DKjCTtnVJXxGbJb6FYCyf8gLGopW5D1PL6I1Hd4EwftdPxSvcW3Z+rZVK7sVMHLIkdsngBo6sjRqe5tjChmyDFcz44Jd4N80XIF3cUbQsAv8PR7sbfJE+d9fgLVndacByxPOc/gj4Ov643FrZVKIeqaYs0JYAJeXETlKDF9WJWmT2Mkz+AuuaKANl2PG70kcHmxhrKckAadCz0/4T7N8Hkv4k5nWO9/2u510afVnufoP3jkS5g== 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=OdpEP/UyAGqz4oxHPFVDbYOKsAIafOJKB5CG4krDax0=; b=mwFBVC+G2ErjLmmTxMCY2hyDgZ808/GYAQ0v72rZ7LzSyL/LprCBJdqIrNy3lEqHLFUCc4Tw27fYzrVzkDdKYYK7KaozBzW2nLtjS4uVsIzBe0KxpB6ALWXbzWkP6Pnr41N5l1eeOfGzLT+HyFyxdCu4ZWgdxJ/xBqYncDU5Moo= 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 PH7PR13MB6435.namprd13.prod.outlook.com (2603:10b6:510:2ea::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 02:47:36 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7a1c:2887:348a:84bd]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7a1c:2887:348a:84bd%6]) with mapi id 15.20.6792.026; Mon, 18 Sep 2023 02:47:36 +0000 From: Chaoyong He To: dev@dpdk.org Cc: Chaoyong He , =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH v4 14/26] net/nfp: refact the rtsym module Date: Mon, 18 Sep 2023 10:46:00 +0800 Message-Id: <20230918024612.1600536-15-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230918024612.1600536-1-chaoyong.he@corigine.com> References: <20230915091551.1459606-1-chaoyong.he@corigine.com> <20230918024612.1600536-1-chaoyong.he@corigine.com> X-ClientProxiedBy: SE2P216CA0016.KORP216.PROD.OUTLOOK.COM (2603:1096:101:114::20) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB6435:EE_ X-MS-Office365-Filtering-Correlation-Id: 7467605a-7ae9-4b41-eaf3-08dbb7f19d61 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mtSPadIZdvzK/9IMW0OKh0Y3neP11g5fK0fkYMUQgi9oaCr1HNCZVAtc/cpm7t83zGw917UAFyPNvO+MwmpAoducYKizkpgDldI6ImurvxeepNh4pfRh6260IYGvJqk/6W7ZC5FJb9MgA7e3YJa0A/QSYFCUUUXPPZYkjRX1Ip7JpufD639pE1CzGjmCZxQuR4wCFxizoAOSMsXHSkAYrEP81UQrvnb6iUi01pZWdrGxD7JHdKBu54O4yfJpvoOhmsCNefkNihNegzaDA3y/OgEiTaTfnhbJYseg1JcYuy4+Smi9aqcL062IirMPi3BPq5VZvrFNqohpFTD+8bmqD0G44cDsPjZczP+7gYco2vy1WRCg8tHyrN04sMlu/AjseXSPh2GGS3qOu3QaJL7W03MgYASqAA9Urt8TrfpuAE6ulIEKMZtPcQG6vHdljUxiRRfg8HZCvw2Hu2WO5lUxifM7lAGZzJqZcFlWRXsrYGENq0i2qd/2r4e65t+4A1/29GG4ODHj39PGHvRKiZI6d7fYI37viLKg/I9HgkqKzKUgdZc4GLS3moi7/Zs1QB8snFBgn7kl0EISTcbZUaX+tkWSNa/kjR2q0MHQIwdyxggdb25beOfyBL3m/yqAojfWSRzeiBZYqv3ijufK156sR0apWYbUMU3wIyZkG6JHnFM= 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:(13230031)(39830400003)(136003)(346002)(366004)(376002)(396003)(1800799009)(451199024)(186009)(54906003)(66476007)(66946007)(66574015)(41300700001)(6916009)(316002)(8676002)(4326008)(8936002)(52116002)(6506007)(6486002)(6512007)(478600001)(6666004)(83380400001)(26005)(1076003)(2616005)(107886003)(86362001)(2906002)(30864003)(44832011)(38100700002)(38350700002)(5660300002)(36756003)(66556008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?9dZSVi2fESJdzEEdmm0EYE3oSzlA?= =?utf-8?q?MCjDWdhsYzcMZvZHKFuFhYtWR5LwPsxdZQD2QmFT6LrhcJceEYzG1CLj0uZpcqNn1?= =?utf-8?q?Tn7abOpphd7mm48TbfqgaHhTyuuL8EJKeHY5TrvRiY8+QqxOIXzylRM2Xiy06Hap8?= =?utf-8?q?5eSmqkrV33/emBpL/IuHKzdks7rh2hlAwe2Ri+2xez/ui+GJE2sDMJJz9bPjrpRoP?= =?utf-8?q?5V8U8dcx7BjoTsKBxbYTLFv09gT8YL4zgqJyKVKC7lZKfA9yeItZb2J9D7AO+XZYT?= =?utf-8?q?TVzfQvjVov5ilLtfAGNjpL0V9cIB5C4RgZNmLYgI8pjinnHQhyZbbNaD+ZuzSbCNz?= =?utf-8?q?Afv1EFpNytGSB21Kr4jtrfU1zrZu+DDm8ZvMtT3lo/J5MRdCMZNqD5TjWHT2UKEHi?= =?utf-8?q?uTbCnd83nrBhWUKROCM/eoTnNE/e+RD4jnVciQYUX0DutKFAn2U44MMU6XZYuJ6Bm?= =?utf-8?q?kfpXoM5cvJLXj0NGHugpA37sP2h2I0b5w/ix9ypj8clXftLuUpIhALfgaNxhpSmT4?= =?utf-8?q?0e38RgxuvAps7xUFxTlcaWkbWmIyFjB3sfiI1hAExSfhmo5lEhy0WF7HSArEAL+8/?= =?utf-8?q?p9flh5pbiYwXf0fEB57cd6BI/yixjRQsv/c8kYa9C5GxG59vzBxNMCrdPrlOxUfL6?= =?utf-8?q?JEW4JUnNEhtY0GcqJnggtmsTuI+DEM5q0B112XDXm7oPs68B65ow4gClO6qDZUscc?= =?utf-8?q?2biGSk8rICIILx7VxIPKv/VgrLvnmlnFoHC931vT3/JnUi8VsUaj6BTV9CLLnFdFJ?= =?utf-8?q?0r3i2+LhwdwEiMTiQC4snKe+qphac64M+pjyMio3YBkHcUfuy2W8Czk0X7cQbgIe7?= =?utf-8?q?Mx+VDiGXV6n1d+0uaC++txWAN6hfk6e/P8XVgzmxW2m1eTAz8gIzVdku5cq0FYW0F?= =?utf-8?q?GBh4g+3DeqSZlYrm/wp+v2JKHzwds+9wrLw0SEtoN8DmLW++PRkpX2kfChnaAz3tv?= =?utf-8?q?CcZfaSelCmKCDP63rT0EfrKGp5YPV4K4pDCSBEtC0cIessXtP1y1HhoU2UJsPeHgf?= =?utf-8?q?m8NS7wPYHZ76BrxQK/W7Eo00TN4Ru6YKbLnw3+CWK8MgH6o/TYX31rw0CK5zDwga6?= =?utf-8?q?NL54rIa+391hSEXuQ3brn4AQP0vGoVCyZ0PnbUKF14VsLmY8gI95jFQi38sHzVlt9?= =?utf-8?q?hEld0t6O0oiCnVrrhjutZ7DW2yZuhSzD7ah7lIsqsCnDfuR95OdYgPEO68cd/pW8m?= =?utf-8?q?qxbCAQAdlATeDg2T0kYE69EkyZnnBgQ4fUXMUh2KGI0V4QP+Lyxovps/FJ/Pfqrz+?= =?utf-8?q?OHU71+/lgCf+YiZQozX1ctx7DiEzV0jAVsvG4SfAeCKE1Vg4V2eCHEBQV+b0cZliB?= =?utf-8?q?bcwm9Gbzbyzo7bbiWl1lojM/ay9ZXTmphfTwAbLF3bAd5ZBUY6dmuBeBPu2IABQol?= =?utf-8?q?X1ICHrnyXqdHBgJgukFoACTwPX0IScxfA+Olpi5ICh1cwcU9Ol7dkiKNe4aSuAN6q?= =?utf-8?q?dd0Khtq5tUERFpgi3+4rd07vkhI3dr6zjxxFbPzzskfIA0Gh8OC3YWAortePZJLSg?= =?utf-8?q?+XgdRljOmLWEA8YBjniQw4P+uFUNsDqSMw=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7467605a-7ae9-4b41-eaf3-08dbb7f19d61 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 02:47:36.1198 (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: Cw9hS1TDiHgpnjiEK2LwE6+SVcfjcs5cvr1y2H8yFIZiv97/nN5ezsxPUpRJy3subZKUXJpSijAF2lgauM8JnNaZ4Tuwh91tqsDRm7E5m7k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB6435 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 Add several read/write APIs and remove the unneeded header file include statements. Signed-off-by: Chaoyong He Reviewed-by: Niklas Söderlund --- drivers/net/nfp/nfpcore/nfp_rtsym.c | 305 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 53 ++--- 2 files changed, 299 insertions(+), 59 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 37811ceaeb..2d4100dda2 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -8,14 +8,25 @@ * Interface for accessing run-time symbol table */ -#include +#include "nfp_rtsym.h" + #include -#include "nfp_cpp.h" + #include "nfp_logs.h" #include "nfp_mip.h" -#include "nfp_rtsym.h" #include "nfp6000/nfp6000.h" +enum nfp_rtsym_type { + NFP_RTSYM_TYPE_NONE, + NFP_RTSYM_TYPE_OBJECT, + NFP_RTSYM_TYPE_FUNCTION, + NFP_RTSYM_TYPE_ABS, +}; + +#define NFP_RTSYM_TARGET_NONE 0 +#define NFP_RTSYM_TARGET_LMEM -1 +#define NFP_RTSYM_TARGET_EMU_CACHE -7 + /* These need to match the linker */ #define SYM_TGT_LMEM 0 #define SYM_TGT_EMU_CACHE 0x17 @@ -32,6 +43,30 @@ struct nfp_rtsym_entry { uint32_t size_lo; }; +/* + * Structure describing a run-time NFP symbol. + * + * The memory target of the symbol is generally the CPP target number and can be + * used directly by the nfp_cpp API calls. However, in some cases (i.e., for + * local memory or control store) the target is encoded using a negative number. + * + * When the target type can not be used to fully describe the location of a + * symbol the domain field is used to further specify the location (i.e., the + * specific ME or island number). + * + * For ME target resources, 'domain' is an MEID. + * For Island target resources, 'domain' is an island ID, with the one exception + * of "sram" symbols for backward compatibility, which are viewed as global. + */ +struct nfp_rtsym { + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + enum nfp_rtsym_type type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ +}; + struct nfp_rtsym_table { struct nfp_cpp *cpp; int num; @@ -80,21 +115,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->domain = -1; } -struct nfp_rtsym_table * -nfp_rtsym_table_read(struct nfp_cpp *cpp) -{ - struct nfp_mip *mip; - struct nfp_rtsym_table *rtbl; - - mip = nfp_mip_open(cpp); - rtbl = __nfp_rtsym_table_read(cpp, mip); - nfp_mip_close(mip); - - return rtbl; -} - -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, +static struct nfp_rtsym_table * +nfp_rtsym_table_read_real(struct nfp_cpp *cpp, const struct nfp_mip *mip) { int n; @@ -162,6 +184,19 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } +struct nfp_rtsym_table * +nfp_rtsym_table_read(struct nfp_cpp *cpp) +{ + struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; + + mip = nfp_mip_open(cpp); + rtbl = nfp_rtsym_table_read_real(cpp, mip); + nfp_mip_close(mip); + + return rtbl; +} + /** * Get the number of RTSYM descriptors * @@ -287,7 +322,59 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, } static int -nfp_rtsym_readl(struct nfp_cpp *cpp, +nfp_rtsym_read_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' read out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + if (sym->type == NFP_RTSYM_TYPE_ABS) { + union { + uint64_t value_64; + uint8_t value_8[8]; + } tmp; + + tmp.value_64 = sym->addr; + memcpy(buf, &tmp.value_8[offset], length); + + return length; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_read(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_read(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_read_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_readl_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -310,8 +397,17 @@ nfp_rtsym_readl(struct nfp_cpp *cpp, return nfp_cpp_readl(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readl(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t *value) +{ + return nfp_rtsym_readl_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + static int -nfp_rtsym_readq(struct nfp_cpp *cpp, +nfp_rtsym_readq_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -339,6 +435,121 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t *value) +{ + return nfp_rtsym_readq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_write_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_write(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_write(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_write_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_writel_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint32_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 4 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writel(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writel(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t value) +{ + return nfp_rtsym_writel_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_writeq_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint64_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 8 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writeq(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writeq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t value) +{ + return nfp_rtsym_writeq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + /** * Read a simple unsigned scalar value from symbol * @@ -374,11 +585,11 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, switch (sym->size) { case 4: - err = nfp_rtsym_readl(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val32); + err = nfp_rtsym_readl(rtbl->cpp, sym, 0, &val32); val = val32; break; case 8: - err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); + err = nfp_rtsym_readq(rtbl->cpp, sym, 0, &val); break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", @@ -387,8 +598,6 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, break; } - if (err) - err = -EIO; exit: if (error != NULL) *error = err; @@ -399,6 +608,54 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, return val; } +/** + * Write an unsigned scalar value to a symbol + * + * Lookup a symbol and write a value to it. Symbol can be 4 or 8 bytes in size. + * If 4 bytes then the lower 32-bits of 'value' are used. Value will be + * written as simple little-endian unsigned value. + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param value + * Value to write + * + * @return + * 0 on success or error code. + */ +int +nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, + const char *name, + uint64_t value) +{ + int err; + uint64_t sym_size; + const struct nfp_rtsym *sym; + + sym = nfp_rtsym_lookup(rtbl, name); + if (sym == NULL) + return -ENOENT; + + sym_size = nfp_rtsym_size(sym); + switch (sym_size) { + case 4: + err = nfp_rtsym_writel(rtbl->cpp, sym, 0, value); + break; + case 8: + err = nfp_rtsym_writeq(rtbl->cpp, sym, 0, value); + break; + default: + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", + name, sym_size); + err = -EINVAL; + break; + } + + return err; +} + uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index fdde1eb75b..f79637ac50 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -6,46 +6,13 @@ #ifndef __NFP_RTSYM_H__ #define __NFP_RTSYM_H__ -#define NFP_RTSYM_TYPE_NONE 0 -#define NFP_RTSYM_TYPE_OBJECT 1 -#define NFP_RTSYM_TYPE_FUNCTION 2 -#define NFP_RTSYM_TYPE_ABS 3 - -#define NFP_RTSYM_TARGET_NONE 0 -#define NFP_RTSYM_TARGET_LMEM -1 -#define NFP_RTSYM_TARGET_EMU_CACHE -7 - -/* - * Structure describing a run-time NFP symbol. - * - * The memory target of the symbol is generally the CPP target number and can be - * used directly by the nfp_cpp API calls. However, in some cases (i.e., for - * local memory or control store) the target is encoded using a negative number. - * - * When the target type can not be used to fully describe the location of a - * symbol the domain field is used to further specify the location (i.e., the - * specific ME or island number). - * - * For ME target resources, 'domain' is an MEID. - * For Island target resources, 'domain' is an island ID, with the one exception - * of "sram" symbols for backward compatibility, which are viewed as global. - */ -struct nfp_rtsym { - const char *name; /**< Symbol name */ - uint64_t addr; /**< Address in the domain/target's address space */ - uint64_t size; /**< Size (in bytes) of the symbol */ - int type; /**< NFP_RTSYM_TYPE_* of the symbol */ - int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ - int domain; /**< CPP target domain */ -}; +#include "nfp_cpp.h" +struct nfp_rtsym; struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, - const struct nfp_mip *mip); - int nfp_rtsym_count(struct nfp_rtsym_table *rtbl); const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); @@ -53,8 +20,24 @@ const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name); +int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t *value); +int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t *value); + +int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t value); +int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t value); + uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); +int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name, + uint64_t value); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area);