virtio_blk.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. {
  21. /* The capacity (in 512-byte sectors). */
  22. __u64 capacity;
  23. /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
  24. __u32 size_max;
  25. /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
  26. __u32 seg_max;
  27. /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
  28. struct virtio_blk_geometry {
  29. __u16 cylinders;
  30. __u8 heads;
  31. __u8 sectors;
  32. } geometry;
  33. /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
  34. __u32 blk_size;
  35. __u8 identify[VIRTIO_BLK_ID_BYTES];
  36. } __attribute__((packed));
  37. /* These two define direction. */
  38. #define VIRTIO_BLK_T_IN 0
  39. #define VIRTIO_BLK_T_OUT 1
  40. /* This bit says it's a scsi command, not an actual read or write. */
  41. #define VIRTIO_BLK_T_SCSI_CMD 2
  42. /* Barrier before this op. */
  43. #define VIRTIO_BLK_T_BARRIER 0x80000000
  44. /* This is the first element of the read scatter-gather list. */
  45. struct virtio_blk_outhdr
  46. {
  47. /* VIRTIO_BLK_T* */
  48. __u32 type;
  49. /* io priority. */
  50. __u32 ioprio;
  51. /* Sector (ie. 512 byte offset) */
  52. __u64 sector;
  53. };
  54. struct virtio_scsi_inhdr {
  55. __u32 errors;
  56. __u32 data_len;
  57. __u32 sense_len;
  58. __u32 residual;
  59. };
  60. /* And this is the final byte of the write scatter-gather list. */
  61. #define VIRTIO_BLK_S_OK 0
  62. #define VIRTIO_BLK_S_IOERR 1
  63. #define VIRTIO_BLK_S_UNSUPP 2
  64. #endif /* _LINUX_VIRTIO_BLK_H */