Skip to content

Commit 3d9cf96

Browse files
Kalesh APdavem330
authored andcommitted
bnxt_en: Use non-standard attribute to expose shutdown temperature
Implement the sysfs attributes directly in the driver for shutdown threshold temperature and pass an extra attribute group to the hwmon core when registering the hwmon device. Link: https://lore.kernel.org/netdev/[email protected]/ Cc: Jean Delvare <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: [email protected] Reviewed-by: Andy Gospodarek <[email protected]> Signed-off-by: Kalesh AP <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cd13244 commit 3d9cf96

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,57 @@ static const struct hwmon_chip_info bnxt_hwmon_chip_info = {
131131
.info = bnxt_hwmon_info,
132132
};
133133

134+
static ssize_t temp1_shutdown_show(struct device *dev,
135+
struct device_attribute *attr, char *buf)
136+
{
137+
struct bnxt *bp = dev_get_drvdata(dev);
138+
139+
return sysfs_emit(buf, "%u\n", bp->shutdown_thresh_temp * 1000);
140+
}
141+
142+
static ssize_t temp1_shutdown_alarm_show(struct device *dev,
143+
struct device_attribute *attr, char *buf)
144+
{
145+
struct bnxt *bp = dev_get_drvdata(dev);
146+
u8 temp;
147+
int rc;
148+
149+
rc = bnxt_hwrm_temp_query(bp, &temp);
150+
if (rc)
151+
return -EIO;
152+
153+
return sysfs_emit(buf, "%u\n", temp >= bp->shutdown_thresh_temp);
154+
}
155+
156+
static DEVICE_ATTR_RO(temp1_shutdown);
157+
static DEVICE_ATTR_RO(temp1_shutdown_alarm);
158+
159+
static struct attribute *bnxt_temp_extra_attrs[] = {
160+
&dev_attr_temp1_shutdown.attr,
161+
&dev_attr_temp1_shutdown_alarm.attr,
162+
NULL,
163+
};
164+
165+
static umode_t bnxt_temp_extra_attrs_visible(struct kobject *kobj,
166+
struct attribute *attr, int index)
167+
{
168+
struct device *dev = kobj_to_dev(kobj);
169+
struct bnxt *bp = dev_get_drvdata(dev);
170+
171+
/* Shutdown temperature setting in NVM is optional */
172+
if (!(bp->fw_cap & BNXT_FW_CAP_THRESHOLD_TEMP_SUPPORTED) ||
173+
!bp->shutdown_thresh_temp)
174+
return 0;
175+
176+
return attr->mode;
177+
}
178+
179+
static const struct attribute_group bnxt_temp_extra_group = {
180+
.attrs = bnxt_temp_extra_attrs,
181+
.is_visible = bnxt_temp_extra_attrs_visible,
182+
};
183+
__ATTRIBUTE_GROUPS(bnxt_temp_extra);
184+
134185
void bnxt_hwmon_uninit(struct bnxt *bp)
135186
{
136187
if (bp->hwmon_dev) {
@@ -156,7 +207,8 @@ void bnxt_hwmon_init(struct bnxt *bp)
156207

157208
bp->hwmon_dev = hwmon_device_register_with_info(&pdev->dev,
158209
DRV_MODULE_NAME, bp,
159-
&bnxt_hwmon_chip_info, NULL);
210+
&bnxt_hwmon_chip_info,
211+
bnxt_temp_extra_groups);
160212
if (IS_ERR(bp->hwmon_dev)) {
161213
bp->hwmon_dev = NULL;
162214
dev_warn(&pdev->dev, "Cannot register hwmon device\n");

0 commit comments

Comments
 (0)