Skip to contentSkip to conversation

platform/mellanox: Add nvsw core and SPC6 host driver

PATCH In review Felix Radensky 2 participants 6 messages Nov 25 – Nov 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover platform/mellanox: Add nvsw core and SPC6 host driver

This series adds support for system control and monitoring on Nvidia SPC6 based switches, through the CPLD/FPGA devices attached to the host CPU.

Patch 1 adds nvsw-core, which implements the register map setup, the I2C mux topology and the creation of the mlxreg-* platform devices shared by all Nvidia switch board drivers. Patch 2 adds nvsw-host-spc6, the first user of that core, covering the liquid cooled systems, along with documentation for the register access attributes it exposes. Patch 3 adds the air cooled SPC6 systems, which unlike the liquid cooled ones carry their own power supplies and fan drawers.

The functionality covered is component resets and reset cause reporting, mux selection for hardware components, general purpose registers, LED control, watchdog control, and fan control on the systems that have fans. The core also creates an mlxreg-hotplug device for boards that describe one; no SPC6 system does, and that path comes into use with the BMC driver mentioned below.

Why a new core instead of extending mlx-platform
================================================

The obvious question is why this does not go into mlx-platform.c, which already serves the existing Mellanox switch generations. There are two reasons.

The first is that mlx-platform.c cannot reach this hardware. It is built around a single memory mapped LPC window: it calls devm_ioport_map() once, hands the resulting base to devm_regmap_init() with its own ioread8()/iowrite8() callbacks, and every system it supports is described in terms of offsets into that window. On SPC6 the CPLD is not on the LPC bus at all, it is an I2C device, and the driver reaches it with devm_regmap_init_i2c() through a client on the host I2C tree. Supporting SPC6 in mlx-platform.c would mean giving it a second, parallel register access path and making its register map setup conditional, which is a larger and more invasive change than adding a separate driver.

The same applies beyond SPC6. The identical CPLD register layout is also managed from an ARM Baseboard Management Controller, where the device is reached over I2C in the same way but is described in device tree rather than discovered through DMI. nvsw-core holds only the parts that do not depend on how the board was found, so the register definitions and the mlxreg-* device descriptions are shared, and each board driver supplies its own instantiation. mlx-platform.c is inherently x86 and DMI bound and cannot serve the BMC side.

The second reason is structural. mlx-platform.c has grown to roughly 8600 lines covering 49 DMI matches, with the per-system description data and the device creation logic interleaved in a single translation unit. Adding another switch generation to it makes the file harder to review and makes it impossible to build support for one system without carrying the tables for all the others. nvsw splits the two concerns:
the core holds the logic (391 lines) and each board driver holds only its own description data, so a kernel can be built with just the boards it needs.

The core is not speculative generality. The SPC6 host driver in this series is its first user, and we intend to submit a BMC driver and an NVL7 host driver on top of it once the core has been reviewed.

Why the SPC6 driver is split over two patches
=============================================

Patches 2 and 3 add a single driver, split along a hardware line rather than chopped into arbitrary pieces. Patch 2 is complete and useful on its own: it covers the liquid cooled SPC6 systems, which shipped first. Patch 3 adds the air cooled systems, which arrived later and expose a different set of CPLD attributes because they carry their own power supplies and fan drawers.

Most of both patches is register description data, and the two sets are largely disjoint. Folding them together would give a single patch of roughly 1700 lines in which two unrelated board descriptions are interleaved, with nothing in the diff to indicate which attribute belongs to which system.

Patch 3 is purely additive: it does not modify or remove a single line introduced by patch 2. The per SKU description struct and the driver_data based DMI dispatch are introduced in patch 2, so patch 3 adds only the new register definitions, the new board description and the DMI entry that selects it.

On the shared "mlxplat" platform device name
============================================

nvsw-host-spc6 registers its platform device as "mlxplat", the same name used by mlx-platform.c. This is deliberate. The mlxreg-io attributes are a long standing userspace ABI documented in Documentation/ABI/stable/sysfs-driver-mlxreg-io, and the management software reads them from /sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/. Keeping the name keeps those paths stable across switch generations, so existing tooling works unchanged on SPC6.

The two drivers cannot collide at runtime: each matches DMI and returns -ENODEV before registering anything, and their DMI tables are disjoint, so on any given system exactly one of them instantiates.
If you would still rather the new driver used a distinct name, we can change it, but it would mean a new sysfs path and a userspace ABI break for the affected systems.

Symbol namespace
================

The two symbols the core exports to its board drivers are exported as EXPORT_SYMBOL_NS_GPL() in the NVSW namespace. They are still global exported symbols, but a module can only use them after importing the namespace with MODULE_IMPORT_NS(), which modpost and the module loader enforce, so the dependency is explicit in each consumer.

Testing
=======

Built on x86_64 against pdx86/for-next with gcc W=1 and with clang 17 W=1 plus CONFIG_WERROR, both warning free, at every patch in the series. Checked with sparse v0.6.5-rc1, smatch and the coccinelle report mode scripts, all clean. checkpatch --strict reports no errors and no checks. Module linkage and the namespace import were verified with modpost and modinfo.

v3->v4
Comments pointed out by Ilpo:
- Stop fanning the matched board description out into module scope. The per SKU data is held in struct nvsw_host_spc6_cfg and reached through the driver_data of the DMI entry, so nvsw_host_init() now matches with dmi_first_match(), hands that description to the platform device as its platform data, and the probe path reads it back from there. A single pointer is carried over instead of ten copies, and the DMI match callback is gone with them.
- Keep the mux parent adapter and the mux client out of module scope too. The client lives in struct nvsw_core, which is already the drvdata, and the adapter is reached through client->adapter where it has to be released. Together with the above this removes every module scope pointer in nvsw-host-spc6 except the platform device itself, and with them the NULL stores on the error paths that the v2 review had already flagged. The board tables remain static.
- Update the ABI Date and KernelVersion in patches 2 and 3, as 7.4 was missed. They now read November 2026 and 7.5.
Issues reported by a local sashiko review:
- Correct the patch 1 commit message, which said the core implements the I2C mux topology. The core only runs the board's mux_init and mux_exit callbacks, and the message and kernel-doc now say so.
- Stop calling set_reg_default from nvsw_core_exit(). It only wrote the probe-time defaults again, so the callback now runs once, from nvsw_core_init().
- Drop the nvsw.h definitions that no driver in the series uses, among them CURRENT_TEMP_RO and SWITCH_IC_QTY, which were missing from nvsw_readable_reg(), NVSW_REG_MIN, NVSW_NR_NONE and 37 masks.
- Drop the unused ASIC2 to ASIC4 health, event and mask registers, which on SPC6 hold thermal and VR signals rather than ASIC health, and say in a comment that 0x2550 packs the health of all four ASICs.
- Drop nvsw_volatile_reg(). With no register cache since v3 it was never consulted, and it listed every readable register, so a cache would have had nothing to hold either. Behaviour is unchanged.
- Stop setting .platform_data on the mux I2C board info in patch 2. i2c-mux-mlxcpld is a platform driver and takes its data from the mux platform devices, so nothing read it. The board info is now const.
- Update the existing asic_reset and asic2_reset ABI entry. On systems which provide asic1_reset to asic4_reset, asic_reset resets all the ASICs at once and the others reset one each.
- Stop creating 32 attributes over reserved bits, or over CPLDs that are not fitted, on the single ASIC liquid cooled systems. They now sit in a table of their own, appended at init to a copy of the common table for the four ASIC system.
- Drop the unused linux/i2c-mux.h include from nvsw-host-spc6.
- Add only the registers patch 3 uses to the nvsw-core register map. Thirteen registers, among them the power supply alarm group and TACHO13 to TACHO20, were made accessible with nothing using them.
- Restore the CPLD fan fault override when the air cooled driver is removed or fails to probe, through a new restore_reg_default core callback paired with set_reg_default. It was cleared at probe and never set again, leaving the fans without fault handling.
- Correct the patch 3 commit message, which said mlx-platform clears the same override. mlx-platform writes a different register, and the override bit, bit 0 of 0x252e, exists only on the air cooled CPLD. The NVSW_FAN_CONTROL_EN_MASK definition now says so.
- Correct the patch 1 commit message and the cover letter, which said the NVSW namespace keeps the core's exports out of the global symbol table. They are still global symbols, and the namespace only makes each user import it with MODULE_IMPORT_NS().
- Shorten the patch 2 commit message on the per SKU description, and describe the host I2C topology the probe relies on, with the CPLD on bus 2 and the deferral until host bus 3 exists.
- Report the bus 3 deferral in nvsw-host-spc6 with dev_err_probe(), and say in the patch 2 commit message that the fixed bus numbers rely on the host I2C controller driver registering first.
- Say in the patch 3 ABI that a write to the psu and fan event files reaches every bit of the register, clearing the bits written as 0 and leaving those written as 1 unchanged.
- Make NVSW_CORE depend on I2C, which REGMAP_I2C and the core itself require, rather than relying on every selecting driver to depend on it.
- Keep the aggregation registers and the event and mask registers of every status register in the nvsw-core register map when dropping the unused registers, since mlxreg-hotplug programs them at probe and would otherwise fail on any board that describes hotplug items.
Additional fixes added by Felix:
- Make the ASIC reset attributes write only in patches 2 and 3, as asic_reset and asic2_reset are in mlx-platform and in the ABI. They were exposed with mode 0644.
- Drop the HI187 SKU, an intermediate system that will not be manufactured.
- Drop the 69 registers that no driver in the series uses from nvsw.h and from the nvsw-core register map, which now holds only the registers the SPC6 driver accesses and those mlxreg-hotplug programs for its status registers.
- Drop the cpu_mctp_ready attribute and its ABI entry from both tables, as the CPLD signal will be removed in future CPLD releases.
- Drop asic_pg_fail from the air cooled table, which the liquid cooled table does not have either.
Other:
- Rebase onto the current platform-drivers-x86 for-next.

