Skip to contentSkip to conversation

hw/net/imx_fec: write TGSR and TCSR3 in imx_enet_write()

PATCH Superseded Chen Qun 2 participants 3 messages Mar 13, 2020 Arm i.MX and Layerscape

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Chen Qun

author
#0 lore raw

PATCH v3 1/1 hw/net/imx_fec: write TGSR and TCSR3 in imx_enet_write()

The current code causes clang static code analyzer generate warning:
hw/net/imx_fec.c:858:9: warning: Value stored to 'value' is never read

        value = value & 0x0000000f;
        ^       ~~~~~~~~~~~~~~~~~~
hw/net/imx_fec.c:864:9: warning: Value stored to 'value' is never read
        value = value & 0x000000fd;
        ^       ~~~~~~~~~~~~~~~~~~

According to the definition of the function, the two “value” assignments
should be written to registers.

---
Cc: Peter Maydell <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: Peter Chubb <[email protected]>

v1->v2:
The register 'ENET_TGSR' write-1-to-clear timer flag. The register 'ENET_TCSRn' 7bit(TF) write-1-to-clear timer flag.

v2->v3:
Optimize code style, based on discussions with Peter.

---
 hw/net/imx_fec.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/net/imx_fec.c +6 -3
index 6a124a154a..3547975710 100644
@@ -854,14 +854,17 @@ static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value)
         s->regs[index] = value & 0x00007f7f;
         break;
     case ENET_TGSR:
-        /* implement clear timer flag */
-        value = value & 0x0000000f;
+        /* implement clear timer flag, 0-3 bits W1C, reserved bits write zero */
+        s->regs[index] &= ~(value & 0x0000000f) & 0x0000000f;
         break;
     case ENET_TCSR0:
     case ENET_TCSR1:
     case ENET_TCSR2:
     case ENET_TCSR3:
-        value = value & 0x000000fd;
+        /* 7 bits W1C, reserved bits write zero */
+        s->regs[index] &= ~(value & 0x00000080) & 0x000000ff;
+        s->regs[index] &= ~0x0000007d; /* writable fields */
+        s->regs[index] |= (value & 0x0000007d);
         break;
     case ENET_TCCR0:
     case ENET_TCCR1:
Signature · 1 line
2.23.0
#1 lore raw
Quoted 34 lines · Chen Qun

The current code causes clang static code analyzer generate warning:
hw/net/imx_fec.c:858:9: warning: Value stored to 'value' is never read

        value = value & 0x0000000f;
        ^       ~~~~~~~~~~~~~~~~~~
hw/net/imx_fec.c:864:9: warning: Value stored to 'value' is never read
        value = value & 0x000000fd;
        ^       ~~~~~~~~~~~~~~~~~~

According to the definition of the function, the two “value” assignments
should be written to registers.

---
Cc: Peter Maydell <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: Peter Chubb <[email protected]>

v1->v2:
The register 'ENET_TGSR' write-1-to-clear timer flag. The register 'ENET_TCSRn' 7bit(TF) write-1-to-clear timer flag.

v2->v3:
Optimize code style, based on discussions with Peter.

---
 hw/net/imx_fec.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/net/imx_fec.c +0 -0
index 6a124a154a..3547975710 100644

hw/net/imx_fec.c static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value) · line 858

Quoted 7 lines
hw/net/imx_fec.c +2 -2
@@ -854,14 +854,17 @@ static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value)
         s->regs[index] = value & 0x00007f7f;
         break;
     case ENET_TGSR:
-        /* implement clear timer flag */
-        value = value & 0x0000000f;
+        /* implement clear timer flag, 0-3 bits W1C, reserved bits write zero */
+        s->regs[index] &= ~(value & 0x0000000f) & 0x0000000f;

I think I must have misunderstood what you were suggesting in your previous question.
The final & with 0x0000000f here is unnecessary, because those bits are always 0 in s->regs[index] anyway.

hw/net/imx_fec.c static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value) · line 865

Quoted 8 lines
hw/net/imx_fec.c +2 -1
         break;
     case ENET_TCSR0:
     case ENET_TCSR1:
     case ENET_TCSR2:
     case ENET_TCSR3:
