diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2014-10-23 11:07:47 -0400 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2014-12-09 05:05:26 -0500 |
commit | b3bb62d11950eb6ac87403cacd667f84fa9495bc (patch) | |
tree | f3aee72f5e622722d19c484c7f5925990e97cffb | |
parent | c102659d690d382171bd2e40f35c5c811f0cdcac (diff) |
virtio: add legacy feature table support
virtio-blk has some legacy feature bits that modern drivers
must not negotiate, but are needed for old legacy hosts
(that e.g. don't support virtio-scsi).
Allow a separate legacy feature table for such cases.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
-rw-r--r-- | drivers/virtio/virtio.c | 25 | ||||
-rw-r--r-- | include/linux/virtio.h | 4 |
2 files changed, 28 insertions, 1 deletions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 3e78f4bcfa8e..f9ad99c8b352 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c | |||
@@ -113,6 +113,13 @@ void virtio_check_driver_offered_feature(const struct virtio_device *vdev, | |||
113 | for (i = 0; i < drv->feature_table_size; i++) | 113 | for (i = 0; i < drv->feature_table_size; i++) |
114 | if (drv->feature_table[i] == fbit) | 114 | if (drv->feature_table[i] == fbit) |
115 | return; | 115 | return; |
116 | |||
117 | if (drv->feature_table_legacy) { | ||
118 | for (i = 0; i < drv->feature_table_size_legacy; i++) | ||
119 | if (drv->feature_table_legacy[i] == fbit) | ||
120 | return; | ||
121 | } | ||
122 | |||
116 | BUG(); | 123 | BUG(); |
117 | } | 124 | } |
118 | EXPORT_SYMBOL_GPL(virtio_check_driver_offered_feature); | 125 | EXPORT_SYMBOL_GPL(virtio_check_driver_offered_feature); |
@@ -161,6 +168,7 @@ static int virtio_dev_probe(struct device *_d) | |||
161 | struct virtio_driver *drv = drv_to_virtio(dev->dev.driver); | 168 | struct virtio_driver *drv = drv_to_virtio(dev->dev.driver); |
162 | u64 device_features; | 169 | u64 device_features; |
163 | u64 driver_features; | 170 | u64 driver_features; |
171 | u64 driver_features_legacy; | ||
164 | unsigned status; | 172 | unsigned status; |
165 | 173 | ||
166 | /* We have a driver! */ | 174 | /* We have a driver! */ |
@@ -177,7 +185,22 @@ static int virtio_dev_probe(struct device *_d) | |||
177 | driver_features |= (1ULL << f); | 185 | driver_features |= (1ULL << f); |
178 | } | 186 | } |
179 | 187 | ||
180 | dev->features = driver_features & device_features; | 188 | /* Some drivers have a separate feature table for virtio v1.0 */ |
189 | if (drv->feature_table_legacy) { | ||
190 | driver_features_legacy = 0; | ||
191 | for (i = 0; i < drv->feature_table_size_legacy; i++) { | ||
192 | unsigned int f = drv->feature_table_legacy[i]; | ||
193 | BUG_ON(f >= 64); | ||
194 | driver_features_legacy |= (1ULL << f); | ||
195 | } | ||
196 | } else { | ||
197 | driver_features_legacy = driver_features; | ||
198 | } | ||
199 | |||
200 | if (driver_features & device_features & (1ULL << VIRTIO_F_VERSION_1)) | ||
201 | dev->features = driver_features & device_features; | ||
202 | else | ||
203 | dev->features = driver_features_legacy & device_features; | ||
181 | 204 | ||
182 | /* Transport features always preserved to pass to finalize_features. */ | 205 | /* Transport features always preserved to pass to finalize_features. */ |
183 | for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) | 206 | for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) |
diff --git a/include/linux/virtio.h b/include/linux/virtio.h index d6359a5d5d4e..f70411eb9d27 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h | |||
@@ -130,6 +130,8 @@ int virtio_device_restore(struct virtio_device *dev); | |||
130 | * @id_table: the ids serviced by this driver. | 130 | * @id_table: the ids serviced by this driver. |
131 | * @feature_table: an array of feature numbers supported by this driver. | 131 | * @feature_table: an array of feature numbers supported by this driver. |
132 | * @feature_table_size: number of entries in the feature table array. | 132 | * @feature_table_size: number of entries in the feature table array. |
133 | * @feature_table_legacy: same as feature_table but when working in legacy mode. | ||
134 | * @feature_table_size_legacy: number of entries in feature table legacy array. | ||
133 | * @probe: the function to call when a device is found. Returns 0 or -errno. | 135 | * @probe: the function to call when a device is found. Returns 0 or -errno. |
134 | * @remove: the function to call when a device is removed. | 136 | * @remove: the function to call when a device is removed. |
135 | * @config_changed: optional function to call when the device configuration | 137 | * @config_changed: optional function to call when the device configuration |
@@ -140,6 +142,8 @@ struct virtio_driver { | |||
140 | const struct virtio_device_id *id_table; | 142 | const struct virtio_device_id *id_table; |
141 | const unsigned int *feature_table; | 143 | const unsigned int *feature_table; |
142 | unsigned int feature_table_size; | 144 | unsigned int feature_table_size; |
145 | const unsigned int *feature_table_legacy; | ||
146 | unsigned int feature_table_size_legacy; | ||
143 | int (*probe)(struct virtio_device *dev); | 147 | int (*probe)(struct virtio_device *dev); |
144 | void (*scan)(struct virtio_device *dev); | 148 | void (*scan)(struct virtio_device *dev); |
145 | void (*remove)(struct virtio_device *dev); | 149 | void (*remove)(struct virtio_device *dev); |