scsi: mpt3sas: add hwmon support
Subsystems (3)
v5 cover scsi: mpt3sas: add hwmon support
Expose the IOC and board temperature sensors of LSI / Broadcom / Avago SAS HBAs that bind to mpt3sas through the hwmon interface. The data lives in MPI IO Unit Page 7.
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
v4 -> v5:
v4: https://lore.kernel.org/r/[email protected]
* In mpt3sas_hwmon_register(), read IO Unit Page 7 and test sensor presence before allocating, so the no-sensor and error paths no longer allocate and free (Damien Le Moal).
* Added Damien Le Moal's Reviewed-by to patch 2.
v3 -> v4:
v3: https://lore.kernel.org/r/[email protected]
v3 (resend): https://lore.kernel.org/r/[email protected]
* Dropped the SCSI_MPT3SAS_HWMON Kconfig option as suggested by
Damien Le Moal; the hwmon code is now built whenever CONFIG_HWMON
is enabled. Used IS_REACHABLE() rather than IS_ENABLED() so SCSI_MPT3SAS=y with HWMON=m still builds, same pattern as i915/xe.
* No line breaks after function return types; aligned multi-line
call arguments to the opening parenthesis (Damien Le Moal).
* Dropped unused #include <linux/kernel.h> from mpt3sas_hwmon.c.
* Added Damien Le Moal's Reviewed-by to patch 1.
v2 -> v3:
v2: https://lore.kernel.org/r/[email protected]
* Removed stale Documentation/hwmon/mpt3sas.rst reference from Kconfig help text.
v1 -> v2:
v1: https://lore.kernel.org/r/[email protected]
* Dropped misleading Documentation/hwmon/mpt3sas.rst.
* Dropped inaccurate concurrency-wait figure from Testing; corrected empirical data is in the on-list discussion.
Testing
-------
Build-tested all four SCSI_MPT3SAS x HWMON combinations (=y and =m each), including the SCSI_MPT3SAS=y with HWMON=m case that requires IS_REACHABLE().
Validated across three Broadcom SAS chip generations. None of the cards had a board sensor present, so the testing only covers the IOC channel:
* LSI 9500-8i / SAS3816, SAS-3:
- hwmon device registers as "mpt3sas" with only temp1 (IOC) exposed
- IOC reading matches storcli /c0 show temperature and lsiutil -p1 -a 25,2,0,0
- rmmod / modprobe cycle goes through the explicit unregister/register paths cleanly
* LSI 9305-24i / SAS3224, SAS-3: same behaviour.
* LSI 9211-4i / SAS2004, SAS-2: firmware reports both *TemperatureUnits = NOT_PRESENT, no hwmon device registered (graceful-skip path).
Not verified (no available hardware):
* Path with both IOC and board sensors present.
* Fahrenheit-units conversion.
* Sub-zero readings (signed-cast path).
Louis Sautier (2):
scsi: mpt3sas: add IO Unit Page 7 config accessor
scsi: mpt3sas: add hwmon support
drivers/scsi/mpt3sas/Makefile | 2 + drivers/scsi/mpt3sas/mpt3sas_base.h | 20 +++ drivers/scsi/mpt3sas/mpt3sas_config.c | 36 +++++ drivers/scsi/mpt3sas/mpt3sas_hwmon.c | 191 ++++++++++++++++++++++++++ drivers/scsi/mpt3sas/mpt3sas_scsih.c | 6 + 5 files changed, 255 insertions(+) create mode 100644 drivers/scsi/mpt3sas/mpt3sas_hwmon.c
base-commit: 5d6919055dec134de3c40167a490f33c74c12581
Signature · 1 line
2.54.0
PATCH v5 1/2 scsi: mpt3sas: add IO Unit Page 7 config accessor
Add mpt3sas_config_get_iounit_pg7(), mirroring the existing iounit page accessors. Used by the hwmon driver added in the following patch to read the IOC and board temperatures.
--- drivers/scsi/mpt3sas/mpt3sas_base.h | 3 +++ drivers/scsi/mpt3sas/mpt3sas_config.c | 36 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/scsi/mpt3sas/mpt3sas_base.h +3 -0
@@ -1904,6 +1904,9 @@ int mpt3sas_config_get_iounit_pg3(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigReply_t *mpi_reply, Mpi2IOUnitPage3_t *config_page, u16 sz);int mpt3sas_config_set_iounit_pg1 (struct MPT3SAS_ADAPTER *ioc,Mpi2ConfigReply_t *mpi_reply,Mpi2IOUnitPage1_t *config_page); +int mpt3sas_config_get_iounit_pg7 (struct MPT3SAS_ADAPTER *ioc, +Mpi2ConfigReply_t *mpi_reply, +Mpi2IOUnitPage7_t *config_page);int mpt3sas_config_get_iounit_pg8 (struct MPT3SAS_ADAPTER *ioc,Mpi2ConfigReply_t *mpi_reply,Mpi2IOUnitPage8_t *config_page); int mpt3sas_config_get_sas_iounit_pg1(struct MPT3SAS_ADAPTER *ioc,
drivers/scsi/mpt3sas/mpt3sas_config.c +36 -0
@@ -991,6 +991,42 @@ mpt3sas_config_get_iounit_pg3(struct MPT3SAS_ADAPTER *ioc,return r; } +/** +* mpt3sas_config_get_iounit_pg7 - obtain iounit page 7 +* @ioc: per adapter object +* @mpi_reply: reply mf payload returned from firmware +* @config_page: contents of the config page +* Context: sleep. +* +* Return: 0 for success, non-zero for failure. +*/ +int mpt3sas_config_get_iounit_pg7 (struct MPT3SAS_ADAPTER *ioc, +Mpi2ConfigReply_t *mpi_reply, +Mpi2IOUnitPage7_t *config_page) +{ +Mpi2ConfigRequest_t mpi_request; +int r; + +memset (&mpi_request,0 ,sizeof (Mpi2ConfigRequest_t)); + mpi_request.Function =MPI2_FUNCTION_CONFIG ; + mpi_request.Action =MPI2_CONFIG_ACTION_PAGE_HEADER ; + mpi_request.Header.PageType =MPI2_CONFIG_PAGETYPE_IO_UNIT ; + mpi_request.Header.PageNumber =7 ; + mpi_request.Header.PageVersion =MPI2_IOUNITPAGE7_PAGEVERSION ; + ioc->build_zero_len_sge_mpi (ioc, &mpi_request.PageBufferSGE); + r =_config_request (ioc, &mpi_request, mpi_reply, +MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT ,NULL ,0 ); +if (r) + goto out; + + mpi_request.Action =MPI2_CONFIG_ACTION_PAGE_READ_CURRENT ; + r =_config_request (ioc, &mpi_request, mpi_reply, +MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT , + config_page,sizeof (*config_page)); + out: +return r; +} +/** * mpt3sas_config_get_iounit_pg8 - obtain iounit page 8 * @ioc: per adapter object
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v5 1/2] scsi: mpt3sas: add IO Unit Page 7 config accessor
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Add
mpt3sas_config_get_iounit_pg7(), mirroring the existing iounit page accessors. Used by the hwmon driver added in the following patch to read the IOC and board temperatures.Assisted-by Claude:claude-opus-4-7Signed-off-by Louis Sautier <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v5 2/2 scsi: mpt3sas: add hwmon support
In reply to Louis SautierExpose 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).
--- drivers/scsi/mpt3sas/Makefile | 2 + drivers/scsi/mpt3sas/mpt3sas_base.h | 17 +++ drivers/scsi/mpt3sas/mpt3sas_hwmon.c | 191 +++++++++++++++++++++++++++ drivers/scsi/mpt3sas/mpt3sas_scsih.c | 6 + 4 files changed, 216 insertions(+) create mode 100644 drivers/scsi/mpt3sas/mpt3sas_hwmon.c
drivers/scsi/mpt3sas/Makefile +2 -0
@@ -9,3 +9,5 @@ mpt3sas-y += mpt3sas_base.o \ mpt3sas_trigger_diag.o \ mpt3sas_warpdrive.o \ mpt3sas_debugfs.o \ + +mpt3sas-$(CONFIG_HWMON) += mpt3sas_hwmon.o
drivers/scsi/mpt3sas/mpt3sas_base.h +17 -0
@@ -1629,6 +1629,9 @@ struct MPT3SAS_ADAPTER {u8 is_aero_ioc;struct dentry *debugfs_root;struct dentry *ioc_dump; +#if IS_REACHABLE (CONFIG_HWMON ) +struct mpt3sas_hwmon *hwmon; +#endif PUT_SMID_IO_FP_HIP put_smid_scsi_io;PUT_SMID_IO_FP_HIP put_smid_fast_path;PUT_SMID_IO_FP_HIP put_smid_hi_priority;
@@ -2050,6 +2053,20 @@ void mpt3sas_destroy_debugfs(struct MPT3SAS_ADAPTER *ioc);void mpt3sas_init_debugfs (void );void mpt3sas_exit_debugfs (void ); +#if IS_REACHABLE (CONFIG_HWMON ) +int mpt3sas_hwmon_register (struct MPT3SAS_ADAPTER *ioc); +void mpt3sas_hwmon_unregister (struct MPT3SAS_ADAPTER *ioc); +#else +static inline int mpt3sas_hwmon_register (struct MPT3SAS_ADAPTER *ioc) +{ +return 0 ; +} + +static inline void mpt3sas_hwmon_unregister (struct MPT3SAS_ADAPTER *ioc) +{ +} +#endif +/** * _scsih_is_pcie_scsi_device - determines if device is an pcie scsi device * @device_info: bitfield providing information about the device.
drivers/scsi/mpt3sas/mpt3sas_hwmon.c new file +191 -0
191 lines not on this page · raw message
drivers/scsi/mpt3sas/mpt3sas_scsih.c +6 -0
@@ -12562,6 +12562,7 @@ static void scsih_remove(struct pci_dev *pdev)/* release all the volumes */ _scsih_ir_shutdown (ioc);mpt3sas_destroy_debugfs (ioc); +mpt3sas_hwmon_unregister (ioc);sas_remove_host (shost);list_for_each_entry_safe (raid_device, next, &ioc->raid_device_list, list) {
@@ -13651,6 +13652,11 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id) }scsi_scan_host (shost); + +if (mpt3sas_hwmon_register (ioc)) +ioc_warn (ioc, +"hwmon registration failed; temperatures not exposed\n" ); +mpt3sas_setup_debugfs (ioc);return 0 ; out_add_shost_fail:
Signature · 1 line
2.54.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 19 lines
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°CEach 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.
Quoted 7 lines
The hwmon code is gated directly on
CONFIG_HWMON.IS_REACHABLE()is used rather thanIS_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-7Signed-off-by Louis Sautier <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Martin K. Petersen
AppliedLouis,
Quoted 3 lines
Expose the IOC and board temperature sensors of LSI / Broadcom / Avago SAS HBAs that bind to mpt3sas through the hwmon interface. The data lives in MPI IO Unit Page 7.
Applied to 7.3/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen