mbox series

[v7,0/8] I3C target mode support

Message ID 20240205233326.552576-1-Frank.Li@nxp.com
Headers show
Series I3C target mode support | expand

Message

Frank Li Feb. 5, 2024, 11:33 p.m. UTC
This  patch introduces support for I3C target mode, which is referenced
with a PCIe Endpoint system. It also establishes a configuration framework
(configfs) for the I3C target controller driver and the I3C target function
driver

Typic usage as

The user can configure the i3c-target-tty device using configfs entry. In
order to change the vendorid, the following commands can be used

        # echo 0x011b > functions/tty/func1/vendor_id
        # echo 0x1000 > functions/tty/func1/part_id
        # echo 0x6 > functions/tty/t/bcr

Binding i3c-target-tty Device to target Controller
------------------------------------------------

In order for the target function device to be useful, it has to be bound to
a I3C target controller driver. Use the configfs to bind the function
device to one of the controller driver present in the system::

        # ln -s functions/pci_epf_test/func1 controllers/44330000.i3c-target/

Host side:
        cat /dev/ttyI3C0
Taret side:
        echo abc >/dev/ttyI3C0

Chagne from v2 to v3
- using 'mode' distingiush master and target.
- move svc-i3c-target.c to under master,
- built together with svc-i3c-master.c

Change from v1 to v2
- change "slave" to "target"
- include master side tty patch
- fixed dtbcheck problem
- fixed kerne-doc check warning

Some review comment may be lost since it is quite long time since v1. Now
master side dependent patches already in linux-next. So sent target side
patches with tty support again.

No sure why an additional "\r\n" appended.

Frank Li (8):
  i3c: add target mode support
  dt-bindings: i3c: svc: add proptery mode
  Documentation: i3c: Add I3C target mode controller and function
  i3c: svc: Add svc-i3c-main.c and svc-i3c.h
  i3c: target: add svc target controller support
  i3c: target: func: add tty driver
  i3c: add API i3c_dev_gettstatus_format1() to get target device status
  tty: i3c: add TTY over I3C master support

 .../bindings/i3c/silvaco,i3c-master.yaml      |  11 +-
 Documentation/driver-api/i3c/index.rst        |   1 +
 .../driver-api/i3c/target/i3c-target-cfs.rst  | 109 +++
 .../driver-api/i3c/target/i3c-target.rst      | 189 +++++
 .../driver-api/i3c/target/i3c-tty-howto.rst   | 109 +++
 Documentation/driver-api/i3c/target/index.rst |  13 +
 drivers/i3c/Kconfig                           |  31 +-
 drivers/i3c/Makefile                          |   3 +
 drivers/i3c/device.c                          |  24 +
 drivers/i3c/func/Kconfig                      |   9 +
 drivers/i3c/func/Makefile                     |   3 +
 drivers/i3c/func/tty.c                        | 474 +++++++++++
 drivers/i3c/i3c-cfs.c                         | 389 +++++++++
 drivers/i3c/internals.h                       |   1 +
 drivers/i3c/master.c                          |  26 +
 drivers/i3c/master/Makefile                   |   3 +-
 drivers/i3c/master/svc-i3c-main.c             |  80 ++
 drivers/i3c/master/svc-i3c-master.c           |  34 +-
 drivers/i3c/master/svc-i3c-target.c           | 776 ++++++++++++++++++
 drivers/i3c/master/svc-i3c.h                  |  15 +
 drivers/i3c/target.c                          | 453 ++++++++++
 drivers/tty/Kconfig                           |  13 +
 drivers/tty/Makefile                          |   1 +
 drivers/tty/i3c_tty.c                         | 428 ++++++++++
 include/linux/i3c/device.h                    |   1 +
 include/linux/i3c/target.h                    | 548 +++++++++++++
 26 files changed, 3713 insertions(+), 31 deletions(-)
 create mode 100644 Documentation/driver-api/i3c/target/i3c-target-cfs.rst
 create mode 100644 Documentation/driver-api/i3c/target/i3c-target.rst
 create mode 100644 Documentation/driver-api/i3c/target/i3c-tty-howto.rst
 create mode 100644 Documentation/driver-api/i3c/target/index.rst
 create mode 100644 drivers/i3c/func/Kconfig
 create mode 100644 drivers/i3c/func/Makefile
 create mode 100644 drivers/i3c/func/tty.c
 create mode 100644 drivers/i3c/i3c-cfs.c
 create mode 100644 drivers/i3c/master/svc-i3c-main.c
 create mode 100644 drivers/i3c/master/svc-i3c-target.c
 create mode 100644 drivers/i3c/master/svc-i3c.h
 create mode 100644 drivers/i3c/target.c
 create mode 100644 drivers/tty/i3c_tty.c
 create mode 100644 include/linux/i3c/target.h

