MCTP I2C driver
Subsystems (9)
Matt Johnston
maintainerv3 cover MCTP I2C driver
Hi,
This patch series adds a netdev driver providing MCTP transport over I2C.
It applies against net-next using recent MCTP changes there, though also has I2C core changes for review. I'll leave it to maintainers where it should be applied - please let me know if it needs to be submitted differently.
The I2C patches were previously sent as RFC though the only feedback there was an ack to 255 bytes for aspeed.
The dt-bindings patch went through review on the list.
Cheers,
Matt
--
v3:
- Added Reviewed-bys for npcm7xx
- Resend with net-next open
v2:
- Simpler Kconfig condition for i2c-mux dependency, from Randy Dunlap
Matt Johnston (6):
i2c: core: Allow 255 byte transfers for SMBus 3.x
i2c: dev: Handle 255 byte blocks for i2c ioctl
i2c: aspeed: Allow 255 byte block transfers
i2c: npcm7xx: Allow 255 byte block SMBus transfers
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/i2c/busses/i2c-aspeed.c | 5 +- drivers/i2c/busses/i2c-npcm7xx.c | 3 +- drivers/i2c/i2c-core-smbus.c | 20 +- drivers/i2c/i2c-dev.c | 93 +- drivers/net/mctp/Kconfig | 12 + drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-i2c.c | 982 ++++++++++++++++++ include/linux/i2c.h | 13 + include/uapi/linux/i2c-dev.h | 2 + include/uapi/linux/i2c.h | 7 +- 12 files changed, 1209 insertions(+), 25 deletions(-) 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 v3 1/6 i2c: core: Allow 255 byte transfers for SMBus 3.x
SMBus 3.0 increased the maximum block transfer size from 32 bytes to 255 bytes. We increase the size of struct i2c_smbus_data's block[] member.
i2c_smbus_xfer() and i2c_smbus_xfer_emulated() now support 255 byte block operations, other block functions remain limited to 32 bytes for compatibility with existing callers.
We allow adapters to indicate support for the larger size with I2C_FUNC_SMBUS_V3_BLOCK. Most emulated drivers should be able to use 255 byte blocks by replacing I2C_SMBUS_BLOCK_MAX with I2C_SMBUS_V3_BLOCK_MAX though some will have hardware limitations that need testing.
--- drivers/i2c/i2c-core-smbus.c | 20 +++++++++++++------- include/linux/i2c.h | 13 +++++++++++++ include/uapi/linux/i2c.h | 5 ++++- 3 files changed, 30 insertions(+), 8 deletions(-)
drivers/i2c/i2c-core-smbus.c +13 -7
@@ -303,7 +303,8 @@ static void i2c_smbus_try_get_dmabuf(struct i2c_msg *msg, u8 init_val)bool is_read = msg->flags &I2C_M_RD ;unsigned char *dma_buf; - dma_buf =kzalloc (I2C_SMBUS_BLOCK_MAX + (is_read ?2 :3 ),GFP_KERNEL ); + dma_buf =kzalloc (I2C_SMBUS_V3_BLOCK_MAX + (is_read ?2 :3 ), +GFP_KERNEL );if (!dma_buf)return ;
@@ -329,9 +330,10 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,* initialize most things with sane defaults, to keep the code below * somewhat simpler. */ -unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX +3 ]; -unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX +2 ]; +unsigned char msgbuf0[I2C_SMBUS_V3_BLOCK_MAX +3 ]; +unsigned char msgbuf1[I2C_SMBUS_V3_BLOCK_MAX +2 ];int nmsgs = read_write ==I2C_SMBUS_READ ?2 :1 ; +u16 block_max;u8 partial_pec =0 ;int status;struct i2c_msg msg[2 ] = {
@@ -350,6 +352,10 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,bool wants_pec = ((flags &I2C_CLIENT_PEC ) && size !=I2C_SMBUS_QUICK && size !=I2C_SMBUS_I2C_BLOCK_DATA ); +/* Drivers must opt in to 255 byte max block size */ + block_max =i2c_check_functionality (adapter,I2C_FUNC_SMBUS_V3_BLOCK ) + ?I2C_SMBUS_V3_BLOCK_MAX :I2C_SMBUS_BLOCK_MAX ; + msgbuf0[0 ] = command;switch (size) {case I2C_SMBUS_QUICK :
@@ -399,7 +405,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,i2c_smbus_try_get_dmabuf (&msg[1 ],0 ); }else { msg[0 ].len = data->block[0 ] +2 ; -if (msg[0 ].len >I2C_SMBUS_BLOCK_MAX +2 ) { +if (msg[0 ].len > block_max +2 ) {dev_err (&adapter->dev,"Invalid block write size %d\n" , data->block[0 ]);
@@ -413,7 +419,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,case I2C_SMBUS_BLOCK_PROC_CALL : nmsgs =2 ;/* Another special case */ read_write =I2C_SMBUS_READ ; -if (data->block[0 ] >I2C_SMBUS_BLOCK_MAX ) { +if (data->block[0 ] > block_max) {dev_err (&adapter->dev,"Invalid block write size %d\n" , data->block[0 ]);
@@ -430,7 +436,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,i2c_smbus_try_get_dmabuf (&msg[1 ],0 );break ;case I2C_SMBUS_I2C_BLOCK_DATA : -if (data->block[0 ] >I2C_SMBUS_BLOCK_MAX ) { +if (data->block[0 ] > block_max) {dev_err (&adapter->dev,"Invalid block %s size %d\n" , read_write ==I2C_SMBUS_READ ?"read" :"write" , data->block[0 ]);
@@ -498,7 +504,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,break ;case I2C_SMBUS_BLOCK_DATA :case I2C_SMBUS_BLOCK_PROC_CALL : -if (msg[1 ].buf[0 ] >I2C_SMBUS_BLOCK_MAX ) { +if (msg[1 ].buf[0 ] > block_max) {dev_err (&adapter->dev,"Invalid block size returned: %d\n" , msg[1 ].buf[0 ]);
include/linux/i2c.h +13 -0
@@ -52,6 +52,19 @@ typedef int (*i2c_slave_cb_t)(struct i2c_client *client,struct module ;struct property_entry ; +/* SMBus 3.0 extends the maximum block read/write size to 255 (from 32). +* The larger size is only supported by some drivers, indicated by +* the I2C_FUNC_SMBUS_V3_BLOCK functionality bit. +*/ +#define I2C_SMBUS_V3_BLOCK_MAX 255/* As specified in SMBus 3.0 standard */ + +/* Note compatibility definition in uapi header with 32 byte block */ +union i2c_smbus_data { +__u8 byte; +__u16 word; +__u8 block[I2C_SMBUS_V3_BLOCK_MAX +1 ];/* block[0] is used for length */ +}; +#if IS_ENABLED (CONFIG_I2C )/* Return the Frequency mode string based on the bus frequency */ const char *i2c_freq_mode_string (u32 bus_freq_hz);
include/uapi/linux/i2c.h +4 -1
@@ -108,6 +108,7 @@ struct i2c_msg {#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000/* I2C-like block xfer */ #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000/* w/ 1-byte reg. addr. */ #define I2C_FUNC_SMBUS_HOST_NOTIFY 0x10000000/* SMBus 2.0 or later */ +#define I2C_FUNC_SMBUS_V3_BLOCK 0x20000000/* Device supports 255 byte block */ #define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \ I2C_FUNC_SMBUS_WRITE_BYTE)
@@ -137,13 +138,15 @@ struct i2c_msg {/* * Data for SMBus Messages */ -#define I2C_SMBUS_BLOCK_MAX 32/* As specified in SMBus standard */ +#define I2C_SMBUS_BLOCK_MAX 32/* As specified in SMBus 2.0 standard */ +#ifndef __KERNEL__union i2c_smbus_data {__u8 byte;__u16 word;__u8 block[I2C_SMBUS_BLOCK_MAX +2 ];/* block[0] is used for length */ /* and one more for user-space compatibility */ }; +#endif /* i2c_smbus_xfer read or write markers */ #define I2C_SMBUS_READ 1
Signature · 1 line
2.32.0
Matt Johnston
maintainerPATCH v3 2/6 i2c: dev: Handle 255 byte blocks for i2c ioctl
In reply to Matt JohnstonI2C_SMBUS is limited to 32 bytes due to compatibility with the 32 byte i2c_smbus_data.block
I2C_RDWR allows larger transfers if sufficient sized buffers are passed.
--- drivers/i2c/i2c-dev.c | 93 ++++++++++++++++++++++++++++++------ include/uapi/linux/i2c-dev.h | 2 + include/uapi/linux/i2c.h | 2 + 3 files changed, 83 insertions(+), 14 deletions(-)
drivers/i2c/i2c-dev.c +79 -14
@@ -46,6 +46,24 @@ struct i2c_dev {struct cdev cdev; }; +/* The userspace union i2c_smbus_data for I2C_SMBUS ioctl is limited +* to 32 bytes (I2C_SMBUS_BLOCK_MAX) for compatibility. +*/ +union compat_i2c_smbus_data { +__u8 byte; +__u16 word; +__u8 block[I2C_SMBUS_BLOCK_MAX +2 ];/* block[0] is used for length */ +/* and one more for user-space compatibility */ +}; + +/* Must match i2c-dev.h definition with compat .data member */ +struct i2c_smbus_ioctl_data { +__u8 read_write; +__u8 command; +__u32 size; +union compat_i2c_smbus_data __user *data; +}; +#define I2C_MINORS (MINORMASK + 1)static LIST_HEAD (i2c_dev_list);static DEFINE_SPINLOCK (i2c_dev_list_lock);
@@ -235,14 +253,17 @@ static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,unsigned nmsgs,struct i2c_msg *msgs) { -u8 __user **data_ptrs; +u8 __user **data_ptrs =NULL ; +u16 *orig_lens =NULL ;int i, res; + res = -ENOMEM ; data_ptrs =kmalloc_array (nmsgs,sizeof (u8 __user *),GFP_KERNEL ); -if (data_ptrs ==NULL ) { -kfree (msgs); -return -ENOMEM ; - } +if (data_ptrs ==NULL ) + goto out; + orig_lens =kmalloc_array (nmsgs,sizeof (u16),GFP_KERNEL ); +if (orig_lens ==NULL ) + goto out; res =0 ;for (i =0 ; i < nmsgs; i++) {
@@ -253,12 +274,30 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client, } data_ptrs[i] = (u8 __user *)msgs[i].buf; - msgs[i].buf =memdup_user (data_ptrs[i], msgs[i].len); + msgs[i].buf =NULL ; +if (msgs[i].len <1 ) { +/* Sanity check */ + res = -EINVAL ; +break ; + + } +/* Allocate a larger buffer to accommodate possible 255 byte +* blocks. Read results will be dropped later +* if they are too large for the original length. +*/ + orig_lens[i] = msgs[i].len; + msgs[i].buf =kmalloc (msgs[i].len +I2C_SMBUS_V3_BLOCK_MAX , +GFP_USER | __GFP_NOWARN);if (IS_ERR (msgs[i].buf)) { res =PTR_ERR (msgs[i].buf);break ; } -/* memdup_user allocates with GFP_KERNEL, so DMA is ok */ +if (copy_from_user (msgs[i].buf, data_ptrs[i], msgs[i].len)) { +kfree (msgs[i].buf); + res = -EFAULT ; +break ; + } +/* Buffer from kmalloc, so DMA is ok */ msgs[i].flags |=I2C_M_DMA_SAFE ;/*
@@ -274,7 +313,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,*/ if (msgs[i].flags &I2C_M_RECV_LEN ) {if (!(msgs[i].flags &I2C_M_RD ) || - msgs[i].len <1 || msgs[i].buf[0 ] <1 || + msgs[i].buf[0 ] <1 || msgs[i].len < msgs[i].buf[0 ] +I2C_SMBUS_BLOCK_MAX ) { i++;
@@ -297,12 +336,16 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client, res =i2c_transfer (client->adapter, msgs, nmsgs);while (i-- >0 ) {if (res >=0 && (msgs[i].flags &I2C_M_RD )) { -if (copy_to_user (data_ptrs[i], msgs[i].buf, - msgs[i].len)) +if (orig_lens[i] < msgs[i].len) + res = -EINVAL ; +else if (copy_to_user (data_ptrs[i], msgs[i].buf, + msgs[i].len)) res = -EFAULT ; }kfree (msgs[i].buf); } +out: +kfree (orig_lens);kfree (data_ptrs);kfree (msgs);return res;
@@ -310,7 +353,7 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client, static noinline int i2cdev_ioctl_smbus(struct i2c_client *client,u8 read_write,u8 command,u32 size, -union i2c_smbus_data __user *data) +union compat_i2c_smbus_data __user *data) {union i2c_smbus_data temp = {};int datasize, res;
@@ -371,6 +414,16 @@ static noinline int i2cdev_ioctl_smbus(struct i2c_client *client,if (copy_from_user (&temp, data, datasize))return -EFAULT ; } +if ((size ==I2C_SMBUS_BLOCK_PROC_CALL || + size ==I2C_SMBUS_I2C_BLOCK_DATA || + size ==I2C_SMBUS_BLOCK_DATA ) && + read_write ==I2C_SMBUS_WRITE && + temp.block[0 ] >I2C_SMBUS_BLOCK_MAX ) { +/* Don't accept writes larger than the buffer size */ +dev_dbg (&client->adapter->dev,"block write is too large" ); +return -EINVAL ; + + }if (size ==I2C_SMBUS_I2C_BLOCK_BROKEN ) {/* Convert old I2C block commands to the new convention. This preserves binary compatibility. */
@@ -380,9 +433,21 @@ static noinline int i2cdev_ioctl_smbus(struct i2c_client *client, } res =i2c_smbus_xfer (client->adapter, client->addr, client->flags, read_write, command, size, &temp); -if (!res && ((size ==I2C_SMBUS_PROC_CALL ) || - (size ==I2C_SMBUS_BLOCK_PROC_CALL ) || - (read_write ==I2C_SMBUS_READ ))) { +if (res) +return res; +if ((size ==I2C_SMBUS_BLOCK_PROC_CALL || + size ==I2C_SMBUS_I2C_BLOCK_DATA || + size ==I2C_SMBUS_BLOCK_DATA ) && + read_write ==I2C_SMBUS_READ && + temp.block[0 ] >I2C_SMBUS_BLOCK_MAX ) { +/* Don't accept reads larger than the buffer size */ +dev_dbg (&client->adapter->dev,"block read is too large" ); +return -EINVAL ; + + } +if ((size ==I2C_SMBUS_PROC_CALL ) || + (size ==I2C_SMBUS_BLOCK_PROC_CALL ) || + (read_write ==I2C_SMBUS_READ )) {if (copy_to_user (data, &temp, datasize))return -EFAULT ; }
include/uapi/linux/i2c-dev.h +2 -0
@@ -39,12 +39,14 @@/* This is the structure as used in the I2C_SMBUS ioctl call */ +#ifndef __KERNEL__struct i2c_smbus_ioctl_data {__u8 read_write;__u8 command;__u32 size;union i2c_smbus_data __user *data; }; +#endif /* This is the structure as used in the I2C_RDWR ioctl call */ struct i2c_rdwr_ioctl_data {
include/uapi/linux/i2c.h +2 -0
@@ -109,6 +109,8 @@ struct i2c_msg {#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000/* w/ 1-byte reg. addr. */ #define I2C_FUNC_SMBUS_HOST_NOTIFY 0x10000000/* SMBus 2.0 or later */ #define I2C_FUNC_SMBUS_V3_BLOCK 0x20000000/* Device supports 255 byte block */ +/* Note that I2C_SMBUS ioctl only */ +/* supports a 32 byte block */ #define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \ I2C_FUNC_SMBUS_WRITE_BYTE)
Signature · 1 line
2.32.0
kernel test robot
build bot[PATCH] i2c: dev: fix eno.cocci warnings
drivers/i2c/i2c-dev.c:291:6-12: ERROR: allocation function on line 289 returns NULL not ERR_PTR on failure
From: kernel test robot <[email protected]>
drivers/i2c/i2c-dev.c:291:6-12: ERROR: allocation function on line 289 returns NULL not ERR_PTR on failure
The various basic memory allocation functions don't return ERR_PTR
Generated by: scripts/coccinelle/null/eno.cocci
---
url: https://github.com/0day-ci/linux/commits/Matt-Johnston/MCTP-I2C-driver/20211115-105011 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 1274a4eb318debe33e395bb8bcf8b98e6eb4670f
:::::: branch date: 10 days ago
:::::: commit date: 10 days ago
i2c-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-dev.c +1 -1
@@ -288,7 +288,7 @@ static noinline int i2cdev_ioctl_rdwr(st orig_lens[i] = msgs[i].len; msgs[i].buf =kmalloc (msgs[i].len +I2C_SMBUS_V3_BLOCK_MAX ,GFP_USER | __GFP_NOWARN); -if (IS_ERR (msgs[i].buf)) { +if (!msgs[i].buf) { res =PTR_ERR (msgs[i].buf);break ; }
kernel test robot
build botRe: [PATCH net-next v3 2/6] i2c: dev: Handle 255 byte blocks for i2c ioctl
In reply to Matt JohnstonI love your patch! Perhaps something to improve:
Hi Matt,
I love your patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
url: https://github.com/0day-ci/linux/commits/Matt-Johnston/MCTP-I2C-driver/20211115-105011 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 1274a4eb318debe33e395bb8bcf8b98e6eb4670f config: parisc-randconfig-c024-20211115 (https://download.01.org/0day-ci/archive/20211125/202111251311.2QoOxvVE-lkp(a)intel.com/config) compiler: hppa-linux-gcc (GCC) 11.2.0
If you fix the issue, kindly add following tag as appropriate
cocci warnings: (new ones prefixed by >>)
>> drivers/i2c/i2c-dev.c:291:6-12: ERROR: allocation function on line 289 returns NULL not ERR_PTR on failure
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Matt Johnston
maintainerPATCH v3 3/6 i2c: aspeed: Allow 255 byte block transfers
In reply to Matt Johnston255 byte transfers have been tested on an AST2500 board
--- drivers/i2c/busses/i2c-aspeed.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-aspeed.c +3 -2
@@ -533,7 +533,7 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status) msg->buf[bus->buf_index++] = recv_byte;if (msg->flags &I2C_M_RECV_LEN ) { -if (unlikely (recv_byte >I2C_SMBUS_BLOCK_MAX )) { +if (unlikely (recv_byte >I2C_SMBUS_V3_BLOCK_MAX )) { bus->cmd_err = -EPROTO ;aspeed_i2c_do_stop (bus); goto out_no_complete;
@@ -718,7 +718,8 @@ static int aspeed_i2c_master_xfer(struct i2c_adapter *adap,static u32 aspeed_i2c_functionality (struct i2c_adapter *adap) { -return I2C_FUNC_I2C |I2C_FUNC_SMBUS_EMUL |I2C_FUNC_SMBUS_BLOCK_DATA ; +return I2C_FUNC_I2C |I2C_FUNC_SMBUS_EMUL | +I2C_FUNC_SMBUS_BLOCK_DATA |I2C_FUNC_SMBUS_V3_BLOCK ; }#if IS_ENABLED (CONFIG_I2C_SLAVE )
Signature · 1 line
2.32.0
Matt Johnston
maintainerPATCH v3 4/6 i2c: npcm7xx: Allow 255 byte block SMBus transfers
In reply to Matt Johnston255 byte support has been tested on a npcm750 board
--- drivers/i2c/busses/i2c-npcm7xx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-npcm7xx.c +2 -1
@@ -1399,7 +1399,7 @@ static void npcm_i2c_irq_master_handler_read(struct npcm_i2c *bus)if (bus->read_block_use) {/* first byte in block protocol is the size: */ data =npcm_i2c_rd_byte (bus); - data =clamp_val (data,1 ,I2C_SMBUS_BLOCK_MAX ); + data =clamp_val (data,1 ,I2C_SMBUS_V3_BLOCK_MAX ); bus->rd_size = data + block_extra_bytes_size; bus->rd_buf[bus->rd_ind++] = data;
@@ -2187,6 +2187,7 @@ static u32 npcm_i2c_functionality(struct i2c_adapter *adap)I2C_FUNC_SMBUS_EMUL |I2C_FUNC_SMBUS_BLOCK_DATA |I2C_FUNC_SMBUS_PEC | +I2C_FUNC_SMBUS_V3_BLOCK |I2C_FUNC_SLAVE ; }
Signature · 1 line
2.32.0
Matt Johnston
maintainerPATCH v3 5/6 dt-bindings: net: New binding mctp-i2c-controller
In reply to Matt JohnstonUsed 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 v3 6/6 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)
This driver requires I2C adapters that allow 255 byte transfers (SMBus 3.0) as the specification requires a minimum MTU of 68 bytes.
--- drivers/net/mctp/Kconfig | 12 + drivers/net/mctp/Makefile | 1 + drivers/net/mctp/mctp-i2c.c | 982 ++++++++++++++++++++++++++++++++++++ 3 files changed, 995 insertions(+) create mode 100644 drivers/net/mctp/mctp-i2c.c
drivers/net/mctp/Kconfig +12 -0
@@ -3,6 +3,18 @@ if MCTP menu "MCTP Device Drivers" +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
@@ -0,0 +1 @@ +obj-$(CONFIG_MCTP_TRANSPORT_I2C) += mctp-i2c.o
drivers/net/mctp/mctp-i2c.c new file +982 -0
982 lines not on this page · raw message
Signature · 1 line
2.32.0
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 11 lines · On Mon, 15 Nov 2021 10:49:20 +0800 you wrote:
Hi,
This patch series adds a netdev driver providing MCTP transport over I2C.
It applies against net-next using recent MCTP changes there, though also has I2C core changes for review. I'll leave it to maintainers where it should be applied - please let me know if it needs to be submitted differently.
[...]
Here is the summary with links:
- [net-next,v3,1/6] i2c: core: Allow 255 byte transfers for SMBus 3.x
https://git.kernel.org/netdev/net-next/c/13cae4a104d2 - [net-next,v3,2/6] i2c: dev: Handle 255 byte blocks for i2c ioctl https://git.kernel.org/netdev/net-next/c/84a107e68b34 - [net-next,v3,3/6] i2c: aspeed: Allow 255 byte block transfers https://git.kernel.org/netdev/net-next/c/1b2ba1f591c9 - [net-next,v3,4/6] i2c: npcm7xx: Allow 255 byte block SMBus transfers https://git.kernel.org/netdev/net-next/c/3ef2de27a05a - [net-next,v3,5/6] dt-bindings: net: New binding mctp-i2c-controller https://git.kernel.org/netdev/net-next/c/0b6141eb2b14 - [net-next,v3,6/6] mctp i2c: MCTP I2C binding driver https://git.kernel.org/netdev/net-next/c/80be9b2c0d93
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 3 lines
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
NACK. Please revert. Besides the driver in net, it modifies the I2C core code. This has not been acked by the I2C maintainer (in this case me). So, please don't pull this in via the net tree. The question raised here (extending SMBus calls to 255 byte) is complicated because we need ABI backwards compatibility.
Jakub Kicinski
maintainerQuoted 8 lines · On Mon, 15 Nov 2021 16:30:39 +0100 Wolfram Sang wrote:
Quoted 2 lines
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
NACK. Please revert. Besides the driver in net, it modifies the I2C core code. This has not been acked by the I2C maintainer (in this case me). So, please don't pull this in via the net tree. The question raised here (extending SMBus calls to 255 byte) is complicated because we need ABI backwards compatibility.
Done, sorry: 2f6a470d6545 ("Revert "Merge branch 'mctp-i2c-driver'"")
Quoted 2 lines
Done, sorry:
2f6a470d6545("Revert "Merge branch 'mctp-i2c-driver'"")
No worries. Thanks for the quick fix!
Matt Johnston
maintainerHi Wolfram,
Quoted 2 lines
(extending SMBus calls to 255 byte) is complicated because we need ABI backwards compatibility.
Is it only the i2c-dev ABI that you are concerned about?
I've tested various edge cases of the I2C dev interface, the only ABI change seen is that I2C_RDWR ioctl will now read larger messages with I2C_M_RECV_LEN if userspace provides a larger buffer. I think that is a reasonable change. The i2ctransfer tool provides a 256 byte buffer already.
The attached driver patch creates an artifical I2C bus for testing, with fixed I2C endpoints 0x30 (for block reads) and 0x40 (for block writes). This was written just to test this case, though could be committed if you think it's more useful generally.
The script below runs through the edge cases around 32 bytes, with either 32 or 255 blockmax on two separate i2c-testbus adapters. The patch applies on top of the 255 byte patch series. The script behaviour is the same applied on a clean tree (after fixing up 'V3' code), apart from the final test as expected.
Cheers,
Matt
#!/bin/sh
# Tests for edge cases around 32 byte block size handling in i2c dev # Matt Johnston <[email protected]> 2021
# Two i2c-testbus adapter numbers.
# Bus 15 has v2-only set on i2c-testbus devicetree node, 32 block max V2_BUS=15
# Bus 14 accepts 255 block max
V3_BUS=14
EXPECT_FAIL="exit 3"
FAIL="exit 2"
# Behaviour of 32 byte (V2) and 255 byte (V3) busses is the same for most operations for b in $V2_BUS $V3_BUS; do
echo "Testing bus $b"
############
echo "Testing 31 byte read"
i2cget -y $b 0x30 31 s || $FAIL
echo "Testing 32 byte read"
i2cget -y $b 0x30 32 s || $FAIL
echo "Testing 33 byte read, should fail"
i2cget -y $b 0x30 33 s && $EXPECT_FAIL
echo "Testing 35 byte i2c read, should succeed"
i2cget -y $b 0x30 35 i || $FAIL
echo "Testing 32 byte i2c set length"
i2cset -y $b 0x30 32 || $FAIL
echo "Testing 32 byte i2c read, should succeed"
i2ctransfer -y $b 'r?@0x30' || $FAIL
############
echo "Testing 31 byte smbus write"
i2cset -y $b 0x40 0x0f 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 s || $FAIL wl=$(i2cget -y $b 0x40)
echo "check length ($wl) is 33==0x21"
[ $wl = 0x21 ] || $FAIL
echo "Testing 32 byte smbus write"
i2cset -y $b 0x40 0x0f 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 s || $FAIL wl=$(i2cget -y $b 0x40)
echo "Check length ($wl) is 34==0x22"
[ $wl = 0x22 ] || $FAIL
echo "Testing 33 byte smbus write (fails)"
i2cset -y $b 0x40 0x0f 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 0x77 s && $EXPECT_FAIL
echo "Testing 70 byte i2c write"
i2ctransfer -y $b w70@0x40 123- || $FAIL
wl=$(i2cget -y $b 0x40)
echo "Check length ($wl) is 70==0x46"
[ $wl = 0x46 ] || $FAIL
echo "Done testing bus $b"
done
########## Behaviour V2 vs V3 differs with tests below
echo "Testing difference of V2 bus $V2_BUS"
b=$V2_BUS
echo "Testing 44 byte read set-length (succeeds with a warning of further failure)" i2cset -y $b 0x30 44 || $FAIL
# i2c-testbus checks size against I2C_SMBUS_BLOCK_MAX in the v2-only case. # This is similar to the I2C_SMBUS_BLOCK_MAX vs I2C_SMBUS_V3_BLOCK_MAX # checks changed in i2c-npcm7xx and i2c-aspeed echo "Testing 44 byte i2c read, fails" i2ctransfer -y $b 'r?@0x30' && $EXPECT_FAIL
echo "Done with difference of V2 bus $V2_BUS"
############
echo "Testing difference of V3 bus $V3_BUS"
b=$V3_BUS
echo "Testing 44 byte read set-length"
i2cset -y $b 0x30 44 || $FAIL
echo "Testing 44 byte i2c read, succeeds. (failed prior to 255 byte patch)" i2ctransfer -y $b 'r?@0x30' || $FAIL
echo "Done with difference of V3 bus $V3_BUS"
############
echo
echo "All tests completed as expected"
--
Subject: [PATCH] i2c testbus: Add an I2C bus for testing
The bus provides fixed endpoints to be used for testing i2c-dev or drivers, without needing real hardware. In particular these can test block size limitations.
Devicetree property "v2-only" will limit the bus to 32 byte SMBus messages, otherwise it supports 255 byte SMBus v3 message.
Examples have i2c-testbus attached as bus number 14:
Address 0x30 provides an endpoint to test block reads
i2cget -y 14 0x30 31 s
will read 31 bytes as an smbus read. >32 bytes will fail.
i2cset -y 14 0x30 200
i2ctransfer -y 14 r?@0x30will read 200 bytes as an I2C read.
Address 0x40 is an endpoint to test block writes. The number of bytes written can be read back from the endpoint.
i2cset -y 14 0x40 0x32 0x12 0x13 s
i2ctransfer -y 14 w30@0x40 0xff 0x19-
--- drivers/i2c/busses/Kconfig | 9 ++ drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-testbus.c | 252 +++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 drivers/i2c/busses/i2c-testbus.c
drivers/i2c/busses/Kconfig +9 -0
@@ -1418,4 +1418,13 @@ config I2C_VIRTIO This driver can also be built as a module. If so, the module will be called i2c-virtio. +config I2C_TESTBUS + tristate "Testing I2C Bus Adapter" + help + Build a driver for testing I2C functionality. The bus provides + various clients at fixed addresses with different functionality. + + This driver can also be built as a module. If so, the module + will be called i2c-testbus. + endmenu
drivers/i2c/busses/Makefile +1 -0
@@ -149,5 +149,6 @@ obj-$(CONFIG_I2C_XGENE_SLIMPRO) += i2c-xgene-slimpro.o obj-$(CONFIG_SCx200_ACB) += scx200_acb.o obj-$(CONFIG_I2C_FSI) += i2c-fsi.o obj-$(CONFIG_I2C_VIRTIO) += i2c-virtio.o +obj-$(CONFIG_I2C_TESTBUS) += i2c-testbus.o ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
drivers/i2c/busses/i2c-testbus.c new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
2.32.0
Hi Matt,
sorry for the long delay. This cycle, I am concentrating on overhauling the bus_recovery handling. I am rather unsure if I have the bandwidth for larger block reads this cycle. But it is planned for next cycle.
Quoted 4 lines
Quoted 2 lines
(extending SMBus calls to 255 byte) is complicated because we need ABI backwards compatibility.
Is it only the i2c-dev ABI that you are concerned about?
To at least give you a pointer what we discussed last time, have a look here:
https://lore.kernel.org/r/[email protected]
I can't go into details now because they escaped my mind :/ But I'll work into it again when the bus_recovery thing is done and the recent driver patches are handled. But you probably will get the idea without me...
Thanks for sharing your script and working on the issue.
Happy hacking,
Wolfram