Skip to contentSkip to conversation

I3C MCTP net driver

PATCH Superseded Matt Johnston 5 participants 12 messages Jul 17, 2023 – Jul 20, 2023

Subsystems (5)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Matt Johnston

author maintainer
#0 lore raw

v2 cover I3C MCTP net driver

This series adds an I3C transport for the kernel's MCTP network protocol. MCTP is a communication protocol between system components (BMCs, drives, NICs etc), with higher level protocols such as NVMe-MI or PLDM built on top of it (in userspace). It runs over various transports such as I2C, PCIe, or I3C.

The mctp-i3c driver follows a similar approach to the kernel's existing mctp-i2c driver, creating a "mctpi3cX" network interface for each numbered I3C bus. Busses opt in to support by adding a "mctp-controller" property to the devicetree:

&i3c0 {
        mctp-controller;
}

The driver will bind to MCTP class devices (DCR 0xCC) that are on a supported I3C bus. Each bus is represented by a struct mctp_i3c_bus that keeps state for the network device. An individual I3C device (struct mctp_i3c_device) performs operations using the "parent" mctp_i3c_bus object. The I3C notify/enumeration patch is needed so that the mctp-i3c driver can handle creating/removing mctp_i3c_bus objects as required.

The mctp-i3c driver is using the Provisioned ID as an identifier for target I3C devices (the neighbour address), as that will be more stable than the I3C dynamic address. The driver internally translates that to a dynamic address for bus operations.

The driver has been tested using an AST2600 platform. A remote endpoint has been tested against Qemu, as well as using the target mode support in Aspeed's vendor tree.

I've rebased to net-next since that is the faster moving tree. If I3C maintainers would prefer I can submit the I3C bus enumeration patch by itself and let it take another cycle to get into net-next, though it wouldn't have any in-tree user. I'll leave that to maintainers.

Thanks,
Matt

---

v2:

- Rebased to net-next
- Removed unnecessary pr_ printing
- Fixed reverse christmas tree ordering
- Reworded DT property description to match I2C

Jeremy Kerr (1):
i3c: Add support for bus enumeration & notification

Matt Johnston (2):
dt-bindings: i3c: Add mctp-controller property
mctp i3c: MCTP I3C driver

 .../devicetree/bindings/i3c/i3c.yaml          |   6 +
 drivers/i3c/master.c                          |  35 +
 drivers/net/mctp/Kconfig                      |   9 +
 drivers/net/mctp/Makefile                     |   1 +
 drivers/net/mctp/mctp-i3c.c                   | 777 ++++++++++++++++++
 include/linux/i3c/master.h                    |  11 +
 6 files changed, 839 insertions(+)
 create mode 100644 drivers/net/mctp/mctp-i3c.c
Signature · 1 line
2.37.2
author maintainer
#1 lore raw

PATCH v2 1/3 dt-bindings: i3c: Add mctp-controller property

This property is used to describe a I3C bus with attached MCTP I3C target devices.

---

v2:

- Reworded DT property description to match I2C

 Documentation/devicetree/bindings/i3c/i3c.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/i3c/i3c.yaml +6 -0
index fdb4212149e7..b052a20d591f 100644
@@ -55,6 +55,12 @@ properties:
 
       May not be supported by all controllers.
 
+  mctp-controller:
+    type: boolean
+    description: |
+      Indicates that the system is accessible via this bus as an endpoint for
+      MCTP over I3C transport.
+
 required:
   - "#address-cells"
   - "#size-cells"
Signature · 1 line
2.37.2
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH net-next v2 1/3] dt-bindings: i3c: Add mctp-controller property

Quoted 7 lines · Matt Johnston

This property is used to describe a I3C bus with attached MCTP I3C target devices.

---

v2:

---

This is an automated instruction, just in case, because many review tags are being ignored. If you do not know the process, here is a short explanation:

Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions, under or above your Signed-off-by tag. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.

https://elixir.bootlin.com/linux/v5.17/source/Documentation/process/submitting-patches.rst#L540