Comments

Joshua Yeong March 6, 2024, 4:01 p.m. UTC | #1
Hi Frank,

> -----Original Message-----
> From: linux-i3c <linux-i3c-bounces@lists.infradead.org> On Behalf Of Frank Li
> Sent: Tuesday, February 6, 2024 7:33 AM
> To: frank.li@nxp.com
> Cc: alexandre.belloni@bootlin.com; conor.culhane@silvaco.com;
> devicetree@vger.kernel.org; gregkh@linuxfoundation.org;
> ilpo.jarvinen@linux.intel.com; imx@lists.linux.dev; jirislaby@kernel.org;
> joe@perches.com; krzysztof.kozlowski+dt@linaro.org;
> krzysztof.kozlowski@linaro.org; linux-i3c@lists.infradead.org; linux-
> kernel@vger.kernel.org; linux-serial@vger.kernel.org;
> miquel.raynal@bootlin.com; robh@kernel.org;
> zbigniew.lukwinski@linux.intel.com
> Subject: [PATCH v7 5/8] i3c: target: add svc target controller support
> 
> Add Silvaco I3C target controller support
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>
> ---
> 
> Notes:
>     Change from v2 to v3
>     - fix build warning
> 
>  drivers/i3c/master/Makefile         |   2 +-
>  drivers/i3c/master/svc-i3c-main.c   |  35 +-
>  drivers/i3c/master/svc-i3c-target.c | 776

I think putting target mode files under "master" might not make sense. We might have to
consider that we may have a "secondary master" mode. Some other ways of splitting
or handling of target mode is needed here.

...

> +
> +#define I3C_SCONFIG	0x4
> +#define   I3C_SCONFIG_SLVENA_MASK	BIT(0)
> +#define	  I3C_SCONFIG_OFFLINE_MASK	BIT(9)
> +#define   I3C_SCONFIG_SADDR_MASK	GENMASK(31, 25)
> +
> +#define I3C_SSTATUS	0x8
> +#define	  I3C_SSTATUS_STNOTSTOP_MASK	BIT(0)
> +#define	  I3C_SSTATUS_STOP_MASK		BIT(10)
> +#define	  I3C_SSTATUS_RX_PEND_MASK	BIT(11)
> +#define   I3C_SSTATUS_TXNOTFULL_MASK	BIT(12)
> +#define	  I3C_SSTATUS_DACHG_MASK	BIT(13)
> +#define	  I3C_SSTATUS_EVDET_MASK	GENMASK(21, 20)
> +#define	  I3C_SSTATUS_EVDET_ACKED	0x3
> +#define	  I3C_SSTATUS_IBIDIS_MASK	BIT(24)
> +#define	  I3C_SSTATUS_HJDIS_MASK	BIT(27)
> +

There is couple of space formatting here that requires to be fixed.

Cheers,
Joshua
Frank Li March 6, 2024, 5:45 p.m. UTC | #2
On Wed, Mar 06, 2024 at 04:01:17PM +0000, Joshua Yeong wrote:
> Hi Frank,
> 
> > -----Original Message-----
> > From: linux-i3c <linux-i3c-bounces@lists.infradead.org> On Behalf Of Frank Li
> > Sent: Tuesday, February 6, 2024 7:33 AM
> > To: frank.li@nxp.com
> > Cc: alexandre.belloni@bootlin.com; conor.culhane@silvaco.com;
> > devicetree@vger.kernel.org; gregkh@linuxfoundation.org;
> > ilpo.jarvinen@linux.intel.com; imx@lists.linux.dev; jirislaby@kernel.org;
> > joe@perches.com; krzysztof.kozlowski+dt@linaro.org;
> > krzysztof.kozlowski@linaro.org; linux-i3c@lists.infradead.org; linux-
> > kernel@vger.kernel.org; linux-serial@vger.kernel.org;
> > miquel.raynal@bootlin.com; robh@kernel.org;
> > zbigniew.lukwinski@linux.intel.com
> > Subject: [PATCH v7 5/8] i3c: target: add svc target controller support
> > 
> > Add Silvaco I3C target controller support
> > 
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> > 
> > Notes:
> >     Change from v2 to v3
> >     - fix build warning
> > 
> >  drivers/i3c/master/Makefile         |   2 +-
> >  drivers/i3c/master/svc-i3c-main.c   |  35 +-
> >  drivers/i3c/master/svc-i3c-target.c | 776
> 
> I think putting target mode files under "master" might not make sense. We might have to
> consider that we may have a "secondary master" mode. Some other ways of splitting
> or handling of target mode is needed here.

