rtl8139: check the buffer availiability
PATCH 1/1 rtl8139: check the buffer availiability
Reduce spurious packet drops on RX ring empty when in c+ mode by verifying that we have at least 1 buffer ahead of the time.
Signed-off-by Jason Wang <[email protected]>
--- hw/rtl8139.c | 43 +++++++++++++++++++++++++++++-------------- 1 files changed, 29 insertions(+), 14 deletions(-)
hw/rtl8139.c +29 -14
@@ -84,6 +84,19 @@#define VLAN_TCI_LEN 2#define VLAN_HLEN (ETHER_TYPE_LEN + VLAN_TCI_LEN) +/* w0 ownership flag */ +#define CP_RX_OWN (1<<31) +/* w0 end of ring flag */ +#define CP_RX_EOR (1<<30) +/* w0 bits 0...12 : buffer size */ +#define CP_RX_BUFFER_SIZE_MASK ((1<<13) - 1) +/* w1 tag available flag */ +#define CP_RX_TAVA (1<<16) +/* w1 bits 0...15 : VLAN tag */ +#define CP_RX_VLAN_TAG_MASK ((1<<16) - 1) +/* w2 low 32bit of Rx buffer ptr */ +/* w3 high 32bit of Rx buffer ptr */ +#if defined (DEBUG_RTL8139 )# define DPRINTF (fmt, ...) \ do { fprintf(stderr, "RTL8139: " fmt, ## __VA_ARGS__); } while (0)
@@ -805,6 +818,21 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high)#endif } +/* Verify that we have at least one available rx buffer */ +static int rtl8139_cp_has_rxbuf (RTL8139State *s) +{ +uint32_t val, rxdw0; +target_phys_addr_t cplus_rx_ring_desc =rtl8139_addr64 (s->RxRingAddrLO, + s->RxRingAddrHI); + cplus_rx_ring_desc +=16 * s->currCPlusRxDesc; +cpu_physical_memory_read (cplus_rx_ring_desc, (uint8_t *)&val,4 ); + rxdw0 =le32_to_cpu (val); +if (rxdw0 &CP_RX_OWN ) +return 1 ; +else +return 0 ; +} +static int rtl8139_can_receive (VLANClientState *nc) {RTL8139State *s =DO_UPCAST (NICState, nc, nc)->opaque;
@@ -819,7 +847,7 @@ static int rtl8139_can_receive(VLANClientState *nc)if (rtl8139_cp_receiver_enabled (s)) {/* ??? Flow control not implemented in c+ mode. This is a hack to work around slirp deficiencies anyway. */ -return 1 ; +return rtl8139_cp_has_rxbuf (s); }else { avail =MOD2 (s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, s->RxBufferSize);
@@ -965,19 +993,6 @@ static ssize_t rtl8139_do_receive(VLANClientState *nc, const uint8_t *buf, size_/* begin C+ receiver mode */ -/* w0 ownership flag */ -#define CP_RX_OWN (1<<31) -/* w0 end of ring flag */ -#define CP_RX_EOR (1<<30) -/* w0 bits 0...12 : buffer size */ -#define CP_RX_BUFFER_SIZE_MASK ((1<<13) - 1) -/* w1 tag available flag */ -#define CP_RX_TAVA (1<<16) -/* w1 bits 0...15 : VLAN tag */ -#define CP_RX_VLAN_TAG_MASK ((1<<16) - 1) -/* w2 low 32bit of Rx buffer ptr */ -/* w3 high 32bit of Rx buffer ptr */ -int descriptor = s->currCPlusRxDesc;target_phys_addr_t cplus_rx_ring_desc;
See my comments below.
Am 14.10.2011 12:49, schrieb Jason Wang:
Quoted 34 lines
Reduce spurious packet drops on RX ring empty when in c+ mode by verifying that we have at least 1 buffer ahead of the time.
Signed-off-by Jason Wang<[email protected]>--- hw/rtl8139.c | 43 +++++++++++++++++++++++++++++-------------- 1 files changed, 29 insertions(+), 14 deletions(-)hw/rtl8139.c +13
-0@@ -84,6 +84,19 @@#define VLAN_TCI_LEN 2#define VLAN_HLEN (ETHER_TYPE_LEN + VLAN_TCI_LEN) +/* w0 ownership flag */ +#define CP_RX_OWN (1<<31) +/* w0 end of ring flag */ +#define CP_RX_EOR (1<<30) +/* w0 bits 0...12 : buffer size */ +#define CP_RX_BUFFER_SIZE_MASK ((1<<13) - 1) +/* w1 tag available flag */ +#define CP_RX_TAVA (1<<16) +/* w1 bits 0...15 : VLAN tag */ +#define CP_RX_VLAN_TAG_MASK ((1<<16) - 1) +/* w2 low 32bit of Rx buffer ptr */ +/* w3 high 32bit of Rx buffer ptr */ +#if defined (DEBUG_RTL8139 )# define DPRINTF (fmt, ...) \ do { fprintf(stderr, "RTL8139: " fmt, ## __VA_ARGS__); } while (0)@@ -805,6 +818,21 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high)#endif
hw/rtl8139.c static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high) · line 828
Quoted 10 lines
hw/rtl8139.c +8
-0} +/* Verify that we have at least one available rx buffer */ +static int rtl8139_cp_has_rxbuf (RTL8139State *s) +{ +uint32_t val, rxdw0; +target_phys_addr_t cplus_rx_ring_desc =rtl8139_addr64 (s->RxRingAddrLO, + s->RxRingAddrHI); + cplus_rx_ring_desc +=16 * s->currCPlusRxDesc; +cpu_physical_memory_read (cplus_rx_ring_desc, (uint8_t *)&val,4 );
The type cast is not needed, please remove it.
hw/rtl8139.c static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high) · line 833
Quoted 5 lines
hw/rtl8139.c +5
-0+ rxdw0 =le32_to_cpu (val); +if (rxdw0&CP_RX_OWN ) +return 1 ; +else +return 0 ;
The QEMU coding conventions require braces here.
Check your patch with scripts/checkpatch.pl.
Regards,
Stefan W.