From patchwork Wed Nov 25 18:49:20 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39445 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 AA9691007D1 for ; Thu, 26 Nov 2009 06:54:08 +1100 (EST) Received: from localhost ([127.0.0.1]:59450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNwE-0005ag-79 for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 14:54:06 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDMyn-0007RE-Dt for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:41 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDMya-0007If-0c for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:35 -0500 Received: from [199.232.76.173] (port=49004 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDMyY-0007Hu-Ok for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57565) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDMyY-0000Ek-4b for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:26 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqP42028328 (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-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqNOX031167; Wed, 25 Nov 2009 13:52:24 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id 27D05B0B3; Wed, 25 Nov 2009 18:49:42 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:20 +0000 Message-Id: <1259174977-26212-28-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.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 27/44] net: convert mcf_fec 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/mcf_fec.c | 58 +++++++++++++++++++++++++++++++++------------------------- 1 files changed, 33 insertions(+), 25 deletions(-) diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c index 8242c8a..4e7fbed 100644 --- a/hw/mcf_fec.c +++ b/hw/mcf_fec.c @@ -25,7 +25,8 @@ do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0) typedef struct { qemu_irq *irq; int mmio_index; - VLANClientState *vc; + NICState *nic; + NICConf conf; uint32_t irq_state; uint32_t eir; uint32_t eimr; @@ -42,7 +43,6 @@ typedef struct { uint32_t erdsr; uint32_t etdsr; uint32_t emrbr; - uint8_t macaddr[6]; } mcf_fec_state; #define FEC_INT_HB 0x80000000 @@ -172,7 +172,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s) if (bd.flags & FEC_BD_L) { /* Last buffer in frame. */ DPRINTF("Sending packet\n"); - qemu_send_packet(s->vc, frame, len); + qemu_send_packet(&s->nic->nc, frame, len); ptr = frame; frame_size = 0; s->eir |= FEC_INT_TXF; @@ -229,11 +229,11 @@ static uint32_t mcf_fec_read(void *opaque, target_phys_addr_t addr) case 0x084: return s->rcr; case 0x0c4: return s->tcr; case 0x0e4: /* PALR */ - return (s->macaddr[0] << 24) | (s->macaddr[1] << 16) - | (s->macaddr[2] << 8) | s->macaddr[3]; + return (s->conf.macaddr.a[0] << 24) | (s->conf.macaddr.a[1] << 16) + | (s->conf.macaddr.a[2] << 8) | s->conf.macaddr.a[3]; break; case 0x0e8: /* PAUR */ - return (s->macaddr[4] << 24) | (s->macaddr[5] << 16) | 0x8808; + return (s->conf.macaddr.a[4] << 24) | (s->conf.macaddr.a[5] << 16) | 0x8808; case 0x0ec: return 0x10000; /* OPD */ case 0x118: return 0; case 0x11c: return 0; @@ -303,14 +303,14 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value) s->eir |= FEC_INT_GRA; break; case 0x0e4: /* PALR */ - s->macaddr[0] = value >> 24; - s->macaddr[1] = value >> 16; - s->macaddr[2] = value >> 8; - s->macaddr[3] = value; + s->conf.macaddr.a[0] = value >> 24; + s->conf.macaddr.a[1] = value >> 16; + s->conf.macaddr.a[2] = value >> 8; + s->conf.macaddr.a[3] = value; break; case 0x0e8: /* PAUR */ - s->macaddr[4] = value >> 24; - s->macaddr[5] = value >> 16; + s->conf.macaddr.a[4] = value >> 24; + s->conf.macaddr.a[5] = value >> 16; break; case 0x0ec: /* OPD */ @@ -347,15 +347,15 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value) mcf_fec_update(s); } -static int mcf_fec_can_receive(VLANClientState *vc) +static int mcf_fec_can_receive(VLANClientState *nc) { - mcf_fec_state *s = vc->opaque; + mcf_fec_state *s = DO_UPCAST(NICState, nc, nc)->opaque; return s->rx_enabled; } -static ssize_t mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +static ssize_t mcf_fec_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { - mcf_fec_state *s = vc->opaque; + mcf_fec_state *s = DO_UPCAST(NICState, nc, nc)->opaque; mcf_fec_bd bd; uint32_t flags = 0; uint32_t addr; @@ -441,15 +441,23 @@ static CPUWriteMemoryFunc * const mcf_fec_writefn[] = { mcf_fec_write }; -static void mcf_fec_cleanup(VLANClientState *vc) +static void mcf_fec_cleanup(VLANClientState *nc) { - mcf_fec_state *s = vc->opaque; + mcf_fec_state *s = DO_UPCAST(NICState, nc, nc)->opaque; cpu_unregister_io_memory(s->mmio_index); qemu_free(s); } +static NetClientInfo net_mcf_fec_info = { + .type = NET_CLIENT_TYPE_NIC, + .size = sizeof(NICState), + .can_receive = mcf_fec_can_receive, + .receive = mcf_fec_receive, + .cleanup = mcf_fec_cleanup, +}; + void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq) { mcf_fec_state *s; @@ -462,11 +470,11 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq) mcf_fec_writefn, s); cpu_register_physical_memory(base, 0x400, s->mmio_index); - s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, - nd->vlan, nd->netdev, - nd->model, nd->name, - mcf_fec_can_receive, mcf_fec_receive, - NULL, NULL, mcf_fec_cleanup, s); - memcpy(s->macaddr, nd->macaddr, 6); - qemu_format_nic_info_str(s->vc, s->macaddr); + memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr)); + s->conf.vlan = nd->vlan; + s->conf.peer = nd->netdev; + + s->nic = qemu_new_nic(&net_mcf_fec_info, &s->conf, nd->model, nd->name, s); + + qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); }