On the one finding sashiko.dev reported against v3, the fan drawer LEDs that patch 3 describes: it is valid, and it is now fixed, in the LED tree rather than here. The capability register of these systems reports a count of the fan drawers present rather than a bitmap, so the LED entries carry a slot index and leave the capability bit at zero, which mlxreg_led_config() did not understand. The same description style is used by mlxplat_mlxcpld_xdr_led_data in mlx-platform.c, which has been losing all twenty of its fan LEDs since the table was introduced in v6.16, so the gap belongs to leds-mlxreg. Lee has applied the fix, commit 68a2bfdf7b4d ("leds:
mlxreg: Fix missing fan LEDs on systems reporting a unit count"), currently in for-leds-next and so queued for the same merge window as this series. There is no build or apply dependency between the two and the LED table here is unchanged.

v2->v3
Comments pointed out by Ilpo:
- Return directly from nvsw_core_init() when nvsw_core_mux_topology_init() fails, instead of jumping to a label that only does a return.
Issues reported by the sashiko.dev review, which Ilpo asked us to check:
- Fix the shift for asic2_health..asic4_health. The four ASIC health fields share one register, two bits each, but all four entries carried .bit = 1, so only asic_health was right aligned and the other three reported their field still shifted up. Set .bit to the one based position of each mask's least significant bit.
- Drop nvsw_core_reg_def and the register cache configuration that went with it. The review pointed out that the array was unsorted and that its entries never reached the hardware. Neither register is relevant on SPC6, so the array is removed rather than sorted, which leaves the cache with nothing to hold. This also drops linux/bits.h from nvsw-core.c, whose only user there was the GENMASK in that array. The one default SPC6 does need is written by the board driver instead, see patch 3.
- Make pdb1_pwr_status..pdb4_pwr_status read only. They were exposed with mode 0644 over a register that is not in nvsw_writeable_reg(), so a write returned -EIO. The ABI documentation is updated to match.
- Correct the mode of the air cooled pwr_cycle attribute, which was 0244 instead of 0200.
- Fix the documented polarity of fan_status and psu_status. The CPLD reports fan drawer and power supply presence active low, so bit value 0 means present. For fan_status that is what mlxreg_fan_read() already assumes when it reads the same register through .reg_prsnt, so only the ABI text was wrong. psu_status shares a description block with psu_ac_status and psu_dc_status, which are active high, so the polarity is now stated per attribute.
- Drop the claim that the air cooled system exposes power supply alarm indications from the patch 3 commit message, since no attribute is described over the alarm registers.
Additional fixes added by Felix:
- Describe jtag_enable as the single bit it is. It was given a two bit mask, but only the lower bit is defined in the CPLD register map, so values 2 and 3 were accepted and wrote a reserved bit.
- Drop the aux_pwr_cycle attribute from the air cooled table, as it is not supported on systems with power supply units.
- Drop the shutdown_unlock attribute. It was described over bit 5 of the general purpose register, which the CPLD register map lists as reserved. Thermal shutdown unlock is handled by the BMC on SPC6, so the attribute is removed rather than moved to the right bit.
- Clear the CPLD fan fault override enable bit on air cooled systems, so that the fan speed is left to the software. This is done from the board driver through the set_reg_default callback, which until now had no user.
- Drop NVSW_REG_FU_CAP_OFFSET from nvsw_writeable_reg(). It is read only in hardware and the only attribute over it is 0444, so the entry could never be reached. Found by checking every register in nvsw_writeable_reg() against the CPLD register map; it is the only mismatch.
- Rename the last remaining *_fail label in nvsw-core to err_*, for consistency with the rest of the file.

v1->v2
Comments pointed out by Ilpo:
- Add the direct includes for the macros the two drivers use rather
than relying on them arriving transitively: linux/array_size.h for
ARRAY_SIZE, linux/bits.h for BIT and GENMASK, linux/err.h for IS_ERR
and PTR_ERR and linux/dev_printk.h for the dev_*() helpers, plus
linux/export.h and linux/types.h in the core.
- Remove the redundant NULL assignments from the error paths. The
registration helpers now return into a local variable, so a struct
nvsw_core field is only ever assigned a valid pointer and never an
ERR_PTR, which is what the NULL stores were papering over. 19 of the
23 assignments are gone; the 4 that remain are on the two module
scope pointers in nvsw-host-spc6, which outlive a failed probe.
- Rework the rollback in nvsw_core_platform_init() and nvsw_host_spc6_mux_topology_init() to be positional, and drop the
defensive pointer tests from the matching exit paths, which can no
longer see a partially initialised state.
Additional fixes added by Felix:
- Sort the include blocks in both drivers.
Link to v1: https://lore.kernel.org/platform-driver-x86/[email protected]/
Link to v2: https://lore.kernel.org/platform-driver-x86/[email protected]/
Link to v3: https://lore.kernel.org/platform-driver-x86/[email protected]/

Felix Radensky (3):
platform/mellanox: nvsw-core: Add core driver for Nvidia switches platform/mellanox: nvsw-host-spc6: Add driver for Nvidia SPC6 switches platform/mellanox: nvsw-host-spc6: Add support for SPC6 air cooled
switches

 .../ABI/stable/sysfs-driver-mlxreg-io         |  205 ++-
 drivers/platform/mellanox/Kconfig             |   20 +
 drivers/platform/mellanox/Makefile            |    2 +
 drivers/platform/mellanox/nvsw-core.c         |  391 +++++
 drivers/platform/mellanox/nvsw-host-spc6.c    | 1485 +++++++++++++++++
 drivers/platform/mellanox/nvsw.h              |  202 +++
 6 files changed, 2304 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/mellanox/nvsw-core.c
 create mode 100644 drivers/platform/mellanox/nvsw-host-spc6.c
 create mode 100644 drivers/platform/mellanox/nvsw.h

base-commit: 2268d837dea13a78639fa3dad60472bb67478709

Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/3 platform/mellanox: nvsw-core: Add core driver for Nvidia switches

The Nvidia switch systems expose system control and monitoring through CPLD/FPGA devices. The register layout and the set of mlxreg-* devices built on top of it are common across switch generations, while the description of which devices exist on a given board is not.

Add nvsw-core, which implements the shared part: creation of the register map for the I2C attached CPLD/FPGA, and the registration of the mlxreg-io, mlxreg-hotplug, mlxreg-fan, leds-mlxreg and mlx-wdt platform devices from a board supplied description.

The register map gives access to the registers the board drivers describe. For the status registers that can carry hotplug items, it also covers their event and mask registers, along with the top and low aggregation registers and their masks, since mlxreg-hotplug programs all of them when it probes.

What remains board specific is supplied through optional callbacks, which the core runs at fixed points. set_reg_default writes register defaults once, right after the register map is created and before any device is registered, and restore_reg_default undoes them once the devices are removed, or when initialisation fails after the defaults were written. mux_init and mux_exit create and remove the I2C mux topology, before the mlxreg-* devices are registered and after they are removed, since the mux layout differs between boards.

Board drivers provide a struct nvsw_core describing their hardware and call nvsw_core_init() and nvsw_core_exit(). Both symbols are exported in the NVSW namespace, so consumers must import the NVSW namespace explicitly with MODULE_IMPORT_NS(), which modpost and the module loader enforce.

The core is selected by the board drivers rather than being directly selectable, since it is not useful on its own.

---

Notes:
v3->v4
Issues reported by a local sashiko review:
- Correct the commit message, which said the core implements the I2C mux topology. It only runs the board's mux_init and mux_exit callbacks; the topology itself is created by the board driver. The message now describes the callbacks and when each one runs, and the struct nvsw_core kernel-doc says the same.
- Stop calling set_reg_default from nvsw_core_exit(). Running it at teardown wrote the probe-time defaults again rather than restoring anything, and mlx-platform applies its defaults only at probe. The callback now runs once, from nvsw_core_init(), so board callbacks need not be safe to run twice.
- Add a restore_reg_default callback, paired with set_reg_default the way mux_exit is paired with mux_init. The core runs it from nvsw_core_exit() after the devices and the mux topology are gone, and from the nvsw_core_init() error paths once set_reg_default has succeeded, so a board can undo a default that is only safe while its devices are bound. Patch 3 is its first user.
- Drop nvsw_volatile_reg(). The register map has had no cache since v3, so regmap treats every register as volatile and the table was never consulted. It also listed exactly the registers of nvsw_readable_reg(), so adding a cache back would not have kept a single register in it. With no cache regmap reads every register from the hardware either way, so behaviour is unchanged.
- Drop the definitions in nvsw.h that no driver in the series uses. CURRENT_TEMP_RO and SWITCH_IC_QTY were defined but missing from nvsw_readable_reg(), so an attribute over either would have failed to read. Patch 3 no longer makes them accessible, so the defines go rather than the register map growing. NVSW_REG_MIN, NVSW_NR_NONE and 37 bit masks, mostly interrupt and aggregation masks, are dropped along with them, so the header holds only what nvsw-core and nvsw-host-spc6 use.
- Drop the ASIC2, ASIC3 and ASIC4 health, event and mask register definitions, and their entries in nvsw_readable_reg() and nvsw_writeable_reg(). Nothing used them, and on SPC6 they are not what their names say: 0x2553 to 0x2555 hold the ASIC thermal warning and shutdown signals, and 0x2582 and 0x2585 are combined ASIC3 and ASIC4 status registers on the four ASIC systems and VR alert registers on the air cooled ones. The health fields of all four ASICs are packed, two bits each, into NVSW_REG_ASIC1_HEALTH_OFFSET, which a comment above the ASIC health masks now says.
- Correct the commit message, which said that exporting nvsw_core_init() and nvsw_core_exit() in the NVSW namespace keeps them out of the global symbol table. They are still global exported symbols; the namespace only makes modpost and the module loader require MODULE_IMPORT_NS("NVSW") in each module that uses them, which is what the message now says.
- Make NVSW_CORE depend on I2C. It selects REGMAP_I2C, which depends on I2C, and the core calls devm_regmap_init_i2c() and uses struct i2c_client itself. It was only safe because the one driver selecting it, nvsw-host-spc6, already depends on I2C.
Additional fixes added by Felix:
- Drop the 69 register definitions that no driver in the series uses, and their 110 entries in nvsw_readable_reg() and nvsw_writeable_reg(). They cover the power good, board, health, VR alert, EROT, power button and FRU interrupt groups, the CPLD debug LEDs, UART baud, safe BIOS, PWM control, configuration and capability registers, the comex aggregation registers, MUX0 and MUX2, TACHO11 and TACHO12, and GP4_RO. The register map now holds only what the SPC6 driver accesses, and what mlxreg-hotplug needs for its status registers. The CPLD part number high bytes and the watchdog TLEFT registers stay although no table names them, as mlxreg-io reads them as the second byte of the part number attributes and mlx-wdt accesses them as the high byte of the type 3 timeout and time left.
Issues reported by a local sashiko review, against the above:
- Keep the registers mlxreg-hotplug programs at probe. The first version of the cleanup dropped them too, so mlxreg-hotplug would have failed its first write, to the aggregation mask, on any board setting hotplug_data. The top and low aggregation registers and their masks (0x253a, 0x253b, 0x2540, 0x2541) stay, together with the event and mask registers of the status registers in the map:
ASIC1 health (0x2551, 0x2552), PS_DC_OK (0x2569), fan (0x258a) and leakage (0x25b0, 0x25b1). The commit message says what the map covers.
Other:
- Rebase onto the current platform-drivers-x86 for-next.

v2->v3
Comments pointed out by Ilpo:
- Return directly from nvsw_core_init() when nvsw_core_mux_topology_init() fails, instead of jumping to a label that only does a return.
Issues reported by the sashiko.dev review:
- Drop nvsw_core_reg_def. The review pointed out that it was unsorted and that its entries never reached the hardware. Neither register is relevant on SPC6, so the array is removed rather than fixed, which leaves .cache_type, .reg_defaults, .num_reg_defaults and the regcache_mark_dirty()/regcache_sync() pair with nothing to do.
- As a consequence linux/bits.h is no longer included here. The GENMASK in the dropped array was its only user in this file.
Additional fixes added by Felix:
- Drop NVSW_REG_FU_CAP_OFFSET from nvsw_writeable_reg(). The register is read only in hardware, and the only attribute described over it, jtag_cap, is 0444, so nothing could reach the write path. Found by checking every register in nvsw_writeable_reg() against the CPLD register map; it is the only mismatch.
- Rename the remaining nvsw_core_platform_init_fail label to err_mux_topology_exit, matching the err_* labels used elsewhere in the file.

v1->v2
Comments pointed out by Ilpo:
- Add the direct includes for the macros this file uses instead of relying on them arriving transitively: linux/array_size.h, linux/bits.h, linux/dev_printk.h, linux/err.h, linux/export.h and linux/types.h.
- Return platform_device_register_resndata() and devm_regmap_init_i2c() into a local, so a struct nvsw_core field is only ever assigned a valid pointer and never an ERR_PTR.
- Drop the NULL assignments from the error paths and from nvsw_core_platform_exit(), and make the rollback in nvsw_core_platform_init() positional.
Additional fixes added by Felix:
- Sort the include block.

 drivers/platform/mellanox/Kconfig     |  10 +
 drivers/platform/mellanox/Makefile    |   1 +
 drivers/platform/mellanox/nvsw-core.c | 375 ++++++++++++++++++++++++++
 drivers/platform/mellanox/nvsw.h      | 187 +++++++++++++
 4 files changed, 573 insertions(+)
 create mode 100644 drivers/platform/mellanox/nvsw-core.c
 create mode 100644 drivers/platform/mellanox/nvsw.h
drivers/platform/mellanox/Kconfig +10 -0
index e3afbe62c7f6..34deba4670c2 100644
@@ -105,6 +105,16 @@ config MLXBF_PMC
 	  to performance monitoring counters within various blocks in the
 	  Mellanox BlueField SoC via a sysfs interface.
 
+config NVSW_CORE
+	tristate
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Shared register map setup and platform device creation for the Nvidia
+	  switch CPLD/FPGA drivers. This symbol has no prompt of its own and is
+	  selected by the drivers that need it, which are built as separate
+	  modules against it.
+
 config NVSW_SN2201
 	tristate "Nvidia SN2201 platform driver support"
 	depends on HWMON && I2C
drivers/platform/mellanox/Makefile +1 -0
index e86723b44c2e..22e40759dd49 100644
@@ -11,4 +11,5 @@ obj-$(CONFIG_MLXREG_DPU)	+= mlxreg-dpu.o
 obj-$(CONFIG_MLXREG_HOTPLUG)	+= mlxreg-hotplug.o
 obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
 obj-$(CONFIG_MLXREG_LC) += mlxreg-lc.o
+obj-$(CONFIG_NVSW_CORE) += nvsw-core.o
 obj-$(CONFIG_NVSW_SN2201) += nvsw-sn2201.o
drivers/platform/mellanox/nvsw-core.c new file +375 -0

375 lines not on this page · raw message

drivers/platform/mellanox/nvsw.h new file +187 -0

187 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/3 platform/mellanox: nvsw-host-spc6: Add driver for Nvidia SPC6 switches

In reply to Felix Radensky

The driver allows system control and monitoring of Nvidia liquid cooled Ethernet switches based on the SPC6 ASIC through CPLD/FPGA devices from the host CPU.

This control includes:
- Various resets handling through sysfs attributes.
- Reset cause reports through sysfs attributes.
- Mux attributes for hw components selection.
- General purpose registers attributes.
- LED control.
- Watchdog control.

These systems carry no power supplies or fan drawers of their own, so the board description covers coolant leakage detection and power distribution board status instead of power supply and fan control.

The driver describes the SPC6 hardware and leaves the register map and platform device creation to nvsw-core.

The per SKU description is taken from the driver_data of the matching DMI entry and passed to the platform device as its platform data.

The driver relies on the host I2C topology of these systems. The host has four I2C controllers, which provide buses 0 to 3, and the CPLD that implements the mux sits at address 0x33 on bus 2. The host buses and the mux channels are both numbered dynamically, so whichever adapter registers first takes the lowest free number. The probe therefore returns -EPROBE_DEFER until bus 3 exists, since a mux channel registered before the last host controller would take bus 3, and the host bus and the mux channels would be numbered differently from boot to boot. The reason for the deferral is reported through dev_err_probe(). The fixed numbers rely on the host controller driver registering its buses before any other I2C bus driver, which the system software of these switches ensures, in the same way as nvsw-sn2201 relies on a fixed main mux bus number.

The four ASIC system, HI188, has CPLDs, ASICs, leakage sensors and power distribution board status bits that the single ASIC HI183 and HI193 lack, where the same registers are reserved or hold other signals. The register access entries for them are kept in a table of their own, which nvsw_host_init() appends to a copy of the common liquid cooled table for the four ASIC system. The single ASIC systems use the common table alone, so they get no attribute over a reserved bit or a CPLD that is not fitted, the common entries are not duplicated, and both counts come from ARRAY_SIZE().

Document the register access attributes which are not yet covered by Documentation/ABI/stable/sysfs-driver-mlxreg-io. Update the existing asic_reset and asic2_reset entry as well: on these systems asic_reset resets all the ASICs at once while asic1_reset to asic4_reset reset the individual ones. The ASIC reset files are write only, as on the other systems.

---

Notes:
v3->v4
Comments pointed out by Ilpo:
- Carry the matched board description over as a single pointer. The per SKU data is held in struct nvsw_host_spc6_cfg and reached through the driver_data of the DMI entry, so nvsw_host_init() now matches with dmi_first_match(), hands that description to the platform device as its platform data, and the probe path reads it back from there. The eight module scope variables it used to be copied into are gone, and so is the DMI match callback.
- Keep the mux parent adapter and the mux client out of module scope as well. The client is stored in struct nvsw_core, which is already the drvdata, and the adapter is reached through client->adapter where it has to be released, so neither needs a module scope pointer and neither has to be cleared on the error paths. Apart from the static board tables, the only module scope variable left is the platform device itself.
- Update the ABI Date and KernelVersion, as 7.4 was missed. They now read November 2026 and 7.5.
Issues reported by a local sashiko review:
- Stop setting .platform_data on the mux board info in probe, and make nvsw_host_spc6_mux_brdinfo const. i2c-mux-mlxcpld is a platform driver and takes its data from the mux platform devices, which already carry it, so nothing read the I2C client's copy.
- Update the existing asic_reset and asic2_reset ABI entry, which left open which file resets the first ASIC. On systems which provide asic1_reset to asic4_reset, asic_reset resets all the ASICs at once and the others reset one each. The asic1_reset, asic3_reset and asic4_reset entry now says the same, and no longer describes writing 0 as releasing the reset, since the CPLD generates the reset as a pulse.
- Stop creating attributes over reserved bits on the single ASIC systems. HI183 and HI193 shared the liquid cooled table with the four ASIC HI188, so they got asic1_reset to asic4_reset, asic2_health to asic4_health, pdb1_pwr_status to pdb4_pwr_status and leakage3 to leakage5 over bits their CPLD reserves, and cpld5 to cpld10 version and part number files for CPLDs they do not have, some over registers holding watchdog and presence signals. These 32 entries are now in a table of their own, which nvsw_host_init() appends to a copy of the common liquid cooled table for the four ASIC system, and the single ASIC systems use the common table alone. Both counts come from ARRAY_SIZE(), so no split point is maintained by hand. The ABI text says
asic1_reset, asic3_reset and asic4_reset are not present on single ASIC systems, instead of describing their bits as reserved.
- Shorten the commit message paragraph on the per SKU board description, which repeated what the code shows and claimed that no board state is kept at module scope, while the board tables are static and nvsw-core stores the register map into them. Describe the host I2C topology the probe relies on: the CPLD at 0x33 on bus 2, and the deferral until bus 3 exists, which keeps a dynamically numbered mux channel from taking that bus number before the last host controller registers.
- Report the deferral until bus 3 exists with dev_err_probe(), so that the reason is recorded in devices_deferred rather than only in a debug message, and say in the commit message that the fixed bus numbers rely on the host controller driver registering its buses before any other I2C bus driver.
- Drop the linux/i2c-mux.h include. The mux is created as an i2c-mux-mlxcpld platform device, and nothing declared in that header is used here.
Additional fixes added by Felix:
- Make asic_reset and asic1_reset to asic4_reset write only. They were exposed with mode 0644, while asic_reset and asic2_reset are write only in mlx-platform and documented as such, so the same attribute would have behaved differently depending on the driver providing it.
- Drop the HI187 DMI entry. HI187 is an intermediate system that will not be manufactured.
- Drop the cpu_mctp_ready attribute and its ABI entry. The CPLD signal behind it is deprecated and will be removed in future CPLD releases.

v2->v3
Additional fixes added by Felix:
- Describe jtag_enable as the single bit it is. It was given a two bit mask, but only the lower bit is defined in the CPLD register map, so values 2 and 3 were accepted and wrote a reserved bit.
- Drop the shutdown_unlock attribute. It was described over bit 5 of the general purpose register, which the CPLD register map lists as reserved. Thermal shutdown unlock is handled by the BMC on SPC6, so the attribute is removed rather than moved.

Issues reported by the sashiko.dev review:
- Fix the shift for asic2_health, asic3_health and asic4_health. The four health fields share ASIC_HEALTH_INT_Stat_REG1, two bits each, but all four entries carried .bit = 1, so only asic_health was right-aligned. The other three reported their field still shifted up, giving 0, 8 or 12 for asic2_health instead of the documented 0, 2 or 3, and likewise for asic3_health and asic4_health. Set .bit to the one-based position of each mask's least significant bit.
- Make pdb1_pwr_status..pdb4_pwr_status read only. They were exposed with mode 0644 over NVSW_REG_PS_DC_OK_OFFSET, which is not listed in nvsw_writeable_reg(), so any write returned -EIO. The ABI documentation is updated to match the description, which only defines read semantics.

v1->v2
Comments pointed out by Ilpo:
- Add the direct includes for the macros this file uses instead of relying on them arriving transitively: linux/array_size.h, linux/bits.h, linux/dev_printk.h and linux/err.h.
- Register into a local in nvsw_host_spc6_mux_topology_init() and in the probe path, publishing the pointer only once it is known good, so the NULL assignments that were hiding an ERR_PTR are gone. The only ones left are on nvsw_host_mux_i2c_client and nvsw_host_mux_i2c_adapter, which are module scope and so outlive a failed probe.
- Drop the per-entry pointer tests from nvsw_host_spc6_mux_topology_exit(), since init now rolls back fully on failure.
Additional fixes added by Felix:
- Sort the include block.

 .../ABI/stable/sysfs-driver-mlxreg-io         | 159 +++-
 drivers/platform/mellanox/Kconfig             |  10 +
 drivers/platform/mellanox/Makefile            |   1 +
 drivers/platform/mellanox/nvsw-host-spc6.c    | 885 ++++++++++++++++++
 4 files changed, 1054 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/mellanox/nvsw-host-spc6.c
Documentation/ABI/stable/sysfs-driver-mlxreg-io +158 -1
index f59461111221..8d59181d7196 100644
@@ -518,7 +518,13 @@ What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic2_reset
 Date:		July 2022
 KernelVersion:	5.20
 Contact:	Vadim Pasternak <[email protected]>
-Description:	These files allow to each of ASICs by writing 1.
+Description:	These files allow to reset the ASICs by writing 1.
+
+		On systems which do not provide asic1_reset, asic_reset
+		resets the first ASIC and asic2_reset resets the second
+		one. On systems which provide asic1_reset, asic3_reset and
+		asic4_reset, asic_reset resets all the ASICs at once, and
+		asic1_reset to asic4_reset reset the individual ASICs.
 
 		The files are write only.
 
@@ -813,3 +819,154 @@ Description:	These files show status of Unified Fabric Manager upgrade.
 		state. 0 - means upgrade is done, 1 - otherwise.
 
 		The file is read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld6_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld6_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld6_version_min
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld7_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld7_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld7_version_min
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld8_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld8_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld8_version_min
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld9_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld9_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld9_version_min
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld10_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld10_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld10_version_min
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show with which CPLD part numbers, version and minor
+		versions have been burned the 6-th to the 10-th CPLD devices
+		equipped on a system.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic1_reset
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic3_reset
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic4_reset
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files allow to reset the first, the third and the fourth
+		ASIC individually on a multi-ASIC system, while asic2_reset
+		resets the second one and asic_reset resets all of them at
+		once. They are not present on systems with a single ASIC,
+		where asic_reset resets that ASIC.
+
+		The files are write only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic3_health
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic4_health
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show health status of the third and the fourth ASIC
+		on a multi-ASIC system. The possible values are:
+		0 - health failed, 2 - health OK, 3 - ASIC in booting state.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage1
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage2
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage3
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage4
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage5
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show the status of the liquid leakage sensors
+		equipped on a liquid cooled system. Value 1 means that a leak
+		has been detected by the related sensor, 0 - otherwise. The
+		number of sensors, and so of these files, depends on the
+		system type.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/pdb1_pwr_status
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/pdb2_pwr_status
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/pdb3_pwr_status
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/pdb4_pwr_status
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show the power status of the power distribution
+		boards equipped on a system. Value 1 means that the related
+		board is powered and operational, 0 - otherwise.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/graceful_pwr_off
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file allows to initiate a graceful power off sequence and
+		shows whether such a sequence is in progress. Writing 1 starts
+		the sequence.
+
+		The file is read/write.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpu_shutdown_req
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file shows a shutdown request raised towards the CPU.
+		Value 1 means that a shutdown of the system has been
+		requested, 0 - otherwise.
+
+		The file is read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpu_power_off_ready
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file allows the CPU to report that it has completed its
+		shutdown procedures and that the system can be powered down.
+		Writing 1 signals readiness for power off.
+
+		The file is read/write.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/bmc_to_cpu_ctrl
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file selects the owner of the shared I2C bus between the
+		Board Management Controller and the CPU. Value 0 selects the
+		CPU as the owner, 1 selects the Board Management Controller.
+
+		The file is read/write.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/uart_sel
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file selects which of the system consumers is connected to
+		the shared UART console.
+
+		The file is read/write.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/aux_pwr_cycle
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file allows to power cycle the auxiliary power domain of
+		the system. Writing 1 performs the power cycle.
+
+		The file is write only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/reset_aux_pwr_or_reload
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/reset_cpu_thermal
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/reset_main_51v
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/reset_mgmt_pwr
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show the system reset cause. Respectively:
+		auxiliary power failure or CPLD field upgrade, CPU thermal
+		shutdown, management board 5.1V rail failure and management
+		board power failure. Value 1 means the related event caused
+		the last reset.
+
+		The files are read only.
drivers/platform/mellanox/Kconfig +10 -0
index 34deba4670c2..f17497ca86f9 100644
@@ -115,6 +115,16 @@ config NVSW_CORE
 	  selected by the drivers that need it, which are built as separate
 	  modules against it.
 
+config NVSW_HOST_SPC6
+	tristate "Nvidia SPC6 host CPLD/FPGA Hardware Control and Monitoring"
+	depends on DMI && HWMON && I2C
+	select NVSW_CORE
+	help
+	  Say Y here to include support for the FPGA/CPLD logic by host CPU
+	  equipped on Nvidia SPC6 ethernet switches.
+	  This driver can also be built as a module. If so the module
+	  will be called nvsw-host-spc6.
+
 config NVSW_SN2201
 	tristate "Nvidia SN2201 platform driver support"
 	depends on HWMON && I2C
drivers/platform/mellanox/Makefile +1 -0
index 22e40759dd49..a959d07f1787 100644
@@ -12,4 +12,5 @@ obj-$(CONFIG_MLXREG_HOTPLUG)	+= mlxreg-hotplug.o
 obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
 obj-$(CONFIG_MLXREG_LC) += mlxreg-lc.o
 obj-$(CONFIG_NVSW_CORE) += nvsw-core.o
+obj-$(CONFIG_NVSW_HOST_SPC6) += nvsw-host-spc6.o
 obj-$(CONFIG_NVSW_SN2201) += nvsw-sn2201.o
drivers/platform/mellanox/nvsw-host-spc6.c new file +885 -0

885 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#3 lore raw

Re: [PATCH v4 2/3] platform/mellanox: nvsw-host-spc6: Add driver for Nvidia SPC6 switches

Quoted 431 lines · Felix Radensky

The driver allows system control and monitoring of Nvidia liquid cooled Ethernet switches based on the SPC6 ASIC through CPLD/FPGA devices from the host CPU.

This control includes:
- Various resets handling through sysfs attributes.
- Reset cause reports through sysfs attributes.
- Mux attributes for hw components selection.
- General purpose registers attributes.
- LED control.
- Watchdog control.

These systems carry no power supplies or fan drawers of their own, so the board description covers coolant leakage detection and power distribution board status instead of power supply and fan control.

The driver describes the SPC6 hardware and leaves the register map and platform device creation to nvsw-core.

The per SKU description is taken from the driver_data of the matching DMI entry and passed to the platform device as its platform data.

The driver relies on the host I2C topology of these systems. The host has four I2C controllers, which provide buses 0 to 3, and the CPLD that implements the mux sits at address 0x33 on bus 2. The host buses and the mux channels are both numbered dynamically, so whichever adapter registers first takes the lowest free number. The probe therefore returns -EPROBE_DEFER until bus 3 exists, since a mux channel registered before the last host controller would take bus 3, and the host bus and the mux channels would be numbered differently from boot to boot. The reason for the deferral is reported through dev_err_probe(). The fixed numbers rely on the host controller driver registering its buses before any other I2C bus driver, which the system software of these switches ensures, in the same way as nvsw-sn2201 relies on a fixed main mux bus number.

The four ASIC system, HI188, has CPLDs, ASICs, leakage sensors and power distribution board status bits that the single ASIC HI183 and HI193 lack, where the same registers are reserved or hold other signals. The register access entries for them are kept in a table of their own, which nvsw_host_init() appends to a copy of the common liquid cooled table for the four ASIC system. The single ASIC systems use the common table alone, so they get no attribute over a reserved bit or a CPLD that is not fitted, the common entries are not duplicated, and both counts come from ARRAY_SIZE().

Document the register access attributes which are not yet covered by Documentation/ABI/stable/sysfs-driver-mlxreg-io. Update the existing asic_reset and asic2_reset entry as well: on these systems asic_reset resets all the ASICs at once while asic1_reset to asic4_reset reset the individual ones. The ASIC reset files are write only, as on the other systems.

---

Notes:
v3->v4
Comments pointed out by Ilpo:
- Carry the matched board description over as a single pointer. The per SKU data is held in struct nvsw_host_spc6_cfg and reached through the driver_data of the DMI entry, so nvsw_host_init() now matches with dmi_first_match(), hands that description to the platform device as its platform data, and the probe path reads it back from there. The eight module scope variables it used to be copied into are gone, and so is the DMI match callback.
- Keep the mux parent adapter and the mux client out of module scope as well. The client is stored in struct nvsw_core, which is already the drvdata, and the adapter is reached through client->adapter where it has to be released, so neither needs a module scope pointer and neither has to be cleared on the error paths. Apart from the static board tables, the only module scope variable left is the platform device itself.
- Update the ABI Date and KernelVersion, as 7.4 was missed. They now read November 2026 and 7.5.
Issues reported by a local sashiko review:
- Stop setting .platform_data on the mux board info in probe, and make nvsw_host_spc6_mux_brdinfo const. i2c-mux-mlxcpld is a platform driver and takes its data from the mux platform devices, which already carry it, so nothing read the I2C client's copy.
- Update the existing asic_reset and asic2_reset ABI entry, which left open which file resets the first ASIC. On systems which provide asic1_reset to asic4_reset, asic_reset resets all the ASICs at once and the others reset one each. The asic1_reset, asic3_reset and asic4_reset entry now says the same, and no longer describes writing 0 as releasing the reset, since the CPLD generates the reset as a pulse.
- Stop creating attributes over reserved bits on the single ASIC systems. HI183 and HI193 shared the liquid cooled table with the four ASIC HI188, so they got asic1_reset to asic4_reset, asic2_health to asic4_health, pdb1_pwr_status to pdb4_pwr_status and leakage3 to leakage5 over bits their CPLD reserves, and cpld5 to cpld10 version and part number files for CPLDs they do not have, some over registers holding watchdog and presence signals. These 32 entries are now in a table of their own, which nvsw_host_init() appends to a copy of the common liquid cooled table for the four ASIC system, and the single ASIC systems use the common table alone. Both counts come from ARRAY_SIZE(), so no split point is maintained by hand. The ABI text says
asic1_reset, asic3_reset and asic4_reset are not present on single ASIC systems, instead of describing their bits as reserved.
- Shorten the commit message paragraph on the per SKU board description, which repeated what the code shows and claimed that no board state is kept at module scope, while the board tables are static and nvsw-core stores the register map into them. Describe the host I2C topology the probe relies on: the CPLD at 0x33 on bus 2, and the deferral until bus 3 exists, which keeps a dynamically numbered mux channel from taking that bus number before the last host controller registers.
- Report the deferral until bus 3 exists with dev_err_probe(), so that the reason is recorded in devices_deferred rather than only in a debug message, and say in the commit message that the fixed bus numbers rely on the host controller driver registering its buses before any other I2C bus driver.
- Drop the linux/i2c-mux.h include. The mux is created as an i2c-mux-mlxcpld platform device, and nothing declared in that header is used here.
Additional fixes added by Felix:
- Make asic_reset and asic1_reset to asic4_reset write only. They were exposed with mode 0644, while asic_reset and asic2_reset are write only in mlx-platform and documented as such, so the same attribute would have behaved differently depending on the driver providing it.
- Drop the HI187 DMI entry. HI187 is an intermediate system that will not be manufactured.
- Drop the cpu_mctp_ready attribute and its ABI entry. The CPLD signal behind it is deprecated and will be removed in future CPLD releases.

v2->v3
Additional fixes added by Felix:
- Describe jtag_enable as the single bit it is. It was given a two bit mask, but only the lower bit is defined in the CPLD register map, so values 2 and 3 were accepted and wrote a reserved bit.
- Drop the shutdown_unlock attribute. It was described over bit 5 of the general purpose register, which the CPLD register map lists as reserved. Thermal shutdown unlock is handled by the BMC on SPC6, so the attribute is removed rather than moved.

Issues reported by the sashiko.dev review:
- Fix the shift for asic2_health, asic3_health and asic4_health. The four health fields share ASIC_HEALTH_INT_Stat_REG1, two bits each, but all four entries carried .bit = 1, so only asic_health was right-aligned. The other three reported their field still shifted up, giving 0, 8 or 12 for asic2_health instead of the documented 0, 2 or 3, and likewise for asic3_health and asic4_health. Set .bit to the one-based position of each mask's least significant bit.
- Make pdb1_pwr_status..pdb4_pwr_status read only. They were exposed with mode 0644 over NVSW_REG_PS_DC_OK_OFFSET, which is not listed in nvsw_writeable_reg(), so any write returned -EIO. The ABI documentation is updated to match the description, which only defines read semantics.

v1->v2
Comments pointed out by Ilpo:
- Add the direct includes for the macros this file uses instead of relying on them arriving transitively: linux/array_size.h, linux/bits.h, linux/dev_printk.h and linux/err.h.
- Register into a local in nvsw_host_spc6_mux_topology_init() and in the probe path, publishing the pointer only once it is known good, so the NULL assignments that were hiding an ERR_PTR are gone. The only ones left are on nvsw_host_mux_i2c_client and nvsw_host_mux_i2c_adapter, which are module scope and so outlive a failed probe.
- Drop the per-entry pointer tests from nvsw_host_spc6_mux_topology_exit(), since init now rolls back fully on failure.
Additional fixes added by Felix:
- Sort the include block.

 .../ABI/stable/sysfs-driver-mlxreg-io         | 159 +++-
 drivers/platform/mellanox/Kconfig             |  10 +
 drivers/platform/mellanox/Makefile            |   1 +
 drivers/platform/mellanox/nvsw-host-spc6.c    | 885 ++++++++++++++++++
 4 files changed, 1054 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/mellanox/nvsw-host-spc6.c
Documentation/ABI/stable/sysfs-driver-mlxreg-io +158 -1
index f59461111221..8d59181d7196 100644
@@ -518,7 +518,13 @@ What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic2_reset
 Date:		July 2022
 KernelVersion:	5.20
 Contact:	Vadim Pasternak <[email protected]>
-Description:	These files allow to each of ASICs by writing 1.
+Description:	These files allow to reset the ASICs by writing 1.
+
+		On systems which do not provide asic1_reset, asic_reset
+		resets the first ASIC and asic2_reset resets the second
+		one. On systems which provide asic1_reset, asic3_reset and
+		asic4_reset, asic_reset resets all the ASICs at once, and
+		asic1_reset to asic4_reset reset the individual ASICs.
 
 		The files are write only.
 
@@ -813,3 +819,154 @@ Description:	These files show status of Unified Fabric Manager upgrade.
 		state. 0 - means upgrade is done, 1 - otherwise.
 
 		The file is read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld6_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld6_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld6_version_min
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld7_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld7_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld7_version_min
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld8_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld8_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld8_version_min
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld9_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld9_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld9_version_min
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld10_pn
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld10_version
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpld10_version_min
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show with which CPLD part numbers, version and minor
+		versions have been burned the 6-th to the 10-th CPLD devices
+		equipped on a system.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic1_reset
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic3_reset
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic4_reset
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files allow to reset the first, the third and the fourth
+		ASIC individually on a multi-ASIC system, while asic2_reset
+		resets the second one and asic_reset resets all of them at
+		once. They are not present on systems with a single ASIC,
+		where asic_reset resets that ASIC.
+
+		The files are write only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic3_health
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/asic4_health
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show health status of the third and the fourth ASIC
+		on a multi-ASIC system. The possible values are:
+		0 - health failed, 2 - health OK, 3 - ASIC in booting state.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage1
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage2
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage3
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage4
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/leakage5
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show the status of the liquid leakage sensors
+		equipped on a liquid cooled system. Value 1 means that a leak
+		has been detected by the related sensor, 0 - otherwise. The
+		number of sensors, and so of these files, depends on the
+		system type.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/pdb1_pwr_status
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/pdb2_pwr_status
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/pdb3_pwr_status
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/pdb4_pwr_status
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show the power status of the power distribution
+		boards equipped on a system. Value 1 means that the related
+		board is powered and operational, 0 - otherwise.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/graceful_pwr_off
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file allows to initiate a graceful power off sequence and
+		shows whether such a sequence is in progress. Writing 1 starts
+		the sequence.
+
+		The file is read/write.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpu_shutdown_req
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file shows a shutdown request raised towards the CPU.
+		Value 1 means that a shutdown of the system has been
+		requested, 0 - otherwise.
+
+		The file is read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/cpu_power_off_ready
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file allows the CPU to report that it has completed its
+		shutdown procedures and that the system can be powered down.
+		Writing 1 signals readiness for power off.
+
+		The file is read/write.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/bmc_to_cpu_ctrl
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file selects the owner of the shared I2C bus between the
+		Board Management Controller and the CPU. Value 0 selects the
+		CPU as the owner, 1 selects the Board Management Controller.
+
+		The file is read/write.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/uart_sel
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file selects which of the system consumers is connected to
+		the shared UART console.
+
+		The file is read/write.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/aux_pwr_cycle
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file allows to power cycle the auxiliary power domain of
+		the system. Writing 1 performs the power cycle.
+
+		The file is write only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/reset_aux_pwr_or_reload
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/reset_cpu_thermal
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/reset_main_51v
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/reset_mgmt_pwr
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show the system reset cause. Respectively:
+		auxiliary power failure or CPLD field upgrade, CPU thermal
+		shutdown, management board 5.1V rail failure and management
+		board power failure. Value 1 means the related event caused
+		the last reset.
+
+		The files are read only.
drivers/platform/mellanox/Kconfig +10 -0
index 34deba4670c2..f17497ca86f9 100644
@@ -115,6 +115,16 @@ config NVSW_CORE
 	  selected by the drivers that need it, which are built as separate
 	  modules against it.
 
+config NVSW_HOST_SPC6
+	tristate "Nvidia SPC6 host CPLD/FPGA Hardware Control and Monitoring"
+	depends on DMI && HWMON && I2C
+	select NVSW_CORE
+	help
+	  Say Y here to include support for the FPGA/CPLD logic by host CPU
+	  equipped on Nvidia SPC6 ethernet switches.
+	  This driver can also be built as a module. If so the module
+	  will be called nvsw-host-spc6.
+
 config NVSW_SN2201
 	tristate "Nvidia SN2201 platform driver support"
 	depends on HWMON && I2C
drivers/platform/mellanox/Makefile +1 -0
index 22e40759dd49..a959d07f1787 100644
@@ -12,4 +12,5 @@ obj-$(CONFIG_MLXREG_HOTPLUG)	+= mlxreg-hotplug.o
 obj-$(CONFIG_MLXREG_IO) += mlxreg-io.o
 obj-$(CONFIG_MLXREG_LC) += mlxreg-lc.o
 obj-$(CONFIG_NVSW_CORE) += nvsw-core.o
+obj-$(CONFIG_NVSW_HOST_SPC6) += nvsw-host-spc6.o
 obj-$(CONFIG_NVSW_SN2201) += nvsw-sn2201.o
drivers/platform/mellanox/nvsw-host-spc6.c new file +42 -0
new file mode 100644
index 000000000000..a3ed8dde9403
@@ -0,0 +1,885 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+/*
+ * Nvidia SPC6 host platform driver
+ *
+ * Copyright (C) 2025-2026 Nvidia Technologies Ltd.
+ */
+
+#include <linux/array_size.h>
+#include <linux/bits.h>
+#include <linux/dev_printk.h>
+#include <linux/device.h>
+#include <linux/dmi.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/platform_data/mlxcpld.h>
+#include <linux/platform_data/mlxreg.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/string.h>
+
+#include "nvsw.h"
+
+#define NVSW_HOST_DEVICE_NAME	"mlxplat"
+
+/* Bus number of mux parent device */
+#define NVSW_I2C_MUX_PARENT_BUS_NR	2
+
+/* Bus number of the last host I2C bus */
+#define NVSW_I2C_LAST_HOST_BUS_NR	3
+
+/**
+ * struct nvsw_host_spc6_cfg - per SKU board description
+ * @regs_io: register access platform data;
+ * @led: led platform data;
+ */
+struct nvsw_host_spc6_cfg {
+	struct mlxreg_core_platform_data *regs_io;
+	struct mlxreg_core_platform_data *led;
+};
+
+/* Platform mux channels */

drivers/platform/mellanox/nvsw-host-spc6.c line 52

Quoted 10 lines
drivers/platform/mellanox/nvsw-host-spc6.c new file +10 -0
+static int nvsw_host_spc6_mux_channels[] = {
+	1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+	18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+	33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+	48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+	63, 64, 65, 66, 67,
+};
+
+/* Platform mux data */
+static struct mlxcpld_mux_plat_data nvsw_host_spc6_mux_data[] = {

Can this be const?

I suggest you generally miss other consts as well because lots of stuff looks just information which is not expected to be mutated.

Quoted 797 lines
drivers/platform/mellanox/nvsw-host-spc6.c new file +797 -0
+	{
+		.chan_ids = nvsw_host_spc6_mux_channels,
+		.num_adaps = ARRAY_SIZE(nvsw_host_spc6_mux_channels),
+		.sel_reg_addr = NVSW_REG_MUX1_OFFSET,
+		.reg_size = 2,
+	},
+};
+
+/* Platform mux board info */
+static const struct i2c_board_info nvsw_host_spc6_mux_brdinfo = {
+	I2C_BOARD_INFO("i2c-mux-mlxcpld", 0x33),
+};
+
+static struct platform_device *nvsw_host_dev;
+
+/* Platform register access data for liquid cooled system */
+static struct mlxreg_core_data nvsw_host_spc6_lc_regs_io_data[] = {
+	{
+		.label = "cpld1_version",
+		.reg = NVSW_REG_CPLD1_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld2_version",
+		.reg = NVSW_REG_CPLD2_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld3_version",
+		.reg = NVSW_REG_CPLD3_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld4_version",
+		.reg = NVSW_REG_CPLD4_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld1_pn",
+		.reg = NVSW_REG_CPLD1_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld2_pn",
+		.reg = NVSW_REG_CPLD2_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld3_pn",
+		.reg = NVSW_REG_CPLD3_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld4_pn",
+		.reg = NVSW_REG_CPLD4_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld1_version_min",
+		.reg = NVSW_REG_CPLD1_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld2_version_min",
+		.reg = NVSW_REG_CPLD2_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld3_version_min",
+		.reg = NVSW_REG_CPLD3_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld4_version_min",
+		.reg = NVSW_REG_CPLD4_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "pwr_converter_prog_en",
+		.reg = NVSW_REG_GP7_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(0),
+		.mode = 0644,
+	},
+	{
+		.label = "graceful_pwr_off",
+		.reg = NVSW_REG_GP7_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(3),
+		.mode = 0644,
+	},
+	{
+		.label = "cpu_shutdown_req",
+		.reg = NVSW_REG_GP0_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(2),
+		.mode = 0444,
+	},
+	{
+		.label = "vpd_wp",
+		.reg = NVSW_REG_GP0_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(3),
+		.mode = 0644,
+		.secured = 1,
+	},
+	{
+		.label = "pcie_asic_reset_dis",
+		.reg = NVSW_REG_GP0_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(4),
+		.mode = 0644,
+	},
+	{
+		.label = "cpu_power_off_ready",
+		.reg = NVSW_REG_GP0_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(6),
+		.mode = 0644,
+	},
+	{
+		.label = "pwr_cycle",
+		.reg = NVSW_REG_GP1_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(2),
+		.mode = 0200,
+	},
+	{
+		.label = "pwr_down",
+		.reg = NVSW_REG_GP1_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(3),
+		.mode = 0200,
+	},
+	{
+		.label = "aux_pwr_cycle",
+		.reg = NVSW_REG_GP1_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(4),
+		.mode = 0200,
+	},
+	{
+		.label = "bmc_to_cpu_ctrl",
+		.reg = NVSW_REG_GP1_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(5),
+		.mode = 0644,
+	},
+	{
+		.label = "uart_sel",
+		.reg = NVSW_REG_GP1_OFFSET,
+		.mask = NVSW_UART_SEL_MASK,
+		.bit = 7,
+		.mode = 0644,
+	},
+	{
+		.label = "leakage1",
+		.reg = NVSW_REG_LEAK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(0),
+		.mode = 0444,
+	},
+	{
+		.label = "leakage2",
+		.reg = NVSW_REG_LEAK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(1),
+		.mode = 0444,
+	},
+	{
+		.label = "asic_reset",
+		.reg = NVSW_REG_RESET_GP2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(3),
+		.mode = 0200,
+	},
+	{
+		.label = "reset_long_pb",
+		.reg = NVSW_REG_RESET_CAUSE_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(0),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_short_pb",
+		.reg = NVSW_REG_RESET_CAUSE_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(1),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_aux_pwr_or_reload",
+		.reg = NVSW_REG_RESET_CAUSE_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(2),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_swb_dc_dc_pwr_fail",
+		.reg = NVSW_REG_RESET_CAUSE_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(3),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_platform",
+		.reg = NVSW_REG_RESET_CAUSE_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(4),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_swb_wd",
+		.reg = NVSW_REG_RESET_CAUSE_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(6),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_asic_thermal",
+		.reg = NVSW_REG_RESET_CAUSE_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(7),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_soc",
+		.reg = NVSW_REG_RESET_CAUSE1_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(5),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_system",
+		.reg = NVSW_REG_RESET_CAUSE2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(1),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_sw_pwr_off",
+		.reg = NVSW_REG_RESET_CAUSE2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(2),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_cpu_thermal",
+		.reg = NVSW_REG_RESET_CAUSE2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(3),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_pwr_converter_fail",
+		.reg = NVSW_REG_RESET_CAUSE2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(5),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_main_51v",
+		.reg = NVSW_REG_RESET_CAUSE2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(6),
+		.mode = 0444,
+	},
+	{
+		.label = "reset_mgmt_pwr",
+		.reg = NVSW_REG_RESET_CAUSE2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(7),
+		.mode = 0444,
+	},
+	{
+		.label = "jtag_cap",
+		.reg = NVSW_REG_FU_CAP_OFFSET,
+		.mask = NVSW_FU_CAP_MASK,
+		.bit = 1,
+		.mode = 0444,
+	},
+	{
+		.label = "jtag_enable",
+		.reg = NVSW_REG_FIELD_UPGRADE,
+		.mask = GENMASK(7, 0) & ~BIT(0),
+		.mode = 0644,
+	},
+	{
+		.label = "asic_health",
+		.reg = NVSW_REG_ASIC1_HEALTH_OFFSET,
+		.mask = NVSW_ASIC_MASK,
+		.bit = 1,
+		.mode = 0444,
+	},
+	{
+		.label = "spi_chnl_select",
+		.reg = NVSW_REG_SPI_CHNL_SELECT,
+		.mask = GENMASK(7, 0),
+		.bit = 1,
+		.mode = 0644,
+	},
+};
+
+/*
+ * Register access data that exists on the liquid cooled four ASIC systems
+ * only, following nvsw_host_spc6_lc_regs_io_data. On the single ASIC ones
+ * the CPLDs it reports are not fitted, and the bits it accesses are reserved
+ * or hold other signals.
+ */
+static const struct mlxreg_core_data nvsw_host_spc6_lc_4asic_only_regs_io_data[] __initconst = {
+	{
+		.label = "cpld5_version",
+		.reg = NVSW_REG_CPLD5_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld6_version",
+		.reg = NVSW_REG_CPLD6_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld7_version",
+		.reg = NVSW_REG_CPLD7_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld8_version",
+		.reg = NVSW_REG_CPLD8_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld9_version",
+		.reg = NVSW_REG_CPLD9_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld10_version",
+		.reg = NVSW_REG_CPLD10_VER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld5_pn",
+		.reg = NVSW_REG_CPLD5_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld6_pn",
+		.reg = NVSW_REG_CPLD6_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld7_pn",
+		.reg = NVSW_REG_CPLD7_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld8_pn",
+		.reg = NVSW_REG_CPLD8_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld9_pn",
+		.reg = NVSW_REG_CPLD9_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld10_pn",
+		.reg = NVSW_REG_CPLD10_PN_OFFSET,
+		.bit = GENMASK(15, 0),
+		.mode = 0444,
+		.regnum = 2,
+	},
+	{
+		.label = "cpld5_version_min",
+		.reg = NVSW_REG_CPLD5_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld6_version_min",
+		.reg = NVSW_REG_CPLD6_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld7_version_min",
+		.reg = NVSW_REG_CPLD7_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld8_version_min",
+		.reg = NVSW_REG_CPLD8_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld9_version_min",
+		.reg = NVSW_REG_CPLD9_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "cpld10_version_min",
+		.reg = NVSW_REG_CPLD10_MVER_OFFSET,
+		.bit = GENMASK(7, 0),
+		.mode = 0444,
+	},
+	{
+		.label = "leakage3",
+		.reg = NVSW_REG_LEAK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(2),
+		.mode = 0444,
+	},
+	{
+		.label = "leakage4",
+		.reg = NVSW_REG_LEAK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(3),
+		.mode = 0444,
+	},
+	{
+		.label = "leakage5",
+		.reg = NVSW_REG_LEAK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(4),
+		.mode = 0444,
+	},
+	{
+		.label = "asic1_reset",
+		.reg = NVSW_REG_RESET_GP2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(1),
+		.mode = 0200,
+	},
+	{
+		.label = "asic2_reset",
+		.reg = NVSW_REG_RESET_GP2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(2),
+		.mode = 0200,
+	},
+	{
+		.label = "asic3_reset",
+		.reg = NVSW_REG_RESET_GP2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(4),
+		.mode = 0200,
+	},
+	{
+		.label = "asic4_reset",
+		.reg = NVSW_REG_RESET_GP2_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(5),
+		.mode = 0200,
+	},
+	{
+		.label = "asic2_health",
+		.reg = NVSW_REG_ASIC1_HEALTH_OFFSET,
+		.mask = NVSW_ASIC2_MASK,
+		.bit = 3,
+		.mode = 0444,
+	},
+	{
+		.label = "asic3_health",
+		.reg = NVSW_REG_ASIC1_HEALTH_OFFSET,
+		.mask = NVSW_ASIC3_MASK,
+		.bit = 5,
+		.mode = 0444,
+	},
+	{
+		.label = "asic4_health",
+		.reg = NVSW_REG_ASIC1_HEALTH_OFFSET,
+		.mask = NVSW_ASIC4_MASK,
+		.bit = 7,
+		.mode = 0444,
+	},
+	{
+		.label = "pdb1_pwr_status",
+		.reg = NVSW_REG_PS_DC_OK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(0),
+		.mode = 0444,
+	},
+	{
+		.label = "pdb2_pwr_status",
+		.reg = NVSW_REG_PS_DC_OK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(1),
+		.mode = 0444,
+	},
+	{
+		.label = "pdb3_pwr_status",
+		.reg = NVSW_REG_PS_DC_OK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(2),
+		.mode = 0444,
+	},
+	{
+		.label = "pdb4_pwr_status",
+		.reg = NVSW_REG_PS_DC_OK_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(3),
+		.mode = 0444,
+	},
+};
+
+static struct mlxreg_core_platform_data nvsw_host_spc6_lc_regs_io = {
+	.data = nvsw_host_spc6_lc_regs_io_data,
+	.counter = ARRAY_SIZE(nvsw_host_spc6_lc_regs_io_data),
+};
+
+/* Filled by nvsw_host_init() from the two tables above, in that order */
+static struct mlxreg_core_data
+nvsw_host_spc6_lc_4asic_regs_io_data[ARRAY_SIZE(nvsw_host_spc6_lc_regs_io_data) +
+				     ARRAY_SIZE(nvsw_host_spc6_lc_4asic_only_regs_io_data)];
+
+static struct mlxreg_core_platform_data nvsw_host_spc6_lc_4asic_regs_io = {
+	.data = nvsw_host_spc6_lc_4asic_regs_io_data,
+	.counter = ARRAY_SIZE(nvsw_host_spc6_lc_4asic_regs_io_data),
+};
+
+/* Platform led data for liquid cooled system */
+static struct mlxreg_core_data nvsw_host_spc6_lc_led_data[] = {
+	{
+		.label = "status:green",
+		.reg = NVSW_REG_LED1_OFFSET,
+		.mask = NVSW_LED_LO_NIBBLE_MASK,
+	},
+	{
+		.label = "status:amber",
+		.reg = NVSW_REG_LED1_OFFSET,
+		.mask = NVSW_LED_LO_NIBBLE_MASK,
+	},
+	{
+		.label = "power:green",
+		.reg = NVSW_REG_LED1_OFFSET,
+		.mask = NVSW_LED_HI_NIBBLE_MASK,
+	},
+	{
+		.label = "power:amber",
+		.reg = NVSW_REG_LED1_OFFSET,
+		.mask = NVSW_LED_HI_NIBBLE_MASK,
+	},
+	{
+		.label = "uid:blue",
+		.reg = NVSW_REG_LED5_OFFSET,
+		.mask = NVSW_LED_LO_NIBBLE_MASK,
+	},
+};
+
+static struct mlxreg_core_platform_data nvsw_host_spc6_lc_led = {
+	.data = nvsw_host_spc6_lc_led_data,
+	.counter = ARRAY_SIZE(nvsw_host_spc6_lc_led_data),
+};
+
+/* Watchdog platform data */
+static struct mlxreg_core_data nvsw_host_spc6_wd_main_regs[] = {
+	{
+		.label = "action",
+		.reg = NVSW_REG_WD2_ACT_OFFSET,
+		.mask = NVSW_WD_RESET_ACT_MASK,
+		.bit = 0,
+	},
+	{
+		.label = "timeout",
+		.reg = NVSW_REG_WD2_TMR_OFFSET,
+		.mask = NVSW_WD_TYPE2_TO_MASK,
+		.health_cntr = NVSW_WD3_DFLT_TIMEOUT,
+	},
+	{
+		.label = "timeleft",
+		.reg = NVSW_REG_WD2_TMR_OFFSET,
+		.mask = NVSW_WD_TYPE2_TO_MASK,
+	},
+	{
+		.label = "ping",
+		.reg = NVSW_REG_WD2_ACT_OFFSET,
+		.mask = NVSW_WD_RESET_ACT_MASK,
+		.bit = 0,
+	},
+	{
+		.label = "reset",
+		.reg = NVSW_REG_RESET_CAUSE_OFFSET,
+		.mask = GENMASK(7, 0) & ~BIT(6),
+		.bit = 6,
+	},
+};
+
+static struct mlxreg_core_data nvsw_host_spc6_wd_aux_regs[] = {
+	{
+		.label = "action",
+		.reg = NVSW_REG_WD3_ACT_OFFSET,
+		.mask = NVSW_WD_FAN_ACT_MASK,
+		.bit = 4,
+	},
+	{
+		.label = "timeout",
+		.reg = NVSW_REG_WD3_TMR_OFFSET,
+		.mask = NVSW_WD_TYPE2_TO_MASK,
+		.health_cntr = NVSW_WD3_DFLT_TIMEOUT,
+	},
+	{
+		.label = "timeleft",
+		.reg = NVSW_REG_WD3_TMR_OFFSET,
+		.mask = NVSW_WD_TYPE2_TO_MASK,
+	},
+	{
+		.label = "ping",
+		.reg = NVSW_REG_WD3_ACT_OFFSET,
+		.mask = NVSW_WD_FAN_ACT_MASK,
+		.bit = 4,
+	},
+};
+
+static struct mlxreg_core_platform_data nvsw_host_spc6_wd_set[] = {
+	{
+		.data = nvsw_host_spc6_wd_main_regs,
+		.counter = ARRAY_SIZE(nvsw_host_spc6_wd_main_regs),
+		.version = MLX_WDT_TYPE3,
+		.identity = "mlx-wdt-main",
+	},
+	{
+		.data = nvsw_host_spc6_wd_aux_regs,
+		.counter = ARRAY_SIZE(nvsw_host_spc6_wd_aux_regs),
+		.version = MLX_WDT_TYPE3,
+		.identity = "mlx-wdt-aux",
+	},
+};
+
+/* Mux init/exit callbacks. */
+static int nvsw_host_spc6_mux_topology_init(struct nvsw_core *nvsw_core)
+{
+	struct platform_device *pdev;
+	int i, err;
+
+	/* Create mux infrastructure. */
+	for (i = 0; i < nvsw_core->mux_num; i++) {
+		pdev = platform_device_register_resndata(&nvsw_core->client->dev,
+							 "i2c-mux-mlxcpld", i, NULL,
+							 0, &nvsw_host_spc6_mux_data[i],
+							 sizeof(nvsw_host_spc6_mux_data[i]));
+		if (IS_ERR(pdev)) {
+			dev_err(nvsw_core->dev, "Failed to create mux infra\n");
+			err = PTR_ERR(pdev);
+			goto err_unregister_mux;
+		}
+		nvsw_core->mux[i] = pdev;
+	}
+
+	return 0;
+
+err_unregister_mux:
+	while (i--)
+		platform_device_unregister(nvsw_core->mux[i]);
+
+	return err;
+}
+
+static void nvsw_host_spc6_mux_topology_exit(struct nvsw_core *nvsw_core)
+{
+	int i;
+
+	for (i = nvsw_core->mux_num - 1; i >= 0; i--)
+		platform_device_unregister(nvsw_core->mux[i]);
+}
+
+/* Liquid cooled single ASIC systems, without power supplies and fans. */
+static const struct nvsw_host_spc6_cfg nvsw_host_spc6_cfg_lc = {
+	.regs_io = &nvsw_host_spc6_lc_regs_io,
+	.led = &nvsw_host_spc6_lc_led,
+};
+
+/* Liquid cooled four ASIC systems, without power supplies and fans. */
+static const struct nvsw_host_spc6_cfg nvsw_host_spc6_cfg_lc_4asic = {
+	.regs_io = &nvsw_host_spc6_lc_4asic_regs_io,
+	.led = &nvsw_host_spc6_lc_led,
+};
+
+static const struct dmi_system_id nvsw_host_dmi_table[] __initconst = {
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_NAME, "VMOD0025"),
+			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "HI193"),
+		},
+		.driver_data = (void *)&nvsw_host_spc6_cfg_lc,
+	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_NAME, "VMOD0027"),
+			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "HI183"),
+		},
+		.driver_data = (void *)&nvsw_host_spc6_cfg_lc,
+	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_NAME, "VMOD0027"),
+			DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "HI188"),
+		},
+		.driver_data = (void *)&nvsw_host_spc6_cfg_lc_4asic,
+	},
+	{ }
+};
+
+MODULE_DEVICE_TABLE(dmi, nvsw_host_dmi_table);
+
+static int nvsw_host_probe(struct platform_device *pdev)
+{
+	const struct nvsw_host_spc6_cfg *cfg = dev_get_platdata(&pdev->dev);
+	struct i2c_adapter *last_host_adapter;
+	struct i2c_adapter *adapter;
+	struct nvsw_core *nvsw_core;
+	struct i2c_client *client;
+	int i, err;
+
+	/*
+	 * Ensure the I2C host driver has finished registering all 4 buses
+	 * (0-3) to prevent the mux from stealing bus 3.
+	 */
+	last_host_adapter = i2c_get_adapter(NVSW_I2C_LAST_HOST_BUS_NR);
+	if (!last_host_adapter)
+		return dev_err_probe(&pdev->dev, -EPROBE_DEFER,
+				     "I2C adapter for bus %d is not ready\n",
+				     NVSW_I2C_LAST_HOST_BUS_NR);
+	i2c_put_adapter(last_host_adapter);
+
+	nvsw_core = devm_kzalloc(&pdev->dev, sizeof(*nvsw_core), GFP_KERNEL);
+	if (!nvsw_core)
+		return -ENOMEM;
+
+	/* Get I2C mux parent adapter */
+	adapter = i2c_get_adapter(NVSW_I2C_MUX_PARENT_BUS_NR);
+	if (!adapter) {
+		dev_err(&pdev->dev,
+			"I2C adapter for bus %d is not available\n",
+			NVSW_I2C_MUX_PARENT_BUS_NR);
+		return -ENODEV;
+	}
+
+	/* Create device at the top of host I2C tree */
+	client = i2c_new_client_device(adapter, &nvsw_host_spc6_mux_brdinfo);
+	if (IS_ERR(client)) {
+		dev_err(&pdev->dev,
+			"Failed to create client %s at bus %d at addr 0x%02x\n",
+			nvsw_host_spc6_mux_brdinfo.type, NVSW_I2C_MUX_PARENT_BUS_NR,
+			nvsw_host_spc6_mux_brdinfo.addr);
+		err = PTR_ERR(client);
+		goto err_put_adapter;
+	}
+
+	/* Set system configuration. */
+	nvsw_core->dev = &pdev->dev;
+	nvsw_core->client = client;
+	nvsw_core->mux_num = ARRAY_SIZE(nvsw_host_spc6_mux_data);
+	for (i = 0; i < ARRAY_SIZE(nvsw_host_spc6_wd_set); i++)
+		nvsw_core->wd_data[i] = &nvsw_host_spc6_wd_set[i];
+	nvsw_core->regio_data = cfg->regs_io;
+	nvsw_core->led_data = cfg->led;
+	nvsw_core->mux_init = nvsw_host_spc6_mux_topology_init;
+	nvsw_core->mux_exit = nvsw_host_spc6_mux_topology_exit;
+	platform_set_drvdata(pdev, nvsw_core);
+
+	err = nvsw_core_init(nvsw_core);
+	if (err)
+		goto err_unregister_client;
+
+	return 0;
+
+err_unregister_client:
+	i2c_unregister_device(client);
+err_put_adapter:
+	i2c_put_adapter(adapter);
+
+	return err;
+}
+
+static void nvsw_host_remove(struct platform_device *pdev)
+{
+	struct nvsw_core *nvsw_core = platform_get_drvdata(pdev);
+	struct i2c_adapter *adapter = nvsw_core->client->adapter;
+
+	nvsw_core_exit(nvsw_core);
+	i2c_unregister_device(nvsw_core->client);
+	i2c_put_adapter(adapter);
+}
+
+static struct platform_driver nvsw_host_driver = {
+	.driver		= {
+		.name	= NVSW_HOST_DEVICE_NAME,
+		.probe_type = PROBE_FORCE_SYNCHRONOUS,
+	},
+	.probe		= nvsw_host_probe,
+	.remove		= nvsw_host_remove,
+};
+
+static int __init nvsw_host_init(void)
+{
+	const struct nvsw_host_spc6_cfg *cfg;
+	const struct dmi_system_id *dmi;
+	int err;
+
+	/* The matched entry carries the board description of this SKU. */

drivers/platform/mellanox/nvsw-host-spc6.c line 859

Quoted 10 lines
drivers/platform/mellanox/nvsw-host-spc6.c new file +10 -0
+	dmi = dmi_first_match(nvsw_host_dmi_table);
+	if (!dmi)
+		return -ENODEV;
+	cfg = dmi->driver_data;
+
+	memcpy(nvsw_host_spc6_lc_4asic_regs_io_data, nvsw_host_spc6_lc_regs_io_data,
+	       sizeof(nvsw_host_spc6_lc_regs_io_data));
+	memcpy(&nvsw_host_spc6_lc_4asic_regs_io_data[ARRAY_SIZE(nvsw_host_spc6_lc_regs_io_data)],
+	       nvsw_host_spc6_lc_4asic_only_regs_io_data,
+	       sizeof(nvsw_host_spc6_lc_4asic_only_regs_io_data));

I'm trying to understand why you need to make this copy? Can't the other case just use smaller .counter?

You may have to use multi-line define(s) to get the array size of the first part without providing it as literal.

Other than this, to me the hw info propagation looks better now.

Quoted 26 lines
drivers/platform/mellanox/nvsw-host-spc6.c new file +25 -0
+	nvsw_host_dev = platform_device_register_data(NULL, NVSW_HOST_DEVICE_NAME,
+						      PLATFORM_DEVID_NONE, cfg,
+						      sizeof(*cfg));
+	if (IS_ERR(nvsw_host_dev))
+		return PTR_ERR(nvsw_host_dev);
+
+	err = platform_driver_register(&nvsw_host_driver);
+	if (err)
+		platform_device_unregister(nvsw_host_dev);
+
+	return err;
+}
+module_init(nvsw_host_init);
+
+static void __exit nvsw_host_exit(void)
+{
+	platform_driver_unregister(&nvsw_host_driver);
+	platform_device_unregister(nvsw_host_dev);
+}
+module_exit(nvsw_host_exit);
+
+MODULE_AUTHOR("Felix Radensky <[email protected]>");
+MODULE_DESCRIPTION("Nvidia platform SPC6 driver");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_IMPORT_NS("NVSW");
Signature · 1 line
 i.
