Commit 4f1c942b7fb29864ad86cb3af9076da38f38f74e
1 parent
e3f5ec2b
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 <markmc@redhat.com>
Showing
18 changed files
with
126 additions
and
95 deletions
hw/dp8393x.c
@@ -725,7 +725,7 @@ static int receive_filter(dp8393xState *s, const uint8_t * buf, int size) | @@ -725,7 +725,7 @@ static int receive_filter(dp8393xState *s, const uint8_t * buf, int size) | ||
725 | return -1; | 725 | return -1; |
726 | } | 726 | } |
727 | 727 | ||
728 | -static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | 728 | +static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) |
729 | { | 729 | { |
730 | uint16_t data[10]; | 730 | uint16_t data[10]; |
731 | dp8393xState *s = vc->opaque; | 731 | dp8393xState *s = vc->opaque; |
@@ -742,7 +742,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | @@ -742,7 +742,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | ||
742 | packet_type = receive_filter(s, buf, size); | 742 | packet_type = receive_filter(s, buf, size); |
743 | if (packet_type < 0) { | 743 | if (packet_type < 0) { |
744 | DPRINTF("packet not for netcard\n"); | 744 | DPRINTF("packet not for netcard\n"); |
745 | - return; | 745 | + return -1; |
746 | } | 746 | } |
747 | 747 | ||
748 | /* XXX: Check byte ordering */ | 748 | /* XXX: Check byte ordering */ |
@@ -755,7 +755,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | @@ -755,7 +755,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | ||
755 | s->memory_rw(s->mem_opaque, address, (uint8_t*)data, size, 0); | 755 | s->memory_rw(s->mem_opaque, address, (uint8_t*)data, size, 0); |
756 | if (data[0 * width] & 0x1) { | 756 | if (data[0 * width] & 0x1) { |
757 | /* Still EOL ; stop reception */ | 757 | /* Still EOL ; stop reception */ |
758 | - return; | 758 | + return -1; |
759 | } else { | 759 | } else { |
760 | s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; | 760 | s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; |
761 | } | 761 | } |
@@ -833,6 +833,8 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | @@ -833,6 +833,8 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | ||
833 | 833 | ||
834 | /* Done */ | 834 | /* Done */ |
835 | dp8393x_update_irq(s); | 835 | dp8393x_update_irq(s); |
836 | + | ||
837 | + return size; | ||
836 | } | 838 | } |
837 | 839 | ||
838 | static void nic_reset(void *opaque) | 840 | static void nic_reset(void *opaque) |
hw/e1000.c
@@ -599,7 +599,7 @@ e1000_can_receive(VLANClientState *vc) | @@ -599,7 +599,7 @@ e1000_can_receive(VLANClientState *vc) | ||
599 | return (s->mac_reg[RCTL] & E1000_RCTL_EN); | 599 | return (s->mac_reg[RCTL] & E1000_RCTL_EN); |
600 | } | 600 | } |
601 | 601 | ||
602 | -static void | 602 | +static ssize_t |
603 | e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 603 | e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
604 | { | 604 | { |
605 | E1000State *s = vc->opaque; | 605 | E1000State *s = vc->opaque; |
@@ -611,16 +611,16 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -611,16 +611,16 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
611 | uint8_t vlan_status = 0, vlan_offset = 0; | 611 | uint8_t vlan_status = 0, vlan_offset = 0; |
612 | 612 | ||
613 | if (!(s->mac_reg[RCTL] & E1000_RCTL_EN)) | 613 | if (!(s->mac_reg[RCTL] & E1000_RCTL_EN)) |
614 | - return; | 614 | + return -1; |
615 | 615 | ||
616 | if (size > s->rxbuf_size) { | 616 | if (size > s->rxbuf_size) { |
617 | DBGOUT(RX, "packet too large for buffers (%lu > %d)\n", | 617 | DBGOUT(RX, "packet too large for buffers (%lu > %d)\n", |
618 | (unsigned long)size, s->rxbuf_size); | 618 | (unsigned long)size, s->rxbuf_size); |
619 | - return; | 619 | + return -1; |
620 | } | 620 | } |
621 | 621 | ||
622 | if (!receive_filter(s, buf, size)) | 622 | if (!receive_filter(s, buf, size)) |
623 | - return; | 623 | + return size; |
624 | 624 | ||
625 | if (vlan_enabled(s) && is_vlan_packet(s, buf)) { | 625 | if (vlan_enabled(s) && is_vlan_packet(s, buf)) { |
626 | vlan_special = cpu_to_le16(be16_to_cpup((uint16_t *)(buf + 14))); | 626 | vlan_special = cpu_to_le16(be16_to_cpup((uint16_t *)(buf + 14))); |
@@ -635,7 +635,7 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -635,7 +635,7 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
635 | do { | 635 | do { |
636 | if (s->mac_reg[RDH] == s->mac_reg[RDT] && s->check_rxov) { | 636 | if (s->mac_reg[RDH] == s->mac_reg[RDT] && s->check_rxov) { |
637 | set_ics(s, 0, E1000_ICS_RXO); | 637 | set_ics(s, 0, E1000_ICS_RXO); |
638 | - return; | 638 | + return -1; |
639 | } | 639 | } |
640 | base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] + | 640 | base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] + |
641 | sizeof(desc) * s->mac_reg[RDH]; | 641 | sizeof(desc) * s->mac_reg[RDH]; |
@@ -659,7 +659,7 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -659,7 +659,7 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
659 | DBGOUT(RXERR, "RDH wraparound @%x, RDT %x, RDLEN %x\n", | 659 | DBGOUT(RXERR, "RDH wraparound @%x, RDT %x, RDLEN %x\n", |
660 | rdh_start, s->mac_reg[RDT], s->mac_reg[RDLEN]); | 660 | rdh_start, s->mac_reg[RDT], s->mac_reg[RDLEN]); |
661 | set_ics(s, 0, E1000_ICS_RXO); | 661 | set_ics(s, 0, E1000_ICS_RXO); |
662 | - return; | 662 | + return -1; |
663 | } | 663 | } |
664 | } while (desc.buffer_addr == 0); | 664 | } while (desc.buffer_addr == 0); |
665 | 665 | ||
@@ -677,6 +677,8 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -677,6 +677,8 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
677 | n |= E1000_ICS_RXDMT0; | 677 | n |= E1000_ICS_RXDMT0; |
678 | 678 | ||
679 | set_ics(s, 0, n); | 679 | set_ics(s, 0, n); |
680 | + | ||
681 | + return size; | ||
680 | } | 682 | } |
681 | 683 | ||
682 | static uint32_t | 684 | static uint32_t |
hw/eepro100.c
@@ -1441,7 +1441,7 @@ static int nic_can_receive(VLANClientState *vc) | @@ -1441,7 +1441,7 @@ static int nic_can_receive(VLANClientState *vc) | ||
1441 | //~ return !eepro100_buffer_full(s); | 1441 | //~ return !eepro100_buffer_full(s); |
1442 | } | 1442 | } |
1443 | 1443 | ||
1444 | -static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | 1444 | +static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) |
1445 | { | 1445 | { |
1446 | /* TODO: | 1446 | /* TODO: |
1447 | * - Magic packets should set bit 30 in power management driver register. | 1447 | * - Magic packets should set bit 30 in power management driver register. |
@@ -1458,18 +1458,18 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | @@ -1458,18 +1458,18 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | ||
1458 | if (s->configuration[8] & 0x80) { | 1458 | if (s->configuration[8] & 0x80) { |
1459 | /* CSMA is disabled. */ | 1459 | /* CSMA is disabled. */ |
1460 | logout("%p received while CSMA is disabled\n", s); | 1460 | logout("%p received while CSMA is disabled\n", s); |
1461 | - return; | 1461 | + return -1; |
1462 | } else if (size < 64 && (s->configuration[7] & 1)) { | 1462 | } else if (size < 64 && (s->configuration[7] & 1)) { |
1463 | /* Short frame and configuration byte 7/0 (discard short receive) set: | 1463 | /* Short frame and configuration byte 7/0 (discard short receive) set: |
1464 | * Short frame is discarded */ | 1464 | * Short frame is discarded */ |
1465 | logout("%p received short frame (%d byte)\n", s, size); | 1465 | logout("%p received short frame (%d byte)\n", s, size); |
1466 | s->statistics.rx_short_frame_errors++; | 1466 | s->statistics.rx_short_frame_errors++; |
1467 | - //~ return; | 1467 | + //~ return -1; |
1468 | } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) { | 1468 | } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) { |
1469 | /* Long frame and configuration byte 18/3 (long receive ok) not set: | 1469 | /* Long frame and configuration byte 18/3 (long receive ok) not set: |
1470 | * Long frames are discarded. */ | 1470 | * Long frames are discarded. */ |
1471 | logout("%p received long frame (%d byte), ignored\n", s, size); | 1471 | logout("%p received long frame (%d byte), ignored\n", s, size); |
1472 | - return; | 1472 | + return -1; |
1473 | } else if (memcmp(buf, s->macaddr, 6) == 0) { // !!! | 1473 | } else if (memcmp(buf, s->macaddr, 6) == 0) { // !!! |
1474 | /* Frame matches individual address. */ | 1474 | /* Frame matches individual address. */ |
1475 | /* TODO: check configuration byte 15/4 (ignore U/L). */ | 1475 | /* TODO: check configuration byte 15/4 (ignore U/L). */ |
@@ -1485,7 +1485,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | @@ -1485,7 +1485,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | ||
1485 | assert(!(s->configuration[21] & BIT(3))); | 1485 | assert(!(s->configuration[21] & BIT(3))); |
1486 | int mcast_idx = compute_mcast_idx(buf); | 1486 | int mcast_idx = compute_mcast_idx(buf); |
1487 | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) { | 1487 | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) { |
1488 | - return; | 1488 | + return size; |
1489 | } | 1489 | } |
1490 | rfd_status |= 0x0002; | 1490 | rfd_status |= 0x0002; |
1491 | } else if (s->configuration[15] & 1) { | 1491 | } else if (s->configuration[15] & 1) { |
@@ -1495,7 +1495,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | @@ -1495,7 +1495,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | ||
1495 | } else { | 1495 | } else { |
1496 | logout("%p received frame, ignored, len=%d,%s\n", s, size, | 1496 | logout("%p received frame, ignored, len=%d,%s\n", s, size, |
1497 | nic_dump(buf, size)); | 1497 | nic_dump(buf, size)); |
1498 | - return; | 1498 | + return size; |
1499 | } | 1499 | } |
1500 | 1500 | ||
1501 | if (get_ru_state(s) != ru_ready) { | 1501 | if (get_ru_state(s) != ru_ready) { |
@@ -1503,7 +1503,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | @@ -1503,7 +1503,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | ||
1503 | logout("no ressources, state=%u\n", get_ru_state(s)); | 1503 | logout("no ressources, state=%u\n", get_ru_state(s)); |
1504 | s->statistics.rx_resource_errors++; | 1504 | s->statistics.rx_resource_errors++; |
1505 | //~ assert(!"no ressources"); | 1505 | //~ assert(!"no ressources"); |
1506 | - return; | 1506 | + return -1; |
1507 | } | 1507 | } |
1508 | //~ !!! | 1508 | //~ !!! |
1509 | //~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}} | 1509 | //~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}} |
@@ -1540,6 +1540,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | @@ -1540,6 +1540,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size) | ||
1540 | /* S bit is set. */ | 1540 | /* S bit is set. */ |
1541 | set_ru_state(s, ru_suspended); | 1541 | set_ru_state(s, ru_suspended); |
1542 | } | 1542 | } |
1543 | + return size; | ||
1543 | } | 1544 | } |
1544 | 1545 | ||
1545 | static int nic_load(QEMUFile * f, void *opaque, int version_id) | 1546 | static int nic_load(QEMUFile * f, void *opaque, int version_id) |
hw/etraxfs_eth.c
@@ -501,7 +501,7 @@ static int eth_can_receive(VLANClientState *vc) | @@ -501,7 +501,7 @@ static int eth_can_receive(VLANClientState *vc) | ||
501 | return 1; | 501 | return 1; |
502 | } | 502 | } |
503 | 503 | ||
504 | -static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 504 | +static ssize_t eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
505 | { | 505 | { |
506 | unsigned char sa_bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 506 | unsigned char sa_bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
507 | struct fs_eth *eth = vc->opaque; | 507 | struct fs_eth *eth = vc->opaque; |
@@ -510,7 +510,7 @@ static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -510,7 +510,7 @@ static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
510 | int r_bcast = eth->regs[RW_REC_CTRL] & 8; | 510 | int r_bcast = eth->regs[RW_REC_CTRL] & 8; |
511 | 511 | ||
512 | if (size < 12) | 512 | if (size < 12) |
513 | - return; | 513 | + return -1; |
514 | 514 | ||
515 | D(printf("%x.%x.%x.%x.%x.%x ma=%d %d bc=%d\n", | 515 | D(printf("%x.%x.%x.%x.%x.%x ma=%d %d bc=%d\n", |
516 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], | 516 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], |
@@ -521,10 +521,12 @@ static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -521,10 +521,12 @@ static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
521 | && (!use_ma1 || memcmp(buf, eth->macaddr[1], 6)) | 521 | && (!use_ma1 || memcmp(buf, eth->macaddr[1], 6)) |
522 | && (!r_bcast || memcmp(buf, sa_bcast, 6)) | 522 | && (!r_bcast || memcmp(buf, sa_bcast, 6)) |
523 | && !eth_match_groupaddr(eth, buf)) | 523 | && !eth_match_groupaddr(eth, buf)) |
524 | - return; | 524 | + return size; |
525 | 525 | ||
526 | /* FIXME: Find another way to pass on the fake csum. */ | 526 | /* FIXME: Find another way to pass on the fake csum. */ |
527 | etraxfs_dmac_input(eth->dma_in, (void *)buf, size + 4, 1); | 527 | etraxfs_dmac_input(eth->dma_in, (void *)buf, size + 4, 1); |
528 | + | ||
529 | + return size; | ||
528 | } | 530 | } |
529 | 531 | ||
530 | static int eth_tx_push(void *opaque, unsigned char *buf, int len) | 532 | static int eth_tx_push(void *opaque, unsigned char *buf, int len) |
hw/mcf_fec.c
@@ -353,7 +353,7 @@ static int mcf_fec_can_receive(VLANClientState *vc) | @@ -353,7 +353,7 @@ static int mcf_fec_can_receive(VLANClientState *vc) | ||
353 | return s->rx_enabled; | 353 | return s->rx_enabled; |
354 | } | 354 | } |
355 | 355 | ||
356 | -static void mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 356 | +static ssize_t mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
357 | { | 357 | { |
358 | mcf_fec_state *s = vc->opaque; | 358 | mcf_fec_state *s = vc->opaque; |
359 | mcf_fec_bd bd; | 359 | mcf_fec_bd bd; |
@@ -426,6 +426,7 @@ static void mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size | @@ -426,6 +426,7 @@ static void mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size | ||
426 | s->rx_descriptor = addr; | 426 | s->rx_descriptor = addr; |
427 | mcf_fec_enable_rx(s); | 427 | mcf_fec_enable_rx(s); |
428 | mcf_fec_update(s); | 428 | mcf_fec_update(s); |
429 | + return size; | ||
429 | } | 430 | } |
430 | 431 | ||
431 | static CPUReadMemoryFunc *mcf_fec_readfn[] = { | 432 | static CPUReadMemoryFunc *mcf_fec_readfn[] = { |
hw/mipsnet.c
@@ -75,7 +75,7 @@ static int mipsnet_can_receive(VLANClientState *vc) | @@ -75,7 +75,7 @@ static int mipsnet_can_receive(VLANClientState *vc) | ||
75 | return !mipsnet_buffer_full(s); | 75 | return !mipsnet_buffer_full(s); |
76 | } | 76 | } |
77 | 77 | ||
78 | -static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 78 | +static ssize_t mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
79 | { | 79 | { |
80 | MIPSnetState *s = vc->opaque; | 80 | MIPSnetState *s = vc->opaque; |
81 | 81 | ||
@@ -83,7 +83,7 @@ static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size | @@ -83,7 +83,7 @@ static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size | ||
83 | printf("mipsnet: receiving len=%d\n", size); | 83 | printf("mipsnet: receiving len=%d\n", size); |
84 | #endif | 84 | #endif |
85 | if (!mipsnet_can_receive(vc)) | 85 | if (!mipsnet_can_receive(vc)) |
86 | - return; | 86 | + return -1; |
87 | 87 | ||
88 | s->busy = 1; | 88 | s->busy = 1; |
89 | 89 | ||
@@ -98,6 +98,8 @@ static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size | @@ -98,6 +98,8 @@ static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size | ||
98 | /* Now we can signal we have received something. */ | 98 | /* Now we can signal we have received something. */ |
99 | s->intctl |= MIPSNET_INTCTL_RXDONE; | 99 | s->intctl |= MIPSNET_INTCTL_RXDONE; |
100 | mipsnet_update_irq(s); | 100 | mipsnet_update_irq(s); |
101 | + | ||
102 | + return size; | ||
101 | } | 103 | } |
102 | 104 | ||
103 | static uint32_t mipsnet_ioport_read(void *opaque, uint32_t addr) | 105 | static uint32_t mipsnet_ioport_read(void *opaque, uint32_t addr) |
hw/musicpal.c
@@ -562,7 +562,7 @@ static int eth_can_receive(VLANClientState *vc) | @@ -562,7 +562,7 @@ static int eth_can_receive(VLANClientState *vc) | ||
562 | return 1; | 562 | return 1; |
563 | } | 563 | } |
564 | 564 | ||
565 | -static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 565 | +static ssize_t eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
566 | { | 566 | { |
567 | mv88w8618_eth_state *s = vc->opaque; | 567 | mv88w8618_eth_state *s = vc->opaque; |
568 | uint32_t desc_addr; | 568 | uint32_t desc_addr; |
@@ -586,11 +586,12 @@ static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -586,11 +586,12 @@ static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
586 | if (s->icr & s->imr) | 586 | if (s->icr & s->imr) |
587 | qemu_irq_raise(s->irq); | 587 | qemu_irq_raise(s->irq); |
588 | eth_rx_desc_put(desc_addr, &desc); | 588 | eth_rx_desc_put(desc_addr, &desc); |
589 | - return; | 589 | + return size; |
590 | } | 590 | } |
591 | desc_addr = desc.next; | 591 | desc_addr = desc.next; |
592 | } while (desc_addr != s->rx_queue[i]); | 592 | } while (desc_addr != s->rx_queue[i]); |
593 | } | 593 | } |
594 | + return size; | ||
594 | } | 595 | } |
595 | 596 | ||
596 | static void eth_tx_desc_put(uint32_t addr, mv88w8618_tx_desc *desc) | 597 | static void eth_tx_desc_put(uint32_t addr, mv88w8618_tx_desc *desc) |
hw/ne2000.c
@@ -224,9 +224,10 @@ static int ne2000_can_receive(VLANClientState *vc) | @@ -224,9 +224,10 @@ static int ne2000_can_receive(VLANClientState *vc) | ||
224 | 224 | ||
225 | #define MIN_BUF_SIZE 60 | 225 | #define MIN_BUF_SIZE 60 |
226 | 226 | ||
227 | -static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 227 | +static ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_) |
228 | { | 228 | { |
229 | NE2000State *s = vc->opaque; | 229 | NE2000State *s = vc->opaque; |
230 | + int size = size_; | ||
230 | uint8_t *p; | 231 | uint8_t *p; |
231 | unsigned int total_len, next, avail, len, index, mcast_idx; | 232 | unsigned int total_len, next, avail, len, index, mcast_idx; |
232 | uint8_t buf1[60]; | 233 | uint8_t buf1[60]; |
@@ -238,7 +239,7 @@ static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -238,7 +239,7 @@ static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
238 | #endif | 239 | #endif |
239 | 240 | ||
240 | if (s->cmd & E8390_STOP || ne2000_buffer_full(s)) | 241 | if (s->cmd & E8390_STOP || ne2000_buffer_full(s)) |
241 | - return; | 242 | + return -1; |
242 | 243 | ||
243 | /* XXX: check this */ | 244 | /* XXX: check this */ |
244 | if (s->rxcr & 0x10) { | 245 | if (s->rxcr & 0x10) { |
@@ -247,14 +248,14 @@ static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -247,14 +248,14 @@ static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
247 | if (!memcmp(buf, broadcast_macaddr, 6)) { | 248 | if (!memcmp(buf, broadcast_macaddr, 6)) { |
248 | /* broadcast address */ | 249 | /* broadcast address */ |
249 | if (!(s->rxcr & 0x04)) | 250 | if (!(s->rxcr & 0x04)) |
250 | - return; | 251 | + return size; |
251 | } else if (buf[0] & 0x01) { | 252 | } else if (buf[0] & 0x01) { |
252 | /* multicast */ | 253 | /* multicast */ |
253 | if (!(s->rxcr & 0x08)) | 254 | if (!(s->rxcr & 0x08)) |
254 | - return; | 255 | + return size; |
255 | mcast_idx = compute_mcast_idx(buf); | 256 | mcast_idx = compute_mcast_idx(buf); |
256 | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) | 257 | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) |
257 | - return; | 258 | + return size; |
258 | } else if (s->mem[0] == buf[0] && | 259 | } else if (s->mem[0] == buf[0] && |
259 | s->mem[2] == buf[1] && | 260 | s->mem[2] == buf[1] && |
260 | s->mem[4] == buf[2] && | 261 | s->mem[4] == buf[2] && |
@@ -263,7 +264,7 @@ static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -263,7 +264,7 @@ static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
263 | s->mem[10] == buf[5]) { | 264 | s->mem[10] == buf[5]) { |
264 | /* match */ | 265 | /* match */ |
265 | } else { | 266 | } else { |
266 | - return; | 267 | + return size; |
267 | } | 268 | } |
268 | } | 269 | } |
269 | 270 | ||
@@ -316,6 +317,8 @@ static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -316,6 +317,8 @@ static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
316 | /* now we can signal we have received something */ | 317 | /* now we can signal we have received something */ |
317 | s->isr |= ENISR_RX; | 318 | s->isr |= ENISR_RX; |
318 | ne2000_update_irq(s); | 319 | ne2000_update_irq(s); |
320 | + | ||
321 | + return size_; | ||
319 | } | 322 | } |
320 | 323 | ||
321 | static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val) | 324 | static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
hw/pcnet.c
@@ -1076,16 +1076,17 @@ static int pcnet_can_receive(VLANClientState *vc) | @@ -1076,16 +1076,17 @@ static int pcnet_can_receive(VLANClientState *vc) | ||
1076 | 1076 | ||
1077 | #define MIN_BUF_SIZE 60 | 1077 | #define MIN_BUF_SIZE 60 |
1078 | 1078 | ||
1079 | -static void pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 1079 | +static ssize_t pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size_) |
1080 | { | 1080 | { |
1081 | PCNetState *s = vc->opaque; | 1081 | PCNetState *s = vc->opaque; |
1082 | int is_padr = 0, is_bcast = 0, is_ladr = 0; | 1082 | int is_padr = 0, is_bcast = 0, is_ladr = 0; |
1083 | uint8_t buf1[60]; | 1083 | uint8_t buf1[60]; |
1084 | int remaining; | 1084 | int remaining; |
1085 | int crc_err = 0; | 1085 | int crc_err = 0; |
1086 | + int size = size_; | ||
1086 | 1087 | ||
1087 | if (CSR_DRX(s) || CSR_STOP(s) || CSR_SPND(s) || !size) | 1088 | if (CSR_DRX(s) || CSR_STOP(s) || CSR_SPND(s) || !size) |
1088 | - return; | 1089 | + return -1; |
1089 | 1090 | ||
1090 | #ifdef PCNET_DEBUG | 1091 | #ifdef PCNET_DEBUG |
1091 | printf("pcnet_receive size=%d\n", size); | 1092 | printf("pcnet_receive size=%d\n", size); |
@@ -1252,6 +1253,8 @@ static void pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -1252,6 +1253,8 @@ static void pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
1252 | 1253 | ||
1253 | pcnet_poll(s); | 1254 | pcnet_poll(s); |
1254 | pcnet_update_irq(s); | 1255 | pcnet_update_irq(s); |
1256 | + | ||
1257 | + return size_; | ||
1255 | } | 1258 | } |
1256 | 1259 | ||
1257 | static void pcnet_transmit(PCNetState *s) | 1260 | static void pcnet_transmit(PCNetState *s) |
hw/rtl8139.c
@@ -812,9 +812,10 @@ static int rtl8139_can_receive(VLANClientState *vc) | @@ -812,9 +812,10 @@ static int rtl8139_can_receive(VLANClientState *vc) | ||
812 | } | 812 | } |
813 | } | 813 | } |
814 | 814 | ||
815 | -static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size, int do_interrupt) | 815 | +static ssize_t rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, size_t size_, int do_interrupt) |
816 | { | 816 | { |
817 | RTL8139State *s = vc->opaque; | 817 | RTL8139State *s = vc->opaque; |
818 | + int size = size_; | ||
818 | 819 | ||
819 | uint32_t packet_header = 0; | 820 | uint32_t packet_header = 0; |
820 | 821 | ||
@@ -828,7 +829,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -828,7 +829,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
828 | if (!s->clock_enabled) | 829 | if (!s->clock_enabled) |
829 | { | 830 | { |
830 | DEBUG_PRINT(("RTL8139: stopped ==========================\n")); | 831 | DEBUG_PRINT(("RTL8139: stopped ==========================\n")); |
831 | - return; | 832 | + return -1; |
832 | } | 833 | } |
833 | 834 | ||
834 | /* first check if receiver is enabled */ | 835 | /* first check if receiver is enabled */ |
@@ -836,7 +837,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -836,7 +837,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
836 | if (!rtl8139_receiver_enabled(s)) | 837 | if (!rtl8139_receiver_enabled(s)) |
837 | { | 838 | { |
838 | DEBUG_PRINT(("RTL8139: receiver disabled ================\n")); | 839 | DEBUG_PRINT(("RTL8139: receiver disabled ================\n")); |
839 | - return; | 840 | + return -1; |
840 | } | 841 | } |
841 | 842 | ||
842 | /* XXX: check this */ | 843 | /* XXX: check this */ |
@@ -854,7 +855,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -854,7 +855,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
854 | /* update tally counter */ | 855 | /* update tally counter */ |
855 | ++s->tally_counters.RxERR; | 856 | ++s->tally_counters.RxERR; |
856 | 857 | ||
857 | - return; | 858 | + return size; |
858 | } | 859 | } |
859 | 860 | ||
860 | packet_header |= RxBroadcast; | 861 | packet_header |= RxBroadcast; |
@@ -873,7 +874,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -873,7 +874,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
873 | /* update tally counter */ | 874 | /* update tally counter */ |
874 | ++s->tally_counters.RxERR; | 875 | ++s->tally_counters.RxERR; |
875 | 876 | ||
876 | - return; | 877 | + return size; |
877 | } | 878 | } |
878 | 879 | ||
879 | int mcast_idx = compute_mcast_idx(buf); | 880 | int mcast_idx = compute_mcast_idx(buf); |
@@ -885,7 +886,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -885,7 +886,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
885 | /* update tally counter */ | 886 | /* update tally counter */ |
886 | ++s->tally_counters.RxERR; | 887 | ++s->tally_counters.RxERR; |
887 | 888 | ||
888 | - return; | 889 | + return size; |
889 | } | 890 | } |
890 | 891 | ||
891 | packet_header |= RxMulticast; | 892 | packet_header |= RxMulticast; |
@@ -909,7 +910,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -909,7 +910,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
909 | /* update tally counter */ | 910 | /* update tally counter */ |
910 | ++s->tally_counters.RxERR; | 911 | ++s->tally_counters.RxERR; |
911 | 912 | ||
912 | - return; | 913 | + return size; |
913 | } | 914 | } |
914 | 915 | ||
915 | packet_header |= RxPhysical; | 916 | packet_header |= RxPhysical; |
@@ -926,7 +927,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -926,7 +927,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
926 | /* update tally counter */ | 927 | /* update tally counter */ |
927 | ++s->tally_counters.RxERR; | 928 | ++s->tally_counters.RxERR; |
928 | 929 | ||
929 | - return; | 930 | + return size; |
930 | } | 931 | } |
931 | } | 932 | } |
932 | 933 | ||
@@ -993,7 +994,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -993,7 +994,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
993 | ++s->tally_counters.MissPkt; | 994 | ++s->tally_counters.MissPkt; |
994 | 995 | ||
995 | rtl8139_update_irq(s); | 996 | rtl8139_update_irq(s); |
996 | - return; | 997 | + return size_; |
997 | } | 998 | } |
998 | 999 | ||
999 | uint32_t rx_space = rxdw0 & CP_RX_BUFFER_SIZE_MASK; | 1000 | 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 | @@ -1013,7 +1014,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
1013 | ++s->tally_counters.MissPkt; | 1014 | ++s->tally_counters.MissPkt; |
1014 | 1015 | ||
1015 | rtl8139_update_irq(s); | 1016 | rtl8139_update_irq(s); |
1016 | - return; | 1017 | + return size_; |
1017 | } | 1018 | } |
1018 | 1019 | ||
1019 | target_phys_addr_t rx_addr = rtl8139_addr64(rxbufLO, rxbufHI); | 1020 | 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 | @@ -1118,7 +1119,7 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
1118 | s->IntrStatus |= RxOverflow; | 1119 | s->IntrStatus |= RxOverflow; |
1119 | ++s->RxMissed; | 1120 | ++s->RxMissed; |
1120 | rtl8139_update_irq(s); | 1121 | rtl8139_update_irq(s); |
1121 | - return; | 1122 | + return size_; |
1122 | } | 1123 | } |
1123 | 1124 | ||
1124 | packet_header |= RxStatusOK; | 1125 | packet_header |= RxStatusOK; |
@@ -1156,11 +1157,13 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | @@ -1156,11 +1157,13 @@ static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size | ||
1156 | { | 1157 | { |
1157 | rtl8139_update_irq(s); | 1158 | rtl8139_update_irq(s); |
1158 | } | 1159 | } |
1160 | + | ||
1161 | + return size_; | ||
1159 | } | 1162 | } |
1160 | 1163 | ||
1161 | -static void rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 1164 | +static ssize_t rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
1162 | { | 1165 | { |
1163 | - rtl8139_do_receive(vc, buf, size, 1); | 1166 | + return rtl8139_do_receive(vc, buf, size, 1); |
1164 | } | 1167 | } |
1165 | 1168 | ||
1166 | static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) | 1169 | static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) |
hw/smc91c111.c
@@ -602,7 +602,7 @@ static int smc91c111_can_receive(VLANClientState *vc) | @@ -602,7 +602,7 @@ static int smc91c111_can_receive(VLANClientState *vc) | ||
602 | return 1; | 602 | return 1; |
603 | } | 603 | } |
604 | 604 | ||
605 | -static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 605 | +static ssize_t smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
606 | { | 606 | { |
607 | smc91c111_state *s = vc->opaque; | 607 | smc91c111_state *s = vc->opaque; |
608 | int status; | 608 | int status; |
@@ -612,7 +612,7 @@ static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t si | @@ -612,7 +612,7 @@ static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t si | ||
612 | uint8_t *p; | 612 | uint8_t *p; |
613 | 613 | ||
614 | if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST)) | 614 | if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST)) |
615 | - return; | 615 | + return -1; |
616 | /* Short packets are padded with zeros. Receiving a packet | 616 | /* Short packets are padded with zeros. Receiving a packet |
617 | < 64 bytes long is considered an error condition. */ | 617 | < 64 bytes long is considered an error condition. */ |
618 | if (size < 64) | 618 | if (size < 64) |
@@ -625,10 +625,10 @@ static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t si | @@ -625,10 +625,10 @@ static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t si | ||
625 | packetsize += 4; | 625 | packetsize += 4; |
626 | /* TODO: Flag overrun and receive errors. */ | 626 | /* TODO: Flag overrun and receive errors. */ |
627 | if (packetsize > 2048) | 627 | if (packetsize > 2048) |
628 | - return; | 628 | + return -1; |
629 | packetnum = smc91c111_allocate_packet(s); | 629 | packetnum = smc91c111_allocate_packet(s); |
630 | if (packetnum == 0x80) | 630 | if (packetnum == 0x80) |
631 | - return; | 631 | + return -1; |
632 | s->rx_fifo[s->rx_fifo_len++] = packetnum; | 632 | s->rx_fifo[s->rx_fifo_len++] = packetnum; |
633 | 633 | ||
634 | p = &s->data[packetnum][0]; | 634 | p = &s->data[packetnum][0]; |
@@ -676,6 +676,8 @@ static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t si | @@ -676,6 +676,8 @@ static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t si | ||
676 | /* TODO: Raise early RX interrupt? */ | 676 | /* TODO: Raise early RX interrupt? */ |
677 | s->int_level |= INT_RCV; | 677 | s->int_level |= INT_RCV; |
678 | smc91c111_update(s); | 678 | smc91c111_update(s); |
679 | + | ||
680 | + return size; | ||
679 | } | 681 | } |
680 | 682 | ||
681 | static CPUReadMemoryFunc *smc91c111_readfn[] = { | 683 | static CPUReadMemoryFunc *smc91c111_readfn[] = { |
hw/stellaris_enet.c
@@ -78,7 +78,7 @@ static void stellaris_enet_update(stellaris_enet_state *s) | @@ -78,7 +78,7 @@ static void stellaris_enet_update(stellaris_enet_state *s) | ||
78 | } | 78 | } |
79 | 79 | ||
80 | /* TODO: Implement MAC address filtering. */ | 80 | /* TODO: Implement MAC address filtering. */ |
81 | -static void stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 81 | +static ssize_t stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
82 | { | 82 | { |
83 | stellaris_enet_state *s = vc->opaque; | 83 | stellaris_enet_state *s = vc->opaque; |
84 | int n; | 84 | int n; |
@@ -86,10 +86,10 @@ static void stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size | @@ -86,10 +86,10 @@ static void stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size | ||
86 | uint32_t crc; | 86 | uint32_t crc; |
87 | 87 | ||
88 | if ((s->rctl & SE_RCTL_RXEN) == 0) | 88 | if ((s->rctl & SE_RCTL_RXEN) == 0) |
89 | - return; | 89 | + return -1; |
90 | if (s->np >= 31) { | 90 | if (s->np >= 31) { |
91 | DPRINTF("Packet dropped\n"); | 91 | DPRINTF("Packet dropped\n"); |
92 | - return; | 92 | + return -1; |
93 | } | 93 | } |
94 | 94 | ||
95 | DPRINTF("Received packet len=%d\n", size); | 95 | DPRINTF("Received packet len=%d\n", size); |
@@ -116,6 +116,8 @@ static void stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size | @@ -116,6 +116,8 @@ static void stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size | ||
116 | 116 | ||
117 | s->ris |= SE_INT_RX; | 117 | s->ris |= SE_INT_RX; |
118 | stellaris_enet_update(s); | 118 | stellaris_enet_update(s); |
119 | + | ||
120 | + return size; | ||
119 | } | 121 | } |
120 | 122 | ||
121 | static int stellaris_enet_can_receive(VLANClientState *vc) | 123 | static int stellaris_enet_can_receive(VLANClientState *vc) |
hw/usb-net.c
@@ -1369,7 +1369,7 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p) | @@ -1369,7 +1369,7 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p) | ||
1369 | return ret; | 1369 | return ret; |
1370 | } | 1370 | } |
1371 | 1371 | ||
1372 | -static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 1372 | +static ssize_t usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
1373 | { | 1373 | { |
1374 | USBNetState *s = vc->opaque; | 1374 | USBNetState *s = vc->opaque; |
1375 | struct rndis_packet_msg_type *msg; | 1375 | struct rndis_packet_msg_type *msg; |
@@ -1377,9 +1377,9 @@ static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -1377,9 +1377,9 @@ static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
1377 | if (s->rndis) { | 1377 | if (s->rndis) { |
1378 | msg = (struct rndis_packet_msg_type *) s->in_buf; | 1378 | msg = (struct rndis_packet_msg_type *) s->in_buf; |
1379 | if (!s->rndis_state == RNDIS_DATA_INITIALIZED) | 1379 | if (!s->rndis_state == RNDIS_DATA_INITIALIZED) |
1380 | - return; | 1380 | + return -1; |
1381 | if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf)) | 1381 | if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf)) |
1382 | - return; | 1382 | + return -1; |
1383 | 1383 | ||
1384 | memset(msg, 0, sizeof(struct rndis_packet_msg_type)); | 1384 | memset(msg, 0, sizeof(struct rndis_packet_msg_type)); |
1385 | msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG); | 1385 | msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG); |
@@ -1398,11 +1398,12 @@ static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -1398,11 +1398,12 @@ static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
1398 | s->in_len = size + sizeof(struct rndis_packet_msg_type); | 1398 | s->in_len = size + sizeof(struct rndis_packet_msg_type); |
1399 | } else { | 1399 | } else { |
1400 | if (size > sizeof(s->in_buf)) | 1400 | if (size > sizeof(s->in_buf)) |
1401 | - return; | 1401 | + return -1; |
1402 | memcpy(s->in_buf, buf, size); | 1402 | memcpy(s->in_buf, buf, size); |
1403 | s->in_len = size; | 1403 | s->in_len = size; |
1404 | } | 1404 | } |
1405 | s->in_ptr = 0; | 1405 | s->in_ptr = 0; |
1406 | + return size; | ||
1406 | } | 1407 | } |
1407 | 1408 | ||
1408 | static int usbnet_can_receive(VLANClientState *vc) | 1409 | static int usbnet_can_receive(VLANClientState *vc) |
hw/virtio-net.c
@@ -361,17 +361,17 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) | @@ -361,17 +361,17 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) | ||
361 | return 0; | 361 | return 0; |
362 | } | 362 | } |
363 | 363 | ||
364 | -static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 364 | +static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
365 | { | 365 | { |
366 | VirtIONet *n = vc->opaque; | 366 | VirtIONet *n = vc->opaque; |
367 | struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL; | 367 | struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL; |
368 | size_t hdr_len, offset, i; | 368 | size_t hdr_len, offset, i; |
369 | 369 | ||
370 | if (!do_virtio_net_can_receive(n, size)) | 370 | if (!do_virtio_net_can_receive(n, size)) |
371 | - return; | 371 | + return -1; |
372 | 372 | ||
373 | if (!receive_filter(n, buf, size)) | 373 | if (!receive_filter(n, buf, size)) |
374 | - return; | 374 | + return size; |
375 | 375 | ||
376 | /* hdr_len refers to the header we supply to the guest */ | 376 | /* hdr_len refers to the header we supply to the guest */ |
377 | hdr_len = n->mergeable_rx_bufs ? | 377 | hdr_len = n->mergeable_rx_bufs ? |
@@ -389,7 +389,7 @@ static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t s | @@ -389,7 +389,7 @@ static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t s | ||
389 | if ((i != 0 && !n->mergeable_rx_bufs) || | 389 | if ((i != 0 && !n->mergeable_rx_bufs) || |
390 | virtqueue_pop(n->rx_vq, &elem) == 0) { | 390 | virtqueue_pop(n->rx_vq, &elem) == 0) { |
391 | if (i == 0) | 391 | if (i == 0) |
392 | - return; | 392 | + return -1; |
393 | fprintf(stderr, "virtio-net truncating packet\n"); | 393 | fprintf(stderr, "virtio-net truncating packet\n"); |
394 | exit(1); | 394 | exit(1); |
395 | } | 395 | } |
@@ -431,6 +431,8 @@ static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t s | @@ -431,6 +431,8 @@ static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t s | ||
431 | 431 | ||
432 | virtqueue_flush(n->rx_vq, i); | 432 | virtqueue_flush(n->rx_vq, i); |
433 | virtio_notify(&n->vdev, n->rx_vq); | 433 | virtio_notify(&n->vdev, n->rx_vq); |
434 | + | ||
435 | + return size; | ||
434 | } | 436 | } |
435 | 437 | ||
436 | /* TX */ | 438 | /* TX */ |
hw/xen_nic.c
@@ -243,7 +243,7 @@ static int net_rx_ok(VLANClientState *vc) | @@ -243,7 +243,7 @@ static int net_rx_ok(VLANClientState *vc) | ||
243 | return 1; | 243 | return 1; |
244 | } | 244 | } |
245 | 245 | ||
246 | -static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) | 246 | +static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) |
247 | { | 247 | { |
248 | struct XenNetDev *netdev = vc->opaque; | 248 | struct XenNetDev *netdev = vc->opaque; |
249 | netif_rx_request_t rxreq; | 249 | netif_rx_request_t rxreq; |
@@ -251,7 +251,7 @@ static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -251,7 +251,7 @@ static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
251 | void *page; | 251 | void *page; |
252 | 252 | ||
253 | if (netdev->xendev.be_state != XenbusStateConnected) | 253 | if (netdev->xendev.be_state != XenbusStateConnected) |
254 | - return; | 254 | + return -1; |
255 | 255 | ||
256 | rc = netdev->rx_ring.req_cons; | 256 | rc = netdev->rx_ring.req_cons; |
257 | rp = netdev->rx_ring.sring->req_prod; | 257 | rp = netdev->rx_ring.sring->req_prod; |
@@ -259,12 +259,12 @@ static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -259,12 +259,12 @@ static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
259 | 259 | ||
260 | if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) { | 260 | if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) { |
261 | xen_be_printf(&netdev->xendev, 2, "no buffer, drop packet\n"); | 261 | xen_be_printf(&netdev->xendev, 2, "no buffer, drop packet\n"); |
262 | - return; | 262 | + return -1; |
263 | } | 263 | } |
264 | if (size > XC_PAGE_SIZE - NET_IP_ALIGN) { | 264 | if (size > XC_PAGE_SIZE - NET_IP_ALIGN) { |
265 | xen_be_printf(&netdev->xendev, 0, "packet too big (%lu > %ld)", | 265 | xen_be_printf(&netdev->xendev, 0, "packet too big (%lu > %ld)", |
266 | (unsigned long)size, XC_PAGE_SIZE - NET_IP_ALIGN); | 266 | (unsigned long)size, XC_PAGE_SIZE - NET_IP_ALIGN); |
267 | - return; | 267 | + return -1; |
268 | } | 268 | } |
269 | 269 | ||
270 | memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq)); | 270 | memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq)); |
@@ -277,11 +277,13 @@ static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -277,11 +277,13 @@ static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
277 | xen_be_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n", | 277 | xen_be_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n", |
278 | rxreq.gref); | 278 | rxreq.gref); |
279 | net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0); | 279 | net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0); |
280 | - return; | 280 | + return -1; |
281 | } | 281 | } |
282 | memcpy(page + NET_IP_ALIGN, buf, size); | 282 | memcpy(page + NET_IP_ALIGN, buf, size); |
283 | xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1); | 283 | xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1); |
284 | net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0); | 284 | net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0); |
285 | + | ||
286 | + return size; | ||
285 | } | 287 | } |
286 | 288 | ||
287 | /* ------------------------------------------------------------- */ | 289 | /* ------------------------------------------------------------- */ |
net.c
@@ -593,13 +593,14 @@ int slirp_is_inited(void) | @@ -593,13 +593,14 @@ int slirp_is_inited(void) | ||
593 | return slirp_inited; | 593 | return slirp_inited; |
594 | } | 594 | } |
595 | 595 | ||
596 | -static void slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 596 | +static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
597 | { | 597 | { |
598 | #ifdef DEBUG_SLIRP | 598 | #ifdef DEBUG_SLIRP |
599 | printf("slirp input:\n"); | 599 | printf("slirp input:\n"); |
600 | hex_dump(stdout, buf, size); | 600 | hex_dump(stdout, buf, size); |
601 | #endif | 601 | #endif |
602 | slirp_input(buf, size); | 602 | slirp_input(buf, size); |
603 | + return size; | ||
603 | } | 604 | } |
604 | 605 | ||
605 | static int slirp_in_use; | 606 | static int slirp_in_use; |
@@ -945,17 +946,16 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, | @@ -945,17 +946,16 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, | ||
945 | return len; | 946 | return len; |
946 | } | 947 | } |
947 | 948 | ||
948 | -static void tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 949 | +static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
949 | { | 950 | { |
950 | TAPState *s = vc->opaque; | 951 | TAPState *s = vc->opaque; |
951 | - int ret; | ||
952 | - for(;;) { | ||
953 | - ret = write(s->fd, buf, size); | ||
954 | - if (ret < 0 && (errno == EINTR || errno == EAGAIN)) { | ||
955 | - } else { | ||
956 | - break; | ||
957 | - } | ||
958 | - } | 952 | + ssize_t len; |
953 | + | ||
954 | + do { | ||
955 | + len = write(s->fd, buf, size); | ||
956 | + } while (len == -1 && (errno == EINTR || errno == EAGAIN)); | ||
957 | + | ||
958 | + return len; | ||
959 | } | 959 | } |
960 | 960 | ||
961 | static int tap_can_send(void *opaque) | 961 | static int tap_can_send(void *opaque) |
@@ -1311,17 +1311,16 @@ static void vde_to_qemu(void *opaque) | @@ -1311,17 +1311,16 @@ static void vde_to_qemu(void *opaque) | ||
1311 | } | 1311 | } |
1312 | } | 1312 | } |
1313 | 1313 | ||
1314 | -static void vde_receive(VLANClientState *vc, const uint8_t *buf, int size) | 1314 | +static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
1315 | { | 1315 | { |
1316 | VDEState *s = vc->opaque; | 1316 | VDEState *s = vc->opaque; |
1317 | - int ret; | ||
1318 | - for(;;) { | ||
1319 | - ret = vde_send(s->vde, (const char *)buf, size, 0); | ||
1320 | - if (ret < 0 && errno == EINTR) { | ||
1321 | - } else { | ||
1322 | - break; | ||
1323 | - } | ||
1324 | - } | 1317 | + ssize ret; |
1318 | + | ||
1319 | + do { | ||
1320 | + ret = vde_send(s->vde, (const char *)buf, size, 0); | ||
1321 | + } while (ret < 0 && errno == EINTR); | ||
1322 | + | ||
1323 | + return ret; | ||
1325 | } | 1324 | } |
1326 | 1325 | ||
1327 | static void vde_cleanup(VLANClientState *vc) | 1326 | static void vde_cleanup(VLANClientState *vc) |
@@ -1380,21 +1379,22 @@ typedef struct NetSocketListenState { | @@ -1380,21 +1379,22 @@ typedef struct NetSocketListenState { | ||
1380 | } NetSocketListenState; | 1379 | } NetSocketListenState; |
1381 | 1380 | ||
1382 | /* XXX: we consider we can send the whole packet without blocking */ | 1381 | /* XXX: we consider we can send the whole packet without blocking */ |
1383 | -static void net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 1382 | +static ssize_t net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
1384 | { | 1383 | { |
1385 | NetSocketState *s = vc->opaque; | 1384 | NetSocketState *s = vc->opaque; |
1386 | uint32_t len; | 1385 | uint32_t len; |
1387 | len = htonl(size); | 1386 | len = htonl(size); |
1388 | 1387 | ||
1389 | send_all(s->fd, (const uint8_t *)&len, sizeof(len)); | 1388 | send_all(s->fd, (const uint8_t *)&len, sizeof(len)); |
1390 | - send_all(s->fd, buf, size); | 1389 | + return send_all(s->fd, buf, size); |
1391 | } | 1390 | } |
1392 | 1391 | ||
1393 | -static void net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size) | 1392 | +static ssize_t net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size) |
1394 | { | 1393 | { |
1395 | NetSocketState *s = vc->opaque; | 1394 | NetSocketState *s = vc->opaque; |
1396 | - sendto(s->fd, buf, size, 0, | ||
1397 | - (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst)); | 1395 | + |
1396 | + return sendto(s->fd, buf, size, 0, | ||
1397 | + (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst)); | ||
1398 | } | 1398 | } |
1399 | 1399 | ||
1400 | static void net_socket_send(void *opaque) | 1400 | static void net_socket_send(void *opaque) |
@@ -1831,7 +1831,7 @@ struct pcap_sf_pkthdr { | @@ -1831,7 +1831,7 @@ struct pcap_sf_pkthdr { | ||
1831 | uint32_t len; | 1831 | uint32_t len; |
1832 | }; | 1832 | }; |
1833 | 1833 | ||
1834 | -static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 1834 | +static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
1835 | { | 1835 | { |
1836 | DumpState *s = vc->opaque; | 1836 | DumpState *s = vc->opaque; |
1837 | struct pcap_sf_pkthdr hdr; | 1837 | struct pcap_sf_pkthdr hdr; |
@@ -1840,7 +1840,7 @@ static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -1840,7 +1840,7 @@ static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
1840 | 1840 | ||
1841 | /* Early return in case of previous error. */ | 1841 | /* Early return in case of previous error. */ |
1842 | if (s->fd < 0) { | 1842 | if (s->fd < 0) { |
1843 | - return; | 1843 | + return size; |
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | ts = muldiv64(qemu_get_clock(vm_clock), 1000000, ticks_per_sec); | 1846 | ts = muldiv64(qemu_get_clock(vm_clock), 1000000, ticks_per_sec); |
@@ -1856,6 +1856,8 @@ static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | @@ -1856,6 +1856,8 @@ static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | ||
1856 | close(s->fd); | 1856 | close(s->fd); |
1857 | s->fd = -1; | 1857 | s->fd = -1; |
1858 | } | 1858 | } |
1859 | + | ||
1860 | + return size; | ||
1859 | } | 1861 | } |
1860 | 1862 | ||
1861 | static void net_dump_cleanup(VLANClientState *vc) | 1863 | static void net_dump_cleanup(VLANClientState *vc) |
net.h
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | typedef struct VLANClientState VLANClientState; | 8 | typedef struct VLANClientState VLANClientState; |
9 | 9 | ||
10 | typedef int (NetCanReceive)(VLANClientState *); | 10 | typedef int (NetCanReceive)(VLANClientState *); |
11 | -typedef void (NetReceive)(VLANClientState *, const uint8_t *, size_t); | 11 | +typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t); |
12 | typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int); | 12 | typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int); |
13 | typedef void (NetCleanup) (VLANClientState *); | 13 | typedef void (NetCleanup) (VLANClientState *); |
14 | typedef void (LinkStatusChanged)(VLANClientState *); | 14 | typedef void (LinkStatusChanged)(VLANClientState *); |
tap-win32.c
@@ -650,11 +650,11 @@ static void tap_cleanup(VLANClientState *vc) | @@ -650,11 +650,11 @@ static void tap_cleanup(VLANClientState *vc) | ||
650 | qemu_free(s); | 650 | qemu_free(s); |
651 | } | 651 | } |
652 | 652 | ||
653 | -static void tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) | 653 | +static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
654 | { | 654 | { |
655 | - TAPState *s = opaque; | 655 | + TAPState *s = vc->opaque; |
656 | 656 | ||
657 | - tap_win32_write(s->handle, buf, size); | 657 | + return tap_win32_write(s->handle, buf, size); |
658 | } | 658 | } |
659 | 659 | ||
660 | static void tap_win32_send(void *opaque) | 660 | static void tap_win32_send(void *opaque) |