syscons,vt: improve phrasing in kern.vty man page description
[freebsd-src.git] / sys / dev / nvme / nvme_ctrlr_cmd.c
blobe2abf0e7fbe228b3ecd3d28f7d753b33015ee52d
1 /*-
2 * Copyright (C) 2012-2013 Intel Corporation
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "nvme_private.h"
32 void
33 nvme_ctrlr_cmd_identify_controller(struct nvme_controller *ctrlr, void *payload,
34 nvme_cb_fn_t cb_fn, void *cb_arg)
36 struct nvme_request *req;
37 struct nvme_command *cmd;
39 req = nvme_allocate_request_vaddr(payload,
40 sizeof(struct nvme_controller_data), cb_fn, cb_arg);
42 cmd = &req->cmd;
43 cmd->opc = NVME_OPC_IDENTIFY;
46 * TODO: create an identify command data structure, which
47 * includes this CNS bit in cdw10.
49 cmd->cdw10 = 1;
51 nvme_ctrlr_submit_admin_request(ctrlr, req);
54 void
55 nvme_ctrlr_cmd_identify_namespace(struct nvme_controller *ctrlr, uint16_t nsid,
56 void *payload, nvme_cb_fn_t cb_fn, void *cb_arg)
58 struct nvme_request *req;
59 struct nvme_command *cmd;
61 req = nvme_allocate_request_vaddr(payload,
62 sizeof(struct nvme_namespace_data), cb_fn, cb_arg);
64 cmd = &req->cmd;
65 cmd->opc = NVME_OPC_IDENTIFY;
68 * TODO: create an identify command data structure
70 cmd->nsid = nsid;
72 nvme_ctrlr_submit_admin_request(ctrlr, req);
75 void
76 nvme_ctrlr_cmd_create_io_cq(struct nvme_controller *ctrlr,
77 struct nvme_qpair *io_que, uint16_t vector, nvme_cb_fn_t cb_fn,
78 void *cb_arg)
80 struct nvme_request *req;
81 struct nvme_command *cmd;
83 req = nvme_allocate_request_null(cb_fn, cb_arg);
85 cmd = &req->cmd;
86 cmd->opc = NVME_OPC_CREATE_IO_CQ;
89 * TODO: create a create io completion queue command data
90 * structure.
92 cmd->cdw10 = ((io_que->num_entries-1) << 16) | io_que->id;
93 /* 0x3 = interrupts enabled | physically contiguous */
94 cmd->cdw11 = (vector << 16) | 0x3;
95 cmd->prp1 = io_que->cpl_bus_addr;
97 nvme_ctrlr_submit_admin_request(ctrlr, req);
100 void
101 nvme_ctrlr_cmd_create_io_sq(struct nvme_controller *ctrlr,
102 struct nvme_qpair *io_que, nvme_cb_fn_t cb_fn, void *cb_arg)
104 struct nvme_request *req;
105 struct nvme_command *cmd;
107 req = nvme_allocate_request_null(cb_fn, cb_arg);
109 cmd = &req->cmd;
110 cmd->opc = NVME_OPC_CREATE_IO_SQ;
113 * TODO: create a create io submission queue command data
114 * structure.
116 cmd->cdw10 = ((io_que->num_entries-1) << 16) | io_que->id;
117 /* 0x1 = physically contiguous */
118 cmd->cdw11 = (io_que->id << 16) | 0x1;
119 cmd->prp1 = io_que->cmd_bus_addr;
121 nvme_ctrlr_submit_admin_request(ctrlr, req);
124 void
125 nvme_ctrlr_cmd_delete_io_cq(struct nvme_controller *ctrlr,
126 struct nvme_qpair *io_que, nvme_cb_fn_t cb_fn, void *cb_arg)
128 struct nvme_request *req;
129 struct nvme_command *cmd;
131 req = nvme_allocate_request_null(cb_fn, cb_arg);
133 cmd = &req->cmd;
134 cmd->opc = NVME_OPC_DELETE_IO_CQ;
137 * TODO: create a delete io completion queue command data
138 * structure.
140 cmd->cdw10 = io_que->id;
142 nvme_ctrlr_submit_admin_request(ctrlr, req);
145 void
146 nvme_ctrlr_cmd_delete_io_sq(struct nvme_controller *ctrlr,
147 struct nvme_qpair *io_que, nvme_cb_fn_t cb_fn, void *cb_arg)
149 struct nvme_request *req;
150 struct nvme_command *cmd;
152 req = nvme_allocate_request_null(cb_fn, cb_arg);
154 cmd = &req->cmd;
155 cmd->opc = NVME_OPC_DELETE_IO_SQ;
158 * TODO: create a delete io submission queue command data
159 * structure.
161 cmd->cdw10 = io_que->id;
163 nvme_ctrlr_submit_admin_request(ctrlr, req);
166 void
167 nvme_ctrlr_cmd_set_feature(struct nvme_controller *ctrlr, uint8_t feature,
168 uint32_t cdw11, void *payload, uint32_t payload_size,
169 nvme_cb_fn_t cb_fn, void *cb_arg)
171 struct nvme_request *req;
172 struct nvme_command *cmd;
174 req = nvme_allocate_request_null(cb_fn, cb_arg);
176 cmd = &req->cmd;
177 cmd->opc = NVME_OPC_SET_FEATURES;
178 cmd->cdw10 = feature;
179 cmd->cdw11 = cdw11;
181 nvme_ctrlr_submit_admin_request(ctrlr, req);
184 void
185 nvme_ctrlr_cmd_get_feature(struct nvme_controller *ctrlr, uint8_t feature,
186 uint32_t cdw11, void *payload, uint32_t payload_size,
187 nvme_cb_fn_t cb_fn, void *cb_arg)
189 struct nvme_request *req;
190 struct nvme_command *cmd;
192 req = nvme_allocate_request_null(cb_fn, cb_arg);
194 cmd = &req->cmd;
195 cmd->opc = NVME_OPC_GET_FEATURES;
196 cmd->cdw10 = feature;
197 cmd->cdw11 = cdw11;
199 nvme_ctrlr_submit_admin_request(ctrlr, req);
202 void
203 nvme_ctrlr_cmd_set_num_queues(struct nvme_controller *ctrlr,
204 uint32_t num_queues, nvme_cb_fn_t cb_fn, void *cb_arg)
206 uint32_t cdw11;
208 cdw11 = ((num_queues - 1) << 16) | (num_queues - 1);
209 nvme_ctrlr_cmd_set_feature(ctrlr, NVME_FEAT_NUMBER_OF_QUEUES, cdw11,
210 NULL, 0, cb_fn, cb_arg);
213 void
214 nvme_ctrlr_cmd_set_async_event_config(struct nvme_controller *ctrlr,
215 union nvme_critical_warning_state state, nvme_cb_fn_t cb_fn,
216 void *cb_arg)
218 uint32_t cdw11;
220 cdw11 = state.raw;
221 nvme_ctrlr_cmd_set_feature(ctrlr,
222 NVME_FEAT_ASYNC_EVENT_CONFIGURATION, cdw11, NULL, 0, cb_fn,
223 cb_arg);
226 void
227 nvme_ctrlr_cmd_set_interrupt_coalescing(struct nvme_controller *ctrlr,
228 uint32_t microseconds, uint32_t threshold, nvme_cb_fn_t cb_fn, void *cb_arg)
230 uint32_t cdw11;
232 if ((microseconds/100) >= 0x100) {
233 nvme_printf(ctrlr, "invalid coal time %d, disabling\n",
234 microseconds);
235 microseconds = 0;
236 threshold = 0;
239 if (threshold >= 0x100) {
240 nvme_printf(ctrlr, "invalid threshold %d, disabling\n",
241 threshold);
242 threshold = 0;
243 microseconds = 0;
246 cdw11 = ((microseconds/100) << 8) | threshold;
247 nvme_ctrlr_cmd_set_feature(ctrlr, NVME_FEAT_INTERRUPT_COALESCING, cdw11,
248 NULL, 0, cb_fn, cb_arg);
251 void
252 nvme_ctrlr_cmd_get_log_page(struct nvme_controller *ctrlr, uint8_t log_page,
253 uint32_t nsid, void *payload, uint32_t payload_size, nvme_cb_fn_t cb_fn,
254 void *cb_arg)
256 struct nvme_request *req;
257 struct nvme_command *cmd;
259 req = nvme_allocate_request_vaddr(payload, payload_size, cb_fn, cb_arg);
261 cmd = &req->cmd;
262 cmd->opc = NVME_OPC_GET_LOG_PAGE;
263 cmd->nsid = nsid;
264 cmd->cdw10 = ((payload_size/sizeof(uint32_t)) - 1) << 16;
265 cmd->cdw10 |= log_page;
267 nvme_ctrlr_submit_admin_request(ctrlr, req);
270 void
271 nvme_ctrlr_cmd_get_error_page(struct nvme_controller *ctrlr,
272 struct nvme_error_information_entry *payload, uint32_t num_entries,
273 nvme_cb_fn_t cb_fn, void *cb_arg)
276 KASSERT(num_entries > 0, ("%s called with num_entries==0\n", __func__));
278 /* Controller's error log page entries is 0-based. */
279 KASSERT(num_entries <= (ctrlr->cdata.elpe + 1),
280 ("%s called with num_entries=%d but (elpe+1)=%d\n", __func__,
281 num_entries, ctrlr->cdata.elpe + 1));
283 if (num_entries > (ctrlr->cdata.elpe + 1))
284 num_entries = ctrlr->cdata.elpe + 1;
286 nvme_ctrlr_cmd_get_log_page(ctrlr, NVME_LOG_ERROR,
287 NVME_GLOBAL_NAMESPACE_TAG, payload, sizeof(*payload) * num_entries,
288 cb_fn, cb_arg);
291 void
292 nvme_ctrlr_cmd_get_health_information_page(struct nvme_controller *ctrlr,
293 uint32_t nsid, struct nvme_health_information_page *payload,
294 nvme_cb_fn_t cb_fn, void *cb_arg)
297 nvme_ctrlr_cmd_get_log_page(ctrlr, NVME_LOG_HEALTH_INFORMATION,
298 nsid, payload, sizeof(*payload), cb_fn, cb_arg);
301 void
302 nvme_ctrlr_cmd_get_firmware_page(struct nvme_controller *ctrlr,
303 struct nvme_firmware_page *payload, nvme_cb_fn_t cb_fn, void *cb_arg)
306 nvme_ctrlr_cmd_get_log_page(ctrlr, NVME_LOG_FIRMWARE_SLOT,
307 NVME_GLOBAL_NAMESPACE_TAG, payload, sizeof(*payload), cb_fn,
308 cb_arg);
311 void
312 nvme_ctrlr_cmd_abort(struct nvme_controller *ctrlr, uint16_t cid,
313 uint16_t sqid, nvme_cb_fn_t cb_fn, void *cb_arg)
315 struct nvme_request *req;
316 struct nvme_command *cmd;
318 req = nvme_allocate_request_null(cb_fn, cb_arg);
320 cmd = &req->cmd;
321 cmd->opc = NVME_OPC_ABORT;
322 cmd->cdw10 = (cid << 16) | sqid;
324 nvme_ctrlr_submit_admin_request(ctrlr, req);