Lines Matching full:ctrl
147 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
149 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
152 void nvme_queue_scan(struct nvme_ctrl *ctrl) in nvme_queue_scan() argument
157 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE && ctrl->tagset) in nvme_queue_scan()
158 queue_work(nvme_wq, &ctrl->scan_work); in nvme_queue_scan()
167 int nvme_try_sched_reset(struct nvme_ctrl *ctrl) in nvme_try_sched_reset() argument
169 if (nvme_ctrl_state(ctrl) != NVME_CTRL_RESETTING) in nvme_try_sched_reset()
171 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_try_sched_reset()
179 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_failfast_work() local
182 if (nvme_ctrl_state(ctrl) != NVME_CTRL_CONNECTING) in nvme_failfast_work()
185 set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_failfast_work()
186 dev_info(ctrl->device, "failfast expired\n"); in nvme_failfast_work()
187 nvme_kick_requeue_lists(ctrl); in nvme_failfast_work()
190 static inline void nvme_start_failfast_work(struct nvme_ctrl *ctrl) in nvme_start_failfast_work() argument
192 if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) in nvme_start_failfast_work()
195 schedule_delayed_work(&ctrl->failfast_work, in nvme_start_failfast_work()
196 ctrl->opts->fast_io_fail_tmo * HZ); in nvme_start_failfast_work()
199 static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) in nvme_stop_failfast_work() argument
201 if (!ctrl->opts) in nvme_stop_failfast_work()
204 cancel_delayed_work_sync(&ctrl->failfast_work); in nvme_stop_failfast_work()
205 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_stop_failfast_work()
209 int nvme_reset_ctrl(struct nvme_ctrl *ctrl) in nvme_reset_ctrl() argument
211 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) in nvme_reset_ctrl()
213 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_reset_ctrl()
219 int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_reset_ctrl_sync() argument
223 ret = nvme_reset_ctrl(ctrl); in nvme_reset_ctrl_sync()
225 flush_work(&ctrl->reset_work); in nvme_reset_ctrl_sync()
226 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE) in nvme_reset_ctrl_sync()
233 static void nvme_do_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_do_delete_ctrl() argument
235 dev_info(ctrl->device, in nvme_do_delete_ctrl()
236 "Removing ctrl: NQN \"%s\"\n", nvmf_ctrl_subsysnqn(ctrl)); in nvme_do_delete_ctrl()
238 flush_work(&ctrl->reset_work); in nvme_do_delete_ctrl()
239 nvme_stop_ctrl(ctrl); in nvme_do_delete_ctrl()
240 nvme_remove_namespaces(ctrl); in nvme_do_delete_ctrl()
241 ctrl->ops->delete_ctrl(ctrl); in nvme_do_delete_ctrl()
242 nvme_uninit_ctrl(ctrl); in nvme_do_delete_ctrl()
247 struct nvme_ctrl *ctrl = in nvme_delete_ctrl_work() local
250 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_work()
253 int nvme_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_delete_ctrl() argument
255 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl()
257 if (!queue_work(nvme_delete_wq, &ctrl->delete_work)) in nvme_delete_ctrl()
263 void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_delete_ctrl_sync() argument
269 nvme_get_ctrl(ctrl); in nvme_delete_ctrl_sync()
270 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl_sync()
271 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_sync()
272 nvme_put_ctrl(ctrl); in nvme_delete_ctrl_sync()
325 delay = nvme_req(req)->ctrl->crdt[crd - 1] * 100; in nvme_retry_req()
353 dev_name(nr->ctrl->device), in nvme_log_error()
370 ns ? ns->disk->disk_name : dev_name(nr->ctrl->device), in nvme_log_err_passthru()
454 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_complete_rq() local
467 if (ctrl->kas && in nvme_complete_rq()
468 req->deadline - req->timeout >= ctrl->ka_last_check_time) in nvme_complete_rq()
469 ctrl->comp_seen = true; in nvme_complete_rq()
483 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_complete_rq()
532 void nvme_cancel_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_tagset() argument
534 if (ctrl->tagset) { in nvme_cancel_tagset()
535 blk_mq_tagset_busy_iter(ctrl->tagset, in nvme_cancel_tagset()
536 nvme_cancel_request, ctrl); in nvme_cancel_tagset()
537 blk_mq_tagset_wait_completed_request(ctrl->tagset); in nvme_cancel_tagset()
542 void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_admin_tagset() argument
544 if (ctrl->admin_tagset) { in nvme_cancel_admin_tagset()
545 blk_mq_tagset_busy_iter(ctrl->admin_tagset, in nvme_cancel_admin_tagset()
546 nvme_cancel_request, ctrl); in nvme_cancel_admin_tagset()
547 blk_mq_tagset_wait_completed_request(ctrl->admin_tagset); in nvme_cancel_admin_tagset()
552 bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, in nvme_change_ctrl_state() argument
559 spin_lock_irqsave(&ctrl->lock, flags); in nvme_change_ctrl_state()
561 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()
915 if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_setup_write_zeroes()
1041 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_cleanup_cmd() local
1043 if (req->special_vec.bv_page == ctrl->discard_page) in nvme_cleanup_cmd()
1044 clear_bit_unlock(0, &ctrl->discard_page_busy); in nvme_cleanup_cmd()
1177 u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_command_effects() argument
1184 dev_warn_once(ctrl->device, in nvme_command_effects()
1195 effects = le32_to_cpu(ctrl->effects->acs[opcode]); in nvme_command_effects()
1206 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_passthru_start() argument
1208 u32 effects = nvme_command_effects(ctrl, ns, opcode); in nvme_passthru_start()
1215 mutex_lock(&ctrl->scan_lock); in nvme_passthru_start()
1216 mutex_lock(&ctrl->subsys->lock); in nvme_passthru_start()
1217 nvme_mpath_start_freeze(ctrl->subsys); in nvme_passthru_start()
1218 nvme_mpath_wait_freeze(ctrl->subsys); in nvme_passthru_start()
1219 nvme_start_freeze(ctrl); in nvme_passthru_start()
1220 nvme_wait_freeze(ctrl); in nvme_passthru_start()
1226 void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, in nvme_passthru_end() argument
1230 nvme_unfreeze(ctrl); in nvme_passthru_end()
1231 nvme_mpath_unfreeze(ctrl->subsys); in nvme_passthru_end()
1232 mutex_unlock(&ctrl->subsys->lock); in nvme_passthru_end()
1233 mutex_unlock(&ctrl->scan_lock); in nvme_passthru_end()
1237 &ctrl->flags)) { in nvme_passthru_end()
1238 dev_info(ctrl->device, in nvme_passthru_end()
1243 nvme_queue_scan(ctrl); in nvme_passthru_end()
1244 flush_work(&ctrl->scan_work); in nvme_passthru_end()
1259 nvme_update_keep_alive(ctrl, cmd); in nvme_passthru_end()
1277 static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl) in nvme_keep_alive_work_period() argument
1279 unsigned long delay = ctrl->kato * HZ / 2; in nvme_keep_alive_work_period()
1287 if (ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) in nvme_keep_alive_work_period()
1292 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) in nvme_queue_keep_alive_work() argument
1295 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_queue_keep_alive_work()
1296 unsigned long ka_next_check_tm = ctrl->ka_last_check_time + delay; in nvme_queue_keep_alive_work()
1303 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_queue_keep_alive_work()
1307 blk_status_t status, struct nvme_ctrl *ctrl) in nvme_keep_alive_finish() argument
1310 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_keep_alive_finish()
1311 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_keep_alive_finish()
1320 dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n", in nvme_keep_alive_finish()
1326 dev_err(ctrl->device, in nvme_keep_alive_finish()
1332 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_finish()
1333 ctrl->comp_seen = false; in nvme_keep_alive_finish()
1335 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_keep_alive_finish()
1340 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_keep_alive_work() local
1342 bool comp_seen = ctrl->comp_seen; in nvme_keep_alive_work()
1346 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_work()
1348 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { in nvme_keep_alive_work()
1349 dev_dbg(ctrl->device, in nvme_keep_alive_work()
1351 ctrl->comp_seen = false; in nvme_keep_alive_work()
1352 nvme_queue_keep_alive_work(ctrl); in nvme_keep_alive_work()
1356 rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd), in nvme_keep_alive_work()
1360 dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq)); in nvme_keep_alive_work()
1361 nvme_reset_ctrl(ctrl); in nvme_keep_alive_work()
1364 nvme_init_request(rq, &ctrl->ka_cmd); in nvme_keep_alive_work()
1366 rq->timeout = ctrl->kato * HZ; in nvme_keep_alive_work()
1368 nvme_keep_alive_finish(rq, status, ctrl); in nvme_keep_alive_work()
1372 static void nvme_start_keep_alive(struct nvme_ctrl *ctrl) in nvme_start_keep_alive() argument
1374 if (unlikely(ctrl->kato == 0)) in nvme_start_keep_alive()
1377 nvme_queue_keep_alive_work(ctrl); in nvme_start_keep_alive()
1380 void nvme_stop_keep_alive(struct nvme_ctrl *ctrl) in nvme_stop_keep_alive() argument
1382 if (unlikely(ctrl->kato == 0)) in nvme_stop_keep_alive()
1385 cancel_delayed_work_sync(&ctrl->ka_work); in nvme_stop_keep_alive()
1389 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, in nvme_update_keep_alive() argument
1395 dev_info(ctrl->device, in nvme_update_keep_alive()
1397 ctrl->kato * 1000 / 2, new_kato * 1000 / 2); in nvme_update_keep_alive()
1399 nvme_stop_keep_alive(ctrl); in nvme_update_keep_alive()
1400 ctrl->kato = new_kato; in nvme_update_keep_alive()
1401 nvme_start_keep_alive(ctrl); in nvme_update_keep_alive()
1404 static bool nvme_id_cns_ok(struct nvme_ctrl *ctrl, u8 cns) in nvme_id_cns_ok() argument
1409 if (ctrl->vs >= NVME_VS(1, 2, 0)) in nvme_id_cns_ok()
1420 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_id_cns_ok()
1421 !(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) in nvme_id_cns_ok()
1452 static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, in nvme_process_ns_desc() argument
1455 const char *warn_str = "ctrl returned bogus length:"; in nvme_process_ns_desc()
1461 dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n", in nvme_process_ns_desc()
1465 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1471 dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n", in nvme_process_ns_desc()
1475 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1481 dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n", in nvme_process_ns_desc()
1485 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1491 dev_warn(ctrl->device, "%s %d for NVME_NIDT_CSI\n", in nvme_process_ns_desc()
1504 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, in nvme_identify_ns_descs() argument
1512 if (ctrl->vs < NVME_VS(1, 3, 0) && !nvme_multi_css(ctrl)) in nvme_identify_ns_descs()
1514 if (ctrl->quirks & NVME_QUIRK_NO_NS_DESC_LIST) in nvme_identify_ns_descs()
1525 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data, in nvme_identify_ns_descs()
1528 dev_warn(ctrl->device, in nvme_identify_ns_descs()
1540 len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); in nvme_identify_ns_descs()
1547 if (nvme_multi_css(ctrl) && !csi_seen) { in nvme_identify_ns_descs()
1548 dev_warn(ctrl->device, "Command set not reported for nsid:%d\n", in nvme_identify_ns_descs()
1558 int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, in nvme_identify_ns() argument
1573 error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id)); in nvme_identify_ns()
1575 dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error); in nvme_identify_ns()
1582 static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, in nvme_ns_info_from_identify() argument
1589 ret = nvme_identify_ns(ctrl, info->nsid, &id); in nvme_ns_info_from_identify()
1604 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) { in nvme_ns_info_from_identify()
1605 dev_info(ctrl->device, in nvme_ns_info_from_identify()
1608 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_ns_info_from_identify()
1611 if (ctrl->vs >= NVME_VS(1, 2, 0) && in nvme_ns_info_from_identify()
1621 static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, in nvme_ns_info_from_id_cs_indep() argument
1636 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_ns_info_from_id_cs_indep()
1683 int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) in nvme_set_queue_count() argument
1689 status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0, in nvme_set_queue_count()
1700 dev_err(ctrl->device, "Could not set queue count (%d)\n", status); in nvme_set_queue_count()
1715 static void nvme_enable_aen(struct nvme_ctrl *ctrl) in nvme_enable_aen() argument
1717 u32 result, supported_aens = ctrl->oaes & NVME_AEN_SUPPORTED; in nvme_enable_aen()
1723 status = nvme_set_features(ctrl, NVME_FEAT_ASYNC_EVENT, supported_aens, in nvme_enable_aen()
1726 dev_warn(ctrl->device, "Failed to configure AEN (cfg %x)\n", in nvme_enable_aen()
1729 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_enable_aen()
1740 if (!try_module_get(ns->ctrl->ops->module)) in nvme_ns_open()
1754 module_put(ns->ctrl->ops->module); in nvme_ns_release()
1842 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_config_discard() local
1844 if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns->head, UINT_MAX)) in nvme_config_discard()
1846 nvme_lba_to_sect(ns->head, ctrl->dmrsl); in nvme_config_discard()
1847 else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) in nvme_config_discard()
1854 if (ctrl->dmrl) in nvme_config_discard()
1855 lim->max_discard_segments = ctrl->dmrl; in nvme_config_discard()
1868 static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid, in nvme_identify_ns_nvm() argument
1884 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm)); in nvme_identify_ns_nvm()
1920 static void nvme_configure_metadata(struct nvme_ctrl *ctrl, in nvme_configure_metadata() argument
1928 if (!head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) in nvme_configure_metadata()
1931 if (nvm && (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { in nvme_configure_metadata()
1947 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_configure_metadata()
1967 if (ctrl->max_integrity_segments && nvme_ns_has_pi(head)) in nvme_configure_metadata()
2000 static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl) in nvme_max_drv_segments() argument
2002 return ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> SECTOR_SHIFT) + 1; in nvme_max_drv_segments()
2005 static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl, in nvme_set_ctrl_limits() argument
2008 lim->max_hw_sectors = ctrl->max_hw_sectors; in nvme_set_ctrl_limits()
2010 min_not_zero(nvme_max_drv_segments(ctrl), ctrl->max_segments)); in nvme_set_ctrl_limits()
2011 lim->max_integrity_segments = ctrl->max_integrity_segments; in nvme_set_ctrl_limits()
2045 atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; in nvme_update_disk_info()
2067 if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_update_disk_info()
2070 lim->max_write_zeroes_sectors = ns->ctrl->max_zeroes_sectors; in nvme_update_disk_info()
2088 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_set_chunk_sectors() local
2091 if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) && in nvme_set_chunk_sectors()
2092 is_power_of_2(ctrl->max_hw_sectors)) in nvme_set_chunk_sectors()
2093 iob = ctrl->max_hw_sectors; in nvme_set_chunk_sectors()
2125 nvme_set_ctrl_limits(ns->ctrl, &lim); in nvme_update_ns_info_generic()
2147 ret = nvme_identify_ns(ns->ctrl, info->nsid, &id); in nvme_update_ns_info_block()
2159 if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) { in nvme_update_ns_info_block()
2160 ret = nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); in nvme_update_ns_info_block()
2178 nvme_set_ctrl_limits(ns->ctrl, &lim); in nvme_update_ns_info_block()
2179 nvme_configure_metadata(ns->ctrl, ns->head, id, nvm, info); in nvme_update_ns_info_block()
2188 if (ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) in nvme_update_ns_info_block()
2243 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2255 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2346 struct nvme_ctrl *ctrl = data; in nvme_sec_submit() local
2357 return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len, in nvme_sec_submit()
2361 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2363 if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) { in nvme_configure_opal()
2364 if (!ctrl->opal_dev) in nvme_configure_opal()
2365 ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit); in nvme_configure_opal()
2367 opal_unlock_from_suspend(ctrl->opal_dev); in nvme_configure_opal()
2369 free_opal_dev(ctrl->opal_dev); in nvme_configure_opal()
2370 ctrl->opal_dev = NULL; in nvme_configure_opal()
2374 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2402 static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val, in nvme_wait_ready() argument
2409 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_wait_ready()
2419 dev_err(ctrl->device, in nvme_wait_ready()
2429 int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown) in nvme_disable_ctrl() argument
2433 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_disable_ctrl()
2435 ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; in nvme_disable_ctrl()
2437 ctrl->ctrl_config &= ~NVME_CC_ENABLE; in nvme_disable_ctrl()
2439 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_disable_ctrl()
2444 return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK, in nvme_disable_ctrl()
2446 ctrl->shutdown_timeout, "shutdown"); in nvme_disable_ctrl()
2448 if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY) in nvme_disable_ctrl()
2450 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, 0, in nvme_disable_ctrl()
2451 (NVME_CAP_TIMEOUT(ctrl->cap) + 1) / 2, "reset"); in nvme_disable_ctrl()
2455 int nvme_enable_ctrl(struct nvme_ctrl *ctrl) in nvme_enable_ctrl() argument
2461 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2463 dev_err(ctrl->device, "Reading CAP failed (%d)\n", ret); in nvme_enable_ctrl()
2466 dev_page_min = NVME_CAP_MPSMIN(ctrl->cap) + 12; in nvme_enable_ctrl()
2469 dev_err(ctrl->device, in nvme_enable_ctrl()
2475 if (NVME_CAP_CSS(ctrl->cap) & NVME_CAP_CSS_CSI) in nvme_enable_ctrl()
2476 ctrl->ctrl_config = NVME_CC_CSS_CSI; in nvme_enable_ctrl()
2478 ctrl->ctrl_config = NVME_CC_CSS_NVM; in nvme_enable_ctrl()
2486 ctrl->ctrl_config &= ~NVME_CC_CRIME; in nvme_enable_ctrl()
2488 ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT; in nvme_enable_ctrl()
2489 ctrl->ctrl_config |= NVME_CC_AMS_RR | NVME_CC_SHN_NONE; in nvme_enable_ctrl()
2490 ctrl->ctrl_config |= NVME_CC_IOSQES | NVME_CC_IOCQES; in nvme_enable_ctrl()
2491 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2496 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2500 timeout = NVME_CAP_TIMEOUT(ctrl->cap); in nvme_enable_ctrl()
2501 if (ctrl->cap & NVME_CAP_CRMS_CRWMS) { in nvme_enable_ctrl()
2504 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CRTO, &crto); in nvme_enable_ctrl()
2506 dev_err(ctrl->device, "Reading CRTO failed (%d)\n", in nvme_enable_ctrl()
2519 dev_warn_once(ctrl->device, "bad crto:%x cap:%llx\n", in nvme_enable_ctrl()
2520 crto, ctrl->cap); in nvme_enable_ctrl()
2525 ctrl->ctrl_config |= NVME_CC_ENABLE; in nvme_enable_ctrl()
2526 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2529 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, NVME_CSTS_RDY, in nvme_enable_ctrl()
2534 static int nvme_configure_timestamp(struct nvme_ctrl *ctrl) in nvme_configure_timestamp() argument
2539 if (!(ctrl->oncs & NVME_CTRL_ONCS_TIMESTAMP)) in nvme_configure_timestamp()
2543 ret = nvme_set_features(ctrl, NVME_FEAT_TIMESTAMP, 0, &ts, sizeof(ts), in nvme_configure_timestamp()
2546 dev_warn_once(ctrl->device, in nvme_configure_timestamp()
2551 static int nvme_configure_host_options(struct nvme_ctrl *ctrl) in nvme_configure_host_options() argument
2558 if (ctrl->crdt[0]) in nvme_configure_host_options()
2560 if (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) in nvme_configure_host_options()
2572 ret = nvme_set_features(ctrl, NVME_FEAT_HOST_BEHAVIOR, 0, in nvme_configure_host_options()
2632 static int nvme_configure_apst(struct nvme_ctrl *ctrl) in nvme_configure_apst() argument
2647 if (!ctrl->apsta) in nvme_configure_apst()
2650 if (ctrl->npss > 31) { in nvme_configure_apst()
2651 dev_warn(ctrl->device, "NPSS is invalid; not using APST\n"); in nvme_configure_apst()
2659 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) { in nvme_configure_apst()
2661 dev_dbg(ctrl->device, "APST disabled\n"); in nvme_configure_apst()
2671 for (state = (int)ctrl->npss; state >= 0; state--) { in nvme_configure_apst()
2681 if (state == ctrl->npss && in nvme_configure_apst()
2682 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) in nvme_configure_apst()
2689 if (!(ctrl->psd[state].flags & NVME_PS_FLAGS_NON_OP_STATE)) in nvme_configure_apst()
2692 exit_latency_us = (u64)le32_to_cpu(ctrl->psd[state].exit_lat); in nvme_configure_apst()
2693 if (exit_latency_us > ctrl->ps_max_latency_us) in nvme_configure_apst()
2697 le32_to_cpu(ctrl->psd[state].entry_lat); in nvme_configure_apst()
2722 dev_dbg(ctrl->device, "APST enabled but no non-operational states are available\n"); in nvme_configure_apst()
2724 …dev_dbg(ctrl->device, "APST enabled: max PS = %d, max round-trip latency = %lluus, table = %*phN\n… in nvme_configure_apst()
2729 ret = nvme_set_features(ctrl, NVME_FEAT_AUTO_PST, apste, in nvme_configure_apst()
2732 dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret); in nvme_configure_apst()
2739 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_set_latency_tolerance() local
2752 if (ctrl->ps_max_latency_us != latency) { in nvme_set_latency_tolerance()
2753 ctrl->ps_max_latency_us = latency; in nvme_set_latency_tolerance()
2754 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_set_latency_tolerance()
2755 nvme_configure_apst(ctrl); in nvme_set_latency_tolerance()
2850 static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ctrl, in nvme_init_subnqn() argument
2856 if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) { in nvme_init_subnqn()
2863 if (ctrl->vs >= NVME_VS(1, 2, 1)) in nvme_init_subnqn()
2864 dev_warn(ctrl->device, "missing or invalid SUBNQN field.\n"); in nvme_init_subnqn()
2939 static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) in nvme_discovery_ctrl() argument
2941 return ctrl->opts && ctrl->opts->discovery_nqn; in nvme_discovery_ctrl()
2945 struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_validate_cntlid() argument
2955 if (tmp->cntlid == ctrl->cntlid) { in nvme_validate_cntlid()
2956 dev_err(ctrl->device, in nvme_validate_cntlid()
2958 ctrl->cntlid, dev_name(tmp->device), in nvme_validate_cntlid()
2964 nvme_discovery_ctrl(ctrl)) in nvme_validate_cntlid()
2967 dev_err(ctrl->device, in nvme_validate_cntlid()
2975 static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_subsystem() argument
2989 nvme_init_subnqn(subsys, ctrl, id); in nvme_init_subsystem()
3002 if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) { in nvme_init_subsystem()
3003 dev_err(ctrl->device, in nvme_init_subsystem()
3015 dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); in nvme_init_subsystem()
3024 if (!nvme_validate_cntlid(subsys, ctrl, id)) { in nvme_init_subsystem()
3031 dev_err(ctrl->device, in nvme_init_subsystem()
3040 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, in nvme_init_subsystem()
3041 dev_name(ctrl->device)); in nvme_init_subsystem()
3043 dev_err(ctrl->device, in nvme_init_subsystem()
3049 subsys->instance = ctrl->instance; in nvme_init_subsystem()
3050 ctrl->subsys = subsys; in nvme_init_subsystem()
3051 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvme_init_subsystem()
3062 int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, in nvme_get_log() argument
3078 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); in nvme_get_log()
3081 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi, in nvme_get_effects_log() argument
3084 struct nvme_effects_log *cel = xa_load(&ctrl->cels, csi); in nvme_get_effects_log()
3094 ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi, in nvme_get_effects_log()
3101 xa_store(&ctrl->cels, csi, cel, GFP_KERNEL); in nvme_get_effects_log()
3107 static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units) in nvme_mps_to_sectors() argument
3109 u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; in nvme_mps_to_sectors()
3116 static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) in nvme_init_non_mdts_limits() argument
3128 if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && in nvme_init_non_mdts_limits()
3129 !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) in nvme_init_non_mdts_limits()
3130 ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; in nvme_init_non_mdts_limits()
3132 ctrl->max_zeroes_sectors = 0; in nvme_init_non_mdts_limits()
3134 if (ctrl->subsys->subtype != NVME_NQN_NVME || in nvme_init_non_mdts_limits()
3135 !nvme_id_cns_ok(ctrl, NVME_ID_CNS_CS_CTRL) || in nvme_init_non_mdts_limits()
3136 test_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags)) in nvme_init_non_mdts_limits()
3147 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_init_non_mdts_limits()
3151 ctrl->dmrl = id->dmrl; in nvme_init_non_mdts_limits()
3152 ctrl->dmrsl = le32_to_cpu(id->dmrsl); in nvme_init_non_mdts_limits()
3154 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); in nvme_init_non_mdts_limits()
3158 set_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags); in nvme_init_non_mdts_limits()
3163 static void nvme_init_known_nvm_effects(struct nvme_ctrl *ctrl) in nvme_init_known_nvm_effects() argument
3165 struct nvme_effects_log *log = ctrl->effects; in nvme_init_known_nvm_effects()
3195 static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_effects() argument
3199 if (ctrl->effects) in nvme_init_effects()
3203 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3208 if (!ctrl->effects) { in nvme_init_effects()
3209 ctrl->effects = kzalloc(sizeof(*ctrl->effects), GFP_KERNEL); in nvme_init_effects()
3210 if (!ctrl->effects) in nvme_init_effects()
3212 xa_store(&ctrl->cels, NVME_CSI_NVM, ctrl->effects, GFP_KERNEL); in nvme_init_effects()
3215 nvme_init_known_nvm_effects(ctrl); in nvme_init_effects()
3219 static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_check_ctrl_fabric_info() argument
3225 if (ctrl->cntlid != le16_to_cpu(id->cntlid)) { in nvme_check_ctrl_fabric_info()
3226 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3228 ctrl->cntlid, le16_to_cpu(id->cntlid)); in nvme_check_ctrl_fabric_info()
3232 if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) { in nvme_check_ctrl_fabric_info()
3233 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3238 if (!nvme_discovery_ctrl(ctrl) && ctrl->ioccsz < 4) { in nvme_check_ctrl_fabric_info()
3239 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3241 ctrl->ioccsz); in nvme_check_ctrl_fabric_info()
3245 if (!nvme_discovery_ctrl(ctrl) && ctrl->iorcsz < 1) { in nvme_check_ctrl_fabric_info()
3246 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3248 ctrl->iorcsz); in nvme_check_ctrl_fabric_info()
3252 if (!ctrl->maxcmd) { in nvme_check_ctrl_fabric_info()
3253 dev_err(ctrl->device, "Maximum outstanding commands is 0\n"); in nvme_check_ctrl_fabric_info()
3260 static int nvme_init_identify(struct nvme_ctrl *ctrl) in nvme_init_identify() argument
3268 ret = nvme_identify_ctrl(ctrl, &id); in nvme_init_identify()
3270 dev_err(ctrl->device, "Identify Controller failed (%d)\n", ret); in nvme_init_identify()
3274 if (!(ctrl->ops->flags & NVME_F_FABRICS)) in nvme_init_identify()
3275 ctrl->cntlid = le16_to_cpu(id->cntlid); in nvme_init_identify()
3277 if (!ctrl->identified) { in nvme_init_identify()
3290 ctrl->quirks |= core_quirks[i].quirks; in nvme_init_identify()
3293 ret = nvme_init_subsystem(ctrl, id); in nvme_init_identify()
3297 ret = nvme_init_effects(ctrl, id); in nvme_init_identify()
3301 memcpy(ctrl->subsys->firmware_rev, id->fr, in nvme_init_identify()
3302 sizeof(ctrl->subsys->firmware_rev)); in nvme_init_identify()
3304 if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) { in nvme_init_identify()
3305 …dev_warn(ctrl->device, "forcibly allowing all power states due to nvme_core.force_apst -- use at y… in nvme_init_identify()
3306 ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS; in nvme_init_identify()
3309 ctrl->crdt[0] = le16_to_cpu(id->crdt1); in nvme_init_identify()
3310 ctrl->crdt[1] = le16_to_cpu(id->crdt2); in nvme_init_identify()
3311 ctrl->crdt[2] = le16_to_cpu(id->crdt3); in nvme_init_identify()
3313 ctrl->oacs = le16_to_cpu(id->oacs); in nvme_init_identify()
3314 ctrl->oncs = le16_to_cpu(id->oncs); in nvme_init_identify()
3315 ctrl->mtfa = le16_to_cpu(id->mtfa); in nvme_init_identify()
3316 ctrl->oaes = le32_to_cpu(id->oaes); in nvme_init_identify()
3317 ctrl->wctemp = le16_to_cpu(id->wctemp); in nvme_init_identify()
3318 ctrl->cctemp = le16_to_cpu(id->cctemp); in nvme_init_identify()
3320 atomic_set(&ctrl->abort_limit, id->acl + 1); in nvme_init_identify()
3321 ctrl->vwc = id->vwc; in nvme_init_identify()
3323 max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); in nvme_init_identify()
3326 ctrl->max_hw_sectors = in nvme_init_identify()
3327 min_not_zero(ctrl->max_hw_sectors, max_hw_sectors); in nvme_init_identify()
3329 lim = queue_limits_start_update(ctrl->admin_q); in nvme_init_identify()
3330 nvme_set_ctrl_limits(ctrl, &lim); in nvme_init_identify()
3331 ret = queue_limits_commit_update(ctrl->admin_q, &lim); in nvme_init_identify()
3335 ctrl->sgls = le32_to_cpu(id->sgls); in nvme_init_identify()
3336 ctrl->kas = le16_to_cpu(id->kas); in nvme_init_identify()
3337 ctrl->max_namespaces = le32_to_cpu(id->mnan); in nvme_init_identify()
3338 ctrl->ctratt = le32_to_cpu(id->ctratt); in nvme_init_identify()
3340 ctrl->cntrltype = id->cntrltype; in nvme_init_identify()
3341 ctrl->dctype = id->dctype; in nvme_init_identify()
3347 ctrl->shutdown_timeout = clamp_t(unsigned int, transition_time, in nvme_init_identify()
3350 if (ctrl->shutdown_timeout != shutdown_timeout) in nvme_init_identify()
3351 dev_info(ctrl->device, in nvme_init_identify()
3353 ctrl->shutdown_timeout); in nvme_init_identify()
3355 ctrl->shutdown_timeout = shutdown_timeout; in nvme_init_identify()
3357 ctrl->npss = id->npss; in nvme_init_identify()
3358 ctrl->apsta = id->apsta; in nvme_init_identify()
3359 prev_apst_enabled = ctrl->apst_enabled; in nvme_init_identify()
3360 if (ctrl->quirks & NVME_QUIRK_NO_APST) { in nvme_init_identify()
3362 …dev_warn(ctrl->device, "forcibly allowing APST due to nvme_core.force_apst -- use at your own risk… in nvme_init_identify()
3363 ctrl->apst_enabled = true; in nvme_init_identify()
3365 ctrl->apst_enabled = false; in nvme_init_identify()
3368 ctrl->apst_enabled = id->apsta; in nvme_init_identify()
3370 memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd)); in nvme_init_identify()
3372 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_init_identify()
3373 ctrl->icdoff = le16_to_cpu(id->icdoff); in nvme_init_identify()
3374 ctrl->ioccsz = le32_to_cpu(id->ioccsz); in nvme_init_identify()
3375 ctrl->iorcsz = le32_to_cpu(id->iorcsz); in nvme_init_identify()
3376 ctrl->maxcmd = le16_to_cpu(id->maxcmd); in nvme_init_identify()
3378 ret = nvme_check_ctrl_fabric_info(ctrl, id); in nvme_init_identify()
3382 ctrl->hmpre = le32_to_cpu(id->hmpre); in nvme_init_identify()
3383 ctrl->hmmin = le32_to_cpu(id->hmmin); in nvme_init_identify()
3384 ctrl->hmminds = le32_to_cpu(id->hmminds); in nvme_init_identify()
3385 ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); in nvme_init_identify()
3388 ret = nvme_mpath_init_identify(ctrl, id); in nvme_init_identify()
3392 if (ctrl->apst_enabled && !prev_apst_enabled) in nvme_init_identify()
3393 dev_pm_qos_expose_latency_tolerance(ctrl->device); in nvme_init_identify()
3394 else if (!ctrl->apst_enabled && prev_apst_enabled) in nvme_init_identify()
3395 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_identify()
3407 int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_init_ctrl_finish() argument
3411 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); in nvme_init_ctrl_finish()
3413 dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); in nvme_init_ctrl_finish()
3417 ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); in nvme_init_ctrl_finish()
3419 if (ctrl->vs >= NVME_VS(1, 1, 0)) in nvme_init_ctrl_finish()
3420 ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); in nvme_init_ctrl_finish()
3422 ret = nvme_init_identify(ctrl); in nvme_init_ctrl_finish()
3426 ret = nvme_configure_apst(ctrl); in nvme_init_ctrl_finish()
3430 ret = nvme_configure_timestamp(ctrl); in nvme_init_ctrl_finish()
3434 ret = nvme_configure_host_options(ctrl); in nvme_init_ctrl_finish()
3438 nvme_configure_opal(ctrl, was_suspended); in nvme_init_ctrl_finish()
3440 if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3445 ret = nvme_hwmon_init(ctrl); in nvme_init_ctrl_finish()
3450 clear_bit(NVME_CTRL_DIRTY_CAPABILITY, &ctrl->flags); in nvme_init_ctrl_finish()
3451 ctrl->identified = true; in nvme_init_ctrl_finish()
3453 nvme_start_keep_alive(ctrl); in nvme_init_ctrl_finish()
3461 struct nvme_ctrl *ctrl = in nvme_dev_open() local
3464 switch (nvme_ctrl_state(ctrl)) { in nvme_dev_open()
3471 nvme_get_ctrl(ctrl); in nvme_dev_open()
3472 if (!try_module_get(ctrl->ops->module)) { in nvme_dev_open()
3473 nvme_put_ctrl(ctrl); in nvme_dev_open()
3477 file->private_data = ctrl; in nvme_dev_open()
3483 struct nvme_ctrl *ctrl = in nvme_dev_release() local
3486 module_put(ctrl->ops->module); in nvme_dev_release()
3487 nvme_put_ctrl(ctrl); in nvme_dev_release()
3500 static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, in nvme_find_ns_head() argument
3505 lockdep_assert_held(&ctrl->subsys->lock); in nvme_find_ns_head()
3507 list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { in nvme_find_ns_head()
3513 if (h->ns_id != nsid || !nvme_is_unique_nsid(ctrl, h)) in nvme_find_ns_head()
3603 ns->cdev_device.parent = ns->ctrl->device; in nvme_add_ns_cdev()
3605 ns->ctrl->instance, ns->head->instance); in nvme_add_ns_cdev()
3610 ns->ctrl->ops->module); in nvme_add_ns_cdev()
3613 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, in nvme_alloc_ns_head() argument
3627 ret = ida_alloc_min(&ctrl->subsys->ns_ida, 1, GFP_KERNEL); in nvme_alloc_ns_head()
3635 head->subsys = ctrl->subsys; in nvme_alloc_ns_head()
3644 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); in nvme_alloc_ns_head()
3648 head->effects = ctrl->effects; in nvme_alloc_ns_head()
3650 ret = nvme_mpath_alloc_disk(ctrl, head); in nvme_alloc_ns_head()
3654 list_add_tail(&head->entry, &ctrl->subsys->nsheads); in nvme_alloc_ns_head()
3656 kref_get(&ctrl->subsys->ref); in nvme_alloc_ns_head()
3662 ida_free(&ctrl->subsys->ns_ida, head->instance); in nvme_alloc_ns_head()
3699 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ns_head() local
3703 ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3721 nvme_print_device_info(ctrl); in nvme_init_ns_head()
3722 if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ in nvme_init_ns_head()
3723 ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && in nvme_init_ns_head()
3725 dev_err(ctrl->device, in nvme_init_ns_head()
3731 dev_err(ctrl->device, in nvme_init_ns_head()
3733 dev_err(ctrl->device, in nvme_init_ns_head()
3738 ctrl->quirks |= NVME_QUIRK_BOGUS_NID; in nvme_init_ns_head()
3741 mutex_lock(&ctrl->subsys->lock); in nvme_init_ns_head()
3742 head = nvme_find_ns_head(ctrl, info->nsid); in nvme_init_ns_head()
3744 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3746 dev_err(ctrl->device, in nvme_init_ns_head()
3751 head = nvme_alloc_ns_head(ctrl, info); in nvme_init_ns_head()
3759 dev_err(ctrl->device, in nvme_init_ns_head()
3765 dev_err(ctrl->device, in nvme_init_ns_head()
3772 dev_warn(ctrl->device, in nvme_init_ns_head()
3775 dev_warn_once(ctrl->device, in nvme_init_ns_head()
3782 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3788 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3792 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_find_get_ns() argument
3797 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_find_get_ns()
3798 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_find_get_ns()
3799 srcu_read_lock_held(&ctrl->srcu)) { in nvme_find_get_ns()
3809 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_find_get_ns()
3821 list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) { in nvme_ns_add_to_ctrl_list()
3827 list_add(&ns->list, &ns->ctrl->namespaces); in nvme_ns_add_to_ctrl_list()
3830 static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) in nvme_alloc_ns() argument
3835 int node = ctrl->numa_node; in nvme_alloc_ns()
3841 if (ctrl->opts && ctrl->opts->data_digest) in nvme_alloc_ns()
3843 if (ctrl->ops->supports_pci_p2pdma && in nvme_alloc_ns()
3844 ctrl->ops->supports_pci_p2pdma(ctrl)) in nvme_alloc_ns()
3847 disk = blk_mq_alloc_disk(ctrl->tagset, &lim, ns); in nvme_alloc_ns()
3855 ns->ctrl = ctrl; in nvme_alloc_ns()
3873 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3874 ctrl->instance, ns->head->instance); in nvme_alloc_ns()
3877 sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3880 sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, in nvme_alloc_ns()
3887 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3889 * Ensure that no namespaces are added to the ctrl list after the queues in nvme_alloc_ns()
3892 if (test_bit(NVME_CTRL_FROZEN, &ctrl->flags)) { in nvme_alloc_ns()
3893 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3897 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3898 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3899 nvme_get_ctrl(ctrl); in nvme_alloc_ns()
3901 if (device_add_disk(ctrl->device, ns->disk, nvme_ns_attr_groups)) in nvme_alloc_ns()
3920 nvme_put_ctrl(ctrl); in nvme_alloc_ns()
3921 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3923 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3924 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3926 mutex_lock(&ctrl->subsys->lock); in nvme_alloc_ns()
3930 mutex_unlock(&ctrl->subsys->lock); in nvme_alloc_ns()
3959 mutex_lock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
3965 mutex_unlock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
3974 mutex_lock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
3976 mutex_unlock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
3977 synchronize_srcu(&ns->ctrl->srcu); in nvme_ns_remove()
3984 static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) in nvme_ns_remove_by_nsid() argument
3986 struct nvme_ns *ns = nvme_find_get_ns(ctrl, nsid); in nvme_ns_remove_by_nsid()
3999 dev_err(ns->ctrl->device, in nvme_validate_ns()
4016 static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_scan_ns() argument
4022 if (nvme_identify_ns_descs(ctrl, &info)) in nvme_scan_ns()
4025 if (info.ids.csi != NVME_CSI_NVM && !nvme_multi_css(ctrl)) { in nvme_scan_ns()
4026 dev_warn(ctrl->device, in nvme_scan_ns()
4036 if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || in nvme_scan_ns()
4038 ret = nvme_ns_info_from_id_cs_indep(ctrl, &info); in nvme_scan_ns()
4040 ret = nvme_ns_info_from_identify(ctrl, &info); in nvme_scan_ns()
4043 nvme_ns_remove_by_nsid(ctrl, nsid); in nvme_scan_ns()
4052 ns = nvme_find_get_ns(ctrl, nsid); in nvme_scan_ns()
4057 nvme_alloc_ns(ctrl, &info); in nvme_scan_ns()
4063 * @ctrl: Controller on which namespaces are being scanned
4073 struct nvme_ctrl *ctrl; member
4087 nvme_scan_ns(scan_info->ctrl, nsid); in nvme_scan_ns_async()
4090 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, in nvme_remove_invalid_namespaces() argument
4096 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4097 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { in nvme_remove_invalid_namespaces()
4100 synchronize_srcu(&ctrl->srcu); in nvme_remove_invalid_namespaces()
4104 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4110 static int nvme_scan_ns_list(struct nvme_ctrl *ctrl) in nvme_scan_ns_list() argument
4123 scan_info.ctrl = ctrl; in nvme_scan_ns_list()
4132 ret = nvme_submit_sync_cmd(ctrl->admin_q, &cmd, ns_list, in nvme_scan_ns_list()
4135 dev_warn(ctrl->device, in nvme_scan_ns_list()
4149 nvme_ns_remove_by_nsid(ctrl, prev); in nvme_scan_ns_list()
4154 nvme_remove_invalid_namespaces(ctrl, prev); in nvme_scan_ns_list()
4161 static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl) in nvme_scan_ns_sequential() argument
4166 if (nvme_identify_ctrl(ctrl, &id)) in nvme_scan_ns_sequential()
4172 nvme_scan_ns(ctrl, i); in nvme_scan_ns_sequential()
4174 nvme_remove_invalid_namespaces(ctrl, nn); in nvme_scan_ns_sequential()
4177 static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl) in nvme_clear_changed_ns_log() argument
4193 error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_CHANGED_NS, 0, in nvme_clear_changed_ns_log()
4196 dev_warn(ctrl->device, in nvme_clear_changed_ns_log()
4204 struct nvme_ctrl *ctrl = in nvme_scan_work() local
4208 /* No tagset on a live ctrl means IO queues could not created */ in nvme_scan_work()
4209 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE || !ctrl->tagset) in nvme_scan_work()
4219 ret = nvme_init_non_mdts_limits(ctrl); in nvme_scan_work()
4221 dev_warn(ctrl->device, in nvme_scan_work()
4226 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { in nvme_scan_work()
4227 dev_info(ctrl->device, "rescanning namespaces.\n"); in nvme_scan_work()
4228 nvme_clear_changed_ns_log(ctrl); in nvme_scan_work()
4231 mutex_lock(&ctrl->scan_lock); in nvme_scan_work()
4232 if (!nvme_id_cns_ok(ctrl, NVME_ID_CNS_NS_ACTIVE_LIST)) { in nvme_scan_work()
4233 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4240 ret = nvme_scan_ns_list(ctrl); in nvme_scan_work()
4242 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4244 mutex_unlock(&ctrl->scan_lock); in nvme_scan_work()
4252 void nvme_remove_namespaces(struct nvme_ctrl *ctrl) in nvme_remove_namespaces() argument
4262 nvme_mpath_clear_ctrl_paths(ctrl); in nvme_remove_namespaces()
4268 nvme_unquiesce_io_queues(ctrl); in nvme_remove_namespaces()
4271 flush_work(&ctrl->scan_work); in nvme_remove_namespaces()
4279 if (nvme_ctrl_state(ctrl) == NVME_CTRL_DEAD) in nvme_remove_namespaces()
4280 nvme_mark_namespaces_dead(ctrl); in nvme_remove_namespaces()
4283 nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); in nvme_remove_namespaces()
4285 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4286 list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu); in nvme_remove_namespaces()
4287 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4288 synchronize_srcu(&ctrl->srcu); in nvme_remove_namespaces()
4297 const struct nvme_ctrl *ctrl = in nvme_class_uevent() local
4299 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_class_uevent()
4302 ret = add_uevent_var(env, "NVME_TRTYPE=%s", ctrl->ops->name); in nvme_class_uevent()
4327 static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata) in nvme_change_uevent() argument
4331 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_change_uevent()
4334 static void nvme_aen_uevent(struct nvme_ctrl *ctrl) in nvme_aen_uevent() argument
4337 u32 aen_result = ctrl->aen_result; in nvme_aen_uevent()
4339 ctrl->aen_result = 0; in nvme_aen_uevent()
4346 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_aen_uevent()
4352 struct nvme_ctrl *ctrl = in nvme_async_event_work() local
4355 nvme_aen_uevent(ctrl); in nvme_async_event_work()
4359 * flushing ctrl async_event_work after changing the controller state in nvme_async_event_work()
4362 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_async_event_work()
4363 ctrl->ops->submit_async_event(ctrl); in nvme_async_event_work()
4366 static bool nvme_ctrl_pp_status(struct nvme_ctrl *ctrl) in nvme_ctrl_pp_status() argument
4371 if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) in nvme_ctrl_pp_status()
4377 return ((ctrl->ctrl_config & NVME_CC_ENABLE) && (csts & NVME_CSTS_PP)); in nvme_ctrl_pp_status()
4380 static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl) in nvme_get_fw_slot_info() argument
4389 if (nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_FW_SLOT, 0, NVME_CSI_NVM, in nvme_get_fw_slot_info()
4391 dev_warn(ctrl->device, "Get FW SLOT INFO log error\n"); in nvme_get_fw_slot_info()
4398 dev_info(ctrl->device, in nvme_get_fw_slot_info()
4403 memcpy(ctrl->subsys->firmware_rev, &log->frs[cur_fw_slot - 1], in nvme_get_fw_slot_info()
4404 sizeof(ctrl->subsys->firmware_rev)); in nvme_get_fw_slot_info()
4412 struct nvme_ctrl *ctrl = container_of(work, in nvme_fw_act_work() local
4416 nvme_auth_stop(ctrl); in nvme_fw_act_work()
4418 if (ctrl->mtfa) in nvme_fw_act_work()
4420 msecs_to_jiffies(ctrl->mtfa * 100); in nvme_fw_act_work()
4425 nvme_quiesce_io_queues(ctrl); in nvme_fw_act_work()
4426 while (nvme_ctrl_pp_status(ctrl)) { in nvme_fw_act_work()
4428 dev_warn(ctrl->device, in nvme_fw_act_work()
4430 nvme_try_sched_reset(ctrl); in nvme_fw_act_work()
4436 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) in nvme_fw_act_work()
4439 nvme_unquiesce_io_queues(ctrl); in nvme_fw_act_work()
4441 nvme_get_fw_slot_info(ctrl); in nvme_fw_act_work()
4443 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_fw_act_work()
4456 static bool nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result) in nvme_handle_aen_notice() argument
4463 set_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events); in nvme_handle_aen_notice()
4464 nvme_queue_scan(ctrl); in nvme_handle_aen_notice()
4472 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) { in nvme_handle_aen_notice()
4474 queue_work(nvme_wq, &ctrl->fw_act_work); in nvme_handle_aen_notice()
4479 if (!ctrl->ana_log_buf) in nvme_handle_aen_notice()
4481 queue_work(nvme_wq, &ctrl->ana_work); in nvme_handle_aen_notice()
4485 ctrl->aen_result = result; in nvme_handle_aen_notice()
4488 dev_warn(ctrl->device, "async event result %08x\n", result); in nvme_handle_aen_notice()
4493 static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl) in nvme_handle_aer_persistent_error() argument
4495 dev_warn(ctrl->device, in nvme_handle_aer_persistent_error()
4497 nvme_reset_ctrl(ctrl); in nvme_handle_aer_persistent_error()
4500 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, in nvme_complete_async_event() argument
4511 trace_nvme_async_event(ctrl, result); in nvme_complete_async_event()
4514 requeue = nvme_handle_aen_notice(ctrl, result); in nvme_complete_async_event()
4522 nvme_handle_aer_persistent_error(ctrl); in nvme_complete_async_event()
4529 ctrl->aen_result = result; in nvme_complete_async_event()
4536 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_complete_async_event()
4540 int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_admin_tag_set() argument
4549 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_admin_tag_set()
4552 set->numa_node = ctrl->numa_node; in nvme_alloc_admin_tag_set()
4554 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_admin_tag_set()
4557 set->driver_data = ctrl; in nvme_alloc_admin_tag_set()
4564 ctrl->admin_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_admin_tag_set()
4565 if (IS_ERR(ctrl->admin_q)) { in nvme_alloc_admin_tag_set()
4566 ret = PTR_ERR(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4570 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_admin_tag_set()
4571 ctrl->fabrics_q = blk_mq_alloc_queue(set, NULL, NULL); in nvme_alloc_admin_tag_set()
4572 if (IS_ERR(ctrl->fabrics_q)) { in nvme_alloc_admin_tag_set()
4573 ret = PTR_ERR(ctrl->fabrics_q); in nvme_alloc_admin_tag_set()
4578 ctrl->admin_tagset = set; in nvme_alloc_admin_tag_set()
4582 blk_mq_destroy_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4583 blk_put_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4586 ctrl->admin_q = NULL; in nvme_alloc_admin_tag_set()
4587 ctrl->fabrics_q = NULL; in nvme_alloc_admin_tag_set()
4592 void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_admin_tag_set() argument
4594 blk_mq_destroy_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4595 blk_put_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4596 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_admin_tag_set()
4597 blk_mq_destroy_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4598 blk_put_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4600 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_remove_admin_tag_set()
4604 int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_io_tag_set() argument
4612 set->queue_depth = min_t(unsigned, ctrl->sqsize, BLK_MQ_MAX_DEPTH - 1); in nvme_alloc_io_tag_set()
4617 if (ctrl->quirks & NVME_QUIRK_SHARED_TAGS) in nvme_alloc_io_tag_set()
4619 else if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_io_tag_set()
4622 set->numa_node = ctrl->numa_node; in nvme_alloc_io_tag_set()
4624 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_io_tag_set()
4627 set->driver_data = ctrl; in nvme_alloc_io_tag_set()
4628 set->nr_hw_queues = ctrl->queue_count - 1; in nvme_alloc_io_tag_set()
4635 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_io_tag_set()
4640 ctrl->connect_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_io_tag_set()
4641 if (IS_ERR(ctrl->connect_q)) { in nvme_alloc_io_tag_set()
4642 ret = PTR_ERR(ctrl->connect_q); in nvme_alloc_io_tag_set()
4647 ctrl->tagset = set; in nvme_alloc_io_tag_set()
4652 ctrl->connect_q = NULL; in nvme_alloc_io_tag_set()
4657 void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_io_tag_set() argument
4659 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_io_tag_set()
4660 blk_mq_destroy_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4661 blk_put_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4663 blk_mq_free_tag_set(ctrl->tagset); in nvme_remove_io_tag_set()
4667 void nvme_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_stop_ctrl() argument
4669 nvme_mpath_stop(ctrl); in nvme_stop_ctrl()
4670 nvme_auth_stop(ctrl); in nvme_stop_ctrl()
4671 nvme_stop_failfast_work(ctrl); in nvme_stop_ctrl()
4672 flush_work(&ctrl->async_event_work); in nvme_stop_ctrl()
4673 cancel_work_sync(&ctrl->fw_act_work); in nvme_stop_ctrl()
4674 if (ctrl->ops->stop_ctrl) in nvme_stop_ctrl()
4675 ctrl->ops->stop_ctrl(ctrl); in nvme_stop_ctrl()
4679 void nvme_start_ctrl(struct nvme_ctrl *ctrl) in nvme_start_ctrl() argument
4681 nvme_enable_aen(ctrl); in nvme_start_ctrl()
4689 if (test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags) && in nvme_start_ctrl()
4690 nvme_discovery_ctrl(ctrl)) in nvme_start_ctrl()
4691 nvme_change_uevent(ctrl, "NVME_EVENT=rediscover"); in nvme_start_ctrl()
4693 if (ctrl->queue_count > 1) { in nvme_start_ctrl()
4694 nvme_queue_scan(ctrl); in nvme_start_ctrl()
4695 nvme_unquiesce_io_queues(ctrl); in nvme_start_ctrl()
4696 nvme_mpath_update(ctrl); in nvme_start_ctrl()
4699 nvme_change_uevent(ctrl, "NVME_EVENT=connected"); in nvme_start_ctrl()
4700 set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags); in nvme_start_ctrl()
4704 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) in nvme_uninit_ctrl() argument
4706 nvme_stop_keep_alive(ctrl); in nvme_uninit_ctrl()
4707 nvme_hwmon_exit(ctrl); in nvme_uninit_ctrl()
4708 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_uninit_ctrl()
4709 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_uninit_ctrl()
4710 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_uninit_ctrl()
4711 nvme_put_ctrl(ctrl); in nvme_uninit_ctrl()
4715 static void nvme_free_cels(struct nvme_ctrl *ctrl) in nvme_free_cels() argument
4720 xa_for_each(&ctrl->cels, i, cel) { in nvme_free_cels()
4721 xa_erase(&ctrl->cels, i); in nvme_free_cels()
4725 xa_destroy(&ctrl->cels); in nvme_free_cels()
4730 struct nvme_ctrl *ctrl = in nvme_free_ctrl() local
4732 struct nvme_subsystem *subsys = ctrl->subsys; in nvme_free_ctrl()
4734 if (!subsys || ctrl->instance != subsys->instance) in nvme_free_ctrl()
4735 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_free_ctrl()
4736 nvme_free_cels(ctrl); in nvme_free_ctrl()
4737 nvme_mpath_uninit(ctrl); in nvme_free_ctrl()
4738 cleanup_srcu_struct(&ctrl->srcu); in nvme_free_ctrl()
4739 nvme_auth_stop(ctrl); in nvme_free_ctrl()
4740 nvme_auth_free(ctrl); in nvme_free_ctrl()
4741 __free_page(ctrl->discard_page); in nvme_free_ctrl()
4742 free_opal_dev(ctrl->opal_dev); in nvme_free_ctrl()
4746 list_del(&ctrl->subsys_entry); in nvme_free_ctrl()
4747 sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device)); in nvme_free_ctrl()
4751 ctrl->ops->free_ctrl(ctrl); in nvme_free_ctrl()
4765 int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, in nvme_init_ctrl() argument
4770 WRITE_ONCE(ctrl->state, NVME_CTRL_NEW); in nvme_init_ctrl()
4771 ctrl->passthru_err_log_enabled = false; in nvme_init_ctrl()
4772 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_init_ctrl()
4773 spin_lock_init(&ctrl->lock); in nvme_init_ctrl()
4774 mutex_init(&ctrl->namespaces_lock); in nvme_init_ctrl()
4776 ret = init_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4780 mutex_init(&ctrl->scan_lock); in nvme_init_ctrl()
4781 INIT_LIST_HEAD(&ctrl->namespaces); in nvme_init_ctrl()
4782 xa_init(&ctrl->cels); in nvme_init_ctrl()
4783 ctrl->dev = dev; in nvme_init_ctrl()
4784 ctrl->ops = ops; in nvme_init_ctrl()
4785 ctrl->quirks = quirks; in nvme_init_ctrl()
4786 ctrl->numa_node = NUMA_NO_NODE; in nvme_init_ctrl()
4787 INIT_WORK(&ctrl->scan_work, nvme_scan_work); in nvme_init_ctrl()
4788 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); in nvme_init_ctrl()
4789 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); in nvme_init_ctrl()
4790 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); in nvme_init_ctrl()
4791 init_waitqueue_head(&ctrl->state_wq); in nvme_init_ctrl()
4793 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); in nvme_init_ctrl()
4794 INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); in nvme_init_ctrl()
4795 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); in nvme_init_ctrl()
4796 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; in nvme_init_ctrl()
4797 ctrl->ka_last_check_time = jiffies; in nvme_init_ctrl()
4801 ctrl->discard_page = alloc_page(GFP_KERNEL); in nvme_init_ctrl()
4802 if (!ctrl->discard_page) { in nvme_init_ctrl()
4810 ctrl->instance = ret; in nvme_init_ctrl()
4812 ret = nvme_auth_init_ctrl(ctrl); in nvme_init_ctrl()
4816 nvme_mpath_init_ctrl(ctrl); in nvme_init_ctrl()
4818 device_initialize(&ctrl->ctrl_device); in nvme_init_ctrl()
4819 ctrl->device = &ctrl->ctrl_device; in nvme_init_ctrl()
4820 ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt), in nvme_init_ctrl()
4821 ctrl->instance); in nvme_init_ctrl()
4822 ctrl->device->class = &nvme_class; in nvme_init_ctrl()
4823 ctrl->device->parent = ctrl->dev; in nvme_init_ctrl()
4825 ctrl->device->groups = ops->dev_attr_groups; in nvme_init_ctrl()
4827 ctrl->device->groups = nvme_dev_attr_groups; in nvme_init_ctrl()
4828 ctrl->device->release = nvme_free_ctrl; in nvme_init_ctrl()
4829 dev_set_drvdata(ctrl->device, ctrl); in nvme_init_ctrl()
4834 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_init_ctrl()
4836 if (ctrl->discard_page) in nvme_init_ctrl()
4837 __free_page(ctrl->discard_page); in nvme_init_ctrl()
4838 cleanup_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4845 * use nvme_uninit_ctrl() to properly free resources associated with the ctrl.
4847 int nvme_add_ctrl(struct nvme_ctrl *ctrl) in nvme_add_ctrl() argument
4851 ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance); in nvme_add_ctrl()
4855 cdev_init(&ctrl->cdev, &nvme_dev_fops); in nvme_add_ctrl()
4856 ctrl->cdev.owner = ctrl->ops->module; in nvme_add_ctrl()
4857 ret = cdev_device_add(&ctrl->cdev, ctrl->device); in nvme_add_ctrl()
4865 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; in nvme_add_ctrl()
4866 dev_pm_qos_update_user_latency_tolerance(ctrl->device, in nvme_add_ctrl()
4869 nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); in nvme_add_ctrl()
4870 nvme_get_ctrl(ctrl); in nvme_add_ctrl()
4877 void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl) in nvme_mark_namespaces_dead() argument
4882 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_mark_namespaces_dead()
4883 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_mark_namespaces_dead()
4884 srcu_read_lock_held(&ctrl->srcu)) in nvme_mark_namespaces_dead()
4886 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_mark_namespaces_dead()
4890 void nvme_unfreeze(struct nvme_ctrl *ctrl) in nvme_unfreeze() argument
4895 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_unfreeze()
4896 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_unfreeze()
4897 srcu_read_lock_held(&ctrl->srcu)) in nvme_unfreeze()
4899 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_unfreeze()
4900 clear_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_unfreeze()
4904 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout) in nvme_wait_freeze_timeout() argument
4909 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze_timeout()
4910 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze_timeout()
4911 srcu_read_lock_held(&ctrl->srcu)) { in nvme_wait_freeze_timeout()
4916 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze_timeout()
4921 void nvme_wait_freeze(struct nvme_ctrl *ctrl) in nvme_wait_freeze() argument
4926 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze()
4927 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze()
4928 srcu_read_lock_held(&ctrl->srcu)) in nvme_wait_freeze()
4930 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze()
4934 void nvme_start_freeze(struct nvme_ctrl *ctrl) in nvme_start_freeze() argument
4939 set_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_start_freeze()
4940 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_start_freeze()
4941 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_start_freeze()
4942 srcu_read_lock_held(&ctrl->srcu)) in nvme_start_freeze()
4944 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_start_freeze()
4948 void nvme_quiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_quiesce_io_queues() argument
4950 if (!ctrl->tagset) in nvme_quiesce_io_queues()
4952 if (!test_and_set_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_quiesce_io_queues()
4953 blk_mq_quiesce_tagset(ctrl->tagset); in nvme_quiesce_io_queues()
4955 blk_mq_wait_quiesce_done(ctrl->tagset); in nvme_quiesce_io_queues()
4959 void nvme_unquiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_unquiesce_io_queues() argument
4961 if (!ctrl->tagset) in nvme_unquiesce_io_queues()
4963 if (test_and_clear_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_unquiesce_io_queues()
4964 blk_mq_unquiesce_tagset(ctrl->tagset); in nvme_unquiesce_io_queues()
4968 void nvme_quiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_quiesce_admin_queue() argument
4970 if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_quiesce_admin_queue()
4971 blk_mq_quiesce_queue(ctrl->admin_q); in nvme_quiesce_admin_queue()
4973 blk_mq_wait_quiesce_done(ctrl->admin_q->tag_set); in nvme_quiesce_admin_queue()
4977 void nvme_unquiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_unquiesce_admin_queue() argument
4979 if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_unquiesce_admin_queue()
4980 blk_mq_unquiesce_queue(ctrl->admin_q); in nvme_unquiesce_admin_queue()
4984 void nvme_sync_io_queues(struct nvme_ctrl *ctrl) in nvme_sync_io_queues() argument
4989 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_sync_io_queues()
4990 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_sync_io_queues()
4991 srcu_read_lock_held(&ctrl->srcu)) in nvme_sync_io_queues()
4993 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_sync_io_queues()
4997 void nvme_sync_queues(struct nvme_ctrl *ctrl) in nvme_sync_queues() argument
4999 nvme_sync_io_queues(ctrl); in nvme_sync_queues()
5000 if (ctrl->admin_q) in nvme_sync_queues()
5001 blk_sync_queue(ctrl->admin_q); in nvme_sync_queues()