Skip to content

Commit 4c01315

Browse files
Yana Esinadavem330
authored andcommitted
net: aquantia: implement hwmon api for chip temperature
Added support for hwmon api to fetch out chip temperature Signed-off-by: Yana Esina <[email protected]> Signed-off-by: Nikita Danilov <[email protected]> Signed-off-by: Igor Russkikh <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8f89401 commit 4c01315

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

drivers/net/ethernet/aquantia/atlantic/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ atlantic-objs := aq_main.o \
3636
aq_ring.o \
3737
aq_hw_utils.o \
3838
aq_ethtool.o \
39+
aq_drvinfo.o \
3940
aq_filters.o \
4041
hw_atl/hw_atl_a0.o \
4142
hw_atl/hw_atl_b0.o \
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/* Copyright (C) 2014-2019 aQuantia Corporation. */
3+
4+
/* File aq_drvinfo.c: Definition of common code for firmware info in sys.*/
5+
6+
#include <linux/init.h>
7+
#include <linux/kobject.h>
8+
#include <linux/module.h>
9+
#include <linux/stat.h>
10+
#include <linux/string.h>
11+
#include <linux/hwmon.h>
12+
#include <linux/uaccess.h>
13+
14+
#include "aq_drvinfo.h"
15+
16+
static int aq_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
17+
u32 attr, int channel, long *value)
18+
{
19+
struct aq_nic_s *aq_nic = dev_get_drvdata(dev);
20+
int temp;
21+
int err;
22+
23+
if (!aq_nic)
24+
return -EIO;
25+
26+
if (type != hwmon_temp)
27+
return -EOPNOTSUPP;
28+
29+
if (!aq_nic->aq_fw_ops->get_phy_temp)
30+
return -EOPNOTSUPP;
31+
32+
switch (attr) {
33+
case hwmon_temp_input:
34+
err = aq_nic->aq_fw_ops->get_phy_temp(aq_nic->aq_hw, &temp);
35+
*value = temp;
36+
return err;
37+
default:
38+
return -EOPNOTSUPP;
39+
}
40+
}
41+
42+
static int aq_hwmon_read_string(struct device *dev,
43+
enum hwmon_sensor_types type,
44+
u32 attr, int channel, const char **str)
45+
{
46+
struct aq_nic_s *aq_nic = dev_get_drvdata(dev);
47+
48+
if (!aq_nic)
49+
return -EIO;
50+
51+
if (type != hwmon_temp)
52+
return -EOPNOTSUPP;
53+
54+
if (!aq_nic->aq_fw_ops->get_phy_temp)
55+
return -EOPNOTSUPP;
56+
57+
switch (attr) {
58+
case hwmon_temp_label:
59+
*str = "PHY Temperature";
60+
return 0;
61+
default:
62+
return -EOPNOTSUPP;
63+
}
64+
}
65+
66+
static umode_t aq_hwmon_is_visible(const void *data,
67+
enum hwmon_sensor_types type,
68+
u32 attr, int channel)
69+
{
70+
if (type != hwmon_temp)
71+
return 0;
72+
73+
switch (attr) {
74+
case hwmon_temp_input:
75+
case hwmon_temp_label:
76+
return 0444;
77+
default:
78+
return 0;
79+
}
80+
}
81+
82+
static const struct hwmon_ops aq_hwmon_ops = {
83+
.is_visible = aq_hwmon_is_visible,
84+
.read = aq_hwmon_read,
85+
.read_string = aq_hwmon_read_string,
86+
};
87+
88+
static u32 aq_hwmon_temp_config[] = {
89+
HWMON_T_INPUT | HWMON_T_LABEL,
90+
0,
91+
};
92+
93+
static const struct hwmon_channel_info aq_hwmon_temp = {
94+
.type = hwmon_temp,
95+
.config = aq_hwmon_temp_config,
96+
};
97+
98+
static const struct hwmon_channel_info *aq_hwmon_info[] = {
99+
&aq_hwmon_temp,
100+
NULL,
101+
};
102+
103+
static const struct hwmon_chip_info aq_hwmon_chip_info = {
104+
.ops = &aq_hwmon_ops,
105+
.info = aq_hwmon_info,
106+
};
107+
108+
int aq_drvinfo_init(struct net_device *ndev)
109+
{
110+
struct aq_nic_s *aq_nic = netdev_priv(ndev);
111+
struct device *dev = &aq_nic->pdev->dev;
112+
struct device *hwmon_dev;
113+
int err = 0;
114+
115+
hwmon_dev = devm_hwmon_device_register_with_info(dev,
116+
ndev->name,
117+
aq_nic,
118+
&aq_hwmon_chip_info,
119+
NULL);
120+
121+
if (IS_ERR(hwmon_dev))
122+
err = PTR_ERR(hwmon_dev);
123+
124+
return err;
125+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/* Copyright (C) 2014-2017 aQuantia Corporation. */
3+
4+
/* File aq_drvinfo.h: Declaration of common code for firmware info in sys.*/
5+
6+
#ifndef AQ_DRVINFO_H
7+
#define AQ_DRVINFO_H
8+
9+
#include "aq_nic.h"
10+
#include "aq_hw.h"
11+
#include "hw_atl/hw_atl_utils.h"
12+
13+
int aq_drvinfo_init(struct net_device *ndev);
14+
15+
#endif /* AQ_DRVINFO_H */

drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "hw_atl/hw_atl_a0.h"
2121
#include "hw_atl/hw_atl_b0.h"
2222
#include "aq_filters.h"
23+
#include "aq_drvinfo.h"
2324

2425
static const struct pci_device_id aq_pci_tbl[] = {
2526
{ PCI_VDEVICE(AQUANTIA, AQ_DEVICE_ID_0001), },
@@ -289,6 +290,8 @@ static int aq_pci_probe(struct pci_dev *pdev,
289290
if (err < 0)
290291
goto err_register;
291292

293+
aq_drvinfo_init(ndev);
294+
292295
return 0;
293296

294297
err_register:

0 commit comments

Comments
 (0)