Best regards,
Krzysztof

maintainer Acked-by on v2 1/3
#3 lore raw

Re: [PATCH net-next v2 1/3] dt-bindings: i3c: Add mctp-controller property

In reply to Matt Johnston
Quoted 4 lines · Matt Johnston

This property is used to describe a I3C bus with attached MCTP I3C target devices.

Quoted 29 lines

---

v2:

- Reworded DT property description to match I2C

 Documentation/devicetree/bindings/i3c/i3c.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/i3c/i3c.yaml +6 -0
index fdb4212149e7..b052a20d591f 100644
@@ -55,6 +55,12 @@ properties:
 
       May not be supported by all controllers.
 
+  mctp-controller:
+    type: boolean
+    description: |
+      Indicates that the system is accessible via this bus as an endpoint for
+      MCTP over I3C transport.
+
 required:
   - "#address-cells"
   - "#size-cells"
Signature · 1 line
2.37.2
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#4 lore raw

PATCH v2 2/3 i3c: Add support for bus enumeration & notification

In reply to Matt Johnston

From: Jeremy Kerr <[email protected]>

This allows other drivers to be notified when new i3c busses are attached, referring to a whole i3c bus as opposed to individual devices.

---
 drivers/i3c/master.c       | 35 +++++++++++++++++++++++++++++++++++
 include/linux/i3c/master.h | 11 +++++++++++
 2 files changed, 46 insertions(+)
drivers/i3c/master.c +35 -0
index 08aeb69a7800..2276abe38bdc 100644
@@ -22,6 +22,7 @@
 static DEFINE_IDR(i3c_bus_idr);
 static DEFINE_MUTEX(i3c_core_lock);
 static int __i3c_first_dynamic_bus_num;
+static BLOCKING_NOTIFIER_HEAD(i3c_bus_notifier);
 
 /**
  * i3c_bus_maintenance_lock - Lock the bus for a maintenance operation
@@ -453,6 +454,36 @@ static int i3c_bus_init(struct i3c_bus *i3cbus, struct device_node *np)
 	return 0;
 }
 
+void i3c_for_each_bus_locked(int (*fn)(struct i3c_bus *bus, void *data),
+			     void *data)
+{
+	struct i3c_bus *bus;
+	int id;
+
+	mutex_lock(&i3c_core_lock);
+	idr_for_each_entry(&i3c_bus_idr, bus, id)
+		fn(bus, data);
+	mutex_unlock(&i3c_core_lock);
+}
+EXPORT_SYMBOL_GPL(i3c_for_each_bus_locked);
+
+int i3c_register_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&i3c_bus_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(i3c_register_notifier);
+
+int i3c_unregister_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&i3c_bus_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(i3c_unregister_notifier);
+
+static void i3c_bus_notify(struct i3c_bus *bus, unsigned int action)
+{
+	blocking_notifier_call_chain(&i3c_bus_notifier, action, bus);
+}
+
 static const char * const i3c_bus_mode_strings[] = {
 	[I3C_BUS_MODE_PURE] = "pure",
 	[I3C_BUS_MODE_MIXED_FAST] = "mixed-fast",
@@ -2678,6 +2709,8 @@ int i3c_master_register(struct i3c_master_controller *master,
 	if (ret)
 		goto err_del_dev;
 
+	i3c_bus_notify(i3cbus, I3C_NOTIFY_BUS_ADD);
+
 	/*
 	 * We're done initializing the bus and the controller, we can now
 	 * register I3C devices discovered during the initial DAA.
@@ -2710,6 +2743,8 @@ EXPORT_SYMBOL_GPL(i3c_master_register);
  */
 void i3c_master_unregister(struct i3c_master_controller *master)
 {
+	i3c_bus_notify(&master->bus, I3C_NOTIFY_BUS_REMOVE);
+
 	i3c_master_i2c_adapter_cleanup(master);
 	i3c_master_unregister_i3c_devs(master);
 	i3c_master_bus_cleanup(master);
include/linux/i3c/master.h +11 -0
index 0b52da4f2346..db909ef79be4 100644
@@ -24,6 +24,12 @@
 
 struct i2c_client;
 
+/* notifier actions. notifier call data is the struct i3c_bus */
+enum {
+	I3C_NOTIFY_BUS_ADD,
+	I3C_NOTIFY_BUS_REMOVE,
+};
+
 struct i3c_master_controller;
 struct i3c_bus;
 struct i3c_device;
@@ -652,4 +658,9 @@ void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot);
 
 struct i3c_ibi_slot *i3c_master_get_free_ibi_slot(struct i3c_dev_desc *dev);
 
