Lines Matching +full:ctrl +full:- +full:module

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
9 #include <linux/module.h>
29 if (!strcmp(host->nqn, hostnqn)) in __nvmf_host_find()
43 kref_get(&host->ref); in nvmf_host_add()
51 kref_init(&host->ref); in nvmf_host_add()
52 strlcpy(host->nqn, hostnqn, NVMF_NQN_SIZE); in nvmf_host_add()
54 list_add_tail(&host->list, &nvmf_hosts); in nvmf_host_add()
68 kref_init(&host->ref); in nvmf_host_default()
69 uuid_gen(&host->id); in nvmf_host_default()
70 snprintf(host->nqn, NVMF_NQN_SIZE, in nvmf_host_default()
71 "nqn.2014-08.org.nvmexpress:uuid:%pUb", &host->id); in nvmf_host_default()
74 list_add_tail(&host->list, &nvmf_hosts); in nvmf_host_default()
85 list_del(&host->list); in nvmf_host_destroy()
94 kref_put(&host->ref, nvmf_host_destroy); in nvmf_host_put()
98 * nvmf_get_address() - Get address/port
99 * @ctrl: Host NVMe controller instance which we got the address
103 int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size) in nvmf_get_address() argument
107 if (ctrl->opts->mask & NVMF_OPT_TRADDR) in nvmf_get_address()
108 len += scnprintf(buf, size, "traddr=%s", ctrl->opts->traddr); in nvmf_get_address()
109 if (ctrl->opts->mask & NVMF_OPT_TRSVCID) in nvmf_get_address()
110 len += scnprintf(buf + len, size - len, "%strsvcid=%s", in nvmf_get_address()
111 (len) ? "," : "", ctrl->opts->trsvcid); in nvmf_get_address()
112 if (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR) in nvmf_get_address()
113 len += scnprintf(buf + len, size - len, "%shost_traddr=%s", in nvmf_get_address()
114 (len) ? "," : "", ctrl->opts->host_traddr); in nvmf_get_address()
115 len += scnprintf(buf + len, size - len, "\n"); in nvmf_get_address()
122 * nvmf_reg_read32() - NVMe Fabrics "Property Get" API function.
123 * @ctrl: Host NVMe controller instance maintaining the admin
131 * Used by the host system to retrieve a 32-bit capsule property value
142 int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val) in nvmf_reg_read32() argument
153 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, NULL, 0, 0, in nvmf_reg_read32()
159 dev_err(ctrl->device, in nvmf_reg_read32()
168 * nvmf_reg_read64() - NVMe Fabrics "Property Get" API function.
169 * @ctrl: Host NVMe controller instance maintaining the admin
177 * Used by the host system to retrieve a 64-bit capsule property value
188 int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val) in nvmf_reg_read64() argument
200 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, NULL, 0, 0, in nvmf_reg_read64()
206 dev_err(ctrl->device, in nvmf_reg_read64()
214 * nvmf_reg_write32() - NVMe Fabrics "Property Write" API function.
215 * @ctrl: Host NVMe controller instance maintaining the admin
223 * Used by the NVMe host system to write a 32-bit capsule property value
234 int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val) in nvmf_reg_write32() argument
246 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, NULL, NULL, 0, 0, in nvmf_reg_write32()
249 dev_err(ctrl->device, in nvmf_reg_write32()
257 * nvmf_log_connect_error() - Error-parsing-diagnostic print
260 * @ctrl: the specific /dev/nvmeX device that had the error.
262 * @errval: Error code to be decoded in a more human-friendly
271 static void nvmf_log_connect_error(struct nvme_ctrl *ctrl, in nvmf_log_connect_error() argument
285 dev_err(ctrl->device, in nvmf_log_connect_error()
287 inv_data, data->cntlid); in nvmf_log_connect_error()
290 dev_err(ctrl->device, in nvmf_log_connect_error()
292 inv_data, data->hostnqn); in nvmf_log_connect_error()
295 dev_err(ctrl->device, in nvmf_log_connect_error()
297 inv_data, data->subsysnqn); in nvmf_log_connect_error()
300 dev_err(ctrl->device, in nvmf_log_connect_error()
310 dev_err(ctrl->device, in nvmf_log_connect_error()
312 inv_sqe, cmd->connect.qid); in nvmf_log_connect_error()
315 dev_err(ctrl->device, in nvmf_log_connect_error()
323 dev_err(ctrl->device, in nvmf_log_connect_error()
325 data->subsysnqn, data->hostnqn); in nvmf_log_connect_error()
329 dev_err(ctrl->device, in nvmf_log_connect_error()
334 dev_err(ctrl->device, in nvmf_log_connect_error()
336 cmd->connect.recfmt); in nvmf_log_connect_error()
340 dev_err(ctrl->device, in nvmf_log_connect_error()
348 * nvmf_connect_admin_queue() - NVMe Fabrics Admin Queue "Connect"
350 * @ctrl: Host nvme controller instance used to request
357 * fabrics-protocol connection of the NVMe Admin queue between the
367 int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl) in nvmf_connect_admin_queue() argument
378 cmd.connect.sqsize = cpu_to_le16(NVME_AQ_DEPTH - 1); in nvmf_connect_admin_queue()
381 * Set keep-alive timeout in seconds granularity (ms * 1000) in nvmf_connect_admin_queue()
384 cmd.connect.kato = ctrl->kato ? in nvmf_connect_admin_queue()
385 cpu_to_le32((ctrl->kato + NVME_KATO_GRACE) * 1000) : 0; in nvmf_connect_admin_queue()
387 if (ctrl->opts->disable_sqflow) in nvmf_connect_admin_queue()
392 return -ENOMEM; in nvmf_connect_admin_queue()
394 uuid_copy(&data->hostid, &ctrl->opts->host->id); in nvmf_connect_admin_queue()
395 data->cntlid = cpu_to_le16(0xffff); in nvmf_connect_admin_queue()
396 strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_connect_admin_queue()
397 strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); in nvmf_connect_admin_queue()
399 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, in nvmf_connect_admin_queue()
403 nvmf_log_connect_error(ctrl, ret, le32_to_cpu(res.u32), in nvmf_connect_admin_queue()
408 ctrl->cntlid = le16_to_cpu(res.u16); in nvmf_connect_admin_queue()
417 * nvmf_connect_io_queue() - NVMe Fabrics I/O Queue "Connect"
419 * @ctrl: Host nvme controller instance used to establish an
427 * This function issues a fabrics-protocol connection
437 int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid, bool poll) in nvmf_connect_io_queue() argument
448 cmd.connect.sqsize = cpu_to_le16(ctrl->sqsize); in nvmf_connect_io_queue()
450 if (ctrl->opts->disable_sqflow) in nvmf_connect_io_queue()
455 return -ENOMEM; in nvmf_connect_io_queue()
457 uuid_copy(&data->hostid, &ctrl->opts->host->id); in nvmf_connect_io_queue()
458 data->cntlid = cpu_to_le16(ctrl->cntlid); in nvmf_connect_io_queue()
459 strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_connect_io_queue()
460 strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); in nvmf_connect_io_queue()
462 ret = __nvme_submit_sync_cmd(ctrl->connect_q, &cmd, &res, in nvmf_connect_io_queue()
466 nvmf_log_connect_error(ctrl, ret, le32_to_cpu(res.u32), in nvmf_connect_io_queue()
474 bool nvmf_should_reconnect(struct nvme_ctrl *ctrl) in nvmf_should_reconnect() argument
476 if (ctrl->opts->max_reconnects == -1 || in nvmf_should_reconnect()
477 ctrl->nr_reconnects < ctrl->opts->max_reconnects) in nvmf_should_reconnect()
485 * nvmf_register_transport() - NVMe Fabrics Library registration function.
495 if (!ops->create_ctrl) in nvmf_register_transport()
496 return -EINVAL; in nvmf_register_transport()
499 list_add_tail(&ops->entry, &nvmf_transports); in nvmf_register_transport()
507 * nvmf_unregister_transport() - NVMe Fabrics Library unregistration function.
518 list_del(&ops->entry); in nvmf_unregister_transport()
531 if (strcmp(ops->name, opts->transport) == 0) in nvmf_lookup_transport()
547 blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl, in nvmf_fail_nonready_command() argument
550 if (ctrl->state != NVME_CTRL_DELETING_NOIO && in nvmf_fail_nonready_command()
551 ctrl->state != NVME_CTRL_DEAD && in nvmf_fail_nonready_command()
552 !blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH)) in nvmf_fail_nonready_command()
555 nvme_req(rq)->status = NVME_SC_HOST_PATH_ERROR; in nvmf_fail_nonready_command()
562 bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq, in __nvmf_check_ready() argument
575 if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD)) in __nvmf_check_ready()
582 switch (ctrl->state) { in __nvmf_check_ready()
584 if (blk_rq_is_passthrough(rq) && nvme_is_fabrics(req->cmd) && in __nvmf_check_ready()
585 req->cmd->fabrics.fctype == nvme_fabrics_type_connect) in __nvmf_check_ready()
632 opts->queue_size = NVMF_DEF_QUEUE_SIZE; in nvmf_parse_options()
633 opts->nr_io_queues = num_online_cpus(); in nvmf_parse_options()
634 opts->reconnect_delay = NVMF_DEF_RECONNECT_DELAY; in nvmf_parse_options()
635 opts->kato = NVME_DEFAULT_KATO; in nvmf_parse_options()
636 opts->duplicate_connect = false; in nvmf_parse_options()
637 opts->hdr_digest = false; in nvmf_parse_options()
638 opts->data_digest = false; in nvmf_parse_options()
639 opts->tos = -1; /* < 0 == use transport default */ in nvmf_parse_options()
643 return -ENOMEM; in nvmf_parse_options()
652 opts->mask |= token; in nvmf_parse_options()
657 ret = -ENOMEM; in nvmf_parse_options()
660 kfree(opts->transport); in nvmf_parse_options()
661 opts->transport = p; in nvmf_parse_options()
666 ret = -ENOMEM; in nvmf_parse_options()
669 kfree(opts->subsysnqn); in nvmf_parse_options()
670 opts->subsysnqn = p; in nvmf_parse_options()
671 nqnlen = strlen(opts->subsysnqn); in nvmf_parse_options()
674 opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_parse_options()
675 ret = -EINVAL; in nvmf_parse_options()
678 opts->discovery_nqn = in nvmf_parse_options()
679 !(strcmp(opts->subsysnqn, in nvmf_parse_options()
685 ret = -ENOMEM; in nvmf_parse_options()
688 kfree(opts->traddr); in nvmf_parse_options()
689 opts->traddr = p; in nvmf_parse_options()
694 ret = -ENOMEM; in nvmf_parse_options()
697 kfree(opts->trsvcid); in nvmf_parse_options()
698 opts->trsvcid = p; in nvmf_parse_options()
702 ret = -EINVAL; in nvmf_parse_options()
708 ret = -EINVAL; in nvmf_parse_options()
711 opts->queue_size = token; in nvmf_parse_options()
715 ret = -EINVAL; in nvmf_parse_options()
720 ret = -EINVAL; in nvmf_parse_options()
723 if (opts->discovery_nqn) { in nvmf_parse_options()
728 opts->nr_io_queues = min_t(unsigned int, in nvmf_parse_options()
733 ret = -EINVAL; in nvmf_parse_options()
739 ret = -EINVAL; in nvmf_parse_options()
741 } else if (token == 0 && !opts->discovery_nqn) { in nvmf_parse_options()
745 opts->kato = token; in nvmf_parse_options()
749 ret = -EINVAL; in nvmf_parse_options()
758 if (opts->host) { in nvmf_parse_options()
759 pr_err("hostnqn already user-assigned: %s\n", in nvmf_parse_options()
760 opts->host->nqn); in nvmf_parse_options()
761 ret = -EADDRINUSE; in nvmf_parse_options()
766 ret = -ENOMEM; in nvmf_parse_options()
774 ret = -EINVAL; in nvmf_parse_options()
777 nvmf_host_put(opts->host); in nvmf_parse_options()
778 opts->host = nvmf_host_add(p); in nvmf_parse_options()
780 if (!opts->host) { in nvmf_parse_options()
781 ret = -ENOMEM; in nvmf_parse_options()
787 ret = -EINVAL; in nvmf_parse_options()
792 ret = -EINVAL; in nvmf_parse_options()
795 opts->reconnect_delay = token; in nvmf_parse_options()
800 ret = -ENOMEM; in nvmf_parse_options()
803 kfree(opts->host_traddr); in nvmf_parse_options()
804 opts->host_traddr = p; in nvmf_parse_options()
809 ret = -ENOMEM; in nvmf_parse_options()
815 ret = -EINVAL; in nvmf_parse_options()
822 opts->duplicate_connect = true; in nvmf_parse_options()
825 opts->disable_sqflow = true; in nvmf_parse_options()
828 opts->hdr_digest = true; in nvmf_parse_options()
831 opts->data_digest = true; in nvmf_parse_options()
835 ret = -EINVAL; in nvmf_parse_options()
840 ret = -EINVAL; in nvmf_parse_options()
843 opts->nr_write_queues = token; in nvmf_parse_options()
847 ret = -EINVAL; in nvmf_parse_options()
852 ret = -EINVAL; in nvmf_parse_options()
855 opts->nr_poll_queues = token; in nvmf_parse_options()
859 ret = -EINVAL; in nvmf_parse_options()
864 ret = -EINVAL; in nvmf_parse_options()
871 opts->tos = token; in nvmf_parse_options()
874 pr_warn("unknown parameter or missing value '%s' in ctrl creation request\n", in nvmf_parse_options()
876 ret = -EINVAL; in nvmf_parse_options()
881 if (opts->discovery_nqn) { in nvmf_parse_options()
882 opts->nr_io_queues = 0; in nvmf_parse_options()
883 opts->nr_write_queues = 0; in nvmf_parse_options()
884 opts->nr_poll_queues = 0; in nvmf_parse_options()
885 opts->duplicate_connect = true; in nvmf_parse_options()
888 opts->max_reconnects = -1; in nvmf_parse_options()
890 opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, in nvmf_parse_options()
891 opts->reconnect_delay); in nvmf_parse_options()
893 if (!opts->host) { in nvmf_parse_options()
894 kref_get(&nvmf_default_host->ref); in nvmf_parse_options()
895 opts->host = nvmf_default_host; in nvmf_parse_options()
898 uuid_copy(&opts->host->id, &hostid); in nvmf_parse_options()
908 if ((opts->mask & required_opts) != required_opts) { in nvmf_check_required_opts()
913 !(opt_tokens[i].token & opts->mask)) { in nvmf_check_required_opts()
919 return -EINVAL; in nvmf_check_required_opts()
925 bool nvmf_ip_options_match(struct nvme_ctrl *ctrl, in nvmf_ip_options_match() argument
928 if (!nvmf_ctlr_matches_baseopts(ctrl, opts) || in nvmf_ip_options_match()
929 strcmp(opts->traddr, ctrl->opts->traddr) || in nvmf_ip_options_match()
930 strcmp(opts->trsvcid, ctrl->opts->trsvcid)) in nvmf_ip_options_match()
938 * - local address is specified and address is not the same in nvmf_ip_options_match()
939 * - local address is not specified but remote is, or vice versa in nvmf_ip_options_match()
942 if ((opts->mask & NVMF_OPT_HOST_TRADDR) && in nvmf_ip_options_match()
943 (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) { in nvmf_ip_options_match()
944 if (strcmp(opts->host_traddr, ctrl->opts->host_traddr)) in nvmf_ip_options_match()
946 } else if ((opts->mask & NVMF_OPT_HOST_TRADDR) || in nvmf_ip_options_match()
947 (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) { in nvmf_ip_options_match()
958 if (opts->mask & ~allowed_opts) { in nvmf_check_allowed_opts()
962 if ((opt_tokens[i].token & opts->mask) && in nvmf_check_allowed_opts()
969 return -EINVAL; in nvmf_check_allowed_opts()
977 nvmf_host_put(opts->host); in nvmf_free_options()
978 kfree(opts->transport); in nvmf_free_options()
979 kfree(opts->traddr); in nvmf_free_options()
980 kfree(opts->trsvcid); in nvmf_free_options()
981 kfree(opts->subsysnqn); in nvmf_free_options()
982 kfree(opts->host_traddr); in nvmf_free_options()
998 struct nvme_ctrl *ctrl; in nvmf_create_ctrl() local
1003 return ERR_PTR(-ENOMEM); in nvmf_create_ctrl()
1010 request_module("nvme-%s", opts->transport); in nvmf_create_ctrl()
1020 opts->mask &= ~NVMF_REQUIRED_OPTS; in nvmf_create_ctrl()
1026 opts->transport); in nvmf_create_ctrl()
1027 ret = -EINVAL; in nvmf_create_ctrl()
1031 if (!try_module_get(ops->module)) { in nvmf_create_ctrl()
1032 ret = -EBUSY; in nvmf_create_ctrl()
1037 ret = nvmf_check_required_opts(opts, ops->required_opts); in nvmf_create_ctrl()
1041 ops->allowed_opts | ops->required_opts); in nvmf_create_ctrl()
1045 ctrl = ops->create_ctrl(dev, opts); in nvmf_create_ctrl()
1046 if (IS_ERR(ctrl)) { in nvmf_create_ctrl()
1047 ret = PTR_ERR(ctrl); in nvmf_create_ctrl()
1051 module_put(ops->module); in nvmf_create_ctrl()
1052 return ctrl; in nvmf_create_ctrl()
1055 module_put(ops->module); in nvmf_create_ctrl()
1071 struct seq_file *seq_file = file->private_data; in nvmf_dev_write()
1072 struct nvme_ctrl *ctrl; in nvmf_dev_write() local
1077 return -ENOMEM; in nvmf_dev_write()
1084 if (seq_file->private) { in nvmf_dev_write()
1085 ret = -EINVAL; in nvmf_dev_write()
1089 ctrl = nvmf_create_ctrl(nvmf_device, buf); in nvmf_dev_write()
1090 if (IS_ERR(ctrl)) { in nvmf_dev_write()
1091 ret = PTR_ERR(ctrl); in nvmf_dev_write()
1095 seq_file->private = ctrl; in nvmf_dev_write()
1105 struct nvme_ctrl *ctrl; in nvmf_dev_show() local
1109 ctrl = seq_file->private; in nvmf_dev_show()
1110 if (!ctrl) { in nvmf_dev_show()
1111 ret = -EINVAL; in nvmf_dev_show()
1116 ctrl->instance, ctrl->cntlid); in nvmf_dev_show()
1126 * The miscdevice code initializes file->private_data, but doesn't in nvmf_dev_open()
1129 file->private_data = NULL; in nvmf_dev_open()
1135 struct seq_file *seq_file = file->private_data; in nvmf_dev_release()
1136 struct nvme_ctrl *ctrl = seq_file->private; in nvmf_dev_release() local
1138 if (ctrl) in nvmf_dev_release()
1139 nvme_put_ctrl(ctrl); in nvmf_dev_release()
1153 .name = "nvme-fabrics",
1163 return -ENOMEM; in nvmf_init()
1165 nvmf_class = class_create(THIS_MODULE, "nvme-fabrics"); in nvmf_init()
1167 pr_err("couldn't register class nvme-fabrics\n"); in nvmf_init()
1175 pr_err("couldn't create nvme-fabris device!\n"); in nvmf_init()