Commit 9e60d24d authored by David S. Miller's avatar David S. Miller

Merge branch 'hns3-pm_ops'

Huazhong Tan says:

====================
net: hns3: add support for pm_ops

This series adds support for pm_ops in the HNS3 ethernet driver.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c69b6718 715c58e9
...@@ -474,8 +474,9 @@ struct hnae3_ae_dev { ...@@ -474,8 +474,9 @@ struct hnae3_ae_dev {
struct hnae3_ae_ops { struct hnae3_ae_ops {
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev); int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
void (*uninit_ae_dev)(struct hnae3_ae_dev *ae_dev); void (*uninit_ae_dev)(struct hnae3_ae_dev *ae_dev);
void (*flr_prepare)(struct hnae3_ae_dev *ae_dev); void (*reset_prepare)(struct hnae3_ae_dev *ae_dev,
void (*flr_done)(struct hnae3_ae_dev *ae_dev); enum hnae3_reset_type rst_type);
void (*reset_done)(struct hnae3_ae_dev *ae_dev);
int (*init_client_instance)(struct hnae3_client *client, int (*init_client_instance)(struct hnae3_client *client,
struct hnae3_ae_dev *ae_dev); struct hnae3_ae_dev *ae_dev);
void (*uninit_client_instance)(struct hnae3_client *client, void (*uninit_client_instance)(struct hnae3_client *client,
......
...@@ -2365,6 +2365,32 @@ static void hns3_shutdown(struct pci_dev *pdev) ...@@ -2365,6 +2365,32 @@ static void hns3_shutdown(struct pci_dev *pdev)
pci_set_power_state(pdev, PCI_D3hot); pci_set_power_state(pdev, PCI_D3hot);
} }
static int __maybe_unused hns3_suspend(struct device *dev)
{
struct hnae3_ae_dev *ae_dev = dev_get_drvdata(dev);
if (hns3_is_phys_func(ae_dev->pdev)) {
dev_info(dev, "Begin to suspend.\n");
if (ae_dev && ae_dev->ops && ae_dev->ops->reset_prepare)
ae_dev->ops->reset_prepare(ae_dev, HNAE3_FUNC_RESET);
}
return 0;
}
static int __maybe_unused hns3_resume(struct device *dev)
{
struct hnae3_ae_dev *ae_dev = dev_get_drvdata(dev);
if (hns3_is_phys_func(ae_dev->pdev)) {
dev_info(dev, "Begin to resume.\n");
if (ae_dev && ae_dev->ops && ae_dev->ops->reset_done)
ae_dev->ops->reset_done(ae_dev);
}
return 0;
}
static pci_ers_result_t hns3_error_detected(struct pci_dev *pdev, static pci_ers_result_t hns3_error_detected(struct pci_dev *pdev,
pci_channel_state_t state) pci_channel_state_t state)
{ {
...@@ -2423,8 +2449,8 @@ static void hns3_reset_prepare(struct pci_dev *pdev) ...@@ -2423,8 +2449,8 @@ static void hns3_reset_prepare(struct pci_dev *pdev)
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev); struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
dev_info(&pdev->dev, "FLR prepare\n"); dev_info(&pdev->dev, "FLR prepare\n");
if (ae_dev && ae_dev->ops && ae_dev->ops->flr_prepare) if (ae_dev && ae_dev->ops && ae_dev->ops->reset_prepare)
ae_dev->ops->flr_prepare(ae_dev); ae_dev->ops->reset_prepare(ae_dev, HNAE3_FLR_RESET);
} }
static void hns3_reset_done(struct pci_dev *pdev) static void hns3_reset_done(struct pci_dev *pdev)
...@@ -2432,8 +2458,8 @@ static void hns3_reset_done(struct pci_dev *pdev) ...@@ -2432,8 +2458,8 @@ static void hns3_reset_done(struct pci_dev *pdev)
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev); struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
dev_info(&pdev->dev, "FLR done\n"); dev_info(&pdev->dev, "FLR done\n");
if (ae_dev && ae_dev->ops && ae_dev->ops->flr_done) if (ae_dev && ae_dev->ops && ae_dev->ops->reset_done)
ae_dev->ops->flr_done(ae_dev); ae_dev->ops->reset_done(ae_dev);
} }
static const struct pci_error_handlers hns3_err_handler = { static const struct pci_error_handlers hns3_err_handler = {
...@@ -2443,12 +2469,15 @@ static const struct pci_error_handlers hns3_err_handler = { ...@@ -2443,12 +2469,15 @@ static const struct pci_error_handlers hns3_err_handler = {
.reset_done = hns3_reset_done, .reset_done = hns3_reset_done,
}; };
static SIMPLE_DEV_PM_OPS(hns3_pm_ops, hns3_suspend, hns3_resume);
static struct pci_driver hns3_driver = { static struct pci_driver hns3_driver = {
.name = hns3_driver_name, .name = hns3_driver_name,
.id_table = hns3_pci_tbl, .id_table = hns3_pci_tbl,
.probe = hns3_probe, .probe = hns3_probe,
.remove = hns3_remove, .remove = hns3_remove,
.shutdown = hns3_shutdown, .shutdown = hns3_shutdown,
.driver.pm = &hns3_pm_ops,
.sriov_configure = hns3_pci_sriov_configure, .sriov_configure = hns3_pci_sriov_configure,
.err_handler = &hns3_err_handler, .err_handler = &hns3_err_handler,
}; };
......
...@@ -11058,10 +11058,11 @@ static void hclge_state_uninit(struct hclge_dev *hdev) ...@@ -11058,10 +11058,11 @@ static void hclge_state_uninit(struct hclge_dev *hdev)
cancel_delayed_work_sync(&hdev->service_task); cancel_delayed_work_sync(&hdev->service_task);
} }
static void hclge_flr_prepare(struct hnae3_ae_dev *ae_dev) static void hclge_reset_prepare_general(struct hnae3_ae_dev *ae_dev,
enum hnae3_reset_type rst_type)
{ {
#define HCLGE_FLR_RETRY_WAIT_MS 500 #define HCLGE_RESET_RETRY_WAIT_MS 500
#define HCLGE_FLR_RETRY_CNT 5 #define HCLGE_RESET_RETRY_CNT 5
struct hclge_dev *hdev = ae_dev->priv; struct hclge_dev *hdev = ae_dev->priv;
int retry_cnt = 0; int retry_cnt = 0;
...@@ -11070,30 +11071,34 @@ static void hclge_flr_prepare(struct hnae3_ae_dev *ae_dev) ...@@ -11070,30 +11071,34 @@ static void hclge_flr_prepare(struct hnae3_ae_dev *ae_dev)
retry: retry:
down(&hdev->reset_sem); down(&hdev->reset_sem);
set_bit(HCLGE_STATE_RST_HANDLING, &hdev->state); set_bit(HCLGE_STATE_RST_HANDLING, &hdev->state);
hdev->reset_type = HNAE3_FLR_RESET; hdev->reset_type = rst_type;
ret = hclge_reset_prepare(hdev); ret = hclge_reset_prepare(hdev);
if (ret || hdev->reset_pending) { if (ret || hdev->reset_pending) {
dev_err(&hdev->pdev->dev, "fail to prepare FLR, ret=%d\n", dev_err(&hdev->pdev->dev, "fail to prepare to reset, ret=%d\n",
ret); ret);
if (hdev->reset_pending || if (hdev->reset_pending ||
retry_cnt++ < HCLGE_FLR_RETRY_CNT) { retry_cnt++ < HCLGE_RESET_RETRY_CNT) {
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"reset_pending:0x%lx, retry_cnt:%d\n", "reset_pending:0x%lx, retry_cnt:%d\n",
hdev->reset_pending, retry_cnt); hdev->reset_pending, retry_cnt);
clear_bit(HCLGE_STATE_RST_HANDLING, &hdev->state); clear_bit(HCLGE_STATE_RST_HANDLING, &hdev->state);
up(&hdev->reset_sem); up(&hdev->reset_sem);
msleep(HCLGE_FLR_RETRY_WAIT_MS); msleep(HCLGE_RESET_RETRY_WAIT_MS);
goto retry; goto retry;
} }
} }
/* disable misc vector before FLR done */ /* disable misc vector before reset done */
hclge_enable_vector(&hdev->misc_vector, false); hclge_enable_vector(&hdev->misc_vector, false);
set_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state); set_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state);
if (hdev->reset_type == HNAE3_FLR_RESET)
hdev->rst_stats.flr_rst_cnt++; hdev->rst_stats.flr_rst_cnt++;
else if (hdev->reset_type == HNAE3_FUNC_RESET)
hdev->rst_stats.pf_rst_cnt++;
} }
static void hclge_flr_done(struct hnae3_ae_dev *ae_dev) static void hclge_reset_done(struct hnae3_ae_dev *ae_dev)
{ {
struct hclge_dev *hdev = ae_dev->priv; struct hclge_dev *hdev = ae_dev->priv;
int ret; int ret;
...@@ -12466,8 +12471,8 @@ static int hclge_get_module_eeprom(struct hnae3_handle *handle, u32 offset, ...@@ -12466,8 +12471,8 @@ static int hclge_get_module_eeprom(struct hnae3_handle *handle, u32 offset,
static const struct hnae3_ae_ops hclge_ops = { static const struct hnae3_ae_ops hclge_ops = {
.init_ae_dev = hclge_init_ae_dev, .init_ae_dev = hclge_init_ae_dev,
.uninit_ae_dev = hclge_uninit_ae_dev, .uninit_ae_dev = hclge_uninit_ae_dev,
.flr_prepare = hclge_flr_prepare, .reset_prepare = hclge_reset_prepare_general,
.flr_done = hclge_flr_done, .reset_done = hclge_reset_done,
.init_client_instance = hclge_init_client_instance, .init_client_instance = hclge_init_client_instance,
.uninit_client_instance = hclge_uninit_client_instance, .uninit_client_instance = hclge_uninit_client_instance,
.map_ring_to_vector = hclge_map_ring_to_vector, .map_ring_to_vector = hclge_map_ring_to_vector,
......
...@@ -2114,10 +2114,11 @@ static void hclgevf_enable_vector(struct hclgevf_misc_vector *vector, bool en) ...@@ -2114,10 +2114,11 @@ static void hclgevf_enable_vector(struct hclgevf_misc_vector *vector, bool en)
writel(en ? 1 : 0, vector->addr); writel(en ? 1 : 0, vector->addr);
} }
static void hclgevf_flr_prepare(struct hnae3_ae_dev *ae_dev) static void hclgevf_reset_prepare_general(struct hnae3_ae_dev *ae_dev,
enum hnae3_reset_type rst_type)
{ {
#define HCLGEVF_FLR_RETRY_WAIT_MS 500 #define HCLGEVF_RESET_RETRY_WAIT_MS 500
#define HCLGEVF_FLR_RETRY_CNT 5 #define HCLGEVF_RESET_RETRY_CNT 5
struct hclgevf_dev *hdev = ae_dev->priv; struct hclgevf_dev *hdev = ae_dev->priv;
int retry_cnt = 0; int retry_cnt = 0;
...@@ -2126,29 +2127,31 @@ static void hclgevf_flr_prepare(struct hnae3_ae_dev *ae_dev) ...@@ -2126,29 +2127,31 @@ static void hclgevf_flr_prepare(struct hnae3_ae_dev *ae_dev)
retry: retry:
down(&hdev->reset_sem); down(&hdev->reset_sem);
set_bit(HCLGEVF_STATE_RST_HANDLING, &hdev->state); set_bit(HCLGEVF_STATE_RST_HANDLING, &hdev->state);
hdev->reset_type = HNAE3_FLR_RESET; hdev->reset_type = rst_type;
ret = hclgevf_reset_prepare(hdev); ret = hclgevf_reset_prepare(hdev);
if (ret) { if (ret) {
dev_err(&hdev->pdev->dev, "fail to prepare FLR, ret=%d\n", dev_err(&hdev->pdev->dev, "fail to prepare to reset, ret=%d\n",
ret); ret);
if (hdev->reset_pending || if (hdev->reset_pending ||
retry_cnt++ < HCLGEVF_FLR_RETRY_CNT) { retry_cnt++ < HCLGEVF_RESET_RETRY_CNT) {
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"reset_pending:0x%lx, retry_cnt:%d\n", "reset_pending:0x%lx, retry_cnt:%d\n",
hdev->reset_pending, retry_cnt); hdev->reset_pending, retry_cnt);
clear_bit(HCLGEVF_STATE_RST_HANDLING, &hdev->state); clear_bit(HCLGEVF_STATE_RST_HANDLING, &hdev->state);
up(&hdev->reset_sem); up(&hdev->reset_sem);
msleep(HCLGEVF_FLR_RETRY_WAIT_MS); msleep(HCLGEVF_RESET_RETRY_WAIT_MS);
goto retry; goto retry;
} }
} }
/* disable misc vector before FLR done */ /* disable misc vector before reset done */
hclgevf_enable_vector(&hdev->misc_vector, false); hclgevf_enable_vector(&hdev->misc_vector, false);
if (hdev->reset_type == HNAE3_FLR_RESET)
hdev->rst_stats.flr_rst_cnt++; hdev->rst_stats.flr_rst_cnt++;
} }
static void hclgevf_flr_done(struct hnae3_ae_dev *ae_dev) static void hclgevf_reset_done(struct hnae3_ae_dev *ae_dev)
{ {
struct hclgevf_dev *hdev = ae_dev->priv; struct hclgevf_dev *hdev = ae_dev->priv;
int ret; int ret;
...@@ -3748,8 +3751,8 @@ void hclgevf_update_port_base_vlan_info(struct hclgevf_dev *hdev, u16 state, ...@@ -3748,8 +3751,8 @@ void hclgevf_update_port_base_vlan_info(struct hclgevf_dev *hdev, u16 state,
static const struct hnae3_ae_ops hclgevf_ops = { static const struct hnae3_ae_ops hclgevf_ops = {
.init_ae_dev = hclgevf_init_ae_dev, .init_ae_dev = hclgevf_init_ae_dev,
.uninit_ae_dev = hclgevf_uninit_ae_dev, .uninit_ae_dev = hclgevf_uninit_ae_dev,
.flr_prepare = hclgevf_flr_prepare, .reset_prepare = hclgevf_reset_prepare_general,
.flr_done = hclgevf_flr_done, .reset_done = hclgevf_reset_done,
.init_client_instance = hclgevf_init_client_instance, .init_client_instance = hclgevf_init_client_instance,
.uninit_client_instance = hclgevf_uninit_client_instance, .uninit_client_instance = hclgevf_uninit_client_instance,
.start = hclgevf_ae_start, .start = hclgevf_ae_start,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment