Lines Matching full:ctrl

137 static void nvmet_async_events_failall(struct nvmet_ctrl *ctrl)  in nvmet_async_events_failall()  argument
141 mutex_lock(&ctrl->lock); in nvmet_async_events_failall()
142 while (ctrl->nr_async_event_cmds) { in nvmet_async_events_failall()
143 req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds]; in nvmet_async_events_failall()
144 mutex_unlock(&ctrl->lock); in nvmet_async_events_failall()
146 mutex_lock(&ctrl->lock); in nvmet_async_events_failall()
148 mutex_unlock(&ctrl->lock); in nvmet_async_events_failall()
151 static void nvmet_async_events_process(struct nvmet_ctrl *ctrl) in nvmet_async_events_process() argument
156 mutex_lock(&ctrl->lock); in nvmet_async_events_process()
157 while (ctrl->nr_async_event_cmds && !list_empty(&ctrl->async_events)) { in nvmet_async_events_process()
158 aen = list_first_entry(&ctrl->async_events, in nvmet_async_events_process()
160 req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds]; in nvmet_async_events_process()
166 mutex_unlock(&ctrl->lock); in nvmet_async_events_process()
167 trace_nvmet_async_event(ctrl, req->cqe->result.u32); in nvmet_async_events_process()
169 mutex_lock(&ctrl->lock); in nvmet_async_events_process()
171 mutex_unlock(&ctrl->lock); in nvmet_async_events_process()
174 static void nvmet_async_events_free(struct nvmet_ctrl *ctrl) in nvmet_async_events_free() argument
178 mutex_lock(&ctrl->lock); in nvmet_async_events_free()
179 list_for_each_entry_safe(aen, tmp, &ctrl->async_events, entry) { in nvmet_async_events_free()
183 mutex_unlock(&ctrl->lock); in nvmet_async_events_free()
188 struct nvmet_ctrl *ctrl = in nvmet_async_event_work() local
191 nvmet_async_events_process(ctrl); in nvmet_async_event_work()
194 void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type, in nvmet_add_async_event() argument
207 mutex_lock(&ctrl->lock); in nvmet_add_async_event()
208 list_add_tail(&aen->entry, &ctrl->async_events); in nvmet_add_async_event()
209 mutex_unlock(&ctrl->lock); in nvmet_add_async_event()
211 queue_work(nvmet_wq, &ctrl->async_event_work); in nvmet_add_async_event()
214 static void nvmet_add_to_changed_ns_log(struct nvmet_ctrl *ctrl, __le32 nsid) in nvmet_add_to_changed_ns_log() argument
218 mutex_lock(&ctrl->lock); in nvmet_add_to_changed_ns_log()
219 if (ctrl->nr_changed_ns > NVME_MAX_CHANGED_NAMESPACES) in nvmet_add_to_changed_ns_log()
222 for (i = 0; i < ctrl->nr_changed_ns; i++) { in nvmet_add_to_changed_ns_log()
223 if (ctrl->changed_ns_list[i] == nsid) in nvmet_add_to_changed_ns_log()
227 if (ctrl->nr_changed_ns == NVME_MAX_CHANGED_NAMESPACES) { in nvmet_add_to_changed_ns_log()
228 ctrl->changed_ns_list[0] = cpu_to_le32(0xffffffff); in nvmet_add_to_changed_ns_log()
229 ctrl->nr_changed_ns = U32_MAX; in nvmet_add_to_changed_ns_log()
233 ctrl->changed_ns_list[ctrl->nr_changed_ns++] = nsid; in nvmet_add_to_changed_ns_log()
235 mutex_unlock(&ctrl->lock); in nvmet_add_to_changed_ns_log()
240 struct nvmet_ctrl *ctrl; in nvmet_ns_changed() local
244 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_ns_changed()
245 nvmet_add_to_changed_ns_log(ctrl, cpu_to_le32(nsid)); in nvmet_ns_changed()
246 if (nvmet_aen_bit_disabled(ctrl, NVME_AEN_BIT_NS_ATTR)) in nvmet_ns_changed()
248 nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE, in nvmet_ns_changed()
257 struct nvmet_ctrl *ctrl; in nvmet_send_ana_event() local
260 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_send_ana_event()
261 if (port && ctrl->port != port) in nvmet_send_ana_event()
263 if (nvmet_aen_bit_disabled(ctrl, NVME_AEN_BIT_ANA_CHANGE)) in nvmet_send_ana_event()
265 nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE, in nvmet_send_ana_event()
306 struct nvmet_ctrl *ctrl; in nvmet_port_del_ctrls() local
309 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_port_del_ctrls()
310 if (ctrl->port == port) in nvmet_port_del_ctrls()
311 ctrl->ops->delete_ctrl(ctrl); in nvmet_port_del_ctrls()
383 struct nvmet_ctrl *ctrl = container_of(to_delayed_work(work), in nvmet_keep_alive_timer() local
385 bool reset_tbkas = ctrl->reset_tbkas; in nvmet_keep_alive_timer()
387 ctrl->reset_tbkas = false; in nvmet_keep_alive_timer()
389 pr_debug("ctrl %d reschedule traffic based keep-alive timer\n", in nvmet_keep_alive_timer()
390 ctrl->cntlid); in nvmet_keep_alive_timer()
391 queue_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_keep_alive_timer()
395 pr_err("ctrl %d keep-alive timer (%d seconds) expired!\n", in nvmet_keep_alive_timer()
396 ctrl->cntlid, ctrl->kato); in nvmet_keep_alive_timer()
398 nvmet_ctrl_fatal_error(ctrl); in nvmet_keep_alive_timer()
401 void nvmet_start_keep_alive_timer(struct nvmet_ctrl *ctrl) in nvmet_start_keep_alive_timer() argument
403 if (unlikely(ctrl->kato == 0)) in nvmet_start_keep_alive_timer()
406 pr_debug("ctrl %d start keep-alive timer for %d secs\n", in nvmet_start_keep_alive_timer()
407 ctrl->cntlid, ctrl->kato); in nvmet_start_keep_alive_timer()
409 queue_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_start_keep_alive_timer()
412 void nvmet_stop_keep_alive_timer(struct nvmet_ctrl *ctrl) in nvmet_stop_keep_alive_timer() argument
414 if (unlikely(ctrl->kato == 0)) in nvmet_stop_keep_alive_timer()
417 pr_debug("ctrl %d stop keep-alive\n", ctrl->cntlid); in nvmet_stop_keep_alive_timer()
419 cancel_delayed_work_sync(&ctrl->ka_work); in nvmet_stop_keep_alive_timer()
499 * Note: ctrl->subsys->lock should be held when calling this function
501 static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl, in nvmet_p2pmem_ns_add_p2p() argument
508 if (!ctrl->p2p_client || !ns->use_p2pmem) in nvmet_p2pmem_ns_add_p2p()
512 ret = pci_p2pdma_distance(ns->p2p_dev, ctrl->p2p_client, true); in nvmet_p2pmem_ns_add_p2p()
518 clients[0] = ctrl->p2p_client; in nvmet_p2pmem_ns_add_p2p()
524 dev_name(ctrl->p2p_client), ns->device_path); in nvmet_p2pmem_ns_add_p2p()
529 ret = radix_tree_insert(&ctrl->p2p_ns_map, ns->nsid, p2p_dev); in nvmet_p2pmem_ns_add_p2p()
552 struct nvmet_ctrl *ctrl; in nvmet_ns_enable() local
580 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_enable()
581 nvmet_p2pmem_ns_add_p2p(ctrl, ns); in nvmet_ns_enable()
608 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_enable()
609 pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid)); in nvmet_ns_enable()
618 struct nvmet_ctrl *ctrl; in nvmet_ns_disable() local
629 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_ns_disable()
630 pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid)); in nvmet_ns_disable()
709 struct nvmet_ctrl *ctrl = req->sq->ctrl; in nvmet_set_error() local
715 if (!ctrl || req->error_loc == NVMET_NO_ERROR_LOC) in nvmet_set_error()
718 spin_lock_irqsave(&ctrl->error_lock, flags); in nvmet_set_error()
719 ctrl->err_counter++; in nvmet_set_error()
721 &ctrl->slots[ctrl->err_counter % NVMET_ERROR_LOG_SLOTS]; in nvmet_set_error()
723 new_error_slot->error_count = cpu_to_le64(ctrl->err_counter); in nvmet_set_error()
730 spin_unlock_irqrestore(&ctrl->error_lock, flags); in nvmet_set_error()
762 void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq, in nvmet_cq_setup() argument
769 void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, in nvmet_sq_setup() argument
776 ctrl->sqs[qid] = sq; in nvmet_sq_setup()
788 struct nvmet_ctrl *ctrl = sq->ctrl; in nvmet_sq_destroy() local
794 if (ctrl && ctrl->sqs && ctrl->sqs[0] == sq) in nvmet_sq_destroy()
795 nvmet_async_events_failall(ctrl); in nvmet_sq_destroy()
802 if (ctrl) { in nvmet_sq_destroy()
809 ctrl->reset_tbkas = true; in nvmet_sq_destroy()
810 sq->ctrl->sqs[sq->qid] = NULL; in nvmet_sq_destroy()
811 nvmet_ctrl_put(ctrl); in nvmet_sq_destroy()
812 sq->ctrl = NULL; /* allows reusing the queue later */ in nvmet_sq_destroy()
956 if (unlikely(!req->sq->ctrl)) in nvmet_req_init()
974 if (sq->ctrl) in nvmet_req_init()
975 sq->ctrl->reset_tbkas = true; in nvmet_req_init()
1048 !req->sq->ctrl || !req->sq->qid || !req->ns) in nvmet_req_find_p2p_dev()
1050 return radix_tree_lookup(&req->sq->ctrl->p2p_ns_map, req->ns->nsid); in nvmet_req_find_p2p_dev()
1146 static void nvmet_start_ctrl(struct nvmet_ctrl *ctrl) in nvmet_start_ctrl() argument
1148 lockdep_assert_held(&ctrl->lock); in nvmet_start_ctrl()
1156 if (!nvmet_is_disc_subsys(ctrl->subsys) && in nvmet_start_ctrl()
1157 (nvmet_cc_iosqes(ctrl->cc) != NVME_NVM_IOSQES || in nvmet_start_ctrl()
1158 nvmet_cc_iocqes(ctrl->cc) != NVME_NVM_IOCQES)) { in nvmet_start_ctrl()
1159 ctrl->csts = NVME_CSTS_CFS; in nvmet_start_ctrl()
1163 if (nvmet_cc_mps(ctrl->cc) != 0 || in nvmet_start_ctrl()
1164 nvmet_cc_ams(ctrl->cc) != 0 || in nvmet_start_ctrl()
1165 !nvmet_css_supported(nvmet_cc_css(ctrl->cc))) { in nvmet_start_ctrl()
1166 ctrl->csts = NVME_CSTS_CFS; in nvmet_start_ctrl()
1170 ctrl->csts = NVME_CSTS_RDY; in nvmet_start_ctrl()
1178 if (ctrl->kato) in nvmet_start_ctrl()
1179 mod_delayed_work(nvmet_wq, &ctrl->ka_work, ctrl->kato * HZ); in nvmet_start_ctrl()
1182 static void nvmet_clear_ctrl(struct nvmet_ctrl *ctrl) in nvmet_clear_ctrl() argument
1184 lockdep_assert_held(&ctrl->lock); in nvmet_clear_ctrl()
1187 ctrl->csts &= ~NVME_CSTS_RDY; in nvmet_clear_ctrl()
1188 ctrl->cc = 0; in nvmet_clear_ctrl()
1191 void nvmet_update_cc(struct nvmet_ctrl *ctrl, u32 new) in nvmet_update_cc() argument
1195 mutex_lock(&ctrl->lock); in nvmet_update_cc()
1196 old = ctrl->cc; in nvmet_update_cc()
1197 ctrl->cc = new; in nvmet_update_cc()
1200 nvmet_start_ctrl(ctrl); in nvmet_update_cc()
1202 nvmet_clear_ctrl(ctrl); in nvmet_update_cc()
1204 nvmet_clear_ctrl(ctrl); in nvmet_update_cc()
1205 ctrl->csts |= NVME_CSTS_SHST_CMPLT; in nvmet_update_cc()
1208 ctrl->csts &= ~NVME_CSTS_SHST_CMPLT; in nvmet_update_cc()
1209 mutex_unlock(&ctrl->lock); in nvmet_update_cc()
1212 static void nvmet_init_cap(struct nvmet_ctrl *ctrl) in nvmet_init_cap() argument
1215 ctrl->cap = (1ULL << 37); in nvmet_init_cap()
1217 ctrl->cap |= (1ULL << 43); in nvmet_init_cap()
1219 ctrl->cap |= (15ULL << 24); in nvmet_init_cap()
1221 if (ctrl->ops->get_max_queue_size) in nvmet_init_cap()
1222 ctrl->cap |= ctrl->ops->get_max_queue_size(ctrl) - 1; in nvmet_init_cap()
1224 ctrl->cap |= NVMET_QUEUE_SIZE - 1; in nvmet_init_cap()
1226 if (nvmet_is_passthru_subsys(ctrl->subsys)) in nvmet_init_cap()
1227 nvmet_passthrough_override_cap(ctrl); in nvmet_init_cap()
1234 struct nvmet_ctrl *ctrl = NULL; in nvmet_ctrl_find_get() local
1246 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) { in nvmet_ctrl_find_get()
1247 if (ctrl->cntlid == cntlid) { in nvmet_ctrl_find_get()
1248 if (strncmp(hostnqn, ctrl->hostnqn, NVMF_NQN_SIZE)) { in nvmet_ctrl_find_get()
1252 if (!kref_get_unless_zero(&ctrl->ref)) in nvmet_ctrl_find_get()
1255 /* ctrl found */ in nvmet_ctrl_find_get()
1260 ctrl = NULL; /* ctrl not found */ in nvmet_ctrl_find_get()
1269 return ctrl; in nvmet_ctrl_find_get()
1274 if (unlikely(!(req->sq->ctrl->cc & NVME_CC_ENABLE))) { in nvmet_check_ctrl_status()
1280 if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) { in nvmet_check_ctrl_status()
1314 * Note: ctrl->subsys->lock should be held when calling this function
1316 static void nvmet_setup_p2p_ns_map(struct nvmet_ctrl *ctrl, in nvmet_setup_p2p_ns_map() argument
1325 ctrl->p2p_client = get_device(req->p2p_client); in nvmet_setup_p2p_ns_map()
1327 xa_for_each(&ctrl->subsys->namespaces, idx, ns) in nvmet_setup_p2p_ns_map()
1328 nvmet_p2pmem_ns_add_p2p(ctrl, ns); in nvmet_setup_p2p_ns_map()
1332 * Note: ctrl->subsys->lock should be held when calling this function
1334 static void nvmet_release_p2p_ns_map(struct nvmet_ctrl *ctrl) in nvmet_release_p2p_ns_map() argument
1339 radix_tree_for_each_slot(slot, &ctrl->p2p_ns_map, &iter, 0) in nvmet_release_p2p_ns_map()
1342 put_device(ctrl->p2p_client); in nvmet_release_p2p_ns_map()
1347 struct nvmet_ctrl *ctrl = in nvmet_fatal_error_handler() local
1350 pr_err("ctrl %d fatal error occurred!\n", ctrl->cntlid); in nvmet_fatal_error_handler()
1351 ctrl->ops->delete_ctrl(ctrl); in nvmet_fatal_error_handler()
1358 struct nvmet_ctrl *ctrl; in nvmet_alloc_ctrl() local
1385 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); in nvmet_alloc_ctrl()
1386 if (!ctrl) in nvmet_alloc_ctrl()
1388 mutex_init(&ctrl->lock); in nvmet_alloc_ctrl()
1390 ctrl->port = req->port; in nvmet_alloc_ctrl()
1391 ctrl->ops = req->ops; in nvmet_alloc_ctrl()
1395 if (ctrl->port->disc_addr.trtype == NVMF_TRTYPE_LOOP) in nvmet_alloc_ctrl()
1399 INIT_WORK(&ctrl->async_event_work, nvmet_async_event_work); in nvmet_alloc_ctrl()
1400 INIT_LIST_HEAD(&ctrl->async_events); in nvmet_alloc_ctrl()
1401 INIT_RADIX_TREE(&ctrl->p2p_ns_map, GFP_KERNEL); in nvmet_alloc_ctrl()
1402 INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler); in nvmet_alloc_ctrl()
1403 INIT_DELAYED_WORK(&ctrl->ka_work, nvmet_keep_alive_timer); in nvmet_alloc_ctrl()
1405 memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE); in nvmet_alloc_ctrl()
1406 memcpy(ctrl->hostnqn, hostnqn, NVMF_NQN_SIZE); in nvmet_alloc_ctrl()
1408 kref_init(&ctrl->ref); in nvmet_alloc_ctrl()
1409 ctrl->subsys = subsys; in nvmet_alloc_ctrl()
1410 nvmet_init_cap(ctrl); in nvmet_alloc_ctrl()
1411 WRITE_ONCE(ctrl->aen_enabled, NVMET_AEN_CFG_OPTIONAL); in nvmet_alloc_ctrl()
1413 ctrl->changed_ns_list = kmalloc_array(NVME_MAX_CHANGED_NAMESPACES, in nvmet_alloc_ctrl()
1415 if (!ctrl->changed_ns_list) in nvmet_alloc_ctrl()
1418 ctrl->sqs = kcalloc(subsys->max_qid + 1, in nvmet_alloc_ctrl()
1421 if (!ctrl->sqs) in nvmet_alloc_ctrl()
1434 ctrl->cntlid = ret; in nvmet_alloc_ctrl()
1440 if (nvmet_is_disc_subsys(ctrl->subsys) && !kato) in nvmet_alloc_ctrl()
1444 ctrl->kato = DIV_ROUND_UP(kato, 1000); in nvmet_alloc_ctrl()
1446 ctrl->err_counter = 0; in nvmet_alloc_ctrl()
1447 spin_lock_init(&ctrl->error_lock); in nvmet_alloc_ctrl()
1449 nvmet_start_keep_alive_timer(ctrl); in nvmet_alloc_ctrl()
1452 list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); in nvmet_alloc_ctrl()
1453 nvmet_setup_p2p_ns_map(ctrl, req); in nvmet_alloc_ctrl()
1456 *ctrlp = ctrl; in nvmet_alloc_ctrl()
1460 kfree(ctrl->sqs); in nvmet_alloc_ctrl()
1462 kfree(ctrl->changed_ns_list); in nvmet_alloc_ctrl()
1464 kfree(ctrl); in nvmet_alloc_ctrl()
1473 struct nvmet_ctrl *ctrl = container_of(ref, struct nvmet_ctrl, ref); in nvmet_ctrl_free() local
1474 struct nvmet_subsys *subsys = ctrl->subsys; in nvmet_ctrl_free()
1477 nvmet_release_p2p_ns_map(ctrl); in nvmet_ctrl_free()
1478 list_del(&ctrl->subsys_entry); in nvmet_ctrl_free()
1481 nvmet_stop_keep_alive_timer(ctrl); in nvmet_ctrl_free()
1483 flush_work(&ctrl->async_event_work); in nvmet_ctrl_free()
1484 cancel_work_sync(&ctrl->fatal_err_work); in nvmet_ctrl_free()
1486 nvmet_destroy_auth(ctrl); in nvmet_ctrl_free()
1488 ida_free(&cntlid_ida, ctrl->cntlid); in nvmet_ctrl_free()
1490 nvmet_async_events_free(ctrl); in nvmet_ctrl_free()
1491 kfree(ctrl->sqs); in nvmet_ctrl_free()
1492 kfree(ctrl->changed_ns_list); in nvmet_ctrl_free()
1493 kfree(ctrl); in nvmet_ctrl_free()
1498 void nvmet_ctrl_put(struct nvmet_ctrl *ctrl) in nvmet_ctrl_put() argument
1500 kref_put(&ctrl->ref, nvmet_ctrl_free); in nvmet_ctrl_put()
1503 void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl) in nvmet_ctrl_fatal_error() argument
1505 mutex_lock(&ctrl->lock); in nvmet_ctrl_fatal_error()
1506 if (!(ctrl->csts & NVME_CSTS_CFS)) { in nvmet_ctrl_fatal_error()
1507 ctrl->csts |= NVME_CSTS_CFS; in nvmet_ctrl_fatal_error()
1508 queue_work(nvmet_wq, &ctrl->fatal_err_work); in nvmet_ctrl_fatal_error()
1510 mutex_unlock(&ctrl->lock); in nvmet_ctrl_fatal_error()
1619 struct nvmet_ctrl *ctrl; in nvmet_subsys_del_ctrls() local
1622 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_subsys_del_ctrls()
1623 ctrl->ops->delete_ctrl(ctrl); in nvmet_subsys_del_ctrls()