1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2019 Hisilicon Limited.
11 #include <rte_common.h>
12 #include <rte_ethdev.h>
14 #include "hns3_logs.h"
15 #include "hns3_regs.h"
16 #include "hns3_ethdev.h"
19 #define HNS3_SHAPER_BS_U_DEF 5
20 #define HNS3_SHAPER_BS_S_DEF 20
21 #define BW_MAX_PERCENT 100
24 * hns3_shaper_para_calc: calculate ir parameter for the shaper
25 * @ir: Rate to be config, its unit is Mbps
26 * @shaper_level: the shaper level. eg: port, pg, priority, queueset
27 * @shaper_para: shaper parameter of IR shaper
31 * IR_b * (2 ^ IR_u) * 8
32 * IR(Mbps) = ------------------------- * CLOCK(1000Mbps)
35 * @return: 0: calculate sucessful, negative: fail
38 hns3_shaper_para_calc(struct hns3_hw *hw, uint32_t ir, uint8_t shaper_level,
39 struct hns3_shaper_parameter *shaper_para)
41 #define SHAPER_DEFAULT_IR_B 126
42 #define DIVISOR_CLK (1000 * 8)
43 #define DIVISOR_IR_B_126 (126 * DIVISOR_CLK)
45 const uint16_t tick_array[HNS3_SHAPER_LVL_CNT] = {
46 6 * 256, /* Prioriy level */
47 6 * 32, /* Prioriy group level */
48 6 * 8, /* Port level */
49 6 * 256 /* Qset level */
51 uint8_t ir_u_calc = 0;
52 uint8_t ir_s_calc = 0;
58 if (shaper_level >= HNS3_SHAPER_LVL_CNT) {
60 "shaper_level(%d) is greater than HNS3_SHAPER_LVL_CNT(%d)",
61 shaper_level, HNS3_SHAPER_LVL_CNT);
65 if (ir > HNS3_ETHER_MAX_RATE) {
66 hns3_err(hw, "rate(%d) exceeds the rate driver supported "
67 "HNS3_ETHER_MAX_RATE(%d)", ir, HNS3_ETHER_MAX_RATE);
71 tick = tick_array[shaper_level];
74 * Calc the speed if ir_b = 126, ir_u = 0 and ir_s = 0
75 * the formula is changed to:
77 * ir_calc = ---------------- * 1000
80 ir_calc = (DIVISOR_IR_B_126 + (tick >> 1) - 1) / tick;
83 shaper_para->ir_b = SHAPER_DEFAULT_IR_B;
84 } else if (ir_calc > ir) {
85 /* Increasing the denominator to select ir_s value */
88 ir_calc = DIVISOR_IR_B_126 / (tick * (1 << ir_s_calc));
89 } while (ir_calc > ir);
92 shaper_para->ir_b = SHAPER_DEFAULT_IR_B;
94 shaper_para->ir_b = (ir * tick * (1 << ir_s_calc) +
95 (DIVISOR_CLK >> 1)) / DIVISOR_CLK;
98 * Increasing the numerator to select ir_u value. ir_u_calc will
99 * get maximum value when ir_calc is minimum and ir is maximum.
100 * ir_calc gets minimum value when tick is the maximum value.
101 * At the same time, value of ir_u_calc can only be increased up
102 * to eight after the while loop if the value of ir is equal
103 * to HNS3_ETHER_MAX_RATE.
108 numerator = DIVISOR_IR_B_126 * (1 << ir_u_calc);
109 ir_calc = (numerator + (tick >> 1)) / tick;
110 } while (ir_calc < ir);
113 shaper_para->ir_b = SHAPER_DEFAULT_IR_B;
118 * The maximum value of ir_u_calc in this branch is
119 * seven in all cases. Thus, value of denominator can
122 denominator = DIVISOR_CLK * (1 << ir_u_calc);
124 (ir * tick + (denominator >> 1)) / denominator;
128 shaper_para->ir_u = ir_u_calc;
129 shaper_para->ir_s = ir_s_calc;
135 hns3_fill_pri_array(struct hns3_hw *hw, uint8_t *pri, uint8_t pri_id)
137 #define HNS3_HALF_BYTE_BIT_OFFSET 4
138 uint8_t tc = hw->dcb_info.prio_tc[pri_id];
140 if (tc >= hw->dcb_info.num_tc)
144 * The register for priority has four bytes, the first bytes includes
145 * priority0 and priority1, the higher 4bit stands for priority1
146 * while the lower 4bit stands for priority0, as below:
147 * first byte: | pri_1 | pri_0 |
148 * second byte: | pri_3 | pri_2 |
149 * third byte: | pri_5 | pri_4 |
150 * fourth byte: | pri_7 | pri_6 |
152 pri[pri_id >> 1] |= tc << ((pri_id & 1) * HNS3_HALF_BYTE_BIT_OFFSET);
158 hns3_up_to_tc_map(struct hns3_hw *hw)
160 struct hns3_cmd_desc desc;
161 uint8_t *pri = (uint8_t *)desc.data;
165 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_PRI_TO_TC_MAPPING, false);
167 for (pri_id = 0; pri_id < HNS3_MAX_USER_PRIO; pri_id++) {
168 ret = hns3_fill_pri_array(hw, pri, pri_id);
173 return hns3_cmd_send(hw, &desc, 1);
177 hns3_pg_to_pri_map_cfg(struct hns3_hw *hw, uint8_t pg_id, uint8_t pri_bit_map)
179 struct hns3_pg_to_pri_link_cmd *map;
180 struct hns3_cmd_desc desc;
182 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_TO_PRI_LINK, false);
184 map = (struct hns3_pg_to_pri_link_cmd *)desc.data;
187 map->pri_bit_map = pri_bit_map;
189 return hns3_cmd_send(hw, &desc, 1);
193 hns3_pg_to_pri_map(struct hns3_hw *hw)
195 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
196 struct hns3_pf *pf = &hns->pf;
197 struct hns3_pg_info *pg_info;
200 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
203 for (i = 0; i < hw->dcb_info.num_pg; i++) {
204 /* Cfg pg to priority mapping */
205 pg_info = &hw->dcb_info.pg_info[i];
206 ret = hns3_pg_to_pri_map_cfg(hw, i, pg_info->tc_bit_map);
215 hns3_qs_to_pri_map_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t pri)
217 struct hns3_qs_to_pri_link_cmd *map;
218 struct hns3_cmd_desc desc;
220 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_TO_PRI_LINK, false);
222 map = (struct hns3_qs_to_pri_link_cmd *)desc.data;
224 map->qs_id = rte_cpu_to_le_16(qs_id);
226 map->link_vld = HNS3_DCB_QS_PRI_LINK_VLD_MSK;
228 return hns3_cmd_send(hw, &desc, 1);
232 hns3_dcb_qs_weight_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t dwrr)
234 struct hns3_qs_weight_cmd *weight;
235 struct hns3_cmd_desc desc;
237 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_WEIGHT, false);
239 weight = (struct hns3_qs_weight_cmd *)desc.data;
241 weight->qs_id = rte_cpu_to_le_16(qs_id);
244 return hns3_cmd_send(hw, &desc, 1);
248 hns3_dcb_ets_tc_dwrr_cfg(struct hns3_hw *hw)
250 #define DEFAULT_TC_WEIGHT 1
251 #define DEFAULT_TC_OFFSET 14
252 struct hns3_ets_tc_weight_cmd *ets_weight;
253 struct hns3_cmd_desc desc;
256 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_ETS_TC_WEIGHT, false);
257 ets_weight = (struct hns3_ets_tc_weight_cmd *)desc.data;
259 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
260 struct hns3_pg_info *pg_info;
262 ets_weight->tc_weight[i] = DEFAULT_TC_WEIGHT;
264 if (!(hw->hw_tc_map & BIT(i)))
267 pg_info = &hw->dcb_info.pg_info[hw->dcb_info.tc_info[i].pgid];
268 ets_weight->tc_weight[i] = pg_info->tc_dwrr[i];
271 ets_weight->weight_offset = DEFAULT_TC_OFFSET;
273 return hns3_cmd_send(hw, &desc, 1);
277 hns3_dcb_pri_weight_cfg(struct hns3_hw *hw, uint8_t pri_id, uint8_t dwrr)
279 struct hns3_priority_weight_cmd *weight;
280 struct hns3_cmd_desc desc;
282 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PRI_WEIGHT, false);
284 weight = (struct hns3_priority_weight_cmd *)desc.data;
286 weight->pri_id = pri_id;
289 return hns3_cmd_send(hw, &desc, 1);
293 hns3_dcb_pg_weight_cfg(struct hns3_hw *hw, uint8_t pg_id, uint8_t dwrr)
295 struct hns3_pg_weight_cmd *weight;
296 struct hns3_cmd_desc desc;
298 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_WEIGHT, false);
300 weight = (struct hns3_pg_weight_cmd *)desc.data;
302 weight->pg_id = pg_id;
305 return hns3_cmd_send(hw, &desc, 1);
308 hns3_dcb_pg_schd_mode_cfg(struct hns3_hw *hw, uint8_t pg_id)
310 struct hns3_cmd_desc desc;
312 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PG_SCH_MODE_CFG, false);
314 if (hw->dcb_info.pg_info[pg_id].pg_sch_mode == HNS3_SCH_MODE_DWRR)
315 desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
319 desc.data[0] = rte_cpu_to_le_32(pg_id);
321 return hns3_cmd_send(hw, &desc, 1);
325 hns3_dcb_get_shapping_para(uint8_t ir_b, uint8_t ir_u, uint8_t ir_s,
326 uint8_t bs_b, uint8_t bs_s)
328 uint32_t shapping_para = 0;
330 hns3_dcb_set_field(shapping_para, IR_B, ir_b);
331 hns3_dcb_set_field(shapping_para, IR_U, ir_u);
332 hns3_dcb_set_field(shapping_para, IR_S, ir_s);
333 hns3_dcb_set_field(shapping_para, BS_B, bs_b);
334 hns3_dcb_set_field(shapping_para, BS_S, bs_s);
336 return shapping_para;
340 hns3_dcb_port_shaper_cfg(struct hns3_hw *hw)
342 struct hns3_port_shapping_cmd *shap_cfg_cmd;
343 struct hns3_shaper_parameter shaper_parameter;
344 uint32_t shapping_para;
345 uint32_t ir_u, ir_b, ir_s;
346 struct hns3_cmd_desc desc;
349 ret = hns3_shaper_para_calc(hw, hw->mac.link_speed,
350 HNS3_SHAPER_LVL_PORT, &shaper_parameter);
352 hns3_err(hw, "calculate shaper parameter failed: %d", ret);
356 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PORT_SHAPPING, false);
357 shap_cfg_cmd = (struct hns3_port_shapping_cmd *)desc.data;
359 ir_b = shaper_parameter.ir_b;
360 ir_u = shaper_parameter.ir_u;
361 ir_s = shaper_parameter.ir_s;
362 shapping_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
363 HNS3_SHAPER_BS_U_DEF,
364 HNS3_SHAPER_BS_S_DEF);
366 shap_cfg_cmd->port_shapping_para = rte_cpu_to_le_32(shapping_para);
368 return hns3_cmd_send(hw, &desc, 1);
372 hns3_dcb_pg_shapping_cfg(struct hns3_hw *hw, enum hns3_shap_bucket bucket,
373 uint8_t pg_id, uint32_t shapping_para)
375 struct hns3_pg_shapping_cmd *shap_cfg_cmd;
376 enum hns3_opcode_type opcode;
377 struct hns3_cmd_desc desc;
379 opcode = bucket ? HNS3_OPC_TM_PG_P_SHAPPING :
380 HNS3_OPC_TM_PG_C_SHAPPING;
381 hns3_cmd_setup_basic_desc(&desc, opcode, false);
383 shap_cfg_cmd = (struct hns3_pg_shapping_cmd *)desc.data;
385 shap_cfg_cmd->pg_id = pg_id;
387 shap_cfg_cmd->pg_shapping_para = rte_cpu_to_le_32(shapping_para);
389 return hns3_cmd_send(hw, &desc, 1);
393 hns3_dcb_pg_shaper_cfg(struct hns3_hw *hw)
395 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
396 struct hns3_shaper_parameter shaper_parameter;
397 struct hns3_pf *pf = &hns->pf;
398 uint32_t ir_u, ir_b, ir_s;
399 uint32_t shaper_para;
404 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
408 for (i = 0; i < hw->dcb_info.num_pg; i++) {
409 /* Calc shaper para */
410 ret = hns3_shaper_para_calc(hw,
411 hw->dcb_info.pg_info[i].bw_limit,
415 hns3_err(hw, "calculate shaper parameter failed: %d",
420 shaper_para = hns3_dcb_get_shapping_para(0, 0, 0,
421 HNS3_SHAPER_BS_U_DEF,
422 HNS3_SHAPER_BS_S_DEF);
424 ret = hns3_dcb_pg_shapping_cfg(hw, HNS3_DCB_SHAP_C_BUCKET, i,
428 "config PG CIR shaper parameter failed: %d",
433 ir_b = shaper_parameter.ir_b;
434 ir_u = shaper_parameter.ir_u;
435 ir_s = shaper_parameter.ir_s;
436 shaper_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
437 HNS3_SHAPER_BS_U_DEF,
438 HNS3_SHAPER_BS_S_DEF);
440 ret = hns3_dcb_pg_shapping_cfg(hw, HNS3_DCB_SHAP_P_BUCKET, i,
444 "config PG PIR shaper parameter failed: %d",
454 hns3_dcb_qs_schd_mode_cfg(struct hns3_hw *hw, uint16_t qs_id, uint8_t mode)
456 struct hns3_cmd_desc desc;
458 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_QS_SCH_MODE_CFG, false);
460 if (mode == HNS3_SCH_MODE_DWRR)
461 desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
465 desc.data[0] = rte_cpu_to_le_32(qs_id);
467 return hns3_cmd_send(hw, &desc, 1);
471 hns3_dcb_pri_schd_mode_cfg(struct hns3_hw *hw, uint8_t pri_id)
473 struct hns3_cmd_desc desc;
475 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_PRI_SCH_MODE_CFG, false);
477 if (hw->dcb_info.tc_info[pri_id].tc_sch_mode == HNS3_SCH_MODE_DWRR)
478 desc.data[1] = rte_cpu_to_le_32(HNS3_DCB_TX_SCHD_DWRR_MSK);
482 desc.data[0] = rte_cpu_to_le_32(pri_id);
484 return hns3_cmd_send(hw, &desc, 1);
488 hns3_dcb_pri_shapping_cfg(struct hns3_hw *hw, enum hns3_shap_bucket bucket,
489 uint8_t pri_id, uint32_t shapping_para)
491 struct hns3_pri_shapping_cmd *shap_cfg_cmd;
492 enum hns3_opcode_type opcode;
493 struct hns3_cmd_desc desc;
495 opcode = bucket ? HNS3_OPC_TM_PRI_P_SHAPPING :
496 HNS3_OPC_TM_PRI_C_SHAPPING;
498 hns3_cmd_setup_basic_desc(&desc, opcode, false);
500 shap_cfg_cmd = (struct hns3_pri_shapping_cmd *)desc.data;
502 shap_cfg_cmd->pri_id = pri_id;
504 shap_cfg_cmd->pri_shapping_para = rte_cpu_to_le_32(shapping_para);
506 return hns3_cmd_send(hw, &desc, 1);
510 hns3_dcb_pri_tc_base_shaper_cfg(struct hns3_hw *hw)
512 struct hns3_shaper_parameter shaper_parameter;
513 uint32_t ir_u, ir_b, ir_s;
514 uint32_t shaper_para;
517 for (i = 0; i < hw->dcb_info.num_tc; i++) {
518 ret = hns3_shaper_para_calc(hw,
519 hw->dcb_info.tc_info[i].bw_limit,
523 hns3_err(hw, "calculate shaper parameter failed: %d",
528 shaper_para = hns3_dcb_get_shapping_para(0, 0, 0,
529 HNS3_SHAPER_BS_U_DEF,
530 HNS3_SHAPER_BS_S_DEF);
532 ret = hns3_dcb_pri_shapping_cfg(hw, HNS3_DCB_SHAP_C_BUCKET, i,
536 "config priority CIR shaper parameter failed: %d",
541 ir_b = shaper_parameter.ir_b;
542 ir_u = shaper_parameter.ir_u;
543 ir_s = shaper_parameter.ir_s;
544 shaper_para = hns3_dcb_get_shapping_para(ir_b, ir_u, ir_s,
545 HNS3_SHAPER_BS_U_DEF,
546 HNS3_SHAPER_BS_S_DEF);
548 ret = hns3_dcb_pri_shapping_cfg(hw, HNS3_DCB_SHAP_P_BUCKET, i,
552 "config priority PIR shaper parameter failed: %d",
563 hns3_dcb_pri_shaper_cfg(struct hns3_hw *hw)
565 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
566 struct hns3_pf *pf = &hns->pf;
569 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
572 ret = hns3_dcb_pri_tc_base_shaper_cfg(hw);
574 hns3_err(hw, "config port shaper failed: %d", ret);
580 hns3_set_rss_size(struct hns3_hw *hw, uint16_t nb_rx_q)
582 struct hns3_rss_conf *rss_cfg = &hw->rss_info;
583 uint16_t rx_qnum_per_tc;
586 rx_qnum_per_tc = nb_rx_q / hw->num_tc;
587 rx_qnum_per_tc = RTE_MIN(hw->rss_size_max, rx_qnum_per_tc);
588 if (hw->alloc_rss_size != rx_qnum_per_tc) {
589 hns3_info(hw, "rss size changes from %u to %u",
590 hw->alloc_rss_size, rx_qnum_per_tc);
591 hw->alloc_rss_size = rx_qnum_per_tc;
593 hw->used_rx_queues = hw->num_tc * hw->alloc_rss_size;
596 * When rss size is changed, we need to update rss redirection table
597 * maintained by driver. Besides, during the entire reset process, we
598 * need to ensure that the rss table information are not overwritten
599 * and configured directly to the hardware in the RESET_STAGE_RESTORE
600 * stage of the reset process.
602 if (rte_atomic16_read(&hw->reset.resetting) == 0) {
603 for (i = 0; i < HNS3_RSS_IND_TBL_SIZE; i++)
604 rss_cfg->rss_indirection_tbl[i] =
605 i % hw->alloc_rss_size;
610 hns3_tc_queue_mapping_cfg(struct hns3_hw *hw, uint16_t nb_queue)
612 struct hns3_tc_queue_info *tc_queue;
615 hw->tx_qnum_per_tc = nb_queue / hw->num_tc;
616 for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
617 tc_queue = &hw->tc_queue[i];
618 if (hw->hw_tc_map & BIT(i) && i < hw->num_tc) {
619 tc_queue->enable = true;
620 tc_queue->tqp_offset = i * hw->tx_qnum_per_tc;
621 tc_queue->tqp_count = hw->tx_qnum_per_tc;
624 /* Set to default queue if TC is disable */
625 tc_queue->enable = false;
626 tc_queue->tqp_offset = 0;
627 tc_queue->tqp_count = 0;
631 hw->used_tx_queues = hw->num_tc * hw->tx_qnum_per_tc;
635 hns3_dcb_update_tc_queue_mapping(struct hns3_hw *hw, uint16_t nb_rx_q,
638 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
639 struct hns3_pf *pf = &hns->pf;
641 hw->num_tc = hw->dcb_info.num_tc;
642 hns3_set_rss_size(hw, nb_rx_q);
643 hns3_tc_queue_mapping_cfg(hw, nb_tx_q);
646 memcpy(pf->prio_tc, hw->dcb_info.prio_tc, HNS3_MAX_USER_PRIO);
650 hns3_dcb_info_init(struct hns3_hw *hw)
652 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
653 struct hns3_pf *pf = &hns->pf;
656 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
657 hw->dcb_info.num_pg != 1)
660 /* Initializing PG information */
661 memset(hw->dcb_info.pg_info, 0,
662 sizeof(struct hns3_pg_info) * HNS3_PG_NUM);
663 for (i = 0; i < hw->dcb_info.num_pg; i++) {
664 hw->dcb_info.pg_dwrr[i] = i ? 0 : BW_MAX_PERCENT;
665 hw->dcb_info.pg_info[i].pg_id = i;
666 hw->dcb_info.pg_info[i].pg_sch_mode = HNS3_SCH_MODE_DWRR;
667 hw->dcb_info.pg_info[i].bw_limit = HNS3_ETHER_MAX_RATE;
672 hw->dcb_info.pg_info[i].tc_bit_map = hw->hw_tc_map;
673 for (k = 0; k < hw->dcb_info.num_tc; k++)
674 hw->dcb_info.pg_info[i].tc_dwrr[k] = BW_MAX_PERCENT;
677 /* All UPs mapping to TC0 */
678 for (i = 0; i < HNS3_MAX_USER_PRIO; i++)
679 hw->dcb_info.prio_tc[i] = 0;
681 /* Initializing tc information */
682 memset(hw->dcb_info.tc_info, 0,
683 sizeof(struct hns3_tc_info) * HNS3_MAX_TC_NUM);
684 for (i = 0; i < hw->dcb_info.num_tc; i++) {
685 hw->dcb_info.tc_info[i].tc_id = i;
686 hw->dcb_info.tc_info[i].tc_sch_mode = HNS3_SCH_MODE_DWRR;
687 hw->dcb_info.tc_info[i].pgid = 0;
688 hw->dcb_info.tc_info[i].bw_limit =
689 hw->dcb_info.pg_info[0].bw_limit;
696 hns3_dcb_lvl2_schd_mode_cfg(struct hns3_hw *hw)
698 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
699 struct hns3_pf *pf = &hns->pf;
702 /* Only being config on TC-Based scheduler mode */
703 if (pf->tx_sch_mode == HNS3_FLAG_VNET_BASE_SCH_MODE)
706 for (i = 0; i < hw->dcb_info.num_pg; i++) {
707 ret = hns3_dcb_pg_schd_mode_cfg(hw, i);
716 hns3_dcb_lvl34_schd_mode_cfg(struct hns3_hw *hw)
718 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
719 struct hns3_pf *pf = &hns->pf;
723 if (pf->tx_sch_mode == HNS3_FLAG_TC_BASE_SCH_MODE) {
724 for (i = 0; i < hw->dcb_info.num_tc; i++) {
725 ret = hns3_dcb_pri_schd_mode_cfg(hw, i);
729 ret = hns3_dcb_qs_schd_mode_cfg(hw, i,
740 hns3_dcb_schd_mode_cfg(struct hns3_hw *hw)
744 ret = hns3_dcb_lvl2_schd_mode_cfg(hw);
746 hns3_err(hw, "config lvl2_schd_mode failed: %d", ret);
750 ret = hns3_dcb_lvl34_schd_mode_cfg(hw);
752 hns3_err(hw, "config lvl34_schd_mode failed: %d", ret);
758 hns3_dcb_pri_tc_base_dwrr_cfg(struct hns3_hw *hw)
760 struct hns3_pg_info *pg_info;
764 for (i = 0; i < hw->dcb_info.num_tc; i++) {
765 pg_info = &hw->dcb_info.pg_info[hw->dcb_info.tc_info[i].pgid];
766 dwrr = pg_info->tc_dwrr[i];
768 ret = hns3_dcb_pri_weight_cfg(hw, i, dwrr);
771 "fail to send priority weight cmd: %d, ret = %d",
776 ret = hns3_dcb_qs_weight_cfg(hw, i, BW_MAX_PERCENT);
778 hns3_err(hw, "fail to send qs_weight cmd: %d, ret = %d",
788 hns3_dcb_pri_dwrr_cfg(struct hns3_hw *hw)
790 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
791 struct hns3_pf *pf = &hns->pf;
795 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
798 ret = hns3_dcb_pri_tc_base_dwrr_cfg(hw);
802 if (!hns3_dev_dcb_supported(hw))
805 ret = hns3_dcb_ets_tc_dwrr_cfg(hw);
806 if (ret == -EOPNOTSUPP) {
807 version = hw->fw_version;
809 "fw %lu.%lu.%lu.%lu doesn't support ets tc weight cmd",
810 hns3_get_field(version, HNS3_FW_VERSION_BYTE3_M,
811 HNS3_FW_VERSION_BYTE3_S),
812 hns3_get_field(version, HNS3_FW_VERSION_BYTE2_M,
813 HNS3_FW_VERSION_BYTE2_S),
814 hns3_get_field(version, HNS3_FW_VERSION_BYTE1_M,
815 HNS3_FW_VERSION_BYTE1_S),
816 hns3_get_field(version, HNS3_FW_VERSION_BYTE0_M,
817 HNS3_FW_VERSION_BYTE0_S));
825 hns3_dcb_pg_dwrr_cfg(struct hns3_hw *hw)
827 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
828 struct hns3_pf *pf = &hns->pf;
832 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
836 for (i = 0; i < hw->dcb_info.num_pg; i++) {
838 ret = hns3_dcb_pg_weight_cfg(hw, i, hw->dcb_info.pg_dwrr[i]);
847 hns3_dcb_dwrr_cfg(struct hns3_hw *hw)
851 ret = hns3_dcb_pg_dwrr_cfg(hw);
853 hns3_err(hw, "config pg_dwrr failed: %d", ret);
857 ret = hns3_dcb_pri_dwrr_cfg(hw);
859 hns3_err(hw, "config pri_dwrr failed: %d", ret);
865 hns3_dcb_shaper_cfg(struct hns3_hw *hw)
869 ret = hns3_dcb_port_shaper_cfg(hw);
871 hns3_err(hw, "config port shaper failed: %d", ret);
875 ret = hns3_dcb_pg_shaper_cfg(hw);
877 hns3_err(hw, "config pg shaper failed: %d", ret);
881 return hns3_dcb_pri_shaper_cfg(hw);
885 hns3_q_to_qs_map_cfg(struct hns3_hw *hw, uint16_t q_id, uint16_t qs_id)
887 struct hns3_nq_to_qs_link_cmd *map;
888 struct hns3_cmd_desc desc;
890 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_NQ_TO_QS_LINK, false);
892 map = (struct hns3_nq_to_qs_link_cmd *)desc.data;
894 map->nq_id = rte_cpu_to_le_16(q_id);
895 map->qset_id = rte_cpu_to_le_16(qs_id | HNS3_DCB_Q_QS_LINK_VLD_MSK);
897 return hns3_cmd_send(hw, &desc, 1);
901 hns3_q_to_qs_map(struct hns3_hw *hw)
903 struct hns3_tc_queue_info *tc_queue;
908 for (i = 0; i < hw->num_tc; i++) {
909 tc_queue = &hw->tc_queue[i];
910 for (j = 0; j < tc_queue->tqp_count; j++) {
911 q_id = tc_queue->tqp_offset + j;
912 ret = hns3_q_to_qs_map_cfg(hw, q_id, i);
922 hns3_pri_q_qs_cfg(struct hns3_hw *hw)
924 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
925 struct hns3_pf *pf = &hns->pf;
929 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE)
932 /* Cfg qs -> pri mapping */
933 for (i = 0; i < hw->num_tc; i++) {
934 ret = hns3_qs_to_pri_map_cfg(hw, i, i);
936 hns3_err(hw, "qs_to_pri mapping fail: %d", ret);
941 /* Cfg q -> qs mapping */
942 ret = hns3_q_to_qs_map(hw);
944 hns3_err(hw, "nq_to_qs mapping fail: %d", ret);
950 hns3_dcb_map_cfg(struct hns3_hw *hw)
954 ret = hns3_up_to_tc_map(hw);
956 hns3_err(hw, "up_to_tc mapping fail: %d", ret);
960 ret = hns3_pg_to_pri_map(hw);
962 hns3_err(hw, "pri_to_pg mapping fail: %d", ret);
966 return hns3_pri_q_qs_cfg(hw);
970 hns3_dcb_schd_setup_hw(struct hns3_hw *hw)
974 /* Cfg dcb mapping */
975 ret = hns3_dcb_map_cfg(hw);
980 ret = hns3_dcb_shaper_cfg(hw);
985 ret = hns3_dcb_dwrr_cfg(hw);
989 /* Cfg schd mode for each level schd */
990 return hns3_dcb_schd_mode_cfg(hw);
994 hns3_pause_param_cfg(struct hns3_hw *hw, const uint8_t *addr,
995 uint8_t pause_trans_gap, uint16_t pause_trans_time)
997 struct hns3_cfg_pause_param_cmd *pause_param;
998 struct hns3_cmd_desc desc;
1000 pause_param = (struct hns3_cfg_pause_param_cmd *)desc.data;
1002 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PARA, false);
1004 memcpy(pause_param->mac_addr, addr, RTE_ETHER_ADDR_LEN);
1005 memcpy(pause_param->mac_addr_extra, addr, RTE_ETHER_ADDR_LEN);
1006 pause_param->pause_trans_gap = pause_trans_gap;
1007 pause_param->pause_trans_time = rte_cpu_to_le_16(pause_trans_time);
1009 return hns3_cmd_send(hw, &desc, 1);
1013 hns3_pause_addr_cfg(struct hns3_hw *hw, const uint8_t *mac_addr)
1015 struct hns3_cfg_pause_param_cmd *pause_param;
1016 struct hns3_cmd_desc desc;
1017 uint16_t trans_time;
1021 pause_param = (struct hns3_cfg_pause_param_cmd *)desc.data;
1023 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PARA, true);
1025 ret = hns3_cmd_send(hw, &desc, 1);
1029 trans_gap = pause_param->pause_trans_gap;
1030 trans_time = rte_le_to_cpu_16(pause_param->pause_trans_time);
1032 return hns3_pause_param_cfg(hw, mac_addr, trans_gap, trans_time);
1036 hns3_pause_param_setup_hw(struct hns3_hw *hw, uint16_t pause_time)
1038 #define PAUSE_TIME_DIV_BY 2
1039 #define PAUSE_TIME_MIN_VALUE 0x4
1041 struct hns3_mac *mac = &hw->mac;
1042 uint8_t pause_trans_gap;
1045 * Pause transmit gap must be less than "pause_time / 2", otherwise
1046 * the behavior of MAC is undefined.
1048 if (pause_time > PAUSE_TIME_DIV_BY * HNS3_DEFAULT_PAUSE_TRANS_GAP)
1049 pause_trans_gap = HNS3_DEFAULT_PAUSE_TRANS_GAP;
1050 else if (pause_time >= PAUSE_TIME_MIN_VALUE &&
1051 pause_time <= PAUSE_TIME_DIV_BY * HNS3_DEFAULT_PAUSE_TRANS_GAP)
1052 pause_trans_gap = pause_time / PAUSE_TIME_DIV_BY - 1;
1054 hns3_warn(hw, "pause_time(%d) is adjusted to 4", pause_time);
1055 pause_time = PAUSE_TIME_MIN_VALUE;
1056 pause_trans_gap = pause_time / PAUSE_TIME_DIV_BY - 1;
1059 return hns3_pause_param_cfg(hw, mac->mac_addr,
1060 pause_trans_gap, pause_time);
1064 hns3_mac_pause_en_cfg(struct hns3_hw *hw, bool tx, bool rx)
1066 struct hns3_cmd_desc desc;
1068 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_MAC_PAUSE_EN, false);
1070 desc.data[0] = rte_cpu_to_le_32((tx ? HNS3_TX_MAC_PAUSE_EN_MSK : 0) |
1071 (rx ? HNS3_RX_MAC_PAUSE_EN_MSK : 0));
1073 return hns3_cmd_send(hw, &desc, 1);
1077 hns3_pfc_pause_en_cfg(struct hns3_hw *hw, uint8_t pfc_bitmap, bool tx, bool rx)
1079 struct hns3_cmd_desc desc;
1080 struct hns3_pfc_en_cmd *pfc = (struct hns3_pfc_en_cmd *)desc.data;
1082 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_PFC_PAUSE_EN, false);
1084 pfc->tx_rx_en_bitmap = (uint8_t)((tx ? HNS3_TX_MAC_PAUSE_EN_MSK : 0) |
1085 (rx ? HNS3_RX_MAC_PAUSE_EN_MSK : 0));
1087 pfc->pri_en_bitmap = pfc_bitmap;
1089 return hns3_cmd_send(hw, &desc, 1);
1093 hns3_qs_bp_cfg(struct hns3_hw *hw, uint8_t tc, uint8_t grp_id, uint32_t bit_map)
1095 struct hns3_bp_to_qs_map_cmd *bp_to_qs_map_cmd;
1096 struct hns3_cmd_desc desc;
1098 hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TM_BP_TO_QSET_MAPPING, false);
1100 bp_to_qs_map_cmd = (struct hns3_bp_to_qs_map_cmd *)desc.data;
1102 bp_to_qs_map_cmd->tc_id = tc;
1103 bp_to_qs_map_cmd->qs_group_id = grp_id;
1104 bp_to_qs_map_cmd->qs_bit_map = rte_cpu_to_le_32(bit_map);
1106 return hns3_cmd_send(hw, &desc, 1);
1110 hns3_get_rx_tx_en_status(struct hns3_hw *hw, bool *tx_en, bool *rx_en)
1112 switch (hw->current_mode) {
1117 case HNS3_FC_RX_PAUSE:
1121 case HNS3_FC_TX_PAUSE:
1137 hns3_mac_pause_setup_hw(struct hns3_hw *hw)
1141 if (hw->current_fc_status == HNS3_FC_STATUS_MAC_PAUSE)
1142 hns3_get_rx_tx_en_status(hw, &tx_en, &rx_en);
1148 return hns3_mac_pause_en_cfg(hw, tx_en, rx_en);
1152 hns3_pfc_setup_hw(struct hns3_hw *hw)
1156 if (hw->current_fc_status == HNS3_FC_STATUS_PFC)
1157 hns3_get_rx_tx_en_status(hw, &tx_en, &rx_en);
1163 return hns3_pfc_pause_en_cfg(hw, hw->dcb_info.pfc_en, tx_en, rx_en);
1167 * Each Tc has a 1024 queue sets to backpress, it divides to
1168 * 32 group, each group contains 32 queue sets, which can be
1169 * represented by uint32_t bitmap.
1172 hns3_bp_setup_hw(struct hns3_hw *hw, uint8_t tc)
1178 for (i = 0; i < HNS3_BP_GRP_NUM; i++) {
1179 uint8_t grp, sub_grp;
1182 grp = hns3_get_field(tc, HNS3_BP_GRP_ID_M, HNS3_BP_GRP_ID_S);
1183 sub_grp = hns3_get_field(tc, HNS3_BP_SUB_GRP_ID_M,
1184 HNS3_BP_SUB_GRP_ID_S);
1186 qs_bitmap |= (1 << sub_grp);
1188 ret = hns3_qs_bp_cfg(hw, tc, i, qs_bitmap);
1197 hns3_dcb_bp_setup(struct hns3_hw *hw)
1201 for (i = 0; i < hw->dcb_info.num_tc; i++) {
1202 ret = hns3_bp_setup_hw(hw, i);
1211 hns3_dcb_pause_setup_hw(struct hns3_hw *hw)
1213 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1214 struct hns3_pf *pf = &hns->pf;
1217 ret = hns3_pause_param_setup_hw(hw, pf->pause_time);
1219 hns3_err(hw, "Fail to set pause parameter. ret = %d", ret);
1223 ret = hns3_mac_pause_setup_hw(hw);
1225 hns3_err(hw, "Fail to setup MAC pause. ret = %d", ret);
1229 /* Only DCB-supported dev supports qset back pressure and pfc cmd */
1230 if (!hns3_dev_dcb_supported(hw))
1233 ret = hns3_pfc_setup_hw(hw);
1235 hns3_err(hw, "config pfc failed! ret = %d", ret);
1239 return hns3_dcb_bp_setup(hw);
1243 hns3_dcb_undrop_tc_map(struct hns3_hw *hw, uint8_t pfc_en)
1245 uint8_t pfc_map = 0;
1249 prio_tc = hw->dcb_info.prio_tc;
1250 for (i = 0; i < hw->dcb_info.num_tc; i++) {
1251 for (j = 0; j < HNS3_MAX_USER_PRIO; j++) {
1252 if (prio_tc[j] == i && pfc_en & BIT(j)) {
1263 hns3_dcb_cfg_validate(struct hns3_adapter *hns, uint8_t *tc, bool *changed)
1265 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
1266 struct hns3_hw *hw = &hns->hw;
1271 dcb_rx_conf = &hw->data->dev_conf.rx_adv_conf.dcb_rx_conf;
1272 for (i = 0; i < HNS3_MAX_USER_PRIO; i++) {
1273 if (dcb_rx_conf->dcb_tc[i] != hw->dcb_info.prio_tc[i])
1276 if (dcb_rx_conf->dcb_tc[i] > max_tc)
1277 max_tc = dcb_rx_conf->dcb_tc[i];
1280 if (*tc != hw->dcb_info.num_tc)
1284 * We ensure that dcb information can be reconfigured
1285 * after the hns3_priority_flow_ctrl_set function called.
1287 if (hw->current_mode != HNS3_FC_FULL)
1289 pfc_en = RTE_LEN2MASK((uint8_t)dcb_rx_conf->nb_tcs, uint8_t);
1290 if (hw->dcb_info.pfc_en != pfc_en)
1295 hns3_dcb_info_cfg(struct hns3_adapter *hns)
1297 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
1298 struct hns3_pf *pf = &hns->pf;
1299 struct hns3_hw *hw = &hns->hw;
1300 uint8_t tc_bw, bw_rest;
1303 dcb_rx_conf = &hw->data->dev_conf.rx_adv_conf.dcb_rx_conf;
1304 pf->local_max_tc = (uint8_t)dcb_rx_conf->nb_tcs;
1305 pf->pfc_max = (uint8_t)dcb_rx_conf->nb_tcs;
1308 memset(hw->dcb_info.pg_info, 0,
1309 sizeof(struct hns3_pg_info) * HNS3_PG_NUM);
1310 hw->dcb_info.pg_dwrr[0] = BW_MAX_PERCENT;
1311 hw->dcb_info.pg_info[0].pg_id = 0;
1312 hw->dcb_info.pg_info[0].pg_sch_mode = HNS3_SCH_MODE_DWRR;
1313 hw->dcb_info.pg_info[0].bw_limit = HNS3_ETHER_MAX_RATE;
1314 hw->dcb_info.pg_info[0].tc_bit_map = hw->hw_tc_map;
1316 /* Each tc has same bw for valid tc by default */
1317 tc_bw = BW_MAX_PERCENT / hw->dcb_info.num_tc;
1318 for (i = 0; i < hw->dcb_info.num_tc; i++)
1319 hw->dcb_info.pg_info[0].tc_dwrr[i] = tc_bw;
1320 /* To ensure the sum of tc_dwrr is equal to 100 */
1321 bw_rest = BW_MAX_PERCENT % hw->dcb_info.num_tc;
1322 for (j = 0; j < bw_rest; j++)
1323 hw->dcb_info.pg_info[0].tc_dwrr[j]++;
1324 for (; i < dcb_rx_conf->nb_tcs; i++)
1325 hw->dcb_info.pg_info[0].tc_dwrr[i] = 0;
1327 /* All tcs map to pg0 */
1328 memset(hw->dcb_info.tc_info, 0,
1329 sizeof(struct hns3_tc_info) * HNS3_MAX_TC_NUM);
1330 for (i = 0; i < hw->dcb_info.num_tc; i++) {
1331 hw->dcb_info.tc_info[i].tc_id = i;
1332 hw->dcb_info.tc_info[i].tc_sch_mode = HNS3_SCH_MODE_DWRR;
1333 hw->dcb_info.tc_info[i].pgid = 0;
1334 hw->dcb_info.tc_info[i].bw_limit =
1335 hw->dcb_info.pg_info[0].bw_limit;
1338 for (i = 0; i < HNS3_MAX_USER_PRIO; i++)
1339 hw->dcb_info.prio_tc[i] = dcb_rx_conf->dcb_tc[i];
1341 hns3_dcb_update_tc_queue_mapping(hw, hw->data->nb_rx_queues,
1342 hw->data->nb_tx_queues);
1346 hns3_dcb_info_update(struct hns3_adapter *hns, uint8_t num_tc)
1348 struct hns3_pf *pf = &hns->pf;
1349 struct hns3_hw *hw = &hns->hw;
1350 uint16_t nb_rx_q = hw->data->nb_rx_queues;
1351 uint16_t nb_tx_q = hw->data->nb_tx_queues;
1352 uint8_t bit_map = 0;
1355 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
1356 hw->dcb_info.num_pg != 1)
1359 if (nb_rx_q < num_tc) {
1360 hns3_err(hw, "number of Rx queues(%d) is less than tcs(%d).",
1365 if (nb_tx_q < num_tc) {
1366 hns3_err(hw, "number of Tx queues(%d) is less than tcs(%d).",
1371 /* Currently not support uncontinuous tc */
1372 hw->dcb_info.num_tc = num_tc;
1373 for (i = 0; i < hw->dcb_info.num_tc; i++)
1378 hw->dcb_info.num_tc = 1;
1380 hw->hw_tc_map = bit_map;
1381 hns3_dcb_info_cfg(hns);
1387 hns3_dcb_hw_configure(struct hns3_adapter *hns)
1389 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
1390 struct hns3_pf *pf = &hns->pf;
1391 struct hns3_hw *hw = &hns->hw;
1392 enum hns3_fc_status fc_status = hw->current_fc_status;
1393 enum hns3_fc_mode current_mode = hw->current_mode;
1394 uint8_t hw_pfc_map = hw->dcb_info.hw_pfc_map;
1397 if (pf->tx_sch_mode != HNS3_FLAG_TC_BASE_SCH_MODE &&
1398 pf->tx_sch_mode != HNS3_FLAG_VNET_BASE_SCH_MODE)
1401 ret = hns3_dcb_schd_setup_hw(hw);
1403 hns3_err(hw, "dcb schdule configure failed! ret = %d", ret);
1407 if (hw->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
1408 dcb_rx_conf = &hw->data->dev_conf.rx_adv_conf.dcb_rx_conf;
1409 if (dcb_rx_conf->nb_tcs == 0)
1410 hw->dcb_info.pfc_en = 1; /* tc0 only */
1412 hw->dcb_info.pfc_en =
1413 RTE_LEN2MASK((uint8_t)dcb_rx_conf->nb_tcs, uint8_t);
1415 hw->dcb_info.hw_pfc_map =
1416 hns3_dcb_undrop_tc_map(hw, hw->dcb_info.pfc_en);
1418 ret = hns3_buffer_alloc(hw);
1422 hw->current_fc_status = HNS3_FC_STATUS_PFC;
1423 hw->current_mode = HNS3_FC_FULL;
1424 ret = hns3_dcb_pause_setup_hw(hw);
1426 hns3_err(hw, "setup pfc failed! ret = %d", ret);
1427 goto pfc_setup_fail;
1431 * Although dcb_capability_en is lack of ETH_DCB_PFC_SUPPORT
1432 * flag, the DCB information is configured, such as tc numbers.
1433 * Therefore, refreshing the allocation of packet buffer is
1436 ret = hns3_buffer_alloc(hw);
1444 hw->current_mode = current_mode;
1445 hw->current_fc_status = fc_status;
1446 hw->dcb_info.hw_pfc_map = hw_pfc_map;
1447 status = hns3_buffer_alloc(hw);
1449 hns3_err(hw, "recover packet buffer fail! status = %d", status);
1455 * hns3_dcb_configure - setup dcb related config
1456 * @hns: pointer to hns3 adapter
1457 * Returns 0 on success, negative value on failure.
1460 hns3_dcb_configure(struct hns3_adapter *hns)
1462 struct hns3_hw *hw = &hns->hw;
1463 bool map_changed = false;
1467 hns3_dcb_cfg_validate(hns, &num_tc, &map_changed);
1468 if (map_changed || rte_atomic16_read(&hw->reset.resetting)) {
1469 ret = hns3_dcb_info_update(hns, num_tc);
1471 hns3_err(hw, "dcb info update failed: %d", ret);
1475 ret = hns3_dcb_hw_configure(hns);
1477 hns3_err(hw, "dcb sw configure failed: %d", ret);
1486 hns3_dcb_init_hw(struct hns3_hw *hw)
1490 ret = hns3_dcb_schd_setup_hw(hw);
1492 hns3_err(hw, "dcb schedule setup failed: %d", ret);
1496 ret = hns3_dcb_pause_setup_hw(hw);
1498 hns3_err(hw, "PAUSE setup failed: %d", ret);
1504 hns3_dcb_init(struct hns3_hw *hw)
1506 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1507 struct hns3_pf *pf = &hns->pf;
1510 PMD_INIT_FUNC_TRACE();
1513 * According to the 'adapter_state' identifier, the following branch
1514 * is only executed to initialize default configurations of dcb during
1515 * the initializing driver process. Due to driver saving dcb-related
1516 * information before reset triggered, the reinit dev stage of the
1517 * reset process can not access to the branch, or those information
1520 if (hw->adapter_state == HNS3_NIC_UNINITIALIZED) {
1521 hw->requested_mode = HNS3_FC_NONE;
1522 hw->current_mode = hw->requested_mode;
1523 pf->pause_time = HNS3_DEFAULT_PAUSE_TRANS_TIME;
1524 hw->current_fc_status = HNS3_FC_STATUS_NONE;
1526 ret = hns3_dcb_info_init(hw);
1528 hns3_err(hw, "dcb info init failed: %d", ret);
1531 hns3_dcb_update_tc_queue_mapping(hw, hw->tqps_num,
1536 * DCB hardware will be configured by following the function during
1537 * the initializing driver process and the reset process. However,
1538 * driver will restore directly configurations of dcb hardware based
1539 * on dcb-related information soft maintained when driver
1540 * initialization has finished and reset is coming.
1542 ret = hns3_dcb_init_hw(hw);
1544 hns3_err(hw, "dcb init hardware failed: %d", ret);
1552 hns3_update_queue_map_configure(struct hns3_adapter *hns)
1554 struct hns3_hw *hw = &hns->hw;
1555 uint16_t nb_rx_q = hw->data->nb_rx_queues;
1556 uint16_t nb_tx_q = hw->data->nb_tx_queues;
1559 hns3_dcb_update_tc_queue_mapping(hw, nb_rx_q, nb_tx_q);
1560 ret = hns3_q_to_qs_map(hw);
1562 hns3_err(hw, "failed to map nq to qs! ret = %d", ret);
1568 hns3_dcb_cfg_update(struct hns3_adapter *hns)
1570 struct hns3_hw *hw = &hns->hw;
1571 enum rte_eth_rx_mq_mode mq_mode = hw->data->dev_conf.rxmode.mq_mode;
1574 if ((uint32_t)mq_mode & ETH_MQ_RX_DCB_FLAG) {
1575 ret = hns3_dcb_configure(hns);
1577 hns3_err(hw, "Failed to config dcb: %d", ret);
1580 * Update queue map without PFC configuration,
1581 * due to queues reconfigured by user.
1583 ret = hns3_update_queue_map_configure(hns);
1586 "Failed to update queue mapping configure: %d",
1594 * hns3_dcb_pfc_enable - Enable priority flow control
1595 * @dev: pointer to ethernet device
1597 * Configures the pfc settings for one porority.
1600 hns3_dcb_pfc_enable(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
1602 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1603 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1604 enum hns3_fc_status fc_status = hw->current_fc_status;
1605 enum hns3_fc_mode current_mode = hw->current_mode;
1606 uint8_t hw_pfc_map = hw->dcb_info.hw_pfc_map;
1607 uint8_t pfc_en = hw->dcb_info.pfc_en;
1608 uint8_t priority = pfc_conf->priority;
1609 uint16_t pause_time = pf->pause_time;
1612 pf->pause_time = pfc_conf->fc.pause_time;
1613 hw->current_mode = hw->requested_mode;
1614 hw->current_fc_status = HNS3_FC_STATUS_PFC;
1615 hw->dcb_info.pfc_en |= BIT(priority);
1616 hw->dcb_info.hw_pfc_map =
1617 hns3_dcb_undrop_tc_map(hw, hw->dcb_info.pfc_en);
1618 ret = hns3_buffer_alloc(hw);
1620 goto pfc_setup_fail;
1623 * The flow control mode of all UPs will be changed based on
1624 * current_mode coming from user.
1626 ret = hns3_dcb_pause_setup_hw(hw);
1628 hns3_err(hw, "enable pfc failed! ret = %d", ret);
1629 goto pfc_setup_fail;
1635 hw->current_mode = current_mode;
1636 hw->current_fc_status = fc_status;
1637 pf->pause_time = pause_time;
1638 hw->dcb_info.pfc_en = pfc_en;
1639 hw->dcb_info.hw_pfc_map = hw_pfc_map;
1640 status = hns3_buffer_alloc(hw);
1642 hns3_err(hw, "recover packet buffer fail: %d", status);
1648 * hns3_fc_enable - Enable MAC pause
1649 * @dev: pointer to ethernet device
1651 * Configures the MAC pause settings.
1654 hns3_fc_enable(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1656 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1657 struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1658 enum hns3_fc_status fc_status = hw->current_fc_status;
1659 enum hns3_fc_mode current_mode = hw->current_mode;
1660 uint16_t pause_time = pf->pause_time;
1663 pf->pause_time = fc_conf->pause_time;
1664 hw->current_mode = hw->requested_mode;
1667 * In fact, current_fc_status is HNS3_FC_STATUS_NONE when mode
1668 * of flow control is configured to be HNS3_FC_NONE.
1670 if (hw->current_mode == HNS3_FC_NONE)
1671 hw->current_fc_status = HNS3_FC_STATUS_NONE;
1673 hw->current_fc_status = HNS3_FC_STATUS_MAC_PAUSE;
1675 ret = hns3_dcb_pause_setup_hw(hw);
1677 hns3_err(hw, "enable MAC Pause failed! ret = %d", ret);
1684 hw->current_mode = current_mode;
1685 hw->current_fc_status = fc_status;
1686 pf->pause_time = pause_time;