From patchwork Wed Nov 25 18:49:13 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39451 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 BF492B6EF5 for ; Thu, 26 Nov 2009 07:21:40 +1100 (EST) Received: from localhost ([127.0.0.1]:49419 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDOMr-0008Qw-8q for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 15:21:37 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDNaJ-0007Kf-0v for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:31:27 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDNaE-0007Da-D8 for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:31:26 -0500 Received: from [199.232.76.173] (port=42937 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNaD-0007DO-Sr for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:31:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17529) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDNaD-0004G3-92 for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:31:21 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqO2l001645 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Nov 2009 13:52:25 -0500 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqNiA026879; Wed, 25 Nov 2009 13:52:24 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id 7DC96B0BA; Wed, 25 Nov 2009 18:49:41 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:13 +0000 Message-Id: <1259174977-26212-21-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.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 20/44] net: convert rtl8139 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/rtl8139.c | 43 ++++++++++++++++++++++++------------------- 1 files changed, 24 insertions(+), 19 deletions(-) diff --git a/hw/rtl8139.c b/hw/rtl8139.c index c166db0..931cde9 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -459,7 +459,7 @@ typedef struct RTL8139State { uint16_t CpCmd; uint8_t TxThresh; - VLANClientState *vc; + NICState *nic; NICConf conf; int rtl8139_mmio_io_addr; @@ -785,9 +785,9 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high) #endif } -static int rtl8139_can_receive(VLANClientState *vc) +static int rtl8139_can_receive(VLANClientState *nc) { - RTL8139State *s = vc->opaque; + RTL8139State *s = DO_UPCAST(NICState, nc, nc)->opaque; int avail; /* Receive (drop) packets if card is disabled. */ @@ -807,9 +807,9 @@ static int rtl8139_can_receive(VLANClientState *vc) } } -static ssize_t rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, size_t size_, int do_interrupt) +static ssize_t rtl8139_do_receive(VLANClientState *nc, const uint8_t *buf, size_t size_, int do_interrupt) { - RTL8139State *s = vc->opaque; + RTL8139State *s = DO_UPCAST(NICState, nc, nc)->opaque; int size = size_; uint32_t packet_header = 0; @@ -1156,9 +1156,9 @@ static ssize_t rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, size_ return size_; } -static ssize_t rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +static ssize_t rtl8139_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { - return rtl8139_do_receive(vc, buf, size, 1); + return rtl8139_do_receive(nc, buf, size, 1); } static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) @@ -1744,11 +1744,11 @@ static void rtl8139_transfer_frame(RTL8139State *s, const uint8_t *buf, int size if (TxLoopBack == (s->TxConfig & TxLoopBack)) { DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n")); - rtl8139_do_receive(s->vc, buf, size, do_interrupt); + rtl8139_do_receive(&s->nic->nc, buf, size, do_interrupt); } else { - qemu_send_packet(s->vc, buf, size); + qemu_send_packet(&s->nic->nc, buf, size); } } @@ -3280,11 +3280,11 @@ static void rtl8139_timer(void *opaque) } #endif /* RTL8139_ONBOARD_TIMER */ -static void rtl8139_cleanup(VLANClientState *vc) +static void rtl8139_cleanup(VLANClientState *nc) { - RTL8139State *s = vc->opaque; + RTL8139State *s = DO_UPCAST(NICState, nc, nc)->opaque; - s->vc = NULL; + s->nic = NULL; } static int pci_rtl8139_uninit(PCIDevice *dev) @@ -3301,10 +3301,18 @@ static int pci_rtl8139_uninit(PCIDevice *dev) qemu_free_timer(s->timer); #endif vmstate_unregister(&vmstate_rtl8139, s); - qemu_del_vlan_client(s->vc); + qemu_del_vlan_client(&s->nic->nc); return 0; } +static NetClientInfo net_rtl8139_info = { + .type = NET_CLIENT_TYPE_NIC, + .size = sizeof(NICState), + .can_receive = rtl8139_can_receive, + .receive = rtl8139_receive, + .cleanup = rtl8139_cleanup, +}; + static int pci_rtl8139_init(PCIDevice *dev) { RTL8139State * s = DO_UPCAST(RTL8139State, dev, dev); @@ -3332,12 +3340,9 @@ static int pci_rtl8139_init(PCIDevice *dev) 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->qdev.info->name, dev->qdev.id, - rtl8139_can_receive, rtl8139_receive, NULL, - NULL, rtl8139_cleanup, s); - qemu_format_nic_info_str(s->vc, s->conf.macaddr.a); + s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf, + dev->qdev.info->name, dev->qdev.id, s); + qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); s->cplus_txbuffer = NULL; s->cplus_txbuffer_len = 0;