i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk
Subsystems (2)
PATCH 1/1 i3c: master: svc: Fix npcm845 FIFO_EMPTY quirk
From: Stanley Chu <[email protected]>
Prefilling in private write transfers is only necessary when the FIFO is empty. Otherwise, if the transfer is NACKed due to IBIWON and retries continue, data may be prefilled again but could be lost because the FIFO is not empty.
--- drivers/i3c/master/svc-i3c-master.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/i3c/master/svc-i3c-master.c +10 -1
@@ -104,6 +104,7 @@#define SVC_I3C_MDATACTRL_TXTRIG_FIFO_NOT_FULL GENMASK(5, 4)#define SVC_I3C_MDATACTRL_RXTRIG_FIFO_NOT_EMPTY 0#define SVC_I3C_MDATACTRL_RXCOUNT (x) FIELD_GET(GENMASK(28, 24), (x)) +#define SVC_I3C_MDATACTRL_TXCOUNT (x) FIELD_GET(GENMASK(20, 16), (x))#define SVC_I3C_MDATACTRL_TXFULL BIT(30)#define SVC_I3C_MDATACTRL_RXEMPTY BIT(31)
@@ -280,6 +281,13 @@ static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask)return !!(master->enabled_events & mask); } +static inline bool svc_i3c_master_tx_empty (struct svc_i3c_master *master) +{ +u32 reg =readl (master->regs +SVC_I3C_MDATACTRL ); + +return (SVC_I3C_MDATACTRL_TXCOUNT (reg) ==0 ); +} +static bool svc_i3c_master_error (struct svc_i3c_master *master) {u32 mstatus, merrwarn;
@@ -1303,7 +1311,8 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,* The only way to work around this hardware issue is to let the * FIFO start filling as soon as possible after EmitStartAddr. */ -if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len) { +if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len && +svc_i3c_master_tx_empty (master)) {u32 end = xfer_len >SVC_I3C_FIFO_SIZE ?0 :SVC_I3C_MWDATAB_END ;u32 len =min_t (u32, xfer_len,SVC_I3C_FIFO_SIZE );
Signature · 1 line
2.34.1
Frank Li
maintainerQuoted 6 lines · Stanley Chu
From: Stanley Chu <[email protected]>
Prefilling in private write transfers is only necessary when the FIFO is empty. Otherwise, if the transfer is NACKed due to IBIWON and retries continue, data may be prefilled again but could be lost because the FIFO is not empty.
why "maybe prefilled", please use certain words.
Quoted 34 lines
Fixes 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")Signed-off-by Stanley Chu <[email protected]>--- drivers/i3c/master/svc-i3c-master.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/i3c/master/svc-i3c-master.c +8
-0@@ -104,6 +104,7 @@#define SVC_I3C_MDATACTRL_TXTRIG_FIFO_NOT_FULL GENMASK(5, 4)#define SVC_I3C_MDATACTRL_RXTRIG_FIFO_NOT_EMPTY 0#define SVC_I3C_MDATACTRL_RXCOUNT (x) FIELD_GET(GENMASK(28, 24), (x)) +#define SVC_I3C_MDATACTRL_TXCOUNT (x) FIELD_GET(GENMASK(20, 16), (x))#define SVC_I3C_MDATACTRL_TXFULL BIT(30)#define SVC_I3C_MDATACTRL_RXEMPTY BIT(31)@@ -280,6 +281,13 @@ static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask)return !!(master->enabled_events & mask); } +static inline bool svc_i3c_master_tx_empty (struct svc_i3c_master *master) +{ +u32 reg =readl (master->regs +SVC_I3C_MDATACTRL ); + +return (SVC_I3C_MDATACTRL_TXCOUNT (reg) ==0 ); +} +static bool svc_i3c_master_error (struct svc_i3c_master *master) {u32 mstatus, merrwarn;
drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_xfer(struct svc_i3c_master *master, · line 1317
Quoted 8 lines
drivers/i3c/master/svc-i3c-master.c +2
-1@@ -1303,7 +1311,8 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,* The only way to work around this hardware issue is to let the * FIFO start filling as soon as possible after EmitStartAddr. */ -if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len) { +if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len && +svc_i3c_master_tx_empty (master)) {u32 end = xfer_len >SVC_I3C_FIFO_SIZE ?0 :SVC_I3C_MWDATAB_END ;u32 len =min_t (u32, xfer_len,SVC_I3C_FIFO_SIZE );
if prefill to FIFO SIZE each time, such as
replace SVC_I3C_FIFO_SIZE with
SVC_I3C_FIFO_SIZE - SVC_I3C_MDATACTRL_TXCOUNT(readl(master->regs + SVC_I3C_MDATACTRL)).
Frank
Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c +0
-1--2.34.1
Hi Frank,
Quoted 10 lines · Frank Li
Quoted 6 lines · Stanley Chu
From: Stanley Chu <[email protected]>
Prefilling in private write transfers is only necessary when the FIFO is empty. Otherwise, if the transfer is NACKed due to IBIWON and retries continue, data may be prefilled again but could be lost because the FIFO is not empty.
why "maybe prefilled", please use certain words.
The original code didn't consider the retry case, data lost happen in the retry case only when total write bytes is larger than FIFO size, not always happen.
In the example of writing 17 bytes (FIFO size is 16), the last byte is lost.
1. Emit S+Addr/W
2. Write 16 bytes to FIFO (FIFO is full)
3. NACKed due to IBIWON
4. (retry) Emit Sr+Addr/W
5. Write last byte to FIFO (data lost)
I just need to prefill FIFO in the beginning to make sure FIFO is not empty when HW starts transmitting.
So, this patch adds a condition that prefill FIFO only when FIFO is empty.
Quoted 46 lines
Quoted 35 lines
Fixes 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")Signed-off-by Stanley Chu <[email protected]>--- drivers/i3c/master/svc-i3c-master.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/i3c/master/svc-i3c-master.c +8
-0@@ -104,6 +104,7 @@#define SVC_I3C_MDATACTRL_TXTRIG_FIFO_NOT_FULL GENMASK(5, 4)#define SVC_I3C_MDATACTRL_RXTRIG_FIFO_NOT_EMPTY 0#define SVC_I3C_MDATACTRL_RXCOUNT (x) FIELD_GET(GENMASK(28, 24), (x)) +#define SVC_I3C_MDATACTRL_TXCOUNT (x) FIELD_GET(GENMASK(20, 16), (x))#define SVC_I3C_MDATACTRL_TXFULL BIT(30)#define SVC_I3C_MDATACTRL_RXEMPTY BIT(31)@@ -280,6 +281,13 @@ static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask)return !!(master->enabled_events & mask); } +static inline bool svc_i3c_master_tx_empty (struct svc_i3c_master *master) +{ +u32 reg =readl (master->regs +SVC_I3C_MDATACTRL ); + +return (SVC_I3C_MDATACTRL_TXCOUNT (reg) ==0 ); +} +static bool svc_i3c_master_error (struct svc_i3c_master *master) {u32 mstatus, merrwarn;drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_xfer(struct svc_i3c_master *master, · line 1317
Quoted 8 lines
drivers/i3c/master/svc-i3c-master.c +2
-1@@ -1303,7 +1311,8 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,* The only way to work around this hardware issue is to let the * FIFO start filling as soon as possible after EmitStartAddr. */ -if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len) { +if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len && +svc_i3c_master_tx_empty (master)) {u32 end = xfer_len >SVC_I3C_FIFO_SIZE ?0 :SVC_I3C_MWDATAB_END ;u32 len =min_t (u32, xfer_len,SVC_I3C_FIFO_SIZE );if prefill to FIFO SIZE each time, such as
Quoted 4 lines
replace
SVC_I3C_FIFO_SIZEwith
SVC_I3C_FIFO_SIZE-SVC_I3C_MDATACTRL_TXCOUNT(readl(master->regs + SVC_I3C_MDATACTRL)).
The free space is SVC_I3C_FIFO_SIZE when FIFO is empty, no need to check TX count again.
--
Stanley
Quoted 5 lines
Frank
Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c +0
-1--2.34.1
Frank Li
maintainerQuoted 13 lines · Stanley Chu
Hi Frank,
Quoted 10 lines · Frank Li
Quoted 6 lines · Stanley Chu
From: Stanley Chu <[email protected]>
Prefilling in private write transfers is only necessary when the FIFO is empty. Otherwise, if the transfer is NACKed due to IBIWON and retries continue, data may be prefilled again but could be lost because the FIFO is not empty.
why "maybe prefilled", please use certain words.
Quoted 9 lines
The original code didn't consider the retry case, data lost happen in the retry case only when total write bytes is larger than FIFO size, not always happen.
In the example of writing 17 bytes (FIFO size is 16), the last byte is lost.
1. Emit S+Addr/W
2. Write 16 bytes to FIFO (FIFO is full)
3. NACKed due to IBIWON
4. (retry) Emit Sr+Addr/W
5. Write last byte to FIFO (data lost)
You need descript clearly at commit message about this.
Quoted 51 lines
I just need to prefill FIFO in the beginning to make sure FIFO is not empty when HW starts transmitting.
So, this patch adds a condition that prefill FIFO only when FIFO is empty.Quoted 46 lines
Quoted 35 lines
Fixes 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")Signed-off-by Stanley Chu <[email protected]>--- drivers/i3c/master/svc-i3c-master.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/i3c/master/svc-i3c-master.c +8
-0@@ -104,6 +104,7 @@#define SVC_I3C_MDATACTRL_TXTRIG_FIFO_NOT_FULL GENMASK(5, 4)#define SVC_I3C_MDATACTRL_RXTRIG_FIFO_NOT_EMPTY 0#define SVC_I3C_MDATACTRL_RXCOUNT (x) FIELD_GET(GENMASK(28, 24), (x)) +#define SVC_I3C_MDATACTRL_TXCOUNT (x) FIELD_GET(GENMASK(20, 16), (x))#define SVC_I3C_MDATACTRL_TXFULL BIT(30)#define SVC_I3C_MDATACTRL_RXEMPTY BIT(31)@@ -280,6 +281,13 @@ static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask)return !!(master->enabled_events & mask); } +static inline bool svc_i3c_master_tx_empty (struct svc_i3c_master *master) +{ +u32 reg =readl (master->regs +SVC_I3C_MDATACTRL ); + +return (SVC_I3C_MDATACTRL_TXCOUNT (reg) ==0 ); +} +static bool svc_i3c_master_error (struct svc_i3c_master *master) {u32 mstatus, merrwarn;drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_xfer(struct svc_i3c_master *master, · line 1317
Quoted 8 lines
drivers/i3c/master/svc-i3c-master.c +2
-1@@ -1303,7 +1311,8 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,* The only way to work around this hardware issue is to let the * FIFO start filling as soon as possible after EmitStartAddr. */ -if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len) { +if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len && +svc_i3c_master_tx_empty (master)) {u32 end = xfer_len >SVC_I3C_FIFO_SIZE ?0 :SVC_I3C_MWDATAB_END ;u32 len =min_t (u32, xfer_len,SVC_I3C_FIFO_SIZE );if prefill to FIFO SIZE each time, such as
Quoted 6 lines
Quoted 4 lines
replace
SVC_I3C_FIFO_SIZEwith
SVC_I3C_FIFO_SIZE-SVC_I3C_MDATACTRL_TXCOUNT(readl(master->regs + SVC_I3C_MDATACTRL)).The free space is
SVC_I3C_FIFO_SIZEwhen FIFO is empty, no need to check TX count again.
My means is that if use above logic, needn't check helper function svc_i3c_master_tx_empty(master).
Does this method work?
Frank
Quoted 14 lines
--
StanleyQuoted 5 lines
Frank
Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c +0
-1--2.34.1
--
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c
Quoted 82 lines · Frank Li
Quoted 13 lines · Stanley Chu
Hi Frank,
Quoted 10 lines · Frank Li
Quoted 6 lines · Stanley Chu
From: Stanley Chu <[email protected]>
Prefilling in private write transfers is only necessary when the FIFO is empty. Otherwise, if the transfer is NACKed due to IBIWON and retries continue, data may be prefilled again but could be lost because the FIFO is not empty.
why "maybe prefilled", please use certain words.
Quoted 9 lines
The original code didn't consider the retry case, data lost happen in the retry case only when total write bytes is larger than FIFO size, not always happen.
In the example of writing 17 bytes (FIFO size is 16), the last byte is lost.
1. Emit S+Addr/W
2. Write 16 bytes to FIFO (FIFO is full)
3. NACKed due to IBIWON
4. (retry) Emit Sr+Addr/W
5. Write last byte to FIFO (data lost)You need descript clearly at commit message about this.
Quoted 55 lines
I just need to prefill FIFO in the beginning to make sure FIFO is not empty when HW starts transmitting.
So, this patch adds a condition that prefill FIFO only when FIFO is empty.Quoted 50 lines
Quoted 35 lines
Fixes 4008a74e0f9b ("i3c: master: svc: Fix npcm845 FIFO empty issue")Signed-off-by Stanley Chu <[email protected]>--- drivers/i3c/master/svc-i3c-master.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)drivers/i3c/master/svc-i3c-master.c +8
-0@@ -104,6 +104,7 @@#define SVC_I3C_MDATACTRL_TXTRIG_FIFO_NOT_FULL GENMASK(5, 4)#define SVC_I3C_MDATACTRL_RXTRIG_FIFO_NOT_EMPTY 0#define SVC_I3C_MDATACTRL_RXCOUNT (x) FIELD_GET(GENMASK(28, 24), (x)) +#define SVC_I3C_MDATACTRL_TXCOUNT (x) FIELD_GET(GENMASK(20, 16), (x))#define SVC_I3C_MDATACTRL_TXFULL BIT(30)#define SVC_I3C_MDATACTRL_RXEMPTY BIT(31)@@ -280,6 +281,13 @@ static inline bool is_events_enabled(struct svc_i3c_master *master, u32 mask)return !!(master->enabled_events & mask); } +static inline bool svc_i3c_master_tx_empty (struct svc_i3c_master *master) +{ +u32 reg =readl (master->regs +SVC_I3C_MDATACTRL ); + +return (SVC_I3C_MDATACTRL_TXCOUNT (reg) ==0 ); +} +static bool svc_i3c_master_error (struct svc_i3c_master *master) {u32 mstatus, merrwarn;drivers/i3c/master/svc-i3c-master.c static int svc_i3c_master_xfer(struct svc_i3c_master *master, · line 1317
Quoted 8 lines
drivers/i3c/master/svc-i3c-master.c +2
-1@@ -1303,7 +1311,8 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,* The only way to work around this hardware issue is to let the * FIFO start filling as soon as possible after EmitStartAddr. */ -if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len) { +if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len && +svc_i3c_master_tx_empty (master)) {u32 end = xfer_len >SVC_I3C_FIFO_SIZE ?0 :SVC_I3C_MWDATAB_END ;u32 len =min_t (u32, xfer_len,SVC_I3C_FIFO_SIZE );if prefill to FIFO SIZE each time, such as
replace
SVC_I3C_FIFO_SIZEwith
SVC_I3C_FIFO_SIZE-SVC_I3C_MDATACTRL_TXCOUNT(readl(master->regs + SVC_I3C_MDATACTRL)).
Quoted 8 lines
Quoted 2 lines
The free space is
SVC_I3C_FIFO_SIZEwhen FIFO is empty, no need to check TX count again.My means is that if use above logic, needn't check helper function
svc_i3c_master_tx_empty(master).Does this method work?
Thanks Frank,
This method is another option that also can work for this issue. I will submit version 2.
Quoted 16 lines
Frank
Quoted 14 lines
--
StanleyQuoted 5 lines
Frank
Quoted 4 lines
drivers/i3c/master/svc-i3c-master.c +0
-1--2.34.1
--
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c