virtio_config.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_VIRTIO_CONFIG_H
  3. #define _LINUX_VIRTIO_CONFIG_H
  4. #include <linux/err.h>
  5. #include <linux/bug.h>
  6. #include <linux/virtio.h>
  7. #include <linux/virtio_byteorder.h>
  8. #include <linux/compiler_types.h>
  9. #include <uapi/linux/virtio_config.h>
  10. struct irq_affinity;
  11. struct virtio_shm_region {
  12. u64 addr;
  13. u64 len;
  14. };
  15. /**
  16. * virtio_config_ops - operations for configuring a virtio device
  17. * Note: Do not assume that a transport implements all of the operations
  18. * getting/setting a value as a simple read/write! Generally speaking,
  19. * any of @get/@set, @get_status/@set_status, or @get_features/
  20. * @finalize_features are NOT safe to be called from an atomic
  21. * context.
  22. * @get: read the value of a configuration field
  23. * vdev: the virtio_device
  24. * offset: the offset of the configuration field
  25. * buf: the buffer to write the field value into.
  26. * len: the length of the buffer
  27. * @set: write the value of a configuration field
  28. * vdev: the virtio_device
  29. * offset: the offset of the configuration field
  30. * buf: the buffer to read the field value from.
  31. * len: the length of the buffer
  32. * @generation: config generation counter (optional)
  33. * vdev: the virtio_device
  34. * Returns the config generation counter
  35. * @get_status: read the status byte
  36. * vdev: the virtio_device
  37. * Returns the status byte
  38. * @set_status: write the status byte
  39. * vdev: the virtio_device
  40. * status: the new status byte
  41. * @reset: reset the device
  42. * vdev: the virtio device
  43. * After this, status and feature negotiation must be done again
  44. * Device must not be reset from its vq/config callbacks, or in
  45. * parallel with being added/removed.
  46. * @find_vqs: find virtqueues and instantiate them.
  47. * vdev: the virtio_device
  48. * nvqs: the number of virtqueues to find
  49. * vqs: on success, includes new virtqueues
  50. * callbacks: array of callbacks, for each virtqueue
  51. * include a NULL entry for vqs that do not need a callback
  52. * names: array of virtqueue names (mainly for debugging)
  53. * include a NULL entry for vqs unused by driver
  54. * Returns 0 on success or error status
  55. * @del_vqs: free virtqueues found by find_vqs().
  56. * @synchronize_cbs: synchronize with the virtqueue callbacks (optional)
  57. * The function guarantees that all memory operations on the
  58. * queue before it are visible to the vring_interrupt() that is
  59. * called after it.
  60. * vdev: the virtio_device
  61. * @get_features: get the array of feature bits for this device.
  62. * vdev: the virtio_device
  63. * Returns the first 64 feature bits (all we currently need).
  64. * @finalize_features: confirm what device features we'll be using.
  65. * vdev: the virtio_device
  66. * This sends the driver feature bits to the device: it can change
  67. * the dev->feature bits if it wants.
  68. * Note: despite the name this can be called any number of times.
  69. * Returns 0 on success or error status
  70. * @bus_name: return the bus name associated with the device (optional)
  71. * vdev: the virtio_device
  72. * This returns a pointer to the bus name a la pci_name from which
  73. * the caller can then copy.
  74. * @set_vq_affinity: set the affinity for a virtqueue (optional).
  75. * @get_vq_affinity: get the affinity for a virtqueue (optional).
  76. * @get_shm_region: get a shared memory region based on the index.
  77. * @disable_vq_and_reset: reset a queue individually (optional).
  78. * vq: the virtqueue
  79. * Returns 0 on success or error status
  80. * disable_vq_and_reset will guarantee that the callbacks are disabled and
  81. * synchronized.
  82. * Except for the callback, the caller should guarantee that the vring is
  83. * not accessed by any functions of virtqueue.
  84. * @enable_vq_after_reset: enable a reset queue
  85. * vq: the virtqueue
  86. * Returns 0 on success or error status
  87. * If disable_vq_and_reset is set, then enable_vq_after_reset must also be
  88. * set.
  89. */
  90. typedef void vq_callback_t(struct virtqueue *);
  91. struct virtio_config_ops {
  92. void (*get)(struct virtio_device *vdev, unsigned offset,
  93. void *buf, unsigned len);
  94. void (*set)(struct virtio_device *vdev, unsigned offset,
  95. const void *buf, unsigned len);
  96. u32 (*generation)(struct virtio_device *vdev);
  97. u8 (*get_status)(struct virtio_device *vdev);
  98. void (*set_status)(struct virtio_device *vdev, u8 status);
  99. void (*reset)(struct virtio_device *vdev);
  100. int (*find_vqs)(struct virtio_device *, unsigned nvqs,
  101. struct virtqueue *vqs[], vq_callback_t *callbacks[],
  102. const char * const names[], const bool *ctx,
  103. struct irq_affinity *desc);
  104. void (*del_vqs)(struct virtio_device *);
  105. void (*synchronize_cbs)(struct virtio_device *);
  106. u64 (*get_features)(struct virtio_device *vdev);
  107. int (*finalize_features)(struct virtio_device *vdev);
  108. const char *(*bus_name)(struct virtio_device *vdev);
  109. int (*set_vq_affinity)(struct virtqueue *vq,
  110. const struct cpumask *cpu_mask);
  111. const struct cpumask *(*get_vq_affinity)(struct virtio_device *vdev,
  112. int index);
  113. bool (*get_shm_region)(struct virtio_device *vdev,
  114. struct virtio_shm_region *region, u8 id);
  115. int (*disable_vq_and_reset)(struct virtqueue *vq);
  116. int (*enable_vq_after_reset)(struct virtqueue *vq);
  117. };
  118. /* If driver didn't advertise the feature, it will never appear. */
  119. void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
  120. unsigned int fbit);
  121. /**
  122. * __virtio_test_bit - helper to test feature bits. For use by transports.
  123. * Devices should normally use virtio_has_feature,
  124. * which includes more checks.
  125. * @vdev: the device
  126. * @fbit: the feature bit
  127. */
  128. static inline bool __virtio_test_bit(const struct virtio_device *vdev,
  129. unsigned int fbit)
  130. {
  131. /* Did you forget to fix assumptions on max features? */
  132. if (__builtin_constant_p(fbit))
  133. BUILD_BUG_ON(fbit >= 64);
  134. else
  135. BUG_ON(fbit >= 64);
  136. return vdev->features & BIT_ULL(fbit);
  137. }
  138. /**
  139. * __virtio_set_bit - helper to set feature bits. For use by transports.
  140. * @vdev: the device
  141. * @fbit: the feature bit
  142. */
  143. static inline void __virtio_set_bit(struct virtio_device *vdev,
  144. unsigned int fbit)
  145. {
  146. /* Did you forget to fix assumptions on max features? */
  147. if (__builtin_constant_p(fbit))
  148. BUILD_BUG_ON(fbit >= 64);
  149. else
  150. BUG_ON(fbit >= 64);
  151. vdev->features |= BIT_ULL(fbit);
  152. }
  153. /**
  154. * __virtio_clear_bit - helper to clear feature bits. For use by transports.
  155. * @vdev: the device
  156. * @fbit: the feature bit
  157. */
  158. static inline void __virtio_clear_bit(struct virtio_device *vdev,
  159. unsigned int fbit)
  160. {
  161. /* Did you forget to fix assumptions on max features? */
  162. if (__builtin_constant_p(fbit))
  163. BUILD_BUG_ON(fbit >= 64);
  164. else
  165. BUG_ON(fbit >= 64);
  166. vdev->features &= ~BIT_ULL(fbit);
  167. }
  168. /**
  169. * virtio_has_feature - helper to determine if this device has this feature.
  170. * @vdev: the device
  171. * @fbit: the feature bit
  172. */
  173. static inline bool virtio_has_feature(const struct virtio_device *vdev,
  174. unsigned int fbit)
  175. {
  176. if (fbit < VIRTIO_TRANSPORT_F_START)
  177. virtio_check_driver_offered_feature(vdev, fbit);
  178. return __virtio_test_bit(vdev, fbit);
  179. }
  180. /**
  181. * virtio_has_dma_quirk - determine whether this device has the DMA quirk
  182. * @vdev: the device
  183. */
  184. static inline bool virtio_has_dma_quirk(const struct virtio_device *vdev)
  185. {
  186. /*
  187. * Note the reverse polarity of the quirk feature (compared to most
  188. * other features), this is for compatibility with legacy systems.
  189. */
  190. return !virtio_has_feature(vdev, VIRTIO_F_ACCESS_PLATFORM);
  191. }
  192. static inline
  193. struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
  194. vq_callback_t *c, const char *n)
  195. {
  196. vq_callback_t *callbacks[] = { c };
  197. const char *names[] = { n };
  198. struct virtqueue *vq;
  199. int err = vdev->config->find_vqs(vdev, 1, &vq, callbacks, names, NULL,
  200. NULL);
  201. if (err < 0)
  202. return ERR_PTR(err);
  203. return vq;
  204. }
  205. static inline
  206. int virtio_find_vqs(struct virtio_device *vdev, unsigned nvqs,
  207. struct virtqueue *vqs[], vq_callback_t *callbacks[],
  208. const char * const names[],
  209. struct irq_affinity *desc)
  210. {
  211. return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, NULL, desc);
  212. }
  213. static inline
  214. int virtio_find_vqs_ctx(struct virtio_device *vdev, unsigned nvqs,
  215. struct virtqueue *vqs[], vq_callback_t *callbacks[],
  216. const char * const names[], const bool *ctx,
  217. struct irq_affinity *desc)
  218. {
  219. return vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names, ctx,
  220. desc);
  221. }
  222. /**
  223. * virtio_synchronize_cbs - synchronize with virtqueue callbacks
  224. * @dev: the virtio device
  225. */
  226. static inline
  227. void virtio_synchronize_cbs(struct virtio_device *dev)
  228. {
  229. if (dev->config->synchronize_cbs) {
  230. dev->config->synchronize_cbs(dev);
  231. } else {
  232. /*
  233. * A best effort fallback to synchronize with
  234. * interrupts, preemption and softirq disabled
  235. * regions. See comment above synchronize_rcu().
  236. */
  237. synchronize_rcu();
  238. }
  239. }
  240. /**
  241. * virtio_device_ready - enable vq use in probe function
  242. * @dev: the virtio device
  243. *
  244. * Driver must call this to use vqs in the probe function.
  245. *
  246. * Note: vqs are enabled automatically after probe returns.
  247. */
  248. static inline
  249. void virtio_device_ready(struct virtio_device *dev)
  250. {
  251. unsigned status = dev->config->get_status(dev);
  252. WARN_ON(status & VIRTIO_CONFIG_S_DRIVER_OK);
  253. #ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION
  254. /*
  255. * The virtio_synchronize_cbs() makes sure vring_interrupt()
  256. * will see the driver specific setup if it sees vq->broken
  257. * as false (even if the notifications come before DRIVER_OK).
  258. */
  259. virtio_synchronize_cbs(dev);
  260. __virtio_unbreak_device(dev);
  261. #endif
  262. /*
  263. * The transport should ensure the visibility of vq->broken
  264. * before setting DRIVER_OK. See the comments for the transport
  265. * specific set_status() method.
  266. *
  267. * A well behaved device will only notify a virtqueue after
  268. * DRIVER_OK, this means the device should "see" the coherenct
  269. * memory write that set vq->broken as false which is done by
  270. * the driver when it sees DRIVER_OK, then the following
  271. * driver's vring_interrupt() will see vq->broken as false so
  272. * we won't lose any notification.
  273. */
  274. dev->config->set_status(dev, status | VIRTIO_CONFIG_S_DRIVER_OK);
  275. }
  276. static inline
  277. const char *virtio_bus_name(struct virtio_device *vdev)
  278. {
  279. if (!vdev->config->bus_name)
  280. return "virtio";
  281. return vdev->config->bus_name(vdev);
  282. }
  283. /**
  284. * virtqueue_set_affinity - setting affinity for a virtqueue
  285. * @vq: the virtqueue
  286. * @cpu_mask: the cpu mask
  287. *
  288. * Pay attention the function are best-effort: the affinity hint may not be set
  289. * due to config support, irq type and sharing.
  290. *
  291. */
  292. static inline
  293. int virtqueue_set_affinity(struct virtqueue *vq, const struct cpumask *cpu_mask)
  294. {
  295. struct virtio_device *vdev = vq->vdev;
  296. if (vdev->config->set_vq_affinity)
  297. return vdev->config->set_vq_affinity(vq, cpu_mask);
  298. return 0;
  299. }
  300. static inline
  301. bool virtio_get_shm_region(struct virtio_device *vdev,
  302. struct virtio_shm_region *region, u8 id)
  303. {
  304. if (!vdev->config->get_shm_region)
  305. return false;
  306. return vdev->config->get_shm_region(vdev, region, id);
  307. }
  308. static inline bool virtio_is_little_endian(struct virtio_device *vdev)
  309. {
  310. return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) ||
  311. virtio_legacy_is_little_endian();
  312. }
  313. /* Memory accessors */
  314. static inline u16 virtio16_to_cpu(struct virtio_device *vdev, __virtio16 val)
  315. {
  316. return __virtio16_to_cpu(virtio_is_little_endian(vdev), val);
  317. }
  318. static inline __virtio16 cpu_to_virtio16(struct virtio_device *vdev, u16 val)
  319. {
  320. return __cpu_to_virtio16(virtio_is_little_endian(vdev), val);
  321. }
  322. static inline u32 virtio32_to_cpu(struct virtio_device *vdev, __virtio32 val)
  323. {
  324. return __virtio32_to_cpu(virtio_is_little_endian(vdev), val);
  325. }
  326. static inline __virtio32 cpu_to_virtio32(struct virtio_device *vdev, u32 val)
  327. {
  328. return __cpu_to_virtio32(virtio_is_little_endian(vdev), val);
  329. }
  330. static inline u64 virtio64_to_cpu(struct virtio_device *vdev, __virtio64 val)
  331. {
  332. return __virtio64_to_cpu(virtio_is_little_endian(vdev), val);
  333. }
  334. static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
  335. {
  336. return __cpu_to_virtio64(virtio_is_little_endian(vdev), val);
  337. }
  338. #define virtio_to_cpu(vdev, x) \
  339. _Generic((x), \
  340. __u8: (x), \
  341. __virtio16: virtio16_to_cpu((vdev), (x)), \
  342. __virtio32: virtio32_to_cpu((vdev), (x)), \
  343. __virtio64: virtio64_to_cpu((vdev), (x)) \
  344. )
  345. #define cpu_to_virtio(vdev, x, m) \
  346. _Generic((m), \
  347. __u8: (x), \
  348. __virtio16: cpu_to_virtio16((vdev), (x)), \
  349. __virtio32: cpu_to_virtio32((vdev), (x)), \
  350. __virtio64: cpu_to_virtio64((vdev), (x)) \
  351. )
  352. #define __virtio_native_type(structname, member) \
  353. typeof(virtio_to_cpu(NULL, ((structname*)0)->member))
  354. /* Config space accessors. */
  355. #define virtio_cread(vdev, structname, member, ptr) \
  356. do { \
  357. typeof(((structname*)0)->member) virtio_cread_v; \
  358. \
  359. might_sleep(); \
  360. /* Sanity check: must match the member's type */ \
  361. typecheck(typeof(virtio_to_cpu((vdev), virtio_cread_v)), *(ptr)); \
  362. \
  363. switch (sizeof(virtio_cread_v)) { \
  364. case 1: \
  365. case 2: \
  366. case 4: \
  367. vdev->config->get((vdev), \
  368. offsetof(structname, member), \
  369. &virtio_cread_v, \
  370. sizeof(virtio_cread_v)); \
  371. break; \
  372. default: \
  373. __virtio_cread_many((vdev), \
  374. offsetof(structname, member), \
  375. &virtio_cread_v, \
  376. 1, \
  377. sizeof(virtio_cread_v)); \
  378. break; \
  379. } \
  380. *(ptr) = virtio_to_cpu(vdev, virtio_cread_v); \
  381. } while(0)
  382. /* Config space accessors. */
  383. #define virtio_cwrite(vdev, structname, member, ptr) \
  384. do { \
  385. typeof(((structname*)0)->member) virtio_cwrite_v = \
  386. cpu_to_virtio(vdev, *(ptr), ((structname*)0)->member); \
  387. \
  388. might_sleep(); \
  389. /* Sanity check: must match the member's type */ \
  390. typecheck(typeof(virtio_to_cpu((vdev), virtio_cwrite_v)), *(ptr)); \
  391. \
  392. vdev->config->set((vdev), offsetof(structname, member), \
  393. &virtio_cwrite_v, \
  394. sizeof(virtio_cwrite_v)); \
  395. } while(0)
  396. /*
  397. * Nothing virtio-specific about these, but let's worry about generalizing
  398. * these later.
  399. */
  400. #define virtio_le_to_cpu(x) \
  401. _Generic((x), \
  402. __u8: (u8)(x), \
  403. __le16: (u16)le16_to_cpu(x), \
  404. __le32: (u32)le32_to_cpu(x), \
  405. __le64: (u64)le64_to_cpu(x) \
  406. )
  407. #define virtio_cpu_to_le(x, m) \
  408. _Generic((m), \
  409. __u8: (x), \
  410. __le16: cpu_to_le16(x), \
  411. __le32: cpu_to_le32(x), \
  412. __le64: cpu_to_le64(x) \
  413. )
  414. /* LE (e.g. modern) Config space accessors. */
  415. #define virtio_cread_le(vdev, structname, member, ptr) \
  416. do { \
  417. typeof(((structname*)0)->member) virtio_cread_v; \
  418. \
  419. might_sleep(); \
  420. /* Sanity check: must match the member's type */ \
  421. typecheck(typeof(virtio_le_to_cpu(virtio_cread_v)), *(ptr)); \
  422. \
  423. switch (sizeof(virtio_cread_v)) { \
  424. case 1: \
  425. case 2: \
  426. case 4: \
  427. vdev->config->get((vdev), \
  428. offsetof(structname, member), \
  429. &virtio_cread_v, \
  430. sizeof(virtio_cread_v)); \
  431. break; \
  432. default: \
  433. __virtio_cread_many((vdev), \
  434. offsetof(structname, member), \
  435. &virtio_cread_v, \
  436. 1, \
  437. sizeof(virtio_cread_v)); \
  438. break; \
  439. } \
  440. *(ptr) = virtio_le_to_cpu(virtio_cread_v); \
  441. } while(0)
  442. #define virtio_cwrite_le(vdev, structname, member, ptr) \
  443. do { \
  444. typeof(((structname*)0)->member) virtio_cwrite_v = \
  445. virtio_cpu_to_le(*(ptr), ((structname*)0)->member); \
  446. \
  447. might_sleep(); \
  448. /* Sanity check: must match the member's type */ \
  449. typecheck(typeof(virtio_le_to_cpu(virtio_cwrite_v)), *(ptr)); \
  450. \
  451. vdev->config->set((vdev), offsetof(structname, member), \
  452. &virtio_cwrite_v, \
  453. sizeof(virtio_cwrite_v)); \
  454. } while(0)
  455. /* Read @count fields, @bytes each. */
  456. static inline void __virtio_cread_many(struct virtio_device *vdev,
  457. unsigned int offset,
  458. void *buf, size_t count, size_t bytes)
  459. {
  460. u32 old, gen = vdev->config->generation ?
  461. vdev->config->generation(vdev) : 0;
  462. int i;
  463. might_sleep();
  464. do {
  465. old = gen;
  466. for (i = 0; i < count; i++)
  467. vdev->config->get(vdev, offset + bytes * i,
  468. buf + i * bytes, bytes);
  469. gen = vdev->config->generation ?
  470. vdev->config->generation(vdev) : 0;
  471. } while (gen != old);
  472. }
  473. static inline void virtio_cread_bytes(struct virtio_device *vdev,
  474. unsigned int offset,
  475. void *buf, size_t len)
  476. {
  477. __virtio_cread_many(vdev, offset, buf, len, 1);
  478. }
  479. static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
  480. {
  481. u8 ret;
  482. might_sleep();
  483. vdev->config->get(vdev, offset, &ret, sizeof(ret));
  484. return ret;
  485. }
  486. static inline void virtio_cwrite8(struct virtio_device *vdev,
  487. unsigned int offset, u8 val)
  488. {
  489. might_sleep();
  490. vdev->config->set(vdev, offset, &val, sizeof(val));
  491. }
  492. static inline u16 virtio_cread16(struct virtio_device *vdev,
  493. unsigned int offset)
  494. {
  495. __virtio16 ret;
  496. might_sleep();
  497. vdev->config->get(vdev, offset, &ret, sizeof(ret));
  498. return virtio16_to_cpu(vdev, ret);
  499. }
  500. static inline void virtio_cwrite16(struct virtio_device *vdev,
  501. unsigned int offset, u16 val)
  502. {
  503. __virtio16 v;
  504. might_sleep();
  505. v = cpu_to_virtio16(vdev, val);
  506. vdev->config->set(vdev, offset, &v, sizeof(v));
  507. }
  508. static inline u32 virtio_cread32(struct virtio_device *vdev,
  509. unsigned int offset)
  510. {
  511. __virtio32 ret;
  512. might_sleep();
  513. vdev->config->get(vdev, offset, &ret, sizeof(ret));
  514. return virtio32_to_cpu(vdev, ret);
  515. }
  516. static inline void virtio_cwrite32(struct virtio_device *vdev,
  517. unsigned int offset, u32 val)
  518. {
  519. __virtio32 v;
  520. might_sleep();
  521. v = cpu_to_virtio32(vdev, val);
  522. vdev->config->set(vdev, offset, &v, sizeof(v));
  523. }
  524. static inline u64 virtio_cread64(struct virtio_device *vdev,
  525. unsigned int offset)
  526. {
  527. __virtio64 ret;
  528. __virtio_cread_many(vdev, offset, &ret, 1, sizeof(ret));
  529. return virtio64_to_cpu(vdev, ret);
  530. }
  531. static inline void virtio_cwrite64(struct virtio_device *vdev,
  532. unsigned int offset, u64 val)
  533. {
  534. __virtio64 v;
  535. might_sleep();
  536. v = cpu_to_virtio64(vdev, val);
  537. vdev->config->set(vdev, offset, &v, sizeof(v));
  538. }
  539. /* Conditional config space accessors. */
  540. #define virtio_cread_feature(vdev, fbit, structname, member, ptr) \
  541. ({ \
  542. int _r = 0; \
  543. if (!virtio_has_feature(vdev, fbit)) \
  544. _r = -ENOENT; \
  545. else \
  546. virtio_cread((vdev), structname, member, ptr); \
  547. _r; \
  548. })
  549. /* Conditional config space accessors. */
  550. #define virtio_cread_le_feature(vdev, fbit, structname, member, ptr) \
  551. ({ \
  552. int _r = 0; \
  553. if (!virtio_has_feature(vdev, fbit)) \
  554. _r = -ENOENT; \
  555. else \
  556. virtio_cread_le((vdev), structname, member, ptr); \
  557. _r; \
  558. })
  559. #endif /* _LINUX_VIRTIO_CONFIG_H */