Lines Matching full:ctrl
140 static void nvmet_async_events_failall(struct nvmet_ctrl *ctrl) in nvmet_async_events_failall() argument
144 mutex_lock(&ctrl->lock); in nvmet_async_events_failall()
145 while (ctrl->nr_async_event_cmds) { in nvmet_async_events_failall()
146 req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds]; in nvmet_async_events_failall()
147 mutex_unlock(&ctrl->lock); in nvmet_async_events_failall()
149 mutex_lock(&ctrl->lock); in nvmet_async_events_failall()
151 mutex_unlock(&ctrl->lock); in nvmet_async_events_failall()
154 static void nvmet_async_events_process(struct nvmet_ctrl *ctrl) in nvmet_async_events_process() argument
159 mutex_lock(&ctrl->lock); in nvmet_async_events_process()
160 while (ctrl->nr_async_event_cmds && !list_empty(&ctrl->async_events)) { in nvmet_async_events_process()
161 aen = list_first_entry(&ctrl->async_events, in nvmet_async_events_process()
163 req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds]; in nvmet_async_events_process()
169 mutex_unlock(&ctrl->lock); in nvmet_async_events_process()
170 trace_nvmet_async_event(ctrl, req->cqe->result.u32); in nvmet_async_events_process()
172 mutex_lock(&ctrl->lock); in nvmet_async_events_process()
174 mutex_unlock(&ctrl->lock); in nvmet_async_events_process()
177 static void nvmet_async_events_free(struct nvmet_ctrl *ctrl) in nvmet_async_events_free() argument
181 mutex_lock(&ctrl->lock); in nvmet_async_events_free()
182 list_for_each_entry_safe(aen, tmp, &ctrl->async_events, entry) { in nvmet_async_events_free()
186 mutex_unlock(&ctrl->lock); in nvmet_async_events_free()
191 struct nvmet_ctrl *ctrl = in nvmet_async_event_work() local
194 nvmet_async_events_process(ctrl); in nvmet_async_event_work()
197 void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, in nvmet_add_async_event() argument
210 mutex_lock(&ctrl->lock); in nvmet_add_async_event()
211 list_add_tail(&aen->entry, &ctrl->async_events); in nvmet_add_async_event()
212 mutex_unlock(&ctrl->lock); in nvmet_add_async_event()
214 queue_work(nvmet_wq, &ctrl->async_event_work); in nvmet_add_async_event()
217 static void nvmet_add_to_changed_ns_log(struct nvmet_ctrl *ctrl, __le32 nsid) in nvmet_add_to_changed_ns_log() argument
221 mutex_lock(&ctrl->lock); in nvmet_add_to_changed_ns_log()
222 if (ctrl->nr_changed_ns > NVME_MAX_CHANGED_NAMESPACES) in nvmet_add_to_changed_ns_log()
225 for (i = 0; i < ctrl->nr_changed_ns; i++) { in nvmet_add_to_changed_ns_log()
226 if (ctrl->changed_ns_list[i] == nsid) in nvmet_add_to_changed_ns_log()
230 if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES) { in nvmet_add_to_changed_ns_log()
231 ctrl->changed_ns_list[0] = cpu_to_le32(0xffffffff); in nvmet_add_to_changed_ns_log()
232 ctrl->nr_changed_ns = U32_MAX; in nvmet_add_to_changed_ns_log()
236 ctrl->changed_ns_list[ctrl->nr_changed_ns++] = nsid; in nvmet_add_to_changed_ns_log()
238 mutex_unlock(&ctrl->lock); in nvmet_add_to_changed_ns_log()
243 struct nvmet_ctrl *ctrl; in nvmet_ns_changed() local
247 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_ns_changed()
248 nvmet_add_to_changed_ns_log(ctrl, cpu_to_le32(nsid)); in nvmet_ns_changed()
249 if (nvmet_aen_bit_disabled(ctrl, NVME_AEN_BIT_NS_ATTR)) in nvmet_ns_changed()
251 nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE, in nvmet_ns_changed()
260 struct nvmet_ctrl *ctrl; in nvmet_send_ana_event() local
263 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_send_ana_event()
264 if (port && ctrl->port != port) in nvmet_send_ana_event()
266 if (nvmet_aen_bit_disabled(ctrl, NVME_AEN_BIT_ANA_CHANGE)) in nvmet_send_ana_event()
268 nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE, in nvmet_send_ana_event()
309 struct nvmet_ctrl *ctrl; in nvmet_port_del_ctrls() local
312 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_port_del_ctrls()
313 if (ctrl->port == port) in nvmet_port_del_ctrls()
314 ctrl->ops->delete_ctrl(ctrl); in nvmet_port_del_ctrls()
386 struct nvmet_ctrl *ctrl = container_of(to_delayed_work(work), in nvmet_keep_alive_timer() local
388 bool reset_tbkas = ctrl->reset_tbkas; in nvmet_keep_alive_timer()
390 ctrl->reset_tbkas = false; in nvmet_keep_alive_timer()
392 pr_debug("ctrl %d reschedule traffic based keep-alive timer\n", in nvmet_keep_alive_timer()
393 ctrl->cntlid); in nvmet_keep_alive_timer()
394 queue_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_keep_alive_timer()
398 pr_err("ctrl %d keep-alive timer (%d seconds) expired!\n", in nvmet_keep_alive_timer()
399 ctrl->cntlid, ctrl->kato); in nvmet_keep_alive_timer()
401 nvmet_ctrl_fatal_error(ctrl); in nvmet_keep_alive_timer()
404 void nvmet_start_keep_alive_timer(struct nvmet_ctrl *ctrl) in nvmet_start_keep_alive_timer() argument
406 if (unlikely(ctrl->kato == 0)) in nvmet_start_keep_alive_timer()
409 pr_debug("ctrl %d start keep-alive timer for %d secs\n", in nvmet_start_keep_alive_timer()
410 ctrl->cntlid, ctrl->kato); in nvmet_start_keep_alive_timer()
412 queue_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_start_keep_alive_timer()
415 void nvmet_stop_keep_alive_timer(struct nvmet_ctrl *ctrl) in nvmet_stop_keep_alive_timer() argument
417 if (unlikely(ctrl->kato == 0)) in nvmet_stop_keep_alive_timer()
420 pr_debug("ctrl %d stop keep-alive\n", ctrl->cntlid); in nvmet_stop_keep_alive_timer()
422 cancel_delayed_work_sync(&ctrl->ka_work); in nvmet_stop_keep_alive_timer()
505 * Note: ctrl->subsys->lock should be held when calling this function
507 static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl, in nvmet_p2pmem_ns_add_p2p() argument
514 if (!ctrl->p2p_client || !ns->use_p2pmem) in nvmet_p2pmem_ns_add_p2p()
518 ret = pci_p2pdma_distance(ns->p2p_dev, ctrl->p2p_client, true); in nvmet_p2pmem_ns_add_p2p()
524 clients[0] = ctrl->p2p_client; in nvmet_p2pmem_ns_add_p2p()
530 dev_name(ctrl->p2p_client), ns->device_path); in nvmet_p2pmem_ns_add_p2p()
535 ret = radix_tree_insert(&ctrl->p2p_ns_map, ns->nsid, p2p_dev); in nvmet_p2pmem_ns_add_p2p()
558 struct nvmet_ctrl *ctrl; in nvmet_ns_enable() local
586 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_enable()
587 nvmet_p2pmem_ns_add_p2p(ctrl, ns); in nvmet_ns_enable()
614 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_enable()
615 pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid)); in nvmet_ns_enable()
624 struct nvmet_ctrl *ctrl; in nvmet_ns_disable() local
635 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_disable()
636 pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid)); in nvmet_ns_disable()
714 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_set_error() local
720 if (!ctrl || req->error_loc == NVMET_NO_ERROR_LOC) in nvmet_set_error()
723 spin_lock_irqsave(&ctrl->error_lock, flags); in nvmet_set_error()
724 ctrl->err_counter++; in nvmet_set_error()
726 &ctrl->slots[ctrl->err_counter % NVMET_ERROR_LOG_SLOTS]; in nvmet_set_error()
728 new_error_slot->error_count = cpu_to_le64(ctrl->err_counter); in nvmet_set_error()
735 spin_unlock_irqrestore(&ctrl->error_lock, flags); in nvmet_set_error()
769 void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq, in nvmet_cq_setup() argument
776 void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, in nvmet_sq_setup() argument
783 ctrl->sqs[qid] = sq; in nvmet_sq_setup()
795 struct nvmet_ctrl *ctrl = sq->ctrl; in nvmet_sq_destroy() local
801 if (ctrl && ctrl->sqs && ctrl->sqs[0] == sq) in nvmet_sq_destroy()
802 nvmet_async_events_failall(ctrl); in nvmet_sq_destroy()
810 * we must reference the ctrl again after waiting for inflight IO in nvmet_sq_destroy()
812 * store sq->ctrl locally, but before we killed the percpu_ref. the in nvmet_sq_destroy()
813 * admin connect allocates and assigns sq->ctrl, which now needs a in nvmet_sq_destroy()
814 * final ref put, as this ctrl is going away. in nvmet_sq_destroy()
816 ctrl = sq->ctrl; in nvmet_sq_destroy()
818 if (ctrl) { in nvmet_sq_destroy()
825 ctrl->reset_tbkas = true; in nvmet_sq_destroy()
826 sq->ctrl->sqs[sq->qid] = NULL; in nvmet_sq_destroy()
827 nvmet_ctrl_put(ctrl); in nvmet_sq_destroy()
828 sq->ctrl = NULL; /* allows reusing the queue later */ in nvmet_sq_destroy()
973 if (unlikely(!req->sq->ctrl)) in nvmet_req_init()
991 if (sq->ctrl) in nvmet_req_init()
992 sq->ctrl->reset_tbkas = true; in nvmet_req_init()
1065 !req->sq->ctrl || !req->sq->qid || !req->ns) in nvmet_req_find_p2p_dev()
1067 return radix_tree_lookup(&req->sq->ctrl->p2p_ns_map, req->ns->nsid); in nvmet_req_find_p2p_dev()
1163 static void nvmet_start_ctrl(struct nvmet_ctrl *ctrl) in nvmet_start_ctrl() argument
1165 lockdep_assert_held(&ctrl->lock); in nvmet_start_ctrl()
1173 if (!nvmet_is_disc_subsys(ctrl->subsys) && in nvmet_start_ctrl()
1174 (nvmet_cc_iosqes(ctrl->cc) != NVME_NVM_IOSQES || in nvmet_start_ctrl()
1175 nvmet_cc_iocqes(ctrl->cc) != NVME_NVM_IOCQES)) { in nvmet_start_ctrl()
1176 ctrl->csts = NVME_CSTS_CFS; in nvmet_start_ctrl()
1180 if (nvmet_cc_mps(ctrl->cc) != 0 || in nvmet_start_ctrl()
1181 nvmet_cc_ams(ctrl->cc) != 0 || in nvmet_start_ctrl()
1182 !nvmet_css_supported(nvmet_cc_css(ctrl->cc))) { in nvmet_start_ctrl()
1183 ctrl->csts = NVME_CSTS_CFS; in nvmet_start_ctrl()
1187 ctrl->csts = NVME_CSTS_RDY; in nvmet_start_ctrl()
1195 if (ctrl->kato) in nvmet_start_ctrl()
1196 mod_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_start_ctrl()
1199 static void nvmet_clear_ctrl(struct nvmet_ctrl *ctrl) in nvmet_clear_ctrl() argument
1201 lockdep_assert_held(&ctrl->lock); in nvmet_clear_ctrl()
1204 ctrl->csts &= ~NVME_CSTS_RDY; in nvmet_clear_ctrl()
1205 ctrl->cc = 0; in nvmet_clear_ctrl()
1208 void nvmet_update_cc(struct nvmet_ctrl *ctrl, u32 new) in nvmet_update_cc() argument
1212 mutex_lock(&ctrl->lock); in nvmet_update_cc()
1213 old = ctrl->cc; in nvmet_update_cc()
1214 ctrl->cc = new; in nvmet_update_cc()
1217 nvmet_start_ctrl(ctrl); in nvmet_update_cc()
1219 nvmet_clear_ctrl(ctrl); in nvmet_update_cc()
1221 nvmet_clear_ctrl(ctrl); in nvmet_update_cc()
1222 ctrl->csts |= NVME_CSTS_SHST_CMPLT; in nvmet_update_cc()
1225 ctrl->csts &= ~NVME_CSTS_SHST_CMPLT; in nvmet_update_cc()
1226 mutex_unlock(&ctrl->lock); in nvmet_update_cc()
1229 static void nvmet_init_cap(struct nvmet_ctrl *ctrl) in nvmet_init_cap() argument
1232 ctrl->cap = (1ULL << 37); in nvmet_init_cap()
1234 ctrl->cap |= (1ULL << 43); in nvmet_init_cap()
1236 ctrl->cap |= (15ULL << 24); in nvmet_init_cap()
1238 if (ctrl->ops->get_max_queue_size) in nvmet_init_cap()
1239 ctrl->cap |= ctrl->ops->get_max_queue_size(ctrl) - 1; in nvmet_init_cap()
1241 ctrl->cap |= NVMET_QUEUE_SIZE - 1; in nvmet_init_cap()
1243 if (nvmet_is_passthru_subsys(ctrl->subsys)) in nvmet_init_cap()
1244 nvmet_passthrough_override_cap(ctrl); in nvmet_init_cap()
1251 struct nvmet_ctrl *ctrl = NULL; in nvmet_ctrl_find_get() local
1263 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_ctrl_find_get()
1264 if (ctrl->cntlid == cntlid) { in nvmet_ctrl_find_get()
1265 if (strncmp(hostnqn, ctrl->hostnqn, NVMF_NQN_SIZE)) { in nvmet_ctrl_find_get()
1269 if (!kref_get_unless_zero(&ctrl->ref)) in nvmet_ctrl_find_get()
1272 /* ctrl found */ in nvmet_ctrl_find_get()
1277 ctrl = NULL; /* ctrl not found */ in nvmet_ctrl_find_get()
1286 return ctrl; in nvmet_ctrl_find_get()
1291 if (unlikely(!(req->sq->ctrl->cc & NVME_CC_ENABLE))) { in nvmet_check_ctrl_status()
1297 if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) { in nvmet_check_ctrl_status()
1331 * Note: ctrl->subsys->lock should be held when calling this function
1333 static void nvmet_setup_p2p_ns_map(struct nvmet_ctrl *ctrl, in nvmet_setup_p2p_ns_map() argument
1342 ctrl->p2p_client = get_device(req->p2p_client); in nvmet_setup_p2p_ns_map()
1344 xa_for_each(&ctrl->subsys->namespaces, idx, ns) in nvmet_setup_p2p_ns_map()
1345 nvmet_p2pmem_ns_add_p2p(ctrl, ns); in nvmet_setup_p2p_ns_map()
1349 * Note: ctrl->subsys->lock should be held when calling this function
1351 static void nvmet_release_p2p_ns_map(struct nvmet_ctrl *ctrl) in nvmet_release_p2p_ns_map() argument
1356 radix_tree_for_each_slot(slot, &ctrl->p2p_ns_map, &iter, 0) in nvmet_release_p2p_ns_map()
1359 put_device(ctrl->p2p_client); in nvmet_release_p2p_ns_map()
1364 struct nvmet_ctrl *ctrl = in nvmet_fatal_error_handler() local
1367 pr_err("ctrl %d fatal error occurred!\n", ctrl->cntlid); in nvmet_fatal_error_handler()
1368 ctrl->ops->delete_ctrl(ctrl); in nvmet_fatal_error_handler()
1375 struct nvmet_ctrl *ctrl; in nvmet_alloc_ctrl() local
1402 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); in nvmet_alloc_ctrl()
1403 if (!ctrl) in nvmet_alloc_ctrl()
1405 mutex_init(&ctrl->lock); in nvmet_alloc_ctrl()
1407 ctrl->port = req->port; in nvmet_alloc_ctrl()
1408 ctrl->ops = req->ops; in nvmet_alloc_ctrl()
1412 if (ctrl->port->disc_addr.trtype == NVMF_TRTYPE_LOOP) in nvmet_alloc_ctrl()
1416 INIT_WORK(&ctrl->async_event_work, nvmet_async_event_work); in nvmet_alloc_ctrl()
1417 INIT_LIST_HEAD(&ctrl->async_events); in nvmet_alloc_ctrl()
1418 INIT_RADIX_TREE(&ctrl->p2p_ns_map, GFP_KERNEL); in nvmet_alloc_ctrl()
1419 INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler); in nvmet_alloc_ctrl()
1420 INIT_DELAYED_WORK(&ctrl->ka_work, nvmet_keep_alive_timer); in nvmet_alloc_ctrl()
1422 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE); in nvmet_alloc_ctrl()
1423 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE); in nvmet_alloc_ctrl()
1425 kref_init(&ctrl->ref); in nvmet_alloc_ctrl()
1426 ctrl->subsys = subsys; in nvmet_alloc_ctrl()
1427 nvmet_init_cap(ctrl); in nvmet_alloc_ctrl()
1428 WRITE_ONCE(ctrl->aen_enabled, NVMET_AEN_CFG_OPTIONAL); in nvmet_alloc_ctrl()
1430 ctrl->changed_ns_list = kmalloc_array(NVME_MAX_CHANGED_NAMESPACES, in nvmet_alloc_ctrl()
1432 if (!ctrl->changed_ns_list) in nvmet_alloc_ctrl()
1435 ctrl->sqs = kcalloc(subsys->max_qid + 1, in nvmet_alloc_ctrl()
1438 if (!ctrl->sqs) in nvmet_alloc_ctrl()
1451 ctrl->cntlid = ret; in nvmet_alloc_ctrl()
1457 if (nvmet_is_disc_subsys(ctrl->subsys) && !kato) in nvmet_alloc_ctrl()
1461 ctrl->kato = DIV_ROUND_UP(kato, 1000); in nvmet_alloc_ctrl()
1463 ctrl->err_counter = 0; in nvmet_alloc_ctrl()
1464 spin_lock_init(&ctrl->error_lock); in nvmet_alloc_ctrl()
1466 nvmet_start_keep_alive_timer(ctrl); in nvmet_alloc_ctrl()
1469 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvmet_alloc_ctrl()
1470 nvmet_setup_p2p_ns_map(ctrl, req); in nvmet_alloc_ctrl()
1473 *ctrlp = ctrl; in nvmet_alloc_ctrl()
1477 kfree(ctrl->sqs); in nvmet_alloc_ctrl()
1479 kfree(ctrl->changed_ns_list); in nvmet_alloc_ctrl()
1481 kfree(ctrl); in nvmet_alloc_ctrl()
1490 struct nvmet_ctrl *ctrl = container_of(ref, struct nvmet_ctrl, ref); in nvmet_ctrl_free() local
1491 struct nvmet_subsys *subsys = ctrl->subsys; in nvmet_ctrl_free()
1494 nvmet_release_p2p_ns_map(ctrl); in nvmet_ctrl_free()
1495 list_del(&ctrl->subsys_entry); in nvmet_ctrl_free()
1498 nvmet_stop_keep_alive_timer(ctrl); in nvmet_ctrl_free()
1500 flush_work(&ctrl->async_event_work); in nvmet_ctrl_free()
1501 cancel_work_sync(&ctrl->fatal_err_work); in nvmet_ctrl_free()
1503 nvmet_destroy_auth(ctrl); in nvmet_ctrl_free()
1505 ida_free(&cntlid_ida, ctrl->cntlid); in nvmet_ctrl_free()
1507 nvmet_async_events_free(ctrl); in nvmet_ctrl_free()
1508 kfree(ctrl->sqs); in nvmet_ctrl_free()
1509 kfree(ctrl->changed_ns_list); in nvmet_ctrl_free()
1510 kfree(ctrl); in nvmet_ctrl_free()
1515 void nvmet_ctrl_put(struct nvmet_ctrl *ctrl) in nvmet_ctrl_put() argument
1517 kref_put(&ctrl->ref, nvmet_ctrl_free); in nvmet_ctrl_put()
1520 void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl) in nvmet_ctrl_fatal_error() argument
1522 mutex_lock(&ctrl->lock); in nvmet_ctrl_fatal_error()
1523 if (!(ctrl->csts & NVME_CSTS_CFS)) { in nvmet_ctrl_fatal_error()
1524 ctrl->csts |= NVME_CSTS_CFS; in nvmet_ctrl_fatal_error()
1525 queue_work(nvmet_wq, &ctrl->fatal_err_work); in nvmet_ctrl_fatal_error()
1527 mutex_unlock(&ctrl->lock); in nvmet_ctrl_fatal_error()
1647 struct nvmet_ctrl *ctrl; in nvmet_subsys_del_ctrls() local
1650 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_subsys_del_ctrls()
1651 ctrl->ops->delete_ctrl(ctrl); in nvmet_subsys_del_ctrls()