bregex.h (15315B)
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 * Purpose: Internal regex function prototypes. 8 */ 9 10 #ifndef _BCM_INT_BREGEX_H_ 11 #define _BCM_INT_BREGEX_H_ 12 #include <soc/defs.h> 13 14 #if defined(INCLUDE_REGEX) 15 #include <bcm/debug.h> 16 #include <bcm_int/esw/field.h> 17 #include <sal/core/sync.h> 18 19 /* 20 * These features are not implemented yet. These identifiers should be removed once the 21 * feature is complete. 22 */ 23 #undef ESW_REGEX_STAT_SUPPORT 24 25 /* 26 * This feature is not supported and has not been tested. It will require the Flow 27 * Tracker to use a second pool of meters. Since meter pools are limited (only 8 on TR3 28 * and HX4) and also used by the Field Processor, only one meter pool is reserved for use 29 * by the Flow Tracker. 30 */ 31 #undef ESW_REGEX_HIERARCHICAL_METERS 32 33 typedef struct _regex_policy_s _regex_policy_t; 34 35 #define _REGEX_INVALID_INDEX -1 36 37 #define _REGEX_DEFAULT_POLICY_ID 0 38 /* 39 * Policy status flags. 40 */ 41 42 /* Software entry differs from one in hardware. */ 43 #define _REGEX_POLICY_DIRTY (1 << 0) 44 45 /* Entry has an ingress Mirror-To-Port reserved. */ 46 #define _REGEX_POLICY_MTP_ING0 (1 << 4) 47 48 /* Entry has an ingress 1 Mirror-To-Port reserved. */ 49 #define _REGEX_POLICY_MTP_ING1 (1 << 5) 50 51 /* Entry has an egress Mirror-To-Port reserved. */ 52 #define _REGEX_POLICY_MTP_EGR0 (1 << 6) 53 54 /* Entry has an egress 1 Mirror-To-Port reserved. */ 55 #define _REGEX_POLICY_MTP_EGR1 (1 << 7) 56 57 /* Field entry installed in hw. */ 58 #define _REGEX_POLICY_INSTALLED (1 << 9) 59 60 /* Treat all packets as green. */ 61 #define _REGEX_POLICY_COLOR_INDEPENDENT (1 << 10) 62 63 /* 64 * Action flags. 65 */ 66 /* Action valid. */ 67 #define _REGEX_ACTION_VALID (1 << 0) 68 /* Reinstall is required. */ 69 #define _REGEX_ACTION_DIRTY (1 << 1) 70 /* Remove action from hw. */ 71 #define _REGEX_ACTION_RESOURCE_FREE (1 << 2) 72 /* Action was updated free previously used hw resources. */ 73 #define _REGEX_ACTION_OLD_RESOURCE_FREE (1 << 3) 74 75 #define _REGEX_ACTION_MODIFY (1 << 4) 76 77 #define _REGEX_ACTION_HW_FREE (_REGEX_ACTION_RESOURCE_FREE | \ 78 _REGEX_ACTION_OLD_RESOURCE_FREE) 79 80 /* policy table Cos queue priority hw modes */ 81 #define _REGEX_ACTION_UCAST_MCAST_QUEUE_NEW_MODE 0x1 82 #define _REGEX_ACTION_UCAST_QUEUE_NEW_MODE 0x8 83 #define _REGEX_ACTION_MCAST_QUEUE_NEW_MODE 0x9 84 /* Action set unicast queue value */ 85 #define _REGEX_ACTION_UCAST_QUEUE_SET(q) ((q) & (0xf)) 86 /* Action set multicast queue value */ 87 #define _REGEX_ACTION_MCAST_QUEUE_SET(q) (((q) & 0x7) << 4) 88 /* Action get unicast queue value */ 89 #define _REGEX_ACTION_UCAST_QUEUE_GET(q) ((q) & (0xf)) 90 /* Action get multicast queue value */ 91 #define _REGEX_ACTION_MCAST_QUEUE_GET(q) (((q) >> 4) & 0x7) 92 /* Action set both unicast and multicast queue value */ 93 #define _REGEX_ACTION_UCAST_MCAST_QUEUE_SET(u,m) ((_REGEX_ACTION_UCAST_QUEUE_SET(u)) | \ 94 (_REGEX_ACTION_MCAST_QUEUE_SET(m))) 95 96 /* 97 * Policer macros 98 */ 99 #define _REGEX_POLICER_MAX_NUM 256 100 101 #if defined(ESW_REGEX_HIERARCHICAL_METERS) 102 #define _REGEX_POLICER_LEVEL_COUNT 2 103 #else 104 #define _REGEX_POLICER_LEVEL_COUNT 1 105 #endif 106 107 /* 108 * Macros for packing and unpacking L3 information for field actions 109 * into and out of a uint32 value. 110 */ 111 112 #define MAX_CNT_BITS 10 113 114 #define _REGEX_L3_ACTION_PACK_ECMP(ecmp_ptr, ecmp_cnt) \ 115 (0x80000000 | ((ecmp_ptr) << MAX_CNT_BITS) | (ecmp_cnt)) 116 #define _REGEX_L3_ACTION_UNPACK_ECMP_MODE(cookie) \ 117 ((cookie) >> 31) 118 #define _REGEX_L3_ACTION_UNPACK_ECMP_PTR(cookie) \ 119 (((cookie) & 0x7fffffff) >> MAX_CNT_BITS) 120 #define _REGEX_L3_ACTION_UNPACK_ECMP_CNT(cookie) \ 121 ((cookie) & ~(0xffffffff << MAX_CNT_BITS)) 122 123 #define _REGEX_L3_ACTION_PACK_NEXT_HOP(next_hop) \ 124 ((next_hop) & 0x7fffffff) 125 #define _REGEX_L3_ACTION_UNPACK_NEXT_HOP(cookie) \ 126 ((cookie) & 0x7fffffff) 127 128 /* Action conflict check macro. */ 129 #define _REGEX_POLICY_ACTIONS_CONFLICT(_val_) \ 130 if (action == _val_) { \ 131 return (BCM_E_CONFIG); \ 132 } 133 134 #define RegexPolicyMax(_unit_, _mem_, _field_) \ 135 ((soc_mem_field_length((_unit_), (_mem_) , (_field_)) < 32) ? \ 136 ((1 << soc_mem_field_length((_unit_), (_mem_), (_field_))) - 1) : \ 137 (0xFFFFFFFFUL)) 138 139 #define RegexPolicyGet(_unit_, _mem_, _entry_, _field_) \ 140 soc_mem_field32_get((_unit_), (_mem_), (_entry_), (_field_)) 141 142 #define RegexPolicySet(_unit_, _mem_, _entry_, _field_, _value_) \ 143 soc_mem_field32_set((_unit_), (_mem_), (_entry_), (_field_), (_value_)) 144 145 #define RegexPolicyCheck(_unit_, _mem_, _field_, _value_) \ 146 if ((uint32)(_value_) > (uint32)RegexPolicyMax((_unit_), (_mem_), (_field_))) { \ 147 LOG_ERROR(BSL_LS_BCM_REGEX, \ 148 (BSL_META_U(unit, \ 149 "FT(unit %d) Error: Policy _value_ %d > %d (max) mem (%d) policy (%d).\n"), \ 150 _unit_, (_value_), \ 151 (uint32)RegexPolicyMax((_unit_), (_mem_), (_field_)), \ 152 (_mem_), (_field_))); \ 153 return (BCM_E_PARAM); \ 154 } 155 156 #define _REGEX_POLICER_ID_ENCODE(u,idx) \ 157 ((((u) & 0xff) << 16) | ((idx) & 0xffff) | \ 158 (BCM_POLICER_TYPE_REGEX << BCM_POLICER_TYPE_SHIFT)) 159 160 #define _REGEX_POLICER_ID_TO_INDEX(pid) ((pid) & 0xffff) 161 162 #define _FT_ACTION_PARAM_SZ (4) 163 164 /* 165 * Typedef: 166 * _regex_policy_action_t 167 * Purpose: 168 * This is the real action storage structure that is hidden behind 169 * the opaque handle bcm_field_action_t. 170 */ 171 typedef struct _regex_policy_action_s { 172 bcm_field_action_t action; /* Action type */ 173 uint32 param[_FT_ACTION_PARAM_SZ]; 174 /* Action specific parameters */ 175 int hw_index; /* Allocated hw resource index. */ 176 int old_index; /* Hw resource to be freed, in */ 177 /* case action parameters were */ 178 /* modified. */ 179 uint8 flags; /* Field action flags. */ 180 struct _regex_policy_action_s *next; 181 } _regex_policy_action_t; 182 183 /* 184 * Typedef: 185 * _regex_policy_t 186 * Purpose: 187 * This is the physical entry structure, hidden behind the logical 188 * bcm_regex_policy_t handle. 189 * Notes: 190 * Entries are stored in an array in the _bcm_tr3_regex_device_info_t 191 * structure. 192 * 193 * Each entry can use 0 or 1 counters. Multiple entries may use the 194 * same counter. The only requirement is that the counter be within 195 * the same slice as the entry. I.e., cannot share counters with the FP 196 * since the flow table is in its own slice. 197 * 198 * Similarly each entry can use 0 or 1 meter. Multiple entries may use 199 * the same meter. The only requirement is that the meter be within 200 * the same slice as the entry. 201 */ 202 struct _regex_policy_s { 203 bcm_regex_policy_t eid; /* BCM unit unique entry identifier */ 204 uint32 flags; /* _REGEX_POLICY_xxx flags */ 205 _regex_policy_action_t *actions; /* linked list of actions for entry */ 206 _field_entry_stat_t statistic; /* Statistics collection entity. */ 207 /* Policers attached to the entry. */ 208 _field_entry_policer_t policer[_REGEX_POLICER_LEVEL_COUNT]; 209 }; 210 211 typedef struct _bcm_esw_regex_functions_s { 212 int (*policy_index_min_get)(int unit); 213 int (*policy_index_max_get)(int unit); 214 /* These next "check" functions should return the same answer as the similar FP 215 * functions for the ingress stage. */ 216 int (*policy_action_support_check)(int unit, 217 bcm_field_action_t action); 218 int (*policy_action_conflict_check)(int unit, 219 bcm_field_action_t action, 220 bcm_field_action_t action1); 221 int (*policy_action_params_check)(int unit, _regex_policy_t *p_ent, 222 _regex_policy_action_t *pa); 223 int (*policy_install)(int unit, _regex_policy_t *p_ent); 224 int (*policy_remove)(int unit, _regex_policy_t *p_ent); 225 int (*policer_install)(int unit, _field_policer_t *f_pl); 226 int (*redirect_profile_alloc)(int unit, _regex_policy_t *p_ent, 227 _regex_policy_action_t *pa); 228 int (*redirect_profile_delete)(int unit, int index); 229 int (*redirect_profile_ref_count_get)(int unit, int index, int *ref_count); 230 231 } _bcm_esw_regex_functions_t; 232 233 typedef struct _bcm_esw_regex_device_info_s { 234 235 sal_mutex_t regex_esw_mutex; 236 _regex_policy_t **policies; 237 int num_policies; 238 int policy_index_min; 239 int policy_index_max; 240 _field_policer_t *policers[_REGEX_POLICER_MAX_NUM]; 241 int meter_base_hw_index; 242 int meter_pool; 243 _bcm_esw_regex_functions_t *functions; 244 uint32 flags; 245 uint32 report_buffer_size; /* The number of entries which 246 * the report buffer can 247 * hold. */ 248 } _bcm_esw_regex_device_info_t; 249 250 /* 251 * These are various defines used for accessing the FT_SESSION and 252 * FT_SESSION_IPV6 tables. 253 */ 254 #define _REGEX_SESSION_DIRECTION_FORWARD 0x0 /* Value indicates 255 FT_SESSION entries 256 stored in the forward 257 direction. */ 258 #define _REGEX_SESSION_DIRECTION_REVERSE 0x1 /* Value indicates 259 FT_SESSION entries 260 stored in the forward 261 direction. */ 262 #define _REGEX_SESSION_AGE_PROFILE_TICKS_US 10000 /* Value indicates number 263 of us in an 264 AGE_PROFILE tick. */ 265 #define _REGEX_SESSION_KEY_TYPE_RESERVED 0x0 /* Value indicates 266 FT_SESSION reserved 267 KEY_TYPE. */ 268 #define _REGEX_SESSION_KEY_TYPE_IPV4 0x1 /* Value indicates 269 FT_SESSION IPV4 270 KEY_TYPE. */ 271 #define _REGEX_SESSION_KEY_TYPE_IPV6_UPPER 0x2 /* Value indicates 272 FT_SESSION IPV6_UPPER 273 KEY_TYPE. */ 274 #define _REGEX_SESSION_KEY_TYPE_IPV6_LOWER 0x3 /* Value indicates 275 FT_SESSION IPV6_LOWER 276 KEY_TYPE. */ 277 278 /* 279 Defines for the flow states 280 */ 281 282 #define _REGEX_SESSION_FLOW_STATE_VALIDATE 0x0 283 #define _REGEX_SESSION_FLOW_STATE_NEW 0x1 284 #define _REGEX_SESSION_FLOW_STATE_CMDWAIT 0x2 285 #define _REGEX_SESSION_FLOW_STATE_ACTIVE 0x3 286 #define _REGEX_SESSION_FLOW_STATE_HOLDWAIT 0x4 287 #define _REGEX_SESSION_FLOW_STATE_RETIRED 0x5 288 #define _REGEX_SESSION_FLOW_STATE_INVALID 0x6 289 #define _REGEX_SESSION_FLOW_STATE_RESERVED 0x7 /* Should not be used. */ 290 291 /* 292 Offsets and lengths for various sub-fields in the FT_SESSION key fields 293 */ 294 295 #define _REGEX_KEY_FIELD_LENGTH 104 296 297 #define _REGEX_KEY_FIELD_V4_OFFSET_PORT_1 0 298 #define _REGEX_KEY_FIELD_V4_OFFSET_PORT_2 16 299 #define _REGEX_KEY_FIELD_V4_OFFSET_PROTOCOL 32 300 #define _REGEX_KEY_FIELD_V4_OFFSET_IP_1 40 301 #define _REGEX_KEY_FIELD_V4_OFFSET_IP_2 72 302 303 #define _REGEX_KEY_FIELD_V4_LENGTH_PORT_1 16 304 #define _REGEX_KEY_FIELD_V4_LENGTH_PORT_2 16 305 #define _REGEX_KEY_FIELD_V4_LENGTH_PROTOCOL 8 306 #define _REGEX_KEY_FIELD_V4_LENGTH_IP_1 32 307 #define _REGEX_KEY_FIELD_V4_LENGTH_IP_2 32 308 309 #define _REGEX_KEY_UPPER_LENGTH 104 310 #define _REGEX_KEY_LOWER_LENGTH 192 311 312 #define _REGEX_KEY_LOWER_V6_OFFSET_PORT_1 0 313 #define _REGEX_KEY_LOWER_V6_OFFSET_PORT_2 16 314 #define _REGEX_KEY_LOWER_V6_OFFSET_PROTOCOL 32 315 #define _REGEX_KEY_LOWER_V6_OFFSET_IP_1 40 316 #define _REGEX_KEY_LOWER_V6_OFFSET_IP_2 168 317 #define _REGEX_KEY_UPPER_V6_OFFSET_IP_2 0 318 319 #define _REGEX_KEY_LOWER_V6_LENGTH_PORT_1 16 320 #define _REGEX_KEY_LOWER_V6_LENGTH_PORT_2 16 321 #define _REGEX_KEY_LOWER_V6_LENGTH_PROTOCOL 8 322 #define _REGEX_KEY_LOWER_V6_LENGTH_IP_1 128 323 #define _REGEX_KEY_LOWER_V6_LENGTH_IP_2 24 324 #define _REGEX_KEY_UPPER_V6_LENGTH_IP_2 104 325 326 #define _REGEX_PROTOCOL_PORT_LENGTH_V4 (_REGEX_KEY_FIELD_V4_LENGTH_PORT_1 + \ 327 _REGEX_KEY_FIELD_V4_LENGTH_PORT_2 + _REGEX_KEY_FIELD_V4_LENGTH_PROTOCOL) 328 329 #define _REGEX_PROTOCOL_PORT_LENGTH_V6 (_REGEX_KEY_LOWER_V6_LENGTH_PORT_1 + \ 330 _REGEX_KEY_LOWER_V6_LENGTH_PORT_2 + _REGEX_KEY_LOWER_V6_LENGTH_PROTOCOL) 331 332 /* 333 If set, the routines that get the FT Session data will also get 334 the key data. This is not normally necessary in a "get" call, 335 since the key data must already be known to get the entry. 336 However, in a traverse call, the key data is not already known, 337 and is different in each entry. 338 339 To use externally, this should be defined in bcm.papi.bregex 340 rather than in this file. 341 */ 342 #define _REGEX_GET_KEY_FROM_HW_ENTRY 0x1 343 #define _REGEX_ENTRY_TYPE_IS_IPV6 0x2 344 345 int _bcm_regex_policy_action_dest_check(int unit, _regex_policy_action_t *pa); 346 347 void _bcm_esw_regex_policy_action_t_init(_regex_policy_action_t *pa); 348 void _bcm_esw_regex_policy_t_init(_regex_policy_t *policy); 349 void _bcm_esw_regex_device_info_t_init(_bcm_esw_regex_device_info_t *info); 350 351 int _bcm_regex_policy_set_l3_nh_resolve(int unit, int value, 352 uint32 *flags, int *nh_ecmp_id); 353 354 int _bcm_regex_policer_get(int unit, bcm_policer_t pid, 355 _field_policer_t **policer_p); 356 int _bcm_esw_regex_policer_create(int unit, bcm_policer_config_t *pol_cfg, 357 bcm_policer_t *pid); 358 int _bcm_esw_regex_policer_destroy(int unit, bcm_policer_t policer_id); 359 int _bcm_esw_regex_policer_destroy_all(int unit); 360 int _bcm_esw_regex_policer_traverse(int unit, bcm_policer_traverse_cb cb, 361 void *user_data); 362 363 int _bcm_esw_regex_report_reset(int unit); 364 365 #endif /* defined(INCLUDE_REGEX) */ 366 367 #endif /* _BCM_INT_BREGEX_H_ */