diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2013-10-14 03:41:51 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2013-10-16 20:25:37 -0400 |
commit | 855e0c5288177bcb193f6f6316952d2490478e1c (patch) | |
tree | 7c5cfed44c9def1a7ca3388f37a9520de52af44b /drivers/net/virtio_net.c | |
parent | 0b90d0622ad290b3717a13489b396af52aea9d2d (diff) |
virtio: use size-based config accessors.
This lets the transport do endian conversion if necessary, and insulates
the drivers from the difference.
Most drivers can use the simple helpers virtio_cread() and virtio_cwrite().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/net/virtio_net.c')
-rw-r--r-- | drivers/net/virtio_net.c | 28 |
1 files changed, 17 insertions, 11 deletions
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 */ |