#4 lore raw

Re: [PATCH v4 2/3] platform/mellanox: nvsw-host-spc6: Add driver for Nvidia SPC6 switches

Hi Ilpo,

Quoted 11 lines · Ilpo Järvinen

drivers/platform/mellanox/nvsw-host-spc6.c line 859

Quoted 5 lines
drivers/platform/mellanox/nvsw-host-spc6.c new file +5 -0
+	memcpy(nvsw_host_spc6_lc_4asic_regs_io_data, nvsw_host_spc6_lc_regs_io_data,
+	       sizeof(nvsw_host_spc6_lc_regs_io_data));
+	memcpy(&nvsw_host_spc6_lc_4asic_regs_io_data[ARRAY_SIZE(nvsw_host_spc6_lc_regs_io_data)],
+	       nvsw_host_spc6_lc_4asic_only_regs_io_data,
+	       sizeof(nvsw_host_spc6_lc_4asic_only_regs_io_data));

I'm trying to understand why you need to make this copy? Can't the other case just use smaller .counter?

You may have to use multi-line define(s) to get the array size of the first part without providing it as literal.

Thanks. v5 is ready but I haven't posted it yet, as I'd like to explain one change first. The memcpy is gone in v5. I did try the smaller .counter approach first, but in the end I'd like to keep two separate static tables for the liquid cooled systems.

