diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-05-02 11:20:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-05-02 11:20:04 -0400 |
commit | 02cdf0827b61d51f0e9cc1b5ddd486950830ba08 (patch) | |
tree | a7e52e9f102782ccb52d72f5ca425f77fedce709 /include | |
parent | 8bec4a5d9305c86d028a519b08f05b81cd63cc55 (diff) | |
parent | a007a751d98fe97142e4724a83a4e31ec66b7532 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus:
lguest: make Launcher see device status updates
lguest: remove bogus NULL cpu check
lguest: avoid using NR_CPUS as a bounds check.
virtio: add virtio disk geometry feature
virtio: explicit advertisement of driver features
virtio: change config to guest endian.
virtio: finer-grained features for virtio_net
virtio: wean net driver off NETDEV_TX_BUSY
virtio-blk: fix remove oops
virtio: fix scatterlist sizing in net driver.
virtio: de-structify virtio_block status byte
virtio: export more headers to userspace
virtio: fix sparse return void-valued expression warnings
virtio: fix tx_ stats in virtio_net
virtio: ignore corrupted virtqueues rather than spinning.
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/Kbuild | 5 | ||||
-rw-r--r-- | include/linux/virtio.h | 7 | ||||
-rw-r--r-- | include/linux/virtio_blk.h | 14 | ||||
-rw-r--r-- | include/linux/virtio_config.h | 81 | ||||
-rw-r--r-- | include/linux/virtio_net.h | 13 |
5 files changed, 75 insertions, 45 deletions
diff --git a/include/linux/Kbuild b/include/linux/Kbuild index 78fade0a1e35..b7d81b2a9041 100644 --- a/include/linux/Kbuild +++ b/include/linux/Kbuild | |||
@@ -346,6 +346,11 @@ unifdef-y += videodev.h | |||
346 | unifdef-y += virtio_config.h | 346 | unifdef-y += virtio_config.h |
347 | unifdef-y += virtio_blk.h | 347 | unifdef-y += virtio_blk.h |
348 | unifdef-y += virtio_net.h | 348 | unifdef-y += virtio_net.h |
349 | unifdef-y += virtio_9p.h | ||
350 | unifdef-y += virtio_balloon.h | ||
351 | unifdef-y += virtio_console.h | ||
352 | unifdef-y += virtio_pci.h | ||
353 | unifdef-y += virtio_ring.h | ||
349 | unifdef-y += vt.h | 354 | unifdef-y += vt.h |
350 | unifdef-y += wait.h | 355 | unifdef-y += wait.h |
351 | unifdef-y += wanrouter.h | 356 | unifdef-y += wanrouter.h |
diff --git a/include/linux/virtio.h b/include/linux/virtio.h index e7d10845b3c1..06005fa9e982 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h | |||
@@ -76,6 +76,7 @@ struct virtqueue_ops { | |||
76 | * @dev: underlying device. | 76 | * @dev: underlying device. |
77 | * @id: the device type identification (used to match it with a driver). | 77 | * @id: the device type identification (used to match it with a driver). |
78 | * @config: the configuration ops for this device. | 78 | * @config: the configuration ops for this device. |
79 | * @features: the features supported by both driver and device. | ||
79 | * @priv: private pointer for the driver's use. | 80 | * @priv: private pointer for the driver's use. |
80 | */ | 81 | */ |
81 | struct virtio_device | 82 | struct virtio_device |
@@ -84,6 +85,8 @@ struct virtio_device | |||
84 | struct device dev; | 85 | struct device dev; |
85 | struct virtio_device_id id; | 86 | struct virtio_device_id id; |
86 | struct virtio_config_ops *config; | 87 | struct virtio_config_ops *config; |
88 | /* Note that this is a Linux set_bit-style bitmap. */ | ||
89 | unsigned long features[1]; | ||
87 | void *priv; | 90 | void *priv; |
88 | }; | 91 | }; |
89 | 92 | ||
@@ -94,6 +97,8 @@ void unregister_virtio_device(struct virtio_device *dev); | |||
94 | * virtio_driver - operations for a virtio I/O driver | 97 | * virtio_driver - operations for a virtio I/O driver |
95 | * @driver: underlying device driver (populate name and owner). | 98 | * @driver: underlying device driver (populate name and owner). |
96 | * @id_table: the ids serviced by this driver. | 99 | * @id_table: the ids serviced by this driver. |
100 | * @feature_table: an array of feature numbers supported by this device. | ||
101 | * @feature_table_size: number of entries in the feature table array. | ||
97 | * @probe: the function to call when a device is found. Returns a token for | 102 | * @probe: the function to call when a device is found. Returns a token for |
98 | * remove, or PTR_ERR(). | 103 | * remove, or PTR_ERR(). |
99 | * @remove: the function when a device is removed. | 104 | * @remove: the function when a device is removed. |
@@ -103,6 +108,8 @@ void unregister_virtio_device(struct virtio_device *dev); | |||
103 | struct virtio_driver { | 108 | struct virtio_driver { |
104 | struct device_driver driver; | 109 | struct device_driver driver; |
105 | const struct virtio_device_id *id_table; | 110 | const struct virtio_device_id *id_table; |
111 | const unsigned int *feature_table; | ||
112 | unsigned int feature_table_size; | ||
106 | int (*probe)(struct virtio_device *dev); | 113 | int (*probe)(struct virtio_device *dev); |
107 | void (*remove)(struct virtio_device *dev); | 114 | void (*remove)(struct virtio_device *dev); |
108 | void (*config_changed)(struct virtio_device *dev); | 115 | void (*config_changed)(struct virtio_device *dev); |
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h index bca0b10d7947..d4695a3356d0 100644 --- a/include/linux/virtio_blk.h +++ b/include/linux/virtio_blk.h | |||
@@ -9,6 +9,7 @@ | |||
9 | #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */ | 9 | #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */ |
10 | #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ | 10 | #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ |
11 | #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ | 11 | #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ |
12 | #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ | ||
12 | 13 | ||
13 | struct virtio_blk_config | 14 | struct virtio_blk_config |
14 | { | 15 | { |
@@ -18,6 +19,12 @@ struct virtio_blk_config | |||
18 | __le32 size_max; | 19 | __le32 size_max; |
19 | /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ | 20 | /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ |
20 | __le32 seg_max; | 21 | __le32 seg_max; |
22 | /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ | ||
23 | struct virtio_blk_geometry { | ||
24 | __le16 cylinders; | ||
25 | __u8 heads; | ||
26 | __u8 sectors; | ||
27 | } geometry; | ||
21 | } __attribute__((packed)); | 28 | } __attribute__((packed)); |
22 | 29 | ||
23 | /* These two define direction. */ | 30 | /* These two define direction. */ |
@@ -41,13 +48,8 @@ struct virtio_blk_outhdr | |||
41 | __u64 sector; | 48 | __u64 sector; |
42 | }; | 49 | }; |
43 | 50 | ||
51 | /* And this is the final byte of the write scatter-gather list. */ | ||
44 | #define VIRTIO_BLK_S_OK 0 | 52 | #define VIRTIO_BLK_S_OK 0 |
45 | #define VIRTIO_BLK_S_IOERR 1 | 53 | #define VIRTIO_BLK_S_IOERR 1 |
46 | #define VIRTIO_BLK_S_UNSUPP 2 | 54 | #define VIRTIO_BLK_S_UNSUPP 2 |
47 | |||
48 | /* This is the first element of the write scatter-gather list */ | ||
49 | struct virtio_blk_inhdr | ||
50 | { | ||
51 | unsigned char status; | ||
52 | }; | ||
53 | #endif /* _LINUX_VIRTIO_BLK_H */ | 55 | #endif /* _LINUX_VIRTIO_BLK_H */ |
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index d581b2914b34..50db245c81ad 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h | |||
@@ -16,27 +16,20 @@ | |||
16 | #define VIRTIO_CONFIG_S_FAILED 0x80 | 16 | #define VIRTIO_CONFIG_S_FAILED 0x80 |
17 | 17 | ||
18 | #ifdef __KERNEL__ | 18 | #ifdef __KERNEL__ |
19 | struct virtio_device; | 19 | #include <linux/virtio.h> |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * virtio_config_ops - operations for configuring a virtio device | 22 | * virtio_config_ops - operations for configuring a virtio device |
23 | * @feature: search for a feature in this config | ||
24 | * vdev: the virtio_device | ||
25 | * bit: the feature bit | ||
26 | * Returns true if the feature is supported. Acknowledges the feature | ||
27 | * so the host can see it. | ||
28 | * @get: read the value of a configuration field | 23 | * @get: read the value of a configuration field |
29 | * vdev: the virtio_device | 24 | * vdev: the virtio_device |
30 | * offset: the offset of the configuration field | 25 | * offset: the offset of the configuration field |
31 | * buf: the buffer to write the field value into. | 26 | * buf: the buffer to write the field value into. |
32 | * len: the length of the buffer | 27 | * len: the length of the buffer |
33 | * Note that contents are conventionally little-endian. | ||
34 | * @set: write the value of a configuration field | 28 | * @set: write the value of a configuration field |
35 | * vdev: the virtio_device | 29 | * vdev: the virtio_device |
36 | * offset: the offset of the configuration field | 30 | * offset: the offset of the configuration field |
37 | * buf: the buffer to read the field value from. | 31 | * buf: the buffer to read the field value from. |
38 | * len: the length of the buffer | 32 | * len: the length of the buffer |
39 | * Note that contents are conventionally little-endian. | ||
40 | * @get_status: read the status byte | 33 | * @get_status: read the status byte |
41 | * vdev: the virtio_device | 34 | * vdev: the virtio_device |
42 | * Returns the status byte | 35 | * Returns the status byte |
@@ -52,10 +45,15 @@ struct virtio_device; | |||
52 | * callback: the virqtueue callback | 45 | * callback: the virqtueue callback |
53 | * Returns the new virtqueue or ERR_PTR() (eg. -ENOENT). | 46 | * Returns the new virtqueue or ERR_PTR() (eg. -ENOENT). |
54 | * @del_vq: free a virtqueue found by find_vq(). | 47 | * @del_vq: free a virtqueue found by find_vq(). |
48 | * @get_features: get the array of feature bits for this device. | ||
49 | * vdev: the virtio_device | ||
50 | * Returns the first 32 feature bits (all we currently need). | ||
51 | * @set_features: confirm what device features we'll be using. | ||
52 | * vdev: the virtio_device | ||
53 | * feature: the first 32 feature bits | ||
55 | */ | 54 | */ |
56 | struct virtio_config_ops | 55 | struct virtio_config_ops |
57 | { | 56 | { |
58 | bool (*feature)(struct virtio_device *vdev, unsigned bit); | ||
59 | void (*get)(struct virtio_device *vdev, unsigned offset, | 57 | void (*get)(struct virtio_device *vdev, unsigned offset, |
60 | void *buf, unsigned len); | 58 | void *buf, unsigned len); |
61 | void (*set)(struct virtio_device *vdev, unsigned offset, | 59 | void (*set)(struct virtio_device *vdev, unsigned offset, |
@@ -67,43 +65,52 @@ struct virtio_config_ops | |||
67 | unsigned index, | 65 | unsigned index, |
68 | void (*callback)(struct virtqueue *)); | 66 | void (*callback)(struct virtqueue *)); |
69 | void (*del_vq)(struct virtqueue *vq); | 67 | void (*del_vq)(struct virtqueue *vq); |
68 | u32 (*get_features)(struct virtio_device *vdev); | ||
69 | void (*set_features)(struct virtio_device *vdev, u32 features); | ||
70 | }; | 70 | }; |
71 | 71 | ||
72 | /* If driver didn't advertise the feature, it will never appear. */ | ||
73 | void virtio_check_driver_offered_feature(const struct virtio_device *vdev, | ||
74 | unsigned int fbit); | ||
75 | |||
72 | /** | 76 | /** |
73 | * virtio_config_val - look for a feature and get a single virtio config. | 77 | * virtio_has_feature - helper to determine if this device has this feature. |
74 | * @vdev: the virtio device | 78 | * @vdev: the device |
75 | * @fbit: the feature bit | 79 | * @fbit: the feature bit |
76 | * @offset: the type to search for. | 80 | */ |
77 | * @val: a pointer to the value to fill in. | 81 | static inline bool virtio_has_feature(const struct virtio_device *vdev, |
78 | * | 82 | unsigned int fbit) |
79 | * The return value is -ENOENT if the feature doesn't exist. Otherwise | 83 | { |
80 | * the value is endian-corrected and returned in v. */ | 84 | /* Did you forget to fix assumptions on max features? */ |
81 | #define virtio_config_val(vdev, fbit, offset, v) ({ \ | 85 | if (__builtin_constant_p(fbit)) |
82 | int _err; \ | 86 | BUILD_BUG_ON(fbit >= 32); |
83 | if ((vdev)->config->feature((vdev), (fbit))) { \ | 87 | |
84 | __virtio_config_val((vdev), (offset), (v)); \ | 88 | virtio_check_driver_offered_feature(vdev, fbit); |
85 | _err = 0; \ | 89 | return test_bit(fbit, vdev->features); |
86 | } else \ | 90 | } |
87 | _err = -ENOENT; \ | ||
88 | _err; \ | ||
89 | }) | ||
90 | 91 | ||
91 | /** | 92 | /** |
92 | * __virtio_config_val - get a single virtio config without feature check. | 93 | * virtio_config_val - look for a feature and get a virtio config entry. |
93 | * @vdev: the virtio device | 94 | * @vdev: the virtio device |
95 | * @fbit: the feature bit | ||
94 | * @offset: the type to search for. | 96 | * @offset: the type to search for. |
95 | * @val: a pointer to the value to fill in. | 97 | * @val: a pointer to the value to fill in. |
96 | * | 98 | * |
97 | * The value is endian-corrected and returned in v. */ | 99 | * The return value is -ENOENT if the feature doesn't exist. Otherwise |
98 | #define __virtio_config_val(vdev, offset, v) do { \ | 100 | * the config value is copied into whatever is pointed to by v. */ |
99 | BUILD_BUG_ON(sizeof(*(v)) != 1 && sizeof(*(v)) != 2 \ | 101 | #define virtio_config_val(vdev, fbit, offset, v) \ |
100 | && sizeof(*(v)) != 4 && sizeof(*(v)) != 8); \ | 102 | virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(v)) |
101 | (vdev)->config->get((vdev), (offset), (v), sizeof(*(v))); \ | 103 | |
102 | switch (sizeof(*(v))) { \ | 104 | static inline int virtio_config_buf(struct virtio_device *vdev, |
103 | case 2: le16_to_cpus((__u16 *) v); break; \ | 105 | unsigned int fbit, |
104 | case 4: le32_to_cpus((__u32 *) v); break; \ | 106 | unsigned int offset, |
105 | case 8: le64_to_cpus((__u64 *) v); break; \ | 107 | void *buf, unsigned len) |
106 | } \ | 108 | { |
107 | } while(0) | 109 | if (!virtio_has_feature(vdev, fbit)) |
110 | return -ENOENT; | ||
111 | |||
112 | vdev->config->get(vdev, offset, buf, len); | ||
113 | return 0; | ||
114 | } | ||
108 | #endif /* __KERNEL__ */ | 115 | #endif /* __KERNEL__ */ |
109 | #endif /* _LINUX_VIRTIO_CONFIG_H */ | 116 | #endif /* _LINUX_VIRTIO_CONFIG_H */ |
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index 1ea3351df609..9405aa6cdf26 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h | |||
@@ -6,9 +6,18 @@ | |||
6 | #define VIRTIO_ID_NET 1 | 6 | #define VIRTIO_ID_NET 1 |
7 | 7 | ||
8 | /* The feature bitmap for virtio net */ | 8 | /* The feature bitmap for virtio net */ |
9 | #define VIRTIO_NET_F_CSUM 0 /* Can handle pkts w/ partial csum */ | 9 | #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ |
10 | #define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ | ||
10 | #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ | 11 | #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ |
11 | #define VIRTIO_NET_F_GSO 6 /* Can handle pkts w/ any GSO type */ | 12 | #define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ |
13 | #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ | ||
14 | #define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ | ||
15 | #define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */ | ||
16 | #define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */ | ||
17 | #define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */ | ||
18 | #define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */ | ||
19 | #define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */ | ||
20 | #define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */ | ||
12 | 21 | ||
13 | struct virtio_net_config | 22 | struct virtio_net_config |
14 | { | 23 | { |