drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c- Extension
.c- Size
- 28965 bytes
- Lines
- 941
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/types.hlinux/device.hlinux/sysfs.hlinux/hwmon.hlinux/err.hlinux/sfp.hcore.hcore_env.h
Detected Declarations
struct mlxsw_hwmon_attrstruct mlxsw_hwmon_devstruct mlxsw_hwmonenum mlxsw_hwmon_attr_typefunction mlxsw_hwmon_get_attr_indexfunction mlxsw_hwmon_temp_showfunction mlxsw_hwmon_temp_max_showfunction mlxsw_hwmon_temp_rst_storefunction mlxsw_hwmon_fan_rpm_showfunction mlxsw_hwmon_fan_fault_showfunction mlxsw_hwmon_pwm_showfunction mlxsw_hwmon_pwm_storefunction mlxsw_hwmon_module_temp_getfunction mlxsw_hwmon_module_temp_showfunction mlxsw_hwmon_module_temp_fault_showfunction mlxsw_hwmon_module_temp_critical_getfunction mlxsw_hwmon_module_temp_critical_showfunction mlxsw_hwmon_module_temp_emergency_getfunction mlxsw_hwmon_module_temp_emergency_showfunction mlxsw_hwmon_module_temp_label_showfunction mlxsw_hwmon_gbox_temp_label_showfunction mlxsw_hwmon_temp_critical_alarm_showfunction mlxsw_hwmon_temp_emergency_alarm_showfunction mlxsw_hwmon_attr_addfunction mlxsw_hwmon_temp_initfunction mlxsw_hwmon_fans_initfunction mlxsw_hwmon_module_initfunction mlxsw_hwmon_gearbox_initfunction mlxsw_hwmon_got_activefunction mlxsw_hwmon_got_inactivefunction mlxsw_hwmon_initfunction mlxsw_hwmon_fini
Annotated Snippet
struct mlxsw_hwmon_attr {
struct device_attribute dev_attr;
struct mlxsw_hwmon_dev *mlxsw_hwmon_dev;
unsigned int type_index;
char name[32];
};
static int mlxsw_hwmon_get_attr_index(int index, int count)
{
if (index >= count)
return index % count + MLXSW_REG_MTMP_GBOX_INDEX_MIN;
return index;
}
struct mlxsw_hwmon_dev {
char name[MLXSW_HWMON_DEV_NAME_LEN_MAX];
struct mlxsw_hwmon *hwmon;
struct device *hwmon_dev;
struct attribute_group group;
const struct attribute_group *groups[2];
struct attribute *attrs[MLXSW_HWMON_ATTR_COUNT + 1];
struct mlxsw_hwmon_attr hwmon_attrs[MLXSW_HWMON_ATTR_COUNT];
unsigned int attrs_count;
u8 sensor_count;
u8 module_sensor_max;
u8 slot_index;
bool active;
};
struct mlxsw_hwmon {
struct mlxsw_core *core;
const struct mlxsw_bus_info *bus_info;
struct mlxsw_hwmon_dev line_cards[];
};
static ssize_t mlxsw_hwmon_temp_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN];
int temp, index;
int err;
index = mlxsw_hwmon_get_attr_index(mlxsw_hwmon_attr->type_index,
mlxsw_hwmon_dev->module_sensor_max);
mlxsw_reg_mtmp_pack(mtmp_pl, mlxsw_hwmon_dev->slot_index, index, false,
false);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n");
return err;
}
mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL, NULL, NULL);
return sprintf(buf, "%d\n", temp);
}
static ssize_t mlxsw_hwmon_temp_max_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN];
int temp_max, index;
int err;
index = mlxsw_hwmon_get_attr_index(mlxsw_hwmon_attr->type_index,
mlxsw_hwmon_dev->module_sensor_max);
mlxsw_reg_mtmp_pack(mtmp_pl, mlxsw_hwmon_dev->slot_index, index, false,
false);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n");
return err;
}
mlxsw_reg_mtmp_unpack(mtmp_pl, NULL, &temp_max, NULL, NULL, NULL);
return sprintf(buf, "%d\n", temp_max);
}
static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/device.h`, `linux/sysfs.h`, `linux/hwmon.h`, `linux/err.h`, `linux/sfp.h`, `core.h`.
- Detected declarations: `struct mlxsw_hwmon_attr`, `struct mlxsw_hwmon_dev`, `struct mlxsw_hwmon`, `enum mlxsw_hwmon_attr_type`, `function mlxsw_hwmon_get_attr_index`, `function mlxsw_hwmon_temp_show`, `function mlxsw_hwmon_temp_max_show`, `function mlxsw_hwmon_temp_rst_store`, `function mlxsw_hwmon_fan_rpm_show`, `function mlxsw_hwmon_fan_fault_show`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.