aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/block/virtio_blk.c77
-rw-r--r--drivers/char/virtio_console.c15
-rw-r--r--drivers/net/caif/caif_virtio.c23
-rw-r--r--drivers/net/virtio_net.c28
-rw-r--r--drivers/scsi/virtio_scsi.c12
-rw-r--r--drivers/virtio/virtio_balloon.c10
-rw-r--r--net/9p/trans_virtio.c9
7 files changed, 79 insertions, 95 deletions
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 89245b5adca1..6b66252fc4e6 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -456,18 +456,15 @@ static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
456static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) 456static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
457{ 457{
458 struct virtio_blk *vblk = bd->bd_disk->private_data; 458 struct virtio_blk *vblk = bd->bd_disk->private_data;
459 struct virtio_blk_geometry vgeo;
460 int err;
461 459
462 /* see if the host passed in geometry config */ 460 /* see if the host passed in geometry config */
463 err = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_GEOMETRY, 461 if (virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_GEOMETRY)) {
464 offsetof(struct virtio_blk_config, geometry), 462 virtio_cread(vblk->vdev, struct virtio_blk_config,
465 &vgeo); 463 geometry.cylinders, &geo->cylinders);
466 464 virtio_cread(vblk->vdev, struct virtio_blk_config,
467 if (!err) { 465 geometry.heads, &geo->heads);
468 geo->heads = vgeo.heads; 466 virtio_cread(vblk->vdev, struct virtio_blk_config,
469 geo->sectors = vgeo.sectors; 467 geometry.sectors, &geo->sectors);
470 geo->cylinders = vgeo.cylinders;
471 } else { 468 } else {
472 /* some standard values, similar to sd */ 469 /* some standard values, similar to sd */
473 geo->heads = 1 << 6; 470 geo->heads = 1 << 6;
@@ -529,8 +526,7 @@ static void virtblk_config_changed_work(struct work_struct *work)
529 goto done; 526 goto done;
530 527
531 /* Host must always specify the capacity. */ 528 /* Host must always specify the capacity. */
532 vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity), 529 virtio_cread(vdev, struct virtio_blk_config, capacity, &capacity);
533 &capacity, sizeof(capacity));
534 530
535 /* If capacity is too big, truncate with warning. */ 531 /* If capacity is too big, truncate with warning. */
536 if ((sector_t)capacity != capacity) { 532 if ((sector_t)capacity != capacity) {
@@ -608,9 +604,9 @@ static int virtblk_get_cache_mode(struct virtio_device *vdev)
608 u8 writeback; 604 u8 writeback;
609 int err; 605 int err;
610 606
611 err = virtio_config_val(vdev, VIRTIO_BLK_F_CONFIG_WCE, 607 err = virtio_cread_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE,
612 offsetof(struct virtio_blk_config, wce), 608 struct virtio_blk_config, wce,
613 &writeback); 609 &writeback);
614 if (err) 610 if (err)
615 writeback = virtio_has_feature(vdev, VIRTIO_BLK_F_WCE); 611 writeback = virtio_has_feature(vdev, VIRTIO_BLK_F_WCE);
616 612
@@ -642,7 +638,6 @@ virtblk_cache_type_store(struct device *dev, struct device_attribute *attr,
642 struct virtio_blk *vblk = disk->private_data; 638 struct virtio_blk *vblk = disk->private_data;
643 struct virtio_device *vdev = vblk->vdev; 639 struct virtio_device *vdev = vblk->vdev;
644 int i; 640 int i;
645 u8 writeback;
646 641
647 BUG_ON(!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_CONFIG_WCE)); 642 BUG_ON(!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_CONFIG_WCE));
648 for (i = ARRAY_SIZE(virtblk_cache_types); --i >= 0; ) 643 for (i = ARRAY_SIZE(virtblk_cache_types); --i >= 0; )
@@ -652,11 +647,7 @@ virtblk_cache_type_store(struct device *dev, struct device_attribute *attr,
652 if (i < 0) 647 if (i < 0)
653 return -EINVAL; 648 return -EINVAL;
654 649
655 writeback = i; 650 virtio_cwrite8(vdev, offsetof(struct virtio_blk_config, wce), i);
656 vdev->config->set(vdev,
657 offsetof(struct virtio_blk_config, wce),
658 &writeback, sizeof(writeback));
659
660 virtblk_update_cache_mode(vdev); 651 virtblk_update_cache_mode(vdev);
661 return count; 652 return count;
662} 653}
@@ -699,9 +690,9 @@ static int virtblk_probe(struct virtio_device *vdev)
699 index = err; 690 index = err;
700 691
701 /* We need to know how many segments before we allocate. */ 692 /* We need to know how many segments before we allocate. */
702 err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX, 693 err = virtio_cread_feature(vdev, VIRTIO_BLK_F_SEG_MAX,
703 offsetof(struct virtio_blk_config, seg_max), 694 struct virtio_blk_config, seg_max,
704 &sg_elems); 695 &sg_elems);
705 696
706 /* We need at least one SG element, whatever they say. */ 697 /* We need at least one SG element, whatever they say. */
707 if (err || !sg_elems) 698 if (err || !sg_elems)
@@ -772,8 +763,7 @@ static int virtblk_probe(struct virtio_device *vdev)
772 set_disk_ro(vblk->disk, 1); 763 set_disk_ro(vblk->disk, 1);
773 764
774 /* Host must always specify the capacity. */ 765 /* Host must always specify the capacity. */
775 vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity), 766 virtio_cread(vdev, struct virtio_blk_config, capacity, &cap);
776 &cap, sizeof(cap));
777 767
778 /* If capacity is too big, truncate with warning. */ 768 /* If capacity is too big, truncate with warning. */
779 if ((sector_t)cap != cap) { 769 if ((sector_t)cap != cap) {
@@ -794,46 +784,45 @@ static int virtblk_probe(struct virtio_device *vdev)
794 784
795 /* Host can optionally specify maximum segment size and number of 785 /* Host can optionally specify maximum segment size and number of
796 * segments. */ 786 * segments. */
797 err = virtio_config_val(vdev, VIRTIO_BLK_F_SIZE_MAX, 787 err = virtio_cread_feature(vdev, VIRTIO_BLK_F_SIZE_MAX,
798 offsetof(struct virtio_blk_config, size_max), 788 struct virtio_blk_config, size_max, &v);
799 &v);
800 if (!err) 789 if (!err)
801 blk_queue_max_segment_size(q, v); 790 blk_queue_max_segment_size(q, v);
802 else 791 else
803 blk_queue_max_segment_size(q, -1U); 792 blk_queue_max_segment_size(q, -1U);
804 793
805 /* Host can optionally specify the block size of the device */ 794 /* Host can optionally specify the block size of the device */
806 err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE, 795 err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE,
807 offsetof(struct virtio_blk_config, blk_size), 796 struct virtio_blk_config, blk_size,
808 &blk_size); 797 &blk_size);
809 if (!err) 798 if (!err)
810 blk_queue_logical_block_size(q, blk_size); 799 blk_queue_logical_block_size(q, blk_size);
811 else 800 else
812 blk_size = queue_logical_block_size(q); 801 blk_size = queue_logical_block_size(q);
813 802
814 /* Use topology information if available */ 803 /* Use topology information if available */
815 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY, 804 err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
816 offsetof(struct virtio_blk_config, physical_block_exp), 805 struct virtio_blk_config, physical_block_exp,
817 &physical_block_exp); 806 &physical_block_exp);
818 if (!err && physical_block_exp) 807 if (!err && physical_block_exp)
819 blk_queue_physical_block_size(q, 808 blk_queue_physical_block_size(q,
820 blk_size * (1 << physical_block_exp)); 809 blk_size * (1 << physical_block_exp));
821 810
822 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY, 811 err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
823 offsetof(struct virtio_blk_config, alignment_offset), 812 struct virtio_blk_config, alignment_offset,
824 &alignment_offset); 813 &alignment_offset);
825 if (!err && alignment_offset) 814 if (!err && alignment_offset)
826 blk_queue_alignment_offset(q, blk_size * alignment_offset); 815 blk_queue_alignment_offset(q, blk_size * alignment_offset);
827 816
828 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY, 817 err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
829 offsetof(struct virtio_blk_config, min_io_size), 818 struct virtio_blk_config, min_io_size,
830 &min_io_size); 819 &min_io_size);
831 if (!err && min_io_size) 820 if (!err && min_io_size)
832 blk_queue_io_min(q, blk_size * min_io_size); 821 blk_queue_io_min(q, blk_size * min_io_size);
833 822
834 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY, 823 err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY,
835 offsetof(struct virtio_blk_config, opt_io_size), 824 struct virtio_blk_config, opt_io_size,
836 &opt_io_size); 825 &opt_io_size);
837 if (!err && opt_io_size) 826 if (!err && opt_io_size)
838 blk_queue_io_opt(q, blk_size * opt_io_size); 827 blk_queue_io_opt(q, blk_size * opt_io_size);
839 828
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 862fd54a0ffb..2a8d9a7a1834 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1837,12 +1837,8 @@ static void config_intr(struct virtio_device *vdev)
1837 struct port *port; 1837 struct port *port;
1838 u16 rows, cols; 1838 u16 rows, cols;
1839 1839
1840 vdev->config->get(vdev, 1840 virtio_cread(vdev, struct virtio_console_config, cols, &cols);
1841 offsetof(struct virtio_console_config, cols), 1841 virtio_cread(vdev, struct virtio_console_config, rows, &rows);
1842 &cols, sizeof(u16));
1843 vdev->config->get(vdev,
1844 offsetof(struct virtio_console_config, rows),
1845 &rows, sizeof(u16));
1846 1842
1847 port = find_port_by_id(portdev, 0); 1843 port = find_port_by_id(portdev, 0);
1848 set_console_size(port, rows, cols); 1844 set_console_size(port, rows, cols);
@@ -2014,10 +2010,9 @@ static int virtcons_probe(struct virtio_device *vdev)
2014 2010
2015 /* Don't test MULTIPORT at all if we're rproc: not a valid feature! */ 2011 /* Don't test MULTIPORT at all if we're rproc: not a valid feature! */
2016 if (!is_rproc_serial(vdev) && 2012 if (!is_rproc_serial(vdev) &&
2017 virtio_config_val(vdev, VIRTIO_CONSOLE_F_MULTIPORT, 2013 virtio_cread_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT,
2018 offsetof(struct virtio_console_config, 2014 struct virtio_console_config, max_nr_ports,
2019 max_nr_ports), 2015 &portdev->config.max_nr_ports) == 0) {
2020 &portdev->config.max_nr_ports) == 0) {
2021 multiport = true; 2016 multiport = true;
2022 } 2017 }
2023 2018
diff --git a/drivers/net/caif/caif_virtio.c b/drivers/net/caif/caif_virtio.c
index b9ed1288ce2d..985608634f8c 100644
--- a/drivers/net/caif/caif_virtio.c
+++ b/drivers/net/caif/caif_virtio.c
@@ -686,18 +686,19 @@ static int cfv_probe(struct virtio_device *vdev)
686 goto err; 686 goto err;
687 687
688 /* Get the CAIF configuration from virtio config space, if available */ 688 /* Get the CAIF configuration from virtio config space, if available */
689#define GET_VIRTIO_CONFIG_OPS(_v, _var, _f) \
690 ((_v)->config->get(_v, offsetof(struct virtio_caif_transf_config, _f), \
691 &_var, \
692 FIELD_SIZEOF(struct virtio_caif_transf_config, _f)))
693
694 if (vdev->config->get) { 689 if (vdev->config->get) {
695 GET_VIRTIO_CONFIG_OPS(vdev, cfv->tx_hr, headroom); 690 virtio_cread(vdev, struct virtio_caif_transf_config, headroom,
696 GET_VIRTIO_CONFIG_OPS(vdev, cfv->rx_hr, headroom); 691 &cfv->tx_hr);
697 GET_VIRTIO_CONFIG_OPS(vdev, cfv->tx_tr, tailroom); 692 virtio_cread(vdev, struct virtio_caif_transf_config, headroom,
698 GET_VIRTIO_CONFIG_OPS(vdev, cfv->rx_tr, tailroom); 693 &cfv->rx_hr);
699 GET_VIRTIO_CONFIG_OPS(vdev, cfv->mtu, mtu); 694 virtio_cread(vdev, struct virtio_caif_transf_config, tailroom,
700 GET_VIRTIO_CONFIG_OPS(vdev, cfv->mru, mtu); 695 &cfv->tx_tr);
696 virtio_cread(vdev, struct virtio_caif_transf_config, tailroom,
697 &cfv->rx_tr);
698 virtio_cread(vdev, struct virtio_caif_transf_config, mtu,
699 &cfv->mtu);
700 virtio_cread(vdev, struct virtio_caif_transf_config, mtu,
701 &cfv->mru);
701 } else { 702 } else {
702 cfv->tx_hr = CFV_DEF_HEADROOM; 703 cfv->tx_hr = CFV_DEF_HEADROOM;
703 cfv->rx_hr = CFV_DEF_HEADROOM; 704 cfv->rx_hr = CFV_DEF_HEADROOM;
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 2ad3d96d4a7c..ee022714eadb 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -852,8 +852,13 @@ static int virtnet_set_mac_address(struct net_device *dev, void *p)
852 return -EINVAL; 852 return -EINVAL;
853 } 853 }
854 } else if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) { 854 } else if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) {
855 vdev->config->set(vdev, offsetof(struct virtio_net_config, mac), 855 unsigned int i;
856 addr->sa_data, dev->addr_len); 856
857 /* Naturally, this has an atomicity problem. */
858 for (i = 0; i < dev->addr_len; i++)
859 virtio_cwrite8(vdev,
860 offsetof(struct virtio_net_config, mac) +
861 i, addr->sa_data[i]);
857 } 862 }
858 863
859 eth_commit_mac_addr_change(dev, p); 864 eth_commit_mac_addr_change(dev, p);
@@ -1266,9 +1271,8 @@ static void virtnet_config_changed_work(struct work_struct *work)
1266 if (!vi->config_enable) 1271 if (!vi->config_enable)
1267 goto done; 1272 goto done;
1268 1273
1269 if (virtio_config_val(vi->vdev, VIRTIO_NET_F_STATUS, 1274 if (virtio_cread_feature(vi->vdev, VIRTIO_NET_F_STATUS,
1270 offsetof(struct virtio_net_config, status), 1275 struct virtio_net_config, status, &v) < 0)
1271 &v) < 0)
1272 goto done; 1276 goto done;
1273 1277
1274 if (v & VIRTIO_NET_S_ANNOUNCE) { 1278 if (v & VIRTIO_NET_S_ANNOUNCE) {
@@ -1490,9 +1494,9 @@ static int virtnet_probe(struct virtio_device *vdev)
1490 u16 max_queue_pairs; 1494 u16 max_queue_pairs;
1491 1495
1492 /* Find if host supports multiqueue virtio_net device */ 1496 /* Find if host supports multiqueue virtio_net device */
1493 err = virtio_config_val(vdev, VIRTIO_NET_F_MQ, 1497 err = virtio_cread_feature(vdev, VIRTIO_NET_F_MQ,
1494 offsetof(struct virtio_net_config, 1498 struct virtio_net_config,
1495 max_virtqueue_pairs), &max_queue_pairs); 1499 max_virtqueue_pairs, &max_queue_pairs);
1496 1500
1497 /* We need at least 2 queue's */ 1501 /* We need at least 2 queue's */
1498 if (err || max_queue_pairs < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN || 1502 if (err || max_queue_pairs < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN ||
@@ -1544,9 +1548,11 @@ static int virtnet_probe(struct virtio_device *vdev)
1544 dev->vlan_features = dev->features; 1548 dev->vlan_features = dev->features;
1545 1549
1546 /* Configuration may specify what MAC to use. Otherwise random. */ 1550 /* Configuration may specify what MAC to use. Otherwise random. */
1547 if (virtio_config_val_len(vdev, VIRTIO_NET_F_MAC, 1551 if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC))
1548 offsetof(struct virtio_net_config, mac), 1552 virtio_cread_bytes(vdev,
1549 dev->dev_addr, dev->addr_len) < 0) 1553 offsetof(struct virtio_net_config, mac),
1554 dev->dev_addr, dev->addr_len);
1555 else
1550 eth_hw_addr_random(dev); 1556 eth_hw_addr_random(dev);
1551 1557
1552 /* Set up our device-specific information */ 1558 /* Set up our device-specific information */
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 2a110391f8ce..e6bb2352df40 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -710,19 +710,15 @@ static struct scsi_host_template virtscsi_host_template_multi = {
710#define virtscsi_config_get(vdev, fld) \ 710#define virtscsi_config_get(vdev, fld) \
711 ({ \ 711 ({ \
712 typeof(((struct virtio_scsi_config *)0)->fld) __val; \ 712 typeof(((struct virtio_scsi_config *)0)->fld) __val; \
713 vdev->config->get(vdev, \ 713 virtio_cread(vdev, struct virtio_scsi_config, fld, &__val); \
714 offsetof(struct virtio_scsi_config, fld), \
715 &__val, sizeof(__val)); \
716 __val; \ 714 __val; \
717 }) 715 })
718 716
719#define virtscsi_config_set(vdev, fld, val) \ 717#define virtscsi_config_set(vdev, fld, val) \
720 (void)({ \ 718 do { \
721 typeof(((struct virtio_scsi_config *)0)->fld) __val = (val); \ 719 typeof(((struct virtio_scsi_config *)0)->fld) __val = (val); \
722 vdev->config->set(vdev, \ 720 virtio_cwrite(vdev, struct virtio_scsi_config, fld, &__val); \
723 offsetof(struct virtio_scsi_config, fld), \ 721 } while(0)
724 &__val, sizeof(__val)); \
725 })
726 722
727static void __virtscsi_set_affinity(struct virtio_scsi *vscsi, bool affinity) 723static void __virtscsi_set_affinity(struct virtio_scsi *vscsi, bool affinity)
728{ 724{
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index d6f681641606..c444654fc33f 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -275,9 +275,8 @@ static inline s64 towards_target(struct virtio_balloon *vb)
275 __le32 v; 275 __le32 v;
276 s64 target; 276 s64 target;
277 277
278 vb->vdev->config->get(vb->vdev, 278 virtio_cread(vb->vdev, struct virtio_balloon_config, num_pages, &v);
279 offsetof(struct virtio_balloon_config, num_pages), 279
280 &v, sizeof(v));
281 target = le32_to_cpu(v); 280 target = le32_to_cpu(v);
282 return target - vb->num_pages; 281 return target - vb->num_pages;
283} 282}
@@ -286,9 +285,8 @@ static void update_balloon_size(struct virtio_balloon *vb)
286{ 285{
287 __le32 actual = cpu_to_le32(vb->num_pages); 286 __le32 actual = cpu_to_le32(vb->num_pages);
288 287
289 vb->vdev->config->set(vb->vdev, 288 virtio_cwrite(vb->vdev, struct virtio_balloon_config, num_pages,
290 offsetof(struct virtio_balloon_config, actual), 289 &actual);
291 &actual, sizeof(actual));
292} 290}
293 291
294static int balloon(void *_vballoon) 292static int balloon(void *_vballoon)
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 990afab2be1b..9c5a1aa34d12 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -544,9 +544,7 @@ static int p9_virtio_probe(struct virtio_device *vdev)
544 544
545 chan->inuse = false; 545 chan->inuse = false;
546 if (virtio_has_feature(vdev, VIRTIO_9P_MOUNT_TAG)) { 546 if (virtio_has_feature(vdev, VIRTIO_9P_MOUNT_TAG)) {
547 vdev->config->get(vdev, 547 virtio_cread(vdev, struct virtio_9p_config, tag_len, &tag_len);
548 offsetof(struct virtio_9p_config, tag_len),
549 &tag_len, sizeof(tag_len));
550 } else { 548 } else {
551 err = -EINVAL; 549 err = -EINVAL;
552 goto out_free_vq; 550 goto out_free_vq;
@@ -556,8 +554,9 @@ static int p9_virtio_probe(struct virtio_device *vdev)
556 err = -ENOMEM; 554 err = -ENOMEM;
557 goto out_free_vq; 555 goto out_free_vq;
558 } 556 }
559 vdev->config->get(vdev, offsetof(struct virtio_9p_config, tag), 557
560 tag, tag_len); 558 virtio_cread_bytes(vdev, offsetof(struct virtio_9p_config, tag),
559 tag, tag_len);
561 chan->tag = tag; 560 chan->tag = tag;
562 chan->tag_len = tag_len; 561 chan->tag_len = tag_len;
563 err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); 562 err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);