Lines Matching +full:battery +full:- +full:profile

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2011-2014, Intel Corporation.
8 #include <linux/blk-mq.h>
9 #include <linux/blk-integrity.h>
16 #include <linux/backing-dev.h>
27 #include <linux/nvme-auth.h>
92 * nvme_wq - hosts nvme related works that are not reset or delete
93 * nvme_reset_wq - hosts nvme reset works
94 * nvme_delete_wq - hosts nvme delete works
97 * keep-alive, periodic reconnects etc. nvme_reset_wq
134 if (ctrl->state == NVME_CTRL_LIVE && ctrl->tagset) in nvme_queue_scan()
135 queue_work(nvme_wq, &ctrl->scan_work); in nvme_queue_scan()
146 if (ctrl->state != NVME_CTRL_RESETTING) in nvme_try_sched_reset()
147 return -EBUSY; in nvme_try_sched_reset()
148 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_try_sched_reset()
149 return -EBUSY; in nvme_try_sched_reset()
159 if (ctrl->state != NVME_CTRL_CONNECTING) in nvme_failfast_work()
162 set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_failfast_work()
163 dev_info(ctrl->device, "failfast expired\n"); in nvme_failfast_work()
169 if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) in nvme_start_failfast_work()
172 schedule_delayed_work(&ctrl->failfast_work, in nvme_start_failfast_work()
173 ctrl->opts->fast_io_fail_tmo * HZ); in nvme_start_failfast_work()
178 if (!ctrl->opts) in nvme_stop_failfast_work()
181 cancel_delayed_work_sync(&ctrl->failfast_work); in nvme_stop_failfast_work()
182 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_stop_failfast_work()
189 return -EBUSY; in nvme_reset_ctrl()
190 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_reset_ctrl()
191 return -EBUSY; in nvme_reset_ctrl()
202 flush_work(&ctrl->reset_work); in nvme_reset_ctrl_sync()
203 if (ctrl->state != NVME_CTRL_LIVE) in nvme_reset_ctrl_sync()
204 ret = -ENETRESET; in nvme_reset_ctrl_sync()
212 dev_info(ctrl->device, in nvme_do_delete_ctrl()
215 flush_work(&ctrl->reset_work); in nvme_do_delete_ctrl()
218 ctrl->ops->delete_ctrl(ctrl); in nvme_do_delete_ctrl()
233 return -EBUSY; in nvme_delete_ctrl()
234 if (!queue_work(nvme_delete_wq, &ctrl->delete_work)) in nvme_delete_ctrl()
235 return -EBUSY; in nvme_delete_ctrl()
244 * since ->delete_ctrl can free the controller. in nvme_delete_ctrl_sync()
300 crd = (nvme_req(req)->status & NVME_SC_CRD) >> 11; in nvme_retry_req()
302 delay = nvme_req(req)->ctrl->crdt[crd - 1] * 100; in nvme_retry_req()
304 nvme_req(req)->retries++; in nvme_retry_req()
306 blk_mq_delay_kick_requeue_list(req->q, delay); in nvme_retry_req()
311 struct nvme_ns *ns = req->q->queuedata; in nvme_log_error()
316 ns->disk ? ns->disk->disk_name : "?", in nvme_log_error()
317 nvme_get_opcode_str(nr->cmd->common.opcode), in nvme_log_error()
318 nr->cmd->common.opcode, in nvme_log_error()
320 (unsigned long long)blk_rq_bytes(req) >> ns->lba_shift, in nvme_log_error()
321 nvme_get_error_status_str(nr->status), in nvme_log_error()
322 nr->status >> 8 & 7, /* Status Code Type */ in nvme_log_error()
323 nr->status & 0xff, /* Status Code */ in nvme_log_error()
324 nr->status & NVME_SC_MORE ? "MORE " : "", in nvme_log_error()
325 nr->status & NVME_SC_DNR ? "DNR " : ""); in nvme_log_error()
330 dev_name(nr->ctrl->device), in nvme_log_error()
331 nvme_get_admin_opcode_str(nr->cmd->common.opcode), in nvme_log_error()
332 nr->cmd->common.opcode, in nvme_log_error()
333 nvme_get_error_status_str(nr->status), in nvme_log_error()
334 nr->status >> 8 & 7, /* Status Code Type */ in nvme_log_error()
335 nr->status & 0xff, /* Status Code */ in nvme_log_error()
336 nr->status & NVME_SC_MORE ? "MORE " : "", in nvme_log_error()
337 nr->status & NVME_SC_DNR ? "DNR " : ""); in nvme_log_error()
349 if (likely(nvme_req(req)->status == 0)) in nvme_decide_disposition()
352 if ((nvme_req(req)->status & 0x7ff) == NVME_SC_AUTH_REQUIRED) in nvme_decide_disposition()
356 (nvme_req(req)->status & NVME_SC_DNR) || in nvme_decide_disposition()
357 nvme_req(req)->retries >= nvme_max_retries) in nvme_decide_disposition()
360 if (req->cmd_flags & REQ_NVME_MPATH) { in nvme_decide_disposition()
361 if (nvme_is_path_error(nvme_req(req)->status) || in nvme_decide_disposition()
362 blk_queue_dying(req->q)) in nvme_decide_disposition()
365 if (blk_queue_dying(req->q)) in nvme_decide_disposition()
376 req->__sector = nvme_lba_to_sect(req->q->queuedata, in nvme_end_req_zoned()
377 le64_to_cpu(nvme_req(req)->result.u64)); in nvme_end_req_zoned()
382 blk_status_t status = nvme_error_status(nvme_req(req)->status); in nvme_end_req()
384 if (unlikely(nvme_req(req)->status && !(req->rq_flags & RQF_QUIET))) in nvme_end_req()
388 if (req->cmd_flags & REQ_NVME_MPATH) in nvme_end_req()
395 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_complete_rq()
401 * Completions of long-running commands should not be able to in nvme_complete_rq()
405 * req->deadline - req->timeout is the command submission time in nvme_complete_rq()
408 if (ctrl->kas && in nvme_complete_rq()
409 req->deadline - req->timeout >= ctrl->ka_last_check_time) in nvme_complete_rq()
410 ctrl->comp_seen = true; in nvme_complete_rq()
424 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_complete_rq()
443 * Called to unwind from ->queue_rq on a failed command submission so that the
450 nvme_req(req)->status = NVME_SC_HOST_PATH_ERROR; in nvme_host_path_error()
459 dev_dbg_ratelimited(((struct nvme_ctrl *) data)->device, in nvme_cancel_request()
460 "Cancelling I/O %d", req->tag); in nvme_cancel_request()
466 nvme_req(req)->status = NVME_SC_HOST_ABORTED_CMD; in nvme_cancel_request()
467 nvme_req(req)->flags |= NVME_REQ_CANCELLED; in nvme_cancel_request()
475 if (ctrl->tagset) { in nvme_cancel_tagset()
476 blk_mq_tagset_busy_iter(ctrl->tagset, in nvme_cancel_tagset()
478 blk_mq_tagset_wait_completed_request(ctrl->tagset); in nvme_cancel_tagset()
485 if (ctrl->admin_tagset) { in nvme_cancel_admin_tagset()
486 blk_mq_tagset_busy_iter(ctrl->admin_tagset, in nvme_cancel_admin_tagset()
488 blk_mq_tagset_wait_completed_request(ctrl->admin_tagset); in nvme_cancel_admin_tagset()
500 spin_lock_irqsave(&ctrl->lock, flags); in nvme_change_ctrl_state()
502 old_state = ctrl->state; in nvme_change_ctrl_state()
570 ctrl->state = new_state; in nvme_change_ctrl_state()
571 wake_up_all(&ctrl->state_wq); in nvme_change_ctrl_state()
574 spin_unlock_irqrestore(&ctrl->lock, flags); in nvme_change_ctrl_state()
578 if (ctrl->state == NVME_CTRL_LIVE) { in nvme_change_ctrl_state()
582 } else if (ctrl->state == NVME_CTRL_CONNECTING && in nvme_change_ctrl_state()
595 switch (ctrl->state) { in nvme_state_terminal()
606 WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state); in nvme_state_terminal()
617 wait_event(ctrl->state_wq, in nvme_wait_reset()
620 return ctrl->state == NVME_CTRL_RESETTING; in nvme_wait_reset()
630 ida_free(&head->subsys->ns_ida, head->instance); in nvme_free_ns_head()
631 cleanup_srcu_struct(&head->srcu); in nvme_free_ns_head()
632 nvme_put_subsystem(head->subsys); in nvme_free_ns_head()
638 return kref_get_unless_zero(&head->ref); in nvme_tryget_ns_head()
643 kref_put(&head->ref, nvme_free_ns_head); in nvme_put_ns_head()
650 put_disk(ns->disk); in nvme_free_ns()
651 nvme_put_ns_head(ns->head); in nvme_free_ns()
652 nvme_put_ctrl(ns->ctrl); in nvme_free_ns()
658 return kref_get_unless_zero(&ns->kref); in nvme_get_ns()
663 kref_put(&ns->kref, nvme_free_ns); in nvme_put_ns()
669 nvme_req(req)->status = 0; in nvme_clear_nvme_request()
670 nvme_req(req)->retries = 0; in nvme_clear_nvme_request()
671 nvme_req(req)->flags = 0; in nvme_clear_nvme_request()
672 req->rq_flags |= RQF_DONTPREP; in nvme_clear_nvme_request()
678 if (req->q->queuedata) in nvme_init_request()
679 req->timeout = NVME_IO_TIMEOUT; in nvme_init_request()
681 req->timeout = NVME_ADMIN_TIMEOUT; in nvme_init_request()
684 cmd->common.flags &= ~NVME_CMD_SGL_ALL; in nvme_init_request()
686 req->cmd_flags |= REQ_FAILFAST_DRIVER; in nvme_init_request()
687 if (req->mq_hctx->type == HCTX_TYPE_POLL) in nvme_init_request()
688 req->cmd_flags |= REQ_POLLED; in nvme_init_request()
690 req->rq_flags |= RQF_QUIET; in nvme_init_request()
691 memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd)); in nvme_init_request()
707 if (ctrl->state != NVME_CTRL_DELETING_NOIO && in nvme_fail_nonready_command()
708 ctrl->state != NVME_CTRL_DELETING && in nvme_fail_nonready_command()
709 ctrl->state != NVME_CTRL_DEAD && in nvme_fail_nonready_command()
710 !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) && in nvme_fail_nonready_command()
711 !blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH)) in nvme_fail_nonready_command()
730 if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD)) in __nvme_check_ready()
733 if (ctrl->ops->flags & NVME_F_FABRICS) { in __nvme_check_ready()
739 switch (ctrl->state) { in __nvme_check_ready()
741 if (blk_rq_is_passthrough(rq) && nvme_is_fabrics(req->cmd) && in __nvme_check_ready()
742 (req->cmd->fabrics.fctype == nvme_fabrics_type_connect || in __nvme_check_ready()
743 req->cmd->fabrics.fctype == nvme_fabrics_type_auth_send || in __nvme_check_ready()
744 req->cmd->fabrics.fctype == nvme_fabrics_type_auth_receive)) in __nvme_check_ready()
762 cmnd->common.opcode = nvme_cmd_flush; in nvme_setup_flush()
763 cmnd->common.nsid = cpu_to_le32(ns->head->ns_id); in nvme_setup_flush()
787 if (test_and_set_bit_lock(0, &ns->ctrl->discard_page_busy)) in nvme_setup_discard()
790 range = page_address(ns->ctrl->discard_page); in nvme_setup_discard()
793 if (queue_max_discard_segments(req->q) == 1) { in nvme_setup_discard()
795 u32 nlb = blk_rq_sectors(req) >> (ns->lba_shift - 9); in nvme_setup_discard()
803 u64 slba = nvme_sect_to_lba(ns, bio->bi_iter.bi_sector); in nvme_setup_discard()
804 u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift; in nvme_setup_discard()
816 if (virt_to_page(range) == ns->ctrl->discard_page) in nvme_setup_discard()
817 clear_bit_unlock(0, &ns->ctrl->discard_page_busy); in nvme_setup_discard()
824 cmnd->dsm.opcode = nvme_cmd_dsm; in nvme_setup_discard()
825 cmnd->dsm.nsid = cpu_to_le32(ns->head->ns_id); in nvme_setup_discard()
826 cmnd->dsm.nr = cpu_to_le32(segments - 1); in nvme_setup_discard()
827 cmnd->dsm.attributes = cpu_to_le32(NVME_DSMGMT_AD); in nvme_setup_discard()
829 bvec_set_virt(&req->special_vec, range, alloc_size); in nvme_setup_discard()
830 req->rq_flags |= RQF_SPECIAL_PAYLOAD; in nvme_setup_discard()
842 switch (ns->guard_type) { in nvme_set_ref_tag()
844 cmnd->rw.reftag = cpu_to_le32(t10_pi_ref_tag(req)); in nvme_set_ref_tag()
851 cmnd->rw.reftag = cpu_to_le32(lower); in nvme_set_ref_tag()
852 cmnd->rw.cdw3 = cpu_to_le32(upper); in nvme_set_ref_tag()
864 if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_setup_write_zeroes()
867 cmnd->write_zeroes.opcode = nvme_cmd_write_zeroes; in nvme_setup_write_zeroes()
868 cmnd->write_zeroes.nsid = cpu_to_le32(ns->head->ns_id); in nvme_setup_write_zeroes()
869 cmnd->write_zeroes.slba = in nvme_setup_write_zeroes()
871 cmnd->write_zeroes.length = in nvme_setup_write_zeroes()
872 cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); in nvme_setup_write_zeroes()
874 if (!(req->cmd_flags & REQ_NOUNMAP) && (ns->features & NVME_NS_DEAC)) in nvme_setup_write_zeroes()
875 cmnd->write_zeroes.control |= cpu_to_le16(NVME_WZ_DEAC); in nvme_setup_write_zeroes()
878 cmnd->write_zeroes.control |= cpu_to_le16(NVME_RW_PRINFO_PRACT); in nvme_setup_write_zeroes()
880 switch (ns->pi_type) { in nvme_setup_write_zeroes()
898 if (req->cmd_flags & REQ_FUA) in nvme_setup_rw()
900 if (req->cmd_flags & (REQ_FAILFAST_DEV | REQ_RAHEAD)) in nvme_setup_rw()
903 if (req->cmd_flags & REQ_RAHEAD) in nvme_setup_rw()
906 cmnd->rw.opcode = op; in nvme_setup_rw()
907 cmnd->rw.flags = 0; in nvme_setup_rw()
908 cmnd->rw.nsid = cpu_to_le32(ns->head->ns_id); in nvme_setup_rw()
909 cmnd->rw.cdw2 = 0; in nvme_setup_rw()
910 cmnd->rw.cdw3 = 0; in nvme_setup_rw()
911 cmnd->rw.metadata = 0; in nvme_setup_rw()
912 cmnd->rw.slba = cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); in nvme_setup_rw()
913 cmnd->rw.length = cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); in nvme_setup_rw()
914 cmnd->rw.reftag = 0; in nvme_setup_rw()
915 cmnd->rw.apptag = 0; in nvme_setup_rw()
916 cmnd->rw.appmask = 0; in nvme_setup_rw()
918 if (ns->ms) { in nvme_setup_rw()
931 switch (ns->pi_type) { in nvme_setup_rw()
946 cmnd->rw.control = cpu_to_le16(control); in nvme_setup_rw()
947 cmnd->rw.dsmgmt = cpu_to_le32(dsmgmt); in nvme_setup_rw()
953 if (req->rq_flags & RQF_SPECIAL_PAYLOAD) { in nvme_cleanup_cmd()
954 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_cleanup_cmd()
956 if (req->special_vec.bv_page == ctrl->discard_page) in nvme_cleanup_cmd()
957 clear_bit_unlock(0, &ctrl->discard_page_busy); in nvme_cleanup_cmd()
959 kfree(bvec_virt(&req->special_vec)); in nvme_cleanup_cmd()
966 struct nvme_command *cmd = nvme_req(req)->cmd; in nvme_setup_cmd()
969 if (!(req->rq_flags & RQF_DONTPREP)) in nvme_setup_cmd()
1013 cmd->common.command_id = nvme_cid(req); in nvme_setup_cmd()
1030 if (nvme_req(rq)->flags & NVME_REQ_CANCELLED) in nvme_execute_rq()
1031 return -EINTR; in nvme_execute_rq()
1032 if (nvme_req(rq)->status) in nvme_execute_rq()
1033 return nvme_req(rq)->status; in nvme_execute_rq()
1053 qid - 1); in __nvme_submit_sync_cmd()
1067 *result = nvme_req(req)->result; in __nvme_submit_sync_cmd()
1087 effects = le32_to_cpu(ns->head->effects->iocs[opcode]); in nvme_command_effects()
1089 dev_warn_once(ctrl->device, in nvme_command_effects()
1100 effects = le32_to_cpu(ctrl->effects->acs[opcode]); in nvme_command_effects()
1116 mutex_lock(&ctrl->scan_lock); in nvme_passthru_start()
1117 mutex_lock(&ctrl->subsys->lock); in nvme_passthru_start()
1118 nvme_mpath_start_freeze(ctrl->subsys); in nvme_passthru_start()
1119 nvme_mpath_wait_freeze(ctrl->subsys); in nvme_passthru_start()
1132 nvme_mpath_unfreeze(ctrl->subsys); in nvme_passthru_end()
1133 mutex_unlock(&ctrl->subsys->lock); in nvme_passthru_end()
1134 mutex_unlock(&ctrl->scan_lock); in nvme_passthru_end()
1138 &ctrl->flags)) { in nvme_passthru_end()
1139 dev_info(ctrl->device, in nvme_passthru_end()
1145 flush_work(&ctrl->scan_work); in nvme_passthru_end()
1150 switch (cmd->common.opcode) { in nvme_passthru_end()
1152 switch (le32_to_cpu(cmd->common.cdw10) & 0xFF) { in nvme_passthru_end()
1180 unsigned long delay = ctrl->kato * HZ / 2; in nvme_keep_alive_work_period()
1188 if (ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) in nvme_keep_alive_work_period()
1195 queue_delayed_work(nvme_wq, &ctrl->ka_work, in nvme_queue_keep_alive_work()
1202 struct nvme_ctrl *ctrl = rq->end_io_data; in nvme_keep_alive_end_io()
1205 unsigned long rtt = jiffies - (rq->deadline - rq->timeout); in nvme_keep_alive_end_io()
1213 delay -= rtt; in nvme_keep_alive_end_io()
1215 dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n", in nvme_keep_alive_end_io()
1223 dev_err(ctrl->device, in nvme_keep_alive_end_io()
1229 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_end_io()
1230 ctrl->comp_seen = false; in nvme_keep_alive_end_io()
1231 spin_lock_irqsave(&ctrl->lock, flags); in nvme_keep_alive_end_io()
1232 if (ctrl->state == NVME_CTRL_LIVE || in nvme_keep_alive_end_io()
1233 ctrl->state == NVME_CTRL_CONNECTING) in nvme_keep_alive_end_io()
1235 spin_unlock_irqrestore(&ctrl->lock, flags); in nvme_keep_alive_end_io()
1237 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_keep_alive_end_io()
1245 bool comp_seen = ctrl->comp_seen; in nvme_keep_alive_work()
1248 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_work()
1250 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { in nvme_keep_alive_work()
1251 dev_dbg(ctrl->device, in nvme_keep_alive_work()
1252 "reschedule traffic based keep-alive timer\n"); in nvme_keep_alive_work()
1253 ctrl->comp_seen = false; in nvme_keep_alive_work()
1258 rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd), in nvme_keep_alive_work()
1262 dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq)); in nvme_keep_alive_work()
1266 nvme_init_request(rq, &ctrl->ka_cmd); in nvme_keep_alive_work()
1268 rq->timeout = ctrl->kato * HZ; in nvme_keep_alive_work()
1269 rq->end_io = nvme_keep_alive_end_io; in nvme_keep_alive_work()
1270 rq->end_io_data = ctrl; in nvme_keep_alive_work()
1276 if (unlikely(ctrl->kato == 0)) in nvme_start_keep_alive()
1284 if (unlikely(ctrl->kato == 0)) in nvme_stop_keep_alive()
1287 cancel_delayed_work_sync(&ctrl->ka_work); in nvme_stop_keep_alive()
1295 DIV_ROUND_UP(le32_to_cpu(cmd->common.cdw11), 1000); in nvme_update_keep_alive()
1297 dev_info(ctrl->device, in nvme_update_keep_alive()
1299 ctrl->kato * 1000 / 2, new_kato * 1000 / 2); in nvme_update_keep_alive()
1302 ctrl->kato = new_kato; in nvme_update_keep_alive()
1314 if (ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS) in nvme_ctrl_limited_cns()
1315 return ctrl->vs < NVME_VS(1, 2, 0); in nvme_ctrl_limited_cns()
1316 return ctrl->vs < NVME_VS(1, 1, 0); in nvme_ctrl_limited_cns()
1324 /* gcc-4.4.4 (at least) has issues with initializers and anon unions */ in nvme_identify_ctrl()
1330 return -ENOMEM; in nvme_identify_ctrl()
1332 error = nvme_submit_sync_cmd(dev->admin_q, &c, *id, in nvme_identify_ctrl()
1345 switch (cur->nidt) { in nvme_process_ns_desc()
1347 if (cur->nidl != NVME_NIDT_EUI64_LEN) { in nvme_process_ns_desc()
1348 dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n", in nvme_process_ns_desc()
1349 warn_str, cur->nidl); in nvme_process_ns_desc()
1350 return -1; in nvme_process_ns_desc()
1352 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1354 memcpy(ids->eui64, data + sizeof(*cur), NVME_NIDT_EUI64_LEN); in nvme_process_ns_desc()
1357 if (cur->nidl != NVME_NIDT_NGUID_LEN) { in nvme_process_ns_desc()
1358 dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n", in nvme_process_ns_desc()
1359 warn_str, cur->nidl); in nvme_process_ns_desc()
1360 return -1; in nvme_process_ns_desc()
1362 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1364 memcpy(ids->nguid, data + sizeof(*cur), NVME_NIDT_NGUID_LEN); in nvme_process_ns_desc()
1367 if (cur->nidl != NVME_NIDT_UUID_LEN) { in nvme_process_ns_desc()
1368 dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n", in nvme_process_ns_desc()
1369 warn_str, cur->nidl); in nvme_process_ns_desc()
1370 return -1; in nvme_process_ns_desc()
1372 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1374 uuid_copy(&ids->uuid, data + sizeof(*cur)); in nvme_process_ns_desc()
1377 if (cur->nidl != NVME_NIDT_CSI_LEN) { in nvme_process_ns_desc()
1378 dev_warn(ctrl->device, "%s %d for NVME_NIDT_CSI\n", in nvme_process_ns_desc()
1379 warn_str, cur->nidl); in nvme_process_ns_desc()
1380 return -1; in nvme_process_ns_desc()
1382 memcpy(&ids->csi, data + sizeof(*cur), NVME_NIDT_CSI_LEN); in nvme_process_ns_desc()
1387 return cur->nidl; in nvme_process_ns_desc()
1399 if (ctrl->vs < NVME_VS(1, 3, 0) && !nvme_multi_css(ctrl)) in nvme_identify_ns_descs()
1401 if (ctrl->quirks & NVME_QUIRK_NO_NS_DESC_LIST) in nvme_identify_ns_descs()
1405 c.identify.nsid = cpu_to_le32(info->nsid); in nvme_identify_ns_descs()
1410 return -ENOMEM; in nvme_identify_ns_descs()
1412 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data, in nvme_identify_ns_descs()
1415 dev_warn(ctrl->device, in nvme_identify_ns_descs()
1417 info->nsid, status); in nvme_identify_ns_descs()
1424 if (cur->nidl == 0) in nvme_identify_ns_descs()
1427 len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); in nvme_identify_ns_descs()
1435 dev_warn(ctrl->device, "Command set not reported for nsid:%d\n", in nvme_identify_ns_descs()
1436 info->nsid); in nvme_identify_ns_descs()
1437 status = -EINVAL; in nvme_identify_ns_descs()
1451 /* gcc-4.4.4 (at least) has issues with initializers and anon unions */ in nvme_identify_ns()
1458 return -ENOMEM; in nvme_identify_ns()
1460 error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id)); in nvme_identify_ns()
1462 dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error); in nvme_identify_ns()
1471 struct nvme_ns_ids *ids = &info->ids; in nvme_ns_info_from_identify()
1475 ret = nvme_identify_ns(ctrl, info->nsid, &id); in nvme_ns_info_from_identify()
1479 if (id->ncap == 0) { in nvme_ns_info_from_identify()
1481 info->is_removed = true; in nvme_ns_info_from_identify()
1482 return -ENODEV; in nvme_ns_info_from_identify()
1485 info->anagrpid = id->anagrpid; in nvme_ns_info_from_identify()
1486 info->is_shared = id->nmic & NVME_NS_NMIC_SHARED; in nvme_ns_info_from_identify()
1487 info->is_readonly = id->nsattr & NVME_NS_ATTR_RO; in nvme_ns_info_from_identify()
1488 info->is_ready = true; in nvme_ns_info_from_identify()
1489 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) { in nvme_ns_info_from_identify()
1490 dev_info(ctrl->device, in nvme_ns_info_from_identify()
1493 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_ns_info_from_identify()
1494 !memchr_inv(ids->eui64, 0, sizeof(ids->eui64))) in nvme_ns_info_from_identify()
1495 memcpy(ids->eui64, id->eui64, sizeof(ids->eui64)); in nvme_ns_info_from_identify()
1496 if (ctrl->vs >= NVME_VS(1, 2, 0) && in nvme_ns_info_from_identify()
1497 !memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) in nvme_ns_info_from_identify()
1498 memcpy(ids->nguid, id->nguid, sizeof(ids->nguid)); in nvme_ns_info_from_identify()
1510 .identify.nsid = cpu_to_le32(info->nsid), in nvme_ns_info_from_id_cs_indep()
1517 return -ENOMEM; in nvme_ns_info_from_id_cs_indep()
1519 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_ns_info_from_id_cs_indep()
1521 info->anagrpid = id->anagrpid; in nvme_ns_info_from_id_cs_indep()
1522 info->is_shared = id->nmic & NVME_NS_NMIC_SHARED; in nvme_ns_info_from_id_cs_indep()
1523 info->is_readonly = id->nsattr & NVME_NS_ATTR_RO; in nvme_ns_info_from_id_cs_indep()
1524 info->is_ready = id->nstat & NVME_NSTAT_NRDY; in nvme_ns_info_from_id_cs_indep()
1541 ret = __nvme_submit_sync_cmd(dev->admin_q, &c, &res, in nvme_features()
1568 u32 q_count = (*count - 1) | ((*count - 1) << 16); in nvme_set_queue_count()
1583 dev_err(ctrl->device, "Could not set queue count (%d)\n", status); in nvme_set_queue_count()
1600 u32 result, supported_aens = ctrl->oaes & NVME_AEN_SUPPORTED; in nvme_enable_aen()
1609 dev_warn(ctrl->device, "Failed to configure AEN (cfg %x)\n", in nvme_enable_aen()
1612 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_enable_aen()
1619 if (WARN_ON_ONCE(nvme_ns_head_multipath(ns->head))) in nvme_ns_open()
1623 if (!try_module_get(ns->ctrl->ops->module)) in nvme_ns_open()
1631 return -ENXIO; in nvme_ns_open()
1637 module_put(ns->ctrl->ops->module); in nvme_ns_release()
1643 return nvme_ns_open(disk->private_data); in nvme_open()
1648 nvme_ns_release(disk->private_data); in nvme_release()
1654 geo->heads = 1 << 6; in nvme_getgeo()
1655 geo->sectors = 1 << 5; in nvme_getgeo()
1656 geo->cylinders = get_capacity(bdev->bd_disk) >> 11; in nvme_getgeo()
1666 switch (ns->pi_type) { in nvme_init_integrity()
1668 switch (ns->guard_type) { in nvme_init_integrity()
1670 integrity.profile = &t10_pi_type3_crc; in nvme_init_integrity()
1675 integrity.profile = &ext_pi_type3_crc64; in nvme_init_integrity()
1680 integrity.profile = NULL; in nvme_init_integrity()
1686 switch (ns->guard_type) { in nvme_init_integrity()
1688 integrity.profile = &t10_pi_type1_crc; in nvme_init_integrity()
1693 integrity.profile = &ext_pi_type1_crc64; in nvme_init_integrity()
1698 integrity.profile = NULL; in nvme_init_integrity()
1703 integrity.profile = NULL; in nvme_init_integrity()
1707 integrity.tuple_size = ns->ms; in nvme_init_integrity()
1709 blk_queue_max_integrity_segments(disk->queue, max_integrity_segments); in nvme_init_integrity()
1720 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_config_discard()
1721 struct request_queue *queue = disk->queue; in nvme_config_discard()
1724 if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns, UINT_MAX)) in nvme_config_discard()
1725 ctrl->max_discard_sectors = nvme_lba_to_sect(ns, ctrl->dmrsl); in nvme_config_discard()
1727 if (ctrl->max_discard_sectors == 0) { in nvme_config_discard()
1735 queue->limits.discard_granularity = size; in nvme_config_discard()
1738 if (queue->limits.max_discard_sectors) in nvme_config_discard()
1741 blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors); in nvme_config_discard()
1742 blk_queue_max_discard_segments(queue, ctrl->max_discard_segments); in nvme_config_discard()
1744 if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_config_discard()
1750 return uuid_equal(&a->uuid, &b->uuid) && in nvme_ns_ids_equal()
1751 memcmp(&a->nguid, &b->nguid, sizeof(a->nguid)) == 0 && in nvme_ns_ids_equal()
1752 memcmp(&a->eui64, &b->eui64, sizeof(a->eui64)) == 0 && in nvme_ns_ids_equal()
1753 a->csi == b->csi; in nvme_ns_ids_equal()
1758 bool first = id->dps & NVME_NS_DPS_PI_FIRST; in nvme_init_ms()
1759 unsigned lbaf = nvme_lbaf_index(id->flbas); in nvme_init_ms()
1760 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ms()
1766 ns->pi_size = 0; in nvme_init_ms()
1767 ns->ms = le16_to_cpu(id->lbaf[lbaf].ms); in nvme_init_ms()
1768 if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { in nvme_init_ms()
1769 ns->pi_size = sizeof(struct t10_pi_tuple); in nvme_init_ms()
1770 ns->guard_type = NVME_NVM_NS_16B_GUARD; in nvme_init_ms()
1776 return -ENOMEM; in nvme_init_ms()
1779 c.identify.nsid = cpu_to_le32(ns->head->ns_id); in nvme_init_ms()
1783 ret = nvme_submit_sync_cmd(ns->ctrl->admin_q, &c, nvm, sizeof(*nvm)); in nvme_init_ms()
1787 elbaf = le32_to_cpu(nvm->elbaf[lbaf]); in nvme_init_ms()
1793 ns->guard_type = nvme_elbaf_guard_type(elbaf); in nvme_init_ms()
1794 switch (ns->guard_type) { in nvme_init_ms()
1796 ns->pi_size = sizeof(struct crc64_pi_tuple); in nvme_init_ms()
1799 ns->pi_size = sizeof(struct t10_pi_tuple); in nvme_init_ms()
1808 if (ns->pi_size && (first || ns->ms == ns->pi_size)) in nvme_init_ms()
1809 ns->pi_type = id->dps & NVME_NS_DPS_PI_MASK; in nvme_init_ms()
1811 ns->pi_type = 0; in nvme_init_ms()
1818 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_configure_metadata()
1823 ns->features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS); in nvme_configure_metadata()
1824 if (!ns->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) in nvme_configure_metadata()
1827 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_configure_metadata()
1833 if (WARN_ON_ONCE(!(id->flbas & NVME_NS_FLBAS_META_EXT))) in nvme_configure_metadata()
1836 ns->features |= NVME_NS_EXT_LBAS; in nvme_configure_metadata()
1847 if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)) in nvme_configure_metadata()
1848 ns->features |= NVME_NS_METADATA_SUPPORTED; in nvme_configure_metadata()
1856 if (id->flbas & NVME_NS_FLBAS_META_EXT) in nvme_configure_metadata()
1857 ns->features |= NVME_NS_EXT_LBAS; in nvme_configure_metadata()
1859 ns->features |= NVME_NS_METADATA_SUPPORTED; in nvme_configure_metadata()
1866 bool vwc = ctrl->vwc & NVME_CTRL_VWC_PRESENT; in nvme_set_queue_limits()
1868 if (ctrl->max_hw_sectors) { in nvme_set_queue_limits()
1870 (ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> 9)) + 1; in nvme_set_queue_limits()
1872 max_segments = min_not_zero(max_segments, ctrl->max_segments); in nvme_set_queue_limits()
1873 blk_queue_max_hw_sectors(q, ctrl->max_hw_sectors); in nvme_set_queue_limits()
1876 blk_queue_virt_boundary(q, NVME_CTRL_PAGE_SIZE - 1); in nvme_set_queue_limits()
1884 sector_t capacity = nvme_lba_to_sect(ns, le64_to_cpu(id->nsze)); in nvme_update_disk_info()
1885 u32 bs = 1U << ns->lba_shift; in nvme_update_disk_info()
1892 if (ns->lba_shift > PAGE_SHIFT) { in nvme_update_disk_info()
1900 if (id->nabo == 0) { in nvme_update_disk_info()
1906 if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) in nvme_update_disk_info()
1907 atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs; in nvme_update_disk_info()
1909 atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; in nvme_update_disk_info()
1912 if (id->nsfeat & NVME_NS_FEAT_IO_OPT) { in nvme_update_disk_info()
1914 phys_bs = bs * (1 + le16_to_cpu(id->npwg)); in nvme_update_disk_info()
1916 io_opt = bs * (1 + le16_to_cpu(id->nows)); in nvme_update_disk_info()
1919 blk_queue_logical_block_size(disk->queue, bs); in nvme_update_disk_info()
1925 blk_queue_physical_block_size(disk->queue, min(phys_bs, atomic_bs)); in nvme_update_disk_info()
1926 blk_queue_io_min(disk->queue, phys_bs); in nvme_update_disk_info()
1927 blk_queue_io_opt(disk->queue, io_opt); in nvme_update_disk_info()
1930 * Register a metadata profile for PI, or the plain non-integrity NVMe in nvme_update_disk_info()
1935 if (ns->ms) { in nvme_update_disk_info()
1937 (ns->features & NVME_NS_METADATA_SUPPORTED)) in nvme_update_disk_info()
1939 ns->ctrl->max_integrity_segments); in nvme_update_disk_info()
1947 blk_queue_max_write_zeroes_sectors(disk->queue, in nvme_update_disk_info()
1948 ns->ctrl->max_zeroes_sectors); in nvme_update_disk_info()
1953 return info->is_readonly || test_bit(NVME_NS_FORCE_RO, &ns->flags); in nvme_ns_is_readonly()
1964 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_set_chunk_sectors()
1967 if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) && in nvme_set_chunk_sectors()
1968 is_power_of_2(ctrl->max_hw_sectors)) in nvme_set_chunk_sectors()
1969 iob = ctrl->max_hw_sectors; in nvme_set_chunk_sectors()
1971 iob = nvme_lba_to_sect(ns, le16_to_cpu(id->noiob)); in nvme_set_chunk_sectors()
1977 if (nvme_first_scan(ns->disk)) in nvme_set_chunk_sectors()
1979 ns->disk->disk_name, iob); in nvme_set_chunk_sectors()
1983 if (blk_queue_is_zoned(ns->disk->queue)) { in nvme_set_chunk_sectors()
1984 if (nvme_first_scan(ns->disk)) in nvme_set_chunk_sectors()
1986 ns->disk->disk_name); in nvme_set_chunk_sectors()
1990 blk_queue_chunk_sectors(ns->queue, iob); in nvme_set_chunk_sectors()
1996 blk_mq_freeze_queue(ns->disk->queue); in nvme_update_ns_info_generic()
1997 nvme_set_queue_limits(ns->ctrl, ns->queue); in nvme_update_ns_info_generic()
1998 set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info)); in nvme_update_ns_info_generic()
1999 blk_mq_unfreeze_queue(ns->disk->queue); in nvme_update_ns_info_generic()
2001 if (nvme_ns_head_multipath(ns->head)) { in nvme_update_ns_info_generic()
2002 blk_mq_freeze_queue(ns->head->disk->queue); in nvme_update_ns_info_generic()
2003 set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info)); in nvme_update_ns_info_generic()
2005 blk_stack_limits(&ns->head->disk->queue->limits, in nvme_update_ns_info_generic()
2006 &ns->queue->limits, 0); in nvme_update_ns_info_generic()
2007 ns->head->disk->flags |= GENHD_FL_HIDDEN; in nvme_update_ns_info_generic()
2008 blk_mq_unfreeze_queue(ns->head->disk->queue); in nvme_update_ns_info_generic()
2011 /* Hide the block-interface for these devices */ in nvme_update_ns_info_generic()
2012 ns->disk->flags |= GENHD_FL_HIDDEN; in nvme_update_ns_info_generic()
2013 set_bit(NVME_NS_READY, &ns->flags); in nvme_update_ns_info_generic()
2025 ret = nvme_identify_ns(ns->ctrl, info->nsid, &id); in nvme_update_ns_info_block()
2029 blk_mq_freeze_queue(ns->disk->queue); in nvme_update_ns_info_block()
2030 lbaf = nvme_lbaf_index(id->flbas); in nvme_update_ns_info_block()
2031 ns->lba_shift = id->lbaf[lbaf].ds; in nvme_update_ns_info_block()
2032 nvme_set_queue_limits(ns->ctrl, ns->queue); in nvme_update_ns_info_block()
2036 nvme_update_disk_info(ns->disk, ns, id); in nvme_update_ns_info_block()
2038 if (ns->head->ids.csi == NVME_CSI_ZNS) { in nvme_update_ns_info_block()
2041 blk_mq_unfreeze_queue(ns->disk->queue); in nvme_update_ns_info_block()
2049 * require that, it must be a no-op if reads from deallocated data in nvme_update_ns_info_block()
2052 if ((id->dlfeat & 0x7) == 0x1 && (id->dlfeat & (1 << 3))) in nvme_update_ns_info_block()
2053 ns->features |= NVME_NS_DEAC; in nvme_update_ns_info_block()
2054 set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info)); in nvme_update_ns_info_block()
2055 set_bit(NVME_NS_READY, &ns->flags); in nvme_update_ns_info_block()
2056 blk_mq_unfreeze_queue(ns->disk->queue); in nvme_update_ns_info_block()
2058 if (blk_queue_is_zoned(ns->queue)) { in nvme_update_ns_info_block()
2060 if (ret && !nvme_first_scan(ns->disk)) in nvme_update_ns_info_block()
2064 if (nvme_ns_head_multipath(ns->head)) { in nvme_update_ns_info_block()
2065 blk_mq_freeze_queue(ns->head->disk->queue); in nvme_update_ns_info_block()
2066 nvme_update_disk_info(ns->head->disk, ns, id); in nvme_update_ns_info_block()
2067 set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info)); in nvme_update_ns_info_block()
2069 blk_stack_limits(&ns->head->disk->queue->limits, in nvme_update_ns_info_block()
2070 &ns->queue->limits, 0); in nvme_update_ns_info_block()
2071 disk_update_readahead(ns->head->disk); in nvme_update_ns_info_block()
2072 blk_mq_unfreeze_queue(ns->head->disk->queue); in nvme_update_ns_info_block()
2081 if (ret == -ENODEV) { in nvme_update_ns_info_block()
2082 ns->disk->flags |= GENHD_FL_HIDDEN; in nvme_update_ns_info_block()
2083 set_bit(NVME_NS_READY, &ns->flags); in nvme_update_ns_info_block()
2092 switch (info->ids.csi) { in nvme_update_ns_info()
2095 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2097 info->nsid); in nvme_update_ns_info()
2104 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2106 info->nsid, info->ids.csi); in nvme_update_ns_info()
2126 return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len, in nvme_sec_submit()
2132 if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) { in nvme_configure_opal()
2133 if (!ctrl->opal_dev) in nvme_configure_opal()
2134 ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit); in nvme_configure_opal()
2136 opal_unlock_from_suspend(ctrl->opal_dev); in nvme_configure_opal()
2138 free_opal_dev(ctrl->opal_dev); in nvme_configure_opal()
2139 ctrl->opal_dev = NULL; in nvme_configure_opal()
2152 return nvme_ns_report_zones(disk->private_data, sector, nr_zones, cb, in nvme_report_zones()
2177 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_wait_ready()
2179 return -ENODEV; in nvme_wait_ready()
2185 return -EINTR; in nvme_wait_ready()
2187 dev_err(ctrl->device, in nvme_wait_ready()
2190 return -ENODEV; in nvme_wait_ready()
2201 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_disable_ctrl()
2203 ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; in nvme_disable_ctrl()
2205 ctrl->ctrl_config &= ~NVME_CC_ENABLE; in nvme_disable_ctrl()
2207 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_disable_ctrl()
2214 ctrl->shutdown_timeout, "shutdown"); in nvme_disable_ctrl()
2216 if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY) in nvme_disable_ctrl()
2219 (NVME_CAP_TIMEOUT(ctrl->cap) + 1) / 2, "reset"); in nvme_disable_ctrl()
2229 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2231 dev_err(ctrl->device, "Reading CAP failed (%d)\n", ret); in nvme_enable_ctrl()
2234 dev_page_min = NVME_CAP_MPSMIN(ctrl->cap) + 12; in nvme_enable_ctrl()
2237 dev_err(ctrl->device, in nvme_enable_ctrl()
2240 return -ENODEV; in nvme_enable_ctrl()
2243 if (NVME_CAP_CSS(ctrl->cap) & NVME_CAP_CSS_CSI) in nvme_enable_ctrl()
2244 ctrl->ctrl_config = NVME_CC_CSS_CSI; in nvme_enable_ctrl()
2246 ctrl->ctrl_config = NVME_CC_CSS_NVM; in nvme_enable_ctrl()
2248 if (ctrl->cap & NVME_CAP_CRMS_CRWMS && ctrl->cap & NVME_CAP_CRMS_CRIMS) in nvme_enable_ctrl()
2249 ctrl->ctrl_config |= NVME_CC_CRIME; in nvme_enable_ctrl()
2251 ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT; in nvme_enable_ctrl()
2252 ctrl->ctrl_config |= NVME_CC_AMS_RR | NVME_CC_SHN_NONE; in nvme_enable_ctrl()
2253 ctrl->ctrl_config |= NVME_CC_IOSQES | NVME_CC_IOCQES; in nvme_enable_ctrl()
2254 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2259 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CC, &ctrl->ctrl_config); in nvme_enable_ctrl()
2264 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2268 timeout = NVME_CAP_TIMEOUT(ctrl->cap); in nvme_enable_ctrl()
2269 if (ctrl->cap & NVME_CAP_CRMS_CRWMS) { in nvme_enable_ctrl()
2272 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CRTO, &crto); in nvme_enable_ctrl()
2274 dev_err(ctrl->device, "Reading CRTO failed (%d)\n", in nvme_enable_ctrl()
2284 if (ctrl->ctrl_config & NVME_CC_CRIME) in nvme_enable_ctrl()
2290 dev_warn_once(ctrl->device, "bad crto:%x cap:%llx\n", in nvme_enable_ctrl()
2291 crto, ctrl->cap); in nvme_enable_ctrl()
2296 ctrl->ctrl_config |= NVME_CC_ENABLE; in nvme_enable_ctrl()
2297 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2310 if (!(ctrl->oncs & NVME_CTRL_ONCS_TIMESTAMP)) in nvme_configure_timestamp()
2317 dev_warn_once(ctrl->device, in nvme_configure_timestamp()
2329 if (ctrl->crdt[0]) in nvme_configure_host_options()
2331 if (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) in nvme_configure_host_options()
2341 host->acre = acre; in nvme_configure_host_options()
2342 host->lbafee = lbafee; in nvme_configure_host_options()
2384 * - If the parameters provide explicit timeouts and tolerances, they will be
2385 * used to build a table with up to 2 non-operational states to transition to.
2389 * and battery power, the timeouts and tolerances reflect a compromise
2390 * between values used by Microsoft for AC and battery scenarios.
2391 * - If not, we'll configure the table with a simple heuristic: we are willing
2394 * lower-power non-operational state after waiting 50 * (enlat + exlat)
2398 * We will not autonomously enter any non-operational state for which the total
2409 int max_ps = -1; in nvme_configure_apst()
2418 if (!ctrl->apsta) in nvme_configure_apst()
2421 if (ctrl->npss > 31) { in nvme_configure_apst()
2422 dev_warn(ctrl->device, "NPSS is invalid; not using APST\n"); in nvme_configure_apst()
2430 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) { in nvme_configure_apst()
2432 dev_dbg(ctrl->device, "APST disabled\n"); in nvme_configure_apst()
2437 * Walk through all states from lowest- to highest-power. in nvme_configure_apst()
2438 * According to the spec, lower-numbered states use more power. NPSS, in nvme_configure_apst()
2439 * despite the name, is the index of the lowest-power state, not the in nvme_configure_apst()
2442 for (state = (int)ctrl->npss; state >= 0; state--) { in nvme_configure_apst()
2446 table->entries[state] = target; in nvme_configure_apst()
2452 if (state == ctrl->npss && in nvme_configure_apst()
2453 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) in nvme_configure_apst()
2457 * Is this state a useful non-operational state for higher-power in nvme_configure_apst()
2460 if (!(ctrl->psd[state].flags & NVME_PS_FLAGS_NON_OP_STATE)) in nvme_configure_apst()
2463 exit_latency_us = (u64)le32_to_cpu(ctrl->psd[state].exit_lat); in nvme_configure_apst()
2464 if (exit_latency_us > ctrl->ps_max_latency_us) in nvme_configure_apst()
2468 le32_to_cpu(ctrl->psd[state].entry_lat); in nvme_configure_apst()
2481 if (transition_ms > (1 << 24) - 1) in nvme_configure_apst()
2482 transition_ms = (1 << 24) - 1; in nvme_configure_apst()
2486 if (max_ps == -1) in nvme_configure_apst()
2492 if (max_ps == -1) in nvme_configure_apst()
2493 dev_dbg(ctrl->device, "APST enabled but no non-operational states are available\n"); in nvme_configure_apst()
2495 …dev_dbg(ctrl->device, "APST enabled: max PS = %d, max round-trip latency = %lluus, table = %*phN\n… in nvme_configure_apst()
2503 dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret); in nvme_configure_apst()
2523 if (ctrl->ps_max_latency_us != latency) { in nvme_set_latency_tolerance()
2524 ctrl->ps_max_latency_us = latency; in nvme_set_latency_tolerance()
2525 if (ctrl->state == NVME_CTRL_LIVE) in nvme_set_latency_tolerance()
2554 * This LiteON CL1-3D*-Q11 firmware version has a race
2564 * This Kioxia CD6-V Series / HPE PE8030 device times out and
2569 * to use "nvme set-feature" to disable APST, but booting with
2592 /* match is null-terminated but idstr is space-padded. */
2616 return q->vid == le16_to_cpu(id->vid) && in quirk_matches()
2617 string_matches(id->mn, q->mn, sizeof(id->mn)) && in quirk_matches()
2618 string_matches(id->fr, q->fr, sizeof(id->fr)); in quirk_matches()
2627 if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) { in nvme_init_subnqn()
2628 nqnlen = strnlen(id->subnqn, NVMF_NQN_SIZE); in nvme_init_subnqn()
2630 strscpy(subsys->subnqn, id->subnqn, NVMF_NQN_SIZE); in nvme_init_subnqn()
2634 if (ctrl->vs >= NVME_VS(1, 2, 1)) in nvme_init_subnqn()
2635 dev_warn(ctrl->device, "missing or invalid SUBNQN field.\n"); in nvme_init_subnqn()
2643 off = snprintf(subsys->subnqn, NVMF_NQN_SIZE, in nvme_init_subnqn()
2645 le16_to_cpu(id->vid), le16_to_cpu(id->ssvid)); in nvme_init_subnqn()
2646 memcpy(subsys->subnqn + off, id->sn, sizeof(id->sn)); in nvme_init_subnqn()
2647 off += sizeof(id->sn); in nvme_init_subnqn()
2648 memcpy(subsys->subnqn + off, id->mn, sizeof(id->mn)); in nvme_init_subnqn()
2649 off += sizeof(id->mn); in nvme_init_subnqn()
2650 memset(subsys->subnqn + off, 0, sizeof(subsys->subnqn) - off); in nvme_init_subnqn()
2658 if (subsys->instance >= 0) in nvme_release_subsystem()
2659 ida_free(&nvme_instance_ida, subsys->instance); in nvme_release_subsystem()
2669 list_del(&subsys->entry); in nvme_destroy_subsystem()
2672 ida_destroy(&subsys->ns_ida); in nvme_destroy_subsystem()
2673 device_del(&subsys->dev); in nvme_destroy_subsystem()
2674 put_device(&subsys->dev); in nvme_destroy_subsystem()
2679 kref_put(&subsys->ref, nvme_destroy_subsystem); in nvme_put_subsystem()
2700 if (strcmp(subsys->subnqn, subsysnqn)) in __nvme_find_get_subsystem()
2702 if (!kref_get_unless_zero(&subsys->ref)) in __nvme_find_get_subsystem()
2712 return ctrl->opts && ctrl->opts->discovery_nqn; in nvme_discovery_ctrl()
2722 list_for_each_entry(tmp, &subsys->ctrls, subsys_entry) { in nvme_validate_cntlid()
2726 if (tmp->cntlid == ctrl->cntlid) { in nvme_validate_cntlid()
2727 dev_err(ctrl->device, in nvme_validate_cntlid()
2729 ctrl->cntlid, dev_name(tmp->device), in nvme_validate_cntlid()
2730 subsys->subnqn); in nvme_validate_cntlid()
2734 if ((id->cmic & NVME_CTRL_CMIC_MULTI_CTRL) || in nvme_validate_cntlid()
2738 dev_err(ctrl->device, in nvme_validate_cntlid()
2753 return -ENOMEM; in nvme_init_subsystem()
2755 subsys->instance = -1; in nvme_init_subsystem()
2756 mutex_init(&subsys->lock); in nvme_init_subsystem()
2757 kref_init(&subsys->ref); in nvme_init_subsystem()
2758 INIT_LIST_HEAD(&subsys->ctrls); in nvme_init_subsystem()
2759 INIT_LIST_HEAD(&subsys->nsheads); in nvme_init_subsystem()
2761 memcpy(subsys->serial, id->sn, sizeof(subsys->serial)); in nvme_init_subsystem()
2762 memcpy(subsys->model, id->mn, sizeof(subsys->model)); in nvme_init_subsystem()
2763 subsys->vendor_id = le16_to_cpu(id->vid); in nvme_init_subsystem()
2764 subsys->cmic = id->cmic; in nvme_init_subsystem()
2767 if (id->cntrltype == NVME_CTRL_DISC || in nvme_init_subsystem()
2768 !strcmp(subsys->subnqn, NVME_DISC_SUBSYS_NAME)) in nvme_init_subsystem()
2769 subsys->subtype = NVME_NQN_DISC; in nvme_init_subsystem()
2771 subsys->subtype = NVME_NQN_NVME; in nvme_init_subsystem()
2773 if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) { in nvme_init_subsystem()
2774 dev_err(ctrl->device, in nvme_init_subsystem()
2776 subsys->subnqn); in nvme_init_subsystem()
2778 return -EINVAL; in nvme_init_subsystem()
2780 subsys->awupf = le16_to_cpu(id->awupf); in nvme_init_subsystem()
2783 subsys->dev.class = nvme_subsys_class; in nvme_init_subsystem()
2784 subsys->dev.release = nvme_release_subsystem; in nvme_init_subsystem()
2785 subsys->dev.groups = nvme_subsys_attrs_groups; in nvme_init_subsystem()
2786 dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); in nvme_init_subsystem()
2787 device_initialize(&subsys->dev); in nvme_init_subsystem()
2790 found = __nvme_find_get_subsystem(subsys->subnqn); in nvme_init_subsystem()
2792 put_device(&subsys->dev); in nvme_init_subsystem()
2796 ret = -EINVAL; in nvme_init_subsystem()
2800 ret = device_add(&subsys->dev); in nvme_init_subsystem()
2802 dev_err(ctrl->device, in nvme_init_subsystem()
2804 put_device(&subsys->dev); in nvme_init_subsystem()
2807 ida_init(&subsys->ns_ida); in nvme_init_subsystem()
2808 list_add_tail(&subsys->entry, &nvme_subsystems); in nvme_init_subsystem()
2811 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, in nvme_init_subsystem()
2812 dev_name(ctrl->device)); in nvme_init_subsystem()
2814 dev_err(ctrl->device, in nvme_init_subsystem()
2820 subsys->instance = ctrl->instance; in nvme_init_subsystem()
2821 ctrl->subsys = subsys; in nvme_init_subsystem()
2822 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvme_init_subsystem()
2843 c.get_log_page.numdl = cpu_to_le16(dwlen & ((1 << 16) - 1)); in nvme_get_log()
2849 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); in nvme_get_log()
2855 struct nvme_effects_log *cel = xa_load(&ctrl->cels, csi); in nvme_get_effects_log()
2863 return -ENOMEM; in nvme_get_effects_log()
2872 xa_store(&ctrl->cels, csi, cel, GFP_KERNEL); in nvme_get_effects_log()
2880 u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; in nvme_mps_to_sectors()
2882 if (check_shl_overflow(1U, units + page_shift - 9, &val)) in nvme_mps_to_sectors()
2893 if (ctrl->oncs & NVME_CTRL_ONCS_DSM) { in nvme_init_non_mdts_limits()
2894 ctrl->max_discard_sectors = UINT_MAX; in nvme_init_non_mdts_limits()
2895 ctrl->max_discard_segments = NVME_DSM_MAX_RANGES; in nvme_init_non_mdts_limits()
2897 ctrl->max_discard_sectors = 0; in nvme_init_non_mdts_limits()
2898 ctrl->max_discard_segments = 0; in nvme_init_non_mdts_limits()
2903 * to the write-zeroes, we are cautious and limit the size to the in nvme_init_non_mdts_limits()
2907 if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && in nvme_init_non_mdts_limits()
2908 !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) in nvme_init_non_mdts_limits()
2909 ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; in nvme_init_non_mdts_limits()
2911 ctrl->max_zeroes_sectors = 0; in nvme_init_non_mdts_limits()
2913 if (ctrl->subsys->subtype != NVME_NQN_NVME || in nvme_init_non_mdts_limits()
2915 test_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags)) in nvme_init_non_mdts_limits()
2920 return -ENOMEM; in nvme_init_non_mdts_limits()
2926 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_init_non_mdts_limits()
2930 if (id->dmrl) in nvme_init_non_mdts_limits()
2931 ctrl->max_discard_segments = id->dmrl; in nvme_init_non_mdts_limits()
2932 ctrl->dmrsl = le32_to_cpu(id->dmrsl); in nvme_init_non_mdts_limits()
2933 if (id->wzsl) in nvme_init_non_mdts_limits()
2934 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); in nvme_init_non_mdts_limits()
2938 set_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags); in nvme_init_non_mdts_limits()
2945 struct nvme_effects_log *log = ctrl->effects; in nvme_init_known_nvm_effects()
2947 log->acs[nvme_admin_format_nvm] |= cpu_to_le32(NVME_CMD_EFFECTS_LBCC | in nvme_init_known_nvm_effects()
2950 log->acs[nvme_admin_sanitize_nvm] |= cpu_to_le32(NVME_CMD_EFFECTS_LBCC | in nvme_init_known_nvm_effects()
2968 log->acs[nvme_admin_security_recv] &= cpu_to_le32(~NVME_CMD_EFFECTS_CSE_MASK); in nvme_init_known_nvm_effects()
2970 log->iocs[nvme_cmd_write] |= cpu_to_le32(NVME_CMD_EFFECTS_LBCC); in nvme_init_known_nvm_effects()
2971 log->iocs[nvme_cmd_write_zeroes] |= cpu_to_le32(NVME_CMD_EFFECTS_LBCC); in nvme_init_known_nvm_effects()
2972 log->iocs[nvme_cmd_write_uncor] |= cpu_to_le32(NVME_CMD_EFFECTS_LBCC); in nvme_init_known_nvm_effects()
2979 if (ctrl->effects) in nvme_init_effects()
2982 if (id->lpa & NVME_CTRL_LPA_CMD_EFFECTS_LOG) { in nvme_init_effects()
2983 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
2988 if (!ctrl->effects) { in nvme_init_effects()
2989 ctrl->effects = kzalloc(sizeof(*ctrl->effects), GFP_KERNEL); in nvme_init_effects()
2990 if (!ctrl->effects) in nvme_init_effects()
2991 return -ENOMEM; in nvme_init_effects()
2992 xa_store(&ctrl->cels, NVME_CSI_NVM, ctrl->effects, GFP_KERNEL); in nvme_init_effects()
3008 dev_err(ctrl->device, "Identify Controller failed (%d)\n", ret); in nvme_init_identify()
3009 return -EIO; in nvme_init_identify()
3012 if (!(ctrl->ops->flags & NVME_F_FABRICS)) in nvme_init_identify()
3013 ctrl->cntlid = le16_to_cpu(id->cntlid); in nvme_init_identify()
3015 if (!ctrl->identified) { in nvme_init_identify()
3022 * could re-scan for quirks every time we reinitialize in nvme_init_identify()
3028 ctrl->quirks |= core_quirks[i].quirks; in nvme_init_identify()
3039 memcpy(ctrl->subsys->firmware_rev, id->fr, in nvme_init_identify()
3040 sizeof(ctrl->subsys->firmware_rev)); in nvme_init_identify()
3042 if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) { in nvme_init_identify()
3043 …dev_warn(ctrl->device, "forcibly allowing all power states due to nvme_core.force_apst -- use at y… in nvme_init_identify()
3044 ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS; in nvme_init_identify()
3047 ctrl->crdt[0] = le16_to_cpu(id->crdt1); in nvme_init_identify()
3048 ctrl->crdt[1] = le16_to_cpu(id->crdt2); in nvme_init_identify()
3049 ctrl->crdt[2] = le16_to_cpu(id->crdt3); in nvme_init_identify()
3051 ctrl->oacs = le16_to_cpu(id->oacs); in nvme_init_identify()
3052 ctrl->oncs = le16_to_cpu(id->oncs); in nvme_init_identify()
3053 ctrl->mtfa = le16_to_cpu(id->mtfa); in nvme_init_identify()
3054 ctrl->oaes = le32_to_cpu(id->oaes); in nvme_init_identify()
3055 ctrl->wctemp = le16_to_cpu(id->wctemp); in nvme_init_identify()
3056 ctrl->cctemp = le16_to_cpu(id->cctemp); in nvme_init_identify()
3058 atomic_set(&ctrl->abort_limit, id->acl + 1); in nvme_init_identify()
3059 ctrl->vwc = id->vwc; in nvme_init_identify()
3060 if (id->mdts) in nvme_init_identify()
3061 max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); in nvme_init_identify()
3064 ctrl->max_hw_sectors = in nvme_init_identify()
3065 min_not_zero(ctrl->max_hw_sectors, max_hw_sectors); in nvme_init_identify()
3067 nvme_set_queue_limits(ctrl, ctrl->admin_q); in nvme_init_identify()
3068 ctrl->sgls = le32_to_cpu(id->sgls); in nvme_init_identify()
3069 ctrl->kas = le16_to_cpu(id->kas); in nvme_init_identify()
3070 ctrl->max_namespaces = le32_to_cpu(id->mnan); in nvme_init_identify()
3071 ctrl->ctratt = le32_to_cpu(id->ctratt); in nvme_init_identify()
3073 ctrl->cntrltype = id->cntrltype; in nvme_init_identify()
3074 ctrl->dctype = id->dctype; in nvme_init_identify()
3076 if (id->rtd3e) { in nvme_init_identify()
3077 /* us -> s */ in nvme_init_identify()
3078 u32 transition_time = le32_to_cpu(id->rtd3e) / USEC_PER_SEC; in nvme_init_identify()
3080 ctrl->shutdown_timeout = clamp_t(unsigned int, transition_time, in nvme_init_identify()
3083 if (ctrl->shutdown_timeout != shutdown_timeout) in nvme_init_identify()
3084 dev_info(ctrl->device, in nvme_init_identify()
3086 ctrl->shutdown_timeout); in nvme_init_identify()
3088 ctrl->shutdown_timeout = shutdown_timeout; in nvme_init_identify()
3090 ctrl->npss = id->npss; in nvme_init_identify()
3091 ctrl->apsta = id->apsta; in nvme_init_identify()
3092 prev_apst_enabled = ctrl->apst_enabled; in nvme_init_identify()
3093 if (ctrl->quirks & NVME_QUIRK_NO_APST) { in nvme_init_identify()
3094 if (force_apst && id->apsta) { in nvme_init_identify()
3095 …dev_warn(ctrl->device, "forcibly allowing APST due to nvme_core.force_apst -- use at your own risk… in nvme_init_identify()
3096 ctrl->apst_enabled = true; in nvme_init_identify()
3098 ctrl->apst_enabled = false; in nvme_init_identify()
3101 ctrl->apst_enabled = id->apsta; in nvme_init_identify()
3103 memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd)); in nvme_init_identify()
3105 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_init_identify()
3106 ctrl->icdoff = le16_to_cpu(id->icdoff); in nvme_init_identify()
3107 ctrl->ioccsz = le32_to_cpu(id->ioccsz); in nvme_init_identify()
3108 ctrl->iorcsz = le32_to_cpu(id->iorcsz); in nvme_init_identify()
3109 ctrl->maxcmd = le16_to_cpu(id->maxcmd); in nvme_init_identify()
3115 if (ctrl->cntlid != le16_to_cpu(id->cntlid)) { in nvme_init_identify()
3116 dev_err(ctrl->device, in nvme_init_identify()
3119 ctrl->cntlid, le16_to_cpu(id->cntlid)); in nvme_init_identify()
3120 ret = -EINVAL; in nvme_init_identify()
3124 if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) { in nvme_init_identify()
3125 dev_err(ctrl->device, in nvme_init_identify()
3126 "keep-alive support is mandatory for fabrics\n"); in nvme_init_identify()
3127 ret = -EINVAL; in nvme_init_identify()
3131 ctrl->hmpre = le32_to_cpu(id->hmpre); in nvme_init_identify()
3132 ctrl->hmmin = le32_to_cpu(id->hmmin); in nvme_init_identify()
3133 ctrl->hmminds = le32_to_cpu(id->hmminds); in nvme_init_identify()
3134 ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); in nvme_init_identify()
3141 if (ctrl->apst_enabled && !prev_apst_enabled) in nvme_init_identify()
3142 dev_pm_qos_expose_latency_tolerance(ctrl->device); in nvme_init_identify()
3143 else if (!ctrl->apst_enabled && prev_apst_enabled) in nvme_init_identify()
3144 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_identify()
3160 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); in nvme_init_ctrl_finish()
3162 dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); in nvme_init_ctrl_finish()
3166 ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); in nvme_init_ctrl_finish()
3168 if (ctrl->vs >= NVME_VS(1, 1, 0)) in nvme_init_ctrl_finish()
3169 ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); in nvme_init_ctrl_finish()
3189 if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3195 if (ret == -EINTR) in nvme_init_ctrl_finish()
3199 clear_bit(NVME_CTRL_DIRTY_CAPABILITY, &ctrl->flags); in nvme_init_ctrl_finish()
3200 ctrl->identified = true; in nvme_init_ctrl_finish()
3209 container_of(inode->i_cdev, struct nvme_ctrl, cdev); in nvme_dev_open()
3211 switch (ctrl->state) { in nvme_dev_open()
3215 return -EWOULDBLOCK; in nvme_dev_open()
3219 if (!try_module_get(ctrl->ops->module)) { in nvme_dev_open()
3221 return -EINVAL; in nvme_dev_open()
3224 file->private_data = ctrl; in nvme_dev_open()
3231 container_of(inode->i_cdev, struct nvme_ctrl, cdev); in nvme_dev_release()
3233 module_put(ctrl->ops->module); in nvme_dev_release()
3252 lockdep_assert_held(&ctrl->subsys->lock); in nvme_find_ns_head()
3254 list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { in nvme_find_ns_head()
3260 if (h->ns_id != nsid || !nvme_is_unique_nsid(ctrl, h)) in nvme_find_ns_head()
3262 if (!list_empty(&h->list) && nvme_tryget_ns_head(h)) in nvme_find_ns_head()
3272 bool has_uuid = !uuid_is_null(&ids->uuid); in nvme_subsys_check_duplicate_ids()
3273 bool has_nguid = memchr_inv(ids->nguid, 0, sizeof(ids->nguid)); in nvme_subsys_check_duplicate_ids()
3274 bool has_eui64 = memchr_inv(ids->eui64, 0, sizeof(ids->eui64)); in nvme_subsys_check_duplicate_ids()
3277 lockdep_assert_held(&subsys->lock); in nvme_subsys_check_duplicate_ids()
3279 list_for_each_entry(h, &subsys->nsheads, entry) { in nvme_subsys_check_duplicate_ids()
3280 if (has_uuid && uuid_equal(&ids->uuid, &h->ids.uuid)) in nvme_subsys_check_duplicate_ids()
3281 return -EINVAL; in nvme_subsys_check_duplicate_ids()
3283 memcmp(&ids->nguid, &h->ids.nguid, sizeof(ids->nguid)) == 0) in nvme_subsys_check_duplicate_ids()
3284 return -EINVAL; in nvme_subsys_check_duplicate_ids()
3286 memcmp(&ids->eui64, &h->ids.eui64, sizeof(ids->eui64)) == 0) in nvme_subsys_check_duplicate_ids()
3287 return -EINVAL; in nvme_subsys_check_duplicate_ids()
3295 ida_free(&nvme_ns_chr_minor_ida, MINOR(dev->devt)); in nvme_cdev_rel()
3312 cdev_device->devt = MKDEV(MAJOR(nvme_ns_chr_devt), minor); in nvme_cdev_add()
3313 cdev_device->class = nvme_ns_chr_class; in nvme_cdev_add()
3314 cdev_device->release = nvme_cdev_rel; in nvme_cdev_add()
3317 cdev->owner = owner; in nvme_cdev_add()
3327 return nvme_ns_open(container_of(inode->i_cdev, struct nvme_ns, cdev)); in nvme_ns_chr_open()
3332 nvme_ns_release(container_of(inode->i_cdev, struct nvme_ns, cdev)); in nvme_ns_chr_release()
3350 ns->cdev_device.parent = ns->ctrl->device; in nvme_add_ns_cdev()
3351 ret = dev_set_name(&ns->cdev_device, "ng%dn%d", in nvme_add_ns_cdev()
3352 ns->ctrl->instance, ns->head->instance); in nvme_add_ns_cdev()
3356 return nvme_cdev_add(&ns->cdev, &ns->cdev_device, &nvme_ns_chr_fops, in nvme_add_ns_cdev()
3357 ns->ctrl->ops->module); in nvme_add_ns_cdev()
3365 int ret = -ENOMEM; in nvme_alloc_ns_head()
3374 ret = ida_alloc_min(&ctrl->subsys->ns_ida, 1, GFP_KERNEL); in nvme_alloc_ns_head()
3377 head->instance = ret; in nvme_alloc_ns_head()
3378 INIT_LIST_HEAD(&head->list); in nvme_alloc_ns_head()
3379 ret = init_srcu_struct(&head->srcu); in nvme_alloc_ns_head()
3382 head->subsys = ctrl->subsys; in nvme_alloc_ns_head()
3383 head->ns_id = info->nsid; in nvme_alloc_ns_head()
3384 head->ids = info->ids; in nvme_alloc_ns_head()
3385 head->shared = info->is_shared; in nvme_alloc_ns_head()
3386 kref_init(&head->ref); in nvme_alloc_ns_head()
3388 if (head->ids.csi) { in nvme_alloc_ns_head()
3389 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); in nvme_alloc_ns_head()
3393 head->effects = ctrl->effects; in nvme_alloc_ns_head()
3399 list_add_tail(&head->entry, &ctrl->subsys->nsheads); in nvme_alloc_ns_head()
3401 kref_get(&ctrl->subsys->ref); in nvme_alloc_ns_head()
3405 cleanup_srcu_struct(&head->srcu); in nvme_alloc_ns_head()
3407 ida_free(&ctrl->subsys->ns_ida, head->instance); in nvme_alloc_ns_head()
3431 mutex_lock(&s->lock); in nvme_global_check_duplicate_ids()
3433 mutex_unlock(&s->lock); in nvme_global_check_duplicate_ids()
3444 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ns_head()
3448 ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3455 * and in user space the /dev/disk/by-id/ links rely on it. in nvme_init_ns_head()
3457 * If the device also claims to be multi-path capable back off in nvme_init_ns_head()
3467 if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ in nvme_init_ns_head()
3468 ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && in nvme_init_ns_head()
3469 info->is_shared)) { in nvme_init_ns_head()
3470 dev_err(ctrl->device, in nvme_init_ns_head()
3472 info->nsid); in nvme_init_ns_head()
3476 dev_err(ctrl->device, in nvme_init_ns_head()
3477 "clearing duplicate IDs for nsid %d\n", info->nsid); in nvme_init_ns_head()
3478 dev_err(ctrl->device, in nvme_init_ns_head()
3479 "use of /dev/disk/by-id/ may cause data corruption\n"); in nvme_init_ns_head()
3480 memset(&info->ids.nguid, 0, sizeof(info->ids.nguid)); in nvme_init_ns_head()
3481 memset(&info->ids.uuid, 0, sizeof(info->ids.uuid)); in nvme_init_ns_head()
3482 memset(&info->ids.eui64, 0, sizeof(info->ids.eui64)); in nvme_init_ns_head()
3483 ctrl->quirks |= NVME_QUIRK_BOGUS_NID; in nvme_init_ns_head()
3486 mutex_lock(&ctrl->subsys->lock); in nvme_init_ns_head()
3487 head = nvme_find_ns_head(ctrl, info->nsid); in nvme_init_ns_head()
3489 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3491 dev_err(ctrl->device, in nvme_init_ns_head()
3493 info->nsid); in nvme_init_ns_head()
3502 ret = -EINVAL; in nvme_init_ns_head()
3503 if (!info->is_shared || !head->shared) { in nvme_init_ns_head()
3504 dev_err(ctrl->device, in nvme_init_ns_head()
3506 info->nsid); in nvme_init_ns_head()
3509 if (!nvme_ns_ids_equal(&head->ids, &info->ids)) { in nvme_init_ns_head()
3510 dev_err(ctrl->device, in nvme_init_ns_head()
3512 info->nsid); in nvme_init_ns_head()
3517 dev_warn(ctrl->device, in nvme_init_ns_head()
3519 info->nsid); in nvme_init_ns_head()
3520 dev_warn_once(ctrl->device, in nvme_init_ns_head()
3525 list_add_tail_rcu(&ns->siblings, &head->list); in nvme_init_ns_head()
3526 ns->head = head; in nvme_init_ns_head()
3527 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3533 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3541 down_read(&ctrl->namespaces_rwsem); in nvme_find_get_ns()
3542 list_for_each_entry(ns, &ctrl->namespaces, list) { in nvme_find_get_ns()
3543 if (ns->head->ns_id == nsid) { in nvme_find_get_ns()
3549 if (ns->head->ns_id > nsid) in nvme_find_get_ns()
3552 up_read(&ctrl->namespaces_rwsem); in nvme_find_get_ns()
3564 list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) { in nvme_ns_add_to_ctrl_list()
3565 if (tmp->head->ns_id < ns->head->ns_id) { in nvme_ns_add_to_ctrl_list()
3566 list_add(&ns->list, &tmp->list); in nvme_ns_add_to_ctrl_list()
3570 list_add(&ns->list, &ns->ctrl->namespaces); in nvme_ns_add_to_ctrl_list()
3577 int node = ctrl->numa_node; in nvme_alloc_ns()
3583 disk = blk_mq_alloc_disk(ctrl->tagset, ns); in nvme_alloc_ns()
3586 disk->fops = &nvme_bdev_ops; in nvme_alloc_ns()
3587 disk->private_data = ns; in nvme_alloc_ns()
3589 ns->disk = disk; in nvme_alloc_ns()
3590 ns->queue = disk->queue; in nvme_alloc_ns()
3592 if (ctrl->opts && ctrl->opts->data_digest) in nvme_alloc_ns()
3593 blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, ns->queue); in nvme_alloc_ns()
3595 blk_queue_flag_set(QUEUE_FLAG_NONROT, ns->queue); in nvme_alloc_ns()
3596 if (ctrl->ops->supports_pci_p2pdma && in nvme_alloc_ns()
3597 ctrl->ops->supports_pci_p2pdma(ctrl)) in nvme_alloc_ns()
3598 blk_queue_flag_set(QUEUE_FLAG_PCI_P2PDMA, ns->queue); in nvme_alloc_ns()
3600 ns->ctrl = ctrl; in nvme_alloc_ns()
3601 kref_init(&ns->kref); in nvme_alloc_ns()
3617 if (nvme_ns_head_multipath(ns->head)) { in nvme_alloc_ns()
3618 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3619 ctrl->instance, ns->head->instance); in nvme_alloc_ns()
3620 disk->flags |= GENHD_FL_HIDDEN; in nvme_alloc_ns()
3622 sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3623 ns->head->instance); in nvme_alloc_ns()
3625 sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, in nvme_alloc_ns()
3626 ns->head->instance); in nvme_alloc_ns()
3632 down_write(&ctrl->namespaces_rwsem); in nvme_alloc_ns()
3634 up_write(&ctrl->namespaces_rwsem); in nvme_alloc_ns()
3637 if (device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups)) in nvme_alloc_ns()
3640 if (!nvme_ns_head_multipath(ns->head)) in nvme_alloc_ns()
3643 nvme_mpath_add_disk(ns, info->anagrpid); in nvme_alloc_ns()
3644 nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name); in nvme_alloc_ns()
3650 down_write(&ctrl->namespaces_rwsem); in nvme_alloc_ns()
3651 list_del_init(&ns->list); in nvme_alloc_ns()
3652 up_write(&ctrl->namespaces_rwsem); in nvme_alloc_ns()
3654 mutex_lock(&ctrl->subsys->lock); in nvme_alloc_ns()
3655 list_del_rcu(&ns->siblings); in nvme_alloc_ns()
3656 if (list_empty(&ns->head->list)) in nvme_alloc_ns()
3657 list_del_init(&ns->head->entry); in nvme_alloc_ns()
3658 mutex_unlock(&ctrl->subsys->lock); in nvme_alloc_ns()
3659 nvme_put_ns_head(ns->head); in nvme_alloc_ns()
3670 if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags)) in nvme_ns_remove()
3673 clear_bit(NVME_NS_READY, &ns->flags); in nvme_ns_remove()
3674 set_capacity(ns->disk, 0); in nvme_ns_remove()
3675 nvme_fault_inject_fini(&ns->fault_inject); in nvme_ns_remove()
3681 synchronize_srcu(&ns->head->srcu); in nvme_ns_remove()
3685 synchronize_srcu(&ns->head->srcu); in nvme_ns_remove()
3687 mutex_lock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
3688 list_del_rcu(&ns->siblings); in nvme_ns_remove()
3689 if (list_empty(&ns->head->list)) { in nvme_ns_remove()
3690 list_del_init(&ns->head->entry); in nvme_ns_remove()
3693 mutex_unlock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
3695 /* guarantee not available in head->list */ in nvme_ns_remove()
3696 synchronize_srcu(&ns->head->srcu); in nvme_ns_remove()
3698 if (!nvme_ns_head_multipath(ns->head)) in nvme_ns_remove()
3699 nvme_cdev_del(&ns->cdev, &ns->cdev_device); in nvme_ns_remove()
3700 del_gendisk(ns->disk); in nvme_ns_remove()
3702 down_write(&ns->ctrl->namespaces_rwsem); in nvme_ns_remove()
3703 list_del_init(&ns->list); in nvme_ns_remove()
3704 up_write(&ns->ctrl->namespaces_rwsem); in nvme_ns_remove()
3707 nvme_mpath_shutdown_disk(ns->head); in nvme_ns_remove()
3725 if (!nvme_ns_ids_equal(&ns->head->ids, &info->ids)) { in nvme_validate_ns()
3726 dev_err(ns->ctrl->device, in nvme_validate_ns()
3727 "identifiers changed for nsid %d\n", ns->head->ns_id); in nvme_validate_ns()
3753 dev_warn(ctrl->device, in nvme_scan_ns()
3763 if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || in nvme_scan_ns()
3794 down_write(&ctrl->namespaces_rwsem); in nvme_remove_invalid_namespaces()
3795 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { in nvme_remove_invalid_namespaces()
3796 if (ns->head->ns_id > nsid) in nvme_remove_invalid_namespaces()
3797 list_move_tail(&ns->list, &rm_list); in nvme_remove_invalid_namespaces()
3799 up_write(&ctrl->namespaces_rwsem); in nvme_remove_invalid_namespaces()
3815 return -ENOMEM; in nvme_scan_ns_list()
3824 ret = nvme_submit_sync_cmd(ctrl->admin_q, &cmd, ns_list, in nvme_scan_ns_list()
3827 dev_warn(ctrl->device, in nvme_scan_ns_list()
3856 nn = le32_to_cpu(id->nn); in nvme_scan_ns_sequential()
3884 dev_warn(ctrl->device, in nvme_clear_changed_ns_log()
3897 if (ctrl->state != NVME_CTRL_LIVE || !ctrl->tagset) in nvme_scan_work()
3903 * such scenario. Controller's non-mdts limits are reported in the unit in nvme_scan_work()
3905 * namespace. Hence re-read the limits at the time of ns allocation. in nvme_scan_work()
3909 dev_warn(ctrl->device, in nvme_scan_work()
3910 "reading non-mdts-limits failed: %d\n", ret); in nvme_scan_work()
3914 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { in nvme_scan_work()
3915 dev_info(ctrl->device, "rescanning namespaces.\n"); in nvme_scan_work()
3919 mutex_lock(&ctrl->scan_lock); in nvme_scan_work()
3932 mutex_unlock(&ctrl->scan_lock); in nvme_scan_work()
3959 flush_work(&ctrl->scan_work); in nvme_remove_namespaces()
3967 if (ctrl->state == NVME_CTRL_DEAD) in nvme_remove_namespaces()
3970 /* this is a no-op when called from the controller reset handler */ in nvme_remove_namespaces()
3973 down_write(&ctrl->namespaces_rwsem); in nvme_remove_namespaces()
3974 list_splice_init(&ctrl->namespaces, &ns_list); in nvme_remove_namespaces()
3975 up_write(&ctrl->namespaces_rwsem); in nvme_remove_namespaces()
3986 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_class_uevent()
3989 ret = add_uevent_var(env, "NVME_TRTYPE=%s", ctrl->ops->name); in nvme_class_uevent()
3994 ret = add_uevent_var(env, "NVME_TRADDR=%s", opts->traddr); in nvme_class_uevent()
3999 opts->trsvcid ?: "none"); in nvme_class_uevent()
4004 opts->host_traddr ?: "none"); in nvme_class_uevent()
4009 opts->host_iface ?: "none"); in nvme_class_uevent()
4018 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_change_uevent()
4024 u32 aen_result = ctrl->aen_result; in nvme_aen_uevent()
4026 ctrl->aen_result = 0; in nvme_aen_uevent()
4033 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_aen_uevent()
4049 if (ctrl->state == NVME_CTRL_LIVE) in nvme_async_event_work()
4050 ctrl->ops->submit_async_event(ctrl); in nvme_async_event_work()
4058 if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) in nvme_ctrl_pp_status()
4064 return ((ctrl->ctrl_config & NVME_CC_ENABLE) && (csts & NVME_CSTS_PP)); in nvme_ctrl_pp_status()
4077 dev_warn(ctrl->device, "Get FW SLOT INFO log error\n"); in nvme_get_fw_slot_info()
4087 if (ctrl->mtfa) in nvme_fw_act_work()
4089 msecs_to_jiffies(ctrl->mtfa * 100); in nvme_fw_act_work()
4097 dev_warn(ctrl->device, in nvme_fw_act_work()
4112 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_fw_act_work()
4132 set_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events); in nvme_handle_aen_notice()
4144 queue_work(nvme_wq, &ctrl->fw_act_work); in nvme_handle_aen_notice()
4149 if (!ctrl->ana_log_buf) in nvme_handle_aen_notice()
4151 queue_work(nvme_wq, &ctrl->ana_work); in nvme_handle_aen_notice()
4155 ctrl->aen_result = result; in nvme_handle_aen_notice()
4158 dev_warn(ctrl->device, "async event result %08x\n", result); in nvme_handle_aen_notice()
4165 dev_warn(ctrl->device, "resetting controller due to AER\n"); in nvme_handle_aer_persistent_error()
4172 u32 result = le32_to_cpu(res->u32); in nvme_complete_async_event()
4198 ctrl->aen_result = result; in nvme_complete_async_event()
4205 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_complete_async_event()
4215 set->ops = ops; in nvme_alloc_admin_tag_set()
4216 set->queue_depth = NVME_AQ_MQ_TAG_DEPTH; in nvme_alloc_admin_tag_set()
4217 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_admin_tag_set()
4218 set->reserved_tags = NVMF_RESERVED_TAGS; in nvme_alloc_admin_tag_set()
4219 set->numa_node = ctrl->numa_node; in nvme_alloc_admin_tag_set()
4220 set->flags = BLK_MQ_F_NO_SCHED; in nvme_alloc_admin_tag_set()
4221 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_admin_tag_set()
4222 set->flags |= BLK_MQ_F_BLOCKING; in nvme_alloc_admin_tag_set()
4223 set->cmd_size = cmd_size; in nvme_alloc_admin_tag_set()
4224 set->driver_data = ctrl; in nvme_alloc_admin_tag_set()
4225 set->nr_hw_queues = 1; in nvme_alloc_admin_tag_set()
4226 set->timeout = NVME_ADMIN_TIMEOUT; in nvme_alloc_admin_tag_set()
4231 ctrl->admin_q = blk_mq_init_queue(set); in nvme_alloc_admin_tag_set()
4232 if (IS_ERR(ctrl->admin_q)) { in nvme_alloc_admin_tag_set()
4233 ret = PTR_ERR(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4237 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_admin_tag_set()
4238 ctrl->fabrics_q = blk_mq_init_queue(set); in nvme_alloc_admin_tag_set()
4239 if (IS_ERR(ctrl->fabrics_q)) { in nvme_alloc_admin_tag_set()
4240 ret = PTR_ERR(ctrl->fabrics_q); in nvme_alloc_admin_tag_set()
4245 ctrl->admin_tagset = set; in nvme_alloc_admin_tag_set()
4249 blk_mq_destroy_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4250 blk_put_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4253 ctrl->admin_q = NULL; in nvme_alloc_admin_tag_set()
4254 ctrl->fabrics_q = NULL; in nvme_alloc_admin_tag_set()
4261 blk_mq_destroy_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4262 blk_put_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4263 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_admin_tag_set()
4264 blk_mq_destroy_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4265 blk_put_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4267 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_remove_admin_tag_set()
4278 set->ops = ops; in nvme_alloc_io_tag_set()
4279 set->queue_depth = min_t(unsigned, ctrl->sqsize, BLK_MQ_MAX_DEPTH - 1); in nvme_alloc_io_tag_set()
4284 if (ctrl->quirks & NVME_QUIRK_SHARED_TAGS) in nvme_alloc_io_tag_set()
4285 set->reserved_tags = NVME_AQ_DEPTH; in nvme_alloc_io_tag_set()
4286 else if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_io_tag_set()
4287 set->reserved_tags = NVMF_RESERVED_TAGS; in nvme_alloc_io_tag_set()
4288 set->numa_node = ctrl->numa_node; in nvme_alloc_io_tag_set()
4289 set->flags = BLK_MQ_F_SHOULD_MERGE; in nvme_alloc_io_tag_set()
4290 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_io_tag_set()
4291 set->flags |= BLK_MQ_F_BLOCKING; in nvme_alloc_io_tag_set()
4292 set->cmd_size = cmd_size, in nvme_alloc_io_tag_set()
4293 set->driver_data = ctrl; in nvme_alloc_io_tag_set()
4294 set->nr_hw_queues = ctrl->queue_count - 1; in nvme_alloc_io_tag_set()
4295 set->timeout = NVME_IO_TIMEOUT; in nvme_alloc_io_tag_set()
4296 set->nr_maps = nr_maps; in nvme_alloc_io_tag_set()
4301 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_io_tag_set()
4302 ctrl->connect_q = blk_mq_init_queue(set); in nvme_alloc_io_tag_set()
4303 if (IS_ERR(ctrl->connect_q)) { in nvme_alloc_io_tag_set()
4304 ret = PTR_ERR(ctrl->connect_q); in nvme_alloc_io_tag_set()
4308 ctrl->connect_q); in nvme_alloc_io_tag_set()
4311 ctrl->tagset = set; in nvme_alloc_io_tag_set()
4316 ctrl->connect_q = NULL; in nvme_alloc_io_tag_set()
4323 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_io_tag_set()
4324 blk_mq_destroy_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4325 blk_put_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4327 blk_mq_free_tag_set(ctrl->tagset); in nvme_remove_io_tag_set()
4337 flush_work(&ctrl->async_event_work); in nvme_stop_ctrl()
4338 cancel_work_sync(&ctrl->fw_act_work); in nvme_stop_ctrl()
4339 if (ctrl->ops->stop_ctrl) in nvme_stop_ctrl()
4340 ctrl->ops->stop_ctrl(ctrl); in nvme_stop_ctrl()
4352 * to re-read the discovery log page to learn about possible changes in nvme_start_ctrl()
4356 if (test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags) && in nvme_start_ctrl()
4360 if (ctrl->queue_count > 1) { in nvme_start_ctrl()
4367 set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags); in nvme_start_ctrl()
4374 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_uninit_ctrl()
4375 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_uninit_ctrl()
4376 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_uninit_ctrl()
4386 xa_for_each(&ctrl->cels, i, cel) { in nvme_free_cels()
4387 xa_erase(&ctrl->cels, i); in nvme_free_cels()
4391 xa_destroy(&ctrl->cels); in nvme_free_cels()
4398 struct nvme_subsystem *subsys = ctrl->subsys; in nvme_free_ctrl()
4400 if (!subsys || ctrl->instance != subsys->instance) in nvme_free_ctrl()
4401 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_free_ctrl()
4407 __free_page(ctrl->discard_page); in nvme_free_ctrl()
4408 free_opal_dev(ctrl->opal_dev); in nvme_free_ctrl()
4412 list_del(&ctrl->subsys_entry); in nvme_free_ctrl()
4413 sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device)); in nvme_free_ctrl()
4417 ctrl->ops->free_ctrl(ctrl); in nvme_free_ctrl()
4433 ctrl->state = NVME_CTRL_NEW; in nvme_init_ctrl()
4434 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_init_ctrl()
4435 spin_lock_init(&ctrl->lock); in nvme_init_ctrl()
4436 mutex_init(&ctrl->scan_lock); in nvme_init_ctrl()
4437 INIT_LIST_HEAD(&ctrl->namespaces); in nvme_init_ctrl()
4438 xa_init(&ctrl->cels); in nvme_init_ctrl()
4439 init_rwsem(&ctrl->namespaces_rwsem); in nvme_init_ctrl()
4440 ctrl->dev = dev; in nvme_init_ctrl()
4441 ctrl->ops = ops; in nvme_init_ctrl()
4442 ctrl->quirks = quirks; in nvme_init_ctrl()
4443 ctrl->numa_node = NUMA_NO_NODE; in nvme_init_ctrl()
4444 INIT_WORK(&ctrl->scan_work, nvme_scan_work); in nvme_init_ctrl()
4445 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); in nvme_init_ctrl()
4446 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); in nvme_init_ctrl()
4447 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); in nvme_init_ctrl()
4448 init_waitqueue_head(&ctrl->state_wq); in nvme_init_ctrl()
4450 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); in nvme_init_ctrl()
4451 INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); in nvme_init_ctrl()
4452 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); in nvme_init_ctrl()
4453 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; in nvme_init_ctrl()
4457 ctrl->discard_page = alloc_page(GFP_KERNEL); in nvme_init_ctrl()
4458 if (!ctrl->discard_page) { in nvme_init_ctrl()
4459 ret = -ENOMEM; in nvme_init_ctrl()
4466 ctrl->instance = ret; in nvme_init_ctrl()
4468 device_initialize(&ctrl->ctrl_device); in nvme_init_ctrl()
4469 ctrl->device = &ctrl->ctrl_device; in nvme_init_ctrl()
4470 ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt), in nvme_init_ctrl()
4471 ctrl->instance); in nvme_init_ctrl()
4472 ctrl->device->class = nvme_class; in nvme_init_ctrl()
4473 ctrl->device->parent = ctrl->dev; in nvme_init_ctrl()
4474 if (ops->dev_attr_groups) in nvme_init_ctrl()
4475 ctrl->device->groups = ops->dev_attr_groups; in nvme_init_ctrl()
4477 ctrl->device->groups = nvme_dev_attr_groups; in nvme_init_ctrl()
4478 ctrl->device->release = nvme_free_ctrl; in nvme_init_ctrl()
4479 dev_set_drvdata(ctrl->device, ctrl); in nvme_init_ctrl()
4480 ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance); in nvme_init_ctrl()
4485 cdev_init(&ctrl->cdev, &nvme_dev_fops); in nvme_init_ctrl()
4486 ctrl->cdev.owner = ops->module; in nvme_init_ctrl()
4487 ret = cdev_device_add(&ctrl->cdev, ctrl->device); in nvme_init_ctrl()
4495 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; in nvme_init_ctrl()
4496 dev_pm_qos_update_user_latency_tolerance(ctrl->device, in nvme_init_ctrl()
4499 nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); in nvme_init_ctrl()
4507 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_init_ctrl()
4508 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_ctrl()
4509 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_init_ctrl()
4512 kfree_const(ctrl->device->kobj.name); in nvme_init_ctrl()
4514 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_init_ctrl()
4516 if (ctrl->discard_page) in nvme_init_ctrl()
4517 __free_page(ctrl->discard_page); in nvme_init_ctrl()
4527 down_read(&ctrl->namespaces_rwsem); in nvme_mark_namespaces_dead()
4528 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_mark_namespaces_dead()
4529 blk_mark_disk_dead(ns->disk); in nvme_mark_namespaces_dead()
4530 up_read(&ctrl->namespaces_rwsem); in nvme_mark_namespaces_dead()
4538 down_read(&ctrl->namespaces_rwsem); in nvme_unfreeze()
4539 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_unfreeze()
4540 blk_mq_unfreeze_queue(ns->queue); in nvme_unfreeze()
4541 up_read(&ctrl->namespaces_rwsem); in nvme_unfreeze()
4549 down_read(&ctrl->namespaces_rwsem); in nvme_wait_freeze_timeout()
4550 list_for_each_entry(ns, &ctrl->namespaces, list) { in nvme_wait_freeze_timeout()
4551 timeout = blk_mq_freeze_queue_wait_timeout(ns->queue, timeout); in nvme_wait_freeze_timeout()
4555 up_read(&ctrl->namespaces_rwsem); in nvme_wait_freeze_timeout()
4564 down_read(&ctrl->namespaces_rwsem); in nvme_wait_freeze()
4565 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_wait_freeze()
4566 blk_mq_freeze_queue_wait(ns->queue); in nvme_wait_freeze()
4567 up_read(&ctrl->namespaces_rwsem); in nvme_wait_freeze()
4575 down_read(&ctrl->namespaces_rwsem); in nvme_start_freeze()
4576 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_start_freeze()
4577 blk_freeze_queue_start(ns->queue); in nvme_start_freeze()
4578 up_read(&ctrl->namespaces_rwsem); in nvme_start_freeze()
4584 if (!ctrl->tagset) in nvme_quiesce_io_queues()
4586 if (!test_and_set_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_quiesce_io_queues()
4587 blk_mq_quiesce_tagset(ctrl->tagset); in nvme_quiesce_io_queues()
4589 blk_mq_wait_quiesce_done(ctrl->tagset); in nvme_quiesce_io_queues()
4595 if (!ctrl->tagset) in nvme_unquiesce_io_queues()
4597 if (test_and_clear_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_unquiesce_io_queues()
4598 blk_mq_unquiesce_tagset(ctrl->tagset); in nvme_unquiesce_io_queues()
4604 if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_quiesce_admin_queue()
4605 blk_mq_quiesce_queue(ctrl->admin_q); in nvme_quiesce_admin_queue()
4607 blk_mq_wait_quiesce_done(ctrl->admin_q->tag_set); in nvme_quiesce_admin_queue()
4613 if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_unquiesce_admin_queue()
4614 blk_mq_unquiesce_queue(ctrl->admin_q); in nvme_unquiesce_admin_queue()
4622 down_read(&ctrl->namespaces_rwsem); in nvme_sync_io_queues()
4623 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_sync_io_queues()
4624 blk_sync_queue(ns->queue); in nvme_sync_io_queues()
4625 up_read(&ctrl->namespaces_rwsem); in nvme_sync_io_queues()
4632 if (ctrl->admin_q) in nvme_sync_queues()
4633 blk_sync_queue(ctrl->admin_q); in nvme_sync_queues()
4639 if (file->f_op != &nvme_dev_fops) in nvme_ctrl_from_file()
4641 return file->private_data; in nvme_ctrl_from_file()
4679 int result = -ENOMEM; in nvme_core_init()
4683 nvme_wq = alloc_workqueue("nvme-wq", in nvme_core_init()
4688 nvme_reset_wq = alloc_workqueue("nvme-reset-wq", in nvme_core_init()
4693 nvme_delete_wq = alloc_workqueue("nvme-delete-wq", in nvme_core_init()
4708 nvme_class->dev_uevent = nvme_class_uevent; in nvme_core_init()
4710 nvme_subsys_class = class_create("nvme-subsystem"); in nvme_core_init()
4717 "nvme-generic"); in nvme_core_init()
4721 nvme_ns_chr_class = class_create("nvme-generic"); in nvme_core_init()