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

latency_monitor.h (10781B)


      1 /*
      2  * 
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2020 Broadcom Inc. All rights reserved.
      7  *
      8  */
      9 
     10 #ifndef __BCM_LATENCY_MONITOR_H__
     11 #define __BCM_LATENCY_MONITOR_H__
     12 
     13 #include <bcm/types.h>
     14 
     15 /* Latency Monitor operation mode. */
     16 typedef enum bcm_latency_monitor_mode_e {
     17     bcmLatencyMonitorAccrueMode = 0,    /* Histogram data is accumulated per
     18                                            queue per bucket */
     19     bcmLatencyMonitorTimeSeriesMode = 1, /* Histogram data retains the time
     20                                            series info */
     21     bcmLatencyMonitorFlexCtrMode = 2    /* Histogram data process is controlled
     22                                            via FlexCtr APIs. When the mode is
     23                                            selected, histogram data
     24                                            configuration and counter collecting
     25                                            APIs will not be supported. */
     26 } bcm_latency_monitor_mode_t;
     27 
     28 /* Latency Monitor count mode (cut-through/store-and-Forward/All). */
     29 typedef enum bcm_latency_monitor_count_mode_e {
     30     bcmLatencyMonitorCutThrough = 0,    /* Count only cut through packets. */
     31     bcmLatencyMonitorStoreAndForward = 1, /* Count only store and forward packets. */
     32     bcmLatencyMonitorCountAll = 2       /* Count all types of packets. */
     33 } bcm_latency_monitor_count_mode_t;
     34 
     35 /* Latency Monitor status */
     36 typedef enum bcm_latency_monitor_status_e {
     37     bcmLatencyMonitorStatusUninit = 0,  /* Latency Monitor is in Uninitialized
     38                                            state. */
     39     bcmLatencyMonitorStatusIdle = 1,    /* Latency Monitor is in Idle state. */
     40     bcmLatencyMonitorStatusRunning = 2, /* Latency Monitor is in Running state. */
     41     bcmLatencyMonitorStatusError = 3    /* Latency Monitor is in Faulty state. */
     42 } bcm_latency_monitor_status_t;
     43 
     44 /* Per COSQ latency limit configuration structure */
     45 typedef struct bcm_latency_monitor_cosq_info_s {
     46     uint8 bucket_count;                 /* Number of histogram buckets for a
     47                                            given cosq. */
     48     uint8 latency_index_array[BCM_MAX_HISTOGRAM_BUCKET_COUNT-1]; /* Array of indexes in to the latency
     49                                            limit table. The indexed value is the
     50                                            upper latency limit for the
     51                                            corresponding bucket. */
     52 } bcm_latency_monitor_cosq_info_t;
     53 
     54 /* Histogram for a given cosq id. */
     55 typedef struct bcm_latency_monitor_histogram_s {
     56     uint8 histogram_size;               /* Number of histogram counters for a
     57                                            given cosq. */
     58     uint64 histogram[BCM_MAX_HISTOGRAM_BUCKET_COUNT]; /* Array of histogram counters */
     59 } bcm_latency_monitor_histogram_t;
     60 
     61 /* Latency Monitor status informations. */
     62 typedef struct bcm_latency_monitor_info_s {
     63     bcm_latency_monitor_status_t monitor_status; /* Monitor status */
     64     void *sw_buf_addr;                  /* Base address of 64 bits wide (Bit
     65                                            Field 0:27 Packet Counter, Bit field
     66                                            28:63 is Byte Counter) software ring
     67                                            buffer (Valid in Time Series Mode
     68                                            only). */
     69     uint32 sw_buf_size;                 /* Size of Software ring buffer in terms
     70                                            of 64 bit width (Valid in Time Series
     71                                            Mode only). */
     72     uint32 sw_buf_wr_idx;               /* Index in to the software ring buffer
     73                                            pointing to last counter write
     74                                            operation (Valid in Time Series Mode
     75                                            only). */
     76 } bcm_latency_monitor_info_t;
     77 
     78 /* 
     79  * User application call back function on update of counter info in
     80  * software ring buffer (Valid in TIME_SERIES mode only).
     81  */
     82 typedef int (*bcm_latency_monitor_cb)(
     83     int unit, 
     84     uint8 monitor_id, 
     85     bcm_latency_monitor_status_t monitor_status, 
     86     void *sw_buf_addr, 
     87     uint32 sw_buf_size, 
     88     uint32 sw_buf_wr_idx);
     89 
     90 /* Monitor configuration structure */
     91 typedef struct bcm_latency_monitor_config_s {
     92     bcm_latency_monitor_mode_t mode;    /* Monitor operation mode. */
     93     bcm_pbmp_t src_pbmp;                /* Ingress Port Bit Map */
     94     bcm_pbmp_t dest_pbmp;               /* Egress Port Bit Map */
     95     uint32 time_step;                   /* Time series step value in Micro Sec.
     96                                            (Min 100 ms). */
     97     bcm_latency_monitor_count_mode_t count_mode; /* cut-though or store-and-Forward or
     98                                            Count All */
     99     uint32 histogram_set_count;         /* Max number of histogram sets to
    100                                            accomodate in Software Ring Buffer
    101                                            (Minimum is 10). */
    102     bcm_latency_monitor_cb cb;          /* User callback function on
    103                                            availability of counter info in the
    104                                            software ring buffer. */
    105 } bcm_latency_monitor_config_t;
    106 
    107 /* Initialize the Monitor configuration structure. */
    108 extern void bcm_latency_monitor_config_t_init(
    109     bcm_latency_monitor_config_t *config);
    110 
    111 /* Initialize the COSQ latency limit configuration structure. */
    112 extern void bcm_latency_monitor_cosq_info_t_init(
    113     bcm_latency_monitor_cosq_info_t *config);
    114 
    115 /* Initialize the latency monitor histogram structure. */
    116 extern void bcm_latency_monitor_histogram_t_init(
    117     bcm_latency_monitor_histogram_t *histogram);
    118 
    119 /* Initialize the latency monitor info structure. */
    120 extern void bcm_latency_monitor_info_t_init(
    121     bcm_latency_monitor_info_t *monitor_info);
    122 
    123 #ifndef BCM_HIDE_DISPATCHABLE
    124 
    125 /* Initialize a latency monitor with the given configuration. */
    126 extern int bcm_latency_monitor_config_set(
    127     int unit, 
    128     uint8 monitor_id, 
    129     bcm_latency_monitor_config_t *config);
    130 
    131 /* Get configuration informations for a given Latency Monitor. */
    132 extern int bcm_latency_monitor_config_get(
    133     int unit, 
    134     uint8 monitor_id, 
    135     bcm_latency_monitor_config_t *config);
    136 
    137 /* Programs latency limit device table. */
    138 extern int bcm_latency_monitor_latency_limit_table_set(
    139     int unit, 
    140     uint8 table_size, 
    141     uint32 *latency_limit_table);
    142 
    143 /* Gets values programmed in latency limit device table. */
    144 extern int bcm_latency_monitor_latency_limit_table_get(
    145     int unit, 
    146     uint8 table_size, 
    147     uint32 *latency_limit_table);
    148 
    149 /* Configures latency upper limits of each bucket for a given COS queue. */
    150 extern int bcm_latency_monitor_cosq_config_set(
    151     int unit, 
    152     uint8 monitor_id, 
    153     uint8 cosq, 
    154     bcm_latency_monitor_cosq_info_t cosq_info);
    155 
    156 /* Gets latency upper limits of each bucket for a given COS queue. */
    157 extern int bcm_latency_monitor_cosq_config_get(
    158     int unit, 
    159     uint8 monitor_id, 
    160     uint8 cosq, 
    161     bcm_latency_monitor_cosq_info_t *cosq_info);
    162 
    163 /* Enable or Disable a given monitor. */
    164 extern int bcm_latency_monitor_enable(
    165     int unit, 
    166     uint8 monitor_id, 
    167     uint8 enable);
    168 
    169 /* Gets histogram counters for a given monitor id and cosq id. */
    170 extern int bcm_latency_monitor_histogram_get(
    171     int unit, 
    172     uint8 monitor_id, 
    173     uint8 cosq, 
    174     uint8 byte_counter_flag, 
    175     bcm_latency_monitor_histogram_t *histogram);
    176 
    177 /* For a given monitor_id, the API returns monitor status information. */
    178 extern int bcm_latency_monitor_info_get(
    179     int unit, 
    180     uint8 monitor_id, 
    181     bcm_latency_monitor_info_t *monitor_info);
    182 
    183 #endif /* BCM_HIDE_DISPATCHABLE */
    184 
    185 /* Latency Monitor information passed to the registered callback handler */
    186 typedef struct bcm_latency_monitor_cb_info_s {
    187     int monitor_id;                     /* Monitor Id. */
    188     bcm_latency_monitor_status_t monitor_status; /* Monitor Status. */
    189     void *sw_buf_addr;                  /* Base address of 64 bits wide (Bit
    190                                            Field 0:27 Packet Counter, Bit field
    191                                            28:63 is Byte Counter) software ring
    192                                            buffer. */
    193     uint32 sw_buf_size;                 /* Size of Software ring buffer in terms
    194                                            of 64 bit width. */
    195     uint32 sw_buf_wr_idx;               /* Index in to the software ring buffer
    196                                            pointing to last counter write
    197                                            operation. */
    198 } bcm_latency_monitor_cb_info_t;
    199 
    200 typedef void (*bcm_latency_monitor_callback_fn)(
    201     int unit, 
    202     bcm_latency_monitor_cb_info_t *latency_monitor_info, 
    203     void *userdata);
    204 
    205 #ifndef BCM_HIDE_DISPATCHABLE
    206 
    207 /* 
    208  * The API is used by the application to register a callback routine that
    209  * gets called by SDK when there is update of software ring buffer with
    210  * histogram data. User application implements the callback handler and
    211  * the processing in the callback handler should be minimal as the
    212  * calling thread would be blocked when this callback is invoked.
    213  */
    214 extern int bcm_latency_monitor_register(
    215     int unit, 
    216     int monitor_id, 
    217     bcm_latency_monitor_callback_fn fn, 
    218     void *user_data);
    219 
    220 /* 
    221  * The API is used by the application to unregister the callback routine
    222  * that gets called by SDK when there is update of software ring buffer
    223  * with histogram data. The API fails if the monitor is in running state.
    224  * User is expected to disable monitor before calling this API.
    225  */
    226 extern int bcm_latency_monitor_unregister(
    227     int unit, 
    228     int monitor_id, 
    229     bcm_latency_monitor_callback_fn fn);
    230 
    231 /* 
    232  * Release all the resource allocated for a given monitor (Effective only
    233  * when the monitor is in Disable/Error state).
    234  */
    235 extern int bcm_latency_monitor_destroy(
    236     int unit, 
    237     uint8 monitor_id);
    238 
    239 /* Initialize the Latency monitor subsystem. */
    240 extern int bcm_latency_monitor_init(
    241     int unit);
    242 
    243 /* Shut down the latency_monitor subsystem. */
    244 extern int bcm_latency_monitor_detach(
    245     int unit);
    246 
    247 /* Attach state counter ID to a given latency monitor ID. */
    248 extern int bcm_latency_monitor_stat_attach(
    249     int unit, 
    250     uint8 monitor_id, 
    251     uint32 stat_counter_id);
    252 
    253 /* Detach state counter ID to a given latency monitor ID. */
    254 extern int bcm_latency_monitor_stat_detach(
    255     int unit, 
    256     uint8 monitor_id);
    257 
    258 /* Attach state counter ID to a given latency monitor ID. */
    259 extern int bcm_latency_monitor_stat_id_get(
    260     int unit, 
    261     uint8 monitor_id, 
    262     uint32 *stat_counter_id);
    263 
    264 #endif /* BCM_HIDE_DISPATCHABLE */
    265 
    266 #endif /* __BCM_LATENCY_MONITOR_H__ */