Blame SOURCES/0071-netdrv-bnxt_en-Add-new-FW-devlink_health_reporter.patch

f95c89
From a5722300aaf495489ab5ce115f8955915a4dcb70 Mon Sep 17 00:00:00 2001
f95c89
From: Jonathan Toppins <jtoppins@redhat.com>
f95c89
Date: Wed, 2 Oct 2019 18:23:26 -0400
f95c89
Subject: [PATCH 71/96] [netdrv] bnxt_en: Add new FW devlink_health_reporter
f95c89
f95c89
Message-id: <54406dbbfa698feebe5b59a0c650fe80f3bd751c.1570027456.git.jtoppins@redhat.com>
f95c89
Patchwork-id: 276493
f95c89
O-Subject: [RHEL-8.2 PATCH 64/78] bnxt_en: Add new FW devlink_health_reporter
f95c89
Bugzilla: 1724766
f95c89
RH-Acked-by: John Linville <linville@redhat.com>
f95c89
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
f95c89
f95c89
Create new FW devlink_health_reporter, to know the current health
f95c89
status of FW.
f95c89
f95c89
Command example and output:
f95c89
$ devlink health show pci/0000:af:00.0 reporter fw
f95c89
f95c89
pci/0000:af:00.0:
f95c89
  name fw
f95c89
    state healthy error 0 recover 0
f95c89
f95c89
 FW status: Healthy; Reset count: 1
f95c89
f95c89
Cc: Jiri Pirko <jiri@mellanox.com>
f95c89
Signed-off-by: Vasundhara Volam <vasundhara-v.volam@broadcom.com>
f95c89
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
f95c89
Signed-off-by: David S. Miller <davem@davemloft.net>
f95c89
(cherry picked from commit 6763c779c2d8b568b2e174f3eeeaf644fa38b34d)
f95c89
Bugzilla: 1724766
f95c89
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=23809532
f95c89
Tested: build, boot, basic ping
f95c89
Signed-off-by: Jonathan Toppins <jtoppins@redhat.com>
f95c89
Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
f95c89
---
f95c89
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  3 +
f95c89
 drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c | 81 +++++++++++++++++++++++
f95c89
 2 files changed, 84 insertions(+)
f95c89
f95c89
Index: src/drivers/net/ethernet/broadcom/bnxt/bnxt.h
f95c89
===================================================================
f95c89
--- src.orig/drivers/net/ethernet/broadcom/bnxt/bnxt.h	2020-02-06 16:23:19.750476068 +0100
f95c89
+++ src/drivers/net/ethernet/broadcom/bnxt/bnxt.h	2020-02-06 16:23:19.896474728 +0100
f95c89
@@ -1368,6 +1368,7 @@
f95c89
 	u32 fw_reset_seq_regs[16];
f95c89
 	u32 fw_reset_seq_vals[16];
f95c89
 	u32 fw_reset_seq_delay_msec[16];
f95c89
+	struct devlink_health_reporter	*fw_reporter;
f95c89
 };
f95c89
 
f95c89
 #define BNXT_FW_HEALTH_REG_TYPE_MASK	3
f95c89
@@ -1382,6 +1383,8 @@
f95c89
 #define BNXT_FW_HEALTH_WIN_BASE		0x3000
f95c89
 #define BNXT_FW_HEALTH_WIN_MAP_OFF	8
f95c89
 
