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->subsys->awupf) * bs; in nvme_update_disk_info()
2084 if ((ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) && in nvme_update_disk_info()
2085 (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM)) in nvme_update_disk_info()
2088 lim->max_write_zeroes_sectors = ns->ctrl->max_zeroes_sectors; in nvme_update_disk_info()
2106 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_set_chunk_sectors() local
2109 if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) && in nvme_set_chunk_sectors()
2110 is_power_of_2(ctrl->max_hw_sectors)) in nvme_set_chunk_sectors()
2111 iob = ctrl->max_hw_sectors; in nvme_set_chunk_sectors()
2143 nvme_set_ctrl_limits(ns->ctrl, &lim); in nvme_update_ns_info_generic()
2168 ret = nvme_identify_ns(ns->ctrl, info->nsid, &id); in nvme_update_ns_info_block()
2180 if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) { in nvme_update_ns_info_block()
2181 ret = nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); in nvme_update_ns_info_block()
2199 nvme_set_ctrl_limits(ns->ctrl, &lim); in nvme_update_ns_info_block()
2200 nvme_configure_metadata(ns->ctrl, ns->head, id, nvm, info); in nvme_update_ns_info_block()
2209 if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc) in nvme_update_ns_info_block()
2267 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2279 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2371 struct nvme_ctrl *ctrl = data; in nvme_sec_submit() local
2382 return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len, in nvme_sec_submit()
2386 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2388 if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) { in nvme_configure_opal()
2389 if (!ctrl->opal_dev) in nvme_configure_opal()
2390 ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit); in nvme_configure_opal()
2392 opal_unlock_from_suspend(ctrl->opal_dev); in nvme_configure_opal()
2394 free_opal_dev(ctrl->opal_dev); in nvme_configure_opal()
2395 ctrl->opal_dev = NULL; in nvme_configure_opal()
2399 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2427 static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val, in nvme_wait_ready() argument
2434 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_wait_ready()
2444 dev_err(ctrl->device, in nvme_wait_ready()
2454 int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown) in nvme_disable_ctrl() argument
2458 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_disable_ctrl()
2460 ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; in nvme_disable_ctrl()
2462 ctrl->ctrl_config &= ~NVME_CC_ENABLE; in nvme_disable_ctrl()
2464 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_disable_ctrl()
2469 return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK, in nvme_disable_ctrl()
2471 ctrl->shutdown_timeout, "shutdown"); in nvme_disable_ctrl()
2473 if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY) in nvme_disable_ctrl()
2475 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, 0, in nvme_disable_ctrl()
2476 (NVME_CAP_TIMEOUT(ctrl->cap) + 1) / 2, "reset"); in nvme_disable_ctrl()
2480 int nvme_enable_ctrl(struct nvme_ctrl *ctrl) in nvme_enable_ctrl() argument
2486 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2488 dev_err(ctrl->device, "Reading CAP failed (%d)\n", ret); in nvme_enable_ctrl()
2491 dev_page_min = NVME_CAP_MPSMIN(ctrl->cap) + 12; in nvme_enable_ctrl()
2494 dev_err(ctrl->device, in nvme_enable_ctrl()
2500 if (NVME_CAP_CSS(ctrl->cap) & NVME_CAP_CSS_CSI) in nvme_enable_ctrl()
2501 ctrl->ctrl_config = NVME_CC_CSS_CSI; in nvme_enable_ctrl()
2503 ctrl->ctrl_config = NVME_CC_CSS_NVM; in nvme_enable_ctrl()
2511 ctrl->ctrl_config &= ~NVME_CC_CRIME; in nvme_enable_ctrl()
2513 ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT; in nvme_enable_ctrl()
2514 ctrl->ctrl_config |= NVME_CC_AMS_RR | NVME_CC_SHN_NONE; in nvme_enable_ctrl()
2515 ctrl->ctrl_config |= NVME_CC_IOSQES | NVME_CC_IOCQES; in nvme_enable_ctrl()
2516 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2521 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2525 timeout = NVME_CAP_TIMEOUT(ctrl->cap); in nvme_enable_ctrl()
2526 if (ctrl->cap & NVME_CAP_CRMS_CRWMS) { in nvme_enable_ctrl()
2529 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CRTO, &crto); in nvme_enable_ctrl()
2531 dev_err(ctrl->device, "Reading CRTO failed (%d)\n", in nvme_enable_ctrl()
2544 dev_warn_once(ctrl->device, "bad crto:%x cap:%llx\n", in nvme_enable_ctrl()
2545 crto, ctrl->cap); in nvme_enable_ctrl()
2550 ctrl->ctrl_config |= NVME_CC_ENABLE; in nvme_enable_ctrl()
2551 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2554 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, NVME_CSTS_RDY, in nvme_enable_ctrl()
2559 static int nvme_configure_timestamp(struct nvme_ctrl *ctrl) in nvme_configure_timestamp() argument
2564 if (!(ctrl->oncs & NVME_CTRL_ONCS_TIMESTAMP)) in nvme_configure_timestamp()
2568 ret = nvme_set_features(ctrl, NVME_FEAT_TIMESTAMP, 0, &ts, sizeof(ts), in nvme_configure_timestamp()
2571 dev_warn_once(ctrl->device, in nvme_configure_timestamp()
2576 static int nvme_configure_host_options(struct nvme_ctrl *ctrl) in nvme_configure_host_options() argument
2583 if (ctrl->crdt[0]) in nvme_configure_host_options()
2585 if (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) in nvme_configure_host_options()
2597 ret = nvme_set_features(ctrl, NVME_FEAT_HOST_BEHAVIOR, 0, in nvme_configure_host_options()
2657 static int nvme_configure_apst(struct nvme_ctrl *ctrl) in nvme_configure_apst() argument
2672 if (!ctrl->apsta) in nvme_configure_apst()
2675 if (ctrl->npss > 31) { in nvme_configure_apst()
2676 dev_warn(ctrl->device, "NPSS is invalid; not using APST\n"); in nvme_configure_apst()
2684 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) { in nvme_configure_apst()
2686 dev_dbg(ctrl->device, "APST disabled\n"); in nvme_configure_apst()
2696 for (state = (int)ctrl->npss; state >= 0; state--) { in nvme_configure_apst()
2706 if (state == ctrl->npss && in nvme_configure_apst()
2707 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) in nvme_configure_apst()
2714 if (!(ctrl->psd[state].flags & NVME_PS_FLAGS_NON_OP_STATE)) in nvme_configure_apst()
2717 exit_latency_us = (u64)le32_to_cpu(ctrl->psd[state].exit_lat); in nvme_configure_apst()
2718 if (exit_latency_us > ctrl->ps_max_latency_us) in nvme_configure_apst()
2722 le32_to_cpu(ctrl->psd[state].entry_lat); in nvme_configure_apst()
2747 dev_dbg(ctrl->device, "APST enabled but no non-operational states are available\n"); in nvme_configure_apst()
2749 …dev_dbg(ctrl->device, "APST enabled: max PS = %d, max round-trip latency = %lluus, table = %*phN\n… in nvme_configure_apst()
2754 ret = nvme_set_features(ctrl, NVME_FEAT_AUTO_PST, apste, in nvme_configure_apst()
2757 dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret); in nvme_configure_apst()
2764 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_set_latency_tolerance() local
2777 if (ctrl->ps_max_latency_us != latency) { in nvme_set_latency_tolerance()
2778 ctrl->ps_max_latency_us = latency; in nvme_set_latency_tolerance()
2779 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_set_latency_tolerance()
2780 nvme_configure_apst(ctrl); in nvme_set_latency_tolerance()
2875 static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ctrl, in nvme_init_subnqn() argument
2881 if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) { in nvme_init_subnqn()
2888 if (ctrl->vs >= NVME_VS(1, 2, 1)) in nvme_init_subnqn()
2889 dev_warn(ctrl->device, "missing or invalid SUBNQN field.\n"); in nvme_init_subnqn()
2964 static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) in nvme_discovery_ctrl() argument
2966 return ctrl->opts && ctrl->opts->discovery_nqn; in nvme_discovery_ctrl()
2970 struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_validate_cntlid() argument
2980 if (tmp->cntlid == ctrl->cntlid) { in nvme_validate_cntlid()
2981 dev_err(ctrl->device, in nvme_validate_cntlid()
2983 ctrl->cntlid, dev_name(tmp->device), in nvme_validate_cntlid()
2989 nvme_discovery_ctrl(ctrl)) in nvme_validate_cntlid()
2992 dev_err(ctrl->device, in nvme_validate_cntlid()
3000 static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_subsystem() argument
3014 nvme_init_subnqn(subsys, ctrl, id); in nvme_init_subsystem()
3027 if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) { in nvme_init_subsystem()
3028 dev_err(ctrl->device, in nvme_init_subsystem()
3040 dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); in nvme_init_subsystem()
3049 if (!nvme_validate_cntlid(subsys, ctrl, id)) { in nvme_init_subsystem()
3056 dev_err(ctrl->device, in nvme_init_subsystem()
3065 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, in nvme_init_subsystem()
3066 dev_name(ctrl->device)); in nvme_init_subsystem()
3068 dev_err(ctrl->device, in nvme_init_subsystem()
3074 subsys->instance = ctrl->instance; in nvme_init_subsystem()
3075 ctrl->subsys = subsys; in nvme_init_subsystem()
3076 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvme_init_subsystem()
3087 int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, in nvme_get_log() argument
3103 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); in nvme_get_log()
3106 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi, in nvme_get_effects_log() argument
3109 struct nvme_effects_log *old, *cel = xa_load(&ctrl->cels, csi); in nvme_get_effects_log()
3119 ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi, in nvme_get_effects_log()
3126 old = xa_store(&ctrl->cels, csi, cel, GFP_KERNEL); in nvme_get_effects_log()
3136 static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units) in nvme_mps_to_sectors() argument
3138 u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; in nvme_mps_to_sectors()
3145 static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) in nvme_init_non_mdts_limits() argument
3157 if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && in nvme_init_non_mdts_limits()
3158 !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) in nvme_init_non_mdts_limits()
3159 ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; in nvme_init_non_mdts_limits()
3161 ctrl->max_zeroes_sectors = 0; in nvme_init_non_mdts_limits()
3163 if (ctrl->subsys->subtype != NVME_NQN_NVME || in nvme_init_non_mdts_limits()
3164 !nvme_id_cns_ok(ctrl, NVME_ID_CNS_CS_CTRL) || in nvme_init_non_mdts_limits()
3165 test_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags)) in nvme_init_non_mdts_limits()
3176 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_init_non_mdts_limits()
3180 ctrl->dmrl = id->dmrl; in nvme_init_non_mdts_limits()
3181 ctrl->dmrsl = le32_to_cpu(id->dmrsl); in nvme_init_non_mdts_limits()
3183 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); in nvme_init_non_mdts_limits()
3187 set_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags); in nvme_init_non_mdts_limits()
3192 static int nvme_init_effects_log(struct nvme_ctrl *ctrl, in nvme_init_effects_log() argument
3201 old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL); in nvme_init_effects_log()
3211 static void nvme_init_known_nvm_effects(struct nvme_ctrl *ctrl) in nvme_init_known_nvm_effects() argument
3213 struct nvme_effects_log *log = ctrl->effects; in nvme_init_known_nvm_effects()
3243 static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_effects() argument
3247 if (ctrl->effects) in nvme_init_effects()
3251 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3256 if (!ctrl->effects) { in nvme_init_effects()
3257 ret = nvme_init_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3262 nvme_init_known_nvm_effects(ctrl); in nvme_init_effects()
3266 static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_check_ctrl_fabric_info() argument
3272 if (ctrl->cntlid != le16_to_cpu(id->cntlid)) { in nvme_check_ctrl_fabric_info()
3273 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3275 ctrl->cntlid, le16_to_cpu(id->cntlid)); in nvme_check_ctrl_fabric_info()
3279 if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) { in nvme_check_ctrl_fabric_info()
3280 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3285 if (!nvme_discovery_ctrl(ctrl) && ctrl->ioccsz < 4) { in nvme_check_ctrl_fabric_info()
3286 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3288 ctrl->ioccsz); in nvme_check_ctrl_fabric_info()
3292 if (!nvme_discovery_ctrl(ctrl) && ctrl->iorcsz < 1) { in nvme_check_ctrl_fabric_info()
3293 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3295 ctrl->iorcsz); in nvme_check_ctrl_fabric_info()
3299 if (!ctrl->maxcmd) { in nvme_check_ctrl_fabric_info()
3300 dev_warn(ctrl->device, in nvme_check_ctrl_fabric_info()
3302 ctrl->maxcmd = ctrl->sqsize + 1; in nvme_check_ctrl_fabric_info()
3308 static int nvme_init_identify(struct nvme_ctrl *ctrl) in nvme_init_identify() argument
3316 ret = nvme_identify_ctrl(ctrl, &id); in nvme_init_identify()
3318 dev_err(ctrl->device, "Identify Controller failed (%d)\n", ret); in nvme_init_identify()
3322 if (!(ctrl->ops->flags & NVME_F_FABRICS)) in nvme_init_identify()
3323 ctrl->cntlid = le16_to_cpu(id->cntlid); in nvme_init_identify()
3325 if (!ctrl->identified) { in nvme_init_identify()
3338 ctrl->quirks |= core_quirks[i].quirks; in nvme_init_identify()
3341 ret = nvme_init_subsystem(ctrl, id); in nvme_init_identify()
3345 ret = nvme_init_effects(ctrl, id); in nvme_init_identify()
3349 memcpy(ctrl->subsys->firmware_rev, id->fr, in nvme_init_identify()
3350 sizeof(ctrl->subsys->firmware_rev)); in nvme_init_identify()
3352 if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) { in nvme_init_identify()
3353 …dev_warn(ctrl->device, "forcibly allowing all power states due to nvme_core.force_apst -- use at y… in nvme_init_identify()
3354 ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS; in nvme_init_identify()
3357 ctrl->crdt[0] = le16_to_cpu(id->crdt1); in nvme_init_identify()
3358 ctrl->crdt[1] = le16_to_cpu(id->crdt2); in nvme_init_identify()
3359 ctrl->crdt[2] = le16_to_cpu(id->crdt3); in nvme_init_identify()
3361 ctrl->oacs = le16_to_cpu(id->oacs); in nvme_init_identify()
3362 ctrl->oncs = le16_to_cpu(id->oncs); in nvme_init_identify()
3363 ctrl->mtfa = le16_to_cpu(id->mtfa); in nvme_init_identify()
3364 ctrl->oaes = le32_to_cpu(id->oaes); in nvme_init_identify()
3365 ctrl->wctemp = le16_to_cpu(id->wctemp); in nvme_init_identify()
3366 ctrl->cctemp = le16_to_cpu(id->cctemp); in nvme_init_identify()
3368 atomic_set(&ctrl->abort_limit, id->acl + 1); in nvme_init_identify()
3369 ctrl->vwc = id->vwc; in nvme_init_identify()
3371 max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); in nvme_init_identify()
3374 ctrl->max_hw_sectors = in nvme_init_identify()
3375 min_not_zero(ctrl->max_hw_sectors, max_hw_sectors); in nvme_init_identify()
3377 lim = queue_limits_start_update(ctrl->admin_q); in nvme_init_identify()
3378 nvme_set_ctrl_limits(ctrl, &lim); in nvme_init_identify()
3379 ret = queue_limits_commit_update(ctrl->admin_q, &lim); in nvme_init_identify()
3383 ctrl->sgls = le32_to_cpu(id->sgls); in nvme_init_identify()
3384 ctrl->kas = le16_to_cpu(id->kas); in nvme_init_identify()
3385 ctrl->max_namespaces = le32_to_cpu(id->mnan); in nvme_init_identify()
3386 ctrl->ctratt = le32_to_cpu(id->ctratt); in nvme_init_identify()
3388 ctrl->cntrltype = id->cntrltype; in nvme_init_identify()
3389 ctrl->dctype = id->dctype; in nvme_init_identify()
3395 ctrl->shutdown_timeout = clamp_t(unsigned int, transition_time, in nvme_init_identify()
3398 if (ctrl->shutdown_timeout != shutdown_timeout) in nvme_init_identify()
3399 dev_info(ctrl->device, in nvme_init_identify()
3401 ctrl->shutdown_timeout); in nvme_init_identify()
3403 ctrl->shutdown_timeout = shutdown_timeout; in nvme_init_identify()
3405 ctrl->npss = id->npss; in nvme_init_identify()
3406 ctrl->apsta = id->apsta; in nvme_init_identify()
3407 prev_apst_enabled = ctrl->apst_enabled; in nvme_init_identify()
3408 if (ctrl->quirks & NVME_QUIRK_NO_APST) { in nvme_init_identify()
3410 …dev_warn(ctrl->device, "forcibly allowing APST due to nvme_core.force_apst -- use at your own risk… in nvme_init_identify()
3411 ctrl->apst_enabled = true; in nvme_init_identify()
3413 ctrl->apst_enabled = false; in nvme_init_identify()
3416 ctrl->apst_enabled = id->apsta; in nvme_init_identify()
3418 memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd)); in nvme_init_identify()
3420 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_init_identify()
3421 ctrl->icdoff = le16_to_cpu(id->icdoff); in nvme_init_identify()
3422 ctrl->ioccsz = le32_to_cpu(id->ioccsz); in nvme_init_identify()
3423 ctrl->iorcsz = le32_to_cpu(id->iorcsz); in nvme_init_identify()
3424 ctrl->maxcmd = le16_to_cpu(id->maxcmd); in nvme_init_identify()
3426 ret = nvme_check_ctrl_fabric_info(ctrl, id); in nvme_init_identify()
3430 ctrl->hmpre = le32_to_cpu(id->hmpre); in nvme_init_identify()
3431 ctrl->hmmin = le32_to_cpu(id->hmmin); in nvme_init_identify()
3432 ctrl->hmminds = le32_to_cpu(id->hmminds); in nvme_init_identify()
3433 ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); in nvme_init_identify()
3436 ret = nvme_mpath_init_identify(ctrl, id); in nvme_init_identify()
3440 if (ctrl->apst_enabled && !prev_apst_enabled) in nvme_init_identify()
3441 dev_pm_qos_expose_latency_tolerance(ctrl->device); in nvme_init_identify()
3442 else if (!ctrl->apst_enabled && prev_apst_enabled) in nvme_init_identify()
3443 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_identify()
3455 int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_init_ctrl_finish() argument
3459 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); in nvme_init_ctrl_finish()
3461 dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); in nvme_init_ctrl_finish()
3465 ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); in nvme_init_ctrl_finish()
3467 if (ctrl->vs >= NVME_VS(1, 1, 0)) in nvme_init_ctrl_finish()
3468 ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); in nvme_init_ctrl_finish()
3470 ret = nvme_init_identify(ctrl); in nvme_init_ctrl_finish()
3474 ret = nvme_configure_apst(ctrl); in nvme_init_ctrl_finish()
3478 ret = nvme_configure_timestamp(ctrl); in nvme_init_ctrl_finish()
3482 ret = nvme_configure_host_options(ctrl); in nvme_init_ctrl_finish()
3486 nvme_configure_opal(ctrl, was_suspended); in nvme_init_ctrl_finish()
3488 if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3493 ret = nvme_hwmon_init(ctrl); in nvme_init_ctrl_finish()
3498 clear_bit(NVME_CTRL_DIRTY_CAPABILITY, &ctrl->flags); in nvme_init_ctrl_finish()
3499 ctrl->identified = true; in nvme_init_ctrl_finish()
3501 nvme_start_keep_alive(ctrl); in nvme_init_ctrl_finish()
3509 struct nvme_ctrl *ctrl = in nvme_dev_open() local
3512 switch (nvme_ctrl_state(ctrl)) { in nvme_dev_open()
3519 nvme_get_ctrl(ctrl); in nvme_dev_open()
3520 if (!try_module_get(ctrl->ops->module)) { in nvme_dev_open()
3521 nvme_put_ctrl(ctrl); in nvme_dev_open()
3525 file->private_data = ctrl; in nvme_dev_open()
3531 struct nvme_ctrl *ctrl = in nvme_dev_release() local
3534 module_put(ctrl->ops->module); in nvme_dev_release()
3535 nvme_put_ctrl(ctrl); in nvme_dev_release()
3548 static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, in nvme_find_ns_head() argument
3553 lockdep_assert_held(&ctrl->subsys->lock); in nvme_find_ns_head()
3555 list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { in nvme_find_ns_head()
3561 if (h->ns_id != nsid || !nvme_is_unique_nsid(ctrl, h)) in nvme_find_ns_head()
3651 ns->cdev_device.parent = ns->ctrl->device; in nvme_add_ns_cdev()
3653 ns->ctrl->instance, ns->head->instance); in nvme_add_ns_cdev()
3658 ns->ctrl->ops->module); in nvme_add_ns_cdev()
3661 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, in nvme_alloc_ns_head() argument
3675 ret = ida_alloc_min(&ctrl->subsys->ns_ida, 1, GFP_KERNEL); in nvme_alloc_ns_head()
3683 head->subsys = ctrl->subsys; in nvme_alloc_ns_head()
3693 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); in nvme_alloc_ns_head()
3697 head->effects = ctrl->effects; in nvme_alloc_ns_head()
3699 ret = nvme_mpath_alloc_disk(ctrl, head); in nvme_alloc_ns_head()
3703 list_add_tail(&head->entry, &ctrl->subsys->nsheads); in nvme_alloc_ns_head()
3705 kref_get(&ctrl->subsys->ref); in nvme_alloc_ns_head()
3711 ida_free(&ctrl->subsys->ns_ida, head->instance); in nvme_alloc_ns_head()
3748 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ns_head() local
3752 ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3770 nvme_print_device_info(ctrl); in nvme_init_ns_head()
3771 if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ in nvme_init_ns_head()
3772 ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && in nvme_init_ns_head()
3774 dev_err(ctrl->device, in nvme_init_ns_head()
3780 dev_err(ctrl->device, in nvme_init_ns_head()
3782 dev_err(ctrl->device, in nvme_init_ns_head()
3787 ctrl->quirks |= NVME_QUIRK_BOGUS_NID; in nvme_init_ns_head()
3790 mutex_lock(&ctrl->subsys->lock); in nvme_init_ns_head()
3791 head = nvme_find_ns_head(ctrl, info->nsid); in nvme_init_ns_head()
3793 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3795 dev_err(ctrl->device, in nvme_init_ns_head()
3800 head = nvme_alloc_ns_head(ctrl, info); in nvme_init_ns_head()
3808 dev_err(ctrl->device, in nvme_init_ns_head()
3814 dev_err(ctrl->device, in nvme_init_ns_head()
3821 dev_warn(ctrl->device, in nvme_init_ns_head()
3824 dev_warn_once(ctrl->device, in nvme_init_ns_head()
3831 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3837 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3841 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_find_get_ns() argument
3846 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_find_get_ns()
3847 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_find_get_ns()
3848 srcu_read_lock_held(&ctrl->srcu)) { in nvme_find_get_ns()
3858 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_find_get_ns()
3870 list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) { in nvme_ns_add_to_ctrl_list()
3876 list_add(&ns->list, &ns->ctrl->namespaces); in nvme_ns_add_to_ctrl_list()
3879 static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) in nvme_alloc_ns() argument
3884 int node = ctrl->numa_node; in nvme_alloc_ns()
3890 if (ctrl->opts && ctrl->opts->data_digest) in nvme_alloc_ns()
3892 if (ctrl->ops->supports_pci_p2pdma && in nvme_alloc_ns()
3893 ctrl->ops->supports_pci_p2pdma(ctrl)) in nvme_alloc_ns()
3896 disk = blk_mq_alloc_disk(ctrl->tagset, &lim, ns); in nvme_alloc_ns()
3904 ns->ctrl = ctrl; in nvme_alloc_ns()
3922 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3923 ctrl->instance, ns->head->instance); in nvme_alloc_ns()
3926 sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3929 sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, in nvme_alloc_ns()
3936 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3938 * Ensure that no namespaces are added to the ctrl list after the queues in nvme_alloc_ns()
3941 if (test_bit(NVME_CTRL_FROZEN, &ctrl->flags)) { in nvme_alloc_ns()
3942 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3946 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3947 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3948 nvme_get_ctrl(ctrl); in nvme_alloc_ns()
3950 if (device_add_disk(ctrl->device, ns->disk, nvme_ns_attr_groups)) in nvme_alloc_ns()
3969 nvme_put_ctrl(ctrl); in nvme_alloc_ns()
3970 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3972 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3973 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3975 mutex_lock(&ctrl->subsys->lock); in nvme_alloc_ns()
3979 mutex_unlock(&ctrl->subsys->lock); in nvme_alloc_ns()
4008 mutex_lock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4014 mutex_unlock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4023 mutex_lock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
4025 mutex_unlock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
4026 synchronize_srcu(&ns->ctrl->srcu); in nvme_ns_remove()
4033 static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) in nvme_ns_remove_by_nsid() argument
4035 struct nvme_ns *ns = nvme_find_get_ns(ctrl, nsid); in nvme_ns_remove_by_nsid()
4048 dev_err(ns->ctrl->device, in nvme_validate_ns()
4065 static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_scan_ns() argument
4071 if (nvme_identify_ns_descs(ctrl, &info)) in nvme_scan_ns()
4074 if (info.ids.csi != NVME_CSI_NVM && !nvme_multi_css(ctrl)) { in nvme_scan_ns()
4075 dev_warn(ctrl->device, in nvme_scan_ns()
4085 if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || in nvme_scan_ns()
4087 ctrl->vs >= NVME_VS(2, 0, 0)) in nvme_scan_ns()
4088 ret = nvme_ns_info_from_id_cs_indep(ctrl, &info); in nvme_scan_ns()
4090 ret = nvme_ns_info_from_identify(ctrl, &info); in nvme_scan_ns()
4093 nvme_ns_remove_by_nsid(ctrl, nsid); in nvme_scan_ns()
4102 ns = nvme_find_get_ns(ctrl, nsid); in nvme_scan_ns()
4107 nvme_alloc_ns(ctrl, &info); in nvme_scan_ns()
4113 * @ctrl: Controller on which namespaces are being scanned
4123 struct nvme_ctrl *ctrl; member
4137 nvme_scan_ns(scan_info->ctrl, nsid); in nvme_scan_ns_async()
4140 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, in nvme_remove_invalid_namespaces() argument
4146 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4147 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { in nvme_remove_invalid_namespaces()
4150 synchronize_srcu(&ctrl->srcu); in nvme_remove_invalid_namespaces()
4154 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4160 static int nvme_scan_ns_list(struct nvme_ctrl *ctrl) in nvme_scan_ns_list() argument
4173 scan_info.ctrl = ctrl; in nvme_scan_ns_list()
4182 ret = nvme_submit_sync_cmd(ctrl->admin_q, &cmd, ns_list, in nvme_scan_ns_list()
4185 dev_warn(ctrl->device, in nvme_scan_ns_list()
4199 nvme_ns_remove_by_nsid(ctrl, prev); in nvme_scan_ns_list()
4204 nvme_remove_invalid_namespaces(ctrl, prev); in nvme_scan_ns_list()
4211 static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl) in nvme_scan_ns_sequential() argument
4216 if (nvme_identify_ctrl(ctrl, &id)) in nvme_scan_ns_sequential()
4222 nvme_scan_ns(ctrl, i); in nvme_scan_ns_sequential()
4224 nvme_remove_invalid_namespaces(ctrl, nn); in nvme_scan_ns_sequential()
4227 static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl) in nvme_clear_changed_ns_log() argument
4243 error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_CHANGED_NS, 0, in nvme_clear_changed_ns_log()
4246 dev_warn(ctrl->device, in nvme_clear_changed_ns_log()
4254 struct nvme_ctrl *ctrl = in nvme_scan_work() local
4258 /* No tagset on a live ctrl means IO queues could not created */ in nvme_scan_work()
4259 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE || !ctrl->tagset) in nvme_scan_work()
4269 ret = nvme_init_non_mdts_limits(ctrl); in nvme_scan_work()
4271 dev_warn(ctrl->device, in nvme_scan_work()
4276 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { in nvme_scan_work()
4277 dev_info(ctrl->device, "rescanning namespaces.\n"); in nvme_scan_work()
4278 nvme_clear_changed_ns_log(ctrl); in nvme_scan_work()
4281 mutex_lock(&ctrl->scan_lock); in nvme_scan_work()
4282 if (!nvme_id_cns_ok(ctrl, NVME_ID_CNS_NS_ACTIVE_LIST)) { in nvme_scan_work()
4283 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4290 ret = nvme_scan_ns_list(ctrl); in nvme_scan_work()
4292 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4294 mutex_unlock(&ctrl->scan_lock); in nvme_scan_work()
4302 void nvme_remove_namespaces(struct nvme_ctrl *ctrl) in nvme_remove_namespaces() argument
4312 nvme_mpath_clear_ctrl_paths(ctrl); in nvme_remove_namespaces()
4318 nvme_unquiesce_io_queues(ctrl); in nvme_remove_namespaces()
4321 flush_work(&ctrl->scan_work); in nvme_remove_namespaces()
4329 if (nvme_ctrl_state(ctrl) == NVME_CTRL_DEAD) in nvme_remove_namespaces()
4330 nvme_mark_namespaces_dead(ctrl); in nvme_remove_namespaces()
4333 nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); in nvme_remove_namespaces()
4335 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4336 list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu); in nvme_remove_namespaces()
4337 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4338 synchronize_srcu(&ctrl->srcu); in nvme_remove_namespaces()
4347 const struct nvme_ctrl *ctrl = in nvme_class_uevent() local
4349 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_class_uevent()
4352 ret = add_uevent_var(env, "NVME_TRTYPE=%s", ctrl->ops->name); in nvme_class_uevent()
4377 static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata) in nvme_change_uevent() argument
4381 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_change_uevent()
4384 static void nvme_aen_uevent(struct nvme_ctrl *ctrl) in nvme_aen_uevent() argument
4387 u32 aen_result = ctrl->aen_result; in nvme_aen_uevent()
4389 ctrl->aen_result = 0; in nvme_aen_uevent()
4396 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_aen_uevent()
4402 struct nvme_ctrl *ctrl = in nvme_async_event_work() local
4405 nvme_aen_uevent(ctrl); in nvme_async_event_work()
4409 * flushing ctrl async_event_work after changing the controller state in nvme_async_event_work()
4412 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_async_event_work()
4413 ctrl->ops->submit_async_event(ctrl); in nvme_async_event_work()
4416 static bool nvme_ctrl_pp_status(struct nvme_ctrl *ctrl) in nvme_ctrl_pp_status() argument
4421 if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) in nvme_ctrl_pp_status()
4427 return ((ctrl->ctrl_config & NVME_CC_ENABLE) && (csts & NVME_CSTS_PP)); in nvme_ctrl_pp_status()
4430 static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl) in nvme_get_fw_slot_info() argument
4439 if (nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_FW_SLOT, 0, NVME_CSI_NVM, in nvme_get_fw_slot_info()
4441 dev_warn(ctrl->device, "Get FW SLOT INFO log error\n"); in nvme_get_fw_slot_info()
4448 dev_info(ctrl->device, in nvme_get_fw_slot_info()
4453 memcpy(ctrl->subsys->firmware_rev, &log->frs[cur_fw_slot - 1], in nvme_get_fw_slot_info()
4454 sizeof(ctrl->subsys->firmware_rev)); in nvme_get_fw_slot_info()
4462 struct nvme_ctrl *ctrl = container_of(work, in nvme_fw_act_work() local
4466 nvme_auth_stop(ctrl); in nvme_fw_act_work()
4468 if (ctrl->mtfa) in nvme_fw_act_work()
4470 msecs_to_jiffies(ctrl->mtfa * 100); in nvme_fw_act_work()
4475 nvme_quiesce_io_queues(ctrl); in nvme_fw_act_work()
4476 while (nvme_ctrl_pp_status(ctrl)) { in nvme_fw_act_work()
4478 dev_warn(ctrl->device, in nvme_fw_act_work()
4480 nvme_try_sched_reset(ctrl); in nvme_fw_act_work()
4486 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) in nvme_fw_act_work()
4489 nvme_unquiesce_io_queues(ctrl); in nvme_fw_act_work()
4491 nvme_get_fw_slot_info(ctrl); in nvme_fw_act_work()
4493 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_fw_act_work()
4506 static bool nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result) in nvme_handle_aen_notice() argument
4513 set_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events); in nvme_handle_aen_notice()
4514 nvme_queue_scan(ctrl); in nvme_handle_aen_notice()
4522 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) { in nvme_handle_aen_notice()
4524 queue_work(nvme_wq, &ctrl->fw_act_work); in nvme_handle_aen_notice()
4529 if (!ctrl->ana_log_buf) in nvme_handle_aen_notice()
4531 queue_work(nvme_wq, &ctrl->ana_work); in nvme_handle_aen_notice()
4535 ctrl->aen_result = result; in nvme_handle_aen_notice()
4538 dev_warn(ctrl->device, "async event result %08x\n", result); in nvme_handle_aen_notice()
4543 static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl) in nvme_handle_aer_persistent_error() argument
4545 dev_warn(ctrl->device, in nvme_handle_aer_persistent_error()
4547 nvme_reset_ctrl(ctrl); in nvme_handle_aer_persistent_error()
4550 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, in nvme_complete_async_event() argument
4561 trace_nvme_async_event(ctrl, result); in nvme_complete_async_event()
4564 requeue = nvme_handle_aen_notice(ctrl, result); in nvme_complete_async_event()
4572 nvme_handle_aer_persistent_error(ctrl); in nvme_complete_async_event()
4579 ctrl->aen_result = result; in nvme_complete_async_event()
4586 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_complete_async_event()
4590 int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_admin_tag_set() argument
4599 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_admin_tag_set()
4602 set->numa_node = ctrl->numa_node; in nvme_alloc_admin_tag_set()
4603 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_admin_tag_set()
4606 set->driver_data = ctrl; in nvme_alloc_admin_tag_set()
4613 ctrl->admin_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_admin_tag_set()
4614 if (IS_ERR(ctrl->admin_q)) { in nvme_alloc_admin_tag_set()
4615 ret = PTR_ERR(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4619 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_admin_tag_set()
4620 ctrl->fabrics_q = blk_mq_alloc_queue(set, NULL, NULL); in nvme_alloc_admin_tag_set()
4621 if (IS_ERR(ctrl->fabrics_q)) { in nvme_alloc_admin_tag_set()
4622 ret = PTR_ERR(ctrl->fabrics_q); in nvme_alloc_admin_tag_set()
4627 ctrl->admin_tagset = set; in nvme_alloc_admin_tag_set()
4631 blk_mq_destroy_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4632 blk_put_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4635 ctrl->admin_q = NULL; in nvme_alloc_admin_tag_set()
4636 ctrl->fabrics_q = NULL; in nvme_alloc_admin_tag_set()
4641 void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_admin_tag_set() argument
4647 nvme_stop_keep_alive(ctrl); in nvme_remove_admin_tag_set()
4648 blk_mq_destroy_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4649 blk_put_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4650 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_admin_tag_set()
4651 blk_mq_destroy_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4652 blk_put_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4654 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_remove_admin_tag_set()
4658 int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_io_tag_set() argument
4666 set->queue_depth = min_t(unsigned, ctrl->sqsize, BLK_MQ_MAX_DEPTH - 1); in nvme_alloc_io_tag_set()
4671 if (ctrl->quirks & NVME_QUIRK_SHARED_TAGS) in nvme_alloc_io_tag_set()
4673 else if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_io_tag_set()
4676 set->numa_node = ctrl->numa_node; in nvme_alloc_io_tag_set()
4677 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_io_tag_set()
4680 set->driver_data = ctrl; in nvme_alloc_io_tag_set()
4681 set->nr_hw_queues = ctrl->queue_count - 1; in nvme_alloc_io_tag_set()
4688 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_io_tag_set()
4693 ctrl->connect_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_io_tag_set()
4694 if (IS_ERR(ctrl->connect_q)) { in nvme_alloc_io_tag_set()
4695 ret = PTR_ERR(ctrl->connect_q); in nvme_alloc_io_tag_set()
4700 ctrl->tagset = set; in nvme_alloc_io_tag_set()
4705 ctrl->connect_q = NULL; in nvme_alloc_io_tag_set()
4710 void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_io_tag_set() argument
4712 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_io_tag_set()
4713 blk_mq_destroy_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4714 blk_put_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4716 blk_mq_free_tag_set(ctrl->tagset); in nvme_remove_io_tag_set()
4720 void nvme_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_stop_ctrl() argument
4722 nvme_mpath_stop(ctrl); in nvme_stop_ctrl()
4723 nvme_auth_stop(ctrl); in nvme_stop_ctrl()
4724 nvme_stop_failfast_work(ctrl); in nvme_stop_ctrl()
4725 flush_work(&ctrl->async_event_work); in nvme_stop_ctrl()
4726 cancel_work_sync(&ctrl->fw_act_work); in nvme_stop_ctrl()
4727 if (ctrl->ops->stop_ctrl) in nvme_stop_ctrl()
4728 ctrl->ops->stop_ctrl(ctrl); in nvme_stop_ctrl()
4732 void nvme_start_ctrl(struct nvme_ctrl *ctrl) in nvme_start_ctrl() argument
4734 nvme_enable_aen(ctrl); in nvme_start_ctrl()
4742 if (test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags) && in nvme_start_ctrl()
4743 nvme_discovery_ctrl(ctrl)) in nvme_start_ctrl()
4744 nvme_change_uevent(ctrl, "NVME_EVENT=rediscover"); in nvme_start_ctrl()
4746 if (ctrl->queue_count > 1) { in nvme_start_ctrl()
4747 nvme_queue_scan(ctrl); in nvme_start_ctrl()
4748 nvme_unquiesce_io_queues(ctrl); in nvme_start_ctrl()
4749 nvme_mpath_update(ctrl); in nvme_start_ctrl()
4752 nvme_change_uevent(ctrl, "NVME_EVENT=connected"); in nvme_start_ctrl()
4753 set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags); in nvme_start_ctrl()
4757 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) in nvme_uninit_ctrl() argument
4759 nvme_stop_keep_alive(ctrl); in nvme_uninit_ctrl()
4760 nvme_hwmon_exit(ctrl); in nvme_uninit_ctrl()
4761 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_uninit_ctrl()
4762 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_uninit_ctrl()
4763 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_uninit_ctrl()
4764 nvme_put_ctrl(ctrl); in nvme_uninit_ctrl()
4768 static void nvme_free_cels(struct nvme_ctrl *ctrl) in nvme_free_cels() argument
4773 xa_for_each(&ctrl->cels, i, cel) { in nvme_free_cels()
4774 xa_erase(&ctrl->cels, i); in nvme_free_cels()
4778 xa_destroy(&ctrl->cels); in nvme_free_cels()
4783 struct nvme_ctrl *ctrl = in nvme_free_ctrl() local
4785 struct nvme_subsystem *subsys = ctrl->subsys; in nvme_free_ctrl()
4787 if (!subsys || ctrl->instance != subsys->instance) in nvme_free_ctrl()
4788 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_free_ctrl()
4789 nvme_free_cels(ctrl); in nvme_free_ctrl()
4790 nvme_mpath_uninit(ctrl); in nvme_free_ctrl()
4791 cleanup_srcu_struct(&ctrl->srcu); in nvme_free_ctrl()
4792 nvme_auth_stop(ctrl); in nvme_free_ctrl()
4793 nvme_auth_free(ctrl); in nvme_free_ctrl()
4794 __free_page(ctrl->discard_page); in nvme_free_ctrl()
4795 free_opal_dev(ctrl->opal_dev); in nvme_free_ctrl()
4799 list_del(&ctrl->subsys_entry); in nvme_free_ctrl()
4800 sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device)); in nvme_free_ctrl()
4804 ctrl->ops->free_ctrl(ctrl); in nvme_free_ctrl()
4818 int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, in nvme_init_ctrl() argument
4823 WRITE_ONCE(ctrl->state, NVME_CTRL_NEW); in nvme_init_ctrl()
4824 ctrl->passthru_err_log_enabled = false; in nvme_init_ctrl()
4825 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_init_ctrl()
4826 spin_lock_init(&ctrl->lock); in nvme_init_ctrl()
4827 mutex_init(&ctrl->namespaces_lock); in nvme_init_ctrl()
4829 ret = init_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4833 mutex_init(&ctrl->scan_lock); in nvme_init_ctrl()
4834 INIT_LIST_HEAD(&ctrl->namespaces); in nvme_init_ctrl()
4835 xa_init(&ctrl->cels); in nvme_init_ctrl()
4836 ctrl->dev = dev; in nvme_init_ctrl()
4837 ctrl->ops = ops; in nvme_init_ctrl()
4838 ctrl->quirks = quirks; in nvme_init_ctrl()
4839 ctrl->numa_node = NUMA_NO_NODE; in nvme_init_ctrl()
4840 INIT_WORK(&ctrl->scan_work, nvme_scan_work); in nvme_init_ctrl()
4841 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); in nvme_init_ctrl()
4842 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); in nvme_init_ctrl()
4843 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); in nvme_init_ctrl()
4844 init_waitqueue_head(&ctrl->state_wq); in nvme_init_ctrl()
4846 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); in nvme_init_ctrl()
4847 INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); in nvme_init_ctrl()
4848 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); in nvme_init_ctrl()
4849 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; in nvme_init_ctrl()
4850 ctrl->ka_last_check_time = jiffies; in nvme_init_ctrl()
4854 ctrl->discard_page = alloc_page(GFP_KERNEL); in nvme_init_ctrl()
4855 if (!ctrl->discard_page) { in nvme_init_ctrl()
4863 ctrl->instance = ret; in nvme_init_ctrl()
4865 ret = nvme_auth_init_ctrl(ctrl); in nvme_init_ctrl()
4869 nvme_mpath_init_ctrl(ctrl); in nvme_init_ctrl()
4871 device_initialize(&ctrl->ctrl_device); in nvme_init_ctrl()
4872 ctrl->device = &ctrl->ctrl_device; in nvme_init_ctrl()
4873 ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt), in nvme_init_ctrl()
4874 ctrl->instance); in nvme_init_ctrl()
4875 ctrl->device->class = &nvme_class; in nvme_init_ctrl()
4876 ctrl->device->parent = ctrl->dev; in nvme_init_ctrl()
4878 ctrl->device->groups = ops->dev_attr_groups; in nvme_init_ctrl()
4880 ctrl->device->groups = nvme_dev_attr_groups; in nvme_init_ctrl()
4881 ctrl->device->release = nvme_free_ctrl; in nvme_init_ctrl()
4882 dev_set_drvdata(ctrl->device, ctrl); in nvme_init_ctrl()
4887 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_init_ctrl()
4889 if (ctrl->discard_page) in nvme_init_ctrl()
4890 __free_page(ctrl->discard_page); in nvme_init_ctrl()
4891 cleanup_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4898 * use nvme_uninit_ctrl() to properly free resources associated with the ctrl.
4900 int nvme_add_ctrl(struct nvme_ctrl *ctrl) in nvme_add_ctrl() argument
4904 ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance); in nvme_add_ctrl()
4908 cdev_init(&ctrl->cdev, &nvme_dev_fops); in nvme_add_ctrl()
4909 ctrl->cdev.owner = ctrl->ops->module; in nvme_add_ctrl()
4910 ret = cdev_device_add(&ctrl->cdev, ctrl->device); in nvme_add_ctrl()
4918 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; in nvme_add_ctrl()
4919 dev_pm_qos_update_user_latency_tolerance(ctrl->device, in nvme_add_ctrl()
4922 nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); in nvme_add_ctrl()
4923 nvme_get_ctrl(ctrl); in nvme_add_ctrl()
4930 void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl) in nvme_mark_namespaces_dead() argument
4935 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_mark_namespaces_dead()
4936 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_mark_namespaces_dead()
4937 srcu_read_lock_held(&ctrl->srcu)) in nvme_mark_namespaces_dead()
4939 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_mark_namespaces_dead()
4943 void nvme_unfreeze(struct nvme_ctrl *ctrl) in nvme_unfreeze() argument
4948 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_unfreeze()
4949 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_unfreeze()
4950 srcu_read_lock_held(&ctrl->srcu)) in nvme_unfreeze()
4952 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_unfreeze()
4953 clear_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_unfreeze()
4957 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout) in nvme_wait_freeze_timeout() argument
4962 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze_timeout()
4963 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze_timeout()
4964 srcu_read_lock_held(&ctrl->srcu)) { in nvme_wait_freeze_timeout()
4969 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze_timeout()
4974 void nvme_wait_freeze(struct nvme_ctrl *ctrl) in nvme_wait_freeze() argument
4979 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze()
4980 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze()
4981 srcu_read_lock_held(&ctrl->srcu)) in nvme_wait_freeze()
4983 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze()
4987 void nvme_start_freeze(struct nvme_ctrl *ctrl) in nvme_start_freeze() argument
4992 set_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_start_freeze()
4993 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_start_freeze()
4994 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_start_freeze()
4995 srcu_read_lock_held(&ctrl->srcu)) in nvme_start_freeze()
5002 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_start_freeze()
5006 void nvme_quiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_quiesce_io_queues() argument
5008 if (!ctrl->tagset) in nvme_quiesce_io_queues()
5010 if (!test_and_set_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_quiesce_io_queues()
5011 blk_mq_quiesce_tagset(ctrl->tagset); in nvme_quiesce_io_queues()
5013 blk_mq_wait_quiesce_done(ctrl->tagset); in nvme_quiesce_io_queues()
5017 void nvme_unquiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_unquiesce_io_queues() argument
5019 if (!ctrl->tagset) in nvme_unquiesce_io_queues()
5021 if (test_and_clear_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_unquiesce_io_queues()
5022 blk_mq_unquiesce_tagset(ctrl->tagset); in nvme_unquiesce_io_queues()
5026 void nvme_quiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_quiesce_admin_queue() argument
5028 if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_quiesce_admin_queue()
5029 blk_mq_quiesce_queue(ctrl->admin_q); in nvme_quiesce_admin_queue()
5031 blk_mq_wait_quiesce_done(ctrl->admin_q->tag_set); in nvme_quiesce_admin_queue()
5035 void nvme_unquiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_unquiesce_admin_queue() argument
5037 if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_unquiesce_admin_queue()
5038 blk_mq_unquiesce_queue(ctrl->admin_q); in nvme_unquiesce_admin_queue()
5042 void nvme_sync_io_queues(struct nvme_ctrl *ctrl) in nvme_sync_io_queues() argument
5047 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_sync_io_queues()
5048 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_sync_io_queues()
5049 srcu_read_lock_held(&ctrl->srcu)) in nvme_sync_io_queues()
5051 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_sync_io_queues()
5055 void nvme_sync_queues(struct nvme_ctrl *ctrl) in nvme_sync_queues() argument
5057 nvme_sync_io_queues(ctrl); in nvme_sync_queues()
5058 if (ctrl->admin_q) in nvme_sync_queues()
5059 blk_sync_queue(ctrl->admin_q); in nvme_sync_queues()