openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

warmboot.h (4187B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        warmboot.h
      8  * Purpose:     
      9  */
     10 
     11 #ifndef   _SHR_WARMBOOT_H_
     12 #define   _SHR_WARMBOOT_H_
     13 
     14 #ifdef BCM_WARM_BOOT_SUPPORT
     15 
     16 #include <shared/bsl.h>
     17 
     18 #include <sal/types.h>
     19 
     20 /*
     21  * For tracking the information required by Warm Boot Level 2,
     22  * we need a handle to both store and recover the scache information.
     23  * This handle is formatted as follows:
     24  *
     25  *  31       24 23        16 15          0
     26  * |  Unit #   |  Module #  |  Sequence # |
     27  *
     28  * Where the unit # is the BCM unit number, the module # is the
     29  * BCM API module index, and the sequence number is selected by
     30  * the requesting module, in case multiple scache segments are required.
     31  */
     32 
     33 #define _SHR_SCACHE_HANDLE_UNIT_MASK            0xff
     34 #define _SHR_SCACHE_HANDLE_MODULE_MASK          0xff
     35 #define _SHR_SCACHE_HANDLE_SEQUENCE_MASK        0xff
     36 
     37 #define _SHR_SCACHE_HANDLE_UNIT_SHIFT           24
     38 #define _SHR_SCACHE_HANDLE_MODULE_SHIFT         16
     39 
     40 #define _SHR_SCACHE_HANDLE_SET(_handle_, _unit_, _module_, _sequence_) \
     41         ((_handle_) = \
     42             (((_unit_) & _SHR_SCACHE_HANDLE_UNIT_MASK) << \
     43                             _SHR_SCACHE_HANDLE_UNIT_SHIFT) | \
     44             (((_module_) & _SHR_SCACHE_HANDLE_MODULE_MASK) << \
     45                             _SHR_SCACHE_HANDLE_MODULE_SHIFT) | \
     46             ((_sequence_) & _SHR_SCACHE_HANDLE_SEQUENCE_MASK))
     47 
     48 #define _SHR_SCACHE_HANDLE_UNIT_GET(_handle_) \
     49         (((_handle_) >> _SHR_SCACHE_HANDLE_UNIT_SHIFT) & \
     50                 _SHR_SCACHE_HANDLE_UNIT_MASK)
     51 
     52 #define _SHR_SCACHE_HANDLE_MODULE_GET(_handle_) \
     53         (((_handle_) >> _SHR_SCACHE_HANDLE_MODULE_SHIFT) & \
     54                 _SHR_SCACHE_HANDLE_MODULE_MASK)
     55 
     56 #define _SHR_SCACHE_HANDLE_SEQUENCE_GET(_handle_) \
     57         ((_handle_) & _SHR_SCACHE_HANDLE_SEQUENCE_MASK)
     58 
     59 
     60 /* scache warm boot versioning */
     61 #define _SHR_SCACHE_V_MAJOR_SHIFT    8
     62 #define _SHR_SCACHE_V_MAJOR_MASK     0xFF
     63 
     64 #define _SHR_SCACHE_V_MINOR_SHIFT    0
     65 #define _SHR_SCACHE_V_MINOR_MASK     0xFF
     66 
     67 #define _SHR_SCACHE_VERSION(major_, minor_)  \
     68         (((major_) & _SHR_SCACHE_V_MAJOR_MASK) << _SHR_SCACHE_V_MAJOR_SHIFT | \
     69         (((minor_) & _SHR_SCACHE_V_MINOR_MASK) << _SHR_SCACHE_V_MINOR_SHIFT))
     70 
     71 #define _SHR_SCACHE_VERSION_MAJOR(v_)    \
     72         (((v_) >> _SHR_SCACHE_V_MAJOR_SHIFT) & _SHR_SCACHE_V_MAJOR_MASK)
     73 #define _SHR_SCACHE_VERSION_MINOR(v_)     \
     74         (((v_) >> _SHR_SCACHE_V_MINOR_SHIFT) & _SHR_SCACHE_V_MINOR_MASK)
     75 
     76 
     77 /* A common scache layout for warm boot */
     78 typedef struct _shr_wb_cache_s {
     79     uint16  version;        /* for upgrade scenarios */
     80     uint16  reserved;
     81     uint8   cache[1];        /* variable length, MUST BE LAST */
     82 } _shr_wb_cache_t;
     83 
     84 /* Size of scache used by control data */
     85 #define _SHR_WB_SCACHE_CONTROL_SIZE   \
     86    ((size_t) &((_shr_wb_cache_t*)0)->cache)
     87 
     88 /* get the size of the caller usable scache,
     89  * size of _shr_wb_cache_t->scache 
     90  */
     91 #define _SHR_WB_SCACHE_SIZE(raw_size_) \
     92   ((raw_size_) - _SHR_WB_SCACHE_CONTROL_SIZE)
     93 
     94 
     95 #define __WB_CHECK_OVERRUN(z,str)				    	       \
     96     if (ptr+z>end_ptr){							       \
     97         LOG_ERROR(BSL_LS_SOC_COMMON, \
     98                   (BSL_META_U(unit, \
     99                               "%s: Incoherent state of scache (%s is not stored correctly).\n"), \
    100                    FUNCTION_NAME(), str));                               \
    101       return SOC_E_INTERNAL;						       \
    102     }
    103 
    104 /* Following macro used for warm and cold boot */
    105 #define __WB_DECOMPRESS_SCALAR(type, var) do {\
    106     if (SOC_WARM_BOOT(unit)){				\
    107       __WB_CHECK_OVERRUN(sizeof(type), #var);		\
    108       (var) = *(type*)ptr; ptr+=sizeof(type);		\
    109     }else{						\
    110       scache_len += sizeof(type);			\
    111     }							\
    112   } while(0)
    113 
    114 #define __WB_COMPRESS_SCALAR(type, var) do {\
    115     __WB_CHECK_OVERRUN(sizeof(type), #var);		\
    116     *(type*)ptr = (var); ptr+=sizeof(type); } while(0)
    117 
    118 #define _WB_OP_DECOMPRESS (0)
    119 #define _WB_OP_COMPRESS   (1)
    120 #define _WB_OP_SIZE       (2)
    121 #define _WB_OP_DUMP       (3)
    122 
    123 
    124 #endif /* BCM_WARM_BOOT_SUPPORT */
    125 
    126 #endif /* _SHR_WARMBOOT_H_ */