Skip to contentSkip to conversation

i3c: master: some fix and improvemnt for hotjoin

PATCH Superseded Frank Li 3 participants 39 messages Aug 19, 2024 – Sep 16, 2024

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Frank Li

author maintainer
#0 lore raw

v3 cover i3c: master: some fix and improvemnt for hotjoin

---
Changes in v3:
- Fix build warning
kernel test robot noticed the following build warnings:

url:    https://github.com/intel-lab-lkp/linux/commits/Frank-Li/i3c-master-Remove-i3c_dev_disable_ibi_locked-olddev-on-device-hotjoin/20240814-234209
base:   41c196e567fb1ea97f68a2ffb7faab451cd90854
patch link:    https://lore.kernel.org/r/20240813-i3c_fix-v2-10-68fe4a050188%40nxp.com
patch subject: [PATCH v2 10/11] i3c: master: svc: wait for Manual ACK/NACK Done before next step
config: x86_64-randconfig-161-20240817 (https://download.01.org/0day-ci/archive/20240818/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- add help function at i3c: master: svc: manually emit NACK/ACK for hotjoin F Add below new fix patch
i3c: master: svc: fix possible assignment of the same address to two devices
i3c: master: svc: wait for Manual ACK/NACK Done before next step
i3c: master: svc: use spinlock_saveirq at svc_i3c_master_ibi_work()
i3c: master: svc: need check IBIWON for dynamtica address assign

- Link to v1: https://lore.kernel.org/r/[email protected]

---
Frank Li (11):
i3c: master: Remove i3c_dev_disable_ibi_locked(olddev) on device hotjoin
i3c: master: Replace hard code 2 with macro I3C_ADDR_SLOT_BITS
i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT
i3c: master: Fix dynamic address leak when 'assigned-address' is present
i3c: master: Fix miss free init_dyn_addr at i3c_master_put_i3c_addrs()
i3c: master: svc: use repeat start when IBI WIN happens
i3c: master: svc: manually emit NACK/ACK for hotjoin
i3c: master: svc: need check IBIWON for dynamtica address assign
i3c: master: svc: use spinlock_saveirq at svc_i3c_master_ibi_work()
i3c: master: svc: wait for Manual ACK/NACK Done before next step
i3c: master: svc: fix possible assignment of the same address to two devices

 drivers/i3c/master.c                |  66 ++++++++++++++---------
 drivers/i3c/master/svc-i3c-master.c | 104 ++++++++++++++++++++++++++----------
 include/linux/i3c/master.h          |   8 ++-
 3 files changed, 125 insertions(+), 53 deletions(-)

---
base-commit: 41c196e567fb1ea97f68a2ffb7faab451cd90854
change-id: 20240724-i3c_fix-371bf8fa9e00

Best regards,
---
Frank Li <[email protected]>

author maintainer
#1 lore raw

PATCH v3 1/11 i3c: master: Remove i3c_dev_disable_ibi_locked(olddev) on device hotjoin

When a new device hotjoins, a new dynamic address is assigned. i3c_master_add_i3c_dev_locked() identifies that the device was previously attached to the bus and locates the olddev.

i3c_master_add_i3c_dev_locked()

{
    ...
    olddev = i3c_master_search_i3c_dev_duplicate(newdev);
    ...
    if (olddev) {
        ...
        i3c_dev_disable_ibi_locked(olddev);
        ^^^^^^
        The olddev should not receive any commands on the i3c bus as it
        does not exist and has been assigned a new address. This will
        result in NACK or timeout. So remove it.
    }
}
Fixes 317bacf960a4 ("i3c: master: add enable(disable) hot join in sys entry")
---
 drivers/i3c/master.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i3c/master.c +1 -3
index 7028f03c2c42e..852b32178b722 100644
@@ -2039,10 +2039,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
 			ibireq.max_payload_len = olddev->ibi->max_payload_len;
 			ibireq.num_slots = olddev->ibi->num_slots;
 
-			if (olddev->ibi->enabled) {
+			if (olddev->ibi->enabled)
 				enable_ibi = true;
-				i3c_dev_disable_ibi_locked(olddev);
-			}
 
 			i3c_dev_free_ibi_locked(olddev);
 		}
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 01/11] i3c: master: Remove i3c_dev_disable_ibi_locked(olddev) on device hotjoin

Quoted 31 lines · Frank Li

When a new device hotjoins, a new dynamic address is assigned. i3c_master_add_i3c_dev_locked() identifies that the device was previously attached to the bus and locates the olddev.

i3c_master_add_i3c_dev_locked()

{
    ...
    olddev = i3c_master_search_i3c_dev_duplicate(newdev);
    ...
    if (olddev) {
        ...
        i3c_dev_disable_ibi_locked(olddev);
        ^^^^^^
        The olddev should not receive any commands on the i3c bus as it
        does not exist and has been assigned a new address. This will
        result in NACK or timeout. So remove it.
    }
}
Fixes 317bacf960a4 ("i3c: master: add enable(disable) hot join in sys entry")
---
 drivers/i3c/master.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i3c/master.c +0 -0
index 7028f03c2c42e..852b32178b722 100644

drivers/i3c/master.c int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, · line 2045

Quoted 10 lines
drivers/i3c/master.c +1 -3
@@ -2039,10 +2039,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
                        ibireq.max_payload_len = olddev->ibi->max_payload_len;
                        ibireq.num_slots = olddev->ibi->num_slots;
 
-                       if (olddev->ibi->enabled) {
+                       if (olddev->ibi->enabled)
                                enable_ibi = true;
-                               i3c_dev_disable_ibi_locked(olddev);
-                       }
 
                        i3c_dev_free_ibi_locked(olddev);

i3c_dev_free_ibi_locked will still encounter WARN_ON(dev->ibi->enabled).

Thanks,
Stanley

Quoted 10 lines
drivers/i3c/master.c +0 -1
                }
 
--

2.34.1

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

author maintainer
#3 lore raw

Re: [PATCH v3 01/11] i3c: master: Remove i3c_dev_disable_ibi_locked(olddev) on device hotjoin

Quoted 41 lines · Stanley Chu
Quoted 40 lines · Frank Li

When a new device hotjoins, a new dynamic address is assigned. i3c_master_add_i3c_dev_locked() identifies that the device was previously attached to the bus and locates the olddev.

i3c_master_add_i3c_dev_locked()

{
    ...
    olddev = i3c_master_search_i3c_dev_duplicate(newdev);
    ...
    if (olddev) {
        ...
        i3c_dev_disable_ibi_locked(olddev);
        ^^^^^^
        The olddev should not receive any commands on the i3c bus as it
        does not exist and has been assigned a new address. This will
        result in NACK or timeout. So remove it.
    }
}
Fixes 317bacf960a4 ("i3c: master: add enable(disable) hot join in sys entry")
---
 drivers/i3c/master.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i3c/master.c +1 -3
index 7028f03c2c42e..852b32178b722 100644
@@ -2039,10 +2039,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
                        ibireq.max_payload_len = olddev->ibi->max_payload_len;
                        ibireq.num_slots = olddev->ibi->num_slots;
 
-                       if (olddev->ibi->enabled) {
+                       if (olddev->ibi->enabled)
                                enable_ibi = true;
-                               i3c_dev_disable_ibi_locked(olddev);
-                       }
 
Quoted 3 lines

drivers/i3c/master.c int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, · line 2045

Quoted 1 line
drivers/i3c/master.c +0 -0
                        i3c_dev_free_ibi_locked(olddev);

i3c_dev_free_ibi_locked will still encounter WARN_ON(dev->ibi->enabled).

Thank you test it. The below patch should fix this problem.

https://lore.kernel.org/imx/[email protected]/T/#u

Quoted 14 lines

Thanks,
Stanley

Quoted 10 lines
drivers/i3c/master.c +0 -1
                }
 
--

2.34.1

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

maintainer Reviewed-by
#4 lore raw

Re: [PATCH v3 01/11] i3c: master: Remove i3c_dev_disable_ibi_locked(olddev) on device hotjoin

Hi Frank,

[email protected] wrote on Tue, 20 Aug 2024 10:45:14 -0400:

Quoted 42 lines · Stanley Chu
Quoted 41 lines · Frank Li
Quoted 40 lines

When a new device hotjoins, a new dynamic address is assigned. i3c_master_add_i3c_dev_locked() identifies that the device was previously attached to the bus and locates the olddev.

i3c_master_add_i3c_dev_locked()

{
    ...
    olddev = i3c_master_search_i3c_dev_duplicate(newdev);
    ...
    if (olddev) {
        ...
        i3c_dev_disable_ibi_locked(olddev);
        ^^^^^^
        The olddev should not receive any commands on the i3c bus as it
        does not exist and has been assigned a new address. This will
        result in NACK or timeout. So remove it.
    }
}
Fixes 317bacf960a4 ("i3c: master: add enable(disable) hot join in sys entry")
---
 drivers/i3c/master.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i3c/master.c +1 -3
index 7028f03c2c42e..852b32178b722 100644
@@ -2039,10 +2039,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
                        ibireq.max_payload_len = olddev->ibi->max_payload_len;
                        ibireq.num_slots = olddev->ibi->num_slots;
 
-                       if (olddev->ibi->enabled) {
+                       if (olddev->ibi->enabled)
                                enable_ibi = true;
-                               i3c_dev_disable_ibi_locked(olddev);
-                       }
 
Quoted 7 lines
Quoted 3 lines

drivers/i3c/master.c int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, · line 2045

Quoted 1 line
drivers/i3c/master.c +0 -0
                        i3c_dev_free_ibi_locked(olddev);  

i3c_dev_free_ibi_locked will still encounter WARN_ON(dev->ibi->enabled).

Thank you test it. The below patch should fix this problem.

https://lore.kernel.org/imx/[email protected]/T/#u

It should indeed. With this change added:

Thanks,
Miquèl

author maintainer
#5 lore raw

PATCH v3 2/11 i3c: master: Replace hard code 2 with macro I3C_ADDR_SLOT_BITS

In reply to Frank Li

Replace the hardcoded value 2, which indicates 2 bits for I3C address status, with the predefined macro I3C_ADDR_SLOT_BITS.

Improve maintainability and extensibility of the code.

---
 drivers/i3c/master.c       | 4 ++--
 include/linux/i3c/master.h | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/i3c/master.c +2 -2