f95c89
+#define BNXT_FW_STATUS_HEALTHY		0x8000
f95c89
+
f95c89
 struct bnxt {
f95c89
 	void __iomem		*bar0;
f95c89
 	void __iomem		*bar1;
f95c89
Index: src/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
f95c89
===================================================================
f95c89
--- src.orig/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c	2020-02-06 16:23:18.306489323 +0100
f95c89
+++ src/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c	2020-02-06 16:23:19.896474728 +0100
f95c89
@@ -15,6 +15,84 @@
f95c89
 #include "bnxt_vfr.h"
f95c89
 #include "bnxt_devlink.h"
f95c89
 
f95c89
+static int bnxt_fw_reporter_diagnose(struct devlink_health_reporter *reporter,
f95c89
+				     struct devlink_fmsg *fmsg)
f95c89
+{
f95c89
+	struct bnxt *bp = devlink_health_reporter_priv(reporter);
f95c89
+	struct bnxt_fw_health *health = bp->fw_health;
f95c89
+	u32 val, health_status;
f95c89
+	int rc;
f95c89
+
f95c89
+	if (!health || test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
f95c89
+		return 0;
f95c89
+
f95c89
+	val = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
f95c89
+	health_status = val & 0xffff;
f95c89
+
f95c89
+	if (health_status == BNXT_FW_STATUS_HEALTHY) {
f95c89
+		rc = devlink_fmsg_string_pair_put(fmsg, "FW status",
f95c89
+						  "Healthy;");
f95c89
+		if (rc)
f95c89
+			return rc;
f95c89
+	} else if (health_status < BNXT_FW_STATUS_HEALTHY) {
f95c89
+		rc = devlink_fmsg_string_pair_put(fmsg, "FW status",
f95c89
+						  "Not yet completed initialization;");
f95c89
+		if (rc)
f95c89
+			return rc;
f95c89
+	} else if (health_status > BNXT_FW_STATUS_HEALTHY) {
f95c89
+		rc = devlink_fmsg_string_pair_put(fmsg, "FW status",
f95c89
+						  "Encountered fatal error and cannot recover;");
f95c89
+		if (rc)
f95c89
+			return rc;
f95c89
+	}
f95c89
+
f95c89
+	if (val >> 16) {
f95c89
+		rc = devlink_fmsg_u32_pair_put(fmsg, "Error", val >> 16);
f95c89
+		if (rc)
f95c89
+			return rc;
f95c89
+	}
f95c89
+
f95c89
+	val = bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
f95c89
+	rc = devlink_fmsg_u32_pair_put(fmsg, "Reset count", val);
f95c89
+	if (rc)
f95c89
+		return rc;
f95c89
+
f95c89
+	return 0;
f95c89
+}
f95c89
+
f95c89
+static const struct devlink_health_reporter_ops bnxt_dl_fw_reporter_ops = {
f95c89
+	.name = "fw",
f95c89
+	.diagnose = bnxt_fw_reporter_diagnose,
f95c89
+};
f95c89
+
f95c89
+static void bnxt_dl_fw_reporters_create(struct bnxt *bp)
f95c89
+{
f95c89
+	struct bnxt_fw_health *health = bp->fw_health;
f95c89
+
f95c89
+	if (!health)
f95c89
+		return;
f95c89
+
f95c89
+	health->fw_reporter =
f95c89
+		devlink_health_reporter_create(bp->dl, &bnxt_dl_fw_reporter_ops,
f95c89
+					       0, false, bp);
f95c89
+	if (IS_ERR(health->fw_reporter)) {
f95c89
+		netdev_warn(bp->dev, "Failed to create FW health reporter, rc = %ld\n",
f95c89
+			    PTR_ERR(health->fw_reporter));
f95c89
+		health->fw_reporter = NULL;
f95c89
+	}
f95c89
+}
f95c89
+
f95c89
+static void bnxt_dl_fw_reporters_destroy(struct bnxt *bp)
f95c89
+{
f95c89
+	struct bnxt_fw_health *health = bp->fw_health;
f95c89
+
f95c89
+	if (!health)
f95c89
+		return;
f95c89
+
f95c89
+	if (health->fw_reporter)
f95c89
+		devlink_health_reporter_destroy(health->fw_reporter);
f95c89
+}
f95c89
+
f95c89
 static const struct devlink_ops bnxt_dl_ops = {
f95c89
 #ifdef CONFIG_BNXT_SRIOV
f95c89
 	.eswitch_mode_set = bnxt_dl_eswitch_mode_set,
f95c89
@@ -246,6 +324,8 @@
f95c89
 
f95c89
 	devlink_params_publish(dl);
f95c89
 
f95c89
+	bnxt_dl_fw_reporters_create(bp);
f95c89
+
f95c89
 	return 0;
f95c89
 
f95c89
 err_dl_port_unreg:
f95c89
@@ -268,6 +348,7 @@
f95c89
 	if (!dl)
f95c89
 		return;
f95c89
 
f95c89
+	bnxt_dl_fw_reporters_destroy(bp);
f95c89
 	devlink_port_params_unregister(&bp->dl_port, bnxt_dl_port_params,
f95c89
 				       ARRAY_SIZE(bnxt_dl_port_params));
f95c89
 	devlink_port_unregister(&bp->dl_port);