~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to hw/ne2000.c

  • Committer: Bazaar Package Importer
  • Author(s): Riku Voipio, Josh Triplett, Riku Voipio
  • Date: 2009-07-29 13:28:05 UTC
  • mfrom: (1.4.1 upstream)
  • mto: (12.1.1 sid) (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20090729132805-cau7rfexh7dawyb8
Tags: 0.10.50+git20090729-1
[ Josh Triplett ]
* Remove myself from Uploaders.

[ Riku Voipio ]
* new upstream RC version
* nuke all linux-user patches (applied upstream)
  06_exit_segfault
  12_signal_powerpc_support
  21_net_soopts
  30_syscall_ipc
  32_syscall_sysctl
  35_syscall_sockaddr
  48_signal_terminate
  55_unmux_socketcall
* nuke all other applied-upstream patches
  01_nostrip (better version upstream)
  07_i386_exec_name (can be reintroduced in debian/rules)
  50_linuxbios_isa_bios_ram (shouldn't be needed anymore)
  51_linuxbios_piix_ram_size (applied)
  56_dhcp (crap)
  60_ppc_ld (reintroduce if needed)
  64_ppc_asm_constraints (ditto)
  66_tls_ld.patch (ditto)
  81_compile_dtb.patch (applied upstream)
  82_qemu-img_decimal (ditto)
* move to git
* simplify build rules
* Correct my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
213
213
    return 0;
214
214
}
215
215
 
216
 
static int ne2000_can_receive(void *opaque)
 
216
static int ne2000_can_receive(VLANClientState *vc)
217
217
{
218
 
    NE2000State *s = opaque;
 
218
    NE2000State *s = vc->opaque;
219
219
 
220
220
    if (s->cmd & E8390_STOP)
221
221
        return 1;
224
224
 
225
225
#define MIN_BUF_SIZE 60
226
226
 
227
 
static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
 
227
static ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
228
228
{
229
 
    NE2000State *s = opaque;
 
229
    NE2000State *s = vc->opaque;
 
230
    int size = size_;
230
231
    uint8_t *p;
231
232
    unsigned int total_len, next, avail, len, index, mcast_idx;
232
233
    uint8_t buf1[60];
238
239
#endif
239
240
 
240
241
    if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
241
 
        return;
 
242
        return -1;
242
243
 
243
244
    /* XXX: check this */
244
245
    if (s->rxcr & 0x10) {
247
248
        if (!memcmp(buf,  broadcast_macaddr, 6)) {
248
249
            /* broadcast address */
249
250
            if (!(s->rxcr & 0x04))
250
 
                return;
 
251
                return size;
251
252
        } else if (buf[0] & 0x01) {
252
253
            /* multicast */
253
254
            if (!(s->rxcr & 0x08))
254
 
                return;
 
255
                return size;
255
256
            mcast_idx = compute_mcast_idx(buf);
256
257
            if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
257
 
                return;
 
258
                return size;
258
259
        } else if (s->mem[0] == buf[0] &&
259
260
                   s->mem[2] == buf[1] &&
260
261
                   s->mem[4] == buf[2] &&
263
264
                   s->mem[10] == buf[5]) {
264
265
            /* match */
265
266
        } else {
266
 
            return;
 
267
            return size;
267
268
        }
268
269
    }
269
270
 
316
317
    /* now we can signal we have received something */
317
318
    s->isr |= ENISR_RX;
318
319
    ne2000_update_irq(s);
 
320
 
 
321
    return size_;
319
322
}
320
323
 
321
324
static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
756
759
 
757
760
    ne2000_reset(s);
758
761
 
759
 
    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
760
 
                                 ne2000_receive, ne2000_can_receive,
761
 
                                 isa_ne2000_cleanup, s);
 
762
    s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
 
763
                                          ne2000_can_receive, ne2000_receive,
 
764
                                          NULL, isa_ne2000_cleanup, s);
762
765
 
763
766
    qemu_format_nic_info_str(s->vc, s->macaddr);
764
767
 
800
803
    unregister_savevm("ne2000", s);
801
804
}
802
805
 
803
 
PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
 
806
static void pci_ne2000_init(PCIDevice *pci_dev)
804
807
{
805
 
    PCINE2000State *d;
 
808
    PCINE2000State *d = (PCINE2000State *)pci_dev;
806
809
    NE2000State *s;
807
810
    uint8_t *pci_conf;
808
811
 
809
 
    d = (PCINE2000State *)pci_register_device(bus,
810
 
                                              "NE2000", sizeof(PCINE2000State),
811
 
                                              devfn,
812
 
                                              NULL, NULL);
813
 
    if (!d)
814
 
       return NULL;
815
 
 
816
812
    pci_conf = d->dev.config;
817
813
    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
818
 
    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_RTL8029);
 
814
    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8029);
819
815
    pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
820
 
    pci_conf[0x0e] = 0x00; // header_type
 
816
    pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
821
817
    pci_conf[0x3d] = 1; // interrupt pin 0
822
818
 
823
 
    pci_register_io_region(&d->dev, 0, 0x100,
 
819
    pci_register_bar(&d->dev, 0, 0x100,
824
820
                           PCI_ADDRESS_SPACE_IO, ne2000_map);
825
821
    s = &d->ne2000;
826
822
    s->irq = d->dev.irq[0];
827
823
    s->pci_dev = (PCIDevice *)d;
828
 
    memcpy(s->macaddr, nd->macaddr, 6);
 
824
    qdev_get_macaddr(&d->dev.qdev, s->macaddr);
829
825
    ne2000_reset(s);
830
 
    s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
831
 
                                 ne2000_receive, ne2000_can_receive,
 
826
    s->vc = qdev_get_vlan_client(&d->dev.qdev,
 
827
                                 ne2000_can_receive, ne2000_receive, NULL,
832
828
                                 ne2000_cleanup, s);
833
829
 
834
830
    qemu_format_nic_info_str(s->vc, s->macaddr);
835
831
 
836
832
    register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
837
 
 
838
 
    return (PCIDevice *)d;
839
 
}
 
833
}
 
834
 
 
835
static PCIDeviceInfo ne2000_info = {
 
836
    .qdev.name = "ne2k_pci",
 
837
    .qdev.size = sizeof(PCINE2000State),
 
838
    .init      = pci_ne2000_init,
 
839
};
 
840
 
 
841
static void ne2000_register_devices(void)
 
842
{
 
843
    pci_qdev_register(&ne2000_info);
 
844
}
 
845
 
 
846
device_init(ne2000_register_devices)