nvme.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (c) 2011-2014, Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. */
  13. #ifndef _NVME_H
  14. #define _NVME_H
  15. #include <linux/mutex.h>
  16. #include <linux/nvme.h>
  17. #include <linux/pci.h>
  18. #include <linux/kref.h>
  19. #include <linux/blk-mq.h>
  20. extern unsigned char nvme_io_timeout;
  21. #define NVME_IO_TIMEOUT (nvme_io_timeout * HZ)
  22. enum {
  23. NVME_NS_LBA = 0,
  24. NVME_NS_LIGHTNVM = 1,
  25. };
  26. /* The below value is the specific amount of delay needed before checking
  27. * readiness in case of the PCI_DEVICE(0x1c58, 0x0003), which needs the
  28. * NVME_QUIRK_DELAY_BEFORE_CHK_RDY quirk enabled. The value (in ms) was
  29. * found empirically.
  30. */
  31. #define NVME_QUIRK_DELAY_AMOUNT 2000
  32. /*
  33. * Represents an NVM Express device. Each nvme_dev is a PCI function.
  34. */
  35. struct nvme_dev {
  36. struct list_head node;
  37. struct nvme_queue **queues;
  38. struct request_queue *admin_q;
  39. struct blk_mq_tag_set tagset;
  40. struct blk_mq_tag_set admin_tagset;
  41. u32 __iomem *dbs;
  42. struct device *dev;
  43. struct dma_pool *prp_page_pool;
  44. struct dma_pool *prp_small_pool;
  45. int instance;
  46. unsigned queue_count;
  47. unsigned online_queues;
  48. unsigned max_qid;
  49. int q_depth;
  50. u32 db_stride;
  51. u32 ctrl_config;
  52. struct msix_entry *entry;
  53. struct nvme_bar __iomem *bar;
  54. struct list_head namespaces;
  55. struct kref kref;
  56. struct device *device;
  57. struct work_struct reset_work;
  58. struct work_struct probe_work;
  59. struct work_struct scan_work;
  60. struct mutex shutdown_lock;
  61. char name[12];
  62. char serial[20];
  63. char model[40];
  64. char firmware_rev[8];
  65. bool subsystem;
  66. u32 max_hw_sectors;
  67. u32 stripe_size;
  68. u32 page_size;
  69. void __iomem *cmb;
  70. dma_addr_t cmb_dma_addr;
  71. u64 cmb_size;
  72. u32 cmbsz;
  73. u16 oncs;
  74. u16 abort_limit;
  75. u8 event_limit;
  76. u8 vwc;
  77. };
  78. /*
  79. * An NVM Express namespace is equivalent to a SCSI LUN
  80. */
  81. struct nvme_ns {
  82. struct list_head list;
  83. struct nvme_dev *dev;
  84. struct request_queue *queue;
  85. struct gendisk *disk;
  86. struct kref kref;
  87. unsigned ns_id;
  88. int lba_shift;
  89. u16 ms;
  90. bool ext;
  91. u8 pi_type;
  92. int type;
  93. u64 mode_select_num_blocks;
  94. u32 mode_select_block_len;
  95. };
  96. /*
  97. * The nvme_iod describes the data in an I/O, including the list of PRP
  98. * entries. You can't see it in this data structure because C doesn't let
  99. * me express that. Use nvme_alloc_iod to ensure there's enough space
  100. * allocated to store the PRP list.
  101. */
  102. struct nvme_iod {
  103. unsigned long private; /* For the use of the submitter of the I/O */
  104. int npages; /* In the PRP list. 0 means small pool in use */
  105. int offset; /* Of PRP list */
  106. int nents; /* Used in scatterlist */
  107. int length; /* Of data, in bytes */
  108. dma_addr_t first_dma;
  109. struct scatterlist meta_sg[1]; /* metadata requires single contiguous buffer */
  110. struct scatterlist sg[0];
  111. };
  112. static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector)
  113. {
  114. return (sector >> (ns->lba_shift - 9));
  115. }
  116. int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
  117. void *buf, unsigned bufflen);
  118. int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
  119. void *buffer, void __user *ubuffer, unsigned bufflen,
  120. u32 *result, unsigned timeout);
  121. int nvme_identify_ctrl(struct nvme_dev *dev, struct nvme_id_ctrl **id);
  122. int nvme_identify_ns(struct nvme_dev *dev, unsigned nsid,
  123. struct nvme_id_ns **id);
  124. int nvme_get_log_page(struct nvme_dev *dev, struct nvme_smart_log **log);
  125. int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid,
  126. dma_addr_t dma_addr, u32 *result);
  127. int nvme_set_features(struct nvme_dev *dev, unsigned fid, unsigned dword11,
  128. dma_addr_t dma_addr, u32 *result);
  129. struct sg_io_hdr;
  130. int nvme_sg_io(struct nvme_ns *ns, struct sg_io_hdr __user *u_hdr);
  131. int nvme_sg_io32(struct nvme_ns *ns, unsigned long arg);
  132. int nvme_sg_get_version_num(int __user *ip);
  133. #ifdef CONFIG_NVM
  134. int nvme_nvm_ns_supported(struct nvme_ns *ns, struct nvme_id_ns *id);
  135. int nvme_nvm_register(struct request_queue *q, char *disk_name);
  136. void nvme_nvm_unregister(struct request_queue *q, char *disk_name);
  137. #else
  138. static inline int nvme_nvm_register(struct request_queue *q, char *disk_name)
  139. {
  140. return 0;
  141. }
  142. static inline void nvme_nvm_unregister(struct request_queue *q, char *disk_name) {};
  143. static inline int nvme_nvm_ns_supported(struct nvme_ns *ns, struct nvme_id_ns *id)
  144. {
  145. return 0;
  146. }
  147. #endif /* CONFIG_NVM */
  148. #endif /* _NVME_H */