Fix announce_self(), misc net fixes and cleanups
Subsystems (4)
cover Fix announce_self(), misc net fixes and cleanups
Hi,
Here's a new series of patches mainly to fix qemu_announce_self()
with -netdev as discussed earlier on the list.
I would have liked to have split the series in three, but there
would be conflicts between each, so here goes:
1) Patches 01 to 05 - net.c cleanups
These patches continue the job of moving net backends from net.c to individual files in the net/ directory
2) Patches 06 to 39 - fix qemu_annonuce_self()
The basic issue is that we need a sane way of iterating all the NICs on the system, obtaining the MAC address for each and inject a packet from each.
The series splits out the per-device-type data from VLANClientState into a new structure called NetClientInfo. It further allows devices to inherit from VLANClientState and introduces a NICState struct and qemu_new_nic() constructor for NICs.
That's a huge amount of churn just to fix qemu_announce_self(), but I think the end result is a very nice cleanup to the net API.
3) Patches 40 to 44 - misc fixes
Some small misc networking fixes, including the two posted by Pierre Riteau earlier.
I've given all this quite a bit of compile and runtime testing
and it seems in good shape.
Thanks,
Mark.
PATCH 1/44 net: move slirp code from net.c to net/slirp.c
--- Makefile | 1 + monitor.c | 1 + net.c | 718 +------------------------------------------------------- net.h | 8 +- net/slirp.c | 752 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/slirp.h | 51 ++++ vl.c | 1 + 7 files changed, 814 insertions(+), 718 deletions(-) create mode 100644 net/slirp.c create mode 100644 net/slirp.h
Makefile +1 -0
@@ -106,6 +106,7 @@ net-nested-$(CONFIG_WIN32) += tap-win32.o net-nested-$(CONFIG_BSD) += tap-bsd.o net-nested-$(CONFIG_SOLARIS) += tap-solaris.o net-nested-$(CONFIG_AIX) += tap-aix.o +net-nested-$(CONFIG_SLIRP) += slirp.o net-obj-y += $(addprefix net/, $(net-nested-y)) ######################################################################
monitor.c +1 -0
@@ -32,6 +32,7 @@#include "hw/loader.h" #include "gdbstub.h" #include "net.h" +#include "net/slirp.h" #include "qemu-char.h" #include "sysemu.h" #include "monitor.h"
net.c +6 -712
770 lines not on this page · raw message
net.h +2 -6
@@ -87,6 +87,8 @@ VLANClientState *qemu_new_vlan_client(net_client_type type, void *opaque);void qemu_del_vlan_client (VLANClientState *vc);VLANClientState *qemu_find_vlan_client (VLANState *vlan,void *opaque); +VLANClientState *qemu_find_vlan_client_by_name (Monitor *mon,int vlan_id, +const char *client_str);int qemu_can_send_packet (VLANClientState *vc);ssize_t qemu_sendv_packet (VLANClientState *vc,const struct iovec *iov,int iovcnt);
@@ -108,8 +110,6 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,void do_info_network (Monitor *mon);void do_set_link (Monitor *mon,const QDict *qdict); -void do_info_usernet (Monitor *mon); -/* NIC info */ #define MAX_NICS 8
@@ -156,10 +156,6 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);void net_client_uninit (NICInfo *nd);int net_client_parse (QemuOptsList *opts_list,const char *str);int net_init_clients (void ); -int net_slirp_smb (const char *exported_dir); -void net_slirp_hostfwd_add (Monitor *mon,const QDict *qdict); -void net_slirp_hostfwd_remove (Monitor *mon,const QDict *qdict); -int net_slirp_redir (const char *redir_str);void net_cleanup (void );void net_set_boot_mask (int boot_mask);void net_host_device_add (Monitor *mon,const QDict *qdict);
net/slirp.c new file +752 -0
752 lines not on this page · raw message
net/slirp.h new file +51 -0
51 lines not on this page · raw message
vl.c +1 -0
@@ -140,6 +140,7 @@ int main(int argc, char **argv)#include "hw/loader.h" #include "bt-host.h" #include "net.h" +#include "net/slirp.h" #include "monitor.h" #include "console.h" #include "sysemu.h"
Signature · 1 line
1.6.5.2
PATCH 2/44 net: move vde code from net.c to net/vde.c
In reply to Mark McLoughlin--- Makefile | 1 + net.c | 102 +------------------------------------------------- net/vde.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/vde.h | 36 ++++++++++++++++++ 4 files changed, 162 insertions(+), 101 deletions(-) create mode 100644 net/vde.c create mode 100644 net/vde.h
Makefile +1 -0
@@ -107,6 +107,7 @@ net-nested-$(CONFIG_BSD) += tap-bsd.o net-nested-$(CONFIG_SOLARIS) += tap-solaris.o net-nested-$(CONFIG_AIX) += tap-aix.o net-nested-$(CONFIG_SLIRP) += slirp.o +net-nested-$(CONFIG_VDE) += vde.o net-obj-y += $(addprefix net/, $(net-nested-y)) ######################################################################
net.c +1 -101
124 lines not on this page · raw message
net/vde.c new file +124 -0
124 lines not on this page · raw message
net/vde.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#ifndef QEMU_NET_VDE_H +#define QEMU_NET_VDE_H + +#include "qemu-common.h" +#include "qemu-option.h" + +#ifdef CONFIG_VDE + +int net_init_vde (QemuOpts *opts,Monitor *mon,const char *name,VLANState *vlan); + +#endif /* CONFIG_VDE */ + +#endif /* QEMU_NET_VDE_H */
Signature · 1 line
1.6.5.2
PATCH 3/44 net: move socket backend code from net.c to net/socket.c
In reply to Mark McLoughlin--- Makefile | 1 + net.c | 530 +------------------------------------------------------ net/socket.c | 561 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/socket.h | 33 ++++ 4 files changed, 596 insertions(+), 529 deletions(-) create mode 100644 net/socket.c create mode 100644 net/socket.h
Makefile +1 -0
@@ -100,6 +100,7 @@ block-obj-y += $(addprefix block/, $(block-nested-y)) net-obj-y = net.o net-nested-y = queue.o checksum.o +net-nested-y += socket.o net-nested-$(CONFIG_POSIX) += tap.o net-nested-$(CONFIG_LINUX) += tap-linux.o net-nested-$(CONFIG_WIN32) += tap-win32.o
net.c +1 -529
548 lines not on this page · raw message
net/socket.c new file +561 -0
561 lines not on this page · raw message
net/socket.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#ifndef QEMU_NET_SOCKET_H +#define QEMU_NET_SOCKET_H + +#include "net.h" +#include "qemu-common.h" + +int net_init_socket (QemuOpts *opts,Monitor *mon, +const char *name,VLANState *vlan); + +#endif /* QEMU_NET_SOCKET_H */
Signature · 1 line
1.6.5.2
PATCH 4/44 net: move dump backend code from net.c to net/dump.c
In reply to Mark McLoughlin--- Makefile | 1 + net.c | 127 +-------------------------------------------------- net/dump.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/dump.h | 33 +++++++++++++ 4 files changed, 186 insertions(+), 126 deletions(-) create mode 100644 net/dump.c create mode 100644 net/dump.h
Makefile +1 -0
@@ -101,6 +101,7 @@ block-obj-y += $(addprefix block/, $(block-nested-y)) net-obj-y = net.o net-nested-y = queue.o checksum.o net-nested-y += socket.o +net-nested-y += dump.o net-nested-$(CONFIG_POSIX) += tap.o net-nested-$(CONFIG_LINUX) += tap-linux.o net-nested-$(CONFIG_WIN32) += tap-win32.o
net.c +1 -126
145 lines not on this page · raw message
net/dump.c new file +151 -0
151 lines not on this page · raw message
net/dump.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#ifndef QEMU_NET_DUMP_H +#define QEMU_NET_DUMP_H + +#include "net.h" +#include "qemu-common.h" + +int net_init_dump (QemuOpts *opts,Monitor *mon, +const char *name,VLANState *vlan); + +#endif /* QEMU_NET_DUMP_H */
Signature · 1 line
1.6.5.2
PATCH 5/44 net: clean up includes in net.c
In reply to Mark McLoughlinThis is probably a little drastic, but the includes in this file are now totally out of control when compared with what includes are actually needed.
This may break the build on e.g. *BSD, but it will be easily fixed by re-instating an include.
--- net.c | 74 +--------------------------------------------------------------- 1 files changed, 2 insertions(+), 72 deletions(-)
net.c +3 -73
@@ -21,76 +21,10 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include <unistd.h> -#include <fcntl.h> -#include <signal.h> -#include <time.h> -#include <errno.h> -#include <sys/time.h> -#include <zlib.h> - -/* Needed early for CONFIG_BSD etc. */ -#include "config-host.h" - -#ifndef _WIN32 -#include <sys/times.h> -#include <sys/wait.h> -#include <termios.h> -#include <sys/mman.h> -#include <sys/ioctl.h> -#include <sys/resource.h> -#include <sys/socket.h> -#include <net/if.h> -#include <dirent.h> -#include <netdb.h> -#include <sys/select.h> -#ifdef CONFIG_BSD -#include <sys/stat.h> -#if defined(__FreeBSD__) || defined(__DragonFly__) -#include <libutil.h> -#else -#include <util.h> -#endif -#elif defined (__GLIBC__) && defined (__FreeBSD_kernel__) -#include <freebsd/stdlib.h> -#else -#ifdef __linux__ -#include <pty.h> -#include <malloc.h> -#include <linux/rtc.h> - -/* For the benefit of older linux systems which don't supply it, -we use a local copy of hpet.h. */ -/* #include <linux/hpet.h> */ -#include "hpet.h" - -#include <linux/ppdev.h> -#include <linux/parport.h> -#endif -#ifdef __sun__ -#include <sys/stat.h> -#include <sys/ethernet.h> -#include <sys/sockio.h> -#include <netinet/arp.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/ip_icmp.h> // must come after ip.h -#include <netinet/udp.h> -#include <netinet/tcp.h> -#include <net/if.h> -#include <syslog.h> -#include <stropts.h> -#endif -#endif -#endif +#include "net.h" -#if defined(__OpenBSD__) -#include <util.h> -#endif +#include "config-host.h" -#include "qemu-common.h" -#include "net.h" #include "net/tap.h" #include "net/socket.h" #include "net/dump.h"
@@ -98,12 +32,8 @@#include "net/vde.h" #include "monitor.h" #include "sysemu.h" -#include "qemu-timer.h" -#include "qemu-char.h" -#include "audio/audio.h" +#include "qemu-common.h" #include "qemu_socket.h" -#include "qemu-log.h" -#include "qemu-config.h" static QTAILQ_HEAD(, VLANState) vlans; static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
Signature · 1 line
1.6.5.2
PATCH 6/44 net: remove NICInfo::vc
In reply to Mark McLoughlinSince 1cc33683, this field is not set for most devices, so just remove it and its remaining few uses.
--- hw/dp8393x.c | 10 +++++----- hw/etraxfs_eth.c | 10 +++++----- hw/mcf_fec.c | 10 +++++----- hw/mipsnet.c | 10 +++++----- hw/usb-net.c | 14 +++++++------- net.h | 1 - 6 files changed, 27 insertions(+), 28 deletions(-)
hw/dp8393x.c +5 -5
@@ -889,11 +889,11 @@ 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 (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - nic_can_receive, nic_receive,NULL ,NULL , - nic_cleanup, s); + s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, + nic_can_receive, nic_receive,NULL ,NULL , + nic_cleanup, s);qemu_format_nic_info_str (s->vc, nd->macaddr);qemu_register_reset (nic_reset, s);
hw/etraxfs_eth.c +5 -5
@@ -590,11 +590,11 @@ 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 (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - eth_can_receive, eth_receive, -NULL ,NULL , eth_cleanup, eth); + eth->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, + eth_can_receive, eth_receive, +NULL ,NULL , eth_cleanup, eth); eth->vc->opaque = eth; eth->vc->link_status_changed = eth_set_link;
hw/mcf_fec.c +5 -5
@@ -462,11 +462,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 = 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 ,NULL , mcf_fec_cleanup, s); + 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); }
hw/mipsnet.c +5 -5
@@ -263,11 +263,11 @@ 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 (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - mipsnet_can_receive, mipsnet_receive, -NULL ,NULL , mipsnet_cleanup, s); + 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 ; }
hw/usb-net.c +7 -7
@@ -1460,13 +1460,13 @@ USBDevice *usb_net_init(NICInfo *nd)memcpy (s->mac, nd->macaddr,6 ); - 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, -NULL ,NULL , - usbnet_cleanup, s); + s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + nd->vlan, nd->netdev, + nd->model, nd->name, + usbnet_can_receive, + usbnet_receive, +NULL ,NULL , + usbnet_cleanup, s);qemu_format_nic_info_str (s->vc, s->mac);
net.h +0 -1
@@ -124,7 +124,6 @@ struct NICInfo {char *devaddr;VLANState *vlan;VLANClientState *netdev; -VLANClientState *vc;void *private;int used;int bootable;
Signature · 1 line
1.6.5.2
PATCH 7/44 net: remove NICInfo::private
In reply to Mark McLoughlinWas used by hot-unplug, but not anymore.
--- net.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
net.h +0 -1
@@ -124,7 +124,6 @@ struct NICInfo {char *devaddr;VLANState *vlan;VLANClientState *netdev; -void *private;int used;int bootable;int nvectors;
Signature · 1 line
1.6.5.2
PATCH 8/44 net: introduce NetClientInfo
In reply to Mark McLoughlinThis structure holds data which is common to all instances of a given net client type/model.
--- net.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
net.h +11 -0
@@ -42,6 +42,17 @@ typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);typedef void (NetCleanup ) (VLANClientState *);typedef void (LinkStatusChanged )(VLANClientState *); +typedef struct NetClientInfo { +net_client_type type; +size_t size; +NetReceive *receive; +NetReceive *receive_raw; +NetReceiveIOV *receive_iov; +NetCanReceive *can_receive; +NetCleanup *cleanup; +LinkStatusChanged *link_status_changed; +}NetClientInfo ; +struct VLANClientState {net_client_type type;NetReceive *receive;
Signature · 1 line
1.6.5.2
PATCH 9/44 net: introduce qemu_new_net_client()
In reply to Mark McLoughlinA replacement for qemu_new_vlan_client(), using NetClientInfo to replace most arguments.
--- net.c | 70 +++++++++++++++++++++++++++++++++++++++++++++------------------- net.h | 5 ++++ 2 files changed, 54 insertions(+), 21 deletions(-)
net.c +49 -21
@@ -248,34 +248,31 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,int iovcnt, void *opaque); -VLANClientState *qemu_new_vlan_client (net_client_type type, -VLANState *vlan, -VLANClientState *peer, -const char *model, -const char *name, -NetCanReceive *can_receive, -NetReceive *receive, -NetReceive *receive_raw, -NetReceiveIOV *receive_iov, -NetCleanup *cleanup, -void *opaque) +VLANClientState *qemu_new_net_client (NetClientInfo *info, +VLANState *vlan, +VLANClientState *peer, +const char *model, +const char *name) {VLANClientState *vc; - vc =qemu_mallocz (sizeof (VLANClientState)); +assert (info->size >=sizeof (VLANClientState)); + + vc =qemu_mallocz (info->size); - vc->type = type; + vc->type = info->type; vc->model =qemu_strdup (model); -if (name) +if (name) { vc->name =qemu_strdup (name); -else + }else { vc->name =assign_name (vc, model); - vc->can_receive = can_receive; - vc->receive = receive; - vc->receive_raw = receive_raw; - vc->receive_iov = receive_iov; - vc->cleanup = cleanup; - vc->opaque = opaque; + } + vc->can_receive = info->can_receive; + vc->receive = info->receive; + vc->receive_raw = info->receive_raw; + vc->receive_iov = info->receive_iov; + vc->cleanup = info->cleanup; + vc->link_status_changed = info->link_status_changed;if (vlan) {assert (!peer);
@@ -296,6 +293,37 @@ VLANClientState *qemu_new_vlan_client(net_client_type type,return vc; } +VLANClientState *qemu_new_vlan_client (net_client_type type, +VLANState *vlan, +VLANClientState *peer, +const char *model, +const char *name, +NetCanReceive *can_receive, +NetReceive *receive, +NetReceive *receive_raw, +NetReceiveIOV *receive_iov, +NetCleanup *cleanup, +void *opaque) +{ +VLANClientState *ret; +NetClientInfo info; + + info.type = type; + info.size =sizeof (VLANClientState); + info.can_receive = can_receive; + info.receive = receive; + info.receive_raw = receive_raw; + info.receive_iov = receive_iov; + info.cleanup = cleanup; + info.link_status_changed =NULL ; + + ret =qemu_new_net_client (&info, vlan, peer, model, name); + + ret->opaque = opaque; + +return ret; +} +void qemu_del_vlan_client (VLANClientState *vc) {if (vc->vlan) {
net.h +5 -0
@@ -85,6 +85,11 @@ struct VLANState {VLANState *qemu_find_vlan (int id,int allocate);VLANClientState *qemu_find_netdev (const char *id); +VLANClientState *qemu_new_net_client (NetClientInfo *info, +VLANState *vlan, +VLANClientState *peer, +const char *model, +const char *name); VLANClientState *qemu_new_vlan_client(net_client_type type, VLANState *vlan, VLANClientState *peer,
Signature · 1 line
1.6.5.2
Re: [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client()
Quoted 9 lines · Mark McLoughlin
A replacement for
qemu_new_vlan_client(), using NetClientInfo to replace most arguments.+VLANClientState *qemu_new_net_client(NetClientInfo *info,
+ VLANState *vlan,
+ VLANClientState *peer,
+ const char *model,
+ const char *name) {
Could you change this to use const NetClientInfo *info instead? Then the device structures could be const as well.
Re: [Qemu-devel] [PATCH 09/44] net: introduce qemu_new_net_client()
Quoted 11 lines · Blue Swirl
Review
Quoted 9 lines · Mark McLoughlin
A replacement for
qemu_new_vlan_client(), using NetClientInfo to replace most arguments.(quoted diff) +5
-0+VLANClientState *qemu_new_net_client(NetClientInfo *info, + VLANState *vlan, + VLANClientState *peer, + const char *model, + const char *name) {
Quoted 2 lines
Could you change this to use const NetClientInfo *info instead? Then the device structures could be const as well.
Good idea.
I've added the patch below to http://repo.or.cz/w/qemu/markmc.git
Thanks,
Mark.
From: Mark McLoughlin <[email protected]>
Subject: [PATCH] net: constify NetClientInfo
--- hw/dp8393x.c | 2 +- hw/e1000.c | 2 +- hw/eepro100.c | 2 +- hw/etraxfs_eth.c | 2 +- hw/lan9118.c | 2 +- hw/lance.c | 2 +- hw/mcf_fec.c | 2 +- hw/mipsnet.c | 2 +- hw/musicpal.c | 2 +- hw/ne2000-isa.c | 2 +- hw/ne2000.c | 2 +- hw/pcnet.c | 4 ++-- hw/pcnet.h | 2 +- hw/rtl8139.c | 2 +- hw/smc91c111.c | 2 +- hw/stellaris_enet.c | 2 +- hw/usb-net.c | 2 +- hw/virtio-net.c | 2 +- hw/xen_nic.c | 2 +- hw/xilinx_ethlite.c | 2 +- net.c | 4 ++-- net.h | 6 +++--- net/dump.c | 2 +- net/slirp.c | 2 +- net/socket.c | 4 ++-- net/tap-win32.c | 2 +- net/tap.c | 2 +- net/vde.c | 2 +- 28 files changed, 33 insertions(+), 33 deletions(-)
hw/dp8393x.c +1 -1
@@ -873,7 +873,7 @@ static void nic_cleanup(VLANClientState *nc)qemu_free (s); } -static NetClientInfo net_dp83932_info = { +static const NetClientInfo net_dp83932_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = nic_can_receive,
hw/e1000.c +1 -1
@@ -1067,7 +1067,7 @@ static void e1000_reset(void *opaque)memset (&d->tx,0 ,sizeof d->tx); } -static NetClientInfo net_e1000_info = { +static const NetClientInfo net_e1000_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = e1000_can_receive,
hw/eepro100.c +1 -1
@@ -1797,7 +1797,7 @@ static int pci_nic_uninit(PCIDevice *pci_dev)return 0 ; } -static NetClientInfo net_eepro100_info = { +static const NetClientInfo net_eepro100_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = nic_can_receive,
hw/etraxfs_eth.c +1 -1
@@ -565,7 +565,7 @@ static void eth_cleanup(VLANClientState *nc)qemu_free (eth); } -static NetClientInfo net_etraxfs_info = { +static const NetClientInfo net_etraxfs_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = eth_can_receive,
hw/lan9118.c +1 -1
@@ -1029,7 +1029,7 @@ static void lan9118_cleanup(VLANClientState *nc) s->nic =NULL ; } -static NetClientInfo net_lan9118_info = { +static const NetClientInfo net_lan9118_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = lan9118_can_receive,
hw/lance.c +1 -1
@@ -100,7 +100,7 @@ static void lance_cleanup(VLANClientState *nc)pcnet_common_cleanup (d); } -static NetClientInfo net_lance_info = { +static const NetClientInfo net_lance_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = pcnet_can_receive,
hw/mcf_fec.c +1 -1
@@ -450,7 +450,7 @@ static void mcf_fec_cleanup(VLANClientState *nc)qemu_free (s); } -static NetClientInfo net_mcf_fec_info = { +static const NetClientInfo net_mcf_fec_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = mcf_fec_can_receive,
hw/mipsnet.c +1 -1
@@ -246,7 +246,7 @@ static void mipsnet_cleanup(VLANClientState *nc)qemu_free (s); } -static NetClientInfo net_mipsnet_info = { +static const NetClientInfo net_mipsnet_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = mipsnet_can_receive,
hw/musicpal.c +1 -1
@@ -372,7 +372,7 @@ static void eth_cleanup(VLANClientState *nc) s->nic =NULL ; } -static NetClientInfo net_mv88w8618_info = { +static const NetClientInfo net_mv88w8618_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = eth_can_receive,
hw/ne2000-isa.c +1 -1
@@ -42,7 +42,7 @@ static void isa_ne2000_cleanup(VLANClientState *nc) s->nic =NULL ; } -static NetClientInfo net_ne2000_isa_info = { +static const NetClientInfo net_ne2000_isa_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = ne2000_can_receive,
hw/ne2000.c +1 -1
@@ -705,7 +705,7 @@ static void ne2000_cleanup(VLANClientState *nc) s->nic =NULL ; } -static NetClientInfo net_ne2000_info = { +static const NetClientInfo net_ne2000_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = ne2000_can_receive,
hw/pcnet.c +2 -2
@@ -1891,7 +1891,7 @@ void pcnet_common_cleanup(PCNetState *d) d->nic =NULL ; } -int pcnet_common_init (DeviceState *dev,PCNetState *s,NetClientInfo *info) +int pcnet_common_init (DeviceState *dev,PCNetState *s,const NetClientInfo *info) { s->poll_timer =qemu_new_timer (vm_clock, pcnet_poll_timer, s);
@@ -1959,7 +1959,7 @@ static int pci_pcnet_uninit(PCIDevice *dev)return 0 ; } -static NetClientInfo net_pci_pcnet_info = { +static const NetClientInfo net_pci_pcnet_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = pcnet_can_receive,
hw/pcnet.h +1 -1
@@ -35,5 +35,5 @@ uint32_t pcnet_ioport_readw(void *opaque, uint32_t addr);int pcnet_can_receive (VLANClientState *nc);ssize_t pcnet_receive (VLANClientState *nc,const uint8_t *buf,size_t size_);void pcnet_common_cleanup (PCNetState *d); -int pcnet_common_init (DeviceState *dev,PCNetState *s,NetClientInfo *info); +int pcnet_common_init (DeviceState *dev,PCNetState *s,const NetClientInfo *info);extern const VMStateDescription vmstate_pcnet;
hw/rtl8139.c +1 -1
@@ -3305,7 +3305,7 @@ static int pci_rtl8139_uninit(PCIDevice *dev)return 0 ; } -static NetClientInfo net_rtl8139_info = { +static const NetClientInfo net_rtl8139_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = rtl8139_can_receive,
hw/smc91c111.c +1 -1
@@ -699,7 +699,7 @@ static void smc91c111_cleanup(VLANClientState *nc) s->nic =NULL ; } -static NetClientInfo net_smc91c111_info = { +static const NetClientInfo net_smc91c111_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = smc91c111_can_receive,
hw/stellaris_enet.c +1 -1
@@ -396,7 +396,7 @@ static void stellaris_enet_cleanup(VLANClientState *nc)qemu_free (s); } -static NetClientInfo net_stellaris_enet_info = { +static const NetClientInfo net_stellaris_enet_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = stellaris_enet_can_receive,
hw/usb-net.c +1 -1
@@ -1450,7 +1450,7 @@ static int usb_net_initfn(USBDevice *dev)return 0 ; } -static NetClientInfo net_usbnet_info = { +static const NetClientInfo net_usbnet_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = usbnet_can_receive,
hw/virtio-net.c +1 -1
@@ -818,7 +818,7 @@ static void virtio_net_cleanup(VLANClientState *nc) n->nic =NULL ; } -static NetClientInfo net_virtio_info = { +static const NetClientInfo net_virtio_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = virtio_net_can_receive,
hw/xen_nic.c +1 -1
@@ -290,7 +290,7 @@ static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t siz/* ------------------------------------------------------------- */ -static NetClientInfo net_xen_info = { +static const NetClientInfo net_xen_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = net_rx_ok,
hw/xilinx_ethlite.c +1 -1
@@ -208,7 +208,7 @@ static void eth_cleanup(VLANClientState *nc) s->nic =NULL ; } -static NetClientInfo net_xilinx_ethlite_info = { +static const NetClientInfo net_xilinx_ethlite_info = { .type =NET_CLIENT_TYPE_NIC , .size =sizeof (NICState), .can_receive = eth_can_rx,
net.c +2 -2
@@ -217,7 +217,7 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,int iovcnt, void *opaque); -VLANClientState *qemu_new_net_client(NetClientInfo *info, +VLANClientState *qemu_new_net_client(const NetClientInfo *info, VLANState *vlan, VLANClientState *peer, const char *model,
@@ -256,7 +256,7 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,return vc; } -NICState *qemu_new_nic(NetClientInfo *info, +NICState *qemu_new_nic(const NetClientInfo *info, NICConf *conf, const char *model, const char *name,
net.h +3 -3
@@ -54,7 +54,7 @@ typedef struct NetClientInfo { } NetClientInfo;struct VLANClientState { -NetClientInfo *info; +const NetClientInfo *info;int link_down;QTAILQ_ENTRY (VLANClientState) next;struct VLANState *vlan;
@@ -82,12 +82,12 @@ struct VLANState {VLANState *qemu_find_vlan (int id,int allocate);VLANClientState *qemu_find_netdev (const char *id); -VLANClientState *qemu_new_net_client (NetClientInfo *info, +VLANClientState *qemu_new_net_client (const NetClientInfo *info,VLANState *vlan,VLANClientState *peer,const char *model,const char *name); -NICState *qemu_new_nic(NetClientInfo *info, +NICState *qemu_new_nic(const NetClientInfo *info, NICConf *conf, const char *model, const char *name,
net/dump.c +1 -1
@@ -90,7 +90,7 @@ static void dump_cleanup(VLANClientState *nc)close (s->fd); } -static NetClientInfo net_dump_info = { +static const NetClientInfo net_dump_info = { .type =NET_CLIENT_TYPE_DUMP , .size =sizeof (DumpState), .receive = dump_receive,
net/slirp.c +1 -1
@@ -125,7 +125,7 @@ static void net_slirp_cleanup(VLANClientState *nc)QTAILQ_REMOVE (&slirp_stacks, s, entry); } -static NetClientInfo net_slirp_info = { +static const NetClientInfo net_slirp_info = { .type =NET_CLIENT_TYPE_SLIRP , .size =sizeof (SlirpState), .receive = net_slirp_receive,
net/socket.c +2 -2
@@ -216,7 +216,7 @@ static void net_socket_cleanup(VLANClientState *nc)close (s->fd); } -static NetClientInfo net_dgram_socket_info = { +static const NetClientInfo net_dgram_socket_info = { .type =NET_CLIENT_TYPE_SOCKET , .size =sizeof (NetSocketState), .receive = net_socket_receive_dgram,
@@ -290,7 +290,7 @@ static void net_socket_connect(void *opaque)qemu_set_fd_handler (s->fd, net_socket_send,NULL , s); } -static NetClientInfo net_socket_info = { +static const NetClientInfo net_socket_info = { .type =NET_CLIENT_TYPE_SOCKET , .size =sizeof (NetSocketState), .receive = net_socket_receive,
net/tap-win32.c +1 -1
@@ -666,7 +666,7 @@ static void tap_win32_send(void *opaque) } } -static NetClientInfo net_tap_win32_info = { +static const NetClientInfo net_tap_win32_info = { .type =NET_CLIENT_TYPE_TAP , .size =sizeof (TAPState), .receive = tap_receive,
net/tap.c +1 -1
@@ -264,7 +264,7 @@ static void tap_cleanup(VLANClientState *nc)/* fd support */ -static NetClientInfo net_tap_info = { +static const NetClientInfo net_tap_info = { .type =NET_CLIENT_TYPE_TAP , .size =sizeof (TAPState), .receive = tap_receive,
net/vde.c +1 -1
@@ -69,7 +69,7 @@ static void vde_cleanup(VLANClientState *nc)vde_close (s->vde); } -static NetClientInfo net_vde_info = { +static const NetClientInfo net_vde_info = { .type =NET_CLIENT_TYPE_VDE , .size =sizeof (VDEState), .receive = vde_receive,
Signature · 1 line
1.6.5.2
PATCH 10/44 qdev: move DO_UPCAST() into osdep.h
In reply to Mark McLoughlinNothing qdev specific about this, make it available throughtout.
--- hw/qdev.h | 10 ---------- osdep.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-)
hw/qdev.h +0 -10
@@ -154,16 +154,6 @@ CharDriverState *qdev_init_chardev(DeviceState *dev);BusState *qdev_get_parent_bus (DeviceState *dev); -/* Convert from a base type to a parent type, with compile time checking. */ -#ifdef __GNUC__ -#define DO_UPCAST (type, field, dev) ( __extension__ ( { \ - char __attribute__((unused)) offset_must_be_zero[ \ - -offsetof(type, field)]; \ - container_of(dev, type, field);})) -#else -#define DO_UPCAST (type, field, dev) container_of(dev, type, field) -#endif -/*** BUS API. ***/ void qbus_create_inplace(BusState *bus, BusInfo *info,
osdep.h +10 -0
@@ -37,6 +37,16 @@ (type *) ((char *) __mptr - offsetof(type, member));})#endif +/* Convert from a base type to a parent type, with compile time checking. */ +#ifdef __GNUC__ +#define DO_UPCAST (type, field, dev) ( __extension__ ( { \ + char __attribute__((unused)) offset_must_be_zero[ \ + -offsetof(type, field)]; \ + container_of(dev, type, field);})) +#else +#define DO_UPCAST (type, field, dev) container_of(dev, type, field) +#endif +#define typeof_field (type, field) typeof(((type *)0)->field)#define type_check (t1,t2) ((t1*)0 - (t2*)0)
Signature · 1 line
1.6.5.2
PATCH 11/44 net: convert tap to NetClientInfo
In reply to Mark McLoughlin--- net/tap.c | 82 +++++++++++++++++++++++++++++++++--------------------------- 1 files changed, 45 insertions(+), 37 deletions(-)
net/tap.c +45 -37
@@ -47,7 +47,7 @@#define TAP_BUFSIZE (4096 + 65536) typedef struct TAPState { - VLANClientState *vc; + VLANClientState nc; int fd; char down_script[1024]; char down_script_arg[128];
@@ -92,7 +92,7 @@ static void tap_writable(void *opaque)tap_write_poll (s,0 ); -qemu_flush_queued_packets (s->vc); +qemu_flush_queued_packets (&s->nc); }static ssize_t tap_write_packet (TAPState *s,const struct iovec *iov,int iovcnt)
@@ -111,10 +111,10 @@ static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcntreturn len; } -static ssize_t tap_receive_iov (VLANClientState *vc,const struct iovec *iov, +static ssize_t tap_receive_iov (VLANClientState *nc,const struct iovec *iov,int iovcnt) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc);const struct iovec *iovp = iov;struct iovec iov_copy[iovcnt +1 ];struct virtio_net_hdr hdr = {0 , };
@@ -130,9 +130,9 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,return tap_write_packet (s, iovp, iovcnt); } -static ssize_t tap_receive_raw (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t tap_receive_raw (VLANClientState *nc,const uint8_t *buf,size_t size) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc);struct iovec iov[2 ];int iovcnt =0 ;struct virtio_net_hdr hdr = {0 , };
@@ -150,13 +150,13 @@ static ssize_t tap_receive_raw(VLANClientState *vc, const uint8_t *buf, size_t sreturn tap_write_packet (s, iov, iovcnt); } -static ssize_t tap_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t tap_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc);struct iovec iov[1 ];if (s->has_vnet_hdr && !s->using_vnet_hdr) { -return tap_receive_raw (vc, buf, size); +return tap_receive_raw (nc, buf, size); } iov[0 ].iov_base = (char *)buf;
@@ -169,7 +169,7 @@ static int tap_can_send(void *opaque) {TAPState *s = opaque; -return qemu_can_send_packet (s->vc); +return qemu_can_send_packet (&s->nc); }#ifndef __sun__
@@ -179,9 +179,9 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) }#endif -static void tap_send_completed (VLANClientState *vc,ssize_t len) +static void tap_send_completed (VLANClientState *nc,ssize_t len) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc);tap_read_poll (s,1 ); }
@@ -203,56 +203,56 @@ static void tap_send(void *opaque) size -=sizeof (struct virtio_net_hdr ); } - size =qemu_send_packet_async (s->vc, buf, size, tap_send_completed); + size =qemu_send_packet_async (&s->nc, buf, size, tap_send_completed);if (size ==0 ) {tap_read_poll (s,0 ); } - }while (size >0 &&qemu_can_send_packet (s->vc)); + }while (size >0 &&qemu_can_send_packet (&s->nc)); } -int tap_has_ufo (VLANClientState *vc) +int tap_has_ufo (VLANClientState *nc) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc); -assert (vc->type ==NET_CLIENT_TYPE_TAP ); +assert (nc->type ==NET_CLIENT_TYPE_TAP );return s->has_ufo; } -int tap_has_vnet_hdr (VLANClientState *vc) +int tap_has_vnet_hdr (VLANClientState *nc) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc); -assert (vc->type ==NET_CLIENT_TYPE_TAP ); +assert (nc->type ==NET_CLIENT_TYPE_TAP );return s->has_vnet_hdr; } -void tap_using_vnet_hdr (VLANClientState *vc,int using_vnet_hdr) +void tap_using_vnet_hdr (VLANClientState *nc,int using_vnet_hdr) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc); using_vnet_hdr = using_vnet_hdr !=0 ; -assert (vc->type ==NET_CLIENT_TYPE_TAP ); +assert (nc->type ==NET_CLIENT_TYPE_TAP );assert (s->has_vnet_hdr == using_vnet_hdr); s->using_vnet_hdr = using_vnet_hdr; } -void tap_set_offload (VLANClientState *vc,int csum,int tso4, +void tap_set_offload (VLANClientState *nc,int csum,int tso4,int tso6,int ecn,int ufo) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc);return tap_fd_set_offload (s->fd, csum, tso4, tso6, ecn, ufo); } -static void tap_cleanup (VLANClientState *vc) +static void tap_cleanup (VLANClientState *nc) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc); -qemu_purge_queued_packets (vc); +qemu_purge_queued_packets (nc);if (s->down_script[0 ])launch_script (s->down_script, s->down_script_arg, s->fd);
@@ -260,29 +260,37 @@ static void tap_cleanup(VLANClientState *vc)tap_read_poll (s,0 );tap_write_poll (s,0 );close (s->fd); -qemu_free (s); }/* fd support */ +static NetClientInfo net_tap_info = { + .type =NET_CLIENT_TYPE_TAP , + .size =sizeof (TAPState), + .receive = tap_receive, + .receive_raw = tap_receive_raw, + .receive_iov = tap_receive_iov, + .cleanup = tap_cleanup, +}; +static TAPState *net_tap_fd_init (VLANState *vlan,const char *model,const char *name,int fd,int vnet_hdr) { +VLANClientState *nc;TAPState *s; - s =qemu_mallocz (sizeof (TAPState)); + nc =qemu_new_net_client (&net_tap_info, vlan,NULL , model, name); + + s =DO_UPCAST (TAPState, nc, nc); + s->fd = fd; s->has_vnet_hdr = vnet_hdr !=0 ; s->using_vnet_hdr =0 ; - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_TAP , - vlan,NULL , model, name,NULL , - tap_receive, tap_receive_raw, - tap_receive_iov, tap_cleanup, s); s->has_ufo =tap_probe_has_ufo (s->fd); -tap_set_offload (s->vc,0 ,0 ,0 ,0 ,0 ); +tap_set_offload (&s->nc,0 ,0 ,0 ,0 ,0 );tap_read_poll (s,1 );return s; }
@@ -415,7 +423,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan }if (qemu_opt_get (opts,"fd" )) { -snprintf (s->vc->info_str,sizeof (s->vc->info_str),"fd=%d" , fd); +snprintf (s->nc.info_str,sizeof (s->nc.info_str),"fd=%d" , fd); }else {const char *ifname, *script, *downscript;
@@ -423,7 +431,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan script =qemu_opt_get (opts,"script" ); downscript =qemu_opt_get (opts,"downscript" ); -snprintf (s->vc->info_str,sizeof (s->vc->info_str), +snprintf (s->nc.info_str,sizeof (s->nc.info_str),"ifname=%s,script=%s,downscript=%s" , ifname, script, downscript);
Signature · 1 line
1.6.5.2
PATCH 12/44 net: convert tap-win32 to NetClientInfo
In reply to Mark McLoughlin--- net/tap-win32.c | 39 +++++++++++++++++++++++---------------- 1 files changed, 23 insertions(+), 16 deletions(-)
net/tap-win32.c +23 -16
@@ -630,25 +630,24 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle,/********************************************/ typedef struct TAPState { -VLANClientState *vc; +VLANClientState nc;tap_win32_overlapped_t *handle; }TAPState ; -static void tap_cleanup (VLANClientState *vc) +static void tap_cleanup (VLANClientState *nc) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc);qemu_del_wait_object (s->handle->tap_semaphore,NULL ,NULL );/* FIXME: need to kill thread and close file handle: tap_win32_close(s); */ -qemu_free (s); } -static ssize_t tap_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t tap_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -TAPState *s = vc->opaque; +TAPState *s =DO_UPCAST (TAPState, nc, nc);return tap_win32_write (s->handle, buf, size); }
@@ -662,33 +661,41 @@ static void tap_win32_send(void *opaque) size =tap_win32_read (s->handle, &buf, max_size);if (size >0 ) { -qemu_send_packet (s->vc, buf, size); +qemu_send_packet (&s->nc, buf, size);tap_win32_free_buffer (s->handle, buf); } } +static NetClientInfo net_tap_win32_info = { + .type =NET_CLIENT_TYPE_TAP , + .size =sizeof (TAPState), + .receive = tap_receive, + .cleanup = tap_cleanup, +}; +static int tap_win32_init (VLANState *vlan,const char *model,const char *name,const char *ifname) { +VLANClientState *nc;TAPState *s; +tap_win32_overlapped_t *handle; - s =qemu_mallocz (sizeof (TAPState)); -if (!s) -return -1 ; -if (tap_win32_open (&s->handle, ifname) <0 ) { +if (tap_win32_open (&handle, ifname) <0 ) {printf ("tap: Could not open '%s'\n" , ifname);return -1 ; } - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_TAP , - vlan,NULL , model, name, -NULL , tap_receive, -NULL ,NULL , tap_cleanup, s); + nc =qemu_new_net_client (&net_tap_win32_info, vlan,NULL , model, name); -snprintf (s->vc->info_str,sizeof (s->vc->info_str), +snprintf (s->nc.info_str,sizeof (s->nc.info_str),"tap: ifname=%s" , ifname); + s =DO_UPCAST (TAPState, nc, nc); + + s->handle = handle; +qemu_add_wait_object (s->handle->tap_semaphore, tap_win32_send, s); +return 0 ; }
Signature · 1 line
1.6.5.2
PATCH 13/44 net: convert slirp to NetClientInfo
In reply to Mark McLoughlin--- net/slirp.c | 61 +++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 37 insertions(+), 24 deletions(-)
net/slirp.c +37 -24
@@ -64,8 +64,8 @@ struct slirp_config_str { }; typedef struct SlirpState { + VLANClientState nc; QTAILQ_ENTRY(SlirpState) entry; - VLANClientState *vc; Slirp *slirp; #ifndef _WIN32 char smb_dir[128];
@@ -97,35 +97,41 @@ int slirp_can_output(void *opaque) {SlirpState *s = opaque; -return qemu_can_send_packet (s->vc); +return qemu_can_send_packet (&s->nc); }void slirp_output (void *opaque,const uint8_t *pkt,int pkt_len) {SlirpState *s = opaque; -qemu_send_packet (s->vc, pkt, pkt_len); +qemu_send_packet (&s->nc, pkt, pkt_len); } -static ssize_t slirp_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t net_slirp_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -SlirpState *s = vc->opaque; +SlirpState *s =DO_UPCAST (SlirpState, nc, nc);slirp_input (s->slirp, buf, size);return size; } -static void net_slirp_cleanup (VLANClientState *vc) +static void net_slirp_cleanup (VLANClientState *nc) { -SlirpState *s = vc->opaque; +SlirpState *s =DO_UPCAST (SlirpState, nc, nc);slirp_cleanup (s->slirp);slirp_smb_cleanup (s);QTAILQ_REMOVE (&slirp_stacks, s, entry); -qemu_free (s); } +static NetClientInfo net_slirp_info = { + .type =NET_CLIENT_TYPE_SLIRP , + .size =sizeof (SlirpState), + .receive = net_slirp_receive, + .cleanup = net_slirp_cleanup, +}; + static int net_slirp_init(VLANState *vlan, const char *model, const char *name, int restricted, const char *vnetwork, const char *vhost,
@@ -143,6 +149,7 @@ static int net_slirp_init(VLANState *vlan, const char *model,#ifndef _WIN32struct in_addr smbsrv = { .s_addr =0 };#endif +VLANClientState *nc;SlirpState *s;char buf[20 ];uint32_t addr;
@@ -228,7 +235,13 @@ static int net_slirp_init(VLANState *vlan, const char *model, }#endif - s =qemu_mallocz (sizeof (SlirpState)); + nc =qemu_new_net_client (&net_slirp_info, vlan,NULL , model, name); + +snprintf (nc->info_str,sizeof (nc->info_str), +"net=%s, restricted=%c" ,inet_ntoa (net), restricted ?'y' :'n' ); + + s =DO_UPCAST (SlirpState, nc, nc); + s->slirp =slirp_init (restricted, net, mask, host, vhostname, tftp_export, bootfile, dhcp, dns, s);QTAILQ_INSERT_TAIL (&slirp_stacks, s, entry);
@@ -237,11 +250,11 @@ static int net_slirp_init(VLANState *vlan, const char *model,if (config->flags &SLIRP_CFG_HOSTFWD ) {if (slirp_hostfwd (s, config->str, config->flags &SLIRP_CFG_LEGACY ) <0 ) -return -1 ; + goto error; }else {if (slirp_guestfwd (s, config->str, config->flags &SLIRP_CFG_LEGACY ) <0 ) -return -1 ; + goto error; } }#ifndef _WIN32
@@ -250,34 +263,32 @@ static int net_slirp_init(VLANState *vlan, const char *model, }if (smb_export) {if (slirp_smb (s, smb_export, smbsrv) <0 ) -return -1 ; + goto error; }#endif - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_SLIRP , - vlan,NULL , model, name,NULL , - slirp_receive,NULL ,NULL , - net_slirp_cleanup, s); -snprintf (s->vc->info_str,sizeof (s->vc->info_str), -"net=%s, restricted=%c" ,inet_ntoa (net), restricted ?'y' :'n' );return 0 ; + +error: +qemu_del_vlan_client (nc); +return -1 ; }static SlirpState *slirp_lookup (Monitor *mon,const char *vlan,const char *stack) { -VLANClientState *vc;if (vlan) { - vc =qemu_find_vlan_client_by_name (mon,strtol (vlan,NULL ,0 ), stack); -if (!vc) { +VLANClientState *nc; + nc =qemu_find_vlan_client_by_name (mon,strtol (vlan,NULL ,0 ), stack); +if (!nc) {return NULL ; } -if (strcmp (vc->model,"user" )) { +if (strcmp (nc->model,"user" )) {monitor_printf (mon,"invalid device specified\n" );return NULL ; } -return vc->opaque; +return DO_UPCAST (SlirpState, nc, nc); }else {if (QTAILQ_EMPTY (&slirp_stacks)) {monitor_printf (mon,"user mode network stack not in use\n" );
@@ -626,7 +637,9 @@ void do_info_usernet(Monitor *mon)SlirpState *s; QTAILQ_FOREACH(s, &slirp_stacks, entry) { -monitor_printf (mon,"VLAN %d (%s):\n" , s->vc->vlan->id, s->vc->name); +monitor_printf (mon,"VLAN %d (%s):\n" , + s->nc.vlan ? s->nc.vlan->id :-1 , + s->nc.name);slirp_connection_info (s->slirp, mon); } }
Signature · 1 line
1.6.5.2
PATCH 14/44 net: convert vde to NetClientInfo
In reply to Mark McLoughlin--- net/vde.c | 45 ++++++++++++++++++++++++++++----------------- 1 files changed, 28 insertions(+), 17 deletions(-)
net/vde.c +28 -17
@@ -34,7 +34,7 @@#include "sysemu.h" typedef struct VDEState { -VLANClientState *vc; +VLANClientState nc;VDECONN *vde; }VDEState ;
@@ -46,13 +46,13 @@ static void vde_to_qemu(void *opaque) size =vde_recv (s->vde, (char *)buf,sizeof (buf),0 );if (size >0 ) { -qemu_send_packet (s->vc, buf, size); +qemu_send_packet (&s->nc, buf, size); } } -static ssize_t vde_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t vde_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -VDEState *s = vc->opaque; +VDEState *s =DO_UPCAST (VDEState, nc, nc);ssize_t ret; do {
@@ -62,19 +62,27 @@ static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size)return ret; } -static void vde_cleanup (VLANClientState *vc) +static void vde_cleanup (VLANClientState *nc) { -VDEState *s = vc->opaque; +VDEState *s =DO_UPCAST (VDEState, nc, nc);qemu_set_fd_handler (vde_datafd (s->vde),NULL ,NULL ,NULL );vde_close (s->vde); -qemu_free (s); } +static NetClientInfo net_vde_info = { + .type =NET_CLIENT_TYPE_VDE , + .size =sizeof (VDEState), + .receive = vde_receive, + .cleanup = vde_cleanup, +}; +static int net_vde_init (VLANState *vlan,const char *model,const char *name,const char *sock,int port,const char *group,int mode) { +VLANClientState *nc;VDEState *s; +VDECONN *vde;char *init_group = (char *)group;char *init_sock = (char *)sock;
@@ -84,19 +92,22 @@ static int net_vde_init(VLANState *vlan, const char *model, .mode = mode, }; - s =qemu_mallocz (sizeof (VDEState)); - s->vde =vde_open (init_sock, (char *)"QEMU" , &args); -if (!s->vde){ -free (s); + vde =vde_open (init_sock, (char *)"QEMU" , &args); +if (!vde){return -1 ; } - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_VDE , - vlan,NULL , model, name,NULL , - vde_receive,NULL ,NULL , - vde_cleanup, s); + + nc =qemu_new_net_client (&net_vde_info, vlan,NULL , model, name); + +snprintf (nc->info_str,sizeof (nc->info_str),"sock=%s,fd=%d" , + sock,vde_datafd (vde)); + + s =DO_UPCAST (VDEState, nc, nc); + + s->vde = vde; +qemu_set_fd_handler (vde_datafd (s->vde), vde_to_qemu,NULL , s); -snprintf (s->vc->info_str,sizeof (s->vc->info_str),"sock=%s,fd=%d" , - sock,vde_datafd (s->vde)); +return 0 ; }
Signature · 1 line
1.6.5.2
PATCH 15/44 net: convert socket to NetClientInfo
In reply to Mark McLoughlin--- net/socket.c | 74 +++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 45 insertions(+), 29 deletions(-)
net/socket.c +45 -29
@@ -33,7 +33,7 @@#include "sysemu.h" typedef struct NetSocketState { - VLANClientState *vc; + VLANClientState nc; int fd; int state; /* 0 = getting length, 1 = getting data */ unsigned int index;
@@ -50,9 +50,9 @@ typedef struct NetSocketListenState { } NetSocketListenState;/* XXX: we consider we can send the whole packet without blocking */ -static ssize_t net_socket_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t net_socket_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -NetSocketState *s = vc->opaque; +NetSocketState *s =DO_UPCAST (NetSocketState, nc, nc);uint32_t len; len =htonl (size);
@@ -60,9 +60,9 @@ static ssize_t net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_return send_all (s->fd, buf, size); } -static ssize_t net_socket_receive_dgram (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t net_socket_receive_dgram (VLANClientState *nc,const uint8_t *buf,size_t size) { -NetSocketState *s = vc->opaque; +NetSocketState *s =DO_UPCAST (NetSocketState, nc, nc);return sendto (s->fd, (const void *)buf, size,0 , (struct sockaddr *)&s->dgram_dst,sizeof (s->dgram_dst));
@@ -124,7 +124,7 @@ static void net_socket_send(void *opaque) buf += l; size -= l;if (s->index >= s->packet_len) { -qemu_send_packet (s->vc, s->buf, s->packet_len); +qemu_send_packet (&s->nc, s->buf, s->packet_len); s->index =0 ; s->state =0 ; }
@@ -146,7 +146,7 @@ static void net_socket_send_dgram(void *opaque)qemu_set_fd_handler (s->fd,NULL ,NULL ,NULL );return ; } -qemu_send_packet (s->vc, s->buf, size); +qemu_send_packet (&s->nc, s->buf, size); }static int net_socket_mcast_create (struct sockaddr_in *mcastaddr)
@@ -209,14 +209,20 @@ fail:return -1 ; } -static void net_socket_cleanup (VLANClientState *vc) +static void net_socket_cleanup (VLANClientState *nc) { -NetSocketState *s = vc->opaque; +NetSocketState *s =DO_UPCAST (NetSocketState, nc, nc);qemu_set_fd_handler (s->fd,NULL ,NULL ,NULL );close (s->fd); -qemu_free (s); } +static NetClientInfo net_dgram_socket_info = { + .type =NET_CLIENT_TYPE_SOCKET , + .size =sizeof (NetSocketState), + .receive = net_socket_receive_dgram, + .cleanup = net_socket_cleanup, +}; + static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model, const char *name,
@@ -225,6 +231,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,struct sockaddr_in saddr;int newfd;socklen_t saddr_len; +VLANClientState *nc;NetSocketState *s;/* fd passed: multicast: "learn" dgram_dst address from bound address and save it
@@ -258,22 +265,22 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, } } - s =qemu_mallocz (sizeof (NetSocketState)); + nc =qemu_new_net_client (&net_dgram_socket_info, vlan,NULL , model, name); + +snprintf (nc->info_str,sizeof (nc->info_str), +"socket: fd=%d (%s mcast=%s:%d)" , + fd, is_connected ?"cloned" :"" , +inet_ntoa (saddr.sin_addr),ntohs (saddr.sin_port)); + + s =DO_UPCAST (NetSocketState, nc, nc); + s->fd = fd; - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_SOCKET , - vlan,NULL , model, name,NULL , - net_socket_receive_dgram,NULL ,NULL , - net_socket_cleanup, s);qemu_set_fd_handler (s->fd, net_socket_send_dgram,NULL , s);/* mcast: save bound address as dst */ if (is_connected) s->dgram_dst=saddr; -snprintf (s->vc->info_str,sizeof (s->vc->info_str), -"socket: fd=%d (%s mcast=%s:%d)" , - fd, is_connected?"cloned" :"" , -inet_ntoa (saddr.sin_addr),ntohs (saddr.sin_port));return s; }
@@ -283,20 +290,29 @@ static void net_socket_connect(void *opaque)qemu_set_fd_handler (s->fd, net_socket_send,NULL , s); } +static NetClientInfo net_socket_info = { + .type =NET_CLIENT_TYPE_SOCKET , + .size =sizeof (NetSocketState), + .receive = net_socket_receive, + .cleanup = net_socket_cleanup, +}; +static NetSocketState *net_socket_fd_init_stream (VLANState *vlan,const char *model,const char *name,int fd,int is_connected) { +VLANClientState *nc;NetSocketState *s; - s =qemu_mallocz (sizeof (NetSocketState)); + + nc =qemu_new_net_client (&net_socket_info, vlan,NULL , model, name); + +snprintf (nc->info_str,sizeof (nc->info_str),"socket: fd=%d" , fd); + + s =DO_UPCAST (NetSocketState, nc, nc); + s->fd = fd; - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_SOCKET , - vlan,NULL , model, name,NULL , - net_socket_receive,NULL ,NULL , - net_socket_cleanup, s); -snprintf (s->vc->info_str,sizeof (s->vc->info_str), -"socket: fd=%d" , fd); +if (is_connected) {net_socket_connect (s); }else {
@@ -350,7 +366,7 @@ static void net_socket_accept(void *opaque)if (!s1) {closesocket (fd); }else { -snprintf (s1->vc->info_str,sizeof (s1->vc->info_str), +snprintf (s1->nc.info_str,sizeof (s1->nc.info_str),"socket: connection from %s:%d" ,inet_ntoa (saddr.sin_addr),ntohs (saddr.sin_port)); }
@@ -443,7 +459,7 @@ static int net_socket_connect_init(VLANState *vlan, s =net_socket_fd_init (vlan, model, name, fd, connected);if (!s)return -1 ; -snprintf (s->vc->info_str,sizeof (s->vc->info_str), +snprintf (s->nc.info_str,sizeof (s->nc.info_str),"socket: connect to %s:%d" ,inet_ntoa (saddr.sin_addr),ntohs (saddr.sin_port));return 0 ;
@@ -472,7 +488,7 @@ static int net_socket_mcast_init(VLANState *vlan, s->dgram_dst = saddr; -snprintf (s->vc->info_str,sizeof (s->vc->info_str), +snprintf (s->nc.info_str,sizeof (s->nc.info_str),"socket: mcast=%s:%d" ,inet_ntoa (saddr.sin_addr),ntohs (saddr.sin_port));return 0 ;
Signature · 1 line
1.6.5.2
PATCH 16/44 net: convert dump to NetClientInfo
In reply to Mark McLoughlin--- net/dump.c | 47 +++++++++++++++++++++++++++-------------------- 1 files changed, 27 insertions(+), 20 deletions(-)
net/dump.c +27 -20
@@ -28,7 +28,7 @@#include "qemu-log.h" typedef struct DumpState { -VLANClientState *pcap_vc; +VLANClientState nc;int fd;int pcap_caplen; }DumpState ;
@@ -54,9 +54,9 @@ struct pcap_sf_pkthdr {uint32_t len; }; -static ssize_t dump_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t dump_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -DumpState *s = vc->opaque; +DumpState *s =DO_UPCAST (DumpState, nc, nc);struct pcap_sf_pkthdr hdr;int64_t ts;int caplen;
@@ -83,30 +83,34 @@ static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t sizereturn size; } -static void net_dump_cleanup (VLANClientState *vc) +static void dump_cleanup (VLANClientState *nc) { -DumpState *s = vc->opaque; +DumpState *s =DO_UPCAST (DumpState, nc, nc);close (s->fd); -qemu_free (s); } +static NetClientInfo net_dump_info = { + .type =NET_CLIENT_TYPE_DUMP , + .size =sizeof (DumpState), + .receive = dump_receive, + .cleanup = dump_cleanup, +}; +static int net_dump_init (VLANState *vlan,const char *device,const char *name,const char *filename,int len) {struct pcap_file_hdr hdr; +VLANClientState *nc;DumpState *s; +int fd; - s =qemu_malloc (sizeof (DumpState)); - - s->fd =open (filename,O_CREAT |O_WRONLY |O_BINARY ,0644 ); -if (s->fd <0 ) { + fd =open (filename,O_CREAT |O_WRONLY |O_BINARY ,0644 ); +if (fd <0 ) {qemu_error ("-net dump: can't open %s\n" , filename);return -1 ; } - s->pcap_caplen = len; - hdr.magic =PCAP_MAGIC ; hdr.version_major =2 ; hdr.version_minor =4 ;
@@ -115,19 +119,22 @@ static int net_dump_init(VLANState *vlan, const char *device, hdr.snaplen = s->pcap_caplen; hdr.linktype =1 ; -if (write (s->fd, &hdr,sizeof (hdr)) <sizeof (hdr)) { +if (write (fd, &hdr,sizeof (hdr)) <sizeof (hdr)) {qemu_error ("-net dump write error: %s\n" ,strerror (errno)); -close (s->fd); -qemu_free (s); +close (fd);return -1 ; } - s->pcap_vc =qemu_new_vlan_client (NET_CLIENT_TYPE_DUMP , - vlan,NULL , device, name,NULL , - dump_receive,NULL ,NULL , - net_dump_cleanup, s); -snprintf (s->pcap_vc->info_str,sizeof (s->pcap_vc->info_str), + nc =qemu_new_net_client (&net_dump_info, vlan,NULL , device, name); + +snprintf (nc->info_str,sizeof (nc->info_str),"dump to %s (len=%d)" , filename, len); + + s =DO_UPCAST (DumpState, nc, nc); + + s->fd = fd; + s->pcap_caplen = len; +return 0 ; }
Signature · 1 line
1.6.5.2
PATCH 17/44 net: introduce NICState and qemu_new_nic()
In reply to Mark McLoughlinCommon state for all NICs.
The opaque member will replace the opaque member in VLANClientState since only NICs need it.
The conf member will allow us to iterate over NICs, access the MAC addr for the NIC and send a packet from each NIC in qemu_announce_self().
--- net.c | 21 +++++++++++++++++++++ net.h | 11 +++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-)
net.c +21 -0
@@ -293,6 +293,27 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,return vc; } +NICState *qemu_new_nic (NetClientInfo *info, +NICConf *conf, +const char *model, +const char *name, +void *opaque) +{ +VLANClientState *nc; +NICState *nic; + +assert (info->type ==NET_CLIENT_TYPE_NIC ); +assert (info->size >=sizeof (NICState)); + + nc =qemu_new_net_client (info, conf->vlan, conf->peer, model, name); + + nic =DO_UPCAST (NICState, nc, nc); + nic->conf = conf; + nic->opaque = opaque; + +return nic; +} + VLANClientState *qemu_new_vlan_client(net_client_type type, VLANState *vlan, VLANClientState *peer,
net.h +11 -0
@@ -75,6 +75,12 @@ struct VLANClientState { unsigned receive_disabled : 1; }; +typedef struct NICState { +VLANClientState nc; +NICConf *conf; +void *opaque; +}NICState ; +struct VLANState {int id; QTAILQ_HEAD(, VLANClientState) clients;
@@ -90,6 +96,11 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,VLANClientState *peer, const char *model, const char *name); +NICState *qemu_new_nic (NetClientInfo *info, +NICConf *conf, +const char *model, +const char *name, +void *opaque); VLANClientState *qemu_new_vlan_client(net_client_type type, VLANState *vlan, VLANClientState *peer,
Signature · 1 line
1.6.5.2
PATCH 18/44 net: convert virtio to NICState
In reply to Mark McLoughlin--- hw/virtio-net.c | 73 +++++++++++++++++++++++++++++------------------------- 1 files changed, 39 insertions(+), 34 deletions(-)
hw/virtio-net.c +39 -34
@@ -31,7 +31,7 @@ typedef struct VirtIONetVirtQueue *rx_vq;VirtQueue *tx_vq;VirtQueue *ctrl_vq; -VLANClientState *vc; +NICState *nic;QEMUTimer *tx_timer;int tx_timer_active;uint32_t has_vnet_hdr;
@@ -85,16 +85,16 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)if (memcmp (netcfg.mac, n->mac,ETH_ALEN )) {memcpy (n->mac, netcfg.mac,ETH_ALEN ); -qemu_format_nic_info_str (n->vc, n->mac); +qemu_format_nic_info_str (&n->nic->nc, n->mac); } } -static void virtio_net_set_link_status (VLANClientState *vc) +static void virtio_net_set_link_status (VLANClientState *nc) { -VirtIONet *n = vc->opaque; +VirtIONet *n =DO_UPCAST (NICState, nc, nc)->opaque;uint16_t old_status = n->status; -if (vc->link_down) +if (nc->link_down) n->status &= ~VIRTIO_NET_S_LINK_UP ;else n->status |=VIRTIO_NET_S_LINK_UP ;
@@ -126,13 +126,13 @@ static void virtio_net_reset(VirtIODevice *vdev)static int peer_has_vnet_hdr (VirtIONet *n) { -if (!n->vc->peer) +if (!n->nic->nc.peer)return 0 ; -if (n->vc->peer->type !=NET_CLIENT_TYPE_TAP ) +if (n->nic->nc.peer->type !=NET_CLIENT_TYPE_TAP )return 0 ; - n->has_vnet_hdr =tap_has_vnet_hdr (n->vc->peer); + n->has_vnet_hdr =tap_has_vnet_hdr (n->nic->nc.peer);return n->has_vnet_hdr; }
@@ -142,7 +142,7 @@ static int peer_has_ufo(VirtIONet *n)if (!peer_has_vnet_hdr (n))return 0 ; - n->has_ufo =tap_has_ufo (n->vc->peer); + n->has_ufo =tap_has_ufo (n->nic->nc.peer);return n->has_ufo; }
@@ -159,7 +159,7 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev) (1 <<VIRTIO_NET_F_CTRL_RX_EXTRA );if (peer_has_vnet_hdr (n)) { -tap_using_vnet_hdr (n->vc->peer,1 ); +tap_using_vnet_hdr (n->nic->nc.peer,1 ); features |= (1 <<VIRTIO_NET_F_CSUM ); features |= (1 <<VIRTIO_NET_F_HOST_TSO4 );
@@ -202,7 +202,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features) n->mergeable_rx_bufs = !!(features & (1 <<VIRTIO_NET_F_MRG_RXBUF ));if (n->has_vnet_hdr) { - tap_set_offload(n->vc->peer, + tap_set_offload(n->nic->nc.peer, (features >> VIRTIO_NET_F_GUEST_CSUM) & 1, (features >> VIRTIO_NET_F_GUEST_TSO4) & 1, (features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
@@ -360,16 +360,16 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq) {VirtIONet *n =to_virtio_net (vdev); -qemu_flush_queued_packets (n->vc); +qemu_flush_queued_packets (&n->nic->nc);/* We now have RX buffers, signal to the IO thread to break out of the * select to re-poll the tap file descriptor */ qemu_notify_event (); } -static int virtio_net_can_receive (VLANClientState *vc) +static int virtio_net_can_receive (VLANClientState *nc) { -VirtIONet *n = vc->opaque; +VirtIONet *n =DO_UPCAST (NICState, nc, nc)->opaque;if (!virtio_queue_ready (n->rx_vq) || !(n->vdev.status &VIRTIO_CONFIG_S_DRIVER_OK ))
@@ -511,13 +511,13 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)return 0 ; } -static ssize_t virtio_net_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t virtio_net_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -VirtIONet *n = vc->opaque; +VirtIONet *n =DO_UPCAST (NICState, nc, nc)->opaque;struct virtio_net_hdr_mrg_rxbuf *mhdr =NULL ;size_t hdr_len, offset, i; -if (!virtio_net_can_receive (n->vc)) +if (!virtio_net_can_receive (&n->nic->nc))return -1 ;if (!virtio_net_has_buffers (n, size))
@@ -590,9 +590,9 @@ static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_static void virtio_net_flush_tx (VirtIONet *n,VirtQueue *vq); -static void virtio_net_tx_complete (VLANClientState *vc,ssize_t len) +static void virtio_net_tx_complete (VLANClientState *nc,ssize_t len) { -VirtIONet *n = vc->opaque; +VirtIONet *n =DO_UPCAST (NICState, nc, nc)->opaque;virtqueue_push (n->tx_vq, &n->async_tx.elem, n->async_tx.len);virtio_notify (&n->vdev, n->tx_vq);
@@ -644,7 +644,7 @@ static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq) len += hdr_len; } - ret =qemu_sendv_packet_async (n->vc, out_sg, out_num, + ret =qemu_sendv_packet_async (&n->nic->nc, out_sg, out_num, virtio_net_tx_complete);if (ret ==0 ) {virtio_queue_set_notification (n->tx_vq,0 );
@@ -766,8 +766,8 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) }if (n->has_vnet_hdr) { -tap_using_vnet_hdr (n->vc->peer,1 ); - tap_set_offload(n->vc->peer, +tap_using_vnet_hdr (n->nic->nc.peer,1 ); + tap_set_offload(n->nic->nc.peer, (n->vdev.features >> VIRTIO_NET_F_GUEST_CSUM) & 1, (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO4) & 1, (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
@@ -811,13 +811,22 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)return 0 ; } -static void virtio_net_cleanup (VLANClientState *vc) +static void virtio_net_cleanup (VLANClientState *nc) { -VirtIONet *n = vc->opaque; +VirtIONet *n =DO_UPCAST (NICState, nc, nc)->opaque; - n->vc =NULL ; + n->nic =NULL ; } +static NetClientInfo net_virtio_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = virtio_net_can_receive, + .receive = virtio_net_receive, + .cleanup = virtio_net_cleanup, + .link_status_changed = virtio_net_set_link_status, +}; +VirtIODevice *virtio_net_init (DeviceState *dev,NICConf *conf) {VirtIONet *n;
@@ -839,14 +848,10 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf)qemu_macaddr_default_if_unset (&conf->macaddr);memcpy (&n->mac[0 ], &conf->macaddr,sizeof (n->mac)); n->status =VIRTIO_NET_S_LINK_UP ; - n->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , conf->vlan, conf->peer, - dev->info->name, dev->id, - virtio_net_can_receive, - virtio_net_receive,NULL ,NULL , - virtio_net_cleanup, n); - n->vc->link_status_changed = virtio_net_set_link_status; -qemu_format_nic_info_str (n->vc, conf->macaddr.a); + n->nic =qemu_new_nic (&net_virtio_info, conf, dev->info->name, dev->id, n); + +qemu_format_nic_info_str (&n->nic->nc, conf->macaddr.a); n->tx_timer =qemu_new_timer (vm_clock, virtio_net_tx_timer, n); n->tx_timer_active =0 ;
@@ -867,7 +872,7 @@ void virtio_net_exit(VirtIODevice *vdev) {VirtIONet *n =DO_UPCAST (VirtIONet, vdev, vdev); -qemu_purge_queued_packets (n->vc); +qemu_purge_queued_packets (&n->nic->nc);unregister_savevm ("virtio-net" , n);
@@ -878,5 +883,5 @@ void virtio_net_exit(VirtIODevice *vdev)qemu_free_timer (n->tx_timer);virtio_cleanup (&n->vdev); -qemu_del_vlan_client (n->vc); +qemu_del_vlan_client (&n->nic->nc); }
Signature · 1 line
1.6.5.2
PATCH 19/44 net: convert e1000 to NICState
In reply to Mark McLoughlin--- hw/e1000.c | 47 ++++++++++++++++++++++++++--------------------- 1 files changed, 26 insertions(+), 21 deletions(-)
hw/e1000.c +26 -21
@@ -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);
Signature · 1 line
1.6.5.2
PATCH 20/44 net: convert rtl8139 to NICState
In reply to Mark McLoughlin--- hw/rtl8139.c | 43 ++++++++++++++++++++++++------------------- 1 files changed, 24 insertions(+), 19 deletions(-)
hw/rtl8139.c +24 -19
@@ -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 sizeif (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 ;
Signature · 1 line
1.6.5.2
PATCH 21/44 net: convert ne2000 to NICState
In reply to Mark McLoughlin--- hw/ne2000-isa.c | 22 ++++++++++++++-------- hw/ne2000.c | 35 +++++++++++++++++++++-------------- hw/ne2000.h | 2 +- 3 files changed, 36 insertions(+), 23 deletions(-)
hw/ne2000-isa.c +14 -8
@@ -35,13 +35,21 @@ typedef struct ISANE2000State {NE2000State ne2000; } ISANE2000State; -static void isa_ne2000_cleanup (VLANClientState *vc) +static void isa_ne2000_cleanup (VLANClientState *nc) { -NE2000State *s = vc->opaque; +NE2000State *s =DO_UPCAST (NICState, nc, nc)->opaque; - s->vc =NULL ; + s->nic =NULL ; } +static NetClientInfo net_ne2000_isa_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = ne2000_can_receive, + .receive = ne2000_receive, + .cleanup = isa_ne2000_cleanup, +}; +static int isa_ne2000_initfn (ISADevice *dev) {ISANE2000State *isa =DO_UPCAST (ISANE2000State, dev, dev);
@@ -63,11 +71,9 @@ static int isa_ne2000_initfn(ISADevice *dev)qemu_macaddr_default_if_unset (&s->c.macaddr);ne2000_reset (s); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , s->c.vlan, s->c.peer, - dev->qdev.info->name, dev->qdev.id, - ne2000_can_receive, ne2000_receive,NULL , -NULL , isa_ne2000_cleanup, s); -qemu_format_nic_info_str (s->vc, s->c.macaddr.a); + s->nic =qemu_new_nic (&net_ne2000_isa_info, &s->c, + dev->qdev.info->name, dev->qdev.id, s); +qemu_format_nic_info_str (&s->nic->nc, s->c.macaddr.a);vmstate_register (-1 , &vmstate_ne2000, s);return 0 ;
hw/ne2000.c +21 -14
@@ -188,9 +188,9 @@ static int ne2000_buffer_full(NE2000State *s)return 0 ; } -int ne2000_can_receive (VLANClientState *vc) +int ne2000_can_receive (VLANClientState *nc) { -NE2000State *s = vc->opaque; +NE2000State *s =DO_UPCAST (NICState, nc, nc)->opaque;if (s->cmd &E8390_STOP )return 1 ;
@@ -199,9 +199,9 @@ int ne2000_can_receive(VLANClientState *vc)#define MIN_BUF_SIZE 60 -ssize_t ne2000_receive (VLANClientState *vc,const uint8_t *buf,size_t size_) +ssize_t ne2000_receive (VLANClientState *nc,const uint8_t *buf,size_t size_) { -NE2000State *s = vc->opaque; +NE2000State *s =DO_UPCAST (NICState, nc, nc)->opaque;int size = size_;uint8_t *p;unsigned int total_len, next, avail, len, index, mcast_idx;
@@ -323,7 +323,7 @@ void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val) index -=NE2000_PMEM_SIZE ;/* fail safe: check range on the transmitted length */ if (index + s->tcnt <=NE2000_PMEM_END ) { -qemu_send_packet (s->vc, s->mem + index, s->tcnt); +qemu_send_packet (&s->nic->nc, s->mem + index, s->tcnt); }/* signal end of transfer */ s->tsr =ENTSR_PTX ;
@@ -698,13 +698,21 @@ static void ne2000_map(PCIDevice *pci_dev, int region_num,register_ioport_read (addr +0x1f ,1 ,1 , ne2000_reset_ioport_read, s); } -static void ne2000_cleanup (VLANClientState *vc) +static void ne2000_cleanup (VLANClientState *nc) { -NE2000State *s = vc->opaque; +NE2000State *s =DO_UPCAST (NICState, nc, nc)->opaque; - s->vc =NULL ; + s->nic =NULL ; } +static NetClientInfo net_ne2000_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = ne2000_can_receive, + .receive = ne2000_receive, + .cleanup = ne2000_cleanup, +}; +static int pci_ne2000_init (PCIDevice *pci_dev) {PCINE2000State *d =DO_UPCAST (PCINE2000State, dev, pci_dev);
@@ -725,11 +733,10 @@ static int pci_ne2000_init(PCIDevice *pci_dev)qemu_macaddr_default_if_unset (&s->c.macaddr);ne2000_reset (s); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , s->c.vlan, s->c.peer, - pci_dev->qdev.info->name, pci_dev->qdev.id, - ne2000_can_receive, ne2000_receive,NULL , -NULL , ne2000_cleanup, s); -qemu_format_nic_info_str (s->vc, s->c.macaddr.a); + + s->nic =qemu_new_nic (&net_ne2000_info, &s->c, + pci_dev->qdev.info->name, pci_dev->qdev.id, s); +qemu_format_nic_info_str (&s->nic->nc, s->c.macaddr.a);if (!pci_dev->qdev.hotplugged) {static int loaded =0 ;
@@ -749,7 +756,7 @@ static int pci_ne2000_exit(PCIDevice *pci_dev)NE2000State *s = &d->ne2000;vmstate_unregister (&vmstate_pci_ne2000, s); -qemu_del_vlan_client (s->vc); +qemu_del_vlan_client (&s->nic->nc);return 0 ; }
hw/ne2000.h +1 -1
@@ -22,7 +22,7 @@ typedef struct NE2000State {uint8_t curpag;uint8_t mult[8 ];/* multicast mask array */ qemu_irq irq; -VLANClientState *vc; +NICState *nic;NICConf c;uint8_t mem[NE2000_MEM_SIZE ]; } NE2000State;
Signature · 1 line
1.6.5.2
PATCH 22/44 net: convert pcnet to NICState
In reply to Mark McLoughlin--- hw/lance.c | 14 +++++++++++--- hw/pcnet.c | 43 +++++++++++++++++++++++-------------------- hw/pcnet.h | 7 ++++--- 3 files changed, 38 insertions(+), 26 deletions(-)
hw/lance.c +11 -3
@@ -92,14 +92,22 @@ static CPUWriteMemoryFunc * const lance_mem_write[3] = { NULL, }; -static void lance_cleanup (VLANClientState *vc) +static void lance_cleanup (VLANClientState *nc) { -PCNetState *d = vc->opaque; +PCNetState *d =DO_UPCAST (NICState, nc, nc)->opaque;vmstate_unregister (&vmstate_pcnet, d);pcnet_common_cleanup (d); } +static NetClientInfo net_lance_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = pcnet_can_receive, + .receive = pcnet_receive, + .cleanup = lance_cleanup, +}; +static int lance_init (SysBusDevice *dev) {SysBusPCNetState *d =FROM_SYSBUS (SysBusPCNetState, dev);
@@ -118,7 +126,7 @@ static int lance_init(SysBusDevice *dev) s->phys_mem_write = ledma_memory_write;vmstate_register (-1 , &vmstate_pcnet, d); -return pcnet_common_init (&dev->qdev, s, lance_cleanup); +return pcnet_common_init (&dev->qdev, s, &net_lance_info); }static void lance_reset (DeviceState *dev)
hw/pcnet.c +23 -20
99 lines not on this page · raw message
hw/pcnet.h +4 -3
@@ -8,7 +8,7 @@typedef struct PCNetState_st PCNetState ;struct PCNetState_st { -VLANClientState *vc; +NICState *nic;NICConf conf;QEMUTimer *poll_timer;int rap, isr, lnkst;
@@ -32,7 +32,8 @@ struct PCNetState_st {void pcnet_h_reset (void *opaque);void pcnet_ioport_writew (void *opaque,uint32_t addr,uint32_t val);uint32_t pcnet_ioport_readw (void *opaque,uint32_t addr); +int pcnet_can_receive (VLANClientState *nc); +ssize_t pcnet_receive (VLANClientState *nc,const uint8_t *buf,size_t size_);void pcnet_common_cleanup (PCNetState *d); -int pcnet_common_init (DeviceState *dev,PCNetState *s, -NetCleanup *cleanup); +int pcnet_common_init (DeviceState *dev,PCNetState *s,NetClientInfo *info);extern const VMStateDescription vmstate_pcnet;
Signature · 1 line
1.6.5.2
PATCH 23/44 net: convert eepro100 to NICState
In reply to Mark McLoughlin--- hw/eepro100.c | 43 ++++++++++++++++++++++++------------------- 1 files changed, 24 insertions(+), 19 deletions(-)
hw/eepro100.c +24 -19
@@ -195,7 +195,7 @@ typedef struct {PCIDevice dev;uint8_t mult[8 ];/* multicast mask array */ int mmio_index; -VLANClientState *vc; +NICState *nic;NICConf conf;uint8_t scb_stat;/* SCB stat/ack byte */ uint8_t int_stat;/* PCI interrupt status */
@@ -868,7 +868,7 @@ static void action_command(EEPRO100State *s) } }TRACE (RXTX ,logout ("%p sending frame, len=%d,%s\n" , s, size,nic_dump (buf, size))); -qemu_send_packet (s->vc, buf, size); +qemu_send_packet (&s->nic->nc, buf, size); s->statistics.tx_good_frames++;/* Transmit with bad status would raise an CX/TNO interrupt. * (82557 only). Emulation never has bad status. */
@@ -1599,21 +1599,21 @@ static void pci_mmio_map(PCIDevice * pci_dev, int region_num, } } -static int nic_can_receive (VLANClientState *vc) +static int nic_can_receive (VLANClientState *nc) { -EEPRO100State *s = vc->opaque; +EEPRO100State *s =DO_UPCAST (NICState, nc, nc)->opaque;TRACE (RXTX ,logout ("%p\n" , s));return get_ru_state (s) == ru_ready;//~ return !eepro100_buffer_full(s); } -static ssize_t nic_receive (VLANClientState *vc,const uint8_t * buf,size_t size) +static ssize_t nic_receive (VLANClientState *nc,const uint8_t * buf,size_t size) {/* TODO: * - Magic packets should set bit 30 in power management driver register. * - Interesting packets should set bit 29 in power management driver register. */ -EEPRO100State *s = vc->opaque; +EEPRO100State *s =DO_UPCAST (NICState, nc, nc)->opaque;uint16_t rfd_status =0xa000 ;static const uint8_t broadcast_macaddr[6 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff };
@@ -1779,11 +1779,11 @@ static const VMStateDescription vmstate_eepro100 = { } }; -static void nic_cleanup (VLANClientState *vc) +static void nic_cleanup (VLANClientState *nc) { -EEPRO100State *s = vc->opaque; +EEPRO100State *s =DO_UPCAST (NICState, nc, nc)->opaque; - s->vc =NULL ; + s->nic =NULL ; }static int pci_nic_uninit (PCIDevice *pci_dev)
@@ -1793,10 +1793,18 @@ static int pci_nic_uninit(PCIDevice *pci_dev)cpu_unregister_io_memory (s->mmio_index);vmstate_unregister (s->vmstate, s);eeprom93xx_free (s->eeprom); -qemu_del_vlan_client (s->vc); +qemu_del_vlan_client (&s->nic->nc);return 0 ; } +static NetClientInfo net_eepro100_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = nic_can_receive, + .receive = nic_receive, + .cleanup = nic_cleanup, +}; +static int nic_init (PCIDevice *pci_dev,uint32_t device) {EEPRO100State *s =DO_UPCAST (EEPRO100State, dev, pci_dev);
@@ -1829,27 +1837,24 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)nic_reset (s); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - pci_dev->qdev.info->name, pci_dev->qdev.id, - nic_can_receive, nic_receive,NULL ,NULL , - nic_cleanup, s); + s->nic =qemu_new_nic (&net_eepro100_info, &s->conf, + pci_dev->qdev.info->name, pci_dev->qdev.id, s); -qemu_format_nic_info_str (s->vc, s->conf.macaddr.a); -TRACE (OTHER ,logout ("%s\n" , s->vc->info_str)); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a); +TRACE (OTHER ,logout ("%s\n" , s->nic->nc.info_str));qemu_register_reset (nic_reset, s); s->vmstate =qemu_malloc (sizeof (vmstate_eepro100));memcpy (s->vmstate, &vmstate_eepro100,sizeof (vmstate_eepro100)); - s->vmstate->name = s->vc->model; + s->vmstate->name = s->nic->nc.model;vmstate_register (-1 , s->vmstate, s);if (!pci_dev->qdev.hotplugged) {static int loaded =0 ;if (!loaded) {char fname[32 ]; -snprintf (fname,sizeof (fname),"pxe-%s.bin" , s->vc->model); +snprintf (fname,sizeof (fname),"pxe-%s.bin" , s->nic->nc.model);rom_add_option (fname); loaded =1 ; }
Signature · 1 line
1.6.5.2
PATCH 24/44 net: convert dp8393x to NICState
In reply to Mark McLoughlin--- hw/dp8393x.c | 41 +++++++++++++++++++++++++---------------- 1 files changed, 25 insertions(+), 16 deletions(-)
hw/dp8393x.c +25 -16
@@ -154,7 +154,8 @@ typedef struct dp8393xState {#endif QEMUTimer *watchdog;int64_t wt_last_update; -VLANClientState *vc; +NICConf conf; +NICState *nic;int mmio_index;/* Registers */
@@ -406,13 +407,13 @@ static void do_transmit_packets(dp8393xState *s)if (s->regs[SONIC_RCR ] & (SONIC_RCR_LB1 |SONIC_RCR_LB0 )) {/* Loopback */ s->regs[SONIC_TCR ] |=SONIC_TCR_CRSL ; -if (s->vc->can_receive (s->vc)) { +if (s->nic->nc.can_receive (&s->nic->nc)) { s->loopback_packet =1 ; - s->vc->receive (s->vc, s->tx_buffer, tx_len); + s->nic->nc.receive (&s->nic->nc, s->tx_buffer, tx_len); } }else {/* Transmit packet */ -qemu_send_packet (s->vc, s->tx_buffer, tx_len); +qemu_send_packet (&s->nic->nc, s->tx_buffer, tx_len); } s->regs[SONIC_TCR ] |=SONIC_TCR_PTX ;
@@ -675,9 +676,9 @@ static CPUWriteMemoryFunc * const dp8393x_write[3] = { dp8393x_writel, }; -static int nic_can_receive (VLANClientState *vc) +static int nic_can_receive (VLANClientState *nc) { -dp8393xState *s = vc->opaque; +dp8393xState *s =DO_UPCAST (NICState, nc, nc)->opaque;if (!(s->regs[SONIC_CR ] &SONIC_CR_RXEN ))return 0 ;
@@ -724,10 +725,10 @@ static int receive_filter(dp8393xState *s, const uint8_t * buf, int size)return -1 ; } -static ssize_t nic_receive (VLANClientState *vc,const uint8_t * buf,size_t size) +static ssize_t nic_receive (VLANClientState *nc,const uint8_t * buf,size_t size) { +dp8393xState *s =DO_UPCAST (NICState, nc, nc)->opaque;uint16_t data[10 ]; -dp8393xState *s = vc->opaque;int packet_type;uint32_t available, address;int width, rx_len = size;
@@ -860,9 +861,9 @@ static void nic_reset(void *opaque)dp8393x_update_irq (s); } -static void nic_cleanup (VLANClientState *vc) +static void nic_cleanup (VLANClientState *nc) { -dp8393xState *s = vc->opaque; +dp8393xState *s =DO_UPCAST (NICState, nc, nc)->opaque;cpu_unregister_io_memory (s->mmio_index);
@@ -872,6 +873,14 @@ static void nic_cleanup(VLANClientState *vc)qemu_free (s); } +static NetClientInfo net_dp83932_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = nic_can_receive, + .receive = nic_receive, + .cleanup = nic_cleanup, +}; +void dp83932_init (NICInfo *nd,target_phys_addr_t base,int it_shift,qemu_irq irq,void * mem_opaque,void (*memory_rw)(void *opaque,target_phys_addr_t addr,uint8_t *buf,int len,int is_write))
@@ -889,13 +898,13 @@ 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 =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - nic_can_receive, nic_receive,NULL ,NULL , - nic_cleanup, s); +memcpy (s->conf.macaddr.a, nd->macaddr,sizeof (s->conf.macaddr)); + s->conf.vlan = nd->vlan; + s->conf.peer = nd->netdev; + + s->nic =qemu_new_nic (&net_dp83932_info, &s->conf, nd->model, nd->name, s); -qemu_format_nic_info_str (s->vc, nd->macaddr); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a);qemu_register_reset (nic_reset, s);nic_reset (s);
Signature · 1 line
1.6.5.2
PATCH 25/44 net: convert etrax to NICState
In reply to Mark McLoughlin--- hw/etraxfs_eth.c | 45 +++++++++++++++++++++++++++------------------ 1 files changed, 27 insertions(+), 18 deletions(-)
hw/etraxfs_eth.c +27 -18
@@ -319,7 +319,8 @@ static void mdio_cycle(struct qemu_mdio *bus)struct fs_eth { -VLANClientState *vc; +NICState *nic; +NICConf conf;int ethregs;/* Two addrs in the filter. */
@@ -495,15 +496,15 @@ static int eth_match_groupaddr(struct fs_eth *eth, const unsigned char *sa)return match; } -static int eth_can_receive (VLANClientState *vc) +static int eth_can_receive (VLANClientState *nc) {return 1 ; } -static ssize_t eth_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t eth_receive (VLANClientState *nc,const uint8_t *buf,size_t size) {unsigned char sa_bcast[6 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff }; -struct fs_eth *eth = vc->opaque; +struct fs_eth *eth =DO_UPCAST (NICState, nc, nc)->opaque;int use_ma0 = eth->regs[RW_REC_CTRL ] &1 ;int use_ma1 = eth->regs[RW_REC_CTRL ] &2 ;int r_bcast = eth->regs[RW_REC_CTRL ] &8 ;
@@ -533,15 +534,15 @@ static int eth_tx_push(void *opaque, unsigned char *buf, int len)struct fs_eth *eth = opaque;D (printf ("%s buf=%p len=%d\n" , __func__, buf, len)); -qemu_send_packet (eth->vc, buf, len); +qemu_send_packet (ð->nic->nc, buf, len);return len; } -static void eth_set_link (VLANClientState *vc) +static void eth_set_link (VLANClientState *nc) { -struct fs_eth *eth = vc->opaque; -D (printf ("%s %d\n" , __func__, vc->link_down)); - eth->phy.link = !vc->link_down; +struct fs_eth *eth =DO_UPCAST (NICState, nc, nc)->opaque; +D (printf ("%s %d\n" , __func__, nc->link_down)); + eth->phy.link = !nc->link_down; }static CPUReadMemoryFunc *const eth_read[] = {
@@ -554,9 +555,9 @@ static CPUWriteMemoryFunc * const eth_write[] = { ð_writel, }; -static void eth_cleanup (VLANClientState *vc) +static void eth_cleanup (VLANClientState *nc) { -struct fs_eth *eth = vc->opaque; +struct fs_eth *eth =DO_UPCAST (NICState, nc, nc)->opaque;cpu_unregister_io_memory (eth->ethregs);
@@ -564,6 +565,15 @@ static void eth_cleanup(VLANClientState *vc)qemu_free (eth); } +static NetClientInfo net_etraxfs_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = eth_can_receive, + .receive = eth_receive, + .cleanup = eth_cleanup, + .link_status_changed = eth_set_link, +}; +void *etraxfs_eth_init (NICInfo *nd,target_phys_addr_t base,int phyaddr) {struct etraxfs_dma_client *dma =NULL ;
@@ -590,13 +600,12 @@ 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 =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - eth_can_receive, eth_receive, -NULL ,NULL , eth_cleanup, eth); - eth->vc->opaque = eth; - eth->vc->link_status_changed = eth_set_link; +memcpy (eth->conf.macaddr.a, nd->macaddr,sizeof (nd->macaddr)); + eth->conf.vlan = nd->vlan; + eth->conf.peer = nd->netdev; + + eth->nic =qemu_new_nic (&net_etraxfs_info, ð->conf, + nd->model, nd->name, eth);return dma; }
Signature · 1 line
1.6.5.2
PATCH 26/44 net: convert LAN9118 to NICState
In reply to Mark McLoughlin--- hw/lan9118.c | 45 +++++++++++++++++++++++++-------------------- 1 files changed, 25 insertions(+), 20 deletions(-)
hw/lan9118.c +25 -20
@@ -137,7 +137,7 @@ typedef struct { typedef struct { SysBusDevice busdev; - VLANClientState *vc; + NICState *nic; NICConf conf; qemu_irq irq; int mmio_index;
@@ -212,7 +212,7 @@ static void lan9118_update(lan9118_state *s)static void lan9118_mac_changed (lan9118_state *s) { -qemu_format_nic_info_str (s->vc, s->conf.macaddr.a); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a); }static void lan9118_reload_eeprom (lan9118_state *s)
@@ -234,16 +234,16 @@ static void lan9118_reload_eeprom(lan9118_state *s)static void phy_update_link (lan9118_state *s) {/* Autonegotiation status mirrors link status. */ -if (s->vc->link_down) { +if (s->nic->nc.link_down) { s->phy_status &= ~0x0024 ; }else { s->phy_status |=0x0024 ; } } -static void lan9118_set_link (VLANClientState *vc) +static void lan9118_set_link (VLANClientState *nc) { -phy_update_link (vc->opaque); +phy_update_link (DO_UPCAST (NICState, nc, nc)->opaque); }static void phy_reset (lan9118_state *s)
@@ -305,7 +305,7 @@ static void lan9118_reset(DeviceState *d)lan9118_reload_eeprom (s); } -static int lan9118_can_receive (VLANClientState *vc) +static int lan9118_can_receive (VLANClientState *nc) {return 1 ; }
@@ -358,10 +358,10 @@ static int lan9118_filter(lan9118_state *s, const uint8_t *addr) } } -static ssize_t lan9118_receive (VLANClientState *vc,const uint8_t *buf, +static ssize_t lan9118_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -lan9118_state *s = vc->opaque; +lan9118_state *s =DO_UPCAST (NICState, nc, nc)->opaque;int fifo_len;int offset;int src_pos;
@@ -506,9 +506,9 @@ static void do_tx_packet(lan9118_state *s)/* FIXME: Honor TX disable, and allow queueing of packets. */ if (s->phy_control &0x4000 ) {/* This assumes the receive routine doesn't touch the VLANClient. */ -lan9118_receive (s->vc, s->txp->data, s->txp->len); +lan9118_receive (&s->nic->nc, s->txp->data, s->txp->len); }else { -qemu_send_packet (s->vc, s->txp->data, s->txp->len); +qemu_send_packet (&s->nic->nc, s->txp->data, s->txp->len); } s->txp->fifo_used =0 ;
@@ -1022,13 +1022,22 @@ static CPUWriteMemoryFunc * const lan9118_writefn[] = { lan9118_writel }; -static void lan9118_cleanup (VLANClientState *vc) +static void lan9118_cleanup (VLANClientState *nc) { -lan9118_state *s = vc->opaque; +lan9118_state *s =DO_UPCAST (NICState, nc, nc)->opaque; - s->vc =NULL ; + s->nic =NULL ; } +static NetClientInfo net_lan9118_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = lan9118_can_receive, + .receive = lan9118_receive, + .cleanup = lan9118_cleanup, + .link_status_changed = lan9118_set_link, +}; +static int lan9118_init1 (SysBusDevice *dev) {lan9118_state *s =FROM_SYSBUS (lan9118_state, dev);
@@ -1040,13 +1049,9 @@ static int lan9118_init1(SysBusDevice *dev)sysbus_init_irq (dev, &s->irq);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, - lan9118_can_receive, lan9118_receive,NULL , -NULL , lan9118_cleanup, s); - s->vc->link_status_changed = lan9118_set_link; -qemu_format_nic_info_str (s->vc, s->conf.macaddr.a); + s->nic =qemu_new_nic (&net_lan9118_info, &s->conf, + dev->qdev.info->name, dev->qdev.id, s); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a); s->eeprom[0 ] =0xa5 ;for (i =0 ; i <6 ; i++) { s->eeprom[i +1 ] = s->conf.macaddr.a[i];
Signature · 1 line
1.6.5.2
PATCH 27/44 net: convert mcf_fec to NICState
In reply to Mark McLoughlin--- hw/mcf_fec.c | 58 +++++++++++++++++++++++++++++++++------------------------- 1 files changed, 33 insertions(+), 25 deletions(-)
hw/mcf_fec.c +33 -25
@@ -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); }
Signature · 1 line
1.6.5.2
PATCH 28/44 net: convert mipsnet to NICState
In reply to Mark McLoughlin--- hw/mipsnet.c | 45 +++++++++++++++++++++++++++------------------ 1 files changed, 27 insertions(+), 18 deletions(-)
hw/mipsnet.c +27 -18
@@ -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);
Signature · 1 line
1.6.5.2
PATCH 29/44 net: convert musicpal to NICState
In reply to Mark McLoughlin--- hw/musicpal.c | 31 ++++++++++++++++++------------- 1 files changed, 18 insertions(+), 13 deletions(-)
hw/musicpal.c +18 -13
@@ -151,7 +151,7 @@ typedef struct mv88w8618_eth_state {uint32_t rx_queue[4 ];uint32_t frx_queue[4 ];uint32_t cur_rx[4 ]; -VLANClientState *vc; +NICState *nic;NICConf conf; } mv88w8618_eth_state;
@@ -175,14 +175,14 @@ static void eth_rx_desc_get(uint32_t addr, mv88w8618_rx_desc *desc)le32_to_cpus (&desc->next); } -static int eth_can_receive (VLANClientState *vc) +static int eth_can_receive (VLANClientState *nc) {return 1 ; } -static ssize_t eth_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t eth_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -mv88w8618_eth_state *s = vc->opaque; +mv88w8618_eth_state *s =DO_UPCAST (NICState, nc, nc)->opaque;uint32_t desc_addr;mv88w8618_rx_desc desc;int i;
@@ -250,7 +250,7 @@ static void eth_send(mv88w8618_eth_state *s, int queue_index) len = desc.bytes;if (len <2048 ) {cpu_physical_memory_read (desc.buffer, buf, len); -qemu_send_packet (s->vc, buf, len); +qemu_send_packet (&s->nic->nc, buf, len); } desc.cmdstat &= ~MP_ETH_TX_OWN ; s->icr |=1 << (MP_ETH_IRQ_TXLO_BIT - queue_index);
@@ -365,23 +365,28 @@ static CPUWriteMemoryFunc * const mv88w8618_eth_writefn[] = {mv88w8618_eth_write }; -static void eth_cleanup (VLANClientState *vc) +static void eth_cleanup (VLANClientState *nc) { -mv88w8618_eth_state *s = vc->opaque; +mv88w8618_eth_state *s =DO_UPCAST (NICState, nc, nc)->opaque; - s->vc =NULL ; + s->nic =NULL ; } +static NetClientInfo net_mv88w8618_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = eth_can_receive, + .receive = eth_receive, + .cleanup = eth_cleanup, +}; +static int mv88w8618_eth_init (SysBusDevice *dev) {mv88w8618_eth_state *s =FROM_SYSBUS (mv88w8618_eth_state, dev);sysbus_init_irq (dev, &s->irq); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - dev->qdev.info->name, dev->qdev.id, - eth_can_receive, eth_receive,NULL , -NULL , eth_cleanup, s); + s->nic =qemu_new_nic (&net_mv88w8618_info, &s->conf, + dev->qdev.info->name, dev->qdev.id, s); s->mmio_index =cpu_register_io_memory (mv88w8618_eth_readfn, mv88w8618_eth_writefn, s);sysbus_init_mmio (dev,MP_ETH_SIZE , s->mmio_index);
Signature · 1 line
1.6.5.2
PATCH 30/44 net: convert smc91c111 to NICState
In reply to Mark McLoughlin--- hw/smc91c111.c | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-)
hw/smc91c111.c +20 -15
@@ -18,7 +18,7 @@ typedef struct { SysBusDevice busdev; - VLANClientState *vc; + NICState *nic; NICConf conf; uint16_t tcr; uint16_t rcr;
@@ -207,7 +207,7 @@ static void smc91c111_do_tx(smc91c111_state *s)smc91c111_release_packet (s, packetnum); else if (s->tx_fifo_done_len < NUM_PACKETS) s->tx_fifo_done[s->tx_fifo_done_len++] = packetnum; -qemu_send_packet (s->vc, p, len); +qemu_send_packet (&s->nic->nc, p, len); } s->tx_fifo_len =0 ;smc91c111_update (s);
@@ -591,9 +591,9 @@ static uint32_t smc91c111_readl(void *opaque, target_phys_addr_t offset)return val; } -static int smc91c111_can_receive (VLANClientState *vc) +static int smc91c111_can_receive (VLANClientState *nc) { -smc91c111_state *s = vc->opaque; +smc91c111_state *s =DO_UPCAST (NICState, nc, nc)->opaque;if ((s->rcr &RCR_RXEN ) ==0 || (s->rcr &RCR_SOFT_RST ))return 1 ;
@@ -602,9 +602,9 @@ static int smc91c111_can_receive(VLANClientState *vc)return 1 ; } -static ssize_t smc91c111_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t smc91c111_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -smc91c111_state *s = vc->opaque; +smc91c111_state *s =DO_UPCAST (NICState, nc, nc)->opaque;int status;int packetsize;uint32_t crc;
@@ -692,13 +692,21 @@ static CPUWriteMemoryFunc * const smc91c111_writefn[] = { smc91c111_writel }; -static void smc91c111_cleanup (VLANClientState *vc) +static void smc91c111_cleanup (VLANClientState *nc) { -smc91c111_state *s = vc->opaque; +smc91c111_state *s =DO_UPCAST (NICState, nc, nc)->opaque; - s->vc =NULL ; + s->nic =NULL ; } +static NetClientInfo net_smc91c111_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = smc91c111_can_receive, + .receive = smc91c111_receive, + .cleanup = smc91c111_cleanup, +}; +static int smc91c111_init1 (SysBusDevice *dev) {smc91c111_state *s =FROM_SYSBUS (smc91c111_state, dev);
@@ -711,12 +719,9 @@ static int smc91c111_init1(SysBusDevice *dev)smc91c111_reset (s); - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - s->conf.vlan, s->conf.peer, - dev->qdev.info->name, dev->qdev.id, - smc91c111_can_receive, smc91c111_receive,NULL , -NULL , smc91c111_cleanup, s); -qemu_format_nic_info_str (s->vc, s->conf.macaddr.a); + s->nic =qemu_new_nic (&net_smc91c111_info, &s->conf, + dev->qdev.info->name, dev->qdev.id, s); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a);/* ??? Save/restore. */ return 0 ; }
Signature · 1 line
1.6.5.2
PATCH 31/44 net: convert stellaris to NICState
In reply to Mark McLoughlin--- hw/stellaris_enet.c | 34 +++++++++++++++++++--------------- 1 files changed, 19 insertions(+), 15 deletions(-)
hw/stellaris_enet.c +19 -15
@@ -66,7 +66,7 @@ typedef struct {uint8_t *rx_fifo;int rx_fifo_len;int next_packet; -VLANClientState *vc; +NICState *nic;NICConf conf;qemu_irq irq;int mmio_index;
@@ -78,9 +78,9 @@ static void stellaris_enet_update(stellaris_enet_state *s) }/* TODO: Implement MAC address filtering. */ -static ssize_t stellaris_enet_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t stellaris_enet_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -stellaris_enet_state *s = vc->opaque; +stellaris_enet_state *s =DO_UPCAST (NICState, nc, nc)->opaque;int n;uint8_t *p;uint32_t crc;
@@ -120,9 +120,9 @@ static ssize_t stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, sreturn size; } -static int stellaris_enet_can_receive (VLANClientState *vc) +static int stellaris_enet_can_receive (VLANClientState *nc) { -stellaris_enet_state *s = vc->opaque; +stellaris_enet_state *s =DO_UPCAST (NICState, nc, nc)->opaque;if ((s->rctl &SE_RCTL_RXEN ) ==0 )return 1 ;
@@ -258,7 +258,7 @@ static void stellaris_enet_write(void *opaque, target_phys_addr_t offset,memset (&s->tx_fifo[s->tx_frame_len],0 ,60 - s->tx_frame_len); s->tx_fifo_len =60 ; } -qemu_send_packet (s->vc, s->tx_fifo, s->tx_frame_len); +qemu_send_packet (&s->nic->nc, s->tx_fifo, s->tx_frame_len); s->tx_frame_len =-1 ; s->ris |=SE_INT_TXEMP ;stellaris_enet_update (s);
@@ -385,9 +385,9 @@ static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id)return 0 ; } -static void stellaris_enet_cleanup (VLANClientState *vc) +static void stellaris_enet_cleanup (VLANClientState *nc) { -stellaris_enet_state *s = vc->opaque; +stellaris_enet_state *s =DO_UPCAST (NICState, nc, nc)->opaque;unregister_savevm ("stellaris_enet" , s);
@@ -396,6 +396,14 @@ static void stellaris_enet_cleanup(VLANClientState *vc)qemu_free (s); } +static NetClientInfo net_stellaris_enet_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = stellaris_enet_can_receive, + .receive = stellaris_enet_receive, + .cleanup = stellaris_enet_cleanup, +}; +static int stellaris_enet_init (SysBusDevice *dev) {stellaris_enet_state *s =FROM_SYSBUS (stellaris_enet_state, dev);
@@ -406,13 +414,9 @@ static int stellaris_enet_init(SysBusDevice *dev)sysbus_init_irq (dev, &s->irq);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, - stellaris_enet_can_receive, - stellaris_enet_receive,NULL ,NULL , - stellaris_enet_cleanup, s); -qemu_format_nic_info_str (s->vc, s->conf.macaddr.a); + s->nic =qemu_new_nic (&net_stellaris_enet_info, &s->conf, + dev->qdev.info->name, dev->qdev.id, s); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a);stellaris_enet_reset (s); register_savevm("stellaris_enet", -1, 1,
Signature · 1 line
1.6.5.2
PATCH 32/44 net: convert usb-net to NICState
In reply to Mark McLoughlin--- hw/usb-net.c | 57 +++++++++++++++++++++++++++++++-------------------------- 1 files changed, 31 insertions(+), 26 deletions(-)
hw/usb-net.c +31 -26
@@ -610,7 +610,6 @@ typedef struct USBNetState {uint32_t media_state;uint16_t filter;uint32_t vendorid; -uint8_t mac[6 ];unsigned int out_ptr;uint8_t out_buf[2048 ];
@@ -620,7 +619,8 @@ typedef struct USBNetState {uint8_t in_buf[2048 ];char usbstring_mac[13 ]; -VLANClientState *vc; +NICState *nic; +NICConf conf; QTAILQ_HEAD(rndis_resp_head, rndis_response) rndis_resp; } USBNetState;
@@ -741,12 +741,12 @@ static int ndis_query(USBNetState *s, uint32_t oid,/* ieee802.3 OIDs (table 4-3) */ /* mandatory */ case OID_802_3_PERMANENT_ADDRESS : -memcpy (outbuf, s->mac,6 ); +memcpy (outbuf, s->conf.macaddr.a,6 );return 6 ;/* mandatory */ case OID_802_3_CURRENT_ADDRESS : -memcpy (outbuf, s->mac,6 ); +memcpy (outbuf, s->conf.macaddr.a,6 );return 6 ;/* mandatory */
@@ -1305,7 +1305,7 @@ static int usb_net_handle_dataout(USBNetState *s, USBPacket *p)if (!s->rndis) {if (ret <64 ) { -qemu_send_packet (s->vc, s->out_buf, s->out_ptr); +qemu_send_packet (&s->nic->nc, s->out_buf, s->out_ptr); s->out_ptr =0 ; }return ret;
@@ -1317,7 +1317,7 @@ static int usb_net_handle_dataout(USBNetState *s, USBPacket *p)uint32_t offs =8 +le32_to_cpu (msg->DataOffset);uint32_t size =le32_to_cpu (msg->DataLength);if (offs + size <= len) -qemu_send_packet (s->vc, s->out_buf + offs, size); +qemu_send_packet (&s->nic->nc, s->out_buf + offs, size); } s->out_ptr -= len;memmove (s->out_buf, &s->out_buf[len], s->out_ptr);
@@ -1369,9 +1369,9 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p)return ret; } -static ssize_t usbnet_receive (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t usbnet_receive (VLANClientState *nc,const uint8_t *buf,size_t size) { -USBNetState *s = vc->opaque; +USBNetState *s =DO_UPCAST (NICState, nc, nc)->opaque;struct rndis_packet_msg_type *msg;if (s->rndis) {
@@ -1406,9 +1406,9 @@ static ssize_t usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t sireturn size; } -static int usbnet_can_receive (VLANClientState *vc) +static int usbnet_can_receive (VLANClientState *nc) { -USBNetState *s = vc->opaque; +USBNetState *s =DO_UPCAST (NICState, nc, nc)->opaque;if (s->rndis && !s->rndis_state ==RNDIS_DATA_INITIALIZED )return 1 ;
@@ -1416,9 +1416,9 @@ static int usbnet_can_receive(VLANClientState *vc)return !s->in_len; } -static void usbnet_cleanup (VLANClientState *vc) +static void usbnet_cleanup (VLANClientState *nc) { -USBNetState *s = vc->opaque; +USBNetState *s =DO_UPCAST (NICState, nc, nc)->opaque;rndis_clear_responsequeue (s);qemu_free (s);
@@ -1429,7 +1429,7 @@ static void usb_net_handle_destroy(USBDevice *dev)USBNetState *s = (USBNetState *) dev;/* TODO: remove the nd_table[] entry */ -qemu_del_vlan_client (s->vc); +qemu_del_vlan_client (&s->nic->nc); }static int usb_net_initfn (USBDevice *dev)
@@ -1450,6 +1450,14 @@ static int usb_net_initfn(USBDevice *dev)return 0 ; } +static NetClientInfo net_usbnet_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = usbnet_can_receive, + .receive = usbnet_receive, + .cleanup = usbnet_cleanup, +}; +USBDevice *usb_net_init (NICInfo *nd) {USBDevice *dev;
@@ -1458,25 +1466,22 @@ USBDevice *usb_net_init(NICInfo *nd) dev =usb_create_simple (NULL /* FIXME */ ,"QEMU USB Network Interface" ); s =DO_UPCAST (USBNetState, dev, dev); -memcpy (s->mac, nd->macaddr,6 ); +memcpy (s->conf.macaddr.a, nd->macaddr,sizeof (nd->macaddr)); + s->conf.vlan = nd->vlan; + s->conf.peer = nd->netdev; - s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - usbnet_can_receive, - usbnet_receive, -NULL ,NULL , - usbnet_cleanup, s); + s->nic =qemu_new_nic (&net_usbnet_info, &s->conf, + nd->model, nd->name, s); -qemu_format_nic_info_str (s->vc, s->mac); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a);snprintf (s->usbstring_mac,sizeof (s->usbstring_mac),"%02x%02x%02x%02x%02x%02x" , -0x40 , s->mac[1 ], s->mac[2 ], - s->mac[3 ], s->mac[4 ], s->mac[5 ]); +0x40 , s->conf.macaddr.a[1 ], s->conf.macaddr.a[2 ], + s->conf.macaddr.a[3 ], s->conf.macaddr.a[4 ], s->conf.macaddr.a[5 ]);fprintf (stderr,"usbnet: initialized mac %02x:%02x:%02x:%02x:%02x:%02x\n" , - s->mac[0 ], s->mac[1 ], s->mac[2 ], - s->mac[3 ], s->mac[4 ], s->mac[5 ]); + s->conf.macaddr.a[0 ], s->conf.macaddr.a[1 ], s->conf.macaddr.a[2 ], + s->conf.macaddr.a[3 ], s->conf.macaddr.a[4 ], s->conf.macaddr.a[5 ]);return (USBDevice *) s; }
Signature · 1 line
1.6.5.2
PATCH 33/44 net: convert xilinx_ethlite to NICState
In reply to Mark McLoughlin--- hw/xilinx_ethlite.c | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-)
hw/xilinx_ethlite.c +20 -15
@@ -51,7 +51,7 @@ struct xlx_ethlite {SysBusDevice busdev;qemu_irq irq; -VLANClientState *vc; +NICState *nic;NICConf conf;uint32_t c_tx_pingpong;
@@ -118,7 +118,7 @@ eth_writel (void *opaque, target_phys_addr_t addr, uint32_t value)D (qemu_log ("%s addr=%x val=%x\n" , __func__, addr *4 , value));if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) { -qemu_send_packet (s->vc, +qemu_send_packet (&s->nic->nc, (void *) &s->regs[base], s->regs[base +R_TX_LEN0 ]);D (qemu_log ("eth_tx %d\n" , s->regs[base +R_TX_LEN0 ]));
@@ -160,17 +160,17 @@ static CPUWriteMemoryFunc * const eth_write[] = { NULL, NULL, ð_writel, }; -static int eth_can_rx (VLANClientState *vc) +static int eth_can_rx (VLANClientState *nc) { -struct xlx_ethlite *s = vc->opaque; +struct xlx_ethlite *s =DO_UPCAST (NICState, nc, nc)->opaque;int r; r = !(s->regs[R_RX_CTRL0 ] &CTRL_S );return r; } -static ssize_t eth_rx (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t eth_rx (VLANClientState *nc,const uint8_t *buf,size_t size) { -struct xlx_ethlite *s = vc->opaque; +struct xlx_ethlite *s =DO_UPCAST (NICState, nc, nc)->opaque;unsigned int rxbase = s->rxbuf * (0x800 /4 );int i;
@@ -201,13 +201,21 @@ static ssize_t eth_rx(VLANClientState *vc, const uint8_t *buf, size_t size)return size; } -static void eth_cleanup (VLANClientState *vc) +static void eth_cleanup (VLANClientState *nc) { -struct xlx_ethlite *s = vc->opaque; +struct xlx_ethlite *s =DO_UPCAST (NICState, nc, nc)->opaque; - s->vc =NULL ; + s->nic =NULL ; } +static NetClientInfo net_xilinx_ethlite_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = eth_can_rx, + .receive = eth_rx, + .cleanup = eth_cleanup, +}; +static int xilinx_ethlite_init (SysBusDevice *dev) {struct xlx_ethlite *s =FROM_SYSBUS (typeof (*s), dev);
@@ -220,12 +228,9 @@ static int xilinx_ethlite_init(SysBusDevice *dev)sysbus_init_mmio (dev,R_MAX *4 , regs);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, - eth_can_rx, eth_rx,NULL , -NULL , eth_cleanup, s); -qemu_format_nic_info_str (s->vc, s->conf.macaddr.a); + s->nic =qemu_new_nic (&net_xilinx_ethlite_info, &s->conf, + dev->qdev.info->name, dev->qdev.id, s); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a);return 0 ; }
Signature · 1 line
1.6.5.2
PATCH 34/44 net: move parse_macaddr() to net/util.[ch]
In reply to Mark McLoughlin--- Makefile | 2 +- net.c | 35 ++--------------------------------- net/util.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/util.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 34 deletions(-) create mode 100644 net/util.c create mode 100644 net/util.h
Makefile +1 -1
@@ -99,7 +99,7 @@ block-nested-$(CONFIG_CURL) += curl.o block-obj-y += $(addprefix block/, $(block-nested-y)) net-obj-y = net.o -net-nested-y = queue.o checksum.o +net-nested-y = queue.o checksum.o util.o net-nested-y += socket.o net-nested-y += dump.o net-nested-$(CONFIG_POSIX) += tap.o
net.c +2 -33
@@ -30,6 +30,7 @@#include "net/dump.h" #include "net/slirp.h" #include "net/vde.h" +#include "net/util.h" #include "monitor.h" #include "sysemu.h" #include "qemu-common.h"
@@ -69,38 +70,6 @@ static void hex_dump(FILE *f, const uint8_t *buf, int size) }#endif -static int parse_macaddr (uint8_t *macaddr,const char *p) -{ -int i; -char *last_char; -long int offset; - - errno =0 ; - offset =strtol (p, &last_char,0 ); -if (0 == errno &&'\0' == *last_char && - offset >=0 && offset <=0xFFFFFF ) { - macaddr[3 ] = (offset &0xFF0000 ) >>16 ; - macaddr[4 ] = (offset &0xFF00 ) >>8 ; - macaddr[5 ] = offset &0xFF ; -return 0 ; - }else { -for (i =0 ; i <6 ; i++) { - macaddr[i] =strtol (p, (char **)&p,16 ); -if (i ==5 ) { -if (*p !='\0' ) -return -1 ; - }else { -if (*p !=':' && *p !='-' ) -return -1 ; - p++; - } - } -return 0 ; - } - -return -1 ; -} -static int get_str_sep (char *buf,int buf_size,const char **pp,int sep) {const char *p, *p1;
@@ -858,7 +827,7 @@ static int net_init_nic(QemuOpts *opts, nd->macaddr[5 ] =0x56 + idx;if (qemu_opt_get (opts,"macaddr" ) && -parse_macaddr (nd->macaddr,qemu_opt_get (opts,"macaddr" )) <0 ) { +net_parse_macaddr (nd->macaddr,qemu_opt_get (opts,"macaddr" )) <0 ) {qemu_error ("invalid syntax for ethernet address\n" );return -1 ; }
net/util.c new file +60 -0
60 lines not on this page · raw message
net/util.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* QEMU System Emulator +* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef QEMU_NET_UTIL_H +#define QEMU_NET_UTIL_H + +#include <stdint.h> + +int net_parse_macaddr (uint8_t *macaddr,const char *p); + +#endif /* QEMU_NET_UTIL_H */
Signature · 1 line
1.6.5.2
PATCH 35/44 net: convert xen to NICState
In reply to Mark McLoughlin--- hw/xen_nic.c | 46 +++++++++++++++++++++++++++++----------------- 1 files changed, 29 insertions(+), 17 deletions(-)
hw/xen_nic.c +29 -17
@@ -41,6 +41,7 @@#include "hw.h" #include "net.h" #include "net/checksum.h" +#include "net/util.h" #include "qemu-char.h" #include "xen_backend.h"
@@ -56,7 +57,8 @@ struct XenNetDev {struct netif_rx_sring *rxs;netif_tx_back_ring_t tx_ring;netif_rx_back_ring_t rx_ring; -VLANClientState *vs; +NICConf conf; +NICState *nic; };/* ------------------------------------------------------------- */
@@ -179,9 +181,9 @@ static void net_tx_packets(struct XenNetDev *netdev) tmpbuf =qemu_malloc (XC_PAGE_SIZE );memcpy (tmpbuf, page + txreq.offset, txreq.size);net_checksum_calculate (tmpbuf, txreq.size); -qemu_send_packet (netdev->vs, tmpbuf, txreq.size); +qemu_send_packet (&netdev->nic->nc, tmpbuf, txreq.size); }else { -qemu_send_packet (netdev->vs, page + txreq.offset, txreq.size); +qemu_send_packet (&netdev->nic->nc, page + txreq.offset, txreq.size); }xc_gnttab_munmap (netdev->xendev.gnttabdev, page,1 );net_tx_response (netdev, &txreq,NETIF_RSP_OKAY );
@@ -223,9 +225,9 @@ static void net_rx_response(struct XenNetDev *netdev,#define NET_IP_ALIGN 2 -static int net_rx_ok (VLANClientState *vc) +static int net_rx_ok (VLANClientState *nc) { -struct XenNetDev *netdev = vc->opaque; +struct XenNetDev *netdev =DO_UPCAST (NICState, nc, nc)->opaque;RING_IDX rc, rp;if (netdev->xendev.be_state != XenbusStateConnected)
@@ -243,9 +245,9 @@ static int net_rx_ok(VLANClientState *vc)return 1 ; } -static ssize_t net_rx_packet (VLANClientState *vc,const uint8_t *buf,size_t size) +static ssize_t net_rx_packet (VLANClientState *nc,const uint8_t *buf,size_t size) { -struct XenNetDev *netdev = vc->opaque; +struct XenNetDev *netdev =DO_UPCAST (NICState, nc, nc)->opaque;netif_rx_request_t rxreq;RING_IDX rc, rp;void *page;
@@ -288,10 +290,16 @@ static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t siz/* ------------------------------------------------------------- */ +static NetClientInfo net_xen_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = net_rx_ok, + .receive = net_rx_packet, +}; +static int net_init (struct XenDevice *xendev) { struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); -VLANState *vlan;/* read xenstore entries */ if (netdev->mac ==NULL )
@@ -301,12 +309,16 @@ static int net_init(struct XenDevice *xendev)if (netdev->mac ==NULL )return -1 ; - vlan =qemu_find_vlan (netdev->xendev.dev,1 ); - netdev->vs =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - vlan,NULL ,"xen" ,NULL , - net_rx_ok, net_rx_packet,NULL ,NULL , -NULL , netdev); -snprintf (netdev->vs->info_str,sizeof (netdev->vs->info_str), +if (net_parse_macaddr (netdev->conf.macaddr.a, netdev->mac) <0 ) +return -1 ; + + netdev->conf.vlan =qemu_find_vlan (netdev->xendev.dev,1 ); + netdev->conf.peer =NULL ; + + netdev->nic =qemu_new_nic (&net_xen_info, &netdev->conf, +"xen" ,NULL , netdev); + +snprintf (netdev->nic->nc.info_str,sizeof (netdev->nic->nc.info_str),"nic: xenbus vif macaddr=%s" , netdev->mac);/* fill info */
@@ -376,9 +388,9 @@ static void net_disconnect(struct XenDevice *xendev)xc_gnttab_munmap (netdev->xendev.gnttabdev, netdev->rxs,1 ); netdev->rxs =NULL ; } -if (netdev->vs) { -qemu_del_vlan_client (netdev->vs); - netdev->vs =NULL ; +if (netdev->nic) { +qemu_del_vlan_client (&netdev->nic->nc); + netdev->nic =NULL ; } }
Signature · 1 line
1.6.5.2
PATCH 36/44 net: remove qemu_new_vlan_client()
In reply to Mark McLoughlin... and VLANClientState::opaque and qemu_find_vlan_client().
All of these are now unused
--- net.c | 44 -------------------------------------------- net.h | 13 ------------- 2 files changed, 0 insertions(+), 57 deletions(-)
net.c +0 -44
@@ -283,37 +283,6 @@ NICState *qemu_new_nic(NetClientInfo *info,return nic; } -VLANClientState *qemu_new_vlan_client (net_client_type type, -VLANState *vlan, -VLANClientState *peer, -const char *model, -const char *name, -NetCanReceive *can_receive, -NetReceive *receive, -NetReceive *receive_raw, -NetReceiveIOV *receive_iov, -NetCleanup *cleanup, -void *opaque) -{ -VLANClientState *ret; -NetClientInfo info; - - info.type = type; - info.size =sizeof (VLANClientState); - info.can_receive = can_receive; - info.receive = receive; - info.receive_raw = receive_raw; - info.receive_iov = receive_iov; - info.cleanup = cleanup; - info.link_status_changed =NULL ; - - ret =qemu_new_net_client (&info, vlan, peer, model, name); - - ret->opaque = opaque; - -return ret; -} -void qemu_del_vlan_client (VLANClientState *vc) {if (vc->vlan) {
@@ -337,19 +306,6 @@ void qemu_del_vlan_client(VLANClientState *vc)qemu_free (vc); } -VLANClientState *qemu_find_vlan_client (VLANState *vlan,void *opaque) -{ -VLANClientState *vc; - - QTAILQ_FOREACH(vc, &vlan->clients, next) { -if (vc->opaque == opaque) { -return vc; - } - } - -return NULL ; -} -VLANClientState *qemu_find_vlan_client_by_name (Monitor *mon,int vlan_id,const char *client_str)
net.h +0 -13
@@ -64,7 +64,6 @@ struct VLANClientState {NetCleanup *cleanup;LinkStatusChanged *link_status_changed;int link_down; -void *opaque;QTAILQ_ENTRY (VLANClientState) next;struct VLANState *vlan;VLANClientState *peer;
@@ -101,19 +100,7 @@ NICState *qemu_new_nic(NetClientInfo *info,const char *model, const char *name, void *opaque); -VLANClientState *qemu_new_vlan_client (net_client_type type, -VLANState *vlan, -VLANClientState *peer, -const char *model, -const char *name, -NetCanReceive *can_receive, -NetReceive *receive, -NetReceive *receive_raw, -NetReceiveIOV *receive_iov, -NetCleanup *cleanup, -void *opaque);void qemu_del_vlan_client (VLANClientState *vc); -VLANClientState *qemu_find_vlan_client (VLANState *vlan,void *opaque);VLANClientState *qemu_find_vlan_client_by_name (Monitor *mon,int vlan_id,const char *client_str);int qemu_can_send_packet (VLANClientState *vc);
Signature · 1 line
1.6.5.2
PATCH 37/44 net: remove VLANClientState members now in NetClientInfo
In reply to Mark McLoughlinAdd a NetClientInfo pointer to VLANClientState and use that for the typecode and function pointers.
--- hw/dp8393x.c | 4 ++-- hw/virtio-net.c | 2 +- net.c | 45 ++++++++++++++++++++------------------------- net.h | 10 +--------- net/tap.c | 6 +++--- 5 files changed, 27 insertions(+), 40 deletions(-)
hw/dp8393x.c +2 -2
@@ -407,9 +407,9 @@ static void do_transmit_packets(dp8393xState *s)if (s->regs[SONIC_RCR ] & (SONIC_RCR_LB1 |SONIC_RCR_LB0 )) {/* Loopback */ s->regs[SONIC_TCR ] |=SONIC_TCR_CRSL ; -if (s->nic->nc.can_receive (&s->nic->nc)) { +if (s->nic->nc.info->can_receive (&s->nic->nc)) { s->loopback_packet =1 ; - s->nic->nc.receive (&s->nic->nc, s->tx_buffer, tx_len); + s->nic->nc.info->receive (&s->nic->nc, s->tx_buffer, tx_len); } }else {/* Transmit packet */
hw/virtio-net.c +1 -1
@@ -129,7 +129,7 @@ static int peer_has_vnet_hdr(VirtIONet *n)if (!n->nic->nc.peer)return 0 ; -if (n->nic->nc.peer->type !=NET_CLIENT_TYPE_TAP ) +if (n->nic->nc.peer->info->type !=NET_CLIENT_TYPE_TAP )return 0 ; n->has_vnet_hdr =tap_has_vnet_hdr (n->nic->nc.peer);
net.c +20 -25
113 lines not on this page · raw message
net.h +1 -9
@@ -54,15 +54,7 @@ typedef struct NetClientInfo { } NetClientInfo;struct VLANClientState { -net_client_type type; -NetReceive *receive; -NetReceive *receive_raw; -NetReceiveIOV *receive_iov; -/* Packets may still be sent if this returns zero. It's used to -rate-limit the slirp code. */ -NetCanReceive *can_receive; -NetCleanup *cleanup; -LinkStatusChanged *link_status_changed; +NetClientInfo *info;int link_down;QTAILQ_ENTRY (VLANClientState) next;struct VLANState *vlan;
net/tap.c +3 -3
@@ -214,7 +214,7 @@ int tap_has_ufo(VLANClientState *nc) {TAPState *s =DO_UPCAST (TAPState, nc, nc); -assert (nc->type ==NET_CLIENT_TYPE_TAP ); +assert (nc->info->type ==NET_CLIENT_TYPE_TAP );return s->has_ufo; }
@@ -223,7 +223,7 @@ int tap_has_vnet_hdr(VLANClientState *nc) {TAPState *s =DO_UPCAST (TAPState, nc, nc); -assert (nc->type ==NET_CLIENT_TYPE_TAP ); +assert (nc->info->type ==NET_CLIENT_TYPE_TAP );return s->has_vnet_hdr; }
@@ -234,7 +234,7 @@ void tap_using_vnet_hdr(VLANClientState *nc, int using_vnet_hdr) using_vnet_hdr = using_vnet_hdr !=0 ; -assert (nc->type ==NET_CLIENT_TYPE_TAP ); +assert (nc->info->type ==NET_CLIENT_TYPE_TAP );assert (s->has_vnet_hdr == using_vnet_hdr); s->using_vnet_hdr = using_vnet_hdr;
Signature · 1 line
1.6.5.2
PATCH 38/44 net: add qemu_foreach_nic()
In reply to Mark McLoughlin--- net.c | 20 ++++++++++++++++++++ net.h | 2 ++ 2 files changed, 22 insertions(+), 0 deletions(-)
net.c +20 -0
@@ -326,6 +326,26 @@ qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,return vc; } +void qemu_foreach_nic (qemu_nic_foreach func,void *opaque) +{ +VLANClientState *nc; +VLANState *vlan; + + QTAILQ_FOREACH(nc, &non_vlan_clients, next) { +if (nc->info->type ==NET_CLIENT_TYPE_NIC ) { +func (DO_UPCAST (NICState, nc, nc), opaque); + } + } + + QTAILQ_FOREACH(vlan, &vlans, next) { + QTAILQ_FOREACH(nc, &vlan->clients, next) { +if (nc->info->type ==NET_CLIENT_TYPE_NIC ) { +func (DO_UPCAST (NICState, nc, nc), opaque); + } + } + } +} +int qemu_can_send_packet (VLANClientState *sender) {VLANState *vlan = sender->vlan;
net.h +2 -0
@@ -95,6 +95,8 @@ NICState *qemu_new_nic(NetClientInfo *info,void qemu_del_vlan_client (VLANClientState *vc);VLANClientState *qemu_find_vlan_client_by_name (Monitor *mon,int vlan_id,const char *client_str); +typedef void (*qemu_nic_foreach )(NICState *nic,void *opaque); +void qemu_foreach_nic (qemu_nic_foreach func,void *opaque);int qemu_can_send_packet (VLANClientState *vc);ssize_t qemu_sendv_packet (VLANClientState *vc,const struct iovec *iov,int iovcnt);
Signature · 1 line
1.6.5.2
PATCH 39/44 net: fix qemu_announce_self()
In reply to Mark McLoughlinNow that we have a way to iterate NICs.
--- savevm.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
savevm.c +13 -13
@@ -123,24 +123,24 @@ static int announce_self_create(uint8_t *buf,return 60 ;/* len (FCS will be added by hardware) */ } -static void qemu_announce_self_once (void *opaque) +static void qemu_announce_self_iter (NICState *nic,void *opaque) { -int i, len; -VLANState *vlan; -VLANClientState *vc;uint8_t buf[60 ]; +int len; + + len =announce_self_create (buf, nic->conf->macaddr.a); + +qemu_send_packet_raw (&nic->nc, buf, len); +} + + +static void qemu_announce_self_once (void *opaque) +{static int count =SELF_ANNOUNCE_ROUNDS ;QEMUTimer *timer = *(QEMUTimer **)opaque; -for (i =0 ; i <MAX_NICS ; i++) { -if (!nd_table[i].used) -continue ; - len =announce_self_create (buf, nd_table[i].macaddr); - vlan = nd_table[i].vlan; - QTAILQ_FOREACH(vc, &vlan->clients, next) { -qemu_send_packet_raw (vc, buf, len); - } - } +qemu_foreach_nic (qemu_announce_self_iter,NULL ); +if (--count) {/* delay 50ms, 150ms, 250ms, ... */ qemu_mod_timer(timer, qemu_get_clock(rt_clock) +
Signature · 1 line
1.6.5.2
PATCH 40/44 net: print correct error for '-netdev ""'
In reply to Mark McLoughlin--- net.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-)
net.c +11 -5
@@ -1055,12 +1055,18 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)int i; type =qemu_opt_get (opts,"type" ); -if (!type) { -qemu_error ("No type specified for -net\n" ); -return -1 ; - } -if (is_netdev) { +if (!is_netdev) { +if (!type) { +qemu_error ("No type specified for -net\n" ); +return -1 ; + } + }else { +if (!type) { +qemu_error ("No type specified for -netdev\n" ); +return -1 ; + } + if (strcmp(type, "tap") != 0 &&#ifdef CONFIG_SLIRP strcmp(type, "user") != 0 &&
Signature · 1 line
1.6.5.2
PATCH 41/44 net: fix TAP networking on host kernels without IFF_VNET_HDR support
In reply to Mark McLoughlinFrom: Pierre Riteau <[email protected]>
vnet_hdr is initialized at 1 by default. We need to reset it to 0 if the kernel doesn't support IFF_VNET_HDR.
--- net/tap-linux.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
net/tap-linux.c +2 -0
@@ -52,6 +52,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required features & IFF_VNET_HDR) { *vnet_hdr =1 ; ifr.ifr_flags |=IFF_VNET_HDR ; + } else { + *vnet_hdr =0 ; }if (vnet_hdr_required && !*vnet_hdr) {
Signature · 1 line
1.6.5.2
PATCH 42/44 net: check for TUNSETOFFLOAD support before trying to enable offload features
In reply to Mark McLoughlinFrom: Pierre Riteau <[email protected]>
This avoids the "TUNSETOFFLOAD ioctl() failed: Invalid argument" message on kernels without TUNSETOFFLOAD support.
--- net/tap-linux.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
net/tap-linux.c +5 -0
@@ -131,6 +131,11 @@ void tap_fd_set_offload(int fd, int csum, int tso4, {unsigned int offload =0 ; +/* Check if our kernel supports TUNSETOFFLOAD */ +if (ioctl (fd,TUNSETOFFLOAD ,0 ) !=0 && errno ==EINVAL ) { +return ; + } +if (csum) { offload |=TUN_F_CSUM ;if (tso4)
Signature · 1 line
1.6.5.2
PATCH 43/44 net: initialize vnet_hdr in net_init_tap()
In reply to Mark McLoughlinnet_tap_init() always sets vnet_hdr using qemu_opt_get_bool(), but initialize it in net_init_tap() just to reduce confusion.
--- net/tap.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/tap.c +1 -1
@@ -378,7 +378,7 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr)int net_init_tap (QemuOpts *opts,Monitor *mon,const char *name,VLANState *vlan) {TAPState *s; -int fd, vnet_hdr; +int fd, vnet_hdr =0 ;if (qemu_opt_get (opts,"fd" )) { if (qemu_opt_get(opts, "ifname") ||
Signature · 1 line
1.6.5.2
PATCH 44/44 net: fix vnet_hdr handling in solaris tap code
In reply to Mark McLoughlinPrint an error if the user specifies vnet_hdr=1 on the cmdline.
--- net/tap-solaris.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
net/tap-solaris.c +11 -0
@@ -180,6 +180,17 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_requiredreturn -1 ; }pstrcpy (ifname, ifname_size, dev); +if (*vnet_hdr) { +/* Solaris doesn't have IFF_VNET_HDR */ + *vnet_hdr =0 ; + +if (vnet_hdr_required && !*vnet_hdr) { +qemu_error ("vnet_hdr=1 requested, but no kernel " +"support for IFF_VNET_HDR available" ); +close (fd); +return -1 ; + } + }fcntl (fd,F_SETFL ,O_NONBLOCK );return fd; }
Signature · 1 line
1.6.5.2