nvme.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Definitions for the NVM Express interface
  3. * Copyright (c) 2011-2014, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _LINUX_NVME_H
  15. #define _LINUX_NVME_H
  16. #include <uapi/linux/nvme.h>
  17. #include <linux/pci.h>
  18. #include <linux/miscdevice.h>
  19. #include <linux/kref.h>
  20. struct nvme_bar {
  21. __u64 cap; /* Controller Capabilities */
  22. __u32 vs; /* Version */
  23. __u32 intms; /* Interrupt Mask Set */
  24. __u32 intmc; /* Interrupt Mask Clear */
  25. __u32 cc; /* Controller Configuration */
  26. __u32 rsvd1; /* Reserved */
  27. __u32 csts; /* Controller Status */
  28. __u32 rsvd2; /* Reserved */
  29. __u32 aqa; /* Admin Queue Attributes */
  30. __u64 asq; /* Admin SQ Base Address */
  31. __u64 acq; /* Admin CQ Base Address */
  32. };
  33. #define NVME_CAP_MQES(cap) ((cap) & 0xffff)
  34. #define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
  35. #define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
  36. #define NVME_CAP_MPSMIN(cap) (((cap) >> 48) & 0xf)
  37. enum {
  38. NVME_CC_ENABLE = 1 << 0,
  39. NVME_CC_CSS_NVM = 0 << 4,
  40. NVME_CC_MPS_SHIFT = 7,
  41. NVME_CC_ARB_RR = 0 << 11,
  42. NVME_CC_ARB_WRRU = 1 << 11,
  43. NVME_CC_ARB_VS = 7 << 11,
  44. NVME_CC_SHN_NONE = 0 << 14,
  45. NVME_CC_SHN_NORMAL = 1 << 14,
  46. NVME_CC_SHN_ABRUPT = 2 << 14,
  47. NVME_CC_SHN_MASK = 3 << 14,
  48. NVME_CC_IOSQES = 6 << 16,
  49. NVME_CC_IOCQES = 4 << 20,
  50. NVME_CSTS_RDY = 1 << 0,
  51. NVME_CSTS_CFS = 1 << 1,
  52. NVME_CSTS_SHST_NORMAL = 0 << 2,
  53. NVME_CSTS_SHST_OCCUR = 1 << 2,
  54. NVME_CSTS_SHST_CMPLT = 2 << 2,
  55. NVME_CSTS_SHST_MASK = 3 << 2,
  56. };
  57. #define NVME_VS(major, minor) (major << 16 | minor)
  58. extern unsigned char nvme_io_timeout;
  59. #define NVME_IO_TIMEOUT (nvme_io_timeout * HZ)
  60. /*
  61. * Represents an NVM Express device. Each nvme_dev is a PCI function.
  62. */
  63. struct nvme_dev {
  64. struct list_head node;
  65. struct nvme_queue __rcu **queues;
  66. unsigned short __percpu *io_queue;
  67. u32 __iomem *dbs;
  68. struct pci_dev *pci_dev;
  69. struct dma_pool *prp_page_pool;
  70. struct dma_pool *prp_small_pool;
  71. int instance;
  72. unsigned queue_count;
  73. unsigned online_queues;
  74. unsigned max_qid;
  75. int q_depth;
  76. u32 db_stride;
  77. u32 ctrl_config;
  78. struct msix_entry *entry;
  79. struct nvme_bar __iomem *bar;
  80. struct list_head namespaces;
  81. struct kref kref;
  82. struct miscdevice miscdev;
  83. work_func_t reset_workfn;
  84. struct work_struct reset_work;
  85. struct work_struct cpu_work;
  86. char name[12];
  87. char serial[20];
  88. char model[40];
  89. char firmware_rev[8];
  90. u32 max_hw_sectors;
  91. u32 stripe_size;
  92. u16 oncs;
  93. u16 abort_limit;
  94. u8 vwc;
  95. u8 initialized;
  96. };
  97. /*
  98. * An NVM Express namespace is equivalent to a SCSI LUN
  99. */
  100. struct nvme_ns {
  101. struct list_head list;
  102. struct nvme_dev *dev;
  103. struct request_queue *queue;
  104. struct gendisk *disk;
  105. unsigned ns_id;
  106. int lba_shift;
  107. int ms;
  108. u64 mode_select_num_blocks;
  109. u32 mode_select_block_len;
  110. };
  111. /*
  112. * The nvme_iod describes the data in an I/O, including the list of PRP
  113. * entries. You can't see it in this data structure because C doesn't let
  114. * me express that. Use nvme_alloc_iod to ensure there's enough space
  115. * allocated to store the PRP list.
  116. */
  117. struct nvme_iod {
  118. void *private; /* For the use of the submitter of the I/O */
  119. int npages; /* In the PRP list. 0 means small pool in use */
  120. int offset; /* Of PRP list */
  121. int nents; /* Used in scatterlist */
  122. int length; /* Of data, in bytes */
  123. unsigned long start_time;
  124. dma_addr_t first_dma;
  125. struct list_head node;
  126. struct scatterlist sg[0];
  127. };
  128. static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector)
  129. {
  130. return (sector >> (ns->lba_shift - 9));
  131. }
  132. /**
  133. * nvme_free_iod - frees an nvme_iod
  134. * @dev: The device that the I/O was submitted to
  135. * @iod: The memory to free
  136. */
  137. void nvme_free_iod(struct nvme_dev *dev, struct nvme_iod *iod);
  138. int nvme_setup_prps(struct nvme_dev *, struct nvme_iod *, int , gfp_t);
  139. struct nvme_iod *nvme_map_user_pages(struct nvme_dev *dev, int write,
  140. unsigned long addr, unsigned length);
  141. void nvme_unmap_user_pages(struct nvme_dev *dev, int write,
  142. struct nvme_iod *iod);
  143. int nvme_submit_io_cmd(struct nvme_dev *, struct nvme_command *, u32 *);
  144. int nvme_submit_admin_cmd(struct nvme_dev *, struct nvme_command *,
  145. u32 *result);
  146. int nvme_identify(struct nvme_dev *, unsigned nsid, unsigned cns,
  147. dma_addr_t dma_addr);
  148. int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid,
  149. dma_addr_t dma_addr, u32 *result);
  150. int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
  151. dma_addr_t dma_addr, u32 *result);
  152. struct sg_io_hdr;
  153. int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr);
  154. int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg);
  155. int nvme_sg_get_version_num(int __user *ip);
  156. #endif /* _LINUX_NVME_H */