control.h (5232B)
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-2020 Broadcom Inc. All rights reserved. 6 * 7 * BCM Control 8 */ 9 10 #ifndef _BCM_INT_CONTROL_H 11 #define _BCM_INT_CONTROL_H 12 13 #include <bcm/types.h> 14 #include <bcm/init.h> 15 #include <bcm_int/dispatch.h> 16 17 #ifndef BCM_CONTROL_MAX 18 #define BCM_CONTROL_MAX BCM_UNITS_MAX 19 #endif 20 21 /* 22 * BCM Supported Dispatch Type Enumeration. 23 */ 24 #define BCM_DLIST_ENTRY(_dtype) \ 25 bcmDtype_##_dtype, 26 27 typedef enum bcm_dtype_e { 28 #include <bcm_int/bcm_dlist.h> 29 bcmTypeCount, 30 bcmTypeNone = -1 31 } bcm_dtype_t; 32 /* Enums which describe the state of bcm_control_t structure */ 33 typedef enum _bcm_control_state_e { 34 _bcmControlStateNone = 0, /* No modules are attached */ 35 36 _bcmControlStateTxRxInit, /* To Initialize tx and rx modules only */ 37 _bcmControlStateTxRxInited, /* Only Tx and Rx modules are initialized */ 38 _bcmControlStateInitedAll, /* All modules are initialized */ 39 40 _bcmControlStateDeinitLateTxRx, /* Detach all modules except Tx and Rx */ 41 _bcmControlStateDeinitAll, /* Only Tx and Rx need to be deinited */ 42 43 _bcmControlStateCount 44 } _bcm_control_state_t; 45 46 typedef struct { 47 int unit; /* driver unit */ 48 void *drv_control; /* driver control structure */ 49 bcm_dtype_t dtype; /* driver dispatch type */ 50 const char* name; /* driver dispatch name */ 51 char *subtype; /* attached subtype (or NULL) */ 52 53 uint32 chip_vendor; /* switch chip ident (pci id) */ 54 uint32 chip_device; 55 uint32 chip_revision; 56 uint32 capability; /* chip capabilities */ 57 #define BCM_CAPA_SWITCH BCM_INFO_SWITCH /* net switch chip */ 58 #define BCM_CAPA_FABRIC BCM_INFO_FABRIC /* fabric chip */ 59 #define BCM_CAPA_L3 BCM_INFO_L3 /* chip has layer 3 */ 60 #define BCM_CAPA_IPMC BCM_INFO_IPMC /* chip has IP mcast */ 61 #define BCM_CAPA_LOCAL 0x1000 /* local (direct) dispatch */ 62 #define BCM_CAPA_REMOTE 0x2000 /* remotely dispatch */ 63 #define BCM_CAPA_COMPOSITE 0x4000 /* composite dispatch */ 64 #define BCM_CAPA_CALLBACK 0x8000 /* attach callback complete */ 65 66 /* Used with early_attach and late_detach sequences. 67 * Will be one of _bcm_control_state_t enums */ 68 int attach_state; 69 70 /* per module storage */ 71 void *data_auth; 72 void *data_i2c; 73 void *data_cosq; 74 void *data_diffserv; 75 void *data_dmux; 76 void *data_filter; 77 void *data_init; 78 void *data_ipmc; 79 void *data_l2; 80 void *data_l3; 81 void *data_link; 82 void *data_mcast; 83 void *data_meter; 84 void *data_mirror; 85 void *data_pkt; 86 void *data_port; 87 void *data_rate; 88 void *data_rx; 89 void *data_stack; 90 void *data_stat; 91 void *data_stg; 92 void *data_switch; 93 void *data_trunk; 94 void *data_tx; 95 void *data_vlan; 96 void *data_misc1; 97 void *data_misc2; 98 void *data_misc3; 99 void *data_misc4; 100 101 /* system_init() return value */ 102 int system_initialized_rv; 103 } bcm_control_t; 104 105 extern bcm_control_t *bcm_control[BCM_CONTROL_MAX]; 106 107 #define BCM_CONTROL(_unit) bcm_control[_unit] 108 #define BCM_DISPATCH(_unit) BCM_CONTROL(_unit)->dispatch 109 110 /* BCM control unit in legal range? */ 111 #define BCM_CONTROL_UNIT_LEGAL(_unit) \ 112 (((_unit) >= 0) && ((_unit) < BCM_CONTROL_MAX)) 113 114 /* use below dispatch layer or during init/deinit */ 115 #define BCM_CONTROL_UNIT_VALID(_unit) \ 116 ((BCM_CONTROL_UNIT_LEGAL(_unit)) && (BCM_CONTROL(_unit) != NULL)) 117 118 /* use at dispatch layer and above */ 119 #ifdef BCM_CONTROL_API_TRACKING 120 121 extern uint32 bcm_control_unit_valid[BCM_CONTROL_MAX]; 122 extern int bcm_unit_refcount(int unit, int refcount); 123 124 125 #define BCM_UNIT_VALID(_unit) (BCM_CONTROL_UNIT_LEGAL(_unit) && \ 126 bcm_control_unit_valid[_unit] != 0) 127 128 /* BCM_UNIT_CHECK/BCM_UNIT_IDLE and 129 BCM_UNIT_BUSY/BCM_UNIT_IDLE must always be used in pairs. 130 BCM_UNIT_CHECK() returns a unit valid flag and is used as a predicate. 131 BCM_UNIT_BUSY() does not return a flag and is used standalone. 132 BCM_UNIT_IDLE() is always used standalone. 133 */ 134 #define BCM_UNIT_CHECK(unit) bcm_unit_refcount((unit), 1) 135 #define BCM_UNIT_BUSY(unit) ((void)BCM_UNIT_CHECK(unit)) 136 #define BCM_UNIT_IDLE(unit) ((void)bcm_unit_refcount((unit), -1)) 137 138 #else /* !BCM_CONTROL_API_TRACKING */ 139 140 #define BCM_UNIT_VALID(_unit) BCM_CONTROL_UNIT_VALID(_unit) 141 #define BCM_UNIT_CHECK(unit) BCM_UNIT_VALID(unit) 142 #define BCM_UNIT_BUSY(unit) 143 #define BCM_UNIT_IDLE(unit) 144 145 #endif /* BCM_CONTROL_API_TRACKING */ 146 147 #define BCM_CAPABILITY(_unit) BCM_CONTROL(_unit)->capability 148 #define BCM_IS_LOCAL(_unit) (BCM_CAPABILITY(_unit) & \ 149 BCM_CAPA_LOCAL) 150 #define BCM_IS_REMOTE(_unit) (BCM_CAPABILITY(_unit) & \ 151 BCM_CAPA_REMOTE) 152 #define BCM_IS_SWITCH(_unit) (BCM_CAPABILITY(_unit) & \ 153 BCM_CAPA_SWITCH) 154 #define BCM_IS_FABRIC(_unit) (BCM_CAPABILITY(_unit) & \ 155 BCM_CAPA_FABRIC) 156 #define BCM_DTYPE(_unit) BCM_CONTROL(_unit)->dtype 157 #define BCM_TYPE_NAME(_unit) BCM_CONTROL(_unit)->name 158 159 extern int bcmi_warmboot_get(int unit); 160 161 #endif /* _BCM_INT_CONTROL_H */