Skip to content

Commit a47f3b3

Browse files
Kalesh APdavem330
authored andcommitted
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 <[email protected]> Cc: Jean Delvare <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: [email protected] Signed-off-by: Kalesh AP <[email protected]> Signed-off-by: Michael Chan <[email protected]> Acked-by: Guenter Roeck <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6ad7198 commit a47f3b3

File tree

4 files changed

+109
-75
lines changed

4 files changed

+109
-75
lines changed

drivers/net/ethernet/broadcom/bnxt/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ obj-$(CONFIG_BNXT) += bnxt_en.o
44
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
55
bnxt_en-$(CONFIG_BNXT_FLOWER_OFFLOAD) += bnxt_tc.o
66
bnxt_en-$(CONFIG_DEBUG_FS) += bnxt_debugfs.o
7+
bnxt_en-$(CONFIG_BNXT_HWMON) += bnxt_hwmon.o

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
#include <linux/cpu_rmap.h>
5353
#include <linux/cpumask.h>
5454
#include <net/pkt_cls.h>
55-
#include <linux/hwmon.h>
56-
#include <linux/hwmon-sysfs.h>
5755
#include <net/page_pool/helpers.h>
5856
#include <linux/align.h>
5957
#include <net/netdev_queues.h>
@@ -71,6 +69,7 @@
7169
#include "bnxt_tc.h"
7270
#include "bnxt_devlink.h"
7371
#include "bnxt_debugfs.h"
72+
#include "bnxt_hwmon.h"
7473

7574
#define BNXT_TX_TIMEOUT (5 * HZ)
7675
#define BNXT_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_HW | \
@@ -10250,79 +10249,6 @@ static void bnxt_get_wol_settings(struct bnxt *bp)
1025010249
} while (handle && handle != 0xffff);
1025110250
}
1025210251

