8628 nvme: use a semaphore to guard submission queue
[unleashed.git] / usr / src / uts / common / io / nvme / nvme_var.h
blob93f0cae064e01d20ab58bd6a1c20dc0936db30a5
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
14 * Copyright 2016 The MathWorks, Inc. All rights reserved.
15 * Copyright 2017 Joyent, Inc.
18 #ifndef _NVME_VAR_H
19 #define _NVME_VAR_H
21 #include <sys/ddi.h>
22 #include <sys/sunddi.h>
23 #include <sys/blkdev.h>
24 #include <sys/taskq_impl.h>
27 * NVMe driver state
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
34 #define NVME_FMA_INIT 0x1
35 #define NVME_REGS_MAPPED 0x2
36 #define NVME_ADMIN_QUEUE 0x4
37 #define NVME_CTRL_LIMITS 0x8
38 #define NVME_INTERRUPTS 0x10
40 #define NVME_MIN_ADMIN_QUEUE_LEN 16
41 #define NVME_MIN_IO_QUEUE_LEN 16
42 #define NVME_DEFAULT_ADMIN_QUEUE_LEN 256
43 #define NVME_DEFAULT_IO_QUEUE_LEN 1024
44 #define NVME_DEFAULT_ASYNC_EVENT_LIMIT 10
45 #define NVME_MIN_ASYNC_EVENT_LIMIT 1
46 #define NVME_DEFAULT_MIN_BLOCK_SIZE 512
49 typedef struct nvme nvme_t;
50 typedef struct nvme_namespace nvme_namespace_t;
51 typedef struct nvme_minor_state nvme_minor_state_t;
52 typedef struct nvme_dma nvme_dma_t;
53 typedef struct nvme_cmd nvme_cmd_t;
54 typedef struct nvme_qpair nvme_qpair_t;
55 typedef struct nvme_task_arg nvme_task_arg_t;
57 struct nvme_minor_state {
58 kmutex_t nm_mutex;
59 boolean_t nm_oexcl;
60 uint_t nm_ocnt;
63 struct nvme_dma {
64 ddi_dma_handle_t nd_dmah;
65 ddi_acc_handle_t nd_acch;
66 ddi_dma_cookie_t nd_cookie;
67 uint_t nd_ncookie;
68 caddr_t nd_memp;
69 size_t nd_len;
70 boolean_t nd_cached;
73 struct nvme_cmd {
74 nvme_sqe_t nc_sqe;
75 nvme_cqe_t nc_cqe;
77 void (*nc_callback)(void *);
78 bd_xfer_t *nc_xfer;
79 boolean_t nc_completed;
80 boolean_t nc_dontpanic;
81 uint16_t nc_sqid;
83 nvme_dma_t *nc_dma;
85 kmutex_t nc_mutex;
86 kcondvar_t nc_cv;
88 taskq_ent_t nc_tqent;
89 nvme_t *nc_nvme;
92 struct nvme_qpair {
93 size_t nq_nentry;
95 nvme_dma_t *nq_sqdma;
96 nvme_sqe_t *nq_sq;
97 uint_t nq_sqhead;
98 uint_t nq_sqtail;
99 uintptr_t nq_sqtdbl;
101 nvme_dma_t *nq_cqdma;
102 nvme_cqe_t *nq_cq;
103 uint_t nq_cqhead;
104 uint_t nq_cqtail;
105 uintptr_t nq_cqhdbl;
107 nvme_cmd_t **nq_cmd;
108 uint16_t nq_next_cmd;
109 uint_t nq_active_cmds;
110 int nq_phase;
112 kmutex_t nq_mutex;
113 ksema_t nq_sema;
116 struct nvme {
117 dev_info_t *n_dip;
118 int n_progress;
120 caddr_t n_regs;
121 ddi_acc_handle_t n_regh;
123 kmem_cache_t *n_cmd_cache;
124 kmem_cache_t *n_prp_cache;
126 size_t n_inth_sz;
127 ddi_intr_handle_t *n_inth;
128 int n_intr_cnt;
129 uint_t n_intr_pri;
130 int n_intr_cap;
131 int n_intr_type;
132 int n_intr_types;
134 char *n_product;
135 char *n_vendor;
137 nvme_version_t n_version;
138 boolean_t n_dead;
139 boolean_t n_strict_version;
140 boolean_t n_ignore_unknown_vendor_status;
141 uint32_t n_admin_queue_len;
142 uint32_t n_io_queue_len;
143 uint16_t n_async_event_limit;
144 uint_t n_min_block_size;
145 uint16_t n_abort_command_limit;
146 uint64_t n_max_data_transfer_size;
147 boolean_t n_write_cache_present;
148 boolean_t n_write_cache_enabled;
149 int n_error_log_len;
150 boolean_t n_lba_range_supported;
151 boolean_t n_auto_pst_supported;
153 int n_nssr_supported;
154 int n_doorbell_stride;
155 int n_timeout;
156 int n_arbitration_mechanisms;
157 int n_cont_queues_reqd;
158 int n_max_queue_entries;
159 int n_pageshift;
160 int n_pagesize;
162 int n_namespace_count;
163 int n_ioq_count;
165 nvme_identify_ctrl_t *n_idctl;
167 nvme_qpair_t *n_adminq;
168 nvme_qpair_t **n_ioq;
170 nvme_namespace_t *n_ns;
172 ddi_dma_attr_t n_queue_dma_attr;
173 ddi_dma_attr_t n_prp_dma_attr;
174 ddi_dma_attr_t n_sgl_dma_attr;
175 ddi_device_acc_attr_t n_reg_acc_attr;
176 ddi_iblock_cookie_t n_fm_ibc;
177 int n_fm_cap;
179 ksema_t n_abort_sema;
181 ddi_taskq_t *n_cmd_taskq;
183 /* state for devctl minor node */
184 nvme_minor_state_t n_minor;
186 /* errors detected by driver */
187 uint32_t n_dma_bind_err;
188 uint32_t n_abort_failed;
189 uint32_t n_cmd_timeout;
190 uint32_t n_cmd_aborted;
191 uint32_t n_wrong_logpage;
192 uint32_t n_unknown_logpage;
193 uint32_t n_too_many_cookies;
195 /* errors detected by hardware */
196 uint32_t n_data_xfr_err;
197 uint32_t n_internal_err;
198 uint32_t n_abort_rq_err;
199 uint32_t n_abort_sq_del;
200 uint32_t n_nvm_cap_exc;
201 uint32_t n_nvm_ns_notrdy;
202 uint32_t n_inv_cq_err;
203 uint32_t n_inv_qid_err;
204 uint32_t n_max_qsz_exc;
205 uint32_t n_inv_int_vect;
206 uint32_t n_inv_log_page;
207 uint32_t n_inv_format;
208 uint32_t n_inv_q_del;
209 uint32_t n_cnfl_attr;
210 uint32_t n_inv_prot;
211 uint32_t n_readonly;
213 /* errors reported by asynchronous events */
214 uint32_t n_diagfail_event;
215 uint32_t n_persistent_event;
216 uint32_t n_transient_event;
217 uint32_t n_fw_load_event;
218 uint32_t n_reliability_event;
219 uint32_t n_temperature_event;
220 uint32_t n_spare_event;
221 uint32_t n_vendor_event;
222 uint32_t n_unknown_event;
226 struct nvme_namespace {
227 nvme_t *ns_nvme;
228 uint8_t ns_eui64[8];
229 char ns_name[17];
231 bd_handle_t ns_bd_hdl;
233 uint32_t ns_id;
234 size_t ns_block_count;
235 size_t ns_block_size;
236 size_t ns_best_block_size;
238 boolean_t ns_ignore;
240 nvme_identify_nsid_t *ns_idns;
242 /* state for attachment point minor node */
243 nvme_minor_state_t ns_minor;
246 * If a namespace has no EUI64, we create a devid in
247 * nvme_prepare_devid().
249 char *ns_devid;
252 struct nvme_task_arg {
253 nvme_t *nt_nvme;
254 nvme_cmd_t *nt_cmd;
258 #ifdef __cplusplus
260 #endif
262 #endif /* _NVME_VAR_H */