forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
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)
....@@ -173,7 +173,7 @@
173173 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,42 @@
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
+
588655 u8 i;
589656
590657 for (i = 0; i < hdev->tm_info.num_pg; i++) {
591658 int k;
592659
593
- hdev->tm_info.pg_dwrr[i] = i ? 0 : 100;
660
+ hdev->tm_info.pg_dwrr[i] = i ? 0 : BW_PERCENT;
594661
595662 hdev->tm_info.pg_info[i].pg_id = i;
596663 hdev->tm_info.pg_info[i].pg_sch_mode = HCLGE_SCH_MODE_DWRR;
597664
598
- hdev->tm_info.pg_info[i].bw_limit = HCLGE_ETHER_MAX_RATE;
665
+ hdev->tm_info.pg_info[i].bw_limit =
666
+ hdev->ae_dev->dev_specs.max_tm_rate;
599667
600668 if (i != 0)
601669 continue;
602670
603671 hdev->tm_info.pg_info[i].tc_bit_map = hdev->hw_tc_map;
604672 for (k = 0; k < hdev->tm_info.num_tc; k++)
605
- hdev->tm_info.pg_info[i].tc_dwrr[k] = 100;
673
+ hdev->tm_info.pg_info[i].tc_dwrr[k] = BW_PERCENT;
674
+ for (; k < HNAE3_MAX_TC; k++)
675
+ hdev->tm_info.pg_info[i].tc_dwrr[k] = 0;
606676 }
607677 }
608678
609
-static void hclge_pfc_info_init(struct hclge_dev *hdev)
679
+static void hclge_update_fc_mode_by_dcb_flag(struct hclge_dev *hdev)
610680 {
611
- if (!(hdev->flag & HCLGE_FLAG_DCB_ENABLE)) {
681
+ if (hdev->tm_info.num_tc == 1 && !hdev->tm_info.pfc_en) {
612682 if (hdev->fc_mode_last_time == HCLGE_FC_PFC)
613683 dev_warn(&hdev->pdev->dev,
614
- "DCB is disable, but last mode is FC_PFC\n");
684
+ "Only 1 tc used, but last mode is FC_PFC\n");
615685
616686 hdev->tm_info.fc_mode = hdev->fc_mode_last_time;
617687 } else if (hdev->tm_info.fc_mode != HCLGE_FC_PFC) {
....@@ -624,21 +694,36 @@
624694 }
625695 }
626696
627
-static int hclge_tm_schd_info_init(struct hclge_dev *hdev)
697
+static void hclge_update_fc_mode(struct hclge_dev *hdev)
628698 {
629
- if ((hdev->tx_sch_mode != HCLGE_FLAG_TC_BASE_SCH_MODE) &&
630
- (hdev->tm_info.num_pg != 1))
631
- return -EINVAL;
699
+ if (!hdev->tm_info.pfc_en) {
700
+ hdev->tm_info.fc_mode = hdev->fc_mode_last_time;
701
+ return;
702
+ }
632703
704
+ if (hdev->tm_info.fc_mode != HCLGE_FC_PFC) {
705
+ hdev->fc_mode_last_time = hdev->tm_info.fc_mode;
706
+ hdev->tm_info.fc_mode = HCLGE_FC_PFC;
707
+ }
708
+}
709
+
710
+void hclge_tm_pfc_info_update(struct hclge_dev *hdev)
711
+{
712
+ if (hdev->ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V3)
713
+ hclge_update_fc_mode(hdev);
714
+ else
715
+ hclge_update_fc_mode_by_dcb_flag(hdev);
716
+}
717
+
718
+static void hclge_tm_schd_info_init(struct hclge_dev *hdev)
719
+{
633720 hclge_tm_pg_info_init(hdev);
634721
635722 hclge_tm_tc_info_init(hdev);
636723
637724 hclge_tm_vport_info_update(hdev);
638725
639
- hclge_pfc_info_init(hdev);
640
-
641
- return 0;
726
+ hclge_tm_pfc_info_update(hdev);
642727 }
643728
644729 static int hclge_tm_pg_to_pri_map(struct hclge_dev *hdev)
....@@ -662,7 +747,9 @@
662747
663748 static int hclge_tm_pg_shaper_cfg(struct hclge_dev *hdev)
664749 {
665
- u8 ir_u, ir_b, ir_s;
750
+ u32 max_tm_rate = hdev->ae_dev->dev_specs.max_tm_rate;
751
+ struct hclge_shaper_ir_para ir_para;
752
+ u32 shaper_para;
666753 int ret;
667754 u32 i;
668755
....@@ -673,25 +760,29 @@
673760 /* Pg to pri */
674761 for (i = 0; i < hdev->tm_info.num_pg; i++) {
675762 /* 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);
763
+ ret = hclge_shaper_para_calc(hdev->tm_info.pg_info[i].bw_limit,
764
+ HCLGE_SHAPER_LVL_PG,
765
+ &ir_para, max_tm_rate);
680766 if (ret)
681767 return ret;
682768
769
+ shaper_para = hclge_tm_get_shapping_para(0, 0, 0,
770
+ HCLGE_SHAPER_BS_U_DEF,
771
+ HCLGE_SHAPER_BS_S_DEF);
683772 ret = hclge_tm_pg_shapping_cfg(hdev,
684773 HCLGE_TM_SHAP_C_BUCKET, i,
685
- 0, 0, 0, HCLGE_SHAPER_BS_U_DEF,
686
- HCLGE_SHAPER_BS_S_DEF);
774
+ shaper_para);
687775 if (ret)
688776 return ret;
689777
778
+ shaper_para = hclge_tm_get_shapping_para(ir_para.ir_b,
779
+ ir_para.ir_u,
780
+ ir_para.ir_s,
781
+ HCLGE_SHAPER_BS_U_DEF,
782
+ HCLGE_SHAPER_BS_S_DEF);
690783 ret = hclge_tm_pg_shapping_cfg(hdev,
691784 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);
785
+ shaper_para);
695786 if (ret)
696787 return ret;
697788 }
....@@ -711,8 +802,7 @@
711802 /* pg to prio */
712803 for (i = 0; i < hdev->tm_info.num_pg; i++) {
713804 /* Cfg dwrr */
714
- ret = hclge_tm_pg_weight_cfg(hdev, i,
715
- hdev->tm_info.pg_dwrr[i]);
805
+ ret = hclge_tm_pg_weight_cfg(hdev, i, hdev->tm_info.pg_dwrr[i]);
716806 if (ret)
717807 return ret;
718808 }
....@@ -753,13 +843,17 @@
753843
754844 if (hdev->tx_sch_mode == HCLGE_FLAG_TC_BASE_SCH_MODE) {
755845 /* 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++) {
846
+ for (k = 0; k < hdev->num_alloc_vport; k++) {
847
+ struct hnae3_knic_private_info *kinfo =
848
+ &vport[k].nic.kinfo;
849
+
850
+ for (i = 0; i < kinfo->num_tc; i++) {
758851 ret = hclge_tm_qs_to_pri_map_cfg(
759852 hdev, vport[k].qs_offset + i, i);
760853 if (ret)
761854 return ret;
762855 }
856
+ }
763857 } else if (hdev->tx_sch_mode == HCLGE_FLAG_VNET_BASE_SCH_MODE) {
764858 /* Cfg qs -> pri mapping, qs = tc, pri = vf, 8 qs -> 1 pri */
765859 for (k = 0; k < hdev->num_alloc_vport; k++)
....@@ -787,29 +881,34 @@
787881
788882 static int hclge_tm_pri_tc_base_shaper_cfg(struct hclge_dev *hdev)
789883 {
790
- u8 ir_u, ir_b, ir_s;
884
+ u32 max_tm_rate = hdev->ae_dev->dev_specs.max_tm_rate;
885
+ struct hclge_shaper_ir_para ir_para;
886
+ u32 shaper_para;
791887 int ret;
792888 u32 i;
793889
794890 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);
891
+ ret = hclge_shaper_para_calc(hdev->tm_info.tc_info[i].bw_limit,
892
+ HCLGE_SHAPER_LVL_PRI,
893
+ &ir_para, max_tm_rate);
799894 if (ret)
800895 return ret;
801896
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);
897
+ shaper_para = hclge_tm_get_shapping_para(0, 0, 0,
898
+ HCLGE_SHAPER_BS_U_DEF,
899
+ HCLGE_SHAPER_BS_S_DEF);
900
+ ret = hclge_tm_pri_shapping_cfg(hdev, HCLGE_TM_SHAP_C_BUCKET, i,
901
+ shaper_para);
806902 if (ret)
807903 return ret;
808904
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);
905
+ shaper_para = hclge_tm_get_shapping_para(ir_para.ir_b,
906
+ ir_para.ir_u,
907
+ ir_para.ir_s,
908
+ HCLGE_SHAPER_BS_U_DEF,
909
+ HCLGE_SHAPER_BS_S_DEF);
910
+ ret = hclge_tm_pri_shapping_cfg(hdev, HCLGE_TM_SHAP_P_BUCKET, i,
911
+ shaper_para);
813912 if (ret)
814913 return ret;
815914 }
....@@ -820,26 +919,30 @@
820919 static int hclge_tm_pri_vnet_base_shaper_pri_cfg(struct hclge_vport *vport)
821920 {
822921 struct hclge_dev *hdev = vport->back;
823
- u8 ir_u, ir_b, ir_s;
922
+ struct hclge_shaper_ir_para ir_para;
923
+ u32 shaper_para;
824924 int ret;
825925
826926 ret = hclge_shaper_para_calc(vport->bw_limit, HCLGE_SHAPER_LVL_VF,
827
- &ir_b, &ir_u, &ir_s);
927
+ &ir_para,
928
+ hdev->ae_dev->dev_specs.max_tm_rate);
828929 if (ret)
829930 return ret;
830931
932
+ shaper_para = hclge_tm_get_shapping_para(0, 0, 0,
933
+ HCLGE_SHAPER_BS_U_DEF,
934
+ HCLGE_SHAPER_BS_S_DEF);
831935 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);
936
+ vport->vport_id, shaper_para);
835937 if (ret)
836938 return ret;
837939
940
+ shaper_para = hclge_tm_get_shapping_para(ir_para.ir_b, ir_para.ir_u,
941
+ ir_para.ir_s,
942
+ HCLGE_SHAPER_BS_U_DEF,
943
+ HCLGE_SHAPER_BS_S_DEF);
838944 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);
945
+ vport->vport_id, shaper_para);
843946 if (ret)
844947 return ret;
845948
....@@ -850,15 +953,15 @@
850953 {
851954 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
852955 struct hclge_dev *hdev = vport->back;
853
- u8 ir_u, ir_b, ir_s;
956
+ u32 max_tm_rate = hdev->ae_dev->dev_specs.max_tm_rate;
957
+ struct hclge_shaper_ir_para ir_para;
854958 u32 i;
855959 int ret;
856960
857961 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);
962
+ ret = hclge_shaper_para_calc(hdev->tm_info.tc_info[i].bw_limit,
963
+ HCLGE_SHAPER_LVL_QSET,
964
+ &ir_para, max_tm_rate);
862965 if (ret)
863966 return ret;
864967 }
....@@ -934,6 +1037,29 @@
9341037 return 0;
9351038 }
9361039
1040
+static int hclge_tm_ets_tc_dwrr_cfg(struct hclge_dev *hdev)
1041
+{
1042
+#define DEFAULT_TC_OFFSET 14
1043
+
1044
+ struct hclge_ets_tc_weight_cmd *ets_weight;
1045
+ struct hclge_desc desc;
1046
+ unsigned int i;
1047
+
1048
+ hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_ETS_TC_WEIGHT, false);
1049
+ ets_weight = (struct hclge_ets_tc_weight_cmd *)desc.data;
1050
+
1051
+ for (i = 0; i < HNAE3_MAX_TC; i++) {
1052
+ struct hclge_pg_info *pg_info;
1053
+
1054
+ pg_info = &hdev->tm_info.pg_info[hdev->tm_info.tc_info[i].pgid];
1055
+ ets_weight->tc_weight[i] = pg_info->tc_dwrr[i];
1056
+ }
1057
+
1058
+ ets_weight->weight_offset = DEFAULT_TC_OFFSET;
1059
+
1060
+ return hclge_cmd_send(&hdev->hw, &desc, 1);
1061
+}
1062
+
9371063 static int hclge_tm_pri_vnet_base_dwrr_pri_cfg(struct hclge_vport *vport)
9381064 {
9391065 struct hnae3_knic_private_info *kinfo = &vport->nic.kinfo;
....@@ -983,6 +1109,19 @@
9831109 ret = hclge_tm_pri_tc_base_dwrr_cfg(hdev);
9841110 if (ret)
9851111 return ret;
1112
+
1113
+ if (!hnae3_dev_dcb_supported(hdev))
1114
+ return 0;
1115
+
1116
+ ret = hclge_tm_ets_tc_dwrr_cfg(hdev);
1117
+ if (ret == -EOPNOTSUPP) {
1118
+ dev_warn(&hdev->pdev->dev,
1119
+ "fw %08x does't support ets tc weight cmd\n",
1120
+ hdev->fw_version);
1121
+ ret = 0;
1122
+ }
1123
+
1124
+ return ret;
9861125 } else {
9871126 ret = hclge_tm_pri_vnet_base_dwrr_cfg(hdev);
9881127 if (ret)
....@@ -992,7 +1131,7 @@
9921131 return 0;
9931132 }
9941133
995
-int hclge_tm_map_cfg(struct hclge_dev *hdev)
1134
+static int hclge_tm_map_cfg(struct hclge_dev *hdev)
9961135 {
9971136 int ret;
9981137
....@@ -1110,7 +1249,7 @@
11101249 return 0;
11111250 }
11121251
1113
-int hclge_tm_schd_mode_hw(struct hclge_dev *hdev)
1252
+static int hclge_tm_schd_mode_hw(struct hclge_dev *hdev)
11141253 {
11151254 int ret;
11161255
....@@ -1121,7 +1260,7 @@
11211260 return hclge_tm_lvl34_schd_mode_cfg(hdev);
11221261 }
11231262
1124
-static int hclge_tm_schd_setup_hw(struct hclge_dev *hdev)
1263
+int hclge_tm_schd_setup_hw(struct hclge_dev *hdev)
11251264 {
11261265 int ret;
11271266
....@@ -1149,8 +1288,8 @@
11491288 struct hclge_mac *mac = &hdev->hw.mac;
11501289
11511290 return hclge_pause_param_cfg(hdev, mac->mac_addr,
1152
- HCLGE_DEFAULT_PAUSE_TRANS_GAP,
1153
- HCLGE_DEFAULT_PAUSE_TRANS_TIME);
1291
+ HCLGE_DEFAULT_PAUSE_TRANS_GAP,
1292
+ HCLGE_DEFAULT_PAUSE_TRANS_TIME);
11541293 }
11551294
11561295 static int hclge_pfc_setup_hw(struct hclge_dev *hdev)
....@@ -1231,10 +1370,23 @@
12311370 return hclge_mac_pause_en_cfg(hdev, tx_en, rx_en);
12321371 }
12331372
1234
-int hclge_pause_setup_hw(struct hclge_dev *hdev)
1373
+static int hclge_tm_bp_setup(struct hclge_dev *hdev)
12351374 {
12361375 int ret;
1237
- u8 i;
1376
+ int i;
1377
+
1378
+ for (i = 0; i < hdev->tm_info.num_tc; i++) {
1379
+ ret = hclge_bp_setup_hw(hdev, i);
1380
+ if (ret)
1381
+ return ret;
1382
+ }
1383
+
1384
+ return 0;
1385
+}
1386
+
1387
+int hclge_pause_setup_hw(struct hclge_dev *hdev, bool init)
1388
+{
1389
+ int ret;
12381390
12391391 ret = hclge_pause_param_setup_hw(hdev);
12401392 if (ret)
....@@ -1248,29 +1400,29 @@
12481400 if (!hnae3_dev_dcb_supported(hdev))
12491401 return 0;
12501402
1251
- /* When MAC is GE Mode, hdev does not support pfc setting */
1403
+ /* GE MAC does not support PFC, when driver is initializing and MAC
1404
+ * is in GE Mode, ignore the error here, otherwise initialization
1405
+ * will fail.
1406
+ */
12521407 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;
1408
+ if (init && ret == -EOPNOTSUPP)
1409
+ dev_warn(&hdev->pdev->dev, "GE MAC does not support pfc\n");
1410
+ else if (ret) {
1411
+ dev_err(&hdev->pdev->dev, "config pfc failed! ret = %d\n",
1412
+ ret);
1413
+ return ret;
12601414 }
12611415
1262
- return 0;
1416
+ return hclge_tm_bp_setup(hdev);
12631417 }
12641418
1265
-int hclge_tm_prio_tc_info_update(struct hclge_dev *hdev, u8 *prio_tc)
1419
+void hclge_tm_prio_tc_info_update(struct hclge_dev *hdev, u8 *prio_tc)
12661420 {
12671421 struct hclge_vport *vport = hdev->vport;
12681422 struct hnae3_knic_private_info *kinfo;
12691423 u32 i, k;
12701424
12711425 for (i = 0; i < HNAE3_MAX_USER_PRIO; i++) {
1272
- if (prio_tc[i] >= hdev->tm_info.num_tc)
1273
- return -EINVAL;
12741426 hdev->tm_info.prio_tc[i] = prio_tc[i];
12751427
12761428 for (k = 0; k < hdev->num_alloc_vport; k++) {
....@@ -1278,12 +1430,12 @@
12781430 kinfo->prio_tc[i] = prio_tc[i];
12791431 }
12801432 }
1281
- return 0;
12821433 }
12831434
12841435 void hclge_tm_schd_info_update(struct hclge_dev *hdev, u8 num_tc)
12851436 {
1286
- u8 i, bit_map = 0;
1437
+ u8 bit_map = 0;
1438
+ u8 i;
12871439
12881440 hdev->tm_info.num_tc = num_tc;
12891441
....@@ -1300,7 +1452,7 @@
13001452 hclge_tm_schd_info_init(hdev);
13011453 }
13021454
1303
-int hclge_tm_init_hw(struct hclge_dev *hdev)
1455
+int hclge_tm_init_hw(struct hclge_dev *hdev, bool init)
13041456 {
13051457 int ret;
13061458
....@@ -1312,7 +1464,7 @@
13121464 if (ret)
13131465 return ret;
13141466
1315
- ret = hclge_pause_setup_hw(hdev);
1467
+ ret = hclge_pause_setup_hw(hdev, init);
13161468 if (ret)
13171469 return ret;
13181470
....@@ -1321,15 +1473,32 @@
13211473
13221474 int hclge_tm_schd_init(struct hclge_dev *hdev)
13231475 {
1324
- int ret;
1325
-
13261476 /* fc_mode is HCLGE_FC_FULL on reset */
13271477 hdev->tm_info.fc_mode = HCLGE_FC_FULL;
13281478 hdev->fc_mode_last_time = hdev->tm_info.fc_mode;
13291479
1330
- ret = hclge_tm_schd_info_init(hdev);
1480
+ if (hdev->tx_sch_mode != HCLGE_FLAG_TC_BASE_SCH_MODE &&
1481
+ hdev->tm_info.num_pg != 1)
1482
+ return -EINVAL;
1483
+
1484
+ hclge_tm_schd_info_init(hdev);
1485
+
1486
+ return hclge_tm_init_hw(hdev, true);
1487
+}
1488
+
1489
+int hclge_tm_vport_map_update(struct hclge_dev *hdev)
1490
+{
1491
+ struct hclge_vport *vport = hdev->vport;
1492
+ int ret;
1493
+
1494
+ hclge_tm_vport_tc_info_update(vport);
1495
+
1496
+ ret = hclge_vport_q_to_qs_map(hdev, vport);
13311497 if (ret)
13321498 return ret;
13331499
1334
- return hclge_tm_init_hw(hdev);
1500
+ if (hdev->tm_info.num_tc == 1 && !hdev->tm_info.pfc_en)
1501
+ return 0;
1502
+
1503
+ return hclge_tm_bp_setup(hdev);
13351504 }