Skip to contentSkip to conversation

mailbox: Add Marvell MHU driver

PATCH Superseded Paul Cercueil 3 participants 6 messages Nov 20 – Nov 21

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover mailbox: Add Marvell MHU driver

Hi Jassi,

This is the v2 of my patchset that adds support for the mailbox found in the OcteonTX and OcteonTX2 based SoCs, which is used for SCMI communication.

I dropped v1's last patch (that affected the SCMI driver) since SCMI maintainers and Sashiko reported that I could replace it with a simple DT property.

Changelog:

v2:

* [1/2]:
- Fix binding path in MAINTAINERS file
- Move MAINTAINERS entry so that it's in alphabetical order
- Fix formatting of DT example

* [2/2]:
- Add Kconfig dependency on PCI
- Order includes properly
- Remove duplicated macros
- Pass a pointer to the "mhu" variable to mrvl_mhu_setup_irq(), instead of getting it from drvdata. Then we don't even need to set drvdata.
- Use devm functions unconditionally. This fixes an issue where pci_free_irq_vectors() was called while IRQs were still in place. It also allows to drop mrvl_mhu_remove().
- Use pcim_iomap_region() instead of pcim_request_region() + pcim_iomap().
- Enable IRQ in .startup(), disable it in .shutdown().
- ACK the IRQ after calling mbox_chan_received_data()
- Fix register used for polling TX done
- Clean up macros

Cheers,
-Paul

George Cherian (2):
dt-bindings: mailbox: add Marvell MHU
mailbox: marvell-mhu: add Marvell MHU driver

 .../bindings/mailbox/marvell,mhu.yaml         |  61 +++++
 MAINTAINERS                                   |   7 +
 drivers/mailbox/Kconfig                       |  11 +
 drivers/mailbox/Makefile                      |   2 +
 drivers/mailbox/marvell_mhu.c                 | 239 ++++++++++++++++++
 5 files changed, 320 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/marvell,mhu.yaml
 create mode 100644 drivers/mailbox/marvell_mhu.c
Signature · 1 line
2.47.3
#1 lore raw

PATCH v2 1/2 dt-bindings: mailbox: add Marvell MHU

From: George Cherian <[email protected]>

Marvell Message Handling Unit is a mailbox controller present in Marvell OcteonTx and OcteonTX2 SoC family.

---

v2:
- Fix binding path in MAINTAINERS file
- Move MAINTAINERS entry so that it's in alphabetical order
- Fix formatting of DT example

---
 .../bindings/mailbox/marvell,mhu.yaml         | 61 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/marvell,mhu.yaml
Documentation/devicetree/bindings/mailbox/marvell,mhu.yaml new file +61 -0
new file mode 100644
index 000000000000..5cf20d5642ac
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/marvell,mhu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell Message Handling Unit
+
+maintainers:
+  - Sujeet Baranwal <[email protected]>
+  - George Cherian <[email protected]>
+
+description:
+  The Control-Processors Cluster (CPC) provides Arm-platform specification
+  entities for managing the system. One of the CPC processors is the System
+  Control Processor (SCP). The SCP is responsible, among others, for booting
+  the chip, clock and power initialization, controlling power consumption
+  through DVFS, monitoring temperature sensors and controlling AVS. The SCP,
+  as each XCP, contains mailboxes for software-to-software communications.
+  Mailbox writes cause an interrupt to the local XCP core or to the AP.
+  This driver exposes AP-SCP Message Handling Unit to the system, providing
+  the mailbox communication mechanism to the system, with the intention
+  of plugging into the SCMI framework. It is designed to work with Marvell
+  OcteonTX and OcteonTX2-based platforms.
+  The mailbox has no other usage than SCMI communication. In case of
+  configurations running without SCMI support it should be disabled.
+
+properties:
+  compatible:
+    enum:
+      - marvell,octeontx-mhu
+      - marvell,octeontx2-mhu
+      - marvell,cn10-mhu
+
+  reg:
+    maxItems: 1
+
+  "#mbox-cells":
+    description: Index of the channel
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - "#mbox-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    ecam {
+        #address-cells = <3>;
+        #size-cells = <2>;
+
+        mailbox@1c,0 {
+            compatible = "marvell,octeontx2-mhu";
+            reg = <0xe000 0x0 0x0 0 0>;
+            #mbox-cells = <1>;
+        };
+    };
+...
MAINTAINERS +6 -0
index 65e8a4b5c90b..8f6f98acc8fc 100644
@@ -15825,6 +15825,12 @@ L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
 F:	arch/arm64/boot/dts/marvell/armada-8040-mcbin.dts
 
