diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-01-08 19:46:33 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-01-08 19:46:33 +0000 |
commit | 554c97dd43e021b626c78ed5bd72bca33d5cb99c (patch) | |
tree | 78e4b93f943ff43051ad972e5f39221e35bccb67 /hw/virtio-net.c | |
parent | 99ed7e30cbd6862ef3bb1ebe51c8a4923d0e282b (diff) |
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 <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6250 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/virtio-net.c')
-rw-r--r-- | hw/virtio-net.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/hw/virtio-net.c b/hw/virtio-net.c index de1f7ceca3..5eca19cd78 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -20,6 +20,7 @@ typedef struct VirtIONet { VirtIODevice vdev; uint8_t mac[6]; + uint16_t status; VirtQueue *rx_vq; VirtQueue *tx_vq; VLANClientState *vc; @@ -42,13 +43,28 @@ static void virtio_net_update_config(VirtIODevice *vdev, uint8_t *config) 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 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) 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 @@ 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->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); |