diff options
-rw-r--r-- | hw/lance.c | 14 | ||||
-rw-r--r-- | hw/pcnet.c | 43 | ||||
-rw-r--r-- | hw/pcnet.h | 7 |
3 files changed, 38 insertions, 26 deletions
diff --git a/hw/lance.c b/hw/lance.c index 0a96644b43..98033a4ed3 100644 --- a/hw/lance.c +++ b/hw/lance.c @@ -92,14 +92,22 @@ static CPUWriteMemoryFunc * const lance_mem_write[3] = { NULL, }; -static void lance_cleanup(VLANClientState *vc) +static void lance_cleanup(VLANClientState *nc) { - PCNetState *d = vc->opaque; + PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque; vmstate_unregister(&vmstate_pcnet, d); pcnet_common_cleanup(d); } +static NetClientInfo net_lance_info = { + .type = NET_CLIENT_TYPE_NIC, + .size = sizeof(NICState), + .can_receive = pcnet_can_receive, + .receive = pcnet_receive, + .cleanup = lance_cleanup, +}; + static int lance_init(SysBusDevice *dev) { SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); @@ -118,7 +126,7 @@ static int lance_init(SysBusDevice *dev) s->phys_mem_write = ledma_memory_write; vmstate_register(-1, &vmstate_pcnet, d); - return pcnet_common_init(&dev->qdev, s, lance_cleanup); + return pcnet_common_init(&dev->qdev, s, &net_lance_info); } static void lance_reset(DeviceState *dev) diff --git a/hw/pcnet.c b/hw/pcnet.c index ee3db09392..195c825c89 100644 --- a/hw/pcnet.c +++ b/hw/pcnet.c @@ -1028,9 +1028,9 @@ static int pcnet_tdte_poll(PCNetState *s) return !!(CSR_CXST(s) & 0x8000); } -static int pcnet_can_receive(VLANClientState *vc) +int pcnet_can_receive(VLANClientState *nc) { - PCNetState *s = vc->opaque; + PCNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; if (CSR_STOP(s) || CSR_SPND(s)) return 0; @@ -1039,9 +1039,9 @@ static int pcnet_can_receive(VLANClientState *vc) #define MIN_BUF_SIZE 60 -static ssize_t pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size_) +ssize_t pcnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size_) { - PCNetState *s = vc->opaque; + PCNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; int is_padr = 0, is_bcast = 0, is_ladr = 0; uint8_t buf1[60]; int remaining; @@ -1268,11 +1268,11 @@ static void pcnet_transmit(PCNetState *s) if (BCR_SWSTYLE(s) == 1) add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS); s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC; - pcnet_receive(s->vc, s->buffer, s->xmit_pos); + pcnet_receive(&s->nic->nc, s->buffer, s->xmit_pos); s->looptest = 0; } else - if (s->vc) - qemu_send_packet(s->vc, s->buffer, s->xmit_pos); + if (s->nic) + qemu_send_packet(&s->nic->nc, s->buffer, s->xmit_pos); s->csr[0] &= ~0x0008; /* clear TDMD */ s->csr[4] |= 0x0004; /* set TXSTRT */ @@ -1888,21 +1888,16 @@ static const VMStateDescription vmstate_pci_pcnet = { void pcnet_common_cleanup(PCNetState *d) { - d->vc = NULL; + d->nic = NULL; } -int pcnet_common_init(DeviceState *dev, PCNetState *s, - NetCleanup *cleanup) +int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info) { s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s); qemu_macaddr_default_if_unset(&s->conf.macaddr); - s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, - s->conf.vlan, s->conf.peer, - dev->info->name, dev->id, - pcnet_can_receive, pcnet_receive, NULL, NULL, - cleanup, s); - qemu_format_nic_info_str(s->vc, s->conf.macaddr.a); + s->nic = qemu_new_nic(info, &s->conf, dev->info->name, dev->id, s); + qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); return 0; } @@ -1945,9 +1940,9 @@ static void pci_physical_memory_read(void *dma_opaque, target_phys_addr_t addr, cpu_physical_memory_read(addr, buf, len); } -static void pci_pcnet_cleanup(VLANClientState *vc) +static void pci_pcnet_cleanup(VLANClientState *nc) { - PCNetState *d = vc->opaque; + PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque; pcnet_common_cleanup(d); } @@ -1960,10 +1955,18 @@ static int pci_pcnet_uninit(PCIDevice *dev) vmstate_unregister(&vmstate_pci_pcnet, d); qemu_del_timer(d->state.poll_timer); qemu_free_timer(d->state.poll_timer); - qemu_del_vlan_client(d->state.vc); + qemu_del_vlan_client(&d->state.nic->nc); return 0; } +static NetClientInfo net_pci_pcnet_info = { + .type = NET_CLIENT_TYPE_NIC, + .size = sizeof(NICState), + .can_receive = pcnet_can_receive, + .receive = pcnet_receive, + .cleanup = pci_pcnet_cleanup, +}; + static int pci_pcnet_init(PCIDevice *pci_dev) { PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev); @@ -2017,7 +2020,7 @@ static int pci_pcnet_init(PCIDevice *pci_dev) } } - return pcnet_common_init(&pci_dev->qdev, s, pci_pcnet_cleanup); + return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info); } static void pci_reset(DeviceState *dev) diff --git a/hw/pcnet.h b/hw/pcnet.h index e61d5a4479..efacc9fa59 100644 --- a/hw/pcnet.h +++ b/hw/pcnet.h @@ -8,7 +8,7 @@ typedef struct PCNetState_st PCNetState; struct PCNetState_st { - VLANClientState *vc; + NICState *nic; NICConf conf; QEMUTimer *poll_timer; int rap, isr, lnkst; @@ -32,7 +32,8 @@ struct PCNetState_st { void pcnet_h_reset(void *opaque); void pcnet_ioport_writew(void *opaque, uint32_t addr, uint32_t val); uint32_t pcnet_ioport_readw(void *opaque, uint32_t addr); +int pcnet_can_receive(VLANClientState *nc); +ssize_t pcnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size_); void pcnet_common_cleanup(PCNetState *d); -int pcnet_common_init(DeviceState *dev, PCNetState *s, - NetCleanup *cleanup); +int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info); extern const VMStateDescription vmstate_pcnet; |