Skip to content

Commit f2f432f

Browse files
Salil Mehtadavem330
authored andcommitted
net: hns3: Refactors the requested reset & pending reset handling code
In exisiting code, the way to detect if driver/client reset should be executed or if hardware should be be soft resetted was overly complex. Existing code use to read the interrupt status register from task context to figure out if the interrupt source event was reset and then use clear the interrupt source for reset while waiting for the hardware to finish the reset. This behaviour again was confusing and overly complex in terms of the flow. This patch simplifies the handling of the requested reset and the pending reset(i.e. reset which have already been asserted by the software and hardware has acknowledged back to driver that it is processing the hardware reset through interrupt) Signed-off-by: Salil Mehta <salil.mehta@huawei.com> Signed-off-by: lipeng <lipeng321@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cb1b9f7 commit f2f432f

File tree

2 files changed

+65
-36
lines changed

2 files changed

+65
-36
lines changed

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

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <linux/netdevice.h>
1818
#include <linux/pci.h>
1919
#include <linux/platform_device.h>
20-
20+
#include <net/rtnetlink.h>
2121
#include "hclge_cmd.h"
2222
#include "hclge_dcb.h"
2323
#include "hclge_main.h"
@@ -2569,12 +2569,12 @@ static int hclge_func_reset_cmd(struct hclge_dev *hdev, int func_id)
25692569
return ret;
25702570
}
25712571

2572-
static void hclge_do_reset(struct hclge_dev *hdev, enum hnae3_reset_type type)
2572+
static void hclge_do_reset(struct hclge_dev *hdev)
25732573
{
25742574
struct pci_dev *pdev = hdev->pdev;
25752575
u32 val;
25762576

2577-
switch (type) {
2577+
switch (hdev->reset_type) {
25782578
case HNAE3_GLOBAL_RESET:
25792579
val = hclge_read_dev(&hdev->hw, HCLGE_GLOBAL_RESET_REG);
25802580
hnae_set_bit(val, HCLGE_GLOBAL_RESET_BIT, 1);
@@ -2596,11 +2596,56 @@ static void hclge_do_reset(struct hclge_dev *hdev, enum hnae3_reset_type type)
25962596
break;
25972597
default:
25982598
dev_warn(&pdev->dev,
2599-
"Unsupported reset type: %d\n", type);
2599+
"Unsupported reset type: %d\n", hdev->reset_type);
26002600
break;
26012601
}
26022602
}
26032603