10253-
#ifdef CONFIG_BNXT_HWMON
10254-
static ssize_t bnxt_show_temp(struct device *dev,
10255-
struct device_attribute *devattr, char *buf)
10256-
{
10257-
struct hwrm_temp_monitor_query_output *resp;
10258-
struct hwrm_temp_monitor_query_input *req;
10259-
struct bnxt *bp = dev_get_drvdata(dev);
10260-
u32 len = 0;
10261-
int rc;
10262-
10263-
rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
10264-
if (rc)
10265-
return rc;
10266-
resp = hwrm_req_hold(bp, req);
10267-
rc = hwrm_req_send(bp, req);
10268-
if (!rc)
10269-
len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */
10270-
hwrm_req_drop(bp, req);
10271-
if (rc)
10272-
return rc;
10273-
return len;
10274-
}
10275-
static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0);
10276-
10277-
static struct attribute *bnxt_attrs[] = {
10278-
&sensor_dev_attr_temp1_input.dev_attr.attr,
10279-
NULL
10280-
};
10281-
ATTRIBUTE_GROUPS(bnxt);
10282-
10283-
static void bnxt_hwmon_uninit(struct bnxt *bp)
10284-
{
10285-
if (bp->hwmon_dev) {
10286-
hwmon_device_unregister(bp->hwmon_dev);
10287-
bp->hwmon_dev = NULL;
10288-
}
10289-
}
10290-
10291-
static void bnxt_hwmon_init(struct bnxt *bp)
10292-
{
10293-
struct hwrm_temp_monitor_query_input *req;
10294-
struct pci_dev *pdev = bp->pdev;
10295-
int rc;
10296-
10297-
rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
10298-
if (!rc)
10299-
rc = hwrm_req_send_silent(bp, req);
10300-
if (rc == -EACCES || rc == -EOPNOTSUPP) {
10301-
bnxt_hwmon_uninit(bp);
10302-
return;
10303-
}
10304-
10305-
if (bp->hwmon_dev)
10306-
return;
10307-
10308-
bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev,
10309-
DRV_MODULE_NAME, bp,
10310-
bnxt_groups);
10311-
if (IS_ERR(bp->hwmon_dev)) {
10312-
bp->hwmon_dev = NULL;
10313-
dev_warn(&pdev->dev, "Cannot register hwmon device\n");
10314-
}
10315-
}
10316-
#else
10317-
static void bnxt_hwmon_uninit(struct bnxt *bp)
10318-
{
10319-
}
10320-
10321-
static void bnxt_hwmon_init(struct bnxt *bp)
10322-
{
10323-
}
10324-
#endif
10325-
1032610252
static bool bnxt_eee_config_ok(struct bnxt *bp)
1032710253
{
1032810254
struct ethtool_eee *eee = &bp->eee;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* Broadcom NetXtreme-C/E network driver.
2+
*
3+
* Copyright (c) 2023 Broadcom Limited
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation.
8+
*/
9+
10+
#include <linux/dev_printk.h>
11+
#include <linux/errno.h>
12+
#include <linux/hwmon.h>
13+
#include <linux/hwmon-sysfs.h>
14+
#include <linux/pci.h>
15+
16+
#include "bnxt_hsi.h"
17+
#include "bnxt.h"
18+
#include "bnxt_hwrm.h"
19+
#include "bnxt_hwmon.h"
20+
21+
static ssize_t bnxt_show_temp(struct device *dev,
22+
struct device_attribute *devattr, char *buf)
23+
{
24+
struct hwrm_temp_monitor_query_output *resp;
25+
struct hwrm_temp_monitor_query_input *req;
26+
struct bnxt *bp = dev_get_drvdata(dev);
27+
u32 len = 0;
28+
int rc;
29+
30+
rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
31+
if (rc)
32+
return rc;
33+
resp = hwrm_req_hold(bp, req);
34+
rc = hwrm_req_send(bp, req);
35+
if (!rc)
36+
len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */
37+
hwrm_req_drop(bp, req);
38+
if (rc)
39+
return rc;
40+
return len;
41+
}
42+
static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0);
43+
44+
static struct attribute *bnxt_attrs[] = {
45+
&sensor_dev_attr_temp1_input.dev_attr.attr,
46+
NULL
47+
};
48+
ATTRIBUTE_GROUPS(bnxt);
49+
50+
void bnxt_hwmon_uninit(struct bnxt *bp)
51+
{
52+
if (bp->hwmon_dev) {
53+
hwmon_device_unregister(bp->hwmon_dev);
54+
bp->hwmon_dev = NULL;
55+
}
56+
}
57+
58+
void bnxt_hwmon_init(struct bnxt *bp)
59+
{
60+
struct hwrm_temp_monitor_query_input *req;
61+
struct pci_dev *pdev = bp->pdev;
62+
int rc;
63+
64+
rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
65+
if (!rc)
66+
rc = hwrm_req_send_silent(bp, req);
67+
if (rc == -EACCES || rc == -EOPNOTSUPP) {
68+
bnxt_hwmon_uninit(bp);
69+
return;
70+
}
71+
72+
if (bp->hwmon_dev)
73+
return;
74+
75+
bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev,
76+
DRV_MODULE_NAME, bp,
77+
bnxt_groups);
78+
if (IS_ERR(bp->hwmon_dev)) {
79+
bp->hwmon_dev = NULL;
80+
dev_warn(&pdev->dev, "Cannot register hwmon device\n");
81+
}
82+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Broadcom NetXtreme-C/E network driver.
2+
*
3+
* Copyright (c) 2023 Broadcom Limited
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation.
8+
*/
9+
10+
#ifndef BNXT_HWMON_H
11+
#define BNXT_HWMON_H
12+
13+
#ifdef CONFIG_BNXT_HWMON
14+
void bnxt_hwmon_uninit(struct bnxt *bp);
15+
void bnxt_hwmon_init(struct bnxt *bp);
16+
#else
17+
static inline void bnxt_hwmon_uninit(struct bnxt *bp)
18+
{
19+
}
20+
21+
static inline void bnxt_hwmon_init(struct bnxt *bp)
22+
{
23+
}
24+
#endif
25+
#endif

0 commit comments

Comments
 (0)