blob: 32baf8e26735d5fd9c693105b681c557cab049e2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Rusty Russellec3d41c2007-10-22 11:03:36 +10002#ifndef _LINUX_VIRTIO_CONFIG_H
3#define _LINUX_VIRTIO_CONFIG_H
Rusty Russell674bfc22008-07-25 12:06:03 -05004
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -06005#include <linux/err.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -05006#include <linux/bug.h>
Rusty Russell72e61eb2008-05-02 21:50:49 -05007#include <linux/virtio.h>
Michael S. Tsirkineef960a2014-10-22 15:35:56 +03008#include <linux/virtio_byteorder.h>
David Howells607ca462012-10-13 10:46:48 +01009#include <uapi/linux/virtio_config.h>
Rusty Russellec3d41c2007-10-22 11:03:36 +100010
Christoph Hellwigfb5e31d2017-02-05 18:15:22 +010011struct irq_affinity;
12
Rusty Russellec3d41c2007-10-22 11:03:36 +100013/**
14 * virtio_config_ops - operations for configuring a virtio device
Rusty Russella586d4f2008-02-04 23:49:56 -050015 * @get: read the value of a configuration field
Rusty Russellec3d41c2007-10-22 11:03:36 +100016 * vdev: the virtio_device
Rusty Russella586d4f2008-02-04 23:49:56 -050017 * offset: the offset of the configuration field
Rusty Russellec3d41c2007-10-22 11:03:36 +100018 * buf: the buffer to write the field value into.
Rusty Russella586d4f2008-02-04 23:49:56 -050019 * len: the length of the buffer
Rusty Russella586d4f2008-02-04 23:49:56 -050020 * @set: write the value of a configuration field
Rusty Russellec3d41c2007-10-22 11:03:36 +100021 * vdev: the virtio_device
Rusty Russella586d4f2008-02-04 23:49:56 -050022 * offset: the offset of the configuration field
Rusty Russellec3d41c2007-10-22 11:03:36 +100023 * buf: the buffer to read the field value from.
Rusty Russella586d4f2008-02-04 23:49:56 -050024 * len: the length of the buffer
Michael S. Tsirkind71de9e2014-12-14 16:55:44 +020025 * @generation: config generation counter
26 * vdev: the virtio_device
27 * Returns the config generation counter
Rusty Russellec3d41c2007-10-22 11:03:36 +100028 * @get_status: read the status byte
29 * vdev: the virtio_device
30 * Returns the status byte
31 * @set_status: write the status byte
32 * vdev: the virtio_device
33 * status: the new status byte
Rusty Russell6e5aa7e2008-02-04 23:50:03 -050034 * @reset: reset the device
35 * vdev: the virtio device
36 * After this, status and feature negotiation must be done again
Michael S. Tsirkine6af5782011-11-17 17:41:15 +020037 * Device must not be reset from its vq/config callbacks, or in
38 * parallel with being added/removed.
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -060039 * @find_vqs: find virtqueues and instantiate them.
Rusty Russellec3d41c2007-10-22 11:03:36 +100040 * vdev: the virtio_device
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -060041 * nvqs: the number of virtqueues to find
42 * vqs: on success, includes new virtqueues
43 * callbacks: array of callbacks, for each virtqueue
Michael S. Tsirkin6457f122012-09-05 21:47:45 +030044 * include a NULL entry for vqs that do not need a callback
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -060045 * names: array of virtqueue names (mainly for debugging)
Michael S. Tsirkin6457f122012-09-05 21:47:45 +030046 * include a NULL entry for vqs unused by driver
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -060047 * Returns 0 on success or error status
48 * @del_vqs: free virtqueues found by find_vqs().
Rusty Russellc45a6812008-05-02 21:50:50 -050049 * @get_features: get the array of feature bits for this device.
50 * vdev: the virtio_device
51 * Returns the first 32 feature bits (all we currently need).
Rusty Russellc6248962008-07-25 12:06:07 -050052 * @finalize_features: confirm what device features we'll be using.
Rusty Russellc45a6812008-05-02 21:50:50 -050053 * vdev: the virtio_device
Rusty Russellc6248962008-07-25 12:06:07 -050054 * This gives the final feature bits for the device: it can change
55 * the dev->feature bits if it wants.
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +020056 * Returns 0 on success or error status
Rick Jones66846042011-11-14 14:17:08 +000057 * @bus_name: return the bus name associated with the device
58 * vdev: the virtio_device
59 * This returns a pointer to the bus name a la pci_name from which
60 * the caller can then copy.
Jason Wang75a0a522012-08-28 13:54:14 +020061 * @set_vq_affinity: set the affinity for a virtqueue.
Christoph Hellwigbbaba472017-02-05 18:15:23 +010062 * @get_vq_affinity: get the affinity for a virtqueue (optional).
Rusty Russellec3d41c2007-10-22 11:03:36 +100063 */
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -060064typedef void vq_callback_t(struct virtqueue *);
Rusty Russell1842f232009-07-30 16:03:46 -060065struct virtio_config_ops {
Rusty Russella586d4f2008-02-04 23:49:56 -050066 void (*get)(struct virtio_device *vdev, unsigned offset,
Rusty Russellec3d41c2007-10-22 11:03:36 +100067 void *buf, unsigned len);
Rusty Russella586d4f2008-02-04 23:49:56 -050068 void (*set)(struct virtio_device *vdev, unsigned offset,
Rusty Russellec3d41c2007-10-22 11:03:36 +100069 const void *buf, unsigned len);
Michael S. Tsirkind71de9e2014-12-14 16:55:44 +020070 u32 (*generation)(struct virtio_device *vdev);
Rusty Russellec3d41c2007-10-22 11:03:36 +100071 u8 (*get_status)(struct virtio_device *vdev);
72 void (*set_status)(struct virtio_device *vdev, u8 status);
Rusty Russell6e5aa7e2008-02-04 23:50:03 -050073 void (*reset)(struct virtio_device *vdev);
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -060074 int (*find_vqs)(struct virtio_device *, unsigned nvqs,
Christoph Hellwigfb5e31d2017-02-05 18:15:22 +010075 struct virtqueue *vqs[], vq_callback_t *callbacks[],
Michael S. Tsirkinf94682d2017-03-06 18:32:29 +020076 const char * const names[], const bool *ctx,
77 struct irq_affinity *desc);
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -060078 void (*del_vqs)(struct virtio_device *);
Michael S. Tsirkind0254772014-10-07 16:39:43 +020079 u64 (*get_features)(struct virtio_device *vdev);
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +020080 int (*finalize_features)(struct virtio_device *vdev);
Rick Jones66846042011-11-14 14:17:08 +000081 const char *(*bus_name)(struct virtio_device *vdev);
Caleb Raitto19e226e2018-08-09 18:18:28 -070082 int (*set_vq_affinity)(struct virtqueue *vq,
83 const struct cpumask *cpu_mask);
Christoph Hellwigbbaba472017-02-05 18:15:23 +010084 const struct cpumask *(*get_vq_affinity)(struct virtio_device *vdev,
85 int index);
Rusty Russellec3d41c2007-10-22 11:03:36 +100086};
87
Rusty Russellc45a6812008-05-02 21:50:50 -050088/* If driver didn't advertise the feature, it will never appear. */
89void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
90 unsigned int fbit);
91
92/**
Michael S. Tsirkind4024af2014-11-27 21:19:02 +020093 * __virtio_test_bit - helper to test feature bits. For use by transports.
94 * Devices should normally use virtio_has_feature,
95 * which includes more checks.
Rusty Russellc45a6812008-05-02 21:50:50 -050096 * @vdev: the device
97 * @fbit: the feature bit
98 */
Michael S. Tsirkind4024af2014-11-27 21:19:02 +020099static inline bool __virtio_test_bit(const struct virtio_device *vdev,
100 unsigned int fbit)
101{
102 /* Did you forget to fix assumptions on max features? */
103 if (__builtin_constant_p(fbit))
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200104 BUILD_BUG_ON(fbit >= 64);
Michael S. Tsirkind4024af2014-11-27 21:19:02 +0200105 else
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200106 BUG_ON(fbit >= 64);
Michael S. Tsirkind4024af2014-11-27 21:19:02 +0200107
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200108 return vdev->features & BIT_ULL(fbit);
Michael S. Tsirkind4024af2014-11-27 21:19:02 +0200109}
110
111/**
112 * __virtio_set_bit - helper to set feature bits. For use by transports.
113 * @vdev: the device
114 * @fbit: the feature bit
115 */
116static inline void __virtio_set_bit(struct virtio_device *vdev,
117 unsigned int fbit)
118{
119 /* Did you forget to fix assumptions on max features? */
120 if (__builtin_constant_p(fbit))
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200121 BUILD_BUG_ON(fbit >= 64);
Michael S. Tsirkind4024af2014-11-27 21:19:02 +0200122 else
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200123 BUG_ON(fbit >= 64);
Michael S. Tsirkind4024af2014-11-27 21:19:02 +0200124
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200125 vdev->features |= BIT_ULL(fbit);
Michael S. Tsirkind4024af2014-11-27 21:19:02 +0200126}
127
128/**
129 * __virtio_clear_bit - helper to clear feature bits. For use by transports.
130 * @vdev: the device
131 * @fbit: the feature bit
132 */
133static inline void __virtio_clear_bit(struct virtio_device *vdev,
Rusty Russellc45a6812008-05-02 21:50:50 -0500134 unsigned int fbit)
135{
136 /* Did you forget to fix assumptions on max features? */
Rusty Russell1765e3a2011-01-24 14:45:10 -0600137 if (__builtin_constant_p(fbit))
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200138 BUILD_BUG_ON(fbit >= 64);
Rusty Russell1765e3a2011-01-24 14:45:10 -0600139 else
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200140 BUG_ON(fbit >= 64);
Rusty Russellc45a6812008-05-02 21:50:50 -0500141
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200142 vdev->features &= ~BIT_ULL(fbit);
Michael S. Tsirkind4024af2014-11-27 21:19:02 +0200143}
144
145/**
146 * virtio_has_feature - helper to determine if this device has this feature.
147 * @vdev: the device
148 * @fbit: the feature bit
149 */
150static inline bool virtio_has_feature(const struct virtio_device *vdev,
151 unsigned int fbit)
152{
Mark McLoughlinee006b352009-05-11 18:11:44 +0100153 if (fbit < VIRTIO_TRANSPORT_F_START)
154 virtio_check_driver_offered_feature(vdev, fbit);
155
Michael S. Tsirkind4024af2014-11-27 21:19:02 +0200156 return __virtio_test_bit(vdev, fbit);
Rusty Russellc45a6812008-05-02 21:50:50 -0500157}
158
Michael S. Tsirkin1a937692016-04-18 12:58:14 +0300159/**
160 * virtio_has_iommu_quirk - determine whether this device has the iommu quirk
161 * @vdev: the device
162 */
163static inline bool virtio_has_iommu_quirk(const struct virtio_device *vdev)
164{
165 /*
166 * Note the reverse polarity of the quirk feature (compared to most
167 * other features), this is for compatibility with legacy systems.
168 */
169 return !virtio_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
170}
171
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -0600172static inline
173struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
174 vq_callback_t *c, const char *n)
175{
176 vq_callback_t *callbacks[] = { c };
177 const char *names[] = { n };
178 struct virtqueue *vq;
Michael S. Tsirkinf94682d2017-03-06 18:32:29 +0200179 int err = vdev->config->find_vqs(vdev, 1, &vq, callbacks, names, NULL,
180 NULL);
Michael S. Tsirkind2a7ddd2009-06-12 22:16:36 -0600181 if (err < 0)
182 return ERR_PTR(err);
183 return vq;
184}
Rick Jones66846042011-11-14 14:17:08 +0000185
Michael S. Tsirkin9b2bbdb2017-03-06 18:19:39 +0200186static inline
187int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
188 struct virtqueue *vqs[], vq_callback_t *callbacks[],
189 const char * const names[],
190 struct irq_affinity *desc)
191{
Michael S. Tsirkinf94682d2017-03-06 18:32:29 +0200192 return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, desc);
193}
194
195static inline
196int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs,
197 struct virtqueue *vqs[], vq_callback_t *callbacks[],
198 const char * const names[], const bool *ctx,
199 struct irq_affinity *desc)
200{
201 return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, ctx,
202 desc);
Michael S. Tsirkin9b2bbdb2017-03-06 18:19:39 +0200203}
204
Michael S. Tsirkin3569db52014-10-15 10:22:30 +1030205/**
206 * virtio_device_ready - enable vq use in probe function
207 * @vdev: the device
208 *
209 * Driver must call this to use vqs in the probe function.
210 *
211 * Note: vqs are enabled automatically after probe returns.
212 */
213static inline
214void virtio_device_ready(struct virtio_device *dev)
215{
216 unsigned status = dev->config->get_status(dev);
217
218 BUG_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
219 dev->config->set_status(dev, status | VIRTIO_CONFIG_S_DRIVER_OK);
220}
221
Rick Jones66846042011-11-14 14:17:08 +0000222static inline
223const char *virtio_bus_name(struct virtio_device *vdev)
224{
225 if (!vdev->config->bus_name)
226 return "virtio";
227 return vdev->config->bus_name(vdev);
228}
229
Jason Wang75a0a522012-08-28 13:54:14 +0200230/**
231 * virtqueue_set_affinity - setting affinity for a virtqueue
232 * @vq: the virtqueue
233 * @cpu: the cpu no.
234 *
235 * Pay attention the function are best-effort: the affinity hint may not be set
236 * due to config support, irq type and sharing.
237 *
238 */
239static inline
Caleb Raitto19e226e2018-08-09 18:18:28 -0700240int virtqueue_set_affinity(struct virtqueue *vq, const struct cpumask *cpu_mask)
Jason Wang75a0a522012-08-28 13:54:14 +0200241{
242 struct virtio_device *vdev = vq->vdev;
243 if (vdev->config->set_vq_affinity)
Caleb Raitto19e226e2018-08-09 18:18:28 -0700244 return vdev->config->set_vq_affinity(vq, cpu_mask);
Jason Wang75a0a522012-08-28 13:54:14 +0200245 return 0;
246}
247
Greg Kurzcf561f02015-04-24 14:24:27 +0200248static inline bool virtio_is_little_endian(struct virtio_device *vdev)
249{
Greg Kurz7d824102015-04-24 14:26:24 +0200250 return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) ||
251 virtio_legacy_is_little_endian();
Greg Kurzcf561f02015-04-24 14:24:27 +0200252}
253
Michael S. Tsirkineef960a2014-10-22 15:35:56 +0300254/* Memory accessors */
255static inline u16 virtio16_to_cpu(struct virtio_device *vdev, __virtio16 val)
256{
Greg Kurzcf561f02015-04-24 14:24:27 +0200257 return __virtio16_to_cpu(virtio_is_little_endian(vdev), val);
Michael S. Tsirkineef960a2014-10-22 15:35:56 +0300258}
259
260static inline __virtio16 cpu_to_virtio16(struct virtio_device *vdev, u16 val)
261{
Greg Kurzcf561f02015-04-24 14:24:27 +0200262 return __cpu_to_virtio16(virtio_is_little_endian(vdev), val);
Michael S. Tsirkineef960a2014-10-22 15:35:56 +0300263}
264
265static inline u32 virtio32_to_cpu(struct virtio_device *vdev, __virtio32 val)
266{
Greg Kurzcf561f02015-04-24 14:24:27 +0200267 return __virtio32_to_cpu(virtio_is_little_endian(vdev), val);
Michael S. Tsirkineef960a2014-10-22 15:35:56 +0300268}
269
270static inline __virtio32 cpu_to_virtio32(struct virtio_device *vdev, u32 val)
271{
Greg Kurzcf561f02015-04-24 14:24:27 +0200272 return __cpu_to_virtio32(virtio_is_little_endian(vdev), val);
Michael S. Tsirkineef960a2014-10-22 15:35:56 +0300273}
274
275static inline u64 virtio64_to_cpu(struct virtio_device *vdev, __virtio64 val)
276{
Greg Kurzcf561f02015-04-24 14:24:27 +0200277 return __virtio64_to_cpu(virtio_is_little_endian(vdev), val);
Michael S. Tsirkineef960a2014-10-22 15:35:56 +0300278}
279
280static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
281{
Greg Kurzcf561f02015-04-24 14:24:27 +0200282 return __cpu_to_virtio64(virtio_is_little_endian(vdev), val);
Michael S. Tsirkineef960a2014-10-22 15:35:56 +0300283}
284
Rusty Russell0b90d062013-10-14 18:11:51 +1030285/* Config space accessors. */
286#define virtio_cread(vdev, structname, member, ptr) \
287 do { \
288 /* Must match the member's type, and be integer */ \
289 if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \
290 (*ptr) = 1; \
291 \
292 switch (sizeof(*ptr)) { \
293 case 1: \
294 *(ptr) = virtio_cread8(vdev, \
295 offsetof(structname, member)); \
296 break; \
297 case 2: \
298 *(ptr) = virtio_cread16(vdev, \
299 offsetof(structname, member)); \
300 break; \
301 case 4: \
302 *(ptr) = virtio_cread32(vdev, \
303 offsetof(structname, member)); \
304 break; \
305 case 8: \
306 *(ptr) = virtio_cread64(vdev, \
307 offsetof(structname, member)); \
308 break; \
309 default: \
310 BUG(); \
311 } \
312 } while(0)
313
314/* Config space accessors. */
315#define virtio_cwrite(vdev, structname, member, ptr) \
316 do { \
317 /* Must match the member's type, and be integer */ \
318 if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \
319 BUG_ON((*ptr) == 1); \
320 \
321 switch (sizeof(*ptr)) { \
322 case 1: \
323 virtio_cwrite8(vdev, \
324 offsetof(structname, member), \
325 *(ptr)); \
326 break; \
327 case 2: \
328 virtio_cwrite16(vdev, \
329 offsetof(structname, member), \
330 *(ptr)); \
331 break; \
332 case 4: \
333 virtio_cwrite32(vdev, \
334 offsetof(structname, member), \
335 *(ptr)); \
336 break; \
337 case 8: \
338 virtio_cwrite64(vdev, \
339 offsetof(structname, member), \
340 *(ptr)); \
341 break; \
342 default: \
343 BUG(); \
344 } \
345 } while(0)
346
Michael S. Tsirkind71de9e2014-12-14 16:55:44 +0200347/* Read @count fields, @bytes each. */
348static inline void __virtio_cread_many(struct virtio_device *vdev,
349 unsigned int offset,
350 void *buf, size_t count, size_t bytes)
351{
352 u32 old, gen = vdev->config->generation ?
353 vdev->config->generation(vdev) : 0;
354 int i;
355
356 do {
357 old = gen;
358
359 for (i = 0; i < count; i++)
360 vdev->config->get(vdev, offset + bytes * i,
361 buf + i * bytes, bytes);
362
363 gen = vdev->config->generation ?
364 vdev->config->generation(vdev) : 0;
365 } while (gen != old);
366}
367
Rusty Russell0b90d062013-10-14 18:11:51 +1030368static inline void virtio_cread_bytes(struct virtio_device *vdev,
369 unsigned int offset,
370 void *buf, size_t len)
371{
Michael S. Tsirkind71de9e2014-12-14 16:55:44 +0200372 __virtio_cread_many(vdev, offset, buf, len, 1);
Rusty Russell0b90d062013-10-14 18:11:51 +1030373}
374
Michael S. Tsirkincaa0e2d2015-04-01 08:21:51 +1030375static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
376{
377 u8 ret;
378 vdev->config->get(vdev, offset, &ret, sizeof(ret));
379 return ret;
380}
381
Rusty Russell0b90d062013-10-14 18:11:51 +1030382static inline void virtio_cwrite8(struct virtio_device *vdev,
383 unsigned int offset, u8 val)
384{
385 vdev->config->set(vdev, offset, &val, sizeof(val));
386}
387
388static inline u16 virtio_cread16(struct virtio_device *vdev,
389 unsigned int offset)
390{
391 u16 ret;
392 vdev->config->get(vdev, offset, &ret, sizeof(ret));
Michael S. Tsirkin92e6d742014-10-22 16:59:01 +0300393 return virtio16_to_cpu(vdev, (__force __virtio16)ret);
Rusty Russell0b90d062013-10-14 18:11:51 +1030394}
395
396static inline void virtio_cwrite16(struct virtio_device *vdev,
397 unsigned int offset, u16 val)
398{
Michael S. Tsirkin92e6d742014-10-22 16:59:01 +0300399 val = (__force u16)cpu_to_virtio16(vdev, val);
Rusty Russell0b90d062013-10-14 18:11:51 +1030400 vdev->config->set(vdev, offset, &val, sizeof(val));
401}
402
403static inline u32 virtio_cread32(struct virtio_device *vdev,
404 unsigned int offset)
405{
406 u32 ret;
407 vdev->config->get(vdev, offset, &ret, sizeof(ret));
Michael S. Tsirkin92e6d742014-10-22 16:59:01 +0300408 return virtio32_to_cpu(vdev, (__force __virtio32)ret);
Rusty Russell0b90d062013-10-14 18:11:51 +1030409}
410
411static inline void virtio_cwrite32(struct virtio_device *vdev,
412 unsigned int offset, u32 val)
413{
Michael S. Tsirkin92e6d742014-10-22 16:59:01 +0300414 val = (__force u32)cpu_to_virtio32(vdev, val);
Rusty Russell0b90d062013-10-14 18:11:51 +1030415 vdev->config->set(vdev, offset, &val, sizeof(val));
416}
417
418static inline u64 virtio_cread64(struct virtio_device *vdev,
419 unsigned int offset)
420{
421 u64 ret;
Michael S. Tsirkind71de9e2014-12-14 16:55:44 +0200422 __virtio_cread_many(vdev, offset, &ret, 1, sizeof(ret));
Michael S. Tsirkin92e6d742014-10-22 16:59:01 +0300423 return virtio64_to_cpu(vdev, (__force __virtio64)ret);
Rusty Russell0b90d062013-10-14 18:11:51 +1030424}
425
426static inline void virtio_cwrite64(struct virtio_device *vdev,
427 unsigned int offset, u64 val)
428{
Michael S. Tsirkin92e6d742014-10-22 16:59:01 +0300429 val = (__force u64)cpu_to_virtio64(vdev, val);
Rusty Russell0b90d062013-10-14 18:11:51 +1030430 vdev->config->set(vdev, offset, &val, sizeof(val));
431}
432
433/* Conditional config space accessors. */
434#define virtio_cread_feature(vdev, fbit, structname, member, ptr) \
435 ({ \
436 int _r = 0; \
437 if (!virtio_has_feature(vdev, fbit)) \
438 _r = -ENOENT; \
439 else \
440 virtio_cread((vdev), structname, member, ptr); \
441 _r; \
442 })
Jason Wang75a0a522012-08-28 13:54:14 +0200443
Rusty Russellec3d41c2007-10-22 11:03:36 +1000444#endif /* _LINUX_VIRTIO_CONFIG_H */