From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUR0e-00029h-Iw for qemu-devel@nongnu.org; Tue, 03 Feb 2009 14:32:36 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUR0c-00028y-TD for qemu-devel@nongnu.org; Tue, 03 Feb 2009 14:32:36 -0500 Received: from [199.232.76.173] (port=57497 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUR0c-00028u-Od for qemu-devel@nongnu.org; Tue, 03 Feb 2009 14:32:34 -0500 Received: from g4t0015.houston.hp.com ([15.201.24.18]:36943) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LUR0c-0004Cv-Bz for qemu-devel@nongnu.org; Tue, 03 Feb 2009 14:32:34 -0500 From: Alex Williamson Date: Tue, 03 Feb 2009 12:29:43 -0700 Message-ID: <20090203192943.19598.77587.stgit@kvm.aw> In-Reply-To: <20090203192932.19598.50925.stgit@kvm.aw> References: <20090203192932.19598.50925.stgit@kvm.aw> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH v2 2/8] qemu:virtio-net: Allow setting the MAC address via set_config Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws, qemu-devel@nongnu.org Cc: markmc@redhat.com, kvm@vger.kernel.org Allow the guest to write to the MAC address config space and update the network info string when it does. Rename get_config for symmetry. Signed-off-by: Alex Williamson Acked-by: Mark McLoughlin --- hw/virtio-net.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 2eb52b8..105daa9 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -40,7 +40,7 @@ static VirtIONet *to_virtio_net(VirtIODevice *vdev) return (VirtIONet *)vdev; } -static void virtio_net_update_config(VirtIODevice *vdev, uint8_t *config) +static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) { VirtIONet *n = to_virtio_net(vdev); struct virtio_net_config netcfg; @@ -50,6 +50,19 @@ static void virtio_net_update_config(VirtIODevice *vdev, uint8_t *config) memcpy(config, &netcfg, sizeof(netcfg)); } +static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config) +{ + VirtIONet *n = to_virtio_net(vdev); + struct virtio_net_config netcfg; + + memcpy(&netcfg, config, sizeof(netcfg)); + + if (memcmp(netcfg.mac, n->mac, 6)) { + memcpy(n->mac, netcfg.mac, 6); + qemu_format_nic_info_str(n->vc, n->mac); + } +} + static void virtio_net_set_link_status(VLANClientState *vc) { VirtIONet *n = vc->opaque; @@ -337,7 +350,8 @@ void virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) if (!n) return; - n->vdev.get_config = virtio_net_update_config; + n->vdev.get_config = virtio_net_get_config; + n->vdev.set_config = virtio_net_set_config; n->vdev.get_features = virtio_net_get_features; n->vdev.set_features = virtio_net_set_features; n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);