Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018-2021 HiSilicon Limited.
3 : : */
4 : :
5 : : #include <rte_io.h>
6 : : #include <rte_ethdev.h>
7 : :
8 : : #include "hns3_logs.h"
9 : : #include "hns3_ethdev.h"
10 : : #include "hns3_dcb.h"
11 : :
12 : : #define HNS3_SHAPER_BS_U_DEF 5
13 : : #define HNS3_SHAPER_BS_S_DEF 20
14 : : #define BW_MAX_PERCENT 100
15 : :
16 : : /*
17 : : * hns3_shaper_para_calc: calculate ir parameter for the shaper
18 : : * @ir: Rate to be config, its unit is Mbps
19 : : * @shaper_level: the shaper level. eg: port, pg, priority, queueset
20 : : * @shaper_para: shaper parameter of IR shaper
21 : : *
22 : : * the formula:
23 : : *
24 : : * IR_b * (2 ^ IR_u) * 8
25 : : * IR(Mbps) = ------------------------- * CLOCK(1000Mbps)
26 : : * Tick * (2 ^ IR_s)
27 : : *
28 : : * @return: 0: calculate successful, negative: fail
29 : : */
30 : : static int
31 : 0 : hns3_shaper_para_calc(struct hns3_hw *hw, uint32_t ir, uint8_t shaper_level,
32 : : struct hns3_shaper_parameter *shaper_para)
33 : : {
34 : : #define SHAPER_DEFAULT_IR_B 126
35 : : #define DIVISOR_CLK (1000 * 8)
36 : : #define DIVISOR_IR_B_126 (126 * DIVISOR_CLK)
37 : :
38 : 0 : const uint16_t tick_array[HNS3_SHAPER_LVL_CNT] = {
39 : : 6 * 256, /* Priority level */
40 : : 6 * 32, /* Priority group level */
41 : : 6 * 8, /* Port level */
42 : : 6 * 256 /* Qset level */
43 : : };
44 : : uint8_t ir_u_calc = 0;
45 : : uint8_t ir_s_calc = 0;
46 : : uint32_t denominator;
47 : : uint32_t ir_calc;
48 : : uint32_t tick;
49 : :
50 : : /* Calc tick */
51 [ # # ]: 0 : if (shaper_level >= HNS3_SHAPER_LVL_CNT) {
52 : 0 : hns3_err(hw,
53 : : "shaper_level(%u) is greater than HNS3_SHAPER_LVL_CNT(%d)",
54 : : shaper_level, HNS3_SHAPER_LVL_CNT);
55 : 0 : return -EINVAL;
56 : : }
57 : :
58 [ # # ]: 0 : if (ir > hw->max_tm_rate) {
59 : 0 : hns3_err(hw, "rate(%u) exceeds the max rate(%u) driver "
60 : : "supported.", ir, hw->max_tm_rate);
61 : 0 : return -EINVAL;
62 : : }
63 : :
64 : 0 : tick = tick_array[shaper_level];
65 : :
66 : : /*
67 : : * Calc the speed if ir_b = 126, ir_u = 0 and ir_s = 0
68 : : * the formula is changed to:
69 : : * 126 * 1 * 8
70 : : * ir_calc = ---------------- * 1000
71 : : * tick * 1
72 : : */
73 : 0 : ir_calc = (DIVISOR_IR_B_126 + (tick >> 1) - 1) / tick;
74 : :
75 [ # # ]: 0 : if (ir_calc == ir) {
76 : 0 : shaper_para->ir_b = SHAPER_DEFAULT_IR_B;
77 [ # # ]: 0 : } else if (ir_calc > ir) {
78 : : /* Increasing the denominator to select ir_s value */
79 [ # # ]: 0 : while (ir_calc >= ir && ir) {
80 : 0 : ir_s_calc++;
81 : 0 : ir_calc = DIVISOR_IR_B_126 / (tick * (1 << ir_s_calc));
82 : : }
83 : :
84 : 0 : shaper_para->ir_b = (ir * tick * (1 << ir_s_calc) +
85 : 0 : (DIVISOR_CLK >> 1)) / DIVISOR_CLK;
86 : : } else {
87 : : /*
88 : : * Increasing the numerator to select ir_u value. ir_u_calc will
89 : : * get maximum value when ir_calc is minimum and ir is maximum.
90 : : * ir_calc gets minimum value when tick is the maximum value.
91 : : * At the same time, value of ir_u_calc can only be increased up
92 : : * to eight after the while loop if the value of ir is equal
93 : : * to hw->max_tm_rate.
94 : : */
95 : : uint32_t numerator;
96 : : do {
97 : 0 : ir_u_calc++;
98 : 0 : numerator = DIVISOR_IR_B_126 * (1 << ir_u_calc);
99 : 0 : ir_calc = (numerator + (tick >> 1)) / tick;
100 [ # # ]: 0 : } while (ir_calc < ir);
101 : :
102 [ # # ]: 0 : if (ir_calc == ir) {
103 : 0 : shaper_para->ir_b = SHAPER_DEFAULT_IR_B;
104 : : } else {
105 : : --ir_u_calc;
106 : :
107 : : /*
108 : : * The maximum value of ir_u_calc in this branch is
109 : : * seven in all cases. Thus, value of denominator can
110 : : * not be zero here.
111 : : */
112 : 0 : denominator = DIVISOR_CLK * (1 << ir_u_calc);
113 : 0 : shaper_para->ir_b =
114 : 0 : (ir * tick + (denominator >> 1)) / denominator;
115 : : }
116 : : }
117 : :
118 : 0 : shaper_para->ir_u = ir_u_calc;
119 : 0 : shaper_para->ir_s = ir_s_calc;
120 : :
121 : 0 : return 0;
122 : : }
123 : :
124 : : static int
125 : : hns3_fill_pri_array(struct hns3_hw *hw, uint8_t *pri, uint8_t pri_id)
126 : : {
127 : : #define HNS3_HALF_BYTE_BIT_OFFSET 4
128 : 0 : uint8_t tc = hw->dcb_info.prio_tc[pri_id];
129 : :
130 : 0 : if (tc >= hw->dcb_info.num_tc)
131 : : return -EINVAL;
132 : :
133 : : /*
134 : : * The register for priority has four bytes, the first bytes includes
135 : : * priority0 and priority1, the higher 4bit stands for priority1
136 : : * while the lower 4bit stands for priority0, as below:
137 : : * first byte: | pri_1 | pri_0 |
138 : : * second byte: | pri_3 | pri_2 |
139 : : * third byte: | pri_5 | pri_4 |
140 : : * fourth byte: | pri_7 | pri_6 |
141 : : */
142 : 0 : pri[pri_id >> 1] |= tc << ((pri_id & 1) * HNS3_HALF_BYTE_BIT_OFFSET);
143 : :
144 : : return 0;
145 : : }
146 : :
147 : : static int
148 : 0 : hns3_up_to_tc_map(struct hns3_hw *hw)
149 : : {
150 : : struct hns3_cmd_desc desc;
151 : : uint8_t *pri = (uint8_t *)desc.data;
152 : : uint8_t pri_id;
153 : : int ret;
154 : :
155 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_PRI_TO_TC_MAPPING, false);
156 : :
157 [ # # ]: 0 : for (pri_id = 0; pri_id < HNS3_MAX_USER_PRIO; pri_id++) {
158 [ # # ]: 0 : ret = hns3_fill_pri_array(hw, pri, pri_id);
159 : : if (ret)
160 : : return ret;
161 : : }
162 : :
163 : 0 : return hns3_cmd_send(hw, &desc, 1);
164 : : }
165 : :
166 : : static int
167 : 0 : hns3_pg_to_pri_map_cfg(struct hns3_hw *hw, uint8_t pg_id, uint8_t pri_bit_map)
168 : : {
169 : : struct hns3_pg_to_pri_link_cmd *map;
170 : : struct hns3_cmd_desc desc;
171 : :
172 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_TO_PRI_LINK, false);
173 : :
174 : : map = (struct hns3_pg_to_pri_link_cmd *)desc.data;
175 : :
176 : 0 : map->pg_id = pg_id;
177 : 0 : map->pri_bit_map = pri_bit_map;
178 : :
179 : 0 : return hns3_cmd_send(hw, &desc, 1);
180 : : }
181 : :
182 : : static int
183 : 0 : hns3_pg_to_pri_map(struct hns3_hw *hw)
184 : : {
185 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
186 : : struct hns3_pf *pf = &hns->pf;
187 : : struct hns3_pg_info *pg_info;
188 : : int ret, i;
189 : :
190 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
191 : : return -EINVAL;
192 : :
193 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_pg; i++) {
194 : : /* Cfg pg to priority mapping */
195 : : pg_info = &hw->dcb_info.pg_info[i];
196 : 0 : ret = hns3_pg_to_pri_map_cfg(hw, i, pg_info->tc_bit_map);
197 [ # # ]: 0 : if (ret)
198 : 0 : return ret;
199 : : }
200 : :
201 : : return 0;
202 : : }
203 : :
204 : : static int
205 : 0 : hns3_qs_to_pri_map_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t pri)
206 : : {
207 : : struct hns3_qs_to_pri_link_cmd *map;
208 : : struct hns3_cmd_desc desc;
209 : :
210 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_TO_PRI_LINK, false);
211 : :
212 : : map = (struct hns3_qs_to_pri_link_cmd *)desc.data;
213 : :
214 : 0 : map->qs_id = rte_cpu_to_le_16(qs_id);
215 : 0 : map->priority = pri;
216 : 0 : map->link_vld = HNS3_DCB_QS_PRI_LINK_VLD_MSK;
217 : :
218 : 0 : return hns3_cmd_send(hw, &desc, 1);
219 : : }
220 : :
221 : : static int
222 : 0 : hns3_dcb_qs_weight_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t dwrr)
223 : : {
224 : : struct hns3_qs_weight_cmd *weight;
225 : : struct hns3_cmd_desc desc;
226 : :
227 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_WEIGHT, false);
228 : :
229 : : weight = (struct hns3_qs_weight_cmd *)desc.data;
230 : :
231 : 0 : weight->qs_id = rte_cpu_to_le_16(qs_id);
232 : 0 : weight->dwrr = dwrr;
233 : :
234 : 0 : return hns3_cmd_send(hw, &desc, 1);
235 : : }
236 : :
237 : : static int
238 : 0 : hns3_dcb_ets_tc_dwrr_cfg(struct hns3_hw *hw)
239 : : {
240 : : #define DEFAULT_TC_OFFSET 14
241 : : struct hns3_ets_tc_weight_cmd *ets_weight;
242 : : struct hns3_pg_info *pg_info;
243 : : struct hns3_cmd_desc desc;
244 : : uint8_t i;
245 : :
246 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_ETS_TC_WEIGHT, false);
247 : : ets_weight = (struct hns3_ets_tc_weight_cmd *)desc.data;
248 : :
249 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
250 : 0 : pg_info = &hw->dcb_info.pg_info[hw->dcb_info.tc_info[i].pgid];
251 : 0 : ets_weight->tc_weight[i] = pg_info->tc_dwrr[i];
252 : : }
253 : :
254 : 0 : ets_weight->weight_offset = DEFAULT_TC_OFFSET;
255 : :
256 : 0 : return hns3_cmd_send(hw, &desc, 1);
257 : : }
258 : :
259 : : static int
260 : 0 : hns3_dcb_pri_weight_cfg(struct hns3_hw *hw, uint8_t pri_id, uint8_t dwrr)
261 : : {
262 : : struct hns3_priority_weight_cmd *weight;
263 : : struct hns3_cmd_desc desc;
264 : :
265 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PRI_WEIGHT, false);
266 : :
267 : : weight = (struct hns3_priority_weight_cmd *)desc.data;
268 : :
269 : 0 : weight->pri_id = pri_id;
270 : 0 : weight->dwrr = dwrr;
271 : :
272 : 0 : return hns3_cmd_send(hw, &desc, 1);
273 : : }
274 : :
275 : : static int
276 : 0 : hns3_dcb_pg_weight_cfg(struct hns3_hw *hw, uint8_t pg_id, uint8_t dwrr)
277 : : {
278 : : struct hns3_pg_weight_cmd *weight;
279 : : struct hns3_cmd_desc desc;
280 : :
281 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_WEIGHT, false);
282 : :
283 : : weight = (struct hns3_pg_weight_cmd *)desc.data;
284 : :
285 : 0 : weight->pg_id = pg_id;
286 : 0 : weight->dwrr = dwrr;
287 : :
288 : 0 : return hns3_cmd_send(hw, &desc, 1);
289 : : }
290 : : static int
291 : 0 : hns3_dcb_pg_schd_mode_cfg(struct hns3_hw *hw, uint8_t pg_id)
292 : : {
293 : : struct hns3_cmd_desc desc;
294 : :
295 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_SCH_MODE_CFG, false);
296 : :
297 [ # # ]: 0 : if (hw->dcb_info.pg_info[pg_id].pg_sch_mode == HNS3_SCH_MODE_DWRR)
298 : 0 : desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
299 : : else
300 : 0 : desc.data[1] = 0;
301 : :
302 : 0 : desc.data[0] = rte_cpu_to_le_32(pg_id);
303 : :
304 : 0 : return hns3_cmd_send(hw, &desc, 1);
305 : : }
306 : :
307 : : static uint32_t
308 : : hns3_dcb_get_shapping_para(uint8_t ir_b, uint8_t ir_u, uint8_t ir_s,
309 : : uint8_t bs_b, uint8_t bs_s)
310 : : {
311 : : uint32_t shapping_para = 0;
312 : :
313 : : /* If ir_b is zero it means IR is 0Mbps, return zero of shapping_para */
314 : 0 : if (ir_b == 0)
315 : : return shapping_para;
316 : :
317 : : hns3_dcb_set_field(shapping_para, IR_B, ir_b);
318 : 0 : hns3_dcb_set_field(shapping_para, IR_U, ir_u);
319 : 0 : hns3_dcb_set_field(shapping_para, IR_S, ir_s);
320 : : hns3_dcb_set_field(shapping_para, BS_B, bs_b);
321 : 0 : hns3_dcb_set_field(shapping_para, BS_S, bs_s);
322 : :
323 : 0 : return shapping_para;
324 : : }
325 : :
326 : : static int
327 : 0 : hns3_dcb_port_shaper_cfg(struct hns3_hw *hw, uint32_t speed)
328 : : {
329 : : struct hns3_port_shapping_cmd *shap_cfg_cmd;
330 : : struct hns3_shaper_parameter shaper_parameter;
331 : : uint32_t shapping_para;
332 : : uint32_t ir_u, ir_b, ir_s;
333 : : struct hns3_cmd_desc desc;
334 : : int ret;
335 : :
336 : 0 : ret = hns3_shaper_para_calc(hw, speed,
337 : : HNS3_SHAPER_LVL_PORT, &shaper_parameter);
338 [ # # ]: 0 : if (ret) {
339 : 0 : hns3_err(hw, "calculate shaper parameter failed: %d", ret);
340 : 0 : return ret;
341 : : }
342 : :
343 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PORT_SHAPPING, false);
344 : : shap_cfg_cmd = (struct hns3_port_shapping_cmd *)desc.data;
345 : :
346 : 0 : ir_b = shaper_parameter.ir_b;
347 : 0 : ir_u = shaper_parameter.ir_u;
348 : 0 : ir_s = shaper_parameter.ir_s;
349 [ # # ]: 0 : shapping_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
350 : : HNS3_SHAPER_BS_U_DEF,
351 : : HNS3_SHAPER_BS_S_DEF);
352 : :
353 : 0 : shap_cfg_cmd->port_shapping_para = rte_cpu_to_le_32(shapping_para);
354 : :
355 : : /*
356 : : * Configure the port_rate and set bit HNS3_TM_RATE_VLD_B of flag
357 : : * field in hns3_port_shapping_cmd to require firmware to recalculate
358 : : * shapping parameters. And whether the parameters are recalculated
359 : : * depends on the firmware version. But driver still needs to
360 : : * calculate it and configure to firmware for better compatibility.
361 : : */
362 : 0 : shap_cfg_cmd->port_rate = rte_cpu_to_le_32(speed);
363 : 0 : hns3_set_bit(shap_cfg_cmd->flag, HNS3_TM_RATE_VLD_B, 1);
364 : :
365 : 0 : return hns3_cmd_send(hw, &desc, 1);
366 : : }
367 : :
368 : : int
369 : 0 : hns3_port_shaper_update(struct hns3_hw *hw, uint32_t speed)
370 : : {
371 : : int ret;
372 : :
373 : 0 : ret = hns3_dcb_port_shaper_cfg(hw, speed);
374 [ # # ]: 0 : if (ret)
375 : 0 : hns3_err(hw, "configure port shappering failed: ret = %d", ret);
376 : :
377 : 0 : return ret;
378 : : }
379 : :
380 : : static int
381 : 0 : hns3_dcb_pg_shapping_cfg(struct hns3_hw *hw, enum hns3_shap_bucket bucket,
382 : : uint8_t pg_id, uint32_t shapping_para, uint32_t rate)
383 : : {
384 : : struct hns3_pg_shapping_cmd *shap_cfg_cmd;
385 : : enum hns3_opcode_type opcode;
386 : : struct hns3_cmd_desc desc;
387 : :
388 [ # # ]: 0 : opcode = bucket ? HNS3_OPC_TM_PG_P_SHAPPING :
389 : : HNS3_OPC_TM_PG_C_SHAPPING;
390 : 0 : hns3_cmd_setup_basic_desc(&desc, opcode, false);
391 : :
392 : : shap_cfg_cmd = (struct hns3_pg_shapping_cmd *)desc.data;
393 : :
394 : 0 : shap_cfg_cmd->pg_id = pg_id;
395 : :
396 : 0 : shap_cfg_cmd->pg_shapping_para = rte_cpu_to_le_32(shapping_para);
397 : :
398 : : /*
399 : : * Configure the pg_rate and set bit HNS3_TM_RATE_VLD_B of flag field in
400 : : * hns3_pg_shapping_cmd to require firmware to recalculate shapping
401 : : * parameters. And whether parameters are recalculated depends on
402 : : * the firmware version. But driver still needs to calculate it and
403 : : * configure to firmware for better compatibility.
404 : : */
405 : 0 : shap_cfg_cmd->pg_rate = rte_cpu_to_le_32(rate);
406 : 0 : hns3_set_bit(shap_cfg_cmd->flag, HNS3_TM_RATE_VLD_B, 1);
407 : :
408 : 0 : return hns3_cmd_send(hw, &desc, 1);
409 : : }
410 : :
411 : : static int
412 : 0 : hns3_pg_shaper_rate_cfg(struct hns3_hw *hw, uint8_t pg_id, uint32_t rate)
413 : : {
414 : : struct hns3_shaper_parameter shaper_parameter;
415 : : uint32_t ir_u, ir_b, ir_s;
416 : : uint32_t shaper_para;
417 : : int ret;
418 : :
419 : : /* Calc shaper para */
420 : 0 : ret = hns3_shaper_para_calc(hw, rate, HNS3_SHAPER_LVL_PG,
421 : : &shaper_parameter);
422 [ # # ]: 0 : if (ret) {
423 : 0 : hns3_err(hw, "calculate shaper parameter fail, ret = %d.",
424 : : ret);
425 : 0 : return ret;
426 : : }
427 : :
428 : : shaper_para = hns3_dcb_get_shapping_para(0, 0, 0,
429 : : HNS3_SHAPER_BS_U_DEF,
430 : : HNS3_SHAPER_BS_S_DEF);
431 : :
432 : 0 : ret = hns3_dcb_pg_shapping_cfg(hw, HNS3_DCB_SHAP_C_BUCKET, pg_id,
433 : : shaper_para, rate);
434 [ # # ]: 0 : if (ret) {
435 : 0 : hns3_err(hw, "config PG CIR shaper parameter fail, ret = %d.",
436 : : ret);
437 : 0 : return ret;
438 : : }
439 : :
440 : 0 : ir_b = shaper_parameter.ir_b;
441 : 0 : ir_u = shaper_parameter.ir_u;
442 : 0 : ir_s = shaper_parameter.ir_s;
443 [ # # ]: 0 : shaper_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
444 : : HNS3_SHAPER_BS_U_DEF,
445 : : HNS3_SHAPER_BS_S_DEF);
446 : :
447 : 0 : ret = hns3_dcb_pg_shapping_cfg(hw, HNS3_DCB_SHAP_P_BUCKET, pg_id,
448 : : shaper_para, rate);
449 [ # # ]: 0 : if (ret) {
450 : 0 : hns3_err(hw, "config PG PIR shaper parameter fail, ret = %d.",
451 : : ret);
452 : 0 : return ret;
453 : : }
454 : :
455 : : return 0;
456 : : }
457 : :
458 : : static int
459 : 0 : hns3_dcb_pg_shaper_cfg(struct hns3_hw *hw)
460 : : {
461 : : struct hns3_pf *pf = HNS3_DEV_HW_TO_PF(hw);
462 : : uint32_t rate;
463 : : uint8_t i;
464 : : int ret;
465 : :
466 : : /* Cfg pg schd */
467 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
468 : : return -EINVAL;
469 : :
470 : : /* Pg to pri */
471 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_pg; i++) {
472 : 0 : rate = hw->dcb_info.pg_info[i].bw_limit;
473 : 0 : ret = hns3_pg_shaper_rate_cfg(hw, i, rate);
474 [ # # ]: 0 : if (ret)
475 : 0 : return ret;
476 : : }
477 : :
478 : : return 0;
479 : : }
480 : :
481 : : static int
482 : 0 : hns3_dcb_qs_schd_mode_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t mode)
483 : : {
484 : : struct hns3_cmd_desc desc;
485 : :
486 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_SCH_MODE_CFG, false);
487 : :
488 [ # # ]: 0 : if (mode == HNS3_SCH_MODE_DWRR)
489 : 0 : desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
490 : : else
491 : 0 : desc.data[1] = 0;
492 : :
493 : 0 : desc.data[0] = rte_cpu_to_le_32(qs_id);
494 : :
495 : 0 : return hns3_cmd_send(hw, &desc, 1);
496 : : }
497 : :
498 : : static int
499 : 0 : hns3_dcb_pri_schd_mode_cfg(struct hns3_hw *hw, uint8_t pri_id)
500 : : {
501 : : struct hns3_cmd_desc desc;
502 : :
503 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PRI_SCH_MODE_CFG, false);
504 : :
505 [ # # ]: 0 : if (hw->dcb_info.tc_info[pri_id].tc_sch_mode == HNS3_SCH_MODE_DWRR)
506 : 0 : desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
507 : : else
508 : 0 : desc.data[1] = 0;
509 : :
510 : 0 : desc.data[0] = rte_cpu_to_le_32(pri_id);
511 : :
512 : 0 : return hns3_cmd_send(hw, &desc, 1);
513 : : }
514 : :
515 : : static int
516 : 0 : hns3_dcb_pri_shapping_cfg(struct hns3_hw *hw, enum hns3_shap_bucket bucket,
517 : : uint8_t pri_id, uint32_t shapping_para, uint32_t rate)
518 : : {
519 : : struct hns3_pri_shapping_cmd *shap_cfg_cmd;
520 : : enum hns3_opcode_type opcode;
521 : : struct hns3_cmd_desc desc;
522 : :
523 [ # # ]: 0 : opcode = bucket ? HNS3_OPC_TM_PRI_P_SHAPPING :
524 : : HNS3_OPC_TM_PRI_C_SHAPPING;
525 : :
526 : 0 : hns3_cmd_setup_basic_desc(&desc, opcode, false);
527 : :
528 : : shap_cfg_cmd = (struct hns3_pri_shapping_cmd *)desc.data;
529 : :
530 : 0 : shap_cfg_cmd->pri_id = pri_id;
531 : :
532 : 0 : shap_cfg_cmd->pri_shapping_para = rte_cpu_to_le_32(shapping_para);
533 : :
534 : : /*
535 : : * Configure the pri_rate and set bit HNS3_TM_RATE_VLD_B of flag
536 : : * field in hns3_pri_shapping_cmd to require firmware to recalculate
537 : : * shapping parameters. And whether the parameters are recalculated
538 : : * depends on the firmware version. But driver still needs to
539 : : * calculate it and configure to firmware for better compatibility.
540 : : */
541 : 0 : shap_cfg_cmd->pri_rate = rte_cpu_to_le_32(rate);
542 : 0 : hns3_set_bit(shap_cfg_cmd->flag, HNS3_TM_RATE_VLD_B, 1);
543 : :
544 : 0 : return hns3_cmd_send(hw, &desc, 1);
545 : : }
546 : :
547 : : static int
548 : 0 : hns3_pri_shaper_rate_cfg(struct hns3_hw *hw, uint8_t tc_no, uint32_t rate)
549 : : {
550 : : struct hns3_shaper_parameter shaper_parameter;
551 : : uint32_t ir_u, ir_b, ir_s;
552 : : uint32_t shaper_para;
553 : : int ret;
554 : :
555 : 0 : ret = hns3_shaper_para_calc(hw, rate, HNS3_SHAPER_LVL_PRI,
556 : : &shaper_parameter);
557 [ # # ]: 0 : if (ret) {
558 : 0 : hns3_err(hw, "calculate shaper parameter failed: %d.",
559 : : ret);
560 : 0 : return ret;
561 : : }
562 : :
563 : : shaper_para = hns3_dcb_get_shapping_para(0, 0, 0,
564 : : HNS3_SHAPER_BS_U_DEF,
565 : : HNS3_SHAPER_BS_S_DEF);
566 : :
567 : 0 : ret = hns3_dcb_pri_shapping_cfg(hw, HNS3_DCB_SHAP_C_BUCKET, tc_no,
568 : : shaper_para, rate);
569 [ # # ]: 0 : if (ret) {
570 : 0 : hns3_err(hw,
571 : : "config priority CIR shaper parameter failed: %d.",
572 : : ret);
573 : 0 : return ret;
574 : : }
575 : :
576 : 0 : ir_b = shaper_parameter.ir_b;
577 : 0 : ir_u = shaper_parameter.ir_u;
578 : 0 : ir_s = shaper_parameter.ir_s;
579 [ # # ]: 0 : shaper_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
580 : : HNS3_SHAPER_BS_U_DEF,
581 : : HNS3_SHAPER_BS_S_DEF);
582 : :
583 : 0 : ret = hns3_dcb_pri_shapping_cfg(hw, HNS3_DCB_SHAP_P_BUCKET, tc_no,
584 : : shaper_para, rate);
585 [ # # ]: 0 : if (ret) {
586 : 0 : hns3_err(hw,
587 : : "config priority PIR shaper parameter failed: %d.",
588 : : ret);
589 : 0 : return ret;
590 : : }
591 : :
592 : : return 0;
593 : : }
594 : :
595 : : static int
596 : 0 : hns3_dcb_pri_shaper_cfg(struct hns3_hw *hw)
597 : : {
598 : : struct hns3_pf *pf = HNS3_DEV_HW_TO_PF(hw);
599 : : uint32_t rate;
600 : : uint8_t i;
601 : : int ret;
602 : :
603 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
604 : : return -EINVAL;
605 : :
606 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++) {
607 : 0 : rate = hw->dcb_info.tc_info[i].bw_limit;
608 : 0 : ret = hns3_pri_shaper_rate_cfg(hw, i, rate);
609 [ # # ]: 0 : if (ret) {
610 : 0 : hns3_err(hw, "config pri shaper failed: %d.", ret);
611 : 0 : return ret;
612 : : }
613 : : }
614 : :
615 : : return 0;
616 : : }
617 : :
618 : : static int
619 : 0 : hns3_set_rss_size(struct hns3_hw *hw, uint16_t nb_rx_q)
620 : : {
621 : : struct hns3_rss_conf *rss_cfg = &hw->rss_info;
622 : : uint16_t rx_qnum_per_tc;
623 : : uint16_t used_rx_queues;
624 : : uint16_t i;
625 : :
626 : 0 : rx_qnum_per_tc = nb_rx_q / hw->num_tc;
627 [ # # ]: 0 : if (rx_qnum_per_tc > hw->rss_size_max) {
628 : 0 : hns3_err(hw, "rx queue number of per tc (%u) is greater than "
629 : : "value (%u) hardware supported.",
630 : : rx_qnum_per_tc, hw->rss_size_max);
631 : 0 : return -EINVAL;
632 : : }
633 : :
634 : 0 : used_rx_queues = hw->num_tc * rx_qnum_per_tc;
635 [ # # ]: 0 : if (used_rx_queues != nb_rx_q) {
636 : 0 : hns3_err(hw, "rx queue number (%u) configured must be an "
637 : : "integral multiple of valid tc number (%u).",
638 : : nb_rx_q, hw->num_tc);
639 : 0 : return -EINVAL;
640 : : }
641 : 0 : hw->alloc_rss_size = rx_qnum_per_tc;
642 : 0 : hw->used_rx_queues = used_rx_queues;
643 : :
644 : : /*
645 : : * When rss size is changed, we need to update rss redirection table
646 : : * maintained by driver. Besides, during the entire reset process, we
647 : : * need to ensure that the rss table information are not overwritten
648 : : * and configured directly to the hardware in the RESET_STAGE_RESTORE
649 : : * stage of the reset process.
650 : : */
651 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed) == 0) {
652 [ # # ]: 0 : for (i = 0; i < hw->rss_ind_tbl_size; i++)
653 : 0 : rss_cfg->rss_indirection_tbl[i] =
654 : 0 : i % hw->alloc_rss_size;
655 : : }
656 : :
657 : : return 0;
658 : : }
659 : :
660 : : static int
661 : 0 : hns3_tc_queue_mapping_cfg(struct hns3_hw *hw, uint16_t nb_tx_q)
662 : : {
663 : : struct hns3_tc_queue_info *tc_queue;
664 : : uint16_t used_tx_queues;
665 : : uint16_t tx_qnum_per_tc;
666 : : uint8_t i;
667 : :
668 : 0 : tx_qnum_per_tc = nb_tx_q / hw->num_tc;
669 : 0 : used_tx_queues = hw->num_tc * tx_qnum_per_tc;
670 [ # # ]: 0 : if (used_tx_queues != nb_tx_q) {
671 : 0 : hns3_err(hw, "tx queue number (%u) configured must be an "
672 : : "integral multiple of valid tc number (%u).",
673 : : nb_tx_q, hw->num_tc);
674 : 0 : return -EINVAL;
675 : : }
676 : :
677 : 0 : hw->used_tx_queues = used_tx_queues;
678 : 0 : hw->tx_qnum_per_tc = tx_qnum_per_tc;
679 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
680 : 0 : tc_queue = &hw->tc_queue[i];
681 [ # # # # ]: 0 : if (hw->hw_tc_map & BIT(i) && i < hw->num_tc) {
682 : 0 : tc_queue->enable = true;
683 : 0 : tc_queue->tqp_offset = i * hw->tx_qnum_per_tc;
684 : 0 : tc_queue->tqp_count = hw->tx_qnum_per_tc;
685 : 0 : tc_queue->tc = i;
686 : : } else {
687 : : /* Set to default queue if TC is disable */
688 : 0 : tc_queue->enable = false;
689 : 0 : tc_queue->tqp_offset = 0;
690 : 0 : tc_queue->tqp_count = 0;
691 : 0 : tc_queue->tc = 0;
692 : : }
693 : : }
694 : :
695 : : return 0;
696 : : }
697 : :
698 : : uint8_t
699 : 0 : hns3_txq_mapped_tc_get(struct hns3_hw *hw, uint16_t txq_no)
700 : : {
701 : : struct hns3_tc_queue_info *tc_queue;
702 : : uint8_t i;
703 : :
704 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
705 : 0 : tc_queue = &hw->tc_queue[i];
706 [ # # ]: 0 : if (!tc_queue->enable)
707 : 0 : continue;
708 : :
709 [ # # ]: 0 : if (txq_no >= tc_queue->tqp_offset &&
710 [ # # ]: 0 : txq_no < tc_queue->tqp_offset + tc_queue->tqp_count)
711 : 0 : return i;
712 : : }
713 : :
714 : : /* return TC0 in default case */
715 : : return 0;
716 : : }
717 : :
718 : : int
719 : 0 : hns3_queue_to_tc_mapping(struct hns3_hw *hw, uint16_t nb_rx_q, uint16_t nb_tx_q)
720 : : {
721 : : int ret;
722 : :
723 [ # # ]: 0 : if (nb_rx_q < hw->num_tc) {
724 : 0 : hns3_err(hw, "number of Rx queues(%u) is less than number of TC(%u).",
725 : : nb_rx_q, hw->num_tc);
726 : 0 : return -EINVAL;
727 : : }
728 : :
729 [ # # ]: 0 : if (nb_tx_q < hw->num_tc) {
730 : 0 : hns3_err(hw, "number of Tx queues(%u) is less than number of TC(%u).",
731 : : nb_tx_q, hw->num_tc);
732 : 0 : return -EINVAL;
733 : : }
734 : :
735 : 0 : ret = hns3_set_rss_size(hw, nb_rx_q);
736 [ # # ]: 0 : if (ret)
737 : : return ret;
738 : :
739 : 0 : return hns3_tc_queue_mapping_cfg(hw, nb_tx_q);
740 : : }
741 : :
742 : : static int
743 : : hns3_dcb_update_tc_queue_mapping(struct hns3_hw *hw, uint16_t nb_rx_q,
744 : : uint16_t nb_tx_q)
745 : : {
746 : 0 : hw->num_tc = hw->dcb_info.num_tc;
747 : :
748 : 0 : return hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q);
749 : : }
750 : :
751 : : int
752 : 0 : hns3_dcb_info_init(struct hns3_hw *hw)
753 : : {
754 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
755 : : struct hns3_pf *pf = &hns->pf;
756 : : int i, k;
757 : :
758 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
759 [ # # ]: 0 : hw->dcb_info.num_pg != 1)
760 : : return -EINVAL;
761 : :
762 : : /* Initializing PG information */
763 : 0 : memset(hw->dcb_info.pg_info, 0,
764 : : sizeof(struct hns3_pg_info) * HNS3_PG_NUM);
765 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_pg; i++) {
766 [ # # ]: 0 : hw->dcb_info.pg_dwrr[i] = i ? 0 : BW_MAX_PERCENT;
767 : 0 : hw->dcb_info.pg_info[i].pg_id = i;
768 : 0 : hw->dcb_info.pg_info[i].pg_sch_mode = HNS3_SCH_MODE_DWRR;
769 : 0 : hw->dcb_info.pg_info[i].bw_limit = hw->max_tm_rate;
770 : :
771 [ # # ]: 0 : if (i != 0)
772 : 0 : continue;
773 : :
774 : 0 : hw->dcb_info.pg_info[i].tc_bit_map = hw->hw_tc_map;
775 [ # # ]: 0 : for (k = 0; k < hw->dcb_info.num_tc; k++)
776 : 0 : hw->dcb_info.pg_info[i].tc_dwrr[k] = BW_MAX_PERCENT;
777 : : }
778 : :
779 : : /* All UPs mapping to TC0 */
780 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_USER_PRIO; i++)
781 : 0 : hw->dcb_info.prio_tc[i] = 0;
782 : :
783 : : /* Initializing tc information */
784 : 0 : memset(hw->dcb_info.tc_info, 0,
785 : : sizeof(struct hns3_tc_info) * HNS3_MAX_TC_NUM);
786 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++) {
787 : 0 : hw->dcb_info.tc_info[i].tc_id = i;
788 : 0 : hw->dcb_info.tc_info[i].tc_sch_mode = HNS3_SCH_MODE_DWRR;
789 : 0 : hw->dcb_info.tc_info[i].pgid = 0;
790 : 0 : hw->dcb_info.tc_info[i].bw_limit =
791 : 0 : hw->dcb_info.pg_info[0].bw_limit;
792 : : }
793 : :
794 : : return 0;
795 : : }
796 : :
797 : : static int
798 : 0 : hns3_dcb_lvl2_schd_mode_cfg(struct hns3_hw *hw)
799 : : {
800 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
801 : : struct hns3_pf *pf = &hns->pf;
802 : : int ret, i;
803 : :
804 : : /* Only being config on TC-Based scheduler mode */
805 [ # # ]: 0 : if (pf->tx_sch_mode == HNS3_FLAG_VNET_BASE_SCH_MODE)
806 : : return -EINVAL;
807 : :
808 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_pg; i++) {
809 : 0 : ret = hns3_dcb_pg_schd_mode_cfg(hw, i);
810 [ # # ]: 0 : if (ret)
811 : 0 : return ret;
812 : : }
813 : :
814 : : return 0;
815 : : }
816 : :
817 : : static int
818 : 0 : hns3_dcb_lvl34_schd_mode_cfg(struct hns3_hw *hw)
819 : : {
820 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
821 : : struct hns3_pf *pf = &hns->pf;
822 : : uint8_t i;
823 : : int ret;
824 : :
825 [ # # ]: 0 : if (pf->tx_sch_mode == HNS3_FLAG_TC_BASE_SCH_MODE) {
826 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++) {
827 : 0 : ret = hns3_dcb_pri_schd_mode_cfg(hw, i);
828 [ # # ]: 0 : if (ret)
829 : 0 : return ret;
830 : :
831 : 0 : ret = hns3_dcb_qs_schd_mode_cfg(hw, i,
832 : : HNS3_SCH_MODE_DWRR);
833 [ # # ]: 0 : if (ret)
834 : 0 : return ret;
835 : : }
836 : : }
837 : :
838 : : return 0;
839 : : }
840 : :
841 : : static int
842 : 0 : hns3_dcb_schd_mode_cfg(struct hns3_hw *hw)
843 : : {
844 : : int ret;
845 : :
846 : 0 : ret = hns3_dcb_lvl2_schd_mode_cfg(hw);
847 [ # # ]: 0 : if (ret) {
848 : 0 : hns3_err(hw, "config lvl2_schd_mode failed: %d", ret);
849 : 0 : return ret;
850 : : }
851 : :
852 : 0 : ret = hns3_dcb_lvl34_schd_mode_cfg(hw);
853 [ # # ]: 0 : if (ret)
854 : 0 : hns3_err(hw, "config lvl34_schd_mode failed: %d", ret);
855 : :
856 : : return ret;
857 : : }
858 : :
859 : : static int
860 : 0 : hns3_dcb_pri_tc_base_dwrr_cfg(struct hns3_hw *hw)
861 : : {
862 : : struct hns3_pg_info *pg_info;
863 : : uint8_t dwrr;
864 : : int ret, i;
865 : :
866 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++) {
867 : 0 : pg_info = &hw->dcb_info.pg_info[hw->dcb_info.tc_info[i].pgid];
868 : 0 : dwrr = pg_info->tc_dwrr[i];
869 : :
870 : 0 : ret = hns3_dcb_pri_weight_cfg(hw, i, dwrr);
871 [ # # ]: 0 : if (ret) {
872 : 0 : hns3_err(hw, "fail to send priority weight cmd: %d, ret = %d",
873 : : i, ret);
874 : 0 : return ret;
875 : : }
876 : :
877 : 0 : ret = hns3_dcb_qs_weight_cfg(hw, i, BW_MAX_PERCENT);
878 [ # # ]: 0 : if (ret) {
879 : 0 : hns3_err(hw, "fail to send qs_weight cmd: %d, ret = %d",
880 : : i, ret);
881 : 0 : return ret;
882 : : }
883 : : }
884 : :
885 : : return 0;
886 : : }
887 : :
888 : : static int
889 : 0 : hns3_dcb_pri_dwrr_cfg(struct hns3_hw *hw)
890 : : {
891 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
892 : : struct hns3_pf *pf = &hns->pf;
893 : : uint32_t version;
894 : : int ret;
895 : :
896 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
897 : : return -EINVAL;
898 : :
899 : 0 : ret = hns3_dcb_pri_tc_base_dwrr_cfg(hw);
900 [ # # ]: 0 : if (ret)
901 : : return ret;
902 : :
903 [ # # ]: 0 : if (!hns3_dev_get_support(hw, DCB))
904 : : return 0;
905 : :
906 : 0 : ret = hns3_dcb_ets_tc_dwrr_cfg(hw);
907 [ # # ]: 0 : if (ret == -EOPNOTSUPP) {
908 : 0 : version = hw->fw_version;
909 : 0 : hns3_warn(hw,
910 : : "fw %lu.%lu.%lu.%lu doesn't support ets tc weight cmd",
911 : : hns3_get_field(version, HNS3_FW_VERSION_BYTE3_M,
912 : : HNS3_FW_VERSION_BYTE3_S),
913 : : hns3_get_field(version, HNS3_FW_VERSION_BYTE2_M,
914 : : HNS3_FW_VERSION_BYTE2_S),
915 : : hns3_get_field(version, HNS3_FW_VERSION_BYTE1_M,
916 : : HNS3_FW_VERSION_BYTE1_S),
917 : : hns3_get_field(version, HNS3_FW_VERSION_BYTE0_M,
918 : : HNS3_FW_VERSION_BYTE0_S));
919 : : ret = 0;
920 : : }
921 : :
922 : : return ret;
923 : : }
924 : :
925 : : static int
926 : 0 : hns3_dcb_pg_dwrr_cfg(struct hns3_hw *hw)
927 : : {
928 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
929 : : struct hns3_pf *pf = &hns->pf;
930 : : int ret, i;
931 : :
932 : : /* Cfg pg schd */
933 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
934 : : return -EINVAL;
935 : :
936 : : /* Cfg pg to prio */
937 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_pg; i++) {
938 : : /* Cfg dwrr */
939 : 0 : ret = hns3_dcb_pg_weight_cfg(hw, i, hw->dcb_info.pg_dwrr[i]);
940 [ # # ]: 0 : if (ret)
941 : 0 : return ret;
942 : : }
943 : :
944 : : return 0;
945 : : }
946 : :
947 : : static int
948 : 0 : hns3_dcb_dwrr_cfg(struct hns3_hw *hw)
949 : : {
950 : : int ret;
951 : :
952 : 0 : ret = hns3_dcb_pg_dwrr_cfg(hw);
953 [ # # ]: 0 : if (ret) {
954 : 0 : hns3_err(hw, "config pg_dwrr failed: %d", ret);
955 : 0 : return ret;
956 : : }
957 : :
958 : 0 : ret = hns3_dcb_pri_dwrr_cfg(hw);
959 [ # # ]: 0 : if (ret)
960 : 0 : hns3_err(hw, "config pri_dwrr failed: %d", ret);
961 : :
962 : : return ret;
963 : : }
964 : :
965 : : static int
966 : 0 : hns3_dcb_shaper_cfg(struct hns3_hw *hw)
967 : : {
968 : : int ret;
969 : :
970 : 0 : ret = hns3_dcb_port_shaper_cfg(hw, hw->mac.link_speed);
971 [ # # ]: 0 : if (ret) {
972 : 0 : hns3_err(hw, "config port shaper failed: %d", ret);
973 : 0 : return ret;
974 : : }
975 : :
976 : 0 : ret = hns3_dcb_pg_shaper_cfg(hw);
977 [ # # ]: 0 : if (ret) {
978 : 0 : hns3_err(hw, "config pg shaper failed: %d", ret);
979 : 0 : return ret;
980 : : }
981 : :
982 : 0 : return hns3_dcb_pri_shaper_cfg(hw);
983 : : }
984 : :
985 : : static int
986 : 0 : hns3_q_to_qs_map_cfg(struct hns3_hw *hw, uint16_t q_id, uint16_t qs_id)
987 : : {
988 : : struct hns3_nq_to_qs_link_cmd *map;
989 : : struct hns3_cmd_desc desc;
990 : : uint16_t tmp_qs_id = 0;
991 : : uint16_t qs_id_l;
992 : : uint16_t qs_id_h;
993 : :
994 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_NQ_TO_QS_LINK, false);
995 : :
996 : : map = (struct hns3_nq_to_qs_link_cmd *)desc.data;
997 : :
998 : 0 : map->nq_id = rte_cpu_to_le_16(q_id);
999 : :
1000 : : /*
1001 : : * Network engine with revision_id 0x21 uses 0~9 bit of qs_id to
1002 : : * configure qset_id. So we need to convert qs_id to the follow
1003 : : * format to support qset_id > 1024.
1004 : : * qs_id: | 15 | 14 ~ 10 | 9 ~ 0 |
1005 : : * / / \ \
1006 : : * / / \ \
1007 : : * qset_id: | 15 ~ 11 | 10 | 9 ~ 0 |
1008 : : * | qs_id_h | vld | qs_id_l |
1009 : : */
1010 : 0 : qs_id_l = hns3_get_field(qs_id, HNS3_DCB_QS_ID_L_MSK,
1011 : : HNS3_DCB_QS_ID_L_S);
1012 : 0 : qs_id_h = hns3_get_field(qs_id, HNS3_DCB_QS_ID_H_MSK,
1013 : : HNS3_DCB_QS_ID_H_S);
1014 : : hns3_set_field(tmp_qs_id, HNS3_DCB_QS_ID_L_MSK, HNS3_DCB_QS_ID_L_S,
1015 : : qs_id_l);
1016 : 0 : hns3_set_field(tmp_qs_id, HNS3_DCB_QS_ID_H_EXT_MSK,
1017 : : HNS3_DCB_QS_ID_H_EXT_S, qs_id_h);
1018 : 0 : map->qset_id = rte_cpu_to_le_16(tmp_qs_id | HNS3_DCB_Q_QS_LINK_VLD_MSK);
1019 : :
1020 : 0 : return hns3_cmd_send(hw, &desc, 1);
1021 : : }
1022 : :
1023 : : static int
1024 : 0 : hns3_q_to_qs_map(struct hns3_hw *hw)
1025 : : {
1026 : : struct hns3_tc_queue_info *tc_queue;
1027 : : uint16_t q_id;
1028 : : uint32_t i, j;
1029 : : int ret;
1030 : :
1031 [ # # ]: 0 : for (i = 0; i < hw->num_tc; i++) {
1032 : : tc_queue = &hw->tc_queue[i];
1033 [ # # ]: 0 : for (j = 0; j < tc_queue->tqp_count; j++) {
1034 : 0 : q_id = tc_queue->tqp_offset + j;
1035 : 0 : ret = hns3_q_to_qs_map_cfg(hw, q_id, i);
1036 [ # # ]: 0 : if (ret)
1037 : 0 : return ret;
1038 : : }
1039 : : }
1040 : :
1041 : : return 0;
1042 : : }
1043 : :
1044 : : static int
1045 : 0 : hns3_pri_q_qs_cfg(struct hns3_hw *hw)
1046 : : {
1047 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1048 : : struct hns3_pf *pf = &hns->pf;
1049 : : uint32_t i;
1050 : : int ret;
1051 : :
1052 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
1053 : : return -EINVAL;
1054 : :
1055 : : /* Cfg qs -> pri mapping */
1056 [ # # ]: 0 : for (i = 0; i < hw->num_tc; i++) {
1057 : 0 : ret = hns3_qs_to_pri_map_cfg(hw, i, i);
1058 [ # # ]: 0 : if (ret) {
1059 : 0 : hns3_err(hw, "qs_to_pri mapping fail: %d", ret);
1060 : 0 : return ret;
1061 : : }
1062 : : }
1063 : :
1064 : : /* Cfg q -> qs mapping */
1065 : 0 : ret = hns3_q_to_qs_map(hw);
1066 [ # # ]: 0 : if (ret)
1067 : 0 : hns3_err(hw, "nq_to_qs mapping fail: %d", ret);
1068 : :
1069 : : return ret;
1070 : : }
1071 : :
1072 : : static int
1073 : 0 : hns3_dcb_map_cfg(struct hns3_hw *hw)
1074 : : {
1075 : : int ret;
1076 : :
1077 : 0 : ret = hns3_up_to_tc_map(hw);
1078 [ # # ]: 0 : if (ret) {
1079 : 0 : hns3_err(hw, "up_to_tc mapping fail: %d", ret);
1080 : 0 : return ret;
1081 : : }
1082 : :
1083 : 0 : ret = hns3_pg_to_pri_map(hw);
1084 [ # # ]: 0 : if (ret) {
1085 : 0 : hns3_err(hw, "pg_to_pri mapping fail: %d", ret);
1086 : 0 : return ret;
1087 : : }
1088 : :
1089 : 0 : return hns3_pri_q_qs_cfg(hw);
1090 : : }
1091 : :
1092 : : static int
1093 : 0 : hns3_dcb_schd_setup_hw(struct hns3_hw *hw)
1094 : : {
1095 : : int ret;
1096 : :
1097 : : /* Cfg dcb mapping */
1098 : 0 : ret = hns3_dcb_map_cfg(hw);
1099 [ # # ]: 0 : if (ret)
1100 : : return ret;
1101 : :
1102 : : /* Cfg dcb shaper */
1103 : 0 : ret = hns3_dcb_shaper_cfg(hw);
1104 [ # # ]: 0 : if (ret)
1105 : : return ret;
1106 : :
1107 : : /* Cfg dwrr */
1108 : 0 : ret = hns3_dcb_dwrr_cfg(hw);
1109 [ # # ]: 0 : if (ret)
1110 : : return ret;
1111 : :
1112 : : /* Cfg schd mode for each level schd */
1113 : 0 : return hns3_dcb_schd_mode_cfg(hw);
1114 : : }
1115 : :
1116 : : static int
1117 : 0 : hns3_pause_param_cfg(struct hns3_hw *hw, const uint8_t *addr,
1118 : : uint8_t pause_trans_gap, uint16_t pause_trans_time)
1119 : : {
1120 : : struct hns3_cfg_pause_param_cmd *pause_param;
1121 : : struct hns3_cmd_desc desc;
1122 : :
1123 : : pause_param = (struct hns3_cfg_pause_param_cmd *)desc.data;
1124 : :
1125 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PARA, false);
1126 : :
1127 : : memcpy(pause_param->mac_addr, addr, RTE_ETHER_ADDR_LEN);
1128 : : memcpy(pause_param->mac_addr_extra, addr, RTE_ETHER_ADDR_LEN);
1129 : 0 : pause_param->pause_trans_gap = pause_trans_gap;
1130 : 0 : pause_param->pause_trans_time = rte_cpu_to_le_16(pause_trans_time);
1131 : :
1132 : 0 : return hns3_cmd_send(hw, &desc, 1);
1133 : : }
1134 : :
1135 : : int
1136 : 0 : hns3_pause_addr_cfg(struct hns3_hw *hw, const uint8_t *mac_addr)
1137 : : {
1138 : : struct hns3_cfg_pause_param_cmd *pause_param;
1139 : : struct hns3_cmd_desc desc;
1140 : : uint16_t trans_time;
1141 : : uint8_t trans_gap;
1142 : : int ret;
1143 : :
1144 : : pause_param = (struct hns3_cfg_pause_param_cmd *)desc.data;
1145 : :
1146 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PARA, true);
1147 : :
1148 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
1149 [ # # ]: 0 : if (ret)
1150 : : return ret;
1151 : :
1152 : 0 : trans_gap = pause_param->pause_trans_gap;
1153 : 0 : trans_time = rte_le_to_cpu_16(pause_param->pause_trans_time);
1154 : :
1155 : 0 : return hns3_pause_param_cfg(hw, mac_addr, trans_gap, trans_time);
1156 : : }
1157 : :
1158 : : static int
1159 : 0 : hns3_pause_param_setup_hw(struct hns3_hw *hw, uint16_t pause_time)
1160 : : {
1161 : : #define PAUSE_TIME_DIV_BY 2
1162 : : #define PAUSE_TIME_MIN_VALUE 0x4
1163 : :
1164 : : struct hns3_mac *mac = &hw->mac;
1165 : : uint8_t pause_trans_gap;
1166 : :
1167 : : /*
1168 : : * Pause transmit gap must be less than "pause_time / 2", otherwise
1169 : : * the behavior of MAC is undefined.
1170 : : */
1171 [ # # ]: 0 : if (pause_time > PAUSE_TIME_DIV_BY * HNS3_DEFAULT_PAUSE_TRANS_GAP)
1172 : : pause_trans_gap = HNS3_DEFAULT_PAUSE_TRANS_GAP;
1173 [ # # ]: 0 : else if (pause_time >= PAUSE_TIME_MIN_VALUE &&
1174 : : pause_time <= PAUSE_TIME_DIV_BY * HNS3_DEFAULT_PAUSE_TRANS_GAP)
1175 : 0 : pause_trans_gap = pause_time / PAUSE_TIME_DIV_BY - 1;
1176 : : else {
1177 : 0 : hns3_warn(hw, "pause_time(%u) is adjusted to 4", pause_time);
1178 : : pause_time = PAUSE_TIME_MIN_VALUE;
1179 : : pause_trans_gap = pause_time / PAUSE_TIME_DIV_BY - 1;
1180 : : }
1181 : :
1182 : 0 : return hns3_pause_param_cfg(hw, mac->mac_addr,
1183 : : pause_trans_gap, pause_time);
1184 : : }
1185 : :
1186 : : static int
1187 : 0 : hns3_mac_pause_en_cfg(struct hns3_hw *hw, bool tx, bool rx)
1188 : : {
1189 : : struct hns3_cmd_desc desc;
1190 : :
1191 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PAUSE_EN, false);
1192 : :
1193 [ # # # # ]: 0 : desc.data[0] = rte_cpu_to_le_32((tx ? HNS3_TX_MAC_PAUSE_EN_MSK : 0) |
1194 : : (rx ? HNS3_RX_MAC_PAUSE_EN_MSK : 0));
1195 : :
1196 : 0 : return hns3_cmd_send(hw, &desc, 1);
1197 : : }
1198 : :
1199 : : static int
1200 : 0 : hns3_pfc_pause_en_cfg(struct hns3_hw *hw, uint8_t pfc_bitmap, bool tx, bool rx)
1201 : : {
1202 : : struct hns3_cmd_desc desc;
1203 : : struct hns3_pfc_en_cmd *pfc = (struct hns3_pfc_en_cmd *)desc.data;
1204 : :
1205 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_PFC_PAUSE_EN, false);
1206 : :
1207 [ # # # # ]: 0 : pfc->tx_rx_en_bitmap = (uint8_t)((tx ? HNS3_TX_MAC_PAUSE_EN_MSK : 0) |
1208 : : (rx ? HNS3_RX_MAC_PAUSE_EN_MSK : 0));
1209 : :
1210 : 0 : pfc->pri_en_bitmap = pfc_bitmap;
1211 : :
1212 : 0 : return hns3_cmd_send(hw, &desc, 1);
1213 : : }
1214 : :
1215 : : static int
1216 : 0 : hns3_qs_bp_cfg(struct hns3_hw *hw, uint8_t tc, uint8_t grp_id, uint32_t bit_map)
1217 : : {
1218 : : struct hns3_bp_to_qs_map_cmd *bp_to_qs_map_cmd;
1219 : : struct hns3_cmd_desc desc;
1220 : :
1221 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_BP_TO_QSET_MAPPING, false);
1222 : :
1223 : : bp_to_qs_map_cmd = (struct hns3_bp_to_qs_map_cmd *)desc.data;
1224 : :
1225 : 0 : bp_to_qs_map_cmd->tc_id = tc;
1226 : 0 : bp_to_qs_map_cmd->qs_group_id = grp_id;
1227 : 0 : bp_to_qs_map_cmd->qs_bit_map = rte_cpu_to_le_32(bit_map);
1228 : :
1229 : 0 : return hns3_cmd_send(hw, &desc, 1);
1230 : : }
1231 : :
1232 : : static void
1233 : : hns3_get_rx_tx_en_status(struct hns3_hw *hw, bool *tx_en, bool *rx_en)
1234 : : {
1235 [ # # # # ]: 0 : switch (hw->requested_fc_mode) {
1236 : : case HNS3_FC_NONE:
1237 : : *tx_en = false;
1238 : : *rx_en = false;
1239 : : break;
1240 : : case HNS3_FC_RX_PAUSE:
1241 : : *tx_en = false;
1242 : : *rx_en = true;
1243 : : break;
1244 : : case HNS3_FC_TX_PAUSE:
1245 : : *tx_en = true;
1246 : : *rx_en = false;
1247 : : break;
1248 : : case HNS3_FC_FULL:
1249 : : *tx_en = true;
1250 : : *rx_en = true;
1251 : : break;
1252 : : default:
1253 : : *tx_en = false;
1254 : : *rx_en = false;
1255 : : break;
1256 : : }
1257 : : }
1258 : :
1259 : : static int
1260 : 0 : hns3_mac_pause_setup_hw(struct hns3_hw *hw)
1261 : : {
1262 : : bool tx_en, rx_en;
1263 : :
1264 [ # # ]: 0 : if (hw->current_fc_status == HNS3_FC_STATUS_MAC_PAUSE)
1265 : : hns3_get_rx_tx_en_status(hw, &tx_en, &rx_en);
1266 : : else {
1267 : : tx_en = false;
1268 : : rx_en = false;
1269 : : }
1270 : :
1271 : 0 : return hns3_mac_pause_en_cfg(hw, tx_en, rx_en);
1272 : : }
1273 : :
1274 : : static int
1275 : 0 : hns3_pfc_setup_hw(struct hns3_hw *hw)
1276 : : {
1277 : : bool tx_en, rx_en;
1278 : :
1279 [ # # ]: 0 : if (hw->current_fc_status == HNS3_FC_STATUS_PFC)
1280 : : hns3_get_rx_tx_en_status(hw, &tx_en, &rx_en);
1281 : : else {
1282 : : tx_en = false;
1283 : : rx_en = false;
1284 : : }
1285 : :
1286 : 0 : return hns3_pfc_pause_en_cfg(hw, hw->dcb_info.pfc_en, tx_en, rx_en);
1287 : : }
1288 : :
1289 : : /*
1290 : : * Each Tc has a 1024 queue sets to backpress, it divides to
1291 : : * 32 group, each group contains 32 queue sets, which can be
1292 : : * represented by uint32_t bitmap.
1293 : : */
1294 : : static int
1295 : 0 : hns3_bp_setup_hw(struct hns3_hw *hw, uint8_t tc)
1296 : : {
1297 : : uint32_t qs_bitmap;
1298 : : int ret;
1299 : : int i;
1300 : :
1301 [ # # ]: 0 : for (i = 0; i < HNS3_BP_GRP_NUM; i++) {
1302 : : uint8_t grp, sub_grp;
1303 : : qs_bitmap = 0;
1304 : :
1305 : 0 : grp = hns3_get_field(tc, HNS3_BP_GRP_ID_M, HNS3_BP_GRP_ID_S);
1306 : 0 : sub_grp = hns3_get_field(tc, HNS3_BP_SUB_GRP_ID_M,
1307 : : HNS3_BP_SUB_GRP_ID_S);
1308 [ # # ]: 0 : if (i == grp)
1309 : 0 : qs_bitmap |= (1 << sub_grp);
1310 : :
1311 : 0 : ret = hns3_qs_bp_cfg(hw, tc, i, qs_bitmap);
1312 [ # # ]: 0 : if (ret)
1313 : 0 : return ret;
1314 : : }
1315 : :
1316 : : return 0;
1317 : : }
1318 : :
1319 : : static int
1320 : : hns3_dcb_bp_setup(struct hns3_hw *hw)
1321 : : {
1322 : : int ret, i;
1323 : :
1324 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++) {
1325 : 0 : ret = hns3_bp_setup_hw(hw, i);
1326 [ # # ]: 0 : if (ret)
1327 : : return ret;
1328 : : }
1329 : :
1330 : : return 0;
1331 : : }
1332 : :
1333 : : static int
1334 : 0 : hns3_dcb_pause_setup_hw(struct hns3_hw *hw)
1335 : : {
1336 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1337 : : struct hns3_pf *pf = &hns->pf;
1338 : : int ret;
1339 : :
1340 : 0 : ret = hns3_pause_param_setup_hw(hw, pf->pause_time);
1341 [ # # ]: 0 : if (ret) {
1342 : 0 : hns3_err(hw, "Fail to set pause parameter. ret = %d", ret);
1343 : 0 : return ret;
1344 : : }
1345 : :
1346 : 0 : ret = hns3_mac_pause_setup_hw(hw);
1347 [ # # ]: 0 : if (ret) {
1348 : 0 : hns3_err(hw, "Fail to setup MAC pause. ret = %d", ret);
1349 : 0 : return ret;
1350 : : }
1351 : :
1352 : : /* Only DCB-supported dev supports qset back pressure and pfc cmd */
1353 [ # # ]: 0 : if (!hns3_dev_get_support(hw, DCB))
1354 : : return 0;
1355 : :
1356 : 0 : ret = hns3_pfc_setup_hw(hw);
1357 [ # # ]: 0 : if (ret) {
1358 : 0 : hns3_err(hw, "config pfc failed! ret = %d", ret);
1359 : 0 : return ret;
1360 : : }
1361 : :
1362 : : return hns3_dcb_bp_setup(hw);
1363 : : }
1364 : :
1365 : : static uint8_t
1366 : : hns3_dcb_undrop_tc_map(struct hns3_hw *hw, uint8_t pfc_en)
1367 : : {
1368 : : uint8_t pfc_map = 0;
1369 : : uint8_t *prio_tc;
1370 : : uint8_t i, j;
1371 : :
1372 : 0 : prio_tc = hw->dcb_info.prio_tc;
1373 [ # # # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++) {
1374 [ # # # # ]: 0 : for (j = 0; j < HNS3_MAX_USER_PRIO; j++) {
1375 [ # # # # : 0 : if (prio_tc[j] == i && pfc_en & BIT(j)) {
# # # # ]
1376 : 0 : pfc_map |= BIT(i);
1377 : 0 : break;
1378 : : }
1379 : : }
1380 : : }
1381 : :
1382 : : return pfc_map;
1383 : : }
1384 : :
1385 : : static uint8_t
1386 : : hns3_dcb_parse_num_tc(struct hns3_adapter *hns)
1387 : : {
1388 : : struct rte_eth_dcb_rx_conf *dcb_rx_conf;
1389 : : struct hns3_hw *hw = &hns->hw;
1390 : : uint8_t max_tc_id = 0;
1391 : : int i;
1392 : :
1393 : 0 : dcb_rx_conf = &hw->data->dev_conf.rx_adv_conf.dcb_rx_conf;
1394 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_USER_PRIO; i++) {
1395 : 0 : if (dcb_rx_conf->dcb_tc[i] > max_tc_id)
1396 : : max_tc_id = dcb_rx_conf->dcb_tc[i];
1397 : : }
1398 : :
1399 : : /* Number of TC is equal to max_tc_id plus 1. */
1400 : 0 : return max_tc_id + 1;
1401 : : }
1402 : :
1403 : : static int
1404 : 0 : hns3_dcb_info_cfg(struct hns3_adapter *hns)
1405 : : {
1406 : : struct rte_eth_dcb_rx_conf *dcb_rx_conf;
1407 : : struct hns3_pf *pf = &hns->pf;
1408 : 0 : struct hns3_hw *hw = &hns->hw;
1409 : : uint8_t tc_bw, bw_rest;
1410 : : uint8_t i, j;
1411 : : int ret;
1412 : :
1413 : 0 : dcb_rx_conf = &hw->data->dev_conf.rx_adv_conf.dcb_rx_conf;
1414 : 0 : pf->local_max_tc = (uint8_t)dcb_rx_conf->nb_tcs;
1415 : 0 : pf->pfc_max = (uint8_t)dcb_rx_conf->nb_tcs;
1416 : :
1417 : : /* Config pg0 */
1418 : 0 : memset(hw->dcb_info.pg_info, 0,
1419 : : sizeof(struct hns3_pg_info) * HNS3_PG_NUM);
1420 : 0 : hw->dcb_info.pg_dwrr[0] = BW_MAX_PERCENT;
1421 : : hw->dcb_info.pg_info[0].pg_id = 0;
1422 : 0 : hw->dcb_info.pg_info[0].pg_sch_mode = HNS3_SCH_MODE_DWRR;
1423 : 0 : hw->dcb_info.pg_info[0].bw_limit = hw->max_tm_rate;
1424 : 0 : hw->dcb_info.pg_info[0].tc_bit_map = hw->hw_tc_map;
1425 : :
1426 : : /* Each tc has same bw for valid tc by default */
1427 : 0 : tc_bw = BW_MAX_PERCENT / hw->dcb_info.num_tc;
1428 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++)
1429 : 0 : hw->dcb_info.pg_info[0].tc_dwrr[i] = tc_bw;
1430 : : /* To ensure the sum of tc_dwrr is equal to 100 */
1431 : 0 : bw_rest = BW_MAX_PERCENT % hw->dcb_info.num_tc;
1432 [ # # ]: 0 : for (j = 0; j < bw_rest; j++)
1433 : 0 : hw->dcb_info.pg_info[0].tc_dwrr[j]++;
1434 [ # # ]: 0 : for (; i < dcb_rx_conf->nb_tcs; i++)
1435 : 0 : hw->dcb_info.pg_info[0].tc_dwrr[i] = 0;
1436 : :
1437 : : /* All tcs map to pg0 */
1438 : 0 : memset(hw->dcb_info.tc_info, 0,
1439 : : sizeof(struct hns3_tc_info) * HNS3_MAX_TC_NUM);
1440 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++) {
1441 : 0 : hw->dcb_info.tc_info[i].tc_id = i;
1442 : 0 : hw->dcb_info.tc_info[i].tc_sch_mode = HNS3_SCH_MODE_DWRR;
1443 : 0 : hw->dcb_info.tc_info[i].pgid = 0;
1444 : 0 : hw->dcb_info.tc_info[i].bw_limit =
1445 : : hw->dcb_info.pg_info[0].bw_limit;
1446 : : }
1447 : :
1448 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_USER_PRIO; i++)
1449 : 0 : hw->dcb_info.prio_tc[i] = dcb_rx_conf->dcb_tc[i];
1450 : :
1451 : 0 : ret = hns3_dcb_update_tc_queue_mapping(hw, hw->data->nb_rx_queues,
1452 : 0 : hw->data->nb_tx_queues);
1453 [ # # ]: 0 : if (ret)
1454 : 0 : hns3_err(hw, "update tc queue mapping failed, ret = %d.", ret);
1455 : :
1456 : 0 : return ret;
1457 : : }
1458 : :
1459 : : static int
1460 : 0 : hns3_dcb_info_update(struct hns3_adapter *hns, uint8_t num_tc)
1461 : : {
1462 : : struct hns3_pf *pf = &hns->pf;
1463 : : struct hns3_hw *hw = &hns->hw;
1464 : 0 : uint16_t nb_rx_q = hw->data->nb_rx_queues;
1465 : 0 : uint16_t nb_tx_q = hw->data->nb_tx_queues;
1466 : : uint8_t bit_map = 0;
1467 : : uint8_t i;
1468 : :
1469 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
1470 [ # # ]: 0 : hw->dcb_info.num_pg != 1)
1471 : : return -EINVAL;
1472 : :
1473 [ # # ]: 0 : if (nb_rx_q < num_tc) {
1474 : 0 : hns3_err(hw, "number of Rx queues(%u) is less than tcs(%u).",
1475 : : nb_rx_q, num_tc);
1476 : 0 : return -EINVAL;
1477 : : }
1478 : :
1479 [ # # ]: 0 : if (nb_tx_q < num_tc) {
1480 : 0 : hns3_err(hw, "number of Tx queues(%u) is less than tcs(%u).",
1481 : : nb_tx_q, num_tc);
1482 : 0 : return -EINVAL;
1483 : : }
1484 : :
1485 : : /* Currently not support uncontinuous tc */
1486 : 0 : hw->dcb_info.num_tc = num_tc;
1487 [ # # ]: 0 : for (i = 0; i < hw->dcb_info.num_tc; i++)
1488 : 0 : bit_map |= BIT(i);
1489 : :
1490 [ # # ]: 0 : if (!bit_map) {
1491 : : bit_map = 1;
1492 : 0 : hw->dcb_info.num_tc = 1;
1493 : : }
1494 : 0 : hw->hw_tc_map = bit_map;
1495 : :
1496 : 0 : return hns3_dcb_info_cfg(hns);
1497 : : }
1498 : :
1499 : : static int
1500 : 0 : hns3_dcb_hw_configure(struct hns3_adapter *hns)
1501 : : {
1502 : : struct hns3_pf *pf = &hns->pf;
1503 : 0 : struct hns3_hw *hw = &hns->hw;
1504 : 0 : enum hns3_fc_status fc_status = hw->current_fc_status;
1505 : 0 : enum hns3_fc_mode requested_fc_mode = hw->requested_fc_mode;
1506 : 0 : uint8_t hw_pfc_map = hw->dcb_info.hw_pfc_map;
1507 : 0 : uint8_t pfc_en = hw->dcb_info.pfc_en;
1508 : : int ret;
1509 : :
1510 [ # # ]: 0 : if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
1511 : : pf->tx_sch_mode != HNS3_FLAG_VNET_BASE_SCH_MODE)
1512 : : return -ENOTSUP;
1513 : :
1514 : 0 : ret = hns3_dcb_schd_setup_hw(hw);
1515 [ # # ]: 0 : if (ret) {
1516 : 0 : hns3_err(hw, "dcb schedule configure failed! ret = %d", ret);
1517 : 0 : return ret;
1518 : : }
1519 : :
1520 [ # # ]: 0 : if (hw->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
1521 : 0 : hw->dcb_info.pfc_en =
1522 : : RTE_LEN2MASK((uint8_t)HNS3_MAX_USER_PRIO, uint8_t);
1523 : :
1524 : 0 : hw->dcb_info.hw_pfc_map =
1525 : : hns3_dcb_undrop_tc_map(hw, hw->dcb_info.pfc_en);
1526 : :
1527 : 0 : hw->current_fc_status = HNS3_FC_STATUS_PFC;
1528 : 0 : hw->requested_fc_mode = HNS3_FC_FULL;
1529 : : } else {
1530 : 0 : hw->current_fc_status = HNS3_FC_STATUS_NONE;
1531 : 0 : hw->requested_fc_mode = HNS3_FC_NONE;
1532 : 0 : hw->dcb_info.pfc_en = 0;
1533 : 0 : hw->dcb_info.hw_pfc_map = 0;
1534 : : }
1535 : :
1536 : 0 : ret = hns3_buffer_alloc(hw);
1537 [ # # ]: 0 : if (ret)
1538 : 0 : goto cfg_fail;
1539 : :
1540 : 0 : ret = hns3_dcb_pause_setup_hw(hw);
1541 [ # # ]: 0 : if (ret) {
1542 : 0 : hns3_err(hw, "setup pfc failed! ret = %d", ret);
1543 : 0 : goto cfg_fail;
1544 : : }
1545 : :
1546 : : return 0;
1547 : :
1548 : 0 : cfg_fail:
1549 : 0 : hw->requested_fc_mode = requested_fc_mode;
1550 : 0 : hw->current_fc_status = fc_status;
1551 : 0 : hw->dcb_info.pfc_en = pfc_en;
1552 : 0 : hw->dcb_info.hw_pfc_map = hw_pfc_map;
1553 : :
1554 : 0 : return ret;
1555 : : }
1556 : :
1557 : : /*
1558 : : * hns3_dcb_configure - setup dcb related config
1559 : : * @hns: pointer to hns3 adapter
1560 : : * Returns 0 on success, negative value on failure.
1561 : : */
1562 : : int
1563 : 0 : hns3_dcb_configure(struct hns3_adapter *hns)
1564 : : {
1565 : : struct hns3_hw *hw = &hns->hw;
1566 : : uint8_t num_tc;
1567 : : int ret;
1568 : :
1569 : : num_tc = hns3_dcb_parse_num_tc(hns);
1570 : 0 : ret = hns3_dcb_info_update(hns, num_tc);
1571 [ # # ]: 0 : if (ret) {
1572 : 0 : hns3_err(hw, "dcb info update failed: %d", ret);
1573 : 0 : return ret;
1574 : : }
1575 : :
1576 : 0 : ret = hns3_dcb_hw_configure(hns);
1577 [ # # ]: 0 : if (ret) {
1578 : 0 : hns3_err(hw, "dcb sw configure failed: %d", ret);
1579 : 0 : return ret;
1580 : : }
1581 : :
1582 : : return 0;
1583 : : }
1584 : :
1585 : : int
1586 : 0 : hns3_dcb_init_hw(struct hns3_hw *hw)
1587 : : {
1588 : : int ret;
1589 : :
1590 : 0 : ret = hns3_dcb_schd_setup_hw(hw);
1591 [ # # ]: 0 : if (ret) {
1592 : 0 : hns3_err(hw, "dcb schedule setup failed: %d", ret);
1593 : 0 : return ret;
1594 : : }
1595 : :
1596 : 0 : ret = hns3_dcb_pause_setup_hw(hw);
1597 [ # # ]: 0 : if (ret)
1598 : 0 : hns3_err(hw, "PAUSE setup failed: %d", ret);
1599 : :
1600 : : return ret;
1601 : : }
1602 : :
1603 : : int
1604 : 0 : hns3_dcb_init(struct hns3_hw *hw)
1605 : : {
1606 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1607 : : struct hns3_pf *pf = &hns->pf;
1608 : : uint16_t default_tqp_num;
1609 : : int ret;
1610 : :
1611 : 0 : PMD_INIT_FUNC_TRACE();
1612 : :
1613 : : /*
1614 : : * According to the 'adapter_state' identifier, the following branch
1615 : : * is only executed to initialize default configurations of dcb during
1616 : : * the initializing driver process. Due to driver saving dcb-related
1617 : : * information before reset triggered, the reinit dev stage of the
1618 : : * reset process can not access to the branch, or those information
1619 : : * will be changed.
1620 : : */
1621 [ # # ]: 0 : if (hw->adapter_state == HNS3_NIC_UNINITIALIZED) {
1622 : 0 : hw->requested_fc_mode = HNS3_FC_NONE;
1623 : 0 : pf->pause_time = HNS3_DEFAULT_PAUSE_TRANS_TIME;
1624 : 0 : hw->current_fc_status = HNS3_FC_STATUS_NONE;
1625 : :
1626 : 0 : ret = hns3_dcb_info_init(hw);
1627 [ # # ]: 0 : if (ret) {
1628 : 0 : hns3_err(hw, "dcb info init failed, ret = %d.", ret);
1629 : 0 : return ret;
1630 : : }
1631 : :
1632 : : /*
1633 : : * The number of queues configured by default cannot exceed
1634 : : * the maximum number of queues for a single TC.
1635 : : */
1636 : 0 : default_tqp_num = RTE_MIN(hw->rss_size_max,
1637 : : hw->tqps_num / hw->dcb_info.num_tc);
1638 : : ret = hns3_dcb_update_tc_queue_mapping(hw, default_tqp_num,
1639 : : default_tqp_num);
1640 [ # # ]: 0 : if (ret) {
1641 : 0 : hns3_err(hw,
1642 : : "update tc queue mapping failed, ret = %d.",
1643 : : ret);
1644 : 0 : return ret;
1645 : : }
1646 : : }
1647 : :
1648 : : /*
1649 : : * DCB hardware will be configured by following the function during
1650 : : * the initializing driver process and the reset process. However,
1651 : : * driver will restore directly configurations of dcb hardware based
1652 : : * on dcb-related information soft maintained when driver
1653 : : * initialization has finished and reset is coming.
1654 : : */
1655 : 0 : ret = hns3_dcb_init_hw(hw);
1656 [ # # ]: 0 : if (ret) {
1657 : 0 : hns3_err(hw, "dcb init hardware failed, ret = %d.", ret);
1658 : 0 : return ret;
1659 : : }
1660 : :
1661 : : return 0;
1662 : : }
1663 : :
1664 : : int
1665 : 0 : hns3_update_queue_map_configure(struct hns3_adapter *hns)
1666 : : {
1667 : 0 : struct hns3_hw *hw = &hns->hw;
1668 : 0 : enum rte_eth_rx_mq_mode mq_mode = hw->data->dev_conf.rxmode.mq_mode;
1669 : 0 : uint16_t nb_rx_q = hw->data->nb_rx_queues;
1670 : 0 : uint16_t nb_tx_q = hw->data->nb_tx_queues;
1671 : : int ret;
1672 : :
1673 [ # # ]: 0 : if ((uint32_t)mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
1674 : : return 0;
1675 : :
1676 : 0 : ret = hns3_dcb_update_tc_queue_mapping(hw, nb_rx_q, nb_tx_q);
1677 [ # # ]: 0 : if (ret) {
1678 : 0 : hns3_err(hw, "failed to update tc queue mapping, ret = %d.",
1679 : : ret);
1680 : 0 : return ret;
1681 : : }
1682 : 0 : ret = hns3_q_to_qs_map(hw);
1683 [ # # ]: 0 : if (ret)
1684 : 0 : hns3_err(hw, "failed to map nq to qs, ret = %d.", ret);
1685 : :
1686 : : return ret;
1687 : : }
1688 : :
1689 : : static void
1690 : 0 : hns3_get_fc_mode(struct hns3_hw *hw, enum rte_eth_fc_mode mode)
1691 : : {
1692 [ # # # # : 0 : switch (mode) {
# ]
1693 : 0 : case RTE_ETH_FC_NONE:
1694 : 0 : hw->requested_fc_mode = HNS3_FC_NONE;
1695 : 0 : break;
1696 : 0 : case RTE_ETH_FC_RX_PAUSE:
1697 : 0 : hw->requested_fc_mode = HNS3_FC_RX_PAUSE;
1698 : 0 : break;
1699 : 0 : case RTE_ETH_FC_TX_PAUSE:
1700 : 0 : hw->requested_fc_mode = HNS3_FC_TX_PAUSE;
1701 : 0 : break;
1702 : 0 : case RTE_ETH_FC_FULL:
1703 : 0 : hw->requested_fc_mode = HNS3_FC_FULL;
1704 : 0 : break;
1705 : 0 : default:
1706 : 0 : hw->requested_fc_mode = HNS3_FC_NONE;
1707 : 0 : hns3_warn(hw, "fc_mode(%u) exceeds member scope and is "
1708 : : "configured to RTE_ETH_FC_NONE", mode);
1709 : 0 : break;
1710 : : }
1711 : 0 : }
1712 : :
1713 : : /*
1714 : : * hns3_dcb_pfc_enable - Enable priority flow control
1715 : : * @dev: pointer to ethernet device
1716 : : *
1717 : : * Configures the pfc settings for one priority.
1718 : : */
1719 : : int
1720 : 0 : hns3_dcb_pfc_enable(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
1721 : : {
1722 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1723 : : struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1724 : 0 : enum hns3_fc_status fc_status = hw->current_fc_status;
1725 : 0 : enum hns3_fc_mode old_fc_mode = hw->requested_fc_mode;
1726 : 0 : uint8_t hw_pfc_map = hw->dcb_info.hw_pfc_map;
1727 : 0 : uint8_t pfc_en = hw->dcb_info.pfc_en;
1728 : 0 : uint8_t priority = pfc_conf->priority;
1729 : 0 : uint16_t pause_time = pf->pause_time;
1730 : : int ret;
1731 : :
1732 : 0 : hw->dcb_info.pfc_en |= BIT(priority);
1733 : 0 : hw->dcb_info.hw_pfc_map =
1734 : : hns3_dcb_undrop_tc_map(hw, hw->dcb_info.pfc_en);
1735 : 0 : ret = hns3_buffer_alloc(hw);
1736 [ # # ]: 0 : if (ret) {
1737 : 0 : hns3_err(hw, "update packet buffer failed, ret = %d", ret);
1738 : 0 : goto buffer_alloc_fail;
1739 : : }
1740 : :
1741 : 0 : pf->pause_time = pfc_conf->fc.pause_time;
1742 : 0 : hns3_get_fc_mode(hw, pfc_conf->fc.mode);
1743 [ # # ]: 0 : if (hw->requested_fc_mode == HNS3_FC_NONE)
1744 : 0 : hw->current_fc_status = HNS3_FC_STATUS_NONE;
1745 : : else
1746 : 0 : hw->current_fc_status = HNS3_FC_STATUS_PFC;
1747 : :
1748 : : /*
1749 : : * The flow control mode of all UPs will be changed based on
1750 : : * requested_fc_mode coming from user.
1751 : : */
1752 : 0 : ret = hns3_dcb_pause_setup_hw(hw);
1753 [ # # ]: 0 : if (ret) {
1754 : 0 : hns3_err(hw, "enable pfc failed! ret = %d", ret);
1755 : 0 : goto pfc_setup_fail;
1756 : : }
1757 : :
1758 : : return 0;
1759 : :
1760 : : pfc_setup_fail:
1761 : 0 : hw->requested_fc_mode = old_fc_mode;
1762 : 0 : hw->current_fc_status = fc_status;
1763 : 0 : pf->pause_time = pause_time;
1764 : 0 : buffer_alloc_fail:
1765 : 0 : hw->dcb_info.pfc_en = pfc_en;
1766 : 0 : hw->dcb_info.hw_pfc_map = hw_pfc_map;
1767 : :
1768 : 0 : return ret;
1769 : : }
1770 : :
1771 : : /*
1772 : : * hns3_fc_enable - Enable MAC pause
1773 : : * @dev: pointer to ethernet device
1774 : : *
1775 : : * Configures the MAC pause settings.
1776 : : */
1777 : : int
1778 : 0 : hns3_fc_enable(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1779 : : {
1780 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1781 : : struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1782 : 0 : enum hns3_fc_mode old_fc_mode = hw->requested_fc_mode;
1783 : 0 : enum hns3_fc_status fc_status = hw->current_fc_status;
1784 : 0 : uint16_t pause_time = pf->pause_time;
1785 : : int ret;
1786 : :
1787 : 0 : pf->pause_time = fc_conf->pause_time;
1788 : 0 : hns3_get_fc_mode(hw, fc_conf->mode);
1789 : :
1790 : : /*
1791 : : * In fact, current_fc_status is HNS3_FC_STATUS_NONE when mode
1792 : : * of flow control is configured to be HNS3_FC_NONE.
1793 : : */
1794 [ # # ]: 0 : if (hw->requested_fc_mode == HNS3_FC_NONE)
1795 : 0 : hw->current_fc_status = HNS3_FC_STATUS_NONE;
1796 : : else
1797 : 0 : hw->current_fc_status = HNS3_FC_STATUS_MAC_PAUSE;
1798 : :
1799 : 0 : ret = hns3_dcb_pause_setup_hw(hw);
1800 [ # # ]: 0 : if (ret) {
1801 : 0 : hns3_err(hw, "enable MAC Pause failed! ret = %d", ret);
1802 : 0 : goto setup_fc_fail;
1803 : : }
1804 : :
1805 : : return 0;
1806 : :
1807 : : setup_fc_fail:
1808 : 0 : hw->requested_fc_mode = old_fc_mode;
1809 : 0 : hw->current_fc_status = fc_status;
1810 : 0 : pf->pause_time = pause_time;
1811 : :
1812 : 0 : return ret;
1813 : : }
|