+void i3c_for_each_bus_locked(int (*fn)(struct i3c_bus *bus, void *data),
+			     void *data);
+int i3c_register_notifier(struct notifier_block *nb);
+int i3c_unregister_notifier(struct notifier_block *nb);
+
 #endif /* I3C_MASTER_H */
Signature · 1 line
2.37.2
maintainer
#5 lore raw

Re: [PATCH net-next v2 2/3] i3c: Add support for bus enumeration & notification

Quoted 8 lines · On Mon, 17 Jul 2023 12:06:37 +0800 Matt Johnston wrote:

From: Jeremy Kerr <[email protected]>

This allows other drivers to be notified when new i3c busses are attached, referring to a whole i3c bus as opposed to individual devices.

We need one of:
- sign-off from Alexandre that he's okay with this code going via netdev; or
- stable branch from Alexandre based on an upstream -rc tag which we can pull into net-next; or
- wait until 6.6 merge window for the change to propagate.
Until then we can't do much on our end, so I'll mark the patches as deferred from netdev perspective.

Signature · 1 line
pw-bot: defer
#6 lore raw

Re: [PATCH net-next v2 2/3] i3c: Add support for bus enumeration & notification

Quoted 10 lines · Jakub Kicinski
Quoted 8 lines · On Mon, 17 Jul 2023 12:06:37 +0800 Matt Johnston wrote:

From: Jeremy Kerr <[email protected]>

This allows other drivers to be notified when new i3c busses are attached, referring to a whole i3c bus as opposed to individual devices.

Quoted 8 lines

We need one of:
- sign-off from Alexandre that he's okay with this code going via netdev; or
- stable branch from Alexandre based on an upstream -rc tag which we can pull into net-next; or
- wait until 6.6 merge window for the change to propagate.
Until then we can't do much on our end, so I'll mark the patches as deferred from netdev perspective.

I'm fine with the series going through netdev. Matt, please carry my ack on the next versions.

Quoted 2 lines
Signature · 1 line
pw-bot: defer
Signature · 8 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
maintainer Acked-by on v2 2/3
#7 lore raw

Re: [PATCH net-next v2 2/3] i3c: Add support for bus enumeration & notification

In reply to Matt Johnston
Quoted 8 lines · Matt Johnston

From: Jeremy Kerr <[email protected]>

This allows other drivers to be notified when new i3c busses are attached, referring to a whole i3c bus as opposed to individual devices.

Quoted 102 lines
---
 drivers/i3c/master.c       | 35 +++++++++++++++++++++++++++++++++++
 include/linux/i3c/master.h | 11 +++++++++++
 2 files changed, 46 insertions(+)
drivers/i3c/master.c +35 -0
index 08aeb69a7800..2276abe38bdc 100644
@@ -22,6 +22,7 @@
 static DEFINE_IDR(i3c_bus_idr);
 static DEFINE_MUTEX(i3c_core_lock);
 static int __i3c_first_dynamic_bus_num;