I think name 'master' is not good here. Previously only support 'master'
mode, it should be fine. Now many controller are dual mode.

And I3C spec use 'controller/target' instead of 'master/slave'. I think
'controller' as master are quite confused. It can be master controller
and slave controller.

Anyway, slave/master may share some code and resource, even only one file.

So far, I think it is fine put under master now. we can rename 'master'
later when more dual mode controller added. 

Frank 

> 
> ...
> 
> > +
> > +#define I3C_SCONFIG	0x4
> > +#define   I3C_SCONFIG_SLVENA_MASK	BIT(0)
> > +#define	  I3C_SCONFIG_OFFLINE_MASK	BIT(9)
> > +#define   I3C_SCONFIG_SADDR_MASK	GENMASK(31, 25)
> > +
> > +#define I3C_SSTATUS	0x8
> > +#define	  I3C_SSTATUS_STNOTSTOP_MASK	BIT(0)
> > +#define	  I3C_SSTATUS_STOP_MASK		BIT(10)
> > +#define	  I3C_SSTATUS_RX_PEND_MASK	BIT(11)
> > +#define   I3C_SSTATUS_TXNOTFULL_MASK	BIT(12)
> > +#define	  I3C_SSTATUS_DACHG_MASK	BIT(13)
> > +#define	  I3C_SSTATUS_EVDET_MASK	GENMASK(21, 20)
> > +#define	  I3C_SSTATUS_EVDET_ACKED	0x3
> > +#define	  I3C_SSTATUS_IBIDIS_MASK	BIT(24)
> > +#define	  I3C_SSTATUS_HJDIS_MASK	BIT(27)
> > +
> 
> There is couple of space formatting here that requires to be fixed.
> 
> Cheers,
> Joshua
Joshua Yeong March 6, 2024, 6:10 p.m. UTC | #3
> -----Original Message-----
> From: Frank Li <Frank.li@nxp.com>
> Sent: Thursday, March 7, 2024 1:45 AM
> To: Joshua Yeong <joshua.yeong@starfivetech.com>
> Cc: alexandre.belloni@bootlin.com; conor.culhane@silvaco.com;
> devicetree@vger.kernel.org; gregkh@linuxfoundation.org;
> ilpo.jarvinen@linux.intel.com; imx@lists.linux.dev; jirislaby@kernel.org;
> joe@perches.com; krzysztof.kozlowski+dt@linaro.org;
> krzysztof.kozlowski@linaro.org; linux-i3c@lists.infradead.org; linux-
> kernel@vger.kernel.org; linux-serial@vger.kernel.org;
> miquel.raynal@bootlin.com; robh@kernel.org;
> zbigniew.lukwinski@linux.intel.com
> Subject: Re: [PATCH v7 5/8] i3c: target: add svc target controller support
> 
> On Wed, Mar 06, 2024 at 04:01:17PM +0000, Joshua Yeong wrote:
> > Hi Frank,
> >
> > > -----Original Message-----
> > > From: linux-i3c <linux-i3c-bounces@lists.infradead.org> On Behalf Of
> > > Frank Li
> > > Sent: Tuesday, February 6, 2024 7:33 AM
> > > To: frank.li@nxp.com
> > > Cc: alexandre.belloni@bootlin.com; conor.culhane@silvaco.com;
> > > devicetree@vger.kernel.org; gregkh@linuxfoundation.org;
> > > ilpo.jarvinen@linux.intel.com; imx@lists.linux.dev;
> > > jirislaby@kernel.org; joe@perches.com;
> > > krzysztof.kozlowski+dt@linaro.org;
> > > krzysztof.kozlowski@linaro.org; linux-i3c@lists.infradead.org;
> > > linux- kernel@vger.kernel.org; linux-serial@vger.kernel.org;
> > > miquel.raynal@bootlin.com; robh@kernel.org;
> > > zbigniew.lukwinski@linux.intel.com
> > > Subject: [PATCH v7 5/8] i3c: target: add svc target controller
> > > support
> > >
> > > Add Silvaco I3C target controller support
> > >
> > > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > > ---
> > >
> > > Notes:
> > >     Change from v2 to v3
> > >     - fix build warning
> > >
> > >  drivers/i3c/master/Makefile         |   2 +-
> > >  drivers/i3c/master/svc-i3c-main.c   |  35 +-
> > >  drivers/i3c/master/svc-i3c-target.c | 776
> >
> > I think putting target mode files under "master" might not make sense.
> > We might have to consider that we may have a "secondary master" mode.
> > Some other ways of splitting or handling of target mode is needed here.
> 
> I think name 'master' is not good here. Previously only support 'master'
> mode, it should be fine. Now many controller are dual mode.
> 
> And I3C spec use 'controller/target' instead of 'master/slave'. I think
> 'controller' as master are quite confused. It can be master controller and slave
> controller.
> 
> Anyway, slave/master may share some code and resource, even only one file.
> 
> So far, I think it is fine put under master now. we can rename 'master'
> later when more dual mode controller added.
> 
> Frank

I am currently working on secondary-controller mode. I would like to explore if 
we can have a different way to implement various modes.

I am guessing that the current inspiration is coming from the existing i2c 
framework. 

However, I am thinking of having a more generic function to replace the way how 
we register the i3c driver. (existing 'i3c_master_register' or 
'devm_i3c_target_ctrl_create' from yours) Maybe along the line where we can have
all the modes set in a struct and return to the i3c framework. So we only need 1
API to register all the different modes instead of having one each.

> 
> >
> > ...
> >
> > > +
> > > +#define I3C_SCONFIG	0x4
> > > +#define   I3C_SCONFIG_SLVENA_MASK	BIT(0)
> > > +#define	  I3C_SCONFIG_OFFLINE_MASK	BIT(9)
> > > +#define   I3C_SCONFIG_SADDR_MASK	GENMASK(31, 25)
> > > +
> > > +#define I3C_SSTATUS	0x8
> > > +#define	  I3C_SSTATUS_STNOTSTOP_MASK	BIT(0)
> > > +#define	  I3C_SSTATUS_STOP_MASK		BIT(10)
> > > +#define	  I3C_SSTATUS_RX_PEND_MASK	BIT(11)
> > > +#define   I3C_SSTATUS_TXNOTFULL_MASK	BIT(12)
> > > +#define	  I3C_SSTATUS_DACHG_MASK	BIT(13)
> > > +#define	  I3C_SSTATUS_EVDET_MASK	GENMASK(21, 20)
> > > +#define	  I3C_SSTATUS_EVDET_ACKED	0x3
> > > +#define	  I3C_SSTATUS_IBIDIS_MASK	BIT(24)
> > > +#define	  I3C_SSTATUS_HJDIS_MASK	BIT(27)
> > > +
> >
> > There is couple of space formatting here that requires to be fixed.
> >
> > Cheers,
> > Joshua
Frank Li March 6, 2024, 7:11 p.m. UTC | #4
On Wed, Mar 06, 2024 at 06:10:30PM +0000, Joshua Yeong wrote:
> 
> > -----Original Message-----
> > From: Frank Li <Frank.li@nxp.com>
> > Sent: Thursday, March 7, 2024 1:45 AM
> > To: Joshua Yeong <joshua.yeong@starfivetech.com>
> > Cc: alexandre.belloni@bootlin.com; conor.culhane@silvaco.com;
> > devicetree@vger.kernel.org; gregkh@linuxfoundation.org;
> > ilpo.jarvinen@linux.intel.com; imx@lists.linux.dev; jirislaby@kernel.org;
> > joe@perches.com; krzysztof.kozlowski+dt@linaro.org;
> > krzysztof.kozlowski@linaro.org; linux-i3c@lists.infradead.org; linux-
> > kernel@vger.kernel.org; linux-serial@vger.kernel.org;
> > miquel.raynal@bootlin.com; robh@kernel.org;
> > zbigniew.lukwinski@linux.intel.com
> > Subject: Re: [PATCH v7 5/8] i3c: target: add svc target controller support
> > 
> > On Wed, Mar 06, 2024 at 04:01:17PM +0000, Joshua Yeong wrote:
> > > Hi Frank,
> > >
> > > > -----Original Message-----
> > > > From: linux-i3c <linux-i3c-bounces@lists.infradead.org> On Behalf Of
> > > > Frank Li
> > > > Sent: Tuesday, February 6, 2024 7:33 AM
> > > > To: frank.li@nxp.com
> > > > Cc: alexandre.belloni@bootlin.com; conor.culhane@silvaco.com;
> > > > devicetree@vger.kernel.org; gregkh@linuxfoundation.org;
> > > > ilpo.jarvinen@linux.intel.com; imx@lists.linux.dev;
> > > > jirislaby@kernel.org; joe@perches.com;
> > > > krzysztof.kozlowski+dt@linaro.org;
> > > > krzysztof.kozlowski@linaro.org; linux-i3c@lists.infradead.org;
> > > > linux- kernel@vger.kernel.org; linux-serial@vger.kernel.org;
> > > > miquel.raynal@bootlin.com; robh@kernel.org;
> > > > zbigniew.lukwinski@linux.intel.com
> > > > Subject: [PATCH v7 5/8] i3c: target: add svc target controller
> > > > support
> > > >
> > > > Add Silvaco I3C target controller support
> > > >
> > > > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > > > ---
> > > >
> > > > Notes:
> > > >     Change from v2 to v3
> > > >     - fix build warning
> > > >
> > > >  drivers/i3c/master/Makefile         |   2 +-
> > > >  drivers/i3c/master/svc-i3c-main.c   |  35 +-
> > > >  drivers/i3c/master/svc-i3c-target.c | 776
> > >
> > > I think putting target mode files under "master" might not make sense.
> > > We might have to consider that we may have a "secondary master" mode.
> > > Some other ways of splitting or handling of target mode is needed here.
> > 
> > I think name 'master' is not good here. Previously only support 'master'
> > mode, it should be fine. Now many controller are dual mode.
> > 
> > And I3C spec use 'controller/target' instead of 'master/slave'. I think
> > 'controller' as master are quite confused. It can be master controller and slave
> > controller.
> > 
> > Anyway, slave/master may share some code and resource, even only one file.
> > 
> > So far, I think it is fine put under master now. we can rename 'master'
> > later when more dual mode controller added.
> > 
> > Frank
> 
> I am currently working on secondary-controller mode. I would like to explore if 
> we can have a different way to implement various modes.

