From: Michael Chan <michael.chan@broadcom•com>
To: davem@davemloft•net
Cc: netdev@vger•kernel.org, edumazet@google•com, kuba@kernel•org,
pabeni@redhat•com, gospo@broadcom•com,
Kalesh AP <kalesh-anakkur.purayil@broadcom•com>,
Andy Gospodarek <andrew.gospodarek@broadcom•com>,
Jean Delvare <jdelvare@suse•com>,
Guenter Roeck <linux@roeck-us•net>,
linux-hwmon@vger•kernel.org
Subject: [PATCH net-next v2 3/9] bnxt_en: Move hwmon functions into a dedicated file
Date: Tue, 26 Sep 2023 20:57:28 -0700 [thread overview]
Message-ID: <20230927035734.42816-4-michael.chan@broadcom.com> (raw)
In-Reply-To: <20230927035734.42816-1-michael.chan@broadcom.com>
[-- Attachment #1: Type: text/plain, Size: 7304 bytes --]
From: Kalesh AP <kalesh-anakkur.purayil@broadcom•com>
This is in preparation for upcoming patches in the series.
Driver has to expose more threshold temperatures through the
hwmon sysfs interface. More code will be added and do not
want to overload bnxt.c.
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom•com>
Cc: Jean Delvare <jdelvare@suse•com>
Cc: Guenter Roeck <linux@roeck-us•net>
Cc: linux-hwmon@vger•kernel.org
Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom•com>
Signed-off-by: Michael Chan <michael.chan@broadcom•com>
---
drivers/net/ethernet/broadcom/bnxt/Makefile | 1 +
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 76 +----------------
.../net/ethernet/broadcom/bnxt/bnxt_hwmon.c | 82 +++++++++++++++++++
.../net/ethernet/broadcom/bnxt/bnxt_hwmon.h | 25 ++++++
4 files changed, 109 insertions(+), 75 deletions(-)
create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c
create mode 100644 drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h
diff --git a/drivers/net/ethernet/broadcom/bnxt/Makefile b/drivers/net/ethernet/broadcom/bnxt/Makefile
index 2bc2b707d6ee..ba6c239d52fa 100644
--- a/drivers/net/ethernet/broadcom/bnxt/Makefile
+++ b/drivers/net/ethernet/broadcom/bnxt/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_BNXT) += bnxt_en.o
bnxt_en-y := bnxt.o bnxt_hwrm.o bnxt_sriov.o bnxt_ethtool.o bnxt_dcb.o bnxt_ulp.o bnxt_xdp.o bnxt_ptp.o bnxt_vfr.o bnxt_devlink.o bnxt_dim.o bnxt_coredump.o
bnxt_en-$(CONFIG_BNXT_FLOWER_OFFLOAD) += bnxt_tc.o
bnxt_en-$(CONFIG_DEBUG_FS) += bnxt_debugfs.o
+bnxt_en-$(CONFIG_BNXT_HWMON) += bnxt_hwmon.o
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 785084147994..b83f8de0a015 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -52,8 +52,6 @@
#include <linux/cpu_rmap.h>
#include <linux/cpumask.h>
#include <net/pkt_cls.h>
-#include <linux/hwmon.h>
-#include <linux/hwmon-sysfs.h>
#include <net/page_pool/helpers.h>
#include <linux/align.h>
#include <net/netdev_queues.h>
@@ -71,6 +69,7 @@
#include "bnxt_tc.h"
#include "bnxt_devlink.h"
#include "bnxt_debugfs.h"
+#include "bnxt_hwmon.h"
#define BNXT_TX_TIMEOUT (5 * HZ)
#define BNXT_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_HW | \
@@ -10250,79 +10249,6 @@ static void bnxt_get_wol_settings(struct bnxt *bp)
} while (handle && handle != 0xffff);
}
-#ifdef CONFIG_BNXT_HWMON
-static ssize_t bnxt_show_temp(struct device *dev,
- struct device_attribute *devattr, char *buf)
-{
- struct hwrm_temp_monitor_query_output *resp;
- struct hwrm_temp_monitor_query_input *req;
- struct bnxt *bp = dev_get_drvdata(dev);
- u32 len = 0;
- int rc;
-
- rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
- if (rc)
- return rc;
- resp = hwrm_req_hold(bp, req);
- rc = hwrm_req_send(bp, req);
- if (!rc)
- len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */
- hwrm_req_drop(bp, req);
- if (rc)
- return rc;
- return len;
-}
-static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0);
-
-static struct attribute *bnxt_attrs[] = {
- &sensor_dev_attr_temp1_input.dev_attr.attr,
- NULL
-};
-ATTRIBUTE_GROUPS(bnxt);
-
-static void bnxt_hwmon_uninit(struct bnxt *bp)
-{
- if (bp->hwmon_dev) {
- hwmon_device_unregister(bp->hwmon_dev);
- bp->hwmon_dev = NULL;
- }
-}
-
-static void bnxt_hwmon_init(struct bnxt *bp)
-{
- struct hwrm_temp_monitor_query_input *req;
- struct pci_dev *pdev = bp->pdev;
- int rc;
-
- rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
- if (!rc)
- rc = hwrm_req_send_silent(bp, req);
- if (rc == -EACCES || rc == -EOPNOTSUPP) {
- bnxt_hwmon_uninit(bp);
- return;
- }
-
- if (bp->hwmon_dev)
- return;
-
- bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev,
- DRV_MODULE_NAME, bp,
- bnxt_groups);
- if (IS_ERR(bp->hwmon_dev)) {
- bp->hwmon_dev = NULL;
- dev_warn(&pdev->dev, "Cannot register hwmon device\n");
- }
-}
-#else
-static void bnxt_hwmon_uninit(struct bnxt *bp)
-{
-}
-
-static void bnxt_hwmon_init(struct bnxt *bp)
-{
-}
-#endif
-
static bool bnxt_eee_config_ok(struct bnxt *bp)
{
struct ethtool_eee *eee = &bp->eee;
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c
new file mode 100644
index 000000000000..476616d97071
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.c
@@ -0,0 +1,82 @@
+/* Broadcom NetXtreme-C/E network driver.
+ *
+ * Copyright (c) 2023 Broadcom Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/dev_printk.h>
+#include <linux/errno.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/pci.h>
+
+#include "bnxt_hsi.h"
+#include "bnxt.h"
+#include "bnxt_hwrm.h"
+#include "bnxt_hwmon.h"
+
+static ssize_t bnxt_show_temp(struct device *dev,
+ struct device_attribute *devattr, char *buf)
+{
+ struct hwrm_temp_monitor_query_output *resp;
+ struct hwrm_temp_monitor_query_input *req;
+ struct bnxt *bp = dev_get_drvdata(dev);
+ u32 len = 0;
+ int rc;
+
+ rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
+ if (rc)
+ return rc;
+ resp = hwrm_req_hold(bp, req);
+ rc = hwrm_req_send(bp, req);
+ if (!rc)
+ len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */
+ hwrm_req_drop(bp, req);
+ if (rc)
+ return rc;
+ return len;
+}
+static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0);
+
+static struct attribute *bnxt_attrs[] = {
+ &sensor_dev_attr_temp1_input.dev_attr.attr,
+ NULL
+};
+ATTRIBUTE_GROUPS(bnxt);
+
+void bnxt_hwmon_uninit(struct bnxt *bp)
+{
+ if (bp->hwmon_dev) {
+ hwmon_device_unregister(bp->hwmon_dev);
+ bp->hwmon_dev = NULL;
+ }
+}
+
+void bnxt_hwmon_init(struct bnxt *bp)
+{
+ struct hwrm_temp_monitor_query_input *req;
+ struct pci_dev *pdev = bp->pdev;
+ int rc;
+
+ rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
+ if (!rc)
+ rc = hwrm_req_send_silent(bp, req);
+ if (rc == -EACCES || rc == -EOPNOTSUPP) {
+ bnxt_hwmon_uninit(bp);
+ return;
+ }
+
+ if (bp->hwmon_dev)
+ return;
+
+ bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev,
+ DRV_MODULE_NAME, bp,
+ bnxt_groups);
+ if (IS_ERR(bp->hwmon_dev)) {
+ bp->hwmon_dev = NULL;
+ dev_warn(&pdev->dev, "Cannot register hwmon device\n");
+ }
+}
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h
new file mode 100644
index 000000000000..af310066687c
--- /dev/null
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwmon.h
@@ -0,0 +1,25 @@
+/* Broadcom NetXtreme-C/E network driver.
+ *
+ * Copyright (c) 2023 Broadcom Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.
+ */
+
+#ifndef BNXT_HWMON_H
+#define BNXT_HWMON_H
+
+#ifdef CONFIG_BNXT_HWMON
+void bnxt_hwmon_uninit(struct bnxt *bp);
+void bnxt_hwmon_init(struct bnxt *bp);
+#else
+static inline void bnxt_hwmon_uninit(struct bnxt *bp)
+{
+}
+
+static inline void bnxt_hwmon_init(struct bnxt *bp)
+{
+}
+#endif
+#endif
--
2.30.1
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]
next prev parent reply other threads:[~2023-09-27 3:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 3:57 [PATCH net-next v2 0/9] bnxt_en: hwmon and SRIOV updates Michael Chan
2023-09-27 3:57 ` [PATCH net-next v2 1/9] bnxt_en: Update firmware interface to 1.10.2.171 Michael Chan
2023-09-27 12:34 ` Andrew Lunn
2023-09-27 17:20 ` Michael Chan
2023-09-27 3:57 ` [PATCH net-next v2 2/9] bnxt_en: Enhance hwmon temperature reporting Michael Chan
2023-09-27 3:57 ` Michael Chan [this message]
2023-09-27 13:55 ` [PATCH net-next v2 3/9] bnxt_en: Move hwmon functions into a dedicated file Guenter Roeck
2023-09-27 3:57 ` [PATCH net-next v2 4/9] bnxt_en: Modify the driver to use hwmon_device_register_with_info Michael Chan
2023-09-27 13:56 ` Guenter Roeck
2023-09-27 3:57 ` [PATCH net-next v2 5/9] bnxt_en: Expose threshold temperatures through hwmon Michael Chan
2023-09-27 14:04 ` Guenter Roeck
2023-09-27 3:57 ` [PATCH net-next v2 6/9] bnxt_en: Use non-standard attribute to expose shutdown temperature Michael Chan
2023-09-27 3:57 ` [PATCH net-next v2 7/9] bnxt_en: Event handler for Thermal event Michael Chan
2023-09-27 14:05 ` Guenter Roeck
2023-09-27 3:57 ` [PATCH net-next v2 8/9] bnxt_en: Support QOS and TPID settings for the SRIOV VLAN Michael Chan
2023-10-04 18:22 ` Jakub Kicinski
2023-09-27 3:57 ` [PATCH net-next v2 9/9] bnxt_en: Update VNIC resource calculation for VFs Michael Chan
2023-10-03 9:11 ` [PATCH net-next v2 0/9] bnxt_en: hwmon and SRIOV updates Simon Horman
2023-10-04 10:30 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230927035734.42816-4-michael.chan@broadcom.com \
--to=michael.chan@broadcom$(echo .)com \
--cc=andrew.gospodarek@broadcom$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--cc=edumazet@google$(echo .)com \
--cc=gospo@broadcom$(echo .)com \
--cc=jdelvare@suse$(echo .)com \
--cc=kalesh-anakkur.purayil@broadcom$(echo .)com \
--cc=kuba@kernel$(echo .)org \
--cc=linux-hwmon@vger$(echo .)kernel.org \
--cc=linux@roeck-us$(echo .)net \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pabeni@redhat$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox