init.c (3565B)
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 8 #include <sal/types.h> 9 #include <sal/core/time.h> 10 #include <sal/core/boot.h> 11 #include <shared/bsl.h> 12 #include <bcm/module.h> 13 #include <bcm/init.h> 14 15 #include <soc/mem.h> 16 #include <soc/drv.h> 17 18 /* Protection mutexes for each unit. */ 19 sal_mutex_t _bcm_lock[BCM_MAX_NUM_UNITS]; 20 21 int inside_bcm_shutdown[BCM_MAX_NUM_UNITS]; 22 23 /* 24 * Function: 25 * bcm_module_name 26 * Purpose: 27 * Return the name of a module given its number 28 * Parameters: 29 * unit - placeholder 30 * module_num - One of BCM_MODULE_xxx 31 * Returns: 32 * Pointer to static char string 33 * Notes: 34 * This function to be moved to its own module when it makes sense. 35 */ 36 37 STATIC char *_bcm_module_names[] = BCM_MODULE_NAMES_INITIALIZER; 38 39 char * 40 bcm_module_name(int unit, int module_num) 41 { 42 if (sizeof(_bcm_module_names) / sizeof(_bcm_module_names[0]) 43 != BCM_MODULE__COUNT) { 44 int i; 45 46 i = sizeof(_bcm_module_names) / sizeof(_bcm_module_names[0]) - 1; 47 48 LOG_ERROR(BSL_LS_BCM_INIT, 49 (BSL_META_U(unit, 50 "bcm_module_name: BCM_MODULE_NAMES_INITIALIZER(%d) and BCM_MODULE__COUNT(%d) mis-match\n"), i, BCM_MODULE__COUNT)); 51 for(;i >= 0;i--) { 52 LOG_ERROR(BSL_LS_BCM_INIT, 53 (BSL_META_U(unit, 54 "%2d. %s\n"), i, _bcm_module_names[i])); 55 } 56 } 57 if (module_num < 0 || module_num >= BCM_MODULE__COUNT) { 58 return "unknown"; 59 } 60 61 return _bcm_module_names[module_num]; 62 } 63 64 /* 65 * Function: 66 * bcm_info_t_init 67 * Purpose: 68 * Initialize the bcm_info_t structure. 69 * Parameters: 70 * info - Pointer to bcm_info_t structure. 71 * Returns: 72 * NONE 73 */ 74 void 75 bcm_info_t_init(bcm_info_t *info) 76 { 77 if (info != NULL) { 78 sal_memset(info, 0, sizeof (*info)); 79 } 80 return; 81 } 82 83 /* 84 * Function: 85 * bcm_attach_info_t_init 86 * Purpose: 87 * Initialize the bcm_attach_info_t structure. 88 * Parameters: 89 * info - (IN/OUT) Pointer to structure to initialize. 90 * Returns: 91 * NONE 92 */ 93 void 94 bcm_attach_info_t_init(bcm_attach_info_t *info) 95 { 96 if (info != NULL) { 97 sal_memset(info, 0, sizeof (*info)); 98 } 99 return; 100 } 101 102 /* 103 * Function: 104 * bcm_detach_retry_t_init 105 * Purpose: 106 * Initialize the bcm_detach_retry_t structure. 107 * Parameters: 108 * retry - Pointer to bcm_detach_retry_t structure. 109 * Returns: 110 * NONE 111 */ 112 void 113 bcm_detach_retry_t_init(bcm_detach_retry_t *retry) 114 { 115 if (retry != NULL) { 116 sal_memset(retry, 0, sizeof (*retry)); 117 } 118 return; 119 } 120 121 #ifdef BCM_WARM_BOOT_SUPPORT 122 /* 123 * Function: 124 * _bcm_shutdown 125 * Purpose: 126 * Free up resources without touching hardware 127 * Parameters: 128 * unit - switch device 129 * Returns: 130 * BCM_E_XXX 131 */ 132 int 133 _bcm_shutdown(int unit) 134 { 135 int warm_boot; 136 int rv; 137 138 /* Since this API is used for warm-boot, we need to enable 139 warm boot here even if it hasn't been already, and restore 140 it afterward if necessary. */ 141 142 warm_boot = SOC_WARM_BOOT(unit); 143 144 if (!warm_boot) 145 { 146 SOC_WARM_BOOT_START(unit); 147 } 148 149 inside_bcm_shutdown[unit] = TRUE; 150 151 rv = bcm_detach(unit); 152 153 if (!warm_boot) 154 { 155 SOC_WARM_BOOT_DONE(unit); 156 } 157 158 inside_bcm_shutdown[unit] = FALSE; 159 160 return rv; 161 } 162 #endif /* BCM_WARM_BOOT_SUPPORT */ 163