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

subport.c (6710B)


      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/subport.c
      8  * Purpose:     BCMX Subport Configuration APIs
      9  */
     10 
     11 #include <bcm/types.h>
     12 
     13 #include <bcmx/lport.h>
     14 #include <bcmx/subport.h>
     15 
     16 #include "bcmx_int.h"
     17 
     18 #define BCMX_SUBPORT_INIT_CHECK    BCMX_READY_CHECK
     19 
     20 #define BCMX_SUBPORT_ERROR_CHECK(_unit, _check, _rv)    \
     21     BCMX_ERROR_CHECK(_unit, _check, _rv)
     22 
     23 #define BCMX_SUBPORT_SET_ERROR_CHECK(_unit, _check, _rv)    \
     24     BCMX_SET_ERROR_CHECK(_unit, _check, _rv)
     25 
     26 #define BCMX_SUBPORT_DELETE_ERROR_CHECK(_unit, _check, _rv)    \
     27     BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv)
     28 
     29 #define BCMX_SUBPORT_GET_IS_VALID(_unit, _rv)    \
     30     BCMX_ERROR_IS_VALID(_unit, _rv)
     31 
     32 #define BCMX_SUBPORT_ERROR_IS_VALID(_unit, _rv)    \
     33     BCMX_ERROR_IS_VALID(_unit, _rv)
     34 
     35 
     36 #define BCMX_SUBPORT_GROUP_CONFIG_T_PTR_TO_BCM(_config)    \
     37     ((bcm_subport_group_config_t *)(_config))
     38 
     39 #define BCMX_SUBPORT_CONFIG_T_PTR_TO_BCM(_config)    \
     40     ((bcm_subport_config_t *)(_config))
     41 
     42 
     43 /*
     44  * Function:
     45  *     bcmx_subport_group_config_t_init
     46  */
     47 void
     48 bcmx_subport_group_config_t_init(bcmx_subport_group_config_t *config)
     49 {
     50     if (config != NULL) {
     51         bcm_subport_group_config_t_init
     52             (BCMX_SUBPORT_GROUP_CONFIG_T_PTR_TO_BCM(config));
     53     }
     54 }
     55 
     56 /*
     57  * Function:
     58  *     bcmx_subport_config_t_init
     59  */
     60 void
     61 bcmx_subport_config_t_init(bcmx_subport_config_t *config)
     62 {
     63     if (config != NULL) {
     64         bcm_subport_config_t_init
     65             (BCMX_SUBPORT_CONFIG_T_PTR_TO_BCM(config));
     66     }
     67 }
     68 
     69 
     70 /*
     71  * Function:
     72  *     bcmx_subport_init
     73  */
     74 int
     75 bcmx_subport_init(void)
     76 {
     77     int  rv = BCM_E_UNAVAIL, tmp_rv;
     78     int  i, bcm_unit;
     79 
     80     BCMX_SUBPORT_INIT_CHECK;
     81 
     82     BCMX_UNIT_ITER(bcm_unit, i) {
     83         tmp_rv = bcm_subport_init(bcm_unit);
     84         BCM_IF_ERROR_RETURN(BCMX_SUBPORT_ERROR_CHECK(bcm_unit, tmp_rv, &rv));
     85     }
     86 
     87     return rv;
     88 }
     89 
     90 /*
     91  * Function:
     92  *     bcmx_subport_cleanup
     93  */
     94 int
     95 bcmx_subport_cleanup(void)
     96 {
     97     int  rv = BCM_E_UNAVAIL, tmp_rv;
     98     int  i, bcm_unit;
     99 
    100     BCMX_SUBPORT_INIT_CHECK;
    101 
    102     BCMX_UNIT_ITER(bcm_unit, i) {
    103         tmp_rv = bcm_subport_cleanup(bcm_unit);
    104         BCM_IF_ERROR_RETURN(BCMX_SUBPORT_ERROR_CHECK(bcm_unit, tmp_rv, &rv));
    105     }
    106 
    107     return rv;
    108 }
    109 
    110 /*
    111  * Function:
    112  *     bcmx_subport_group_create
    113  */
    114 int
    115 bcmx_subport_group_create(bcmx_subport_group_config_t *config, 
    116                           bcm_gport_t *group)
    117 {
    118     int  rv = BCM_E_UNAVAIL, tmp_rv;
    119     int  i, bcm_unit;
    120     bcmx_subport_group_config_t  tmp_config;
    121 
    122     BCMX_SUBPORT_INIT_CHECK;
    123 
    124     BCMX_PARAM_NULL_CHECK(config);
    125     BCMX_PARAM_NULL_CHECK(group);
    126 
    127     tmp_config = *config;
    128     BCMX_UNIT_ITER(bcm_unit, i) {
    129 
    130         tmp_rv = bcm_subport_group_create(bcm_unit,
    131                                           BCMX_SUBPORT_GROUP_CONFIG_T_PTR_TO_BCM
    132                                           (&tmp_config),
    133                                           group);
    134         BCM_IF_ERROR_RETURN
    135             (BCMX_SUBPORT_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv));
    136 
    137         /*
    138          * Use the ID from first successful 'create' if group ID
    139          * is not specified.
    140          */
    141         if (!(tmp_config.flags & BCM_SUBPORT_GROUP_WITH_ID)) {
    142             if (BCM_SUCCESS(tmp_rv)) {
    143                 tmp_config.flags |= BCM_SUBPORT_GROUP_WITH_ID;
    144             }
    145         }
    146     }
    147 
    148     return rv;
    149 }
    150 
    151 /*
    152  * Function:
    153  *     bcmx_subport_group_destroy
    154  */
    155 int
    156 bcmx_subport_group_destroy(bcm_gport_t group)
    157 {
    158     int  rv = BCM_E_UNAVAIL, tmp_rv;
    159     int  i, bcm_unit;
    160 
    161     BCMX_SUBPORT_INIT_CHECK;
    162 
    163     BCMX_UNIT_ITER(bcm_unit, i) {
    164         tmp_rv = bcm_subport_group_destroy(bcm_unit, group);
    165         BCM_IF_ERROR_RETURN
    166             (BCMX_SUBPORT_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv));
    167     }
    168 
    169     return rv;
    170 }
    171 
    172 /*
    173  * Function:
    174  *     bcmx_subport_group_get
    175  */
    176 int
    177 bcmx_subport_group_get(bcm_gport_t group, bcmx_subport_group_config_t *config)
    178 {
    179     int  rv;
    180     int  i;
    181     int  bcm_unit;
    182 
    183     BCMX_SUBPORT_INIT_CHECK;
    184 
    185     BCMX_PARAM_NULL_CHECK(config);
    186 
    187     BCMX_UNIT_ITER(bcm_unit, i) {
    188         rv = bcm_subport_group_get(bcm_unit, group,
    189                                    BCMX_SUBPORT_GROUP_CONFIG_T_PTR_TO_BCM
    190                                    (config));
    191         if (BCMX_SUBPORT_GET_IS_VALID(bcm_unit, rv)) {
    192             return rv;
    193         }
    194     }
    195 
    196     return BCM_E_UNAVAIL;
    197 }
    198 
    199 /*
    200  * Function:
    201  *     bcmx_subport_port_add
    202  */
    203 int
    204 bcmx_subport_port_add(bcmx_subport_config_t *config, bcm_gport_t *port)
    205 {
    206     int  rv = BCM_E_UNAVAIL, tmp_rv;
    207     int  i;
    208     int  bcm_unit;
    209 
    210     BCMX_SUBPORT_INIT_CHECK;
    211 
    212     BCMX_PARAM_NULL_CHECK(config);
    213     BCMX_PARAM_NULL_CHECK(port);
    214 
    215     /*
    216      * A subport port is added only in the unit where the physical
    217      * port resides, and this information is known at the BCM layer.
    218      *
    219      * The agreed behavior between BCM and BCMX is that
    220      * the BCM will return BCM_E_PARAM whenever the 'add' function
    221      * is called on a unit where the physical port does not belong.
    222      *
    223      * The BCMX, on the other hand, will iterate over the units
    224      * and returns on the first successful 'add' of the subport port.
    225      */
    226     BCMX_UNIT_ITER(bcm_unit, i) {
    227         tmp_rv = bcm_subport_port_add(bcm_unit,
    228                                       BCMX_SUBPORT_CONFIG_T_PTR_TO_BCM
    229                                       (config),
    230                                       port);
    231         if (!BCMX_SUBPORT_ERROR_IS_VALID(bcm_unit, tmp_rv)) {  /* Ignore */
    232             continue;
    233         }
    234 
    235         rv = tmp_rv;
    236         if (tmp_rv == BCM_E_PARAM) {  /* Port is not in unit, try next */
    237             continue;
    238         }
    239 
    240         break;
    241     }
    242 
    243     return rv;
    244 }
    245 
    246 /*
    247  * Function:
    248  *     bcmx_subport_port_delete
    249  */
    250 int
    251 bcmx_subport_port_delete(bcm_gport_t port)
    252 {
    253     int  rv = BCM_E_UNAVAIL, tmp_rv;
    254     int  i;
    255     int  bcm_unit;
    256 
    257     BCMX_SUBPORT_INIT_CHECK;
    258 
    259     BCMX_UNIT_ITER(bcm_unit, i) {
    260         tmp_rv = bcm_subport_port_delete(bcm_unit, port);
    261         BCM_IF_ERROR_RETURN
    262             (BCMX_SUBPORT_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv));
    263     }
    264 
    265     return rv;
    266 }
    267 
    268 /*
    269  * Function:
    270  *     bcmx_subport_port_get
    271  */
    272 int bcmx_subport_port_get(bcm_gport_t port, bcmx_subport_config_t *config)
    273 {
    274     int  rv;
    275     int  i;
    276     int  bcm_unit;
    277 
    278     BCMX_SUBPORT_INIT_CHECK;
    279 
    280     BCMX_PARAM_NULL_CHECK(config);
    281 
    282     BCMX_UNIT_ITER(bcm_unit, i) {
    283         rv = bcm_subport_port_get(bcm_unit, port,
    284                                   BCMX_SUBPORT_CONFIG_T_PTR_TO_BCM(config));
    285         if (BCMX_SUBPORT_GET_IS_VALID(bcm_unit, rv)) {
    286             return rv;
    287         }
    288     }
    289 
    290     return BCM_E_UNAVAIL;
    291 }
    292 
    293 
    294