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 strscpy(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
155 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, NULL, 0, in nvmf_reg_read32()
161 dev_err(ctrl->device, in nvmf_reg_read32()
170 * nvmf_reg_read64() - NVMe Fabrics "Property Get" API function.
171 * @ctrl: Host NVMe controller instance maintaining the admin
179 * Used by the host system to retrieve a 64-bit capsule property value
190 int nvmf_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val) in nvmf_reg_read64() argument
201 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, NULL, 0, in nvmf_reg_read64()
207 dev_err(ctrl->device, in nvmf_reg_read64()
215 * nvmf_reg_write32() - NVMe Fabrics "Property Write" API function.
216 * @ctrl: Host NVMe controller instance maintaining the admin
224 * Used by the NVMe host system to write a 32-bit capsule property value
235 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, in nvmf_reg_write32()
249 dev_err(ctrl->device, in nvmf_reg_write32()
257 * nvmf_log_connect_error() - Error-parsing-diagnostic print out function for
259 * @ctrl: The specific /dev/nvmeX device that had the error.
260 * @errval: Error code to be decoded in a more human-friendly
267 static void nvmf_log_connect_error(struct nvme_ctrl *ctrl, in nvmf_log_connect_error() argument
274 dev_err(ctrl->device, in nvmf_log_connect_error()
286 dev_err(ctrl->device, in nvmf_log_connect_error()
288 inv_data, data->cntlid); in nvmf_log_connect_error()
291 dev_err(ctrl->device, in nvmf_log_connect_error()
293 inv_data, data->hostnqn); in nvmf_log_connect_error()
296 dev_err(ctrl->device, in nvmf_log_connect_error()
298 inv_data, data->subsysnqn); in nvmf_log_connect_error()
301 dev_err(ctrl->device, in nvmf_log_connect_error()
311 dev_err(ctrl->device, in nvmf_log_connect_error()
313 inv_sqe, cmd->connect.qid); in nvmf_log_connect_error()
316 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()
328 dev_err(ctrl->device, in nvmf_log_connect_error()
332 dev_err(ctrl->device, in nvmf_log_connect_error()
334 cmd->connect.recfmt); in nvmf_log_connect_error()
337 dev_err(ctrl->device, in nvmf_log_connect_error()
341 dev_err(ctrl->device, in nvmf_log_connect_error()
345 dev_err(ctrl->device, in nvmf_log_connect_error()
353 * nvmf_connect_admin_queue() - NVMe Fabrics Admin Queue "Connect"
355 * @ctrl: Host nvme controller instance used to request
362 * fabrics-protocol connection of the NVMe Admin queue between the
372 int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl) in nvmf_connect_admin_queue() argument
383 cmd.connect.sqsize = cpu_to_le16(NVME_AQ_DEPTH - 1); in nvmf_connect_admin_queue()
386 * Set keep-alive timeout in seconds granularity (ms * 1000) in nvmf_connect_admin_queue()
388 cmd.connect.kato = cpu_to_le32(ctrl->kato * 1000); in nvmf_connect_admin_queue()
390 if (ctrl->opts->disable_sqflow) in nvmf_connect_admin_queue()
395 return -ENOMEM; in nvmf_connect_admin_queue()
397 uuid_copy(&data->hostid, &ctrl->opts->host->id); in nvmf_connect_admin_queue()
398 data->cntlid = cpu_to_le16(0xffff); in nvmf_connect_admin_queue()
399 strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_connect_admin_queue()
400 strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); in nvmf_connect_admin_queue()
402 ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res, in nvmf_connect_admin_queue()
406 nvmf_log_connect_error(ctrl, ret, le32_to_cpu(res.u32), in nvmf_connect_admin_queue()
412 ctrl->cntlid = result & 0xFFFF; in nvmf_connect_admin_queue()
415 ret = nvme_auth_negotiate(ctrl, 0); in nvmf_connect_admin_queue()
417 dev_warn(ctrl->device, in nvmf_connect_admin_queue()
422 ret = nvme_auth_wait(ctrl, 0); in nvmf_connect_admin_queue()
424 dev_warn(ctrl->device, in nvmf_connect_admin_queue()
427 dev_info(ctrl->device, in nvmf_connect_admin_queue()
437 * nvmf_connect_io_queue() - NVMe Fabrics I/O Queue "Connect"
439 * @ctrl: Host nvme controller instance used to establish an
446 * This function issues a fabrics-protocol connection
456 int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid) in nvmf_connect_io_queue() argument
467 cmd.connect.sqsize = cpu_to_le16(ctrl->sqsize); in nvmf_connect_io_queue()
469 if (ctrl->opts->disable_sqflow) in nvmf_connect_io_queue()
474 return -ENOMEM; in nvmf_connect_io_queue()
476 uuid_copy(&data->hostid, &ctrl->opts->host->id); in nvmf_connect_io_queue()
477 data->cntlid = cpu_to_le16(ctrl->cntlid); in nvmf_connect_io_queue()
478 strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_connect_io_queue()
479 strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE); in nvmf_connect_io_queue()
481 ret = __nvme_submit_sync_cmd(ctrl->connect_q, &cmd, &res, in nvmf_connect_io_queue()
485 nvmf_log_connect_error(ctrl, ret, le32_to_cpu(res.u32), in nvmf_connect_io_queue()
491 ret = nvme_auth_negotiate(ctrl, qid); in nvmf_connect_io_queue()
493 dev_warn(ctrl->device, in nvmf_connect_io_queue()
497 ret = nvme_auth_wait(ctrl, qid); in nvmf_connect_io_queue()
499 dev_warn(ctrl->device, in nvmf_connect_io_queue()
508 bool nvmf_should_reconnect(struct nvme_ctrl *ctrl) in nvmf_should_reconnect() argument
510 if (ctrl->opts->max_reconnects == -1 || in nvmf_should_reconnect()
511 ctrl->nr_reconnects < ctrl->opts->max_reconnects) in nvmf_should_reconnect()
519 * nvmf_register_transport() - NVMe Fabrics Library registration function.
529 if (!ops->create_ctrl) in nvmf_register_transport()
530 return -EINVAL; in nvmf_register_transport()
533 list_add_tail(&ops->entry, &nvmf_transports); in nvmf_register_transport()
541 * nvmf_unregister_transport() - NVMe Fabrics Library unregistration function.
552 list_del(&ops->entry); in nvmf_unregister_transport()
565 if (strcmp(ops->name, opts->transport) == 0) in nvmf_lookup_transport()
611 opts->queue_size = NVMF_DEF_QUEUE_SIZE; in nvmf_parse_options()
612 opts->nr_io_queues = num_online_cpus(); in nvmf_parse_options()
613 opts->reconnect_delay = NVMF_DEF_RECONNECT_DELAY; in nvmf_parse_options()
614 opts->kato = 0; in nvmf_parse_options()
615 opts->duplicate_connect = false; in nvmf_parse_options()
616 opts->fast_io_fail_tmo = NVMF_DEF_FAIL_FAST_TMO; in nvmf_parse_options()
617 opts->hdr_digest = false; in nvmf_parse_options()
618 opts->data_digest = false; in nvmf_parse_options()
619 opts->tos = -1; /* < 0 == use transport default */ in nvmf_parse_options()
623 return -ENOMEM; in nvmf_parse_options()
632 opts->mask |= token; in nvmf_parse_options()
637 ret = -ENOMEM; in nvmf_parse_options()
640 kfree(opts->transport); in nvmf_parse_options()
641 opts->transport = p; in nvmf_parse_options()
646 ret = -ENOMEM; in nvmf_parse_options()
649 kfree(opts->subsysnqn); in nvmf_parse_options()
650 opts->subsysnqn = p; in nvmf_parse_options()
651 nqnlen = strlen(opts->subsysnqn); in nvmf_parse_options()
654 opts->subsysnqn, NVMF_NQN_SIZE); in nvmf_parse_options()
655 ret = -EINVAL; in nvmf_parse_options()
658 opts->discovery_nqn = in nvmf_parse_options()
659 !(strcmp(opts->subsysnqn, in nvmf_parse_options()
665 ret = -ENOMEM; in nvmf_parse_options()
668 kfree(opts->traddr); in nvmf_parse_options()
669 opts->traddr = p; in nvmf_parse_options()
674 ret = -ENOMEM; in nvmf_parse_options()
677 kfree(opts->trsvcid); in nvmf_parse_options()
678 opts->trsvcid = p; in nvmf_parse_options()
682 ret = -EINVAL; in nvmf_parse_options()
688 ret = -EINVAL; in nvmf_parse_options()
691 opts->queue_size = token; in nvmf_parse_options()
695 ret = -EINVAL; in nvmf_parse_options()
700 ret = -EINVAL; in nvmf_parse_options()
703 if (opts->discovery_nqn) { in nvmf_parse_options()
708 opts->nr_io_queues = min_t(unsigned int, in nvmf_parse_options()
713 ret = -EINVAL; in nvmf_parse_options()
719 ret = -EINVAL; in nvmf_parse_options()
721 } else if (token == 0 && !opts->discovery_nqn) { in nvmf_parse_options()
725 opts->kato = token; in nvmf_parse_options()
729 ret = -EINVAL; in nvmf_parse_options()
739 ret = -EINVAL; in nvmf_parse_options()
747 token = -1; in nvmf_parse_options()
749 opts->fast_io_fail_tmo = token; in nvmf_parse_options()
752 if (opts->host) { in nvmf_parse_options()
753 pr_err("hostnqn already user-assigned: %s\n", in nvmf_parse_options()
754 opts->host->nqn); in nvmf_parse_options()
755 ret = -EADDRINUSE; in nvmf_parse_options()
760 ret = -ENOMEM; in nvmf_parse_options()
768 ret = -EINVAL; in nvmf_parse_options()
771 opts->host = nvmf_host_add(p); in nvmf_parse_options()
773 if (!opts->host) { in nvmf_parse_options()
774 ret = -ENOMEM; in nvmf_parse_options()
780 ret = -EINVAL; in nvmf_parse_options()
785 ret = -EINVAL; in nvmf_parse_options()
788 opts->reconnect_delay = token; in nvmf_parse_options()
793 ret = -ENOMEM; in nvmf_parse_options()
796 kfree(opts->host_traddr); in nvmf_parse_options()
797 opts->host_traddr = p; in nvmf_parse_options()
802 ret = -ENOMEM; in nvmf_parse_options()
805 kfree(opts->host_iface); in nvmf_parse_options()
806 opts->host_iface = p; in nvmf_parse_options()
811 ret = -ENOMEM; in nvmf_parse_options()
817 ret = -EINVAL; in nvmf_parse_options()
824 opts->duplicate_connect = true; in nvmf_parse_options()
827 opts->disable_sqflow = true; in nvmf_parse_options()
830 opts->hdr_digest = true; in nvmf_parse_options()
833 opts->data_digest = true; in nvmf_parse_options()
837 ret = -EINVAL; in nvmf_parse_options()
842 ret = -EINVAL; in nvmf_parse_options()
845 opts->nr_write_queues = token; in nvmf_parse_options()
849 ret = -EINVAL; in nvmf_parse_options()
854 ret = -EINVAL; in nvmf_parse_options()
857 opts->nr_poll_queues = token; in nvmf_parse_options()
861 ret = -EINVAL; in nvmf_parse_options()
866 ret = -EINVAL; in nvmf_parse_options()
873 opts->tos = token; in nvmf_parse_options()
876 opts->discovery_nqn = true; in nvmf_parse_options()
881 ret = -ENOMEM; in nvmf_parse_options()
884 if (strlen(p) < 11 || strncmp(p, "DHHC-1:", 7)) { in nvmf_parse_options()
885 pr_err("Invalid DH-CHAP secret %s\n", p); in nvmf_parse_options()
886 ret = -EINVAL; in nvmf_parse_options()
889 kfree(opts->dhchap_secret); in nvmf_parse_options()
890 opts->dhchap_secret = p; in nvmf_parse_options()
895 ret = -ENOMEM; in nvmf_parse_options()
898 if (strlen(p) < 11 || strncmp(p, "DHHC-1:", 7)) { in nvmf_parse_options()
899 pr_err("Invalid DH-CHAP secret %s\n", p); in nvmf_parse_options()
900 ret = -EINVAL; in nvmf_parse_options()
903 kfree(opts->dhchap_ctrl_secret); in nvmf_parse_options()
904 opts->dhchap_ctrl_secret = p; in nvmf_parse_options()
907 pr_warn("unknown parameter or missing value '%s' in ctrl creation request\n", in nvmf_parse_options()
909 ret = -EINVAL; in nvmf_parse_options()
914 if (opts->discovery_nqn) { in nvmf_parse_options()
915 opts->nr_io_queues = 0; in nvmf_parse_options()
916 opts->nr_write_queues = 0; in nvmf_parse_options()
917 opts->nr_poll_queues = 0; in nvmf_parse_options()
918 opts->duplicate_connect = true; in nvmf_parse_options()
920 if (!opts->kato) in nvmf_parse_options()
921 opts->kato = NVME_DEFAULT_KATO; in nvmf_parse_options()
924 opts->max_reconnects = -1; in nvmf_parse_options()
926 opts->max_reconnects = DIV_ROUND_UP(ctrl_loss_tmo, in nvmf_parse_options()
927 opts->reconnect_delay); in nvmf_parse_options()
928 if (ctrl_loss_tmo < opts->fast_io_fail_tmo) in nvmf_parse_options()
930 opts->fast_io_fail_tmo, ctrl_loss_tmo); in nvmf_parse_options()
933 if (!opts->host) { in nvmf_parse_options()
934 kref_get(&nvmf_default_host->ref); in nvmf_parse_options()
935 opts->host = nvmf_default_host; in nvmf_parse_options()
938 uuid_copy(&opts->host->id, &hostid); in nvmf_parse_options()
948 if ((opts->mask & required_opts) != required_opts) { in nvmf_check_required_opts()
953 !(opt_tokens[i].token & opts->mask)) { in nvmf_check_required_opts()
959 return -EINVAL; in nvmf_check_required_opts()
965 bool nvmf_ip_options_match(struct nvme_ctrl *ctrl, in nvmf_ip_options_match() argument
968 if (!nvmf_ctlr_matches_baseopts(ctrl, opts) || in nvmf_ip_options_match()
969 strcmp(opts->traddr, ctrl->opts->traddr) || in nvmf_ip_options_match()
970 strcmp(opts->trsvcid, ctrl->opts->trsvcid)) in nvmf_ip_options_match()
980 * - local address or host interface is specified and address in nvmf_ip_options_match()
982 * - local address or host interface is not specified but in nvmf_ip_options_match()
986 if ((opts->mask & NVMF_OPT_HOST_TRADDR) && in nvmf_ip_options_match()
987 (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) { in nvmf_ip_options_match()
988 if (strcmp(opts->host_traddr, ctrl->opts->host_traddr)) in nvmf_ip_options_match()
990 } else if ((opts->mask & NVMF_OPT_HOST_TRADDR) || in nvmf_ip_options_match()
991 (ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) { in nvmf_ip_options_match()
995 if ((opts->mask & NVMF_OPT_HOST_IFACE) && in nvmf_ip_options_match()
996 (ctrl->opts->mask & NVMF_OPT_HOST_IFACE)) { in nvmf_ip_options_match()
997 if (strcmp(opts->host_iface, ctrl->opts->host_iface)) in nvmf_ip_options_match()
999 } else if ((opts->mask & NVMF_OPT_HOST_IFACE) || in nvmf_ip_options_match()
1000 (ctrl->opts->mask & NVMF_OPT_HOST_IFACE)) { in nvmf_ip_options_match()
1011 if (opts->mask & ~allowed_opts) { in nvmf_check_allowed_opts()
1015 if ((opt_tokens[i].token & opts->mask) && in nvmf_check_allowed_opts()
1022 return -EINVAL; in nvmf_check_allowed_opts()
1030 nvmf_host_put(opts->host); in nvmf_free_options()
1031 kfree(opts->transport); in nvmf_free_options()
1032 kfree(opts->traddr); in nvmf_free_options()
1033 kfree(opts->trsvcid); in nvmf_free_options()
1034 kfree(opts->subsysnqn); in nvmf_free_options()
1035 kfree(opts->host_traddr); in nvmf_free_options()
1036 kfree(opts->host_iface); in nvmf_free_options()
1037 kfree(opts->dhchap_secret); in nvmf_free_options()
1038 kfree(opts->dhchap_ctrl_secret); in nvmf_free_options()
1056 struct nvme_ctrl *ctrl; in nvmf_create_ctrl() local
1061 return ERR_PTR(-ENOMEM); in nvmf_create_ctrl()
1068 request_module("nvme-%s", opts->transport); in nvmf_create_ctrl()
1078 opts->mask &= ~NVMF_REQUIRED_OPTS; in nvmf_create_ctrl()
1084 opts->transport); in nvmf_create_ctrl()
1085 ret = -EINVAL; in nvmf_create_ctrl()
1089 if (!try_module_get(ops->module)) { in nvmf_create_ctrl()
1090 ret = -EBUSY; in nvmf_create_ctrl()
1095 ret = nvmf_check_required_opts(opts, ops->required_opts); in nvmf_create_ctrl()
1099 ops->allowed_opts | ops->required_opts); in nvmf_create_ctrl()
1103 ctrl = ops->create_ctrl(dev, opts); in nvmf_create_ctrl()
1104 if (IS_ERR(ctrl)) { in nvmf_create_ctrl()
1105 ret = PTR_ERR(ctrl); in nvmf_create_ctrl()
1109 module_put(ops->module); in nvmf_create_ctrl()
1110 return ctrl; in nvmf_create_ctrl()
1113 module_put(ops->module); in nvmf_create_ctrl()
1129 struct seq_file *seq_file = file->private_data; in nvmf_dev_write()
1130 struct nvme_ctrl *ctrl; in nvmf_dev_write() local
1135 return -ENOMEM; in nvmf_dev_write()
1142 if (seq_file->private) { in nvmf_dev_write()
1143 ret = -EINVAL; in nvmf_dev_write()
1147 ctrl = nvmf_create_ctrl(nvmf_device, buf); in nvmf_dev_write()
1148 if (IS_ERR(ctrl)) { in nvmf_dev_write()
1149 ret = PTR_ERR(ctrl); in nvmf_dev_write()
1153 seq_file->private = ctrl; in nvmf_dev_write()
1168 * signal an invalid/non-existing controller in __nvmf_concat_opt_tokens()
1170 seq_puts(seq_file, "instance=-1,cntlid=-1"); in __nvmf_concat_opt_tokens()
1173 if (tok->token == NVMF_OPT_ERR) in __nvmf_concat_opt_tokens()
1176 seq_puts(seq_file, tok->pattern); in __nvmf_concat_opt_tokens()
1183 struct nvme_ctrl *ctrl; in nvmf_dev_show() local
1186 ctrl = seq_file->private; in nvmf_dev_show()
1187 if (!ctrl) { in nvmf_dev_show()
1193 ctrl->instance, ctrl->cntlid); in nvmf_dev_show()
1203 * The miscdevice code initializes file->private_data, but doesn't in nvmf_dev_open()
1206 file->private_data = NULL; in nvmf_dev_open()
1212 struct seq_file *seq_file = file->private_data; in nvmf_dev_release()
1213 struct nvme_ctrl *ctrl = seq_file->private; in nvmf_dev_release() local
1215 if (ctrl) in nvmf_dev_release()
1216 nvme_put_ctrl(ctrl); in nvmf_dev_release()
1230 .name = "nvme-fabrics",
1240 return -ENOMEM; in nvmf_init()
1242 nvmf_class = class_create(THIS_MODULE, "nvme-fabrics"); in nvmf_init()
1244 pr_err("couldn't register class nvme-fabrics\n"); in nvmf_init()
1252 pr_err("couldn't create nvme-fabrics device!\n"); in nvmf_init()