New upstream version 18.08
[deb_dpdk.git] / drivers / net / nfp / nfpcore / nfp_hwinfo.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Netronome Systems, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef __NFP_HWINFO_H__
7 #define __NFP_HWINFO_H__
8
9 #include <inttypes.h>
10
11 #define HWINFO_SIZE_MIN 0x100
12
13 /*
14  * The Hardware Info Table defines the properties of the system.
15  *
16  * HWInfo v1 Table (fixed size)
17  *
18  * 0x0000: uint32_t version             Hardware Info Table version (1.0)
19  * 0x0004: uint32_t size                Total size of the table, including the
20  *                                      CRC32 (IEEE 802.3)
21  * 0x0008: uint32_t jumptab             Offset of key/value table
22  * 0x000c: uint32_t keys                Total number of keys in the key/value
23  *                                      table
24  * NNNNNN:                              Key/value jump table and string data
25  * (size - 4): uint32_t crc32   CRC32 (same as IEEE 802.3, POSIX csum, etc)
26  *                              CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE
27  *
28  * HWInfo v2 Table (variable size)
29  *
30  * 0x0000: uint32_t version             Hardware Info Table version (2.0)
31  * 0x0004: uint32_t size                Current size of the data area, excluding
32  *                                      CRC32
33  * 0x0008: uint32_t limit               Maximum size of the table
34  * 0x000c: uint32_t reserved            Unused, set to zero
35  * NNNNNN:                      Key/value data
36  * (size - 4): uint32_t crc32   CRC32 (same as IEEE 802.3, POSIX csum, etc)
37  *                              CRC32("",0) = ~0, CRC32("a",1) = 0x48C279FE
38  *
39  * If the HWInfo table is in the process of being updated, the low bit of
40  * version will be set.
41  *
42  * HWInfo v1 Key/Value Table
43  * -------------------------
44  *
45  *  The key/value table is a set of offsets to ASCIIZ strings which have
46  *  been strcmp(3) sorted (yes, please use bsearch(3) on the table).
47  *
48  *  All keys are guaranteed to be unique.
49  *
50  * N+0: uint32_t key_1          Offset to the first key
51  * N+4: uint32_t val_1          Offset to the first value
52  * N+8: uint32_t key_2          Offset to the second key
53  * N+c: uint32_t val_2          Offset to the second value
54  * ...
55  *
56  * HWInfo v2 Key/Value Table
57  * -------------------------
58  *
59  * Packed UTF8Z strings, ie 'key1\000value1\000key2\000value2\000'
60  *
61  * Unsorted.
62  */
63
64 #define NFP_HWINFO_VERSION_1 ('H' << 24 | 'I' << 16 | 1 << 8 | 0 << 1 | 0)
65 #define NFP_HWINFO_VERSION_2 ('H' << 24 | 'I' << 16 | 2 << 8 | 0 << 1 | 0)
66 #define NFP_HWINFO_VERSION_UPDATING     BIT(0)
67
68 struct nfp_hwinfo {
69         uint8_t start[0];
70
71         uint32_t version;
72         uint32_t size;
73
74         /* v2 specific fields */
75         uint32_t limit;
76         uint32_t resv;
77
78         char data[];
79 };
80
81 struct nfp_hwinfo *nfp_hwinfo_read(struct nfp_cpp *cpp);
82
83 const char *nfp_hwinfo_lookup(struct nfp_hwinfo *hwinfo, const char *lookup);
84
85 #endif