i3c: master: svc: Prevent incomplete IBI transaction
Subsystems (2)
PATCH v2 1/1 i3c: master: svc: Prevent incomplete IBI transaction
From: Stanley Chu <[email protected]>
If no free IBI slot is available, svc_i3c_master_handle_ibi returns immediately. This causes the STOP condition to be missed because the EmitStop request is sent when the transfer is not complete. To resolve this, svc_i3c_master_handle_ibi must wait for the transfer to complete before returning.
---
Changes since v1:
* do not touch coding style change
--- drivers/i3c/master/svc-i3c-master.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/i3c/master/svc-i3c-master.c +14 -8
@@ -406,21 +406,27 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,int ret, val;u8 *buf; - slot =i3c_generic_ibi_get_free_slot (data->ibi_pool); -if (!slot) -return -ENOSPC ; - - slot->len =0 ; - buf = slot->data; - +/* +* Wait for transfer to complete before returning. Otherwise, the EmitStop +* request might be sent when the transfer is not complete. +*/ ret =readl_relaxed_poll_timeout (master->regs +SVC_I3C_MSTATUS , val,SVC_I3C_MSTATUS_COMPLETE (val),0 ,1000 );if (ret) {dev_err (master->dev,"Timeout when polling for COMPLETE\n" ); -i3c_generic_ibi_recycle_slot (data->ibi_pool, slot);return ret; } + slot =i3c_generic_ibi_get_free_slot (data->ibi_pool); +if (!slot) { +dev_dbg (master->dev,"No free ibi slot, drop the data\n" ); +writel (SVC_I3C_MDATACTRL_FLUSHRB , master->regs +SVC_I3C_MDATACTRL ); +return -ENOSPC ; + } + + slot->len =0 ; + buf = slot->data; +while (SVC_I3C_MSTATUS_RXPEND (readl (master->regs +SVC_I3C_MSTATUS )) && slot->len <SVC_I3C_FIFO_SIZE ) { mdatactrl =readl (master->regs +SVC_I3C_MDATACTRL );
Signature · 1 line
2.34.1
Quoted 11 lines · Stanley Chu
From: Stanley Chu <[email protected]>
If no free IBI slot is available,
svc_i3c_master_handle_ibireturns immediately. This causes the STOP condition to be missed because the EmitStop request is sent when the transfer is not complete. To resolve this,svc_i3c_master_handle_ibimust wait for the transfer to complete before returning.Fixes dd3c52846d59 ("i3c: master: svc: Add Silvaco I3C master driver")Signed-off-by Stanley Chu <[email protected]>---
Quoted 49 lines
Changes since v1:
* do not touch coding style change--- drivers/i3c/master/svc-i3c-master.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)drivers/i3c/master/svc-i3c-master.c +14
-9@@ -406,21 +406,27 @@ static int svc_i3c_master_handle_ibi(struct svc_i3c_master *master,int ret, val;u8 *buf; - slot =i3c_generic_ibi_get_free_slot (data->ibi_pool); -if (!slot) -return -ENOSPC ; - - slot->len =0 ; - buf = slot->data; - +/* +* Wait for transfer to complete before returning. Otherwise, the EmitStop +* request might be sent when the transfer is not complete. +*/ ret =readl_relaxed_poll_timeout (master->regs +SVC_I3C_MSTATUS , val,SVC_I3C_MSTATUS_COMPLETE (val),0 ,1000 );if (ret) {dev_err (master->dev,"Timeout when polling for COMPLETE\n" ); -i3c_generic_ibi_recycle_slot (data->ibi_pool, slot);return ret; } + slot =i3c_generic_ibi_get_free_slot (data->ibi_pool); +if (!slot) { +dev_dbg (master->dev,"No free ibi slot, drop the data\n" ); +writel (SVC_I3C_MDATACTRL_FLUSHRB , master->regs +SVC_I3C_MDATACTRL ); +return -ENOSPC ; + } + + slot->len =0 ; + buf = slot->data; +while (SVC_I3C_MSTATUS_RXPEND (readl (master->regs +SVC_I3C_MSTATUS )) && slot->len <SVC_I3C_FIFO_SIZE ) { mdatactrl =readl (master->regs +SVC_I3C_MDATACTRL ); --2.34.1
Hello,
Quoted 9 lines · Frank Li
Quoted 8 lines · Stanley Chu
From: Stanley Chu <[email protected]>
If no free IBI slot is available,
svc_i3c_master_handle_ibireturns immediately. This causes the STOP condition to be missed because the EmitStop request is sent when the transfer is not complete. To resolve this,svc_i3c_master_handle_ibimust wait for the transfer to complete before returning.
Quoted 5 lines
Quoted 3 lines
Fixes dd3c52846d59 ("i3c: master: svc: Add Silvaco I3C master driver")Signed-off-by Stanley Chu <[email protected]>---
Reviewed-by Frank Li <[email protected]>
Thanks,
Miquèl
Quoted 8 lines · Stanley Chu
If no free IBI slot is available,
svc_i3c_master_handle_ibireturns immediately. This causes the STOP condition to be missed because the EmitStop request is sent when the transfer is not complete. To resolve this,svc_i3c_master_handle_ibimust wait for the transfer to complete before returning.[...]
Applied, thanks!
[1/1] i3c: master: svc: Prevent incomplete IBI transaction
https://git.kernel.org/abelloni/c/3a36273e5a07
Best regards,
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com