+MARVELL MHU MAILBOX DRIVER
+M:	Sujeet Baranwal <[email protected]>
+M:	George Cherian <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/mailbox/marvell,mhu.yaml
+
 MARVELL MV643XX ETHERNET DRIVER
 M:	Sebastian Hesselbarth <[email protected]>
 L:	[email protected]
Signature · 1 line
2.47.3
#2 lore raw

PATCH v2 2/2 mailbox: marvell-mhu: add Marvell MHU driver

In reply to Paul Cercueil

From: George Cherian <[email protected]>

Add support for Message Handling Units on Marvell OcteonTx and OcteonTx2 platforms. The module uses mailbox controller interface to provide communication between SCP and AP using SCMI protocol over a single shared memory communication channel.

---

v2:
- Add Kconfig dependency on PCI
- Order includes properly
- Remove duplicated macros
- Pass a pointer to the "mhu" variable to mrvl_mhu_setup_irq(), instead of getting it from drvdata. Then we don't even need to set drvdata.
- Use devm functions unconditionally. This fixes an issue where pci_free_irq_vectors() was called while IRQs were still in place. It also allows to drop mrvl_mhu_remove().
- Use pcim_iomap_region() instead of pcim_request_region() + pcim_iomap().
- Enable IRQ in .startup(), disable it in .shutdown().
- ACK the IRQ after calling mbox_chan_received_data()
- Fix register used for polling TX done
- Clean up macros

---
 MAINTAINERS                   |   1 +
 drivers/mailbox/Kconfig       |  11 ++
 drivers/mailbox/Makefile      |   2 +
 drivers/mailbox/marvell_mhu.c | 239 ++++++++++++++++++++++++++++++++++
 4 files changed, 253 insertions(+)
 create mode 100644 drivers/mailbox/marvell_mhu.c
MAINTAINERS +1 -0
index 8f6f98acc8fc..06c49bef8390 100644
@@ -15830,6 +15830,7 @@ M:	Sujeet Baranwal <[email protected]>
 M:	George Cherian <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/mailbox/marvell,mhu.yaml
+F:	drivers/mailbox/marvell_mhu.c
 
 MARVELL MV643XX ETHERNET DRIVER
 M:	Sebastian Hesselbarth <[email protected]>
drivers/mailbox/Kconfig +11 -0
index ab869769e278..62744399cdb8 100644
@@ -195,6 +195,17 @@ config MAILBOX_TEST
 	  Test client to help with testing new Controller driver
 	  implementations.
 
+config MARVELL_MHU
+	tristate "Marvell Message Handling Unit"
+	depends on (ARM64 || COMPILE_TEST) && 64BIT
+	depends on PCI && OF
+	help
+	  This driver adds support for Marvell MHU controller.
+	  The MHU mailbox is used by SCMI for OcteonTX and OcteonTX2
+	  to control various aspects of platform operation like cpufreq
+	  or sensors. The controller supports single channel to SCP.
+	  Say Y here to build this module. If unsure say N.
+
 config POLARFIRE_SOC_MAILBOX
 	tristate "PolarFire SoC (MPFS) Mailbox"
 	depends on HAS_IOMEM
drivers/mailbox/Makefile +2 -0
index 45dc59bb3e7f..83b26e7bbd27 100644
@@ -49,6 +49,8 @@ obj-$(CONFIG_BCM_PDC_MBOX)	+= bcm-pdc-mailbox.o
 
 obj-$(CONFIG_BCM_FLEXRM_MBOX)	+= bcm-flexrm-mailbox.o
 
+obj-$(CONFIG_MARVELL_MHU)	+= marvell_mhu.o
+
 obj-$(CONFIG_POLARFIRE_SOC_MAILBOX)	+= mailbox-mpfs.o
 
 obj-$(CONFIG_MCHP_SBI_IPC_MBOX)		+= mailbox-mchp-ipc-sbi.o
drivers/mailbox/marvell_mhu.c new file +239 -0

239 lines not on this page · raw message

Signature · 1 line
2.47.3
#3 lore raw

Re: [PATCH v2 2/2] mailbox: marvell-mhu: add Marvell MHU driver

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] mailbox: marvell-mhu: missing IRQF_NO_AUTOEN in mrvl_mhu_setup_irq() - [Medium] mailbox…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] mailbox: marvell-mhu: missing IRQF_NO_AUTOEN in mrvl_mhu_setup_irq()
- [Medium] mailbox: marvell-mhu: inverted TX done check in mrvl_mhu_last_tx_done()
- [Low] mailbox: marvell-mhu: invalid min_vecs in mrvl_mhu_setup_irq() --

commit 2ee602a4969cc96c3afca49d7d2c3b05ee5ffda2
Author: George Cherian <[email protected]>

mailbox: marvell-mhu: add Marvell MHU driver