+static BLOCKING_NOTIFIER_HEAD(i3c_bus_notifier);
 
 /**
  * i3c_bus_maintenance_lock - Lock the bus for a maintenance operation
@@ -453,6 +454,36 @@ static int i3c_bus_init(struct i3c_bus *i3cbus, struct device_node *np)
 	return 0;
 }
 
+void i3c_for_each_bus_locked(int (*fn)(struct i3c_bus *bus, void *data),
+			     void *data)
+{
+	struct i3c_bus *bus;
+	int id;
+
+	mutex_lock(&i3c_core_lock);
+	idr_for_each_entry(&i3c_bus_idr, bus, id)
+		fn(bus, data);
+	mutex_unlock(&i3c_core_lock);
+}
+EXPORT_SYMBOL_GPL(i3c_for_each_bus_locked);
+
+int i3c_register_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&i3c_bus_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(i3c_register_notifier);
+
+int i3c_unregister_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&i3c_bus_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(i3c_unregister_notifier);
+
+static void i3c_bus_notify(struct i3c_bus *bus, unsigned int action)
+{
+	blocking_notifier_call_chain(&i3c_bus_notifier, action, bus);
+}
+
 static const char * const i3c_bus_mode_strings[] = {
 	[I3C_BUS_MODE_PURE] = "pure",
 	[I3C_BUS_MODE_MIXED_FAST] = "mixed-fast",
@@ -2678,6 +2709,8 @@ int i3c_master_register(struct i3c_master_controller *master,
 	if (ret)
 		goto err_del_dev;
 
+	i3c_bus_notify(i3cbus, I3C_NOTIFY_BUS_ADD);
+
 	/*
 	 * We're done initializing the bus and the controller, we can now
 	 * register I3C devices discovered during the initial DAA.
@@ -2710,6 +2743,8 @@ EXPORT_SYMBOL_GPL(i3c_master_register);
  */
 void i3c_master_unregister(struct i3c_master_controller *master)
 {
+	i3c_bus_notify(&master->bus, I3C_NOTIFY_BUS_REMOVE);
+
 	i3c_master_i2c_adapter_cleanup(master);
 	i3c_master_unregister_i3c_devs(master);
 	i3c_master_bus_cleanup(master);
include/linux/i3c/master.h +11 -0
index 0b52da4f2346..db909ef79be4 100644
@@ -24,6 +24,12 @@
 
 struct i2c_client;
 
+/* notifier actions. notifier call data is the struct i3c_bus */
+enum {
+	I3C_NOTIFY_BUS_ADD,
+	I3C_NOTIFY_BUS_REMOVE,
+};
+
 struct i3c_master_controller;
 struct i3c_bus;
 struct i3c_device;
@@ -652,4 +658,9 @@ void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot);
 
 struct i3c_ibi_slot *i3c_master_get_free_ibi_slot(struct i3c_dev_desc *dev);
 
+void i3c_for_each_bus_locked(int (*fn)(struct i3c_bus *bus, void *data),
+			     void *data);
+int i3c_register_notifier(struct notifier_block *nb);
+int i3c_unregister_notifier(struct notifier_block *nb);
+
 #endif /* I3C_MASTER_H */
Signature · 1 line
2.37.2
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#8 lore raw

PATCH v2 3/3 mctp i3c: MCTP I3C driver

In reply to Matt Johnston

Provides MCTP network transport over an I3C bus, as specified in DMTF DSP0233.

Each I3C bus (with "mctp-controller" devicetree property) gets an "mctpi3cX" net device created. I3C devices are reachable as remote endpoints through that net device. Link layer addressing uses the I3C PID as a fixed hardware address for neighbour table entries.

The driver matches I3C devices that have the MIPI assigned DCR 0xCC for MCTP.

---

v2:

- Removed unnecessary pr_ printing
- Fixed reverse christmas tree ordering

 drivers/net/mctp/Kconfig    |   9 +
 drivers/net/mctp/Makefile   |   1 +
 drivers/net/mctp/mctp-i3c.c | 777 ++++++++++++++++++++++++++++++++++++
 3 files changed, 787 insertions(+)
 create mode 100644 drivers/net/mctp/mctp-i3c.c
