bfd_int.h (11104B)
1 /*! \file bfd_int.h 2 * 3 * BFD module internal header file. 4 * This file contains BFD definitions internal 5 * to the BFD module itself. 6 */ 7 /* 8 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 9 * 10 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 11 */ 12 13 #ifndef BCMINT_LTSW_BFD_INT_H 14 #define BCMINT_LTSW_BFD_INT_H 15 16 #include <bcm/types.h> 17 #include <sal/sal_types.h> 18 #include <shr/shr_types.h> 19 #include <shr/shr_util_pack.h> 20 #include <shr/shr_bitop.h> 21 #include <sal/sal_mutex.h> 22 #include <sal/sal_thread.h> 23 #include <bcmltd/chip/bcmltd_common_enum_ctype.h> 24 #include <bcmltd/chip/bcmltd_oam_constants.h> 25 #include <bcmltd/bcmltd_lt_types.h> 26 #include <bcm_int/ltsw/generated/bfd_ha.h> 27 28 #define BSL_LOG_MODULE BSL_LS_BCM_BFD 29 30 #define BFD_LTSW_INFO(_u) (&bfd_glb_info[_u]) 31 32 #define BFD_LTSW_INIT_CHECK(unit) \ 33 do { \ 34 if (BFD_LTSW_INFO(unit)->init == 0) { \ 35 SHR_ERR_EXIT(SHR_E_INIT); \ 36 } \ 37 } while(0) 38 39 #define BFD_LTSW_LOCK(unit) \ 40 do { \ 41 if (BFD_LTSW_INFO(unit)->lock) { \ 42 sal_mutex_take(BFD_LTSW_INFO(unit)->lock, SAL_MUTEX_FOREVER); \ 43 } else { \ 44 SHR_ERR_EXIT(SHR_E_INIT); \ 45 } \ 46 } while(0) 47 48 #define BFD_LTSW_UNLOCK(unit) \ 49 do { \ 50 if (BFD_LTSW_INFO(unit)->lock) { \ 51 sal_mutex_give(BFD_LTSW_INFO(unit)->lock); \ 52 } else { \ 53 _func_rv = SHR_E_INIT; \ 54 } \ 55 } while(0) 56 57 typedef enum _bfd_ha_sub_comp_id_e { 58 BFD_SUB_COMP_ID_GLOBAL_LIST = 0, 59 BFD_SUB_COMP_ID_PER_EP_INFO = 1 60 }bfd_ha_sub_comp_id_t; 61 62 63 #define BFD_ID_INFO(_u) BFD_LTSW_INFO(_u)->ha_info 64 65 #define BFD_GLB_ID_BMP(_u) BFD_ID_INFO(_u).glb_id_bmp->w 66 67 #define BFD_GLB_ID_BMP_SET(unit, id) \ 68 SHR_BITSET(BFD_GLB_ID_BMP(unit),id) 69 #define BFD_GLB_ID_BMP_GET(unit, id) \ 70 SHR_BITGET(BFD_GLB_ID_BMP(unit),id) 71 #define BFD_GLB_ID_BMP_CLEAR(unit, id) \ 72 SHR_BITCLR(BFD_GLB_ID_BMP(unit),id) 73 74 75 #define BFD_HA_EP_INFO(_u, id) BFD_ID_INFO(_u).ep_info[id] 76 77 #define BFD_EP_ENCAP_TYPE(unit, id) \ 78 (BFD_HA_EP_INFO(unit,id).ep_type) 79 80 #define BFD_EP_EGRESS_IF(unit, id) \ 81 (BFD_HA_EP_INFO(unit,id).egress_if) 82 83 #define BFD_EP_GPORT(unit, id) \ 84 (BFD_HA_EP_INFO(unit,id).gport) 85 86 #define BFD_EP_TX_GPORT(unit, id) \ 87 (BFD_HA_EP_INFO(unit,id).tx_gport) 88 89 /* Macro to differentiate BFD encap type */ 90 #define BFD_ENCAP_TYPE_TNL_IPV4(x) ((x == bcmBFDTunnelTypeIp4in4) || (x == bcmBFDTunnelTypeIp4in6) || \ 91 (x == bcmBFDTunnelTypeGRE)|| (x == bcmBFDTunnelTypeGre4In6)) 92 93 94 #define BFD_ENCAP_TYPE_TNL_IPV6(x) ((x == bcmBFDTunnelTypeIp6in4) || (x == bcmBFDTunnelTypeIp6in6) || \ 95 (x == bcmBFDTunnelTypeGre6In4)|| (x == bcmBFDTunnelTypeGre6In6)) 96 97 98 #define BFD_ENCAP_TYPE_TNL_MPLS(x) ((x == bcmBFDTunnelTypeMpls) || (x == bcmBFDTunnelTypeMplsTpCc) || \ 99 (x == bcmBFDTunnelTypeMplsTpCcCv)) 100 101 #define BFD_LTSW_MAX_MPLS_LABELS 7 102 103 #define BFD_LTSW_MEP_IDENTIFIER_MAX_LENGTH 32 104 105 #define BCM_LTSW_BFD_ENDPOINT_IPV6 0x80000000 106 107 /* 108 * Default BFD RX Event Notification thread priority 109 */ 110 #define BCM_LTSW_BFD_THREAD_PRI_DFLT 200 111 112 113 #define BCMINT_BFD_MEM_ALLOC(_ptr, _sz, _str) \ 114 do { \ 115 SHR_ALLOC(_ptr, _sz, _str); \ 116 SHR_NULL_CHECK(_ptr, SHR_E_MEMORY); \ 117 sal_memset(_ptr, 0, _sz); \ 118 } while(0) 119 120 #define BCMINT_BFD_MEM_FREE(_ptr) \ 121 do { \ 122 SHR_FREE(_ptr); \ 123 } while(0) 124 125 /* Checks for 'null' argument */ 126 #define BFD_LTSW_PARAM_NULL_CHECK(arg_) \ 127 if ((arg_) == NULL) { \ 128 SHR_IF_ERR_EXIT(SHR_E_PARAM); \ 129 } 130 131 /* BFD Event Handler */ 132 typedef struct bfd_ltsw_event_handler_s { 133 struct bfd_ltsw_event_handler_s *next; 134 bcm_bfd_event_types_t event_types; 135 bcm_bfd_event_cb cb; 136 void *user_data; 137 } bfd_ltsw_event_handler_t; 138 139 /* Book keeping information to track allocation of BFD ids. */ 140 typedef struct bcmint_bfd_ha_info_s{ 141 /*! Bitmap of endpoint IDs.*/ 142 bcmi_bfd_epid_bmp_t *glb_id_bmp; 143 144 /*! Endpoint params: [EP_TYPE][EGRESS_IF][TX_GPORT][GPORT] */ 145 bcmi_bfd_ep_info_t *ep_info; 146 147 }bcmint_bfd_ha_info_t; 148 149 /* Internal data structure to store global BFD information. */ 150 typedef struct bcm_int_bfd_info_s { 151 /* Is BFD initialized*/ 152 bool init; 153 154 /* Maximum number of BFD endpoints that can be created */ 155 uint32_t max_endpoints; 156 157 /* Maximum number of BFD SHA1 authentication keys. */ 158 uint32_t max_auth_sha1_keys; 159 160 /* Maximum number of BFD simple password authentication keys. */ 161 uint32_t max_auth_simple_password_keys; 162 163 /* Maximum packet size. */ 164 uint32_t max_pkt_size; 165 166 /* Enable to use an internally generated value for the My Discriminator */ 167 bool use_ep_id_as_disc; 168 169 /* Enable to prevent the run-time update of the remote discriminator */ 170 bool static_remote_disc; 171 172 /* Enable to raise the LOCAL_STATE_DOWN event if the endpoint does not 173 transition to Up state after creation */ 174 bool state_down_event_on_ep_creation; 175 176 /* Enable to set the C bit when transmitting BFD control packets.*/ 177 bool cpi; 178 179 /*! Enable to allow transmission of BFD packets from the endpoints. */ 180 bool tx; 181 182 /*! Enable for raw ingress inject of BFD Tx packets. */ 183 bool tx_raw_ingress; 184 185 /* BFD module lock. */ 186 sal_mutex_t lock; 187 188 /* List of event handlers */ 189 bfd_ltsw_event_handler_t *event_handler_list; 190 191 /* BFD ID info */ 192 bcmint_bfd_ha_info_t ha_info; 193 } bcm_int_bfd_info_t; 194 195 extern bcm_int_bfd_info_t bfd_glb_info[BCM_MAX_NUM_UNITS]; 196 197 /* Chip common driver routines */ 198 extern int 199 bcm_ltsw_bfd_init_common(int unit); 200 201 extern int 202 bcm_ltsw_bfd_detach_common(int unit); 203 204 205 /* Logical tables access routines */ 206 207 extern int 208 bcm_ltsw_bfd_control_entry_get(int unit, 209 bcm_int_bfd_info_t *entry); 210 211 extern int 212 bcm_ltsw_bfd_control_entry_set(int unit, 213 bool update, 214 bcm_int_bfd_info_t *entry); 215 216 extern int 217 bcm_ltsw_bfd_tnl_mpls_endpoint_entry_set(int unit, 218 bool update, 219 bcm_bfd_endpoint_info_t *endpoint_info); 220 221 extern int 222 bcm_ltsw_bfd_tnl_ipv6_endpoint_entry_set(int unit, 223 bool update, 224 bcm_bfd_endpoint_info_t *endpoint_info); 225 226 extern int 227 bcm_ltsw_bfd_tnl_ipv4_endpoint_entry_set(int unit, 228 bool update, 229 bcm_bfd_endpoint_info_t *endpoint_info); 230 231 extern int 232 bcm_ltsw_bfd_ipv6_endpoint_entry_set(int unit, 233 bool update, 234 bcm_bfd_endpoint_info_t *endpoint_info); 235 236 extern int 237 bcm_ltsw_bfd_ipv4_endpoint_entry_set(int unit, 238 bool update, 239 bcm_bfd_endpoint_info_t *endpoint_info); 240 241 extern int 242 bcm_ltsw_bfd_endpoint_create_common(int unit, 243 bcm_bfd_endpoint_info_t *endpoint_info); 244 245 extern int 246 bcm_ltsw_bfd_tnl_mpls_endpoint_entry_get(int unit, 247 bcm_bfd_endpoint_info_t *endpoint_info); 248 249 extern int 250 bcm_ltsw_bfd_tnl_ipv6_endpoint_entry_get(int unit, 251 bcm_bfd_endpoint_info_t *endpoint_info); 252 253 extern int 254 bcm_ltsw_bfd_tnl_ipv4_endpoint_entry_get(int unit, 255 bcm_bfd_endpoint_info_t *endpoint_info); 256 257 extern int 258 bcm_ltsw_bfd_ipv6_endpoint_entry_get(int unit, 259 bcm_bfd_endpoint_info_t *endpoint_info); 260 261 extern int 262 bcm_ltsw_bfd_ipv4_endpoint_entry_get(int unit, 263 bcm_bfd_endpoint_info_t *endpoint_info); 264 265 extern int 266 bcm_ltsw_bfd_endpoint_entry_delete(int unit, 267 bcm_bfd_endpoint_t id); 268 269 extern int bcm_ltsw_bfd_endpoint_destroy_common(int unit, 270 bcm_bfd_endpoint_t endpoint); 271 272 extern int bcm_ltsw_bfd_destroy_all_common(int unit); 273 274 extern int bcm_ltsw_bfd_discard_stat_entry_get(int unit, 275 bcm_bfd_discard_stat_t *discarded_info); 276 277 extern int bcm_ltsw_bfd_discard_stat_entry_set(int unit, 278 bcm_bfd_discard_stat_t *discarded_info); 279 280 extern int bcm_ltsw_bfd_auth_simple_password_get_common(int unit, 281 int index, 282 bcm_bfd_auth_simple_password_t *sp); 283 284 extern int bcm_ltsw_bfd_auth_sha1_set_common(int unit, 285 int index, 286 bcm_bfd_auth_sha1_t *sha1); 287 288 extern int bcm_ltsw_bfd_auth_simple_password_set_common(int unit, 289 int index, 290 bcm_bfd_auth_simple_password_t *sp); 291 292 extern int bcm_ltsw_bfd_endpoint_poll_common(int unit, bcm_bfd_endpoint_t endpoint); 293 294 extern int bcm_ltsw_bfd_endpoint_get_common(int unit, 295 bcm_bfd_endpoint_t endpoint, 296 bcm_bfd_endpoint_info_t *endpoint_info); 297 298 extern int bcm_ltsw_bfd_endpoint_destroy_common(int unit, 299 bcm_bfd_endpoint_t endpoint); 300 301 extern int bcm_ltsw_bfd_destroy_all_common(int unit); 302 303 extern int bcm_ltsw_bfd_tx_set_common(int unit, bool enable); 304 305 extern int bcm_ltsw_bfd_endpoint_poll_common(int unit, bcm_bfd_endpoint_t endpoint); 306 307 extern int bcm_ltsw_bfd_auth_sha1_get_common(int unit, 308 int index, 309 bcm_bfd_auth_sha1_t *sha1); 310 311 extern int bcm_ltsw_bfd_endpoint_stat_entry_get(int unit, bcm_bfd_endpoint_t endpoint, 312 bcm_bfd_endpoint_stat_t *ctr_info); 313 314 extern int bcm_ltsw_bfd_endpoint_stat_entry_set(int unit, bcm_bfd_endpoint_t endpoint); 315 316 extern int bcm_ltsw_bfd_endpoint_stat_get_common(int unit, 317 bcm_bfd_endpoint_t endpoint, 318 bcm_bfd_endpoint_stat_t *ctr_info, uint32_t options); 319 320 extern int bcm_ltsw_bfd_endpoint_stat_entry_set(int unit, bcm_bfd_endpoint_t endpoint); 321 322 extern int bcm_ltsw_bfd_endpoint_stat_entry_get(int unit, bcm_bfd_endpoint_t endpoint, 323 bcm_bfd_endpoint_stat_t *ctr_info); 324 325 extern int bcm_ltsw_bfd_tx_start_field_set(int unit, bool enable); 326 327 extern int bcm_ltsw_bfd_endpoint_poll_field_set(int unit, bcm_bfd_endpoint_t endpoint); 328 329 extern int bcm_ltsw_bfd_endpoint_sp_entry_set(int unit, int index, 330 bcm_bfd_auth_simple_password_t *sp); 331 332 extern int bcm_ltsw_bfd_endpoint_sp_entry_get(int unit, int index, 333 bcm_bfd_auth_simple_password_t *sp); 334 335 extern int bcm_ltsw_bfd_endpoint_auth_sha1_entry_set(int unit, int index, bcm_bfd_auth_sha1_t *sha1); 336 337 extern int bcm_ltsw_bfd_endpoint_auth_sha1_entry_get(int unit, int index, bcm_bfd_auth_sha1_t *sha1); 338 339 extern int bcm_ltsw_bfd_event_control_entry_set(int unit, bcm_bfd_event_types_t event_types); 340 341 extern int 342 bcm_ltsw_bfd_event_entry_get(int unit, bcmlt_entry_handle_t entry_hdl, 343 bcm_bfd_event_type_t *event, int *ep_id); 344 345 extern int 346 bcm_ltsw_bfd_event_register_common(int unit, 347 bcm_bfd_event_types_t event_types, 348 bcm_bfd_event_cb cb, void *user_data); 349 350 extern int bcm_ltsw_bfd_endpoint_sp_entry_delete(int unit, int index); 351 352 extern int bcm_ltsw_bfd_endpoint_auth_sha1_entry_delete(int unit, 353 int index); 354 355 extern int bcm_ltsw_bfd_endpoint_status_entry_get(int unit, 356 bcm_bfd_endpoint_t endpoint, 357 bcm_bfd_endpoint_info_t *ep_info); 358 359 extern int bcm_ltsw_bfd_event_unregister_common(int unit, 360 bcm_bfd_event_types_t event_types, 361 bcm_bfd_event_cb cb); 362 #endif /* BCMINT_LTSW_BFD_INT_H */