nvme.h 5.2 KB

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