hw/net: Make NetCanReceive() return a boolean

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é <philmd@redhat.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
stable-5.0
Philippe Mathieu-Daudé 2020-03-05 18:56:49 +01:00 committed by Jason Wang
parent 3317db7439
commit b8c4b67e3e
20 changed files with 45 additions and 48 deletions

View File

@ -178,7 +178,7 @@ static uint32_t fifo8_pop_word(Fifo8 *fifo)
return ret; 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); AwEmacState *s = qemu_get_nic_opaque(nc);

View File

@ -505,7 +505,7 @@ static void phy_update_link(CadenceGEMState *s)
} }
} }
static int gem_can_receive(NetClientState *nc) static bool gem_can_receive(NetClientState *nc)
{ {
CadenceGEMState *s; CadenceGEMState *s;
int i; int i;
@ -518,7 +518,7 @@ static int gem_can_receive(NetClientState *nc)
s->can_rx_state = 1; s->can_rx_state = 1;
DB_PRINT("can't receive - no enable\n"); DB_PRINT("can't receive - no enable\n");
} }
return 0; return false;
} }
for (i = 0; i < s->num_priority_queues; i++) { for (i = 0; i < s->num_priority_queues; i++) {
@ -532,14 +532,14 @@ static int gem_can_receive(NetClientState *nc)
s->can_rx_state = 2; s->can_rx_state = 2;
DB_PRINT("can't receive - all the buffer descriptors are busy\n"); DB_PRINT("can't receive - all the buffer descriptors are busy\n");
} }
return 0; return false;
} }
if (s->can_rx_state != 0) { if (s->can_rx_state != 0) {
s->can_rx_state = 0; s->can_rx_state = 0;
DB_PRINT("can receive\n"); DB_PRINT("can receive\n");
} }
return 1; return true;
} }
/* /*

View File

@ -414,7 +414,7 @@ static void dp8393x_do_stop_timer(dp8393xState *s)
dp8393x_update_wt_regs(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) static void dp8393x_do_receiver_enable(dp8393xState *s)
{ {
@ -718,13 +718,11 @@ static void dp8393x_watchdog(void *opaque)
dp8393x_update_irq(s); 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); dp8393xState *s = qemu_get_nic_opaque(nc);
if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN)) return !!(s->regs[SONIC_CR] & SONIC_CR_RXEN);
return 0;
return 1;
} }
static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf, static int dp8393x_receive_filter(dp8393xState *s, const uint8_t * buf,

View File

@ -845,7 +845,7 @@ static bool e1000_has_rxbufs(E1000State *s, size_t total_size)
return total_size <= bufs * s->rxbuf_size; return total_size <= bufs * s->rxbuf_size;
} }
static int static bool
e1000_can_receive(NetClientState *nc) e1000_can_receive(NetClientState *nc)
{ {
E1000State *s = qemu_get_nic_opaque(nc); E1000State *s = qemu_get_nic_opaque(nc);

View File

@ -199,7 +199,7 @@ static const MemoryRegionOps io_ops = {
}, },
}; };
static int static bool
e1000e_nc_can_receive(NetClientState *nc) e1000e_nc_can_receive(NetClientState *nc)
{ {
E1000EState *s = qemu_get_nic_opaque(nc); E1000EState *s = qemu_get_nic_opaque(nc);

View File

@ -562,18 +562,18 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,
ftgmac100_update_irq(s); 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)); FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
FTGMAC100Desc bd; FTGMAC100Desc bd;
if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN))
!= (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)) { if (ftgmac100_read_bd(&bd, s->rx_descriptor)) {
return 0; return false;
} }
return !(bd.des0 & FTGMAC100_RXDES0_RXPKT_RDY); return !(bd.des0 & FTGMAC100_RXDES0_RXPKT_RDY);
} }

View File

@ -470,23 +470,23 @@ void i82596_h_reset(void *opaque)
i82596_s_reset(s); i82596_s_reset(s);
} }
int i82596_can_receive(NetClientState *nc) bool i82596_can_receive(NetClientState *nc)
{ {
I82596State *s = qemu_get_nic_opaque(nc); I82596State *s = qemu_get_nic_opaque(nc);
if (s->rx_status == RX_SUSPENDED) { if (s->rx_status == RX_SUSPENDED) {
return 0; return false;
} }
if (!s->lnkst) { if (!s->lnkst) {
return 0; return false;
} }
if (USE_TIMER && !timer_pending(s->flush_queue_timer)) { if (USE_TIMER && !timer_pending(s->flush_queue_timer)) {
return 1; return true;
} }
return 1; return true;
} }
#define MIN_BUF_SIZE 60 #define MIN_BUF_SIZE 60

View File

@ -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_ioport_readl(void *opaque, uint32_t addr);
uint32_t i82596_bcr_readw(I82596State *s, uint32_t rap); uint32_t i82596_bcr_readw(I82596State *s, uint32_t rap);
ssize_t i82596_receive(NetClientState *nc, const uint8_t *buf, size_t size_); 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_set_link_status(NetClientState *nc);
void i82596_common_init(DeviceState *dev, I82596State *s, NetClientInfo *info); void i82596_common_init(DeviceState *dev, I82596State *s, NetClientInfo *info);
extern const VMStateDescription vmstate_i82596; extern const VMStateDescription vmstate_i82596;

View File

@ -1049,7 +1049,7 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,
imx_eth_update(s); 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)); IMXFECState *s = IMX_FEC(qemu_get_nic_opaque(nc));

View File

@ -349,12 +349,11 @@ static void open_eth_reset(void *opaque)
open_eth_set_link_status(qemu_get_queue(s->nic)); 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); OpenEthState *s = qemu_get_nic_opaque(nc);
return GET_REGBIT(s, MODER, RXEN) && return GET_REGBIT(s, MODER, RXEN) && (s->regs[TX_BD_NUM] < 0x80);
(s->regs[TX_BD_NUM] < 0x80);
} }
static ssize_t open_eth_receive(NetClientState *nc, static ssize_t open_eth_receive(NetClientState *nc,

View File

@ -793,23 +793,23 @@ static bool rtl8139_cp_rx_valid(RTL8139State *s)
return !(s->RxRingAddrLO == 0 && s->RxRingAddrHI == 0); 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); RTL8139State *s = qemu_get_nic_opaque(nc);
int avail; int avail;
/* Receive (drop) packets if card is disabled. */ /* Receive (drop) packets if card is disabled. */
if (!s->clock_enabled) { if (!s->clock_enabled) {
return 1; return true;
} }
if (!rtl8139_receiver_enabled(s)) { if (!rtl8139_receiver_enabled(s)) {
return 1; return true;
} }
if (rtl8139_cp_receiver_enabled(s) && rtl8139_cp_rx_valid(s)) { if (rtl8139_cp_receiver_enabled(s) && rtl8139_cp_rx_valid(s)) {
/* ??? Flow control not implemented in c+ mode. /* ??? Flow control not implemented in c+ mode.
This is a hack to work around slirp deficiencies anyway. */ This is a hack to work around slirp deficiencies anyway. */
return 1; return true;
} }
avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr,

View File

@ -667,7 +667,7 @@ 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); smc91c111_state *s = qemu_get_nic_opaque(nc);

View File

@ -110,11 +110,11 @@ typedef struct SpaprVioVlan {
RxBufPool *rx_pool[RX_MAX_POOLS]; /* Receive buffer descriptor pools */ RxBufPool *rx_pool[RX_MAX_POOLS]; /* Receive buffer descriptor pools */
} SpaprVioVlan; } SpaprVioVlan;
static int spapr_vlan_can_receive(NetClientState *nc) static bool spapr_vlan_can_receive(NetClientState *nc)
{ {
SpaprVioVlan *dev = qemu_get_nic_opaque(nc); SpaprVioVlan *dev = qemu_get_nic_opaque(nc);
return (dev->isopen && dev->rx_bufs > 0); return dev->isopen && dev->rx_bufs > 0;
} }
/** /**

View File

@ -433,7 +433,7 @@ static bool sungem_rx_full(SunGEMState *s, uint32_t kick, uint32_t done)
return kick == ((done + 1) & s->rx_mask); 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); SunGEMState *s = qemu_get_nic_opaque(nc);
uint32_t kick, done, rxdma_cfg, rxmac_cfg; uint32_t kick, done, rxdma_cfg, rxmac_cfg;
@ -445,11 +445,11 @@ static int sungem_can_receive(NetClientState *nc)
/* If MAC disabled, can't receive */ /* If MAC disabled, can't receive */
if ((rxmac_cfg & MAC_RXCFG_ENAB) == 0) { if ((rxmac_cfg & MAC_RXCFG_ENAB) == 0) {
trace_sungem_rx_mac_disabled(); trace_sungem_rx_mac_disabled();
return 0; return false;
} }
if ((rxdma_cfg & RXDMA_CFG_ENABLE) == 0) { if ((rxdma_cfg & RXDMA_CFG_ENABLE) == 0) {
trace_sungem_rx_txdma_disabled(); trace_sungem_rx_txdma_disabled();
return 0; return false;
} }
/* Check RX availability */ /* Check RX availability */