2604+
static enum hnae3_reset_type hclge_get_reset_level(struct hclge_dev *hdev,
2605+
unsigned long *addr)
2606+
{
2607+
enum hnae3_reset_type rst_level = HNAE3_NONE_RESET;
2608+
2609+
/* return the highest priority reset level amongst all */
2610+
if (test_bit(HNAE3_GLOBAL_RESET, addr))
2611+
rst_level = HNAE3_GLOBAL_RESET;
2612+
else if (test_bit(HNAE3_CORE_RESET, addr))
2613+
rst_level = HNAE3_CORE_RESET;
2614+
else if (test_bit(HNAE3_IMP_RESET, addr))
2615+
rst_level = HNAE3_IMP_RESET;
2616+
else if (test_bit(HNAE3_FUNC_RESET, addr))
2617+
rst_level = HNAE3_FUNC_RESET;
2618+
2619+
/* now, clear all other resets */
2620+
clear_bit(HNAE3_GLOBAL_RESET, addr);
2621+
clear_bit(HNAE3_CORE_RESET, addr);
2622+
clear_bit(HNAE3_IMP_RESET, addr);
2623+
clear_bit(HNAE3_FUNC_RESET, addr);
2624+
2625+
return rst_level;
2626+
}
2627+
2628+
static void hclge_reset(struct hclge_dev *hdev)
2629+
{
2630+
/* perform reset of the stack & ae device for a client */
2631+
2632+
hclge_notify_client(hdev, HNAE3_DOWN_CLIENT);
2633+
2634+
if (!hclge_reset_wait(hdev)) {
2635+
rtnl_lock();
2636+
hclge_notify_client(hdev, HNAE3_UNINIT_CLIENT);
2637+
hclge_reset_ae_dev(hdev->ae_dev);
2638+
hclge_notify_client(hdev, HNAE3_INIT_CLIENT);
2639+
rtnl_unlock();
2640+
} else {
2641+
/* schedule again to check pending resets later */
2642+
set_bit(hdev->reset_type, &hdev->reset_pending);
2643+
hclge_reset_task_schedule(hdev);
2644+
}
2645+
2646+
hclge_notify_client(hdev, HNAE3_UP_CLIENT);
2647+
}
2648+
26042649
static void hclge_reset_event(struct hnae3_handle *handle,
26052650
enum hnae3_reset_type reset)
26062651
{
@@ -2626,39 +2671,24 @@ static void hclge_reset_event(struct hnae3_handle *handle,
26262671

26272672
static void hclge_reset_subtask(struct hclge_dev *hdev)
26282673
{
2629-
bool do_reset;
2630-
2631-
do_reset = hdev->reset_type != HNAE3_NONE_RESET;
2632-
2633-
2634-
if (hdev->reset_type == HNAE3_NONE_RESET)
2635-
return;
2636-
2637-
switch (hdev->reset_type) {
2638-
case HNAE3_FUNC_RESET:
2639-
case HNAE3_CORE_RESET:
2640-
case HNAE3_GLOBAL_RESET:
2641-
case HNAE3_IMP_RESET:
2642-
hclge_notify_client(hdev, HNAE3_DOWN_CLIENT);
2674+
/* check if there is any ongoing reset in the hardware. This status can
2675+
* be checked from reset_pending. If there is then, we need to wait for
2676+
* hardware to complete reset.
2677+
* a. If we are able to figure out in reasonable time that hardware
2678+
* has fully resetted then, we can proceed with driver, client
2679+
* reset.
2680+
* b. else, we can come back later to check this status so re-sched
2681+
* now.
2682+
*/
2683+
hdev->reset_type = hclge_get_reset_level(hdev, &hdev->reset_pending);
2684+
if (hdev->reset_type != HNAE3_NONE_RESET)
2685+
hclge_reset(hdev);
26432686

2644-
if (do_reset)
2645-
hclge_do_reset(hdev, hdev->reset_type);
2646-
else
2647-
set_bit(HCLGE_STATE_RESET_INT, &hdev->state);
2687+
/* check if we got any *new* reset requests to be honored */
2688+
hdev->reset_type = hclge_get_reset_level(hdev, &hdev->reset_request);
2689+
if (hdev->reset_type != HNAE3_NONE_RESET)
2690+
hclge_do_reset(hdev);
26482691

2649-
if (!hclge_reset_wait(hdev)) {
2650-
hclge_notify_client(hdev, HNAE3_UNINIT_CLIENT);
2651-
hclge_reset_ae_dev(hdev->ae_dev);
2652-
hclge_notify_client(hdev, HNAE3_INIT_CLIENT);
2653-
clear_bit(HCLGE_STATE_RESET_INT, &hdev->state);
2654-
}
2655-
hclge_notify_client(hdev, HNAE3_UP_CLIENT);
2656-
break;
2657-
default:
2658-
dev_err(&hdev->pdev->dev, "Unsupported reset type:%d\n",
2659-
hdev->reset_type);
2660-
break;
2661-
}
26622692
hdev->reset_type = HNAE3_NONE_RESET;
26632693
}
26642694

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ enum HCLGE_DEV_STATE {
103103
HCLGE_STATE_RST_HANDLING,
104104
HCLGE_STATE_MBX_HANDLING,
105105
HCLGE_STATE_MBX_IRQ,
106-
HCLGE_STATE_RESET_INT,
107106
HCLGE_STATE_MAX
108107
};
109108

0 commit comments

Comments
 (0)