virtio-net.c (5c314a2eb713f560d753cb194d194fd462cff719) virtio-net.c (95129d6fc9ead97155627a4ca0cfd37282883658)
1/*
2 * Virtio Network Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *

--- 72 unchanged lines hidden (view full) ---

81
82static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
83{
84 VirtIONet *n = VIRTIO_NET(vdev);
85 struct virtio_net_config netcfg = {};
86
87 memcpy(&netcfg, config, n->config_size);
88
1/*
2 * Virtio Network Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *

--- 72 unchanged lines hidden (view full) ---

81
82static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
83{
84 VirtIONet *n = VIRTIO_NET(vdev);
85 struct virtio_net_config netcfg = {};
86
87 memcpy(&netcfg, config, n->config_size);
88
89 if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR) &&
90 !virtio_has_feature(vdev, VIRTIO_F_VERSION_1) &&
89 if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR) &&
90 !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1) &&
91 memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
92 memcpy(n->mac, netcfg.mac, ETH_ALEN);
93 qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
94 }
95}
96
97static bool virtio_net_started(VirtIONet *n, uint8_t status)
98{

--- 200 unchanged lines hidden (view full) ---

299 entry = g_malloc0(sizeof(*entry));
300 entry->value = qemu_mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
301 entry->next = str_list;
302 str_list = entry;
303 }
304 info->multicast_table = str_list;
305 info->vlan_table = get_vlan_table(n);
306
91 memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
92 memcpy(n->mac, netcfg.mac, ETH_ALEN);
93 qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
94 }
95}
96
97static bool virtio_net_started(VirtIONet *n, uint8_t status)
98{

--- 200 unchanged lines hidden (view full) ---

299 entry = g_malloc0(sizeof(*entry));
300 entry->value = qemu_mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
301 entry->next = str_list;
302 str_list = entry;
303 }
304 info->multicast_table = str_list;
305 info->vlan_table = get_vlan_table(n);
306
307 if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VLAN)) {
307 if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VLAN)) {
308 info->vlan = RX_STATE_ALL;
309 } else if (!info->vlan_table) {
310 info->vlan = RX_STATE_NONE;
311 } else {
312 info->vlan = RX_STATE_NORMAL;
313 }
314
315 /* enable event notification after query */

--- 208 unchanged lines hidden (view full) ---

524}
525
526static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
527{
528 VirtIONet *n = VIRTIO_NET(vdev);
529 int i;
530
531 virtio_net_set_multiqueue(n,
308 info->vlan = RX_STATE_ALL;
309 } else if (!info->vlan_table) {
310 info->vlan = RX_STATE_NONE;
311 } else {
312 info->vlan = RX_STATE_NORMAL;
313 }
314
315 /* enable event notification after query */

--- 208 unchanged lines hidden (view full) ---

524}
525
526static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
527{
528 VirtIONet *n = VIRTIO_NET(vdev);
529 int i;
530
531 virtio_net_set_multiqueue(n,
532 __virtio_has_feature(features, VIRTIO_NET_F_MQ));
532 virtio_has_feature(features, VIRTIO_NET_F_MQ));
533
534 virtio_net_set_mrg_rx_bufs(n,
533
534 virtio_net_set_mrg_rx_bufs(n,
535 __virtio_has_feature(features,
536 VIRTIO_NET_F_MRG_RXBUF),
537 __virtio_has_feature(features,
538 VIRTIO_F_VERSION_1));
535 virtio_has_feature(features,
536 VIRTIO_NET_F_MRG_RXBUF),
537 virtio_has_feature(features,
538 VIRTIO_F_VERSION_1));
539
540 if (n->has_vnet_hdr) {
541 n->curr_guest_offloads =
542 virtio_net_guest_offloads_by_features(features);
543 virtio_net_apply_guest_offloads(n);
544 }
545
546 for (i = 0; i < n->max_queues; i++) {
547 NetClientState *nc = qemu_get_subqueue(n->nic, i);
548
549 if (!get_vhost_net(nc->peer)) {
550 continue;
551 }
552 vhost_net_ack_features(get_vhost_net(nc->peer), features);
553 }
554
539
540 if (n->has_vnet_hdr) {
541 n->curr_guest_offloads =
542 virtio_net_guest_offloads_by_features(features);
543 virtio_net_apply_guest_offloads(n);
544 }
545
546 for (i = 0; i < n->max_queues; i++) {
547 NetClientState *nc = qemu_get_subqueue(n->nic, i);
548
549 if (!get_vhost_net(nc->peer)) {
550 continue;
551 }
552 vhost_net_ack_features(get_vhost_net(nc->peer), features);
553 }
554
555 if (__virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
555 if (virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
556 memset(n->vlans, 0, MAX_VLAN >> 3);
557 } else {
558 memset(n->vlans, 0xff, MAX_VLAN >> 3);
559 }
560}
561
562static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
563 struct iovec *iov, unsigned int iov_cnt)

