algo_rates.h (6224B)
1 /** 2 * \file algo/rate/algo_rates.h 3 * 4 * Internal DNX Shapers rates APIs 5 */ 6 /* 7 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 8 * 9 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 10 */ 11 12 #ifndef __ALGO_RATES_H_INCLUDED__ 13 #define __ALGO_RATES_H_INCLUDED__ 14 15 #ifndef BCM_DNX_SUPPORT 16 #error "This file is for use by DNX (JR2) family only!" 17 #endif 18 19 /* 20 * Includes 21 * { 22 */ 23 24 #include <shared/shrextend/shrextend_error.h> 25 26 /* 27 * } 28 */ 29 30 /* 31 * Typedefs 32 * { 33 */ 34 35 /* 36 * \brief 37 * Shaper rate is composed from credit and interval. 38 * When converting a rate to credit and interval, needs to specify 39 * the HW boundaries for them. 40 */ 41 typedef struct 42 { 43 /** Minimum value for credit */ 44 uint32 credit_min; 45 /** Maximum value for credit */ 46 uint32 credit_max; 47 /** Minimum value for interval */ 48 uint32 interval_min; 49 /** Maximum value for interval */ 50 uint32 interval_max; 51 } dnx_algo_rates_shaper_bounds_t; 52 53 /* 54 * } 55 */ 56 57 /* 58 * Functions: 59 * { 60 */ 61 62 /** 63 * \brief - Convert a rate given in Kbits/sec units to an interval 64 * between 2 consecutive credits in device clocks. 65 * 66 * The conversion is done according to: 67 * Credit [Kbits] * Num_of_clocks_in_sec [clocks/sec] 68 * Rate [Kbits/Sec] = ------------------------------------------------------------- 69 * interval_between_credits_in_clocks [clocks] 70 * \param [in] unit - 71 * The unit id. 72 * \param [in] rate - 73 * The rate [KBits/Sec]. 74 * \param [in] credit - 75 * The credit size [Bytes]. 76 * \param [out] interval - 77 * Interval between credits [clocks]. 78 * 79 * \note 80 * Due to rounding issues we don't actually divide the credit 81 * size by 1000 to get size in KBits. Instead we divide 82 * the ticks parameter (which is much bigger) by 1000. 83 * 84 * \see - None 85 */ 86 shr_error_e dnx_algo_rates_kbits_per_sec_to_clocks( 87 int unit, 88 uint32 rate, 89 uint32 credit, 90 uint32 *interval); 91 92 /** 93 * \brief - 94 * Convert an interval between 2 consecutive credits given in 95 * device clocks to rate in Kbits/sec units. 96 * 97 * The conversion is done according to: 98 * Credit [Kbits] * Num_of_clocks_in_sec [clocks/sec] 99 * Rate [Kbits/Sec] = ------------------------------------------------------------- 100 * interval_between_credits_in_clocks [clocks] 101 * \param [in] unit - 102 * The unit id. 103 * \param [in] interval - 104 * Interval between credits [clocks]. 105 * \param [in] credit - 106 * The credit size [Bytes]. 107 * \param [out] rate - 108 * The rate [KBits/Sec]. 109 * \note 110 * For rounding issues we don't actually divide the credit 111 * size by 1000 to get size in KBits. Instead we divide 112 * the ticks parameter (which is much bigger) by 1000. 113 * \see - None 114 */ 115 shr_error_e dnx_algo_rates_clocks_to_kbits_per_sec( 116 int unit, 117 uint32 interval, 118 uint32 credit, 119 uint32 *rate); 120 121 /** 122 * \brief 123 * The shaper rate is determind by 'credit' and 'interval': 124 * 125 * Credit [Bytes] * Num_of_clocks_in_sec [Kclocks/sec] 126 * Rate [KBytes/Sec] = ----------------------------------------------------- 127 * Interval_between_credits_in_clocks [clocks] 128 * 129 * This function converts shaper rate given in kbits_per_sec to the credit 130 * and interval that compose it: 131 * 1. interval: Time interval to add the credit value to the shaper balance. 132 * 2. credit: Credit value to add to the shaper balance. 133 * 134 * \param [in] unit - 135 * The unit number. 136 * \param [in] shaper_rate - 137 * The shaper's max rate [KBytes/Sec]. 138 * \param [in] shaper_bounds - 139 * Shpaer's params boundaries (HW bounds). 140 * \param [in] interval_resolution - 141 * Clocks resolution of the interval param [clocks]. 142 * \param [in] credit_resolution - 143 * Bytes resolution of the credit param [Bytes]. 144 * \param [out] shaper_interval - 145 * The shaper's interval part [clocks*interval_resolution]. 146 * This is the value that should be set to HW. 147 * \param [out] shaper_credit - 148 * The shaper's credit part [Bytes]. 149 * This is the value that should be set to HW. 150 * \retval 151 * See \ref shr_error_e 152 * \remark 153 * * Pay attention to the [units] of each param. 154 * * The returned shaper_interval is in interval_resolution units resolution. 155 * \see 156 * None. 157 */ 158 shr_error_e dnx_algo_rates_rate_to_credit_interval( 159 int unit, 160 uint32 shaper_rate, 161 dnx_algo_rates_shaper_bounds_t * shaper_bounds, 162 uint32 interval_resolution, 163 uint32 credit_resolution, 164 uint32 *shaper_interval, 165 uint32 *shaper_credit); 166 167 /** 168 * \brief 169 * The shaper rate is determind by 'credit' and 'interval': 170 * 171 * Credit [Bytes] * Num_of_clocks_in_sec [Kclocks/sec] 172 * Rate [KBytes/Sec] = ----------------------------------------------------- 173 * Interval_between_credits_in_clocks [clocks] 174 * 175 * This function converts credit and interval to a rate in kbits_per_sec. 176 * 1. interval: Time interval to add the credit value to the shaper balance. 177 * 2. credit: Credit value to add to the shaper balance. 178 * 179 * \param [in] unit - 180 * The unit number. 181 * \param [in] credit_resolution - 182 * Bytes resolution of the credit param [Bytes]. 183 * \param [in] interval_resolution - 184 * Clocks resolution of the interval param [clocks]. 185 * \param [in] shaper_interval - 186 * The shaper's interval part [clocks]. 187 * This is the value that retreived from HW. 188 * \param [in] shaper_credit - 189 * The shaper's credit part [Bytes]. 190 * This is the value that retreived from HW. 191 * \param [out] shaper_rate - 192 * The shaper's max rate [KBytes/Sec]. 193 * \retval 194 * See \ref shr_error_e 195 * \remark 196 * * Pay attention to the [units] of each param. 197 * * The actual interval that will be used to compute the rate is 198 * shaper_interval*interval_resolution. 199 * \see 200 * None. 201 */ 202 shr_error_e dnx_algo_rates_credit_interval_to_rate( 203 int unit, 204 uint32 credit_resolution, 205 uint32 interval_resolution, 206 uint32 shaper_interval, 207 uint32 shaper_credit, 208 uint32 *shaper_rate); 209 210 /* 211 * } 212 */ 213 214 #endif /* __ALGO_RATES_H_INCLUDED__ */