index 852b32178b722..85c737554c940 100644
@@ -348,7 +348,7 @@ static enum i3c_addr_slot_status
 i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr)
 {
 	unsigned long status;
-	int bitpos = addr * 2;
+	int bitpos = addr * I3C_ADDR_SLOT_BITS;
 
 	if (addr > I2C_MAX_ADDR)
 		return I3C_ADDR_SLOT_RSVD;
@@ -362,7 +362,7 @@ i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr)
 static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr,
 					 enum i3c_addr_slot_status status)
 {
-	int bitpos = addr * 2;
+	int bitpos = addr * I3C_ADDR_SLOT_BITS;
 	unsigned long *ptr;
 
 	if (addr > I2C_MAX_ADDR)
include/linux/i3c/master.h +3 -1
index 074f632868d98..4601b6957f799 100644
@@ -299,6 +299,8 @@ enum i3c_addr_slot_status {
 	I3C_ADDR_SLOT_STATUS_MASK = 3,
 };
 
+#define I3C_ADDR_SLOT_BITS 2
+
 /**
  * struct i3c_bus - I3C bus object
  * @cur_master: I3C master currently driving the bus. Since I3C is multi-master
@@ -340,7 +342,7 @@ enum i3c_addr_slot_status {
 struct i3c_bus {
 	struct i3c_dev_desc *cur_master;
 	int id;
-	unsigned long addrslots[((I2C_MAX_ADDR + 1) * 2) / BITS_PER_LONG];
+	unsigned long addrslots[((I2C_MAX_ADDR + 1) * I3C_ADDR_SLOT_BITS) / BITS_PER_LONG];
 	enum i3c_bus_mode mode;
 	struct {
 		unsigned long i3c;
Signature · 1 line
2.34.1
maintainer
#6 lore raw

Re: [PATCH v3 02/11] i3c: master: Replace hard code 2 with macro I3C_ADDR_SLOT_BITS

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:01:56 -0400:

Quoted 2 lines

Replace the hardcoded value 2, which indicates 2 bits for I3C address status, with the predefined macro I3C_ADDR_SLOT_BITS.

I'm fine with the idea but I don't understand the macro name. You're talking about status bits and yet the macro is named addr_slot?

Quoted 1 line

Improve maintainability and extensibility of the code.

Thanks,
Miquèl

author maintainer
#7 lore raw

Re: [PATCH v3 02/11] i3c: master: Replace hard code 2 with macro I3C_ADDR_SLOT_BITS

Quoted 10 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:01:56 -0400:

Quoted 2 lines

Replace the hardcoded value 2, which indicates 2 bits for I3C address status, with the predefined macro I3C_ADDR_SLOT_BITS.

I'm fine with the idea but I don't understand the macro name. You're talking about status bits and yet the macro is named addr_slot?

How about I3C_ADDR_SLOT_STATUS_BITS ?

Quoted 4 lines
Quoted 1 line

Improve maintainability and extensibility of the code.

Thanks,
Miquèl

maintainer
#8 lore raw

Re: [PATCH v3 02/11] i3c: master: Replace hard code 2 with macro I3C_ADDR_SLOT_BITS

Hi Frank,

[email protected] wrote on Fri, 23 Aug 2024 13:57:31 -0400:

Quoted 5 lines · Miquel Raynal
Quoted 4 lines

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:01:56 -0400:

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

Replace the hardcoded value 2, which indicates 2 bits for I3C address status, with the predefined macro I3C_ADDR_SLOT_BITS.

I'm fine with the idea but I don't understand the macro name. You're talking about status bits and yet the macro is named addr_slot?

How about I3C_ADDR_SLOT_STATUS_BITS ?

Quoted 1 line
Quoted 1 line

Improve maintainability and extensibility of the code.

I'm a bit flaky on this concept, but let's try that. Perhaps with all the changes requested (esp. rephrasing) it might become clearer in next version.

Thanks,
Miquèl

author maintainer
#9 lore raw

PATCH v3 3/11 i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

In reply to Frank Li

Extend the address status bit to 4 and introduce the I3C_ADDR_SLOT_EXT_INIT macro to indicate that a device prefers a specific address. This is generally set by the 'assigned-address' in the device tree source (dts) file.

When an i3c device is removed from the bus, the old address status is set to FREE, allowing other devices to use the address during hotjoin. The I3C_ADDR_SLOT_EXT_INIT status indicates that an address is preferred by some devices. The function i3c_bus_get_free_addr() will first attempt to use unassigned addresses before searching for assigned addresses of devices that have been removed from the bus, trying to best match the 'assigned-address'.

---
 drivers/i3c/master.c       | 43 ++++++++++++++++++++++++++++++++++---------
 include/linux/i3c/master.h |  6 +++++-
 2 files changed, 39 insertions(+), 10 deletions(-)
drivers/i3c/master.c +34 -9
index 85c737554c940..4281f673e08d8 100644
@@ -345,7 +345,7 @@ const struct bus_type i3c_bus_type = {
 EXPORT_SYMBOL_GPL(i3c_bus_type);
 
 static enum i3c_addr_slot_status
-i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr)
+i3c_bus_get_addr_slot_status_ext(struct i3c_bus *bus, u16 addr)
 {
 	unsigned long status;
 	int bitpos = addr * I3C_ADDR_SLOT_BITS;
@@ -356,11 +356,17 @@ i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr)
 	status = bus->addrslots[bitpos / BITS_PER_LONG];
 	status >>= bitpos % BITS_PER_LONG;
 
-	return status & I3C_ADDR_SLOT_STATUS_MASK;
+	return status & I3C_ADDR_SLOT_EXT_STATUS_MASK;
 }
 
-static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr,
-					 enum i3c_addr_slot_status status)
+static enum i3c_addr_slot_status
+i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr)
+{
+	return i3c_bus_get_addr_slot_status_ext(bus, addr) & I3C_ADDR_SLOT_STATUS_MASK;
+}
+
+static void i3c_bus_set_addr_slot_status_mask(struct i3c_bus *bus, u16 addr,
+					      enum i3c_addr_slot_status status, int mask)
 {
 	int bitpos = addr * I3C_ADDR_SLOT_BITS;
 	unsigned long *ptr;
@@ -369,11 +375,22 @@ static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr,
 		return;
 
 	ptr = bus->addrslots + (bitpos / BITS_PER_LONG);
-	*ptr &= ~((unsigned long)I3C_ADDR_SLOT_STATUS_MASK <<
-						(bitpos % BITS_PER_LONG));
+	*ptr &= ~((unsigned long)mask << (bitpos % BITS_PER_LONG));
 	*ptr |= (unsigned long)status << (bitpos % BITS_PER_LONG);
 }
 
+static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr,
+					 enum i3c_addr_slot_status status)
+{
+	i3c_bus_set_addr_slot_status_mask(bus, addr, status, I3C_ADDR_SLOT_STATUS_MASK);
+}
+
+static void i3c_bus_set_addr_slot_status_ext(struct i3c_bus *bus, u16 addr,
+					     enum i3c_addr_slot_status status)
+{
+	i3c_bus_set_addr_slot_status_mask(bus, addr, status, I3C_ADDR_SLOT_EXT_STATUS_MASK);
+}
+
 static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr)
 {
 	enum i3c_addr_slot_status status;
@@ -388,6 +405,14 @@ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr)
 	enum i3c_addr_slot_status status;
 	u8 addr;
 
+	/* try find an address, which have not pre-allocated by assigned-address */
+	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
+		status = i3c_bus_get_addr_slot_status_ext(bus, addr);
+		if (status == I3C_ADDR_SLOT_FREE)
+			return addr;
+	}
+
+	/* use pre-allocoated by assigned-address because such device was removed at bus*/
 	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
 		status = i3c_bus_get_addr_slot_status(bus, addr);
 		if (status == I3C_ADDR_SLOT_FREE)
@@ -1906,9 +1931,9 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
 			goto err_rstdaa;
 		}
 
-		i3c_bus_set_addr_slot_status(&master->bus,
-					     i3cboardinfo->init_dyn_addr,
-					     I3C_ADDR_SLOT_I3C_DEV);
+		i3c_bus_set_addr_slot_status_ext(&master->bus,
+						 i3cboardinfo->init_dyn_addr,
+						 I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT);
 
 		/*
 		 * Only try to create/attach devices that have a static
include/linux/i3c/master.h +5 -1
index 4601b6957f799..c923b76bbc321 100644
@@ -284,6 +284,8 @@ enum i3c_bus_mode {
  * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device
  * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device
  * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask
+ * @I3C_ADDR_SLOT_EXT_INIT: the bit mask display of addresses is preferred by some devices,
+ *			    such as the "assigned-address" in device tree source (dts).
  *
  * On an I3C bus, addresses are assigned dynamically, and we need to know which
  * addresses are free to use and which ones are already assigned.
@@ -297,9 +299,11 @@ enum i3c_addr_slot_status {
 	I3C_ADDR_SLOT_I2C_DEV,
 	I3C_ADDR_SLOT_I3C_DEV,
 	I3C_ADDR_SLOT_STATUS_MASK = 3,
+	I3C_ADDR_SLOT_EXT_STATUS_MASK = 7,
+	I3C_ADDR_SLOT_EXT_INIT = BIT(2),
 };
 
-#define I3C_ADDR_SLOT_BITS 2
+#define I3C_ADDR_SLOT_BITS 4
 
 /**
  * struct i3c_bus - I3C bus object
Signature · 1 line
2.34.1
maintainer
#10 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Hi Frank,

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 408

Quoted 8 lines

static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) {

drivers/i3c/master.c +1 -0
 	enum i3c_addr_slot_status status;
@@ -388,6 +405,14 @@ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr)
 	enum i3c_addr_slot_status status;
 	u8 addr;
 
+	/* try find an address, which have not pre-allocated by assigned-address */

Try to find has been

pre-allocated?

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 415

Quoted 7 lines
drivers/i3c/master.c +7 -0
+	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
+		status = i3c_bus_get_addr_slot_status_ext(bus, addr);
+		if (status == I3C_ADDR_SLOT_FREE)
+			return addr;
+	}
+
+	/* use pre-allocoated by assigned-address because such device was removed at bus*/

Use allocated

pre-allocated or assigned?

I guess the logic should be:
- try the assigned-address
- look for a free slot
- look for an already in use slot that must concern a disconnected device

But the comments are not precise enough IMHO. Can you rephrase them?

Quoted 21 lines
drivers/i3c/master.c +3 -3
 	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
 		status = i3c_bus_get_addr_slot_status(bus, addr);
 		if (status == I3C_ADDR_SLOT_FREE)
@@ -1906,9 +1931,9 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
 			goto err_rstdaa;
 		}
 
-		i3c_bus_set_addr_slot_status(&master->bus,
-					     i3cboardinfo->init_dyn_addr,
-					     I3C_ADDR_SLOT_I3C_DEV);
+		i3c_bus_set_addr_slot_status_ext(&master->bus,
+						 i3cboardinfo->init_dyn_addr,
+						 I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT);
 
 		/*
 		 * Only try to create/attach devices that have a static
include/linux/i3c/master.h +0 -0
index 4601b6957f799..c923b76bbc321 100644

include/linux/i3c/master.h enum i3c_bus_mode { · line 287

Quoted 4 lines
include/linux/i3c/master.h +1 -0
@@ -284,6 +284,8 @@ enum i3c_bus_mode {
  * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device
  * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device
  * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask
+ * @I3C_ADDR_SLOT_EXT_INIT: the bit mask display of addresses is preferred by some devices,

I'm sorry, but I don't understand what "bit mask display of addresses" means.

Quoted 8 lines
include/linux/i3c/master.h +1 -0
+ *			    such as the "assigned-address" in device tree source (dts).
  *
  * On an I3C bus, addresses are assigned dynamically, and we need to know which
  * addresses are free to use and which ones are already assigned.
@@ -297,9 +299,11 @@ enum i3c_addr_slot_status {
 	I3C_ADDR_SLOT_I2C_DEV,
 	I3C_ADDR_SLOT_I3C_DEV,

include/linux/i3c/master.h enum i3c_addr_slot_status { · line 309

Quoted 10 lines
include/linux/i3c/master.h +3 -1
 	I3C_ADDR_SLOT_STATUS_MASK = 3,
+	I3C_ADDR_SLOT_EXT_STATUS_MASK = 7,
+	I3C_ADDR_SLOT_EXT_INIT = BIT(2),
 };
 
-#define I3C_ADDR_SLOT_BITS 2
+#define I3C_ADDR_SLOT_BITS 4
 
 /**
  * struct i3c_bus - I3C bus object

Thanks,
Miquèl

author maintainer
#11 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Quoted 28 lines · Miquel Raynal

Hi Frank,

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 408

Quoted 8 lines

static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) {

drivers/i3c/master.c +1 -0
 	enum i3c_addr_slot_status status;
@@ -388,6 +405,14 @@ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr)
 	enum i3c_addr_slot_status status;
 	u8 addr;
 
+	/* try find an address, which have not pre-allocated by assigned-address */

Try to find has been

pre-allocated?

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 415

Quoted 7 lines
drivers/i3c/master.c +7 -0
+	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
+		status = i3c_bus_get_addr_slot_status_ext(bus, addr);
+		if (status == I3C_ADDR_SLOT_FREE)
+			return addr;
+	}
+
+	/* use pre-allocoated by assigned-address because such device was removed at bus*/

Use allocated

pre-allocated or assigned?

Quoted 7 lines

I guess the logic should be:
- try the assigned-address
- look for a free slot
- look for an already in use slot that must concern a disconnected device

