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

udf.c (25890B)


      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-2019 Broadcom Inc. All rights reserved.
      7  */
      8 
      9 #include <bcm/udf.h>
     10 #include <bcm/error.h>
     11 
     12 #include <soc/defs.h>
     13 #include <soc/drv.h>
     14 
     15 #include <bcm_int/esw/xgs4.h>
     16 #include <bcm_int/esw/udf.h>
     17 #include <bcm_int/esw/udf_common.h>
     18 
     19 #if defined (BCM_TRIUMPH2_SUPPORT)
     20 #if defined(BCM_WARM_BOOT_SUPPORT)
     21 int
     22 _bcm_esw_udf_scache_sync(int unit)
     23 {
     24     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
     25         int rv = BCM_E_UNAVAIL; 
     26 
     27         _BCM_UDF_INIT_CHECK(unit);
     28 
     29         _BCM_UDF_LOCK(unit);
     30         if (UDF_CONTROL(unit)->functions.udf_wb_sync != NULL) {
     31            rv =  UDF_CONTROL(unit)->functions.udf_wb_sync(unit);
     32         }
     33         _BCM_UDF_UNLOCK(unit);
     34 
     35         return rv;
     36     }
     37 
     38     if (soc_feature(unit, soc_feature_udf_support)) {
     39         return bcmi_xgs4_udf_wb_sync(unit);
     40     }
     41 
     42     return BCM_E_NONE;
     43 }
     44 #endif /* BCM_WARM_BOOT_SUPPORT */
     45 #endif /* BCM_TRIUMPH2_SUPPORT */
     46 
     47 /*
     48  * Function:
     49  *      bcm_udf_init
     50  * Purpose:
     51  *      Initialize UDF module
     52  * Parameters:
     53  *      unit - (IN) Unit number.
     54  * Returns:
     55  *      BCM_E_NONE          UDF module initialized successfully.
     56  *      BCM_E_UNIT          Invalid BCM Unit number.
     57  *      BCM_E_UNAVAIL       Feature not supported.
     58  *      BCM_E_XXX           Standard error code.
     59  * Notes:
     60  */
     61 int
     62 bcm_esw_udf_init(
     63     int unit)
     64 {
     65     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
     66         int rv = BCM_E_UNAVAIL; 
     67 
     68         _BCM_UDF_LOCK(unit);
     69         rv = _bcm_udf_common_init(unit);
     70         _BCM_UDF_UNLOCK(unit);
     71 
     72         return rv;
     73     }
     74 #if defined (BCM_TRIUMPH2_SUPPORT)
     75     if (soc_feature(unit, soc_feature_udf_support)) {
     76         return bcmi_xgs4_udf_init(unit);
     77     }
     78 #endif
     79 
     80     return BCM_E_UNAVAIL;
     81 }
     82 
     83 
     84 /*
     85  * Function:
     86  *      bcm_udf_detach
     87  * Purpose:
     88  *      Detach UDF module
     89  * Parameters:
     90  *      unit - (IN) Unit number.
     91  * Returns:
     92  *      BCM_E_NONE          UDF module detached successfully.
     93  *      BCM_E_UNIT          Invalid BCM Unit number.
     94  *      BCM_E_INIT          UDF module not initialized.
     95  *      BCM_E_UNAVAIL       Feature not supported.
     96  *      BCM_E_XXX           Standard error code.
     97  * Notes:
     98  */
     99 int
    100 bcm_esw_udf_detach(
    101     int unit)
    102 {
    103     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    104         int rv = BCM_E_UNAVAIL; 
    105 
    106         _BCM_UDF_INIT_CHECK(unit);
    107 
    108         _BCM_UDF_LOCK(unit);
    109         rv = _bcm_udf_common_detach(unit);
    110         _BCM_UDF_UNLOCK(unit);
    111 
    112         return rv;
    113     }
    114 #if defined (BCM_TRIUMPH2_SUPPORT)
    115     if (soc_feature(unit, soc_feature_udf_support)) {
    116         return bcmi_xgs4_udf_detach(unit);
    117     }
    118 #endif
    119 
    120     return BCM_E_UNAVAIL;
    121 }
    122 
    123 
    124 /*
    125  * Function:
    126  *      bcm_udf_create
    127  * Purpose:
    128  *      Creates a UDF object
    129  * Parameters:
    130  *      unit - (IN) Unit number.
    131  *      hints - (IN) Hints to UDF allocator
    132  *      udf_info - (IN) UDF structure
    133  *      udf_id - (IN/OUT) UDF ID
    134  * Returns:
    135  *      BCM_E_NONE          UDF created successfully.
    136  *      BCM_E_EXISTS        Entry already exists.
    137  *      BCM_E_FULL          UDF table full.
    138  *      BCM_E_UNIT          Invalid BCM Unit number.
    139  *      BCM_E_INIT          UDF module not initialized.
    140  *      BCM_E_UNAVAIL       Feature not supported.
    141  *      BCM_E_XXX           Standard error code.
    142  * Notes:
    143  */
    144 int
    145 bcm_esw_udf_create(
    146     int unit,
    147     bcm_udf_alloc_hints_t *hints,
    148     bcm_udf_t *udf_info,
    149     bcm_udf_id_t *udf_id)
    150 {
    151 #if defined (BCM_TRIUMPH2_SUPPORT)
    152     if (soc_feature(unit, soc_feature_udf_support)) {
    153         return bcmi_xgs4_udf_create(unit, hints, udf_info, udf_id);
    154     }
    155 #endif
    156 
    157     return BCM_E_UNAVAIL;
    158 }
    159 
    160 
    161 /*
    162  * Function:
    163  *      bcm_udf_get
    164  * Purpose:
    165  *      Fetches the UDF object created in the system
    166  * Parameters:
    167  *      unit - (IN) Unit number.
    168  *      udf_id - (IN) UDF Object ID
    169  *      udf_info - (OUT) UDF info structure
    170  * Returns:
    171  *      BCM_E_NONE          UDF get successful.
    172  *      BCM_E_NOT_FOUND     UDF does not exist.
    173  *      BCM_E_UNIT          Invalid BCM Unit number.
    174  *      BCM_E_INIT          UDF module not initialized.
    175  *      BCM_E_UNAVAIL       Feature not supported.
    176  *      BCM_E_XXX           Standard error code.
    177  * Notes:
    178  */
    179 int
    180 bcm_esw_udf_get(
    181     int unit,
    182     bcm_udf_id_t udf_id,
    183     bcm_udf_t *udf_info)
    184 {
    185 #if defined (BCM_TRIUMPH2_SUPPORT)
    186     if (soc_feature(unit, soc_feature_udf_support)) {
    187         return bcmi_xgs4_udf_get(unit, udf_id, udf_info);
    188     }
    189 #endif
    190 
    191     return BCM_E_UNAVAIL;
    192 }
    193 
    194 
    195 /*
    196  * Function:
    197  *      bcm_udf_get_all
    198  * Purpose:
    199  *      Fetches all existing UDF ids
    200  * Parameters:
    201  *      unit - (IN) Unit number.
    202  *      max - (IN) Max number of UDF IDs
    203  *      udf_id_list - (OUT) List of UDF IDs
    204  *      actual - (OUT) Actual udfs retrieved
    205  * Returns:
    206  *      BCM_E_NONE          UDF get successful.
    207  *      BCM_E_UNIT          Invalid BCM Unit number.
    208  *      BCM_E_INIT          UDF module not initialized.
    209  *      BCM_E_UNAVAIL       Feature not supported.
    210  *      BCM_E_XXX           Standard error code.
    211  * Notes:
    212  */
    213 int
    214 bcm_esw_udf_get_all(
    215     int unit,
    216     bcm_udf_id_t max,
    217     bcm_udf_id_t *udf_id_list,
    218     int *actual)
    219 {
    220 #if defined (BCM_TRIUMPH2_SUPPORT)
    221     if (soc_feature(unit, soc_feature_udf_support)) {
    222         return bcmi_xgs4_udf_get_all(unit, max, udf_id_list, actual);
    223     }
    224 #endif
    225 
    226     return BCM_E_UNAVAIL;
    227 }
    228 
    229 
    230 /*
    231  * Function:
    232  *      bcm_udf_destroy
    233  * Purpose:
    234  *      Destroys the UDF object
    235  * Parameters:
    236  *      unit - (IN) Unit number.
    237  *      udf_id - (IN) UDF Object ID
    238  * Returns:
    239  *      BCM_E_NONE          UDF deleted successfully.
    240  *      BCM_E_NOT_FOUND     UDF does not exist.
    241  *      BCM_E_UNIT          Invalid BCM Unit number.
    242  *      BCM_E_INIT          UDF module not initialized.
    243  *      BCM_E_UNAVAIL       Feature not supported.
    244  *      BCM_E_XXX           Standard error code.
    245  * Notes:
    246  */
    247 int
    248 bcm_esw_udf_destroy(
    249     int unit,
    250     bcm_udf_id_t udf_id)
    251 {
    252     int rv = BCM_E_UNAVAIL;
    253 
    254     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    255         _BCM_UDF_INIT_CHECK(unit);
    256         _BCM_UDF_LOCK(unit);
    257         if (UDF_CONTROL(unit)->functions.udf_destroy != NULL) {
    258            rv = UDF_CONTROL(unit)->functions.udf_destroy(unit, udf_id);
    259         }
    260         _BCM_UDF_UNLOCK(unit);
    261         return rv;
    262     }
    263 
    264 #if defined (BCM_TRIUMPH2_SUPPORT)
    265     if (soc_feature(unit, soc_feature_udf_support)) {
    266         return bcmi_xgs4_udf_destroy(unit, udf_id);
    267     }
    268 #endif
    269 
    270     return rv;
    271 }
    272 
    273 
    274 /*
    275  * Function:
    276  *      bcm_udf_pkt_format_create
    277  * Purpose:
    278  *      Create a packet format entry
    279  * Parameters:
    280  *      unit - (IN) Unit number.
    281  *      options - (IN) API Options.
    282  *      pkt_format - (IN) UDF packet format info structure
    283  *      pkt_format_id - (OUT) Packet format ID
    284  * Returns:
    285  *      BCM_E_NONE          UDF packet format entry created
    286  *                          successfully.
    287  *      BCM_E_UNIT          Invalid BCM Unit number.
    288  *      BCM_E_INIT          UDF module not initialized.
    289  *      BCM_E_UNAVAIL       Feature not supported.
    290  *      BCM_E_XXX           Standard error code.
    291  * Notes:
    292  */
    293 int
    294 bcm_esw_udf_pkt_format_create(
    295     int unit,
    296     bcm_udf_pkt_format_options_t options,
    297     bcm_udf_pkt_format_info_t *pkt_format,
    298     bcm_udf_pkt_format_id_t *pkt_format_id)
    299 {
    300 #if defined (BCM_TRIUMPH2_SUPPORT)
    301     if (soc_feature(unit, soc_feature_udf_support)) {
    302         return bcmi_xgs4_udf_pkt_format_create(unit, options,
    303                                               pkt_format, pkt_format_id);
    304     }
    305 #endif
    306 
    307     return BCM_E_UNAVAIL;
    308 }
    309 
    310 
    311 /*
    312  * Function:
    313  *      bcm_udf_pkt_format_info_get
    314  * Purpose:
    315  *      Retrieve packet format info given the packet format Id
    316  * Parameters:
    317  *      unit - (IN) Unit number.
    318  *      pkt_format_id - (IN) Packet format ID
    319  *      pkt_format - (OUT) UDF packet format info structure
    320  * Returns:
    321  *      BCM_E_NONE          Packet format get successful.
    322  *      BCM_E_NOT_FOUND     Packet format entry does not exist.
    323  *      BCM_E_UNIT          Invalid BCM Unit number.
    324  *      BCM_E_INIT          UDF module not initialized.
    325  *      BCM_E_UNAVAIL       Feature not supported.
    326  *      BCM_E_XXX           Standard error code.
    327  * Notes:
    328  */
    329 int
    330 bcm_esw_udf_pkt_format_info_get(
    331     int unit,
    332     bcm_udf_pkt_format_id_t pkt_format_id,
    333     bcm_udf_pkt_format_info_t *pkt_format)
    334 {
    335 #if defined (BCM_TRIUMPH2_SUPPORT)
    336     if (soc_feature(unit, soc_feature_udf_support)) {
    337         return bcmi_xgs4_udf_pkt_format_info_get(unit,
    338                                                 pkt_format_id, pkt_format);
    339     }
    340 #endif
    341 
    342     return BCM_E_UNAVAIL;
    343 }
    344 
    345 
    346 /*
    347  * Function:
    348  *      bcm_udf_pkt_format_destroy
    349  * Purpose:
    350  *      Destroy existing packet format entry
    351  * Parameters:
    352  *      unit - (IN) Unit number.
    353  *      pkt_format_id - (IN) Packet format ID
    354  *      pkt_format - (IN) UDF packet format info structure
    355  * Returns:
    356  *      BCM_E_NONE          Destroy packet format entry.
    357  *      BCM_E_NOT_FOUND     Packet format ID does not exist.
    358  *      BCM_E_UNIT          Invalid BCM Unit number.
    359  *      BCM_E_INIT          UDF module not initialized.
    360  *      BCM_E_UNAVAIL       Feature not supported.
    361  *      BCM_E_XXX           Standard error code.
    362  * Notes:
    363  */
    364 int
    365 bcm_esw_udf_pkt_format_destroy(
    366     int unit,
    367     bcm_udf_pkt_format_id_t pkt_format_id)
    368 {
    369 #if defined (BCM_TRIUMPH2_SUPPORT)
    370     if (soc_feature(unit, soc_feature_udf_support)) {
    371         return bcmi_xgs4_udf_pkt_format_destroy(unit, pkt_format_id);
    372     }
    373 #endif
    374 
    375     return BCM_E_UNAVAIL;
    376 }
    377 
    378 
    379 /*
    380  * Function:
    381  *      bcm_udf_pkt_format_add
    382  * Purpose:
    383  *      Adds packet format entry to UDF object
    384  * Parameters:
    385  *      unit - (IN) Unit number.
    386  *      udf_id - (IN) UDF ID
    387  *      pkt_format_id - (IN) Packet format ID
    388  * Returns:
    389  *      BCM_E_NONE          Packet format entry added to UDF
    390  *                          successfully.
    391  *      BCM_E_NOT_FOUND     UDF Id or packet format entry does not
    392  *                          exist.
    393  *      BCM_E_UNIT          Invalid BCM Unit number.
    394  *      BCM_E_INIT          UDF module not initialized.
    395  *      BCM_E_UNAVAIL       Feature not supported.
    396  *      BCM_E_XXX           Standard error code.
    397  * Notes:
    398  */
    399 int
    400 bcm_esw_udf_pkt_format_add(
    401     int unit,
    402     bcm_udf_id_t udf_id,
    403     bcm_udf_pkt_format_id_t pkt_format_id)
    404 {
    405 #if defined (BCM_TRIUMPH2_SUPPORT)
    406     if (soc_feature(unit, soc_feature_udf_support)) {
    407         return bcmi_xgs4_udf_pkt_format_add(unit, udf_id, pkt_format_id);
    408     }
    409 #endif
    410 
    411     return BCM_E_UNAVAIL;
    412 }
    413 
    414 
    415 /*
    416  * Function:
    417  *      bcm_udf_pkt_format_get
    418  * Purpose:
    419  *      Fetches all UDFs that share the common packet format entry.
    420  * Parameters:
    421  *      unit - (IN) Unit number.
    422  *      pkt_format_id - (IN) Packet format ID.
    423  *      max - (IN) Max number of UDF IDs
    424  *      udf_id_list - (OUT) List of UDF IDs
    425  *      actual - (OUT) Actual udfs retrieved
    426  * Returns:
    427  *      BCM_E_NONE          Success.
    428  *      BCM_E_UNIT          Invalid BCM Unit number.
    429  *      BCM_E_INIT          UDF module not initialized.
    430  *      BCM_E_UNAVAIL       Feature not supported.
    431  *      BCM_E_XXX           Standard error code.
    432  * Notes:
    433  */
    434 int
    435 bcm_esw_udf_pkt_format_get(
    436     int unit,
    437     bcm_udf_pkt_format_id_t pkt_format_id,
    438     bcm_udf_id_t max,
    439     bcm_udf_id_t *udf_id_list,
    440     int *actual)
    441 {
    442 #if defined (BCM_TRIUMPH2_SUPPORT)
    443     if (soc_feature(unit, soc_feature_udf_support)) {
    444         return bcmi_xgs4_udf_pkt_format_get(unit, pkt_format_id,
    445                                             max, udf_id_list, actual);
    446     }
    447 #endif
    448 
    449     return BCM_E_UNAVAIL;
    450 }
    451 
    452 
    453 /*
    454  * Function:
    455  *      bcm_udf_pkt_format_delete
    456  * Purpose:
    457  *      Deletes packet format spec associated with the UDF
    458  * Parameters:
    459  *      unit - (IN) Unit number.
    460  *      udf_id - (IN) UDF ID
    461  *      pkt_format_id - (IN) Packet format ID
    462  * Returns:
    463  *      BCM_E_NONE          Packet format configuration successfully
    464  *                          deleted from UDF.
    465  *      BCM_E_NOT_FOUND     UDF Id or packet format entry does not
    466  *                          exist.
    467  *      BCM_E_UNIT          Invalid BCM Unit number.
    468  *      BCM_E_INIT          UDF module not initialized.
    469  *      BCM_E_UNAVAIL       Feature not supported.
    470  *      BCM_E_XXX           Standard error code.
    471  * Notes:
    472  */
    473 int
    474 bcm_esw_udf_pkt_format_delete(
    475     int unit,
    476     bcm_udf_id_t udf_id,
    477     bcm_udf_pkt_format_id_t pkt_format_id)
    478 {
    479 #if defined (BCM_TRIUMPH2_SUPPORT)
    480     if (soc_feature(unit, soc_feature_udf_support)) {
    481         return bcmi_xgs4_udf_pkt_format_delete(unit, udf_id, pkt_format_id);
    482     }
    483 #endif
    484 
    485     return BCM_E_UNAVAIL;
    486 }
    487 
    488 
    489 /*
    490  * Function:
    491  *      bcm_udf_pkt_format_get_all
    492  * Purpose:
    493  *      Retrieves the user defined format specification configuration
    494  *      from UDF
    495  * Parameters:
    496  *      unit - (IN) Unit number.
    497  *      udf_id - (IN) UDF ID
    498  *      max - (IN) Max Packet formats attached to a UDF object
    499  *      pkt_format_id_list - (OUT) List of packet format entries added to udf id
    500  *      actual - (OUT) Actual number of Packet formats retrieved
    501  * Returns:
    502  *      BCM_E_NONE          Success.
    503  *      BCM_E_NOT_FOUND     Either the UDF or packet format entry does
    504  *                          not exist.
    505  *      BCM_E_UNIT          Invalid BCM Unit number.
    506  *      BCM_E_INIT          UDF module not initialized.
    507  *      BCM_E_UNAVAIL       Feature not supported.
    508  *      BCM_E_XXX           Standard error code.
    509  * Notes:
    510  */
    511 int
    512 bcm_esw_udf_pkt_format_get_all(
    513     int unit,
    514     bcm_udf_id_t udf_id,
    515     int max,
    516     bcm_udf_pkt_format_id_t *pkt_format_id_list,
    517     int *actual)
    518 {
    519 #if defined (BCM_TRIUMPH2_SUPPORT)
    520     if (soc_feature(unit, soc_feature_udf_support)) {
    521         return bcmi_xgs4_udf_pkt_format_get_all(unit, udf_id, max,
    522                                                pkt_format_id_list, actual);
    523     }
    524 #endif
    525 
    526     return BCM_E_UNAVAIL;
    527 }
    528 
    529 
    530 /*
    531  * Function:
    532  *      bcm_udf_pkt_format_delete_all
    533  * Purpose:
    534  *      Deletes all packet format specs associated with the UDF
    535  * Parameters:
    536  *      unit - (IN) Unit number.
    537  *      udf_id - (IN) UDF ID
    538  * Returns:
    539  *      BCM_E_NONE          Deletes all packet formats associated with
    540  *                          the UDF.
    541  *      BCM_E_NOT_FOUND     UDF Id does not exist.
    542  *      BCM_E_UNIT          Invalid BCM Unit number.
    543  *      BCM_E_INIT          UDF module not initialized.
    544  *      BCM_E_UNAVAIL       Feature not supported.
    545  *      BCM_E_XXX           Standard error code.
    546  * Notes:
    547  */
    548 int
    549 bcm_esw_udf_pkt_format_delete_all(
    550     int unit,
    551     bcm_udf_id_t udf_id)
    552 {
    553 #if defined (BCM_TRIUMPH2_SUPPORT)
    554     if (soc_feature(unit, soc_feature_udf_support)) {
    555         return bcmi_xgs4_udf_pkt_format_delete_all(unit, udf_id);
    556     }
    557 #endif
    558 
    559     return BCM_E_UNAVAIL;
    560 }
    561 
    562 
    563 /*
    564  * Function:
    565  *      bcm_esw_udf_hash_config_add
    566  * Purpose:
    567  *      Add UDF id into hashing list and configure it
    568  * Parameters:
    569  *      unit            (IN) BCM unit number
    570  *      options         (IN) See bcm_esw_udf_HASH_ADD_O_xxx
    571  *      config          (IN) UDF hashing configuration info
    572  * Returns:
    573  *      BCM_E_NONE      UDF hashing added successfully
    574  *      BCM_E_BADID     UDF id does not exist or is not for UDF hashing usage
    575  *      BCM_E_XXX       Standard error code
    576  * Notes:
    577  */
    578 int bcm_esw_udf_hash_config_add(
    579     int unit,
    580     uint32 options,
    581     bcm_udf_hash_config_t *config)
    582 {
    583 #if defined (BCM_TRIDENT2_SUPPORT)
    584     if (soc_feature(unit, soc_feature_udf_hashing)) {
    585         return bcmi_xgs4_udf_hash_config_add(unit, options, config);
    586     }
    587 #endif /* BCM_TRIDENT2_SUPPORT */
    588 
    589     return BCM_E_UNAVAIL;
    590 }
    591 
    592 /*
    593  * Function:
    594  *      bcm_esw_udf_hash_config_delete
    595  * Purpose:
    596  *      Delete UDF id from hashing list
    597  * Parameters:
    598  *      unit            (IN) BCM unit number
    599  *      config          (IN) UDF hashing configuration info
    600  * Returns:
    601  *      BCM_E_NONE      UDF hashing added successfully
    602  *      BCM_E_XXX       Standard error code
    603  * Notes:
    604  */
    605 int bcm_esw_udf_hash_config_delete(
    606     int unit,
    607     bcm_udf_hash_config_t *config)
    608 {
    609 #if defined (BCM_TRIDENT2_SUPPORT)
    610     if (soc_feature(unit, soc_feature_udf_hashing)) {
    611         return bcmi_xgs4_udf_hash_config_delete(unit, config);
    612     }
    613 #endif /* BCM_TRIDENT2_SUPPORT */
    614 
    615     return BCM_E_UNAVAIL;
    616 }
    617 
    618 
    619 /*
    620  * Function:
    621  *      bcm_esw_udf_hash_config_delete_all
    622  * Purpose:
    623  *      Delete all UDF id from hashing list
    624  * Parameters:
    625  *      unit            (IN) BCM unit number
    626  * Returns:
    627  *      BCM_E_NONE      UDF hashing added successfully
    628  *      BCM_E_XXX       Standard error code
    629  * Notes:
    630  */
    631 int bcm_esw_udf_hash_config_delete_all(
    632     int unit)
    633 {
    634 #if defined (BCM_TRIDENT2_SUPPORT)
    635     if (soc_feature(unit, soc_feature_udf_hashing)) {
    636         return bcmi_xgs4_udf_hash_config_delete_all(unit);
    637     }
    638 #endif /* BCM_TRIDENT2_SUPPORT */
    639 
    640     return BCM_E_UNAVAIL;
    641 }
    642 
    643 
    644 /*
    645  * Function:
    646  *      bcm_esw_udf_hash_config_get
    647  * Purpose:
    648  *      Get UDF hashing configuration of a certain id
    649  * Parameters:
    650  *      unit            (IN) BCM unit number
    651  *      config          (INOUT) UDF hashing configuration info
    652  * Returns:
    653  *      BCM_E_NONE      UDF hashing added successfully
    654  *      BCM_E_NOT_FOUND Requested UDF hashing info does not exist
    655  *      BCM_E_XXX       Standard error code
    656  * Notes:
    657  */
    658 int bcm_esw_udf_hash_config_get(
    659     int unit,
    660     bcm_udf_hash_config_t *config)
    661 {
    662 #if defined (BCM_TRIDENT2_SUPPORT)
    663     if (soc_feature(unit, soc_feature_udf_hashing)) {
    664         return bcmi_xgs4_udf_hash_config_get(unit, config);
    665     }
    666 #endif /* BCM_TRIDENT2_SUPPORT */
    667 
    668     return BCM_E_UNAVAIL;
    669 }
    670 
    671 
    672 /*
    673  * Function:
    674  *      bcm_esw_udf_hash_config_get_all
    675  * Purpose:
    676  *      Get all added UDF ids from list
    677  * Parameters:
    678  *      unit                  (IN) BCM unit number
    679  *      max                   (IN) Max count of UDF ids in the list. 
    680  *      udf_hash_config_list  (OUT) List of UDF hashing configuration
    681  *      actual                (OUT) Actual count of UDF ids
    682  * Returns:
    683  *      BCM_E_NONE      UDF hashing added successfully
    684  *      BCM_E_XXX       Standard error code
    685  * Notes:
    686  */
    687 int bcm_esw_udf_hash_config_get_all(
    688     int unit,
    689     int max,
    690     bcm_udf_hash_config_t *udf_hash_config_list,
    691     int *actual)
    692 {
    693 #if defined (BCM_TRIDENT2_SUPPORT)
    694     if (soc_feature(unit, soc_feature_udf_hashing)) {
    695         return bcmi_xgs4_udf_hash_config_get_all(unit, max, udf_hash_config_list, actual);
    696     }
    697 #endif /* BCM_TRIDENT2_SUPPORT */
    698 
    699     return BCM_E_UNAVAIL;
    700 }
    701 
    702 
    703 /* Configure udf operation mode. */
    704 int bcm_esw_udf_oper_mode_set(
    705     int unit, 
    706     bcm_udf_oper_mode_t oper_mode) 
    707 {
    708 #if defined (BCM_TOMAHAWK_SUPPORT)
    709     if ((soc_feature(unit, soc_feature_udf_support)) &&
    710        (soc_feature(unit, soc_feature_udf_multi_pipe_support))) {
    711         return bcmi_xgs4_udf_oper_mode_set(unit, oper_mode);
    712     }
    713 #endif
    714 
    715     return BCM_E_UNAVAIL;
    716 }
    717 
    718 /* Retrieves current udf operation mode. */
    719 int bcm_esw_udf_oper_mode_get(
    720     int unit, 
    721     bcm_udf_oper_mode_t *oper_mode)
    722 {
    723 #if defined (BCM_TOMAHAWK_SUPPORT)
    724     if ((soc_feature(unit, soc_feature_udf_support)) &&
    725        (soc_feature(unit, soc_feature_udf_multi_pipe_support))) {
    726         return bcmi_xgs4_udf_oper_mode_get(unit, oper_mode);
    727     }
    728 #endif
    729 
    730     return BCM_E_UNAVAIL;
    731 }
    732 
    733 /* Creates a UDF object */
    734 int 
    735 bcm_esw_udf_chunk_create(
    736     int unit, 
    737     bcm_udf_alloc_hints_t *hints, 
    738     bcm_udf_chunk_info_t *udf_chunk_info, 
    739     bcm_udf_id_t *udf_id)
    740 {
    741     int rv = BCM_E_UNAVAIL;
    742 
    743     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    744        _BCM_UDF_INIT_CHECK(unit);
    745 
    746        _BCM_UDF_LOCK(unit);
    747        if (UDF_CONTROL(unit)->functions.udf_chunk_create != NULL) {
    748           rv = UDF_CONTROL(unit)->functions.udf_chunk_create(
    749                                           unit,
    750                                           hints,
    751                                           udf_chunk_info,
    752                                           udf_id);
    753        }
    754        _BCM_UDF_UNLOCK(unit);
    755     }
    756     return rv;
    757 }
    758 
    759 /* Get a UDF object information. */
    760 int 
    761 bcm_esw_udf_chunk_info_get(
    762     int unit, 
    763     bcm_udf_id_t udf_id, 
    764     bcm_udf_chunk_info_t *udf_chunk_info)
    765 {
    766     int rv = BCM_E_UNAVAIL;
    767 
    768     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    769        _BCM_UDF_INIT_CHECK(unit);
    770 
    771        _BCM_UDF_LOCK(unit);
    772        if (UDF_CONTROL(unit)->functions.udf_chunk_info_get != NULL) {
    773           rv = UDF_CONTROL(unit)->functions.udf_chunk_info_get(
    774                                           unit,
    775                                           udf_id,
    776                                           udf_chunk_info);
    777        }
    778        _BCM_UDF_UNLOCK(unit);
    779     }
    780 
    781     return rv;
    782 }
    783 
    784 int bcm_esw_udf_flow_based_chunk_arrange_set(
    785         int unit, 
    786         bcm_udf_tunnel_term_flow_type_t flow_type, 
    787         uint32 chunk_bmap)
    788 {
    789     int rv = BCM_E_UNAVAIL;
    790 
    791     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    792        _BCM_UDF_INIT_CHECK(unit);
    793 
    794        _BCM_UDF_LOCK(unit);
    795        if (UDF_CONTROL(unit)->functions.udf_flow_based_chunk_arrange_set != NULL) {
    796           rv = UDF_CONTROL(unit)->functions.udf_flow_based_chunk_arrange_set(
    797                                           unit,
    798                                           flow_type,
    799                                           chunk_bmap);
    800        }
    801        _BCM_UDF_UNLOCK(unit);
    802     }
    803 
    804     return rv;
    805 }
    806 
    807 int bcm_esw_udf_flow_based_chunk_arrange_get(
    808         int unit, 
    809         bcm_udf_tunnel_term_flow_type_t flow_type, 
    810         uint32 *chunk_bmap)
    811 {
    812     int rv = BCM_E_UNAVAIL;
    813 
    814     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    815        _BCM_UDF_INIT_CHECK(unit);
    816 
    817        _BCM_UDF_LOCK(unit);
    818        if (UDF_CONTROL(unit)->functions.udf_flow_based_chunk_arrange_get != NULL) {
    819           rv = UDF_CONTROL(unit)->functions.udf_flow_based_chunk_arrange_get(
    820                                           unit,
    821                                           flow_type,
    822                                           chunk_bmap);
    823        }
    824        _BCM_UDF_UNLOCK(unit);
    825     }
    826 
    827     return rv;
    828 }
    829 /* 
    830  * Retrieve the list of UDF Objects associated with a given abstract
    831  * packet format
    832  */
    833 int
    834 bcm_esw_udf_abstract_pkt_format_object_list_get(
    835     int unit, 
    836     bcm_udf_abstract_pkt_format_t abstract_pkt_format, 
    837     int max, 
    838     bcm_udf_id_t *udf_id_list, 
    839     int *actual)
    840 {
    841     int rv = BCM_E_UNAVAIL;
    842     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    843         _BCM_UDF_INIT_CHECK(unit);
    844 
    845         _BCM_UDF_LOCK(unit);
    846         if (UDF_CONTROL(unit)->
    847                   functions.udf_abstr_pkt_format_obj_list_get != NULL) {
    848            rv = UDF_CONTROL(unit)->
    849                   functions.udf_abstr_pkt_format_obj_list_get(
    850                                              unit,
    851                                              abstract_pkt_format,
    852                                              max, udf_id_list,
    853                                              actual);
    854         }
    855         _BCM_UDF_UNLOCK(unit);
    856     }
    857     return rv;
    858 }
    859 
    860 /* 
    861  * API to retrieve Abstract packet format information. To create a UDF
    862  * object for a given abstract packet format, user needs to know the
    863  * information about the start base offset in the packet header and
    864  * number of chunks supported and consumed to extract the UDF fields.
    865  */
    866 int
    867 bcm_esw_udf_abstract_pkt_format_info_get(
    868     int unit, 
    869     bcm_udf_abstract_pkt_format_t abstract_pkt_format, 
    870     bcm_udf_abstract_pkt_format_info_t *pkt_format_info)
    871 {
    872     int rv = BCM_E_UNAVAIL;
    873     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    874         _BCM_UDF_INIT_CHECK(unit);
    875 
    876         _BCM_UDF_LOCK(unit);
    877         if (UDF_CONTROL(unit)->functions.udf_abstr_pkt_format_info_get != NULL) {
    878            rv = UDF_CONTROL(unit)->functions.udf_abstr_pkt_format_info_get(
    879                                              unit,
    880                                              abstract_pkt_format,
    881                                              pkt_format_info);
    882         }
    883         _BCM_UDF_UNLOCK(unit);
    884     }
    885     return rv;
    886 }
    887 
    888 
    889 /* 
    890  * API to retrieve Chunk information supported for Range checker module
    891  */
    892 int
    893 bcm_esw_udf_range_checker_chunk_info_get(
    894     int unit,
    895     uint8 *num_chunks,
    896     uint32 *chunk_bmap)
    897 {
    898     int rv = BCM_E_UNAVAIL;
    899     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    900        _BCM_UDF_INIT_CHECK(unit);
    901 
    902        _BCM_UDF_LOCK(unit);
    903        if (UDF_CONTROL(unit)->functions.udf_range_checker_chunk_info_get != NULL) {
    904           rv = UDF_CONTROL(unit)->functions.udf_range_checker_chunk_info_get(
    905                                             unit,
    906                                             num_chunks,
    907                                             chunk_bmap);
    908        }
    909        _BCM_UDF_UNLOCK(unit);
    910     }
    911     return rv;
    912 }
    913 
    914 
    915 /*
    916  * Function:
    917  *     _bcm_esw_udf_sw_dump
    918  * Purpose:
    919  *     Displays UDF information maintained by software.
    920  * Parameters:
    921  *     unit - Device unit number
    922  * Returns:
    923  *     None
    924  */
    925 void
    926 _bcm_esw_udf_sw_dump(int unit)
    927 {
    928     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    929        if (UDF_CONTROL(unit) == NULL) {
    930           return;
    931        }
    932 
    933        _BCM_UDF_LOCK(unit);
    934        if (UDF_CONTROL(unit)->functions.udf_sw_dump != NULL) {
    935           UDF_CONTROL(unit)->functions.udf_sw_dump(unit);
    936        }
    937        _BCM_UDF_UNLOCK(unit);
    938     }
    939 
    940     return;
    941 }
    942 
    943 /*
    944  * Function:
    945  *     _bcm_esw_udf_sw_mem_dump
    946  * Purpose:
    947  *     Displays UDF information for a given memory
    948  * Parameters:
    949  *     unit - Device unit number
    950  *     mem  - Table to be displayed for the given index.
    951  *     idx  - Table index.
    952  * Returns:
    953  *     None
    954  */
    955 void
    956 _bcm_esw_udf_sw_mem_dump(int unit, soc_mem_t mem, int idx)
    957 {
    958     if (soc_feature(unit, soc_feature_udf_td3x_support)) {
    959        if (UDF_CONTROL(unit) == NULL) {
    960           return;
    961        }
    962 
    963        _BCM_UDF_LOCK(unit);
    964        if (UDF_CONTROL(unit)->functions.udf_sw_mem_dump != NULL) {
    965           UDF_CONTROL(unit)->functions.udf_sw_mem_dump(unit, mem, idx);
    966        }
    967        _BCM_UDF_UNLOCK(unit);
    968     }
    969 
    970     return;
    971 }
    972