From patchwork Wed Nov 25 18:49:12 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39449 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 94B231007D1 for ; Thu, 26 Nov 2009 07:14:05 +1100 (EST) Received: from localhost ([127.0.0.1]:53812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDOFW-00031n-Py for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 15:14:02 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDNHG-0006VF-7g for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:11:46 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDNHB-0006SZ-Cj for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:11:45 -0500 Received: from [199.232.76.173] (port=51861 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNHB-0006SU-5R for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:11:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40989) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDNHA-0002Pk-Hj for qemu-devel@nongnu.org; Wed, 25 Nov 2009 14:11:40 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqOIE031859 (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-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqMRf014170; Wed, 25 Nov 2009 13:52:24 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id 67CFCB0B9; Wed, 25 Nov 2009 18:49:41 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:12 +0000 Message-Id: <1259174977-26212-20-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.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 19/44] net: convert e1000 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/e1000.c | 47 ++++++++++++++++++++++++++--------------------- 1 files changed, 26 insertions(+), 21 deletions(-) diff --git a/hw/e1000.c b/hw/e1000.c index 00f6a57..683fdcc 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -75,7 +75,7 @@ enum { typedef struct E1000State_st { PCIDevice dev; - VLANClientState *vc; + NICState *nic; NICConf conf; int mmio_index; @@ -385,9 +385,9 @@ xmit_seg(E1000State *s) if (tp->vlan_needed) { memmove(tp->vlan, tp->data, 12); memcpy(tp->data + 8, tp->vlan_header, 4); - qemu_send_packet(s->vc, tp->vlan, tp->size + 4); + qemu_send_packet(&s->nic->nc, tp->vlan, tp->size + 4); } else - qemu_send_packet(s->vc, tp->data, tp->size); + qemu_send_packet(&s->nic->nc, tp->data, tp->size); s->mac_reg[TPT]++; s->mac_reg[GPTC]++; n = s->mac_reg[TOTL]; @@ -590,12 +590,12 @@ receive_filter(E1000State *s, const uint8_t *buf, int size) } static void -e1000_set_link_status(VLANClientState *vc) +e1000_set_link_status(VLANClientState *nc) { - E1000State *s = vc->opaque; + E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque; uint32_t old_status = s->mac_reg[STATUS]; - if (vc->link_down) + if (nc->link_down) s->mac_reg[STATUS] &= ~E1000_STATUS_LU; else s->mac_reg[STATUS] |= E1000_STATUS_LU; @@ -605,17 +605,17 @@ e1000_set_link_status(VLANClientState *vc) } static int -e1000_can_receive(VLANClientState *vc) +e1000_can_receive(VLANClientState *nc) { - E1000State *s = vc->opaque; + E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque; return (s->mac_reg[RCTL] & E1000_RCTL_EN); } static ssize_t -e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) +e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size) { - E1000State *s = vc->opaque; + E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque; struct e1000_rx_desc desc; target_phys_addr_t base; unsigned int n, rdt; @@ -1037,11 +1037,11 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num, } static void -e1000_cleanup(VLANClientState *vc) +e1000_cleanup(VLANClientState *nc) { - E1000State *d = vc->opaque; + E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque; - d->vc = NULL; + s->nic = NULL; } static int @@ -1050,7 +1050,7 @@ pci_e1000_uninit(PCIDevice *dev) E1000State *d = DO_UPCAST(E1000State, dev, dev); cpu_unregister_io_memory(d->mmio_index); - qemu_del_vlan_client(d->vc); + qemu_del_vlan_client(&d->nic->nc); vmstate_unregister(&vmstate_e1000, d); return 0; } @@ -1067,6 +1067,15 @@ static void e1000_reset(void *opaque) memset(&d->tx, 0, sizeof d->tx); } +static NetClientInfo net_e1000_info = { + .type = NET_CLIENT_TYPE_NIC, + .size = sizeof(NICState), + .can_receive = e1000_can_receive, + .receive = e1000_receive, + .cleanup = e1000_cleanup, + .link_status_changed = e1000_set_link_status, +}; + static int pci_e1000_init(PCIDevice *pci_dev) { E1000State *d = DO_UPCAST(E1000State, dev, pci_dev); @@ -1107,14 +1116,10 @@ static int pci_e1000_init(PCIDevice *pci_dev) checksum = (uint16_t) EEPROM_SUM - checksum; d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum; - d->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, - d->conf.vlan, d->conf.peer, - d->dev.qdev.info->name, d->dev.qdev.id, - e1000_can_receive, e1000_receive, NULL, - NULL, e1000_cleanup, d); - d->vc->link_status_changed = e1000_set_link_status; + d->nic = qemu_new_nic(&net_e1000_info, &d->conf, + d->dev.qdev.info->name, d->dev.qdev.id, d); - qemu_format_nic_info_str(d->vc, macaddr); + qemu_format_nic_info_str(&d->nic->nc, macaddr); vmstate_register(-1, &vmstate_e1000, d);