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

bcmx_int.h (7888B)


      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:        bcmx_int.h
      8  * Purpose:     Internal header file for BCMX
      9  */
     10 
     11 #ifndef   _BCMX_BCMX_INT_H_
     12 #define   _BCMX_BCMX_INT_H_
     13 
     14 
     15 #include <sal/core/sync.h>
     16 #include <bcm/types.h>
     17 
     18 /*
     19  * The BCMX logical port is currently defined as a gport type
     20  * and it can refer to a physical or a virtual port.
     21  * 
     22  * BCMX maintains a port list which contains the physical ports
     23  * of attached units.
     24  *
     25  * Some BCMX APIs require the port to be in the BCMX port list;
     26  * other APIs can take virtual ports.
     27  *
     28  * The following macros can be used to check for lport:
     29  *   BCMX_IS_LPORT / BCMX_LPORT_CHECK
     30  *   Check that port is within allowed value range.
     31  *   Port can be of most gport types (physical and virtual ports).
     32  * 
     33  *   BCMX_LPORT_VALID / BCMX_LPORT_VALID_CHECK
     34  *   Check that port is in the BCMX port list.
     35  *
     36  *   BCMX_LPORT_IS_PHYSICAL
     37  *   Check that port is an allowed physical port value.
     38  */
     39 
     40 /* Check that port is within allowed value range (physical/virtual ports) */
     41 #define BCMX_IS_LPORT(_lport)       \
     42     (BCM_GPORT_IS_SET(_lport) &&    \
     43      !BCM_GPORT_IS_LOCAL(_lport) && !BCM_GPORT_IS_LOCAL_CPU(_lport))
     44 
     45 /* Same as above, but performs a return in calling routine on failure */
     46 #define BCMX_LPORT_CHECK(_lport)   \
     47     if (!BCMX_IS_LPORT(_lport)) { return BCM_E_PORT; }
     48 
     49 /* Check that port is in the BCMX port list; performs return on failure */
     50 #define BCMX_LPORT_VALID_CHECK(_lport)   \
     51     if (!bcmx_lport_valid(_lport)) { return BCM_E_PORT; }
     52 
     53 /* Check that given lport is an allowed physical port value */
     54 #define BCMX_LPORT_IS_PHYSICAL(_lport)                              \
     55     (BCM_GPORT_IS_MODPORT(_lport) || BCM_GPORT_IS_DEVPORT(_lport))
     56 
     57 
     58 /* Cast lport <-> gport */
     59 #define BCMX_LPORT_TO_GPORT_CAST(_lport)    ((bcm_gport_t)(_lport))
     60 #define BCMX_GPORT_TO_LPORT_CAST(_gport)    ((bcmx_lport_t)(_gport))
     61 
     62 
     63 /* Check for 'null' argument (returns on failure) */
     64 #define BCMX_PARAM_NULL_CHECK(_arg)  if ((_arg) == NULL) {return BCM_E_PARAM;}
     65 #define BCMX_PARAM_ARRAY_NULL_CHECK(_size, _arg_array)    \
     66     if (_size > 0) { BCMX_PARAM_NULL_CHECK(_arg_array); }
     67 
     68 
     69 #include <bcm_int/control.h>
     70 #define BCMX_UNITS_MAX BCM_CONTROL_MAX
     71 
     72 extern int bcmx_unit_list[BCMX_UNITS_MAX];
     73 
     74 extern sal_mutex_t bcmx_config_lock;
     75 
     76 extern int _bcmx_rx_running;
     77 extern volatile int _bcmx_l2n_running;
     78 
     79 
     80 /*
     81  * Sanity check macros for BCMX subsystem state
     82  *
     83  * BCMX can be in one of these following states:
     84  *   - Unitialized
     85  *       Initial BCMX software layer state
     86  *   - Initialized, no units attached
     87  *       State after calling bcmx_init()
     88  *   - Initialized, unit(s) attached
     89  *       State after calling bcmx_device_attach()
     90  */
     91 /* Check that BCMX is initialized */
     92 #define BCMX_INIT          (bcmx_config_lock != NULL)
     93 #define BCMX_INIT_CHECK    if (!BCMX_INIT) { return BCM_E_INIT; }
     94 
     95 /* Check that BCMX contains at least one unit */
     96 #define BCMX_UNIT          (bcmx_unit_count > 0)
     97 #define BCMX_UNIT_CHECK    if (!BCMX_UNIT) { return BCM_E_CONFIG; }
     98 
     99 /* Check that BCMX is initialized and contains at least one unit */
    100 #define BCMX_READY         (BCMX_INIT && BCMX_UNIT)
    101 #define BCMX_READY_CHECK    do {     \
    102         BCMX_INIT_CHECK;      \
    103         BCMX_UNIT_CHECK;      \
    104     } while (0)
    105 
    106 
    107 #define BCMX_CONFIG_LOCK sal_mutex_take(bcmx_config_lock, sal_sem_FOREVER)
    108 #define BCMX_CONFIG_UNLOCK sal_mutex_give(bcmx_config_lock)
    109 
    110 /*
    111  * BCMX error code check
    112  */
    113 extern int _bcmx_error_check(int unit, int check, int ignore, int *rv);
    114 
    115 #define BCMX_FABRIC_E_UNAVAIL(_unit, _rv)  \
    116     ((_rv == BCM_E_UNAVAIL) && BCM_IS_FABRIC(_unit))
    117 
    118 #define BCMX_ERROR_IS_VALID(_unit, _rv)  (!BCMX_FABRIC_E_UNAVAIL(_unit, _rv))
    119 
    120 #define BCMX_ERROR_CHECK(_unit, _check, _rv)    \
    121     (_bcmx_error_check(_unit, _check, BCM_E_NONE, _rv))
    122 
    123 #define BCMX_SET_ERROR_CHECK(_unit, _check, _rv)    \
    124     (_bcmx_error_check(_unit, _check, BCM_E_EXISTS, _rv))
    125 
    126 #define BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv)    \
    127     (_bcmx_error_check(_unit, _check, BCM_E_NOT_FOUND, _rv))
    128 
    129 
    130 #define BCMX_UNIT_ITER(unit, i)                                           \
    131     for (i = 0, unit = bcmx_unit_list[0];                                 \
    132          i < bcmx_unit_count;                                             \
    133          unit = bcmx_unit_list[++i])
    134 
    135 #define BCMX_LOCAL_UNIT_ITER(unit, i)                                     \
    136     for (i = 0, unit = bcmx_unit_list[0];                                 \
    137          i < bcmx_unit_count;                                             \
    138          unit = bcmx_unit_list[++i]) if (BCM_IS_LOCAL(unit))
    139 
    140 
    141 /* Get local CPU lport if set */
    142 extern bcmx_lport_t bcmx_lport_local_cpu[BCM_CONTROL_MAX];
    143 #define BCMX_LPORT_LOCAL_CPU_GET(bcm_unit) (bcmx_lport_local_cpu[bcm_unit])
    144 
    145 
    146 /*
    147  * Conversion BCMX to/from BCM destination information
    148  */
    149 typedef struct _bcmx_dest_bcmx_s {
    150     bcmx_lport_t  port;    /* BCMX logical port (gport format) */
    151     bcm_trunk_t   trunk;   /* Trunk id */
    152     int           mcast;   /* Mcast */
    153 } _bcmx_dest_bcmx_t;
    154 
    155 typedef struct _bcmx_dest_bcm_s {
    156     int           unit;         /* Device unit number */
    157     bcm_port_t    port;         /* Device port number (old format) or gport */
    158     bcm_module_t  module_id;    /* Module id */
    159     bcm_port_t    module_port;  /* Module relative port (old format) or gport */
    160     bcm_trunk_t   trunk;        /* Trunk id */
    161     int           mcast;        /* Mcast */
    162 } _bcmx_dest_bcm_t;
    163 
    164 
    165 /*
    166  * Conversion flags BCMX to/from BCM destination information
    167  *
    168  * NOTES:
    169  *   GPORT_AWARE  - Convert to new gport format, used only when
    170  *                  translating to BCM
    171  *   TRUNK        - Data is in old format, data is in 'trunk' member
    172  *   MCAST        - Data is in old format, data is in 'mcast' member
    173  */
    174 #define BCMX_DEST_GPORT_AWARE  0x00000001  /* BCM can handle GPORT */
    175 #define BCMX_DEST_TRUNK        0x00000002  /* Trunk */
    176 #define BCMX_DEST_MCAST        0x00000004  /* Mcast */
    177 #define BCMX_DEST_DISCARD      0x00000008  /* Black hole */
    178 #define BCMX_DEST_LOCAL_CPU    0x00000010  /* Local CPU */
    179 
    180 /*
    181  * Initializer routines
    182  */
    183 extern void
    184 _bcmx_dest_bcmx_t_init(_bcmx_dest_bcmx_t *dest_bcmx);
    185 
    186 extern void
    187 _bcmx_dest_bcm_t_init(_bcmx_dest_bcm_t *dest_bcm);
    188 
    189 /*
    190  * Conversion routines for destination structures
    191  */
    192 extern int
    193 _bcmx_dest_to_bcm(_bcmx_dest_bcmx_t *from_bcmx, _bcmx_dest_bcm_t *to_bcm,
    194                   uint32 *flags);
    195 
    196 extern int
    197 _bcmx_dest_from_bcm(_bcmx_dest_bcmx_t *to_bcmx, _bcmx_dest_bcm_t *from_bcm,
    198                     uint32 *flags);
    199 
    200 /*
    201  * Conversion default flag for BCMX to/from BCM.
    202  * 
    203  * Current default flag value indicates to convert to new BCM port
    204  * format (gport), for _bcmx_dest_to_modid_port() or
    205  * _bcmx_dest_unit_port() routines.
    206  */
    207 #define BCMX_DEST_CONVERT_NON_GPORT  0x0
    208 #define BCMX_DEST_CONVERT_GPORT      BCMX_DEST_GPORT_AWARE
    209 #define BCMX_DEST_CONVERT_DEFAULT    BCMX_DEST_CONVERT_GPORT
    210 
    211 /*
    212  * Conversion routines for specific destination information
    213  * (module/port, unit/port, ...)
    214  */
    215 extern int
    216 _bcmx_dest_to_modid_port(bcmx_lport_t port,
    217                          bcm_module_t *bcm_module, bcm_port_t *bcm_port,
    218                          uint32 flags);
    219 extern int
    220 _bcmx_dest_from_modid_port(bcmx_lport_t *port,
    221                            bcm_module_t bcm_module, bcm_port_t bcm_port,
    222                            uint32 flags);
    223 extern int
    224 _bcmx_dest_to_unit_port(bcmx_lport_t port,
    225                         int *bcm_unit, bcm_port_t *bcm_port,
    226                         uint32 flags);
    227 
    228 extern int
    229 _bcmx_dest_from_unit_port(bcmx_lport_t *port,
    230                           int bcm_unit, bcm_port_t bcm_port,
    231                           uint32 flags);
    232 
    233 extern int
    234 _bcmx_port_changed(bcmx_lport_t lport);
    235 
    236 
    237 #endif /* _BCMX_BCMX_INT_H_ */