Skip to content

Commit 25b450c

Browse files
emuslndavem330
authored andcommitted
pds_core: add devlink health facilities
Add devlink health reporting on top of our fw watchdog. Example: # devlink health show pci/0000:2b:00.0 reporter fw pci/0000:2b:00.0: reporter fw state healthy error 0 recover 0 # devlink health diagnose pci/0000:2b:00.0 reporter fw Status: healthy State: 1 Generation: 0 Recoveries: 0 Signed-off-by: Shannon Nelson <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c2dbb09 commit 25b450c

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

Documentation/networking/device_drivers/ethernet/amd/pds_core.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ messages such as these::
2626
pds_core 0000:b6:00.0: 252.048 Gb/s available PCIe bandwidth (16.0 GT/s PCIe x16 link)
2727
pds_core 0000:b6:00.0: FW: 1.60.0-73
2828

29+
Health Reporters
30+
================
31+
32+
The driver supports a devlink health reporter for FW status::
33+
34+
# devlink health show pci/0000:2b:00.0 reporter fw
35+
pci/0000:2b:00.0:
36+
reporter fw
37+
state healthy error 0 recover 0
38+
# devlink health diagnose pci/0000:2b:00.0 reporter fw
39+
Status: healthy State: 1 Generation: 0 Recoveries: 0
40+
2941
Support
3042
=======
3143

drivers/net/ethernet/amd/pds_core/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
obj-$(CONFIG_PDS_CORE) := pds_core.o
55

66
pds_core-y := main.o \
7+
devlink.o \
78
dev.o \
89
core.o
910

drivers/net/ethernet/amd/pds_core/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
int pdsc_setup(struct pdsc *pdsc, bool init)
77
{
8-
int err = 0;
8+
int err;
99

1010
if (init)
1111
err = pdsc_dev_init(pdsc);
@@ -42,6 +42,8 @@ static void pdsc_fw_down(struct pdsc *pdsc)
4242
return;
4343
}
4444

45+
devlink_health_report(pdsc->fw_reporter, "FW down reported", pdsc);
46+
4547
pdsc_teardown(pdsc, PDSC_TEARDOWN_RECOVERY);
4648
}
4749

@@ -58,6 +60,10 @@ static void pdsc_fw_up(struct pdsc *pdsc)
5860
if (err)
5961
goto err_out;
6062

63+
pdsc->fw_recoveries++;
64+
devlink_health_reporter_state_update(pdsc->fw_reporter,
65+
DEVLINK_HEALTH_REPORTER_STATE_HEALTHY);
66+
6167
return;
6268

6369
err_out:

drivers/net/ethernet/amd/pds_core/core.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ struct pdsc {
6868
struct timer_list wdtimer;
6969
unsigned int wdtimer_period;
7070
struct work_struct health_work;
71+
struct devlink_health_reporter *fw_reporter;
72+
u32 fw_recoveries;
7173

7274
struct pdsc_devinfo dev_info;
7375
struct pds_core_dev_identity dev_ident;
@@ -88,6 +90,10 @@ struct pdsc {
8890
u64 __iomem *kern_dbpage;
8991
};
9092

93+
int pdsc_fw_reporter_diagnose(struct devlink_health_reporter *reporter,
94+
struct devlink_fmsg *fmsg,
95+
struct netlink_ext_ack *extack);
96+
9197
void pdsc_debugfs_create(void);
9298
void pdsc_debugfs_destroy(void);
9399
void pdsc_debugfs_add_dev(struct pdsc *pdsc);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright(c) 2023 Advanced Micro Devices, Inc */
3+
4+
#include "core.h"
5+
6+
int pdsc_fw_reporter_diagnose(struct devlink_health_reporter *reporter,
7+
struct devlink_fmsg *fmsg,
8+
struct netlink_ext_ack *extack)
9+
{
10+
struct pdsc *pdsc = devlink_health_reporter_priv(reporter);
11+
int err;
12+
13+
mutex_lock(&pdsc->config_lock);
14+
15+
if (test_bit(PDSC_S_FW_DEAD, &pdsc->state))
16+
err = devlink_fmsg_string_pair_put(fmsg, "Status", "dead");
17+
else if (!pdsc_is_fw_good(pdsc))
18+
err = devlink_fmsg_string_pair_put(fmsg, "Status", "unhealthy");
19+
else
20+
err = devlink_fmsg_string_pair_put(fmsg, "Status", "healthy");
21+
22+
mutex_unlock(&pdsc->config_lock);
23+
24+
if (err)
25+
return err;
26+
27+
err = devlink_fmsg_u32_pair_put(fmsg, "State",
28+
pdsc->fw_status &
29+
~PDS_CORE_FW_STS_F_GENERATION);
30+
if (err)
31+
return err;
32+
33+
err = devlink_fmsg_u32_pair_put(fmsg, "Generation",
34+
pdsc->fw_generation >> 4);
35+
if (err)
36+
return err;
37+
38+
return devlink_fmsg_u32_pair_put(fmsg, "Recoveries",
39+
pdsc->fw_recoveries);
40+
}

drivers/net/ethernet/amd/pds_core/main.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,16 @@ static int pdsc_init_vf(struct pdsc *vf)
130130
return -1;
131131
}
132132

133+
static const struct devlink_health_reporter_ops pdsc_fw_reporter_ops = {
134+
.name = "fw",
135+
.diagnose = pdsc_fw_reporter_diagnose,
136+
};
137+
133138
#define PDSC_WQ_NAME_LEN 24
134139

135140
static int pdsc_init_pf(struct pdsc *pdsc)
136141
{
142+
struct devlink_health_reporter *hr;
137143
char wq_name[PDSC_WQ_NAME_LEN];
138144
struct devlink *dl;
139145
int err;
@@ -172,6 +178,16 @@ static int pdsc_init_pf(struct pdsc *pdsc)
172178

173179
dl = priv_to_devlink(pdsc);
174180
devl_lock(dl);
181+
182+
hr = devl_health_reporter_create(dl, &pdsc_fw_reporter_ops, 0, pdsc);
183+
if (IS_ERR(hr)) {
184+
dev_warn(pdsc->dev, "Failed to create fw reporter: %pe\n", hr);
185+
err = PTR_ERR(hr);
186+
devl_unlock(dl);
187+
goto err_out_teardown;
188+
}
189+
pdsc->fw_reporter = hr;
190+
175191
devl_register(dl);
176192
devl_unlock(dl);
177193

@@ -180,6 +196,8 @@ static int pdsc_init_pf(struct pdsc *pdsc)
180196

181197
return 0;
182198

199+
err_out_teardown:
200+
pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING);
183201
err_out_unmap_bars:
184202
mutex_unlock(&pdsc->config_lock);
185203
del_timer_sync(&pdsc->wdtimer);
@@ -283,6 +301,10 @@ static void pdsc_remove(struct pci_dev *pdev)
283301
dl = priv_to_devlink(pdsc);
284302
devl_lock(dl);
285303
devl_unregister(dl);
304+
if (pdsc->fw_reporter) {
305+
devl_health_reporter_destroy(pdsc->fw_reporter);
306+
pdsc->fw_reporter = NULL;
307+
}
286308
devl_unlock(dl);
287309

288310
if (!pdev->is_virtfn) {

0 commit comments

Comments
 (0)