Lines Matching refs:ctrl

151 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
153 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
155 static int nvme_get_log_lsi(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page,
158 void nvme_queue_scan(struct nvme_ctrl *ctrl) in nvme_queue_scan() argument
163 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE && ctrl->tagset) in nvme_queue_scan()
164 queue_work(nvme_wq, &ctrl->scan_work); in nvme_queue_scan()
173 int nvme_try_sched_reset(struct nvme_ctrl *ctrl) in nvme_try_sched_reset() argument
175 if (nvme_ctrl_state(ctrl) != NVME_CTRL_RESETTING) in nvme_try_sched_reset()
177 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_try_sched_reset()
185 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_failfast_work() local
188 if (nvme_ctrl_state(ctrl) != NVME_CTRL_CONNECTING) in nvme_failfast_work()
191 set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_failfast_work()
192 dev_info(ctrl->device, "failfast expired\n"); in nvme_failfast_work()
193 nvme_kick_requeue_lists(ctrl); in nvme_failfast_work()
196 static inline void nvme_start_failfast_work(struct nvme_ctrl *ctrl) in nvme_start_failfast_work() argument
198 if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) in nvme_start_failfast_work()
201 schedule_delayed_work(&ctrl->failfast_work, in nvme_start_failfast_work()
202 ctrl->opts->fast_io_fail_tmo * HZ); in nvme_start_failfast_work()
205 static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) in nvme_stop_failfast_work() argument
207 if (!ctrl->opts) in nvme_stop_failfast_work()
210 cancel_delayed_work_sync(&ctrl->failfast_work); in nvme_stop_failfast_work()
211 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_stop_failfast_work()
215 int nvme_reset_ctrl(struct nvme_ctrl *ctrl) in nvme_reset_ctrl() argument
217 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) in nvme_reset_ctrl()
219 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_reset_ctrl()
225 int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_reset_ctrl_sync() argument
229 ret = nvme_reset_ctrl(ctrl); in nvme_reset_ctrl_sync()
231 flush_work(&ctrl->reset_work); in nvme_reset_ctrl_sync()
232 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE) in nvme_reset_ctrl_sync()
239 static void nvme_do_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_do_delete_ctrl() argument
241 dev_info(ctrl->device, in nvme_do_delete_ctrl()
242 "Removing ctrl: NQN \"%s\"\n", nvmf_ctrl_subsysnqn(ctrl)); in nvme_do_delete_ctrl()
244 flush_work(&ctrl->reset_work); in nvme_do_delete_ctrl()
245 nvme_stop_ctrl(ctrl); in nvme_do_delete_ctrl()
246 nvme_remove_namespaces(ctrl); in nvme_do_delete_ctrl()
247 ctrl->ops->delete_ctrl(ctrl); in nvme_do_delete_ctrl()
248 nvme_uninit_ctrl(ctrl); in nvme_do_delete_ctrl()
253 struct nvme_ctrl *ctrl = in nvme_delete_ctrl_work() local
256 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_work()
259 int nvme_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_delete_ctrl() argument
261 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl()
263 if (!queue_work(nvme_delete_wq, &ctrl->delete_work)) in nvme_delete_ctrl()
269 void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_delete_ctrl_sync() argument
275 nvme_get_ctrl(ctrl); in nvme_delete_ctrl_sync()
276 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl_sync()
277 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_sync()
278 nvme_put_ctrl(ctrl); in nvme_delete_ctrl_sync()
330 delay = nvme_req(req)->ctrl->crdt[crd - 1] * 100; in nvme_retry_req()
358 dev_name(nr->ctrl->device), in nvme_log_error()
375 ns ? ns->disk->disk_name : dev_name(nr->ctrl->device), in nvme_log_err_passthru()
459 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_complete_rq() local
472 if (ctrl->kas && in nvme_complete_rq()
473 req->deadline - req->timeout >= ctrl->ka_last_check_time) in nvme_complete_rq()
474 ctrl->comp_seen = true; in nvme_complete_rq()
488 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_complete_rq()
537 void nvme_cancel_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_tagset() argument
539 if (ctrl->tagset) { in nvme_cancel_tagset()
540 blk_mq_tagset_busy_iter(ctrl->tagset, in nvme_cancel_tagset()
541 nvme_cancel_request, ctrl); in nvme_cancel_tagset()
542 blk_mq_tagset_wait_completed_request(ctrl->tagset); in nvme_cancel_tagset()
547 void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_admin_tagset() argument
549 if (ctrl->admin_tagset) { in nvme_cancel_admin_tagset()
550 blk_mq_tagset_busy_iter(ctrl->admin_tagset, in nvme_cancel_admin_tagset()
551 nvme_cancel_request, ctrl); in nvme_cancel_admin_tagset()
552 blk_mq_tagset_wait_completed_request(ctrl->admin_tagset); in nvme_cancel_admin_tagset()
557 bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, in nvme_change_ctrl_state() argument
564 spin_lock_irqsave(&ctrl->lock, flags); in nvme_change_ctrl_state()
566 old_state = nvme_ctrl_state(ctrl); in nvme_change_ctrl_state()
632 WRITE_ONCE(ctrl->state, new_state); in nvme_change_ctrl_state()
633 wake_up_all(&ctrl->state_wq); in nvme_change_ctrl_state()
636 spin_unlock_irqrestore(&ctrl->lock, flags); in nvme_change_ctrl_state()
642 nvme_stop_failfast_work(ctrl); in nvme_change_ctrl_state()
643 nvme_kick_requeue_lists(ctrl); in nvme_change_ctrl_state()
646 nvme_start_failfast_work(ctrl); in nvme_change_ctrl_state()
656 bool nvme_wait_reset(struct nvme_ctrl *ctrl) in nvme_wait_reset() argument
658 wait_event(ctrl->state_wq, in nvme_wait_reset()
659 nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING) || in nvme_wait_reset()
660 nvme_state_terminal(ctrl)); in nvme_wait_reset()
661 return nvme_ctrl_state(ctrl) == NVME_CTRL_RESETTING; in nvme_wait_reset()
694 nvme_put_ctrl(ns->ctrl); in nvme_free_ns()
729 logging_enabled = nr->ctrl->passthru_err_log_enabled; in nvme_init_request()
756 blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl, in nvme_fail_nonready_command() argument
759 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_fail_nonready_command()
764 !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) && in nvme_fail_nonready_command()
775 bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq, in __nvme_check_ready() argument
788 if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD)) in __nvme_check_ready()
791 if (ctrl->ops->flags & NVME_F_FABRICS) { in __nvme_check_ready()
845 if (test_and_set_bit_lock(0, &ns->ctrl->discard_page_busy)) in nvme_setup_discard()
848 range = page_address(ns->ctrl->discard_page); in nvme_setup_discard()
875 if (virt_to_page(range) == ns->ctrl->discard_page) in nvme_setup_discard()
876 clear_bit_unlock(0, &ns->ctrl->discard_page_busy); in nvme_setup_discard()
938 if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_setup_write_zeroes()
1070 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_cleanup_cmd() local
1072 if (req->special_vec.bv_page == ctrl->discard_page) in nvme_cleanup_cmd()
1073 clear_bit_unlock(0, &ctrl->discard_page_busy); in nvme_cleanup_cmd()
1206 u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_command_effects() argument
1213 dev_warn_once(ctrl->device, in nvme_command_effects()
1224 effects = le32_to_cpu(ctrl->effects->acs[opcode]); in nvme_command_effects()
1235 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_passthru_start() argument
1237 u32 effects = nvme_command_effects(ctrl, ns, opcode); in nvme_passthru_start()
1244 mutex_lock(&ctrl->scan_lock); in nvme_passthru_start()
1245 mutex_lock(&ctrl->subsys->lock); in nvme_passthru_start()
1246 nvme_mpath_start_freeze(ctrl->subsys); in nvme_passthru_start()
1247 nvme_mpath_wait_freeze(ctrl->subsys); in nvme_passthru_start()
1248 nvme_start_freeze(ctrl); in nvme_passthru_start()
1249 nvme_wait_freeze(ctrl); in nvme_passthru_start()
1255 void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, in nvme_passthru_end() argument
1259 nvme_unfreeze(ctrl); in nvme_passthru_end()
1260 nvme_mpath_unfreeze(ctrl->subsys); in nvme_passthru_end()
1261 mutex_unlock(&ctrl->subsys->lock); in nvme_passthru_end()
1262 mutex_unlock(&ctrl->scan_lock); in nvme_passthru_end()
1266 &ctrl->flags)) { in nvme_passthru_end()
1267 dev_info(ctrl->device, in nvme_passthru_end()
1272 nvme_queue_scan(ctrl); in nvme_passthru_end()
1273 flush_work(&ctrl->scan_work); in nvme_passthru_end()
1288 nvme_update_keep_alive(ctrl, cmd); in nvme_passthru_end()
1306 static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl) in nvme_keep_alive_work_period() argument
1308 unsigned long delay = ctrl->kato * HZ / 2; in nvme_keep_alive_work_period()
1316 if (ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) in nvme_keep_alive_work_period()
1321 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) in nvme_queue_keep_alive_work() argument
1324 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_queue_keep_alive_work()
1325 unsigned long ka_next_check_tm = ctrl->ka_last_check_time + delay; in nvme_queue_keep_alive_work()
1332 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_queue_keep_alive_work()
1339 struct nvme_ctrl *ctrl = rq->end_io_data; in nvme_keep_alive_end_io() local
1341 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_keep_alive_end_io()
1342 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_keep_alive_end_io()
1351 dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n", in nvme_keep_alive_end_io()
1359 dev_err(ctrl->device, in nvme_keep_alive_end_io()
1365 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_end_io()
1366 ctrl->comp_seen = false; in nvme_keep_alive_end_io()
1368 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_keep_alive_end_io()
1374 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_keep_alive_work() local
1376 bool comp_seen = ctrl->comp_seen; in nvme_keep_alive_work()
1379 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_work()
1381 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { in nvme_keep_alive_work()
1382 dev_dbg(ctrl->device, in nvme_keep_alive_work()
1384 ctrl->comp_seen = false; in nvme_keep_alive_work()
1385 nvme_queue_keep_alive_work(ctrl); in nvme_keep_alive_work()
1389 rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd), in nvme_keep_alive_work()
1393 dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq)); in nvme_keep_alive_work()
1394 nvme_reset_ctrl(ctrl); in nvme_keep_alive_work()
1397 nvme_init_request(rq, &ctrl->ka_cmd); in nvme_keep_alive_work()
1399 rq->timeout = ctrl->kato * HZ; in nvme_keep_alive_work()
1401 rq->end_io_data = ctrl; in nvme_keep_alive_work()
1405 static void nvme_start_keep_alive(struct nvme_ctrl *ctrl) in nvme_start_keep_alive() argument
1407 if (unlikely(ctrl->kato == 0)) in nvme_start_keep_alive()
1410 nvme_queue_keep_alive_work(ctrl); in nvme_start_keep_alive()
1413 void nvme_stop_keep_alive(struct nvme_ctrl *ctrl) in nvme_stop_keep_alive() argument
1415 if (unlikely(ctrl->kato == 0)) in nvme_stop_keep_alive()
1418 cancel_delayed_work_sync(&ctrl->ka_work); in nvme_stop_keep_alive()
1422 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, in nvme_update_keep_alive() argument
1428 dev_info(ctrl->device, in nvme_update_keep_alive()
1430 ctrl->kato * 1000 / 2, new_kato * 1000 / 2); in nvme_update_keep_alive()
1432 nvme_stop_keep_alive(ctrl); in nvme_update_keep_alive()
1433 ctrl->kato = new_kato; in nvme_update_keep_alive()
1434 nvme_start_keep_alive(ctrl); in nvme_update_keep_alive()
1437 static bool nvme_id_cns_ok(struct nvme_ctrl *ctrl, u8 cns) in nvme_id_cns_ok() argument
1442 if (ctrl->vs >= NVME_VS(1, 2, 0)) in nvme_id_cns_ok()
1453 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_id_cns_ok()
1454 !(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) in nvme_id_cns_ok()
1485 static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, in nvme_process_ns_desc() argument
1494 dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n", in nvme_process_ns_desc()
1498 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1504 dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n", in nvme_process_ns_desc()
1508 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1514 dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n", in nvme_process_ns_desc()
1518 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1524 dev_warn(ctrl->device, "%s %d for NVME_NIDT_CSI\n", in nvme_process_ns_desc()
1537 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, in nvme_identify_ns_descs() argument
1545 if (ctrl->vs < NVME_VS(1, 3, 0) && !nvme_multi_css(ctrl)) in nvme_identify_ns_descs()
1547 if (ctrl->quirks & NVME_QUIRK_NO_NS_DESC_LIST) in nvme_identify_ns_descs()
1558 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data, in nvme_identify_ns_descs()
1561 dev_warn(ctrl->device, in nvme_identify_ns_descs()
1573 len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); in nvme_identify_ns_descs()
1580 if (nvme_multi_css(ctrl) && !csi_seen) { in nvme_identify_ns_descs()
1581 dev_warn(ctrl->device, "Command set not reported for nsid:%d\n", in nvme_identify_ns_descs()
1591 int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, in nvme_identify_ns() argument
1606 error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id)); in nvme_identify_ns()
1608 dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error); in nvme_identify_ns()
1615 static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, in nvme_ns_info_from_identify() argument
1622 ret = nvme_identify_ns(ctrl, info->nsid, &id); in nvme_ns_info_from_identify()
1638 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) { in nvme_ns_info_from_identify()
1639 dev_info(ctrl->device, in nvme_ns_info_from_identify()
1642 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_ns_info_from_identify()
1645 if (ctrl->vs >= NVME_VS(1, 2, 0) && in nvme_ns_info_from_identify()
1655 static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, in nvme_ns_info_from_id_cs_indep() argument
1670 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_ns_info_from_id_cs_indep()
1720 int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) in nvme_set_queue_count() argument
1726 status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0, in nvme_set_queue_count()
1743 dev_err(ctrl->device, "Could not set queue count (%d)\n", status); in nvme_set_queue_count()
1758 static void nvme_enable_aen(struct nvme_ctrl *ctrl) in nvme_enable_aen() argument
1760 u32 result, supported_aens = ctrl->oaes & NVME_AEN_SUPPORTED; in nvme_enable_aen()
1766 status = nvme_set_features(ctrl, NVME_FEAT_ASYNC_EVENT, supported_aens, in nvme_enable_aen()
1769 dev_warn(ctrl->device, "Failed to configure AEN (cfg %x)\n", in nvme_enable_aen()
1772 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_enable_aen()
1783 if (!try_module_get(ns->ctrl->ops->module)) in nvme_ns_open()
1797 module_put(ns->ctrl->ops->module); in nvme_ns_release()
1888 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_config_discard() local
1890 if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns->head, UINT_MAX)) in nvme_config_discard()
1892 nvme_lba_to_sect(ns->head, ctrl->dmrsl); in nvme_config_discard()
1893 else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) in nvme_config_discard()
1900 if (ctrl->dmrl) in nvme_config_discard()
1901 lim->max_discard_segments = ctrl->dmrl; in nvme_config_discard()
1914 static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid, in nvme_identify_ns_nvm() argument
1930 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm)); in nvme_identify_ns_nvm()
1966 static void nvme_configure_metadata(struct nvme_ctrl *ctrl, in nvme_configure_metadata() argument
1974 if (!head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) in nvme_configure_metadata()
1977 if (nvm && (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { in nvme_configure_metadata()
1993 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_configure_metadata()
2013 if (ctrl->max_integrity_segments && nvme_ns_has_pi(head)) in nvme_configure_metadata()
2049 if (ns->ctrl->awupf) in nvme_configure_atomic_write()
2050 dev_info_once(ns->ctrl->device, in nvme_configure_atomic_write()
2063 static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl) in nvme_max_drv_segments() argument
2065 return ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> SECTOR_SHIFT) + 1; in nvme_max_drv_segments()
2068 static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl, in nvme_set_ctrl_limits() argument
2071 lim->max_hw_sectors = ctrl->max_hw_sectors; in nvme_set_ctrl_limits()
2073 min_not_zero(nvme_max_drv_segments(ctrl), ctrl->max_segments)); in nvme_set_ctrl_limits()
2074 lim->max_integrity_segments = ctrl->max_integrity_segments; in nvme_set_ctrl_limits()
2075 lim->virt_boundary_mask = ctrl->ops->get_virt_boundary(ctrl, is_admin); in nvme_set_ctrl_limits()
2118 if ((ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) && in nvme_update_disk_info()
2119 (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM)) in nvme_update_disk_info()
2122 lim->max_write_zeroes_sectors = ns->ctrl->max_zeroes_sectors; in nvme_update_disk_info()
2140 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_set_chunk_sectors() local
2143 if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) && in nvme_set_chunk_sectors()
2144 is_power_of_2(ctrl->max_hw_sectors)) in nvme_set_chunk_sectors()
2145 iob = ctrl->max_hw_sectors; in nvme_set_chunk_sectors()
2177 nvme_set_ctrl_limits(ns->ctrl, &lim, false); in nvme_update_ns_info_generic()
2190 static int nvme_query_fdp_granularity(struct nvme_ctrl *ctrl, in nvme_query_fdp_granularity() argument
2199 ret = nvme_get_log_lsi(ctrl, 0, NVME_LOG_FDP_CONFIGS, 0, in nvme_query_fdp_granularity()
2202 dev_warn(ctrl->device, in nvme_query_fdp_granularity()
2210 dev_warn(ctrl->device, "FDP config size too large:%zu\n", in nvme_query_fdp_granularity()
2219 ret = nvme_get_log_lsi(ctrl, 0, NVME_LOG_FDP_CONFIGS, 0, in nvme_query_fdp_granularity()
2222 dev_warn(ctrl->device, in nvme_query_fdp_granularity()
2230 dev_warn(ctrl->device, "FDP index:%d out of range:%d\n", in nvme_query_fdp_granularity()
2244 dev_warn(ctrl->device, in nvme_query_fdp_granularity()
2252 dev_warn(ctrl->device, "FDP NRG > 1 not supported\n"); in nvme_query_fdp_granularity()
2266 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_query_fdp_info() local
2281 ret = nvme_get_features(ctrl, NVME_FEAT_FDP, info->endgid, NULL, 0, in nvme_query_fdp_info()
2284 dev_warn(ctrl->device, "FDP get feature status:0x%x\n", ret); in nvme_query_fdp_info()
2291 ret = nvme_query_fdp_granularity(ctrl, info, fdp.fdpcidx); in nvme_query_fdp_info()
2306 dev_warn(ctrl->device, "FDP io-mgmt status:0x%x\n", ret); in nvme_query_fdp_info()
2317 dev_warn(ctrl->device, in nvme_query_fdp_info()
2344 ret = nvme_identify_ns(ns->ctrl, info->nsid, &id); in nvme_update_ns_info_block()
2356 if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) { in nvme_update_ns_info_block()
2357 ret = nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); in nvme_update_ns_info_block()
2369 if (ns->ctrl->ctratt & NVME_CTRL_ATTR_FDPS) { in nvme_update_ns_info_block()
2381 nvme_set_ctrl_limits(ns->ctrl, &lim, false); in nvme_update_ns_info_block()
2382 nvme_configure_metadata(ns->ctrl, ns->head, id, nvm, info); in nvme_update_ns_info_block()
2392 if ((ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) && !info->no_vwc) in nvme_update_ns_info_block()
2458 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2470 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2564 struct nvme_ctrl *ctrl = data; in nvme_sec_submit() local
2575 return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len, in nvme_sec_submit()
2579 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2581 if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) { in nvme_configure_opal()
2582 if (!ctrl->opal_dev) in nvme_configure_opal()
2583 ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit); in nvme_configure_opal()
2585 opal_unlock_from_suspend(ctrl->opal_dev); in nvme_configure_opal()
2587 free_opal_dev(ctrl->opal_dev); in nvme_configure_opal()
2588 ctrl->opal_dev = NULL; in nvme_configure_opal()
2592 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2619 static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val, in nvme_wait_ready() argument
2626 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_wait_ready()
2636 dev_err(ctrl->device, in nvme_wait_ready()
2646 int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown) in nvme_disable_ctrl() argument
2650 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_disable_ctrl()
2652 ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; in nvme_disable_ctrl()
2654 ctrl->ctrl_config &= ~NVME_CC_ENABLE; in nvme_disable_ctrl()
2656 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_disable_ctrl()
2661 return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK, in nvme_disable_ctrl()
2663 ctrl->shutdown_timeout, "shutdown"); in nvme_disable_ctrl()
2665 if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY) in nvme_disable_ctrl()
2667 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, 0, in nvme_disable_ctrl()
2668 (NVME_CAP_TIMEOUT(ctrl->cap) + 1) / 2, "reset"); in nvme_disable_ctrl()
2672 int nvme_enable_ctrl(struct nvme_ctrl *ctrl) in nvme_enable_ctrl() argument
2678 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2680 dev_err(ctrl->device, "Reading CAP failed (%d)\n", ret); in nvme_enable_ctrl()
2683 dev_page_min = NVME_CAP_MPSMIN(ctrl->cap) + 12; in nvme_enable_ctrl()
2686 dev_err(ctrl->device, in nvme_enable_ctrl()
2692 if (NVME_CAP_CSS(ctrl->cap) & NVME_CAP_CSS_CSI) in nvme_enable_ctrl()
2693 ctrl->ctrl_config = NVME_CC_CSS_CSI; in nvme_enable_ctrl()
2695 ctrl->ctrl_config = NVME_CC_CSS_NVM; in nvme_enable_ctrl()
2703 ctrl->ctrl_config &= ~NVME_CC_CRIME; in nvme_enable_ctrl()
2705 ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT; in nvme_enable_ctrl()
2706 ctrl->ctrl_config |= NVME_CC_AMS_RR | NVME_CC_SHN_NONE; in nvme_enable_ctrl()
2707 ctrl->ctrl_config |= NVME_CC_IOSQES | NVME_CC_IOCQES; in nvme_enable_ctrl()
2708 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2713 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2717 timeout = NVME_CAP_TIMEOUT(ctrl->cap); in nvme_enable_ctrl()
2718 if (ctrl->cap & NVME_CAP_CRMS_CRWMS) { in nvme_enable_ctrl()
2721 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CRTO, &crto); in nvme_enable_ctrl()
2723 dev_err(ctrl->device, "Reading CRTO failed (%d)\n", in nvme_enable_ctrl()
2736 dev_warn_once(ctrl->device, "bad crto:%x cap:%llx\n", in nvme_enable_ctrl()
2737 crto, ctrl->cap); in nvme_enable_ctrl()
2742 ctrl->ctrl_config |= NVME_CC_ENABLE; in nvme_enable_ctrl()
2743 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2746 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, NVME_CSTS_RDY, in nvme_enable_ctrl()
2751 static int nvme_configure_timestamp(struct nvme_ctrl *ctrl) in nvme_configure_timestamp() argument
2756 if (!(ctrl->oncs & NVME_CTRL_ONCS_TIMESTAMP)) in nvme_configure_timestamp()
2760 ret = nvme_set_features(ctrl, NVME_FEAT_TIMESTAMP, 0, &ts, sizeof(ts), in nvme_configure_timestamp()
2763 dev_warn_once(ctrl->device, in nvme_configure_timestamp()
2768 static int nvme_configure_host_options(struct nvme_ctrl *ctrl) in nvme_configure_host_options() argument
2775 if (ctrl->crdt[0]) in nvme_configure_host_options()
2777 if (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) in nvme_configure_host_options()
2789 ret = nvme_set_features(ctrl, NVME_FEAT_HOST_BEHAVIOR, 0, in nvme_configure_host_options()
2849 static int nvme_configure_apst(struct nvme_ctrl *ctrl) in nvme_configure_apst() argument
2864 if (!ctrl->apsta) in nvme_configure_apst()
2867 if (ctrl->npss > 31) { in nvme_configure_apst()
2868 dev_warn(ctrl->device, "NPSS is invalid; not using APST\n"); in nvme_configure_apst()
2876 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) { in nvme_configure_apst()
2878 dev_dbg(ctrl->device, "APST disabled\n"); in nvme_configure_apst()
2888 for (state = (int)ctrl->npss; state >= 0; state--) { in nvme_configure_apst()
2898 if (state == ctrl->npss && in nvme_configure_apst()
2899 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) in nvme_configure_apst()
2906 if (!(ctrl->psd[state].flags & NVME_PS_FLAGS_NON_OP_STATE)) in nvme_configure_apst()
2909 exit_latency_us = (u64)le32_to_cpu(ctrl->psd[state].exit_lat); in nvme_configure_apst()
2910 if (exit_latency_us > ctrl->ps_max_latency_us) in nvme_configure_apst()
2914 le32_to_cpu(ctrl->psd[state].entry_lat); in nvme_configure_apst()
2939 dev_dbg(ctrl->device, "APST enabled but no non-operational states are available\n"); in nvme_configure_apst()
2941 …dev_dbg(ctrl->device, "APST enabled: max PS = %d, max round-trip latency = %lluus, table = %*phN\n… in nvme_configure_apst()
2946 ret = nvme_set_features(ctrl, NVME_FEAT_AUTO_PST, apste, in nvme_configure_apst()
2949 dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret); in nvme_configure_apst()
2956 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_set_latency_tolerance() local
2969 if (ctrl->ps_max_latency_us != latency) { in nvme_set_latency_tolerance()
2970 ctrl->ps_max_latency_us = latency; in nvme_set_latency_tolerance()
2971 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_set_latency_tolerance()
2972 nvme_configure_apst(ctrl); in nvme_set_latency_tolerance()
3067 static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ctrl, in nvme_init_subnqn() argument
3073 if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) { in nvme_init_subnqn()
3080 if (ctrl->vs >= NVME_VS(1, 2, 1)) in nvme_init_subnqn()
3081 dev_warn(ctrl->device, "missing or invalid SUBNQN field.\n"); in nvme_init_subnqn()
3156 static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) in nvme_discovery_ctrl() argument
3158 return ctrl->opts && ctrl->opts->discovery_nqn; in nvme_discovery_ctrl()
3161 static inline bool nvme_admin_ctrl(struct nvme_ctrl *ctrl) in nvme_admin_ctrl() argument
3163 return ctrl->cntrltype == NVME_CTRL_ADMIN; in nvme_admin_ctrl()
3166 static inline bool nvme_is_io_ctrl(struct nvme_ctrl *ctrl) in nvme_is_io_ctrl() argument
3168 return !nvme_discovery_ctrl(ctrl) && !nvme_admin_ctrl(ctrl); in nvme_is_io_ctrl()
3172 struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_validate_cntlid() argument
3182 if (tmp->cntlid == ctrl->cntlid) { in nvme_validate_cntlid()
3183 dev_err(ctrl->device, in nvme_validate_cntlid()
3185 ctrl->cntlid, dev_name(tmp->device), in nvme_validate_cntlid()
3191 nvme_discovery_ctrl(ctrl)) in nvme_validate_cntlid()
3194 dev_err(ctrl->device, in nvme_validate_cntlid()
3202 static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_subsystem() argument
3216 nvme_init_subnqn(subsys, ctrl, id); in nvme_init_subsystem()
3229 if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) { in nvme_init_subsystem()
3230 dev_err(ctrl->device, in nvme_init_subsystem()
3241 dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); in nvme_init_subsystem()
3250 if (!nvme_validate_cntlid(subsys, ctrl, id)) { in nvme_init_subsystem()
3257 dev_err(ctrl->device, in nvme_init_subsystem()
3266 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, in nvme_init_subsystem()
3267 dev_name(ctrl->device)); in nvme_init_subsystem()
3269 dev_err(ctrl->device, in nvme_init_subsystem()
3275 subsys->instance = ctrl->instance; in nvme_init_subsystem()
3276 ctrl->subsys = subsys; in nvme_init_subsystem()
3277 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvme_init_subsystem()
3288 static int nvme_get_log_lsi(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, in nvme_get_log_lsi() argument
3305 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); in nvme_get_log_lsi()
3308 int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, in nvme_get_log() argument
3311 return nvme_get_log_lsi(ctrl, nsid, log_page, lsp, csi, log, size, in nvme_get_log()
3315 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi, in nvme_get_effects_log() argument
3318 struct nvme_effects_log *old, *cel = xa_load(&ctrl->cels, csi); in nvme_get_effects_log()
3328 ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi, in nvme_get_effects_log()
3335 old = xa_store(&ctrl->cels, csi, cel, GFP_KERNEL); in nvme_get_effects_log()
3345 static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units) in nvme_mps_to_sectors() argument
3347 u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; in nvme_mps_to_sectors()
3354 static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) in nvme_init_non_mdts_limits() argument
3366 if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && in nvme_init_non_mdts_limits()
3367 !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) in nvme_init_non_mdts_limits()
3368 ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; in nvme_init_non_mdts_limits()
3370 ctrl->max_zeroes_sectors = 0; in nvme_init_non_mdts_limits()
3372 if (!nvme_is_io_ctrl(ctrl) || in nvme_init_non_mdts_limits()
3373 !nvme_id_cns_ok(ctrl, NVME_ID_CNS_CS_CTRL) || in nvme_init_non_mdts_limits()
3374 test_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags)) in nvme_init_non_mdts_limits()
3385 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_init_non_mdts_limits()
3389 ctrl->dmrl = id->dmrl; in nvme_init_non_mdts_limits()
3390 ctrl->dmrsl = le32_to_cpu(id->dmrsl); in nvme_init_non_mdts_limits()
3392 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); in nvme_init_non_mdts_limits()
3396 set_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags); in nvme_init_non_mdts_limits()
3401 static int nvme_init_effects_log(struct nvme_ctrl *ctrl, in nvme_init_effects_log() argument
3410 old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL); in nvme_init_effects_log()
3420 static void nvme_init_known_nvm_effects(struct nvme_ctrl *ctrl) in nvme_init_known_nvm_effects() argument
3422 struct nvme_effects_log *log = ctrl->effects; in nvme_init_known_nvm_effects()
3452 static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_effects() argument
3456 if (ctrl->effects) in nvme_init_effects()
3460 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3465 if (!ctrl->effects) { in nvme_init_effects()
3466 ret = nvme_init_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3471 nvme_init_known_nvm_effects(ctrl); in nvme_init_effects()
3475 static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_check_ctrl_fabric_info() argument
3481 if (ctrl->cntlid != le16_to_cpu(id->cntlid)) { in nvme_check_ctrl_fabric_info()
3482 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3484 ctrl->cntlid, le16_to_cpu(id->cntlid)); in nvme_check_ctrl_fabric_info()
3488 if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) { in nvme_check_ctrl_fabric_info()
3489 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3494 if (nvme_is_io_ctrl(ctrl) && ctrl->ioccsz < 4) { in nvme_check_ctrl_fabric_info()
3495 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3497 ctrl->ioccsz); in nvme_check_ctrl_fabric_info()
3501 if (nvme_is_io_ctrl(ctrl) && ctrl->iorcsz < 1) { in nvme_check_ctrl_fabric_info()
3502 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3504 ctrl->iorcsz); in nvme_check_ctrl_fabric_info()
3508 if (!ctrl->maxcmd) { in nvme_check_ctrl_fabric_info()
3509 dev_warn(ctrl->device, in nvme_check_ctrl_fabric_info()
3511 ctrl->maxcmd = ctrl->sqsize + 1; in nvme_check_ctrl_fabric_info()
3517 static int nvme_init_identify(struct nvme_ctrl *ctrl) in nvme_init_identify() argument
3525 ret = nvme_identify_ctrl(ctrl, &id); in nvme_init_identify()
3527 dev_err(ctrl->device, "Identify Controller failed (%d)\n", ret); in nvme_init_identify()
3531 if (!(ctrl->ops->flags & NVME_F_FABRICS)) in nvme_init_identify()
3532 ctrl->cntlid = le16_to_cpu(id->cntlid); in nvme_init_identify()
3534 if (!ctrl->identified) { in nvme_init_identify()
3547 ctrl->quirks |= core_quirks[i].quirks; in nvme_init_identify()
3550 ret = nvme_init_subsystem(ctrl, id); in nvme_init_identify()
3554 ret = nvme_init_effects(ctrl, id); in nvme_init_identify()
3558 memcpy(ctrl->subsys->firmware_rev, id->fr, in nvme_init_identify()
3559 sizeof(ctrl->subsys->firmware_rev)); in nvme_init_identify()
3561 if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) { in nvme_init_identify()
3562 …dev_warn(ctrl->device, "forcibly allowing all power states due to nvme_core.force_apst -- use at y… in nvme_init_identify()
3563 ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS; in nvme_init_identify()
3566 ctrl->crdt[0] = le16_to_cpu(id->crdt1); in nvme_init_identify()
3567 ctrl->crdt[1] = le16_to_cpu(id->crdt2); in nvme_init_identify()
3568 ctrl->crdt[2] = le16_to_cpu(id->crdt3); in nvme_init_identify()
3570 ctrl->oacs = le16_to_cpu(id->oacs); in nvme_init_identify()
3571 ctrl->oncs = le16_to_cpu(id->oncs); in nvme_init_identify()
3572 ctrl->mtfa = le16_to_cpu(id->mtfa); in nvme_init_identify()
3573 ctrl->oaes = le32_to_cpu(id->oaes); in nvme_init_identify()
3574 ctrl->wctemp = le16_to_cpu(id->wctemp); in nvme_init_identify()
3575 ctrl->cctemp = le16_to_cpu(id->cctemp); in nvme_init_identify()
3577 atomic_set(&ctrl->abort_limit, id->acl + 1); in nvme_init_identify()
3578 ctrl->vwc = id->vwc; in nvme_init_identify()
3580 max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); in nvme_init_identify()
3583 ctrl->max_hw_sectors = in nvme_init_identify()
3584 min_not_zero(ctrl->max_hw_sectors, max_hw_sectors); in nvme_init_identify()
3586 lim = queue_limits_start_update(ctrl->admin_q); in nvme_init_identify()
3587 nvme_set_ctrl_limits(ctrl, &lim, true); in nvme_init_identify()
3588 ret = queue_limits_commit_update(ctrl->admin_q, &lim); in nvme_init_identify()
3592 ctrl->sgls = le32_to_cpu(id->sgls); in nvme_init_identify()
3593 ctrl->kas = le16_to_cpu(id->kas); in nvme_init_identify()
3594 ctrl->max_namespaces = le32_to_cpu(id->mnan); in nvme_init_identify()
3595 ctrl->ctratt = le32_to_cpu(id->ctratt); in nvme_init_identify()
3597 ctrl->cntrltype = id->cntrltype; in nvme_init_identify()
3598 ctrl->dctype = id->dctype; in nvme_init_identify()
3604 ctrl->shutdown_timeout = clamp_t(unsigned int, transition_time, in nvme_init_identify()
3607 if (ctrl->shutdown_timeout != shutdown_timeout) in nvme_init_identify()
3608 dev_info(ctrl->device, in nvme_init_identify()
3610 ctrl->shutdown_timeout); in nvme_init_identify()
3612 ctrl->shutdown_timeout = shutdown_timeout; in nvme_init_identify()
3614 ctrl->npss = id->npss; in nvme_init_identify()
3615 ctrl->apsta = id->apsta; in nvme_init_identify()
3616 prev_apst_enabled = ctrl->apst_enabled; in nvme_init_identify()
3617 if (ctrl->quirks & NVME_QUIRK_NO_APST) { in nvme_init_identify()
3619 …dev_warn(ctrl->device, "forcibly allowing APST due to nvme_core.force_apst -- use at your own risk… in nvme_init_identify()
3620 ctrl->apst_enabled = true; in nvme_init_identify()
3622 ctrl->apst_enabled = false; in nvme_init_identify()
3625 ctrl->apst_enabled = id->apsta; in nvme_init_identify()
3627 memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd)); in nvme_init_identify()
3629 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_init_identify()
3630 ctrl->icdoff = le16_to_cpu(id->icdoff); in nvme_init_identify()
3631 ctrl->ioccsz = le32_to_cpu(id->ioccsz); in nvme_init_identify()
3632 ctrl->iorcsz = le32_to_cpu(id->iorcsz); in nvme_init_identify()
3633 ctrl->maxcmd = le16_to_cpu(id->maxcmd); in nvme_init_identify()
3635 ret = nvme_check_ctrl_fabric_info(ctrl, id); in nvme_init_identify()
3639 ctrl->hmpre = le32_to_cpu(id->hmpre); in nvme_init_identify()
3640 ctrl->hmmin = le32_to_cpu(id->hmmin); in nvme_init_identify()
3641 ctrl->hmminds = le32_to_cpu(id->hmminds); in nvme_init_identify()
3642 ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); in nvme_init_identify()
3645 ret = nvme_mpath_init_identify(ctrl, id); in nvme_init_identify()
3649 if (ctrl->apst_enabled && !prev_apst_enabled) in nvme_init_identify()
3650 dev_pm_qos_expose_latency_tolerance(ctrl->device); in nvme_init_identify()
3651 else if (!ctrl->apst_enabled && prev_apst_enabled) in nvme_init_identify()
3652 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_identify()
3653 ctrl->awupf = le16_to_cpu(id->awupf); in nvme_init_identify()
3664 int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_init_ctrl_finish() argument
3668 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); in nvme_init_ctrl_finish()
3670 dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); in nvme_init_ctrl_finish()
3674 ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); in nvme_init_ctrl_finish()
3676 if (ctrl->vs >= NVME_VS(1, 1, 0)) in nvme_init_ctrl_finish()
3677 ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); in nvme_init_ctrl_finish()
3679 ret = nvme_init_identify(ctrl); in nvme_init_ctrl_finish()
3683 if (nvme_admin_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3688 dev_dbg(ctrl->device, in nvme_init_ctrl_finish()
3690 ctrl->subsys->subnqn); in nvme_init_ctrl_finish()
3691 ctrl->queue_count = 1; in nvme_init_ctrl_finish()
3694 ret = nvme_configure_apst(ctrl); in nvme_init_ctrl_finish()
3698 ret = nvme_configure_timestamp(ctrl); in nvme_init_ctrl_finish()
3702 ret = nvme_configure_host_options(ctrl); in nvme_init_ctrl_finish()
3706 nvme_configure_opal(ctrl, was_suspended); in nvme_init_ctrl_finish()
3708 if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3713 ret = nvme_hwmon_init(ctrl); in nvme_init_ctrl_finish()
3718 clear_bit(NVME_CTRL_DIRTY_CAPABILITY, &ctrl->flags); in nvme_init_ctrl_finish()
3719 ctrl->identified = true; in nvme_init_ctrl_finish()
3721 nvme_start_keep_alive(ctrl); in nvme_init_ctrl_finish()
3729 struct nvme_ctrl *ctrl = in nvme_dev_open() local
3732 switch (nvme_ctrl_state(ctrl)) { in nvme_dev_open()
3739 nvme_get_ctrl(ctrl); in nvme_dev_open()
3740 if (!try_module_get(ctrl->ops->module)) { in nvme_dev_open()
3741 nvme_put_ctrl(ctrl); in nvme_dev_open()
3745 file->private_data = ctrl; in nvme_dev_open()
3751 struct nvme_ctrl *ctrl = in nvme_dev_release() local
3754 module_put(ctrl->ops->module); in nvme_dev_release()
3755 nvme_put_ctrl(ctrl); in nvme_dev_release()
3768 static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, in nvme_find_ns_head() argument
3773 lockdep_assert_held(&ctrl->subsys->lock); in nvme_find_ns_head()
3775 list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { in nvme_find_ns_head()
3781 if (h->ns_id != nsid || !nvme_is_unique_nsid(ctrl, h)) in nvme_find_ns_head()
3871 ns->cdev_device.parent = ns->ctrl->device; in nvme_add_ns_cdev()
3873 ns->ctrl->instance, ns->head->instance); in nvme_add_ns_cdev()
3878 ns->ctrl->ops->module); in nvme_add_ns_cdev()
3881 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, in nvme_alloc_ns_head() argument
3895 ret = ida_alloc_min(&ctrl->subsys->ns_ida, 1, GFP_KERNEL); in nvme_alloc_ns_head()
3903 head->subsys = ctrl->subsys; in nvme_alloc_ns_head()
3913 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); in nvme_alloc_ns_head()
3917 head->effects = ctrl->effects; in nvme_alloc_ns_head()
3919 ret = nvme_mpath_alloc_disk(ctrl, head); in nvme_alloc_ns_head()
3923 list_add_tail(&head->entry, &ctrl->subsys->nsheads); in nvme_alloc_ns_head()
3925 kref_get(&ctrl->subsys->ref); in nvme_alloc_ns_head()
3931 ida_free(&ctrl->subsys->ns_ida, head->instance); in nvme_alloc_ns_head()
3968 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ns_head() local
3972 ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3990 nvme_print_device_info(ctrl); in nvme_init_ns_head()
3991 if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ in nvme_init_ns_head()
3992 ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && in nvme_init_ns_head()
3994 dev_err(ctrl->device, in nvme_init_ns_head()
4000 dev_err(ctrl->device, in nvme_init_ns_head()
4002 dev_err(ctrl->device, in nvme_init_ns_head()
4007 ctrl->quirks |= NVME_QUIRK_BOGUS_NID; in nvme_init_ns_head()
4010 mutex_lock(&ctrl->subsys->lock); in nvme_init_ns_head()
4011 head = nvme_find_ns_head(ctrl, info->nsid); in nvme_init_ns_head()
4013 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
4015 dev_err(ctrl->device, in nvme_init_ns_head()
4020 head = nvme_alloc_ns_head(ctrl, info); in nvme_init_ns_head()
4029 dev_err(ctrl->device, in nvme_init_ns_head()
4035 dev_err(ctrl->device, in nvme_init_ns_head()
4042 dev_warn(ctrl->device, in nvme_init_ns_head()
4045 dev_warn_once(ctrl->device, in nvme_init_ns_head()
4052 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
4062 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
4066 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_find_get_ns() argument
4071 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_find_get_ns()
4072 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_find_get_ns()
4073 srcu_read_lock_held(&ctrl->srcu)) { in nvme_find_get_ns()
4083 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_find_get_ns()
4095 list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) { in nvme_ns_add_to_ctrl_list()
4101 list_add_rcu(&ns->list, &ns->ctrl->namespaces); in nvme_ns_add_to_ctrl_list()
4104 static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) in nvme_alloc_ns() argument
4109 int node = ctrl->numa_node; in nvme_alloc_ns()
4116 if (ctrl->opts && ctrl->opts->data_digest) in nvme_alloc_ns()
4118 if (ctrl->ops->supports_pci_p2pdma && in nvme_alloc_ns()
4119 ctrl->ops->supports_pci_p2pdma(ctrl)) in nvme_alloc_ns()
4122 disk = blk_mq_alloc_disk(ctrl->tagset, &lim, ns); in nvme_alloc_ns()
4130 ns->ctrl = ctrl; in nvme_alloc_ns()
4148 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
4149 ctrl->instance, ns->head->instance); in nvme_alloc_ns()
4152 sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
4155 sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, in nvme_alloc_ns()
4162 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
4167 if (test_bit(NVME_CTRL_FROZEN, &ctrl->flags)) { in nvme_alloc_ns()
4168 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
4172 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
4173 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
4174 nvme_get_ctrl(ctrl); in nvme_alloc_ns()
4176 if (device_add_disk(ctrl->device, ns->disk, nvme_ns_attr_groups)) in nvme_alloc_ns()
4188 nvme_put_ctrl(ctrl); in nvme_alloc_ns()
4189 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
4191 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
4192 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
4194 mutex_lock(&ctrl->subsys->lock); in nvme_alloc_ns()
4209 mutex_unlock(&ctrl->subsys->lock); in nvme_alloc_ns()
4240 mutex_lock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4247 mutex_unlock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4259 mutex_lock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
4261 mutex_unlock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
4262 synchronize_srcu(&ns->ctrl->srcu); in nvme_ns_remove()
4269 static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) in nvme_ns_remove_by_nsid() argument
4271 struct nvme_ns *ns = nvme_find_get_ns(ctrl, nsid); in nvme_ns_remove_by_nsid()
4284 dev_err(ns->ctrl->device, in nvme_validate_ns()
4301 static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_scan_ns() argument
4307 if (nvme_identify_ns_descs(ctrl, &info)) in nvme_scan_ns()
4310 if (info.ids.csi != NVME_CSI_NVM && !nvme_multi_css(ctrl)) { in nvme_scan_ns()
4311 dev_warn(ctrl->device, in nvme_scan_ns()
4321 if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || in nvme_scan_ns()
4323 ctrl->vs >= NVME_VS(2, 0, 0)) in nvme_scan_ns()
4324 ret = nvme_ns_info_from_id_cs_indep(ctrl, &info); in nvme_scan_ns()
4326 ret = nvme_ns_info_from_identify(ctrl, &info); in nvme_scan_ns()
4329 nvme_ns_remove_by_nsid(ctrl, nsid); in nvme_scan_ns()
4338 ns = nvme_find_get_ns(ctrl, nsid); in nvme_scan_ns()
4343 nvme_alloc_ns(ctrl, &info); in nvme_scan_ns()
4359 struct nvme_ctrl *ctrl; member
4373 nvme_scan_ns(scan_info->ctrl, nsid); in nvme_scan_ns_async()
4376 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, in nvme_remove_invalid_namespaces() argument
4382 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4383 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { in nvme_remove_invalid_namespaces()
4386 synchronize_srcu(&ctrl->srcu); in nvme_remove_invalid_namespaces()
4390 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4396 static int nvme_scan_ns_list(struct nvme_ctrl *ctrl) in nvme_scan_ns_list() argument
4409 scan_info.ctrl = ctrl; in nvme_scan_ns_list()
4418 ret = nvme_submit_sync_cmd(ctrl->admin_q, &cmd, ns_list, in nvme_scan_ns_list()
4421 dev_warn(ctrl->device, in nvme_scan_ns_list()
4435 nvme_ns_remove_by_nsid(ctrl, prev); in nvme_scan_ns_list()
4440 nvme_remove_invalid_namespaces(ctrl, prev); in nvme_scan_ns_list()
4447 static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl) in nvme_scan_ns_sequential() argument
4452 if (nvme_identify_ctrl(ctrl, &id)) in nvme_scan_ns_sequential()
4458 nvme_scan_ns(ctrl, i); in nvme_scan_ns_sequential()
4460 nvme_remove_invalid_namespaces(ctrl, nn); in nvme_scan_ns_sequential()
4463 static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl) in nvme_clear_changed_ns_log() argument
4479 error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_CHANGED_NS, 0, in nvme_clear_changed_ns_log()
4482 dev_warn(ctrl->device, in nvme_clear_changed_ns_log()
4490 struct nvme_ctrl *ctrl = in nvme_scan_work() local
4495 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE || !ctrl->tagset) in nvme_scan_work()
4505 ret = nvme_init_non_mdts_limits(ctrl); in nvme_scan_work()
4507 dev_warn(ctrl->device, in nvme_scan_work()
4512 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { in nvme_scan_work()
4513 dev_info(ctrl->device, "rescanning namespaces.\n"); in nvme_scan_work()
4514 nvme_clear_changed_ns_log(ctrl); in nvme_scan_work()
4517 mutex_lock(&ctrl->scan_lock); in nvme_scan_work()
4518 if (!nvme_id_cns_ok(ctrl, NVME_ID_CNS_NS_ACTIVE_LIST)) { in nvme_scan_work()
4519 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4526 ret = nvme_scan_ns_list(ctrl); in nvme_scan_work()
4528 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4530 mutex_unlock(&ctrl->scan_lock); in nvme_scan_work()
4533 if (test_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) in nvme_scan_work()
4534 nvme_queue_scan(ctrl); in nvme_scan_work()
4536 else if (ctrl->ana_log_buf) in nvme_scan_work()
4538 queue_work(nvme_wq, &ctrl->ana_work); in nvme_scan_work()
4547 void nvme_remove_namespaces(struct nvme_ctrl *ctrl) in nvme_remove_namespaces() argument
4557 nvme_mpath_clear_ctrl_paths(ctrl); in nvme_remove_namespaces()
4563 nvme_unquiesce_io_queues(ctrl); in nvme_remove_namespaces()
4566 flush_work(&ctrl->scan_work); in nvme_remove_namespaces()
4574 if (nvme_ctrl_state(ctrl) == NVME_CTRL_DEAD) in nvme_remove_namespaces()
4575 nvme_mark_namespaces_dead(ctrl); in nvme_remove_namespaces()
4578 nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); in nvme_remove_namespaces()
4580 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4581 list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu); in nvme_remove_namespaces()
4582 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4583 synchronize_srcu(&ctrl->srcu); in nvme_remove_namespaces()
4592 const struct nvme_ctrl *ctrl = in nvme_class_uevent() local
4594 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_class_uevent()
4597 ret = add_uevent_var(env, "NVME_TRTYPE=%s", ctrl->ops->name); in nvme_class_uevent()
4622 static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata) in nvme_change_uevent() argument
4626 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_change_uevent()
4629 static void nvme_aen_uevent(struct nvme_ctrl *ctrl) in nvme_aen_uevent() argument
4632 u32 aen_result = ctrl->aen_result; in nvme_aen_uevent()
4634 ctrl->aen_result = 0; in nvme_aen_uevent()
4641 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_aen_uevent()
4647 struct nvme_ctrl *ctrl = in nvme_async_event_work() local
4650 nvme_aen_uevent(ctrl); in nvme_async_event_work()
4657 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_async_event_work()
4658 ctrl->ops->submit_async_event(ctrl); in nvme_async_event_work()
4661 static bool nvme_ctrl_pp_status(struct nvme_ctrl *ctrl) in nvme_ctrl_pp_status() argument
4666 if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) in nvme_ctrl_pp_status()
4672 return ((ctrl->ctrl_config & NVME_CC_ENABLE) && (csts & NVME_CSTS_PP)); in nvme_ctrl_pp_status()
4675 static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl) in nvme_get_fw_slot_info() argument
4684 if (nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_FW_SLOT, 0, NVME_CSI_NVM, in nvme_get_fw_slot_info()
4686 dev_warn(ctrl->device, "Get FW SLOT INFO log error\n"); in nvme_get_fw_slot_info()
4693 dev_info(ctrl->device, in nvme_get_fw_slot_info()
4698 memcpy(ctrl->subsys->firmware_rev, &log->frs[cur_fw_slot - 1], in nvme_get_fw_slot_info()
4699 sizeof(ctrl->subsys->firmware_rev)); in nvme_get_fw_slot_info()
4707 struct nvme_ctrl *ctrl = container_of(work, in nvme_fw_act_work() local
4711 nvme_auth_stop(ctrl); in nvme_fw_act_work()
4713 if (ctrl->mtfa) in nvme_fw_act_work()
4714 fw_act_timeout = jiffies + msecs_to_jiffies(ctrl->mtfa * 100); in nvme_fw_act_work()
4718 nvme_quiesce_io_queues(ctrl); in nvme_fw_act_work()
4719 while (nvme_ctrl_pp_status(ctrl)) { in nvme_fw_act_work()
4721 dev_warn(ctrl->device, in nvme_fw_act_work()
4723 nvme_try_sched_reset(ctrl); in nvme_fw_act_work()
4729 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING) || in nvme_fw_act_work()
4730 !nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) in nvme_fw_act_work()
4733 nvme_unquiesce_io_queues(ctrl); in nvme_fw_act_work()
4735 nvme_get_fw_slot_info(ctrl); in nvme_fw_act_work()
4737 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_fw_act_work()
4750 static bool nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result) in nvme_handle_aen_notice() argument
4757 set_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events); in nvme_handle_aen_notice()
4758 nvme_queue_scan(ctrl); in nvme_handle_aen_notice()
4766 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) { in nvme_handle_aen_notice()
4768 queue_work(nvme_wq, &ctrl->fw_act_work); in nvme_handle_aen_notice()
4773 if (!ctrl->ana_log_buf) in nvme_handle_aen_notice()
4775 queue_work(nvme_wq, &ctrl->ana_work); in nvme_handle_aen_notice()
4779 ctrl->aen_result = result; in nvme_handle_aen_notice()
4782 dev_warn(ctrl->device, "async event result %08x\n", result); in nvme_handle_aen_notice()
4787 static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl) in nvme_handle_aer_persistent_error() argument
4789 dev_warn(ctrl->device, in nvme_handle_aer_persistent_error()
4791 nvme_reset_ctrl(ctrl); in nvme_handle_aer_persistent_error()
4794 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, in nvme_complete_async_event() argument
4805 trace_nvme_async_event(ctrl, result); in nvme_complete_async_event()
4808 requeue = nvme_handle_aen_notice(ctrl, result); in nvme_complete_async_event()
4816 nvme_handle_aer_persistent_error(ctrl); in nvme_complete_async_event()
4823 ctrl->aen_result = result; in nvme_complete_async_event()
4830 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_complete_async_event()
4834 int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_admin_tag_set() argument
4842 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_admin_tag_set()
4845 set->numa_node = ctrl->numa_node; in nvme_alloc_admin_tag_set()
4846 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_admin_tag_set()
4849 set->driver_data = ctrl; in nvme_alloc_admin_tag_set()
4860 if (ctrl->admin_q) in nvme_alloc_admin_tag_set()
4861 blk_put_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4863 ctrl->admin_q = blk_mq_alloc_queue(set, NULL, NULL); in nvme_alloc_admin_tag_set()
4864 if (IS_ERR(ctrl->admin_q)) { in nvme_alloc_admin_tag_set()
4865 ret = PTR_ERR(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4869 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_admin_tag_set()
4870 ctrl->fabrics_q = blk_mq_alloc_queue(set, NULL, NULL); in nvme_alloc_admin_tag_set()
4871 if (IS_ERR(ctrl->fabrics_q)) { in nvme_alloc_admin_tag_set()
4872 ret = PTR_ERR(ctrl->fabrics_q); in nvme_alloc_admin_tag_set()
4877 ctrl->admin_tagset = set; in nvme_alloc_admin_tag_set()
4881 blk_mq_destroy_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4882 blk_put_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4885 ctrl->admin_q = NULL; in nvme_alloc_admin_tag_set()
4886 ctrl->fabrics_q = NULL; in nvme_alloc_admin_tag_set()
4891 void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_admin_tag_set() argument
4897 nvme_stop_keep_alive(ctrl); in nvme_remove_admin_tag_set()
4898 blk_mq_destroy_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4899 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_admin_tag_set()
4900 blk_mq_destroy_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4901 blk_put_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4903 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_remove_admin_tag_set()
4907 int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_io_tag_set() argument
4915 set->queue_depth = min_t(unsigned, ctrl->sqsize, BLK_MQ_MAX_DEPTH - 1); in nvme_alloc_io_tag_set()
4920 if (ctrl->quirks & NVME_QUIRK_SHARED_TAGS) in nvme_alloc_io_tag_set()
4922 else if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_io_tag_set()
4925 set->numa_node = ctrl->numa_node; in nvme_alloc_io_tag_set()
4926 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_io_tag_set()
4929 set->driver_data = ctrl; in nvme_alloc_io_tag_set()
4930 set->nr_hw_queues = ctrl->queue_count - 1; in nvme_alloc_io_tag_set()
4937 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_io_tag_set()
4942 ctrl->connect_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_io_tag_set()
4943 if (IS_ERR(ctrl->connect_q)) { in nvme_alloc_io_tag_set()
4944 ret = PTR_ERR(ctrl->connect_q); in nvme_alloc_io_tag_set()
4949 ctrl->tagset = set; in nvme_alloc_io_tag_set()
4954 ctrl->connect_q = NULL; in nvme_alloc_io_tag_set()
4959 void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_io_tag_set() argument
4961 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_io_tag_set()
4962 blk_mq_destroy_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4963 blk_put_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4965 blk_mq_free_tag_set(ctrl->tagset); in nvme_remove_io_tag_set()
4969 void nvme_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_stop_ctrl() argument
4971 nvme_mpath_stop(ctrl); in nvme_stop_ctrl()
4972 nvme_auth_stop(ctrl); in nvme_stop_ctrl()
4973 nvme_stop_failfast_work(ctrl); in nvme_stop_ctrl()
4974 flush_work(&ctrl->async_event_work); in nvme_stop_ctrl()
4975 cancel_work_sync(&ctrl->fw_act_work); in nvme_stop_ctrl()
4976 if (ctrl->ops->stop_ctrl) in nvme_stop_ctrl()
4977 ctrl->ops->stop_ctrl(ctrl); in nvme_stop_ctrl()
4981 void nvme_start_ctrl(struct nvme_ctrl *ctrl) in nvme_start_ctrl() argument
4983 nvme_enable_aen(ctrl); in nvme_start_ctrl()
4991 if (test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags) && in nvme_start_ctrl()
4992 nvme_discovery_ctrl(ctrl)) { in nvme_start_ctrl()
4993 if (!ctrl->kato) { in nvme_start_ctrl()
4994 nvme_stop_keep_alive(ctrl); in nvme_start_ctrl()
4995 ctrl->kato = NVME_DEFAULT_KATO; in nvme_start_ctrl()
4996 nvme_start_keep_alive(ctrl); in nvme_start_ctrl()
4998 nvme_change_uevent(ctrl, "NVME_EVENT=rediscover"); in nvme_start_ctrl()
5001 if (ctrl->queue_count > 1) { in nvme_start_ctrl()
5002 nvme_queue_scan(ctrl); in nvme_start_ctrl()
5003 nvme_unquiesce_io_queues(ctrl); in nvme_start_ctrl()
5004 nvme_mpath_update(ctrl); in nvme_start_ctrl()
5007 nvme_change_uevent(ctrl, "NVME_EVENT=connected"); in nvme_start_ctrl()
5008 set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags); in nvme_start_ctrl()
5012 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) in nvme_uninit_ctrl() argument
5014 nvme_stop_keep_alive(ctrl); in nvme_uninit_ctrl()
5015 nvme_hwmon_exit(ctrl); in nvme_uninit_ctrl()
5016 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_uninit_ctrl()
5017 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_uninit_ctrl()
5018 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_uninit_ctrl()
5019 nvme_put_ctrl(ctrl); in nvme_uninit_ctrl()
5023 static void nvme_free_cels(struct nvme_ctrl *ctrl) in nvme_free_cels() argument
5028 xa_for_each(&ctrl->cels, i, cel) { in nvme_free_cels()
5029 xa_erase(&ctrl->cels, i); in nvme_free_cels()
5033 xa_destroy(&ctrl->cels); in nvme_free_cels()
5038 struct nvme_ctrl *ctrl = in nvme_free_ctrl() local
5040 struct nvme_subsystem *subsys = ctrl->subsys; in nvme_free_ctrl()
5042 if (ctrl->admin_q) in nvme_free_ctrl()
5043 blk_put_queue(ctrl->admin_q); in nvme_free_ctrl()
5044 if (!subsys || ctrl->instance != subsys->instance) in nvme_free_ctrl()
5045 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_free_ctrl()
5046 nvme_free_cels(ctrl); in nvme_free_ctrl()
5047 nvme_mpath_uninit(ctrl); in nvme_free_ctrl()
5048 cleanup_srcu_struct(&ctrl->srcu); in nvme_free_ctrl()
5049 nvme_auth_stop(ctrl); in nvme_free_ctrl()
5050 nvme_auth_free(ctrl); in nvme_free_ctrl()
5051 __free_page(ctrl->discard_page); in nvme_free_ctrl()
5052 free_opal_dev(ctrl->opal_dev); in nvme_free_ctrl()
5056 list_del(&ctrl->subsys_entry); in nvme_free_ctrl()
5057 sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device)); in nvme_free_ctrl()
5061 ctrl->ops->free_ctrl(ctrl); in nvme_free_ctrl()
5075 int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, in nvme_init_ctrl() argument
5080 WRITE_ONCE(ctrl->state, NVME_CTRL_NEW); in nvme_init_ctrl()
5081 ctrl->passthru_err_log_enabled = false; in nvme_init_ctrl()
5082 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_init_ctrl()
5083 spin_lock_init(&ctrl->lock); in nvme_init_ctrl()
5084 mutex_init(&ctrl->namespaces_lock); in nvme_init_ctrl()
5086 ret = init_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
5090 mutex_init(&ctrl->scan_lock); in nvme_init_ctrl()
5091 INIT_LIST_HEAD(&ctrl->namespaces); in nvme_init_ctrl()
5092 xa_init(&ctrl->cels); in nvme_init_ctrl()
5093 ctrl->dev = dev; in nvme_init_ctrl()
5094 ctrl->ops = ops; in nvme_init_ctrl()
5095 ctrl->quirks = quirks; in nvme_init_ctrl()
5096 ctrl->numa_node = NUMA_NO_NODE; in nvme_init_ctrl()
5097 INIT_WORK(&ctrl->scan_work, nvme_scan_work); in nvme_init_ctrl()
5098 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); in nvme_init_ctrl()
5099 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); in nvme_init_ctrl()
5100 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); in nvme_init_ctrl()
5101 init_waitqueue_head(&ctrl->state_wq); in nvme_init_ctrl()
5103 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); in nvme_init_ctrl()
5104 INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); in nvme_init_ctrl()
5105 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); in nvme_init_ctrl()
5106 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; in nvme_init_ctrl()
5107 ctrl->ka_last_check_time = jiffies; in nvme_init_ctrl()
5111 ctrl->discard_page = alloc_page(GFP_KERNEL); in nvme_init_ctrl()
5112 if (!ctrl->discard_page) { in nvme_init_ctrl()
5120 ctrl->instance = ret; in nvme_init_ctrl()
5122 ret = nvme_auth_init_ctrl(ctrl); in nvme_init_ctrl()
5126 nvme_mpath_init_ctrl(ctrl); in nvme_init_ctrl()
5128 device_initialize(&ctrl->ctrl_device); in nvme_init_ctrl()
5129 ctrl->device = &ctrl->ctrl_device; in nvme_init_ctrl()
5130 ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt), in nvme_init_ctrl()
5131 ctrl->instance); in nvme_init_ctrl()
5132 ctrl->device->class = &nvme_class; in nvme_init_ctrl()
5133 ctrl->device->parent = ctrl->dev; in nvme_init_ctrl()
5135 ctrl->device->groups = ops->dev_attr_groups; in nvme_init_ctrl()
5137 ctrl->device->groups = nvme_dev_attr_groups; in nvme_init_ctrl()
5138 ctrl->device->release = nvme_free_ctrl; in nvme_init_ctrl()
5139 dev_set_drvdata(ctrl->device, ctrl); in nvme_init_ctrl()
5144 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_init_ctrl()
5146 if (ctrl->discard_page) in nvme_init_ctrl()
5147 __free_page(ctrl->discard_page); in nvme_init_ctrl()
5148 cleanup_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
5157 int nvme_add_ctrl(struct nvme_ctrl *ctrl) in nvme_add_ctrl() argument
5161 ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance); in nvme_add_ctrl()
5165 cdev_init(&ctrl->cdev, &nvme_dev_fops); in nvme_add_ctrl()
5166 ctrl->cdev.owner = ctrl->ops->module; in nvme_add_ctrl()
5167 ret = cdev_device_add(&ctrl->cdev, ctrl->device); in nvme_add_ctrl()
5175 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; in nvme_add_ctrl()
5176 dev_pm_qos_update_user_latency_tolerance(ctrl->device, in nvme_add_ctrl()
5179 nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); in nvme_add_ctrl()
5180 nvme_get_ctrl(ctrl); in nvme_add_ctrl()
5187 void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl) in nvme_mark_namespaces_dead() argument
5192 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_mark_namespaces_dead()
5193 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_mark_namespaces_dead()
5194 srcu_read_lock_held(&ctrl->srcu)) in nvme_mark_namespaces_dead()
5196 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_mark_namespaces_dead()
5200 void nvme_unfreeze(struct nvme_ctrl *ctrl) in nvme_unfreeze() argument
5205 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_unfreeze()
5206 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_unfreeze()
5207 srcu_read_lock_held(&ctrl->srcu)) in nvme_unfreeze()
5209 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_unfreeze()
5210 clear_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_unfreeze()
5214 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout) in nvme_wait_freeze_timeout() argument
5219 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze_timeout()
5220 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze_timeout()
5221 srcu_read_lock_held(&ctrl->srcu)) { in nvme_wait_freeze_timeout()
5226 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze_timeout()
5231 void nvme_wait_freeze(struct nvme_ctrl *ctrl) in nvme_wait_freeze() argument
5236 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze()
5237 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze()
5238 srcu_read_lock_held(&ctrl->srcu)) in nvme_wait_freeze()
5240 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze()
5244 void nvme_start_freeze(struct nvme_ctrl *ctrl) in nvme_start_freeze() argument
5249 set_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_start_freeze()
5250 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_start_freeze()
5251 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_start_freeze()
5252 srcu_read_lock_held(&ctrl->srcu)) in nvme_start_freeze()
5259 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_start_freeze()
5263 void nvme_quiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_quiesce_io_queues() argument
5265 if (!ctrl->tagset) in nvme_quiesce_io_queues()
5267 if (!test_and_set_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_quiesce_io_queues()
5268 blk_mq_quiesce_tagset(ctrl->tagset); in nvme_quiesce_io_queues()
5270 blk_mq_wait_quiesce_done(ctrl->tagset); in nvme_quiesce_io_queues()
5274 void nvme_unquiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_unquiesce_io_queues() argument
5276 if (!ctrl->tagset) in nvme_unquiesce_io_queues()
5278 if (test_and_clear_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_unquiesce_io_queues()
5279 blk_mq_unquiesce_tagset(ctrl->tagset); in nvme_unquiesce_io_queues()
5283 void nvme_quiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_quiesce_admin_queue() argument
5285 if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_quiesce_admin_queue()
5286 blk_mq_quiesce_queue(ctrl->admin_q); in nvme_quiesce_admin_queue()
5288 blk_mq_wait_quiesce_done(ctrl->admin_q->tag_set); in nvme_quiesce_admin_queue()
5292 void nvme_unquiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_unquiesce_admin_queue() argument
5294 if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_unquiesce_admin_queue()
5295 blk_mq_unquiesce_queue(ctrl->admin_q); in nvme_unquiesce_admin_queue()
5299 void nvme_sync_io_queues(struct nvme_ctrl *ctrl) in nvme_sync_io_queues() argument
5304 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_sync_io_queues()
5305 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_sync_io_queues()
5306 srcu_read_lock_held(&ctrl->srcu)) in nvme_sync_io_queues()
5308 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_sync_io_queues()
5312 void nvme_sync_queues(struct nvme_ctrl *ctrl) in nvme_sync_queues() argument
5314 nvme_sync_io_queues(ctrl); in nvme_sync_queues()
5315 if (ctrl->admin_q) in nvme_sync_queues()
5316 blk_sync_queue(ctrl->admin_q); in nvme_sync_queues()