From patchwork Wed Nov 25 18:49:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39424 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 CBA881007D1 for ; Thu, 26 Nov 2009 06:11:07 +1100 (EST) Received: from localhost ([127.0.0.1]:56378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNGY-0005vZ-Hx for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 14:11:02 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDMyi-0007Oa-4s for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:36 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDMya-0007Ib-Pi for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:32 -0500 Received: from [199.232.76.173] (port=49003 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDMyY-0007Ht-OT for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29810) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDMyY-0000Eg-1D for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqPDo015249 (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-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqMlP030217; Wed, 25 Nov 2009 13:52:24 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id 3D6D8B07D; Wed, 25 Nov 2009 18:49:42 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:21 +0000 Message-Id: <1259174977-26212-29-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.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 28/44] net: convert mipsnet 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/mipsnet.c | 45 +++++++++++++++++++++++++++------------------ 1 files changed, 27 insertions(+), 18 deletions(-) diff --git a/hw/mipsnet.c b/hw/mipsnet.c index 67160a4..a066f63 100644 --- a/hw/mipsnet.c +++ b/hw/mipsnet.c @@ -35,7 +35,8 @@ typedef struct MIPSnetState { uint8_t tx_buffer[MAX_ETH_FRAME_SIZE]; int io_base; qemu_irq irq; - VLANClientState *vc; + NICState *nic; + NICConf conf; } MIPSnetState; static void mipsnet_reset(MIPSnetState *s) @@ -66,23 +67,23 @@ static int mipsnet_buffer_full(MIPSnetState *s) return 0; } -static int mipsnet_can_receive(VLANClientState *vc) +static int mipsnet_can_receive(VLANClientState *nc) { - MIPSnetState *s = vc->opaque; + MIPSnetState *s = DO_UPCAST(NICState, nc, nc)->opaque; if (s->busy) return 0; return !mipsnet_buffer_full(s); } -static ssize_t mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +static ssize_t mipsnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { - MIPSnetState *s = vc->opaque; + MIPSnetState *s = DO_UPCAST(NICState, nc, nc)->opaque; #ifdef DEBUG_MIPSNET_RECEIVE printf("mipsnet: receiving len=%d\n", size); #endif - if (!mipsnet_can_receive(vc)) + if (!mipsnet_can_receive(nc)) return -1; s->busy = 1; @@ -183,7 +184,7 @@ static void mipsnet_ioport_write(void *opaque, uint32_t addr, uint32_t val) #ifdef DEBUG_MIPSNET_SEND printf("mipsnet: sending len=%d\n", s->tx_count); #endif - qemu_send_packet(s->vc, s->tx_buffer, s->tx_count); + qemu_send_packet(&s->nic->nc, s->tx_buffer, s->tx_count); s->tx_count = s->tx_written = 0; s->intctl |= MIPSNET_INTCTL_TXDONE; s->busy = 1; @@ -234,9 +235,9 @@ static int mipsnet_load(QEMUFile *f, void *opaque, int version_id) return 0; } -static void mipsnet_cleanup(VLANClientState *vc) +static void mipsnet_cleanup(VLANClientState *nc) { - MIPSnetState *s = vc->opaque; + MIPSnetState *s = DO_UPCAST(NICState, nc, nc)->opaque; unregister_savevm("mipsnet", s); @@ -245,6 +246,14 @@ static void mipsnet_cleanup(VLANClientState *vc) qemu_free(s); } +static NetClientInfo net_mipsnet_info = { + .type = NET_CLIENT_TYPE_NIC, + .size = sizeof(NICState), + .can_receive = mipsnet_can_receive, + .receive = mipsnet_receive, + .cleanup = mipsnet_cleanup, +}; + void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) { MIPSnetState *s; @@ -262,17 +271,17 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) s->io_base = base; s->irq = irq; + if (nd) { - s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, - nd->vlan, nd->netdev, - nd->model, nd->name, - mipsnet_can_receive, mipsnet_receive, - NULL, NULL, mipsnet_cleanup, s); - } else { - s->vc = NULL; - } + memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr)); + s->conf.vlan = nd->vlan; + s->conf.peer = nd->netdev; - qemu_format_nic_info_str(s->vc, nd->macaddr); + s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf, + nd->model, nd->name, s); + + qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); + } mipsnet_reset(s); register_savevm("mipsnet", 0, 0, mipsnet_save, mipsnet_load, s);