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_stat.c (63900B)


      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 Counter get/set API implemenation for Tomahawk3
      8  */
      9 #if defined(BCM_TOMAHAWK3_SUPPORT)
     10 #include <bcm_int/esw/pfc.h>
     11 #include <bcm_int/esw/port.h>
     12 #include <bcm_int/esw/tomahawk3.h>
     13 #include <soc/feature.h>
     14 #include <soc/drv.h>
     15 #include <soc/types.h>
     16 #include <soc/scache.h>
     17 #include <soc/profile_mem.h>
     18 #include <soc/debug.h>
     19 #include <soc/tomahawk3.h>
     20 #include <soc/dma.h>
     21 #include <soc/mmu_config.h>
     22 #include <soc/init/tomahawk3_idb_init.h>
     23 
     24 /* Number of COSQs configured for this unit */
     25 #define TH3_PORT_NUM_COS(unit, port) \
     26     ((IS_CPU_PORT(unit, port)) ? SOC_TH3_NUM_CPU_QUEUES : SOC_TH3_NUM_GP_QUEUES)
     27 
     28 
     29 STATIC int
     30 _bcm_th3_cosq_mmu_port_queue_counters_get(int unit, bcm_gport_t port,
     31         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync)
     32 {
     33     soc_ctr_control_info_t ctrl_info;
     34     soc_reg_t ctr_reg_uc, ctr_reg_mc;
     35     _bcm_th3_cosq_index_style_t style;
     36     int startq = 0, ci;
     37     bcm_port_t local_port = -1;
     38     uint64 sum, value64;
     39     soc_info_t *si = &SOC_INFO(unit);
     40     int num_uc = -1, num_mc = -1;
     41     int uc_q[2], mc_q[1];
     42     int loop_idx;
     43 
     44     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_PORT;
     45     if (stat == bcmCosqStatOutBytes) {
     46         ctr_reg_uc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE_UC;
     47         ctr_reg_mc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE;
     48     } else if (stat == bcmCosqStatOutPackets) {
     49         ctr_reg_uc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT_UC;
     50         ctr_reg_mc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT;
     51     } else if (stat == bcmCosqStatUCOutPackets) {
     52         ctr_reg_uc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT_UC;
     53         ctr_reg_mc = INVALIDr;
     54     } else if (stat == bcmCosqStatMCOutPackets) {
     55         ctr_reg_uc = INVALIDr;
     56         ctr_reg_mc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT;
     57     } else if (stat == bcmCosqStatUCOutBytes) {
     58         ctr_reg_uc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE_UC;
     59         ctr_reg_mc = INVALIDr;
     60     } else if (stat == bcmCosqStatMCOutBytes) {
     61         ctr_reg_uc = INVALIDr;
     62         ctr_reg_mc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE;
     63     } else if (stat == bcmCosqStatDroppedBytes) {
     64         ctr_reg_uc = SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE_UC;
     65         ctr_reg_mc = SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE;
     66         ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
     67     } else { /*stat == bcmCosqStatEgressCongestionDroppedPackets */
     68         ctr_reg_uc = SOC_COUNTER_NON_DMA_COSQ_DROP_PKT_UC;
     69         ctr_reg_mc = SOC_COUNTER_NON_DMA_COSQ_DROP_PKT;
     70         ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
     71     }
     72 
     73     /* Use index style cos to get the UC-COS/MC cos offset */
     74     style = _BCM_TH3_COSQ_INDEX_STYLE_COS;
     75     BCM_IF_ERROR_RETURN
     76             (_bcm_th3_cosq_index_resolve
     77             (unit, port, cosq, style, &local_port, &startq, NULL));
     78     if ((cosq < -1) || (cosq >= TH3_PORT_NUM_COS(unit, local_port))) {
     79         return BCM_E_PARAM;
     80     }
     81     ctrl_info.instance = local_port;
     82     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port)) {
     83         BCM_IF_ERROR_RETURN
     84             (soc_counter_generic_get(unit, ctr_reg_uc,
     85                 ctrl_info, sync, startq, value));
     86     } else if (BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
     87         BCM_IF_ERROR_RETURN
     88             (soc_counter_generic_get(unit, ctr_reg_mc,
     89                 ctrl_info, sync, startq, value));
     90     } else if (BCM_GPORT_IS_SCHEDULER(port)) {
     91         BCM_IF_ERROR_RETURN(
     92                 _bcm_th3_cosq_sched_node_child_get(unit, port, &num_uc, uc_q,
     93                 &num_mc, mc_q));
     94         if (num_uc > 2 || num_mc > 1) {
     95             return BCM_E_INTERNAL;
     96         }
     97         COMPILER_64_ZERO(sum);
     98         if (num_uc > 0) {
     99             for (loop_idx = 0; loop_idx < num_uc; loop_idx++) {
    100                 if (ctr_reg_uc != INVALIDr) {
    101                     BCM_IF_ERROR_RETURN(
    102                         soc_counter_generic_get(unit, ctr_reg_uc,
    103                                                      ctrl_info,
    104                                                      sync, uc_q[loop_idx],
    105                                                      &value64));
    106                     COMPILER_64_ADD_64(sum, value64);
    107                 }
    108 
    109             }
    110         }
    111         if (num_mc > 0) {
    112             for (loop_idx = 0; loop_idx < num_mc; loop_idx++) {
    113                 if (ctr_reg_mc != INVALIDr) {
    114                     BCM_IF_ERROR_RETURN(
    115                         soc_counter_generic_get(unit, ctr_reg_mc,
    116                                                      ctrl_info,
    117                                                      sync, mc_q[loop_idx],
    118                                                      &value64));
    119                     COMPILER_64_ADD_64(sum, value64);
    120                 }
    121 
    122             }
    123         }
    124         *value = sum;
    125     } else {
    126         if (cosq == -1) {
    127             /* Get UC values for NON CPU port */
    128             COMPILER_64_ZERO(sum);
    129             if (!IS_CPU_PORT(unit, local_port) &&
    130                     (stat != bcmCosqStatMCOutBytes) &&
    131                     (stat != bcmCosqStatMCOutPackets)) {
    132                 for (ci = 0; ci < si->port_num_uc_cosq[local_port] ; ci++) {
    133                     if (ctr_reg_uc != INVALIDr) {
    134                         BCM_IF_ERROR_RETURN
    135                             (soc_counter_generic_get(unit, ctr_reg_uc,
    136                                                      ctrl_info,
    137                                                      sync, ci, &value64));
    138                         COMPILER_64_ADD_64(sum, value64);
    139                     }
    140                 }
    141             }
    142             /* Get sum of MC values for any port*/
    143             if ((stat != bcmCosqStatUCOutBytes) &&
    144                     (stat != bcmCosqStatUCOutPackets)) {
    145                 for (ci = 0; ci < si->port_num_cosq[local_port] ; ci++) {
    146                     BCM_IF_ERROR_RETURN
    147                         (soc_counter_generic_get(unit, ctr_reg_mc,
    148                                           ctrl_info, sync, ci, &value64));
    149                     COMPILER_64_ADD_64(sum, value64);
    150                 }
    151             }
    152             *value = sum;
    153         } else {
    154             if (cosq < si->port_num_uc_cosq[local_port]) {
    155                 /* If queue is unicast */
    156                 if ((stat == bcmCosqStatMCOutBytes) ||
    157                     (stat == bcmCosqStatMCOutPackets)) {
    158                     return BCM_E_PARAM;
    159                 }
    160                 BCM_IF_ERROR_RETURN
    161                             (soc_counter_generic_get(unit, ctr_reg_uc,
    162                                                      ctrl_info,
    163                                                sync, cosq, value));
    164             } else {
    165                 /* Multicast queue */
    166                 if ((stat == bcmCosqStatUCOutBytes) ||
    167                     (stat == bcmCosqStatUCOutPackets)) {
    168                     return BCM_E_PARAM;
    169                 }
    170                 ci = cosq - si->port_num_uc_cosq[local_port];
    171                 BCM_IF_ERROR_RETURN
    172                     (soc_counter_generic_get(unit, ctr_reg_mc,
    173                                              ctrl_info,
    174                                              sync, ci, value));
    175             }
    176         }
    177     }
    178     return BCM_E_NONE;
    179 }
    180 
    181 STATIC int
    182 _bcm_th3_cosq_mmu_port_queue_counters_set(int unit, bcm_gport_t port,
    183         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 value)
    184 {
    185     soc_ctr_control_info_t ctrl_info;
    186     soc_reg_t ctr_reg_uc, ctr_reg_mc;
    187     _bcm_th3_cosq_index_style_t style;
    188     int startq = 0, ci;
    189     bcm_port_t local_port = -1;
    190     soc_info_t *si = &SOC_INFO(unit);
    191     int num_uc = -1, num_mc = -1;
    192     int uc_q[2], mc_q[1];
    193     int loop_idx;
    194 
    195     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_PORT;
    196 
    197     if (stat == bcmCosqStatOutBytes) {
    198         ctr_reg_uc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE_UC;
    199         ctr_reg_mc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE;
    200     } else if (stat == bcmCosqStatOutPackets) {
    201         ctr_reg_uc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT_UC;
    202         ctr_reg_mc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT;
    203     } else if (stat == bcmCosqStatUCOutPackets) {
    204         ctr_reg_uc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT_UC;
    205         ctr_reg_mc = INVALIDr;
    206     } else if (stat == bcmCosqStatMCOutPackets) {
    207         ctr_reg_uc = INVALIDr;
    208         ctr_reg_mc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_PKT;
    209     } else if (stat == bcmCosqStatUCOutBytes) {
    210         ctr_reg_uc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE_UC;
    211         ctr_reg_mc = INVALIDr;
    212     } else if (stat == bcmCosqStatMCOutBytes) {
    213         ctr_reg_uc = INVALIDr;
    214         ctr_reg_mc = SOC_COUNTER_NON_DMA_EGR_PERQ_XMT_BYTE;
    215     } else if (stat == bcmCosqStatDroppedBytes) {
    216         ctr_reg_uc = SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE_UC;
    217         ctr_reg_mc = SOC_COUNTER_NON_DMA_COSQ_DROP_BYTE;
    218         ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
    219     } else { /*stat == bcmCosqStatEgressCongestionDroppedPackets */
    220         ctr_reg_uc = SOC_COUNTER_NON_DMA_COSQ_DROP_PKT_UC;
    221         ctr_reg_mc = SOC_COUNTER_NON_DMA_COSQ_DROP_PKT;
    222         ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
    223     }
    224 
    225     /* Use index style cos to get the UC-COS/MC cos offset */
    226     style = _BCM_TH3_COSQ_INDEX_STYLE_COS;
    227     BCM_IF_ERROR_RETURN
    228             (_bcm_th3_cosq_index_resolve
    229             (unit, port, cosq, style, &local_port, &startq, NULL));
    230     if ((cosq < -1) || (cosq >= TH3_PORT_NUM_COS(unit, local_port))) {
    231         return BCM_E_PARAM;
    232     }
    233     ctrl_info.instance = local_port;
    234     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port)) {
    235         BCM_IF_ERROR_RETURN
    236             (soc_counter_generic_set(unit, ctr_reg_uc,
    237                 ctrl_info, 0, startq, value));
    238     } else if (BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    239         BCM_IF_ERROR_RETURN
    240             (soc_counter_generic_set(unit, ctr_reg_mc,
    241                 ctrl_info, 0, startq, value));
    242     } else if (BCM_GPORT_IS_SCHEDULER(port)) {
    243         BCM_IF_ERROR_RETURN(
    244             _bcm_th3_cosq_sched_node_child_get(unit, port, &num_uc, uc_q,
    245                 &num_mc, mc_q));
    246         if (num_uc > 2 || num_mc > 1) {
    247             return BCM_E_INTERNAL;
    248         }
    249         if (num_uc > 0) {
    250             for (loop_idx = 0; loop_idx < num_uc; loop_idx++) {
    251                 if (ctr_reg_uc != INVALIDr) {
    252                     BCM_IF_ERROR_RETURN(
    253                         soc_counter_generic_set(unit, ctr_reg_uc,
    254                                                      ctrl_info, 0,
    255                                                      uc_q[loop_idx],
    256                                                      value));
    257                 }
    258 
    259             }
    260         }
    261         if (num_mc > 0) {
    262             for (loop_idx = 0; loop_idx < num_mc; loop_idx++) {
    263                 if (ctr_reg_mc != INVALIDr) {
    264                     BCM_IF_ERROR_RETURN(
    265                         soc_counter_generic_set(unit, ctr_reg_mc,
    266                                                      ctrl_info, 0,
    267                                                      mc_q[loop_idx],
    268                                                      value));
    269                 }
    270 
    271             }
    272         }
    273     } else {
    274         BCM_IF_ERROR_RETURN
    275             (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    276         ctrl_info.instance = local_port;
    277         if (cosq == -1) {
    278             /* Get UC values for NON CPU port */
    279             if (!IS_CPU_PORT(unit, local_port) &&
    280                     (stat != bcmCosqStatMCOutBytes) &&
    281                     (stat != bcmCosqStatMCOutPackets)) {
    282                 for (ci = 0; ci < si->port_num_uc_cosq[local_port] ; ci++) {
    283                     if (ctr_reg_uc != INVALIDr) {
    284                         BCM_IF_ERROR_RETURN
    285                             (soc_counter_generic_set(unit, ctr_reg_uc,
    286                                                      ctrl_info, 0,
    287                                                      ci, value));
    288                     }
    289                 }
    290             }
    291             if ((stat != bcmCosqStatUCOutBytes) &&
    292                 (stat != bcmCosqStatUCOutPackets)) {
    293                 for (ci = 0; ci < si->port_num_cosq[local_port] ; ci++) {
    294                     if (ctr_reg_mc != INVALIDr) {
    295                         BCM_IF_ERROR_RETURN
    296                             (soc_counter_generic_set(unit, ctr_reg_mc,
    297                                           ctrl_info, 0, ci, value));
    298                     }
    299                 }
    300             }
    301         } else {
    302             if ((!IS_CPU_PORT(unit, local_port)) && (cosq <
    303                         si->port_num_uc_cosq[local_port])) {
    304                 if ((stat == bcmCosqStatMCOutBytes) ||
    305                     (stat == bcmCosqStatMCOutPackets)) {
    306                     return BCM_E_PARAM;
    307                 }
    308                 /* If queue is unicast */
    309                 BCM_IF_ERROR_RETURN
    310                             (soc_counter_generic_set(unit, ctr_reg_uc,
    311                                                      ctrl_info,
    312                                                0, cosq, value));
    313             } else {
    314                 /* Multicast queue */
    315                 if ((stat == bcmCosqStatUCOutBytes) ||
    316                     (stat == bcmCosqStatUCOutPackets)) {
    317                     return BCM_E_PARAM;
    318                 }
    319 
    320                 ci = cosq - si->port_num_uc_cosq[local_port];
    321                 BCM_IF_ERROR_RETURN
    322                     (soc_counter_generic_set(unit, ctr_reg_mc,
    323                                              ctrl_info,
    324                                              0, ci, value));
    325             }
    326         }
    327     }
    328     return BCM_E_NONE;
    329 }
    330 
    331 STATIC int
    332 _bcm_th3_cosq_mmu_port_queue_total_drop_counters_get(int unit, bcm_gport_t port,
    333         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync)
    334 {
    335     soc_ctr_control_info_t ctrl_info;
    336     _bcm_th3_cosq_index_style_t style;
    337     int startq = 0, ci;
    338     bcm_port_t local_port = -1;
    339     uint64 sum, value64;
    340     soc_info_t *si = &SOC_INFO(unit);
    341     int num_uc = -1, num_mc = -1;
    342     int uc_q[2], mc_q[1];
    343     int loop_idx;
    344 
    345     /* Use index style cos to get the UC-COS/MC cos offset */
    346     style = _BCM_TH3_COSQ_INDEX_STYLE_COS;
    347     BCM_IF_ERROR_RETURN
    348             (_bcm_th3_cosq_index_resolve
    349             (unit, port, cosq, style, &local_port, &startq, NULL));
    350     if ((cosq < -1) || (cosq >= TH3_PORT_NUM_COS(unit, local_port))) {
    351         return BCM_E_PARAM;
    352     }
    353     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
    354     ctrl_info.instance = local_port;
    355     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port)) {
    356         COMPILER_64_ZERO(sum);
    357         BCM_IF_ERROR_RETURN
    358             (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_PKT_UC,
    359                 ctrl_info, sync, startq, &value64));
    360         COMPILER_64_ADD_64(sum, value64);
    361         BCM_IF_ERROR_RETURN
    362             (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_WRED_PKT,
    363                 ctrl_info, sync, startq, &value64));
    364         COMPILER_64_ADD_64(sum, value64);
    365         *value = sum;
    366     } else if (BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    367         BCM_IF_ERROR_RETURN
    368             (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_PKT,
    369                 ctrl_info, sync, startq, value));
    370     } else if (BCM_GPORT_IS_SCHEDULER(port)) {
    371         BCM_IF_ERROR_RETURN(
    372             _bcm_th3_cosq_sched_node_child_get(unit, port, &num_uc, uc_q,
    373                 &num_mc, mc_q));
    374         if (num_uc > 2 || num_mc > 1) {
    375             return BCM_E_INTERNAL;
    376         }
    377         COMPILER_64_ZERO(sum);
    378         if (num_uc > 0) {
    379             for (loop_idx = 0; loop_idx < num_uc; loop_idx++) {
    380                 BCM_IF_ERROR_RETURN(
    381                     soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_PKT_UC,
    382                                                  ctrl_info,
    383                                                  sync, uc_q[loop_idx],
    384                                                  &value64));
    385                 COMPILER_64_ADD_64(sum, value64);
    386                 BCM_IF_ERROR_RETURN(
    387                     soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_WRED_PKT,
    388                                                  ctrl_info,
    389                                                  sync, uc_q[loop_idx],
    390                                                  &value64));
    391                 COMPILER_64_ADD_64(sum, value64);
    392             }
    393 
    394         }
    395         if (num_mc > 0) {
    396             for (loop_idx = 0; loop_idx < num_mc; loop_idx++) {
    397                 BCM_IF_ERROR_RETURN(
    398                     soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_PKT,
    399                                                  ctrl_info,
    400                                                  sync, mc_q[loop_idx],
    401                                                  &value64));
    402                 COMPILER_64_ADD_64(sum, value64);
    403 
    404             }
    405         }
    406         *value = sum;
    407     } else {
    408         if (cosq == -1) {
    409             /* Get UC values for NON CPU port */
    410             COMPILER_64_ZERO(sum);
    411             if (!IS_CPU_PORT(unit, local_port)) {
    412                 for (ci = 0; ci < si->port_num_uc_cosq[local_port] ; ci++) {
    413                     BCM_IF_ERROR_RETURN
    414                         (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_PKT_UC,
    415                                                  ctrl_info,
    416                                                  sync, ci, &value64));
    417                     COMPILER_64_ADD_64(sum, value64);
    418                     BCM_IF_ERROR_RETURN
    419                         (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_WRED_PKT,
    420                                                  ctrl_info,
    421                                                  sync, ci, &value64));
    422                     COMPILER_64_ADD_64(sum, value64);
    423                 }
    424             }
    425             /* Get sum of MC values for any port*/
    426             for (ci = 0; ci < si->port_num_cosq[local_port] ; ci++) {
    427                 BCM_IF_ERROR_RETURN
    428                     (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_PKT,
    429                                       ctrl_info, sync, ci, &value64));
    430                 COMPILER_64_ADD_64(sum, value64);
    431             }
    432             *value = sum;
    433         } else {
    434             if (cosq < si->port_num_uc_cosq[local_port]) {
    435                 /* If queue is unicast */
    436                 COMPILER_64_ZERO(sum);
    437                 BCM_IF_ERROR_RETURN
    438                     (soc_counter_generic_get(unit,
    439                      SOC_COUNTER_NON_DMA_COSQ_DROP_PKT_UC, ctrl_info, sync,
    440                      cosq, &value64));
    441                 COMPILER_64_ADD_64(sum, value64);
    442                 BCM_IF_ERROR_RETURN
    443                     (soc_counter_generic_get(unit,
    444                     SOC_COUNTER_NON_DMA_COSQ_DROP_WRED_PKT, ctrl_info, sync,
    445                     cosq, &value64));
    446                 COMPILER_64_ADD_64(sum, value64);
    447                 *value = sum;
    448             } else {
    449                 /* Multicast queue */
    450                 ci = cosq - si->port_num_uc_cosq[local_port];
    451                 BCM_IF_ERROR_RETURN
    452                     (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_COSQ_DROP_PKT,
    453                                              ctrl_info,
    454                                              sync, ci, value));
    455             }
    456         }
    457     }
    458     return BCM_E_NONE;
    459 }
    460 
    461 STATIC int
    462 _bcm_th3_cosq_mmu_port_queue_total_drop_counters_set(int unit, bcm_gport_t port,
    463         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 value)
    464 {
    465     soc_ctr_control_info_t ctrl_info;
    466     soc_reg_t ctr_reg_uc0, ctr_reg_mc, ctr_reg_uc1;
    467     _bcm_th3_cosq_index_style_t style;
    468     int startq = 0, ci;
    469     bcm_port_t local_port = -1;
    470     soc_info_t *si = &SOC_INFO(unit);
    471     int num_uc = -1, num_mc = -1;
    472     int uc_q[2], mc_q[1];
    473     int loop_idx;
    474 
    475     ctr_reg_uc0 = SOC_COUNTER_NON_DMA_COSQ_DROP_PKT_UC;
    476     ctr_reg_uc1 = SOC_COUNTER_NON_DMA_COSQ_DROP_WRED_PKT;
    477     ctr_reg_mc = SOC_COUNTER_NON_DMA_COSQ_DROP_PKT;
    478 
    479     /* Use index style cos to get the UC-COS/MC cos offset */
    480     style = _BCM_TH3_COSQ_INDEX_STYLE_COS;
    481     BCM_IF_ERROR_RETURN
    482             (_bcm_th3_cosq_index_resolve
    483             (unit, port, cosq, style, &local_port, &startq, NULL));
    484     if ((cosq < -1) || (cosq >= TH3_PORT_NUM_COS(unit, local_port))) {
    485         return BCM_E_PARAM;
    486     }
    487     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
    488     ctrl_info.instance = local_port;
    489     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port)) {
    490         BCM_IF_ERROR_RETURN
    491             (soc_counter_generic_set(unit, ctr_reg_uc0,
    492                 ctrl_info, 0, startq, value));
    493         BCM_IF_ERROR_RETURN
    494             (soc_counter_generic_set(unit, ctr_reg_uc1,
    495                 ctrl_info, 0, startq, value));
    496     } else if (BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    497         BCM_IF_ERROR_RETURN
    498             (soc_counter_generic_set(unit, ctr_reg_mc,
    499                 ctrl_info, 0, startq, value));
    500     } else if (BCM_GPORT_IS_SCHEDULER(port)) {
    501         BCM_IF_ERROR_RETURN(
    502             _bcm_th3_cosq_sched_node_child_get(unit, port, &num_uc, uc_q,
    503                 &num_mc, mc_q));
    504         if (num_uc > 2 || num_mc > 1) {
    505             return BCM_E_INTERNAL;
    506         }
    507         if (num_uc > 0) {
    508             for (loop_idx = 0; loop_idx < num_uc; loop_idx++) {
    509                 BCM_IF_ERROR_RETURN(
    510                     soc_counter_generic_set(unit, ctr_reg_uc0,
    511                                                  ctrl_info, 0,
    512                                                  uc_q[loop_idx],
    513                                                  value));
    514                 BCM_IF_ERROR_RETURN(
    515                     soc_counter_generic_set(unit, ctr_reg_uc1,
    516                                                  ctrl_info, 0,
    517                                                  uc_q[loop_idx],
    518                                                  value));
    519             }
    520         }
    521         if (num_mc > 0) {
    522             for (loop_idx = 0; loop_idx < num_mc; loop_idx++) {
    523                 if (ctr_reg_mc != INVALIDr) {
    524                     BCM_IF_ERROR_RETURN(
    525                         soc_counter_generic_set(unit, ctr_reg_mc,
    526                                                      ctrl_info, 0,
    527                                                      mc_q[loop_idx],
    528                                                      value));
    529                 }
    530 
    531             }
    532         }
    533     } else {
    534         BCM_IF_ERROR_RETURN
    535             (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    536         ctrl_info.instance = local_port;
    537         if (cosq == -1) {
    538             /* Get UC values for NON CPU port */
    539             if (!IS_CPU_PORT(unit, local_port)) {
    540                 for (ci = 0; ci < si->port_num_uc_cosq[local_port] ; ci++) {
    541                     BCM_IF_ERROR_RETURN
    542                         (soc_counter_generic_set(unit, ctr_reg_uc0,
    543                                                  ctrl_info, 0,
    544                                                  ci, value));
    545                     BCM_IF_ERROR_RETURN
    546                         (soc_counter_generic_set(unit, ctr_reg_uc1,
    547                                                  ctrl_info, 0,
    548                                                  ci, value));
    549                 }
    550             }
    551             for (ci = 0; ci < si->port_num_cosq[local_port] ; ci++) {
    552                 BCM_IF_ERROR_RETURN
    553                     (soc_counter_generic_set(unit, ctr_reg_mc,
    554                                   ctrl_info, 0, ci, value));
    555             }
    556         } else {
    557             if (cosq < si->port_num_uc_cosq[local_port]) {
    558                 /* If queue is unicast */
    559                 BCM_IF_ERROR_RETURN
    560                             (soc_counter_generic_set(unit, ctr_reg_uc0,
    561                                                      ctrl_info,
    562                                                0, cosq, value));
    563                 BCM_IF_ERROR_RETURN
    564                             (soc_counter_generic_set(unit, ctr_reg_uc1,
    565                                                      ctrl_info,
    566                                                0, cosq, value));
    567             } else {
    568                 /* Multicast queue */
    569                 ci = cosq - si->port_num_uc_cosq[local_port];
    570                 BCM_IF_ERROR_RETURN
    571                     (soc_counter_generic_set(unit, ctr_reg_mc,
    572                                              ctrl_info,
    573                                              0, ci, value));
    574             }
    575         }
    576     }
    577     return BCM_E_NONE;
    578 }
    579 
    580 STATIC int
    581 _bcm_th3_obm_port_counters_get(int unit, bcm_gport_t port, bcm_cos_queue_t cosq,
    582                      bcm_cosq_stat_t stat, uint64 *value, int sync) {
    583     soc_ctr_control_info_t ctrl_info;
    584     soc_reg_t ctr_reg;
    585     int local_port;
    586     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
    587         BCM_GPORT_IS_SCHEDULER(port) ||
    588         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    589         /* OBM port counters not supported at queue/scheduler level */
    590         return BCM_E_PARAM;
    591     }
    592     BCM_IF_ERROR_RETURN
    593         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    594     if ((stat == bcmCosqStatHighPriDroppedPackets) ||
    595         (stat == bcmCosqStatOBMLossyHighPriDroppedPackets)) {
    596         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_OBM_LOSSY_HI;
    597     } else if ((stat == bcmCosqStatLowPriDroppedPackets) ||
    598                (stat == bcmCosqStatOBMLossyLowPriDroppedPackets)) {
    599         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_OBM_LOSSY_LO;
    600     } else if ((stat == bcmCosqStatHighPriDroppedBytes) ||
    601                (stat == bcmCosqStatOBMLossyHighPriDroppedBytes)) {
    602         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_OBM_LOSSY_HI;
    603     } else if ((stat == bcmCosqStatLowPriDroppedBytes) ||
    604                (stat == bcmCosqStatOBMLossyLowPriDroppedBytes)) {
    605         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_OBM_LOSSY_LO;
    606     } else if (stat == bcmCosqStatOBMLossless0DroppedPackets) {
    607         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_OBM_LOSSLESS0;
    608     } else if (stat == bcmCosqStatOBMLossless1DroppedPackets) {
    609         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_OBM_LOSSLESS1;
    610     } else if (stat == bcmCosqStatOBMLossless0DroppedBytes) {
    611         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_OBM_LOSSLESS0;
    612     } else if (stat == bcmCosqStatOBMLossless1DroppedBytes) {
    613         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_OBM_LOSSLESS1;
    614     } else { /* (stat == bcmCosqStatOBMFlowControlEvents)  */
    615         ctr_reg = SOC_COUNTER_NON_DMA_PORT_OBM_FC_EVENTS;
    616     }
    617     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_PORT;
    618     ctrl_info.instance = local_port;
    619     /* Always pass sync mode 0 for OBM counters*/
    620     BCM_IF_ERROR_RETURN
    621         (soc_counter_generic_get(unit, ctr_reg, ctrl_info, 0,
    622                                  0, value));
    623     return BCM_E_NONE;
    624 }
    625 
    626 STATIC int
    627 _bcm_th3_obm_port_counters_set(int unit, bcm_gport_t port, bcm_cos_queue_t cosq,
    628                      bcm_cosq_stat_t stat, uint64 value) {
    629     soc_ctr_control_info_t ctrl_info;
    630     soc_reg_t ctr_reg;
    631     int local_port;
    632     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
    633         BCM_GPORT_IS_SCHEDULER(port) ||
    634         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    635         return BCM_E_PARAM;
    636     }
    637     BCM_IF_ERROR_RETURN
    638         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    639     if ((stat == bcmCosqStatHighPriDroppedPackets) ||
    640         (stat == bcmCosqStatOBMLossyHighPriDroppedPackets)) {
    641         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_OBM_LOSSY_HI;
    642     } else if ((stat == bcmCosqStatLowPriDroppedPackets) ||
    643                (stat == bcmCosqStatOBMLossyLowPriDroppedPackets)) {
    644         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_OBM_LOSSY_LO;
    645     } else if ((stat == bcmCosqStatHighPriDroppedBytes) ||
    646                (stat == bcmCosqStatOBMLossyHighPriDroppedBytes)) {
    647         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_OBM_LOSSY_HI;
    648     } else if ((stat == bcmCosqStatLowPriDroppedBytes) ||
    649                (stat == bcmCosqStatOBMLossyLowPriDroppedBytes)) {
    650         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_OBM_LOSSY_LO;
    651     } else if (stat == bcmCosqStatOBMLossless0DroppedPackets) {
    652         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_OBM_LOSSLESS0;
    653     } else if (stat == bcmCosqStatOBMLossless1DroppedPackets) {
    654         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_OBM_LOSSLESS1;
    655     } else if (stat == bcmCosqStatOBMLossless0DroppedBytes) {
    656         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_OBM_LOSSLESS0;
    657     } else if (stat == bcmCosqStatOBMLossless1DroppedBytes) {
    658         ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_BYTE_OBM_LOSSLESS1;
    659     } else { /* (stat == bcmCosqStatOBMFlowControlEvents)  */
    660         ctr_reg = SOC_COUNTER_NON_DMA_PORT_OBM_FC_EVENTS;
    661     }
    662     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_PORT;
    663     ctrl_info.instance = local_port;
    664     BCM_IF_ERROR_RETURN
    665         (soc_counter_generic_set(unit, ctr_reg, ctrl_info, 0,
    666                                  0, value));
    667     return BCM_E_NONE;
    668 }
    669 
    670 STATIC int
    671 _bcm_th3_cosq_mmu_port_queue_wred_color_drop_get(int unit, bcm_gport_t port,
    672         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync) {
    673     soc_ctr_control_info_t ctrl_info;
    674     int startq = 0, ci;
    675     bcm_port_t local_port = -1;
    676     uint64 sum, value64;
    677     soc_info_t *si = &SOC_INFO(unit);
    678     soc_reg_t ctr_reg;
    679 
    680     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
    681         BCM_GPORT_IS_SCHEDULER(port) ||
    682         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    683         return BCM_E_PARAM;
    684     }
    685     if (cosq != BCM_COS_INVALID) {
    686         return BCM_E_UNAVAIL;
    687     }
    688     BCM_IF_ERROR_RETURN
    689         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    690 
    691     ctrl_info.instance = local_port;
    692     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
    693     if (stat == bcmCosqStatGreenDiscardDroppedPackets) {
    694         /*Sum of complete WRED dropped - red WRED - yellow WRED*/
    695         COMPILER_64_ZERO(sum);
    696         for (ci = 0; ci < si->port_num_uc_cosq[local_port]; ci++) {
    697             BCM_IF_ERROR_RETURN
    698                 (soc_counter_generic_get(unit,
    699                  SOC_COUNTER_NON_DMA_COSQ_DROP_WRED_PKT, ctrl_info, sync,
    700                  ci, &value64));
    701             COMPILER_64_ADD_64(sum, value64);
    702         }
    703         BCM_IF_ERROR_RETURN
    704             (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_PORT_WRED_PKT_YELLOW,
    705                                  ctrl_info, sync, startq, &value64));
    706         COMPILER_64_SUB_64(sum, value64);
    707         BCM_IF_ERROR_RETURN
    708             (soc_counter_generic_get(unit, SOC_COUNTER_NON_DMA_PORT_WRED_PKT_RED,
    709                                  ctrl_info, sync, startq, &value64));
    710         COMPILER_64_SUB_64(sum, value64);
    711         *value = sum;
    712         return BCM_E_NONE;
    713     }
    714 
    715     if (stat == bcmCosqStatYellowDiscardDroppedPackets) {
    716         ctr_reg = SOC_COUNTER_NON_DMA_PORT_WRED_PKT_YELLOW;
    717     } else { /*(stat == bcmCosqStatRedDiscardDroppedPackets) */
    718         ctr_reg = SOC_COUNTER_NON_DMA_PORT_WRED_PKT_RED;
    719     }
    720 
    721     BCM_IF_ERROR_RETURN
    722         (soc_counter_generic_get(unit, ctr_reg, ctrl_info,
    723                                  sync, startq, value));
    724 
    725 
    726     return BCM_E_NONE;
    727 }
    728 
    729 STATIC int
    730 _bcm_th3_cosq_mmu_port_queue_wred_color_drop_set(int unit, bcm_gport_t port,
    731         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 value) {
    732     soc_ctr_control_info_t ctrl_info;
    733     int startq = 0;
    734     bcm_port_t local_port = -1;
    735     soc_reg_t ctr_reg;
    736 
    737     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
    738         BCM_GPORT_IS_SCHEDULER(port) ||
    739         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    740         return BCM_E_PARAM;
    741     }
    742     if (cosq != BCM_COS_INVALID) {
    743         return BCM_E_UNAVAIL;
    744     }
    745     if (stat == bcmCosqStatGreenDiscardDroppedPackets) {
    746         /* Green Discard drop is combination of complete drops and red/yellow
    747          * discard. All the elements can be set using other stat Enums */
    748         return BCM_E_UNAVAIL;
    749      }
    750     if (stat == bcmCosqStatYellowDiscardDroppedPackets) {
    751         ctr_reg = SOC_COUNTER_NON_DMA_PORT_WRED_PKT_YELLOW;
    752     } else { /*(stat == bcmCosqStatRedDiscardDroppedPackets) */
    753         ctr_reg = SOC_COUNTER_NON_DMA_PORT_WRED_PKT_RED;
    754     }
    755     BCM_IF_ERROR_RETURN
    756         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    757 
    758     ctrl_info.instance = local_port;
    759     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
    760     BCM_IF_ERROR_RETURN
    761         (soc_counter_generic_set(unit, ctr_reg, ctrl_info,
    762                                  0, startq, value));
    763 
    764     return BCM_E_NONE;
    765 }
    766 
    767 STATIC int
    768 _bcm_th3_cosq_mmu_port_queue_color_drop_get(int unit, bcm_gport_t port,
    769         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync) {
    770     soc_ctr_control_info_t ctrl_info;
    771     int startq = 0;
    772     bcm_port_t local_port = -1;
    773     uint64 sum, value64;
    774 
    775     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
    776         BCM_GPORT_IS_SCHEDULER(port) ||
    777         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    778         return BCM_E_PARAM;
    779     }
    780     if (cosq != BCM_COS_INVALID) {
    781         return BCM_E_UNAVAIL;
    782     }
    783     BCM_IF_ERROR_RETURN
    784         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    785 
    786     ctrl_info.instance = local_port;
    787     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
    788 
    789     if (stat == bcmCosqStatYellowCongestionDroppedPackets) {
    790         /*Sum of UC yellow drops and MC yellow drops*/
    791         COMPILER_64_ZERO(sum);
    792         /* MMU_THDO_PORT_DROP_COUNT_MCm.PORT_PACKET_YELLOW_DROPf */
    793         BCM_IF_ERROR_RETURN
    794             (soc_counter_generic_get(unit,
    795              SOC_COUNTER_NON_DMA_PORT_DROP_PKT_YELLOW, ctrl_info, sync,
    796              startq, &value64));
    797         COMPILER_64_ADD_64(sum, value64);
    798         /* MMU_THDO_PORT_DROP_COUNT_UCm.PORT_PACKET_YELLOW_DROPf */
    799         BCM_IF_ERROR_RETURN
    800             (soc_counter_generic_get(unit,
    801              SOC_COUNTER_NON_DMA_PORT_DROP_PKT_YELLOW_UC, ctrl_info, sync,
    802              startq, &value64));
    803         COMPILER_64_ADD_64(sum, value64);
    804 
    805         *value = sum;
    806     } else if (stat == bcmCosqStatRedCongestionDroppedPackets) {
    807         /*Sum of UC red drops and MC red drops*/
    808         COMPILER_64_ZERO(sum);
    809         /* MMU_THDO_PORT_DROP_COUNT_MCm.PORT_PACKET_RED_DROPf */
    810         BCM_IF_ERROR_RETURN
    811             (soc_counter_generic_get(unit,
    812              SOC_COUNTER_NON_DMA_PORT_DROP_PKT_RED, ctrl_info, sync,
    813              startq, &value64));
    814         COMPILER_64_ADD_64(sum, value64);
    815         /* MMU_THDO_PORT_DROP_COUNT_UCm.PORT_PACKET_RED_DROPf */
    816         BCM_IF_ERROR_RETURN
    817             (soc_counter_generic_get(unit,
    818              SOC_COUNTER_NON_DMA_PORT_DROP_PKT_RED_UC, ctrl_info, sync,
    819              startq, &value64));
    820         COMPILER_64_ADD_64(sum, value64);
    821         *value = sum;
    822     }
    823     return BCM_E_NONE;
    824 }
    825 
    826 STATIC int
    827 _bcm_th3_cosq_mmu_port_queue_color_drop_set(int unit, bcm_gport_t port,
    828         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 value) {
    829     soc_ctr_control_info_t ctrl_info;
    830     int startq = 0;
    831     bcm_port_t local_port = -1;
    832 
    833     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
    834         BCM_GPORT_IS_SCHEDULER(port) ||
    835         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    836         return BCM_E_PARAM;
    837     }
    838     if (cosq != BCM_COS_INVALID) {
    839         return BCM_E_UNAVAIL;
    840     }
    841     BCM_IF_ERROR_RETURN
    842         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    843 
    844     ctrl_info.instance = local_port;
    845     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
    846     if (stat == bcmCosqStatYellowCongestionDroppedPackets) {
    847         BCM_IF_ERROR_RETURN
    848         (soc_counter_generic_set(unit, SOC_COUNTER_NON_DMA_PORT_DROP_PKT_YELLOW,
    849                                  ctrl_info, 0, startq, value));
    850         BCM_IF_ERROR_RETURN
    851         (soc_counter_generic_set(unit,
    852                                  SOC_COUNTER_NON_DMA_PORT_DROP_PKT_YELLOW_UC,
    853                                  ctrl_info, 0, startq, value));
    854     } else if (stat == bcmCosqStatRedCongestionDroppedPackets) {
    855         BCM_IF_ERROR_RETURN
    856         (soc_counter_generic_set(unit, SOC_COUNTER_NON_DMA_PORT_DROP_PKT_RED,
    857                                  ctrl_info, 0, startq, value));
    858         BCM_IF_ERROR_RETURN
    859         (soc_counter_generic_set(unit, SOC_COUNTER_NON_DMA_PORT_DROP_PKT_RED_UC,
    860                                  ctrl_info, 0, startq, value));
    861 
    862     }
    863     return BCM_E_NONE;
    864 }
    865 
    866 STATIC int
    867 _bcm_th3_queue_current_usage_bytes_get(int unit, bcm_gport_t port,
    868         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync) {
    869     _bcm_th3_cosq_index_style_t style;
    870     bcm_port_t local_port = -1;
    871     soc_info_t *si = &SOC_INFO(unit);
    872     soc_mem_t mem = INVALIDm;
    873     int itm, chip_q_num;
    874     uint32 entry[SOC_MAX_MEM_WORDS];
    875     uint32 fld_value = 0, itm_map;
    876     uint64 val64;
    877     soc_field_t field;
    878 
    879     BCM_IF_ERROR_RETURN
    880         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    881     if ((cosq < 0) || (cosq >= TH3_PORT_NUM_COS(unit, local_port))) {
    882         return BCM_E_PARAM;
    883     }
    884 
    885     if (stat == bcmCosqStatEgressMCQueueBytesCurrent ||
    886         stat == bcmCosqStatEgressMCQueueMinBytesCurrent) {
    887         if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
    888             BCM_GPORT_IS_SCHEDULER(port)) {
    889             return BCM_E_PARAM;
    890         }
    891         style = _BCM_TH3_COSQ_INDEX_STYLE_MCAST_QUEUE;
    892     } else {
    893         /*(stat == bcmCosqStatEgressUCQueueBytesCurrent ||
    894          * stat == bcmCosqStatEgressUCQueueMinBytesCurrent)
    895          */
    896         if (BCM_GPORT_IS_MCAST_QUEUE_GROUP(port) ||
    897             BCM_GPORT_IS_SCHEDULER(port)) {
    898             return BCM_E_PARAM;
    899         }
    900         style = _BCM_TH3_COSQ_INDEX_STYLE_UCAST_QUEUE;
    901     }
    902 
    903     if (stat == bcmCosqStatEgressMCQueueBytesCurrent ||
    904         stat == bcmCosqStatEgressUCQueueBytesCurrent ) {
    905         field = TOTALCOUNTf;
    906     } else {
    907         /*Queue Min Bytes enums*/
    908         field = MIN_COUNTf;
    909     }
    910 
    911     BCM_IF_ERROR_RETURN
    912         (_bcm_th3_cosq_index_resolve
    913         (unit, port, cosq, style, &local_port, &chip_q_num, NULL));
    914 
    915     itm_map = si->itm_map;
    916     COMPILER_64_ZERO(val64);
    917     for (itm = 0; itm < NUM_ITM(unit); itm++) {
    918         if (itm_map & (1 << itm)) {
    919             mem = SOC_MEM_UNIQUE_ACC_ITM(unit, MMU_THDO_COUNTER_QUEUEm, itm);
    920             if (mem != INVALIDm) {
    921                 BCM_IF_ERROR_RETURN
    922                     (soc_mem_read(unit, mem, MEM_BLOCK_ALL, chip_q_num, entry));
    923                 fld_value = soc_mem_field32_get(unit, mem, entry, field);
    924                 COMPILER_64_ADD_32(val64, fld_value);
    925             }
    926         }
    927     }
    928     *value = val64;
    929     return BCM_E_NONE;
    930 }
    931 
    932 STATIC int
    933 _bcm_th3_pg_current_usage_bytes_get(int unit, bcm_gport_t port,
    934         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync) {
    935     bcm_port_t local_port = -1;
    936     uint32 entry[SOC_MAX_MEM_WORDS];
    937     soc_mem_t mem = INVALIDm;
    938     soc_field_t field = INVALIDf;
    939     soc_field_t fld_pg_min[_TH3_MMU_NUM_PG] = {PG0_MIN_COUNTf, PG1_MIN_COUNTf,
    940         PG2_MIN_COUNTf, PG3_MIN_COUNTf, PG4_MIN_COUNTf, PG5_MIN_COUNTf,
    941         PG6_MIN_COUNTf, PG7_MIN_COUNTf};
    942     soc_field_t fld_pg_shr[_TH3_MMU_NUM_PG] = {PG0_SHARED_COUNTf, PG1_SHARED_COUNTf,
    943         PG2_SHARED_COUNTf, PG3_SHARED_COUNTf, PG4_SHARED_COUNTf, PG5_SHARED_COUNTf,
    944         PG6_SHARED_COUNTf, PG7_SHARED_COUNTf};
    945     soc_field_t fld_pg_hdrm[_TH3_MMU_NUM_PG] = {PG0_HDRM_COUNTf, PG1_HDRM_COUNTf,
    946         PG2_HDRM_COUNTf, PG3_HDRM_COUNTf, PG4_HDRM_COUNTf, PG5_HDRM_COUNTf,
    947         PG6_HDRM_COUNTf, PG7_HDRM_COUNTf};
    948     int mmu_local_port, pipe;
    949     uint32 fld_value;
    950 
    951 
    952     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
    953         BCM_GPORT_IS_SCHEDULER(port) ||
    954         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
    955         return BCM_E_PARAM;
    956     }
    957     if ((cosq < 0) || (cosq >= _TH3_MMU_NUM_PG)) {
    958         return BCM_E_PARAM;
    959     }
    960     BCM_IF_ERROR_RETURN
    961         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
    962     mmu_local_port = SOC_TH3_MMU_LOCAL_PORT(unit, local_port);
    963 
    964     BCM_IF_ERROR_RETURN(soc_port_pipe_get(unit, local_port, &pipe));
    965     if (stat == bcmCosqStatIngressPortPGMinBytesCurrent) {
    966         mem = SOC_MEM_UNIQUE_ACC_PIPE(unit, MMU_THDI_PORT_PG_MIN_COUNTERm,
    967                 pipe);
    968         field = fld_pg_min[cosq];
    969     } else if (stat == bcmCosqStatIngressPortPGSharedBytesCurrent) {
    970         mem = SOC_MEM_UNIQUE_ACC_PIPE(unit, MMU_THDI_PORT_PG_SHARED_COUNTERm,
    971                 pipe);
    972         field = fld_pg_shr[cosq];
    973     } else {/* (stat == bcmCosqStatIngressPortPGHeadroomBytesCurrent) */
    974         mem = SOC_MEM_UNIQUE_ACC_PIPE(unit, MMU_THDI_PORT_PG_HDRM_COUNTERm,
    975                 pipe);
    976         field = fld_pg_hdrm[cosq];
    977     }
    978 
    979     BCM_IF_ERROR_RETURN
    980         (soc_mem_read(unit, mem, MEM_BLOCK_ALL, mmu_local_port, entry));
    981     fld_value = soc_mem_field32_get(unit, mem, entry, field);
    982     COMPILER_64_SET(*value, 0x0, fld_value);
    983 
    984     return BCM_E_NONE;
    985 }
    986 
    987 
    988 STATIC int
    989 _bcm_th3_sp_current_usage_bytes_get(int unit, bcm_gport_t port,
    990         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync) {
    991     bcm_port_t local_port = -1;
    992     int pool = -1;
    993     soc_field_t sp_shr[_TH3_MMU_NUM_POOL] = {PORTSP0_SHARED_COUNTf,
    994         PORTSP1_SHARED_COUNTf, PORTSP2_SHARED_COUNTf, PORTSP3_SHARED_COUNTf};
    995     uint32 entry[SOC_MAX_MEM_WORDS];
    996     soc_mem_t mem = INVALIDm;
    997     int pipe, mmu_local_port;
    998     uint32 fld_value;
    999 
   1000     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1001         BCM_GPORT_IS_SCHEDULER(port) ||
   1002         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1003         return BCM_E_PARAM;
   1004     }
   1005     if ((cosq < 0) || (cosq >= _TH3_MMU_NUM_PG)) {
   1006         return BCM_E_PARAM;
   1007     }
   1008     BCM_IF_ERROR_RETURN
   1009         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
   1010     BCM_IF_ERROR_RETURN(soc_port_pipe_get(unit, local_port, &pipe));
   1011     mmu_local_port = SOC_TH3_MMU_LOCAL_PORT(unit, local_port);
   1012 
   1013     /* Retrieve Ing service pool mapped to {port, PG}*/
   1014     _bcm_th3_cosq_ingress_sp_get_by_pg(unit, port, cosq, &pool);
   1015     if (pool == -1) {
   1016         return BCM_E_INTERNAL;
   1017     }
   1018     mem = SOC_MEM_UNIQUE_ACC_PIPE(unit, MMU_THDI_PORTSP_COUNTERm, pipe);
   1019     BCM_IF_ERROR_RETURN
   1020         (soc_mem_read(unit, mem, MEM_BLOCK_ALL, mmu_local_port, entry));
   1021     fld_value = soc_mem_field32_get(unit, mem, entry, sp_shr[pool]);
   1022     COMPILER_64_SET(*value, 0x0, fld_value);
   1023 
   1024     return BCM_E_NONE;
   1025 }
   1026 
   1027 STATIC int
   1028 _bcm_th3_cosq_obmhighwatermark_set(int unit, bcm_port_t port, uint64 value)
   1029 {
   1030     int pipe, obm_id, subp, pport, reg_id;
   1031     soc_reg_t reg;
   1032     uint64 rval64;
   1033     soc_info_t *si = &SOC_INFO(unit);
   1034     soc_reg_t obm_high_watermark_reg[_TH3_PBLKS_PER_PIPE][3] = {
   1035         {IDB_OBM0_MAX_USAGEr, IDB_OBM0_MAX_USAGE_1r, IDB_OBM0_MAX_USAGE_2r},
   1036         {IDB_OBM1_MAX_USAGEr, IDB_OBM1_MAX_USAGE_1r, IDB_OBM1_MAX_USAGE_2r},
   1037         {IDB_OBM2_MAX_USAGEr, IDB_OBM2_MAX_USAGE_1r, IDB_OBM2_MAX_USAGE_2r},
   1038         {IDB_OBM3_MAX_USAGEr, IDB_OBM3_MAX_USAGE_1r, IDB_OBM3_MAX_USAGE_2r},
   1039     };
   1040 
   1041     soc_field_t obm_high_watermark_fields[] = {
   1042         PORT0_MAX_USAGEf, PORT1_MAX_USAGEf,
   1043         PORT2_MAX_USAGEf, PORT3_MAX_USAGEf,
   1044         PORT4_MAX_USAGEf, PORT5_MAX_USAGEf,
   1045         PORT6_MAX_USAGEf, PORT7_MAX_USAGEf
   1046     };
   1047     pport = si->port_l2p_mapping[port];
   1048     obm_id = soc_tomahawk3_get_pipe_pm_from_phy_port(pport);
   1049     subp = soc_tomahawk3_get_subp_from_phy_port(pport);
   1050     reg_id = subp / 3; /*upto 3 subports in each of usage, usage_1 and usage_2
   1051                          regs*/
   1052     if (obm_id >= _TH3_PBLKS_PER_PIPE || (subp < 0 || subp >= _TH3_PORTS_PER_PBLK)) {
   1053             return BCM_E_PARAM;
   1054     }
   1055     if(!COMPILER_64_IS_ZERO(value)) {
   1056         return BCM_E_PARAM;
   1057     }
   1058     pipe = si->port_pipe[port];
   1059 
   1060     reg = SOC_REG_UNIQUE_ACC(unit, obm_high_watermark_reg[obm_id][reg_id])[pipe];
   1061     COMPILER_64_ZERO(rval64);
   1062     BCM_IF_ERROR_RETURN
   1063             (soc_reg64_get(unit, reg, REG_PORT_ANY, 0, &rval64));
   1064 
   1065     soc_reg64_field32_set(unit, reg, &rval64, obm_high_watermark_fields[subp], 0);
   1066     BCM_IF_ERROR_RETURN
   1067             (soc_reg64_set(unit, reg, REG_PORT_ANY, 0, rval64));
   1068     return BCM_E_NONE;
   1069 }
   1070 
   1071 STATIC int
   1072 _bcm_th3_cosq_obmhighwatermark_get(int unit, bcm_port_t port, uint64 *value)
   1073 {
   1074     int pipe, obm_id, subp, pport, reg_id;
   1075     soc_reg_t reg;
   1076     uint64 rval64;
   1077     soc_info_t *si = &SOC_INFO(unit);
   1078     soc_reg_t obm_high_watermark_reg[_TH3_PBLKS_PER_PIPE][3] = {
   1079         {IDB_OBM0_MAX_USAGEr, IDB_OBM0_MAX_USAGE_1r, IDB_OBM0_MAX_USAGE_2r},
   1080         {IDB_OBM1_MAX_USAGEr, IDB_OBM1_MAX_USAGE_1r, IDB_OBM1_MAX_USAGE_2r},
   1081         {IDB_OBM2_MAX_USAGEr, IDB_OBM2_MAX_USAGE_1r, IDB_OBM2_MAX_USAGE_2r},
   1082         {IDB_OBM3_MAX_USAGEr, IDB_OBM3_MAX_USAGE_1r, IDB_OBM3_MAX_USAGE_2r},
   1083     };
   1084 
   1085     soc_field_t obm_high_watermark_fields[] = {
   1086         PORT0_MAX_USAGEf, PORT1_MAX_USAGEf,
   1087         PORT2_MAX_USAGEf, PORT3_MAX_USAGEf,
   1088         PORT4_MAX_USAGEf, PORT5_MAX_USAGEf,
   1089         PORT6_MAX_USAGEf, PORT7_MAX_USAGEf
   1090     };
   1091     pport = si->port_l2p_mapping[port];
   1092     obm_id = soc_tomahawk3_get_pipe_pm_from_phy_port(pport);
   1093     subp = soc_tomahawk3_get_subp_from_phy_port(pport);
   1094     reg_id = subp / 3; /*upto 3 subports in each of usage, usage_1 and usage_2
   1095                          regs*/
   1096     if (obm_id >= _TH3_PBLKS_PER_PIPE || (subp < 0 || subp >= _TH3_PORTS_PER_PBLK)) {
   1097             return BCM_E_PARAM;
   1098     }
   1099     pipe = si->port_pipe[port];
   1100 
   1101     reg = SOC_REG_UNIQUE_ACC(unit, obm_high_watermark_reg[obm_id][reg_id])[pipe];
   1102     COMPILER_64_ZERO(rval64);
   1103     BCM_IF_ERROR_RETURN
   1104             (soc_reg64_get(unit, reg, REG_PORT_ANY, 0, &rval64));
   1105 
   1106     *value = soc_reg64_field_get(unit, reg, rval64,
   1107             obm_high_watermark_fields[subp]);
   1108     return BCM_E_NONE;
   1109 }
   1110 
   1111 STATIC int
   1112 _bcm_th3_cosq_obm_buf_use_cnt_get(int unit, bcm_port_t port, bcm_cos_queue_t
   1113         cosq, bcm_cosq_stat_t stat, uint64 *value)
   1114 {
   1115     int pipe, obm_id, subp, pport;
   1116     soc_reg_t reg;
   1117     soc_field_t fld;
   1118     uint64 rval64;
   1119     soc_info_t *si = &SOC_INFO(unit);
   1120     soc_reg_t obm_usage_reg_1[_TH3_PBLKS_PER_PIPE] = {
   1121             IDB_OBM0_USAGE_1r, IDB_OBM1_USAGE_1r,
   1122             IDB_OBM2_USAGE_1r, IDB_OBM3_USAGE_1r,
   1123     };
   1124     soc_reg_t obm_usage_reg[_TH3_PBLKS_PER_PIPE] = {
   1125             IDB_OBM0_USAGEr, IDB_OBM1_USAGEr,
   1126             IDB_OBM2_USAGEr, IDB_OBM3_USAGEr,
   1127     };
   1128     bcm_port_t local_port = -1;
   1129 
   1130     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1131         BCM_GPORT_IS_SCHEDULER(port) ||
   1132         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1133         return BCM_E_PARAM;
   1134     }
   1135     BCM_IF_ERROR_RETURN
   1136         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
   1137 
   1138     pport = si->port_l2p_mapping[local_port];
   1139     obm_id = soc_tomahawk3_get_pipe_pm_from_phy_port(pport);
   1140     subp = soc_tomahawk3_get_subp_from_phy_port(pport);
   1141     if (obm_id >= _TH3_PBLKS_PER_PIPE || (subp < 0 || subp >= _TH3_PORTS_PER_PBLK)) {
   1142         return BCM_E_PARAM;
   1143     }
   1144     pipe = si->port_pipe[local_port];
   1145 
   1146     if (stat == bcmCosqStatOBMBufferBytes) {
   1147         reg = SOC_REG_UNIQUE_ACC(unit, obm_usage_reg_1[obm_id])[pipe];
   1148         fld = TOTAL_COUNTf;
   1149     } else if (stat == bcmCosqStatOBMLossless1BufferBytes) {
   1150         reg = SOC_REG_UNIQUE_ACC(unit, obm_usage_reg_1[obm_id])[pipe];
   1151         fld = LOSSLESS1_COUNTf;
   1152     } else if (stat == bcmCosqStatOBMLossless0BufferBytes) {
   1153         reg = SOC_REG_UNIQUE_ACC(unit, obm_usage_reg[obm_id])[pipe];
   1154         fld = LOSSLESS0_COUNTf;
   1155     } else { /* (stat == bcmCosqStatOBMLossyBufferBytes) */
   1156         reg = SOC_REG_UNIQUE_ACC(unit, obm_usage_reg[obm_id])[pipe];
   1157         fld = LOSSY_COUNTf;
   1158     }
   1159 
   1160     COMPILER_64_ZERO(rval64);
   1161     BCM_IF_ERROR_RETURN
   1162             (soc_reg64_get(unit, reg, REG_PORT_ANY, subp, &rval64));
   1163 
   1164     *value = soc_reg64_field_get(unit, reg, rval64, fld);
   1165     return BCM_E_NONE;
   1166 }
   1167 
   1168 STATIC int
   1169 _bcm_th3_rqe_drop_counters_set(int unit, bcm_gport_t port,
   1170         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 value) {
   1171     soc_ctr_control_info_t ctrl_info;
   1172     soc_reg_t ctr_reg;
   1173     uint16 dev_id;
   1174     uint8 rev_id;
   1175 
   1176     soc_cm_get_id(unit, &dev_id, &rev_id);
   1177 
   1178     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
   1179     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1180         BCM_GPORT_IS_SCHEDULER(port) ||
   1181         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1182         return BCM_E_PARAM;
   1183     }
   1184     if ((cosq < 0) || (cosq >= _TH3_MMU_NUM_RQE_QUEUES)) {
   1185         return BCM_E_PARAM;
   1186     }
   1187     if (stat == bcmCosqStatRQEGreenDroppedPackets) {
   1188         /*Combnation of other stats*/
   1189         return BCM_E_UNAVAIL;
   1190     }
   1191     if (stat == bcmCosqStatRQETotalDroppedPackets) {
   1192         ctr_reg = SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT;
   1193     } else if (stat == bcmCosqStatRQETotalDroppedBytes) {
   1194         ctr_reg = SOC_COUNTER_NON_DMA_PRIQ_DROP_BYTE;
   1195     } else if (stat == bcmCosqStatRQERedDroppedPackets) {
   1196         ctr_reg = SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT_RED;
   1197     } else { /*(stat == bcmCosqStatRQEYellowDroppedPackets) */
   1198         ctr_reg = SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT_YELLOW;
   1199     }
   1200     ctrl_info.instance = 0;
   1201     BCM_IF_ERROR_RETURN
   1202         (soc_counter_generic_set(unit, ctr_reg,
   1203                                  ctrl_info, 0, cosq, value));
   1204 
   1205     return BCM_E_NONE;
   1206 }
   1207 
   1208 STATIC int
   1209 _bcm_th3_rqe_drop_counters_get(int unit, bcm_gport_t port,
   1210         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync) {
   1211     soc_ctr_control_info_t ctrl_info;
   1212     soc_reg_t ctr_reg;
   1213     uint64 sum, value64;
   1214     uint16 dev_id;
   1215     uint8 rev_id;
   1216 
   1217     soc_cm_get_id(unit, &dev_id, &rev_id);
   1218 
   1219     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
   1220     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1221         BCM_GPORT_IS_SCHEDULER(port) ||
   1222         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1223         return BCM_E_PARAM;
   1224     }
   1225     if ((cosq < 0) || (cosq >= _TH3_MMU_NUM_RQE_QUEUES)) {
   1226         return BCM_E_PARAM;
   1227     }
   1228     ctrl_info.instance = 0;
   1229     if (stat == bcmCosqStatRQEGreenDroppedPackets) {
   1230         COMPILER_64_ZERO(sum);
   1231         BCM_IF_ERROR_RETURN
   1232             (soc_counter_generic_get(unit,
   1233              SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT, ctrl_info, sync,
   1234              cosq, &value64));
   1235         COMPILER_64_ADD_64(sum, value64);
   1236         BCM_IF_ERROR_RETURN
   1237             (soc_counter_generic_get(unit,
   1238              SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT_YELLOW, ctrl_info, sync,
   1239              cosq, &value64));
   1240         COMPILER_64_SUB_64(sum, value64);
   1241         BCM_IF_ERROR_RETURN
   1242             (soc_counter_generic_get(unit,
   1243              SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT_RED, ctrl_info, sync,
   1244              cosq, &value64));
   1245         COMPILER_64_SUB_64(sum, value64);
   1246         *value = sum;
   1247         return BCM_E_NONE;
   1248     }
   1249     if (stat == bcmCosqStatRQETotalDroppedPackets) {
   1250         ctr_reg = SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT;
   1251     } else if (stat == bcmCosqStatRQETotalDroppedBytes) {
   1252         ctr_reg = SOC_COUNTER_NON_DMA_PRIQ_DROP_BYTE;
   1253     } else if (stat == bcmCosqStatRQERedDroppedPackets) {
   1254         ctr_reg = SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT_RED;
   1255     } else { /* (stat == bcmCosqStatRQEYellowDroppedPackets) */
   1256         ctr_reg = SOC_COUNTER_NON_DMA_PRIQ_DROP_PKT_YELLOW;
   1257     }
   1258     BCM_IF_ERROR_RETURN
   1259         (soc_counter_generic_get(unit, ctr_reg,
   1260                          ctrl_info, sync, cosq, value));
   1261 
   1262     return BCM_E_NONE;
   1263 }
   1264 
   1265 STATIC int
   1266 _bcm_th3_hp_drop_counter_set(int unit, bcm_gport_t port,
   1267         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 value) {
   1268     soc_ctr_control_info_t ctrl_info;
   1269     soc_reg_t ctr_reg;
   1270     int pool = -1;
   1271 
   1272     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
   1273     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1274         BCM_GPORT_IS_SCHEDULER(port) ||
   1275         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1276         return BCM_E_PARAM;
   1277     }
   1278     if ((cosq < 0) || (cosq >= _TH3_MMU_NUM_PG)) {
   1279         return BCM_E_PARAM;
   1280     }
   1281 
   1282     /* Retrieve headroom pool mapped to input {port, PG}*/
   1283     _bcm_th3_cosq_ingress_hdrm_pool_get_by_pg(unit, port, cosq, &pool);
   1284     if (pool == -1) {
   1285         return BCM_E_INTERNAL;
   1286     }
   1287     ctr_reg = SOC_COUNTER_NON_DMA_HDRM_POOL_DROP_PKT;
   1288     ctrl_info.instance = 0;
   1289     BCM_IF_ERROR_RETURN
   1290         (soc_counter_generic_set(unit, ctr_reg,
   1291                          ctrl_info, 0, pool, value));
   1292 
   1293     return BCM_E_NONE;
   1294 }
   1295 
   1296 STATIC int
   1297 _bcm_th3_hp_drop_counter_get(int unit, bcm_gport_t port,
   1298         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync) {
   1299     soc_ctr_control_info_t ctrl_info;
   1300     soc_reg_t ctr_reg;
   1301     int pool = -1;
   1302 
   1303     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_ITM;
   1304     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1305         BCM_GPORT_IS_SCHEDULER(port) ||
   1306         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1307         return BCM_E_PARAM;
   1308     }
   1309     if ((cosq < 0) || (cosq >= _TH3_MMU_NUM_PG)) {
   1310         return BCM_E_PARAM;
   1311     }
   1312 
   1313     /* Retrieve headroom pool mapped to input {port, PG}*/
   1314     _bcm_th3_cosq_ingress_hdrm_pool_get_by_pg(unit, port, cosq, &pool);
   1315     if (pool == -1) {
   1316         return BCM_E_INTERNAL;
   1317     }
   1318     ctr_reg = SOC_COUNTER_NON_DMA_HDRM_POOL_DROP_PKT;
   1319     ctrl_info.instance = 0;
   1320     BCM_IF_ERROR_RETURN
   1321         (soc_counter_generic_get(unit, ctr_reg,
   1322                          ctrl_info, sync, pool, value));
   1323 
   1324     return BCM_E_NONE;
   1325 }
   1326 
   1327 STATIC int
   1328 _bcm_th3_ing_port_drop_counters_get(int unit, bcm_gport_t port,
   1329         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 *value, int sync) {
   1330     soc_ctr_control_info_t ctrl_info;
   1331     soc_reg_t ctr_reg;
   1332     bcm_port_t local_port = -1;
   1333 
   1334     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1335         BCM_GPORT_IS_SCHEDULER(port) ||
   1336         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1337         return BCM_E_PARAM;
   1338     }
   1339     if (cosq != BCM_COS_INVALID) {
   1340         return BCM_E_UNAVAIL;
   1341     }
   1342     BCM_IF_ERROR_RETURN
   1343         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
   1344 
   1345     ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_ING;
   1346     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_PORT;
   1347     ctrl_info.instance = local_port;
   1348 
   1349     BCM_IF_ERROR_RETURN
   1350         (soc_counter_generic_get(unit, ctr_reg,
   1351                          ctrl_info, sync, cosq, value));
   1352 
   1353     return BCM_E_NONE;
   1354 }
   1355 
   1356 STATIC int
   1357 _bcm_th3_ing_port_drop_counters_set(int unit, bcm_gport_t port,
   1358         bcm_cos_queue_t cosq, bcm_cosq_stat_t stat, uint64 value) {
   1359     soc_ctr_control_info_t ctrl_info;
   1360     soc_reg_t ctr_reg;
   1361     bcm_port_t local_port = -1;
   1362 
   1363     if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1364         BCM_GPORT_IS_SCHEDULER(port) ||
   1365         BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1366         return BCM_E_PARAM;
   1367     }
   1368     if (cosq != BCM_COS_INVALID) {
   1369         return BCM_E_UNAVAIL;
   1370     }
   1371     BCM_IF_ERROR_RETURN
   1372         (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
   1373 
   1374     ctr_reg = SOC_COUNTER_NON_DMA_PORT_DROP_PKT_ING;
   1375     ctrl_info.instance_type = SOC_CTR_INSTANCE_TYPE_PORT;
   1376     ctrl_info.instance = local_port;
   1377 
   1378     BCM_IF_ERROR_RETURN
   1379         (soc_counter_generic_set(unit, ctr_reg,
   1380                          ctrl_info, 0, cosq, value));
   1381 
   1382     return BCM_E_NONE;
   1383 }
   1384 
   1385 int
   1386 bcm_th3_cosq_stat_set(int unit, bcm_gport_t port, bcm_cos_queue_t cosq,
   1387                      bcm_cosq_stat_t stat, uint64 value)
   1388 {
   1389     bcm_port_t local_port = -1;
   1390     switch (stat) {
   1391         case bcmCosqStatOutPackets:
   1392         case bcmCosqStatOutBytes:
   1393         case bcmCosqStatDroppedBytes:
   1394         case bcmCosqStatEgressCongestionDroppedPackets:
   1395             return _bcm_th3_cosq_mmu_port_queue_counters_set(unit, port,
   1396                     cosq, stat, value);
   1397         case bcmCosqStatUCOutPackets:
   1398         case bcmCosqStatUCOutBytes:
   1399             if (BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1400                 return BCM_E_PARAM;
   1401             }
   1402             return _bcm_th3_cosq_mmu_port_queue_counters_set(unit, port,
   1403                     cosq, stat, value);
   1404         case bcmCosqStatMCOutPackets:
   1405         case bcmCosqStatMCOutBytes:
   1406             if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port)) {
   1407                 return BCM_E_PARAM;
   1408             }
   1409             return _bcm_th3_cosq_mmu_port_queue_counters_set(unit, port,
   1410                     cosq, stat, value);
   1411         case bcmCosqStatDroppedPackets:
   1412             return _bcm_th3_cosq_mmu_port_queue_total_drop_counters_set(unit,
   1413                     port, cosq, stat, value);
   1414         case bcmCosqStatYellowDiscardDroppedPackets:
   1415         case bcmCosqStatRedDiscardDroppedPackets:
   1416         case bcmCosqStatGreenDiscardDroppedPackets:
   1417             return  _bcm_th3_cosq_mmu_port_queue_wred_color_drop_set(unit, port,
   1418                 cosq, stat, value);
   1419         case bcmCosqStatYellowCongestionDroppedPackets:
   1420         case bcmCosqStatRedCongestionDroppedPackets:
   1421             return  _bcm_th3_cosq_mmu_port_queue_color_drop_set(unit, port,
   1422                 cosq, stat, value);
   1423         case bcmCosqStatHighPriDroppedPackets:
   1424         case bcmCosqStatOBMLossyHighPriDroppedPackets:
   1425         case bcmCosqStatLowPriDroppedPackets:
   1426         case bcmCosqStatOBMLossyLowPriDroppedPackets:
   1427         case bcmCosqStatHighPriDroppedBytes:
   1428         case bcmCosqStatOBMLossyHighPriDroppedBytes:
   1429         case bcmCosqStatLowPriDroppedBytes:
   1430         case bcmCosqStatOBMLossyLowPriDroppedBytes:
   1431         case bcmCosqStatOBMLossless0DroppedPackets:
   1432         case bcmCosqStatOBMLossless1DroppedPackets:
   1433         case bcmCosqStatOBMLossless0DroppedBytes:
   1434         case bcmCosqStatOBMLossless1DroppedBytes:
   1435         case bcmCosqStatOBMFlowControlEvents:
   1436             return _bcm_th3_obm_port_counters_set(unit, port, cosq, stat, value);
   1437         case bcmCosqStatOBMHighWatermark:
   1438             if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1439                 BCM_GPORT_IS_SCHEDULER(port) ||
   1440                 BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1441                 return BCM_E_PARAM;
   1442             }
   1443             BCM_IF_ERROR_RETURN
   1444                 (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
   1445             BCM_IF_ERROR_RETURN
   1446                 (_bcm_th3_cosq_obmhighwatermark_set(unit, local_port, value));
   1447             return BCM_E_NONE;
   1448         case bcmCosqStatHdrmPoolDroppedPackets:
   1449             return _bcm_th3_hp_drop_counter_set(unit, port, cosq, stat,
   1450                     value);
   1451         case bcmCosqStatSourcePortDroppedPackets:
   1452             return _bcm_th3_ing_port_drop_counters_set(unit, port, cosq, stat,
   1453                     value);
   1454         case bcmCosqStatRQETotalDroppedPackets:
   1455         case bcmCosqStatRQETotalDroppedBytes:
   1456         case bcmCosqStatRQEGreenDroppedPackets:
   1457         case bcmCosqStatRQEYellowDroppedPackets:
   1458         case bcmCosqStatRQERedDroppedPackets:
   1459             return _bcm_th3_rqe_drop_counters_set(unit, port,
   1460                     cosq, stat, value);
   1461         default:
   1462             return BCM_E_PARAM;
   1463     }
   1464     return BCM_E_NONE;
   1465 
   1466 }
   1467 
   1468 int
   1469 bcm_th3_cosq_stat_get(int unit, bcm_gport_t port, bcm_cos_queue_t cosq,
   1470                      bcm_cosq_stat_t stat, int sync_mode, uint64 *value)
   1471 {
   1472 
   1473     int sync = sync_mode ? SOC_COUNTER_SYNC_ENABLE : 0;
   1474     bcm_port_t local_port = -1;
   1475     uint64 cell_value;
   1476     COMPILER_64_ZERO(cell_value);
   1477     switch (stat) {
   1478         case bcmCosqStatOutPackets:
   1479         case bcmCosqStatOutBytes:
   1480         case bcmCosqStatDroppedBytes:
   1481         case bcmCosqStatEgressCongestionDroppedPackets:
   1482             return _bcm_th3_cosq_mmu_port_queue_counters_get(unit, port,
   1483                     cosq, stat, value, sync);
   1484         case bcmCosqStatUCOutPackets:
   1485         case bcmCosqStatUCOutBytes:
   1486             if (BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1487                 return BCM_E_PARAM;
   1488             }
   1489             return _bcm_th3_cosq_mmu_port_queue_counters_get(unit, port,
   1490                     cosq, stat, value, sync);
   1491         case bcmCosqStatMCOutPackets:
   1492         case bcmCosqStatMCOutBytes:
   1493             if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port)) {
   1494                 return BCM_E_PARAM;
   1495             }
   1496             return _bcm_th3_cosq_mmu_port_queue_counters_get(unit, port,
   1497                     cosq, stat, value, sync);
   1498         case bcmCosqStatDroppedPackets:
   1499             return _bcm_th3_cosq_mmu_port_queue_total_drop_counters_get(unit, port,
   1500                 cosq, stat, value, sync);
   1501         case bcmCosqStatYellowDiscardDroppedPackets:
   1502         case bcmCosqStatRedDiscardDroppedPackets:
   1503         case bcmCosqStatGreenDiscardDroppedPackets:
   1504             return _bcm_th3_cosq_mmu_port_queue_wred_color_drop_get(unit, port,
   1505                 cosq, stat, value, sync);
   1506         case bcmCosqStatYellowCongestionDroppedPackets:
   1507         case bcmCosqStatRedCongestionDroppedPackets:
   1508             return _bcm_th3_cosq_mmu_port_queue_color_drop_get(unit, port,
   1509                 cosq, stat, value, sync);
   1510         case bcmCosqStatEgressUCQueueBytesCurrent:
   1511         case bcmCosqStatEgressMCQueueBytesCurrent:
   1512         case bcmCosqStatEgressMCQueueMinBytesCurrent:
   1513         case bcmCosqStatEgressUCQueueMinBytesCurrent:
   1514             BCM_IF_ERROR_RETURN
   1515                 (_bcm_th3_queue_current_usage_bytes_get(unit, port,
   1516                     cosq, stat, &cell_value, sync));
   1517             /*value = *cell_value * _TH3_MMU_BYTES_PER_CELL;*/
   1518             COMPILER_64_ZERO(*value);
   1519             COMPILER_64_ADD_64(*value, cell_value);
   1520             COMPILER_64_UMUL_32(*value, _TH3_MMU_BYTES_PER_CELL);
   1521             return BCM_E_NONE;
   1522         case bcmCosqStatIngressPortPGMinBytesCurrent:
   1523         case bcmCosqStatIngressPortPGSharedBytesCurrent:
   1524         case bcmCosqStatIngressPortPGHeadroomBytesCurrent:
   1525             BCM_IF_ERROR_RETURN
   1526                 (_bcm_th3_pg_current_usage_bytes_get(unit, port,
   1527                     cosq, stat, &cell_value, sync));
   1528             /*value = *cell_value * _TH3_MMU_BYTES_PER_CELL;*/
   1529             COMPILER_64_ZERO(*value);
   1530             COMPILER_64_ADD_64(*value, cell_value);
   1531             COMPILER_64_UMUL_32(*value, _TH3_MMU_BYTES_PER_CELL);
   1532             return BCM_E_NONE;
   1533         case bcmCosqStatIngressPortPoolSharedBytesCurrent:
   1534             BCM_IF_ERROR_RETURN
   1535                 (_bcm_th3_sp_current_usage_bytes_get(unit, port,
   1536                     cosq, stat, &cell_value, sync));
   1537             /*value = *cell_value * _TH3_MMU_BYTES_PER_CELL;*/
   1538             COMPILER_64_ZERO(*value);
   1539             COMPILER_64_ADD_64(*value, cell_value);
   1540             COMPILER_64_UMUL_32(*value, _TH3_MMU_BYTES_PER_CELL);
   1541             return BCM_E_NONE;
   1542         case bcmCosqStatHighPriDroppedPackets:
   1543         case bcmCosqStatOBMLossyHighPriDroppedPackets:
   1544         case bcmCosqStatLowPriDroppedPackets:
   1545         case bcmCosqStatOBMLossyLowPriDroppedPackets:
   1546         case bcmCosqStatHighPriDroppedBytes:
   1547         case bcmCosqStatOBMLossyHighPriDroppedBytes:
   1548         case bcmCosqStatLowPriDroppedBytes:
   1549         case bcmCosqStatOBMLossyLowPriDroppedBytes:
   1550         case bcmCosqStatOBMLossless0DroppedPackets:
   1551         case bcmCosqStatOBMLossless1DroppedPackets:
   1552         case bcmCosqStatOBMLossless0DroppedBytes:
   1553         case bcmCosqStatOBMLossless1DroppedBytes:
   1554         case bcmCosqStatOBMFlowControlEvents:
   1555             return _bcm_th3_obm_port_counters_get(unit, port, cosq, stat,
   1556                     value, sync);
   1557         case bcmCosqStatOBMHighWatermark:
   1558             if (BCM_GPORT_IS_UCAST_QUEUE_GROUP(port) ||
   1559                 BCM_GPORT_IS_SCHEDULER(port) ||
   1560                 BCM_GPORT_IS_MCAST_QUEUE_GROUP(port)) {
   1561                 return BCM_E_PARAM;
   1562             }
   1563             BCM_IF_ERROR_RETURN
   1564                 (_bcm_th3_cosq_localport_resolve(unit, port, &local_port));
   1565             BCM_IF_ERROR_RETURN
   1566                 (_bcm_th3_cosq_obmhighwatermark_get(unit, local_port, value));
   1567             return BCM_E_NONE;
   1568         case bcmCosqStatHdrmPoolDroppedPackets:
   1569             return _bcm_th3_hp_drop_counter_get(unit, port, cosq, stat,
   1570                     value, sync);
   1571         case bcmCosqStatSourcePortDroppedPackets:
   1572             return _bcm_th3_ing_port_drop_counters_get(unit, port, cosq, stat,
   1573                     value, sync);
   1574         case bcmCosqStatRQETotalDroppedPackets:
   1575         case bcmCosqStatRQETotalDroppedBytes:
   1576         case bcmCosqStatRQEGreenDroppedPackets:
   1577         case bcmCosqStatRQEYellowDroppedPackets:
   1578         case bcmCosqStatRQERedDroppedPackets:
   1579             return _bcm_th3_rqe_drop_counters_get(unit, port,
   1580                     cosq, stat, value, sync);
   1581         case bcmCosqStatOBMLossyBufferBytes:
   1582         case bcmCosqStatOBMLossless0BufferBytes:
   1583         case bcmCosqStatOBMLossless1BufferBytes:
   1584         case bcmCosqStatOBMBufferBytes:
   1585             return _bcm_th3_cosq_obm_buf_use_cnt_get(unit, port, cosq, stat, value);
   1586         default:
   1587             return BCM_E_PARAM;
   1588     }
   1589     return BCM_E_NONE;
   1590 
   1591 }
   1592 
   1593 
   1594 
   1595 #endif
   1596