-        value = value & 0x000000fd;
+        /* 7 bits W1C, reserved bits write zero */
+        s->regs[index] &= ~(value & 0x00000080) & 0x000000ff;

Similarly here.

hw/net/imx_fec.c static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value) · line 870

Quoted 5 lines
hw/net/imx_fec.c +2 -0
+        s->regs[index] &= ~0x0000007d; /* writable fields */
+        s->regs[index] |= (value & 0x0000007d);
         break;
     case ENET_TCCR0:
     case ENET_TCCR1:

Short answer: my recommendation is to use the expressions I recommended that you use...

thanks
-- PMM

#2 lore raw
Quoted 71 lines

-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Friday, March 13, 2020 7:31 PM
To: Chenqun (kuhn) <[email protected]>
Cc: QEMU Developers <[email protected]>; QEMU Trivial <qemu- [email protected]>; Zhanghailiang <[email protected]>; Euler Robot <[email protected]>; Jason Wang <[email protected]>; Peter Chubb <[email protected]>
Subject: Re: [PATCH v3] hw/net/imx_fec: write TGSR and TCSR3 in imx_enet_write()

hw/net/imx_fec.c static void imx_enet_write(IMXFECState *s,

Quoted 34 lines · Chen Qun

The current code causes clang static code analyzer generate warning:
hw/net/imx_fec.c:858:9: warning: Value stored to 'value' is never read

        value = value & 0x0000000f;
        ^       ~~~~~~~~~~~~~~~~~~
hw/net/imx_fec.c:864:9: warning: Value stored to 'value' is never read
        value = value & 0x000000fd;
        ^       ~~~~~~~~~~~~~~~~~~

According to the definition of the function, the two “value” assignments should be written to registers.

---
Cc: Peter Maydell <[email protected]>
Cc: Jason Wang <[email protected]>
Cc: Peter Chubb <[email protected]>

v1->v2:
The register 'ENET_TGSR' write-1-to-clear timer flag. The register 'ENET_TCSRn' 7bit(TF) write-1-to-clear timer flag.

v2->v3:
Optimize code style, based on discussions with Peter.

---
 hw/net/imx_fec.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/net/imx_fec.c index renamed from hw/net/imx_fec.c +0 -0

6a124a154a..3547975710 100644

hw/net/imx_fec.c +0 -0
@@ -854,14 +854,17 @@ static void imx_enet_write(IMXFECState *s,

uint32_t index, uint32_t value)

hw/net/imx_fec.c static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value) · line 858

Quoted 7 lines
hw/net/imx_fec.c +2 -2
         s->regs[index] = value & 0x00007f7f;
         break;
     case ENET_TGSR:
-        /* implement clear timer flag */
-        value = value & 0x0000000f;
+        /* implement clear timer flag, 0-3 bits W1C, reserved bits write zero */
+        s->regs[index] &= ~(value & 0x0000000f) & 0x0000000f;

I think I must have misunderstood what you were suggesting in your previous question.
The final & with 0x0000000f here is unnecessary, because those bits are always 0 in s->regs[index] anyway.

hw/net/imx_fec.c static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value) · line 865

Quoted 8 lines
hw/net/imx_fec.c +2 -1
         break;
     case ENET_TCSR0:
     case ENET_TCSR1:
     case ENET_TCSR2:
     case ENET_TCSR3:
-        value = value & 0x000000fd;
+        /* 7 bits W1C, reserved bits write zero */
+        s->regs[index] &= ~(value & 0x00000080) & 0x000000ff;

Similarly here.

Quoted 8 lines

hw/net/imx_fec.c static void imx_enet_write(IMXFECState *s, uint32_t index, uint32_t value) · line 870

Quoted 5 lines
hw/net/imx_fec.c +2 -0
+        s->regs[index] &= ~0x0000007d; /* writable fields */
+        s->regs[index] |= (value & 0x0000007d);
         break;
     case ENET_TCCR0:
     case ENET_TCCR1:

Short answer: my recommendation is to use the expressions I recommended that you use...

All right, I change it later.

Thanks.