But the comments are not precise enough IMHO. Can you rephrase them?

How about:

Follow the steps below to obtain the I3C dynamic address:

1. Retrieve the assigned-address from the device tree (DT).
2. Look for an available slot address.
3. Look for an address that is pre-reserved by another device with assigned-address in DT, but where the device is currently offline.

Quoted 52 lines
Quoted 22 lines
drivers/i3c/master.c +3 -3
 	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
 		status = i3c_bus_get_addr_slot_status(bus, addr);
 		if (status == I3C_ADDR_SLOT_FREE)
@@ -1906,9 +1931,9 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
 			goto err_rstdaa;
 		}
 
-		i3c_bus_set_addr_slot_status(&master->bus,
-					     i3cboardinfo->init_dyn_addr,
-					     I3C_ADDR_SLOT_I3C_DEV);
+		i3c_bus_set_addr_slot_status_ext(&master->bus,
+						 i3cboardinfo->init_dyn_addr,
+						 I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT);
 
 		/*
 		 * Only try to create/attach devices that have a static
include/linux/i3c/master.h +0 -0
index 4601b6957f799..c923b76bbc321 100644

include/linux/i3c/master.h enum i3c_bus_mode { · line 287

Quoted 4 lines
include/linux/i3c/master.h +1 -0
@@ -284,6 +284,8 @@ enum i3c_bus_mode {
  * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device
  * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device
  * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask
+ * @I3C_ADDR_SLOT_EXT_INIT: the bit mask display of addresses is preferred by some devices,

I'm sorry, but I don't understand what "bit mask display of addresses" means.

Quoted 8 lines
include/linux/i3c/master.h +1 -0
+ *			    such as the "assigned-address" in device tree source (dts).
  *
  * On an I3C bus, addresses are assigned dynamically, and we need to know which
  * addresses are free to use and which ones are already assigned.
@@ -297,9 +299,11 @@ enum i3c_addr_slot_status {
 	I3C_ADDR_SLOT_I2C_DEV,
 	I3C_ADDR_SLOT_I3C_DEV,

include/linux/i3c/master.h enum i3c_addr_slot_status { · line 309

Quoted 10 lines
include/linux/i3c/master.h +3 -1
 	I3C_ADDR_SLOT_STATUS_MASK = 3,
+	I3C_ADDR_SLOT_EXT_STATUS_MASK = 7,
+	I3C_ADDR_SLOT_EXT_INIT = BIT(2),
 };
 
-#define I3C_ADDR_SLOT_BITS 2
+#define I3C_ADDR_SLOT_BITS 4
 
 /**
  * struct i3c_bus - I3C bus object

Thanks,
Miquèl

maintainer
#12 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Hi Frank,

[email protected] wrote on Fri, 23 Aug 2024 13:55:15 -0400:

Quoted 35 lines · Miquel Raynal
Quoted 34 lines

Hi Frank,

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 408

Quoted 8 lines

static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) {

drivers/i3c/master.c +1 -0
 	enum i3c_addr_slot_status status;
@@ -388,6 +405,14 @@ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr)
 	enum i3c_addr_slot_status status;
 	u8 addr;
 
+	/* try find an address, which have not pre-allocated by assigned-address */  

Try to find has been

pre-allocated?

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 415

Quoted 7 lines
drivers/i3c/master.c +7 -0
+	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
+		status = i3c_bus_get_addr_slot_status_ext(bus, addr);
+		if (status == I3C_ADDR_SLOT_FREE)
+			return addr;
+	}
+
+	/* use pre-allocoated by assigned-address because such device was removed at bus*/  

Use allocated

pre-allocated or assigned?

I guess the logic should be:
- try the assigned-address
- look for a free slot
- look for an already in use slot that must concern a disconnected device

Quoted 7 lines
Quoted 1 line

But the comments are not precise enough IMHO. Can you rephrase them?

How about:

Follow the steps below to obtain the I3C dynamic address:

1. Retrieve the assigned-address from the device tree (DT).

I guess here you mean that you try to pick that address, unless if already in use on the bus, right?

Quoted 1 line

2. Look for an available slot address.

"available address slot"?

Quoted 2 lines

3. Look for an address that is pre-reserved by another device with assigned-address in DT, but where the device is currently offline.

I don't think this part is precise enough. You don't look for addresses "pre-reserved" but rather more for busy address slots, which might no longer be in-use because the device is currently offline. The fact that the slot might have been pre-reserved in the DT is a detail that may, in some cases, not be true. And as far as I understand your changes, you're not checking the DT addresses but rather more the addresses that have been allocated live (which is anyway better, because i3c might very well be used on a !OF platform).

Once we settle on a description, maybe this can be part of the kdoc for the main function searching for the best dynamic address?

Thanks,
Miquèl

author maintainer
#13 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Quoted 41 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Fri, 23 Aug 2024 13:55:15 -0400:

Quoted 37 lines · Miquel Raynal
Quoted 35 lines

Hi Frank,

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 408

Quoted 8 lines

static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) {

drivers/i3c/master.c +1 -0
 	enum i3c_addr_slot_status status;
@@ -388,6 +405,14 @@ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr)
 	enum i3c_addr_slot_status status;
 	u8 addr;
 
+	/* try find an address, which have not pre-allocated by assigned-address */

Try to find has been

pre-allocated?

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 415

Quoted 7 lines
drivers/i3c/master.c +7 -0
+	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
+		status = i3c_bus_get_addr_slot_status_ext(bus, addr);
+		if (status == I3C_ADDR_SLOT_FREE)
+			return addr;
+	}
+
+	/* use pre-allocoated by assigned-address because such device was removed at bus*/

Use allocated

pre-allocated or assigned?

I guess the logic should be:
- try the assigned-address
- look for a free slot
- look for an already in use slot that must concern a disconnected device

But the comments are not precise enough IMHO. Can you rephrase them?

Quoted 9 lines
Quoted 5 lines

How about:

Follow the steps below to obtain the I3C dynamic address:

1. Retrieve the assigned-address from the device tree (DT).

I guess here you mean that you try to pick that address, unless if already in use on the bus, right?

Sorry, It should be typo. See below

Quoted 16 lines
Quoted 1 line

2. Look for an available slot address.

"available address slot"?

Quoted 2 lines

3. Look for an address that is pre-reserved by another device with assigned-address in DT, but where the device is currently offline.

I don't think this part is precise enough. You don't look for addresses "pre-reserved" but rather more for busy address slots, which might no longer be in-use because the device is currently offline. The fact that the slot might have been pre-reserved in the DT is a detail that may, in some cases, not be true. And as far as I understand your changes, you're not checking the DT addresses but rather more the addresses that have been allocated live (which is anyway better, because i3c might very well be used on a !OF platform).

Quoted 2 lines

Once we settle on a description, maybe this can be part of the kdoc for the main function searching for the best dynamic address?

I am not sure I understand what's your means here. The current framework is

1. Get a free address first, the get more infromation from devices, like BCR, DCR ...
2. Check if it is old device, or dt node have assigned-address property.
3. if it is old device, switch to use old address (if old address is free) according to i3c spec. If dt pre-reserved address is free, switch to use dt pre-reserved address.

To match 3's requirement as much as possible, when 1 return address, which should avoid return dt's assigned-address.

/*
* I3C Framework Address Assignment Flow:
* 1 Initial Address Assignment: Attempt to obtain a free address first,
then gather additional information such as PID, BCR, and DRCR
* 2 Address switch:
- 2a: Check if this target device is appeared before. Switch
to use prevous address of this device.
* - 2b: Check if this target device have assigned-address property in dt,
switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT). If no such address is available, it can return an address that was pre-reserved by a target device that is currently offline.

*/

Quoted 3 lines

Thanks,
Miquèl

maintainer
#14 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Hi Frank,

[email protected] wrote on Mon, 26 Aug 2024 11:56:57 -0400:

Quoted 84 lines · Miquel Raynal
Quoted 41 lines

Hi Frank,

[email protected] wrote on Fri, 23 Aug 2024 13:55:15 -0400:

Quoted 37 lines · Miquel Raynal
Quoted 35 lines

Hi Frank,

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 408

Quoted 8 lines

static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) {

drivers/i3c/master.c +1 -0
 	enum i3c_addr_slot_status status;
@@ -388,6 +405,14 @@ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr)
 	enum i3c_addr_slot_status status;
 	u8 addr;
 
+	/* try find an address, which have not pre-allocated by assigned-address */  

Try to find has been

pre-allocated?

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 415

Quoted 7 lines
drivers/i3c/master.c +7 -0
+	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
+		status = i3c_bus_get_addr_slot_status_ext(bus, addr);
+		if (status == I3C_ADDR_SLOT_FREE)
+			return addr;
+	}
+
+	/* use pre-allocoated by assigned-address because such device was removed at bus*/  

Use allocated

pre-allocated or assigned?

I guess the logic should be:
- try the assigned-address
- look for a free slot
- look for an already in use slot that must concern a disconnected device

But the comments are not precise enough IMHO. Can you rephrase them?

Quoted 9 lines
Quoted 5 lines

How about:

Follow the steps below to obtain the I3C dynamic address:

1. Retrieve the assigned-address from the device tree (DT).

I guess here you mean that you try to pick that address, unless if already in use on the bus, right?

Sorry, It should be typo. See below

Quoted 16 lines
Quoted 1 line

2. Look for an available slot address.

"available address slot"?

Quoted 2 lines

3. Look for an address that is pre-reserved by another device with assigned-address in DT, but where the device is currently offline.

I don't think this part is precise enough. You don't look for addresses "pre-reserved" but rather more for busy address slots, which might no longer be in-use because the device is currently offline. The fact that the slot might have been pre-reserved in the DT is a detail that may, in some cases, not be true. And as far as I understand your changes, you're not checking the DT addresses but rather more the addresses that have been allocated live (which is anyway better, because i3c might very well be used on a !OF platform).

Quoted 2 lines

Once we settle on a description, maybe this can be part of the kdoc for the main function searching for the best dynamic address?

I am not sure I understand what's your means here. The current framework is

1. Get a free address first, the get more infromation from devices, like BCR, DCR ...
2. Check if it is old device, or dt node have assigned-address property.
3. if it is old device, switch to use old address (if old address is free) according to i3c spec. If dt pre-reserved address is free, switch to use dt pre-reserved address.

Quoted 6 lines

To match 3's requirement as much as possible, when 1 return address, which should avoid return dt's assigned-address.

/*
* I3C Framework Address Assignment Flow:

f a a f

Quoted 1 line

* 1 Initial Address Assignment: Attempt to obtain a free address first,

1. a a

Quoted 2 lines

then gather additional information such as PID, BCR, and DRCR
* 2 Address switch:

     2.
Quoted 2 lines

- 2a: Check if this target device is appeared before. Switch
to use prevous address of this device.

the previous for

Quoted 1 line

* - 2b: Check if this target device have assigned-address property in dt,

has a preferred address based on firmware data (DT). Switch to it if it is the case and the address is free.

Today it's the DT, maybe not tomorrow. You take these values from the firmware on the board, that feels more generic than talking about a DT property name.

Quoted 5 lines

switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT).

This does not make sense, if you want to optimize for 2b, why not selecting the assigned-address property in the first place if it's available? Also, I don't understand why you would care to specifically *not* return an address that might be the default one for another device in the first place. Changing to a free slot (if possible) not reserved by another device might be done in 2b, which makes operation 1 much more simple, so you put all the complexity at the same time. Even if you are proceeding with two devices asking the DAA at the same time, the procedure should work in a way which does not impact the fact that the second device will get its desired address if the first can take another one.

Quoted 3 lines

If no such address
is available, it can return an address that was pre-reserved by a target device that is currently offline.

Thanks,
Miquèl

author maintainer
#15 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Quoted 128 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 26 Aug 2024 11:56:57 -0400:

Quoted 84 lines · Miquel Raynal
Quoted 41 lines

Hi Frank,

[email protected] wrote on Fri, 23 Aug 2024 13:55:15 -0400:

Quoted 37 lines · Miquel Raynal
Quoted 35 lines

Hi Frank,

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 408

Quoted 8 lines

static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) {

drivers/i3c/master.c +1 -0
 	enum i3c_addr_slot_status status;
@@ -388,6 +405,14 @@ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr)
 	enum i3c_addr_slot_status status;
 	u8 addr;
 
+	/* try find an address, which have not pre-allocated by assigned-address */

