1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2019 Hisilicon Limited.
6 #include <rte_ethdev.h>
9 #include "hns3_ethdev.h"
12 #define HNS3_SHAPER_BS_U_DEF 5
13 #define HNS3_SHAPER_BS_S_DEF 20
14 #define BW_MAX_PERCENT 100
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
24 * IR_b * (2 ^ IR_u) * 8
25 * IR(Mbps) = ------------------------- * CLOCK(1000Mbps)
28 * @return: 0: calculate sucessful, negative: fail
31 hns3_shaper_para_calc(struct hns3_hw *hw, uint32_t ir, uint8_t shaper_level,
32 struct hns3_shaper_parameter *shaper_para)
34 #define SHAPER_DEFAULT_IR_B 126
35 #define DIVISOR_CLK (1000 * 8)
36 #define DIVISOR_IR_B_126 (126 * DIVISOR_CLK)
38 const uint16_t tick_array[HNS3_SHAPER_LVL_CNT] = {
39 6 * 256, /* Prioriy level */
40 6 * 32, /* Prioriy group level */
41 6 * 8, /* Port level */
42 6 * 256 /* Qset level */
44 uint8_t ir_u_calc = 0;
45 uint8_t ir_s_calc = 0;
51 if (shaper_level >= HNS3_SHAPER_LVL_CNT) {
53 "shaper_level(%u) is greater than HNS3_SHAPER_LVL_CNT(%d)",
54 shaper_level, HNS3_SHAPER_LVL_CNT);
58 if (ir > hw->max_tm_rate) {
59 hns3_err(hw, "rate(%u) exceeds the max rate(%u) driver "
60 "supported.", ir, hw->max_tm_rate);
64 tick = tick_array[shaper_level];
67 * Calc the speed if ir_b = 126, ir_u = 0 and ir_s = 0
68 * the formula is changed to:
70 * ir_calc = ---------------- * 1000
73 ir_calc = (DIVISOR_IR_B_126 + (tick >> 1) - 1) / tick;
76 shaper_para->ir_b = SHAPER_DEFAULT_IR_B;
77 } else if (ir_calc > ir) {
78 /* Increasing the denominator to select ir_s value */
79 while (ir_calc >= ir && ir) {
81 ir_calc = DIVISOR_IR_B_126 / (tick * (1 << ir_s_calc));
84 shaper_para->ir_b = (ir * tick * (1 << ir_s_calc) +
85 (DIVISOR_CLK >> 1)) / DIVISOR_CLK;
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
98 numerator = DIVISOR_IR_B_126 * (1 << ir_u_calc);
99 ir_calc = (numerator + (tick >> 1)) / tick;
100 } while (ir_calc < ir);
103 shaper_para->ir_b = SHAPER_DEFAULT_IR_B;
108 * The maximum value of ir_u_calc in this branch is
109 * seven in all cases. Thus, value of denominator can
112 denominator = DIVISOR_CLK * (1 << ir_u_calc);
114 (ir * tick + (denominator >> 1)) / denominator;
118 shaper_para->ir_u = ir_u_calc;
119 shaper_para->ir_s = ir_s_calc;
125 hns3_fill_pri_array(struct hns3_hw *hw, uint8_t *pri, uint8_t pri_id)
127 #define HNS3_HALF_BYTE_BIT_OFFSET 4
128 uint8_t tc = hw->dcb_info.prio_tc[pri_id];
130 if (tc >= hw->dcb_info.num_tc)
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 |
142 pri[pri_id >> 1] |= tc << ((pri_id & 1) * HNS3_HALF_BYTE_BIT_OFFSET);
148 hns3_up_to_tc_map(struct hns3_hw *hw)
150 struct hns3_cmd_desc desc;
151 uint8_t *pri = (uint8_t *)desc.data;
155 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_PRI_TO_TC_MAPPING, false);
157 for (pri_id = 0; pri_id < HNS3_MAX_USER_PRIO; pri_id++) {
158 ret = hns3_fill_pri_array(hw, pri, pri_id);
163 return hns3_cmd_send(hw, &desc, 1);
167 hns3_pg_to_pri_map_cfg(struct hns3_hw *hw, uint8_t pg_id, uint8_t pri_bit_map)
169 struct hns3_pg_to_pri_link_cmd *map;
170 struct hns3_cmd_desc desc;
172 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_TO_PRI_LINK, false);
174 map = (struct hns3_pg_to_pri_link_cmd *)desc.data;
177 map->pri_bit_map = pri_bit_map;
179 return hns3_cmd_send(hw, &desc, 1);
183 hns3_pg_to_pri_map(struct hns3_hw *hw)
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;
190 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
193 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 ret = hns3_pg_to_pri_map_cfg(hw, i, pg_info->tc_bit_map);
205 hns3_qs_to_pri_map_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t pri)
207 struct hns3_qs_to_pri_link_cmd *map;
208 struct hns3_cmd_desc desc;
210 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_TO_PRI_LINK, false);
212 map = (struct hns3_qs_to_pri_link_cmd *)desc.data;
214 map->qs_id = rte_cpu_to_le_16(qs_id);
216 map->link_vld = HNS3_DCB_QS_PRI_LINK_VLD_MSK;
218 return hns3_cmd_send(hw, &desc, 1);
222 hns3_dcb_qs_weight_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t dwrr)
224 struct hns3_qs_weight_cmd *weight;
225 struct hns3_cmd_desc desc;
227 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_WEIGHT, false);
229 weight = (struct hns3_qs_weight_cmd *)desc.data;
231 weight->qs_id = rte_cpu_to_le_16(qs_id);
234 return hns3_cmd_send(hw, &desc, 1);
238 hns3_dcb_ets_tc_dwrr_cfg(struct hns3_hw *hw)
240 #define DEFAULT_TC_WEIGHT 1
241 #define DEFAULT_TC_OFFSET 14
242 struct hns3_ets_tc_weight_cmd *ets_weight;
243 struct hns3_cmd_desc desc;
246 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_ETS_TC_WEIGHT, false);
247 ets_weight = (struct hns3_ets_tc_weight_cmd *)desc.data;
249 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
250 struct hns3_pg_info *pg_info;
252 ets_weight->tc_weight[i] = DEFAULT_TC_WEIGHT;
254 if (!(hw->hw_tc_map & BIT(i)))
257 pg_info = &hw->dcb_info.pg_info[hw->dcb_info.tc_info[i].pgid];
258 ets_weight->tc_weight[i] = pg_info->tc_dwrr[i];
261 ets_weight->weight_offset = DEFAULT_TC_OFFSET;
263 return hns3_cmd_send(hw, &desc, 1);
267 hns3_dcb_pri_weight_cfg(struct hns3_hw *hw, uint8_t pri_id, uint8_t dwrr)
269 struct hns3_priority_weight_cmd *weight;
270 struct hns3_cmd_desc desc;
272 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PRI_WEIGHT, false);
274 weight = (struct hns3_priority_weight_cmd *)desc.data;
276 weight->pri_id = pri_id;
279 return hns3_cmd_send(hw, &desc, 1);
283 hns3_dcb_pg_weight_cfg(struct hns3_hw *hw, uint8_t pg_id, uint8_t dwrr)
285 struct hns3_pg_weight_cmd *weight;
286 struct hns3_cmd_desc desc;
288 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_WEIGHT, false);
290 weight = (struct hns3_pg_weight_cmd *)desc.data;
292 weight->pg_id = pg_id;
295 return hns3_cmd_send(hw, &desc, 1);
298 hns3_dcb_pg_schd_mode_cfg(struct hns3_hw *hw, uint8_t pg_id)
300 struct hns3_cmd_desc desc;
302 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_SCH_MODE_CFG, false);
304 if (hw->dcb_info.pg_info[pg_id].pg_sch_mode == HNS3_SCH_MODE_DWRR)
305 desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
309 desc.data[0] = rte_cpu_to_le_32(pg_id);
311 return hns3_cmd_send(hw, &desc, 1);
315 hns3_dcb_get_shapping_para(uint8_t ir_b, uint8_t ir_u, uint8_t ir_s,
316 uint8_t bs_b, uint8_t bs_s)
318 uint32_t shapping_para = 0;
320 /* If ir_b is zero it means IR is 0Mbps, return zero of shapping_para */
322 return shapping_para;
324 hns3_dcb_set_field(shapping_para, IR_B, ir_b);
325 hns3_dcb_set_field(shapping_para, IR_U, ir_u);
326 hns3_dcb_set_field(shapping_para, IR_S, ir_s);
327 hns3_dcb_set_field(shapping_para, BS_B, bs_b);
328 hns3_dcb_set_field(shapping_para, BS_S, bs_s);
330 return shapping_para;
334 hns3_dcb_port_shaper_cfg(struct hns3_hw *hw, uint32_t speed)
336 struct hns3_port_shapping_cmd *shap_cfg_cmd;
337 struct hns3_shaper_parameter shaper_parameter;
338 uint32_t shapping_para;
339 uint32_t ir_u, ir_b, ir_s;
340 struct hns3_cmd_desc desc;
343 ret = hns3_shaper_para_calc(hw, speed,
344 HNS3_SHAPER_LVL_PORT, &shaper_parameter);
346 hns3_err(hw, "calculate shaper parameter failed: %d", ret);
350 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PORT_SHAPPING, false);
351 shap_cfg_cmd = (struct hns3_port_shapping_cmd *)desc.data;
353 ir_b = shaper_parameter.ir_b;
354 ir_u = shaper_parameter.ir_u;
355 ir_s = shaper_parameter.ir_s;
356 shapping_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
357 HNS3_SHAPER_BS_U_DEF,
358 HNS3_SHAPER_BS_S_DEF);
360 shap_cfg_cmd->port_shapping_para = rte_cpu_to_le_32(shapping_para);
363 * Configure the port_rate and set bit HNS3_TM_RATE_VLD_B of flag
364 * field in hns3_port_shapping_cmd to require firmware to recalculate
365 * shapping parameters. And whether the parameters are recalculated
366 * depends on the firmware version. But driver still needs to
367 * calculate it and configure to firmware for better compatibility.
369 shap_cfg_cmd->port_rate = rte_cpu_to_le_32(speed);
370 hns3_set_bit(shap_cfg_cmd->flag, HNS3_TM_RATE_VLD_B, 1);
372 return hns3_cmd_send(hw, &desc, 1);
376 hns3_port_shaper_update(struct hns3_hw *hw, uint32_t speed)
380 ret = hns3_dcb_port_shaper_cfg(hw, speed);
382 hns3_err(hw, "configure port shappering failed: ret = %d", ret);
388 hns3_dcb_pg_shapping_cfg(struct hns3_hw *hw, enum hns3_shap_bucket bucket,
389 uint8_t pg_id, uint32_t shapping_para, uint32_t rate)
391 struct hns3_pg_shapping_cmd *shap_cfg_cmd;
392 enum hns3_opcode_type opcode;
393 struct hns3_cmd_desc desc;
395 opcode = bucket ? HNS3_OPC_TM_PG_P_SHAPPING :
396 HNS3_OPC_TM_PG_C_SHAPPING;
397 hns3_cmd_setup_basic_desc(&desc, opcode, false);
399 shap_cfg_cmd = (struct hns3_pg_shapping_cmd *)desc.data;
401 shap_cfg_cmd->pg_id = pg_id;
403 shap_cfg_cmd->pg_shapping_para = rte_cpu_to_le_32(shapping_para);
406 * Configure the pg_rate and set bit HNS3_TM_RATE_VLD_B of flag field in
407 * hns3_pg_shapping_cmd to require firmware to recalculate shapping
408 * parameters. And whether parameters are recalculated depends on
409 * the firmware version. But driver still needs to calculate it and
410 * configure to firmware for better compatibility.
412 shap_cfg_cmd->pg_rate = rte_cpu_to_le_32(rate);
413 hns3_set_bit(shap_cfg_cmd->flag, HNS3_TM_RATE_VLD_B, 1);
415 return hns3_cmd_send(hw, &desc, 1);
419 hns3_pg_shaper_rate_cfg(struct hns3_hw *hw, uint8_t pg_id, uint32_t rate)
421 struct hns3_shaper_parameter shaper_parameter;
422 uint32_t ir_u, ir_b, ir_s;
423 uint32_t shaper_para;
426 /* Calc shaper para */
427 ret = hns3_shaper_para_calc(hw, rate, HNS3_SHAPER_LVL_PG,
430 hns3_err(hw, "calculate shaper parameter fail, ret = %d.",
435 shaper_para = hns3_dcb_get_shapping_para(0, 0, 0,
436 HNS3_SHAPER_BS_U_DEF,
437 HNS3_SHAPER_BS_S_DEF);
439 ret = hns3_dcb_pg_shapping_cfg(hw, HNS3_DCB_SHAP_C_BUCKET, pg_id,
442 hns3_err(hw, "config PG CIR shaper parameter fail, ret = %d.",
447 ir_b = shaper_parameter.ir_b;
448 ir_u = shaper_parameter.ir_u;
449 ir_s = shaper_parameter.ir_s;
450 shaper_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
451 HNS3_SHAPER_BS_U_DEF,
452 HNS3_SHAPER_BS_S_DEF);
454 ret = hns3_dcb_pg_shapping_cfg(hw, HNS3_DCB_SHAP_P_BUCKET, pg_id,
457 hns3_err(hw, "config PG PIR shaper parameter fail, ret = %d.",
466 hns3_dcb_pg_shaper_cfg(struct hns3_hw *hw)
468 struct hns3_pf *pf = HNS3_DEV_HW_TO_PF(hw);
474 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
478 for (i = 0; i < hw->dcb_info.num_pg; i++) {
479 rate = hw->dcb_info.pg_info[i].bw_limit;
480 ret = hns3_pg_shaper_rate_cfg(hw, i, rate);
489 hns3_dcb_qs_schd_mode_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t mode)
491 struct hns3_cmd_desc desc;
493 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_SCH_MODE_CFG, false);
495 if (mode == HNS3_SCH_MODE_DWRR)
496 desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
500 desc.data[0] = rte_cpu_to_le_32(qs_id);
502 return hns3_cmd_send(hw, &desc, 1);
506 hns3_dcb_pri_schd_mode_cfg(struct hns3_hw *hw, uint8_t pri_id)
508 struct hns3_cmd_desc desc;
510 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PRI_SCH_MODE_CFG, false);
512 if (hw->dcb_info.tc_info[pri_id].tc_sch_mode == HNS3_SCH_MODE_DWRR)
513 desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
517 desc.data[0] = rte_cpu_to_le_32(pri_id);
519 return hns3_cmd_send(hw, &desc, 1);
523 hns3_dcb_pri_shapping_cfg(struct hns3_hw *hw, enum hns3_shap_bucket bucket,
524 uint8_t pri_id, uint32_t shapping_para, uint32_t rate)
526 struct hns3_pri_shapping_cmd *shap_cfg_cmd;
527 enum hns3_opcode_type opcode;
528 struct hns3_cmd_desc desc;
530 opcode = bucket ? HNS3_OPC_TM_PRI_P_SHAPPING :
531 HNS3_OPC_TM_PRI_C_SHAPPING;
533 hns3_cmd_setup_basic_desc(&desc, opcode, false);
535 shap_cfg_cmd = (struct hns3_pri_shapping_cmd *)desc.data;
537 shap_cfg_cmd->pri_id = pri_id;
539 shap_cfg_cmd->pri_shapping_para = rte_cpu_to_le_32(shapping_para);
542 * Configure the pri_rate and set bit HNS3_TM_RATE_VLD_B of flag
543 * field in hns3_pri_shapping_cmd to require firmware to recalculate
544 * shapping parameters. And whether the parameters are recalculated
545 * depends on the firmware version. But driver still needs to
546 * calculate it and configure to firmware for better compatibility.
548 shap_cfg_cmd->pri_rate = rte_cpu_to_le_32(rate);
549 hns3_set_bit(shap_cfg_cmd->flag, HNS3_TM_RATE_VLD_B, 1);
551 return hns3_cmd_send(hw, &desc, 1);
555 hns3_pri_shaper_rate_cfg(struct hns3_hw *hw, uint8_t tc_no, uint32_t rate)
557 struct hns3_shaper_parameter shaper_parameter;
558 uint32_t ir_u, ir_b, ir_s;
559 uint32_t shaper_para;
562 ret = hns3_shaper_para_calc(hw, rate, HNS3_SHAPER_LVL_PRI,
565 hns3_err(hw, "calculate shaper parameter failed: %d.",
570 shaper_para = hns3_dcb_get_shapping_para(0, 0, 0,
571 HNS3_SHAPER_BS_U_DEF,
572 HNS3_SHAPER_BS_S_DEF);
574 ret = hns3_dcb_pri_shapping_cfg(hw, HNS3_DCB_SHAP_C_BUCKET, tc_no,
578 "config priority CIR shaper parameter failed: %d.",
583 ir_b = shaper_parameter.ir_b;
584 ir_u = shaper_parameter.ir_u;
585 ir_s = shaper_parameter.ir_s;
586 shaper_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
587 HNS3_SHAPER_BS_U_DEF,
588 HNS3_SHAPER_BS_S_DEF);
590 ret = hns3_dcb_pri_shapping_cfg(hw, HNS3_DCB_SHAP_P_BUCKET, tc_no,
594 "config priority PIR shaper parameter failed: %d.",
603 hns3_dcb_pri_shaper_cfg(struct hns3_hw *hw)
605 struct hns3_pf *pf = HNS3_DEV_HW_TO_PF(hw);
610 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
613 for (i = 0; i < hw->dcb_info.num_tc; i++) {
614 rate = hw->dcb_info.tc_info[i].bw_limit;
615 ret = hns3_pri_shaper_rate_cfg(hw, i, rate);
617 hns3_err(hw, "config pri shaper failed: %d.", ret);
626 hns3_set_rss_size(struct hns3_hw *hw, uint16_t nb_rx_q)
628 struct hns3_rss_conf *rss_cfg = &hw->rss_info;
629 uint16_t rx_qnum_per_tc;
630 uint16_t used_rx_queues;
633 rx_qnum_per_tc = nb_rx_q / hw->num_tc;
634 if (rx_qnum_per_tc > hw->rss_size_max) {
635 hns3_err(hw, "rx queue number of per tc (%u) is greater than "
636 "value (%u) hardware supported.",
637 rx_qnum_per_tc, hw->rss_size_max);
641 used_rx_queues = hw->num_tc * rx_qnum_per_tc;
642 if (used_rx_queues != nb_rx_q) {
643 hns3_err(hw, "rx queue number (%u) configured must be an "
644 "integral multiple of valid tc number (%u).",
645 nb_rx_q, hw->num_tc);
648 hw->alloc_rss_size = rx_qnum_per_tc;
649 hw->used_rx_queues = used_rx_queues;
652 * When rss size is changed, we need to update rss redirection table
653 * maintained by driver. Besides, during the entire reset process, we
654 * need to ensure that the rss table information are not overwritten
655 * and configured directly to the hardware in the RESET_STAGE_RESTORE
656 * stage of the reset process.
658 if (__atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED) == 0) {
659 for (i = 0; i < hw->rss_ind_tbl_size; i++)
660 rss_cfg->rss_indirection_tbl[i] =
661 i % hw->alloc_rss_size;
668 hns3_tc_queue_mapping_cfg(struct hns3_hw *hw, uint16_t nb_tx_q)
670 struct hns3_tc_queue_info *tc_queue;
671 uint16_t used_tx_queues;
672 uint16_t tx_qnum_per_tc;
675 tx_qnum_per_tc = nb_tx_q / hw->num_tc;
676 used_tx_queues = hw->num_tc * tx_qnum_per_tc;
677 if (used_tx_queues != nb_tx_q) {
678 hns3_err(hw, "tx queue number (%u) configured must be an "
679 "integral multiple of valid tc number (%u).",
680 nb_tx_q, hw->num_tc);
684 hw->used_tx_queues = used_tx_queues;
685 hw->tx_qnum_per_tc = tx_qnum_per_tc;
686 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
687 tc_queue = &hw->tc_queue[i];
688 if (hw->hw_tc_map & BIT(i) && i < hw->num_tc) {
689 tc_queue->enable = true;
690 tc_queue->tqp_offset = i * hw->tx_qnum_per_tc;
691 tc_queue->tqp_count = hw->tx_qnum_per_tc;
694 /* Set to default queue if TC is disable */
695 tc_queue->enable = false;
696 tc_queue->tqp_offset = 0;
697 tc_queue->tqp_count = 0;
706 hns3_txq_mapped_tc_get(struct hns3_hw *hw, uint16_t txq_no)
708 struct hns3_tc_queue_info *tc_queue;
711 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
712 tc_queue = &hw->tc_queue[i];
713 if (!tc_queue->enable)
716 if (txq_no >= tc_queue->tqp_offset &&
717 txq_no < tc_queue->tqp_offset + tc_queue->tqp_count)
721 /* return TC0 in default case */
726 hns3_queue_to_tc_mapping(struct hns3_hw *hw, uint16_t nb_rx_q, uint16_t nb_tx_q)
730 ret = hns3_set_rss_size(hw, nb_rx_q);
734 return hns3_tc_queue_mapping_cfg(hw, nb_tx_q);
738 hns3_dcb_update_tc_queue_mapping(struct hns3_hw *hw, uint16_t nb_rx_q,
741 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
742 struct hns3_pf *pf = &hns->pf;
745 hw->num_tc = hw->dcb_info.num_tc;
746 ret = hns3_queue_to_tc_mapping(hw, nb_rx_q, nb_tx_q);
751 memcpy(pf->prio_tc, hw->dcb_info.prio_tc, HNS3_MAX_USER_PRIO);
757 hns3_dcb_info_init(struct hns3_hw *hw)
759 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
760 struct hns3_pf *pf = &hns->pf;
763 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
764 hw->dcb_info.num_pg != 1)
767 /* Initializing PG information */
768 memset(hw->dcb_info.pg_info, 0,
769 sizeof(struct hns3_pg_info) * HNS3_PG_NUM);
770 for (i = 0; i < hw->dcb_info.num_pg; i++) {
771 hw->dcb_info.pg_dwrr[i] = i ? 0 : BW_MAX_PERCENT;
772 hw->dcb_info.pg_info[i].pg_id = i;
773 hw->dcb_info.pg_info[i].pg_sch_mode = HNS3_SCH_MODE_DWRR;
774 hw->dcb_info.pg_info[i].bw_limit = hw->max_tm_rate;
779 hw->dcb_info.pg_info[i].tc_bit_map = hw->hw_tc_map;
780 for (k = 0; k < hw->dcb_info.num_tc; k++)
781 hw->dcb_info.pg_info[i].tc_dwrr[k] = BW_MAX_PERCENT;
784 /* All UPs mapping to TC0 */
785 for (i = 0; i < HNS3_MAX_USER_PRIO; i++)
786 hw->dcb_info.prio_tc[i] = 0;
788 /* Initializing tc information */
789 memset(hw->dcb_info.tc_info, 0,
790 sizeof(struct hns3_tc_info) * HNS3_MAX_TC_NUM);
791 for (i = 0; i < hw->dcb_info.num_tc; i++) {
792 hw->dcb_info.tc_info[i].tc_id = i;
793 hw->dcb_info.tc_info[i].tc_sch_mode = HNS3_SCH_MODE_DWRR;
794 hw->dcb_info.tc_info[i].pgid = 0;
795 hw->dcb_info.tc_info[i].bw_limit =
796 hw->dcb_info.pg_info[0].bw_limit;
803 hns3_dcb_lvl2_schd_mode_cfg(struct hns3_hw *hw)
805 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
806 struct hns3_pf *pf = &hns->pf;
809 /* Only being config on TC-Based scheduler mode */
810 if (pf->tx_sch_mode == HNS3_FLAG_VNET_BASE_SCH_MODE)
813 for (i = 0; i < hw->dcb_info.num_pg; i++) {
814 ret = hns3_dcb_pg_schd_mode_cfg(hw, i);
823 hns3_dcb_lvl34_schd_mode_cfg(struct hns3_hw *hw)
825 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
826 struct hns3_pf *pf = &hns->pf;
830 if (pf->tx_sch_mode == HNS3_FLAG_TC_BASE_SCH_MODE) {
831 for (i = 0; i < hw->dcb_info.num_tc; i++) {
832 ret = hns3_dcb_pri_schd_mode_cfg(hw, i);
836 ret = hns3_dcb_qs_schd_mode_cfg(hw, i,
847 hns3_dcb_schd_mode_cfg(struct hns3_hw *hw)
851 ret = hns3_dcb_lvl2_schd_mode_cfg(hw);
853 hns3_err(hw, "config lvl2_schd_mode failed: %d", ret);
857 ret = hns3_dcb_lvl34_schd_mode_cfg(hw);
859 hns3_err(hw, "config lvl34_schd_mode failed: %d", ret);
865 hns3_dcb_pri_tc_base_dwrr_cfg(struct hns3_hw *hw)
867 struct hns3_pg_info *pg_info;
871 for (i = 0; i < hw->dcb_info.num_tc; i++) {
872 pg_info = &hw->dcb_info.pg_info[hw->dcb_info.tc_info[i].pgid];
873 dwrr = pg_info->tc_dwrr[i];
875 ret = hns3_dcb_pri_weight_cfg(hw, i, dwrr);
878 "fail to send priority weight cmd: %d, ret = %d",
883 ret = hns3_dcb_qs_weight_cfg(hw, i, BW_MAX_PERCENT);
885 hns3_err(hw, "fail to send qs_weight cmd: %d, ret = %d",
895 hns3_dcb_pri_dwrr_cfg(struct hns3_hw *hw)
897 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
898 struct hns3_pf *pf = &hns->pf;
902 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
905 ret = hns3_dcb_pri_tc_base_dwrr_cfg(hw);
909 if (!hns3_dev_dcb_supported(hw))
912 ret = hns3_dcb_ets_tc_dwrr_cfg(hw);
913 if (ret == -EOPNOTSUPP) {
914 version = hw->fw_version;
916 "fw %lu.%lu.%lu.%lu doesn't support ets tc weight cmd",
917 hns3_get_field(version, HNS3_FW_VERSION_BYTE3_M,
918 HNS3_FW_VERSION_BYTE3_S),
919 hns3_get_field(version, HNS3_FW_VERSION_BYTE2_M,
920 HNS3_FW_VERSION_BYTE2_S),
921 hns3_get_field(version, HNS3_FW_VERSION_BYTE1_M,
922 HNS3_FW_VERSION_BYTE1_S),
923 hns3_get_field(version, HNS3_FW_VERSION_BYTE0_M,
924 HNS3_FW_VERSION_BYTE0_S));
932 hns3_dcb_pg_dwrr_cfg(struct hns3_hw *hw)
934 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
935 struct hns3_pf *pf = &hns->pf;
939 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
943 for (i = 0; i < hw->dcb_info.num_pg; i++) {
945 ret = hns3_dcb_pg_weight_cfg(hw, i, hw->dcb_info.pg_dwrr[i]);
954 hns3_dcb_dwrr_cfg(struct hns3_hw *hw)
958 ret = hns3_dcb_pg_dwrr_cfg(hw);
960 hns3_err(hw, "config pg_dwrr failed: %d", ret);
964 ret = hns3_dcb_pri_dwrr_cfg(hw);
966 hns3_err(hw, "config pri_dwrr failed: %d", ret);
972 hns3_dcb_shaper_cfg(struct hns3_hw *hw)
976 ret = hns3_dcb_port_shaper_cfg(hw, hw->mac.link_speed);
978 hns3_err(hw, "config port shaper failed: %d", ret);
982 ret = hns3_dcb_pg_shaper_cfg(hw);
984 hns3_err(hw, "config pg shaper failed: %d", ret);
988 return hns3_dcb_pri_shaper_cfg(hw);
992 hns3_q_to_qs_map_cfg(struct hns3_hw *hw, uint16_t q_id, uint16_t qs_id)
994 struct hns3_nq_to_qs_link_cmd *map;
995 struct hns3_cmd_desc desc;
996 uint16_t tmp_qs_id = 0;
1000 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_NQ_TO_QS_LINK, false);
1002 map = (struct hns3_nq_to_qs_link_cmd *)desc.data;
1004 map->nq_id = rte_cpu_to_le_16(q_id);
1007 * Network engine with revision_id 0x21 uses 0~9 bit of qs_id to
1008 * configure qset_id. So we need to convert qs_id to the follow
1009 * format to support qset_id > 1024.
1010 * qs_id: | 15 | 14 ~ 10 | 9 ~ 0 |
1013 * qset_id: | 15 ~ 11 | 10 | 9 ~ 0 |
1014 * | qs_id_h | vld | qs_id_l |
1016 qs_id_l = hns3_get_field(qs_id, HNS3_DCB_QS_ID_L_MSK,
1017 HNS3_DCB_QS_ID_L_S);
1018 qs_id_h = hns3_get_field(qs_id, HNS3_DCB_QS_ID_H_MSK,
1019 HNS3_DCB_QS_ID_H_S);
1020 hns3_set_field(tmp_qs_id, HNS3_DCB_QS_ID_L_MSK, HNS3_DCB_QS_ID_L_S,
1022 hns3_set_field(tmp_qs_id, HNS3_DCB_QS_ID_H_EXT_MSK,
1023 HNS3_DCB_QS_ID_H_EXT_S, qs_id_h);
1024 map->qset_id = rte_cpu_to_le_16(tmp_qs_id | HNS3_DCB_Q_QS_LINK_VLD_MSK);
1026 return hns3_cmd_send(hw, &desc, 1);
1030 hns3_q_to_qs_map(struct hns3_hw *hw)
1032 struct hns3_tc_queue_info *tc_queue;
1037 for (i = 0; i < hw->num_tc; i++) {
1038 tc_queue = &hw->tc_queue[i];
1039 for (j = 0; j < tc_queue->tqp_count; j++) {
1040 q_id = tc_queue->tqp_offset + j;
1041 ret = hns3_q_to_qs_map_cfg(hw, q_id, i);
1051 hns3_pri_q_qs_cfg(struct hns3_hw *hw)
1053 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1054 struct hns3_pf *pf = &hns->pf;
1058 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
1061 /* Cfg qs -> pri mapping */
1062 for (i = 0; i < hw->num_tc; i++) {
1063 ret = hns3_qs_to_pri_map_cfg(hw, i, i);
1065 hns3_err(hw, "qs_to_pri mapping fail: %d", ret);
1070 /* Cfg q -> qs mapping */
1071 ret = hns3_q_to_qs_map(hw);
1073 hns3_err(hw, "nq_to_qs mapping fail: %d", ret);
1079 hns3_dcb_map_cfg(struct hns3_hw *hw)
1083 ret = hns3_up_to_tc_map(hw);
1085 hns3_err(hw, "up_to_tc mapping fail: %d", ret);
1089 ret = hns3_pg_to_pri_map(hw);
1091 hns3_err(hw, "pri_to_pg mapping fail: %d", ret);
1095 return hns3_pri_q_qs_cfg(hw);
1099 hns3_dcb_schd_setup_hw(struct hns3_hw *hw)
1103 /* Cfg dcb mapping */
1104 ret = hns3_dcb_map_cfg(hw);
1108 /* Cfg dcb shaper */
1109 ret = hns3_dcb_shaper_cfg(hw);
1114 ret = hns3_dcb_dwrr_cfg(hw);
1118 /* Cfg schd mode for each level schd */
1119 return hns3_dcb_schd_mode_cfg(hw);
1123 hns3_pause_param_cfg(struct hns3_hw *hw, const uint8_t *addr,
1124 uint8_t pause_trans_gap, uint16_t pause_trans_time)
1126 struct hns3_cfg_pause_param_cmd *pause_param;
1127 struct hns3_cmd_desc desc;
1129 pause_param = (struct hns3_cfg_pause_param_cmd *)desc.data;
1131 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PARA, false);
1133 memcpy(pause_param->mac_addr, addr, RTE_ETHER_ADDR_LEN);
1134 memcpy(pause_param->mac_addr_extra, addr, RTE_ETHER_ADDR_LEN);
1135 pause_param->pause_trans_gap = pause_trans_gap;
1136 pause_param->pause_trans_time = rte_cpu_to_le_16(pause_trans_time);
1138 return hns3_cmd_send(hw, &desc, 1);
1142 hns3_pause_addr_cfg(struct hns3_hw *hw, const uint8_t *mac_addr)
1144 struct hns3_cfg_pause_param_cmd *pause_param;
1145 struct hns3_cmd_desc desc;
1146 uint16_t trans_time;
1150 pause_param = (struct hns3_cfg_pause_param_cmd *)desc.data;
1152 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PARA, true);
1154 ret = hns3_cmd_send(hw, &desc, 1);
1158 trans_gap = pause_param->pause_trans_gap;
1159 trans_time = rte_le_to_cpu_16(pause_param->pause_trans_time);
1161 return hns3_pause_param_cfg(hw, mac_addr, trans_gap, trans_time);
1165 hns3_pause_param_setup_hw(struct hns3_hw *hw, uint16_t pause_time)
1167 #define PAUSE_TIME_DIV_BY 2
1168 #define PAUSE_TIME_MIN_VALUE 0x4
1170 struct hns3_mac *mac = &hw->mac;
1171 uint8_t pause_trans_gap;
1174 * Pause transmit gap must be less than "pause_time / 2", otherwise
1175 * the behavior of MAC is undefined.
1177 if (pause_time > PAUSE_TIME_DIV_BY * HNS3_DEFAULT_PAUSE_TRANS_GAP)
1178 pause_trans_gap = HNS3_DEFAULT_PAUSE_TRANS_GAP;
1179 else if (pause_time >= PAUSE_TIME_MIN_VALUE &&
1180 pause_time <= PAUSE_TIME_DIV_BY * HNS3_DEFAULT_PAUSE_TRANS_GAP)
1181 pause_trans_gap = pause_time / PAUSE_TIME_DIV_BY - 1;
1183 hns3_warn(hw, "pause_time(%u) is adjusted to 4", pause_time);
1184 pause_time = PAUSE_TIME_MIN_VALUE;
1185 pause_trans_gap = pause_time / PAUSE_TIME_DIV_BY - 1;
1188 return hns3_pause_param_cfg(hw, mac->mac_addr,
1189 pause_trans_gap, pause_time);
1193 hns3_mac_pause_en_cfg(struct hns3_hw *hw, bool tx, bool rx)
1195 struct hns3_cmd_desc desc;
1197 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PAUSE_EN, false);
1199 desc.data[0] = rte_cpu_to_le_32((tx ? HNS3_TX_MAC_PAUSE_EN_MSK : 0) |
1200 (rx ? HNS3_RX_MAC_PAUSE_EN_MSK : 0));
1202 return hns3_cmd_send(hw, &desc, 1);
1206 hns3_pfc_pause_en_cfg(struct hns3_hw *hw, uint8_t pfc_bitmap, bool tx, bool rx)
1208 struct hns3_cmd_desc desc;
1209 struct hns3_pfc_en_cmd *pfc = (struct hns3_pfc_en_cmd *)desc.data;
1211 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_PFC_PAUSE_EN, false);
1213 pfc->tx_rx_en_bitmap = (uint8_t)((tx ? HNS3_TX_MAC_PAUSE_EN_MSK : 0) |
1214 (rx ? HNS3_RX_MAC_PAUSE_EN_MSK : 0));
1216 pfc->pri_en_bitmap = pfc_bitmap;
1218 return hns3_cmd_send(hw, &desc, 1);
1222 hns3_qs_bp_cfg(struct hns3_hw *hw, uint8_t tc, uint8_t grp_id, uint32_t bit_map)
1224 struct hns3_bp_to_qs_map_cmd *bp_to_qs_map_cmd;
1225 struct hns3_cmd_desc desc;
1227 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_BP_TO_QSET_MAPPING, false);
1229 bp_to_qs_map_cmd = (struct hns3_bp_to_qs_map_cmd *)desc.data;
1231 bp_to_qs_map_cmd->tc_id = tc;
1232 bp_to_qs_map_cmd->qs_group_id = grp_id;
1233 bp_to_qs_map_cmd->qs_bit_map = rte_cpu_to_le_32(bit_map);
1235 return hns3_cmd_send(hw, &desc, 1);
1239 hns3_get_rx_tx_en_status(struct hns3_hw *hw, bool *tx_en, bool *rx_en)
1241 switch (hw->current_mode) {
1246 case HNS3_FC_RX_PAUSE:
1250 case HNS3_FC_TX_PAUSE:
1266 hns3_mac_pause_setup_hw(struct hns3_hw *hw)
1270 if (hw->current_fc_status == HNS3_FC_STATUS_MAC_PAUSE)
1271 hns3_get_rx_tx_en_status(hw, &tx_en, &rx_en);
1277 return hns3_mac_pause_en_cfg(hw, tx_en, rx_en);
1281 hns3_pfc_setup_hw(struct hns3_hw *hw)
1285 if (hw->current_fc_status == HNS3_FC_STATUS_PFC)
1286 hns3_get_rx_tx_en_status(hw, &tx_en, &rx_en);
1292 return hns3_pfc_pause_en_cfg(hw, hw->dcb_info.pfc_en, tx_en, rx_en);
1296 * Each Tc has a 1024 queue sets to backpress, it divides to
1297 * 32 group, each group contains 32 queue sets, which can be
1298 * represented by uint32_t bitmap.
1301 hns3_bp_setup_hw(struct hns3_hw *hw, uint8_t tc)
1307 for (i = 0; i < HNS3_BP_GRP_NUM; i++) {
1308 uint8_t grp, sub_grp;
1311 grp = hns3_get_field(tc, HNS3_BP_GRP_ID_M, HNS3_BP_GRP_ID_S);
1312 sub_grp = hns3_get_field(tc, HNS3_BP_SUB_GRP_ID_M,
1313 HNS3_BP_SUB_GRP_ID_S);
1315 qs_bitmap |= (1 << sub_grp);
1317 ret = hns3_qs_bp_cfg(hw, tc, i, qs_bitmap);
1326 hns3_dcb_bp_setup(struct hns3_hw *hw)
1330 for (i = 0; i < hw->dcb_info.num_tc; i++) {
1331 ret = hns3_bp_setup_hw(hw, i);
1340 hns3_dcb_pause_setup_hw(struct hns3_hw *hw)
1342 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1343 struct hns3_pf *pf = &hns->pf;
1346 ret = hns3_pause_param_setup_hw(hw, pf->pause_time);
1348 hns3_err(hw, "Fail to set pause parameter. ret = %d", ret);
1352 ret = hns3_mac_pause_setup_hw(hw);
1354 hns3_err(hw, "Fail to setup MAC pause. ret = %d", ret);
1358 /* Only DCB-supported dev supports qset back pressure and pfc cmd */
1359 if (!hns3_dev_dcb_supported(hw))
1362 ret = hns3_pfc_setup_hw(hw);
1364 hns3_err(hw, "config pfc failed! ret = %d", ret);
1368 return hns3_dcb_bp_setup(hw);
1372 hns3_dcb_undrop_tc_map(struct hns3_hw *hw, uint8_t pfc_en)
1374 uint8_t pfc_map = 0;
1378 prio_tc = hw->dcb_info.prio_tc;
1379 for (i = 0; i < hw->dcb_info.num_tc; i++) {
1380 for (j = 0; j < HNS3_MAX_USER_PRIO; j++) {
1381 if (prio_tc[j] == i && pfc_en & BIT(j)) {
1392 hns3_dcb_cfg_validate(struct hns3_adapter *hns, uint8_t *tc, bool *changed)
1394 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
1395 struct hns3_hw *hw = &hns->hw;
1396 uint16_t nb_rx_q = hw->data->nb_rx_queues;
1397 uint16_t nb_tx_q = hw->data->nb_tx_queues;
1402 dcb_rx_conf = &hw->data->dev_conf.rx_adv_conf.dcb_rx_conf;
1403 for (i = 0; i < HNS3_MAX_USER_PRIO; i++) {
1404 if (dcb_rx_conf->dcb_tc[i] != hw->dcb_info.prio_tc[i])
1407 if (dcb_rx_conf->dcb_tc[i] > max_tc)
1408 max_tc = dcb_rx_conf->dcb_tc[i];
1411 if (*tc != hw->dcb_info.num_tc)
1415 * We ensure that dcb information can be reconfigured
1416 * after the hns3_priority_flow_ctrl_set function called.
1418 if (hw->current_mode != HNS3_FC_FULL)
1420 pfc_en = RTE_LEN2MASK((uint8_t)dcb_rx_conf->nb_tcs, uint8_t);
1421 if (hw->dcb_info.pfc_en != pfc_en)
1424 /* tx/rx queue number is reconfigured. */
1425 if (nb_rx_q != hw->used_rx_queues || nb_tx_q != hw->used_tx_queues)
1430 hns3_dcb_info_cfg(struct hns3_adapter *hns)
1432 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
1433 struct hns3_pf *pf = &hns->pf;
1434 struct hns3_hw *hw = &hns->hw;
1435 uint8_t tc_bw, bw_rest;
1439 dcb_rx_conf = &hw->data->dev_conf.rx_adv_conf.dcb_rx_conf;
1440 pf->local_max_tc = (uint8_t)dcb_rx_conf->nb_tcs;
1441 pf->pfc_max = (uint8_t)dcb_rx_conf->nb_tcs;
1444 memset(hw->dcb_info.pg_info, 0,
1445 sizeof(struct hns3_pg_info) * HNS3_PG_NUM);
1446 hw->dcb_info.pg_dwrr[0] = BW_MAX_PERCENT;
1447 hw->dcb_info.pg_info[0].pg_id = 0;
1448 hw->dcb_info.pg_info[0].pg_sch_mode = HNS3_SCH_MODE_DWRR;
1449 hw->dcb_info.pg_info[0].bw_limit = hw->max_tm_rate;
1450 hw->dcb_info.pg_info[0].tc_bit_map = hw->hw_tc_map;
1452 /* Each tc has same bw for valid tc by default */
1453 tc_bw = BW_MAX_PERCENT / hw->dcb_info.num_tc;
1454 for (i = 0; i < hw->dcb_info.num_tc; i++)
1455 hw->dcb_info.pg_info[0].tc_dwrr[i] = tc_bw;
1456 /* To ensure the sum of tc_dwrr is equal to 100 */
1457 bw_rest = BW_MAX_PERCENT % hw->dcb_info.num_tc;
1458 for (j = 0; j < bw_rest; j++)
1459 hw->dcb_info.pg_info[0].tc_dwrr[j]++;
1460 for (; i < dcb_rx_conf->nb_tcs; i++)
1461 hw->dcb_info.pg_info[0].tc_dwrr[i] = 0;
1463 /* All tcs map to pg0 */
1464 memset(hw->dcb_info.tc_info, 0,
1465 sizeof(struct hns3_tc_info) * HNS3_MAX_TC_NUM);
1466 for (i = 0; i < hw->dcb_info.num_tc; i++) {
1467 hw->dcb_info.tc_info[i].tc_id = i;
1468 hw->dcb_info.tc_info[i].tc_sch_mode = HNS3_SCH_MODE_DWRR;
1469 hw->dcb_info.tc_info[i].pgid = 0;
1470 hw->dcb_info.tc_info[i].bw_limit =
1471 hw->dcb_info.pg_info[0].bw_limit;
1474 for (i = 0; i < HNS3_MAX_USER_PRIO; i++)
1475 hw->dcb_info.prio_tc[i] = dcb_rx_conf->dcb_tc[i];
1477 ret = hns3_dcb_update_tc_queue_mapping(hw, hw->data->nb_rx_queues,
1478 hw->data->nb_tx_queues);
1480 hns3_err(hw, "update tc queue mapping failed, ret = %d.", ret);
1486 hns3_dcb_info_update(struct hns3_adapter *hns, uint8_t num_tc)
1488 struct hns3_pf *pf = &hns->pf;
1489 struct hns3_hw *hw = &hns->hw;
1490 uint16_t nb_rx_q = hw->data->nb_rx_queues;
1491 uint16_t nb_tx_q = hw->data->nb_tx_queues;
1492 uint8_t bit_map = 0;
1495 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
1496 hw->dcb_info.num_pg != 1)
1499 if (nb_rx_q < num_tc) {
1500 hns3_err(hw, "number of Rx queues(%u) is less than tcs(%u).",
1505 if (nb_tx_q < num_tc) {
1506 hns3_err(hw, "number of Tx queues(%u) is less than tcs(%u).",
1511 /* Currently not support uncontinuous tc */
1512 hw->dcb_info.num_tc = num_tc;
1513 for (i = 0; i < hw->dcb_info.num_tc; i++)
1518 hw->dcb_info.num_tc = 1;
1520 hw->hw_tc_map = bit_map;
1522 return hns3_dcb_info_cfg(hns);
1526 hns3_dcb_hw_configure(struct hns3_adapter *hns)
1528 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
1529 struct hns3_pf *pf = &hns->pf;
1530 struct hns3_hw *hw = &hns->hw;
1531 enum hns3_fc_status fc_status = hw->current_fc_status;
1532 enum hns3_fc_mode current_mode = hw->current_mode;
1533 uint8_t hw_pfc_map = hw->dcb_info.hw_pfc_map;
1536 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
1537 pf->tx_sch_mode != HNS3_FLAG_VNET_BASE_SCH_MODE)
1540 ret = hns3_dcb_schd_setup_hw(hw);
1542 hns3_err(hw, "dcb schdule configure failed! ret = %d", ret);
1546 if (hw->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
1547 dcb_rx_conf = &hw->data->dev_conf.rx_adv_conf.dcb_rx_conf;
1548 if (dcb_rx_conf->nb_tcs == 0)
1549 hw->dcb_info.pfc_en = 1; /* tc0 only */
1551 hw->dcb_info.pfc_en =
1552 RTE_LEN2MASK((uint8_t)dcb_rx_conf->nb_tcs, uint8_t);
1554 hw->dcb_info.hw_pfc_map =
1555 hns3_dcb_undrop_tc_map(hw, hw->dcb_info.pfc_en);
1557 ret = hns3_buffer_alloc(hw);
1561 hw->current_fc_status = HNS3_FC_STATUS_PFC;
1562 hw->current_mode = HNS3_FC_FULL;
1563 ret = hns3_dcb_pause_setup_hw(hw);
1565 hns3_err(hw, "setup pfc failed! ret = %d", ret);
1566 goto pfc_setup_fail;
1570 * Although dcb_capability_en is lack of ETH_DCB_PFC_SUPPORT
1571 * flag, the DCB information is configured, such as tc numbers.
1572 * Therefore, refreshing the allocation of packet buffer is
1575 ret = hns3_buffer_alloc(hw);
1583 hw->current_mode = current_mode;
1584 hw->current_fc_status = fc_status;
1585 hw->dcb_info.hw_pfc_map = hw_pfc_map;
1586 status = hns3_buffer_alloc(hw);
1588 hns3_err(hw, "recover packet buffer fail! status = %d", status);
1594 * hns3_dcb_configure - setup dcb related config
1595 * @hns: pointer to hns3 adapter
1596 * Returns 0 on success, negative value on failure.
1599 hns3_dcb_configure(struct hns3_adapter *hns)
1601 struct hns3_hw *hw = &hns->hw;
1602 bool map_changed = false;
1606 hns3_dcb_cfg_validate(hns, &num_tc, &map_changed);
1608 __atomic_load_n(&hw->reset.resetting, __ATOMIC_RELAXED)) {
1609 ret = hns3_dcb_info_update(hns, num_tc);
1611 hns3_err(hw, "dcb info update failed: %d", ret);
1615 ret = hns3_dcb_hw_configure(hns);
1617 hns3_err(hw, "dcb sw configure failed: %d", ret);
1626 hns3_dcb_init_hw(struct hns3_hw *hw)
1630 ret = hns3_dcb_schd_setup_hw(hw);
1632 hns3_err(hw, "dcb schedule setup failed: %d", ret);
1636 ret = hns3_dcb_pause_setup_hw(hw);
1638 hns3_err(hw, "PAUSE setup failed: %d", ret);
1644 hns3_dcb_init(struct hns3_hw *hw)
1646 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1647 struct hns3_pf *pf = &hns->pf;
1648 uint16_t default_tqp_num;
1651 PMD_INIT_FUNC_TRACE();
1654 * According to the 'adapter_state' identifier, the following branch
1655 * is only executed to initialize default configurations of dcb during
1656 * the initializing driver process. Due to driver saving dcb-related
1657 * information before reset triggered, the reinit dev stage of the
1658 * reset process can not access to the branch, or those information
1661 if (hw->adapter_state == HNS3_NIC_UNINITIALIZED) {
1662 hw->requested_mode = HNS3_FC_NONE;
1663 hw->current_mode = hw->requested_mode;
1664 pf->pause_time = HNS3_DEFAULT_PAUSE_TRANS_TIME;
1665 hw->current_fc_status = HNS3_FC_STATUS_NONE;
1667 ret = hns3_dcb_info_init(hw);
1669 hns3_err(hw, "dcb info init failed, ret = %d.", ret);
1674 * The number of queues configured by default cannot exceed
1675 * the maximum number of queues for a single TC.
1677 default_tqp_num = RTE_MIN(hw->rss_size_max,
1678 hw->tqps_num / hw->dcb_info.num_tc);
1679 ret = hns3_dcb_update_tc_queue_mapping(hw, default_tqp_num,
1683 "update tc queue mapping failed, ret = %d.",
1690 * DCB hardware will be configured by following the function during
1691 * the initializing driver process and the reset process. However,
1692 * driver will restore directly configurations of dcb hardware based
1693 * on dcb-related information soft maintained when driver
1694 * initialization has finished and reset is coming.
1696 ret = hns3_dcb_init_hw(hw);
1698 hns3_err(hw, "dcb init hardware failed, ret = %d.", ret);
1706 hns3_update_queue_map_configure(struct hns3_adapter *hns)
1708 struct hns3_hw *hw = &hns->hw;
1709 uint16_t nb_rx_q = hw->data->nb_rx_queues;
1710 uint16_t nb_tx_q = hw->data->nb_tx_queues;
1713 ret = hns3_dcb_update_tc_queue_mapping(hw, nb_rx_q, nb_tx_q);
1715 hns3_err(hw, "failed to update tc queue mapping, ret = %d.",
1719 ret = hns3_q_to_qs_map(hw);
1721 hns3_err(hw, "failed to map nq to qs, ret = %d.", ret);
1727 hns3_dcb_cfg_update(struct hns3_adapter *hns)
1729 struct hns3_hw *hw = &hns->hw;
1730 enum rte_eth_rx_mq_mode mq_mode = hw->data->dev_conf.rxmode.mq_mode;
1733 if ((uint32_t)mq_mode & ETH_MQ_RX_DCB_FLAG) {
1734 ret = hns3_dcb_configure(hns);
1736 hns3_err(hw, "Failed to config dcb: %d", ret);
1739 * Update queue map without PFC configuration,
1740 * due to queues reconfigured by user.
1742 ret = hns3_update_queue_map_configure(hns);
1745 "Failed to update queue mapping configure: %d",
1753 * hns3_dcb_pfc_enable - Enable priority flow control
1754 * @dev: pointer to ethernet device
1756 * Configures the pfc settings for one porority.
1759 hns3_dcb_pfc_enable(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
1761 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1762 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1763 enum hns3_fc_status fc_status = hw->current_fc_status;
1764 enum hns3_fc_mode current_mode = hw->current_mode;
1765 uint8_t hw_pfc_map = hw->dcb_info.hw_pfc_map;
1766 uint8_t pfc_en = hw->dcb_info.pfc_en;
1767 uint8_t priority = pfc_conf->priority;
1768 uint16_t pause_time = pf->pause_time;
1771 pf->pause_time = pfc_conf->fc.pause_time;
1772 hw->current_mode = hw->requested_mode;
1773 hw->current_fc_status = HNS3_FC_STATUS_PFC;
1774 hw->dcb_info.pfc_en |= BIT(priority);
1775 hw->dcb_info.hw_pfc_map =
1776 hns3_dcb_undrop_tc_map(hw, hw->dcb_info.pfc_en);
1777 ret = hns3_buffer_alloc(hw);
1779 goto pfc_setup_fail;
1782 * The flow control mode of all UPs will be changed based on
1783 * current_mode coming from user.
1785 ret = hns3_dcb_pause_setup_hw(hw);
1787 hns3_err(hw, "enable pfc failed! ret = %d", ret);
1788 goto pfc_setup_fail;
1794 hw->current_mode = current_mode;
1795 hw->current_fc_status = fc_status;
1796 pf->pause_time = pause_time;
1797 hw->dcb_info.pfc_en = pfc_en;
1798 hw->dcb_info.hw_pfc_map = hw_pfc_map;
1799 status = hns3_buffer_alloc(hw);
1801 hns3_err(hw, "recover packet buffer fail: %d", status);
1807 * hns3_fc_enable - Enable MAC pause
1808 * @dev: pointer to ethernet device
1810 * Configures the MAC pause settings.
1813 hns3_fc_enable(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1815 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1816 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1817 enum hns3_fc_status fc_status = hw->current_fc_status;
1818 enum hns3_fc_mode current_mode = hw->current_mode;
1819 uint16_t pause_time = pf->pause_time;
1822 pf->pause_time = fc_conf->pause_time;
1823 hw->current_mode = hw->requested_mode;
1826 * In fact, current_fc_status is HNS3_FC_STATUS_NONE when mode
1827 * of flow control is configured to be HNS3_FC_NONE.
1829 if (hw->current_mode == HNS3_FC_NONE)
1830 hw->current_fc_status = HNS3_FC_STATUS_NONE;
1832 hw->current_fc_status = HNS3_FC_STATUS_MAC_PAUSE;
1834 ret = hns3_dcb_pause_setup_hw(hw);
1836 hns3_err(hw, "enable MAC Pause failed! ret = %d", ret);
1843 hw->current_mode = current_mode;
1844 hw->current_fc_status = fc_status;
1845 pf->pause_time = pause_time;