View File

@ -657,11 +657,11 @@ static void sunhme_transmit(SunHMEState *s)
sunhme_update_irq(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); 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) static void sunhme_link_status_changed(NetClientState *nc)

View File

@ -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)); 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); VirtIONet *n = qemu_get_nic_opaque(nc);
VirtIODevice *vdev = VIRTIO_DEVICE(n); VirtIODevice *vdev = VIRTIO_DEVICE(n);
VirtIONetQueue *q = virtio_net_get_subqueue(nc); VirtIONetQueue *q = virtio_net_get_subqueue(nc);
if (!vdev->vm_running) { if (!vdev->vm_running) {
return 0; return false;
} }
if (nc->queue_index >= n->curr_queues) { if (nc->queue_index >= n->curr_queues) {
return 0; return false;
} }
if (!virtio_queue_ready(q->rx_vq) || if (!virtio_queue_ready(q->rx_vq) ||
!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { !(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) static int virtio_net_has_buffers(VirtIONetQueue *q, int bufsize)

View File

@ -175,7 +175,7 @@ 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); struct xlx_ethlite *s = qemu_get_nic_opaque(nc);
unsigned int rxbase = s->rxbuf * (0x800 / 4); unsigned int rxbase = s->rxbuf * (0x800 / 4);

View File

@ -42,7 +42,7 @@ typedef struct NICConf {
/* Net clients */ /* Net clients */
typedef void (NetPoll)(NetClientState *, bool enable); 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 (NetReceive)(NetClientState *, const uint8_t *, size_t);
typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
typedef void (NetCleanup) (NetClientState *); typedef void (NetCleanup) (NetClientState *);

View File

@ -74,7 +74,7 @@ static ssize_t filter_buffer_receive_iov(NetFilterState *nf,
* the filter can still accept packets until its internal queue is full. * the filter can still accept packets until its internal queue is full.
* For example: * For example:
* For some reason, receiver could not receive more packets * 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 * 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 * unit its sent_cb() was called. With a filter, it will keep receiving
* the packets without caring about the receiver. This is suboptimal. * the packets without caring about the receiver. This is suboptimal.

View File

@ -90,7 +90,7 @@ static NetHub *net_hub_new(int id)
return hub; return hub;
} }
static int net_hub_port_can_receive(NetClientState *nc) static bool net_hub_port_can_receive(NetClientState *nc)
{ {
NetHubPort *port; NetHubPort *port;
NetHubPort *src_port = DO_UPCAST(NetHubPort, nc, nc); NetHubPort *src_port = DO_UPCAST(NetHubPort, nc, nc);
@ -102,11 +102,11 @@ static int net_hub_port_can_receive(NetClientState *nc)
} }
if (qemu_can_send_packet(&port->nc)) { if (qemu_can_send_packet(&port->nc)) {
return 1; return true;
} }
} }
return 0; return false;
} }
static ssize_t net_hub_port_receive(NetClientState *nc, static ssize_t net_hub_port_receive(NetClientState *nc,