forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
....@@ -23,14 +23,11 @@
2323 #define HCLGE_SHAPER_BS_U_DEF 5
2424 #define HCLGE_SHAPER_BS_S_DEF 20
2525
26
-#define HCLGE_ETHER_MAX_RATE 100000
27
-
2826 /* hclge_shaper_para_calc: calculate ir parameter for the shaper
2927 * @ir: Rate to be config, its unit is Mbps
3028 * @shaper_level: the shaper level. eg: port, pg, priority, queueset
31
- * @ir_b: IR_B parameter of IR shaper
32
- * @ir_u: IR_U parameter of IR shaper
33
- * @ir_s: IR_S parameter of IR shaper
29
+ * @ir_para: parameters of IR shaper
30
+ * @max_tm_rate: max tm rate is available to config
3431 *
3532 * the formula:
3633 *
....@@ -41,21 +38,26 @@
4138 * @return: 0: calculate sucessful, negative: fail
4239 */
4340 static int hclge_shaper_para_calc(u32 ir, u8 shaper_level,
44
- u8 *ir_b, u8 *ir_u, u8 *ir_s)
41
+ struct hclge_shaper_ir_para *ir_para,
42
+ u32 max_tm_rate)
4543 {
46
- const u16 tick_array[HCLGE_SHAPER_LVL_CNT] = {
44
+#define DIVISOR_CLK (1000 * 8)
45
+#define DIVISOR_IR_B_126 (126 * DIVISOR_CLK)
46
+
47
+ static const u16 tick_array[HCLGE_SHAPER_LVL_CNT] = {
4748 6 * 256, /* Prioriy level */
4849 6 * 32, /* Prioriy group level */
4950 6 * 8, /* Port level */
5051 6 * 256 /* Qset level */
5152 };
52
- u8 ir_u_calc = 0, ir_s_calc = 0;
53
+ u8 ir_u_calc = 0;
54
+ u8 ir_s_calc = 0;
5355 u32 ir_calc;
5456 u32 tick;
5557
5658 /* Calc tick */
5759 if (shaper_level >= HCLGE_SHAPER_LVL_CNT ||
58
- ir > HCLGE_ETHER_MAX_RATE)
60
+ ir > max_tm_rate)
5961 return -EINVAL;
6062
6163 tick = tick_array[shaper_level];
....@@ -67,45 +69,44 @@
6769 * ir_calc = ---------------- * 1000
6870 * tick * 1
6971 */
70
- ir_calc = (1008000 + (tick >> 1) - 1) / tick;
72
+ ir_calc = (DIVISOR_IR_B_126 + (tick >> 1) - 1) / tick;
7173
7274 if (ir_calc == ir) {
73
- *ir_b = 126;
74
- *ir_u = 0;
75
- *ir_s = 0;
75
+ ir_para->ir_b = 126;
76
+ ir_para->ir_u = 0;
77
+ ir_para->ir_s = 0;
7678
7779 return 0;
7880 } else if (ir_calc > ir) {
7981 /* Increasing the denominator to select ir_s value */
80
- while (ir_calc > ir) {
82
+ while (ir_calc >= ir && ir) {
8183 ir_s_calc++;
82
- ir_calc = 1008000 / (tick * (1 << ir_s_calc));
84
+ ir_calc = DIVISOR_IR_B_126 / (tick * (1 << ir_s_calc));
8385 }
8486
85
- if (ir_calc == ir)
86
- *ir_b = 126;
87
- else
88
- *ir_b = (ir * tick * (1 << ir_s_calc) + 4000) / 8000;
87
+ ir_para->ir_b = (ir * tick * (1 << ir_s_calc) +
88
+ (DIVISOR_CLK >> 1)) / DIVISOR_CLK;
8989 } else {
9090 /* Increasing the numerator to select ir_u value */
9191 u32 numerator;
9292
9393 while (ir_calc < ir) {
9494 ir_u_calc++;
95
- numerator = 1008000 * (1 << ir_u_calc);
95
+ numerator = DIVISOR_IR_B_126 * (1 << ir_u_calc);
9696 ir_calc = (numerator + (tick >> 1)) / tick;
9797 }
9898
9999 if (ir_calc == ir) {
100
- *ir_b = 126;
100
+ ir_para->ir_b = 126;
101101 } else {
102
- u32 denominator = (8000 * (1 << --ir_u_calc));
103
- *ir_b = (ir * tick + (denominator >> 1)) / denominator;
102
+ u32 denominator = DIVISOR_CLK * (1 << --ir_u_calc);
103
+ ir_para->ir_b = (ir * tick + (denominator >> 1)) /
104
+ denominator;
104105 }
105106 }
106107
107
- *ir_u = ir_u_calc;
108
- *ir_s = ir_s_calc;
108
+ ir_para->ir_u = ir_u_calc;
109
+ ir_para->ir_s = ir_s_calc;
109110
110111 return 0;
111112 }
....@@ -120,13 +121,12 @@
120121 opcode == HCLGE_OPC_QUERY_PFC_TX_PKT_CNT))
121122 return -EINVAL;
122123
123
- for (i = 0; i < HCLGE_TM_PFC_PKT_GET_CMD_NUM; i++) {
124
+ for (i = 0; i < HCLGE_TM_PFC_PKT_GET_CMD_NUM - 1; i++) {
124125 hclge_cmd_setup_basic_desc(&desc[i], opcode, true);
125
- if (i != (HCLGE_TM_PFC_PKT_GET_CMD_NUM - 1))
126
- desc[i].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
127
- else
128
- desc[i].flag &= ~cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
126
+ desc[i].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
129127 }
128
+
129
+ hclge_cmd_setup_basic_desc(&desc[i], opcode, true);
130130
131131 ret = hclge_cmd_send(&hdev->hw, desc, HCLGE_TM_PFC_PKT_GET_CMD_NUM);
132132 if (ret)
....@@ -169,11 +169,11 @@
169169 return hclge_cmd_send(&hdev->hw, &desc, 1);
170170 }
171171
172
-static int hclge_pfc_pause_en_cfg(struct hclge_dev *hdev, u8 tx_rx_bitmap,
173
- u8 pfc_bitmap)
172
+int hclge_pfc_pause_en_cfg(struct hclge_dev *hdev, u8 tx_rx_bitmap,
173
+ u8 pfc_bitmap)
174174 {
175175 struct hclge_desc desc;
176
- struct hclge_pfc_en_cmd *pfc = (struct hclge_pfc_en_cmd *)&desc.data;
176
+ struct hclge_pfc_en_cmd *pfc = (struct hclge_pfc_en_cmd *)desc.data;
177177
178178 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_PFC_PAUSE_EN, false);
179179
....@@ -189,11 +189,12 @@
189189 struct hclge_cfg_pause_param_cmd *pause_param;
190190 struct hclge_desc desc;
191191
192
- pause_param = (struct hclge_cfg_pause_param_cmd *)&desc.data;
192
+ pause_param = (struct hclge_cfg_pause_param_cmd *)desc.data;
193193
194194 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_MAC_PARA, false);
195195
196196 ether_addr_copy(pause_param->mac_addr, addr);
197
+ ether_addr_copy(pause_param->mac_addr_extra, addr);
197198 pause_param->pause_trans_gap = pause_trans_gap;
198199 pause_param->pause_trans_time = cpu_to_le16(pause_trans_time);
199200
....@@ -208,7 +209,7 @@
208209 u8 trans_gap;
209210 int ret;
210211
211
- pause_param = (struct hclge_cfg_pause_param_cmd *)&desc.data;
212
+ pause_param = (struct hclge_cfg_pause_param_cmd *)desc.data;
212213
213214 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_MAC_PARA, true);
214215
....@@ -219,8 +220,7 @@
219220 trans_gap = pause_param->pause_trans_gap;
220221 trans_time = le16_to_cpu(pause_param->pause_trans_time);
221222
222
- return hclge_pause_param_cfg(hdev, mac_addr, trans_gap,
223
- trans_time);
223
+ return hclge_pause_param_cfg(hdev, mac_addr, trans_gap, trans_time);
224224 }
225225
226226 static int hclge_fill_pri_array(struct hclge_dev *hdev, u8 *pri, u8 pri_id)
....@@ -361,28 +361,35 @@
361361 return hclge_cmd_send(&hdev->hw, &desc, 1);
362362 }
363363
364
-static int hclge_tm_pg_shapping_cfg(struct hclge_dev *hdev,
365
- enum hclge_shap_bucket bucket, u8 pg_id,
366
- u8 ir_b, u8 ir_u, u8 ir_s, u8 bs_b, u8 bs_s)
364
+static u32 hclge_tm_get_shapping_para(u8 ir_b, u8 ir_u, u8 ir_s,
365
+ u8 bs_b, u8 bs_s)
367366 {
368
- struct hclge_pg_shapping_cmd *shap_cfg_cmd;
369
- enum hclge_opcode_type opcode;
370
- struct hclge_desc desc;
371367 u32 shapping_para = 0;
372
-
373
- opcode = bucket ? HCLGE_OPC_TM_PG_P_SHAPPING :
374
- HCLGE_OPC_TM_PG_C_SHAPPING;
375
- hclge_cmd_setup_basic_desc(&desc, opcode, false);
376
-
377
- shap_cfg_cmd = (struct hclge_pg_shapping_cmd *)desc.data;
378
-
379
- shap_cfg_cmd->pg_id = pg_id;
380368
381369 hclge_tm_set_field(shapping_para, IR_B, ir_b);
382370 hclge_tm_set_field(shapping_para, IR_U, ir_u);
383371 hclge_tm_set_field(shapping_para, IR_S, ir_s);
384372 hclge_tm_set_field(shapping_para, BS_B, bs_b);
385373 hclge_tm_set_field(shapping_para, BS_S, bs_s);
374
+
375
+ return shapping_para;
376
+}
377
+
378
+static int hclge_tm_pg_shapping_cfg(struct hclge_dev *hdev,
379
+ enum hclge_shap_bucket bucket, u8 pg_id,
380
+ u32 shapping_para)
381
+{
382
+ struct hclge_pg_shapping_cmd *shap_cfg_cmd;
383
+ enum hclge_opcode_type opcode;
384
+ struct hclge_desc desc;
385
+
386
+ opcode = bucket ? HCLGE_OPC_TM_PG_P_SHAPPING :
387
+ HCLGE_OPC_TM_PG_C_SHAPPING;
388
+ hclge_cmd_setup_basic_desc(&desc, opcode, false);
389
+
390
+ shap_cfg_cmd = (struct hclge_pg_shapping_cmd *)desc.data;
391
+
392
+ shap_cfg_cmd->pg_id = pg_id;
386393
387394 shap_cfg_cmd->pg_shapping_para = cpu_to_le32(shapping_para);
388395
....@@ -392,25 +399,24 @@
392399 static int hclge_tm_port_shaper_cfg(struct hclge_dev *hdev)
393400 {
394401 struct hclge_port_shapping_cmd *shap_cfg_cmd;
402
+ struct hclge_shaper_ir_para ir_para;
395403 struct hclge_desc desc;
396
- u32 shapping_para = 0;
397
- u8 ir_u, ir_b, ir_s;
404
+ u32 shapping_para;
398405 int ret;
399406
400
- ret = hclge_shaper_para_calc(HCLGE_ETHER_MAX_RATE,
401
- HCLGE_SHAPER_LVL_PORT,
402
- &ir_b, &ir_u, &ir_s);
407
+ ret = hclge_shaper_para_calc(hdev->hw.mac.speed, HCLGE_SHAPER_LVL_PORT,
408
+ &ir_para,
409
+ hdev->ae_dev->dev_specs.max_tm_rate);
403410 if (ret)
404411 return ret;
405412
406413 hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_TM_PORT_SHAPPING, false);
407414 shap_cfg_cmd = (struct hclge_port_shapping_cmd *)desc.data;
408415
409
- hclge_tm_set_field(shapping_para, IR_B, ir_b);
410
- hclge_tm_set_field(shapping_para, IR_U, ir_u);
411
- hclge_tm_set_field(shapping_para, IR_S, ir_s);
412
- hclge_tm_set_field(shapping_para, BS_B, HCLGE_SHAPER_BS_U_DEF);
413
- hclge_tm_set_field(shapping_para, BS_S, HCLGE_SHAPER_BS_S_DEF);
416
+ shapping_para = hclge_tm_get_shapping_para(ir_para.ir_b, ir_para.ir_u,
417
+ ir_para.ir_s,
418
+ HCLGE_SHAPER_BS_U_DEF,
419
+ HCLGE_SHAPER_BS_S_DEF);
414420
415421 shap_cfg_cmd->port_shapping_para = cpu_to_le32(shapping_para);
416422
....@@ -419,28 +425,20 @@
419425
420426 static int hclge_tm_pri_shapping_cfg(struct hclge_dev *hdev,
421427 enum hclge_shap_bucket bucket, u8 pri_id,
422
- u8 ir_b, u8 ir_u, u8 ir_s,
423
- u8 bs_b, u8 bs_s)
428
+ u32 shapping_para)
424429 {
425430 struct hclge_pri_shapping_cmd *shap_cfg_cmd;
426431 enum hclge_opcode_type opcode;
427432 struct hclge_desc desc;
428
- u32 shapping_para = 0;
429433
430434 opcode = bucket ? HCLGE_OPC_TM_PRI_P_SHAPPING :
431
- HCLGE_OPC_TM_PRI_C_SHAPPING;
435
+ HCLGE_OPC_TM_PRI_C_SHAPPING;
432436
433437 hclge_cmd_setup_basic_desc(&desc, opcode, false);
434438
435439 shap_cfg_cmd = (struct hclge_pri_shapping_cmd *)desc.data;
436440
437441 shap_cfg_cmd->pri_id = pri_id;
438
-
439
- hclge_tm_set_field(shapping_para, IR_B, ir_b);
440
- hclge_tm_set_field(shapping_para, IR_U, ir_u);
441
- hclge_tm_set_field(shapping_para, IR_S, ir_s);
442
- hclge_tm_set_field(shapping_para, BS_B, bs_b);
443
- hclge_tm_set_field(shapping_para, BS_S, bs_s);
444442
445443 shap_cfg_cmd->pri_shapping_para = cpu_to_le32(shapping_para);
446444
....@@ -513,24 +511,97 @@
513511 return hclge_cmd_send(&hdev->hw, &desc, 1);
514512 }
515513
514
+int hclge_tm_qs_shaper_cfg(struct hclge_vport *vport, int max_tx_rate)
515
+{
516
+ struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
517
+ struct hclge_qs_shapping_cmd *shap_cfg_cmd;
518
+ struct hclge_shaper_ir_para ir_para;
519
+ struct hclge_dev *hdev = vport->back;
520
+ struct hclge_desc desc;
521
+ u32 shaper_para;
522
+ int ret, i;
523
+
524
+ if (!max_tx_rate)
525
+ max_tx_rate = hdev->ae_dev->dev_specs.max_tm_rate;
526
+
527
+ ret = hclge_shaper_para_calc(max_tx_rate, HCLGE_SHAPER_LVL_QSET,
528
+ &ir_para,
529
+ hdev->ae_dev->dev_specs.max_tm_rate);
530
+ if (ret)
531
+ return ret;
532
+
533
+ shaper_para = hclge_tm_get_shapping_para(ir_para.ir_b, ir_para.ir_u,
534
+ ir_para.ir_s,
535
+ HCLGE_SHAPER_BS_U_DEF,
536
+ HCLGE_SHAPER_BS_S_DEF);
537
+
538
+ for (i = 0; i < kinfo->num_tc; i++) {
539
+ hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QCN_SHAPPING_CFG,
540
+ false);
541
+
542
+ shap_cfg_cmd = (struct hclge_qs_shapping_cmd *)desc.data;
543
+ shap_cfg_cmd->qs_id = cpu_to_le16(vport->qs_offset + i);
544
+ shap_cfg_cmd->qs_shapping_para = cpu_to_le32(shaper_para);
545
+
546
+ ret = hclge_cmd_send(&hdev->hw, &desc, 1);
547
+ if (ret) {
548
+ dev_err(&hdev->pdev->dev,
549
+ "vf%u, qs%u failed to set tx_rate:%d, ret=%d\n",
550
+ vport->vport_id, shap_cfg_cmd->qs_id,
551
+ max_tx_rate, ret);
552
+ return ret;
553
+ }
554
+ }
555
+
556
+ return 0;
557
+}
558
+
516559 static void hclge_tm_vport_tc_info_update(struct hclge_vport *vport)
517560 {
518561 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
519562 struct hclge_dev *hdev = vport->back;
563
+ u16 max_rss_size;
520564 u8 i;
521565
522
- vport->bw_limit = hdev->tm_info.pg_info[0].bw_limit;
523
- kinfo->num_tc =
524
- min_t(u16, kinfo->num_tqps, hdev->tm_info.num_tc);
525
- kinfo->rss_size
526
- = min_t(u16, hdev->rss_size_max,
527
- kinfo->num_tqps / kinfo->num_tc);
528
- vport->qs_offset = hdev->tm_info.num_tc * vport->vport_id;
566
+ /* TC configuration is shared by PF/VF in one port, only allow
567
+ * one tc for VF for simplicity. VF's vport_id is non zero.
568
+ */
569
+ kinfo->num_tc = vport->vport_id ? 1 :
570
+ min_t(u16, vport->alloc_tqps, hdev->tm_info.num_tc);
571
+ vport->qs_offset = (vport->vport_id ? HNAE3_MAX_TC : 0) +
572
+ (vport->vport_id ? (vport->vport_id - 1) : 0);
573
+
574
+ max_rss_size = min_t(u16, hdev->rss_size_max,
575
+ vport->alloc_tqps / kinfo->num_tc);
576
+
577
+ /* Set to user value, no larger than max_rss_size. */
578
+ if (kinfo->req_rss_size != kinfo->rss_size && kinfo->req_rss_size &&
579
+ kinfo->req_rss_size <= max_rss_size) {
580
+ dev_info(&hdev->pdev->dev, "rss changes from %u to %u\n",
581
+ kinfo->rss_size, kinfo->req_rss_size);
582
+ kinfo->rss_size = kinfo->req_rss_size;
583
+ } else if (kinfo->rss_size > max_rss_size ||
584
+ (!kinfo->req_rss_size && kinfo->rss_size < max_rss_size)) {
585
+ /* if user not set rss, the rss_size should compare with the
586
+ * valid msi numbers to ensure one to one map between tqp and
587
+ * irq as default.
588
+ */
589
+ if (!kinfo->req_rss_size)
590
+ max_rss_size = min_t(u16, max_rss_size,
591
+ (hdev->num_nic_msi - 1) /
592
+ kinfo->num_tc);
593
+
594
+ /* Set to the maximum specification value (max_rss_size). */
595
+ kinfo->rss_size = max_rss_size;
596
+ }
597
+
598
+ kinfo->num_tqps = kinfo->num_tc * kinfo->rss_size;
529599 vport->dwrr = 100; /* 100 percent as init */
530600 vport->alloc_rss_size = kinfo->rss_size;
601
+ vport->bw_limit = hdev->tm_info.pg_info[0].bw_limit;
531602
532
- for (i = 0; i < kinfo->num_tc; i++) {
533
- if (hdev->hw_tc_map & BIT(i)) {
603
+ for (i = 0; i < HNAE3_MAX_TC; i++) {
604
+ if (hdev->hw_tc_map & BIT(i) && i < kinfo->num_tc) {
534605 kinfo->tc_info[i].enable = true;
535606 kinfo->tc_info[i].tqp_offset = i * kinfo->rss_size;
536607 kinfo->tc_info[i].tqp_count = kinfo->rss_size;
....@@ -545,7 +616,7 @@
545616 }
546617
547618 memcpy(kinfo->prio_tc, hdev->tm_info.prio_tc,
548
- FIELD_SIZEOF(struct hnae3_knic_private_info, prio_tc));
619
+ sizeof_field(struct hnae3_knic_private_info, prio_tc));
549620 }
550621
551622 static void hclge_tm_vport_info_update(struct hclge_dev *hdev)
....@@ -575,43 +646,43 @@
575646 for (i = 0; i < HNAE3_MAX_USER_PRIO; i++)
576647 hdev->tm_info.prio_tc[i] =
577648 (i >= hdev->tm_info.num_tc) ? 0 : i;
578
-
579
- /* DCB is enabled if we have more than 1 TC */
580
- if (hdev->tm_info.num_tc > 1)
581
- hdev->flag |= HCLGE_FLAG_DCB_ENABLE;
582
- else
583
- hdev->flag &= ~HCLGE_FLAG_DCB_ENABLE;
584649 }
585650
586651 static void hclge_tm_pg_info_init(struct hclge_dev *hdev)
587652 {
653
+#define BW_PERCENT 100
654
+#define DEFAULT_BW_WEIGHT 1
655
+
588656 u8 i;
589657
590658 for (i = 0; i < hdev->tm_info.num_pg; i++) {
591659 int k;
592660
593
- hdev->tm_info.pg_dwrr[i] = i ? 0 : 100;
661
+ hdev->tm_info.pg_dwrr[i] = i ? 0 : BW_PERCENT;
594662
595663 hdev->tm_info.pg_info[i].pg_id = i;
596664 hdev->tm_info.pg_info[i].pg_sch_mode = HCLGE_SCH_MODE_DWRR;
597665
598
- hdev->tm_info.pg_info[i].bw_limit = HCLGE_ETHER_MAX_RATE;
666
+ hdev->tm_info.pg_info[i].bw_limit =
667
+ hdev->ae_dev->dev_specs.max_tm_rate;
599668
600669 if (i != 0)
601670 continue;
602671
603672 hdev->tm_info.pg_info[i].tc_bit_map = hdev->hw_tc_map;
604673 for (k = 0; k < hdev->tm_info.num_tc; k++)
605
- hdev->tm_info.pg_info[i].tc_dwrr[k] = 100;
674
+ hdev->tm_info.pg_info[i].tc_dwrr[k] = BW_PERCENT;
675
+ for (; k < HNAE3_MAX_TC; k++)
676
+ hdev->tm_info.pg_info[i].tc_dwrr[k] = DEFAULT_BW_WEIGHT;
606677 }
607678 }
608679
609
-static void hclge_pfc_info_init(struct hclge_dev *hdev)
680
+static void hclge_update_fc_mode_by_dcb_flag(struct hclge_dev *hdev)
610681 {
611
- if (!(hdev->flag & HCLGE_FLAG_DCB_ENABLE)) {
682
+ if (hdev->tm_info.num_tc == 1 && !hdev->tm_info.pfc_en) {
612683 if (hdev->fc_mode_last_time == HCLGE_FC_PFC)
613684 dev_warn(&hdev->pdev->dev,
614
- "DCB is disable, but last mode is FC_PFC\n");
685
+ "Only 1 tc used, but last mode is FC_PFC\n");
615686
616687 hdev->tm_info.fc_mode = hdev->fc_mode_last_time;
617688 } else if (hdev->tm_info.fc_mode != HCLGE_FC_PFC) {
....@@ -624,21 +695,36 @@
624695 }
625696 }
626697
627
-static int hclge_tm_schd_info_init(struct hclge_dev *hdev)
698
+static void hclge_update_fc_mode(struct hclge_dev *hdev)
628699 {
629
- if ((hdev->tx_sch_mode != HCLGE_FLAG_TC_BASE_SCH_MODE) &&
630
- (hdev->tm_info.num_pg != 1))
631
- return -EINVAL;
700
+ if (!hdev->tm_info.pfc_en) {
701
+ hdev->tm_info.fc_mode = hdev->fc_mode_last_time;
702
+ return;
703
+ }
632704
705
+ if (hdev->tm_info.fc_mode != HCLGE_FC_PFC) {
706
+ hdev->fc_mode_last_time = hdev->tm_info.fc_mode;
707
+ hdev->tm_info.fc_mode = HCLGE_FC_PFC;
708
+ }
709
+}
710
+
711
+void hclge_tm_pfc_info_update(struct hclge_dev *hdev)
712
+{
713
+ if (hdev->ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V3)
714
+ hclge_update_fc_mode(hdev);
715
+ else
716
+ hclge_update_fc_mode_by_dcb_flag(hdev);
717
+}
718
+
719
+static void hclge_tm_schd_info_init(struct hclge_dev *hdev)
720
+{
633721 hclge_tm_pg_info_init(hdev);
634722
635723 hclge_tm_tc_info_init(hdev);
636724
637725 hclge_tm_vport_info_update(hdev);
638726
639
- hclge_pfc_info_init(hdev);
640
-
641
- return 0;
727
+ hclge_tm_pfc_info_update(hdev);
642728 }
643729
644730 static int hclge_tm_pg_to_pri_map(struct hclge_dev *hdev)
....@@ -662,7 +748,9 @@
662748
663749 static int hclge_tm_pg_shaper_cfg(struct hclge_dev *hdev)
664750 {
665
- u8 ir_u, ir_b, ir_s;
751
+ u32 max_tm_rate = hdev->ae_dev->dev_specs.max_tm_rate;
752
+ struct hclge_shaper_ir_para ir_para;
753
+ u32 shaper_para;
666754 int ret;
667755 u32 i;
668756
....@@ -673,25 +761,29 @@
673761 /* Pg to pri */
674762 for (i = 0; i < hdev->tm_info.num_pg; i++) {
675763 /* Calc shaper para */
676
- ret = hclge_shaper_para_calc(
677
- hdev->tm_info.pg_info[i].bw_limit,
678
- HCLGE_SHAPER_LVL_PG,
679
- &ir_b, &ir_u, &ir_s);
764
+ ret = hclge_shaper_para_calc(hdev->tm_info.pg_info[i].bw_limit,
765
+ HCLGE_SHAPER_LVL_PG,
766
+ &ir_para, max_tm_rate);
680767 if (ret)
681768 return ret;
682769
770
+ shaper_para = hclge_tm_get_shapping_para(0, 0, 0,
771
+ HCLGE_SHAPER_BS_U_DEF,
772
+ HCLGE_SHAPER_BS_S_DEF);
683773 ret = hclge_tm_pg_shapping_cfg(hdev,
684774 HCLGE_TM_SHAP_C_BUCKET, i,
685
- 0, 0, 0, HCLGE_SHAPER_BS_U_DEF,
686
- HCLGE_SHAPER_BS_S_DEF);
775
+ shaper_para);
687776 if (ret)
688777 return ret;
689778
779
+ shaper_para = hclge_tm_get_shapping_para(ir_para.ir_b,
780
+ ir_para.ir_u,
781
+ ir_para.ir_s,
782
+ HCLGE_SHAPER_BS_U_DEF,
783
+ HCLGE_SHAPER_BS_S_DEF);
690784 ret = hclge_tm_pg_shapping_cfg(hdev,
691785 HCLGE_TM_SHAP_P_BUCKET, i,
692
- ir_b, ir_u, ir_s,
693
- HCLGE_SHAPER_BS_U_DEF,
694
- HCLGE_SHAPER_BS_S_DEF);
786
+ shaper_para);
695787 if (ret)
696788 return ret;
697789 }
....@@ -711,8 +803,7 @@
711803 /* pg to prio */
712804 for (i = 0; i < hdev->tm_info.num_pg; i++) {
713805 /* Cfg dwrr */
714
- ret = hclge_tm_pg_weight_cfg(hdev, i,
715
- hdev->tm_info.pg_dwrr[i]);
806
+ ret = hclge_tm_pg_weight_cfg(hdev, i, hdev->tm_info.pg_dwrr[i]);
716807 if (ret)
717808 return ret;
718809 }
....@@ -753,13 +844,17 @@
753844
754845 if (hdev->tx_sch_mode == HCLGE_FLAG_TC_BASE_SCH_MODE) {
755846 /* Cfg qs -> pri mapping, one by one mapping */
756
- for (k = 0; k < hdev->num_alloc_vport; k++)
757
- for (i = 0; i < hdev->tm_info.num_tc; i++) {
847
+ for (k = 0; k < hdev->num_alloc_vport; k++) {
848
+ struct hnae3_knic_private_info *kinfo =
849
+ &vport[k].nic.kinfo;
850
+
851
+ for (i = 0; i < kinfo->num_tc; i++) {
758852 ret = hclge_tm_qs_to_pri_map_cfg(
759853 hdev, vport[k].qs_offset + i, i);
760854 if (ret)
761855 return ret;
762856 }
857
+ }
763858 } else if (hdev->tx_sch_mode == HCLGE_FLAG_VNET_BASE_SCH_MODE) {
764859 /* Cfg qs -> pri mapping, qs = tc, pri = vf, 8 qs -> 1 pri */
765860 for (k = 0; k < hdev->num_alloc_vport; k++)
....@@ -787,29 +882,34 @@
787882
788883 static int hclge_tm_pri_tc_base_shaper_cfg(struct hclge_dev *hdev)
789884 {
790
- u8 ir_u, ir_b, ir_s;
885
+ u32 max_tm_rate = hdev->ae_dev->dev_specs.max_tm_rate;
886
+ struct hclge_shaper_ir_para ir_para;
887
+ u32 shaper_para;
791888 int ret;
792889 u32 i;
793890
794891 for (i = 0; i < hdev->tm_info.num_tc; i++) {
795
- ret = hclge_shaper_para_calc(
796
- hdev->tm_info.tc_info[i].bw_limit,
797
- HCLGE_SHAPER_LVL_PRI,
798
- &ir_b, &ir_u, &ir_s);
892
+ ret = hclge_shaper_para_calc(hdev->tm_info.tc_info[i].bw_limit,
893
+ HCLGE_SHAPER_LVL_PRI,
894
+ &ir_para, max_tm_rate);
799895 if (ret)
800896 return ret;
801897
802
- ret = hclge_tm_pri_shapping_cfg(
803
- hdev, HCLGE_TM_SHAP_C_BUCKET, i,
804
- 0, 0, 0, HCLGE_SHAPER_BS_U_DEF,
805
- HCLGE_SHAPER_BS_S_DEF);
898
+ shaper_para = hclge_tm_get_shapping_para(0, 0, 0,
899
+ HCLGE_SHAPER_BS_U_DEF,
900
+ HCLGE_SHAPER_BS_S_DEF);
901
+ ret = hclge_tm_pri_shapping_cfg(hdev, HCLGE_TM_SHAP_C_BUCKET, i,
902
+ shaper_para);
806903 if (ret)
807904 return ret;
808905
809
- ret = hclge_tm_pri_shapping_cfg(
810
- hdev, HCLGE_TM_SHAP_P_BUCKET, i,
811
- ir_b, ir_u, ir_s, HCLGE_SHAPER_BS_U_DEF,
812
- HCLGE_SHAPER_BS_S_DEF);
906
+ shaper_para = hclge_tm_get_shapping_para(ir_para.ir_b,
907
+ ir_para.ir_u,
908
+ ir_para.ir_s,
909
+ HCLGE_SHAPER_BS_U_DEF,
910
+ HCLGE_SHAPER_BS_S_DEF);
911
+ ret = hclge_tm_pri_shapping_cfg(hdev, HCLGE_TM_SHAP_P_BUCKET, i,
912
+ shaper_para);
813913 if (ret)
814914 return ret;
815915 }
....@@ -820,26 +920,30 @@
820920 static int hclge_tm_pri_vnet_base_shaper_pri_cfg(struct hclge_vport *vport)
821921 {
822922 struct hclge_dev *hdev = vport->back;
823
- u8 ir_u, ir_b, ir_s;
923
+ struct hclge_shaper_ir_para ir_para;
924
+ u32 shaper_para;
824925 int ret;
825926
826927 ret = hclge_shaper_para_calc(vport->bw_limit, HCLGE_SHAPER_LVL_VF,
827
- &ir_b, &ir_u, &ir_s);
928
+ &ir_para,
929
+ hdev->ae_dev->dev_specs.max_tm_rate);
828930 if (ret)
829931 return ret;
830932
933
+ shaper_para = hclge_tm_get_shapping_para(0, 0, 0,
934
+ HCLGE_SHAPER_BS_U_DEF,
935
+ HCLGE_SHAPER_BS_S_DEF);
831936 ret = hclge_tm_pri_shapping_cfg(hdev, HCLGE_TM_SHAP_C_BUCKET,
832
- vport->vport_id,
833
- 0, 0, 0, HCLGE_SHAPER_BS_U_DEF,
834
- HCLGE_SHAPER_BS_S_DEF);
937
+ vport->vport_id, shaper_para);
835938 if (ret)
836939 return ret;
837940
941
+ shaper_para = hclge_tm_get_shapping_para(ir_para.ir_b, ir_para.ir_u,
942
+ ir_para.ir_s,
943
+ HCLGE_SHAPER_BS_U_DEF,
944
+ HCLGE_SHAPER_BS_S_DEF);
838945 ret = hclge_tm_pri_shapping_cfg(hdev, HCLGE_TM_SHAP_P_BUCKET,
839
- vport->vport_id,
840
- ir_b, ir_u, ir_s,
841
- HCLGE_SHAPER_BS_U_DEF,
842
- HCLGE_SHAPER_BS_S_DEF);
946
+ vport->vport_id, shaper_para);
843947 if (ret)
844948 return ret;
845949
....@@ -850,15 +954,15 @@
850954 {
851955 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
852956 struct hclge_dev *hdev = vport->back;
853
- u8 ir_u, ir_b, ir_s;
957
+ u32 max_tm_rate = hdev->ae_dev->dev_specs.max_tm_rate;
958
+ struct hclge_shaper_ir_para ir_para;
854959 u32 i;
855960 int ret;
856961
857962 for (i = 0; i < kinfo->num_tc; i++) {
858
- ret = hclge_shaper_para_calc(
859
- hdev->tm_info.tc_info[i].bw_limit,
860
- HCLGE_SHAPER_LVL_QSET,
861
- &ir_b, &ir_u, &ir_s);
963
+ ret = hclge_shaper_para_calc(hdev->tm_info.tc_info[i].bw_limit,
964
+ HCLGE_SHAPER_LVL_QSET,
965
+ &ir_para, max_tm_rate);
862966 if (ret)
863967 return ret;
864968 }
....@@ -934,6 +1038,29 @@
9341038 return 0;
9351039 }
9361040
1041
+static int hclge_tm_ets_tc_dwrr_cfg(struct hclge_dev *hdev)
1042
+{
1043
+#define DEFAULT_TC_OFFSET 14
1044
+
1045
+ struct hclge_ets_tc_weight_cmd *ets_weight;
1046
+ struct hclge_desc desc;
1047
+ unsigned int i;
1048
+
1049
+ hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_ETS_TC_WEIGHT, false);
1050
+ ets_weight = (struct hclge_ets_tc_weight_cmd *)desc.data;
1051
+
1052
+ for (i = 0; i < HNAE3_MAX_TC; i++) {
1053
+ struct hclge_pg_info *pg_info;
1054
+
1055
+ pg_info = &hdev->tm_info.pg_info[hdev->tm_info.tc_info[i].pgid];
1056
+ ets_weight->tc_weight[i] = pg_info->tc_dwrr[i];
1057
+ }
1058
+
1059
+ ets_weight->weight_offset = DEFAULT_TC_OFFSET;
1060
+
1061
+ return hclge_cmd_send(&hdev->hw, &desc, 1);
1062
+}
1063
+
9371064 static int hclge_tm_pri_vnet_base_dwrr_pri_cfg(struct hclge_vport *vport)
9381065 {
9391066 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
....@@ -983,6 +1110,19 @@
9831110 ret = hclge_tm_pri_tc_base_dwrr_cfg(hdev);
9841111 if (ret)
9851112 return ret;
1113
+
1114
+ if (!hnae3_dev_dcb_supported(hdev))
1115
+ return 0;
1116
+
1117
+ ret = hclge_tm_ets_tc_dwrr_cfg(hdev);
1118
+ if (ret == -EOPNOTSUPP) {
1119
+ dev_warn(&hdev->pdev->dev,
1120
+ "fw %08x does't support ets tc weight cmd\n",
1121
+ hdev->fw_version);
1122
+ ret = 0;
1123
+ }
1124
+
1125
+ return ret;
9861126 } else {
9871127 ret = hclge_tm_pri_vnet_base_dwrr_cfg(hdev);
9881128 if (ret)
....@@ -992,7 +1132,7 @@
9921132 return 0;
9931133 }
9941134
995
-int hclge_tm_map_cfg(struct hclge_dev *hdev)
1135
+static int hclge_tm_map_cfg(struct hclge_dev *hdev)
9961136 {
9971137 int ret;
9981138
....@@ -1110,7 +1250,7 @@
11101250 return 0;
11111251 }
11121252
1113
-int hclge_tm_schd_mode_hw(struct hclge_dev *hdev)
1253
+static int hclge_tm_schd_mode_hw(struct hclge_dev *hdev)
11141254 {
11151255 int ret;
11161256
....@@ -1121,7 +1261,7 @@
11211261 return hclge_tm_lvl34_schd_mode_cfg(hdev);
11221262 }
11231263
1124
-static int hclge_tm_schd_setup_hw(struct hclge_dev *hdev)
1264
+int hclge_tm_schd_setup_hw(struct hclge_dev *hdev)
11251265 {
11261266 int ret;
11271267
....@@ -1149,8 +1289,8 @@
11491289 struct hclge_mac *mac = &hdev->hw.mac;
11501290
11511291 return hclge_pause_param_cfg(hdev, mac->mac_addr,
1152
- HCLGE_DEFAULT_PAUSE_TRANS_GAP,
1153
- HCLGE_DEFAULT_PAUSE_TRANS_TIME);
1292
+ HCLGE_DEFAULT_PAUSE_TRANS_GAP,
1293
+ HCLGE_DEFAULT_PAUSE_TRANS_TIME);
11541294 }
11551295
11561296 static int hclge_pfc_setup_hw(struct hclge_dev *hdev)
....@@ -1231,10 +1371,23 @@
12311371 return hclge_mac_pause_en_cfg(hdev, tx_en, rx_en);
12321372 }
12331373
1234
-int hclge_pause_setup_hw(struct hclge_dev *hdev)
1374
+static int hclge_tm_bp_setup(struct hclge_dev *hdev)
12351375 {
12361376 int ret;
1237
- u8 i;
1377
+ int i;
1378
+
1379
+ for (i = 0; i < hdev->tm_info.num_tc; i++) {
1380
+ ret = hclge_bp_setup_hw(hdev, i);
1381
+ if (ret)
1382
+ return ret;
1383
+ }
1384
+
1385
+ return 0;
1386
+}
1387
+
1388
+int hclge_pause_setup_hw(struct hclge_dev *hdev, bool init)
1389
+{
1390
+ int ret;
12381391
12391392 ret = hclge_pause_param_setup_hw(hdev);
12401393 if (ret)
....@@ -1248,29 +1401,29 @@
12481401 if (!hnae3_dev_dcb_supported(hdev))
12491402 return 0;
12501403
1251
- /* When MAC is GE Mode, hdev does not support pfc setting */
1404
+ /* GE MAC does not support PFC, when driver is initializing and MAC
1405
+ * is in GE Mode, ignore the error here, otherwise initialization
1406
+ * will fail.
1407
+ */
12521408 ret = hclge_pfc_setup_hw(hdev);
1253
- if (ret)
1254
- dev_warn(&hdev->pdev->dev, "set pfc pause failed:%d\n", ret);
1255
-
1256
- for (i = 0; i < hdev->tm_info.num_tc; i++) {
1257
- ret = hclge_bp_setup_hw(hdev, i);
1258
- if (ret)
1259
- return ret;
1409
+ if (init && ret == -EOPNOTSUPP)
1410
+ dev_warn(&hdev->pdev->dev, "GE MAC does not support pfc\n");
1411
+ else if (ret) {
1412
+ dev_err(&hdev->pdev->dev, "config pfc failed! ret = %d\n",
1413
+ ret);
1414
+ return ret;
12601415 }
12611416
1262
- return 0;
1417
+ return hclge_tm_bp_setup(hdev);
12631418 }
12641419
1265
-int hclge_tm_prio_tc_info_update(struct hclge_dev *hdev, u8 *prio_tc)
1420
+void hclge_tm_prio_tc_info_update(struct hclge_dev *hdev, u8 *prio_tc)
12661421 {
12671422 struct hclge_vport *vport = hdev->vport;
12681423 struct hnae3_knic_private_info *kinfo;
12691424 u32 i, k;
12701425
12711426 for (i = 0; i < HNAE3_MAX_USER_PRIO; i++) {
1272
- if (prio_tc[i] >= hdev->tm_info.num_tc)
1273
- return -EINVAL;
12741427 hdev->tm_info.prio_tc[i] = prio_tc[i];
12751428
12761429 for (k = 0; k < hdev->num_alloc_vport; k++) {
....@@ -1278,12 +1431,12 @@
12781431 kinfo->prio_tc[i] = prio_tc[i];
12791432 }
12801433 }
1281
- return 0;
12821434 }
12831435
12841436 void hclge_tm_schd_info_update(struct hclge_dev *hdev, u8 num_tc)
12851437 {
1286
- u8 i, bit_map = 0;
1438
+ u8 bit_map = 0;
1439
+ u8 i;
12871440
12881441 hdev->tm_info.num_tc = num_tc;
12891442
....@@ -1300,7 +1453,7 @@
13001453 hclge_tm_schd_info_init(hdev);
13011454 }
13021455
1303
-int hclge_tm_init_hw(struct hclge_dev *hdev)
1456
+int hclge_tm_init_hw(struct hclge_dev *hdev, bool init)
13041457 {
13051458 int ret;
13061459
....@@ -1312,7 +1465,7 @@
13121465 if (ret)
13131466 return ret;
13141467
1315
- ret = hclge_pause_setup_hw(hdev);
1468
+ ret = hclge_pause_setup_hw(hdev, init);
13161469 if (ret)
13171470 return ret;
13181471
....@@ -1321,15 +1474,32 @@
13211474
13221475 int hclge_tm_schd_init(struct hclge_dev *hdev)
13231476 {
1324
- int ret;
1325
-
13261477 /* fc_mode is HCLGE_FC_FULL on reset */
13271478 hdev->tm_info.fc_mode = HCLGE_FC_FULL;
13281479 hdev->fc_mode_last_time = hdev->tm_info.fc_mode;
13291480
1330
- ret = hclge_tm_schd_info_init(hdev);
1481
+ if (hdev->tx_sch_mode != HCLGE_FLAG_TC_BASE_SCH_MODE &&
1482
+ hdev->tm_info.num_pg != 1)
1483
+ return -EINVAL;
1484
+
1485
+ hclge_tm_schd_info_init(hdev);
1486
+
1487
+ return hclge_tm_init_hw(hdev, true);
1488
+}
1489
+
1490
+int hclge_tm_vport_map_update(struct hclge_dev *hdev)
1491
+{
1492
+ struct hclge_vport *vport = hdev->vport;
1493
+ int ret;
1494
+
1495
+ hclge_tm_vport_tc_info_update(vport);
1496
+
1497
+ ret = hclge_vport_q_to_qs_map(hdev, vport);
13311498 if (ret)
13321499 return ret;
13331500
1334
- return hclge_tm_init_hw(hdev);
1501
+ if (hdev->tm_info.num_tc == 1 && !hdev->tm_info.pfc_en)
1502
+ return 0;
1503
+
1504
+ return hclge_tm_bp_setup(hdev);
13351505 }