Lines Matching full:ctrl

123 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
125 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl,
128 void nvme_queue_scan(struct nvme_ctrl *ctrl) in nvme_queue_scan() argument
133 if (ctrl->state == NVME_CTRL_LIVE && ctrl->tagset) in nvme_queue_scan()
134 queue_work(nvme_wq, &ctrl->scan_work); in nvme_queue_scan()
143 int nvme_try_sched_reset(struct nvme_ctrl *ctrl) in nvme_try_sched_reset() argument
145 if (ctrl->state != NVME_CTRL_RESETTING) in nvme_try_sched_reset()
147 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_try_sched_reset()
155 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_failfast_work() local
158 if (ctrl->state != NVME_CTRL_CONNECTING) in nvme_failfast_work()
161 set_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_failfast_work()
162 dev_info(ctrl->device, "failfast expired\n"); in nvme_failfast_work()
163 nvme_kick_requeue_lists(ctrl); in nvme_failfast_work()
166 static inline void nvme_start_failfast_work(struct nvme_ctrl *ctrl) in nvme_start_failfast_work() argument
168 if (!ctrl->opts || ctrl->opts->fast_io_fail_tmo == -1) in nvme_start_failfast_work()
171 schedule_delayed_work(&ctrl->failfast_work, in nvme_start_failfast_work()
172 ctrl->opts->fast_io_fail_tmo * HZ); in nvme_start_failfast_work()
175 static inline void nvme_stop_failfast_work(struct nvme_ctrl *ctrl) in nvme_stop_failfast_work() argument
177 if (!ctrl->opts) in nvme_stop_failfast_work()
180 cancel_delayed_work_sync(&ctrl->failfast_work); in nvme_stop_failfast_work()
181 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_stop_failfast_work()
185 int nvme_reset_ctrl(struct nvme_ctrl *ctrl) in nvme_reset_ctrl() argument
187 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) in nvme_reset_ctrl()
189 if (!queue_work(nvme_reset_wq, &ctrl->reset_work)) in nvme_reset_ctrl()
195 int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_reset_ctrl_sync() argument
199 ret = nvme_reset_ctrl(ctrl); in nvme_reset_ctrl_sync()
201 flush_work(&ctrl->reset_work); in nvme_reset_ctrl_sync()
202 if (ctrl->state != NVME_CTRL_LIVE) in nvme_reset_ctrl_sync()
209 static void nvme_do_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_do_delete_ctrl() argument
211 dev_info(ctrl->device, in nvme_do_delete_ctrl()
212 "Removing ctrl: NQN \"%s\"\n", nvmf_ctrl_subsysnqn(ctrl)); in nvme_do_delete_ctrl()
214 flush_work(&ctrl->reset_work); in nvme_do_delete_ctrl()
215 nvme_stop_ctrl(ctrl); in nvme_do_delete_ctrl()
216 nvme_remove_namespaces(ctrl); in nvme_do_delete_ctrl()
217 ctrl->ops->delete_ctrl(ctrl); in nvme_do_delete_ctrl()
218 nvme_uninit_ctrl(ctrl); in nvme_do_delete_ctrl()
223 struct nvme_ctrl *ctrl = in nvme_delete_ctrl_work() local
226 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_work()
229 int nvme_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_delete_ctrl() argument
231 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl()
233 if (!queue_work(nvme_delete_wq, &ctrl->delete_work)) in nvme_delete_ctrl()
239 static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) in nvme_delete_ctrl_sync() argument
245 nvme_get_ctrl(ctrl); in nvme_delete_ctrl_sync()
246 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING)) in nvme_delete_ctrl_sync()
247 nvme_do_delete_ctrl(ctrl); in nvme_delete_ctrl_sync()
248 nvme_put_ctrl(ctrl); in nvme_delete_ctrl_sync()
301 delay = nvme_req(req)->ctrl->crdt[crd - 1] * 100; in nvme_retry_req()
329 dev_name(nr->ctrl->device), in nvme_log_error()
392 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_complete_rq() local
397 if (ctrl->kas) in nvme_complete_rq()
398 ctrl->comp_seen = true; in nvme_complete_rq()
412 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_complete_rq()
461 void nvme_cancel_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_tagset() argument
463 if (ctrl->tagset) { in nvme_cancel_tagset()
464 blk_mq_tagset_busy_iter(ctrl->tagset, in nvme_cancel_tagset()
465 nvme_cancel_request, ctrl); in nvme_cancel_tagset()
466 blk_mq_tagset_wait_completed_request(ctrl->tagset); in nvme_cancel_tagset()
471 void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl) in nvme_cancel_admin_tagset() argument
473 if (ctrl->admin_tagset) { in nvme_cancel_admin_tagset()
474 blk_mq_tagset_busy_iter(ctrl->admin_tagset, in nvme_cancel_admin_tagset()
475 nvme_cancel_request, ctrl); in nvme_cancel_admin_tagset()
476 blk_mq_tagset_wait_completed_request(ctrl->admin_tagset); in nvme_cancel_admin_tagset()
481 bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl, in nvme_change_ctrl_state() argument
488 spin_lock_irqsave(&ctrl->lock, flags); in nvme_change_ctrl_state()
490 old_state = ctrl->state; in nvme_change_ctrl_state()
558 ctrl->state = new_state; in nvme_change_ctrl_state()
559 wake_up_all(&ctrl->state_wq); in nvme_change_ctrl_state()
562 spin_unlock_irqrestore(&ctrl->lock, flags); in nvme_change_ctrl_state()
566 if (ctrl->state == NVME_CTRL_LIVE) { in nvme_change_ctrl_state()
568 nvme_stop_failfast_work(ctrl); in nvme_change_ctrl_state()
569 nvme_kick_requeue_lists(ctrl); in nvme_change_ctrl_state()
570 } else if (ctrl->state == NVME_CTRL_CONNECTING && in nvme_change_ctrl_state()
572 nvme_start_failfast_work(ctrl); in nvme_change_ctrl_state()
581 static bool nvme_state_terminal(struct nvme_ctrl *ctrl) in nvme_state_terminal() argument
583 switch (ctrl->state) { in nvme_state_terminal()
594 WARN_ONCE(1, "Unhandled ctrl state:%d", ctrl->state); in nvme_state_terminal()
603 bool nvme_wait_reset(struct nvme_ctrl *ctrl) in nvme_wait_reset() argument
605 wait_event(ctrl->state_wq, in nvme_wait_reset()
606 nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING) || in nvme_wait_reset()
607 nvme_state_terminal(ctrl)); in nvme_wait_reset()
608 return ctrl->state == NVME_CTRL_RESETTING; in nvme_wait_reset()
640 nvme_put_ctrl(ns->ctrl); in nvme_free_ns()
692 blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl, in nvme_fail_nonready_command() argument
695 if (ctrl->state != NVME_CTRL_DELETING_NOIO && in nvme_fail_nonready_command()
696 ctrl->state != NVME_CTRL_DELETING && in nvme_fail_nonready_command()
697 ctrl->state != NVME_CTRL_DEAD && in nvme_fail_nonready_command()
698 !test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) && in nvme_fail_nonready_command()
705 bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq, in __nvme_check_ready() argument
718 if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD)) in __nvme_check_ready()
721 if (ctrl->ops->flags & NVME_F_FABRICS) { in __nvme_check_ready()
727 switch (ctrl->state) { in __nvme_check_ready()
775 if (test_and_set_bit_lock(0, &ns->ctrl->discard_page_busy)) in nvme_setup_discard()
778 range = page_address(ns->ctrl->discard_page); in nvme_setup_discard()
794 if (virt_to_page(range) == ns->ctrl->discard_page) in nvme_setup_discard()
795 clear_bit_unlock(0, &ns->ctrl->discard_page_busy); in nvme_setup_discard()
844 if (ns->ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_setup_write_zeroes()
931 struct nvme_ctrl *ctrl = nvme_req(req)->ctrl; in nvme_cleanup_cmd() local
933 if (req->special_vec.bv_page == ctrl->discard_page) in nvme_cleanup_cmd()
934 clear_bit_unlock(0, &ctrl->discard_page_busy); in nvme_cleanup_cmd()
1072 u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opcode) in nvme_command_effects() argument
1080 dev_warn_once(ctrl->device, in nvme_command_effects()
1086 if (ctrl->effects) in nvme_command_effects()
1087 effects = le32_to_cpu(ctrl->effects->acs[opcode]); in nvme_command_effects()
1094 static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, in nvme_passthru_start() argument
1097 u32 effects = nvme_command_effects(ctrl, ns, opcode); in nvme_passthru_start()
1104 mutex_lock(&ctrl->scan_lock); in nvme_passthru_start()
1105 mutex_lock(&ctrl->subsys->lock); in nvme_passthru_start()
1106 nvme_mpath_start_freeze(ctrl->subsys); in nvme_passthru_start()
1107 nvme_mpath_wait_freeze(ctrl->subsys); in nvme_passthru_start()
1108 nvme_start_freeze(ctrl); in nvme_passthru_start()
1109 nvme_wait_freeze(ctrl); in nvme_passthru_start()
1114 void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects, in nvme_passthru_end() argument
1118 nvme_unfreeze(ctrl); in nvme_passthru_end()
1119 nvme_mpath_unfreeze(ctrl->subsys); in nvme_passthru_end()
1120 mutex_unlock(&ctrl->subsys->lock); in nvme_passthru_end()
1121 nvme_remove_invalid_namespaces(ctrl, NVME_NSID_ALL); in nvme_passthru_end()
1122 mutex_unlock(&ctrl->scan_lock); in nvme_passthru_end()
1125 nvme_init_ctrl_finish(ctrl); in nvme_passthru_end()
1127 nvme_queue_scan(ctrl); in nvme_passthru_end()
1128 flush_work(&ctrl->scan_work); in nvme_passthru_end()
1141 nvme_update_keep_alive(ctrl, cmd); in nvme_passthru_end()
1156 struct nvme_ctrl *ctrl = nvme_req(rq)->ctrl; in nvme_execute_passthru_rq() local
1159 *effects = nvme_passthru_start(ctrl, ns, cmd->common.opcode); in nvme_execute_passthru_rq()
1170 static void nvme_queue_keep_alive_work(struct nvme_ctrl *ctrl) in nvme_queue_keep_alive_work() argument
1172 queue_delayed_work(nvme_wq, &ctrl->ka_work, ctrl->kato * HZ / 2); in nvme_queue_keep_alive_work()
1178 struct nvme_ctrl *ctrl = rq->end_io_data; in nvme_keep_alive_end_io() local
1185 dev_err(ctrl->device, in nvme_keep_alive_end_io()
1191 ctrl->comp_seen = false; in nvme_keep_alive_end_io()
1192 spin_lock_irqsave(&ctrl->lock, flags); in nvme_keep_alive_end_io()
1193 if (ctrl->state == NVME_CTRL_LIVE || in nvme_keep_alive_end_io()
1194 ctrl->state == NVME_CTRL_CONNECTING) in nvme_keep_alive_end_io()
1196 spin_unlock_irqrestore(&ctrl->lock, flags); in nvme_keep_alive_end_io()
1198 nvme_queue_keep_alive_work(ctrl); in nvme_keep_alive_end_io()
1204 struct nvme_ctrl *ctrl = container_of(to_delayed_work(work), in nvme_keep_alive_work() local
1206 bool comp_seen = ctrl->comp_seen; in nvme_keep_alive_work()
1209 if ((ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen) { in nvme_keep_alive_work()
1210 dev_dbg(ctrl->device, in nvme_keep_alive_work()
1212 ctrl->comp_seen = false; in nvme_keep_alive_work()
1213 nvme_queue_keep_alive_work(ctrl); in nvme_keep_alive_work()
1217 rq = blk_mq_alloc_request(ctrl->admin_q, nvme_req_op(&ctrl->ka_cmd), in nvme_keep_alive_work()
1221 dev_err(ctrl->device, "keep-alive failed: %ld\n", PTR_ERR(rq)); in nvme_keep_alive_work()
1222 nvme_reset_ctrl(ctrl); in nvme_keep_alive_work()
1225 nvme_init_request(rq, &ctrl->ka_cmd); in nvme_keep_alive_work()
1227 rq->timeout = ctrl->kato * HZ; in nvme_keep_alive_work()
1229 rq->end_io_data = ctrl; in nvme_keep_alive_work()
1233 static void nvme_start_keep_alive(struct nvme_ctrl *ctrl) in nvme_start_keep_alive() argument
1235 if (unlikely(ctrl->kato == 0)) in nvme_start_keep_alive()
1238 nvme_queue_keep_alive_work(ctrl); in nvme_start_keep_alive()
1241 void nvme_stop_keep_alive(struct nvme_ctrl *ctrl) in nvme_stop_keep_alive() argument
1243 if (unlikely(ctrl->kato == 0)) in nvme_stop_keep_alive()
1246 cancel_delayed_work_sync(&ctrl->ka_work); in nvme_stop_keep_alive()
1250 static void nvme_update_keep_alive(struct nvme_ctrl *ctrl, in nvme_update_keep_alive() argument
1256 dev_info(ctrl->device, in nvme_update_keep_alive()
1258 ctrl->kato * 1000 / 2, new_kato * 1000 / 2); in nvme_update_keep_alive()
1260 nvme_stop_keep_alive(ctrl); in nvme_update_keep_alive()
1261 ctrl->kato = new_kato; in nvme_update_keep_alive()
1262 nvme_start_keep_alive(ctrl); in nvme_update_keep_alive()
1271 static bool nvme_ctrl_limited_cns(struct nvme_ctrl *ctrl) in nvme_ctrl_limited_cns() argument
1273 if (ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS) in nvme_ctrl_limited_cns()
1274 return ctrl->vs < NVME_VS(1, 2, 0); in nvme_ctrl_limited_cns()
1275 return ctrl->vs < NVME_VS(1, 1, 0); in nvme_ctrl_limited_cns()
1298 static int nvme_process_ns_desc(struct nvme_ctrl *ctrl, struct nvme_ns_ids *ids, in nvme_process_ns_desc() argument
1301 const char *warn_str = "ctrl returned bogus length:"; in nvme_process_ns_desc()
1307 dev_warn(ctrl->device, "%s %d for NVME_NIDT_EUI64\n", in nvme_process_ns_desc()
1311 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1317 dev_warn(ctrl->device, "%s %d for NVME_NIDT_NGUID\n", in nvme_process_ns_desc()
1321 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1327 dev_warn(ctrl->device, "%s %d for NVME_NIDT_UUID\n", in nvme_process_ns_desc()
1331 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) in nvme_process_ns_desc()
1337 dev_warn(ctrl->device, "%s %d for NVME_NIDT_CSI\n", in nvme_process_ns_desc()
1350 static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, in nvme_identify_ns_descs() argument
1358 if (ctrl->vs < NVME_VS(1, 3, 0) && !nvme_multi_css(ctrl)) in nvme_identify_ns_descs()
1360 if (ctrl->quirks & NVME_QUIRK_NO_NS_DESC_LIST) in nvme_identify_ns_descs()
1371 status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data, in nvme_identify_ns_descs()
1374 dev_warn(ctrl->device, in nvme_identify_ns_descs()
1386 len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); in nvme_identify_ns_descs()
1393 if (nvme_multi_css(ctrl) && !csi_seen) { in nvme_identify_ns_descs()
1394 dev_warn(ctrl->device, "Command set not reported for nsid:%d\n", in nvme_identify_ns_descs()
1404 static int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid, in nvme_identify_ns() argument
1419 error = nvme_submit_sync_cmd(ctrl->admin_q, &c, *id, sizeof(**id)); in nvme_identify_ns()
1421 dev_warn(ctrl->device, "Identify namespace failed (%d)\n", error); in nvme_identify_ns()
1435 static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, in nvme_ns_info_from_identify() argument
1442 ret = nvme_identify_ns(ctrl, info->nsid, &id); in nvme_ns_info_from_identify()
1449 if (ctrl->quirks & NVME_QUIRK_BOGUS_NID) { in nvme_ns_info_from_identify()
1450 dev_info(ctrl->device, in nvme_ns_info_from_identify()
1453 if (ctrl->vs >= NVME_VS(1, 1, 0) && in nvme_ns_info_from_identify()
1456 if (ctrl->vs >= NVME_VS(1, 2, 0) && in nvme_ns_info_from_identify()
1464 static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, in nvme_ns_info_from_id_cs_indep() argument
1479 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_ns_info_from_id_cs_indep()
1526 int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) in nvme_set_queue_count() argument
1532 status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0, in nvme_set_queue_count()
1543 dev_err(ctrl->device, "Could not set queue count (%d)\n", status); in nvme_set_queue_count()
1558 static void nvme_enable_aen(struct nvme_ctrl *ctrl) in nvme_enable_aen() argument
1560 u32 result, supported_aens = ctrl->oaes & NVME_AEN_SUPPORTED; in nvme_enable_aen()
1566 status = nvme_set_features(ctrl, NVME_FEAT_ASYNC_EVENT, supported_aens, in nvme_enable_aen()
1569 dev_warn(ctrl->device, "Failed to configure AEN (cfg %x)\n", in nvme_enable_aen()
1572 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_enable_aen()
1583 if (!try_module_get(ns->ctrl->ops->module)) in nvme_ns_open()
1597 module_put(ns->ctrl->ops->module); in nvme_ns_release()
1680 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_config_discard() local
1684 if (ctrl->max_discard_sectors == 0) { in nvme_config_discard()
1698 if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns, UINT_MAX)) in nvme_config_discard()
1699 ctrl->max_discard_sectors = nvme_lba_to_sect(ns, ctrl->dmrsl); in nvme_config_discard()
1701 blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors); in nvme_config_discard()
1702 blk_queue_max_discard_segments(queue, ctrl->max_discard_segments); in nvme_config_discard()
1704 if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) in nvme_config_discard()
1720 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ms() local
1728 if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { in nvme_init_ms()
1743 ret = nvme_submit_sync_cmd(ns->ctrl->admin_q, &c, nvm, sizeof(*nvm)); in nvme_init_ms()
1778 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_configure_metadata() local
1784 if (!ns->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) in nvme_configure_metadata()
1787 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_configure_metadata()
1807 if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)) in nvme_configure_metadata()
1823 static void nvme_set_queue_limits(struct nvme_ctrl *ctrl, in nvme_set_queue_limits() argument
1826 bool vwc = ctrl->vwc & NVME_CTRL_VWC_PRESENT; in nvme_set_queue_limits()
1828 if (ctrl->max_hw_sectors) { in nvme_set_queue_limits()
1830 (ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> 9)) + 1; in nvme_set_queue_limits()
1832 max_segments = min_not_zero(max_segments, ctrl->max_segments); in nvme_set_queue_limits()
1833 blk_queue_max_hw_sectors(q, ctrl->max_hw_sectors); in nvme_set_queue_limits()
1869 atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; in nvme_update_disk_info()
1899 ns->ctrl->max_integrity_segments); in nvme_update_disk_info()
1908 ns->ctrl->max_zeroes_sectors); in nvme_update_disk_info()
1924 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_set_chunk_sectors() local
1927 if ((ctrl->quirks & NVME_QUIRK_STRIPE_SIZE) && in nvme_set_chunk_sectors()
1928 is_power_of_2(ctrl->max_hw_sectors)) in nvme_set_chunk_sectors()
1929 iob = ctrl->max_hw_sectors; in nvme_set_chunk_sectors()
1957 nvme_set_queue_limits(ns->ctrl, ns->queue); in nvme_update_ns_info_generic()
1985 ret = nvme_identify_ns(ns->ctrl, info->nsid, &id); in nvme_update_ns_info_block()
1992 nvme_set_queue_limits(ns->ctrl, ns->queue); in nvme_update_ns_info_block()
2047 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2056 dev_info(ns->ctrl->device, in nvme_update_ns_info()
2185 struct nvme_ctrl *ctrl = data; in nvme_sec_submit() local
2196 return __nvme_submit_sync_cmd(ctrl->admin_q, &cmd, NULL, buffer, len, in nvme_sec_submit()
2224 static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 timeout, bool enabled) in nvme_wait_ready() argument
2230 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_wait_ready()
2240 dev_err(ctrl->device, in nvme_wait_ready()
2256 int nvme_disable_ctrl(struct nvme_ctrl *ctrl) in nvme_disable_ctrl() argument
2260 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_disable_ctrl()
2261 ctrl->ctrl_config &= ~NVME_CC_ENABLE; in nvme_disable_ctrl()
2263 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_disable_ctrl()
2267 if (ctrl->quirks & NVME_QUIRK_DELAY_BEFORE_CHK_RDY) in nvme_disable_ctrl()
2270 return nvme_wait_ready(ctrl, NVME_CAP_TIMEOUT(ctrl->cap), false); in nvme_disable_ctrl()
2274 int nvme_enable_ctrl(struct nvme_ctrl *ctrl) in nvme_enable_ctrl() argument
2280 ret = ctrl->ops->reg_read64(ctrl, NVME_REG_CAP, &ctrl->cap); in nvme_enable_ctrl()
2282 dev_err(ctrl->device, "Reading CAP failed (%d)\n", ret); in nvme_enable_ctrl()
2285 dev_page_min = NVME_CAP_MPSMIN(ctrl->cap) + 12; in nvme_enable_ctrl()
2288 dev_err(ctrl->device, in nvme_enable_ctrl()
2294 if (NVME_CAP_CSS(ctrl->cap) & NVME_CAP_CSS_CSI) in nvme_enable_ctrl()
2295 ctrl->ctrl_config = NVME_CC_CSS_CSI; in nvme_enable_ctrl()
2297 ctrl->ctrl_config = NVME_CC_CSS_NVM; in nvme_enable_ctrl()
2299 if (ctrl->cap & NVME_CAP_CRMS_CRWMS) { in nvme_enable_ctrl()
2302 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CRTO, &crto); in nvme_enable_ctrl()
2304 dev_err(ctrl->device, "Reading CRTO failed (%d)\n", in nvme_enable_ctrl()
2309 if (ctrl->cap & NVME_CAP_CRMS_CRIMS) { in nvme_enable_ctrl()
2310 ctrl->ctrl_config |= NVME_CC_CRIME; in nvme_enable_ctrl()
2316 timeout = NVME_CAP_TIMEOUT(ctrl->cap); in nvme_enable_ctrl()
2319 ctrl->ctrl_config |= (NVME_CTRL_PAGE_SHIFT - 12) << NVME_CC_MPS_SHIFT; in nvme_enable_ctrl()
2320 ctrl->ctrl_config |= NVME_CC_AMS_RR | NVME_CC_SHN_NONE; in nvme_enable_ctrl()
2321 ctrl->ctrl_config |= NVME_CC_IOSQES | NVME_CC_IOCQES; in nvme_enable_ctrl()
2322 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2327 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CC, &ctrl->ctrl_config); in nvme_enable_ctrl()
2331 ctrl->ctrl_config |= NVME_CC_ENABLE; in nvme_enable_ctrl()
2332 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_enable_ctrl()
2335 return nvme_wait_ready(ctrl, timeout, true); in nvme_enable_ctrl()
2339 int nvme_shutdown_ctrl(struct nvme_ctrl *ctrl) in nvme_shutdown_ctrl() argument
2341 unsigned long timeout = jiffies + (ctrl->shutdown_timeout * HZ); in nvme_shutdown_ctrl()
2345 ctrl->ctrl_config &= ~NVME_CC_SHN_MASK; in nvme_shutdown_ctrl()
2346 ctrl->ctrl_config |= NVME_CC_SHN_NORMAL; in nvme_shutdown_ctrl()
2348 ret = ctrl->ops->reg_write32(ctrl, NVME_REG_CC, ctrl->ctrl_config); in nvme_shutdown_ctrl()
2352 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { in nvme_shutdown_ctrl()
2360 dev_err(ctrl->device, in nvme_shutdown_ctrl()
2370 static int nvme_configure_timestamp(struct nvme_ctrl *ctrl) in nvme_configure_timestamp() argument
2375 if (!(ctrl->oncs & NVME_CTRL_ONCS_TIMESTAMP)) in nvme_configure_timestamp()
2379 ret = nvme_set_features(ctrl, NVME_FEAT_TIMESTAMP, 0, &ts, sizeof(ts), in nvme_configure_timestamp()
2382 dev_warn_once(ctrl->device, in nvme_configure_timestamp()
2387 static int nvme_configure_host_options(struct nvme_ctrl *ctrl) in nvme_configure_host_options() argument
2394 if (ctrl->crdt[0]) in nvme_configure_host_options()
2396 if (ctrl->ctratt & NVME_CTRL_ATTR_ELBAS) in nvme_configure_host_options()
2408 ret = nvme_set_features(ctrl, NVME_FEAT_HOST_BEHAVIOR, 0, in nvme_configure_host_options()
2468 static int nvme_configure_apst(struct nvme_ctrl *ctrl) in nvme_configure_apst() argument
2483 if (!ctrl->apsta) in nvme_configure_apst()
2486 if (ctrl->npss > 31) { in nvme_configure_apst()
2487 dev_warn(ctrl->device, "NPSS is invalid; not using APST\n"); in nvme_configure_apst()
2495 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us == 0) { in nvme_configure_apst()
2497 dev_dbg(ctrl->device, "APST disabled\n"); in nvme_configure_apst()
2507 for (state = (int)ctrl->npss; state >= 0; state--) { in nvme_configure_apst()
2517 if (state == ctrl->npss && in nvme_configure_apst()
2518 (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) in nvme_configure_apst()
2525 if (!(ctrl->psd[state].flags & NVME_PS_FLAGS_NON_OP_STATE)) in nvme_configure_apst()
2528 exit_latency_us = (u64)le32_to_cpu(ctrl->psd[state].exit_lat); in nvme_configure_apst()
2529 if (exit_latency_us > ctrl->ps_max_latency_us) in nvme_configure_apst()
2533 le32_to_cpu(ctrl->psd[state].entry_lat); in nvme_configure_apst()
2558 dev_dbg(ctrl->device, "APST enabled but no non-operational states are available\n"); in nvme_configure_apst()
2560 …dev_dbg(ctrl->device, "APST enabled: max PS = %d, max round-trip latency = %lluus, table = %*phN\n… in nvme_configure_apst()
2565 ret = nvme_set_features(ctrl, NVME_FEAT_AUTO_PST, apste, in nvme_configure_apst()
2568 dev_err(ctrl->device, "failed to set APST feature (%d)\n", ret); in nvme_configure_apst()
2575 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_set_latency_tolerance() local
2588 if (ctrl->ps_max_latency_us != latency) { in nvme_set_latency_tolerance()
2589 ctrl->ps_max_latency_us = latency; in nvme_set_latency_tolerance()
2590 if (ctrl->state == NVME_CTRL_LIVE) in nvme_set_latency_tolerance()
2591 nvme_configure_apst(ctrl); in nvme_set_latency_tolerance()
2686 static void nvme_init_subnqn(struct nvme_subsystem *subsys, struct nvme_ctrl *ctrl, in nvme_init_subnqn() argument
2692 if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) { in nvme_init_subnqn()
2699 if (ctrl->vs >= NVME_VS(1, 2, 1)) in nvme_init_subnqn()
2700 dev_warn(ctrl->device, "missing or invalid SUBNQN field.\n"); in nvme_init_subnqn()
2844 static inline bool nvme_discovery_ctrl(struct nvme_ctrl *ctrl) in nvme_discovery_ctrl() argument
2846 return ctrl->opts && ctrl->opts->discovery_nqn; in nvme_discovery_ctrl()
2850 struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_validate_cntlid() argument
2860 if (tmp->cntlid == ctrl->cntlid) { in nvme_validate_cntlid()
2861 dev_err(ctrl->device, in nvme_validate_cntlid()
2863 ctrl->cntlid, dev_name(tmp->device), in nvme_validate_cntlid()
2869 nvme_discovery_ctrl(ctrl)) in nvme_validate_cntlid()
2872 dev_err(ctrl->device, in nvme_validate_cntlid()
2880 static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) in nvme_init_subsystem() argument
2894 nvme_init_subnqn(subsys, ctrl, id); in nvme_init_subsystem()
2907 if (nvme_discovery_ctrl(ctrl) && subsys->subtype != NVME_NQN_DISC) { in nvme_init_subsystem()
2908 dev_err(ctrl->device, in nvme_init_subsystem()
2920 dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); in nvme_init_subsystem()
2929 if (!nvme_validate_cntlid(subsys, ctrl, id)) { in nvme_init_subsystem()
2936 dev_err(ctrl->device, in nvme_init_subsystem()
2945 ret = sysfs_create_link(&subsys->dev.kobj, &ctrl->device->kobj, in nvme_init_subsystem()
2946 dev_name(ctrl->device)); in nvme_init_subsystem()
2948 dev_err(ctrl->device, in nvme_init_subsystem()
2954 subsys->instance = ctrl->instance; in nvme_init_subsystem()
2955 ctrl->subsys = subsys; in nvme_init_subsystem()
2956 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvme_init_subsystem()
2967 int nvme_get_log(struct nvme_ctrl *ctrl, u32 nsid, u8 log_page, u8 lsp, u8 csi, in nvme_get_log() argument
2983 return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size); in nvme_get_log()
2986 static int nvme_get_effects_log(struct nvme_ctrl *ctrl, u8 csi, in nvme_get_effects_log() argument
2989 struct nvme_effects_log *cel = xa_load(&ctrl->cels, csi); in nvme_get_effects_log()
2999 ret = nvme_get_log(ctrl, 0x00, NVME_LOG_CMD_EFFECTS, 0, csi, in nvme_get_effects_log()
3006 xa_store(&ctrl->cels, csi, cel, GFP_KERNEL); in nvme_get_effects_log()
3012 static inline u32 nvme_mps_to_sectors(struct nvme_ctrl *ctrl, u32 units) in nvme_mps_to_sectors() argument
3014 u32 page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12, val; in nvme_mps_to_sectors()
3021 static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) in nvme_init_non_mdts_limits() argument
3027 if (ctrl->oncs & NVME_CTRL_ONCS_DSM) { in nvme_init_non_mdts_limits()
3028 ctrl->max_discard_sectors = UINT_MAX; in nvme_init_non_mdts_limits()
3029 ctrl->max_discard_segments = NVME_DSM_MAX_RANGES; in nvme_init_non_mdts_limits()
3031 ctrl->max_discard_sectors = 0; in nvme_init_non_mdts_limits()
3032 ctrl->max_discard_segments = 0; in nvme_init_non_mdts_limits()
3041 if ((ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) && in nvme_init_non_mdts_limits()
3042 !(ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) in nvme_init_non_mdts_limits()
3043 ctrl->max_zeroes_sectors = ctrl->max_hw_sectors; in nvme_init_non_mdts_limits()
3045 ctrl->max_zeroes_sectors = 0; in nvme_init_non_mdts_limits()
3047 if (nvme_ctrl_limited_cns(ctrl)) in nvme_init_non_mdts_limits()
3058 ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id)); in nvme_init_non_mdts_limits()
3063 ctrl->max_discard_segments = id->dmrl; in nvme_init_non_mdts_limits()
3064 ctrl->dmrsl = le32_to_cpu(id->dmrsl); in nvme_init_non_mdts_limits()
3066 ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); in nvme_init_non_mdts_limits()
3073 static int nvme_init_identify(struct nvme_ctrl *ctrl) in nvme_init_identify() argument
3080 ret = nvme_identify_ctrl(ctrl, &id); in nvme_init_identify()
3082 dev_err(ctrl->device, "Identify Controller failed (%d)\n", ret); in nvme_init_identify()
3087 ret = nvme_get_effects_log(ctrl, NVME_CSI_NVM, &ctrl->effects); in nvme_init_identify()
3092 if (!(ctrl->ops->flags & NVME_F_FABRICS)) in nvme_init_identify()
3093 ctrl->cntlid = le16_to_cpu(id->cntlid); in nvme_init_identify()
3095 if (!ctrl->identified) { in nvme_init_identify()
3108 ctrl->quirks |= core_quirks[i].quirks; in nvme_init_identify()
3111 ret = nvme_init_subsystem(ctrl, id); in nvme_init_identify()
3115 memcpy(ctrl->subsys->firmware_rev, id->fr, in nvme_init_identify()
3116 sizeof(ctrl->subsys->firmware_rev)); in nvme_init_identify()
3118 if (force_apst && (ctrl->quirks & NVME_QUIRK_NO_DEEPEST_PS)) { in nvme_init_identify()
3119 …dev_warn(ctrl->device, "forcibly allowing all power states due to nvme_core.force_apst -- use at y… in nvme_init_identify()
3120 ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS; in nvme_init_identify()
3123 ctrl->crdt[0] = le16_to_cpu(id->crdt1); in nvme_init_identify()
3124 ctrl->crdt[1] = le16_to_cpu(id->crdt2); in nvme_init_identify()
3125 ctrl->crdt[2] = le16_to_cpu(id->crdt3); in nvme_init_identify()
3127 ctrl->oacs = le16_to_cpu(id->oacs); in nvme_init_identify()
3128 ctrl->oncs = le16_to_cpu(id->oncs); in nvme_init_identify()
3129 ctrl->mtfa = le16_to_cpu(id->mtfa); in nvme_init_identify()
3130 ctrl->oaes = le32_to_cpu(id->oaes); in nvme_init_identify()
3131 ctrl->wctemp = le16_to_cpu(id->wctemp); in nvme_init_identify()
3132 ctrl->cctemp = le16_to_cpu(id->cctemp); in nvme_init_identify()
3134 atomic_set(&ctrl->abort_limit, id->acl + 1); in nvme_init_identify()
3135 ctrl->vwc = id->vwc; in nvme_init_identify()
3137 max_hw_sectors = nvme_mps_to_sectors(ctrl, id->mdts); in nvme_init_identify()
3140 ctrl->max_hw_sectors = in nvme_init_identify()
3141 min_not_zero(ctrl->max_hw_sectors, max_hw_sectors); in nvme_init_identify()
3143 nvme_set_queue_limits(ctrl, ctrl->admin_q); in nvme_init_identify()
3144 ctrl->sgls = le32_to_cpu(id->sgls); in nvme_init_identify()
3145 ctrl->kas = le16_to_cpu(id->kas); in nvme_init_identify()
3146 ctrl->max_namespaces = le32_to_cpu(id->mnan); in nvme_init_identify()
3147 ctrl->ctratt = le32_to_cpu(id->ctratt); in nvme_init_identify()
3149 ctrl->cntrltype = id->cntrltype; in nvme_init_identify()
3150 ctrl->dctype = id->dctype; in nvme_init_identify()
3156 ctrl->shutdown_timeout = clamp_t(unsigned int, transition_time, in nvme_init_identify()
3159 if (ctrl->shutdown_timeout != shutdown_timeout) in nvme_init_identify()
3160 dev_info(ctrl->device, in nvme_init_identify()
3162 ctrl->shutdown_timeout); in nvme_init_identify()
3164 ctrl->shutdown_timeout = shutdown_timeout; in nvme_init_identify()
3166 ctrl->npss = id->npss; in nvme_init_identify()
3167 ctrl->apsta = id->apsta; in nvme_init_identify()
3168 prev_apst_enabled = ctrl->apst_enabled; in nvme_init_identify()
3169 if (ctrl->quirks & NVME_QUIRK_NO_APST) { in nvme_init_identify()
3171 …dev_warn(ctrl->device, "forcibly allowing APST due to nvme_core.force_apst -- use at your own risk… in nvme_init_identify()
3172 ctrl->apst_enabled = true; in nvme_init_identify()
3174 ctrl->apst_enabled = false; in nvme_init_identify()
3177 ctrl->apst_enabled = id->apsta; in nvme_init_identify()
3179 memcpy(ctrl->psd, id->psd, sizeof(ctrl->psd)); in nvme_init_identify()
3181 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_init_identify()
3182 ctrl->icdoff = le16_to_cpu(id->icdoff); in nvme_init_identify()
3183 ctrl->ioccsz = le32_to_cpu(id->ioccsz); in nvme_init_identify()
3184 ctrl->iorcsz = le32_to_cpu(id->iorcsz); in nvme_init_identify()
3185 ctrl->maxcmd = le16_to_cpu(id->maxcmd); in nvme_init_identify()
3191 if (ctrl->cntlid != le16_to_cpu(id->cntlid)) { in nvme_init_identify()
3192 dev_err(ctrl->device, in nvme_init_identify()
3195 ctrl->cntlid, le16_to_cpu(id->cntlid)); in nvme_init_identify()
3200 if (!nvme_discovery_ctrl(ctrl) && !ctrl->kas) { in nvme_init_identify()
3201 dev_err(ctrl->device, in nvme_init_identify()
3207 ctrl->hmpre = le32_to_cpu(id->hmpre); in nvme_init_identify()
3208 ctrl->hmmin = le32_to_cpu(id->hmmin); in nvme_init_identify()
3209 ctrl->hmminds = le32_to_cpu(id->hmminds); in nvme_init_identify()
3210 ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); in nvme_init_identify()
3213 ret = nvme_mpath_init_identify(ctrl, id); in nvme_init_identify()
3217 if (ctrl->apst_enabled && !prev_apst_enabled) in nvme_init_identify()
3218 dev_pm_qos_expose_latency_tolerance(ctrl->device); in nvme_init_identify()
3219 else if (!ctrl->apst_enabled && prev_apst_enabled) in nvme_init_identify()
3220 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_init_identify()
3232 int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl) in nvme_init_ctrl_finish() argument
3236 ret = ctrl->ops->reg_read32(ctrl, NVME_REG_VS, &ctrl->vs); in nvme_init_ctrl_finish()
3238 dev_err(ctrl->device, "Reading VS failed (%d)\n", ret); in nvme_init_ctrl_finish()
3242 ctrl->sqsize = min_t(u16, NVME_CAP_MQES(ctrl->cap), ctrl->sqsize); in nvme_init_ctrl_finish()
3244 if (ctrl->vs >= NVME_VS(1, 1, 0)) in nvme_init_ctrl_finish()
3245 ctrl->subsystem = NVME_CAP_NSSRC(ctrl->cap); in nvme_init_ctrl_finish()
3247 ret = nvme_init_identify(ctrl); in nvme_init_ctrl_finish()
3251 ret = nvme_configure_apst(ctrl); in nvme_init_ctrl_finish()
3255 ret = nvme_configure_timestamp(ctrl); in nvme_init_ctrl_finish()
3259 ret = nvme_configure_host_options(ctrl); in nvme_init_ctrl_finish()
3263 if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { in nvme_init_ctrl_finish()
3268 ret = nvme_hwmon_init(ctrl); in nvme_init_ctrl_finish()
3273 ctrl->identified = true; in nvme_init_ctrl_finish()
3281 struct nvme_ctrl *ctrl = in nvme_dev_open() local
3284 switch (ctrl->state) { in nvme_dev_open()
3291 nvme_get_ctrl(ctrl); in nvme_dev_open()
3292 if (!try_module_get(ctrl->ops->module)) { in nvme_dev_open()
3293 nvme_put_ctrl(ctrl); in nvme_dev_open()
3297 file->private_data = ctrl; in nvme_dev_open()
3303 struct nvme_ctrl *ctrl = in nvme_dev_release() local
3306 module_put(ctrl->ops->module); in nvme_dev_release()
3307 nvme_put_ctrl(ctrl); in nvme_dev_release()
3324 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_reset() local
3327 ret = nvme_reset_ctrl_sync(ctrl); in nvme_sysfs_reset()
3338 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_rescan() local
3340 nvme_queue_scan(ctrl); in nvme_sysfs_rescan()
3460 if (!nvme_ctrl_use_ana(nvme_get_ns_from_dev(dev)->ctrl)) in nvme_ns_id_attrs_are_visible()
3481 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \
3483 (int)sizeof(ctrl->subsys->field), ctrl->subsys->field); \
3495 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \
3496 return sysfs_emit(buf, "%d\n", ctrl->field); \
3510 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_delete() local
3513 nvme_delete_ctrl_sync(ctrl); in nvme_sysfs_delete()
3522 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_transport() local
3524 return sysfs_emit(buf, "%s\n", ctrl->ops->name); in nvme_sysfs_show_transport()
3532 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_state() local
3543 if ((unsigned)ctrl->state < ARRAY_SIZE(state_name) && in nvme_sysfs_show_state()
3544 state_name[ctrl->state]) in nvme_sysfs_show_state()
3545 return sysfs_emit(buf, "%s\n", state_name[ctrl->state]); in nvme_sysfs_show_state()
3556 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_subsysnqn() local
3558 return sysfs_emit(buf, "%s\n", ctrl->subsys->subnqn); in nvme_sysfs_show_subsysnqn()
3566 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_hostnqn() local
3568 return sysfs_emit(buf, "%s\n", ctrl->opts->host->nqn); in nvme_sysfs_show_hostnqn()
3576 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_hostid() local
3578 return sysfs_emit(buf, "%pU\n", &ctrl->opts->host->id); in nvme_sysfs_show_hostid()
3586 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_sysfs_show_address() local
3588 return ctrl->ops->get_address(ctrl, buf, PAGE_SIZE); in nvme_sysfs_show_address()
3595 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_loss_tmo_show() local
3596 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_loss_tmo_show()
3598 if (ctrl->opts->max_reconnects == -1) in nvme_ctrl_loss_tmo_show()
3607 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_loss_tmo_store() local
3608 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_loss_tmo_store()
3628 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_reconnect_delay_show() local
3630 if (ctrl->opts->reconnect_delay == -1) in nvme_ctrl_reconnect_delay_show()
3632 return sysfs_emit(buf, "%d\n", ctrl->opts->reconnect_delay); in nvme_ctrl_reconnect_delay_show()
3638 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_reconnect_delay_store() local
3646 ctrl->opts->reconnect_delay = v; in nvme_ctrl_reconnect_delay_store()
3655 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_fast_io_fail_tmo_show() local
3657 if (ctrl->opts->fast_io_fail_tmo == -1) in nvme_ctrl_fast_io_fail_tmo_show()
3659 return sysfs_emit(buf, "%d\n", ctrl->opts->fast_io_fail_tmo); in nvme_ctrl_fast_io_fail_tmo_show()
3665 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_fast_io_fail_tmo_store() local
3666 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_fast_io_fail_tmo_store()
3690 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in cntrltype_show() local
3692 if (ctrl->cntrltype > NVME_CTRL_ADMIN || !type[ctrl->cntrltype]) in cntrltype_show()
3695 return sysfs_emit(buf, type[ctrl->cntrltype]); in cntrltype_show()
3707 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in dctype_show() local
3709 if (ctrl->dctype > NVME_DCTYPE_CDC || !type[ctrl->dctype]) in dctype_show()
3712 return sysfs_emit(buf, type[ctrl->dctype]); in dctype_show()
3720 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_dhchap_secret_show() local
3721 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_dhchap_secret_show()
3731 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_dhchap_secret_store() local
3732 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_dhchap_secret_store()
3735 if (!ctrl->opts->dhchap_secret) in nvme_ctrl_dhchap_secret_store()
3746 nvme_auth_stop(ctrl); in nvme_ctrl_dhchap_secret_store()
3750 ret = nvme_auth_generate_key(dhchap_secret, &ctrl->host_key); in nvme_ctrl_dhchap_secret_store()
3756 nvme_auth_reset(ctrl); in nvme_ctrl_dhchap_secret_store()
3759 dev_info(ctrl->device, "re-authenticating controller\n"); in nvme_ctrl_dhchap_secret_store()
3760 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_ctrl_dhchap_secret_store()
3770 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_dhchap_ctrl_secret_show() local
3771 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_dhchap_ctrl_secret_show()
3781 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_ctrl_dhchap_ctrl_secret_store() local
3782 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_ctrl_dhchap_ctrl_secret_store()
3785 if (!ctrl->opts->dhchap_ctrl_secret) in nvme_ctrl_dhchap_ctrl_secret_store()
3796 nvme_auth_stop(ctrl); in nvme_ctrl_dhchap_ctrl_secret_store()
3800 ret = nvme_auth_generate_key(dhchap_secret, &ctrl->ctrl_key); in nvme_ctrl_dhchap_ctrl_secret_store()
3806 nvme_auth_reset(ctrl); in nvme_ctrl_dhchap_ctrl_secret_store()
3809 dev_info(ctrl->device, "re-authenticating controller\n"); in nvme_ctrl_dhchap_ctrl_secret_store()
3810 queue_work(nvme_wq, &ctrl->dhchap_auth_work); in nvme_ctrl_dhchap_ctrl_secret_store()
3852 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); in nvme_dev_attrs_are_visible() local
3854 if (a == &dev_attr_delete_controller.attr && !ctrl->ops->delete_ctrl) in nvme_dev_attrs_are_visible()
3856 if (a == &dev_attr_address.attr && !ctrl->ops->get_address) in nvme_dev_attrs_are_visible()
3858 if (a == &dev_attr_hostnqn.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
3860 if (a == &dev_attr_hostid.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
3862 if (a == &dev_attr_ctrl_loss_tmo.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
3864 if (a == &dev_attr_reconnect_delay.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
3866 if (a == &dev_attr_fast_io_fail_tmo.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
3869 if (a == &dev_attr_dhchap_secret.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
3871 if (a == &dev_attr_dhchap_ctrl_secret.attr && !ctrl->opts) in nvme_dev_attrs_are_visible()
3888 static struct nvme_ns_head *nvme_find_ns_head(struct nvme_ctrl *ctrl, in nvme_find_ns_head() argument
3893 lockdep_assert_held(&ctrl->subsys->lock); in nvme_find_ns_head()
3895 list_for_each_entry(h, &ctrl->subsys->nsheads, entry) { in nvme_find_ns_head()
3901 if (h->ns_id != nsid || !nvme_is_unique_nsid(ctrl, h)) in nvme_find_ns_head()
3991 ns->cdev_device.parent = ns->ctrl->device; in nvme_add_ns_cdev()
3993 ns->ctrl->instance, ns->head->instance); in nvme_add_ns_cdev()
3998 ns->ctrl->ops->module); in nvme_add_ns_cdev()
4001 static struct nvme_ns_head *nvme_alloc_ns_head(struct nvme_ctrl *ctrl, in nvme_alloc_ns_head() argument
4015 ret = ida_alloc_min(&ctrl->subsys->ns_ida, 1, GFP_KERNEL); in nvme_alloc_ns_head()
4023 head->subsys = ctrl->subsys; in nvme_alloc_ns_head()
4030 ret = nvme_get_effects_log(ctrl, head->ids.csi, &head->effects); in nvme_alloc_ns_head()
4034 head->effects = ctrl->effects; in nvme_alloc_ns_head()
4036 ret = nvme_mpath_alloc_disk(ctrl, head); in nvme_alloc_ns_head()
4040 list_add_tail(&head->entry, &ctrl->subsys->nsheads); in nvme_alloc_ns_head()
4042 kref_get(&ctrl->subsys->ref); in nvme_alloc_ns_head()
4048 ida_free(&ctrl->subsys->ns_ida, head->instance); in nvme_alloc_ns_head()
4085 struct nvme_ctrl *ctrl = ns->ctrl; in nvme_init_ns_head() local
4089 ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
4091 dev_err(ctrl->device, in nvme_init_ns_head()
4093 nvme_print_device_info(ctrl); in nvme_init_ns_head()
4097 mutex_lock(&ctrl->subsys->lock); in nvme_init_ns_head()
4098 head = nvme_find_ns_head(ctrl, info->nsid); in nvme_init_ns_head()
4100 ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); in nvme_init_ns_head()
4102 dev_err(ctrl->device, in nvme_init_ns_head()
4107 head = nvme_alloc_ns_head(ctrl, info); in nvme_init_ns_head()
4115 dev_err(ctrl->device, in nvme_init_ns_head()
4121 dev_err(ctrl->device, in nvme_init_ns_head()
4128 dev_warn(ctrl->device, in nvme_init_ns_head()
4131 dev_warn_once(ctrl->device, in nvme_init_ns_head()
4138 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
4144 mutex_unlock(&ctrl->subsys->lock); in nvme_init_ns_head()
4148 struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_find_get_ns() argument
4152 down_read(&ctrl->namespaces_rwsem); in nvme_find_get_ns()
4153 list_for_each_entry(ns, &ctrl->namespaces, list) { in nvme_find_get_ns()
4163 up_read(&ctrl->namespaces_rwsem); in nvme_find_get_ns()
4175 list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) { in nvme_ns_add_to_ctrl_list()
4181 list_add(&ns->list, &ns->ctrl->namespaces); in nvme_ns_add_to_ctrl_list()
4184 static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) in nvme_alloc_ns() argument
4188 int node = ctrl->numa_node; in nvme_alloc_ns()
4194 disk = blk_mq_alloc_disk(ctrl->tagset, ns); in nvme_alloc_ns()
4203 if (ctrl->opts && ctrl->opts->data_digest) in nvme_alloc_ns()
4207 if (ctrl->ops->supports_pci_p2pdma && in nvme_alloc_ns()
4208 ctrl->ops->supports_pci_p2pdma(ctrl)) in nvme_alloc_ns()
4211 ns->ctrl = ctrl; in nvme_alloc_ns()
4229 sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
4230 ctrl->instance, ns->head->instance); in nvme_alloc_ns()
4233 sprintf(disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, in nvme_alloc_ns()
4236 sprintf(disk->disk_name, "nvme%dn%d", ctrl->instance, in nvme_alloc_ns()
4243 down_write(&ctrl->namespaces_rwsem); in nvme_alloc_ns()
4245 up_write(&ctrl->namespaces_rwsem); in nvme_alloc_ns()
4246 nvme_get_ctrl(ctrl); in nvme_alloc_ns()
4248 if (device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups)) in nvme_alloc_ns()
4260 nvme_put_ctrl(ctrl); in nvme_alloc_ns()
4261 down_write(&ctrl->namespaces_rwsem); in nvme_alloc_ns()
4263 up_write(&ctrl->namespaces_rwsem); in nvme_alloc_ns()
4265 mutex_lock(&ctrl->subsys->lock); in nvme_alloc_ns()
4269 mutex_unlock(&ctrl->subsys->lock); in nvme_alloc_ns()
4298 mutex_lock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4304 mutex_unlock(&ns->ctrl->subsys->lock); in nvme_ns_remove()
4313 down_write(&ns->ctrl->namespaces_rwsem); in nvme_ns_remove()
4315 up_write(&ns->ctrl->namespaces_rwsem); in nvme_ns_remove()
4322 static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid) in nvme_ns_remove_by_nsid() argument
4324 struct nvme_ns *ns = nvme_find_get_ns(ctrl, nsid); in nvme_ns_remove_by_nsid()
4341 dev_err(ns->ctrl->device, in nvme_validate_ns()
4358 static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid) in nvme_scan_ns() argument
4363 if (nvme_identify_ns_descs(ctrl, &info)) in nvme_scan_ns()
4366 if (info.ids.csi != NVME_CSI_NVM && !nvme_multi_css(ctrl)) { in nvme_scan_ns()
4367 dev_warn(ctrl->device, in nvme_scan_ns()
4377 if ((ctrl->cap & NVME_CAP_CRMS_CRIMS) || in nvme_scan_ns()
4379 if (nvme_ns_info_from_id_cs_indep(ctrl, &info)) in nvme_scan_ns()
4382 if (nvme_ns_info_from_identify(ctrl, &info)) in nvme_scan_ns()
4393 ns = nvme_find_get_ns(ctrl, nsid); in nvme_scan_ns()
4398 nvme_alloc_ns(ctrl, &info); in nvme_scan_ns()
4402 static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl, in nvme_remove_invalid_namespaces() argument
4408 down_write(&ctrl->namespaces_rwsem); in nvme_remove_invalid_namespaces()
4409 list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) { in nvme_remove_invalid_namespaces()
4413 up_write(&ctrl->namespaces_rwsem); in nvme_remove_invalid_namespaces()
4420 static int nvme_scan_ns_list(struct nvme_ctrl *ctrl) in nvme_scan_ns_list() argument
4427 if (nvme_ctrl_limited_cns(ctrl)) in nvme_scan_ns_list()
4441 ret = nvme_submit_sync_cmd(ctrl->admin_q, &cmd, ns_list, in nvme_scan_ns_list()
4444 dev_warn(ctrl->device, in nvme_scan_ns_list()
4454 nvme_scan_ns(ctrl, nsid); in nvme_scan_ns_list()
4456 nvme_ns_remove_by_nsid(ctrl, prev); in nvme_scan_ns_list()
4460 nvme_remove_invalid_namespaces(ctrl, prev); in nvme_scan_ns_list()
4466 static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl) in nvme_scan_ns_sequential() argument
4471 if (nvme_identify_ctrl(ctrl, &id)) in nvme_scan_ns_sequential()
4477 nvme_scan_ns(ctrl, i); in nvme_scan_ns_sequential()
4479 nvme_remove_invalid_namespaces(ctrl, nn); in nvme_scan_ns_sequential()
4482 static void nvme_clear_changed_ns_log(struct nvme_ctrl *ctrl) in nvme_clear_changed_ns_log() argument
4498 error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_CHANGED_NS, 0, in nvme_clear_changed_ns_log()
4501 dev_warn(ctrl->device, in nvme_clear_changed_ns_log()
4509 struct nvme_ctrl *ctrl = in nvme_scan_work() local
4513 /* No tagset on a live ctrl means IO queues could not created */ in nvme_scan_work()
4514 if (ctrl->state != NVME_CTRL_LIVE || !ctrl->tagset) in nvme_scan_work()
4524 ret = nvme_init_non_mdts_limits(ctrl); in nvme_scan_work()
4526 dev_warn(ctrl->device, in nvme_scan_work()
4531 if (test_and_clear_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events)) { in nvme_scan_work()
4532 dev_info(ctrl->device, "rescanning namespaces.\n"); in nvme_scan_work()
4533 nvme_clear_changed_ns_log(ctrl); in nvme_scan_work()
4536 mutex_lock(&ctrl->scan_lock); in nvme_scan_work()
4537 if (nvme_scan_ns_list(ctrl) != 0) in nvme_scan_work()
4538 nvme_scan_ns_sequential(ctrl); in nvme_scan_work()
4539 mutex_unlock(&ctrl->scan_lock); 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()
4560 flush_work(&ctrl->scan_work); in nvme_remove_namespaces()
4568 if (ctrl->state == NVME_CTRL_DEAD) in nvme_remove_namespaces()
4569 nvme_kill_queues(ctrl); in nvme_remove_namespaces()
4572 nvme_change_ctrl_state(ctrl, NVME_CTRL_DELETING_NOIO); in nvme_remove_namespaces()
4574 down_write(&ctrl->namespaces_rwsem); in nvme_remove_namespaces()
4575 list_splice_init(&ctrl->namespaces, &ns_list); in nvme_remove_namespaces()
4576 up_write(&ctrl->namespaces_rwsem); in nvme_remove_namespaces()
4585 struct nvme_ctrl *ctrl = in nvme_class_uevent() local
4587 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_class_uevent()
4590 ret = add_uevent_var(env, "NVME_TRTYPE=%s", ctrl->ops->name); in nvme_class_uevent()
4615 static void nvme_change_uevent(struct nvme_ctrl *ctrl, char *envdata) in nvme_change_uevent() argument
4619 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_change_uevent()
4622 static void nvme_aen_uevent(struct nvme_ctrl *ctrl) in nvme_aen_uevent() argument
4625 u32 aen_result = ctrl->aen_result; in nvme_aen_uevent()
4627 ctrl->aen_result = 0; in nvme_aen_uevent()
4634 kobject_uevent_env(&ctrl->device->kobj, KOBJ_CHANGE, envp); in nvme_aen_uevent()
4640 struct nvme_ctrl *ctrl = in nvme_async_event_work() local
4643 nvme_aen_uevent(ctrl); in nvme_async_event_work()
4647 * flushing ctrl async_event_work after changing the controller state in nvme_async_event_work()
4650 if (ctrl->state == NVME_CTRL_LIVE) in nvme_async_event_work()
4651 ctrl->ops->submit_async_event(ctrl); in nvme_async_event_work()
4654 static bool nvme_ctrl_pp_status(struct nvme_ctrl *ctrl) in nvme_ctrl_pp_status() argument
4659 if (ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) in nvme_ctrl_pp_status()
4665 return ((ctrl->ctrl_config & NVME_CC_ENABLE) && (csts & NVME_CSTS_PP)); in nvme_ctrl_pp_status()
4668 static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl) in nvme_get_fw_slot_info() argument
4676 if (nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_FW_SLOT, 0, NVME_CSI_NVM, in nvme_get_fw_slot_info()
4678 dev_warn(ctrl->device, "Get FW SLOT INFO log error\n"); in nvme_get_fw_slot_info()
4684 struct nvme_ctrl *ctrl = container_of(work, in nvme_fw_act_work() local
4688 if (ctrl->mtfa) in nvme_fw_act_work()
4690 msecs_to_jiffies(ctrl->mtfa * 100); in nvme_fw_act_work()
4695 nvme_stop_queues(ctrl); in nvme_fw_act_work()
4696 while (nvme_ctrl_pp_status(ctrl)) { in nvme_fw_act_work()
4698 dev_warn(ctrl->device, in nvme_fw_act_work()
4700 nvme_try_sched_reset(ctrl); in nvme_fw_act_work()
4706 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) in nvme_fw_act_work()
4709 nvme_start_queues(ctrl); in nvme_fw_act_work()
4711 nvme_get_fw_slot_info(ctrl); in nvme_fw_act_work()
4713 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_fw_act_work()
4726 static bool nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result) in nvme_handle_aen_notice() argument
4731 trace_nvme_async_event(ctrl, aer_notice_type); in nvme_handle_aen_notice()
4735 set_bit(NVME_AER_NOTICE_NS_CHANGED, &ctrl->events); in nvme_handle_aen_notice()
4736 nvme_queue_scan(ctrl); in nvme_handle_aen_notice()
4744 if (nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) { in nvme_handle_aen_notice()
4745 nvme_auth_stop(ctrl); in nvme_handle_aen_notice()
4747 queue_work(nvme_wq, &ctrl->fw_act_work); in nvme_handle_aen_notice()
4752 if (!ctrl->ana_log_buf) in nvme_handle_aen_notice()
4754 queue_work(nvme_wq, &ctrl->ana_work); in nvme_handle_aen_notice()
4758 ctrl->aen_result = result; in nvme_handle_aen_notice()
4761 dev_warn(ctrl->device, "async event result %08x\n", result); in nvme_handle_aen_notice()
4766 static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl) in nvme_handle_aer_persistent_error() argument
4768 trace_nvme_async_event(ctrl, NVME_AER_ERROR); in nvme_handle_aer_persistent_error()
4769 dev_warn(ctrl->device, "resetting controller due to AER\n"); in nvme_handle_aer_persistent_error()
4770 nvme_reset_ctrl(ctrl); in nvme_handle_aer_persistent_error()
4773 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status, in nvme_complete_async_event() argument
4786 requeue = nvme_handle_aen_notice(ctrl, result); in nvme_complete_async_event()
4794 nvme_handle_aer_persistent_error(ctrl); in nvme_complete_async_event()
4801 trace_nvme_async_event(ctrl, aer_type); in nvme_complete_async_event()
4802 ctrl->aen_result = result; in nvme_complete_async_event()
4809 queue_work(nvme_wq, &ctrl->async_event_work); in nvme_complete_async_event()
4813 int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_admin_tag_set() argument
4822 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_alloc_admin_tag_set()
4824 set->numa_node = ctrl->numa_node; in nvme_alloc_admin_tag_set()
4827 set->driver_data = ctrl; in nvme_alloc_admin_tag_set()
4834 ctrl->admin_q = blk_mq_init_queue(set); in nvme_alloc_admin_tag_set()
4835 if (IS_ERR(ctrl->admin_q)) { in nvme_alloc_admin_tag_set()
4836 ret = PTR_ERR(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4840 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_admin_tag_set()
4841 ctrl->fabrics_q = blk_mq_init_queue(set); in nvme_alloc_admin_tag_set()
4842 if (IS_ERR(ctrl->fabrics_q)) { in nvme_alloc_admin_tag_set()
4843 ret = PTR_ERR(ctrl->fabrics_q); in nvme_alloc_admin_tag_set()
4848 ctrl->admin_tagset = set; in nvme_alloc_admin_tag_set()
4852 blk_mq_destroy_queue(ctrl->admin_q); in nvme_alloc_admin_tag_set()
4854 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_alloc_admin_tag_set()
4859 void nvme_remove_admin_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_admin_tag_set() argument
4861 blk_mq_destroy_queue(ctrl->admin_q); in nvme_remove_admin_tag_set()
4862 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_remove_admin_tag_set()
4863 blk_mq_destroy_queue(ctrl->fabrics_q); in nvme_remove_admin_tag_set()
4864 blk_mq_free_tag_set(ctrl->admin_tagset); in nvme_remove_admin_tag_set()
4868 int nvme_alloc_io_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set, in nvme_alloc_io_tag_set() argument
4876 set->queue_depth = ctrl->sqsize + 1; in nvme_alloc_io_tag_set()
4878 set->numa_node = ctrl->numa_node; in nvme_alloc_io_tag_set()
4881 set->driver_data = ctrl; in nvme_alloc_io_tag_set()
4882 set->nr_hw_queues = ctrl->queue_count - 1; in nvme_alloc_io_tag_set()
4885 set->nr_maps = ctrl->opts->nr_poll_queues ? HCTX_MAX_TYPES : 2; in nvme_alloc_io_tag_set()
4890 if (ctrl->ops->flags & NVME_F_FABRICS) { in nvme_alloc_io_tag_set()
4891 ctrl->connect_q = blk_mq_init_queue(set); in nvme_alloc_io_tag_set()
4892 if (IS_ERR(ctrl->connect_q)) { in nvme_alloc_io_tag_set()
4893 ret = PTR_ERR(ctrl->connect_q); in nvme_alloc_io_tag_set()
4898 ctrl->tagset = set; in nvme_alloc_io_tag_set()
4907 void nvme_remove_io_tag_set(struct nvme_ctrl *ctrl) in nvme_remove_io_tag_set() argument
4909 if (ctrl->ops->flags & NVME_F_FABRICS) in nvme_remove_io_tag_set()
4910 blk_mq_destroy_queue(ctrl->connect_q); in nvme_remove_io_tag_set()
4911 blk_mq_free_tag_set(ctrl->tagset); in nvme_remove_io_tag_set()
4915 void nvme_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_stop_ctrl() argument
4917 nvme_mpath_stop(ctrl); in nvme_stop_ctrl()
4918 nvme_auth_stop(ctrl); in nvme_stop_ctrl()
4919 nvme_stop_keep_alive(ctrl); in nvme_stop_ctrl()
4920 nvme_stop_failfast_work(ctrl); in nvme_stop_ctrl()
4921 flush_work(&ctrl->async_event_work); in nvme_stop_ctrl()
4922 cancel_work_sync(&ctrl->fw_act_work); in nvme_stop_ctrl()
4923 if (ctrl->ops->stop_ctrl) in nvme_stop_ctrl()
4924 ctrl->ops->stop_ctrl(ctrl); in nvme_stop_ctrl()
4928 void nvme_start_ctrl(struct nvme_ctrl *ctrl) in nvme_start_ctrl() argument
4930 nvme_start_keep_alive(ctrl); in nvme_start_ctrl()
4932 nvme_enable_aen(ctrl); in nvme_start_ctrl()
4940 if (test_and_set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags) && in nvme_start_ctrl()
4941 nvme_discovery_ctrl(ctrl)) in nvme_start_ctrl()
4942 nvme_change_uevent(ctrl, "NVME_EVENT=rediscover"); in nvme_start_ctrl()
4944 if (ctrl->queue_count > 1) { in nvme_start_ctrl()
4945 nvme_queue_scan(ctrl); in nvme_start_ctrl()
4946 nvme_start_queues(ctrl); in nvme_start_ctrl()
4947 nvme_mpath_update(ctrl); in nvme_start_ctrl()
4950 nvme_change_uevent(ctrl, "NVME_EVENT=connected"); in nvme_start_ctrl()
4954 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) in nvme_uninit_ctrl() argument
4956 nvme_hwmon_exit(ctrl); in nvme_uninit_ctrl()
4957 nvme_fault_inject_fini(&ctrl->fault_inject); in nvme_uninit_ctrl()
4958 dev_pm_qos_hide_latency_tolerance(ctrl->device); in nvme_uninit_ctrl()
4959 cdev_device_del(&ctrl->cdev, ctrl->device); in nvme_uninit_ctrl()
4960 nvme_put_ctrl(ctrl); in nvme_uninit_ctrl()
4964 static void nvme_free_cels(struct nvme_ctrl *ctrl) in nvme_free_cels() argument
4969 xa_for_each(&ctrl->cels, i, cel) { in nvme_free_cels()
4970 xa_erase(&ctrl->cels, i); in nvme_free_cels()
4974 xa_destroy(&ctrl->cels); in nvme_free_cels()
4979 struct nvme_ctrl *ctrl = in nvme_free_ctrl() local
4981 struct nvme_subsystem *subsys = ctrl->subsys; in nvme_free_ctrl()
4983 if (!subsys || ctrl->instance != subsys->instance) in nvme_free_ctrl()
4984 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_free_ctrl()
4986 nvme_free_cels(ctrl); in nvme_free_ctrl()
4987 nvme_mpath_uninit(ctrl); in nvme_free_ctrl()
4988 nvme_auth_stop(ctrl); in nvme_free_ctrl()
4989 nvme_auth_free(ctrl); in nvme_free_ctrl()
4990 __free_page(ctrl->discard_page); in nvme_free_ctrl()
4994 list_del(&ctrl->subsys_entry); in nvme_free_ctrl()
4995 sysfs_remove_link(&subsys->dev.kobj, dev_name(ctrl->device)); in nvme_free_ctrl()
4999 ctrl->ops->free_ctrl(ctrl); in nvme_free_ctrl()
5010 int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, in nvme_init_ctrl() argument
5015 ctrl->state = NVME_CTRL_NEW; in nvme_init_ctrl()
5016 clear_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags); in nvme_init_ctrl()
5017 spin_lock_init(&ctrl->lock); in nvme_init_ctrl()
5018 mutex_init(&ctrl->scan_lock); in nvme_init_ctrl()
5019 INIT_LIST_HEAD(&ctrl->namespaces); in nvme_init_ctrl()
5020 xa_init(&ctrl->cels); in nvme_init_ctrl()
5021 init_rwsem(&ctrl->namespaces_rwsem); in nvme_init_ctrl()
5022 ctrl->dev = dev; in nvme_init_ctrl()
5023 ctrl->ops = ops; in nvme_init_ctrl()
5024 ctrl->quirks = quirks; in nvme_init_ctrl()
5025 ctrl->numa_node = NUMA_NO_NODE; in nvme_init_ctrl()
5026 INIT_WORK(&ctrl->scan_work, nvme_scan_work); in nvme_init_ctrl()
5027 INIT_WORK(&ctrl->async_event_work, nvme_async_event_work); in nvme_init_ctrl()
5028 INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work); in nvme_init_ctrl()
5029 INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work); in nvme_init_ctrl()
5030 init_waitqueue_head(&ctrl->state_wq); in nvme_init_ctrl()
5032 INIT_DELAYED_WORK(&ctrl->ka_work, nvme_keep_alive_work); in nvme_init_ctrl()
5033 INIT_DELAYED_WORK(&ctrl->failfast_work, nvme_failfast_work); in nvme_init_ctrl()
5034 memset(&ctrl->ka_cmd, 0, sizeof(ctrl->ka_cmd)); in nvme_init_ctrl()
5035 ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive; in nvme_init_ctrl()
5039 ctrl->discard_page = alloc_page(GFP_KERNEL); in nvme_init_ctrl()
5040 if (!ctrl->discard_page) { in nvme_init_ctrl()
5048 ctrl->instance = ret; in nvme_init_ctrl()
5050 device_initialize(&ctrl->ctrl_device); in nvme_init_ctrl()
5051 ctrl->device = &ctrl->ctrl_device; in nvme_init_ctrl()
5052 ctrl->device->devt = MKDEV(MAJOR(nvme_ctrl_base_chr_devt), in nvme_init_ctrl()
5053 ctrl->instance); in nvme_init_ctrl()
5054 ctrl->device->class = nvme_class; in nvme_init_ctrl()
5055 ctrl->device->parent = ctrl->dev; in nvme_init_ctrl()
5056 ctrl->device->groups = nvme_dev_attr_groups; in nvme_init_ctrl()
5057 ctrl->device->release = nvme_free_ctrl; in nvme_init_ctrl()
5058 dev_set_drvdata(ctrl->device, ctrl); in nvme_init_ctrl()
5059 ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance); in nvme_init_ctrl()
5063 nvme_get_ctrl(ctrl); in nvme_init_ctrl()
5064 cdev_init(&ctrl->cdev, &nvme_dev_fops); in nvme_init_ctrl()
5065 ctrl->cdev.owner = ops->module; in nvme_init_ctrl()
5066 ret = cdev_device_add(&ctrl->cdev, ctrl->device); in nvme_init_ctrl()
5074 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; in nvme_init_ctrl()
5075 dev_pm_qos_update_user_latency_tolerance(ctrl->device, in nvme_init_ctrl()
5078 nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); in nvme_init_ctrl()
5079 nvme_mpath_init_ctrl(ctrl); in nvme_init_ctrl()
5080 nvme_auth_init_ctrl(ctrl); in nvme_init_ctrl()
5084 nvme_put_ctrl(ctrl); in nvme_init_ctrl()
5085 kfree_const(ctrl->device->kobj.name); in nvme_init_ctrl()
5087 ida_free(&nvme_instance_ida, ctrl->instance); in nvme_init_ctrl()
5089 if (ctrl->discard_page) in nvme_init_ctrl()
5090 __free_page(ctrl->discard_page); in nvme_init_ctrl()
5130 * @ctrl: the dead controller that needs to end
5135 void nvme_kill_queues(struct nvme_ctrl *ctrl) in nvme_kill_queues() argument
5139 down_read(&ctrl->namespaces_rwsem); in nvme_kill_queues()
5142 if (ctrl->admin_q && !blk_queue_dying(ctrl->admin_q)) in nvme_kill_queues()
5143 nvme_start_admin_queue(ctrl); in nvme_kill_queues()
5145 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_kill_queues()
5148 up_read(&ctrl->namespaces_rwsem); in nvme_kill_queues()
5152 void nvme_unfreeze(struct nvme_ctrl *ctrl) in nvme_unfreeze() argument
5156 down_read(&ctrl->namespaces_rwsem); in nvme_unfreeze()
5157 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_unfreeze()
5159 up_read(&ctrl->namespaces_rwsem); in nvme_unfreeze()
5163 int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout) in nvme_wait_freeze_timeout() argument
5167 down_read(&ctrl->namespaces_rwsem); in nvme_wait_freeze_timeout()
5168 list_for_each_entry(ns, &ctrl->namespaces, list) { in nvme_wait_freeze_timeout()
5173 up_read(&ctrl->namespaces_rwsem); in nvme_wait_freeze_timeout()
5178 void nvme_wait_freeze(struct nvme_ctrl *ctrl) in nvme_wait_freeze() argument
5182 down_read(&ctrl->namespaces_rwsem); in nvme_wait_freeze()
5183 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_wait_freeze()
5185 up_read(&ctrl->namespaces_rwsem); in nvme_wait_freeze()
5189 void nvme_start_freeze(struct nvme_ctrl *ctrl) in nvme_start_freeze() argument
5193 down_read(&ctrl->namespaces_rwsem); in nvme_start_freeze()
5194 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_start_freeze()
5196 up_read(&ctrl->namespaces_rwsem); in nvme_start_freeze()
5200 void nvme_stop_queues(struct nvme_ctrl *ctrl) in nvme_stop_queues() argument
5204 down_read(&ctrl->namespaces_rwsem); in nvme_stop_queues()
5205 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_stop_queues()
5207 up_read(&ctrl->namespaces_rwsem); in nvme_stop_queues()
5211 void nvme_start_queues(struct nvme_ctrl *ctrl) in nvme_start_queues() argument
5215 down_read(&ctrl->namespaces_rwsem); in nvme_start_queues()
5216 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_start_queues()
5218 up_read(&ctrl->namespaces_rwsem); in nvme_start_queues()
5222 void nvme_stop_admin_queue(struct nvme_ctrl *ctrl) in nvme_stop_admin_queue() argument
5224 if (!test_and_set_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_stop_admin_queue()
5225 blk_mq_quiesce_queue(ctrl->admin_q); in nvme_stop_admin_queue()
5227 blk_mq_wait_quiesce_done(ctrl->admin_q); in nvme_stop_admin_queue()
5231 void nvme_start_admin_queue(struct nvme_ctrl *ctrl) in nvme_start_admin_queue() argument
5233 if (test_and_clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->flags)) in nvme_start_admin_queue()
5234 blk_mq_unquiesce_queue(ctrl->admin_q); in nvme_start_admin_queue()
5238 void nvme_sync_io_queues(struct nvme_ctrl *ctrl) in nvme_sync_io_queues() argument
5242 down_read(&ctrl->namespaces_rwsem); in nvme_sync_io_queues()
5243 list_for_each_entry(ns, &ctrl->namespaces, list) in nvme_sync_io_queues()
5245 up_read(&ctrl->namespaces_rwsem); in nvme_sync_io_queues()
5249 void nvme_sync_queues(struct nvme_ctrl *ctrl) in nvme_sync_queues() argument
5251 nvme_sync_io_queues(ctrl); in nvme_sync_queues()
5252 if (ctrl->admin_q) in nvme_sync_queues()
5253 blk_sync_queue(ctrl->admin_q); in nvme_sync_queues()