Lines Matching full:ctrl
149 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
151 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
154 void nvme_queue_scan(struct nvme_ctrl *ctrl) in nvme_queue_scan() argument
159 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE && ctrl->tagset) in nvme_queue_scan()
160 queue_work(nvme_wq, &ctrl->scan_work); in nvme_queue_scan()
169 int nvme_try_sched_reset(struct nvme_ctrl *ctrl) in nvme_try_sched_reset() argument
171 if (nvme_ctrl_state(ctrl) != NVME_CTRL_RESETTING) in nvme_try_sched_reset()
173 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_try_sched_reset()
181 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_failfast_work() local
184 if (nvme_ctrl_state(ctrl) != NVME_CTRL_CONNECTING) in nvme_failfast_work()
187 set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_failfast_work()
188 dev_info(ctrl->device, "failfast expired\n"); in nvme_failfast_work()
189 nvme_kick_requeue_lists(ctrl); in nvme_failfast_work()
192 static inline void nvme_start_failfast_work(struct nvme_ctrl *ctrl) in nvme_start_failfast_work() argument
194 if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) in nvme_start_failfast_work()
197 schedule_delayed_work(&ctrl->failfast_work, in nvme_start_failfast_work()
198 ctrl->opts->fast_io_fail_tmo * HZ); in nvme_start_failfast_work()
201 static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) in nvme_stop_failfast_work() argument
203 if (!ctrl->opts) in nvme_stop_failfast_work()
206 cancel_delayed_work_sync(&ctrl->failfast_work); in nvme_stop_failfast_work()
207 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_stop_failfast_work()
211 int nvme_reset_ctrl(struct nvme_ctrl *ctrl) in nvme_reset_ctrl() argument
213 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) in nvme_reset_ctrl()
215 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_reset_ctrl()
221 int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_reset_ctrl_sync() argument
225 ret = nvme_reset_ctrl(ctrl); in nvme_reset_ctrl_sync()
227 flush_work(&ctrl->reset_work); in nvme_reset_ctrl_sync()
228 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE) in nvme_reset_ctrl_sync()
235 static void nvme_do_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_do_delete_ctrl() argument
237 dev_info(ctrl->device, in nvme_do_delete_ctrl()
238 "Removing ctrl: NQN \"%s\"\n", nvmf_ctrl_subsysnqn(ctrl)); in nvme_do_delete_ctrl()
240 flush_work(&ctrl->reset_work); in nvme_do_delete_ctrl()
241 nvme_stop_ctrl(ctrl); in nvme_do_delete_ctrl()
242 nvme_remove_namespaces(ctrl); in nvme_do_delete_ctrl()
243 ctrl->ops->delete_ctrl(ctrl); in nvme_do_delete_ctrl()
244 nvme_uninit_ctrl(ctrl); in nvme_do_delete_ctrl()
249 struct nvme_ctrl *ctrl = in nvme_delete_ctrl_work() local
252 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_work()
255 int nvme_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_delete_ctrl() argument
257 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl()
259 if (!queue_work(nvme_delete_wq, &ctrl->delete_work)) in nvme_delete_ctrl()
265 void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_delete_ctrl_sync() argument
271 nvme_get_ctrl(ctrl); in nvme_delete_ctrl_sync()
272 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl_sync()
273 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_sync()
274 nvme_put_ctrl(ctrl); in nvme_delete_ctrl_sync()
327 delay = nvme_req(req)->ctrl->crdt[crd - 1] * 100; in nvme_retry_req()
355 dev_name(nr->ctrl->device), in nvme_log_error()
372 ns ? ns->disk->disk_name : dev_name(nr->ctrl->device), in nvme_log_err_passthru()
456 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_complete_rq() local
469 if (ctrl->kas && in nvme_complete_rq()
470 req->deadline - req->timeout >= ctrl->ka_last_check_time) in nvme_complete_rq()
471 ctrl->comp_seen = true; in nvme_complete_rq()
485 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_complete_rq()
534 void nvme_cancel_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_tagset() argument
536 if (ctrl->tagset) { in nvme_cancel_tagset()
537 blk_mq_tagset_busy_iter(ctrl->tagset, in nvme_cancel_tagset()
538 nvme_cancel_request, ctrl); in nvme_cancel_tagset()
539 blk_mq_tagset_wait_completed_request(ctrl->tagset); in nvme_cancel_tagset()
544 void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_admin_tagset() argument
546 if (ctrl->admin_tagset) { in nvme_cancel_admin_tagset()
547 blk_mq_tagset_busy_iter(ctrl->admin_tagset, in nvme_cancel_admin_tagset()
548 nvme_cancel_request, ctrl); in nvme_cancel_admin_tagset()
549 blk_mq_tagset_wait_completed_request(ctrl->admin_tagset); in nvme_cancel_admin_tagset()
554 bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, in nvme_change_ctrl_state() argument
561 spin_lock_irqsave(&ctrl->lock, flags); in nvme_change_ctrl_state()
563 old_state = nvme_ctrl_state(ctrl); in nvme_change_ctrl_state()
629 WRITE_ONCE(ctrl->state, new_state); in nvme_change_ctrl_state()
630 wake_up_all(&ctrl->state_wq); in nvme_change_ctrl_state()
633 spin_unlock_irqrestore(&ctrl->lock, flags); in nvme_change_ctrl_state()
639 nvme_stop_failfast_work(ctrl); in nvme_change_ctrl_state()
640 nvme_kick_requeue_lists(ctrl); in nvme_change_ctrl_state()
643 nvme_start_failfast_work(ctrl); in nvme_change_ctrl_state()
653 bool nvme_wait_reset(struct nvme_ctrl *ctrl) in nvme_wait_reset() argument
655 wait_event(ctrl->state_wq, in nvme_wait_reset()
656 nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING) || in nvme_wait_reset()
657 nvme_state_terminal(ctrl)); in nvme_wait_reset()
658 return nvme_ctrl_state(ctrl) == NVME_CTRL_RESETTING; in nvme_wait_reset()
690 nvme_put_ctrl(ns->ctrl); in nvme_free_ns()
725 logging_enabled = nr->ctrl->passthru_err_log_enabled; in nvme_init_request()
752 blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl, in nvme_fail_nonready_command() argument
755 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_fail_nonready_command()
760 !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) && in nvme_fail_nonready_command()
767 bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq, in __nvme_check_ready() argument
780 if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD)) in __nvme_check_ready()
783 if (ctrl->ops->flags & NVME_F_FABRICS) { in __nvme_check_ready()
837 if (test_and_set_bit_lock(0, &ns->ctrl->discard_page_busy)) in nvme_setup_discard()
840 range = page_address(ns->ctrl->discard_page); in nvme_setup_discard()
867 if (virt_to_page(range) == ns->ctrl->discard_page) in nvme_setup_discard()
868 clear_bit_unlock(0, &ns->ctrl->discard_page_busy); in nvme_setup_discard()
921 if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_setup_write_zeroes()
1046 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_cleanup_cmd() local
1048 if (req->special_vec.bv_page == ctrl->discard_page) in nvme_cleanup_cmd()
1049 clear_bit_unlock(0, &ctrl->discard_page_busy); in nvme_cleanup_cmd()
1182 u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_command_effects() argument
1189 dev_warn_once(ctrl->device, in nvme_command_effects()
1200 effects = le32_to_cpu(ctrl->effects->acs[opcode]); in nvme_command_effects()
1211 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_passthru_start() argument
1213 u32 effects = nvme_command_effects(ctrl, ns, opcode); in nvme_passthru_start()
1220 mutex_lock(&ctrl->scan_lock); in nvme_passthru_start()
1221 mutex_lock(&ctrl->subsys->lock); in nvme_passthru_start()
1222 nvme_mpath_start_freeze(ctrl->subsys); in nvme_passthru_start()
1223 nvme_mpath_wait_freeze(ctrl->subsys); in nvme_passthru_start()
1224 nvme_start_freeze(ctrl); in nvme_passthru_start()
1225 nvme_wait_freeze(ctrl); in nvme_passthru_start()
1231 void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, in nvme_passthru_end() argument
1235 nvme_unfreeze(ctrl); in nvme_passthru_end()
1236 nvme_mpath_unfreeze(ctrl->subsys); in nvme_passthru_end()
1237 mutex_unlock(&ctrl->subsys->lock); in nvme_passthru_end()
1238 mutex_unlock(&ctrl->scan_lock); in nvme_passthru_end()
1242 &ctrl->flags)) { in nvme_passthru_end()
1243 dev_info(ctrl->device, in nvme_passthru_end()
1248 nvme_queue_scan(ctrl); in nvme_passthru_end()
1249 flush_work(&ctrl->scan_work); in nvme_passthru_end()
1264 nvme_update_keep_alive(ctrl, cmd); in nvme_passthru_end()
1282 static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl) in nvme_keep_alive_work_period() argument
1284 unsigned long delay = ctrl->kato * HZ / 2; in nvme_keep_alive_work_period()
1292 if (ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) in nvme_keep_alive_work_period()
1297 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) in nvme_queue_keep_alive_work() argument
1300 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_queue_keep_alive_work()
1301 unsigned long ka_next_check_tm = ctrl->ka_last_check_time + delay; in nvme_queue_keep_alive_work()
1308 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_queue_keep_alive_work()
1314 struct nvme_ctrl *ctrl = rq->end_io_data; in nvme_keep_alive_end_io() local
1316 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_keep_alive_end_io()
1317 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_keep_alive_end_io()
1326 dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n", in nvme_keep_alive_end_io()
1334 dev_err(ctrl->device, in nvme_keep_alive_end_io()
1340 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_end_io()
1341 ctrl->comp_seen = false; in nvme_keep_alive_end_io()
1343 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_keep_alive_end_io()
1349 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_keep_alive_work() local
1351 bool comp_seen = ctrl->comp_seen; in nvme_keep_alive_work()
1354 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_work()
1356 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { in nvme_keep_alive_work()
1357 dev_dbg(ctrl->device, in nvme_keep_alive_work()
1359 ctrl->comp_seen = false; in nvme_keep_alive_work()
1360 nvme_queue_keep_alive_work(ctrl); in nvme_keep_alive_work()
1364 rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd), in nvme_keep_alive_work()
1368 dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq)); in nvme_keep_alive_work()
1369 nvme_reset_ctrl(ctrl); in nvme_keep_alive_work()
1372 nvme_init_request(rq, &ctrl->ka_cmd); in nvme_keep_alive_work()
1374 rq->timeout = ctrl->kato * HZ; in nvme_keep_alive_work()
1376 rq->end_io_data = ctrl; in nvme_keep_alive_work()
1380 static void nvme_start_keep_alive(struct nvme_ctrl *ctrl) in nvme_start_keep_alive() argument
1382 if (unlikely(ctrl->kato == 0)) in nvme_start_keep_alive()
1385 nvme_queue_keep_alive_work(ctrl); in nvme_start_keep_alive()
1388 void nvme_stop_keep_alive(struct nvme_ctrl *ctrl) in nvme_stop_keep_alive() argument
1390 if (unlikely(ctrl->kato == 0)) in nvme_stop_keep_alive()
1393 cancel_delayed_work_sync(&ctrl->ka_work); in nvme_stop_keep_alive()
1397 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, in nvme_update_keep_alive() argument
1403 dev_info(ctrl->device, in nvme_update_keep_alive()
1405 ctrl->kato * 1000 / 2, new_kato * 1000 / 2); in nvme_update_keep_alive()
1407 nvme_stop_keep_alive(ctrl); in nvme_update_keep_alive()
1408 ctrl->kato = new_kato; in nvme_update_keep_alive()
1409 nvme_start_keep_alive(ctrl); in nvme_update_keep_alive()
1412 static bool nvme_id_cns_ok(struct nvme_ctrl *ctrl, u8 cns) in nvme_id_cns_ok() argument
1417 if (ctrl->vs >= NVME_VS(1, 2, 0)) in nvme_id_cns_ok()
1428 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_id_cns_ok()
1429 !(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) in nvme_id_cns_ok()
1460 static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, in nvme_process_ns_desc() argument
1463 const char *warn_str = "ctrl returned bogus length:"; in nvme_process_ns_desc()
1469 dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n", in nvme_process_ns_desc()
1473 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1479 dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n", in nvme_process_ns_desc()
1483 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1489 dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n", in nvme_process_ns_desc()
1493 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1499 dev_warn(ctrl->device, "%s %d for NVME_NIDT_CSI\n", in nvme_process_ns_desc()
1512 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, in nvme_identify_ns_descs() argument
1520 if (ctrl->vs < NVME_VS(1, 3, 0) && !nvme_multi_css(ctrl)) in nvme_identify_ns_descs()
1522 if (ctrl->quirks & NVME_QUIRK_NO_NS_DESC_LIST) in nvme_identify_ns_descs()
1533 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data, in nvme_identify_ns_descs()
1536 dev_warn(ctrl->device, in nvme_identify_ns_descs()
1548 len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); in nvme_identify_ns_descs()
1555 if (nvme_multi_css(ctrl) && !csi_seen) { in nvme_identify_ns_descs()
1556 dev_warn(ctrl->device, "Command set not reported for nsid:%d\n", in nvme_identify_ns_descs()
1566 int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, in nvme_identify_ns() argument
1581 error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id)); in nvme_identify_ns()
1583 dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error); in nvme_identify_ns()
1590 static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, in nvme_ns_info_from_identify() argument
1597 ret = nvme_identify_ns(ctrl, info->nsid, &id); in nvme_ns_info_from_identify()
1612 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) { in nvme_ns_info_from_identify()
1613 dev_info(ctrl->device, in nvme_ns_info_from_identify()
1616 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_ns_info_from_identify()
1619 if (ctrl->vs >= NVME_VS(1, 2, 0) && in nvme_ns_info_from_identify()
1629 static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, in nvme_ns_info_from_id_cs_indep() argument
1644 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_ns_info_from_id_cs_indep()
1693 int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) in nvme_set_queue_count() argument
1699 status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0, in nvme_set_queue_count()
1716 dev_err(ctrl->device, "Could not set queue count (%d)\n", status); in nvme_set_queue_count()
1731 static void nvme_enable_aen(struct nvme_ctrl *ctrl) in nvme_enable_aen() argument
1733 u32 result, supported_aens = ctrl->oaes & NVME_AEN_SUPPORTED; in nvme_enable_aen()
1739 status = nvme_set_features(ctrl, NVME_FEAT_ASYNC_EVENT, supported_aens, in nvme_enable_aen()
1742 dev_warn(ctrl->device, "Failed to configure AEN (cfg %x)\n", in nvme_enable_aen()
1745 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_enable_aen()
1756 if (!try_module_get(ns->ctrl->ops->module)) in nvme_ns_open()
1770 module_put(ns->ctrl->ops->module); in nvme_ns_release()
1858 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_config_discard() local
1860 if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns->head, UINT_MAX)) in nvme_config_discard()
1862 nvme_lba_to_sect(ns->head, ctrl->dmrsl); in nvme_config_discard()
1863 else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) in nvme_config_discard()
1870 if (ctrl->dmrl) in nvme_config_discard()
1871 lim->max_discard_segments = ctrl->dmrl; in nvme_config_discard()
1884 static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid, in nvme_identify_ns_nvm() argument
1900 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm)); in nvme_identify_ns_nvm()
1936 static void nvme_configure_metadata(struct nvme_ctrl *ctrl, in nvme_configure_metadata() argument
1944 if (!head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) in nvme_configure_metadata()
1947 if (nvm && (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { in nvme_configure_metadata()
1963 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_configure_metadata()
1983 if (ctrl->max_integrity_segments && nvme_ns_has_pi(head)) in nvme_configure_metadata()
2017 static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl) in nvme_max_drv_segments() argument
2019 return ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> SECTOR_SHIFT) + 1; in nvme_max_drv_segments()
2022 static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl, in nvme_set_ctrl_limits() argument
2025 lim->max_hw_sectors = ctrl->max_hw_sectors; in nvme_set_ctrl_limits()
2027 min_not_zero(nvme_max_drv_segments(ctrl), ctrl->max_segments)); in nvme_set_ctrl_limits()
2028 lim->max_integrity_segments = ctrl->max_integrity_segments; in nvme_set_ctrl_limits()
2062 atomic_bs = (1 + ns->ctrl->awupf) * bs; in nvme_update_disk_info()
2067 if (ns->ctrl->subsys->atomic_bs) { in nvme_update_disk_info()
2068 if (atomic_bs != ns->ctrl->subsys->atomic_bs) { in nvme_update_disk_info()
2069 dev_err_ratelimited(ns->ctrl->device, in nvme_update_disk_info()
2072 ns->ctrl->subsys->atomic_bs, in nvme_update_disk_info()
2076 ns->ctrl->subsys->atomic_bs = atomic_bs; in nvme_update_disk_info()
2098 if ((ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) && in nvme_update_disk_info()
2099 (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM)) in nvme_update_disk_info()
2102 lim->max_write_zeroes_sectors = ns->ctrl->max_zeroes_sectors; in nvme_update_disk_info()
2120 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_set_chunk_sectors() local
2123 if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) && in nvme_set_chunk_sectors()
2124 is_power_of_2(ctrl->max_hw_sectors)) in nvme_set_chunk_sectors()
2125 iob = ctrl->max_hw_sectors; in nvme_set_chunk_sectors()
2157 nvme_set_ctrl_limits(ns->ctrl, &lim); in nvme_update_ns_info_generic()
2182 ret = nvme_identify_ns(ns->ctrl, info->nsid, &id); in nvme_update_ns_info_block()
2194 if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) { in nvme_update_ns_info_block()
2195 ret = nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); in nvme_update_ns_info_block()
2213 nvme_set_ctrl_limits(ns->ctrl, &lim); in nvme_update_ns_info_block()
2214 nvme_configure_metadata(ns->ctrl, ns->head, id, nvm, info); in nvme_update_ns_info_block()
2223 if (lim.atomic_write_hw_max > ns->ctrl->subsys->atomic_bs) { in nvme_update_ns_info_block()
2234 if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc) in nvme_update_ns_info_block()
2292 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2304 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2396 struct nvme_ctrl *ctrl = data; in nvme_sec_submit() local
2407 return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len, in nvme_sec_submit()
2411 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2413 if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) { in nvme_configure_opal()
2414 if (!ctrl->opal_dev) in nvme_configure_opal()
2415 ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit); in nvme_configure_opal()
2417 opal_unlock_from_suspend(ctrl->opal_dev); in nvme_configure_opal()
2419 free_opal_dev(ctrl->opal_dev); in nvme_configure_opal()
2420 ctrl->opal_dev = NULL; in nvme_configure_opal()
2424 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2452 static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val, in nvme_wait_ready() argument
2459 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_wait_ready()
2469 dev_err(ctrl->device, in nvme_wait_ready()
2479 int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown) in nvme_disable_ctrl() argument
2483 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_disable_ctrl()
2485 ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; in nvme_disable_ctrl()
2487 ctrl->ctrl_config &= ~NVME_CC_ENABLE; in nvme_disable_ctrl()
2489 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_disable_ctrl()
2494 return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK, in nvme_disable_ctrl()
2496 ctrl->shutdown_timeout, "shutdown"); in nvme_disable_ctrl()
2498 if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY) in nvme_disable_ctrl()
2500 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, 0, in nvme_disable_ctrl()
2501 (NVME_CAP_TIMEOUT(ctrl->cap) + 1) / 2, "reset"); in nvme_disable_ctrl()
2505 int nvme_enable_ctrl(struct nvme_ctrl *ctrl) in nvme_enable_ctrl() argument
2511 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2513 dev_err(ctrl->device, "Reading CAP failed (%d)\n", ret); in nvme_enable_ctrl()
2516 dev_page_min = NVME_CAP_MPSMIN(ctrl->cap) + 12; in nvme_enable_ctrl()
2519 dev_err(ctrl->device, in nvme_enable_ctrl()
2525 if (NVME_CAP_CSS(ctrl->cap) & NVME_CAP_CSS_CSI) in nvme_enable_ctrl()
2526 ctrl->ctrl_config = NVME_CC_CSS_CSI; in nvme_enable_ctrl()
2528 ctrl->ctrl_config = NVME_CC_CSS_NVM; in nvme_enable_ctrl()
2536 ctrl->ctrl_config &= ~NVME_CC_CRIME; in nvme_enable_ctrl()
2538 ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT; in nvme_enable_ctrl()
2539 ctrl->ctrl_config |= NVME_CC_AMS_RR | NVME_CC_SHN_NONE; in nvme_enable_ctrl()
2540 ctrl->ctrl_config |= NVME_CC_IOSQES | NVME_CC_IOCQES; in nvme_enable_ctrl()
2541 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2546 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2550 timeout = NVME_CAP_TIMEOUT(ctrl->cap); in nvme_enable_ctrl()
2551 if (ctrl->cap & NVME_CAP_CRMS_CRWMS) { in nvme_enable_ctrl()
2554 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CRTO, &crto); in nvme_enable_ctrl()
2556 dev_err(ctrl->device, "Reading CRTO failed (%d)\n", in nvme_enable_ctrl()
2569 dev_warn_once(ctrl->device, "bad crto:%x cap:%llx\n", in nvme_enable_ctrl()
2570 crto, ctrl->cap); in nvme_enable_ctrl()
2575 ctrl->ctrl_config |= NVME_CC_ENABLE; in nvme_enable_ctrl()
2576 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2579 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, NVME_CSTS_RDY, in nvme_enable_ctrl()
2584 static int nvme_configure_timestamp(struct nvme_ctrl *ctrl) in nvme_configure_timestamp() argument
2589 if (!(ctrl->oncs & NVME_CTRL_ONCS_TIMESTAMP)) in nvme_configure_timestamp()
2593 ret = nvme_set_features(ctrl, NVME_FEAT_TIMESTAMP, 0, &ts, sizeof(ts), in nvme_configure_timestamp()
2596 dev_warn_once(ctrl->device, in nvme_configure_timestamp()
2601 static int nvme_configure_host_options(struct nvme_ctrl *ctrl) in nvme_configure_host_options() argument
2608 if (ctrl->crdt[0]) in nvme_configure_host_options()
2610 if (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) in nvme_configure_host_options()
2622 ret = nvme_set_features(ctrl, NVME_FEAT_HOST_BEHAVIOR, 0, in nvme_configure_host_options()
2682 static int nvme_configure_apst(struct nvme_ctrl *ctrl) in nvme_configure_apst() argument
2697 if (!ctrl->apsta) in nvme_configure_apst()
2700 if (ctrl->npss > 31) { in nvme_configure_apst()
2701 dev_warn(ctrl->device, "NPSS is invalid; not using APST\n"); in nvme_configure_apst()
2709 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) { in nvme_configure_apst()
2711 dev_dbg(ctrl->device, "APST disabled\n"); in nvme_configure_apst()
2721 for (state = (int)ctrl->npss; state >= 0; state--) { in nvme_configure_apst()
2731 if (state == ctrl->npss && in nvme_configure_apst()
2732 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) in nvme_configure_apst()
2739 if (!(ctrl->psd[state].flags & NVME_PS_FLAGS_NON_OP_STATE)) in nvme_configure_apst()
2742 exit_latency_us = (u64)le32_to_cpu(ctrl->psd[state].exit_lat); in nvme_configure_apst()
2743 if (exit_latency_us > ctrl->ps_max_latency_us) in nvme_configure_apst()
2747 le32_to_cpu(ctrl->psd[state].entry_lat); in nvme_configure_apst()
2772 dev_dbg(ctrl->device, "APST enabled but no non-operational states are available\n"); in nvme_configure_apst()
2774 …dev_dbg(ctrl->device, "APST enabled: max PS = %d, max round-trip latency = %lluus, table = %*phN\n… in nvme_configure_apst()
2779 ret = nvme_set_features(ctrl, NVME_FEAT_AUTO_PST, apste, in nvme_configure_apst()
2782 dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret); in nvme_configure_apst()
2789 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_set_latency_tolerance() local
2802 if (ctrl->ps_max_latency_us != latency) { in nvme_set_latency_tolerance()
2803 ctrl->ps_max_latency_us = latency; in nvme_set_latency_tolerance()
2804 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_set_latency_tolerance()
2805 nvme_configure_apst(ctrl); in nvme_set_latency_tolerance()
2900 static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ctrl, in nvme_init_subnqn() argument
2906 if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) { in nvme_init_subnqn()
2913 if (ctrl->vs >= NVME_VS(1, 2, 1)) in nvme_init_subnqn()
2914 dev_warn(ctrl->device, "missing or invalid SUBNQN field.\n"); in nvme_init_subnqn()
2989 static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) in nvme_discovery_ctrl() argument
2991 return ctrl->opts && ctrl->opts->discovery_nqn; in nvme_discovery_ctrl()
2995 struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_validate_cntlid() argument
3005 if (tmp->cntlid == ctrl->cntlid) { in nvme_validate_cntlid()
3006 dev_err(ctrl->device, in nvme_validate_cntlid()
3008 ctrl->cntlid, dev_name(tmp->device), in nvme_validate_cntlid()
3014 nvme_discovery_ctrl(ctrl)) in nvme_validate_cntlid()
3017 dev_err(ctrl->device, in nvme_validate_cntlid()
3025 static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_subsystem() argument
3039 nvme_init_subnqn(subsys, ctrl, id); in nvme_init_subsystem()
3052 if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) { in nvme_init_subsystem()
3053 dev_err(ctrl->device, in nvme_init_subsystem()
3064 dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); in nvme_init_subsystem()
3073 if (!nvme_validate_cntlid(subsys, ctrl, id)) { in nvme_init_subsystem()
3080 dev_err(ctrl->device, in nvme_init_subsystem()
3089 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, in nvme_init_subsystem()
3090 dev_name(ctrl->device)); in nvme_init_subsystem()
3092 dev_err(ctrl->device, in nvme_init_subsystem()
3098 subsys->instance = ctrl->instance; in nvme_init_subsystem()
3099 ctrl->subsys = subsys; in nvme_init_subsystem()
3100 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvme_init_subsystem()
3111 int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, in nvme_get_log() argument
3127 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); in nvme_get_log()
3130 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi, in nvme_get_effects_log() argument
3133 struct nvme_effects_log *old, *cel = xa_load(&ctrl->cels, csi); in nvme_get_effects_log()
3143 ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi, in nvme_get_effects_log()
3150 old = xa_store(&ctrl->cels, csi, cel, GFP_KERNEL); in nvme_get_effects_log()
3160 static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units) in nvme_mps_to_sectors() argument
3162 u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; in nvme_mps_to_sectors()
3169 static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) in nvme_init_non_mdts_limits() argument
3181 if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && in nvme_init_non_mdts_limits()
3182 !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) in nvme_init_non_mdts_limits()
3183 ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; in nvme_init_non_mdts_limits()
3185 ctrl->max_zeroes_sectors = 0; in nvme_init_non_mdts_limits()
3187 if (ctrl->subsys->subtype != NVME_NQN_NVME || in nvme_init_non_mdts_limits()
3188 !nvme_id_cns_ok(ctrl, NVME_ID_CNS_CS_CTRL) || in nvme_init_non_mdts_limits()
3189 test_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags)) in nvme_init_non_mdts_limits()
3200 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_init_non_mdts_limits()
3204 ctrl->dmrl = id->dmrl; in nvme_init_non_mdts_limits()
3205 ctrl->dmrsl = le32_to_cpu(id->dmrsl); in nvme_init_non_mdts_limits()
3207 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); in nvme_init_non_mdts_limits()
3211 set_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags); in nvme_init_non_mdts_limits()
3216 static int nvme_init_effects_log(struct nvme_ctrl *ctrl, in nvme_init_effects_log() argument
3225 old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL); in nvme_init_effects_log()
3235 static void nvme_init_known_nvm_effects(struct nvme_ctrl *ctrl) in nvme_init_known_nvm_effects() argument
3237 struct nvme_effects_log *log = ctrl->effects; in nvme_init_known_nvm_effects()
3267 static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_effects() argument
3271 if (ctrl->effects) in nvme_init_effects()
3275 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3280 if (!ctrl->effects) { in nvme_init_effects()
3281 ret = nvme_init_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3286 nvme_init_known_nvm_effects(ctrl); in nvme_init_effects()
3290 static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_check_ctrl_fabric_info() argument
3296 if (ctrl->cntlid != le16_to_cpu(id->cntlid)) { in nvme_check_ctrl_fabric_info()
3297 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3299 ctrl->cntlid, le16_to_cpu(id->cntlid)); in nvme_check_ctrl_fabric_info()
3303 if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) { in nvme_check_ctrl_fabric_info()
3304 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3309 if (!nvme_discovery_ctrl(ctrl) && ctrl->ioccsz < 4) { in nvme_check_ctrl_fabric_info()
3310 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3312 ctrl->ioccsz); in nvme_check_ctrl_fabric_info()
3316 if (!nvme_discovery_ctrl(ctrl) && ctrl->iorcsz < 1) { in nvme_check_ctrl_fabric_info()
3317 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3319 ctrl->iorcsz); in nvme_check_ctrl_fabric_info()
3323 if (!ctrl->maxcmd) { in nvme_check_ctrl_fabric_info()
3324 dev_warn(ctrl->device, in nvme_check_ctrl_fabric_info()
3326 ctrl->maxcmd = ctrl->sqsize + 1; in nvme_check_ctrl_fabric_info()
3332 static int nvme_init_identify(struct nvme_ctrl *ctrl) in nvme_init_identify() argument
3340 ret = nvme_identify_ctrl(ctrl, &id); in nvme_init_identify()
3342 dev_err(ctrl->device, "Identify Controller failed (%d)\n", ret); in nvme_init_identify()
3346 if (!(ctrl->ops->flags & NVME_F_FABRICS)) in nvme_init_identify()
3347 ctrl->cntlid = le16_to_cpu(id->cntlid); in nvme_init_identify()
3349 if (!ctrl->identified) { in nvme_init_identify()
3362 ctrl->quirks |= core_quirks[i].quirks; in nvme_init_identify()
3365 ret = nvme_init_subsystem(ctrl, id); in nvme_init_identify()
3369 ret = nvme_init_effects(ctrl, id); in nvme_init_identify()
3373 memcpy(ctrl->subsys->firmware_rev, id->fr, in nvme_init_identify()
3374 sizeof(ctrl->subsys->firmware_rev)); in nvme_init_identify()
3376 if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) { in nvme_init_identify()
3377 …dev_warn(ctrl->device, "forcibly allowing all power states due to nvme_core.force_apst -- use at y… in nvme_init_identify()
3378 ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS; in nvme_init_identify()
3381 ctrl->crdt[0] = le16_to_cpu(id->crdt1); in nvme_init_identify()
3382 ctrl->crdt[1] = le16_to_cpu(id->crdt2); in nvme_init_identify()
3383 ctrl->crdt[2] = le16_to_cpu(id->crdt3); in nvme_init_identify()
3385 ctrl->oacs = le16_to_cpu(id->oacs); in nvme_init_identify()
3386 ctrl->oncs = le16_to_cpu(id->oncs); in nvme_init_identify()
3387 ctrl->mtfa = le16_to_cpu(id->mtfa); in nvme_init_identify()
3388 ctrl->oaes = le32_to_cpu(id->oaes); in nvme_init_identify()
3389 ctrl->wctemp = le16_to_cpu(id->wctemp); in nvme_init_identify()
3390 ctrl->cctemp = le16_to_cpu(id->cctemp); in nvme_init_identify()
3392 atomic_set(&ctrl->abort_limit, id->acl + 1); in nvme_init_identify()
3393 ctrl->vwc = id->vwc; in nvme_init_identify()
3395 max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); in nvme_init_identify()
3398 ctrl->max_hw_sectors = in nvme_init_identify()
3399 min_not_zero(ctrl->max_hw_sectors, max_hw_sectors); in nvme_init_identify()
3401 lim = queue_limits_start_update(ctrl->admin_q); in nvme_init_identify()
3402 nvme_set_ctrl_limits(ctrl, &lim); in nvme_init_identify()
3403 ret = queue_limits_commit_update(ctrl->admin_q, &lim); in nvme_init_identify()
3407 ctrl->sgls = le32_to_cpu(id->sgls); in nvme_init_identify()
3408 ctrl->kas = le16_to_cpu(id->kas); in nvme_init_identify()
3409 ctrl->max_namespaces = le32_to_cpu(id->mnan); in nvme_init_identify()
3410 ctrl->ctratt = le32_to_cpu(id->ctratt); in nvme_init_identify()
3412 ctrl->cntrltype = id->cntrltype; in nvme_init_identify()
3413 ctrl->dctype = id->dctype; in nvme_init_identify()
3419 ctrl->shutdown_timeout = clamp_t(unsigned int, transition_time, in nvme_init_identify()
3422 if (ctrl->shutdown_timeout != shutdown_timeout) in nvme_init_identify()
3423 dev_info(ctrl->device, in nvme_init_identify()
3425 ctrl->shutdown_timeout); in nvme_init_identify()
3427 ctrl->shutdown_timeout = shutdown_timeout; in nvme_init_identify()
3429 ctrl->npss = id->npss; in nvme_init_identify()
3430 ctrl->apsta = id->apsta; in nvme_init_identify()
3431 prev_apst_enabled = ctrl->apst_enabled; in nvme_init_identify()
3432 if (ctrl->quirks & NVME_QUIRK_NO_APST) { in nvme_init_identify()
3434 …dev_warn(ctrl->device, "forcibly allowing APST due to nvme_core.force_apst -- use at your own risk… in nvme_init_identify()
3435 ctrl->apst_enabled = true; in nvme_init_identify()
3437 ctrl->apst_enabled = false; in nvme_init_identify()
3440 ctrl->apst_enabled = id->apsta; in nvme_init_identify()
3442 memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd)); in nvme_init_identify()
3444 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_init_identify()
3445 ctrl->icdoff = le16_to_cpu(id->icdoff); in nvme_init_identify()
3446 ctrl->ioccsz = le32_to_cpu(id->ioccsz); in nvme_init_identify()
3447 ctrl->iorcsz = le32_to_cpu(id->iorcsz); in nvme_init_identify()
3448 ctrl->maxcmd = le16_to_cpu(id->maxcmd); in nvme_init_identify()
3450 ret = nvme_check_ctrl_fabric_info(ctrl, id); in nvme_init_identify()
3454 ctrl->hmpre = le32_to_cpu(id->hmpre); in nvme_init_identify()
3455 ctrl->hmmin = le32_to_cpu(id->hmmin); in nvme_init_identify()
3456 ctrl->hmminds = le32_to_cpu(id->hmminds); in nvme_init_identify()
3457 ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); in nvme_init_identify()
3460 ret = nvme_mpath_init_identify(ctrl, id); in nvme_init_identify()
3464 if (ctrl->apst_enabled && !prev_apst_enabled) in nvme_init_identify()
3465 dev_pm_qos_expose_latency_tolerance(ctrl->device); in nvme_init_identify()
3466 else if (!ctrl->apst_enabled && prev_apst_enabled) in nvme_init_identify()
3467 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_identify()
3468 ctrl->awupf = le16_to_cpu(id->awupf); in nvme_init_identify()
3479 int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_init_ctrl_finish() argument
3483 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); in nvme_init_ctrl_finish()
3485 dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); in nvme_init_ctrl_finish()
3489 ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); in nvme_init_ctrl_finish()
3491 if (ctrl->vs >= NVME_VS(1, 1, 0)) in nvme_init_ctrl_finish()
3492 ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); in nvme_init_ctrl_finish()
3494 ret = nvme_init_identify(ctrl); in nvme_init_ctrl_finish()
3498 ret = nvme_configure_apst(ctrl); in nvme_init_ctrl_finish()
3502 ret = nvme_configure_timestamp(ctrl); in nvme_init_ctrl_finish()
3506 ret = nvme_configure_host_options(ctrl); in nvme_init_ctrl_finish()
3510 nvme_configure_opal(ctrl, was_suspended); in nvme_init_ctrl_finish()
3512 if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3517 ret = nvme_hwmon_init(ctrl); in nvme_init_ctrl_finish()
3522 clear_bit(NVME_CTRL_DIRTY_CAPABILITY, &ctrl->flags); in nvme_init_ctrl_finish()
3523 ctrl->identified = true; in nvme_init_ctrl_finish()
3525 nvme_start_keep_alive(ctrl); in nvme_init_ctrl_finish()
3533 struct nvme_ctrl *ctrl = in nvme_dev_open() local
3536 switch (nvme_ctrl_state(ctrl)) { in nvme_dev_open()
3543 nvme_get_ctrl(ctrl); in nvme_dev_open()
3544 if (!try_module_get(ctrl->ops->module)) { in nvme_dev_open()
3545 nvme_put_ctrl(ctrl); in nvme_dev_open()
3549 file->private_data = ctrl; in nvme_dev_open()
3555 struct nvme_ctrl *ctrl = in nvme_dev_release() local
3558 module_put(ctrl->ops->module); in nvme_dev_release()
3559 nvme_put_ctrl(ctrl); in nvme_dev_release()
3572 static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, in nvme_find_ns_head() argument
3577 lockdep_assert_held(&ctrl->subsys->lock); in nvme_find_ns_head()
3579 list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { in nvme_find_ns_head()
3585 if (h->ns_id != nsid || !nvme_is_unique_nsid(ctrl, h)) in nvme_find_ns_head()
3675 ns->cdev_device.parent = ns->ctrl->device; in nvme_add_ns_cdev()
3677 ns->ctrl->instance, ns->head->instance); in nvme_add_ns_cdev()
3682 ns->ctrl->ops->module); in nvme_add_ns_cdev()
3685 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, in nvme_alloc_ns_head() argument
3699 ret = ida_alloc_min(&ctrl->subsys->ns_ida, 1, GFP_KERNEL); in nvme_alloc_ns_head()
3707 head->subsys = ctrl->subsys; in nvme_alloc_ns_head()
3717 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); in nvme_alloc_ns_head()
3721 head->effects = ctrl->effects; in nvme_alloc_ns_head()
3723 ret = nvme_mpath_alloc_disk(ctrl, head); in nvme_alloc_ns_head()
3727 list_add_tail(&head->entry, &ctrl->subsys->nsheads); in nvme_alloc_ns_head()
3729 kref_get(&ctrl->subsys->ref); in nvme_alloc_ns_head()
3735 ida_free(&ctrl->subsys->ns_ida, head->instance); in nvme_alloc_ns_head()
3772 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ns_head() local
3776 ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3794 nvme_print_device_info(ctrl); in nvme_init_ns_head()
3795 if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ in nvme_init_ns_head()
3796 ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && in nvme_init_ns_head()
3798 dev_err(ctrl->device, in nvme_init_ns_head()
3804 dev_err(ctrl->device, in nvme_init_ns_head()
3806 dev_err(ctrl->device, in nvme_init_ns_head()
3811 ctrl->quirks |= NVME_QUIRK_BOGUS_NID; in nvme_init_ns_head()
3814 mutex_lock(&ctrl->subsys->lock); in nvme_init_ns_head()
3815 head = nvme_find_ns_head(ctrl, info->nsid); in nvme_init_ns_head()
3817 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3819 dev_err(ctrl->device, in nvme_init_ns_head()
3824 head = nvme_alloc_ns_head(ctrl, info); in nvme_init_ns_head()
3832 dev_err(ctrl->device, in nvme_init_ns_head()
3838 dev_err(ctrl->device, in nvme_init_ns_head()
3845 dev_warn(ctrl->device, in nvme_init_ns_head()
3848 dev_warn_once(ctrl->device, in nvme_init_ns_head()
3855 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3861 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3865 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_find_get_ns() argument
3870 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_find_get_ns()
3871 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_find_get_ns()
3872 srcu_read_lock_held(&ctrl->srcu)) { in nvme_find_get_ns()
3882 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_find_get_ns()
3894 list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) { in nvme_ns_add_to_ctrl_list()
3900 list_add(&ns->list, &ns->ctrl->namespaces); in nvme_ns_add_to_ctrl_list()
3903 static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) in nvme_alloc_ns() argument
3908 int node = ctrl->numa_node; in nvme_alloc_ns()
3914 if (ctrl->opts && ctrl->opts->data_digest) in nvme_alloc_ns()
3916 if (ctrl->ops->supports_pci_p2pdma && in nvme_alloc_ns()
3917 ctrl->ops->supports_pci_p2pdma(ctrl)) in nvme_alloc_ns()
3920 disk = blk_mq_alloc_disk(ctrl->tagset, &lim, ns); in nvme_alloc_ns()
3928 ns->ctrl = ctrl; in nvme_alloc_ns()
3946 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3947 ctrl->instance, ns->head->instance); in nvme_alloc_ns()
3950 sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3953 sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, in nvme_alloc_ns()
3960 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3962 * Ensure that no namespaces are added to the ctrl list after the queues in nvme_alloc_ns()
3965 if (test_bit(NVME_CTRL_FROZEN, &ctrl->flags)) { in nvme_alloc_ns()
3966 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3970 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3971 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3972 nvme_get_ctrl(ctrl); in nvme_alloc_ns()
3974 if (device_add_disk(ctrl->device, ns->disk, nvme_ns_attr_groups)) in nvme_alloc_ns()
3993 nvme_put_ctrl(ctrl); in nvme_alloc_ns()
3994 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3996 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3997 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3999 mutex_lock(&ctrl->subsys->lock); in nvme_alloc_ns()
4003 mutex_unlock(&ctrl->subsys->lock); in nvme_alloc_ns()
4032 mutex_lock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4038 mutex_unlock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4050 mutex_lock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
4052 mutex_unlock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
4053 synchronize_srcu(&ns->ctrl->srcu); in nvme_ns_remove()
4060 static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) in nvme_ns_remove_by_nsid() argument
4062 struct nvme_ns *ns = nvme_find_get_ns(ctrl, nsid); in nvme_ns_remove_by_nsid()
4075 dev_err(ns->ctrl->device, in nvme_validate_ns()
4092 static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_scan_ns() argument
4098 if (nvme_identify_ns_descs(ctrl, &info)) in nvme_scan_ns()
4101 if (info.ids.csi != NVME_CSI_NVM && !nvme_multi_css(ctrl)) { in nvme_scan_ns()
4102 dev_warn(ctrl->device, in nvme_scan_ns()
4112 if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || in nvme_scan_ns()
4114 ctrl->vs >= NVME_VS(2, 0, 0)) in nvme_scan_ns()
4115 ret = nvme_ns_info_from_id_cs_indep(ctrl, &info); in nvme_scan_ns()
4117 ret = nvme_ns_info_from_identify(ctrl, &info); in nvme_scan_ns()
4120 nvme_ns_remove_by_nsid(ctrl, nsid); in nvme_scan_ns()
4129 ns = nvme_find_get_ns(ctrl, nsid); in nvme_scan_ns()
4134 nvme_alloc_ns(ctrl, &info); in nvme_scan_ns()
4140 * @ctrl: Controller on which namespaces are being scanned
4150 struct nvme_ctrl *ctrl; member
4164 nvme_scan_ns(scan_info->ctrl, nsid); in nvme_scan_ns_async()
4167 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, in nvme_remove_invalid_namespaces() argument
4173 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4174 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { in nvme_remove_invalid_namespaces()
4177 synchronize_srcu(&ctrl->srcu); in nvme_remove_invalid_namespaces()
4181 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4187 static int nvme_scan_ns_list(struct nvme_ctrl *ctrl) in nvme_scan_ns_list() argument
4200 scan_info.ctrl = ctrl; in nvme_scan_ns_list()
4209 ret = nvme_submit_sync_cmd(ctrl->admin_q, &cmd, ns_list, in nvme_scan_ns_list()
4212 dev_warn(ctrl->device, in nvme_scan_ns_list()
4226 nvme_ns_remove_by_nsid(ctrl, prev); in nvme_scan_ns_list()
4231 nvme_remove_invalid_namespaces(ctrl, prev); in nvme_scan_ns_list()
4238 static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl) in nvme_scan_ns_sequential() argument
4243 if (nvme_identify_ctrl(ctrl, &id)) in nvme_scan_ns_sequential()
4249 nvme_scan_ns(ctrl, i); in nvme_scan_ns_sequential()
4251 nvme_remove_invalid_namespaces(ctrl, nn); in nvme_scan_ns_sequential()
4254 static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl) in nvme_clear_changed_ns_log() argument
4270 error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_CHANGED_NS, 0, in nvme_clear_changed_ns_log()
4273 dev_warn(ctrl->device, in nvme_clear_changed_ns_log()
4281 struct nvme_ctrl *ctrl = in nvme_scan_work() local
4285 /* No tagset on a live ctrl means IO queues could not created */ in nvme_scan_work()
4286 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE || !ctrl->tagset) in nvme_scan_work()
4296 ret = nvme_init_non_mdts_limits(ctrl); in nvme_scan_work()
4298 dev_warn(ctrl->device, in nvme_scan_work()
4303 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { in nvme_scan_work()
4304 dev_info(ctrl->device, "rescanning namespaces.\n"); in nvme_scan_work()
4305 nvme_clear_changed_ns_log(ctrl); in nvme_scan_work()
4308 mutex_lock(&ctrl->scan_lock); in nvme_scan_work()
4309 if (!nvme_id_cns_ok(ctrl, NVME_ID_CNS_NS_ACTIVE_LIST)) { in nvme_scan_work()
4310 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4317 ret = nvme_scan_ns_list(ctrl); in nvme_scan_work()
4319 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4321 mutex_unlock(&ctrl->scan_lock); in nvme_scan_work()
4324 if (test_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) in nvme_scan_work()
4325 nvme_queue_scan(ctrl); in nvme_scan_work()
4327 else if (ctrl->ana_log_buf) in nvme_scan_work()
4329 queue_work(nvme_wq, &ctrl->ana_work); in nvme_scan_work()
4338 void nvme_remove_namespaces(struct nvme_ctrl *ctrl) in nvme_remove_namespaces() argument
4348 nvme_mpath_clear_ctrl_paths(ctrl); in nvme_remove_namespaces()
4354 nvme_unquiesce_io_queues(ctrl); in nvme_remove_namespaces()
4357 flush_work(&ctrl->scan_work); in nvme_remove_namespaces()
4365 if (nvme_ctrl_state(ctrl) == NVME_CTRL_DEAD) in nvme_remove_namespaces()
4366 nvme_mark_namespaces_dead(ctrl); in nvme_remove_namespaces()
4369 nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); in nvme_remove_namespaces()
4371 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4372 list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu); in nvme_remove_namespaces()
4373 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4374 synchronize_srcu(&ctrl->srcu); in nvme_remove_namespaces()
4383 const struct nvme_ctrl *ctrl = in nvme_class_uevent() local
4385 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_class_uevent()
4388 ret = add_uevent_var(env, "NVME_TRTYPE=%s", ctrl->ops->name); in nvme_class_uevent()
4413 static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata) in nvme_change_uevent() argument
4417 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_change_uevent()
4420 static void nvme_aen_uevent(struct nvme_ctrl *ctrl) in nvme_aen_uevent() argument
4423 u32 aen_result = ctrl->aen_result; in nvme_aen_uevent()
4425 ctrl->aen_result = 0; in nvme_aen_uevent()
4432 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_aen_uevent()
4438 struct nvme_ctrl *ctrl = in nvme_async_event_work() local
4441 nvme_aen_uevent(ctrl); in nvme_async_event_work()
4445 * flushing ctrl async_event_work after changing the controller state in nvme_async_event_work()
4448 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_async_event_work()
4449 ctrl->ops->submit_async_event(ctrl); in nvme_async_event_work()
4452 static bool nvme_ctrl_pp_status(struct nvme_ctrl *ctrl) in nvme_ctrl_pp_status() argument
4457 if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) in nvme_ctrl_pp_status()
4463 return ((ctrl->ctrl_config & NVME_CC_ENABLE) && (csts & NVME_CSTS_PP)); in nvme_ctrl_pp_status()
4466 static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl) in nvme_get_fw_slot_info() argument
4475 if (nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_FW_SLOT, 0, NVME_CSI_NVM, in nvme_get_fw_slot_info()
4477 dev_warn(ctrl->device, "Get FW SLOT INFO log error\n"); in nvme_get_fw_slot_info()
4484 dev_info(ctrl->device, in nvme_get_fw_slot_info()
4489 memcpy(ctrl->subsys->firmware_rev, &log->frs[cur_fw_slot - 1], in nvme_get_fw_slot_info()
4490 sizeof(ctrl->subsys->firmware_rev)); in nvme_get_fw_slot_info()
4498 struct nvme_ctrl *ctrl = container_of(work, in nvme_fw_act_work() local
4502 nvme_auth_stop(ctrl); in nvme_fw_act_work()
4504 if (ctrl->mtfa) in nvme_fw_act_work()
4505 fw_act_timeout = jiffies + msecs_to_jiffies(ctrl->mtfa * 100); in nvme_fw_act_work()
4509 nvme_quiesce_io_queues(ctrl); in nvme_fw_act_work()
4510 while (nvme_ctrl_pp_status(ctrl)) { in nvme_fw_act_work()
4512 dev_warn(ctrl->device, in nvme_fw_act_work()
4514 nvme_try_sched_reset(ctrl); in nvme_fw_act_work()
4520 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING) || in nvme_fw_act_work()
4521 !nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) in nvme_fw_act_work()
4524 nvme_unquiesce_io_queues(ctrl); in nvme_fw_act_work()
4526 nvme_get_fw_slot_info(ctrl); in nvme_fw_act_work()
4528 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_fw_act_work()
4541 static bool nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result) in nvme_handle_aen_notice() argument
4548 set_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events); in nvme_handle_aen_notice()
4549 nvme_queue_scan(ctrl); in nvme_handle_aen_notice()
4557 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) { in nvme_handle_aen_notice()
4559 queue_work(nvme_wq, &ctrl->fw_act_work); in nvme_handle_aen_notice()
4564 if (!ctrl->ana_log_buf) in nvme_handle_aen_notice()
4566 queue_work(nvme_wq, &ctrl->ana_work); in nvme_handle_aen_notice()
4570 ctrl->aen_result = result; in nvme_handle_aen_notice()
4573 dev_warn(ctrl->device, "async event result %08x\n", result); in nvme_handle_aen_notice()
4578 static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl) in nvme_handle_aer_persistent_error() argument
4580 dev_warn(ctrl->device, in nvme_handle_aer_persistent_error()
4582 nvme_reset_ctrl(ctrl); in nvme_handle_aer_persistent_error()
4585 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, in nvme_complete_async_event() argument
4596 trace_nvme_async_event(ctrl, result); in nvme_complete_async_event()
4599 requeue = nvme_handle_aen_notice(ctrl, result); in nvme_complete_async_event()
4607 nvme_handle_aer_persistent_error(ctrl); in nvme_complete_async_event()
4614 ctrl->aen_result = result; in nvme_complete_async_event()
4621 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_complete_async_event()
4625 int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_admin_tag_set() argument
4634 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_admin_tag_set()
4637 set->numa_node = ctrl->numa_node; in nvme_alloc_admin_tag_set()
4638 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_admin_tag_set()
4641 set->driver_data = ctrl; in nvme_alloc_admin_tag_set()
4648 ctrl->admin_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_admin_tag_set()
4649 if (IS_ERR(ctrl->admin_q)) { in nvme_alloc_admin_tag_set()
4650 ret = PTR_ERR(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4654 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_admin_tag_set()
4655 ctrl->fabrics_q = blk_mq_alloc_queue(set, NULL, NULL); in nvme_alloc_admin_tag_set()
4656 if (IS_ERR(ctrl->fabrics_q)) { in nvme_alloc_admin_tag_set()
4657 ret = PTR_ERR(ctrl->fabrics_q); in nvme_alloc_admin_tag_set()
4662 ctrl->admin_tagset = set; in nvme_alloc_admin_tag_set()
4666 blk_mq_destroy_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4667 blk_put_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4670 ctrl->admin_q = NULL; in nvme_alloc_admin_tag_set()
4671 ctrl->fabrics_q = NULL; in nvme_alloc_admin_tag_set()
4676 void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_admin_tag_set() argument
4682 nvme_stop_keep_alive(ctrl); in nvme_remove_admin_tag_set()
4683 blk_mq_destroy_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4684 blk_put_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4685 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_admin_tag_set()
4686 blk_mq_destroy_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4687 blk_put_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4689 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_remove_admin_tag_set()
4693 int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_io_tag_set() argument
4701 set->queue_depth = min_t(unsigned, ctrl->sqsize, BLK_MQ_MAX_DEPTH - 1); in nvme_alloc_io_tag_set()
4706 if (ctrl->quirks & NVME_QUIRK_SHARED_TAGS) in nvme_alloc_io_tag_set()
4708 else if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_io_tag_set()
4711 set->numa_node = ctrl->numa_node; in nvme_alloc_io_tag_set()
4712 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_io_tag_set()
4715 set->driver_data = ctrl; in nvme_alloc_io_tag_set()
4716 set->nr_hw_queues = ctrl->queue_count - 1; in nvme_alloc_io_tag_set()
4723 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_io_tag_set()
4728 ctrl->connect_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_io_tag_set()
4729 if (IS_ERR(ctrl->connect_q)) { in nvme_alloc_io_tag_set()
4730 ret = PTR_ERR(ctrl->connect_q); in nvme_alloc_io_tag_set()
4735 ctrl->tagset = set; in nvme_alloc_io_tag_set()
4740 ctrl->connect_q = NULL; in nvme_alloc_io_tag_set()
4745 void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_io_tag_set() argument
4747 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_io_tag_set()
4748 blk_mq_destroy_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4749 blk_put_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4751 blk_mq_free_tag_set(ctrl->tagset); in nvme_remove_io_tag_set()
4755 void nvme_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_stop_ctrl() argument
4757 nvme_mpath_stop(ctrl); in nvme_stop_ctrl()
4758 nvme_auth_stop(ctrl); in nvme_stop_ctrl()
4759 nvme_stop_failfast_work(ctrl); in nvme_stop_ctrl()
4760 flush_work(&ctrl->async_event_work); in nvme_stop_ctrl()
4761 cancel_work_sync(&ctrl->fw_act_work); in nvme_stop_ctrl()
4762 if (ctrl->ops->stop_ctrl) in nvme_stop_ctrl()
4763 ctrl->ops->stop_ctrl(ctrl); in nvme_stop_ctrl()
4767 void nvme_start_ctrl(struct nvme_ctrl *ctrl) in nvme_start_ctrl() argument
4769 nvme_enable_aen(ctrl); in nvme_start_ctrl()
4777 if (test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags) && in nvme_start_ctrl()
4778 nvme_discovery_ctrl(ctrl)) in nvme_start_ctrl()
4779 nvme_change_uevent(ctrl, "NVME_EVENT=rediscover"); in nvme_start_ctrl()
4781 if (ctrl->queue_count > 1) { in nvme_start_ctrl()
4782 nvme_queue_scan(ctrl); in nvme_start_ctrl()
4783 nvme_unquiesce_io_queues(ctrl); in nvme_start_ctrl()
4784 nvme_mpath_update(ctrl); in nvme_start_ctrl()
4787 nvme_change_uevent(ctrl, "NVME_EVENT=connected"); in nvme_start_ctrl()
4788 set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags); in nvme_start_ctrl()
4792 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) in nvme_uninit_ctrl() argument
4794 nvme_stop_keep_alive(ctrl); in nvme_uninit_ctrl()
4795 nvme_hwmon_exit(ctrl); in nvme_uninit_ctrl()
4796 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_uninit_ctrl()
4797 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_uninit_ctrl()
4798 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_uninit_ctrl()
4799 nvme_put_ctrl(ctrl); in nvme_uninit_ctrl()
4803 static void nvme_free_cels(struct nvme_ctrl *ctrl) in nvme_free_cels() argument
4808 xa_for_each(&ctrl->cels, i, cel) { in nvme_free_cels()
4809 xa_erase(&ctrl->cels, i); in nvme_free_cels()
4813 xa_destroy(&ctrl->cels); in nvme_free_cels()
4818 struct nvme_ctrl *ctrl = in nvme_free_ctrl() local
4820 struct nvme_subsystem *subsys = ctrl->subsys; in nvme_free_ctrl()
4822 if (!subsys || ctrl->instance != subsys->instance) in nvme_free_ctrl()
4823 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_free_ctrl()
4824 nvme_free_cels(ctrl); in nvme_free_ctrl()
4825 nvme_mpath_uninit(ctrl); in nvme_free_ctrl()
4826 cleanup_srcu_struct(&ctrl->srcu); in nvme_free_ctrl()
4827 nvme_auth_stop(ctrl); in nvme_free_ctrl()
4828 nvme_auth_free(ctrl); in nvme_free_ctrl()
4829 __free_page(ctrl->discard_page); in nvme_free_ctrl()
4830 free_opal_dev(ctrl->opal_dev); in nvme_free_ctrl()
4834 list_del(&ctrl->subsys_entry); in nvme_free_ctrl()
4835 sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device)); in nvme_free_ctrl()
4839 ctrl->ops->free_ctrl(ctrl); in nvme_free_ctrl()
4853 int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, in nvme_init_ctrl() argument
4858 WRITE_ONCE(ctrl->state, NVME_CTRL_NEW); in nvme_init_ctrl()
4859 ctrl->passthru_err_log_enabled = false; in nvme_init_ctrl()
4860 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_init_ctrl()
4861 spin_lock_init(&ctrl->lock); in nvme_init_ctrl()
4862 mutex_init(&ctrl->namespaces_lock); in nvme_init_ctrl()
4864 ret = init_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4868 mutex_init(&ctrl->scan_lock); in nvme_init_ctrl()
4869 INIT_LIST_HEAD(&ctrl->namespaces); in nvme_init_ctrl()
4870 xa_init(&ctrl->cels); in nvme_init_ctrl()
4871 ctrl->dev = dev; in nvme_init_ctrl()
4872 ctrl->ops = ops; in nvme_init_ctrl()
4873 ctrl->quirks = quirks; in nvme_init_ctrl()
4874 ctrl->numa_node = NUMA_NO_NODE; in nvme_init_ctrl()
4875 INIT_WORK(&ctrl->scan_work, nvme_scan_work); in nvme_init_ctrl()
4876 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); in nvme_init_ctrl()
4877 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); in nvme_init_ctrl()
4878 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); in nvme_init_ctrl()
4879 init_waitqueue_head(&ctrl->state_wq); in nvme_init_ctrl()
4881 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); in nvme_init_ctrl()
4882 INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); in nvme_init_ctrl()
4883 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); in nvme_init_ctrl()
4884 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; in nvme_init_ctrl()
4885 ctrl->ka_last_check_time = jiffies; in nvme_init_ctrl()
4889 ctrl->discard_page = alloc_page(GFP_KERNEL); in nvme_init_ctrl()
4890 if (!ctrl->discard_page) { in nvme_init_ctrl()
4898 ctrl->instance = ret; in nvme_init_ctrl()
4900 ret = nvme_auth_init_ctrl(ctrl); in nvme_init_ctrl()
4904 nvme_mpath_init_ctrl(ctrl); in nvme_init_ctrl()
4906 device_initialize(&ctrl->ctrl_device); in nvme_init_ctrl()
4907 ctrl->device = &ctrl->ctrl_device; in nvme_init_ctrl()
4908 ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt), in nvme_init_ctrl()
4909 ctrl->instance); in nvme_init_ctrl()
4910 ctrl->device->class = &nvme_class; in nvme_init_ctrl()
4911 ctrl->device->parent = ctrl->dev; in nvme_init_ctrl()
4913 ctrl->device->groups = ops->dev_attr_groups; in nvme_init_ctrl()
4915 ctrl->device->groups = nvme_dev_attr_groups; in nvme_init_ctrl()
4916 ctrl->device->release = nvme_free_ctrl; in nvme_init_ctrl()
4917 dev_set_drvdata(ctrl->device, ctrl); in nvme_init_ctrl()
4922 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_init_ctrl()
4924 if (ctrl->discard_page) in nvme_init_ctrl()
4925 __free_page(ctrl->discard_page); in nvme_init_ctrl()
4926 cleanup_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4933 * use nvme_uninit_ctrl() to properly free resources associated with the ctrl.
4935 int nvme_add_ctrl(struct nvme_ctrl *ctrl) in nvme_add_ctrl() argument
4939 ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance); in nvme_add_ctrl()
4943 cdev_init(&ctrl->cdev, &nvme_dev_fops); in nvme_add_ctrl()
4944 ctrl->cdev.owner = ctrl->ops->module; in nvme_add_ctrl()
4945 ret = cdev_device_add(&ctrl->cdev, ctrl->device); in nvme_add_ctrl()
4953 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; in nvme_add_ctrl()
4954 dev_pm_qos_update_user_latency_tolerance(ctrl->device, in nvme_add_ctrl()
4957 nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); in nvme_add_ctrl()
4958 nvme_get_ctrl(ctrl); in nvme_add_ctrl()
4965 void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl) in nvme_mark_namespaces_dead() argument
4970 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_mark_namespaces_dead()
4971 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_mark_namespaces_dead()
4972 srcu_read_lock_held(&ctrl->srcu)) in nvme_mark_namespaces_dead()
4974 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_mark_namespaces_dead()
4978 void nvme_unfreeze(struct nvme_ctrl *ctrl) in nvme_unfreeze() argument
4983 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_unfreeze()
4984 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_unfreeze()
4985 srcu_read_lock_held(&ctrl->srcu)) in nvme_unfreeze()
4987 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_unfreeze()
4988 clear_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_unfreeze()
4992 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout) in nvme_wait_freeze_timeout() argument
4997 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze_timeout()
4998 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze_timeout()
4999 srcu_read_lock_held(&ctrl->srcu)) { in nvme_wait_freeze_timeout()
5004 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze_timeout()
5009 void nvme_wait_freeze(struct nvme_ctrl *ctrl) in nvme_wait_freeze() argument
5014 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze()
5015 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze()
5016 srcu_read_lock_held(&ctrl->srcu)) in nvme_wait_freeze()
5018 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze()
5022 void nvme_start_freeze(struct nvme_ctrl *ctrl) in nvme_start_freeze() argument
5027 set_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_start_freeze()
5028 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_start_freeze()
5029 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_start_freeze()
5030 srcu_read_lock_held(&ctrl->srcu)) in nvme_start_freeze()
5037 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_start_freeze()
5041 void nvme_quiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_quiesce_io_queues() argument
5043 if (!ctrl->tagset) in nvme_quiesce_io_queues()
5045 if (!test_and_set_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_quiesce_io_queues()
5046 blk_mq_quiesce_tagset(ctrl->tagset); in nvme_quiesce_io_queues()
5048 blk_mq_wait_quiesce_done(ctrl->tagset); in nvme_quiesce_io_queues()
5052 void nvme_unquiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_unquiesce_io_queues() argument
5054 if (!ctrl->tagset) in nvme_unquiesce_io_queues()
5056 if (test_and_clear_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_unquiesce_io_queues()
5057 blk_mq_unquiesce_tagset(ctrl->tagset); in nvme_unquiesce_io_queues()
5061 void nvme_quiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_quiesce_admin_queue() argument
5063 if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_quiesce_admin_queue()
5064 blk_mq_quiesce_queue(ctrl->admin_q); in nvme_quiesce_admin_queue()
5066 blk_mq_wait_quiesce_done(ctrl->admin_q->tag_set); in nvme_quiesce_admin_queue()
5070 void nvme_unquiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_unquiesce_admin_queue() argument
5072 if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_unquiesce_admin_queue()
5073 blk_mq_unquiesce_queue(ctrl->admin_q); in nvme_unquiesce_admin_queue()
5077 void nvme_sync_io_queues(struct nvme_ctrl *ctrl) in nvme_sync_io_queues() argument
5082 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_sync_io_queues()
5083 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_sync_io_queues()
5084 srcu_read_lock_held(&ctrl->srcu)) in nvme_sync_io_queues()
5086 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_sync_io_queues()
5090 void nvme_sync_queues(struct nvme_ctrl *ctrl) in nvme_sync_queues() argument
5092 nvme_sync_io_queues(ctrl); in nvme_sync_queues()
5093 if (ctrl->admin_q) in nvme_sync_queues()
5094 blk_sync_queue(ctrl->admin_q); in nvme_sync_queues()