field.h (3892B)
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 * File: field.h 8 * Purpose: Register/memory field descriptions 9 */ 10 11 #ifndef _SOC_FIELD_H 12 #define _SOC_FIELD_H 13 14 #include <soc/types.h> 15 #if defined(BCM_ESW_SUPPORT) || defined(BCM_SAND_SUPPORT) || defined(PORTMOD_SUPPORT) 16 #include <soc/mcm/allenum.h> 17 #endif 18 #include <soc/schanmsg.h> 19 #include <soc/types.h> 20 21 22 /* Values for flags */ 23 24 #define SOCF_LE 0x01 /* little endian */ 25 #define SOCF_RO 0x02 /* read only */ 26 #define SOCF_WO 0x04 /* write only */ 27 28 #define SOCF_LSB 0x05 /* Used for define the MAC Address format */ 29 #define SOCF_MSB 0x06 /* Used for define the MAC Address format */ 30 31 #define SOCF_SC 0x08 32 #define SOCF_RES 0x10 /* reserved (do not test, etc.) */ 33 #define SOCF_GLOBAL 0x20 /* Fields common to different views */ 34 #define SOCF_W1TC 0x40 /* write 1 to clear, TREX2 STYLE field only */ 35 #define SOCF_COR 0x80 /* clear on read, TREX2 STYLE field only */ 36 #define SOCF_PUNCH 0x100 /* punch bit, write 1 but always read 0. TREX2 STYLE field only */ 37 #define SOCF_WVTC 0x200 /* write value to clear */ 38 #define SOCF_RWBW 0x400 /* read/write, block writable, TREX2 STYLE field only */ 39 #define SOCF_SIG 0x800 /* Field is a signal*/ 40 #define SOCF_INTR 0x1000 /*field is an interrupt */ 41 #define SOCF_IGNORE_DEFAULT_TEST 0x2000 /*field is an for ignore default test */ 42 #define SOCF_COUNTER 0x4000 /* field is a counter */ 43 44 45 46 typedef struct soc_field_info_s { 47 soc_field_t field; 48 uint16 len; /* Bits in field */ 49 uint16 bp; /* Least bit position of the field */ 50 uint16 flags; /* Logical OR of SOCF_* */ 51 } soc_field_info_t; 52 53 /* 54 * Find field _fsrch in the field list _flist (with _fnum entries) 55 * Sets _infop to the field_info of _fsrch or NULL if not found 56 */ 57 #define SOC_FIND_FIELD(_fsrch, _flist, _fnum, _infop) do { \ 58 soc_field_info_t *__s, *__m, *__e; \ 59 _infop = NULL; \ 60 __s = _flist; \ 61 if (__s->field == _fsrch) { \ 62 _infop = __s; \ 63 } else { \ 64 __e = &__s[_fnum-1]; \ 65 if (__e->field == _fsrch) { \ 66 _infop = __e; \ 67 } else { \ 68 __m = __s + _fnum/2; \ 69 while ((__s < __e) && (__m < __e) && (__s->field != _fsrch) && \ 70 (__m->field != _fsrch)) { \ 71 if (_fsrch < __m->field) { \ 72 __e = __m - 1; \ 73 } else if (_fsrch > __m->field) { \ 74 __s = __m + 1; \ 75 } else { \ 76 break; \ 77 } \ 78 __m = __s + ((__e-__s)+1)/2; \ 79 } \ 80 if (__m->field == _fsrch) { \ 81 _infop = __m; \ 82 } else if (__s->field == _fsrch) { \ 83 _infop = __s; \ 84 } \ 85 } \ 86 } \ 87 } while (0) 88 89 EXTERN int soc_mem_field_length(int unit, soc_mem_t mem, soc_field_t field); 90 91 #define SOC_MEM_FIELD32_VALUE_MAX(_unit, _mem, _field) \ 92 ((soc_mem_field_length((_unit), (_mem) , (_field)) < 32) ? \ 93 ((1 << soc_mem_field_length((_unit), (_mem), (_field))) - 1) : \ 94 ((uint32)(0xFFFFFFFF))) 95 96 #define SOC_MEM_FIELD32_VALUE_FIT(_unit, _mem, _field, _value) \ 97 (((uint32)(_value)) <= SOC_MEM_FIELD32_VALUE_MAX((_unit), (_mem), (_field))) 98 99 #if !defined(SOC_NO_NAMES) 100 EXTERN char *soc_fieldnames[]; 101 #define SOC_FIELD_NAME(unit, field) soc_fieldnames[field] 102 #else 103 #define SOC_FIELD_NAME(unit, field) "" 104 #endif 105 106 #endif /* !_SOC_FIELD_H */