@@ -52,7 +52,10 @@ static void hclge_tm_info_to_ieee_ets(struct hclge_dev *hdev,
5252
5353 for (i = 0 ; i < HNAE3_MAX_TC ; i ++ ) {
5454 ets -> prio_tc [i ] = hdev -> tm_info .prio_tc [i ];
55- ets -> tc_tx_bw [i ] = hdev -> tm_info .pg_info [0 ].tc_dwrr [i ];
55+ if (i < hdev -> tm_info .num_tc )
56+ ets -> tc_tx_bw [i ] = hdev -> tm_info .pg_info [0 ].tc_dwrr [i ];
57+ else
58+ ets -> tc_tx_bw [i ] = 0 ;
5659
5760 if (hdev -> tm_info .tc_info [i ].tc_sch_mode ==
5861 HCLGE_SCH_MODE_SP )
@@ -123,7 +126,8 @@ static u8 hclge_ets_tc_changed(struct hclge_dev *hdev, struct ieee_ets *ets,
123126}
124127
125128static int hclge_ets_sch_mode_validate (struct hclge_dev * hdev ,
126- struct ieee_ets * ets , bool * changed )
129+ struct ieee_ets * ets , bool * changed ,
130+ u8 tc_num )
127131{
128132 bool has_ets_tc = false;
129133 u32 total_ets_bw = 0 ;
@@ -137,6 +141,13 @@ static int hclge_ets_sch_mode_validate(struct hclge_dev *hdev,
137141 * changed = true;
138142 break ;
139143 case IEEE_8021QAZ_TSA_ETS :
144+ if (i >= tc_num ) {
145+ dev_err (& hdev -> pdev -> dev ,
146+ "tc%u is disabled, cannot set ets bw\n" ,
147+ i );
148+ return - EINVAL ;
149+ }
150+
140151 /* The hardware will switch to sp mode if bandwidth is
141152 * 0, so limit ets bandwidth must be greater than 0.
142153 */
@@ -176,7 +187,7 @@ static int hclge_ets_validate(struct hclge_dev *hdev, struct ieee_ets *ets,
176187 if (ret )
177188 return ret ;
178189
179- ret = hclge_ets_sch_mode_validate (hdev , ets , changed );
190+ ret = hclge_ets_sch_mode_validate (hdev , ets , changed , tc_num );
180191 if (ret )
181192 return ret ;
182193
@@ -216,6 +227,10 @@ static int hclge_notify_down_uinit(struct hclge_dev *hdev)
216227 if (ret )
217228 return ret ;
218229
230+ ret = hclge_tm_flush_cfg (hdev , true);
231+ if (ret )
232+ return ret ;
233+
219234 return hclge_notify_client (hdev , HNAE3_UNINIT_CLIENT );
220235}
221236
@@ -227,6 +242,10 @@ static int hclge_notify_init_up(struct hclge_dev *hdev)
227242 if (ret )
228243 return ret ;
229244
245+ ret = hclge_tm_flush_cfg (hdev , false);
246+ if (ret )
247+ return ret ;
248+
230249 return hclge_notify_client (hdev , HNAE3_UP_CLIENT );
231250}
232251
@@ -313,6 +332,7 @@ static int hclge_ieee_setpfc(struct hnae3_handle *h, struct ieee_pfc *pfc)
313332 struct net_device * netdev = h -> kinfo .netdev ;
314333 struct hclge_dev * hdev = vport -> back ;
315334 u8 i , j , pfc_map , * prio_tc ;
335+ int last_bad_ret = 0 ;
316336 int ret ;
317337
318338 if (!(hdev -> dcbx_cap & DCB_CAP_DCBX_VER_IEEE ))
@@ -350,13 +370,28 @@ static int hclge_ieee_setpfc(struct hnae3_handle *h, struct ieee_pfc *pfc)
350370 if (ret )
351371 return ret ;
352372
353- ret = hclge_buffer_alloc (hdev );
354- if (ret ) {
355- hclge_notify_client (hdev , HNAE3_UP_CLIENT );
373+ ret = hclge_tm_flush_cfg (hdev , true);
374+ if (ret )
356375 return ret ;
357- }
358376
359- return hclge_notify_client (hdev , HNAE3_UP_CLIENT );
377+ /* No matter whether the following operations are performed
378+ * successfully or not, disabling the tm flush and notify
379+ * the network status to up are necessary.
380+ * Do not return immediately.
381+ */
382+ ret = hclge_buffer_alloc (hdev );
383+ if (ret )
384+ last_bad_ret = ret ;
385+
386+ ret = hclge_tm_flush_cfg (hdev , false);
387+ if (ret )
388+ last_bad_ret = ret ;
389+
390+ ret = hclge_notify_client (hdev , HNAE3_UP_CLIENT );
391+ if (ret )
392+ last_bad_ret = ret ;
393+
394+ return last_bad_ret ;
360395}
361396
362397static int hclge_ieee_setapp (struct hnae3_handle * h , struct dcb_app * app )
0 commit comments