--- 30 unchanged lines hidden (view full) ---

594
595static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
596 struct iovec *iov, unsigned int iov_cnt)
597{
598 VirtIODevice *vdev = VIRTIO_DEVICE(n);
599 uint64_t offloads;
600 size_t s;
601
556 memset(n->vlans, 0, MAX_VLAN >> 3);
557 } else {
558 memset(n->vlans, 0xff, MAX_VLAN >> 3);
559 }
560}
561
562static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
563 struct iovec *iov, unsigned int iov_cnt)

--- 30 unchanged lines hidden (view full) ---

594
595static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
596 struct iovec *iov, unsigned int iov_cnt)
597{
598 VirtIODevice *vdev = VIRTIO_DEVICE(n);
599 uint64_t offloads;
600 size_t s;
601
602 if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
602 if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
603 return VIRTIO_NET_ERR;
604 }
605
606 s = iov_to_buf(iov, iov_cnt, 0, &offloads, sizeof(offloads));
607 if (s != sizeof(offloads)) {
608 return VIRTIO_NET_ERR;
609 }
610

--- 833 unchanged lines hidden (view full) ---

1444 if (n->max_queues > 1) {
1445 qemu_put_be16(f, n->max_queues);
1446 qemu_put_be16(f, n->curr_queues);
1447 for (i = 1; i < n->curr_queues; i++) {
1448 qemu_put_be32(f, n->vqs[i].tx_waiting);
1449 }
1450 }
1451
603 return VIRTIO_NET_ERR;
604 }
605
606 s = iov_to_buf(iov, iov_cnt, 0, &offloads, sizeof(offloads));
607 if (s != sizeof(offloads)) {
608 return VIRTIO_NET_ERR;
609 }
610

--- 833 unchanged lines hidden (view full) ---

