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

cosq.c (355437B)


      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  * COS Queue Management
      8  * Purpose: API to set different cosq, priorities, and scheduler registers.
      9  */
     10 #include <sal/core/libc.h>
     11 
     12 #include <soc/drv.h>
     13 #include <soc/mem.h>
     14 #include <soc/debug.h>
     15 #if defined(BCM_TOMAHAWK3_SUPPORT)
     16 #include <soc/format.h>
     17 #include <soc/mcm/formatacc.h>
     18 #endif
     19 
     20 #include <bcm/error.h>
     21 #include <bcm/cosq.h>
     22 
     23 #include <bcm_int/esw/mbcm.h>
     24 #include <bcm_int/esw/cosq.h>
     25 #include <bcm_int/esw/tas.h>
     26 #include <bcm_int/esw/firebolt.h>
     27 #include <bcm_int/esw/scorpion.h>
     28 #include <bcm_int/esw/triumph.h>
     29 #include <bcm_int/esw/triumph2.h>
     30 #include <bcm_int/esw/trident.h>
     31 #include <bcm_int/esw/hurricane.h>
     32 #include <bcm_int/esw/katana.h>
     33 #include <bcm_int/esw/katana2.h>
     34 #include <bcm_int/esw/apache.h>
     35 #include <bcm_int/esw/monterey.h>
     36 #include <bcm_int/esw/triumph3.h>
     37 #include <bcm_int/esw/trident2.h>
     38 #include <bcm_int/esw/trident2plus.h>
     39 #include <bcm_int/esw/greyhound.h>
     40 #include <bcm_int/esw/tomahawk.h>
     41 #include <bcm_int/esw/trident3.h>
     42 #include <bcm_int/esw/greyhound2.h>
     43 #include <bcm_int/esw/tomahawk2.h>
     44 #include <bcm_int/esw/helix5.h>
     45 #include <bcm_int/esw/tomahawk3.h>
     46 #include <soc/monterey.h>
     47 #include <bcm_int/esw_dispatch.h>
     48 #include <bcm_int/esw/stat.h>
     49 #include <bcm_int/esw/pfc_deadlock.h>
     50 #include <bcm_int/bst.h>
     51 #if defined(INCLUDE_TCB) && defined (BCM_TCB_SUPPORT)
     52 #include <bcm_int/esw/tcb.h>
     53 #endif
     54 #ifdef BCM_WARM_BOOT_SUPPORT
     55 #include <bcm_int/esw/switch.h>
     56 #endif /* BCM_WARM_BOOT_SUPPORT */
     57 
     58 #define BCM_COSQ_QUEUE_VALID(unit, numq) \
     59     ((numq) >= 0 && (numq) < NUM_COS(unit))
     60 
     61 sal_mutex_t cosq_sync_lock[SOC_MAX_NUM_DEVICES];
     62 
     63 /* Cosq Event Handler */
     64 typedef struct cosq_event_handler_s {
     65     struct cosq_event_handler_s *next;
     66     bcm_cosq_event_types_t event_types;
     67     SHR_BITDCL pbmp[_SHR_BITDCLSIZE(SOC_MAX_NUM_PORTS)];
     68     SHR_BITDCL qbmp[_SHR_BITDCLSIZE(BCM_COS_COUNT)];
     69     bcm_cosq_event_cb cb;
     70     void *user_data;
     71 } cosq_event_handler_t;
     72 
     73 STATIC cosq_event_handler_t *cosq_event_handler_list[SOC_MAX_NUM_DEVICES] = {NULL};
     74 STATIC int cosq_event_handler_count[SOC_MAX_NUM_DEVICES][bcmCosqEventCount] = {{0}};
     75 STATIC sal_mutex_t cosq_event_lock[SOC_MAX_NUM_DEVICES] = {NULL};
     76 STATIC int bcmi_esw_cosq_event_deinit(int unit);
     77 STATIC int bcmi_esw_cosq_event_init(int unit);
     78 static uint8 cosq_event_initialized = 0;
     79 
     80 #define COSQ_EVENT_LOCK(unit) \
     81     do { \
     82         if (cosq_event_lock[unit]) { \
     83             sal_mutex_take(cosq_event_lock[unit], \
     84                            sal_mutex_FOREVER); \
     85         } \
     86 } while (0)
     87 
     88 #define COSQ_EVENT_UNLOCK(unit) \
     89     do { \
     90         if (cosq_event_lock[unit]) { \
     91             sal_mutex_give(cosq_event_lock[unit]); \
     92         } \
     93 } while (0)
     94 
     95 #ifdef BCM_WARM_BOOT_SUPPORT
     96 /*
     97  * Function:
     98  *      _bcm_esw_cosq_sync
     99  * Purpose:
    100  *      Record COSq module persisitent info for Level 2 Warm Boot.
    101  * Parameters:
    102  *      unit - StrataSwitch unit number.
    103  * Returns:
    104  *      BCM_E_XXX
    105  */
    106 int
    107 _bcm_esw_cosq_sync(int unit)
    108 {
    109 #ifdef BCM_TAS_SUPPORT
    110     if (soc_feature(unit, soc_feature_tas)) {
    111         BCM_IF_ERROR_RETURN(bcmi_esw_tas_sync(unit));
    112     }
    113 #endif
    114     return mbcm_driver[unit]->mbcm_cosq_sync(unit);
    115 }
    116 #endif /* BCM_WARM_BOOT_SUPPORT */
    117 
    118 /*
    119  * Function:
    120  *      _bcm_esw_cosq_config_property_get
    121  * Purpose:
    122  *      Get number COSQ from SOC property.
    123  * Parameters:
    124  *      unit - Unit number.
    125  * Returns:
    126  *      Number COSQ from SOC property.
    127  */
    128 int
    129 _bcm_esw_cosq_config_property_get(int unit)
    130 {
    131     int  num_cos;
    132 
    133 #if defined (BCM_HAWKEYE_SUPPORT)
    134     if (SOC_IS_HAWKEYE(unit)) {
    135         /* Use 2 as the default number of COS queue for HAWKEYE, 
    136            if bcm_num_cos is not set in config.bcm */
    137         num_cos = soc_property_get(unit, spn_BCM_NUM_COS, 2);
    138     } else 
    139 #endif /* BCM_HAWKEYE_SUPPORT */
    140 
    141 #if defined (BCM_HURRICANE_SUPPORT) 
    142     if (SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
    143         SOC_IS_GREYHOUND2(unit)) {
    144         if (soc_feature(unit, soc_feature_wh2)) {
    145             /* Default 4 COSQ if config file not assigned */
    146             num_cos = soc_property_get(unit, spn_BCM_NUM_COS, BCM_COS_DEFAULT);
    147         } else {
    148             /* Use 8 as the default number of COS queue for HURRICANE,
    149                if bcm_num_cos is not set in config.bcm */
    150             num_cos = soc_property_get(unit, spn_BCM_NUM_COS, BCM_COS_COUNT);
    151         }
    152     } else
    153 #endif /* BCM_HURRICANE_SUPPORT */
    154     {
    155         num_cos = soc_property_get(unit, spn_BCM_NUM_COS, BCM_COS_DEFAULT);
    156     }
    157 
    158     if (num_cos < 1) {
    159         num_cos = 1;
    160     } else if (num_cos > NUM_COS(unit)) {
    161         num_cos = NUM_COS(unit);
    162     }
    163 
    164     return num_cos;
    165 }
    166 
    167 #ifdef BCM_TRIUMPH_SUPPORT
    168 #define _BCM_CPU_COS_MAPS_RSVD   9
    169 #define _BCM_INT_PRI_8_15_MASK   0x8
    170 #define _BCM_INT_PRI_0_7_MASK    0xf
    171 #endif /* BCM_TRIUMPH_SUPPORT */
    172 
    173 /*
    174  * Function:
    175  *      _bcm_esw_cpu_cosq_mapping_default_set 
    176  * Purpose:
    177  *      Map 16 internal priorities to CPU COS queues using CPU_COS_MAPm
    178  *      Default cpu_cos_maps should have lower priorities than user created maps
    179  * Parameters:
    180  *      unit - Unit number.
    181  *      numq - number of COS queues (1-8).
    182  * Returns:
    183  *      BCM_E_XXX
    184  */
    185 int
    186 _bcm_esw_cpu_cosq_mapping_default_set(int unit, int numq)
    187 {
    188 #ifdef BCM_TRIUMPH_SUPPORT
    189     int cos=0, prio, ratio, remain, index;
    190     cpu_cos_map_entry_t cpu_cos_map_entry;
    191 #if defined(BCM_TOMAHAWK3_SUPPORT)
    192     uint32 tcam_entry[SOC_MAX_MEM_WORDS];
    193     uint32 data_entry[SOC_MAX_MEM_WORDS];
    194     uint32 action_set[4];
    195 
    196     /* initialize the variables */
    197     sal_memset(action_set,0x0,(sizeof(uint32))*4);
    198     sal_memset(&tcam_entry, 0, sizeof(tcam_entry));
    199     sal_memset(&data_entry, 0, sizeof(data_entry));
    200 #endif
    201     ratio = 8 / numq;
    202     remain = 8 % numq;
    203 
    204     /* Nothing to do on devices with no CPU_COS_MAP memory */
    205     if (!SOC_MEM_IS_VALID(unit, CPU_COS_MAPm)) {
    206         return BCM_E_NONE;
    207     }
    208 
    209     /* Map internal priorities 0 ~ 7 to appropriate CPU CoS queue */
    210     sal_memset(&cpu_cos_map_entry, 0, sizeof(cpu_cos_map_entry_t));
    211 #if defined(BCM_TOMAHAWK3_SUPPORT)
    212     if (SOC_IS_TOMAHAWK3(unit)) {
    213         soc_format_field32_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, VALIDf, 1);
    214     } else
    215 #endif
    216 #if defined(BCM_TOMAHAWK2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    217     if (SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) {
    218         soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry, VALIDf, 3);
    219     } else
    220 #endif
    221     {
    222     soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry, VALIDf, 1);
    223     }
    224 
    225 #if defined(BCM_TOMAHAWK3_SUPPORT)
    226     if (SOC_IS_TOMAHAWK3(unit)) {
    227         action_set[0] = _BCM_INT_PRI_0_7_MASK; 
    228         soc_format_field_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, MASKf, action_set);
    229     } else
    230 #endif
    231     {
    232     soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry,
    233                         INT_PRI_MASKf, _BCM_INT_PRI_0_7_MASK);
    234     }
    235 
    236     index = (soc_mem_index_count(unit, CPU_COS_MAPm) - _BCM_CPU_COS_MAPS_RSVD);
    237     for (prio = BCM_PRIO_MIN; prio <= BCM_PRIO_MAX; prio++, index++) {
    238 #if defined(BCM_TOMAHAWK3_SUPPORT)
    239         if (SOC_IS_TOMAHAWK3(unit)) {
    240             action_set[0] = prio;
    241             soc_format_field_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, KEYf, action_set);
    242             soc_format_field32_set(unit, CPU_COS_MAP_DATA_FORMATfmt, data_entry, COSf, cos);
    243             SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
    244                                                tcam_entry));
    245             SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAP_DATA_ONLYm(unit, MEM_BLOCK_ALL, index,
    246                                                data_entry));
    247         } else
    248 #endif
    249         {
    250         soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry,
    251                             INT_PRI_KEYf, prio);
    252         soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry, COSf, cos);
    253         SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
    254                                                &cpu_cos_map_entry));
    255         }
    256 
    257 
    258         if ((prio + 1) == (((cos + 1) * ratio) + ((remain < (numq - cos)) ?
    259                            0 : (remain - (numq - cos) + 1)))) {
    260             cos++;
    261         }
    262     }
    263 
    264     /* Map internal priorities 8 ~ 15 to (numq - 1) CPU CoS queue */
    265 #if defined(BCM_TOMAHAWK3_SUPPORT)
    266     if (SOC_IS_TOMAHAWK3(unit)) {
    267         action_set[0] = _BCM_INT_PRI_8_15_MASK;
    268         soc_format_field_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, MASKf, action_set);
    269         action_set[0] = 0x8;
    270         soc_format_field_set(unit, CPU_COS_MAP_TCAM_FORMATfmt, tcam_entry, KEYf, action_set);
    271         soc_format_field32_set(unit, CPU_COS_MAP_DATA_FORMATfmt, data_entry, COSf, numq-1);
    272         SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
    273                                                tcam_entry));
    274         SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAP_DATA_ONLYm(unit, MEM_BLOCK_ALL, index,
    275                                                data_entry));
    276     } else
    277 #endif
    278     {
    279     soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry,
    280                         INT_PRI_KEYf, 0x8);
    281     soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry,
    282                         INT_PRI_MASKf, _BCM_INT_PRI_8_15_MASK);
    283     soc_mem_field32_set(unit, CPU_COS_MAPm, &cpu_cos_map_entry, COSf, numq - 1);
    284     SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
    285                                            &cpu_cos_map_entry));
    286     }
    287 #endif /* BCM_TRIUMPH_SUPPORT */
    288 
    289     return BCM_E_NONE;
    290 }
    291 
    292 
    293 /*
    294  * Function:
    295  *      bcm_esw_cosq_init
    296  * Purpose:
    297  *      Initialize (clear) all COS schedule/mapping state.
    298  * Parameters:
    299  *      unit - StrataSwitch unit number.
    300  * Returns:
    301  *      BCM_E_XXX
    302  */
    303 
    304 int
    305 bcm_esw_cosq_init(int unit)
    306 {
    307     if (SOC_IS_SHADOW(unit)) {
    308         return BCM_E_UNAVAIL;
    309     }
    310 #ifdef BCM_TAS_SUPPORT
    311     if (soc_feature(unit, soc_feature_tas)) {
    312         BCM_IF_ERROR_RETURN(bcmi_esw_tas_init(unit));
    313     }
    314 #endif
    315     BCM_IF_ERROR_RETURN(bcmi_esw_cosq_event_init(unit));
    316     return mbcm_driver[unit]->mbcm_cosq_init(unit);
    317 }
    318 
    319 /*
    320  * Function:
    321  *      bcm_esw_cosq_detach
    322  * Purpose:
    323  *      Discard all COS schedule/mapping state.
    324  * Parameters:
    325  *      unit - StrataSwitch unit number.
    326  * Returns:
    327  *      BCM_E_XXX
    328  */
    329 
    330 int
    331 bcm_esw_cosq_detach(int unit)
    332 {
    333 #ifdef BCM_TAS_SUPPORT
    334     if (soc_feature(unit, soc_feature_tas)) {
    335         BCM_IF_ERROR_RETURN(bcmi_esw_tas_deinit(unit));
    336     }
    337 #endif
    338     BCM_IF_ERROR_RETURN(bcmi_esw_cosq_event_deinit(unit));
    339     return (mbcm_driver[unit]->mbcm_cosq_detach(unit, 0));
    340 }
    341 
    342 int bcm_esw_cosq_deinit(int unit)
    343 {
    344 #ifdef BCM_TAS_SUPPORT
    345     if (soc_feature(unit, soc_feature_tas)) {
    346         BCM_IF_ERROR_RETURN(bcmi_esw_tas_deinit(unit));
    347     }
    348 #endif
    349     BCM_IF_ERROR_RETURN(bcmi_esw_cosq_event_deinit(unit));
    350     return (mbcm_driver[unit]->mbcm_cosq_detach(unit, 1));
    351 }
    352 
    353 /*
    354  * Function:
    355  *      bcm_esw_cosq_config_set
    356  * Purpose:
    357  *      Set the number of COS queues
    358  * Parameters:
    359  *      unit - StrataSwitch unit number.
    360  *      numq - number of COS queues (1, 2, or 4).
    361  * Returns:
    362  *      BCM_E_XXX
    363  */
    364 
    365 int
    366 bcm_esw_cosq_config_set(int unit, bcm_cos_queue_t numq)
    367 {
    368     if (!SOC_IS_TOMAHAWKX(unit) && (!SOC_IS_TRIDENT3X(unit)) &&(!SOC_IS_MONTEREY(unit))  
    369          && (numq > 8)) {
    370         return BCM_E_PARAM;
    371     }
    372     return mbcm_driver[unit]->mbcm_cosq_config_set(unit, numq);
    373 }
    374 
    375 /*
    376  * Function:
    377  *      bcm_esw_cosq_config_get
    378  * Purpose:
    379  *      Get the number of cos queues
    380  * Parameters:
    381  *      unit - StrataSwitch unit number.
    382  *      numq - (Output) number of cosq
    383  * Returns:
    384  *      BCM_E_XXX
    385  */
    386 
    387 int
    388 bcm_esw_cosq_config_get(int unit, bcm_cos_queue_t *numq)
    389 {
    390     return (mbcm_driver[unit]->mbcm_cosq_config_get(unit, numq));
    391 }
    392 
    393 /*
    394  * Function:
    395  *      bcm_esw_cosq_mapping_set
    396  * Purpose:
    397  *      Set which cosq a given priority should fall into
    398  * Parameters:
    399  *      unit - StrataSwitch unit number.
    400  *      priority - Priority value to map
    401  *      cosq - COS queue to map to
    402  * Returns:
    403  *      BCM_E_XXX
    404  */
    405 
    406 int
    407 bcm_esw_cosq_mapping_set(int unit, bcm_cos_t priority, bcm_cos_queue_t cosq)
    408 {
    409     if (!BCM_COSQ_QUEUE_VALID(unit, cosq)) {
    410     return (BCM_E_PARAM);
    411     }
    412 
    413     return (mbcm_driver[unit]->mbcm_cosq_mapping_set(unit, -1,
    414                              priority, cosq));
    415 }
    416 
    417 int
    418 bcm_esw_cosq_port_mapping_set(int unit, bcm_port_t port,
    419                   bcm_cos_t priority, bcm_cos_queue_t cosq)
    420 {
    421     if (!soc_feature(unit, soc_feature_ets)) {
    422         if (!BCM_COSQ_QUEUE_VALID(unit, cosq)) {
    423             return (BCM_E_PARAM);
    424         }
    425         if (BCM_GPORT_IS_SET(port) && !SOC_IS_KATANAX(unit)) {
    426             BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, &port));
    427         }
    428     }
    429 
    430     return (mbcm_driver[unit]->mbcm_cosq_mapping_set(unit, port,
    431                              priority, cosq));
    432 }
    433 
    434 /*
    435  * Function:
    436  *      bcm_esw_cosq_port_mapping_multi_set
    437  * Purpose:
    438  *      mapping multiple priorities to their respective cos in one call
    439  * Parameters:
    440  *      unit - StrataSwitch unit number.
    441  *      port - Ingress Port
    442  *      count - Number of entries to be configured
    443  *      priority_array - Priority array to map
    444  *      cosq_array - COS queue array to map to
    445  * Returns:
    446  *      BCM_E_XXX
    447  */
    448 int 
    449 bcm_esw_cosq_port_mapping_multi_set(int unit, bcm_port_t port, int count,
    450                   bcm_cos_t *priority_array,bcm_cos_queue_t *cosq_array)
    451 {
    452 #ifdef BCM_KATANA2_SUPPORT
    453     if (SOC_IS_KATANA2(unit)) {    
    454         if (!soc_feature(unit, soc_feature_ets)) {
    455             int index = 0;
    456             if ((count < 1) || (count > 16)) {
    457                 return (BCM_E_PARAM);
    458             }
    459             if ((NULL == cosq_array) || (NULL == priority_array)) {
    460                 return (BCM_E_PARAM);
    461             }
    462             for (index = 0; index < count; index++) {
    463                 if (!BCM_COSQ_QUEUE_VALID(unit, cosq_array[index])) {
    464                     return (BCM_E_PARAM);
    465                 }
    466             }
    467             if (BCM_GPORT_IS_SET(port)){ 
    468                 BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, &port));
    469             }
    470         }
    471         return (bcm_kt2_cosq_port_mapping_multi_set(unit, port,count, 
    472                     priority_array, cosq_array));
    473     }
    474 #endif
    475     return BCM_E_UNAVAIL;
    476 }
    477 
    478 /*
    479  * Function:
    480  *      bcm_esw_cosq_stat_config_set 
    481  * Purpose:
    482  *      configures the stat types provided in stat_array 
    483  * Parameters:
    484  *      unit - StrataSwitch unit number.
    485  *      stat_count -  number of stat type entries in the stat_array
    486  *      stat_array - array containing information regarding the stats to be configured 
    487  * Returns:
    488  *      BCM_E_XXX
    489  */
    490 int 
    491 bcm_esw_cosq_stat_config_set(
    492         int unit, int stat_count,
    493         bcm_cosq_stat_t *stat_array)
    494 {
    495 #if defined(BCM_KATANA2_SUPPORT)
    496     if (SOC_IS_KATANA2(unit)) {
    497         return (bcm_kt2_cosq_stat_config_set(unit, stat_count, stat_array));
    498     }
    499 #endif
    500     return BCM_E_UNAVAIL;
    501 }
    502 
    503 
    504  /*
    505  * Function:
    506  *      bcm_esw_cosq_stat_config_get 
    507  * Purpose:
    508  *      configures the stat types provided in stat_array 
    509  * Parameters:
    510  *      unit - StrataSwitch unit number.
    511  *      stat_count -  number of stat type entries in the stat_array
    512  *      stat_array - array containing information regarding the stats to be configured 
    513  * Returns:
    514  *      BCM_E_XXX
    515  */
    516 int 
    517 bcm_esw_cosq_stat_config_get(
    518         int unit, int stat_count,
    519         bcm_cosq_stat_t *stat_array)
    520 {
    521 #if defined(BCM_KATANA2_SUPPORT)
    522     if (SOC_IS_KATANA2(unit)) {
    523         return (bcm_kt2_cosq_stat_config_get(unit, stat_count, stat_array));
    524     }
    525 #endif
    526     return BCM_E_UNAVAIL;
    527 }       
    528 
    529 /*
    530  * Function:
    531  *      bcm_esw_cosq_gport_egress_mapping_set
    532  * Purpose:
    533  *      Set which cosq a given priority should fall into
    534  * Parameters:
    535  *      unit - StrataSwitch unit number.
    536  *      gport - GPORT ID.
    537  *      priority - Priority value to map
    538  *      cosq - COS queue to map to
    539  *      flags - specify to which type of mapping
    540  * Returns:
    541  *      BCM_E_XXX
    542  */
    543 
    544     int
    545 bcm_esw_cosq_gport_egress_mapping_set(
    546         int unit, bcm_port_t gport, bcm_cos_t priority,
    547         bcm_cos_t cosq, uint32 flags)
    548 {
    549     switch(flags) {
    550         case BCM_COSQ_GPORT_EGRESS_MAPPING_REDIRECTION_COS:
    551 #ifdef BCM_KATANA2_SUPPORT
    552             if (SOC_IS_KATANA2(unit)) {
    553                 return bcm_kt2_cosq_gport_egress_mapping_set(
    554                         unit, gport, priority,
    555                         cosq, flags);
    556             }
    557 #endif /* BCM_KATANA2_SUPPORT */
    558             break;
    559         default :
    560             break;
    561     }
    562 
    563     return BCM_E_UNAVAIL;
    564 }
    565 
    566 /*
    567  * Function:
    568  *      bcm_esw_cosq_gport_egress_mapping_get
    569  * Purpose:
    570  *      Get cosq for the corresponding priority 
    571  * Parameters:
    572  *      unit - StrataSwitch unit number.
    573  *      gport - GPORT ID.
    574  *      priority - Priority value to map
    575  *      cosq - COS queue to map to
    576  *      flags - specify to which type of mapping
    577  * Returns:
    578  *      BCM_E_XXX
    579  */
    580 
    581 
    582 int
    583 bcm_esw_cosq_gport_egress_mapping_get(
    584         int unit, bcm_port_t gport, bcm_cos_t *priority,
    585         bcm_cos_t *cosq, uint32 flags)
    586 {
    587     switch(flags) {
    588         case BCM_COSQ_GPORT_EGRESS_MAPPING_REDIRECTION_COS:
    589 #ifdef BCM_KATANA2_SUPPORT
    590             if (SOC_IS_KATANA2(unit)) {
    591                 return bcm_kt2_cosq_gport_egress_mapping_get(
    592                         unit, gport, priority,
    593                         cosq, flags);
    594             }
    595 #endif /* BCM_KATANA2_SUPPORT */
    596             break;
    597         default :
    598             break;
    599     }
    600 
    601     return BCM_E_UNAVAIL;
    602 }
    603 /*
    604  * Function:
    605  *      bcm_esw_cosq_congestion_mapping_set
    606  * Purpose:
    607  *      Set congestion state as per the desired flow control for fabric 
    608  * Parameters:
    609  *      unit - StrataSwitch unit number.
    610  *      fabric_modid - Specify the fabric_modid on which congestion state
    611  *                     need to be applied  
    612  *      config - specify the flow control bits, which the fabric is interested
    613  * Returns:
    614  *      BCM_E_XXX
    615  */
    616 
    617 int
    618 bcm_esw_cosq_congestion_mapping_set(int unit,int fabric_modid ,
    619         bcm_cosq_congestion_mapping_info_t *config)
    620 {
    621 #ifdef BCM_KATANA2_SUPPORT
    622     if (SOC_IS_KATANA2(unit)) {
    623         return bcm_kt2_cosq_congestion_mapping_set(unit, fabric_modid,
    624                config);
    625     }
    626 #endif /* BCM_KATANA2_SUPPORT */
    627 
    628   return BCM_E_UNAVAIL;
    629 }
    630 
    631 /*
    632  * Function:
    633  *      bcm_esw_cosq_congestion_mapping_get
    634  * Purpose:
    635  *      Get congestion state as per the configured flow control value for fabric 
    636  * Parameters:
    637  *      unit - StrataSwitch unit number.
    638  *      fabric_modid - Specify the fabric_modid on which congestion state
    639  *                     need to be applied  
    640  *      config - specify the flow control bits, which the fabric is interested
    641  * Returns:
    642  *      BCM_E_XXX
    643  */
    644 
    645 
    646 int
    647 bcm_esw_cosq_congestion_mapping_get(int unit,int fabric_modid ,
    648         bcm_cosq_congestion_mapping_info_t *config)
    649 {
    650 #ifdef BCM_KATANA2_SUPPORT
    651     if (SOC_IS_KATANA2(unit)) {
    652         return bcm_kt2_cosq_congestion_mapping_get(unit, fabric_modid,
    653                config);
    654     }
    655 #endif /* BCM_KATANA2_SUPPORT */
    656 
    657   return BCM_E_UNAVAIL;
    658 }
    659 
    660 /*
    661  * Function:
    662  *      bcm_esw_cosq_mapping_get
    663  * Purpose:
    664  *      Determine which COS queue a given priority currently maps to.
    665  * Parameters:
    666  *      unit - StrataSwitch unit number.
    667  *      priority - Priority value
    668  *      cosq - (Output) COS queue number
    669  * Returns:
    670  *      BCM_E_XXX
    671  */
    672 
    673 int
    674 bcm_esw_cosq_mapping_get(int unit, bcm_cos_t priority, bcm_cos_queue_t *cosq)
    675 {
    676     return (mbcm_driver[unit]->mbcm_cosq_mapping_get(unit, -1,
    677                              priority, cosq));
    678 }
    679 
    680 int
    681 bcm_esw_cosq_port_mapping_get(int unit, bcm_port_t port,
    682                   bcm_cos_t priority, bcm_cos_queue_t *cosq)
    683 {
    684     if (!soc_feature(unit, soc_feature_ets)) {
    685         if (BCM_GPORT_IS_SET(port) && !SOC_IS_KATANAX(unit)) {
    686             BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, &port));
    687         }
    688     }
    689 
    690     return (mbcm_driver[unit]->mbcm_cosq_mapping_get(unit, port,
    691                              priority, cosq));
    692 }
    693 
    694 /*
    695  * Function:
    696  *      bcm_esw_cosq_mapping_multi_get
    697  * Purpose:
    698  *      Determine which COS queue a given priority currently maps to.
    699  * Parameters:
    700  *      unit - StrataSwitch unit number.
    701  *      port - Ingress PORT     
    702  *      priority - Priority array for which we need cosq values
    703  *      count - number of entries to be retrieved
    704  *      cosq - (Output) COS queue array  
    705  * Returns:
    706  *      BCM_E_XXX
    707  */
    708 int
    709 bcm_esw_cosq_port_mapping_multi_get(int unit, bcm_port_t port, int count,
    710                   bcm_cos_t *priority_array, bcm_cos_queue_t *cosq_array)
    711 {
    712 #ifdef BCM_KATANA2_SUPPORT
    713     if (SOC_IS_KATANA2(unit)) {  
    714         if (!soc_feature(unit, soc_feature_ets)) {
    715             if (BCM_GPORT_IS_SET(port)) { 
    716                 BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, &port));
    717             }
    718         }
    719         return bcm_kt2_cosq_port_mapping_multi_get(unit, port, count, 
    720                 priority_array, cosq_array);
    721     }
    722 #endif
    723     return BCM_E_UNAVAIL;
    724 }
    725 
    726 /*
    727  * Function:
    728  *      bcm_esw_cosq_priority_mapping_get_all
    729  *
    730  * Purpose:
    731  *      Get all priorities associated to the specific priority_group or
    732  *      service_pool on one port.
    733  * Parameters:
    734  *      unit - Unit number.
    735  *      gport - Gport ID.
    736  *      index - Priority group ID or service pool id, depends on type value.
    737  *      type - Support priority group or ingress service pool.
    738  *      pri_max - Indicate the cosq number user required.
    739  *      pri_array - Priority list attached to the priority_group on the port,
    740  *                  -1 is invalid value.
    741  *      pri_count - Indicate cosq number returned. When pri_max is zero,
    742  *                  pri_array is null, pri_count will return the total cosq
    743  *                  number attached to the port pg/port sp.
    744  * Returns:
    745  *      BCM_E_XXX
    746  */
    747 int bcm_esw_cosq_priority_mapping_get_all(int unit, bcm_gport_t gport,
    748                           int index, bcm_cosq_priority_mapping_t type,
    749                           int pri_max, bcm_cos_queue_t *pri_array,
    750                           int *pri_count)
    751 {
    752 
    753 #ifdef BCM_APACHE_SUPPORT
    754     if (SOC_IS_APACHE(unit)) {
    755         return bcm_ap_cosq_priority_mapping_get_all(unit, gport, index, type,
    756                                              pri_max, pri_array, pri_count);
    757     }
    758 #endif /* BCM_APACHE_SUPPORT */
    759 #ifdef BCM_TOMAHAWK_SUPPORT
    760     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
    761         return bcm_th_cosq_priority_mapping_get_all(unit, gport, index, type,
    762                                              pri_max, pri_array, pri_count);
    763     }
    764 #endif
    765 #ifdef BCM_TRIDENT3_SUPPORT
    766     if (SOC_IS_TRIDENT3X(unit)) {
    767         return bcm_td3_cosq_priority_mapping_get_all(unit, gport, index, type,
    768                                              pri_max, pri_array, pri_count);
    769     }
    770 #endif
    771 #ifdef BCM_TRIDENT2_SUPPORT
    772     if (SOC_IS_TRIDENT2(unit) || SOC_IS_TRIDENT2PLUS(unit)) {
    773         return bcm_td2_cosq_priority_mapping_get_all(unit, gport, index, type,
    774                                              pri_max, pri_array, pri_count);
    775     }
    776 #endif
    777     return BCM_E_UNAVAIL;
    778 }
    779 
    780 /*
    781  * Function:
    782  *      bcm_esw_cosq_sched_set
    783  * Purpose:
    784  *      Set up class-of-service policy and corresponding weights and delay
    785  * Parameters:
    786  *      unit - StrataSwitch unit number.
    787  *      mode - Scheduling mode, one of BCM_COSQ_xxx
    788  *    weights - Weights for each COS queue
    789  *        Unused if mode is BCM_COSQ_STRICT.
    790  *        Indicates number of packets sent before going on to
    791  *        the next COS queue.
    792  *    delay - Maximum delay in microseconds before returning the
    793  *        round-robin to the highest priority COS queue
    794  *        (Unused if mode other than BCM_COSQ_BOUNDED_DELAY)
    795  * Returns:
    796  *      BCM_E_XXX
    797  */
    798 
    799 int
    800 bcm_esw_cosq_sched_set(int unit, int mode, const int weights[], int delay)
    801 {
    802     bcm_pbmp_t pbmp;
    803 
    804     if (soc_feature(unit, soc_feature_ets)) {
    805         BCM_PBMP_ASSIGN(pbmp, PBMP_CMIC(unit));
    806     } else {
    807         BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
    808     }
    809 
    810     return (mbcm_driver[unit]->mbcm_cosq_port_sched_set(unit, pbmp, mode,
    811                                                         weights, delay));
    812 }
    813 
    814 int
    815 bcm_esw_cosq_port_sched_set(int unit, bcm_pbmp_t pbm,
    816             int mode, const int weights[], int delay)
    817 {
    818     bcm_pbmp_t pbm_all = PBMP_ALL(unit);
    819     BCM_PBMP_AND(pbm_all, pbm);
    820     if (BCM_PBMP_NEQ(pbm_all, pbm)) {
    821         return BCM_E_PORT;
    822     }
    823     return (mbcm_driver[unit]->mbcm_cosq_port_sched_set(unit,
    824                             pbm,
    825                             mode, weights, delay));
    826 }
    827 
    828 /*
    829  * Function:
    830  *      bcm_esw_cosq_sched_get
    831  * Purpose:
    832  *      Retrieve class-of-service policy and corresponding weights and delay
    833  * Parameters:
    834  *      unit - StrataSwitch unit number.
    835  *      mode_ptr - (output) Scheduling mode, one of BCM_COSQ_xxx
    836  *    weights - (output) Weights for each COS queue
    837  *        Unused if mode is BCM_COSQ_STRICT.
    838  *    delay - (output) Maximum delay in microseconds before returning
    839  *        the round-robin to the highest priority COS queue
    840  *        Unused if mode other than BCM_COSQ_BOUNDED_DELAY.
    841  * Returns:
    842  *      BCM_E_XXX
    843  */
    844 
    845 int
    846 bcm_esw_cosq_sched_get(int unit, int *mode, int weights[], int *delay)
    847 {
    848     bcm_pbmp_t pbmp;
    849 
    850     if (soc_feature(unit, soc_feature_ets)) {
    851         BCM_PBMP_ASSIGN(pbmp, PBMP_CMIC(unit));
    852     } else {
    853         BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
    854     }
    855 
    856     return (mbcm_driver[unit]->mbcm_cosq_port_sched_get(unit, pbmp, mode,
    857                                                         weights, delay));
    858 }
    859 
    860 int
    861 bcm_esw_cosq_port_sched_get(int unit, bcm_pbmp_t pbm,
    862             int *mode, int weights[], int *delay)
    863 {
    864     bcm_pbmp_t pbm_all = PBMP_ALL(unit);
    865     BCM_PBMP_AND(pbm_all, pbm);
    866     if (BCM_PBMP_NEQ(pbm_all, pbm)) {
    867         return BCM_E_PARAM;
    868     }
    869     return (mbcm_driver[unit]->mbcm_cosq_port_sched_get(unit,
    870                             pbm,
    871                             mode, weights, delay));
    872 }
    873 
    874 /*
    875  * Function:
    876  *      bcm_esw_cosq_sched_weight_max_get
    877  * Purpose:
    878  *      Retrieve maximum weights for given COS policy.
    879  * Parameters:
    880  *      unit - StrataSwitch unit number.
    881  *      mode - Scheduling mode, one of BCM_COSQ_xxx
    882  *    weight_max - (output) Maximum weight for COS queue.
    883  *        0 if mode is BCM_COSQ_STRICT.
    884  *        1 if mode is BCM_COSQ_ROUND_ROBIN.
    885  *        -1 if not applicable to mode.
    886  * Returns:
    887  *      BCM_E_XXX
    888  */
    889 
    890 int
    891 bcm_esw_cosq_sched_weight_max_get(int unit, int mode, int *weight_max)
    892 {
    893     return (mbcm_driver[unit]->mbcm_cosq_sched_weight_max_get(unit,
    894                                   mode,
    895                                   weight_max));
    896 }
    897 
    898 /*
    899  * Function:
    900  *      bcm_esw_cosq_port_bandwidth_set
    901  * Purpose:
    902  *      Set bandwidth values for given COS policy.
    903  * Parameters:
    904  *      unit - StrataSwitch unit number.
    905  *    port - port to configure, -1 for all ports.
    906  *      cosq - COS queue to configure, -1 for all COS queues.
    907  *      kbits_sec_min - minimum bandwidth, kbits/sec.
    908  *      kbits_sec_max - maximum bandwidth, kbits/sec.
    909  *      flags - may include:
    910  *              BCM_COSQ_BW_EXCESS_PREF
    911  *              BCM_COSQ_BW_MINIMUM_PREF
    912  * Returns:
    913  *      BCM_E_XXX
    914  */
    915 
    916 int
    917 bcm_esw_cosq_port_bandwidth_set(int unit, bcm_port_t port,
    918                                 bcm_cos_queue_t cosq,
    919                                 uint32 kbits_sec_min,
    920                                 uint32 kbits_sec_max,
    921                                 uint32 flags)
    922 {
    923     int rv = BCM_E_NONE;
    924     bcm_pbmp_t pbmp;
    925     bcm_port_t loc_port;
    926     bcm_cos_queue_t start_cos, end_cos, loc_cos;
    927     int num_cosq;
    928 
    929     if (port < 0) {
    930         if (SOC_IS_TRIUMPH(unit) || SOC_IS_VALKYRIE(unit) ||
    931             SOC_IS_SC_CQ(unit) || SOC_IS_ENDURO(unit)  ||
    932             SOC_IS_KATANA(unit)) {
    933             BCM_PBMP_ASSIGN(pbmp, PBMP_PORT_ALL(unit));
    934             loc_port = SOC_PORT_MIN(unit,port);
    935         } else {
    936             BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
    937             loc_port = SOC_PORT_MIN(unit,all);
    938         }
    939         num_cosq = NUM_COS(unit);
    940     } else {
    941         if (BCM_GPORT_IS_SET(port)) {
    942             BCM_IF_ERROR_RETURN(
    943                 bcm_esw_port_local_get(unit, port, &loc_port)); 
    944         } else {
    945             loc_port = port;
    946         }
    947         if (SOC_PORT_VALID(unit, loc_port)) {
    948             BCM_PBMP_PORT_SET(pbmp, loc_port);
    949         } else {
    950             return BCM_E_PORT;
    951         }
    952         num_cosq = IS_CPU_PORT(unit, loc_port) ?
    953             NUM_CPU_COSQ(unit) : NUM_COS(unit);
    954     }
    955 
    956     if (soc_feature(unit, soc_feature_wh2)) {
    957         /* Get the configured cosq number */
    958         BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
    959     }
    960 
    961     if (cosq < 0) {
    962         start_cos = 0;
    963         end_cos = num_cosq - 1;
    964     } else if (cosq >= num_cosq) {
    965         return BCM_E_PARAM;
    966     } else {
    967         start_cos = end_cos = cosq;
    968     }
    969 
    970     BCM_PBMP_ITER(pbmp, loc_port) {
    971         if (SOC_IS_HELIX5(unit) && IS_FAE_PORT(unit, loc_port)) {
    972             continue;
    973         }
    974         for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
    975             if ((rv = mbcm_driver[unit]->mbcm_cosq_port_bandwidth_set(unit,
    976                            loc_port, loc_cos, kbits_sec_min, kbits_sec_max,
    977                             kbits_sec_max, flags)) < 0) {
    978                 return rv;
    979             }
    980         }
    981     }
    982 
    983     return rv;
    984 }
    985 
    986 /*
    987  * Function:
    988  *      bcm_esw_cosq_port_bandwidth_get
    989  * Purpose:
    990  *      Retrieve bandwidth values for given COS policy.
    991  * Parameters:
    992  *      unit - StrataSwitch unit number.
    993  *    port - port to configure, -1 for any port.
    994  *      cosq - COS queue to configure, -1 for any COS queue.
    995  *      kbits_sec_min - (OUT) minimum bandwidth, kbits/sec.
    996  *      kbits_sec_max - (OUT) maximum bandwidth, kbits/sec.
    997  *      flags - (OUT) may include:
    998  *              BCM_COSQ_BW_EXCESS_PREF
    999  *              BCM_COSQ_BW_MINIMUM_PREF
   1000  * Returns:
   1001  *      BCM_E_XXX
   1002  */
   1003 
   1004 int
   1005 bcm_esw_cosq_port_bandwidth_get(int unit, bcm_port_t port, 
   1006                                 bcm_cos_queue_t cosq,
   1007                                 uint32 *kbits_sec_min,
   1008                                 uint32 *kbits_sec_max,
   1009                                 uint32 *flags)
   1010 {
   1011     bcm_port_t loc_port;
   1012     bcm_cos_queue_t loc_cos;
   1013     int num_cosq;
   1014     uint32 kbits_sec_burst;    /* Dummy variable */
   1015 
   1016     if (flags == NULL) {
   1017         return BCM_E_PARAM;
   1018     }
   1019 
   1020     if (port < 0) {
   1021         loc_port = SOC_PORT_MIN(unit,all);
   1022         num_cosq = NUM_COS(unit);
   1023     } else {
   1024         if (BCM_GPORT_IS_SET(port)) {
   1025             BCM_IF_ERROR_RETURN(
   1026                 bcm_esw_port_local_get(unit, port, &loc_port)); 
   1027         } else {
   1028             loc_port = port;
   1029         }
   1030         if (!SOC_PORT_VALID(unit, loc_port)) {
   1031             return BCM_E_PORT;
   1032         }
   1033         num_cosq = IS_CPU_PORT(unit, loc_port) ?
   1034             NUM_CPU_COSQ(unit) : NUM_COS(unit);
   1035     }
   1036 
   1037     if (soc_feature(unit, soc_feature_wh2)) {
   1038         /* Get the configured max cosq number */
   1039         BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
   1040     }
   1041 
   1042     if (cosq < 0) {
   1043         loc_cos = 0;
   1044     } else if (cosq >= num_cosq) {
   1045         return BCM_E_PARAM;
   1046     } else {
   1047         loc_cos = cosq;
   1048     }
   1049 
   1050     return (mbcm_driver[unit]->mbcm_cosq_port_bandwidth_get(unit,
   1051                            loc_port, loc_cos, kbits_sec_min, kbits_sec_max,
   1052                                               &kbits_sec_burst, flags));
   1053 }
   1054 
   1055 /*
   1056  * Function:
   1057  *      bcm_esw_cosq_discard_set
   1058  * Purpose:
   1059  *      Set the COS queue WRED parameters
   1060  * Parameters:
   1061  *      unit  - StrataSwitch unit number.
   1062  *      flags - BCM_COSQ_DISCARD_*
   1063  * Returns:
   1064  *      BCM_E_XXX
   1065  */
   1066  
   1067 int     
   1068 bcm_esw_cosq_discard_set(int unit, uint32 flags)
   1069 {
   1070     return (mbcm_driver[unit]->mbcm_cosq_discard_set(unit, flags));
   1071 }
   1072  
   1073 /*
   1074  * Function:
   1075  *      bcm_esw_cosq_discard_get
   1076  * Purpose:
   1077  *      Get the COS queue WRED parameters
   1078  * Parameters:
   1079  *      unit  - StrataSwitch unit number.
   1080  *      flags - (OUT) BCM_COSQ_DISCARD_*
   1081  * Returns:
   1082  *      BCM_E_XXX
   1083  */
   1084 
   1085 int
   1086 bcm_esw_cosq_discard_get(int unit, uint32 *flags)
   1087 {
   1088     if (flags == NULL) {
   1089         return BCM_E_PARAM;
   1090     }
   1091 
   1092     return (mbcm_driver[unit]->mbcm_cosq_discard_get(unit, flags));
   1093 }
   1094     
   1095 /*
   1096  * Function:
   1097  *      bcm_esw_cosq_discard_port_set
   1098  * Purpose:
   1099  *      Set the COS queue WRED parameters
   1100  * Parameters:
   1101  *      unit  - StrataSwitch unit number.
   1102  *      port  - port to configure (-1 for all ports).
   1103  *      cosq  - COS queue to configure (-1 for all queues).
   1104  *      color - BCM_COSQ_DISCARD_COLOR_*
   1105  *      drop_start -  percentage of queue
   1106  *      drop_slope -  degress 0..90
   1107  *      average_time - in microseconds
   1108  *
   1109  * Returns:
   1110  *      BCM_E_XXX
   1111  */
   1112 
   1113 int
   1114 bcm_esw_cosq_discard_port_set(int unit, bcm_port_t port,
   1115                           bcm_cos_queue_t cosq,
   1116                           uint32 color,
   1117                           int drop_start,
   1118                           int drop_slope,
   1119                           int average_time)
   1120 {
   1121     return mbcm_driver[unit]->mbcm_cosq_discard_port_set
   1122         (unit, port, cosq, color, drop_start, drop_slope, average_time);
   1123 }
   1124 
   1125 /*
   1126  * Function:
   1127  *      bcm_esw_cosq_discard_port_get
   1128  * Purpose:
   1129  *      Set the COS queue WRED parameters
   1130  * Parameters:
   1131  *      unit  - StrataSwitch unit number.
   1132  *      port  - port to get (-1 for any).
   1133  *      cosq  - COS queue to get (-1 for any).
   1134  *      color - BCM_COSQ_DISCARD_COLOR_*
   1135  *      drop_start - (OUT) percentage of queue
   1136  *      drop_slope - (OUT) degress 0..90
   1137  *      average_time - (OUT) in microseconds
   1138  *
   1139  * Returns:
   1140  *      BCM_E_XXX
   1141  */
   1142 
   1143 int
   1144 bcm_esw_cosq_discard_port_get(int unit, bcm_port_t port,
   1145                           bcm_cos_queue_t cosq,
   1146                           uint32 color,
   1147                           int *drop_start,
   1148                           int *drop_slope,
   1149                           int *average_time)
   1150 {
   1151     return mbcm_driver[unit]->mbcm_cosq_discard_port_get
   1152         (unit, port, cosq, color, drop_start, drop_slope, average_time);
   1153 }
   1154 
   1155 /*
   1156  * Function:
   1157  *      bcm_cosq_gport_discard_set
   1158  * Purpose:
   1159  *
   1160  * Parameters:
   1161  *      unit    - (IN) Unit number.
   1162  *      port    - (IN) GPORT ID.
   1163  *      cosq    - (IN) COS queue to configure
   1164  *      discard - (IN) Discard settings
   1165  * Returns:
   1166  *      BCM_E_XXX
   1167  */
   1168 int 
   1169 bcm_esw_cosq_gport_discard_set(int unit, bcm_gport_t port, bcm_cos_queue_t cosq,
   1170                                bcm_cosq_gport_discard_t *discard)
   1171 {
   1172 #ifdef BCM_MONTEREY_SUPPORT
   1173     if (SOC_IS_MONTEREY(unit)) {
   1174         return bcm_mn_cosq_gport_discard_set(unit, port, cosq, discard);
   1175     }
   1176 #endif /* BCM_MONTEREY_SUPPORT */
   1177 #ifdef BCM_APACHE_SUPPORT
   1178     if (SOC_IS_APACHE(unit)) {
   1179         return bcm_ap_cosq_gport_discard_set(unit, port, cosq, discard);
   1180     }
   1181 #endif /* BCM_APACHE_SUPPORT */
   1182 #ifdef BCM_TOMAHAWK3_SUPPORT
   1183     if (SOC_IS_TOMAHAWK3(unit)) {
   1184         return bcm_th3_cosq_gport_discard_set(unit, port, cosq, 
   1185             BCM_COSQ_BUFFER_ID_INVALID, discard);
   1186     }
   1187 #endif /* BCM_TOMAHAWK_SUPPORT */
   1188 #ifdef BCM_TOMAHAWK_SUPPORT
   1189     if (SOC_IS_TOMAHAWKX(unit)) {
   1190         return bcm_th_cosq_gport_discard_set(unit, port, cosq,
   1191             BCM_COSQ_BUFFER_ID_INVALID, discard);
   1192     }
   1193 #endif /* BCM_TOMAHAWK_SUPPORT */
   1194 #ifdef BCM_HELIX5_SUPPORT
   1195     if (SOC_IS_HELIX5(unit)) {
   1196         return bcm_hx5_cosq_gport_discard_set(unit, port, cosq, discard);
   1197     }
   1198 #endif /* BCM_HELIX5_SUPPORT */
   1199 #ifdef BCM_TRIDENT3_SUPPORT
   1200     if (SOC_IS_TRIDENT3X(unit)) {
   1201         return bcm_td3_cosq_gport_discard_set(unit, port, cosq, discard);
   1202     }
   1203 #endif /* BCM_TRIDENT3_SUPPORT */
   1204 #ifdef BCM_TRIDENT2_SUPPORT
   1205     if (SOC_IS_TD2_TT2(unit)) {
   1206         return bcm_td2_cosq_gport_discard_set(unit, port, cosq, discard);
   1207     }
   1208 #endif /* BCM_TRIDENT2_SUPPORT */
   1209 #ifdef BCM_TRIDENT_SUPPORT
   1210     if (SOC_IS_TD_TT(unit)) {
   1211         return bcm_td_cosq_gport_discard_set(unit, port, cosq, discard);
   1212     }
   1213 #endif /* BCM_TRIDENT_SUPPORT */
   1214 #ifdef BCM_KATANA_SUPPORT
   1215         if (SOC_IS_KATANA(unit)) {
   1216                     return bcm_kt_cosq_gport_discard_set(unit, port, cosq, discard);
   1217                         }
   1218 #endif /* BCM_KATANA_SUPPORT */
   1219 #ifdef BCM_KATANA2_SUPPORT
   1220             if (SOC_IS_KATANA2(unit)) {
   1221                         return bcm_kt2_cosq_gport_discard_set(unit, port, cosq, discard);
   1222                             }
   1223 #endif /* BCM_KATANA2_SUPPORT */
   1224 #ifdef BCM_TRIUMPH3_SUPPORT
   1225                 if (SOC_IS_TRIUMPH3(unit)) {
   1226                             return bcm_tr3_cosq_gport_discard_set(unit, port, cosq, discard);
   1227                                 }
   1228 #endif /* BCM_TRIUMPH3_SUPPORT */
   1229 
   1230 /*Removed GPORT_INVALID check for KT/KT2/TR3/TD/TD2 to enable 
   1231   global wred discard profile for all ports when -1 is passed */
   1232 
   1233     if (port == BCM_GPORT_INVALID) {
   1234         return (BCM_E_PORT);
   1235     }
   1236 #ifdef BCM_TRIUMPH2_SUPPORT
   1237     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   1238         SOC_IS_VALKYRIE2(unit)) {
   1239         return bcm_tr2_cosq_gport_discard_set(unit, port, cosq, discard);
   1240     }
   1241 #endif
   1242 #ifdef BCM_TRX_SUPPORT
   1243     if (SOC_IS_TRX(unit)) {
   1244 #if defined(BCM_HURRICANE_SUPPORT)
   1245         if(SOC_IS_HURRICANE(unit) || SOC_IS_HURRICANE2(unit)) {
   1246             return bcm_hu_cosq_gport_discard_set(unit, port, cosq, discard);
   1247         } else         
   1248 #endif /*BCM_HURRICANE_SUPPORT*/
   1249 #if defined(BCM_GREYHOUND_SUPPORT)
   1250         if(SOC_IS_GREYHOUND(unit) || SOC_IS_HURRICANE3(unit)) {
   1251             return bcm_gh_cosq_gport_discard_set(unit, port, cosq, discard);
   1252         } else      
   1253 #endif /*BCM_GREYHOUND_SUPPORT*/
   1254 #if defined(BCM_GREYHOUND2_SUPPORT)
   1255         if (SOC_IS_GREYHOUND2(unit)) {
   1256             return bcmi_gh2_cosq_gport_discard_set(unit, port, cosq, discard);
   1257         } else
   1258 #endif /* BCM_GREYHOUND2_SUPPORT */
   1259         {
   1260             return bcm_tr_cosq_gport_discard_set(unit, port, cosq, discard);
   1261         }
   1262     }
   1263 #endif /* BCM_TRX_SUPPORT */
   1264     return BCM_E_UNAVAIL; 
   1265 }
   1266 
   1267 /*
   1268  * Function:
   1269  *      bcm_cosq_gport_discard_get
   1270  * Purpose:
   1271  *
   1272  * Parameters:
   1273  *      unit    - (IN) Unit number.
   1274  *      port    - (IN) GPORT ID.
   1275  *      cosq    - (IN) COS queue to get
   1276  *      discard - (IN/OUT) Discard settings
   1277  * Returns:
   1278  *      BCM_E_XXX
   1279  */
   1280 int 
   1281 bcm_esw_cosq_gport_discard_get(int unit, bcm_gport_t port, bcm_cos_queue_t cosq,
   1282                                bcm_cosq_gport_discard_t *discard)
   1283 {
   1284 #ifdef BCM_MONTEREY_SUPPORT
   1285     if (SOC_IS_MONTEREY(unit)) {
   1286         return bcm_mn_cosq_gport_discard_get(unit, port, cosq, discard);
   1287     }
   1288 #endif /* BCM_MONTEREY_SUPPORT */
   1289 
   1290 #ifdef BCM_APACHE_SUPPORT
   1291     if (SOC_IS_APACHE(unit)) {
   1292         return bcm_ap_cosq_gport_discard_get(unit, port, cosq, discard);
   1293     }
   1294 #endif /* BCM_APACHE_SUPPORT */
   1295 #ifdef BCM_TOMAHAWK3_SUPPORT
   1296     if (SOC_IS_TOMAHAWK3(unit)) {
   1297         return bcm_th3_cosq_gport_discard_get(unit, port, cosq,
   1298             BCM_COSQ_BUFFER_ID_INVALID, discard);
   1299     }
   1300 #endif /* BCM_TOMAHAWK_SUPPORT */
   1301 #ifdef BCM_TOMAHAWK_SUPPORT
   1302     if (SOC_IS_TOMAHAWKX(unit)) {
   1303         return bcm_th_cosq_gport_discard_get(unit, port, cosq,
   1304             BCM_COSQ_BUFFER_ID_INVALID, discard);
   1305     }
   1306 #endif /* BCM_TOMAHAWK_SUPPORT */
   1307 #ifdef BCM_HELIX5_SUPPORT
   1308     if (SOC_IS_HELIX5(unit)) {
   1309         return bcm_hx5_cosq_gport_discard_get(unit, port, cosq, discard);
   1310     }
   1311 #endif /* BCM_HELIX5_SUPPORT */
   1312 #ifdef BCM_TRIDENT3_SUPPORT
   1313     if (SOC_IS_TRIDENT3X(unit)) {
   1314         return bcm_td3_cosq_gport_discard_get(unit, port, cosq, discard);
   1315     }
   1316 #endif /* BCM_TRIDENT3_SUPPORT */
   1317 #ifdef BCM_TRIDENT2_SUPPORT
   1318     if (SOC_IS_TD2_TT2(unit)) {
   1319         return bcm_td2_cosq_gport_discard_get(unit, port, cosq, discard);
   1320     }
   1321 #endif /* BCM_TRIDENT_SUPPORT */
   1322 #ifdef BCM_TRIDENT_SUPPORT
   1323     if (SOC_IS_TD_TT(unit)) {
   1324         return bcm_td_cosq_gport_discard_get(unit, port, cosq, discard);
   1325     }
   1326 #endif /* BCM_TRIDENT_SUPPORT */
   1327 #ifdef BCM_KATANA_SUPPORT
   1328         if (SOC_IS_KATANA(unit)) {
   1329                     return bcm_kt_cosq_gport_discard_get(unit, port, cosq, discard);
   1330                         }
   1331 #endif /* BCM_KATANA_SUPPORT */
   1332 #ifdef BCM_KATANA2_SUPPORT
   1333             if (SOC_IS_KATANA2(unit)) {
   1334                         return bcm_kt2_cosq_gport_discard_get(unit, port, cosq, discard);
   1335                             }
   1336 #endif /* BCM_KATANA2_SUPPORT */
   1337 #ifdef BCM_TRIUMPH3_SUPPORT
   1338                 if (SOC_IS_TRIUMPH3(unit)) {
   1339                             return bcm_tr3_cosq_gport_discard_get(unit, port, cosq, discard);
   1340                                 }
   1341 #endif /* BCM_TRIUMPH3_SUPPORT */
   1342 
   1343 /*Removed GPORT_INVALID check for KT/KT2/TR3/TD/TD2 to enable 
   1344     global wred discard profile for all ports when -1 is passed */
   1345 
   1346     if (port == BCM_GPORT_INVALID) {
   1347         return (BCM_E_PORT);
   1348     }
   1349 #ifdef BCM_TRIUMPH2_SUPPORT
   1350     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   1351         SOC_IS_VALKYRIE2(unit)) {
   1352         return bcm_tr2_cosq_gport_discard_get(unit, port, cosq, discard);
   1353     }
   1354 #endif
   1355 #ifdef BCM_TRX_SUPPORT
   1356     if (SOC_IS_TRX(unit)) {
   1357 #if defined(BCM_HURRICANE_SUPPORT)
   1358         if(SOC_IS_HURRICANE(unit) || SOC_IS_HURRICANE2(unit)) {
   1359             return bcm_hu_cosq_gport_discard_get(unit, port, cosq, discard);
   1360         } else             
   1361 #endif
   1362 #if defined(BCM_GREYHOUND_SUPPORT)
   1363         if(SOC_IS_GREYHOUND(unit) || SOC_IS_HURRICANE3(unit)) {
   1364             return bcm_gh_cosq_gport_discard_get(unit, port, cosq, discard);
   1365         } else      
   1366 #endif /*BCM_GREYHOUND_SUPPORT*/
   1367 #if defined(BCM_GREYHOUND2_SUPPORT)
   1368         if (SOC_IS_GREYHOUND2(unit)) {
   1369             return bcmi_gh2_cosq_gport_discard_get(unit, port, cosq, discard);
   1370         } else
   1371 #endif /* BCM_GREYHOUND2_SUPPORT */
   1372 
   1373         {
   1374             return bcm_tr_cosq_gport_discard_get(unit, port, cosq, discard);
   1375         }
   1376     }
   1377 #endif /* BCM_TRX_SUPPORT */
   1378     return BCM_E_UNAVAIL; 
   1379 }
   1380 
   1381 /*
   1382  * Function:
   1383  *      bcm_esw_cosq_gport_discard_extended_set
   1384  * Purpose:
   1385  *
   1386  * Parameters:
   1387  *      unit    - (IN) Unit number.
   1388  *      id      - (IN) Integrated cosq index
   1389  *      discard - (IN) Discard settings
   1390  * Returns:
   1391  *      BCM_E_XXX
   1392  */
   1393 int 
   1394 bcm_esw_cosq_gport_discard_extended_set(
   1395     int unit, 
   1396     bcm_cosq_object_id_t *id,
   1397     bcm_cosq_gport_discard_t *discard)
   1398 {
   1399 #ifdef BCM_TOMAHAWK3_SUPPORT
   1400     if (SOC_IS_TOMAHAWK3(unit)) {
   1401         return BCM_E_UNAVAIL;
   1402     }
   1403 #endif /* BCM_TOMAHAWK3_SUPPORT */
   1404 #ifdef BCM_TOMAHAWK_SUPPORT
   1405     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   1406         return bcm_th_cosq_gport_discard_set(unit, 
   1407             id->port, id->cosq, id->buffer, discard);
   1408     }
   1409 #endif /* BCM_TOMAHAWK_SUPPORT */
   1410 
   1411     return BCM_E_UNAVAIL;
   1412 }
   1413 
   1414 /*
   1415  * Function:
   1416  *      bcm_esw_cosq_gport_discard_extended_get
   1417  * Purpose:
   1418  *
   1419  * Parameters:
   1420  *      unit    - (IN) Unit number.
   1421  *      id      - (IN) Integrated cosq index
   1422  *      discard - (OUT) Discard settings
   1423  * Returns:
   1424  *      BCM_E_XXX
   1425  */
   1426 int 
   1427 bcm_esw_cosq_gport_discard_extended_get(
   1428     int unit, 
   1429     bcm_cosq_object_id_t *id,
   1430     bcm_cosq_gport_discard_t *discard)
   1431 {
   1432 #ifdef BCM_TOMAHAWK3_SUPPORT
   1433     if (SOC_IS_TOMAHAWK3(unit)) {
   1434         return BCM_E_UNAVAIL;
   1435     }
   1436 #endif /* BCM_TOMAHAWK3_SUPPORT */
   1437 #ifdef BCM_TOMAHAWK_SUPPORT
   1438     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   1439         return bcm_th_cosq_gport_discard_get(unit, 
   1440             id->port, id->cosq, id->buffer, discard);
   1441     }
   1442 #endif /* BCM_TOMAHAWK_SUPPORT */
   1443 
   1444     return BCM_E_UNAVAIL;
   1445 }
   1446 
   1447 /*
   1448  * Function:
   1449  *     bcm_esw_cosq_discard_profile_create
   1450  * Purpose:
   1451  *     Create an empty rule profile
   1452  * Parameters:
   1453  *     unit                - (IN) unit number
   1454  *     profile_id          - (OUT) profile index
   1455  * Returns:
   1456  *     BCM_E_XXX
   1457  */
   1458 int bcm_esw_cosq_discard_profile_create(
   1459     int unit,
   1460     int *profile_id)
   1461 {
   1462 #ifdef BCM_TOMAHAWK3_SUPPORT
   1463     if (SOC_IS_TOMAHAWK3(unit)) {
   1464         return bcm_th3_cosq_wred_resolution_entry_create(unit, profile_id);
   1465     }
   1466 #endif /* BCM_TOMAHAWK_SUPPORT */
   1467 #ifdef BCM_TOMAHAWK_SUPPORT
   1468     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   1469         return bcm_th_cosq_wred_resolution_entry_create(unit, profile_id);
   1470     }
   1471 #endif /* BCM_TOMAHAWK_SUPPORT */
   1472 #ifdef BCM_HELIX5_SUPPORT
   1473     if (SOC_IS_HELIX5(unit)) {
   1474         return bcm_hx5_cosq_wred_resolution_entry_create(unit, profile_id);
   1475     }
   1476 #endif /* BCM_HELIX5_SUPPORT */
   1477 #ifdef BCM_TRIDENT3_SUPPORT
   1478     if (SOC_IS_TRIDENT3X(unit)) {
   1479         return bcm_td3_cosq_wred_resolution_entry_create(unit, profile_id);
   1480     }
   1481 #endif /* BCM_TRIDENT3_SUPPORT */
   1482 
   1483     return BCM_E_UNAVAIL;
   1484 }
   1485 
   1486 /*
   1487  * Function:
   1488  *     bcm_esw_cosq_discard_profile_destroy
   1489  * Purpose:
   1490  *     Destroy a rule profile
   1491  * Parameters:
   1492  *     unit                - (IN) unit number
   1493  *     profile_id          - (IN) profile index
   1494  * Returns:
   1495  *     BCM_E_XXX
   1496  */
   1497 int bcm_esw_cosq_discard_profile_destroy(
   1498     int unit,
   1499     int profile_id)
   1500 {
   1501 #ifdef BCM_TOMAHAWK3_SUPPORT
   1502     if (SOC_IS_TOMAHAWK3(unit)) {
   1503         return bcm_th3_cosq_wred_resolution_entry_destroy(unit, profile_id);
   1504     }
   1505 #endif /* BCM_TOMAHAWK_SUPPORT */
   1506 #ifdef BCM_TOMAHAWK_SUPPORT
   1507     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   1508         return bcm_th_cosq_wred_resolution_entry_destroy(unit, profile_id);
   1509     }
   1510 #endif /* BCM_TOMAHAWK_SUPPORT */
   1511 #ifdef BCM_HELIX5_SUPPORT
   1512     if (SOC_IS_HELIX5(unit)) {
   1513         return bcm_hx5_cosq_wred_resolution_entry_destroy(unit, profile_id);
   1514     }
   1515 #endif /* BCM_HELIX5_SUPPORT */
   1516 #ifdef BCM_TRIDENT3_SUPPORT
   1517     if (SOC_IS_TRIDENT3X(unit)) {
   1518         return bcm_td3_cosq_wred_resolution_entry_destroy(unit, profile_id);
   1519     }
   1520 #endif /* BCM_TRIDENT3_SUPPORT */
   1521 
   1522     return BCM_E_UNAVAIL;
   1523 }
   1524 
   1525 /*
   1526  * Function:
   1527  *     bcm_esw_cosq_discard_profile_update
   1528  * Purpose:
   1529  *     Update one rule in a profile
   1530  * Parameters:
   1531  *     unit                - (IN) unit number
   1532  *     profile_id          - (IN) profile index
   1533  *     rule                - (IN) discard rule
   1534  * Returns:
   1535  *     BCM_E_XXX
   1536  */
   1537 int bcm_esw_cosq_discard_profile_update(
   1538     int unit,
   1539     int profile_id,
   1540     bcm_cosq_discard_rule_t *rule)
   1541 {
   1542 #ifdef BCM_TOMAHAWK3_SUPPORT
   1543     if (SOC_IS_TOMAHAWK3(unit)) {
   1544         return bcm_th3_cosq_wred_resolution_set(unit, profile_id, rule);
   1545     }
   1546 #endif /* BCM_TOMAHAWK_SUPPORT */
   1547 #ifdef BCM_TOMAHAWK_SUPPORT
   1548     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   1549         return bcm_th_cosq_wred_resolution_set(unit, profile_id, rule);
   1550     }
   1551 #endif /* BCM_TOMAHAWK_SUPPORT */
   1552 #ifdef BCM_HELIX5_SUPPORT
   1553     if (SOC_IS_HELIX5(unit)) {
   1554         return bcm_hx5_cosq_wred_resolution_set(unit, profile_id, rule);
   1555     }
   1556 #endif /* BCM_HELIX5_SUPPORT */
   1557 #ifdef BCM_TRIDENT3_SUPPORT
   1558     if (SOC_IS_TRIDENT3X(unit)) {
   1559         return bcm_td3_cosq_wred_resolution_set(unit, profile_id, rule);
   1560     }
   1561 #endif /* BCM_TRIDENT3_SUPPORT */
   1562 
   1563     return BCM_E_UNAVAIL;
   1564 }
   1565 
   1566 /*
   1567  * Function:
   1568  *     bcm_esw_cosq_discard_profile_get
   1569  * Purpose:
   1570  *     Get all rules of a profile
   1571  * Parameters:
   1572  *     unit                - (IN) unit number
   1573  *     profile_id          - (IN) profile index
   1574  *     max                 - (IN) rule array size
   1575  *     rule_array          - (OUT) rule array
   1576  *     rule_count          - (OUT) actual rules count
   1577  * Returns:
   1578  *     BCM_E_XXX
   1579  */
   1580 int bcm_esw_cosq_discard_profile_get(
   1581     int unit,
   1582     int profile_id,
   1583     int max,
   1584     bcm_cosq_discard_rule_t *rule_array,
   1585     int *rule_count)
   1586 {
   1587 #ifdef BCM_TOMAHAWK3_SUPPORT
   1588     if (SOC_IS_TOMAHAWK3(unit)) {
   1589         return bcm_th3_cosq_wred_resolution_get(unit, profile_id, max,
   1590                 rule_array, rule_count);
   1591     }
   1592 #endif /* BCM_TOMAHAWK_SUPPORT */
   1593 #ifdef BCM_TOMAHAWK_SUPPORT
   1594     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   1595         return bcm_th_cosq_wred_resolution_get(unit, profile_id, max,
   1596                 rule_array, rule_count);
   1597     }
   1598 #endif /* BCM_TOMAHAWK_SUPPORT */
   1599 #ifdef BCM_HELIX5_SUPPORT
   1600     if (SOC_IS_HELIX5(unit)) {
   1601         return bcm_hx5_cosq_wred_resolution_get(unit, profile_id, max,
   1602                 rule_array, rule_count);
   1603     }
   1604 #endif /* BCM_HELIX5_SUPPORT */
   1605 #ifdef BCM_TRIDENT3_SUPPORT
   1606     if (SOC_IS_TRIDENT3X(unit)) {
   1607         return bcm_td3_cosq_wred_resolution_get(unit, profile_id, max,
   1608                 rule_array, rule_count);
   1609     }
   1610 #endif /* BCM_TRIDENT3_SUPPORT */
   1611 
   1612     return BCM_E_UNAVAIL;
   1613 }
   1614 
   1615 
   1616 /*
   1617  * Function:
   1618  *      bcm_cosq_gport_add
   1619  * Purpose:
   1620  *       
   1621  * Parameters:
   1622  *      unit - (IN) Unit number.
   1623  *      port - (IN) Physical port.
   1624  *      numq - (IN) Number of COS queues.
   1625  *      flags - (IN) Flags.
   1626  *      gport - (IN/OUT) GPORT ID.
   1627  * Returns:
   1628  *      BCM_E_XXX
   1629  */
   1630 int 
   1631 bcm_esw_cosq_gport_add(int unit, bcm_gport_t port, int numq, 
   1632                        uint32 flags, bcm_gport_t *gport)
   1633 {
   1634     if (port == BCM_GPORT_INVALID) {
   1635         return (BCM_E_PORT);
   1636     }
   1637 #ifdef BCM_MONTEREY_SUPPORT
   1638     if (SOC_IS_MONTEREY(unit)) {
   1639         return bcm_mn_cosq_gport_add(unit, port, numq, flags, gport); 
   1640     }
   1641 #endif /* BCM_MONTEREY_SUPPORT */
   1642 
   1643 #ifdef BCM_APACHE_SUPPORT
   1644     if (SOC_IS_APACHE(unit)) {
   1645         return bcm_ap_cosq_gport_add(unit, port, numq, flags, gport);
   1646     }
   1647 #endif
   1648 #ifdef BCM_TRIUMPH2_SUPPORT
   1649     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   1650         SOC_IS_VALKYRIE2(unit)) {
   1651         return bcm_tr2_cosq_gport_add(unit, port, numq, flags, gport);
   1652     }
   1653 #endif
   1654 #ifdef BCM_TOMAHAWK3_SUPPORT
   1655     if (SOC_IS_TOMAHAWK3(unit)) {
   1656         /* Return BCM_E_PARAM because of fixed hierarchy gport tree
   1657            is created during init */
   1658         return BCM_E_PARAM;
   1659     }
   1660 #endif /* BCM_TOMAHAWK3_SUPPORT */
   1661 #ifdef BCM_TOMAHAWK_SUPPORT
   1662     if (SOC_IS_TOMAHAWKX(unit)) {
   1663         /* Return BCM_E_PARAM because of fixed hierarchy gport tree
   1664            is created during init */
   1665         return BCM_E_PARAM;
   1666     }
   1667 #endif /* BCM_TOMAHAWK_SUPPORT */
   1668 #ifdef BCM_TRIDENT3_SUPPORT
   1669     if (SOC_IS_TRIDENT3X(unit)) {
   1670         /* Return BCM_E_PARAM because of fixed hierarchy gport tree
   1671            is created during init */
   1672         return BCM_E_PARAM;
   1673     }
   1674 #endif /* BCM_TRIDENT3_SUPPORT */
   1675 #ifdef BCM_TRIDENT2_SUPPORT
   1676     if (SOC_IS_TD2_TT2(unit)) {
   1677         return bcm_td2_cosq_gport_add(unit, port, numq, flags, gport);
   1678     }
   1679 #endif /* BCM_TRIDENT2_SUPPORT */
   1680 #ifdef BCM_TRIDENT_SUPPORT
   1681     if (SOC_IS_TD_TT(unit)) {
   1682         return bcm_td_cosq_gport_add(unit, port, numq, flags, gport);
   1683     }
   1684 #endif /* BCM_TRIDENT_SUPPORT */
   1685 #ifdef BCM_TRIUMPH3_SUPPORT
   1686     if (SOC_IS_TRIUMPH3(unit)) {
   1687         return bcm_tr3_cosq_gport_add(unit, port, numq, flags, gport, 0);
   1688     }
   1689 #endif
   1690 #ifdef BCM_KATANA_SUPPORT
   1691     if (SOC_IS_KATANA(unit)) {
   1692         return bcm_kt_cosq_gport_add(unit, port, numq, flags, gport);
   1693     }
   1694 #endif /* BCM_KATANA_SUPPORT */
   1695 #ifdef BCM_KATANA2_SUPPORT
   1696     if (SOC_IS_KATANA2(unit)) {
   1697         return bcm_kt2_cosq_gport_add(unit, port, numq, flags, gport);
   1698     }
   1699 #endif /* BCM_KATANA2_SUPPORT */
   1700 #ifdef BCM_TRIUMPH_SUPPORT
   1701     if (SOC_IS_TR_VL(unit)) {
   1702         if (!SOC_IS_HURRICANEX(unit) && !SOC_IS_GREYHOUND(unit) &&
   1703             !SOC_IS_GREYHOUND2(unit)) {
   1704             return bcm_tr_cosq_gport_add(unit, port, numq, flags, gport);
   1705         }
   1706     }
   1707 #endif
   1708 #ifdef BCM_GREYHOUND2_SUPPORT
   1709     if (SOC_IS_GREYHOUND2(unit)) {
   1710         return bcmi_gh2_cosq_gport_add(unit, port, numq, flags, gport);
   1711     }
   1712 #endif
   1713     return BCM_E_UNAVAIL; 
   1714 }
   1715 
   1716 /*
   1717  * Function:
   1718  *      bcm_cosq_gport_delete
   1719  * Purpose:
   1720  *      
   1721  * Parameters:
   1722  *      unit - (IN) Unit number.
   1723  *      gport - (IN) GPORT ID.
   1724  * Returns:
   1725  *      BCM_E_XXX
   1726  */
   1727 int 
   1728 bcm_esw_cosq_gport_delete(int unit, bcm_gport_t gport)
   1729 {
   1730     if (gport == BCM_GPORT_INVALID) {
   1731         return (BCM_E_PORT);
   1732     }
   1733 #ifdef BCM_MONTEREY_SUPPORT
   1734     if (SOC_IS_MONTEREY(unit)) {
   1735         return bcm_mn_cosq_gport_delete(unit, gport); 
   1736     }
   1737 #endif /* BCM_MONTEREY_SUPPORT */
   1738 
   1739 #ifdef BCM_APACHE_SUPPORT
   1740     if (SOC_IS_APACHE(unit)) {
   1741         return bcm_ap_cosq_gport_delete(unit, gport);
   1742     }
   1743 #endif
   1744 
   1745 #ifdef BCM_TRIUMPH2_SUPPORT
   1746     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   1747         SOC_IS_VALKYRIE2(unit)) {
   1748         return bcm_tr2_cosq_gport_delete(unit, gport);
   1749     }
   1750 #endif
   1751 #ifdef BCM_TOMAHAWK3_SUPPORT
   1752     if (SOC_IS_TOMAHAWK3(unit)) {
   1753         /* Return BCM_E_PARAM because of fixed hierarchy gport tree
   1754            is created during init */
   1755         return BCM_E_PARAM;
   1756     }
   1757 #endif
   1758 #ifdef BCM_TOMAHAWK_SUPPORT
   1759     if (SOC_IS_TOMAHAWKX(unit)) {
   1760         /* Return BCM_E_PARAM because of fixed hierarchy gport tree
   1761            is created during init */
   1762         return BCM_E_PARAM;
   1763     }
   1764 #endif /* BCM_TOMAHAWK_SUPPORT */
   1765 #ifdef BCM_TRIDENT3_SUPPORT
   1766     if (SOC_IS_TRIDENT3X(unit)) {
   1767         /* Return BCM_E_PARAM because of fixed hierarchy gport tree
   1768            is created during init */
   1769         return BCM_E_PARAM;
   1770     }
   1771 #endif /* BCM_TRIDENT3_SUPPORT */
   1772 #ifdef BCM_TRIDENT2_SUPPORT
   1773     if (SOC_IS_TD2_TT2(unit)) {
   1774         return bcm_td2_cosq_gport_delete(unit, gport);
   1775     }
   1776 #endif /* BCM_TRIDENT2_SUPPORT */
   1777 #ifdef BCM_TRIDENT_SUPPORT
   1778     if (SOC_IS_TD_TT(unit)) {
   1779         return bcm_td_cosq_gport_delete(unit, gport);
   1780     }
   1781 #endif /* BCM_TRIDENT_SUPPORT */
   1782 #ifdef BCM_TRIUMPH3_SUPPORT
   1783     if (SOC_IS_TRIUMPH3(unit)) {
   1784         return bcm_tr3_cosq_gport_delete(unit, gport);
   1785     }
   1786 #endif /* BCM_TRIDENT_SUPPORT */
   1787 #ifdef BCM_KATANA_SUPPORT
   1788     if (SOC_IS_KATANA(unit)) {
   1789         return bcm_kt_cosq_gport_delete(unit, gport);
   1790     }
   1791 #endif /* BCM_KATANA_SUPPORT */
   1792 #ifdef BCM_KATANA2_SUPPORT
   1793     if (SOC_IS_KATANA2(unit)) {
   1794         return bcm_kt2_cosq_gport_delete(unit, gport);
   1795     }
   1796 #endif /* BCM_KATANA2_SUPPORT */
   1797 #ifdef BCM_TRIUMPH_SUPPORT
   1798     /*no stage 1 queues and s1 scheduler to delete for HU*/
   1799     if (SOC_IS_TR_VL(unit)) {
   1800         if (!SOC_IS_HURRICANEX(unit) && !SOC_IS_GREYHOUND(unit) &&
   1801             !SOC_IS_GREYHOUND2(unit)) {
   1802             return bcm_tr_cosq_gport_delete(unit, gport);
   1803         }
   1804     }
   1805 #endif
   1806 #ifdef BCM_GREYHOUND2_SUPPORT
   1807     if (SOC_IS_GREYHOUND2(unit)) {
   1808         return bcmi_gh2_cosq_gport_delete(unit, gport);
   1809     }
   1810 #endif
   1811     return BCM_E_UNAVAIL; 
   1812 }
   1813 
   1814 /*
   1815  * Function:
   1816  *      bcm_cosq_gport_traverse
   1817  * Purpose:
   1818  *      Walks through the valid COSQ GPORTs and calls
   1819  *      the user supplied callback function for each entry.
   1820  * Parameters:
   1821  *      unit       - (IN) bcm device.
   1822  *      trav_fn    - (IN) Callback function.
   1823  *      user_data  - (IN) User data to be passed to callback function.
   1824  * Returns:
   1825  *      BCM_E_NONE - Success.
   1826  *      BCM_E_XXX
   1827  */
   1828 int
   1829 bcm_esw_cosq_gport_traverse(int unit, bcm_cosq_gport_traverse_cb cb,
   1830                             void *user_data)
   1831 {
   1832 #ifdef BCM_MONTEREY_SUPPORT
   1833     if (SOC_IS_MONTEREY(unit)) {
   1834         return bcm_mn_cosq_gport_traverse(unit, cb, user_data); 
   1835     }
   1836 #endif /* BCM_MONTEREY_SUPPORT */
   1837 
   1838 #ifdef BCM_APACHE_SUPPORT
   1839     if (SOC_IS_APACHE(unit)) {
   1840         return bcm_ap_cosq_gport_traverse(unit, cb, user_data);
   1841     }
   1842 #endif
   1843 
   1844 #ifdef BCM_TOMAHAWK3_SUPPORT
   1845     if (SOC_IS_TOMAHAWK3(unit)) {
   1846         return bcm_th3_cosq_gport_traverse(unit, cb, user_data);
   1847 
   1848     }
   1849 #endif /* BCM_TOMAHAWK3_SUPPORT */
   1850 #ifdef BCM_TOMAHAWK_SUPPORT
   1851     if (SOC_IS_TOMAHAWKX(unit)) {
   1852         return bcm_th_cosq_gport_traverse(unit, cb, user_data);
   1853     }
   1854 #endif /* BCM_TOMAHAWK_SUPPORT */
   1855 #ifdef BCM_HELIX5_SUPPORT
   1856     if (SOC_IS_HELIX5(unit)) {
   1857         return bcm_hx5_cosq_gport_traverse(unit, cb, user_data);
   1858     }
   1859 #endif /* BCM_HELIX5_SUPPORT */
   1860 #ifdef BCM_TRIDENT3_SUPPORT
   1861     if (SOC_IS_TRIDENT3X(unit)) {
   1862         return bcm_td3_cosq_gport_traverse(unit, cb, user_data);
   1863     }
   1864 #endif /* BCM_TRIDENT3_SUPPORT */
   1865 #ifdef BCM_TRIUMPH2_SUPPORT
   1866     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   1867         SOC_IS_VALKYRIE2(unit)) {
   1868         return bcm_tr2_cosq_gport_traverse(unit, cb, user_data);
   1869     }
   1870 #endif
   1871 #ifdef BCM_TRIDENT2_SUPPORT
   1872     if (SOC_IS_TD2_TT2(unit)) {
   1873         return bcm_td2_cosq_gport_traverse(unit, cb, user_data);
   1874     }
   1875 #endif /* BCM_TRIDENT2_SUPPORT */
   1876 #ifdef BCM_TRIDENT_SUPPORT
   1877     if (SOC_IS_TD_TT(unit)) {
   1878         return bcm_td_cosq_gport_traverse(unit, cb, user_data);
   1879     }
   1880 #endif /* BCM_TRIDENT_SUPPORT */
   1881 #ifdef BCM_TRIUMPH3_SUPPORT
   1882     if (SOC_IS_TRIUMPH3(unit)) {
   1883         return bcm_tr3_cosq_gport_traverse(unit, cb, user_data);
   1884     }
   1885 #endif /* BCM_TRIUMPH3_SUPPORT */
   1886 #ifdef BCM_KATANA_SUPPORT
   1887     if (SOC_IS_KATANA(unit)) {
   1888         return bcm_kt_cosq_gport_traverse(unit, cb, user_data);
   1889     }
   1890 #endif /* BCM_KATANA_SUPPORT */
   1891 #ifdef BCM_KATANA2_SUPPORT
   1892     if (SOC_IS_KATANA2(unit)) {
   1893         return bcm_kt2_cosq_gport_traverse(unit, cb, user_data);
   1894     }
   1895 #endif /* BCM_KATANA2_SUPPORT */
   1896 #ifdef BCM_TRIUMPH_SUPPORT
   1897     /*for each 24q ports, this calls a call-back func 
   1898     for scheduler gport. 24q ports and scheduler (S1) do not 
   1899     exist for Hurricane*/
   1900     if (SOC_IS_TR_VL(unit)) {
   1901         if (!SOC_IS_HURRICANEX(unit) && !SOC_IS_GREYHOUND(unit) &&
   1902             !SOC_IS_GREYHOUND2(unit)) {
   1903             return bcm_tr_cosq_gport_traverse(unit, cb, user_data);
   1904         }
   1905     }
   1906 #endif
   1907 #ifdef BCM_GREYHOUND2_SUPPORT
   1908     if (SOC_IS_GREYHOUND2(unit)) {
   1909         return bcmi_gh2_cosq_gport_traverse(unit, cb, user_data);
   1910     }
   1911 #endif /* BCM_GREYHOUND2_SUPPORT */
   1912     return BCM_E_UNAVAIL;
   1913 }
   1914 
   1915 /*
   1916  * Function:
   1917  *     bcm_cosq_gport_traverse_by_port
   1918  * Purpose:
   1919  *     Walks through the valid COSQ GPORTs belong to a port and calls
   1920  *     the user supplied callback function for each entry.
   1921  * Parameters:
   1922  *     unit       - (IN) unit number
   1923  *     port       - (IN) port number or GPORT identifier
   1924  *     trav_fn    - (IN) Callback function.
   1925  *     user_data  - (IN) User data to be passed to callback function
   1926  * Returns:
   1927  *     BCM_E_NONE - Success.
   1928  *     BCM_E_XXX
   1929  */
   1930 int
   1931 bcm_esw_cosq_gport_traverse_by_port(int unit, bcm_gport_t port,
   1932                            bcm_cosq_gport_traverse_cb cb,
   1933                            void *user_data)
   1934 {
   1935 #ifdef BCM_TOMAHAWK_SUPPORT
   1936     if (SOC_IS_TOMAHAWKX(unit)) {
   1937         return bcm_th_cosq_gport_traverse_by_port(unit, port, cb, user_data);
   1938     }
   1939 #endif /* BCM_TOMAHAWK_SUPPORT */
   1940 #ifdef BCM_HELIX5_SUPPORT
   1941     if (SOC_IS_HELIX5(unit)) {
   1942         return bcm_hx5_cosq_gport_traverse_by_port(unit, port, cb, user_data);
   1943     }
   1944 #endif /* BCM_TOMAHAWK_SUPPORT */
   1945     return BCM_E_UNAVAIL;
   1946 }
   1947 
   1948 int
   1949 bcm_esw_cosq_gport_mapping_set(int unit, bcm_port_t ing_port,
   1950                                bcm_cos_t int_pri, uint32 flags,
   1951                                bcm_gport_t gport, bcm_cos_queue_t cosq)
   1952 {
   1953 #ifdef BCM_MONTEREY_SUPPORT
   1954     if (SOC_IS_MONTEREY(unit)) {
   1955         return bcm_mn_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   1956                                              gport, cosq); 
   1957     }
   1958 #endif /* BCM_MONTEREY_SUPPORT */
   1959 
   1960 #ifdef BCM_APACHE_SUPPORT
   1961     if (SOC_IS_APACHE(unit)) {
   1962         return bcm_ap_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   1963                                              gport, cosq);
   1964     }
   1965 #endif
   1966 
   1967 #ifdef BCM_KATANA2_SUPPORT
   1968     if (SOC_IS_KATANA2(unit)) {
   1969         return bcm_kt2_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   1970                                              gport, cosq);
   1971     }
   1972 #endif /* BCM_TRIDENT_SUPPORT */
   1973 
   1974 
   1975     if (!soc_feature(unit, soc_feature_ets)) {
   1976         return BCM_E_UNAVAIL;
   1977     }
   1978 
   1979 #ifdef BCM_TOMAHAWK3_SUPPORT
   1980     if (SOC_IS_TOMAHAWK3(unit)) {
   1981         return bcm_th3_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   1982                                              gport, cosq);
   1983     }
   1984 #endif /* BCM_TOMAHAWK3_SUPPORT */
   1985 
   1986 #ifdef BCM_TOMAHAWK_SUPPORT
   1987     if (SOC_IS_TOMAHAWKX(unit)) {
   1988         return bcm_th_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   1989                                              gport, cosq);
   1990     }
   1991 #endif /* BCM_TOMAHAWK_SUPPORT */
   1992 #ifdef BCM_HELIX5_SUPPORT
   1993     if (SOC_IS_HELIX5(unit)) {
   1994         return bcm_hx5_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   1995                                               gport, cosq);
   1996     }
   1997 #endif /* BCM_HELIX5_SUPPORT */
   1998 
   1999 
   2000 #ifdef BCM_TRIDENT3_SUPPORT
   2001     if (SOC_IS_TRIDENT3X(unit)) {
   2002         return bcm_td3_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   2003                                               gport, cosq);
   2004     }
   2005 #endif /* BCM_TRIDENT3_SUPPORT */
   2006 
   2007 #ifdef BCM_TRIDENT2_SUPPORT
   2008     if (SOC_IS_TD2_TT2(unit)) {
   2009         return bcm_td2_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   2010                                              gport, cosq);
   2011     }
   2012 #endif /* BCM_TRIDENT2_SUPPORT */
   2013 
   2014 #ifdef BCM_TRIDENT_SUPPORT
   2015     if (SOC_IS_TD_TT(unit)) {
   2016         return bcm_td_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   2017                                              gport, cosq);
   2018     }
   2019 #endif /* BCM_TRIDENT_SUPPORT */
   2020 
   2021 #ifdef BCM_TRIUMPH3_SUPPORT
   2022     if (SOC_IS_TRIUMPH3(unit)) {
   2023         return bcm_tr3_cosq_gport_mapping_set(unit, ing_port, int_pri, flags,
   2024                                              gport, cosq);
   2025     }
   2026 #endif /* BCM_TRIDENT_SUPPORT */
   2027     return BCM_E_UNAVAIL;
   2028 }
   2029 
   2030 int
   2031 bcm_esw_cosq_gport_mapping_get(int unit, bcm_port_t ing_port,
   2032                                bcm_cos_t int_pri, uint32 flags,
   2033                                bcm_gport_t *gport, bcm_cos_queue_t *cosq)
   2034 {
   2035 #ifdef BCM_KATANA2_SUPPORT
   2036     if (SOC_IS_KATANA2(unit)) {
   2037         return bcm_kt2_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2038                                              gport, cosq);
   2039     }
   2040 #endif /* BCM_KATANA2_SUPPORT */
   2041 
   2042 
   2043     if (!soc_feature(unit, soc_feature_ets)) {
   2044         return BCM_E_UNAVAIL;
   2045     }
   2046 #ifdef BCM_MONTEREY_SUPPORT
   2047     if (SOC_IS_MONTEREY(unit)) {
   2048         return bcm_mn_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2049                                              gport, cosq);
   2050     }
   2051 #endif /* BCM_MONTEREY_SUPPORT */
   2052 
   2053 #ifdef BCM_APACHE_SUPPORT
   2054     if (SOC_IS_APACHE(unit)) {
   2055         return bcm_ap_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2056                                              gport, cosq);
   2057     }
   2058 #endif
   2059 
   2060 #ifdef BCM_TOMAHAWK3_SUPPORT
   2061     if (SOC_IS_TOMAHAWK3(unit)) {
   2062         return bcm_th3_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2063                                              gport, cosq);
   2064     }
   2065 #endif /* BCM_TOMAHAWK3_SUPPORT */
   2066 
   2067 #ifdef BCM_TOMAHAWK_SUPPORT
   2068     if (SOC_IS_TOMAHAWKX(unit)) {
   2069         return bcm_th_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2070                                              gport, cosq);
   2071     }
   2072 #endif /* BCM_TOMAHAWK_SUPPORT */
   2073 
   2074 #ifdef BCM_HELIX5_SUPPORT
   2075     if (SOC_IS_HELIX5(unit)) {
   2076         return bcm_hx5_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2077                                               gport, cosq);
   2078     }
   2079 #endif /* BCM_HELIX5_SUPPORT */
   2080 #ifdef BCM_TRIDENT3_SUPPORT
   2081     if (SOC_IS_TRIDENT3X(unit)) {
   2082         return bcm_td3_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2083                                               gport, cosq);
   2084     }
   2085 #endif /* BCM_TRIDENT3_SUPPORT */
   2086 
   2087 #ifdef BCM_TRIDENT2_SUPPORT
   2088     if (SOC_IS_TD2_TT2(unit)) {
   2089         return bcm_td2_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2090                                              gport, cosq);
   2091     }
   2092 #endif /* BCM_TRIDENT2_SUPPORT */
   2093 
   2094 #ifdef BCM_TRIDENT_SUPPORT
   2095     if (SOC_IS_TD_TT(unit)) {
   2096         return bcm_td_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2097                                              gport, cosq);
   2098     }
   2099 #endif /* BCM_TRIDENT_SUPPORT */
   2100 
   2101 #ifdef BCM_TRIUMPH3_SUPPORT
   2102     if (SOC_IS_TRIUMPH3(unit)) {
   2103         return bcm_tr3_cosq_gport_mapping_get(unit, ing_port, int_pri, flags,
   2104                                              gport, cosq);
   2105     }
   2106 #endif /* BCM_TRIUMPH3_SUPPORT */
   2107 
   2108     return BCM_E_UNAVAIL;
   2109 }
   2110 
   2111 /*
   2112  * Function:
   2113  *      bcm_cosq_gport_bandwidth_set
   2114  * Purpose:
   2115  *       
   2116  * Parameters:
   2117  *      unit - (IN) Unit number.
   2118  *      gport - (IN) GPORT ID.
   2119  *      cosq - (IN) COS queue to configure, -1 for all COS queues.
   2120  *      kbits_sec_min - (IN) minimum bandwidth, kbits/sec.
   2121  *      kbits_sec_max - (IN) maximum bandwidth, kbits/sec.
   2122  *      flags - (IN) BCM_COSQ_BW_*
   2123  * Returns:
   2124  *      BCM_E_XXX
   2125  */
   2126 int 
   2127 bcm_esw_cosq_gport_bandwidth_set(int unit, bcm_gport_t gport, 
   2128                                  bcm_cos_queue_t cosq, uint32 kbits_sec_min, 
   2129                                  uint32 kbits_sec_max, uint32 flags)
   2130 {
   2131     if (gport == BCM_GPORT_INVALID) {
   2132         return (BCM_E_PORT);
   2133     }
   2134 
   2135     if ((kbits_sec_max != 0) && (kbits_sec_max < kbits_sec_min )) {
   2136         return (BCM_E_PARAM);
   2137     }
   2138 #ifdef BCM_MONTEREY_SUPPORT
   2139     if (SOC_IS_MONTEREY(unit)) {
   2140         return bcm_mn_cosq_gport_bandwidth_set(unit, gport,
   2141                                                cosq, kbits_sec_min,
   2142                                                kbits_sec_max, flags); 
   2143     }
   2144 #endif /* BCM_MONTEREY_SUPPORT */
   2145 
   2146 #ifdef BCM_APACHE_SUPPORT
   2147     if (SOC_IS_APACHE(unit)) {
   2148         return bcm_ap_cosq_gport_bandwidth_set(unit, gport, 
   2149                                                cosq, kbits_sec_min, 
   2150                                                kbits_sec_max, flags);
   2151     }
   2152 #endif
   2153 
   2154 #ifdef BCM_TRIUMPH2_SUPPORT
   2155     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   2156         SOC_IS_VALKYRIE2(unit)) {
   2157         return bcm_tr2_cosq_gport_bandwidth_set(unit, gport, 
   2158                                                cosq, kbits_sec_min, 
   2159                                                kbits_sec_max, flags);
   2160     }
   2161 #endif
   2162 #ifdef BCM_TOMAHAWK3_SUPPORT
   2163     if (SOC_IS_TOMAHAWK3(unit)) {
   2164         return bcm_th3_cosq_gport_bandwidth_set(unit, gport, cosq,
   2165                                                kbits_sec_min, kbits_sec_max,
   2166                                                flags);
   2167     }
   2168 #endif /* BCM_TOMAHAWK_SUPPORT */
   2169 #ifdef BCM_TOMAHAWK_SUPPORT
   2170     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   2171         return bcm_th_cosq_gport_bandwidth_set(unit, gport, cosq,
   2172                                                kbits_sec_min, kbits_sec_max,
   2173                                                flags);
   2174     }
   2175 #endif /* BCM_TOMAHAWK_SUPPORT */
   2176 #ifdef BCM_HELIX5_SUPPORT
   2177     if (SOC_IS_HELIX5(unit)) {
   2178         return bcm_hx5_cosq_gport_bandwidth_set(unit, gport, cosq,
   2179                                                 kbits_sec_min, kbits_sec_max,
   2180                                                 flags);
   2181     }
   2182 #endif /* BCM_HELIX5_SUPPORT */
   2183 #ifdef BCM_TRIDENT3_SUPPORT
   2184     if (SOC_IS_TRIDENT3X(unit)) {
   2185         return bcm_td3_cosq_gport_bandwidth_set(unit, gport, cosq,
   2186                                                 kbits_sec_min, kbits_sec_max,
   2187                                                 flags);
   2188     }
   2189 #endif /* BCM_TRIDENT3_SUPPORT */
   2190 #ifdef BCM_TRIDENT2_SUPPORT
   2191     if (SOC_IS_TD2_TT2(unit)) {
   2192         return bcm_td2_cosq_gport_bandwidth_set(unit, gport, cosq,
   2193                                                kbits_sec_min, kbits_sec_max,
   2194                                                flags);
   2195     }
   2196 #endif /* BCM_TRIDENT2_SUPPORT */
   2197 #ifdef BCM_TRIDENT_SUPPORT
   2198     if (SOC_IS_TD_TT(unit)) {
   2199         return bcm_td_cosq_gport_bandwidth_set(unit, gport, cosq,
   2200                                                kbits_sec_min, kbits_sec_max,
   2201                                                flags);
   2202     }
   2203 #endif /* BCM_TRIDENT_SUPPORT */
   2204 #ifdef BCM_KATANA_SUPPORT
   2205     if (SOC_IS_KATANA(unit)) {
   2206         return bcm_kt_cosq_gport_child_node_bandwidth_set(unit, gport, cosq,
   2207                                                kbits_sec_min, kbits_sec_max,
   2208                                                flags);
   2209     }
   2210 #endif /* BCM_KATANA_SUPPORT */
   2211 #ifdef BCM_KATANA2_SUPPORT
   2212     if (SOC_IS_KATANA2(unit)) {
   2213         return bcm_kt2_cosq_gport_child_node_bandwidth_set(unit, gport, cosq,
   2214                                                kbits_sec_min, kbits_sec_max,
   2215                                                flags);
   2216     }
   2217 #endif /* BCM_KATANA2_SUPPORT */
   2218 #ifdef BCM_TRIUMPH3_SUPPORT
   2219     if (SOC_IS_TRIUMPH3(unit)) {
   2220         return bcm_tr3_cosq_gport_bandwidth_set(unit, gport, cosq,
   2221                                                kbits_sec_min, kbits_sec_max,
   2222                                                flags);
   2223     }
   2224 #endif /* BCM_TRIUMPH3_SUPPORT */
   2225 #ifdef BCM_TRIUMPH_SUPPORT
   2226     if (SOC_IS_TR_VL(unit)) {
   2227 #if defined(BCM_HURRICANE_SUPPORT)
   2228         if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
   2229             return bcm_hu_cosq_gport_bandwidth_set(unit, gport, 
   2230                                                    cosq, kbits_sec_min, 
   2231                                                    kbits_sec_max, flags);
   2232         }           
   2233 #endif /*SOC_IS_HURRICANE*/
   2234 #if defined(BCM_GREYHOUND2_SUPPORT)
   2235         if (SOC_IS_GREYHOUND2(unit)) {
   2236             return bcmi_gh2_cosq_gport_bandwidth_set(unit, gport,
   2237                                                      cosq, kbits_sec_min,
   2238                                                      kbits_sec_max, flags);
   2239         }
   2240 #endif /* BCM_GREYHOUND2_SUPPORT */
   2241         return bcm_tr_cosq_gport_bandwidth_set(unit, gport, 
   2242                                                cosq, kbits_sec_min, 
   2243                                                kbits_sec_max, flags);
   2244     }
   2245 #endif
   2246     return BCM_E_UNAVAIL; 
   2247 }
   2248 
   2249 /*
   2250  * Function:
   2251  *      bcm_cosq_gport_bandwidth_get
   2252  * Purpose:
   2253  *       
   2254  * Parameters:
   2255  *      unit - (IN) Unit number.
   2256  *      gport - (IN) GPORT ID.
   2257  *      cosq - (IN) COS queue to configure, -1 for all COS queues.
   2258  *      kbits_sec_min - (OUT) minimum bandwidth, kbits/sec.
   2259  *      kbits_sec_max - (OUT) maximum bandwidth, kbits/sec.
   2260  *      flags - (OUT) BCM_COSQ_BW_*
   2261  * Returns:
   2262  *      BCM_E_XXX
   2263  */
   2264 int 
   2265 bcm_esw_cosq_gport_bandwidth_get(int unit, bcm_gport_t gport, 
   2266                                  bcm_cos_queue_t cosq, uint32 *kbits_sec_min, 
   2267                                  uint32 *kbits_sec_max, uint32 *flags)
   2268 {
   2269     if (gport == BCM_GPORT_INVALID) {
   2270         return (BCM_E_PORT);
   2271     }
   2272 #ifdef BCM_MONTEREY_SUPPORT
   2273     if (SOC_IS_MONTEREY(unit)) {
   2274         return bcm_mn_cosq_gport_bandwidth_get(unit, gport,
   2275                                                cosq, kbits_sec_min,
   2276                                                kbits_sec_max, flags);
   2277     }
   2278 #endif /* BCM_MONTEREY_SUPPORT */
   2279 
   2280 #ifdef BCM_APACHE_SUPPORT
   2281     if (SOC_IS_APACHE(unit)) {
   2282         return bcm_ap_cosq_gport_bandwidth_get(unit, gport, 
   2283                                                cosq, kbits_sec_min, 
   2284                                                kbits_sec_max, flags);
   2285     }
   2286 #endif
   2287 
   2288 #ifdef BCM_TRIUMPH2_SUPPORT
   2289     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   2290         SOC_IS_VALKYRIE2(unit)) {
   2291         return bcm_tr2_cosq_gport_bandwidth_get(unit, gport, 
   2292                                                cosq, kbits_sec_min, 
   2293                                                kbits_sec_max, flags);
   2294     }
   2295 #endif
   2296 #ifdef BCM_TOMAHAWK3_SUPPORT
   2297     if (SOC_IS_TOMAHAWK3(unit)) {
   2298         return bcm_th3_cosq_gport_bandwidth_get(unit, gport, cosq,
   2299                                                kbits_sec_min, kbits_sec_max,
   2300                                                flags);
   2301     }
   2302 #endif /* BCM_TOMAHAWK_SUPPORT */
   2303 #ifdef BCM_TOMAHAWK_SUPPORT
   2304     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   2305         return bcm_th_cosq_gport_bandwidth_get(unit, gport, cosq,
   2306                                                kbits_sec_min, kbits_sec_max,
   2307                                                flags);
   2308     }
   2309 #endif /* BCM_TOMAHAWK_SUPPORT */
   2310 #ifdef BCM_HELIX5_SUPPORT
   2311     if (SOC_IS_HELIX5(unit)) {
   2312         return bcm_hx5_cosq_gport_bandwidth_get(unit, gport, cosq,
   2313                                                 kbits_sec_min, kbits_sec_max,
   2314                                                 flags);
   2315     }
   2316 #endif /* BCM_HELIX5_SUPPORT */
   2317 #ifdef BCM_TRIDENT3_SUPPORT
   2318     if (SOC_IS_TRIDENT3X(unit)) {
   2319         return bcm_td3_cosq_gport_bandwidth_get(unit, gport, cosq,
   2320                                                 kbits_sec_min, kbits_sec_max,
   2321                                                 flags);
   2322     }
   2323 #endif /* BCM_TRIDENT3_SUPPORT */
   2324 #ifdef BCM_TRIDENT2_SUPPORT
   2325     if (SOC_IS_TD2_TT2(unit)) {
   2326         return bcm_td2_cosq_gport_bandwidth_get(unit, gport, cosq,
   2327                                                kbits_sec_min, kbits_sec_max,
   2328                                                flags);
   2329     }
   2330 #endif /* BCM_TRIDENT2_SUPPORT */
   2331 #ifdef BCM_TRIDENT_SUPPORT
   2332     if (SOC_IS_TD_TT(unit)) {
   2333         return bcm_td_cosq_gport_bandwidth_get(unit, gport, cosq,
   2334                                                kbits_sec_min, kbits_sec_max,
   2335                                                flags);
   2336     }
   2337 #endif /* BCM_TRIDENT_SUPPORT */
   2338 #ifdef BCM_KATANA_SUPPORT
   2339     if (SOC_IS_KATANA(unit)) {
   2340         return bcm_kt_cosq_gport_child_node_bandwidth_get(unit, gport, cosq,
   2341                                                kbits_sec_min, kbits_sec_max,
   2342                                                flags);
   2343     }
   2344 #endif /* BCM_KATANA_SUPPORT */
   2345 #ifdef BCM_KATANA2_SUPPORT
   2346     if (SOC_IS_KATANA2(unit)) {
   2347         return bcm_kt2_cosq_gport_child_node_bandwidth_get(unit, gport, cosq,
   2348                                                kbits_sec_min, kbits_sec_max,
   2349                                                flags);
   2350     }
   2351 #endif /* BCM_KATANA2_SUPPORT */
   2352 #ifdef BCM_TRIUMPH3_SUPPORT
   2353     if (SOC_IS_TRIUMPH3(unit)) {
   2354         return bcm_tr3_cosq_gport_bandwidth_get(unit, gport, cosq,
   2355                                                kbits_sec_min, kbits_sec_max,
   2356                                                flags);
   2357     }
   2358 #endif /* BCM_TRIUMPH3_SUPPORT */
   2359 #ifdef BCM_TRIUMPH_SUPPORT
   2360     if (SOC_IS_TR_VL(unit)) {
   2361 #if defined(BCM_HURRICANE_SUPPORT)
   2362         if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
   2363             return bcm_hu_cosq_gport_bandwidth_get(unit, gport, 
   2364                                                    cosq, kbits_sec_min, 
   2365                                                    kbits_sec_max, flags);
   2366         } else
   2367 #endif /* BCM_HURRICANE_SUPPORT*/
   2368 #if defined(BCM_GREYHOUND2_SUPPORT)
   2369         if (SOC_IS_GREYHOUND2(unit)) {
   2370             return bcmi_gh2_cosq_gport_bandwidth_get(unit, gport,
   2371                                                      cosq, kbits_sec_min,
   2372                                                      kbits_sec_max, flags);
   2373         } else
   2374 #endif /* BCM_GREYHOUND2_SUPPORT */
   2375         {
   2376             return bcm_tr_cosq_gport_bandwidth_get(unit, gport, 
   2377                                                    cosq, kbits_sec_min, 
   2378                                                    kbits_sec_max, flags);
   2379         }
   2380     }
   2381 #endif
   2382     return BCM_E_UNAVAIL; 
   2383 }
   2384 
   2385 /*
   2386  * Function:
   2387  *      bcm_cosq_gport_sched_set
   2388  * Purpose:
   2389  *      
   2390  * Parameters:
   2391  *      unit - (IN) Unit number.
   2392  *      gport - (IN) GPORT ID.
   2393  *      cosq - (IN) COS queue to configure, -1 for all COS queues.
   2394  *      mode - (IN) Scheduling mode, one of BCM_COSQ_xxx
   2395  *    weight - (IN) Weight for the specified COS queue(s)
   2396  *               Unused if mode is BCM_COSQ_STRICT.
   2397  * Returns:
   2398  *      BCM_E_XXX
   2399  */
   2400 int 
   2401 bcm_esw_cosq_gport_sched_set(int unit, bcm_gport_t gport, 
   2402                              bcm_cos_queue_t cosq, int mode, int weight)
   2403 {
   2404     if (gport == BCM_GPORT_INVALID) {
   2405         return (BCM_E_PORT);
   2406     }
   2407 #ifdef BCM_MONTEREY_SUPPORT
   2408     if (SOC_IS_MONTEREY(unit)) {
   2409         return bcm_mn_cosq_gport_sched_set(unit, gport, cosq, mode, weight); 
   2410     }
   2411 #endif /* BCM_MONTEREY_SUPPORT */
   2412 
   2413 #ifdef BCM_APACHE_SUPPORT
   2414     if (SOC_IS_APACHE(unit)) {
   2415         return bcm_ap_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2416     }
   2417 #endif
   2418 
   2419 #ifdef BCM_TOMAHAWK3_SUPPORT
   2420     if (SOC_IS_TOMAHAWK3(unit)) {
   2421         return bcm_th3_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2422     }
   2423 #endif /* BCM_TOMAHAWK_SUPPORT */
   2424 #ifdef BCM_TOMAHAWK_SUPPORT
   2425     if (SOC_IS_TOMAHAWKX(unit)) {
   2426         return bcm_th_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2427     }
   2428 #endif /* BCM_TOMAHAWK_SUPPORT */
   2429 #ifdef BCM_HELIX5_SUPPORT
   2430     if (SOC_IS_HELIX5(unit)) {
   2431         return bcm_hx5_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2432     }
   2433 #endif
   2434 #ifdef BCM_TRIDENT3_SUPPORT
   2435     if (SOC_IS_TRIDENT3X(unit)) {
   2436         return bcm_td3_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2437     }
   2438 #endif /* BCM_TRIDENT3_SUPPORT */
   2439 #ifdef BCM_TRIUMPH2_SUPPORT
   2440     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   2441         SOC_IS_VALKYRIE2(unit)) {
   2442         return bcm_tr2_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2443     }
   2444 #endif
   2445 #ifdef BCM_TRIDENT2_SUPPORT
   2446     if (SOC_IS_TD2_TT2(unit)) {
   2447         return bcm_td2_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2448     }
   2449 #endif /* BCM_TRIDENT2_SUPPORT */
   2450 #ifdef BCM_TRIDENT_SUPPORT
   2451     if (SOC_IS_TD_TT(unit)) {
   2452         return bcm_td_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2453     }
   2454 #endif /* BCM_TRIDENT_SUPPORT */
   2455 #ifdef BCM_TRIUMPH3_SUPPORT
   2456     if (SOC_IS_TRIUMPH3(unit)) {
   2457         return bcm_tr3_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2458     }
   2459 #endif /* BCM_TRIDENT_SUPPORT */
   2460 #ifdef BCM_KATANA_SUPPORT
   2461     if (SOC_IS_KATANA(unit)) {
   2462         return bcm_kt_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2463     }
   2464 #endif /* BCM_KATANA_SUPPORT */
   2465 #ifdef BCM_KATANA2_SUPPORT
   2466     if (SOC_IS_KATANA2(unit)) {
   2467         return bcm_kt2_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2468     }
   2469 #endif /* BCM_KATANA2_SUPPORT */
   2470 #ifdef BCM_TRIUMPH_SUPPORT
   2471     if (SOC_IS_TR_VL(unit)) {
   2472 #if defined(BCM_HURRICANE_SUPPORT)
   2473         if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
   2474             return bcm_hu_cosq_gport_sched_set(unit, gport, cosq, mode, weight);            
   2475         } else     
   2476 #endif /* BCM_HURRICANE_SUPPORT*/
   2477 #if defined(BCM_GREYHOUND2_SUPPORT)
   2478         if (SOC_IS_GREYHOUND2(unit)) {
   2479             return bcmi_gh2_cosq_gport_sched_set(
   2480                        unit, gport, cosq, mode, weight);
   2481         } else
   2482 #endif /* BCM_GREYHOUND2_SUPPORT */
   2483         {
   2484             return bcm_tr_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2485         }
   2486     }
   2487 #endif
   2488 #ifdef BCM_SCORPION_SUPPORT 
   2489     if (SOC_IS_SC_CQ(unit)) {
   2490         return bcm_sc_cosq_gport_sched_set(unit, gport, cosq, mode, weight);
   2491     }
   2492 #endif
   2493     return BCM_E_UNAVAIL; 
   2494 }
   2495 
   2496 /*
   2497  * Function:
   2498  *      bcm_cosq_gport_sched_get
   2499  * Purpose:
   2500  *      
   2501  * Parameters:
   2502  *      unit - (IN) Unit number.
   2503  *      gport - (IN) GPORT ID.
   2504  *      cosq - (IN) COS queue
   2505  *      mode - (OUT) Scheduling mode, one of BCM_COSQ_xxx
   2506  *    weight - (OUT) Weight for the specified COS queue(s)
   2507  *               Unused if mode is BCM_COSQ_STRICT.
   2508  * Returns:
   2509  *      BCM_E_XXX
   2510  */
   2511 int 
   2512 bcm_esw_cosq_gport_sched_get(int unit, bcm_gport_t gport, 
   2513                              bcm_cos_queue_t cosq, int *mode, int *weight)
   2514 {
   2515     if (gport == BCM_GPORT_INVALID) {
   2516         return (BCM_E_PORT);
   2517     }
   2518 #ifdef BCM_MONTEREY_SUPPORT
   2519     if (SOC_IS_MONTEREY(unit)) {
   2520         return bcm_mn_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2521     }
   2522 #endif /* BCM_MONTEREY_SUPPORT */
   2523 #ifdef BCM_APACHE_SUPPORT
   2524     if (SOC_IS_APACHE(unit)) {
   2525         return bcm_ap_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2526     }
   2527 #endif
   2528 
   2529 #ifdef BCM_TOMAHAWK3_SUPPORT
   2530     if (SOC_IS_TOMAHAWK3(unit)) {
   2531         return bcm_th3_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2532     }
   2533 #endif /* BCM_TOMAHAWK_SUPPORT */
   2534 #ifdef BCM_TOMAHAWK_SUPPORT
   2535     if (SOC_IS_TOMAHAWKX(unit)) {
   2536         return bcm_th_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2537     }
   2538 #endif /* BCM_TOMAHAWK_SUPPORT */
   2539 #ifdef BCM_HELIX5_SUPPORT
   2540     if (SOC_IS_HELIX5(unit)) {
   2541         return bcm_hx5_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2542     }
   2543 #endif /* BCM_HELIX5_SUPPORT */
   2544 #ifdef BCM_TRIDENT3_SUPPORT
   2545     if (SOC_IS_TRIDENT3X(unit)) {
   2546         return bcm_td3_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2547     }
   2548 #endif /* BCM_TRIDENT3_SUPPORT */
   2549 #ifdef BCM_TRIUMPH2_SUPPORT
   2550     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   2551         SOC_IS_VALKYRIE2(unit)) {
   2552         return bcm_tr2_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2553     }
   2554 #endif
   2555 #ifdef BCM_TRIDENT2_SUPPORT
   2556     if (SOC_IS_TD2_TT2(unit)) {
   2557         return bcm_td2_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2558     }
   2559 #endif /* BCM_TRIDENT2_SUPPORT */
   2560 #ifdef BCM_TRIDENT_SUPPORT
   2561     if (SOC_IS_TD_TT(unit)) {
   2562         return bcm_td_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2563     }
   2564 #endif /* BCM_TRIDENT_SUPPORT */
   2565 #ifdef BCM_TRIUMPH3_SUPPORT
   2566     if (SOC_IS_TRIUMPH3(unit)) {
   2567         return bcm_tr3_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2568     }
   2569 #endif /* BCM_TRIDENT_SUPPORT */
   2570 #ifdef BCM_KATANA_SUPPORT
   2571     if (SOC_IS_KATANA(unit)) {
   2572         return bcm_kt_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2573     }
   2574 #endif /* BCM_KATANA_SUPPORT */
   2575 #ifdef BCM_KATANA2_SUPPORT
   2576     if (SOC_IS_KATANA2(unit)) {
   2577         return bcm_kt2_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2578     }
   2579 #endif /* BCM_KATANA2_SUPPORT */
   2580 #ifdef BCM_TRIUMPH_SUPPORT
   2581     if (SOC_IS_TR_VL(unit)) {
   2582 #if defined(BCM_HURRICANE_SUPPORT)
   2583         if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
   2584             return bcm_hu_cosq_gport_sched_get(unit, gport, cosq, mode, weight);           
   2585         } else     
   2586 #endif /* BCM_HURRICANE_SUPPORT*/
   2587 #if defined(BCM_GREYHOUND2_SUPPORT)
   2588         if (SOC_IS_GREYHOUND2(unit)) {
   2589             return bcmi_gh2_cosq_gport_sched_get(
   2590                        unit, gport, cosq, mode, weight);
   2591         } else
   2592 #endif /* BCM_GREYHOUND2_SUPPORT */
   2593         {
   2594             return bcm_tr_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2595         }
   2596     }
   2597 #endif
   2598 #ifdef BCM_SCORPION_SUPPORT 
   2599     if (SOC_IS_SC_CQ(unit)) {
   2600         return bcm_sc_cosq_gport_sched_get(unit, gport, cosq, mode, weight);
   2601     }
   2602 #endif
   2603     return BCM_E_UNAVAIL; 
   2604 }
   2605 
   2606 /*
   2607  * Function:
   2608  *      bcm_cosq_gport_attach
   2609  * Purpose:
   2610  *      
   2611  * Parameters:
   2612  *      unit       - (IN) Unit number.
   2613  *      sched_port - (IN) Scheduler GPORT ID.
   2614  *      input_port - (IN) GPORT to attach to.
   2615  *      cosq       - (IN) COS queue to attach to.
   2616  * Returns:
   2617  *      BCM_E_XXX
   2618  * Notes:
   2619  */
   2620 int 
   2621 bcm_esw_cosq_gport_attach(int unit, bcm_gport_t sched_gport, 
   2622                           bcm_gport_t input_gport, bcm_cos_queue_t cosq)
   2623 {
   2624     if (sched_gport == BCM_GPORT_INVALID) {
   2625         return (BCM_E_PORT);
   2626     }
   2627 #ifdef BCM_MONTEREY_SUPPORT
   2628     if (SOC_IS_MONTEREY(unit)) {
   2629         return bcm_mn_cosq_gport_attach(unit, sched_gport,
   2630                                         input_gport, cosq); 
   2631     }
   2632 #endif /* BCM_MONTEREY_SUPPORT */
   2633 
   2634 #ifdef BCM_APACHE_SUPPORT
   2635     if (SOC_IS_APACHE(unit)) {
   2636         return bcm_ap_cosq_gport_attach(unit, sched_gport, 
   2637                                         input_gport, cosq);
   2638     }
   2639 #endif
   2640 
   2641 #ifdef BCM_TRIUMPH2_SUPPORT
   2642     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   2643         SOC_IS_VALKYRIE2(unit)) {
   2644         return bcm_tr2_cosq_gport_attach(unit, sched_gport, 
   2645                                         input_gport, cosq);
   2646     }
   2647 #endif
   2648 #ifdef BCM_TOMAHAWK3_SUPPORT
   2649     if (SOC_IS_TOMAHAWK3(unit)) {
   2650         return bcm_th3_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2651     }
   2652 #endif /* BCM_TOMAHAWK3_SUPPORT */
   2653 #ifdef BCM_TOMAHAWK_SUPPORT
   2654     if (SOC_IS_TOMAHAWKX(unit)) {
   2655         return bcm_th_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2656     }
   2657 #endif /* BCM_TOMAHAWK_SUPPORT */
   2658 #ifdef BCM_HELIX5_SUPPORT
   2659     if (SOC_IS_HELIX5(unit)) {
   2660         return bcm_hx5_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2661     }
   2662 #endif /* BCM_HELIX5_SUPPORT */
   2663 #ifdef BCM_TRIDENT3_SUPPORT
   2664     if (SOC_IS_TRIDENT3X(unit)) {
   2665         return bcm_td3_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2666     }
   2667 #endif /* BCM_TRIDENT3_SUPPORT */
   2668 #if defined(BCM_TRIDENT2_SUPPORT)
   2669     if (SOC_IS_TD2_TT2(unit)) {
   2670         return bcm_td2_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2671     }
   2672 #endif /* BCM_TRIDENT2_SUPPORT */
   2673 #if defined(BCM_TRIDENT_SUPPORT)
   2674     if (SOC_IS_TD_TT(unit)) {
   2675         return bcm_td_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2676     }
   2677 #endif /* BCM_TRIDENT_SUPPORT */
   2678 #if defined(BCM_TRIUMPH3_SUPPORT)
   2679     if (SOC_IS_TRIUMPH3(unit)) {
   2680         return bcm_tr3_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2681     }
   2682 #endif /* BCM_TRIUMPH3_SUPPORT */
   2683 #ifdef BCM_KATANA_SUPPORT
   2684     if (SOC_IS_KATANA(unit)) {
   2685         return bcm_kt_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2686     }
   2687 #endif /* BCM_KATANA_SUPPORT */
   2688 #ifdef BCM_KATANA2_SUPPORT
   2689     if (SOC_IS_KATANA2(unit)) {
   2690         BCM_IF_ERROR_RETURN(bcm_kt2_cosq_gport_validate(unit,
   2691         sched_gport, input_gport, cosq));
   2692         return bcm_kt2_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2693     }
   2694 #endif /* BCM_KATANA2_SUPPORT */
   2695 #ifdef BCM_TRIUMPH_SUPPORT
   2696     /*for HU there is no VLAN cosq and scheduler (S1)*/
   2697 	if (SOC_IS_TR_VL(unit)) {
   2698         if (!SOC_IS_HURRICANEX(unit) && ! SOC_IS_GREYHOUND(unit) &&
   2699             !SOC_IS_GREYHOUND2(unit)) {
   2700             return bcm_tr_cosq_gport_attach(unit, sched_gport, 
   2701                                         input_gport, cosq);
   2702         }
   2703     }
   2704 #endif
   2705 #if defined(BCM_GREYHOUND2_SUPPORT)
   2706     if (SOC_IS_GREYHOUND2(unit)) {
   2707         return bcmi_gh2_cosq_gport_attach(unit, sched_gport, input_gport, cosq);
   2708     }
   2709 #endif /* BCM_GREYHOUND2_SUPPORT */
   2710     return BCM_E_UNAVAIL; 
   2711 }
   2712 
   2713 /*
   2714  * Function:
   2715  *      bcm_cosq_gport_reattach
   2716  * Purpose:
   2717  *      
   2718  * Parameters:
   2719  *      unit       - (IN) Unit number.
   2720  *      sched_port - (IN) Scheduler GPORT ID.
   2721  *      input_port - (IN) GPORT to attach to.
   2722  *      cosq       - (IN) COS queue to attach to.
   2723  * Returns:
   2724  *      BCM_E_XXX
   2725  * Notes:
   2726  */
   2727 int 
   2728 bcm_esw_cosq_gport_reattach(int unit, bcm_gport_t sched_gport, 
   2729                           bcm_gport_t input_gport, bcm_cos_queue_t cosq)
   2730 {
   2731 
   2732     if (sched_gport == BCM_GPORT_INVALID) {
   2733         return (BCM_E_PORT);
   2734     }
   2735 #ifdef BCM_KATANA2_SUPPORT
   2736     if (SOC_IS_KATANA2(unit)) {
   2737         return bcm_kt2_cosq_gport_reattach(unit, sched_gport,
   2738                                            input_gport, cosq);
   2739     }
   2740 #endif /* BCM_KATANA2_SUPPORT */
   2741 
   2742     return BCM_E_UNAVAIL; 
   2743 }
   2744 
   2745 /*
   2746  * Function:
   2747  *      bcm_cosq_gport_detach
   2748  * Purpose:
   2749  *
   2750  * Parameters:
   2751  *      unit       - (IN) Unit number.
   2752  *      sched_port - (IN) Scheduler GPORT ID.
   2753  *      input_port - (IN) GPORT to detach from.
   2754  *      cosq       - (IN) COS queue to detach from.
   2755  * Returns:
   2756  *      BCM_E_XXX
   2757  * Notes:
   2758  */
   2759 int
   2760 bcm_esw_cosq_gport_detach(int unit, bcm_gport_t sched_gport,
   2761                           bcm_gport_t input_gport, bcm_cos_queue_t cosq)
   2762 {
   2763     if (sched_gport == BCM_GPORT_INVALID || input_gport == BCM_GPORT_INVALID) {
   2764         return (BCM_E_PORT);
   2765     }
   2766 #ifdef BCM_MONTEREY_SUPPORT
   2767     if (SOC_IS_MONTEREY(unit)) {
   2768         return bcm_mn_cosq_gport_detach(unit, sched_gport,
   2769                                         input_gport, cosq);
   2770     }
   2771 #endif /* BCM_MONTEREY_SUPPORT */
   2772 
   2773 #ifdef BCM_APACHE_SUPPORT
   2774     if (SOC_IS_APACHE(unit)) {
   2775         return bcm_ap_cosq_gport_detach(unit, sched_gport,
   2776                                         input_gport, cosq);
   2777     }
   2778 #endif
   2779 
   2780 #ifdef BCM_TRIUMPH2_SUPPORT
   2781     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   2782         SOC_IS_VALKYRIE2(unit)) {
   2783         return bcm_tr2_cosq_gport_detach(unit, sched_gport,
   2784                                         input_gport, cosq);
   2785     }
   2786 #endif
   2787 #ifdef BCM_TOMAHAWK3_SUPPORT
   2788     if (SOC_IS_TOMAHAWK3(unit)) {
   2789         return bcm_th3_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2790     }
   2791 #endif /* BCM_TOMAHAWK3_SUPPORT */
   2792 #ifdef BCM_TOMAHAWK_SUPPORT
   2793     if (SOC_IS_TOMAHAWKX(unit)) {
   2794         return bcm_th_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2795     }
   2796 #endif /* BCM_TOMAHAWK_SUPPORT */
   2797 #ifdef BCM_HELIX5_SUPPORT
   2798     if (SOC_IS_HELIX5(unit)) {
   2799         return bcm_hx5_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2800     }
   2801 #endif /* BCM_HELIX5_SUPPORT */
   2802 #ifdef BCM_TRIDENT3_SUPPORT
   2803     if (SOC_IS_TRIDENT3X(unit)) {
   2804         return bcm_td3_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2805     }
   2806 #endif /* BCM_TRIDENT3_SUPPORT */
   2807 #if defined(BCM_TRIDENT2_SUPPORT)
   2808     if (SOC_IS_TD2_TT2(unit)) {
   2809         return bcm_td2_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2810     }
   2811 #endif /* BCM_TRIDENT2_SUPPORT */
   2812 #if defined(BCM_TRIDENT_SUPPORT)
   2813     if (SOC_IS_TD_TT(unit)) {
   2814         return bcm_td_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2815     }
   2816 #endif /* BCM_TRIDENT_SUPPORT */
   2817 #if defined(BCM_TRIUMPH3_SUPPORT)
   2818     if (SOC_IS_TRIUMPH3(unit)) {
   2819         return bcm_tr3_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2820     }
   2821 #endif /* BCM_TRIUMPH3_SUPPORT */
   2822 #if defined(BCM_KATANA_SUPPORT)
   2823     if (SOC_IS_KATANA(unit)) {
   2824         return bcm_kt_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2825     }
   2826 #endif /* BCM_KATANA_SUPPORT */
   2827 #if defined(BCM_KATANA2_SUPPORT)
   2828     if (SOC_IS_KATANA2(unit)) {
   2829         BCM_IF_ERROR_RETURN (bcm_kt2_cosq_gport_validate
   2830                 (unit, sched_gport, input_gport, cosq));
   2831         return bcm_kt2_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2832     }
   2833 #endif /* BCM_KATANA2_SUPPORT */
   2834 #ifdef BCM_TRIUMPH_SUPPORT
   2835     if (SOC_IS_TR_VL(unit)) {
   2836         if (!SOC_IS_HURRICANEX(unit) && ! SOC_IS_GREYHOUND(unit) &&
   2837             !SOC_IS_GREYHOUND2(unit)) {
   2838             return bcm_tr_cosq_gport_detach(unit, sched_gport,
   2839                                         input_gport, cosq);
   2840         }
   2841     }
   2842 #endif
   2843 #if defined(BCM_GREYHOUND2_SUPPORT)
   2844     if (SOC_IS_GREYHOUND2(unit)) {
   2845         return bcmi_gh2_cosq_gport_detach(unit, sched_gport, input_gport, cosq);
   2846     }
   2847 #endif /* BCM_GREYHOUND2_SUPPORT */
   2848     return BCM_E_UNAVAIL;
   2849 }
   2850 
   2851 /*
   2852  * Function:
   2853  *      bcm_cosq_gport_attach_get
   2854  * Purpose:
   2855  *
   2856  * Parameters:
   2857  *      unit       - (IN) Unit number.
   2858  *      sched_port - (IN) Scheduler GPORT ID.
   2859  *      input_port - (OUT) GPORT attached to.
   2860  *      cosq       - (OUT) COS queue attached to.
   2861  * Returns:
   2862  *      BCM_E_XXX
   2863  * Notes:
   2864  */
   2865 int
   2866 bcm_esw_cosq_gport_attach_get(int unit, bcm_gport_t sched_gport,
   2867                               bcm_gport_t *input_gport, bcm_cos_queue_t *cosq)
   2868 {
   2869     if (sched_gport == BCM_GPORT_INVALID) {
   2870         return (BCM_E_PORT);
   2871     }
   2872 #ifdef BCM_MONTEREY_SUPPORT
   2873     if (SOC_IS_MONTEREY(unit)) {
   2874         return bcm_mn_cosq_gport_attach_get(unit, sched_gport,
   2875                                             input_gport, cosq);
   2876     }
   2877 #endif /* BCM_MONTEREY_SUPPORT */
   2878 
   2879 #ifdef BCM_APACHE_SUPPORT
   2880     if (SOC_IS_APACHE(unit)) {
   2881         return bcm_ap_cosq_gport_attach_get(unit, sched_gport, 
   2882                                             input_gport, cosq);
   2883     }
   2884 #endif
   2885 
   2886 #ifdef BCM_TRIUMPH2_SUPPORT
   2887     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   2888         SOC_IS_VALKYRIE2(unit)) {
   2889         return bcm_tr2_cosq_gport_attach_get(unit, sched_gport, 
   2890                                             input_gport, cosq);
   2891     }
   2892 #endif
   2893 #if defined(BCM_TOMAHAWK3_SUPPORT)
   2894     if (SOC_IS_TOMAHAWK3(unit)) {
   2895         return bcm_th3_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2896                                             cosq);
   2897     }
   2898 #endif /* BCM_TOMAHAWK3_SUPPORT */
   2899 #if defined(BCM_TOMAHAWK_SUPPORT)
   2900     if (SOC_IS_TOMAHAWKX(unit)) {
   2901         return bcm_th_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2902                                             cosq);
   2903     }
   2904 #endif /* BCM_TOMAHAWK_SUPPORT */
   2905 #ifdef BCM_HELIX5_SUPPORT
   2906     if (SOC_IS_HELIX5(unit)) {
   2907         return bcm_hx5_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2908                                              cosq);
   2909     }
   2910 #endif /* BCM_HELIX5_SUPPORT */
   2911 #if defined(BCM_TRIDENT3_SUPPORT)
   2912     if (SOC_IS_TRIDENT3X(unit)) {
   2913         return bcm_td3_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2914                                              cosq);
   2915     }
   2916 #endif /* BCM_TRIDENT3_SUPPORT */
   2917 #if defined(BCM_TRIDENT2_SUPPORT)
   2918     if (SOC_IS_TD2_TT2(unit)) {
   2919         return bcm_td2_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2920                                             cosq);
   2921     }
   2922 #endif /* BCM_TRIDENT2_SUPPORT */
   2923 #if defined(BCM_TRIDENT_SUPPORT)
   2924     if (SOC_IS_TD_TT(unit)) {
   2925         return bcm_td_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2926                                             cosq);
   2927     }
   2928 #endif /* BCM_TRIDENT_SUPPORT */
   2929 #if defined(BCM_KATANA_SUPPORT)
   2930     if (SOC_IS_KATANA(unit)) {
   2931         return bcm_kt_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2932                                             cosq);
   2933     }
   2934 #endif /* BCM_KATANA_SUPPORT */
   2935 #if defined(BCM_KATANA2_SUPPORT)
   2936     if (SOC_IS_KATANA2(unit)) {
   2937         return bcm_kt2_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2938                                             cosq);
   2939     }
   2940 #endif /* BCM_KATANA2_SUPPORT */
   2941 #if defined(BCM_TRIUMPH3_SUPPORT)
   2942     if (SOC_IS_TRIUMPH3(unit)) {
   2943         return bcm_tr3_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2944                                             cosq);
   2945     }
   2946 #endif /* BCM_TRIUMPH3_SUPPORT */
   2947 #ifdef BCM_TRIUMPH_SUPPORT
   2948     if (SOC_IS_TR_VL(unit)) {
   2949         if (!SOC_IS_HURRICANEX(unit) && ! SOC_IS_GREYHOUND(unit) &&
   2950             !SOC_IS_GREYHOUND2(unit)) {
   2951             return bcm_tr_cosq_gport_attach_get(unit, sched_gport, 
   2952                                             input_gport, cosq);
   2953         }
   2954     }
   2955 #endif
   2956 #if defined(BCM_GREYHOUND2_SUPPORT)
   2957     if (SOC_IS_GREYHOUND2(unit)) {
   2958         return bcmi_gh2_cosq_gport_attach_get(unit, sched_gport, input_gport,
   2959                                               cosq);
   2960     }
   2961 #endif /* BCM_GREYHOUND2_SUPPORT */
   2962     return BCM_E_UNAVAIL;
   2963 }
   2964 
   2965 /*
   2966  * Function:
   2967  *      bcm_cosq_gport_child_get
   2968  * Purpose:
   2969  *
   2970  * Parameters:
   2971  *      unit       - (IN)  Unit number.
   2972  *      in_gport   - (IN)  Scheduler GPORT ID.
   2973  *      cosq       - (IN)  COS queue attached to.
   2974  *      out_gport  - (OUT) child GPORT ID.
   2975  * Returns:
   2976  *      BCM_E_XXX
   2977  * Notes:
   2978  */
   2979 int
   2980 bcm_esw_cosq_gport_child_get(int unit, bcm_gport_t in_gport,
   2981                               bcm_cos_queue_t cosq,
   2982                               bcm_gport_t *out_gport)
   2983 {
   2984     if (in_gport == BCM_GPORT_INVALID) {
   2985         return (BCM_E_PORT);
   2986     }
   2987 #ifdef BCM_TOMAHAWK3_SUPPORT
   2988     if (SOC_IS_TOMAHAWK3(unit)) {
   2989         return bcm_th3_cosq_gport_child_get(unit, in_gport,cosq,
   2990                                            out_gport);
   2991     }
   2992 #endif /* BCM_TOMAHAWK3_SUPPORT */
   2993 #ifdef BCM_TOMAHAWK_SUPPORT
   2994     if (SOC_IS_TOMAHAWKX(unit)) {
   2995         return bcm_th_cosq_gport_child_get(unit, in_gport,cosq,
   2996                                            out_gport);
   2997     }
   2998 #endif /* BCM_TOMAHAWK_SUPPORT */
   2999 
   3000 #ifdef BCM_MONTEREY_SUPPORT
   3001     if (SOC_IS_MONTEREY(unit)) {
   3002         return bcm_mn_cosq_gport_child_get(unit, in_gport,cosq,
   3003                                            out_gport);
   3004     }
   3005 #endif /* BCM_MONTEREY_SUPPORT */
   3006 
   3007 #ifdef BCM_HELIX5_SUPPORT
   3008     if (SOC_IS_HELIX5(unit)) {
   3009         return bcm_hx5_cosq_gport_child_get(unit, in_gport,cosq,
   3010                                             out_gport);
   3011     }
   3012 #endif /* BCM_HELIX5_SUPPORT */
   3013 
   3014 #ifdef BCM_TRIDENT3_SUPPORT
   3015     if (SOC_IS_TRIDENT3X(unit)) {
   3016         return bcm_td3_cosq_gport_child_get(unit, in_gport,cosq,
   3017                                             out_gport);
   3018     }
   3019 #endif /* BCM_TRIDENT3_SUPPORT */
   3020 #if defined(BCM_APACHE_SUPPORT)
   3021     if (SOC_IS_APACHE(unit)) {
   3022         return bcm_ap_cosq_gport_child_get(unit, in_gport,cosq,
   3023                                             out_gport);
   3024     }
   3025 #endif /* BCM_APACHE_SUPPORT */
   3026 #if defined(BCM_TRIDENT2_SUPPORT)
   3027     if (SOC_IS_TD2_TT2(unit)) {
   3028         return bcm_td2_cosq_gport_child_get(unit, in_gport,cosq,
   3029                                             out_gport);
   3030     }
   3031 #endif /* BCM_TRIDENT2_SUPPORT */
   3032 #if defined(BCM_GREYHOUND2_SUPPORT)
   3033     if (SOC_IS_GREYHOUND2(unit)) {
   3034         return bcmi_gh2_cosq_gport_child_get(unit, in_gport, cosq,
   3035                                              out_gport);
   3036     }
   3037 #endif /* BCM_GREYHOUND2_SUPPORT */
   3038 #ifdef BCM_TRIUMPH3_SUPPORT
   3039     if (SOC_IS_TRIUMPH3(unit)) {
   3040         return bcm_tr3_cosq_gport_child_get(unit, in_gport,cosq,
   3041                                             out_gport);
   3042     }
   3043 #endif /* BCM_TRIUMPH3_SUPPORT */
   3044     return BCM_E_UNAVAIL;
   3045 }
   3046 
   3047 /*
   3048  * Function:
   3049  *      bcm_cosq_gport_get
   3050  * Returns:
   3051  *      BCM_E_XXX
   3052  */
   3053 int 
   3054 bcm_esw_cosq_gport_get(
   3055     int unit, 
   3056     bcm_gport_t gport, 
   3057     bcm_gport_t *physical_port, 
   3058     int *num_cos_levels, 
   3059     uint32 *flags)
   3060 {
   3061 #ifdef BCM_MONTEREY_SUPPORT
   3062     if (SOC_IS_MONTEREY(unit)) {
   3063         return bcm_mn_cosq_gport_get(unit, gport, physical_port,
   3064                 num_cos_levels, flags); 
   3065     }
   3066 #endif /* BCM_MONTEREY_SUPPORT */
   3067 
   3068 #ifdef BCM_APACHE_SUPPORT
   3069     if (SOC_IS_APACHE(unit)) {
   3070         return bcm_ap_cosq_gport_get(unit, gport, physical_port,
   3071                 num_cos_levels, flags);
   3072     }
   3073 #endif
   3074 #ifdef BCM_TOMAHAWK3_SUPPORT
   3075     if (SOC_IS_TOMAHAWK3(unit)) {
   3076         return bcm_th3_cosq_gport_get(unit, gport, physical_port,
   3077                                      num_cos_levels, flags);
   3078     }
   3079 #endif /* BCM_TOMAHAWK_SUPPORT */
   3080 #ifdef BCM_TOMAHAWK_SUPPORT
   3081     if (SOC_IS_TOMAHAWKX(unit)) {
   3082         return bcm_th_cosq_gport_get(unit, gport, physical_port,
   3083                                      num_cos_levels, flags);
   3084     }
   3085 #endif /* BCM_TOMAHAWK_SUPPORT */
   3086 #ifdef BCM_HELIX5_SUPPORT
   3087     if (SOC_IS_HELIX5(unit)) {
   3088         return bcm_hx5_cosq_gport_get(unit, gport, physical_port,
   3089                                       num_cos_levels, flags);
   3090     }
   3091 #endif /* BCM_TRIDENT3_SUPPORT */
   3092 #ifdef BCM_TRIDENT3_SUPPORT
   3093     if (SOC_IS_TRIDENT3X(unit)) {
   3094         return bcm_td3_cosq_gport_get(unit, gport, physical_port,
   3095                                       num_cos_levels, flags);
   3096     }
   3097 #endif /* BCM_TRIDENT3_SUPPORT */
   3098 #ifdef BCM_TRIDENT2_SUPPORT
   3099     if (SOC_IS_TD2_TT2(unit)) {
   3100         return bcm_td2_cosq_gport_get(unit, gport, physical_port,
   3101                                      num_cos_levels, flags);
   3102     }
   3103 #endif /* BCM_TRIDENT2_SUPPORT */
   3104 #ifdef BCM_TRIDENT_SUPPORT
   3105     if (SOC_IS_TD_TT(unit)) {
   3106         return bcm_td_cosq_gport_get(unit, gport, physical_port,
   3107                                      num_cos_levels, flags);
   3108     }
   3109 #endif /* BCM_TRIDENT_SUPPORT */
   3110 #ifdef BCM_TRIUMPH3_SUPPORT
   3111     if (SOC_IS_TRIUMPH3(unit)) {
   3112         return bcm_tr3_cosq_gport_get(unit, gport, physical_port,
   3113                                      num_cos_levels, flags);
   3114     }
   3115 #endif /* BCM_TRIUMPH3_SUPPORT */
   3116 #ifdef BCM_KATANA_SUPPORT
   3117     if (SOC_IS_KATANA(unit)) {
   3118         return bcm_kt_cosq_gport_get(unit, gport, physical_port,
   3119                                      num_cos_levels, flags);
   3120     }
   3121 #endif /* BCM_KATANA_SUPPORT */
   3122 #ifdef BCM_KATANA2_SUPPORT
   3123     if (SOC_IS_KATANA2(unit)) {
   3124         return bcm_kt2_cosq_gport_get(unit, gport, physical_port,
   3125                                      num_cos_levels, flags);
   3126     }
   3127 #endif /* BCM_KATANA2_SUPPORT */
   3128 #ifdef BCM_GREYHOUND2_SUPPORT
   3129     if (SOC_IS_GREYHOUND2(unit)) {
   3130         return bcmi_gh2_cosq_gport_get(unit, gport, physical_port,
   3131                                        num_cos_levels, flags);
   3132     }
   3133 #endif /* BCM_GREYHOUND2_SUPPORT */
   3134     return BCM_E_UNAVAIL; 
   3135 }
   3136 
   3137 /*
   3138  * Function:
   3139  *      bcm_cosq_gport_size_set
   3140  * Returns:
   3141  *      BCM_E_XXX
   3142  */
   3143 int 
   3144 bcm_esw_cosq_gport_size_set(
   3145     int unit, 
   3146     bcm_gport_t gport, 
   3147     bcm_cos_queue_t cosq, 
   3148     uint32 bytes_min, 
   3149     uint32 bytes_max)
   3150 {
   3151     return BCM_E_UNAVAIL; 
   3152 }
   3153 
   3154 /*
   3155  * Function:
   3156  *      bcm_cosq_gport_size_get
   3157  * Returns:
   3158  *      BCM_E_XXX
   3159  */
   3160 int 
   3161 bcm_esw_cosq_gport_size_get(
   3162     int unit, 
   3163     bcm_gport_t gport, 
   3164     bcm_cos_queue_t cosq, 
   3165     uint32 *bytes_min, 
   3166     uint32 *bytes_max)
   3167 {
   3168     return BCM_E_UNAVAIL; 
   3169 }
   3170 
   3171 /*
   3172  * Function:
   3173  *      bcm_cosq_gport_enable_set
   3174  * Returns:
   3175  *      BCM_E_XXX
   3176  */
   3177 int 
   3178 bcm_esw_cosq_gport_enable_set(
   3179     int unit, 
   3180     bcm_gport_t gport, 
   3181     bcm_cos_queue_t cosq, 
   3182     int enable)
   3183 {
   3184     return BCM_E_UNAVAIL; 
   3185 }
   3186 
   3187 /*
   3188  * Function:
   3189  *      bcm_cosq_gport_enable_get
   3190  * Returns:
   3191  *      BCM_E_XXX
   3192  */
   3193 int 
   3194 bcm_esw_cosq_gport_enable_get(
   3195     int unit, 
   3196     bcm_gport_t gport, 
   3197     bcm_cos_queue_t cosq, 
   3198     int *enable)
   3199 {
   3200     return BCM_E_UNAVAIL; 
   3201 }
   3202 
   3203 /*
   3204  * Function:
   3205  *      bcm_cosq_gport_stat_enable_set
   3206  * Purpose:
   3207  *      ?
   3208  * Returns:
   3209  *      BCM_E_XXX
   3210  */
   3211 int 
   3212 bcm_esw_cosq_gport_stat_enable_set(
   3213     int unit, 
   3214     bcm_gport_t gport, 
   3215     int enable)
   3216 {
   3217     return BCM_E_UNAVAIL; 
   3218 }
   3219 
   3220 /*
   3221  * Function:
   3222  *      bcm_cosq_gport_stat_enable_get
   3223  * Returns:
   3224  *      BCM_E_XXX
   3225  */
   3226 int 
   3227 bcm_esw_cosq_gport_stat_enable_get(
   3228     int unit, 
   3229     bcm_gport_t gport, 
   3230     int *enable)
   3231 {
   3232     return BCM_E_UNAVAIL; 
   3233 }
   3234 
   3235 /*
   3236  * Function:
   3237  *      _bcm_esw_cosq_gport_stat_get
   3238  *      if sync_mode is set, sync the sw accumulated count
   3239  *      with hw count value first, else return sw count.  
   3240  *
   3241  *Parameters:
   3242  *      unit        - (IN) Unit number.
   3243  *      sync_mode   - (IN) hwcount is to be synced to sw count 
   3244  *      port        - (IN) GPORT ID.
   3245  *      cosq        - (IN) COS queue to configure
   3246  *      stat        - (IN) Statistic to be retrieved.
   3247  *      value       - (OUT) Returned statistic value.
   3248  * Returns:
   3249  *      BCM_E_XXX
   3250  */
   3251 int 
   3252 _bcm_esw_cosq_gport_stat_get(
   3253     int unit, 
   3254     int sync_mode,
   3255     bcm_gport_t gport, 
   3256     bcm_cos_queue_t cosq, 
   3257     bcm_cosq_gport_stats_t stat, 
   3258     uint64 *value)
   3259 {
   3260 #ifdef BCM_KATANA_SUPPORT
   3261     if (soc_feature(unit, soc_feature_cosq_gport_stat_ability)) {
   3262         return bcm_kt_cosq_gport_stat_get(unit, sync_mode, gport, cosq,
   3263                                           stat, value);
   3264     } 
   3265 #endif /* BCM_KATANA_SUPPORT */
   3266     return BCM_E_UNAVAIL; 
   3267 }
   3268 
   3269 
   3270 
   3271 /*
   3272  * Function:
   3273  *      bcm_esw_cosq_gport_stat_get
   3274  * Parameters:
   3275  *      unit  - (IN) Unit number
   3276  *      gport - (IN) GPORT ID
   3277  *      cosq  - (IN) COS queue.
   3278  *      stat  - (IN) Statistic to be retrieved.
   3279  *      value - (OUT) Returned statistic value.
   3280  * Returns:
   3281  *      BCM_E_XXX
   3282  */
   3283 int 
   3284 bcm_esw_cosq_gport_stat_get(
   3285     int unit, 
   3286     bcm_gport_t gport, 
   3287     bcm_cos_queue_t cosq, 
   3288     bcm_cosq_gport_stats_t stat, 
   3289     uint64 *value)
   3290 {
   3291 
   3292     return _bcm_esw_cosq_gport_stat_get(unit, 0, gport, cosq, stat, value);
   3293 
   3294 }    
   3295 
   3296 
   3297 /*
   3298  * Function:
   3299  *      bcm_esw_cosq_gport_stat_sync_get
   3300  *      sw accumulated counters synced with hw count.
   3301  * Parameters:
   3302  *      unit  - (IN) Unit number
   3303  *      gport - (IN) GPORT ID
   3304  *      cosq  - (IN) COS queue.
   3305  *      stat  - (IN) Statistic to be retrieved.
   3306  *      value - (OUT) Returned statistic value.
   3307  * Returns:
   3308  *      BCM_E_XXX
   3309  */
   3310 int 
   3311 bcm_esw_cosq_gport_stat_sync_get(
   3312     int unit, 
   3313     bcm_gport_t gport, 
   3314     bcm_cos_queue_t cosq, 
   3315     bcm_cosq_gport_stats_t stat, 
   3316     uint64 *value)
   3317 {
   3318 
   3319     return _bcm_esw_cosq_gport_stat_get(unit, 1, gport, cosq, stat, value);
   3320 
   3321 }    
   3322 
   3323 
   3324 /*
   3325  * Function:
   3326  *      bcm_cosq_gport_stat_set
   3327  * Returns:
   3328  *      BCM_E_XXX
   3329  */
   3330 int 
   3331 bcm_esw_cosq_gport_stat_set(
   3332     int unit, 
   3333     bcm_gport_t gport, 
   3334     bcm_cos_queue_t cosq, 
   3335     bcm_cosq_gport_stats_t stat, 
   3336     uint64 value)
   3337 {
   3338 #ifdef BCM_KATANA_SUPPORT
   3339     if (soc_feature(unit, soc_feature_cosq_gport_stat_ability)) {
   3340         return bcm_kt_cosq_gport_stat_set(unit, gport, cosq,
   3341                                           stat, value);
   3342     } 
   3343 #endif /* BCM_KATANA_SUPPORT */
   3344     return BCM_E_UNAVAIL; 
   3345 }
   3346 
   3347 /*
   3348  * Function:
   3349  *      bcm_esw_cosq_control_set
   3350  * Purpose:
   3351  *      Set specified feature configuration
   3352  *
   3353  * Parameters:
   3354  *      unit - (IN) Unit number.
   3355  *      port - (IN) GPORT ID.
   3356  *      cosq - (IN) COS queue.
   3357  *      type - (IN) feature
   3358  *      arg  - (IN) feature value
   3359  * Returns:
   3360  *      BCM_E_XXX
   3361  * Notes:
   3362  */
   3363 int
   3364 bcm_esw_cosq_control_set(int unit, bcm_gport_t gport, bcm_cos_queue_t cosq,
   3365                          bcm_cosq_control_t type, int arg)
   3366 {
   3367     uint32 kbits_sec_min, kbits_sec_max, kbits_sec_burst;
   3368     uint32 kbits_burst, flags;
   3369     bcm_pbmp_t pbmp;
   3370     bcm_port_t port;
   3371     bcm_cos_queue_t start_cos, end_cos, loc_cos;
   3372     uint32 cm_val, ocm_val, cmc1_val, ocmc1_val;
   3373     uint64 cmc_val64, ocmc_val64, mask64;
   3374     int num_cos = NUM_COS(unit);
   3375     uint32 kbits_burst_min, kbits_burst_max;
   3376 #if defined(BCM_HURRICANE2_SUPPORT)
   3377     soc_reg_t select_reg[8] = { \
   3378         EEE_PROFILE_SEL_0r, EEE_PROFILE_SEL_1r, \
   3379         EEE_PROFILE_SEL_2r, EEE_PROFILE_SEL_3r, \
   3380         EEE_PROFILE_SEL_4r, EEE_PROFILE_SEL_5r, \
   3381         EEE_PROFILE_SEL_6r, EEE_PROFILE_SEL_7r};
   3382 #endif /* BCM_HURRICANE2_SUPPORT */
   3383 
   3384     kbits_burst_min = 0;
   3385     kbits_burst_max = 0;
   3386 
   3387     COMPILER_REFERENCE(kbits_burst_min);
   3388     COMPILER_REFERENCE(kbits_burst_max);
   3389     
   3390 #ifdef BCM_TOMAHAWK3_SUPPORT
   3391         if (SOC_IS_TOMAHAWK3(unit)) {
   3392             return bcm_th3_cosq_control_set(unit, gport, cosq,
   3393                 BCM_COSQ_BUFFER_ID_INVALID, type, arg);
   3394         }
   3395 #endif /* BCM_TOMAHAWK3_SUPPORT */
   3396 #ifdef BCM_TOMAHAWK_SUPPORT
   3397         if (SOC_IS_TOMAHAWKX(unit)) {
   3398             return bcm_th_cosq_control_set(unit, gport, cosq,
   3399                 BCM_COSQ_BUFFER_ID_INVALID, type, arg);
   3400         }
   3401 #endif /* BCM_TOMAHAWK_SUPPORT */
   3402 #ifdef BCM_HELIX5_SUPPORT
   3403     if (SOC_IS_HELIX5(unit)) {
   3404         return (bcm_hx5_cosq_control_set(unit, gport, cosq, type, arg));
   3405     }
   3406 #endif /* BCM_HELIX5_SUPPORT */
   3407 #ifdef BCM_TRIDENT3_SUPPORT
   3408         if (SOC_IS_TRIDENT3X(unit)) {
   3409             return (bcm_td3_cosq_control_set(unit, gport, cosq, type, arg));
   3410         }
   3411 #endif /* BCM_TRIDENT3_SUPPORT */
   3412 
   3413     switch (type) {
   3414     case bcmCosqControlBandwidthBurstMax:
   3415         kbits_burst = arg & 0x7fffffff; /* Convert to uint32  */
   3416 #ifdef BCM_MONTEREY_SUPPORT
   3417     if (SOC_IS_MONTEREY(unit)) {
   3418         BCM_IF_ERROR_RETURN
   3419                 (bcm_mn_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3420                                                        &kbits_burst_min,
   3421                                                        &kbits_burst_max));
   3422             return bcm_mn_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3423                                                          kbits_burst_min,
   3424                                                          kbits_burst); 
   3425     }
   3426 #endif /* BCM_MONTEREY_SUPPORT */
   3427 
   3428 #ifdef BCM_APACHE_SUPPORT
   3429         if (SOC_IS_APACHE(unit)) {
   3430             BCM_IF_ERROR_RETURN
   3431                 (bcm_ap_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3432                                                        &kbits_burst_min,
   3433                                                        &kbits_burst_max));
   3434             return bcm_ap_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3435                                                          kbits_burst_min,
   3436                                                          kbits_burst);
   3437         }
   3438 #endif /* BCM_APACHE_SUPPORT */
   3439 #ifdef BCM_TRIUMPH2_SUPPORT
   3440         if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   3441             SOC_IS_VALKYRIE2(unit)) {
   3442             BCM_IF_ERROR_RETURN(
   3443                 bcm_tr2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3444                                       &kbits_burst_min, &kbits_burst_max));
   3445             return bcm_tr2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3446                                               kbits_burst_min, kbits_burst);
   3447         }
   3448 #endif  
   3449 #ifdef BCM_TRIUMPH3_SUPPORT
   3450         if (SOC_IS_TRIUMPH3(unit)) {
   3451             BCM_IF_ERROR_RETURN(
   3452                 bcm_tr3_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3453                                       &kbits_burst_min, &kbits_burst_max));
   3454             return bcm_tr3_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3455                                               kbits_burst_min, kbits_burst);
   3456         }
   3457 #endif /* BCM_TRIUMPH3_SUPPORT */
   3458 #ifdef BCM_TRIDENT2_SUPPORT
   3459         if (SOC_IS_TD2_TT2(unit)) {
   3460             BCM_IF_ERROR_RETURN(
   3461                 bcm_td2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3462                                       &kbits_burst_min, &kbits_burst_max));
   3463             return bcm_td2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3464                                                 kbits_burst_min, kbits_burst);
   3465         }
   3466 #endif /* BCM_TRIDENT2_SUPPORT */
   3467 #ifdef BCM_TRIDENT_SUPPORT
   3468         if (SOC_IS_TD_TT(unit)) {
   3469             BCM_IF_ERROR_RETURN(
   3470                 bcm_td_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3471                                       &kbits_burst_min, &kbits_burst_max));
   3472             return bcm_td_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3473                                                 kbits_burst_min, kbits_burst);
   3474         }
   3475 #endif /* BCM_TRIDENT_SUPPORT */
   3476 #ifdef BCM_KATANA_SUPPORT
   3477         if (SOC_IS_KATANA(unit)) {
   3478             BCM_IF_ERROR_RETURN
   3479                 (bcm_kt_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3480                                                        &kbits_burst_min,
   3481                                                        &kbits_burst_max));
   3482             return bcm_kt_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3483                                                          kbits_burst_min,
   3484                                                          kbits_burst);
   3485         }
   3486 #endif /* BCM_KATANA_SUPPORT */
   3487 #ifdef BCM_KATANA2_SUPPORT
   3488         if (SOC_IS_KATANA2(unit)) {
   3489             BCM_IF_ERROR_RETURN
   3490                 (bcm_kt2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3491                                                        &kbits_burst_min,
   3492                                                        &kbits_burst_max));
   3493             return bcm_kt2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3494                                                          kbits_burst_min,
   3495                                                          kbits_burst);
   3496         }
   3497 #endif /* BCM_KATANA2_SUPPORT */
   3498 #ifdef BCM_TRIUMPH_SUPPORT
   3499         if (SOC_IS_TR_VL(unit)) {
   3500 #if defined(BCM_HURRICANE_SUPPORT)
   3501             if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
   3502                 return bcm_hu_cosq_gport_bandwidth_burst_set(unit, gport,
   3503                                                               cosq, kbits_burst);                
   3504             } else    
   3505 #endif /* BCM_HURRICANE_SUPPORT*/
   3506 #if defined(BCM_GREYHOUND2_SUPPORT)
   3507             if (SOC_IS_GREYHOUND2(unit)) {
   3508                 return bcmi_gh2_cosq_gport_bandwidth_burst_set(unit, gport,
   3509                                                                cosq,
   3510                                                                kbits_burst);
   3511             } else
   3512 #endif /* BCM_GREYHOUND2_SUPPORT */
   3513             {
   3514                 BCM_IF_ERROR_RETURN(
   3515                     bcm_tr_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3516                                           &kbits_burst_min, &kbits_burst_max));
   3517                 return bcm_tr_cosq_gport_bandwidth_burst_set(unit, gport, cosq, 
   3518                                                   kbits_burst_min , kbits_burst);
   3519             }
   3520         }
   3521 #endif  
   3522         if (gport < 0) {
   3523             BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
   3524         } else {
   3525             /* Must use local ports on legacy devices */
   3526             BCM_IF_ERROR_RETURN
   3527                 (bcm_esw_port_local_get(unit, gport, &port));
   3528             if (SOC_PORT_VALID(unit, port)) {
   3529                 BCM_PBMP_PORT_SET(pbmp, port);
   3530             } else {
   3531                 return BCM_E_PORT;
   3532             }
   3533         }
   3534 
   3535         if (cosq < 0) {
   3536             start_cos = 0;
   3537             end_cos = NUM_COS(unit) - 1;
   3538         } else {
   3539             if (cosq < NUM_COS(unit)) {
   3540                 start_cos = end_cos = cosq;
   3541             } else {
   3542                 return BCM_E_PARAM;
   3543             }
   3544         }
   3545 
   3546         BCM_PBMP_ITER(pbmp, port) {
   3547             for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
   3548                 BCM_IF_ERROR_RETURN
   3549                     (mbcm_driver[unit]->
   3550                      mbcm_cosq_port_bandwidth_get(unit, port, loc_cos,
   3551                                                   &kbits_sec_min,
   3552                                                   &kbits_sec_max,
   3553                                                   &kbits_sec_burst, &flags));
   3554                 BCM_IF_ERROR_RETURN
   3555                     (mbcm_driver[unit]->
   3556                      mbcm_cosq_port_bandwidth_set(unit, port, loc_cos,
   3557                                                   kbits_sec_min,
   3558                                                   kbits_sec_max,
   3559                                                   kbits_burst, flags));
   3560             }
   3561         }
   3562         return BCM_E_NONE;
   3563 
   3564     case bcmCosqControlBandwidthBurstMin:
   3565         kbits_burst = arg & 0x7fffffff; /* Convert to uint32  */
   3566 #ifdef BCM_MONTEREY_SUPPORT
   3567     if (SOC_IS_MONTEREY(unit)) {
   3568         BCM_IF_ERROR_RETURN
   3569                 (bcm_mn_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3570                                                        &kbits_burst_min,
   3571                                                        &kbits_burst_max));
   3572             return bcm_mn_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3573                                                          kbits_burst,
   3574                                                          kbits_burst_max);
   3575     }
   3576 #endif /* BCM_MONTEREY_SUPPORT */
   3577 
   3578 #ifdef BCM_APACHE_SUPPORT
   3579         if (SOC_IS_APACHE(unit)) {
   3580             BCM_IF_ERROR_RETURN
   3581                 (bcm_ap_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3582                                                        &kbits_burst_min,
   3583                                                        &kbits_burst_max));
   3584             return bcm_ap_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3585                                                          kbits_burst,
   3586                                                          kbits_burst_max);
   3587         } else 
   3588 #endif /* BCM_APACHE_SUPPORT */
   3589 #ifdef BCM_KATANA_SUPPORT
   3590         if (SOC_IS_KATANA(unit)) {
   3591             BCM_IF_ERROR_RETURN
   3592                 (bcm_kt_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3593                                                        &kbits_burst_min,
   3594                                                        &kbits_burst_max));
   3595             return bcm_kt_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3596                                                          kbits_burst,
   3597                                                          kbits_burst_max);
   3598         } else
   3599 #endif /* BCM_KATANA_SUPPORT */
   3600 #ifdef BCM_KATANA2_SUPPORT
   3601         if (SOC_IS_KATANA2(unit)) {
   3602             BCM_IF_ERROR_RETURN
   3603                 (bcm_kt2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3604                                                        &kbits_burst_min,
   3605                                                        &kbits_burst_max));
   3606             return bcm_kt2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3607                                                          kbits_burst,
   3608                                                          kbits_burst_max);
   3609         } else
   3610 #endif /* BCM_KATANA2_SUPPORT */
   3611 #ifdef BCM_TRIUMPH2_SUPPORT
   3612         if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   3613             SOC_IS_VALKYRIE2(unit)) {
   3614             BCM_IF_ERROR_RETURN(
   3615                 bcm_tr2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3616                                       &kbits_burst_min, &kbits_burst_max));
   3617             return bcm_tr2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3618                                               kbits_burst, kbits_burst_max);
   3619         } else
   3620 #endif  
   3621 #ifdef BCM_TRIUMPH3_SUPPORT
   3622         if (SOC_IS_TRIUMPH3(unit)) {
   3623             BCM_IF_ERROR_RETURN(
   3624                 bcm_tr3_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3625                                       &kbits_burst_min, &kbits_burst_max));
   3626             return bcm_tr3_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3627                                       kbits_burst, kbits_burst_max);
   3628         } else
   3629 #endif /* BCM_TRIUMPH3_SUPPORT */
   3630 #ifdef BCM_TRIDENT2_SUPPORT
   3631         if (SOC_IS_TD2_TT2(unit)) {
   3632             BCM_IF_ERROR_RETURN(
   3633                 bcm_td2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3634                                       &kbits_burst_min, &kbits_burst_max));
   3635             return bcm_td2_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3636                                         kbits_burst, kbits_burst_max);
   3637         } else
   3638 #endif /* BCM_TRIDENT2_SUPPORT */
   3639 #ifdef BCM_TRIDENT_SUPPORT
   3640         if (SOC_IS_TD_TT(unit)) {
   3641             BCM_IF_ERROR_RETURN(
   3642                 bcm_td_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3643                                       &kbits_burst_min, &kbits_burst_max));
   3644             return bcm_td_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3645                                         kbits_burst, kbits_burst_max);
   3646         } else
   3647 #endif /* BCM_TRIDENT_SUPPORT */
   3648 #ifdef BCM_TRIUMPH_SUPPORT
   3649         if (SOC_IS_TR_VL(unit)) {
   3650 #if defined(BCM_HURRICANE_SUPPORT)
   3651             /* coverity[dead_error_begin : FALSE] */
   3652             if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
   3653                SOC_IS_GREYHOUND2(unit)) {
   3654              /*need to support later*/
   3655               return BCM_E_UNAVAIL;
   3656             } else
   3657 #endif /* BCM_HURRICANE_SUPPORT*/
   3658             {
   3659                 BCM_IF_ERROR_RETURN(
   3660                     bcm_tr_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   3661                                           &kbits_burst_min, &kbits_burst_max));
   3662                 return bcm_tr_cosq_gport_bandwidth_burst_set(unit, gport, cosq,
   3663                                                   kbits_burst, kbits_burst_max);
   3664             }
   3665         } else
   3666 #endif /* BCM_TRIUMPH_SUPPORT */
   3667         return BCM_E_UNAVAIL;
   3668 
   3669     case bcmCosqControlSchedulable:
   3670         if (!soc_reg_field_valid(unit, COSMASKr, COSMASKf)) {
   3671             return BCM_E_UNAVAIL;
   3672         }
   3673 
   3674         if (gport < 0) {
   3675             BCM_PBMP_ASSIGN(pbmp, PBMP_ALL(unit));
   3676         } else {
   3677             /* Must use local ports on legacy devices */
   3678             BCM_IF_ERROR_RETURN
   3679                 (bcm_esw_port_local_get(unit, gport, &port));
   3680             if (SOC_PORT_VALID(unit, port)) {
   3681                 BCM_PBMP_PORT_SET(pbmp, port);
   3682             } else {
   3683                 return BCM_E_PORT;
   3684             }
   3685         }
   3686         
   3687         if (BCM_PBMP_MEMBER(pbmp, CMIC_PORT(unit))) {
   3688             
   3689             if (soc_reg_field_valid(unit, COSMASK_CPU1r, COSMASKf)) {
   3690                 if (cosq < 0) {
   3691                     start_cos = 0;
   3692                     end_cos = 31; 
   3693                 } else {
   3694                     if (cosq < 32) {
   3695                         start_cos = end_cos = cosq;
   3696                     } else {
   3697                         return BCM_E_PARAM;
   3698                     }
   3699                 }
   3700                 port = CMIC_PORT(unit);
   3701                 BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
   3702                 BCM_IF_ERROR_RETURN
   3703                     (READ_COSMASK_CPU1r(unit, &cmc1_val));
   3704                 ocm_val = cm_val;
   3705                 ocmc1_val = cmc1_val;
   3706                 for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
   3707                     if (loc_cos < 10) {
   3708                         if (arg) {
   3709                             cm_val &= ~(1 << loc_cos);
   3710                         } else {
   3711                             cm_val |= (1 << loc_cos);
   3712                         }
   3713                     } else {
   3714                         if (arg) {
   3715                             cmc1_val &= ~(1 << loc_cos);
   3716                         } else {
   3717                             cmc1_val |= (1 << loc_cos);
   3718                         }
   3719                     }
   3720                 }
   3721                 if (ocm_val != cm_val) {
   3722                     BCM_IF_ERROR_RETURN(WRITE_COSMASKr(unit, port, cm_val));
   3723                 }
   3724                 if (ocmc1_val != cmc1_val) {
   3725                     BCM_IF_ERROR_RETURN
   3726                         (WRITE_COSMASK_CPU1r(unit, cmc1_val));
   3727                 }
   3728                 
   3729                 BCM_PBMP_PORT_REMOVE(pbmp, CMIC_PORT(unit));
   3730             } else if (soc_reg_field_valid(unit, COSMASK_CPUr, COSMASKf)) {
   3731                 if (cosq < 0) {
   3732                     start_cos = 0;
   3733                     end_cos = 47; 
   3734                 } else {
   3735                     if (cosq < 48) {
   3736                         start_cos = end_cos = cosq;
   3737                     } else {
   3738                         return BCM_E_PARAM;
   3739                     }
   3740                 }
   3741 
   3742                 BCM_IF_ERROR_RETURN
   3743                     (READ_COSMASK_CPUr(unit, &cmc_val64));
   3744                 ocmc_val64 = cmc_val64;
   3745 
   3746                 for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
   3747                     COMPILER_64_MASK_CREATE(mask64, 1, loc_cos);
   3748                     if (arg) {
   3749                         COMPILER_64_NOT(mask64);
   3750                         COMPILER_64_AND(cmc_val64, mask64);
   3751                     } else {
   3752                         COMPILER_64_OR(cmc_val64, mask64);
   3753                     }
   3754                 }
   3755 
   3756                 if (COMPILER_64_NE(ocmc_val64, cmc_val64)) {
   3757                     BCM_IF_ERROR_RETURN
   3758                         (WRITE_COSMASK_CPUr(unit, cmc_val64));
   3759                 }
   3760 
   3761                 BCM_PBMP_PORT_REMOVE(pbmp, CMIC_PORT(unit));
   3762             } else {
   3763                 /* Handle below */
   3764                 num_cos = 10; /* CMIC has more COS queues */
   3765             }
   3766         }
   3767 
   3768         if (BCM_PBMP_IS_NULL(pbmp)) {
   3769             /* Done */
   3770             return BCM_E_NONE;
   3771         }
   3772 
   3773         if (cosq < 0) {
   3774             start_cos = 0;
   3775             end_cos = num_cos - 1;
   3776         } else {
   3777             if (cosq < num_cos) {
   3778                 start_cos = end_cos = cosq;
   3779             } else {
   3780                 return BCM_E_PARAM;
   3781             }
   3782         }
   3783 
   3784         BCM_PBMP_ITER(pbmp, port) {
   3785             BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
   3786             ocm_val = cm_val;
   3787             for (loc_cos = start_cos; loc_cos <= end_cos; loc_cos++) {
   3788                 if (arg) {
   3789                     /*
   3790                      * COVERITY
   3791                      *
   3792                      * Max left shift of only 10.
   3793                      * This code is intentional.
   3794                      */
   3795                     /* coverity[large_shift] */
   3796                     cm_val &= ~(1 << loc_cos);
   3797                 } else {
   3798                     /*
   3799                      * COVERITY
   3800                      *
   3801                      * Max left shift of only 10.
   3802                      * This code is intentional.
   3803                      */
   3804                     /* coverity[large_shift] */
   3805                     cm_val |= (1 << loc_cos);
   3806                 }
   3807             }
   3808             if (ocm_val != cm_val) {
   3809                 BCM_IF_ERROR_RETURN(WRITE_COSMASKr(unit, port, cm_val));
   3810             }
   3811         }
   3812         return BCM_E_NONE;
   3813 
   3814     case bcmCosqControlCongestionManagedQueue:
   3815         if (soc_feature(unit, soc_feature_qcn)) {
   3816 #if defined(BCM_APACHE_SUPPORT)
   3817             if (SOC_IS_APACHE(unit)) {
   3818                 return bcm_ap_cosq_congestion_queue_set(unit, gport, cosq, arg);
   3819             }
   3820 #endif
   3821 #if defined(BCM_TRIDENT2_SUPPORT)
   3822             if (SOC_IS_TD2_TT2(unit)) {
   3823                 return bcm_td2_cosq_congestion_queue_set(unit, gport, cosq, arg);
   3824             }
   3825 #endif
   3826 #if defined(BCM_TRIDENT_SUPPORT)
   3827             if (SOC_IS_TD_TT(unit)) {
   3828                 return bcm_td_cosq_congestion_queue_set(unit, gport, cosq, arg);
   3829             }
   3830 #endif
   3831 #if defined(BCM_TRIUMPH3_SUPPORT)
   3832             if (SOC_IS_TRIUMPH3(unit)) {
   3833                 return bcm_tr3_cosq_congestion_queue_set(unit, gport, cosq, arg);
   3834             }
   3835 #endif
   3836         }
   3837         break;
   3838     case bcmCosqControlCongestionFeedbackWeight:
   3839         if (soc_feature(unit, soc_feature_qcn)) {
   3840 #if defined(BCM_APACHE_SUPPORT)
   3841             if (SOC_IS_APACHE(unit)) {
   3842                 return bcm_ap_cosq_congestion_quantize_set(unit, gport, cosq, arg,
   3843                                                        -1);
   3844             }
   3845 #endif 
   3846 
   3847 #if defined(BCM_TRIDENT2_SUPPORT)
   3848             if (SOC_IS_TD2_TT2(unit)) {
   3849                 return bcm_td2_cosq_congestion_quantize_set(unit, gport, cosq, arg,
   3850                                                        -1);
   3851             }
   3852 #endif
   3853 #if defined(BCM_TRIDENT_SUPPORT)
   3854             if (SOC_IS_TD_TT(unit)) {
   3855                 return bcm_td_cosq_congestion_quantize_set(unit, gport, cosq, arg,
   3856                                                        -1);
   3857             }
   3858 #endif
   3859 #if defined(BCM_TRIUMPH3_SUPPORT)
   3860             if (SOC_IS_TRIUMPH3(unit)) {
   3861                 return bcm_tr3_cosq_congestion_quantize_set(unit, gport, 
   3862                                                                 cosq, arg, -1);
   3863             }
   3864 #endif
   3865         }
   3866         break;
   3867     case bcmCosqControlCongestionSetPoint:
   3868         if (soc_feature(unit, soc_feature_qcn)) {
   3869 #if defined(BCM_APACHE_SUPPORT)
   3870             if (SOC_IS_APACHE(unit)) {
   3871                 return bcm_ap_cosq_congestion_quantize_set(unit, gport, cosq, -1,
   3872                                                        arg);
   3873             }
   3874 #endif 
   3875 #if defined(BCM_TRIDENT2_SUPPORT)
   3876             if (SOC_IS_TD2_TT2(unit)) {
   3877                 return bcm_td2_cosq_congestion_quantize_set(unit, gport, cosq, -1,
   3878                                                        arg);
   3879             }
   3880 #endif
   3881 #if defined(BCM_TRIDENT_SUPPORT)
   3882             if (SOC_IS_TD_TT(unit)) {
   3883                 return bcm_td_cosq_congestion_quantize_set(unit, gport, cosq, -1,
   3884                                                        arg);
   3885             }
   3886 #endif
   3887 #if defined(BCM_TRIUMPH3_SUPPORT)
   3888             if (SOC_IS_TRIUMPH3(unit)) {
   3889                 return bcm_tr3_cosq_congestion_quantize_set(unit, gport, cosq, -1,
   3890                                                        arg);
   3891             }
   3892 #endif
   3893         }
   3894         break;
   3895     case bcmCosqControlCongestionSampleBytesMin:
   3896         if (soc_feature(unit, soc_feature_qcn)) {
   3897 #if defined(BCM_APACHE_SUPPORT)
   3898             if (SOC_IS_APACHE(unit)) {
   3899                 return bcm_ap_cosq_congestion_sample_int_set(unit, gport, cosq,
   3900                                                          arg, -1);
   3901             }
   3902 #endif 
   3903 #if defined(BCM_TRIDENT2_SUPPORT)
   3904             if (SOC_IS_TD2_TT2(unit)) {
   3905                 return bcm_td2_cosq_congestion_sample_int_set(unit, gport, cosq,
   3906                                                          arg, -1);
   3907             }
   3908 #endif
   3909 #if defined(BCM_TRIDENT_SUPPORT)
   3910             if (SOC_IS_TD_TT(unit)) {
   3911                 return bcm_td_cosq_congestion_sample_int_set(unit, gport, cosq,
   3912                                                          arg, -1);
   3913             }
   3914 #endif
   3915 #if defined(BCM_TRIUMPH3_SUPPORT)
   3916             if (SOC_IS_TRIUMPH3(unit)) {
   3917                 return bcm_tr3_cosq_congestion_sample_int_set(unit, gport, cosq,
   3918                                                          arg, -1);
   3919             }
   3920 #endif
   3921         }
   3922         break;
   3923     case bcmCosqControlCongestionSampleBytesMax:
   3924         if (soc_feature(unit, soc_feature_qcn)) {
   3925 #if defined(BCM_APACHE_SUPPORT)
   3926             if (SOC_IS_APACHE(unit)) {
   3927                 return bcm_ap_cosq_congestion_sample_int_set(unit, gport, cosq,
   3928                                                          -1, arg);
   3929             }
   3930 #endif
   3931 #if defined(BCM_TRIDENT2_SUPPORT)
   3932             if (SOC_IS_TD2_TT2(unit)) {
   3933                 return bcm_td2_cosq_congestion_sample_int_set(unit, gport, cosq,
   3934                                                          -1, arg);
   3935             }
   3936 #endif
   3937 #if defined(BCM_TRIDENT_SUPPORT)
   3938             if (SOC_IS_TD_TT(unit)) {
   3939                 return bcm_td_cosq_congestion_sample_int_set(unit, gport, cosq,
   3940                                                          -1, arg);
   3941             }
   3942 #endif
   3943 #if defined(BCM_TRIUMPH3_SUPPORT)
   3944             if (SOC_IS_TRIUMPH3(unit)) {
   3945                 return bcm_tr3_cosq_congestion_sample_int_set(unit, gport, cosq,
   3946                                                          -1, arg);
   3947             }
   3948 #endif
   3949         }
   3950         break;
   3951 
   3952     case bcmCosqControlCongestionProxy:
   3953         if (!SOC_REG_IS_VALID(unit, QCN_CNM_PRP_CTRLr)) {
   3954             return BCM_E_UNAVAIL;
   3955         }
   3956         
   3957 #if defined(BCM_TRIDENT2_SUPPORT)
   3958         if (SOC_IS_TD2_TT2(unit)) {
   3959             return bcm_td2_cosq_control_set(unit, gport, cosq, type, arg);
   3960         }
   3961 #endif
   3962 
   3963 #if defined(BCM_TRIUMPH3_SUPPORT)
   3964         if (SOC_IS_TRIUMPH3(unit)) {
   3965             return bcm_tr3_cosq_control_set(unit, gport, cosq, type, arg);
   3966         }
   3967 #endif
   3968         break;
   3969 
   3970     case bcmCosqControlEgressPool:
   3971     case bcmCosqControlEgressPoolLimitBytes:
   3972     case bcmCosqControlEgressPoolYellowLimitBytes:
   3973     case bcmCosqControlEgressPoolRedLimitBytes:
   3974     case bcmCosqControlEgressPoolLimitEnable:
   3975     case bcmCosqControlEgressUCQueueMinLimitBytes:
   3976     case bcmCosqControlEgressUCQueueSharedLimitBytes:
   3977     case bcmCosqControlEgressUCQueueLimitEnable:
   3978     case bcmCosqControlEgressUCQueueColorLimitEnable:
   3979     case bcmCosqControlEgressUCSharedDynamicEnable:        
   3980     case bcmCosqControlEgressMCQueueSharedLimitBytes:
   3981     case bcmCosqControlEgressMCQueueMinLimitBytes:
   3982     case bcmCosqControlEgressMCSharedDynamicEnable:
   3983     case bcmCosqControlEgressMCQueueLimitEnable:
   3984     case bcmCosqControlEgressMCQueueColorLimitEnable:
   3985     case bcmCosqControlIngressPortPGSharedLimitBytes:
   3986     case bcmCosqControlIngressPortPoolMaxLimitBytes:
   3987     case bcmCosqControlIngressPortPGSharedDynamicEnable:
   3988     case bcmCosqControlIngressPortPoolMinLimitBytes:
   3989     case bcmCosqControlDropLimitAlpha:
   3990     case bcmCosqControlUCDropLimitAlpha:
   3991     case bcmCosqControlMCDropLimitAlpha:
   3992     case bcmCosqControlIngressPool:
   3993     case bcmCosqControlEgressPortPoolYellowLimitBytes:
   3994     case bcmCosqControlEgressPortPoolRedLimitBytes:
   3995     case bcmCosqControlUCEgressPool:
   3996     case bcmCosqControlMCEgressPool:
   3997     case bcmCosqControlIngressPoolLimitBytes:    
   3998     case bcmCosqControlIngressPortPGHeadroomLimitBytes:
   3999     case bcmCosqControlIngressPortPGResetFloorBytes:
   4000     case bcmCosqControlEgressPoolSharedLimitBytes: 
   4001     case bcmCosqControlEgressPoolResumeLimitBytes:
   4002     case bcmCosqControlEgressPoolYellowSharedLimitBytes: 
   4003     case bcmCosqControlEgressPoolYellowResumeLimitBytes:
   4004     case bcmCosqControlEgressPoolRedSharedLimitBytes:
   4005     case bcmCosqControlEgressPoolRedResumeLimitBytes:
   4006     case bcmCosqControlEgressUCQueueGroupMinEnable:
   4007     case bcmCosqControlEgressUCQueueGroupSharedLimitEnable:
   4008     case bcmCosqControlEgressUCQueueGroupMinLimitBytes:
   4009     case bcmCosqControlEgressUCQueueGroupSharedLimitBytes:
   4010     case bcmCosqControlEgressUCQueueGroupSharedDynamicEnable:
   4011     case bcmCosqControlEgressUCQueueGroupDropLimitAlpha:
   4012     case bcmCosqControlObmDiscardLimit:
   4013     case bcmCosqControlObmMinLimit:
   4014     case bcmCosqControlEgressUCQueueColorLimitDynamicEnable:
   4015     case bcmCosqControlEgressMCQueueColorLimitDynamicEnable:
   4016     case bcmCosqControlEgressUCQueueRedLimit:
   4017     case bcmCosqControlEgressUCQueueYellowLimit:
   4018     case bcmCosqControlEgressMCQueueRedLimit:
   4019     case bcmCosqControlEgressMCQueueYellowLimit:
   4020 #ifdef BCM_MONTEREY_SUPPORT
   4021     if (SOC_IS_MONTEREY(unit)) {
   4022         return bcm_mn_cosq_control_set(unit, gport, cosq, type, arg); 
   4023     }
   4024 #endif /* BCM_MONTEREY_SUPPORT */
   4025 #if defined(BCM_APACHE_SUPPORT)
   4026         if (SOC_IS_APACHE(unit)) {
   4027             return bcm_ap_cosq_control_set(unit, gport, cosq, type, arg);
   4028         }
   4029 #endif
   4030 #if defined(BCM_TRIDENT2_SUPPORT)
   4031         if (SOC_IS_TD2_TT2(unit)) {
   4032             return bcm_td2_cosq_control_set(unit, gport, cosq, type, arg);
   4033         }
   4034 #endif
   4035 #if defined(BCM_TRIDENT_SUPPORT)
   4036         if (SOC_IS_TD_TT(unit)) {
   4037             return bcm_td_cosq_control_set(unit, gport, cosq, type, arg);
   4038         }
   4039 #endif
   4040 #if defined(BCM_TRIUMPH3_SUPPORT)
   4041         if (SOC_IS_TRIUMPH3(unit)) {
   4042             return bcm_tr3_cosq_control_set(unit, gport, cosq, type, arg);
   4043         }
   4044 #endif
   4045 #if defined(BCM_KATANA2_SUPPORT)
   4046         if (SOC_IS_KATANA2(unit)) {
   4047             return bcm_kt2_cosq_control_set(unit, gport, cosq, type, arg);
   4048         }
   4049 #endif /* BCM_KATANA2_SUPPORT */
   4050         break;
   4051     case bcmCosqControlIngressPortPGMinLimitBytes:
   4052 #if defined(BCM_KATANA2_SUPPORT)
   4053         if (SOC_IS_KATANA2(unit)) {
   4054             return bcm_kt2_cosq_control_set(unit, gport, cosq, type, arg);
   4055         }
   4056 #endif /* BCM_KATANA2_SUPPORT */
   4057 #ifdef BCM_MONTEREY_SUPPORT
   4058     if (SOC_IS_MONTEREY(unit)) {
   4059         return bcm_mn_cosq_control_set(unit, gport, cosq, type, arg);
   4060     }
   4061 #endif /* BCM_MONTEREY_SUPPORT */
   4062 #if defined(BCM_APACHE_SUPPORT)
   4063         if (SOC_IS_APACHE(unit)){
   4064             return bcm_ap_cosq_control_set(unit, gport, cosq, type, arg);
   4065         }
   4066 #endif /*BCM_APACHE_SUPPORT*/
   4067 #if defined(BCM_TRIDENT2_SUPPORT)
   4068         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TITAN2X(unit)) {
   4069             return bcm_td2_cosq_control_set(unit, gport, cosq, type, arg);
   4070         }
   4071 #endif /* BCM_TRIDENT2_SUPPORT */
   4072 #if defined(BCM_TRIUMPH3_SUPPORT)
   4073         if (SOC_IS_TRIUMPH3(unit)) {
   4074             return bcm_tr3_cosq_control_set(unit, gport, cosq, type, arg);
   4075         }
   4076 #endif
   4077         break;
   4078 
   4079     case bcmCosqControlEfPropagation:
   4080 #if defined(BCM_TRIDENT2_SUPPORT)
   4081         if (SOC_IS_TD2_TT2(unit)) {
   4082             return bcm_td2_cosq_control_set(unit, gport, cosq, type, arg);
   4083         }
   4084 #endif
   4085 #if defined(BCM_TRIUMPH3_SUPPORT)
   4086         if (SOC_IS_TRIUMPH3(unit)) {
   4087             return bcm_tr3_cosq_control_set(unit, gport, cosq, type, arg);
   4088         }
   4089 #endif
   4090 #if defined(BCM_KATANA_SUPPORT)
   4091         if (SOC_IS_KATANA(unit)) {
   4092             return bcm_kt_cosq_control_set(unit, gport, cosq, type, arg);
   4093         }
   4094 #endif /* BCM_KATANA_SUPPORT */
   4095 #if defined(BCM_KATANA2_SUPPORT)
   4096         if (SOC_IS_KATANA2(unit)) {
   4097             return bcm_kt2_cosq_control_set(unit, gport, cosq, type, arg);
   4098         }
   4099 #endif /* BCM_KATANA2_SUPPORT */
   4100         break;
   4101     case bcmCosqControlRedirectQueueSharedLimitBytes:
   4102     case bcmCosqControlRedirectQueueMinLimitBytes:
   4103     case bcmCosqControlRedirectSharedDynamicEnable:
   4104     case bcmCosqControlRedirectQueueLimitEnable:
   4105     case bcmCosqControlRedirectColorDynamicEnable:
   4106     case bcmCosqControlRedirectColorEnable:
   4107 #if defined(BCM_KATANA2_SUPPORT)
   4108         if (SOC_IS_KATANA2(unit)) {
   4109             return bcm_kt2_cosq_control_set(unit, gport, cosq, type, arg);
   4110         }
   4111 #endif /* BCM_KATANA2_SUPPORT */
   4112         break;
   4113     case bcmCosqControlEEEQueueThresholdProfileSelect:
   4114         if (soc_feature(unit, soc_feature_eee_bb_mode)) {
   4115             int num_cosq;
   4116 
   4117 #if defined(BCM_GREYHOUND2_SUPPORT)
   4118            if (SOC_IS_GREYHOUND2(unit)) {
   4119                return bcmi_gh2_cosq_control_set(unit, gport, cosq, type, arg);
   4120            }
   4121 #endif /* BCM_GREYHOUND2_SUPPORT */
   4122 
   4123             if (soc_feature(unit, soc_feature_wh2)) {
   4124                 /* Get the configured max cosq number */
   4125                 BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
   4126             } else {
   4127                 num_cosq = NUM_COS(unit);
   4128             }
   4129 
   4130             if ((cosq < 0) || (cosq >= num_cosq)) {
   4131                 return BCM_E_PARAM;
   4132             }
   4133             BCM_IF_ERROR_RETURN
   4134                 (bcm_esw_port_local_get(unit, gport, &port));
   4135             if (!SOC_PORT_VALID(unit, port)) {
   4136                 return BCM_E_PORT;
   4137             }
   4138 #if defined(BCM_HURRICANE2_SUPPORT)
   4139             if (SOC_IS_HURRICANE2(unit)||SOC_IS_GREYHOUND(unit)||
   4140                 SOC_IS_HURRICANE3(unit)) {
   4141                 BCM_IF_ERROR_RETURN(
   4142                     soc_reg_field32_modify(unit, select_reg[cosq], port, 
   4143                     EEE_THRESH_SELf, arg));
   4144                 return BCM_E_NONE;
   4145             }
   4146 #endif /* BCM_HURRICANE2_SUPPORT */
   4147         }
   4148         break;
   4149     case bcmCosqControlEEEPacketLatencyProfileSelect:
   4150         if (soc_feature(unit, soc_feature_eee_bb_mode)) {
   4151             int num_cosq;
   4152 #if defined(BCM_GREYHOUND2_SUPPORT)
   4153             if (SOC_IS_GREYHOUND2(unit)) {
   4154                 return bcmi_gh2_cosq_control_set(unit, gport, cosq, type, arg);
   4155             }
   4156 #endif /* BCM_GREYHOUND2_SUPPORT */
   4157 
   4158             if (soc_feature(unit, soc_feature_wh2)) {
   4159                 /* Get the configured max cosq number */
   4160                 BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
   4161             } else {
   4162                 num_cosq = NUM_COS(unit);
   4163             }
   4164 
   4165             if ((cosq < 0) || (cosq >= num_cosq)) {
   4166                 return BCM_E_PARAM;
   4167             }
   4168             BCM_IF_ERROR_RETURN
   4169                 (bcm_esw_port_local_get(unit, gport, &port));
   4170             if (!SOC_PORT_VALID(unit, port)) {
   4171                 return BCM_E_PORT;
   4172             }
   4173 
   4174 #if defined(BCM_HURRICANE2_SUPPORT)
   4175             if (SOC_IS_HURRICANE2(unit)||SOC_IS_GREYHOUND(unit)||
   4176                 SOC_IS_HURRICANE3(unit)) {
   4177                 BCM_IF_ERROR_RETURN(
   4178                     soc_reg_field32_modify(unit, select_reg[cosq], port, 
   4179                     EEE_LATENCY_SELf, arg));
   4180                 return BCM_E_NONE;
   4181             }
   4182 #endif /* BCM_HURRICANE2_SUPPORT */
   4183         }
   4184         break;
   4185     case bcmCosqControlPFCBackpressureEnable:
   4186         if (soc_feature(unit, soc_feature_priority_flow_control)) {
   4187 #if defined(BCM_GREYHOUND_SUPPORT)
   4188             if (soc_feature(unit, soc_feature_gh_style_pfc_config)) {
   4189                 return bcm_gh_cosq_control_set(unit, gport, cosq, type, arg);
   4190             }
   4191 #endif /* BCM_GREYHOUND_SUPPORT */
   4192         }
   4193         break;
   4194     case bcmCosqControlE2ECCTransmitEnable:
   4195 #ifdef BCM_KATANA2_SUPPORT
   4196         if (SOC_IS_KATANA2(unit)) {
   4197             return bcm_kt2_cosq_gport_e2ecc_transmit_set(unit, gport, cosq,
   4198                                                          type, arg);
   4199         } 
   4200 #endif /* BCM_KATANA2_SUPPORT */ 
   4201         break;
   4202     case bcmCosqControlAlternateStoreForward:
   4203         if (soc_feature(unit, soc_feature_asf)) {
   4204 #if defined(BCM_GREYHOUND2_SUPPORT)
   4205             if (SOC_IS_GREYHOUND2(unit)) {
   4206                 return bcmi_gh2_cosq_control_set(unit, gport, cosq, type, arg);
   4207             }
   4208 #endif /* BCM_GREYHOUND2_SUPPORT */
   4209         }
   4210         break;
   4211     default:
   4212         break;
   4213     }
   4214 
   4215     return BCM_E_UNAVAIL;
   4216 }
   4217 
   4218 /* 
   4219  * Function:
   4220  *      bcm_esw_cosq_control_get
   4221  * Purpose:
   4222  *      Get specified feature configuration
   4223  *      
   4224  * Parameters:
   4225  *      unit - (IN) Unit number.
   4226  *      port - (IN) GPORT ID.
   4227  *      cosq - (IN) COS queue.
   4228  *      type - (IN) feature
   4229  *      arg  - (OUT) feature value
   4230  * Returns:
   4231  *      BCM_E_XXX
   4232  * Notes:
   4233  */
   4234 int
   4235 bcm_esw_cosq_control_get(int unit, bcm_gport_t gport, bcm_cos_queue_t cosq,
   4236                          bcm_cosq_control_t type, int *arg)
   4237 {
   4238     uint32 kbits_sec_min, kbits_sec_max, kbits_burst, flags;
   4239     bcm_port_t port;
   4240     bcm_cos_queue_t loc_cos;
   4241     uint32 cm_val, cmc1_val;
   4242     uint64 cmc_val64;
   4243 #if defined(BCM_HURRICANE2_SUPPORT)
   4244     soc_reg_t select_reg[8] = { \
   4245         EEE_PROFILE_SEL_0r, EEE_PROFILE_SEL_1r, \
   4246         EEE_PROFILE_SEL_2r, EEE_PROFILE_SEL_3r, \
   4247         EEE_PROFILE_SEL_4r, EEE_PROFILE_SEL_5r, \
   4248         EEE_PROFILE_SEL_6r, EEE_PROFILE_SEL_7r};
   4249 #endif /* BCM_HURRICANE2_SUPPORT */
   4250 
   4251 #ifdef BCM_TOMAHAWK3_SUPPORT
   4252         if (SOC_IS_TOMAHAWK3(unit)) {
   4253             return bcm_th3_cosq_control_get(unit, gport, cosq,
   4254                 BCM_COSQ_BUFFER_ID_INVALID, type, arg);
   4255         }
   4256 #endif /* BCM_TOMAHAWK3_SUPPORT */
   4257 #ifdef BCM_TOMAHAWK_SUPPORT
   4258         if (SOC_IS_TOMAHAWKX(unit)) {
   4259             return bcm_th_cosq_control_get(unit, gport, cosq,
   4260                 BCM_COSQ_BUFFER_ID_INVALID, type, arg);
   4261         }
   4262 #endif /* BCM_TOMAHAWK_SUPPORT */
   4263 #ifdef BCM_HELIX5_SUPPORT
   4264     if (SOC_IS_HELIX5(unit)) {
   4265         return (bcm_hx5_cosq_control_get(unit, gport, cosq, type, arg));
   4266     }
   4267 #endif /* BCM_HELIX5_SUPPORT */
   4268 #ifdef BCM_TRIDENT3_SUPPORT
   4269         if (SOC_IS_TRIDENT3X(unit)) {
   4270            return (bcm_td3_cosq_control_get(unit, gport, cosq, type, arg));
   4271         }
   4272 #endif /* BCM_TRIDENT3_SUPPORT */
   4273 
   4274     switch (type) {
   4275     case bcmCosqControlBandwidthBurstMax:
   4276 #ifdef BCM_MONTEREY_SUPPORT
   4277     if (SOC_IS_MONTEREY(unit)) {
   4278         uint32 kburst_tmp;
   4279             BCM_IF_ERROR_RETURN
   4280                 (bcm_mn_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4281                                                 &kburst_tmp, &kbits_burst));
   4282         } else
   4283 #endif /* BCM_MONTEREY_SUPPORT */
   4284 #ifdef BCM_APACHE_SUPPORT
   4285         if (SOC_IS_APACHE(unit)) {
   4286             uint32 kburst_tmp;
   4287             BCM_IF_ERROR_RETURN
   4288                 (bcm_ap_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4289                                                 &kburst_tmp, &kbits_burst));
   4290         } else
   4291 #endif /* BCM_APACHE_SUPPORT */
   4292 #ifdef BCM_TRIUMPH2_SUPPORT
   4293         if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   4294             SOC_IS_VALKYRIE2(unit)) {
   4295             uint32 kburst_tmp;
   4296             BCM_IF_ERROR_RETURN
   4297                 (bcm_tr2_cosq_gport_bandwidth_burst_get(unit, gport, cosq, 
   4298                                                         &kburst_tmp, &kbits_burst));
   4299         } else 
   4300 #endif  
   4301 #ifdef BCM_TRIDENT2_SUPPORT
   4302         if (SOC_IS_TD2_TT2(unit)) {
   4303             uint32 kburst_tmp;
   4304             BCM_IF_ERROR_RETURN
   4305                 (bcm_td2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4306                                                 &kburst_tmp, &kbits_burst));
   4307         } else
   4308 #endif /* BCM_TRIDENT2_SUPPORT */
   4309 #ifdef BCM_TRIDENT_SUPPORT
   4310         if (SOC_IS_TD_TT(unit)) {
   4311             uint32 kburst_tmp;
   4312             BCM_IF_ERROR_RETURN
   4313                 (bcm_td_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4314                                                 &kburst_tmp, &kbits_burst));
   4315         } else
   4316 #endif /* BCM_TRIDENT_SUPPORT */
   4317 #ifdef BCM_KATANA_SUPPORT
   4318         if (SOC_IS_KATANA(unit)) {
   4319             uint32 kburst_tmp;
   4320             BCM_IF_ERROR_RETURN
   4321                 (bcm_kt_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4322                                                 &kburst_tmp, &kbits_burst));
   4323         } else
   4324 #endif /* BCM_KATANA_SUPPORT */
   4325 #ifdef BCM_KATANA2_SUPPORT
   4326         if (SOC_IS_KATANA2(unit)) {
   4327             uint32 kburst_tmp;
   4328             BCM_IF_ERROR_RETURN
   4329                 (bcm_kt2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4330                                                 &kburst_tmp, &kbits_burst));
   4331         } else
   4332 #endif /* BCM_KATANA2_SUPPORT */
   4333 #ifdef BCM_TRIUMPH3_SUPPORT
   4334         if (SOC_IS_TRIUMPH3(unit)) {
   4335             uint32 kburst_tmp;
   4336             BCM_IF_ERROR_RETURN
   4337                 (bcm_tr3_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4338                                                         &kburst_tmp, &kbits_burst));
   4339         } else
   4340 #endif /* BCM_TRIUMPH3_SUPPORT */
   4341 #ifdef BCM_TRIUMPH_SUPPORT
   4342         if (SOC_IS_TR_VL(unit)) {
   4343             uint32 kburst_tmp;
   4344 #if defined(BCM_HURRICANE_SUPPORT)
   4345             if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
   4346                 BCM_IF_ERROR_RETURN
   4347                     (bcm_hu_cosq_gport_bandwidth_burst_get(unit, gport,
   4348                                                            cosq, &kbits_burst));                
   4349             } else
   4350 #endif /* BCM_HURRICANE_SUPPORT*/
   4351 #if defined(BCM_GREYHOUND2_SUPPORT)
   4352             if (SOC_IS_GREYHOUND2(unit)) {
   4353                 BCM_IF_ERROR_RETURN
   4354                     (bcmi_gh2_cosq_gport_bandwidth_burst_get(unit, gport,
   4355                                                              cosq,
   4356                                                              &kbits_burst));
   4357             } else
   4358 #endif /* BCM_GREYHOUND2_SUPPORT */
   4359             {
   4360                 BCM_IF_ERROR_RETURN
   4361                     (bcm_tr_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4362                                                            &kburst_tmp, &kbits_burst));
   4363             }
   4364         } else  /*SOC_IS_TR_VL*/
   4365 #endif  
   4366         {
   4367             if (gport < 0) {
   4368                 port = SOC_PORT_MIN(unit,all);
   4369             } else {
   4370                 /* Must use local ports on legacy devices */
   4371                 BCM_IF_ERROR_RETURN
   4372                     (bcm_esw_port_local_get(unit, gport, &port));
   4373                 if (!SOC_PORT_VALID(unit, port)) {
   4374                     return BCM_E_PORT;
   4375                 }
   4376             }
   4377 
   4378             if (cosq < 0) {
   4379                 loc_cos = 0;
   4380             } else {
   4381                 if (cosq < NUM_COS(unit)) {
   4382                     loc_cos = cosq;
   4383                 } else {
   4384                     return BCM_E_PARAM;
   4385                 }
   4386             }
   4387 
   4388             BCM_IF_ERROR_RETURN
   4389                 (mbcm_driver[unit]->
   4390                  mbcm_cosq_port_bandwidth_get(unit, port, loc_cos,
   4391                                               &kbits_sec_min, &kbits_sec_max,
   4392                                               &kbits_burst, &flags));
   4393         }
   4394         *arg = kbits_burst & 0x7fffffff; /* Convert to int  */
   4395         return BCM_E_NONE;
   4396 
   4397     case bcmCosqControlBandwidthBurstMin:
   4398 #ifdef BCM_MONTEREY_SUPPORT
   4399     if (SOC_IS_MONTEREY(unit)) {
   4400         uint32 kburst_tmp;
   4401         return bcm_mn_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4402                                                      (uint32*)arg, &kburst_tmp); 
   4403         } else
   4404 #endif /* BCM_MONTEREY_SUPPORT */
   4405 #ifdef BCM_APACHE_SUPPORT
   4406         if (SOC_IS_APACHE(unit)) {
   4407             uint32 kburst_tmp;
   4408             return bcm_ap_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4409                                                      (uint32*)arg, &kburst_tmp);
   4410         } else
   4411 #endif /* BCM_APACHE_SUPPORT */
   4412 #ifdef BCM_TRIUMPH2_SUPPORT
   4413         if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   4414             SOC_IS_VALKYRIE2(unit)) {
   4415             uint32 kburst_tmp;
   4416             BCM_IF_ERROR_RETURN
   4417                 (bcm_tr2_cosq_gport_bandwidth_burst_get(unit, gport, cosq, 
   4418                                                         (uint32*)arg, &kburst_tmp));
   4419         } else 
   4420 #endif 
   4421 #ifdef BCM_TRIDENT2_SUPPORT
   4422         if (SOC_IS_TD2_TT2(unit)) {
   4423             uint32 kburst_tmp;
   4424             return bcm_td2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4425                                                      (uint32*)arg, &kburst_tmp);
   4426         } else
   4427 #endif /* BCM_TRIDENT2_SUPPORT */
   4428 #ifdef BCM_TRIUMPH3_SUPPORT
   4429         if (SOC_IS_TRIUMPH3(unit)) {
   4430             uint32 kburst_tmp;
   4431             return bcm_tr3_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4432                                                      (uint32*)arg, &kburst_tmp);
   4433         } else
   4434 #endif /* BCM_TRIUMPH3_SUPPORT */
   4435 #if defined(BCM_TRIDENT_SUPPORT)
   4436         if (SOC_IS_TD_TT(unit)) {
   4437             uint32 kburst_tmp;
   4438             return bcm_td_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4439                                                       (uint32*)arg, &kburst_tmp);
   4440         } else
   4441 #endif
   4442 #ifdef BCM_KATANA_SUPPORT
   4443         if (SOC_IS_KATANA(unit)) {
   4444             uint32 kburst_tmp;
   4445             return bcm_kt_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4446                                                       (uint32*)arg, &kburst_tmp);
   4447         } else 
   4448 #endif /* BCM_KATANA_SUPPORT */
   4449 #ifdef BCM_KATANA2_SUPPORT
   4450         if (SOC_IS_KATANA2(unit)) {
   4451             uint32 kburst_tmp;
   4452             return bcm_kt2_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4453                                                       (uint32*)arg, &kburst_tmp);
   4454         } else 
   4455 #endif /* BCM_KATANA2_SUPPORT */
   4456 #ifdef BCM_TRIUMPH_SUPPORT
   4457         if (SOC_IS_TR_VL(unit)) {
   4458             uint32 kburst_tmp;
   4459 #if defined(BCM_HURRICANE_SUPPORT)
   4460             /* coverity[dead_error_begin : FALSE] */
   4461             if(SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit)) {
   4462              /*need to support later*/
   4463             } else   
   4464 #endif /* BCM_HURRICANE_SUPPORT*/
   4465             {
   4466                 BCM_IF_ERROR_RETURN
   4467                     (bcm_tr_cosq_gport_bandwidth_burst_get(unit, gport, cosq,
   4468                                                            (uint32*)arg, &kburst_tmp));
   4469             }
   4470         } else  /*BCM_TRIUMPH_SUPPORT*/
   4471 #endif 
   4472         /* coverity[dead_error_begin : FALSE] */
   4473         {
   4474             /*do nothing*/
   4475         }
   4476 
   4477         return BCM_E_UNAVAIL;
   4478 
   4479     case bcmCosqControlSchedulable:
   4480         if (!soc_reg_field_valid(unit, COSMASKr, COSMASKf)) {
   4481             return BCM_E_UNAVAIL;
   4482         }
   4483 
   4484         if (gport < 0) {
   4485             port = SOC_PORT_MIN(unit,all);
   4486         } else {
   4487             /* Must use local ports on legacy devices */
   4488             BCM_IF_ERROR_RETURN
   4489                 (bcm_esw_port_local_get(unit, gport, &port));
   4490             if (!SOC_PORT_VALID(unit, port)) {
   4491                 return BCM_E_PORT;
   4492             }
   4493         }
   4494 
   4495         loc_cos = (cosq < 0) ? 0 : cosq;
   4496 
   4497         if (port == CMIC_PORT(unit)) {
   4498             if (soc_reg_field_valid(unit, COSMASK_CPUr, COSMASKf)) {
   4499                 if (loc_cos > 47) {
   4500                     return BCM_E_PARAM;
   4501                 }
   4502 
   4503                 BCM_IF_ERROR_RETURN
   4504                     (READ_COSMASK_CPUr(unit, &cmc_val64));
   4505                 *arg = COMPILER_64_BITTEST(cmc_val64, loc_cos) ?
   4506                     FALSE : TRUE; 
   4507             } else if (soc_reg_field_valid(unit, COSMASK_CPU1r, COSMASKf)) {
   4508                 if (loc_cos < 10) {
   4509                     BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
   4510                     *arg = (cm_val & (1 << loc_cos)) ? FALSE : TRUE; 
   4511                 } else if (loc_cos < 32) {
   4512                     BCM_IF_ERROR_RETURN(READ_COSMASK_CPU1r(unit, &cmc1_val));
   4513                     *arg = (cmc1_val & (1 << loc_cos)) ? FALSE : TRUE;
   4514                 } else {
   4515                     return BCM_E_PARAM;
   4516                 }
   4517             } else {
   4518                 if (loc_cos < 10) {
   4519                     BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
   4520                     *arg = (cm_val & (1 << loc_cos)) ? FALSE : TRUE; 
   4521                 } else {
   4522                     return BCM_E_PARAM;
   4523                 }
   4524             }
   4525         } else {
   4526             if (cosq < NUM_COS(unit)) {
   4527                 BCM_IF_ERROR_RETURN(READ_COSMASKr(unit, port, &cm_val));
   4528                 *arg = (cm_val & (1 << loc_cos)) ? FALSE : TRUE; 
   4529             } else {
   4530                 return BCM_E_PARAM;
   4531             }
   4532         }
   4533 
   4534         return BCM_E_NONE;
   4535 
   4536     case bcmCosqControlCongestionManagedQueue:
   4537         if (soc_feature(unit, soc_feature_qcn)) {
   4538 #if defined(BCM_APACHE_SUPPORT)
   4539             if (SOC_IS_APACHE(unit)) {
   4540                 return bcm_ap_cosq_congestion_queue_get(unit, gport, cosq, arg);
   4541             }
   4542 #endif
   4543 #if defined(BCM_TRIDENT2_SUPPORT)
   4544             if (SOC_IS_TD2_TT2(unit)) {
   4545                 return bcm_td2_cosq_congestion_queue_get(unit, gport, cosq, arg);
   4546             }
   4547 #endif
   4548 #if defined(BCM_TRIDENT_SUPPORT)
   4549             if (SOC_IS_TD_TT(unit)) {
   4550                 return bcm_td_cosq_congestion_queue_get(unit, gport, cosq, arg);
   4551             }
   4552 #endif
   4553 #if defined(BCM_TRIUMPH3_SUPPORT)
   4554             if (SOC_IS_TRIUMPH3(unit)) {
   4555                 return bcm_tr3_cosq_congestion_queue_get(unit, gport, cosq, arg);
   4556             }
   4557 #endif
   4558         }
   4559         break;
   4560     case bcmCosqControlCongestionFeedbackWeight:
   4561         if (soc_feature(unit, soc_feature_qcn)) {
   4562 #if defined(BCM_APACHE_SUPPORT)
   4563             if (SOC_IS_APACHE(unit)) {
   4564                 return bcm_ap_cosq_congestion_quantize_get(unit, gport, 
   4565                                                         cosq, arg, NULL);
   4566             }
   4567 #endif 
   4568 #if defined(BCM_TRIDENT2_SUPPORT)
   4569             if (SOC_IS_TD2_TT2(unit)) {
   4570                 return bcm_td2_cosq_congestion_quantize_get(unit, gport, 
   4571                                                         cosq, arg, NULL);
   4572             }
   4573 #endif
   4574 #if defined(BCM_TRIDENT_SUPPORT)
   4575             if (SOC_IS_TD_TT(unit)) {
   4576                 return bcm_td_cosq_congestion_quantize_get(unit, gport, 
   4577                                                         cosq, arg, NULL);
   4578             }
   4579 #endif
   4580 #if defined(BCM_TRIUMPH3_SUPPORT)
   4581             if (SOC_IS_TRIUMPH3(unit)) {
   4582                 return bcm_tr3_cosq_congestion_quantize_get(unit, gport, 
   4583                                                         cosq, arg, NULL);
   4584             }
   4585 #endif
   4586         }
   4587         break;
   4588     case bcmCosqControlCongestionSetPoint:
   4589         if (soc_feature(unit, soc_feature_qcn)) {
   4590 #if defined(BCM_APACHE_SUPPORT)
   4591             if (SOC_IS_APACHE(unit)) {
   4592                 return bcm_ap_cosq_congestion_quantize_get(unit, gport, 
   4593                                                             cosq, NULL, arg);
   4594             }
   4595 #endif 
   4596 #if defined(BCM_TRIDENT2_SUPPORT)
   4597             if (SOC_IS_TD2_TT2(unit)) {
   4598                 return bcm_td2_cosq_congestion_quantize_get(unit, gport, 
   4599                                                             cosq, NULL, arg);
   4600             }
   4601 #endif
   4602 #if defined(BCM_TRIDENT_SUPPORT)
   4603             if (SOC_IS_TD_TT(unit)) {
   4604                 return bcm_td_cosq_congestion_quantize_get(unit, gport, 
   4605                                                             cosq, NULL, arg);
   4606             }
   4607 #endif
   4608 #if defined(BCM_TRIUMPH3_SUPPORT)
   4609             if (SOC_IS_TRIUMPH3(unit)) {
   4610                 return bcm_tr3_cosq_congestion_quantize_get(unit, gport, 
   4611                                                             cosq, NULL, arg);
   4612             }
   4613 #endif
   4614         }
   4615         break;
   4616     case bcmCosqControlCongestionSampleBytesMin:
   4617         if (soc_feature(unit, soc_feature_qcn)) {
   4618 #if defined(BCM_APACHE_SUPPORT)
   4619             if (SOC_IS_APACHE(unit)) {
   4620                 return bcm_ap_cosq_congestion_sample_int_get(unit, gport, cosq,
   4621                                                          arg, NULL);
   4622             }
   4623 #endif 
   4624 #if defined(BCM_TRIDENT2_SUPPORT)
   4625             if (SOC_IS_TD2_TT2(unit)) {
   4626                 return bcm_td2_cosq_congestion_sample_int_get(unit, gport, cosq,
   4627                                                          arg, NULL);
   4628             }
   4629 #endif
   4630 #if defined(BCM_TRIDENT_SUPPORT)
   4631             if (SOC_IS_TD_TT(unit)) {
   4632                 return bcm_td_cosq_congestion_sample_int_get(unit, gport, cosq,
   4633                                                          arg, NULL);
   4634             }
   4635 #endif
   4636 #if defined(BCM_TRIUMPH3_SUPPORT)
   4637             if (SOC_IS_TRIUMPH3(unit)) {
   4638                 return bcm_tr3_cosq_congestion_sample_int_get(unit, gport, cosq,
   4639                                                          arg, NULL);
   4640             }
   4641 #endif
   4642         }
   4643         break;
   4644     case bcmCosqControlCongestionSampleBytesMax:
   4645         if (soc_feature(unit, soc_feature_qcn)) {
   4646 #if defined(BCM_APACHE_SUPPORT)
   4647             if (SOC_IS_APACHE(unit)) {
   4648                 return bcm_ap_cosq_congestion_sample_int_get(unit, gport, cosq,
   4649                                                          NULL, arg);
   4650             }
   4651 #endif
   4652 #if defined(BCM_TRIDENT2_SUPPORT)
   4653             if (SOC_IS_TD2_TT2(unit)) {
   4654                 return bcm_td2_cosq_congestion_sample_int_get(unit, gport, cosq,
   4655                                                          NULL, arg);
   4656             }
   4657 #endif
   4658 #if defined(BCM_TRIDENT_SUPPORT)
   4659             if (SOC_IS_TD_TT(unit)) {
   4660                 return bcm_td_cosq_congestion_sample_int_get(unit, gport, cosq,
   4661                                                          NULL, arg);
   4662             }
   4663 #endif
   4664 #if defined(BCM_TRIUMPH3_SUPPORT)
   4665             if (SOC_IS_TRIUMPH3(unit)) {
   4666                 return bcm_tr3_cosq_congestion_sample_int_get(unit, gport, cosq,
   4667                                                          NULL, arg);
   4668             }
   4669 #endif
   4670         }
   4671         break;
   4672     case bcmCosqControlEgressPool:
   4673     case bcmCosqControlEgressPoolLimitBytes:
   4674     case bcmCosqControlEgressPoolYellowLimitBytes:
   4675     case bcmCosqControlEgressPoolRedLimitBytes:
   4676     case bcmCosqControlEgressPoolLimitEnable:
   4677     case bcmCosqControlEgressUCQueueMinLimitBytes:
   4678     case bcmCosqControlEgressUCQueueSharedLimitBytes:
   4679     case bcmCosqControlEgressUCQueueLimitEnable:
   4680     case bcmCosqControlEgressUCQueueColorLimitEnable:
   4681     case bcmCosqControlEgressUCSharedDynamicEnable:        
   4682     case bcmCosqControlEgressMCQueueSharedLimitBytes:
   4683     case bcmCosqControlEgressMCQueueMinLimitBytes:
   4684     case bcmCosqControlEgressMCSharedDynamicEnable:
   4685     case bcmCosqControlEgressMCQueueLimitEnable:
   4686     case bcmCosqControlEgressMCQueueColorLimitEnable:
   4687     case bcmCosqControlIngressPortPGSharedLimitBytes:
   4688     case bcmCosqControlIngressPortPoolMaxLimitBytes:
   4689     case bcmCosqControlIngressPortPGSharedDynamicEnable:
   4690     case bcmCosqControlIngressPortPoolMinLimitBytes:
   4691     case bcmCosqControlDropLimitAlpha:      
   4692     case bcmCosqControlUCDropLimitAlpha:      
   4693     case bcmCosqControlMCDropLimitAlpha:      
   4694     case bcmCosqControlSPPortLimitState:
   4695     case bcmCosqControlPGPortLimitState:
   4696     case bcmCosqControlPGPortXoffState:
   4697     case bcmCosqControlPoolRedDropState:
   4698     case bcmCosqControlPoolYellowDropState:
   4699     case bcmCosqControlPoolGreenDropState:
   4700     case bcmCosqControlIngressPool:
   4701     case bcmCosqControlEgressPortPoolYellowLimitBytes:
   4702     case bcmCosqControlEgressPortPoolRedLimitBytes:
   4703     case bcmCosqControlUCEgressPool:
   4704     case bcmCosqControlMCEgressPool:
   4705     case bcmCosqControlIngressPoolLimitBytes:    
   4706     case bcmCosqControlIngressPortPGHeadroomLimitBytes:
   4707     case bcmCosqControlIngressPortPGResetFloorBytes:
   4708     case bcmCosqControlEgressPoolSharedLimitBytes: 
   4709     case bcmCosqControlEgressPoolResumeLimitBytes:
   4710     case bcmCosqControlEgressPoolYellowSharedLimitBytes: 
   4711     case bcmCosqControlEgressPoolYellowResumeLimitBytes:
   4712     case bcmCosqControlEgressPoolRedSharedLimitBytes:
   4713     case bcmCosqControlEgressPoolRedResumeLimitBytes:
   4714     case bcmCosqControlEgressUCQueueGroupMinEnable:
   4715     case bcmCosqControlEgressUCQueueGroupSharedLimitEnable:
   4716     case bcmCosqControlEgressUCQueueGroupMinLimitBytes:
   4717     case bcmCosqControlEgressUCQueueGroupSharedLimitBytes:
   4718     case bcmCosqControlEgressUCQueueGroupSharedDynamicEnable:
   4719     case bcmCosqControlEgressUCQueueGroupDropLimitAlpha:
   4720     case bcmCosqControlObmDiscardLimit:
   4721     case bcmCosqControlObmMinLimit:
   4722     case bcmCosqControlEgressUCQueueColorLimitDynamicEnable:
   4723     case bcmCosqControlEgressMCQueueColorLimitDynamicEnable:
   4724     case bcmCosqControlEgressUCQueueRedLimit:
   4725     case bcmCosqControlEgressUCQueueYellowLimit:
   4726     case bcmCosqControlEgressMCQueueRedLimit:
   4727     case bcmCosqControlEgressMCQueueYellowLimit:
   4728 #ifdef BCM_MONTEREY_SUPPORT
   4729        if (SOC_IS_MONTEREY(unit)) {
   4730            return bcm_mn_cosq_control_get(unit, gport, cosq, type, arg); 
   4731        }
   4732 #endif /* BCM_MONTEREY_SUPPORT */
   4733 #if defined(BCM_APACHE_SUPPORT)
   4734             if (SOC_IS_APACHE(unit)) {
   4735                 return bcm_ap_cosq_control_get(unit, gport, cosq, type, arg);
   4736             }
   4737 #endif
   4738 #if defined(BCM_TRIDENT2_SUPPORT)
   4739             if (SOC_IS_TD2_TT2(unit)) {
   4740                 return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
   4741             }
   4742 #endif
   4743         if (SOC_IS_TD_TT(unit)) {
   4744 #if defined(BCM_TRIDENT_SUPPORT)
   4745             if (SOC_IS_TD_TT(unit)) {
   4746                 return bcm_td_cosq_control_get(unit, gport, cosq, type, arg);
   4747             }
   4748 #endif
   4749         }
   4750 #if defined(BCM_TRIUMPH3_SUPPORT)
   4751         if (SOC_IS_TRIUMPH3(unit)) {
   4752             return bcm_tr3_cosq_control_get(unit, gport, cosq, type, arg);
   4753         }
   4754 #endif
   4755 #ifdef BCM_KATANA2_SUPPORT
   4756         if (SOC_IS_KATANA2(unit)) {
   4757             return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
   4758         }
   4759 #endif /* BCM_KATANA2_SUPPORT */
   4760         break;
   4761     case bcmCosqControlCongestionProxy:
   4762             if (!SOC_REG_IS_VALID(unit, QCN_CNM_PRP_CTRLr)) {
   4763                 return BCM_E_UNAVAIL;
   4764             }
   4765 #ifdef BCM_MONTEREY_SUPPORT
   4766        if (SOC_IS_MONTEREY(unit)) {
   4767            return bcm_mn_cosq_control_get(unit, gport, cosq, type, arg);
   4768        }
   4769 #endif /* BCM_MONTEREY_SUPPORT */
   4770 
   4771 #if defined(BCM_APACHE_SUPPORT)
   4772             if (SOC_IS_APACHE(unit)) {
   4773                 return bcm_ap_cosq_control_get(unit, gport, cosq, type, arg);
   4774             }
   4775 #endif
   4776 #if defined(BCM_TRIDENT2_SUPPORT)
   4777             if (SOC_IS_TD2_TT2(unit)) {
   4778                 return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
   4779             }
   4780 #endif
   4781         break;
   4782         
   4783     case bcmCosqControlIngressPortPGMinLimitBytes:
   4784 #ifdef BCM_KATANA2_SUPPORT
   4785         if (SOC_IS_KATANA2(unit)) {
   4786             return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
   4787         }
   4788 #endif /* BCM_KATANA2_SUPPORT */
   4789 #ifdef BCM_MONTEREY_SUPPORT
   4790        if (SOC_IS_MONTEREY(unit)) {
   4791            return bcm_mn_cosq_control_get(unit, gport, cosq, type, arg);
   4792        }
   4793 #endif /* BCM_MONTEREY_SUPPORT */
   4794 #if defined(BCM_APACHE_SUPPORT)
   4795         if (SOC_IS_APACHE(unit)){
   4796             return bcm_ap_cosq_control_get(unit, gport, cosq, type, arg);
   4797         }
   4798 #endif /* BCM_APACHE_SUPPORT*/
   4799 #if defined(BCM_TRIDENT2_SUPPORT)
   4800         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TITAN2X(unit)) {
   4801             return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
   4802         }
   4803 #endif /* BCM_TRIDENT2_SUPPORT */
   4804 #if defined(BCM_TRIUMPH3_SUPPORT)
   4805         if (SOC_IS_TRIUMPH3(unit)) {
   4806             return bcm_tr3_cosq_control_get(unit, gport, cosq, type, arg);
   4807         }
   4808 #endif
   4809         break;
   4810     case bcmCosqControlEfPropagation:
   4811 #if defined(BCM_TRIDENT2_SUPPORT)
   4812         if (SOC_IS_TD2_TT2(unit)) {
   4813             return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
   4814         }
   4815 #endif
   4816 #ifdef BCM_KATANA_SUPPORT
   4817         if (SOC_IS_KATANA(unit)) {
   4818             return bcm_kt_cosq_control_get(unit, gport, cosq, type, arg);
   4819         }
   4820 #endif /* BCM_KATANA_SUPPORT */
   4821 #ifdef BCM_KATANA2_SUPPORT
   4822         if (SOC_IS_KATANA2(unit)) {
   4823             return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
   4824         }
   4825 #endif /* BCM_KATANA2_SUPPORT */
   4826         break;
   4827     case bcmCosqControlEEEQueueThresholdProfileSelect:
   4828         if (soc_feature(unit, soc_feature_eee_bb_mode)) {
   4829             int num_cosq;
   4830 #if defined(BCM_GREYHOUND2_SUPPORT)
   4831             if (SOC_IS_GREYHOUND2(unit)) {
   4832                 return bcmi_gh2_cosq_control_get(unit, gport, cosq, type, arg);
   4833             }
   4834 #endif /* BCM_GREYHOUND2_SUPPORT */
   4835 
   4836             if (soc_feature(unit, soc_feature_wh2)) {
   4837                 /* Get the configured max cosq number */
   4838                 BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
   4839             } else {
   4840                 num_cosq = NUM_COS(unit);
   4841             }
   4842 
   4843             if ((cosq < 0) || (cosq >= num_cosq)) {
   4844                 return BCM_E_PARAM;
   4845             }
   4846             BCM_IF_ERROR_RETURN
   4847                 (bcm_esw_port_local_get(unit, gport, &port));
   4848             if (!SOC_PORT_VALID(unit, port)) {
   4849                 return BCM_E_PORT;
   4850             }
   4851 
   4852 #if defined(BCM_HURRICANE2_SUPPORT)
   4853             if (SOC_IS_HURRICANE2(unit)||SOC_IS_GREYHOUND(unit)||
   4854                 SOC_IS_HURRICANE3(unit)) {
   4855                 uint32 rval = 0;
   4856 
   4857                 BCM_IF_ERROR_RETURN(
   4858                     soc_reg32_get(unit, select_reg[cosq], port, 0, &rval));
   4859                 *arg = soc_reg_field_get(unit, select_reg[cosq], 
   4860                            rval, EEE_THRESH_SELf);
   4861                 return BCM_E_NONE;
   4862             }
   4863 #endif /* BCM_HURRICANE2_SUPPORT */
   4864         }
   4865         break;
   4866     case bcmCosqControlEEEPacketLatencyProfileSelect:
   4867         if (soc_feature(unit, soc_feature_eee_bb_mode)) {
   4868             int num_cosq;
   4869 #if defined(BCM_GREYHOUND2_SUPPORT)
   4870             if (SOC_IS_GREYHOUND2(unit)) {
   4871                 return bcmi_gh2_cosq_control_get(unit, gport, cosq, type, arg);
   4872             }
   4873 #endif /* BCM_GREYHOUND2_SUPPORT */
   4874 
   4875             if (soc_feature(unit, soc_feature_wh2)) {
   4876                 /* Get the configured max cosq number */
   4877                 BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
   4878             } else {
   4879                 num_cosq = NUM_COS(unit);
   4880             }
   4881 
   4882             if ((cosq < 0) || (cosq >= num_cosq)) {
   4883                 return BCM_E_PARAM;
   4884             }
   4885             BCM_IF_ERROR_RETURN
   4886                 (bcm_esw_port_local_get(unit, gport, &port));
   4887             if (!SOC_PORT_VALID(unit, port)) {
   4888                 return BCM_E_PORT;
   4889             }
   4890 
   4891 #if defined(BCM_HURRICANE2_SUPPORT)
   4892             if (SOC_IS_HURRICANE2(unit)||SOC_IS_GREYHOUND(unit)||
   4893                 SOC_IS_HURRICANE3(unit)) {
   4894                 uint32 rval = 0;
   4895 
   4896                 BCM_IF_ERROR_RETURN(
   4897                     soc_reg32_get(unit, select_reg[cosq], port, 0, &rval));
   4898                 *arg = soc_reg_field_get(unit, select_reg[cosq], 
   4899                            rval, EEE_LATENCY_SELf);
   4900                 return BCM_E_NONE;
   4901             }
   4902 #endif /* BCM_HURRICANE2_SUPPORT */
   4903         }
   4904         break;
   4905     case bcmCosqControlPortQueueUcast:
   4906     case bcmCosqControlPortQueueMcast:
   4907 #ifdef BCM_MONTEREY_SUPPORT
   4908        if (SOC_IS_MONTEREY(unit)) {
   4909            return bcm_mn_cosq_control_get(unit, gport, cosq, type, arg);
   4910        }
   4911 #endif /* BCM_MONTEREY_SUPPORT */
   4912 #if defined(BCM_APACHE_SUPPORT)
   4913             if (SOC_IS_APACHE(unit)) {
   4914                 return bcm_ap_cosq_control_get(unit, gport, cosq, type, arg);
   4915             }
   4916 #endif
   4917 #if defined(BCM_TRIDENT2_SUPPORT)
   4918         if (SOC_IS_TD2_TT2(unit)) {
   4919             return bcm_td2_cosq_control_get(unit, gport, cosq, type, arg);
   4920         }
   4921 #endif
   4922 #if defined(BCM_TRIUMPH3_SUPPORT)
   4923         if (SOC_IS_TRIUMPH3(unit)) {
   4924             return bcm_tr3_cosq_control_get(unit, gport, cosq, type, arg);
   4925         }
   4926 #endif
   4927 #ifdef BCM_KATANA_SUPPORT
   4928         if (SOC_IS_KATANA(unit)) {
   4929             return bcm_kt_cosq_control_get(unit, gport, cosq, type, arg);
   4930         }
   4931 #endif
   4932 #ifdef BCM_KATANA2_SUPPORT
   4933         if (SOC_IS_KATANA2(unit)) {
   4934             return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
   4935         }
   4936 #endif
   4937 
   4938         if (!BCM_COSQ_QUEUE_VALID(unit, cosq)) {
   4939             return BCM_E_PARAM;
   4940         }
   4941 
   4942         if (arg == NULL) {
   4943             return BCM_E_PARAM;
   4944         }
   4945 
   4946         *arg = cosq;
   4947         break;
   4948     case bcmCosqControlRedirectQueueSharedLimitBytes:
   4949     case bcmCosqControlRedirectQueueMinLimitBytes:
   4950     case bcmCosqControlRedirectSharedDynamicEnable:
   4951     case bcmCosqControlRedirectQueueLimitEnable:
   4952     case bcmCosqControlRedirectColorDynamicEnable:
   4953     case bcmCosqControlRedirectColorEnable:
   4954 #if defined(BCM_KATANA2_SUPPORT)
   4955         if (SOC_IS_KATANA2(unit)) {
   4956             return bcm_kt2_cosq_control_get(unit, gport, cosq, type, arg);
   4957         }
   4958 #endif /* BCM_KATANA2_SUPPORT */
   4959         break;
   4960     case bcmCosqControlPFCBackpressureEnable:
   4961         if (soc_feature(unit, soc_feature_priority_flow_control)) {
   4962 #if defined(BCM_GREYHOUND_SUPPORT)
   4963             if (soc_feature(unit, soc_feature_gh_style_pfc_config)) {
   4964                 return bcm_gh_cosq_control_get(unit, gport, cosq, type, arg);
   4965             }
   4966 #endif /* BCM_GREYHOUND_SUPPORT */
   4967         }
   4968         break;
   4969     case bcmCosqControlE2ECCTransmitEnable:
   4970 #ifdef BCM_KATANA2_SUPPORT
   4971         if (SOC_IS_KATANA2(unit)) {
   4972             return bcm_kt2_cosq_gport_e2ecc_transmit_get(unit, gport, cosq,
   4973                                                          type, arg);
   4974         }
   4975 #endif /* BCM_KATANA2_SUPPORT */
   4976         break;
   4977     case bcmCosqControlAlternateStoreForward:
   4978         if (soc_feature(unit, soc_feature_asf)) {
   4979 #if defined(BCM_GREYHOUND2_SUPPORT)
   4980             if (SOC_IS_GREYHOUND2(unit)) {
   4981                 return bcmi_gh2_cosq_control_get(unit, gport, cosq, type, arg);
   4982             }
   4983 #endif /* BCM_GREYHOUND2_SUPPORT */
   4984         }
   4985         break;
   4986     default:
   4987         break;
   4988     }
   4989 
   4990     return BCM_E_UNAVAIL;
   4991 }
   4992 
   4993 /*
   4994  * Function:
   4995  *      bcm_esw_cosq_control_extended_set
   4996  * Purpose:
   4997  *      Set specified feature configuration
   4998  *
   4999  * Parameters:
   5000  *      unit    - (IN) Unit number
   5001  *      id      - (IN) Integrated cosq index
   5002  *      control - (IN) Integrated cosq control data
   5003  * Returns:
   5004  *      BCM_E_XXX
   5005  * Notes:
   5006  */
   5007 int
   5008 bcm_esw_cosq_control_extended_set(
   5009     int unit, 
   5010     bcm_cosq_object_id_t *id,
   5011     bcm_cosq_control_data_t *control)
   5012 {
   5013 #ifdef BCM_TOMAHAWK3_SUPPORT
   5014     if (SOC_IS_TOMAHAWK3(unit)) {
   5015         return bcm_th3_cosq_control_set(unit, 
   5016             id->port, id->cosq, id->buffer, 
   5017             control->type, control->arg);
   5018     }
   5019 #endif /* BCM_TOMAHAWK3_SUPPORT */
   5020 #ifdef BCM_TOMAHAWK_SUPPORT
   5021     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   5022         return bcm_th_cosq_control_set(unit, 
   5023             id->port, id->cosq, id->buffer, 
   5024             control->type, control->arg);
   5025     }
   5026 #endif /* BCM_TOMAHAWK_SUPPORT */
   5027 
   5028     return BCM_E_UNAVAIL;
   5029 }
   5030 
   5031 /*
   5032  * Function:
   5033  *      bcm_esw_cosq_control_extended_get
   5034  * Purpose:
   5035  *      Get specified feature configuration
   5036  *
   5037  * Parameters:
   5038  *      unit    - (IN) Unit number
   5039  *      id      - (IN) Integrated cosq index
   5040  *      control - (INOUT) Integrated cosq control data
   5041  * Returns:
   5042  *      BCM_E_XXX
   5043  * Notes:
   5044  */
   5045 int
   5046 bcm_esw_cosq_control_extended_get(
   5047     int unit, 
   5048     bcm_cosq_object_id_t *id,
   5049     bcm_cosq_control_data_t *control)
   5050 {
   5051 #ifdef BCM_TOMAHAWK3_SUPPORT
   5052     if (SOC_IS_TOMAHAWK3(unit)) {
   5053         return bcm_th3_cosq_control_get(unit, 
   5054             id->port, id->cosq, id->buffer, 
   5055             control->type, &(control->arg));
   5056     }
   5057 #endif /* BCM_TOMAHAWK3_SUPPORT */
   5058 #ifdef BCM_TOMAHAWK_SUPPORT
   5059     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   5060         return bcm_th_cosq_control_get(unit, 
   5061             id->port, id->cosq, id->buffer, 
   5062             control->type, &(control->arg));
   5063     }
   5064 #endif /* BCM_TOMAHAWK_SUPPORT */
   5065 
   5066     return BCM_E_UNAVAIL;
   5067 }
   5068 
   5069 
   5070 STATIC int _bcm_esw_cosq_num_validate(int cosq, int max_cosq_per_port)
   5071 {
   5072     
   5073     if (((cosq >= 0) && (cosq < max_cosq_per_port)) || 
   5074         (cosq == BCM_COS_INVALID)) {
   5075         return BCM_E_NONE;
   5076     }
   5077 
   5078     return BCM_E_PARAM;
   5079 }
   5080 
   5081 /*
   5082  * Function:
   5083  *      _bcm_cosq_stat_get
   5084  * Purpose:
   5085  *      Get MMU statistics on a per port per cosq basis.
   5086  * Parameters:
   5087  *      unit  - (IN) Unit number.
   5088  *      gport - (IN) GPORT ID
   5089  *      cosq  - (IN) COS queue.
   5090  *      stat  - (IN) Statistic to be retrieved.
   5091  *      value - (OUT) Returned statistic value.
   5092  * Returns:
   5093  *      BCM_E_xxx
   5094  * Notes:
   5095  *      Triumph and Triumph2 have the following MMU drop counters:
   5096  *        - Per cosq packet drop:            DROP_PKT_CNT.
   5097  *        - Per cosq byte drop:              DROP_BYTE_CNT.
   5098  *        - Additional per port packet drop: DROP_PKT_CNT_ING.
   5099  *        - Additional per port byte drop:   DROP_BYTE_CNT_ING.
   5100  *        - Per port yellow packet drop:     DROP_PKT_CNT_YEL.
   5101  *        - Per port red packet drop:        DROP_PKT_CNT_RED.
   5102  *
   5103  *      Scorpion has the following MMU drop counters:
   5104  *        - Per cosq packet drop:            HOLDROP_PKT_CNT.
   5105  *        - Additional per port packet drop: IBP_DROP_PKT_CNT, CFAP_DROP_PKT_CNT.
   5106  *        - Per port yellow packet drop:     YELLOW_CNG_DROP_CNT.
   5107  *        - Per port red packet drop:        RED_CN_DROP_CNT.
   5108  *
   5109  *      Bradley has the following MMU drop counters:
   5110  *        - Per port packet drop:            DROP_PKT_CNT.
   5111  *
   5112  *      Firebolt and Hurricane have the following MMU drop counters:
   5113  *        - Per port packet drop:            EGRDROPPKTCOUNT.
   5114  *        - Per port yellow packet drop:     CNGDROPCOUNT1.
   5115  *        - Per port red packet drop:        CNGDROPCOUNT0.
   5116  */
   5117 int 
   5118 _bcm_esw_cosq_stat_get(
   5119                        int unit, 
   5120                        bcm_gport_t gport, 
   5121                        bcm_cos_queue_t cosq, 
   5122                        bcm_cosq_stat_t stat, 
   5123                        int sync_mode, 
   5124                        uint64 *value)
   5125 {
   5126     int max_cosq_per_port;
   5127     bcm_port_t local_port;
   5128     int (*counter_get) (int , soc_port_t , soc_reg_t , int , uint64 *);
   5129 
   5130 #ifdef BCM_TOMAHAWK3_SUPPORT
   5131     if (SOC_IS_TOMAHAWK3(unit)) {
   5132         return bcm_th3_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5133     }
   5134 #endif /* BCM_TOMAHAWK3_SUPPORT */
   5135 #ifdef BCM_TOMAHAWK_SUPPORT
   5136     if (SOC_IS_TOMAHAWKX(unit)) {
   5137         return bcm_th_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5138     }
   5139 #endif /* BCM_TOMAHAWK_SUPPORT */
   5140 #ifdef BCM_MONTEREY_SUPPORT
   5141    if (SOC_IS_MONTEREY(unit)) {
   5142        return bcm_mn_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5143    }
   5144 #endif /* BCM_MONTEREY_SUPPORT */
   5145 #ifdef BCM_HELIX5_SUPPORT
   5146     if (SOC_IS_HELIX5(unit)) {
   5147         return bcm_hx5_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5148     }
   5149 #endif /* BCM_HELIX5_SUPPORT */
   5150 #ifdef BCM_TRIDENT3_SUPPORT
   5151     if (SOC_IS_TRIDENT3X(unit)) {
   5152         return bcm_td3_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5153     }
   5154 #endif /* BCM_TRIDENT3_SUPPORT */
   5155 #ifdef BCM_APACHE_SUPPORT
   5156     if (SOC_IS_APACHE(unit)) {
   5157         return bcm_ap_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5158     }
   5159 #endif /* BCM_APACHE_SUPPORT */
   5160 #ifdef BCM_TRIDENT2_SUPPORT
   5161     if (SOC_IS_TD2_TT2(unit)) {
   5162         return bcm_td2_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5163     }
   5164 #endif /* BCM_TRIDENT_SUPPORT */
   5165 #ifdef BCM_TRIDENT_SUPPORT
   5166     if (SOC_IS_TD_TT(unit)) {
   5167         return bcm_td_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5168     }
   5169 #endif /* BCM_TRIDENT_SUPPORT */
   5170 #ifdef BCM_KATANA_SUPPORT
   5171     if (SOC_IS_KATANA(unit)) {
   5172         return bcm_kt_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5173     }
   5174 #endif /* BCM_KATANA_SUPPORT */
   5175 #ifdef BCM_KATANA2_SUPPORT
   5176     if (SOC_IS_KATANA2(unit)) {
   5177         return bcm_kt2_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5178     }
   5179 #endif /* BCM_KATANA2_SUPPORT */
   5180 
   5181 #ifdef BCM_TRIUMPH3_SUPPORT
   5182     if (SOC_IS_TRIUMPH3(unit)) {
   5183         return bcm_tr3_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5184     }
   5185 #endif /* BCM_TRIDENT_SUPPORT */
   5186 
   5187 #ifdef BCM_GREYHOUND2_SUPPORT
   5188     if (SOC_IS_GREYHOUND2(unit)) {
   5189         return bcmi_gh2_cosq_stat_get(unit, gport, cosq, stat, sync_mode,
   5190                                       value);
   5191     }
   5192 #endif /* BCM_GREYHOUND2_SUPPORT */
   5193 
   5194     if (SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
   5195          SOC_IS_TR_VL(unit) || SOC_IS_SC_CQ(unit) ||
   5196          SOC_IS_HB_GW(unit) || SOC_IS_FB_FX_HX(unit)) {
   5197         max_cosq_per_port = 0;
   5198     } else {
   5199         return BCM_E_UNAVAIL;
   5200     }
   5201 
   5202 
   5203     if (value == NULL) {
   5204         return BCM_E_PARAM;
   5205     }        
   5206 
   5207     /*
   5208      * if sync-mode is set, update the software cached counter value, 
   5209      * with the hardware count and then retrieve the count.
   5210      * else return the software cache counter value.
   5211      */
   5212     counter_get = (sync_mode == 1)? soc_counter_sync_get: soc_counter_get;
   5213 
   5214     COMPILER_64_ZERO(*value);
   5215 
   5216     switch (stat) {
   5217         case bcmCosqStatDroppedPackets:
   5218 #ifdef BCM_TRIUMPH_SUPPORT
   5219             if (SOC_IS_TR_VL(unit) && !(SOC_IS_HURRICANE(unit))) {
   5220                 uint64 val64;
   5221                 int i, rv;
   5222                 BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5223                 if (soc_feature(unit, soc_feature_wh2)) {
   5224                     BCM_IF_ERROR_RETURN(
   5225                         bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
   5226                 } else {
   5227                     max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
   5228                                             NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5229                 }
   5230                 BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5231                 if (cosq == BCM_COS_INVALID) {
   5232                     for (i = 0; i < max_cosq_per_port; i++) {
   5233                         rv = counter_get(unit, local_port, 
   5234                                 SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, i, &val64);
   5235                         if (SOC_SUCCESS(rv)) {
   5236                             COMPILER_64_ADD_64(*value, val64);
   5237                         } else {
   5238                             break;
   5239                         }
   5240                     }
   5241                 } else {
   5242                     SOC_IF_ERROR_RETURN(counter_get(unit, local_port, 
   5243                         SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, cosq, value));
   5244                 } 
   5245             } else 
   5246 #endif /* BCM_TRIUMPH_SUPPORT */
   5247 #ifdef BCM_SCORPION_SUPPORT
   5248             if (SOC_IS_SC_CQ(unit)) {
   5249                 uint64 val64;
   5250                 int i, rv;
   5251                 BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5252                 max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5253                 BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5254                 if (cosq == BCM_COS_INVALID) {
   5255                     for (i = 0; i < max_cosq_per_port; i++) {
   5256                         rv = counter_get(unit, local_port, 
   5257                                 SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, i, &val64);
   5258                         if (SOC_SUCCESS(rv)) {
   5259                             COMPILER_64_ADD_64(*value, val64);
   5260                         } else {
   5261                             break;
   5262                         }
   5263                     }
   5264 
   5265                     /* Also add per port IBP_DROP_PKT_CNT */
   5266                     SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
   5267                         SOC_COUNTER_NON_DMA_PORT_DROP_PKT_IBP, 0, &val64));
   5268                     COMPILER_64_ADD_64(*value, val64);
   5269 
   5270                     /* Also add per port CFAP_DROP_PKT_CNT */
   5271                     SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
   5272                         SOC_COUNTER_NON_DMA_PORT_DROP_PKT_CFAP, 0, &val64));
   5273                     COMPILER_64_ADD_64(*value, val64);
   5274                 } else {
   5275                     SOC_IF_ERROR_RETURN(counter_get(unit, local_port, 
   5276                         SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, cosq, value));
   5277                 } 
   5278             } else 
   5279 #endif /* BCM_SCORPION_SUPPORT */
   5280 #ifdef BCM_BRADLEY_SUPPORT
   5281             if (SOC_IS_HB_GW(unit)) {
   5282                 BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5283                 max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5284                 BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5285                 /* Only the per port DROP_PKT_CNT is available */
   5286                 if (cosq != BCM_COS_INVALID) {
   5287                     return BCM_E_UNAVAIL;
   5288                 }
   5289                 SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
   5290                        SOC_COUNTER_NON_DMA_PORT_DROP_PKT, 0, value));
   5291             } else 
   5292 #endif /* BCM_BRADLEY_SUPPORT */
   5293 #ifdef BCM_FIREBOLT_SUPPORT
   5294             if (SOC_IS_FB_FX_HX(unit) || SOC_IS_HURRICANE(unit)) {
   5295                 BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5296                 max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5297                 BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port)); 
   5298                 /* Only the per port EGRDROPPKTCOUNT is available */
   5299                 if (cosq != BCM_COS_INVALID) {
   5300                     return BCM_E_UNAVAIL;
   5301                 }
   5302                 _bcm_stat_counter_extra_get(unit, EGRDROPPKTCOUNTr,
   5303                     local_port, value);
   5304             } else 
   5305 #endif /* BCM_FIREBOLT_SUPPORT */
   5306             {
   5307                 return BCM_E_UNAVAIL;
   5308             }
   5309 
   5310             break;
   5311 
   5312         case bcmCosqStatDroppedBytes:
   5313 #ifdef BCM_TRIUMPH_SUPPORT
   5314             if (SOC_IS_TR_VL(unit) && 
   5315                 !(SOC_IS_HURRICANEX(unit)||SOC_IS_GREYHOUND(unit) ||
   5316                 SOC_IS_GREYHOUND2(unit))) {
   5317                 uint64 val64;
   5318                 int i, rv;
   5319                 BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5320                 max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5321                 BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5322                 if (cosq == BCM_COS_INVALID) {
   5323                     for (i = 0; i < max_cosq_per_port; i++) {
   5324                         rv = counter_get(unit, local_port, 
   5325                                 SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, i, &val64);
   5326                         if (SOC_SUCCESS(rv)) {
   5327                             COMPILER_64_ADD_64(*value, val64);
   5328                         } else {
   5329                             break;
   5330                         }
   5331                     }
   5332 
   5333                     /* Also add the per port DROP_BYTE_CNT_ING */
   5334                     SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
   5335                         SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_ING, 0, &val64));
   5336                     COMPILER_64_ADD_64(*value, val64);
   5337                 } else {
   5338                     SOC_IF_ERROR_RETURN(counter_get(unit, local_port, 
   5339                         SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, cosq, value));
   5340                 } 
   5341             } else 
   5342 #endif /* BCM_TRIUMPH_SUPPORT */
   5343             {
   5344                 return BCM_E_UNAVAIL;
   5345             }
   5346             break;
   5347 
   5348         case bcmCosqStatYellowCongestionDroppedPackets:
   5349             BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5350             if (soc_feature(unit, soc_feature_wh2)) {
   5351                 BCM_IF_ERROR_RETURN(
   5352                     bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
   5353             } else {
   5354                 max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
   5355                                         NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5356             }
   5357             BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5358             if (cosq != BCM_COS_INVALID) {
   5359                 /* Yellow dropped packet counters are available only on a per
   5360                  * port basis.
   5361                  */
   5362                 return BCM_E_UNAVAIL;
   5363             }
   5364             SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
   5365                 SOC_COUNTER_NON_DMA_PORT_DROP_PKT_YELLOW, 0, value));
   5366             break;
   5367 
   5368         case bcmCosqStatRedCongestionDroppedPackets:
   5369             BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5370             if (soc_feature(unit, soc_feature_wh2)) {
   5371                 BCM_IF_ERROR_RETURN(
   5372                     bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
   5373             } else {
   5374                 max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
   5375                                         NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5376             }
   5377             BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5378             if (cosq != BCM_COS_INVALID) {
   5379                 /* Red dropped packet counters are available only on a per
   5380                  * port basis.
   5381                  */
   5382                 return BCM_E_UNAVAIL;
   5383             }
   5384             SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
   5385                 SOC_COUNTER_NON_DMA_PORT_DROP_PKT_RED, 0, value));
   5386             break;
   5387 
   5388         case bcmCosqStatOutPackets:
   5389 #ifdef BCM_TRIUMPH_SUPPORT
   5390             if (SOC_IS_TR_VL(unit)) {
   5391                 uint64 val64;
   5392                 int i, rv;
   5393                 BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5394                 if (soc_feature(unit, soc_feature_wh2)) {
   5395                     BCM_IF_ERROR_RETURN(
   5396                         bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
   5397                 } else {
   5398                     max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
   5399                                             NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5400                 }
   5401                 BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5402                 COMPILER_64_ZERO(*value);
   5403                 if (cosq == BCM_COS_INVALID) {
   5404                     for (i = 0; i < max_cosq_per_port; i++) {
   5405                         rv = counter_get(unit, local_port,
   5406                                              SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, i, &val64);
   5407                         if (SOC_SUCCESS(rv)) {
   5408                             COMPILER_64_ADD_64(*value, val64);
   5409                         } else {
   5410                             break;
   5411                         }
   5412                     }
   5413                 } else {
   5414                     SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
   5415                                                         SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, cosq, value));
   5416                 }
   5417              
   5418             } else 
   5419 #endif
   5420             {
   5421                 return BCM_E_UNAVAIL;
   5422             }
   5423         break;
   5424 
   5425         case bcmCosqStatOutBytes:
   5426 #ifdef BCM_TRIUMPH_SUPPORT
   5427             if (SOC_IS_TR_VL(unit)) {
   5428             uint64 val64;
   5429             int i, rv;
   5430             BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5431             if (soc_feature(unit, soc_feature_wh2)) {
   5432                 BCM_IF_ERROR_RETURN(
   5433                     bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
   5434             } else {
   5435                 max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
   5436                                         NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5437             }
   5438             BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5439             COMPILER_64_ZERO(*value);
   5440             if (cosq == BCM_COS_INVALID) {
   5441                 for (i = 0; i < max_cosq_per_port; i++) {
   5442                     rv = counter_get(unit, local_port,
   5443                                          SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, i, &val64);
   5444                     if (SOC_SUCCESS(rv)) {
   5445                         COMPILER_64_ADD_64(*value, val64);
   5446                     } else {
   5447                         break;
   5448                     }
   5449                 }
   5450             } else {
   5451                 SOC_IF_ERROR_RETURN(counter_get(unit, local_port,
   5452                                                     SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, cosq, value));
   5453             }
   5454         } else 
   5455 #endif
   5456         {
   5457             return BCM_E_UNAVAIL;
   5458         }
   5459         break;
   5460 
   5461         case bcmCosqStatDiscardDroppedPackets:
   5462 #if defined(BCM_GREYHOUND_SUPPORT)
   5463         if (soc_feature(unit, soc_feature_wred_drop_counter_per_port)) {
   5464 
   5465             BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5466             if (soc_feature(unit, soc_feature_wh2)) {
   5467                 BCM_IF_ERROR_RETURN(
   5468                     bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
   5469             } else {
   5470                 max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
   5471                                         NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5472             }
   5473             BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5474             COMPILER_64_ZERO(*value);
   5475             if (cosq == BCM_COS_INVALID) {
   5476                 SOC_IF_ERROR_RETURN(soc_counter_get(unit, local_port, 
   5477                             SOC_COUNTER_NON_DMA_PORT_WRED_DROP_PKT, 0, value));
   5478                 
   5479             } else {
   5480                 return BCM_E_UNAVAIL;
   5481             }
   5482         } else 
   5483 #endif
   5484         {
   5485             return BCM_E_UNAVAIL;
   5486         }
   5487         break;
   5488     case bcmCosqStatHOLDropPackets:
   5489 #if defined(BCM_HURRICANE2_SUPPORT)
   5490     if (soc_feature(unit,soc_feature_cosq_hol_drop_packet_count)) {
   5491         bcm_port_t selected_port;
   5492         uint32 rval;
   5493         int i;
   5494         static soc_reg_t hold_reg[] = {
   5495             HOLD_COS0r, HOLD_COS1r, HOLD_COS2r, HOLD_COS3r,
   5496             HOLD_COS4r, HOLD_COS5r, HOLD_COS6r, HOLD_COS7r,
   5497         };
   5498     
   5499         if (!SOC_REG_IS_VALID(unit, HOLD_COS0r)) {
   5500             return BCM_E_UNAVAIL;
   5501         }
   5502         if (!SOC_REG_IS_VALID(unit, HOLD_COS_PORT_SELECTr)) {
   5503             return BCM_E_UNAVAIL;
   5504         }
   5505 
   5506         BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5507         if (soc_feature(unit, soc_feature_wh2)) {
   5508             BCM_IF_ERROR_RETURN(
   5509                 bcm_esw_cosq_config_get(unit, &max_cosq_per_port));
   5510         } else {
   5511             max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
   5512                                     NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5513         }
   5514         BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   5515         COMPILER_64_ZERO(*value);
   5516     
   5517         SOC_IF_ERROR_RETURN(READ_HOLD_COS_PORT_SELECTr(unit, &rval)); 
   5518         selected_port = soc_reg_field_get(unit, HOLD_COS_PORT_SELECTr, rval,
   5519                             PORT_NUMf);
   5520     
   5521         if (selected_port != local_port) {
   5522             return BCM_E_PORT;
   5523         }
   5524         if (cosq == BCM_COS_INVALID) {
   5525             for (i = 0; i < COUNTOF(hold_reg); i++) {
   5526                 SOC_IF_ERROR_RETURN(soc_reg32_get(unit, hold_reg[i], REG_PORT_ANY, 0, &rval));
   5527                 COMPILER_64_ADD_32(*value, rval);
   5528            }
   5529         } else {
   5530             if (cosq >= COUNTOF(hold_reg)) {
   5531                 return BCM_E_PARAM;
   5532             }
   5533             SOC_IF_ERROR_RETURN(soc_reg32_get(unit, hold_reg[cosq], REG_PORT_ANY, 0, &rval));
   5534             COMPILER_64_ADD_32(*value, rval);
   5535         }
   5536     } else 
   5537 #endif
   5538     {
   5539     return BCM_E_UNAVAIL;
   5540     }
   5541 break;
   5542             
   5543         default:
   5544             return BCM_E_UNAVAIL;
   5545     }
   5546 
   5547     return BCM_E_NONE;
   5548 }
   5549 
   5550 /*
   5551  * Function:
   5552  *      bcm_cosq_stat_get
   5553  * Purpose:
   5554  *      Get MMU statistics on a per port per cosq basis.
   5555  * Parameters:
   5556  *      unit  - (IN) Unit number.
   5557  *      gport - (IN) GPORT ID
   5558  *      cosq  - (IN) COS queue.
   5559  *      stat  - (IN) Statistic to be retrieved.
   5560  *      value - (OUT) Returned statistic value.
   5561  * Returns:
   5562  *      BCM_E_xxx
   5563  * Notes:
   5564  *      Triumph and Triumph2 have the following MMU drop counters:
   5565  *        - Per cosq packet drop:            DROP_PKT_CNT.
   5566  *        - Per cosq byte drop:              DROP_BYTE_CNT.
   5567  *        - Additional per port packet drop: DROP_PKT_CNT_ING.
   5568  *        - Additional per port byte drop:   DROP_BYTE_CNT_ING.
   5569  *        - Per port yellow packet drop:     DROP_PKT_CNT_YEL.
   5570  *        - Per port red packet drop:        DROP_PKT_CNT_RED.
   5571  *
   5572  *      Scorpion has the following MMU drop counters:
   5573  *        - Per cosq packet drop:            HOLDROP_PKT_CNT.
   5574  *        - Additional per port packet drop: IBP_DROP_PKT_CNT, CFAP_DROP_PKT_CNT.
   5575  *        - Per port yellow packet drop:     YELLOW_CNG_DROP_CNT.
   5576  *        - Per port red packet drop:        RED_CN_DROP_CNT.
   5577  *
   5578  *      Bradley has the following MMU drop counters:
   5579  *        - Per port packet drop:            DROP_PKT_CNT.
   5580  *
   5581  *      Firebolt and Hurricane have the following MMU drop counters:
   5582  *        - Per port packet drop:            EGRDROPPKTCOUNT.
   5583  *        - Per port yellow packet drop:     CNGDROPCOUNT1.
   5584  *        - Per port red packet drop:        CNGDROPCOUNT0.
   5585  */
   5586 int 
   5587 bcm_esw_cosq_stat_get(
   5588                       int unit, 
   5589                       bcm_gport_t gport, 
   5590                       bcm_cos_queue_t cosq, 
   5591                       bcm_cosq_stat_t stat, 
   5592                       uint64 *value)
   5593 {
   5594     int sync_mode = 0;
   5595 
   5596     if (NULL == value) {
   5597         return (BCM_E_PARAM);
   5598     }
   5599 
   5600     return _bcm_esw_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5601 
   5602     return BCM_E_NONE;
   5603 }
   5604 
   5605 /*
   5606  * Function:
   5607  *      bcm_cosq_stat_get32
   5608  * Purpose:
   5609  *      Get MMU statistics on a per port per cosq basis.
   5610  * Parameters:
   5611  *      unit  - (IN) Unit number.
   5612  *      gport - (IN) GPORT ID
   5613  *      cosq  - (IN) COS queue.
   5614  *      stat  - (IN) Statistic to be retrieved.
   5615  *      value - (OUT) Returned statistic value.
   5616  * Returns:
   5617  *      BCM_E_xxx
   5618  * Notes:
   5619  */
   5620 int 
   5621 bcm_esw_cosq_stat_get32(
   5622                         int unit, 
   5623                         bcm_gport_t gport, 
   5624                         bcm_cos_queue_t cosq, 
   5625                         bcm_cosq_stat_t stat, 
   5626                         uint32 *value)
   5627 {
   5628     uint64 val64;
   5629     int rv;
   5630 
   5631     if (NULL == value) {
   5632         return (BCM_E_PARAM);
   5633     }
   5634 
   5635     rv = bcm_esw_cosq_stat_get(unit, gport, cosq, stat, &val64);
   5636 
   5637     if (BCM_SUCCESS(rv)) {
   5638         *value = COMPILER_64_LO(val64);
   5639     }
   5640 
   5641     return rv;
   5642 }
   5643 
   5644 /*
   5645  * Function:
   5646  *      bcm_cosq_stat_sync_get
   5647  * Purpose:
   5648  *      Get MMU statistics on a per port per cosq basis.
   5649  *      The software cached count is synced with the hardware 
   5650  *      value. 
   5651  * Parameters:
   5652  *      unit  - (IN) Unit number.
   5653  *      gport - (IN) GPORT ID
   5654  *      cosq  - (IN) COS queue.
   5655  *      stat  - (IN) Statistic to be retrieved.
   5656  *      value - (OUT) Returned statistic value.
   5657  * Returns:
   5658  *      BCM_E_xxx
   5659  * Notes:
   5660  *      Triumph and Triumph2 have the following MMU drop counters:
   5661  *        - Per cosq packet drop:            DROP_PKT_CNT.
   5662  *        - Per cosq byte drop:              DROP_BYTE_CNT.
   5663  *        - Additional per port packet drop: DROP_PKT_CNT_ING.
   5664  *        - Additional per port byte drop:   DROP_BYTE_CNT_ING.
   5665  *        - Per port yellow packet drop:     DROP_PKT_CNT_YEL.
   5666  *        - Per port red packet drop:        DROP_PKT_CNT_RED.
   5667  *
   5668  *      Scorpion has the following MMU drop counters:
   5669  *        - Per cosq packet drop:            HOLDROP_PKT_CNT.
   5670  *        - Additional per port packet drop: IBP_DROP_PKT_CNT, CFAP_DROP_PKT_CNT.
   5671  *        - Per port yellow packet drop:     YELLOW_CNG_DROP_CNT.
   5672  *        - Per port red packet drop:        RED_CN_DROP_CNT.
   5673  *
   5674  *      Bradley has the following MMU drop counters:
   5675  *        - Per port packet drop:            DROP_PKT_CNT.
   5676  *
   5677  *      Firebolt and Hurricane have the following MMU drop counters:
   5678  *        - Per port packet drop:            EGRDROPPKTCOUNT.
   5679  *        - Per port yellow packet drop:     CNGDROPCOUNT1.
   5680  *        - Per port red packet drop:        CNGDROPCOUNT0.
   5681  */
   5682 int 
   5683 bcm_esw_cosq_stat_sync_get(
   5684                            int unit, 
   5685                            bcm_gport_t gport, 
   5686                            bcm_cos_queue_t cosq, 
   5687                            bcm_cosq_stat_t stat, 
   5688                            uint64 *value)
   5689 {
   5690     int sync_mode = 1;
   5691 
   5692     if (NULL == value) {
   5693         return (BCM_E_PARAM);
   5694     }
   5695 
   5696     return _bcm_esw_cosq_stat_get(unit, gport, cosq, stat, sync_mode, value);
   5697 }
   5698 
   5699 /*
   5700  * Function:
   5701  *      bcm_esw_cosq_stat_sync_multi_get
   5702  * Purpose:
   5703  *      Get multiple MMU statistics on a per port per cosq basis.
   5704  *      The software cached count is synced with the hardware
   5705  *      value.
   5706  * Parameters:
   5707  *      unit  - (IN) Unit number.
   5708  *      gport - (IN) GPORT ID
   5709  *      cosq  - (IN) COS queue.
   5710  *      nstat - (IN) Number of elements in stat array
   5711  *      stat_arr - (IN) Array of statistics types defined in bcm_cos_queue_t
   5712  *      value_arr - (OUT) Array of collected statistics values
   5713  * Returns:
   5714  *      BCM_E_xxx
   5715  */
   5716 int
   5717 bcm_esw_cosq_stat_sync_multi_get(
   5718                            int unit,
   5719                            bcm_gport_t gport,
   5720                            bcm_cos_queue_t cosq,
   5721                            int nstat,
   5722                            bcm_cosq_stat_t *stat_arr,
   5723                            uint64 *value_arr)
   5724 {
   5725     int sync_mode = 1;
   5726     int stix;
   5727 
   5728     if (nstat <= 0) {
   5729         return BCM_E_PARAM;
   5730     }
   5731 
   5732     if ((NULL == stat_arr) || (NULL == value_arr)) {
   5733         return BCM_E_PARAM;
   5734     }
   5735 
   5736     for (stix = 0; stix < nstat; stix++) {
   5737         BCM_IF_ERROR_RETURN
   5738             (_bcm_esw_cosq_stat_get(unit, gport, cosq, stat_arr[stix],
   5739                 sync_mode,  &(value_arr[stix])));
   5740     }
   5741 
   5742     return BCM_E_NONE;
   5743 }
   5744 
   5745 /*
   5746  * Function:
   5747  *      bcm_cosq_stat_get32
   5748  * Purpose:
   5749  *      Get MMU statistics on a per port per cosq basis.
   5750  *      The software cached count is synced with the hardware 
   5751  *      value. 
   5752  * Parameters:
   5753  *      unit  - (IN) Unit number.
   5754  *      gport - (IN) GPORT ID
   5755  *      cosq  - (IN) COS queue.
   5756  *      stat  - (IN) Statistic to be retrieved.
   5757  *      value - (OUT) Returned statistic value.
   5758  * Returns:
   5759  *      BCM_E_xxx
   5760  * Notes:
   5761  */
   5762 int 
   5763 bcm_esw_cosq_stat_sync_get32(
   5764                              int unit, 
   5765                              bcm_gport_t gport, 
   5766                              bcm_cos_queue_t cosq, 
   5767                              bcm_cosq_stat_t stat, 
   5768                              uint32 *value)
   5769 {
   5770     uint64 val64;
   5771     int rv;
   5772 
   5773     if (NULL == value) {
   5774         return (BCM_E_PARAM);
   5775     }
   5776 
   5777     rv = bcm_esw_cosq_stat_sync_get(unit, gport, cosq, stat, &val64);
   5778 
   5779     if (BCM_SUCCESS(rv)) {
   5780         *value = COMPILER_64_LO(val64);
   5781     }
   5782 
   5783     return rv;
   5784 }
   5785 /*
   5786 
   5787  * Function:
   5788  *      bcm_esw_cosq_stat_sync_multi_get32
   5789  * Purpose:
   5790  *      Get multiple MMU statistics on a per port per cosq basis.
   5791  *      The software cached count is synced with the hardware
   5792  *      value.
   5793  * Parameters:
   5794  *      unit  - (IN) Unit number.
   5795  *      gport - (IN) GPORT ID
   5796  *      cosq  - (IN) COS queue.
   5797  *      nstat - (IN) Number of elements in stat array
   5798  *      stat_arr - (IN) Array of statistics types defined in bcm_cos_queue_t
   5799  *      value_arr - (OUT) Array of collected statistics values
   5800  * Returns:
   5801  *      BCM_E_xxx
   5802  */
   5803 int
   5804 bcm_esw_cosq_stat_sync_multi_get32(
   5805                            int unit,
   5806                            bcm_gport_t gport,
   5807                            bcm_cos_queue_t cosq,
   5808                            int nstat,
   5809                            bcm_cosq_stat_t *stat_arr,
   5810                            uint32 *value_arr)
   5811 {
   5812     int sync_mode = 1;
   5813     int stix;
   5814     uint64 val64;
   5815 
   5816     if (nstat <= 0) {
   5817         return BCM_E_PARAM;
   5818     }
   5819 
   5820     if ((NULL == stat_arr) || (NULL == value_arr)) {
   5821         return BCM_E_PARAM;
   5822     }
   5823 
   5824     for (stix = 0; stix < nstat; stix++) {
   5825         COMPILER_64_ZERO(val64);
   5826         BCM_IF_ERROR_RETURN
   5827             (_bcm_esw_cosq_stat_get(unit, gport, cosq, stat_arr[stix],
   5828                 sync_mode, &val64));
   5829         value_arr[stix] = COMPILER_64_LO(val64);
   5830     }
   5831 
   5832     return BCM_E_NONE;
   5833 }
   5834 
   5835 /*
   5836  * Function:
   5837  *      bcm_cosq_stat_set
   5838  * Purpose:
   5839  *      Set MMU statistics on a per port per cosq basis.
   5840  * Parameters:
   5841  *      unit  - (IN) Unit number.
   5842  *      gport - (IN) GPORT ID
   5843  *      cosq  - (IN) COS queue.
   5844  *      stat  - (IN) Statistic to be set.
   5845  *      value - (IN) Statistic value to be set.
   5846  * Returns:
   5847  *      BCM_E_xxx
   5848  * Notes:
   5849  */
   5850 int 
   5851 bcm_esw_cosq_stat_set(
   5852     int unit, 
   5853     bcm_gport_t gport, 
   5854     bcm_cos_queue_t cosq, 
   5855     bcm_cosq_stat_t stat, 
   5856     uint64 value)
   5857 {
   5858     int max_cosq_per_port;
   5859     bcm_port_t local_port;
   5860     int cosq_allowed=0;
   5861 
   5862 #ifdef BCM_TOMAHAWK3_SUPPORT
   5863     if (SOC_IS_TOMAHAWK3(unit)) {
   5864         return bcm_th3_cosq_stat_set(unit, gport, cosq, stat, value);
   5865     }
   5866 #endif /* BCM_TOMAHAWK3_SUPPORT */
   5867 
   5868 #ifdef BCM_TOMAHAWK_SUPPORT
   5869     if (SOC_IS_TOMAHAWKX(unit)) {
   5870         return bcm_th_cosq_stat_set(unit, gport, cosq, stat, value);
   5871     }
   5872 #endif /* BCM_TOMAHAWK_SUPPORT */
   5873 #ifdef BCM_MONTEREY_SUPPORT
   5874    if (SOC_IS_MONTEREY(unit)) {
   5875        return bcm_ap_cosq_stat_set(unit, gport, cosq, stat, value); 
   5876    }
   5877 #endif /* BCM_MONTEREY_SUPPORT */
   5878 
   5879 #ifdef BCM_HELIX5_SUPPORT
   5880     if (SOC_IS_HELIX5(unit)) {
   5881         return bcm_hx5_cosq_stat_set(unit, gport, cosq, stat, value);
   5882     }
   5883 #endif /* BCM_HELIX5_SUPPORT */
   5884 
   5885 #ifdef BCM_TRIDENT3_SUPPORT
   5886     if (SOC_IS_TRIDENT3X(unit)) {
   5887         return bcm_td3_cosq_stat_set(unit, gport, cosq, stat, value);
   5888     }
   5889 #endif /* BCM_TRIDENT3_SUPPORT */
   5890 
   5891 #ifdef BCM_APACHE_SUPPORT
   5892     if (SOC_IS_APACHE(unit)) {
   5893         return bcm_ap_cosq_stat_set(unit, gport, cosq, stat, value);
   5894     }
   5895 #endif /* BCM_TRIDENT2_SUPPORT */
   5896 
   5897 #ifdef BCM_TRIDENT2_SUPPORT
   5898     if (SOC_IS_TD2_TT2(unit)) {
   5899         return bcm_td2_cosq_stat_set(unit, gport, cosq, stat, value);
   5900     }
   5901 #endif /* BCM_TRIDENT2_SUPPORT */
   5902 
   5903 #ifdef BCM_TRIDENT_SUPPORT
   5904     if (SOC_IS_TD_TT(unit)) {
   5905         return bcm_td_cosq_stat_set(unit, gport, cosq, stat, value);
   5906     }
   5907 #endif /* BCM_TRIDENT_SUPPORT */
   5908 
   5909 #ifdef BCM_KATANA_SUPPORT
   5910         if (SOC_IS_KATANA(unit)) {
   5911             return bcm_kt_cosq_stat_set(unit, gport, cosq, stat, value);
   5912         }
   5913 #endif /* BCM_KATANA_SUPPORT */
   5914 
   5915 #ifdef BCM_KATANA2_SUPPORT
   5916         if (SOC_IS_KATANA2(unit)) {
   5917             return bcm_kt2_cosq_stat_set(unit, gport, cosq, stat, value);
   5918         }
   5919 #endif /* BCM_KATANA2_SUPPORT */
   5920 
   5921 #ifdef BCM_TRIUMPH3_SUPPORT
   5922     if (SOC_IS_TRIUMPH3(unit)) {
   5923         return bcm_tr3_cosq_stat_set(unit, gport, cosq, stat, value);
   5924     }
   5925 #endif /* BCM_TRIUMPH3_SUPPORT */
   5926 
   5927 #ifdef BCM_GREYHOUND2_SUPPORT
   5928     if (SOC_IS_GREYHOUND2(unit)) {
   5929         return bcmi_gh2_cosq_stat_set(unit, gport, cosq, stat, value);
   5930     }
   5931 #endif /* BCM_GREYHOUND2_SUPPORT */
   5932 
   5933     if (SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
   5934          SOC_IS_TR_VL(unit) || SOC_IS_SC_CQ(unit) ||
   5935          SOC_IS_HB_GW(unit) || SOC_IS_FB_FX_HX(unit)) {
   5936         max_cosq_per_port = 0;
   5937     } else {
   5938         return BCM_E_UNAVAIL;
   5939     }
   5940 
   5941     BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   5942 
   5943     if (soc_feature(unit, soc_feature_wh2)) {
   5944         BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit,
   5945                                                     &max_cosq_per_port));
   5946     } else {
   5947         max_cosq_per_port = IS_CPU_PORT(unit, local_port) ? \
   5948                                 NUM_CPU_COSQ(unit) : NUM_COS(unit);
   5949     }
   5950 
   5951     if (((cosq >= 0) && (cosq < max_cosq_per_port)) ||
   5952         (cosq == BCM_COS_INVALID)) {
   5953         cosq_allowed = 1;
   5954     }
   5955 
   5956     if (!cosq_allowed) {
   5957         return BCM_E_PARAM;
   5958     }
   5959 
   5960     switch (stat) {
   5961         case bcmCosqStatDroppedPackets:
   5962 #ifdef BCM_TRIUMPH_SUPPORT
   5963             if (SOC_IS_TR_VL(unit) && !(SOC_IS_HURRICANE(unit))) {
   5964                 uint64 val64_zero;
   5965                 int i, rv;
   5966                 COMPILER_64_ZERO(val64_zero);
   5967                 if (SOC_IS_HURRICANE3(unit) || SOC_IS_GREYHOUND(unit) ||
   5968                     SOC_IS_HURRICANE2(unit)) {
   5969                     /* Registers are read-only */
   5970                     return BCM_E_UNAVAIL;
   5971                 }
   5972                 if (cosq == BCM_COS_INVALID) {
   5973                     /* Write given value to first COS queue */
   5974                     rv = soc_counter_set(unit, local_port, 
   5975                             SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, 0, value);
   5976 
   5977                     /* Write zero to all other COS queues */
   5978                     for (i = 1; i < max_cosq_per_port; i++) {
   5979                         rv = soc_counter_set(unit, local_port, 
   5980                                 SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, i, val64_zero);
   5981                         if (SOC_FAILURE(rv)) {
   5982                             break;
   5983                         }
   5984                     }
   5985                 } else {
   5986                     SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port, 
   5987                         SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, cosq, value));
   5988                 } 
   5989             } else 
   5990 #endif /* BCM_TRIUMPH_SUPPORT */
   5991 #ifdef BCM_SCORPION_SUPPORT
   5992             if (SOC_IS_SC_CQ(unit)) {
   5993                 uint64 val64_zero;
   5994                 int i, rv;
   5995 
   5996                 COMPILER_64_ZERO(val64_zero);
   5997                 if (cosq == BCM_COS_INVALID) {
   5998                     /* Write given value to first COS queue */
   5999                     rv = soc_counter_set(unit, local_port, 
   6000                             SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, 0, value);
   6001 
   6002                     /* Write zero to all other COS queues */
   6003                     for (i = 1; i < max_cosq_per_port; i++) {
   6004                         rv = soc_counter_set(unit, local_port, 
   6005                                 SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, i, val64_zero);
   6006                         if (SOC_FAILURE(rv)) {
   6007                             break;
   6008                         }
   6009                     }
   6010 
   6011                     /* Also write zero to per port IBP_DROP_PKT_CNT */
   6012                     SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
   6013                         SOC_COUNTER_NON_DMA_PORT_DROP_PKT_IBP, 0, val64_zero));
   6014 
   6015                     /* Also write zero to per port CFAP_DROP_PKT_CNT */
   6016                     SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
   6017                         SOC_COUNTER_NON_DMA_PORT_DROP_PKT_CFAP, 0, val64_zero));
   6018                 } else {
   6019                     SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port, 
   6020                         SOC_COUNTER_NON_DMA_COSQ_DROP_PKT, cosq, value));
   6021                 } 
   6022             } else 
   6023 #endif /* BCM_SCORPION_SUPPORT */
   6024 #ifdef BCM_BRADLEY_SUPPORT
   6025             if (SOC_IS_HB_GW(unit)) {
   6026                 /* Only the per port DROP_PKT_CNT is available */
   6027                 if (cosq != BCM_COS_INVALID) {
   6028                     return BCM_E_UNAVAIL;
   6029                 }
   6030                 SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
   6031                        SOC_COUNTER_NON_DMA_PORT_DROP_PKT, 0, value));
   6032             } else 
   6033 #endif /* BCM_BRADLEY_SUPPORT */
   6034 #ifdef BCM_FIREBOLT_SUPPORT
   6035             if (SOC_IS_FB_FX_HX(unit) || SOC_IS_HURRICANE(unit)) {
   6036                 /* EGRDROPPKTCOUNT is read-only */
   6037                 return BCM_E_UNAVAIL;
   6038             } else 
   6039 #endif /* BCM_FIREBOLT_SUPPORT */
   6040             {
   6041                 return BCM_E_UNAVAIL;
   6042             }
   6043 
   6044             break;
   6045 
   6046         case bcmCosqStatDroppedBytes:
   6047 #ifdef BCM_TRIUMPH_SUPPORT
   6048             if (SOC_IS_TR_VL(unit) && 
   6049                 !(SOC_IS_HURRICANEX(unit)||SOC_IS_GREYHOUND(unit))) {
   6050                 uint64 val64_zero;
   6051                 int i, rv;
   6052 
   6053                 COMPILER_64_ZERO(val64_zero);
   6054                 if (cosq == BCM_COS_INVALID) {
   6055                     /* Write given value to first COS queue */
   6056                     rv = soc_counter_set(unit, local_port, 
   6057                             SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, 0, value);
   6058 
   6059                     /* Write zero to all other COS queues */
   6060                     for (i = 1; i < max_cosq_per_port; i++) {
   6061                         rv = soc_counter_set(unit, local_port, 
   6062                                 SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, i, val64_zero);
   6063                         if (SOC_FAILURE(rv)) {
   6064                             break;
   6065                         }
   6066                     }
   6067 
   6068                     /* Also write zero to per port DROP_BYTE_CNT_ING */
   6069                     SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
   6070                         SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_ING, 0, val64_zero));
   6071                 } else {
   6072                     SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port, 
   6073                         SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE, cosq, value));
   6074                 } 
   6075             } else 
   6076 #endif /* BCM_TRIUMPH_SUPPORT */
   6077             {
   6078                 return BCM_E_UNAVAIL;
   6079             }
   6080             break;
   6081 
   6082         case bcmCosqStatYellowCongestionDroppedPackets:
   6083             if (cosq != BCM_COS_INVALID) {
   6084                 /* Yellow dropped packet counters are available only on a per
   6085                  * port basis.
   6086                  */
   6087                 return BCM_E_UNAVAIL;
   6088             }
   6089             if (SOC_IS_FB_FX_HX(unit) || SOC_IS_HURRICANEX(unit) ||
   6090                 SOC_IS_GREYHOUND(unit)) {
   6091                 /* CNGDROPCOUNT1 is read-only */
   6092                 return BCM_E_UNAVAIL;
   6093             }
   6094             SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
   6095                 SOC_COUNTER_NON_DMA_PORT_DROP_PKT_YELLOW, 0, value));
   6096             break;
   6097 
   6098         case bcmCosqStatRedCongestionDroppedPackets:
   6099             if (cosq != BCM_COS_INVALID) {
   6100                 /* Red dropped packet counters are available only on a per
   6101                  * port basis.
   6102                  */
   6103                 return BCM_E_UNAVAIL;
   6104             }
   6105             if (SOC_IS_FB_FX_HX(unit) || SOC_IS_HURRICANEX(unit) ||
   6106                 SOC_IS_GREYHOUND(unit)) {
   6107                 /* CNGDROPCOUNT0 is read-only */
   6108                 return BCM_E_UNAVAIL;
   6109             }
   6110             SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port,
   6111                 SOC_COUNTER_NON_DMA_PORT_DROP_PKT_RED, 0, value));
   6112             break;
   6113         case bcmCosqStatOutPackets:
   6114 #ifdef BCM_TRIUMPH_SUPPORT
   6115             if (SOC_IS_TR_VL(unit)) {
   6116                 uint64 val64_zero;
   6117                 int i, rv;
   6118 
   6119                 COMPILER_64_ZERO(val64_zero);
   6120                 if (cosq == BCM_COS_INVALID) {
   6121                     /* Write given value to first COS queue */
   6122                     rv = soc_counter_set(unit, local_port, 
   6123                             SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, 0, value);
   6124 
   6125                     /* Write zero to all other COS queues */
   6126                     for (i = 1; i < max_cosq_per_port; i++) {
   6127                         rv = soc_counter_set(unit, local_port, 
   6128                                 SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, i, val64_zero);
   6129                         if (SOC_FAILURE(rv)) {
   6130                             break;
   6131                         }
   6132                     }
   6133                 } else {
   6134                     SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port, 
   6135                         SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT, cosq, value));
   6136                 } 
   6137 
   6138             } else 
   6139 #endif
   6140             {
   6141                 return BCM_E_UNAVAIL;
   6142             }
   6143         break;
   6144 
   6145         case bcmCosqStatOutBytes:
   6146 #ifdef BCM_TRIUMPH_SUPPORT
   6147             if (SOC_IS_TR_VL(unit)) {
   6148                 uint64 val64_zero;
   6149                 int i, rv;
   6150 
   6151                 COMPILER_64_ZERO(val64_zero);
   6152                 if (cosq == BCM_COS_INVALID) {
   6153                     /* Write given value to first COS queue */
   6154                     rv = soc_counter_set(unit, local_port, 
   6155                             SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, 0, value);
   6156 
   6157                     /* Write zero to all other COS queues */
   6158                     for (i = 1; i < max_cosq_per_port; i++) {
   6159                         rv = soc_counter_set(unit, local_port, 
   6160                                 SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, i, val64_zero);
   6161                         if (SOC_FAILURE(rv)) {
   6162                             break;
   6163                         }
   6164                     }
   6165                 } else {
   6166                     SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port, 
   6167                         SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE, cosq, value));
   6168                 } 
   6169 
   6170             } else 
   6171 #endif
   6172             {
   6173                 return BCM_E_UNAVAIL;
   6174             }
   6175         break;		
   6176 
   6177         case bcmCosqStatDiscardDroppedPackets:
   6178 #if defined(BCM_GREYHOUND_SUPPORT)
   6179         if (soc_feature(unit, soc_feature_wred_drop_counter_per_port)) {
   6180             
   6181             if (cosq == BCM_COS_INVALID) {
   6182                 SOC_IF_ERROR_RETURN(soc_counter_set(unit, local_port, 
   6183                             SOC_COUNTER_NON_DMA_PORT_WRED_DROP_PKT, 0, value));
   6184             } else {
   6185                 return BCM_E_UNAVAIL;
   6186             }
   6187         } else 
   6188 #endif
   6189         {
   6190             return BCM_E_UNAVAIL;
   6191         }
   6192         break;
   6193     case bcmCosqStatHOLDropPackets:
   6194 #if defined(BCM_HURRICANE2_SUPPORT)
   6195         if (soc_feature(unit,soc_feature_cosq_hol_drop_packet_count)) {
   6196             int i;
   6197             static soc_reg_t hold_reg[] = {
   6198                 HOLD_COS0r, HOLD_COS1r, HOLD_COS2r, HOLD_COS3r,
   6199                 HOLD_COS4r, HOLD_COS5r, HOLD_COS6r, HOLD_COS7r,
   6200             };
   6201         
   6202             if (!SOC_REG_IS_VALID(unit, HOLD_COS0r)) {
   6203                 return BCM_E_UNAVAIL;
   6204             }
   6205         
   6206             if (!SOC_REG_IS_VALID(unit, HOLD_COS_PORT_SELECTr)) {
   6207                 return BCM_E_UNAVAIL;
   6208             }
   6209 
   6210             BCM_IF_ERROR_RETURN(_bcm_esw_port_gport_validate(unit, gport, &local_port));
   6211             BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, max_cosq_per_port));
   6212 
   6213             soc_reg_field32_modify(unit, HOLD_COS_PORT_SELECTr,
   6214                                 REG_PORT_ANY,
   6215                                 PORT_NUMf, local_port);
   6216         
   6217             if (cosq == BCM_COS_INVALID) {
   6218                 for (i = 0; i < COUNTOF(hold_reg); i++) {
   6219                     SOC_IF_ERROR_RETURN(soc_reg32_set(unit, hold_reg[i], 
   6220                        REG_PORT_ANY, 0, COMPILER_64_LO(value)));
   6221                 }
   6222             } else {
   6223                 if (cosq >= COUNTOF(hold_reg)) {
   6224                     return BCM_E_PARAM;
   6225                 }
   6226                 SOC_IF_ERROR_RETURN(soc_reg32_set(unit, hold_reg[cosq], 
   6227                        REG_PORT_ANY, 0, COMPILER_64_LO(value)));
   6228             }
   6229         } else 
   6230 #endif
   6231         {
   6232         return BCM_E_UNAVAIL;
   6233         }
   6234 break;
   6235 
   6236         default:
   6237             return BCM_E_PARAM;
   6238     }
   6239 
   6240     return BCM_E_NONE;
   6241 }
   6242 
   6243 /*
   6244  * Function:
   6245  *      bcm_cosq_stat_set32
   6246  * Purpose:
   6247  *      Set MMU statistics on a per port per cosq basis.
   6248  * Parameters:
   6249  *      unit  - (IN) Unit number.
   6250  *      gport - (IN) GPORT ID
   6251  *      cosq  - (IN) COS queue.
   6252  *      stat  - (IN) Statistic to be set.
   6253  *      value - (IN) Statistic value to be set.
   6254  * Returns:
   6255  *      BCM_E_xxx
   6256  * Notes:
   6257  */
   6258 int 
   6259 bcm_esw_cosq_stat_set32(
   6260     int unit, 
   6261     bcm_gport_t gport, 
   6262     bcm_cos_queue_t cosq, 
   6263     bcm_cosq_stat_t stat, 
   6264     uint32 value)
   6265 {
   6266     uint64 val64;
   6267 
   6268     COMPILER_64_SET(val64, 0, value);
   6269     return bcm_esw_cosq_stat_set(unit, gport, cosq, stat, val64);
   6270 }
   6271 
   6272 /*
   6273  * Function:
   6274  *      bcm_esw_cosq_subport_flow_control_set
   6275  * Purpose:
   6276  *      Set a port or node (L0, L1, L2) to flow control when
   6277  *      a CoE control frame is received on a subtended port.
   6278  * Parameters:
   6279  *      unit            - (IN) Unit number.
   6280  *      subport         - (IN) Subtended port
   6281  *      sched_port      - (IN) Node (Port, L0, L1, L2) to flow control 
   6282  * Returns:
   6283  *      BCM_E_xxx
   6284  * Notes:
   6285  */
   6286 int
   6287 bcm_esw_cosq_subport_flow_control_set(    
   6288     int unit, 
   6289     bcm_gport_t subport, 
   6290     bcm_gport_t sched_port)
   6291 {
   6292 
   6293 #ifdef BCM_HGPROXY_COE_SUPPORT 
   6294     if (soc_feature(unit, soc_feature_hgproxy_subtag_coe)) {
   6295 #ifdef BCM_APACHE_SUPPORT
   6296         if (SOC_IS_APACHE(unit)) {
   6297            return  bcm_ap_cosq_subport_flow_control_set(unit, subport, sched_port);
   6298         }  
   6299 #endif 
   6300         if (SOC_IS_TRIDENT2PLUS(unit)) {
   6301             bcm_td2p_cosq_subport_flow_control_set(unit, subport, sched_port);
   6302         } else {
   6303             return BCM_E_UNAVAIL;
   6304         }
   6305     } else
   6306 #endif /* BCM_HGPROXY_COE_SUPPORT */
   6307    {
   6308         return BCM_E_UNAVAIL;
   6309    }
   6310 
   6311     return BCM_E_NONE;
   6312 }
   6313 
   6314 /*
   6315  * Function:
   6316  *      bcm_esw_cosq_subport_flow_control_get
   6317  * Purpose:
   6318  *      Get a port or node (L0, L1, L2) that's flow controlled when
   6319  *      a CoE control frame is received on a subtended port.
   6320  * Parameters:
   6321  *      unit            - (IN) Unit number.
   6322  *      subport         - (IN) Subtended port
   6323  *      sched_port      - (IN) Node (Port, L0, L1, L2) being flow controlled 
   6324  * Returns:
   6325  *      BCM_E_xxx
   6326  * Notes:
   6327  */
   6328 int
   6329 bcm_esw_cosq_subport_flow_control_get(    
   6330     int unit, 
   6331     bcm_gport_t subport, 
   6332     bcm_gport_t * sched_port)
   6333 {
   6334 #ifdef BCM_HGPROXY_COE_SUPPORT 
   6335     if (soc_feature(unit, soc_feature_hgproxy_subtag_coe)) {
   6336 #ifdef BCM_APACHE_SUPPORT
   6337         if (SOC_IS_APACHE(unit)) {
   6338             return bcm_ap_cosq_subport_flow_control_get(unit, subport, sched_port);
   6339         } 
   6340 #endif         
   6341         if (SOC_IS_TRIDENT2PLUS(unit)) {
   6342             bcm_td2p_cosq_subport_flow_control_get(unit, subport, sched_port);
   6343         } else {
   6344             return BCM_E_UNAVAIL;
   6345         }
   6346     } else
   6347 #endif /* BCM_HGPROXY_COE_SUPPORT */
   6348     {
   6349         return BCM_E_UNAVAIL;
   6350     }
   6351 
   6352     return BCM_E_NONE;
   6353 }
   6354 
   6355 /*
   6356  * Function:
   6357  *      bcm_esw_cosq_gport_destmod_attach
   6358  * Purpose:
   6359  *      Attach gport mapping from ingress port, dest_modid to
   6360  *      fabric egress port.
   6361  * Parameters:
   6362  *      unit            - (IN) Unit number.
   6363  *      gport           - (IN) GPORT ID
   6364  *      ingress_port    - (IN) Ingress port
   6365  *      dest_modid      - (IN) Destination module ID
   6366  *      fabric_egress_port - (IN) Port number on fabric that 
   6367  *                             is connected to dest_modid
   6368  * Returns:
   6369  *      BCM_E_xxx
   6370  * Notes:
   6371  */
   6372 int bcm_esw_cosq_gport_destmod_attach(int unit, bcm_gport_t gport,
   6373                                       bcm_port_t ingress_port, 
   6374                                       bcm_module_t dest_modid, 
   6375                                       int fabric_egress_port)
   6376 {
   6377 #ifdef BCM_TRIDENT_SUPPORT
   6378     if (SOC_IS_TD_TT(unit) && !SOC_IS_APACHE(unit)) {
   6379         return bcm_td_cosq_gport_destmod_attach(unit, gport, ingress_port,
   6380                                            dest_modid, fabric_egress_port);
   6381     }
   6382 #endif
   6383     return BCM_E_UNAVAIL;
   6384 }
   6385 
   6386 /*
   6387  * Function:
   6388  *      bcm_esw_cosq_gport_destmod_detach
   6389  * Purpose:
   6390  *      Attach gport mapping from ingress port, dest_modid to
   6391  *      fabric egress port.
   6392  * Parameters:
   6393  *      unit            - (IN) Unit number.
   6394  *      gport           - (IN) GPORT ID
   6395  *      ingress_port    - (IN) Ingress port
   6396  *      dest_modid      - (IN) Destination module ID
   6397  *      fabric_egress_port - (IN) Port number on fabric that 
   6398  *                             is connected to dest_modid
   6399  * Returns:
   6400  *      BCM_E_xxx
   6401  * Notes:
   6402  */
   6403 int bcm_esw_cosq_gport_destmod_detach(int unit, bcm_gport_t gport,
   6404                                       bcm_port_t ingress_port, 
   6405                                       bcm_module_t dest_modid, 
   6406                                       int fabric_egress_port)
   6407 {
   6408 #ifdef BCM_TRIDENT_SUPPORT
   6409     if (SOC_IS_TD_TT(unit) && !SOC_IS_APACHE(unit)) {
   6410         return bcm_td_cosq_gport_destmod_detach(unit, gport, ingress_port,
   6411                                            dest_modid, fabric_egress_port);
   6412     }
   6413 #endif
   6414     return BCM_E_UNAVAIL;
   6415 }
   6416 
   6417 int bcm_esw_cosq_gport_congestion_config_set(int unit, bcm_gport_t gport, 
   6418                                          bcm_cos_queue_t cosq, 
   6419                                          bcm_cosq_congestion_info_t *config)
   6420 {
   6421 #ifdef BCM_MONTEREY_SUPPORT
   6422     if (SOC_IS_MONTEREY(unit)) {
   6423         return bcm_mn_cosq_gport_congestion_config_set(unit, gport, cosq, config);
   6424     }
   6425 #endif /* BCM_MONTEREY_SUPPORT */
   6426 #ifdef BCM_APACHE_SUPPORT
   6427     if (SOC_IS_APACHE(unit)) {
   6428         return bcm_ap_cosq_gport_congestion_config_set(unit, gport, cosq, config);
   6429     }
   6430 #endif
   6431 #ifdef BCM_TRIDENT2_SUPPORT
   6432     if (SOC_IS_TD2_TT2(unit)) {
   6433         return bcm_td2_cosq_gport_congestion_config_set(unit, gport, cosq, config);
   6434     }
   6435 #endif
   6436 #ifdef BCM_TRIUMPH3_SUPPORT
   6437     if (SOC_IS_TRIUMPH3(unit)) {
   6438         return bcm_tr3_cosq_gport_congestion_config_set(unit, gport, cosq, config);
   6439     }
   6440 #endif
   6441 #ifdef BCM_KATANA2_SUPPORT
   6442     if (SOC_IS_KATANA2(unit)) {
   6443         return bcm_kt2_cosq_gport_congestion_config_set(unit, gport, cosq, config);
   6444     }
   6445 #endif
   6446     return BCM_E_UNAVAIL;
   6447 }
   6448 
   6449 int bcm_esw_cosq_gport_congestion_config_get(int unit, bcm_gport_t gport, 
   6450                                          bcm_cos_queue_t cosq, 
   6451                                          bcm_cosq_congestion_info_t *config)
   6452 {
   6453 #ifdef BCM_MONTEREY_SUPPORT
   6454     if (SOC_IS_MONTEREY(unit)) {
   6455         return bcm_mn_cosq_gport_congestion_config_get(unit, gport, cosq, config);
   6456     }
   6457 #endif /* BCM_MONTEREY_SUPPORT */
   6458 #ifdef BCM_APACHE_SUPPORT
   6459     if (SOC_IS_APACHE(unit)) {
   6460         return bcm_ap_cosq_gport_congestion_config_get(unit, gport, cosq, config);
   6461     }
   6462 #endif
   6463 #ifdef BCM_TRIDENT2_SUPPORT
   6464     if (SOC_IS_TD2_TT2(unit)) {
   6465         return bcm_td2_cosq_gport_congestion_config_get(unit, gport, cosq, config);
   6466     }
   6467 #endif
   6468 #ifdef BCM_TRIUMPH3_SUPPORT
   6469     if (SOC_IS_TRIUMPH3(unit)) {
   6470         return bcm_tr3_cosq_gport_congestion_config_get(unit, gport, cosq, config);
   6471     }
   6472 #endif
   6473 #ifdef BCM_KATANA2_SUPPORT
   6474     if (SOC_IS_KATANA2(unit)) {
   6475         return bcm_kt2_cosq_gport_congestion_config_get(unit, gport, cosq, config);
   6476     }
   6477 #endif
   6478     return BCM_E_UNAVAIL;
   6479 }
   6480 
   6481 int bcm_esw_cosq_bst_profile_set(int unit, 
   6482                                  bcm_gport_t port, 
   6483                                  bcm_cos_queue_t cosq, 
   6484                                  bcm_bst_stat_id_t bid,
   6485                                  bcm_cosq_bst_profile_t *profile)
   6486 {
   6487     if (!SOC_UNIT_VALID(unit)) {
   6488         return BCM_E_UNIT;
   6489     }
   6490 #ifdef BCM_TOMAHAWK3_SUPPORT
   6491     if (SOC_IS_TOMAHAWK3(unit)) {
   6492         return _bcm_th3_bst_cmn_profile_set
   6493                     (unit, port, cosq, BCM_BST_DUP_XPE, bid, profile);
   6494     }
   6495 #endif
   6496 #ifdef BCM_TOMAHAWK_SUPPORT
   6497     if (SOC_IS_TOMAHAWKX(unit)) {
   6498         return bcm_th_cosq_bst_profile_set(unit, port, cosq, bid, profile);
   6499     }
   6500 #endif
   6501 #ifdef BCM_MONTEREY_SUPPORT
   6502     if (SOC_IS_MONTEREY(unit)) {
   6503          BCM_IF_ERROR_RETURN(
   6504             bcm_mn_cosq_bst_profile_set(unit, port, cosq, bid, profile));
   6505         return BCM_E_NONE; 
   6506     }
   6507 #endif /* BCM_MONTEREY_SUPPORT */
   6508 #ifdef BCM_TRIDENT3_SUPPORT
   6509     if (SOC_IS_TRIDENT3X(unit)) {
   6510         return bcm_td3_cosq_bst_profile_set(unit, port, cosq, bid, profile);
   6511     }
   6512 #endif
   6513 #ifdef BCM_APACHE_SUPPORT
   6514     if (SOC_IS_APACHE(unit)) {
   6515         BCM_IF_ERROR_RETURN(
   6516             bcm_ap_cosq_bst_profile_set(unit, port, cosq, bid, profile));
   6517         return BCM_E_NONE;
   6518     }
   6519 #endif
   6520 #ifdef BCM_TRIDENT2_SUPPORT
   6521     if (SOC_IS_TD2_TT2(unit)) {
   6522         BCM_IF_ERROR_RETURN(
   6523             bcm_td2_cosq_bst_profile_set(unit, port, cosq, bid, profile));
   6524         return BCM_E_NONE;
   6525     }
   6526 #endif
   6527 #ifdef BCM_TRIUMPH3_SUPPORT
   6528     if (SOC_IS_TRIUMPH3(unit)) {
   6529         BCM_IF_ERROR_RETURN(
   6530             bcm_tr3_cosq_bst_profile_set(unit, port, cosq, bid, profile));
   6531         return BCM_E_NONE;
   6532     }
   6533 #endif
   6534     return BCM_E_UNAVAIL;
   6535 }
   6536 
   6537 int bcm_esw_cosq_bst_profile_get(int unit, 
   6538                                  bcm_gport_t port, 
   6539                                  bcm_cos_queue_t cosq, 
   6540                                  bcm_bst_stat_id_t bid,
   6541                                  bcm_cosq_bst_profile_t *profile)
   6542 {
   6543     if (!SOC_UNIT_VALID(unit)) {
   6544         return BCM_E_UNIT;
   6545     }
   6546 #ifdef BCM_TOMAHAWK3_SUPPORT
   6547     if (SOC_IS_TOMAHAWK3(unit)) {
   6548         return _bcm_th3_bst_cmn_profile_get
   6549                         (unit, port, cosq, BCM_BST_DUP_XPE, bid, profile);
   6550     }
   6551 #endif
   6552 #ifdef BCM_TOMAHAWK_SUPPORT
   6553     if (SOC_IS_TOMAHAWKX(unit)) {
   6554         return bcm_th_cosq_bst_profile_get(unit, port, cosq, bid, profile);
   6555     }
   6556 #endif
   6557 #ifdef BCM_MONTEREY_SUPPORT
   6558     if (SOC_IS_MONTEREY(unit)) {
   6559          BCM_IF_ERROR_RETURN(
   6560             bcm_mn_cosq_bst_profile_get(unit, port, cosq, bid, profile));
   6561         return BCM_E_NONE;
   6562     }
   6563 #endif /* BCM_MONTEREY_SUPPORT */
   6564 #ifdef BCM_TRIDENT3_SUPPORT
   6565     if (SOC_IS_TRIDENT3X(unit)) {
   6566         return bcm_td3_cosq_bst_profile_get(unit, port, cosq, bid, profile);
   6567     }
   6568 #endif
   6569 #ifdef BCM_APACHE_SUPPORT
   6570     if (SOC_IS_APACHE(unit)) {
   6571         BCM_IF_ERROR_RETURN(
   6572             bcm_ap_cosq_bst_profile_get(unit, port, cosq, bid, profile));
   6573         return BCM_E_NONE;
   6574     }
   6575 #endif
   6576 #ifdef BCM_TRIDENT2_SUPPORT
   6577     if (SOC_IS_TD2_TT2(unit)) {
   6578         BCM_IF_ERROR_RETURN(
   6579             bcm_td2_cosq_bst_profile_get(unit, port, cosq, bid, profile));
   6580         return BCM_E_NONE;
   6581     }
   6582 #endif
   6583 #ifdef BCM_TRIUMPH3_SUPPORT
   6584     if (SOC_IS_TRIUMPH3(unit)) {
   6585         BCM_IF_ERROR_RETURN(
   6586             bcm_tr3_cosq_bst_profile_get(unit, port, cosq, bid, profile));
   6587         return BCM_E_NONE;
   6588     }
   6589 #endif
   6590     return BCM_E_UNAVAIL;
   6591 }
   6592 
   6593 int bcm_esw_cosq_bst_multi_profile_set(int unit, 
   6594                                  bcm_gport_t port, 
   6595                                  bcm_cos_queue_t cosq, 
   6596                                  bcm_bst_stat_id_t bid,
   6597                                  int array_size,
   6598                                  bcm_cosq_bst_profile_t *profile_array)
   6599 {
   6600     if (!SOC_UNIT_VALID(unit)) {
   6601         return BCM_E_UNIT;
   6602     }
   6603 #ifdef BCM_TOMAHAWK3_SUPPORT
   6604     if(SOC_IS_TOMAHAWK3(unit)) {
   6605         int i;
   6606         if(bid != bcmBstStatIdDevice) {
   6607             /* only CFAP thresh is non-duplicate */
   6608             return BCM_E_UNAVAIL;
   6609         }
   6610         if(array_size > NUM_ITM(unit)) {
   6611             return BCM_E_PARAM;
   6612         }
   6613         for(i = 0 ; i < array_size; i++) {
   6614             BCM_IF_ERROR_RETURN(
   6615                 _bcm_th3_bst_cmn_profile_set(unit, port, cosq, i, bid,
   6616                                                          &profile_array[i]));
   6617         }
   6618         return BCM_E_NONE;
   6619     }
   6620 #endif
   6621 #ifdef BCM_TOMAHAWK_SUPPORT
   6622     if (SOC_IS_TOMAHAWKX(unit)) {
   6623         return bcm_th_cosq_bst_multi_profile_set(unit, port, cosq, bid, 
   6624             array_size, profile_array);
   6625     }
   6626 #endif
   6627     return BCM_E_UNAVAIL;
   6628 }
   6629 
   6630 int bcm_esw_cosq_bst_multi_profile_get(int unit, 
   6631                                  bcm_gport_t port, 
   6632                                  bcm_cos_queue_t cosq, 
   6633                                  bcm_bst_stat_id_t bid,
   6634                                  int array_size,
   6635                                  bcm_cosq_bst_profile_t *profile_array,
   6636                                  int *count)
   6637 {
   6638     if (!SOC_UNIT_VALID(unit)) {
   6639         return BCM_E_UNIT;
   6640     }
   6641 #ifdef BCM_TOMAHAWK3_SUPPORT
   6642     if(SOC_IS_TOMAHAWK3(unit)) {
   6643         int i;
   6644         if(bid != bcmBstStatIdDevice) {
   6645             /* only CFAP thresh is non-duplicate */
   6646             return BCM_E_UNAVAIL;
   6647         }
   6648         if(array_size > NUM_ITM(unit)) {
   6649             return BCM_E_PARAM;
   6650         }
   6651         for(i = 0 ; i < array_size; i++) {
   6652             BCM_IF_ERROR_RETURN(
   6653                 _bcm_th3_bst_cmn_profile_get(unit, port, cosq, i,
   6654                                                 bid, &profile_array[i]));
   6655 
   6656         }
   6657         *count = i;
   6658         return BCM_E_NONE;
   6659     }
   6660 #endif
   6661 #ifdef BCM_TOMAHAWK_SUPPORT
   6662     if (SOC_IS_TOMAHAWKX(unit)) {
   6663         return bcm_th_cosq_bst_multi_profile_get(unit, port, cosq, bid, 
   6664             array_size, profile_array, count);
   6665     }
   6666 #endif
   6667     return BCM_E_UNAVAIL;
   6668 }
   6669 
   6670 /*
   6671  * Function:
   6672  *      bcm_esw_cosq_bst_stat_get
   6673  * Purpose:
   6674  *      Set the profile for tracking. 
   6675  * Parameters:
   6676  *      unit          - (IN) Unit number.
   6677  *      port          - (IN) GPORT ID
   6678  *      cosq          - (IN) COS queue
   6679  *      bid           - (IN) BST statistics ID.
   6680  *      options       - (IN) Clear-on-read or not
   6681  *      value         - (OUT) Returned statistic value.
   6682  * Returns:
   6683  *      BCM_E_XXX
   6684  */
   6685 int bcm_esw_cosq_bst_stat_get(int unit, 
   6686                               bcm_gport_t port, 
   6687                               bcm_cos_queue_t cosq, 
   6688                               bcm_bst_stat_id_t bid,
   6689                               uint32 options,
   6690                               uint64 *pvalue)
   6691 {
   6692     if (!SOC_UNIT_VALID(unit)) {
   6693         return BCM_E_UNIT;
   6694     }
   6695 
   6696     if (pvalue == NULL) {
   6697         return BCM_E_PARAM;
   6698     }
   6699 #ifdef BCM_TOMAHAWK3_SUPPORT
   6700     if (SOC_IS_TOMAHAWK3(unit)) {
   6701         return bcm_th3_cosq_bst_stat_get
   6702             (unit, port, cosq, BCM_COSQ_BUFFER_ID_INVALID, bid, options, pvalue);
   6703     }
   6704 #endif
   6705 #ifdef BCM_TOMAHAWK_SUPPORT
   6706     if (SOC_IS_TOMAHAWKX(unit)) {
   6707         return bcm_th_cosq_bst_stat_get
   6708             (unit, port, cosq, BCM_COSQ_BUFFER_ID_INVALID, bid, options, pvalue);
   6709     }
   6710 #endif
   6711 #ifdef BCM_MONTEREY_SUPPORT
   6712     if (SOC_IS_MONTEREY(unit)) {
   6713          BCM_IF_ERROR_RETURN(
   6714              bcm_mn_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue)); 
   6715         return BCM_E_NONE;
   6716     }
   6717 #endif /* BCM_MONTEREY_SUPPORT */
   6718 #ifdef BCM_TRIDENT3_SUPPORT
   6719     if (SOC_IS_TRIDENT3X(unit)) {
   6720         return bcm_td3_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue);
   6721     }
   6722 #endif
   6723 #ifdef BCM_APACHE_SUPPORT
   6724     if (SOC_IS_APACHE(unit)) {
   6725         BCM_IF_ERROR_RETURN(
   6726             bcm_ap_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue));
   6727         return BCM_E_NONE;
   6728     }
   6729 #endif
   6730 #ifdef BCM_TRIDENT2_SUPPORT
   6731     if (SOC_IS_TD2_TT2(unit)) {
   6732         BCM_IF_ERROR_RETURN(
   6733             bcm_td2_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue));
   6734         return BCM_E_NONE;
   6735     }
   6736 #endif
   6737 #ifdef BCM_TRIUMPH3_SUPPORT
   6738     if (SOC_IS_TRIUMPH3(unit)) {
   6739         BCM_IF_ERROR_RETURN(
   6740             bcm_tr3_cosq_bst_stat_get(unit, port, cosq, bid, options, pvalue));
   6741         return BCM_E_NONE;
   6742     }
   6743 #endif
   6744     return BCM_E_UNAVAIL;
   6745 }
   6746 
   6747 /*
   6748  * Function:
   6749  *      bcm_esw_cosq_bst_stat_get32
   6750  * Purpose:
   6751  *      Set the profile for tracking. 
   6752  * Parameters:
   6753  *      unit          - (IN) Unit number.
   6754  *      port          - (IN) GPORT ID
   6755  *      cosq          - (IN) COS queue
   6756  *      bid           - (IN) BST statistics ID.
   6757  *      options       - (IN) Clear-on-read or not
   6758  *      value         - (OUT) Returned statistic value.
   6759  * Returns:
   6760  *      BCM_E_XXX
   6761  */
   6762 int bcm_esw_cosq_bst_stat_get32(int unit, 
   6763                               bcm_gport_t port, 
   6764                               bcm_cos_queue_t cosq, 
   6765                               bcm_bst_stat_id_t bid,
   6766                               uint32 options,
   6767                               uint32 *pvalue)
   6768 {
   6769     uint64 val64;
   6770     int rv;
   6771 
   6772     if (NULL == pvalue) {
   6773         return BCM_E_PARAM;
   6774     }
   6775 
   6776     rv = bcm_esw_cosq_bst_stat_get(unit, port, cosq, bid, options, &val64);
   6777 
   6778     if (BCM_SUCCESS(rv)) {
   6779         *pvalue = COMPILER_64_LO(val64);
   6780     }
   6781 
   6782     return rv;
   6783 }
   6784 
   6785 /*
   6786  * Function:
   6787  *      bcm_esw_cosq_bst_stat_extended_get
   6788  * Purpose:
   6789  *      Set the profile for tracking. 
   6790  * Parameters:
   6791  *      unit          - (IN) Unit number.
   6792  *      id            - (IN) Integrated cosq index
   6793  *      bid           - (IN) BST statistics ID.
   6794  *      options       - (IN) Clear-on-read or not
   6795  *      value         - (OUT) Returned statistic value.
   6796  * Returns:
   6797  *      BCM_E_XXX
   6798  */
   6799 int bcm_esw_cosq_bst_stat_extended_get(int unit, 
   6800                               bcm_cosq_object_id_t *id,
   6801                               bcm_bst_stat_id_t bid,
   6802                               uint32 options,
   6803                               uint64 *pvalue)
   6804 {
   6805     if (!SOC_UNIT_VALID(unit)) {
   6806         return BCM_E_UNIT;
   6807     }
   6808 
   6809     if (pvalue == NULL) {
   6810         return BCM_E_PARAM;
   6811     }
   6812 #ifdef BCM_TOMAHAWK3_SUPPORT
   6813     if (SOC_IS_TOMAHAWK3(unit)) {
   6814         return bcm_th3_cosq_bst_stat_get
   6815             (unit, id->port, id->cosq, id->buffer, bid, options, pvalue);
   6816     }
   6817 #endif
   6818 #ifdef BCM_TOMAHAWK_SUPPORT
   6819     if (SOC_IS_TOMAHAWKX(unit)) {
   6820         return bcm_th_cosq_bst_stat_get
   6821             (unit, id->port, id->cosq, id->buffer, bid, options, pvalue);
   6822     }
   6823 #endif
   6824     return BCM_E_UNAVAIL;
   6825 }
   6826 
   6827 /*
   6828  * Function:
   6829  *      bcm_esw_cosq_bst_stat_extended_get32
   6830  * Purpose:
   6831  *      Set the profile for tracking. 
   6832  * Parameters:
   6833  *      unit          - (IN) Unit number.
   6834  *      id            - (IN) Integrated cosq index
   6835  *      bid           - (IN) BST statistics ID.
   6836  *      options       - (IN) Clear-on-read or not
   6837  *      value         - (OUT) Returned statistic value.
   6838  * Returns:
   6839  *      BCM_E_XXX
   6840  */
   6841 int bcm_esw_cosq_bst_stat_extended_get32(int unit, 
   6842                               bcm_cosq_object_id_t *id,
   6843                               bcm_bst_stat_id_t bid,
   6844                               uint32 options,
   6845                               uint32 *pvalue)
   6846 {
   6847     uint64 val64;
   6848     int rv;
   6849 
   6850     if (NULL == pvalue) {
   6851         return BCM_E_PARAM;
   6852     }
   6853 
   6854     rv = bcm_esw_cosq_bst_stat_extended_get(unit, id, bid, options, &val64);
   6855 
   6856     if (BCM_SUCCESS(rv)) {
   6857         *pvalue = COMPILER_64_LO(val64);
   6858     }
   6859 
   6860     return rv;
   6861 }
   6862 
   6863 /*
   6864  * Function:
   6865  *      bcm_esw_cosq_bst_stat_multi_get
   6866  * Purpose:
   6867  *      To retrieve a list of stats all at once. To match the usual API
   6868  *      multi_get(), the signature for this function should take a list 
   6869  *      of stat IDs to fetch, and return a list of values along with 
   6870  *      the count of items returned.
   6871  * Parameters:
   6872  *      unit - StrataSwitch unit number.
   6873  *      port - port to configure, -1 for any port.
   6874  *      cosq - COS queue to configure, -1 for any COS queue.
   6875  *      options - BCM_COSQ_STAT_CLEAR.
   6876  *      max_values - max value in id_list.
   6877  *      id_list - (IN) IDs to retrieve.
   6878  *      values - (OUT) values retrieved from id_list
   6879  * Returns:
   6880  *      BCM_E_XXX
   6881  */ 
   6882 int bcm_esw_cosq_bst_stat_multi_get(int unit,
   6883                                     bcm_gport_t port,
   6884                                     bcm_cos_queue_t cosq,
   6885                                     uint32 options,
   6886                                     int max_values,
   6887                                     bcm_bst_stat_id_t *id_list,
   6888                                     uint64 *values)
   6889 {
   6890     /* Parameter validation checks */
   6891     if (!SOC_UNIT_VALID(unit)) {
   6892         return BCM_E_UNIT;
   6893     }
   6894 
   6895     if (id_list == NULL || values == NULL) {
   6896         return BCM_E_PARAM;
   6897     }
   6898 
   6899 #ifdef BCM_TOMAHAWK3_SUPPORT
   6900     if (SOC_IS_TOMAHAWK3(unit)) {
   6901         return bcm_th3_cosq_bst_stat_multi_get(unit, port, cosq, options,
   6902                                               max_values, id_list, values);
   6903     }
   6904 #endif
   6905 
   6906 #ifdef BCM_TOMAHAWK_SUPPORT
   6907     if (SOC_IS_TOMAHAWKX(unit)) {
   6908         return bcm_th_cosq_bst_stat_multi_get(unit, port, cosq, options,
   6909                                               max_values, id_list, values);
   6910     }
   6911 #endif
   6912 #ifdef BCM_MONTEREY_SUPPORT
   6913     if (SOC_IS_MONTEREY(unit)) {
   6914          BCM_IF_ERROR_RETURN(
   6915               bcm_mn_cosq_bst_stat_multi_get(unit, port, cosq, options,
   6916                                             max_values, id_list, values));
   6917         return BCM_E_NONE;
   6918     }
   6919 #endif /* BCM_MONTEREY_SUPPORT */
   6920 
   6921 #ifdef BCM_TRIDENT3_SUPPORT
   6922     if (SOC_IS_TRIDENT3X(unit)) {
   6923         return bcm_td3_cosq_bst_stat_multi_get(unit, port, cosq, options,
   6924                                                max_values, id_list, values);
   6925     }
   6926 #endif
   6927 #ifdef BCM_APACHE_SUPPORT
   6928     if (SOC_IS_APACHE(unit)) {
   6929         BCM_IF_ERROR_RETURN(
   6930             bcm_ap_cosq_bst_stat_multi_get(unit, port, cosq, options, 
   6931                                             max_values, id_list, values));
   6932         return BCM_E_NONE;
   6933     }
   6934 #endif
   6935 #ifdef BCM_TRIDENT2_SUPPORT
   6936     if (SOC_IS_TD2_TT2(unit)) {
   6937         BCM_IF_ERROR_RETURN(
   6938             bcm_td2_cosq_bst_stat_multi_get(unit, port, cosq, options, 
   6939                                             max_values, id_list, values));
   6940         return BCM_E_NONE;
   6941     }
   6942 #endif
   6943 #ifdef BCM_TRIUMPH3_SUPPORT
   6944     if (SOC_IS_TRIUMPH3(unit)) {
   6945         BCM_IF_ERROR_RETURN(
   6946             bcm_tr3_cosq_bst_stat_multi_get(unit, port, cosq, options, 
   6947                                             max_values, id_list, values));
   6948         return BCM_E_NONE;
   6949     }
   6950 #endif
   6951     return BCM_E_UNAVAIL;
   6952 }
   6953 
   6954 /*
   6955  * Function:
   6956  *      bcm_esw_cosq_bst_stat_multi_get32
   6957  * Purpose:
   6958  *      To retrieve a list of stats all at once. To match the usual API
   6959  *      multi_get(), the signature for this function should take a list 
   6960  *      of stat IDs to fetch, and return a list of values along with 
   6961  *      the count of items returned.
   6962  * Parameters:
   6963  *      unit - StrataSwitch unit number.
   6964  *      port - port to configure, -1 for any port.
   6965  *      cosq - COS queue to configure, -1 for any COS queue.
   6966  *      options - BCM_COSQ_STAT_CLEAR.
   6967  *      max_values - max value in id_list.
   6968  *      id_list - (IN) IDs to retrieve.
   6969  *      values - (OUT) values retrieved from id_list
   6970  * Returns:
   6971  *      BCM_E_XXX
   6972  */ 
   6973 int bcm_esw_cosq_bst_stat_multi_get32(int unit,
   6974                                     bcm_gport_t port,
   6975                                     bcm_cos_queue_t cosq,
   6976                                     uint32 options,
   6977                                     int max_values,
   6978                                     bcm_bst_stat_id_t *id_list,
   6979                                     uint32 *values)
   6980 {
   6981     int i, rv;
   6982     uint64 *val64;
   6983 
   6984     val64 = sal_alloc(max_values * sizeof(uint64), "bst_stat_multi_get32");
   6985     if (val64 == NULL) {
   6986         return BCM_E_MEMORY;
   6987     }
   6988     sal_memset(val64, 0x0, max_values * sizeof(uint64));
   6989 
   6990     rv = bcm_esw_cosq_bst_stat_multi_get(unit, port, cosq, options, max_values, \
   6991                                     id_list, val64);
   6992     if (BCM_SUCCESS(rv)) {
   6993         for (i = 0; i < max_values; i++) {
   6994             values[i] = COMPILER_64_LO(val64[i]);
   6995         }
   6996     }
   6997 
   6998     sal_free(val64);
   6999     return rv;
   7000 }
   7001 
   7002 /*
   7003  * Function:
   7004  *      bcm_esw_cosq_bst_stat_clear
   7005  * Purpose:
   7006  *      clear given BST stats to zero
   7007  * Parameters:
   7008  *      unit - StrataSwitch unit number.
   7009  *      port - port to configure, -1 for any port.
   7010  *      cosq - COS queue to configure, -1 for any COS queue.
   7011  * Returns:
   7012  *      BCM_E_XXX
   7013  */ 
   7014 int bcm_esw_cosq_bst_stat_clear(int unit, bcm_gport_t port, 
   7015                                 bcm_cos_queue_t cosq, bcm_bst_stat_id_t bid)
   7016 {
   7017     if (!SOC_UNIT_VALID(unit)) {
   7018         return BCM_E_UNIT;
   7019     }
   7020 #ifdef BCM_TOMAHAWK3_SUPPORT
   7021     if (SOC_IS_TOMAHAWK3(unit)) {
   7022         return bcm_th3_cosq_bst_stat_clear
   7023             (unit, port, cosq, BCM_COSQ_BUFFER_ID_INVALID, bid);
   7024     }
   7025 #endif
   7026 #ifdef BCM_TOMAHAWK_SUPPORT
   7027     if (SOC_IS_TOMAHAWKX(unit)) {
   7028         return bcm_th_cosq_bst_stat_clear
   7029             (unit, port, cosq, BCM_COSQ_BUFFER_ID_INVALID, bid);
   7030     }
   7031 #endif
   7032 #ifdef BCM_MONTEREY_SUPPORT
   7033     if (SOC_IS_MONTEREY(unit)) {
   7034          BCM_IF_ERROR_RETURN(
   7035              bcm_mn_cosq_bst_stat_clear(unit, port, cosq, bid)); 
   7036         return BCM_E_NONE;
   7037     }
   7038 #endif /* BCM_MONTEREY_SUPPORT */
   7039 #ifdef BCM_TRIDENT3_SUPPORT
   7040     if (SOC_IS_TRIDENT3X(unit)) {
   7041         return bcm_td3_cosq_bst_stat_clear(unit, port, cosq, bid);
   7042     }
   7043 #endif
   7044 #ifdef BCM_APACHE_SUPPORT
   7045     if (SOC_IS_APACHE(unit)) {
   7046         BCM_IF_ERROR_RETURN(
   7047             bcm_ap_cosq_bst_stat_clear(unit, port, cosq, bid));
   7048         return BCM_E_NONE;
   7049     }
   7050 #endif
   7051 #ifdef BCM_TRIDENT2_SUPPORT
   7052     if (SOC_IS_TD2_TT2(unit)) {
   7053         BCM_IF_ERROR_RETURN(
   7054             bcm_td2_cosq_bst_stat_clear(unit, port, cosq, bid));
   7055         return BCM_E_NONE;
   7056     }
   7057 #endif
   7058 #ifdef BCM_TRIUMPH3_SUPPORT
   7059     if (SOC_IS_TRIUMPH3(unit)) {
   7060         BCM_IF_ERROR_RETURN(
   7061             bcm_tr3_cosq_bst_stat_clear(unit, port, cosq, bid));
   7062         return BCM_E_NONE;
   7063     }
   7064 #endif
   7065     return BCM_E_UNAVAIL;
   7066 }
   7067 
   7068 /*
   7069  * Function:
   7070  *      bcm_esw_cosq_bst_stat_extended_clear
   7071  * Purpose:
   7072  *      clear given BST stats to zero
   7073  * Parameters:
   7074  *      unit - StrataSwitch unit number.
   7075  *      id   - Integrated cosq index
   7076  * Returns:
   7077  *      BCM_E_XXX
   7078  */ 
   7079 int bcm_esw_cosq_bst_stat_extended_clear(int unit, bcm_cosq_object_id_t *id,
   7080                                          bcm_bst_stat_id_t bid)
   7081 {
   7082     if (!SOC_UNIT_VALID(unit)) {
   7083         return BCM_E_UNIT;
   7084     }
   7085 
   7086 #ifdef BCM_TOMAHAWK3_SUPPORT
   7087     if (SOC_IS_TOMAHAWK3(unit)) {
   7088         return bcm_th3_cosq_bst_stat_clear
   7089             (unit, id->port, id->cosq, id->buffer, bid);
   7090     }
   7091 #endif
   7092 #ifdef BCM_TOMAHAWK_SUPPORT
   7093     if (SOC_IS_TOMAHAWKX(unit)) {
   7094         return bcm_th_cosq_bst_stat_clear
   7095             (unit, id->port, id->cosq, id->buffer, bid);
   7096     }
   7097 #endif
   7098     return BCM_E_UNAVAIL;
   7099 }
   7100 
   7101 int bcm_esw_cosq_bst_stat_sync(int unit, bcm_bst_stat_id_t bid)
   7102 {
   7103 #ifdef BCM_TOMAHAWK_SUPPORT
   7104     if (SOC_IS_TOMAHAWKX(unit)) {
   7105         BCM_IF_ERROR_RETURN(
   7106             bcm_th_cosq_bst_stat_sync(unit, bid));
   7107         return BCM_E_NONE;
   7108     }
   7109 #endif
   7110 #ifdef BCM_MONTEREY_SUPPORT
   7111     if (SOC_IS_MONTEREY(unit)) {
   7112          BCM_IF_ERROR_RETURN(
   7113              bcm_ap_cosq_bst_stat_sync(unit, bid)); 
   7114         return BCM_E_NONE;
   7115     }
   7116 #endif /* BCM_MONTEREY_SUPPORT */
   7117 
   7118 #ifdef BCM_TRIDENT3_SUPPORT
   7119     if (SOC_IS_TRIDENT3X(unit)) {
   7120         BCM_IF_ERROR_RETURN(
   7121             bcm_td3_cosq_bst_stat_sync(unit, bid));
   7122         return BCM_E_NONE;
   7123     }
   7124 #endif
   7125 #ifdef BCM_APACHE_SUPPORT
   7126     if (SOC_IS_APACHE(unit)) {
   7127         BCM_IF_ERROR_RETURN(
   7128             bcm_ap_cosq_bst_stat_sync(unit, bid));
   7129         return BCM_E_NONE;
   7130     }
   7131 #endif
   7132 #ifdef BCM_TRIDENT2_SUPPORT
   7133     if (SOC_IS_TD2_TT2(unit)) {
   7134         BCM_IF_ERROR_RETURN(
   7135             bcm_td2_cosq_bst_stat_sync(unit, bid));
   7136         return BCM_E_NONE;
   7137     }
   7138 #endif
   7139 #ifdef BCM_TRIUMPH3_SUPPORT
   7140     if (SOC_IS_TRIUMPH3(unit)) {
   7141         BCM_IF_ERROR_RETURN(
   7142             bcm_tr3_cosq_bst_stat_sync(unit, bid));
   7143         return BCM_E_NONE;
   7144     }
   7145 #endif
   7146     return BCM_E_UNAVAIL;
   7147 }
   7148 
   7149 /*
   7150  * Function:
   7151  *      bcm_esw_cosq_classifier_create
   7152  * Purpose:
   7153  *      Create a cosq classifier.
   7154  * Parameters:
   7155  *      unit          - (IN) Unit number.
   7156  *      classifier    - (IN) Classifier attributes
   7157  *      classifier_id - (IN/OUT) Classifier ID
   7158  * Returns:
   7159  *      BCM_E_xxx
   7160  */
   7161 int
   7162 bcm_esw_cosq_classifier_create(
   7163     int unit, 
   7164     bcm_cosq_classifier_t *classifier, 
   7165     int *classifier_id)
   7166 {
   7167     if ((classifier->flags & BCM_COSQ_CLASSIFIER_VLAN) &&
   7168         (classifier->flags & BCM_COSQ_CLASSIFIER_VFI)) {
   7169         return BCM_E_PARAM;
   7170     }
   7171 
   7172 #ifdef BCM_TRIUMPH3_SUPPORT
   7173     if ((classifier->flags & BCM_COSQ_CLASSIFIER_FIELD) &&
   7174         (!(classifier->flags & BCM_COSQ_CLASSIFIER_WITH_ID))) {
   7175         if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
   7176 #ifdef BCM_KATANA2_SUPPORT
   7177             if (SOC_IS_KATANA2(unit)) {
   7178                 BCM_IF_ERROR_RETURN
   7179                     (bcm_kt2_cosq_field_classifier_id_create(unit, classifier,
   7180                                                              classifier_id));
   7181             } else    
   7182 #endif
   7183 #ifdef BCM_TOMAHAWK3_SUPPORT
   7184             if (SOC_IS_TOMAHAWK3(unit)) {
   7185                 BCM_IF_ERROR_RETURN
   7186                     (bcm_th3_cosq_field_classifier_id_create(unit, classifier,
   7187                                                             classifier_id));
   7188             } else
   7189 #endif
   7190 #ifdef BCM_TOMAHAWK_SUPPORT
   7191             if (SOC_IS_TOMAHAWKX(unit)) {
   7192                 BCM_IF_ERROR_RETURN
   7193                     (bcm_th_cosq_field_classifier_id_create(unit, classifier,
   7194                                                             classifier_id));
   7195             } else
   7196 #endif
   7197 #ifdef BCM_MONTEREY_SUPPORT
   7198     if (SOC_IS_MONTEREY(unit)) {
   7199         BCM_IF_ERROR_RETURN
   7200             (bcm_mn_cosq_field_classifier_id_create(unit, classifier,
   7201                                                     classifier_id));
   7202             } else
   7203 #endif /* BCM_MONTEREY_SUPPORT */
   7204 #ifdef BCM_HELIX5_SUPPORT
   7205             if (SOC_IS_HELIX5(unit)) {
   7206                 BCM_IF_ERROR_RETURN
   7207                     (bcm_hx5_cosq_field_classifier_id_create(unit, classifier,
   7208                                                              classifier_id));
   7209             } else
   7210 #endif /* BCM_HELIX5_SUPPORT */
   7211 #ifdef BCM_TRIDENT3_SUPPORT
   7212             if (SOC_IS_TRIDENT3X(unit)) {
   7213                 BCM_IF_ERROR_RETURN
   7214                     (bcm_td3_cosq_field_classifier_id_create(unit, classifier,
   7215                                                              classifier_id));
   7216             } else
   7217 #endif /* BCM_TRIDENT3_SUPPORT */
   7218 #ifdef BCM_APACHE_SUPPORT
   7219             if (SOC_IS_APACHE(unit)) {
   7220                 BCM_IF_ERROR_RETURN
   7221                     (bcm_ap_cosq_field_classifier_id_create(unit, classifier,
   7222                                                              classifier_id));
   7223             } else 
   7224 #endif      
   7225 #ifdef BCM_TRIDENT2_SUPPORT
   7226             if (SOC_IS_TD2_TT2(unit)) {
   7227                 BCM_IF_ERROR_RETURN
   7228                     (bcm_td2_cosq_field_classifier_id_create(unit, classifier,
   7229                                                              classifier_id));
   7230             } else    
   7231 #endif
   7232             {
   7233                 BCM_IF_ERROR_RETURN
   7234                     (bcm_tr3_cosq_field_classifier_id_create(unit, classifier,
   7235                                                              classifier_id));
   7236             }
   7237         } else {
   7238             return (BCM_E_UNAVAIL);
   7239         }
   7240     } else 
   7241 #endif
   7242     if (classifier->flags & BCM_COSQ_CLASSIFIER_L2 ||
   7243         classifier->flags & BCM_COSQ_CLASSIFIER_L3 ||
   7244         classifier->flags & BCM_COSQ_CLASSIFIER_GPORT || 
   7245         classifier->flags & BCM_COSQ_CLASSIFIER_L3_EGRESS) {
   7246 #ifdef BCM_APACHE_SUPPORT
   7247         if (SOC_IS_APACHE(unit) &&
   7248             soc_feature(unit, soc_feature_endpoint_queuing)) {
   7249             BCM_IF_ERROR_RETURN(bcm_ap_cosq_endpoint_create(unit, classifier,
   7250                         classifier_id));
   7251         } else
   7252 #endif /* BCM_APACHE_SUPPORT */
   7253 #ifdef BCM_TRIDENT2_SUPPORT
   7254         if (soc_feature(unit, soc_feature_endpoint_queuing)) {
   7255             BCM_IF_ERROR_RETURN(bcm_td2_cosq_endpoint_create(unit, classifier,
   7256                         classifier_id));
   7257         } else
   7258 #endif /* BCM_TRIDENT2_SUPPORT */
   7259         {
   7260             return BCM_E_PARAM;
   7261         }
   7262     } else if (classifier->flags & BCM_COSQ_CLASSIFIER_VLAN) {
   7263 #if defined(BCM_TRIUMPH3_SUPPORT)
   7264         if (soc_feature(unit, soc_feature_service_queuing)) {
   7265 #ifdef BCM_KATANA2_SUPPORT
   7266             if (SOC_IS_KATANA2(unit)) {
   7267                 BCM_IF_ERROR_RETURN(bcm_kt2_cosq_service_classifier_id_create(
   7268                              unit, classifier, classifier_id));
   7269             } else
   7270 #endif
   7271 #if defined(BCM_APACHE_SUPPORT)
   7272             if (SOC_IS_APACHE(unit)) {
   7273                 BCM_IF_ERROR_RETURN(
   7274                     bcm_ap_cosq_service_classifier_id_create(unit, classifier,
   7275                                                               classifier_id));
   7276             } else
   7277 #endif  /* BCM_APACHE_SUPPORT */
   7278 #if defined(BCM_TRIDENT2_SUPPORT)
   7279             if (SOC_IS_TRIDENT2(unit)) {
   7280                 BCM_IF_ERROR_RETURN(
   7281                     bcm_td2_cosq_service_classifier_id_create(unit, classifier,
   7282                                                               classifier_id));
   7283             } else
   7284 #endif /* BCM_TRIDENT2_SUPPORT */
   7285             {
   7286                 BCM_IF_ERROR_RETURN(bcm_tr3_cosq_service_classifier_id_create(
   7287                              unit, classifier, classifier_id));
   7288             }
   7289         } else
   7290 #endif /* BCM_TRIUMPH3_SUPPORT */
   7291         {
   7292             return BCM_E_UNAVAIL;
   7293         }
   7294     } else if (classifier->flags & BCM_COSQ_CLASSIFIER_VFI) {
   7295         if (soc_feature(unit, soc_feature_service_queuing)) {
   7296 #ifdef BCM_KATANA2_SUPPORT
   7297             if (SOC_IS_KATANA2(unit)) {
   7298                 BCM_IF_ERROR_RETURN(bcm_kt2_cosq_service_classifier_id_create(
   7299                              unit, classifier, classifier_id));
   7300             } else
   7301 #endif
   7302 #ifdef BCM_TRIDENT2_SUPPORT
   7303             if (SOC_IS_TRIDENT2(unit)) {
   7304                 BCM_IF_ERROR_RETURN(
   7305                     bcm_td2_cosq_service_classifier_id_create(unit, classifier,
   7306                                                               classifier_id));
   7307             } else
   7308 #endif /* BCM_TRIDENT2_SUPPORT */
   7309             {
   7310                 return BCM_E_UNAVAIL;
   7311             }
   7312         }
   7313     } else {
   7314         return BCM_E_PARAM;
   7315     }
   7316 
   7317     return BCM_E_NONE;
   7318 }
   7319 
   7320 /*
   7321  * Function:
   7322  *      bcm_esw_cosq_classifier_destroy
   7323  * Purpose:
   7324  *      Destroy a cosq classifier.
   7325  * Parameters:
   7326  *      unit          - (IN) Unit number.
   7327  *      classifier_id - (IN) Classifier ID
   7328  * Returns:
   7329  *      BCM_E_xxx
   7330  */
   7331 int
   7332 bcm_esw_cosq_classifier_destroy(
   7333     int unit, 
   7334     int classifier_id)
   7335 {
   7336 
   7337 #ifdef BCM_TRIUMPH3_SUPPORT
   7338     if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
   7339         if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
   7340 #ifdef BCM_KATANA2_SUPPORT
   7341             if (SOC_IS_KATANA2(unit)) {
   7342                 BCM_IF_ERROR_RETURN
   7343                     (bcm_kt2_cosq_field_classifier_id_destroy(unit, 
   7344                                                          classifier_id));
   7345             } else 
   7346 #endif
   7347 #ifdef BCM_TOMAHAWK3_SUPPORT
   7348             if (SOC_IS_TOMAHAWK3(unit)) {
   7349                 BCM_IF_ERROR_RETURN
   7350                     (bcm_th3_cosq_field_classifier_id_destroy(unit,
   7351                                                              classifier_id));
   7352             } else
   7353 #endif
   7354 #ifdef BCM_TOMAHAWK_SUPPORT
   7355             if (SOC_IS_TOMAHAWKX(unit)) {
   7356                 BCM_IF_ERROR_RETURN
   7357                     (bcm_th_cosq_field_classifier_id_destroy(unit,
   7358                                                              classifier_id));
   7359             } else
   7360 #endif
   7361 #ifdef BCM_MONTEREY_SUPPORT
   7362     if (SOC_IS_MONTEREY(unit)) {
   7363         BCM_IF_ERROR_RETURN
   7364             (bcm_ap_cosq_field_classifier_id_destroy(unit,
   7365                                                      classifier_id)); 
   7366             } else
   7367 #endif /* BCM_MONTEREY_SUPPORT */
   7368 #ifdef BCM_HELIX5_SUPPORT
   7369             if (SOC_IS_HELIX5(unit)) {
   7370                 BCM_IF_ERROR_RETURN
   7371                     (bcm_hx5_cosq_field_classifier_id_destroy(unit,
   7372                                                               classifier_id));
   7373             } else
   7374 #endif
   7375 #ifdef BCM_TRIDENT3_SUPPORT
   7376             if (SOC_IS_TRIDENT3X(unit)) {
   7377                 BCM_IF_ERROR_RETURN
   7378                     (bcm_td3_cosq_field_classifier_id_destroy(unit,
   7379                                                               classifier_id));
   7380             } else
   7381 #endif
   7382 #ifdef BCM_APACHE_SUPPORT
   7383             if (SOC_IS_APACHE(unit)) {
   7384                 BCM_IF_ERROR_RETURN
   7385                     (bcm_ap_cosq_field_classifier_id_destroy(unit, 
   7386                                                               classifier_id));
   7387             } else 
   7388 #endif
   7389 #ifdef BCM_TRIDENT2_SUPPORT
   7390             if (SOC_IS_TD2_TT2(unit)) {
   7391                 BCM_IF_ERROR_RETURN
   7392                     (bcm_td2_cosq_field_classifier_id_destroy(unit, 
   7393                                                               classifier_id));
   7394             } else 
   7395 #endif
   7396             {
   7397                 BCM_IF_ERROR_RETURN
   7398                     (bcm_tr3_cosq_field_classifier_id_destroy(unit, 
   7399                                                          classifier_id));
   7400             }
   7401         } else {
   7402             return (BCM_E_UNAVAIL);
   7403         }
   7404     } else 
   7405 #endif
   7406     if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
   7407 #ifdef BCM_APACHE_SUPPORT
   7408         if (SOC_IS_APACHE(unit) && 
   7409             soc_feature(unit, soc_feature_endpoint_queuing)) {
   7410             BCM_IF_ERROR_RETURN
   7411                 (bcm_ap_cosq_endpoint_destroy(unit, classifier_id));
   7412         } else
   7413 #endif /* BCM_APACHE_SUPPORT */
   7414 #ifdef BCM_TRIDENT2_SUPPORT
   7415         if (soc_feature(unit, soc_feature_endpoint_queuing)) {
   7416             BCM_IF_ERROR_RETURN
   7417                 (bcm_td2_cosq_endpoint_destroy(unit, classifier_id));
   7418         } else
   7419 #endif /* BCM_TRIDENT2_SUPPORT */
   7420         {
   7421             return BCM_E_PARAM;
   7422         }
   7423     } else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
   7424 #ifdef BCM_TRIUMPH3_SUPPORT
   7425         if (soc_feature(unit, soc_feature_service_queuing)) {
   7426 #ifdef BCM_KATANA2_SUPPORT
   7427             if (SOC_IS_KATANA2(unit)) {
   7428                 BCM_IF_ERROR_RETURN(bcm_kt2_cosq_service_classifier_id_destroy(
   7429                                        unit, classifier_id));
   7430             } else 
   7431 #endif
   7432 #ifdef BCM_APACHE_SUPPORT
   7433             if (SOC_IS_APACHE(unit)) {
   7434                 BCM_IF_ERROR_RETURN(
   7435                     bcm_ap_cosq_service_classifier_id_destroy(unit,
   7436                                                                classifier_id));
   7437             } else
   7438 #endif /* BCM_APACHE_SUPPORT */
   7439 #ifdef BCM_TRIDENT2_SUPPORT
   7440             if (SOC_IS_TRIDENT2(unit)) {
   7441                 BCM_IF_ERROR_RETURN(
   7442                     bcm_td2_cosq_service_classifier_id_destroy(unit,
   7443                                                                classifier_id));
   7444             } else
   7445 #endif /* BCM_TRIDENT2_SUPPORT */
   7446             {
   7447                 BCM_IF_ERROR_RETURN(bcm_tr3_cosq_service_classifier_id_destroy(
   7448                                        unit, classifier_id));
   7449             }
   7450         } else
   7451 #endif /* BCM_TRIUMPH3_SUPPORT */
   7452         {
   7453             return BCM_E_UNAVAIL;
   7454         }
   7455     } else {
   7456         return BCM_E_PARAM;
   7457     }
   7458 
   7459     return BCM_E_NONE;
   7460 }
   7461 
   7462 /*
   7463  * Function:
   7464  *      bcm_esw_cosq_classifier_get
   7465  * Purpose:
   7466  *      Get info about a cosq classifier.
   7467  * Parameters:
   7468  *      unit          - (IN) Unit number.
   7469  *      classifier_id - (IN) Classifier ID
   7470  *      classifier    - (OUT) Classifier attributes
   7471  * Returns:
   7472  *      BCM_E_xxx
   7473  */
   7474 int
   7475 bcm_esw_cosq_classifier_get(
   7476     int unit, 
   7477     int classifier_id, 
   7478     bcm_cosq_classifier_t *classifier)
   7479 {
   7480 #ifdef BCM_TRIUMPH3_SUPPORT
   7481     if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
   7482         if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
   7483 #ifdef BCM_KATANA2_SUPPORT
   7484             if (SOC_IS_KATANA2(unit)) {
   7485                 BCM_IF_ERROR_RETURN
   7486                     (bcm_kt2_cosq_field_classifier_get(unit, classifier_id,
   7487                                                        classifier));
   7488             } else
   7489 #endif
   7490 #ifdef BCM_TOMAHAWK3_SUPPORT
   7491             if (SOC_IS_TOMAHAWK3(unit)) {
   7492                 BCM_IF_ERROR_RETURN
   7493                     (bcm_th3_cosq_field_classifier_get(unit, classifier_id,
   7494                                                       classifier));
   7495             } else
   7496 #endif
   7497 #ifdef BCM_TOMAHAWK_SUPPORT
   7498             if (SOC_IS_TOMAHAWKX(unit)) {
   7499                 BCM_IF_ERROR_RETURN
   7500                     (bcm_th_cosq_field_classifier_get(unit, classifier_id,
   7501                                                       classifier));
   7502             } else
   7503 #endif
   7504 #ifdef BCM_MONTEREY_SUPPORT
   7505     if (SOC_IS_MONTEREY(unit)) {
   7506         BCM_IF_ERROR_RETURN
   7507             (bcm_mn_cosq_field_classifier_get(unit, classifier_id,
   7508                                               classifier));
   7509             } else
   7510 #endif /* BCM_MONTEREY_SUPPORT */
   7511 #ifdef BCM_HELIX5_SUPPORT
   7512             if (SOC_IS_HELIX5(unit)) {
   7513                 BCM_IF_ERROR_RETURN
   7514                     (bcm_hx5_cosq_field_classifier_get(unit, classifier_id,
   7515                                                        classifier));
   7516             } else
   7517 #endif
   7518 #ifdef BCM_TRIDENT3_SUPPORT
   7519             if (SOC_IS_TRIDENT3X(unit)) {
   7520                 BCM_IF_ERROR_RETURN
   7521                     (bcm_td3_cosq_field_classifier_get(unit, classifier_id,
   7522                                                        classifier));
   7523             } else
   7524 #endif
   7525 #ifdef BCM_APACHE_SUPPORT
   7526             if (SOC_IS_APACHE(unit)) {
   7527                 BCM_IF_ERROR_RETURN
   7528                     (bcm_ap_cosq_field_classifier_get(unit, classifier_id,
   7529                                                        classifier));
   7530             } else
   7531 #endif
   7532 #ifdef BCM_TRIDENT2_SUPPORT
   7533             if (SOC_IS_TD2_TT2(unit)) {
   7534                 BCM_IF_ERROR_RETURN
   7535                     (bcm_td2_cosq_field_classifier_get(unit, classifier_id,
   7536                                                        classifier));
   7537             } else
   7538 #endif
   7539             {
   7540                 BCM_IF_ERROR_RETURN
   7541                     (bcm_tr3_cosq_field_classifier_get(unit, classifier_id,
   7542                                                        classifier));
   7543             }
   7544         } else {
   7545             return (BCM_E_UNAVAIL);
   7546         }
   7547     } else 
   7548 #endif
   7549     if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
   7550 #ifdef BCM_APACHE_SUPPORT
   7551         if (SOC_IS_APACHE(unit) &&
   7552             soc_feature(unit, soc_feature_endpoint_queuing)) {
   7553             BCM_IF_ERROR_RETURN
   7554                 (bcm_ap_cosq_endpoint_get(unit, classifier_id, classifier));
   7555         } else
   7556 #endif /* BCM_APACHE_SUPPORT */
   7557 #ifdef BCM_TRIDENT2_SUPPORT
   7558         if (soc_feature(unit, soc_feature_endpoint_queuing)) {
   7559             BCM_IF_ERROR_RETURN
   7560                 (bcm_td2_cosq_endpoint_get(unit, classifier_id, classifier));
   7561         } else
   7562 #endif /* BCM_TRIDENT2_SUPPORT */
   7563         {
   7564             return BCM_E_PARAM;
   7565         }
   7566     } else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
   7567 #ifdef BCM_TRIUMPH3_SUPPORT
   7568         if (soc_feature(unit, soc_feature_service_queuing)) {
   7569 #ifdef BCM_KATANA2_SUPPORT
   7570             if (SOC_IS_KATANA2(unit)) {
   7571                 BCM_IF_ERROR_RETURN(bcm_kt2_cosq_service_classifier_get(unit, 
   7572                                      classifier_id, classifier));
   7573             } else 
   7574 #endif
   7575 #ifdef BCM_APACHE_SUPPORT
   7576             if (SOC_IS_APACHE(unit)) {
   7577                 BCM_IF_ERROR_RETURN(
   7578                     bcm_ap_cosq_service_classifier_get(unit, classifier_id,
   7579                                                         classifier));
   7580             } else
   7581 #endif /* BCM_APACHE_SUPPORT */
   7582 #ifdef BCM_TRIDENT2_SUPPORT
   7583             if (SOC_IS_TRIDENT2(unit)) {
   7584                 BCM_IF_ERROR_RETURN(
   7585                     bcm_td2_cosq_service_classifier_get(unit, classifier_id,
   7586                                                         classifier));
   7587             } else
   7588 #endif /* BCM_TRIDENT2_SUPPORT */
   7589             {
   7590                 BCM_IF_ERROR_RETURN(bcm_tr3_cosq_service_classifier_get(unit, 
   7591                                      classifier_id, classifier));            
   7592             }
   7593         } else
   7594 #endif /* BCM_TRIUMPH3_SUPPORT */
   7595         {
   7596             return BCM_E_UNAVAIL;
   7597         }
   7598     } else {
   7599         return BCM_E_PARAM;
   7600     }
   7601 
   7602     return BCM_E_NONE;
   7603 }
   7604 
   7605 /*
   7606  * Function:
   7607  *      bcm_esw_cosq_classifier_mapping_multi_set
   7608  * Purpose:
   7609  *      Set the mapping from port, classifier, and multiple internal priorities
   7610  *      to multiple COS queues in a queue group.
   7611  * Parameters:
   7612  *      unit           - (IN) Unit number.
   7613  *      port           - (IN) GPORT ID
   7614  *      classifier_id  - (IN) Classifier ID
   7615  *      queue_group    - (IN) Queue group
   7616  *      array_count    - (IN) Number of elements in priority_array and
   7617  *                            cosq_array
   7618  *      priority_array - (IN) Array of internal priorities
   7619  *      cosq_array     - (IN) Array of COS queues
   7620  * Returns:
   7621  *      BCM_E_xxx
   7622  */
   7623 int
   7624 bcm_esw_cosq_classifier_mapping_multi_set(
   7625     int unit, 
   7626     bcm_gport_t port, 
   7627     int classifier_id, 
   7628     bcm_gport_t queue_group, 
   7629     int array_count, 
   7630     bcm_cos_t *priority_array, 
   7631     bcm_cos_queue_t *cosq_array)
   7632 {
   7633     bcm_port_t local_port;
   7634     int sysportid;
   7635 
   7636     if (array_count <= 0) {
   7637         return BCM_E_PARAM;
   7638     }
   7639     
   7640     if (NULL == priority_array || NULL == cosq_array) {
   7641         return BCM_E_PARAM;
   7642     }
   7643 
   7644 #ifdef BCM_TRIUMPH3_SUPPORT
   7645     if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
   7646         if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
   7647 #ifdef BCM_KATANA2_SUPPORT
   7648             if (SOC_IS_KATANA2(unit)) {
   7649                 BCM_IF_ERROR_RETURN
   7650                     (bcm_kt2_cosq_field_classifier_map_set(unit,
   7651                                                        classifier_id,
   7652                                                        array_count,
   7653                                                        priority_array,
   7654                                                        cosq_array));        
   7655             } else
   7656 #endif
   7657 #ifdef BCM_TOMAHAWK3_SUPPORT
   7658             if (SOC_IS_TOMAHAWK3(unit)) {
   7659                 BCM_IF_ERROR_RETURN
   7660                     (bcm_th3_cosq_field_classifier_map_set(unit,
   7661                                                           classifier_id,
   7662                                                           array_count,
   7663                                                           priority_array,
   7664                                                           cosq_array));
   7665             } else
   7666 #endif
   7667 #ifdef BCM_TOMAHAWK_SUPPORT
   7668             if (SOC_IS_TOMAHAWKX(unit)) {
   7669                 BCM_IF_ERROR_RETURN
   7670                     (bcm_th_cosq_field_classifier_map_set(unit,
   7671                                                           classifier_id,
   7672                                                           array_count,
   7673                                                           priority_array,
   7674                                                           cosq_array));
   7675             } else
   7676 #endif
   7677 #ifdef BCM_MONTEREY_SUPPORT
   7678             if (SOC_IS_MONTEREY(unit)) {
   7679                 BCM_IF_ERROR_RETURN
   7680                      (bcm_mn_cosq_field_classifier_map_set(unit,
   7681                                                            classifier_id,
   7682                                                            array_count,
   7683                                                            priority_array,
   7684                                                            cosq_array));
   7685             } else
   7686 #endif /* BCM_MONTEREY_SUPPORT */
   7687 #ifdef BCM_HELIX5_SUPPORT
   7688             if (SOC_IS_HELIX5(unit)) {
   7689                 BCM_IF_ERROR_RETURN
   7690                     (bcm_hx5_cosq_field_classifier_map_set(unit,
   7691                                                            classifier_id,
   7692                                                            array_count,
   7693                                                            priority_array,
   7694                                                            cosq_array));
   7695             } else
   7696 #endif
   7697 #ifdef BCM_TRIDENT3_SUPPORT
   7698             if (SOC_IS_TRIDENT3X(unit)) {
   7699                 BCM_IF_ERROR_RETURN
   7700                     (bcm_td3_cosq_field_classifier_map_set(unit,
   7701                                                            classifier_id,
   7702                                                            array_count,
   7703                                                            priority_array,
   7704                                                            cosq_array));
   7705             } else
   7706 #endif
   7707 #ifdef BCM_APACHE_SUPPORT
   7708             if (SOC_IS_APACHE(unit)) {
   7709                 BCM_IF_ERROR_RETURN
   7710                     (bcm_ap_cosq_field_classifier_map_set(unit,
   7711                                                            classifier_id,
   7712                                                            array_count,
   7713                                                            priority_array,
   7714                                                            cosq_array));        
   7715             } else
   7716 #endif
   7717 #ifdef BCM_TRIDENT2_SUPPORT
   7718             if (SOC_IS_TD2_TT2(unit)) {
   7719                 BCM_IF_ERROR_RETURN
   7720                     (bcm_td2_cosq_field_classifier_map_set(unit,
   7721                                                            classifier_id,
   7722                                                            array_count,
   7723                                                            priority_array,
   7724                                                            cosq_array));        
   7725             } else
   7726 #endif
   7727             {
   7728                 BCM_IF_ERROR_RETURN
   7729                     (bcm_tr3_cosq_field_classifier_map_set(unit,
   7730                                                        classifier_id,
   7731                                                        array_count,
   7732                                                        priority_array,
   7733                                                        cosq_array));
   7734             }
   7735         } else {
   7736             return (BCM_E_UNAVAIL);
   7737         }
   7738     } else 
   7739 #endif
   7740     {
   7741         if (BCM_GPORT_IS_SET(port)) {
   7742             BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port,
   7743                                                        &local_port));
   7744         } else if (SOC_PORT_VALID(unit, port)) {
   7745             local_port = port;
   7746         } else {
   7747             return BCM_E_PORT;
   7748         }
   7749         
   7750         if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(queue_group)) {
   7751             sysportid = BCM_GPORT_UCAST_QUEUE_GROUP_SYSPORTID_GET(queue_group);
   7752             if (sysportid != local_port) {
   7753                 /* The port the queue_group was created on does not match
   7754                  * the input parameter port.
   7755                  */
   7756                 return BCM_E_PORT;
   7757             }
   7758         } else {
   7759             if (!BCM_GPORT_IS_UCAST_SUBSCRIBER_QUEUE_GROUP(queue_group)) {
   7760                 return BCM_E_PARAM;
   7761             }
   7762         }
   7763 
   7764         if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
   7765 #ifdef BCM_APACHE_SUPPORT
   7766             if (SOC_IS_APACHE(unit) &&
   7767                 soc_feature(unit, soc_feature_endpoint_queuing)) {
   7768                 BCM_IF_ERROR_RETURN
   7769                     (bcm_ap_cosq_endpoint_map_set(unit, local_port,
   7770                                                    classifier_id, queue_group,
   7771                                                    array_count, priority_array,
   7772                                                    cosq_array));
   7773             } else
   7774 #endif /* BCM_TRIDENT2_SUPPORT */
   7775 #ifdef BCM_TRIDENT2_SUPPORT
   7776             if (soc_feature(unit, soc_feature_endpoint_queuing)) {
   7777                 BCM_IF_ERROR_RETURN
   7778                     (bcm_td2_cosq_endpoint_map_set(unit, local_port,
   7779                                                    classifier_id, queue_group,
   7780                                                    array_count, priority_array,
   7781                                                    cosq_array));
   7782             } else
   7783 #endif /* BCM_TRIDENT2_SUPPORT */
   7784             {
   7785                 return BCM_E_PARAM;
   7786             }
   7787         } else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
   7788 #ifdef BCM_TRIUMPH3_SUPPORT
   7789             if (soc_feature(unit, soc_feature_service_queuing)) {
   7790 #ifdef BCM_KATANA2_SUPPORT
   7791                 if (SOC_IS_KATANA2(unit)) {
   7792                     BCM_IF_ERROR_RETURN
   7793                         (bcm_kt2_cosq_service_map_set(unit, local_port,
   7794                                                   classifier_id, queue_group,
   7795                                                   array_count, priority_array,
   7796                                                   cosq_array)); 
   7797                 } else 
   7798 #endif
   7799 #ifdef BCM_APACHE_SUPPORT
   7800                 if (SOC_IS_APACHE(unit)) {
   7801                     BCM_IF_ERROR_RETURN(
   7802                         bcm_ap_cosq_service_map_set(unit, local_port,
   7803                                                      classifier_id, queue_group,
   7804                                                      array_count,
   7805                                                      priority_array,
   7806                                                      cosq_array));
   7807                 } else
   7808 #endif /* BCM_APACHE_SUPPORT */
   7809 #ifdef BCM_TRIDENT2_SUPPORT
   7810                 if (SOC_IS_TRIDENT2(unit)
   7811                     || (SOC_IS_TRIDENT2PLUS(unit) || SOC_IS_TITAN2PLUS(unit))) {
   7812                     BCM_IF_ERROR_RETURN(
   7813                         bcm_td2_cosq_service_map_set(unit, local_port,
   7814                                                      classifier_id, queue_group,
   7815                                                      array_count,
   7816                                                      priority_array,
   7817                                                      cosq_array));
   7818                 } else
   7819 #endif /* BCM_TRIDENT2_SUPPORT */
   7820                 {
   7821                     BCM_IF_ERROR_RETURN
   7822                         (bcm_tr3_cosq_service_map_set(unit, local_port,
   7823                                                   classifier_id, queue_group,
   7824                                                   array_count, priority_array,
   7825                                                   cosq_array));
   7826                 }
   7827             } else
   7828 #endif /* BCM_TRIUMPH3_SUPPORT */
   7829             {
   7830                 return BCM_E_UNAVAIL;
   7831             }
   7832         } else {
   7833             return BCM_E_PARAM;
   7834         }
   7835     }
   7836 
   7837     return (BCM_E_NONE);
   7838 }
   7839 
   7840 /*
   7841  * Function:
   7842  *      bcm_esw_cosq_classifier_mapping_set
   7843  * Purpose:
   7844  *      Set the mapping from port, classifier, and internal priority to a COS
   7845  *      queue in a queue group.
   7846  * Parameters:
   7847  *      unit          - (IN) Unit number.
   7848  *      port          - (IN) GPORT ID
   7849  *      classifier_id - (IN) Classifier ID
   7850  *      queue_group   - (IN) Queue group
   7851  *      priority      - (IN) Internal priority
   7852  *      cosq          - (IN) COS queue in queue group  
   7853  * Returns:
   7854  *      BCM_E_xxx
   7855  */
   7856 int
   7857 bcm_esw_cosq_classifier_mapping_set(
   7858     int unit, 
   7859     bcm_gport_t port, 
   7860     int classifier_id, 
   7861     bcm_gport_t queue_group, 
   7862     bcm_cos_t priority, 
   7863     bcm_cos_queue_t cosq)
   7864 {
   7865     if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
   7866         return (BCM_E_UNAVAIL);
   7867     }
   7868     return bcm_esw_cosq_classifier_mapping_multi_set(unit, port, classifier_id,
   7869             queue_group, 1, &priority, &cosq);
   7870 }
   7871 
   7872 /*
   7873  * Function:
   7874  *      bcm_esw_cosq_classifier_mapping_multi_get
   7875  * Purpose:
   7876  *      Get the mapping from port, classifier, and multiple internal priorities
   7877  *      to multiple COS queues in a queue group.
   7878  * Parameters:
   7879  *      unit           - (IN) Unit number.
   7880  *      port           - (IN) GPORT ID
   7881  *      classifier_id  - (IN) Classifier ID
   7882  *      queue_group    - (OUT) Queue group
   7883  *      array_max      - (IN) Size of priority_array and cosq_array
   7884  *      priority_array - (IN) Array of internal priorities
   7885  *      cosq_array     - (OUT) Array of COS queues
   7886  *      array_count    - (OUT) Size of cosq_array
   7887  * Returns:
   7888  *      BCM_E_xxx
   7889  */
   7890 int
   7891 bcm_esw_cosq_classifier_mapping_multi_get(
   7892     int unit, 
   7893     bcm_gport_t port, 
   7894     int classifier_id, 
   7895     bcm_gport_t *queue_group, 
   7896     int array_max, 
   7897     bcm_cos_t *priority_array, 
   7898     bcm_cos_queue_t *cosq_array, 
   7899     int *array_count)
   7900 {
   7901     bcm_port_t local_port;
   7902 
   7903 #ifdef BCM_TRIUMPH3_SUPPORT
   7904     if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
   7905         if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
   7906 #ifdef BCM_KATANA2_SUPPORT
   7907             if (SOC_IS_KATANA2(unit)) {
   7908                 return (bcm_kt2_cosq_field_classifier_map_get(unit,
   7909                                                           classifier_id,
   7910                                                           array_max,
   7911                                                           priority_array,
   7912                                                           cosq_array,
   7913                                                           array_count)); 
   7914             } else
   7915 #endif
   7916 #ifdef BCM_TOMAHAWK3_SUPPORT
   7917             if (SOC_IS_TOMAHAWK3(unit)) {
   7918                 return (bcm_th3_cosq_field_classifier_map_get(unit,
   7919                                                              classifier_id,
   7920                                                              array_max,
   7921                                                              priority_array,
   7922                                                              cosq_array,
   7923                                                              array_count));
   7924             } else
   7925 #endif
   7926 #ifdef BCM_TOMAHAWK_SUPPORT
   7927             if (SOC_IS_TOMAHAWKX(unit)) {
   7928                 return (bcm_th_cosq_field_classifier_map_get(unit,
   7929                                                              classifier_id,
   7930                                                              array_max,
   7931                                                              priority_array,
   7932                                                              cosq_array,
   7933                                                              array_count));
   7934             } else
   7935 #endif
   7936 #ifdef BCM_MONTEREY_SUPPORT
   7937             if (SOC_IS_MONTEREY(unit)) {
   7938                 return (bcm_mn_cosq_field_classifier_map_get(unit,
   7939                                                              classifier_id,
   7940                                                              array_max,
   7941                                                              priority_array,
   7942                                                              cosq_array,
   7943                                                              array_count));
   7944             } else
   7945 #endif /* BCM_MONTEREY_SUPPORT */
   7946 #ifdef BCM_HELIX5_SUPPORT
   7947             if (SOC_IS_HELIX5(unit)) {
   7948                 return (bcm_hx5_cosq_field_classifier_map_get(unit,
   7949                                                               classifier_id,
   7950                                                               array_max,
   7951                                                               priority_array,
   7952                                                               cosq_array,
   7953                                                               array_count)); 
   7954             } else
   7955 #endif
   7956 #ifdef BCM_TRIDENT3_SUPPORT
   7957             if (SOC_IS_TRIDENT3X(unit)) {
   7958                 return (bcm_td3_cosq_field_classifier_map_get(unit,
   7959                                                               classifier_id,
   7960                                                               array_max,
   7961                                                               priority_array,
   7962                                                               cosq_array,
   7963                                                               array_count)); 
   7964             } else
   7965 #endif
   7966 #ifdef BCM_APACHE_SUPPORT
   7967             if (SOC_IS_APACHE(unit)) {
   7968                 return (bcm_ap_cosq_field_classifier_map_get(unit,
   7969                                                               classifier_id,
   7970                                                               array_max,
   7971                                                               priority_array,
   7972                                                               cosq_array,
   7973                                                               array_count)); 
   7974             } else
   7975 #endif
   7976 #ifdef BCM_TRIDENT2_SUPPORT
   7977             if (SOC_IS_TD2_TT2(unit)) {
   7978                 return (bcm_td2_cosq_field_classifier_map_get(unit,
   7979                                                               classifier_id,
   7980                                                               array_max,
   7981                                                               priority_array,
   7982                                                               cosq_array,
   7983                                                               array_count)); 
   7984             } else
   7985 #endif
   7986             {
   7987                 return (bcm_tr3_cosq_field_classifier_map_get(unit,
   7988                                                           classifier_id,
   7989                                                           array_max,
   7990                                                           priority_array,
   7991                                                           cosq_array,
   7992                                                           array_count));
   7993             }
   7994         } else {
   7995             return (BCM_E_UNAVAIL);
   7996         }
   7997     } else
   7998 #endif
   7999     {
   8000         if (BCM_GPORT_IS_SET(port)) {
   8001             BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port,
   8002                                                        &local_port));
   8003         } else if (SOC_PORT_VALID(unit, port)) {
   8004             local_port = port;
   8005         } else {
   8006             return BCM_E_PORT;
   8007         }
   8008 
   8009         if (NULL == queue_group) {
   8010             return BCM_E_PARAM;
   8011         }
   8012 
   8013         if (array_max > 0) {
   8014             if (NULL == priority_array || NULL == cosq_array) {
   8015                 return BCM_E_PARAM;
   8016             }
   8017             
   8018             if (NULL == array_count) {
   8019                 return BCM_E_PARAM;
   8020             }
   8021         }
   8022 
   8023         if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
   8024 #ifdef BCM_APACHE_SUPPORT
   8025             if (SOC_IS_APACHE(unit) &&
   8026                 soc_feature(unit, soc_feature_endpoint_queuing)) {
   8027                 BCM_IF_ERROR_RETURN
   8028                     (bcm_ap_cosq_endpoint_map_get(unit, local_port,
   8029                                                    classifier_id,
   8030                                                    queue_group,
   8031                                                    array_max,
   8032                                                    priority_array,
   8033                                                    cosq_array,
   8034                                                    array_count));
   8035             } else
   8036 #endif /* BCM_APACHE_SUPPORT */
   8037 #ifdef BCM_TRIDENT2_SUPPORT
   8038             if (soc_feature(unit, soc_feature_endpoint_queuing)) {
   8039                 BCM_IF_ERROR_RETURN
   8040                     (bcm_td2_cosq_endpoint_map_get(unit, local_port,
   8041                                                    classifier_id,
   8042                                                    queue_group,
   8043                                                    array_max,
   8044                                                    priority_array,
   8045                                                    cosq_array,
   8046                                                    array_count));
   8047             } else
   8048 #endif /* BCM_TRIDENT2_SUPPORT */
   8049             {
   8050                 return BCM_E_PARAM;
   8051             }
   8052         } else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
   8053 #ifdef BCM_TRIUMPH3_SUPPORT
   8054             if (soc_feature(unit, soc_feature_service_queuing)) {
   8055 #ifdef BCM_KATANA2_SUPPORT
   8056                 if (SOC_IS_KATANA2(unit)) {
   8057                     BCM_IF_ERROR_RETURN
   8058                         (bcm_kt2_cosq_service_map_get(unit, local_port,
   8059                                                   classifier_id,
   8060                                                   queue_group,
   8061                                                   array_max,
   8062                                                   priority_array,
   8063                                                   cosq_array,
   8064                                                   array_count)); 
   8065                 } else
   8066 #endif
   8067 #ifdef BCM_APACHE_SUPPORT
   8068                 if (SOC_IS_APACHE(unit)) {
   8069                     BCM_IF_ERROR_RETURN(
   8070                         bcm_ap_cosq_service_map_get(unit, local_port,
   8071                                                      classifier_id,
   8072                                                      queue_group,
   8073                                                      array_max,
   8074                                                      priority_array,
   8075                                                      cosq_array, array_count));
   8076                 } else
   8077 #endif /* BCM_APACHE_SUPPORT */
   8078 #ifdef BCM_TRIDENT2_SUPPORT
   8079                 if (SOC_IS_TRIDENT2(unit)
   8080                     || (SOC_IS_TRIDENT2PLUS(unit) || SOC_IS_TITAN2PLUS(unit))) {
   8081                     BCM_IF_ERROR_RETURN(
   8082                         bcm_td2_cosq_service_map_get(unit, local_port,
   8083                                                      classifier_id,
   8084                                                      queue_group,
   8085                                                      array_max,
   8086                                                      priority_array,
   8087                                                      cosq_array, array_count));
   8088                 } else
   8089 #endif /* BCM_TRIDENT2_SUPPORT */
   8090                 {
   8091                     BCM_IF_ERROR_RETURN
   8092                         (bcm_tr3_cosq_service_map_get(unit, local_port,
   8093                                                   classifier_id,
   8094                                                   queue_group,
   8095                                                   array_max,
   8096                                                   priority_array,
   8097                                                   cosq_array,
   8098                                                   array_count));
   8099                 }
   8100             } else
   8101 #endif /* BCM_TRIUMPH3_SUPPORT */
   8102             {
   8103                 return BCM_E_UNAVAIL;
   8104             }
   8105         } else {
   8106             return BCM_E_PARAM;
   8107         }
   8108     }
   8109 
   8110     return (BCM_E_NONE);
   8111 }
   8112 
   8113 /*
   8114  * Function:
   8115  *      bcm_esw_cosq_classifier_mapping_get
   8116  * Purpose:
   8117  *      Get the mapping from port, classifier, and internal priority to a COS
   8118  *      queue in a queue group.
   8119  * Parameters:
   8120  *      unit          - (IN) Unit number.
   8121  *      port          - (IN) GPORT ID
   8122  *      classifier_id - (IN) Classifier ID
   8123  *      queue_group   - (OUT) Queue group
   8124  *      priority      - (IN) Internal priority
   8125  *      cosq          - (OUT) COS queue in queue group  
   8126  * Returns:
   8127  *      BCM_E_xxx
   8128  */
   8129 int
   8130 bcm_esw_cosq_classifier_mapping_get(
   8131     int unit, 
   8132     bcm_gport_t port, 
   8133     int classifier_id, 
   8134     bcm_gport_t *queue_group, 
   8135     bcm_cos_t priority, 
   8136     bcm_cos_queue_t *cosq)
   8137 {
   8138     int array_count;
   8139 
   8140     if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
   8141         return (BCM_E_UNAVAIL);
   8142     }
   8143 
   8144     return bcm_esw_cosq_classifier_mapping_multi_get(unit, port, classifier_id,
   8145             queue_group, 1, &priority, cosq, &array_count);
   8146 }
   8147 
   8148 /*
   8149  * Function:
   8150  *      bcm_esw_cosq_classifier_mapping_clear
   8151  * Purpose:
   8152  *      Clear the mapping from port, classifier, and internal priorities
   8153  *      to COS queues in a queue group.
   8154  * Parameters:
   8155  *      unit          - (IN) Unit number.
   8156  *      port          - (IN) GPORT ID
   8157  *      classifier_id - (IN) Classifier ID
   8158  * Returns:
   8159  *      BCM_E_xxx
   8160  */
   8161 int
   8162 bcm_esw_cosq_classifier_mapping_clear(
   8163     int unit, 
   8164     bcm_gport_t port, 
   8165     int classifier_id)
   8166 {
   8167     bcm_port_t local_port;
   8168 
   8169 #ifdef BCM_TRIUMPH3_SUPPORT
   8170     if (_BCM_COSQ_CLASSIFIER_IS_FIELD(classifier_id)) {
   8171         if (soc_feature(unit, soc_feature_field_ingress_cosq_override)) {
   8172 #ifdef BCM_KATANA2_SUPPORT
   8173             if (SOC_IS_KATANA2(unit)) {
   8174                 BCM_IF_ERROR_RETURN
   8175                     (bcm_kt2_cosq_field_classifier_map_clear(unit, 
   8176                                                              classifier_id));
   8177             } else
   8178 #endif
   8179 #ifdef BCM_TOMAHAWK3_SUPPORT
   8180             if (SOC_IS_TOMAHAWK3(unit)) {
   8181                 BCM_IF_ERROR_RETURN
   8182                     (bcm_th3_cosq_field_classifier_map_clear(unit,
   8183                                                             classifier_id));
   8184             } else
   8185 #endif
   8186 #ifdef BCM_TOMAHAWK_SUPPORT
   8187             if (SOC_IS_TOMAHAWKX(unit)) {
   8188                 BCM_IF_ERROR_RETURN
   8189                     (bcm_th_cosq_field_classifier_map_clear(unit,
   8190                                                             classifier_id));
   8191             } else
   8192 #endif
   8193 #ifdef BCM_MONTEREY_SUPPORT
   8194             if (SOC_IS_MONTEREY(unit)) {
   8195                 BCM_IF_ERROR_RETURN
   8196                     (bcm_mn_cosq_field_classifier_map_clear(unit,
   8197                                                              classifier_id));
   8198             } else
   8199 #endif /* BCM_MONTEREY_SUPPORT */
   8200 #ifdef BCM_HELIX5_SUPPORT
   8201             if (SOC_IS_HELIX5(unit)) {
   8202                 BCM_IF_ERROR_RETURN
   8203                     (bcm_hx5_cosq_field_classifier_map_clear(unit,
   8204                                                              classifier_id));
   8205             } else
   8206 #endif
   8207 #ifdef BCM_TRIDENT3_SUPPORT
   8208             if (SOC_IS_TRIDENT3X(unit)) {
   8209                 BCM_IF_ERROR_RETURN
   8210                     (bcm_td3_cosq_field_classifier_map_clear(unit,
   8211                                                              classifier_id));
   8212             } else
   8213 #endif
   8214 #ifdef BCM_APACHE_SUPPORT
   8215             if (SOC_IS_APACHE(unit)) {
   8216                 BCM_IF_ERROR_RETURN
   8217                     (bcm_ap_cosq_field_classifier_map_clear(unit, 
   8218                                                              classifier_id));
   8219             } else
   8220 #endif
   8221 #ifdef BCM_TRIDENT2_SUPPORT
   8222             if (SOC_IS_TD2_TT2(unit)) {
   8223                 BCM_IF_ERROR_RETURN
   8224                     (bcm_td2_cosq_field_classifier_map_clear(unit, 
   8225                                                              classifier_id));
   8226             } else
   8227 #endif
   8228             {
   8229                 BCM_IF_ERROR_RETURN
   8230                     (bcm_tr3_cosq_field_classifier_map_clear(unit, 
   8231                                                              classifier_id));
   8232             }
   8233         } else {
   8234             return (BCM_E_UNAVAIL);
   8235         }
   8236     } else 
   8237 #endif
   8238     {
   8239         if (BCM_GPORT_IS_SET(port)) {
   8240             BCM_IF_ERROR_RETURN(bcm_esw_port_local_get(unit, port, 
   8241                                                        &local_port));
   8242         } else if (SOC_PORT_VALID(unit, port)) {
   8243             local_port = port;
   8244         } else {
   8245             return BCM_E_PORT;
   8246         }
   8247 
   8248         if (_BCM_COSQ_CLASSIFIER_IS_ENDPOINT(classifier_id)) {
   8249 #ifdef BCM_APACHE_SUPPORT
   8250             if (SOC_IS_APACHE(unit) &&
   8251                 soc_feature(unit, soc_feature_endpoint_queuing)) {
   8252                 BCM_IF_ERROR_RETURN
   8253                     (bcm_ap_cosq_endpoint_map_clear(unit, local_port,
   8254                                                      classifier_id));
   8255             } else
   8256 #endif /* BCM_APACHE_SUPPORT */
   8257 #ifdef BCM_TRIDENT2_SUPPORT
   8258             if (soc_feature(unit, soc_feature_endpoint_queuing)) {
   8259                 BCM_IF_ERROR_RETURN
   8260                     (bcm_td2_cosq_endpoint_map_clear(unit, local_port,
   8261                                                      classifier_id));
   8262             } else
   8263 #endif /* BCM_TRIDENT2_SUPPORT */
   8264             {
   8265                 return BCM_E_PARAM;
   8266             }
   8267         } else if (_BCM_COSQ_CLASSIFIER_IS_SERVICE(classifier_id)) {
   8268 #ifdef BCM_TRIUMPH3_SUPPORT
   8269             if (soc_feature(unit, soc_feature_service_queuing)) {
   8270 #ifdef BCM_KATANA2_SUPPORT
   8271                 if (SOC_IS_KATANA2(unit)) {
   8272                     BCM_IF_ERROR_RETURN
   8273                         (bcm_kt2_cosq_service_map_clear(unit, local_port,
   8274                                                         classifier_id)); 
   8275                 } else
   8276 #endif
   8277 #ifdef BCM_APACHE_SUPPORT
   8278                 if (SOC_IS_APACHE(unit)) {
   8279                     BCM_IF_ERROR_RETURN(
   8280                         bcm_ap_cosq_service_map_clear(unit, local_port,
   8281                                                        classifier_id));
   8282                 } else
   8283 #endif /* BCM_APACHE_SUPPORT */
   8284 #ifdef BCM_TRIDENT2_SUPPORT
   8285                 if (SOC_IS_TRIDENT2(unit)
   8286                     || (SOC_IS_TRIDENT2PLUS(unit) || SOC_IS_TITAN2PLUS(unit))) {
   8287                     BCM_IF_ERROR_RETURN(
   8288                         bcm_td2_cosq_service_map_clear(unit, local_port,
   8289                                                        classifier_id));
   8290                 } else
   8291 #endif /* BCM_TRIDENT2_SUPPORT */
   8292                 {
   8293                     BCM_IF_ERROR_RETURN
   8294                         (bcm_tr3_cosq_service_map_clear(unit, local_port,
   8295                                                         classifier_id));
   8296                 }
   8297             } else
   8298 #endif /* BCM_TRIUMPH3_SUPPORT */
   8299             {
   8300                 return BCM_E_UNAVAIL;
   8301             }
   8302         } else {
   8303             return BCM_E_PARAM;
   8304         }
   8305     }
   8306 
   8307     return (BCM_E_NONE);
   8308 }
   8309 
   8310 int 
   8311 bcm_esw_cosq_classifier_id_get(
   8312     int unit, 
   8313     bcm_cosq_classifier_t *classifier, 
   8314     int array_count, 
   8315     bcm_cos_t *priority_array, 
   8316     bcm_cos_queue_t *cosq_array, 
   8317     int *classifier_id)
   8318 {
   8319     int rv = BCM_E_UNAVAIL;
   8320     if ((NULL == priority_array)||(NULL == cosq_array)||
   8321         (NULL == classifier_id) ||(NULL == classifier)||
   8322         ( 0 == array_count)){
   8323         return BCM_E_PARAM;
   8324     }
   8325 #ifdef BCM_TRIUMPH3_SUPPORT
   8326     if (classifier->flags & BCM_COSQ_CLASSIFIER_FIELD) { 
   8327         if (SOC_IS_TRIUMPH3(unit)){
   8328             rv = bcm_tr3_cosq_classifier_id_get(unit, classifier, array_count,
   8329                     priority_array, cosq_array, classifier_id);
   8330         }
   8331     }
   8332 #endif
   8333     return rv;
   8334 }
   8335 /*
   8336  * Function:
   8337  *      bcm_esw_cosq_cpu_cosq_enable_set
   8338  * Purpose:
   8339  *      To enable/disable Rx of packets on the specified CPU cosq.
   8340  * Parameters:
   8341  *      unit          - (IN) Unit number.
   8342  *      cosq          - (IN) CPU Cosq ID
   8343  *      enable        - (IN) Enable/Disable
   8344  * Returns:
   8345  *      BCM_E_xxx
   8346  */
   8347 int
   8348 bcm_esw_cosq_cpu_cosq_enable_set(
   8349     int unit,
   8350     bcm_cos_queue_t cosq,
   8351     int enable)
   8352 {
   8353 #ifdef BCM_TOMAHAWK3_SUPPORT
   8354     if (SOC_IS_TOMAHAWK3(unit)) {
   8355         BCM_IF_ERROR_RETURN(
   8356             bcm_th3_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8357     } else
   8358 #endif /* BCM_TOMAHAWK3_SUPPORT */
   8359 #ifdef BCM_TOMAHAWK_SUPPORT
   8360     if (SOC_IS_TOMAHAWKX(unit)) {
   8361         BCM_IF_ERROR_RETURN(
   8362             bcm_th_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8363     } else
   8364 #endif /* BCM_TOMAHAWK_SUPPORT */
   8365 #ifdef BCM_MONTEREY_SUPPORT
   8366     if (SOC_IS_MONTEREY(unit)) {
   8367           BCM_IF_ERROR_RETURN(
   8368             bcm_mn_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8369     } else 
   8370 #endif /* BCM_MONTEREY_SUPPORT */
   8371 #ifdef BCM_HELIX5_SUPPORT
   8372     if (SOC_IS_HELIX5(unit)) {
   8373         BCM_IF_ERROR_RETURN
   8374             (bcm_hx5_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8375     } else
   8376 #endif /* BCM_HELIX5_SUPPORT */
   8377 #ifdef BCM_TRIDENT3_SUPPORT
   8378     if (SOC_IS_TRIDENT3X(unit)) {
   8379         BCM_IF_ERROR_RETURN
   8380             (bcm_td3_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8381     } else
   8382 #endif /* BCM_TRIDENT3_SUPPORT */
   8383 #ifdef BCM_APACHE_SUPPORT
   8384     if (SOC_IS_APACHE(unit)){
   8385         BCM_IF_ERROR_RETURN(
   8386             bcm_ap_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8387     } else
   8388 #endif /*BCM_APACHE_SUPPORT*/
   8389 #ifdef BCM_TRIDENT2_SUPPORT
   8390     if (SOC_IS_TD2_TT2(unit)) {
   8391         BCM_IF_ERROR_RETURN(
   8392             bcm_td2_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8393     } else
   8394 #endif /* BCM_TRIDENT2_SUPPORT */
   8395 #ifdef BCM_TRIUMPH3_SUPPORT
   8396     if (SOC_IS_TRIUMPH3(unit)) {
   8397         BCM_IF_ERROR_RETURN(
   8398             bcm_tr3_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8399     } else
   8400 #endif /* BCM_TRIUMPH3_SUPPORT */
   8401 #ifdef BCM_TRIDENT_SUPPORT
   8402     if (SOC_IS_TD_TT(unit)) {
   8403         BCM_IF_ERROR_RETURN(
   8404             bcm_td_cosq_cpu_cosq_enable_set(unit, cosq, enable));
   8405     } else
   8406 #endif /* BCM_TRIDENT_SUPPORT */
   8407     {
   8408         return BCM_E_UNAVAIL;
   8409     }
   8410     return BCM_E_NONE;
   8411 }
   8412 
   8413 /*
   8414  * Function:
   8415  *      bcm_esw_cosq_cpu_cosq_enable_get
   8416  * Purpose:
   8417  *      To get enable/disable status on Rx of packets on the specified CPU cosq.
   8418  * Parameters:
   8419  *      unit          - (IN) Unit number.
   8420  *      cosq          - (IN) CPU Cosq ID
   8421  *      enable        - (OUT) Enable/Disable
   8422  * Returns:
   8423  *      BCM_E_xxx
   8424  */
   8425 int
   8426 bcm_esw_cosq_cpu_cosq_enable_get(
   8427     int unit,
   8428     bcm_cos_queue_t cosq,
   8429     int *enable)
   8430 {
   8431 #ifdef BCM_TOMAHAWK3_SUPPORT
   8432     if (SOC_IS_TOMAHAWK3(unit)) {
   8433         BCM_IF_ERROR_RETURN(
   8434             bcm_th3_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8435     } else
   8436 #endif /* BCM_TOMAHAWK_SUPPORT */
   8437 #ifdef BCM_TOMAHAWK_SUPPORT
   8438     if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
   8439         BCM_IF_ERROR_RETURN(
   8440             bcm_th_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8441     } else
   8442 #endif /* BCM_TOMAHAWK_SUPPORT */
   8443 #ifdef BCM_MONTEREY_SUPPORT
   8444     if (SOC_IS_MONTEREY(unit)) {
   8445           BCM_IF_ERROR_RETURN(
   8446             bcm_mn_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8447     } else
   8448 #endif /* BCM_MONTEREY_SUPPORT */
   8449 #ifdef BCM_HELIX5_SUPPORT
   8450     if (SOC_IS_HELIX5(unit)) {
   8451         BCM_IF_ERROR_RETURN
   8452             (bcm_hx5_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8453     } else
   8454 #endif /* BCM_HELIX5_SUPPORT */
   8455 #ifdef BCM_TRIDENT3_SUPPORT
   8456     if (SOC_IS_TRIDENT3X(unit)) {
   8457         BCM_IF_ERROR_RETURN
   8458             (bcm_td3_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8459     } else
   8460 #endif /* BCM_TRIDENT3_SUPPORT */
   8461 #ifdef BCM_APACHE_SUPPORT
   8462     if (SOC_IS_APACHE(unit)) {
   8463         BCM_IF_ERROR_RETURN(
   8464             bcm_ap_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8465     } else 
   8466 #endif /* BCM_APACHE_SUPPORT*/
   8467 #ifdef BCM_TRIDENT2_SUPPORT
   8468     if (SOC_IS_TD2_TT2(unit)) {
   8469         BCM_IF_ERROR_RETURN(
   8470             bcm_td2_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8471     } else
   8472 #endif /* BCM_TRIDENT2_SUPPORT */
   8473 #ifdef BCM_TRIUMPH3_SUPPORT
   8474     if (SOC_IS_TRIUMPH3(unit)) {
   8475         BCM_IF_ERROR_RETURN(
   8476             bcm_tr3_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8477     } else
   8478 #endif /* BCM_TRIUMPH3_SUPPORT */
   8479 #ifdef BCM_TRIDENT_SUPPORT
   8480     if (SOC_IS_TD_TT(unit)) {
   8481         BCM_IF_ERROR_RETURN(
   8482             bcm_td_cosq_cpu_cosq_enable_get(unit, cosq, enable));
   8483     } else
   8484 #endif /* BCM_TRIDENT_SUPPORT */
   8485     {
   8486         return BCM_E_UNAVAIL;
   8487     }
   8488     return BCM_E_NONE;
   8489 }
   8490 
   8491 int
   8492 bcm_esw_cosq_service_pool_set(
   8493     int unit,
   8494     bcm_service_pool_id_t id,
   8495     bcm_cosq_service_pool_t cosq_service_pool)
   8496 {  
   8497 #ifdef BCM_TOMAHAWK3_SUPPORT
   8498     if (SOC_IS_TOMAHAWK3(unit)) {
   8499         BCM_IF_ERROR_RETURN(
   8500             bcm_th3_cosq_service_pool_set(unit, id, cosq_service_pool));
   8501     } else
   8502 #endif /* BCM_TOMAHAWK3_SUPPORT */
   8503 #ifdef BCM_TRIDENT2_SUPPORT
   8504     if (SOC_IS_TD2_TT2(unit)) {
   8505         BCM_IF_ERROR_RETURN(
   8506             bcm_td2_cosq_service_pool_set(unit, id, cosq_service_pool));
   8507     } else
   8508 #endif /* BCM_TRIDENT2_SUPPORT */
   8509     {
   8510         return BCM_E_UNAVAIL;
   8511     }
   8512     return BCM_E_NONE;
   8513 }
   8514 
   8515 int
   8516 bcm_esw_cosq_service_pool_get(
   8517     int unit,
   8518     bcm_service_pool_id_t id,
   8519     bcm_cosq_service_pool_t *cosq_service_pool)
   8520 {
   8521 #ifdef BCM_TOMAHAWK3_SUPPORT
   8522     if (SOC_IS_TOMAHAWK3(unit)) {
   8523         BCM_IF_ERROR_RETURN(
   8524             bcm_th3_cosq_service_pool_get(unit, id, cosq_service_pool));
   8525     } else
   8526 #endif /* BCM_TOMAHAWK3_SUPPORT */
   8527 #ifdef BCM_TRIDENT2_SUPPORT
   8528     if (SOC_IS_TD2_TT2(unit)) {
   8529         BCM_IF_ERROR_RETURN(
   8530             bcm_td2_cosq_service_pool_get(unit, id, cosq_service_pool));
   8531     } else
   8532 #endif /* BCM_TRIDENT2_SUPPORT */
   8533     {
   8534         return BCM_E_UNAVAIL;
   8535     }
   8536     return BCM_E_NONE;
   8537 }
   8538 
   8539 /*
   8540  * Function:
   8541  *     bcm_esw_cosq_pfc_class_mapping_set
   8542  * Purpose:
   8543  *     Set PFC mapping for port. PFC class is mapped to cosq or scheduler node gports.
   8544  * Parameters:
   8545  *     unit             - (IN) unit number
   8546  *     port             - (IN) port number
   8547  *     array_count      - (IN) count of mapping
   8548  *     mapping_array    - (IN) mappings 
   8549  * Returns:
   8550  *     BCM_E_XXX
   8551  */
   8552 int
   8553 bcm_esw_cosq_pfc_class_mapping_set(
   8554     int unit,
   8555     bcm_gport_t port,
   8556     int array_count,
   8557     bcm_cosq_pfc_class_mapping_t *mapping_array)
   8558 {
   8559 #ifdef BCM_TOMAHAWK_SUPPORT
   8560     if (SOC_IS_TOMAHAWKX(unit)) {
   8561         BCM_IF_ERROR_RETURN(
   8562             bcm_th_cosq_pfc_class_mapping_set(unit, port,
   8563                                               array_count, mapping_array));
   8564     } else
   8565 #endif /* BCM_TOMAHAWK_SUPPORT */
   8566 #ifdef BCM_MONTEREY_SUPPORT
   8567     if (SOC_IS_MONTEREY(unit)) {
   8568         BCM_IF_ERROR_RETURN(
   8569             _bcm_mn_cosq_pfc_class_mapping_set(unit, port,
   8570                                                array_count, mapping_array));
   8571     } else
   8572 #endif /* BCM_MONTEREY_SUPPORT */
   8573 #ifdef BCM_HELIX5_SUPPORT
   8574     if (SOC_IS_HELIX5(unit)) {
   8575         BCM_IF_ERROR_RETURN(
   8576             bcm_hx5_cosq_pfc_class_mapping_set(unit, port,
   8577                                                array_count, mapping_array));
   8578     } else
   8579 #endif /* BCM_HELIX5_SUPPORT */
   8580 #ifdef BCM_TRIDENT3_SUPPORT
   8581     if (SOC_IS_TRIDENT3X(unit)) {
   8582         BCM_IF_ERROR_RETURN(
   8583             bcm_td3_cosq_pfc_class_mapping_set(unit, port,
   8584                                                array_count, mapping_array));
   8585     } else
   8586 #endif /* BCM_TRIDENT3_SUPPORT */
   8587 #ifdef BCM_APACHE_SUPPORT
   8588     if (SOC_IS_APACHE(unit)) {
   8589         BCM_IF_ERROR_RETURN(
   8590             _bcm_ap_cosq_pfc_class_mapping_set(unit, port, 
   8591                                                array_count, mapping_array));
   8592     } else
   8593 #endif /* BCM_APACHE_SUPPORT */
   8594 #ifdef BCM_TRIDENT2_SUPPORT
   8595     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TITAN2X(unit)) {
   8596         BCM_IF_ERROR_RETURN(
   8597             bcm_td2_cosq_pfc_class_mapping_set(unit, port, 
   8598                                                array_count, mapping_array));
   8599     } else
   8600 #endif /* BCM_TRIDENT2_SUPPORT */
   8601 #ifdef BCM_TRIDENT_SUPPORT
   8602     if (SOC_IS_TRIDENT(unit)) {
   8603         BCM_IF_ERROR_RETURN(
   8604             bcm_td_cosq_pfc_class_mapping_set(unit, port, 
   8605                                               array_count, mapping_array));
   8606     } else
   8607 #endif /* BCM_TRIDENT_SUPPORT */
   8608 #ifdef BCM_KATANA2_SUPPORT
   8609     if (SOC_IS_KATANA2(unit))  {
   8610         BCM_IF_ERROR_RETURN(
   8611             bcm_kt2_cosq_pfc_class_mapping_set(unit, port, 
   8612                                                array_count, mapping_array));
   8613     } else 
   8614 #endif /* BCM_KATANA2_SUPPORT */
   8615 #ifdef BCM_TRIUMPH3_SUPPORT
   8616     if (SOC_IS_TRIUMPH3(unit))  {
   8617         BCM_IF_ERROR_RETURN(
   8618             bcm_tr3_cosq_pfc_class_mapping_set(unit, port, 
   8619                                                array_count, mapping_array));
   8620     } else 
   8621 #endif /* BCM_TRIUMPH3_SUPPORT */
   8622     {
   8623         return BCM_E_UNAVAIL;
   8624     }
   8625     return BCM_E_NONE;
   8626 }
   8627 
   8628 /*
   8629  * Function:
   8630  *     bcm_esw_cosq_pfc_class_mapping_get
   8631  * Purpose:
   8632  *     Get PFC mapping of a port. 
   8633  *     Retrieves cosq or scheduler node gports associated to PFC classes.
   8634  * Parameters:
   8635  *     unit             - (IN) unit number
   8636  *     port             - (IN) port number
   8637  *     array_max        - (IN) max retrieve count
   8638  *     mapping_array    - (OUT) mappings 
   8639  *     array_count      - (OUT) retrieved mapping count
   8640  * Returns:
   8641  *     BCM_E_XXX
   8642  */
   8643 int
   8644 bcm_esw_cosq_pfc_class_mapping_get(
   8645     int unit,
   8646     bcm_gport_t port,
   8647     int array_max,
   8648     bcm_cosq_pfc_class_mapping_t *mapping_array,
   8649     int *array_count)
   8650 {
   8651 #ifdef BCM_TOMAHAWK_SUPPORT
   8652     if (SOC_IS_TOMAHAWKX(unit)) {
   8653         BCM_IF_ERROR_RETURN(
   8654             bcm_th_cosq_pfc_class_mapping_get(unit, port, array_max,
   8655                                               mapping_array, array_count));
   8656     } else
   8657 #endif /* BCM_TOMAHAWK_SUPPORT */
   8658 #ifdef BCM_MONTEREY_SUPPORT
   8659     if (SOC_IS_MONTEREY(unit)) {
   8660         BCM_IF_ERROR_RETURN(
   8661             _bcm_mn_cosq_pfc_class_mapping_get(unit, port, array_max,
   8662                                                array_count, mapping_array)); 
   8663     } else
   8664 #endif /* BCM_MONTEREY_SUPPORT */
   8665 
   8666 #ifdef BCM_HELIX5_SUPPORT
   8667     if (SOC_IS_HELIX5(unit)) {
   8668         BCM_IF_ERROR_RETURN(
   8669             bcm_hx5_cosq_pfc_class_mapping_get(unit, port, array_max,
   8670                                                mapping_array,array_count));
   8671     } else
   8672 #endif /* BCM_HELIX5_SUPPORT */
   8673 #ifdef BCM_TRIDENT3_SUPPORT
   8674     if (SOC_IS_TRIDENT3X(unit)) {
   8675         BCM_IF_ERROR_RETURN(
   8676             bcm_td3_cosq_pfc_class_mapping_get(unit, port, array_max,
   8677                                                mapping_array,array_count));
   8678     } else
   8679 #endif /* BCM_TRIDENT3_SUPPORT */
   8680 #ifdef BCM_APACHE_SUPPORT
   8681     if (SOC_IS_APACHE(unit)) {
   8682         BCM_IF_ERROR_RETURN(
   8683             _bcm_ap_cosq_pfc_class_mapping_get(unit, port, array_max, 
   8684                                                array_count, mapping_array));
   8685     } else
   8686 #endif 
   8687 #ifdef BCM_TRIDENT2_SUPPORT
   8688     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TITAN2X(unit)) {
   8689         BCM_IF_ERROR_RETURN(
   8690             bcm_td2_cosq_pfc_class_mapping_get(unit, port, array_max, 
   8691                                                mapping_array, array_count));
   8692     } else
   8693 #endif /* BCM_TRIDENT2_SUPPORT */
   8694 
   8695 #ifdef BCM_TRIDENT_SUPPORT
   8696     if (SOC_IS_TRIDENT(unit)) {
   8697         BCM_IF_ERROR_RETURN(
   8698             bcm_td_cosq_pfc_class_mapping_get(unit, port, array_max, 
   8699                                               mapping_array, array_count));
   8700     } else
   8701 #endif /* BCM_TRIDENT_SUPPORT */
   8702 #ifdef BCM_KATANA2_SUPPORT
   8703     if (SOC_IS_KATANA2(unit)) {
   8704         BCM_IF_ERROR_RETURN(
   8705             bcm_kt2_cosq_pfc_class_mapping_get(unit, port, array_max, 
   8706                                                array_count, mapping_array));
   8707     } else
   8708 #endif 
   8709 #ifdef BCM_TRIUMPH3_SUPPORT
   8710     if (SOC_IS_TRIUMPH3(unit)) {
   8711         BCM_IF_ERROR_RETURN(
   8712             bcm_tr3_cosq_pfc_class_mapping_get(unit, port, array_max, 
   8713                                                mapping_array, array_count));
   8714     } else
   8715 #endif 
   8716     {
   8717         return BCM_E_UNAVAIL;
   8718     }
   8719     return BCM_E_NONE;
   8720 }
   8721 
   8722 /*
   8723  * Function:
   8724  *     bcm_esw_cosq_safc_class_mapping_set
   8725  * Purpose:
   8726  *     Set SAFC mapping for port. SAFC class
   8727  *     is mapped to cosq or scheduler node gports.
   8728  * Parameters:
   8729  *     unit             - (IN) unit number
   8730  *     port             - (IN) port number
   8731  *     array_count      - (IN) count of mapping
   8732  *     mapping_array    - (IN) mappings
   8733  * Returns:
   8734  *     BCM_E_XXX
   8735  */
   8736 int
   8737 bcm_esw_cosq_safc_class_mapping_set(
   8738     int unit,
   8739     bcm_gport_t port,
   8740     int array_count,
   8741     bcm_cosq_safc_class_mapping_t *mapping_array)
   8742 {
   8743 #ifdef BCM_TOMAHAWK_SUPPORT
   8744     if (SOC_IS_TOMAHAWKX(unit)) {
   8745         BCM_IF_ERROR_RETURN(
   8746             bcm_th_cosq_safc_class_mapping_set(unit, port,
   8747                                                array_count, mapping_array));
   8748     } else
   8749 #endif /* BCM_TOMAHAWK_SUPPORT */
   8750 
   8751 #ifdef BCM_HELIX5_SUPPORT
   8752     if (SOC_IS_HELIX5(unit)) {
   8753         BCM_IF_ERROR_RETURN(
   8754             bcm_hx5_cosq_safc_class_mapping_set(unit, port,
   8755                                                 array_count, mapping_array));
   8756     } else
   8757 #endif /* BCM_HELIX5_SUPPORT */
   8758 
   8759 #ifdef BCM_TRIDENT3_SUPPORT
   8760     if (SOC_IS_TRIDENT3X(unit)) {
   8761         BCM_IF_ERROR_RETURN(
   8762             bcm_td3_cosq_safc_class_mapping_set(unit, port,
   8763                                                 array_count, mapping_array));
   8764     } else
   8765 #endif /* BCM_TRIDENT3_SUPPORT */
   8766 
   8767 #ifdef BCM_KATANA2_SUPPORT
   8768     if (SOC_IS_KATANA2(unit)) {
   8769         BCM_IF_ERROR_RETURN(
   8770             bcm_kt2_cosq_safc_class_mapping_set(unit, port,  
   8771                                                array_count, mapping_array));
   8772     } else
   8773 #endif 
   8774 #ifdef BCM_MONTEREY_SUPPORT
   8775     if (SOC_IS_MONTEREY(unit)) {
   8776         BCM_IF_ERROR_RETURN(
   8777             _bcm_mn_cosq_safc_class_mapping_set(unit, port,
   8778                                                array_count, mapping_array)); 
   8779     } else
   8780 #endif /* BCM_MONTEREY_SUPPORT */
   8781 #ifdef BCM_APACHE_SUPPORT
   8782     if (SOC_IS_APACHE(unit)) {
   8783         BCM_IF_ERROR_RETURN(
   8784             _bcm_ap_cosq_safc_class_mapping_set(unit, port,
   8785                                                array_count, mapping_array));
   8786     } else
   8787 #endif 
   8788     {
   8789         return BCM_E_UNAVAIL;
   8790     }
   8791     return BCM_E_NONE;
   8792 }
   8793 
   8794 /*
   8795  * Function:
   8796  *     bcm_esw_cosq_safc_class_mapping_get
   8797  * Purpose:
   8798  *     Get SAFC mapping of a port.
   8799  *     Retrieves cosq or scheduler node
   8800  *     gports associated to SAFC classes.
   8801  * Parameters:
   8802  *     unit             - (IN) unit number
   8803  *     port             - (IN) port number
   8804  *     array_max        - (IN) max retrieve count
   8805  *     mapping_array    - (OUT) mappings
   8806  *     array_count      - (OUT) retrieved mapping count
   8807  * Returns:
   8808  *     BCM_E_XXX
   8809  */
   8810 int
   8811 bcm_esw_cosq_safc_class_mapping_get(
   8812     int unit,
   8813     bcm_gport_t port,
   8814     int array_max,
   8815     bcm_cosq_safc_class_mapping_t *mapping_array,
   8816     int *array_count)
   8817 {
   8818 #ifdef BCM_TOMAHAWK_SUPPORT
   8819     if (SOC_IS_TOMAHAWKX(unit)) {
   8820         BCM_IF_ERROR_RETURN(
   8821             bcm_th_cosq_safc_class_mapping_get(unit, port, array_max,
   8822                                                mapping_array, array_count));
   8823     } else
   8824 #endif /* BCM_TOMAHAWK_SUPPORT */
   8825 
   8826 #ifdef BCM_HELIX5_SUPPORT
   8827     if (SOC_IS_HELIX5(unit)) {
   8828         BCM_IF_ERROR_RETURN(
   8829             bcm_hx5_cosq_safc_class_mapping_get(unit, port, array_max,
   8830                                                 mapping_array, array_count));
   8831     } else
   8832 #endif /* BCM_TRIDENT3_SUPPORT */
   8833 
   8834 #ifdef BCM_TRIDENT3_SUPPORT
   8835     if (SOC_IS_TRIDENT3X(unit)) {
   8836         BCM_IF_ERROR_RETURN(
   8837             bcm_td3_cosq_safc_class_mapping_get(unit, port, array_max,
   8838                                                 mapping_array, array_count));
   8839     } else
   8840 #endif /* BCM_TRIDENT3_SUPPORT */
   8841 
   8842 #ifdef BCM_KATANA2_SUPPORT
   8843     if (SOC_IS_KATANA2(unit)) {
   8844         BCM_IF_ERROR_RETURN(
   8845             bcm_kt2_cosq_safc_class_mapping_get(unit, port, array_max, 
   8846                                                array_count, mapping_array ));
   8847     } else
   8848 #endif
   8849 #ifdef BCM_MONTEREY_SUPPORT
   8850     if (SOC_IS_MONTEREY(unit)) {
   8851         BCM_IF_ERROR_RETURN(
   8852             _bcm_mn_cosq_safc_class_mapping_get(unit, port, array_max,
   8853                                                mapping_array, array_count)); 
   8854     } else
   8855 #endif /* BCM_MONTEREY_SUPPORT */ 
   8856 #ifdef BCM_APACHE_SUPPORT
   8857     if (SOC_IS_APACHE(unit)) {
   8858         BCM_IF_ERROR_RETURN(
   8859             _bcm_ap_cosq_safc_class_mapping_get(unit, port, array_max,
   8860                                                mapping_array, array_count));
   8861     } else
   8862 #endif 
   8863     {
   8864         return BCM_E_UNAVAIL;
   8865     }
   8866     return BCM_E_NONE;
   8867 }
   8868 
   8869 /*
   8870  * Function:
   8871  *     bcm_esw_cosq_pfc_deadlock_config_set
   8872  * Purpose:
   8873  *     Setup PFC deadlock feature to monitor for the given priority with
   8874  *     associated values.
   8875  * Parameters:
   8876  *     unit             - (IN) unit number
   8877  *     priority         - (IN) priority
   8878  *     config           - (IN) Config for a given priority
   8879  * Returns:
   8880  *     BCM_E_XXX
   8881  */
   8882 int bcm_esw_cosq_pfc_deadlock_config_set(
   8883     int unit,
   8884     int priority,
   8885     bcm_cosq_pfc_deadlock_config_t *config)
   8886 {
   8887 
   8888 #ifdef BCM_TOMAHAWK3_SUPPORT
   8889     if(SOC_IS_TOMAHAWK3(unit)) {
   8890         return BCM_E_UNAVAIL;
   8891     }
   8892 #endif
   8893     if (soc_feature(unit, soc_feature_pfc_deadlock)) {
   8894         return _bcm_pfc_deadlock_config_set(unit, priority, config);
   8895     } else {
   8896         return BCM_E_UNAVAIL;
   8897     }
   8898 }
   8899 
   8900 /*
   8901  * Function:
   8902  *     bcm_esw_cosq_pfc_deadlock_config_get
   8903  * Purpose:
   8904  *     Get config values for a given priority in PFC deadlock feature.
   8905  * Parameters:
   8906  *     unit             - (IN) unit number
   8907  *     priority         - (IN) priority
   8908  *     config           - (OUT) Config for a given priority
   8909  * Returns:
   8910  *     BCM_E_XXX
   8911  */
   8912 int bcm_esw_cosq_pfc_deadlock_config_get(
   8913     int unit,
   8914     int priority,
   8915     bcm_cosq_pfc_deadlock_config_t *config)
   8916 {
   8917 
   8918 #ifdef BCM_TOMAHAWK3_SUPPORT
   8919     if(SOC_IS_TOMAHAWK3(unit)) {
   8920         return BCM_E_UNAVAIL;
   8921     }
   8922 #endif
   8923     if (soc_feature(unit, soc_feature_pfc_deadlock)) {
   8924         return _bcm_pfc_deadlock_config_get(unit, priority, config);
   8925     } else {
   8926         return BCM_E_UNAVAIL;
   8927     }
   8928 }
   8929 
   8930 /*
   8931  * Function:
   8932  *     bcm_esw_cosq_pfc_deadlock_info_get
   8933  * Purpose:
   8934  *     Get bitmap of Enabled(Admin) and Current Deadlock ports status for a
   8935  *     given priority in PFC deadlock feature.
   8936  * Parameters:
   8937  *     unit             - (IN) unit number
   8938  *     priority         - (IN) priority
   8939  *     info             - (OUT) Info for a given priority
   8940  * Returns:
   8941  *     BCM_E_XXX
   8942  */
   8943 int bcm_esw_cosq_pfc_deadlock_info_get(
   8944     int unit,
   8945     int priority,
   8946     bcm_cosq_pfc_deadlock_info_t *pfc_deadlock_info)
   8947 {
   8948     if (soc_feature(unit, soc_feature_pfc_deadlock)) {
   8949 #ifdef BCM_TOMAHAWK3_SUPPORT
   8950         if(SOC_IS_TOMAHAWK3(unit)) {
   8951           return _bcm_th3_pfc_deadlock_info_get(unit, priority, pfc_deadlock_info);
   8952         } else
   8953 #endif
   8954         {
   8955         return _bcm_pfc_deadlock_info_get(unit, priority, pfc_deadlock_info);
   8956         }
   8957     } else {
   8958         return BCM_E_UNAVAIL;
   8959     }
   8960 }
   8961 
   8962 /*
   8963  * Function:
   8964  *     bcm_esw_cosq_pfc_deadlock_queue_config_set
   8965  * Purpose:
   8966  *     Enable or disable the given Port/Queue for PFC deadlock feature to
   8967  *     monitor.
   8968  * Parameters:
   8969  *     unit             - (IN) unit number
   8970  *     priority         - (IN) priority
   8971  *     config           - (IN) Config for a given UC Queue Gport
   8972  * Returns:
   8973  *     BCM_E_XXX
   8974  */
   8975 
   8976 int bcm_esw_cosq_pfc_deadlock_queue_config_set(
   8977     int unit,
   8978     bcm_gport_t gport,
   8979     bcm_cosq_pfc_deadlock_queue_config_t *q_config)
   8980 {
   8981 
   8982 #ifdef BCM_TOMAHAWK3_SUPPORT
   8983     if(SOC_IS_TOMAHAWK3(unit)) {
   8984         return BCM_E_UNAVAIL;
   8985     }
   8986 #endif
   8987     if (soc_feature(unit, soc_feature_pfc_deadlock)) {
   8988         return _bcm_pfc_deadlock_queue_config_set(unit, gport, q_config);
   8989     } else {
   8990         return BCM_E_UNAVAIL;
   8991     }
   8992 }
   8993 
   8994 /*
   8995  * Function:
   8996  *     bcm_esw_cosq_pfc_deadlock_queue_config_get
   8997  * Purpose:
   8998  *     Get the Enable or disable monitoring status for the given Port/Queue.
   8999  * Parameters:
   9000  *     unit             - (IN) unit number
   9001  *     priority         - (IN) priority
   9002  *     config           - (OUT) Config for a given UC Queue Gport
   9003  * Returns:
   9004  *     BCM_E_XXX
   9005  */
   9006 int bcm_esw_cosq_pfc_deadlock_queue_config_get(
   9007     int unit,
   9008     bcm_gport_t gport,
   9009     bcm_cosq_pfc_deadlock_queue_config_t *q_config)
   9010 {
   9011 
   9012 #ifdef BCM_TOMAHAWK3_SUPPORT
   9013     if(SOC_IS_TOMAHAWK3(unit)) {
   9014         return BCM_E_UNAVAIL;
   9015     }
   9016 #endif
   9017     if (soc_feature(unit, soc_feature_pfc_deadlock)) {
   9018         return _bcm_pfc_deadlock_queue_config_get(unit, gport, q_config);
   9019     } else {
   9020         return BCM_E_UNAVAIL;
   9021     }
   9022 }
   9023 
   9024 /*
   9025  * Function:
   9026  *     bcm_esw_cosq_pfc_deadlock_queue_status_get
   9027  * Purpose:
   9028  *     Get the current Deadlock status for the given Port/Queue.
   9029  * Parameters:
   9030  *     unit             - (IN) unit number
   9031  *     priority         - (IN) priority
   9032  *     deadlock_status  - (OUT) Deatlock status for the given UC Queue Gport
   9033  * Returns:
   9034  *     BCM_E_XXX
   9035  */
   9036 int bcm_esw_cosq_pfc_deadlock_queue_status_get(
   9037     int unit,
   9038     bcm_gport_t gport,
   9039     uint8 *deadlock_status)
   9040 {
   9041     if (soc_feature(unit, soc_feature_pfc_deadlock)) {
   9042 #ifdef BCM_TOMAHAWK3_SUPPORT
   9043         if(SOC_IS_TOMAHAWK3(unit)) {
   9044             return _bcm_th3_pfc_deadlock_port_status_get
   9045                        (unit, gport, deadlock_status);
   9046         }
   9047 #endif
   9048         return _bcm_pfc_deadlock_queue_status_get(unit, gport, deadlock_status);
   9049     } else {
   9050         return BCM_E_UNAVAIL;
   9051     }
   9052 }
   9053 
   9054 /*
   9055  * Function:
   9056  *     bcmi_esw_cosq_handle_interrupt
   9057  * Purpose:
   9058  *     Internal interrupt event callback function to invoke registered callback
   9059  *     function (by bcm_esw_cosq_event_register).
   9060  * Parameters:
   9061  *     unit             - (IN) unit number
   9062  *     event            - (IN) event which trigger the interrupt.
   9063  *     port             - (IN) port which event happened. If the event is
   9064  *                             system wise or not port related, port = -1.
   9065  *     cosq             - (IN) cosq which event happened. If the event is
   9066  *                             system wise or not cosq related, cosq = -1.
   9067  * Returns:
   9068  *     BCM_E_XXX
   9069  */
   9070 int
   9071 bcmi_esw_cosq_handle_interrupt(int unit,
   9072                                bcm_cosq_event_type_t event,
   9073                                bcm_port_t port,
   9074                                bcm_cos_queue_t cosq)
   9075 {
   9076     cosq_event_handler_t *e_handler;
   9077     bcm_gport_t gport;
   9078     uint8 do_cb = 0, pbmp_valid, qbmp_valid, port_match, cosq_match;
   9079     int rv = BCM_E_NONE;
   9080 
   9081     COSQ_EVENT_LOCK(unit);
   9082     for (e_handler = cosq_event_handler_list[unit];
   9083          e_handler != NULL;
   9084          e_handler = e_handler->next) {
   9085         if (BCM_COSQ_EVENT_TYPE_GET(e_handler->event_types, event)){
   9086             pbmp_valid = 0;
   9087             qbmp_valid = 0;
   9088             port_match = 0;
   9089             cosq_match = 0;
   9090             if (port != -1) {
   9091                 pbmp_valid = !SHR_BITNULL_RANGE(e_handler->pbmp, 0,
   9092                                                 SOC_MAX_NUM_PORTS);
   9093                 port_match = SHR_BITGET(e_handler->pbmp, port) ? 1 : 0;
   9094             }
   9095             if (cosq != -1) {
   9096                 qbmp_valid = !SHR_BITNULL_RANGE(e_handler->qbmp, 0,
   9097                                                 BCM_COS_COUNT);
   9098                 cosq_match = SHR_BITGET(e_handler->qbmp, cosq) ? 1 : 0;
   9099             }
   9100 
   9101             if (port == -1) {
   9102                 gport = BCM_GPORT_INVALID;
   9103             } else {
   9104                 rv = bcm_esw_port_gport_get(unit, port, &gport);
   9105                 if (BCM_FAILURE (rv)) {
   9106                     COSQ_EVENT_UNLOCK(unit);
   9107                     return rv;
   9108                 }
   9109             }
   9110             if (pbmp_valid && qbmp_valid) {
   9111                 /* If pbmp and qbmp are specified, invoke cb
   9112                  * when port/cosq both matched */
   9113                 if (port_match && cosq_match) {
   9114                     do_cb = 1;
   9115                 }
   9116             } else if (pbmp_valid || qbmp_valid) {
   9117                 if (pbmp_valid && port_match) {
   9118                     do_cb = 1;
   9119                 }
   9120                 if (qbmp_valid && cosq_match) {
   9121                     do_cb = 1;
   9122                 }
   9123             } else {
   9124                 do_cb = 1;
   9125             }
   9126             if (do_cb){
   9127                 if (e_handler->cb != NULL) {
   9128                     e_handler->cb(unit, event, gport, cosq,
   9129                                   e_handler->user_data);
   9130                 }
   9131             }
   9132         }
   9133     }
   9134     COSQ_EVENT_UNLOCK(unit);
   9135     return BCM_E_NONE;
   9136 }
   9137 
   9138 STATIC int
   9139 bcmi_esw_cosq_event_mask_set(int unit, bcm_cosq_event_type_t event_type,
   9140                              int val)
   9141 {
   9142     /* Interrupt mask definitions are device specific. */
   9143 #ifdef BCM_GREYHOUND2_SUPPORT
   9144     if (SOC_IS_GREYHOUND2(unit)) {
   9145         return bcmi_gh2_cosq_event_mask_set(unit, event_type, val);
   9146     }
   9147 #endif
   9148     return BCM_E_UNAVAIL;
   9149 }
   9150 
   9151 STATIC int
   9152 bcmi_esw_cosq_events_validate(int unit, bcm_cosq_event_types_t event_types)
   9153 {
   9154     /* Event support validation(checking) is device specific.*/
   9155 #ifdef BCM_GREYHOUND2_SUPPORT
   9156     if (SOC_IS_GREYHOUND2(unit)) {
   9157         return bcmi_gh2_cosq_events_validate(unit, event_types);
   9158     }
   9159 #endif
   9160     return BCM_E_UNAVAIL;
   9161 }
   9162 
   9163 /*
   9164  * Function: 
   9165  *     bcm_esw_cosq_pfc_deadlock_callback_register
   9166  * Purpose:
   9167  *      Register pfc deadlock recovery callback in PFC deadlock feature.
   9168  * Parameters:
   9169  *     unit             - (IN) unit number
   9170  *     callback         - (IN) callback function
   9171  *     userdata         - (IN) user data
   9172  * Returns:
   9173  *     BCM_E_XXX
   9174  */
   9175 int bcm_esw_cosq_pfc_deadlock_recovery_event_register(
   9176     int unit, 
   9177     bcm_cosq_pfc_deadlock_recovery_event_cb_t callback, 
   9178     void *userdata)
   9179 {
   9180     if (soc_feature(unit, soc_feature_pfc_deadlock)) {
   9181         return _bcm_cosq_pfc_deadlock_recovery_event_register(unit, callback, userdata);
   9182     } else {
   9183         return BCM_E_UNAVAIL;
   9184     }
   9185 }
   9186 
   9187 /*
   9188  * Function:
   9189  *     bcm_esw_cosq_pfc_deadlock_recovery_start
   9190  * Purpose:
   9191  *     Start pfc deadlock recovery.
   9192  * Parameters:
   9193  *     unit             - (IN) unit number
   9194  *     port             - (IN) port number 
   9195  *     pri              - (IN) priority 
   9196  * Returns:
   9197  *     BCM_E_XXX
   9198  */
   9199 int
   9200 bcm_esw_cosq_pfc_deadlock_recovery_start(int unit, bcm_port_t port,
   9201                                          bcm_cos_t pri)
   9202 {
   9203 #ifdef BCM_TOMAHAWK3_SUPPORT
   9204     if (SOC_IS_TOMAHAWK3(unit)) {
   9205         if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
   9206             return bcm_th3_pfc_deadlock_recovery_start(unit, port, pri);
   9207         }
   9208     }
   9209 #endif
   9210 #ifdef BCM_TOMAHAWK_SUPPORT
   9211     if (SOC_IS_TOMAHAWKX(unit)) {
   9212         if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
   9213             return bcm_th_pfc_deadlock_recovery_start(unit, port, pri);
   9214         }
   9215     }
   9216 #endif
   9217 #ifdef BCM_HELIX5_SUPPORT
   9218     if (SOC_IS_HELIX5(unit)) {
   9219         if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
   9220             return bcm_hx5_pfc_deadlock_recovery_start(unit, port, pri);
   9221         }
   9222     }
   9223 #endif
   9224 #ifdef BCM_TRIDENT3_SUPPORT
   9225     if (SOC_IS_TRIDENT3X(unit)) {
   9226         if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
   9227             return bcm_td3_pfc_deadlock_recovery_start(unit, port, pri);
   9228         }
   9229     }
   9230 #endif
   9231     return BCM_E_UNAVAIL;
   9232 }
   9233 
   9234 /*
   9235  * Function:
   9236  *     bcm_esw_cosq_pfc_deadlock_recovery_exit
   9237  * Purpose:
   9238  *     Exit pfc deadlock recovery.
   9239  * Parameters:
   9240  *     unit             - (IN) unit number
   9241  *     port             - (IN) port number 
   9242  *     pri              - (IN) priority 
   9243  * Returns:
   9244  *     BCM_E_XXX
   9245  */
   9246 int
   9247 bcm_esw_cosq_pfc_deadlock_recovery_exit(int unit, bcm_port_t port,
   9248                                         bcm_cos_t pri)
   9249 {
   9250 #ifdef BCM_TOMAHAWK3_SUPPORT
   9251     if (SOC_IS_TOMAHAWK3(unit)) {
   9252         if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
   9253             return bcm_th3_pfc_deadlock_recovery_exit(unit, port, pri);
   9254         }
   9255     }
   9256 #endif
   9257 #ifdef BCM_TOMAHAWK_SUPPORT
   9258     if (SOC_IS_TOMAHAWKX(unit)) {
   9259         if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
   9260             return bcm_th_pfc_deadlock_recovery_exit(unit, port, pri);
   9261         }
   9262     }
   9263 #endif
   9264 #ifdef BCM_HELIX5_SUPPORT
   9265     if (SOC_IS_HELIX5(unit)) {
   9266         if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
   9267             return bcm_hx5_pfc_deadlock_recovery_exit(unit, port, pri);
   9268         }
   9269     }
   9270 #endif
   9271 #ifdef BCM_TRIDENT3_SUPPORT
   9272     if (SOC_IS_TRIDENT3X(unit)) {
   9273         if (soc_property_get(unit, spn_PFC_DEADLOCK_SEQ_CONTROL, 0)) {
   9274             return bcm_td3_pfc_deadlock_recovery_exit(unit, port, pri);
   9275         }
   9276     }
   9277 #endif
   9278     return BCM_E_UNAVAIL;
   9279 }
   9280 
   9281 /*
   9282  * Function:
   9283  *     bcm_esw_cosq_pfc_deadlock_callback_unregister
   9284  * Purpose:
   9285  *      Unregister pfc deadlock recovery callback in PFC deadlock feature.
   9286  * Parameters:
   9287  *     unit             - (IN) unit number
   9288  *     callback         - (IN) callback function
   9289  *     userdata         - (IN) user data
   9290  * Returns:
   9291  *     BCM_E_XXX
   9292  */
   9293 int bcm_esw_cosq_pfc_deadlock_recovery_event_unregister(
   9294     int unit, 
   9295     bcm_cosq_pfc_deadlock_recovery_event_cb_t callback, 
   9296     void *userdata)
   9297 {
   9298     if (soc_feature(unit, soc_feature_pfc_deadlock)) {
   9299         return _bcm_cosq_pfc_deadlock_recovery_event_unregister(unit, callback, userdata);
   9300     } else {
   9301         return BCM_E_UNAVAIL;
   9302     }
   9303 }
   9304 
   9305 /*
   9306  * Function:
   9307  *      bcm_esw_cosq_buffer_id_multi_get
   9308  * Purpose:
   9309  *      Get mutliple buffer ids associated with a specified port.
   9310  * Parameters:
   9311  *      unit - (IN) BCM device number.
   9312  *      gport - (IN) Port
   9313  *      cosq - (IN) Reserved field
   9314  *      direction - (IN) Specify ingress or egress direction
   9315  *      array_max - (IN) number of entries to be retrieved
   9316  *      buf_id_array - (OUT) Buffer id array
   9317  *      array_count - (OUT) Actural buffer id count in buf_id_array
   9318  * Returns:
   9319  *      BCM_E_XXX
   9320  */
   9321 int
   9322 bcm_esw_cosq_buffer_id_multi_get(int unit,
   9323                                  bcm_gport_t gport,
   9324                                  bcm_cos_queue_t cosq,
   9325                                  bcm_cosq_dir_t direction,
   9326                                  int array_max,
   9327                                  bcm_cosq_buffer_id_t *buf_id_array,
   9328                                  int *array_count)
   9329 {
   9330 #ifdef BCM_TOMAHAWK3_SUPPORT
   9331     if (SOC_IS_TOMAHAWK3(unit)) {
   9332         return bcm_th3_cosq_buffer_id_multi_get(unit, gport, cosq, direction,
   9333                                                array_max, buf_id_array, array_count);
   9334     }
   9335 #endif
   9336 #ifdef BCM_TOMAHAWK_SUPPORT
   9337     if (SOC_IS_TOMAHAWKX(unit)) {
   9338         return bcm_th_cosq_buffer_id_multi_get(unit, gport, 0, direction,
   9339                                                array_max, buf_id_array, array_count);
   9340     }
   9341 #endif
   9342 #ifdef BCM_HELIX5_SUPPORT
   9343     if (SOC_IS_HELIX5(unit)) {
   9344         return bcm_hx5_cosq_buffer_id_multi_get(unit, gport, 0, direction,
   9345                                                 array_max, buf_id_array, array_count);
   9346     } else
   9347 #endif
   9348 #ifdef BCM_TRIDENT3_SUPPORT
   9349     if (SOC_IS_TRIDENT3X(unit)) {
   9350         return bcm_td3_cosq_buffer_id_multi_get(unit, gport, 0, direction,
   9351                                                 array_max, buf_id_array, array_count);
   9352     }
   9353 #endif
   9354     return BCM_E_UNAVAIL;
   9355 }
   9356 
   9357 STATIC int
   9358 bcmi_esw_cosq_event_unregister_all(int unit)
   9359 {
   9360     cosq_event_handler_t *e_handler;
   9361     cosq_event_handler_t *e_handler_to_delete;
   9362 
   9363     COSQ_EVENT_LOCK(unit);
   9364     e_handler = cosq_event_handler_list[unit];
   9365     while (e_handler != NULL) {
   9366         e_handler_to_delete = e_handler;
   9367         e_handler = e_handler->next;
   9368         sal_free(e_handler_to_delete);
   9369     }
   9370     cosq_event_handler_list[unit] = NULL;
   9371     COSQ_EVENT_UNLOCK(unit);
   9372 
   9373     return BCM_E_NONE;
   9374 }
   9375 
   9376 STATIC int
   9377 bcmi_esw_cosq_event_deinit(int unit)
   9378 {
   9379 
   9380     if (cosq_event_handler_list[unit] != NULL) {
   9381         bcmi_esw_cosq_event_unregister_all(unit);
   9382     }
   9383     sal_memset(&cosq_event_handler_count[unit], 0,
   9384                sizeof(int) * bcmCosqEventCount);
   9385 
   9386     if (cosq_event_lock[unit] != NULL) {
   9387         sal_mutex_destroy(cosq_event_lock[unit]);
   9388         cosq_event_lock[unit] = NULL;
   9389     }
   9390     return BCM_E_NONE;
   9391 }
   9392 
   9393 
   9394 STATIC int
   9395 bcmi_esw_cosq_event_init(int unit)
   9396 {
   9397     int i;
   9398     if (cosq_event_initialized == 0) {
   9399         for (i = 0; i < SOC_MAX_NUM_DEVICES; i ++) {
   9400             cosq_event_lock[i] = NULL;
   9401             cosq_event_handler_list[i] = NULL;
   9402             sal_memset(&cosq_event_handler_count[i], 0,
   9403                        sizeof(int) * bcmCosqEventCount);
   9404         }
   9405         cosq_event_initialized = 1;
   9406     } else {
   9407         BCM_IF_ERROR_RETURN(bcmi_esw_cosq_event_deinit(unit));
   9408     }
   9409     if (cosq_event_lock[unit] == NULL) {
   9410         cosq_event_lock[unit] = sal_mutex_create("cosq event lock");
   9411         if (cosq_event_lock[unit] == NULL) {
   9412             return BCM_E_MEMORY;
   9413         }
   9414     }
   9415     return BCM_E_NONE;
   9416 }
   9417 
   9418 /*
   9419  * Function:
   9420  *     bcm_esw_cosq_event_register
   9421  * Purpose:
   9422  *     The callback function registration by specifying port or traffic class to
   9423  *     handle the COSQ events.
   9424  * Parameters:
   9425  *     unit             - (IN) unit number
   9426  *     event_types      - (IN) The set of Cosq events for which the specified
   9427  *                             callback should be invoked.
   9428  *     port             - (IN) gport id
   9429  *     cosq             - (IN) cos queue
   9430  *     cb               - (IN) callback function
   9431  *     user_data        - (IN) Pinter to user data to supply in the callback.
   9432  * Returns:
   9433  *     BCM_E_XXX
   9434  * Notes:
   9435  *     If the event is not on port or traffic class basis, the gport and cosq
   9436  *     value should be -1.
   9437  *     If user do not want to register the event on specific port or queue basis,
   9438  *     The gport or cosq value should assign to -1.
   9439  */
   9440 int
   9441 bcm_esw_cosq_event_register(
   9442     int unit,
   9443     bcm_cosq_event_types_t event_types,
   9444     bcm_gport_t port,
   9445     bcm_cos_queue_t cosq,
   9446     bcm_cosq_event_cb cb,
   9447     void *user_data)
   9448 {
   9449     cosq_event_handler_t *e_handler;
   9450     cosq_event_handler_t *previous = NULL;
   9451     bcm_cosq_event_type_t e_type;
   9452     int result;
   9453     int rv = BCM_E_NONE;
   9454     bcm_port_t lport;
   9455 
   9456     if (cb == NULL) {
   9457         return BCM_E_PARAM;
   9458     }
   9459 
   9460     SHR_BITTEST_RANGE(event_types.w, 0, bcmCosqEventCount, result);
   9461     if (result == 0) {
   9462         return BCM_E_PARAM;
   9463     }
   9464     BCM_IF_ERROR_RETURN(bcmi_esw_cosq_events_validate(unit, event_types));
   9465 
   9466     if (port != BCM_GPORT_INVALID) {
   9467         BCM_IF_ERROR_RETURN(
   9468             _bcm_esw_port_gport_validate(unit, port, &lport));
   9469     }
   9470 
   9471     BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, NUM_COS(unit)));
   9472 
   9473     COSQ_EVENT_LOCK(unit);
   9474     for (e_handler = cosq_event_handler_list[unit];
   9475          e_handler != NULL;
   9476          e_handler = e_handler->next) {
   9477         if (e_handler->cb == cb) {
   9478             break;
   9479         }
   9480         previous = e_handler;
   9481     }
   9482 
   9483     if (e_handler == NULL) {
   9484         /* This handler hasn't been registered yet */
   9485         e_handler = sal_alloc(sizeof(*e_handler), "Cosq event handler");
   9486         if (e_handler == NULL) {
   9487             COSQ_EVENT_UNLOCK(unit);
   9488             return BCM_E_MEMORY;
   9489         }
   9490         sal_memset(e_handler, 0, sizeof(*e_handler));
   9491 
   9492         e_handler->next = NULL;
   9493         e_handler->cb = cb;
   9494 
   9495         if (previous != NULL) {
   9496             previous->next = e_handler;
   9497         } else {
   9498             cosq_event_handler_list[unit] = e_handler;
   9499         }
   9500     }
   9501 
   9502     for (e_type = 0; e_type < bcmCosqEventCount; ++e_type) {
   9503         if (BCM_COSQ_EVENT_TYPE_GET(event_types, e_type)) {
   9504             if (!BCM_COSQ_EVENT_TYPE_GET(e_handler->event_types, e_type)) {
   9505                 /* This handler isn't handling this event yet */
   9506                 BCM_COSQ_EVENT_TYPE_SET(e_handler->event_types, e_type);
   9507                 if (cosq_event_handler_count[unit][e_type] == 0) {
   9508                     rv = bcmi_esw_cosq_event_mask_set(unit, e_type, 1);
   9509                     if (BCM_FAILURE(rv)) {
   9510                         COSQ_EVENT_UNLOCK(unit);
   9511                         return rv;
   9512                     }
   9513                 }
   9514                 cosq_event_handler_count[unit][e_type] += 1;
   9515             }
   9516         }
   9517     }
   9518 
   9519     e_handler->user_data = user_data;
   9520     if (port != BCM_GPORT_INVALID) {
   9521         SHR_BITSET(e_handler->pbmp, lport);
   9522     } else {
   9523         /* clear bitmap */
   9524         SHR_BITCLR_RANGE(e_handler->pbmp, 0, SOC_MAX_NUM_PORTS);
   9525     }
   9526     if (cosq != BCM_COS_INVALID) {
   9527         SHR_BITSET(e_handler->qbmp, cosq);
   9528     } else {
   9529         /* clear bitmap */
   9530         SHR_BITCLR_RANGE(e_handler->qbmp, 0, BCM_COS_COUNT);
   9531     }
   9532     COSQ_EVENT_UNLOCK(unit);
   9533     return rv;
   9534 }
   9535 
   9536 /*
   9537  * Function:
   9538  *     bcm_esw_cosq_event_unregister
   9539  * Purpose:
   9540  *     The callback function unregistration of COSQ events by specifying port or
   9541  *     traffic class.
   9542  * Parameters:
   9543  *     unit             - (IN) unit number
   9544  *     event_types      - (IN) The set of Cosq events for which the specified
   9545  *                             callback should be invoked.
   9546  *     port             - (IN) gport id
   9547  *     cosq             - (IN) cos queue
   9548  *     cb               - (IN) callback function
   9549  * Returns:
   9550  *     BCM_E_XXX
   9551  */
   9552 int
   9553 bcm_esw_cosq_event_unregister(
   9554     int unit,
   9555     bcm_cosq_event_types_t event_types,
   9556     bcm_gport_t port,
   9557     bcm_cos_queue_t cosq,
   9558     bcm_cosq_event_cb cb)
   9559 {
   9560     cosq_event_handler_t *e_handler;
   9561     cosq_event_handler_t *previous = NULL;
   9562     bcm_cosq_event_type_t e_type;
   9563     int result;
   9564     int rv = BCM_E_NONE;
   9565     bcm_port_t  lport;
   9566     uint8 pbmp_valid = 0, qbmp_valid = 0;
   9567 
   9568     if (cb == NULL) {
   9569         return BCM_E_PARAM;
   9570     }
   9571 
   9572     SHR_BITTEST_RANGE(event_types.w, 0, bcmCosqEventCount, result);
   9573     if (result == 0) {
   9574         return BCM_E_PARAM;
   9575     }
   9576     if (port != BCM_GPORT_INVALID) {
   9577         BCM_IF_ERROR_RETURN(
   9578             _bcm_esw_port_gport_validate(unit, port, &lport));
   9579     }
   9580 
   9581     BCM_IF_ERROR_RETURN(_bcm_esw_cosq_num_validate(cosq, NUM_COS(unit)));
   9582 
   9583     COSQ_EVENT_LOCK(unit);
   9584     for (e_handler = cosq_event_handler_list[unit];
   9585          e_handler != NULL;
   9586          e_handler = e_handler->next) {
   9587         /* Find the e_handler by specified cb */
   9588         if (e_handler->cb == cb) {
   9589             break;
   9590         }
   9591         previous = e_handler;
   9592     }
   9593 
   9594     if (e_handler == NULL) {
   9595         /* Could not find the registed e_handler */
   9596         COSQ_EVENT_UNLOCK(unit);
   9597         return BCM_E_NOT_FOUND;
   9598     }
   9599 
   9600     for (e_type = 0; e_type < bcmCosqEventCount; ++e_type) {
   9601         if (BCM_COSQ_EVENT_TYPE_GET(event_types, e_type)) {
   9602             /* Iterate the specified events  */
   9603             if ((BCM_COSQ_EVENT_TYPE_GET(e_handler->event_types, e_type)) &&
   9604                 (cosq_event_handler_count[unit][e_type] > 0)) {
   9605                 /* Check if the event was among the registered events. */
   9606                 cosq_event_handler_count[unit][e_type] -= 1;
   9607                 BCM_COSQ_EVENT_TYPE_CLEAR(e_handler->event_types, e_type);
   9608                 /* Clear event mask when event is not associated with others.*/
   9609                 if (cosq_event_handler_count[unit][e_type] == 0) {
   9610                     rv = bcmi_esw_cosq_event_mask_set(unit, e_type, 0);
   9611                     if (BCM_FAILURE(rv)) {
   9612                         COSQ_EVENT_UNLOCK(unit);
   9613                         return rv;
   9614                     }
   9615                 }
   9616             }
   9617         }
   9618     }
   9619 
   9620     SHR_BITTEST_RANGE(e_handler->event_types.w, 0, bcmCosqEventCount, result);
   9621 
   9622     if (0 == result) {
   9623         /* Free the handler if no more events for this handler to handle */
   9624         if (previous != NULL) {
   9625             previous->next = e_handler->next;
   9626         } else {
   9627             cosq_event_handler_list[unit] = e_handler->next;
   9628         }
   9629         sal_free(e_handler);
   9630     } else {
   9631         pbmp_valid = !SHR_BITNULL_RANGE(e_handler->pbmp, 0,
   9632                                         SOC_MAX_NUM_PORTS);
   9633         /* Ignore events associated with certain port */
   9634         if (port != BCM_GPORT_INVALID) {
   9635             if (!pbmp_valid) {
   9636                 /* The orginal registered to ignore port case.
   9637                    set bitmaps to 1 */
   9638                 SHR_BITSET_RANGE(e_handler->pbmp, 0, SOC_MAX_NUM_PORTS);
   9639             }
   9640             SHR_BITCLR(e_handler->pbmp, lport);
   9641         }
   9642 
   9643         qbmp_valid = !SHR_BITNULL_RANGE(e_handler->qbmp, 0,
   9644                                         BCM_COS_COUNT);
   9645         /* Ignore events associated with certian cosq */
   9646         if (cosq != BCM_COS_INVALID) {
   9647             if (!qbmp_valid) {
   9648                 /* The orginal registered to ignore cosq case.
   9649                    set bitmaps to 1 */
   9650                 SHR_BITSET_RANGE(e_handler->qbmp, 0, BCM_COS_COUNT);
   9651             }
   9652             SHR_BITCLR(e_handler->qbmp, cosq);
   9653         }
   9654     }
   9655     COSQ_EVENT_UNLOCK(unit);
   9656     return BCM_E_NONE;
   9657 }
   9658 
   9659 /*
   9660  * Function:
   9661  *     bcm_esw_cosq_tas_control_get
   9662  * Purpose:
   9663  *     Get various configurations for TAS.
   9664  * Parameters:
   9665  *     unit             - (IN) unit number
   9666  *     port             - (IN) gport id
   9667  *     type             - (IN) tas control type defined in bcm_cos_tas_control_t
   9668  *     arg              - (OUT) tas control value
   9669  * Returns:
   9670  *     BCM_E_XXX
   9671  * Notes:
   9672  *     Most of the TAS configurations are on port basis. For some configuration
   9673  *     which is on system basis, the gport should assign to -1.
   9674  */
   9675 int
   9676 bcm_esw_cosq_tas_control_get(
   9677     int unit,
   9678     bcm_gport_t port,
   9679     bcm_cosq_tas_control_t type,
   9680     int *arg)
   9681 {
   9682 #ifdef BCM_TAS_SUPPORT
   9683     if (soc_feature(unit, soc_feature_tas)) {
   9684         return bcmi_esw_tas_control_get(unit, port, type, arg);
   9685     }
   9686 #endif
   9687     return BCM_E_UNAVAIL;
   9688 }
   9689 
   9690 /*
   9691  * Function:
   9692  *     bcm_esw_cosq_tas_control_set
   9693  * Purpose:
   9694  *     Set various configurations for TAS.
   9695  * Parameters:
   9696  *     unit             - (IN) unit number
   9697  *     port             - (IN) gport id
   9698  *     type             - (IN) tas control type defined in bcm_cos_tas_control_t
   9699  *     arg              - (IN) tas control value
   9700  * Returns:
   9701  *     BCM_E_XXX
   9702  * Notes:
   9703  *     Most of the TAS configurations are on port basis. For some configuration
   9704  *     which is on system basis, the gport should assign to -1.
   9705  */
   9706 int
   9707 bcm_esw_cosq_tas_control_set(
   9708     int unit,
   9709     bcm_gport_t port,
   9710     bcm_cosq_tas_control_t type,
   9711     int arg)
   9712 {
   9713 #ifdef BCM_TAS_SUPPORT
   9714     if (soc_feature(unit, soc_feature_tas)) {
   9715         return bcmi_esw_tas_control_set(unit, port, type, arg);
   9716     }
   9717 #endif
   9718     return BCM_E_UNAVAIL;
   9719 }
   9720 
   9721 /*
   9722  * Function:
   9723  *     bcm_esw_cosq_tas_status_get
   9724  * Purpose:
   9725  *     Get TAS status by specifying the type.
   9726  * Parameters:
   9727  *     unit             - (IN) unit number
   9728  *     port             - (IN) gport id
   9729  *     type             - (IN) tas status type defined in bcm_cos_tas_status_t
   9730  *     arg              - (OUT) tas status value
   9731  * Returns:
   9732  *     BCM_E_XXX
   9733  */
   9734 int
   9735 bcm_esw_cosq_tas_status_get(
   9736     int unit,
   9737     bcm_gport_t port,
   9738     bcm_cosq_tas_status_t type,
   9739     int *arg)
   9740 {
   9741 #ifdef BCM_TAS_SUPPORT
   9742     if (soc_feature(unit, soc_feature_tas)) {
   9743         return bcmi_esw_tas_status_get(unit, port, type, arg);
   9744     }
   9745 #endif
   9746     return BCM_E_UNAVAIL;
   9747 }
   9748 
   9749 /*
   9750  * Function:
   9751  *     bcm_esw_cosq_tas_profile_commit
   9752  * Purpose:
   9753  *     Commit the profile to indicate the profile is ready to write to hardware.
   9754  * Parameters:
   9755  *     unit             - (IN) unit number
   9756  *     port             - (IN) gport id
   9757  *     pid              - (IN) profile id
   9758  * Returns:
   9759  *     BCM_E_XXX
   9760  */
   9761 int
   9762 bcm_esw_cosq_tas_profile_commit(
   9763     int unit,
   9764     bcm_gport_t port,
   9765     bcm_cosq_tas_profile_id_t pid)
   9766 {
   9767 #ifdef BCM_TAS_SUPPORT
   9768     if (soc_feature(unit, soc_feature_tas)) {
   9769         return bcmi_esw_tas_profile_commit(unit, port, pid);
   9770     }
   9771 #endif
   9772     return BCM_E_UNAVAIL;
   9773 }
   9774 
   9775 /*
   9776  * Function:
   9777  *     bcm_esw_cosq_tas_profile_create
   9778  * Purpose:
   9779  *     Create a profile by specifying the profile settings including calendar
   9780  *     table, ptp time information for PTP mode.
   9781  *     A profile id will be assigned along with the settings.
   9782  * Parameters:
   9783  *     unit             - (IN) unit number
   9784  *     port             - (IN) gport id
   9785  *     profile          - (IN) Pointer to profile structure which specifies
   9786  *                             entries in calendar table, ptp time information
   9787  *                             for PTP mode
   9788  *     pid              - (OUT) profile id
   9789  * Returns:
   9790  *     BCM_E_XXX
   9791  */
   9792 int
   9793 bcm_esw_cosq_tas_profile_create(
   9794     int unit,
   9795     bcm_gport_t port,
   9796     bcm_cosq_tas_profile_t *profile,
   9797     bcm_cosq_tas_profile_id_t *pid)
   9798 {
   9799 #ifdef BCM_TAS_SUPPORT
   9800     if (soc_feature(unit, soc_feature_tas)) {
   9801         return bcmi_esw_tas_profile_create(unit, port, profile, pid);
   9802     }
   9803 #endif
   9804     return BCM_E_UNAVAIL;
   9805 }
   9806 
   9807 /*
   9808  * Function:
   9809  *     bcm_esw_cosq_tas_profile_get
   9810  * Purpose:
   9811  *     Get the profile information by specifying the profile id.
   9812  * Parameters:
   9813  *     unit             - (IN) unit number
   9814  *     port             - (IN) gport id
   9815  *     pid              - (IN) profile id
   9816  *     profile          - (OUT) pointer to profile structure
   9817  * Returns:
   9818  *     BCM_E_XXX
   9819  */
   9820 int
   9821 bcm_esw_cosq_tas_profile_get(
   9822     int unit,
   9823     bcm_gport_t port,
   9824     bcm_cosq_tas_profile_id_t pid,
   9825     bcm_cosq_tas_profile_t *profile)
   9826 {
   9827 #ifdef BCM_TAS_SUPPORT
   9828     if (soc_feature(unit, soc_feature_tas)) {
   9829         return bcmi_esw_tas_profile_get(unit, port, pid, profile);
   9830     }
   9831 #endif
   9832     return BCM_E_UNAVAIL;
   9833 }
   9834 
   9835 /*
   9836  * Function:
   9837  *     bcm_esw_cosq_tas_profile_set
   9838  * Purpose:
   9839  *     Modify the profile information
   9840  * NOTE:
   9841  *     This API is used to modify the profile if needed before doing commit.
   9842  * Parameters:
   9843  *     unit             - (IN) unit number
   9844  *     port             - (IN) gport id
   9845  *     pid              - (IN) profile id
   9846  *     profile          - (IN) pointer to profile structure
   9847  * Returns:
   9848  *     BCM_E_XXX
   9849  */
   9850 int
   9851 bcm_esw_cosq_tas_profile_set(
   9852     int unit,
   9853     bcm_gport_t port,
   9854     bcm_cosq_tas_profile_id_t pid,
   9855     bcm_cosq_tas_profile_t *profile)
   9856 {
   9857 #ifdef BCM_TAS_SUPPORT
   9858     if (soc_feature(unit, soc_feature_tas)) {
   9859         return bcmi_esw_tas_profile_set(unit, port, pid, profile);
   9860     }
   9861 #endif
   9862     return BCM_E_UNAVAIL;
   9863 }
   9864 
   9865 /*
   9866  * Function:
   9867  *     bcm_esw_cosq_tas_profile_traverse
   9868  * Purpose:
   9869  *     Traverse the set of profiles associated with the specified port.
   9870  * Parameters:
   9871  *     unit             - (IN) unit number
   9872  *     port             - (IN) gport id
   9873  *     cb               - (IN) A pointer to callback function to call
   9874  *                             for each profile in the specified gport.
   9875  *     user_data        - (IN) Pointer to user data to supply in the callback
   9876  * Returns:
   9877  *     BCM_E_XXX
   9878  */
   9879 int
   9880 bcm_esw_cosq_tas_profile_traverse(
   9881     int unit,
   9882     bcm_gport_t port,
   9883     bcm_cosq_tas_profile_traverse_cb cb,
   9884     void *user_data)
   9885 {
   9886 #ifdef BCM_TAS_SUPPORT
   9887     if (soc_feature(unit, soc_feature_tas)) {
   9888         return bcmi_esw_tas_profile_traverse(unit, port, cb, user_data);
   9889     }
   9890 #endif
   9891     return BCM_E_UNAVAIL;
   9892 }
   9893 
   9894 
   9895 /*
   9896  * Function:
   9897  *     bcm_esw_cosq_tas_profile_destroy
   9898  * Purpose:
   9899  *     Destroy the profile and associated resources.
   9900  * Parameters:
   9901  *     unit             - (IN) unit number
   9902  *     port             - (IN) gport id
   9903  *     pid              - (IN) profile id
   9904  * Returns:
   9905  *     BCM_E_XXX
   9906  */
   9907 int
   9908 bcm_esw_cosq_tas_profile_destroy(
   9909     int unit,
   9910     bcm_gport_t port,
   9911     bcm_cosq_tas_profile_id_t pid)
   9912 {
   9913 #ifdef BCM_TAS_SUPPORT
   9914     if (soc_feature(unit, soc_feature_tas)) {
   9915         return bcmi_esw_tas_profile_destroy(unit, port, pid);
   9916     }
   9917 #endif
   9918     return BCM_E_UNAVAIL;
   9919 }
   9920 
   9921 /*
   9922  * Function:
   9923  *     bcm_esw_cosq_tas_profile_destroy_all
   9924  * Purpose:
   9925  *     Destroy all the profile associated with the port.
   9926  * Parameters:
   9927  *     unit             - (IN) unit number
   9928  *     port             - (IN) gport id
   9929  * Returns:
   9930  *     BCM_E_XXX
   9931  */
   9932 int
   9933 bcm_esw_cosq_tas_profile_destroy_all(
   9934     int unit,
   9935     bcm_gport_t port)
   9936 {
   9937 #ifdef BCM_TAS_SUPPORT
   9938     if (soc_feature(unit, soc_feature_tas)) {
   9939         return bcmi_esw_tas_profile_destroy_all(unit, port);
   9940     }
   9941 #endif
   9942     return BCM_E_UNAVAIL;
   9943 }
   9944 
   9945 /*
   9946  * Function:
   9947  *     bcm_esw_cosq_tas_profile_status_get
   9948  * Purpose:
   9949  *     Get the profile status like profile state, config change time and
   9950  *     entries in the hardware calendar table.
   9951  * Parameters:
   9952  *     unit             - (IN) unit number
   9953  *     port             - (IN) gport id
   9954  *     pid              - (IN) profile id
   9955  *     status           - (OUT) pointer to profile status structure
   9956  * Returns:
   9957  *     BCM_E_XXX
   9958  */
   9959 int
   9960 bcm_esw_cosq_tas_profile_status_get(
   9961     int unit,
   9962     bcm_gport_t port,
   9963     bcm_cosq_tas_profile_id_t pid,
   9964     bcm_cosq_tas_profile_status_t *status)
   9965 {
   9966 #ifdef BCM_TAS_SUPPORT
   9967     if (soc_feature(unit, soc_feature_tas)) {
   9968         return bcmi_esw_tas_profile_status_get(unit, port, pid, status);
   9969     }
   9970 #endif
   9971     return BCM_E_UNAVAIL;
   9972 }
   9973 
   9974 #if defined(INCLUDE_TCB)
   9975 
   9976 #if defined (BCM_TCB_SUPPORT)
   9977 _bcm_cosq_tcb_unit_ctrl_t  *_bcm_cosq_tcb_unit_control[BCM_MAX_NUM_UNITS];
   9978 #endif
   9979 
   9980 /*
   9981  * Function:
   9982  *      bcm_esw_cosq_tcb_config_set
   9983  * Purpose:
   9984  *      Set TCB instance config attributes.
   9985  * Parameters:
   9986  *      unit - (IN) BCM device number.
   9987  *      buffer_id - (IN) TCB buffer id.
   9988  *      config - (IN) TCB config information
   9989  * Returns:
   9990  *      BCM_E_XXX
   9991  */
   9992 int
   9993 bcm_esw_cosq_tcb_config_set(int unit,
   9994                             bcm_cosq_buffer_id_t buffer_id,
   9995                             bcm_cosq_tcb_config_t *config)
   9996 {
   9997 #ifdef BCM_TCB_SUPPORT
   9998     int rv = BCM_E_NONE;
   9999     if (soc_feature(unit, soc_feature_tcb)) {
  10000         TCB_INIT(unit);
  10001         TCB_LOCK(unit);
  10002 
  10003 #ifdef BCM_TOMAHAWK2_SUPPORT
  10004         if (SOC_IS_TOMAHAWK2(unit)) {
  10005         rv = bcm_th2_cosq_tcb_config_set(unit, buffer_id, config);
  10006         }
  10007 #endif
  10008 
  10009 #ifdef BCM_HELIX5_SUPPORT
  10010        if (SOC_IS_HELIX5(unit)) {
  10011            rv = bcm_hx5_cosq_tcb_config_set(unit, buffer_id, config);
  10012        } 
  10013 #endif /* BCM_HELIX5_SUPPORT */
  10014 
  10015 #ifdef BCM_TRIDENT3_SUPPORT
  10016         if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
  10017             rv = bcm_td3_cosq_tcb_config_set(unit, buffer_id, config);
  10018         }
  10019 #endif
  10020 
  10021         TCB_UNLOCK(unit);
  10022         return rv;
  10023     }
  10024 #endif
  10025     return BCM_E_UNAVAIL;
  10026 }
  10027 
  10028 /*
  10029  * Function:
  10030  *      bcm_esw_cosq_tcb_config_get
  10031  * Purpose:
  10032  *      Get TCB instance control status.
  10033  * Parameters:
  10034  *      unit - (IN) BCM device number.
  10035  *      buffer_id - (IN) TCB buffer id.
  10036  *      config - (OUT) TCB config information
  10037  * Returns:
  10038  *      BCM_E_XXX
  10039  */
  10040 int
  10041 bcm_esw_cosq_tcb_config_get(int unit,
  10042                             bcm_cosq_buffer_id_t buffer_id,
  10043                             bcm_cosq_tcb_config_t *config)
  10044 {
  10045 #ifdef BCM_TCB_SUPPORT
  10046     int rv = BCM_E_NONE;
  10047     if (soc_feature(unit, soc_feature_tcb)) {
  10048         TCB_INIT(unit);
  10049         TCB_LOCK(unit);
  10050 #ifdef BCM_TOMAHAWK2_SUPPORT
  10051         if (SOC_IS_TOMAHAWK2(unit)) {
  10052         rv = bcm_th2_cosq_tcb_config_get(unit, buffer_id, config);
  10053         }
  10054 #endif
  10055 
  10056 #ifdef BCM_HELIX5_SUPPORT
  10057         if (SOC_IS_HELIX5(unit)) {
  10058             rv = bcm_hx5_cosq_tcb_config_get(unit, buffer_id, config);
  10059         } 
  10060 #endif /* BCM_HELIX5_SUPPORT */
  10061 
  10062 #ifdef BCM_TRIDENT3_SUPPORT
  10063         if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
  10064                rv = bcm_td3_cosq_tcb_config_get(unit, buffer_id, config);
  10065         }
  10066 #endif
  10067         TCB_UNLOCK(unit);
  10068         return rv;
  10069     }
  10070 #endif
  10071     return BCM_E_UNAVAIL;
  10072 }
  10073 
  10074 /*
  10075  * Function:
  10076  *      bcm_esw_cosq_tcb_gport_threshold_mapping_set
  10077  * Purpose:
  10078  *      Set threshold profile for a UCQ or a port.
  10079  * Parameters:
  10080  *      unit  - (IN) unit number
  10081  *      id    - (IN) Integrated cosq index
  10082  *      index - (IN) Threshold profile index
  10083  * Returns:
  10084  *      BCM_E_XXX
  10085  * Notes:
  10086  *      When gport is a port, SDK will attach all Ucqs in this port to one threshold profile.
  10087  */
  10088 int
  10089 bcm_esw_cosq_tcb_gport_threshold_mapping_set(int unit,
  10090                                              bcm_cosq_object_id_t *id,
  10091                                              int index)
  10092 {
  10093 #ifdef BCM_TCB_SUPPORT
  10094     int rv = BCM_E_NONE;
  10095     if (soc_feature(unit, soc_feature_tcb)) {
  10096         TCB_INIT(unit);
  10097         TCB_LOCK(unit);
  10098 #ifdef BCM_TOMAHAWK2_SUPPORT
  10099         if (SOC_IS_TOMAHAWK2(unit)) {
  10100         rv = bcm_th2_cosq_tcb_gport_threshold_mapping_set(unit, 
  10101             id->port, id->cosq, id->buffer, index);
  10102         }
  10103 #endif
  10104 #ifdef BCM_HELIX5_SUPPORT
  10105         if (SOC_IS_HELIX5(unit)) {
  10106             rv = bcm_hx5_cosq_tcb_gport_threshold_mapping_set(unit,
  10107                     id->port, id->cosq, id->buffer, index);
  10108         }
  10109 #endif /* BCM_HELIX5_SUPPORT */
  10110 #ifdef BCM_TRIDENT3_SUPPORT
  10111         if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
  10112                 rv = bcm_td3_cosq_tcb_gport_threshold_mapping_set(unit,
  10113                      id->port, id->cosq, id->buffer, index);
  10114         }
  10115 #endif
  10116         TCB_UNLOCK(unit);
  10117         return rv;
  10118     }
  10119 #endif
  10120     return BCM_E_UNAVAIL;
  10121 }
  10122 
  10123 /*
  10124  * Function:
  10125  *      bcm_esw_cosq_tcb_gport_threshold_mapping_get
  10126  * Purpose:
  10127  *      Set threshold profile for a UCQ or a port.
  10128  * Parameters:
  10129  *      unit  - (IN) unit number
  10130  *      id    - (IN) Integrated cosq index
  10131  *      index - (OUT) Threshold profile index
  10132  * Returns:
  10133  *      BCM_E_XXX
  10134  * Notes:
  10135  *      When gport is a port, SDK will return the threshold profile index of the first Ucq in this
  10136  *      port.
  10137  */
  10138 int
  10139 bcm_esw_cosq_tcb_gport_threshold_mapping_get(int unit,
  10140                                              bcm_cosq_object_id_t *id,
  10141                                              int *index)
  10142 {
  10143 #ifdef BCM_TCB_SUPPORT
  10144     int rv = BCM_E_NONE;
  10145     if (soc_feature(unit, soc_feature_tcb)) {
  10146         TCB_INIT(unit);
  10147         TCB_LOCK(unit);
  10148 #ifdef BCM_TOMAHAWK2_SUPPORT
  10149         if (SOC_IS_TOMAHAWK2(unit)) {
  10150         rv =  bcm_th2_cosq_tcb_gport_threshold_mapping_get(unit, 
  10151             id->port, id->cosq, id->buffer, index);
  10152         }
  10153 #endif
  10154 
  10155 #ifdef BCM_HELIX5_SUPPORT
  10156         if (SOC_IS_HELIX5(unit)) {
  10157             rv = bcm_hx5_cosq_tcb_gport_threshold_mapping_get(unit,
  10158                     id->port, id->cosq, id->buffer, index);
  10159         } 
  10160 #endif /* BCM_HELIX5_SUPPORT */
  10161 #ifdef BCM_TRIDENT3_SUPPORT
  10162         if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
  10163                 rv = bcm_td3_cosq_tcb_gport_threshold_mapping_get(unit,
  10164                      id->port, id->cosq, id->buffer, index);
  10165         }
  10166 #endif
  10167         TCB_UNLOCK(unit);
  10168         return rv;
  10169     }
  10170 #endif
  10171     return BCM_E_UNAVAIL;
  10172 }
  10173 
  10174 /*
  10175  * Function:
  10176  *      bcm_esw_cosq_tcb_threshold_profile_create
  10177  * Purpose:
  10178  *      Create a threshold profile for a specified TCB buffer.
  10179  * Parameters:
  10180  *      unit - (IN) BCM device number.
  10181  *      flags - (IN) BCM_COSQ_TCB_THRESHOLD_PROFILE_WITH_ID: Index arg is given
  10182  *                       BCM_COSQ_TCB_THRESHOLD_PROFILE_REPLACE: Replace existing profile
  10183  *      buffer_id - (IN) TCB buffer id.
  10184  *      threshold - (IN) Threshold profile
  10185  *      index - (INOUT) profile index
  10186  * Returns:
  10187  *      BCM_E_XXX
  10188  * Notes:
  10189  *      If user do not specify index, SDK will alloc a profile index and return to user.
  10190  *      With BCM_COSQ_TCB_THRESHOLD_PROFILE_REPLACE flag user could directly update a
  10191  *      existing threshold profile to new values.
  10192  */
  10193 int
  10194 bcm_esw_cosq_tcb_threshold_profile_create(int unit,
  10195                                           int flags,
  10196                                           bcm_cosq_buffer_id_t buffer_id,
  10197                                           bcm_cosq_tcb_threshold_profile_t *threshold,
  10198                                           int *index)
  10199 {
  10200 #ifdef BCM_TCB_SUPPORT
  10201     int rv = BCM_E_NONE;
  10202     if (soc_feature(unit, soc_feature_tcb)) {
  10203         TCB_INIT(unit);
  10204         TCB_LOCK(unit);
  10205 #ifdef BCM_HELIX5_SUPPORT
  10206         if (SOC_IS_HELIX5(unit)) {
  10207             rv = bcm_hx5_cosq_tcb_threshold_profile_create(unit, flags, buffer_id,
  10208                                                            threshold, index);
  10209         }
  10210 #endif
  10211 #if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
  10212         if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
  10213             rv = bcm_th2_cosq_tcb_threshold_profile_create(unit, flags, buffer_id,
  10214                     threshold, index);
  10215         }
  10216 #endif
  10217         TCB_UNLOCK(unit);
  10218         return rv;
  10219     }
  10220 #endif
  10221     return BCM_E_UNAVAIL;
  10222 }
  10223 
  10224 /*
  10225  * Function:
  10226  *      bcm_esw_cosq_tcb_threshold_profile_get
  10227  * Purpose:
  10228  *      Get a threshold profile for a specified TCB buffer.
  10229  * Parameters:
  10230  *      unit - (IN) BCM device number.
  10231  *      buffer_id - (IN) TCB buffer id.
  10232  *      index - (IN) profile index
  10233  *      threshold - (OUT) Threshold profile
  10234  * Returns:
  10235  *      BCM_E_XXX
  10236  */
  10237 int
  10238 bcm_esw_cosq_tcb_threshold_profile_get(int unit,
  10239                                        bcm_cosq_buffer_id_t buffer_id,
  10240                                        int index,
  10241                                        bcm_cosq_tcb_threshold_profile_t *threshold)
  10242 {
  10243 #ifdef BCM_TCB_SUPPORT
  10244     int rv = BCM_E_NONE;
  10245     if (soc_feature(unit, soc_feature_tcb)) {
  10246         TCB_INIT(unit);
  10247         TCB_LOCK(unit);
  10248 #ifdef BCM_HELIX5_SUPPORT
  10249         if (SOC_IS_HELIX5(unit)) {
  10250             rv = bcm_hx5_cosq_tcb_threshold_profile_get(unit, buffer_id, index,
  10251                                                         threshold);
  10252         } else
  10253 #endif /* BCM_HELIX5_SUPPORT */
  10254 #if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
  10255         if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
  10256             rv = bcm_th2_cosq_tcb_threshold_profile_get(unit, buffer_id, index,
  10257                                                         threshold);
  10258         }
  10259 #endif
  10260         TCB_UNLOCK(unit);
  10261         return rv;
  10262     }
  10263 #endif
  10264     return BCM_E_UNAVAIL;
  10265 }
  10266 
  10267 /*
  10268  * Function:
  10269  *      bcm_esw_cosq_tcb_threshold_profile_destroy
  10270  * Purpose:
  10271  *      Destory a existing threshold profile for a specified TCB buffer.
  10272  * Parameters:
  10273  *      unit - (IN) BCM device number.
  10274  *      buffer_id - (IN) TCB buffer id.
  10275  *      index - (IN) profile index
  10276  * Returns:
  10277  *      BCM_E_XXX
  10278  */
  10279 int
  10280 bcm_esw_cosq_tcb_threshold_profile_destroy(int unit,
  10281                                            bcm_cosq_buffer_id_t buffer_id,
  10282                                            int index)
  10283 {
  10284 #ifdef BCM_TCB_SUPPORT
  10285     int rv = BCM_E_NONE;
  10286     if (soc_feature(unit, soc_feature_tcb)) {
  10287         TCB_INIT(unit);
  10288         TCB_LOCK(unit);
  10289 #ifdef BCM_HELIX5_SUPPORT
  10290         if (SOC_IS_HELIX5(unit)) {
  10291             rv = bcm_hx5_cosq_tcb_threshold_profile_destroy(unit, buffer_id, index);
  10292         } else
  10293 #endif /* BCM_HELIX5_SUPPORT */
  10294 #if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
  10295         if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
  10296             rv = bcm_th2_cosq_tcb_threshold_profile_destroy(unit, buffer_id, index);
  10297         }
  10298 #endif
  10299         TCB_UNLOCK(unit);
  10300         return rv;
  10301     }
  10302 #endif
  10303     return BCM_E_UNAVAIL;
  10304 }
  10305 
  10306 /*
  10307  * Function:
  10308  *      bcm_esw_cosq_tcb_buffer_multi_get
  10309  * Purpose:
  10310  *      Get packet records in a specified TCB buffer.
  10311  * Parameters:
  10312  *      unit - (IN) BCM device number.
  10313  *      buffer_id - (IN) buffer id
  10314  *      array_max - (IN) Number of entries to be retrieved
  10315  *      buffer_array - (OUT) Pakcet record array
  10316  *      array_count - (OUT) Number of packet records returned in buffer_array
  10317  * Returns:
  10318  *      BCM_E_XXX
  10319  * Notes:
  10320  *      When array_max is 0, buffer_array is NULL, array_count will return actural packet record
  10321  *      count in the TCB buffer.
  10322  */
  10323 int
  10324 bcm_esw_cosq_tcb_buffer_multi_get(int unit,
  10325                                   bcm_cosq_buffer_id_t buffer_id,
  10326                                   int array_max,
  10327                                   bcm_cosq_tcb_buffer_t *buffer_array,
  10328                                   int *array_count)
  10329 {
  10330 #ifdef BCM_TCB_SUPPORT
  10331     int rv = BCM_E_NONE;
  10332     if (soc_feature(unit, soc_feature_tcb)) {
  10333         TCB_INIT(unit);
  10334         TCB_LOCK(unit);
  10335 #ifdef BCM_HELIX5_SUPPORT
  10336     if (SOC_IS_HELIX5(unit)) {
  10337         rv = bcm_hx5_cosq_tcb_buffer_multi_get(unit, buffer_id, array_max,
  10338                                                  buffer_array, array_count);
  10339     }
  10340 #endif /* BCM_HELIX5_SUPPORT */
  10341 #if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
  10342     if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
  10343         rv = bcm_th2_cosq_tcb_buffer_multi_get(unit, buffer_id, array_max,
  10344                                                 buffer_array, array_count);
  10345     }
  10346 #endif
  10347         TCB_UNLOCK(unit);
  10348         return rv;
  10349     }
  10350 #endif
  10351     return BCM_E_UNAVAIL;
  10352 }
  10353 
  10354 /*
  10355  * Function:
  10356  *      bcm_esw_cosq_tcb_event_multi_get
  10357  * Purpose:
  10358  *      Get drop event records in a specified TCB buffer.
  10359  * Parameters:
  10360  *      unit - (IN) BCM device number.
  10361  *      buffer_id - (IN) buffer id
  10362  *      array_max - (IN) Number of entries to be retrieved
  10363  *      event_array - (OUT) Drop event record array
  10364  *      array_count - (OUT) Number of drop event records returned in event_array
  10365  *      overflow_count - (OUT) Drop event count exceed the event buffer.
  10366  * Returns:
  10367  *      BCM_E_XXX
  10368  * Notes:
  10369  *      When array_max is 0, event_array is NULL, array_count will return actural drop event
  10370  *      record count in the TCB buffer.
  10371  */
  10372 int
  10373 bcm_esw_cosq_tcb_event_multi_get(int unit,
  10374                                  bcm_cosq_buffer_id_t buffer_id,
  10375                                  int array_max,
  10376                                  bcm_cosq_tcb_event_t *event_array,
  10377                                  int *array_count,
  10378                                  int *overflow_count)
  10379 {
  10380 #ifdef BCM_TCB_SUPPORT
  10381     int rv = BCM_E_NONE;
  10382     if (soc_feature(unit, soc_feature_tcb)) {
  10383         TCB_INIT(unit);
  10384         TCB_LOCK(unit);
  10385 #ifdef BCM_HELIX5_SUPPORT
  10386     if (SOC_IS_HELIX5(unit)) {
  10387         rv = bcm_hx5_cosq_tcb_event_multi_get(unit, buffer_id, array_max,
  10388                                               event_array, array_count,
  10389                                               overflow_count);
  10390     }
  10391 #endif /* BCM_HELIX5_SUPPORT */
  10392 #if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
  10393     if ((SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) && !SOC_IS_HELIX5(unit)) {
  10394         rv = bcm_th2_cosq_tcb_event_multi_get(unit, buffer_id, array_max,
  10395                                               event_array, array_count,
  10396                                               overflow_count);
  10397     }
  10398 #endif
  10399     TCB_UNLOCK(unit);
  10400         return rv;
  10401     }
  10402 #endif
  10403     return BCM_E_UNAVAIL;
  10404 }
  10405 
  10406 /*
  10407  * Function:
  10408  *      bcm_esw_cosq_tcb_control_set
  10409  * Purpose:
  10410  *      Set TCB instance control status.
  10411  * Parameters:
  10412  *      unit - (IN) BCM device number.
  10413  *      buffer_id - (IN) TCB buffer id.
  10414  *      type - (IN) Control type
  10415  *      arg - (OUT) argument.
  10416  * Returns:
  10417  *      BCM_E_XXX
  10418  * Notes:
  10419  *      When control type is bcmCosqTcbControlFreeze, if buffer_id is -1, this API will freeze all
  10420  *      TCB instance at a once.
  10421  */
  10422 int
  10423 bcm_esw_cosq_tcb_control_set(int unit,
  10424                              bcm_cosq_buffer_id_t buffer_id,
  10425                              bcm_cosq_tcb_control_t type,
  10426                              int arg)
  10427 {
  10428 #ifdef BCM_TCB_SUPPORT
  10429     int rv = BCM_E_NONE;
  10430     if (soc_feature(unit, soc_feature_tcb)) {
  10431         TCB_INIT(unit);
  10432         if (type == bcmCosqTcbControlEnable) {
  10433             TCB_LOCK(unit);
  10434 #ifdef BCM_TOMAHAWK2_SUPPORT
  10435             if (SOC_IS_TOMAHAWK2(unit)) {
  10436             rv = bcm_th2_cosq_tcb_enable(unit, buffer_id, arg);
  10437             }
  10438 #endif
  10439 #ifdef BCM_HELIX5_SUPPORT
  10440            if (SOC_IS_HELIX5(unit)) {
  10441                 rv = bcm_hx5_cosq_tcb_enable(unit, buffer_id, arg);
  10442            }
  10443 #endif /* BCM_HELIX5_SUPPORT */
  10444 #ifdef BCM_TRIDENT3_SUPPORT
  10445             if (SOC_IS_TRIDENT3X(unit) && !SOC_IS_HELIX5(unit)) {
  10446                 rv = bcm_td3_cosq_tcb_enable(unit, buffer_id, arg);
  10447             }
  10448 #endif
  10449             TCB_UNLOCK(unit);
  10450             return rv;
  10451         } else if (type == bcmCosqTcbControlFreeze) {
  10452             TCB_LOCK(unit);
  10453 #ifdef BCM_TOMAHAWK2_SUPPORT
  10454             if (SOC_IS_TOMAHAWK2(unit)) {
  10455             rv = bcm_th2_cosq_tcb_freeze(unit, buffer_id, arg);
  10456             }
  10457 #endif
  10458 #ifdef BCM_HELIX5_SUPPORT
  10459            if (SOC_IS_HELIX5(unit)) {
  10460                 rv = bcm_hx5_cosq_tcb_freeze(unit, buffer_id, arg);
  10461            }
  10462 #endif /* BCM_HELIX5_SUPPORT */
  10463 #ifdef BCM_TRIDENT3_SUPPORT
  10464             if (SOC_IS_TRIDENT3X(unit)  && !SOC_IS_HELIX5(unit)) {
  10465                 rv = bcm_td3_cosq_tcb_freeze(unit, buffer_id, arg);
  10466             }
  10467 #endif
  10468             TCB_UNLOCK(unit);
  10469             return rv;
  10470         } else {
  10471             return BCM_E_PARAM;
  10472         }
  10473     }
  10474 #endif
  10475     return BCM_E_UNAVAIL;
  10476 }
  10477 
  10478 /*
  10479  * Function:
  10480  *      bcm_esw_cosq_tcb_control_get
  10481  * Purpose:
  10482  *      Get TCB instance control status.
  10483  * Parameters:
  10484  *      unit - (IN) BCM device number.
  10485  *      buffer_id - (IN) TCB buffer id.
  10486  *      type - (IN) Control type
  10487  *      arg - (OUT) argument.
  10488  * Returns:
  10489  *      BCM_E_XXX
  10490  */
  10491 int
  10492 bcm_esw_cosq_tcb_control_get(int unit,
  10493                              bcm_cosq_buffer_id_t buffer_id,
  10494                              bcm_cosq_tcb_control_t type,
  10495                              int *arg)
  10496 {
  10497 #ifdef BCM_TCB_SUPPORT
  10498     int rv = BCM_E_NONE;
  10499     if (soc_feature(unit, soc_feature_tcb)) {
  10500 #if defined (BCM_TOMAHAWK2_SUPPORT) || defined (BCM_TRIDENT3_SUPPORT)
  10501         TCB_INIT(unit);
  10502         TCB_LOCK(unit);
  10503         rv = bcm_th2_cosq_tcb_control_get(unit, buffer_id, type, arg);
  10504         TCB_UNLOCK(unit);
  10505         return rv;
  10506 #endif
  10507     }
  10508 #endif
  10509     return BCM_E_UNAVAIL;
  10510 }
  10511 
  10512 /*
  10513  * Function:
  10514  *      bcm_esw_cosq_tcb_cb_register
  10515  * Purpose:
  10516  *      Register a callback for handling TCB freeze events.
  10517  * Parameters:
  10518  *      unit - (IN) BCM device number.
  10519  *      fn - (IN) A pointer to the callback function to call for TCB freeze events.
  10520  *      user_data - (IN) Pointer to user data to supply in the callback
  10521  * Returns:
  10522  *      BCM_E_XXX
  10523  */
  10524 int
  10525 bcm_esw_cosq_tcb_cb_register(int unit, bcm_cosq_tcb_callback_t fn, void *user_data)
  10526 {
  10527 #ifdef BCM_TCB_SUPPORT
  10528     int rv = BCM_E_NONE;
  10529     _bcm_cosq_tcb_unit_ctrl_t *tcb_unit_info;
  10530 
  10531     tcb_unit_info = TCB_UNIT_CONTROL(unit);
  10532 
  10533     if (soc_feature(unit, soc_feature_tcb)) {
  10534         TCB_INIT(unit);
  10535         TCB_LOCK(unit);
  10536 
  10537         if(NULL == tcb_unit_info->tcb_evt_cb) {
  10538             tcb_unit_info->tcb_evt_cb = fn;
  10539             tcb_unit_info->tcb_evt_user_data = user_data;
  10540         } else {
  10541             /* Callback function is already registered */
  10542             rv = BCM_E_EXISTS;
  10543         }
  10544 
  10545         TCB_UNLOCK(unit);
  10546         return rv;
  10547     }
  10548 #endif
  10549     return BCM_E_UNAVAIL;
  10550 }
  10551 
  10552 /*
  10553  * Function:
  10554  *      bcm_esw_cosq_tcb_cb_unregister
  10555  * Purpose:
  10556  *      Unregister a callback for handling TCB freeze events.
  10557  * Parameters:
  10558  *      unit - (IN) BCM device number.
  10559  *      fn - (IN) A pointer to the callback function to unregister from TCB freeze events
  10560  * Returns:
  10561  *      BCM_E_XXX
  10562  */
  10563 int
  10564 bcm_esw_cosq_tcb_cb_unregister(int unit, bcm_cosq_tcb_callback_t fn)
  10565 {
  10566 #ifdef BCM_TCB_SUPPORT
  10567     int rv = BCM_E_NONE;
  10568     _bcm_cosq_tcb_unit_ctrl_t *tcb_unit_info;
  10569 
  10570     tcb_unit_info = TCB_UNIT_CONTROL(unit);
  10571 
  10572     if (soc_feature(unit, soc_feature_tcb)) {
  10573         TCB_INIT(unit);
  10574         TCB_LOCK(unit);
  10575 
  10576         if(fn == tcb_unit_info->tcb_evt_cb) {
  10577             tcb_unit_info->tcb_evt_cb = NULL;
  10578             tcb_unit_info->tcb_evt_user_data = NULL;
  10579         } else {
  10580             /* Callback function is not registered */
  10581             rv = BCM_E_NOT_FOUND;
  10582         }
  10583 
  10584         TCB_UNLOCK(unit);
  10585         return rv;
  10586     }
  10587 #endif
  10588 
  10589     return BCM_E_UNAVAIL;
  10590 }
  10591 
  10592 int
  10593 _bcm_cosq_tcb_uc_queue_resolve(int unit, bcm_cosq_buffer_id_t buffer_id, int queue,
  10594                                bcm_gport_t *uc_gport)
  10595 {
  10596 #ifdef BCM_TCB_SUPPORT
  10597     int rv = BCM_E_UNAVAIL;
  10598 
  10599 #ifdef BCM_TOMAHAWK2_SUPPORT
  10600     if (SOC_IS_TOMAHAWK2(unit)) {
  10601         rv = bcm_th2_cosq_tcb_uc_queue_resolve(unit, buffer_id, queue, uc_gport);
  10602     }
  10603 #endif
  10604 #ifdef BCM_HELIX5_SUPPORT
  10605     if (SOC_IS_HELIX5(unit)) {
  10606         rv = bcm_hx5_cosq_tcb_uc_queue_resolve(unit, buffer_id, queue, uc_gport);
  10607     }
  10608 #endif
  10609 #ifdef BCM_TRIDENT3_SUPPORT
  10610     if (SOC_IS_TRIDENT3X(unit)  && !SOC_IS_HELIX5(unit)) {
  10611         rv = bcm_td3_cosq_tcb_uc_queue_resolve(unit, buffer_id, queue, uc_gport);
  10612     }
  10613 #endif
  10614     return rv;
  10615 #endif
  10616     return BCM_E_UNAVAIL;
  10617 }
  10618 #endif /* INCLUDE_TCB && BCM_TCB_SUPPORT */
  10619 
  10620 int
  10621 _bcm_esw_cosq_num_get(
  10622     int unit,
  10623     int *num_cos)
  10624 {
  10625 #ifdef BCM_TRIDENT_SUPPORT
  10626     int index, cosq;
  10627     cpu_cos_map_entry_t cpu_cos_map_entry;
  10628 
  10629     if (SOC_IS_TD_TT(unit)) {
  10630         index = soc_mem_index_count(unit, CPU_COS_MAPm) - _BCM_CPU_COS_MAPS_RSVD +
  10631                 (BCM_PRIO_MAX - BCM_PRIO_MIN + 1);
  10632         /* Read the entry */
  10633         SOC_IF_ERROR_RETURN
  10634             (READ_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, index, &cpu_cos_map_entry));
  10635 
  10636         cosq = soc_mem_field32_get(unit, CPU_COS_MAPm, &cpu_cos_map_entry, COSf);
  10637         *num_cos = cosq + 1;
  10638     }
  10639 #endif
  10640 
  10641     return BCM_E_NONE;
  10642 }
  10643 
  10644 #ifndef BCM_SW_STATE_DUMP_DISABLE
  10645 /*
  10646  * Function:
  10647  *     _bcm_cosq_sw_dump
  10648  * Purpose:
  10649  *     Displays COS Queue information maintained by software.
  10650  * Parameters:
  10651  *     unit - Device unit number
  10652  * Returns:
  10653  *     None
  10654  */
  10655 void
  10656 _bcm_cosq_sw_dump(int unit)
  10657 {
  10658     mbcm_driver[unit]->mbcm_cosq_sw_dump(unit);
  10659 }
  10660 #endif /*  BCM_SW_STATE_DUMP_DISABLE */
  10661 
  10662 int bcm_esw_cosq_burst_monitor_dma_config_set(int unit,
  10663                                               uint32 host_mem_size,
  10664                                               uint32 **host_mem_add)
  10665 {
  10666     int result = BCM_E_UNAVAIL;
  10667     /* Take lock */
  10668     COSQ_EVENT_LOCK(unit);
  10669     /* QCM app microburst APIs.  */
  10670 
  10671 #ifdef BCM_TOMAHAWK_SUPPORT
  10672     if (SOC_IS_TOMAHAWKX(unit)) {
  10673         result = bcm_th_cosq_burst_monitor_dma_config_set(unit, host_mem_size,
  10674                                                           host_mem_add);
  10675     }
  10676 #endif /* BCM_TOMAHAWK_SUPPORT */
  10677 #ifdef BCM_TRIDENT3_SUPPORT
  10678     if (SOC_IS_TRIDENT3(unit)) {
  10679         result = bcm_td3_cosq_burst_monitor_dma_config_set(unit, host_mem_size,
  10680                                                            host_mem_add);
  10681     }
  10682 #endif
  10683 
  10684     /* Release lock */
  10685     COSQ_EVENT_UNLOCK(unit);
  10686     return result;
  10687 }
  10688 
  10689 int bcm_esw_cosq_burst_monitor_dma_config_get(int unit,
  10690                                               uint32 *host_mem_size,
  10691                                               uint32 **host_mem_add)
  10692 {
  10693     int result = BCM_E_UNAVAIL;
  10694     /* Take lock */
  10695     COSQ_EVENT_LOCK(unit);
  10696     /* QCM app microburst APIs.  */
  10697 #ifdef BCM_TOMAHAWK_SUPPORT
  10698     if (SOC_IS_TOMAHAWKX(unit)) {
  10699        result = bcm_th_cosq_burst_monitor_dma_config_get(unit, host_mem_size,
  10700                                                          host_mem_add);
  10701     }
  10702 #endif /* BCM_TOMAHAWK_SUPPORT */
  10703 #ifdef BCM_TRIDENT3_SUPPORT
  10704     if (SOC_IS_TRIDENT3(unit)) {
  10705        result = bcm_td3_cosq_burst_monitor_dma_config_get(unit, host_mem_size,
  10706                                                           host_mem_add);
  10707     }
  10708 #endif /* BCM_TRIDENT3_SUPPORT */
  10709     /* Release lock */
  10710     COSQ_EVENT_UNLOCK(unit);
  10711     return result;
  10712 }
  10713 
  10714 int bcm_esw_cosq_burst_monitor_set(int unit, int num_gports,
  10715                                    bcm_gport_t *gport_list)
  10716 {
  10717     int result = BCM_E_UNAVAIL;
  10718     /* Take lock */
  10719     COSQ_EVENT_LOCK(unit);
  10720 
  10721     /* QCM app microburst APIs.  */
  10722 #ifdef BCM_TOMAHAWK_SUPPORT
  10723     if (SOC_IS_TOMAHAWKX(unit)) {
  10724         result = bcm_th_cosq_burst_monitor_set(unit, num_gports,
  10725                                                gport_list);
  10726     }
  10727 #endif /* BCM_TOMAHAWK_SUPPORT */
  10728 #ifdef BCM_TRIDENT3_SUPPORT
  10729     if (SOC_IS_TRIDENT3(unit)) {
  10730         result = bcm_td3_cosq_burst_monitor_set(unit, num_gports,
  10731                                                 gport_list);
  10732     }
  10733 #endif
  10734 
  10735     /* Release lock */
  10736     COSQ_EVENT_UNLOCK(unit);
  10737     return result;
  10738 }
  10739 
  10740 int bcm_esw_cosq_burst_monitor_get(int unit, int  max_gports,
  10741                                    bcm_gport_t *gport_list, int *num_gports)
  10742 {
  10743     int result = BCM_E_UNAVAIL;
  10744     /* Take lock */
  10745     COSQ_EVENT_LOCK(unit);
  10746 
  10747     /* QCM app microburst APIs.  */
  10748 #ifdef BCM_TOMAHAWK_SUPPORT
  10749     if (SOC_IS_TOMAHAWKX(unit)) {
  10750         result = bcm_th_cosq_burst_monitor_get(unit, max_gports,
  10751                                                gport_list, num_gports);
  10752     }
  10753 #endif /* BCM_TOMAHAWK_SUPPORT */
  10754 #ifdef BCM_TRIDENT3_SUPPORT
  10755     if (SOC_IS_TRIDENT3(unit)) {
  10756         result = bcm_td3_cosq_burst_monitor_get(unit, max_gports,
  10757                                                 gport_list, num_gports);
  10758     }
  10759 #endif
  10760 
  10761     /* Release lock */
  10762     COSQ_EVENT_UNLOCK(unit);
  10763     return result;
  10764 }
  10765 
  10766 /*
  10767  * Function:
  10768  *     bcm_esw_cosq_gport_info_get
  10769  * Purpose:
  10770  *     Get cosq gport info.
  10771  * Parameters:
  10772  *     unit             - (IN) unit number
  10773  *     gport            - (IN) priority
  10774  *     info             - (OUT) Info of the given cosq gport
  10775  * Returns:
  10776  *     BCM_E_XXX
  10777  */
  10778  int bcm_esw_cosq_gport_info_get(
  10779      int unit,
  10780      bcm_gport_t gport,
  10781      bcm_cosq_gport_level_info_t *info)
  10782 {
  10783     int rv = BCM_E_UNAVAIL;
  10784 
  10785 #ifdef BCM_HELIX5_SUPPORT
  10786     if (SOC_IS_HELIX5(unit)) {
  10787         rv  = bcm_hx5_cosq_gport_info_get(unit, gport, info);
  10788     }
  10789 #endif
  10790   return rv;
  10791 }
  10792 int
  10793 bcm_esw_obm_cb_register(int unit,
  10794                          bcm_obm_callback_fn  fn,
  10795                          void *fn_data)
  10796 {
  10797 
  10798     int rv = BCM_E_UNAVAIL;
  10799 
  10800 #ifdef BCM_MONTEREY_SUPPORT
  10801     if (SOC_IS_MONTEREY(unit)) {
  10802         rv = _soc_monterey_obm_cb_register(unit ,fn, fn_data);
  10803     }
  10804 #endif
  10805     return rv;
  10806 }
  10807 
  10808 int
  10809 bcm_esw_obm_cb_unregister(int unit,
  10810                          bcm_obm_callback_fn  fn,
  10811                          void *fn_data)
  10812 {
  10813 
  10814     int rv = BCM_E_UNAVAIL;
  10815 
  10816 #ifdef BCM_MONTEREY_SUPPORT
  10817     if (SOC_IS_MONTEREY(unit)) {
  10818         rv = _soc_monterey_obm_cb_unregister(unit,fn, fn_data);
  10819     }
  10820 #endif
  10821     return rv;
  10822 }
  10823