1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (C) 2012-2016 Intel Corporation 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 #include "opt_cam.h" 31 #include "opt_nvme.h" 32 33 #include <sys/param.h> 34 #include <sys/systm.h> 35 #include <sys/buf.h> 36 #include <sys/bus.h> 37 #include <sys/conf.h> 38 #include <sys/ioccom.h> 39 #include <sys/proc.h> 40 #include <sys/smp.h> 41 #include <sys/uio.h> 42 #include <sys/sbuf.h> 43 #include <sys/endian.h> 44 #include <machine/stdarg.h> 45 #include <vm/vm.h> 46 47 #include "nvme_private.h" 48 49 #define B4_CHK_RDY_DELAY_MS 2300 /* work around controller bug */ 50 51 static void nvme_ctrlr_construct_and_submit_aer(struct nvme_controller *ctrlr, 52 struct nvme_async_event_request *aer); 53 54 static void 55 nvme_ctrlr_barrier(struct nvme_controller *ctrlr, int flags) 56 { 57 bus_barrier(ctrlr->resource, 0, rman_get_size(ctrlr->resource), flags); 58 } 59 60 static void 61 nvme_ctrlr_devctl_log(struct nvme_controller *ctrlr, const char *type, const char *msg, ...) 62 { 63 struct sbuf sb; 64 va_list ap; 65 int error; 66 67 if (sbuf_new(&sb, NULL, 0, SBUF_AUTOEXTEND | SBUF_NOWAIT) == NULL) 68 return; 69 sbuf_printf(&sb, "%s: ", device_get_nameunit(ctrlr->dev)); 70 va_start(ap, msg); 71 sbuf_vprintf(&sb, msg, ap); 72 va_end(ap); 73 error = sbuf_finish(&sb); 74 if (error == 0) 75 printf("%s\n", sbuf_data(&sb)); 76 77 sbuf_clear(&sb); 78 sbuf_printf(&sb, "name=\"%s\" reason=\"", device_get_nameunit(ctrlr->dev)); 79 va_start(ap, msg); 80 sbuf_vprintf(&sb, msg, ap); 81 va_end(ap); 82 sbuf_printf(&sb, "\""); 83 error = sbuf_finish(&sb); 84 if (error == 0) 85 devctl_notify("nvme", "controller", type, sbuf_data(&sb)); 86 sbuf_delete(&sb); 87 } 88 89 static int 90 nvme_ctrlr_construct_admin_qpair(struct nvme_controller *ctrlr) 91 { 92 struct nvme_qpair *qpair; 93 uint32_t num_entries; 94 int error; 95 96 qpair = &ctrlr->adminq; 97 qpair->id = 0; 98 qpair->cpu = CPU_FFS(&cpuset_domain[ctrlr->domain]) - 1; 99 qpair->domain = ctrlr->domain; 100 101 num_entries = NVME_ADMIN_ENTRIES; 102 TUNABLE_INT_FETCH("hw.nvme.admin_entries", &num_entries); 103 /* 104 * If admin_entries was overridden to an invalid value, revert it 105 * back to our default value. 106 */ 107 if (num_entries < NVME_MIN_ADMIN_ENTRIES || 108 num_entries > NVME_MAX_ADMIN_ENTRIES) { 109 nvme_printf(ctrlr, "invalid hw.nvme.admin_entries=%d " 110 "specified\n", num_entries); 111 num_entries = NVME_ADMIN_ENTRIES; 112 } 113 114 /* 115 * The admin queue's max xfer size is treated differently than the 116 * max I/O xfer size. 16KB is sufficient here - maybe even less? 117 */ 118 error = nvme_qpair_construct(qpair, num_entries, NVME_ADMIN_TRACKERS, 119 ctrlr); 120 return (error); 121 } 122 123 #define QP(ctrlr, c) ((c) * (ctrlr)->num_io_queues / mp_ncpus) 124 125 static int 126 nvme_ctrlr_construct_io_qpairs(struct nvme_controller *ctrlr) 127 { 128 struct nvme_qpair *qpair; 129 uint32_t cap_lo; 130 uint16_t mqes; 131 int c, error, i, n; 132 int num_entries, num_trackers, max_entries; 133 134 /* 135 * NVMe spec sets a hard limit of 64K max entries, but devices may 136 * specify a smaller limit, so we need to check the MQES field in the 137 * capabilities register. We have to cap the number of entries to the 138 * current stride allows for in BAR 0/1, otherwise the remainder entries 139 * are inaccessible. MQES should reflect this, and this is just a 140 * fail-safe. 141 */ 142 max_entries = 143 (rman_get_size(ctrlr->resource) - nvme_mmio_offsetof(doorbell[0])) / 144 (1 << (ctrlr->dstrd + 1)); 145 num_entries = NVME_IO_ENTRIES; 146 TUNABLE_INT_FETCH("hw.nvme.io_entries", &num_entries); 147 cap_lo = nvme_mmio_read_4(ctrlr, cap_lo); 148 mqes = NVME_CAP_LO_MQES(cap_lo); 149 num_entries = min(num_entries, mqes + 1); 150 num_entries = min(num_entries, max_entries); 151 152 num_trackers = NVME_IO_TRACKERS; 153 TUNABLE_INT_FETCH("hw.nvme.io_trackers", &num_trackers); 154 155 num_trackers = max(num_trackers, NVME_MIN_IO_TRACKERS); 156 num_trackers = min(num_trackers, NVME_MAX_IO_TRACKERS); 157 /* 158 * No need to have more trackers than entries in the submit queue. Note 159 * also that for a queue size of N, we can only have (N-1) commands 160 * outstanding, hence the "-1" here. 161 */ 162 num_trackers = min(num_trackers, (num_entries-1)); 163 164 /* 165 * Our best estimate for the maximum number of I/Os that we should 166 * normally have in flight at one time. This should be viewed as a hint, 167 * not a hard limit and will need to be revisited when the upper layers 168 * of the storage system grows multi-queue support. 169 */ 170 ctrlr->max_hw_pend_io = num_trackers * ctrlr->num_io_queues * 3 / 4; 171 172 ctrlr->ioq = malloc(ctrlr->num_io_queues * sizeof(struct nvme_qpair), 173 M_NVME, M_ZERO | M_WAITOK); 174 175 for (i = c = n = 0; i < ctrlr->num_io_queues; i++, c += n) { 176 qpair = &ctrlr->ioq[i]; 177 178 /* 179 * Admin queue has ID=0. IO queues start at ID=1 - 180 * hence the 'i+1' here. 181 */ 182 qpair->id = i + 1; 183 if (ctrlr->num_io_queues > 1) { 184 /* Find number of CPUs served by this queue. */ 185 for (n = 1; QP(ctrlr, c + n) == i; n++) 186 ; 187 /* Shuffle multiple NVMe devices between CPUs. */ 188 qpair->cpu = c + (device_get_unit(ctrlr->dev)+n/2) % n; 189 qpair->domain = pcpu_find(qpair->cpu)->pc_domain; 190 } else { 191 qpair->cpu = CPU_FFS(&cpuset_domain[ctrlr->domain]) - 1; 192 qpair->domain = ctrlr->domain; 193 } 194 195 /* 196 * For I/O queues, use the controller-wide max_xfer_size 197 * calculated in nvme_attach(). 198 */ 199 error = nvme_qpair_construct(qpair, num_entries, num_trackers, 200 ctrlr); 201 if (error) 202 return (error); 203 204 /* 205 * Do not bother binding interrupts if we only have one I/O 206 * interrupt thread for this controller. 207 */ 208 if (ctrlr->num_io_queues > 1) 209 bus_bind_intr(ctrlr->dev, qpair->res, qpair->cpu); 210 } 211 212 return (0); 213 } 214 215 static void 216 nvme_ctrlr_fail(struct nvme_controller *ctrlr) 217 { 218 int i; 219 220 /* 221 * No need to disable queues before failing them. Failing is a superet 222 * of disabling (though pedantically we'd abort the AERs silently with 223 * a different error, though when we fail, that hardly matters). 224 */ 225 ctrlr->is_failed = true; 226 nvme_qpair_fail(&ctrlr->adminq); 227 if (ctrlr->ioq != NULL) { 228 for (i = 0; i < ctrlr->num_io_queues; i++) { 229 nvme_qpair_fail(&ctrlr->ioq[i]); 230 } 231 } 232 nvme_notify_fail_consumers(ctrlr); 233 } 234 235 void 236 nvme_ctrlr_post_failed_request(struct nvme_controller *ctrlr, 237 struct nvme_request *req) 238 { 239 240 mtx_lock(&ctrlr->lock); 241 STAILQ_INSERT_TAIL(&ctrlr->fail_req, req, stailq); 242 mtx_unlock(&ctrlr->lock); 243 if (!ctrlr->is_dying) 244 taskqueue_enqueue(ctrlr->taskqueue, &ctrlr->fail_req_task); 245 } 246 247 static void 248 nvme_ctrlr_fail_req_task(void *arg, int pending) 249 { 250 struct nvme_controller *ctrlr = arg; 251 struct nvme_request *req; 252 253 mtx_lock(&ctrlr->lock); 254 while ((req = STAILQ_FIRST(&ctrlr->fail_req)) != NULL) { 255 STAILQ_REMOVE_HEAD(&ctrlr->fail_req, stailq); 256 mtx_unlock(&ctrlr->lock); 257 nvme_qpair_manual_complete_request(req->qpair, req, 258 NVME_SCT_GENERIC, NVME_SC_ABORTED_BY_REQUEST); 259 mtx_lock(&ctrlr->lock); 260 } 261 mtx_unlock(&ctrlr->lock); 262 } 263 264 /* 265 * Wait for RDY to change. 266 * 267 * Starts sleeping for 1us and geometrically increases it the longer we wait, 268 * capped at 1ms. 269 */ 270 static int 271 nvme_ctrlr_wait_for_ready(struct nvme_controller *ctrlr, int desired_val) 272 { 273 int timeout = ticks + MSEC_2_TICKS(ctrlr->ready_timeout_in_ms); 274 sbintime_t delta_t = SBT_1US; 275 uint32_t csts; 276 277 while (1) { 278 csts = nvme_mmio_read_4(ctrlr, csts); 279 if (csts == NVME_GONE) /* Hot unplug. */ 280 return (ENXIO); 281 if (((csts >> NVME_CSTS_REG_RDY_SHIFT) & NVME_CSTS_REG_RDY_MASK) 282 == desired_val) 283 break; 284 if (timeout - ticks < 0) { 285 nvme_printf(ctrlr, "controller ready did not become %d " 286 "within %d ms\n", desired_val, ctrlr->ready_timeout_in_ms); 287 return (ENXIO); 288 } 289 290 pause_sbt("nvmerdy", delta_t, 0, C_PREL(1)); 291 delta_t = min(SBT_1MS, delta_t * 3 / 2); 292 } 293 294 return (0); 295 } 296 297 static int 298 nvme_ctrlr_disable(struct nvme_controller *ctrlr) 299 { 300 uint32_t cc; 301 uint32_t csts; 302 uint8_t en, rdy; 303 int err; 304 305 cc = nvme_mmio_read_4(ctrlr, cc); 306 csts = nvme_mmio_read_4(ctrlr, csts); 307 308 en = (cc >> NVME_CC_REG_EN_SHIFT) & NVME_CC_REG_EN_MASK; 309 rdy = (csts >> NVME_CSTS_REG_RDY_SHIFT) & NVME_CSTS_REG_RDY_MASK; 310 311 /* 312 * Per 3.1.5 in NVME 1.3 spec, transitioning CC.EN from 0 to 1 313 * when CSTS.RDY is 1 or transitioning CC.EN from 1 to 0 when 314 * CSTS.RDY is 0 "has undefined results" So make sure that CSTS.RDY 315 * isn't the desired value. Short circuit if we're already disabled. 316 */ 317 if (en == 0) { 318 /* Wait for RDY == 0 or timeout & fail */ 319 if (rdy == 0) 320 return (0); 321 return (nvme_ctrlr_wait_for_ready(ctrlr, 0)); 322 } 323 if (rdy == 0) { 324 /* EN == 1, wait for RDY == 1 or timeout & fail */ 325 err = nvme_ctrlr_wait_for_ready(ctrlr, 1); 326 if (err != 0) 327 return (err); 328 } 329 330 cc &= ~NVME_CC_REG_EN_MASK; 331 nvme_mmio_write_4(ctrlr, cc, cc); 332 333 /* 334 * A few drives have firmware bugs that freeze the drive if we access 335 * the mmio too soon after we disable. 336 */ 337 if (ctrlr->quirks & QUIRK_DELAY_B4_CHK_RDY) 338 pause("nvmeR", MSEC_2_TICKS(B4_CHK_RDY_DELAY_MS)); 339 return (nvme_ctrlr_wait_for_ready(ctrlr, 0)); 340 } 341 342 static int 343 nvme_ctrlr_enable(struct nvme_controller *ctrlr) 344 { 345 uint32_t cc; 346 uint32_t csts; 347 uint32_t aqa; 348 uint32_t qsize; 349 uint8_t en, rdy; 350 int err; 351 352 cc = nvme_mmio_read_4(ctrlr, cc); 353 csts = nvme_mmio_read_4(ctrlr, csts); 354 355 en = (cc >> NVME_CC_REG_EN_SHIFT) & NVME_CC_REG_EN_MASK; 356 rdy = (csts >> NVME_CSTS_REG_RDY_SHIFT) & NVME_CSTS_REG_RDY_MASK; 357 358 /* 359 * See note in nvme_ctrlr_disable. Short circuit if we're already enabled. 360 */ 361 if (en == 1) { 362 if (rdy == 1) 363 return (0); 364 return (nvme_ctrlr_wait_for_ready(ctrlr, 1)); 365 } 366 367 /* EN == 0 already wait for RDY == 0 or timeout & fail */ 368 err = nvme_ctrlr_wait_for_ready(ctrlr, 0); 369 if (err != 0) 370 return (err); 371 372 nvme_mmio_write_8(ctrlr, asq, ctrlr->adminq.cmd_bus_addr); 373 nvme_mmio_write_8(ctrlr, acq, ctrlr->adminq.cpl_bus_addr); 374 375 /* acqs and asqs are 0-based. */ 376 qsize = ctrlr->adminq.num_entries - 1; 377 378 aqa = 0; 379 aqa = (qsize & NVME_AQA_REG_ACQS_MASK) << NVME_AQA_REG_ACQS_SHIFT; 380 aqa |= (qsize & NVME_AQA_REG_ASQS_MASK) << NVME_AQA_REG_ASQS_SHIFT; 381 nvme_mmio_write_4(ctrlr, aqa, aqa); 382 383 /* Initialization values for CC */ 384 cc = 0; 385 cc |= 1 << NVME_CC_REG_EN_SHIFT; 386 cc |= 0 << NVME_CC_REG_CSS_SHIFT; 387 cc |= 0 << NVME_CC_REG_AMS_SHIFT; 388 cc |= 0 << NVME_CC_REG_SHN_SHIFT; 389 cc |= 6 << NVME_CC_REG_IOSQES_SHIFT; /* SQ entry size == 64 == 2^6 */ 390 cc |= 4 << NVME_CC_REG_IOCQES_SHIFT; /* CQ entry size == 16 == 2^4 */ 391 392 /* 393 * Use the Memory Page Size selected during device initialization. Note 394 * that value stored in mps is suitable to use here without adjusting by 395 * NVME_MPS_SHIFT. 396 */ 397 cc |= ctrlr->mps << NVME_CC_REG_MPS_SHIFT; 398 399 nvme_ctrlr_barrier(ctrlr, BUS_SPACE_BARRIER_WRITE); 400 nvme_mmio_write_4(ctrlr, cc, cc); 401 402 return (nvme_ctrlr_wait_for_ready(ctrlr, 1)); 403 } 404 405 static void 406 nvme_ctrlr_disable_qpairs(struct nvme_controller *ctrlr) 407 { 408 int i; 409 410 nvme_admin_qpair_disable(&ctrlr->adminq); 411 /* 412 * I/O queues are not allocated before the initial HW 413 * reset, so do not try to disable them. Use is_initialized 414 * to determine if this is the initial HW reset. 415 */ 416 if (ctrlr->is_initialized) { 417 for (i = 0; i < ctrlr->num_io_queues; i++) 418 nvme_io_qpair_disable(&ctrlr->ioq[i]); 419 } 420 } 421 422 static int 423 nvme_ctrlr_hw_reset(struct nvme_controller *ctrlr) 424 { 425 int err; 426 427 TSENTER(); 428 429 nvme_ctrlr_disable_qpairs(ctrlr); 430 431 err = nvme_ctrlr_disable(ctrlr); 432 if (err != 0) 433 goto out; 434 435 err = nvme_ctrlr_enable(ctrlr); 436 out: 437 438 TSEXIT(); 439 return (err); 440 } 441 442 void 443 nvme_ctrlr_reset(struct nvme_controller *ctrlr) 444 { 445 int cmpset; 446 447 cmpset = atomic_cmpset_32(&ctrlr->is_resetting, 0, 1); 448 449 if (cmpset == 0 || ctrlr->is_failed) 450 /* 451 * Controller is already resetting or has failed. Return 452 * immediately since there is no need to kick off another 453 * reset in these cases. 454 */ 455 return; 456 457 if (!ctrlr->is_dying) 458 taskqueue_enqueue(ctrlr->taskqueue, &ctrlr->reset_task); 459 } 460 461 static int 462 nvme_ctrlr_identify(struct nvme_controller *ctrlr) 463 { 464 struct nvme_completion_poll_status status; 465 466 status.done = 0; 467 nvme_ctrlr_cmd_identify_controller(ctrlr, &ctrlr->cdata, 468 nvme_completion_poll_cb, &status); 469 nvme_completion_poll(&status); 470 if (nvme_completion_is_error(&status.cpl)) { 471 nvme_printf(ctrlr, "nvme_identify_controller failed!\n"); 472 return (ENXIO); 473 } 474 475 /* Convert data to host endian */ 476 nvme_controller_data_swapbytes(&ctrlr->cdata); 477 478 /* 479 * Use MDTS to ensure our default max_xfer_size doesn't exceed what the 480 * controller supports. 481 */ 482 if (ctrlr->cdata.mdts > 0) 483 ctrlr->max_xfer_size = min(ctrlr->max_xfer_size, 484 1 << (ctrlr->cdata.mdts + NVME_MPS_SHIFT + 485 NVME_CAP_HI_MPSMIN(ctrlr->cap_hi))); 486 487 return (0); 488 } 489 490 static int 491 nvme_ctrlr_set_num_qpairs(struct nvme_controller *ctrlr) 492 { 493 struct nvme_completion_poll_status status; 494 int cq_allocated, sq_allocated; 495 496 status.done = 0; 497 nvme_ctrlr_cmd_set_num_queues(ctrlr, ctrlr->num_io_queues, 498 nvme_completion_poll_cb, &status); 499 nvme_completion_poll(&status); 500 if (nvme_completion_is_error(&status.cpl)) { 501 nvme_printf(ctrlr, "nvme_ctrlr_set_num_qpairs failed!\n"); 502 return (ENXIO); 503 } 504 505 /* 506 * Data in cdw0 is 0-based. 507 * Lower 16-bits indicate number of submission queues allocated. 508 * Upper 16-bits indicate number of completion queues allocated. 509 */ 510 sq_allocated = (status.cpl.cdw0 & 0xFFFF) + 1; 511 cq_allocated = (status.cpl.cdw0 >> 16) + 1; 512 513 /* 514 * Controller may allocate more queues than we requested, 515 * so use the minimum of the number requested and what was 516 * actually allocated. 517 */ 518 ctrlr->num_io_queues = min(ctrlr->num_io_queues, sq_allocated); 519 ctrlr->num_io_queues = min(ctrlr->num_io_queues, cq_allocated); 520 if (ctrlr->num_io_queues > vm_ndomains) 521 ctrlr->num_io_queues -= ctrlr->num_io_queues % vm_ndomains; 522 523 return (0); 524 } 525 526 static int 527 nvme_ctrlr_create_qpairs(struct nvme_controller *ctrlr) 528 { 529 struct nvme_completion_poll_status status; 530 struct nvme_qpair *qpair; 531 int i; 532 533 for (i = 0; i < ctrlr->num_io_queues; i++) { 534 qpair = &ctrlr->ioq[i]; 535 536 status.done = 0; 537 nvme_ctrlr_cmd_create_io_cq(ctrlr, qpair, 538 nvme_completion_poll_cb, &status); 539 nvme_completion_poll(&status); 540 if (nvme_completion_is_error(&status.cpl)) { 541 nvme_printf(ctrlr, "nvme_create_io_cq failed!\n"); 542 return (ENXIO); 543 } 544 545 status.done = 0; 546 nvme_ctrlr_cmd_create_io_sq(ctrlr, qpair, 547 nvme_completion_poll_cb, &status); 548 nvme_completion_poll(&status); 549 if (nvme_completion_is_error(&status.cpl)) { 550 nvme_printf(ctrlr, "nvme_create_io_sq failed!\n"); 551 return (ENXIO); 552 } 553 } 554 555 return (0); 556 } 557 558 static int 559 nvme_ctrlr_delete_qpairs(struct nvme_controller *ctrlr) 560 { 561 struct nvme_completion_poll_status status; 562 struct nvme_qpair *qpair; 563 564 for (int i = 0; i < ctrlr->num_io_queues; i++) { 565 qpair = &ctrlr->ioq[i]; 566 567 status.done = 0; 568 nvme_ctrlr_cmd_delete_io_sq(ctrlr, qpair, 569 nvme_completion_poll_cb, &status); 570 nvme_completion_poll(&status); 571 if (nvme_completion_is_error(&status.cpl)) { 572 nvme_printf(ctrlr, "nvme_destroy_io_sq failed!\n"); 573 return (ENXIO); 574 } 575 576 status.done = 0; 577 nvme_ctrlr_cmd_delete_io_cq(ctrlr, qpair, 578 nvme_completion_poll_cb, &status); 579 nvme_completion_poll(&status); 580 if (nvme_completion_is_error(&status.cpl)) { 581 nvme_printf(ctrlr, "nvme_destroy_io_cq failed!\n"); 582 return (ENXIO); 583 } 584 } 585 586 return (0); 587 } 588 589 static int 590 nvme_ctrlr_construct_namespaces(struct nvme_controller *ctrlr) 591 { 592 struct nvme_namespace *ns; 593 uint32_t i; 594 595 for (i = 0; i < min(ctrlr->cdata.nn, NVME_MAX_NAMESPACES); i++) { 596 ns = &ctrlr->ns[i]; 597 nvme_ns_construct(ns, i+1, ctrlr); 598 } 599 600 return (0); 601 } 602 603 static bool 604 is_log_page_id_valid(uint8_t page_id) 605 { 606 607 switch (page_id) { 608 case NVME_LOG_ERROR: 609 case NVME_LOG_HEALTH_INFORMATION: 610 case NVME_LOG_FIRMWARE_SLOT: 611 case NVME_LOG_CHANGED_NAMESPACE: 612 case NVME_LOG_COMMAND_EFFECT: 613 case NVME_LOG_RES_NOTIFICATION: 614 case NVME_LOG_SANITIZE_STATUS: 615 return (true); 616 } 617 618 return (false); 619 } 620 621 static uint32_t 622 nvme_ctrlr_get_log_page_size(struct nvme_controller *ctrlr, uint8_t page_id) 623 { 624 uint32_t log_page_size; 625 626 switch (page_id) { 627 case NVME_LOG_ERROR: 628 log_page_size = min( 629 sizeof(struct nvme_error_information_entry) * 630 (ctrlr->cdata.elpe + 1), NVME_MAX_AER_LOG_SIZE); 631 break; 632 case NVME_LOG_HEALTH_INFORMATION: 633 log_page_size = sizeof(struct nvme_health_information_page); 634 break; 635 case NVME_LOG_FIRMWARE_SLOT: 636 log_page_size = sizeof(struct nvme_firmware_page); 637 break; 638 case NVME_LOG_CHANGED_NAMESPACE: 639 log_page_size = sizeof(struct nvme_ns_list); 640 break; 641 case NVME_LOG_COMMAND_EFFECT: 642 log_page_size = sizeof(struct nvme_command_effects_page); 643 break; 644 case NVME_LOG_RES_NOTIFICATION: 645 log_page_size = sizeof(struct nvme_res_notification_page); 646 break; 647 case NVME_LOG_SANITIZE_STATUS: 648 log_page_size = sizeof(struct nvme_sanitize_status_page); 649 break; 650 default: 651 log_page_size = 0; 652 break; 653 } 654 655 return (log_page_size); 656 } 657 658 static void 659 nvme_ctrlr_log_critical_warnings(struct nvme_controller *ctrlr, 660 uint8_t state) 661 { 662 663 if (state & NVME_CRIT_WARN_ST_AVAILABLE_SPARE) 664 nvme_ctrlr_devctl_log(ctrlr, "critical", 665 "available spare space below threshold"); 666 667 if (state & NVME_CRIT_WARN_ST_TEMPERATURE) 668 nvme_ctrlr_devctl_log(ctrlr, "critical", 669 "temperature above threshold"); 670 671 if (state & NVME_CRIT_WARN_ST_DEVICE_RELIABILITY) 672 nvme_ctrlr_devctl_log(ctrlr, "critical", 673 "device reliability degraded"); 674 675 if (state & NVME_CRIT_WARN_ST_READ_ONLY) 676 nvme_ctrlr_devctl_log(ctrlr, "critical", 677 "media placed in read only mode"); 678 679 if (state & NVME_CRIT_WARN_ST_VOLATILE_MEMORY_BACKUP) 680 nvme_ctrlr_devctl_log(ctrlr, "critical", 681 "volatile memory backup device failed"); 682 683 if (state & NVME_CRIT_WARN_ST_RESERVED_MASK) 684 nvme_ctrlr_devctl_log(ctrlr, "critical", 685 "unknown critical warning(s): state = 0x%02x", state); 686 } 687 688 static void 689 nvme_ctrlr_async_event_log_page_cb(void *arg, const struct nvme_completion *cpl) 690 { 691 struct nvme_async_event_request *aer = arg; 692 struct nvme_health_information_page *health_info; 693 struct nvme_ns_list *nsl; 694 struct nvme_error_information_entry *err; 695 int i; 696 697 /* 698 * If the log page fetch for some reason completed with an error, 699 * don't pass log page data to the consumers. In practice, this case 700 * should never happen. 701 */ 702 if (nvme_completion_is_error(cpl)) 703 nvme_notify_async_consumers(aer->ctrlr, &aer->cpl, 704 aer->log_page_id, NULL, 0); 705 else { 706 /* Convert data to host endian */ 707 switch (aer->log_page_id) { 708 case NVME_LOG_ERROR: 709 err = (struct nvme_error_information_entry *)aer->log_page_buffer; 710 for (i = 0; i < (aer->ctrlr->cdata.elpe + 1); i++) 711 nvme_error_information_entry_swapbytes(err++); 712 break; 713 case NVME_LOG_HEALTH_INFORMATION: 714 nvme_health_information_page_swapbytes( 715 (struct nvme_health_information_page *)aer->log_page_buffer); 716 break; 717 case NVME_LOG_CHANGED_NAMESPACE: 718 nvme_ns_list_swapbytes( 719 (struct nvme_ns_list *)aer->log_page_buffer); 720 break; 721 case NVME_LOG_COMMAND_EFFECT: 722 nvme_command_effects_page_swapbytes( 723 (struct nvme_command_effects_page *)aer->log_page_buffer); 724 break; 725 case NVME_LOG_RES_NOTIFICATION: 726 nvme_res_notification_page_swapbytes( 727 (struct nvme_res_notification_page *)aer->log_page_buffer); 728 break; 729 case NVME_LOG_SANITIZE_STATUS: 730 nvme_sanitize_status_page_swapbytes( 731 (struct nvme_sanitize_status_page *)aer->log_page_buffer); 732 break; 733 case INTEL_LOG_TEMP_STATS: 734 intel_log_temp_stats_swapbytes( 735 (struct intel_log_temp_stats *)aer->log_page_buffer); 736 break; 737 default: 738 break; 739 } 740 741 if (aer->log_page_id == NVME_LOG_HEALTH_INFORMATION) { 742 health_info = (struct nvme_health_information_page *) 743 aer->log_page_buffer; 744 nvme_ctrlr_log_critical_warnings(aer->ctrlr, 745 health_info->critical_warning); 746 /* 747 * Critical warnings reported through the 748 * SMART/health log page are persistent, so 749 * clear the associated bits in the async event 750 * config so that we do not receive repeated 751 * notifications for the same event. 752 */ 753 aer->ctrlr->async_event_config &= 754 ~health_info->critical_warning; 755 nvme_ctrlr_cmd_set_async_event_config(aer->ctrlr, 756 aer->ctrlr->async_event_config, NULL, NULL); 757 } else if (aer->log_page_id == NVME_LOG_CHANGED_NAMESPACE && 758 !nvme_use_nvd) { 759 nsl = (struct nvme_ns_list *)aer->log_page_buffer; 760 for (i = 0; i < nitems(nsl->ns) && nsl->ns[i] != 0; i++) { 761 if (nsl->ns[i] > NVME_MAX_NAMESPACES) 762 break; 763 nvme_notify_ns(aer->ctrlr, nsl->ns[i]); 764 } 765 } 766 767 /* 768 * Pass the cpl data from the original async event completion, 769 * not the log page fetch. 770 */ 771 nvme_notify_async_consumers(aer->ctrlr, &aer->cpl, 772 aer->log_page_id, aer->log_page_buffer, aer->log_page_size); 773 } 774 775 /* 776 * Repost another asynchronous event request to replace the one 777 * that just completed. 778 */ 779 nvme_ctrlr_construct_and_submit_aer(aer->ctrlr, aer); 780 } 781 782 static void 783 nvme_ctrlr_async_event_cb(void *arg, const struct nvme_completion *cpl) 784 { 785 struct nvme_async_event_request *aer = arg; 786 787 if (nvme_completion_is_error(cpl)) { 788 /* 789 * Do not retry failed async event requests. This avoids 790 * infinite loops where a new async event request is submitted 791 * to replace the one just failed, only to fail again and 792 * perpetuate the loop. 793 */ 794 return; 795 } 796 797 /* Associated log page is in bits 23:16 of completion entry dw0. */ 798 aer->log_page_id = (cpl->cdw0 & 0xFF0000) >> 16; 799 800 nvme_printf(aer->ctrlr, "async event occurred (type 0x%x, info 0x%02x," 801 " page 0x%02x)\n", (cpl->cdw0 & 0x07), (cpl->cdw0 & 0xFF00) >> 8, 802 aer->log_page_id); 803 804 if (is_log_page_id_valid(aer->log_page_id)) { 805 aer->log_page_size = nvme_ctrlr_get_log_page_size(aer->ctrlr, 806 aer->log_page_id); 807 memcpy(&aer->cpl, cpl, sizeof(*cpl)); 808 nvme_ctrlr_cmd_get_log_page(aer->ctrlr, aer->log_page_id, 809 NVME_GLOBAL_NAMESPACE_TAG, aer->log_page_buffer, 810 aer->log_page_size, nvme_ctrlr_async_event_log_page_cb, 811 aer); 812 /* Wait to notify consumers until after log page is fetched. */ 813 } else { 814 nvme_notify_async_consumers(aer->ctrlr, cpl, aer->log_page_id, 815 NULL, 0); 816 817 /* 818 * Repost another asynchronous event request to replace the one 819 * that just completed. 820 */ 821 nvme_ctrlr_construct_and_submit_aer(aer->ctrlr, aer); 822 } 823 } 824 825 static void 826 nvme_ctrlr_construct_and_submit_aer(struct nvme_controller *ctrlr, 827 struct nvme_async_event_request *aer) 828 { 829 struct nvme_request *req; 830 831 aer->ctrlr = ctrlr; 832 req = nvme_allocate_request_null(nvme_ctrlr_async_event_cb, aer); 833 aer->req = req; 834 835 /* 836 * Disable timeout here, since asynchronous event requests should by 837 * nature never be timed out. 838 */ 839 req->timeout = false; 840 req->cmd.opc = NVME_OPC_ASYNC_EVENT_REQUEST; 841 nvme_ctrlr_submit_admin_request(ctrlr, req); 842 } 843 844 static void 845 nvme_ctrlr_configure_aer(struct nvme_controller *ctrlr) 846 { 847 struct nvme_completion_poll_status status; 848 struct nvme_async_event_request *aer; 849 uint32_t i; 850 851 ctrlr->async_event_config = NVME_CRIT_WARN_ST_AVAILABLE_SPARE | 852 NVME_CRIT_WARN_ST_DEVICE_RELIABILITY | 853 NVME_CRIT_WARN_ST_READ_ONLY | 854 NVME_CRIT_WARN_ST_VOLATILE_MEMORY_BACKUP; 855 if (ctrlr->cdata.ver >= NVME_REV(1, 2)) 856 ctrlr->async_event_config |= NVME_ASYNC_EVENT_NS_ATTRIBUTE | 857 NVME_ASYNC_EVENT_FW_ACTIVATE; 858 859 status.done = 0; 860 nvme_ctrlr_cmd_get_feature(ctrlr, NVME_FEAT_TEMPERATURE_THRESHOLD, 861 0, NULL, 0, nvme_completion_poll_cb, &status); 862 nvme_completion_poll(&status); 863 if (nvme_completion_is_error(&status.cpl) || 864 (status.cpl.cdw0 & 0xFFFF) == 0xFFFF || 865 (status.cpl.cdw0 & 0xFFFF) == 0x0000) { 866 nvme_printf(ctrlr, "temperature threshold not supported\n"); 867 } else 868 ctrlr->async_event_config |= NVME_CRIT_WARN_ST_TEMPERATURE; 869 870 nvme_ctrlr_cmd_set_async_event_config(ctrlr, 871 ctrlr->async_event_config, NULL, NULL); 872 873 /* aerl is a zero-based value, so we need to add 1 here. */ 874 ctrlr->num_aers = min(NVME_MAX_ASYNC_EVENTS, (ctrlr->cdata.aerl+1)); 875 876 for (i = 0; i < ctrlr->num_aers; i++) { 877 aer = &ctrlr->aer[i]; 878 nvme_ctrlr_construct_and_submit_aer(ctrlr, aer); 879 } 880 } 881 882 static void 883 nvme_ctrlr_configure_int_coalescing(struct nvme_controller *ctrlr) 884 { 885 886 ctrlr->int_coal_time = 0; 887 TUNABLE_INT_FETCH("hw.nvme.int_coal_time", 888 &ctrlr->int_coal_time); 889 890 ctrlr->int_coal_threshold = 0; 891 TUNABLE_INT_FETCH("hw.nvme.int_coal_threshold", 892 &ctrlr->int_coal_threshold); 893 894 nvme_ctrlr_cmd_set_interrupt_coalescing(ctrlr, ctrlr->int_coal_time, 895 ctrlr->int_coal_threshold, NULL, NULL); 896 } 897 898 static void 899 nvme_ctrlr_hmb_free(struct nvme_controller *ctrlr) 900 { 901 struct nvme_hmb_chunk *hmbc; 902 int i; 903 904 if (ctrlr->hmb_desc_paddr) { 905 bus_dmamap_unload(ctrlr->hmb_desc_tag, ctrlr->hmb_desc_map); 906 bus_dmamem_free(ctrlr->hmb_desc_tag, ctrlr->hmb_desc_vaddr, 907 ctrlr->hmb_desc_map); 908 ctrlr->hmb_desc_paddr = 0; 909 } 910 if (ctrlr->hmb_desc_tag) { 911 bus_dma_tag_destroy(ctrlr->hmb_desc_tag); 912 ctrlr->hmb_desc_tag = NULL; 913 } 914 for (i = 0; i < ctrlr->hmb_nchunks; i++) { 915 hmbc = &ctrlr->hmb_chunks[i]; 916 bus_dmamap_unload(ctrlr->hmb_tag, hmbc->hmbc_map); 917 bus_dmamem_free(ctrlr->hmb_tag, hmbc->hmbc_vaddr, 918 hmbc->hmbc_map); 919 } 920 ctrlr->hmb_nchunks = 0; 921 if (ctrlr->hmb_tag) { 922 bus_dma_tag_destroy(ctrlr->hmb_tag); 923 ctrlr->hmb_tag = NULL; 924 } 925 if (ctrlr->hmb_chunks) { 926 free(ctrlr->hmb_chunks, M_NVME); 927 ctrlr->hmb_chunks = NULL; 928 } 929 } 930 931 static void 932 nvme_ctrlr_hmb_alloc(struct nvme_controller *ctrlr) 933 { 934 struct nvme_hmb_chunk *hmbc; 935 size_t pref, min, minc, size; 936 int err, i; 937 uint64_t max; 938 939 /* Limit HMB to 5% of RAM size per device by default. */ 940 max = (uint64_t)physmem * PAGE_SIZE / 20; 941 TUNABLE_UINT64_FETCH("hw.nvme.hmb_max", &max); 942 943 /* 944 * Units of Host Memory Buffer in the Identify info are always in terms 945 * of 4k units. 946 */ 947 min = (long long unsigned)ctrlr->cdata.hmmin * NVME_HMB_UNITS; 948 if (max == 0 || max < min) 949 return; 950 pref = MIN((long long unsigned)ctrlr->cdata.hmpre * NVME_HMB_UNITS, max); 951 minc = MAX(ctrlr->cdata.hmminds * NVME_HMB_UNITS, ctrlr->page_size); 952 if (min > 0 && ctrlr->cdata.hmmaxd > 0) 953 minc = MAX(minc, min / ctrlr->cdata.hmmaxd); 954 ctrlr->hmb_chunk = pref; 955 956 again: 957 /* 958 * However, the chunk sizes, number of chunks, and alignment of chunks 959 * are all based on the current MPS (ctrlr->page_size). 960 */ 961 ctrlr->hmb_chunk = roundup2(ctrlr->hmb_chunk, ctrlr->page_size); 962 ctrlr->hmb_nchunks = howmany(pref, ctrlr->hmb_chunk); 963 if (ctrlr->cdata.hmmaxd > 0 && ctrlr->hmb_nchunks > ctrlr->cdata.hmmaxd) 964 ctrlr->hmb_nchunks = ctrlr->cdata.hmmaxd; 965 ctrlr->hmb_chunks = malloc(sizeof(struct nvme_hmb_chunk) * 966 ctrlr->hmb_nchunks, M_NVME, M_WAITOK); 967 err = bus_dma_tag_create(bus_get_dma_tag(ctrlr->dev), 968 ctrlr->page_size, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, 969 ctrlr->hmb_chunk, 1, ctrlr->hmb_chunk, 0, NULL, NULL, &ctrlr->hmb_tag); 970 if (err != 0) { 971 nvme_printf(ctrlr, "HMB tag create failed %d\n", err); 972 nvme_ctrlr_hmb_free(ctrlr); 973 return; 974 } 975 976 for (i = 0; i < ctrlr->hmb_nchunks; i++) { 977 hmbc = &ctrlr->hmb_chunks[i]; 978 if (bus_dmamem_alloc(ctrlr->hmb_tag, 979 (void **)&hmbc->hmbc_vaddr, BUS_DMA_NOWAIT, 980 &hmbc->hmbc_map)) { 981 nvme_printf(ctrlr, "failed to alloc HMB\n"); 982 break; 983 } 984 if (bus_dmamap_load(ctrlr->hmb_tag, hmbc->hmbc_map, 985 hmbc->hmbc_vaddr, ctrlr->hmb_chunk, nvme_single_map, 986 &hmbc->hmbc_paddr, BUS_DMA_NOWAIT) != 0) { 987 bus_dmamem_free(ctrlr->hmb_tag, hmbc->hmbc_vaddr, 988 hmbc->hmbc_map); 989 nvme_printf(ctrlr, "failed to load HMB\n"); 990 break; 991 } 992 bus_dmamap_sync(ctrlr->hmb_tag, hmbc->hmbc_map, 993 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 994 } 995 996 if (i < ctrlr->hmb_nchunks && i * ctrlr->hmb_chunk < min && 997 ctrlr->hmb_chunk / 2 >= minc) { 998 ctrlr->hmb_nchunks = i; 999 nvme_ctrlr_hmb_free(ctrlr); 1000 ctrlr->hmb_chunk /= 2; 1001 goto again; 1002 } 1003 ctrlr->hmb_nchunks = i; 1004 if (ctrlr->hmb_nchunks * ctrlr->hmb_chunk < min) { 1005 nvme_ctrlr_hmb_free(ctrlr); 1006 return; 1007 } 1008 1009 size = sizeof(struct nvme_hmb_desc) * ctrlr->hmb_nchunks; 1010 err = bus_dma_tag_create(bus_get_dma_tag(ctrlr->dev), 1011 16, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, 1012 size, 1, size, 0, NULL, NULL, &ctrlr->hmb_desc_tag); 1013 if (err != 0) { 1014 nvme_printf(ctrlr, "HMB desc tag create failed %d\n", err); 1015 nvme_ctrlr_hmb_free(ctrlr); 1016 return; 1017 } 1018 if (bus_dmamem_alloc(ctrlr->hmb_desc_tag, 1019 (void **)&ctrlr->hmb_desc_vaddr, BUS_DMA_WAITOK, 1020 &ctrlr->hmb_desc_map)) { 1021 nvme_printf(ctrlr, "failed to alloc HMB desc\n"); 1022 nvme_ctrlr_hmb_free(ctrlr); 1023 return; 1024 } 1025 if (bus_dmamap_load(ctrlr->hmb_desc_tag, ctrlr->hmb_desc_map, 1026 ctrlr->hmb_desc_vaddr, size, nvme_single_map, 1027 &ctrlr->hmb_desc_paddr, BUS_DMA_NOWAIT) != 0) { 1028 bus_dmamem_free(ctrlr->hmb_desc_tag, ctrlr->hmb_desc_vaddr, 1029 ctrlr->hmb_desc_map); 1030 nvme_printf(ctrlr, "failed to load HMB desc\n"); 1031 nvme_ctrlr_hmb_free(ctrlr); 1032 return; 1033 } 1034 1035 for (i = 0; i < ctrlr->hmb_nchunks; i++) { 1036 memset(&ctrlr->hmb_desc_vaddr[i], 0, 1037 sizeof(struct nvme_hmb_desc)); 1038 ctrlr->hmb_desc_vaddr[i].addr = 1039 htole64(ctrlr->hmb_chunks[i].hmbc_paddr); 1040 ctrlr->hmb_desc_vaddr[i].size = htole32(ctrlr->hmb_chunk / ctrlr->page_size); 1041 } 1042 bus_dmamap_sync(ctrlr->hmb_desc_tag, ctrlr->hmb_desc_map, 1043 BUS_DMASYNC_PREWRITE); 1044 1045 nvme_printf(ctrlr, "Allocated %lluMB host memory buffer\n", 1046 (long long unsigned)ctrlr->hmb_nchunks * ctrlr->hmb_chunk 1047 / 1024 / 1024); 1048 } 1049 1050 static void 1051 nvme_ctrlr_hmb_enable(struct nvme_controller *ctrlr, bool enable, bool memret) 1052 { 1053 struct nvme_completion_poll_status status; 1054 uint32_t cdw11; 1055 1056 cdw11 = 0; 1057 if (enable) 1058 cdw11 |= 1; 1059 if (memret) 1060 cdw11 |= 2; 1061 status.done = 0; 1062 nvme_ctrlr_cmd_set_feature(ctrlr, NVME_FEAT_HOST_MEMORY_BUFFER, cdw11, 1063 ctrlr->hmb_nchunks * ctrlr->hmb_chunk / ctrlr->page_size, 1064 ctrlr->hmb_desc_paddr, ctrlr->hmb_desc_paddr >> 32, 1065 ctrlr->hmb_nchunks, NULL, 0, 1066 nvme_completion_poll_cb, &status); 1067 nvme_completion_poll(&status); 1068 if (nvme_completion_is_error(&status.cpl)) 1069 nvme_printf(ctrlr, "nvme_ctrlr_hmb_enable failed!\n"); 1070 } 1071 1072 static void 1073 nvme_ctrlr_start(void *ctrlr_arg, bool resetting) 1074 { 1075 struct nvme_controller *ctrlr = ctrlr_arg; 1076 uint32_t old_num_io_queues; 1077 int i; 1078 1079 TSENTER(); 1080 1081 /* 1082 * Only reset adminq here when we are restarting the 1083 * controller after a reset. During initialization, 1084 * we have already submitted admin commands to get 1085 * the number of I/O queues supported, so cannot reset 1086 * the adminq again here. 1087 */ 1088 if (resetting) { 1089 nvme_qpair_reset(&ctrlr->adminq); 1090 nvme_admin_qpair_enable(&ctrlr->adminq); 1091 } 1092 1093 if (ctrlr->ioq != NULL) { 1094 for (i = 0; i < ctrlr->num_io_queues; i++) 1095 nvme_qpair_reset(&ctrlr->ioq[i]); 1096 } 1097 1098 /* 1099 * If it was a reset on initialization command timeout, just 1100 * return here, letting initialization code fail gracefully. 1101 */ 1102 if (resetting && !ctrlr->is_initialized) 1103 return; 1104 1105 if (resetting && nvme_ctrlr_identify(ctrlr) != 0) { 1106 nvme_ctrlr_fail(ctrlr); 1107 return; 1108 } 1109 1110 /* 1111 * The number of qpairs are determined during controller initialization, 1112 * including using NVMe SET_FEATURES/NUMBER_OF_QUEUES to determine the 1113 * HW limit. We call SET_FEATURES again here so that it gets called 1114 * after any reset for controllers that depend on the driver to 1115 * explicit specify how many queues it will use. This value should 1116 * never change between resets, so panic if somehow that does happen. 1117 */ 1118 if (resetting) { 1119 old_num_io_queues = ctrlr->num_io_queues; 1120 if (nvme_ctrlr_set_num_qpairs(ctrlr) != 0) { 1121 nvme_ctrlr_fail(ctrlr); 1122 return; 1123 } 1124 1125 if (old_num_io_queues != ctrlr->num_io_queues) { 1126 panic("num_io_queues changed from %u to %u", 1127 old_num_io_queues, ctrlr->num_io_queues); 1128 } 1129 } 1130 1131 if (ctrlr->cdata.hmpre > 0 && ctrlr->hmb_nchunks == 0) { 1132 nvme_ctrlr_hmb_alloc(ctrlr); 1133 if (ctrlr->hmb_nchunks > 0) 1134 nvme_ctrlr_hmb_enable(ctrlr, true, false); 1135 } else if (ctrlr->hmb_nchunks > 0) 1136 nvme_ctrlr_hmb_enable(ctrlr, true, true); 1137 1138 if (nvme_ctrlr_create_qpairs(ctrlr) != 0) { 1139 nvme_ctrlr_fail(ctrlr); 1140 return; 1141 } 1142 1143 if (nvme_ctrlr_construct_namespaces(ctrlr) != 0) { 1144 nvme_ctrlr_fail(ctrlr); 1145 return; 1146 } 1147 1148 nvme_ctrlr_configure_aer(ctrlr); 1149 nvme_ctrlr_configure_int_coalescing(ctrlr); 1150 1151 for (i = 0; i < ctrlr->num_io_queues; i++) 1152 nvme_io_qpair_enable(&ctrlr->ioq[i]); 1153 TSEXIT(); 1154 } 1155 1156 void 1157 nvme_ctrlr_start_config_hook(void *arg) 1158 { 1159 struct nvme_controller *ctrlr = arg; 1160 1161 TSENTER(); 1162 1163 /* 1164 * Don't call pre/post reset here. We've not yet created the qpairs, 1165 * haven't setup the ISRs, so there's no need to 'drain' them or 1166 * 'exclude' them. 1167 */ 1168 if (nvme_ctrlr_hw_reset(ctrlr) != 0) { 1169 fail: 1170 nvme_ctrlr_fail(ctrlr); 1171 config_intrhook_disestablish(&ctrlr->config_hook); 1172 return; 1173 } 1174 1175 #ifdef NVME_2X_RESET 1176 /* 1177 * Reset controller twice to ensure we do a transition from cc.en==1 to 1178 * cc.en==0. This is because we don't really know what status the 1179 * controller was left in when boot handed off to OS. Linux doesn't do 1180 * this, however, and when the controller is in state cc.en == 0, no 1181 * I/O can happen. 1182 */ 1183 if (nvme_ctrlr_hw_reset(ctrlr) != 0) 1184 goto fail; 1185 #endif 1186 1187 nvme_qpair_reset(&ctrlr->adminq); 1188 nvme_admin_qpair_enable(&ctrlr->adminq); 1189 1190 if (nvme_ctrlr_identify(ctrlr) == 0 && 1191 nvme_ctrlr_set_num_qpairs(ctrlr) == 0 && 1192 nvme_ctrlr_construct_io_qpairs(ctrlr) == 0) 1193 nvme_ctrlr_start(ctrlr, false); 1194 else 1195 goto fail; 1196 1197 nvme_sysctl_initialize_ctrlr(ctrlr); 1198 config_intrhook_disestablish(&ctrlr->config_hook); 1199 1200 ctrlr->is_initialized = 1; 1201 nvme_notify_new_controller(ctrlr); 1202 TSEXIT(); 1203 } 1204 1205 static void 1206 nvme_ctrlr_reset_task(void *arg, int pending) 1207 { 1208 struct nvme_controller *ctrlr = arg; 1209 int status; 1210 1211 nvme_ctrlr_devctl_log(ctrlr, "RESET", "resetting controller"); 1212 status = nvme_ctrlr_hw_reset(ctrlr); 1213 if (status == 0) 1214 nvme_ctrlr_start(ctrlr, true); 1215 else 1216 nvme_ctrlr_fail(ctrlr); 1217 1218 atomic_cmpset_32(&ctrlr->is_resetting, 1, 0); 1219 } 1220 1221 /* 1222 * Poll all the queues enabled on the device for completion. 1223 */ 1224 void 1225 nvme_ctrlr_poll(struct nvme_controller *ctrlr) 1226 { 1227 int i; 1228 1229 nvme_qpair_process_completions(&ctrlr->adminq); 1230 1231 for (i = 0; i < ctrlr->num_io_queues; i++) 1232 if (ctrlr->ioq && ctrlr->ioq[i].cpl) 1233 nvme_qpair_process_completions(&ctrlr->ioq[i]); 1234 } 1235 1236 /* 1237 * Poll the single-vector interrupt case: num_io_queues will be 1 and 1238 * there's only a single vector. While we're polling, we mask further 1239 * interrupts in the controller. 1240 */ 1241 void 1242 nvme_ctrlr_shared_handler(void *arg) 1243 { 1244 struct nvme_controller *ctrlr = arg; 1245 1246 nvme_mmio_write_4(ctrlr, intms, 1); 1247 nvme_ctrlr_poll(ctrlr); 1248 nvme_mmio_write_4(ctrlr, intmc, 1); 1249 } 1250 1251 static void 1252 nvme_pt_done(void *arg, const struct nvme_completion *cpl) 1253 { 1254 struct nvme_pt_command *pt = arg; 1255 struct mtx *mtx = pt->driver_lock; 1256 uint16_t status; 1257 1258 bzero(&pt->cpl, sizeof(pt->cpl)); 1259 pt->cpl.cdw0 = cpl->cdw0; 1260 1261 status = cpl->status; 1262 status &= ~NVME_STATUS_P_MASK; 1263 pt->cpl.status = status; 1264 1265 mtx_lock(mtx); 1266 pt->driver_lock = NULL; 1267 wakeup(pt); 1268 mtx_unlock(mtx); 1269 } 1270 1271 int 1272 nvme_ctrlr_passthrough_cmd(struct nvme_controller *ctrlr, 1273 struct nvme_pt_command *pt, uint32_t nsid, int is_user_buffer, 1274 int is_admin_cmd) 1275 { 1276 struct nvme_request *req; 1277 struct mtx *mtx; 1278 struct buf *buf = NULL; 1279 int ret = 0; 1280 1281 if (pt->len > 0) { 1282 if (pt->len > ctrlr->max_xfer_size) { 1283 nvme_printf(ctrlr, "pt->len (%d) " 1284 "exceeds max_xfer_size (%d)\n", pt->len, 1285 ctrlr->max_xfer_size); 1286 return EIO; 1287 } 1288 if (is_user_buffer) { 1289 /* 1290 * Ensure the user buffer is wired for the duration of 1291 * this pass-through command. 1292 */ 1293 PHOLD(curproc); 1294 buf = uma_zalloc(pbuf_zone, M_WAITOK); 1295 buf->b_iocmd = pt->is_read ? BIO_READ : BIO_WRITE; 1296 if (vmapbuf(buf, pt->buf, pt->len, 1) < 0) { 1297 ret = EFAULT; 1298 goto err; 1299 } 1300 req = nvme_allocate_request_vaddr(buf->b_data, pt->len, 1301 nvme_pt_done, pt); 1302 } else 1303 req = nvme_allocate_request_vaddr(pt->buf, pt->len, 1304 nvme_pt_done, pt); 1305 } else 1306 req = nvme_allocate_request_null(nvme_pt_done, pt); 1307 1308 /* Assume user space already converted to little-endian */ 1309 req->cmd.opc = pt->cmd.opc; 1310 req->cmd.fuse = pt->cmd.fuse; 1311 req->cmd.rsvd2 = pt->cmd.rsvd2; 1312 req->cmd.rsvd3 = pt->cmd.rsvd3; 1313 req->cmd.cdw10 = pt->cmd.cdw10; 1314 req->cmd.cdw11 = pt->cmd.cdw11; 1315 req->cmd.cdw12 = pt->cmd.cdw12; 1316 req->cmd.cdw13 = pt->cmd.cdw13; 1317 req->cmd.cdw14 = pt->cmd.cdw14; 1318 req->cmd.cdw15 = pt->cmd.cdw15; 1319 1320 req->cmd.nsid = htole32(nsid); 1321 1322 mtx = mtx_pool_find(mtxpool_sleep, pt); 1323 pt->driver_lock = mtx; 1324 1325 if (is_admin_cmd) 1326 nvme_ctrlr_submit_admin_request(ctrlr, req); 1327 else 1328 nvme_ctrlr_submit_io_request(ctrlr, req); 1329 1330 mtx_lock(mtx); 1331 while (pt->driver_lock != NULL) 1332 mtx_sleep(pt, mtx, PRIBIO, "nvme_pt", 0); 1333 mtx_unlock(mtx); 1334 1335 if (buf != NULL) { 1336 vunmapbuf(buf); 1337 err: 1338 uma_zfree(pbuf_zone, buf); 1339 PRELE(curproc); 1340 } 1341 1342 return (ret); 1343 } 1344 1345 static int 1346 nvme_ctrlr_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag, 1347 struct thread *td) 1348 { 1349 struct nvme_controller *ctrlr; 1350 struct nvme_pt_command *pt; 1351 1352 ctrlr = cdev->si_drv1; 1353 1354 switch (cmd) { 1355 case NVME_RESET_CONTROLLER: 1356 nvme_ctrlr_reset(ctrlr); 1357 break; 1358 case NVME_PASSTHROUGH_CMD: 1359 pt = (struct nvme_pt_command *)arg; 1360 return (nvme_ctrlr_passthrough_cmd(ctrlr, pt, le32toh(pt->cmd.nsid), 1361 1 /* is_user_buffer */, 1 /* is_admin_cmd */)); 1362 case NVME_GET_NSID: 1363 { 1364 struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg; 1365 strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev), 1366 sizeof(gnsid->cdev)); 1367 gnsid->cdev[sizeof(gnsid->cdev) - 1] = '\0'; 1368 gnsid->nsid = 0; 1369 break; 1370 } 1371 case NVME_GET_MAX_XFER_SIZE: 1372 *(uint64_t *)arg = ctrlr->max_xfer_size; 1373 break; 1374 default: 1375 return (ENOTTY); 1376 } 1377 1378 return (0); 1379 } 1380 1381 static struct cdevsw nvme_ctrlr_cdevsw = { 1382 .d_version = D_VERSION, 1383 .d_flags = 0, 1384 .d_ioctl = nvme_ctrlr_ioctl 1385 }; 1386 1387 int 1388 nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev) 1389 { 1390 struct make_dev_args md_args; 1391 uint32_t cap_lo; 1392 uint32_t cap_hi; 1393 uint32_t to, vs, pmrcap; 1394 int status, timeout_period; 1395 1396 ctrlr->dev = dev; 1397 1398 mtx_init(&ctrlr->lock, "nvme ctrlr lock", NULL, MTX_DEF); 1399 if (bus_get_domain(dev, &ctrlr->domain) != 0) 1400 ctrlr->domain = 0; 1401 1402 ctrlr->cap_lo = cap_lo = nvme_mmio_read_4(ctrlr, cap_lo); 1403 if (bootverbose) { 1404 device_printf(dev, "CapLo: 0x%08x: MQES %u%s%s%s%s, TO %u\n", 1405 cap_lo, NVME_CAP_LO_MQES(cap_lo), 1406 NVME_CAP_LO_CQR(cap_lo) ? ", CQR" : "", 1407 NVME_CAP_LO_AMS(cap_lo) ? ", AMS" : "", 1408 (NVME_CAP_LO_AMS(cap_lo) & 0x1) ? " WRRwUPC" : "", 1409 (NVME_CAP_LO_AMS(cap_lo) & 0x2) ? " VS" : "", 1410 NVME_CAP_LO_TO(cap_lo)); 1411 } 1412 ctrlr->cap_hi = cap_hi = nvme_mmio_read_4(ctrlr, cap_hi); 1413 if (bootverbose) { 1414 device_printf(dev, "CapHi: 0x%08x: DSTRD %u%s, CSS %x%s, " 1415 "CPS %x, MPSMIN %u, MPSMAX %u%s%s%s%s%s\n", cap_hi, 1416 NVME_CAP_HI_DSTRD(cap_hi), 1417 NVME_CAP_HI_NSSRS(cap_hi) ? ", NSSRS" : "", 1418 NVME_CAP_HI_CSS(cap_hi), 1419 NVME_CAP_HI_BPS(cap_hi) ? ", BPS" : "", 1420 NVME_CAP_HI_CPS(cap_hi), 1421 NVME_CAP_HI_MPSMIN(cap_hi), 1422 NVME_CAP_HI_MPSMAX(cap_hi), 1423 NVME_CAP_HI_PMRS(cap_hi) ? ", PMRS" : "", 1424 NVME_CAP_HI_CMBS(cap_hi) ? ", CMBS" : "", 1425 NVME_CAP_HI_NSSS(cap_hi) ? ", NSSS" : "", 1426 NVME_CAP_HI_CRWMS(cap_hi) ? ", CRWMS" : "", 1427 NVME_CAP_HI_CRIMS(cap_hi) ? ", CRIMS" : ""); 1428 } 1429 if (bootverbose) { 1430 vs = nvme_mmio_read_4(ctrlr, vs); 1431 device_printf(dev, "Version: 0x%08x: %d.%d\n", vs, 1432 NVME_MAJOR(vs), NVME_MINOR(vs)); 1433 } 1434 if (bootverbose && NVME_CAP_HI_PMRS(cap_hi)) { 1435 pmrcap = nvme_mmio_read_4(ctrlr, pmrcap); 1436 device_printf(dev, "PMRCap: 0x%08x: BIR %u%s%s, PMRTU %u, " 1437 "PMRWBM %x, PMRTO %u%s\n", pmrcap, 1438 NVME_PMRCAP_BIR(pmrcap), 1439 NVME_PMRCAP_RDS(pmrcap) ? ", RDS" : "", 1440 NVME_PMRCAP_WDS(pmrcap) ? ", WDS" : "", 1441 NVME_PMRCAP_PMRTU(pmrcap), 1442 NVME_PMRCAP_PMRWBM(pmrcap), 1443 NVME_PMRCAP_PMRTO(pmrcap), 1444 NVME_PMRCAP_CMSS(pmrcap) ? ", CMSS" : ""); 1445 } 1446 1447 ctrlr->dstrd = NVME_CAP_HI_DSTRD(cap_hi) + 2; 1448 1449 ctrlr->mps = NVME_CAP_HI_MPSMIN(cap_hi); 1450 ctrlr->page_size = 1 << (NVME_MPS_SHIFT + ctrlr->mps); 1451 1452 /* Get ready timeout value from controller, in units of 500ms. */ 1453 to = NVME_CAP_LO_TO(cap_lo) + 1; 1454 ctrlr->ready_timeout_in_ms = to * 500; 1455 1456 timeout_period = NVME_ADMIN_TIMEOUT_PERIOD; 1457 TUNABLE_INT_FETCH("hw.nvme.admin_timeout_period", &timeout_period); 1458 timeout_period = min(timeout_period, NVME_MAX_TIMEOUT_PERIOD); 1459 timeout_period = max(timeout_period, NVME_MIN_TIMEOUT_PERIOD); 1460 ctrlr->admin_timeout_period = timeout_period; 1461 1462 timeout_period = NVME_DEFAULT_TIMEOUT_PERIOD; 1463 TUNABLE_INT_FETCH("hw.nvme.timeout_period", &timeout_period); 1464 timeout_period = min(timeout_period, NVME_MAX_TIMEOUT_PERIOD); 1465 timeout_period = max(timeout_period, NVME_MIN_TIMEOUT_PERIOD); 1466 ctrlr->timeout_period = timeout_period; 1467 1468 nvme_retry_count = NVME_DEFAULT_RETRY_COUNT; 1469 TUNABLE_INT_FETCH("hw.nvme.retry_count", &nvme_retry_count); 1470 1471 ctrlr->enable_aborts = 0; 1472 TUNABLE_INT_FETCH("hw.nvme.enable_aborts", &ctrlr->enable_aborts); 1473 1474 /* Cap transfers by the maximum addressable by page-sized PRP (4KB pages -> 2MB). */ 1475 ctrlr->max_xfer_size = MIN(maxphys, (ctrlr->page_size / 8 * ctrlr->page_size)); 1476 if (nvme_ctrlr_construct_admin_qpair(ctrlr) != 0) 1477 return (ENXIO); 1478 1479 /* 1480 * Create 2 threads for the taskqueue. The reset thread will block when 1481 * it detects that the controller has failed until all I/O has been 1482 * failed up the stack. The fail_req task needs to be able to run in 1483 * this case to finish the request failure for some cases. 1484 * 1485 * We could partially solve this race by draining the failed requeust 1486 * queue before proceding to free the sim, though nothing would stop 1487 * new I/O from coming in after we do that drain, but before we reach 1488 * cam_sim_free, so this big hammer is used instead. 1489 */ 1490 ctrlr->taskqueue = taskqueue_create("nvme_taskq", M_WAITOK, 1491 taskqueue_thread_enqueue, &ctrlr->taskqueue); 1492 taskqueue_start_threads(&ctrlr->taskqueue, 2, PI_DISK, "nvme taskq"); 1493 1494 ctrlr->is_resetting = 0; 1495 ctrlr->is_initialized = 0; 1496 ctrlr->notification_sent = 0; 1497 TASK_INIT(&ctrlr->reset_task, 0, nvme_ctrlr_reset_task, ctrlr); 1498 TASK_INIT(&ctrlr->fail_req_task, 0, nvme_ctrlr_fail_req_task, ctrlr); 1499 STAILQ_INIT(&ctrlr->fail_req); 1500 ctrlr->is_failed = false; 1501 1502 make_dev_args_init(&md_args); 1503 md_args.mda_devsw = &nvme_ctrlr_cdevsw; 1504 md_args.mda_uid = UID_ROOT; 1505 md_args.mda_gid = GID_WHEEL; 1506 md_args.mda_mode = 0600; 1507 md_args.mda_unit = device_get_unit(dev); 1508 md_args.mda_si_drv1 = (void *)ctrlr; 1509 status = make_dev_s(&md_args, &ctrlr->cdev, "nvme%d", 1510 device_get_unit(dev)); 1511 if (status != 0) 1512 return (ENXIO); 1513 1514 return (0); 1515 } 1516 1517 void 1518 nvme_ctrlr_destruct(struct nvme_controller *ctrlr, device_t dev) 1519 { 1520 int gone, i; 1521 1522 ctrlr->is_dying = true; 1523 1524 if (ctrlr->resource == NULL) 1525 goto nores; 1526 if (!mtx_initialized(&ctrlr->adminq.lock)) 1527 goto noadminq; 1528 1529 /* 1530 * Check whether it is a hot unplug or a clean driver detach. 1531 * If device is not there any more, skip any shutdown commands. 1532 */ 1533 gone = (nvme_mmio_read_4(ctrlr, csts) == NVME_GONE); 1534 if (gone) 1535 nvme_ctrlr_fail(ctrlr); 1536 else 1537 nvme_notify_fail_consumers(ctrlr); 1538 1539 for (i = 0; i < NVME_MAX_NAMESPACES; i++) 1540 nvme_ns_destruct(&ctrlr->ns[i]); 1541 1542 if (ctrlr->cdev) 1543 destroy_dev(ctrlr->cdev); 1544 1545 if (ctrlr->is_initialized) { 1546 if (!gone) { 1547 if (ctrlr->hmb_nchunks > 0) 1548 nvme_ctrlr_hmb_enable(ctrlr, false, false); 1549 nvme_ctrlr_delete_qpairs(ctrlr); 1550 } 1551 nvme_ctrlr_hmb_free(ctrlr); 1552 } 1553 if (ctrlr->ioq != NULL) { 1554 for (i = 0; i < ctrlr->num_io_queues; i++) 1555 nvme_io_qpair_destroy(&ctrlr->ioq[i]); 1556 free(ctrlr->ioq, M_NVME); 1557 } 1558 nvme_admin_qpair_destroy(&ctrlr->adminq); 1559 1560 /* 1561 * Notify the controller of a shutdown, even though this is due to 1562 * a driver unload, not a system shutdown (this path is not invoked 1563 * during shutdown). This ensures the controller receives a 1564 * shutdown notification in case the system is shutdown before 1565 * reloading the driver. 1566 */ 1567 if (!gone) 1568 nvme_ctrlr_shutdown(ctrlr); 1569 1570 if (!gone) 1571 nvme_ctrlr_disable(ctrlr); 1572 1573 noadminq: 1574 if (ctrlr->taskqueue) 1575 taskqueue_free(ctrlr->taskqueue); 1576 1577 if (ctrlr->tag) 1578 bus_teardown_intr(ctrlr->dev, ctrlr->res, ctrlr->tag); 1579 1580 if (ctrlr->res) 1581 bus_release_resource(ctrlr->dev, SYS_RES_IRQ, 1582 rman_get_rid(ctrlr->res), ctrlr->res); 1583 1584 if (ctrlr->bar4_resource != NULL) { 1585 bus_release_resource(dev, SYS_RES_MEMORY, 1586 ctrlr->bar4_resource_id, ctrlr->bar4_resource); 1587 } 1588 1589 bus_release_resource(dev, SYS_RES_MEMORY, 1590 ctrlr->resource_id, ctrlr->resource); 1591 1592 nores: 1593 mtx_destroy(&ctrlr->lock); 1594 } 1595 1596 void 1597 nvme_ctrlr_shutdown(struct nvme_controller *ctrlr) 1598 { 1599 uint32_t cc; 1600 uint32_t csts; 1601 int timeout; 1602 1603 cc = nvme_mmio_read_4(ctrlr, cc); 1604 cc &= ~(NVME_CC_REG_SHN_MASK << NVME_CC_REG_SHN_SHIFT); 1605 cc |= NVME_SHN_NORMAL << NVME_CC_REG_SHN_SHIFT; 1606 nvme_mmio_write_4(ctrlr, cc, cc); 1607 1608 timeout = ticks + (ctrlr->cdata.rtd3e == 0 ? 5 * hz : 1609 ((uint64_t)ctrlr->cdata.rtd3e * hz + 999999) / 1000000); 1610 while (1) { 1611 csts = nvme_mmio_read_4(ctrlr, csts); 1612 if (csts == NVME_GONE) /* Hot unplug. */ 1613 break; 1614 if (NVME_CSTS_GET_SHST(csts) == NVME_SHST_COMPLETE) 1615 break; 1616 if (timeout - ticks < 0) { 1617 nvme_printf(ctrlr, "shutdown timeout\n"); 1618 break; 1619 } 1620 pause("nvmeshut", 1); 1621 } 1622 } 1623 1624 void 1625 nvme_ctrlr_submit_admin_request(struct nvme_controller *ctrlr, 1626 struct nvme_request *req) 1627 { 1628 1629 nvme_qpair_submit_request(&ctrlr->adminq, req); 1630 } 1631 1632 void 1633 nvme_ctrlr_submit_io_request(struct nvme_controller *ctrlr, 1634 struct nvme_request *req) 1635 { 1636 struct nvme_qpair *qpair; 1637 1638 qpair = &ctrlr->ioq[QP(ctrlr, curcpu)]; 1639 nvme_qpair_submit_request(qpair, req); 1640 } 1641 1642 device_t 1643 nvme_ctrlr_get_device(struct nvme_controller *ctrlr) 1644 { 1645 1646 return (ctrlr->dev); 1647 } 1648 1649 const struct nvme_controller_data * 1650 nvme_ctrlr_get_data(struct nvme_controller *ctrlr) 1651 { 1652 1653 return (&ctrlr->cdata); 1654 } 1655 1656 int 1657 nvme_ctrlr_suspend(struct nvme_controller *ctrlr) 1658 { 1659 int to = hz; 1660 1661 /* 1662 * Can't touch failed controllers, so it's already suspended. 1663 */ 1664 if (ctrlr->is_failed) 1665 return (0); 1666 1667 /* 1668 * We don't want the reset taskqueue running, since it does similar 1669 * things, so prevent it from running after we start. Wait for any reset 1670 * that may have been started to complete. The reset process we follow 1671 * will ensure that any new I/O will queue and be given to the hardware 1672 * after we resume (though there should be none). 1673 */ 1674 while (atomic_cmpset_32(&ctrlr->is_resetting, 0, 1) == 0 && to-- > 0) 1675 pause("nvmesusp", 1); 1676 if (to <= 0) { 1677 nvme_printf(ctrlr, 1678 "Competing reset task didn't finish. Try again later.\n"); 1679 return (EWOULDBLOCK); 1680 } 1681 1682 if (ctrlr->hmb_nchunks > 0) 1683 nvme_ctrlr_hmb_enable(ctrlr, false, false); 1684 1685 /* 1686 * Per Section 7.6.2 of NVMe spec 1.4, to properly suspend, we need to 1687 * delete the hardware I/O queues, and then shutdown. This properly 1688 * flushes any metadata the drive may have stored so it can survive 1689 * having its power removed and prevents the unsafe shutdown count from 1690 * incriminating. Once we delete the qpairs, we have to disable them 1691 * before shutting down. 1692 */ 1693 nvme_ctrlr_delete_qpairs(ctrlr); 1694 nvme_ctrlr_disable_qpairs(ctrlr); 1695 nvme_ctrlr_shutdown(ctrlr); 1696 1697 return (0); 1698 } 1699 1700 int 1701 nvme_ctrlr_resume(struct nvme_controller *ctrlr) 1702 { 1703 1704 /* 1705 * Can't touch failed controllers, so nothing to do to resume. 1706 */ 1707 if (ctrlr->is_failed) 1708 return (0); 1709 1710 if (nvme_ctrlr_hw_reset(ctrlr) != 0) 1711 goto fail; 1712 1713 /* 1714 * Now that we've reset the hardware, we can restart the controller. Any 1715 * I/O that was pending is requeued. Any admin commands are aborted with 1716 * an error. Once we've restarted, take the controller out of reset. 1717 */ 1718 nvme_ctrlr_start(ctrlr, true); 1719 (void)atomic_cmpset_32(&ctrlr->is_resetting, 1, 0); 1720 1721 return (0); 1722 fail: 1723 /* 1724 * Since we can't bring the controller out of reset, announce and fail 1725 * the controller. However, we have to return success for the resume 1726 * itself, due to questionable APIs. 1727 */ 1728 nvme_printf(ctrlr, "Failed to reset on resume, failing.\n"); 1729 nvme_ctrlr_fail(ctrlr); 1730 (void)atomic_cmpset_32(&ctrlr->is_resetting, 1, 0); 1731 return (0); 1732 } 1733