Try to find has been

pre-allocated?

drivers/i3c/master.c static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) · line 415

Quoted 7 lines
drivers/i3c/master.c +7 -0
+	for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) {
+		status = i3c_bus_get_addr_slot_status_ext(bus, addr);
+		if (status == I3C_ADDR_SLOT_FREE)
+			return addr;
+	}
+
+	/* use pre-allocoated by assigned-address because such device was removed at bus*/

Use allocated

pre-allocated or assigned?

I guess the logic should be:
- try the assigned-address
- look for a free slot
- look for an already in use slot that must concern a disconnected device

But the comments are not precise enough IMHO. Can you rephrase them?

Quoted 9 lines
Quoted 5 lines

How about:

Follow the steps below to obtain the I3C dynamic address:

1. Retrieve the assigned-address from the device tree (DT).

I guess here you mean that you try to pick that address, unless if already in use on the bus, right?

Sorry, It should be typo. See below

Quoted 16 lines
Quoted 1 line

2. Look for an available slot address.

"available address slot"?

Quoted 2 lines

3. Look for an address that is pre-reserved by another device with assigned-address in DT, but where the device is currently offline.

I don't think this part is precise enough. You don't look for addresses "pre-reserved" but rather more for busy address slots, which might no longer be in-use because the device is currently offline. The fact that the slot might have been pre-reserved in the DT is a detail that may, in some cases, not be true. And as far as I understand your changes, you're not checking the DT addresses but rather more the addresses that have been allocated live (which is anyway better, because i3c might very well be used on a !OF platform).

Quoted 2 lines

Once we settle on a description, maybe this can be part of the kdoc for the main function searching for the best dynamic address?

I am not sure I understand what's your means here. The current framework is

1. Get a free address first, the get more infromation from devices, like BCR, DCR ...
2. Check if it is old device, or dt node have assigned-address property.
3. if it is old device, switch to use old address (if old address is free) according to i3c spec. If dt pre-reserved address is free, switch to use dt pre-reserved address.

Quoted 6 lines

To match 3's requirement as much as possible, when 1 return address, which should avoid return dt's assigned-address.

