i3c: master: some fix and improvemnt for hotjoin
Subsystems (3)
Frank Li
maintainerv4 cover i3c: master: some fix and improvemnt for hotjoin
---
Changes in v4:
- See each patch
- Link to v3: https://lore.kernel.org/r/[email protected]
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_STATUS_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 spin_lock_irqsave 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 | 100 +++++++++++++++++++++-------- drivers/i3c/master/svc-i3c-master.c | 122 +++++++++++++++++++++++++++--------- include/linux/i3c/master.h | 9 ++- 3 files changed, 175 insertions(+), 56 deletions(-)
---
base-commit: f2b9f0aeff2b3bb0446c955f0d8fac7659644c75
change-id: 20240724-i3c_fix-371bf8fa9e00
Best regards,
---
Frank Li <[email protected]>
Frank Li
maintainerPATCH v4 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.
}
i3c_dev_free_ibi_locked(olddev);
^^^^^^^^
This function internally calls i3c_dev_disable_ibi_locked() function
causing to send DISEC command with old Address.
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, update the olddev->ibi->enabled
flag to false to avoid DISEC with OldAddr.
}Include part of Ravindra Yashvant Shinde's work:
https://lore.kernel.org/linux-i3c/[email protected]/T/#u
---
change from v3 to v4
- merge https://lore.kernel.org/linux-i3c/[email protected]/T/#u
- add Miquel Raynal review tag
- add Ravindra Yashvant Shinde 's signed-off
--- drivers/i3c/master.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/i3c/master.c +9 -4
@@ -2039,11 +2039,16 @@ 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); - } - +/* +* 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, update the olddev->ibi->enabled flag to false +* to avoid DISEC with OldAddr. +*/ + olddev->ibi->enabled = false;i3c_dev_free_ibi_locked (olddev); }mutex_unlock (&olddev->ibi_lock);
Signature · 1 line
2.34.1
Frank Li
maintainerPATCH v4 2/11 i3c: master: Replace hard code 2 with macro I3C_ADDR_SLOT_STATUS_BITS
In reply to Frank LiReplace the hardcoded value 2, which indicates 2 bits for I3C address status, with the predefined macro I3C_ADDR_SLOT_STATUS_BITS.
Improve maintainability and extensibility of the code.
---
Change from v3 to v4
- rename to I3C_ADDR_SLOT_STATUS_BITS
--- drivers/i3c/master.c | 4 ++-- include/linux/i3c/master.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/i3c/master.c +2 -2
@@ -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_STATUS_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_STATUS_BITS ;unsigned long *ptr;if (addr >I2C_MAX_ADDR )
include/linux/i3c/master.h +3 -1
@@ -299,6 +299,8 @@ enum i3c_addr_slot_status { I3C_ADDR_SLOT_STATUS_MASK = 3, }; +#define I3C_ADDR_SLOT_STATUS_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_STATUS_BITS ) /BITS_PER_LONG ];enum i3c_bus_mode mode;struct {unsigned long i3c;
Signature · 1 line
2.34.1
Frank Li
maintainerPATCH v4 3/11 i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT
In reply to Frank LiExtend 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.
┌────┬─────────────┬───┬─────────┬───┐
│S/Sr│ 7'h7E RnW=0 │ACK│ ENTDAA │ T ├────┐
└────┴─────────────┴───┴─────────┴───┘ │
┌─────────────────────────────────────────┘
│ ┌──┬─────────────┬───┬─────────────────┬────────────────┬───┬─────────┐
└─►│Sr│7'h7E RnW=1 │ACK│48bit UID BCR DCR│Assign 7bit Addr│PAR│ ACK/NACK│
└──┴─────────────┴───┴─────────────────┴────────────────┴───┴─────────┘Some master controllers (such as HCI) need to prepare the entire above transaction before sending it out to the I3C bus. This means that a 7-bit dynamic address needs to be allocated before knowing the target device's UID information.
However, some I3C targets want a specific address (called as "init_dyn_addr"), which is typically specified by the DT's assigned-address property. (Lower addresses have higher IBI priority, and the target can adjust this by using the assigned-address property if using DT). The function i3c_master_add_i3c_dev_locked() will switch to this "init_dyn_addr" if it is not in use.
Therefore, i3c_bus_get_free_addr() should return a free address that has not been claimed by any target devices as "init_dyn_addr" (indicated by I3C_ADDR_SLOT_EXT_INIT). This allows the device with the "init_dyn_addr" to switch to its "init_dyn_addr" when it hot-joins the I3C bus. Otherwise, if the "init_dyn_addr" is already in use by another I3C device, the target device will not be able to switch to its desired address.
If all of above address are already used, i3c_bus_get_free_addr() return one from the claimed as init_dyn_addr and free address slot. This ensures support devices as much as possible.
---
change from v3 to v4
- rewrite commit message and comment for i3c_bus_get_free_addr()
--- drivers/i3c/master.c | 68 ++++++++++++++++++++++++++++++++++++++++------ include/linux/i3c/master.h | 7 +++-- 2 files changed, 64 insertions(+), 11 deletions(-)
drivers/i3c/master.c +59 -9
@@ -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_STATUS_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_STATUS_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;
@@ -383,11 +400,44 @@ static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr)return status ==I3C_ADDR_SLOT_FREE ; } +/* +* ┌────┬─────────────┬───┬─────────┬───┐ +* │S/Sr│ 7'h7E RnW=0 │ACK│ ENTDAA │ T ├────┐ +* └────┴─────────────┴───┴─────────┴───┘ │ +* ┌─────────────────────────────────────────┘ +* │ ┌──┬─────────────┬───┬─────────────────┬────────────────┬───┬─────────┐ +* └─►│Sr│7'h7E RnW=1 │ACK│48bit UID BCR DCR│Assign 7bit Addr│PAR│ ACK/NACK│ +* └──┴─────────────┴───┴─────────────────┴────────────────┴───┴─────────┘ +* Some master controllers (such as HCI) need to prepare the entire above transaction before +* sending it out to the I3C bus. This means that a 7-bit dynamic address needs to be allocated +* before knowing the target device's UID information. +* +* However, some I3C targets want a specific address (called as "init_dyn_addr"), which is +* typically specified by the DT's assigned-address property. (Lower addresses have higher IBI +* priority, and the target can adjust this by using the assigned-address property if using DT). +* The function i3c_master_add_i3c_dev_locked() will switch to this "init_dyn_addr" if it is not +* in use. +* +* Therefore, i3c_bus_get_free_addr() should return a free address that has not been claimed by any +* target devices as "init_dyn_addr". This allows the device with the "init_dyn_addr" to switch to +* its "init_dyn_addr" when it hot-joins the I3C bus. Otherwise, if the "init_dyn_addr" is already +* in use by another I3C device, the target device will not be able to switch to its desired +* address. +* +* If all of above address are already used, i3c_bus_get_free_addr() return one from the claimed as +* init_dyn_addr and free address slot. This ensures support devices as much as possible. +*/ static int i3c_bus_get_free_addr (struct i3c_bus *bus,u8 start_addr) {enum i3c_addr_slot_status status;u8 addr; +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; + } +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 +1956,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 -2
@@ -284,7 +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 bitmask represents addresses that are preferred by some devices, +* such as the "assigned-address" property in a 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 +298,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_STATUS_BITS 2 +#define I3C_ADDR_SLOT_STATUS_BITS 4/** * struct i3c_bus - I3C bus object
Signature · 1 line
2.34.1
Frank Li
maintainerPATCH v4 4/11 i3c: master: Fix dynamic address leak when 'assigned-address' is present
In reply to Frank LiIf 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().
---
Change v3 to v4
- none
--- drivers/i3c/master.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/i3c/master.c +5 -10
@@ -1556,16 +1556,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 );
@@ -1956,9 +1949,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
@@ -2126,7 +2120,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
Frank Li
maintainerPATCH v4 5/11 i3c: master: Fix miss free init_dyn_addr at i3c_master_put_i3c_addrs()
In reply to Frank Liif (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 copy/paste error "dyn_addr" by replacing it with "init_dyn_addr".
---
change from v3 to v4
- mention copy/paste error
- Add Miquel's review tag
--- drivers/i3c/master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master.c +1 -1
@@ -1467,7 +1467,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
Frank Li
maintainerPATCH v4 6/11 i3c: master: svc: use repeat start when IBI WIN happens
In reply to Frank LiThere 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.
---
change from v3 to v4
- add miquel's ack tag
--- drivers/i3c/master/svc-i3c-master.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/i3c/master/svc-i3c-master.c +18 -18
@@ -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
Frank Li
maintainerPATCH v4 7/11 i3c: master: svc: manually emit NACK/ACK for hotjoin
In reply to Frank LiWhen 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.
---
change from v3 to v4
- add Miquel review tag
--- drivers/i3c/master/svc-i3c-master.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/i3c/master/svc-i3c-master.c +19 -1
@@ -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
Frank Li
maintainerPATCH v4 8/11 i3c: master: svc: need check IBIWON for dynamtica address assign
In reply to Frank LiWhen 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 during a REQUEST_PROC_DAA, NACK the IBI request then send a repeated start to continue current dynamtica address assign.
---
change from v3 to v4
- rework commit message
--- drivers/i3c/master/svc-i3c-master.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/i3c/master/svc-i3c-master.c +6 -0
@@ -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
Frank Li
maintainerPATCH v4 9/11 i3c: master: svc: use spin_lock_irqsave at svc_i3c_master_ibi_work()
In reply to Frank LiAccording 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 ACK/NACK Phase of I3C/I2C transfer. But maximum stall time is 100us. The IRQs have to be disabled to prevent schedule during the whole I3C transaction, otherwise, the I3C bus timeout may happen if any irq or schedule happen during transaction.
Replace mutex with spin_lock_irqsave() to avoid stalling SCL more than 100us.
---
Change from v3-v4
- improve commit message
- needn't mutex here, other place already use spin_lock_saveirq to protent i3c transfer.
--- drivers/i3c/master/svc-i3c-master.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/i3c/master/svc-i3c-master.c +11 -3
@@ -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 ACK/NACK Phase of I3C/I2C +* transfer. But maximum stall time is 100us. The IRQs have to be disabled to prevent +* schedule during the whole I3C transaction, otherwise, the I3C bus timeout may happen if +* any irq or schedule happen during 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
Frank Li
maintainerPATCH v4 10/11 i3c: master: svc: wait for Manual ACK/NACK Done before next step
In reply to Frank LiWait for the controller to complete emitting ACK/NACK, otherwise the next command may be omitted by the hardware.
A "command done" check in svc_i3c_master_nack(ack)_ibi() and change the return type to int to flag possible timeouts.
---
Change from v3 to v4
- rework commit message
- add miquel's review tag
- directly return readl(...)
--- drivers/i3c/master/svc-i3c-master.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)
drivers/i3c/master/svc-i3c-master.c +23 -6
@@ -384,10 +384,11 @@ 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; +u32 reg; ibi_ack_nack =SVC_I3C_MCTRL_REQUEST_IBI_ACKNACK ;if (mandatory_byte)
@@ -396,18 +397,30 @@ 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 ); + +return readl_poll_timeout_atomic (master->regs +SVC_I3C_MSTATUS , reg, +SVC_I3C_MSTATUS_MCTRLDONE (reg),1 ,1000 ); + } -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 +430,10 @@ static int svc_i3c_master_handle_ibi_won(struct svc_i3c_master *master, u32 mstaswitch (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 +884,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 +1160,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
Frank Li
maintainerPATCH v4 11/11 i3c: master: svc: fix possible assignment of the same address to two devices
In reply to Frank Lisvc_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.
---
change from v3 to v4
- add comments about not check return value
- add miquel's review tag
--- drivers/i3c/master/svc-i3c-master.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
drivers/i3c/master/svc-i3c-master.c +21 -6
@@ -1039,12 +1039,27 @@ static int svc_i3c_master_do_daa(struct i3c_master_controller *m)if (ret) 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; - } +/* +* Register all devices who participated to the core +* +* 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. +*/ +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
Frank Li
maintainerQuoted 2 lines · Frank Li
Signed-off-by Frank Li <[email protected]>---
Alex:
https://lore.kernel.org/linux-i3c/[email protected]/T/#m16fa9bb875b0ae9d37c5f6e91f90e375551c6366
There is some discuss about assiged address, I already explain the reason and ping 3 times,
These patch are actual fixed hot join issues.
How move forward?
best regard
Frank Li
Quoted 59 lines
Changes in v4:
- See each patch
- Link to v3: https://lore.kernel.org/r/[email protected]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: usespinlock_saveirqatsvc_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: Removei3c_dev_disable_ibi_locked(olddev)on device hotjoin
i3c: master: Replace hard code 2 with macroI3C_ADDR_SLOT_STATUS_BITS
i3c: master: Extend address status bit to 4 and addI3C_ADDR_SLOT_EXT_INIT
i3c: master: Fix dynamic address leak when 'assigned-address' is present
i3c: master: Fix miss freeinit_dyn_addrati3c_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: usespin_lock_irqsaveatsvc_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 devicesdrivers/i3c/master.c | 100 +++++++++++++++++++++-------- drivers/i3c/master/svc-i3c-master.c | 122 +++++++++++++++++++++++++++--------- include/linux/i3c/master.h | 9 ++- 3 files changed, 175 insertions(+), 56 deletions(-)---
base-commit:f2b9f0aeff2b3bb0446c955f0d8fac7659644c75
change-id: 20240724-i3c_fix-371bf8fa9e00Best regards,
---
Frank Li <[email protected]>
Miquel Raynal
maintainerHi Frank,
[email protected] wrote on Thu, 26 Sep 2024 13:02:06 -0400:
Quoted 10 lines · Frank Li
Quoted 2 lines
Signed-off-by Frank Li <[email protected]>---
Alex:
https://lore.kernel.org/linux-i3c/[email protected]/T/#m16fa9bb875b0ae9d37c5f6e91f90e375551c6366
There is some discuss about assiged address, I already explain the reason and ping 3 times,
Pinging will not help as long as the code is not clear and simplified. I honestly think the PID should be retrieved earlier in the HCI part and that would solve most of your issues.
Otherwise if that is not possible I still find hard to understand the big picture, the comments and the code. I've already spent quite a bit of time trying to improve it with you, but the logic is still a little bit too specific and complex from my point of view.
Quoted 1 line
These patch are actual fixed hot join issues.
It should not be the case. Hot-join should work without the devices having all the time the preferred address. If hot-join really does not work, then please split the series with the "preferred address" handling being done apart in a second series.
Thanks,
Miquèl
Frank Li
maintainerQuoted 8 lines · Miquel Raynal
Hi Frank,
[email protected] wrote on Thu, 26 Sep 2024 13:02:06 -0400:
Quoted 4 lines · Frank Li
Quoted 2 lines
Signed-off-by Frank Li <[email protected]>---
Quoted 8 lines
Quoted 6 lines
Alex:
https://lore.kernel.org/linux-i3c/[email protected]/T/#m16fa9bb875b0ae9d37c5f6e91f90e375551c6366
There is some discuss about assiged address, I already explain the reason and ping 3 times,
Pinging will not help as long as the code is not clear and simplified.
The problem is that no reply after I posted last reply and ping 3 times have not response about it.
Quoted 2 lines
I honestly think the PID should be retrieved earlier in the HCI part and that would solve most of your issues.
If there are problem or difference opinion, we can continue to discuss it. But no reply will stop the whole thing move forward.
I3C HCI Spec 1.2, sec 6.4.1, when do DAA, "DAA CMD and dynmatic address" queue to cmd together. We don't know PID before DAA CMD. So dynmatic address can NOT get based on PID.
If I am wrong about HCI, let me know since I have not worked HCI before.
Quoted 6 lines
Otherwise if that is not possible I still find hard to understand the big picture, the comments and the code. I've already spent quite a bit of time trying to improve it with you, but the logic is still a little bit too specific and complex from my point of view.
Quoted 6 lines
Quoted 1 line
These patch are actual fixed hot join issues.
It should not be the case. Hot-join should work without the devices having all the time the preferred address. If hot-join really does not work, then please split the series with the "preferred address" handling being done apart in a second series.
I can do that, could you check svc part and most already acked you? I can post svc part only later by addressing your comments if you have.
Frank
Quoted 3 lines
Thanks,
Miquèl
Frank Li
maintainerQuoted 2 lines · Frank Li
Signed-off-by Frank Li <[email protected]>---
Alex:
you can superseded this serie. According to mirquel's suggestion,
I splitted into 4 parts:
1. svc driver fix patches: https://lore.kernel.org/imx/ZvwpMBWzNjTXpPZF@lizhi-Precision-Tower-5810/T/#t
2. i3c master fix patches with miquel's ack
a: https://lore.kernel.org/imx/[email protected]/T/#u
b: https://lore.kernel.org/imx/[email protected]/T/#u
3. ongoing discussion on about dt assigne address:
https://lore.kernel.org/imx/[email protected]/T/#t
I hope above help you manage these patches.
Frank
Quoted 59 lines
Changes in v4:
- See each patch
- Link to v3: https://lore.kernel.org/r/[email protected]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: usespinlock_saveirqatsvc_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: Removei3c_dev_disable_ibi_locked(olddev)on device hotjoin
i3c: master: Replace hard code 2 with macroI3C_ADDR_SLOT_STATUS_BITS
i3c: master: Extend address status bit to 4 and addI3C_ADDR_SLOT_EXT_INIT
i3c: master: Fix dynamic address leak when 'assigned-address' is present
i3c: master: Fix miss freeinit_dyn_addrati3c_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: usespin_lock_irqsaveatsvc_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 devicesdrivers/i3c/master.c | 100 +++++++++++++++++++++-------- drivers/i3c/master/svc-i3c-master.c | 122 +++++++++++++++++++++++++++--------- include/linux/i3c/master.h | 9 ++- 3 files changed, 175 insertions(+), 56 deletions(-)---
base-commit:f2b9f0aeff2b3bb0446c955f0d8fac7659644c75
change-id: 20240724-i3c_fix-371bf8fa9e00Best regards,
---
Frank Li <[email protected]>