1444 if (n->max_queues > 1) {
1445 qemu_put_be16(f, n->max_queues);
1446 qemu_put_be16(f, n->curr_queues);
1447 for (i = 1; i < n->curr_queues; i++) {
1448 qemu_put_be32(f, n->vqs[i].tx_waiting);
1449 }
1450 }
1451
1452 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
1452 if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
1453 qemu_put_be64(f, n->curr_guest_offloads);
1454 }
1455}
1456
1457static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
1458{
1459 VirtIONet *n = opaque;
1460 VirtIODevice *vdev = VIRTIO_DEVICE(n);

--- 9 unchanged lines hidden (view full) ---

1470{
1471 VirtIONet *n = VIRTIO_NET(vdev);
1472 int i, link_down;
1473
1474 qemu_get_buffer(f, n->mac, ETH_ALEN);
1475 n->vqs[0].tx_waiting = qemu_get_be32(f);
1476
1477 virtio_net_set_mrg_rx_bufs(n, qemu_get_be32(f),
1453 qemu_put_be64(f, n->curr_guest_offloads);
1454 }
1455}
1456
1457static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
1458{
1459 VirtIONet *n = opaque;
1460 VirtIODevice *vdev = VIRTIO_DEVICE(n);

--- 9 unchanged lines hidden (view full) ---

1470{
1471 VirtIONet *n = VIRTIO_NET(vdev);
1472 int i, link_down;
1473
1474 qemu_get_buffer(f, n->mac, ETH_ALEN);
1475 n->vqs[0].tx_waiting = qemu_get_be32(f);
1476
1477 virtio_net_set_mrg_rx_bufs(n, qemu_get_be32(f),
1478 virtio_has_feature(vdev, VIRTIO_F_VERSION_1));
1478 virtio_vdev_has_feature(vdev,
1479 VIRTIO_F_VERSION_1));
1479
1480 if (version_id >= 3)
1481 n->status = qemu_get_be16(f);
1482
1483 if (version_id >= 4) {
1484 if (version_id < 8) {
1485 n->promisc = qemu_get_be32(f);
1486 n->allmulti = qemu_get_be32(f);

--- 66 unchanged lines hidden (view full) ---

1553 n->curr_queues, n->max_queues);
1554 return -1;
1555 }
1556 for (i = 1; i < n->curr_queues; i++) {
1557 n->vqs[i].tx_waiting = qemu_get_be32(f);
1558 }
1559 }
1560
1480
1481 if (version_id >= 3)
1482 n->status = qemu_get_be16(f);
1483
1484 if (version_id >= 4) {
1485 if (version_id < 8) {
1486 n->promisc = qemu_get_be32(f);
1487 n->allmulti = qemu_get_be32(f);

--- 66 unchanged lines hidden (view full) ---

1554 n->curr_queues, n->max_queues);
1555 return -1;
1556 }
1557 for (i = 1; i < n->curr_queues; i++) {
1558 n->vqs[i].tx_waiting = qemu_get_be32(f);
1559 }
1560 }
1561
1561 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
1562 if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
1562 n->curr_guest_offloads = qemu_get_be64(f);
1563 } else {
1564 n->curr_guest_offloads = virtio_net_supported_guest_offloads(n);
1565 }
1566
1567 if (peer_has_vnet_hdr(n)) {
1568 virtio_net_apply_guest_offloads(n);
1569 }

--- 10 unchanged lines hidden (view full) ---

1580
1581 /* nc.link_down can't be migrated, so infer link_down according
1582 * to link status bit in n->status */
1583 link_down = (n->status & VIRTIO_NET_S_LINK_UP) == 0;
1584 for (i = 0; i < n->max_queues; i++) {
1585 qemu_get_subqueue(n->nic, i)->link_down = link_down;
1586 }
1587
1563 n->curr_guest_offloads = qemu_get_be64(f);
1564 } else {
1565 n->curr_guest_offloads = virtio_net_supported_guest_offloads(n);
1566 }
1567
1568 if (peer_has_vnet_hdr(n)) {
1569 virtio_net_apply_guest_offloads(n);
1570 }

--- 10 unchanged lines hidden (view full) ---

1581
1582 /* nc.link_down can't be migrated, so infer link_down according
1583 * to link status bit in n->status */
1584 link_down = (n->status & VIRTIO_NET_S_LINK_UP) == 0;
1585 for (i = 0; i < n->max_queues; i++) {
1586 qemu_get_subqueue(n->nic, i)->link_down = link_down;
1587 }
1588
1588 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
1589 virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
1589 if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
1590 virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
1590 n->announce_counter = SELF_ANNOUNCE_ROUNDS;
1591 timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL));
1592 }
1593
1594 return 0;
1595}
1596
1597static NetClientInfo net_virtio_info = {

--- 262 unchanged lines hidden ---
1591 n->announce_counter = SELF_ANNOUNCE_ROUNDS;
1592 timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL));
1593 }
1594
1595 return 0;
1596}
1597
1598static NetClientInfo net_virtio_info = {

--- 262 unchanged lines hidden ---