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 BFDB8430EF; Thu, 24 Aug 2023 13:12:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 56E084327E; Thu, 24 Aug 2023 13:11:11 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2123.outbound.protection.outlook.com [40.107.93.123]) by mails.dpdk.org (Postfix) with ESMTP id CA41D4326F for ; Thu, 24 Aug 2023 13:11:09 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lIR+mhhOP7X9vsczC9LdcTs+L5FPzeNES1iEYhFzcav8BO0hMFMA+cnAPJQFfy+A4EA9393aTYeVZcLm+vJUF9GHQnWJel4dfWBNw1w0cbzmvqGd0F8wvestdTKfWx1oT5KUHK6qeWyZ6i2OseZ069HIdS95j0cNfRt2NW/Ro8QWxwSZ4wwy6ytTYSGs0dsj2zhjnVh2xBkKxRf1ywOUgr1aT7Z1l2tCyNJ8/J+5O9ImUbTfYVtF8CvkK1mc0Q58X4WKvdv2+DWyjcW4aMNNWDuZELPieIRqaH/hY6H20keFpFWD3fXpLM8/CavJuPrkJ9TDYziyX4CrdDxJ+IXwHA== 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=+yvZDG2HDEPnYtWF1Wkl+yal9KI7LdfqgZhh7PgB9Zg=; b=RHM5kBUFXI44Rqo6zJ0TRLrzf+XVMgYDUfHZztpEQfSnEnkrt98kg65BBO35BvD+nNDezyLKRhy+aV1TsR7NC7wz6j8/EtJ9JOa1Do0Ek2DzITjmC7KT5kSmpTyY4RelyTmjj+piLEWoLmIClcLQs/bMWE3Dfsoa8s4fs7enUIKieMKtpFffHBJnV/RuLzXorxlYFd1Y79RNAxAwLLct6h/OAYCk1rJN4mztJcb3oMnGx5SC5lN3CYgswheqpk92RSAO2GoT10eGjDD1SAXePzl9iGkQ6jfE9rW7BTZCDUGaptickDwPKZ/hOIFxUB+2OnSnpKxBvq3qKm1Jbm8HYg== 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=+yvZDG2HDEPnYtWF1Wkl+yal9KI7LdfqgZhh7PgB9Zg=; b=iGCMQi8qcjgE4z6WsHHG9yEaixUb8R3cLqBysRvNd8V6WyQ8YNohTvyZKhVCytUbY7B1UEpIarIuxwO31o2P/2jtJDXyAZJeYKy6wuyl5OKMggBshOlo73N/pImi8hiK7hxIm11xECrg6Pu5A6P4TjOHNVJg9XIPScHR9iDJfDA= 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 PH7PR13MB6116.namprd13.prod.outlook.com (2603:10b6:510:2b7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Thu, 24 Aug 2023 11:11:07 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::51fe:5846:af8b:bace]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::51fe:5846:af8b:bace%3]) with mapi id 15.20.6699.020; Thu, 24 Aug 2023 11:11:07 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com, Chaoyong He Subject: [PATCH 12/27] net/nfp: refact the hwinfo module Date: Thu, 24 Aug 2023 19:09:41 +0800 Message-Id: <20230824110956.1943559-13-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230824110956.1943559-1-chaoyong.he@corigine.com> References: <20230824110956.1943559-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SJ0PR05CA0005.namprd05.prod.outlook.com (2603:10b6:a03:33b::10) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB6116:EE_ X-MS-Office365-Filtering-Correlation-Id: 0291c559-a0da-470c-01d2-08dba492d08c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XIEBlLZmRLkRETNT19fCD7AI3ymoKRPTFOAdNXR4Cx3avjHR++ZvcW7rscUoUhnqM+QycUNzz7qfgGN60ek74qnbLfQup87toIJ22D0+OGGb+ZlSRJgS/yK9rnnmy4w3iL8xijNfP+WLMOE3z7szo/oFs/DeRFdCG1pXMgINTvFkqoJNNsXSknTbF91yUnKP46KrVDUED0K55X535lRPyFrBUUzsGheuHCYYj9EGTIKBcoZZPcwc48dvshO0Zg4Oe3YWr+9K+5cW7iu9VF2K9wqLmLXREKEFZ7yY2tZjBJuOYcJ9wgaUutrroyQSNDZYBOZB1IMINqQ3UJrKeDv7n5HcKQYwhEvjXwXWmYOwu9J4wxedTyBV2b3bw44k7CBmtaYlo/owGhwaGemK9FiuMQkR/Bs6fciouOeWc6SXkQQK3WI+afw2zpwn8oNIuZF9gsBJo4HOZmXOEr1jJTGHcsxCeHlOksMZJELFaTxpnsmkW2XwUjatN/m0iMGrd8N+J8K+auWv/HH4oORPGBA3Y27cQgU42MEvvhNno9lSisVD1MPUSSnSnRRDH4IZcfUn6+iTA7+GBjugyegEwIyNYJPDQEJioZbAQgi61R0Cn5eFFDKXEaiNPh3nBE7mMOMRLbqT56LYZ1GWpvWVYZpx9w0Ntu3Brgt5hd7s71NyQ16qje4aVSe4GQnW8hyKlmCK 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)(366004)(39830400003)(346002)(396003)(136003)(376002)(1800799009)(186009)(451199024)(6506007)(26005)(1076003)(2616005)(107886003)(52116002)(12101799020)(6512007)(66574015)(6486002)(83380400001)(38100700002)(8676002)(8936002)(36756003)(316002)(4326008)(41300700001)(2906002)(86362001)(5660300002)(44832011)(38350700002)(6666004)(6916009)(478600001)(66476007)(66946007)(66556008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?QlBpbEpCSVlVNWRRUEhla2I0SmkrVEtQY0ZrZlhPYkxmSkxZSitHWU9ueEht?= =?utf-8?B?Q1RNY2FERjNHb05iSEFJRU92ZnYxRDZiWGdKeWVvaTFIdlk3cmdHZ1N2WlNy?= =?utf-8?B?S1BYT0F3TndTeXZERUJyZFM5aXBaZmZGTTQxNXFZRjNxdzBTdUwrYmROUmhN?= =?utf-8?B?cld1QTM1MEhaOHg4MXdPOWZKMlUxdnJlU0doNUMyYWJiNG0vZ1ZzU1hBUnpQ?= =?utf-8?B?VHRMTWo1d0Noc0p4SzJrdC9pQ1krR2tMbDFUcWdZMHVHU01zb2w3eHZvRENw?= =?utf-8?B?VHFRd0ZMUDgxY1ROZmt6WVBDWlVWRnVKNURNWEhsVHNYaE9wK09rNTNxL3RO?= =?utf-8?B?NE5lU1QrdFN0dGVs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05o?= =?utf-8?B?VUE9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0291c559-a0da-470c-01d2-08dba492d08c X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2023 11:11:07.7449 (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: HXZS0b7dWutg2Om/shsjkxtZE4O3sfLMAiH5jRRJ7SbrSqPQDGxpNdVtTcpPZV4YxitRuSt/k6tAo1uMzbBy+4ImBL1gX4KF1f5Lkgvk9Gg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB6116 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 cee37210b0..25c2262dfc 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: rte_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