Lines Matching full:ctrl

141 static void nvmet_async_events_failall(struct nvmet_ctrl *ctrl)  in nvmet_async_events_failall()  argument
145 mutex_lock(&ctrl->lock); in nvmet_async_events_failall()
146 while (ctrl->nr_async_event_cmds) { in nvmet_async_events_failall()
147 req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds]; in nvmet_async_events_failall()
148 mutex_unlock(&ctrl->lock); in nvmet_async_events_failall()
150 mutex_lock(&ctrl->lock); in nvmet_async_events_failall()
152 mutex_unlock(&ctrl->lock); in nvmet_async_events_failall()
155 static void nvmet_async_events_process(struct nvmet_ctrl *ctrl) in nvmet_async_events_process() argument
160 mutex_lock(&ctrl->lock); in nvmet_async_events_process()
161 while (ctrl->nr_async_event_cmds && !list_empty(&ctrl->async_events)) { in nvmet_async_events_process()
162 aen = list_first_entry(&ctrl->async_events, in nvmet_async_events_process()
164 req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds]; in nvmet_async_events_process()
170 mutex_unlock(&ctrl->lock); in nvmet_async_events_process()
171 trace_nvmet_async_event(ctrl, req->cqe->result.u32); in nvmet_async_events_process()
173 mutex_lock(&ctrl->lock); in nvmet_async_events_process()
175 mutex_unlock(&ctrl->lock); in nvmet_async_events_process()
178 static void nvmet_async_events_free(struct nvmet_ctrl *ctrl) in nvmet_async_events_free() argument
182 mutex_lock(&ctrl->lock); in nvmet_async_events_free()
183 list_for_each_entry_safe(aen, tmp, &ctrl->async_events, entry) { in nvmet_async_events_free()
187 mutex_unlock(&ctrl->lock); in nvmet_async_events_free()
192 struct nvmet_ctrl *ctrl = in nvmet_async_event_work() local
195 nvmet_async_events_process(ctrl); in nvmet_async_event_work()
198 void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, in nvmet_add_async_event() argument
211 mutex_lock(&ctrl->lock); in nvmet_add_async_event()
212 list_add_tail(&aen->entry, &ctrl->async_events); in nvmet_add_async_event()
213 mutex_unlock(&ctrl->lock); in nvmet_add_async_event()
215 queue_work(nvmet_wq, &ctrl->async_event_work); in nvmet_add_async_event()
218 static void nvmet_add_to_changed_ns_log(struct nvmet_ctrl *ctrl, __le32 nsid) in nvmet_add_to_changed_ns_log() argument
222 mutex_lock(&ctrl->lock); in nvmet_add_to_changed_ns_log()
223 if (ctrl->nr_changed_ns > NVME_MAX_CHANGED_NAMESPACES) in nvmet_add_to_changed_ns_log()
226 for (i = 0; i < ctrl->nr_changed_ns; i++) { in nvmet_add_to_changed_ns_log()
227 if (ctrl->changed_ns_list[i] == nsid) in nvmet_add_to_changed_ns_log()
231 if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES) { in nvmet_add_to_changed_ns_log()
232 ctrl->changed_ns_list[0] = cpu_to_le32(0xffffffff); in nvmet_add_to_changed_ns_log()
233 ctrl->nr_changed_ns = U32_MAX; in nvmet_add_to_changed_ns_log()
237 ctrl->changed_ns_list[ctrl->nr_changed_ns++] = nsid; in nvmet_add_to_changed_ns_log()
239 mutex_unlock(&ctrl->lock); in nvmet_add_to_changed_ns_log()
244 struct nvmet_ctrl *ctrl; in nvmet_ns_changed() local
248 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_ns_changed()
249 nvmet_add_to_changed_ns_log(ctrl, cpu_to_le32(nsid)); in nvmet_ns_changed()
250 if (nvmet_aen_bit_disabled(ctrl, NVME_AEN_BIT_NS_ATTR)) in nvmet_ns_changed()
252 nvmet_add_async_event(ctrl, NVME_AER_NOTICE, in nvmet_ns_changed()
261 struct nvmet_ctrl *ctrl; in nvmet_send_ana_event() local
264 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_send_ana_event()
265 if (port && ctrl->port != port) in nvmet_send_ana_event()
267 if (nvmet_aen_bit_disabled(ctrl, NVME_AEN_BIT_ANA_CHANGE)) in nvmet_send_ana_event()
269 nvmet_add_async_event(ctrl, NVME_AER_NOTICE, in nvmet_send_ana_event()
310 struct nvmet_ctrl *ctrl; in nvmet_port_del_ctrls() local
313 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_port_del_ctrls()
314 if (ctrl->port == port) in nvmet_port_del_ctrls()
315 ctrl->ops->delete_ctrl(ctrl); in nvmet_port_del_ctrls()
399 struct nvmet_ctrl *ctrl = container_of(to_delayed_work(work), in nvmet_keep_alive_timer() local
401 bool reset_tbkas = ctrl->reset_tbkas; in nvmet_keep_alive_timer()
403 ctrl->reset_tbkas = false; in nvmet_keep_alive_timer()
405 pr_debug("ctrl %d reschedule traffic based keep-alive timer\n", in nvmet_keep_alive_timer()
406 ctrl->cntlid); in nvmet_keep_alive_timer()
407 queue_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_keep_alive_timer()
411 pr_err("ctrl %d keep-alive timer (%d seconds) expired!\n", in nvmet_keep_alive_timer()
412 ctrl->cntlid, ctrl->kato); in nvmet_keep_alive_timer()
414 nvmet_ctrl_fatal_error(ctrl); in nvmet_keep_alive_timer()
417 void nvmet_start_keep_alive_timer(struct nvmet_ctrl *ctrl) in nvmet_start_keep_alive_timer() argument
419 if (unlikely(ctrl->kato == 0)) in nvmet_start_keep_alive_timer()
422 pr_debug("ctrl %d start keep-alive timer for %d secs\n", in nvmet_start_keep_alive_timer()
423 ctrl->cntlid, ctrl->kato); in nvmet_start_keep_alive_timer()
425 queue_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_start_keep_alive_timer()
428 void nvmet_stop_keep_alive_timer(struct nvmet_ctrl *ctrl) in nvmet_stop_keep_alive_timer() argument
430 if (unlikely(ctrl->kato == 0)) in nvmet_stop_keep_alive_timer()
433 pr_debug("ctrl %d stop keep-alive\n", ctrl->cntlid); in nvmet_stop_keep_alive_timer()
435 cancel_delayed_work_sync(&ctrl->ka_work); in nvmet_stop_keep_alive_timer()
518 * Note: ctrl->subsys->lock should be held when calling this function
520 static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl, in nvmet_p2pmem_ns_add_p2p() argument
527 if (!ctrl->p2p_client || !ns->use_p2pmem) in nvmet_p2pmem_ns_add_p2p()
531 ret = pci_p2pdma_distance(ns->p2p_dev, ctrl->p2p_client, true); in nvmet_p2pmem_ns_add_p2p()
537 clients[0] = ctrl->p2p_client; in nvmet_p2pmem_ns_add_p2p()
543 dev_name(ctrl->p2p_client), ns->device_path); in nvmet_p2pmem_ns_add_p2p()
548 ret = radix_tree_insert(&ctrl->p2p_ns_map, ns->nsid, p2p_dev); in nvmet_p2pmem_ns_add_p2p()
571 struct nvmet_ctrl *ctrl; in nvmet_ns_enable() local
599 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_enable()
600 nvmet_p2pmem_ns_add_p2p(ctrl, ns); in nvmet_ns_enable()
627 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_enable()
628 pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid)); in nvmet_ns_enable()
637 struct nvmet_ctrl *ctrl; in nvmet_ns_disable() local
648 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_disable()
649 pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid)); in nvmet_ns_disable()
727 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_set_error() local
733 if (!ctrl || req->error_loc == NVMET_NO_ERROR_LOC) in nvmet_set_error()
736 spin_lock_irqsave(&ctrl->error_lock, flags); in nvmet_set_error()
737 ctrl->err_counter++; in nvmet_set_error()
739 &ctrl->slots[ctrl->err_counter % NVMET_ERROR_LOG_SLOTS]; in nvmet_set_error()
741 new_error_slot->error_count = cpu_to_le64(ctrl->err_counter); in nvmet_set_error()
748 spin_unlock_irqrestore(&ctrl->error_lock, flags); in nvmet_set_error()
782 void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq, in nvmet_cq_setup() argument
789 void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, in nvmet_sq_setup() argument
796 ctrl->sqs[qid] = sq; in nvmet_sq_setup()
808 struct nvmet_ctrl *ctrl = sq->ctrl; in nvmet_sq_destroy() local
814 if (ctrl && ctrl->sqs && ctrl->sqs[0] == sq) in nvmet_sq_destroy()
815 nvmet_async_events_failall(ctrl); in nvmet_sq_destroy()
823 * we must reference the ctrl again after waiting for inflight IO in nvmet_sq_destroy()
825 * store sq->ctrl locally, but before we killed the percpu_ref. the in nvmet_sq_destroy()
826 * admin connect allocates and assigns sq->ctrl, which now needs a in nvmet_sq_destroy()
827 * final ref put, as this ctrl is going away. in nvmet_sq_destroy()
829 ctrl = sq->ctrl; in nvmet_sq_destroy()
831 if (ctrl) { in nvmet_sq_destroy()
838 ctrl->reset_tbkas = true; in nvmet_sq_destroy()
839 sq->ctrl->sqs[sq->qid] = NULL; in nvmet_sq_destroy()
840 nvmet_ctrl_put(ctrl); in nvmet_sq_destroy()
841 sq->ctrl = NULL; /* allows reusing the queue later */ in nvmet_sq_destroy()
986 if (unlikely(!req->sq->ctrl)) in nvmet_req_init()
1004 if (sq->ctrl) in nvmet_req_init()
1005 sq->ctrl->reset_tbkas = true; in nvmet_req_init()
1078 !req->sq->ctrl || !req->sq->qid || !req->ns) in nvmet_req_find_p2p_dev()
1080 return radix_tree_lookup(&req->sq->ctrl->p2p_ns_map, req->ns->nsid); in nvmet_req_find_p2p_dev()
1176 static void nvmet_start_ctrl(struct nvmet_ctrl *ctrl) in nvmet_start_ctrl() argument
1178 lockdep_assert_held(&ctrl->lock); in nvmet_start_ctrl()
1186 if (!nvmet_is_disc_subsys(ctrl->subsys) && in nvmet_start_ctrl()
1187 (nvmet_cc_iosqes(ctrl->cc) != NVME_NVM_IOSQES || in nvmet_start_ctrl()
1188 nvmet_cc_iocqes(ctrl->cc) != NVME_NVM_IOCQES)) { in nvmet_start_ctrl()
1189 ctrl->csts = NVME_CSTS_CFS; in nvmet_start_ctrl()
1193 if (nvmet_cc_mps(ctrl->cc) != 0 || in nvmet_start_ctrl()
1194 nvmet_cc_ams(ctrl->cc) != 0 || in nvmet_start_ctrl()
1195 !nvmet_css_supported(nvmet_cc_css(ctrl->cc))) { in nvmet_start_ctrl()
1196 ctrl->csts = NVME_CSTS_CFS; in nvmet_start_ctrl()
1200 ctrl->csts = NVME_CSTS_RDY; in nvmet_start_ctrl()
1208 if (ctrl->kato) in nvmet_start_ctrl()
1209 mod_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_start_ctrl()
1212 static void nvmet_clear_ctrl(struct nvmet_ctrl *ctrl) in nvmet_clear_ctrl() argument
1214 lockdep_assert_held(&ctrl->lock); in nvmet_clear_ctrl()
1217 ctrl->csts &= ~NVME_CSTS_RDY; in nvmet_clear_ctrl()
1218 ctrl->cc = 0; in nvmet_clear_ctrl()
1221 void nvmet_update_cc(struct nvmet_ctrl *ctrl, u32 new) in nvmet_update_cc() argument
1225 mutex_lock(&ctrl->lock); in nvmet_update_cc()
1226 old = ctrl->cc; in nvmet_update_cc()
1227 ctrl->cc = new; in nvmet_update_cc()
1230 nvmet_start_ctrl(ctrl); in nvmet_update_cc()
1232 nvmet_clear_ctrl(ctrl); in nvmet_update_cc()
1234 nvmet_clear_ctrl(ctrl); in nvmet_update_cc()
1235 ctrl->csts |= NVME_CSTS_SHST_CMPLT; in nvmet_update_cc()
1238 ctrl->csts &= ~NVME_CSTS_SHST_CMPLT; in nvmet_update_cc()
1239 mutex_unlock(&ctrl->lock); in nvmet_update_cc()
1242 static void nvmet_init_cap(struct nvmet_ctrl *ctrl) in nvmet_init_cap() argument
1245 ctrl->cap = (1ULL << 37); in nvmet_init_cap()
1247 ctrl->cap |= (1ULL << 43); in nvmet_init_cap()
1249 ctrl->cap |= (15ULL << 24); in nvmet_init_cap()
1251 if (ctrl->ops->get_max_queue_size) in nvmet_init_cap()
1252 ctrl->cap |= min_t(u16, ctrl->ops->get_max_queue_size(ctrl), in nvmet_init_cap()
1253 ctrl->port->max_queue_size) - 1; in nvmet_init_cap()
1255 ctrl->cap |= ctrl->port->max_queue_size - 1; in nvmet_init_cap()
1257 if (nvmet_is_passthru_subsys(ctrl->subsys)) in nvmet_init_cap()
1258 nvmet_passthrough_override_cap(ctrl); in nvmet_init_cap()
1265 struct nvmet_ctrl *ctrl = NULL; in nvmet_ctrl_find_get() local
1277 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_ctrl_find_get()
1278 if (ctrl->cntlid == cntlid) { in nvmet_ctrl_find_get()
1279 if (strncmp(hostnqn, ctrl->hostnqn, NVMF_NQN_SIZE)) { in nvmet_ctrl_find_get()
1283 if (!kref_get_unless_zero(&ctrl->ref)) in nvmet_ctrl_find_get()
1286 /* ctrl found */ in nvmet_ctrl_find_get()
1291 ctrl = NULL; /* ctrl not found */ in nvmet_ctrl_find_get()
1300 return ctrl; in nvmet_ctrl_find_get()
1305 if (unlikely(!(req->sq->ctrl->cc & NVME_CC_ENABLE))) { in nvmet_check_ctrl_status()
1311 if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) { in nvmet_check_ctrl_status()
1345 * Note: ctrl->subsys->lock should be held when calling this function
1347 static void nvmet_setup_p2p_ns_map(struct nvmet_ctrl *ctrl, in nvmet_setup_p2p_ns_map() argument
1356 ctrl->p2p_client = get_device(req->p2p_client); in nvmet_setup_p2p_ns_map()
1358 xa_for_each(&ctrl->subsys->namespaces, idx, ns) in nvmet_setup_p2p_ns_map()
1359 nvmet_p2pmem_ns_add_p2p(ctrl, ns); in nvmet_setup_p2p_ns_map()
1363 * Note: ctrl->subsys->lock should be held when calling this function
1365 static void nvmet_release_p2p_ns_map(struct nvmet_ctrl *ctrl) in nvmet_release_p2p_ns_map() argument
1370 radix_tree_for_each_slot(slot, &ctrl->p2p_ns_map, &iter, 0) in nvmet_release_p2p_ns_map()
1373 put_device(ctrl->p2p_client); in nvmet_release_p2p_ns_map()
1378 struct nvmet_ctrl *ctrl = in nvmet_fatal_error_handler() local
1381 pr_err("ctrl %d fatal error occurred!\n", ctrl->cntlid); in nvmet_fatal_error_handler()
1382 ctrl->ops->delete_ctrl(ctrl); in nvmet_fatal_error_handler()
1389 struct nvmet_ctrl *ctrl; in nvmet_alloc_ctrl() local
1416 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); in nvmet_alloc_ctrl()
1417 if (!ctrl) in nvmet_alloc_ctrl()
1419 mutex_init(&ctrl->lock); in nvmet_alloc_ctrl()
1421 ctrl->port = req->port; in nvmet_alloc_ctrl()
1422 ctrl->ops = req->ops; in nvmet_alloc_ctrl()
1426 if (ctrl->port->disc_addr.trtype == NVMF_TRTYPE_LOOP) in nvmet_alloc_ctrl()
1430 INIT_WORK(&ctrl->async_event_work, nvmet_async_event_work); in nvmet_alloc_ctrl()
1431 INIT_LIST_HEAD(&ctrl->async_events); in nvmet_alloc_ctrl()
1432 INIT_RADIX_TREE(&ctrl->p2p_ns_map, GFP_KERNEL); in nvmet_alloc_ctrl()
1433 INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler); in nvmet_alloc_ctrl()
1434 INIT_DELAYED_WORK(&ctrl->ka_work, nvmet_keep_alive_timer); in nvmet_alloc_ctrl()
1436 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE); in nvmet_alloc_ctrl()
1437 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE); in nvmet_alloc_ctrl()
1439 kref_init(&ctrl->ref); in nvmet_alloc_ctrl()
1440 ctrl->subsys = subsys; in nvmet_alloc_ctrl()
1441 ctrl->pi_support = ctrl->port->pi_enable && ctrl->subsys->pi_support; in nvmet_alloc_ctrl()
1442 nvmet_init_cap(ctrl); in nvmet_alloc_ctrl()
1443 WRITE_ONCE(ctrl->aen_enabled, NVMET_AEN_CFG_OPTIONAL); in nvmet_alloc_ctrl()
1445 ctrl->changed_ns_list = kmalloc_array(NVME_MAX_CHANGED_NAMESPACES, in nvmet_alloc_ctrl()
1447 if (!ctrl->changed_ns_list) in nvmet_alloc_ctrl()
1450 ctrl->sqs = kcalloc(subsys->max_qid + 1, in nvmet_alloc_ctrl()
1453 if (!ctrl->sqs) in nvmet_alloc_ctrl()
1463 ctrl->cntlid = ret; in nvmet_alloc_ctrl()
1469 if (nvmet_is_disc_subsys(ctrl->subsys) && !kato) in nvmet_alloc_ctrl()
1473 ctrl->kato = DIV_ROUND_UP(kato, 1000); in nvmet_alloc_ctrl()
1475 ctrl->err_counter = 0; in nvmet_alloc_ctrl()
1476 spin_lock_init(&ctrl->error_lock); in nvmet_alloc_ctrl()
1478 nvmet_start_keep_alive_timer(ctrl); in nvmet_alloc_ctrl()
1481 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvmet_alloc_ctrl()
1482 nvmet_setup_p2p_ns_map(ctrl, req); in nvmet_alloc_ctrl()
1483 nvmet_debugfs_ctrl_setup(ctrl); in nvmet_alloc_ctrl()
1486 *ctrlp = ctrl; in nvmet_alloc_ctrl()
1490 kfree(ctrl->sqs); in nvmet_alloc_ctrl()
1492 kfree(ctrl->changed_ns_list); in nvmet_alloc_ctrl()
1494 kfree(ctrl); in nvmet_alloc_ctrl()
1503 struct nvmet_ctrl *ctrl = container_of(ref, struct nvmet_ctrl, ref); in nvmet_ctrl_free() local
1504 struct nvmet_subsys *subsys = ctrl->subsys; in nvmet_ctrl_free()
1507 nvmet_release_p2p_ns_map(ctrl); in nvmet_ctrl_free()
1508 list_del(&ctrl->subsys_entry); in nvmet_ctrl_free()
1511 nvmet_stop_keep_alive_timer(ctrl); in nvmet_ctrl_free()
1513 flush_work(&ctrl->async_event_work); in nvmet_ctrl_free()
1514 cancel_work_sync(&ctrl->fatal_err_work); in nvmet_ctrl_free()
1516 nvmet_destroy_auth(ctrl); in nvmet_ctrl_free()
1518 nvmet_debugfs_ctrl_free(ctrl); in nvmet_ctrl_free()
1520 ida_free(&cntlid_ida, ctrl->cntlid); in nvmet_ctrl_free()
1522 nvmet_async_events_free(ctrl); in nvmet_ctrl_free()
1523 kfree(ctrl->sqs); in nvmet_ctrl_free()
1524 kfree(ctrl->changed_ns_list); in nvmet_ctrl_free()
1525 kfree(ctrl); in nvmet_ctrl_free()
1530 void nvmet_ctrl_put(struct nvmet_ctrl *ctrl) in nvmet_ctrl_put() argument
1532 kref_put(&ctrl->ref, nvmet_ctrl_free); in nvmet_ctrl_put()
1535 void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl) in nvmet_ctrl_fatal_error() argument
1537 mutex_lock(&ctrl->lock); in nvmet_ctrl_fatal_error()
1538 if (!(ctrl->csts & NVME_CSTS_CFS)) { in nvmet_ctrl_fatal_error()
1539 ctrl->csts |= NVME_CSTS_CFS; in nvmet_ctrl_fatal_error()
1540 queue_work(nvmet_wq, &ctrl->fatal_err_work); in nvmet_ctrl_fatal_error()
1542 mutex_unlock(&ctrl->lock); in nvmet_ctrl_fatal_error()
1546 ssize_t nvmet_ctrl_host_traddr(struct nvmet_ctrl *ctrl, in nvmet_ctrl_host_traddr() argument
1549 if (!ctrl->ops->host_traddr) in nvmet_ctrl_host_traddr()
1551 return ctrl->ops->host_traddr(ctrl, traddr, traddr_len); in nvmet_ctrl_host_traddr()
1685 struct nvmet_ctrl *ctrl; in nvmet_subsys_del_ctrls() local
1688 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_subsys_del_ctrls()
1689 ctrl->ops->delete_ctrl(ctrl); in nvmet_subsys_del_ctrls()