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
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 2018 Nexenta Systems, Inc.
14 * Copyright 2016 The MathWorks, Inc. All rights reserved.
15 * Copyright 2017 Joyent, Inc.
22 #include <sys/sunddi.h>
23 #include <sys/blkdev.h>
24 #include <sys/taskq_impl.h>
35 #define NVME_FMA_INIT 0x1
36 #define NVME_REGS_MAPPED 0x2
37 #define NVME_ADMIN_QUEUE 0x4
38 #define NVME_CTRL_LIMITS 0x8
39 #define NVME_INTERRUPTS 0x10
41 #define NVME_MIN_ADMIN_QUEUE_LEN 16
42 #define NVME_MIN_IO_QUEUE_LEN 16
43 #define NVME_DEFAULT_ADMIN_QUEUE_LEN 256
44 #define NVME_DEFAULT_IO_QUEUE_LEN 1024
45 #define NVME_DEFAULT_ASYNC_EVENT_LIMIT 10
46 #define NVME_MIN_ASYNC_EVENT_LIMIT 1
47 #define NVME_DEFAULT_MIN_BLOCK_SIZE 512
50 typedef struct nvme nvme_t
;
51 typedef struct nvme_namespace nvme_namespace_t
;
52 typedef struct nvme_minor_state nvme_minor_state_t
;
53 typedef struct nvme_dma nvme_dma_t
;
54 typedef struct nvme_cmd nvme_cmd_t
;
55 typedef struct nvme_qpair nvme_qpair_t
;
56 typedef struct nvme_task_arg nvme_task_arg_t
;
58 struct nvme_minor_state
{
65 ddi_dma_handle_t nd_dmah
;
66 ddi_acc_handle_t nd_acch
;
67 ddi_dma_cookie_t nd_cookie
;
75 struct list_node nc_list
;
80 void (*nc_callback
)(void *);
82 boolean_t nc_completed
;
83 boolean_t nc_dontpanic
;
104 nvme_dma_t
*nq_cqdma
;
111 uint16_t nq_next_cmd
;
112 uint_t nq_active_cmds
;
124 ddi_acc_handle_t n_regh
;
126 kmem_cache_t
*n_cmd_cache
;
127 kmem_cache_t
*n_prp_cache
;
130 ddi_intr_handle_t
*n_inth
;
140 nvme_version_t n_version
;
142 boolean_t n_strict_version
;
143 boolean_t n_ignore_unknown_vendor_status
;
144 uint32_t n_admin_queue_len
;
145 uint32_t n_io_queue_len
;
146 uint16_t n_async_event_limit
;
147 uint_t n_min_block_size
;
148 uint16_t n_abort_command_limit
;
149 uint64_t n_max_data_transfer_size
;
150 boolean_t n_write_cache_present
;
151 boolean_t n_write_cache_enabled
;
153 boolean_t n_lba_range_supported
;
154 boolean_t n_auto_pst_supported
;
155 boolean_t n_async_event_supported
;
156 boolean_t n_progress_supported
;
158 int n_nssr_supported
;
159 int n_doorbell_stride
;
161 int n_arbitration_mechanisms
;
162 int n_cont_queues_reqd
;
163 int n_max_queue_entries
;
167 int n_namespace_count
;
168 uint16_t n_ioq_count
;
170 nvme_identify_ctrl_t
*n_idctl
;
172 nvme_qpair_t
*n_adminq
;
173 nvme_qpair_t
**n_ioq
;
175 nvme_namespace_t
*n_ns
;
177 ddi_dma_attr_t n_queue_dma_attr
;
178 ddi_dma_attr_t n_prp_dma_attr
;
179 ddi_dma_attr_t n_sgl_dma_attr
;
180 ddi_device_acc_attr_t n_reg_acc_attr
;
181 ddi_iblock_cookie_t n_fm_ibc
;
184 ksema_t n_abort_sema
;
186 ddi_taskq_t
*n_cmd_taskq
;
188 /* state for devctl minor node */
189 nvme_minor_state_t n_minor
;
191 /* errors detected by driver */
192 uint32_t n_dma_bind_err
;
193 uint32_t n_abort_failed
;
194 uint32_t n_cmd_timeout
;
195 uint32_t n_cmd_aborted
;
196 uint32_t n_wrong_logpage
;
197 uint32_t n_unknown_logpage
;
198 uint32_t n_too_many_cookies
;
200 /* errors detected by hardware */
201 uint32_t n_data_xfr_err
;
202 uint32_t n_internal_err
;
203 uint32_t n_abort_rq_err
;
204 uint32_t n_abort_sq_del
;
205 uint32_t n_nvm_cap_exc
;
206 uint32_t n_nvm_ns_notrdy
;
207 uint32_t n_inv_cq_err
;
208 uint32_t n_inv_qid_err
;
209 uint32_t n_max_qsz_exc
;
210 uint32_t n_inv_int_vect
;
211 uint32_t n_inv_log_page
;
212 uint32_t n_inv_format
;
213 uint32_t n_inv_q_del
;
214 uint32_t n_cnfl_attr
;
218 /* errors reported by asynchronous events */
219 uint32_t n_diagfail_event
;
220 uint32_t n_persistent_event
;
221 uint32_t n_transient_event
;
222 uint32_t n_fw_load_event
;
223 uint32_t n_reliability_event
;
224 uint32_t n_temperature_event
;
225 uint32_t n_spare_event
;
226 uint32_t n_vendor_event
;
227 uint32_t n_unknown_event
;
231 struct nvme_namespace
{
236 bd_handle_t ns_bd_hdl
;
239 size_t ns_block_count
;
240 size_t ns_block_size
;
241 size_t ns_best_block_size
;
245 nvme_identify_nsid_t
*ns_idns
;
247 /* state for attachment point minor node */
248 nvme_minor_state_t ns_minor
;
251 * If a namespace has no EUI64, we create a devid in
252 * nvme_prepare_devid().
257 struct nvme_task_arg
{
267 #endif /* _NVME_VAR_H */