virtio_blk.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
  18. struct virtio_blk_config {
  19. /* The capacity (in 512-byte sectors). */
  20. __u64 capacity;
  21. /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
  22. __u32 size_max;
  23. /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
  24. __u32 seg_max;
  25. /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
  26. struct virtio_blk_geometry {
  27. __u16 cylinders;
  28. __u8 heads;
  29. __u8 sectors;
  30. } geometry;
  31. /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
  32. __u32 blk_size;
  33. /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */
  34. /* exponent for physical block per logical block. */
  35. __u8 physical_block_exp;
  36. /* alignment offset in logical blocks. */
  37. __u8 alignment_offset;
  38. /* minimum I/O size without performance penalty in logical blocks. */
  39. __u16 min_io_size;
  40. /* optimal sustained I/O size in logical blocks. */
  41. __u32 opt_io_size;
  42. } __attribute__((packed));
  43. /*
  44. * Command types
  45. *
  46. * Usage is a bit tricky as some bits are used as flags and some are not.
  47. *
  48. * Rules:
  49. * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or
  50. * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own
  51. * and may not be combined with any of the other flags.
  52. */
  53. /* These two define direction. */
  54. #define VIRTIO_BLK_T_IN 0
  55. #define VIRTIO_BLK_T_OUT 1
  56. /* This bit says it's a scsi command, not an actual read or write. */
  57. #define VIRTIO_BLK_T_SCSI_CMD 2
  58. /* Cache flush command */
  59. #define VIRTIO_BLK_T_FLUSH 4
  60. /* Barrier before this op. */
  61. #define VIRTIO_BLK_T_BARRIER 0x80000000
  62. /* This is the first element of the read scatter-gather list. */
  63. struct virtio_blk_outhdr {
  64. /* VIRTIO_BLK_T* */
  65. __u32 type;
  66. /* io priority. */
  67. __u32 ioprio;
  68. /* Sector (ie. 512 byte offset) */
  69. __u64 sector;
  70. };
  71. struct virtio_scsi_inhdr {
  72. __u32 errors;
  73. __u32 data_len;
  74. __u32 sense_len;
  75. __u32 residual;
  76. };
  77. /* And this is the final byte of the write scatter-gather list. */
  78. #define VIRTIO_BLK_S_OK 0
  79. #define VIRTIO_BLK_S_IOERR 1
  80. #define VIRTIO_BLK_S_UNSUPP 2
  81. #endif /* _LINUX_VIRTIO_BLK_H */