The shared variant put the 33 four ASIC only entries in a multi-line macro at the end of the table, with their count taken from ARRAY_SIZE() of a compound literal built from the same macro, and the single ASIC description used the smaller counter. It worked, but checkpatch reports the macro as an error ("Macros with complex values should be enclosed in parentheses"), which a list of initializers cannot satisfy.

More importantly, the tables no longer differ only by a tail. While reworking v5 we aligned the ASIC attributes with the existing ABI:

- the single ASIC systems keep asic_reset and asic_health, the names mlx-platform and nvsw-sn2201 already use for the same bits, plus asic1_reset and asic1_health on the same bits;
- the four ASIC system has no asic_reset, since the same bit resets all four ASICs there. It has asic_reset_all instead, plus asic1_reset to asic4_reset and asic1_health to asic4_health.

So each system now has entries of its own at the start of the table as well as at the end. A shared array would need system specific entries at both ends, a pointer offset for one description and a reduced counter for the other, on top of the macro. I had that version working (with .data = table + 1) and found it much harder to read than two plain tables.

With separate tables each one lists exactly what its system exposes, both counts are a plain ARRAY_SIZE(), and there is no copy at init. The cost is that the shared entries appear in both tables, which is also what mlx-platform does with its per system tables. A comment on each table asks to keep the shared entries in sync.

