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

compat_656.c (7876B)


      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  * RPC Compatibility with sdk-6.5.6 routines
      8  */
      9 
     10 #ifdef	BCM_RPC_SUPPORT
     11 
     12 #include <shared/alloc.h>
     13 
     14 #include <bcm/types.h>
     15 #include <bcm/error.h>
     16 
     17 #include <bcm_int/compat/compat_656.h>
     18 
     19 /*
     20  * Function:
     21  *      _bcm_compat656in_field_qset_t
     22  * Purpose:
     23  *      Convert the bcm_field_qset_t datatype from older versions to
     24  *      SDK 6.5.6+
     25  * Parameters:
     26  *      from        - (IN) The old version of the datatype
     27  *      to          - (OUT) The SDK 6.5.6+ version of the datatype
     28  * Returns:
     29  *      Nothing
     30  */
     31 STATIC void
     32 _bcm_compat656in_field_qset_t(
     33     bcm_compat656_field_qset_t *from,
     34     bcm_field_qset_t *to)
     35 {
     36     uint32  field_qualify_cnt_size =
     37         (BCM_COMPAT656_FIELD_QUALIFY_CNT < bcmFieldQualifyCount) ?
     38             BCM_COMPAT656_FIELD_QUALIFY_CNT :  bcmFieldQualifyCount;
     39     uint32  field_user_num_udfs_size =
     40        (BCM_COMPAT656_FIELD_USER_NUM_UDFS < BCM_FIELD_USER_NUM_UDFS) ?
     41         BCM_COMPAT656_FIELD_USER_NUM_UDFS : BCM_FIELD_USER_NUM_UDFS;
     42 
     43     SHR_BITCOPY_RANGE(to->w, 0, from->w, 0, field_qualify_cnt_size);
     44     SHR_BITCOPY_RANGE(to->w, bcmFieldQualifyCount,
     45                       from->w, BCM_COMPAT656_FIELD_QUALIFY_CNT,
     46                       field_user_num_udfs_size);
     47     SHR_BITCOPY_RANGE(to->udf_map, 0,
     48                       from->udf_map, 0,
     49                       field_user_num_udfs_size);
     50 }
     51 
     52 /*
     53  * Function:
     54  *      _bcm_compat656out_field_qset_t
     55  * Purpose:
     56  *      Convert the bcm_field_qset_t datatype from SDK 6.5.6+ to
     57  *      older versions
     58  * Parameters:
     59  *      from        - (IN) The SDK 6.5.6+ version of the datatype
     60  *      to          - (OUT) The old version of the datatype
     61  * Returns:
     62  *      Nothing
     63  */
     64 STATIC void
     65 _bcm_compat656out_field_qset_t(
     66     bcm_field_qset_t *from,
     67     bcm_compat656_field_qset_t *to)
     68 {
     69     uint32  field_qualify_cnt_size =
     70         (BCM_COMPAT656_FIELD_QUALIFY_CNT < bcmFieldQualifyCount) ?
     71             BCM_COMPAT656_FIELD_QUALIFY_CNT :  bcmFieldQualifyCount;
     72     uint32  field_user_num_udfs_size =
     73        (BCM_COMPAT656_FIELD_USER_NUM_UDFS < BCM_FIELD_USER_NUM_UDFS) ?
     74         BCM_COMPAT656_FIELD_USER_NUM_UDFS : BCM_FIELD_USER_NUM_UDFS;
     75 
     76     SHR_BITCOPY_RANGE(to->w, 0, from->w, 0, field_qualify_cnt_size);
     77     SHR_BITCOPY_RANGE(to->w, BCM_COMPAT656_FIELD_QUALIFY_CNT,
     78                       from->w, bcmFieldQualifyCount,
     79                       field_user_num_udfs_size);
     80     SHR_BITCOPY_RANGE(to->udf_map, 0,
     81                       from->udf_map, 0,
     82                       field_user_num_udfs_size);
     83 }
     84 
     85 /*
     86  * Function: bcm_compat656_field_group_create
     87  *
     88  * Purpose:
     89  *      Compatibility function for RPC call to bcm_field_group_create.
     90  *      Used to create a FP group using an older version of the datatype.
     91  *
     92  * Parameters:
     93  *     unit - (IN) BCM device number.
     94  *     qset - (IN) Old field qualifier set
     95  *     pri  - (IN) Priority within allowable range,
     96  *                 or BCM_FIELD_GROUP_PRIO_ANY to automatically assign
     97  *                 priority; each priority value may be used only once
     98  *     group - (OUT) New field group ID
     99  *
    100  * Returns:
    101  *     BCM_E_INIT     - BCM unit not initialized
    102  *     BCM_E_PARAM    - pri out of range (0-15 for FB & ER) or group == NULL
    103  *     BCM_E_RESOURCE - no select codes will satisfy qualifier set
    104  *     BCM_E_MEMORY   - allocation failure
    105  *     BCM_E_NONE     - Success
    106  */
    107 int
    108 bcm_compat656_field_group_create(int unit,
    109                                 bcm_compat656_field_qset_t qset,
    110                                 int pri,
    111                                 bcm_field_group_t *group)
    112 {
    113     int rv;
    114     bcm_field_qset_t *p_new_qset;
    115 
    116     /* Create the qualifier set from heap to avoid the stack to bloat */
    117     p_new_qset =
    118         (bcm_field_qset_t *) sal_alloc(sizeof(bcm_field_qset_t), "NewQset");
    119     if (NULL == p_new_qset) {
    120         return BCM_E_MEMORY;
    121     }
    122 
    123     /* Initialize the new qualifier set */
    124     BCM_FIELD_QSET_INIT(*p_new_qset);
    125 
    126     /* Transform the qulaifier set from the old format to new one */
    127     _bcm_compat656in_field_qset_t(&qset, p_new_qset);
    128 
    129     /* Call the BCM API with new qset format */
    130     rv = bcm_field_group_create(unit, *p_new_qset, pri, group);
    131 
    132     /* Deallocate the q set memory */
    133     sal_free(p_new_qset);
    134 
    135     return rv;
    136 }
    137 
    138 /*
    139  * Function: bcm_compat656_field_group_create_id
    140  *
    141  * Purpose:
    142  *      Compatibility function for RPC call to bcm_field_group_create_id.
    143  *      Used to create a FP group using an older version of the datatype.
    144  *
    145  * Parameters:
    146  *     unit - (IN) BCM device number.
    147  *     qset - (IN) Old field qualifier set
    148  *     pri  - (IN) Priority within allowable range,
    149  *                 or BCM_FIELD_GROUP_PRIO_ANY to automatically assign
    150  *                 priority; each priority value may be used only once
    151  *     group - (IN) Requested new field group ID
    152  *
    153  * Returns:
    154  *     BCM_E_INIT      - BCM unit not initialized
    155  *     BCM_E_RESOURCE  - No unused group/slices left
    156  *     BCM_E_PARAM     - priority out of range (0-15 for FB & ER)
    157  *     BCM_E_EXISTS    - group with that id already exists on this unit.
    158  *     BCM_E_MEMORY    - Memory allocation failure
    159  *     BCM_E_NONE      - Success
    160  */
    161 int
    162 bcm_compat656_field_group_create_id(int unit,
    163                                     bcm_compat656_field_qset_t qset,
    164                                     int pri,
    165                                     bcm_field_group_t group)
    166 {
    167     int rv;
    168     bcm_field_qset_t *p_new_qset;
    169 
    170     /* Create the qualifier set from heap to avoid the huge stack variable */
    171     p_new_qset =
    172         (bcm_field_qset_t *) sal_alloc(sizeof(bcm_field_qset_t), "NewQset");
    173     if (NULL == p_new_qset) {
    174         return BCM_E_MEMORY;
    175     }
    176 
    177     /* Initialize the new qualifier set */
    178     BCM_FIELD_QSET_INIT(*p_new_qset);
    179 
    180     /* Transform the qulaifier set from the old format to new one */
    181     _bcm_compat656in_field_qset_t(&qset, p_new_qset);
    182 
    183     /* Call the BCM API with new qset format */
    184     rv = bcm_field_group_create_id(unit, *p_new_qset, pri, group);
    185 
    186     /* Deallocate the q set memory */
    187     sal_free(p_new_qset);
    188 
    189     return (rv);
    190 }
    191 
    192 /*
    193  * Function: bcm_compat656_field_qset_data_qualifier_add
    194  *
    195  * Purpose:
    196  *      Compatibility function for RPC call to bcm_field_qset_data_qualifier_add
    197  *      Used to add field data qualifier to group qset.
    198  *
    199  * Parameters:
    200  *     unit - (IN) BCM device number.
    201  *     qset - (IN/OUT) Old group qualifier set
    202  *     qualifier_id  - (IN) Data qualifier id.
    203  *
    204  * Returns:
    205  *     BCM_E_XXX
    206  */
    207 int
    208 bcm_compat656_field_qset_data_qualifier_add(int unit,
    209                                             bcm_compat656_field_qset_t *qset,
    210                                             int qual_id)
    211 {
    212     int rv;
    213     bcm_field_qset_t *p_new_qset=NULL;
    214 
    215     /* Only tranform qualifier set if given a valid qset */
    216     if (qset) {
    217 
    218         /* Create the qualifier set from heap to avoid the stack to bloat */
    219         p_new_qset =
    220             (bcm_field_qset_t *)sal_alloc(sizeof(bcm_field_qset_t), "NewQset");
    221         if (NULL == p_new_qset) {
    222             return BCM_E_MEMORY;
    223         }
    224 
    225         /* Initialize the new qualifier set */
    226         BCM_FIELD_QSET_INIT(*p_new_qset);
    227 
    228         /* Transform the qualifier set from the old format to new one */
    229         _bcm_compat656in_field_qset_t(qset, p_new_qset);
    230     }
    231 
    232     /* Call the BCM API with new qset format */
    233     rv = bcm_field_qset_data_qualifier_add(unit, p_new_qset, qual_id);
    234 
    235     if (qset) {
    236         /* Copy back the qset from new to old format */
    237         if (BCM_SUCCESS(rv)) {
    238             _bcm_compat656out_field_qset_t(p_new_qset, qset);
    239         }
    240 
    241         /* Deallocate the q set memory */
    242         sal_free(p_new_qset);
    243     }
    244 
    245     return (rv);
    246 }
    247 
    248 #endif  /* BCM_RPC_SUPPORT */