openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

lplist.h (11003B)


      1 /*
      2  * 
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2020 Broadcom Inc. All rights reserved.
      7  * 
      8  * DO NOT EDIT THIS FILE!
      9  * This file is auto-generated.
     10  * Edits to this file will be lost when it is regenerated.
     11  */
     12 
     13 #ifndef __BCMX_LPLIST_H__
     14 #define __BCMX_LPLIST_H__
     15 
     16 #include <bcm/types.h>
     17 #include <bcmx/types.h>
     18 
     19 /* 
     20  * Deprecated flags to indicate groups of ports.
     21  * 
     22  * Use BCMX_PORT_LP_* instead.
     23  */
     24 #define BCMX_LP_ALL             (1 << 0)   /* 0x00000001 */
     25 #define BCMX_LP_FE              (1 << 1)   /* 0x00000002 */
     26 #define BCMX_LP_GE              (1 << 2)   /* 0x00000004 */
     27 #define BCMX_LP_XE              (1 << 3)   /* 0x00000008 */
     28 #define BCMX_LP_HG              (1 << 4)   /* 0x00000010 */
     29 
     30 /* 
     31  * Deprecated flags.
     32  * 
     33  * BCMX_LP_UNIQ:  Elements appear on the list at most once.
     34  * BCMX_LP_SORT:  Keep the list sorted by bcmx_lport value
     35  * BCMX_LP_USER is a flag that can be used at the application level
     36  */
     37 #define BCMX_LP_UNIQ            (1 << 5)   /* 0x00000020 */
     38 #define BCMX_LP_SORT            (1 << 6)   /* 0x00000040 */
     39 #define BCMX_LP_USER            (1 << 8)   /* 0x00000100 */
     40 
     41 /* BCMX Logical Port List */
     42 typedef struct bcmx_lplist_s {
     43     int lp_last;            /* Index of last elt on list. -1 --> empty (only
     44                                significant if list is not null). */
     45     int lp_alloc;           /* How many spaces currently allocated. */
     46     bcmx_lport_t *lp_ports; /* Pointer to the ports. */
     47 } bcmx_lplist_t;
     48 
     49 /* 
     50  * Logical Port List macros.
     51  * 
     52  *      BCMX_LPLIST_ADD(list, lport)
     53  *           Add an element to the end of the list; doesn't check
     54  *           for sorted or uniquness.
     55  *           Alias for function w/ same (lower case) name
     56  *      BCMX_LPLIST_REMOVE(list, lport)
     57  *           Search for the first occurrance of lport on the list
     58  *           and remove it if found.
     59  *      BCMX_LPLIST_IDX_REMOVE(list, idx)
     60  *           Remove the lport at idx
     61  *      BCMX_LPLIST_ITER(list, lport, count)
     62  *           Iterate through the list (passed by value)
     63  *           in order of the array
     64  *      BCMX_LPLIST_IDX_ITER(list, lport, count)
     65  *           Iterate through the list (passed by reference)
     66  *           in order of the array
     67  *      BCMX_LPLIST_IS_NULL
     68  *           Boolean: Is list invalid?
     69  *      BCMX_LPLIST_IS_EMPTY
     70  *           Boolean:  Is list invalid or has no elements?
     71  *      BCMX_LPLIST_COUNT
     72  *           Returns the number of elements on the list
     73  */
     74 #define BCMX_LPLIST_IS_NULL(list)  \
     75     (((void *)(list) == NULL) || ((list)->lp_ports == NULL)) 
     76 #define BCMX_LPLIST_IS_EMPTY(list)  \
     77     (BCMX_LPLIST_IS_NULL(list) || ((list)->lp_last < 0)) 
     78 #define BCMX_LPLIST_COUNT(list)  \
     79     (BCMX_LPLIST_IS_EMPTY(list) ? 0 : ((list)->lp_last + 1)) 
     80 #define BCMX_LPLIST_IDX_REMOVE(list, idx)  do {                 \
     81     int _i;                                                     \
     82                                                                 \
     83     if (((idx) >= 0) && ((idx) <= (list)->lp_last)) {           \
     84         for (_i = (idx); _i < (list)->lp_last; _i++) {          \
     85             (list)->lp_ports[_i] = (list)->lp_ports[_i + 1];    \
     86         }                                                       \
     87         ((list)->lp_last)--;                                    \
     88     }                                                           \
     89 } while (0) 
     90 #define BCMX_LPLIST_REMOVE(list, lport)  do {                   \
     91     int _idx;                                                   \
     92                                                                 \
     93     _idx = bcmx_lplist_index_get(list, lport);                  \
     94     if (_idx >= 0) {                                            \
     95         BCMX_LPLIST_IDX_REMOVE(list, _idx);                     \
     96     }                                                           \
     97 } while (0) 
     98 #define BCMX_LPLIST_ADD(list, lport)  \
     99     bcmx_lplist_add(list, lport) /* Alias bcmx_lplist_add as a macro. */
    100 #define BCMX_LPLIST_IDX_ITER(list_p, lport, count)               \
    101     for ((lport) = (list_p)->lp_ports[0], (count) = 0;           \
    102          (count) <= (list_p)->lp_last;                           \
    103          (lport) = (list_p)->lp_ports[++(count)]) /* NOTE:  List is a pointer here; not
    104                                               a pointer below.  Ick. */
    105 
    106 /* 
    107  * Iterate across a port list.
    108  *    Notes:  If a port is on the list twice, it will
    109  *    occur twice in the loop.
    110  *    Does not support flags in the port list (ALL, FE, GE....)
    111  * NOTE:  List is NOT a pointer here; it is a pointer above.  Ick.
    112  */
    113 #define BCMX_LPLIST_ITER(list, lport, count)  \
    114     BCMX_LPLIST_IDX_ITER(&(list), lport, count) 
    115 
    116 /* 
    117  * Logical Port List functions.
    118  * 
    119  *   int  bcmx_lplist_init(list, init_count, flags)
    120  *   void bcmx_lplist_t_init(list)
    121  *      Initialize the lplist.
    122  *   int  bcmx_lplist_free(list)
    123  *   void bcmx_lplist_t_free(list)
    124  *      Free an initialized lplist.
    125  *   int bcmx_lplist_clear(list)
    126  *      Clear an lplist.
    127  *   int bcmx_lplist_index_get(list, lport)
    128  *      Return the index of lport
    129  *   int bcmx_lplist_index_get_from(list, position, port)
    130  *      Return the index of lport starting at position
    131  *   bcmx_lport_t bcmx_lplist_index(list, position)
    132  *      Return the lport at position
    133  *   int bcmx_lplist_add(list, lport)
    134  *      Add lport to the end of list
    135  *   int bcmx_lplist_port_remove(list, lport, all)
    136  *      Remove first or all lport from list
    137  *   int bcmx_lplist_eq(list1, list2)
    138  *      Return 1 if lists have the same members (O(N^2))
    139  *   int bcmx_lplist_append(list1, list2)
    140  *      Append list2 to list2
    141  *   int bcmx_lplist_copy(dest, src)
    142  *      Copy src to dest
    143  *   int bcmx_lplist_check(list)
    144  *      Check list consistency
    145  *   int bcmx_lplist_range(list, start, end)
    146  *      Add range of lports to list
    147  * 
    148  * Compatibility
    149  * 
    150  *   bcmx_lplist_first(list)
    151  *      Return first lport in list
    152  *   bcmx_lplist_last_insert(list, port)
    153  *      Same as bcmx_lplist_add()
    154  * 
    155  * Removed for SDK 5.3.0
    156  * 
    157  *   BCMX_LP_ALL
    158  *   BCMX_LP_FE
    159  *   BCMX_LP_GE
    160  *   BCMX_LP_XE
    161  *   BCMX_LP_HG
    162  * 
    163  *     BCMX_PORT_LP_* and bcmx_port_lplist_populate provide equivalent
    164  *     functionality.
    165  * 
    166  * 
    167  *   BCMX_LP_SORT
    168  *   BCMX_LP_UNIQ
    169  * 
    170  *     Use bcmx_lplist_sort() and bcmx_lplist_uniq() to sort and
    171  *     make lists contail unique members.
    172  * 
    173  * 
    174  *   BCMX_LP_USER
    175  * 
    176  *     No equivalent functionality provided.
    177  * 
    178  *   bcmx_lplist_current_insert()
    179  *   bcmx_lplist_current_delete()
    180  *   bcmx_lplist_last_insert()
    181  *   bcmx_lplist_insert()
    182  *   bcmx_lplist_next()
    183  *   bcmx_lplist_current()
    184  *   bcmx_lplist_merge()
    185  *   BCMX_LPL_DEF_LEN
    186  * 
    187  *   No equivalent functionality provided.
    188  */
    189 
    190 extern int bcmx_lplist_init(
    191     bcmx_lplist_t *list, 
    192     int init_count, 
    193     uint32 flags);
    194 
    195 extern int bcmx_lplist_free(
    196     bcmx_lplist_t *list);
    197 
    198 extern int bcmx_lplist_clear(
    199     bcmx_lplist_t *list);
    200 
    201 extern void bcmx_lplist_t_init(
    202     bcmx_lplist_t *list);
    203 
    204 extern void bcmx_lplist_t_free(
    205     bcmx_lplist_t *list);
    206 
    207 extern int bcmx_lplist_index_get(
    208     bcmx_lplist_t *list, 
    209     bcmx_lport_t port);
    210 
    211 extern int bcmx_lplist_index_get_from(
    212     bcmx_lplist_t *list, 
    213     int position, 
    214     bcmx_lport_t port);
    215 
    216 extern bcmx_lport_t bcmx_lplist_index(
    217     bcmx_lplist_t *list, 
    218     int position);
    219 
    220 /* Compatibility. */
    221 #define bcmx_lplist_first(list)  bcmx_lplist_index((list), 0) 
    222 #define bcmx_lplist_last_insert(list, port)  bcmx_lplist_add((list), (port)) 
    223 
    224 extern int bcmx_lplist_add(
    225     bcmx_lplist_t *list, 
    226     bcmx_lport_t lport);
    227 
    228 extern int bcmx_lplist_port_remove(
    229     bcmx_lplist_t *list, 
    230     bcmx_lport_t lport, 
    231     int all);
    232 
    233 extern int bcmx_lplist_eq(
    234     bcmx_lplist_t *list1, 
    235     bcmx_lplist_t *list2);
    236 
    237 extern int bcmx_lplist_append(
    238     bcmx_lplist_t *list1, 
    239     bcmx_lplist_t *list2);
    240 
    241 extern int bcmx_lplist_copy(
    242     bcmx_lplist_t *dest, 
    243     bcmx_lplist_t *src);
    244 
    245 extern int bcmx_lplist_check(
    246     bcmx_lplist_t *list);
    247 
    248 extern int bcmx_lplist_range(
    249     bcmx_lplist_t *list, 
    250     bcmx_lport_t start, 
    251     bcmx_lport_t end);
    252 
    253 extern int bcmx_lplist_is_null(
    254     bcmx_lplist_t *list);
    255 
    256 extern int bcmx_lplist_is_empty(
    257     bcmx_lplist_t *list);
    258 
    259 extern int bcmx_lplist_count(
    260     bcmx_lplist_t *list);
    261 
    262 extern void bcmx_lplist_remove(
    263     bcmx_lplist_t *list, 
    264     int lport);
    265 
    266 extern void bcmx_lplist_idx_remove(
    267     bcmx_lplist_t *list, 
    268     int idx);
    269 
    270 extern int bcmx_lplist_pbmp_add(
    271     bcmx_lplist_t *list, 
    272     int unit, 
    273     bcm_pbmp_t *pbm);
    274 
    275 extern void bcmx_lplist_to_pbmp(
    276     bcmx_lplist_t *list, 
    277     int unit, 
    278     bcm_pbmp_t *pbm);
    279 
    280 extern int bcmx_lplist_sort(
    281     bcmx_lplist_t *list);
    282 
    283 extern int bcmx_lplist_uniq(
    284     bcmx_lplist_t *list);
    285 
    286 extern int _bcmx_lplist_pbmp_add(
    287     bcmx_lplist_t *list, 
    288     int unit, 
    289     bcm_pbmp_t pbm);
    290 
    291 /* 
    292  * LP List to port bitmap function/macros.
    293  * 
    294  *     BCMX_LPLIST_TO_PBMP   -- Extract ports from an lplist to a bitmap
    295  *                              Procedural (no return value)
    296  *     BCMX_LPLIST_PBMP_ADD  -- Add ports from a bitmap to an lplist
    297  *                              Returns BCM_E_XXX.
    298  * 
    299  * Note:  These macros are inefficient and may be replaced with a
    300  * better implementation (with lplist changes) in the future.
    301  */
    302 #define BCMX_LPLISTPTR_TO_PBMP(_lplist, _unit, _pbm)  do {               \
    303     bcmx_lport_t _lport;                                                 \
    304     int _count;                                                          \
    305     int _cpu_port;                                                       \
    306     int _bcm_unit;                                                       \
    307     bcm_port_t _bcm_port;                                                \
    308     BCM_PBMP_CLEAR(_pbm);                                                \
    309     BCMX_LPLIST_IDX_ITER(((_lplist)), _lport, _count) {                  \
    310         if (_lport == BCMX_LPORT_LOCAL_CPU) {                            \
    311             if (bcmx_lport_local_cpu_get(_unit, &_cpu_port) >= 0) {      \
    312                 BCM_PBMP_PORT_ADD(_pbm, BCMX_LPORT_BCM_PORT(_cpu_port)); \
    313             }                                                            \
    314         } else if (BCMX_LPORT_VALID(_lport)) {                           \
    315             bcmx_lport_to_unit_port(_lport, &_bcm_unit, &_bcm_port);     \
    316             if (_bcm_unit == _unit) {                                    \
    317                 BCM_PBMP_PORT_ADD(_pbm, _bcm_port);                      \
    318             }                                                            \
    319         }                                                                \
    320     }                                                                    \
    321 } while (0) 
    322 #define BCMX_LPLIST_TO_PBMP(_lplist, _unit, _pbm)  \
    323     BCMX_LPLISTPTR_TO_PBMP(&_lplist, _unit, _pbm) 
    324 #define BCMX_LPLIST_PBMP_ADD(_lplist_p, _unit, _pbm)  \
    325     _bcmx_lplist_pbmp_add(_lplist_p, _unit, _pbm) 
    326 
    327 #endif /* __BCMX_LPLIST_H__ */