/*
* I3C Framework Address Assignment Flow:

f a a f

Quoted 1 line

* 1 Initial Address Assignment: Attempt to obtain a free address first,

1. a a

Quoted 2 lines

then gather additional information such as PID, BCR, and DRCR
* 2 Address switch:

     2.
Quoted 2 lines

- 2a: Check if this target device is appeared before. Switch
to use prevous address of this device.

the previous for

Quoted 1 line

* - 2b: Check if this target device have assigned-address property in dt,

has a preferred address based on firmware data (DT). Switch to it if it is the case and the address is free.

Today it's the DT, maybe not tomorrow. You take these values from the firmware on the board, that feels more generic than talking about a DT property name.

Quoted 5 lines

switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT).

Quoted 3 lines

This does not make sense, if you want to optimize for 2b, why not selecting the assigned-address property in the first place if it's available?

This is my first idea. But I gived up this way.

Select an assigned-address here will involve a big change in i3c framework. There are no PID information in i3c_master_get_free_addr().

In DAA flow:
- SVC is get PID first, the get_free_addr(). This case, we can use PID to get dt assigned address.(if change/add API)
- But HCI, it is difference, hci_cmd_v2_daa(), get_free_addr() firstly then send out DAA command. So no PID information when call get_free_addr().

To cover both case, return a *real* free address here is simplest solution.

Quoted 3 lines

Also, I don't understand why you would care to specifically
*not* return an address that might be the default one for another device in the first place.

If devices A (want adddress 0xA), device B (want address 0xB), if both device send hot join at the same time. device B's PID less than device A,

Device B will be found firstly, call get_free_addr(), 0xA will be return if no this patch.

Device A, call try_get_freeaddr() to get 0xB.

So Devcie B will be assign to 0xA, and Device A will be assign to address 0xB.

After do_daa command, framework will add device B and device A into i3c bus.

When framework try to add device B to i3c bus, framework will try switch device B's address to 0xB from 0xA, but it will be fail because 0xB already assigned to device A.

Quoted 3 lines

Changing to a free slot (if possible) not
reserved by another device might be done in 2b, which makes operation 1 much more simple, so you put all the complexity at the same time.

I am sure if I understand your means here.

I put all address (not reserved by another device) to free slot.

reserved addr by another devices but offline, should be used only when not free slot avaible.

Quoted 5 lines

Even
if you are proceeding with two devices asking the DAA at the same time, the procedure should work in a way which does not impact the fact that the second device will get its desired address if the first can take another one.

I am sure if this is still validate if you understand HCI case.

Frank

Quoted 7 lines
Quoted 4 lines

If no such address
is available, it can return an address that was pre-reserved by a target device that is currently offline.

Thanks,
Miquèl

maintainer
#16 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Hi Frank,

Quoted 15 lines
Quoted 9 lines
Quoted 5 lines

switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT).

This does not make sense, if you want to optimize for 2b, why not selecting the assigned-address property in the first place if it's available?

This is my first idea. But I gived up this way.

Select an assigned-address here will involve a big change in i3c framework. There are no PID information in i3c_master_get_free_addr().

Quoted 7 lines

In DAA flow:
- SVC is get PID first, the get_free_addr(). This case, we can use PID to get dt assigned address.(if change/add API)
- But HCI, it is difference, hci_cmd_v2_daa(), get_free_addr() firstly then send out DAA command. So no PID information when call get_free_addr().

To cover both case, return a *real* free address here is simplest solution.

But this is a limitation of the HCI driver? So why not addressing this in the HCI driver instead? It would greatly simplify the core logic which becomes complex for wrong reasons.

Quoted 12 lines
Quoted 3 lines

Also, I don't understand why you would care to specifically
*not* return an address that might be the default one for another device in the first place.

If devices A (want adddress 0xA), device B (want address 0xB), if both device send hot join at the same time. device B's PID less than device A,

Device B will be found firstly, call get_free_addr(), 0xA will be return if no this patch.

Device A, call try_get_freeaddr() to get 0xB.

Quoted 7 lines

So Devcie B will be assign to 0xA, and Device A will be assign to address 0xB.

After do_daa command, framework will add device B and device A into i3c bus.

When framework try to add device B to i3c bus, framework will try switch device B's address to 0xB from 0xA, but it will be fail because 0xB already assigned to device A.

Well, okay, but that's exactly the situation that will happen if these devices are not described in your DT. I guess it's expected that a device not described in your DT can be connected, thanks to the hot-join feature. In this case you cannot know what is this device preferred address and you might end-up in the exact same situation.

May I question the need for preferred addresses at all? Is this even part of the spec? What is the use-case?

Thanks,
Miquèl

author maintainer
#17 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Quoted 23 lines · Miquel Raynal

Hi Frank,

Quoted 21 lines
Quoted 9 lines
Quoted 5 lines

switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT).

This does not make sense, if you want to optimize for 2b, why not selecting the assigned-address property in the first place if it's available?

This is my first idea. But I gived up this way.

Select an assigned-address here will involve a big change in i3c framework. There are no PID information in i3c_master_get_free_addr().

In DAA flow:
- SVC is get PID first, the get_free_addr(). This case, we can use PID to get dt assigned address.(if change/add API)
- But HCI, it is difference, hci_cmd_v2_daa(), get_free_addr() firstly then send out DAA command. So no PID information when call get_free_addr().

Quoted 5 lines
Quoted 1 line

To cover both case, return a *real* free address here is simplest solution.

But this is a limitation of the HCI driver? So why not addressing this in the HCI driver instead? It would greatly simplify the core logic which becomes complex for wrong reasons.

It is reasonable requirement to reduce stall SCL time. After get PID, SCL have to stall low to wait for software get dynamtic address, I3C spec allow relative long time for this, but still better if hardware can send out PID and dynamatic address together withoug stall SCL low. Pre-alloc adddress is good method if consider this.

Quoted 21 lines
Quoted 13 lines
Quoted 4 lines

Also, I don't understand why you would care to specifically
*not* return an address that might be the default one for another device in the first place.

If devices A (want adddress 0xA), device B (want address 0xB), if both device send hot join at the same time. device B's PID less than device A,

Device B will be found firstly, call get_free_addr(), 0xA will be return if no this patch.

Device A, call try_get_freeaddr() to get 0xB.

Quoted 7 lines

So Devcie B will be assign to 0xA, and Device A will be assign to address 0xB.

After do_daa command, framework will add device B and device A into i3c bus.

When framework try to add device B to i3c bus, framework will try switch device B's address to 0xB from 0xA, but it will be fail because 0xB already assigned to device A.

Quoted 5 lines

Well, okay, but that's exactly the situation that will happen if these devices are not described in your DT. I guess it's expected that a device not described in your DT can be connected, thanks to the hot-join feature. In this case you cannot know what is this device preferred address and you might end-up in the exact same situation.

If not descript in DT, it means that any dynmatic address can be assigned.

Quoted 3 lines

May I question the need for preferred addresses at all? Is this even part of the spec? What is the use-case?

It is implements detail. I3C spec said lower dynamtic address have high IBI priority. Spec just said assign lower dynamtic address if want to higher IBI prioerity. Using DT assign-address just is one implement method.

Quoted 3 lines

Thanks,
Miquèl

maintainer
#18 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Hi Frank,

[email protected] wrote on Mon, 2 Sep 2024 14:20:51 -0400:

Quoted 30 lines · Miquel Raynal
Quoted 23 lines

Hi Frank,

Quoted 21 lines
Quoted 9 lines
Quoted 5 lines

switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT).

This does not make sense, if you want to optimize for 2b, why not selecting the assigned-address property in the first place if it's available?

This is my first idea. But I gived up this way.

Select an assigned-address here will involve a big change in i3c framework. There are no PID information in i3c_master_get_free_addr().

In DAA flow:
- SVC is get PID first, the get_free_addr(). This case, we can use PID to get dt assigned address.(if change/add API)
- But HCI, it is difference, hci_cmd_v2_daa(), get_free_addr() firstly then send out DAA command. So no PID information when call get_free_addr().

Quoted 5 lines
Quoted 1 line

To cover both case, return a *real* free address here is simplest solution.

But this is a limitation of the HCI driver? So why not addressing this in the HCI driver instead? It would greatly simplify the core logic which becomes complex for wrong reasons.

Quoted 5 lines

It is reasonable requirement to reduce stall SCL time. After get PID, SCL have to stall low to wait for software get dynamtic address, I3C spec allow relative long time for this, but still better if hardware can send out PID and dynamatic address together withoug stall SCL low. Pre-alloc adddress is good method if consider this.

I don't think it is worth the trouble, given the complexity of all the changes. I prefer to simplify a bit the software and keep it readable than gaining few us with SCL low. In this case you also spend more time on the configuration I guess, so is it better than keeping SCL low (it will be low for some time anyway).

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 3 lines

Also, I don't understand why you would care to specifically
*not* return an address that might be the default one for another device in the first place.

If devices A (want adddress 0xA), device B (want address 0xB), if both device send hot join at the same time. device B's PID less than device A,

Device B will be found firstly, call get_free_addr(), 0xA will be return if no this patch.

Device A, call try_get_freeaddr() to get 0xB.

So Devcie B will be assign to 0xA, and Device A will be assign to address 0xB.

After do_daa command, framework will add device B and device A into i3c bus.

When framework try to add device B to i3c bus, framework will try switch device B's address to 0xB from 0xA, but it will be fail because 0xB already assigned to device A.

Quoted 7 lines
Quoted 5 lines

Well, okay, but that's exactly the situation that will happen if these devices are not described in your DT. I guess it's expected that a device not described in your DT can be connected, thanks to the hot-join feature. In this case you cannot know what is this device preferred address and you might end-up in the exact same situation.

If not descript in DT, it means that any dynmatic address can be assigned.

That's the point of view of the host. But a device might be "critical" and expect a low address, but the host not being aware. This is the same situation as your A and B conflict example.

Quoted 6 lines
Quoted 2 lines

May I question the need for preferred addresses at all? Is this even part of the spec? What is the use-case?

It is implements detail. I3C spec said lower dynamtic address have high IBI priority. Spec just said assign lower dynamtic address if want to higher IBI prioerity. Using DT assign-address just is one implement method.

Thanks for all the information, for me the HCI driver must be modified to retrieve the PID before assigning the dynamic address.

Thanks,
Miquèl

author maintainer
#19 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Quoted 40 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 2 Sep 2024 14:20:51 -0400:

Quoted 30 lines · Miquel Raynal
Quoted 23 lines

Hi Frank,

Quoted 21 lines
Quoted 9 lines
Quoted 5 lines

switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT).

This does not make sense, if you want to optimize for 2b, why not selecting the assigned-address property in the first place if it's available?

This is my first idea. But I gived up this way.

Select an assigned-address here will involve a big change in i3c framework. There are no PID information in i3c_master_get_free_addr().

In DAA flow:
- SVC is get PID first, the get_free_addr(). This case, we can use PID to get dt assigned address.(if change/add API)
- But HCI, it is difference, hci_cmd_v2_daa(), get_free_addr() firstly then send out DAA command. So no PID information when call get_free_addr().

Quoted 5 lines
Quoted 1 line

To cover both case, return a *real* free address here is simplest solution.

But this is a limitation of the HCI driver? So why not addressing this in the HCI driver instead? It would greatly simplify the core logic which becomes complex for wrong reasons.

Quoted 5 lines

It is reasonable requirement to reduce stall SCL time. After get PID, SCL have to stall low to wait for software get dynamtic address, I3C spec allow relative long time for this, but still better if hardware can send out PID and dynamatic address together withoug stall SCL low. Pre-alloc adddress is good method if consider this.

Quoted 5 lines

I don't think it is worth the trouble, given the complexity of all the changes. I prefer to simplify a bit the software and keep it readable than gaining few us with SCL low. In this case you also spend more time on the configuration I guess, so is it better than keeping SCL low (it will be low for some time anyway).

Yes, but see below about HCI. But two solutions will be worse.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 13 lines
Quoted 4 lines

Also, I don't understand why you would care to specifically
*not* return an address that might be the default one for another device in the first place.

If devices A (want adddress 0xA), device B (want address 0xB), if both device send hot join at the same time. device B's PID less than device A,

Device B will be found firstly, call get_free_addr(), 0xA will be return if no this patch.

Device A, call try_get_freeaddr() to get 0xB.

Quoted 7 lines

So Devcie B will be assign to 0xA, and Device A will be assign to address 0xB.

After do_daa command, framework will add device B and device A into i3c bus.

When framework try to add device B to i3c bus, framework will try switch device B's address to 0xB from 0xA, but it will be fail because 0xB already assigned to device A.

Well, okay, but that's exactly the situation that will happen if these devices are not described in your DT. I guess it's expected that a device not described in your DT can be connected, thanks to the hot-join feature. In this case you cannot know what is this device preferred address and you might end-up in the exact same situation.

Quoted 5 lines
Quoted 1 line

If not descript in DT, it means that any dynmatic address can be assigned.

That's the point of view of the host. But a device might be "critical" and expect a low address, but the host not being aware. This is the same situation as your A and B conflict example.

DT provided addtional information to let host aware it.

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines

May I question the need for preferred addresses at all? Is this even part of the spec? What is the use-case?

It is implements detail. I3C spec said lower dynamtic address have high IBI priority. Spec just said assign lower dynamtic address if want to higher IBI prioerity. Using DT assign-address just is one implement method.

Thanks for all the information, for me the HCI driver must be modified to retrieve the PID before assigning the dynamic address.

I am not famillar with HCI, but according to I3C HCI Spec 1.2, sec 6.4.1 Dynamic Address Assignment with ENTDAA:

I think it is impossible to do that. A dynatimic address must be provided before issue ENTDAA command. HCI is MIPI I3C standard defined Host interface. we have to consider this.

Frank

Quoted 3 lines

Thanks,
Miquèl

author maintainer
#20 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Quoted 95 lines · Frank Li
Quoted 40 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 2 Sep 2024 14:20:51 -0400:

Quoted 30 lines · Miquel Raynal
Quoted 23 lines

Hi Frank,

Quoted 21 lines
Quoted 9 lines
Quoted 5 lines

switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT).

This does not make sense, if you want to optimize for 2b, why not selecting the assigned-address property in the first place if it's available?

This is my first idea. But I gived up this way.

Select an assigned-address here will involve a big change in i3c framework. There are no PID information in i3c_master_get_free_addr().

In DAA flow:
- SVC is get PID first, the get_free_addr(). This case, we can use PID to get dt assigned address.(if change/add API)
- But HCI, it is difference, hci_cmd_v2_daa(), get_free_addr() firstly then send out DAA command. So no PID information when call get_free_addr().

Quoted 5 lines
Quoted 1 line

To cover both case, return a *real* free address here is simplest solution.

But this is a limitation of the HCI driver? So why not addressing this in the HCI driver instead? It would greatly simplify the core logic which becomes complex for wrong reasons.

Quoted 5 lines

It is reasonable requirement to reduce stall SCL time. After get PID, SCL have to stall low to wait for software get dynamtic address, I3C spec allow relative long time for this, but still better if hardware can send out PID and dynamatic address together withoug stall SCL low. Pre-alloc adddress is good method if consider this.

Quoted 5 lines

I don't think it is worth the trouble, given the complexity of all the changes. I prefer to simplify a bit the software and keep it readable than gaining few us with SCL low. In this case you also spend more time on the configuration I guess, so is it better than keeping SCL low (it will be low for some time anyway).

Yes, but see below about HCI. But two solutions will be worse.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 13 lines
Quoted 4 lines

Also, I don't understand why you would care to specifically
*not* return an address that might be the default one for another device in the first place.

If devices A (want adddress 0xA), device B (want address 0xB), if both device send hot join at the same time. device B's PID less than device A,

Device B will be found firstly, call get_free_addr(), 0xA will be return if no this patch.

Device A, call try_get_freeaddr() to get 0xB.

Quoted 7 lines

So Devcie B will be assign to 0xA, and Device A will be assign to address 0xB.

After do_daa command, framework will add device B and device A into i3c bus.

When framework try to add device B to i3c bus, framework will try switch device B's address to 0xB from 0xA, but it will be fail because 0xB already assigned to device A.

Well, okay, but that's exactly the situation that will happen if these devices are not described in your DT. I guess it's expected that a device not described in your DT can be connected, thanks to the hot-join feature. In this case you cannot know what is this device preferred address and you might end-up in the exact same situation.

Quoted 5 lines
Quoted 1 line

If not descript in DT, it means that any dynmatic address can be assigned.

That's the point of view of the host. But a device might be "critical" and expect a low address, but the host not being aware. This is the same situation as your A and B conflict example.

DT provided addtional information to let host aware it.

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines

May I question the need for preferred addresses at all? Is this even part of the spec? What is the use-case?

It is implements detail. I3C spec said lower dynamtic address have high IBI priority. Spec just said assign lower dynamtic address if want to higher IBI prioerity. Using DT assign-address just is one implement method.

Thanks for all the information, for me the HCI driver must be modified to retrieve the PID before assigning the dynamic address.

Quoted 6 lines

I am not famillar with HCI, but according to I3C HCI Spec 1.2, sec 6.4.1 Dynamic Address Assignment with ENTDAA:

I think it is impossible to do that. A dynatimic address must be provided before issue ENTDAA command. HCI is MIPI I3C standard defined Host interface. we have to consider this.

Miquèl:
Do you have any additional comments for this?

Frank

Quoted 5 lines

Frank

Quoted 3 lines

Thanks,
Miquèl

author maintainer
#21 lore raw

Re: [PATCH v3 03/11] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT

Quoted 99 lines · Frank Li
Quoted 98 lines · Frank Li
Quoted 40 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 2 Sep 2024 14:20:51 -0400:

Quoted 30 lines · Miquel Raynal
Quoted 23 lines

Hi Frank,

Quoted 21 lines
Quoted 9 lines
Quoted 5 lines

switch to this address if it is free.
*
In step 1, i3c_bus_get_free_addr() is called. To optimize for step 2b, this function should return an address that is not pre-reserved by any target device with an assigned address in the device tree (DT).

This does not make sense, if you want to optimize for 2b, why not selecting the assigned-address property in the first place if it's available?

This is my first idea. But I gived up this way.

Select an assigned-address here will involve a big change in i3c framework. There are no PID information in i3c_master_get_free_addr().

In DAA flow:
- SVC is get PID first, the get_free_addr(). This case, we can use PID to get dt assigned address.(if change/add API)
- But HCI, it is difference, hci_cmd_v2_daa(), get_free_addr() firstly then send out DAA command. So no PID information when call get_free_addr().

Quoted 5 lines
Quoted 1 line

To cover both case, return a *real* free address here is simplest solution.

But this is a limitation of the HCI driver? So why not addressing this in the HCI driver instead? It would greatly simplify the core logic which becomes complex for wrong reasons.

Quoted 5 lines

It is reasonable requirement to reduce stall SCL time. After get PID, SCL have to stall low to wait for software get dynamtic address, I3C spec allow relative long time for this, but still better if hardware can send out PID and dynamatic address together withoug stall SCL low. Pre-alloc adddress is good method if consider this.

Quoted 5 lines

I don't think it is worth the trouble, given the complexity of all the changes. I prefer to simplify a bit the software and keep it readable than gaining few us with SCL low. In this case you also spend more time on the configuration I guess, so is it better than keeping SCL low (it will be low for some time anyway).

Yes, but see below about HCI. But two solutions will be worse.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 13 lines
Quoted 4 lines

Also, I don't understand why you would care to specifically
*not* return an address that might be the default one for another device in the first place.

If devices A (want adddress 0xA), device B (want address 0xB), if both device send hot join at the same time. device B's PID less than device A,

Device B will be found firstly, call get_free_addr(), 0xA will be return if no this patch.

Device A, call try_get_freeaddr() to get 0xB.

Quoted 7 lines

So Devcie B will be assign to 0xA, and Device A will be assign to address 0xB.

After do_daa command, framework will add device B and device A into i3c bus.

When framework try to add device B to i3c bus, framework will try switch device B's address to 0xB from 0xA, but it will be fail because 0xB already assigned to device A.

Well, okay, but that's exactly the situation that will happen if these devices are not described in your DT. I guess it's expected that a device not described in your DT can be connected, thanks to the hot-join feature. In this case you cannot know what is this device preferred address and you might end-up in the exact same situation.

Quoted 5 lines
Quoted 1 line

If not descript in DT, it means that any dynmatic address can be assigned.

That's the point of view of the host. But a device might be "critical" and expect a low address, but the host not being aware. This is the same situation as your A and B conflict example.

DT provided addtional information to let host aware it.

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines

May I question the need for preferred addresses at all? Is this even part of the spec? What is the use-case?

It is implements detail. I3C spec said lower dynamtic address have high IBI priority. Spec just said assign lower dynamtic address if want to higher IBI prioerity. Using DT assign-address just is one implement method.

Thanks for all the information, for me the HCI driver must be modified to retrieve the PID before assigning the dynamic address.

I am not famillar with HCI, but according to I3C HCI Spec 1.2, sec 6.4.1 Dynamic Address Assignment with ENTDAA:

Quoted 8 lines
Quoted 3 lines

I think it is impossible to do that. A dynatimic address must be provided before issue ENTDAA command. HCI is MIPI I3C standard defined Host interface. we have to consider this.

Miquèl:
Do you have any additional comments for this?

Frank

Do you have any additional comments? HCI is MIPI I3C standard. we have to consider this.

Frank

Quoted 11 lines
Quoted 6 lines

Frank

Quoted 3 lines

Thanks,
Miquèl

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

author maintainer
#22 lore raw

PATCH v3 4/11 i3c: master: Fix dynamic address leak when 'assigned-address' is present

In reply to Frank Li

If the DTS contains 'assigned-address', a dynamic address leak occurs during hotjoin events.

Assume a device have assigned-address 0xb.
- Device issue Hotjoin
- Call i3c_master_do_daa()
- Call driver xxx_do_daa()
- Call i3c_master_get_free_addr() to get dynamic address 0x9
- i3c_master_add_i3c_dev_locked(0x9)
- expected_dyn_addr = newdev->boardinfo->init_dyn_addr (0xb);
- i3c_master_reattach_i3c_dev(newdev(0xb), old_dyn_addr(0x9));
- if (dev->info.dyn_addr != old_dyn_addr &&

                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0xb != 0x9 -> TRUE
                (!dev->boardinfo ||
                 ^^^^^^^^^^^^^^^ ->  FALSE
                 dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) {
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 0xb != 0xb      ->  FALSE
                 ...
                 i3c_bus_set_addr_slot_status(&master->bus, old_dyn_addr,
                                                     I3C_ADDR_SLOT_FREE);
		 ^^^
                 This will be skipped. So old_dyn_addr never free
            }

- i3c_master_get_free_addr() will return increased sequence number.

Remove dev->info.dyn_addr != dev->boardinfo->init_dyn_addr condition check. dev->info.dyn_addr should be checked before calling this function because i3c_master_setnewda_locked() has already been called and the target device has already accepted dyn_addr. It is too late to check if dyn_addr is free in i3c_master_reattach_i3c_dev().

Add check to ensure expected_dyn_addr is free before i3c_master_setnewda_locked().

Fixes cc3a392d69b6 ("i3c: master: fix for SETDASA and DAA process")
---
 drivers/i3c/master.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/i3c/master.c +5 -10
index 4281f673e08d8..c8eaeada54781 100644
@@ -1531,16 +1531,9 @@ static int i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev,
 				       u8 old_dyn_addr)
 {
 	struct i3c_master_controller *master = i3c_dev_get_master(dev);
-	enum i3c_addr_slot_status status;
 	int ret;
 
-	if (dev->info.dyn_addr != old_dyn_addr &&
-	    (!dev->boardinfo ||
-	     dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) {
-		status = i3c_bus_get_addr_slot_status(&master->bus,
-						      dev->info.dyn_addr);
-		if (status != I3C_ADDR_SLOT_FREE)
-			return -EBUSY;
+	if (dev->info.dyn_addr != old_dyn_addr) {
 		i3c_bus_set_addr_slot_status(&master->bus,
 					     dev->info.dyn_addr,
 					     I3C_ADDR_SLOT_I3C_DEV);
@@ -1931,9 +1924,10 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
 			goto err_rstdaa;
 		}
 
+		/* Not mark as occupied until real device exist in bus */
 		i3c_bus_set_addr_slot_status_ext(&master->bus,
 						 i3cboardinfo->init_dyn_addr,
-						 I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT);
+						 I3C_ADDR_SLOT_EXT_INIT);
 
 		/*
 		 * Only try to create/attach devices that have a static
@@ -2094,7 +2088,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,
 	else
 		expected_dyn_addr = newdev->info.dyn_addr;
 
-	if (newdev->info.dyn_addr != expected_dyn_addr) {
+	if (newdev->info.dyn_addr != expected_dyn_addr &&
+	    i3c_bus_get_addr_slot_status(&master->bus, expected_dyn_addr) == I3C_ADDR_SLOT_FREE) {
 		/*
 		 * Try to apply the expected dynamic address. If it fails, keep
 		 * the address assigned by the master.
Signature · 1 line
2.34.1
author maintainer
#23 lore raw

PATCH v3 5/11 i3c: master: Fix miss free init_dyn_addr at i3c_master_put_i3c_addrs()

In reply to Frank Li

if (dev->boardinfo && dev->boardinfo->init_dyn_addr)

                                      ^^^ here check "init_dyn_addr"
	i3c_bus_set_addr_slot_status(&master->bus, dev->info.dyn_addr, ...)
						             ^^^^
							free "dyn_addr"

Fix typo "dyn_addr" by replacing it with "init_dyn_addr".

Fixes 3a379bbcea0a ("i3c: Add core I3C infrastructure")
---
 drivers/i3c/master.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master.c +1 -1
index c8eaeada54781..65642e5afdcfb 100644
@@ -1442,7 +1442,7 @@ static void i3c_master_put_i3c_addrs(struct i3c_dev_desc *dev)
 					     I3C_ADDR_SLOT_FREE);
 
 	if (dev->boardinfo && dev->boardinfo->init_dyn_addr)
-		i3c_bus_set_addr_slot_status(&master->bus, dev->info.dyn_addr,
+		i3c_bus_set_addr_slot_status(&master->bus, dev->boardinfo->init_dyn_addr,
 					     I3C_ADDR_SLOT_FREE);
 }
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 5/11
#24 lore raw

Re: [PATCH v3 05/11] i3c: master: Fix miss free init_dyn_addr at i3c_master_put_i3c_addrs()

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:01:59 -0400:

Quoted 6 lines

if (dev->boardinfo && dev->boardinfo->init_dyn_addr)

                                      ^^^ here check "init_dyn_addr"
	i3c_bus_set_addr_slot_status(&master->bus, dev->info.dyn_addr, ...)
						             ^^^^
							free "dyn_addr"

Fix typo "dyn_addr" by replacing it with "init_dyn_addr".

Maybe you can mention it's a copy/paste error, which makes the diff -when looking at the previous lines- obvious.

Thanks,
Miquèl

author maintainer
#25 lore raw

PATCH v3 6/11 i3c: master: svc: use repeat start when IBI WIN happens

In reply to Frank Li

There is a possibility of an IBI WIN occurring when addressing issues, even when sending CCC commands. Most of the time, returning -EAGAIN is acceptable, but the case below becomes highly complex.

When a Hotjoin event occurs:
- i3c_master_do_daa()
- i3c_master_add_i3c_dev_locked()
- A dynamic address (e.g., 0x9) is already set during DAA.
- i3c_master_getpid_locked()
- Another device issues HJ or IBI here. Returning -EAGAIN causes failure in adding the new device. However, the dynamic address(0x9) has already been assigned to this device. If another device issues HJ, it will get this address 0x9 again, causing two devices on the bus to use the same dynamic address 0x9.
- Attempting to send RSTDAA when the first device fails at i3c_master_getpid_locked() could also fail when sending RSTDAA for the same reason.

According to the I3C spec, address arbitration only happens at START, never at REPEAT start. Using repeat start when an IBI WIN occurs simplifies this case, as i3c_master_getpid_locked() will not return an error when another device tries to send HJ or IBI.

---
 drivers/i3c/master/svc-i3c-master.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/i3c/master/svc-i3c-master.c +18 -18
index e80c002991f75..5d19251238ff8 100644
@@ -1099,6 +1099,24 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 		if (ret)
 			goto emit_stop;
 
+		/*
+		 * According to I3C spec ver 1.1.1, 5.1.2.2.3 Consequence of Controller Starting a
+		 * Frame with I3C Target Address.
+		 *
+		 * The I3C Controller normally should start a Frame, the Address may be arbitrated,
+		 * and so the Controller shall monitor to see whether an In-Band Interrupt request,
+		 * a Controller Role Request (i.e., Secondary Controller requests to become the
+		 * Active Controller), or a Hot-Join Request has been made.
+		 *
+		 * If missed IBIWON check, the wrong data will be return. When IBIWON happen, issue
+		 * repeat start. Address arbitrate only happen at START, never happen at REPEAT
+		 * start.
+		 */
+		if (SVC_I3C_MSTATUS_IBIWON(reg)) {
+			writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS);
+			continue;
+		}
+
 		if (readl(master->regs + SVC_I3C_MERRWARN) & SVC_I3C_MERRWARN_NACK) {
 			/*
 			 * According to I3C Spec 1.1.1, 11-Jun-2021, section: 5.1.2.2.3.
@@ -1132,24 +1150,6 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 		}
 	}
 
-	/*
-	 * According to I3C spec ver 1.1.1, 5.1.2.2.3 Consequence of Controller Starting a Frame
-	 * with I3C Target Address.
-	 *
-	 * The I3C Controller normally should start a Frame, the Address may be arbitrated, and so
-	 * the Controller shall monitor to see whether an In-Band Interrupt request, a Controller
-	 * Role Request (i.e., Secondary Controller requests to become the Active Controller), or
-	 * a Hot-Join Request has been made.
-	 *
-	 * If missed IBIWON check, the wrong data will be return. When IBIWON happen, return failure
-	 * and yield the above events handler.
-	 */
-	if (SVC_I3C_MSTATUS_IBIWON(reg)) {
-		ret = -EAGAIN;
-		*actual_len = 0;
-		goto emit_stop;
-	}
-
 	if (rnw)
 		ret = svc_i3c_master_read(master, in, xfer_len);
 	else
Signature · 1 line
2.34.1
maintainer Acked-by on v3 6/11
#26 lore raw

Re: [PATCH v3 06/11] i3c: master: svc: use repeat start when IBI WIN happens

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:02:00 -0400:

Quoted 18 lines

There is a possibility of an IBI WIN occurring when addressing issues, even when sending CCC commands. Most of the time, returning -EAGAIN is acceptable, but the case below becomes highly complex.

When a Hotjoin event occurs:
- i3c_master_do_daa()
- i3c_master_add_i3c_dev_locked()
- A dynamic address (e.g., 0x9) is already set during DAA.
- i3c_master_getpid_locked()
- Another device issues HJ or IBI here. Returning -EAGAIN causes failure in adding the new device. However, the dynamic address(0x9) has already been assigned to this device. If another device issues HJ, it will get this address 0x9 again, causing two devices on the bus to use the same dynamic address 0x9.
- Attempting to send RSTDAA when the first device fails at i3c_master_getpid_locked() could also fail when sending RSTDAA for the same reason.

Quoted 6 lines

According to the I3C spec, address arbitration only happens at START, never at REPEAT start. Using repeat start when an IBI WIN occurs simplifies this case, as i3c_master_getpid_locked() will not return an error when another device tries to send HJ or IBI.

Feels sensible.

Thanks,
Miquèl

author maintainer
#27 lore raw

PATCH v3 7/11 i3c: master: svc: manually emit NACK/ACK for hotjoin

In reply to Frank Li

When the address is arbitrated at send address, the hardware can auto-send NACK if it is an IBI. However, manual emission of NACK/ACK is needed for hot join or controller request events.

Add help function svc_i3c_master_handle_ibi_won() to check event type and send out NACK if the event is not an IBI.

---
 drivers/i3c/master/svc-i3c-master.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/i3c/master/svc-i3c-master.c +19 -1
index 5d19251238ff8..d665639523e3c 100644
@@ -405,6 +405,24 @@ static void svc_i3c_master_nack_ibi(struct svc_i3c_master *master)
 	       master->regs + SVC_I3C_MCTRL);
 }
 