For what it's worth, even sharing the liquid cooled tables would not remove most of the duplication. The single ASIC liquid cooled table has 46 entries and the air cooled one added in patch 3 has 55, and 41 of them are identical between the two; 38 are identical across all three tables. Avoiding that would mean moving the common block of all three tables into a macro, which I think would make the driver harder to follow, not easier.

Your const comment is addressed in the pending v5 as well: the mux data and all the platform data structures are const, and nvsw-core no longer writes into them. The mlxreg_core_data entry tables and the mux channel table stay writable only because the mlxreg and mlxcpld platform data structures point to them through non-const pointers.

If you still prefer the shared table, I'll switch back to it before posting v5.

Thanks,
Felix

#5 lore raw

PATCH v4 3/3 platform/mellanox: nvsw-host-spc6: Add support for SPC6 air cooled switches

In reply to Felix Radensky

Add support for air cooled Ethernet switches based on the Nvidia SPC6 ASIC. Unlike the liquid cooled systems already supported by the driver, these carry their own power supplies and fan drawers.

They therefore expose a different set of register access attributes:
power supply presence, AC and DC status and fan drawer presence, in place of the coolant leakage detection and power distribution board status of the liquid cooled systems. They also come with their own LED layout, adding power supply and per fan drawer LEDs, and with fan control. Add the LED and power supply registers these attributes use to the nvsw-core register map. As for the other status registers in the map, the mask registers of the two power supply status registers are added too, so that a board can describe hotplug items over them. These systems do not create a hotplug device; they report power supply and fan events through the mlxreg-io event attributes.

