virtio-net.c (0cd09c3a6cc2230ba38c462fc410b4acce59eb6f) virtio-net.c (ef546f1275f6563e8934dd5e338d29d9f9909ca6)
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 (!(vdev->guest_features >> VIRTIO_NET_F_CTRL_MAC_ADDR & 1) &&
89 if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR) &&
90 memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
91 memcpy(n->mac, netcfg.mac, ETH_ALEN);
92 qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
93 }
94}
95
96static bool virtio_net_started(VirtIONet *n, uint8_t status)
97{

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

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

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

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

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

514 return virtio_net_guest_offloads_by_features(vdev->guest_features);
515}
516
517static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
518{
519 VirtIONet *n = VIRTIO_NET(vdev);
520 int i;
521
309 info->vlan = RX_STATE_ALL;
310 } else if (!info->vlan_table) {
311 info->vlan = RX_STATE_NONE;
312 } else {
313 info->vlan = RX_STATE_NORMAL;
314 }
315
316 /* enable event notification after query */

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

514 return virtio_net_guest_offloads_by_features(vdev->guest_features);
515}
516
517static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
518{
519 VirtIONet *n = VIRTIO_NET(vdev);
520 int i;
521
522 virtio_net_set_multiqueue(n, !!(features & (1 << VIRTIO_NET_F_MQ)));
522 virtio_net_set_multiqueue(n,
523 __virtio_has_feature(features, VIRTIO_NET_F_MQ));
523
524
524 virtio_net_set_mrg_rx_bufs(n, !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF)));
525 virtio_net_set_mrg_rx_bufs(n,
526 __virtio_has_feature(features,
527 VIRTIO_NET_F_MRG_RXBUF));
525
526 if (n->has_vnet_hdr) {
527 n->curr_guest_offloads =
528 virtio_net_guest_offloads_by_features(features);
529 virtio_net_apply_guest_offloads(n);
530 }
531
532 for (i = 0; i < n->max_queues; i++) {
533 NetClientState *nc = qemu_get_subqueue(n->nic, i);
534
535 if (!get_vhost_net(nc->peer)) {
536 continue;
537 }
538 vhost_net_ack_features(get_vhost_net(nc->peer), features);
539 }
540
528
529 if (n->has_vnet_hdr) {
530 n->curr_guest_offloads =
531 virtio_net_guest_offloads_by_features(features);
532 virtio_net_apply_guest_offloads(n);
533 }
534
535 for (i = 0; i < n->max_queues; i++) {
536 NetClientState *nc = qemu_get_subqueue(n->nic, i);
537
538 if (!get_vhost_net(nc->peer)) {
539 continue;
540 }
541 vhost_net_ack_features(get_vhost_net(nc->peer), features);
542 }
543
541 if ((1 << VIRTIO_NET_F_CTRL_VLAN) & features) {
544 if (__virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
542 memset(n->vlans, 0, MAX_VLAN >> 3);
543 } else {
544 memset(n->vlans, 0xff, MAX_VLAN >> 3);
545 }
546}
547
548static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
549 struct iovec *iov, unsigned int iov_cnt)

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

580
581static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
582 struct iovec *iov, unsigned int iov_cnt)
583{
584 VirtIODevice *vdev = VIRTIO_DEVICE(n);
585 uint64_t offloads;
586 size_t s;
587
545 memset(n->vlans, 0, MAX_VLAN >> 3);
546 } else {
547 memset(n->vlans, 0xff, MAX_VLAN >> 3);
548 }
549}
550
551static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
552 struct iovec *iov, unsigned int iov_cnt)

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