+static int svc_i3c_master_handle_ibi_won(struct svc_i3c_master *master, u32 mstatus)
+{
+	u32 ibitype;
+
+	ibitype = SVC_I3C_MSTATUS_IBITYPE(mstatus);
+
+	writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS);
+
+	/* Hardware can't auto emit NACK for hot join and master request */
+	switch (ibitype) {
+	case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
+	case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
+		svc_i3c_master_nack_ibi(master);
+	}
+
+	return 0;
+}
+
 static void svc_i3c_master_ibi_work(struct work_struct *work)
 {
 	struct svc_i3c_master *master = container_of(work, struct svc_i3c_master, ibi_work);
@@ -1113,7 +1131,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 		 * start.
 		 */
 		if (SVC_I3C_MSTATUS_IBIWON(reg)) {
-			writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS);
+			svc_i3c_master_handle_ibi_won(master, reg);
 			continue;
 		}
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 7/11
#28 lore raw

Re: [PATCH v3 07/11] i3c: master: svc: manually emit NACK/ACK for hotjoin

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:02:01 -0400:

Quoted 8 lines

When the address is arbitrated at send address, the hardware can auto-send NACK if it is an IBI. However, manual emission of NACK/ACK is needed for hot join or controller request events.

Add help function svc_i3c_master_handle_ibi_won() to check event type and send out NACK if the event is not an IBI.

