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

rx.c (250959B)


      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  * File:        rx.c
      8  * Purpose:     Receive packet mechanism
      9  * Requires:
     10  *
     11  * See sdk/doc/txrx.txt and pkt.txt for
     12  * information on the RX API and implementation.
     13  *
     14  * Quick overview:
     15  *
     16  *     Packet buffer allocation/deallocation is user configurable.
     17  *     This expects to be given monolithic (single block) buffers.
     18  *     When "HANDLED_OWNED" is returned by a handler, that means
     19  *     that the data buffer is stolen, not the packet structure.
     20  *
     21  *     Callback functions may be registered in interrupt or non-
     22  *     interrupt mode.  Non-interrupt is preferred.
     23  *
     24  *     Interrupt load is limited by setting overall rate limit
     25  *     (bcm_rx_rate_burst_set/get).
     26  *
     27  *     If a packet is not serviced in interrupt mode, it is queued
     28  *     based on its COS.
     29  *
     30  *     Each queue has a rate limit (bcm_rx_cos_rate_set/get) which
     31  *     controls the number of callbacks that will be made for the queue.
     32  *     The non-interrupt thread services these queues from highest to
     33  *     lowest and will discard packets in the queue when they exceed
     34  *     the queue's rate limit.
     35  *
     36  *     Packets handled at interrupt level are still accounted for in
     37  *     the COS rate limiting.
     38  *
     39  *     A channel is:
     40  *          Physically:  A separate hardware DMA process
     41  *          Logically:  A collection of COS bundled together.
     42  *     Rate limiting per channel is no longer supported (replaced
     43  *     by COS queue rate limiting).
     44  *
     45  *     Channels may be enabled and disabled separately from starting RX
     46  *     running.  However, stopping RX disables all channels.
     47  *
     48  *     Packets are started in groups called "chains", each of which
     49  *     is controlled by a "DV" (DMA-descriptor vector).
     50  *
     51  *     Updates to the handler linked list need to be synchronized
     52  *     both with thread packet processing (mutex) and interrupt
     53  *     packet processing (spl).
     54  *
     55  *     If no real callouts are registered (other than internal discard)
     56  *     don't bother starting DVs, nor queuing input pkts into cos queues.
     57  */
     58 
     59 /* We need to call top-level APIs on other units */
     60 #ifdef BCM_HIDE_DISPATCHABLE
     61 #undef BCM_HIDE_DISPATCHABLE
     62 #endif
     63 #include <shared/bsl.h>
     64 
     65 #include <shared/alloc.h>
     66 #include <shared/bitop.h>
     67 
     68 #include <soc/drv.h>
     69 #include <soc/scache.h>
     70 #include <soc/higig.h>
     71 #include <bcm/rx.h>
     72 #include <bcm_int/common/rx.h>
     73 #include <bcm_int/esw_dispatch.h>
     74 #include <bcm_int/esw/rx.h>
     75 #include <bcm_int/esw/trunk.h>
     76 #include <bcm_int/control.h>
     77 #include <bcm_int/esw/switch.h>
     78 #include <bcm_int/esw/firebolt.h>
     79 #include <bcm_int/esw/triumph.h>
     80 #include <bcm_int/esw/triumph2.h>
     81 #include <bcm_int/esw/triumph3.h>
     82 #include <bcm_int/esw/trident.h>
     83 #include <bcm_int/esw/trident2.h>
     84 #include <bcm_int/esw/katana.h>
     85 #include <bcm_int/esw/katana2.h>
     86 #include <bcm_int/esw/tomahawk.h>
     87 #include <bcm_int/esw/tomahawk3.h>
     88 #include <bcm_int/esw/trident3.h>
     89 #include <bcm_int/esw/helix5.h>
     90 #include <bcm_int/esw/apache.h>
     91 #include <bcm_int/esw/monterey.h>
     92 #ifdef BCM_HURRICANE2_SUPPORT
     93 #include <bcm_int/esw/hurricane2.h>
     94 #endif
     95 #if defined (BCM_EP_REDIRECT_VERSION_2)
     96 #include <bcm_int/esw/xgs5.h>
     97 #endif /* BCM_EP_REDIRECT_VERSION_2 */
     98 
     99 
    100 #include <bcm_int/api_xlate_port.h>
    101 
    102 #include <bcm_int/rpc/rlink.h>
    103 
    104 #ifdef BCM_WARM_BOOT_SUPPORT
    105 #define BCM_RX_WB_VERSION_1_0                     SOC_SCACHE_VERSION(1,0)
    106 #define BCM_RX_WB_VERSION_1_1                     SOC_SCACHE_VERSION(1,1)
    107 #define BCM_RX_WB_VERSION_1_2                     SOC_SCACHE_VERSION(1,2)
    108 #define BCM_RX_WB_DEFAULT_VERSION                 BCM_RX_WB_VERSION_1_2
    109 
    110 STATIC int _bcm_esw_rx_recover(int unit);
    111 STATIC int _bcm_esw_rx_wb_scache_alloc(int unit);
    112 #endif
    113 #ifdef BCM_TRX_SUPPORT
    114 STATIC int _bcm_esw_rx_cosq_mapping_init(int unit);
    115 #endif
    116 
    117 #if defined(BCM_TOMAHAWK3_SUPPORT)
    118 #include <soc/format.h>
    119 #include <soc/mcm/formatacc.h>
    120 #endif
    121 
    122 
    123 /*
    124  * Function:
    125  *      bcm_esw_rx_sched_register
    126  * Purpose:
    127  *      Rx scheduler registration function. 
    128  * Parameters:
    129  *      unit       - (IN) Unused. 
    130  *      sched_cb   - (IN) Rx scheduler routine.
    131  * Returns:
    132  *      BCM_E_XXX
    133  */
    134 int
    135 bcm_esw_rx_sched_register(int unit, bcm_rx_sched_cb sched_cb)
    136 {
    137     return (_bcm_common_rx_sched_register(unit, sched_cb));
    138 }
    139 
    140 /*
    141  * Function:
    142  *      bcm_esw_rx_sched_unregister
    143  * Purpose:
    144  *      Rx scheduler de-registration function. 
    145  * Parameters:
    146  *      unit  - (IN) Unused. 
    147  * Returns:
    148  *      BCM_E_XXX
    149  */
    150 int
    151 bcm_esw_rx_sched_unregister(int unit)
    152 {
    153     return (_bcm_common_rx_sched_unregister(unit));
    154 }
    155 
    156 /*
    157  * Function:
    158  *      bcm_esw_rx_unit_next_get
    159  * Purpose:
    160  *      Rx started units iteration routine.
    161  * Parameters:
    162  *      unit       - (IN)  BCM device number. 
    163  *      unit_next  - (OUT) Next attached unit with started rx.
    164  * Returns:
    165  *      BCM_E_XXX
    166  */
    167 int
    168 bcm_esw_rx_unit_next_get(int unit, int *unit_next)
    169 {
    170     return (_bcm_common_rx_unit_next_get(unit, unit_next));
    171 }
    172 
    173 /*
    174  * Function:
    175  *      bcm_esw_rx_queue_max_get
    176  * Purpose:
    177  *      Get maximum cos queue number for the device.
    178  * Parameters:
    179  *      unit    - (IN) BCM device number. 
    180  *      cosq    - (OUT) Maximum queue priority.
    181  * Returns:
    182  *      BCM_E_XXX
    183  */
    184 int
    185 bcm_esw_rx_queue_max_get(int unit, bcm_cos_queue_t  *cosq)
    186 {  
    187     return (_bcm_common_rx_queue_max_get(unit, cosq));
    188 }
    189 
    190 /*
    191  * Function:
    192  *      bcm_esw_rx_queue_packet_count_get
    193  * Purpose:
    194  *      Get number of packets awaiting processing in the specific device/queue.
    195  * Parameters:
    196  *      unit         - (IN) BCM device number. 
    197  *      cosq         - (IN) Queue priority.
    198  *      packet_count - (OUT) Number of packets awaiting processing. 
    199  * Returns:
    200  *      BCM_E_XXX
    201  */
    202 int
    203 bcm_esw_rx_queue_packet_count_get(int unit, bcm_cos_queue_t cosq, int *packet_count)
    204 {
    205     return (_bcm_common_rx_queue_packet_count_get(unit, cosq, packet_count));
    206 }
    207 
    208 /*
    209  * Function:
    210  *      bcm_esw_rx_queue_rate_limit_status_get
    211  * Purpose:
    212  *      Get number of packet that can be rx scheduled 
    213  *      until system hits queue rx rate limit. 
    214  * Parameters:
    215  *      unit           - (IN) BCM device number. 
    216  *      cosq           - (IN) Queue priority.
    217  *      packet_tokens  - (OUT)Maximum number of packets that can be  scheduled.
    218  * Returns:
    219  *      BCM_E_XXX
    220  */
    221 int
    222 bcm_esw_rx_queue_rate_limit_status_get(int unit, bcm_cos_queue_t cosq, 
    223                                        int *packet_tokens)
    224 {
    225     return (_bcm_common_rx_queue_rate_limit_status_get(unit, cosq, 
    226 						       packet_tokens));
    227 }
    228 
    229 
    230 /*
    231  * Function:
    232  *      bcm_rx_init
    233  * Purpose:
    234  *      Software initialization for RX API
    235  * Parameters:
    236  *      unit - Unit to init
    237  * Returns:
    238  *      BCM_E_XXX
    239  * Notes:
    240  *      Allocates rx control structure
    241  *      Copies default config into active config
    242  *      Adds discard handler
    243  */
    244 
    245 int
    246 bcm_esw_rx_init(int unit)
    247 {
    248     int rv = BCM_E_NONE;
    249 
    250     /* RX init is done already during early attach */
    251     if (BCM_CONTROL(unit)->attach_state != _bcmControlStateTxRxInited) {
    252         rv =_bcm_common_rx_init(unit);
    253     }
    254     if (!RX_IS_LOCAL(unit) || !SOC_UNIT_VALID(unit)) {
    255         return rv;
    256     }
    257 
    258 #if defined (BCM_EP_REDIRECT_VERSION_2)
    259 
    260     if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
    261 
    262         int size = 0;
    263 
    264         /* Create a mutex for copy-to-cpu protection */
    265         _bcmi_rx_copy_to_cpu_config_mutex[unit] =
    266             sal_mutex_create("RX_COPY_TO_CPU_MUTEX");
    267         if (_bcmi_rx_copy_to_cpu_config_mutex[unit] == NULL) {
    268             return (BCM_E_MEMORY);
    269         }
    270 
    271         /* Allocate space to store the copy-to-cpu config data */
    272         size = soc_mem_index_count(unit, EP_CTC_RES_TABLEm) *
    273                    sizeof(_bcmi_rx_CopyToCpu_config_t);
    274         _bcmi_rx_egr_drop_copy_to_cpu_config_data[unit] =
    275                         sal_alloc(size, "copy-to-cpu table data config alloc");
    276         if (_bcmi_rx_egr_drop_copy_to_cpu_config_data[unit] == NULL) {
    277             return BCM_E_MEMORY;
    278         }
    279         sal_memset(_bcmi_rx_egr_drop_copy_to_cpu_config_data[unit], 0, size);
    280 
    281         /* Allocate space to store the inuse bitmap for copy-to-cpu config */
    282         size = SHR_BITALLOCSIZE(soc_mem_index_count(unit, EP_CTC_RES_TABLEm));
    283         _bcmi_rx_egr_drop_copy_to_cpu_loc_bitmap[unit] =
    284                         sal_alloc(size, "copy-to-cpu table bitmap alloc");
    285         if (_bcmi_rx_egr_drop_copy_to_cpu_loc_bitmap[unit] == NULL) {
    286             sal_free(_bcmi_rx_egr_drop_copy_to_cpu_config_data[unit]);
    287             return BCM_E_MEMORY;
    288         }
    289         sal_memset(_bcmi_rx_egr_drop_copy_to_cpu_loc_bitmap[unit], 0, size);
    290     }
    291 #endif
    292 
    293 #ifdef BCM_WARM_BOOT_SUPPORT
    294     if (SOC_WARM_BOOT(unit) && (rv == BCM_E_NONE)) {
    295         /* Early attach: Postpone RX WB recovery until bcm_attach() */
    296         if (BCM_CONTROL(unit)->attach_state != _bcmControlStateTxRxInit) {
    297             rv = _bcm_esw_rx_recover(unit);
    298         }
    299     } else if (rv == BCM_E_NONE) {
    300 
    301        /* Allocate Warm boot level 2 cache size */
    302        rv = _bcm_esw_rx_wb_scache_alloc(unit);
    303 
    304        if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    305            return rv;
    306        }
    307 
    308         rv = BCM_E_NONE;
    309     }
    310 
    311     if (!SOC_WARM_BOOT(unit))
    312 #endif /* BCM_WARM_BOOT_SUPPORT */
    313     {
    314 #ifdef BCM_TRX_SUPPORT
    315         
    316         if (SOC_IS_TRX(unit)) {
    317         if(rv == BCM_E_NONE){
    318                 /*Init cosq mapping*/
    319             rv = _bcm_esw_rx_cosq_mapping_init(unit);
    320         }
    321     }
    322 #endif
    323     }
    324 
    325     return rv;
    326 }
    327 
    328 
    329 /*
    330  * Function:
    331  *      bcm_rx_cfg_init
    332  * Purpose:
    333  *      Re-initialize the user level configuration
    334  * Parameters:
    335  *      unit - StrataXGS unit number
    336  * Returns:
    337  *      BCM_E_XXX
    338  * Notes:
    339  *      Can't use if currently running.  Should be called before
    340  *      doing a simple modification of the RX configuration in case
    341  *      the previous user has left it in a strange state.
    342  */
    343 
    344 int
    345 bcm_esw_rx_cfg_init(int unit)
    346 {
    347     return (_bcm_common_rx_cfg_init(unit));
    348 }
    349 
    350 /*
    351  * Function:
    352  *      bcm_rx_start
    353  * Purpose:
    354  *      Initialize and configure the RX subsystem for a given unit
    355  * Parameters:
    356  *      unit - Unit to configure
    357  *      cfg - Configuration to use.  See include/bcm/rx.h
    358  * Returns:
    359  *      BCM_E_XXX
    360  * Notes:
    361  *      Starts the packet receive thread if not already running.
    362  *      cfg may be null:  Use default config.
    363  *      alloc/free in cfg may be null:  Use default alloc/free functions
    364  */
    365 
    366 int
    367 bcm_esw_rx_start(int unit, bcm_rx_cfg_t *cfg)
    368 {
    369     return (_bcm_common_rx_start(unit, cfg));
    370 }
    371 
    372 /*
    373  * Function:
    374  *      bcm_rx_stop
    375  * Purpose:
    376  *      Stop RX for the given unit; saves current configuration
    377  * Parameters:
    378  *      unit - The unit to stop
    379  *      cfg - OUT Configuration copied to this parameter
    380  * Returns:
    381  *      BCM_E_XXX
    382  * Notes:
    383  *      This signals the thread to exit.
    384  */
    385 
    386 int
    387 bcm_esw_rx_stop(int unit, bcm_rx_cfg_t *cfg)
    388 {
    389     return (_bcm_common_rx_stop(unit, cfg));
    390 }
    391 
    392 
    393 /*
    394  * Function:
    395  *      bcm_esw_rx_clear
    396  * Purpose:
    397  *      Clear all RX info
    398  * Returns:
    399  *      BCM_E_NONE
    400  */
    401 
    402 int
    403 bcm_esw_rx_clear(int unit)
    404 {
    405     return (_bcm_common_rx_clear(unit));
    406 }
    407 
    408 
    409 int bcm_esw_rx_deinit(int unit)
    410 {
    411 
    412 #if defined (BCM_EP_REDIRECT_VERSION_2)
    413     if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
    414         /* De-allocate space to store the copy-to-cpu
    415            config data */
    416         sal_free(_bcmi_rx_egr_drop_copy_to_cpu_config_data[unit]);
    417         /* De-allocate space to store the inuse bitmap
    418            for copy-to-cpu config */
    419         sal_free(_bcmi_rx_egr_drop_copy_to_cpu_loc_bitmap[unit]);
    420         /* Deinit the mutex */
    421         sal_mutex_destroy(_bcmi_rx_copy_to_cpu_config_mutex[unit]);
    422     }
    423 #endif
    424     return _bcm_rx_shutdown(unit);
    425 }
    426 
    427 /*
    428  * Function:
    429  *      bcm_rx_cfg_get
    430  * Purpose:
    431  *      Check if init done; get the current RX configuration
    432  * Parameters:
    433  *      unit - Strata device ID
    434  *      cfg - OUT Configuration copied to this parameter.  May be NULL
    435  * Returns:
    436  *      BCM_E_INIT if not running on unit
    437  *      BCM_E_NONE if running on unit
    438  *      < 0 BCM_E_XXX error code
    439  * Notes:
    440  */
    441 
    442 int
    443 bcm_esw_rx_cfg_get(int unit, bcm_rx_cfg_t *cfg)
    444 {
    445     return (_bcm_common_rx_cfg_get(unit, cfg));
    446 }
    447 
    448 /*
    449  * Function:
    450  *      bcm_rx_queue_register
    451  * Purpose:
    452  *      Register an application callback for the specified CPU queue
    453  * Parameters:
    454  *      unit - StrataSwitch unit number.
    455  *      name - constant character string for debug purposes.
    456  *      cosq - CPU cos queue
    457  *      callback - callback function pointer.
    458  *      priority - priority of handler in list (0 is lowest priority).
    459  *      cookie - cookie passed to driver when packet arrives.
    460  *      flags - Register for interrupt or non-interrupt callback
    461  * Returns:
    462  *      BCM_E_NONE - callout registered.
    463  *      BCM_E_MEMORY - memory allocation failed.
    464  */
    465 
    466 int
    467 bcm_esw_rx_queue_register(int unit, const char *name, bcm_cos_queue_t cosq, 
    468                           bcm_rx_cb_f callback, uint8 priority, void *cookie, 
    469                           uint32 flags)
    470 {
    471     return (_bcm_common_rx_queue_register(unit, name, cosq, callback,
    472                                        priority, cookie, flags));
    473 }
    474 
    475 /*
    476  * Function:
    477  *      bcm_rx_register
    478  * Purpose:
    479  *      Register an upper layer driver
    480  * Parameters:
    481  *      unit - StrataSwitch unit number.
    482  *      chan - DMA channel number
    483  *      name - constant character string for debug purposes.
    484  *      priority - priority of handler in list (0 is lowest priority).
    485  *      f - function to call for that driver.
    486  *      cookie - cookie passed to driver when packet arrives.
    487  *      flags - Register for interrupt or non-interrupt callback
    488  * Returns:
    489  *      BCM_E_NONE - callout registered.
    490  *      BCM_E_MEMORY - memory allocation failed.
    491  * Notes:
    492  *      Refer bcm_rx_queue_register() if cosq is bigger than 16.
    493  */
    494 
    495 int
    496 bcm_esw_rx_register(int unit, const char *name, bcm_rx_cb_f callback,
    497                 uint8 priority, void *cookie, uint32 flags)
    498 {
    499     return (_bcm_common_rx_register(unit, name, callback,
    500                                     priority, cookie, flags));
    501 }
    502 
    503 
    504 /*
    505  * Function:
    506  *      bcm_rx_unregister
    507  * Purpose:
    508  *      De-register a callback function
    509  * Parameters:
    510  *      unit - Unit reference
    511  *      priority - Priority of registered callback
    512  *      callback - The function being registered
    513  * Returns:
    514  *      BCM_E_XXX
    515  * Notes:
    516  *      Run through linked list looking for match of function and priority
    517  */
    518 
    519 int
    520 bcm_esw_rx_unregister(int unit, bcm_rx_cb_f callback, uint8 priority)
    521 {
    522     return (_bcm_common_rx_unregister(unit, callback, priority));
    523 }
    524 
    525 /*
    526  * Function:
    527  *      bcm_rx_queue_unregister
    528  * Purpose:
    529  *      Unregister a callback function
    530  * Parameters:
    531  *      unit - Unit reference
    532  *      cosq - CPU cos queue
    533  *      priority - Priority of registered callback
    534  *      callback - The function being registered
    535  * Returns:
    536  *      BCM_E_XXX
    537  */
    538 
    539 int
    540 bcm_esw_rx_queue_unregister(int unit, bcm_cos_queue_t cosq,
    541                             bcm_rx_cb_f callback, uint8 priority)
    542 {
    543     return (_bcm_common_rx_queue_unregister(unit, cosq, callback, priority));
    544 }
    545 
    546 /*
    547  * Function:
    548  *      bcm_rx_cosq_mapping_size_get
    549  * Purpose:
    550  *      Get number of COSQ mapping entries
    551  * Parameters:
    552  *      unit - Unit reference
    553  *      size - (OUT) number of entries
    554  * Returns:
    555  *      BCM_E_XXX
    556  */
    557 int
    558 bcm_esw_rx_cosq_mapping_size_get(int unit, int *size)
    559 {
    560     if (size == NULL) {
    561         return BCM_E_PARAM;
    562     }
    563 
    564     if (SOC_UNIT_VALID(unit) && SOC_MEM_IS_VALID(unit, CPU_COS_MAPm)) {
    565         *size = soc_mem_index_count(unit, CPU_COS_MAPm);
    566         return BCM_E_NONE;
    567     }
    568 
    569     *size = 0;
    570     return BCM_E_UNAVAIL;
    571 }
    572 
    573 /*
    574  * Function:
    575  *      _bcm_esw_rx_olp_match_rule_set
    576  * Purpose:
    577  *      Set Olp Match Rule value in rx_ctl
    578  * Parameters:
    579  *      unit - StrataSwitch unit number.
    580  *      olp_match_rule - Olp Match Rule Value.
    581  * Returns:
    582  *      BCM_E_XXX
    583  */
    584 int
    585 _bcm_esw_rx_olp_match_rule_set (int unit, int olp_match_rule)
    586 {
    587 #if defined BCM_TRIDENT2PLUS_SUPPORT
    588     if (SOC_IS_TRIDENT2PLUS(unit)) {
    589         return _bcm_common_rx_olp_match_rule_set (unit, olp_match_rule);
    590     }
    591 #endif
    592     return BCM_E_UNAVAIL;
    593 }
    594 
    595 
    596 /*
    597  * Function:
    598  *      _bcm_esw_rx_olp_match_rule_get
    599  * Purpose:
    600  *      Get Olp Match Rule value in rx_ctl
    601  * Parameters:
    602  *      unit - StrataSwitch unit number.
    603  *      olp_match_rule - Olp Match Rule Value.
    604  * Returns:
    605  *      BCM_E_XXX
    606  */
    607 int
    608 _bcm_esw_rx_olp_match_rule_get (int unit, int *olp_match_rule)
    609 {
    610 #if defined BCM_TRIDENT2PLUS_SUPPORT
    611     if (SOC_IS_TRIDENT2PLUS(unit)) {
    612         return _bcm_common_rx_olp_match_rule_get (unit, olp_match_rule);
    613     }
    614 #endif
    615     return BCM_E_UNAVAIL;
    616 }
    617 
    618 
    619 
    620 #ifdef BCM_WARM_BOOT_SUPPORT
    621 
    622 /*
    623  * Function:
    624  *      _bcm_esw_rx_wb_scache_alloc
    625  * Purpose:
    626  *      Allocates scache space for Level 2 Warm Boot
    627  * Parameters:
    628  *      unit - StrataSwitch unit number.
    629  * Returns:
    630  *      BCM_E_XXX
    631  */
    632 STATIC int
    633 _bcm_esw_rx_wb_scache_alloc(int unit)
    634 {
    635     int                 rv = BCM_E_NONE;
    636     uint8               *rx_scache_ptr;
    637     uint32              rx_scache_size = 0;
    638     int                 stable_size = 0;
    639     soc_scache_handle_t scache_handle;
    640 
    641     BCM_IF_ERROR_RETURN(soc_stable_size_get(unit, &stable_size));
    642     if ((stable_size == 0) || (SOC_WARM_BOOT_SCACHE_IS_LIMITED(unit))) {
    643         return BCM_E_NONE;
    644     }
    645 
    646     /* To store global_pps, max_burst and system_pps configuration */
    647     rx_scache_size += 3 * sizeof(int32);
    648 
    649     /* Store per queue PPS and Burst settings in L2 cache
    650        if harware rate limit is not supported */
    651     if (!soc_feature(unit, soc_feature_packet_rate_limit)) {
    652         /* Per cosq PPS, Burst and Max permitted packets configuration */
    653         rx_scache_size += (RX_QUEUE_MAX(unit) + 1) * (3 * sizeof(int32));
    654     } else {
    655         /* To store max permitted packets configuration */
    656         rx_scache_size += (RX_QUEUE_MAX(unit) + 1) * sizeof(int32);
    657     }
    658     /* OLP match rule for fp based oam */
    659 #if defined (BCM_TRIDENT2PLUS_SUPPORT)
    660     if (SOC_IS_TRIDENT2PLUS(unit) &&
    661             soc_feature(unit, soc_feature_fp_based_oam)) {
    662         rx_scache_size += sizeof(RX_OLP_MATCH_RULE(unit));
    663     }
    664 #endif
    665 
    666 #if defined (BCM_EP_REDIRECT_VERSION_2)
    667     if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
    668 
    669         int size = 0;
    670 
    671         /* Allocate space to store the copy-to-cpu config data */
    672         size = soc_mem_index_count(unit, EP_CTC_RES_TABLEm) *
    673                           sizeof(_bcmi_rx_CopyToCpu_config_t);
    674         rx_scache_size += size;
    675         /* Allocate space to store the inuse bitmap for copy-to-cpu config */
    676         size = SHR_BITALLOCSIZE(
    677             soc_mem_index_count(unit, EP_CTC_RES_TABLEm));
    678         rx_scache_size += size;
    679     }
    680 #endif
    681 #if defined (BCM_KATANA_SUPPORT)
    682     if (SOC_IS_KATANAX(unit)) {
    683         /* Allocate space to store rx_ctl[unit]->flags */
    684         rx_scache_size += sizeof(rx_ctl[unit]->flags);
    685     }
    686 #endif
    687 
    688     SOC_SCACHE_HANDLE_SET(scache_handle, unit, BCM_MODULE_RX, 0);
    689     rv = _bcm_esw_scache_ptr_get(unit, scache_handle, TRUE,
    690                                  rx_scache_size,
    691                                  &rx_scache_ptr,
    692                                  BCM_RX_WB_DEFAULT_VERSION, NULL);
    693 
    694     return rv;
    695 }
    696 
    697 /*
    698  * Function:
    699  *      bcm_esw_rx_recover
    700  * Purpose:
    701  *      Recover RX configuration from Hardware and L2 scache.
    702  * Parameters:
    703  *      unit - Unit reference
    704  * Returns:
    705  *      BCM_E_XXX
    706  */
    707 STATIC int
    708 _bcm_esw_rx_recover(int unit)
    709 {
    710    soc_scache_handle_t scache_handle;
    711    uint8               *rx_scache_ptr;
    712    rx_queue_t          *queue;
    713    bcm_cos_queue_t     cosq;
    714    int		           system_pps;
    715    int                 rv = BCM_E_NONE;
    716    uint16              recovered_ver;
    717    uint32              additional_scache_size = 0;
    718 #if defined(BCM_TRX_SUPPORT) || defined(BCM_FIREBOLT2_SUPPORT)
    719    bcm_port_t          cpu_port;
    720    cpu_port = CMIC_PORT(unit);
    721 #endif
    722 
    723    if (SOC_WARM_BOOT_SCACHE_IS_LIMITED(unit)) {
    724        return BCM_E_NONE;
    725    }
    726    SOC_SCACHE_HANDLE_SET(scache_handle, unit, BCM_MODULE_RX, 0);
    727    rv = _bcm_esw_scache_ptr_get(unit, scache_handle, FALSE,
    728                                 0, &rx_scache_ptr,
    729                                 BCM_RX_WB_DEFAULT_VERSION, &recovered_ver);
    730    if (rv == SOC_E_NOT_FOUND) {
    731        /* Use non-Level 2 case for recovery */
    732        /* and Allocate scache space for further syncs */
    733        BCM_IF_ERROR_RETURN(_bcm_esw_rx_wb_scache_alloc(unit));
    734    }  else if (SOC_FAILURE(rv)) {
    735        return rv;
    736    } else { /* Use Level 2 cache */
    737 
    738        sal_memcpy(&RX_PPS(unit), rx_scache_ptr, sizeof(RX_PPS(unit)));
    739        rx_scache_ptr += sizeof(RX_PPS(unit));
    740 
    741        sal_memcpy(&RX_BURST(unit), rx_scache_ptr, sizeof(RX_BURST(unit)));
    742        rx_scache_ptr += sizeof(RX_BURST(unit));
    743 
    744        sal_memcpy(&system_pps, rx_scache_ptr, sizeof(system_pps));
    745        BCM_IF_ERROR_RETURN(bcm_esw_rx_cpu_rate_set(unit, system_pps));
    746        rx_scache_ptr += sizeof(system_pps);
    747 
    748        for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    749             queue = RX_QUEUE(unit, cosq);
    750             /* Retrieve PPS and Burst configuration of cpu cosq's from L2 
    751                cache if harware rate limit is not supported */
    752             if (!soc_feature(unit, soc_feature_packet_rate_limit)) {
    753                 sal_memcpy(&queue->pps, rx_scache_ptr, sizeof(queue->pps));
    754                 rx_scache_ptr += sizeof(queue->pps);
    755                 sal_memcpy(&queue->burst, rx_scache_ptr, sizeof(queue->burst));
    756                 rx_scache_ptr += sizeof(queue->burst);
    757             }
    758             sal_memcpy(&queue->max_len, rx_scache_ptr, sizeof(queue->max_len));
    759             if (cosq < RX_QUEUE_MAX(unit)) {
    760                 rx_scache_ptr += sizeof(queue->max_len);
    761             }
    762        } 
    763        if (recovered_ver >= BCM_RX_WB_VERSION_1_1) {
    764 #if defined (BCM_TRIDENT2PLUS_SUPPORT)
    765            if (SOC_IS_TRIDENT2PLUS(unit) &&
    766                    soc_feature(unit, soc_feature_fp_based_oam)) {
    767                sal_memcpy(&RX_OLP_MATCH_RULE(unit), rx_scache_ptr, sizeof(RX_OLP_MATCH_RULE(unit)));
    768                rx_scache_ptr += sizeof(RX_OLP_MATCH_RULE(unit));
    769            }
    770 #endif
    771        } else {
    772 #if defined (BCM_TRIDENT2PLUS_SUPPORT)
    773            if (SOC_IS_TRIDENT2PLUS(unit) &&
    774                    soc_feature(unit, soc_feature_fp_based_oam)) {
    775 
    776                additional_scache_size += sizeof(RX_OLP_MATCH_RULE(unit));
    777            }
    778 #endif 
    779        }
    780        if (additional_scache_size > 0) {
    781            SOC_IF_ERROR_RETURN(soc_scache_realloc(unit, scache_handle,
    782                                                        additional_scache_size));
    783        }
    784    }
    785 
    786    /* Recover PPS and Burst settings from Hardware */
    787 #if defined(BCM_TRX_SUPPORT) || defined(BCM_FIREBOLT2_SUPPORT)
    788    if (soc_feature(unit, soc_feature_packet_rate_limit)) {
    789 #ifdef BCM_TRIDENT_SUPPORT
    790 #ifdef BCM_TRIDENT2_SUPPORT
    791 #ifdef BCM_TOMAHAWK3_SUPPORT
    792       if (SOC_IS_TOMAHAWK3(unit)) {
    793           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    794                BCM_IF_ERROR_RETURN(bcm_th3_cosq_port_pps_get(unit, cpu_port,
    795                                            cosq, &RX_COS_PPS(unit, cosq)));
    796                BCM_IF_ERROR_RETURN(bcm_th3_cosq_port_burst_get(unit, cpu_port,
    797                                           cosq, &RX_COS_BURST(unit, cosq)));
    798           }
    799       }
    800 #endif /* BCM_TOMAHAWK3_SUPPORT */
    801 #ifdef BCM_TOMAHAWK_SUPPORT
    802       if (SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TOMAHAWK3(unit)) {
    803           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    804                BCM_IF_ERROR_RETURN(bcm_th_cosq_port_pps_get(unit, cpu_port,
    805                                            cosq, &RX_COS_PPS(unit, cosq)));
    806                BCM_IF_ERROR_RETURN(bcm_th_cosq_port_burst_get(unit, cpu_port,
    807                                           cosq, &RX_COS_BURST(unit, cosq)));
    808           }
    809       }
    810 #endif /* BCM_TOMAHAWK_SUPPORT */
    811 #ifdef BCM_HELIX5_SUPPORT
    812       if (SOC_IS_HELIX5(unit)) {
    813           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    814               BCM_IF_ERROR_RETURN
    815                   (bcm_hx5_cosq_port_pps_get(unit, cpu_port, cosq,
    816                                              &RX_COS_PPS(unit, cosq)));
    817               BCM_IF_ERROR_RETURN
    818                   (bcm_hx5_cosq_port_burst_get(unit, cpu_port, cosq,
    819                                                &RX_COS_BURST(unit, cosq)));
    820           }
    821       } else
    822 #endif /* BCM_HELIX5_SUPPORT */
    823 #ifdef BCM_MONTEREY_SUPPORT
    824       if (SOC_IS_MONTEREY(unit)) {
    825           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    826                rv = bcm_mn_cosq_port_pps_get(unit, cpu_port, cosq,
    827                                              &RX_COS_PPS(unit, cosq));
    828                if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    829                    return rv;
    830                }
    831                rv = bcm_mn_cosq_port_burst_get(unit, cpu_port, cosq,
    832                                                &RX_COS_BURST(unit, cosq));
    833                if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    834                    return rv;
    835                }
    836           }
    837       } else
    838 #endif
    839 #ifdef BCM_TRIDENT3_SUPPORT
    840       if (SOC_IS_TRIDENT3X(unit)) {
    841           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    842               BCM_IF_ERROR_RETURN
    843                   (bcm_td3_cosq_port_pps_get(unit, cpu_port, cosq,
    844                                              &RX_COS_PPS(unit, cosq)));
    845               BCM_IF_ERROR_RETURN
    846                   (bcm_td3_cosq_port_burst_get(unit, cpu_port, cosq,
    847                                                &RX_COS_BURST(unit, cosq)));
    848           }
    849       } else
    850 #endif /* BCM_TRIDENT3_SUPPORT */
    851 #ifdef BCM_APACHE_SUPPORT
    852       if (SOC_IS_APACHE(unit)) {
    853           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    854                rv = bcm_ap_cosq_port_pps_get(unit, cpu_port, cosq,
    855                                              &RX_COS_PPS(unit, cosq));
    856                if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    857                    return rv;
    858                }
    859                rv = bcm_ap_cosq_port_burst_get(unit, cpu_port, cosq,
    860                                                &RX_COS_BURST(unit, cosq));
    861                if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    862                    return rv;
    863                }
    864           }
    865       } else
    866 #endif
    867       if (SOC_IS_TD2_TT2(unit) && !SOC_IS_TOMAHAWKX(unit) && !SOC_IS_TRIDENT3X(unit)) {
    868           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    869                rv = bcm_td2_cosq_port_pps_get(unit, cpu_port,
    870                                             cosq, &RX_COS_PPS(unit, cosq));
    871                if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    872                    return rv;
    873                }
    874                rv = bcm_td2_cosq_port_burst_get(unit, cpu_port,
    875                                            cosq, &RX_COS_BURST(unit, cosq));
    876                if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    877                    return rv;
    878                }
    879           }
    880       }
    881 #endif 
    882       if (SOC_IS_TRIDENT(unit) || SOC_IS_TITAN(unit)) {
    883           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    884                BCM_IF_ERROR_RETURN(bcm_td_cosq_port_pps_get(unit, cpu_port,
    885                                             cosq, &RX_COS_PPS(unit, cosq)));
    886                BCM_IF_ERROR_RETURN(bcm_td_cosq_port_burst_get(unit, cpu_port,
    887                                             cosq, &RX_COS_BURST(unit, cosq)));
    888           }
    889       } 
    890 #endif
    891 #ifdef BCM_TRIUMPH3_SUPPORT
    892       if (SOC_IS_TRIUMPH3(unit)) {
    893           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    894                rv = bcm_tr3_cosq_port_pps_get(unit, cpu_port,
    895                                             cosq, &RX_COS_PPS(unit, cosq));
    896                /* cosq config may not be complete before warmboot. such
    897                 * cases will return BCM_E_NOT_FOUND and needs to be ignored.
    898                 */
    899                if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    900                    return rv;
    901                }
    902                rv = bcm_tr3_cosq_port_burst_get(unit, cpu_port,
    903                                             cosq, &RX_COS_BURST(unit, cosq));
    904                if (BCM_FAILURE(rv) && (rv != BCM_E_NOT_FOUND)) {
    905                    return rv;
    906                }
    907           }
    908       } 
    909 #endif
    910 #ifdef BCM_KATANA2_SUPPORT
    911       if (SOC_IS_KATANA2(unit)) {
    912           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    913                BCM_IF_ERROR_RETURN(bcm_kt2_cosq_port_pps_get(unit, cpu_port,
    914                                             cosq, &RX_COS_PPS(unit, cosq)));
    915                BCM_IF_ERROR_RETURN(bcm_kt2_cosq_port_burst_get(unit, cpu_port,
    916                                             cosq, &RX_COS_BURST(unit, cosq)));
    917           }
    918       }
    919 #endif
    920 #ifdef BCM_KATANA_SUPPORT 
    921       if (SOC_IS_KATANA(unit)) {
    922           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    923                BCM_IF_ERROR_RETURN(bcm_kt_cosq_port_pps_get(unit, cpu_port,
    924                                             cosq, &RX_COS_PPS(unit, cosq)));
    925                BCM_IF_ERROR_RETURN(bcm_kt_cosq_port_burst_get(unit, cpu_port,
    926                                             cosq, &RX_COS_BURST(unit, cosq)));
    927           }
    928       }
    929 #endif
    930 #ifdef BCM_TRIUMPH2_SUPPORT
    931       if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
    932           SOC_IS_VALKYRIE2(unit)) {
    933           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    934                BCM_IF_ERROR_RETURN(bcm_tr2_cosq_port_pps_get(unit, cpu_port,
    935                                             cosq, &RX_COS_PPS(unit, cosq)));
    936                BCM_IF_ERROR_RETURN(bcm_tr2_cosq_port_burst_get(unit, cpu_port,
    937                                             cosq, &RX_COS_BURST(unit, cosq)));
    938           }
    939       }
    940 #endif
    941 #ifdef BCM_FIREBOLT2_SUPPORT
    942       if (SOC_IS_FIREBOLT2(unit)) {
    943           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    944                BCM_IF_ERROR_RETURN(bcm_fb2_cosq_port_pps_get(unit, cpu_port,
    945                                             cosq, &RX_COS_PPS(unit, cosq)));
    946                BCM_IF_ERROR_RETURN(bcm_fb2_cosq_port_burst_get(unit, cpu_port,
    947                                             cosq, &RX_COS_BURST(unit, cosq)));
    948           }
    949       }
    950 #endif
    951 #ifdef BCM_TRX_SUPPORT
    952       if (SOC_IS_TRIUMPH(unit) || SOC_IS_VALKYRIE(unit) || 
    953           SOC_IS_ENDURO(unit) || SOC_IS_SCORPION(unit)) {
    954           for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
    955                BCM_IF_ERROR_RETURN(bcm_tr_cosq_port_pps_get(unit, cpu_port,
    956                                             cosq, &RX_COS_PPS(unit, cosq)));
    957                BCM_IF_ERROR_RETURN(bcm_tr_cosq_port_burst_get(unit, cpu_port,
    958                                            cosq, &RX_COS_BURST(unit, cosq)));
    959           }
    960       }
    961 #endif
    962    }
    963 #endif /* BCM_FIREBOLT2_SUPPORT || BCM_TRX_SUPPORT */
    964 
    965 #if defined (BCM_EP_REDIRECT_VERSION_2)
    966    /* Sync the inuse bitmap for copy-to-cpu config */
    967    if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
    968 
    969         int size = 0, table_count, i = 0;
    970 
    971         /* Get the table depth */
    972         table_count = soc_mem_index_count(unit, EP_CTC_RES_TABLEm);
    973 
    974         /* Copy over the indidivual values into s/w structs */
    975         for(i = 0; i < table_count; i++) {
    976 
    977             sal_memcpy(&BCMI_GET_COPY_TOCPU_FLAGS_GET(unit, i),
    978                         rx_scache_ptr,
    979                         BCMI_GET_COPY_TOCPU_FLAGS_SIZE_GET(unit));
    980             rx_scache_ptr += BCMI_GET_COPY_TOCPU_FLAGS_SIZE_GET(unit );
    981 
    982             sal_memcpy(&BCMI_GET_COPY_TOCPU_DROP_REASONS_GET(unit, i),
    983                         rx_scache_ptr,
    984                         BCMI_GET_COPY_TOCPU_DROP_REASONS_SIZE_GET(unit));
    985             rx_scache_ptr += BCMI_GET_COPY_TOCPU_DROP_REASONS_SIZE_GET(unit);
    986 
    987             sal_memcpy(&BCMI_GET_COPY_TOCPU_STRENGTH_GET(unit, i),
    988                         rx_scache_ptr,
    989                         BCMI_GET_COPY_TOCPU_STRENGTH_SIZE_GET(unit));
    990             rx_scache_ptr += BCMI_GET_COPY_TOCPU_STRENGTH_SIZE_GET(unit);
    991 
    992             sal_memcpy(&BCMI_GET_COPY_TOCPU_BUFFER_PRIORITY_GET(unit, i),
    993                         rx_scache_ptr,
    994                         BCMI_GET_COPY_TOCPU_BUFFER_PRIORITY_SIZE_GET(unit));
    995             rx_scache_ptr += BCMI_GET_COPY_TOCPU_BUFFER_PRIORITY_SIZE_GET(unit);
    996 
    997             sal_memcpy(&BCMI_GET_COPY_TOCPU_COS_Q_GET(unit, i),
    998                         rx_scache_ptr,
    999                         BCMI_GET_COPY_TOCPU_COS_Q_SIZE_GET(unit));
   1000             rx_scache_ptr += BCMI_GET_COPY_TOCPU_COS_Q_SIZE_GET(unit);
   1001         }
   1002 
   1003         /* Recover the copy-to-cpu inuse bitmap */
   1004         size = SHR_BITALLOCSIZE(table_count);
   1005         sal_memcpy(_bcmi_rx_egr_drop_copy_to_cpu_loc_bitmap[unit], rx_scache_ptr, size);
   1006         rx_scache_ptr += size;
   1007    }
   1008 #endif
   1009 #if defined (BCM_KATANA_SUPPORT)
   1010    if (SOC_IS_KATANAX(unit)) {
   1011        if (recovered_ver >= BCM_RX_WB_VERSION_1_2) {
   1012            sal_memcpy(&rx_ctl[unit]->flags, rx_scache_ptr, sizeof(rx_ctl[unit]->flags));
   1013        }
   1014    }
   1015 #endif
   1016 
   1017    return BCM_E_NONE;
   1018 }
   1019 
   1020 /*
   1021  * Function:
   1022  *      _bcm_esw_rx_sync
   1023  * Purpose:
   1024  *      Record rx module persisitent info for Level 2 Warm Boot
   1025  * Parameters:
   1026  *      unit - StrataSwitch unit number.
   1027  * Returns:
   1028  *      BCM_E_XXX
   1029  */
   1030 
   1031 int 
   1032 _bcm_esw_rx_sync(int unit) 
   1033 {
   1034    soc_scache_handle_t scache_handle;
   1035    uint8 *rx_scache_ptr;
   1036    rx_queue_t *cpu_queue;
   1037    int system_pps;
   1038    int cosq;
   1039 	
   1040    if (!RX_IS_LOCAL(unit)|| !SOC_UNIT_VALID(unit)) {
   1041        return BCM_E_NONE;
   1042    }
   1043    if (SOC_WARM_BOOT_SCACHE_IS_LIMITED(unit)) {
   1044        return BCM_E_NONE;
   1045    }
   1046    SOC_SCACHE_HANDLE_SET(scache_handle, unit, BCM_MODULE_RX, 0);
   1047    BCM_IF_ERROR_RETURN
   1048         (_bcm_esw_scache_ptr_get(unit, scache_handle, FALSE,
   1049                                  0, &rx_scache_ptr,
   1050                                  BCM_RX_WB_DEFAULT_VERSION, NULL));
   1051 
   1052    /* global_pps configuration */
   1053    sal_memcpy(rx_scache_ptr, &RX_PPS(unit), sizeof(RX_PPS(unit)));   
   1054    rx_scache_ptr += sizeof(RX_PPS(unit));
   1055 
   1056    /* max_burst configuration */
   1057    sal_memcpy(rx_scache_ptr, &RX_BURST(unit), sizeof(RX_BURST(unit)));
   1058    rx_scache_ptr += sizeof(RX_BURST(unit));
   1059 
   1060    /* system_pps configuration */
   1061    BCM_IF_ERROR_RETURN(bcm_esw_rx_cpu_rate_get(unit, &system_pps));
   1062    sal_memcpy(rx_scache_ptr, &system_pps, sizeof(system_pps)); 
   1063    rx_scache_ptr += sizeof(system_pps);
   1064 
   1065    for (cosq = 0; cosq <= RX_QUEUE_MAX(unit); cosq++) {
   1066        cpu_queue = RX_QUEUE(unit, cosq);
   1067 
   1068        /* Store per queue PPS and Burst settings in L2 cache
   1069            if harware rate limit is not supported */
   1070        if (!soc_feature(unit, soc_feature_packet_rate_limit)) {
   1071            sal_memcpy(rx_scache_ptr, &cpu_queue->pps, sizeof(cpu_queue->pps));
   1072            rx_scache_ptr += sizeof(cpu_queue->pps);
   1073 
   1074            sal_memcpy(rx_scache_ptr, &cpu_queue->burst, sizeof(cpu_queue->burst));
   1075            rx_scache_ptr += sizeof(cpu_queue->burst);
   1076        }
   1077 
   1078        /* To store max permitted packets configuration */
   1079        sal_memcpy(rx_scache_ptr, &cpu_queue->max_len, sizeof(cpu_queue->max_len));
   1080        if (cosq < RX_QUEUE_MAX(unit)) {
   1081            rx_scache_ptr += sizeof(cpu_queue->max_len);
   1082        }
   1083    }
   1084 #if defined (BCM_TRIDENT2PLUS_SUPPORT)
   1085    /* save OLP match_rule value */
   1086    if (SOC_IS_TRIDENT2PLUS(unit) &&
   1087            soc_feature(unit, soc_feature_fp_based_oam)) {
   1088        sal_memcpy(rx_scache_ptr, &RX_OLP_MATCH_RULE(unit), sizeof(RX_OLP_MATCH_RULE(unit)));
   1089        rx_scache_ptr += sizeof(RX_OLP_MATCH_RULE(unit));
   1090    }
   1091 #endif
   1092 
   1093 #if defined (BCM_EP_REDIRECT_VERSION_2)
   1094    /* Sync the inuse bitmap for copy-to-cpu config */
   1095    if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
   1096 
   1097        int i = 0, table_count = 0, size = 0;
   1098 
   1099        /* Sync the copy-to-cpu config data */
   1100        /* Get the table depth */
   1101        table_count = soc_mem_index_count(unit, EP_CTC_RES_TABLEm);
   1102 
   1103        /* Sync over the indidivual values from s/w structs */
   1104        for(i = 0; i < table_count; i++) {
   1105            sal_memcpy(rx_scache_ptr,
   1106                       &BCMI_GET_COPY_TOCPU_FLAGS_GET(unit, i),
   1107                            BCMI_GET_COPY_TOCPU_FLAGS_SIZE_GET(unit));
   1108            rx_scache_ptr += BCMI_GET_COPY_TOCPU_FLAGS_SIZE_GET(unit);
   1109 
   1110            sal_memcpy(rx_scache_ptr,
   1111                       &BCMI_GET_COPY_TOCPU_DROP_REASONS_GET(unit, i),
   1112                       BCMI_GET_COPY_TOCPU_DROP_REASONS_SIZE_GET(unit));
   1113            rx_scache_ptr += BCMI_GET_COPY_TOCPU_DROP_REASONS_SIZE_GET(unit);
   1114 
   1115            sal_memcpy(rx_scache_ptr,
   1116                       &BCMI_GET_COPY_TOCPU_STRENGTH_GET(unit, i),
   1117                       BCMI_GET_COPY_TOCPU_STRENGTH_SIZE_GET(unit));
   1118            rx_scache_ptr += BCMI_GET_COPY_TOCPU_STRENGTH_SIZE_GET(unit);
   1119 
   1120            sal_memcpy(rx_scache_ptr,
   1121                       &BCMI_GET_COPY_TOCPU_BUFFER_PRIORITY_GET(unit, i),
   1122                       BCMI_GET_COPY_TOCPU_BUFFER_PRIORITY_SIZE_GET(unit));
   1123            rx_scache_ptr += BCMI_GET_COPY_TOCPU_BUFFER_PRIORITY_SIZE_GET(unit);
   1124 
   1125            sal_memcpy(rx_scache_ptr,
   1126                       &BCMI_GET_COPY_TOCPU_COS_Q_GET(unit, i),
   1127                       BCMI_GET_COPY_TOCPU_COS_Q_SIZE_GET(unit));
   1128            rx_scache_ptr += BCMI_GET_COPY_TOCPU_COS_Q_SIZE_GET(unit);
   1129 
   1130        }
   1131 
   1132        /* Sync the copy-to-cpu inuse bitmap */
   1133        size = SHR_BITALLOCSIZE(table_count);
   1134        sal_memcpy(rx_scache_ptr, _bcmi_rx_egr_drop_copy_to_cpu_loc_bitmap[unit], size);
   1135        rx_scache_ptr += size;
   1136    }
   1137 #endif
   1138 #if defined (BCM_KATANA_SUPPORT)
   1139    if (SOC_IS_KATANAX(unit)) {
   1140        /* Clear BCM_RX_F_STARTED before sync. Need to restart CPU rx after warmboot */
   1141        rx_ctl[unit]->flags &= ~BCM_RX_F_STARTED;
   1142        sal_memcpy(rx_scache_ptr, &rx_ctl[unit]->flags, sizeof(rx_ctl[unit]->flags));
   1143    }
   1144 #endif
   1145   return BCM_E_NONE;
   1146 }
   1147 #endif /* BCM_WARM_BOOT_SUPPORT */
   1148 
   1149 #ifdef BCM_TRX_SUPPORT
   1150 
   1151 /* CPU_COS_MAP_KEY format for TRX */
   1152 #define _bcm_scorpion_rx_cpu_cosmap_key_max             39
   1153 #define _bcm_triumph_rx_cpu_cosmap_key_max              44
   1154 #define _bcm_triumph2_rx_cpu_cosmap_key_max             59
   1155 #define _bcm_trident_rx_cpu_cosmap_key_max              60
   1156 #define _bcm_katana_rx_cpu_cosmap_key_max               62
   1157 #define _bcm_enduro_rx_cpu_cosmap_key_max               50
   1158 #define _bcm_triumph_rx_cpu_max_cosq                    48
   1159 #define _bcm_trident2_rx_cpu_max_cosq                   48
   1160 #define _bcm_tomahawk3_rx_cpu_max_cosq                  48
   1161 #define _bcm_katana2_rx_cpu_max_cosq                    48
   1162 #define _bcm_triumph3_rx_cpu_max_cosq                   45
   1163 #define _bcm_triumph3_rx_cpu_max_cosq_a0_a1             48
   1164 #define _bcm_scorpion_rx_cpu_max_cosq                   32
   1165 #define _bcm_hurricane_rx_cpu_max_cosq                   8
   1166 #define _bcm_tr3_rx_ip_cpu_cosmap_key_max               90
   1167 #define _bcm_tr3_rx_ep_cpu_cosmap_key_max               15
   1168 #define _bcm_tr3_rx_nlf_cpu_cosmap_key_max               7
   1169 #define _bcm_tr3_rx_cpu_cosmap_key_overlays              3
   1170 #define _bcm_tr3_rx_cpu_cosmap_key_words                 3
   1171 #define _bcm_tr3_rx_cpu_cosmap_reason_type_mask        0x3
   1172 #define _bcm_rx_cpu_cosmap_key_words_max                 3 /* For now */
   1173 
   1174 
   1175 
   1176 static bcm_rx_reason_t 
   1177 _bcm_trx_cpu_cos_map_key [] =
   1178 {
   1179     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   1180     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   1181     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   1182     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   1183     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   1184     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   1185     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   1186     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   1187     bcmRxReasonParityError,             /* PARITY_ERROR */
   1188     bcmRxReasonHigigControl,            /* MH_CONTROL */
   1189     bcmRxReasonTtl1,                    /* TTL_1 */
   1190     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   1191     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   1192     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   1193     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   1194     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   1195     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   1196     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   1197     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   1198     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   1199     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   1200     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   1201     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   1202     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   1203     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   1204     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   1205     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   1206     bcmRxReasonVlanFilterMatch,         /* VFP */
   1207     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   1208     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   1209     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   1210     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   1211     bcmRxReasonNhop,                    /* NHOP */
   1212     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   1213     bcmRxReasonFilterMatch,             /* CPU_FFP */
   1214     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   1215     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   1216     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   1217     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   1218 
   1219     /* Below are not available for Scorpion */
   1220     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   1221     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   1222     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   1223     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   1224     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   1225 
   1226     /* Below are not available Triumph */
   1227     bcmRxReasonMplsCtrlWordError,       /* MPLS_CW_TYPE_NOT_ZERO */
   1228     bcmRxReasonMmrp,                    /* PROTOCOL_MMRP */
   1229     bcmRxReasonSrp,                     /* PROTOCOL_SRP */
   1230     bcmRxReasonWlanSlowpathKeepalive,   /* CAPWAP_KEEPALIVE */
   1231     bcmRxReasonWlanClientError,         /* WLAN_CLIENT_DATABASE_ERROR */
   1232     bcmRxReasonWlanDot1xDrop,           /* WLAN_DOT1X_DROP */
   1233     bcmRxReasonWlanSlowpath,            /* WLAN_CAPWAP_SLOWPATH */
   1234     bcmRxReasonEncapHigigError,         /* EHG_NONHG */
   1235     bcmRxReasonTunnelControl,           /* AMT_CONTROL_PKT */
   1236     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   1237     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   1238     bcmRxReasonOAMError,                /* OAM_ERROR */
   1239     bcmRxReasonL2Marked,                /* PROTOCOL_L2_PKT */
   1240     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   1241     bcmRxReasonIpfixRateViolation       /* IPFIX_FLOW */
   1242 };
   1243 
   1244 #ifdef BCM_TOMAHAWK3_SUPPORT
   1245 static bcm_rx_reason_t
   1246 _bcm_th3_cpu_cos_map_key [] =
   1247 {
   1248     bcmRxReasonTunnelControl,           /* 0: AMT_CONTROL_PKT */
   1249     bcmRxReasonBfd,                     /* 1: BFD_ERROR */
   1250     bcmRxReasonBfdSlowpath,             /* 2: BFD_SLOWPATH */
   1251     bcmRxReasonClassBasedMove,          /* 3:CBSM_PREVENTED */
   1252     bcmRxReasonDLBMonitor,              /* 4:DLB_MONITOR_TO_CPU */
   1253     bcmRxReasonL2DestMiss,              /* 5:CPU_DLF */
   1254     bcmRxReasonDosAttack,               /* 6:CPU_DOS_ATTACK */
   1255     bcmRxReasonETrapMonitor,            /* 7:ETRAP_MONITOR_TO_CPU */
   1256     bcmRxReasonFilterMatch,             /* 8:CPU_FFP */
   1257     bcmRxReasonInvalid,                 /* 9:RESERVED Remote CPU*/
   1258     bcmRxReasonInvalid,                 /* 10:RESERVED */
   1259     bcmRxReasonInvalid,                 /* 11:RESERVED */
   1260     bcmRxReasonInvalid,                 /* 12:RESERVED */
   1261     bcmRxReasonInvalid,                 /* 13:RESERVED */
   1262     bcmRxReasonInvalid,                 /* 14:RESERVED */
   1263     bcmRxReasonInvalid,                 /* 15:RESERVED */
   1264     bcmRxReasonInvalid,                 /* 16:RESERVED */
   1265     bcmRxReasonInvalid,                 /* 17:RESERVED */
   1266     bcmRxReasonHigigHdrError,           /* 18:HGHDR_ERROR */
   1267     bcmRxReasonClassTagPackets,         /* 19:HG_HDR_TYPE1 */
   1268     bcmRxReasonIcmpRedirect,            /* 20:ICMP_REDIRECT */
   1269     bcmRxReasonTimesyncUnknownVersion,  /* 21:IEEE1588_UNKNOWN_VERSION */
   1270     bcmRxReasonReserved0,               /* 22:INSTRUMENT_OFFSET */
   1271     bcmRxReasonIntHopLimit,             /* 23:IXME_KP:INT_HOP_LIMIT_TO_CPU */
   1272     bcmRxReasonIntTurnAround,           /* 24:INT_TURNAROUND_TO_CPU */
   1273     bcmRxReasonIpmcInterfaceMismatch,   /* 25:CPU_IPMC_INTERFACE_MISMATCH */
   1274     bcmRxReasonIpMcastMiss,             /* 26:CPU_IPMC_MISS */
   1275     bcmRxReasonL3Slowpath,              /* 27:IP_OPTIONS_PKT. */
   1276     bcmRxReasonL2Cpu,                   /* 28:CPU_L2CPU */
   1277     bcmRxReasonL2GreSipMiss,            /* 29:L2GRE_SIP_MISS */
   1278     bcmRxReasonL2GreVpnIdMiss,          /* 30:L2GRE_VPNID_MISS */
   1279     bcmRxReasonL2Move,                  /* 31:CPU_L2MOVE */
   1280     bcmRxReasonL3DestMiss,              /* 32:CPU_L3DST_MISS */
   1281     bcmRxReasonL3HeaderError,           /* 33:CPU_L3HDR_ERR */
   1282     bcmRxReasonL3SourceMiss,            /* 34:CPU_L3SRC_MISS. */
   1283     bcmRxReasonL3SourceMove,            /* 35:CPU_L3SRC_MOVE */
   1284     bcmRxReasonL3MtuFail,               /* 36:L3_MTU_CHECK_FAIL */
   1285     bcmRxReasonL3AddrBindFail,          /* 37:MAC_BIND_FAIL */
   1286     bcmRxReasonMartianAddr,             /* 38:CPU_MARTIAN_ADDR */
   1287     bcmRxReasonMcastIdxError,           /* 39:MCIDX_ERROR */
   1288     bcmRxReasonMcastMiss,               /* 40:CPU_MC_MISS */
   1289     bcmRxReasonHigigControl,            /* 41:MH_CONTROL */
   1290     bcmRxReasonMplsRouterAlertLabel,    /* 42:MPLS_ALERT_LABEL */
   1291     bcmRxReasonMplsIllegalReservedLabel,/* 43:MPLS_ILLEGAL_RESERVED_LABEL */
   1292     bcmRxReasonMplsInvalidAction,       /* 44:MPLS_INVALID_ACTION */
   1293     bcmRxReasonMplsInvalidPayload,      /* 45:MPLS_INVALID_PAYLOAD */
   1294     bcmRxReasonMplsLabelMiss,           /* 46:MPLS_LABEL_MISS */
   1295     bcmRxReasonMplsSequenceNumber,      /* 47:MPLS_SEQ_NUM_FAIL */
   1296     bcmRxReasonMplsTtl,                 /* 48:MPLS_TTL_CHECK_FAIL */
   1297     bcmRxReasonMplsUnknownAch,          /* 49:MPLS_UNKNOWN_ACH_ERROR */
   1298     bcmRxReasonStation,                 /* 50:MY_STATION */
   1299     bcmRxReasonNat,                     /* 51:NAT_DROP_REASON_ENCODING */
   1300     bcmRxReasonNat,                     /* 52:NAT_DROP_REASON_ENCODING */
   1301     bcmRxReasonNat,                     /* 53:NAT_DROP_REASON_ENCODING */
   1302     bcmRxReasonNhop,                    /* 54:NHOP_OFFSET */
   1303     bcmRxReasonOAMError,                /* 55:OAM_ERROR */
   1304     bcmRxReasonOAMSlowpath,             /* 56:OAM_SLOWPATH */
   1305 #if 1
   1306     bcmRxReasonInvalid,                 /* 57:NOT DEFINED */
   1307 #endif
   1308     bcmRxReasonParityError,             /* 58:PARITY_ERROR */
   1309     bcmRxReasonL2NonUnicastMiss,        /* 59:PBT_NONUC_PKT */
   1310     bcmRxReasonArp,                     /* 60:PROTOCOL_ARP */
   1311     bcmRxReasonBpdu,                    /* 61:PROTOCOL_BPDU */
   1312     bcmRxReasonDhcp,                    /* 62:PROTOCOL_DHCP */
   1313     bcmRxReasonIgmp,                    /* 63:PROTOCOL_IGMP */
   1314     bcmRxReasonIpmcReserved,            /* 64:PROTOCOL_IPMC_RSVD */
   1315     bcmRxReasonL2Marked,                /* 65:PROTOCOL_L2_PKT */
   1316     bcmRxReasonMmrp,                    /* 66:PROTOCOL_MMRP */
   1317     bcmRxReasonSrp,                     /* 67:PROTOCOL_SRP */
   1318     bcmRxReasonSharedVlanMismatch,      /* 68:PVLAN_MISMATCH */
   1319     bcmRxReasonSampleDest,              /* 69:CPU_SFLOW_DST */
   1320     bcmRxReasonSampleSourceFlex,        /* 70:CPU_SFLOW_FLEX */
   1321     bcmRxReasonSampleSource,            /* 71:CPU_SFLOW_SRC */
   1322     bcmRxReasonL2SourceMiss,            /* 72:CPU_SLF */
   1323     bcmRxReasonTimeSync,                /* 73:TIME_SYNC_PKT */
   1324     bcmRxReasonTtl1,                    /* 74:TTL_1 */
   1325     bcmRxReasonTunnelDecapEcnError,     /* 75:TUNNEL_DECAP_ECN_ERR */
   1326     bcmRxReasonTunnelError,             /* 76:CPU_TUNNEL_ERR */
   1327     bcmRxReasonUrpfFail,                /* 77:URPF_FAILED */
   1328     bcmRxReasonUnknownVlan,             /* 78:CPU_UVLAN. */
   1329     bcmRxReasonVlanFilterMatch,         /* 79:VFP */
   1330     bcmRxReasonVlanTranslate,           /* 80:VXLT_MISS */
   1331 };
   1332 #endif
   1333 
   1334 #ifdef BCM_ENDURO_SUPPORT
   1335 static bcm_rx_reason_t 
   1336 _bcm_enduro_cpu_cos_map_key [] =
   1337 {
   1338     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   1339     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   1340     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   1341     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   1342     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   1343     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   1344     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   1345     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   1346     bcmRxReasonParityError,             /* PARITY_ERROR */
   1347     bcmRxReasonHigigControl,            /* MH_CONTROL */
   1348     bcmRxReasonTtl1,                    /* TTL_1 */
   1349     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   1350     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   1351     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   1352     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   1353     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   1354     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   1355     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   1356     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   1357     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   1358     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   1359     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   1360     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   1361     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   1362     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   1363     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   1364     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   1365     bcmRxReasonVlanFilterMatch,         /* VFP */
   1366     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   1367     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   1368     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   1369     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   1370     bcmRxReasonNhop,                    /* NHOP */
   1371     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   1372     bcmRxReasonFilterMatch,             /* CPU_FFP */
   1373     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   1374     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   1375     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   1376     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   1377     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   1378     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   1379     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   1380     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   1381     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   1382     bcmRxReasonMplsCtrlWordError,       /* MPLS_CW_TYPE_NOT_ZERO */
   1383     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   1384     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   1385     bcmRxReasonOAMError,                /* OAM_ERROR */
   1386     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   1387     bcmRxReasonL2Marked                 /* PROTOCOL_L2_PKT */
   1388 };
   1389 #endif /* BCM_ENDURO_SUPPORT */
   1390 
   1391 #ifdef BCM_TRIDENT_SUPPORT
   1392 static bcm_rx_reason_t 
   1393 _bcm_trident_cpu_cos_map_key [] =
   1394 {
   1395     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   1396     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   1397     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   1398     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   1399     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   1400     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   1401     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   1402     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   1403     bcmRxReasonParityError,             /* PARITY_ERROR */
   1404     bcmRxReasonHigigControl,            /* MH_CONTROL */
   1405     bcmRxReasonTtl1,                    /* TTL_1 */
   1406     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   1407     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   1408     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   1409     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   1410     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   1411     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   1412     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   1413     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   1414     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   1415     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   1416     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   1417     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   1418     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   1419     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   1420     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   1421     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   1422     bcmRxReasonVlanFilterMatch,         /* VFP */
   1423     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   1424     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   1425     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   1426     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   1427     bcmRxReasonNhop,                    /* NHOP */
   1428     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   1429     bcmRxReasonFilterMatch,             /* CPU_FFP */
   1430     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   1431     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   1432     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   1433     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   1434     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   1435     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   1436     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   1437     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   1438     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   1439     bcmRxReasonMplsCtrlWordError,       /* MPLS_CW_TYPE_NOT_ZERO */
   1440     bcmRxReasonMmrp,                    /* PROTOCOL_MMRP */
   1441     bcmRxReasonSrp,                     /* PROTOCOL_SRP */
   1442     bcmRxReasonStation,                 /* MY_STATION */
   1443     bcmRxReasonNiv,                     /* NIV_DROP_REASON_ENCODING */
   1444     bcmRxReasonNiv,                     /*   -> */
   1445     bcmRxReasonNiv,                     /* 3 bits */
   1446     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   1447     bcmRxReasonTunnelControl,           /* AMT_CONTROL_PKT */
   1448     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   1449     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   1450     bcmRxReasonOAMError,                /* OAM_ERROR */
   1451     bcmRxReasonL2Marked,                /* PROTOCOL_L2_PKT */
   1452     bcmRxReasonTrill,                   /* TRILL_DROP_REASON_ENCODING */
   1453     bcmRxReasonTrill,                   /*   -> */
   1454     bcmRxReasonTrill                    /* 3 bits */
   1455 };
   1456 
   1457 /* From FORMAT TRILL_CPU_OPCODE_ENCODING */
   1458 static bcm_rx_reason_t
   1459 _bcm_trill_cpu_opcode_encoding[] =
   1460 {
   1461     bcmRxReasonTrill,            /* 0:NO_ERRORS
   1462                                   * Base field, must match the entries above */
   1463     bcmRxReasonTrillInvalid,     /* 1:TRILL_HDR_ERROR */
   1464     bcmRxReasonTrillMiss,        /* 2:TRILL_LOOKUP_MISS */
   1465     bcmRxReasonTrillRpfFail,     /* 3:TRILL_RPF_CHECK_FAIL */
   1466     bcmRxReasonTrillSlowpath,    /* 4:TRILL_SLOWPATH */
   1467     bcmRxReasonTrillCoreIsIs,    /* 5:TRILL_CORE_IS_IS_PKT */
   1468     bcmRxReasonTrillTtl          /* 6:TRILL_HOP_COUNT_CHECK_FAIL */
   1469 };
   1470 
   1471 #endif /* BCM_TRIDENT_SUPPORT */
   1472 
   1473 #if defined(BCM_TRIDENT_SUPPORT) || defined(BCM_GREYHOUND_SUPPORT)
   1474 /* From FORMAT NIV_CPU_OPCODE_ENCODING */
   1475 static bcm_rx_reason_t
   1476 _bcm_niv_cpu_opcode_encoding[] =
   1477 {
   1478     bcmRxReasonNiv,              /* 0: NO_ERRORS
   1479                                   * Base field, must match the entries above */
   1480     bcmRxReasonNivPrioDrop,      /* 1:DOT1P_ADMITTANCE_DISCARD */
   1481     bcmRxReasonNivInterfaceMiss, /* 2:VIF_LOOKUP_MISS */
   1482     bcmRxReasonNivRpfFail,       /* 3:RPF_LOOKUP_MISS */
   1483     bcmRxReasonNivTagInvalid,    /* 4:VNTAG_FORMAT_ERROR */
   1484     bcmRxReasonNivTagDrop,       /* 5:VNTAG_PRESENT_DROP */
   1485     bcmRxReasonNivUntagDrop      /* 6:VNTAG_NOT_PRESENT_DROP */
   1486 };
   1487 
   1488 #endif /* BCM_TRIDENT_SUPPORT || BCM_GREYHOUND_SUPPORT */
   1489 
   1490 #ifdef BCM_TRIDENT2_SUPPORT
   1491 /* From FORMAT CPU_COS_MAP_KEY (exclude common bits (bit 0 to 6) */
   1492 static bcm_rx_reason_t
   1493 _bcm_trident2_cpu_cos_map_key[] =
   1494 {
   1495     bcmRxReasonBpdu,                    /* 07:PROTOCOL_BPDU */
   1496     bcmRxReasonIpmcReserved,            /* 08:PROTOCOL_IPMC_RSVD */
   1497     bcmRxReasonDhcp,                    /* 09:PROTOCOL_DHCP */
   1498     bcmRxReasonIgmp,                    /* 10:PROTOCOL_IGMP */
   1499     bcmRxReasonArp,                     /* 11:PROTOCOL_ARP */
   1500     bcmRxReasonUnknownVlan,             /* 12:CPU_UVLAN. */
   1501     bcmRxReasonSharedVlanMismatch,      /* 13:PVLAN_MISMATCH */
   1502     bcmRxReasonDosAttack,               /* 14:CPU_DOS_ATTACK */
   1503     bcmRxReasonParityError,             /* 15:PARITY_ERROR */
   1504     bcmRxReasonHigigControl,            /* 16:MH_CONTROL */
   1505     bcmRxReasonTtl1,                    /* 17:TTL_1 */
   1506     bcmRxReasonL3Slowpath,              /* 18:IP_OPTIONS_PKT. */
   1507     bcmRxReasonL2SourceMiss,            /* 19:CPU_SLF */
   1508     bcmRxReasonL2DestMiss,              /* 20:CPU_DLF */
   1509     bcmRxReasonL2Move,                  /* 21:CPU_L2MOVE */
   1510     bcmRxReasonL2Cpu,                   /* 22:CPU_L2CPU */
   1511     bcmRxReasonL2NonUnicastMiss,        /* 23:PBT_NONUC_PKT */
   1512     bcmRxReasonL3SourceMiss,            /* 24:CPU_L3SRC_MISS. */
   1513     bcmRxReasonL3DestMiss,              /* 25:CPU_L3DST_MISS */
   1514     bcmRxReasonL3SourceMove,            /* 26:CPU_L3SRC_MOVE */
   1515     bcmRxReasonMcastMiss,               /* 27:CPU_MC_MISS */
   1516     bcmRxReasonIpMcastMiss,             /* 28:CPU_IPMC_MISS */
   1517     bcmRxReasonL3HeaderError,           /* 29:CPU_L3HDR_ERR */
   1518     bcmRxReasonMartianAddr,             /* 30:CPU_MARTIAN_ADDR */
   1519     bcmRxReasonTunnelError,             /* 31:CPU_TUNNEL_ERR */
   1520     bcmRxReasonHigigHdrError,           /* 32:HGHDR_ERROR */
   1521     bcmRxReasonMcastIdxError,           /* 33:MCIDX_ERROR */
   1522     bcmRxReasonVlanFilterMatch,         /* 34:VFP */
   1523     bcmRxReasonClassBasedMove,          /* 35:CBSM_PREVENTED */
   1524     bcmRxReasonCongestionCnm,           /* 36:ICNM */
   1525     bcmRxReasonE2eHolIbp,               /* 37:E2E_HOL_IBP */
   1526     bcmRxReasonClassTagPackets,         /* 38:HG_HDR_TYPE1 */
   1527     bcmRxReasonNhop,                    /* 39:NHOP */
   1528     bcmRxReasonUrpfFail,                /* 40:URPF_FAILED */
   1529     bcmRxReasonFilterMatch,             /* 41:CPU_FFP */
   1530     bcmRxReasonIcmpRedirect,            /* 42:ICMP_REDIRECT */
   1531     bcmRxReasonSampleSource,            /* 43:CPU_SFLOW_SRC */
   1532     bcmRxReasonSampleDest,              /* 44:CPU_SFLOW_DST */
   1533     bcmRxReasonL3MtuFail,               /* 45:L3_MTU_CHECK_FAIL */
   1534     bcmRxReasonMplsLabelMiss,           /* 46:MPLS_LABEL_MISS */
   1535     bcmRxReasonMplsInvalidAction,       /* 47:MPLS_INVALID_ACTION */
   1536     bcmRxReasonMplsInvalidPayload,      /* 48:MPLS_INVALID_PAYLOAD */
   1537     bcmRxReasonMplsTtl,                 /* 49:MPLS_TTL_CHECK_FAIL */
   1538     bcmRxReasonMplsSequenceNumber,      /* 50:MPLS_SEQ_NUM_FAIL */
   1539     bcmRxReasonMplsUnknownAch,          /* 51:MPLS_UNKNOWN_ACH_ERROR */
   1540     bcmRxReasonMmrp,                    /* 52:PROTOCOL_MMRP */
   1541     bcmRxReasonSrp,                     /* 53:PROTOCOL_SRP */
   1542     bcmRxReasonTimesyncUnknownVersion,  /* 54:IEEE1588_UNKNOWN_VERSION */
   1543     bcmRxReasonMplsRouterAlertLabel,    /* 55:MPLS_ALERT_LABEL */
   1544     bcmRxReasonMplsIllegalReservedLabel,/* 56:MPLS_ILLEGAL_RESERVED_LABEL */
   1545     bcmRxReasonVlanTranslate,           /* 57:VXLT_MISS */
   1546     bcmRxReasonTunnelControl,           /* 58:AMT_CONTROL_PKT */
   1547     bcmRxReasonTimeSync,                /* 59:TIME_SYNC */
   1548     bcmRxReasonOAMSlowpath,             /* 60:OAM_SLOWPATH */
   1549     bcmRxReasonOAMError,                /* 61:OAM_ERROR */
   1550     bcmRxReasonL2Marked,                /* 62:PROTOCOL_L2_PKT */
   1551     bcmRxReasonL3AddrBindFail,          /* 63:MAC_BIND_FAIL */
   1552     bcmRxReasonStation,                 /* 64:MY_STATION */
   1553     bcmRxReasonNiv,                     /* 65:NIV_DROP_REASON_ENCODING */
   1554     bcmRxReasonNiv,                     /* 66:  -> */
   1555     bcmRxReasonNiv,                     /* 67:3 bits */
   1556     bcmRxReasonTrill,                   /* 68:TRILL_DROP_REASON_ENCODING */
   1557     bcmRxReasonTrill,                   /* 69:  -> */
   1558     bcmRxReasonTrill,                   /* 70:3 bits */
   1559     bcmRxReasonL2GreSipMiss,            /* 71:L2GRE_SIP_MISS */
   1560     bcmRxReasonL2GreVpnIdMiss,          /* 72:L2GRE_VPNID_MISS */
   1561     bcmRxReasonBfdSlowpath,             /* 73:BFD_SLOWPATH */
   1562     bcmRxReasonBfd,                     /* 74:BFD_ERROR */
   1563     bcmRxReasonOAMLMDM,                 /* 75:OAM_LMDM */
   1564     bcmRxReasonCongestionCnmProxy,      /* 76:QCN_CNM_PRP */
   1565     bcmRxReasonCongestionCnmProxyError, /* 77:QCN_CNM_PRP_DLF */
   1566     bcmRxReasonVxlanSipMiss,            /* 78:VXLAN_SIP_MISS */
   1567     bcmRxReasonVxlanVpnIdMiss,          /* 79:VXLAN_VN_ID_MISS */
   1568     bcmRxReasonFcoeZoneCheckFail,       /* 80:FCOE_ZONE_CHECK_FAIL */
   1569     bcmRxReasonNat,                     /* 81:NAT_DROP_REASON_ENCODING */
   1570     bcmRxReasonNat,                     /* 82:  -> */
   1571     bcmRxReasonNat,                     /* 83:3 bits */
   1572     bcmRxReasonIpmcInterfaceMismatch    /* 84:CPU_IPMC_INTERFACE_MISMATCH */
   1573 };
   1574 
   1575 /* From FORMAT NAT_CPU_OPCODE_ENCODING */
   1576 static bcm_rx_reason_t
   1577 _bcm_nat_cpu_opcode_encoding[] =
   1578 {
   1579     bcmRxReasonNat,              /* 0:NOP
   1580                                   * Base field, must match the entries above */
   1581     bcmRxReasonTcpUdpNatMiss,    /* 1:NORMAL */
   1582     bcmRxReasonIcmpNatMiss,      /* 2:ICMP */
   1583     bcmRxReasonNatFragment,      /* 3:FRAGMEMT */
   1584     bcmRxReasonNatMiss           /* 4:OTHER */
   1585 };
   1586 
   1587 static bcm_rx_reason_t
   1588 /* From FORMAT TRILL_CPU_OPCODE_ENCODING */
   1589 _bcm_trident2_trill_cpu_opcode_encoding[] =
   1590 {
   1591     bcmRxReasonTrill,            /* 0:NO_ERRORS
   1592                                   * Base field, must match the entries above */
   1593     bcmRxReasonTrillInvalid,     /* 1:TRILL_HDR_ERROR */
   1594     bcmRxReasonTrillMiss,        /* 2:TRILL_LOOKUP_MISS */
   1595     bcmRxReasonTrillRpfFail,     /* 3:TRILL_RPF_CHECK_FAIL */
   1596     bcmRxReasonTrillSlowpath,    /* 4:TRILL_SLOWPATH */
   1597     bcmRxReasonTrillCoreIsIs,    /* 5:TRILL_CORE_IS_IS_PKT */
   1598     bcmRxReasonTrillTtl,         /* 6:TRILL_HOP_COUNT_CHECK_FAIL */
   1599     bcmRxReasonTrillName         /* 7:NICKNAME_TABLE_COPYTOCPU */
   1600 };
   1601 #endif /* BCM_TRIDENT2_SUPPORT */
   1602 
   1603 #ifdef BCM_TOMAHAWK_SUPPORT
   1604 /* From FORMAT CPU_COS_MAP_KEY (exclude common bits (bit 0 to 6) */
   1605 static bcm_rx_reason_t
   1606 _bcm_tomahawk_cpu_cos_map_key[] =
   1607 {
   1608     bcmRxReasonBpdu,                    /* 07:PROTOCOL_BPDU */
   1609     bcmRxReasonIpmcReserved,            /* 08:PROTOCOL_IPMC_RSVD */
   1610     bcmRxReasonDhcp,                    /* 09:PROTOCOL_DHCP */
   1611     bcmRxReasonIgmp,                    /* 10:PROTOCOL_IGMP */
   1612     bcmRxReasonArp,                     /* 11:PROTOCOL_ARP */
   1613     bcmRxReasonUnknownVlan,             /* 12:CPU_UVLAN. */
   1614     bcmRxReasonSharedVlanMismatch,      /* 13:PVLAN_MISMATCH */
   1615     bcmRxReasonDosAttack,               /* 14:CPU_DOS_ATTACK */
   1616     bcmRxReasonParityError,             /* 15:PARITY_ERROR */
   1617     bcmRxReasonHigigControl,            /* 16:MH_CONTROL */
   1618     bcmRxReasonTtl1,                    /* 17:TTL_1 */
   1619     bcmRxReasonL3Slowpath,              /* 18:IP_OPTIONS_PKT. */
   1620     bcmRxReasonL2SourceMiss,            /* 19:CPU_SLF */
   1621     bcmRxReasonL2DestMiss,              /* 20:CPU_DLF */
   1622     bcmRxReasonL2Move,                  /* 21:CPU_L2MOVE */
   1623     bcmRxReasonL2Cpu,                   /* 22:CPU_L2CPU */
   1624     bcmRxReasonL2NonUnicastMiss,        /* 23:PBT_NONUC_PKT */
   1625     bcmRxReasonL3SourceMiss,            /* 24:CPU_L3SRC_MISS. */
   1626     bcmRxReasonL3DestMiss,              /* 25:CPU_L3DST_MISS */
   1627     bcmRxReasonL3SourceMove,            /* 26:CPU_L3SRC_MOVE */
   1628     bcmRxReasonMcastMiss,               /* 27:CPU_MC_MISS */
   1629     bcmRxReasonIpMcastMiss,             /* 28:CPU_IPMC_MISS */
   1630     bcmRxReasonL3HeaderError,           /* 29:CPU_L3HDR_ERR */
   1631     bcmRxReasonMartianAddr,             /* 30:CPU_MARTIAN_ADDR */
   1632     bcmRxReasonTunnelError,             /* 31:CPU_TUNNEL_ERR */
   1633     bcmRxReasonHigigHdrError,           /* 32:HGHDR_ERROR */
   1634     bcmRxReasonMcastIdxError,           /* 33:MCIDX_ERROR */
   1635     bcmRxReasonVlanFilterMatch,         /* 34:VFP */
   1636     bcmRxReasonClassBasedMove,          /* 35:CBSM_PREVENTED */
   1637     bcmRxReasonInvalid,                 /* 36:Reserved */
   1638     bcmRxReasonTunnelDecapEcnError,     /* 37:TUNNEL_DECAP_ECN_ERR */
   1639     bcmRxReasonClassTagPackets,         /* 38:HG_HDR_TYPE1 */
   1640     bcmRxReasonNhop,                    /* 39:NHOP */
   1641     bcmRxReasonUrpfFail,                /* 40:URPF_FAILED */
   1642     bcmRxReasonFilterMatch,             /* 41:CPU_FFP */
   1643     bcmRxReasonIcmpRedirect,            /* 42:ICMP_REDIRECT */
   1644     bcmRxReasonSampleSource,            /* 43:CPU_SFLOW_SRC */
   1645     bcmRxReasonSampleDest,              /* 44:CPU_SFLOW_DST */
   1646     bcmRxReasonL3MtuFail,               /* 45:L3_MTU_CHECK_FAIL */
   1647     bcmRxReasonMplsLabelMiss,           /* 46:MPLS_LABEL_MISS */
   1648     bcmRxReasonMplsInvalidAction,       /* 47:MPLS_INVALID_ACTION */
   1649     bcmRxReasonMplsInvalidPayload,      /* 48:MPLS_INVALID_PAYLOAD */
   1650     bcmRxReasonMplsTtl,                 /* 49:MPLS_TTL_CHECK_FAIL */
   1651     bcmRxReasonMplsSequenceNumber,      /* 50:MPLS_SEQ_NUM_FAIL */
   1652     bcmRxReasonMplsUnknownAch,          /* 51:MPLS_UNKNOWN_ACH_ERROR */
   1653     bcmRxReasonMmrp,                    /* 52:PROTOCOL_MMRP */
   1654     bcmRxReasonSrp,                     /* 53:PROTOCOL_SRP */
   1655     bcmRxReasonTimesyncUnknownVersion,  /* 54:IEEE1588_UNKNOWN_VERSION */
   1656     bcmRxReasonMplsRouterAlertLabel,    /* 55:MPLS_ALERT_LABEL */
   1657     bcmRxReasonMplsIllegalReservedLabel,/* 56:MPLS_ILLEGAL_RESERVED_LABEL */
   1658     bcmRxReasonVlanTranslate,           /* 57:VXLT_MISS */
   1659     bcmRxReasonTunnelControl,           /* 58:AMT_CONTROL_PKT */
   1660     bcmRxReasonTimeSync,                /* 59:TIME_SYNC */
   1661     bcmRxReasonOAMSlowpath,             /* 60:OAM_SLOWPATH */
   1662     bcmRxReasonOAMError,                /* 61:OAM_ERROR */
   1663     bcmRxReasonL2Marked,                /* 62:PROTOCOL_L2_PKT */
   1664     bcmRxReasonL3AddrBindFail,          /* 63:MAC_BIND_FAIL */
   1665     bcmRxReasonStation,                 /* 64:MY_STATION */
   1666     bcmRxReasonNiv,                     /* 65:NIV_DROP_REASON_ENCODING */
   1667     bcmRxReasonNiv,                     /* 66:  -> */
   1668     bcmRxReasonNiv,                     /* 67:3 bits */
   1669     bcmRxReasonTrill,                   /* 68:TRILL_DROP_REASON_ENCODING */
   1670     bcmRxReasonTrill,                   /* 69:  -> */
   1671     bcmRxReasonTrill,                   /* 70:3 bits */
   1672     bcmRxReasonL2GreSipMiss,            /* 71:L2GRE_SIP_MISS */
   1673     bcmRxReasonL2GreVpnIdMiss,          /* 72:L2GRE_VPNID_MISS */
   1674     bcmRxReasonBfdSlowpath,             /* 73:BFD_SLOWPATH */
   1675     bcmRxReasonBfd,                     /* 74:BFD_ERROR */
   1676     bcmRxReasonOAMLMDM,                 /* 75:OAM_LMDM */
   1677     bcmRxReasonInvalid,                 /* 76:Reserved */
   1678     bcmRxReasonInvalid,                 /* 77:Reserved */
   1679     bcmRxReasonVxlanSipMiss,            /* 78:VXLAN_SIP_MISS */
   1680     bcmRxReasonVxlanVpnIdMiss,          /* 79:VXLAN_VN_ID_MISS */
   1681     bcmRxReasonFcoeZoneCheckFail,       /* 80:FCOE_ZONE_CHECK_FAIL */
   1682     bcmRxReasonNat,                     /* 81:NAT_DROP_REASON_ENCODING */
   1683     bcmRxReasonNat,                     /* 82:  -> */
   1684     bcmRxReasonNat,                     /* 83:3 bits */
   1685     bcmRxReasonIpmcInterfaceMismatch,   /* 84:CPU_IPMC_INTERFACE_MISMATCH */
   1686     bcmRxReasonSampleSourceFlex         /* 85:CPU_SFLOW_FLEX */
   1687 };
   1688 #endif /* BCM_TOMAHAWK_SUPPORT */
   1689 
   1690 #ifdef BCM_TRIDENT2PLUS_SUPPORT
   1691 /* From FORMAT CPU_COS_MAP_KEY (exclude common bits (bit 0 to 6) */
   1692 static bcm_rx_reason_t
   1693 _bcm_trident2plus_cpu_cos_map_key[] =
   1694 {
   1695     bcmRxReasonBpdu,                    /* 07:PROTOCOL_BPDU */
   1696     bcmRxReasonIpmcReserved,            /* 08:PROTOCOL_IPMC_RSVD */
   1697     bcmRxReasonDhcp,                    /* 09:PROTOCOL_DHCP */
   1698     bcmRxReasonIgmp,                    /* 10:PROTOCOL_IGMP */
   1699     bcmRxReasonArp,                     /* 11:PROTOCOL_ARP */
   1700     bcmRxReasonUnknownVlan,             /* 12:CPU_UVLAN. */
   1701     bcmRxReasonSharedVlanMismatch,      /* 13:PVLAN_MISMATCH */
   1702     bcmRxReasonDosAttack,               /* 14:CPU_DOS_ATTACK */
   1703     bcmRxReasonParityError,             /* 15:PARITY_ERROR */
   1704     bcmRxReasonHigigControl,            /* 16:MH_CONTROL */
   1705     bcmRxReasonTtl1,                    /* 17:TTL_1 */
   1706     bcmRxReasonL3Slowpath,              /* 18:IP_OPTIONS_PKT. */
   1707     bcmRxReasonL2SourceMiss,            /* 19:CPU_SLF */
   1708     bcmRxReasonL2DestMiss,              /* 20:CPU_DLF */
   1709     bcmRxReasonL2Move,                  /* 21:CPU_L2MOVE */
   1710     bcmRxReasonL2Cpu,                   /* 22:CPU_L2CPU */
   1711     bcmRxReasonL2NonUnicastMiss,        /* 23:PBT_NONUC_PKT */
   1712     bcmRxReasonL3SourceMiss,            /* 24:CPU_L3SRC_MISS. */
   1713     bcmRxReasonL3DestMiss,              /* 25:CPU_L3DST_MISS */
   1714     bcmRxReasonL3SourceMove,            /* 26:CPU_L3SRC_MOVE */
   1715     bcmRxReasonMcastMiss,               /* 27:CPU_MC_MISS */
   1716     bcmRxReasonIpMcastMiss,             /* 28:CPU_IPMC_MISS */
   1717     bcmRxReasonL3HeaderError,           /* 29:CPU_L3HDR_ERR */
   1718     bcmRxReasonMartianAddr,             /* 30:CPU_MARTIAN_ADDR */
   1719     bcmRxReasonTunnelError,             /* 31:CPU_TUNNEL_ERR */
   1720     bcmRxReasonHigigHdrError,           /* 32:HGHDR_ERROR */
   1721     bcmRxReasonMcastIdxError,           /* 33:MCIDX_ERROR */
   1722     bcmRxReasonVlanFilterMatch,         /* 34:VFP */
   1723     bcmRxReasonClassBasedMove,          /* 35:CBSM_PREVENTED */
   1724     bcmRxReasonCongestionCnm,           /* 36:ICNM */
   1725     bcmRxReasonE2eHolIbp,               /* 37:E2E_HOL_IBP */
   1726     bcmRxReasonClassTagPackets,         /* 38:HG_HDR_TYPE1 */
   1727     bcmRxReasonNhop,                    /* 39:NHOP */
   1728     bcmRxReasonUrpfFail,                /* 40:URPF_FAILED */
   1729     bcmRxReasonFilterMatch,             /* 41:CPU_FFP */
   1730     bcmRxReasonIcmpRedirect,            /* 42:ICMP_REDIRECT */
   1731     bcmRxReasonSampleSource,            /* 43:CPU_SFLOW_SRC */
   1732     bcmRxReasonSampleDest,              /* 44:CPU_SFLOW_DST */
   1733     bcmRxReasonL3MtuFail,               /* 45:L3_MTU_CHECK_FAIL */
   1734     bcmRxReasonMplsLabelMiss,           /* 46:MPLS_LABEL_MISS */
   1735     bcmRxReasonMplsInvalidAction,       /* 47:MPLS_INVALID_ACTION */
   1736     bcmRxReasonMplsInvalidPayload,      /* 48:MPLS_INVALID_PAYLOAD */
   1737     bcmRxReasonMplsTtl,                 /* 49:MPLS_TTL_CHECK_FAIL */
   1738     bcmRxReasonMplsSequenceNumber,      /* 50:MPLS_SEQ_NUM_FAIL */
   1739     bcmRxReasonMplsUnknownAch,          /* 51:MPLS_UNKNOWN_ACH_ERROR */
   1740     bcmRxReasonMmrp,                    /* 52:PROTOCOL_MMRP */
   1741     bcmRxReasonSrp,                     /* 53:PROTOCOL_SRP */
   1742     bcmRxReasonTimesyncUnknownVersion,  /* 54:IEEE1588_UNKNOWN_VERSION */
   1743     bcmRxReasonMplsRouterAlertLabel,    /* 55:MPLS_ALERT_LABEL */
   1744     bcmRxReasonMplsIllegalReservedLabel,/* 56:MPLS_ILLEGAL_RESERVED_LABEL */
   1745     bcmRxReasonVlanTranslate,           /* 57:VXLT_MISS */
   1746     bcmRxReasonTunnelControl,           /* 58:AMT_CONTROL_PKT */
   1747     bcmRxReasonTimeSync,                /* 59:TIME_SYNC */
   1748     bcmRxReasonOAMSlowpath,             /* 60:OAM_SLOWPATH */
   1749     bcmRxReasonOAMError,                /* 61:OAM_ERROR */
   1750     bcmRxReasonL2Marked,                /* 62:PROTOCOL_L2_PKT */
   1751     bcmRxReasonL3AddrBindFail,          /* 63:MAC_BIND_FAIL */
   1752     bcmRxReasonStation,                 /* 64:MY_STATION */
   1753     bcmRxReasonNiv,                     /* 65:NIV_DROP_REASON_ENCODING */
   1754     bcmRxReasonNiv,                     /* 66:  -> */
   1755     bcmRxReasonNiv,                     /* 67:3 bits */
   1756     bcmRxReasonTrill,                   /* 68:TRILL_DROP_REASON_ENCODING */
   1757     bcmRxReasonTrill,                   /* 69:  -> */
   1758     bcmRxReasonTrill,                   /* 70:3 bits */
   1759     bcmRxReasonL2GreSipMiss,            /* 71:L2GRE_SIP_MISS */
   1760     bcmRxReasonL2GreVpnIdMiss,          /* 72:L2GRE_VPNID_MISS */
   1761     bcmRxReasonBfdSlowpath,             /* 73:BFD_SLOWPATH */
   1762     bcmRxReasonBfd,                     /* 74:BFD_ERROR */
   1763     bcmRxReasonOAMLMDM,                 /* 75:OAM_LMDM */
   1764     bcmRxReasonCongestionCnmProxy,      /* 76:QCN_CNM_PRP */
   1765     bcmRxReasonCongestionCnmProxyError, /* 77:QCN_CNM_PRP_DLF */
   1766     bcmRxReasonVxlanSipMiss,            /* 78:VXLAN_SIP_MISS */
   1767     bcmRxReasonVxlanVpnIdMiss,          /* 79:VXLAN_VN_ID_MISS */
   1768     bcmRxReasonFcoeZoneCheckFail,       /* 80:FCOE_ZONE_CHECK_FAIL */
   1769     bcmRxReasonNat,                     /* 81:NAT_DROP_REASON_ENCODING */
   1770     bcmRxReasonNat,                     /* 82:  -> */
   1771     bcmRxReasonNat,                     /* 83:3 bits */
   1772     bcmRxReasonIpmcInterfaceMismatch,   /* 84:CPU_IPMC_INTERFACE_MISMATCH */
   1773     bcmRxReasonFailoverDrop,            /* 85:PROTECTION_DATA_DROP_OFFSET */
   1774     bcmRxReasonEncapHigigError,         /* 86:NON_EMBEDDED_HG_OFFSET */
   1775 #if 1
   1776     bcmRxReasonInvalid                  /* 87:NOT DEFINED */
   1777 #endif
   1778 };
   1779 
   1780 static bcm_rx_reason_t
   1781 /* From FORMAT NIV_CPU_OPCODE_ENCODING */
   1782 _bcm_trident2plus_niv_cpu_opcode_encoding[] =
   1783 {
   1784     bcmRxReasonNiv,              /* 0: NO_ERRORS
   1785                                   * Base field, must match the entries above */
   1786     bcmRxReasonNivPrioDrop,      /* 1:DOT1P_ADMITTANCE_DISCARD */
   1787     bcmRxReasonNivInterfaceMiss, /* 2:VIF_LOOKUP_MISS */
   1788     bcmRxReasonNivRpfFail,       /* 3:RPF_LOOKUP_MISS */
   1789     bcmRxReasonNivTagInvalid,    /* 4:VNTAG_FORMAT_ERROR */
   1790     bcmRxReasonNivTagDrop,       /* 5:VNTAG_PRESENT_DROP */
   1791     bcmRxReasonNivUntagDrop,     /* 6:VNTAG_NOT_PRESENT_DROP */
   1792     bcmRxReasonUnknownSubtendingPort /* 7: UNKNOWN_SUBTENDING_PORT */
   1793 };
   1794 
   1795 static bcm_rx_reason_t
   1796 /* From FORMAT NAT_CPU_OPCODE_ENCODING */
   1797 _bcm_trident2plus_nat_cpu_opcode_encoding[] =
   1798 {
   1799     bcmRxReasonNat,              /* 0:NOP
   1800                                   * Base field, must match the entries above */
   1801     bcmRxReasonTcpUdpNatMiss,    /* 1:NORMAL */
   1802     bcmRxReasonIcmpNatMiss,      /* 2:ICMP */
   1803     bcmRxReasonNatFragment,      /* 3:FRAGMEMT */
   1804     bcmRxReasonNatMiss,          /* 4:OTHER */
   1805     bcmRxReasonInvalid,          /* 5:RESERVED */
   1806     bcmRxReasonInvalid,          /* 6:RESERVED */
   1807 #if 1
   1808     bcmRxReasonInvalid           /* 7:NOT DEFINED */
   1809 #endif
   1810 };
   1811 #endif /* BCM_TRIDENT2PLUS_SUPPORT */
   1812 
   1813 #ifdef BCM_TRIDENT3_SUPPORT
   1814 /* From FORMAT CPU_COS_MAP_KEY (exclude common bits (bit 0 to 6) */
   1815 static bcm_rx_reason_t
   1816 _bcm_trident3_cpu_cos_map_key[] =
   1817 {
   1818     bcmRxReasonBpdu,                    /* 07:PROTOCOL_BPDU */
   1819     bcmRxReasonIpmcReserved,            /* 08:PROTOCOL_IPMC_RSVD */
   1820     bcmRxReasonDhcp,                    /* 09:PROTOCOL_DHCP */
   1821     bcmRxReasonIgmp,                    /* 10:PROTOCOL_IGMP */
   1822     bcmRxReasonArp,                     /* 11:PROTOCOL_ARP */
   1823     bcmRxReasonUnknownVlan,             /* 12:CPU_UVLAN. */
   1824     bcmRxReasonSharedVlanMismatch,      /* 13:PVLAN_MISMATCH */
   1825     bcmRxReasonDosAttack,               /* 14:CPU_DOS_ATTACK */
   1826     bcmRxReasonParityError,             /* 15:PARITY_ERROR */
   1827     bcmRxReasonHigigControl,            /* 16:MH_CONTROL */
   1828     bcmRxReasonTtl1,                    /* 17:TTL_1 */
   1829     bcmRxReasonL3Slowpath,              /* 18:IP_OPTIONS_PKT. */
   1830     bcmRxReasonL2SourceMiss,            /* 19:CPU_SLF */
   1831     bcmRxReasonL2DestMiss,              /* 20:CPU_DLF */
   1832     bcmRxReasonL2Move,                  /* 21:CPU_L2MOVE */
   1833     bcmRxReasonL2Cpu,                   /* 22:CPU_L2CPU */
   1834     bcmRxReasonL2NonUnicastMiss,        /* 23:PBT_NONUC_PKT */
   1835     bcmRxReasonInvalid,                 /* 24:RESERVED */
   1836     bcmRxReasonInvalid,                 /* 25:RESERVED */
   1837     bcmRxReasonL3SourceMove,            /* 26:CPU_L3SRC_MOVE */
   1838     bcmRxReasonMcastMiss,               /* 27:CPU_MC_MISS */
   1839     bcmRxReasonIpMcastMiss,             /* 28:CPU_IPMC_MISS */
   1840     bcmRxReasonL3HeaderMismatch,        /* 29:CPU_L3HDR_MISMATCH */
   1841     bcmRxReasonMartianAddr,             /* 30:CPU_MARTIAN_ADDR */
   1842     bcmRxReasonTunnelError,             /* 31:CPU_TUNNEL_ERR */
   1843     bcmRxReasonHigigHdrError,           /* 32:HGHDR_ERROR */
   1844     bcmRxReasonMcastIdxError,           /* 33:MCIDX_ERROR */
   1845     bcmRxReasonVlanFilterMatch,         /* 34:VFP */
   1846     bcmRxReasonClassBasedMove,          /* 35:CBSM_PREVENTED */
   1847     bcmRxReasonInvalid,                 /* 36:RESERVED */
   1848     bcmRxReasonTunnelDecapEcnError,     /* 37:TUNNEL_DECAP_ECN_ERROR */
   1849     bcmRxReasonClassTagPackets,         /* 38:HG_HDR_TYPE1 */
   1850     bcmRxReasonNhop,                    /* 39:NHOP */
   1851     bcmRxReasonUrpfFail,                /* 40:URPF_FAILED */
   1852     bcmRxReasonFilterMatch,             /* 41:CPU_FFP */
   1853     bcmRxReasonIcmpRedirect,            /* 42:ICMP_REDIRECT */
   1854     bcmRxReasonSampleSource,            /* 43:CPU_SFLOW_SRC */
   1855     bcmRxReasonSampleDest,              /* 44:CPU_SFLOW_DST */
   1856     bcmRxReasonL3MtuFail,               /* 45:L3_MTU_CHECK_FAIL */
   1857     bcmRxReasonMplsLabelMiss,           /* 46:MPLS_LABEL_MISS */
   1858     bcmRxReasonMplsInvalidAction,       /* 47:MPLS_INVALID_ACTION */
   1859     bcmRxReasonMplsInvalidPayload,      /* 48:MPLS_INVALID_PAYLOAD */
   1860     bcmRxReasonMplsControlPacket,       /* 49:MPLS_CONTROL_PKT */
   1861     bcmRxReasonMplsSequenceNumber,      /* 50:MPLS_SEQ_NUM_FAIL */
   1862     bcmRxReasonInvalidTpid,             /* 51:INVALID_TPID */
   1863     bcmRxReasonInvalid,                 /* 52:RESERVED */
   1864     bcmRxReasonInvalid,                 /* 53:RESERVED */
   1865     bcmRxReasonTimesyncUnknownVersion,  /* 54:IEEE1588_UNKNOWN_VERSION */
   1866     bcmRxReasonMplsRouterAlertLabel,    /* 55:MPLS_ALERT_LABEL */
   1867     bcmRxReasonMplsIllegalReservedLabel,/* 56:MPLS_ILLEGAL_RESERVED_LABEL */
   1868     bcmRxReasonPacketFlowSelectMiss,    /* 57:FLOW_SELECT_MISS */
   1869     bcmRxReasonTimeSync,                /* 58:TIME_SYNC */
   1870     bcmRxReasonL2Marked,                /* 59:PROTOCOL_L2_PKT */
   1871     bcmRxReasonL3AddrBindFail,          /* 60:MAC_BIND_FAIL */
   1872     bcmRxReasonStation,                 /* 61:MY_STATION */
   1873     bcmRxReasonNivPrioDrop,             /* 62:DOT1P_ADMITTANCE_DISCARD */
   1874     bcmRxReasonNivRpfFail,              /* 63:RPF_LOOKUP_MISS */
   1875     bcmRxReasonUnknownSubtendingPort,   /* 64:UNKOWN SUBTENDING PORT */
   1876     bcmRxReasonL3Cpu,                   /* 65:L3CPU */
   1877     bcmRxReasonReserved0,               /* 66:INSTRUMENT */
   1878     bcmRxReasonTunnelObjectValidationFail, /*67:TUNNEL_OBJECT_VALIDATION_FAIL */
   1879     bcmRxReasonTunnelTtlError,          /* 68:TUNNEL_TTL_CHECK_FAIL */
   1880     bcmRxReasonL3HeaderError,           /* 69:L3_HDR_ERROR */
   1881     bcmRxReasonL2HeaderError,           /* 70:L2_HDR_ERROR */
   1882     bcmRxReasonTtl,                     /* 71:TTL */
   1883     bcmRxReasonFcoeZoneCheckFail,       /* 72:FCOE_ZONE_CHECK_FAIL */
   1884     bcmRxReasonNat,                     /* 73:NAT_ERROR */
   1885     bcmRxReasonInvalid,                 /* 74:RESERVED */
   1886     bcmRxReasonInvalid,                 /* 75:RESERVED */
   1887     bcmRxReasonIpmcInterfaceMismatch,   /* 76:CPU_IPMC_INTERFACE_MISMATCH */
   1888     bcmRxReasonSampleSourceFlex,        /* 77:CPU_SFLOW_FLEX */
   1889     bcmRxReasonInvalid,                 /* 78:RESERVED */
   1890     bcmRxReasonInvalid,                 /* 79:RESERVED */
   1891     bcmRxReasonInvalid,                 /* 80:RESERVED */
   1892     bcmRxReasonInvalid,                 /* 81:RESERVED */
   1893     bcmRxReasonInvalid,                 /* 82:RESERVED */
   1894     bcmRxReasonInvalid,                 /* 83:RESERVED */
   1895     bcmRxReasonInvalid,                 /* 84:RESERVED */
   1896     bcmRxReasonInvalid,                 /* 85:RESERVED */
   1897     bcmRxReasonInvalid,                 /* 86:RESERVED */
   1898 #if 1
   1899     bcmRxReasonInvalid,                 /* 87:NOT DEFINED */
   1900 #endif
   1901     bcmRxReasonL2SrcLookupMiss,         /* 88:FORWARDING_L2_SOURCE_LOOKUP_MISS_OFFSET */
   1902     bcmRxReasonInvalid,                 /* 89:RESERVED */
   1903     bcmRxReasonL2DstLookupMiss,         /* 90:FORWARDING_L2_DEST_LOOKUP_MISS_OFFSET */
   1904     bcmRxReasonInvalid,                 /* 91:RESERVED */
   1905     bcmRxReasonInvalid,                 /* 92:RESERVED */
   1906     bcmRxReasonL3SrcHostLookupMiss,     /* 93:FORWARDING_L3_SOURCE_HOST_LOOKUP_MISS_OFFSET */
   1907     bcmRxReasonInvalid,                 /* 94:RESERVED */
   1908     bcmRxReasonInvalid,                 /* 95:RESERVED */
   1909     bcmRxReasonInvalid,                 /* 96:RESERVED */
   1910     bcmRxReasonL3DstHostLookupMiss,     /* 97:FORWARDING_L3_DEST_HOST_LOOKUP_MISS_OFFSET */
   1911     bcmRxReasonInvalid,                 /* 98:RESERVED */
   1912     bcmRxReasonInvalid,                 /* 99:RESERVED */
   1913     bcmRxReasonVlanTranslate1Lookup1Miss, /*100:TUNNEL_ADAPT_1_LOOKUP_1_OFFSET */
   1914     bcmRxReasonVlanTranslate1Lookup2Miss, /*101:TUNNEL_ADAPT_1_LOOKUP_2_OFFSET */
   1915     bcmRxReasonMplsLookup1Miss,           /*102:TUNNEL_ADAPT_2_LOOKUP_1_OFFSET */
   1916     bcmRxReasonMplsLookup2Miss,           /*103:TUNNEL_ADAPT_2_LOOKUP_2_OFFSET */
   1917     bcmRxReasonL3TunnelLookupMiss,        /*104:TUNNEL_ADAPT_3_LOOKUP_1_OFFSET */
   1918     bcmRxReasonVlanTranslate2Lookup1Miss, /*105:TUNNEL_ADAPT_4_LOOKUP_1_OFFSET */
   1919     bcmRxReasonVlanTranslate2Lookup2Miss, /*106:TUNNEL_ADAPT_4_LOOKUP_2_OFFSET */
   1920     bcmRxReasonPacketFlowSelect,        /* 107:PKT_FLOW_SELECT */
   1921     bcmRxReasonFailoverDrop             /* 108:PROTECTION_DATA_DROP_OFFSET */
   1922 };
   1923 
   1924 #endif /* BCM_TRIDENT3_SUPPORT */
   1925 
   1926 #ifdef BCM_KATANA_SUPPORT
   1927 static bcm_rx_reason_t 
   1928 _bcm_katana_cpu_cos_map_key [] =
   1929 {
   1930     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   1931     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   1932     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   1933     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   1934     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   1935     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   1936     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   1937     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   1938     bcmRxReasonParityError,             /* PARITY_ERROR */
   1939     bcmRxReasonHigigControl,            /* MH_CONTROL */
   1940     bcmRxReasonTtl1,                    /* TTL_1 */
   1941     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   1942     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   1943     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   1944     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   1945     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   1946     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   1947     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   1948     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   1949     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   1950     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   1951     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   1952     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   1953     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   1954     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   1955     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   1956     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   1957     bcmRxReasonVlanFilterMatch,         /* VFP */
   1958     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   1959     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   1960     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   1961     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   1962     bcmRxReasonNhop,                    /* NHOP */
   1963     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   1964     bcmRxReasonFilterMatch,             /* CPU_FFP */
   1965     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   1966     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   1967     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   1968     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   1969     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   1970     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   1971     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   1972     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   1973     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   1974     bcmRxReasonBfdSlowpath,             /* BFD_SLOWPATH */
   1975     bcmRxReasonMmrp,                    /* PROTOCOL_MMRP */
   1976     bcmRxReasonSrp,                     /* PROTOCOL_SRP */
   1977     bcmRxReasonStation,                 /* MY_STATION */
   1978     bcmRxReasonNiv,                     /* NIV_DROP_REASON_ENCODING */
   1979     bcmRxReasonNiv,                     /*   -> */
   1980     bcmRxReasonNiv,                     /* 3 bits */
   1981     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   1982     bcmRxReasonTunnelControl,           /* AMT_CONTROL_PKT */
   1983     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   1984     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   1985     bcmRxReasonOAMError,                /* OAM_ERROR */
   1986     bcmRxReasonL2Marked,                /* PROTOCOL_L2_PKT */
   1987     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   1988     bcmRxReasonInvalid,                 /* RESERVED_0 */
   1989     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   1990     bcmRxReasonBfd,                     /* BFD_ERROR_ENCODING */
   1991     bcmRxReasonBfdUnknownVersion
   1992 };
   1993 
   1994 static bcm_rx_reason_t
   1995 _bcm_bfd_cpu_opcode_encoding[] =
   1996 {
   1997     bcmRxReasonBfd,        /* Base field, must match the entries above */
   1998     bcmRxReasonBfdUnknownVersion,
   1999     bcmRxReasonBfdInvalidVersion,
   2000     /* bcmRxReasonBfdLookupFailure, use special case to handle */
   2001     bcmRxReasonBfdInvalidPacket
   2002 };
   2003 #endif /* BCM_KATANA_SUPPORT */
   2004 
   2005 #ifdef BCM_KATANA2_SUPPORT
   2006 static bcm_rx_reason_t 
   2007 _bcm_katana2_cpu_cos_map_key [] =
   2008 {
   2009     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   2010     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   2011     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   2012     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   2013     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   2014     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   2015     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   2016     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   2017     bcmRxReasonParityError,             /* PARITY_ERROR */
   2018     bcmRxReasonHigigControl,            /* MH_CONTROL */
   2019     bcmRxReasonTtl1,                    /* TTL_1 */
   2020     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   2021     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   2022     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   2023     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   2024     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   2025     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   2026     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   2027     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   2028     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   2029     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   2030     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   2031     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   2032     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   2033     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   2034     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   2035     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   2036     bcmRxReasonVlanFilterMatch,         /* VFP */
   2037     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   2038     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   2039     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   2040     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   2041     bcmRxReasonNhop,                    /* NHOP */
   2042     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   2043     bcmRxReasonFilterMatch,             /* CPU_FFP */
   2044     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   2045     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   2046     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   2047     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   2048     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   2049     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   2050     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   2051     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   2052     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   2053     bcmRxReasonBfdSlowpath,             /* BFD_SLOWPATH */
   2054     bcmRxReasonMmrp,                    /* PROTOCOL_MMRP */
   2055     bcmRxReasonSrp,                     /* PROTOCOL_SRP */
   2056     bcmRxReasonStation,                 /* MY_STATION */
   2057     bcmRxReasonNiv,                     /* NIV_DROP_REASON_ENCODING */
   2058     bcmRxReasonNiv,                     /*   -> */
   2059     bcmRxReasonNiv,                     /* 3 bits */
   2060     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   2061     bcmRxReasonTunnelControl,           /* AMT_CONTROL_PKT */
   2062     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   2063     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   2064     bcmRxReasonOAMError,                /* OAM_ERROR */
   2065     bcmRxReasonL2Marked,                /* PROTOCOL_L2_PKT */
   2066     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   2067     bcmRxReasonInvalid,                 /* RESERVED_0 */
   2068     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   2069     bcmRxReasonBfd,                     /* BFD_ERROR_ENCODING */
   2070     bcmRxReasonBfdUnknownVersion,
   2071     bcmRxReasonInvalid,                 /* UNKNOWN_SUBTENDING_PORT */
   2072     bcmRxReasonOAMCCMSlowpath,          /* OAM_CCM */
   2073     bcmRxReasonInvalid,                 /* LLTAG_PRESENT */
   2074     bcmRxReasonInvalid,                 /* LLTAG_NOT_PRESENT */
   2075     bcmRxReasonInvalid,                 /* ENTROPY_LABEL_IN_UNALLOWED_RANGE */
   2076     bcmRxReasonInvalid,                 /* NIV_RPF_LOOKUP_MISS */
   2077     bcmRxReasonInvalid,                 /* NIV_VNTAG_PRESENT */
   2078     bcmRxReasonInvalid,                 /* NIV_VNTAG_NOT_PRESENT */
   2079     bcmRxReasonInvalid,                 /* MPLS_OUT_OF_LOOKUPS */
   2080     bcmRxReasonBHHOAM,                  /* BHH_OAM_PACKET */
   2081     bcmRxReasonMplsRouterAlertLabel,    /* MPLS_ALERT_LABEL */
   2082     bcmRxReasonMplsIllegalReservedLabel,/* MPLS_ILLEGAL_RESERVED_LABEL */
   2083 };
   2084 #endif
   2085 
   2086 #ifdef BCM_SABER2_SUPPORT
   2087 static bcm_rx_reason_t 
   2088 _bcm_saber2_cpu_cos_map_key [] =
   2089 {
   2090     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   2091     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   2092     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   2093     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   2094     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   2095     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   2096     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   2097     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   2098     bcmRxReasonParityError,             /* PARITY_ERROR */
   2099     bcmRxReasonHigigControl,            /* MH_CONTROL */
   2100     bcmRxReasonTtl1,                    /* TTL_1 */
   2101     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   2102     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   2103     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   2104     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   2105     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   2106     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   2107     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   2108     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   2109     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   2110     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   2111     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   2112     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   2113     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   2114     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   2115     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   2116     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   2117     bcmRxReasonVlanFilterMatch,         /* VFP */
   2118     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   2119     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   2120     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   2121     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   2122     bcmRxReasonNhop,                    /* NHOP */
   2123     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   2124     bcmRxReasonFilterMatch,             /* CPU_FFP */
   2125     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   2126     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   2127     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   2128     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   2129     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   2130     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   2131     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   2132     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   2133     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   2134     bcmRxReasonBfdSlowpath,             /* BFD_SLOWPATH */
   2135     bcmRxReasonMmrp,                    /* PROTOCOL_MMRP */
   2136     bcmRxReasonSrp,                     /* PROTOCOL_SRP */
   2137     bcmRxReasonStation,                 /* MY_STATION */
   2138     bcmRxReasonNiv,                     /* NIV_DROP_REASON_ENCODING */
   2139     bcmRxReasonNiv,                     /*   -> */
   2140     bcmRxReasonNiv,                     /* 3 bits */
   2141     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   2142     bcmRxReasonTunnelControl,           /* AMT_CONTROL_PKT */
   2143     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   2144     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   2145     bcmRxReasonOAMError,                /* OAM_ERROR */
   2146     bcmRxReasonL2Marked,                /* PROTOCOL_L2_PKT */
   2147     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   2148     bcmRxReasonInvalid,                 /* RESERVED_0 */
   2149     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   2150     bcmRxReasonBfd,                     /* BFD_ERROR_ENCODING */
   2151     bcmRxReasonBfdUnknownVersion,
   2152     bcmRxReasonInvalid,                 /* UNKNOWN_SUBTENDING_PORT */
   2153     bcmRxReasonOAMCCMSlowpath,          /* OAM_CCM */
   2154     bcmRxReasonInvalid,                 /* LLTAG_PRESENT */
   2155     bcmRxReasonInvalid,                 /* LLTAG_NOT_PRESENT */
   2156     bcmRxReasonInvalid,                 /* ENTROPY_LABEL_IN_UNALLOWED_RANGE */
   2157     bcmRxReasonInvalid,                 /* NIV_RPF_LOOKUP_MISS */
   2158     bcmRxReasonInvalid,                 /* NIV_VNTAG_PRESENT */
   2159     bcmRxReasonInvalid,                 /* NIV_VNTAG_NOT_PRESENT */
   2160     bcmRxReasonInvalid,                 /* MPLS_OUT_OF_LOOKUPS */
   2161     bcmRxReasonBHHOAM,                  /* BHH_OAM_PACKET */
   2162     bcmRxReasonMplsRouterAlertLabel,    /* MPLS_ALERT_LABEL */
   2163     bcmRxReasonMplsIllegalReservedLabel,/* MPLS_ILLEGAL_RESERVED_LABEL */
   2164     bcmRxReasonInvalid,                 /* SAT_DN_SAMP_RX */
   2165     bcmRxReasonOAMMplsLmDm,             /* MPLS_LMDM_OAM_PKT */
   2166 };
   2167 #endif /* BCM_SABER2_SUPPORT */
   2168 
   2169 #ifdef BCM_TRIUMPH3_SUPPORT
   2170 
   2171 
   2172 static bcm_rx_reason_t 
   2173 _bcm_triumph3_ip_cpu_cos_map_key [] =
   2174 {
   2175     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   2176     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   2177     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   2178     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   2179     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   2180     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   2181     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   2182     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   2183     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   2184     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   2185     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   2186     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   2187     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   2188     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   2189     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   2190     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   2191     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   2192     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   2193     bcmRxReasonMmrp,                    /* PROTOCOL_MMRP */
   2194     bcmRxReasonSrp,                     /* PROTOCOL_SRP */
   2195     bcmRxReasonTunnelControl,           /* AMT_CONTROL_PKT */
   2196     bcmRxReasonL2Marked,                /* PROTOCOL_L2_PKT */
   2197     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   2198     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   2199     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   2200     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   2201     bcmRxReasonInvalid,                 /* L3_SLOWPATH - duplicate */
   2202     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   2203     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   2204     bcmRxReasonVlanFilterMatch,         /* VFP */
   2205     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   2206     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   2207     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   2208     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   2209     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   2210     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   2211     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   2212     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   2213     bcmRxReasonNhop,                    /* NHOP */
   2214     bcmRxReasonStation,                 /* MY_STATION */
   2215     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   2216     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   2217     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   2218     bcmRxReasonOAMError,                /* OAM_ERROR */
   2219     bcmRxReasonIpfixRateViolation,      /* IPFIX_FLOW */
   2220     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   2221     bcmRxReasonEncapHigigError,         /* EHG_NONHG */
   2222     bcmRxReasonRegexMatch,              /* FLOW_TRACKER */
   2223     bcmRxReasonBfd,                     /* BFD_ERROR */
   2224     bcmRxReasonBfdSlowpath,             /* BFD_SLOWPATH */
   2225     bcmRxReasonFailoverDrop,            /* PROTECTION_DROP_DATA */
   2226     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   2227     bcmRxReasonHigigControl,            /* MH_CONTROL */
   2228     bcmRxReasonTtl1,                    /* TTL_1 */
   2229     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   2230     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   2231     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   2232     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   2233     bcmRxReasonNivUntagDrop,            /* NIV_UNTAG_DROP */
   2234     bcmRxReasonNivTagDrop,              /* NIV_TAG_DROP */
   2235     bcmRxReasonNivTagInvalid,           /* NIV_TAG_INVALID */
   2236     bcmRxReasonNivRpfFail,              /* NIV_RPF_FAIL */
   2237     bcmRxReasonNivInterfaceMiss,        /* NIV_INTERFACE_MISS */
   2238     bcmRxReasonNivPrioDrop,             /* NIV_PRIO_DROP */
   2239     bcmRxReasonTrillName,               /* NICKNAME_TABLE_COPYTOCPU */
   2240     bcmRxReasonTrillTtl,                /* TRILL_HOP_COUNT_CHECK_FAIL */
   2241     bcmRxReasonTrillCoreIsIs,           /* TRILL_CORE_IS_IS_PKT */
   2242     bcmRxReasonTrillSlowpath,           /* TRILL_SLOWPATH */
   2243     bcmRxReasonTrillRpfFail,            /* TRILL_RPF_CHECK_FAIL */
   2244     bcmRxReasonTrillMiss,               /* TRILL_LOOKUP_MISS */
   2245     bcmRxReasonTrillInvalid,            /* TRILL_HDR_ERROR */
   2246     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   2247     bcmRxReasonWlanSlowpathKeepalive,   /* CAPWAP_KEEPALIVE */
   2248     bcmRxReasonWlanTunnelError,         /* WLAN_SHIM_HEADER_ERROR_TO_CPU */
   2249     bcmRxReasonWlanSlowpath,            /* WLAN_CAPWAP_SLOWPATH */
   2250     bcmRxReasonWlanDot1xDrop,           /* WLAN_DOT1X_DROP */
   2251     bcmRxReasonMplsReservedEntropyLabel, /* ENTROPY_LABEL_IN_UNALLOWED_RANGE */
   2252     bcmRxReasonCongestionCnmProxy,      /* QCN_CNM_PRP */
   2253     bcmRxReasonCongestionCnmProxyError, /* QCN_CNM_PRP_DLF */
   2254     bcmRxReasonMplsUnknownAch,          /* MPLS_UNKNOWN_ACH_TYPE */
   2255     bcmRxReasonMplsLookupsExceeded,     /* MPLS_OUT_OF_LOOKUPS */
   2256     bcmRxReasonMplsIllegalReservedLabel, /* MPLS_ILLEGAL_RESERVED_LABEL */
   2257     bcmRxReasonMplsRouterAlertLabel,    /* MPLS_ALERT_LABEL */
   2258     bcmRxReasonParityError,             /* PARITY_ERROR */
   2259     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   2260     bcmRxReasonFilterMatch,             /* CPU_FFP */
   2261     bcmRxReasonTimesyncUnknownVersion,  /* IEEE1588_UNKNOWN_VERSION */
   2262     bcmRxReasonCongestionCnm,           /* ICNM */
   2263     bcmRxReasonL2GreSipMiss,            /* L2GRE_SIP_MISS */
   2264     bcmRxReasonL2GreVpnIdMiss,          /* L2GRE_VPNID_MISS */
   2265 };
   2266 
   2267 static bcm_rx_reason_t 
   2268 _bcm_triumph3_ep_cpu_cos_map_key [] =
   2269 {
   2270     bcmRxReasonUnknownVlan,             /* CPUE_VLAN */
   2271     bcmRxReasonStp,                     /* CPUE_STG */
   2272     bcmRxReasonVlanTranslate,           /* CPUE_VXLT */
   2273     bcmRxReasonTunnelError,             /* CPUE_TUNNEL */
   2274     bcmRxReasonIpmc,                    /* CPUE_L3ERR */
   2275     bcmRxReasonL3HeaderError,           /* CPUE_L3PKT_ERR */
   2276     bcmRxReasonTtl,                     /* CPUE_TTL_DROP */
   2277     bcmRxReasonL2MtuFail,               /* CPUE_MTU */
   2278     bcmRxReasonHigigHdrError,           /* CPUE_HIGIG */
   2279     bcmRxReasonSplitHorizon,            /* CPUE_PRUNE */
   2280     bcmRxReasonNivPrune,                /* CPUE_NIV_DISCARD */
   2281     bcmRxReasonVirtualPortPrune,        /* CPUE_SPLIT_HORIZON */
   2282     bcmRxReasonInvalid,                 /* CPUE_EFP */
   2283     bcmRxReasonNonUnicastDrop,          /* CPUE_MULTI_DEST */
   2284     bcmRxReasonTrillPacketPortMismatch, /* CPUE_TRILL */
   2285     bcmRxReasonInvalid,                 /* Reserved */
   2286     bcmRxReasonInvalid,                 /* Reserved */
   2287     bcmRxReasonInvalid,                 /* Reserved */
   2288     bcmRxReasonInvalid,                 /* Reserved */
   2289     bcmRxReasonInvalid,                 /* Reserved */
   2290     bcmRxReasonTunnelControl,           /* AMT_CONTROL_PKT */
   2291     bcmRxReasonL2Marked,                /* PROTOCOL_L2_PKT */
   2292     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   2293     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   2294     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   2295     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   2296     bcmRxReasonInvalid,                 /* L3_SLOWPATH - duplicate */
   2297     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   2298     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   2299     bcmRxReasonVlanFilterMatch,         /* VFP */
   2300     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   2301     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   2302     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   2303     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   2304     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   2305     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   2306     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   2307     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   2308     bcmRxReasonNhop,                    /* NHOP */
   2309     bcmRxReasonStation,                 /* MY_STATION */
   2310     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   2311     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   2312     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   2313     bcmRxReasonOAMError,                /* OAM_ERROR */
   2314     bcmRxReasonIpfixRateViolation,      /* IPFIX_FLOW */
   2315     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   2316     bcmRxReasonEncapHigigError,         /* EHG_NONHG */
   2317     bcmRxReasonRegexMatch,              /* FLOW_TRACKER */
   2318     bcmRxReasonBfd,                     /* BFD_ERROR */
   2319     bcmRxReasonBfdSlowpath,             /* BFD_SLOWPATH */
   2320     bcmRxReasonFailoverDrop,            /* PROTECTION_DROP_DATA */
   2321     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   2322     bcmRxReasonHigigControl,            /* MH_CONTROL */
   2323     bcmRxReasonTtl1,                    /* TTL_1 */
   2324     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   2325     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   2326     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   2327     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   2328     bcmRxReasonNivUntagDrop,            /* NIV_UNTAG_DROP */
   2329     bcmRxReasonNivTagDrop,              /* NIV_TAG_DROP */
   2330     bcmRxReasonNivTagInvalid,           /* NIV_TAG_INVALID */
   2331     bcmRxReasonNivRpfFail,              /* NIV_RPF_FAIL */
   2332     bcmRxReasonNivInterfaceMiss,        /* NIV_INTERFACE_MISS */
   2333     bcmRxReasonNivPrioDrop,             /* NIV_PRIO_DROP */
   2334     bcmRxReasonTrillName,               /* NICKNAME_TABLE_COPYTOCPU */
   2335     bcmRxReasonTrillTtl,                /* TRILL_HOP_COUNT_CHECK_FAIL */
   2336     bcmRxReasonTrillCoreIsIs,           /* TRILL_CORE_IS_IS_PKT */
   2337     bcmRxReasonTrillSlowpath,           /* TRILL_SLOWPATH */
   2338     bcmRxReasonTrillRpfFail,            /* TRILL_RPF_CHECK_FAIL */
   2339     bcmRxReasonTrillMiss,               /* TRILL_LOOKUP_MISS */
   2340     bcmRxReasonTrillInvalid,            /* TRILL_HDR_ERROR */
   2341     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   2342     bcmRxReasonWlanSlowpathKeepalive,   /* CAPWAP_KEEPALIVE */
   2343     bcmRxReasonWlanTunnelError,         /* WLAN_SHIM_HEADER_ERROR_TO_CPU */
   2344     bcmRxReasonWlanSlowpath,            /* WLAN_CAPWAP_SLOWPATH */
   2345     bcmRxReasonWlanDot1xDrop,           /* WLAN_DOT1X_DROP */
   2346     bcmRxReasonMplsReservedEntropyLabel, /* ENTROPY_LABEL_IN_UNALLOWED_RANGE */
   2347     bcmRxReasonCongestionCnmProxy,      /* QCN_CNM_PRP */
   2348     bcmRxReasonCongestionCnmProxyError, /* QCN_CNM_PRP_DLF */
   2349     bcmRxReasonMplsUnknownAch,          /* MPLS_UNKNOWN_ACH_TYPE */
   2350     bcmRxReasonMplsLookupsExceeded,     /* MPLS_OUT_OF_LOOKUPS */
   2351     bcmRxReasonMplsIllegalReservedLabel, /* MPLS_ILLEGAL_RESERVED_LABEL */
   2352     bcmRxReasonMplsRouterAlertLabel,    /* MPLS_ALERT_LABEL */
   2353     bcmRxReasonParityError,             /* PARITY_ERROR */
   2354     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   2355     bcmRxReasonFilterMatch,             /* CPU_FFP */
   2356     bcmRxReasonTimesyncUnknownVersion,  /* IEEE1588_UNKNOWN_VERSION */
   2357     bcmRxReasonCongestionCnm,           /* ICNM */
   2358     bcmRxReasonL2GreSipMiss,            /* L2GRE_SIP_MISS */
   2359     bcmRxReasonL2GreVpnIdMiss,          /* L2GRE_VPNID_MISS */
   2360 };
   2361 
   2362 static bcm_rx_reason_t 
   2363 _bcm_triumph3_nlf_cpu_cos_map_key [] =
   2364 {
   2365     bcmRxReasonRegexAction,              /* SM_TOCPU */
   2366     bcmRxReasonWlanClientMove,          /* WLAN_MOVE_TOCPU */
   2367     bcmRxReasonWlanSourcePortMiss,      /* WLAN_SVP_MISS_TOCPU */
   2368     bcmRxReasonWlanClientError,         /* WLAN_DATABASE_ERROR */
   2369     bcmRxReasonWlanClientSourceMiss,    /* WLAN_CLIENT_DATABASE_SA_MISS */
   2370     bcmRxReasonWlanClientDestMiss,      /* WLAN_CLIENT_DATABASE_DA_MISS */
   2371     bcmRxReasonWlanMtu,                 /* WLAN_MTU_FAIL */
   2372     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   2373     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   2374     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   2375     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   2376     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   2377     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   2378     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   2379     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   2380     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   2381     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   2382     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   2383     bcmRxReasonMmrp,                    /* PROTOCOL_MMRP */
   2384     bcmRxReasonSrp,                     /* PROTOCOL_SRP */
   2385     bcmRxReasonTunnelControl,           /* AMT_CONTROL_PKT */
   2386     bcmRxReasonL2Marked,                /* PROTOCOL_L2_PKT */
   2387     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   2388     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   2389     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   2390     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   2391     bcmRxReasonInvalid,                 /* L3_SLOWPATH - duplicate */
   2392     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   2393     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   2394     bcmRxReasonVlanFilterMatch,         /* VFP */
   2395     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   2396     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   2397     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   2398     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   2399     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   2400     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   2401     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   2402     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   2403     bcmRxReasonNhop,                    /* NHOP */
   2404     bcmRxReasonStation,                 /* MY_STATION */
   2405     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   2406     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   2407     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   2408     bcmRxReasonOAMError,                /* OAM_ERROR */
   2409     bcmRxReasonIpfixRateViolation,      /* IPFIX_FLOW */
   2410     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   2411     bcmRxReasonEncapHigigError,         /* EHG_NONHG */
   2412     bcmRxReasonRegexMatch,              /* FLOW_TRACKER */
   2413     bcmRxReasonBfd,                     /* BFD_ERROR */
   2414     bcmRxReasonBfdSlowpath,             /* BFD_SLOWPATH */
   2415     bcmRxReasonFailoverDrop,            /* PROTECTION_DROP_DATA */
   2416     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   2417     bcmRxReasonHigigControl,            /* MH_CONTROL */
   2418     bcmRxReasonTtl1,                    /* TTL_1 */
   2419     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   2420     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   2421     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   2422     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   2423     bcmRxReasonNivUntagDrop,            /* NIV_UNTAG_DROP */
   2424     bcmRxReasonNivTagDrop,              /* NIV_TAG_DROP */
   2425     bcmRxReasonNivTagInvalid,           /* NIV_TAG_INVALID */
   2426     bcmRxReasonNivRpfFail,              /* NIV_RPF_FAIL */
   2427     bcmRxReasonNivInterfaceMiss,        /* NIV_INTERFACE_MISS */
   2428     bcmRxReasonNivPrioDrop,             /* NIV_PRIO_DROP */
   2429     bcmRxReasonTrillName,               /* NICKNAME_TABLE_COPYTOCPU */
   2430     bcmRxReasonTrillTtl,                /* TRILL_HOP_COUNT_CHECK_FAIL */
   2431     bcmRxReasonTrillCoreIsIs,           /* TRILL_CORE_IS_IS_PKT */
   2432     bcmRxReasonTrillSlowpath,           /* TRILL_SLOWPATH */
   2433     bcmRxReasonTrillRpfFail,            /* TRILL_RPF_CHECK_FAIL */
   2434     bcmRxReasonTrillMiss,               /* TRILL_LOOKUP_MISS */
   2435     bcmRxReasonTrillInvalid,            /* TRILL_HDR_ERROR */
   2436     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   2437     bcmRxReasonWlanSlowpathKeepalive,   /* CAPWAP_KEEPALIVE */
   2438     bcmRxReasonWlanTunnelError,         /* WLAN_SHIM_HEADER_ERROR_TO_CPU */
   2439     bcmRxReasonWlanSlowpath,            /* WLAN_CAPWAP_SLOWPATH */
   2440     bcmRxReasonWlanDot1xDrop,           /* WLAN_DOT1X_DROP */
   2441     bcmRxReasonMplsReservedEntropyLabel, /* ENTROPY_LABEL_IN_UNALLOWED_RANGE */
   2442     bcmRxReasonCongestionCnmProxy,      /* QCN_CNM_PRP */
   2443     bcmRxReasonCongestionCnmProxyError, /* QCN_CNM_PRP_DLF */
   2444     bcmRxReasonMplsUnknownAch,          /* MPLS_UNKNOWN_ACH_TYPE */
   2445     bcmRxReasonMplsLookupsExceeded,     /* MPLS_OUT_OF_LOOKUPS */
   2446     bcmRxReasonMplsIllegalReservedLabel, /* MPLS_ILLEGAL_RESERVED_LABEL */
   2447     bcmRxReasonMplsRouterAlertLabel,    /* MPLS_ALERT_LABEL */
   2448     bcmRxReasonParityError,             /* PARITY_ERROR */
   2449     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   2450     bcmRxReasonFilterMatch,             /* CPU_FFP */
   2451     bcmRxReasonTimesyncUnknownVersion,  /* IEEE1588_UNKNOWN_VERSION */
   2452     bcmRxReasonCongestionCnm,           /* ICNM */
   2453     bcmRxReasonL2GreSipMiss,            /* L2GRE_SIP_MISS */
   2454     bcmRxReasonL2GreVpnIdMiss,          /* L2GRE_VPNID_MISS */
   2455 };
   2456 
   2457 static bcm_rx_reason_t *_bcm_tr3_cpu_cos_map_overlays[_bcm_tr3_rx_cpu_cosmap_key_overlays] = {
   2458     _bcm_triumph3_ip_cpu_cos_map_key,
   2459     _bcm_triumph3_ep_cpu_cos_map_key,
   2460     _bcm_triumph3_nlf_cpu_cos_map_key,
   2461 };
   2462 
   2463 static uint32 _bcm_tr3_cpu_cos_map_maxs[_bcm_tr3_rx_cpu_cosmap_key_overlays] = {
   2464     _bcm_tr3_rx_ip_cpu_cosmap_key_max,
   2465     _bcm_tr3_rx_ep_cpu_cosmap_key_max,
   2466     _bcm_tr3_rx_nlf_cpu_cosmap_key_max,
   2467 };
   2468 
   2469 #endif /* BCM_TRIUMPH3_SUPPORT */
   2470 
   2471 #ifdef BCM_GREYHOUND_SUPPORT
   2472 static bcm_rx_reason_t 
   2473 _bcm_greyhound_cpu_cos_map_key [] =
   2474 {
   2475     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   2476     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   2477     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   2478     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   2479     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   2480     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   2481     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   2482     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   2483     bcmRxReasonParityError,             /* PARITY_ERROR */
   2484     bcmRxReasonHigigControl,            /* MH_CONTROL */
   2485     bcmRxReasonTtl1,                    /* TTL_1 */
   2486     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   2487     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   2488     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   2489     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   2490     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   2491     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   2492     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   2493     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   2494     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   2495     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   2496     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   2497     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   2498     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   2499     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   2500     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   2501     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   2502     bcmRxReasonVlanFilterMatch,         /* VFP */
   2503     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   2504     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   2505     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   2506     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   2507     bcmRxReasonNhop,                    /* NHOP */
   2508     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   2509     bcmRxReasonFilterMatch,             /* CPU_FFP */
   2510     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   2511     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   2512     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   2513     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   2514     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   2515     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   2516     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   2517     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   2518     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   2519     bcmRxReasonMplsCtrlWordError,       /* MPLS_CW_TYPE_NOT_ZERO */
   2520     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   2521     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   2522     bcmRxReasonOAMError,                /* OAM_ERROR */
   2523     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   2524     bcmRxReasonL2Marked,                 /* PROTOCOL_L2_PKT */
   2525     bcmRxReasonTimesyncUnknownVersion,  /* IEEE1588_UNKNOWN_VERSION */
   2526     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   2527     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   2528     bcmRxReasonNiv,                     /* NIV_DROP_REASON_ENCODING */
   2529     bcmRxReasonNiv,                     /*   -> */
   2530     bcmRxReasonNiv,                      /* 3 bits */
   2531 };
   2532 #endif /* BCM_GREYHOUND_SUPPORT */
   2533 
   2534 #ifdef BCM_GREYHOUND2_SUPPORT
   2535 static bcm_rx_reason_t
   2536 _bcm_greyhound2_cpu_cos_map_key [] =
   2537 {
   2538     bcmRxReasonBpdu,                    /* PROTOCOL_BPDU */
   2539     bcmRxReasonIpmcReserved,            /* PROTOCOL_IPMC_RSVD */
   2540     bcmRxReasonDhcp,                    /* PROTOCOL_DHCP */
   2541     bcmRxReasonIgmp,                    /* PROTOCOL_IGMP */
   2542     bcmRxReasonArp,                     /* PROTOCOL_ARP */
   2543     bcmRxReasonUnknownVlan,             /* CPU_UVLAN. */
   2544     bcmRxReasonSharedVlanMismatch,      /* PVLAN_MISMATCH */
   2545     bcmRxReasonDosAttack,               /* CPU_DOS_ATTACK */
   2546     bcmRxReasonParityError,             /* PARITY_ERROR */
   2547     bcmRxReasonHigigControl,            /* MH_CONTROL */
   2548     bcmRxReasonTtl1,                    /* TTL_1 */
   2549     bcmRxReasonL3Slowpath,              /* IP_OPTIONS_PKT. */
   2550     bcmRxReasonL2SourceMiss,            /* CPU_SLF */
   2551     bcmRxReasonL2DestMiss,              /* CPU_DLF */
   2552     bcmRxReasonL2Move,                  /* CPU_L2MOVE */
   2553     bcmRxReasonL2Cpu,                   /* CPU_L2CPU */
   2554     bcmRxReasonL2NonUnicastMiss,        /* PBT_NONUC_PKT */
   2555     bcmRxReasonL3SourceMiss,            /* CPU_L3SRC_MISS. */
   2556     bcmRxReasonL3DestMiss,              /* CPU_L3DST_MISS */
   2557     bcmRxReasonL3SourceMove,            /* CPU_L3SRC_MOVE */
   2558     bcmRxReasonMcastMiss,               /* CPU_MC_MISS */
   2559     bcmRxReasonIpMcastMiss,             /* CPU_IPMC_MISS */
   2560     bcmRxReasonL3HeaderError,           /* CPU_L3HDR_ERR */
   2561     bcmRxReasonMartianAddr,             /* CPU_MARTIAN_ADDR */
   2562     bcmRxReasonTunnelError,             /* CPU_TUNNEL_ERR */
   2563     bcmRxReasonHigigHdrError,           /* HGHDR_ERROR */
   2564     bcmRxReasonMcastIdxError,           /* MCIDX_ERROR */
   2565     bcmRxReasonVlanFilterMatch,         /* VFP */
   2566     bcmRxReasonClassBasedMove,          /* CBSM_PREVENTED */
   2567     bcmRxReasonL2LearnLimit,            /* MAC_LIMIT */
   2568     bcmRxReasonE2eHolIbp,               /* E2E_HOL_IBP */
   2569     bcmRxReasonClassTagPackets,         /* HG_HDR_TYPE1 */
   2570     bcmRxReasonNhop,                    /* NHOP */
   2571     bcmRxReasonUrpfFail,                /* URPF_FAILED */
   2572     bcmRxReasonFilterMatch,             /* CPU_FFP */
   2573     bcmRxReasonIcmpRedirect,            /* ICMP_REDIRECT */
   2574     bcmRxReasonSampleSource,            /* CPU_SFLOW_SRC */
   2575     bcmRxReasonSampleDest,              /* CPU_SFLOW_DST */
   2576     bcmRxReasonL3MtuFail,               /* L3_MTU_CHECK_FAIL */
   2577     bcmRxReasonMplsLabelMiss,           /* MPLS_LABEL_MISS */
   2578     bcmRxReasonMplsInvalidAction,       /* MPLS_INVALID_ACTION */
   2579     bcmRxReasonMplsInvalidPayload,      /* MPLS_INVALID_PAYLOAD */
   2580     bcmRxReasonMplsTtl,                 /* MPLS_TTL_CHECK_FAIL */
   2581     bcmRxReasonMplsSequenceNumber,      /* MPLS_SEQ_NUM_FAIL */
   2582     bcmRxReasonMplsCtrlWordError,       /* MPLS_CW_TYPE_NOT_ZERO */
   2583     bcmRxReasonTimeSync,                /* TIME_SYNC_PKT */
   2584     bcmRxReasonOAMSlowpath,             /* OAM_SLOWPATH */
   2585     bcmRxReasonOAMError,                /* OAM_ERROR */
   2586     bcmRxReasonOAMLMDM,                 /* OAM_LMDM */
   2587     bcmRxReasonL2Marked,                 /* PROTOCOL_L2_PKT */
   2588     bcmRxReasonTimesyncUnknownVersion,  /* IEEE1588_UNKNOWN_VERSION */
   2589     bcmRxReasonL3AddrBindFail,          /* MAC_BIND_FAIL */
   2590     bcmRxReasonVlanTranslate,           /* VXLT_MISS */
   2591     bcmRxReasonNiv,                     /* NIV_DROP_REASON_ENCODING */
   2592     bcmRxReasonNiv,                     /*   -> */
   2593     bcmRxReasonNiv,                     /* 3 bits */
   2594     bcmRxReasonStation,                 /* MY_STATION_PKT_OFFSET */
   2595     bcmRxReasonL2StuFail,               /* STU_CHECK_FAIL_OFFSET */
   2596     bcmRxReasonSrCounterExceeded,       /* SR_COUNTER_THRESHOLD_EXCEEDED_OFFSET */
   2597     bcmRxReasonSrCopyToCpuBit0,         /* USER_DEFINED_CPU_OFFSET */
   2598     bcmRxReasonSrCopyToCpuBit1,         /*   -> */
   2599     bcmRxReasonSrCopyToCpuBit2,         /*   -> */
   2600     bcmRxReasonSrCopyToCpuBit3,         /*   -> */
   2601     bcmRxReasonSrCopyToCpuBit4,         /*   -> */
   2602     bcmRxReasonSrCopyToCpuBit5,         /* 6 bits */
   2603 };
   2604 #endif /* BCM_GREYHOUND2_SUPPORT */
   2605 
   2606 
   2607 #endif /* BCM_TRX_SUPPORT */
   2608 
   2609 #ifdef BCM_TRIUMPH3_SUPPORT
   2610 /*
   2611  * Function:
   2612  *      _bcm_esw_rcmr_overlay_get
   2613  * Purpose:
   2614  *      Get all supported reasons for overlayed CPU cosq mapping 
   2615  * Parameters:
   2616  *      unit - Unit reference
   2617  *      reasons - cpu cosq "reasons" mapping bitmap
   2618  * Returns:
   2619  *      BCM_E_XXX
   2620  */
   2621 STATIC int 
   2622 _bcm_esw_rcmr_overlay_get(int unit, bcm_rx_reasons_t * reasons)
   2623 {
   2624     uint32          sz, *sz_overlays;
   2625     uint32          ix, ovx;
   2626     bcm_rx_reason_t *cpu_cos_map_key, **cpu_cos_map_overlays;
   2627 
   2628     if (SOC_IS_TRIUMPH3(unit)) {
   2629         cpu_cos_map_overlays = _bcm_tr3_cpu_cos_map_overlays;
   2630         sz_overlays = _bcm_tr3_cpu_cos_map_maxs;
   2631     } else {
   2632         /* If the feature check passes, we should have an implementation */
   2633         return BCM_E_INTERNAL;
   2634     }
   2635 
   2636     for (ovx = 0; ovx < _bcm_tr3_rx_cpu_cosmap_key_overlays; ovx++) {
   2637         cpu_cos_map_key = cpu_cos_map_overlays[ovx];
   2638         sz = sz_overlays[ovx];
   2639         for (ix = 0; ix < sz; ix++) {
   2640             /* coverity [mixed_enums] */
   2641              if (cpu_cos_map_key[ix] != (bcm_rx_reason_t) bcmRxReasonInvalid) {
   2642                  BCM_RX_REASON_SET(*reasons, cpu_cos_map_key[ix]);
   2643              }
   2644         }
   2645     }
   2646     return BCM_E_NONE;
   2647 }
   2648 
   2649 static soc_field_t _bcm_tr3_reason_fields[_bcm_tr3_rx_cpu_cosmap_key_words] = {
   2650     REASONS_KEY_LOWf,
   2651     REASONS_KEY_MIDf,
   2652     REASONS_KEY_HIGHf,
   2653 };
   2654 
   2655 static soc_field_t _bcm_tr3_mask_fields[_bcm_tr3_rx_cpu_cosmap_key_words] = {
   2656     REASONS_MASK_LOWf,
   2657     REASONS_MASK_MIDf,
   2658     REASONS_MASK_HIGHf,
   2659 };
   2660 
   2661 STATIC int
   2662 _bcm_tr3_rx_cosq_mapping_get(int unit, int index,
   2663                             bcm_rx_reasons_t *reasons, 
   2664                             bcm_rx_reasons_t *reasons_mask,
   2665                             uint8 *prio, uint8 *prio_mask,
   2666                             uint32 *packet_type, uint32 * packet_type_mask,
   2667                             bcm_cos_queue_t *cosq)
   2668 {
   2669     cpu_cos_map_entry_t entry; 
   2670     uint32 key[_bcm_rx_cpu_cosmap_key_words_max];
   2671     uint32 mask[_bcm_rx_cpu_cosmap_key_words_max];
   2672     uint32 maskwordlen[_bcm_rx_cpu_cosmap_key_words_max];
   2673     uint32 keywordlen[_bcm_rx_cpu_cosmap_key_words_max];
   2674     uint32 ix, ovx, word, words, key_len, mask_len, cur_len;
   2675     uint32 sw_pkt_type_mask, sw_pkt_type_key;
   2676     uint32 reason_type_mask, reason_type_key;
   2677     uint32 maskbitset, keybitset;
   2678     soc_field_t *reason_fields, *mask_fields;
   2679     bcm_rx_reason_t *cpu_cos_map_key, **cpu_cos_map_overlays;
   2680 
   2681     if (SOC_IS_TRIUMPH3(unit)) {
   2682         cpu_cos_map_overlays = _bcm_tr3_cpu_cos_map_overlays;
   2683         reason_fields = _bcm_tr3_reason_fields;
   2684         mask_fields = _bcm_tr3_mask_fields;
   2685         words = _bcm_tr3_rx_cpu_cosmap_key_words;
   2686     } else {
   2687         
   2688         return BCM_E_INTERNAL;
   2689     }
   2690 
   2691     /* Verify the index */
   2692     if (index < soc_mem_index_min(unit, CPU_COS_MAPm) ||
   2693         index > soc_mem_index_max(unit, CPU_COS_MAPm)) {
   2694         return BCM_E_PARAM;
   2695     }
   2696 
   2697     /* NULL pointer check */
   2698     if (reasons == NULL  || reasons_mask == NULL  || 
   2699         prio == NULL || prio_mask == NULL || 
   2700         packet_type == NULL || packet_type_mask == NULL || 
   2701         cosq == NULL) {
   2702         return BCM_E_PARAM;
   2703     }
   2704  
   2705     /* Read the entry */
   2706     SOC_IF_ERROR_RETURN
   2707         (READ_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, index, &entry));
   2708 
   2709     /* Return BCM_E_NOT_FOUND if invalid */
   2710     if (soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, VALIDf) == 0) {
   2711         return (BCM_E_NOT_FOUND);
   2712     }        
   2713 
   2714     sal_memset(reasons, 0, sizeof(bcm_rx_reasons_t));
   2715     sal_memset(reasons_mask, 0, sizeof(bcm_rx_reasons_t));
   2716 
   2717     *cosq = (bcm_cos_queue_t)
   2718               soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, COSf);
   2719     
   2720     sw_pkt_type_mask = soc_mem_field32_get(unit, CPU_COS_MAPm, 
   2721                                            &entry, SW_PKT_TYPE_MASKf);
   2722     sw_pkt_type_key  = soc_mem_field32_get(unit, CPU_COS_MAPm, 
   2723                                            &entry, SW_PKT_TYPE_KEYf);
   2724 
   2725     if (sw_pkt_type_mask == 0 && sw_pkt_type_key == 0) {
   2726         /* all packets matched */
   2727         *packet_type_mask = 0;
   2728         *packet_type = 0;
   2729     } else if (sw_pkt_type_mask == 2 && sw_pkt_type_key == 0) {
   2730         /* Only non-switched packets */
   2731         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   2732         *packet_type = 0;
   2733     } else if (sw_pkt_type_mask == 2 && sw_pkt_type_key == 2) {
   2734         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   2735         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   2736     } else if (sw_pkt_type_mask == 3 && sw_pkt_type_key == 2) {
   2737         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED | 
   2738                              BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   2739         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   2740     } else if (sw_pkt_type_mask == 3 && sw_pkt_type_key == 3) {
   2741         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED |
   2742                              BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   2743         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED |
   2744                         BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   2745     }
   2746  
   2747     if (soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, MIRR_PKT_MASKf)) {
   2748         *packet_type_mask |= BCM_RX_COSQ_PACKET_TYPE_MIRROR;
   2749     }
   2750 
   2751     if (soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, MIRR_PKT_KEYf)) {
   2752         *packet_type |= BCM_RX_COSQ_PACKET_TYPE_MIRROR;
   2753     }
   2754 
   2755     reason_type_mask = soc_mem_field32_get(unit, CPU_COS_MAPm, 
   2756                                            &entry, REASON_CODE_TYPE_MASKf);
   2757     reason_type_key  = soc_mem_field32_get(unit, CPU_COS_MAPm, 
   2758                                            &entry, REASON_CODE_TYPE_KEYf);
   2759 
   2760     if ((0 != reason_type_mask) && 
   2761         (_bcm_tr3_rx_cpu_cosmap_reason_type_mask != reason_type_mask)) {
   2762         /* This should be set to exact match or all */
   2763         return BCM_E_INTERNAL;
   2764     }
   2765 
   2766     switch (reason_type_key) {
   2767     case 0:
   2768         ovx = 0; /* IP overlay */
   2769         break;
   2770     case 2:
   2771         ovx = 1; /* EP overlay */
   2772         break;
   2773     case 3:
   2774         ovx = 2; /* NLF overlay */
   2775         break;
   2776     default:
   2777         /* Not a valid choice on current devices */
   2778         return BCM_E_INTERNAL;
   2779     }
   2780     cpu_cos_map_key = cpu_cos_map_overlays[ovx];
   2781 
   2782     *prio_mask = 
   2783         soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, INT_PRI_MASKf);
   2784     *prio = 
   2785         soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, INT_PRI_KEYf);
   2786 
   2787     mask_len = key_len = 0;
   2788     for (word = 0; word < words; word++) {
   2789         mask[word] = 
   2790             soc_mem_field32_get(unit, CPU_COS_MAPm, &entry,
   2791                                 mask_fields[word]);
   2792         maskwordlen[word] =
   2793             soc_mem_field_length(unit, CPU_COS_MAPm, mask_fields[word]);
   2794         mask_len += maskwordlen[word];
   2795 
   2796         key[word] = 
   2797             soc_mem_field32_get(unit, CPU_COS_MAPm, &entry,
   2798                                 reason_fields[word]);
   2799         keywordlen[word] =
   2800             soc_mem_field_length(unit, CPU_COS_MAPm, reason_fields[word]);
   2801         key_len += keywordlen[word];
   2802 
   2803         if (keywordlen[word] != maskwordlen[word]) {
   2804             
   2805             return BCM_E_INTERNAL;
   2806         }
   2807     }
   2808 
   2809     if (key_len != mask_len) {
   2810         
   2811         return BCM_E_INTERNAL;
   2812     }
   2813 
   2814     cur_len = word = 0;
   2815     for (ix = 0; ix < key_len; ix++) {
   2816         if (ix == (cur_len + keywordlen[word])) {
   2817             /* Start of new word, advance values */
   2818             cur_len += keywordlen[word];
   2819             word++;
   2820         }
   2821 
   2822         keybitset = key[word] & (1 << (ix - cur_len));
   2823         maskbitset = mask[word] & (1 << (ix - cur_len));
   2824 
   2825         if (maskbitset) {
   2826             BCM_RX_REASON_SET(*reasons_mask, cpu_cos_map_key[ix]);
   2827         }
   2828         if (keybitset) {
   2829             BCM_RX_REASON_SET(*reasons, cpu_cos_map_key[ix]);
   2830         }
   2831     }
   2832 
   2833     return BCM_E_NONE;
   2834 }
   2835 
   2836 int
   2837 _bcm_tr3_rx_cosq_mapping_set(int unit, int index,
   2838                             bcm_rx_reasons_t reasons, bcm_rx_reasons_t
   2839                             reasons_mask,
   2840                             uint8 int_prio, uint8 int_prio_mask,
   2841                             uint32 packet_type, uint32 packet_type_mask,
   2842                             bcm_cos_queue_t cosq)
   2843 {
   2844     bcm_rx_reason_t  ridx;
   2845     bcm_rx_reasons_t reasons_remain;
   2846     uint32 key[_bcm_tr3_rx_cpu_cosmap_key_words];
   2847     uint32 mask[_bcm_tr3_rx_cpu_cosmap_key_words];
   2848     uint32 maskwordlen[_bcm_tr3_rx_cpu_cosmap_key_words];
   2849     uint32 keywordlen[_bcm_tr3_rx_cpu_cosmap_key_words];
   2850     uint32 word, words, key_len, mask_len, cur_len;
   2851     int32 ovx, ovx_max;
   2852     int reason_set;
   2853     cpu_cos_map_entry_t entry; 
   2854     uint8 sw_pkt_type_key = 0;
   2855     uint8 sw_pkt_type_mask = 0;
   2856     uint32 reason_type_mask = 0;
   2857     uint32 reason_type_key = 0;
   2858     uint32 bit;
   2859     soc_field_t *reason_fields, *mask_fields;
   2860     bcm_rx_reason_t *cpu_cos_map_key, **cpu_cos_map_overlays;
   2861     int match_count[_bcm_tr3_rx_cpu_cosmap_key_overlays], max_match, match_ovx;
   2862     int max_overlay_index = 20;
   2863 
   2864     if (SOC_IS_TRIUMPH3(unit)) {
   2865         cpu_cos_map_overlays = _bcm_tr3_cpu_cos_map_overlays;
   2866         reason_fields = _bcm_tr3_reason_fields;
   2867         mask_fields = _bcm_tr3_mask_fields;
   2868         words = _bcm_tr3_rx_cpu_cosmap_key_words;
   2869         ovx_max = _bcm_tr3_rx_cpu_cosmap_key_overlays - 1;
   2870     } else {
   2871         
   2872         return BCM_E_INTERNAL;
   2873     }
   2874 
   2875     /* Verify the index */
   2876     if (index < soc_mem_index_min(unit, CPU_COS_MAPm) ||
   2877         index > soc_mem_index_max(unit, CPU_COS_MAPm)) {
   2878         return BCM_E_PARAM;
   2879     }
   2880 
   2881     /* Verify the cosq */
   2882     if (SOC_IS_TRIUMPH3(unit) &&
   2883         soc_feature(unit, soc_feature_cmic_reserved_queues) && 
   2884         cosq >= _bcm_triumph3_rx_cpu_max_cosq) {
   2885         return BCM_E_PARAM;
   2886     }
   2887 
   2888     if (SOC_IS_TRIUMPH3(unit) &&
   2889         !soc_feature(unit, soc_feature_cmic_reserved_queues) && 
   2890         cosq >= _bcm_triumph3_rx_cpu_max_cosq_a0_a1) {
   2891         return BCM_E_PARAM;
   2892     }
   2893 
   2894     if (SOC_IS_HELIX4(unit) && 
   2895         cosq >= _bcm_trident2_rx_cpu_max_cosq) {
   2896         return BCM_E_PARAM;
   2897     }
   2898 
   2899     /* Verify the packet type */
   2900 
   2901     if (packet_type & BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST) {
   2902         sw_pkt_type_key |= 1;
   2903     }
   2904     if (packet_type & BCM_RX_COSQ_PACKET_TYPE_SWITCHED) {
   2905         sw_pkt_type_key |= 2;
   2906     }
   2907     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST) {
   2908         sw_pkt_type_mask |= 1;
   2909     }
   2910     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_SWITCHED) {
   2911         sw_pkt_type_mask |= 2;
   2912     }
   2913     sw_pkt_type_key &= sw_pkt_type_mask;
   2914 
   2915     if ((sw_pkt_type_mask == 0x1) || 
   2916         ((sw_pkt_type_mask != 0) && (sw_pkt_type_key == 0x1))) { 
   2917         /* Hw doesn't support these cases */
   2918         return BCM_E_PARAM;
   2919     }
   2920 
   2921     BCM_RX_REASON_CLEAR(reasons_mask, bcmRxReasonInvalid);
   2922     reasons_remain = reasons_mask;
   2923 
   2924     mask_len = key_len = 0;
   2925     for (word = 0; word < words; word++) {
   2926         mask[word] = 0;
   2927         maskwordlen[word] =
   2928             soc_mem_field_length(unit, CPU_COS_MAPm, mask_fields[word]);
   2929         mask_len += maskwordlen[word];
   2930 
   2931         key[word] = 0;
   2932         keywordlen[word] =
   2933             soc_mem_field_length(unit, CPU_COS_MAPm, reason_fields[word]);
   2934         key_len += keywordlen[word];
   2935 
   2936         if (keywordlen[word] != maskwordlen[word]) {
   2937             
   2938             return BCM_E_INTERNAL;
   2939         }
   2940     }
   2941 
   2942     if (key_len != mask_len) {
   2943         
   2944         return BCM_E_INTERNAL;
   2945     }
   2946 
   2947     /* Since all overlays are same from max_overlay_index onwards,
   2948        traverse till max_overlay_index to find Max Matching overlay */
   2949     max_match = 0;
   2950     match_ovx = 0;
   2951     for (ovx = ovx_max; ovx >= 0; ovx--) {
   2952         cpu_cos_map_key = cpu_cos_map_overlays[ovx];
   2953         match_count[ovx] = 0;
   2954         for (bit =0; bit < max_overlay_index; bit++) {
   2955             ridx  = cpu_cos_map_key[bit];
   2956             if (BCM_RX_REASON_GET(reasons_mask, ridx)) {
   2957                 match_count[ovx]++;
   2958             }            
   2959         }
   2960         if (max_match <= match_count[ovx]) {
   2961             max_match = match_count[ovx];
   2962             match_ovx = ovx;
   2963         }
   2964     }
   2965 
   2966     ovx = match_ovx;
   2967     cpu_cos_map_key = cpu_cos_map_overlays[ovx];
   2968     reason_set = FALSE;
   2969             bit = 0;
   2970     /* Run through entire selcted overlay */
   2971     for (; bit < _bcm_tr3_rx_ip_cpu_cosmap_key_max; bit++) {
   2972             /* Find reason being set */
   2973             ridx  = cpu_cos_map_key[bit];
   2974 
   2975         if (ridx == bcmRxReasonInvalid) {
   2976             continue;
   2977         }
   2978             if (!BCM_RX_REASON_GET(reasons_mask, ridx)) {
   2979                 continue;
   2980             }
   2981 
   2982             cur_len = 0;
   2983             for (word = 0; word < words; word++) {
   2984                 if (bit < (cur_len + keywordlen[word])) {
   2985                     break;
   2986                 } else {
   2987                     cur_len += keywordlen[word];
   2988                 }
   2989             }
   2990             if (word == words) {
   2991                 
   2992                 return BCM_E_INTERNAL;
   2993             }
   2994 
   2995             mask[word] |=  1 << (bit - cur_len);
   2996             if (BCM_RX_REASON_GET(reasons, ridx)) {
   2997                 key[word] |=  1 << (bit - cur_len);
   2998             }
   2999 
   3000             /* clean the bit of reasons_remain */
   3001             BCM_RX_REASON_CLEAR(reasons_remain, ridx);
   3002 
   3003             if (!reason_set) {
   3004                 reason_set = TRUE;
   3005                 switch (ovx) {
   3006                 case 0:
   3007                     if (bit < _bcm_tr3_cpu_cos_map_maxs[1]) {
   3008                         /* First bit in the overlayed range, must be IP */
   3009                         reason_type_mask = 0x3;
   3010                     } else {
   3011                         /* First bit in the common range, no restriction */
   3012                         reason_type_mask = 0;
   3013                     }
   3014                     reason_type_key = 0; /* IP overlay */
   3015                     break;
   3016                 case 1:
   3017                     reason_type_mask = 0x3;
   3018                     reason_type_key = 2; /* EP overlay */
   3019                     break;
   3020                 case 2:
   3021                     reason_type_mask = 0x3;
   3022                     reason_type_key = 3; /* NLF overlay */
   3023                     break;
   3024                 default:
   3025                     return BCM_E_INTERNAL;
   3026                 }
   3027             }
   3028         }
   3029 
   3030     /* check whether there are reasons unsupported or unmappped */
   3031     /* coverity [mixed_enums] */
   3032     for (ridx = bcmRxReasonInvalid; ridx < bcmRxReasonCount; ridx++) {
   3033         if (BCM_RX_REASON_GET(reasons_remain, ridx)) {
   3034             return BCM_E_PARAM;
   3035         }
   3036     }
   3037 
   3038     /* Now zero entry */
   3039     sal_memset (&entry, 0, sizeof(cpu_cos_map_entry_t));
   3040 
   3041     /* Program the key and mask */
   3042     for (word = 0; word < words; word++) {
   3043         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3044                             reason_fields[word], key[word]);   
   3045 
   3046         /* program the mask field */
   3047         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3048                             mask_fields[word], mask[word]);   
   3049     }
   3050 
   3051     /* Program the reasons type */ 
   3052     if (0 != reason_type_mask) {
   3053         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3054                             REASON_CODE_TYPE_MASKf, reason_type_mask);   
   3055         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3056                             REASON_CODE_TYPE_KEYf, reason_type_key);   
   3057     }
   3058 
   3059     /* Program the packet type */ 
   3060     if (packet_type_mask & (BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST |
   3061                          BCM_RX_COSQ_PACKET_TYPE_SWITCHED)) {
   3062         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3063                             SW_PKT_TYPE_MASKf, sw_pkt_type_mask);   
   3064         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3065                             SW_PKT_TYPE_KEYf, sw_pkt_type_key);   
   3066     }
   3067 
   3068     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_MIRROR) {
   3069         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3070                             MIRR_PKT_MASKf, 1);   
   3071         if (packet_type & BCM_RX_COSQ_PACKET_TYPE_MIRROR) {
   3072             soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3073                                 MIRR_PKT_KEYf, 1);   
   3074         }
   3075     }
   3076 
   3077     /* Handle priority when int_prio_mask != 0 */
   3078     if (int_prio_mask) {
   3079         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3080                             INT_PRI_KEYf, (int_prio & 0xf));   
   3081         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   3082                             INT_PRI_MASKf, (int_prio_mask & 0xf));   
   3083     }
   3084 
   3085     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, COSf, cosq);
   3086     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, VALIDf, 1);
   3087 
   3088     /* write to memory */
   3089     SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, 
   3090                                            index, &entry));
   3091 
   3092     return BCM_E_NONE;
   3093 }
   3094 
   3095 #endif /* BCM_TRIUMPH3_SUPPORT */
   3096 
   3097 #ifdef BCM_TRX_SUPPORT
   3098 /* Each device has 1 cos map key table and zero or more encoding tables */
   3099 STATIC int
   3100 _bcm_rx_reason_table_get(int unit,
   3101                          bcm_rx_reason_t **cpu_cos_map_key,
   3102                          int *key_table_len,
   3103                          bcm_rx_reason_t **cpu_opcode_encoding,
   3104                          int *encoding_table_len,
   3105                          int *encoding_table_count)
   3106 {
   3107 #ifdef BCM_TRIDENT3_SUPPORT
   3108     if (SOC_IS_TRIDENT3X(unit)) {
   3109 #ifdef BCM_HELIX5_SUPPORT
   3110         if (soc_feature(unit, soc_feature_hx5_oam_support)) {
   3111         /* OAM_SLOWPATH_OFFSET for Helix5 */
   3112             _bcm_trident3_cpu_cos_map_key[59] = bcmRxReasonOAMSlowpath;
   3113         }
   3114 #endif
   3115         *cpu_cos_map_key = _bcm_trident3_cpu_cos_map_key;
   3116         *key_table_len = sizeof(_bcm_trident3_cpu_cos_map_key) /
   3117             sizeof(_bcm_trident3_cpu_cos_map_key[0]);
   3118 
   3119         *encoding_table_len = 0;
   3120         *encoding_table_count = 0;
   3121 
   3122         return BCM_E_NONE;
   3123     }
   3124 #endif /* BCM_TRIDENT3_SUPPORT */
   3125 #ifdef BCM_TOMAHAWK3_SUPPORT
   3126     if (SOC_IS_TOMAHAWK3(unit)) {
   3127         *cpu_cos_map_key = _bcm_th3_cpu_cos_map_key;
   3128         *key_table_len = sizeof(_bcm_th3_cpu_cos_map_key) /
   3129             sizeof(_bcm_th3_cpu_cos_map_key[0]);
   3130 
   3131         *encoding_table_len = 0;
   3132         *encoding_table_count = 0;
   3133 
   3134         return BCM_E_NONE;
   3135     }
   3136 #endif /* BCM_TOMAHAWK3_SUPPORT */
   3137 
   3138 #ifdef BCM_TRIDENT_SUPPORT
   3139 #ifdef BCM_TRIDENT2_SUPPORT
   3140 #ifdef BCM_TRIDENT2PLUS_SUPPORT
   3141     if (SOC_IS_TD2P_TT2P(unit) || SOC_IS_APACHE(unit)) {
   3142         *cpu_cos_map_key = _bcm_trident2plus_cpu_cos_map_key;
   3143         *key_table_len = sizeof(_bcm_trident2plus_cpu_cos_map_key) /
   3144             sizeof(_bcm_trident2plus_cpu_cos_map_key[0]);
   3145 
   3146         *encoding_table_count = 3;
   3147 
   3148         cpu_opcode_encoding[0] = _bcm_trident2plus_niv_cpu_opcode_encoding;
   3149         encoding_table_len[0] = sizeof(_bcm_trident2plus_niv_cpu_opcode_encoding) /
   3150             sizeof(_bcm_trident2plus_niv_cpu_opcode_encoding[0]);
   3151 
   3152         cpu_opcode_encoding[1] = _bcm_trident2_trill_cpu_opcode_encoding;
   3153         encoding_table_len[1] = sizeof(_bcm_trident2_trill_cpu_opcode_encoding) /
   3154             sizeof(_bcm_trident2_trill_cpu_opcode_encoding[0]);
   3155 
   3156         cpu_opcode_encoding[2] = _bcm_trident2plus_nat_cpu_opcode_encoding;
   3157         encoding_table_len[2] = sizeof(_bcm_trident2plus_nat_cpu_opcode_encoding) /
   3158             sizeof(_bcm_trident2plus_nat_cpu_opcode_encoding[0]);
   3159 
   3160         return BCM_E_NONE;
   3161     } else
   3162 #endif /* BCM_TRIDENT2PLUS_SUPPORT */
   3163     if (SOC_IS_TD2_TT2(unit)) {
   3164 #ifdef BCM_TOMAHAWK_SUPPORT
   3165         if (SOC_IS_TOMAHAWKX(unit)) {
   3166             *cpu_cos_map_key = _bcm_tomahawk_cpu_cos_map_key;
   3167             *key_table_len = sizeof(_bcm_tomahawk_cpu_cos_map_key) /
   3168                 sizeof(_bcm_tomahawk_cpu_cos_map_key[0]);
   3169         } else
   3170 #endif /* BCM_TOMAHAWK_SUPPORT */
   3171         {
   3172             *cpu_cos_map_key = _bcm_trident2_cpu_cos_map_key;
   3173             *key_table_len = sizeof(_bcm_trident2_cpu_cos_map_key) /
   3174                 sizeof(_bcm_trident2_cpu_cos_map_key[0]);
   3175         }
   3176 
   3177         *encoding_table_count = 3;
   3178 
   3179         cpu_opcode_encoding[0] = _bcm_niv_cpu_opcode_encoding;
   3180         encoding_table_len[0] = sizeof(_bcm_niv_cpu_opcode_encoding) /
   3181             sizeof(_bcm_niv_cpu_opcode_encoding[0]);
   3182 
   3183         cpu_opcode_encoding[1] = _bcm_trident2_trill_cpu_opcode_encoding;
   3184         encoding_table_len[1] = sizeof(_bcm_trident2_trill_cpu_opcode_encoding) /
   3185             sizeof(_bcm_trident2_trill_cpu_opcode_encoding[0]);
   3186 
   3187         cpu_opcode_encoding[2] = _bcm_nat_cpu_opcode_encoding;
   3188         encoding_table_len[2] = sizeof(_bcm_nat_cpu_opcode_encoding) /
   3189             sizeof(_bcm_nat_cpu_opcode_encoding[0]);
   3190 
   3191         return BCM_E_NONE;
   3192     } else
   3193 #endif /* BCM_TRIDENT2_SUPPORT */
   3194     if (SOC_IS_TD_TT(unit)) {
   3195         *cpu_cos_map_key = _bcm_trident_cpu_cos_map_key;
   3196         *key_table_len = sizeof(_bcm_trident_cpu_cos_map_key) /
   3197             sizeof(_bcm_trident_cpu_cos_map_key[0]);
   3198 
   3199         *encoding_table_count = 2;
   3200 
   3201         cpu_opcode_encoding[0] = _bcm_niv_cpu_opcode_encoding;
   3202         encoding_table_len[0] = sizeof(_bcm_niv_cpu_opcode_encoding) /
   3203             sizeof(_bcm_niv_cpu_opcode_encoding[0]);
   3204 
   3205         cpu_opcode_encoding[1] = _bcm_trill_cpu_opcode_encoding;
   3206         encoding_table_len[1] = sizeof(_bcm_trill_cpu_opcode_encoding) /
   3207             sizeof(_bcm_trill_cpu_opcode_encoding[0]);
   3208 
   3209         return BCM_E_NONE;
   3210     }
   3211 
   3212 #endif /* BCM_TRIDENT_SUPPORT */
   3213 
   3214 #ifdef BCM_KATANA_SUPPORT
   3215     if (SOC_IS_KATANA(unit)) {
   3216         cpu_opcode_encoding[0] = _bcm_bfd_cpu_opcode_encoding;
   3217         encoding_table_len[0] = sizeof(_bcm_bfd_cpu_opcode_encoding) /
   3218             sizeof(_bcm_bfd_cpu_opcode_encoding[0]);
   3219         *encoding_table_count = 1;
   3220         *cpu_cos_map_key = _bcm_katana_cpu_cos_map_key;
   3221         *key_table_len = sizeof(_bcm_katana_cpu_cos_map_key) /
   3222             sizeof(_bcm_katana_cpu_cos_map_key[0]);
   3223         return BCM_E_NONE;
   3224     }
   3225 #endif /* BCM_KATANA_SUPPORT */
   3226 
   3227 #ifdef BCM_SABER2_SUPPORT
   3228     if (SOC_IS_SABER2(unit)) {
   3229         cpu_opcode_encoding[0] = _bcm_bfd_cpu_opcode_encoding;
   3230         encoding_table_len[0] = sizeof(_bcm_bfd_cpu_opcode_encoding) /
   3231             sizeof(_bcm_bfd_cpu_opcode_encoding[0]);
   3232         *encoding_table_count = 1;
   3233         *cpu_cos_map_key = _bcm_saber2_cpu_cos_map_key;
   3234         *key_table_len = sizeof(_bcm_saber2_cpu_cos_map_key) /
   3235             sizeof(_bcm_saber2_cpu_cos_map_key[0]);
   3236         return BCM_E_NONE;
   3237     }
   3238 #endif /* BCM_SABER2_SUPPORT */
   3239 
   3240 
   3241 #ifdef BCM_KATANA2_SUPPORT
   3242     if (SOC_IS_KATANA2(unit)) {
   3243         cpu_opcode_encoding[0] = _bcm_bfd_cpu_opcode_encoding;
   3244         encoding_table_len[0] = sizeof(_bcm_bfd_cpu_opcode_encoding) /
   3245             sizeof(_bcm_bfd_cpu_opcode_encoding[0]);
   3246         *encoding_table_count = 1;
   3247         *cpu_cos_map_key = _bcm_katana2_cpu_cos_map_key;
   3248         *key_table_len = sizeof(_bcm_katana2_cpu_cos_map_key) /
   3249             sizeof(_bcm_katana2_cpu_cos_map_key[0]);
   3250         return BCM_E_NONE;
   3251     }
   3252 #endif /* BCM_KATANA2_SUPPORT */
   3253 
   3254 
   3255 
   3256 #ifdef BCM_ENDURO_SUPPORT
   3257     if (SOC_IS_ENDURO(unit) || SOC_IS_HURRICANE(unit) ||
   3258         SOC_IS_HURRICANE2(unit)) {
   3259         *encoding_table_count = 0;
   3260         *cpu_cos_map_key = _bcm_enduro_cpu_cos_map_key;
   3261         *key_table_len = sizeof(_bcm_enduro_cpu_cos_map_key) /
   3262             sizeof(_bcm_enduro_cpu_cos_map_key[0]);
   3263         return BCM_E_NONE;
   3264     }
   3265 #endif /* BCM_ENDURO_SUPPORT */
   3266 
   3267 #ifdef BCM_GREYHOUND_SUPPORT
   3268     if (SOC_IS_GREYHOUND(unit) || SOC_IS_HURRICANE3(unit) ||
   3269         SOC_IS_GREYHOUND2(unit)) {
   3270         cpu_opcode_encoding[0] = _bcm_niv_cpu_opcode_encoding;
   3271         encoding_table_len[0] = sizeof(_bcm_niv_cpu_opcode_encoding) /
   3272             sizeof(_bcm_niv_cpu_opcode_encoding[0]);
   3273         *encoding_table_count = 1;
   3274 
   3275 #ifdef BCM_GREYHOUND2_SUPPORT
   3276         if (SOC_IS_GREYHOUND2(unit)) {
   3277             *cpu_cos_map_key = _bcm_greyhound2_cpu_cos_map_key;
   3278             *key_table_len = sizeof(_bcm_greyhound2_cpu_cos_map_key) /
   3279                 sizeof(_bcm_greyhound2_cpu_cos_map_key[0]);
   3280         } else
   3281 #endif /* BCM_GREYHOUND2_SUPPORT */
   3282         {
   3283         *cpu_cos_map_key = _bcm_greyhound_cpu_cos_map_key;
   3284         *key_table_len = sizeof(_bcm_greyhound_cpu_cos_map_key) /
   3285             sizeof(_bcm_greyhound_cpu_cos_map_key[0]);
   3286         }
   3287         return BCM_E_NONE;
   3288     }
   3289 #endif /* BCM_GREYHOUND_SUPPORT */
   3290 
   3291     *encoding_table_count = 0;
   3292     *cpu_cos_map_key = _bcm_trx_cpu_cos_map_key;
   3293     if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
   3294         SOC_IS_VALKYRIE2(unit)) {
   3295         *key_table_len = _bcm_triumph2_rx_cpu_cosmap_key_max;
   3296     } else if (SOC_IS_TR_VL(unit)) {
   3297         *key_table_len = _bcm_triumph_rx_cpu_cosmap_key_max;
   3298     } else if (SOC_IS_SC_CQ(unit)) {
   3299         *key_table_len = _bcm_scorpion_rx_cpu_cosmap_key_max;
   3300     } else {
   3301         return BCM_E_UNAVAIL;
   3302     }
   3303     return BCM_E_NONE;
   3304 }
   3305 #endif
   3306 
   3307 /*
   3308  * Function:
   3309  *      bcm_rx_cosq_mapping_reasons_get
   3310  * Purpose:
   3311  *      Get all supported reasons for CPU cosq mapping  
   3312  * Parameters:
   3313  *      unit - Unit reference
   3314  *      reasons - cpu cosq "reasons" mapping bitmap
   3315  * Returns:
   3316  *      BCM_E_XXX
   3317  */
   3318 int 
   3319 bcm_esw_rx_cosq_mapping_reasons_get(int unit, bcm_rx_reasons_t * reasons)
   3320 {
   3321 #ifdef BCM_TRX_SUPPORT
   3322     bcm_rx_reason_t *cpu_cos_map_key, *cpu_opcode_enc[3];
   3323     int key_table_len, enc_table_len[3], enc_count;
   3324     int key_idx, table_idx, enc_idx;
   3325 
   3326     if (reasons == NULL) {
   3327         return BCM_E_PARAM;
   3328     }
   3329 
   3330     BCM_RX_REASON_CLEAR_ALL(*reasons);
   3331 
   3332 #ifdef BCM_TRIUMPH3_SUPPORT
   3333     if (soc_feature(unit, soc_feature_rx_reason_overlay)) {
   3334         return _bcm_esw_rcmr_overlay_get(unit, reasons);
   3335     }
   3336 #endif /* BCM_TRIUMPH3_SUPPORT */
   3337 
   3338     if (SOC_IS_TRX(unit)) {
   3339         BCM_IF_ERROR_RETURN
   3340             (_bcm_rx_reason_table_get(unit, &cpu_cos_map_key, &key_table_len,
   3341                                       cpu_opcode_enc, enc_table_len,
   3342                                       &enc_count));
   3343 
   3344         for (key_idx = 0; key_idx < key_table_len; key_idx++) {
   3345             /* coverity [mixed_enums] */
   3346             if (cpu_cos_map_key[key_idx] != (bcm_rx_reason_t)bcmRxReasonInvalid) {
   3347                 BCM_RX_REASON_SET(*reasons, cpu_cos_map_key[key_idx]);
   3348             }
   3349         }
   3350         for (table_idx = 0; table_idx < enc_count; table_idx++) {
   3351             for (enc_idx = 0; enc_idx < enc_table_len[table_idx]; enc_idx++) {
   3352                 /* coverity [mixed_enums] */
   3353                 if (cpu_opcode_enc[table_idx][enc_idx] != (bcm_rx_reason_t)bcmRxReasonInvalid) {
   3354                     BCM_RX_REASON_SET(*reasons,
   3355                                       cpu_opcode_enc[table_idx][enc_idx]);
   3356                 }
   3357             }
   3358         }
   3359 
   3360         return BCM_E_NONE;
   3361     }
   3362 #endif
   3363 
   3364     return BCM_E_UNAVAIL;
   3365 }
   3366 
   3367 /*
   3368  * Function:
   3369  *      bcm_rx_reasons_get
   3370  * Purpose:
   3371  *      Get all supported reasons for rx packets
   3372  * Parameters:
   3373  *      unit - Unit reference
   3374  *      reasons - rx packet "reasons" bitmap
   3375  * Returns:
   3376  *      BCM_E_XXX
   3377  */
   3378 int 
   3379 bcm_esw_rx_reasons_get (int unit, bcm_rx_reasons_t *reasons)
   3380 {
   3381     int rv;
   3382 
   3383     rv = _bcm_common_rx_reasons_get(unit, reasons);
   3384 
   3385 #ifdef BCM_TRX_SUPPORT
   3386     if (SOC_IS_TRX(unit)) {
   3387         bcm_rx_reason_t *cpu_cos_map_key, *cpu_opcode_enc[3];
   3388         int key_table_len, enc_table_len[3], enc_count;
   3389         int table_idx, enc_idx;
   3390 
   3391         BCM_IF_ERROR_RETURN
   3392             (_bcm_rx_reason_table_get(unit, &cpu_cos_map_key, &key_table_len,
   3393                                       cpu_opcode_enc, enc_table_len,
   3394                                       &enc_count));
   3395         for (table_idx = 0; table_idx < enc_count; table_idx++) {
   3396             if (BCM_RX_REASON_GET(*reasons, cpu_opcode_enc[table_idx][0])) {
   3397                 for (enc_idx = 1; enc_idx < enc_table_len[table_idx];
   3398                      enc_idx++) {
   3399                     /* coverity [mixed_enums] */
   3400                     if (cpu_opcode_enc[table_idx][enc_idx] != 
   3401                         (bcm_rx_reason_t)bcmRxReasonInvalid) {
   3402                         BCM_RX_REASON_SET(*reasons,
   3403                                           cpu_opcode_enc[table_idx][enc_idx]);
   3404                     }
   3405                 }
   3406             }
   3407         }
   3408     }
   3409 #endif /* BCM_TRX_SUPPORT */
   3410 
   3411     return rv;
   3412 }
   3413 
   3414 static soc_reg_t _rx_redirect_reg[3][2] = {
   3415     { CMIC_PKT_REASONr, CMIC_PKT_REASON_HIr },
   3416     { CMIC_PKT_REASON_DIRECTr, CMIC_PKT_REASON_DIRECT_HIr },
   3417     { CMIC_PKT_REASON_MINIr, CMIC_PKT_REASON_MINI_HIr }
   3418 };
   3419 
   3420 #ifdef BCM_CMICM_SUPPORT
   3421 static soc_reg_t _cmicm_rx_redirect_reg[3][2] = {
   3422     {CMIC_PKT_REASON_0_TYPEr, CMIC_PKT_REASON_1_TYPEr},
   3423     {CMIC_PKT_REASON_DIRECT_0_TYPEr, CMIC_PKT_REASON_DIRECT_1_TYPEr},
   3424     {CMIC_PKT_REASON_MINI_0_TYPEr, CMIC_PKT_REASON_MINI_0_TYPEr}
   3425 };
   3426 #endif
   3427 
   3428 #ifdef BCM_CMICX_SUPPORT
   3429 static soc_reg_t _cmicx_rx_redirect_reg[3][2] = {
   3430     {CMIC_RPE_PKT_REASON_0_TYPEr, CMIC_RPE_PKT_REASON_1_TYPEr},
   3431     {CMIC_RPE_PKT_REASON_DIRECT_0_TYPEr, CMIC_RPE_PKT_REASON_DIRECT_1_TYPEr},
   3432     {CMIC_RPE_PKT_REASON_MINI_0_TYPEr, CMIC_RPE_PKT_REASON_MINI_0_TYPEr}
   3433 };
   3434 #endif
   3435 
   3436 int
   3437 bcm_esw_rx_redirect_reasons_set(int unit, bcm_rx_redirect_t mode, bcm_rx_reasons_t reasons)
   3438 {
   3439     uint32 ix, i, max_index = 32;
   3440     uint32 addr, rval, rval_hi = 0;
   3441     soc_rx_reason_t *map;
   3442     uint8 set = 0;
   3443     soc_reg_t cmic_reg;
   3444 
   3445     if (!SOC_UNIT_VALID(unit)) { 
   3446         return BCM_E_UNIT;
   3447     }
   3448     /* coverity [mixed_enums] */
   3449     if ((mode < 0) || (mode > (bcm_rx_redirect_t)_SHR_RX_REDIRECT_MAX)) {
   3450         return SOC_E_PARAM;
   3451     }
   3452     if ((map = (SOC_DCB_RX_REASON_MAPS(unit))[0]) == NULL) {
   3453         return SOC_E_INTERNAL;
   3454     }
   3455 
   3456 #ifdef BCM_CMICM_SUPPORT
   3457     if (soc_feature(unit, soc_feature_cmicm)) {
   3458         addr = soc_reg_addr(unit, _cmicm_rx_redirect_reg[mode][0], REG_PORT_ANY, 0);
   3459     } else
   3460 #endif
   3461 #ifdef BCM_CMICX_SUPPORT
   3462     if (soc_feature(unit, soc_feature_cmicx)) {
   3463         addr = soc_reg_addr(unit, _cmicx_rx_redirect_reg[mode][0], REG_PORT_ANY, 0);
   3464     } else
   3465 #endif
   3466     {
   3467         addr = soc_reg_addr(unit, _rx_redirect_reg[mode][0], REG_PORT_ANY, 0);
   3468     }
   3469     rval = soc_pci_read(unit, addr);
   3470     if (soc_feature(unit, soc_feature_dcb_reason_hi)) {
   3471         max_index = 64;
   3472 #ifdef BCM_CMICM_SUPPORT
   3473         if (soc_feature(unit, soc_feature_cmicm)) {
   3474             addr = soc_reg_addr(unit, _cmicm_rx_redirect_reg[mode][1], REG_PORT_ANY, 0);
   3475         } else
   3476 #endif
   3477 #ifdef BCM_CMICX_SUPPORT
   3478         if (soc_feature(unit, soc_feature_cmicx)) {
   3479             addr = soc_reg_addr(unit, _cmicx_rx_redirect_reg[mode][1], REG_PORT_ANY, 0);
   3480         } else
   3481 #endif
   3482         {
   3483             addr = soc_reg_addr(unit, _rx_redirect_reg[mode][1], REG_PORT_ANY, 0);
   3484         }
   3485         rval_hi = soc_pci_read(unit, addr);
   3486     }
   3487     
   3488     for (ix = 0; ix < max_index ; ix++) {
   3489         /* coverity [mixed_enums] */
   3490         if (map[ix] != (soc_rx_reason_t)socRxReasonInvalid && 
   3491                map[ix] != (soc_rx_reason_t)socRxReasonCount) {
   3492             if (BCM_RX_REASON_GET(reasons, (bcm_rx_reason_t)map[ix])) {
   3493                 set++;
   3494                 if (ix < 32) {
   3495                     rval |= (1 << ix);
   3496                 } else {
   3497                     rval_hi |= (1 << (ix-32));
   3498                 }
   3499             } else {
   3500                 set++;
   3501                 if (ix < 32) {
   3502                     rval &= ~(1 << ix);
   3503                 } else {
   3504                     rval_hi &= ~(1 << (ix-32));
   3505                 }
   3506             }
   3507         }
   3508     }
   3509     
   3510     if (set) {
   3511 #ifdef BCM_CMICM_SUPPORT
   3512         if (soc_feature(unit, soc_feature_cmicm)) {
   3513             cmic_reg = _cmicm_rx_redirect_reg[mode][0];
   3514         } else
   3515 #endif
   3516 #ifdef BCM_CMICX_SUPPORT
   3517         if (soc_feature(unit, soc_feature_cmicx)) {
   3518             cmic_reg = _cmicx_rx_redirect_reg[mode][0];
   3519         } else
   3520 #endif
   3521         {
   3522             cmic_reg = _rx_redirect_reg[mode][0];
   3523         }
   3524         for (i = 0; i < SOC_REG_NUMELS(unit, cmic_reg); i++) {
   3525              addr = soc_reg_addr(unit, cmic_reg, REG_PORT_ANY, i);
   3526              soc_pci_write(unit, addr, rval);
   3527         }
   3528         if (soc_feature(unit, soc_feature_dcb_reason_hi)) {
   3529 #ifdef BCM_CMICM_SUPPORT
   3530             if (soc_feature(unit, soc_feature_cmicm)) {
   3531                 cmic_reg = _cmicm_rx_redirect_reg[mode][1];
   3532             } else
   3533 #endif
   3534 #ifdef BCM_CMICX_SUPPORT
   3535             if (soc_feature(unit, soc_feature_cmicx)) {
   3536                 cmic_reg = _cmicx_rx_redirect_reg[mode][1];
   3537             } else
   3538 #endif
   3539             {
   3540                 cmic_reg = _rx_redirect_reg[mode][1];
   3541             }
   3542             for (i = 0; i < SOC_REG_NUMELS(unit, cmic_reg); i++) {
   3543                 addr = soc_reg_addr(unit, cmic_reg, REG_PORT_ANY, i);
   3544                 soc_pci_write(unit, addr, rval_hi);
   3545             }
   3546         }
   3547     }
   3548     return SOC_E_NONE;
   3549 }
   3550 
   3551 int
   3552 bcm_esw_rx_redirect_reasons_get(int unit, 
   3553                                 bcm_rx_redirect_t mode, 
   3554                                 bcm_rx_reasons_t *reasons)
   3555 {
   3556     uint32 ix, max_index = 32;
   3557     uint32 addr, rval;
   3558     uint32 rval_hi = 0;
   3559     soc_rx_reason_t *map;
   3560 
   3561     if (!SOC_UNIT_VALID(unit)) { 
   3562         return BCM_E_UNIT;
   3563     }
   3564     /* coverity [mixed_enums] */
   3565     if ((mode < 0) || (mode > (bcm_rx_redirect_t)_SHR_RX_REDIRECT_MAX)) {
   3566         return SOC_E_PARAM;
   3567     }
   3568     if ((map = (SOC_DCB_RX_REASON_MAPS(unit))[0]) == NULL) {
   3569         return SOC_E_INTERNAL;
   3570     }
   3571 
   3572 #ifdef BCM_CMICM_SUPPORT
   3573     if (soc_feature(unit, soc_feature_cmicm)) {
   3574         addr = soc_reg_addr(unit, _cmicm_rx_redirect_reg[mode][0], REG_PORT_ANY, 0);
   3575     } else
   3576 #endif
   3577 #ifdef BCM_CMICX_SUPPORT
   3578     if (soc_feature(unit, soc_feature_cmicx)) {
   3579         addr = soc_reg_addr(unit, _cmicx_rx_redirect_reg[mode][0], REG_PORT_ANY, 0);
   3580     } else
   3581 #endif
   3582     {
   3583         addr = soc_reg_addr(unit, _rx_redirect_reg[mode][0], REG_PORT_ANY, 0);
   3584     }
   3585     rval = soc_pci_read(unit, addr);
   3586     if (soc_feature(unit, soc_feature_dcb_reason_hi)) {
   3587         max_index = 64;
   3588 #ifdef BCM_CMICM_SUPPORT
   3589         if (soc_feature(unit, soc_feature_cmicm)) {
   3590             addr = soc_reg_addr(unit, _cmicm_rx_redirect_reg[mode][1], REG_PORT_ANY, 0);
   3591         } else
   3592 #endif
   3593 #ifdef BCM_CMICX_SUPPORT
   3594         if (soc_feature(unit, soc_feature_cmicx)) {
   3595             addr = soc_reg_addr(unit, _cmicx_rx_redirect_reg[mode][1], REG_PORT_ANY, 0);
   3596         } else
   3597 #endif
   3598         {
   3599             addr = soc_reg_addr(unit, _rx_redirect_reg[mode][1], REG_PORT_ANY, 0);
   3600         }
   3601         rval_hi = soc_pci_read(unit, addr);
   3602     }
   3603     BCM_RX_REASON_CLEAR_ALL(*reasons);
   3604     for (ix = 0; ix < max_index ; ix++) {
   3605         /* coverity [mixed_enums] */
   3606         if (map[ix] != (soc_rx_reason_t)socRxReasonInvalid && 
   3607                map[ix] != (soc_rx_reason_t)socRxReasonCount) {
   3608             if (ix < 32) {
   3609                 if (rval & (1 << ix)) {
   3610                     BCM_RX_REASON_SET(*reasons, (bcm_rx_reason_t)map[ix]);
   3611                 }
   3612             } else {
   3613                 if (rval_hi & (1 << (ix - 32))) {
   3614                     BCM_RX_REASON_SET(*reasons, (bcm_rx_reason_t)map[ix]);
   3615                 }
   3616             }
   3617         }
   3618     }
   3619     return SOC_E_NONE;
   3620 }
   3621 
   3622 #ifdef BCM_TRX_SUPPORT
   3623 extern int _bcm_esw_cpu_cosq_mapping_default_set(int unit, int numq);
   3624 extern int _bcm_esw_cosq_config_property_get(int unit);
   3625 /* Delete an entry of CPU_COS_MAPm */
   3626 int
   3627 _bcm_trx_rx_cosq_mapping_delete(int unit, int index)
   3628 {
   3629     cpu_cos_map_entry_t entry; 
   3630 
   3631     if (index < soc_mem_index_min(unit, CPU_COS_MAPm) ||
   3632         index > soc_mem_index_max(unit, CPU_COS_MAPm)) {
   3633         return BCM_E_PARAM;
   3634     }
   3635 
   3636 #if defined(BCM_TOMAHAWK_SUPPORT) || defined(BCM_KATANA_SUPPORT)
   3637     if (SOC_IS_TOMAHAWKX(unit) || SOC_IS_TRIDENT3X(unit) || SOC_IS_KATANAX(unit)) {
   3638         int rv;
   3639         bcm_rx_reasons_t reasons;
   3640         bcm_rx_reasons_t reasons_mask;
   3641         uint8 prio;
   3642         uint8 prio_mask;
   3643         uint32 packet_type;
   3644         uint32 packet_type_mask;
   3645         bcm_cos_queue_t cosq;
   3646         rv = bcm_esw_rx_cosq_mapping_get(
   3647             unit, index, &reasons, &reasons_mask, &prio,
   3648             &prio_mask,&packet_type, &packet_type_mask, &cosq);
   3649 
   3650         if (rv == BCM_E_NONE) {
   3651             if (!SOC_IS_KATANAX(unit)) {
   3652                 if (BCM_RX_REASON_GET(reasons, bcmRxReasonSampleDest)) {
   3653                     BCM_IF_ERROR_RETURN(WRITE_EGR_SFLOW_CPU_COS_CONFIGr(unit, 0));
   3654                 }
   3655 
   3656                 if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_MIRROR) {
   3657                     BCM_IF_ERROR_RETURN(WRITE_MIRROR_CPU_COS_CONFIGr(unit, 0));
   3658                 }
   3659             } else {
   3660                 if (BCM_RX_REASON_GET(reasons, bcmRxReasonBfd)) {
   3661                     RX_UNIT_REASONS_BFD_CLEAR(unit);
   3662                 }
   3663                 if (BCM_RX_REASON_GET(reasons, bcmRxReasonMplsCtrlWordError) ||
   3664                     BCM_RX_REASON_GET(reasons, bcmRxReasonMplsUnknownAch)) {
   3665                     RX_UNIT_REASONS_MPLS_BFD_CLEAR(unit);
   3666                 }
   3667             }
   3668         }
   3669     }
   3670 #endif
   3671 
   3672     /* Now zero entry */
   3673     sal_memset (&entry, 0, sizeof(cpu_cos_map_entry_t));
   3674 
   3675     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, VALIDf, 0);
   3676 
   3677     /* write to memory */
   3678     SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, 
   3679                             index, &entry));
   3680 
   3681     return BCM_E_NONE;
   3682 }
   3683 
   3684 
   3685 /* Delete all entry of CPU_COS_MAPm */
   3686 int
   3687 _bcm_trx_rx_cosq_mapping_init(int unit)
   3688 {
   3689     cpu_cos_map_entry_t entry; 
   3690     int index;
   3691     int numq = 0;
   3692 
   3693     /*one by one,space instead of time if we use soc_mem_write_range*/
   3694     for (index = soc_mem_index_min(unit, CPU_COS_MAPm);
   3695          index <= soc_mem_index_max(unit, CPU_COS_MAPm);index++){
   3696         /* Now zero entry */
   3697         sal_memset (&entry, 0, sizeof(cpu_cos_map_entry_t));
   3698 
   3699         /* write to memory */
   3700         SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, 
   3701                                 index, &entry));
   3702     }
   3703 
   3704     numq = _bcm_esw_cosq_config_property_get(unit);
   3705     
   3706     /* Map internal priority levels to CPU CoS queues */
   3707     
   3708     BCM_IF_ERROR_RETURN(_bcm_esw_cpu_cosq_mapping_default_set(unit, numq));
   3709 #ifdef BCM_KATANA_SUPPORT
   3710     if (SOC_IS_KATANAX(unit)) {
   3711         RX_UNIT_REASONS_BFD_CLEAR(unit);
   3712         RX_UNIT_REASONS_MPLS_BFD_CLEAR(unit);
   3713     }
   3714 #endif /* BCM_KATANA_SUPPORT */
   3715 
   3716     return BCM_E_NONE;
   3717 }
   3718 
   3719 /* Get the rx cosq mapping */
   3720 int
   3721 _bcm_trx_rx_cosq_mapping_get(int unit, int index,
   3722                             bcm_rx_reasons_t *reasons, 
   3723                             bcm_rx_reasons_t *reasons_mask,
   3724                             uint8 *prio, uint8 *prio_mask,
   3725                             uint32 *packet_type, uint32 * packet_type_mask,
   3726                             bcm_cos_queue_t *cosq, uint32 *flags)
   3727 {
   3728     bcm_rx_reason_t *cpu_cos_map_key, *cpu_opcode_enc[6] = {0};
   3729     int key_table_len, enc_table_len[6] = {0}, enc_count;
   3730     int word_idx, bit_idx, key_idx, table_idx, word_count, bit_count, idx;
   3731     uint32 mask[6] = {0}, key[6] = {0}, enc_mask[6] = {0};
   3732     uint32 enc_key[6] = {0}, field_size[6] = {0}, bit_key[6] = {0};
   3733     cpu_cos_map_entry_t entry; 
   3734     uint32 sw_pkt_type_mask, sw_pkt_type_key;
   3735     soc_field_t field = -1;
   3736     uint32 bit_skip = 0;
   3737 #ifdef BCM_KATANA_SUPPORT
   3738     int rx_reasons_bfd_get = 0, rx_reasons_mpls_bfd_get = 0;
   3739 #endif
   3740     BCM_IF_ERROR_RETURN
   3741         (_bcm_rx_reason_table_get(unit, &cpu_cos_map_key, &key_table_len,
   3742                                   cpu_opcode_enc, enc_table_len, &enc_count));
   3743 
   3744     /* Verify the index */
   3745     if (index < soc_mem_index_min(unit, CPU_COS_MAPm) ||
   3746         index > soc_mem_index_max(unit, CPU_COS_MAPm)) {
   3747         return BCM_E_PARAM;
   3748     }
   3749 
   3750     /* NULL pointer check */
   3751     if (reasons == NULL  || reasons_mask == NULL  || 
   3752         prio == NULL || prio_mask == NULL || 
   3753         packet_type == NULL || packet_type_mask == NULL || 
   3754         cosq == NULL) {
   3755         return BCM_E_PARAM;
   3756     }
   3757  
   3758     /* Read the entry */
   3759     SOC_IF_ERROR_RETURN(READ_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, index, &entry));
   3760 
   3761     /* Return BCM_E_NOT_FOUND if invalid */
   3762     if (soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, VALIDf) == 0) {
   3763         return (BCM_E_NOT_FOUND);
   3764     }        
   3765 
   3766     sal_memset(reasons, 0, sizeof(bcm_rx_reasons_t));
   3767     sal_memset(reasons_mask, 0, sizeof(bcm_rx_reasons_t));
   3768 
   3769     *cosq = (bcm_cos_queue_t)
   3770               soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, COSf);
   3771     
   3772     sw_pkt_type_mask = soc_mem_field32_get(unit, CPU_COS_MAPm, 
   3773                                            &entry, SW_PKT_TYPE_MASKf);
   3774     sw_pkt_type_key  = soc_mem_field32_get(unit, CPU_COS_MAPm, 
   3775                                            &entry, SW_PKT_TYPE_KEYf);
   3776 
   3777     if (sw_pkt_type_mask == 0 && sw_pkt_type_key == 0) {
   3778         /* all packets matched */
   3779         *packet_type_mask = 0;
   3780         *packet_type = 0;
   3781     } else if (sw_pkt_type_mask == 2 && sw_pkt_type_key == 0) {
   3782         /* Only non-switched packets */
   3783         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   3784         *packet_type = 0;
   3785     } else if (sw_pkt_type_mask == 2 && sw_pkt_type_key == 2) {
   3786         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   3787         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   3788     } else if (sw_pkt_type_mask == 3 && sw_pkt_type_key == 2) {
   3789         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED | 
   3790                              BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   3791         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   3792     } else if (sw_pkt_type_mask == 3 && sw_pkt_type_key == 3) {
   3793         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED |
   3794                              BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   3795         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED |
   3796                         BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   3797     }
   3798  
   3799     if (soc_mem_field_valid(unit, CPU_COS_MAPm, RESERVED_MIRR_PKT_MASKf)) {
   3800         field = RESERVED_MIRR_PKT_MASKf;
   3801     } else {
   3802         field = MIRR_PKT_MASKf;
   3803     }
   3804 
   3805     if (soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, field)) {
   3806         *packet_type_mask |= BCM_RX_COSQ_PACKET_TYPE_MIRROR;
   3807     }
   3808 
   3809     if (soc_mem_field_valid(unit, CPU_COS_MAPm, RESERVED_MIRR_PKT_KEYf)) {
   3810         field = RESERVED_MIRR_PKT_KEYf;
   3811     } else {
   3812         field = MIRR_PKT_KEYf;
   3813     }
   3814 
   3815     if (soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, field)) {
   3816         *packet_type |= BCM_RX_COSQ_PACKET_TYPE_MIRROR;
   3817     }
   3818 #ifdef BCM_TRIDENT2_SUPPORT    
   3819     if (soc_mem_field_valid(unit, CPU_COS_MAPm, TRUNCATE_CPU_COPYf) && 
   3820         flags != NULL) {
   3821         *flags = soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, TRUNCATE_CPU_COPYf) ? 
   3822                  BCM_RX_COPYTOCPU_TRUNCATE : 0;
   3823     }
   3824 #endif
   3825 
   3826     *prio_mask = 
   3827         soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, INT_PRI_MASKf);
   3828     *prio = 
   3829         soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, INT_PRI_KEYf);
   3830 
   3831 #if defined BCM_TRIDENT3_SUPPORT
   3832     if (SOC_IS_TRIDENT3X(unit)) {
   3833         int length = 0;
   3834         word_count = 0;
   3835 
   3836         length = soc_mem_field_length(unit, CPU_COS_MAPm, KEYf);
   3837         while (length > 32) {
   3838             field_size[word_count] = 32;
   3839             word_count++;
   3840             length -= 32;
   3841         }
   3842         field_size[word_count] = length;
   3843         word_count++;
   3844 
   3845         soc_mem_field_get(unit, CPU_COS_MAPm, (uint32 *)&entry, MASKf,&mask[0]);
   3846         soc_mem_field_get(unit, CPU_COS_MAPm, (uint32 *)&entry, KEYf, &key[0]);
   3847         /* 4bits INT_PRI + 1bit RESERVED_MIRR_PKT + 2bits SW_PKT_TYPE */
   3848         bit_skip = 0x7;
   3849     } else
   3850 #endif
   3851     {
   3852     mask[0] =
   3853         soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, REASONS_MASK_LOWf);
   3854     key[0] =
   3855         soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, REASONS_KEY_LOWf);
   3856     field_size[0] =
   3857         soc_mem_field_length(unit, CPU_COS_MAPm, REASONS_KEY_LOWf);
   3858     word_count = 1;
   3859     if (soc_mem_field_valid(unit, CPU_COS_MAPm, REASONS_MASK_MIDf)) {
   3860         mask[word_count] =
   3861             soc_mem_field32_get(unit, CPU_COS_MAPm,
   3862                                 &entry, REASONS_MASK_MIDf);
   3863         key[word_count] =
   3864             soc_mem_field32_get(unit, CPU_COS_MAPm,
   3865                                 &entry, REASONS_KEY_MIDf);
   3866         field_size[word_count] =
   3867             soc_mem_field_length(unit, CPU_COS_MAPm, REASONS_KEY_MIDf);
   3868         word_count++;
   3869     }
   3870     mask[word_count] =
   3871         soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, REASONS_MASK_HIGHf);
   3872     key[word_count] =
   3873         soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, REASONS_KEY_HIGHf);
   3874     field_size[word_count] =
   3875         soc_mem_field_length(unit, CPU_COS_MAPm, REASONS_KEY_HIGHf);
   3876     word_count++;
   3877     }
   3878 
   3879     sal_memset(enc_mask, 0, sizeof(enc_mask));
   3880     sal_memset(enc_key, 0, sizeof(enc_key));
   3881     sal_memset(bit_key, 0, sizeof(bit_key));
   3882     for (word_idx = 0; word_idx < word_count; word_idx++) {
   3883         bit_count = field_size[word_idx];
   3884 #if defined BCM_TRIDENT3_SUPPORT
   3885         if (SOC_IS_TRIDENT3X(unit)) {
   3886             bit_idx = (word_idx == 0 ? bit_skip:0);
   3887         } else
   3888 #endif
   3889         {
   3890             bit_idx = 0;
   3891         }
   3892         for (; bit_idx < bit_count; bit_idx++) {
   3893             uint32 maskbitset;
   3894             uint32 keybitset;
   3895 
   3896             maskbitset = mask[word_idx] & (1 << bit_idx);
   3897             keybitset = key[word_idx] & (1 << bit_idx);
   3898             key_idx = word_idx * 32 + bit_idx;
   3899             key_idx -= bit_skip;
   3900             if (key_idx >= key_table_len) {
   3901                 break;
   3902             }
   3903 
   3904            for (table_idx = 0; table_idx < enc_count; table_idx++) {
   3905                if (cpu_cos_map_key[key_idx] == cpu_opcode_enc[table_idx][0]) {
   3906                        if (maskbitset) { /* should always be set */
   3907                        enc_mask[table_idx] |= (1 << bit_key[table_idx]);
   3908                        }
   3909                        if (keybitset) {
   3910                        enc_key[table_idx] |= (1 << bit_key[table_idx]);
   3911                    }
   3912                    bit_key[table_idx]++;
   3913                }
   3914            }
   3915            if (maskbitset) {
   3916                BCM_RX_REASON_SET(*reasons_mask, cpu_cos_map_key[key_idx]);
   3917            }
   3918            if (keybitset) {
   3919                BCM_RX_REASON_SET(*reasons, cpu_cos_map_key[key_idx]);
   3920            }
   3921        }
   3922     }
   3923 
   3924     for (table_idx = 0; table_idx < enc_count; table_idx++) {
   3925         idx = enc_key[table_idx];
   3926         if (idx > 0) {
   3927                 BCM_RX_REASON_SET(*reasons, cpu_opcode_enc[table_idx][idx]);
   3928             }
   3929         }
   3930 #ifdef BCM_KATANA_SUPPORT
   3931     if (SOC_IS_KATANAX(unit)) {
   3932         uint32 bfdval = 0;
   3933         bfdval = (key[1] & 0x3fffffff) >> 28;
   3934         BCM_RX_REASON_CLEAR(*reasons, bcmRxReasonBfd);
   3935         BCM_RX_REASON_CLEAR(*reasons, bcmRxReasonBfdUnknownVersion);
   3936         BCM_RX_REASON_CLEAR(*reasons_mask, bcmRxReasonBfd);
   3937         BCM_RX_REASON_CLEAR(*reasons_mask, bcmRxReasonBfdUnknownVersion);
   3938         RX_UNIT_REASONS_MPLS_BFD_GET(unit, rx_reasons_mpls_bfd_get);
   3939         RX_UNIT_REASONS_BFD_GET(unit, rx_reasons_bfd_get);
   3940 
   3941         if (bfdval == 0x1) {
   3942             if (rx_reasons_bfd_get) {
   3943                 BCM_RX_REASON_SET(*reasons, bcmRxReasonBfd);
   3944                 BCM_RX_REASON_SET(*reasons, bcmRxReasonBfdUnknownVersion);
   3945                 BCM_RX_REASON_SET(*reasons_mask, bcmRxReasonBfd);
   3946                 BCM_RX_REASON_SET(*reasons_mask, bcmRxReasonBfdUnknownVersion);
   3947             }
   3948             if (rx_reasons_mpls_bfd_get) {
   3949                 BCM_RX_REASON_SET(*reasons, bcmRxReasonMplsUnknownAch);
   3950                 BCM_RX_REASON_SET(*reasons_mask, bcmRxReasonMplsUnknownAch);
   3951             }
   3952         } else if(bfdval == 0x2) {
   3953            BCM_RX_REASON_SET(*reasons, bcmRxReasonBfd);
   3954            BCM_RX_REASON_SET(*reasons, bcmRxReasonBfdInvalidVersion);
   3955            BCM_RX_REASON_SET(*reasons_mask, bcmRxReasonBfd);
   3956            BCM_RX_REASON_SET(*reasons_mask, bcmRxReasonBfdInvalidVersion);
   3957         } else if (bfdval == 0x3) {
   3958             if (rx_reasons_bfd_get) {
   3959                 BCM_RX_REASON_SET(*reasons, bcmRxReasonBfd);
   3960                 BCM_RX_REASON_SET(*reasons, bcmRxReasonBfdInvalidPacket);
   3961                 BCM_RX_REASON_SET(*reasons_mask, bcmRxReasonBfd);
   3962                 BCM_RX_REASON_SET(*reasons_mask, bcmRxReasonBfdInvalidPacket);
   3963             }
   3964             if (rx_reasons_mpls_bfd_get) {
   3965                 BCM_RX_REASON_SET(*reasons, bcmRxReasonMplsCtrlWordError);
   3966                 BCM_RX_REASON_SET(*reasons_mask, bcmRxReasonMplsCtrlWordError);
   3967             }
   3968         }
   3969     }
   3970 #endif
   3971 
   3972     return BCM_E_NONE;
   3973 }
   3974 
   3975 /* Set the rx cosq mapping */
   3976 int
   3977 _bcm_trx_rx_cosq_mapping_set(int unit, int index,
   3978                             bcm_rx_reasons_t reasons, bcm_rx_reasons_t
   3979                             reasons_mask,
   3980                             uint8 int_prio, uint8 int_prio_mask,
   3981                             uint32 packet_type, uint32 packet_type_mask,
   3982                             bcm_cos_queue_t cosq, uint32 flags)
   3983 {
   3984     bcm_rx_reason_t *cpu_cos_map_key, *cpu_opcode_enc[6] = {0};
   3985     int key_table_len, enc_table_len[3], enc_count;
   3986     int word_idx, bit_idx, key_idx, table_idx, enc_idx, word_count;
   3987     uint32 mask[6] = {0}, key[6] = {0}, enc_key, field_size[6] = {0};
   3988     bcm_rx_reason_t  reason_enum, enc_enum;
   3989     bcm_rx_reasons_t reasons_remain;
   3990     cpu_cos_map_entry_t entry; 
   3991     uint8 sw_pkt_type_key = 0;
   3992     uint8 sw_pkt_type_mask = 0;
   3993     soc_field_t field = -1;
   3994     uint32 bit_skip = 0;
   3995 #ifdef BCM_KATANA_SUPPORT
   3996     int rx_reasons_bfd_set = 0, rx_reasons_mpls_bfd_set = 0;
   3997 #endif
   3998 
   3999     BCM_IF_ERROR_RETURN
   4000         (_bcm_rx_reason_table_get(unit, &cpu_cos_map_key, &key_table_len,
   4001                                   cpu_opcode_enc, enc_table_len, &enc_count));
   4002 
   4003     /* Verify COSQ */
   4004     if (SOC_IS_TD_TT(unit)) {
   4005 #ifdef BCM_TRIDENT_SUPPORT
   4006         if (SOC_IS_TD2_TT2(unit)) { 
   4007             /* TD2 */
   4008             if (cosq >= _bcm_trident2_rx_cpu_max_cosq) {
   4009                 return BCM_E_PARAM;
   4010             }
   4011         } else { 
   4012             /* TD */
   4013             if (cosq >= _bcm_triumph_rx_cpu_max_cosq) {
   4014                 return BCM_E_PARAM;
   4015             }
   4016         }
   4017 #endif /* BCM_TRIDENT_SUPPORT */
   4018     } else if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) ||
   4019                SOC_IS_VALKYRIE2(unit)) {
   4020         if (cosq >= _bcm_triumph_rx_cpu_max_cosq) {
   4021             return BCM_E_PARAM;
   4022         }
   4023 #ifdef BCM_KATANA_SUPPORT
   4024     } else if (SOC_IS_KATANAX(unit)) {
   4025         if (SOC_IS_KATANA2(unit)) {
   4026             /* KATANA2 */
   4027             if (cosq >= _bcm_katana2_rx_cpu_max_cosq) {
   4028                 return BCM_E_PARAM;
   4029             }
   4030         } else {
   4031             /* KATANA */
   4032             if (cosq >= _bcm_triumph_rx_cpu_max_cosq) {
   4033                 return BCM_E_PARAM;
   4034             }
   4035         }
   4036 #endif /* BCM_KATANA_SUPPORT */
   4037 #ifdef BCM_ENDURO_SUPPORT
   4038     } else if (SOC_IS_ENDURO(unit) || SOC_IS_HURRICANEX(unit) || \
   4039                 SOC_IS_GREYHOUND(unit) || SOC_IS_GREYHOUND2(unit)) {
   4040 #if defined(BCM_HURRICANE_SUPPORT)
   4041         if (SOC_IS_HURRICANEX(unit) || SOC_IS_GREYHOUND(unit) ||
   4042             SOC_IS_GREYHOUND2(unit)) {
   4043             if (cosq >= _bcm_hurricane_rx_cpu_max_cosq) {
   4044                 return BCM_E_PARAM;
   4045             }            
   4046         } else
   4047 #endif /* BCM_HURRICANE_SUPPORT */
   4048         if (cosq >= _bcm_triumph_rx_cpu_max_cosq) {
   4049             return BCM_E_PARAM;
   4050         }
   4051 #endif /* BCM_ENDURO_SUPPORT */
   4052     } else if (SOC_IS_TR_VL(unit)) {
   4053         if (cosq >= _bcm_triumph_rx_cpu_max_cosq) {
   4054             return BCM_E_PARAM;
   4055         }
   4056     } else if (SOC_IS_SC_CQ(unit)) {
   4057         if (cosq >= _bcm_scorpion_rx_cpu_max_cosq) {
   4058             return BCM_E_PARAM;
   4059         }
   4060     } else {
   4061         return BCM_E_UNAVAIL;
   4062     }
   4063 
   4064     /* Verify the index */
   4065     if (index < soc_mem_index_min(unit, CPU_COS_MAPm) ||
   4066         index > soc_mem_index_max(unit, CPU_COS_MAPm)) {
   4067         return BCM_E_PARAM;
   4068     }
   4069 
   4070     /* Verify the packet type */
   4071 
   4072     if (packet_type & BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST) {
   4073         sw_pkt_type_key |= 1;
   4074     }
   4075     if (packet_type & BCM_RX_COSQ_PACKET_TYPE_SWITCHED) {
   4076         sw_pkt_type_key |= 2;
   4077     }
   4078     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST) {
   4079         sw_pkt_type_mask |= 1;
   4080     }
   4081     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_SWITCHED) {
   4082         sw_pkt_type_mask |= 2;
   4083     }
   4084     sw_pkt_type_key &= sw_pkt_type_mask;
   4085 
   4086     if ((sw_pkt_type_mask == 0x1) || 
   4087         ((sw_pkt_type_mask != 0) && (sw_pkt_type_key == 0x1))) { 
   4088         /* Hw doesn't support these cases */
   4089         return BCM_E_PARAM;
   4090     }
   4091 
   4092 #ifdef BCM_KATANA_SUPPORT
   4093     if (SOC_IS_KATANAX(unit)) {
   4094         if (BCM_RX_REASON_GET(reasons, bcmRxReasonBfd)) {
   4095             rx_reasons_bfd_set = 1;
   4096         }
   4097         if (BCM_RX_REASON_GET(reasons, bcmRxReasonMplsCtrlWordError)){
   4098             BCM_RX_REASON_CLEAR(reasons, bcmRxReasonMplsCtrlWordError);
   4099             BCM_RX_REASON_CLEAR(reasons_mask, bcmRxReasonMplsCtrlWordError);
   4100             BCM_RX_REASON_SET(reasons, bcmRxReasonBfd);
   4101             BCM_RX_REASON_SET(reasons, bcmRxReasonBfdInvalidPacket);
   4102             BCM_RX_REASON_SET(reasons_mask, bcmRxReasonBfd);
   4103             BCM_RX_REASON_SET(reasons_mask, bcmRxReasonBfdInvalidPacket);
   4104             rx_reasons_mpls_bfd_set = 1;
   4105         }
   4106         if (BCM_RX_REASON_GET(reasons, bcmRxReasonMplsUnknownAch)){
   4107             BCM_RX_REASON_CLEAR(reasons, bcmRxReasonMplsUnknownAch);
   4108             BCM_RX_REASON_CLEAR(reasons_mask, bcmRxReasonMplsUnknownAch);
   4109             BCM_RX_REASON_SET(reasons, bcmRxReasonBfd);
   4110             BCM_RX_REASON_SET(reasons, bcmRxReasonBfdUnknownVersion);
   4111             BCM_RX_REASON_SET(reasons_mask, bcmRxReasonBfd);
   4112             BCM_RX_REASON_SET(reasons_mask, bcmRxReasonBfdUnknownVersion);
   4113             rx_reasons_mpls_bfd_set = 1;
   4114         }
   4115        if (BCM_RX_REASON_GET(reasons, bcmRxReasonBfdLookupFailure)) {
   4116            BCM_RX_REASON_CLEAR(reasons, bcmRxReasonBfdLookupFailure);
   4117            BCM_RX_REASON_SET(reasons, bcmRxReasonBfdInvalidVersion);
   4118        }
   4119        if (BCM_RX_REASON_GET(reasons_mask, bcmRxReasonBfdLookupFailure)) {
   4120            BCM_RX_REASON_CLEAR(reasons_mask, bcmRxReasonBfdLookupFailure);
   4121            BCM_RX_REASON_SET(reasons_mask, bcmRxReasonBfdInvalidVersion);
   4122        }
   4123 
   4124        if (BCM_RX_REASON_GET(reasons, bcmRxReasonBfd) &&
   4125                !(BCM_RX_REASON_GET(reasons, bcmRxReasonBfdUnknownVersion) ||
   4126                    BCM_RX_REASON_GET(reasons, bcmRxReasonBfdInvalidVersion) ||
   4127                    BCM_RX_REASON_GET(reasons, bcmRxReasonBfdInvalidPacket))) {
   4128            return BCM_E_PARAM;
   4129        }
   4130     }
   4131 
   4132 #endif /* BCM_KATANA_SUPPORT */
   4133 #if defined BCM_TRIDENT3_SUPPORT
   4134 if (SOC_IS_TRIDENT3X(unit)) {
   4135         int length = 0;
   4136         word_count = 0;
   4137         length = soc_mem_field_length(unit, CPU_COS_MAPm, KEYf);
   4138         while (length > 32) {
   4139             field_size[word_count] = 32;
   4140             word_count++;
   4141             length -= 32;
   4142         }
   4143         field_size[word_count] = length;
   4144         word_count++;
   4145 
   4146         /* 4bits INT_PRI + 1bit RESERVED_MIRR_PKT + 2bits SW_PKT_TYPE */
   4147         bit_skip = 0x7;
   4148     } else
   4149 #endif
   4150     {
   4151     field_size[0] =
   4152         soc_mem_field_length(unit, CPU_COS_MAPm, REASONS_KEY_LOWf);
   4153     word_count = 1;
   4154     if (soc_mem_field_valid(unit, CPU_COS_MAPm, REASONS_MASK_MIDf)) {
   4155         field_size[word_count] =
   4156             soc_mem_field_length(unit, CPU_COS_MAPm, REASONS_KEY_MIDf);
   4157         word_count++;
   4158     }
   4159     field_size[word_count] =
   4160         soc_mem_field_length(unit, CPU_COS_MAPm, REASONS_KEY_HIGHf);
   4161     word_count++;
   4162     }
   4163     reasons_remain = reasons_mask;
   4164     enc_enum = -1;
   4165     enc_key = 0;
   4166     word_idx = 0;
   4167     bit_idx = bit_skip;
   4168     sal_memset(mask, 0, sizeof(mask));
   4169     sal_memset(key, 0, sizeof(key));
   4170     for (key_idx = 0; key_idx < key_table_len; key_idx++, bit_idx++) {
   4171         if (bit_idx == field_size[word_idx]) {
   4172             bit_idx = 0;
   4173             word_idx++;
   4174             if (word_idx == word_count) {
   4175                 /* Trap implementation error */
   4176                 return BCM_E_INTERNAL;
   4177             }
   4178         }
   4179  
   4180         reason_enum = cpu_cos_map_key[key_idx];
   4181         if (reason_enum == enc_enum) { /* following bit of encoding */
   4182             mask[word_idx] |= 1 << bit_idx;
   4183             key[word_idx] |= (enc_key & 1) << bit_idx;
   4184             enc_key >>= 1;
   4185             continue;
   4186         }
   4187 
   4188         /* Find reason being set */
   4189         if (!BCM_RX_REASON_GET(reasons_mask, reason_enum)) {
   4190             continue;
   4191         }
   4192         BCM_RX_REASON_CLEAR(reasons_remain, reason_enum);
   4193 
   4194         for (table_idx = 0; table_idx < enc_count; table_idx++) {
   4195             if (reason_enum != cpu_opcode_enc[table_idx][0]) {
   4196                 continue;
   4197             }
   4198 
   4199             enc_enum = reason_enum;
   4200             for (enc_idx = 1; enc_idx < enc_table_len[table_idx]; enc_idx++) {
   4201                 reason_enum = cpu_opcode_enc[table_idx][enc_idx];
   4202                 if (!BCM_RX_REASON_GET(reasons, reason_enum)) {
   4203                     BCM_RX_REASON_CLEAR(reasons_remain, reason_enum);
   4204                     continue;
   4205                 } else if (enc_key != 0) { /* multiple reasons supplied */
   4206                     return BCM_E_PARAM;
   4207                 }
   4208                 BCM_RX_REASON_CLEAR(reasons_remain, reason_enum);
   4209                 enc_key = enc_idx;
   4210             }
   4211             mask[word_idx] |= 1 << bit_idx;
   4212             key[word_idx] |= (enc_key & 1) << bit_idx;
   4213             enc_key >>= 1;
   4214             break;
   4215         }
   4216         if (table_idx == enc_count) {
   4217             mask[word_idx] |= 1 << bit_idx;
   4218             if (BCM_RX_REASON_GET(reasons, reason_enum)) {
   4219                 key[word_idx] |= 1 << bit_idx;
   4220             }
   4221         }
   4222     }
   4223 
   4224     /* check whether there are reasons unsupported */
   4225     if (!BCM_RX_REASON_IS_NULL(reasons_remain)) {
   4226         return BCM_E_PARAM;
   4227     }
   4228 
   4229 #ifdef BCM_KATANA_SUPPORT
   4230     if (SOC_IS_KATANAX(unit)) {
   4231         uint32 bfdval = 0, bfdmask = 0, bfdkey = 0;
   4232         if (BCM_RX_REASON_GET(reasons, bcmRxReasonBfd)) {
   4233             if (BCM_RX_REASON_GET(reasons, bcmRxReasonBfdUnknownVersion)) {
   4234                 bfdval |= 0x1;
   4235             } else if (BCM_RX_REASON_GET(reasons, bcmRxReasonBfdInvalidVersion)) {
   4236                 bfdval |= 0x2;
   4237             } else if (BCM_RX_REASON_GET(reasons, bcmRxReasonBfdInvalidPacket)) {
   4238                 bfdval |= 0x3;
   4239             }
   4240             if (bfdval) {
   4241                 bfdkey = key[1];
   4242                 bfdmask = mask[1];
   4243                 SHR_BITCLR(&bfdkey, 28);
   4244                 SHR_BITCLR(&bfdkey, 29);
   4245                 SHR_BITCLR(&bfdmask, 28);
   4246                 SHR_BITCLR(&bfdmask, 29);
   4247                 mask[1] =  bfdmask | (bfdval << 28);
   4248                 key[1] = bfdkey | (bfdval << 28);
   4249             }
   4250         }
   4251     }
   4252 #endif
   4253     /* Now zero entry */
   4254     sal_memset (&entry, 0, sizeof(cpu_cos_map_entry_t));
   4255 
   4256     /* Program the key and mask when reasons_mask is not NULL */
   4257     if (!BCM_RX_REASON_IS_NULL(reasons_mask)) {
   4258 #if defined BCM_TRIDENT3_SUPPORT
   4259         if (SOC_IS_TRIDENT3X(unit)) {
   4260             soc_mem_field_set(unit, CPU_COS_MAPm, (uint32 *)&entry, MASKf,
   4261                 &mask[0]);
   4262             soc_mem_field_set(unit, CPU_COS_MAPm, (uint32 *)&entry, KEYf,
   4263                 &key[0]);
   4264         } else
   4265 #endif
   4266         {
   4267         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, REASONS_MASK_LOWf,
   4268                             mask[0]);   
   4269         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, REASONS_KEY_LOWf,
   4270                             key[0]);
   4271         word_count = 1;
   4272         if (soc_mem_field_valid(unit, CPU_COS_MAPm, REASONS_MASK_MIDf)) {
   4273                 soc_mem_field32_set(unit, CPU_COS_MAPm, &entry,
   4274                     REASONS_MASK_MIDf, mask[word_count]);
   4275                 soc_mem_field32_set(unit, CPU_COS_MAPm, &entry,
   4276                     REASONS_KEY_MIDf, key[word_count]);
   4277             word_count++;
   4278         }
   4279         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, REASONS_MASK_HIGHf,
   4280                             mask[word_count]);   
   4281         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, REASONS_KEY_HIGHf,
   4282                             key[word_count]);
   4283     }
   4284     }
   4285 
   4286     /* Program the packet type */ 
   4287 
   4288     if (packet_type_mask & (BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST |
   4289                          BCM_RX_COSQ_PACKET_TYPE_SWITCHED)) {
   4290         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   4291                             SW_PKT_TYPE_MASKf, sw_pkt_type_mask);   
   4292         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   4293                             SW_PKT_TYPE_KEYf, sw_pkt_type_key);   
   4294     }
   4295 
   4296     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_MIRROR) {
   4297         if (soc_mem_field_valid(unit, CPU_COS_MAPm, RESERVED_MIRR_PKT_MASKf)) {
   4298             field = RESERVED_MIRR_PKT_MASKf;
   4299         } else {
   4300             field = MIRR_PKT_MASKf;
   4301         }
   4302 
   4303         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry,
   4304                             field, 1);
   4305 
   4306         if (packet_type & BCM_RX_COSQ_PACKET_TYPE_MIRROR) {
   4307             if (soc_mem_field_valid(unit, CPU_COS_MAPm, RESERVED_MIRR_PKT_KEYf)) {
   4308                 field = RESERVED_MIRR_PKT_KEYf;
   4309             } else {
   4310                 field = MIRR_PKT_KEYf;
   4311             }
   4312 
   4313             soc_mem_field32_set(unit, CPU_COS_MAPm, &entry,
   4314                                 field, 1);
   4315         }
   4316     }
   4317 
   4318     /* Handle priority when int_prio_mask != 0 */
   4319     if (int_prio_mask) {
   4320         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   4321                             INT_PRI_KEYf, (int_prio & 0xf));   
   4322         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, 
   4323                             INT_PRI_MASKf, (int_prio_mask & 0xf));   
   4324     }
   4325 
   4326     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, COSf, cosq);
   4327 #if defined(BCM_TOMAHAWK2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
   4328     if (SOC_IS_TOMAHAWK2(unit) || SOC_IS_TRIDENT3X(unit)) {
   4329         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, VALIDf, 3);
   4330     } else
   4331 #endif
   4332     {
   4333     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, VALIDf, 1);
   4334     }
   4335 
   4336 #ifdef BCM_TOMAHAWK_SUPPORT
   4337     if(SOC_MEM_FIELD_VALID(unit, CPU_COS_MAPm, STRENGTHf)) {
   4338         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, STRENGTHf,
   4339                     (soc_mem_index_max(unit, CPU_COS_MAPm) - index));
   4340     }
   4341 #endif /* BCM_TOMAHAWK_SUPPORT */
   4342 
   4343 #ifdef BCM_TRIDENT2_SUPPORT
   4344     if(SOC_MEM_FIELD_VALID(unit, CPU_COS_MAPm, TRUNCATE_CPU_COPYf)) {
   4345         soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, TRUNCATE_CPU_COPYf,
   4346                             (flags & BCM_RX_COPYTOCPU_TRUNCATE) ? 1 : 0);
   4347     }    
   4348 #endif
   4349 
   4350     
   4351 
   4352 
   4353     /* write to memory */
   4354     SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, 
   4355                                            index, &entry));
   4356 
   4357 #ifdef BCM_TOMAHAWK_SUPPORT
   4358     if (SOC_IS_TOMAHAWKX(unit) || SOC_IS_TRIDENT3X(unit)) {
   4359         uint32 cpu_cos_config;
   4360         if (BCM_RX_REASON_GET(reasons, bcmRxReasonSampleDest)) {
   4361             BCM_IF_ERROR_RETURN
   4362                 (READ_EGR_SFLOW_CPU_COS_CONFIGr(unit, &cpu_cos_config));
   4363             soc_reg_field_set(unit, EGR_SFLOW_CPU_COS_CONFIGr, &cpu_cos_config,
   4364                               COSf, cosq);
   4365             soc_reg_field_set(unit, EGR_SFLOW_CPU_COS_CONFIGr, &cpu_cos_config,
   4366                               STRENGTHf,
   4367                               (soc_mem_index_max(unit, CPU_COS_MAPm) - index));
   4368             soc_reg_field_set(unit, EGR_SFLOW_CPU_COS_CONFIGr, &cpu_cos_config,
   4369                               TRUNCATE_CPU_COPYf,
   4370                               (flags & BCM_RX_COPYTOCPU_TRUNCATE) ? 1 : 0);
   4371             BCM_IF_ERROR_RETURN
   4372                 (WRITE_EGR_SFLOW_CPU_COS_CONFIGr(unit, cpu_cos_config));
   4373         }
   4374         if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_MIRROR) {
   4375             BCM_IF_ERROR_RETURN
   4376                 (READ_MIRROR_CPU_COS_CONFIGr(unit, &cpu_cos_config));
   4377             soc_reg_field_set(unit, MIRROR_CPU_COS_CONFIGr, &cpu_cos_config,
   4378                               COSf, cosq);
   4379             soc_reg_field_set(unit, MIRROR_CPU_COS_CONFIGr, &cpu_cos_config,
   4380                               STRENGTHf,
   4381                               (soc_mem_index_max(unit, CPU_COS_MAPm) - index));
   4382             soc_reg_field_set(unit, MIRROR_CPU_COS_CONFIGr, &cpu_cos_config,
   4383                               TRUNCATE_CPU_COPYf,
   4384                               (flags & BCM_RX_COPYTOCPU_TRUNCATE) ? 1 : 0);
   4385             BCM_IF_ERROR_RETURN
   4386                 (WRITE_MIRROR_CPU_COS_CONFIGr(unit, cpu_cos_config));
   4387         }
   4388     }
   4389 #endif /* BCM_TOMAHAWK_SUPPORT */
   4390 #ifdef BCM_KATANA_SUPPORT
   4391     if (SOC_IS_KATANAX(unit)) {
   4392         if (rx_reasons_bfd_set) {
   4393             RX_UNIT_REASONS_BFD_SET(unit);
   4394         }
   4395         if (rx_reasons_mpls_bfd_set) {
   4396             RX_UNIT_REASONS_MPLS_BFD_SET(unit);
   4397         }
   4398     }
   4399 #endif /* BCM_KATANA_SUPPORT */
   4400 
   4401     return BCM_E_NONE;
   4402 }
   4403 #endif /* BCM_TRX_SUPPORT */
   4404 
   4405 #ifdef BCM_TOMAHAWK3_SUPPORT
   4406 int
   4407 _bcm_th3_rx_cosq_mapping_get(int unit, int index,
   4408                             bcm_rx_reasons_t *reasons,
   4409                             bcm_rx_reasons_t *reasons_mask,
   4410                             uint8 *prio, uint8 *prio_mask,
   4411                             uint32 *packet_type, uint32 * packet_type_mask,
   4412                             bcm_cos_queue_t *cosq, uint32 *flags)
   4413 {
   4414 #define KEY_ENTRY_WORDS_MAX 6
   4415     bcm_rx_reason_t *cpu_cos_map_key, *cpu_opcode_enc[KEY_ENTRY_WORDS_MAX] = {0};
   4416     int key_table_len, enc_table_len[KEY_ENTRY_WORDS_MAX] = {0}, enc_count;
   4417     int word_idx, bit_idx, key_idx, table_idx, word_count, bit_count, idx;
   4418     uint32 mask[KEY_ENTRY_WORDS_MAX] = {0}, key[KEY_ENTRY_WORDS_MAX] = {0}, enc_mask[KEY_ENTRY_WORDS_MAX] = {0};
   4419     uint32 enc_key[KEY_ENTRY_WORDS_MAX] = {0}, field_size[KEY_ENTRY_WORDS_MAX] = {0}, bit_key[KEY_ENTRY_WORDS_MAX] = {0};
   4420     uint32 sw_pkt_type_mask, sw_pkt_type_key;
   4421     uint32 bit_skip = 0;
   4422     uint32 entry[SOC_MAX_MEM_WORDS];
   4423     uint32 cpu_cos_map_mask_entry[SOC_MAX_MEM_WORDS];
   4424     uint32 cpu_cos_map_key_entry[SOC_MAX_MEM_WORDS];
   4425     int length = 0;
   4426 
   4427     word_count = 0;
   4428 
   4429     sal_memset (&cpu_cos_map_mask_entry, 0, sizeof(cpu_cos_map_mask_entry));
   4430     sal_memset (&cpu_cos_map_key_entry, 0, sizeof(cpu_cos_map_key_entry));
   4431     sal_memset (&entry, 0, sizeof(entry));
   4432 
   4433 
   4434     BCM_IF_ERROR_RETURN
   4435         (_bcm_rx_reason_table_get(unit, &cpu_cos_map_key, &key_table_len,
   4436                                   cpu_opcode_enc, enc_table_len, &enc_count));
   4437 
   4438     /* Verify the index */
   4439     if (index < soc_mem_index_min(unit, CPU_COS_MAPm) ||
   4440         index > soc_mem_index_max(unit, CPU_COS_MAPm)) {
   4441         return BCM_E_PARAM;
   4442     }
   4443 
   4444     /* NULL pointer check */
   4445     if (reasons == NULL  || reasons_mask == NULL  ||
   4446         prio == NULL || prio_mask == NULL ||
   4447         packet_type == NULL || packet_type_mask == NULL ||
   4448         cosq == NULL) {
   4449         return BCM_E_PARAM;
   4450     }
   4451 
   4452     /* Read the entry */
   4453     SOC_IF_ERROR_RETURN(READ_CPU_COS_MAPm(unit, MEM_BLOCK_ANY, index, entry));
   4454 
   4455     /* Return BCM_E_NOT_FOUND if invalid */
   4456     if (soc_mem_field32_get(unit, CPU_COS_MAPm, entry, VALIDf) == 0) {
   4457         return (BCM_E_NOT_FOUND);
   4458     }
   4459 
   4460     sal_memset(reasons, 0, sizeof(bcm_rx_reasons_t));
   4461     sal_memset(reasons_mask, 0, sizeof(bcm_rx_reasons_t));
   4462 
   4463     *cosq = (bcm_cos_queue_t)
   4464               soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, COSf);
   4465 
   4466     soc_mem_field_get(unit, CPU_COS_MAPm, (uint32 *)&entry, MASKf, &cpu_cos_map_mask_entry[0]);
   4467     soc_mem_field_get(unit, CPU_COS_MAPm, (uint32 *)&entry, KEYf, &cpu_cos_map_key_entry[0]);
   4468 
   4469     sw_pkt_type_mask = soc_format_field32_get(unit, CPU_COS_MAP_KEYfmt,
   4470                                            &cpu_cos_map_mask_entry, SW_PKT_TYPEf);
   4471     sw_pkt_type_key  = soc_format_field32_get(unit, CPU_COS_MAP_KEYfmt,
   4472                                            &cpu_cos_map_key_entry, SW_PKT_TYPEf);
   4473 
   4474     if (sw_pkt_type_mask == 0 && sw_pkt_type_key == 0) {
   4475         /* all packets matched */
   4476         *packet_type_mask = 0;
   4477         *packet_type = 0;
   4478     } else if (sw_pkt_type_mask == 2 && sw_pkt_type_key == 0) {
   4479         /* Only non-switched packets */
   4480         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   4481         *packet_type = 0;
   4482     } else if (sw_pkt_type_mask == 2 && sw_pkt_type_key == 2) {
   4483         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   4484         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   4485     } else if (sw_pkt_type_mask == 3 && sw_pkt_type_key == 2) {
   4486         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED |
   4487                              BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   4488         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED;
   4489     } else if (sw_pkt_type_mask == 3 && sw_pkt_type_key == 3) {
   4490         *packet_type_mask = BCM_RX_COSQ_PACKET_TYPE_SWITCHED |
   4491                              BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   4492         *packet_type = BCM_RX_COSQ_PACKET_TYPE_SWITCHED |
   4493                         BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST;
   4494     }
   4495 
   4496     if (soc_format_field32_get(unit, CPU_COS_MAP_KEYfmt, &cpu_cos_map_mask_entry, RESERVED_MIRR_PKTf)) {
   4497         *packet_type_mask |= BCM_RX_COSQ_PACKET_TYPE_MIRROR;
   4498     }
   4499 
   4500     if (soc_format_field32_get(unit, CPU_COS_MAP_KEYfmt, &cpu_cos_map_key_entry, RESERVED_MIRR_PKTf)) {
   4501         *packet_type |= BCM_RX_COSQ_PACKET_TYPE_MIRROR;
   4502     }
   4503 
   4504     if (flags != NULL) {
   4505         *flags = soc_mem_field32_get(unit, CPU_COS_MAPm, &entry, TRUNCATE_CPU_COPYf) ?
   4506                  BCM_RX_COPYTOCPU_TRUNCATE : 0;
   4507     }
   4508 
   4509     *prio_mask =
   4510         soc_format_field32_get(unit, CPU_COS_MAP_KEYfmt, &cpu_cos_map_mask_entry, INT_PRIf);
   4511     *prio =
   4512         soc_format_field32_get(unit, CPU_COS_MAP_KEYfmt, &cpu_cos_map_key_entry, INT_PRIf);
   4513 
   4514 
   4515     length = soc_mem_field_length(unit, CPU_COS_MAPm, KEYf);
   4516     while (length > 32) {
   4517         field_size[word_count] = 32;
   4518         word_count++;
   4519         length -= 32;
   4520     }
   4521     field_size[word_count] = length;
   4522     word_count++;
   4523 
   4524     soc_mem_field_get(unit, CPU_COS_MAPm, entry, MASKf, mask);
   4525     soc_mem_field_get(unit, CPU_COS_MAPm, entry, KEYf, key);
   4526 
   4527     /* 4bits INT_PRI + 1bit RESERVED_MIRR_PKT + 2bits SW_PKT_TYPE */
   4528     bit_skip = 0x7;
   4529 
   4530     sal_memset(enc_mask, 0, sizeof(enc_mask));
   4531     sal_memset(enc_key, 0, sizeof(enc_key));
   4532     sal_memset(bit_key, 0, sizeof(bit_key));
   4533     for (word_idx = 0; word_idx < word_count; word_idx++) {
   4534         bit_count = field_size[word_idx];
   4535         bit_idx = (word_idx == 0 ? bit_skip:0);
   4536         for (; bit_idx < bit_count; bit_idx++) {
   4537             uint32 maskbitset;
   4538             uint32 keybitset;
   4539 
   4540             maskbitset = mask[word_idx] & (1 << bit_idx);
   4541             keybitset = key[word_idx] & (1 << bit_idx);
   4542             key_idx = word_idx * 32 + bit_idx;
   4543             key_idx -= bit_skip;
   4544             if (key_idx >= key_table_len) {
   4545                 break;
   4546             }
   4547 
   4548            for (table_idx = 0; table_idx < enc_count; table_idx++) {
   4549                if (cpu_cos_map_key[key_idx] == cpu_opcode_enc[table_idx][0]) {
   4550                        if (maskbitset) { /* should always be set */
   4551                        enc_mask[table_idx] |= (1 << bit_key[table_idx]);
   4552                        }
   4553                        if (keybitset) {
   4554                        enc_key[table_idx] |= (1 << bit_key[table_idx]);
   4555                    }
   4556                    bit_key[table_idx]++;
   4557                }
   4558            }
   4559            if (maskbitset) {
   4560                BCM_RX_REASON_SET(*reasons_mask, cpu_cos_map_key[key_idx]);
   4561            }
   4562            if (keybitset) {
   4563                BCM_RX_REASON_SET(*reasons, cpu_cos_map_key[key_idx]);
   4564            }
   4565        }
   4566     }
   4567 
   4568     for (table_idx = 0; table_idx < enc_count; table_idx++) {
   4569         idx = enc_key[table_idx];
   4570         if (idx > 0) {
   4571                 BCM_RX_REASON_SET(*reasons, cpu_opcode_enc[table_idx][idx]);
   4572             }
   4573         }
   4574 
   4575 #undef KEY_ENTRY_WORDS_MAX
   4576     return BCM_E_NONE;
   4577 }
   4578 
   4579 /* Set the rx cosq mapping for Tomahawk3 */
   4580 int
   4581 _bcm_th3_rx_cosq_mapping_set(int unit, int index,
   4582                             bcm_rx_reasons_t reasons, bcm_rx_reasons_t
   4583                             reasons_mask,
   4584                             uint8 int_prio, uint8 int_prio_mask,
   4585                             uint32 packet_type, uint32 packet_type_mask,
   4586                             bcm_cos_queue_t cosq, uint32 flags)
   4587 {
   4588 #define KEY_ENTRY_WORDS_MAX 6
   4589     bcm_rx_reason_t *cpu_cos_map_key, *cpu_opcode_enc[KEY_ENTRY_WORDS_MAX] = {0};
   4590     int key_table_len, enc_table_len[3], enc_count;
   4591     int word_idx, bit_idx, key_idx, table_idx, enc_idx, word_count;
   4592     uint32 mask[KEY_ENTRY_WORDS_MAX] = {0}, key[KEY_ENTRY_WORDS_MAX] = {0}, enc_key, field_size[KEY_ENTRY_WORDS_MAX] = {0};
   4593     bcm_rx_reason_t  reason_enum, enc_enum;
   4594     bcm_rx_reasons_t reasons_remain;
   4595     cpu_cos_map_entry_t entry;
   4596     uint8 sw_pkt_type_key = 0;
   4597     uint8 sw_pkt_type_mask = 0;
   4598     uint32 bit_skip = 0;
   4599     uint32 cpu_cos_map_mask_entry[SOC_MAX_MEM_WORDS];
   4600     uint32 cpu_cos_map_key_entry[SOC_MAX_MEM_WORDS];
   4601     uint32 final_int_prio, final_int_prio_mask;
   4602     int length = 0;
   4603     uint32 cpu_cos_config;
   4604 
   4605     word_count = 0;
   4606     bit_idx = 0;
   4607 
   4608     sal_memset (&cpu_cos_map_mask_entry, 0, sizeof(cpu_cos_map_mask_entry));
   4609     sal_memset (&cpu_cos_map_key_entry, 0, sizeof(cpu_cos_map_key_entry));
   4610 
   4611     BCM_IF_ERROR_RETURN
   4612         (_bcm_rx_reason_table_get(unit, &cpu_cos_map_key, &key_table_len,
   4613                                   cpu_opcode_enc, enc_table_len, &enc_count));
   4614 
   4615     /* Verify COSQ */
   4616     if (cosq >= _bcm_tomahawk3_rx_cpu_max_cosq) {
   4617         return BCM_E_PARAM;
   4618     }
   4619 
   4620     /* Verify the index */
   4621     if (index < soc_mem_index_min(unit, CPU_COS_MAPm) ||
   4622         index > soc_mem_index_max(unit, CPU_COS_MAPm)) {
   4623         return BCM_E_PARAM;
   4624     }
   4625 
   4626     /* Verify the packet type */
   4627     if (packet_type & BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST) {
   4628         sw_pkt_type_key |= 1;
   4629     }
   4630     if (packet_type & BCM_RX_COSQ_PACKET_TYPE_SWITCHED) {
   4631         sw_pkt_type_key |= 2;
   4632     }
   4633     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST) {
   4634         sw_pkt_type_mask |= 1;
   4635     }
   4636     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_SWITCHED) {
   4637         sw_pkt_type_mask |= 2;
   4638     }
   4639     sw_pkt_type_key &= sw_pkt_type_mask;
   4640 
   4641     if ((sw_pkt_type_mask == 0x1) ||
   4642         ((sw_pkt_type_mask != 0) && (sw_pkt_type_key == 0x1))) {
   4643         /* Hw doesn't support these cases */
   4644         return BCM_E_PARAM;
   4645     }
   4646 
   4647     length = soc_mem_field_length(unit, CPU_COS_MAPm, KEYf);
   4648     while (length > 32) {
   4649         field_size[word_count] = 32;
   4650         word_count++;
   4651         length -= 32;
   4652     }
   4653     field_size[word_count] = length;
   4654     word_count++;
   4655 
   4656     /* 4bits INT_PRI + 1bit RESERVED_MIRR_PKT + 2bits SW_PKT_TYPE */
   4657     bit_skip = 0x7;
   4658 
   4659     reasons_remain = reasons_mask;
   4660     enc_enum = -1;
   4661     enc_key = 0;
   4662     word_idx = 0;
   4663     bit_idx = bit_skip;
   4664     sal_memset(mask, 0, sizeof(mask));
   4665     sal_memset(key, 0, sizeof(key));
   4666     for (key_idx = 0; key_idx < key_table_len; key_idx++, bit_idx++) {
   4667         if (bit_idx == field_size[word_idx]) {
   4668             bit_idx = 0;
   4669             word_idx++;
   4670             if (word_idx == word_count) {
   4671                 /* Trap implementation error */
   4672                 return BCM_E_INTERNAL;
   4673             }
   4674         }
   4675 
   4676         reason_enum = cpu_cos_map_key[key_idx];
   4677         if (reason_enum == enc_enum) { /* following bit of encoding */
   4678             mask[word_idx] |= 1 << bit_idx;
   4679             key[word_idx] |= (enc_key & 1) << bit_idx;
   4680             enc_key >>= 1;
   4681             continue;
   4682         }
   4683 
   4684         /* Find reason being set */
   4685         if (!BCM_RX_REASON_GET(reasons_mask, reason_enum)) {
   4686             continue;
   4687         }
   4688         BCM_RX_REASON_CLEAR(reasons_remain, reason_enum);
   4689 
   4690         for (table_idx = 0; table_idx < enc_count; table_idx++) {
   4691             if (reason_enum != cpu_opcode_enc[table_idx][0]) {
   4692                 continue;
   4693             }
   4694 
   4695             enc_enum = reason_enum;
   4696             for (enc_idx = 1; enc_idx < enc_table_len[table_idx]; enc_idx++) {
   4697                 reason_enum = cpu_opcode_enc[table_idx][enc_idx];
   4698                 if (!BCM_RX_REASON_GET(reasons, reason_enum)) {
   4699                     BCM_RX_REASON_CLEAR(reasons_remain, reason_enum);
   4700                     continue;
   4701                 } else if (enc_key != 0) { /* multiple reasons supplied */
   4702                     return BCM_E_PARAM;
   4703                 }
   4704                 BCM_RX_REASON_CLEAR(reasons_remain, reason_enum);
   4705                 enc_key = enc_idx;
   4706             }
   4707             mask[word_idx] |= 1 << bit_idx;
   4708             key[word_idx] |= (enc_key & 1) << bit_idx;
   4709             enc_key >>= 1;
   4710             break;
   4711         }
   4712         if (table_idx == enc_count) {
   4713             mask[word_idx] |= 1 << bit_idx;
   4714             if (BCM_RX_REASON_GET(reasons, reason_enum)) {
   4715                 key[word_idx] |= 1 << bit_idx;
   4716             }
   4717         }
   4718     }
   4719 
   4720     /* check whether there are reasons unsupported */
   4721     if (!BCM_RX_REASON_IS_NULL(reasons_remain)) {
   4722         return BCM_E_PARAM;
   4723     }
   4724 
   4725     /* Now zero entry */
   4726     sal_memset (&entry, 0, sizeof(cpu_cos_map_entry_t));
   4727 
   4728     /* Program the key and mask when reasons_mask is not NULL */
   4729     if (!BCM_RX_REASON_IS_NULL(reasons_mask)) {
   4730         soc_mem_field_set(unit, CPU_COS_MAPm, (uint32 *)&entry, MASKf, mask);
   4731         soc_mem_field_set(unit, CPU_COS_MAPm, (uint32 *)&entry, KEYf, key);
   4732     }
   4733     soc_mem_field_get(unit, CPU_COS_MAPm, (uint32 *)&entry, MASKf, cpu_cos_map_mask_entry);
   4734     soc_mem_field_get(unit, CPU_COS_MAPm, (uint32 *)&entry, KEYf, cpu_cos_map_key_entry);
   4735 
   4736     /* Program the packet type */
   4737 
   4738     if (packet_type_mask & (BCM_RX_COSQ_PACKET_TYPE_NON_UNICAST |
   4739                          BCM_RX_COSQ_PACKET_TYPE_SWITCHED)) {
   4740         soc_format_field32_set(unit, CPU_COS_MAP_KEYfmt, cpu_cos_map_mask_entry,
   4741                             SW_PKT_TYPEf, sw_pkt_type_mask);
   4742         soc_format_field32_set(unit, CPU_COS_MAP_KEYfmt, cpu_cos_map_key_entry,
   4743                             SW_PKT_TYPEf, sw_pkt_type_key);
   4744     }
   4745 
   4746     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_MIRROR) {
   4747         soc_format_field32_set(unit, CPU_COS_MAP_KEYfmt, cpu_cos_map_key_entry,
   4748                             RESERVED_MIRR_PKTf, 1);
   4749         soc_format_field32_set(unit, CPU_COS_MAP_KEYfmt, cpu_cos_map_mask_entry,
   4750                             RESERVED_MIRR_PKTf, 1);
   4751     }
   4752 
   4753     /* Handle priority when int_prio_mask != 0 */
   4754     if (int_prio_mask) {
   4755         final_int_prio = int_prio & 0xf;
   4756         final_int_prio_mask = int_prio_mask & 0xf;
   4757         soc_format_field32_set(unit, CPU_COS_MAP_KEYfmt, cpu_cos_map_key_entry,
   4758                             INT_PRIf, final_int_prio);
   4759         soc_format_field32_set(unit, CPU_COS_MAP_KEYfmt, cpu_cos_map_mask_entry,
   4760                             INT_PRIf, final_int_prio_mask);
   4761     }
   4762 
   4763     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, COSf, cosq);
   4764     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, VALIDf, 1);
   4765     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, STRENGTHf,
   4766                           (soc_mem_index_max(unit, CPU_COS_MAPm) - index));
   4767 
   4768     soc_mem_field32_set(unit, CPU_COS_MAPm, &entry, TRUNCATE_CPU_COPYf,
   4769                         (flags & BCM_RX_COPYTOCPU_TRUNCATE) ? 1 : 0);
   4770     soc_mem_field_set(unit, CPU_COS_MAPm, (uint32 *)&entry,
   4771                             KEYf, &cpu_cos_map_key_entry[0]);
   4772     soc_mem_field_set(unit, CPU_COS_MAPm, (uint32 *)&entry,
   4773                             MASKf, &cpu_cos_map_mask_entry[0]);
   4774 
   4775     /* write to memory */
   4776     SOC_IF_ERROR_RETURN(WRITE_CPU_COS_MAPm(unit, MEM_BLOCK_ALL, index,
   4777                                                &entry));
   4778 
   4779     if (BCM_RX_REASON_GET(reasons, bcmRxReasonSampleDest)) {
   4780         BCM_IF_ERROR_RETURN
   4781             (READ_EGR_SFLOW_CPU_COS_CONFIGr(unit, &cpu_cos_config));
   4782         soc_reg_field_set(unit, EGR_SFLOW_CPU_COS_CONFIGr, &cpu_cos_config,
   4783                           COSf, cosq);
   4784         soc_reg_field_set(unit, EGR_SFLOW_CPU_COS_CONFIGr, &cpu_cos_config,
   4785                           STRENGTHf,
   4786                           (soc_mem_index_max(unit, CPU_COS_MAPm) - index));
   4787         soc_reg_field_set(unit, EGR_SFLOW_CPU_COS_CONFIGr, &cpu_cos_config,
   4788                           TRUNCATE_CPU_COPYf,
   4789                           (flags & BCM_RX_COPYTOCPU_TRUNCATE) ? 1 : 0);
   4790         BCM_IF_ERROR_RETURN
   4791             (WRITE_EGR_SFLOW_CPU_COS_CONFIGr(unit, cpu_cos_config));
   4792     }
   4793     if (packet_type_mask & BCM_RX_COSQ_PACKET_TYPE_MIRROR) {
   4794         BCM_IF_ERROR_RETURN
   4795             (READ_MIRROR_CPU_COS_CONFIGr(unit, &cpu_cos_config));
   4796         soc_reg_field_set(unit, MIRROR_CPU_COS_CONFIGr, &cpu_cos_config,
   4797                           COSf, cosq);
   4798         soc_reg_field_set(unit, MIRROR_CPU_COS_CONFIGr, &cpu_cos_config,
   4799                           STRENGTHf,
   4800                           (soc_mem_index_max(unit, CPU_COS_MAPm) - index));
   4801         soc_reg_field_set(unit, MIRROR_CPU_COS_CONFIGr, &cpu_cos_config,
   4802                           TRUNCATE_CPU_COPYf,
   4803                           (flags & BCM_RX_COPYTOCPU_TRUNCATE) ? 1 : 0);
   4804         BCM_IF_ERROR_RETURN
   4805             (WRITE_MIRROR_CPU_COS_CONFIGr(unit, cpu_cos_config));
   4806     }
   4807 #undef KEY_ENTRY_WORDS_MAX
   4808 
   4809     return BCM_E_NONE;
   4810 }
   4811 #endif /* BCM_TOMAHAWK3_SUPPORT */
   4812 
   4813 /*
   4814  * Function:
   4815  *      bcm_rx_cosq_mapping_set
   4816  * Purpose:
   4817  *      Set the COSQ mapping to map qualified packets to the a CPU cos queue.
   4818  * Parameters: 
   4819  *      unit - Unit reference
   4820  *      index - Index into COSQ mapping table (0 is lowest match priority)
   4821  *      reasons - packet "reasons" bitmap
   4822  *      reasons_mask - mask for packet "reasons" bitmap
   4823  *      int_prio - internal priority value
   4824  *      int_prio_mask - mask for internal priority value
   4825  *      packet_type - packet type bitmap (BCM_RX_COSQ_PACKET_TYPE_*)
   4826  *      packet_type_mask - mask for packet type bitmap
   4827  *      cosq - CPU cos queue
   4828  * Returns:
   4829  *      BCM_E_XXX
   4830  */
   4831 int
   4832 bcm_esw_rx_cosq_mapping_set(int unit, int index, 
   4833                             bcm_rx_reasons_t reasons,
   4834                             bcm_rx_reasons_t reasons_mask, 
   4835                             uint8 int_prio, uint8 int_prio_mask,
   4836                             uint32 packet_type, uint32 packet_type_mask,
   4837                             bcm_cos_queue_t cosq)
   4838 {
   4839 #ifdef BCM_TOMAHAWK3_SUPPORT
   4840    if (SOC_IS_TOMAHAWK3(unit)) {
   4841        return _bcm_th3_rx_cosq_mapping_set(unit, index,
   4842                                            reasons, reasons_mask,
   4843                                            int_prio, int_prio_mask,
   4844                                            packet_type, packet_type_mask,
   4845                                            cosq, 0);
   4846    }
   4847 #endif
   4848 #ifdef BCM_TRIUMPH3_SUPPORT
   4849     if (soc_feature(unit, soc_feature_rx_reason_overlay)) {
   4850        return _bcm_tr3_rx_cosq_mapping_set(unit, index,
   4851                                            reasons, reasons_mask,
   4852                                            int_prio, int_prio_mask, 
   4853                                            packet_type, packet_type_mask,
   4854                                            cosq);
   4855    }
   4856 #endif
   4857 #ifdef BCM_TRX_SUPPORT
   4858    if (SOC_IS_TRX(unit)) {
   4859        return _bcm_trx_rx_cosq_mapping_set(unit, index,
   4860                                            reasons, reasons_mask,
   4861                                            int_prio, int_prio_mask, 
   4862                                            packet_type, packet_type_mask,
   4863                                            cosq, 0);
   4864    }
   4865 #endif
   4866     return BCM_E_UNAVAIL;
   4867 }
   4868 
   4869 /*
   4870  * Function:
   4871  *      bcm_rx_cosq_mapping_get
   4872  * Purpose:
   4873  *      Get the COSQ mapping at the specified index
   4874  * Parameters:
   4875  *      unit - Unit reference
   4876  *      index - Index into COSQ mapping table (0 is lowest match priority)
   4877  *      reasons - packet "reasons" bitmap
   4878  *      reasons_mask - mask for packet "reasons" bitmap
   4879  *      int_prio - internal priority value
   4880  *      int_prio_mask - mask for internal priority value
   4881  *      packet_type - packet type bitmap (BCM_RX_COSQ_PACKET_TYPE_*)
   4882  *      packet_type_mask - mask for packet type bitmap 
   4883  *      cosq - CPU cos queue 
   4884  * Returns:
   4885  *      BCM_E_XXX
   4886  */
   4887 int
   4888 bcm_esw_rx_cosq_mapping_get(int unit, int index, 
   4889                             bcm_rx_reasons_t *reasons, bcm_rx_reasons_t *reasons_mask, 
   4890                             uint8 *int_prio, uint8 *int_prio_mask,
   4891                             uint32 *packet_type, uint32 *packet_type_mask,
   4892                             bcm_cos_queue_t *cosq)
   4893 {
   4894 #ifdef BCM_TOMAHAWK3_SUPPORT
   4895    if (SOC_IS_TOMAHAWK3(unit)) {
   4896        return _bcm_th3_rx_cosq_mapping_get(unit, index, reasons, reasons_mask,
   4897                                            int_prio, int_prio_mask,
   4898                                            packet_type, packet_type_mask,
   4899                                            cosq, NULL);
   4900    }
   4901 #endif
   4902 #ifdef BCM_TRIUMPH3_SUPPORT
   4903     if (soc_feature(unit, soc_feature_rx_reason_overlay)) {
   4904        return _bcm_tr3_rx_cosq_mapping_get(unit, index, reasons, reasons_mask,
   4905                                            int_prio, int_prio_mask, 
   4906                                            packet_type, packet_type_mask,
   4907                                            cosq);
   4908    }
   4909 #endif
   4910 #ifdef BCM_TRX_SUPPORT
   4911    if (SOC_IS_TRX(unit)) {
   4912        return _bcm_trx_rx_cosq_mapping_get(unit, index, reasons, reasons_mask,
   4913                                            int_prio, int_prio_mask, 
   4914                                            packet_type, packet_type_mask,
   4915                                            cosq, NULL);
   4916    }
   4917 #endif
   4918     return BCM_E_UNAVAIL;
   4919 }
   4920 
   4921 /*
   4922  * Function:
   4923  *      bcm_rx_cosq_mapping_delete
   4924  * Purpose:
   4925  *      Delete the COSQ mapping at the specified index
   4926  * Parameters: 
   4927  *      unit - Unit reference
   4928  *      index - Index into COSQ mapping table 
   4929  * Returns:
   4930  *      BCM_E_XXX
   4931  */
   4932 int
   4933 bcm_esw_rx_cosq_mapping_delete(int unit, int index)
   4934 {
   4935 #ifdef BCM_TRX_SUPPORT
   4936     if (SOC_IS_TRX(unit)) {
   4937         return _bcm_trx_rx_cosq_mapping_delete(unit, index);
   4938     }
   4939 #endif
   4940     return BCM_E_UNAVAIL;
   4941 }
   4942 
   4943 
   4944 /*
   4945  * Function:
   4946  *      bcm_rx_cosq_mapping_extended_set
   4947  * Purpose:
   4948  *      Set the COSQ mapping to map qualified packets to the a CPU cos queue.
   4949  * Parameters: 
   4950  *      unit - Unit reference
   4951  *      rx_cosq_mapping - rx cosq mapping ptr
   4952  * Returns:
   4953  *      BCM_E_XXX
   4954  */
   4955 int
   4956 bcm_esw_rx_cosq_mapping_extended_set(int unit, uint32 options, 
   4957                                                       bcm_rx_cosq_mapping_t *rx_cosq_mapping)
   4958 {
   4959 #ifdef BCM_TRIDENT2_SUPPORT
   4960     if (soc_feature(unit, soc_feature_truncate_cpu_copy)) {
   4961 #ifdef BCM_TOMAHAWK3_SUPPORT
   4962        if (SOC_IS_TOMAHAWK3(unit)) {
   4963             return _bcm_th3_rx_cosq_mapping_set(unit, rx_cosq_mapping->index,
   4964                                                 rx_cosq_mapping->reasons,
   4965                                                 rx_cosq_mapping->reasons_mask,
   4966                                                 rx_cosq_mapping->int_prio,
   4967                                                 rx_cosq_mapping->int_prio_mask,
   4968                                                 rx_cosq_mapping->packet_type,
   4969                                                 rx_cosq_mapping->packet_type_mask,
   4970                                                 rx_cosq_mapping->cosq,
   4971                                                 rx_cosq_mapping->flags);
   4972        }
   4973        else
   4974 #endif
   4975        {
   4976         return _bcm_trx_rx_cosq_mapping_set(unit, rx_cosq_mapping->index,
   4977                                             rx_cosq_mapping->reasons, 
   4978                                             rx_cosq_mapping->reasons_mask,
   4979                                             rx_cosq_mapping->int_prio, 
   4980                                             rx_cosq_mapping->int_prio_mask, 
   4981                                             rx_cosq_mapping->packet_type, 
   4982                                             rx_cosq_mapping->packet_type_mask,
   4983                                             rx_cosq_mapping->cosq, 
   4984                                             rx_cosq_mapping->flags);
   4985        }
   4986 
   4987    }
   4988 #endif 
   4989     return BCM_E_UNAVAIL;
   4990 }
   4991 
   4992 /*
   4993  * Function:
   4994  *      bcm_rx_cosq_mapping_extended_get
   4995  * Purpose:
   4996  *      Get the COSQ mapping at the specified index
   4997  * Parameters:
   4998  *      unit - Unit reference
   4999  *      rx_cosq_mapping - rx cosq mapping ptr
   5000  * Returns:
   5001  *      BCM_E_XXX
   5002  */
   5003 int
   5004 bcm_esw_rx_cosq_mapping_extended_get(int unit, bcm_rx_cosq_mapping_t *rx_cosq_mapping)
   5005 {
   5006 #ifdef BCM_TRIDENT2_SUPPORT
   5007     if (soc_feature(unit, soc_feature_truncate_cpu_copy)) {
   5008 #ifdef BCM_TOMAHAWK3_SUPPORT
   5009         if (SOC_IS_TOMAHAWK3(unit)) {
   5010             return _bcm_th3_rx_cosq_mapping_get(unit, rx_cosq_mapping->index,
   5011                                                 &rx_cosq_mapping->reasons,
   5012                                                 &rx_cosq_mapping->reasons_mask,
   5013                                                 &rx_cosq_mapping->int_prio,
   5014                                                 &rx_cosq_mapping->int_prio_mask,
   5015                                                 &rx_cosq_mapping->packet_type,
   5016                                                 &rx_cosq_mapping->packet_type_mask,
   5017                                                 &rx_cosq_mapping->cosq,
   5018                                                 &rx_cosq_mapping->flags);
   5019         }
   5020         else
   5021 #endif
   5022         {
   5023         return _bcm_trx_rx_cosq_mapping_get(unit, rx_cosq_mapping->index, 
   5024                                             &rx_cosq_mapping->reasons, 
   5025                                             &rx_cosq_mapping->reasons_mask,
   5026                                             &rx_cosq_mapping->int_prio, 
   5027                                             &rx_cosq_mapping->int_prio_mask, 
   5028                                             &rx_cosq_mapping->packet_type, 
   5029                                             &rx_cosq_mapping->packet_type_mask,
   5030                                             &rx_cosq_mapping->cosq, 
   5031                                             &rx_cosq_mapping->flags);
   5032         }
   5033 
   5034    }
   5035 #endif
   5036     return BCM_E_UNAVAIL;
   5037 }
   5038 
   5039 /*
   5040  * Function:
   5041  *      _bcm_esw_rx_cosq_mapping_init
   5042  * Purpose:
   5043  *      Delete all the COSQ mapping
   5044  * Parameters: 
   5045  *      unit - Unit reference
   5046  * Returns:
   5047  *      BCM_E_XXX
   5048  */
   5049 #ifdef BCM_TRX_SUPPORT
   5050 STATIC int _bcm_esw_rx_cosq_mapping_init(int unit)
   5051 {
   5052     if (SOC_IS_TRX(unit)) {
   5053         return _bcm_trx_rx_cosq_mapping_init(unit);
   5054     }
   5055     return BCM_E_UNAVAIL;
   5056 }
   5057 #endif
   5058 
   5059 
   5060 /*  
   5061  * Function:
   5062  *      bcm_rx_queue_channel_set
   5063  * Purpose:
   5064  *      Assign a RX channel to a cosq 
   5065  * Parameters:
   5066  *      unit - Unit reference
   5067  *      queue_id - CPU cos queue index (0 - (max cosq - 1)) 
   5068  *                                      (Negative for all)
   5069  *      chan_id - channel index (0 - (SOC_CMCS_NUM(unit) * BCM_RX_CHANNELS-1))
   5070  * Returns:
   5071  *      BCM_E_XXX
   5072  */
   5073 int
   5074 bcm_esw_rx_queue_channel_set (int unit, bcm_cos_queue_t queue_id, 
   5075                               bcm_rx_chan_t chan_id)
   5076 {
   5077 #if defined(BCM_CMICM_SUPPORT) || defined(BCM_CMICX_SUPPORT)
   5078     uint32 max_rx_channels = 0;
   5079 
   5080     soc_dma_max_rx_channels_get(unit, &max_rx_channels);
   5081 
   5082     if (chan_id >= (SOC_CMCS_NUM(unit) * max_rx_channels)) {
   5083         /* API access is constrained to only the PCI host channels. */
   5084         return BCM_E_PARAM;
   5085     }
   5086 #endif
   5087 
   5088     return (_bcm_common_rx_queue_channel_set(unit, queue_id, 
   5089 	  				     chan_id));
   5090 }
   5091 
   5092 /*  
   5093  * Function:
   5094  *      bcm_rx_queue_channel_get
   5095  * Purpose:
   5096  *      Get the associated rx channel with a given cosq
   5097  * Parameters:
   5098  *      unit - Unit reference
   5099  *      queue_id - CPU cos queue index (0 - (max cosq - 1)) 
   5100  *      chan_id - channel index (0 - (BCM_RX_CHANNELS-1))
   5101  * Returns:
   5102  *      BCM_E_XXX
   5103  */
   5104 int
   5105 bcm_esw_rx_queue_channel_get(int unit, bcm_cos_queue_t queue_id, 
   5106                              bcm_rx_chan_t *chan_id)
   5107 {
   5108     return (_bcm_common_rx_queue_channel_get(unit, queue_id, 
   5109 	  				     chan_id));
   5110 }
   5111 
   5112 /*
   5113  * Function:
   5114  *      bcm_rx_active
   5115  * Purpose:
   5116  *      Return boolean as to whether unit is running
   5117  * Parameters:
   5118  *      unit - StrataXGS to check
   5119  * Returns:
   5120  *      Boolean:   TRUE if unit is running.
   5121  * Notes:
   5122  */
   5123 
   5124 int
   5125 bcm_esw_rx_active(int unit)
   5126 {
   5127     return (_bcm_common_rx_active(unit));
   5128 }
   5129 
   5130 
   5131 /*
   5132  * Function:
   5133  *      bcm_rx_running_channels_get
   5134  * Purpose:
   5135  *      Returns a bitmap indicating which channels are active
   5136  * Parameters:
   5137  *      unit       - Which unit to operate on
   5138  * Returns:
   5139  *      Bitmap of active channels
   5140  * Notes:
   5141  */
   5142 
   5143 int
   5144 bcm_esw_rx_channels_running(int unit, uint32 *channels)
   5145 {
   5146     return (_bcm_common_rx_channels_running(unit, channels));
   5147 }
   5148 
   5149 /*
   5150  * Function:
   5151  *      bcm_rx_alloc
   5152  * Purpose:
   5153  *      Gateway to configured RX allocation function
   5154  * Parameters:
   5155  *      unit - Unit reference
   5156  *      pkt_size - Packet size, see notes.
   5157  *      flags - Used to set up packet flags
   5158  * Returns:
   5159  *      Pointer to new packet buffer or NULL if cannot alloc memory
   5160  * Notes:
   5161  *      Although the packet size is normally configured per unit,
   5162  *      the option of using a different size is given here.  If
   5163  *      pkt_size <= 0, then the default packet size for the unit
   5164  *      is used.
   5165  */
   5166 
   5167 int
   5168 bcm_esw_rx_alloc(int unit, int pkt_size, uint32 flags, void **buf)
   5169 {
   5170     return (_bcm_common_rx_alloc(unit, pkt_size, flags, buf));
   5171 }
   5172 
   5173 
   5174 /*
   5175  * Function:
   5176  *      bcm_rx_free
   5177  * Purpose:
   5178  *      Gateway to configured RX free function.  Generally, packet
   5179  *      buffer was allocated with bcm_rx_alloc.
   5180  * Parameters:
   5181  *      unit - Unit reference
   5182  *      pkt - Packet to free
   5183  * Returns:
   5184  * Notes:
   5185  *      In particular, packets stolen from RX with BCM_RX_HANDLED_OWNED
   5186  *      should use this to free packets.
   5187  */
   5188 
   5189 int
   5190 bcm_esw_rx_free(int unit, void *pkt_data)
   5191 {
   5192     return (_bcm_common_rx_free(unit, pkt_data));
   5193 }
   5194 
   5195 
   5196 /*
   5197  * Function:
   5198  *      bcm_rx_free_enqueue
   5199  * Purpose:
   5200  *      Queue a packet to be freed by the RX thread.
   5201  * Parameters:
   5202  *      unit - Unit reference
   5203  *      pkt - Packet to free
   5204  * Returns:
   5205  * Notes:
   5206  *      This may be called in interrupt context to queue
   5207  *      a packet to be freed.
   5208  *
   5209  *      Assumes pkt_data is 32-bit aligned.
   5210  *      Uses the first word of the freed data as a "next" pointer
   5211  *      for the free list.
   5212  */
   5213 int
   5214 bcm_esw_rx_free_enqueue(int unit, void *pkt_data)
   5215 {
   5216     return (_bcm_common_rx_free_enqueue(unit, pkt_data));
   5217 }
   5218 
   5219 
   5220 /****************************************************************
   5221  *
   5222  * Global (all COS) and per COS rate limiting configuration
   5223  */
   5224 
   5225 
   5226 /*
   5227  * Functions:
   5228  *      bcm_rx_burst_set, get; bcm_rx_rate_set, get
   5229  *      bcm_rx_cos_burst_set, get; bcm_rx_cos_rate_set, get;
   5230  *      bcm_rx_cos_max_len_set, get
   5231  * Purpose:
   5232  *      Get/Set the global and per COS limits:
   5233  *           rate:      Packets/second
   5234  *           burst:     Packets (max tokens in bucket)
   5235  *           max_len:   Packets (max permitted in queue).
   5236  * Parameters:
   5237  *      unit - Unit reference
   5238  *      cos - For per COS functions, which COS queue affected
   5239  *      pps - Rate in packets per second (OUT for get functions)
   5240  *      burst - Burst rate for the system in packets (OUT for get functions)
   5241  *      max_q_len - Burst rate for the system in packets (OUT for get functions)
   5242  * Returns:
   5243  *      BCM_E_XXX
   5244  * Notes:
   5245  *      PPS must be >= 0 and
   5246  *      Max queue length must be >= 0;
   5247  *          otherwise param error.
   5248  *
   5249  *      PPS == 0 -> rate limiting disabled.
   5250  *      max_q_len == 0 -> no limit on queue length (not recommended)
   5251  */
   5252 
   5253 int
   5254 bcm_esw_rx_rate_set(int unit, int pps)
   5255 {
   5256     RX_INIT_CHECK(unit);
   5257 
   5258     if (pps < 0) {
   5259         return BCM_E_PARAM;
   5260     }
   5261     RX_PPS(unit) = pps;
   5262 
   5263 #if defined(BCM_HURRICANE2_SUPPORT)
   5264     if (SOC_IS_HURRICANE2(unit) || SOC_IS_GREYHOUND(unit) ||
   5265         SOC_IS_HURRICANE3(unit) || SOC_IS_GREYHOUND2(unit)) {
   5266         return bcm_rx_cos_rate_set(unit, BCM_RX_COS_ALL, pps);
   5267     }
   5268 #endif /* BCM_HURRICANE2_SUPPORT */
   5269 
   5270 #if defined(BCM_FIREBOLT2_SUPPORT) || defined(BCM_TRX_SUPPORT)
   5271     if (RX_IS_LOCAL(unit) && SOC_UNIT_VALID(unit)) {
   5272         if (soc_feature(unit, soc_feature_packet_rate_limit)) {
   5273 #ifdef BCM_TRIUMPH2_SUPPORT
   5274             if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   5275                 SOC_IS_VALKYRIE2(unit)) {
   5276                 return bcm_rx_cos_rate_set(unit, BCM_RX_COS_ALL, pps);
   5277             } else if (SOC_IS_TD_TT(unit) || SOC_IS_KATANAX(unit) || 
   5278                 SOC_IS_TRIUMPH3(unit)) {
   5279                 int burst;
   5280                 BCM_IF_ERROR_RETURN(bcm_esw_rx_burst_get(unit, &burst));
   5281 
   5282                 if (SOC_IS_TITAN(unit)) {
   5283                     return bcm_tr_port_pps_rate_egress_set(unit, CMIC_PORT(unit),
   5284                                                        (uint32)pps, (uint32)burst);
   5285                 } else {
   5286                     return bcm_esw_port_rate_egress_pps_set(unit, CMIC_PORT(unit),
   5287                                                         (uint32)pps, (uint32)burst);
   5288                 }
   5289             }
   5290 #endif /* BCM_TRIUMPH2_SUPPORT */
   5291 #ifdef BCM_TRX_SUPPORT
   5292             if (SOC_IS_TRX(unit) && \
   5293                 !(SOC_IS_HURRICANEX(unit)||SOC_IS_GREYHOUND(unit)||
   5294                   SOC_IS_GREYHOUND2(unit))) {
   5295                 return bcm_tr_cosq_port_pps_set(unit, CMIC_PORT(unit),
   5296                                                -1, pps);
   5297             }
   5298 #endif /* BCM_TRX_SUPPORT */
   5299 #ifdef BCM_FIREBOLT2_SUPPORT
   5300             if (SOC_IS_FIREBOLT2(unit)) {
   5301                 return bcm_fb2_cosq_port_pps_set(unit, CMIC_PORT(unit),
   5302                                                  -1, pps);
   5303             }
   5304 #endif /* BCM_FIREBOLT2_SUPPORT */
   5305         }
   5306     }
   5307 #endif /* BCM_FIREBOLT2_SUPPORT || BCM_TRX_SUPPORT */
   5308 
   5309     return BCM_E_NONE;
   5310 }
   5311 
   5312 int
   5313 bcm_esw_rx_rate_get(int unit, int *pps)
   5314 {
   5315     return (_bcm_common_rx_rate_get(unit, pps));
   5316 }
   5317 
   5318 int 
   5319 bcm_esw_rx_cpu_rate_set(int unit, int pps)
   5320 {
   5321     return (_bcm_common_rx_cpu_rate_set(unit, pps));
   5322 }
   5323 
   5324 int 
   5325 bcm_esw_rx_cpu_rate_get(int unit, int *pps)
   5326 {
   5327     return (_bcm_common_rx_cpu_rate_get(unit, pps));
   5328 }
   5329 
   5330 
   5331 int
   5332 bcm_esw_rx_burst_set(int unit, int burst)
   5333 {
   5334     RX_INIT_CHECK(unit);
   5335 
   5336     RX_BURST(unit) = burst;
   5337     RX_TOKENS(unit) = burst;
   5338 
   5339 #if defined(BCM_FIREBOLT2_SUPPORT) || defined(BCM_TRX_SUPPORT)
   5340     if (RX_IS_LOCAL(unit) && SOC_UNIT_VALID(unit)) {
   5341         if (soc_feature(unit, soc_feature_packet_rate_limit)) {
   5342 #ifdef BCM_TRIUMPH2_SUPPORT
   5343             if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   5344                 SOC_IS_VALKYRIE2(unit) || SOC_IS_KATANAX(unit)) {
   5345                 return bcm_rx_cos_burst_set(unit, BCM_RX_COS_ALL, burst);
   5346             } else 
   5347 #if defined(BCM_TRIDENT2_SUPPORT)
   5348             if (SOC_IS_TD2_TT2(unit)) {
   5349                 int pps;
   5350                 BCM_IF_ERROR_RETURN(bcm_esw_rx_rate_get(unit, &pps));
   5351                 return mbcm_driver[unit]->mbcm_port_rate_egress_set
   5352                     (unit, CMIC_PORT(unit), pps, burst,
   5353                      _BCM_PORT_RATE_PPS_MODE);
   5354             } else
   5355 #endif /* BCM_TRIDENT2_SUPPORT */
   5356             if (SOC_IS_TD_TT(unit)) {
   5357                 int pps;
   5358                 BCM_IF_ERROR_RETURN(bcm_esw_rx_rate_get(unit, &pps));
   5359                 return bcm_tr_port_pps_rate_egress_set(unit, CMIC_PORT(unit),
   5360                                                        (uint32)pps, (uint32)burst);
   5361             }
   5362 #endif /* BCM_TRIUMPH2_SUPPORT */
   5363 #ifdef BCM_TRX_SUPPORT
   5364             if (SOC_IS_TRX(unit) && \
   5365                 !(SOC_IS_HURRICANEX(unit)||SOC_IS_GREYHOUND(unit) ||
   5366                 SOC_IS_GREYHOUND2(unit))) {
   5367 #ifdef BCM_TRIUMPH3_SUPPORT
   5368                 if (SOC_IS_TRIUMPH3(unit)) {
   5369                     int pps;
   5370                     BCM_IF_ERROR_RETURN(bcm_esw_rx_rate_get(unit, &pps));
   5371                     return mbcm_driver[unit]->mbcm_port_rate_egress_set
   5372                         (unit, CMIC_PORT(unit), pps, burst,
   5373                          _BCM_PORT_RATE_PPS_MODE);
   5374                 } else 
   5375 #endif /* BCM_TRIUMPH3_SUPPORT */
   5376                 {
   5377                     return bcm_tr_cosq_port_burst_set(unit, CMIC_PORT(unit), -1,
   5378                                                   burst);
   5379                 }
   5380             }
   5381 #endif /* BCM_TRX_SUPPORT */
   5382 #ifdef BCM_FIREBOLT2_SUPPORT
   5383             if (SOC_IS_FIREBOLT2(unit)) {
   5384                 return bcm_fb2_cosq_port_burst_set(unit, CMIC_PORT(unit), -1,
   5385                                                    burst);
   5386             }
   5387 #endif /* BCM_FIREBOLT2_SUPPORT */
   5388         }
   5389     }
   5390 #endif /* BCM_FIREBOLT2_SUPPORT || BCM_TRX_SUPPORT */
   5391 
   5392     return BCM_E_NONE;
   5393 }
   5394 
   5395 int
   5396 bcm_esw_rx_burst_get(int unit, int *burst)
   5397 {
   5398     return (_bcm_common_rx_burst_get(unit, burst));
   5399 }
   5400 
   5401 
   5402 int
   5403 bcm_esw_rx_cos_rate_set(int unit, int cos, int pps)
   5404 {
   5405     int i;
   5406 
   5407     RX_INIT_CHECK(unit);
   5408     if (!LEGAL_COS(cos) || pps < 0) {
   5409         return BCM_E_PARAM;
   5410     }
   5411 
   5412     if (cos > RX_QUEUE_MAX(unit)) {
   5413         return BCM_E_PARAM;
   5414     }
   5415 
   5416     if (cos == BCM_RX_COS_ALL) {
   5417         for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5418             RX_COS_PPS(unit, i) = pps;
   5419         }
   5420     } else {
   5421         RX_COS_PPS(unit, cos) = pps;
   5422     }
   5423 
   5424 #if defined(BCM_FIREBOLT2_SUPPORT) || defined(BCM_TRX_SUPPORT)
   5425     if (RX_IS_LOCAL(unit) && SOC_UNIT_VALID(unit)) {
   5426         if (soc_feature(unit, soc_feature_packet_rate_limit)) {
   5427 #ifdef BCM_MONTEREY_SUPPORT
   5428             if (SOC_IS_MONTEREY(unit)) {
   5429                 if (cos == BCM_RX_COS_ALL) {
   5430                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5431                         BCM_IF_ERROR_RETURN
   5432                             (bcm_mn_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5433                                                       pps));
   5434                     }
   5435                 } else {
   5436                     BCM_IF_ERROR_RETURN
   5437                         (bcm_mn_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5438                                                   pps));
   5439                 }
   5440                 return BCM_E_NONE;
   5441             }
   5442 #endif
   5443 #ifdef BCM_APACHE_SUPPORT
   5444             if (SOC_IS_APACHE(unit)) {
   5445                 if (cos == BCM_RX_COS_ALL) {
   5446                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5447                         BCM_IF_ERROR_RETURN
   5448                             (bcm_ap_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5449                                                       pps));
   5450                     }
   5451                 } else {
   5452                     BCM_IF_ERROR_RETURN
   5453                         (bcm_ap_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5454                                                   pps));
   5455                 }
   5456                 return BCM_E_NONE;
   5457             }
   5458 #endif
   5459 #ifdef BCM_TOMAHAWK3_SUPPORT
   5460             if (SOC_IS_TOMAHAWK3(unit)) {
   5461                 if (cos == BCM_RX_COS_ALL) {
   5462                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5463                         BCM_IF_ERROR_RETURN
   5464                             (bcm_th3_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5465                                                       pps));
   5466                     }
   5467                 } else {
   5468                     BCM_IF_ERROR_RETURN
   5469                         (bcm_th3_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5470                                                   pps));
   5471                 }
   5472                 return BCM_E_NONE;
   5473             } else
   5474 #endif /* BCM_TOMAHAWK_SUPPORT */
   5475 #ifdef BCM_TOMAHAWK_SUPPORT
   5476             if (SOC_IS_TOMAHAWKX(unit)) {
   5477                 if (cos == BCM_RX_COS_ALL) {
   5478                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5479                         BCM_IF_ERROR_RETURN
   5480                             (bcm_th_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5481                                                       pps));
   5482                     }
   5483                 } else {
   5484                     BCM_IF_ERROR_RETURN
   5485                         (bcm_th_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5486                                                   pps));
   5487                 }
   5488                 return BCM_E_NONE;
   5489             } else 
   5490 #endif /* BCM_TOMAHAWK_SUPPORT */
   5491 #ifdef BCM_HELIX5_SUPPORT
   5492             if (SOC_IS_HELIX5(unit)) {
   5493                 if (cos == BCM_RX_COS_ALL) {
   5494                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5495                         BCM_IF_ERROR_RETURN
   5496                             (bcm_hx5_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5497                                                        pps));
   5498                     }
   5499                 } else {
   5500                     BCM_IF_ERROR_RETURN
   5501                         (bcm_hx5_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5502                                                    pps));
   5503                 }
   5504                 return BCM_E_NONE;
   5505             } else
   5506 #endif /* BCM_HELIX5_SUPPORT */
   5507 #ifdef BCM_TRIDENT3_SUPPORT
   5508             if (SOC_IS_TRIDENT3X(unit)) {
   5509                 if (cos == BCM_RX_COS_ALL) {
   5510                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5511                         BCM_IF_ERROR_RETURN
   5512                             (bcm_td3_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5513                                                        pps));
   5514                     }
   5515                 } else {
   5516                     BCM_IF_ERROR_RETURN
   5517                         (bcm_td3_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5518                                                    pps));
   5519                 }
   5520                 return BCM_E_NONE;
   5521             } else
   5522 #endif /* BCM_TRIDENT3_SUPPORT */
   5523 #ifdef BCM_TRIDENT_SUPPORT
   5524             if (SOC_IS_TD2_TT2(unit)) {
   5525 #ifdef BCM_TRIDENT2_SUPPORT
   5526                 if (cos == BCM_RX_COS_ALL) {
   5527                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5528                         BCM_IF_ERROR_RETURN
   5529                             (bcm_td2_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5530                                                       pps));
   5531                     }
   5532                 } else {
   5533                     BCM_IF_ERROR_RETURN
   5534                         (bcm_td2_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5535                                                   pps));
   5536                 }
   5537                 return BCM_E_NONE;
   5538 #else
   5539                 return BCM_E_UNAVAIL;
   5540 #endif
   5541             } else 
   5542             if (SOC_IS_TD_TT(unit)) {
   5543                 if (cos == BCM_RX_COS_ALL) {
   5544                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5545                         BCM_IF_ERROR_RETURN
   5546                             (bcm_td_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5547                                                       pps));
   5548                     }
   5549                 } else {
   5550                     BCM_IF_ERROR_RETURN
   5551                         (bcm_td_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5552                                                   pps));
   5553                 }
   5554                 return BCM_E_NONE;
   5555             }
   5556 #endif /* BCM_TRIDENT_SUPPORT */
   5557 #ifdef BCM_TRIUMPH3_SUPPORT
   5558             if (SOC_IS_TRIUMPH3(unit)) {
   5559                 if (cos == BCM_RX_COS_ALL) {
   5560                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5561                         BCM_IF_ERROR_RETURN
   5562                             (bcm_tr3_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5563                                                       pps));
   5564                     }
   5565                 } else {
   5566                     BCM_IF_ERROR_RETURN
   5567                         (bcm_tr3_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5568                                                   pps));
   5569                 }
   5570                 return BCM_E_NONE;
   5571             }
   5572 #endif /* BCM_TRIUMPH3_SUPPORT */
   5573 #ifdef BCM_TRIUMPH2_SUPPORT
   5574             if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   5575                 SOC_IS_VALKYRIE2(unit)) {
   5576                 if (cos == BCM_RX_COS_ALL) {
   5577                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5578                         BCM_IF_ERROR_RETURN
   5579                             (bcm_tr2_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5580                                                       pps));
   5581                     }
   5582                 } else {
   5583                     BCM_IF_ERROR_RETURN
   5584                         (bcm_tr2_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5585                                                   pps));
   5586                 }
   5587                 return BCM_E_NONE;
   5588             }
   5589 #endif /* BCM_TRIUMPH2_SUPPORT */
   5590 #if defined(BCM_HURRICANE1_SUPPORT)
   5591             if (SOC_IS_HURRICANE(unit)) {
   5592                 if (cos >= NUM_CPU_COSQ(unit)) {
   5593                     return BCM_E_PARAM;
   5594                 }
   5595                 return BCM_E_NONE;
   5596             }
   5597 #endif
   5598 #ifdef BCM_KATANA_SUPPORT
   5599             if (SOC_IS_KATANA(unit)) {
   5600                 if (cos == BCM_RX_COS_ALL) {
   5601                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5602                         BCM_IF_ERROR_RETURN
   5603                             (bcm_kt_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5604                                                       pps));
   5605                     }
   5606                 } else {
   5607                     BCM_IF_ERROR_RETURN
   5608                         (bcm_kt_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5609                                                   pps));
   5610                 }
   5611                 return BCM_E_NONE;
   5612             }
   5613 #endif
   5614 #ifdef BCM_KATANA2_SUPPORT
   5615             if (SOC_IS_KATANA2(unit)) {
   5616                 if (cos == BCM_RX_COS_ALL) {
   5617                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5618                         BCM_IF_ERROR_RETURN
   5619                             (bcm_kt2_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5620                                                       pps));
   5621                     }
   5622                 } else {
   5623                     BCM_IF_ERROR_RETURN
   5624                         (bcm_kt2_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5625                                                   pps));
   5626                 }
   5627                 return BCM_E_NONE;
   5628             }
   5629 #endif
   5630 #ifdef BCM_HURRICANE2_SUPPORT
   5631             if (SOC_IS_HURRICANE2(unit) || SOC_IS_GREYHOUND(unit) ||
   5632                 SOC_IS_HURRICANE3(unit) || SOC_IS_GREYHOUND2(unit)) {
   5633                 if (cos == BCM_RX_COS_ALL) {
   5634                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5635                         BCM_IF_ERROR_RETURN
   5636                             (bcm_hr2_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5637                                                       pps));
   5638                     }
   5639                 } else {
   5640                     BCM_IF_ERROR_RETURN
   5641                         (bcm_hr2_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5642                                                   pps));
   5643                 }
   5644                 return BCM_E_NONE;
   5645             }
   5646 #endif
   5647 #ifdef BCM_TRX_SUPPORT
   5648             if (SOC_IS_TRX(unit)) {
   5649                 if (cos == BCM_RX_COS_ALL) {
   5650                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5651                         BCM_IF_ERROR_RETURN
   5652                             (bcm_tr_cosq_port_pps_set(unit, CMIC_PORT(unit), i,
   5653                                                       pps));
   5654                     }
   5655                 } else {
   5656                     BCM_IF_ERROR_RETURN
   5657                         (bcm_tr_cosq_port_pps_set(unit, CMIC_PORT(unit), cos,
   5658                                                   pps));
   5659                 }
   5660                 return BCM_E_NONE;
   5661             }
   5662 #endif /* BCM_TRX_SUPPORT */
   5663 #ifdef BCM_FIREBOLT2_SUPPORT
   5664             if (SOC_IS_FIREBOLT2(unit)) {
   5665                 if (cos == BCM_RX_COS_ALL) {
   5666                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5667                         BCM_IF_ERROR_RETURN
   5668                             (bcm_fb2_cosq_port_pps_set(unit, CMIC_PORT(unit),
   5669                                                        i, pps));
   5670                     }
   5671                 } else {
   5672                     BCM_IF_ERROR_RETURN
   5673                         (bcm_fb2_cosq_port_pps_set(unit, CMIC_PORT(unit),
   5674                                                    cos, pps));
   5675                 }
   5676                 return BCM_E_NONE;
   5677             }
   5678  #endif /* BCM_FIREBOLT2_SUPPORT */
   5679        }
   5680     }
   5681 #endif /* BCM_FIREBOLT2_SUPPORT || BCM_TRX_SUPPORT */
   5682     return BCM_E_NONE;
   5683 }
   5684 
   5685 int
   5686 bcm_esw_rx_cos_rate_get(int unit, int cos, int *pps)
   5687 {
   5688     if (!RX_INIT_DONE(unit)) {
   5689         return BCM_E_INIT;
   5690     }
   5691 
   5692     if ( (cos < 0) || (cos > RX_QUEUE_MAX(unit))) {
   5693         return BCM_E_PARAM;
   5694     }
   5695 
   5696     return (_bcm_common_rx_cos_rate_get(unit, cos, pps));
   5697 }
   5698 
   5699 int
   5700 bcm_esw_rx_cos_burst_set(int unit, int cos, int burst)
   5701 {
   5702     rx_queue_t *queue;
   5703     int i;
   5704 
   5705     RX_INIT_CHECK(unit);
   5706     if (!LEGAL_COS(cos)) {
   5707         return BCM_E_PARAM;
   5708     }
   5709 
   5710     if (cos > RX_QUEUE_MAX(unit)) {
   5711         return BCM_E_PARAM;
   5712     }
   5713 
   5714     if (cos == BCM_RX_COS_ALL) {
   5715         for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5716             queue = RX_QUEUE(unit, i);
   5717             queue->burst = burst;
   5718             queue->tokens = burst;
   5719         }
   5720     } else {
   5721         queue = RX_QUEUE(unit, cos);
   5722         queue->burst = burst;
   5723         queue->tokens = burst;
   5724     }
   5725 
   5726 #if defined(BCM_FIREBOLT2_SUPPORT) || defined(BCM_TRX_SUPPORT)
   5727     if (RX_IS_LOCAL(unit) && SOC_UNIT_VALID(unit)) {
   5728         if (soc_feature(unit, soc_feature_packet_rate_limit)) {
   5729 #ifdef BCM_MONTEREY_SUPPORT
   5730              if (SOC_IS_MONTEREY(unit)) {
   5731                 if (cos == BCM_RX_COS_ALL) {
   5732                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5733                         BCM_IF_ERROR_RETURN
   5734                             (bcm_mn_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5735                                                         i, burst));
   5736                     }
   5737                 } else {
   5738                     BCM_IF_ERROR_RETURN
   5739                         (bcm_mn_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5740                                                     burst));
   5741                 }
   5742                 return BCM_E_NONE;
   5743             }
   5744 #endif
   5745 #ifdef BCM_APACHE_SUPPORT
   5746              if (SOC_IS_APACHE(unit)) {
   5747                 if (cos == BCM_RX_COS_ALL) {
   5748                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5749                         BCM_IF_ERROR_RETURN
   5750                             (bcm_ap_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5751                                                         i, burst));
   5752                     }
   5753                 } else {
   5754                     BCM_IF_ERROR_RETURN
   5755                         (bcm_ap_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5756                                                     burst));
   5757                 }
   5758                 return BCM_E_NONE;
   5759             }
   5760 #endif
   5761 #ifdef BCM_TOMAHAWK3_SUPPORT
   5762             if (SOC_IS_TOMAHAWK3(unit)) {
   5763                 if (cos == BCM_RX_COS_ALL) {
   5764                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5765                         BCM_IF_ERROR_RETURN
   5766                             (bcm_th3_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5767                                                         i, burst));
   5768                     }
   5769                 } else {
   5770                     BCM_IF_ERROR_RETURN
   5771                         (bcm_th3_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5772                                                     burst));
   5773                 }
   5774                 return BCM_E_NONE;
   5775             } else
   5776 #endif /* BCM_TOMAHAWK3_SUPPORT */
   5777 #ifdef BCM_TOMAHAWK_SUPPORT
   5778             if (SOC_IS_TOMAHAWKX(unit)) {
   5779                 if (cos == BCM_RX_COS_ALL) {
   5780                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5781                         BCM_IF_ERROR_RETURN
   5782                             (bcm_th_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5783                                                         i, burst));
   5784                     }
   5785                 } else {
   5786                     BCM_IF_ERROR_RETURN
   5787                         (bcm_th_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5788                                                     burst));
   5789                 }
   5790                 return BCM_E_NONE;
   5791             } else 
   5792 #endif /* BCM_TOMAHAWK_SUPPORT */
   5793 #ifdef BCM_TRIDENT3_SUPPORT
   5794                 if (SOC_IS_TRIDENT3X(unit)) {
   5795 #ifdef BCM_HELIX5_SUPPORT
   5796                     if (SOC_IS_HELIX5(unit)) {
   5797                         if (cos == BCM_RX_COS_ALL) {
   5798                             for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5799                                 BCM_IF_ERROR_RETURN
   5800                                     (bcm_hx5_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5801                                                                  i, burst));
   5802                             }
   5803                         } else {
   5804                             BCM_IF_ERROR_RETURN
   5805                                 (bcm_hx5_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5806                                                              burst));
   5807                         }
   5808                         return BCM_E_NONE;
   5809                     } else
   5810 #endif
   5811                     {
   5812                         if (cos == BCM_RX_COS_ALL) {
   5813                             for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5814                                 BCM_IF_ERROR_RETURN
   5815                                     (bcm_td3_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5816                                                                  i, burst));
   5817                             }
   5818                         } else {
   5819                             BCM_IF_ERROR_RETURN
   5820                                 (bcm_td3_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5821                                                              burst));
   5822                         }
   5823                         return BCM_E_NONE;
   5824                     }
   5825                 } else
   5826 #endif /* BCM_TRIDENT3_SUPPORT */
   5827 #ifdef BCM_TRIDENT_SUPPORT
   5828             if (SOC_IS_TD2_TT2(unit)) {
   5829 #ifdef BCM_TRIDENT2_SUPPORT
   5830                 if (cos == BCM_RX_COS_ALL) {
   5831                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5832                         BCM_IF_ERROR_RETURN
   5833                             (bcm_td2_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5834                                                         i, burst));
   5835                     }
   5836                 } else {
   5837                     BCM_IF_ERROR_RETURN
   5838                         (bcm_td2_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5839                                                     burst));
   5840                 }
   5841                 return BCM_E_NONE;
   5842 #else
   5843                 return BCM_E_UNAVAIL;
   5844 #endif
   5845             } else 
   5846             if (SOC_IS_TD_TT(unit)) {
   5847                 if (cos == BCM_RX_COS_ALL) {
   5848                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5849                         BCM_IF_ERROR_RETURN
   5850                             (bcm_td_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5851                                                         i, burst));
   5852                     }
   5853                 } else {
   5854                     BCM_IF_ERROR_RETURN
   5855                         (bcm_td_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5856                                                     burst));
   5857                 }
   5858                 return BCM_E_NONE;
   5859             }
   5860 #endif /* BCM_TRIDENT_SUPPORT */
   5861 #ifdef BCM_TRIUMPH3_SUPPORT
   5862             if (SOC_IS_TRIUMPH3(unit)) {
   5863                 if (cos == BCM_RX_COS_ALL) {
   5864                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5865                         BCM_IF_ERROR_RETURN
   5866                             (bcm_tr3_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5867                                                         i, burst));
   5868                     }
   5869                 } else {
   5870                     BCM_IF_ERROR_RETURN
   5871                         (bcm_tr3_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5872                                                     burst));
   5873                 }
   5874                 return BCM_E_NONE;
   5875             }
   5876 #endif /* BCM_TRIUMPH3_SUPPORT */
   5877 #ifdef BCM_TRIUMPH2_SUPPORT
   5878             if (SOC_IS_TRIUMPH2(unit) || SOC_IS_APOLLO(unit) || 
   5879                 SOC_IS_VALKYRIE2(unit)) {
   5880                 if (cos == BCM_RX_COS_ALL) {
   5881                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5882                         BCM_IF_ERROR_RETURN
   5883                             (bcm_tr2_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5884                                                         i, burst));
   5885                     }
   5886                 } else {
   5887                     BCM_IF_ERROR_RETURN
   5888                         (bcm_tr2_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5889                                                     burst));
   5890                 }
   5891                 return BCM_E_NONE;
   5892             }
   5893 #endif /* BCM_TRIUMPH2_SUPPORT */
   5894 #ifdef BCM_KATANA_SUPPORT
   5895              if (SOC_IS_KATANA(unit)) {
   5896                 if (cos == BCM_RX_COS_ALL) {
   5897                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5898                         BCM_IF_ERROR_RETURN
   5899                             (bcm_kt_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5900                                                         i, burst));
   5901                     }
   5902                 } else {
   5903                     BCM_IF_ERROR_RETURN
   5904                         (bcm_kt_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5905                                                     burst));
   5906                 }
   5907                 return BCM_E_NONE;
   5908             }
   5909 #endif
   5910 #ifdef BCM_KATANA2_SUPPORT
   5911              if (SOC_IS_KATANA2(unit)) {
   5912                 if (cos == BCM_RX_COS_ALL) {
   5913                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5914                         BCM_IF_ERROR_RETURN
   5915                             (bcm_kt2_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5916                                                         i, burst));
   5917                     }
   5918                 } else {
   5919                     BCM_IF_ERROR_RETURN
   5920                         (bcm_kt2_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5921                                                     burst));
   5922                 }
   5923                 return BCM_E_NONE;
   5924             }
   5925 #endif
   5926 #ifdef BCM_HURRICANE2_SUPPORT
   5927             if (SOC_IS_HURRICANE2(unit) || SOC_IS_GREYHOUND(unit) ||
   5928                 SOC_IS_HURRICANE3(unit) || SOC_IS_GREYHOUND2(unit)) {
   5929                 if (cos == BCM_RX_COS_ALL) {
   5930                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5931                         BCM_IF_ERROR_RETURN
   5932                             (bcm_hr2_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5933                                                         i, burst));
   5934                     }
   5935                 } else {
   5936                     BCM_IF_ERROR_RETURN
   5937                         (bcm_hr2_cosq_port_burst_set(unit, CMIC_PORT(unit), cos,
   5938                                                     burst));
   5939                 }
   5940                 return BCM_E_NONE;
   5941             }
   5942 #endif
   5943 #ifdef BCM_TRX_SUPPORT
   5944             if (SOC_IS_TRX(unit)) { 
   5945 #ifdef BCM_HURRICANE1_SUPPORT
   5946                 if (SOC_IS_HURRICANE(unit)) {
   5947                     if (cos >= NUM_CPU_COSQ(unit)) {
   5948                         return BCM_E_PARAM;
   5949                     }
   5950                 } else
   5951 #endif
   5952                 {
   5953                     if (cos == BCM_RX_COS_ALL) {
   5954                         for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5955                             BCM_IF_ERROR_RETURN
   5956                                 (bcm_tr_cosq_port_burst_set(unit, 
   5957                                          CMIC_PORT(unit), i, burst));
   5958                         }
   5959                     } else {
   5960                         BCM_IF_ERROR_RETURN
   5961                             (bcm_tr_cosq_port_burst_set(unit, 
   5962                                          CMIC_PORT(unit), cos, burst));
   5963                     }
   5964                 }
   5965                 return BCM_E_NONE;
   5966             }
   5967 #endif /* BCM_TRX_SUPPORT */
   5968 #ifdef BCM_FIREBOLT2_SUPPORT
   5969             if (SOC_IS_FIREBOLT2(unit)) {
   5970                 if (cos == BCM_RX_COS_ALL) {
   5971                     for (i = 0; i <= RX_QUEUE_MAX(unit); i++) {
   5972                         BCM_IF_ERROR_RETURN
   5973                             (bcm_fb2_cosq_port_burst_set(unit,
   5974                                                          CMIC_PORT(unit),
   5975                                                          i, burst));
   5976                     }
   5977                 } else {
   5978                     BCM_IF_ERROR_RETURN
   5979                         (bcm_fb2_cosq_port_burst_set(unit, CMIC_PORT(unit),
   5980                                                      cos, burst));
   5981                 }
   5982                 return BCM_E_NONE;
   5983             }
   5984 #endif /* BCM_FIREBOLT2_SUPPORT */
   5985         }
   5986     }
   5987 #endif /* BCM_FIREBOLT2_SUPPORT || BCM_TRX_SUPPORT */
   5988 
   5989     return BCM_E_NONE;
   5990 }
   5991 
   5992 int
   5993 bcm_esw_rx_cos_burst_get(int unit, int cos, int *burst)
   5994 {
   5995     if (!RX_INIT_DONE(unit)) {
   5996         return BCM_E_INIT;
   5997     }
   5998 
   5999     if ( (cos < 0) || (cos > RX_QUEUE_MAX(unit))) {
   6000         return BCM_E_PARAM;
   6001     }
   6002 
   6003     return (_bcm_common_rx_cos_burst_get(unit, cos, burst));
   6004 }
   6005 
   6006 int
   6007 bcm_esw_rx_cos_max_len_set(int unit, int cos, int max_q_len)
   6008 {
   6009     if (!RX_INIT_DONE(unit)) {
   6010         return BCM_E_INIT;
   6011     }
   6012 
   6013     if (!LEGAL_COS(cos)) {
   6014         return BCM_E_PARAM;
   6015     }
   6016 
   6017     if (cos > RX_QUEUE_MAX(unit)) {
   6018         return BCM_E_PARAM;
   6019     }
   6020 
   6021     return (_bcm_common_rx_cos_max_len_set(unit, cos, max_q_len));
   6022 }
   6023 
   6024 int
   6025 bcm_esw_rx_cos_max_len_get(int unit, int cos, int *max_q_len)
   6026 {
   6027     if (!RX_INIT_DONE(unit)) {
   6028         return BCM_E_INIT;
   6029     }
   6030 
   6031     if ( (cos < 0) || (cos > RX_QUEUE_MAX(unit))) {
   6032         return BCM_E_PARAM;
   6033     }
   6034 
   6035     return (_bcm_common_rx_cos_max_len_get(unit, cos, max_q_len));
   6036 }
   6037 
   6038 /****************************************************************
   6039  *
   6040  * RX Control
   6041  */
   6042 
   6043 STATIC int
   6044 _bcm_esw_rx_chan_flag_set(int unit, uint32 flag, int value)
   6045 {
   6046     int chan;
   6047 
   6048     FOREACH_SETUP_CHANNEL(unit, chan) {
   6049         if (value) {
   6050             RX_CHAN_FLAGS(unit, chan) |= flag;
   6051         } else {
   6052             RX_CHAN_FLAGS(unit, chan) &= ~flag;
   6053         }
   6054     }
   6055 
   6056     return BCM_E_NONE;
   6057 }
   6058 
   6059 STATIC int
   6060 _bcm_esw_rx_chan_flag_get(int unit, uint32 flag, int *value)
   6061 {
   6062     int chan;
   6063 
   6064     FOREACH_SETUP_CHANNEL(unit, chan) {
   6065         *value = RX_CHAN_FLAGS(unit, chan) & flag;
   6066         break;
   6067     }
   6068 
   6069     return BCM_E_NONE;
   6070 }
   6071 
   6072 STATIC int
   6073 _bcm_esw_rx_user_flag_set(int unit, uint32 flag, int value)
   6074 {
   6075     if (value) {
   6076         RX_USER_FLAGS(unit) |= flag;
   6077     } else {
   6078         RX_USER_FLAGS(unit) &= ~flag;
   6079     }
   6080 
   6081     return BCM_E_NONE;
   6082 }
   6083 
   6084 
   6085 STATIC int
   6086 _bcm_esw_rx_user_flag_get(int unit, uint32 flag, int *value)
   6087 {
   6088     *value = RX_USER_FLAGS(unit) & flag;
   6089 
   6090     return BCM_E_NONE;
   6091 }
   6092 
   6093 
   6094 /*
   6095  * Function:
   6096  *      bcm_rx_control_get(int unit, bcm_rx_control_t type, int *value)
   6097  * Description:
   6098  *      Get the status of specified RX feature.
   6099  * Parameters:
   6100  *      unit - Device number
   6101  *      type - RX control parameter
   6102  *      value - (OUT) Current value of control parameter
   6103  * Return Value:
   6104  *      BCM_E_NONE
   6105  *      BCM_E_UNAVAIL - Functionality not available
   6106  */
   6107 
   6108 int
   6109 bcm_esw_rx_control_get(int unit, bcm_rx_control_t type, int *value)
   6110 {
   6111     int rv = BCM_E_UNAVAIL;
   6112 
   6113     if (!RX_INIT_DONE(unit)) {
   6114         return BCM_E_INIT;
   6115     }
   6116 
   6117     switch (type) {
   6118     case bcmRxControlCRCStrip:
   6119         rv = _bcm_esw_rx_chan_flag_get(unit, BCM_RX_F_CRC_STRIP, value);
   6120         break;
   6121     case bcmRxControlVTagStrip:
   6122         rv = _bcm_esw_rx_chan_flag_get(unit, BCM_RX_F_VTAG_STRIP, value);
   6123         break;
   6124     case bcmRxControlRateStall:
   6125         rv = _bcm_esw_rx_chan_flag_get(unit, BCM_RX_F_RATE_STALL, value);
   6126         break;
   6127     case bcmRxControlMultiDCB:
   6128         rv = _bcm_esw_rx_chan_flag_get(unit, BCM_RX_F_MULTI_DCB, value);
   6129         break;
   6130     case bcmRxControlOversizedOK:
   6131         rv = _bcm_esw_rx_chan_flag_get(unit, BCM_RX_F_OVERSIZED_OK, value);
   6132         break;
   6133     case bcmRxControlIgnoreHGHeader:
   6134         rv = _bcm_esw_rx_user_flag_get(unit, BCM_RX_F_IGNORE_HGHDR, value);
   6135         break;
   6136     case bcmRxControlIgnoreSLHeader:
   6137         rv = _bcm_esw_rx_user_flag_get(unit, BCM_RX_F_IGNORE_SLTAG, value);
   6138         break;
   6139     default:
   6140         /* unsupported flag */
   6141         break;
   6142     }
   6143     return rv;
   6144 }
   6145 
   6146 /*
   6147  * Function:
   6148  *      bcm_rx_control_set(int unit, bcm_rx_control_t type, int value)
   6149  * Description:
   6150  *      Enable/Disable specified RX feature.
   6151  * Parameters:
   6152  *      unit - Device number
   6153  *      type - RX control parameter
   6154  *      value - new value of control parameter
   6155  * Return Value:
   6156  *      BCM_E_NONE
   6157  *      BCM_E_UNAVAIL - Functionality not available
   6158  */
   6159 
   6160 int
   6161 bcm_esw_rx_control_set(int unit, bcm_rx_control_t type, int value)
   6162 {
   6163     int rv = BCM_E_UNAVAIL;
   6164 
   6165     if (!RX_INIT_DONE(unit)) {
   6166         return BCM_E_INIT;
   6167     }
   6168 
   6169     switch (type) {
   6170     case bcmRxControlCRCStrip:
   6171         rv = _bcm_esw_rx_chan_flag_set(unit, BCM_RX_F_CRC_STRIP, value);
   6172         break;
   6173     case bcmRxControlVTagStrip:
   6174         rv = _bcm_esw_rx_chan_flag_set(unit, BCM_RX_F_VTAG_STRIP, value);
   6175         break;
   6176     case bcmRxControlRateStall:
   6177         rv = _bcm_esw_rx_chan_flag_set(unit, BCM_RX_F_RATE_STALL, value);
   6178         break;
   6179     case bcmRxControlMultiDCB:
   6180         rv = _bcm_esw_rx_chan_flag_set(unit, BCM_RX_F_MULTI_DCB, value);
   6181         break;
   6182     case bcmRxControlOversizedOK:
   6183         rv = _bcm_esw_rx_chan_flag_set(unit, BCM_RX_F_OVERSIZED_OK, value);
   6184         break;
   6185     case bcmRxControlIgnoreHGHeader:
   6186         rv = _bcm_esw_rx_user_flag_set(unit, BCM_RX_F_IGNORE_HGHDR, value);
   6187         break;
   6188     case bcmRxControlIgnoreSLHeader:
   6189         rv = _bcm_esw_rx_user_flag_set(unit, BCM_RX_F_IGNORE_SLTAG, value);
   6190         break;
   6191     default:
   6192         /* unsupported flag */
   6193         break;
   6194     }
   6195     return rv;
   6196 }
   6197 
   6198 /*
   6199  * Function:
   6200  *      bcm_rx_remote_pkt_enqueue
   6201  * Purpose:
   6202  *      Enqueue a remote packet for normal RX processing
   6203  * Parameters:
   6204  *      unit          - The BCM unit in which queue the pkt is placed
   6205  *      pkt           - The packet to enqueue
   6206  * Returns:
   6207  *      BCM_E_XXX
   6208  */
   6209 
   6210 int
   6211 bcm_esw_rx_remote_pkt_enqueue(int unit, bcm_pkt_t *pkt)
   6212 {
   6213     return (_bcm_common_rx_remote_pkt_enqueue(unit, pkt));
   6214 }
   6215 
   6216 
   6217 /*
   6218  * Function:
   6219  *      bcm_esw_rx_CopyToCpu_config_t_init
   6220  * Purpose:
   6221  *      Initialize a copy-to-cpu config entry
   6222  * Parameters:
   6223  *      copyToCpu_config  - (IN) Pointer to the copy-to-cpu config structure
   6224  * Returns:
   6225  *      BCM_E_*
   6226  */
   6227 
   6228 void bcm_esw_rx_CopyToCpu_config_t_init(
   6229             bcm_rx_CopyToCpu_config_t *copyToCpu_config)
   6230 {
   6231     return;
   6232 }
   6233 
   6234 /*
   6235  * Function:
   6236  *      bcm_esw_rx_CopyToCpu_config_add
   6237  * Purpose:
   6238  *      Add a copy-to-cpu entry
   6239  * Parameters:
   6240  *      unit              - (IN) device id.
   6241  *      options           - (IN) options.
   6242  *      copyToCpu_config  - (IN) Pointer to the copy-to-cpu config structure
   6243  * Returns:
   6244  *      BCM_E_*
   6245  */
   6246 
   6247 int bcm_esw_rx_CopyToCpu_config_add(int unit, uint32 options,
   6248                                 bcm_rx_CopyToCpu_config_t *copyToCpu_config)
   6249 {
   6250     int rv = BCM_E_UNAVAIL;
   6251 
   6252 #if defined (BCM_EP_REDIRECT_VERSION_2)
   6253     if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
   6254         if (!RX_INIT_DONE(unit)) {
   6255             return BCM_E_INIT;
   6256         }
   6257 
   6258         RX_COPY_TO_CPU_LOCK(unit);
   6259         rv = bcmi_xgs5_rx_CopyToCpu_config_add(unit, options,
   6260                                 copyToCpu_config);
   6261         RX_COPY_TO_CPU_UNLOCK(unit);
   6262     }
   6263 #endif
   6264 
   6265     return rv;
   6266 }
   6267 
   6268 /*
   6269  * Function:
   6270  *      bcm_esw_rx_CopyToCpu_config_get
   6271  * Purpose:
   6272  *      Get a copy-to-cpu entry
   6273  * Parameters:
   6274  *      unit              - (IN) device id.
   6275  *      index             - (IN) Index of the entry.
   6276  *      copyToCpu_config  - (OUT) Pointer to the copy-to-cpu config structure
   6277  * Returns:
   6278  *      BCM_E_*
   6279  */
   6280 
   6281 int bcm_esw_rx_CopyToCpu_config_get(int unit, int index,
   6282                            bcm_rx_CopyToCpu_config_t *copyToCpu_config)
   6283 {
   6284 #if defined (BCM_EP_REDIRECT_VERSION_2)
   6285     if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
   6286         return bcmi_xgs5_rx_CopyToCpu_config_get(unit, index,
   6287                                                  copyToCpu_config);
   6288     }
   6289 #endif
   6290 
   6291     return BCM_E_UNAVAIL;
   6292 }
   6293 
   6294 
   6295 /*
   6296  * Function:
   6297  *      bcm_esw_rx_CopyToCpu_config_delete
   6298  * Purpose:
   6299  *      Delete a copy-to-cpu entry
   6300  * Parameters:
   6301  *      unit   - (IN) device id.
   6302  *      index  - (IN) Index of the entry to delete
   6303  * Returns:
   6304  *      BCM_E_*
   6305  */
   6306 
   6307 int bcm_esw_rx_CopyToCpu_config_delete(int unit, int index)
   6308 {
   6309     int rv = BCM_E_UNAVAIL;
   6310 
   6311 #if defined (BCM_EP_REDIRECT_VERSION_2)
   6312     if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
   6313         if (!RX_INIT_DONE(unit)) {
   6314             return BCM_E_INIT;
   6315         }
   6316 
   6317         RX_COPY_TO_CPU_LOCK(unit);
   6318         rv = bcmi_xgs5_rx_CopyToCpu_config_delete(unit, index);
   6319         RX_COPY_TO_CPU_UNLOCK(unit);
   6320     }
   6321 #endif
   6322 
   6323     return rv;
   6324 }
   6325 
   6326 /*
   6327  * Function:
   6328  *      bcm_esw_rx_CopyToCpu_config_get_all
   6329  * Purpose:
   6330  *      Retrieve muultiple copy-to-cpu entries
   6331  * Parameters:
   6332  *      unit              - (IN) device id.
   6333  *      entries_max       - (IN) Max entries to retrieve
   6334  *      copyToCpu_config  - (OUT) Pointer to the copy-to-cpu config structure
   6335  *      entries_count     - (OUT) Number of entries actually retrieved
   6336  * Returns:
   6337  *      BCM_E_*
   6338  */
   6339 
   6340 int bcm_esw_rx_CopyToCpu_config_get_all(int unit, int entries_max,
   6341                                  bcm_rx_CopyToCpu_config_t *copyToCpu_config,
   6342                                  int *entries_count)
   6343 {
   6344 #if defined (BCM_EP_REDIRECT_VERSION_2)
   6345     if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
   6346         return bcmi_xgs5_rx_CopyToCpu_config_get_all(unit, entries_max,
   6347                                  copyToCpu_config, entries_count);
   6348     }
   6349 #endif
   6350     return BCM_E_UNAVAIL;
   6351 }
   6352 
   6353 /*
   6354  * Function:
   6355  *      bcm_esw_rx_CopyToCpu_config_delete_all
   6356  * Purpose:
   6357  *      Delete all copy-to-cpu entries configured
   6358  * Parameters:
   6359  *      unit              - (IN) device id.
   6360  * Returns:
   6361  *      BCM_E_*
   6362  */
   6363 
   6364 int bcm_esw_rx_CopyToCpu_config_delete_all(int unit)
   6365 {
   6366     int rv = BCM_E_UNAVAIL;
   6367 
   6368 #if defined (BCM_EP_REDIRECT_VERSION_2)
   6369     if(soc_feature(unit, soc_feature_ep_redirect_v2)) {
   6370         if (!RX_INIT_DONE(unit)) {
   6371             return BCM_E_INIT;
   6372         }
   6373 
   6374         RX_COPY_TO_CPU_LOCK(unit);
   6375         rv = bcmi_xgs5_rx_CopyToCpu_config_delete_all(unit);
   6376         RX_COPY_TO_CPU_UNLOCK(unit);
   6377     }
   6378 #endif
   6379 
   6380     return rv;
   6381 }
   6382 
   6383 
   6384 #if defined(BROADCOM_DEBUG)
   6385 
   6386 /*
   6387  * Function:
   6388  *      bcm_rx_show
   6389  * Purpose:
   6390  *      Show RX information for the specified device.
   6391  * Parameters:
   6392  *      unit - StrataSwitch unit number.
   6393  * Returns:
   6394  *      Nothing.
   6395  */
   6396 
   6397 int
   6398 bcm_esw_rx_show(int unit)
   6399 {
   6400     return _bcm_common_rx_show(unit);
   6401 }
   6402 
   6403 #endif  /* BROADCOM_DEBUG */