xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/include/bcmrand.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * bcmrand.h.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (C) 2020, Broadcom.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *      Unless you and Broadcom execute a separate written software license
7*4882a593Smuzhiyun  * agreement governing use of this software, this software is licensed to you
8*4882a593Smuzhiyun  * under the terms of the GNU General Public License version 2 (the "GPL"),
9*4882a593Smuzhiyun  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10*4882a593Smuzhiyun  * following added to such license:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *      As a special exception, the copyright holders of this software give you
13*4882a593Smuzhiyun  * permission to link this software with independent modules, and to copy and
14*4882a593Smuzhiyun  * distribute the resulting executable under terms of your choice, provided that
15*4882a593Smuzhiyun  * you also meet, for each linked independent module, the terms and conditions of
16*4882a593Smuzhiyun  * the license of that module.  An independent module is a module which is not
17*4882a593Smuzhiyun  * derived from this software.  The special exception does not apply to any
18*4882a593Smuzhiyun  * modifications of the software.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * <<Broadcom-WL-IPTag/Dual:>>
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #ifndef	_bcmrand_h_
25*4882a593Smuzhiyun #define	_bcmrand_h_
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /* When HOST driver is for PCIE dongle image, we suppose the HOST must provide the entropy
28*4882a593Smuzhiyun  * input if it does not define the macro BCM_RNG_NO_HOST_ENTROPY
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun #if defined(BCMPCIEDEV) && !defined(BCMFUZZ)
31*4882a593Smuzhiyun #if !defined(BCM_RNG_HOST_ENTROPY) && !defined(BCM_RNG_NO_HOST_ENTROPY)
32*4882a593Smuzhiyun #define BCM_RNG_HOST_ENTROPY
33*4882a593Smuzhiyun #define BCM_RNG_PCIEDEV_DEFAULT
34*4882a593Smuzhiyun #endif /* !BCM_RNG_HOST_ENTROPY && !BCM_RNG_NO_HOST_ENTROPY */
35*4882a593Smuzhiyun #endif /* BCMPCIEDEV */
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /* the format of current TCM layout during boot
38*4882a593Smuzhiyun  *
39*4882a593Smuzhiyun  *    Code Unused memory   Random numbers   Random number    Magic number    NVRAM      NVRAM
40*4882a593Smuzhiyun  *                                          byte Count       0xFEEDC0DE                 Size
41*4882a593Smuzhiyun  *   |<-----Variable---->|<---Variable--->|<-----4 bytes-->|<---4 bytes---->|<---V--->|<--4B--->|
42*4882a593Smuzhiyun  *                       |<------------- BCM_ENTROPY_HOST_MAXSIZE --------->|
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* The HOST need to provided 64 bytes (512 bits) entropy for the bcm SW RNG */
46*4882a593Smuzhiyun #define BCM_ENTROPY_MAGIC_SIZE		4u
47*4882a593Smuzhiyun #define BCM_ENTROPY_COUNT_SIZE		4u
48*4882a593Smuzhiyun #define BCM_ENTROPY_SEED_NBYTES		64u
49*4882a593Smuzhiyun #define BCM_ENTROPY_NONCE_NBYTES	16u
50*4882a593Smuzhiyun #define BCM_ENTROPY_HOST_NBYTES		128u
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #ifdef DBG_RNG_SEC_TEST
53*4882a593Smuzhiyun #define BCM_ENTROPY_MAX_NBYTES		128u
54*4882a593Smuzhiyun #else
55*4882a593Smuzhiyun #define BCM_ENTROPY_MAX_NBYTES		512u
56*4882a593Smuzhiyun #endif /* DBG_RNG_SEC_TEST */
57*4882a593Smuzhiyun #define BCM_ENTROPY_HOST_MAXSIZE	\
58*4882a593Smuzhiyun 	(BCM_ENTROPY_MAGIC_SIZE + BCM_ENTROPY_COUNT_SIZE + BCM_ENTROPY_MAX_NBYTES)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /* Constant for calculate the location of host entropy input */
61*4882a593Smuzhiyun #define BCM_NVRAM_OFFSET_TCM		4u
62*4882a593Smuzhiyun #define BCM_NVRAM_IMG_COMPRS_FACTOR	4u
63*4882a593Smuzhiyun #define BCM_NVRAM_RNG_SIGNATURE		0xFEEDC0DEu
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun #endif	/* _bcmrand_h_ */
66