Skip to content

Commit 8806307

Browse files
sanmanp2111993kuba-moo
authored andcommitted
eth: fbnic: Add hardware monitoring support via HWMON interface
This patch adds support for hardware monitoring to the fbnic driver, allowing for temperature and voltage sensor data to be exposed to userspace via the HWMON interface. The driver registers a HWMON device and provides callbacks for reading sensor data, enabling system admins to monitor the health and operating conditions of fbnic. Signed-off-by: Sanman Pradhan <[email protected]> Reviewed-by: Michal Swiatkowski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 89e6f19 commit 8806307

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

drivers/net/ethernet/meta/fbnic/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fbnic-y := fbnic_csr.o \
1313
fbnic_ethtool.o \
1414
fbnic_fw.o \
1515
fbnic_hw_stats.o \
16+
fbnic_hwmon.o \
1617
fbnic_irq.o \
1718
fbnic_mac.o \
1819
fbnic_netdev.o \

drivers/net/ethernet/meta/fbnic/fbnic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct fbnic_dev {
2424
struct device *dev;
2525
struct net_device *netdev;
2626
struct dentry *dbg_fbd;
27+
struct device *hwmon;
2728

2829
u32 __iomem *uc_addr0;
2930
u32 __iomem *uc_addr4;
@@ -150,6 +151,9 @@ void fbnic_devlink_unregister(struct fbnic_dev *fbd);
150151
int fbnic_fw_enable_mbx(struct fbnic_dev *fbd);
151152
void fbnic_fw_disable_mbx(struct fbnic_dev *fbd);
152153

154+
void fbnic_hwmon_register(struct fbnic_dev *fbd);
155+
void fbnic_hwmon_unregister(struct fbnic_dev *fbd);
156+
153157
int fbnic_pcs_irq_enable(struct fbnic_dev *fbd);
154158
void fbnic_pcs_irq_disable(struct fbnic_dev *fbd);
155159

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) Meta Platforms, Inc. and affiliates. */
3+
4+
#include <linux/hwmon.h>
5+
6+
#include "fbnic.h"
7+
#include "fbnic_mac.h"
8+
9+
static int fbnic_hwmon_sensor_id(enum hwmon_sensor_types type)
10+
{
11+
if (type == hwmon_temp)
12+
return FBNIC_SENSOR_TEMP;
13+
if (type == hwmon_in)
14+
return FBNIC_SENSOR_VOLTAGE;
15+
16+
return -EOPNOTSUPP;
17+
}
18+
19+
static umode_t fbnic_hwmon_is_visible(const void *drvdata,
20+
enum hwmon_sensor_types type,
21+
u32 attr, int channel)
22+
{
23+
if (type == hwmon_temp && attr == hwmon_temp_input)
24+
return 0444;
25+
if (type == hwmon_in && attr == hwmon_in_input)
26+
return 0444;
27+
28+
return 0;
29+
}
30+
31+
static int fbnic_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
32+
u32 attr, int channel, long *val)
33+
{
34+
struct fbnic_dev *fbd = dev_get_drvdata(dev);
35+
const struct fbnic_mac *mac = fbd->mac;
36+
int id;
37+
38+
id = fbnic_hwmon_sensor_id(type);
39+
return id < 0 ? id : mac->get_sensor(fbd, id, val);
40+
}
41+
42+
static const struct hwmon_ops fbnic_hwmon_ops = {
43+
.is_visible = fbnic_hwmon_is_visible,
44+
.read = fbnic_hwmon_read,
45+
};
46+
47+
static const struct hwmon_channel_info *fbnic_hwmon_info[] = {
48+
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
49+
HWMON_CHANNEL_INFO(in, HWMON_I_INPUT),
50+
NULL
51+
};
52+
53+
static const struct hwmon_chip_info fbnic_chip_info = {
54+
.ops = &fbnic_hwmon_ops,
55+
.info = fbnic_hwmon_info,
56+
};
57+
58+
void fbnic_hwmon_register(struct fbnic_dev *fbd)
59+
{
60+
if (!IS_REACHABLE(CONFIG_HWMON))
61+
return;
62+
63+
fbd->hwmon = hwmon_device_register_with_info(fbd->dev, "fbnic",
64+
fbd, &fbnic_chip_info,
65+
NULL);
66+
if (IS_ERR(fbd->hwmon)) {
67+
dev_notice(fbd->dev,
68+
"Failed to register hwmon device %pe\n",
69+
fbd->hwmon);
70+
fbd->hwmon = NULL;
71+
}
72+
}
73+
74+
void fbnic_hwmon_unregister(struct fbnic_dev *fbd)
75+
{
76+
if (!IS_REACHABLE(CONFIG_HWMON) || !fbd->hwmon)
77+
return;
78+
79+
hwmon_device_unregister(fbd->hwmon);
80+
fbd->hwmon = NULL;
81+
}

drivers/net/ethernet/meta/fbnic/fbnic_pci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ static int fbnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
296296
/* Capture snapshot of hardware stats so netdev can calculate delta */
297297
fbnic_reset_hw_stats(fbd);
298298

299+
fbnic_hwmon_register(fbd);
300+
299301
if (!fbd->dsn) {
300302
dev_warn(&pdev->dev, "Reading serial number failed\n");
301303
goto init_failure_mode;
@@ -358,6 +360,7 @@ static void fbnic_remove(struct pci_dev *pdev)
358360
fbnic_netdev_free(fbd);
359361
}
360362

363+
fbnic_hwmon_unregister(fbd);
361364
fbnic_dbg_fbd_exit(fbd);
362365
fbnic_devlink_unregister(fbd);
363366
fbnic_fw_disable_mbx(fbd);

0 commit comments

Comments
 (0)