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

eav.c (21620B)


      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  * Ethernet AV BCM APIs
      8  */
      9 
     10 #include <soc/drv.h>
     11 #include <soc/mem.h>
     12 
     13 #include <bcm/error.h>
     14 #include <bcm/eav.h>
     15 
     16 #include <bcm_int/esw/firebolt.h>
     17 #include <bcm_int/esw/switch.h>
     18 
     19 #include <bcm_int/esw_dispatch.h>
     20 
     21 #define PHASE_FREQUENCY_ADJUSTMENT_MODE_SHIFT  20
     22 #define PHASE_FREQUENCY_ADJUSTMENT_MODE_MASK   0x3
     23 #define PHASE_FREQUENCY_ADJUSTMENT_ATTR_MASK   0xFFFFF
     24 
     25 #define HK_BURST_GRANULARITY   64 /* 64bytes */
     26 #define HK_BW_FIELD_MAX        0x3FFFF
     27 #define BCM_EAV_CLASS_A_QUEUE  3
     28 #define BCM_EAV_CLASS_B_QUEUE  2
     29 
     30 /*
     31 * Function:
     32 *      bcm_eav_init
     33 * Description:
     34 *      Initialize the Residential Ethernet module and enable
     35 *      the Ethernet AV (EAV) support.
     36 * Parameters:
     37 *      unit - device unit number.
     38 * Returns:
     39 *      BCM_E_XXX
     40 *      
     41 * Notes:
     42 *      1. This function will enable the global EAV functionality
     43 *      2. Decide the way to report egress timestamp info to CPU
     44 *         Either loopback reporting packets
     45 *         or CPU directly read register later.
     46 */
     47 int 
     48 bcm_esw_eav_init(int unit)
     49 {
     50     /* Init ether type and DA of TS, SRP and MMRP. */
     51     if (SOC_IS_HAWKEYE(unit)) {
     52 
     53         BCM_IF_ERROR_RETURN(
     54             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncDestMacOui, 
     55                                        TS_MAC_OUI_DEFAULT)); 
     56         BCM_IF_ERROR_RETURN(
     57             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncDestMacNonOui, 
     58                                        TS_MAC_NONOUI_DEFAULT)); 
     59         BCM_IF_ERROR_RETURN(
     60             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncEthertype, 
     61                                        TS_ETHERTYPE_DEFAULT));
     62         BCM_IF_ERROR_RETURN(
     63             bcm_esw_switch_control_set(unit, bcmSwitchMMRPEthertype, 
     64                                        MMRP_ETHERTYPE_DEFAULT)); 
     65         BCM_IF_ERROR_RETURN(
     66             bcm_esw_switch_control_set(unit, bcmSwitchMMRPDestMacOui, 
     67                                        MMRP_MAC_OUI_DEFAULT)); 
     68         BCM_IF_ERROR_RETURN(
     69             bcm_esw_switch_control_set(unit, bcmSwitchMMRPDestMacNonOui, 
     70                                        MMRP_MAC_NONOUI_DEFAULT)); 
     71 
     72         /* Enable CPU 802.1as egress capability to get ingress timestamp. */
     73         BCM_IF_ERROR_RETURN(bcm_esw_port_control_set(unit, CMIC_PORT(unit),
     74                             bcmPortControlIEEE8021ASEnableEgress,1));
     75         return BCM_E_NONE;
     76     }
     77     return BCM_E_UNAVAIL;
     78 }
     79 
     80 /*
     81 * Function:
     82 *      bcm_eav_port_enable_get
     83 * Description:
     84 *      Get enable status of per port Ethernet AV functionality
     85 * Parameters:
     86 *      unit - device unit number.
     87 *      port - port number
     88 *      enable - (OUT) TRUE, port is enabled for Ethernet AV
     89 *                     FALSE, port is disabled for Ethernet AV
     90 * Returns:
     91 *      BCM_E_NONE
     92 *      BCM_E_XXX
     93 * Notes:
     94 */
     95 
     96 int 
     97 bcm_esw_eav_port_enable_get(int unit, bcm_port_t port, int *enable)
     98 {
     99     return bcm_esw_port_control_get(unit, port, 
    100                                     bcmPortControlTimestampEnable, enable);
    101 }
    102 
    103 /*
    104 * Function:
    105 *      bcm_eav_port_enable_set
    106 * Description:
    107 *      Enable or disable per port Ethernet AV functionality
    108 * Parameters:
    109 *      unit - device unit number.
    110 *      port - port number
    111 *      enable - TRUE, port is enabled for Ethernet AV
    112 *               FALSE, port is disabled for Ethernet AV
    113 * Returns:
    114 *      BCM_E_NONE
    115 *      BCM_E_XXX
    116 *
    117 * Notes:
    118 *      Need to disable the per port flow control
    119 */
    120 
    121 int 
    122 bcm_esw_eav_port_enable_set(int unit, bcm_port_t port, int enable)
    123 {
    124     if (SOC_IS_HAWKEYE(unit)) {
    125         if (!SOC_PORT_VALID(unit, port)) {
    126             return BCM_E_PORT;
    127         }
    128         /* Enable EAV packets parsing */
    129         BCM_IF_ERROR_RETURN(
    130             bcm_esw_port_control_set(unit, port, 
    131                                      bcmPortControlTimestampEnable, 
    132                                      enable));
    133         /* Enable TS protocol packets parsing */
    134         BCM_IF_ERROR_RETURN(
    135             bcm_esw_port_control_set(unit, port, 
    136                                      bcmPortControlIEEE8021ASEnableIngress, 
    137                                      enable));
    138         BCM_IF_ERROR_RETURN(
    139             bcm_esw_port_control_set(unit, port,
    140                                      bcmPortControlIEEE8021ASEnableEgress,
    141                                      enable));
    142         /* Setup switch behavior for TS packets. */
    143         BCM_IF_ERROR_RETURN(
    144             bcm_esw_switch_control_port_set(unit, port,
    145                                             bcmSwitchTimeSyncPktDrop, enable));
    146         BCM_IF_ERROR_RETURN(
    147             bcm_esw_switch_control_port_set(unit, port,
    148                                             bcmSwitchTimeSyncPktToCpu, enable));
    149         return BCM_E_NONE;
    150     }
    151     return BCM_E_UNAVAIL;
    152 }
    153 
    154 /*
    155 * Function:
    156 *      bcm_eav_link_status_get
    157 * Description:
    158 *      Get link status of per port Ethernet AV functionality
    159 * Parameters:
    160 *      unit - device unit number.
    161 *      port - port number
    162 *      link - (OUT) TRUE, Ethernet AV led is light on
    163 *                     FALSE, Ethernet AV led is light off
    164 * Returns:
    165 *      BCM_E_NONE
    166 *      BCM_E_XXX
    167 * Notes:
    168 */
    169 
    170 int 
    171 bcm_esw_eav_link_status_get(int unit, bcm_port_t port, int *link)
    172 {
    173     return bcm_esw_port_link_status_get(unit, port, link);
    174 }
    175 
    176 /*
    177 * Function:
    178 *      bcm_eav_link_status_set
    179 * Description:
    180 *      Set the EAV link status of  per port Ethernet AV functionality
    181 * Parameters:
    182 *      unit - device unit number.
    183 *      port - port number
    184 *      link - TRUE, Ethernet AV led is light on
    185 *               FALSE, Ethernet AV led is light off
    186 * Returns:
    187 *      BCM_E_NONE
    188 *      BCM_E_XXX
    189 *
    190 * Notes:
    191 */
    192 
    193 int 
    194 bcm_esw_eav_link_status_set(int unit, bcm_port_t port, int link)
    195 {
    196     return BCM_E_UNAVAIL;
    197 }
    198 
    199 /*
    200 * Function:
    201 *      bcm_eav_control_get
    202 * Description:
    203 *      Get the configuration for specific type
    204 * Parameters:
    205 *      unit - device unit number.
    206 *      type - configuration type
    207 *      arg1 - (OUT) the pointer buffer to store the returned configuration
    208 *      arg2 - (OUT) the pointer buffer to store the returned configuration
    209 * Returns:
    210 *      BCM_E_NONE
    211 *      BCM_E_XXX
    212 * Notes:
    213 */
    214 
    215 int 
    216 bcm_esw_eav_control_get(int unit, bcm_eav_control_t type, 
    217         uint32 *arg1, uint32 *arg2)
    218 {
    219     int rv = BCM_E_UNAVAIL;
    220     uint32 rval;
    221 
    222     if (SOC_IS_HAWKEYE(unit)) {
    223         switch (type) {
    224             case bcmEAVControlTimeBase:
    225                 if (arg1 != NULL) {
    226                     /* coverity[result_independent_of_operands] */
    227                     SOC_IF_ERROR_RETURN(READ_CMIC_TIMESYNC_TIMERr(unit, arg1));
    228                 }
    229                 return BCM_E_NONE;
    230             case bcmEAVControlTimeAdjust:
    231                 /* coverity[result_independent_of_operands] */
    232                 SOC_IF_ERROR_RETURN(READ_CMIC_TIMESYNC_CONTROLr(unit, &rval));
    233                 if (arg1 != NULL) {
    234                     *arg1 = (rval >> PHASE_FREQUENCY_ADJUSTMENT_MODE_SHIFT) &
    235                              PHASE_FREQUENCY_ADJUSTMENT_MODE_MASK;
    236                 }
    237                 if (arg2 != NULL) {
    238                     *arg2 = (rval & PHASE_FREQUENCY_ADJUSTMENT_ATTR_MASK);
    239                 }
    240                 return BCM_E_NONE;
    241             default:
    242                 break;
    243         }
    244         return BCM_E_PARAM; 
    245     }
    246     return rv;
    247 }
    248 
    249 /*
    250 * Function:
    251 *      bcm_eav_control_set
    252 * Description:
    253 *      Set the configuration for specific type
    254 * Parameters:
    255 *      unit - device unit number.
    256 *      type - configuration type
    257 *      arg1 - the configuration data to set 
    258 *      arg2 - the configuration data to set 
    259 * Returns:
    260 *      BCM_E_NONE
    261 *      BCM_E_XXX
    262 * Notes:
    263 */
    264 
    265 int 
    266 bcm_esw_eav_control_set(int unit, bcm_eav_control_t type, 
    267        uint32 arg1, uint32 arg2)
    268 {
    269     int rv = BCM_E_UNAVAIL;
    270     uint32 rval = 0;
    271     if (SOC_IS_HAWKEYE(unit)) {
    272         switch (type) {
    273             case bcmEAVControlTimeAdjust:
    274                 /* arg1 = mode, arg2 = phase/freq adjustment value */
    275                 rval = (arg1 << PHASE_FREQUENCY_ADJUSTMENT_MODE_SHIFT) | 
    276                        (arg2 & PHASE_FREQUENCY_ADJUSTMENT_ATTR_MASK);
    277                 switch (arg1) {
    278                     case BCM_EAV_TIMEREF_MODE_FREERUN:
    279                         rval = 0x0;
    280                     case BCM_EAV_TIMEREF_MODE_PHASE_ADJUSTMENT:
    281                     case BCM_EAV_TIMEREF_MODE_FREQ_ADJUMENT1:
    282                     case BCM_EAV_TIMEREF_MODE_FREQ_ADJUMENT2:
    283                         break;
    284                     default:
    285                     return BCM_E_PARAM;
    286                 }
    287                 /* coverity[result_independent_of_operands] */
    288                 SOC_IF_ERROR_RETURN(WRITE_CMIC_TIMESYNC_CONTROLr(unit, rval));
    289                 break;
    290             default:
    291                 return BCM_E_PARAM;
    292         }
    293         return BCM_E_NONE; 
    294     }
    295     return rv;
    296 }
    297 
    298 /*
    299 * Function:
    300 *      bcm_eav_egress_timestamp_get
    301 * Description:
    302 *      Get the per port egress timestamp value of TS protocol packets
    303 * Parameters:
    304 *      unit - device unit number
    305 *      port - port number
    306 *      timestamp - (OUT) the pointer buffer to store the returned timestamp  
    307 * Returns:
    308 *      BCM_E_NONE
    309 *      BCM_E_XXX
    310 * Notes:
    311 */
    312 
    313 int 
    314 bcm_esw_eav_timestamp_get(int unit, bcm_port_t port, uint32 *timestamp)
    315 {
    316     if (SOC_IS_HAWKEYE(unit)) {
    317         if (!SOC_PORT_VALID(unit, port)) {
    318             return BCM_E_PORT;
    319         }
    320         return bcm_esw_port_control_get(unit, port, 
    321                                         bcmPortControlTimestampTransmit, 
    322                                         (int *)timestamp);
    323     }
    324     return BCM_E_UNAVAIL;
    325 }
    326 
    327 /*
    328 * Function:
    329 *      bcm_eav_timesync_mac_get
    330 * Description:
    331 *      Get the Mac address of Time Sync protocol
    332 * Parameters:
    333 *      unit - device unit number
    334 *      eav_mac - the pointer buffer to restorm the mac addrss  
    335 * Returns:
    336 *      BCM_E_NONE
    337 *      BCM_E_XXX
    338 * Notes:
    339 */
    340 
    341 int 
    342 bcm_esw_eav_timesync_mac_get(int unit, bcm_mac_t eav_mac)
    343 {
    344     uint32 MacOui, MacNonOui;
    345     if (SOC_IS_HAWKEYE(unit)) {
    346 
    347         BCM_IF_ERROR_RETURN(
    348             bcm_esw_switch_control_get(unit, bcmSwitchTimeSyncDestMacOui, 
    349                                       (int *)&MacOui));
    350         BCM_IF_ERROR_RETURN(
    351             bcm_esw_switch_control_get(unit, bcmSwitchTimeSyncDestMacNonOui, 
    352                                       (int *)&MacNonOui));
    353         eav_mac[0] = (uint8) (MacOui >> 16);
    354         eav_mac[1] = (uint8) (MacOui >> 8); 
    355         eav_mac[2] = (uint8) (MacOui); 
    356         eav_mac[3] = (uint8) (MacNonOui >> 16);
    357         eav_mac[4] = (uint8) (MacNonOui >> 8); 
    358         eav_mac[5] = (uint8) (MacNonOui); 
    359 
    360         return BCM_E_NONE; 
    361     }
    362     return BCM_E_UNAVAIL;
    363 }
    364 
    365 /*
    366 * Function:
    367 *      bcm_eav_timesync_mac_set
    368 * Description:
    369 *      Set the Mac address of Time Sync protocol
    370 * Parameters:
    371 *      unit - device unit number
    372 *      eav_mac - the pointer buffer to restorm the mac addrss  
    373 * Returns:
    374 *      BCM_E_NONE
    375 *      BCM_E_XXX
    376 * Notes:
    377 */
    378 
    379 int 
    380 bcm_esw_eav_timesync_mac_set(int unit, bcm_mac_t eav_mac)
    381 {
    382     uint32 MacOui, MacNonOui;
    383 
    384     if (SOC_IS_HAWKEYE(unit)) {
    385         MacOui = (((uint32)eav_mac[0]) << 16 | ((uint32)eav_mac[1]) << 8 | ((uint32)eav_mac[2]));
    386         MacNonOui = (((uint32)eav_mac[3]) << 16 | ((uint32)eav_mac[4]) << 8 | ((uint32)eav_mac[5]));
    387 
    388         BCM_IF_ERROR_RETURN(
    389             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncDestMacOui, 
    390                                        MacOui));
    391         BCM_IF_ERROR_RETURN(
    392             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncDestMacNonOui, 
    393                                        MacNonOui));
    394 
    395         return BCM_E_NONE; 
    396     }
    397     return BCM_E_UNAVAIL;
    398 }
    399 
    400 /*
    401  * Function:
    402  *      bcm_eav_srp_mac_ethertype_set
    403  * Description:
    404  *      Get the Mac address and Ethertype used to trap SRP protocol packets
    405  * Parameters:
    406  *      unit - device unit number
    407  *      mac  - the mac addrss   
    408  *      ethertype - the EtherType
    409  * Returns:
    410  *      BCM_E_NONE
    411  *      BCM_E_XXX
    412  * Notes:
    413  */
    414 int
    415 bcm_esw_eav_srp_mac_ethertype_set(int unit, bcm_mac_t mac, bcm_port_ethertype_t ethertype)
    416 {
    417     uint32 MacOui, MacNonOui;
    418 
    419     if (SOC_IS_HAWKEYE(unit)) {
    420         MacOui = (((uint32)mac[0]) << 16 | ((uint32)mac[1]) << 8 | ((uint32)mac[2]));
    421         MacNonOui = (((uint32)mac[3]) << 16 | ((uint32)mac[4]) << 8 | ((uint32)mac[5]));
    422 
    423         BCM_IF_ERROR_RETURN(
    424             bcm_esw_switch_control_set(unit, bcmSwitchSRPDestMacOui, 
    425                                        MacOui));
    426         BCM_IF_ERROR_RETURN(
    427             bcm_esw_switch_control_set(unit, bcmSwitchSRPDestMacNonOui, 
    428                                        MacNonOui));
    429         BCM_IF_ERROR_RETURN(
    430             bcm_esw_switch_control_set(unit, bcmSwitchSRPEthertype, ethertype));
    431 
    432         return BCM_E_NONE;
    433     }
    434     return BCM_E_UNAVAIL;
    435 }
    436 
    437 /*
    438  * Function:
    439  *      bcm_eav_srp_mac_ethertype_get
    440  * Description:
    441  *      Get the Mac address and Ethertype used to trap SRP protocol packets
    442  * Parameters:
    443  *      unit - device unit number
    444  *      mac  - (OUT)the mac addrss   
    445  *      ethertype - (OUT)the EtherType
    446  * Returns:
    447  *      BCM_E_NONE
    448  *      BCM_E_XXX
    449  * Notes:
    450  */                               
    451 int 
    452 bcm_esw_eav_srp_mac_ethertype_get(int unit, bcm_mac_t mac, bcm_port_ethertype_t *ethertype)
    453 {
    454     uint32 MacOui, MacNonOui;
    455     int    type;
    456     if (SOC_IS_HAWKEYE(unit)) {
    457 
    458         BCM_IF_ERROR_RETURN(
    459             bcm_esw_switch_control_get(unit, bcmSwitchSRPDestMacOui, 
    460                                       (int *)&MacOui));
    461         BCM_IF_ERROR_RETURN(
    462             bcm_esw_switch_control_get(unit, bcmSwitchSRPDestMacNonOui, 
    463                                       (int *)&MacNonOui));
    464         mac[0] = (uint8) (MacOui >> 16);
    465         mac[1] = (uint8) (MacOui >> 8); 
    466         mac[2] = (uint8) (MacOui); 
    467         mac[3] = (uint8) (MacNonOui >> 16);
    468         mac[4] = (uint8) (MacNonOui >> 8); 
    469         mac[5] = (uint8) (MacNonOui); 
    470 
    471         BCM_IF_ERROR_RETURN(
    472             bcm_esw_switch_control_get(unit, bcmSwitchSRPEthertype, 
    473                                        &type));
    474         *ethertype = type;
    475 
    476         return BCM_E_NONE;
    477     }
    478     return BCM_E_UNAVAIL;
    479 }
    480 
    481 /*
    482  * Function:
    483  *      bcm_eav_pcp_mapping_set
    484  * Description:
    485  *      Set the PCP(priority) value mapping for each EAV class packets
    486  * Parameters:
    487  *      unit - device unit number
    488  *      type - Class A or Class B stream
    489  *      pcp  - Priority for the Class   
    490  *      rempapped_pcp - For NonEAV traffic with PCP=ClassA_PCP or ClassB_PCP
    491  *      exiting through an egress port configured in EAV mode must be remapped
    492  *      to another pcp.
    493  * Returns:
    494  *      BCM_E_NONE
    495  *      BCM_E_XXX
    496  * Notes:
    497  */
    498 int
    499 bcm_esw_eav_pcp_mapping_set(
    500     int unit, 
    501     bcm_eav_stream_class_t type, 
    502     int pcp, 
    503     int remapped_pcp)
    504 {
    505     if (type == bcmEAVCStreamClassA) {
    506         BCM_IF_ERROR_RETURN(
    507             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncClassAPktPrio, pcp));
    508         BCM_IF_ERROR_RETURN(
    509             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncClassAExeptionPktPrio, 
    510                                    remapped_pcp));
    511     } else if (type == bcmEAVCStreamClassB) {
    512         BCM_IF_ERROR_RETURN(
    513             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncClassBPktPrio, pcp));
    514         BCM_IF_ERROR_RETURN(
    515             bcm_esw_switch_control_set(unit, bcmSwitchTimeSyncClassBExeptionPktPrio, 
    516                                    remapped_pcp));
    517     } else {
    518         return BCM_E_PARAM;
    519     }
    520 
    521     return BCM_E_NONE;
    522     }
    523 
    524 /*
    525  * Function:
    526  *      bcm_esw_eav_pcp_mapping_get
    527  * Description:
    528  *      Set the PCP(priority) value mapping for each EAV class packets
    529  * Parameters:
    530  *      unit - device unit number
    531  *      type - Class A or Class B stream
    532  *      pcp  - Priority for the Class   
    533  *      rempapped_pcp - For NonEAV traffic with PCP=ClassA_PCP or ClassB_PCP
    534  *      exiting through an egress port configured in EAV mode must be remapped
    535  *      to another pcp.
    536  * Returns:
    537  *      BCM_E_NONE
    538  *      BCM_E_XXX
    539  * Notes:
    540  */
    541 int
    542 bcm_esw_eav_pcp_mapping_get(
    543     int unit, 
    544     bcm_eav_stream_class_t type, 
    545     int *pcp, 
    546     int *remapped_pcp)
    547 {
    548 
    549     if (type == bcmEAVCStreamClassA) {
    550         BCM_IF_ERROR_RETURN(
    551             bcm_esw_switch_control_get(unit, bcmSwitchTimeSyncClassAPktPrio, pcp));
    552         BCM_IF_ERROR_RETURN(
    553             bcm_esw_switch_control_get(unit, bcmSwitchTimeSyncClassAExeptionPktPrio, 
    554                                    remapped_pcp));
    555         } else if (type == bcmEAVCStreamClassB) {
    556         BCM_IF_ERROR_RETURN(
    557             bcm_esw_switch_control_get(unit, bcmSwitchTimeSyncClassBPktPrio, pcp));
    558         BCM_IF_ERROR_RETURN(
    559             bcm_esw_switch_control_get(unit, bcmSwitchTimeSyncClassBExeptionPktPrio, 
    560                                    remapped_pcp));
    561         } else {
    562             return BCM_E_PARAM;
    563         }
    564 
    565         return BCM_E_NONE;
    566     }
    567 
    568 /*
    569  * Function:
    570  *      bcm_esw_eav_bandwidth_set
    571  * Description:
    572  *      Set the reserved bandwidth for Class A or B stream traffic
    573  * Parameters:
    574  *      unit - device unit number
    575  *      port - port number   
    576  *      type - Class A or Class B stream
    577  *      bytes_sec - maximum bytes per second.
    578  *      bytes_burst - maximum burst size in bytes. 
    579  * Returns:
    580  *      BCM_E_NONE
    581  *      BCM_E_XXX
    582  * Notes:
    583  */
    584 int
    585 bcm_esw_eav_bandwidth_set(
    586     int unit, 
    587     bcm_port_t port, 
    588     bcm_eav_stream_class_t type, 
    589     uint32 bytes_sec,
    590     uint32 bytes_burst)
    591 {
    592 #if defined(BCM_HAWKEYE_SUPPORT)
    593     uint32 kbits_sec_max, kbits_sec_burst, burst_size, rval, meter_flags = 0;
    594     bcm_cos_queue_t cosq;
    595     
    596     if (SOC_IS_HAWKEYE(unit)) {
    597         if (!SOC_PORT_VALID(unit, port)) {
    598             return BCM_E_PORT;
    599         }
    600         if (type == bcmEAVCStreamClassA) {
    601             cosq = BCM_EAV_CLASS_A_QUEUE;
    602         } else if (type == bcmEAVCStreamClassB) {
    603             cosq = BCM_EAV_CLASS_B_QUEUE;
    604         } else {
    605             return BCM_E_PARAM;
    606         }
    607         
    608         /* disable ingress policing and egress metering */
    609         if (bytes_sec) {
    610             BCM_IF_ERROR_RETURN(bcm_esw_port_rate_ingress_set(unit, port, 0, 0));
    611             BCM_IF_ERROR_RETURN(bcm_esw_port_rate_egress_set(unit, port, 0, 0));
    612         }
    613         
    614         kbits_sec_max = bytes_sec * 8 / 1000;
    615         kbits_sec_burst = bytes_burst * 8 / 1000;
    616 
    617         BCM_IF_ERROR_RETURN(
    618             bcm_fb_cosq_port_bandwidth_set(unit, port, cosq, kbits_sec_max,
    619                                            kbits_sec_max, kbits_sec_burst,
    620                                            meter_flags));
    621 
    622         burst_size = (bytes_burst + (HK_BURST_GRANULARITY - 1)) / HK_BURST_GRANULARITY;
    623         if (burst_size > HK_BW_FIELD_MAX) {
    624                 burst_size = HK_BW_FIELD_MAX;
    625         }
    626 
    627         SOC_IF_ERROR_RETURN(READ_MAXBUCKETCONFIGr(unit, port, cosq, &rval));
    628         soc_reg_field_set(unit, MAXBUCKETCONFIGr, &rval,MAX_THD_SELf, 
    629                           (burst_size >> 6) & 0xFFF);
    630         SOC_IF_ERROR_RETURN(WRITE_MAXBUCKETCONFIGr(unit, port, cosq, rval));
    631  
    632         SOC_IF_ERROR_RETURN(READ_EAVBUCKETCONFIG_EXTr(unit, port, &rval));
    633         soc_reg_field_set(unit, EAVBUCKETCONFIG_EXTr, &rval,
    634                           (type == bcmEAVCStreamClassA)? CLASSA_THD_SEL_6LSBf:
    635                               CLASSB_THD_SEL_6LSBf, burst_size & 0x3f);
    636         SOC_IF_ERROR_RETURN(WRITE_EAVBUCKETCONFIG_EXTr(unit, port, rval));
    637 
    638         return BCM_E_NONE;
    639     }
    640 #endif /* BCM_HAWKEYE_SUPPORT */
    641     return BCM_E_UNAVAIL;
    642 }
    643 
    644 /*
    645  * Function:
    646  *      bcm_esw_eav_bandwidth_get
    647  * Description:
    648  *      Get the reserved bandwidth for Class A or B stream traffic
    649  * Parameters:
    650  *      unit - device unit number
    651  *      port - port number   
    652  *      type - Class A or Class B stream
    653  *      bytes_sec - bytes per second.
    654  *      bytes_burst - max burst bytes.
    655  * Returns:
    656  *      BCM_E_NONE
    657  *      BCM_E_XXX
    658  * Notes:
    659  */
    660 int
    661 bcm_esw_eav_bandwidth_get(
    662     int unit, 
    663     bcm_port_t port, 
    664     bcm_eav_stream_class_t type, 
    665     uint32 *bytes_sec,
    666     uint32 *bytes_burst)
    667 {
    668 #if defined(BCM_HAWKEYE_SUPPORT)
    669     uint32 regval, kbits_sec_max, kbits_sec_min, kbits_sec_burst;
    670     uint32 burst_hi, burst_lo, meter_flags = 0;
    671     bcm_cos_queue_t cosq;
    672     
    673     if (SOC_IS_HAWKEYE(unit)) {
    674         if (!SOC_PORT_VALID(unit, port)) {
    675             return BCM_E_PORT;
    676         }
    677         if (type == bcmEAVCStreamClassA) {
    678             cosq = BCM_EAV_CLASS_A_QUEUE;
    679         } else if (type == bcmEAVCStreamClassB) {
    680             cosq = BCM_EAV_CLASS_B_QUEUE;
    681         } else {
    682             return BCM_E_PARAM;
    683         }
    684         
    685         BCM_IF_ERROR_RETURN(
    686             bcm_fb_cosq_port_bandwidth_get(unit, port, cosq, &kbits_sec_min, 
    687                                            &kbits_sec_max, &kbits_sec_burst, 
    688                                            &meter_flags));
    689 
    690         
    691         *bytes_sec = (kbits_sec_max * 1000) / 8;
    692         SOC_IF_ERROR_RETURN(READ_MAXBUCKETCONFIGr(unit, port, cosq, &regval));
    693         burst_hi = soc_reg_field_get(unit, MAXBUCKETCONFIGr, regval, MAX_THD_SELf);
    694         SOC_IF_ERROR_RETURN(READ_EAVBUCKETCONFIG_EXTr(unit, port, &regval));
    695         if (type == bcmEAVCStreamClassA) {
    696             burst_lo = soc_reg_field_get(unit, EAVBUCKETCONFIG_EXTr, regval, CLASSA_THD_SEL_6LSBf);
    697         } else {
    698             burst_lo = soc_reg_field_get(unit, EAVBUCKETCONFIG_EXTr, regval, CLASSB_THD_SEL_6LSBf);
    699         }
    700         *bytes_burst = ((burst_hi << 6) | burst_lo)*HK_BURST_GRANULARITY;
    701         return BCM_E_NONE;
    702     }
    703 #endif /* BCM_HAWKEYE_SUPPORT */
    704     return BCM_E_UNAVAIL;
    705 }
    706