drivers/net/mctp/Kconfig +9 -0
index dc71657d9184..ce9d2d2ccf3b 100644
@@ -33,6 +33,15 @@ config MCTP_TRANSPORT_I2C
 	  from DMTF specification DSP0237. A MCTP protocol network device is
 	  created for each I2C bus that has been assigned a mctp-i2c device.
 
+config MCTP_TRANSPORT_I3C
+	tristate "MCTP I3C transport"
+	depends on I3C
+	help
+	  Provides a driver to access MCTP devices over I3C transport,
+	  from DMTF specification DSP0233.
+	  A MCTP protocol network device is created for each I3C bus
+	  having a "mctp-controller" devicetree property.
+
 endmenu
 
 endif
drivers/net/mctp/Makefile +1 -0
index 1ca3e6028f77..e1cb99ced54a 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_MCTP_SERIAL) += mctp-serial.o
 obj-$(CONFIG_MCTP_TRANSPORT_I2C) += mctp-i2c.o
+obj-$(CONFIG_MCTP_TRANSPORT_I3C) += mctp-i3c.o
drivers/net/mctp/mctp-i3c.c new file +777 -0

777 lines not on this page · raw message

Signature · 1 line
2.37.2
maintainer
#9 lore raw

Re: [PATCH net-next v2 3/3] mctp i3c: MCTP I3C driver

drivers/net/mctp/mctp-i3c.c line 606

Quoted 1 line · On Mon, 17 Jul 2023 12:06:38 +0800 Matt Johnston wrote:
drivers/net/mctp/mctp-i3c.c new file +1 -0
+	dev_net_set(ndev, current->nsproxy->net_ns);

This is a bit odd, we may have missed similar code in earlier mctp drivers. Are you actually making use of auto-assigning netns?

drivers/net/mctp/mctp-i3c.c line 633

Quoted 10 lines
drivers/net/mctp/mctp-i3c.c new file +10 -0
+	mbus->tx_thread = kthread_create(mctp_i3c_tx_thread, mbus,
+					 "%s/tx", ndev->name);
+	if (IS_ERR(mbus->tx_thread)) {
+		dev_warn(&ndev->dev, "Error creating thread: %pe\n",
+			mbus->tx_thread);
+		rc = PTR_ERR(mbus->tx_thread);
+		mbus->tx_thread = NULL;
+		goto err;
+	}
+	wake_up_process(mbus->tx_thread);

kthread_run()

maintainer
#10 lore raw

Re: [PATCH net-next v2 3/3] mctp i3c: MCTP I3C driver

In reply to Matt Johnston

drivers/net/mctp/mctp-i3c.c line 104

Quoted 6 lines · On Mon, 17 Jul 2023 12:06:38 +0800 Matt Johnston wrote:
drivers/net/mctp/mctp-i3c.c new file +6 -0
+/* Returns the 48 bit Provisioned Id from an i3c_device_info.pid */
+static void pid_to_addr(u64 pid, u8 addr[PID_SIZE])
+{
+	pid = cpu_to_be64(pid);
+	memcpy(addr, ((u8 *)&pid) + 2, PID_SIZE);
+}

put_unaligned_be48() ? That or you need a local variable or something, because otherwise sparse is not happy (build test with C=1).

#11 lore raw

Re: [PATCH net-next v2 3/3] mctp i3c: MCTP I3C driver

In reply to Matt Johnston

On Mon, Jul 17, 2023 at 12:06:38PM +0800, Matt Johnston wrote:

...

Hi Matt,

drivers/net/mctp/mctp-i3c.c line 102

Quoted 4 lines
drivers/net/mctp/mctp-i3c.c new file +4 -0
+/* Returns the 48 bit Provisioned Id from an i3c_device_info.pid */
+static void pid_to_addr(u64 pid, u8 addr[PID_SIZE])
+{
+	pid = cpu_to_be64(pid);

This assigns a be64 value to a u64 variable, which is incorrect from a Sparse annotation perspective.

Quoted 2 lines
(quoted diff) +2 -0
+	memcpy(addr, ((u8 *)&pid) + 2, PID_SIZE);
+}

...