hw/net: Make Net/CanBus can_receive() handlers return a boolean
Subsystems (5)
cover hw/net: Make Net/CanBus can_receive() handlers return a boolean
The Net/CanBus can_receive() handlers return whether the network device can or can not receive new data. Make it obvious by returning a boolean type
Philippe Mathieu-Daudé (6):
hw/net/e1000e_core: Let e1000e_can_receive() return a boolean hw/net/smc91c111: Let smc91c111_can_receive() return a boolean hw/net/rtl8139: Simplify if/else statement hw/net/rtl8139: Update coding style to make checkpatch.pl happy hw/net: Make NetCanReceive() return a boolean hw/net/can: Make CanBusClientInfo::can_receive() return a boolean
hw/net/can/can_sja1000.h | 2 +- hw/net/e1000e_core.h | 2 +- hw/net/i82596.h | 2 +- include/net/can_emu.h | 2 +- include/net/net.h | 2 +- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 8 ++++---- hw/net/can/can_sja1000.c | 8 ++++---- hw/net/dp8393x.c | 8 +++----- hw/net/e1000.c | 2 +- hw/net/e1000e.c | 2 +- hw/net/e1000e_core.c | 2 +- hw/net/ftgmac100.c | 6 +++--- hw/net/i82596.c | 10 +++++----- hw/net/imx_fec.c | 2 +- hw/net/opencores_eth.c | 5 ++--- hw/net/rtl8139.c | 22 ++++++++++++---------- hw/net/smc91c111.c | 10 +++++----- hw/net/spapr_llan.c | 4 ++-- hw/net/sungem.c | 6 +++--- hw/net/sunhme.c | 4 ++-- hw/net/virtio-net.c | 10 +++++----- hw/net/xilinx_ethlite.c | 2 +- net/can/can_socketcan.c | 4 ++-- net/filter-buffer.c | 2 +- net/hub.c | 6 +++--- 26 files changed, 67 insertions(+), 68 deletions(-)
Signature · 1 line
2.21.1
PATCH 1/6 hw/net/e1000e_core: Let e1000e_can_receive() return a boolean
The e1000e_can_receive() function simply returns a boolean value.
--- hw/net/e1000e_core.h | 2 +- hw/net/e1000e_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/net/e1000e_core.h +1 -1
@@ -143,7 +143,7 @@ e1000e_core_set_link_status(E1000ECore *core);void e1000e_core_pci_uninit (E1000ECore *core); -int +bool e1000e_can_receive (E1000ECore *core);ssize_t
hw/net/e1000e_core.c +1 -1
@@ -967,7 +967,7 @@ e1000e_start_recv(E1000ECore *core) } } -int +bool e1000e_can_receive (E1000ECore *core) {int i;
Signature · 1 line
2.21.1
Re: [PATCH 1/6] hw/net/e1000e_core: Let e1000e_can_receive() return a boolean
Quoted 4 lines · Philippe Mathieu-Daudé
The
e1000e_can_receive()function simply returns a boolean value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 35 lines
--- hw/net/e1000e_core.h | 2 +- hw/net/e1000e_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/net/e1000e_core.h +1
-1@@ -143,7 +143,7 @@ e1000e_core_set_link_status(E1000ECore *core);void e1000e_core_pci_uninit (E1000ECore *core); -int +bool e1000e_can_receive (E1000ECore *core);ssize_t hw/net/e1000e_core.c +1
-2@@ -967,7 +967,7 @@ e1000e_start_recv(E1000ECore *core) } } -int +bool e1000e_can_receive (E1000ECore *core) {int i; --2.21.1
Re: [PATCH 1/6] hw/net/e1000e_core: Let e1000e_can_receive() return a boolean
In reply to Philippe Mathieu-DaudéQuoted 27 lines · Philippe Mathieu-Daudé
The
e1000e_can_receive()function simply returns a boolean value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/e1000e_core.h | 2 +- hw/net/e1000e_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/net/e1000e_core.h +1
-1@@ -143,7 +143,7 @@ e1000e_core_set_link_status(E1000ECore *core);void e1000e_core_pci_uninit (E1000ECore *core); -int +bool e1000e_can_receive (E1000ECore *core);ssize_t hw/net/e1000e_core.c +0
-0
hw/net/e1000e_core.c e1000e_start_recv(E1000ECore *core) · line 973
Quoted 8 lines
hw/net/e1000e_core.c +1
-1@@ -967,7 +967,7 @@ e1000e_start_recv(E1000ECore *core) } } -int +bool e1000e_can_receive (E1000ECore *core) {int i;
Re: [PATCH 1/6] hw/net/e1000e_core: Let e1000e_can_receive() return a boolean
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
The
e1000e_can_receive()function simply returns a boolean value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 32 lines
--- hw/net/e1000e_core.h | 2 +- hw/net/e1000e_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/net/e1000e_core.h +1
-1@@ -143,7 +143,7 @@ e1000e_core_set_link_status(E1000ECore *core);void e1000e_core_pci_uninit (E1000ECore *core); -int +bool e1000e_can_receive (E1000ECore *core);ssize_t hw/net/e1000e_core.c +1
-1@@ -967,7 +967,7 @@ e1000e_start_recv(E1000ECore *core) } } -int +bool e1000e_can_receive (E1000ECore *core) {int i;
PATCH 2/6 hw/net/smc91c111: Let smc91c111_can_receive() return a boolean
In reply to Philippe Mathieu-DaudéThe smc91c111_can_receive() function simply returns a boolean value.
--- hw/net/smc91c111.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/net/smc91c111.c +4 -4
@@ -130,16 +130,16 @@ static void smc91c111_update(smc91c111_state *s)qemu_set_irq (s->irq, level); } -static int smc91c111_can_receive (smc91c111_state *s) +static bool smc91c111_can_receive (smc91c111_state *s) {if ((s->rcr &RCR_RXEN ) ==0 || (s->rcr &RCR_SOFT_RST )) { -return 1 ; +return true; }if (s->allocated == (1 <<NUM_PACKETS ) -1 || s->rx_fifo_len ==NUM_PACKETS ) { -return 0 ; +return false; } -return 1 ; +return true; }static inline void smc91c111_flush_queued_packets (smc91c111_state *s)
Signature · 1 line
2.21.1
Re: [PATCH 2/6] hw/net/smc91c111: Let smc91c111_can_receive() return a boolean
Quoted 4 lines · Philippe Mathieu-Daudé
The
smc91c111_can_receive()function simply returns a boolean value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 33 lines
--- hw/net/smc91c111.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/net/smc91c111.c +4
-5@@ -130,16 +130,16 @@ static void smc91c111_update(smc91c111_state *s)qemu_set_irq (s->irq, level); } -static int smc91c111_can_receive (smc91c111_state *s) +static bool smc91c111_can_receive (smc91c111_state *s) {if ((s->rcr &RCR_RXEN ) ==0 || (s->rcr &RCR_SOFT_RST )) { -return 1 ; +return true; }if (s->allocated == (1 <<NUM_PACKETS ) -1 || s->rx_fifo_len ==NUM_PACKETS ) { -return 0 ; +return false; } -return 1 ; +return true; }static inline void smc91c111_flush_queued_packets (smc91c111_state *s) --2.21.1
Re: [PATCH 2/6] hw/net/smc91c111: Let smc91c111_can_receive() return a boolean
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
The
smc91c111_can_receive()function simply returns a boolean value.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 30 lines
--- hw/net/smc91c111.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/net/smc91c111.c +4
-4@@ -130,16 +130,16 @@ static void smc91c111_update(smc91c111_state *s)qemu_set_irq (s->irq, level); } -static int smc91c111_can_receive (smc91c111_state *s) +static bool smc91c111_can_receive (smc91c111_state *s) {if ((s->rcr &RCR_RXEN ) ==0 || (s->rcr &RCR_SOFT_RST )) { -return 1 ; +return true; }if (s->allocated == (1 <<NUM_PACKETS ) -1 || s->rx_fifo_len ==NUM_PACKETS ) { -return 0 ; +return false; } -return 1 ; +return true; }static inline void smc91c111_flush_queued_packets (smc91c111_state *s)
PATCH 3/6 hw/net/rtl8139: Simplify if/else statement
In reply to Philippe Mathieu-DaudéRewrite:
if (E) {
return A;
} else {
return B;
}
/* EOF */}
as:
if (E) {
return A;
}
return B;}
--- hw/net/rtl8139.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/net/rtl8139.c +4 -4
@@ -808,11 +808,11 @@ static int rtl8139_can_receive(NetClientState *nc)/* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ return 1 ; - }else { - avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, - s->RxBufferSize); -return (avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow)); } + + avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, + s->RxBufferSize); +return avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow); }static ssize_t rtl8139_do_receive (NetClientState *nc,const uint8_t *buf,size_t size_,int do_interrupt)
Signature · 1 line
2.21.1
Re: [PATCH 3/6] hw/net/rtl8139: Simplify if/else statement
Quoted 13 lines · Philippe Mathieu-Daudé
Rewrite:
if (E) { return A; } else { return B; } /* EOF */}
as:
Quoted 7 lines
if (E) { return A; } return B;}
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 28 lines
--- hw/net/rtl8139.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/net/rtl8139.c +4
-5@@ -808,11 +808,11 @@ static int rtl8139_can_receive(NetClientState *nc)/* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ return 1 ; - }else { - avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, - s->RxBufferSize); -return (avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow)); } + + avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, + s->RxBufferSize); +return avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow); }static ssize_t rtl8139_do_receive (NetClientState *nc,const uint8_t *buf,size_t size_,int do_interrupt) --2.21.1
Re: [PATCH 3/6] hw/net/rtl8139: Simplify if/else statement
In reply to Philippe Mathieu-DaudéQuoted 12 lines · Philippe Mathieu-Daudé
Rewrite:
if (E) { return A; } else { return B; } /* EOF */}
as:
Quoted 7 lines
if (E) { return A; } return B;}
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 25 lines
--- hw/net/rtl8139.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/net/rtl8139.c +4
-4@@ -808,11 +808,11 @@ static int rtl8139_can_receive(NetClientState *nc)/* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ return 1 ; - }else { - avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, - s->RxBufferSize); -return (avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow)); } + + avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, + s->RxBufferSize); +return avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow); }static ssize_t rtl8139_do_receive (NetClientState *nc,const uint8_t *buf,size_t size_,int do_interrupt)
PATCH 4/6 hw/net/rtl8139: Update coding style to make checkpatch.pl happy
In reply to Philippe Mathieu-DaudéWe will modify this code in the next commit. Clean it up first to avoid checkpatch.pl errors.
--- hw/net/rtl8139.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
hw/net/rtl8139.c +6 -4
@@ -799,10 +799,12 @@ static int rtl8139_can_receive(NetClientState *nc)int avail;/* Receive (drop) packets if card is disabled. */ -if (!s->clock_enabled) -return 1 ; -if (!rtl8139_receiver_enabled (s)) -return 1 ; +if (!s->clock_enabled) { +return 1 ; + } +if (!rtl8139_receiver_enabled (s)) { +return 1 ; + }if (rtl8139_cp_receiver_enabled (s) &&rtl8139_cp_rx_valid (s)) {/* ??? Flow control not implemented in c+ mode.
Signature · 1 line
2.21.1
Re: [PATCH 4/6] hw/net/rtl8139: Update coding style to make checkpatch.pl happy
Quoted 5 lines · Philippe Mathieu-Daudé
We will modify this code in the next commit. Clean it up first to avoid checkpatch.pl errors.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 29 lines
--- hw/net/rtl8139.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)hw/net/rtl8139.c +6
-5@@ -799,10 +799,12 @@ static int rtl8139_can_receive(NetClientState *nc)int avail;/* Receive (drop) packets if card is disabled. */ -if (!s->clock_enabled) -return 1 ; -if (!rtl8139_receiver_enabled (s)) -return 1 ; +if (!s->clock_enabled) { +return 1 ; + } +if (!rtl8139_receiver_enabled (s)) { +return 1 ; + }if (rtl8139_cp_receiver_enabled (s) &&rtl8139_cp_rx_valid (s)) {/* ??? Flow control not implemented in c+ mode. -- 2.21.1
Re: [PATCH 4/6] hw/net/rtl8139: Update coding style to make checkpatch.pl happy
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
We will modify this code in the next commit. Clean it up first to avoid checkpatch.pl errors.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 26 lines
--- hw/net/rtl8139.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)hw/net/rtl8139.c +6
-4@@ -799,10 +799,12 @@ static int rtl8139_can_receive(NetClientState *nc)int avail;/* Receive (drop) packets if card is disabled. */ -if (!s->clock_enabled) -return 1 ; -if (!rtl8139_receiver_enabled (s)) -return 1 ; +if (!s->clock_enabled) { +return 1 ; + } +if (!rtl8139_receiver_enabled (s)) { +return 1 ; + }if (rtl8139_cp_receiver_enabled (s) &&rtl8139_cp_rx_valid (s)) {/* ??? Flow control not implemented in c+ mode.
PATCH 5/6 hw/net: Make NetCanReceive() return a boolean
In reply to Philippe Mathieu-DaudéThe NetCanReceive handler return whether the device can or can not receive new packets. Make it obvious by returning a boolean type.
--- hw/net/i82596.h | 2 +- include/net/net.h | 2 +- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 8 ++++---- hw/net/dp8393x.c | 8 +++----- hw/net/e1000.c | 2 +- hw/net/e1000e.c | 2 +- hw/net/ftgmac100.c | 6 +++--- hw/net/i82596.c | 10 +++++----- hw/net/imx_fec.c | 2 +- hw/net/opencores_eth.c | 5 ++--- hw/net/rtl8139.c | 8 ++++---- hw/net/smc91c111.c | 2 +- hw/net/spapr_llan.c | 4 ++-- hw/net/sungem.c | 6 +++--- hw/net/sunhme.c | 4 ++-- hw/net/virtio-net.c | 10 +++++----- hw/net/xilinx_ethlite.c | 2 +- net/filter-buffer.c | 2 +- net/hub.c | 6 +++--- 20 files changed, 45 insertions(+), 48 deletions(-)
hw/net/i82596.h +1 -1
@@ -48,7 +48,7 @@ void i82596_ioport_writel(void *opaque, uint32_t addr, uint32_t val);uint32_t i82596_ioport_readl (void *opaque,uint32_t addr);uint32_t i82596_bcr_readw (I82596State *s,uint32_t rap);ssize_t i82596_receive (NetClientState *nc,const uint8_t *buf,size_t size_); -int i82596_can_receive (NetClientState *nc); +bool i82596_can_receive (NetClientState *nc);void i82596_set_link_status (NetClientState *nc);void i82596_common_init (DeviceState *dev,I82596State *s,NetClientInfo *info);extern const VMStateDescription vmstate_i82596;
include/net/net.h +1 -1
@@ -42,7 +42,7 @@ typedef struct NICConf {/* Net clients */ typedef void (NetPoll )(NetClientState *,bool enable); -typedef int (NetCanReceive )(NetClientState *); +typedef bool (NetCanReceive )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int );typedef void (NetCleanup ) (NetClientState *);
hw/net/allwinner_emac.c +1 -1
@@ -178,13 +178,13 @@ static uint32_t fifo8_pop_word(Fifo8 *fifo)return ret; } -static int aw_emac_can_receive (NetClientState *nc) +static bool aw_emac_can_receive (NetClientState *nc) {AwEmacState *s =qemu_get_nic_opaque (nc);/* * To avoid packet drops, allow reception only when there is space * for a full frame: 1522 + 8 (rx headers) + 2 (padding). */ return (s->ctl &EMAC_CTL_RX_EN ) && (fifo8_num_free (&s->rx_fifo) >=1532 ); }
hw/net/cadence_gem.c +4 -4
@@ -505,44 +505,44 @@ static void phy_update_link(CadenceGEMState *s) } } -static int gem_can_receive (NetClientState *nc) +static bool gem_can_receive (NetClientState *nc) {CadenceGEMState *s;int i; s =qemu_get_nic_opaque (nc);/* Do nothing if receive is not enabled. */ if (!(s->regs[GEM_NWCTRL ] &GEM_NWCTRL_RXENA )) {if (s->can_rx_state !=1 ) { s->can_rx_state =1 ;DB_PRINT ("can't receive - no enable\n" ); } -return 0 ; +return false; }for (i =0 ; i < s->num_priority_queues; i++) {if (rx_desc_get_ownership (s->rx_desc[i]) !=1 ) {break ; } };if (i == s->num_priority_queues) {if (s->can_rx_state !=2 ) { s->can_rx_state =2 ;DB_PRINT ("can't receive - all the buffer descriptors are busy\n" ); } -return 0 ; +return false; }if (s->can_rx_state !=0 ) { s->can_rx_state =0 ;DB_PRINT ("can receive\n" ); } -return 1 ; +return true; }/* * gem_update_int_status: * Raise or lower interrupt based on current status. */
hw/net/dp8393x.c +3 -5
@@ -414,7 +414,7 @@ static void dp8393x_do_stop_timer(dp8393xState *s)dp8393x_update_wt_regs (s); } -static int dp8393x_can_receive (NetClientState *nc); +static bool dp8393x_can_receive (NetClientState *nc);static void dp8393x_do_receiver_enable (dp8393xState *s) {
@@ -718,13 +718,11 @@ static void dp8393x_watchdog(void *opaque)dp8393x_update_irq (s); } -static int dp8393x_can_receive (NetClientState *nc) +static bool dp8393x_can_receive (NetClientState *nc) {dp8393xState *s =qemu_get_nic_opaque (nc); -if (!(s->regs[SONIC_CR ] &SONIC_CR_RXEN )) -return 0 ; -return 1 ; +return !!(s->regs[SONIC_CR ] &SONIC_CR_RXEN ); } static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf,
hw/net/e1000.c +1 -1
@@ -845,7 +845,7 @@ static bool e1000_has_rxbufs(E1000State *s, size_t total_size)return total_size <= bufs * s->rxbuf_size; } -static int +static bool e1000_can_receive (NetClientState *nc) {E1000State *s =qemu_get_nic_opaque (nc);
hw/net/e1000e.c +1 -1
@@ -199,7 +199,7 @@ static const MemoryRegionOps io_ops = { }, }; -static int +static bool e1000e_nc_can_receive (NetClientState *nc) {E1000EState *s =qemu_get_nic_opaque (nc);
hw/net/ftgmac100.c +3 -3
@@ -562,24 +562,24 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,ftgmac100_update_irq (s); } -static int ftgmac100_can_receive (NetClientState *nc) +static bool ftgmac100_can_receive (NetClientState *nc) {FTGMAC100State *s =FTGMAC100 (qemu_get_nic_opaque (nc));FTGMAC100Desc bd;if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN |FTGMAC100_MACCR_RXMAC_EN )) != (FTGMAC100_MACCR_RXDMA_EN |FTGMAC100_MACCR_RXMAC_EN )) { -return 0 ; +return false; }if (ftgmac100_read_bd (&bd, s->rx_descriptor)) { -return 0 ; +return false; }return !(bd.des0 &FTGMAC100_RXDES0_RXPKT_RDY ); }/* * This is purely informative. The HW can poll the RW (and RX) ring * buffers for available descriptors but we don't need to trigger a * timer for that in qemu. */
hw/net/i82596.c +5 -5
@@ -474,23 +474,23 @@ void i82596_h_reset(void *opaque)i82596_s_reset (s); } -int i82596_can_receive (NetClientState *nc) +bool i82596_can_receive (NetClientState *nc) {I82596State *s =qemu_get_nic_opaque (nc);if (s->rx_status ==RX_SUSPENDED ) { -return 0 ; +return false; }if (!s->lnkst) { -return 0 ; +return false; }if (USE_TIMER && !timer_pending (s->flush_queue_timer)) { -return 1 ; +return true; } -return 1 ; +return true; }#define MIN_BUF_SIZE 60
hw/net/imx_fec.c +1 -1
@@ -1047,11 +1047,11 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,imx_eth_update (s); } -static int imx_eth_can_receive (NetClientState *nc) +static bool imx_eth_can_receive (NetClientState *nc) {IMXFECState *s =IMX_FEC (qemu_get_nic_opaque (nc));FEC_PRINTF ("\n" );return !!s->regs[ENET_RDAR ]; }
hw/net/opencores_eth.c +2 -3
@@ -349,12 +349,11 @@ static void open_eth_reset(void *opaque)open_eth_set_link_status (qemu_get_queue (s->nic)); } -static int open_eth_can_receive (NetClientState *nc) +static bool open_eth_can_receive (NetClientState *nc) {OpenEthState *s =qemu_get_nic_opaque (nc); -return GET_REGBIT (s,MODER ,RXEN ) && - (s->regs[TX_BD_NUM ] <0x80 ); +return GET_REGBIT (s,MODER ,RXEN ) && (s->regs[TX_BD_NUM ] <0x80 ); } static ssize_t open_eth_receive(NetClientState *nc,
hw/net/rtl8139.c +4 -4
@@ -793,26 +793,26 @@ static bool rtl8139_cp_rx_valid(RTL8139State *s)return !(s->RxRingAddrLO ==0 && s->RxRingAddrHI ==0 ); } -static int rtl8139_can_receive (NetClientState *nc) +static bool rtl8139_can_receive (NetClientState *nc) {RTL8139State *s =qemu_get_nic_opaque (nc);int avail;/* Receive (drop) packets if card is disabled. */ if (!s->clock_enabled) { -return 1 ; +return true; }if (!rtl8139_receiver_enabled (s)) { -return 1 ; +return true; }if (rtl8139_cp_receiver_enabled (s) &&rtl8139_cp_rx_valid (s)) {/* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ -return 1 ; +return true; } avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize);return avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow); }
hw/net/smc91c111.c +1 -1
@@ -667,9 +667,9 @@ static void smc91c111_writefn(void *opaque, hwaddr addr, } } -static int smc91c111_can_receive_nc (NetClientState *nc) +static bool smc91c111_can_receive_nc (NetClientState *nc) {smc91c111_state *s =qemu_get_nic_opaque (nc);return smc91c111_can_receive (s); }
hw/net/spapr_llan.c +2 -2
@@ -110,17 +110,17 @@ typedef struct SpaprVioVlan {RxBufPool *rx_pool[RX_MAX_POOLS ];/* Receive buffer descriptor pools */ } SpaprVioVlan; -static int spapr_vlan_can_receive (NetClientState *nc) +static bool spapr_vlan_can_receive (NetClientState *nc) {SpaprVioVlan *dev =qemu_get_nic_opaque (nc); -return (dev->isopen && dev->rx_bufs >0 ); +return dev->isopen && dev->rx_bufs >0 ; }/** * The last 8 bytes of the receive buffer list page (that has been * supplied by the guest with the H_REGISTER_LOGICAL_LAN call) contain * a counter for frames that have been dropped because there was no * suitable receive buffer available. This function is used to increase * this counter by one. */
hw/net/sungem.c +3 -3
@@ -433,31 +433,31 @@ static bool sungem_rx_full(SunGEMState *s, uint32_t kick, uint32_t done)return kick == ((done +1 ) & s->rx_mask); } -static int sungem_can_receive (NetClientState *nc) +static bool sungem_can_receive (NetClientState *nc) {SunGEMState *s =qemu_get_nic_opaque (nc);uint32_t kick, done, rxdma_cfg, rxmac_cfg;bool full; rxmac_cfg = s->macregs[MAC_RXCFG >>2 ]; rxdma_cfg = s->rxdmaregs[RXDMA_CFG >>2 ];/* If MAC disabled, can't receive */ if ((rxmac_cfg &MAC_RXCFG_ENAB ) ==0 ) {trace_sungem_rx_mac_disabled (); -return 0 ; +return false; }if ((rxdma_cfg &RXDMA_CFG_ENABLE ) ==0 ) {trace_sungem_rx_txdma_disabled (); -return 0 ; +return false; }/* Check RX availability */ kick = s->rxdmaregs[RXDMA_KICK >>2 ]; done = s->rxdmaregs[RXDMA_DONE >>2 ]; full =sungem_rx_full (s, kick, done);trace_sungem_rx_check (!full, kick, done);return !full; }
hw/net/sunhme.c +2 -2
@@ -657,11 +657,11 @@ static void sunhme_transmit(SunHMEState *s)sunhme_update_irq (s); } -static int sunhme_can_receive (NetClientState *nc) +static bool sunhme_can_receive (NetClientState *nc) {SunHMEState *s =qemu_get_nic_opaque (nc); -return s->macregs[HME_MACI_RXCFG >>2 ] &HME_MAC_RXCFG_ENABLE ; +return !!(s->macregs[HME_MACI_RXCFG >>2 ] &HME_MAC_RXCFG_ENABLE ); }static void sunhme_link_status_changed (NetClientState *nc)
hw/net/virtio-net.c +5 -5
@@ -1234,26 +1234,26 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)qemu_flush_queued_packets (qemu_get_subqueue (n->nic, queue_index)); } -static int virtio_net_can_receive (NetClientState *nc) +static bool virtio_net_can_receive (NetClientState *nc) {VirtIONet *n =qemu_get_nic_opaque (nc);VirtIODevice *vdev =VIRTIO_DEVICE (n);VirtIONetQueue *q =virtio_net_get_subqueue (nc);if (!vdev->vm_running) { -return 0 ; +return false; }if (nc->queue_index >= n->curr_queues) { -return 0 ; +return false; }if (!virtio_queue_ready (q->rx_vq) || !(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { -return 0 ; +return false; } -return 1 ; +return true; }static int virtio_net_has_buffers (VirtIONetQueue *q,int bufsize)
hw/net/xilinx_ethlite.c +1 -1
@@ -175,10 +175,10 @@ static const MemoryRegionOps eth_ops = { } }; -static int eth_can_rx (NetClientState *nc) +static bool eth_can_rx (NetClientState *nc) {struct xlx_ethlite *s =qemu_get_nic_opaque (nc);unsigned int rxbase = s->rxbuf * (0x800 /4 );return !(s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S ); }
net/filter-buffer.c +1 -1
@@ -59,28 +59,28 @@ static void filter_buffer_release_timer(void *opaque)/* filter APIs */ static ssize_t filter_buffer_receive_iov (NetFilterState *nf,NetClientState *sender,unsigned flags,const struct iovec *iov,int iovcnt,NetPacketSent *sent_cb) {FilterBufferState *s =FILTER_BUFFER (nf);/* * We return size when buffer a packet, the sender will take it as * a already sent packet, so sent_cb should not be called later. * * FIXME: Even if the guest can't receive packets for some reasons, * the filter can still accept packets until its internal queue is full. * For example: * For some reason, receiver could not receive more packets -* (.can_receive() returns zero). Without a filter, at most one packet +* (.can_receive() returns false). Without a filter, at most one packet * will be queued in incoming queue and sender's poll will be disabled * unit its sent_cb() was called. With a filter, it will keep receiving * the packets without caring about the receiver. This is suboptimal. * May need more thoughts (e.g keeping sent_cb). */ qemu_net_queue_append_iov (s->incoming_queue, sender, flags, iov, iovcnt,NULL );return iov_size (iov, iovcnt); }
net/hub.c +3 -3
@@ -90,23 +90,23 @@ static NetHub *net_hub_new(int id)return hub; } -static int net_hub_port_can_receive (NetClientState *nc) +static bool net_hub_port_can_receive (NetClientState *nc) {NetHubPort *port;NetHubPort *src_port =DO_UPCAST (NetHubPort, nc, nc);NetHub *hub = src_port->hub; QLIST_FOREACH(port, &hub->ports, next) {if (port == src_port) {continue ; }if (qemu_can_send_packet (&port->nc)) { -return 1 ; +return true; } } -return 0 ; +return false; } static ssize_t net_hub_port_receive(NetClientState *nc,
Signature · 1 line
2.21.1
Re: [PATCH 5/6] hw/net: Make NetCanReceive() return a boolean
Quoted 6 lines · Philippe Mathieu-Daudé
The NetCanReceive handler return whether the device can or can not receive new packets. Make it obvious by returning a boolean type.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 529 lines
--- hw/net/i82596.h | 2 +- include/net/net.h | 2 +- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 8 ++++---- hw/net/dp8393x.c | 8 +++----- hw/net/e1000.c | 2 +- hw/net/e1000e.c | 2 +- hw/net/ftgmac100.c | 6 +++--- hw/net/i82596.c | 10 +++++----- hw/net/imx_fec.c | 2 +- hw/net/opencores_eth.c | 5 ++--- hw/net/rtl8139.c | 8 ++++---- hw/net/smc91c111.c | 2 +- hw/net/spapr_llan.c | 4 ++-- hw/net/sungem.c | 6 +++--- hw/net/sunhme.c | 4 ++-- hw/net/virtio-net.c | 10 +++++----- hw/net/xilinx_ethlite.c | 2 +- net/filter-buffer.c | 2 +- net/hub.c | 6 +++--- 20 files changed, 45 insertions(+), 48 deletions(-)hw/net/i82596.h +1
-1@@ -48,7 +48,7 @@ void i82596_ioport_writel(void *opaque, uint32_t addr, uint32_t val);uint32_t i82596_ioport_readl (void *opaque,uint32_t addr);uint32_t i82596_bcr_readw (I82596State *s,uint32_t rap);ssize_t i82596_receive (NetClientState *nc,const uint8_t *buf,size_t size_); -int i82596_can_receive (NetClientState *nc); +bool i82596_can_receive (NetClientState *nc);void i82596_set_link_status (NetClientState *nc);void i82596_common_init (DeviceState *dev,I82596State *s,NetClientInfo *info);extern const VMStateDescription vmstate_i82596;include/net/net.h +1
-1@@ -42,7 +42,7 @@ typedef struct NICConf {/* Net clients */ typedef void (NetPoll )(NetClientState *,bool enable); -typedef int (NetCanReceive )(NetClientState *); +typedef bool (NetCanReceive )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int );typedef void (NetCleanup ) (NetClientState *);hw/net/allwinner_emac.c +1
-1@@ -178,13 +178,13 @@ static uint32_t fifo8_pop_word(Fifo8 *fifo)return ret; } -static int aw_emac_can_receive (NetClientState *nc) +static bool aw_emac_can_receive (NetClientState *nc) {AwEmacState *s =qemu_get_nic_opaque (nc);/* * To avoid packet drops, allow reception only when there is space * for a full frame: 1522 + 8 (rx headers) + 2 (padding). */ return (s->ctl &EMAC_CTL_RX_EN ) && (fifo8_num_free (&s->rx_fifo) >=1532 ); }hw/net/cadence_gem.c +4
-4@@ -505,44 +505,44 @@ static void phy_update_link(CadenceGEMState *s) } } -static int gem_can_receive (NetClientState *nc) +static bool gem_can_receive (NetClientState *nc) {CadenceGEMState *s;int i; s =qemu_get_nic_opaque (nc);/* Do nothing if receive is not enabled. */ if (!(s->regs[GEM_NWCTRL ] &GEM_NWCTRL_RXENA )) {if (s->can_rx_state !=1 ) { s->can_rx_state =1 ;DB_PRINT ("can't receive - no enable\n" ); } -return 0 ; +return false; }for (i =0 ; i < s->num_priority_queues; i++) {if (rx_desc_get_ownership (s->rx_desc[i]) !=1 ) {break ; } };if (i == s->num_priority_queues) {if (s->can_rx_state !=2 ) { s->can_rx_state =2 ;DB_PRINT ("can't receive - all the buffer descriptors are busy\n" ); } -return 0 ; +return false; }if (s->can_rx_state !=0 ) { s->can_rx_state =0 ;DB_PRINT ("can receive\n" ); } -return 1 ; +return true; }/* * gem_update_int_status: * Raise or lower interrupt based on current status. */ hw/net/dp8393x.c +3
-5@@ -414,7 +414,7 @@ static void dp8393x_do_stop_timer(dp8393xState *s)dp8393x_update_wt_regs (s); } -static int dp8393x_can_receive (NetClientState *nc); +static bool dp8393x_can_receive (NetClientState *nc);static void dp8393x_do_receiver_enable (dp8393xState *s) {@@ -718,13 +718,11 @@ static void dp8393x_watchdog(void *opaque)dp8393x_update_irq (s); } -static int dp8393x_can_receive (NetClientState *nc) +static bool dp8393x_can_receive (NetClientState *nc) {dp8393xState *s =qemu_get_nic_opaque (nc); -if (!(s->regs[SONIC_CR ] &SONIC_CR_RXEN )) -return 0 ; -return 1 ; +return !!(s->regs[SONIC_CR ] &SONIC_CR_RXEN ); } static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf,hw/net/e1000.c +1
-1@@ -845,7 +845,7 @@ static bool e1000_has_rxbufs(E1000State *s, size_t total_size)return total_size <= bufs * s->rxbuf_size; } -static int +static bool e1000_can_receive (NetClientState *nc) {E1000State *s =qemu_get_nic_opaque (nc);hw/net/e1000e.c +1
-1@@ -199,7 +199,7 @@ static const MemoryRegionOps io_ops = { }, }; -static int +static bool e1000e_nc_can_receive (NetClientState *nc) {E1000EState *s =qemu_get_nic_opaque (nc);hw/net/ftgmac100.c +3
-3@@ -562,24 +562,24 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,ftgmac100_update_irq (s); } -static int ftgmac100_can_receive (NetClientState *nc) +static bool ftgmac100_can_receive (NetClientState *nc) {FTGMAC100State *s =FTGMAC100 (qemu_get_nic_opaque (nc));FTGMAC100Desc bd;if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN |FTGMAC100_MACCR_RXMAC_EN )) != (FTGMAC100_MACCR_RXDMA_EN |FTGMAC100_MACCR_RXMAC_EN )) { -return 0 ; +return false; }if (ftgmac100_read_bd (&bd, s->rx_descriptor)) { -return 0 ; +return false; }return !(bd.des0 &FTGMAC100_RXDES0_RXPKT_RDY ); }/* * This is purely informative. The HW can poll the RW (and RX) ring * buffers for available descriptors but we don't need to trigger a * timer for that in qemu. */ hw/net/i82596.c +5
-5@@ -474,23 +474,23 @@ void i82596_h_reset(void *opaque)i82596_s_reset (s); } -int i82596_can_receive (NetClientState *nc) +bool i82596_can_receive (NetClientState *nc) {I82596State *s =qemu_get_nic_opaque (nc);if (s->rx_status ==RX_SUSPENDED ) { -return 0 ; +return false; }if (!s->lnkst) { -return 0 ; +return false; }if (USE_TIMER && !timer_pending (s->flush_queue_timer)) { -return 1 ; +return true; } -return 1 ; +return true; }#define MIN_BUF_SIZE 60hw/net/imx_fec.c +1
-1@@ -1047,11 +1047,11 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,imx_eth_update (s); } -static int imx_eth_can_receive (NetClientState *nc) +static bool imx_eth_can_receive (NetClientState *nc) {IMXFECState *s =IMX_FEC (qemu_get_nic_opaque (nc));FEC_PRINTF ("\n" );return !!s->regs[ENET_RDAR ]; }hw/net/opencores_eth.c +2
-3@@ -349,12 +349,11 @@ static void open_eth_reset(void *opaque)open_eth_set_link_status (qemu_get_queue (s->nic)); } -static int open_eth_can_receive (NetClientState *nc) +static bool open_eth_can_receive (NetClientState *nc) {OpenEthState *s =qemu_get_nic_opaque (nc); -return GET_REGBIT (s,MODER ,RXEN ) && - (s->regs[TX_BD_NUM ] <0x80 ); +return GET_REGBIT (s,MODER ,RXEN ) && (s->regs[TX_BD_NUM ] <0x80 ); } static ssize_t open_eth_receive(NetClientState *nc,hw/net/rtl8139.c +4
-4@@ -793,26 +793,26 @@ static bool rtl8139_cp_rx_valid(RTL8139State *s)return !(s->RxRingAddrLO ==0 && s->RxRingAddrHI ==0 ); } -static int rtl8139_can_receive (NetClientState *nc) +static bool rtl8139_can_receive (NetClientState *nc) {RTL8139State *s =qemu_get_nic_opaque (nc);int avail;/* Receive (drop) packets if card is disabled. */ if (!s->clock_enabled) { -return 1 ; +return true; }if (!rtl8139_receiver_enabled (s)) { -return 1 ; +return true; }if (rtl8139_cp_receiver_enabled (s) &&rtl8139_cp_rx_valid (s)) {/* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ -return 1 ; +return true; } avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize);return avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow); }hw/net/smc91c111.c +1
-1@@ -667,9 +667,9 @@ static void smc91c111_writefn(void *opaque, hwaddr addr, } } -static int smc91c111_can_receive_nc (NetClientState *nc) +static bool smc91c111_can_receive_nc (NetClientState *nc) {smc91c111_state *s =qemu_get_nic_opaque (nc);return smc91c111_can_receive (s); }hw/net/spapr_llan.c +2
-2@@ -110,17 +110,17 @@ typedef struct SpaprVioVlan {RxBufPool *rx_pool[RX_MAX_POOLS ];/* Receive buffer descriptor pools */ } SpaprVioVlan; -static int spapr_vlan_can_receive (NetClientState *nc) +static bool spapr_vlan_can_receive (NetClientState *nc) {SpaprVioVlan *dev =qemu_get_nic_opaque (nc); -return (dev->isopen && dev->rx_bufs >0 ); +return dev->isopen && dev->rx_bufs >0 ; }/** * The last 8 bytes of the receive buffer list page (that has been * supplied by the guest with the H_REGISTER_LOGICAL_LAN call) contain * a counter for frames that have been dropped because there was no * suitable receive buffer available. This function is used to increase * this counter by one. */ hw/net/sungem.c +3
-3@@ -433,31 +433,31 @@ static bool sungem_rx_full(SunGEMState *s, uint32_t kick, uint32_t done)return kick == ((done +1 ) & s->rx_mask); } -static int sungem_can_receive (NetClientState *nc) +static bool sungem_can_receive (NetClientState *nc) {SunGEMState *s =qemu_get_nic_opaque (nc);uint32_t kick, done, rxdma_cfg, rxmac_cfg;bool full; rxmac_cfg = s->macregs[MAC_RXCFG >>2 ]; rxdma_cfg = s->rxdmaregs[RXDMA_CFG >>2 ];/* If MAC disabled, can't receive */ if ((rxmac_cfg &MAC_RXCFG_ENAB ) ==0 ) {trace_sungem_rx_mac_disabled (); -return 0 ; +return false; }if ((rxdma_cfg &RXDMA_CFG_ENABLE ) ==0 ) {trace_sungem_rx_txdma_disabled (); -return 0 ; +return false; }/* Check RX availability */ kick = s->rxdmaregs[RXDMA_KICK >>2 ]; done = s->rxdmaregs[RXDMA_DONE >>2 ]; full =sungem_rx_full (s, kick, done);trace_sungem_rx_check (!full, kick, done);return !full; }hw/net/sunhme.c +2
-2@@ -657,11 +657,11 @@ static void sunhme_transmit(SunHMEState *s)sunhme_update_irq (s); } -static int sunhme_can_receive (NetClientState *nc) +static bool sunhme_can_receive (NetClientState *nc) {SunHMEState *s =qemu_get_nic_opaque (nc); -return s->macregs[HME_MACI_RXCFG >>2 ] &HME_MAC_RXCFG_ENABLE ; +return !!(s->macregs[HME_MACI_RXCFG >>2 ] &HME_MAC_RXCFG_ENABLE ); }static void sunhme_link_status_changed (NetClientState *nc)hw/net/virtio-net.c +5
-5@@ -1234,26 +1234,26 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)qemu_flush_queued_packets (qemu_get_subqueue (n->nic, queue_index)); } -static int virtio_net_can_receive (NetClientState *nc) +static bool virtio_net_can_receive (NetClientState *nc) {VirtIONet *n =qemu_get_nic_opaque (nc);VirtIODevice *vdev =VIRTIO_DEVICE (n);VirtIONetQueue *q =virtio_net_get_subqueue (nc);if (!vdev->vm_running) { -return 0 ; +return false; }if (nc->queue_index >= n->curr_queues) { -return 0 ; +return false; }if (!virtio_queue_ready (q->rx_vq) || !(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { -return 0 ; +return false; } -return 1 ; +return true; }static int virtio_net_has_buffers (VirtIONetQueue *q,int bufsize)hw/net/xilinx_ethlite.c +1
-1@@ -175,10 +175,10 @@ static const MemoryRegionOps eth_ops = { } }; -static int eth_can_rx (NetClientState *nc) +static bool eth_can_rx (NetClientState *nc) {struct xlx_ethlite *s =qemu_get_nic_opaque (nc);unsigned int rxbase = s->rxbuf * (0x800 /4 );return !(s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S ); }net/filter-buffer.c +1
-1@@ -59,28 +59,28 @@ static void filter_buffer_release_timer(void *opaque)/* filter APIs */ static ssize_t filter_buffer_receive_iov (NetFilterState *nf,NetClientState *sender,unsigned flags,const struct iovec *iov,int iovcnt,NetPacketSent *sent_cb) {FilterBufferState *s =FILTER_BUFFER (nf);/* * We return size when buffer a packet, the sender will take it as * a already sent packet, so sent_cb should not be called later. * * FIXME: Even if the guest can't receive packets for some reasons, * the filter can still accept packets until its internal queue is full. * For example: * For some reason, receiver could not receive more packets -* (.can_receive() returns zero). Without a filter, at most one packet +* (.can_receive() returns false). Without a filter, at most one packet * will be queued in incoming queue and sender's poll will be disabled * unit its sent_cb() was called. With a filter, it will keep receiving * the packets without caring about the receiver. This is suboptimal. * May need more thoughts (e.g keeping sent_cb). */ qemu_net_queue_append_iov (s->incoming_queue, sender, flags, iov, iovcnt,NULL );return iov_size (iov, iovcnt); }net/hub.c +3
-4@@ -90,23 +90,23 @@ static NetHub *net_hub_new(int id)return hub; } -static int net_hub_port_can_receive (NetClientState *nc) +static bool net_hub_port_can_receive (NetClientState *nc) {NetHubPort *port;NetHubPort *src_port =DO_UPCAST (NetHubPort, nc, nc);NetHub *hub = src_port->hub; QLIST_FOREACH(port, &hub->ports, next) {if (port == src_port) {continue ; }if (qemu_can_send_packet (&port->nc)) { -return 1 ; +return true; } } -return 0 ; +return false; } static ssize_t net_hub_port_receive(NetClientState *nc, --2.21.1
Re: [PATCH 5/6] hw/net: Make NetCanReceive() return a boolean
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
The NetCanReceive handler return whether the device can or can not receive new packets. Make it obvious by returning a boolean type.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
ppc parts
Quoted 525 lines
--- hw/net/i82596.h | 2 +- include/net/net.h | 2 +- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 8 ++++---- hw/net/dp8393x.c | 8 +++----- hw/net/e1000.c | 2 +- hw/net/e1000e.c | 2 +- hw/net/ftgmac100.c | 6 +++--- hw/net/i82596.c | 10 +++++----- hw/net/imx_fec.c | 2 +- hw/net/opencores_eth.c | 5 ++--- hw/net/rtl8139.c | 8 ++++---- hw/net/smc91c111.c | 2 +- hw/net/spapr_llan.c | 4 ++-- hw/net/sungem.c | 6 +++--- hw/net/sunhme.c | 4 ++-- hw/net/virtio-net.c | 10 +++++----- hw/net/xilinx_ethlite.c | 2 +- net/filter-buffer.c | 2 +- net/hub.c | 6 +++--- 20 files changed, 45 insertions(+), 48 deletions(-)hw/net/i82596.h +1
-1@@ -48,7 +48,7 @@ void i82596_ioport_writel(void *opaque, uint32_t addr, uint32_t val);uint32_t i82596_ioport_readl (void *opaque,uint32_t addr);uint32_t i82596_bcr_readw (I82596State *s,uint32_t rap);ssize_t i82596_receive (NetClientState *nc,const uint8_t *buf,size_t size_); -int i82596_can_receive (NetClientState *nc); +bool i82596_can_receive (NetClientState *nc);void i82596_set_link_status (NetClientState *nc);void i82596_common_init (DeviceState *dev,I82596State *s,NetClientInfo *info);extern const VMStateDescription vmstate_i82596;include/net/net.h +1
-1@@ -42,7 +42,7 @@ typedef struct NICConf {/* Net clients */ typedef void (NetPoll )(NetClientState *,bool enable); -typedef int (NetCanReceive )(NetClientState *); +typedef bool (NetCanReceive )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int );typedef void (NetCleanup ) (NetClientState *);hw/net/allwinner_emac.c +1
-1@@ -178,13 +178,13 @@ static uint32_t fifo8_pop_word(Fifo8 *fifo)return ret; } -static int aw_emac_can_receive (NetClientState *nc) +static bool aw_emac_can_receive (NetClientState *nc) {AwEmacState *s =qemu_get_nic_opaque (nc);/* * To avoid packet drops, allow reception only when there is space * for a full frame: 1522 + 8 (rx headers) + 2 (padding). */ return (s->ctl &EMAC_CTL_RX_EN ) && (fifo8_num_free (&s->rx_fifo) >=1532 ); }hw/net/cadence_gem.c +4
-4@@ -505,44 +505,44 @@ static void phy_update_link(CadenceGEMState *s) } } -static int gem_can_receive (NetClientState *nc) +static bool gem_can_receive (NetClientState *nc) {CadenceGEMState *s;int i; s =qemu_get_nic_opaque (nc);/* Do nothing if receive is not enabled. */ if (!(s->regs[GEM_NWCTRL ] &GEM_NWCTRL_RXENA )) {if (s->can_rx_state !=1 ) { s->can_rx_state =1 ;DB_PRINT ("can't receive - no enable\n" ); } -return 0 ; +return false; }for (i =0 ; i < s->num_priority_queues; i++) {if (rx_desc_get_ownership (s->rx_desc[i]) !=1 ) {break ; } };if (i == s->num_priority_queues) {if (s->can_rx_state !=2 ) { s->can_rx_state =2 ;DB_PRINT ("can't receive - all the buffer descriptors are busy\n" ); } -return 0 ; +return false; }if (s->can_rx_state !=0 ) { s->can_rx_state =0 ;DB_PRINT ("can receive\n" ); } -return 1 ; +return true; }/* * gem_update_int_status: * Raise or lower interrupt based on current status. */ hw/net/dp8393x.c +3
-5@@ -414,7 +414,7 @@ static void dp8393x_do_stop_timer(dp8393xState *s)dp8393x_update_wt_regs (s); } -static int dp8393x_can_receive (NetClientState *nc); +static bool dp8393x_can_receive (NetClientState *nc);static void dp8393x_do_receiver_enable (dp8393xState *s) {@@ -718,13 +718,11 @@ static void dp8393x_watchdog(void *opaque)dp8393x_update_irq (s); } -static int dp8393x_can_receive (NetClientState *nc) +static bool dp8393x_can_receive (NetClientState *nc) {dp8393xState *s =qemu_get_nic_opaque (nc); -if (!(s->regs[SONIC_CR ] &SONIC_CR_RXEN )) -return 0 ; -return 1 ; +return !!(s->regs[SONIC_CR ] &SONIC_CR_RXEN ); } static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf,hw/net/e1000.c +1
-1@@ -845,7 +845,7 @@ static bool e1000_has_rxbufs(E1000State *s, size_t total_size)return total_size <= bufs * s->rxbuf_size; } -static int +static bool e1000_can_receive (NetClientState *nc) {E1000State *s =qemu_get_nic_opaque (nc);hw/net/e1000e.c +1
-1@@ -199,7 +199,7 @@ static const MemoryRegionOps io_ops = { }, }; -static int +static bool e1000e_nc_can_receive (NetClientState *nc) {E1000EState *s =qemu_get_nic_opaque (nc);hw/net/ftgmac100.c +3
-3@@ -562,24 +562,24 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,ftgmac100_update_irq (s); } -static int ftgmac100_can_receive (NetClientState *nc) +static bool ftgmac100_can_receive (NetClientState *nc) {FTGMAC100State *s =FTGMAC100 (qemu_get_nic_opaque (nc));FTGMAC100Desc bd;if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN |FTGMAC100_MACCR_RXMAC_EN )) != (FTGMAC100_MACCR_RXDMA_EN |FTGMAC100_MACCR_RXMAC_EN )) { -return 0 ; +return false; }if (ftgmac100_read_bd (&bd, s->rx_descriptor)) { -return 0 ; +return false; }return !(bd.des0 &FTGMAC100_RXDES0_RXPKT_RDY ); }/* * This is purely informative. The HW can poll the RW (and RX) ring * buffers for available descriptors but we don't need to trigger a * timer for that in qemu. */ hw/net/i82596.c +5
-5@@ -474,23 +474,23 @@ void i82596_h_reset(void *opaque)i82596_s_reset (s); } -int i82596_can_receive (NetClientState *nc) +bool i82596_can_receive (NetClientState *nc) {I82596State *s =qemu_get_nic_opaque (nc);if (s->rx_status ==RX_SUSPENDED ) { -return 0 ; +return false; }if (!s->lnkst) { -return 0 ; +return false; }if (USE_TIMER && !timer_pending (s->flush_queue_timer)) { -return 1 ; +return true; } -return 1 ; +return true; }#define MIN_BUF_SIZE 60hw/net/imx_fec.c +1
-1@@ -1047,11 +1047,11 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,imx_eth_update (s); } -static int imx_eth_can_receive (NetClientState *nc) +static bool imx_eth_can_receive (NetClientState *nc) {IMXFECState *s =IMX_FEC (qemu_get_nic_opaque (nc));FEC_PRINTF ("\n" );return !!s->regs[ENET_RDAR ]; }hw/net/opencores_eth.c +2
-3@@ -349,12 +349,11 @@ static void open_eth_reset(void *opaque)open_eth_set_link_status (qemu_get_queue (s->nic)); } -static int open_eth_can_receive (NetClientState *nc) +static bool open_eth_can_receive (NetClientState *nc) {OpenEthState *s =qemu_get_nic_opaque (nc); -return GET_REGBIT (s,MODER ,RXEN ) && - (s->regs[TX_BD_NUM ] <0x80 ); +return GET_REGBIT (s,MODER ,RXEN ) && (s->regs[TX_BD_NUM ] <0x80 ); } static ssize_t open_eth_receive(NetClientState *nc,hw/net/rtl8139.c +4
-4@@ -793,26 +793,26 @@ static bool rtl8139_cp_rx_valid(RTL8139State *s)return !(s->RxRingAddrLO ==0 && s->RxRingAddrHI ==0 ); } -static int rtl8139_can_receive (NetClientState *nc) +static bool rtl8139_can_receive (NetClientState *nc) {RTL8139State *s =qemu_get_nic_opaque (nc);int avail;/* Receive (drop) packets if card is disabled. */ if (!s->clock_enabled) { -return 1 ; +return true; }if (!rtl8139_receiver_enabled (s)) { -return 1 ; +return true; }if (rtl8139_cp_receiver_enabled (s) &&rtl8139_cp_rx_valid (s)) {/* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ -return 1 ; +return true; } avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize);return avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow); }hw/net/smc91c111.c +1
-1@@ -667,9 +667,9 @@ static void smc91c111_writefn(void *opaque, hwaddr addr, } } -static int smc91c111_can_receive_nc (NetClientState *nc) +static bool smc91c111_can_receive_nc (NetClientState *nc) {smc91c111_state *s =qemu_get_nic_opaque (nc);return smc91c111_can_receive (s); }hw/net/spapr_llan.c +2
-2@@ -110,17 +110,17 @@ typedef struct SpaprVioVlan {RxBufPool *rx_pool[RX_MAX_POOLS ];/* Receive buffer descriptor pools */ } SpaprVioVlan; -static int spapr_vlan_can_receive (NetClientState *nc) +static bool spapr_vlan_can_receive (NetClientState *nc) {SpaprVioVlan *dev =qemu_get_nic_opaque (nc); -return (dev->isopen && dev->rx_bufs >0 ); +return dev->isopen && dev->rx_bufs >0 ; }/** * The last 8 bytes of the receive buffer list page (that has been * supplied by the guest with the H_REGISTER_LOGICAL_LAN call) contain * a counter for frames that have been dropped because there was no * suitable receive buffer available. This function is used to increase * this counter by one. */ hw/net/sungem.c +3
-3@@ -433,31 +433,31 @@ static bool sungem_rx_full(SunGEMState *s, uint32_t kick, uint32_t done)return kick == ((done +1 ) & s->rx_mask); } -static int sungem_can_receive (NetClientState *nc) +static bool sungem_can_receive (NetClientState *nc) {SunGEMState *s =qemu_get_nic_opaque (nc);uint32_t kick, done, rxdma_cfg, rxmac_cfg;bool full; rxmac_cfg = s->macregs[MAC_RXCFG >>2 ]; rxdma_cfg = s->rxdmaregs[RXDMA_CFG >>2 ];/* If MAC disabled, can't receive */ if ((rxmac_cfg &MAC_RXCFG_ENAB ) ==0 ) {trace_sungem_rx_mac_disabled (); -return 0 ; +return false; }if ((rxdma_cfg &RXDMA_CFG_ENABLE ) ==0 ) {trace_sungem_rx_txdma_disabled (); -return 0 ; +return false; }/* Check RX availability */ kick = s->rxdmaregs[RXDMA_KICK >>2 ]; done = s->rxdmaregs[RXDMA_DONE >>2 ]; full =sungem_rx_full (s, kick, done);trace_sungem_rx_check (!full, kick, done);return !full; }hw/net/sunhme.c +2
-2@@ -657,11 +657,11 @@ static void sunhme_transmit(SunHMEState *s)sunhme_update_irq (s); } -static int sunhme_can_receive (NetClientState *nc) +static bool sunhme_can_receive (NetClientState *nc) {SunHMEState *s =qemu_get_nic_opaque (nc); -return s->macregs[HME_MACI_RXCFG >>2 ] &HME_MAC_RXCFG_ENABLE ; +return !!(s->macregs[HME_MACI_RXCFG >>2 ] &HME_MAC_RXCFG_ENABLE ); }static void sunhme_link_status_changed (NetClientState *nc)hw/net/virtio-net.c +5
-5@@ -1234,26 +1234,26 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)qemu_flush_queued_packets (qemu_get_subqueue (n->nic, queue_index)); } -static int virtio_net_can_receive (NetClientState *nc) +static bool virtio_net_can_receive (NetClientState *nc) {VirtIONet *n =qemu_get_nic_opaque (nc);VirtIODevice *vdev =VIRTIO_DEVICE (n);VirtIONetQueue *q =virtio_net_get_subqueue (nc);if (!vdev->vm_running) { -return 0 ; +return false; }if (nc->queue_index >= n->curr_queues) { -return 0 ; +return false; }if (!virtio_queue_ready (q->rx_vq) || !(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { -return 0 ; +return false; } -return 1 ; +return true; }static int virtio_net_has_buffers (VirtIONetQueue *q,int bufsize)hw/net/xilinx_ethlite.c +1
-1@@ -175,10 +175,10 @@ static const MemoryRegionOps eth_ops = { } }; -static int eth_can_rx (NetClientState *nc) +static bool eth_can_rx (NetClientState *nc) {struct xlx_ethlite *s =qemu_get_nic_opaque (nc);unsigned int rxbase = s->rxbuf * (0x800 /4 );return !(s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S ); }net/filter-buffer.c +1
-1@@ -59,28 +59,28 @@ static void filter_buffer_release_timer(void *opaque)/* filter APIs */ static ssize_t filter_buffer_receive_iov (NetFilterState *nf,NetClientState *sender,unsigned flags,const struct iovec *iov,int iovcnt,NetPacketSent *sent_cb) {FilterBufferState *s =FILTER_BUFFER (nf);/* * We return size when buffer a packet, the sender will take it as * a already sent packet, so sent_cb should not be called later. * * FIXME: Even if the guest can't receive packets for some reasons, * the filter can still accept packets until its internal queue is full. * For example: * For some reason, receiver could not receive more packets -* (.can_receive() returns zero). Without a filter, at most one packet +* (.can_receive() returns false). Without a filter, at most one packet * will be queued in incoming queue and sender's poll will be disabled * unit its sent_cb() was called. With a filter, it will keep receiving * the packets without caring about the receiver. This is suboptimal. * May need more thoughts (e.g keeping sent_cb). */ qemu_net_queue_append_iov (s->incoming_queue, sender, flags, iov, iovcnt,NULL );return iov_size (iov, iovcnt); }net/hub.c +3
-3@@ -90,23 +90,23 @@ static NetHub *net_hub_new(int id)return hub; } -static int net_hub_port_can_receive (NetClientState *nc) +static bool net_hub_port_can_receive (NetClientState *nc) {NetHubPort *port;NetHubPort *src_port =DO_UPCAST (NetHubPort, nc, nc);NetHub *hub = src_port->hub; QLIST_FOREACH(port, &hub->ports, next) {if (port == src_port) {continue ; }if (qemu_can_send_packet (&port->nc)) { -return 1 ; +return true; } } -return 0 ; +return false; } static ssize_t net_hub_port_receive(NetClientState *nc,
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH 5/6] hw/net: Make NetCanReceive() return a boolean
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
The NetCanReceive handler return whether the device can or can not receive new packets. Make it obvious by returning a boolean type.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
ftgmac100 looks good.
Thanks,
C.
Quoted 526 lines
--- hw/net/i82596.h | 2 +- include/net/net.h | 2 +- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 8 ++++---- hw/net/dp8393x.c | 8 +++----- hw/net/e1000.c | 2 +- hw/net/e1000e.c | 2 +- hw/net/ftgmac100.c | 6 +++--- hw/net/i82596.c | 10 +++++----- hw/net/imx_fec.c | 2 +- hw/net/opencores_eth.c | 5 ++--- hw/net/rtl8139.c | 8 ++++---- hw/net/smc91c111.c | 2 +- hw/net/spapr_llan.c | 4 ++-- hw/net/sungem.c | 6 +++--- hw/net/sunhme.c | 4 ++-- hw/net/virtio-net.c | 10 +++++----- hw/net/xilinx_ethlite.c | 2 +- net/filter-buffer.c | 2 +- net/hub.c | 6 +++--- 20 files changed, 45 insertions(+), 48 deletions(-)hw/net/i82596.h +1
-1@@ -48,7 +48,7 @@ void i82596_ioport_writel(void *opaque, uint32_t addr, uint32_t val);uint32_t i82596_ioport_readl (void *opaque,uint32_t addr);uint32_t i82596_bcr_readw (I82596State *s,uint32_t rap);ssize_t i82596_receive (NetClientState *nc,const uint8_t *buf,size_t size_); -int i82596_can_receive (NetClientState *nc); +bool i82596_can_receive (NetClientState *nc);void i82596_set_link_status (NetClientState *nc);void i82596_common_init (DeviceState *dev,I82596State *s,NetClientInfo *info);extern const VMStateDescription vmstate_i82596;include/net/net.h +1
-1@@ -42,7 +42,7 @@ typedef struct NICConf {/* Net clients */ typedef void (NetPoll )(NetClientState *,bool enable); -typedef int (NetCanReceive )(NetClientState *); +typedef bool (NetCanReceive )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int );typedef void (NetCleanup ) (NetClientState *);hw/net/allwinner_emac.c +1
-1@@ -178,13 +178,13 @@ static uint32_t fifo8_pop_word(Fifo8 *fifo)return ret; } -static int aw_emac_can_receive (NetClientState *nc) +static bool aw_emac_can_receive (NetClientState *nc) {AwEmacState *s =qemu_get_nic_opaque (nc);/* * To avoid packet drops, allow reception only when there is space * for a full frame: 1522 + 8 (rx headers) + 2 (padding). */ return (s->ctl &EMAC_CTL_RX_EN ) && (fifo8_num_free (&s->rx_fifo) >=1532 ); }hw/net/cadence_gem.c +4
-4@@ -505,44 +505,44 @@ static void phy_update_link(CadenceGEMState *s) } } -static int gem_can_receive (NetClientState *nc) +static bool gem_can_receive (NetClientState *nc) {CadenceGEMState *s;int i; s =qemu_get_nic_opaque (nc);/* Do nothing if receive is not enabled. */ if (!(s->regs[GEM_NWCTRL ] &GEM_NWCTRL_RXENA )) {if (s->can_rx_state !=1 ) { s->can_rx_state =1 ;DB_PRINT ("can't receive - no enable\n" ); } -return 0 ; +return false; }for (i =0 ; i < s->num_priority_queues; i++) {if (rx_desc_get_ownership (s->rx_desc[i]) !=1 ) {break ; } };if (i == s->num_priority_queues) {if (s->can_rx_state !=2 ) { s->can_rx_state =2 ;DB_PRINT ("can't receive - all the buffer descriptors are busy\n" ); } -return 0 ; +return false; }if (s->can_rx_state !=0 ) { s->can_rx_state =0 ;DB_PRINT ("can receive\n" ); } -return 1 ; +return true; }/* * gem_update_int_status: * Raise or lower interrupt based on current status. */ hw/net/dp8393x.c +3
-5@@ -414,7 +414,7 @@ static void dp8393x_do_stop_timer(dp8393xState *s)dp8393x_update_wt_regs (s); } -static int dp8393x_can_receive (NetClientState *nc); +static bool dp8393x_can_receive (NetClientState *nc);static void dp8393x_do_receiver_enable (dp8393xState *s) {@@ -718,13 +718,11 @@ static void dp8393x_watchdog(void *opaque)dp8393x_update_irq (s); } -static int dp8393x_can_receive (NetClientState *nc) +static bool dp8393x_can_receive (NetClientState *nc) {dp8393xState *s =qemu_get_nic_opaque (nc); -if (!(s->regs[SONIC_CR ] &SONIC_CR_RXEN )) -return 0 ; -return 1 ; +return !!(s->regs[SONIC_CR ] &SONIC_CR_RXEN ); } static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf,hw/net/e1000.c +1
-1@@ -845,7 +845,7 @@ static bool e1000_has_rxbufs(E1000State *s, size_t total_size)return total_size <= bufs * s->rxbuf_size; } -static int +static bool e1000_can_receive (NetClientState *nc) {E1000State *s =qemu_get_nic_opaque (nc);hw/net/e1000e.c +1
-1@@ -199,7 +199,7 @@ static const MemoryRegionOps io_ops = { }, }; -static int +static bool e1000e_nc_can_receive (NetClientState *nc) {E1000EState *s =qemu_get_nic_opaque (nc);hw/net/ftgmac100.c +3
-3@@ -562,24 +562,24 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,ftgmac100_update_irq (s); } -static int ftgmac100_can_receive (NetClientState *nc) +static bool ftgmac100_can_receive (NetClientState *nc) {FTGMAC100State *s =FTGMAC100 (qemu_get_nic_opaque (nc));FTGMAC100Desc bd;if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN |FTGMAC100_MACCR_RXMAC_EN )) != (FTGMAC100_MACCR_RXDMA_EN |FTGMAC100_MACCR_RXMAC_EN )) { -return 0 ; +return false; }if (ftgmac100_read_bd (&bd, s->rx_descriptor)) { -return 0 ; +return false; }return !(bd.des0 &FTGMAC100_RXDES0_RXPKT_RDY ); }/* * This is purely informative. The HW can poll the RW (and RX) ring * buffers for available descriptors but we don't need to trigger a * timer for that in qemu. */ hw/net/i82596.c +5
-5@@ -474,23 +474,23 @@ void i82596_h_reset(void *opaque)i82596_s_reset (s); } -int i82596_can_receive (NetClientState *nc) +bool i82596_can_receive (NetClientState *nc) {I82596State *s =qemu_get_nic_opaque (nc);if (s->rx_status ==RX_SUSPENDED ) { -return 0 ; +return false; }if (!s->lnkst) { -return 0 ; +return false; }if (USE_TIMER && !timer_pending (s->flush_queue_timer)) { -return 1 ; +return true; } -return 1 ; +return true; }#define MIN_BUF_SIZE 60hw/net/imx_fec.c +1
-1@@ -1047,11 +1047,11 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,imx_eth_update (s); } -static int imx_eth_can_receive (NetClientState *nc) +static bool imx_eth_can_receive (NetClientState *nc) {IMXFECState *s =IMX_FEC (qemu_get_nic_opaque (nc));FEC_PRINTF ("\n" );return !!s->regs[ENET_RDAR ]; }hw/net/opencores_eth.c +2
-3@@ -349,12 +349,11 @@ static void open_eth_reset(void *opaque)open_eth_set_link_status (qemu_get_queue (s->nic)); } -static int open_eth_can_receive (NetClientState *nc) +static bool open_eth_can_receive (NetClientState *nc) {OpenEthState *s =qemu_get_nic_opaque (nc); -return GET_REGBIT (s,MODER ,RXEN ) && - (s->regs[TX_BD_NUM ] <0x80 ); +return GET_REGBIT (s,MODER ,RXEN ) && (s->regs[TX_BD_NUM ] <0x80 ); } static ssize_t open_eth_receive(NetClientState *nc,hw/net/rtl8139.c +4
-4@@ -793,26 +793,26 @@ static bool rtl8139_cp_rx_valid(RTL8139State *s)return !(s->RxRingAddrLO ==0 && s->RxRingAddrHI ==0 ); } -static int rtl8139_can_receive (NetClientState *nc) +static bool rtl8139_can_receive (NetClientState *nc) {RTL8139State *s =qemu_get_nic_opaque (nc);int avail;/* Receive (drop) packets if card is disabled. */ if (!s->clock_enabled) { -return 1 ; +return true; }if (!rtl8139_receiver_enabled (s)) { -return 1 ; +return true; }if (rtl8139_cp_receiver_enabled (s) &&rtl8139_cp_rx_valid (s)) {/* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ -return 1 ; +return true; } avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize);return avail ==0 || avail >=1514 || (s->IntrMask & RxOverflow); }hw/net/smc91c111.c +1
-1@@ -667,9 +667,9 @@ static void smc91c111_writefn(void *opaque, hwaddr addr, } } -static int smc91c111_can_receive_nc (NetClientState *nc) +static bool smc91c111_can_receive_nc (NetClientState *nc) {smc91c111_state *s =qemu_get_nic_opaque (nc);return smc91c111_can_receive (s); }hw/net/spapr_llan.c +2
-2@@ -110,17 +110,17 @@ typedef struct SpaprVioVlan {RxBufPool *rx_pool[RX_MAX_POOLS ];/* Receive buffer descriptor pools */ } SpaprVioVlan; -static int spapr_vlan_can_receive (NetClientState *nc) +static bool spapr_vlan_can_receive (NetClientState *nc) {SpaprVioVlan *dev =qemu_get_nic_opaque (nc); -return (dev->isopen && dev->rx_bufs >0 ); +return dev->isopen && dev->rx_bufs >0 ; }/** * The last 8 bytes of the receive buffer list page (that has been * supplied by the guest with the H_REGISTER_LOGICAL_LAN call) contain * a counter for frames that have been dropped because there was no * suitable receive buffer available. This function is used to increase * this counter by one. */ hw/net/sungem.c +3
-3@@ -433,31 +433,31 @@ static bool sungem_rx_full(SunGEMState *s, uint32_t kick, uint32_t done)return kick == ((done +1 ) & s->rx_mask); } -static int sungem_can_receive (NetClientState *nc) +static bool sungem_can_receive (NetClientState *nc) {SunGEMState *s =qemu_get_nic_opaque (nc);uint32_t kick, done, rxdma_cfg, rxmac_cfg;bool full; rxmac_cfg = s->macregs[MAC_RXCFG >>2 ]; rxdma_cfg = s->rxdmaregs[RXDMA_CFG >>2 ];/* If MAC disabled, can't receive */ if ((rxmac_cfg &MAC_RXCFG_ENAB ) ==0 ) {trace_sungem_rx_mac_disabled (); -return 0 ; +return false; }if ((rxdma_cfg &RXDMA_CFG_ENABLE ) ==0 ) {trace_sungem_rx_txdma_disabled (); -return 0 ; +return false; }/* Check RX availability */ kick = s->rxdmaregs[RXDMA_KICK >>2 ]; done = s->rxdmaregs[RXDMA_DONE >>2 ]; full =sungem_rx_full (s, kick, done);trace_sungem_rx_check (!full, kick, done);return !full; }hw/net/sunhme.c +2
-2@@ -657,11 +657,11 @@ static void sunhme_transmit(SunHMEState *s)sunhme_update_irq (s); } -static int sunhme_can_receive (NetClientState *nc) +static bool sunhme_can_receive (NetClientState *nc) {SunHMEState *s =qemu_get_nic_opaque (nc); -return s->macregs[HME_MACI_RXCFG >>2 ] &HME_MAC_RXCFG_ENABLE ; +return !!(s->macregs[HME_MACI_RXCFG >>2 ] &HME_MAC_RXCFG_ENABLE ); }static void sunhme_link_status_changed (NetClientState *nc)hw/net/virtio-net.c +5
-5@@ -1234,26 +1234,26 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)qemu_flush_queued_packets (qemu_get_subqueue (n->nic, queue_index)); } -static int virtio_net_can_receive (NetClientState *nc) +static bool virtio_net_can_receive (NetClientState *nc) {VirtIONet *n =qemu_get_nic_opaque (nc);VirtIODevice *vdev =VIRTIO_DEVICE (n);VirtIONetQueue *q =virtio_net_get_subqueue (nc);if (!vdev->vm_running) { -return 0 ; +return false; }if (nc->queue_index >= n->curr_queues) { -return 0 ; +return false; }if (!virtio_queue_ready (q->rx_vq) || !(vdev->status &VIRTIO_CONFIG_S_DRIVER_OK )) { -return 0 ; +return false; } -return 1 ; +return true; }static int virtio_net_has_buffers (VirtIONetQueue *q,int bufsize)hw/net/xilinx_ethlite.c +1
-1@@ -175,10 +175,10 @@ static const MemoryRegionOps eth_ops = { } }; -static int eth_can_rx (NetClientState *nc) +static bool eth_can_rx (NetClientState *nc) {struct xlx_ethlite *s =qemu_get_nic_opaque (nc);unsigned int rxbase = s->rxbuf * (0x800 /4 );return !(s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S ); }net/filter-buffer.c +1
-1@@ -59,28 +59,28 @@ static void filter_buffer_release_timer(void *opaque)/* filter APIs */ static ssize_t filter_buffer_receive_iov (NetFilterState *nf,NetClientState *sender,unsigned flags,const struct iovec *iov,int iovcnt,NetPacketSent *sent_cb) {FilterBufferState *s =FILTER_BUFFER (nf);/* * We return size when buffer a packet, the sender will take it as * a already sent packet, so sent_cb should not be called later. * * FIXME: Even if the guest can't receive packets for some reasons, * the filter can still accept packets until its internal queue is full. * For example: * For some reason, receiver could not receive more packets -* (.can_receive() returns zero). Without a filter, at most one packet +* (.can_receive() returns false). Without a filter, at most one packet * will be queued in incoming queue and sender's poll will be disabled * unit its sent_cb() was called. With a filter, it will keep receiving * the packets without caring about the receiver. This is suboptimal. * May need more thoughts (e.g keeping sent_cb). */ qemu_net_queue_append_iov (s->incoming_queue, sender, flags, iov, iovcnt,NULL );return iov_size (iov, iovcnt); }net/hub.c +3
-3@@ -90,23 +90,23 @@ static NetHub *net_hub_new(int id)return hub; } -static int net_hub_port_can_receive (NetClientState *nc) +static bool net_hub_port_can_receive (NetClientState *nc) {NetHubPort *port;NetHubPort *src_port =DO_UPCAST (NetHubPort, nc, nc);NetHub *hub = src_port->hub; QLIST_FOREACH(port, &hub->ports, next) {if (port == src_port) {continue ; }if (qemu_can_send_packet (&port->nc)) { -return 1 ; +return true; } } -return 0 ; +return false; } static ssize_t net_hub_port_receive(NetClientState *nc,
PATCH 6/6 hw/net/can: Make CanBusClientInfo::can_receive() return a boolean
In reply to Philippe Mathieu-DaudéThe CanBusClientInfo::can_receive handler return whether the device can or can not receive new frames. Make it obvious by returning a boolean type.
--- hw/net/can/can_sja1000.h | 2 +- include/net/can_emu.h | 2 +- hw/net/can/can_sja1000.c | 8 ++++---- net/can/can_socketcan.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
hw/net/can/can_sja1000.h +1 -1
@@ -137,7 +137,7 @@ void can_sja_disconnect(CanSJA1000State *s);int can_sja_init (CanSJA1000State *s,qemu_irq irq); -int can_sja_can_receive (CanBusClientState *client); +bool can_sja_can_receive (CanBusClientState *client);ssize_t can_sja_receive (CanBusClientState *client,const qemu_can_frame *frames,size_t frames_cnt);
include/net/can_emu.h +1 -1
@@ -83,7 +83,7 @@ typedef struct CanBusClientState CanBusClientState;typedef struct CanBusState CanBusState ;typedef struct CanBusClientInfo { -int (*can_receive)(CanBusClientState *); +bool (*can_receive)(CanBusClientState *);ssize_t (*receive)(CanBusClientState *,const struct qemu_can_frame *frames,size_t frames_cnt); }CanBusClientInfo ;
hw/net/can/can_sja1000.c +4 -4
@@ -733,21 +733,21 @@ uint64_t can_sja_mem_read(CanSJA1000State *s, hwaddr addr, unsigned size)return temp; } -int can_sja_can_receive (CanBusClientState *client) +bool can_sja_can_receive (CanBusClientState *client) {CanSJA1000State *s =container_of (client, CanSJA1000State, bus_client);if (s->clock &0x80 ) {/* PeliCAN Mode */ if (s->mode &0x01 ) {/* reset mode. */ -return 0 ; +return false; } }else {/* BasicCAN mode */ if (s->control &0x01 ) { -return 0 ; +return false; } } -return 1 ;/* always return 1, when operation mode */ +return true;/* always return true, when operation mode */ } ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *frames,
net/can/can_socketcan.c +2 -2
@@ -110,9 +110,9 @@ static void can_host_socketcan_read(void *opaque) } } -static int can_host_socketcan_can_receive (CanBusClientState *client) +static bool can_host_socketcan_can_receive (CanBusClientState *client) { -return 1 ; +return true; } static ssize_t can_host_socketcan_receive(CanBusClientState *client,
Signature · 1 line
2.21.1
Re: [PATCH 6/6] hw/net/can: Make CanBusClientInfo::can_receive() return a boolean
Quoted 6 lines · Philippe Mathieu-Daudé
The
CanBusClientInfo::can_receivehandler return whether the device can or can not receive new frames. Make it obvious by returning a boolean type.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Alistair
Quoted 83 lines
--- hw/net/can/can_sja1000.h | 2 +- include/net/can_emu.h | 2 +- hw/net/can/can_sja1000.c | 8 ++++---- net/can/can_socketcan.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)hw/net/can/can_sja1000.h +1
-1@@ -137,7 +137,7 @@ void can_sja_disconnect(CanSJA1000State *s);int can_sja_init (CanSJA1000State *s,qemu_irq irq); -int can_sja_can_receive (CanBusClientState *client); +bool can_sja_can_receive (CanBusClientState *client);ssize_t can_sja_receive (CanBusClientState *client,const qemu_can_frame *frames,size_t frames_cnt);include/net/can_emu.h +1
-1@@ -83,7 +83,7 @@ typedef struct CanBusClientState CanBusClientState;typedef struct CanBusState CanBusState ;typedef struct CanBusClientInfo { -int (*can_receive)(CanBusClientState *); +bool (*can_receive)(CanBusClientState *);ssize_t (*receive)(CanBusClientState *,const struct qemu_can_frame *frames,size_t frames_cnt); }CanBusClientInfo ;hw/net/can/can_sja1000.c +4
-4@@ -733,21 +733,21 @@ uint64_t can_sja_mem_read(CanSJA1000State *s, hwaddr addr, unsigned size)return temp; } -int can_sja_can_receive (CanBusClientState *client) +bool can_sja_can_receive (CanBusClientState *client) {CanSJA1000State *s =container_of (client, CanSJA1000State, bus_client);if (s->clock &0x80 ) {/* PeliCAN Mode */ if (s->mode &0x01 ) {/* reset mode. */ -return 0 ; +return false; } }else {/* BasicCAN mode */ if (s->control &0x01 ) { -return 0 ; +return false; } } -return 1 ;/* always return 1, when operation mode */ +return true;/* always return true, when operation mode */ } ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *frames,net/can/can_socketcan.c +2
-3@@ -110,9 +110,9 @@ static void can_host_socketcan_read(void *opaque) } } -static int can_host_socketcan_can_receive (CanBusClientState *client) +static bool can_host_socketcan_can_receive (CanBusClientState *client) { -return 1 ; +return true; } static ssize_t can_host_socketcan_receive(CanBusClientState *client, --2.21.1
Re: [PATCH 6/6] hw/net/can: Make CanBusClientInfo::can_receive() return a boolean
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
The
CanBusClientInfo::can_receivehandler return whether the device can or can not receive new frames. Make it obvious by returning a boolean type.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 80 lines
--- hw/net/can/can_sja1000.h | 2 +- include/net/can_emu.h | 2 +- hw/net/can/can_sja1000.c | 8 ++++---- net/can/can_socketcan.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)hw/net/can/can_sja1000.h +1
-1@@ -137,7 +137,7 @@ void can_sja_disconnect(CanSJA1000State *s);int can_sja_init (CanSJA1000State *s,qemu_irq irq); -int can_sja_can_receive (CanBusClientState *client); +bool can_sja_can_receive (CanBusClientState *client);ssize_t can_sja_receive (CanBusClientState *client,const qemu_can_frame *frames,size_t frames_cnt);include/net/can_emu.h +1
-1@@ -83,7 +83,7 @@ typedef struct CanBusClientState CanBusClientState;typedef struct CanBusState CanBusState ;typedef struct CanBusClientInfo { -int (*can_receive)(CanBusClientState *); +bool (*can_receive)(CanBusClientState *);ssize_t (*receive)(CanBusClientState *,const struct qemu_can_frame *frames,size_t frames_cnt); }CanBusClientInfo ;hw/net/can/can_sja1000.c +4
-4@@ -733,21 +733,21 @@ uint64_t can_sja_mem_read(CanSJA1000State *s, hwaddr addr, unsigned size)return temp; } -int can_sja_can_receive (CanBusClientState *client) +bool can_sja_can_receive (CanBusClientState *client) {CanSJA1000State *s =container_of (client, CanSJA1000State, bus_client);if (s->clock &0x80 ) {/* PeliCAN Mode */ if (s->mode &0x01 ) {/* reset mode. */ -return 0 ; +return false; } }else {/* BasicCAN mode */ if (s->control &0x01 ) { -return 0 ; +return false; } } -return 1 ;/* always return 1, when operation mode */ +return true;/* always return true, when operation mode */ } ssize_t can_sja_receive(CanBusClientState *client, const qemu_can_frame *frames,net/can/can_socketcan.c +2
-2@@ -110,9 +110,9 @@ static void can_host_socketcan_read(void *opaque) } } -static int can_host_socketcan_can_receive (CanBusClientState *client) +static bool can_host_socketcan_can_receive (CanBusClientState *client) { -return 1 ; +return true; } static ssize_t can_host_socketcan_receive(CanBusClientState *client,
Ping?
This series is fully reviewed.
Quoted 40 lines · Philippe Mathieu-Daudé
The Net/CanBus
can_receive()handlers return whether the network device can or can not receive new data. Make it obvious by returning a boolean typePhilippe Mathieu-Daudé (6):
hw/net/e1000e_core: Lete1000e_can_receive()return a boolean hw/net/smc91c111: Letsmc91c111_can_receive()return a boolean hw/net/rtl8139: Simplify if/else statement hw/net/rtl8139: Update coding style to make checkpatch.pl happy hw/net: MakeNetCanReceive()return a boolean hw/net/can: MakeCanBusClientInfo::can_receive()return a booleanhw/net/can/can_sja1000.h | 2 +- hw/net/e1000e_core.h | 2 +- hw/net/i82596.h | 2 +- include/net/can_emu.h | 2 +- include/net/net.h | 2 +- hw/net/allwinner_emac.c | 2 +- hw/net/cadence_gem.c | 8 ++++---- hw/net/can/can_sja1000.c | 8 ++++---- hw/net/dp8393x.c | 8 +++----- hw/net/e1000.c | 2 +- hw/net/e1000e.c | 2 +- hw/net/e1000e_core.c | 2 +- hw/net/ftgmac100.c | 6 +++--- hw/net/i82596.c | 10 +++++----- hw/net/imx_fec.c | 2 +- hw/net/opencores_eth.c | 5 ++--- hw/net/rtl8139.c | 22 ++++++++++++---------- hw/net/smc91c111.c | 10 +++++----- hw/net/spapr_llan.c | 4 ++-- hw/net/sungem.c | 6 +++--- hw/net/sunhme.c | 4 ++-- hw/net/virtio-net.c | 10 +++++----- hw/net/xilinx_ethlite.c | 2 +- net/can/can_socketcan.c | 4 ++-- net/filter-buffer.c | 2 +- net/hub.c | 6 +++--- 26 files changed, 67 insertions(+), 68 deletions(-)
Jason Wang
AppliedQuoted 3 lines · Philippe Mathieu-Daudé
Ping?
This series is fully reviewed.
Sorry for the delay.
Applied.
Thanks