From 463af5349a787160642f023dad10eaf0cb419fb7 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 18 May 2009 12:55:27 +0100 Subject: net: add fd_readv() handler to qemu_new_vlan_client() args This, apparently, is the style we prefer - all VLANClientState should be an argument to qemu_new_vlan_client(). Signed-off-by: Mark McLoughlin --- hw/rtl8139.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw/rtl8139.c') diff --git a/hw/rtl8139.c b/hw/rtl8139.c index d99f35c..ab68bda 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -3475,7 +3475,7 @@ static void pci_rtl8139_init(PCIDevice *dev) qdev_get_macaddr(&dev->qdev, s->macaddr); rtl8139_reset(s); s->vc = qdev_get_vlan_client(&dev->qdev, - rtl8139_receive, rtl8139_can_receive, + rtl8139_can_receive, rtl8139_receive, NULL, rtl8139_cleanup, s); qemu_format_nic_info_str(s->vc, s->macaddr); -- cgit v1.1 From cda9046ba7dbba45f3016e5d60caffa2d72960fa Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 18 May 2009 13:13:16 +0100 Subject: net: re-name vc->fd_read() to vc->receive() VLANClientState's fd_read() handler doesn't read from file descriptors, it adds a buffer to the client's receive queue. Re-name the handlers to make things a little less confusing. Signed-off-by: Mark McLoughlin --- hw/rtl8139.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw/rtl8139.c') diff --git a/hw/rtl8139.c b/hw/rtl8139.c index ab68bda..14119d4 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -1158,7 +1158,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d } } -static void rtl8139_receive(void *opaque, const uint8_t *buf, int size) +static void rtl8139_receive(void *opaque, const uint8_t *buf, size_t size) { rtl8139_do_receive(opaque, buf, size, 1); } -- cgit v1.1 From e3f5ec2b5e92706e3b807059f79b1fb5d936e567 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 18 May 2009 13:33:03 +0100 Subject: net: pass VLANClientState* as first arg to receive handlers Give static type checking a chance to catch errors. Signed-off-by: Mark McLoughlin --- hw/rtl8139.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'hw/rtl8139.c') diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 14119d4..8626d5e 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -790,9 +790,9 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high) #endif } -static int rtl8139_can_receive(void *opaque) +static int rtl8139_can_receive(VLANClientState *vc) { - RTL8139State *s = opaque; + RTL8139State *s = vc->opaque; int avail; /* Receive (drop) packets if card is disabled. */ @@ -812,9 +812,9 @@ static int rtl8139_can_receive(void *opaque) } } -static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int do_interrupt) +static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size, int do_interrupt) { - RTL8139State *s = opaque; + RTL8139State *s = vc->opaque; uint32_t packet_header = 0; @@ -1158,9 +1158,9 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d } } -static void rtl8139_receive(void *opaque, const uint8_t *buf, size_t size) +static void rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size) { - rtl8139_do_receive(opaque, buf, size, 1); + rtl8139_do_receive(vc, buf, size, 1); } static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) @@ -1757,7 +1757,7 @@ static void rtl8139_transfer_frame(RTL8139State *s, const uint8_t *buf, int size if (TxLoopBack == (s->TxConfig & TxLoopBack)) { DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n")); - rtl8139_do_receive(s, buf, size, do_interrupt); + rtl8139_do_receive(s->vc, buf, size, do_interrupt); } else { -- cgit v1.1 From 4f1c942b7fb29864ad86cb3af9076da38f38f74e Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 18 May 2009 13:40:55 +0100 Subject: net: add return value to packet receive handler This allows us to handle queue full conditions rather than dropping the packet on the floor. Signed-off-by: Mark McLoughlin --- hw/rtl8139.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'hw/rtl8139.c') diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 8626d5e..c86b782 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -812,9 +812,10 @@ static int rtl8139_can_receive(VLANClientState *vc) } } -static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size, int do_interrupt) +static ssize_t rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, size_t size_, int do_interrupt) { RTL8139State *s = vc->opaque; + int size = size_; uint32_t packet_header = 0; @@ -828,7 +829,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size if (!s->clock_enabled) { DEBUG_PRINT(("RTL8139: stopped ==========================\n")); - return; + return -1; } /* first check if receiver is enabled */ @@ -836,7 +837,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size if (!rtl8139_receiver_enabled(s)) { DEBUG_PRINT(("RTL8139: receiver disabled ================\n")); - return; + return -1; } /* XXX: check this */ @@ -854,7 +855,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size /* update tally counter */ ++s->tally_counters.RxERR; - return; + return size; } packet_header |= RxBroadcast; @@ -873,7 +874,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size /* update tally counter */ ++s->tally_counters.RxERR; - return; + return size; } int mcast_idx = compute_mcast_idx(buf); @@ -885,7 +886,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size /* update tally counter */ ++s->tally_counters.RxERR; - return; + return size; } packet_header |= RxMulticast; @@ -909,7 +910,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size /* update tally counter */ ++s->tally_counters.RxERR; - return; + return size; } packet_header |= RxPhysical; @@ -926,7 +927,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size /* update tally counter */ ++s->tally_counters.RxERR; - return; + return size; } } @@ -993,7 +994,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size ++s->tally_counters.MissPkt; rtl8139_update_irq(s); - return; + return size_; } uint32_t rx_space = rxdw0 & CP_RX_BUFFER_SIZE_MASK; @@ -1013,7 +1014,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size ++s->tally_counters.MissPkt; rtl8139_update_irq(s); - return; + return size_; } target_phys_addr_t rx_addr = rtl8139_addr64(rxbufLO, rxbufHI); @@ -1118,7 +1119,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size s->IntrStatus |= RxOverflow; ++s->RxMissed; rtl8139_update_irq(s); - return; + return size_; } packet_header |= RxStatusOK; @@ -1156,11 +1157,13 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size { rtl8139_update_irq(s); } + + return size_; } -static void rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +static ssize_t rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size) { - rtl8139_do_receive(vc, buf, size, 1); + return rtl8139_do_receive(vc, buf, size, 1); } static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) -- cgit v1.1