-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bnxt_en: Move hwmon functions into a dedicated file
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> Acked-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Kalesh AP
authored and
David S. Miller
committed
Oct 4, 2023
1 parent
6ad7198
commit a47f3b3
Showing
4 changed files
with
109 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |