nvme.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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/kref.h>
  19. #include <linux/blk-mq.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 nssr; /* Subsystem Reset */
  29. __u32 aqa; /* Admin Queue Attributes */
  30. __u64 asq; /* Admin SQ Base Address */
  31. __u64 acq; /* Admin CQ Base Address */
  32. __u32 cmbloc; /* Controller Memory Buffer Location */
  33. __u32 cmbsz; /* Controller Memory Buffer Size */
  34. };
  35. #define NVME_CAP_MQES(cap) ((cap) & 0xffff)
  36. #define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
  37. #define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
  38. #define NVME_CAP_NSSRC(cap) (((cap) >> 36) & 0x1)
  39. #define NVME_CAP_MPSMIN(cap) (((cap) >> 48) & 0xf)
  40. #define NVME_CAP_MPSMAX(cap) (((cap) >> 52) & 0xf)
  41. #define NVME_CMB_BIR(cmbloc) ((cmbloc) & 0x7)
  42. #define NVME_CMB_OFST(cmbloc) (((cmbloc) >> 12) & 0xfffff)
  43. #define NVME_CMB_SZ(cmbsz) (((cmbsz) >> 12) & 0xfffff)
  44. #define NVME_CMB_SZU(cmbsz) (((cmbsz) >> 8) & 0xf)
  45. #define NVME_CMB_WDS(cmbsz) ((cmbsz) & 0x10)
  46. #define NVME_CMB_RDS(cmbsz) ((cmbsz) & 0x8)
  47. #define NVME_CMB_LISTS(cmbsz) ((cmbsz) & 0x4)
  48. #define NVME_CMB_CQS(cmbsz) ((cmbsz) & 0x2)
  49. #define NVME_CMB_SQS(cmbsz) ((cmbsz) & 0x1)
  50. enum {
  51. NVME_CC_ENABLE = 1 << 0,
  52. NVME_CC_CSS_NVM = 0 << 4,
  53. NVME_CC_MPS_SHIFT = 7,
  54. NVME_CC_ARB_RR = 0 << 11,
  55. NVME_CC_ARB_WRRU = 1 << 11,
  56. NVME_CC_ARB_VS = 7 << 11,
  57. NVME_CC_SHN_NONE = 0 << 14,
  58. NVME_CC_SHN_NORMAL = 1 << 14,
  59. NVME_CC_SHN_ABRUPT = 2 << 14,
  60. NVME_CC_SHN_MASK = 3 << 14,
  61. NVME_CC_IOSQES = 6 << 16,
  62. NVME_CC_IOCQES = 4 << 20,
  63. NVME_CSTS_RDY = 1 << 0,
  64. NVME_CSTS_CFS = 1 << 1,
  65. NVME_CSTS_NSSRO = 1 << 4,
  66. NVME_CSTS_SHST_NORMAL = 0 << 2,
  67. NVME_CSTS_SHST_OCCUR = 1 << 2,
  68. NVME_CSTS_SHST_CMPLT = 2 << 2,
  69. NVME_CSTS_SHST_MASK = 3 << 2,
  70. };
  71. extern unsigned char nvme_io_timeout;
  72. #define NVME_IO_TIMEOUT (nvme_io_timeout * HZ)
  73. /*
  74. * Represents an NVM Express device. Each nvme_dev is a PCI function.
  75. */
  76. struct nvme_dev {
  77. struct list_head node;
  78. struct nvme_queue **queues;
  79. struct request_queue *admin_q;
  80. struct blk_mq_tag_set tagset;
  81. struct blk_mq_tag_set admin_tagset;
  82. u32 __iomem *dbs;
  83. struct device *dev;
  84. struct dma_pool *prp_page_pool;
  85. struct dma_pool *prp_small_pool;
  86. int instance;
  87. unsigned queue_count;
  88. unsigned online_queues;
  89. unsigned max_qid;
  90. int q_depth;
  91. u32 db_stride;
  92. u32 ctrl_config;
  93. struct msix_entry *entry;
  94. struct nvme_bar __iomem *bar;
  95. struct list_head namespaces;
  96. struct kref kref;
  97. struct device *device;
  98. work_func_t reset_workfn;
  99. struct work_struct reset_work;
  100. struct work_struct probe_work;
  101. struct work_struct scan_work;
  102. char name[12];
  103. char serial[20];
  104. char model[40];
  105. char firmware_rev[8];
  106. bool subsystem;
  107. u32 max_hw_sectors;
  108. u32 stripe_size;
  109. u32 page_size;
  110. void __iomem *cmb;
  111. dma_addr_t cmb_dma_addr;
  112. u64 cmb_size;
  113. u32 cmbsz;
  114. u16 oncs;
  115. u16 abort_limit;
  116. u8 event_limit;
  117. u8 vwc;
  118. };
  119. /*
  120. * An NVM Express namespace is equivalent to a SCSI LUN
  121. */
  122. struct nvme_ns {
  123. struct list_head list;
  124. struct nvme_dev *dev;
  125. struct request_queue *queue;
  126. struct gendisk *disk;
  127. unsigned ns_id;
  128. int lba_shift;
  129. u16 ms;
  130. bool ext;
  131. u8 pi_type;
  132. u64 mode_select_num_blocks;
  133. u32 mode_select_block_len;
  134. };
  135. /*
  136. * The nvme_iod describes the data in an I/O, including the list of PRP
  137. * entries. You can't see it in this data structure because C doesn't let
  138. * me express that. Use nvme_alloc_iod to ensure there's enough space
  139. * allocated to store the PRP list.
  140. */
  141. struct nvme_iod {
  142. unsigned long private; /* For the use of the submitter of the I/O */
  143. int npages; /* In the PRP list. 0 means small pool in use */
  144. int offset; /* Of PRP list */
  145. int nents; /* Used in scatterlist */
  146. int length; /* Of data, in bytes */
  147. dma_addr_t first_dma;
  148. struct scatterlist meta_sg[1]; /* metadata requires single contiguous buffer */
  149. struct scatterlist sg[0];
  150. };
  151. static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector)
  152. {
  153. return (sector >> (ns->lba_shift - 9));
  154. }
  155. int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
  156. void *buf, unsigned bufflen);
  157. int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
  158. void *buffer, void __user *ubuffer, unsigned bufflen,
  159. u32 *result, unsigned timeout);
  160. int nvme_identify_ctrl(struct nvme_dev *dev, struct nvme_id_ctrl **id);
  161. int nvme_identify_ns(struct nvme_dev *dev, unsigned nsid,
  162. struct nvme_id_ns **id);
  163. int nvme_get_log_page(struct nvme_dev *dev, struct nvme_smart_log **log);
  164. int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid,
  165. dma_addr_t dma_addr, u32 *result);
  166. int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
  167. dma_addr_t dma_addr, u32 *result);
  168. struct sg_io_hdr;
  169. int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr);
  170. int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg);
  171. int nvme_sg_get_version_num(int __user *ip);
  172. #endif /* _LINUX_NVME_H */