583
584static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
585 struct iovec *iov, unsigned int iov_cnt)
586{
587 VirtIODevice *vdev = VIRTIO_DEVICE(n);
588 uint64_t offloads;
589 size_t s;
590
588 if (!((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features)) {
591 if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
589 return VIRTIO_NET_ERR;
590 }
591
592 s = iov_to_buf(iov, iov_cnt, 0, &offloads, sizeof(offloads));
593 if (s != sizeof(offloads)) {
594 return VIRTIO_NET_ERR;
595 }
596

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

1373 if (n->max_queues > 1) {
1374 qemu_put_be16(f, n->max_queues);
1375 qemu_put_be16(f, n->curr_queues);
1376 for (i = 1; i < n->curr_queues; i++) {
1377 qemu_put_be32(f, n->vqs[i].tx_waiting);
1378 }
1379 }
1380
592 return VIRTIO_NET_ERR;
593 }
594
595 s = iov_to_buf(iov, iov_cnt, 0, &offloads, sizeof(offloads));
596 if (s != sizeof(offloads)) {
597 return VIRTIO_NET_ERR;
598 }
599

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

1376 if (n->max_queues > 1) {
1377 qemu_put_be16(f, n->max_queues);
1378 qemu_put_be16(f, n->curr_queues);
1379 for (i = 1; i < n->curr_queues; i++) {
1380 qemu_put_be32(f, n->vqs[i].tx_waiting);
1381 }
1382 }
1383
1381 if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) {
1384 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
1382 qemu_put_be64(f, n->curr_guest_offloads);
1383 }
1384}
1385
1386static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
1387{
1388 VirtIONet *n = opaque;
1389 VirtIODevice *vdev = VIRTIO_DEVICE(n);

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

1481 n->curr_queues, n->max_queues);
1482 return -1;
1483 }
1484 for (i = 1; i < n->curr_queues; i++) {
1485 n->vqs[i].tx_waiting = qemu_get_be32(f);
1486 }
1487 }
1488
1385 qemu_put_be64(f, n->curr_guest_offloads);
1386 }
1387}
1388
1389static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
1390{
1391 VirtIONet *n = opaque;
1392 VirtIODevice *vdev = VIRTIO_DEVICE(n);

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

1484 n->curr_queues, n->max_queues);
1485 return -1;
1486 }
1487 for (i = 1; i < n->curr_queues; i++) {
1488 n->vqs[i].tx_waiting = qemu_get_be32(f);
1489 }
1490 }
1491
1489 if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) {
1492 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS)) {
1490 n->curr_guest_offloads = qemu_get_be64(f);
1491 } else {
1492 n->curr_guest_offloads = virtio_net_supported_guest_offloads(n);
1493 }
1494
1495 if (peer_has_vnet_hdr(n)) {
1496 virtio_net_apply_guest_offloads(n);
1497 }

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

1508
1509 /* nc.link_down can't be migrated, so infer link_down according
1510 * to link status bit in n->status */
1511 link_down = (n->status & VIRTIO_NET_S_LINK_UP) == 0;
1512 for (i = 0; i < n->max_queues; i++) {
1513 qemu_get_subqueue(n->nic, i)->link_down = link_down;
1514 }
1515
1493 n->curr_guest_offloads = qemu_get_be64(f);
1494 } else {
1495 n->curr_guest_offloads = virtio_net_supported_guest_offloads(n);
1496 }
1497
1498 if (peer_has_vnet_hdr(n)) {
1499 virtio_net_apply_guest_offloads(n);
1500 }

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

1511
1512 /* nc.link_down can't be migrated, so infer link_down according
1513 * to link status bit in n->status */
1514 link_down = (n->status & VIRTIO_NET_S_LINK_UP) == 0;
1515 for (i = 0; i < n->max_queues; i++) {
1516 qemu_get_subqueue(n->nic, i)->link_down = link_down;
1517 }
1518
1516 if (vdev->guest_features & (0x1 << VIRTIO_NET_F_GUEST_ANNOUNCE) &&
1517 vdev->guest_features & (0x1 << VIRTIO_NET_F_CTRL_VQ)) {
1519 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) &&
1520 virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) {
1518 n->announce_counter = SELF_ANNOUNCE_ROUNDS;
1519 timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL));
1520 }
1521
1522 return 0;
1523}
1524
1525static NetClientInfo net_virtio_info = {

--- 232 unchanged lines hidden ---
1521 n->announce_counter = SELF_ANNOUNCE_ROUNDS;
1522 timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL));
1523 }
1524
1525 return 0;
1526}
1527
1528static NetClientInfo net_virtio_info = {

--- 232 unchanged lines hidden ---