]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/nvme/target/admin-cmd.c
nvmet: add commands supported and effects log page
[mirror_ubuntu-jammy-kernel.git] / drivers / nvme / target / admin-cmd.c
CommitLineData
a07b4970
CH
1/*
2 * NVMe admin command implementation.
3 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#include <linux/module.h>
b2d09103
IM
16#include <linux/rculist.h>
17
a07b4970 18#include <generated/utsrelease.h>
2d79c7dc 19#include <asm/unaligned.h>
a07b4970
CH
20#include "nvmet.h"
21
22u32 nvmet_get_log_page_len(struct nvme_command *cmd)
23{
24 u32 len = le16_to_cpu(cmd->get_log_page.numdu);
25
26 len <<= 16;
27 len += le16_to_cpu(cmd->get_log_page.numdl);
28 /* NUMD is a 0's based value */
29 len += 1;
30 len *= sizeof(u32);
31
32 return len;
33}
34
8ab0805f
CH
35static void nvmet_execute_get_log_page_noop(struct nvmet_req *req)
36{
37 nvmet_req_complete(req, nvmet_zero_sgl(req, 0, req->data_len));
38}
39
2d79c7dc
CK
40static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,
41 struct nvme_smart_log *slog)
42{
2d79c7dc
CK
43 struct nvmet_ns *ns;
44 u64 host_reads, host_writes, data_units_read, data_units_written;
45
2d79c7dc
CK
46 ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->get_log_page.nsid);
47 if (!ns) {
b38b9054 48 pr_err("nvmet : Could not find namespace id : %d\n",
2d79c7dc 49 le32_to_cpu(req->cmd->get_log_page.nsid));
4185f25a 50 return NVME_SC_INVALID_NS;
2d79c7dc
CK
51 }
52
d5eff33e
CK
53 /* we don't have the right data for file backed ns */
54 if (!ns->bdev)
55 goto out;
56
2d79c7dc
CK
57 host_reads = part_stat_read(ns->bdev->bd_part, ios[READ]);
58 data_units_read = part_stat_read(ns->bdev->bd_part, sectors[READ]);
59 host_writes = part_stat_read(ns->bdev->bd_part, ios[WRITE]);
60 data_units_written = part_stat_read(ns->bdev->bd_part, sectors[WRITE]);
61
62 put_unaligned_le64(host_reads, &slog->host_reads[0]);
63 put_unaligned_le64(data_units_read, &slog->data_units_read[0]);
64 put_unaligned_le64(host_writes, &slog->host_writes[0]);
65 put_unaligned_le64(data_units_written, &slog->data_units_written[0]);
d5eff33e 66out:
2d79c7dc 67 nvmet_put_namespace(ns);
4185f25a
SG
68
69 return NVME_SC_SUCCESS;
2d79c7dc
CK
70}
71
72static u16 nvmet_get_smart_log_all(struct nvmet_req *req,
73 struct nvme_smart_log *slog)
74{
2d79c7dc
CK
75 u64 host_reads = 0, host_writes = 0;
76 u64 data_units_read = 0, data_units_written = 0;
77 struct nvmet_ns *ns;
78 struct nvmet_ctrl *ctrl;
79
2d79c7dc
CK
80 ctrl = req->sq->ctrl;
81
82 rcu_read_lock();
83 list_for_each_entry_rcu(ns, &ctrl->subsys->namespaces, dev_link) {
d5eff33e
CK
84 /* we don't have the right data for file backed ns */
85 if (!ns->bdev)
86 continue;
2d79c7dc
CK
87 host_reads += part_stat_read(ns->bdev->bd_part, ios[READ]);
88 data_units_read +=
89 part_stat_read(ns->bdev->bd_part, sectors[READ]);
90 host_writes += part_stat_read(ns->bdev->bd_part, ios[WRITE]);
91 data_units_written +=
92 part_stat_read(ns->bdev->bd_part, sectors[WRITE]);
93
94 }
95 rcu_read_unlock();
96
97 put_unaligned_le64(host_reads, &slog->host_reads[0]);
98 put_unaligned_le64(data_units_read, &slog->data_units_read[0]);
99 put_unaligned_le64(host_writes, &slog->host_writes[0]);
100 put_unaligned_le64(data_units_written, &slog->data_units_written[0]);
101
4185f25a 102 return NVME_SC_SUCCESS;
2d79c7dc
CK
103}
104
8ab0805f 105static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)
a07b4970 106{
8ab0805f
CH
107 struct nvme_smart_log *log;
108 u16 status = NVME_SC_INTERNAL;
a07b4970 109
8ab0805f 110 if (req->data_len != sizeof(*log))
a07b4970 111 goto out;
a07b4970 112
8ab0805f
CH
113 log = kzalloc(sizeof(*log), GFP_KERNEL);
114 if (!log)
115 goto out;
a07b4970 116
8ab0805f
CH
117 if (req->cmd->get_log_page.nsid == cpu_to_le32(NVME_NSID_ALL))
118 status = nvmet_get_smart_log_all(req, log);
119 else
120 status = nvmet_get_smart_log_nsid(req, log);
121 if (status)
c42d7a30 122 goto out_free_log;
a07b4970 123
8ab0805f 124 status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log));
c42d7a30
CK
125out_free_log:
126 kfree(log);
a07b4970
CH
127out:
128 nvmet_req_complete(req, status);
129}
130
0866bf0c
CK
131static void nvmet_execute_get_log_cmd_effects_ns(struct nvmet_req *req)
132{
133 u16 status = NVME_SC_INTERNAL;
134 struct nvme_effects_log *log;
135
136 log = kzalloc(sizeof(*log), GFP_KERNEL);
137 if (!log)
138 goto out;
139
140 log->acs[nvme_admin_get_log_page] = cpu_to_le32(1 << 0);
141 log->acs[nvme_admin_identify] = cpu_to_le32(1 << 0);
142 log->acs[nvme_admin_abort_cmd] = cpu_to_le32(1 << 0);
143 log->acs[nvme_admin_set_features] = cpu_to_le32(1 << 0);
144 log->acs[nvme_admin_get_features] = cpu_to_le32(1 << 0);
145 log->acs[nvme_admin_async_event] = cpu_to_le32(1 << 0);
146 log->acs[nvme_admin_keep_alive] = cpu_to_le32(1 << 0);
147
148 log->iocs[nvme_cmd_read] = cpu_to_le32(1 << 0);
149 log->iocs[nvme_cmd_write] = cpu_to_le32(1 << 0);
150 log->iocs[nvme_cmd_flush] = cpu_to_le32(1 << 0);
151 log->iocs[nvme_cmd_dsm] = cpu_to_le32(1 << 0);
152 log->iocs[nvme_cmd_write_zeroes] = cpu_to_le32(1 << 0);
153
154 status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log));
155
156 kfree(log);
157out:
158 nvmet_req_complete(req, status);
159}
160
c16734ea
CH
161static void nvmet_execute_get_log_changed_ns(struct nvmet_req *req)
162{
163 struct nvmet_ctrl *ctrl = req->sq->ctrl;
164 u16 status = NVME_SC_INTERNAL;
165 size_t len;
166
167 if (req->data_len != NVME_MAX_CHANGED_NAMESPACES * sizeof(__le32))
168 goto out;
169
170 mutex_lock(&ctrl->lock);
171 if (ctrl->nr_changed_ns == U32_MAX)
172 len = sizeof(__le32);
173 else
174 len = ctrl->nr_changed_ns * sizeof(__le32);
175 status = nvmet_copy_to_sgl(req, 0, ctrl->changed_ns_list, len);
176 if (!status)
177 status = nvmet_zero_sgl(req, len, req->data_len - len);
178 ctrl->nr_changed_ns = 0;
55fdd6b6 179 clear_bit(NVME_AEN_CFG_NS_ATTR, &ctrl->aen_masked);
c16734ea
CH
180 mutex_unlock(&ctrl->lock);
181out:
182 nvmet_req_complete(req, status);
183}
184
a07b4970
CH
185static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
186{
187 struct nvmet_ctrl *ctrl = req->sq->ctrl;
188 struct nvme_id_ctrl *id;
a07b4970 189 u16 status = 0;
42de82a8 190 const char model[] = "Linux";
a07b4970
CH
191
192 id = kzalloc(sizeof(*id), GFP_KERNEL);
193 if (!id) {
194 status = NVME_SC_INTERNAL;
195 goto out;
196 }
197
198 /* XXX: figure out how to assign real vendors IDs. */
199 id->vid = 0;
200 id->ssvid = 0;
201
c7399698 202 memset(id->sn, ' ', sizeof(id->sn));
42de82a8
MW
203 bin2hex(id->sn, &ctrl->subsys->serial,
204 min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2));
17c39d05
MW
205 memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' ');
206 memcpy_and_pad(id->fr, sizeof(id->fr),
207 UTS_RELEASE, strlen(UTS_RELEASE), ' ');
a07b4970 208
a07b4970
CH
209 id->rab = 6;
210
211 /*
212 * XXX: figure out how we can assign a IEEE OUI, but until then
213 * the safest is to leave it as zeroes.
214 */
215
216 /* we support multiple ports and multiples hosts: */
a446c084 217 id->cmic = (1 << 0) | (1 << 1);
a07b4970
CH
218
219 /* no limit on data transfer sizes for now */
220 id->mdts = 0;
221 id->cntlid = cpu_to_le16(ctrl->cntlid);
222 id->ver = cpu_to_le32(ctrl->subsys->ver);
223
224 /* XXX: figure out what to do about RTD3R/RTD3 */
c86b8f7b 225 id->oaes = cpu_to_le32(NVMET_AEN_CFG_OPTIONAL);
a07b4970
CH
226 id->ctratt = cpu_to_le32(1 << 0);
227
228 id->oacs = 0;
229
230 /*
231 * We don't really have a practical limit on the number of abort
232 * comands. But we don't do anything useful for abort either, so
233 * no point in allowing more abort commands than the spec requires.
234 */
235 id->acl = 3;
236
237 id->aerl = NVMET_ASYNC_EVENTS - 1;
238
239 /* first slot is read-only, only one slot supported */
240 id->frmw = (1 << 0) | (1 << 1);
0866bf0c 241 id->lpa = (1 << 0) | (1 << 1) | (1 << 2);
a07b4970
CH
242 id->elpe = NVMET_ERROR_LOG_SLOTS - 1;
243 id->npss = 0;
244
245 /* We support keep-alive timeout in granularity of seconds */
246 id->kas = cpu_to_le16(NVMET_KAS);
247
248 id->sqes = (0x6 << 4) | 0x6;
249 id->cqes = (0x4 << 4) | 0x4;
250
251 /* no enforcement soft-limit for maxcmd - pick arbitrary high value */
252 id->maxcmd = cpu_to_le16(NVMET_MAX_CMD);
253
254 id->nn = cpu_to_le32(ctrl->subsys->max_nsid);
d2629209
CK
255 id->oncs = cpu_to_le16(NVME_CTRL_ONCS_DSM |
256 NVME_CTRL_ONCS_WRITE_ZEROES);
a07b4970
CH
257
258 /* XXX: don't report vwc if the underlying device is write through */
259 id->vwc = NVME_CTRL_VWC_PRESENT;
260
261 /*
262 * We can't support atomic writes bigger than a LBA without support
263 * from the backend device.
264 */
265 id->awun = 0;
266 id->awupf = 0;
267
268 id->sgls = cpu_to_le32(1 << 0); /* we always support SGLs */
269 if (ctrl->ops->has_keyed_sgls)
270 id->sgls |= cpu_to_le32(1 << 2);
271 if (ctrl->ops->sqe_inline_size)
272 id->sgls |= cpu_to_le32(1 << 20);
273
274 strcpy(id->subnqn, ctrl->subsys->subsysnqn);
275
276 /* Max command capsule size is sqe + single page of in-capsule data */
277 id->ioccsz = cpu_to_le32((sizeof(struct nvme_command) +
278 ctrl->ops->sqe_inline_size) / 16);
279 /* Max response capsule size is cqe */
280 id->iorcsz = cpu_to_le32(sizeof(struct nvme_completion) / 16);
281
282 id->msdbd = ctrl->ops->msdbd;
283
284 /*
285 * Meh, we don't really support any power state. Fake up the same
286 * values that qemu does.
287 */
288 id->psd[0].max_power = cpu_to_le16(0x9c4);
289 id->psd[0].entry_lat = cpu_to_le32(0x10);
290 id->psd[0].exit_lat = cpu_to_le32(0x4);
291
292 status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id));
293
294 kfree(id);
295out:
296 nvmet_req_complete(req, status);
297}
298
299static void nvmet_execute_identify_ns(struct nvmet_req *req)
300{
301 struct nvmet_ns *ns;
302 struct nvme_id_ns *id;
303 u16 status = 0;
304
f39ae471 305 if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) {
a07b4970
CH
306 status = NVME_SC_INVALID_NS | NVME_SC_DNR;
307 goto out;
308 }
309
310 id = kzalloc(sizeof(*id), GFP_KERNEL);
311 if (!id) {
312 status = NVME_SC_INTERNAL;
f39ae471 313 goto out;
a07b4970
CH
314 }
315
f39ae471
CH
316 /* return an all zeroed buffer if we can't find an active namespace */
317 ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid);
318 if (!ns)
319 goto done;
320
a07b4970 321 /*
18c53e40 322 * nuse = ncap = nsze isn't always true, but we have no way to find
a07b4970
CH
323 * that out from the underlying device.
324 */
325 id->ncap = id->nuse = id->nsze =
326 cpu_to_le64(ns->size >> ns->blksize_shift);
327
328 /*
329 * We just provide a single LBA format that matches what the
330 * underlying device reports.
331 */
332 id->nlbaf = 0;
333 id->flbas = 0;
334
335 /*
336 * Our namespace might always be shared. Not just with other
337 * controllers, but also with any other user of the block device.
338 */
339 id->nmic = (1 << 0);
340
341 memcpy(&id->nguid, &ns->nguid, sizeof(uuid_le));
342
343 id->lbaf[0].ds = ns->blksize_shift;
344
f39ae471
CH
345 nvmet_put_namespace(ns);
346done:
a07b4970 347 status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id));
a07b4970 348 kfree(id);
a07b4970
CH
349out:
350 nvmet_req_complete(req, status);
351}
352
353static void nvmet_execute_identify_nslist(struct nvmet_req *req)
354{
0add5e8e 355 static const int buf_size = NVME_IDENTIFY_DATA_SIZE;
a07b4970
CH
356 struct nvmet_ctrl *ctrl = req->sq->ctrl;
357 struct nvmet_ns *ns;
358 u32 min_nsid = le32_to_cpu(req->cmd->identify.nsid);
359 __le32 *list;
360 u16 status = 0;
361 int i = 0;
362
363 list = kzalloc(buf_size, GFP_KERNEL);
364 if (!list) {
365 status = NVME_SC_INTERNAL;
366 goto out;
367 }
368
369 rcu_read_lock();
370 list_for_each_entry_rcu(ns, &ctrl->subsys->namespaces, dev_link) {
371 if (ns->nsid <= min_nsid)
372 continue;
373 list[i++] = cpu_to_le32(ns->nsid);
374 if (i == buf_size / sizeof(__le32))
375 break;
376 }
377 rcu_read_unlock();
378
379 status = nvmet_copy_to_sgl(req, 0, list, buf_size);
380
381 kfree(list);
382out:
383 nvmet_req_complete(req, status);
384}
385
637dc0f3
JT
386static u16 nvmet_copy_ns_identifier(struct nvmet_req *req, u8 type, u8 len,
387 void *id, off_t *off)
388{
389 struct nvme_ns_id_desc desc = {
390 .nidt = type,
391 .nidl = len,
392 };
393 u16 status;
394
395 status = nvmet_copy_to_sgl(req, *off, &desc, sizeof(desc));
396 if (status)
397 return status;
398 *off += sizeof(desc);
399
400 status = nvmet_copy_to_sgl(req, *off, id, len);
401 if (status)
402 return status;
403 *off += len;
404
405 return 0;
406}
407
408static void nvmet_execute_identify_desclist(struct nvmet_req *req)
409{
410 struct nvmet_ns *ns;
411 u16 status = 0;
412 off_t off = 0;
413
414 ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid);
415 if (!ns) {
416 status = NVME_SC_INVALID_NS | NVME_SC_DNR;
417 goto out;
418 }
419
420 if (memchr_inv(&ns->uuid, 0, sizeof(ns->uuid))) {
421 status = nvmet_copy_ns_identifier(req, NVME_NIDT_UUID,
422 NVME_NIDT_UUID_LEN,
423 &ns->uuid, &off);
424 if (status)
425 goto out_put_ns;
426 }
427 if (memchr_inv(ns->nguid, 0, sizeof(ns->nguid))) {
428 status = nvmet_copy_ns_identifier(req, NVME_NIDT_NGUID,
429 NVME_NIDT_NGUID_LEN,
430 &ns->nguid, &off);
431 if (status)
432 goto out_put_ns;
433 }
434
435 if (sg_zero_buffer(req->sg, req->sg_cnt, NVME_IDENTIFY_DATA_SIZE - off,
436 off) != NVME_IDENTIFY_DATA_SIZE - off)
437 status = NVME_SC_INTERNAL | NVME_SC_DNR;
438out_put_ns:
439 nvmet_put_namespace(ns);
440out:
441 nvmet_req_complete(req, status);
442}
443
a07b4970 444/*
18c53e40 445 * A "minimum viable" abort implementation: the command is mandatory in the
a07b4970
CH
446 * spec, but we are not required to do any useful work. We couldn't really
447 * do a useful abort, so don't bother even with waiting for the command
448 * to be exectuted and return immediately telling the command to abort
449 * wasn't found.
450 */
451static void nvmet_execute_abort(struct nvmet_req *req)
452{
453 nvmet_set_result(req, 1);
454 nvmet_req_complete(req, 0);
455}
456
457static void nvmet_execute_set_features(struct nvmet_req *req)
458{
459 struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
460 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10[0]);
a07b4970
CH
461 u32 val32;
462 u16 status = 0;
463
28dd5cf7 464 switch (cdw10 & 0xff) {
a07b4970
CH
465 case NVME_FEAT_NUM_QUEUES:
466 nvmet_set_result(req,
467 (subsys->max_qid - 1) | ((subsys->max_qid - 1) << 16));
468 break;
469 case NVME_FEAT_KATO:
6c73f949 470 val32 = le32_to_cpu(req->cmd->common.cdw10[1]);
a07b4970
CH
471 req->sq->ctrl->kato = DIV_ROUND_UP(val32, 1000);
472 nvmet_set_result(req, req->sq->ctrl->kato);
473 break;
c86b8f7b
CH
474 case NVME_FEAT_ASYNC_EVENT:
475 val32 = le32_to_cpu(req->cmd->common.cdw10[1]);
476 if (val32 & ~NVMET_AEN_CFG_ALL) {
477 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
478 break;
479 }
480
481 WRITE_ONCE(req->sq->ctrl->aen_enabled, val32);
482 nvmet_set_result(req, val32);
483 break;
28dd5cf7
OM
484 case NVME_FEAT_HOST_ID:
485 status = NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
486 break;
a07b4970
CH
487 default:
488 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
489 break;
490 }
491
492 nvmet_req_complete(req, status);
493}
494
495static void nvmet_execute_get_features(struct nvmet_req *req)
496{
497 struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
498 u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10[0]);
499 u16 status = 0;
500
28dd5cf7 501 switch (cdw10 & 0xff) {
a07b4970
CH
502 /*
503 * These features are mandatory in the spec, but we don't
504 * have a useful way to implement them. We'll eventually
505 * need to come up with some fake values for these.
506 */
507#if 0
508 case NVME_FEAT_ARBITRATION:
509 break;
510 case NVME_FEAT_POWER_MGMT:
511 break;
512 case NVME_FEAT_TEMP_THRESH:
513 break;
514 case NVME_FEAT_ERR_RECOVERY:
515 break;
516 case NVME_FEAT_IRQ_COALESCE:
517 break;
518 case NVME_FEAT_IRQ_CONFIG:
519 break;
520 case NVME_FEAT_WRITE_ATOMIC:
521 break;
c86b8f7b 522#endif
a07b4970 523 case NVME_FEAT_ASYNC_EVENT:
c86b8f7b 524 nvmet_set_result(req, READ_ONCE(req->sq->ctrl->aen_enabled));
a07b4970 525 break;
a07b4970
CH
526 case NVME_FEAT_VOLATILE_WC:
527 nvmet_set_result(req, 1);
528 break;
529 case NVME_FEAT_NUM_QUEUES:
530 nvmet_set_result(req,
531 (subsys->max_qid-1) | ((subsys->max_qid-1) << 16));
532 break;
533 case NVME_FEAT_KATO:
534 nvmet_set_result(req, req->sq->ctrl->kato * 1000);
535 break;
28dd5cf7
OM
536 case NVME_FEAT_HOST_ID:
537 /* need 128-bit host identifier flag */
538 if (!(req->cmd->common.cdw10[1] & cpu_to_le32(1 << 0))) {
539 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
540 break;
541 }
542
543 status = nvmet_copy_to_sgl(req, 0, &req->sq->ctrl->hostid,
544 sizeof(req->sq->ctrl->hostid));
545 break;
a07b4970
CH
546 default:
547 status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
548 break;
549 }
550
551 nvmet_req_complete(req, status);
552}
553
554static void nvmet_execute_async_event(struct nvmet_req *req)
555{
556 struct nvmet_ctrl *ctrl = req->sq->ctrl;
557
558 mutex_lock(&ctrl->lock);
559 if (ctrl->nr_async_event_cmds >= NVMET_ASYNC_EVENTS) {
560 mutex_unlock(&ctrl->lock);
561 nvmet_req_complete(req, NVME_SC_ASYNC_LIMIT | NVME_SC_DNR);
562 return;
563 }
564 ctrl->async_event_cmds[ctrl->nr_async_event_cmds++] = req;
565 mutex_unlock(&ctrl->lock);
566
567 schedule_work(&ctrl->async_event_work);
568}
569
570static void nvmet_execute_keep_alive(struct nvmet_req *req)
571{
572 struct nvmet_ctrl *ctrl = req->sq->ctrl;
573
574 pr_debug("ctrl %d update keep-alive timer for %d secs\n",
575 ctrl->cntlid, ctrl->kato);
576
577 mod_delayed_work(system_wq, &ctrl->ka_work, ctrl->kato * HZ);
578 nvmet_req_complete(req, 0);
579}
580
64a0ca88 581u16 nvmet_parse_admin_cmd(struct nvmet_req *req)
a07b4970
CH
582{
583 struct nvme_command *cmd = req->cmd;
64a0ca88 584 u16 ret;
a07b4970 585
64a0ca88
PP
586 ret = nvmet_check_ctrl_status(req, cmd);
587 if (unlikely(ret))
588 return ret;
a07b4970
CH
589
590 switch (cmd->common.opcode) {
591 case nvme_admin_get_log_page:
592 req->data_len = nvmet_get_log_page_len(cmd);
593
594 switch (cmd->get_log_page.lid) {
2ca0786d 595 case NVME_LOG_ERROR:
8ab0805f
CH
596 /*
597 * We currently never set the More bit in the status
598 * field, so all error log entries are invalid and can
599 * be zeroed out. This is called a minum viable
600 * implementation (TM) of this mandatory log page.
601 */
602 req->execute = nvmet_execute_get_log_page_noop;
603 return 0;
2ca0786d 604 case NVME_LOG_SMART:
8ab0805f
CH
605 req->execute = nvmet_execute_get_log_page_smart;
606 return 0;
2ca0786d 607 case NVME_LOG_FW_SLOT:
8ab0805f
CH
608 /*
609 * We only support a single firmware slot which always
610 * is active, so we can zero out the whole firmware slot
611 * log and still claim to fully implement this mandatory
612 * log page.
613 */
614 req->execute = nvmet_execute_get_log_page_noop;
a07b4970 615 return 0;
c16734ea
CH
616 case NVME_LOG_CHANGED_NS:
617 req->execute = nvmet_execute_get_log_changed_ns;
618 return 0;
0866bf0c
CK
619 case NVME_LOG_CMD_EFFECTS:
620 req->execute = nvmet_execute_get_log_cmd_effects_ns;
621 return 0;
a07b4970
CH
622 }
623 break;
624 case nvme_admin_identify:
0add5e8e 625 req->data_len = NVME_IDENTIFY_DATA_SIZE;
986994a2 626 switch (cmd->identify.cns) {
e9c9346e 627 case NVME_ID_CNS_NS:
a07b4970
CH
628 req->execute = nvmet_execute_identify_ns;
629 return 0;
e9c9346e 630 case NVME_ID_CNS_CTRL:
a07b4970
CH
631 req->execute = nvmet_execute_identify_ctrl;
632 return 0;
e9c9346e 633 case NVME_ID_CNS_NS_ACTIVE_LIST:
a07b4970
CH
634 req->execute = nvmet_execute_identify_nslist;
635 return 0;
637dc0f3
JT
636 case NVME_ID_CNS_NS_DESC_LIST:
637 req->execute = nvmet_execute_identify_desclist;
638 return 0;
a07b4970
CH
639 }
640 break;
641 case nvme_admin_abort_cmd:
642 req->execute = nvmet_execute_abort;
643 req->data_len = 0;
644 return 0;
645 case nvme_admin_set_features:
646 req->execute = nvmet_execute_set_features;
647 req->data_len = 0;
648 return 0;
649 case nvme_admin_get_features:
650 req->execute = nvmet_execute_get_features;
651 req->data_len = 0;
652 return 0;
653 case nvme_admin_async_event:
654 req->execute = nvmet_execute_async_event;
655 req->data_len = 0;
656 return 0;
657 case nvme_admin_keep_alive:
658 req->execute = nvmet_execute_keep_alive;
659 req->data_len = 0;
660 return 0;
661 }
662
64a0ca88
PP
663 pr_err("unhandled cmd %d on qid %d\n", cmd->common.opcode,
664 req->sq->qid);
a07b4970
CH
665 return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
666}