I3C MCTP net driver
Subsystems (5)
Matt Johnston
maintainerv3 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.
I3C maintainers have acked merging this through net-next tree.
Thanks,
Matt
---
v3:
- Use get_unaligned_be48()
- Use kthread_run()
- Don't set net namespace
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 | 760 ++++++++++++++++++ include/linux/i3c/master.h | 11 + 6 files changed, 822 insertions(+) create mode 100644 drivers/net/mctp/mctp-i3c.c
Signature · 1 line
2.39.2
Matt Johnston
maintainerPATCH v3 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
@@ -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.39.2
Matt Johnston
maintainerPATCH v3 2/3 i3c: Add support for bus enumeration & notification
In reply to Matt JohnstonFrom: 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
@@ -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" ,
@@ -2682,6 +2713,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.
@@ -2714,6 +2747,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
@@ -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.39.2
Matt Johnston
maintainerPATCH v3 3/3 mctp i3c: MCTP I3C driver
In reply to Matt JohnstonProvides 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.
---
v3:
- Use get_unaligned_be48()
- Use kthread_run()
- Don't set net namespace
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 | 760 ++++++++++++++++++++++++++++++++++++ 3 files changed, 770 insertions(+) create mode 100644 drivers/net/mctp/mctp-i3c.c
drivers/net/mctp/Kconfig +9 -0
@@ -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
@@ -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 +760 -0
760 lines not on this page · raw message
Signature · 1 line
2.39.2
kernel test robot
build botRe: [PATCH net-next v3 3/3] mctp i3c: MCTP I3C driver
kernel test robot noticed the following build errors:
Hi Matt,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Matt-Johnston/dt-bindings-i3c-Add-mctp-controller-property/20231003-144037 base: net-next/main patch link: https://lore.kernel.org/r/20231003063624.126723-4-matt%40codeconstruct.com.au patch subject: [PATCH net-next v3 3/3] mctp i3c: MCTP I3C driver config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20231003/[email protected]/config) compiler: sh4-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231003/[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/net/mctp/mctp-i3c.c: In function 'mctp_i3c_read':
>> drivers/net/mctp/mctp-i3c.c:121:9: error: implicit declaration of function 'put_unaligned_be48' [-Werror=implicit-function-declaration]
121 | put_unaligned_be48(mi->pid, ihdr->source);
| ^~~~~~~~~~~~~~~~~~
drivers/net/mctp/mctp-i3c.c: In function 'mctp_i3c_xmit':
>> drivers/net/mctp/mctp-i3c.c:380:15: error: implicit declaration of function 'get_unaligned_be48'; did you mean 'get_unalign_ctl'? [-Werror=implicit-function-declaration]
380 | pid = get_unaligned_be48(ihdr->dest);
| ^~~~~~~~~~~~~~~~~~
| get_unalign_ctlcc1: some warnings being treated as errors
vim +/put_unaligned_be48 +121 drivers/net/mctp/mctp-i3c.c
98
99 static int mctp_i3c_read(struct mctp_i3c_device *mi)
100 {
101 struct i3c_priv_xfer xfer = { .rnw = 1, .len = mi->mrl };
102 struct net_device_stats *stats = &mi->mbus->ndev->stats;
103 struct mctp_i3c_internal_hdr *ihdr = NULL;
104 struct sk_buff *skb = NULL;
105 struct mctp_skb_cb *cb;
106 int net_status, rc;
107 u8 pec, addr;
108
109 skb = netdev_alloc_skb(mi->mbus->ndev,
110 mi->mrl + sizeof(struct mctp_i3c_internal_hdr));
111 if (!skb) {
112 stats->rx_dropped++;
113 rc = -ENOMEM;
114 goto err;
115 }
116
117 skb->protocol = htons(ETH_P_MCTP);
118 /* Create a header for internal use */
119 skb_reset_mac_header(skb);
120 ihdr = skb_put(skb, sizeof(struct mctp_i3c_internal_hdr));
> 121 put_unaligned_be48(mi->pid, ihdr->source);
122 put_unaligned_be48(mi->mbus->pid, ihdr->dest);
123 skb_pull(skb, sizeof(struct mctp_i3c_internal_hdr));
124
125 xfer.data.in = skb_put(skb, mi->mrl);
126
127 rc = i3c_device_do_priv_xfers(mi->i3c, &xfer, 1);
128 if (rc < 0)
129 goto err;
130
131 if (WARN_ON_ONCE(xfer.len > mi->mrl)) {
132 /* Bad i3c bus driver */
133 rc = -EIO;
134 goto err;
135 }
136 if (xfer.len < MCTP_I3C_MINLEN) {
137 stats->rx_length_errors++;
138 rc = -EIO;
139 goto err;
140 }
141
142 /* check PEC, including address byte */
143 addr = mi->addr << 1 | 1;
144 pec = i2c_smbus_pec(0, &addr, 1);
145 pec = i2c_smbus_pec(pec, xfer.data.in, xfer.len - 1);
146 if (pec != ((u8 *)xfer.data.in)[xfer.len - 1]) {
147 stats->rx_crc_errors++;
148 rc = -EINVAL;
149 goto err;
150 }
151
152 /* Remove PEC */
153 skb_trim(skb, xfer.len - 1);
154
155 cb = __mctp_cb(skb);
156 cb->halen = PID_SIZE;
157 put_unaligned_be48(mi->pid, cb->haddr);
158
159 net_status = netif_rx(skb);
160
161 if (net_status == NET_RX_SUCCESS) {
162 stats->rx_packets++;
163 stats->rx_bytes += xfer.len - 1;
164 } else {
165 stats->rx_dropped++;
166 }
167
168 return 0;
169 err:
170 kfree_skb(skb);
171 return rc;
172 }
173
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki