31 #define SSE2_QOS_DEBUG_ERROR(msg, args...) \ 32 fformat(stderr, msg "\n", ##args); 34 #define SSE2_QOS_DEBUG_INFO(msg, args...) \ 35 fformat(stderr, msg "\n", ##args); 38 #define SSE2_QOS_TR_ERR(TpParms...) 42 #define SSE2_QOS_TR_INFO(TpParms...) 45 #define MIN(x,y) (((x)<(y))?(x):(y)) 49 #define MAX(x,y) (((x)>(y))?(x):(y)) 52 #define IPE_POLICER_FULL_WRITE_REQUEST_M40AH_OFFSET 0 53 #define IPE_POLICER_FULL_WRITE_REQUEST_M40AH_MASK 8 54 #define IPE_POLICER_FULL_WRITE_REQUEST_M40AH_SHIFT 24 56 #define IPE_POLICER_FULL_WRITE_REQUEST_TYPE_OFFSET 2 57 #define IPE_POLICER_FULL_WRITE_REQUEST_TYPE_MASK 2 58 #define IPE_POLICER_FULL_WRITE_REQUEST_TYPE_SHIFT 10 60 #define IPE_POLICER_FULL_WRITE_REQUEST_CMD_OFFSET 3 61 #define IPE_POLICER_FULL_WRITE_REQUEST_CMD_MASK 2 62 #define IPE_POLICER_FULL_WRITE_REQUEST_CMD_SHIFT 0 64 #define IPE_POLICER_FULL_WRITE_REQUEST_M40AL_OFFSET 4 65 #define IPE_POLICER_FULL_WRITE_REQUEST_M40AL_MASK 32 66 #define IPE_POLICER_FULL_WRITE_REQUEST_M40AL_SHIFT 0 68 #define IPE_POLICER_FULL_WRITE_REQUEST_RFC_OFFSET 8 69 #define IPE_POLICER_FULL_WRITE_REQUEST_RFC_MASK 2 70 #define IPE_POLICER_FULL_WRITE_REQUEST_RFC_SHIFT 30 72 #define IPE_POLICER_FULL_WRITE_REQUEST_AN_OFFSET 8 73 #define IPE_POLICER_FULL_WRITE_REQUEST_AN_MASK 1 74 #define IPE_POLICER_FULL_WRITE_REQUEST_AN_SHIFT 29 76 #define IPE_POLICER_FULL_WRITE_REQUEST_REXP_OFFSET 8 77 #define IPE_POLICER_FULL_WRITE_REQUEST_REXP_MASK 4 78 #define IPE_POLICER_FULL_WRITE_REQUEST_REXP_SHIFT 22 80 #define IPE_POLICER_FULL_WRITE_REQUEST_ARM_OFFSET 9 81 #define IPE_POLICER_FULL_WRITE_REQUEST_ARM_MASK 11 82 #define IPE_POLICER_FULL_WRITE_REQUEST_ARM_SHIFT 11 84 #define IPE_POLICER_FULL_WRITE_REQUEST_PRM_OFFSET 10 85 #define IPE_POLICER_FULL_WRITE_REQUEST_PRM_MASK 11 86 #define IPE_POLICER_FULL_WRITE_REQUEST_PRM_SHIFT 0 88 #define IPE_POLICER_FULL_WRITE_REQUEST_CBLE_OFFSET 12 89 #define IPE_POLICER_FULL_WRITE_REQUEST_CBLE_MASK 5 90 #define IPE_POLICER_FULL_WRITE_REQUEST_CBLE_SHIFT 27 92 #define IPE_POLICER_FULL_WRITE_REQUEST_CBLM_OFFSET 12 93 #define IPE_POLICER_FULL_WRITE_REQUEST_CBLM_MASK 7 94 #define IPE_POLICER_FULL_WRITE_REQUEST_CBLM_SHIFT 20 96 #define IPE_POLICER_FULL_WRITE_REQUEST_EBLE_OFFSET 13 97 #define IPE_POLICER_FULL_WRITE_REQUEST_EBLE_MASK 5 98 #define IPE_POLICER_FULL_WRITE_REQUEST_EBLE_SHIFT 15 100 #define IPE_POLICER_FULL_WRITE_REQUEST_EBLM_OFFSET 14 101 #define IPE_POLICER_FULL_WRITE_REQUEST_EBLM_MASK 7 102 #define IPE_POLICER_FULL_WRITE_REQUEST_EBLM_SHIFT 8 104 #define IPE_POLICER_FULL_WRITE_REQUEST_CB_OFFSET 16 105 #define IPE_POLICER_FULL_WRITE_REQUEST_CB_MASK 31 106 #define IPE_POLICER_FULL_WRITE_REQUEST_CB_SHIFT 0 108 #define IPE_POLICER_FULL_WRITE_REQUEST_EB_OFFSET 20 109 #define IPE_POLICER_FULL_WRITE_REQUEST_EB_MASK 31 110 #define IPE_POLICER_FULL_WRITE_REQUEST_EB_SHIFT 0 112 #define IPE_RFC_RFC2697 0x00000000 113 #define IPE_RFC_RFC2698 0x00000001 114 #define IPE_RFC_RFC4115 0x00000002 115 #define IPE_RFC_MEF5CF1 0x00000003 120 #define SSE2_QOS_POLICER_FIXED_PKT_SIZE 256 123 #define SSE2_QOS_POL_TICKS_PER_SEC 1000LL 128 #define SSE2_QOS_POL_DEF_BURST_BYTE 100 134 #define SSE2_QOS_POL_MIN_BURST_BYTE 9*1024 141 #define SSE2_QOS_POL_ALLOW_NEGATIVE 1 145 #define SSE2_QOS_POL_COMM_BKT_MAX \ 146 (1<<IPE_POLICER_FULL_WRITE_REQUEST_CB_MASK) 147 #define SSE2_QOS_POL_EXTD_BKT_MAX \ 148 (1<<IPE_POLICER_FULL_WRITE_REQUEST_EB_MASK) 150 #define SSE2_QOS_POL_RATE_EXP_SIZE \ 151 (IPE_POLICER_FULL_WRITE_REQUEST_REXP_MASK) 152 #define SSE2_QOS_POL_RATE_EXP_MAX ((1<<SSE2_QOS_POL_RATE_EXP_SIZE) - 1) 153 #define SSE2_QOS_POL_AVG_RATE_MANT_SIZE \ 154 (IPE_POLICER_FULL_WRITE_REQUEST_ARM_MASK) 155 #define SSE2_QOS_POL_AVG_RATE_MANT_MAX \ 156 ((1<< SSE2_QOS_POL_AVG_RATE_MANT_SIZE) - 1) 157 #define SSE2_QOS_POL_AVG_RATE_MAX \ 158 (SSE2_QOS_POL_AVG_RATE_MANT_MAX << \ 159 SSE2_QOS_POL_RATE_EXP_MAX) 161 #define SSE2_QOS_POL_PEAK_RATE_MANT_SIZE \ 162 (IPE_POLICER_FULL_WRITE_REQUEST_PRM_MASK) 163 #define SSE2_QOS_POL_PEAK_RATE_MANT_MAX \ 164 ((1<<SSE2_QOS_POL_PEAK_RATE_MANT_SIZE) - 1) 165 #define SSE2_QOS_POL_PEAK_RATE_MAX \ 166 (SSE2_QOS_POL_PEAK_RATE_MANT_MAX << \ 167 SSE2_QOS_POL_RATE_EXP_MAX) 169 #define SSE2_QOS_POL_COMM_BKT_LIMIT_MANT_SIZE \ 170 (IPE_POLICER_FULL_WRITE_REQUEST_CBLM_MASK) 171 #define SSE2_QOS_POL_COMM_BKT_LIMIT_MANT_MAX \ 172 ((1<<SSE2_QOS_POL_COMM_BKT_LIMIT_MANT_SIZE) - 1) 173 #define SSE2_QOS_POL_COMM_BKT_LIMIT_EXP_SIZE \ 174 (IPE_POLICER_FULL_WRITE_REQUEST_CBLE_MASK) 175 #define SSE2_QOS_POL_COMM_BKT_LIMIT_EXP_MAX \ 176 ((1<<SSE2_QOS_POL_COMM_BKT_LIMIT_EXP_SIZE) - 1) 177 #define SSE2_QOS_POL_COMM_BKT_LIMIT_MAX \ 178 ((u64)SSE2_QOS_POL_COMM_BKT_LIMIT_MANT_MAX << \ 179 (u64)SSE2_QOS_POL_COMM_BKT_LIMIT_EXP_MAX) 181 #define SSE2_QOS_POL_EXTD_BKT_LIMIT_MANT_SIZE \ 182 (IPE_POLICER_FULL_WRITE_REQUEST_EBLM_MASK) 183 #define SSE2_QOS_POL_EXTD_BKT_LIMIT_MANT_MAX \ 184 ((1<<SSE2_QOS_POL_EXTD_BKT_LIMIT_MANT_SIZE) - 1) 185 #define SSE2_QOS_POL_EXTD_BKT_LIMIT_EXP_SIZE \ 186 (IPE_POLICER_FULL_WRITE_REQUEST_EBLE_MASK) 187 #define SSE2_QOS_POL_EXTD_BKT_LIMIT_EXP_MAX \ 188 ((1<<SSE2_QOS_POL_EXTD_BKT_LIMIT_EXP_SIZE) - 1) 189 #define SSE2_QOS_POL_EXT_BKT_LIMIT_MAX \ 190 ((u64)SSE2_QOS_POL_EXTD_BKT_LIMIT_MANT_MAX << \ 191 (u64)SSE2_QOS_POL_EXTD_BKT_LIMIT_EXP_MAX) 202 #define RATE256 (256114688000LL / 8LL / SSE2_QOS_POL_TICKS_PER_SEC) 203 #define RATE128 (128057344000LL / 8LL / SSE2_QOS_POL_TICKS_PER_SEC) 204 #define RATE64 ( 64028672000LL / 8LL / SSE2_QOS_POL_TICKS_PER_SEC) 206 #define RATE_OVER256_UNIT 8LL 207 #define RATE_128TO256_UNIT 4LL 208 #define RATE_64TO128_UNIT 2LL 217 if (denominator == 0)
227 *rounded_value = ((numerator + (denominator >> 1)) / denominator);
231 *rounded_value = (numerator / denominator);
232 if ((*rounded_value * denominator) < numerator)
239 *rounded_value = (numerator / denominator);
256 u64 numer, denom, rnd_value;
283 cir_hw = (
u32) rnd_value;
294 eir_hw = (
u32) rnd_value;
299 "max supported value (%u)", cir_hw,
308 "max supported value (%u). Capping it to the max. " 309 "supported value", eir_hw,
318 if ((cfg->
rb.
kbps.cir_kbps == 0) && cfg->
rb.
kbps.cb_bytes)
325 if ((cfg->
rb.
kbps.eir_kbps == 0) &&
333 if (cfg->
rb.
kbps.eir_kbps &&
357 u8 * exp,
u32 * mant)
368 while (temp_exp <= max_exp_value)
370 if (temp_mant <= max_mant_value)
379 temp_mant = rnd_value;
382 if (temp_exp > max_exp_value)
388 temp_mant = max_mant_value;
392 *mant = (
u32) temp_mant;
404 u32 cir_hw, eir_hw, hi_mant, hi_rate, cir_rnded, eir_rnded, eir_kbps;
405 u64 numer, denom, rnd_value;
419 (
"Rounding error, rate: %d kbps, rounding_type: %d",
424 cir_hw = (
u32) rnd_value;
426 if (cfg->
rb.
kbps.cir_kbps && (cir_hw == 0))
440 eir_kbps = cfg->
rb.
kbps.cir_kbps;
444 eir_kbps = cfg->
rb.
kbps.eir_kbps - cfg->
rb.
kbps.cir_kbps;
448 eir_kbps = cfg->
rb.
kbps.eir_kbps;
451 numer = (
u64) eir_kbps;
457 (
"Rounding error, rate: %d kbps, rounding_type: %d", eir_kbps,
462 eir_hw = (
u32) rnd_value;
464 if (eir_kbps && (eir_hw == 0))
484 if ((cir_hw == 0) && (eir_hw == 0))
505 denom = (1ULL << exp);
506 if (hi_rate == eir_hw)
552 "kbps (mant: %u, exp: %u, rate: %u bytes/tick)",
557 "kbps (mant: %u, exp: %u, rate: %u bytes/tick)",
589 return (bkt_max - 1);
647 u8 * exp,
u32 * mant,
u32 * bkt_value)
649 u64 bkt_max = max_bkt_value;
654 bkt_limit_max = ((
u64) max_mant_value << (
u64) max_exp_value);
656 bkt_max =
MIN (bkt_max, bkt_limit_max);
666 if (cfg_burst > bkt_max)
669 "supported value 0x%llx bytes. Capping it to the " 670 "max", cfg_burst, bkt_max);
672 (uint) cfg_burst, (uint) bkt_max);
683 "supported value %u bytes. Rounding it up to " 696 rnd_burst = ((
u64) (*mant) << (
u64) (*exp));
698 *bkt_value = (
u32) temp_bkt_value;
706 u32 temp_mant, rate_hw;
719 rate_hw, &temp_exp, &temp_mant, &bkt_value);
721 "exp: %u, rnded: 0x%llx cb:%u bytes",
722 cfg->
rb.
kbps.cb_bytes, temp_mant, temp_exp,
723 ((
u64) temp_mant << (
u64) temp_exp), bkt_value);
744 "exp: %u, rnded: 0x%llx bytes",
756 eb_bytes = cfg->
rb.
kbps.cb_bytes + cfg->
rb.
kbps.eb_bytes;
760 eb_bytes = cfg->
rb.
kbps.eb_bytes - cfg->
rb.
kbps.cb_bytes;
764 eb_bytes = cfg->
rb.
kbps.eb_bytes;
772 rate_hw, &temp_exp, &temp_mant, &bkt_value);
775 "exp: %u, rnded: 0x%llx eb:%u bytes",
776 cfg->
rb.
kbps.eb_bytes, temp_mant, temp_exp,
777 ((
u64) temp_mant << (
u64) temp_exp), bkt_value);
857 u64 numer, rnd_value = 0;
859 numer = (
u64) ((
u64) rate_pps *
864 return ((
u32) rnd_value);
870 u64 numer, rnd_value = 0;
875 numer = (
u64) ((
u64) burst_ms * (
u64) rate_kbps);
880 return ((
u32) rnd_value);
930 #if defined (INTERNAL_SS) || defined (X86) 944 return (
u64) cpu_freq;
956 u32 * extended_limit,
957 u32 * cir_bytes_per_period,
958 u32 * pir_bytes_per_period,
u32 * scale)
961 double internal_cir_bytes_per_period;
962 double internal_pir_bytes_per_period;
966 u32 __attribute__ ((unused)) orig_current_limit = *current_limit;
973 internal_cir_bytes_per_period = (double) cir_rate / period;
974 internal_pir_bytes_per_period = (double) pir_rate / period;
984 #define MAX_RATE_SHIFT 10 985 max =
MAX (*current_limit, *extended_limit);
988 scale_shift = __builtin_clz (max);
990 scale_amount = 1 << scale_shift;
991 *scale = scale_shift;
994 *current_limit = *current_limit << scale_shift;
995 *extended_limit = *extended_limit << scale_shift;
998 internal_cir_bytes_per_period =
999 internal_cir_bytes_per_period * ((double) scale_amount);
1000 internal_pir_bytes_per_period =
1001 internal_pir_bytes_per_period * ((double) scale_amount);
1005 if (internal_cir_bytes_per_period < 1.0)
1007 internal_cir_bytes_per_period = 1.0;
1009 if (internal_pir_bytes_per_period < 1.0)
1011 internal_pir_bytes_per_period = 1.0;
1014 *cir_bytes_per_period = (
u32) internal_cir_bytes_per_period;
1015 *pir_bytes_per_period = (
u32) internal_pir_bytes_per_period;
1018 #ifdef PRINT_X86_POLICE_PARAMS 1026 (((
u64) (*cir_bytes_per_period * (
u64) period)) >> *scale);
1028 printf (
"hz=%llu, cir_rate=%llu, limit=%u => " 1029 "periods-per-sec=%d usec-per-period=%d => " 1030 "scale=%d cir_BPP=%u, scaled_limit=%u => " 1031 "effective BPS=%llu, accuracy=%f\n",
1033 (
unsigned long long) hz,
1034 (
unsigned long long) cir_rate, orig_current_limit,
1037 (
u32) (1000.0 * 1000.0 / period),
1038 *scale, *cir_bytes_per_period, *current_limit,
1040 (
unsigned long long) effective_BPS,
1041 (
double) cir_rate / (
double) effective_BPS);
1058 const int BYTES_PER_KBIT = (1000 / 8);
1074 (cfg->
rb.
kbps.cb_bytes > 0xFFFFFFFF) ? 0xFFFFFFFF : cfg->
rb.
kbps.cb_bytes;
1077 (cfg->
rb.
kbps.eb_bytes > 0xFFFFFFFF) ? 0xFFFFFFFF : cfg->
rb.
kbps.eb_bytes;
1080 if ((cfg->
rb.
kbps.cir_kbps == 0) && (cfg->
rb.
kbps.cb_bytes == 0)
1081 && (cfg->
rb.
kbps.eb_bytes == 0))
1099 (
"Policer parameter validation failed -- 1R2C.");
1103 if ((cfg->
rb.
kbps.cir_kbps == 0) ||
1104 (cfg->
rb.
kbps.eir_kbps != 0) ||
1105 ((cfg->
rb.
kbps.cb_bytes == 0) && (cfg->
rb.
kbps.eb_bytes == 0)))
1128 if ((cfg->
rb.
kbps.cir_kbps == 0) || (cfg->
rb.
kbps.eir_kbps == 0)
1130 || (cfg->
rb.
kbps.cb_bytes == 0) || (cfg->
rb.
kbps.eb_bytes == 0))
1153 (
"Config parameter validation failed. RFC not supported");
1197 kbps_cfg.
rb.
kbps.cir_kbps =
1199 kbps_cfg.
rb.
kbps.eir_kbps =
1206 kbps_cfg.
rb.
kbps.eb_bytes =
1208 kbps_cfg.
rb.
kbps.eir_kbps);
1229 #if !defined (INTERNAL_SS) && !defined (X86) 1239 phys->rfc = pol_hw.
rfc;
1276 #endif // if !defined (INTERNAL_SS) && !defined (X86) 1287 #if !defined (INTERNAL_SS) && !defined (X86) 1288 hw_fmt->
rfc = (
u8) bkt->rfc;
1349 cfg->
rb.
kbps.cir_kbps = (
u32) temp_rate;
1353 cfg->
rb.
kbps.eir_kbps = (
u32) temp_rate;
1367 cfg->
rb.
kbps.eir_kbps = 0;
1385 "burst: 0x%llx bytes, eb burst: 0x%llx bytes",
1390 (uint) cfg->
rb.
kbps.cb_bytes,
1391 (uint) cfg->
rb.
kbps.eb_bytes);
1399 u64 numer, denom, rnd_value = 0;
1404 numer = (
u64) ((
u64) rate_kbps * 1000LL);
1410 return ((
u32) rnd_value);
1416 u64 numer, denom, rnd_value = 0;
1421 numer = burst_bytes * 8LL;
1422 denom = (
u64) rate_kbps;
1427 return ((
u32) rnd_value);
1473 cfg->
rb.
pps.cir_pps =
1475 cfg->
rb.
pps.eir_pps =
1479 kbps_cfg.
rb.
kbps.cir_kbps);
1482 kbps_cfg.
rb.
kbps.eir_kbps);
struct sse2_qos_pol_cfg_params_st_::@238::@240 pps
static void sse2_pol_rnd_burst_byte_fmt(u64 cfg_burst, u16 max_exp_value, u16 max_mant_value, u32 max_bkt_value, u32 rate_hw, u8 *exp, u32 *mant, u32 *bkt_value)
static void sse2_qos_convert_pol_bucket_to_hw_fmt(policer_read_response_type_st *bkt, sse2_qos_pol_hw_params_st *hw_fmt)
sse2_qos_pol_action_params_st conform_action
#define SSE2_QOS_POL_AVG_RATE_MANT_MAX
#define SSE2_QOS_POL_MIN_BURST_BYTE
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
static int sse2_pol_convert_hw_to_cfg_params(sse2_qos_pol_hw_params_st *hw, sse2_qos_pol_cfg_params_st *cfg)
#define SSE2_QOS_DEBUG_ERROR(msg, args...)
#define SSE2_QOS_DEBUG_INFO(msg, args...)
u32 pir_tokens_per_period
#define SSE2_QOS_POLICER_FIXED_PKT_SIZE
int x86_pol_compute_hw_params(sse2_qos_pol_cfg_params_st *cfg, policer_read_response_type_st *hw)
u32 sse2_qos_convert_kbps_to_pps(u32 rate_kbps)
#define SSE2_QOS_TR_INFO(TpParms...)
static int compute_policer_params(u64 hz, u64 cir_rate, u64 pir_rate, u32 *current_limit, u32 *extended_limit, u32 *cir_bytes_per_period, u32 *pir_bytes_per_period, u32 *scale)
#define SSE2_QOS_POL_TICKS_PER_SEC
static int sse2_pol_convert_cfg_burst_to_hw(sse2_qos_pol_cfg_params_st *cfg, sse2_qos_pol_hw_params_st *hw)
#define SSE2_QOS_POL_COMM_BKT_LIMIT_MANT_MAX
static int sse2_pol_convert_cfg_rates_to_hw(sse2_qos_pol_cfg_params_st *cfg, sse2_qos_pol_hw_params_st *hw)
#define RATE_128TO256_UNIT
int sse2_pol_compute_hw_params(sse2_qos_pol_cfg_params_st *cfg, sse2_qos_pol_hw_params_st *hw)
#define SSE2_QOS_POL_EXTD_BKT_LIMIT_MANT_MAX
static void sse2_qos_convert_value_to_exp_mant_fmt(u64 value, u16 max_exp_value, u16 max_mant_value, sse2_qos_round_type_en type, u8 *exp, u32 *mant)
sse2_qos_pol_action_params_st violate_action
#define SSE2_QOS_POL_COMM_BKT_LIMIT_EXP_MAX
static int sse2_qos_pol_round(u64 numerator, u64 denominator, u64 *rounded_value, sse2_qos_round_type_en round_type)
sse2_qos_pol_action_params_st exceed_action
u64 sse2_pol_get_bkt_max(u64 rate_hw, u64 bkt_max)
u32 sse2_qos_convert_burst_bytes_to_ms(u64 burst_bytes, u32 rate_kbps)
#define SSE2_QOS_POL_RATE_EXP_MAX
u64 sse2_pol_get_bkt_value(u64 rate_hw, u64 byte_value)
#define SSE2_QOS_POL_PEAK_RATE_MAX
#define SSE2_QOS_TR_ERR(TpParms...)
int sse2_pol_logical_2_physical(sse2_qos_pol_cfg_params_st *cfg, policer_read_response_type_st *phys)
#define SSE2_QOS_POL_ALLOW_NEGATIVE
#define RATE_OVER256_UNIT
#define RATE_64TO128_UNIT
#define SSE2_QOS_POL_DEF_BURST_BYTE
u32 cir_tokens_per_period
union sse2_qos_pol_cfg_params_st_::@238 rb
static int sse2_pol_convert_cfg_to_hw_params(sse2_qos_pol_cfg_params_st *cfg, sse2_qos_pol_hw_params_st *hw)
int sse2_pol_physical_2_logical(policer_read_response_type_st *phys, sse2_qos_pol_cfg_params_st *cfg)
#define SSE2_QOS_POL_AVG_RATE_MAX
u32 sse2_qos_convert_burst_ms_to_bytes(u32 burst_ms, u32 rate_kbps)
static u64 get_tsc_hz(void)
static int sse2_pol_validate_cfg_params(sse2_qos_pol_cfg_params_st *cfg)
u32 sse2_qos_convert_pps_to_kbps(u32 rate_pps)
#define SSE2_QOS_POL_EXTD_BKT_LIMIT_EXP_MAX
#define SSE2_QOS_POL_EXTD_BKT_MAX
struct sse2_qos_pol_cfg_params_st_::@238::@239 kbps
#define POLICER_TICKS_PER_PERIOD
#define SSE2_QOS_POL_COMM_BKT_MAX
f64 os_cpu_clock_frequency(void)