Skip to content

Commit cd13244

Browse files
Kalesh APdavem330
authored andcommitted
bnxt_en: Expose threshold temperatures through hwmon
HWRM_TEMP_MONITOR_QUERY response now indicates various threshold temperatures. Expose these threshold temperatures through the hwmon sysfs using this mapping: hwmon_temp_max : bp->warn_thresh_temp hwmon_temp_crit : bp->crit_thresh_temp hwmon_temp_emergency : bp->fatal_thresh_temp hwmon_temp_max_alarm : temp >= bp->warn_thresh_temp hwmon_temp_crit_alarm : temp >= bp->crit_thresh_temp hwmon_temp_emergency_alarm : temp >= bp->fatal_thresh_temp Link: https://lore.kernel.org/netdev/[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 847da8b commit cd13244

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,7 @@ struct bnxt {
20132013
#define BNXT_FW_CAP_RING_MONITOR BIT_ULL(30)
20142014
#define BNXT_FW_CAP_DBG_QCAPS BIT_ULL(31)
20152015
#define BNXT_FW_CAP_PTP BIT_ULL(32)
2016+
#define BNXT_FW_CAP_THRESHOLD_TEMP_SUPPORTED BIT_ULL(33)
20162017

20172018
u32 fw_dbg_cap;
20182019

@@ -2185,7 +2186,13 @@ struct bnxt {
21852186
struct bnxt_tc_info *tc_info;
21862187
struct list_head tc_indr_block_list;
21872188
struct dentry *debugfs_pdev;
2189+
#ifdef CONFIG_BNXT_HWMON
21882190
struct device *hwmon_dev;
2191+
u8 warn_thresh_temp;
2192+
u8 crit_thresh_temp;
2193+
u8 fatal_thresh_temp;
2194+
u8 shutdown_thresh_temp;
2195+
#endif
21892196
enum board_idx board_idx;
21902197
};
21912198

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

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ static int bnxt_hwrm_temp_query(struct bnxt *bp, u8 *temp)
3232
if (rc)
3333
goto drop_req;
3434

35-
*temp = resp->temp;
36-
35+
if (temp) {
36+
*temp = resp->temp;
37+
} else if (resp->flags &
38+
TEMP_MONITOR_QUERY_RESP_FLAGS_THRESHOLD_VALUES_AVAILABLE) {
39+
bp->fw_cap |= BNXT_FW_CAP_THRESHOLD_TEMP_SUPPORTED;
40+
bp->warn_thresh_temp = resp->warn_threshold;
41+
bp->crit_thresh_temp = resp->critical_threshold;
42+
bp->fatal_thresh_temp = resp->fatal_threshold;
43+
bp->shutdown_thresh_temp = resp->shutdown_threshold;
44+
}
3745
drop_req:
3846
hwrm_req_drop(bp, req);
3947
return rc;
@@ -42,12 +50,23 @@ static int bnxt_hwrm_temp_query(struct bnxt *bp, u8 *temp)
4250
static umode_t bnxt_hwmon_is_visible(const void *_data, enum hwmon_sensor_types type,
4351
u32 attr, int channel)
4452
{
53+
const struct bnxt *bp = _data;
54+
4555
if (type != hwmon_temp)
4656
return 0;
4757

4858
switch (attr) {
4959
case hwmon_temp_input:
5060
return 0444;
61+
case hwmon_temp_max:
62+
case hwmon_temp_crit:
63+
case hwmon_temp_emergency:
64+
case hwmon_temp_max_alarm:
65+
case hwmon_temp_crit_alarm:
66+
case hwmon_temp_emergency_alarm:
67+
if (!(bp->fw_cap & BNXT_FW_CAP_THRESHOLD_TEMP_SUPPORTED))
68+
return 0;
69+
return 0444;
5170
default:
5271
return 0;
5372
}
@@ -66,13 +85,39 @@ static int bnxt_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32
6685
if (!rc)
6786
*val = temp * 1000;
6887
return rc;
88+
case hwmon_temp_max:
89+
*val = bp->warn_thresh_temp * 1000;
90+
return 0;
91+
case hwmon_temp_crit:
92+
*val = bp->crit_thresh_temp * 1000;
93+
return 0;
94+
case hwmon_temp_emergency:
95+
*val = bp->fatal_thresh_temp * 1000;
96+
return 0;
97+
case hwmon_temp_max_alarm:
98+
rc = bnxt_hwrm_temp_query(bp, &temp);
99+
if (!rc)
100+
*val = temp >= bp->warn_thresh_temp;
101+
return rc;
102+
case hwmon_temp_crit_alarm:
103+
rc = bnxt_hwrm_temp_query(bp, &temp);
104+
if (!rc)
105+
*val = temp >= bp->crit_thresh_temp;
106+
return rc;
107+
case hwmon_temp_emergency_alarm:
108+
rc = bnxt_hwrm_temp_query(bp, &temp);
109+
if (!rc)
110+
*val = temp >= bp->fatal_thresh_temp;
111+
return rc;
69112
default:
70113
return -EOPNOTSUPP;
71114
}
72115
}
73116

74117
static const struct hwmon_channel_info *bnxt_hwmon_info[] = {
75-
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
118+
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_CRIT |
119+
HWMON_T_EMERGENCY | HWMON_T_MAX_ALARM |
120+
HWMON_T_CRIT_ALARM | HWMON_T_EMERGENCY_ALARM),
76121
NULL
77122
};
78123

@@ -96,13 +141,11 @@ void bnxt_hwmon_uninit(struct bnxt *bp)
96141

97142
void bnxt_hwmon_init(struct bnxt *bp)
98143
{
99-
struct hwrm_temp_monitor_query_input *req;
100144
struct pci_dev *pdev = bp->pdev;
101145
int rc;
102146

103-
rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
104-
if (!rc)
105-
rc = hwrm_req_send_silent(bp, req);
147+
/* temp1_xxx is only sensor, ensure not registered if it will fail */
148+
rc = bnxt_hwrm_temp_query(bp, NULL);
106149
if (rc == -EACCES || rc == -EOPNOTSUPP) {
107150
bnxt_hwmon_uninit(bp);
108151
return;

0 commit comments

Comments
 (0)