Thanks,
Miquèl

author maintainer
#29 lore raw

PATCH v3 8/11 i3c: master: svc: need check IBIWON for dynamtica address assign

In reply to Frank Li

When sending REQUEST_PROC_DAA, emit START and address 7E. Address arbitration may occur at this time if other devices trigger HJ, IBI, or CR events.

When IBIWON happen at REQUEST_PROC_DAA, nack IBI request then use repeat start to continue current dynamtica address assign.

---
 drivers/i3c/master/svc-i3c-master.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/i3c/master/svc-i3c-master.c +6 -0
index d665639523e3c..161ccd824443b 100644
@@ -808,6 +808,9 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
 	int ret, i;
 
 	while (true) {
+		/* clean SVC_I3C_MINT_IBIWON w1c bits */
+		writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS);
+
 		/* SVC_I3C_MCTRL_REQUEST_PROC_DAA have two mode, ENTER DAA or PROCESS DAA.
 		 *
 		 * ENTER DAA:
@@ -859,6 +862,9 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
 			ret = svc_i3c_master_readb(master, data, 2);
 			if (ret)
 				break;
+		} else if (SVC_I3C_MSTATUS_IBIWON(reg)) {
+			svc_i3c_master_handle_ibi_won(master, reg);
+			continue;
 		} else if (SVC_I3C_MSTATUS_MCTRLDONE(reg)) {
 			if (SVC_I3C_MSTATUS_STATE_IDLE(reg) &&
 			    SVC_I3C_MSTATUS_COMPLETE(reg)) {
Signature · 1 line
2.34.1
maintainer
#30 lore raw

Re: [PATCH v3 08/11] i3c: master: svc: need check IBIWON for dynamtica address assign

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:02:02 -0400:

Quoted 5 lines

When sending REQUEST_PROC_DAA, emit START and address 7E. Address arbitration may occur at this time if other devices trigger HJ, IBI, or CR events.

When IBIWON happen at REQUEST_PROC_DAA, nack IBI request then use repeat

during a NACK the send a

repeated start

Quoted 1 line

start to continue current dynamtica address assign.

                             ?
Quoted 2 lines

Thanks,
Miquèl

author maintainer
#31 lore raw

PATCH v3 9/11 i3c: master: svc: use spinlock_saveirq at svc_i3c_master_ibi_work()

In reply to Frank Li

According to I3C spec ver 1.1, 09-Jun-2021, section 5.1.2.5:

The I3C Controller shall hold SCL Low while the Bus is in I3C/I2C Transfer, ACK/NACK Phase. But maximum stall time is 100us. We have to disable irq and schedule during whole I3C transaction, otherwise, I3C bus timeout will happen if any irq or schedule happen during transaction.

Replace mutex with spinlock_saveirq() to make sure finish whole i3c transaction without stall SCL more than 100us.

---
 drivers/i3c/master/svc-i3c-master.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/i3c/master/svc-i3c-master.c +11 -3
index 161ccd824443b..fbb6cef405577 100644
@@ -432,7 +432,16 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 	u32 status, val;
 	int ret;
 
-	mutex_lock(&master->lock);
+	/*
+	 * According to I3C spec ver 1.1, 09-Jun-2021, section 5.1.2.5:
+	 *
+	 * The I3C Controller shall hold SCL Low while the Bus is in I3C/I2C Transfer, ACK/NACK
+	 * Phase. But maximum stall time is 100us. We have to disable irq and schedule during whole
+	 * I3C transaction, otherwise, I3C bus timeout will happen if any irq or schedule happen
+	 * between transaction..
+	 */
+	guard(spinlock_irqsave)(&master->xferqueue.lock);
+
 	/*
 	 * IBIWON may be set before SVC_I3C_MCTRL_REQUEST_AUTO_IBI, causing
 	 * readl_relaxed_poll_timeout() to return immediately. Consequently,
@@ -452,7 +461,7 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 	       master->regs + SVC_I3C_MCTRL);
 
 	/* Wait for IBIWON, should take approximately 100us */
-	ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val,
+	ret = readl_relaxed_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, val,
 					 SVC_I3C_MSTATUS_IBIWON(val), 0, 1000);
 	if (ret) {
 		dev_err(master->dev, "Timeout when polling for IBIWON\n");
@@ -525,7 +534,6 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 
 reenable_ibis:
 	svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART);
-	mutex_unlock(&master->lock);
 }
 
 static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)
Signature · 1 line
2.34.1
maintainer
#32 lore raw

Re: [PATCH v3 09/11] i3c: master: svc: use spinlock_saveirq at svc_i3c_master_ibi_work()

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:02:03 -0400:

Quoted 3 lines

According to I3C spec ver 1.1, 09-Jun-2021, section 5.1.2.5:

The I3C Controller shall hold SCL Low while the Bus is in I3C/I2C Transfer,

low transfer

Quoted 1 line

ACK/NACK Phase. But maximum stall time is 100us. We have to disable irq and

and/or (I'm not sure) the IRQs

Quoted 1 line

schedule during whole I3C transaction, otherwise, I3C bus timeout will

prevnet scheduling during the whole the may
timeout.

Quoted 3 lines

happen if any irq or schedule happen during transaction.

Replace mutex with spinlock_saveirq() to make sure finish whole i3c

wrong name to avoid stalling SCL...

Quoted 3 lines

transaction without stall SCL more than 100us.

Yes, 100us is low, and that's why I initially did my best to enforce auto ack/nack. We cannot make sure this limit will not be crossed, and when it's the case, we need to handle the consequences.

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ibi_work(struct work_struct *work) · line 435

Quoted 13 lines
---
 drivers/i3c/master/svc-i3c-master.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/i3c/master/svc-i3c-master.c +0 -1
index 161ccd824443b..fbb6cef405577 100644
@@ -432,7 +432,16 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 	u32 status, val;
 	int ret;
 
-	mutex_lock(&master->lock);

Don't you still need this lock for other concurrency reasons?

Quoted 14 lines
drivers/i3c/master/svc-i3c-master.c +10 -0
+	/*
+	 * According to I3C spec ver 1.1, 09-Jun-2021, section 5.1.2.5:
+	 *
+	 * The I3C Controller shall hold SCL Low while the Bus is in I3C/I2C Transfer, ACK/NACK
+	 * Phase. But maximum stall time is 100us. We have to disable irq and schedule during whole
+	 * I3C transaction, otherwise, I3C bus timeout will happen if any irq or schedule happen
+	 * between transaction..
+	 */
+	guard(spinlock_irqsave)(&master->xferqueue.lock);
+
 	/*
 	 * IBIWON may be set before SVC_I3C_MCTRL_REQUEST_AUTO_IBI, causing
 	 * readl_relaxed_poll_timeout() to return immediately. Consequently,

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ibi_work(struct work_struct *work) · line 465

Quoted 6 lines
drivers/i3c/master/svc-i3c-master.c +1 -1
@@ -452,7 +461,7 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 	       master->regs + SVC_I3C_MCTRL);
 
 	/* Wait for IBIWON, should take approximately 100us */
-	ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val,
+	ret = readl_relaxed_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, val,
 					 SVC_I3C_MSTATUS_IBIWON(val), 0, 1000);

This means you lock one CPU for 100us doing nothing every time you send a frame, that's not possible. Actually the delay was already very small (could have been set to ~10 maybe) but this is not possible.

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ibi_work(struct work_struct *work) · line 539

Quoted 11 lines
drivers/i3c/master/svc-i3c-master.c +0 -1
 	if (ret) {
 		dev_err(master->dev, "Timeout when polling for IBIWON\n");
@@ -525,7 +534,6 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 
 reenable_ibis:
 	svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART);
-	mutex_unlock(&master->lock);
 }
 
 static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)

Thanks,
Miquèl

author maintainer
#33 lore raw

Re: [PATCH v3 09/11] i3c: master: svc: use spinlock_saveirq at svc_i3c_master_ibi_work()

Quoted 25 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:02:03 -0400:

Quoted 3 lines

According to I3C spec ver 1.1, 09-Jun-2021, section 5.1.2.5:

The I3C Controller shall hold SCL Low while the Bus is in I3C/I2C Transfer,

low transfer

Quoted 1 line

ACK/NACK Phase. But maximum stall time is 100us. We have to disable irq and

and/or (I'm not sure) the IRQs

Quoted 1 line

schedule during whole I3C transaction, otherwise, I3C bus timeout will

prevnet scheduling during the whole the may
timeout.

Quoted 3 lines

happen if any irq or schedule happen during transaction.

Replace mutex with spinlock_saveirq() to make sure finish whole i3c

wrong name to avoid stalling SCL...

Quoted 7 lines
Quoted 3 lines

transaction without stall SCL more than 100us.

Yes, 100us is low, and that's why I initially did my best to enforce auto ack/nack. We cannot make sure this limit will not be crossed, and when it's the case, we need to handle the consequences.

Only IBI use auto ack/nack. hardware can't handle it for HJ and CR, which have to manually send out.

Quoted 33 lines
Quoted 10 lines
---
 drivers/i3c/master/svc-i3c-master.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/i3c/master/svc-i3c-master.c +0 -0
index 161ccd824443b..fbb6cef405577 100644

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ibi_work(struct work_struct *work) · line 435

Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c +0 -1
@@ -432,7 +432,16 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 	u32 status, val;
 	int ret;
 
-	mutex_lock(&master->lock);

Don't you still need this lock for other concurrency reasons?

Quoted 16 lines
drivers/i3c/master/svc-i3c-master.c +10 -0
+	/*
+	 * According to I3C spec ver 1.1, 09-Jun-2021, section 5.1.2.5:
+	 *
+	 * The I3C Controller shall hold SCL Low while the Bus is in I3C/I2C Transfer, ACK/NACK
+	 * Phase. But maximum stall time is 100us. We have to disable irq and schedule during whole
+	 * I3C transaction, otherwise, I3C bus timeout will happen if any irq or schedule happen
+	 * between transaction..
+	 */
+	guard(spinlock_irqsave)(&master->xferqueue.lock);
+
 	/*
 	 * IBIWON may be set before SVC_I3C_MCTRL_REQUEST_AUTO_IBI, causing
 	 * readl_relaxed_poll_timeout() to return immediately. Consequently,
@@ -452,7 +461,7 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 	       master->regs + SVC_I3C_MCTRL);
 
Quoted 8 lines

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ibi_work(struct work_struct *work) · line 465

Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c +1 -1
 	/* Wait for IBIWON, should take approximately 100us */
-	ret = readl_relaxed_poll_timeout(master->regs + SVC_I3C_MSTATUS, val,
+	ret = readl_relaxed_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, val,
 					 SVC_I3C_MSTATUS_IBIWON(val), 0, 1000);

This means you lock one CPU for 100us doing nothing every time you send a frame, that's not possible. Actually the delay was already very small (could have been set to ~10 maybe) but this is not possible.

It happen only at error case. Most time should wait for only 9th SCL. I think original comment is wrong.

Hardware set IBIWON at 8th SCL.

Frank

Quoted 16 lines

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ibi_work(struct work_struct *work) · line 539

Quoted 12 lines
drivers/i3c/master/svc-i3c-master.c +0 -1
 	if (ret) {
 		dev_err(master->dev, "Timeout when polling for IBIWON\n");
@@ -525,7 +534,6 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)
 
 reenable_ibis:
 	svc_i3c_master_enable_interrupts(master, SVC_I3C_MINT_SLVSTART);
-	mutex_unlock(&master->lock);
 }
 
 static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)

