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 C2FAB425C9; Mon, 18 Sep 2023 04:48:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 11621410DD; Mon, 18 Sep 2023 04:47:39 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2099.outbound.protection.outlook.com [40.107.244.99]) by mails.dpdk.org (Postfix) with ESMTP id 8AE3D40DDB for ; Mon, 18 Sep 2023 04:47:32 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DmU+rayMYQvn8kQQlTqIUYJ0m2ZVJmN8aUqQxh0BgRofhUQT5m0hKrAG5cY0+41nQ6j4eoUh06Y2kVaGSQmd0UuxVpeDSgAJIxAy0Ra1cgip7eHxtyUzvGExJ5v9RA3/PfqE8LNg9ru7xRwzWUl786pw9WurPN7x2WIzjsMYf1X+p46ZypN9CuMWoqF1mxTSMa7bOoJbNwVhk3ZXFQ5SsKNWhl761lkvtrgva7kOGz+wLZ92qjaink8azEw07z5Oz99wwu9zwv4nrAecCkYbw5HtoA8WwKhD8AVaJaQ/WGkz+zpuOLWnJtBS20QO91ok6Ab3GjwP+fWNg3vja8ZQMQ== 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=MVplEs2sAk92yGMmVcIf5pLy07SQG2SerBo5PzMxvJ4=; b=mKLA1MGIr6THYj580BBtinbGpnLgKLG/LotLiYtjhUoC9SFX3fMCOAwXsNk3ABO6ME9zrOFSZy5vH+iYKIzn2Fh2KmebBsAfvmPzbF5t5xS63vd91WZZX2p+Bnyg9NlyUjB/lWuqov0UU9J7NVb3i6FHPulrxHGNgO8BMiyITjgwGBVKHmMY4NFqbIjOlEzHF8Csd0jgakKQjQyA370FcULuoSh75IP8sJBMBlUYPsnRYsQqm30Lb+COiw4oKY81O4aUa3qK3PZ1CiFdGsEvJUz0r6X7P4b1qhvxYqsQGDbJgw+kXMRHgVLRKSJanomqKfNEfh7eSSiXN+vI1kkh9Q== 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=MVplEs2sAk92yGMmVcIf5pLy07SQG2SerBo5PzMxvJ4=; b=srwRFZM7ECLYGp2vGBbXjFjf/P/bnbRTt1fAto8YyxEPkUaqHQhKvcAY1p6vjLRnYcuE6aQWAuTk7ZBVbN2DclctcPglY7ole9N/VmoaBtriPhFmmTeVh1oyhtRELOqZ83R2VducG9aFKXFDmpvDOU/Iyn9omkiSlDnElilf+lE= 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:31 +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:31 +0000 From: Chaoyong He To: dev@dpdk.org Cc: Chaoyong He , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v4 11/26] net/nfp: refact the hwinfo module Date: Mon, 18 Sep 2023 10:45:57 +0800 Message-Id: <20230918024612.1600536-12-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> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 367c3d78-49eb-42e8-6de1-08dbb7f19a75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8jRCmePA/0SVMf7rYOx4L1OwF+5EO6asp1YdVLGITcvN3zm3xgjAr5sb/BtzGiwh9gZSiWdUsHFS7h3zdzZYGcF5inhMfgrrV+ah7iJd6YcLDH+VmMgc6YpucEoW9cjVo9YMPxr0PhpytzRwp/DaXNb00DFDFPKayJFl8Wa/oX54UKv7i0KwhODH5Bom8llnniNsDx54iIgLzDpiKMJZVTnIboPX+7+EVVyZji8wzonb1fljVGOaY1OnrlXU426zn+0HKmBzIHd6oWKS34J4Wxnsm/PY/ZT7RAyamh8k0ewaz4hDslubybSfBTL0WClncE2NPEct/7po/FpJ74WlIeBu5ahZmKM/iuVeOg09XOH4ITUiZDeJ/2h8+W/PWGOvFooHcIl1XSu5BflHLSZdFbD3M8l2K7AVlcc/TEjULWeRdBBNKM9xOTAh4r7cTncWc3MGgkquaFkt0iUaML960gUg75qpFJ/CSJNSrmZnAHEXIM4dscw9zR2j7EMfm6rZ8XOebGIFP/sxnEQQNjX23g22PhXgnPdWY5la4m9dDEIj04EtojHJ8UBwQTEeh+xaisu4ak9yOEHu4kqK55835MjBDhsU1ZBHiYm4vh1zSMYr3gNgcK3ScU+NpdiCcHdpAiYLedaViUJ+ccrgwxj7DrwhlZH8ons0n98yApYrMLs= 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)(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?B?WnpKNDZFZ2JBVjFMNWtQUkNtRUFEZ3JXYndYalVPZGFwMGVGMGE1NkVkV012?= =?utf-8?B?SVVySkxhQURnMGRScC9wcVhxTFJYdmlpQ3VlQUhJUytTZXZQNmF1d3VidUpj?= =?utf-8?B?UGltK0pLTUNVR24yUDVTZFhibTZ3QXZTeWxwQVhsaGZsemd2VHZ2anhhcitW?= =?utf-8?B?Q2kweHcydHpUTW5YMmpsVUdWWEZ1Vy95dStjWC9CYkY2SjVnZy9RbkxCQk5j?= =?utf-8?B?K1BiRlUyQWMzYkNYMVJNREE2SEh6R25iMkhERURWVGROa2pITUZRYVRpT2lJ?= =?utf-8?B?VUg2QTZlQVNKcG9LcDlEcmRaWTdPUXJDd3lYeWR5b3lLV3MrWmtPU0REV3FO?= =?utf-8?B?UHQvcEgxaVdPdjlzY09r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TVM?= =?utf-8?B?dFE9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 367c3d78-49eb-42e8-6de1-08dbb7f19a75 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:31.1075 (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: eoTivIpWqvzQERjh+OwNYg3rYON4D4O/4cdjqxLsZgDioCOBuHHdRf41YSZ5Evgs0/Yhq08UfJaGsxtZCdhk5gsviYCXg+7QAGtd9NqgOlQ= 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 Move the definition of data structure and macro into the implement file. Also remove the unneeded header file include statements. Signed-off-by: Chaoyong He Reviewed-by: Niklas Söderlund --- drivers/net/nfp/nfpcore/nfp_hwinfo.c | 84 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_hwinfo.h | 71 +---------------------- 2 files changed, 77 insertions(+), 78 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.c b/drivers/net/nfp/nfpcore/nfp_hwinfo.c index e33e660ea9..c334202bd7 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.c +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.c @@ -17,17 +17,82 @@ * (ie, in this example, ME 39 has been reserved by boardconfig.) */ -#include -#include +#include "nfp_hwinfo.h" -#include "nfp_cpp.h" +#include "nfp_crc.h" #include "nfp_logs.h" -#include "nfp6000/nfp6000.h" #include "nfp_resource.h" -#include "nfp_hwinfo.h" -#include "nfp_crc.h" -static int +#define HWINFO_SIZE_MIN 0x100 + +/* + * The Hardware Info Table defines the properties of the system. + * + * HWInfo v1 Table (fixed size) + * + * 0x0000: uint32_t version Hardware Info Table version (1.0) + * 0x0004: uint32_t size Total size of the table, including the + * CRC32 (IEEE 802.3) + * 0x0008: uint32_t jumptab Offset of key/value table + * 0x000c: uint32_t keys Total number of keys in the key/value table + * NNNNNN: Key/value jump table and string data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * HWInfo v2 Table (variable size) + * + * 0x0000: uint32_t version Hardware Info Table version (2.0) + * 0x0004: uint32_t size Current size of the data area, excluding CRC32 + * 0x0008: uint32_t limit Maximum size of the table + * 0x000c: uint32_t reserved Unused, set to zero + * NNNNNN: Key/value data + * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) + * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE + * + * If the HWInfo table is in the process of being updated, the low bit of + * version will be set. + * + * HWInfo v1 Key/Value Table + * ------------------------- + * + * The key/value table is a set of offsets to ASCIIZ strings which have + * been strcmp(3) sorted (yes, please use bsearch(3) on the table). + * + * All keys are guaranteed to be unique. + * + * N+0: uint32_t key_1 Offset to the first key + * N+4: uint32_t val_1 Offset to the first value + * N+8: uint32_t key_2 Offset to the second key + * N+c: uint32_t val_2 Offset to the second value + * ... + * + * HWInfo v2 Key/Value Table + * ------------------------- + * + * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' + * Unsorted. + * + * Note: Only the HwInfo v2 Table be supported now. + */ + +#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) +#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) + +struct nfp_hwinfo { + uint8_t start[0]; + + uint32_t version; + uint32_t size; + + /* V2 specific fields */ + uint32_t limit; + uint32_t resv; + + char data[]; +}; + +static bool nfp_hwinfo_is_updating(struct nfp_hwinfo *hwinfo) { return hwinfo->version & NFP_HWINFO_VERSION_UPDATING; @@ -120,7 +185,7 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, goto exit_free; } - header = (void *)db; + header = (struct nfp_hwinfo *)db; if (nfp_hwinfo_is_updating(header)) goto exit_free; @@ -133,7 +198,8 @@ nfp_hwinfo_try_fetch(struct nfp_cpp *cpp, /* NULL-terminate for safety */ db[*cpp_size] = '\0'; - return (void *)db; + return (struct nfp_hwinfo *)db; + exit_free: free(db); return NULL; diff --git a/drivers/net/nfp/nfpcore/nfp_hwinfo.h b/drivers/net/nfp/nfpcore/nfp_hwinfo.h index 543562779a..c812f10076 100644 --- a/drivers/net/nfp/nfpcore/nfp_hwinfo.h +++ b/drivers/net/nfp/nfpcore/nfp_hwinfo.h @@ -6,76 +6,9 @@ #ifndef __NFP_HWINFO_H__ #define __NFP_HWINFO_H__ -#include +#include "nfp_cpp.h" -#define HWINFO_SIZE_MIN 0x100 - -/* - * The Hardware Info Table defines the properties of the system. - * - * HWInfo v1 Table (fixed size) - * - * 0x0000: uint32_t version Hardware Info Table version (1.0) - * 0x0004: uint32_t size Total size of the table, including the - * CRC32 (IEEE 802.3) - * 0x0008: uint32_t jumptab Offset of key/value table - * 0x000c: uint32_t keys Total number of keys in the key/value table - * NNNNNN: Key/value jump table and string data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * HWInfo v2 Table (variable size) - * - * 0x0000: uint32_t version Hardware Info Table version (2.0) - * 0x0004: uint32_t size Current size of the data area, excluding CRC32 - * 0x0008: uint32_t limit Maximum size of the table - * 0x000c: uint32_t reserved Unused, set to zero - * NNNNNN: Key/value data - * (size - 4): uint32_t crc32 CRC32 (same as IEEE 802.3, POSIX csum, etc) - * CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE - * - * If the HWInfo table is in the process of being updated, the low bit of - * version will be set. - * - * HWInfo v1 Key/Value Table - * ------------------------- - * - * The key/value table is a set of offsets to ASCIIZ strings which have - * been strcmp(3) sorted (yes, please use bsearch(3) on the table). - * - * All keys are guaranteed to be unique. - * - * N+0: uint32_t key_1 Offset to the first key - * N+4: uint32_t val_1 Offset to the first value - * N+8: uint32_t key_2 Offset to the second key - * N+c: uint32_t val_2 Offset to the second value - * ... - * - * HWInfo v2 Key/Value Table - * ------------------------- - * - * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000' - * Unsorted. - * - * Note: Only the HwInfo v2 Table be supported now. - */ - -#define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0) -#define NFP_HWINFO_VERSION_UPDATING RTE_BIT32(0) - -struct nfp_hwinfo { - uint8_t start[0]; - - uint32_t version; - uint32_t size; - - /* v2 specific fields */ - uint32_t limit; - uint32_t resv; - - char data[]; -}; +struct nfp_hwinfo; struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp); -- 2.39.1