Skip to contentSkip to conversation

i3c: Address i3c_device_id related issues

PATCH In review Boris Brezillon 1 participant 6 messages Feb 22, 2020 – Feb 26, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover i3c: Address i3c_device_id related issues

Hello,

When the I3C subsystem was introduced part of the modalias generation logic was missing (modalias generation based on i3c_device_id tables). This patch series addresses that limitation and simplifies our match function along the way.

Regards,

Boris

Boris Brezillon (3):
i3c: Fix MODALIAS uevents
i3c: Generate aliases for i3c modules
i3c: Simplify i3c_device_match_id()

 drivers/i3c/device.c              | 50 ++++++++++++++-----------------
 drivers/i3c/master.c              |  2 +-
 scripts/mod/devicetable-offsets.c |  7 +++++
 scripts/mod/file2alias.c          | 19 ++++++++++++
 4 files changed, 49 insertions(+), 29 deletions(-)
Signature · 7 lines
2.24.1


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

PATCH 1/3 i3c: Fix MODALIAS uevents

file2alias uses %X formatters. Fix typos in the MODALIAS uevent to print the part and ext IDs in uppercase.

---
 drivers/i3c/master.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master.c +1 -1
index b56207bbed2b..b6db82862a63 100644
@@ -267,7 +267,7 @@ static int i3c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
 				      devinfo.dcr, manuf);
 
 	return add_uevent_var(env,
-			      "MODALIAS=i3c:dcr%02Xmanuf%04Xpart%04xext%04x",
+			      "MODALIAS=i3c:dcr%02Xmanuf%04Xpart%04Xext%04X",
 			      devinfo.dcr, manuf, part, ext);
 }
 
Signature · 1 line
2.24.1
#2 lore raw

PATCH 2/3 i3c: Generate aliases for i3c modules

In reply to Boris Brezillon

This part was missing, thus preventing user space from loading modules automatically when MODALIAS uevents are received.

---
 scripts/mod/devicetable-offsets.c |  7 +++++++
 scripts/mod/file2alias.c          | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+)
scripts/mod/devicetable-offsets.c +7 -0
index 054405b90ba4..d3c237b9b7c0 100644
@@ -145,6 +145,13 @@ int main(void)
 	DEVID(i2c_device_id);
 	DEVID_FIELD(i2c_device_id, name);
 
+	DEVID(i3c_device_id);
+	DEVID_FIELD(i3c_device_id, match_flags);
+	DEVID_FIELD(i3c_device_id, dcr);
+	DEVID_FIELD(i3c_device_id, manuf_id);
+	DEVID_FIELD(i3c_device_id, part_id);
+	DEVID_FIELD(i3c_device_id, extra_info);
+
 	DEVID(spi_device_id);
 	DEVID_FIELD(spi_device_id, name);
 
scripts/mod/file2alias.c +19 -0
index c91eba751804..1754de3f119f 100644
@@ -919,6 +919,24 @@ static int do_i2c_entry(const char *filename, void *symval,
 	return 1;
 }
 
+static int do_i3c_entry(const char *filename, void *symval,
+			char *alias)
+{
+	DEF_FIELD(symval, i3c_device_id, match_flags);
+	DEF_FIELD(symval, i3c_device_id, dcr);
+	DEF_FIELD(symval, i3c_device_id, manuf_id);
+	DEF_FIELD(symval, i3c_device_id, part_id);
+	DEF_FIELD(symval, i3c_device_id, extra_info);
+
+	strcpy(alias, "i3c:");
+	ADD(alias, "dcr", match_flags & I3C_MATCH_DCR, dcr);
+	ADD(alias, "manuf", match_flags & I3C_MATCH_MANUF, dcr);
+	ADD(alias, "part", match_flags & I3C_MATCH_PART, dcr);
+	ADD(alias, "ext", match_flags & I3C_MATCH_EXTRA_INFO, dcr);
+
+	return 1;
+}
+
 /* Looks like: spi:S */
 static int do_spi_entry(const char *filename, void *symval,
 			char *alias)