Thanks,
Miquèl

author maintainer
#34 lore raw

PATCH v3 10/11 i3c: master: svc: wait for Manual ACK/NACK Done before next step

In reply to Frank Li

Wait for the controller to complete emitting ACK/NACK, otherwise the next command may be omitted by the hardware.

Add command done check at svc_i3c_master_nack(ack)_ibi() and change return type to int to indicate wait done timeout.

---
 drivers/i3c/master/svc-i3c-master.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/i3c/master/svc-i3c-master.c +25 -6
index fbb6cef405577..2010495906eb3 100644
@@ -384,10 +384,12 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
 	return 0;
 }
 
-static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
+static int svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
 				   bool mandatory_byte)
 {
 	unsigned int ibi_ack_nack;
+	int ret;
+	u32 reg;
 
 	ibi_ack_nack = SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK;
 	if (mandatory_byte)
@@ -396,18 +398,31 @@ static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
 		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITHOUT_BYTE;
 
 	writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL);
+
+	ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, reg,
+					SVC_I3C_MSTATUS_MCTRLDONE(reg), 1, 1000);
+	return ret;
+
 }
 
-static void svc_i3c_master_nack_ibi(struct svc_i3c_master *master)
+static int svc_i3c_master_nack_ibi(struct svc_i3c_master *master)
 {
+	int ret;
+	u32 reg;
+
 	writel(SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK |
 	       SVC_I3C_MCTRL_IBIRESP_NACK,
 	       master->regs + SVC_I3C_MCTRL);
+
+	ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, reg,
+					SVC_I3C_MSTATUS_MCTRLDONE(reg), 1, 1000);
+	return ret;
 }
 
 static int svc_i3c_master_handle_ibi_won(struct svc_i3c_master *master, u32 mstatus)
 {
 	u32 ibitype;
+	int ret = 0;
 
 	ibitype = SVC_I3C_MSTATUS_IBITYPE(mstatus);
 
@@ -417,10 +432,10 @@ static int svc_i3c_master_handle_ibi_won(struct svc_i3c_master *master, u32 msta
 	switch (ibitype) {
 	case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
 	case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
-		svc_i3c_master_nack_ibi(master);
+		ret = svc_i3c_master_nack_ibi(master);
 	}
 
-	return 0;
+	return ret;
 }
 
 static void svc_i3c_master_ibi_work(struct work_struct *work)
@@ -871,7 +886,9 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
 			if (ret)
 				break;
 		} else if (SVC_I3C_MSTATUS_IBIWON(reg)) {
-			svc_i3c_master_handle_ibi_won(master, reg);
+			ret = svc_i3c_master_handle_ibi_won(master, reg);
+			if (ret)
+				break;
 			continue;
 		} else if (SVC_I3C_MSTATUS_MCTRLDONE(reg)) {
 			if (SVC_I3C_MSTATUS_STATE_IDLE(reg) &&
@@ -1145,7 +1162,9 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,
 		 * start.
 		 */
 		if (SVC_I3C_MSTATUS_IBIWON(reg)) {
-			svc_i3c_master_handle_ibi_won(master, reg);
+			ret = svc_i3c_master_handle_ibi_won(master, reg);
+			if (ret)
+				goto emit_stop;
 			continue;
 		}
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 10/11
#35 lore raw

Re: [PATCH v3 10/11] i3c: master: svc: wait for Manual ACK/NACK Done before next step

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:02:04 -0400:

Quoted 4 lines

Wait for the controller to complete emitting ACK/NACK, otherwise the next command may be omitted by the hardware.

Add command done check at svc_i3c_master_nack(ack)_ibi() and change return

a "command done" check in

the reutnr type

Quoted 1 line

type to int to indicate wait done timeout.

flag possible timeouts.

Quoted 25 lines
---
 drivers/i3c/master/svc-i3c-master.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/i3c/master/svc-i3c-master.c +3 -1
index fbb6cef405577..2010495906eb3 100644
@@ -384,10 +384,12 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
 	return 0;
 }
 
-static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
+static int svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
 				   bool mandatory_byte)
 {
 	unsigned int ibi_ack_nack;
+	int ret;
+	u32 reg;
 
 	ibi_ack_nack = SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK;
 	if (mandatory_byte)

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master, · line 403

Quoted 6 lines
drivers/i3c/master/svc-i3c-master.c +3 -0
@@ -396,18 +398,31 @@ static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
 		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITHOUT_BYTE;
 
 	writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL);
+
+	ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, reg,
+					SVC_I3C_MSTATUS_MCTRLDONE(reg), 1, 1000);

Still concerned about the _atomic.

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master, · line 404

Quoted 1 line
drivers/i3c/master/svc-i3c-master.c +1 -0
+	return ret;

return readl...

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master, · line 406

Quoted 2 lines
drivers/i3c/master/svc-i3c-master.c +1 -0
+
 }

Otherwise LGTM

Thanks,
Miquèl

author maintainer
#36 lore raw

Re: [PATCH v3 10/11] i3c: master: svc: wait for Manual ACK/NACK Done before next step

Quoted 44 lines · Miquel Raynal

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:02:04 -0400:

Quoted 4 lines

Wait for the controller to complete emitting ACK/NACK, otherwise the next command may be omitted by the hardware.

Add command done check at svc_i3c_master_nack(ack)_ibi() and change return

a "command done" check in

the reutnr type

Quoted 1 line

type to int to indicate wait done timeout.

flag possible timeouts.

Quoted 27 lines
---
 drivers/i3c/master/svc-i3c-master.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
drivers/i3c/master/svc-i3c-master.c +3 -1
index fbb6cef405577..2010495906eb3 100644
@@ -384,10 +384,12 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,
 	return 0;
 }
 
-static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
+static int svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
 				   bool mandatory_byte)
 {
 	unsigned int ibi_ack_nack;
+	int ret;
+	u32 reg;
 
 	ibi_ack_nack = SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK;
 	if (mandatory_byte)
@@ -396,18 +398,31 @@ static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master,
 		ibi_ack_nack |= SVC_I3C_MCTRL_IBIRESP_ACK_WITHOUT_BYTE;
 
Quoted 6 lines

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master, · line 403

Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c +3 -0
 	writel(ibi_ack_nack, master->regs + SVC_I3C_MCTRL);
+
+	ret = readl_poll_timeout_atomic(master->regs + SVC_I3C_MSTATUS, reg,
+					SVC_I3C_MSTATUS_MCTRLDONE(reg), 1, 1000);

Still concerned about the _atomic.

It may be call in atomic context. Because hardware design limition, i3c transact have been in irq disable context to avoid 100us timeout issue.

Frank

Quoted 14 lines

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master, · line 404

Quoted 2 lines
drivers/i3c/master/svc-i3c-master.c +1 -0
+	return ret;

return readl...

drivers/i3c/master/svc-i3c-master.c static void svc_i3c_master_ack_ibi(struct svc_i3c_master *master, · line 406

Quoted 2 lines
drivers/i3c/master/svc-i3c-master.c +1 -0
+
 }

Otherwise LGTM

Thanks,
Miquèl

author maintainer
#37 lore raw

PATCH v3 11/11 i3c: master: svc: fix possible assignment of the same address to two devices

In reply to Frank Li
svc_i3c_master_do_daa() {
    ...
    for (i = 0; i < dev_nb; i++) {
        ret = i3c_master_add_i3c_dev_locked(m, addrs[i]);
        if (ret)
            goto rpm_out;
    }
}

If two devices (A and B) are detected in DAA and address 0xa is assigned to device A and 0xb to device B, a failure in i3c_master_add_i3c_dev_locked() for device A (addr: 0xa) could prevent device B (addr: 0xb) from being registered on the bus. The I3C stack might still consider 0xb a free address. If a subsequent Hotjoin occurs, 0xb might be assigned to Device A, causing both devices A and B to use the same address 0xb, violating the I3C specification.

The return value for i3c_master_add_i3c_dev_locked() should not be checked because subsequent steps will scan the entire I3C bus, independent of whether i3c_master_add_i3c_dev_locked() returns success.

If device A registration fails, there is still a chance to register device B. i3c_master_add_i3c_dev_locked() can reset DAA if a failure occurs while retrieving device information.

Fixes 317bacf960a4 ("i3c: master: add enable(disable) hot join in sys entry")
---
 drivers/i3c/master/svc-i3c-master.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/i3c/master/svc-i3c-master.c +2 -5
index 2010495906eb3..003565fddc261 100644
@@ -1042,11 +1042,8 @@ static int svc_i3c_master_do_daa(struct i3c_master_controller *m)
 		goto rpm_out;
 
 	/* Register all devices who participated to the core */
-	for (i = 0; i < dev_nb; i++) {
-		ret = i3c_master_add_i3c_dev_locked(m, addrs[i]);
-		if (ret)
-			goto rpm_out;
-	}
+	for (i = 0; i < dev_nb; i++)
+		i3c_master_add_i3c_dev_locked(m, addrs[i]);
 
 	/* Configure IBI auto-rules */
 	ret = svc_i3c_update_ibirules(master);
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 11/11
#38 lore raw

Re: [PATCH v3 11/11] i3c: master: svc: fix possible assignment of the same address to two devices

Hi Frank,

[email protected] wrote on Mon, 19 Aug 2024 12:02:05 -0400:

Quoted 37 lines
svc_i3c_master_do_daa() {
    ...
    for (i = 0; i < dev_nb; i++) {
        ret = i3c_master_add_i3c_dev_locked(m, addrs[i]);
        if (ret)
            goto rpm_out;
    }
}

If two devices (A and B) are detected in DAA and address 0xa is assigned to device A and 0xb to device B, a failure in i3c_master_add_i3c_dev_locked() for device A (addr: 0xa) could prevent device B (addr: 0xb) from being registered on the bus. The I3C stack might still consider 0xb a free address. If a subsequent Hotjoin occurs, 0xb might be assigned to Device A, causing both devices A and B to use the same address 0xb, violating the I3C specification.

The return value for i3c_master_add_i3c_dev_locked() should not be checked because subsequent steps will scan the entire I3C bus, independent of whether i3c_master_add_i3c_dev_locked() returns success.

If device A registration fails, there is still a chance to register device B. i3c_master_add_i3c_dev_locked() can reset DAA if a failure occurs while retrieving device information.

Fixes 317bacf960a4 ("i3c: master: add enable(disable) hot join in sys entry")
---
 drivers/i3c/master/svc-i3c-master.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/i3c/master/svc-i3c-master.c +0 -0
index 2010495906eb3..003565fddc261 100644

drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_do_daa(struct i3c_master_controller *m) · line 1046

Quoted 10 lines
drivers/i3c/master/svc-i3c-master.c +2 -5
@@ -1042,11 +1042,8 @@ static int svc_i3c_master_do_daa(struct i3c_master_controller *m)
 		goto rpm_out;
 
 	/* Register all devices who participated to the core */
-	for (i = 0; i < dev_nb; i++) {
-		ret = i3c_master_add_i3c_dev_locked(m, addrs[i]);
-		if (ret)
-			goto rpm_out;
-	}
+	for (i = 0; i < dev_nb; i++)
+		i3c_master_add_i3c_dev_locked(m, addrs[i]);

Makes sense, but please explain why don't check the return value in a comment (your commit log is good).

drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_do_daa(struct i3c_master_controller *m)

Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c +0 -0
 	/* Configure IBI auto-rules */
 	ret = svc_i3c_update_ibirules(master);
 

With the comment added,

Thanks,
Miquèl