virtio_blk.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef _LINUX_VIRTIO_BLK_H
  2. #define _LINUX_VIRTIO_BLK_H
  3. /* This header is BSD licensed so anyone can use the definitions to implement
  4. * compatible drivers/servers. */
  5. #include <linux/types.h>
  6. #include <linux/virtio_ids.h>
  7. #include <linux/virtio_config.h>
  8. /* Feature bits */
  9. #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
  10. #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
  11. #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
  12. #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
  13. #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
  14. #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
  15. #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
  16. #define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */
  17. struct virtio_blk_config {
  18. /* The capacity (in 512-byte sectors). */
  19. __u64 capacity;
  20. /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
  21. __u32 size_max;
  22. /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
  23. __u32 seg_max;
  24. /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
  25. struct virtio_blk_geometry {
  26. __u16 cylinders;
  27. __u8 heads;
  28. __u8 sectors;
  29. } geometry;
  30. /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
  31. __u32 blk_size;
  32. } __attribute__((packed));
  33. /*
  34. * Command types
  35. *
  36. * Usage is a bit tricky as some bits are used as flags and some are not.
  37. *
  38. * Rules:
  39. * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or
  40. * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own
  41. * and may not be combined with any of the other flags.
  42. */
  43. /* These two define direction. */
  44. #define VIRTIO_BLK_T_IN 0
  45. #define VIRTIO_BLK_T_OUT 1
  46. /* This bit says it's a scsi command, not an actual read or write. */
  47. #define VIRTIO_BLK_T_SCSI_CMD 2
  48. /* Cache flush command */
  49. #define VIRTIO_BLK_T_FLUSH 4
  50. /* Barrier before this op. */
  51. #define VIRTIO_BLK_T_BARRIER 0x80000000
  52. /* This is the first element of the read scatter-gather list. */
  53. struct virtio_blk_outhdr {
  54. /* VIRTIO_BLK_T* */
  55. __u32 type;
  56. /* io priority. */
  57. __u32 ioprio;
  58. /* Sector (ie. 512 byte offset) */
  59. __u64 sector;
  60. };
  61. struct virtio_scsi_inhdr {
  62. __u32 errors;
  63. __u32 data_len;
  64. __u32 sense_len;
  65. __u32 residual;
  66. };
  67. /* And this is the final byte of the write scatter-gather list. */
  68. #define VIRTIO_BLK_S_OK 0
  69. #define VIRTIO_BLK_S_IOERR 1
  70. #define VIRTIO_BLK_S_UNSUPP 2
  71. #endif /* _LINUX_VIRTIO_BLK_H */