Lines Matching +full:ctrl +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
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
105 int len = 0; in nvmf_get_address() local
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 if (ctrl->opts->mask & NVMF_OPT_HOST_IFACE) in nvmf_get_address()
116 len += scnprintf(buf + len, size - len, "%shost_iface=%s", in nvmf_get_address()
117 (len) ? "," : "", ctrl->opts->host_iface); in nvmf_get_address()
118 len += scnprintf(buf + len, size - len, "\n"); in nvmf_get_address()
120 return len; in nvmf_get_address()
125 * nvmf_reg_read32() - NVMe Fabrics "Property Get" API function.
126 * @ctrl: Host NVMe controller instance maintaining the admin
134 * Used by the host system to retrieve a 32-bit capsule property value
145 int nvmf_reg_read32(struct nvme_ctrl *ctrl, u32 off, u32 *val) in nvmf_reg_read32() argument
156 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, NULL, 0, 0, in nvmf_reg_read32()
162 dev_err(ctrl->device, in nvmf_reg_read32()
171 * nvmf_reg_read64() - NVMe Fabrics "Property Get" API function.
172 * @ctrl: Host NVMe controller instance maintaining the admin
180 * Used by the host system to retrieve a 64-bit capsule property value
191 int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val) in nvmf_reg_read64() argument
202 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, NULL, 0, 0, in nvmf_reg_read64()
208 dev_err(ctrl->device, in nvmf_reg_read64()
216 * nvmf_reg_write32() - NVMe Fabrics "Property Write" API function.
217 * @ctrl: Host NVMe controller instance maintaining the admin
225 * Used by the NVMe host system to write a 32-bit capsule property value
236 int nvmf_reg_write32(struct nvme_ctrl *ctrl, u32 off, u32 val) in nvmf_reg_write32() argument
247 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, NULL, NULL, 0, 0, in nvmf_reg_write32()
250 dev_err(ctrl->device, in nvmf_reg_write32()
258 * nvmf_log_connect_error() - Error-parsing-diagnostic print out function for
260 * @ctrl: The specific /dev/nvmeX device that had the error.
261 * @errval: Error code to be decoded in a more human-friendly
268 static void nvmf_log_connect_error(struct nvme_ctrl *ctrl, in nvmf_log_connect_error() argument
281 dev_err(ctrl->device, in nvmf_log_connect_error()
283 inv_data, data->cntlid); in nvmf_log_connect_error()
286 dev_err(ctrl->device, in nvmf_log_connect_error()
288 inv_data, data->hostnqn); in nvmf_log_connect_error()
291 dev_err(ctrl->device, in nvmf_log_connect_error()
293 inv_data, data->subsysnqn); in nvmf_log_connect_error()
296 dev_err(ctrl->device, in nvmf_log_connect_error()
306 dev_err(ctrl->device, in nvmf_log_connect_error()
308 inv_sqe, cmd->connect.qid); in nvmf_log_connect_error()
311 dev_err(ctrl->device, in nvmf_log_connect_error()
318 dev_err(ctrl->device, in nvmf_log_connect_error()
320 data->subsysnqn, data->hostnqn); in nvmf_log_connect_error()
323 dev_err(ctrl->device, in nvmf_log_connect_error()
327 dev_err(ctrl->device, in nvmf_log_connect_error()
329 cmd->connect.recfmt); in nvmf_log_connect_error()
332 dev_err(ctrl->device, in nvmf_log_connect_error()
336 dev_err(ctrl->device, in nvmf_log_connect_error()
344 * nvmf_connect_admin_queue() - NVMe Fabrics Admin Queue "Connect"
346 * @ctrl: Host nvme controller instance used to request
353 * fabrics-protocol connection of the NVMe Admin queue between the
363 int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl) in nvmf_connect_admin_queue() argument
373 cmd.connect.sqsize = cpu_to_le16(NVME_AQ_DEPTH - 1); in nvmf_connect_admin_queue()
376 * Set keep-alive timeout in seconds granularity (ms * 1000) in nvmf_connect_admin_queue()
378 cmd.connect.kato = cpu_to_le32(ctrl->kato * 1000); in nvmf_connect_admin_queue()
380 if (ctrl->opts->disable_sqflow) in nvmf_connect_admin_queue()
385 return -ENOMEM; in nvmf_connect_admin_queue()
387 uuid_copy(&data->hostid, &ctrl->opts->host->id); in nvmf_connect_admin_queue()
388 data->cntlid = cpu_to_le16(0xffff); in nvmf_connect_admin_queue()
389 strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_connect_admin_queue()
390 strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); in nvmf_connect_admin_queue()
392 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, in nvmf_connect_admin_queue()
396 nvmf_log_connect_error(ctrl, ret, le32_to_cpu(res.u32), in nvmf_connect_admin_queue()
401 ctrl->cntlid = le16_to_cpu(res.u16); in nvmf_connect_admin_queue()
410 * nvmf_connect_io_queue() - NVMe Fabrics I/O Queue "Connect"
412 * @ctrl: Host nvme controller instance used to establish an
419 * This function issues a fabrics-protocol connection
429 int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid) in nvmf_connect_io_queue() argument
439 cmd.connect.sqsize = cpu_to_le16(ctrl->sqsize); in nvmf_connect_io_queue()
441 if (ctrl->opts->disable_sqflow) in nvmf_connect_io_queue()
446 return -ENOMEM; in nvmf_connect_io_queue()
448 uuid_copy(&data->hostid, &ctrl->opts->host->id); in nvmf_connect_io_queue()
449 data->cntlid = cpu_to_le16(ctrl->cntlid); in nvmf_connect_io_queue()
450 strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_connect_io_queue()
451 strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); in nvmf_connect_io_queue()
453 ret = __nvme_submit_sync_cmd(ctrl->connect_q, &cmd, &res, in nvmf_connect_io_queue()
457 nvmf_log_connect_error(ctrl, ret, le32_to_cpu(res.u32), in nvmf_connect_io_queue()
465 bool nvmf_should_reconnect(struct nvme_ctrl *ctrl) in nvmf_should_reconnect() argument
467 if (ctrl->opts->max_reconnects == -1 || in nvmf_should_reconnect()
468 ctrl->nr_reconnects < ctrl->opts->max_reconnects) in nvmf_should_reconnect()
476 * nvmf_register_transport() - NVMe Fabrics Library registration function.
486 if (!ops->create_ctrl) in nvmf_register_transport()
487 return -EINVAL; in nvmf_register_transport()
490 list_add_tail(&ops->entry, &nvmf_transports); in nvmf_register_transport()
498 * nvmf_unregister_transport() - NVMe Fabrics Library unregistration function.
509 list_del(&ops->entry); in nvmf_unregister_transport()
522 if (strcmp(ops->name, opts->transport) == 0) in nvmf_lookup_transport()
565 opts->queue_size = NVMF_DEF_QUEUE_SIZE; in nvmf_parse_options()
566 opts->nr_io_queues = num_online_cpus(); in nvmf_parse_options()
567 opts->reconnect_delay = NVMF_DEF_RECONNECT_DELAY; in nvmf_parse_options()
568 opts->kato = 0; in nvmf_parse_options()
569 opts->duplicate_connect = false; in nvmf_parse_options()
570 opts->fast_io_fail_tmo = NVMF_DEF_FAIL_FAST_TMO; in nvmf_parse_options()
571 opts->hdr_digest = false; in nvmf_parse_options()
572 opts->data_digest = false; in nvmf_parse_options()
573 opts->tos = -1; /* < 0 == use transport default */ in nvmf_parse_options()
577 return -ENOMEM; in nvmf_parse_options()
586 opts->mask |= token; in nvmf_parse_options()
591 ret = -ENOMEM; in nvmf_parse_options()
594 kfree(opts->transport); in nvmf_parse_options()
595 opts->transport = p; in nvmf_parse_options()
600 ret = -ENOMEM; in nvmf_parse_options()
603 kfree(opts->subsysnqn); in nvmf_parse_options()
604 opts->subsysnqn = p; in nvmf_parse_options()
605 nqnlen = strlen(opts->subsysnqn); in nvmf_parse_options()
608 opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_parse_options()
609 ret = -EINVAL; in nvmf_parse_options()
612 opts->discovery_nqn = in nvmf_parse_options()
613 !(strcmp(opts->subsysnqn, in nvmf_parse_options()
619 ret = -ENOMEM; in nvmf_parse_options()
622 kfree(opts->traddr); in nvmf_parse_options()
623 opts->traddr = p; in nvmf_parse_options()
628 ret = -ENOMEM; in nvmf_parse_options()
631 kfree(opts->trsvcid); in nvmf_parse_options()
632 opts->trsvcid = p; in nvmf_parse_options()
636 ret = -EINVAL; in nvmf_parse_options()
642 ret = -EINVAL; in nvmf_parse_options()
645 opts->queue_size = token; in nvmf_parse_options()
649 ret = -EINVAL; in nvmf_parse_options()
654 ret = -EINVAL; in nvmf_parse_options()
657 if (opts->discovery_nqn) { in nvmf_parse_options()
662 opts->nr_io_queues = min_t(unsigned int, in nvmf_parse_options()
667 ret = -EINVAL; in nvmf_parse_options()
673 ret = -EINVAL; in nvmf_parse_options()
675 } else if (token == 0 && !opts->discovery_nqn) { in nvmf_parse_options()
679 opts->kato = token; in nvmf_parse_options()
683 ret = -EINVAL; in nvmf_parse_options()
693 ret = -EINVAL; in nvmf_parse_options()
700 opts->fast_io_fail_tmo = token; in nvmf_parse_options()
703 if (opts->host) { in nvmf_parse_options()
704 pr_err("hostnqn already user-assigned: %s\n", in nvmf_parse_options()
705 opts->host->nqn); in nvmf_parse_options()
706 ret = -EADDRINUSE; in nvmf_parse_options()
711 ret = -ENOMEM; in nvmf_parse_options()
719 ret = -EINVAL; in nvmf_parse_options()
722 opts->host = nvmf_host_add(p); in nvmf_parse_options()
724 if (!opts->host) { in nvmf_parse_options()
725 ret = -ENOMEM; in nvmf_parse_options()
731 ret = -EINVAL; in nvmf_parse_options()
736 ret = -EINVAL; in nvmf_parse_options()
739 opts->reconnect_delay = token; in nvmf_parse_options()
744 ret = -ENOMEM; in nvmf_parse_options()
747 kfree(opts->host_traddr); in nvmf_parse_options()
748 opts->host_traddr = p; in nvmf_parse_options()
753 ret = -ENOMEM; in nvmf_parse_options()
756 kfree(opts->host_iface); in nvmf_parse_options()
757 opts->host_iface = p; in nvmf_parse_options()
762 ret = -ENOMEM; in nvmf_parse_options()
768 ret = -EINVAL; in nvmf_parse_options()
775 opts->duplicate_connect = true; in nvmf_parse_options()
778 opts->disable_sqflow = true; in nvmf_parse_options()
781 opts->hdr_digest = true; in nvmf_parse_options()
784 opts->data_digest = true; in nvmf_parse_options()
788 ret = -EINVAL; in nvmf_parse_options()
793 ret = -EINVAL; in nvmf_parse_options()
796 opts->nr_write_queues = token; in nvmf_parse_options()
800 ret = -EINVAL; in nvmf_parse_options()
805 ret = -EINVAL; in nvmf_parse_options()
808 opts->nr_poll_queues = token; in nvmf_parse_options()
812 ret = -EINVAL; in nvmf_parse_options()
817 ret = -EINVAL; in nvmf_parse_options()
824 opts->tos = token; in nvmf_parse_options()
827 pr_warn("unknown parameter or missing value '%s' in ctrl creation request\n", in nvmf_parse_options()
829 ret = -EINVAL; in nvmf_parse_options()
834 if (opts->discovery_nqn) { in nvmf_parse_options()
835 opts->nr_io_queues = 0; in nvmf_parse_options()
836 opts->nr_write_queues = 0; in nvmf_parse_options()
837 opts->nr_poll_queues = 0; in nvmf_parse_options()
838 opts->duplicate_connect = true; in nvmf_parse_options()
840 if (!opts->kato) in nvmf_parse_options()
841 opts->kato = NVME_DEFAULT_KATO; in nvmf_parse_options()
844 opts->max_reconnects = -1; in nvmf_parse_options()
846 opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, in nvmf_parse_options()
847 opts->reconnect_delay); in nvmf_parse_options()
848 if (ctrl_loss_tmo < opts->fast_io_fail_tmo) in nvmf_parse_options()
850 opts->fast_io_fail_tmo, ctrl_loss_tmo); in nvmf_parse_options()
853 if (!opts->host) { in nvmf_parse_options()
854 kref_get(&nvmf_default_host->ref); in nvmf_parse_options()
855 opts->host = nvmf_default_host; in nvmf_parse_options()
858 uuid_copy(&opts->host->id, &hostid); in nvmf_parse_options()
868 if ((opts->mask & required_opts) != required_opts) { in nvmf_check_required_opts()
873 !(opt_tokens[i].token & opts->mask)) { in nvmf_check_required_opts()
879 return -EINVAL; in nvmf_check_required_opts()
885 bool nvmf_ip_options_match(struct nvme_ctrl *ctrl, in nvmf_ip_options_match() argument
888 if (!nvmf_ctlr_matches_baseopts(ctrl, opts) || in nvmf_ip_options_match()
889 strcmp(opts->traddr, ctrl->opts->traddr) || in nvmf_ip_options_match()
890 strcmp(opts->trsvcid, ctrl->opts->trsvcid)) in nvmf_ip_options_match()
898 * - local address is specified and address is not the same in nvmf_ip_options_match()
899 * - local address is not specified but remote is, or vice versa in nvmf_ip_options_match()
902 if ((opts->mask & NVMF_OPT_HOST_TRADDR) && in nvmf_ip_options_match()
903 (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) { in nvmf_ip_options_match()
904 if (strcmp(opts->host_traddr, ctrl->opts->host_traddr)) in nvmf_ip_options_match()
906 } else if ((opts->mask & NVMF_OPT_HOST_TRADDR) || in nvmf_ip_options_match()
907 (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) { in nvmf_ip_options_match()
918 if (opts->mask & ~allowed_opts) { in nvmf_check_allowed_opts()
922 if ((opt_tokens[i].token & opts->mask) && in nvmf_check_allowed_opts()
929 return -EINVAL; in nvmf_check_allowed_opts()
937 nvmf_host_put(opts->host); in nvmf_free_options()
938 kfree(opts->transport); in nvmf_free_options()
939 kfree(opts->traddr); in nvmf_free_options()
940 kfree(opts->trsvcid); in nvmf_free_options()
941 kfree(opts->subsysnqn); in nvmf_free_options()
942 kfree(opts->host_traddr); in nvmf_free_options()
943 kfree(opts->host_iface); in nvmf_free_options()
960 struct nvme_ctrl *ctrl; in nvmf_create_ctrl() local
965 return ERR_PTR(-ENOMEM); in nvmf_create_ctrl()
972 request_module("nvme-%s", opts->transport); in nvmf_create_ctrl()
982 opts->mask &= ~NVMF_REQUIRED_OPTS; in nvmf_create_ctrl()
988 opts->transport); in nvmf_create_ctrl()
989 ret = -EINVAL; in nvmf_create_ctrl()
993 if (!try_module_get(ops->module)) { in nvmf_create_ctrl()
994 ret = -EBUSY; in nvmf_create_ctrl()
999 ret = nvmf_check_required_opts(opts, ops->required_opts); in nvmf_create_ctrl()
1003 ops->allowed_opts | ops->required_opts); in nvmf_create_ctrl()
1007 ctrl = ops->create_ctrl(dev, opts); in nvmf_create_ctrl()
1008 if (IS_ERR(ctrl)) { in nvmf_create_ctrl()
1009 ret = PTR_ERR(ctrl); in nvmf_create_ctrl()
1013 module_put(ops->module); in nvmf_create_ctrl()
1014 return ctrl; in nvmf_create_ctrl()
1017 module_put(ops->module); in nvmf_create_ctrl()
1033 struct seq_file *seq_file = file->private_data; in nvmf_dev_write()
1034 struct nvme_ctrl *ctrl; in nvmf_dev_write() local
1039 return -ENOMEM; in nvmf_dev_write()
1046 if (seq_file->private) { in nvmf_dev_write()
1047 ret = -EINVAL; in nvmf_dev_write()
1051 ctrl = nvmf_create_ctrl(nvmf_device, buf); in nvmf_dev_write()
1052 if (IS_ERR(ctrl)) { in nvmf_dev_write()
1053 ret = PTR_ERR(ctrl); in nvmf_dev_write()
1057 seq_file->private = ctrl; in nvmf_dev_write()
1067 struct nvme_ctrl *ctrl; in nvmf_dev_show() local
1071 ctrl = seq_file->private; in nvmf_dev_show()
1072 if (!ctrl) { in nvmf_dev_show()
1073 ret = -EINVAL; in nvmf_dev_show()
1078 ctrl->instance, ctrl->cntlid); in nvmf_dev_show()
1088 * The miscdevice code initializes file->private_data, but doesn't in nvmf_dev_open()
1091 file->private_data = NULL; in nvmf_dev_open()
1097 struct seq_file *seq_file = file->private_data; in nvmf_dev_release()
1098 struct nvme_ctrl *ctrl = seq_file->private; in nvmf_dev_release() local
1100 if (ctrl) in nvmf_dev_release()
1101 nvme_put_ctrl(ctrl); in nvmf_dev_release()
1115 .name = "nvme-fabrics",
1125 return -ENOMEM; in nvmf_init()
1127 nvmf_class = class_create(THIS_MODULE, "nvme-fabrics"); in nvmf_init()
1129 pr_err("couldn't register class nvme-fabrics\n"); in nvmf_init()
1137 pr_err("couldn't create nvme-fabris device!\n"); in nvmf_init()