| 81 | } |
| 82 | |
| 83 | int |
| 84 | rte_red_config_init(struct rte_red_config *red_cfg, |
| 85 | const uint16_t wq_log2, |
| 86 | const uint16_t min_th, |
| 87 | const uint16_t max_th, |
| 88 | const uint16_t maxp_inv) |
| 89 | { |
| 90 | if (red_cfg == NULL) { |
| 91 | return -1; |
| 92 | } |
| 93 | if (max_th > RTE_RED_MAX_TH_MAX) { |
| 94 | return -2; |
| 95 | } |
| 96 | if (min_th >= max_th) { |
| 97 | return -3; |
| 98 | } |
| 99 | if (wq_log2 > RTE_RED_WQ_LOG2_MAX) { |
| 100 | return -4; |
| 101 | } |
| 102 | if (wq_log2 < RTE_RED_WQ_LOG2_MIN) { |
| 103 | return -5; |
| 104 | } |
| 105 | if (maxp_inv < RTE_RED_MAXP_INV_MIN) { |
| 106 | return -6; |
| 107 | } |
| 108 | if (maxp_inv > RTE_RED_MAXP_INV_MAX) { |
| 109 | return -7; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Initialize the RED module if not already done |
| 114 | */ |
| 115 | if (!rte_red_init_done) { |
| 116 | rte_red_rand_seed = rte_rand(); |
| 117 | rte_red_rand_val = rte_fast_rand(); |
| 118 | __rte_red_init_tables(); |
| 119 | rte_red_init_done = 1; |
| 120 | } |
| 121 | |
| 122 | red_cfg->min_th = ((uint32_t) min_th) << (wq_log2 + RTE_RED_SCALING); |
| 123 | red_cfg->max_th = ((uint32_t) max_th) << (wq_log2 + RTE_RED_SCALING); |
| 124 | red_cfg->pa_const = (2 * (max_th - min_th) * maxp_inv) << RTE_RED_SCALING; |
| 125 | red_cfg->maxp_inv = maxp_inv; |
| 126 | red_cfg->wq_log2 = wq_log2; |
| 127 | |
| 128 | return 0; |
| 129 | } |