Lines Matching full:ctrl

124 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
126 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
129 void nvme_queue_scan(struct nvme_ctrl *ctrl) in nvme_queue_scan() argument
134 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE && ctrl->tagset) in nvme_queue_scan()
135 queue_work(nvme_wq, &ctrl->scan_work); in nvme_queue_scan()
144 int nvme_try_sched_reset(struct nvme_ctrl *ctrl) in nvme_try_sched_reset() argument
146 if (nvme_ctrl_state(ctrl) != NVME_CTRL_RESETTING) in nvme_try_sched_reset()
148 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_try_sched_reset()
156 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_failfast_work() local
159 if (nvme_ctrl_state(ctrl) != NVME_CTRL_CONNECTING) in nvme_failfast_work()
162 set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_failfast_work()
163 dev_info(ctrl->device, "failfast expired\n"); in nvme_failfast_work()
164 nvme_kick_requeue_lists(ctrl); in nvme_failfast_work()
167 static inline void nvme_start_failfast_work(struct nvme_ctrl *ctrl) in nvme_start_failfast_work() argument
169 if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) in nvme_start_failfast_work()
172 schedule_delayed_work(&ctrl->failfast_work, in nvme_start_failfast_work()
173 ctrl->opts->fast_io_fail_tmo * HZ); in nvme_start_failfast_work()
176 static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) in nvme_stop_failfast_work() argument
178 if (!ctrl->opts) in nvme_stop_failfast_work()
181 cancel_delayed_work_sync(&ctrl->failfast_work); in nvme_stop_failfast_work()
182 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_stop_failfast_work()
186 int nvme_reset_ctrl(struct nvme_ctrl *ctrl) in nvme_reset_ctrl() argument
188 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) in nvme_reset_ctrl()
190 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_reset_ctrl()
196 int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_reset_ctrl_sync() argument
200 ret = nvme_reset_ctrl(ctrl); in nvme_reset_ctrl_sync()
202 flush_work(&ctrl->reset_work); in nvme_reset_ctrl_sync()
203 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE) in nvme_reset_ctrl_sync()
210 static void nvme_do_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_do_delete_ctrl() argument
212 dev_info(ctrl->device, in nvme_do_delete_ctrl()
213 "Removing ctrl: NQN \"%s\"\n", nvmf_ctrl_subsysnqn(ctrl)); in nvme_do_delete_ctrl()
215 flush_work(&ctrl->reset_work); in nvme_do_delete_ctrl()
216 nvme_stop_ctrl(ctrl); in nvme_do_delete_ctrl()
217 nvme_remove_namespaces(ctrl); in nvme_do_delete_ctrl()
218 ctrl->ops->delete_ctrl(ctrl); in nvme_do_delete_ctrl()
219 nvme_uninit_ctrl(ctrl); in nvme_do_delete_ctrl()
224 struct nvme_ctrl *ctrl = in nvme_delete_ctrl_work() local
227 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_work()
230 int nvme_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_delete_ctrl() argument
232 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl()
234 if (!queue_work(nvme_delete_wq, &ctrl->delete_work)) in nvme_delete_ctrl()
240 void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_delete_ctrl_sync() argument
246 nvme_get_ctrl(ctrl); in nvme_delete_ctrl_sync()
247 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl_sync()
248 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_sync()
249 nvme_put_ctrl(ctrl); in nvme_delete_ctrl_sync()
302 delay = nvme_req(req)->ctrl->crdt[crd - 1] * 100; in nvme_retry_req()
330 dev_name(nr->ctrl->device), in nvme_log_error()
395 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_complete_rq() local
408 if (ctrl->kas && in nvme_complete_rq()
409 req->deadline - req->timeout >= ctrl->ka_last_check_time) in nvme_complete_rq()
410 ctrl->comp_seen = true; in nvme_complete_rq()
424 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_complete_rq()
473 void nvme_cancel_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_tagset() argument
475 if (ctrl->tagset) { in nvme_cancel_tagset()
476 blk_mq_tagset_busy_iter(ctrl->tagset, in nvme_cancel_tagset()
477 nvme_cancel_request, ctrl); in nvme_cancel_tagset()
478 blk_mq_tagset_wait_completed_request(ctrl->tagset); in nvme_cancel_tagset()
483 void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_admin_tagset() argument
485 if (ctrl->admin_tagset) { in nvme_cancel_admin_tagset()
486 blk_mq_tagset_busy_iter(ctrl->admin_tagset, in nvme_cancel_admin_tagset()
487 nvme_cancel_request, ctrl); in nvme_cancel_admin_tagset()
488 blk_mq_tagset_wait_completed_request(ctrl->admin_tagset); in nvme_cancel_admin_tagset()
493 bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, in nvme_change_ctrl_state() argument
500 spin_lock_irqsave(&ctrl->lock, flags); in nvme_change_ctrl_state()
502 old_state = nvme_ctrl_state(ctrl); in nvme_change_ctrl_state()
570 WRITE_ONCE(ctrl->state, new_state); in nvme_change_ctrl_state()
571 wake_up_all(&ctrl->state_wq); in nvme_change_ctrl_state()
574 spin_unlock_irqrestore(&ctrl->lock, flags); in nvme_change_ctrl_state()
580 nvme_stop_failfast_work(ctrl); in nvme_change_ctrl_state()
581 nvme_kick_requeue_lists(ctrl); in nvme_change_ctrl_state()
584 nvme_start_failfast_work(ctrl); in nvme_change_ctrl_state()
594 bool nvme_wait_reset(struct nvme_ctrl *ctrl) in nvme_wait_reset() argument
596 wait_event(ctrl->state_wq, in nvme_wait_reset()
597 nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING) || in nvme_wait_reset()
598 nvme_state_terminal(ctrl)); in nvme_wait_reset()
599 return nvme_ctrl_state(ctrl) == NVME_CTRL_RESETTING; in nvme_wait_reset()
631 nvme_put_ctrl(ns->ctrl); in nvme_free_ns()
683 blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl, in nvme_fail_nonready_command() argument
686 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_fail_nonready_command()
691 !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) && in nvme_fail_nonready_command()
698 bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq, in __nvme_check_ready() argument
711 if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD)) in __nvme_check_ready()
714 if (ctrl->ops->flags & NVME_F_FABRICS) { in __nvme_check_ready()
720 switch (nvme_ctrl_state(ctrl)) { in __nvme_check_ready()
768 if (test_and_set_bit_lock(0, &ns->ctrl->discard_page_busy)) in nvme_setup_discard()
771 range = page_address(ns->ctrl->discard_page); in nvme_setup_discard()
797 if (virt_to_page(range) == ns->ctrl->discard_page) in nvme_setup_discard()
798 clear_bit_unlock(0, &ns->ctrl->discard_page_busy); in nvme_setup_discard()
845 if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_setup_write_zeroes()
935 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_cleanup_cmd() local
937 if (req->special_vec.bv_page == ctrl->discard_page) in nvme_cleanup_cmd()
938 clear_bit_unlock(0, &ctrl->discard_page_busy); in nvme_cleanup_cmd()
1064 u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_command_effects() argument
1071 dev_warn_once(ctrl->device, in nvme_command_effects()
1082 effects = le32_to_cpu(ctrl->effects->acs[opcode]); in nvme_command_effects()
1089 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_passthru_start() argument
1091 u32 effects = nvme_command_effects(ctrl, ns, opcode); in nvme_passthru_start()
1098 mutex_lock(&ctrl->scan_lock); in nvme_passthru_start()
1099 mutex_lock(&ctrl->subsys->lock); in nvme_passthru_start()
1100 nvme_mpath_start_freeze(ctrl->subsys); in nvme_passthru_start()
1101 nvme_mpath_wait_freeze(ctrl->subsys); in nvme_passthru_start()
1102 nvme_start_freeze(ctrl); in nvme_passthru_start()
1103 nvme_wait_freeze(ctrl); in nvme_passthru_start()
1109 void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, in nvme_passthru_end() argument
1113 nvme_unfreeze(ctrl); in nvme_passthru_end()
1114 nvme_mpath_unfreeze(ctrl->subsys); in nvme_passthru_end()
1115 mutex_unlock(&ctrl->subsys->lock); in nvme_passthru_end()
1116 mutex_unlock(&ctrl->scan_lock); in nvme_passthru_end()
1120 &ctrl->flags)) { in nvme_passthru_end()
1121 dev_info(ctrl->device, in nvme_passthru_end()
1126 nvme_queue_scan(ctrl); in nvme_passthru_end()
1127 flush_work(&ctrl->scan_work); in nvme_passthru_end()
1142 nvme_update_keep_alive(ctrl, cmd); in nvme_passthru_end()
1160 static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl) in nvme_keep_alive_work_period() argument
1162 unsigned long delay = ctrl->kato * HZ / 2; in nvme_keep_alive_work_period()
1170 if (ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) in nvme_keep_alive_work_period()
1175 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) in nvme_queue_keep_alive_work() argument
1177 queue_delayed_work(nvme_wq, &ctrl->ka_work, in nvme_queue_keep_alive_work()
1178 nvme_keep_alive_work_period(ctrl)); in nvme_queue_keep_alive_work()
1184 struct nvme_ctrl *ctrl = rq->end_io_data; in nvme_keep_alive_end_io() local
1186 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_keep_alive_end_io()
1187 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_keep_alive_end_io()
1196 dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n", in nvme_keep_alive_end_io()
1204 dev_err(ctrl->device, in nvme_keep_alive_end_io()
1210 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_end_io()
1211 ctrl->comp_seen = false; in nvme_keep_alive_end_io()
1213 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_keep_alive_end_io()
1219 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_keep_alive_work() local
1221 bool comp_seen = ctrl->comp_seen; in nvme_keep_alive_work()
1224 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_work()
1226 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { in nvme_keep_alive_work()
1227 dev_dbg(ctrl->device, in nvme_keep_alive_work()
1229 ctrl->comp_seen = false; in nvme_keep_alive_work()
1230 nvme_queue_keep_alive_work(ctrl); in nvme_keep_alive_work()
1234 rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd), in nvme_keep_alive_work()
1238 dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq)); in nvme_keep_alive_work()
1239 nvme_reset_ctrl(ctrl); in nvme_keep_alive_work()
1242 nvme_init_request(rq, &ctrl->ka_cmd); in nvme_keep_alive_work()
1244 rq->timeout = ctrl->kato * HZ; in nvme_keep_alive_work()
1246 rq->end_io_data = ctrl; in nvme_keep_alive_work()
1250 static void nvme_start_keep_alive(struct nvme_ctrl *ctrl) in nvme_start_keep_alive() argument
1252 if (unlikely(ctrl->kato == 0)) in nvme_start_keep_alive()
1255 nvme_queue_keep_alive_work(ctrl); in nvme_start_keep_alive()
1258 void nvme_stop_keep_alive(struct nvme_ctrl *ctrl) in nvme_stop_keep_alive() argument
1260 if (unlikely(ctrl->kato == 0)) in nvme_stop_keep_alive()
1263 cancel_delayed_work_sync(&ctrl->ka_work); in nvme_stop_keep_alive()
1267 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, in nvme_update_keep_alive() argument
1273 dev_info(ctrl->device, in nvme_update_keep_alive()
1275 ctrl->kato * 1000 / 2, new_kato * 1000 / 2); in nvme_update_keep_alive()
1277 nvme_stop_keep_alive(ctrl); in nvme_update_keep_alive()
1278 ctrl->kato = new_kato; in nvme_update_keep_alive()
1279 nvme_start_keep_alive(ctrl); in nvme_update_keep_alive()
1288 static bool nvme_ctrl_limited_cns(struct nvme_ctrl *ctrl) in nvme_ctrl_limited_cns() argument
1290 if (ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS) in nvme_ctrl_limited_cns()
1291 return ctrl->vs < NVME_VS(1, 2, 0); in nvme_ctrl_limited_cns()
1292 return ctrl->vs < NVME_VS(1, 1, 0); in nvme_ctrl_limited_cns()
1317 static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, in nvme_process_ns_desc() argument
1320 const char *warn_str = "ctrl returned bogus length:"; in nvme_process_ns_desc()
1326 dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n", in nvme_process_ns_desc()
1330 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1336 dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n", in nvme_process_ns_desc()
1340 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1346 dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n", in nvme_process_ns_desc()
1350 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1356 dev_warn(ctrl->device, "%s %d for NVME_NIDT_CSI\n", in nvme_process_ns_desc()
1369 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, in nvme_identify_ns_descs() argument
1377 if (ctrl->vs < NVME_VS(1, 3, 0) && !nvme_multi_css(ctrl)) in nvme_identify_ns_descs()
1379 if (ctrl->quirks & NVME_QUIRK_NO_NS_DESC_LIST) in nvme_identify_ns_descs()
1390 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data, in nvme_identify_ns_descs()
1393 dev_warn(ctrl->device, in nvme_identify_ns_descs()
1405 len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); in nvme_identify_ns_descs()
1412 if (nvme_multi_css(ctrl) && !csi_seen) { in nvme_identify_ns_descs()
1413 dev_warn(ctrl->device, "Command set not reported for nsid:%d\n", in nvme_identify_ns_descs()
1423 static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, in nvme_identify_ns() argument
1438 error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id)); in nvme_identify_ns()
1440 dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error); in nvme_identify_ns()
1447 static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, in nvme_ns_info_from_identify() argument
1454 ret = nvme_identify_ns(ctrl, info->nsid, &id); in nvme_ns_info_from_identify()
1469 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) { in nvme_ns_info_from_identify()
1470 dev_info(ctrl->device, in nvme_ns_info_from_identify()
1473 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_ns_info_from_identify()
1476 if (ctrl->vs >= NVME_VS(1, 2, 0) && in nvme_ns_info_from_identify()
1486 static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, in nvme_ns_info_from_id_cs_indep() argument
1501 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_ns_info_from_id_cs_indep()
1548 int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) in nvme_set_queue_count() argument
1554 status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0, in nvme_set_queue_count()
1571 dev_err(ctrl->device, "Could not set queue count (%d)\n", status); in nvme_set_queue_count()
1586 static void nvme_enable_aen(struct nvme_ctrl *ctrl) in nvme_enable_aen() argument
1588 u32 result, supported_aens = ctrl->oaes & NVME_AEN_SUPPORTED; in nvme_enable_aen()
1594 status = nvme_set_features(ctrl, NVME_FEAT_ASYNC_EVENT, supported_aens, in nvme_enable_aen()
1597 dev_warn(ctrl->device, "Failed to configure AEN (cfg %x)\n", in nvme_enable_aen()
1600 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_enable_aen()
1611 if (!try_module_get(ns->ctrl->ops->module)) in nvme_ns_open()
1625 module_put(ns->ctrl->ops->module); in nvme_ns_release()
1708 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_config_discard() local
1712 if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns, UINT_MAX)) in nvme_config_discard()
1713 ctrl->max_discard_sectors = nvme_lba_to_sect(ns, ctrl->dmrsl); in nvme_config_discard()
1715 if (ctrl->max_discard_sectors == 0) { in nvme_config_discard()
1729 blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors); in nvme_config_discard()
1730 blk_queue_max_discard_segments(queue, ctrl->max_discard_segments); in nvme_config_discard()
1732 if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_config_discard()
1748 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ms() local
1756 if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { in nvme_init_ms()
1771 ret = nvme_submit_sync_cmd(ns->ctrl->admin_q, &c, nvm, sizeof(*nvm)); in nvme_init_ms()
1806 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_configure_metadata() local
1814 if (!ns->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) in nvme_configure_metadata()
1817 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_configure_metadata()
1837 if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)) in nvme_configure_metadata()
1854 static void nvme_set_queue_limits(struct nvme_ctrl *ctrl, in nvme_set_queue_limits() argument
1857 bool vwc = ctrl->vwc & NVME_CTRL_VWC_PRESENT; in nvme_set_queue_limits()
1859 if (ctrl->max_hw_sectors) { in nvme_set_queue_limits()
1861 (ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> 9)) + 1; in nvme_set_queue_limits()
1863 max_segments = min_not_zero(max_segments, ctrl->max_segments); in nvme_set_queue_limits()
1864 blk_queue_max_hw_sectors(q, ctrl->max_hw_sectors); in nvme_set_queue_limits()
1901 atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; in nvme_update_disk_info()
1931 ns->ctrl->max_integrity_segments); in nvme_update_disk_info()
1940 ns->ctrl->max_zeroes_sectors); in nvme_update_disk_info()
1956 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_set_chunk_sectors() local
1959 if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) && in nvme_set_chunk_sectors()
1960 is_power_of_2(ctrl->max_hw_sectors)) in nvme_set_chunk_sectors()
1961 iob = ctrl->max_hw_sectors; in nvme_set_chunk_sectors()
1989 nvme_set_queue_limits(ns->ctrl, ns->queue); in nvme_update_ns_info_generic()
2017 ret = nvme_identify_ns(ns->ctrl, info->nsid, &id); in nvme_update_ns_info_block()
2031 nvme_set_queue_limits(ns->ctrl, ns->queue); in nvme_update_ns_info_block()
2100 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2109 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2120 struct nvme_ctrl *ctrl = data; in nvme_sec_submit() local
2131 return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len, in nvme_sec_submit()
2135 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2137 if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) { in nvme_configure_opal()
2138 if (!ctrl->opal_dev) in nvme_configure_opal()
2139 ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit); in nvme_configure_opal()
2141 opal_unlock_from_suspend(ctrl->opal_dev); in nvme_configure_opal()
2143 free_opal_dev(ctrl->opal_dev); in nvme_configure_opal()
2144 ctrl->opal_dev = NULL; in nvme_configure_opal()
2148 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2175 static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val, in nvme_wait_ready() argument
2182 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_wait_ready()
2192 dev_err(ctrl->device, in nvme_wait_ready()
2202 int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown) in nvme_disable_ctrl() argument
2206 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_disable_ctrl()
2208 ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; in nvme_disable_ctrl()
2210 ctrl->ctrl_config &= ~NVME_CC_ENABLE; in nvme_disable_ctrl()
2212 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_disable_ctrl()
2217 return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK, in nvme_disable_ctrl()
2219 ctrl->shutdown_timeout, "shutdown"); in nvme_disable_ctrl()
2221 if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY) in nvme_disable_ctrl()
2223 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, 0, in nvme_disable_ctrl()
2224 (NVME_CAP_TIMEOUT(ctrl->cap) + 1) / 2, "reset"); in nvme_disable_ctrl()
2228 int nvme_enable_ctrl(struct nvme_ctrl *ctrl) in nvme_enable_ctrl() argument
2234 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2236 dev_err(ctrl->device, "Reading CAP failed (%d)\n", ret); in nvme_enable_ctrl()
2239 dev_page_min = NVME_CAP_MPSMIN(ctrl->cap) + 12; in nvme_enable_ctrl()
2242 dev_err(ctrl->device, in nvme_enable_ctrl()
2248 if (NVME_CAP_CSS(ctrl->cap) & NVME_CAP_CSS_CSI) in nvme_enable_ctrl()
2249 ctrl->ctrl_config = NVME_CC_CSS_CSI; in nvme_enable_ctrl()
2251 ctrl->ctrl_config = NVME_CC_CSS_NVM; in nvme_enable_ctrl()
2259 ctrl->ctrl_config &= ~NVME_CC_CRIME; in nvme_enable_ctrl()
2261 ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT; in nvme_enable_ctrl()
2262 ctrl->ctrl_config |= NVME_CC_AMS_RR | NVME_CC_SHN_NONE; in nvme_enable_ctrl()
2263 ctrl->ctrl_config |= NVME_CC_IOSQES | NVME_CC_IOCQES; in nvme_enable_ctrl()
2264 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2269 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CC, &ctrl->ctrl_config); in nvme_enable_ctrl()
2274 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2278 timeout = NVME_CAP_TIMEOUT(ctrl->cap); in nvme_enable_ctrl()
2279 if (ctrl->cap & NVME_CAP_CRMS_CRWMS) { in nvme_enable_ctrl()
2282 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CRTO, &crto); in nvme_enable_ctrl()
2284 dev_err(ctrl->device, "Reading CRTO failed (%d)\n", in nvme_enable_ctrl()
2297 dev_warn_once(ctrl->device, "bad crto:%x cap:%llx\n", in nvme_enable_ctrl()
2298 crto, ctrl->cap); in nvme_enable_ctrl()
2303 ctrl->ctrl_config |= NVME_CC_ENABLE; in nvme_enable_ctrl()
2304 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2307 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, NVME_CSTS_RDY, in nvme_enable_ctrl()
2312 static int nvme_configure_timestamp(struct nvme_ctrl *ctrl) in nvme_configure_timestamp() argument
2317 if (!(ctrl->oncs & NVME_CTRL_ONCS_TIMESTAMP)) in nvme_configure_timestamp()
2321 ret = nvme_set_features(ctrl, NVME_FEAT_TIMESTAMP, 0, &ts, sizeof(ts), in nvme_configure_timestamp()
2324 dev_warn_once(ctrl->device, in nvme_configure_timestamp()
2329 static int nvme_configure_host_options(struct nvme_ctrl *ctrl) in nvme_configure_host_options() argument
2336 if (ctrl->crdt[0]) in nvme_configure_host_options()
2338 if (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) in nvme_configure_host_options()
2350 ret = nvme_set_features(ctrl, NVME_FEAT_HOST_BEHAVIOR, 0, in nvme_configure_host_options()
2410 static int nvme_configure_apst(struct nvme_ctrl *ctrl) in nvme_configure_apst() argument
2425 if (!ctrl->apsta) in nvme_configure_apst()
2428 if (ctrl->npss > 31) { in nvme_configure_apst()
2429 dev_warn(ctrl->device, "NPSS is invalid; not using APST\n"); in nvme_configure_apst()
2437 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) { in nvme_configure_apst()
2439 dev_dbg(ctrl->device, "APST disabled\n"); in nvme_configure_apst()
2449 for (state = (int)ctrl->npss; state >= 0; state--) { in nvme_configure_apst()
2459 if (state == ctrl->npss && in nvme_configure_apst()
2460 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) in nvme_configure_apst()
2467 if (!(ctrl->psd[state].flags & NVME_PS_FLAGS_NON_OP_STATE)) in nvme_configure_apst()
2470 exit_latency_us = (u64)le32_to_cpu(ctrl->psd[state].exit_lat); in nvme_configure_apst()
2471 if (exit_latency_us > ctrl->ps_max_latency_us) in nvme_configure_apst()
2475 le32_to_cpu(ctrl->psd[state].entry_lat); in nvme_configure_apst()
2500 dev_dbg(ctrl->device, "APST enabled but no non-operational states are available\n"); in nvme_configure_apst()
2502 …dev_dbg(ctrl->device, "APST enabled: max PS = %d, max round-trip latency = %lluus, table = %*phN\n… in nvme_configure_apst()
2507 ret = nvme_set_features(ctrl, NVME_FEAT_AUTO_PST, apste, in nvme_configure_apst()
2510 dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret); in nvme_configure_apst()
2517 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_set_latency_tolerance() local
2530 if (ctrl->ps_max_latency_us != latency) { in nvme_set_latency_tolerance()
2531 ctrl->ps_max_latency_us = latency; in nvme_set_latency_tolerance()
2532 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_set_latency_tolerance()
2533 nvme_configure_apst(ctrl); in nvme_set_latency_tolerance()
2628 static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ctrl, in nvme_init_subnqn() argument
2634 if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) { in nvme_init_subnqn()
2641 if (ctrl->vs >= NVME_VS(1, 2, 1)) in nvme_init_subnqn()
2642 dev_warn(ctrl->device, "missing or invalid SUBNQN field.\n"); in nvme_init_subnqn()
2717 static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) in nvme_discovery_ctrl() argument
2719 return ctrl->opts && ctrl->opts->discovery_nqn; in nvme_discovery_ctrl()
2723 struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_validate_cntlid() argument
2733 if (tmp->cntlid == ctrl->cntlid) { in nvme_validate_cntlid()
2734 dev_err(ctrl->device, in nvme_validate_cntlid()
2736 ctrl->cntlid, dev_name(tmp->device), in nvme_validate_cntlid()
2742 nvme_discovery_ctrl(ctrl)) in nvme_validate_cntlid()
2745 dev_err(ctrl->device, in nvme_validate_cntlid()
2753 static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_subsystem() argument
2767 nvme_init_subnqn(subsys, ctrl, id); in nvme_init_subsystem()
2780 if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) { in nvme_init_subsystem()
2781 dev_err(ctrl->device, in nvme_init_subsystem()
2793 dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); in nvme_init_subsystem()
2802 if (!nvme_validate_cntlid(subsys, ctrl, id)) { in nvme_init_subsystem()
2809 dev_err(ctrl->device, in nvme_init_subsystem()
2818 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, in nvme_init_subsystem()
2819 dev_name(ctrl->device)); in nvme_init_subsystem()
2821 dev_err(ctrl->device, in nvme_init_subsystem()
2827 subsys->instance = ctrl->instance; in nvme_init_subsystem()
2828 ctrl->subsys = subsys; in nvme_init_subsystem()
2829 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvme_init_subsystem()
2840 int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, in nvme_get_log() argument
2856 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); in nvme_get_log()
2859 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi, in nvme_get_effects_log() argument
2862 struct nvme_effects_log *old, *cel = xa_load(&ctrl->cels, csi); in nvme_get_effects_log()
2872 ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi, in nvme_get_effects_log()
2879 old = xa_store(&ctrl->cels, csi, cel, GFP_KERNEL); in nvme_get_effects_log()
2889 static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units) in nvme_mps_to_sectors() argument
2891 u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; in nvme_mps_to_sectors()
2898 static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) in nvme_init_non_mdts_limits() argument
2904 if (ctrl->oncs & NVME_CTRL_ONCS_DSM) { in nvme_init_non_mdts_limits()
2905 ctrl->max_discard_sectors = UINT_MAX; in nvme_init_non_mdts_limits()
2906 ctrl->max_discard_segments = NVME_DSM_MAX_RANGES; in nvme_init_non_mdts_limits()
2908 ctrl->max_discard_sectors = 0; in nvme_init_non_mdts_limits()
2909 ctrl->max_discard_segments = 0; in nvme_init_non_mdts_limits()
2918 if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && in nvme_init_non_mdts_limits()
2919 !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) in nvme_init_non_mdts_limits()
2920 ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; in nvme_init_non_mdts_limits()
2922 ctrl->max_zeroes_sectors = 0; in nvme_init_non_mdts_limits()
2924 if (ctrl->subsys->subtype != NVME_NQN_NVME || in nvme_init_non_mdts_limits()
2925 nvme_ctrl_limited_cns(ctrl) || in nvme_init_non_mdts_limits()
2926 test_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags)) in nvme_init_non_mdts_limits()
2937 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_init_non_mdts_limits()
2942 ctrl->max_discard_segments = id->dmrl; in nvme_init_non_mdts_limits()
2943 ctrl->dmrsl = le32_to_cpu(id->dmrsl); in nvme_init_non_mdts_limits()
2945 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); in nvme_init_non_mdts_limits()
2949 set_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags); in nvme_init_non_mdts_limits()
2954 static int nvme_init_effects_log(struct nvme_ctrl *ctrl, in nvme_init_effects_log() argument
2963 old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL); in nvme_init_effects_log()
2973 static void nvme_init_known_nvm_effects(struct nvme_ctrl *ctrl) in nvme_init_known_nvm_effects() argument
2975 struct nvme_effects_log *log = ctrl->effects; in nvme_init_known_nvm_effects()
3005 static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_effects() argument
3009 if (ctrl->effects) in nvme_init_effects()
3013 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3018 if (!ctrl->effects) { in nvme_init_effects()
3019 ret = nvme_init_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3024 nvme_init_known_nvm_effects(ctrl); in nvme_init_effects()
3028 static int nvme_init_identify(struct nvme_ctrl *ctrl) in nvme_init_identify() argument
3035 ret = nvme_identify_ctrl(ctrl, &id); in nvme_init_identify()
3037 dev_err(ctrl->device, "Identify Controller failed (%d)\n", ret); in nvme_init_identify()
3041 if (!(ctrl->ops->flags & NVME_F_FABRICS)) in nvme_init_identify()
3042 ctrl->cntlid = le16_to_cpu(id->cntlid); in nvme_init_identify()
3044 if (!ctrl->identified) { in nvme_init_identify()
3057 ctrl->quirks |= core_quirks[i].quirks; in nvme_init_identify()
3060 ret = nvme_init_subsystem(ctrl, id); in nvme_init_identify()
3064 ret = nvme_init_effects(ctrl, id); in nvme_init_identify()
3068 memcpy(ctrl->subsys->firmware_rev, id->fr, in nvme_init_identify()
3069 sizeof(ctrl->subsys->firmware_rev)); in nvme_init_identify()
3071 if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) { in nvme_init_identify()
3072 …dev_warn(ctrl->device, "forcibly allowing all power states due to nvme_core.force_apst -- use at y… in nvme_init_identify()
3073 ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS; in nvme_init_identify()
3076 ctrl->crdt[0] = le16_to_cpu(id->crdt1); in nvme_init_identify()
3077 ctrl->crdt[1] = le16_to_cpu(id->crdt2); in nvme_init_identify()
3078 ctrl->crdt[2] = le16_to_cpu(id->crdt3); in nvme_init_identify()
3080 ctrl->oacs = le16_to_cpu(id->oacs); in nvme_init_identify()
3081 ctrl->oncs = le16_to_cpu(id->oncs); in nvme_init_identify()
3082 ctrl->mtfa = le16_to_cpu(id->mtfa); in nvme_init_identify()
3083 ctrl->oaes = le32_to_cpu(id->oaes); in nvme_init_identify()
3084 ctrl->wctemp = le16_to_cpu(id->wctemp); in nvme_init_identify()
3085 ctrl->cctemp = le16_to_cpu(id->cctemp); in nvme_init_identify()
3087 atomic_set(&ctrl->abort_limit, id->acl + 1); in nvme_init_identify()
3088 ctrl->vwc = id->vwc; in nvme_init_identify()
3090 max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); in nvme_init_identify()
3093 ctrl->max_hw_sectors = in nvme_init_identify()
3094 min_not_zero(ctrl->max_hw_sectors, max_hw_sectors); in nvme_init_identify()
3096 nvme_set_queue_limits(ctrl, ctrl->admin_q); in nvme_init_identify()
3097 ctrl->sgls = le32_to_cpu(id->sgls); in nvme_init_identify()
3098 ctrl->kas = le16_to_cpu(id->kas); in nvme_init_identify()
3099 ctrl->max_namespaces = le32_to_cpu(id->mnan); in nvme_init_identify()
3100 ctrl->ctratt = le32_to_cpu(id->ctratt); in nvme_init_identify()
3102 ctrl->cntrltype = id->cntrltype; in nvme_init_identify()
3103 ctrl->dctype = id->dctype; in nvme_init_identify()
3109 ctrl->shutdown_timeout = clamp_t(unsigned int, transition_time, in nvme_init_identify()
3112 if (ctrl->shutdown_timeout != shutdown_timeout) in nvme_init_identify()
3113 dev_info(ctrl->device, in nvme_init_identify()
3115 ctrl->shutdown_timeout); in nvme_init_identify()
3117 ctrl->shutdown_timeout = shutdown_timeout; in nvme_init_identify()
3119 ctrl->npss = id->npss; in nvme_init_identify()
3120 ctrl->apsta = id->apsta; in nvme_init_identify()
3121 prev_apst_enabled = ctrl->apst_enabled; in nvme_init_identify()
3122 if (ctrl->quirks & NVME_QUIRK_NO_APST) { in nvme_init_identify()
3124 …dev_warn(ctrl->device, "forcibly allowing APST due to nvme_core.force_apst -- use at your own risk… in nvme_init_identify()
3125 ctrl->apst_enabled = true; in nvme_init_identify()
3127 ctrl->apst_enabled = false; in nvme_init_identify()
3130 ctrl->apst_enabled = id->apsta; in nvme_init_identify()
3132 memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd)); in nvme_init_identify()
3134 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_init_identify()
3135 ctrl->icdoff = le16_to_cpu(id->icdoff); in nvme_init_identify()
3136 ctrl->ioccsz = le32_to_cpu(id->ioccsz); in nvme_init_identify()
3137 ctrl->iorcsz = le32_to_cpu(id->iorcsz); in nvme_init_identify()
3138 ctrl->maxcmd = le16_to_cpu(id->maxcmd); in nvme_init_identify()
3144 if (ctrl->cntlid != le16_to_cpu(id->cntlid)) { in nvme_init_identify()
3145 dev_err(ctrl->device, in nvme_init_identify()
3148 ctrl->cntlid, le16_to_cpu(id->cntlid)); in nvme_init_identify()
3153 if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) { in nvme_init_identify()
3154 dev_err(ctrl->device, in nvme_init_identify()
3160 ctrl->hmpre = le32_to_cpu(id->hmpre); in nvme_init_identify()
3161 ctrl->hmmin = le32_to_cpu(id->hmmin); in nvme_init_identify()
3162 ctrl->hmminds = le32_to_cpu(id->hmminds); in nvme_init_identify()
3163 ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); in nvme_init_identify()
3166 ret = nvme_mpath_init_identify(ctrl, id); in nvme_init_identify()
3170 if (ctrl->apst_enabled && !prev_apst_enabled) in nvme_init_identify()
3171 dev_pm_qos_expose_latency_tolerance(ctrl->device); in nvme_init_identify()
3172 else if (!ctrl->apst_enabled && prev_apst_enabled) in nvme_init_identify()
3173 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_identify()
3185 int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_init_ctrl_finish() argument
3189 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); in nvme_init_ctrl_finish()
3191 dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); in nvme_init_ctrl_finish()
3195 ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); in nvme_init_ctrl_finish()
3197 if (ctrl->vs >= NVME_VS(1, 1, 0)) in nvme_init_ctrl_finish()
3198 ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); in nvme_init_ctrl_finish()
3200 ret = nvme_init_identify(ctrl); in nvme_init_ctrl_finish()
3204 ret = nvme_configure_apst(ctrl); in nvme_init_ctrl_finish()
3208 ret = nvme_configure_timestamp(ctrl); in nvme_init_ctrl_finish()
3212 ret = nvme_configure_host_options(ctrl); in nvme_init_ctrl_finish()
3216 nvme_configure_opal(ctrl, was_suspended); in nvme_init_ctrl_finish()
3218 if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3223 ret = nvme_hwmon_init(ctrl); in nvme_init_ctrl_finish()
3228 clear_bit(NVME_CTRL_DIRTY_CAPABILITY, &ctrl->flags); in nvme_init_ctrl_finish()
3229 ctrl->identified = true; in nvme_init_ctrl_finish()
3237 struct nvme_ctrl *ctrl = in nvme_dev_open() local
3240 switch (nvme_ctrl_state(ctrl)) { in nvme_dev_open()
3247 nvme_get_ctrl(ctrl); in nvme_dev_open()
3248 if (!try_module_get(ctrl->ops->module)) { in nvme_dev_open()
3249 nvme_put_ctrl(ctrl); in nvme_dev_open()
3253 file->private_data = ctrl; in nvme_dev_open()
3259 struct nvme_ctrl *ctrl = in nvme_dev_release() local
3262 module_put(ctrl->ops->module); in nvme_dev_release()
3263 nvme_put_ctrl(ctrl); in nvme_dev_release()
3276 static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, in nvme_find_ns_head() argument
3281 lockdep_assert_held(&ctrl->subsys->lock); in nvme_find_ns_head()
3283 list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { in nvme_find_ns_head()
3289 if (h->ns_id != nsid || !nvme_is_unique_nsid(ctrl, h)) in nvme_find_ns_head()
3379 ns->cdev_device.parent = ns->ctrl->device; in nvme_add_ns_cdev()
3381 ns->ctrl->instance, ns->head->instance); in nvme_add_ns_cdev()
3386 ns->ctrl->ops->module); in nvme_add_ns_cdev()
3389 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, in nvme_alloc_ns_head() argument
3403 ret = ida_alloc_min(&ctrl->subsys->ns_ida, 1, GFP_KERNEL); in nvme_alloc_ns_head()
3411 head->subsys = ctrl->subsys; in nvme_alloc_ns_head()
3418 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); in nvme_alloc_ns_head()
3422 head->effects = ctrl->effects; in nvme_alloc_ns_head()
3424 ret = nvme_mpath_alloc_disk(ctrl, head); in nvme_alloc_ns_head()
3428 list_add_tail(&head->entry, &ctrl->subsys->nsheads); in nvme_alloc_ns_head()
3430 kref_get(&ctrl->subsys->ref); in nvme_alloc_ns_head()
3436 ida_free(&ctrl->subsys->ns_ida, head->instance); in nvme_alloc_ns_head()
3473 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ns_head() local
3477 ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3495 nvme_print_device_info(ctrl); in nvme_init_ns_head()
3496 if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ in nvme_init_ns_head()
3497 ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && in nvme_init_ns_head()
3499 dev_err(ctrl->device, in nvme_init_ns_head()
3505 dev_err(ctrl->device, in nvme_init_ns_head()
3507 dev_err(ctrl->device, in nvme_init_ns_head()
3512 ctrl->quirks |= NVME_QUIRK_BOGUS_NID; in nvme_init_ns_head()
3515 mutex_lock(&ctrl->subsys->lock); in nvme_init_ns_head()
3516 head = nvme_find_ns_head(ctrl, info->nsid); in nvme_init_ns_head()
3518 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3520 dev_err(ctrl->device, in nvme_init_ns_head()
3525 head = nvme_alloc_ns_head(ctrl, info); in nvme_init_ns_head()
3533 dev_err(ctrl->device, in nvme_init_ns_head()
3539 dev_err(ctrl->device, in nvme_init_ns_head()
3546 dev_warn(ctrl->device, in nvme_init_ns_head()
3549 dev_warn_once(ctrl->device, in nvme_init_ns_head()
3556 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3562 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3566 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_find_get_ns() argument
3571 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_find_get_ns()
3572 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_find_get_ns()
3573 srcu_read_lock_held(&ctrl->srcu)) { in nvme_find_get_ns()
3583 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_find_get_ns()
3595 list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) { in nvme_ns_add_to_ctrl_list()
3601 list_add(&ns->list, &ns->ctrl->namespaces); in nvme_ns_add_to_ctrl_list()
3604 static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) in nvme_alloc_ns() argument
3608 int node = ctrl->numa_node; in nvme_alloc_ns()
3614 disk = blk_mq_alloc_disk(ctrl->tagset, ns); in nvme_alloc_ns()
3623 if (ctrl->opts && ctrl->opts->data_digest) in nvme_alloc_ns()
3627 if (ctrl->ops->supports_pci_p2pdma && in nvme_alloc_ns()
3628 ctrl->ops->supports_pci_p2pdma(ctrl)) in nvme_alloc_ns()
3631 ns->ctrl = ctrl; in nvme_alloc_ns()
3649 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3650 ctrl->instance, ns->head->instance); in nvme_alloc_ns()
3653 sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3656 sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, in nvme_alloc_ns()
3663 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3665 * Ensure that no namespaces are added to the ctrl list after the queues in nvme_alloc_ns()
3668 if (test_bit(NVME_CTRL_FROZEN, &ctrl->flags)) { in nvme_alloc_ns()
3669 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3673 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3674 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3675 nvme_get_ctrl(ctrl); in nvme_alloc_ns()
3677 if (device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups)) in nvme_alloc_ns()
3689 nvme_put_ctrl(ctrl); in nvme_alloc_ns()
3690 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3692 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3693 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3695 mutex_lock(&ctrl->subsys->lock); in nvme_alloc_ns()
3699 mutex_unlock(&ctrl->subsys->lock); in nvme_alloc_ns()
3728 mutex_lock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
3734 mutex_unlock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
3743 mutex_lock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
3745 mutex_unlock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
3746 synchronize_srcu(&ns->ctrl->srcu); in nvme_ns_remove()
3753 static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) in nvme_ns_remove_by_nsid() argument
3755 struct nvme_ns *ns = nvme_find_get_ns(ctrl, nsid); in nvme_ns_remove_by_nsid()
3768 dev_err(ns->ctrl->device, in nvme_validate_ns()
3785 static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_scan_ns() argument
3791 if (nvme_identify_ns_descs(ctrl, &info)) in nvme_scan_ns()
3794 if (info.ids.csi != NVME_CSI_NVM && !nvme_multi_css(ctrl)) { in nvme_scan_ns()
3795 dev_warn(ctrl->device, in nvme_scan_ns()
3805 if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || in nvme_scan_ns()
3807 ret = nvme_ns_info_from_id_cs_indep(ctrl, &info); in nvme_scan_ns()
3809 ret = nvme_ns_info_from_identify(ctrl, &info); in nvme_scan_ns()
3812 nvme_ns_remove_by_nsid(ctrl, nsid); in nvme_scan_ns()
3821 ns = nvme_find_get_ns(ctrl, nsid); in nvme_scan_ns()
3826 nvme_alloc_ns(ctrl, &info); in nvme_scan_ns()
3830 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, in nvme_remove_invalid_namespaces() argument
3836 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
3837 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { in nvme_remove_invalid_namespaces()
3840 synchronize_srcu(&ctrl->srcu); in nvme_remove_invalid_namespaces()
3844 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
3850 static int nvme_scan_ns_list(struct nvme_ctrl *ctrl) in nvme_scan_ns_list() argument
3868 ret = nvme_submit_sync_cmd(ctrl->admin_q, &cmd, ns_list, in nvme_scan_ns_list()
3871 dev_warn(ctrl->device, in nvme_scan_ns_list()
3881 nvme_scan_ns(ctrl, nsid); in nvme_scan_ns_list()
3883 nvme_ns_remove_by_nsid(ctrl, prev); in nvme_scan_ns_list()
3887 nvme_remove_invalid_namespaces(ctrl, prev); in nvme_scan_ns_list()
3893 static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl) in nvme_scan_ns_sequential() argument
3898 if (nvme_identify_ctrl(ctrl, &id)) in nvme_scan_ns_sequential()
3904 nvme_scan_ns(ctrl, i); in nvme_scan_ns_sequential()
3906 nvme_remove_invalid_namespaces(ctrl, nn); in nvme_scan_ns_sequential()
3909 static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl) in nvme_clear_changed_ns_log() argument
3925 error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_CHANGED_NS, 0, in nvme_clear_changed_ns_log()
3928 dev_warn(ctrl->device, in nvme_clear_changed_ns_log()
3936 struct nvme_ctrl *ctrl = in nvme_scan_work() local
3940 /* No tagset on a live ctrl means IO queues could not created */ in nvme_scan_work()
3941 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE || !ctrl->tagset) in nvme_scan_work()
3951 ret = nvme_init_non_mdts_limits(ctrl); in nvme_scan_work()
3953 dev_warn(ctrl->device, in nvme_scan_work()
3958 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { in nvme_scan_work()
3959 dev_info(ctrl->device, "rescanning namespaces.\n"); in nvme_scan_work()
3960 nvme_clear_changed_ns_log(ctrl); in nvme_scan_work()
3963 mutex_lock(&ctrl->scan_lock); in nvme_scan_work()
3964 if (nvme_ctrl_limited_cns(ctrl)) { in nvme_scan_work()
3965 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
3972 ret = nvme_scan_ns_list(ctrl); in nvme_scan_work()
3974 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
3976 mutex_unlock(&ctrl->scan_lock); in nvme_scan_work()
3984 void nvme_remove_namespaces(struct nvme_ctrl *ctrl) in nvme_remove_namespaces() argument
3994 nvme_mpath_clear_ctrl_paths(ctrl); in nvme_remove_namespaces()
4000 nvme_unquiesce_io_queues(ctrl); in nvme_remove_namespaces()
4003 flush_work(&ctrl->scan_work); in nvme_remove_namespaces()
4011 if (nvme_ctrl_state(ctrl) == NVME_CTRL_DEAD) in nvme_remove_namespaces()
4012 nvme_mark_namespaces_dead(ctrl); in nvme_remove_namespaces()
4015 nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); in nvme_remove_namespaces()
4017 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4018 list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu); in nvme_remove_namespaces()
4019 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4020 synchronize_srcu(&ctrl->srcu); in nvme_remove_namespaces()
4029 const struct nvme_ctrl *ctrl = in nvme_class_uevent() local
4031 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_class_uevent()
4034 ret = add_uevent_var(env, "NVME_TRTYPE=%s", ctrl->ops->name); in nvme_class_uevent()
4059 static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata) in nvme_change_uevent() argument
4063 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_change_uevent()
4066 static void nvme_aen_uevent(struct nvme_ctrl *ctrl) in nvme_aen_uevent() argument
4069 u32 aen_result = ctrl->aen_result; in nvme_aen_uevent()
4071 ctrl->aen_result = 0; in nvme_aen_uevent()
4078 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_aen_uevent()
4084 struct nvme_ctrl *ctrl = in nvme_async_event_work() local
4087 nvme_aen_uevent(ctrl); in nvme_async_event_work()
4091 * flushing ctrl async_event_work after changing the controller state in nvme_async_event_work()
4094 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_async_event_work()
4095 ctrl->ops->submit_async_event(ctrl); in nvme_async_event_work()
4098 static bool nvme_ctrl_pp_status(struct nvme_ctrl *ctrl) in nvme_ctrl_pp_status() argument
4103 if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) in nvme_ctrl_pp_status()
4109 return ((ctrl->ctrl_config & NVME_CC_ENABLE) && (csts & NVME_CSTS_PP)); in nvme_ctrl_pp_status()
4112 static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl) in nvme_get_fw_slot_info() argument
4120 if (nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_FW_SLOT, 0, NVME_CSI_NVM, in nvme_get_fw_slot_info()
4122 dev_warn(ctrl->device, "Get FW SLOT INFO log error\n"); in nvme_get_fw_slot_info()
4128 struct nvme_ctrl *ctrl = container_of(work, in nvme_fw_act_work() local
4132 nvme_auth_stop(ctrl); in nvme_fw_act_work()
4134 if (ctrl->mtfa) in nvme_fw_act_work()
4136 msecs_to_jiffies(ctrl->mtfa * 100); in nvme_fw_act_work()
4141 nvme_quiesce_io_queues(ctrl); in nvme_fw_act_work()
4142 while (nvme_ctrl_pp_status(ctrl)) { in nvme_fw_act_work()
4144 dev_warn(ctrl->device, in nvme_fw_act_work()
4146 nvme_try_sched_reset(ctrl); in nvme_fw_act_work()
4152 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) in nvme_fw_act_work()
4155 nvme_unquiesce_io_queues(ctrl); in nvme_fw_act_work()
4157 nvme_get_fw_slot_info(ctrl); in nvme_fw_act_work()
4159 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_fw_act_work()
4172 static bool nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result) in nvme_handle_aen_notice() argument
4179 set_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events); in nvme_handle_aen_notice()
4180 nvme_queue_scan(ctrl); in nvme_handle_aen_notice()
4188 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) { in nvme_handle_aen_notice()
4190 queue_work(nvme_wq, &ctrl->fw_act_work); in nvme_handle_aen_notice()
4195 if (!ctrl->ana_log_buf) in nvme_handle_aen_notice()
4197 queue_work(nvme_wq, &ctrl->ana_work); in nvme_handle_aen_notice()
4201 ctrl->aen_result = result; in nvme_handle_aen_notice()
4204 dev_warn(ctrl->device, "async event result %08x\n", result); in nvme_handle_aen_notice()
4209 static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl) in nvme_handle_aer_persistent_error() argument
4211 dev_warn(ctrl->device, "resetting controller due to AER\n"); in nvme_handle_aer_persistent_error()
4212 nvme_reset_ctrl(ctrl); in nvme_handle_aer_persistent_error()
4215 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, in nvme_complete_async_event() argument
4226 trace_nvme_async_event(ctrl, result); in nvme_complete_async_event()
4229 requeue = nvme_handle_aen_notice(ctrl, result); in nvme_complete_async_event()
4237 nvme_handle_aer_persistent_error(ctrl); in nvme_complete_async_event()
4244 ctrl->aen_result = result; in nvme_complete_async_event()
4251 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_complete_async_event()
4255 int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_admin_tag_set() argument
4263 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_admin_tag_set()
4266 set->numa_node = ctrl->numa_node; in nvme_alloc_admin_tag_set()
4268 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_admin_tag_set()
4271 set->driver_data = ctrl; in nvme_alloc_admin_tag_set()
4278 ctrl->admin_q = blk_mq_init_queue(set); in nvme_alloc_admin_tag_set()
4279 if (IS_ERR(ctrl->admin_q)) { in nvme_alloc_admin_tag_set()
4280 ret = PTR_ERR(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4284 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_admin_tag_set()
4285 ctrl->fabrics_q = blk_mq_init_queue(set); in nvme_alloc_admin_tag_set()
4286 if (IS_ERR(ctrl->fabrics_q)) { in nvme_alloc_admin_tag_set()
4287 ret = PTR_ERR(ctrl->fabrics_q); in nvme_alloc_admin_tag_set()
4292 ctrl->admin_tagset = set; in nvme_alloc_admin_tag_set()
4296 blk_mq_destroy_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4297 blk_put_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4300 ctrl->admin_q = NULL; in nvme_alloc_admin_tag_set()
4301 ctrl->fabrics_q = NULL; in nvme_alloc_admin_tag_set()
4306 void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_admin_tag_set() argument
4308 blk_mq_destroy_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4309 blk_put_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4310 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_admin_tag_set()
4311 blk_mq_destroy_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4312 blk_put_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4314 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_remove_admin_tag_set()
4318 int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_io_tag_set() argument
4326 set->queue_depth = min_t(unsigned, ctrl->sqsize, BLK_MQ_MAX_DEPTH - 1); in nvme_alloc_io_tag_set()
4331 if (ctrl->quirks & NVME_QUIRK_SHARED_TAGS) in nvme_alloc_io_tag_set()
4333 else if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_io_tag_set()
4336 set->numa_node = ctrl->numa_node; in nvme_alloc_io_tag_set()
4338 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_io_tag_set()
4341 set->driver_data = ctrl; in nvme_alloc_io_tag_set()
4342 set->nr_hw_queues = ctrl->queue_count - 1; in nvme_alloc_io_tag_set()
4349 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_io_tag_set()
4350 ctrl->connect_q = blk_mq_init_queue(set); in nvme_alloc_io_tag_set()
4351 if (IS_ERR(ctrl->connect_q)) { in nvme_alloc_io_tag_set()
4352 ret = PTR_ERR(ctrl->connect_q); in nvme_alloc_io_tag_set()
4356 ctrl->connect_q); in nvme_alloc_io_tag_set()
4359 ctrl->tagset = set; in nvme_alloc_io_tag_set()
4364 ctrl->connect_q = NULL; in nvme_alloc_io_tag_set()
4369 void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_io_tag_set() argument
4371 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_io_tag_set()
4372 blk_mq_destroy_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4373 blk_put_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4375 blk_mq_free_tag_set(ctrl->tagset); in nvme_remove_io_tag_set()
4379 void nvme_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_stop_ctrl() argument
4381 nvme_mpath_stop(ctrl); in nvme_stop_ctrl()
4382 nvme_auth_stop(ctrl); in nvme_stop_ctrl()
4383 nvme_stop_keep_alive(ctrl); in nvme_stop_ctrl()
4384 nvme_stop_failfast_work(ctrl); in nvme_stop_ctrl()
4385 flush_work(&ctrl->async_event_work); in nvme_stop_ctrl()
4386 cancel_work_sync(&ctrl->fw_act_work); in nvme_stop_ctrl()
4387 if (ctrl->ops->stop_ctrl) in nvme_stop_ctrl()
4388 ctrl->ops->stop_ctrl(ctrl); in nvme_stop_ctrl()
4392 void nvme_start_ctrl(struct nvme_ctrl *ctrl) in nvme_start_ctrl() argument
4394 nvme_start_keep_alive(ctrl); in nvme_start_ctrl()
4396 nvme_enable_aen(ctrl); in nvme_start_ctrl()
4404 if (test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags) && in nvme_start_ctrl()
4405 nvme_discovery_ctrl(ctrl)) in nvme_start_ctrl()
4406 nvme_change_uevent(ctrl, "NVME_EVENT=rediscover"); in nvme_start_ctrl()
4408 if (ctrl->queue_count > 1) { in nvme_start_ctrl()
4409 nvme_queue_scan(ctrl); in nvme_start_ctrl()
4410 nvme_unquiesce_io_queues(ctrl); in nvme_start_ctrl()
4411 nvme_mpath_update(ctrl); in nvme_start_ctrl()
4414 nvme_change_uevent(ctrl, "NVME_EVENT=connected"); in nvme_start_ctrl()
4415 set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags); in nvme_start_ctrl()
4419 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) in nvme_uninit_ctrl() argument
4421 nvme_hwmon_exit(ctrl); in nvme_uninit_ctrl()
4422 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_uninit_ctrl()
4423 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_uninit_ctrl()
4424 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_uninit_ctrl()
4425 nvme_put_ctrl(ctrl); in nvme_uninit_ctrl()
4429 static void nvme_free_cels(struct nvme_ctrl *ctrl) in nvme_free_cels() argument
4434 xa_for_each(&ctrl->cels, i, cel) { in nvme_free_cels()
4435 xa_erase(&ctrl->cels, i); in nvme_free_cels()
4439 xa_destroy(&ctrl->cels); in nvme_free_cels()
4444 struct nvme_ctrl *ctrl = in nvme_free_ctrl() local
4446 struct nvme_subsystem *subsys = ctrl->subsys; in nvme_free_ctrl()
4448 if (!subsys || ctrl->instance != subsys->instance) in nvme_free_ctrl()
4449 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_free_ctrl()
4451 nvme_free_cels(ctrl); in nvme_free_ctrl()
4452 nvme_mpath_uninit(ctrl); in nvme_free_ctrl()
4453 cleanup_srcu_struct(&ctrl->srcu); in nvme_free_ctrl()
4454 nvme_auth_stop(ctrl); in nvme_free_ctrl()
4455 nvme_auth_free(ctrl); in nvme_free_ctrl()
4456 __free_page(ctrl->discard_page); in nvme_free_ctrl()
4457 free_opal_dev(ctrl->opal_dev); in nvme_free_ctrl()
4461 list_del(&ctrl->subsys_entry); in nvme_free_ctrl()
4462 sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device)); in nvme_free_ctrl()
4466 ctrl->ops->free_ctrl(ctrl); in nvme_free_ctrl()
4477 int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, in nvme_init_ctrl() argument
4482 WRITE_ONCE(ctrl->state, NVME_CTRL_NEW); in nvme_init_ctrl()
4483 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_init_ctrl()
4484 spin_lock_init(&ctrl->lock); in nvme_init_ctrl()
4485 mutex_init(&ctrl->namespaces_lock); in nvme_init_ctrl()
4487 ret = init_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4491 mutex_init(&ctrl->scan_lock); in nvme_init_ctrl()
4492 INIT_LIST_HEAD(&ctrl->namespaces); in nvme_init_ctrl()
4493 xa_init(&ctrl->cels); in nvme_init_ctrl()
4494 ctrl->dev = dev; in nvme_init_ctrl()
4495 ctrl->ops = ops; in nvme_init_ctrl()
4496 ctrl->quirks = quirks; in nvme_init_ctrl()
4497 ctrl->numa_node = NUMA_NO_NODE; in nvme_init_ctrl()
4498 INIT_WORK(&ctrl->scan_work, nvme_scan_work); in nvme_init_ctrl()
4499 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); in nvme_init_ctrl()
4500 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); in nvme_init_ctrl()
4501 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); in nvme_init_ctrl()
4502 init_waitqueue_head(&ctrl->state_wq); in nvme_init_ctrl()
4504 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); in nvme_init_ctrl()
4505 INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); in nvme_init_ctrl()
4506 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); in nvme_init_ctrl()
4507 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; in nvme_init_ctrl()
4511 ctrl->discard_page = alloc_page(GFP_KERNEL); in nvme_init_ctrl()
4512 if (!ctrl->discard_page) { in nvme_init_ctrl()
4520 ctrl->instance = ret; in nvme_init_ctrl()
4522 device_initialize(&ctrl->ctrl_device); in nvme_init_ctrl()
4523 ctrl->device = &ctrl->ctrl_device; in nvme_init_ctrl()
4524 ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt), in nvme_init_ctrl()
4525 ctrl->instance); in nvme_init_ctrl()
4526 ctrl->device->class = nvme_class; in nvme_init_ctrl()
4527 ctrl->device->parent = ctrl->dev; in nvme_init_ctrl()
4529 ctrl->device->groups = ops->dev_attr_groups; in nvme_init_ctrl()
4531 ctrl->device->groups = nvme_dev_attr_groups; in nvme_init_ctrl()
4532 ctrl->device->release = nvme_free_ctrl; in nvme_init_ctrl()
4533 dev_set_drvdata(ctrl->device, ctrl); in nvme_init_ctrl()
4534 ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance); in nvme_init_ctrl()
4538 nvme_get_ctrl(ctrl); in nvme_init_ctrl()
4539 cdev_init(&ctrl->cdev, &nvme_dev_fops); in nvme_init_ctrl()
4540 ctrl->cdev.owner = ops->module; in nvme_init_ctrl()
4541 ret = cdev_device_add(&ctrl->cdev, ctrl->device); in nvme_init_ctrl()
4549 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; in nvme_init_ctrl()
4550 dev_pm_qos_update_user_latency_tolerance(ctrl->device, in nvme_init_ctrl()
4553 nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); in nvme_init_ctrl()
4554 nvme_mpath_init_ctrl(ctrl); in nvme_init_ctrl()
4555 ret = nvme_auth_init_ctrl(ctrl); in nvme_init_ctrl()
4561 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_init_ctrl()
4562 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_ctrl()
4563 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_init_ctrl()
4565 nvme_put_ctrl(ctrl); in nvme_init_ctrl()
4566 kfree_const(ctrl->device->kobj.name); in nvme_init_ctrl()
4568 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_init_ctrl()
4570 if (ctrl->discard_page) in nvme_init_ctrl()
4571 __free_page(ctrl->discard_page); in nvme_init_ctrl()
4572 cleanup_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4578 void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl) in nvme_mark_namespaces_dead() argument
4583 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_mark_namespaces_dead()
4584 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_mark_namespaces_dead()
4585 srcu_read_lock_held(&ctrl->srcu)) in nvme_mark_namespaces_dead()
4587 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_mark_namespaces_dead()
4591 void nvme_unfreeze(struct nvme_ctrl *ctrl) in nvme_unfreeze() argument
4596 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_unfreeze()
4597 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_unfreeze()
4598 srcu_read_lock_held(&ctrl->srcu)) in nvme_unfreeze()
4600 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_unfreeze()
4601 clear_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_unfreeze()
4605 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout) in nvme_wait_freeze_timeout() argument
4610 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze_timeout()
4611 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze_timeout()
4612 srcu_read_lock_held(&ctrl->srcu)) { in nvme_wait_freeze_timeout()
4617 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze_timeout()
4622 void nvme_wait_freeze(struct nvme_ctrl *ctrl) in nvme_wait_freeze() argument
4627 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze()
4628 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze()
4629 srcu_read_lock_held(&ctrl->srcu)) in nvme_wait_freeze()
4631 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze()
4635 void nvme_start_freeze(struct nvme_ctrl *ctrl) in nvme_start_freeze() argument
4640 set_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_start_freeze()
4641 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_start_freeze()
4642 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_start_freeze()
4643 srcu_read_lock_held(&ctrl->srcu)) in nvme_start_freeze()
4645 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_start_freeze()
4649 void nvme_quiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_quiesce_io_queues() argument
4651 if (!ctrl->tagset) in nvme_quiesce_io_queues()
4653 if (!test_and_set_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_quiesce_io_queues()
4654 blk_mq_quiesce_tagset(ctrl->tagset); in nvme_quiesce_io_queues()
4656 blk_mq_wait_quiesce_done(ctrl->tagset); in nvme_quiesce_io_queues()
4660 void nvme_unquiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_unquiesce_io_queues() argument
4662 if (!ctrl->tagset) in nvme_unquiesce_io_queues()
4664 if (test_and_clear_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_unquiesce_io_queues()
4665 blk_mq_unquiesce_tagset(ctrl->tagset); in nvme_unquiesce_io_queues()
4669 void nvme_quiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_quiesce_admin_queue() argument
4671 if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_quiesce_admin_queue()
4672 blk_mq_quiesce_queue(ctrl->admin_q); in nvme_quiesce_admin_queue()
4674 blk_mq_wait_quiesce_done(ctrl->admin_q->tag_set); in nvme_quiesce_admin_queue()
4678 void nvme_unquiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_unquiesce_admin_queue() argument
4680 if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_unquiesce_admin_queue()
4681 blk_mq_unquiesce_queue(ctrl->admin_q); in nvme_unquiesce_admin_queue()
4685 void nvme_sync_io_queues(struct nvme_ctrl *ctrl) in nvme_sync_io_queues() argument
4690 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_sync_io_queues()
4691 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_sync_io_queues()
4692 srcu_read_lock_held(&ctrl->srcu)) in nvme_sync_io_queues()
4694 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_sync_io_queues()
4698 void nvme_sync_queues(struct nvme_ctrl *ctrl) in nvme_sync_queues() argument
4700 nvme_sync_io_queues(ctrl); in nvme_sync_queues()
4701 if (ctrl->admin_q) in nvme_sync_queues()
4702 blk_sync_queue(ctrl->admin_q); in nvme_sync_queues()