From patchwork Thu Oct 22 16:43:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36705 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 AE890B7BA9 for ; Fri, 23 Oct 2009 04:04:36 +1100 (EST) Received: from localhost ([127.0.0.1]:47114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N115V-0006JD-O2 for incoming@patchwork.ozlabs.org; Thu, 22 Oct 2009 13:04:33 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N10nV-0007FF-Fp for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:45:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N10nL-0006zX-UT for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:45:52 -0400 Received: from [199.232.76.173] (port=47950 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N10nK-0006yl-Uu for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:45:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52055) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N10nJ-0003Fl-6O for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:45:45 -0400 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 n9MGjiWh017092 for ; Thu, 22 Oct 2009 12:45:44 -0400 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 n9MGjhrZ008055; Thu, 22 Oct 2009 12:45:43 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 70253457AD; Thu, 22 Oct 2009 17:43:50 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 22 Oct 2009 17:43:38 +0100 Message-Id: <1256229830-28066-8-git-send-email-markmc@redhat.com> In-Reply-To: <1256229830-28066-1-git-send-email-markmc@redhat.com> References: <1256229830-28066-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 07/19] net: add a client type code 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 This is so as to allow APIs which operate on specific client types without having to add a function table entry which is only implemented by a single client type. Signed-off-by: Mark McLoughlin --- hw/dp8393x.c | 3 ++- hw/etraxfs_eth.c | 3 ++- hw/mcf_fec.c | 3 ++- hw/mipsnet.c | 3 ++- hw/qdev.c | 3 ++- hw/usb-net.c | 3 ++- hw/xen_nic.c | 3 ++- net.c | 22 +++++++++++++++------- net.h | 14 +++++++++++++- tap-win32.c | 3 ++- 10 files changed, 44 insertions(+), 16 deletions(-) diff --git a/hw/dp8393x.c b/hw/dp8393x.c index e4caab0..5622170 100644 --- a/hw/dp8393x.c +++ b/hw/dp8393x.c @@ -889,7 +889,8 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift, s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s); s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */ - s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev, + s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, + nd->vlan, nd->netdev, nd->model, nd->name, nic_can_receive, nic_receive, NULL, nic_cleanup, s); diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c index a411dab..2a583a3 100644 --- a/hw/etraxfs_eth.c +++ b/hw/etraxfs_eth.c @@ -590,7 +590,8 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr) eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth); cpu_register_physical_memory (base, 0x5c, eth->ethregs); - eth->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev, + eth->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, + nd->vlan, nd->netdev, nd->model, nd->name, eth_can_receive, eth_receive, NULL, eth_cleanup, eth); diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c index f9f437a..0567bcd 100644 --- a/hw/mcf_fec.c +++ b/hw/mcf_fec.c @@ -462,7 +462,8 @@ 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 = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev, + s->vc = nd->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, mcf_fec_cleanup, s); diff --git a/hw/mipsnet.c b/hw/mipsnet.c index ea8b570..d32099f 100644 --- a/hw/mipsnet.c +++ b/hw/mipsnet.c @@ -263,7 +263,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) s->io_base = base; s->irq = irq; if (nd) { - s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev, + s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, + nd->vlan, nd->netdev, nd->model, nd->name, mipsnet_can_receive, mipsnet_receive, NULL, mipsnet_cleanup, s); diff --git a/hw/qdev.c b/hw/qdev.c index 20f931c..bc3a0d5 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -370,7 +370,8 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev, { NICInfo *nd = dev->nd; assert(nd); - nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev, + nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, + nd->vlan, nd->netdev, nd->model, nd->name, can_receive, receive, receive_iov, cleanup, opaque); diff --git a/hw/usb-net.c b/hw/usb-net.c index 5c753e0..2393812 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -1460,7 +1460,8 @@ USBDevice *usb_net_init(NICInfo *nd) memcpy(s->mac, nd->macaddr, 6); - s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev, + s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, + nd->vlan, nd->netdev, nd->model, nd->name, usbnet_can_receive, usbnet_receive, diff --git a/hw/xen_nic.c b/hw/xen_nic.c index b09b48a..2a179f0 100644 --- a/hw/xen_nic.c +++ b/hw/xen_nic.c @@ -301,7 +301,8 @@ static int net_init(struct XenDevice *xendev) return -1; vlan = qemu_find_vlan(netdev->xendev.dev, 1); - netdev->vs = qemu_new_vlan_client(vlan, NULL, "xen", NULL, + netdev->vs = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, + vlan, NULL, "xen", NULL, net_rx_ok, net_rx_packet, NULL, NULL, netdev); snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str), diff --git a/net.c b/net.c index d62ab7b..638ba36 100644 --- a/net.c +++ b/net.c @@ -310,7 +310,8 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender, int iovcnt, void *opaque); -VLANClientState *qemu_new_vlan_client(VLANState *vlan, +VLANClientState *qemu_new_vlan_client(net_client_type type, + VLANState *vlan, VLANClientState *peer, const char *model, const char *name, @@ -324,6 +325,7 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan, vc = qemu_mallocz(sizeof(VLANClientState)); + vc->type = type; vc->model = qemu_strdup(model); if (name) vc->name = qemu_strdup(name); @@ -865,7 +867,8 @@ static int net_slirp_init(VLANState *vlan, const char *model, } #endif - s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL, + s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SLIRP, + vlan, NULL, model, name, NULL, slirp_receive, NULL, net_slirp_cleanup, s); snprintf(s->vc->info_str, sizeof(s->vc->info_str), @@ -1471,7 +1474,8 @@ static TAPState *net_tap_fd_init(VLANState *vlan, s = qemu_mallocz(sizeof(TAPState)); s->fd = fd; s->has_vnet_hdr = vnet_hdr != 0; - s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL, + s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP, + vlan, NULL, model, name, NULL, tap_receive, tap_receive_iov, tap_cleanup, s); tap_read_poll(s, 1); @@ -1830,7 +1834,8 @@ static int net_vde_init(VLANState *vlan, const char *model, free(s); return -1; } - s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL, + s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_VDE, + vlan, NULL, model, name, NULL, vde_receive, NULL, vde_cleanup, s); qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); @@ -2070,7 +2075,8 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, s = qemu_mallocz(sizeof(NetSocketState)); s->fd = fd; - s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL, + s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET, + vlan, NULL, model, name, NULL, net_socket_receive_dgram, NULL, net_socket_cleanup, s); qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s); @@ -2099,7 +2105,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, NetSocketState *s; s = qemu_mallocz(sizeof(NetSocketState)); s->fd = fd; - s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL, + s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_SOCKET, + vlan, NULL, model, name, NULL, net_socket_receive, NULL, net_socket_cleanup, s); snprintf(s->vc->info_str, sizeof(s->vc->info_str), @@ -2381,7 +2388,8 @@ static int net_dump_init(VLANState *vlan, const char *device, return -1; } - s->pcap_vc = qemu_new_vlan_client(vlan, NULL, device, name, NULL, + s->pcap_vc = qemu_new_vlan_client(NET_CLIENT_TYPE_DUMP, + vlan, NULL, device, name, NULL, dump_receive, NULL, net_dump_cleanup, s); snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str), diff --git a/net.h b/net.h index 439de2a..aefeef4 100644 --- a/net.h +++ b/net.h @@ -9,6 +9,16 @@ /* VLANs support */ +typedef enum { + NET_CLIENT_TYPE_NONE, + NET_CLIENT_TYPE_NIC, + NET_CLIENT_TYPE_SLIRP, + NET_CLIENT_TYPE_TAP, + NET_CLIENT_TYPE_SOCKET, + NET_CLIENT_TYPE_VDE, + NET_CLIENT_TYPE_DUMP +} net_client_type; + typedef int (NetCanReceive)(VLANClientState *); typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t); typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int); @@ -16,6 +26,7 @@ typedef void (NetCleanup) (VLANClientState *); typedef void (LinkStatusChanged)(VLANClientState *); struct VLANClientState { + net_client_type type; NetReceive *receive; NetReceiveIOV *receive_iov; /* Packets may still be sent if this returns zero. It's used to @@ -43,7 +54,8 @@ struct VLANState { }; VLANState *qemu_find_vlan(int id, int allocate); -VLANClientState *qemu_new_vlan_client(VLANState *vlan, +VLANClientState *qemu_new_vlan_client(net_client_type type, + VLANState *vlan, VLANClientState *peer, const char *model, const char *name, diff --git a/tap-win32.c b/tap-win32.c index e4fdde8..e2bac3e 100644 --- a/tap-win32.c +++ b/tap-win32.c @@ -677,7 +677,8 @@ int tap_win32_init(VLANState *vlan, const char *model, return -1; } - s->vc = qemu_new_vlan_client(vlan, NULL, model, name, + s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_TAP, + vlan, NULL, model, name, NULL, tap_receive, NULL, tap_cleanup, s);