The CPLD of these systems can override the fan PWM and drive the fans at full speed when it detects a fan fault. The override is enabled by bit 0 of the general purpose register at 0x252e, which is set by default. Clear it through the set_reg_default callback, which runs before the fan device is registered, leaving the fan speed to the software. Set it again through restore_reg_default when the driver is removed or fails to probe, so that the CPLD handles fan faults whenever no software controls the fans.

Describe the system and select its description through the driver_data of the matching DMI entry, so that the board data is chosen by the SKU that was matched rather than by inspecting DMI again.

Document the power supply and fan drawer attributes the new system exposes, which are not yet covered by Documentation/ABI/stable/sysfs-driver-mlxreg-io.

---

Notes:
v3->v4
Comments pointed out by Ilpo:
- Take the fan platform data and the set_reg_default callback from the matched board description in the probe path, following the rework in patch 2. The two module scope copies are gone.
- Update the ABI Date and KernelVersion to November 2026 and 7.5, as in patch 2.
Issues reported by a local sashiko review:
- Add only the registers this patch uses to the nvsw-core register map. The power supply alarm status, event and mask registers, TACHO13 to TACHO20, and CURRENT_TEMP_RO and SWITCH_IC_QTY were made accessible with no attribute, LED or fan entry over them, widening regmap and debugfs access for no user. They are dropped from the tables, along with the definitions this patch introduced for them, and the commit message now says which registers are added. The mask registers of the power supply and power supply AC status registers (0x255d, 0x2563) stay, so that every status register in the map has its event and mask registers, as in patch 1. Nothing in the series accesses them, since these systems create no hotplug device and report power supply and fan events through mlxreg-io, and the commit message says so.
- Restore the CPLD fan fault override on remove and on probe failure. The override was cleared at probe and never set again, so after an unbind, or a probe that failed past set_reg_default, the fans were left at their last PWM value with neither the CPLD nor software reacting to a fan fault. The new restore_reg_default callback sets NVSW_FAN_CONTROL_EN_MASK again once the fan device is gone.
- Drop the claim that mlx-platform clears the same override. Its defaults write PWM_CONTROL, whose SPC6 counterpart at 0x2537 holds SPD write protect and power controls instead. The override is bit 0 of 0x252e on the air cooled CPLD only; the liquid cooled one uses that bit for a USB to UART bridge reset. The commit message names the register, and NVSW_FAN_CONTROL_EN_MASK carries a comment.
- Say in the ABI what a write to psu_event, psu_ac_event, psu_dc_event and fan_event does to the other bits. The attributes cover the whole register, so a write reaches every bit of it, and the CPLD clears the bits written as 0 and leaves those written as 1 unchanged. The text only said that writing 0 to a bit clears it.
- On the sashiko.dev finding against this patch: it is valid, and it is fixed in the LED tree rather than here. The fan drawer LEDs are described by a slot index because the capability register of these systems reports a count rather than a bitmap, and mlxreg_led_config() only understood the bitmap flavour. The same description style is used by mlx-platform, which has been losing all twenty of its fan LEDs since v6.16, so the gap belongs to leds-mlxreg. Lee has applied the fix, commit 68a2bfdf7b4d ("leds:
mlxreg: Fix missing fan LEDs on systems reporting a unit count"), queued for the same merge window. The LED table is unchanged here.
Additional fixes added by Felix:
- Make asic_reset write only, as in patch 2.
- Drop the cpu_mctp_ready attribute, as in patch 2.
- Drop the asic_pg_fail attribute, which the liquid cooled table does not have either. GP4_RO, the register only it used, is dropped from the patch 1 register map with it.

v2->v3
Additional fixes added by Felix:
- Describe jtag_enable as the single bit it is, as in patch 2.
- Drop the aux_pwr_cycle attribute, which is not supported on systems with power supply units.
- Clear the CPLD fan fault override enable bit, so that the fan speed is left to the software. This is done from the board driver through the set_reg_default callback, which the core calls before the fan device is registered.

Issues reported by the sashiko.dev review:
- Fix the documented polarity of psu_status. The CPLD reports power supply presence active low, so bit value 0 means the unit is present. psu_ac_status and psu_dc_status share the same description block but are active high, so the polarity is now spelled out per attribute instead of in one sentence covering all three.
- Fix the documented polarity of fan_status. The CPLD reports fan drawer presence active low, so bit value 0 means the drawer is present, which is what mlxreg_fan_read() already assumes when it reads the same register through .reg_prsnt. The ABI text claimed the opposite.
- Drop the claim that this system exposes power supply alarm indications from the commit message. The alarm registers are defined and reachable through the register map, but no attribute is described over them.
- Correct the mode of the pwr_cycle attribute, which was 0244 instead of the 0200 used by the liquid cooled table and documented in the ABI. 0244 denied read access to root while granting it to everyone else on a write only attribute.

v1->v2
- No change. The hunk offsets moved because of the include additions in patches 1 and 2.

 .../ABI/stable/sysfs-driver-mlxreg-io         |  46 ++
 drivers/platform/mellanox/nvsw-core.c         |  16 +
 drivers/platform/mellanox/nvsw-host-spc6.c    | 600 ++++++++++++++++++
 drivers/platform/mellanox/nvsw.h              |  15 +
 4 files changed, 677 insertions(+)
Documentation/ABI/stable/sysfs-driver-mlxreg-io +46 -0
index 8d59181d7196..25f722379873 100644
@@ -970,3 +970,49 @@ Description:	These files show the system reset cause. Respectively:
 		the last reset.
 
 		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/psu_status
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/psu_ac_status
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/psu_dc_status
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show the state of the system power supply units, one
+		bit per unit. Respectively: unit presence, unit AC power good
+		and unit DC power good. In psu_status bit value 0 means the
+		related unit is present, 1 - otherwise. In psu_ac_status and
+		psu_dc_status bit value 1 means the related power is good,
+		0 - otherwise.
+
+		The files are read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/fan_status
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	This file shows the presence of the system fan drawers, one bit
+		per drawer. Bit value 0 means the related drawer is present,
+		1 - otherwise.
+
+		The file is read only.
+
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/psu_event
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/psu_ac_event
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/psu_dc_event
+What:		/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*/fan_event
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	Felix Radensky <[email protected]>
+Description:	These files show the sticky indication of a change in the
+		matching status file: power supply unit presence, power supply
+		unit AC power, power supply unit DC power and fan drawer
+		presence. Bit value 1 means the related unit changed its state
+		since the indication was last cleared.
+
+		A write applies to all the bits of the file at once: a bit
+		written as 0 is cleared, and a bit written as 1 is left
+		unchanged. Writing 0 clears all the indications, and writing
+		a value with only the bit of one unit at 0 clears the
+		indication of that unit alone.
+
+		The files are read/write.
drivers/platform/mellanox/nvsw-core.c +16 -0
index 82b2d856292b..e9d0ff9b2c1a 100644
@@ -33,10 +33,17 @@ static bool nvsw_writeable_reg(struct device *dev, unsigned int reg)
 	case NVSW_REG_ASIC1_EVENT_OFFSET:
 	case NVSW_REG_ASIC1_MASK_OFFSET:
 	case NVSW_REG_LED1_OFFSET:
+	case NVSW_REG_LED2_OFFSET:
+	case NVSW_REG_LED3_OFFSET:
+	case NVSW_REG_LED4_OFFSET:
 	case NVSW_REG_LED5_OFFSET:
 	case NVSW_REG_LED6_OFFSET:
+	case NVSW_REG_PS_AC_2_EVENT_OFFSET:
+	case NVSW_REG_PS_AC_2_MASK_OFFSET:
 	case NVSW_REG_PS_DC_OK_EVENT_OFFSET:
 	case NVSW_REG_PS_DC_OK_MASK_OFFSET:
+	case NVSW_REG_PS_2_EVENT_OFFSET:
+	case NVSW_REG_PS_2_MASK_OFFSET:
 	case NVSW_REG_FAN_EVENT_OFFSET:
 	case NVSW_REG_FAN_MASK_OFFSET:
 	case NVSW_REG_LEAK_EVENT_OFFSET:
@@ -82,6 +89,9 @@ static bool nvsw_readable_reg(struct device *dev, unsigned int reg)
 	case NVSW_REG_RESET_CAUSE1_OFFSET:
 	case NVSW_REG_RESET_CAUSE2_OFFSET:
 	case NVSW_REG_LED1_OFFSET:
+	case NVSW_REG_LED2_OFFSET:
+	case NVSW_REG_LED3_OFFSET:
+	case NVSW_REG_LED4_OFFSET:
 	case NVSW_REG_LED5_OFFSET:
 	case NVSW_REG_LED6_OFFSET:
 	case NVSW_REG_CPLD7_PN_OFFSET:
@@ -100,6 +110,12 @@ static bool nvsw_readable_reg(struct device *dev, unsigned int reg)
 	case NVSW_REG_ASIC1_HEALTH_OFFSET:
 	case NVSW_REG_ASIC1_EVENT_OFFSET:
 	case NVSW_REG_ASIC1_MASK_OFFSET:
+	case NVSW_REG_PS_AC_2_OFFSET:
+	case NVSW_REG_PS_AC_2_EVENT_OFFSET:
+	case NVSW_REG_PS_AC_2_MASK_OFFSET:
+	case NVSW_REG_PS_2_OFFSET:
+	case NVSW_REG_PS_2_EVENT_OFFSET:
+	case NVSW_REG_PS_2_MASK_OFFSET:
 	case NVSW_REG_PS_DC_OK_OFFSET:
 	case NVSW_REG_PS_DC_OK_EVENT_OFFSET:
 	case NVSW_REG_PS_DC_OK_MASK_OFFSET:
drivers/platform/mellanox/nvsw-host-spc6.c +600 -0

641 lines not on this page · raw message

drivers/platform/mellanox/nvsw.h +15 -0
index 65746e4b539b..0b3544fbee49 100644
@@ -37,6 +37,9 @@ struct regmap;
 #define NVSW_REG_RESET_CAUSE1_OFFSET	0x251e
 #define NVSW_REG_RESET_CAUSE2_OFFSET	0x251f
 #define NVSW_REG_LED1_OFFSET		0x2520
+#define NVSW_REG_LED2_OFFSET		0x2521
+#define NVSW_REG_LED3_OFFSET		0x2522
+#define NVSW_REG_LED4_OFFSET		0x2523
 #define NVSW_REG_LED5_OFFSET		0x2524
 #define NVSW_REG_LED6_OFFSET		0x2525
 #define NVSW_REG_CPLD7_PN_OFFSET	0x2528
@@ -55,6 +58,12 @@ struct regmap;
 #define NVSW_REG_ASIC1_HEALTH_OFFSET	0x2550
 #define NVSW_REG_ASIC1_EVENT_OFFSET	0x2551
 #define NVSW_REG_ASIC1_MASK_OFFSET	0x2552
+#define NVSW_REG_PS_2_OFFSET		0x255b
+#define NVSW_REG_PS_2_EVENT_OFFSET	0x255c
+#define NVSW_REG_PS_2_MASK_OFFSET	0x255d
+#define NVSW_REG_PS_AC_2_OFFSET		0x2561
+#define NVSW_REG_PS_AC_2_EVENT_OFFSET	0x2562
+#define NVSW_REG_PS_AC_2_MASK_OFFSET	0x2563
 #define NVSW_REG_PS_DC_OK_OFFSET	0x2567
 #define NVSW_REG_PS_DC_OK_EVENT_OFFSET	0x2568
 #define NVSW_REG_PS_DC_OK_MASK_OFFSET	0x2569
@@ -113,6 +122,12 @@ struct regmap;
 #define NVSW_REG_TACHO_SPEED_OFFSET	0x25f8
 #define NVSW_REG_MAX			0x26ff
 
+/*
+ * CPLD fan PWM override on fan failure, in NVSW_REG_GP0_OFFSET of the air
+ * cooled SPC6 systems only. The liquid cooled ones use the same bit for a
+ * pulsed USB to UART bridge reset.
+ */
+#define NVSW_FAN_CONTROL_EN_MASK	BIT(0)
 /*
  * Health fields of the first to the fourth ASIC, two bits each, all held in
  * NVSW_REG_ASIC1_HEALTH_OFFSET.
Signature · 1 line
2.34.1