From patchwork Wed Nov 25 18:49:15 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 773CFB7BBA for ; Thu, 26 Nov 2009 06:16:59 +1100 (EST) Received: from localhost ([127.0.0.1]:41178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNMG-0000ZC-Ds for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 14:16:56 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDMyk-0007OC-GB for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDMyY-0007Hk-KJ for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:33 -0500 Received: from [199.232.76.173] (port=49001 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDMyY-0007HD-BT for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1025) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDMyX-0000ER-KM for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqOE2020206 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Nov 2009 13:52:24 -0500 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqMqa027238; Wed, 25 Nov 2009 13:52:24 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id B00DEB03F; Wed, 25 Nov 2009 18:49:41 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:15 +0000 Message-Id: <1259174977-26212-23-git-send-email-markmc@redhat.com> In-Reply-To: <1259174977-26212-1-git-send-email-markmc@redhat.com> References: <1259174977-26212-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 22/44] net: convert pcnet to NICState X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Mark McLoughlin --- hw/lance.c | 14 +++++++++++--- hw/pcnet.c | 43 +++++++++++++++++++++++-------------------- hw/pcnet.h | 7 ++++--- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/hw/lance.c b/hw/lance.c index 0a96644..98033a4 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 ee3db09..195c825 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 e61d5a4..efacc9f 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;