Skip to content

Commit a071c6a

Browse files
committed
Merge branch 'hns3-fixes'
Jijie Shao says: ==================== There are some bugfix for the HNS3 ethernet driver There are some bugfix for the HNS3 ethernet driver ==================== Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents c7b75be + 882481b commit a071c6a

File tree

8 files changed

+110
-16
lines changed

8 files changed

+110
-16
lines changed

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/pci.h>
3232
#include <linux/pkt_sched.h>
3333
#include <linux/types.h>
34+
#include <linux/bitmap.h>
3435
#include <net/pkt_cls.h>
3536
#include <net/pkt_sched.h>
3637

@@ -101,6 +102,7 @@ enum HNAE3_DEV_CAP_BITS {
101102
HNAE3_DEV_SUPPORT_FEC_STATS_B,
102103
HNAE3_DEV_SUPPORT_LANE_NUM_B,
103104
HNAE3_DEV_SUPPORT_WOL_B,
105+
HNAE3_DEV_SUPPORT_TM_FLUSH_B,
104106
};
105107

106108
#define hnae3_ae_dev_fd_supported(ae_dev) \
@@ -172,6 +174,9 @@ enum HNAE3_DEV_CAP_BITS {
172174
#define hnae3_ae_dev_wol_supported(ae_dev) \
173175
test_bit(HNAE3_DEV_SUPPORT_WOL_B, (ae_dev)->caps)
174176

177+
#define hnae3_ae_dev_tm_flush_supported(hdev) \
178+
test_bit(HNAE3_DEV_SUPPORT_TM_FLUSH_B, (hdev)->ae_dev->caps)
179+
175180
enum HNAE3_PF_CAP_BITS {
176181
HNAE3_PF_SUPPORT_VLAN_FLTR_MDF_B = 0,
177182
};
@@ -407,7 +412,7 @@ struct hnae3_ae_dev {
407412
unsigned long hw_err_reset_req;
408413
struct hnae3_dev_specs dev_specs;
409414
u32 dev_version;
410-
unsigned long caps[BITS_TO_LONGS(HNAE3_DEV_CAPS_MAX_NUM)];
415+
DECLARE_BITMAP(caps, HNAE3_DEV_CAPS_MAX_NUM);
411416
void *priv;
412417
};
413418

drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_cmd.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ static const struct hclge_comm_caps_bit_map hclge_pf_cmd_caps[] = {
156156
{HCLGE_COMM_CAP_FEC_STATS_B, HNAE3_DEV_SUPPORT_FEC_STATS_B},
157157
{HCLGE_COMM_CAP_LANE_NUM_B, HNAE3_DEV_SUPPORT_LANE_NUM_B},
158158
{HCLGE_COMM_CAP_WOL_B, HNAE3_DEV_SUPPORT_WOL_B},
159+
{HCLGE_COMM_CAP_TM_FLUSH_B, HNAE3_DEV_SUPPORT_TM_FLUSH_B},
159160
};
160161

161162
static const struct hclge_comm_caps_bit_map hclge_vf_cmd_caps[] = {
@@ -171,6 +172,20 @@ static const struct hclge_comm_caps_bit_map hclge_vf_cmd_caps[] = {
171172
{HCLGE_COMM_CAP_GRO_B, HNAE3_DEV_SUPPORT_GRO_B},
172173
};
173174

175+
static void
176+
hclge_comm_capability_to_bitmap(unsigned long *bitmap, __le32 *caps)
177+
{
178+
const unsigned int words = HCLGE_COMM_QUERY_CAP_LENGTH;
179+
u32 val[HCLGE_COMM_QUERY_CAP_LENGTH];
180+
unsigned int i;
181+
182+
for (i = 0; i < words; i++)
183+
val[i] = __le32_to_cpu(caps[i]);
184+
185+
bitmap_from_arr32(bitmap, val,
186+
HCLGE_COMM_QUERY_CAP_LENGTH * BITS_PER_TYPE(u32));
187+
}
188+
174189
static void
175190
hclge_comm_parse_capability(struct hnae3_ae_dev *ae_dev, bool is_pf,
176191
struct hclge_comm_query_version_cmd *cmd)
@@ -179,11 +194,12 @@ hclge_comm_parse_capability(struct hnae3_ae_dev *ae_dev, bool is_pf,
179194
is_pf ? hclge_pf_cmd_caps : hclge_vf_cmd_caps;
180195
u32 size = is_pf ? ARRAY_SIZE(hclge_pf_cmd_caps) :
181196
ARRAY_SIZE(hclge_vf_cmd_caps);
182-
u32 caps, i;
197+
DECLARE_BITMAP(caps, HCLGE_COMM_QUERY_CAP_LENGTH * BITS_PER_TYPE(u32));
198+
u32 i;
183199

184-
caps = __le32_to_cpu(cmd->caps[0]);
200+
hclge_comm_capability_to_bitmap(caps, cmd->caps);
185201
for (i = 0; i < size; i++)
186-
if (hnae3_get_bit(caps, caps_map[i].imp_bit))
202+
if (test_bit(caps_map[i].imp_bit, caps))
187203
set_bit(caps_map[i].local_bit, ae_dev->caps);
188204
}
189205

drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_cmd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ enum hclge_opcode_type {
153153
HCLGE_OPC_TM_INTERNAL_STS = 0x0850,
154154
HCLGE_OPC_TM_INTERNAL_CNT = 0x0851,
155155
HCLGE_OPC_TM_INTERNAL_STS_1 = 0x0852,
156+
HCLGE_OPC_TM_FLUSH = 0x0872,
156157

157158
/* Packet buffer allocate commands */
158159
HCLGE_OPC_TX_BUFF_ALLOC = 0x0901,
@@ -349,6 +350,7 @@ enum HCLGE_COMM_CAP_BITS {
349350
HCLGE_COMM_CAP_FEC_STATS_B = 25,
350351
HCLGE_COMM_CAP_LANE_NUM_B = 27,
351352
HCLGE_COMM_CAP_WOL_B = 28,
353+
HCLGE_COMM_CAP_TM_FLUSH_B = 31,
352354
};
353355

354356
enum HCLGE_COMM_API_CAP_BITS {

drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ static struct hns3_dbg_cap_info hns3_dbg_cap[] = {
411411
}, {
412412
.name = "support wake on lan",
413413
.cap_bit = HNAE3_DEV_SUPPORT_WOL_B,
414+
}, {
415+
.name = "support tm flush",
416+
.cap_bit = HNAE3_DEV_SUPPORT_TM_FLUSH_B,
414417
}
415418
};
416419

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

125128
static 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

362397
static int hclge_ieee_setapp(struct hnae3_handle *h, struct dcb_app *app)

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ static int hclge_dbg_dump_tc(struct hclge_dev *hdev, char *buf, int len)
693693
for (i = 0; i < HNAE3_MAX_TC; i++) {
694694
sch_mode_str = ets_weight->tc_weight[i] ? "dwrr" : "sp";
695695
pos += scnprintf(buf + pos, len - pos, "%u %4s %3u\n",
696-
i, sch_mode_str,
697-
hdev->tm_info.pg_info[0].tc_dwrr[i]);
696+
i, sch_mode_str, ets_weight->tc_weight[i]);
698697
}
699698

700699
return 0;

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ static void hclge_tm_tc_info_init(struct hclge_dev *hdev)
785785
static void hclge_tm_pg_info_init(struct hclge_dev *hdev)
786786
{
787787
#define BW_PERCENT 100
788+
#define DEFAULT_BW_WEIGHT 1
788789

789790
u8 i;
790791

@@ -806,7 +807,7 @@ static void hclge_tm_pg_info_init(struct hclge_dev *hdev)
806807
for (k = 0; k < hdev->tm_info.num_tc; k++)
807808
hdev->tm_info.pg_info[i].tc_dwrr[k] = BW_PERCENT;
808809
for (; k < HNAE3_MAX_TC; k++)
809-
hdev->tm_info.pg_info[i].tc_dwrr[k] = 0;
810+
hdev->tm_info.pg_info[i].tc_dwrr[k] = DEFAULT_BW_WEIGHT;
810811
}
811812
}
812813

@@ -1484,7 +1485,11 @@ int hclge_tm_schd_setup_hw(struct hclge_dev *hdev)
14841485
return ret;
14851486

14861487
/* Cfg schd mode for each level schd */
1487-
return hclge_tm_schd_mode_hw(hdev);
1488+
ret = hclge_tm_schd_mode_hw(hdev);
1489+
if (ret)
1490+
return ret;
1491+
1492+
return hclge_tm_flush_cfg(hdev, false);
14881493
}
14891494

