udf_common.c (2306B)
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 * All Rights Reserved.$ 7 * 8 * File: udf_common.c 9 * Purpose: Contains initilization of UDF common resources 10 * and manage device specific driver functions. 11 */ 12 13 #include <soc/defs.h> 14 #include <soc/drv.h> 15 #include <soc/format.h> 16 #include <soc/error.h> 17 #include <shared/bsl.h> 18 #include <shared/bitop.h> 19 20 #include <bcm/udf.h> 21 #include <bcm_int/esw/udf.h> 22 23 _bcm_udf_control_t *_udf_control[BCM_MAX_NUM_UNITS]; 24 25 /* 26 * Function to detach UDF common resources. 27 */ 28 int _bcm_udf_common_detach(int unit) 29 { 30 _bcm_udf_control_t *udf_ctrl = NULL; 31 32 udf_ctrl = UDF_CONTROL(unit); 33 if (udf_ctrl == NULL) { 34 return BCM_E_NONE; 35 } 36 37 if (udf_ctrl->functions.udf_detach != NULL) { 38 (void) udf_ctrl->functions.udf_detach(unit); 39 } else { 40 return BCM_E_INTERNAL; 41 } 42 43 _BCM_UDF_FREE(udf_ctrl); 44 UDF_CONTROL(unit) = NULL; 45 return BCM_E_NONE; 46 } 47 48 /* 49 * Function to initialize UDF common resources and 50 * device specific routines. 51 */ 52 int _bcm_udf_common_init(int unit) 53 { 54 int rv; 55 _bcm_udf_control_t *udf_ctrl = NULL; 56 57 udf_ctrl = UDF_CONTROL(unit); 58 59 /* Detatch first if it's been previously initialized. */ 60 if (udf_ctrl != NULL) { 61 rv = _bcm_udf_common_detach(unit); 62 if (BCM_FAILURE(rv)) { 63 return (rv); 64 } 65 udf_ctrl = NULL; 66 } 67 68 /* Allocate a bcm_udf_control */ 69 _BCM_UDF_ALLOC(udf_ctrl, sizeof (_bcm_udf_control_t), "UDF common control"); 70 if (NULL == udf_ctrl) { 71 return (BCM_E_MEMORY); 72 } 73 74 UDF_CONTROL(unit) = udf_ctrl; 75 76 #if defined BCM_TRIDENT3_SUPPORT 77 if (soc_feature(unit, soc_feature_udf_td3x_support)) { 78 /* Initialize the function pointers */ 79 _bcm_udf_td3_functions_init(&udf_ctrl->functions); 80 } 81 #endif /* BCM_TRIDENT3_SUPPORT */ 82 83 if (udf_ctrl->functions.udf_init != NULL) { 84 rv = udf_ctrl->functions.udf_init(unit); 85 } else { 86 rv = BCM_E_INIT; 87 } 88 BCM_IF_ERROR_GOTO_CLEANUP(rv); 89 90 return BCM_E_NONE; 91 92 cleanup: 93 if (UDF_CONTROL(unit) != NULL) { 94 _BCM_UDF_FREE(UDF_CONTROL(unit)); 95 } 96 return rv; 97 }