Second controller should be more similar than master mode.

> 
> I am guessing that the current inspiration is coming from the existing i2c 
> framework.

i2c slave mode is quite simple. The major problem is that the latency to
fill FIFO. Modem async transfer queue should be better handle it. When
host START transfer, fetch one transfer from queue. 

There are only a simple I2c slave test driver in kernel. I think not much
people use it.

> 
> However, I am thinking of having a more generic function to replace the way how 
> we register the i3c driver. (existing 'i3c_master_register' or 
> 'devm_i3c_target_ctrl_create' from yours) Maybe along the line where we can have
> all the modes set in a struct and return to the i3c framework. So we only need 1
> API to register all the different modes instead of having one each.

You can try, but it is not easy. Like USB, PCIE-Endpoint, all was use
different register for difference mode. 

By the way, rename 'master' as 'controller' should be good idea. A I3C IP
can support (master, slave and second) controller.

I think the folder name should not block issue for this patch series.

Frank

> 
> > 
> > >
> > > ...
> > >
> > > > +
> > > > +#define I3C_SCONFIG	0x4
> > > > +#define   I3C_SCONFIG_SLVENA_MASK	BIT(0)
> > > > +#define	  I3C_SCONFIG_OFFLINE_MASK	BIT(9)
> > > > +#define   I3C_SCONFIG_SADDR_MASK	GENMASK(31, 25)
> > > > +
> > > > +#define I3C_SSTATUS	0x8
> > > > +#define	  I3C_SSTATUS_STNOTSTOP_MASK	BIT(0)
> > > > +#define	  I3C_SSTATUS_STOP_MASK		BIT(10)
> > > > +#define	  I3C_SSTATUS_RX_PEND_MASK	BIT(11)
> > > > +#define   I3C_SSTATUS_TXNOTFULL_MASK	BIT(12)
> > > > +#define	  I3C_SSTATUS_DACHG_MASK	BIT(13)
> > > > +#define	  I3C_SSTATUS_EVDET_MASK	GENMASK(21, 20)
> > > > +#define	  I3C_SSTATUS_EVDET_ACKED	0x3
> > > > +#define	  I3C_SSTATUS_IBIDIS_MASK	BIT(24)
> > > > +#define	  I3C_SSTATUS_HJDIS_MASK	BIT(27)
> > > > +
> > >
> > > There is couple of space formatting here that requires to be fixed.
> > >
> > > Cheers,
> > > Joshua