14901495
static int hclge_pause_param_setup_hw(struct hclge_dev *hdev)
@@ -2113,3 +2118,28 @@ int hclge_tm_get_port_shaper(struct hclge_dev *hdev,
21132118

21142119
return 0;
21152120
}
2121+
2122+
int hclge_tm_flush_cfg(struct hclge_dev *hdev, bool enable)
2123+
{
2124+
struct hclge_desc desc;
2125+
int ret;
2126+
2127+
if (!hnae3_ae_dev_tm_flush_supported(hdev))
2128+
return 0;
2129+
2130+
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_TM_FLUSH, false);
2131+
2132+
desc.data[0] = cpu_to_le32(enable ? HCLGE_TM_FLUSH_EN_MSK : 0);
2133+
2134+
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
2135+
if (ret) {
2136+
dev_err(&hdev->pdev->dev,
2137+
"failed to config tm flush, ret = %d\n", ret);
2138+
return ret;
2139+
}
2140+
2141+
if (enable)
2142+
msleep(HCLGE_TM_FLUSH_TIME_MS);
2143+
2144+
return ret;
2145+
}

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ enum hclge_opcode_type;
3333
#define HCLGE_DSCP_MAP_TC_BD_NUM 2
3434
#define HCLGE_DSCP_TC_SHIFT(n) (((n) & 1) * 4)
3535

36+
#define HCLGE_TM_FLUSH_TIME_MS 10
37+
#define HCLGE_TM_FLUSH_EN_MSK BIT(0)
38+
3639
struct hclge_pg_to_pri_link_cmd {
3740
u8 pg_id;
3841
u8 rsvd1[3];
@@ -272,4 +275,5 @@ int hclge_tm_get_port_shaper(struct hclge_dev *hdev,
272275
struct hclge_tm_shaper_para *para);
273276
int hclge_up_to_tc_map(struct hclge_dev *hdev);
274277
int hclge_dscp_to_tc_map(struct hclge_dev *hdev);
278+
int hclge_tm_flush_cfg(struct hclge_dev *hdev, bool enable);
275279
#endif

0 commit comments

Comments
 (0)