This commit adds a mailbox controller driver for the Message Handling Unit on Marvell OcteonTX and OcteonTX2 platforms.

Quoted 6 lines
drivers/mailbox/marvell_mhu.c new file +0 -0
new file mode 100644
index 0000000000000..9b618b3fe2768
@@ -0,0 +1,239 @@

[ ... ]

Quoted 5 lines
drivers/mailbox/marvell_mhu.c new file +5 -0
+#define SCP_INDEX	0x0
+#define DEV_AP0		0x2
+#define SCP_TO_AP_INTERRUPT	2
+#define INT_VECS_MIN	0
+#define INT_VECS_MAX	3

[ ... ]

drivers/mailbox/marvell_mhu.c line 109

Quoted 9 lines
drivers/mailbox/marvell_mhu.c new file +9 -0
+static bool mrvl_mhu_last_tx_done(struct mbox_chan *chan)
+{
+	struct mrvl_mhu *mhu = chan->con_priv;
+	u64 status;
+
+	status = ioread64(mhu->base + AP0_TO_SCP_MBOX_LINT);
+
+	return status != 0;
+}

[Severity: Medium]
Is the status check in mrvl_mhu_last_tx_done() inverted?

Writing the doorbell in mrvl_mhu_send_data() asserts the interrupt bit in AP0_TO_SCP_MBOX_LINT, and the register remains non-zero until the SCP services and clears the interrupt. Returning status != 0 reports TX done while the interrupt is still pending (or times out if the SCP clears it before the poll runs), instead of waiting for status == 0.

Quoted 20 lines
drivers/mailbox/marvell_mhu.c new file +20 -0
+
+static int mrvl_mhu_startup(struct mbox_chan *chan)
+{
+	struct mrvl_mhu *mhu = chan->con_priv;
+
+	/* Enable interrupts only if there is client for data */
+	writeq_relaxed(1ul, mhu->base + SCP_TO_AP0_MBOX_RINT_ENA_W1S);
+
+	enable_irq(mhu->irq);
+
+	return 0;
+}
+
+static void mrvl_mhu_shutdown(struct mbox_chan *chan)
+{
+	struct mrvl_mhu *mhu = chan->con_priv;
+
+	/* Could be using SCP_TO_AP0_MBOX_RINT_DIS_W1S if we knew where it was */
+	disable_irq(mhu->irq);
+}

[ ... ]

Quoted 4 lines
drivers/mailbox/marvell_mhu.c new file +4 -0
+static int mrvl_mhu_setup_irq(struct mrvl_mhu *mhu, struct pci_dev *pdev)
+{
+	struct device *dev = &pdev->dev;
+	int ret, nvec;

drivers/mailbox/marvell_mhu.c line 157

Quoted 10 lines
drivers/mailbox/marvell_mhu.c new file +10 -0
+
+	nvec = pci_alloc_irq_vectors(pdev, INT_VECS_MIN, INT_VECS_MAX, PCI_IRQ_MSIX);
+	if (nvec < 0)
+		return nvec;
+
+	ret = devm_add_action_or_reset(dev, mrvl_mhu_free_irq_vector, pdev);
+	if (ret)
+		return ret;
+
+	mhu->irq = pci_irq_vector(pdev, SCP_TO_AP_INTERRUPT);

[Severity: Low]
Should INT_VECS_MIN be 3 (or SCP_TO_AP_INTERRUPT + 1) instead of 0? pci_alloc_irq_vectors() requires min_vecs >= 1, and requesting vector index 2 requires at least 3 MSI-X vectors to be allocated.

drivers/mailbox/marvell_mhu.c line 163

Quoted 6 lines
drivers/mailbox/marvell_mhu.c new file +6 -0
+	if (mhu->irq < 0)
+		return mhu->irq;
+
+	return devm_request_irq(dev, mhu->irq,
+				mrvl_mhu_rx_interrupt, 0, "mvl-mhu", mhu);
+}

[Severity: High]
Should devm_request_irq() pass IRQF_NO_AUTOEN?

With irqflags set to 0, mhu->irq is enabled immediately during probe while mhu->chan.cl is still NULL. When a client binds to the channel, mrvl_mhu_startup() calls enable_irq(mhu->irq) on the already-enabled IRQ and triggers an "Unbalanced enable for IRQ" warning in __enable_irq(). In addition, if an SCP interrupt fires before a client attaches, mrvl_mhu_rx_interrupt() calls mbox_chan_received_data(&mhu->chan, ...) and dereferences a NULL chan->cl.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH v2 2/2] mailbox: marvell-mhu: add Marvell MHU driver

In reply to Paul Cercueil
kernel test robot noticed the following build errors:

Hi Paul,

kernel test robot noticed the following build errors:

[auto build test ERROR on jassibrar-mailbox/for-next]
[also build test ERROR on robh/for-next krzk-dt/for-next linus/master v7.4-rc3 next-20261119] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Paul-Cercueil/dt-bindings-mailbox-add-Marvell-MHU/20261120-123951
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jassibrar/mailbox.git for-next
patch link:    https://lore.kernel.org/r/20261120113952.168265-3-paul.cercueil%40bootlin.com
patch subject: [PATCH v2 2/2] mailbox: marvell-mhu: add Marvell MHU driver
config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20261121/[email protected]/config)
compiler: powerpc64-linux-gcc (GCC) 16.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261121/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/mailbox/marvell_mhu.c: In function 'mrvl_mhu_send_data':

>> drivers/mailbox/marvell_mhu.c:96:9: error: implicit declaration of function 'iowrite64'; did you mean 'iowrite32'? [-Wimplicit-function-declaration]
      96 |         iowrite64(doorbell, mhu->base + AP0_TO_SCP_MBOX);
         |         ^~~~~~~~~
         |         iowrite32
   drivers/mailbox/marvell_mhu.c: In function 'mrvl_mhu_last_tx_done':
>> drivers/mailbox/marvell_mhu.c:106:18: error: implicit declaration of function 'ioread64'; did you mean 'ioread32'? [-Wimplicit-function-declaration]
     106 |         status = ioread64(mhu->base + AP0_TO_SCP_MBOX_LINT);
         |                  ^~~~~~~~
         |                  ioread32

vim +96 drivers/mailbox/marvell_mhu.c

    89	
    90	static int mrvl_mhu_send_data(struct mbox_chan *chan, void *data)
    91	{
    92		const u64 doorbell = 0xff;  /* Arbitrary value, SCP requires a value */
    93		struct mrvl_mhu *mhu = chan->con_priv;
    94	
    95		/* signal SCP */
  > 96		iowrite64(doorbell, mhu->base + AP0_TO_SCP_MBOX);
    97	
    98		return 0;
    99	}
   100	
   101	static bool mrvl_mhu_last_tx_done(struct mbox_chan *chan)
   102	{
   103		struct mrvl_mhu *mhu = chan->con_priv;
   104		u64 status;
   105	
 > 106		status = ioread64(mhu->base + AP0_TO_SCP_MBOX_LINT);

107
108 return status != 0;
109 }
110

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

Re: [PATCH v2 2/2] mailbox: marvell-mhu: add Marvell MHU driver

In reply to Paul Cercueil
kernel test robot noticed the following build errors:

Hi Paul,

kernel test robot noticed the following build errors:

[auto build test ERROR on jassibrar-mailbox/for-next]
[also build test ERROR on robh/for-next krzk-dt/for-next linus/master v7.4-rc3 next-20261119] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Paul-Cercueil/dt-bindings-mailbox-add-Marvell-MHU/20261120-123951
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jassibrar/mailbox.git for-next
patch link:    https://lore.kernel.org/r/20261120113952.168265-3-paul.cercueil%40bootlin.com
patch subject: [PATCH v2 2/2] mailbox: marvell-mhu: add Marvell MHU driver
config: x86_64-allmodconfig (https://download.01.org/0day-ci/archive/20261122/[email protected]/config)
compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)
rustc: rustc 1.96.0 (ac68faa20 2026-05-25)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/mailbox/marvell_mhu.c:96:2: error: call to undeclared function 'iowrite64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      96 |         iowrite64(doorbell, mhu->base + AP0_TO_SCP_MBOX);
         |         ^
>> drivers/mailbox/marvell_mhu.c:106:11: error: call to undeclared function 'ioread64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     106 |         status = ioread64(mhu->base + AP0_TO_SCP_MBOX_LINT);
         |                  ^

2 errors generated.

vim +/iowrite64 +96 drivers/mailbox/marvell_mhu.c

    89	
    90	static int mrvl_mhu_send_data(struct mbox_chan *chan, void *data)
    91	{
    92		const u64 doorbell = 0xff;  /* Arbitrary value, SCP requires a value */
    93		struct mrvl_mhu *mhu = chan->con_priv;
    94	
    95		/* signal SCP */
  > 96		iowrite64(doorbell, mhu->base + AP0_TO_SCP_MBOX);
    97	
    98		return 0;
    99	}
   100	
   101	static bool mrvl_mhu_last_tx_done(struct mbox_chan *chan)
   102	{
   103		struct mrvl_mhu *mhu = chan->con_priv;
   104		u64 status;
   105	
 > 106		status = ioread64(mhu->base + AP0_TO_SCP_MBOX_LINT);

107
108 return status != 0;
109 }
110

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki