Skip to contentSkip to conversation

Introduce i3c device userspace interface

RFC Superseded Vitor Soares 3 participants 20 messages Dec 10, 2019 – Dec 20, 2019 I3C

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

RFC 1/5 i3c: master: export i3c_masterdev_type

In reply to Vitor Soares

Export i3c_masterdev_type symbol so i3cdev module can verify if an i3c device is a master device.

---
 drivers/i3c/internals.h | 1 +
 drivers/i3c/master.c    | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/i3c/internals.h +1 -0
index 86b7b44..bc062e8 100644
@@ -11,6 +11,7 @@
 #include <linux/i3c/master.h>
 
 extern struct bus_type i3c_bus_type;
+extern const struct device_type i3c_masterdev_type;
 
 void i3c_bus_normaluse_lock(struct i3c_bus *bus);
 void i3c_bus_normaluse_unlock(struct i3c_bus *bus);
drivers/i3c/master.c +2 -1
index 0436916..a1fb5f7 100644
@@ -523,9 +523,10 @@ static void i3c_masterdev_release(struct device *dev)
 	of_node_put(dev->of_node);
 }
 
-static const struct device_type i3c_masterdev_type = {
+const struct device_type i3c_masterdev_type = {
 	.groups	= i3c_masterdev_groups,
 };
+EXPORT_SYMBOL_GPL(i3c_masterdev_type);
 
 int i3c_bus_set_mode(struct i3c_bus *i3cbus, enum i3c_bus_mode mode,
 		     unsigned long max_i2c_scl_rate)
Signature · 1 line
2.7.4
#6 lore raw

RFC 4/5 i3c: master: add i3c_for_each_dev helper

In reply to Vitor Soares

Introduce i3c_for_each_dev(), an i3c device iterator for use by i3cdev.

---
 drivers/i3c/internals.h |  1 +
 drivers/i3c/master.c    | 12 ++++++++++++
 2 files changed, 13 insertions(+)
drivers/i3c/internals.h +1 -0
index bc062e8..a6deedf 100644
@@ -24,4 +24,5 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev);
 int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
 			       const struct i3c_ibi_setup *req);
 void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev);
+int i3c_for_each_dev(void *data, int (*fn)(struct device *, void *));
 #endif /* I3C_INTERNAL_H */
drivers/i3c/master.c +12 -0
index a9df276..cc41efe 100644
@@ -2640,6 +2640,18 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
 	dev->ibi = NULL;
 }
 
+int i3c_for_each_dev(void *data, int (*fn)(struct device *, void *))
+{
+	int res;
+
+	mutex_lock(&i3c_core_lock);
+	res = bus_for_each_dev(&i3c_bus_type, NULL, data, fn);
+	mutex_unlock(&i3c_core_lock);
+
+	return res;
+}
+EXPORT_SYMBOL_GPL(i3c_for_each_dev);
+
 static int __init i3c_init(void)
 {
 	return bus_register(&i3c_bus_type);
Signature · 7 lines
2.7.4


_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#7 lore raw

RFC 5/5 i3c: add i3cdev module to expose i3c dev in /dev

In reply to Vitor Soares

This patch adds user-mode support to I3C SDR transfers.

The module is based on i2c-dev.c with the following features:
- expose on /dev the i3c devices dynamically based on if they have a device driver bound.
- Dynamically allocate the char device Major number.

---
 drivers/i3c/Kconfig             |  15 ++
 drivers/i3c/Makefile            |   1 +
 drivers/i3c/i3cdev.c            | 438 ++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/i3c/i3cdev.h |  27 +++
 4 files changed, 481 insertions(+)
 create mode 100644 drivers/i3c/i3cdev.c
 create mode 100644 include/uapi/linux/i3c/i3cdev.h
drivers/i3c/Kconfig +15 -0
index 30a4415..0164276 100644
@@ -20,5 +20,20 @@ menuconfig I3C
 	  will be called i3c.
 
 if I3C
+
+config I3CDEV
+	tristate "I3C device interface"
+	depends on I3C
+	help
+	  Say Y here to use i3c-* device files, usually found in the /dev
+	  directory on your system.  They make it possible to have user-space
+	  programs use the I3C devices.
+
+	  This support is also available as a module.  If so, the module
+	  will be called i3cdev.
+
+	  Note that this application programming interface is EXPERIMENTAL
+	  and hence SUBJECT TO CHANGE WITHOUT NOTICE while it stabilizes.
+
 source "drivers/i3c/master/Kconfig"
 endif # I3C
drivers/i3c/Makefile +1 -0
index 11982ef..606d422 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 i3c-y				:= device.o master.o
 obj-$(CONFIG_I3C)		+= i3c.o
+obj-$(CONFIG_I3CDEV)		+= i3cdev.o
 obj-$(CONFIG_I3C)		+= master/
drivers/i3c/i3cdev.c new file +438 -0

438 lines not on this page · raw message

include/uapi/linux/i3c/i3cdev.h new file +27 -0
new file mode 100644
index 0000000..4030043
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates.
+ *
+ * Author: Vitor Soares <[email protected]>
+ */
+
+#ifndef _UAPI_I3C_DEV_H_
+#define _UAPI_I3C_DEV_H_
+
+#include <linux/types.h>
+#include <linux/ioctl.h>
+
+/* IOCTL commands */
+#define I3C_DEV_IOC_MAGIC	0x07
+
+struct i3c_ioc_priv_xfer {
+	struct i3c_priv_xfer __user *xfers;	/* pointers to i3c_priv_xfer */
+	__u32 nxfers;				/* number of i3c_priv_xfer */
+};
+
+#define I3C_IOC_PRIV_XFER	\
+	_IOW(I3C_DEV_IOC_MAGIC, 30, struct i3c_ioc_priv_xfer)
+
+#define  I3C_IOC_PRIV_XFER_MAX_MSGS	42
+
+#endif
Signature · 1 line
2.7.4
#0 lore raw

cover Introduce i3c device userspace interface

For today there is no way to use i3c devices from user space and the introduction of such API will help developers during the i3c device or i3c host controllers development.

The i3cdev module is highly based on i2c-dev and yet I tried to address the concerns raised in [1].

NOTES:
- The i3cdev dynamically request an unused major number.

- The i3c devices are dynamically exposed/removed from dev/ folder based on if they have a device driver bound to it.

- For now, the module exposes i3c devices without device driver on dev/i3c-<bus>-<pid>, but we can change the path to dev/bus/i3c/<bus>-<pid> or dev/i3c/<bus>-<pid>.

- As in the i2c subsystem, here it is exposed the i3c_priv_xfer to userspace. I tried to use a dedicated structure as in spidev but I don't see any obvious advantage.

- Since the i3c API only exposes i3c_priv_xfer to devices, for now, the module just makes use of one ioctl(). This can change in the future with the introduction hdr commands or by the need of exposing some CCC commands to the device API (private contract between master-slave). Regarding the i3c device info, some information is already available through sysfs. We can add more device attributes to expose more information or add a dedicated ioctl() request for that purpose or both.

- Similar to i2c, I have also created a tool that you can find in [2] for testing purposes. If you have some time available I would appreciate your feedback about it as well.

[1] https://lkml.org/lkml/2018/11/15/853
[2] https://github.com/vitor-soares-snps/i3c-tools.git

Vitor Soares (5):
i3c: master: export i3c_masterdev_type
i3c: master: export i3c_bus_type symbol
i3c: device: expose transfer strutures to uapi
i3c: master: add i3c_for_each_dev helper
i3c: add i3cdev module to expose i3c dev in /dev

 drivers/i3c/Kconfig             |  15 ++
 drivers/i3c/Makefile            |   1 +
 drivers/i3c/i3cdev.c            | 438 ++++++++++++++++++++++++++++++++++++++++
 drivers/i3c/internals.h         |   2 +
 drivers/i3c/master.c            |  16 +-
 include/linux/i3c/device.h      |  54 +----
 include/uapi/linux/i3c/device.h |  66 ++++++
 include/uapi/linux/i3c/i3cdev.h |  27 +++
 8 files changed, 565 insertions(+), 54 deletions(-)
 create mode 100644 drivers/i3c/i3cdev.c
 create mode 100644 include/uapi/linux/i3c/device.h
 create mode 100644 include/uapi/linux/i3c/i3cdev.h
Signature · 7 lines
2.7.4


_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#2 lore raw

RFC 2/5 i3c: master: export i3c_bus_type symbol

Export i3c_bus_type symbol so i3cdev can register a notifier chain for the i3c bus.

---
 drivers/i3c/master.c | 1 +
 1 file changed, 1 insertion(+)
drivers/i3c/master.c +1 -0
index a1fb5f7..a9df276 100644
@@ -321,6 +321,7 @@ struct bus_type i3c_bus_type = {
 	.probe = i3c_device_probe,
 	.remove = i3c_device_remove,
 };
+EXPORT_SYMBOL_GPL(i3c_bus_type);
 
 static enum i3c_addr_slot_status
 i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr)
Signature · 7 lines
2.7.4


_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#3 lore raw

RFC 3/5 i3c: device: expose transfer strutures to uapi

In reply to Vitor Soares

Move i3c transfer related structures to uapi, so they can be access by userspace.

---
 include/linux/i3c/device.h      | 54 +--------------------------------
 include/uapi/linux/i3c/device.h | 66 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 53 deletions(-)
 create mode 100644 include/uapi/linux/i3c/device.h
include/linux/i3c/device.h +1 -53
index de102e4..1df05c2 100644
@@ -14,59 +14,7 @@
 #include <linux/kconfig.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
-
-/**
- * enum i3c_error_code - I3C error codes
- *
- * These are the standard error codes as defined by the I3C specification.
- * When -EIO is returned by the i3c_device_do_priv_xfers() or
- * i3c_device_send_hdr_cmds() one can check the error code in
- * &struct_i3c_priv_xfer.err or &struct i3c_hdr_cmd.err to get a better idea of
- * what went wrong.
- *
- * @I3C_ERROR_UNKNOWN: unknown error, usually means the error is not I3C
- *		       related
- * @I3C_ERROR_M0: M0 error
- * @I3C_ERROR_M1: M1 error
- * @I3C_ERROR_M2: M2 error
- */
-enum i3c_error_code {
-	I3C_ERROR_UNKNOWN = 0,
-	I3C_ERROR_M0 = 1,
-	I3C_ERROR_M1,
-	I3C_ERROR_M2,
-};
-
-/**
- * enum i3c_hdr_mode - HDR mode ids
- * @I3C_HDR_DDR: DDR mode
- * @I3C_HDR_TSP: TSP mode
- * @I3C_HDR_TSL: TSL mode
- */
-enum i3c_hdr_mode {
-	I3C_HDR_DDR,
-	I3C_HDR_TSP,
-	I3C_HDR_TSL,
-};
-
-/**
- * struct i3c_priv_xfer - I3C SDR private transfer
- * @rnw: encodes the transfer direction. true for a read, false for a write
- * @len: transfer length in bytes of the transfer
- * @data: input/output buffer
- * @data.in: input buffer. Must point to a DMA-able buffer
- * @data.out: output buffer. Must point to a DMA-able buffer
- * @err: I3C error code
- */
-struct i3c_priv_xfer {
-	u8 rnw;
-	u16 len;
-	union {
-		void *in;
-		const void *out;
-	} data;
-	enum i3c_error_code err;
-};
+#include <uapi/linux/i3c/device.h>
 
 /**
  * enum i3c_dcr - I3C DCR values
include/uapi/linux/i3c/device.h new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

Re: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

In reply to Vitor Soares

include/uapi/linux/i3c/i3cdev.h line 25

Quoted 13 lines · Vitor Soares
include/uapi/linux/i3c/i3cdev.h new file +12 -0
+/* IOCTL commands */
+#define I3C_DEV_IOC_MAGIC      0x07
+
+struct i3c_ioc_priv_xfer {
+       struct i3c_priv_xfer __user *xfers;     /* pointers to i3c_priv_xfer */
+       __u32 nxfers;                           /* number of i3c_priv_xfer */
+};
+
+#define I3C_IOC_PRIV_XFER      \
+       _IOW(I3C_DEV_IOC_MAGIC, 30, struct i3c_ioc_priv_xfer)
+
+#define  I3C_IOC_PRIV_XFER_MAX_MSGS    42

This is not a great data structure for UAPI, please see
https://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git/tree/Documentation/core-api/ioctl.rst?h=compat-ioctl-endgame&id=927324b7900ee9b877691a8b237e272fabb21bf5

for some background. I'm planning to submit that documentation for mainline integration soon.

Arnd

#9 lore raw

RE: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

Hi Arnd,

From: Arnd Bergmann <[email protected]>
Date: Tue, Dec 10, 2019 at 17:51:14

Quoted 18 lines · Vitor Soares

include/uapi/linux/i3c/i3cdev.h line 25

Quoted 13 lines
include/uapi/linux/i3c/i3cdev.h new file +12 -0
+/* IOCTL commands */
+#define I3C_DEV_IOC_MAGIC      0x07
+
+struct i3c_ioc_priv_xfer {
+       struct i3c_priv_xfer __user *xfers;     /* pointers to i3c_priv_xfer */
+       __u32 nxfers;                           /* number of i3c_priv_xfer */
+};
+
+#define I3C_IOC_PRIV_XFER      \
+       _IOW(I3C_DEV_IOC_MAGIC, 30, struct i3c_ioc_priv_xfer)
+
+#define  I3C_IOC_PRIV_XFER_MAX_MSGS    42

This is not a great data structure for UAPI, please see
https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_arnd_playground.git_tree_Documentation_core-2Dapi_ioctl.rst-3Fh-3Dcompat-2Dioctl-2Dendgame-26id-3D927324b7900ee9b877691a8b237e272fabb21bf5&d=DwIBaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=5Q9WjK0o93NR7DQ9NM6So6mfdgpNnZnSaP8qMpgaC7E&s=LzzjrUQAG8fx5jkVyK73dBDrahNAvk09Cxxlx3KOiXI&e=

Quoted 4 lines

for some background. I'm planning to submit that documentation for mainline integration soon.

Arnd

Thanks for sharing the document.

My understanding is that I should use a data structure like the struct spi_ioc_transfer, with this I may also use the same ioctl command definition. Am I right?
In the documentation you also refer the compact_ioctl() and It is not clear to me if the compact_ioctl() is mandatory in this case. Should I implement it as well?

Best regards,
Vitor Soares

#10 lore raw

Re: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

Quoted 24 lines · Vitor Soares

From: Arnd Bergmann <[email protected]>
Date: Tue, Dec 10, 2019 at 17:51:14

Quoted 21 lines · Vitor Soares

include/uapi/linux/i3c/i3cdev.h line 25

Quoted 13 lines
include/uapi/linux/i3c/i3cdev.h new file +12 -0
+/* IOCTL commands */
+#define I3C_DEV_IOC_MAGIC      0x07
+
+struct i3c_ioc_priv_xfer {
+       struct i3c_priv_xfer __user *xfers;     /* pointers to i3c_priv_xfer */
+       __u32 nxfers;                           /* number of i3c_priv_xfer */
+};
+
+#define I3C_IOC_PRIV_XFER      \
+       _IOW(I3C_DEV_IOC_MAGIC, 30, struct i3c_ioc_priv_xfer)
+
+#define  I3C_IOC_PRIV_XFER_MAX_MSGS    42

This is not a great data structure for UAPI, please see
https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_arnd_playground.git_tree_Documentation_core-2Dapi_ioctl.rst-3Fh-3Dcompat-2Dioctl-2Dendgame-26id-3D927324b7900ee9b877691a8b237e272fabb21bf5&d=DwIBaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=5Q9WjK0o93NR7DQ9NM6So6mfdgpNnZnSaP8qMpgaC7E&s=LzzjrUQAG8fx5jkVyK73dBDrahNAvk09Cxxlx3KOiXI&e=

for some background. I'm planning to submit that documentation for mainline integration soon.

Quoted 7 lines
Quoted 1 line

Arnd

Thanks for sharing the document.

My understanding is that I should use a data structure like the struct spi_ioc_transfer, with this I may also use the same ioctl command definition. Am I right?

Yes, that would be an example of a structure that follows the best practices from my document. It is still rather complex, so if you can make it any simpler, that would be ideal.

Quoted 3 lines

In the documentation you also refer the compact_ioctl() and It is not clear to me if the compact_ioctl() is mandatory in this case. Should I implement it as well?

If the structure is defined like that, you just need to set ".compat_ioctl=compat_ptr_ioctl," in the file_operations structure and it will work, but you cannot skip that step.

As your interface is basically just read/write based, I wonder if there is a way to completely avoid the ioctl and instead use io_submit() as the primary interface.

Arnd

#11 lore raw

RE: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

Hi Arnd,

From: Arnd Bergmann <[email protected]>
Date: Tue, Dec 10, 2019 at 19:37:14

Quoted 29 lines · Vitor Soares
Quoted 28 lines

From: Arnd Bergmann <[email protected]>
Date: Tue, Dec 10, 2019 at 17:51:14

Quoted 18 lines · Vitor Soares

include/uapi/linux/i3c/i3cdev.h line 25

Quoted 13 lines
include/uapi/linux/i3c/i3cdev.h new file +12 -0
+/* IOCTL commands */
+#define I3C_DEV_IOC_MAGIC      0x07
+
+struct i3c_ioc_priv_xfer {
+       struct i3c_priv_xfer __user *xfers;     /* pointers to i3c_priv_xfer */
+       __u32 nxfers;                           /* number of i3c_priv_xfer */
+};
+
+#define I3C_IOC_PRIV_XFER      \
+       _IOW(I3C_DEV_IOC_MAGIC, 30, struct i3c_ioc_priv_xfer)
+
+#define  I3C_IOC_PRIV_XFER_MAX_MSGS    42

This is not a great data structure for UAPI, please see
https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_arnd_playground.git_tree_Documentation_core-2Dapi_ioctl.rst-3Fh-3Dcompat-2Dioctl-2Dendgame-26id-3D927324b7900ee9b877691a8b237e272fabb21bf5&d=DwIBaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=5Q9WjK0o93NR7DQ9NM6So6mfdgpNnZnSaP8qMpgaC7E&s=LzzjrUQAG8fx5jkVyK73dBDrahNAvk09Cxxlx3KOiXI&e=

Quoted 4 lines

for some background. I'm planning to submit that documentation for mainline integration soon.

Arnd

Thanks for sharing the document.

Quoted 7 lines
Quoted 3 lines

My understanding is that I should use a data structure like the struct spi_ioc_transfer, with this I may also use the same ioctl command definition. Am I right?

Yes, that would be an example of a structure that follows the best practices from my document. It is still rather complex, so if you can make it any simpler, that would be ideal.

I will try to do that.

Quoted 8 lines
Quoted 4 lines

In the documentation you also refer the compact_ioctl() and It is not clear to me if the compact_ioctl() is mandatory in this case. Should I implement it as well?

If the structure is defined like that, you just need to set ".compat_ioctl=compat_ptr_ioctl," in the file_operations structure and it will work, but you cannot skip that step.

Thanks, now I know that is mandatory 😊.

Quoted 6 lines

As your interface is basically just read/write based, I wonder if there is a way to completely avoid the ioctl and instead use io_submit() as the primary interface.

Arnd

I confess that I wasn't familiar with io_submit() until now and went straightway for the ioctl() approach.
So far, my understanding is that io_submit() will call .write or .read of i3cdev module depending on the iocb command. if so, we won't be able to do a repeated start between a multiple iocb in the same list, right?

Apart from this private read/write need, another requirement that leads me to use the ioctl() was:
- When we support HDR command in i3c subsystem we can expand the ioctl() command to support it.
- For now, device API doesn't expose CCC commands but some of them are used for a private contract between master and device and we likely need that support in the future as well.

Thanks,
Best regards,
Vitor Soares

_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c

#12 lore raw

Re: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

Quoted 10 lines · Vitor Soares

From: Arnd Bergmann <[email protected]>
Date: Tue, Dec 10, 2019 at 19:37:14

Quoted 7 lines · Vitor Soares
Quoted 3 lines

From: Arnd Bergmann <[email protected]>
Date: Tue, Dec 10, 2019 at 17:51:14

Quoted 1 line · Vitor Soares

As your interface is basically just read/write based, I wonder if there is a way to completely avoid the ioctl and instead use io_submit() as the primary interface.

Quoted 5 lines

I confess that I wasn't familiar with io_submit() until now and went straightway for the ioctl() approach.
So far, my understanding is that io_submit() will call .write or .read of i3cdev module depending on the iocb command. if so, we won't be able to do a repeated start between a multiple iocb in the same list, right?

I'm not sure what you mean with "repeated start", but it's definitely possible that io_submit() is not a useful interface for i3c. The main advantage would be that it avoids creating a complex ioctl command.

Quoted 7 lines

Apart from this private read/write need, another requirement that leads me to use the ioctl() was:
- When we support HDR command in i3c subsystem we can expand the ioctl() command to support it.
- For now, device API doesn't expose CCC commands but some of them are used for a private contract between master and device and we likely need that support in the future as well.

I think you could still have both the io_submit() interface for basic I/O (if you can get it to do what you want), plus an ioctl interface for more complex interactions.

Arnd

#4 lore raw

Re: [RFC 3/5] i3c: device: expose transfer strutures to uapi

In reply to Vitor Soares

include/uapi/linux/i3c/device.h line 1

Quoted 4 lines · Vitor Soares
include/uapi/linux/i3c/device.h new file +1 -0
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0 */

