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

policer.h (4174B)


      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-2020 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        policer.h
      8  * Purpose:     policer internal definitions to the BCM library.
      9  */
     10 
     11 #ifndef   _BCM_INT_DPP_POLICER_H_
     12 #define   _BCM_INT_DPP_POLICER_H_
     13 
     14 #include <bcm/policer.h>
     15 
     16 /* 
     17  * format meter id 
     18  * 0-12/14: meter/policer id 
     19  * 13/15: group (for meter) 
     20  * 14/16: core (for meter) 
     21  * 29: type 0:meter 1:ethernet-policer , 
     22  *     needed as same APIs and ID used for both meter types
     23  * Notes: 
     24  *    - meter type: has to be zero, as pointer by FP
     25  *    - meter core: currently up to two cores are supported by the macros
     26  */
     27 
     28 
     29 /* type: 0:meter 1:ethernet-policer */
     30 #define _DPP_POLICER_METER_TYPE_SHIFT(__unit)  (29)
     31 /* group: 0 or 1 */
     32 #define _DPP_POLICER_METER_GROUP_SHIFT(__unit) (SOC_IS_QUX(__unit) ? (13) : (15))
     33 /* core: 0 or 1 */
     34 #define _DPP_POLICER_METER_CORE_SHIFT(__unit)  (_DPP_POLICER_METER_GROUP_SHIFT(__unit) + 1)
     35 
     36 /* 0 -12. for meter id */
     37 #define _DPP_POLICER_METER_ID_MASK(__unit)    (_DPP_POLICER_METER_GROUP_MASK(__unit) - 1)
     38 /* 13/15 for meter group */
     39 #define _DPP_POLICER_METER_GROUP_MASK(__unit) (1 << _DPP_POLICER_METER_GROUP_SHIFT(__unit))
     40 /* 14/16 for meter core */
     41 #define _DPP_POLICER_METER_CORE_MASK(__unit)  (1 << _DPP_POLICER_METER_CORE_SHIFT(__unit))
     42 /* 29 for meter type*/
     43 #define _DPP_POLICER_METER_TYPE_MASK(__unit)  (1 << _DPP_POLICER_METER_TYPE_SHIFT(__unit))
     44 
     45 #define _DPP_POLICER_ID_TO_CORE(__unit , __meter_id)    (((__meter_id) & _DPP_POLICER_METER_CORE_MASK(__unit)) >> _DPP_POLICER_METER_CORE_SHIFT(__unit))
     46 #define _DPP_POLICER_ID_TO_GROUP(__unit , __meter_id)   (((__meter_id) & _DPP_POLICER_METER_GROUP_MASK(__unit)) >> _DPP_POLICER_METER_GROUP_SHIFT(__unit))
     47 #define _DPP_POLICER_ID_TO_METER(__unit, __meter_id)    ((__meter_id) & _DPP_POLICER_METER_ID_MASK(__unit))
     48 #define _DPP_POLICER_ID_FROM_METER_GROUP_CORE(__unit, __meter, __group, __core)   (((__core) << _DPP_POLICER_METER_CORE_SHIFT(__unit))|((__group) << _DPP_POLICER_METER_GROUP_SHIFT(__unit))|__meter)
     49 
     50 #define _DPP_POLICER_NOF_POLICERS (8)
     51 #define _DPP_POLICER_MAX_POLICER_ID (_DPP_POLICER_NOF_POLICERS - 1)
     52 #define _DPP_POLICER_MIN_POLICER_ID  (1)
     53 
     54 /* iterate over all metering cores */
     55 #define _DPP_POLICER_METER_CORES_ITER(index) \
     56     for(index = 0; index < SOC_DPP_CONFIG(unit)->meter.nof_meter_cores; index++)
     57 
     58 #define _DPP_IS_ETH_POLICER_ID(__unit, __meter)  			((__meter) & _DPP_POLICER_METER_TYPE_MASK(__unit))
     59 #define _DPP_ETH_POLICER_ID_GET(__unit, __meter) 			((__meter) & _DPP_POLICER_METER_ID_MASK(__unit))
     60 #define _DPP_ETH_POLICER_ID_SET(__unit, __meter, __core) 	((__meter) | _DPP_POLICER_METER_TYPE_MASK(__unit) | ((__core) << _DPP_POLICER_METER_CORE_SHIFT(__unit)))
     61 #define _DPP_ETH_POLICER_CORE_GET(__unit , __meter_id)    	(((__meter_id) & _DPP_POLICER_METER_CORE_MASK(__unit)) >> _DPP_POLICER_METER_CORE_SHIFT(__unit))
     62 
     63 #define _DPP_ETH_METER_ID_GET(__unit, __meter) (__meter)
     64 
     65 #define _DPP_POLICER_METER_MAX_CORE_ID(unit)                 (SOC_DPP_CONFIG(unit)->meter.nof_meter_cores - 1)
     66 #define _DPP_POLICER_METER_IS_SINGLE_CORE(unit)              (SOC_DPP_CONFIG(unit)->meter.nof_meter_cores == 1)
     67 #define _DPP_POLICER_NOF_COLORS                               4
     68 #define _DPP_POLICER_NOF_METER_ACTIONS                        4
     69 
     70 /* 
     71 * sw state for meter/policer
     72 */  
     73 
     74 
     75 /* for each bcm-policer used dpp_policers*/
     76 typedef struct _dpp_policer_info_s {
     77     bcm_policer_group_mode_t mode;
     78 } _dpp_policer_group_info_t;
     79 
     80 /* dpp policers status */
     81 
     82 typedef struct _dpp_policer_state_s {
     83     _dpp_policer_group_info_t policer_group[_DPP_POLICER_NOF_POLICERS];
     84 } _dpp_policer_state_t;
     85 
     86 
     87 #define _DPP_POLICER_MAX_KBITS_SEC_UNLIMITED (0xffffffff)
     88 
     89 
     90 /* map port to policer group */
     91 int bcm_petra_policer_port_set(
     92     int unit, 
     93     bcm_port_t port, 
     94     bcm_policer_t policer_id);
     95     
     96 /* return policer group assigned to port */
     97 int bcm_petra_policer_port_get(
     98     int unit, 
     99     bcm_port_t port, 
    100     bcm_policer_t *policer_id);
    101     
    102 extern int
    103 bcm_petra_policer_detach(int unit);
    104 
    105 #endif /* _BCM_INT_DPP_POLICER_H_ */