Skip to content

Commit fac24df

Browse files
IronShendavem330
authored andcommitted
net: hns3: fix return value error when query MAC link status fail
Currently, PF queries the MAC link status per second by calling function hclge_get_mac_link_status(). It return the error code when failed to send cmdq command to firmware. It's incorrect, because this return value is used as the MAC link status, which 0 means link down, and none-zero means link up. So fixes it. Fixes: 46a3df9 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer Support") Signed-off-by: Jian Shen <[email protected]> Signed-off-by: Huazhong tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8ceca59 commit fac24df

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

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

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,11 +2673,10 @@ void hclge_task_schedule(struct hclge_dev *hdev, unsigned long delay_time)
26732673
delay_time);
26742674
}
26752675

2676-
static int hclge_get_mac_link_status(struct hclge_dev *hdev)
2676+
static int hclge_get_mac_link_status(struct hclge_dev *hdev, int *link_status)
26772677
{
26782678
struct hclge_link_status_cmd *req;
26792679
struct hclge_desc desc;
2680-
int link_status;
26812680
int ret;
26822681

26832682
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_LINK_STATUS, true);
@@ -2689,33 +2688,25 @@ static int hclge_get_mac_link_status(struct hclge_dev *hdev)
26892688
}
26902689

26912690
req = (struct hclge_link_status_cmd *)desc.data;
2692-
link_status = req->status & HCLGE_LINK_STATUS_UP_M;
2691+
*link_status = (req->status & HCLGE_LINK_STATUS_UP_M) > 0 ?
2692+
HCLGE_LINK_STATUS_UP : HCLGE_LINK_STATUS_DOWN;
26932693

2694-
return !!link_status;
2694+
return 0;
26952695
}
26962696

2697-
static int hclge_get_mac_phy_link(struct hclge_dev *hdev)
2697+
static int hclge_get_mac_phy_link(struct hclge_dev *hdev, int *link_status)
26982698
{
2699-
unsigned int mac_state;
2700-
int link_stat;
2699+
struct phy_device *phydev = hdev->hw.mac.phydev;
2700+
2701+
*link_status = HCLGE_LINK_STATUS_DOWN;
27012702

27022703
if (test_bit(HCLGE_STATE_DOWN, &hdev->state))
27032704
return 0;
27042705

2705-
mac_state = hclge_get_mac_link_status(hdev);
2706-
2707-
if (hdev->hw.mac.phydev) {
2708-
if (hdev->hw.mac.phydev->state == PHY_RUNNING)
2709-
link_stat = mac_state &
2710-
hdev->hw.mac.phydev->link;
2711-
else
2712-
link_stat = 0;
2713-
2714-
} else {
2715-
link_stat = mac_state;
2716-
}
2706+
if (phydev && (phydev->state != PHY_RUNNING || !phydev->link))
2707+
return 0;
27172708

2718-
return !!link_stat;
2709+
return hclge_get_mac_link_status(hdev, link_status);
27192710
}
27202711

27212712
static void hclge_update_link_status(struct hclge_dev *hdev)
@@ -2725,6 +2716,7 @@ static void hclge_update_link_status(struct hclge_dev *hdev)
27252716
struct hnae3_handle *rhandle;
27262717
struct hnae3_handle *handle;
27272718
int state;
2719+
int ret;
27282720
int i;
27292721

27302722
if (!client)
@@ -2733,7 +2725,12 @@ static void hclge_update_link_status(struct hclge_dev *hdev)
27332725
if (test_and_set_bit(HCLGE_STATE_LINK_UPDATING, &hdev->state))
27342726
return;
27352727

2736-
state = hclge_get_mac_phy_link(hdev);
2728+
ret = hclge_get_mac_phy_link(hdev, &state);
2729+
if (ret) {
2730+
clear_bit(HCLGE_STATE_LINK_UPDATING, &hdev->state);
2731+
return;
2732+
}
2733+
27372734
if (state != hdev->hw.mac.link) {
27382735
for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
27392736
handle = &hdev->vport[i].nic;
@@ -6524,14 +6521,15 @@ static int hclge_mac_link_status_wait(struct hclge_dev *hdev, int link_ret)
65246521
{
65256522
#define HCLGE_MAC_LINK_STATUS_NUM 100
65266523

6524+
int link_status;
65276525
int i = 0;
65286526
int ret;
65296527

65306528
do {
6531-
ret = hclge_get_mac_link_status(hdev);
6532-
if (ret < 0)
6529+
ret = hclge_get_mac_link_status(hdev, &link_status);
6530+
if (ret)
65336531
return ret;
6534-
else if (ret == link_ret)
6532+
if (link_status == link_ret)
65356533
return 0;
65366534

65376535
msleep(HCLGE_LINK_STATUS_MS);
@@ -6542,9 +6540,6 @@ static int hclge_mac_link_status_wait(struct hclge_dev *hdev, int link_ret)
65426540
static int hclge_mac_phy_link_status_wait(struct hclge_dev *hdev, bool en,
65436541
bool is_phy)
65446542
{
6545-
#define HCLGE_LINK_STATUS_DOWN 0
6546-
#define HCLGE_LINK_STATUS_UP 1
6547-
65486543
int link_ret;
65496544

65506545
link_ret = en ? HCLGE_LINK_STATUS_UP : HCLGE_LINK_STATUS_DOWN;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ enum hclge_link_fail_code {
317317
HCLGE_LF_XSFP_ABSENT,
318318
};
319319

320+
#define HCLGE_LINK_STATUS_DOWN 0
321+
#define HCLGE_LINK_STATUS_UP 1
322+
320323
#define HCLGE_PG_NUM 4
321324
#define HCLGE_SCH_MODE_SP 0
322325
#define HCLGE_SCH_MODE_DWRR 1

0 commit comments

Comments
 (0)