I3C device addresing adjustments
v4 cover I3C device addresing adjustments
This patch series is based on Vitor's Soares previous patch series. I'm trying to meet requirements and comments which came up during the code review.
Description related to things which were taken from v3:
Propagate i3c_boardinfo, if available, to i3c_dev_desc during i3c_master_add_i3c_dev_locked(). This change will permit to describe devices with a preferable dynamic address (important due to priority reason) but without a static address in DT.
In addition, I'm improving the management of the Data Address Table in DW I3C Master by keeping the free slots consecutive.
Sending the devices without DA in DEFSLVS frame will be fixed in separate patch if needed.
There are also some improvements related to DT bindings documentation.
Changes in v4:
- Remove device detach/free
- Add PID check before registering the device
- Add pre-reservation of init_dyn_addr
Change in v3:
- Change cover letter
- Change commit message for patch 1
- Add Rob rb-tags
Change in v2:
- Move out detach/free the i3c_dev_desc from pre_assign_dyn_addr()
- Change i3c_master_search_i3c_boardinfo(newdev) to i3c_master_init_i3c_dev_boardinfo(newdev)
- Add fixes, stable tags on patch 2
- Add a note for no guarantee of 'assigned-address' use
Przemysław Gaj (2):
i3c: master: pre-reserve boardinfo->init_dyn_addr when available
i3c: master: make sure the PID is set before registering the device
Vitor Soares (4):
i3c: master: make sure ->boardinfo is initialized in
add_i3c_dev_locked()
dt-bindings: i3c: Make 'assigned-address' valid if static address == 0
dt-bindings: i3c: add a note for no guarantee of 'assigned-address'
use
i3c: master: dw: reattach device on first available location of
address table
Documentation/devicetree/bindings/i3c/i3c.txt | 15 +++++++++++--- drivers/i3c/master.c | 29 +++++++++++++++++++++++++-- drivers/i3c/master/dw-i3c-master.c | 16 +++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) mode change 100644 => 100755 drivers/i3c/master.c
Signature · 7 lines
2.14.0 _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
PATCH v4 1/6 i3c: master: make sure ->boardinfo is initialized in add_i3c_dev_locked()
From: Vitor Soares <[email protected]>
The newdev->boardinfo assignment was missing in i3c_master_add_i3c_dev_locked() and hence the ->of_node info isn't propagated to i3c_dev_desc.
Fix this by trying to initialize device i3c_dev_boardinfo if available.
---
Change in v4:
- Remove addrstatus check, this will be sent as a separate patch
Change in v3:
- None
Changes in v2:
- Change commit message
- Change i3c_master_search_i3c_boardinfo(newdev) to i3c_master_init_i3c_dev_boardinfo(newdev)
- Add fixes, stable tags
--- drivers/i3c/master.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) mode change 100644 => 100755 drivers/i3c/master.c
drivers/i3c/master.c +18 -0
@@ -1774,6 +1774,22 @@ i3c_master_search_i3c_dev_duplicate(struct i3c_dev_desc *refdev)return NULL ; } +static void i3c_master_init_i3c_dev_boardinfo (struct i3c_dev_desc *dev) +{ +struct i3c_master_controller *master =i3c_dev_get_master (dev); +struct i3c_dev_boardinfo *boardinfo; + +if (dev->boardinfo) +return ; + +list_for_each_entry (boardinfo, &master->boardinfo.i3c, node) { +if (dev->info.pid == boardinfo->pid) { + dev->boardinfo = boardinfo; +return ; + } + } +} +/** * i3c_master_add_i3c_dev_locked() - add an I3C slave to the bus * @master: master used to send frames on the bus
@@ -1854,6 +1870,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master,if (ret) goto err_detach_dev; +i3c_master_init_i3c_dev_boardinfo (newdev); +/* * Depending on our previous state, the expected dynamic address might * differ:
Signature · 7 lines
2.14.0 _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
PATCH v4 2/6 i3c: master: pre-reserve boardinfo->init_dyn_addr when available
In reply to Przemysław GajIt may be the case that SETDASA fails for some reason. Reserve ->init_dyn_addr when it's defined to prevent assigning this address to another slave device. This way when device shows up we don't have to re-assign addresses.
--- drivers/i3c/master.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/i3c/master.c +7 -1
@@ -1263,7 +1263,8 @@ 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 ); }
@@ -1675,6 +1676,11 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) ret = -EBUSY ; goto err_detach_devs; } + +/* Reserve the slot. */ +i3c_bus_set_addr_slot_status (&master->bus, + i3cboardinfo->init_dyn_addr, +I3C_ADDR_SLOT_I3C_DEV ); } i3cdev =i3c_master_alloc_i3c_dev (master, &info);
Signature · 7 lines
2.14.0 _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
Re: [PATCH v4 2/6] i3c: master: pre-reserve boardinfo->init_dyn_addr when available
Quoted 15 lines · On Tue, 10 Dec 2019 11:14:58 +0100 Przemysław Gaj <[email protected]> wrote:
It may be the case that SETDASA fails for some reason. Reserve ->init_dyn_addr when it's defined to prevent assigning this address to another slave device. This way when device shows up we don't have to re-assign addresses.
Signed-off-by Przemysław Gaj <[email protected]>--- drivers/i3c/master.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/i3c/master.c +0
-0
drivers/i3c/master.c static void i3c_master_put_i3c_addrs(struct i3c_dev_desc *dev) · line 1268
Quoted 7 lines
drivers/i3c/master.c +2
-1@@ -1263,7 +1263,8 @@ 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 );
Should be fixed in a separate patch, or at least mentioned in the commit message.
drivers/i3c/master.c static int i3c_master_bus_init(struct i3c_master_controller *master) · line 1683
Quoted 11 lines
drivers/i3c/master.c +5
-0}@@ -1675,6 +1676,11 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) ret = -EBUSY ; goto err_detach_devs; } + +/* Reserve the slot. */ +i3c_bus_set_addr_slot_status (&master->bus, + i3cboardinfo->init_dyn_addr, +I3C_ADDR_SLOT_I3C_DEV );
Looks like the "reserve/release init_dyn_addr slot" logic is asymmetric. I wonder if that's not a problem. Can't we end up in a situation where the ->init_dyn_addr is released (when SETDASA() fails) and then re-used without being reserved (when the device is later discovered through a regular DAA)?
So maybe I was wrong and we should indeed reserve the address in the i3c_master_get_i3c_addrs() path.
drivers/i3c/master.c static int i3c_master_bus_init(struct i3c_master_controller *master) · line 1686
Quoted 3 lines
drivers/i3c/master.c +0
-0} i3cdev =i3c_master_alloc_i3c_dev (master, &info);
_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
RE: [PATCH v4 2/6] i3c: master: pre-reserve boardinfo->init_dyn_addr when available
In reply to Przemysław GajHi Przemysław,
From: Przemysław Gaj <[email protected]>
Date: Tue, Dec 10, 2019 at 10:14:58
Quoted 38 lines
It may be the case that SETDASA fails for some reason. Reserve ->init_dyn_addr when it's defined to prevent assigning this address to another slave device. This way when device shows up we don't have to re-assign addresses.
Signed-off-by Przemysław Gaj <[email protected]>--- drivers/i3c/master.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/i3c/master.c +7
-1@@ -1263,7 +1263,8 @@ 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 ); }@@ -1675,6 +1676,11 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) ret = -EBUSY ; goto err_detach_devs; } + +/* Reserve the slot. */ +i3c_bus_set_addr_slot_status (&master->bus, + i3cboardinfo->init_dyn_addr, +I3C_ADDR_SLOT_I3C_DEV ); } i3cdev =i3c_master_alloc_i3c_dev (master, &info);Signature · 1 line
2.14.0
In my experience we should pre-reserve all DT DA entries and not use them during the ENTDAA for safety reasons.
That would be one of my next steps in this patch series.
Best regards,
Vitor Soares
_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
Re: [PATCH v4 2/6] i3c: master: pre-reserve boardinfo->init_dyn_addr when available
Hi Vitor,
Quoted 41 lines · Vitor Soares
Hi Przemysław,
From: Przemysław Gaj <[email protected]>
Date: Tue, Dec 10, 2019 at 10:14:58Quoted 35 lines
It may be the case that SETDASA fails for some reason. Reserve ->init_dyn_addr when it's defined to prevent assigning this address to another slave device. This way when device shows up we don't have to re-assign addresses.
Signed-off-by Przemysław Gaj <[email protected]>--- drivers/i3c/master.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/i3c/master.c +7
-1@@ -1263,7 +1263,8 @@ 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 ); }@@ -1675,6 +1676,11 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) ret = -EBUSY ; goto err_detach_devs; } + +/* Reserve the slot. */ +i3c_bus_set_addr_slot_status (&master->bus, + i3cboardinfo->init_dyn_addr, +I3C_ADDR_SLOT_I3C_DEV ); }
Quoted 7 lines
Quoted 3 lines
drivers/i3c/master.c +0
-0i3cdev =i3c_master_alloc_i3c_dev (master, &info);Signature · 1 line
2.14.0In my experience we should pre-reserve all DT DA entries and not use them during the ENTDAA for safety reasons.
That would be one of my next steps in this patch series.
Actually, I reserve DT DA address above. The only thing I will rework, I won't free up the address. That will be documented in the code.
We can rework it later if really needed.
Quoted 4 lines
Best regards,
Vitor Soares
Signature · 8 lines
-- Regards, Przemek _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
PATCH v4 3/6 i3c: master: make sure the PID is set before registering the device
In reply to Przemysław GajIf SETDASA failed for some reason or Provisioned ID (PID) retrieval failed PID may not be set. Check that condition before registering the device.
--- drivers/i3c/master.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i3c/master.c +2 -1
@@ -1450,7 +1450,8 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)return ;i3c_bus_for_each_i3cdev (&master->bus, desc) { -if (desc->dev || !desc->info.dyn_addr || desc == master->this) +if (desc->dev || !desc->info.dyn_addr || + desc == master->this || !desc->info.pid)continue ; desc->dev =kzalloc (sizeof (*desc->dev),GFP_KERNEL );
Signature · 7 lines
2.14.0 _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
PATCH v4 4/6 dt-bindings: i3c: Make 'assigned-address' valid if static address == 0
In reply to Przemysław GajFrom: Vitor Soares <[email protected]>
The I3C devices without a static address can require a specific dynamic address for priority reasons.
Let's update the binding document to make the 'assigned-address' property valid if static address == 0 and add an example with this use case.
---
Change in v3:
- Add Rob rb-tag
Change in v2:
- Fix typo in commit message
--- Documentation/devicetree/bindings/i3c/i3c.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/i3c/i3c.txt +10 -3
@@ -100,9 +100,7 @@ Required properties Optional properties ------------------- -- assigned-address: dynamic address to be assigned to this device. This - property is only valid if the I3C device has a static - address (first cell of the reg property != 0). +- assigned-address: dynamic address to be assigned to this device. Example:
@@ -129,6 +127,15 @@ Example: assigned-address = <0xa>; }; + /* + * I3C device without a static I2C address but requiring + * specific dynamic address. + */ + sensor@0,39200154004 { + reg = <0x0 0x6072 0x303904d2>; + assigned-address = <0xb>; + }; + /* * I3C device without a static I2C address but requiring * resources described in the DT.
Signature · 7 lines
2.14.0 _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
PATCH v4 5/6 dt-bindings: i3c: add a note for no guarantee of 'assigned-address' use
In reply to Przemysław GajFrom: Vitor Soares <[email protected]>
By default, the framework will try to assign the 'assigned-address' to the device but if the address is already in use the device dynamic address will be different.
---
Change in v3:
- Add Rob rb-tag
--- Documentation/devicetree/bindings/i3c/i3c.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/i3c/i3c.txt +3 -1
@@ -100,7 +100,9 @@ Required properties Optional properties ------------------- -- assigned-address: dynamic address to be assigned to this device. +- assigned-address: dynamic address to be assigned to this device. The framework + will try to assign this dynamic address but if something + fails the device dynamic address will be different. Example:
Signature · 7 lines
2.14.0 _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
PATCH v4 6/6 i3c: master: dw: reattach device on first available location of address table
In reply to Przemysław GajFrom: Vitor Soares <[email protected]>
For today the reattach function only update the device address on the controller.
Update the location to the first available too, will optimize the enumeration process avoiding additional checks to keep the available positions on address table consecutive.
---
Change in v3:
- None
Change in v2:
- Add Boris rb-tag
--- drivers/i3c/master/dw-i3c-master.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/i3c/master/dw-i3c-master.c +16 -0
@@ -899,6 +899,22 @@ static int dw_i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev,struct dw_i3c_i2c_dev_data *data =i3c_dev_get_master_data (dev);struct i3c_master_controller *m =i3c_dev_get_master (dev);struct dw_i3c_master *master =to_dw_i3c_master (m); +int pos; + + pos =dw_i3c_master_get_free_pos (master); + +if (data->index > pos && pos >0 ) { +writel (0 , + master->regs + +DEV_ADDR_TABLE_LOC (master->datstartaddr, data->index)); + + master->addrs[data->index] =0 ; + master->free_pos |=BIT (data->index); + + data->index = pos; + master->addrs[pos] = dev->info.dyn_addr; + master->free_pos &= ~BIT (pos); + } writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(dev->info.dyn_addr), master->regs +
Signature · 7 lines
2.14.0 _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
RE: [PATCH v4 6/6] i3c: master: dw: reattach device on first available location of address table
++João Pinto
Hi Przemysław,
Sorry for this, but please drop this patch from this series. Boris as Maintainer could already merge it when gives rb tag.
From: Przemysław Gaj <[email protected]>
Date: Tue, Dec 10, 2019 at 10:15:02
Quoted 51 lines
From: Vitor Soares <[email protected]>
For today the reattach function only update the device address on the controller.
Update the location to the first available too, will optimize the enumeration process avoiding additional checks to keep the available positions on address table consecutive.
Signed-off-by Vitor Soares <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Signed-off-by Przemyslaw Gaj <[email protected]>---
Change in v3:
- NoneChange in v2:
- Add Boris rb-tag--- drivers/i3c/master/dw-i3c-master.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/i3c/master/dw-i3c-master.c +16
-0@@ -899,6 +899,22 @@ static int dw_i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev,struct dw_i3c_i2c_dev_data *data =i3c_dev_get_master_data (dev);struct i3c_master_controller *m =i3c_dev_get_master (dev);struct dw_i3c_master *master =to_dw_i3c_master (m); +int pos; + + pos =dw_i3c_master_get_free_pos (master); + +if (data->index > pos && pos >0 ) { +writel (0 , + master->regs + +DEV_ADDR_TABLE_LOC (master->datstartaddr, data->index)); + + master->addrs[data->index] =0 ; + master->free_pos |=BIT (data->index); + + data->index = pos; + master->addrs[pos] = dev->info.dyn_addr; + master->free_pos &= ~BIT (pos); + } writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(dev->info.dyn_addr), master->regs +Signature · 1 line
2.14.0
Best regards,
Vitor Soares
_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
Re: [PATCH v4 6/6] i3c: master: dw: reattach device on first available location of address table
Hi Vitor,
Quoted 7 lines · Vitor Soares
++João Pinto
Hi Przemysław,
Sorry for this, but please drop this patch from this series. Boris as Maintainer could already merge it when gives rb tag.
OK, understand. Thank you for the information.
Quoted 58 lines
From: Przemysław Gaj <[email protected]>
Date: Tue, Dec 10, 2019 at 10:15:02Quoted 51 lines
From: Vitor Soares <[email protected]>
For today the reattach function only update the device address on the controller.
Update the location to the first available too, will optimize the enumeration process avoiding additional checks to keep the available positions on address table consecutive.
Signed-off-by Vitor Soares <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Signed-off-by Przemyslaw Gaj <[email protected]>---
Change in v3:
- NoneChange in v2:
- Add Boris rb-tag--- drivers/i3c/master/dw-i3c-master.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/i3c/master/dw-i3c-master.c +16
-0@@ -899,6 +899,22 @@ static int dw_i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev,struct dw_i3c_i2c_dev_data *data =i3c_dev_get_master_data (dev);struct i3c_master_controller *m =i3c_dev_get_master (dev);struct dw_i3c_master *master =to_dw_i3c_master (m); +int pos; + + pos =dw_i3c_master_get_free_pos (master); + +if (data->index > pos && pos >0 ) { +writel (0 , + master->regs + +DEV_ADDR_TABLE_LOC (master->datstartaddr, data->index)); + + master->addrs[data->index] =0 ; + master->free_pos |=BIT (data->index); + + data->index = pos; + master->addrs[pos] = dev->info.dyn_addr; + master->free_pos &= ~BIT (pos); + } writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(dev->info.dyn_addr), master->regs +Signature · 1 line
2.14.0Best regards,
Vitor Soares
Signature · 8 lines
-- Regards, Przemek _______________________________________________ linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
Re: [PATCH v4 6/6] i3c: master: dw: reattach device on first available location of address table
In reply to Vitor SoaresQuoted 6 lines · On Tue, 10 Dec 2019 14:40:49 +0000 Vitor Soares <[email protected]>…
++João Pinto
Hi Przemysław,
Sorry for this, but please drop this patch from this series. Boris as Maintainer could already merge it when gives rb tag.
Noted, I'll queue that one separately (IIUC, it's independent from the rest of the series).
Quoted 51 lines
From: Przemysław Gaj <[email protected]>
Date: Tue, Dec 10, 2019 at 10:15:02Quoted 47 lines
From: Vitor Soares <[email protected]>
For today the reattach function only update the device address on the controller.
Update the location to the first available too, will optimize the enumeration process avoiding additional checks to keep the available positions on address table consecutive.
Signed-off-by Vitor Soares <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Signed-off-by Przemyslaw Gaj <[email protected]>---
Change in v3:
- NoneChange in v2:
- Add Boris rb-tag--- drivers/i3c/master/dw-i3c-master.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/i3c/master/dw-i3c-master.c +16
-0@@ -899,6 +899,22 @@ static int dw_i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev,struct dw_i3c_i2c_dev_data *data =i3c_dev_get_master_data (dev);struct i3c_master_controller *m =i3c_dev_get_master (dev);struct dw_i3c_master *master =to_dw_i3c_master (m); +int pos; + + pos =dw_i3c_master_get_free_pos (master); + +if (data->index > pos && pos >0 ) { +writel (0 , + master->regs + +DEV_ADDR_TABLE_LOC (master->datstartaddr, data->index)); + + master->addrs[data->index] =0 ; + master->free_pos |=BIT (data->index); + + data->index = pos; + master->addrs[pos] = dev->info.dyn_addr; + master->free_pos &= ~BIT (pos); + }
Quoted 7 lines
Quoted 4 lines
drivers/i3c/master/dw-i3c-master.c +0
-0writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(dev->info.dyn_addr), master->regs +Signature · 1 line
2.14.0Best regards,
Vitor Soares
_______________________________________________
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c