xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/include/bcmnvram.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * NVRAM variable manipulation
3  *
4  * Copyright (C) 2020, Broadcom.
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *
21  * <<Broadcom-WL-IPTag/Dual:>>
22  */
23 
24 #ifndef _bcmnvram_h_
25 #define _bcmnvram_h_
26 
27 #ifndef _LANGUAGE_ASSEMBLY
28 
29 #include <typedefs.h>
30 
31 struct nvram_header {
32 	uint32 magic;
33 	uint32 len;
34 	uint32 crc_ver_init;	/* 0:7 crc, 8:15 ver, 16:31 sdram_init */
35 	uint32 config_refresh;	/* 0:15 sdram_config, 16:31 sdram_refresh */
36 	uint32 config_ncdl;	/* ncdl values for memc */
37 };
38 
39 struct nvram_tuple {
40 	char *name;
41 	char *value;
42 	struct nvram_tuple *next;
43 };
44 
45 #ifdef BCMDRIVER
46 #include <siutils.h>
47 
48 /*
49  * Initialize NVRAM access. May be unnecessary or undefined on certain
50  * platforms.
51  */
52 extern int nvram_init(si_t *sih);
53 
54 extern int nvram_file_read(char **nvramp, int *nvraml);
55 
56 /*
57  * Append a chunk of nvram variables to the global list
58  */
59 extern int nvram_append(void *si, char *vars, uint varsz, uint16 prio);
60 
61 /*
62  * Check for reset button press for restoring factory defaults.
63  */
64 extern int nvram_reset(si_t *sih);
65 
66 /*
67  * Disable NVRAM access. May be unnecessary or undefined on certain
68  * platforms.
69  */
70 extern void nvram_exit(si_t *sih);
71 
72 /*
73  * Get the value of an NVRAM variable. The pointer returned may be
74  * invalid after a set.
75  * @param	name	name of variable to get
76  * @return	value of variable or NULL if undefined
77  */
78 extern char * nvram_get(const char *name);
79 
80 /*
81  * Get the value of an NVRAM variable.
82  * @param	name	name of variable to get
83  * @return	value of variable or NUL if undefined
84  */
85 static INLINE char *
nvram_safe_get(const char * name)86 nvram_safe_get(const char *name)
87 {
88 	char *p = nvram_get(name);
89 	return p ? p : "";
90 }
91 
92 /*
93  * Set the value of an NVRAM variable. The name and value strings are
94  * copied into private storage. Pointers to previously set values
95  * may become invalid. The new value may be immediately
96  * retrieved but will not be permanently stored until a commit.
97  * @param	name	name of variable to set
98  * @param	value	value of variable
99  * @return	0 on success and errno on failure
100  */
101 extern int nvram_set(const char *name, const char *value);
102 
103 /*
104  * Unset an NVRAM variable. Pointers to previously set values
105  * remain valid until a set.
106  * @param	name	name of variable to unset
107  * @return	0 on success and errno on failure
108  * NOTE: use nvram_commit to commit this change to flash.
109  */
110 extern int nvram_unset(const char *name);
111 
112 /*
113  * Commit NVRAM variables to permanent storage. All pointers to values
114  * may be invalid after a commit.
115  * NVRAM values are undefined after a commit.
116  * @return	0 on success and errno on failure
117  */
118 extern int nvram_commit(void);
119 
120 /*
121  * Get all NVRAM variables (format name=value\0 ... \0\0).
122  * @param	buf	buffer to store variables
123  * @param	count	size of buffer in bytes
124  * @return	0 on success and errno on failure
125  */
126 extern int nvram_getall(char *nvram_buf, int count);
127 
128 /*
129  * returns the crc value of the nvram
130  * @param	nvh	nvram header pointer
131  */
132 uint8 nvram_calc_crc(struct nvram_header * nvh);
133 
134 extern void nvram_printall(void);
135 
136 #endif /* BCMDRIVER */
137 #endif /* _LANGUAGE_ASSEMBLY */
138 
139 #define NVRAM_MAGIC		0x48534C46	/* 'FLSH' */
140 #define NVRAM_VERSION		1
141 #define NVRAM_HEADER_SIZE	20
142 /* This definition is for precommit staging, and will be removed */
143 #define NVRAM_SPACE		0x8000
144 #define MAX_NVRAM_SPACE		0x10000
145 #define DEF_NVRAM_SPACE		0x8000
146 #define NVRAM_LZMA_MAGIC	0x4c5a4d41	/* 'LZMA' */
147 
148 #define NVRAM_MAX_VALUE_LEN 255
149 #define NVRAM_MAX_PARAM_LEN 64
150 
151 #define NVRAM_CRC_START_POSITION	9 /* magic, len, crc8 to be skipped */
152 #define NVRAM_CRC_VER_MASK	0xffffff00 /* for crc_ver_init */
153 
154 #define BCM_JUMBO_NVRAM_DELIMIT '\n'
155 #define BCM_JUMBO_START "Broadcom Jumbo Nvram file"
156 
157 #if defined(BCMSDIODEV) || defined(BCMHOSTVARS)
158 extern char *_vars;
159 extern uint _varsz;
160 #endif
161 
162 #endif /* _bcmnvram_h_ */
163