From patchwork Wed Jan 7 17:37:39 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 1212 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n07HXhvH024636 for ; Wed, 7 Jan 2009 09:33:43 -0800 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753213AbZAGRhO (ORCPT ); Wed, 7 Jan 2009 12:37:14 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753428AbZAGRhO (ORCPT ); Wed, 7 Jan 2009 12:37:14 -0500 Received: from g1t0028.austin.hp.com ([15.216.28.35]:32741 "EHLO g1t0028.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753213AbZAGRhM (ORCPT ); Wed, 7 Jan 2009 12:37:12 -0500 Received: from g1t0038.austin.hp.com (g1t0038.austin.hp.com [16.236.32.44]) by g1t0028.austin.hp.com (Postfix) with ESMTP id CF96A1C003; Wed, 7 Jan 2009 17:37:11 +0000 (UTC) Received: from ldl.fc.hp.com (ldl.fc.hp.com [15.11.146.30]) by g1t0038.austin.hp.com (Postfix) with ESMTP id A286C30069; Wed, 7 Jan 2009 17:37:11 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl.fc.hp.com (Postfix) with ESMTP id 4C16739C010; Wed, 7 Jan 2009 10:37:11 -0700 (MST) X-Virus-Scanned: Debian amavisd-new at ldl.fc.hp.com Received: from ldl.fc.hp.com ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nScgWo-zZxRF; Wed, 7 Jan 2009 10:37:09 -0700 (MST) Received: from [10.91.73.10] (lart.fc.hp.com [15.11.146.31]) by ldl.fc.hp.com (Postfix) with ESMTP id 897AB39C008; Wed, 7 Jan 2009 10:37:09 -0700 (MST) Subject: [PATCH 3/5][RFC] virtio-net: Name the status bits, adding promisc and allmulti From: Alex Williamson To: kvm , qemu-devel Cc: Mark McLoughlin Organization: OSLO R&D Date: Wed, 07 Jan 2009 10:37:39 -0700 Message-Id: <1231349859.7109.82.camel@lappy> Mime-Version: 1.0 X-Mailer: Evolution 2.24.2 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org virtio-net: Name the status bits, adding promisc and allmulti Signed-off-by: Alex Williamson --- hw/virtio-net.c | 36 ++++++++++++++++++++++++------------ hw/virtio-net.h | 11 ++++++++++- 2 files changed, 34 insertions(+), 13 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 77e3077..653cad4 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -22,7 +22,14 @@ typedef struct VirtIONet { VirtIODevice vdev; uint8_t mac[6]; - uint16_t status; + union { + uint16_t raw; + struct { + uint16_t link:1; + uint16_t promisc:1; + uint16_t allmulti:1; + } bits; + } status; VirtQueue *rx_vq; VirtQueue *tx_vq; VLANClientState *vc; @@ -45,7 +52,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) VirtIONet *n = to_virtio_net(vdev); struct virtio_net_config netcfg; - netcfg.status = n->status; + netcfg.status.raw = n->status.raw; memcpy(netcfg.mac, n->mac, 6); memcpy(config, &netcfg, sizeof(netcfg)); } @@ -64,20 +71,23 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config) n->mac[0], n->mac[1], n->mac[2], n->mac[3], n->mac[4], n->mac[5]); } + + if (netcfg.status.raw != n->status.raw) { + if (netcfg.status.bits.promisc != n->status.bits.promisc) + n->status.bits.promisc = netcfg.status.bits.promisc; + if (netcfg.status.bits.allmulti != n->status.bits.allmulti) + n->status.bits.allmulti = netcfg.status.bits.allmulti; + } } static void virtio_net_set_link_status(VLANClientState *vc) { VirtIONet *n = vc->opaque; - uint16_t old_status = n->status; - - if (vc->link_down) - n->status &= ~VIRTIO_NET_S_LINK_UP; - else - n->status |= VIRTIO_NET_S_LINK_UP; - if (n->status != old_status) + if (n->status.bits.link != !(vc->link_down)) { + n->status.bits.link = !(vc->link_down); virtio_notify_config(&n->vdev); + } } static uint32_t virtio_net_get_features(VirtIODevice *vdev) @@ -309,7 +319,7 @@ static void virtio_net_save(QEMUFile *f, void *opaque) qemu_put_buffer(f, n->mac, 6); qemu_put_be32(f, n->tx_timer_active); - qemu_put_be16(f, n->status); + qemu_put_be16(f, n->status.raw); } static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) @@ -325,7 +335,9 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) n->tx_timer_active = qemu_get_be32(f); if (version_id >= 2) - n->status = qemu_get_be16(f); + n->status.raw = qemu_get_be16(f); + else + n->status.raw |= (VIRTIO_NET_S_PROMISC | VIRTIO_NET_S_ALLMULTI); if (n->tx_timer_active) { qemu_mod_timer(n->tx_timer, @@ -355,7 +367,7 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx); n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx); memcpy(n->mac, nd->macaddr, 6); - n->status = VIRTIO_NET_S_LINK_UP; + n->status.raw = VIRTIO_NET_S_LINK_UP; n->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, virtio_net_receive, virtio_net_can_receive, n); n->vc->link_status_changed = virtio_net_set_link_status; diff --git a/hw/virtio-net.h b/hw/virtio-net.h index 9ac9e34..74f1595 100644 --- a/hw/virtio-net.h +++ b/hw/virtio-net.h @@ -40,6 +40,8 @@ #define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */ #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ +#define VIRTIO_NET_S_PROMISC 2 /* Promiscuous mode */ +#define VIRTIO_NET_S_ALLMULTI 4 /* All-multicast mode */ #define TX_TIMER_INTERVAL 150000 /* 150 us */ @@ -51,7 +53,14 @@ struct virtio_net_config /* The config defining mac address (6 bytes) */ uint8_t mac[6]; /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ - uint16_t status; + union { + uint16_t raw; + struct { + uint16_t link:1; + uint16_t promisc:1; + uint16_t allmulti:1; + } bits; + } status; } __attribute__((packed)); /* This is the first element of the scatter-gather list. If you don't