virtio_blk.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_config.h>
  7. /* The ID for virtio_block */
  8. #define VIRTIO_ID_BLOCK 2
  9. /* Feature bits */
  10. #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
  11. #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
  12. #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
  13. #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
  14. #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
  15. #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
  16. #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
  17. #define VIRTIO_BLK_F_IDENTIFY 8 /* ATA IDENTIFY supported */
  18. #define VIRTIO_BLK_ID_BYTES (sizeof(__u16[256])) /* IDENTIFY DATA */
  19. struct virtio_blk_config {
  20. /* The capacity (in 512-byte sectors). */
  21. __u64 capacity;
  22. /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
  23. __u32 size_max;
  24. /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
  25. __u32 seg_max;
  26. /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
  27. struct virtio_blk_geometry {
  28. __u16 cylinders;
  29. __u8 heads;
  30. __u8 sectors;
  31. } geometry;
  32. /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
  33. __u32 blk_size;
  34. __u8 identify[VIRTIO_BLK_ID_BYTES];
  35. } __attribute__((packed));
  36. /* These two define direction. */
  37. #define VIRTIO_BLK_T_IN 0
  38. #define VIRTIO_BLK_T_OUT 1
  39. /* This bit says it's a scsi command, not an actual read or write. */
  40. #define VIRTIO_BLK_T_SCSI_CMD 2
  41. /* Barrier before this op. */
  42. #define VIRTIO_BLK_T_BARRIER 0x80000000
  43. /* This is the first element of the read scatter-gather list. */
  44. struct virtio_blk_outhdr {
  45. /* VIRTIO_BLK_T* */
  46. __u32 type;
  47. /* io priority. */
  48. __u32 ioprio;
  49. /* Sector (ie. 512 byte offset) */
  50. __u64 sector;
  51. };
  52. struct virtio_scsi_inhdr {
  53. __u32 errors;
  54. __u32 data_len;
  55. __u32 sense_len;
  56. __u32 residual;
  57. };
  58. /* And this is the final byte of the write scatter-gather list. */
  59. #define VIRTIO_BLK_S_OK 0
  60. #define VIRTIO_BLK_S_IOERR 1
  61. #define VIRTIO_BLK_S_UNSUPP 2
  62. #endif /* _LINUX_VIRTIO_BLK_H */