From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LL0py-00045r-3Q for qemu-devel@nongnu.org; Thu, 08 Jan 2009 14:46:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LL0pw-00045Q-Gr for qemu-devel@nongnu.org; Thu, 08 Jan 2009 14:46:37 -0500 Received: from [199.232.76.173] (port=51343 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LL0pw-00045J-BP for qemu-devel@nongnu.org; Thu, 08 Jan 2009 14:46:36 -0500 Received: from savannah.gnu.org ([199.232.41.3]:47445 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LL0pv-0007ab-Sp for qemu-devel@nongnu.org; Thu, 08 Jan 2009 14:46:36 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LL0pu-0007OQ-VS for qemu-devel@nongnu.org; Thu, 08 Jan 2009 19:46:35 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LL0pu-0007OM-Bc for qemu-devel@nongnu.org; Thu, 08 Jan 2009 19:46:34 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 08 Jan 2009 19:46:34 +0000 Subject: [Qemu-devel] [6250] Implement virtio_net link status (Mark McLoughlin) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6250 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6250 Author: aliguori Date: 2009-01-08 19:46:33 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Implement virtio_net link status (Mark McLoughlin) Implement the VIRTIO_NET_F_STATUS feature by exposing the link status through virtio_net_config::status. Signed-off-by: Mark McLoughlin Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/hw/virtio-net.c trunk/hw/virtio-net.h Modified: trunk/hw/virtio-net.c =================================================================== --- trunk/hw/virtio-net.c 2009-01-08 19:45:50 UTC (rev 6249) +++ trunk/hw/virtio-net.c 2009-01-08 19:46:33 UTC (rev 6250) @@ -20,6 +20,7 @@ { VirtIODevice vdev; uint8_t mac[6]; + uint16_t status; VirtQueue *rx_vq; VirtQueue *tx_vq; VLANClientState *vc; @@ -42,13 +43,28 @@ VirtIONet *n = to_virtio_net(vdev); struct virtio_net_config netcfg; + netcfg.status = n->status; memcpy(netcfg.mac, n->mac, 6); memcpy(config, &netcfg, sizeof(netcfg)); } +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) + virtio_notify_config(&n->vdev); +} + static uint32_t virtio_net_get_features(VirtIODevice *vdev) { - uint32_t features = (1 << VIRTIO_NET_F_MAC); + uint32_t features = (1 << VIRTIO_NET_F_MAC) | (1 << VIRTIO_NET_F_STATUS); return features; } @@ -307,7 +323,8 @@ n = (VirtIONet *)virtio_init_pci(bus, "virtio-net", 6900, 0x1000, 0, VIRTIO_ID_NET, 0x02, 0x00, 0x00, - 6, sizeof(VirtIONet)); + sizeof(struct virtio_net_config), + sizeof(VirtIONet)); if (!n) return NULL; @@ -317,8 +334,10 @@ 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->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; qemu_format_nic_info_str(n->vc, n->mac); Modified: trunk/hw/virtio-net.h =================================================================== --- trunk/hw/virtio-net.h 2009-01-08 19:45:50 UTC (rev 6249) +++ trunk/hw/virtio-net.h 2009-01-08 19:46:33 UTC (rev 6250) @@ -37,16 +37,21 @@ #define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */ #define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */ #define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */ +#define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */ +#define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ + #define TX_TIMER_INTERVAL 150000 /* 150 us */ /* Maximum packet size we can receive from tap device: header + 64k */ #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10)) -/* The config defining mac address (6 bytes) */ 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; } __attribute__((packed)); /* This is the first element of the scatter-gather list. If you don't