Not a valid uapi SPDX license :(

Quoted 21 lines
include/uapi/linux/i3c/device.h new file +21 -0
+/*
+ * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates.
+ *
+ * Author: Vitor Soares <[email protected]>
+ */
+
+#ifndef _UAPI_LINUX_I3C_DEVICE_H
+#define _UAPI_LINUX_I3C_DEVICE_H
+
+#include <linux/types.h>
+
+/**
+ * enum i3c_error_code - I3C error codes
+ *
+ * These are the standard error codes as defined by the I3C specification.
+ * When -EIO is returned by the i3c_device_do_priv_xfers() or
+ * i3c_device_send_hdr_cmds() one can check the error code in
+ * &struct_i3c_priv_xfer.err or &struct i3c_hdr_cmd.err to get a better idea of
+ * what went wrong.
+ *
+ * @I3C_ERROR_UNKNOWN: unknown error, usually means the error is not I3C

include/uapi/linux/i3c/device.h line 32

Quoted 10 lines
include/uapi/linux/i3c/device.h new file +10 -0
+ *		       related
+ * @I3C_ERROR_M0: M0 error
+ * @I3C_ERROR_M1: M1 error
+ * @I3C_ERROR_M2: M2 error
+ */
+enum i3c_error_code {
+	I3C_ERROR_UNKNOWN = 0,
+	I3C_ERROR_M0 = 1,
+	I3C_ERROR_M1,
+	I3C_ERROR_M2,

You have to specify all of these.

include/uapi/linux/i3c/device.h line 44

Quoted 12 lines
include/uapi/linux/i3c/device.h new file +12 -0
+};
+
+/**
+ * enum i3c_hdr_mode - HDR mode ids
+ * @I3C_HDR_DDR: DDR mode
+ * @I3C_HDR_TSP: TSP mode
+ * @I3C_HDR_TSL: TSL mode
+ */
+enum i3c_hdr_mode {
+	I3C_HDR_DDR,
+	I3C_HDR_TSP,
+	I3C_HDR_TSL,

same here.

Quoted 9 lines
include/uapi/linux/i3c/device.h new file +9 -0
+};
+
+/**
+ * struct i3c_priv_xfer - I3C SDR private transfer
+ * @rnw: encodes the transfer direction. true for a read, false for a write
+ * @len: transfer length in bytes of the transfer
+ * @data: input/output buffer
+ * @data.in: input buffer. Must point to a DMA-able buffer
+ * @data.out: output buffer. Must point to a DMA-able buffer

include/uapi/linux/i3c/device.h line 63

Quoted 10 lines
include/uapi/linux/i3c/device.h new file +10 -0
+ * @err: I3C error code
+ */
+struct i3c_priv_xfer {
+	u8 rnw;
+	u16 len;
+	union {
+		void *in;
+		const void *out;
+	} data;
+	enum i3c_error_code err;

Ick, that's a horrid user/kernel api structure that will not work at all.

Please fix.

thanks,

greg k-h

#14 lore raw

Re: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

In reply to Vitor Soares

drivers/i3c/i3cdev.c line 392

Quoted 5 lines · Vitor Soares
drivers/i3c/i3cdev.c new file +5 -0
+static int __init i3cdev_init(void)
+{
+	int res;
+
+	pr_info("i3c /dev entries driver\n");

Please remove debugging information, kernel code should be quiet unless something goes wrong.

drivers/i3c/i3cdev.c line 395

Quoted 2 lines
drivers/i3c/i3cdev.c new file +2 -0
+	/* Dynamically request unused major number */
+	res = alloc_chrdev_region(&i3cdev_number, 0, N_I3C_MINORS, "i3c");

Do you really need a whole major, or will a few minors work?

thanks,

greg k-h

#19 lore raw

Re: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

In reply to Vitor Soares
Quoted 1 line · Vitor Soares

+static struct i3cdev_data *i3cdev_get_by_minor(unsigned int minor)

Why? Why not just embed the structure in the cdev if you really need it?

drivers/i3c/i3cdev.c line 82

Quoted 6 lines
drivers/i3c/i3cdev.c new file +6 -0
+static struct i3cdev_data *get_free_i3cdev(struct i3c_device *i3c)
+{
+	struct i3cdev_data *i3cdev;
+	unsigned long minor;
+
+	minor = find_first_zero_bit(minors, N_I3C_MINORS);

No locking, fun!!!

:(

Why not use an idr instead, that is what it is there for. Don't try to roll your own.

thanks,

greg k-h

#5 lore raw

RE: [RFC 3/5] i3c: device: expose transfer strutures to uapi

In reply to Greg KH

HI Greg,

From: Greg KH <[email protected]>
Date: Thu, Dec 12, 2019 at 14:42:33

Quoted 7 lines · Vitor Soares

include/uapi/linux/i3c/device.h line 1

Quoted 4 lines
include/uapi/linux/i3c/device.h new file +1 -0
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0 */

Not a valid uapi SPDX license :(

Sorry, I missed that one. I already got the right SPDX.

Quoted 75 lines
Quoted 23 lines
include/uapi/linux/i3c/device.h new file +21 -0
+/*
+ * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates.
+ *
+ * Author: Vitor Soares <[email protected]>
+ */
+
+#ifndef _UAPI_LINUX_I3C_DEVICE_H
+#define _UAPI_LINUX_I3C_DEVICE_H
+
+#include <linux/types.h>
+
+/**
+ * enum i3c_error_code - I3C error codes
+ *
+ * These are the standard error codes as defined by the I3C specification.
+ * When -EIO is returned by the i3c_device_do_priv_xfers() or
+ * i3c_device_send_hdr_cmds() one can check the error code in
+ * &struct_i3c_priv_xfer.err or &struct i3c_hdr_cmd.err to get a better idea of
+ * what went wrong.
+ *
+ * @I3C_ERROR_UNKNOWN: unknown error, usually means the error is not I3C

include/uapi/linux/i3c/device.h line 32

Quoted 10 lines
include/uapi/linux/i3c/device.h new file +10 -0
+ *		       related
+ * @I3C_ERROR_M0: M0 error
+ * @I3C_ERROR_M1: M1 error
+ * @I3C_ERROR_M2: M2 error
+ */
+enum i3c_error_code {
+	I3C_ERROR_UNKNOWN = 0,
+	I3C_ERROR_M0 = 1,
+	I3C_ERROR_M1,
+	I3C_ERROR_M2,

You have to specify all of these.

include/uapi/linux/i3c/device.h line 44

Quoted 12 lines
include/uapi/linux/i3c/device.h new file +12 -0
+};
+
+/**
+ * enum i3c_hdr_mode - HDR mode ids
+ * @I3C_HDR_DDR: DDR mode
+ * @I3C_HDR_TSP: TSP mode
+ * @I3C_HDR_TSL: TSL mode
+ */
+enum i3c_hdr_mode {
+	I3C_HDR_DDR,
+	I3C_HDR_TSP,
+	I3C_HDR_TSL,

same here.

Quoted 9 lines
include/uapi/linux/i3c/device.h new file +9 -0
+};
+
+/**
+ * struct i3c_priv_xfer - I3C SDR private transfer
+ * @rnw: encodes the transfer direction. true for a read, false for a write
+ * @len: transfer length in bytes of the transfer
+ * @data: input/output buffer
+ * @data.in: input buffer. Must point to a DMA-able buffer
+ * @data.out: output buffer. Must point to a DMA-able buffer

include/uapi/linux/i3c/device.h line 63

Quoted 10 lines
include/uapi/linux/i3c/device.h new file +10 -0
+ * @err: I3C error code
+ */
+struct i3c_priv_xfer {
+	u8 rnw;
+	u16 len;
+	union {
+		void *in;
+		const void *out;
+	} data;
+	enum i3c_error_code err;

Ick, that's a horrid user/kernel api structure that will not work at all.

Quoted 5 lines

Please fix.

thanks,

greg k-h

Thanks for your feedback, I will address it in next version.

Best regards,
Vitor Soares

#15 lore raw

RE: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

In reply to Greg KH

Hi Greg,

From: Greg KH <[email protected]>
Date: Thu, Dec 12, 2019 at 14:44:59

Quoted 9 lines · Vitor Soares

drivers/i3c/i3cdev.c line 392

Quoted 5 lines
drivers/i3c/i3cdev.c new file +5 -0
+static int __init i3cdev_init(void)
+{
+	int res;
+
+	pr_info("i3c /dev entries driver\n");

Please remove debugging information, kernel code should be quiet unless something goes wrong.

I will remove it.

Quoted 9 lines

drivers/i3c/i3cdev.c line 395

Quoted 3 lines
drivers/i3c/i3cdev.c new file +2 -0
+	/* Dynamically request unused major number */
+	res = alloc_chrdev_region(&i3cdev_number, 0, N_I3C_MINORS, "i3c");

Do you really need a whole major, or will a few minors work?

thanks,

greg k-h

I'm reserving one per device. What do you suggest?

Best regards,
Vitor Soares

_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c

#16 lore raw

Re: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

Quoted 23 lines · Vitor Soares

Hi Greg,

From: Greg KH <[email protected]>
Date: Thu, Dec 12, 2019 at 14:44:59

Quoted 9 lines · Vitor Soares

drivers/i3c/i3cdev.c line 392

Quoted 5 lines
drivers/i3c/i3cdev.c new file +5 -0
+static int __init i3cdev_init(void)
+{
+	int res;
+
+	pr_info("i3c /dev entries driver\n");

Please remove debugging information, kernel code should be quiet unless something goes wrong.

I will remove it.

Quoted 6 lines

drivers/i3c/i3cdev.c line 395

Quoted 3 lines
drivers/i3c/i3cdev.c new file +2 -0
+	/* Dynamically request unused major number */
+	res = alloc_chrdev_region(&i3cdev_number, 0, N_I3C_MINORS, "i3c");

Do you really need a whole major, or will a few minors work?

Quoted 5 lines
Quoted 3 lines

thanks,

greg k-h

I'm reserving one per device. What do you suggest?

How many devices do you have in a system?

#17 lore raw

RE: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

From: Greg KH <[email protected]>
Date: Thu, Dec 12, 2019 at 16:00:45

Quoted 24 lines · Vitor Soares
Quoted 23 lines

Hi Greg,

From: Greg KH <[email protected]>
Date: Thu, Dec 12, 2019 at 14:44:59

Quoted 9 lines · Vitor Soares

drivers/i3c/i3cdev.c line 392

Quoted 5 lines
drivers/i3c/i3cdev.c new file +5 -0
+static int __init i3cdev_init(void)
+{
+	int res;
+
+	pr_info("i3c /dev entries driver\n");

Please remove debugging information, kernel code should be quiet unless something goes wrong.

I will remove it.

Quoted 6 lines

drivers/i3c/i3cdev.c line 395

Quoted 3 lines
drivers/i3c/i3cdev.c new file +2 -0
+	/* Dynamically request unused major number */
+	res = alloc_chrdev_region(&i3cdev_number, 0, N_I3C_MINORS, "i3c");

Do you really need a whole major, or will a few minors work?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

thanks,

greg k-h

I'm reserving one per device. What do you suggest?

How many devices do you have in a system?

According to MIPI I3C spec, the maximum number of devices on a bus will depend on trace length, bus load, and clock requirements.

Frankly, I don't know what is the best compromise because it depends from system to system and the end-use of it. In my case, I started developing this to help me during the HC controller driver development. Even If I choose a fixed major, I wouldn't know in which one i3c fits.

Best regards,
Vitor Soares

#18 lore raw

Re: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

Quoted 35 lines · Vitor Soares

From: Greg KH <[email protected]>
Date: Thu, Dec 12, 2019 at 16:00:45

Quoted 24 lines · Vitor Soares
Quoted 23 lines

Hi Greg,

From: Greg KH <[email protected]>
Date: Thu, Dec 12, 2019 at 14:44:59

Quoted 9 lines · Vitor Soares

drivers/i3c/i3cdev.c line 392

Quoted 5 lines
drivers/i3c/i3cdev.c new file +5 -0
+static int __init i3cdev_init(void)
+{
+	int res;
+
+	pr_info("i3c /dev entries driver\n");

Please remove debugging information, kernel code should be quiet unless something goes wrong.

I will remove it.

Quoted 6 lines

drivers/i3c/i3cdev.c line 395

Quoted 3 lines
drivers/i3c/i3cdev.c new file +2 -0
+	/* Dynamically request unused major number */
+	res = alloc_chrdev_region(&i3cdev_number, 0, N_I3C_MINORS, "i3c");

Do you really need a whole major, or will a few minors work?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

thanks,

greg k-h

I'm reserving one per device. What do you suggest?

How many devices do you have in a system?

Quoted 7 lines

According to MIPI I3C spec, the maximum number of devices on a bus will depend on trace length, bus load, and clock requirements.

Frankly, I don't know what is the best compromise because it depends from system to system and the end-use of it. In my case, I started developing this to help me during the HC controller driver development. Even If I choose a fixed major, I wouldn't know in which one i3c fits.

Ok, a full major will be fine, I was worried you only wanted 1 or 2 minor numbers, which would mean you could have used a misc device instead.

This is fine.

thanks,

greg k-h

#13 lore raw

RE: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev

In reply to Arnd Bergmann

Hi Arnd,

From: Arnd Bergmann <[email protected]>
Date: Tue, Dec 10, 2019 at 17:51:14

Quoted 18 lines · Vitor Soares

include/uapi/linux/i3c/i3cdev.h line 25

Quoted 13 lines
include/uapi/linux/i3c/i3cdev.h new file +12 -0
+/* IOCTL commands */
+#define I3C_DEV_IOC_MAGIC      0x07
+
+struct i3c_ioc_priv_xfer {
+       struct i3c_priv_xfer __user *xfers;     /* pointers to i3c_priv_xfer */
+       __u32 nxfers;                           /* number of i3c_priv_xfer */
+};
+
+#define I3C_IOC_PRIV_XFER      \
+       _IOW(I3C_DEV_IOC_MAGIC, 30, struct i3c_ioc_priv_xfer)
+
+#define  I3C_IOC_PRIV_XFER_MAX_MSGS    42

This is not a great data structure for UAPI, please see
https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_arnd_playground.git_tree_Documentation_core-2Dapi_ioctl.rst-3Fh-3Dcompat-2Dioctl-2Dendgame-26id-3D927324b7900ee9b877691a8b237e272fabb21bf5&d=DwIBaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=qVuU64u9x77Y0Kd0PhDK_lpxFgg6PK9PateHwjb_DY0&m=5Q9WjK0o93NR7DQ9NM6So6mfdgpNnZnSaP8qMpgaC7E&s=LzzjrUQAG8fx5jkVyK73dBDrahNAvk09Cxxlx3KOiXI&e=

Quoted 4 lines

for some background. I'm planning to submit that documentation for mainline integration soon.

Arnd

I was checking other code examples for this and found that some authors add extra reserved fields for future use. Should I do the same?

I have some doubt too if it is ok to use the same ioctl command approach as in spidev:

#define SPI_MSGSIZE(N) \

  	((((N)*(sizeof (struct spi_ioc_transfer))) < (1 << _IOC_SIZEBITS)) \
		? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)

#define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)])

Or the best is to use another structure to embedded N transfers like in this patch.

Thanks in advance for your help.
Best regards,
Vitor Soares