Re: [PATCH v4 2/2] scsi: mpt3sas: add hwmon support

From: Damien Le Moal

Date: Mon Jun 29 2026 - 20:28:54 EST


On 6/13/26 11:38, Louis Sautier wrote:
> Expose the IOC and board temperature sensors of LSI / Broadcom SAS
> HBAs through hwmon. Readings come from MPI IO Unit Page 7 via the
> accessor added in the preceding patch.
>
> The same fields are exposed by Broadcom's userspace tooling
> through the /dev/mpt[23]ctl ioctl path (typically root-only):
> IOCTemperature and BoardTemperature in lsiutil; ROC and Controller
> in storcli. With this driver, sensors(1) shows them unprivileged:
>
> $ sensors mpt3sas-pci-0200
> mpt3sas-pci-0200
> Adapter: PCI adapter
> IOC: +42.0°C
>
> Each channel is gated independently by its *TemperatureUnits field
> through is_visible(); cards that populate only one sensor expose
> only one input file, and cards that populate neither do not register
> an hwmon device.
>
> The hwmon code is gated directly on CONFIG_HWMON. IS_REACHABLE() is
> used rather than IS_ENABLED() so that SCSI_MPT3SAS=y with HWMON=m
> still builds; in that configuration, the sensors are not exposed
> (same pattern as i915 and xe).
>
> Assisted-by: Claude:claude-opus-4-7
> Signed-off-by: Louis Sautier <sautier.louis@xxxxxxxxx>

Looks OK to me, modulo a couple of nits below.
With these addressed, feel free to add:

Reviewed-by: Damien Le Moal <dlemoal@xxxxxxxxxx>

> +int mpt3sas_hwmon_register(struct MPT3SAS_ADAPTER *ioc)
> +{
> + struct device *parent = &ioc->pdev->dev;
> + struct mpt3sas_hwmon *h;
> + struct device *hwdev;
> + Mpi2ConfigReply_t mpi_reply;
> + Mpi2IOUnitPage7_t page;
> + int r;
> +
> + h = kzalloc_obj(*h);
> + if (!h)
> + return -ENOMEM;
> +
> + h->ioc = ioc;

maybe move this below together with the h->ioc_present initialization ?
There seem to be no point for this line to be alone here.

> +
> + r = mpt3sas_config_get_iounit_pg7(ioc, &mpi_reply, &page);
> + if (r) {
> + kfree(h);
> + return r;
> + }

You should test for the page being present first and then allocate h if it is.
That would be cleaner/simpler.

> +
> + h->ioc_present = page.IOCTemperatureUnits != MPI2_IOUNITPAGE7_IOC_TEMP_NOT_PRESENT;
> + h->board_present = page.BoardTemperatureUnits != MPI2_IOUNITPAGE7_BOARD_TEMP_NOT_PRESENT;
> +
> + /*
> + * A page where both *TemperatureUnits are NOT_PRESENT covers
> + * two cases: cards that genuinely lack sensors, and firmware
> + * errors that left the page zero-filled (the accessor mirrors
> + * _config_request() behaviour). Either way: skip registration.
> + */
> + if (!h->ioc_present && !h->board_present) {
> + kfree(h);
> + return 0;
> + }
> +
> + hwdev = hwmon_device_register_with_info(parent, "mpt3sas", h,
> + &mpt3sas_hwmon_chip_info,
> + NULL);
> + if (IS_ERR(hwdev)) {
> + kfree(h);
> + return PTR_ERR(hwdev);
> + }
> +
> + h->hwmon_dev = hwdev;
> + ioc->hwmon = h;
> + return 0;
> +}


--
Damien Le Moal
Western Digital Research