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 (3987B)


      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 
      8 #include <soc/defs.h>
      9 
     10 #include <assert.h>
     11 
     12 #include <sal/core/libc.h>
     13 #if defined(BCM_GREYHOUND_SUPPORT)
     14 #include <shared/util.h>
     15 #include <soc/mem.h>
     16 #include <soc/cm.h>
     17 #include <soc/drv.h>
     18 #include <soc/register.h>
     19 #include <soc/memory.h>
     20 #include <bcm_int/esw/port.h>
     21 #include <bcm_int/esw/greyhound.h>
     22 #include <bcm_int/esw_dispatch.h>
     23 
     24 int
     25 bcm_gh_cosq_control_set(int unit, bcm_gport_t gport, bcm_cos_queue_t cosq,
     26                         bcm_cosq_control_t type, int arg)
     27 {
     28     bcm_port_t port;
     29     int num_cosq;
     30 
     31     LOG_INFO(BSL_LS_BCM_COSQ,
     32              (BSL_META_U(unit,
     33                          "bcm_gh_cosq_control_set: unit=%d gport=0x%x cosq=%d \
     34                          type=%d arg=%d\n"),
     35               unit, gport, cosq, type, arg));
     36 
     37     if (soc_feature(unit, soc_feature_wh2)) {
     38         /* Get the configured max cosq number */
     39         BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
     40     } else {
     41         num_cosq = NUM_COS(unit);
     42     }
     43 
     44     if ((cosq < 0) || (cosq >= num_cosq)) {
     45         return BCM_E_PARAM;
     46     }
     47 
     48     switch (type) {
     49     case bcmCosqControlPFCBackpressureEnable:
     50         if (soc_feature(unit, soc_feature_priority_flow_control) &&
     51             soc_feature(unit, soc_feature_gh_style_pfc_config)) {
     52             uint32 rval;
     53             uint32 fval;
     54             if (!BCM_COSQ_QUEUE_VALID(unit, cosq)) {
     55                 return BCM_E_PARAM;
     56             }
     57             BCM_IF_ERROR_RETURN
     58                 (bcm_esw_port_local_get(unit, gport, &port));
     59             if (!SOC_PORT_VALID(unit, port)) {
     60                 return BCM_E_PORT;
     61             }
     62             BCM_IF_ERROR_RETURN(READ_MMU_FC_RX_ENr(unit, port, &rval));
     63             fval = soc_reg_field_get(unit, MMU_FC_RX_ENr, 
     64                                      rval, MMU_FC_RX_ENABLEf);
     65             if (arg) {
     66                 fval |= (1 << cosq);
     67             } else {
     68                 fval &= ~(1 << cosq);
     69             }
     70             soc_reg_field_set(unit, MMU_FC_RX_ENr, 
     71                               &rval, MMU_FC_RX_ENABLEf, fval);
     72             BCM_IF_ERROR_RETURN(WRITE_MMU_FC_RX_ENr(unit, port, rval));
     73             return BCM_E_NONE;
     74         }
     75         break;
     76     default:
     77         break;
     78     }
     79 
     80     return BCM_E_UNAVAIL;
     81 }
     82 
     83 int
     84 bcm_gh_cosq_control_get(int unit, bcm_gport_t gport, bcm_cos_queue_t cosq,
     85                         bcm_cosq_control_t type, int *arg)
     86 {
     87     bcm_port_t port;
     88     int num_cosq;
     89 
     90     LOG_INFO(BSL_LS_BCM_COSQ,
     91              (BSL_META_U(unit,
     92                          "bcm_gh_cosq_control_get: unit=%d gport=0x%x cosq=%d type=%d\n"),
     93               unit, gport, cosq, type));
     94 
     95     if (soc_feature(unit, soc_feature_wh2)) {
     96         /* Get the configured max cosq number */
     97         BCM_IF_ERROR_RETURN(bcm_esw_cosq_config_get(unit, &num_cosq));
     98     } else {
     99         num_cosq = NUM_COS(unit);
    100     }
    101 
    102     if ((cosq < 0) || (cosq >= num_cosq)) {
    103         return BCM_E_PARAM;
    104     }
    105 
    106     switch (type) {
    107     case bcmCosqControlPFCBackpressureEnable:
    108         if (soc_feature(unit, soc_feature_priority_flow_control) &&
    109             soc_feature(unit, soc_feature_gh_style_pfc_config)) {
    110             uint32 value;
    111             if (!BCM_COSQ_QUEUE_VALID(unit, cosq)) {
    112                 return BCM_E_PARAM;
    113             }
    114             BCM_IF_ERROR_RETURN
    115                 (bcm_esw_port_local_get(unit, gport, &port));
    116             if (!SOC_PORT_VALID(unit, port)) {
    117                 return BCM_E_PORT;
    118             }
    119             BCM_IF_ERROR_RETURN(READ_MMU_FC_RX_ENr(unit, port, &value));
    120             if (value & (1 << cosq)) {
    121                 *arg = 1;
    122             } else {
    123                 *arg = 0;
    124             }
    125             return BCM_E_NONE;
    126         }
    127         break;
    128     default:
    129         break;
    130     }
    131 
    132     return BCM_E_UNAVAIL;
    133 }
    134 
    135 #endif /* BCM_GREYHOUND_SUPPORT */
    136