@@ -1386,6 +1404,7 @@ static const struct devtable devtable[] = {
 	{"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
 	{"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
 	{"i2c", SIZE_i2c_device_id, do_i2c_entry},
+	{"i3c", SIZE_i3c_device_id, do_i3c_entry},
 	{"spi", SIZE_spi_device_id, do_spi_entry},
 	{"dmi", SIZE_dmi_system_id, do_dmi_entry},
 	{"platform", SIZE_platform_device_id, do_platform_entry},
Signature · 1 line
2.24.1
#3 lore raw

Re: [PATCH 2/3] i3c: Generate aliases for i3c modules

scripts/mod/file2alias.c static int do_i2c_entry(const char *filename, void *symval, · line 933

Quoted 12 lines · On Sat, 22 Feb 2020 11:27:10 +0100 Boris Brezillon…
scripts/mod/file2alias.c +12 -0
+static int do_i3c_entry(const char *filename, void *symval,
+			char *alias)
+{
+	DEF_FIELD(symval, i3c_device_id, match_flags);
+	DEF_FIELD(symval, i3c_device_id, dcr);
+	DEF_FIELD(symval, i3c_device_id, manuf_id);
+	DEF_FIELD(symval, i3c_device_id, part_id);
+	DEF_FIELD(symval, i3c_device_id, extra_info);
+
+	strcpy(alias, "i3c:");
+	ADD(alias, "dcr", match_flags & I3C_MATCH_DCR, dcr);
+	ADD(alias, "manuf", match_flags & I3C_MATCH_MANUF, dcr);

^manuf_id

scripts/mod/file2alias.c static int do_i2c_entry(const char *filename, void *symval, · line 934

Quoted 1 line
scripts/mod/file2alias.c +1 -0
+	ADD(alias, "part", match_flags & I3C_MATCH_PART, dcr);

^part_id

scripts/mod/file2alias.c static int do_i2c_entry(const char *filename, void *symval, · line 935

Quoted 1 line
scripts/mod/file2alias.c +1 -0
+	ADD(alias, "ext", match_flags & I3C_MATCH_EXTRA_INFO, dcr);

^extra_info

#4 lore raw

PATCH 3/3 i3c: Simplify i3c_device_match_id()

In reply to Boris Brezillon

Simply match against ->match_flags instead of trying to be smart and fix drivers inconsistent ID tables.

---
 drivers/i3c/device.c | 50 +++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 28 deletions(-)
drivers/i3c/device.c +22 -28
index 9e2e1406f85e..bb8e60dff988 100644
@@ -213,40 +213,34 @@ i3c_device_match_id(struct i3c_device *i3cdev,
 {
 	struct i3c_device_info devinfo;
 	const struct i3c_device_id *id;
+	u16 manuf, part, ext_info;
+	bool rndpid;
 
 	i3c_device_get_info(i3cdev, &devinfo);
 
-	/*
-	 * The lower 32bits of the provisional ID is just filled with a random
-	 * value, try to match using DCR info.
-	 */
-	if (!I3C_PID_RND_LOWER_32BITS(devinfo.pid)) {
-		u16 manuf = I3C_PID_MANUF_ID(devinfo.pid);
-		u16 part = I3C_PID_PART_ID(devinfo.pid);
-		u16 ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
-
-		/* First try to match by manufacturer/part ID. */
-		for (id = id_table; id->match_flags != 0; id++) {
-			if ((id->match_flags & I3C_MATCH_MANUF_AND_PART) !=
-			    I3C_MATCH_MANUF_AND_PART)
-				continue;
-
-			if (manuf != id->manuf_id || part != id->part_id)
-				continue;
-
-			if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
-			    ext_info != id->extra_info)
-				continue;
-
-			return id;
-		}
-	}
+	manuf = I3C_PID_MANUF_ID(devinfo.pid);
+	part = I3C_PID_PART_ID(devinfo.pid);
+	ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
+	rndpid = I3C_PID_RND_LOWER_32BITS(devinfo.pid);
 
-	/* Fallback to DCR match. */
 	for (id = id_table; id->match_flags != 0; id++) {
 		if ((id->match_flags & I3C_MATCH_DCR) &&
-		    id->dcr == devinfo.dcr)
-			return id;
+		    id->dcr != devinfo.dcr)
+			continue;
+
+		if ((id->match_flags & I3C_MATCH_MANUF) &&
+		    id->manuf_id != manuf)
+			continue;
+
+		if ((id->match_flags & I3C_MATCH_PART) &&
+		    (rndpid || id->part_id != part))
+			continue;
+
+		if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
+		    (rndpid || id->extra_info != ext_info))
+			continue;
+
+		return id;
 	}
 
 	return NULL;
Signature · 7 lines
2.24.1


_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
#5 lore raw
In reply to Boris Brezillon
Quoted 7 lines · On Sat, 22 Feb 2020 11:27:08 +0100 Boris Brezillon…

Hello,

When the I3C subsystem was introduced part of the modalias generation logic was missing (modalias generation based on i3c_device_id tables). This patch series addresses that limitation and simplifies our match function along the way.

Quoted 6 lines

Regards,

Boris

Boris Brezillon (3):
i3c: Fix MODALIAS uevents

We also lack a modalias sysfs attribute.

Quoted 9 lines

i3c: Generate aliases for i3c modules
i3c: Simplify i3c_device_match_id()

 drivers/i3c/device.c              | 50 ++++++++++++++-----------------
 drivers/i3c/master.c              |  2 +-
 scripts/mod/devicetable-offsets.c |  7 +++++
 scripts/mod/file2alias.c          | 19 ++++++++++++
 4 files changed, 49 insertions(+), 29 deletions(-)