• Home
  • Raw
  • Download

Lines Matching refs:ctrl

147 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
149 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
152 void nvme_queue_scan(struct nvme_ctrl *ctrl) in nvme_queue_scan() argument
157 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE && ctrl->tagset) in nvme_queue_scan()
158 queue_work(nvme_wq, &ctrl->scan_work); in nvme_queue_scan()
167 int nvme_try_sched_reset(struct nvme_ctrl *ctrl) in nvme_try_sched_reset() argument
169 if (nvme_ctrl_state(ctrl) != NVME_CTRL_RESETTING) in nvme_try_sched_reset()
171 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_try_sched_reset()
179 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_failfast_work() local
182 if (nvme_ctrl_state(ctrl) != NVME_CTRL_CONNECTING) in nvme_failfast_work()
185 set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_failfast_work()
186 dev_info(ctrl->device, "failfast expired\n"); in nvme_failfast_work()
187 nvme_kick_requeue_lists(ctrl); in nvme_failfast_work()
190 static inline void nvme_start_failfast_work(struct nvme_ctrl *ctrl) in nvme_start_failfast_work() argument
192 if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) in nvme_start_failfast_work()
195 schedule_delayed_work(&ctrl->failfast_work, in nvme_start_failfast_work()
196 ctrl->opts->fast_io_fail_tmo * HZ); in nvme_start_failfast_work()
199 static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) in nvme_stop_failfast_work() argument
201 if (!ctrl->opts) in nvme_stop_failfast_work()
204 cancel_delayed_work_sync(&ctrl->failfast_work); in nvme_stop_failfast_work()
205 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_stop_failfast_work()
209 int nvme_reset_ctrl(struct nvme_ctrl *ctrl) in nvme_reset_ctrl() argument
211 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) in nvme_reset_ctrl()
213 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_reset_ctrl()
219 int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_reset_ctrl_sync() argument
223 ret = nvme_reset_ctrl(ctrl); in nvme_reset_ctrl_sync()
225 flush_work(&ctrl->reset_work); in nvme_reset_ctrl_sync()
226 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE) in nvme_reset_ctrl_sync()
233 static void nvme_do_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_do_delete_ctrl() argument
235 dev_info(ctrl->device, in nvme_do_delete_ctrl()
236 "Removing ctrl: NQN \"%s\"\n", nvmf_ctrl_subsysnqn(ctrl)); in nvme_do_delete_ctrl()
238 flush_work(&ctrl->reset_work); in nvme_do_delete_ctrl()
239 nvme_stop_ctrl(ctrl); in nvme_do_delete_ctrl()
240 nvme_remove_namespaces(ctrl); in nvme_do_delete_ctrl()
241 ctrl->ops->delete_ctrl(ctrl); in nvme_do_delete_ctrl()
242 nvme_uninit_ctrl(ctrl); in nvme_do_delete_ctrl()
247 struct nvme_ctrl *ctrl = in nvme_delete_ctrl_work() local
250 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_work()
253 int nvme_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_delete_ctrl() argument
255 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl()
257 if (!queue_work(nvme_delete_wq, &ctrl->delete_work)) in nvme_delete_ctrl()
263 void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_delete_ctrl_sync() argument
269 nvme_get_ctrl(ctrl); in nvme_delete_ctrl_sync()
270 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl_sync()
271 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_sync()
272 nvme_put_ctrl(ctrl); in nvme_delete_ctrl_sync()
324 delay = nvme_req(req)->ctrl->crdt[crd - 1] * 100; in nvme_retry_req()
352 dev_name(nr->ctrl->device), in nvme_log_error()
369 ns ? ns->disk->disk_name : dev_name(nr->ctrl->device), in nvme_log_err_passthru()
453 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_complete_rq() local
466 if (ctrl->kas && in nvme_complete_rq()
467 req->deadline - req->timeout >= ctrl->ka_last_check_time) in nvme_complete_rq()
468 ctrl->comp_seen = true; in nvme_complete_rq()
482 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_complete_rq()
531 void nvme_cancel_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_tagset() argument
533 if (ctrl->tagset) { in nvme_cancel_tagset()
534 blk_mq_tagset_busy_iter(ctrl->tagset, in nvme_cancel_tagset()
535 nvme_cancel_request, ctrl); in nvme_cancel_tagset()
536 blk_mq_tagset_wait_completed_request(ctrl->tagset); in nvme_cancel_tagset()
541 void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_admin_tagset() argument
543 if (ctrl->admin_tagset) { in nvme_cancel_admin_tagset()
544 blk_mq_tagset_busy_iter(ctrl->admin_tagset, in nvme_cancel_admin_tagset()
545 nvme_cancel_request, ctrl); in nvme_cancel_admin_tagset()
546 blk_mq_tagset_wait_completed_request(ctrl->admin_tagset); in nvme_cancel_admin_tagset()
551 bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, in nvme_change_ctrl_state() argument
558 spin_lock_irqsave(&ctrl->lock, flags); in nvme_change_ctrl_state()
560 old_state = nvme_ctrl_state(ctrl); in nvme_change_ctrl_state()
626 WRITE_ONCE(ctrl->state, new_state); in nvme_change_ctrl_state()
627 wake_up_all(&ctrl->state_wq); in nvme_change_ctrl_state()
630 spin_unlock_irqrestore(&ctrl->lock, flags); in nvme_change_ctrl_state()
636 nvme_stop_failfast_work(ctrl); in nvme_change_ctrl_state()
637 nvme_kick_requeue_lists(ctrl); in nvme_change_ctrl_state()
640 nvme_start_failfast_work(ctrl); in nvme_change_ctrl_state()
650 bool nvme_wait_reset(struct nvme_ctrl *ctrl) in nvme_wait_reset() argument
652 wait_event(ctrl->state_wq, in nvme_wait_reset()
653 nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING) || in nvme_wait_reset()
654 nvme_state_terminal(ctrl)); in nvme_wait_reset()
655 return nvme_ctrl_state(ctrl) == NVME_CTRL_RESETTING; in nvme_wait_reset()
687 nvme_put_ctrl(ns->ctrl); in nvme_free_ns()
722 logging_enabled = nr->ctrl->passthru_err_log_enabled; in nvme_init_request()
749 blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl, in nvme_fail_nonready_command() argument
752 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_fail_nonready_command()
757 !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) && in nvme_fail_nonready_command()
768 bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq, in __nvme_check_ready() argument
781 if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD)) in __nvme_check_ready()
784 if (ctrl->ops->flags & NVME_F_FABRICS) { in __nvme_check_ready()
838 if (test_and_set_bit_lock(0, &ns->ctrl->discard_page_busy)) in nvme_setup_discard()
841 range = page_address(ns->ctrl->discard_page); in nvme_setup_discard()
868 if (virt_to_page(range) == ns->ctrl->discard_page) in nvme_setup_discard()
869 clear_bit_unlock(0, &ns->ctrl->discard_page_busy); in nvme_setup_discard()
925 if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_setup_write_zeroes()
1046 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_cleanup_cmd() local
1048 if (req->special_vec.bv_page == ctrl->discard_page) in nvme_cleanup_cmd()
1049 clear_bit_unlock(0, &ctrl->discard_page_busy); in nvme_cleanup_cmd()
1182 u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_command_effects() argument
1189 dev_warn_once(ctrl->device, in nvme_command_effects()
1200 effects = le32_to_cpu(ctrl->effects->acs[opcode]); in nvme_command_effects()
1211 u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_passthru_start() argument
1213 u32 effects = nvme_command_effects(ctrl, ns, opcode); in nvme_passthru_start()
1220 mutex_lock(&ctrl->scan_lock); in nvme_passthru_start()
1221 mutex_lock(&ctrl->subsys->lock); in nvme_passthru_start()
1222 nvme_mpath_start_freeze(ctrl->subsys); in nvme_passthru_start()
1223 nvme_mpath_wait_freeze(ctrl->subsys); in nvme_passthru_start()
1224 nvme_start_freeze(ctrl); in nvme_passthru_start()
1225 nvme_wait_freeze(ctrl); in nvme_passthru_start()
1231 void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 effects, in nvme_passthru_end() argument
1235 nvme_unfreeze(ctrl); in nvme_passthru_end()
1236 nvme_mpath_unfreeze(ctrl->subsys); in nvme_passthru_end()
1237 mutex_unlock(&ctrl->subsys->lock); in nvme_passthru_end()
1238 mutex_unlock(&ctrl->scan_lock); in nvme_passthru_end()
1242 &ctrl->flags)) { in nvme_passthru_end()
1243 dev_info(ctrl->device, in nvme_passthru_end()
1248 nvme_queue_scan(ctrl); in nvme_passthru_end()
1249 flush_work(&ctrl->scan_work); in nvme_passthru_end()
1264 nvme_update_keep_alive(ctrl, cmd); in nvme_passthru_end()
1282 static unsigned long nvme_keep_alive_work_period(struct nvme_ctrl *ctrl) in nvme_keep_alive_work_period() argument
1284 unsigned long delay = ctrl->kato * HZ / 2; in nvme_keep_alive_work_period()
1292 if (ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) in nvme_keep_alive_work_period()
1297 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) in nvme_queue_keep_alive_work() argument
1300 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_queue_keep_alive_work()
1301 unsigned long ka_next_check_tm = ctrl->ka_last_check_time + delay; in nvme_queue_keep_alive_work()
1308 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_queue_keep_alive_work()
1314 struct nvme_ctrl *ctrl = rq->end_io_data; in nvme_keep_alive_end_io() local
1316 unsigned long delay = nvme_keep_alive_work_period(ctrl); in nvme_keep_alive_end_io()
1317 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_keep_alive_end_io()
1326 dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n", in nvme_keep_alive_end_io()
1334 dev_err(ctrl->device, in nvme_keep_alive_end_io()
1340 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_end_io()
1341 ctrl->comp_seen = false; in nvme_keep_alive_end_io()
1343 queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); in nvme_keep_alive_end_io()
1349 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_keep_alive_work() local
1351 bool comp_seen = ctrl->comp_seen; in nvme_keep_alive_work()
1354 ctrl->ka_last_check_time = jiffies; in nvme_keep_alive_work()
1356 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { in nvme_keep_alive_work()
1357 dev_dbg(ctrl->device, in nvme_keep_alive_work()
1359 ctrl->comp_seen = false; in nvme_keep_alive_work()
1360 nvme_queue_keep_alive_work(ctrl); in nvme_keep_alive_work()
1364 rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd), in nvme_keep_alive_work()
1368 dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq)); in nvme_keep_alive_work()
1369 nvme_reset_ctrl(ctrl); in nvme_keep_alive_work()
1372 nvme_init_request(rq, &ctrl->ka_cmd); in nvme_keep_alive_work()
1374 rq->timeout = ctrl->kato * HZ; in nvme_keep_alive_work()
1376 rq->end_io_data = ctrl; in nvme_keep_alive_work()
1380 static void nvme_start_keep_alive(struct nvme_ctrl *ctrl) in nvme_start_keep_alive() argument
1382 if (unlikely(ctrl->kato == 0)) in nvme_start_keep_alive()
1385 nvme_queue_keep_alive_work(ctrl); in nvme_start_keep_alive()
1388 void nvme_stop_keep_alive(struct nvme_ctrl *ctrl) in nvme_stop_keep_alive() argument
1390 if (unlikely(ctrl->kato == 0)) in nvme_stop_keep_alive()
1393 cancel_delayed_work_sync(&ctrl->ka_work); in nvme_stop_keep_alive()
1397 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, in nvme_update_keep_alive() argument
1403 dev_info(ctrl->device, in nvme_update_keep_alive()
1405 ctrl->kato * 1000 / 2, new_kato * 1000 / 2); in nvme_update_keep_alive()
1407 nvme_stop_keep_alive(ctrl); in nvme_update_keep_alive()
1408 ctrl->kato = new_kato; in nvme_update_keep_alive()
1409 nvme_start_keep_alive(ctrl); in nvme_update_keep_alive()
1412 static bool nvme_id_cns_ok(struct nvme_ctrl *ctrl, u8 cns) in nvme_id_cns_ok() argument
1417 if (ctrl->vs >= NVME_VS(1, 2, 0)) in nvme_id_cns_ok()
1428 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_id_cns_ok()
1429 !(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) in nvme_id_cns_ok()
1460 static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, in nvme_process_ns_desc() argument
1469 dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n", in nvme_process_ns_desc()
1473 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1479 dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n", in nvme_process_ns_desc()
1483 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1489 dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n", in nvme_process_ns_desc()
1493 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1499 dev_warn(ctrl->device, "%s %d for NVME_NIDT_CSI\n", in nvme_process_ns_desc()
1512 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, in nvme_identify_ns_descs() argument
1520 if (ctrl->vs < NVME_VS(1, 3, 0) && !nvme_multi_css(ctrl)) in nvme_identify_ns_descs()
1522 if (ctrl->quirks & NVME_QUIRK_NO_NS_DESC_LIST) in nvme_identify_ns_descs()
1533 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data, in nvme_identify_ns_descs()
1536 dev_warn(ctrl->device, in nvme_identify_ns_descs()
1548 len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); in nvme_identify_ns_descs()
1555 if (nvme_multi_css(ctrl) && !csi_seen) { in nvme_identify_ns_descs()
1556 dev_warn(ctrl->device, "Command set not reported for nsid:%d\n", in nvme_identify_ns_descs()
1566 int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, in nvme_identify_ns() argument
1581 error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id)); in nvme_identify_ns()
1583 dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error); in nvme_identify_ns()
1590 static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, in nvme_ns_info_from_identify() argument
1597 ret = nvme_identify_ns(ctrl, info->nsid, &id); in nvme_ns_info_from_identify()
1612 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) { in nvme_ns_info_from_identify()
1613 dev_info(ctrl->device, in nvme_ns_info_from_identify()
1616 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_ns_info_from_identify()
1619 if (ctrl->vs >= NVME_VS(1, 2, 0) && in nvme_ns_info_from_identify()
1629 static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, in nvme_ns_info_from_id_cs_indep() argument
1644 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_ns_info_from_id_cs_indep()
1691 int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) in nvme_set_queue_count() argument
1697 status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0, in nvme_set_queue_count()
1714 dev_err(ctrl->device, "Could not set queue count (%d)\n", status); in nvme_set_queue_count()
1729 static void nvme_enable_aen(struct nvme_ctrl *ctrl) in nvme_enable_aen() argument
1731 u32 result, supported_aens = ctrl->oaes & NVME_AEN_SUPPORTED; in nvme_enable_aen()
1737 status = nvme_set_features(ctrl, NVME_FEAT_ASYNC_EVENT, supported_aens, in nvme_enable_aen()
1740 dev_warn(ctrl->device, "Failed to configure AEN (cfg %x)\n", in nvme_enable_aen()
1743 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_enable_aen()
1754 if (!try_module_get(ns->ctrl->ops->module)) in nvme_ns_open()
1768 module_put(ns->ctrl->ops->module); in nvme_ns_release()
1856 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_config_discard() local
1858 if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns->head, UINT_MAX)) in nvme_config_discard()
1860 nvme_lba_to_sect(ns->head, ctrl->dmrsl); in nvme_config_discard()
1861 else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) in nvme_config_discard()
1868 if (ctrl->dmrl) in nvme_config_discard()
1869 lim->max_discard_segments = ctrl->dmrl; in nvme_config_discard()
1882 static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid, in nvme_identify_ns_nvm() argument
1898 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm)); in nvme_identify_ns_nvm()
1934 static void nvme_configure_metadata(struct nvme_ctrl *ctrl, in nvme_configure_metadata() argument
1942 if (!head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) in nvme_configure_metadata()
1945 if (nvm && (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { in nvme_configure_metadata()
1961 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_configure_metadata()
1981 if (ctrl->max_integrity_segments && nvme_ns_has_pi(head)) in nvme_configure_metadata()
2014 static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl) in nvme_max_drv_segments() argument
2016 return ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> SECTOR_SHIFT) + 1; in nvme_max_drv_segments()
2019 static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl, in nvme_set_ctrl_limits() argument
2022 lim->max_hw_sectors = ctrl->max_hw_sectors; in nvme_set_ctrl_limits()
2024 min_not_zero(nvme_max_drv_segments(ctrl), ctrl->max_segments)); in nvme_set_ctrl_limits()
2025 lim->max_integrity_segments = ctrl->max_integrity_segments; in nvme_set_ctrl_limits()
2059 atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; in nvme_update_disk_info()
2081 if ((ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) && in nvme_update_disk_info()
2082 (ns->ctrl->oncs & NVME_CTRL_ONCS_DSM)) in nvme_update_disk_info()
2085 lim->max_write_zeroes_sectors = ns->ctrl->max_zeroes_sectors; in nvme_update_disk_info()
2103 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_set_chunk_sectors() local
2106 if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) && in nvme_set_chunk_sectors()
2107 is_power_of_2(ctrl->max_hw_sectors)) in nvme_set_chunk_sectors()
2108 iob = ctrl->max_hw_sectors; in nvme_set_chunk_sectors()
2139 nvme_set_ctrl_limits(ns->ctrl, &lim); in nvme_update_ns_info_generic()
2163 ret = nvme_identify_ns(ns->ctrl, info->nsid, &id); in nvme_update_ns_info_block()
2175 if (ns->ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) { in nvme_update_ns_info_block()
2176 ret = nvme_identify_ns_nvm(ns->ctrl, info->nsid, &nvm); in nvme_update_ns_info_block()
2194 nvme_set_ctrl_limits(ns->ctrl, &lim); in nvme_update_ns_info_block()
2195 nvme_configure_metadata(ns->ctrl, ns->head, id, nvm, info); in nvme_update_ns_info_block()
2204 if (ns->ctrl->vwc & NVME_CTRL_VWC_PRESENT) in nvme_update_ns_info_block()
2259 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2271 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2362 struct nvme_ctrl *ctrl = data; in nvme_sec_submit() local
2373 return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len, in nvme_sec_submit()
2377 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2379 if (ctrl->oacs & NVME_CTRL_OACS_SEC_SUPP) { in nvme_configure_opal()
2380 if (!ctrl->opal_dev) in nvme_configure_opal()
2381 ctrl->opal_dev = init_opal_dev(ctrl, &nvme_sec_submit); in nvme_configure_opal()
2383 opal_unlock_from_suspend(ctrl->opal_dev); in nvme_configure_opal()
2385 free_opal_dev(ctrl->opal_dev); in nvme_configure_opal()
2386 ctrl->opal_dev = NULL; in nvme_configure_opal()
2390 static void nvme_configure_opal(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_configure_opal() argument
2418 static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val, in nvme_wait_ready() argument
2425 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_wait_ready()
2435 dev_err(ctrl->device, in nvme_wait_ready()
2445 int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown) in nvme_disable_ctrl() argument
2449 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_disable_ctrl()
2451 ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; in nvme_disable_ctrl()
2453 ctrl->ctrl_config &= ~NVME_CC_ENABLE; in nvme_disable_ctrl()
2455 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_disable_ctrl()
2460 return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK, in nvme_disable_ctrl()
2462 ctrl->shutdown_timeout, "shutdown"); in nvme_disable_ctrl()
2464 if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY) in nvme_disable_ctrl()
2466 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, 0, in nvme_disable_ctrl()
2467 (NVME_CAP_TIMEOUT(ctrl->cap) + 1) / 2, "reset"); in nvme_disable_ctrl()
2471 int nvme_enable_ctrl(struct nvme_ctrl *ctrl) in nvme_enable_ctrl() argument
2477 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2479 dev_err(ctrl->device, "Reading CAP failed (%d)\n", ret); in nvme_enable_ctrl()
2482 dev_page_min = NVME_CAP_MPSMIN(ctrl->cap) + 12; in nvme_enable_ctrl()
2485 dev_err(ctrl->device, in nvme_enable_ctrl()
2491 if (NVME_CAP_CSS(ctrl->cap) & NVME_CAP_CSS_CSI) in nvme_enable_ctrl()
2492 ctrl->ctrl_config = NVME_CC_CSS_CSI; in nvme_enable_ctrl()
2494 ctrl->ctrl_config = NVME_CC_CSS_NVM; in nvme_enable_ctrl()
2502 ctrl->ctrl_config &= ~NVME_CC_CRIME; in nvme_enable_ctrl()
2504 ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT; in nvme_enable_ctrl()
2505 ctrl->ctrl_config |= NVME_CC_AMS_RR | NVME_CC_SHN_NONE; in nvme_enable_ctrl()
2506 ctrl->ctrl_config |= NVME_CC_IOSQES | NVME_CC_IOCQES; in nvme_enable_ctrl()
2507 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2512 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2516 timeout = NVME_CAP_TIMEOUT(ctrl->cap); in nvme_enable_ctrl()
2517 if (ctrl->cap & NVME_CAP_CRMS_CRWMS) { in nvme_enable_ctrl()
2520 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CRTO, &crto); in nvme_enable_ctrl()
2522 dev_err(ctrl->device, "Reading CRTO failed (%d)\n", in nvme_enable_ctrl()
2535 dev_warn_once(ctrl->device, "bad crto:%x cap:%llx\n", in nvme_enable_ctrl()
2536 crto, ctrl->cap); in nvme_enable_ctrl()
2541 ctrl->ctrl_config |= NVME_CC_ENABLE; in nvme_enable_ctrl()
2542 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2545 return nvme_wait_ready(ctrl, NVME_CSTS_RDY, NVME_CSTS_RDY, in nvme_enable_ctrl()
2550 static int nvme_configure_timestamp(struct nvme_ctrl *ctrl) in nvme_configure_timestamp() argument
2555 if (!(ctrl->oncs & NVME_CTRL_ONCS_TIMESTAMP)) in nvme_configure_timestamp()
2559 ret = nvme_set_features(ctrl, NVME_FEAT_TIMESTAMP, 0, &ts, sizeof(ts), in nvme_configure_timestamp()
2562 dev_warn_once(ctrl->device, in nvme_configure_timestamp()
2567 static int nvme_configure_host_options(struct nvme_ctrl *ctrl) in nvme_configure_host_options() argument
2574 if (ctrl->crdt[0]) in nvme_configure_host_options()
2576 if (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) in nvme_configure_host_options()
2588 ret = nvme_set_features(ctrl, NVME_FEAT_HOST_BEHAVIOR, 0, in nvme_configure_host_options()
2648 static int nvme_configure_apst(struct nvme_ctrl *ctrl) in nvme_configure_apst() argument
2663 if (!ctrl->apsta) in nvme_configure_apst()
2666 if (ctrl->npss > 31) { in nvme_configure_apst()
2667 dev_warn(ctrl->device, "NPSS is invalid; not using APST\n"); in nvme_configure_apst()
2675 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) { in nvme_configure_apst()
2677 dev_dbg(ctrl->device, "APST disabled\n"); in nvme_configure_apst()
2687 for (state = (int)ctrl->npss; state >= 0; state--) { in nvme_configure_apst()
2697 if (state == ctrl->npss && in nvme_configure_apst()
2698 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) in nvme_configure_apst()
2705 if (!(ctrl->psd[state].flags & NVME_PS_FLAGS_NON_OP_STATE)) in nvme_configure_apst()
2708 exit_latency_us = (u64)le32_to_cpu(ctrl->psd[state].exit_lat); in nvme_configure_apst()
2709 if (exit_latency_us > ctrl->ps_max_latency_us) in nvme_configure_apst()
2713 le32_to_cpu(ctrl->psd[state].entry_lat); in nvme_configure_apst()
2738 dev_dbg(ctrl->device, "APST enabled but no non-operational states are available\n"); in nvme_configure_apst()
2740 …dev_dbg(ctrl->device, "APST enabled: max PS = %d, max round-trip latency = %lluus, table = %*phN\n… in nvme_configure_apst()
2745 ret = nvme_set_features(ctrl, NVME_FEAT_AUTO_PST, apste, in nvme_configure_apst()
2748 dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret); in nvme_configure_apst()
2755 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_set_latency_tolerance() local
2768 if (ctrl->ps_max_latency_us != latency) { in nvme_set_latency_tolerance()
2769 ctrl->ps_max_latency_us = latency; in nvme_set_latency_tolerance()
2770 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_set_latency_tolerance()
2771 nvme_configure_apst(ctrl); in nvme_set_latency_tolerance()
2866 static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ctrl, in nvme_init_subnqn() argument
2872 if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) { in nvme_init_subnqn()
2879 if (ctrl->vs >= NVME_VS(1, 2, 1)) in nvme_init_subnqn()
2880 dev_warn(ctrl->device, "missing or invalid SUBNQN field.\n"); in nvme_init_subnqn()
2955 static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) in nvme_discovery_ctrl() argument
2957 return ctrl->opts && ctrl->opts->discovery_nqn; in nvme_discovery_ctrl()
2961 struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_validate_cntlid() argument
2971 if (tmp->cntlid == ctrl->cntlid) { in nvme_validate_cntlid()
2972 dev_err(ctrl->device, in nvme_validate_cntlid()
2974 ctrl->cntlid, dev_name(tmp->device), in nvme_validate_cntlid()
2980 nvme_discovery_ctrl(ctrl)) in nvme_validate_cntlid()
2983 dev_err(ctrl->device, in nvme_validate_cntlid()
2991 static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_subsystem() argument
3005 nvme_init_subnqn(subsys, ctrl, id); in nvme_init_subsystem()
3018 if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) { in nvme_init_subsystem()
3019 dev_err(ctrl->device, in nvme_init_subsystem()
3031 dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); in nvme_init_subsystem()
3040 if (!nvme_validate_cntlid(subsys, ctrl, id)) { in nvme_init_subsystem()
3047 dev_err(ctrl->device, in nvme_init_subsystem()
3056 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, in nvme_init_subsystem()
3057 dev_name(ctrl->device)); in nvme_init_subsystem()
3059 dev_err(ctrl->device, in nvme_init_subsystem()
3065 subsys->instance = ctrl->instance; in nvme_init_subsystem()
3066 ctrl->subsys = subsys; in nvme_init_subsystem()
3067 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvme_init_subsystem()
3078 int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, in nvme_get_log() argument
3094 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); in nvme_get_log()
3097 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi, in nvme_get_effects_log() argument
3100 struct nvme_effects_log *old, *cel = xa_load(&ctrl->cels, csi); in nvme_get_effects_log()
3110 ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi, in nvme_get_effects_log()
3117 old = xa_store(&ctrl->cels, csi, cel, GFP_KERNEL); in nvme_get_effects_log()
3127 static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units) in nvme_mps_to_sectors() argument
3129 u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; in nvme_mps_to_sectors()
3136 static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) in nvme_init_non_mdts_limits() argument
3148 if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && in nvme_init_non_mdts_limits()
3149 !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) in nvme_init_non_mdts_limits()
3150 ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; in nvme_init_non_mdts_limits()
3152 ctrl->max_zeroes_sectors = 0; in nvme_init_non_mdts_limits()
3154 if (ctrl->subsys->subtype != NVME_NQN_NVME || in nvme_init_non_mdts_limits()
3155 !nvme_id_cns_ok(ctrl, NVME_ID_CNS_CS_CTRL) || in nvme_init_non_mdts_limits()
3156 test_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags)) in nvme_init_non_mdts_limits()
3167 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_init_non_mdts_limits()
3171 ctrl->dmrl = id->dmrl; in nvme_init_non_mdts_limits()
3172 ctrl->dmrsl = le32_to_cpu(id->dmrsl); in nvme_init_non_mdts_limits()
3174 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); in nvme_init_non_mdts_limits()
3178 set_bit(NVME_CTRL_SKIP_ID_CNS_CS, &ctrl->flags); in nvme_init_non_mdts_limits()
3183 static int nvme_init_effects_log(struct nvme_ctrl *ctrl, in nvme_init_effects_log() argument
3192 old = xa_store(&ctrl->cels, csi, effects, GFP_KERNEL); in nvme_init_effects_log()
3202 static void nvme_init_known_nvm_effects(struct nvme_ctrl *ctrl) in nvme_init_known_nvm_effects() argument
3204 struct nvme_effects_log *log = ctrl->effects; in nvme_init_known_nvm_effects()
3234 static int nvme_init_effects(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_effects() argument
3238 if (ctrl->effects) in nvme_init_effects()
3242 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3247 if (!ctrl->effects) { in nvme_init_effects()
3248 ret = nvme_init_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_effects()
3253 nvme_init_known_nvm_effects(ctrl); in nvme_init_effects()
3257 static int nvme_check_ctrl_fabric_info(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_check_ctrl_fabric_info() argument
3263 if (ctrl->cntlid != le16_to_cpu(id->cntlid)) { in nvme_check_ctrl_fabric_info()
3264 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3266 ctrl->cntlid, le16_to_cpu(id->cntlid)); in nvme_check_ctrl_fabric_info()
3270 if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) { in nvme_check_ctrl_fabric_info()
3271 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3276 if (!nvme_discovery_ctrl(ctrl) && ctrl->ioccsz < 4) { in nvme_check_ctrl_fabric_info()
3277 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3279 ctrl->ioccsz); in nvme_check_ctrl_fabric_info()
3283 if (!nvme_discovery_ctrl(ctrl) && ctrl->iorcsz < 1) { in nvme_check_ctrl_fabric_info()
3284 dev_err(ctrl->device, in nvme_check_ctrl_fabric_info()
3286 ctrl->iorcsz); in nvme_check_ctrl_fabric_info()
3290 if (!ctrl->maxcmd) { in nvme_check_ctrl_fabric_info()
3291 dev_warn(ctrl->device, in nvme_check_ctrl_fabric_info()
3293 ctrl->maxcmd = ctrl->sqsize + 1; in nvme_check_ctrl_fabric_info()
3299 static int nvme_init_identify(struct nvme_ctrl *ctrl) in nvme_init_identify() argument
3307 ret = nvme_identify_ctrl(ctrl, &id); in nvme_init_identify()
3309 dev_err(ctrl->device, "Identify Controller failed (%d)\n", ret); in nvme_init_identify()
3313 if (!(ctrl->ops->flags & NVME_F_FABRICS)) in nvme_init_identify()
3314 ctrl->cntlid = le16_to_cpu(id->cntlid); in nvme_init_identify()
3316 if (!ctrl->identified) { in nvme_init_identify()
3329 ctrl->quirks |= core_quirks[i].quirks; in nvme_init_identify()
3332 ret = nvme_init_subsystem(ctrl, id); in nvme_init_identify()
3336 ret = nvme_init_effects(ctrl, id); in nvme_init_identify()
3340 memcpy(ctrl->subsys->firmware_rev, id->fr, in nvme_init_identify()
3341 sizeof(ctrl->subsys->firmware_rev)); in nvme_init_identify()
3343 if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) { in nvme_init_identify()
3344 …dev_warn(ctrl->device, "forcibly allowing all power states due to nvme_core.force_apst -- use at y… in nvme_init_identify()
3345 ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS; in nvme_init_identify()
3348 ctrl->crdt[0] = le16_to_cpu(id->crdt1); in nvme_init_identify()
3349 ctrl->crdt[1] = le16_to_cpu(id->crdt2); in nvme_init_identify()
3350 ctrl->crdt[2] = le16_to_cpu(id->crdt3); in nvme_init_identify()
3352 ctrl->oacs = le16_to_cpu(id->oacs); in nvme_init_identify()
3353 ctrl->oncs = le16_to_cpu(id->oncs); in nvme_init_identify()
3354 ctrl->mtfa = le16_to_cpu(id->mtfa); in nvme_init_identify()
3355 ctrl->oaes = le32_to_cpu(id->oaes); in nvme_init_identify()
3356 ctrl->wctemp = le16_to_cpu(id->wctemp); in nvme_init_identify()
3357 ctrl->cctemp = le16_to_cpu(id->cctemp); in nvme_init_identify()
3359 atomic_set(&ctrl->abort_limit, id->acl + 1); in nvme_init_identify()
3360 ctrl->vwc = id->vwc; in nvme_init_identify()
3362 max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); in nvme_init_identify()
3365 ctrl->max_hw_sectors = in nvme_init_identify()
3366 min_not_zero(ctrl->max_hw_sectors, max_hw_sectors); in nvme_init_identify()
3368 lim = queue_limits_start_update(ctrl->admin_q); in nvme_init_identify()
3369 nvme_set_ctrl_limits(ctrl, &lim); in nvme_init_identify()
3370 ret = queue_limits_commit_update(ctrl->admin_q, &lim); in nvme_init_identify()
3374 ctrl->sgls = le32_to_cpu(id->sgls); in nvme_init_identify()
3375 ctrl->kas = le16_to_cpu(id->kas); in nvme_init_identify()
3376 ctrl->max_namespaces = le32_to_cpu(id->mnan); in nvme_init_identify()
3377 ctrl->ctratt = le32_to_cpu(id->ctratt); in nvme_init_identify()
3379 ctrl->cntrltype = id->cntrltype; in nvme_init_identify()
3380 ctrl->dctype = id->dctype; in nvme_init_identify()
3386 ctrl->shutdown_timeout = clamp_t(unsigned int, transition_time, in nvme_init_identify()
3389 if (ctrl->shutdown_timeout != shutdown_timeout) in nvme_init_identify()
3390 dev_info(ctrl->device, in nvme_init_identify()
3392 ctrl->shutdown_timeout); in nvme_init_identify()
3394 ctrl->shutdown_timeout = shutdown_timeout; in nvme_init_identify()
3396 ctrl->npss = id->npss; in nvme_init_identify()
3397 ctrl->apsta = id->apsta; in nvme_init_identify()
3398 prev_apst_enabled = ctrl->apst_enabled; in nvme_init_identify()
3399 if (ctrl->quirks & NVME_QUIRK_NO_APST) { in nvme_init_identify()
3401 …dev_warn(ctrl->device, "forcibly allowing APST due to nvme_core.force_apst -- use at your own risk… in nvme_init_identify()
3402 ctrl->apst_enabled = true; in nvme_init_identify()
3404 ctrl->apst_enabled = false; in nvme_init_identify()
3407 ctrl->apst_enabled = id->apsta; in nvme_init_identify()
3409 memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd)); in nvme_init_identify()
3411 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_init_identify()
3412 ctrl->icdoff = le16_to_cpu(id->icdoff); in nvme_init_identify()
3413 ctrl->ioccsz = le32_to_cpu(id->ioccsz); in nvme_init_identify()
3414 ctrl->iorcsz = le32_to_cpu(id->iorcsz); in nvme_init_identify()
3415 ctrl->maxcmd = le16_to_cpu(id->maxcmd); in nvme_init_identify()
3417 ret = nvme_check_ctrl_fabric_info(ctrl, id); in nvme_init_identify()
3421 ctrl->hmpre = le32_to_cpu(id->hmpre); in nvme_init_identify()
3422 ctrl->hmmin = le32_to_cpu(id->hmmin); in nvme_init_identify()
3423 ctrl->hmminds = le32_to_cpu(id->hmminds); in nvme_init_identify()
3424 ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); in nvme_init_identify()
3427 ret = nvme_mpath_init_identify(ctrl, id); in nvme_init_identify()
3431 if (ctrl->apst_enabled && !prev_apst_enabled) in nvme_init_identify()
3432 dev_pm_qos_expose_latency_tolerance(ctrl->device); in nvme_init_identify()
3433 else if (!ctrl->apst_enabled && prev_apst_enabled) in nvme_init_identify()
3434 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_identify()
3446 int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended) in nvme_init_ctrl_finish() argument
3450 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); in nvme_init_ctrl_finish()
3452 dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); in nvme_init_ctrl_finish()
3456 ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); in nvme_init_ctrl_finish()
3458 if (ctrl->vs >= NVME_VS(1, 1, 0)) in nvme_init_ctrl_finish()
3459 ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); in nvme_init_ctrl_finish()
3461 ret = nvme_init_identify(ctrl); in nvme_init_ctrl_finish()
3465 ret = nvme_configure_apst(ctrl); in nvme_init_ctrl_finish()
3469 ret = nvme_configure_timestamp(ctrl); in nvme_init_ctrl_finish()
3473 ret = nvme_configure_host_options(ctrl); in nvme_init_ctrl_finish()
3477 nvme_configure_opal(ctrl, was_suspended); in nvme_init_ctrl_finish()
3479 if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3484 ret = nvme_hwmon_init(ctrl); in nvme_init_ctrl_finish()
3489 clear_bit(NVME_CTRL_DIRTY_CAPABILITY, &ctrl->flags); in nvme_init_ctrl_finish()
3490 ctrl->identified = true; in nvme_init_ctrl_finish()
3492 nvme_start_keep_alive(ctrl); in nvme_init_ctrl_finish()
3500 struct nvme_ctrl *ctrl = in nvme_dev_open() local
3503 switch (nvme_ctrl_state(ctrl)) { in nvme_dev_open()
3510 nvme_get_ctrl(ctrl); in nvme_dev_open()
3511 if (!try_module_get(ctrl->ops->module)) { in nvme_dev_open()
3512 nvme_put_ctrl(ctrl); in nvme_dev_open()
3516 file->private_data = ctrl; in nvme_dev_open()
3522 struct nvme_ctrl *ctrl = in nvme_dev_release() local
3525 module_put(ctrl->ops->module); in nvme_dev_release()
3526 nvme_put_ctrl(ctrl); in nvme_dev_release()
3539 static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, in nvme_find_ns_head() argument
3544 lockdep_assert_held(&ctrl->subsys->lock); in nvme_find_ns_head()
3546 list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { in nvme_find_ns_head()
3552 if (h->ns_id != nsid || !nvme_is_unique_nsid(ctrl, h)) in nvme_find_ns_head()
3642 ns->cdev_device.parent = ns->ctrl->device; in nvme_add_ns_cdev()
3644 ns->ctrl->instance, ns->head->instance); in nvme_add_ns_cdev()
3649 ns->ctrl->ops->module); in nvme_add_ns_cdev()
3652 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, in nvme_alloc_ns_head() argument
3666 ret = ida_alloc_min(&ctrl->subsys->ns_ida, 1, GFP_KERNEL); in nvme_alloc_ns_head()
3674 head->subsys = ctrl->subsys; in nvme_alloc_ns_head()
3683 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); in nvme_alloc_ns_head()
3687 head->effects = ctrl->effects; in nvme_alloc_ns_head()
3689 ret = nvme_mpath_alloc_disk(ctrl, head); in nvme_alloc_ns_head()
3693 list_add_tail(&head->entry, &ctrl->subsys->nsheads); in nvme_alloc_ns_head()
3695 kref_get(&ctrl->subsys->ref); in nvme_alloc_ns_head()
3701 ida_free(&ctrl->subsys->ns_ida, head->instance); in nvme_alloc_ns_head()
3738 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ns_head() local
3742 ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3760 nvme_print_device_info(ctrl); in nvme_init_ns_head()
3761 if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ in nvme_init_ns_head()
3762 ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && in nvme_init_ns_head()
3764 dev_err(ctrl->device, in nvme_init_ns_head()
3770 dev_err(ctrl->device, in nvme_init_ns_head()
3772 dev_err(ctrl->device, in nvme_init_ns_head()
3777 ctrl->quirks |= NVME_QUIRK_BOGUS_NID; in nvme_init_ns_head()
3780 mutex_lock(&ctrl->subsys->lock); in nvme_init_ns_head()
3781 head = nvme_find_ns_head(ctrl, info->nsid); in nvme_init_ns_head()
3783 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
3785 dev_err(ctrl->device, in nvme_init_ns_head()
3790 head = nvme_alloc_ns_head(ctrl, info); in nvme_init_ns_head()
3798 dev_err(ctrl->device, in nvme_init_ns_head()
3804 dev_err(ctrl->device, in nvme_init_ns_head()
3811 dev_warn(ctrl->device, in nvme_init_ns_head()
3814 dev_warn_once(ctrl->device, in nvme_init_ns_head()
3821 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3827 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
3831 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_find_get_ns() argument
3836 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_find_get_ns()
3837 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_find_get_ns()
3838 srcu_read_lock_held(&ctrl->srcu)) { in nvme_find_get_ns()
3848 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_find_get_ns()
3860 list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) { in nvme_ns_add_to_ctrl_list()
3866 list_add_rcu(&ns->list, &ns->ctrl->namespaces); in nvme_ns_add_to_ctrl_list()
3869 static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) in nvme_alloc_ns() argument
3874 int node = ctrl->numa_node; in nvme_alloc_ns()
3880 if (ctrl->opts && ctrl->opts->data_digest) in nvme_alloc_ns()
3882 if (ctrl->ops->supports_pci_p2pdma && in nvme_alloc_ns()
3883 ctrl->ops->supports_pci_p2pdma(ctrl)) in nvme_alloc_ns()
3886 disk = blk_mq_alloc_disk(ctrl->tagset, &lim, ns); in nvme_alloc_ns()
3894 ns->ctrl = ctrl; in nvme_alloc_ns()
3912 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3913 ctrl->instance, ns->head->instance); in nvme_alloc_ns()
3916 sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
3919 sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, in nvme_alloc_ns()
3926 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3931 if (test_bit(NVME_CTRL_FROZEN, &ctrl->flags)) { in nvme_alloc_ns()
3932 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3936 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3937 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3938 nvme_get_ctrl(ctrl); in nvme_alloc_ns()
3940 if (device_add_disk(ctrl->device, ns->disk, nvme_ns_attr_groups)) in nvme_alloc_ns()
3959 nvme_put_ctrl(ctrl); in nvme_alloc_ns()
3960 mutex_lock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3962 mutex_unlock(&ctrl->namespaces_lock); in nvme_alloc_ns()
3963 synchronize_srcu(&ctrl->srcu); in nvme_alloc_ns()
3965 mutex_lock(&ctrl->subsys->lock); in nvme_alloc_ns()
3969 mutex_unlock(&ctrl->subsys->lock); in nvme_alloc_ns()
3998 mutex_lock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4004 mutex_unlock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4013 mutex_lock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
4015 mutex_unlock(&ns->ctrl->namespaces_lock); in nvme_ns_remove()
4016 synchronize_srcu(&ns->ctrl->srcu); in nvme_ns_remove()
4023 static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) in nvme_ns_remove_by_nsid() argument
4025 struct nvme_ns *ns = nvme_find_get_ns(ctrl, nsid); in nvme_ns_remove_by_nsid()
4038 dev_err(ns->ctrl->device, in nvme_validate_ns()
4055 static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_scan_ns() argument
4061 if (nvme_identify_ns_descs(ctrl, &info)) in nvme_scan_ns()
4064 if (info.ids.csi != NVME_CSI_NVM && !nvme_multi_css(ctrl)) { in nvme_scan_ns()
4065 dev_warn(ctrl->device, in nvme_scan_ns()
4075 if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || in nvme_scan_ns()
4077 ret = nvme_ns_info_from_id_cs_indep(ctrl, &info); in nvme_scan_ns()
4079 ret = nvme_ns_info_from_identify(ctrl, &info); in nvme_scan_ns()
4082 nvme_ns_remove_by_nsid(ctrl, nsid); in nvme_scan_ns()
4091 ns = nvme_find_get_ns(ctrl, nsid); in nvme_scan_ns()
4096 nvme_alloc_ns(ctrl, &info); in nvme_scan_ns()
4112 struct nvme_ctrl *ctrl; member
4126 nvme_scan_ns(scan_info->ctrl, nsid); in nvme_scan_ns_async()
4129 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, in nvme_remove_invalid_namespaces() argument
4135 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4136 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { in nvme_remove_invalid_namespaces()
4139 synchronize_srcu(&ctrl->srcu); in nvme_remove_invalid_namespaces()
4143 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_invalid_namespaces()
4149 static int nvme_scan_ns_list(struct nvme_ctrl *ctrl) in nvme_scan_ns_list() argument
4162 scan_info.ctrl = ctrl; in nvme_scan_ns_list()
4171 ret = nvme_submit_sync_cmd(ctrl->admin_q, &cmd, ns_list, in nvme_scan_ns_list()
4174 dev_warn(ctrl->device, in nvme_scan_ns_list()
4188 nvme_ns_remove_by_nsid(ctrl, prev); in nvme_scan_ns_list()
4193 nvme_remove_invalid_namespaces(ctrl, prev); in nvme_scan_ns_list()
4200 static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl) in nvme_scan_ns_sequential() argument
4205 if (nvme_identify_ctrl(ctrl, &id)) in nvme_scan_ns_sequential()
4211 nvme_scan_ns(ctrl, i); in nvme_scan_ns_sequential()
4213 nvme_remove_invalid_namespaces(ctrl, nn); in nvme_scan_ns_sequential()
4216 static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl) in nvme_clear_changed_ns_log() argument
4232 error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_CHANGED_NS, 0, in nvme_clear_changed_ns_log()
4235 dev_warn(ctrl->device, in nvme_clear_changed_ns_log()
4243 struct nvme_ctrl *ctrl = in nvme_scan_work() local
4248 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE || !ctrl->tagset) in nvme_scan_work()
4258 ret = nvme_init_non_mdts_limits(ctrl); in nvme_scan_work()
4260 dev_warn(ctrl->device, in nvme_scan_work()
4265 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { in nvme_scan_work()
4266 dev_info(ctrl->device, "rescanning namespaces.\n"); in nvme_scan_work()
4267 nvme_clear_changed_ns_log(ctrl); in nvme_scan_work()
4270 mutex_lock(&ctrl->scan_lock); in nvme_scan_work()
4271 if (!nvme_id_cns_ok(ctrl, NVME_ID_CNS_NS_ACTIVE_LIST)) { in nvme_scan_work()
4272 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4279 ret = nvme_scan_ns_list(ctrl); in nvme_scan_work()
4281 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4283 mutex_unlock(&ctrl->scan_lock); in nvme_scan_work()
4286 if (test_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) in nvme_scan_work()
4287 nvme_queue_scan(ctrl); in nvme_scan_work()
4289 else if (ctrl->ana_log_buf) in nvme_scan_work()
4291 queue_work(nvme_wq, &ctrl->ana_work); in nvme_scan_work()
4300 void nvme_remove_namespaces(struct nvme_ctrl *ctrl) in nvme_remove_namespaces() argument
4310 nvme_mpath_clear_ctrl_paths(ctrl); in nvme_remove_namespaces()
4316 nvme_unquiesce_io_queues(ctrl); in nvme_remove_namespaces()
4319 flush_work(&ctrl->scan_work); in nvme_remove_namespaces()
4327 if (nvme_ctrl_state(ctrl) == NVME_CTRL_DEAD) in nvme_remove_namespaces()
4328 nvme_mark_namespaces_dead(ctrl); in nvme_remove_namespaces()
4331 nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); in nvme_remove_namespaces()
4333 mutex_lock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4334 list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu); in nvme_remove_namespaces()
4335 mutex_unlock(&ctrl->namespaces_lock); in nvme_remove_namespaces()
4336 synchronize_srcu(&ctrl->srcu); in nvme_remove_namespaces()
4345 const struct nvme_ctrl *ctrl = in nvme_class_uevent() local
4347 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_class_uevent()
4350 ret = add_uevent_var(env, "NVME_TRTYPE=%s", ctrl->ops->name); in nvme_class_uevent()
4375 static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata) in nvme_change_uevent() argument
4379 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_change_uevent()
4382 static void nvme_aen_uevent(struct nvme_ctrl *ctrl) in nvme_aen_uevent() argument
4385 u32 aen_result = ctrl->aen_result; in nvme_aen_uevent()
4387 ctrl->aen_result = 0; in nvme_aen_uevent()
4394 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_aen_uevent()
4400 struct nvme_ctrl *ctrl = in nvme_async_event_work() local
4403 nvme_aen_uevent(ctrl); in nvme_async_event_work()
4410 if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) in nvme_async_event_work()
4411 ctrl->ops->submit_async_event(ctrl); in nvme_async_event_work()
4414 static bool nvme_ctrl_pp_status(struct nvme_ctrl *ctrl) in nvme_ctrl_pp_status() argument
4419 if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) in nvme_ctrl_pp_status()
4425 return ((ctrl->ctrl_config & NVME_CC_ENABLE) && (csts & NVME_CSTS_PP)); in nvme_ctrl_pp_status()
4428 static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl) in nvme_get_fw_slot_info() argument
4437 if (nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_FW_SLOT, 0, NVME_CSI_NVM, in nvme_get_fw_slot_info()
4439 dev_warn(ctrl->device, "Get FW SLOT INFO log error\n"); in nvme_get_fw_slot_info()
4446 dev_info(ctrl->device, in nvme_get_fw_slot_info()
4451 memcpy(ctrl->subsys->firmware_rev, &log->frs[cur_fw_slot - 1], in nvme_get_fw_slot_info()
4452 sizeof(ctrl->subsys->firmware_rev)); in nvme_get_fw_slot_info()
4460 struct nvme_ctrl *ctrl = container_of(work, in nvme_fw_act_work() local
4464 nvme_auth_stop(ctrl); in nvme_fw_act_work()
4466 if (ctrl->mtfa) in nvme_fw_act_work()
4468 msecs_to_jiffies(ctrl->mtfa * 100); in nvme_fw_act_work()
4473 nvme_quiesce_io_queues(ctrl); in nvme_fw_act_work()
4474 while (nvme_ctrl_pp_status(ctrl)) { in nvme_fw_act_work()
4476 dev_warn(ctrl->device, in nvme_fw_act_work()
4478 nvme_try_sched_reset(ctrl); in nvme_fw_act_work()
4484 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING) || in nvme_fw_act_work()
4485 !nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) in nvme_fw_act_work()
4488 nvme_unquiesce_io_queues(ctrl); in nvme_fw_act_work()
4490 nvme_get_fw_slot_info(ctrl); in nvme_fw_act_work()
4492 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_fw_act_work()
4505 static bool nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result) in nvme_handle_aen_notice() argument
4512 set_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events); in nvme_handle_aen_notice()
4513 nvme_queue_scan(ctrl); in nvme_handle_aen_notice()
4521 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) { in nvme_handle_aen_notice()
4523 queue_work(nvme_wq, &ctrl->fw_act_work); in nvme_handle_aen_notice()
4528 if (!ctrl->ana_log_buf) in nvme_handle_aen_notice()
4530 queue_work(nvme_wq, &ctrl->ana_work); in nvme_handle_aen_notice()
4534 ctrl->aen_result = result; in nvme_handle_aen_notice()
4537 dev_warn(ctrl->device, "async event result %08x\n", result); in nvme_handle_aen_notice()
4542 static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl) in nvme_handle_aer_persistent_error() argument
4544 dev_warn(ctrl->device, in nvme_handle_aer_persistent_error()
4546 nvme_reset_ctrl(ctrl); in nvme_handle_aer_persistent_error()
4549 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, in nvme_complete_async_event() argument
4560 trace_nvme_async_event(ctrl, result); in nvme_complete_async_event()
4563 requeue = nvme_handle_aen_notice(ctrl, result); in nvme_complete_async_event()
4571 nvme_handle_aer_persistent_error(ctrl); in nvme_complete_async_event()
4578 ctrl->aen_result = result; in nvme_complete_async_event()
4585 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_complete_async_event()
4589 int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_admin_tag_set() argument
4598 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_admin_tag_set()
4601 set->numa_node = ctrl->numa_node; in nvme_alloc_admin_tag_set()
4603 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_admin_tag_set()
4606 set->driver_data = ctrl; in nvme_alloc_admin_tag_set()
4613 ctrl->admin_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_admin_tag_set()
4614 if (IS_ERR(ctrl->admin_q)) { in nvme_alloc_admin_tag_set()
4615 ret = PTR_ERR(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4619 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_admin_tag_set()
4620 ctrl->fabrics_q = blk_mq_alloc_queue(set, NULL, NULL); in nvme_alloc_admin_tag_set()
4621 if (IS_ERR(ctrl->fabrics_q)) { in nvme_alloc_admin_tag_set()
4622 ret = PTR_ERR(ctrl->fabrics_q); in nvme_alloc_admin_tag_set()
4627 ctrl->admin_tagset = set; in nvme_alloc_admin_tag_set()
4631 blk_mq_destroy_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4632 blk_put_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4635 ctrl->admin_q = NULL; in nvme_alloc_admin_tag_set()
4636 ctrl->fabrics_q = NULL; in nvme_alloc_admin_tag_set()
4641 void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_admin_tag_set() argument
4647 nvme_stop_keep_alive(ctrl); in nvme_remove_admin_tag_set()
4648 blk_mq_destroy_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4649 blk_put_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4650 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_admin_tag_set()
4651 blk_mq_destroy_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4652 blk_put_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4654 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_remove_admin_tag_set()
4658 int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_io_tag_set() argument
4666 set->queue_depth = min_t(unsigned, ctrl->sqsize, BLK_MQ_MAX_DEPTH - 1); in nvme_alloc_io_tag_set()
4671 if (ctrl->quirks & NVME_QUIRK_SHARED_TAGS) in nvme_alloc_io_tag_set()
4673 else if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_io_tag_set()
4676 set->numa_node = ctrl->numa_node; in nvme_alloc_io_tag_set()
4678 if (ctrl->ops->flags & NVME_F_BLOCKING) in nvme_alloc_io_tag_set()
4681 set->driver_data = ctrl; in nvme_alloc_io_tag_set()
4682 set->nr_hw_queues = ctrl->queue_count - 1; in nvme_alloc_io_tag_set()
4689 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_io_tag_set()
4694 ctrl->connect_q = blk_mq_alloc_queue(set, &lim, NULL); in nvme_alloc_io_tag_set()
4695 if (IS_ERR(ctrl->connect_q)) { in nvme_alloc_io_tag_set()
4696 ret = PTR_ERR(ctrl->connect_q); in nvme_alloc_io_tag_set()
4701 ctrl->tagset = set; in nvme_alloc_io_tag_set()
4706 ctrl->connect_q = NULL; in nvme_alloc_io_tag_set()
4711 void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_io_tag_set() argument
4713 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_remove_io_tag_set()
4714 blk_mq_destroy_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4715 blk_put_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4717 blk_mq_free_tag_set(ctrl->tagset); in nvme_remove_io_tag_set()
4721 void nvme_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_stop_ctrl() argument
4723 nvme_mpath_stop(ctrl); in nvme_stop_ctrl()
4724 nvme_auth_stop(ctrl); in nvme_stop_ctrl()
4725 nvme_stop_failfast_work(ctrl); in nvme_stop_ctrl()
4726 flush_work(&ctrl->async_event_work); in nvme_stop_ctrl()
4727 cancel_work_sync(&ctrl->fw_act_work); in nvme_stop_ctrl()
4728 if (ctrl->ops->stop_ctrl) in nvme_stop_ctrl()
4729 ctrl->ops->stop_ctrl(ctrl); in nvme_stop_ctrl()
4733 void nvme_start_ctrl(struct nvme_ctrl *ctrl) in nvme_start_ctrl() argument
4735 nvme_enable_aen(ctrl); in nvme_start_ctrl()
4743 if (test_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags) && in nvme_start_ctrl()
4744 nvme_discovery_ctrl(ctrl)) in nvme_start_ctrl()
4745 nvme_change_uevent(ctrl, "NVME_EVENT=rediscover"); in nvme_start_ctrl()
4747 if (ctrl->queue_count > 1) { in nvme_start_ctrl()
4748 nvme_queue_scan(ctrl); in nvme_start_ctrl()
4749 nvme_unquiesce_io_queues(ctrl); in nvme_start_ctrl()
4750 nvme_mpath_update(ctrl); in nvme_start_ctrl()
4753 nvme_change_uevent(ctrl, "NVME_EVENT=connected"); in nvme_start_ctrl()
4754 set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags); in nvme_start_ctrl()
4758 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) in nvme_uninit_ctrl() argument
4760 nvme_stop_keep_alive(ctrl); in nvme_uninit_ctrl()
4761 nvme_hwmon_exit(ctrl); in nvme_uninit_ctrl()
4762 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_uninit_ctrl()
4763 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_uninit_ctrl()
4764 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_uninit_ctrl()
4765 nvme_put_ctrl(ctrl); in nvme_uninit_ctrl()
4769 static void nvme_free_cels(struct nvme_ctrl *ctrl) in nvme_free_cels() argument
4774 xa_for_each(&ctrl->cels, i, cel) { in nvme_free_cels()
4775 xa_erase(&ctrl->cels, i); in nvme_free_cels()
4779 xa_destroy(&ctrl->cels); in nvme_free_cels()
4784 struct nvme_ctrl *ctrl = in nvme_free_ctrl() local
4786 struct nvme_subsystem *subsys = ctrl->subsys; in nvme_free_ctrl()
4788 if (!subsys || ctrl->instance != subsys->instance) in nvme_free_ctrl()
4789 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_free_ctrl()
4790 nvme_free_cels(ctrl); in nvme_free_ctrl()
4791 nvme_mpath_uninit(ctrl); in nvme_free_ctrl()
4792 cleanup_srcu_struct(&ctrl->srcu); in nvme_free_ctrl()
4793 nvme_auth_stop(ctrl); in nvme_free_ctrl()
4794 nvme_auth_free(ctrl); in nvme_free_ctrl()
4795 __free_page(ctrl->discard_page); in nvme_free_ctrl()
4796 free_opal_dev(ctrl->opal_dev); in nvme_free_ctrl()
4800 list_del(&ctrl->subsys_entry); in nvme_free_ctrl()
4801 sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device)); in nvme_free_ctrl()
4805 ctrl->ops->free_ctrl(ctrl); in nvme_free_ctrl()
4819 int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, in nvme_init_ctrl() argument
4824 WRITE_ONCE(ctrl->state, NVME_CTRL_NEW); in nvme_init_ctrl()
4825 ctrl->passthru_err_log_enabled = false; in nvme_init_ctrl()
4826 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_init_ctrl()
4827 spin_lock_init(&ctrl->lock); in nvme_init_ctrl()
4828 mutex_init(&ctrl->namespaces_lock); in nvme_init_ctrl()
4830 ret = init_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4834 mutex_init(&ctrl->scan_lock); in nvme_init_ctrl()
4835 INIT_LIST_HEAD(&ctrl->namespaces); in nvme_init_ctrl()
4836 xa_init(&ctrl->cels); in nvme_init_ctrl()
4837 ctrl->dev = dev; in nvme_init_ctrl()
4838 ctrl->ops = ops; in nvme_init_ctrl()
4839 ctrl->quirks = quirks; in nvme_init_ctrl()
4840 ctrl->numa_node = NUMA_NO_NODE; in nvme_init_ctrl()
4841 INIT_WORK(&ctrl->scan_work, nvme_scan_work); in nvme_init_ctrl()
4842 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); in nvme_init_ctrl()
4843 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); in nvme_init_ctrl()
4844 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); in nvme_init_ctrl()
4845 init_waitqueue_head(&ctrl->state_wq); in nvme_init_ctrl()
4847 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); in nvme_init_ctrl()
4848 INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); in nvme_init_ctrl()
4849 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); in nvme_init_ctrl()
4850 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; in nvme_init_ctrl()
4851 ctrl->ka_last_check_time = jiffies; in nvme_init_ctrl()
4855 ctrl->discard_page = alloc_page(GFP_KERNEL); in nvme_init_ctrl()
4856 if (!ctrl->discard_page) { in nvme_init_ctrl()
4864 ctrl->instance = ret; in nvme_init_ctrl()
4866 ret = nvme_auth_init_ctrl(ctrl); in nvme_init_ctrl()
4870 nvme_mpath_init_ctrl(ctrl); in nvme_init_ctrl()
4872 device_initialize(&ctrl->ctrl_device); in nvme_init_ctrl()
4873 ctrl->device = &ctrl->ctrl_device; in nvme_init_ctrl()
4874 ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt), in nvme_init_ctrl()
4875 ctrl->instance); in nvme_init_ctrl()
4876 ctrl->device->class = &nvme_class; in nvme_init_ctrl()
4877 ctrl->device->parent = ctrl->dev; in nvme_init_ctrl()
4879 ctrl->device->groups = ops->dev_attr_groups; in nvme_init_ctrl()
4881 ctrl->device->groups = nvme_dev_attr_groups; in nvme_init_ctrl()
4882 ctrl->device->release = nvme_free_ctrl; in nvme_init_ctrl()
4883 dev_set_drvdata(ctrl->device, ctrl); in nvme_init_ctrl()
4888 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_init_ctrl()
4890 if (ctrl->discard_page) in nvme_init_ctrl()
4891 __free_page(ctrl->discard_page); in nvme_init_ctrl()
4892 cleanup_srcu_struct(&ctrl->srcu); in nvme_init_ctrl()
4901 int nvme_add_ctrl(struct nvme_ctrl *ctrl) in nvme_add_ctrl() argument
4905 ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance); in nvme_add_ctrl()
4909 cdev_init(&ctrl->cdev, &nvme_dev_fops); in nvme_add_ctrl()
4910 ctrl->cdev.owner = ctrl->ops->module; in nvme_add_ctrl()
4911 ret = cdev_device_add(&ctrl->cdev, ctrl->device); in nvme_add_ctrl()
4919 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; in nvme_add_ctrl()
4920 dev_pm_qos_update_user_latency_tolerance(ctrl->device, in nvme_add_ctrl()
4923 nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); in nvme_add_ctrl()
4924 nvme_get_ctrl(ctrl); in nvme_add_ctrl()
4931 void nvme_mark_namespaces_dead(struct nvme_ctrl *ctrl) in nvme_mark_namespaces_dead() argument
4936 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_mark_namespaces_dead()
4937 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_mark_namespaces_dead()
4938 srcu_read_lock_held(&ctrl->srcu)) in nvme_mark_namespaces_dead()
4940 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_mark_namespaces_dead()
4944 void nvme_unfreeze(struct nvme_ctrl *ctrl) in nvme_unfreeze() argument
4949 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_unfreeze()
4950 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_unfreeze()
4951 srcu_read_lock_held(&ctrl->srcu)) in nvme_unfreeze()
4953 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_unfreeze()
4954 clear_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_unfreeze()
4958 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout) in nvme_wait_freeze_timeout() argument
4963 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze_timeout()
4964 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze_timeout()
4965 srcu_read_lock_held(&ctrl->srcu)) { in nvme_wait_freeze_timeout()
4970 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze_timeout()
4975 void nvme_wait_freeze(struct nvme_ctrl *ctrl) in nvme_wait_freeze() argument
4980 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_wait_freeze()
4981 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_wait_freeze()
4982 srcu_read_lock_held(&ctrl->srcu)) in nvme_wait_freeze()
4984 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_wait_freeze()
4988 void nvme_start_freeze(struct nvme_ctrl *ctrl) in nvme_start_freeze() argument
4993 set_bit(NVME_CTRL_FROZEN, &ctrl->flags); in nvme_start_freeze()
4994 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_start_freeze()
4995 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_start_freeze()
4996 srcu_read_lock_held(&ctrl->srcu)) in nvme_start_freeze()
4998 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_start_freeze()
5002 void nvme_quiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_quiesce_io_queues() argument
5004 if (!ctrl->tagset) in nvme_quiesce_io_queues()
5006 if (!test_and_set_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_quiesce_io_queues()
5007 blk_mq_quiesce_tagset(ctrl->tagset); in nvme_quiesce_io_queues()
5009 blk_mq_wait_quiesce_done(ctrl->tagset); in nvme_quiesce_io_queues()
5013 void nvme_unquiesce_io_queues(struct nvme_ctrl *ctrl) in nvme_unquiesce_io_queues() argument
5015 if (!ctrl->tagset) in nvme_unquiesce_io_queues()
5017 if (test_and_clear_bit(NVME_CTRL_STOPPED, &ctrl->flags)) in nvme_unquiesce_io_queues()
5018 blk_mq_unquiesce_tagset(ctrl->tagset); in nvme_unquiesce_io_queues()
5022 void nvme_quiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_quiesce_admin_queue() argument
5024 if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_quiesce_admin_queue()
5025 blk_mq_quiesce_queue(ctrl->admin_q); in nvme_quiesce_admin_queue()
5027 blk_mq_wait_quiesce_done(ctrl->admin_q->tag_set); in nvme_quiesce_admin_queue()
5031 void nvme_unquiesce_admin_queue(struct nvme_ctrl *ctrl) in nvme_unquiesce_admin_queue() argument
5033 if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_unquiesce_admin_queue()
5034 blk_mq_unquiesce_queue(ctrl->admin_q); in nvme_unquiesce_admin_queue()
5038 void nvme_sync_io_queues(struct nvme_ctrl *ctrl) in nvme_sync_io_queues() argument
5043 srcu_idx = srcu_read_lock(&ctrl->srcu); in nvme_sync_io_queues()
5044 list_for_each_entry_srcu(ns, &ctrl->namespaces, list, in nvme_sync_io_queues()
5045 srcu_read_lock_held(&ctrl->srcu)) in nvme_sync_io_queues()
5047 srcu_read_unlock(&ctrl->srcu, srcu_idx); in nvme_sync_io_queues()
5051 void nvme_sync_queues(struct nvme_ctrl *ctrl) in nvme_sync_queues() argument
5053 nvme_sync_io_queues(ctrl); in nvme_sync_queues()
5054 if (ctrl->admin_q) in nvme_sync_queues()
5055 blk_sync_queue(ctrl->admin_q); in nvme_sync_queues()