hw/net: npcm7xx_emc fix missing queue_flush
PATCH 1/1 hw/net: npcm7xx_emc fix missing queue_flush
The rx_active boolean change to true should always trigger a try_read call that flushes the queue.
--- hw/net/npcm7xx_emc.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
hw/net/npcm7xx_emc.c +2 -8
@@ -581,13 +581,6 @@ static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1)return len; } -static void emc_try_receive_next_packet (NPCM7xxEMCState *emc) -{ -if (emc_can_receive (qemu_get_queue (emc->nic))) { -qemu_flush_queued_packets (qemu_get_queue (emc->nic)); - } -} -static uint64_t npcm7xx_emc_read (void *opaque,hwaddr offset,unsigned size) {NPCM7xxEMCState *emc = opaque;
@@ -704,6 +697,7 @@ static void npcm7xx_emc_write(void *opaque, hwaddr offset, }if (value ®_MCMDR_RXON ) { emc->rx_active = true; +qemu_flush_queued_packets (qemu_get_queue (emc->nic)); }else {emc_halt_rx (emc,0 ); }
@@ -740,7 +734,7 @@ static void npcm7xx_emc_write(void *opaque, hwaddr offset,case REG_RSDR :if (emc->regs[REG_MCMDR ] ®_MCMDR_RXON ) { emc->rx_active = true; -emc_try_receive_next_packet (emc); +qemu_flush_queued_packets (qemu_get_queue (emc->nic)); }break ;case REG_MIIDA :
Signature · 1 line
2.34.1.400.ga245620fadb-goog
Quoted 13 lines · Patrick Venture
The
rx_activeboolean change to true should always trigger atry_readcall that flushes the queue.Signed-off-by Patrick Venture <[email protected]>--- hw/net/npcm7xx_emc.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)hw/net/npcm7xx_emc.c +0
-0
hw/net/npcm7xx_emc.c static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1) · line 589
Quoted 9 lines
hw/net/npcm7xx_emc.c +0
-6@@ -581,13 +581,6 @@ static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1)return len; } -static void emc_try_receive_next_packet (NPCM7xxEMCState *emc) -{ -if (emc_can_receive (qemu_get_queue (emc->nic))) { -qemu_flush_queued_packets (qemu_get_queue (emc->nic)); - } -}
What about modifying as emc_flush_rx() or emc_receive_and_flush() helper instead?
static void emc_flush_rx(NPCM7xxEMCState *emc)
{
emc->rx_active = true;
qemu_flush_queued_packets(qemu_get_queue(emc->nic));}
Quoted 21 lines
hw/net/npcm7xx_emc.c +2
-1static uint64_t npcm7xx_emc_read (void *opaque,hwaddr offset,unsigned size) {NPCM7xxEMCState *emc = opaque;@@ -704,6 +697,7 @@ static void npcm7xx_emc_write(void *opaque, hwaddr offset, }if (value ®_MCMDR_RXON ) { emc->rx_active = true; +qemu_flush_queued_packets (qemu_get_queue (emc->nic)); }else {emc_halt_rx (emc,0 ); }@@ -740,7 +734,7 @@ static void npcm7xx_emc_write(void *opaque, hwaddr offset,case REG_RSDR :if (emc->regs[REG_MCMDR ] ®_MCMDR_RXON ) { emc->rx_active = true; -emc_try_receive_next_packet (emc); +qemu_flush_queued_packets (qemu_get_queue (emc->nic)); }break ;case REG_MIIDA :
Quoted 28 lines · Philippe Mathieu-Daudé
hw/net/npcm7xx_emc.c static ssize_t emc_receive(NetClientState *nc,
Quoted 13 lines · Patrick Venture
The
rx_activeboolean change to true should always trigger atry_readcall that flushes the queue.Signed-off-by Patrick Venture <[email protected]>--- hw/net/npcm7xx_emc.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)hw/net/npcm7xx_emc.c +0
-0@@ -581,13 +581,6 @@ static ssize_t emc_receive(NetClientState *nc,const
uint8_t*buf,size_tlen1)hw/net/npcm7xx_emc.c static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1) · line 589
Quoted 9 lines
hw/net/npcm7xx_emc.c +0
-6return len; } -static void emc_try_receive_next_packet (NPCM7xxEMCState *emc) -{ -if (emc_can_receive (qemu_get_queue (emc->nic))) { -qemu_flush_queued_packets (qemu_get_queue (emc->nic)); - } -}What about modifying as
emc_flush_rx()oremc_receive_and_flush()helper instead?
Quoted 6 lines
static void
emc_flush_rx(NPCM7xxEMCState *emc){ emc->rx_active = true; qemu_flush_queued_packets(qemu_get_queue(emc->nic));}
I'm ok with that idea, although I'm less fond that it _hides_ the rx_active=true. There is an emc_halt_rx that hides rx_active=false, so one could argue it's not an issue. Looking at ftgmac100, it mostly just calls the qemu_flush_queued_packets inline where it needs it. So given the prior art, I'm more inclined to leave this as a two-line pair, versus collapsing it into a method. Mostly because I don't anticipate this call being made from any other places, so it's not a "growing" device. The method originally was emc_try_receive_next_packet, which didn't do anything more than a no-op check and the queue_flush. The new method would move the rx_active setting from the call that deliberately controls it (the register change) into a subordinate method...
Beyond all that, I think it's fine either way. Feel free to push back and I'll make the change.
Quoted 27 lines
hw/net/npcm7xx_emc.c static ssize_t emc_receive(NetClientState *nc, · line 584
Quoted 2 lines
hw/net/npcm7xx_emc.c +0
-0static uint64_t npcm7xx_emc_read(void *opaque, hwaddr offset, unsignedsize)
hw/net/npcm7xx_emc.c static void npcm7xx_emc_write(void *opaque, hwaddr
Quoted 3 lines
hw/net/npcm7xx_emc.c +0
-0{NPCM7xxEMCState *emc = opaque;@@ -704,6 +697,7 @@ static void npcm7xx_emc_write(void *opaque, hwaddroffset,
hw/net/npcm7xx_emc.c static void npcm7xx_emc_write(void *opaque, hwaddr
Quoted 8 lines
hw/net/npcm7xx_emc.c +1
-0}if (value ®_MCMDR_RXON ) { emc->rx_active = true; +qemu_flush_queued_packets (qemu_get_queue (emc->nic)); }else {emc_halt_rx (emc,0 ); }@@ -740,7 +734,7 @@ static void npcm7xx_emc_write(void *opaque, hwaddroffset,
Quoted 9 lines
hw/net/npcm7xx_emc.c +1
-1case REG_RSDR :if (emc->regs[REG_MCMDR ] ®_MCMDR_RXON ) { emc->rx_active = true; -emc_try_receive_next_packet (emc); +qemu_flush_queued_packets (qemu_get_queue (emc->nic)); }break ;case REG_MIIDA :
Quoted 52 lines · Patrick Venture
Quoted 28 lines · Philippe Mathieu-Daudé
hw/net/npcm7xx_emc.c static ssize_t emc_receive(NetClientState *nc,
Quoted 13 lines · Patrick Venture
The
rx_activeboolean change to true should always trigger atry_readcall that flushes the queue.Signed-off-by Patrick Venture <[email protected]>--- hw/net/npcm7xx_emc.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)hw/net/npcm7xx_emc.c +0
-0@@ -581,13 +581,6 @@ static ssize_t emc_receive(NetClientState *nc,const
uint8_t*buf,size_tlen1)hw/net/npcm7xx_emc.c static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1) · line 589
Quoted 9 lines
hw/net/npcm7xx_emc.c +0
-6return len; } -static void emc_try_receive_next_packet (NPCM7xxEMCState *emc) -{ -if (emc_can_receive (qemu_get_queue (emc->nic))) { -qemu_flush_queued_packets (qemu_get_queue (emc->nic)); - } -}What about modifying as
emc_flush_rx()oremc_receive_and_flush()helper instead?Quoted 6 lines
static void
emc_flush_rx(NPCM7xxEMCState *emc){ emc->rx_active = true; qemu_flush_queued_packets(qemu_get_queue(emc->nic));}
I'm ok with that idea, although I'm less fond that it _hides_ the rx_active=true. There is an
emc_halt_rxthat hides rx_active=false, so one could argue it's not an issue. Looking at ftgmac100, it mostly just calls theqemu_flush_queued_packetsinline where it needs it. So given the prior art, I'm more inclined to leave this as a two-line pair, versus collapsing it into a method. Mostly because I don't anticipate this call being made from any other places, so it's not a "growing" device. The method originally wasemc_try_receive_next_packet, which didn't do anything more than a no-op check and thequeue_flush. The new method would move therx_activesetting from the call that deliberately controls it (the register change) into a subordinate method...
Quoted 3 lines
Beyond all that, I think it's fine either way. Feel free to push back and I'll make the change.
I figured why not :) And just made the change and sent out a v2.
Quoted 27 lines
Quoted 27 lines
hw/net/npcm7xx_emc.c static ssize_t emc_receive(NetClientState *nc, · line 584
Quoted 2 lines
hw/net/npcm7xx_emc.c +0
-0static uint64_t npcm7xx_emc_read(void *opaque, hwaddr offset, unsignedsize)
hw/net/npcm7xx_emc.c static void npcm7xx_emc_write(void *opaque, hwaddr
Quoted 3 lines
hw/net/npcm7xx_emc.c +0
-0{NPCM7xxEMCState *emc = opaque;@@ -704,6 +697,7 @@ static void npcm7xx_emc_write(void *opaque, hwaddroffset,
hw/net/npcm7xx_emc.c static void npcm7xx_emc_write(void *opaque, hwaddr
Quoted 8 lines
hw/net/npcm7xx_emc.c +1
-0}if (value ®_MCMDR_RXON ) { emc->rx_active = true; +qemu_flush_queued_packets (qemu_get_queue (emc->nic)); }else {emc_halt_rx (emc,0 ); }@@ -740,7 +734,7 @@ static void npcm7xx_emc_write(void *opaque, hwaddroffset,
Quoted 9 lines
hw/net/npcm7xx_emc.c +1
-1case REG_RSDR :if (emc->regs[REG_MCMDR ] ®_MCMDR_RXON ) { emc->rx_active = true; -emc_try_receive_next_packet (emc); +qemu_flush_queued_packets (qemu_get_queue (emc->nic)); }break ;case REG_MIIDA :