Lines Matching full:ctrl

37 	struct nvme_ctrl	ctrl;  member
42 static inline struct nvme_loop_ctrl *to_loop_ctrl(struct nvme_ctrl *ctrl) in to_loop_ctrl() argument
44 return container_of(ctrl, struct nvme_loop_ctrl, ctrl); in to_loop_ctrl()
54 struct nvme_loop_ctrl *ctrl; member
65 static void nvme_loop_delete_ctrl(struct nvmet_ctrl *ctrl);
71 return queue - queue->ctrl->queues; in nvme_loop_queue_idx()
87 return queue->ctrl->admin_tag_set.tags[queue_idx]; in nvme_loop_tagset()
88 return queue->ctrl->tag_set.tags[queue_idx - 1]; in nvme_loop_tagset()
105 nvme_complete_async_event(&queue->ctrl->ctrl, cqe->status, in nvme_loop_queue_response()
112 dev_err(queue->ctrl->ctrl.device, in nvme_loop_queue_response()
141 if (!nvme_check_ready(&queue->ctrl->ctrl, req, queue_ready)) in nvme_loop_queue_rq()
142 return nvme_fail_nonready_command(&queue->ctrl->ctrl, req); in nvme_loop_queue_rq()
150 iod->req.port = queue->ctrl->port; in nvme_loop_queue_rq()
175 struct nvme_loop_ctrl *ctrl = to_loop_ctrl(arg); in nvme_loop_submit_async_event() local
176 struct nvme_loop_queue *queue = &ctrl->queues[0]; in nvme_loop_submit_async_event()
177 struct nvme_loop_iod *iod = &ctrl->async_event_iod; in nvme_loop_submit_async_event()
186 dev_err(ctrl->ctrl.device, "failed async event work\n"); in nvme_loop_submit_async_event()
193 static int nvme_loop_init_iod(struct nvme_loop_ctrl *ctrl, in nvme_loop_init_iod() argument
198 iod->queue = &ctrl->queues[queue_idx]; in nvme_loop_init_iod()
207 struct nvme_loop_ctrl *ctrl = to_loop_ctrl(set->driver_data); in nvme_loop_init_request() local
210 nvme_req(req)->ctrl = &ctrl->ctrl; in nvme_loop_init_request()
212 return nvme_loop_init_iod(ctrl, blk_mq_rq_to_pdu(req), in nvme_loop_init_request()
213 (set == &ctrl->tag_set) ? hctx_idx + 1 : 0); in nvme_loop_init_request()
221 struct nvme_loop_ctrl *ctrl = to_loop_ctrl(data); in nvme_loop_init_hctx() local
222 struct nvme_loop_queue *queue = &ctrl->queues[hctx_idx + 1]; in nvme_loop_init_hctx()
224 BUG_ON(hctx_idx >= ctrl->ctrl.queue_count); in nvme_loop_init_hctx()
241 struct nvme_loop_ctrl *ctrl = to_loop_ctrl(data); in nvme_loop_init_admin_hctx() local
242 struct nvme_loop_queue *queue = &ctrl->queues[0]; in nvme_loop_init_admin_hctx()
264 static void nvme_loop_destroy_admin_queue(struct nvme_loop_ctrl *ctrl) in nvme_loop_destroy_admin_queue() argument
266 if (!test_and_clear_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[0].flags)) in nvme_loop_destroy_admin_queue()
268 nvmet_sq_destroy(&ctrl->queues[0].nvme_sq); in nvme_loop_destroy_admin_queue()
269 nvme_remove_admin_tag_set(&ctrl->ctrl); in nvme_loop_destroy_admin_queue()
274 struct nvme_loop_ctrl *ctrl = to_loop_ctrl(nctrl); in nvme_loop_free_ctrl() local
276 if (list_empty(&ctrl->list)) in nvme_loop_free_ctrl()
280 list_del(&ctrl->list); in nvme_loop_free_ctrl()
285 kfree(ctrl->queues); in nvme_loop_free_ctrl()
288 kfree(ctrl); in nvme_loop_free_ctrl()
291 static void nvme_loop_destroy_io_queues(struct nvme_loop_ctrl *ctrl) in nvme_loop_destroy_io_queues() argument
295 for (i = 1; i < ctrl->ctrl.queue_count; i++) { in nvme_loop_destroy_io_queues()
296 clear_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[i].flags); in nvme_loop_destroy_io_queues()
297 nvmet_sq_destroy(&ctrl->queues[i].nvme_sq); in nvme_loop_destroy_io_queues()
299 ctrl->ctrl.queue_count = 1; in nvme_loop_destroy_io_queues()
302 static int nvme_loop_init_io_queues(struct nvme_loop_ctrl *ctrl) in nvme_loop_init_io_queues() argument
304 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts; in nvme_loop_init_io_queues()
309 ret = nvme_set_queue_count(&ctrl->ctrl, &nr_io_queues); in nvme_loop_init_io_queues()
313 dev_info(ctrl->ctrl.device, "creating %d I/O queues.\n", nr_io_queues); in nvme_loop_init_io_queues()
316 ctrl->queues[i].ctrl = ctrl; in nvme_loop_init_io_queues()
317 ret = nvmet_sq_init(&ctrl->queues[i].nvme_sq); in nvme_loop_init_io_queues()
321 ctrl->ctrl.queue_count++; in nvme_loop_init_io_queues()
327 nvme_loop_destroy_io_queues(ctrl); in nvme_loop_init_io_queues()
331 static int nvme_loop_connect_io_queues(struct nvme_loop_ctrl *ctrl) in nvme_loop_connect_io_queues() argument
335 for (i = 1; i < ctrl->ctrl.queue_count; i++) { in nvme_loop_connect_io_queues()
336 ret = nvmf_connect_io_queue(&ctrl->ctrl, i); in nvme_loop_connect_io_queues()
339 set_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[i].flags); in nvme_loop_connect_io_queues()
345 static int nvme_loop_configure_admin_queue(struct nvme_loop_ctrl *ctrl) in nvme_loop_configure_admin_queue() argument
349 ctrl->queues[0].ctrl = ctrl; in nvme_loop_configure_admin_queue()
350 error = nvmet_sq_init(&ctrl->queues[0].nvme_sq); in nvme_loop_configure_admin_queue()
353 ctrl->ctrl.queue_count = 1; in nvme_loop_configure_admin_queue()
355 error = nvme_alloc_admin_tag_set(&ctrl->ctrl, &ctrl->admin_tag_set, in nvme_loop_configure_admin_queue()
363 clear_bit(NVME_CTRL_ADMIN_Q_STOPPED, &ctrl->ctrl.flags); in nvme_loop_configure_admin_queue()
365 error = nvmf_connect_admin_queue(&ctrl->ctrl); in nvme_loop_configure_admin_queue()
369 set_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[0].flags); in nvme_loop_configure_admin_queue()
371 error = nvme_enable_ctrl(&ctrl->ctrl); in nvme_loop_configure_admin_queue()
375 ctrl->ctrl.max_hw_sectors = in nvme_loop_configure_admin_queue()
378 nvme_start_admin_queue(&ctrl->ctrl); in nvme_loop_configure_admin_queue()
380 error = nvme_init_ctrl_finish(&ctrl->ctrl); in nvme_loop_configure_admin_queue()
387 clear_bit(NVME_LOOP_Q_LIVE, &ctrl->queues[0].flags); in nvme_loop_configure_admin_queue()
388 nvme_remove_admin_tag_set(&ctrl->ctrl); in nvme_loop_configure_admin_queue()
390 nvmet_sq_destroy(&ctrl->queues[0].nvme_sq); in nvme_loop_configure_admin_queue()
394 static void nvme_loop_shutdown_ctrl(struct nvme_loop_ctrl *ctrl) in nvme_loop_shutdown_ctrl() argument
396 if (ctrl->ctrl.queue_count > 1) { in nvme_loop_shutdown_ctrl()
397 nvme_stop_queues(&ctrl->ctrl); in nvme_loop_shutdown_ctrl()
398 nvme_cancel_tagset(&ctrl->ctrl); in nvme_loop_shutdown_ctrl()
399 nvme_loop_destroy_io_queues(ctrl); in nvme_loop_shutdown_ctrl()
402 nvme_stop_admin_queue(&ctrl->ctrl); in nvme_loop_shutdown_ctrl()
403 if (ctrl->ctrl.state == NVME_CTRL_LIVE) in nvme_loop_shutdown_ctrl()
404 nvme_shutdown_ctrl(&ctrl->ctrl); in nvme_loop_shutdown_ctrl()
406 nvme_cancel_admin_tagset(&ctrl->ctrl); in nvme_loop_shutdown_ctrl()
407 nvme_loop_destroy_admin_queue(ctrl); in nvme_loop_shutdown_ctrl()
410 static void nvme_loop_delete_ctrl_host(struct nvme_ctrl *ctrl) in nvme_loop_delete_ctrl_host() argument
412 nvme_loop_shutdown_ctrl(to_loop_ctrl(ctrl)); in nvme_loop_delete_ctrl_host()
417 struct nvme_loop_ctrl *ctrl; in nvme_loop_delete_ctrl() local
420 list_for_each_entry(ctrl, &nvme_loop_ctrl_list, list) { in nvme_loop_delete_ctrl()
421 if (ctrl->ctrl.cntlid == nctrl->cntlid) in nvme_loop_delete_ctrl()
422 nvme_delete_ctrl(&ctrl->ctrl); in nvme_loop_delete_ctrl()
429 struct nvme_loop_ctrl *ctrl = in nvme_loop_reset_ctrl_work() local
430 container_of(work, struct nvme_loop_ctrl, ctrl.reset_work); in nvme_loop_reset_ctrl_work()
433 nvme_stop_ctrl(&ctrl->ctrl); in nvme_loop_reset_ctrl_work()
434 nvme_loop_shutdown_ctrl(ctrl); in nvme_loop_reset_ctrl_work()
436 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { in nvme_loop_reset_ctrl_work()
437 if (ctrl->ctrl.state != NVME_CTRL_DELETING && in nvme_loop_reset_ctrl_work()
438 ctrl->ctrl.state != NVME_CTRL_DELETING_NOIO) in nvme_loop_reset_ctrl_work()
439 /* state change failure for non-deleted ctrl? */ in nvme_loop_reset_ctrl_work()
444 ret = nvme_loop_configure_admin_queue(ctrl); in nvme_loop_reset_ctrl_work()
448 ret = nvme_loop_init_io_queues(ctrl); in nvme_loop_reset_ctrl_work()
452 ret = nvme_loop_connect_io_queues(ctrl); in nvme_loop_reset_ctrl_work()
456 blk_mq_update_nr_hw_queues(&ctrl->tag_set, in nvme_loop_reset_ctrl_work()
457 ctrl->ctrl.queue_count - 1); in nvme_loop_reset_ctrl_work()
459 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE)) in nvme_loop_reset_ctrl_work()
462 nvme_start_ctrl(&ctrl->ctrl); in nvme_loop_reset_ctrl_work()
467 nvme_loop_destroy_io_queues(ctrl); in nvme_loop_reset_ctrl_work()
469 nvme_loop_destroy_admin_queue(ctrl); in nvme_loop_reset_ctrl_work()
471 dev_warn(ctrl->ctrl.device, "Removing after reset failure\n"); in nvme_loop_reset_ctrl_work()
472 nvme_uninit_ctrl(&ctrl->ctrl); in nvme_loop_reset_ctrl_work()
488 static int nvme_loop_create_io_queues(struct nvme_loop_ctrl *ctrl) in nvme_loop_create_io_queues() argument
492 ret = nvme_loop_init_io_queues(ctrl); in nvme_loop_create_io_queues()
496 ret = nvme_alloc_io_tag_set(&ctrl->ctrl, &ctrl->tag_set, in nvme_loop_create_io_queues()
503 ret = nvme_loop_connect_io_queues(ctrl); in nvme_loop_create_io_queues()
510 nvme_remove_io_tag_set(&ctrl->ctrl); in nvme_loop_create_io_queues()
512 nvme_loop_destroy_io_queues(ctrl); in nvme_loop_create_io_queues()
516 static struct nvmet_port *nvme_loop_find_port(struct nvme_ctrl *ctrl) in nvme_loop_find_port() argument
523 if ((ctrl->opts->mask & NVMF_OPT_TRADDR) && in nvme_loop_find_port()
524 strcmp(ctrl->opts->traddr, p->disc_addr.traddr)) in nvme_loop_find_port()
536 struct nvme_loop_ctrl *ctrl; in nvme_loop_create_ctrl() local
539 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); in nvme_loop_create_ctrl()
540 if (!ctrl) in nvme_loop_create_ctrl()
542 ctrl->ctrl.opts = opts; in nvme_loop_create_ctrl()
543 INIT_LIST_HEAD(&ctrl->list); in nvme_loop_create_ctrl()
545 INIT_WORK(&ctrl->ctrl.reset_work, nvme_loop_reset_ctrl_work); in nvme_loop_create_ctrl()
547 ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_loop_ctrl_ops, in nvme_loop_create_ctrl()
550 kfree(ctrl); in nvme_loop_create_ctrl()
554 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) in nvme_loop_create_ctrl()
559 ctrl->ctrl.kato = opts->kato; in nvme_loop_create_ctrl()
560 ctrl->port = nvme_loop_find_port(&ctrl->ctrl); in nvme_loop_create_ctrl()
562 ctrl->queues = kcalloc(opts->nr_io_queues + 1, sizeof(*ctrl->queues), in nvme_loop_create_ctrl()
564 if (!ctrl->queues) in nvme_loop_create_ctrl()
567 ret = nvme_loop_configure_admin_queue(ctrl); in nvme_loop_create_ctrl()
571 if (opts->queue_size > ctrl->ctrl.maxcmd) { in nvme_loop_create_ctrl()
573 dev_warn(ctrl->ctrl.device, in nvme_loop_create_ctrl()
574 "queue_size %zu > ctrl maxcmd %u, clamping down\n", in nvme_loop_create_ctrl()
575 opts->queue_size, ctrl->ctrl.maxcmd); in nvme_loop_create_ctrl()
576 opts->queue_size = ctrl->ctrl.maxcmd; in nvme_loop_create_ctrl()
578 ctrl->ctrl.sqsize = opts->queue_size - 1; in nvme_loop_create_ctrl()
581 ret = nvme_loop_create_io_queues(ctrl); in nvme_loop_create_ctrl()
586 nvme_loop_init_iod(ctrl, &ctrl->async_event_iod, 0); in nvme_loop_create_ctrl()
588 dev_info(ctrl->ctrl.device, in nvme_loop_create_ctrl()
589 "new ctrl: \"%s\"\n", ctrl->ctrl.opts->subsysnqn); in nvme_loop_create_ctrl()
591 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE)) in nvme_loop_create_ctrl()
595 list_add_tail(&ctrl->list, &nvme_loop_ctrl_list); in nvme_loop_create_ctrl()
598 nvme_start_ctrl(&ctrl->ctrl); in nvme_loop_create_ctrl()
600 return &ctrl->ctrl; in nvme_loop_create_ctrl()
603 nvme_loop_destroy_admin_queue(ctrl); in nvme_loop_create_ctrl()
605 kfree(ctrl->queues); in nvme_loop_create_ctrl()
607 nvme_uninit_ctrl(&ctrl->ctrl); in nvme_loop_create_ctrl()
608 nvme_put_ctrl(&ctrl->ctrl); in nvme_loop_create_ctrl()
671 struct nvme_loop_ctrl *ctrl, *next; in nvme_loop_cleanup_module() local
677 list_for_each_entry_safe(ctrl, next, &nvme_loop_ctrl_list, list) in nvme_loop_cleanup_module()
678 nvme_delete_ctrl(&ctrl->ctrl); in nvme_loop_cleanup_module()