MCTP I2C driver
Subsystems (5)
Matt Johnston
maintainerv4 cover MCTP I2C driver
Hi,
This patch series adds a netdev driver providing MCTP transport over I2C.
Since the v3 submission I have switched to using I2C transfers which support >32 bytes. It could be switch back to smbus transfers once 255 byte support is ready. It now doesn't require any changes to I2C core.
The dt-bindings patch went through review on the list.
Cheers,
Matt
--
v4:
- Switch to __i2c_transfer() rather than __i2c_smbus_xfer(), drop 255 byte smbus patches
- Use wait_event_idle() for the sleeping TX thread
- Use dev_addr_set()
v3:
- Added Reviewed-bys for npcm7xx
- Resend with net-next open
v2:
- Simpler Kconfig condition for i2c-mux dependency, from Randy Dunlap
Matt Johnston (2):
dt-bindings: net: New binding mctp-i2c-controller mctp i2c: MCTP I2C binding driver
Documentation/devicetree/bindings/i2c/i2c.txt | 4 + .../bindings/net/mctp-i2c-controller.yaml | 92 ++ drivers/net/mctp/Kconfig | 13 + drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-i2c.c | 1002 +++++++++++++++++ 5 files changed, 1112 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mctp-i2c-controller.yaml create mode 100644 drivers/net/mctp/mctp-i2c.c
Signature · 1 line
2.32.0
Matt Johnston
maintainerPATCH v4 1/2 dt-bindings: net: New binding mctp-i2c-controller
Used to define a local endpoint to communicate with MCTP peripherals attached to an I2C bus. This I2C endpoint can communicate with remote MCTP devices on the I2C bus.
In the example I2C topology below (matching the second yaml example) we have MCTP devices on busses i2c1 and i2c6. MCTP-supporting busses are indicated by the 'mctp-controller' DT property on an I2C bus node.
A mctp-i2c-controller I2C client DT node is placed at the top of the mux topology, since only the root I2C adapter will support I2C slave functionality.
.-------.
|eeprom |
.------------. .------. /'-------'
| adapter | | mux --@0,i2c5------'
| i2c1 ----.*| --@1,i2c6--.--.
|............| \'------' \ \ .........
| mctp-i2c- | \ \ \ .mctpB .
| controller | \ \ '.0x30 .
| | \ ......... \ '.......'
| 0x50 | \ .mctpA . \ .........
'------------' '.0x1d . '.mctpC .
'.......' '.0x31 .
'.......'(mctpX boxes above are remote MCTP devices not included in the DT at present, they can be hotplugged/probed at runtime. A DT binding for specific fixed MCTP devices could be added later if required)
--- Documentation/devicetree/bindings/i2c/i2c.txt | 4 + .../bindings/net/mctp-i2c-controller.yaml | 92 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/mctp-i2c-controller.yaml
Documentation/devicetree/bindings/i2c/i2c.txt +4 -0
@@ -95,6 +95,10 @@ wants to support one of the below features, it should adapt these bindings. - smbus-alert states that the optional SMBus-Alert feature apply to this bus. +- mctp-controller + indicates that the system is accessible via this bus as an endpoint for + MCTP over I2C transport. + Required properties (per child device) --------------------------------------
Documentation/devicetree/bindings/net/mctp-i2c-controller.yaml new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.32.0
Matt Johnston
maintainerPATCH v4 2/2 mctp i2c: MCTP I2C binding driver
In reply to Matt JohnstonProvides MCTP network transport over an I2C bus, as specified in DMTF DSP0237. All messages between nodes are sent as SMBus Block Writes.
Each I2C bus to be used for MCTP is flagged in devicetree by a 'mctp-controller' property on the bus node. Each flagged bus gets a mctpi2cX net device created based on the bus number. A 'mctp-i2c-controller' I2C client needs to be added under the adapter. In an I2C mux situation the mctp-i2c-controller node must be attached only to the root I2C bus. The I2C client will handle incoming I2C slave block write data for subordinate busses as well as its own bus.
In configurations without devicetree a driver instance can be attached to a bus using the I2C slave new_device mechanism.
The MCTP core will hold/release the MCTP I2C device while responses are pending (a 6 second timeout or once a socket is closed, response received etc). While held the MCTP I2C driver will lock the I2C bus so that the correct I2C mux remains selected while responses are received.
(Ideally we would just lock the mux to keep the current bus selected for the response rather than a full I2C bus lock, but that isn't exposed in the I2C mux API)
--- drivers/net/mctp/Kconfig | 13 + drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-i2c.c | 1002 +++++++++++++++++++++++++++++++++++ 3 files changed, 1016 insertions(+) create mode 100644 drivers/net/mctp/mctp-i2c.c
drivers/net/mctp/Kconfig +13 -0
@@ -3,6 +3,7 @@ if MCTP menu "MCTP Device Drivers" + config MCTP_SERIAL tristate "MCTP serial transport" depends on TTY
@@ -21,6 +22,18 @@ config MCTP_SERIAL Say y here if you need to connect to MCTP endpoints over serial. To compile as a module, use m; the module will be called mctp-serial. +config MCTP_TRANSPORT_I2C + tristate "MCTP SMBus/I2C transport" + # i2c-mux is optional, but we must build as a module if i2c-mux is a module + depends on I2C_MUX || !I2C_MUX + depends on I2C + depends on I2C_SLAVE + select MCTP_FLOWS + help + Provides a driver to access MCTP devices over SMBus/I2C transport, + from DMTF specification DSP0237. A MCTP protocol network device is + created for each I2C bus that has been assigned a mctp-i2c device. + endmenu endif
drivers/net/mctp/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_MCTP_SERIAL) += mctp-serial.o +obj-$(CONFIG_MCTP_TRANSPORT_I2C) += mctp-i2c.o
drivers/net/mctp/mctp-i2c.c new file +1002 -0
1,002 lines not on this page · raw message
Signature · 1 line
2.32.0
Jakub Kicinski
maintainerRe: [PATCH net-next v4 2/2] mctp i2c: MCTP I2C binding driver
Quoted 19 lines · On Wed, 9 Feb 2022 18:31:21 +0800 Matt Johnston wrote:
Provides MCTP network transport over an I2C bus, as specified in DMTF DSP0237. All messages between nodes are sent as SMBus Block Writes.
Each I2C bus to be used for MCTP is flagged in devicetree by a 'mctp-controller' property on the bus node. Each flagged bus gets a mctpi2cX net device created based on the bus number. A 'mctp-i2c-controller' I2C client needs to be added under the adapter. In an I2C mux situation the mctp-i2c-controller node must be attached only to the root I2C bus. The I2C client will handle incoming I2C slave block write data for subordinate busses as well as its own bus.
In configurations without devicetree a driver instance can be attached to a bus using the I2C slave
new_devicemechanism.The MCTP core will hold/release the MCTP I2C device while responses are pending (a 6 second timeout or once a socket is closed, response received etc). While held the MCTP I2C driver will lock the I2C bus so that the correct I2C mux remains selected while responses are received.
Quoted 6 lines
(Ideally we would just lock the mux to keep the current bus selected for the response rather than a full I2C bus lock, but that isn't exposed in the I2C mux API)
Signed-off-by Matt Johnston <[email protected]>Signed-off-by Jeremy Kerr <[email protected]>
drivers/net/mctp/mctp-i2c.c: In function ‘mctp_i2c_xmit’:drivers/net/mctp/mctp-i2c.c:442:38: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 3 has type ‘int’ [-Wformat=]
442 | "Bad tx length %zu vs skb %u\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~include/linux/dev_printk.h:110:30: note: in definition of macro ‘dev_printk_index_wrap’
110 | _p_func(dev, fmt, ##__VA_ARGS__); \
| ^~~include/linux/dev_printk.h:146:61: note: in expansion of macro ‘dev_fmt’
146 | dev_printk_index_wrap(_dev_warn, KERN_WARNING, dev, dev_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~include/linux/dev_printk.h:208:17: note: in expansion of macro ‘dev_warn’
208 | dev_level(dev, fmt, ##__VA_ARGS__); \
| ^~~~~~~~~
include/linux/dev_printk.h:220:9: note: in expansion of macro ‘dev_level_ratelimited’
220 | dev_level_ratelimited(dev_warn, dev, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~~
drivers/net/mctp/mctp-i2c.c:441:17: note: in expansion of macro ‘dev_warn_ratelimited’
441 | dev_warn_ratelimited(&midev->adapter->dev,
| ^~~~~~~~~~~~~~~~~~~~
drivers/net/mctp/mctp-i2c.c:442:55: note: format string is defined here
442 | "Bad tx length %zu vs skb %u\n",
| ~~^
| |
| long unsigned int
| %u