PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/include/bcmnvram.h

https://gitlab.com/buktemirlnk/mirrors
C Header | 329 lines | 120 code | 47 blank | 162 comment | 7 complexity | 735e483f8774ccf2e10d60e3c99dac1e MD5 | raw file
  1. /*
  2. * NVRAM variable manipulation
  3. *
  4. * Copyright (C) 1999-2017, Broadcom Corporation
  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. * Notwithstanding the above, under no circumstances may you combine this
  21. * software in any way with any other Broadcom software provided under a license
  22. * other than the GPL, without Broadcom's express prior written consent.
  23. *
  24. *
  25. * <<Broadcom-WL-IPTag/Open:>>
  26. *
  27. * $Id: bcmnvram.h 613043 2016-01-16 00:24:13Z $
  28. */
  29. #ifndef _bcmnvram_h_
  30. #define _bcmnvram_h_
  31. #ifndef _LANGUAGE_ASSEMBLY
  32. #include <typedefs.h>
  33. #include <bcmdefs.h>
  34. struct nvram_header {
  35. uint32 magic;
  36. uint32 len;
  37. uint32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
  38. uint32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
  39. uint32 config_ncdl; /* ncdl values for memc */
  40. };
  41. struct nvram_tuple {
  42. char *name;
  43. char *value;
  44. struct nvram_tuple *next;
  45. };
  46. /*
  47. * Get default value for an NVRAM variable
  48. */
  49. extern char *nvram_default_get(const char *name);
  50. /*
  51. * validate/restore all per-interface related variables
  52. */
  53. extern void nvram_validate_all(char *prefix, bool restore);
  54. /*
  55. * restore specific per-interface variable
  56. */
  57. extern void nvram_restore_var(char *prefix, char *name);
  58. /*
  59. * Initialize NVRAM access. May be unnecessary or undefined on certain
  60. * platforms.
  61. */
  62. extern int nvram_init(void *sih);
  63. extern int nvram_deinit(void *sih);
  64. /*
  65. * Append a chunk of nvram variables to the global list
  66. */
  67. extern int nvram_append(void *si, char *vars, uint varsz);
  68. extern void nvram_get_global_vars(char **varlst, uint *varsz);
  69. /*
  70. * Check for reset button press for restoring factory defaults.
  71. */
  72. extern int nvram_reset(void *sih);
  73. /*
  74. * Disable NVRAM access. May be unnecessary or undefined on certain
  75. * platforms.
  76. */
  77. extern void nvram_exit(void *sih);
  78. /*
  79. * Get the value of an NVRAM variable. The pointer returned may be
  80. * invalid after a set.
  81. * @param name name of variable to get
  82. * @return value of variable or NULL if undefined
  83. */
  84. extern char * nvram_get(const char *name);
  85. /*
  86. * Get the value of an NVRAM variable. The pointer returned may be
  87. * invalid after a set.
  88. * @param name name of variable to get
  89. * @param bit bit value to get
  90. * @return value of variable or NULL if undefined
  91. */
  92. extern char * nvram_get_bitflag(const char *name, const int bit);
  93. /*
  94. * Read the reset GPIO value from the nvram and set the GPIO
  95. * as input
  96. */
  97. extern int nvram_resetgpio_init(void *sih);
  98. /*
  99. * Get the value of an NVRAM variable.
  100. * @param name name of variable to get
  101. * @return value of variable or NUL if undefined
  102. */
  103. static INLINE char *
  104. nvram_safe_get(const char *name)
  105. {
  106. char *p = nvram_get(name);
  107. return p ? p : "";
  108. }
  109. /*
  110. * Match an NVRAM variable.
  111. * @param name name of variable to match
  112. * @param match value to compare against value of variable
  113. * @return TRUE if variable is defined and its value is string equal
  114. * to match or FALSE otherwise
  115. */
  116. static INLINE int
  117. nvram_match(const char *name, const char *match)
  118. {
  119. const char *value = nvram_get(name);
  120. /* In nvramstubs.c builds, nvram_get() is defined as returning zero,
  121. * so the return line below never executes the strcmp(),
  122. * resulting in 'match' being an unused parameter.
  123. * Make a ref to 'match' to quiet the compiler warning.
  124. */
  125. BCM_REFERENCE(match);
  126. return (value && !strcmp(value, match));
  127. }
  128. /*
  129. * Match an NVRAM variable.
  130. * @param name name of variable to match
  131. * @param bit bit value to get
  132. * @param match value to compare against value of variable
  133. * @return TRUE if variable is defined and its value is string equal
  134. * to match or FALSE otherwise
  135. */
  136. static INLINE int
  137. nvram_match_bitflag(const char *name, const int bit, const char *match)
  138. {
  139. const char *value = nvram_get_bitflag(name, bit);
  140. BCM_REFERENCE(match);
  141. return (value && !strcmp(value, match));
  142. }
  143. /*
  144. * Inversely match an NVRAM variable.
  145. * @param name name of variable to match
  146. * @param match value to compare against value of variable
  147. * @return TRUE if variable is defined and its value is not string
  148. * equal to invmatch or FALSE otherwise
  149. */
  150. static INLINE int
  151. nvram_invmatch(const char *name, const char *invmatch)
  152. {
  153. const char *value = nvram_get(name);
  154. /* In nvramstubs.c builds, nvram_get() is defined as returning zero,
  155. * so the return line below never executes the strcmp(),
  156. * resulting in 'invmatch' being an unused parameter.
  157. * Make a ref to 'invmatch' to quiet the compiler warning.
  158. */
  159. BCM_REFERENCE(invmatch);
  160. return (value && strcmp(value, invmatch));
  161. }
  162. /*
  163. * Set the value of an NVRAM variable. The name and value strings are
  164. * copied into private storage. Pointers to previously set values
  165. * may become invalid. The new value may be immediately
  166. * retrieved but will not be permanently stored until a commit.
  167. * @param name name of variable to set
  168. * @param value value of variable
  169. * @return 0 on success and errno on failure
  170. */
  171. extern int nvram_set(const char *name, const char *value);
  172. /*
  173. * Set the value of an NVRAM variable. The name and value strings are
  174. * copied into private storage. Pointers to previously set values
  175. * may become invalid. The new value may be immediately
  176. * retrieved but will not be permanently stored until a commit.
  177. * @param name name of variable to set
  178. * @param bit bit value to set
  179. * @param value value of variable
  180. * @return 0 on success and errno on failure
  181. */
  182. extern int nvram_set_bitflag(const char *name, const int bit, const int value);
  183. /*
  184. * Unset an NVRAM variable. Pointers to previously set values
  185. * remain valid until a set.
  186. * @param name name of variable to unset
  187. * @return 0 on success and errno on failure
  188. * NOTE: use nvram_commit to commit this change to flash.
  189. */
  190. extern int nvram_unset(const char *name);
  191. /*
  192. * Commit NVRAM variables to permanent storage. All pointers to values
  193. * may be invalid after a commit.
  194. * NVRAM values are undefined after a commit.
  195. * @param nvram_corrupt true to corrupt nvram, false otherwise.
  196. * @return 0 on success and errno on failure
  197. */
  198. extern int nvram_commit_internal(bool nvram_corrupt);
  199. /*
  200. * Commit NVRAM variables to permanent storage. All pointers to values
  201. * may be invalid after a commit.
  202. * NVRAM values are undefined after a commit.
  203. * @return 0 on success and errno on failure
  204. */
  205. extern int nvram_commit(void);
  206. /*
  207. * Get all NVRAM variables (format name=value\0 ... \0\0).
  208. * @param buf buffer to store variables
  209. * @param count size of buffer in bytes
  210. * @return 0 on success and errno on failure
  211. */
  212. extern int nvram_getall(char *nvram_buf, int count);
  213. /*
  214. * returns the crc value of the nvram
  215. * @param nvh nvram header pointer
  216. */
  217. uint8 nvram_calc_crc(struct nvram_header * nvh);
  218. extern int nvram_space;
  219. #endif /* _LANGUAGE_ASSEMBLY */
  220. /* The NVRAM version number stored as an NVRAM variable */
  221. #define NVRAM_SOFTWARE_VERSION "1"
  222. #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
  223. #define NVRAM_CLEAR_MAGIC 0x0
  224. #define NVRAM_INVALID_MAGIC 0xFFFFFFFF
  225. #define NVRAM_VERSION 1
  226. #define NVRAM_HEADER_SIZE 20
  227. /* This definition is for precommit staging, and will be removed */
  228. #define NVRAM_SPACE 0x8000
  229. /* For CFE builds this gets passed in thru the makefile */
  230. #ifndef MAX_NVRAM_SPACE
  231. #define MAX_NVRAM_SPACE 0x10000
  232. #endif
  233. #define DEF_NVRAM_SPACE 0x8000
  234. #define ROM_ENVRAM_SPACE 0x1000
  235. #define NVRAM_LZMA_MAGIC 0x4c5a4d41 /* 'LZMA' */
  236. #define NVRAM_MAX_VALUE_LEN 255
  237. #define NVRAM_MAX_PARAM_LEN 64
  238. #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
  239. #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
  240. /* Offsets to embedded nvram area */
  241. #define NVRAM_START_COMPRESSED 0x400
  242. #define NVRAM_START 0x1000
  243. #define BCM_JUMBO_NVRAM_DELIMIT '\n'
  244. #define BCM_JUMBO_START "Broadcom Jumbo Nvram file"
  245. #if (defined(FAILSAFE_UPGRADE) || defined(CONFIG_FAILSAFE_UPGRADE) || \
  246. defined(__CONFIG_FAILSAFE_UPGRADE_SUPPORT__))
  247. #define IMAGE_SIZE "image_size"
  248. #define BOOTPARTITION "bootpartition"
  249. #define IMAGE_BOOT BOOTPARTITION
  250. #define PARTIALBOOTS "partialboots"
  251. #define MAXPARTIALBOOTS "maxpartialboots"
  252. #define IMAGE_1ST_FLASH_TRX "flash0.trx"
  253. #define IMAGE_1ST_FLASH_OS "flash0.os"
  254. #define IMAGE_2ND_FLASH_TRX "flash0.trx2"
  255. #define IMAGE_2ND_FLASH_OS "flash0.os2"
  256. #define IMAGE_FIRST_OFFSET "image_first_offset"
  257. #define IMAGE_SECOND_OFFSET "image_second_offset"
  258. #define LINUX_FIRST "linux"
  259. #define LINUX_SECOND "linux2"
  260. #endif
  261. #if (defined(DUAL_IMAGE) || defined(CONFIG_DUAL_IMAGE) || \
  262. defined(__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__))
  263. /* Shared by all: CFE, Linux Kernel, and Ap */
  264. #define IMAGE_BOOT "image_boot"
  265. #define BOOTPARTITION IMAGE_BOOT
  266. /* CFE variables */
  267. #define IMAGE_1ST_FLASH_TRX "flash0.trx"
  268. #define IMAGE_1ST_FLASH_OS "flash0.os"
  269. #define IMAGE_2ND_FLASH_TRX "flash0.trx2"
  270. #define IMAGE_2ND_FLASH_OS "flash0.os2"
  271. #define IMAGE_SIZE "image_size"
  272. /* CFE and Linux Kernel shared variables */
  273. #define IMAGE_FIRST_OFFSET "image_first_offset"
  274. #define IMAGE_SECOND_OFFSET "image_second_offset"
  275. /* Linux application variables */
  276. #define LINUX_FIRST "linux"
  277. #define LINUX_SECOND "linux2"
  278. #define POLICY_TOGGLE "toggle"
  279. #define LINUX_PART_TO_FLASH "linux_to_flash"
  280. #define LINUX_FLASH_POLICY "linux_flash_policy"
  281. #endif /* defined(DUAL_IMAGE||CONFIG_DUAL_IMAGE)||__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__ */
  282. #endif /* _bcmnvram_h_ */