Lines Matching +full:host +full:- +full:port
1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
14 #include <linux/pci-p2pdma.h>
16 #include <linux/nvme-auth.h>
18 #include <linux/nvme-keyring.h>
54 if (p->enabled) in nvmet_is_port_enabled()
55 pr_err("Disable port '%u' before changing attribute in %s\n", in nvmet_is_port_enabled()
56 le16_to_cpu(p->disc_addr.portid), caller); in nvmet_is_port_enabled()
57 return p->enabled; in nvmet_is_port_enabled()
66 u8 adrfam = to_nvmet_port(item)->disc_addr.adrfam; in nvmet_addr_adrfam_show()
81 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_adrfam_store() local
84 if (nvmet_is_port_enabled(port, __func__)) in nvmet_addr_adrfam_store()
85 return -EACCES; in nvmet_addr_adrfam_store()
93 return -EINVAL; in nvmet_addr_adrfam_store()
96 port->disc_addr.adrfam = nvmet_addr_family[i].type; in nvmet_addr_adrfam_store()
105 __le16 portid = to_nvmet_port(item)->disc_addr.portid; in nvmet_addr_portid_show()
113 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_portid_store() local
118 return -EINVAL; in nvmet_addr_portid_store()
121 if (nvmet_is_port_enabled(port, __func__)) in nvmet_addr_portid_store()
122 return -EACCES; in nvmet_addr_portid_store()
124 port->disc_addr.portid = cpu_to_le16(portid); in nvmet_addr_portid_store()
133 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_traddr_show() local
135 return snprintf(page, PAGE_SIZE, "%s\n", port->disc_addr.traddr); in nvmet_addr_traddr_show()
141 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_traddr_store() local
145 return -EINVAL; in nvmet_addr_traddr_store()
148 if (nvmet_is_port_enabled(port, __func__)) in nvmet_addr_traddr_store()
149 return -EACCES; in nvmet_addr_traddr_store()
151 if (sscanf(page, "%s\n", port->disc_addr.traddr) != 1) in nvmet_addr_traddr_store()
152 return -EINVAL; in nvmet_addr_traddr_store()
164 static inline u8 nvmet_port_disc_addr_treq_mask(struct nvmet_port *port) in nvmet_port_disc_addr_treq_mask() argument
166 return (port->disc_addr.treq & ~NVME_TREQ_SECURE_CHANNEL_MASK); in nvmet_port_disc_addr_treq_mask()
186 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_treq_store() local
187 u8 treq = nvmet_port_disc_addr_treq_mask(port); in nvmet_addr_treq_store()
190 if (nvmet_is_port_enabled(port, __func__)) in nvmet_addr_treq_store()
191 return -EACCES; in nvmet_addr_treq_store()
199 return -EINVAL; in nvmet_addr_treq_store()
202 if (port->disc_addr.trtype == NVMF_TRTYPE_TCP && in nvmet_addr_treq_store()
203 port->disc_addr.tsas.tcp.sectype == NVMF_TCP_SECTYPE_TLS13) { in nvmet_addr_treq_store()
208 return -EINVAL; in nvmet_addr_treq_store()
210 pr_warn("Allow non-TLS connections while TLS1.3 is enabled\n"); in nvmet_addr_treq_store()
217 port->disc_addr.treq = treq; in nvmet_addr_treq_store()
226 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_trsvcid_show() local
228 return snprintf(page, PAGE_SIZE, "%s\n", port->disc_addr.trsvcid); in nvmet_addr_trsvcid_show()
234 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_trsvcid_store() local
238 return -EINVAL; in nvmet_addr_trsvcid_store()
240 if (nvmet_is_port_enabled(port, __func__)) in nvmet_addr_trsvcid_store()
241 return -EACCES; in nvmet_addr_trsvcid_store()
243 if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1) in nvmet_addr_trsvcid_store()
244 return -EINVAL; in nvmet_addr_trsvcid_store()
253 struct nvmet_port *port = to_nvmet_port(item); in nvmet_param_inline_data_size_show() local
255 return snprintf(page, PAGE_SIZE, "%d\n", port->inline_data_size); in nvmet_param_inline_data_size_show()
261 struct nvmet_port *port = to_nvmet_port(item); in nvmet_param_inline_data_size_store() local
264 if (nvmet_is_port_enabled(port, __func__)) in nvmet_param_inline_data_size_store()
265 return -EACCES; in nvmet_param_inline_data_size_store()
266 ret = kstrtoint(page, 0, &port->inline_data_size); in nvmet_param_inline_data_size_store()
269 return -EINVAL; in nvmet_param_inline_data_size_store()
279 struct nvmet_port *port = to_nvmet_port(item); in nvmet_param_max_queue_size_show() local
281 return snprintf(page, PAGE_SIZE, "%d\n", port->max_queue_size); in nvmet_param_max_queue_size_show()
287 struct nvmet_port *port = to_nvmet_port(item); in nvmet_param_max_queue_size_store() local
290 if (nvmet_is_port_enabled(port, __func__)) in nvmet_param_max_queue_size_store()
291 return -EACCES; in nvmet_param_max_queue_size_store()
292 ret = kstrtoint(page, 0, &port->max_queue_size); in nvmet_param_max_queue_size_store()
295 return -EINVAL; in nvmet_param_max_queue_size_store()
306 struct nvmet_port *port = to_nvmet_port(item); in nvmet_param_pi_enable_show() local
308 return snprintf(page, PAGE_SIZE, "%d\n", port->pi_enable); in nvmet_param_pi_enable_show()
314 struct nvmet_port *port = to_nvmet_port(item); in nvmet_param_pi_enable_store() local
318 return -EINVAL; in nvmet_param_pi_enable_store()
320 if (nvmet_is_port_enabled(port, __func__)) in nvmet_param_pi_enable_store()
321 return -EACCES; in nvmet_param_pi_enable_store()
323 port->pi_enable = val; in nvmet_param_pi_enable_store()
333 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_trtype_show() local
337 if (port->disc_addr.trtype == nvmet_transport[i].type) in nvmet_addr_trtype_show()
345 static void nvmet_port_init_tsas_rdma(struct nvmet_port *port) in nvmet_port_init_tsas_rdma() argument
347 port->disc_addr.tsas.rdma.qptype = NVMF_RDMA_QPTYPE_CONNECTED; in nvmet_port_init_tsas_rdma()
348 port->disc_addr.tsas.rdma.prtype = NVMF_RDMA_PRTYPE_NOT_SPECIFIED; in nvmet_port_init_tsas_rdma()
349 port->disc_addr.tsas.rdma.cms = NVMF_RDMA_CMS_RDMA_CM; in nvmet_port_init_tsas_rdma()
352 static void nvmet_port_init_tsas_tcp(struct nvmet_port *port, int sectype) in nvmet_port_init_tsas_tcp() argument
354 port->disc_addr.tsas.tcp.sectype = sectype; in nvmet_port_init_tsas_tcp()
360 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_trtype_store() local
363 if (nvmet_is_port_enabled(port, __func__)) in nvmet_addr_trtype_store()
364 return -EACCES; in nvmet_addr_trtype_store()
372 return -EINVAL; in nvmet_addr_trtype_store()
375 memset(&port->disc_addr.tsas, 0, NVMF_TSAS_SIZE); in nvmet_addr_trtype_store()
376 port->disc_addr.trtype = nvmet_transport[i].type; in nvmet_addr_trtype_store()
377 if (port->disc_addr.trtype == NVMF_TRTYPE_RDMA) in nvmet_addr_trtype_store()
378 nvmet_port_init_tsas_rdma(port); in nvmet_addr_trtype_store()
379 else if (port->disc_addr.trtype == NVMF_TRTYPE_TCP) in nvmet_addr_trtype_store()
380 nvmet_port_init_tsas_tcp(port, NVMF_TCP_SECTYPE_NONE); in nvmet_addr_trtype_store()
399 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_tsas_show() local
402 if (port->disc_addr.trtype == NVMF_TRTYPE_TCP) { in nvmet_addr_tsas_show()
404 if (port->disc_addr.tsas.tcp.sectype == nvmet_addr_tsas_tcp[i].type) in nvmet_addr_tsas_show()
407 } else if (port->disc_addr.trtype == NVMF_TRTYPE_RDMA) { in nvmet_addr_tsas_show()
409 if (port->disc_addr.tsas.rdma.qptype == nvmet_addr_tsas_rdma[i].type) in nvmet_addr_tsas_show()
441 struct nvmet_port *port = to_nvmet_port(item); in nvmet_addr_tsas_store() local
442 u8 treq = nvmet_port_disc_addr_treq_mask(port); in nvmet_addr_tsas_store()
445 if (nvmet_is_port_enabled(port, __func__)) in nvmet_addr_tsas_store()
446 return -EACCES; in nvmet_addr_tsas_store()
448 if (port->disc_addr.trtype == NVMF_TRTYPE_RDMA) { in nvmet_addr_tsas_store()
450 if (qptype == port->disc_addr.tsas.rdma.qptype) in nvmet_addr_tsas_store()
452 } else if (port->disc_addr.trtype == NVMF_TRTYPE_TCP) { in nvmet_addr_tsas_store()
459 return -EINVAL; in nvmet_addr_tsas_store()
465 return -EINVAL; in nvmet_addr_tsas_store()
467 if (!port->keyring) { in nvmet_addr_tsas_store()
469 return -EINVAL; in nvmet_addr_tsas_store()
473 nvmet_port_init_tsas_tcp(port, sectype); in nvmet_addr_tsas_store()
478 u8 sc = nvmet_port_disc_addr_treq_secure_channel(port); in nvmet_addr_tsas_store()
487 port->disc_addr.treq = treq; in nvmet_addr_tsas_store()
498 return sprintf(page, "%s\n", to_nvmet_ns(item)->device_path); in nvmet_ns_device_path_show()
505 struct nvmet_subsys *subsys = ns->subsys; in nvmet_ns_device_path_store()
509 mutex_lock(&subsys->lock); in nvmet_ns_device_path_store()
510 ret = -EBUSY; in nvmet_ns_device_path_store()
511 if (ns->enabled) in nvmet_ns_device_path_store()
514 ret = -EINVAL; in nvmet_ns_device_path_store()
519 kfree(ns->device_path); in nvmet_ns_device_path_store()
520 ret = -ENOMEM; in nvmet_ns_device_path_store()
521 ns->device_path = kmemdup_nul(page, len, GFP_KERNEL); in nvmet_ns_device_path_store()
522 if (!ns->device_path) in nvmet_ns_device_path_store()
525 mutex_unlock(&subsys->lock); in nvmet_ns_device_path_store()
529 mutex_unlock(&subsys->lock); in nvmet_ns_device_path_store()
540 return pci_p2pdma_enable_show(page, ns->p2p_dev, ns->use_p2pmem); in nvmet_ns_p2pmem_show()
552 mutex_lock(&ns->subsys->lock); in nvmet_ns_p2pmem_store()
553 if (ns->enabled) { in nvmet_ns_p2pmem_store()
554 ret = -EBUSY; in nvmet_ns_p2pmem_store()
564 ns->use_p2pmem = use_p2pmem; in nvmet_ns_p2pmem_store()
565 pci_dev_put(ns->p2p_dev); in nvmet_ns_p2pmem_store()
566 ns->p2p_dev = p2p_dev; in nvmet_ns_p2pmem_store()
569 mutex_unlock(&ns->subsys->lock); in nvmet_ns_p2pmem_store()
579 return sprintf(page, "%pUb\n", &to_nvmet_ns(item)->uuid); in nvmet_ns_device_uuid_show()
586 struct nvmet_subsys *subsys = ns->subsys; in nvmet_ns_device_uuid_store()
589 mutex_lock(&subsys->lock); in nvmet_ns_device_uuid_store()
590 if (ns->enabled) { in nvmet_ns_device_uuid_store()
591 ret = -EBUSY; in nvmet_ns_device_uuid_store()
595 if (uuid_parse(page, &ns->uuid)) in nvmet_ns_device_uuid_store()
596 ret = -EINVAL; in nvmet_ns_device_uuid_store()
599 mutex_unlock(&subsys->lock); in nvmet_ns_device_uuid_store()
607 return sprintf(page, "%pUb\n", &to_nvmet_ns(item)->nguid); in nvmet_ns_device_nguid_show()
614 struct nvmet_subsys *subsys = ns->subsys; in nvmet_ns_device_nguid_store()
620 mutex_lock(&subsys->lock); in nvmet_ns_device_nguid_store()
621 if (ns->enabled) { in nvmet_ns_device_nguid_store()
622 ret = -EBUSY; in nvmet_ns_device_nguid_store()
628 ret = -EINVAL; in nvmet_ns_device_nguid_store()
632 ret = -EINVAL; in nvmet_ns_device_nguid_store()
639 if (*p == '-' || *p == ':') in nvmet_ns_device_nguid_store()
643 memcpy(&ns->nguid, nguid, sizeof(nguid)); in nvmet_ns_device_nguid_store()
645 mutex_unlock(&subsys->lock); in nvmet_ns_device_nguid_store()
653 return sprintf(page, "%u\n", to_nvmet_ns(item)->anagrpid); in nvmet_ns_ana_grpid_show()
668 return -EINVAL; in nvmet_ns_ana_grpid_store()
671 oldgrpid = ns->anagrpid; in nvmet_ns_ana_grpid_store()
674 ns->anagrpid = newgrpid; in nvmet_ns_ana_grpid_store()
675 nvmet_ana_group_enabled[oldgrpid]--; in nvmet_ns_ana_grpid_store()
679 nvmet_send_ana_event(ns->subsys, NULL); in nvmet_ns_ana_grpid_store()
687 return sprintf(page, "%d\n", to_nvmet_ns(item)->enabled); in nvmet_ns_enable_show()
698 return -EINVAL; in nvmet_ns_enable_store()
702 * window where it releases the subsys-lock, giving a chance to in nvmet_ns_enable_store()
720 return sprintf(page, "%d\n", to_nvmet_ns(item)->buffered_io); in nvmet_ns_buffered_io_show()
730 return -EINVAL; in nvmet_ns_buffered_io_store()
732 mutex_lock(&ns->subsys->lock); in nvmet_ns_buffered_io_store()
733 if (ns->enabled) { in nvmet_ns_buffered_io_store()
735 mutex_unlock(&ns->subsys->lock); in nvmet_ns_buffered_io_store()
736 return -EINVAL; in nvmet_ns_buffered_io_store()
739 ns->buffered_io = val; in nvmet_ns_buffered_io_store()
740 mutex_unlock(&ns->subsys->lock); in nvmet_ns_buffered_io_store()
753 return -EINVAL; in nvmet_ns_revalidate_size_store()
756 return -EINVAL; in nvmet_ns_revalidate_size_store()
758 mutex_lock(&ns->subsys->lock); in nvmet_ns_revalidate_size_store()
759 if (!ns->enabled) { in nvmet_ns_revalidate_size_store()
761 mutex_unlock(&ns->subsys->lock); in nvmet_ns_revalidate_size_store()
762 return -EINVAL; in nvmet_ns_revalidate_size_store()
765 nvmet_ns_changed(ns->subsys, ns->nsid); in nvmet_ns_revalidate_size_store()
766 mutex_unlock(&ns->subsys->lock); in nvmet_ns_revalidate_size_store()
774 return sysfs_emit(page, "%d\n", to_nvmet_ns(item)->pr.enable); in nvmet_ns_resv_enable_show()
784 return -EINVAL; in nvmet_ns_resv_enable_store()
786 mutex_lock(&ns->subsys->lock); in nvmet_ns_resv_enable_store()
787 if (ns->enabled) { in nvmet_ns_resv_enable_store()
788 pr_err("the ns:%d is already enabled.\n", ns->nsid); in nvmet_ns_resv_enable_store()
789 mutex_unlock(&ns->subsys->lock); in nvmet_ns_resv_enable_store()
790 return -EINVAL; in nvmet_ns_resv_enable_store()
792 ns->pr.enable = val; in nvmet_ns_resv_enable_store()
793 mutex_unlock(&ns->subsys->lock); in nvmet_ns_resv_enable_store()
833 struct nvmet_subsys *subsys = namespaces_to_subsys(&group->cg_item); in nvmet_ns_make()
842 ret = -EINVAL; in nvmet_ns_make()
848 ret = -ENOMEM; in nvmet_ns_make()
852 config_group_init_type_name(&ns->group, name, &nvmet_ns_type); in nvmet_ns_make()
854 pr_info("adding nsid %d to subsystem %s\n", nsid, subsys->subsysnqn); in nvmet_ns_make()
856 return &ns->group; in nvmet_ns_make()
875 struct nvmet_subsys *subsys = to_subsys(item->ci_parent); in nvmet_passthru_device_path_show()
877 return snprintf(page, PAGE_SIZE, "%s\n", subsys->passthru_ctrl_path); in nvmet_passthru_device_path_show()
883 struct nvmet_subsys *subsys = to_subsys(item->ci_parent); in nvmet_passthru_device_path_store()
887 mutex_lock(&subsys->lock); in nvmet_passthru_device_path_store()
889 ret = -EBUSY; in nvmet_passthru_device_path_store()
890 if (subsys->passthru_ctrl) in nvmet_passthru_device_path_store()
893 ret = -EINVAL; in nvmet_passthru_device_path_store()
898 kfree(subsys->passthru_ctrl_path); in nvmet_passthru_device_path_store()
899 ret = -ENOMEM; in nvmet_passthru_device_path_store()
900 subsys->passthru_ctrl_path = kstrndup(page, len, GFP_KERNEL); in nvmet_passthru_device_path_store()
901 if (!subsys->passthru_ctrl_path) in nvmet_passthru_device_path_store()
904 mutex_unlock(&subsys->lock); in nvmet_passthru_device_path_store()
908 mutex_unlock(&subsys->lock); in nvmet_passthru_device_path_store()
916 struct nvmet_subsys *subsys = to_subsys(item->ci_parent); in nvmet_passthru_enable_show()
918 return sprintf(page, "%d\n", subsys->passthru_ctrl ? 1 : 0); in nvmet_passthru_enable_show()
924 struct nvmet_subsys *subsys = to_subsys(item->ci_parent); in nvmet_passthru_enable_store()
929 return -EINVAL; in nvmet_passthru_enable_store()
943 return sprintf(page, "%u\n", to_subsys(item->ci_parent)->admin_timeout); in nvmet_passthru_admin_timeout_show()
949 struct nvmet_subsys *subsys = to_subsys(item->ci_parent); in nvmet_passthru_admin_timeout_store()
953 return -EINVAL; in nvmet_passthru_admin_timeout_store()
954 subsys->admin_timeout = timeout; in nvmet_passthru_admin_timeout_store()
962 return sprintf(page, "%u\n", to_subsys(item->ci_parent)->io_timeout); in nvmet_passthru_io_timeout_show()
968 struct nvmet_subsys *subsys = to_subsys(item->ci_parent); in nvmet_passthru_io_timeout_store()
972 return -EINVAL; in nvmet_passthru_io_timeout_store()
973 subsys->io_timeout = timeout; in nvmet_passthru_io_timeout_store()
981 return sprintf(page, "%u\n", to_subsys(item->ci_parent)->clear_ids); in nvmet_passthru_clear_ids_show()
987 struct nvmet_subsys *subsys = to_subsys(item->ci_parent); in nvmet_passthru_clear_ids_store()
991 return -EINVAL; in nvmet_passthru_clear_ids_store()
992 subsys->clear_ids = clear_ids; in nvmet_passthru_clear_ids_store()
1013 config_group_init_type_name(&subsys->passthru_group, in nvmet_add_passthru_group()
1015 configfs_add_default_group(&subsys->passthru_group, in nvmet_add_passthru_group()
1016 &subsys->group); in nvmet_add_passthru_group()
1030 struct nvmet_port *port = to_nvmet_port(parent->ci_parent); in nvmet_port_subsys_allow_link() local
1035 if (target->ci_type != &nvmet_subsys_type) { in nvmet_port_subsys_allow_link()
1037 return -EINVAL; in nvmet_port_subsys_allow_link()
1042 return -ENOMEM; in nvmet_port_subsys_allow_link()
1043 link->subsys = subsys; in nvmet_port_subsys_allow_link()
1046 ret = -EEXIST; in nvmet_port_subsys_allow_link()
1047 list_for_each_entry(p, &port->subsystems, entry) { in nvmet_port_subsys_allow_link()
1048 if (p->subsys == subsys) in nvmet_port_subsys_allow_link()
1052 if (list_empty(&port->subsystems)) { in nvmet_port_subsys_allow_link()
1053 ret = nvmet_enable_port(port); in nvmet_port_subsys_allow_link()
1058 list_add_tail(&link->entry, &port->subsystems); in nvmet_port_subsys_allow_link()
1059 nvmet_port_disc_changed(port, subsys); in nvmet_port_subsys_allow_link()
1073 struct nvmet_port *port = to_nvmet_port(parent->ci_parent); in nvmet_port_subsys_drop_link() local
1078 list_for_each_entry(p, &port->subsystems, entry) { in nvmet_port_subsys_drop_link()
1079 if (p->subsys == subsys) in nvmet_port_subsys_drop_link()
1086 list_del(&p->entry); in nvmet_port_subsys_drop_link()
1087 nvmet_port_del_ctrls(port, subsys); in nvmet_port_subsys_drop_link()
1088 nvmet_port_disc_changed(port, subsys); in nvmet_port_subsys_drop_link()
1090 if (list_empty(&port->subsystems)) in nvmet_port_subsys_drop_link()
1091 nvmet_disable_port(port); in nvmet_port_subsys_drop_link()
1109 struct nvmet_subsys *subsys = to_subsys(parent->ci_parent); in nvmet_allowed_hosts_allow_link()
1110 struct nvmet_host *host; in nvmet_allowed_hosts_allow_link() local
1114 if (target->ci_type != &nvmet_host_type) { in nvmet_allowed_hosts_allow_link()
1116 return -EINVAL; in nvmet_allowed_hosts_allow_link()
1119 host = to_host(target); in nvmet_allowed_hosts_allow_link()
1122 return -ENOMEM; in nvmet_allowed_hosts_allow_link()
1123 link->host = host; in nvmet_allowed_hosts_allow_link()
1126 ret = -EINVAL; in nvmet_allowed_hosts_allow_link()
1127 if (subsys->allow_any_host) { in nvmet_allowed_hosts_allow_link()
1132 ret = -EEXIST; in nvmet_allowed_hosts_allow_link()
1133 list_for_each_entry(p, &subsys->hosts, entry) { in nvmet_allowed_hosts_allow_link()
1134 if (!strcmp(nvmet_host_name(p->host), nvmet_host_name(host))) in nvmet_allowed_hosts_allow_link()
1137 list_add_tail(&link->entry, &subsys->hosts); in nvmet_allowed_hosts_allow_link()
1138 nvmet_subsys_disc_changed(subsys, host); in nvmet_allowed_hosts_allow_link()
1151 struct nvmet_subsys *subsys = to_subsys(parent->ci_parent); in nvmet_allowed_hosts_drop_link()
1152 struct nvmet_host *host = to_host(target); in nvmet_allowed_hosts_drop_link() local
1156 list_for_each_entry(p, &subsys->hosts, entry) { in nvmet_allowed_hosts_drop_link()
1157 if (!strcmp(nvmet_host_name(p->host), nvmet_host_name(host))) in nvmet_allowed_hosts_drop_link()
1164 list_del(&p->entry); in nvmet_allowed_hosts_drop_link()
1165 nvmet_subsys_disc_changed(subsys, host); in nvmet_allowed_hosts_drop_link()
1185 to_subsys(item)->allow_any_host); in nvmet_subsys_attr_allow_any_host_show()
1196 return -EINVAL; in nvmet_subsys_attr_allow_any_host_store()
1199 if (allow_any_host && !list_empty(&subsys->hosts)) { in nvmet_subsys_attr_allow_any_host_store()
1201 ret = -EINVAL; in nvmet_subsys_attr_allow_any_host_store()
1205 if (subsys->allow_any_host != allow_any_host) { in nvmet_subsys_attr_allow_any_host_store()
1206 subsys->allow_any_host = allow_any_host; in nvmet_subsys_attr_allow_any_host_store()
1222 if (NVME_TERTIARY(subsys->ver)) in nvmet_subsys_attr_version_show()
1224 NVME_MAJOR(subsys->ver), in nvmet_subsys_attr_version_show()
1225 NVME_MINOR(subsys->ver), in nvmet_subsys_attr_version_show()
1226 NVME_TERTIARY(subsys->ver)); in nvmet_subsys_attr_version_show()
1229 NVME_MAJOR(subsys->ver), in nvmet_subsys_attr_version_show()
1230 NVME_MINOR(subsys->ver)); in nvmet_subsys_attr_version_show()
1240 if (subsys->subsys_discovered) { in nvmet_subsys_attr_version_store_locked()
1241 if (NVME_TERTIARY(subsys->ver)) in nvmet_subsys_attr_version_store_locked()
1243 NVME_MAJOR(subsys->ver), in nvmet_subsys_attr_version_store_locked()
1244 NVME_MINOR(subsys->ver), in nvmet_subsys_attr_version_store_locked()
1245 NVME_TERTIARY(subsys->ver)); in nvmet_subsys_attr_version_store_locked()
1248 NVME_MAJOR(subsys->ver), in nvmet_subsys_attr_version_store_locked()
1249 NVME_MINOR(subsys->ver)); in nvmet_subsys_attr_version_store_locked()
1250 return -EINVAL; in nvmet_subsys_attr_version_store_locked()
1255 return -EINVAL; in nvmet_subsys_attr_version_store_locked()
1259 return -EINVAL; in nvmet_subsys_attr_version_store_locked()
1261 subsys->ver = NVME_VS(major, minor, tertiary); in nvmet_subsys_attr_version_store_locked()
1273 mutex_lock(&subsys->lock); in nvmet_subsys_attr_version_store()
1275 mutex_unlock(&subsys->lock); in nvmet_subsys_attr_version_store()
1294 NVMET_SN_MAX_SIZE, subsys->serial); in nvmet_subsys_attr_serial_show()
1303 if (subsys->subsys_discovered) { in nvmet_subsys_attr_serial_store_locked()
1305 subsys->serial); in nvmet_subsys_attr_serial_store_locked()
1306 return -EINVAL; in nvmet_subsys_attr_serial_store_locked()
1312 return -EINVAL; in nvmet_subsys_attr_serial_store_locked()
1318 return -EINVAL; in nvmet_subsys_attr_serial_store_locked()
1322 memcpy_and_pad(subsys->serial, NVMET_SN_MAX_SIZE, page, len, ' '); in nvmet_subsys_attr_serial_store_locked()
1334 mutex_lock(&subsys->lock); in nvmet_subsys_attr_serial_store()
1336 mutex_unlock(&subsys->lock); in nvmet_subsys_attr_serial_store()
1346 return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_min); in nvmet_subsys_attr_cntlid_min_show()
1355 return -EINVAL; in nvmet_subsys_attr_cntlid_min_store()
1358 return -EINVAL; in nvmet_subsys_attr_cntlid_min_store()
1361 if (cntlid_min > to_subsys(item)->cntlid_max) in nvmet_subsys_attr_cntlid_min_store()
1363 to_subsys(item)->cntlid_min = cntlid_min; in nvmet_subsys_attr_cntlid_min_store()
1369 return -EINVAL; in nvmet_subsys_attr_cntlid_min_store()
1376 return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_max); in nvmet_subsys_attr_cntlid_max_show()
1385 return -EINVAL; in nvmet_subsys_attr_cntlid_max_store()
1388 return -EINVAL; in nvmet_subsys_attr_cntlid_max_store()
1391 if (cntlid_max < to_subsys(item)->cntlid_min) in nvmet_subsys_attr_cntlid_max_store()
1393 to_subsys(item)->cntlid_max = cntlid_max; in nvmet_subsys_attr_cntlid_max_store()
1399 return -EINVAL; in nvmet_subsys_attr_cntlid_max_store()
1408 return snprintf(page, PAGE_SIZE, "%s\n", subsys->model_number); in nvmet_subsys_attr_model_show()
1417 if (subsys->subsys_discovered) { in nvmet_subsys_attr_model_store_locked()
1419 subsys->model_number); in nvmet_subsys_attr_model_store_locked()
1420 return -EINVAL; in nvmet_subsys_attr_model_store_locked()
1425 return -EINVAL; in nvmet_subsys_attr_model_store_locked()
1430 return -EINVAL; in nvmet_subsys_attr_model_store_locked()
1435 return -EINVAL; in nvmet_subsys_attr_model_store_locked()
1440 return -ENOMEM; in nvmet_subsys_attr_model_store_locked()
1441 kfree(subsys->model_number); in nvmet_subsys_attr_model_store_locked()
1442 subsys->model_number = val; in nvmet_subsys_attr_model_store_locked()
1453 mutex_lock(&subsys->lock); in nvmet_subsys_attr_model_store()
1455 mutex_unlock(&subsys->lock); in nvmet_subsys_attr_model_store()
1467 return sysfs_emit(page, "0x%06x\n", subsys->ieee_oui); in nvmet_subsys_attr_ieee_oui_show()
1476 if (subsys->subsys_discovered) { in nvmet_subsys_attr_ieee_oui_store_locked()
1478 subsys->ieee_oui); in nvmet_subsys_attr_ieee_oui_store_locked()
1479 return -EINVAL; in nvmet_subsys_attr_ieee_oui_store_locked()
1487 return -EINVAL; in nvmet_subsys_attr_ieee_oui_store_locked()
1489 subsys->ieee_oui = val; in nvmet_subsys_attr_ieee_oui_store_locked()
1501 mutex_lock(&subsys->lock); in nvmet_subsys_attr_ieee_oui_store()
1503 mutex_unlock(&subsys->lock); in nvmet_subsys_attr_ieee_oui_store()
1515 return sysfs_emit(page, "%s\n", subsys->firmware_rev); in nvmet_subsys_attr_firmware_show()
1524 if (subsys->subsys_discovered) { in nvmet_subsys_attr_firmware_store_locked()
1526 subsys->firmware_rev); in nvmet_subsys_attr_firmware_store_locked()
1527 return -EINVAL; in nvmet_subsys_attr_firmware_store_locked()
1532 return -EINVAL; in nvmet_subsys_attr_firmware_store_locked()
1537 return -EINVAL; in nvmet_subsys_attr_firmware_store_locked()
1542 return -EINVAL; in nvmet_subsys_attr_firmware_store_locked()
1547 return -ENOMEM; in nvmet_subsys_attr_firmware_store_locked()
1549 kfree(subsys->firmware_rev); in nvmet_subsys_attr_firmware_store_locked()
1551 subsys->firmware_rev = val; in nvmet_subsys_attr_firmware_store_locked()
1563 mutex_lock(&subsys->lock); in nvmet_subsys_attr_firmware_store()
1565 mutex_unlock(&subsys->lock); in nvmet_subsys_attr_firmware_store()
1576 return snprintf(page, PAGE_SIZE, "%d\n", to_subsys(item)->pi_support); in nvmet_subsys_attr_pi_enable_show()
1586 return -EINVAL; in nvmet_subsys_attr_pi_enable_store()
1588 subsys->pi_support = pi_enable; in nvmet_subsys_attr_pi_enable_store()
1597 return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->max_qid); in nvmet_subsys_attr_qid_max_show()
1608 return -EINVAL; in nvmet_subsys_attr_qid_max_store()
1611 return -EINVAL; in nvmet_subsys_attr_qid_max_store()
1614 subsys->max_qid = qid_max; in nvmet_subsys_attr_qid_max_store()
1617 list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) in nvmet_subsys_attr_qid_max_store()
1618 ctrl->ops->delete_ctrl(ctrl); in nvmet_subsys_attr_qid_max_store()
1669 return ERR_PTR(-EINVAL); in nvmet_subsys_make()
1672 if (sysfs_streq(name, nvmet_disc_subsys->subsysnqn)) { in nvmet_subsys_make()
1674 return ERR_PTR(-EINVAL); in nvmet_subsys_make()
1681 config_group_init_type_name(&subsys->group, name, &nvmet_subsys_type); in nvmet_subsys_make()
1683 config_group_init_type_name(&subsys->namespaces_group, in nvmet_subsys_make()
1685 configfs_add_default_group(&subsys->namespaces_group, &subsys->group); in nvmet_subsys_make()
1687 config_group_init_type_name(&subsys->allowed_hosts_group, in nvmet_subsys_make()
1689 configfs_add_default_group(&subsys->allowed_hosts_group, in nvmet_subsys_make()
1690 &subsys->group); in nvmet_subsys_make()
1694 return &subsys->group; in nvmet_subsys_make()
1709 return snprintf(page, PAGE_SIZE, "%d\n", to_nvmet_port(item)->enabled); in nvmet_referral_enable_show()
1715 struct nvmet_port *parent = to_nvmet_port(item->ci_parent->ci_parent); in nvmet_referral_enable_store()
1716 struct nvmet_port *port = to_nvmet_port(item); in nvmet_referral_enable_store() local
1723 nvmet_referral_enable(parent, port); in nvmet_referral_enable_store()
1725 nvmet_referral_disable(parent, port); in nvmet_referral_enable_store()
1730 return -EINVAL; in nvmet_referral_enable_store()
1752 struct nvmet_port *parent = to_nvmet_port(item->ci_parent->ci_parent); in nvmet_referral_notify()
1753 struct nvmet_port *port = to_nvmet_port(item); in nvmet_referral_notify() local
1755 nvmet_referral_disable(parent, port); in nvmet_referral_notify()
1760 struct nvmet_port *port = to_nvmet_port(item); in nvmet_referral_release() local
1762 kfree(port); in nvmet_referral_release()
1778 struct nvmet_port *port; in nvmet_referral_make() local
1780 port = kzalloc(sizeof(*port), GFP_KERNEL); in nvmet_referral_make()
1781 if (!port) in nvmet_referral_make()
1782 return ERR_PTR(-ENOMEM); in nvmet_referral_make()
1784 INIT_LIST_HEAD(&port->entry); in nvmet_referral_make()
1785 config_group_init_type_name(&port->group, name, &nvmet_referral_type); in nvmet_referral_make()
1787 return &port->group; in nvmet_referral_make()
1802 { NVME_ANA_NONOPTIMIZED, "non-optimized" },
1804 { NVME_ANA_PERSISTENT_LOSS, "persistent-loss" },
1812 enum nvme_ana_state state = grp->port->ana_state[grp->grpid]; in nvmet_ana_group_ana_state_show()
1827 enum nvme_ana_state *ana_state = grp->port->ana_state; in nvmet_ana_group_ana_state_store()
1836 return -EINVAL; in nvmet_ana_group_ana_state_store()
1840 ana_state[grp->grpid] = (enum nvme_ana_state) nvmet_ana_state[i].type; in nvmet_ana_group_ana_state_store()
1843 nvmet_port_send_ana_event(grp->port); in nvmet_ana_group_ana_state_store()
1858 if (grp == &grp->port->ana_default_group) in nvmet_ana_group_release()
1862 grp->port->ana_state[grp->grpid] = NVME_ANA_INACCESSIBLE; in nvmet_ana_group_release()
1863 nvmet_ana_group_enabled[grp->grpid]--; in nvmet_ana_group_release()
1866 nvmet_port_send_ana_event(grp->port); in nvmet_ana_group_release()
1883 struct nvmet_port *port = ana_groups_to_port(&group->cg_item); in nvmet_ana_groups_make_group() local
1892 ret = -EINVAL; in nvmet_ana_groups_make_group()
1896 ret = -ENOMEM; in nvmet_ana_groups_make_group()
1900 grp->port = port; in nvmet_ana_groups_make_group()
1901 grp->grpid = grpid; in nvmet_ana_groups_make_group()
1908 nvmet_port_send_ana_event(grp->port); in nvmet_ana_groups_make_group()
1910 config_group_init_type_name(&grp->group, name, &nvmet_ana_group_type); in nvmet_ana_groups_make_group()
1911 return &grp->group; in nvmet_ana_groups_make_group()
1930 struct nvmet_port *port = to_nvmet_port(item); in nvmet_port_release() local
1934 list_del(&port->global_entry); in nvmet_port_release()
1936 key_put(port->keyring); in nvmet_port_release()
1937 kfree(port->ana_state); in nvmet_port_release()
1938 kfree(port); in nvmet_port_release()
1969 struct nvmet_port *port; in nvmet_ports_make() local
1974 return ERR_PTR(-EINVAL); in nvmet_ports_make()
1976 port = kzalloc(sizeof(*port), GFP_KERNEL); in nvmet_ports_make()
1977 if (!port) in nvmet_ports_make()
1978 return ERR_PTR(-ENOMEM); in nvmet_ports_make()
1980 port->ana_state = kcalloc(NVMET_MAX_ANAGRPS + 1, in nvmet_ports_make()
1981 sizeof(*port->ana_state), GFP_KERNEL); in nvmet_ports_make()
1982 if (!port->ana_state) { in nvmet_ports_make()
1983 kfree(port); in nvmet_ports_make()
1984 return ERR_PTR(-ENOMEM); in nvmet_ports_make()
1988 port->keyring = key_lookup(nvme_keyring_id()); in nvmet_ports_make()
1989 if (IS_ERR(port->keyring)) { in nvmet_ports_make()
1991 port->keyring = NULL; in nvmet_ports_make()
1997 port->ana_state[1] = NVME_ANA_OPTIMIZED; in nvmet_ports_make()
1999 port->ana_state[i] = NVME_ANA_INACCESSIBLE; in nvmet_ports_make()
2002 list_add(&port->global_entry, &nvmet_ports_list); in nvmet_ports_make()
2004 INIT_LIST_HEAD(&port->entry); in nvmet_ports_make()
2005 INIT_LIST_HEAD(&port->subsystems); in nvmet_ports_make()
2006 INIT_LIST_HEAD(&port->referrals); in nvmet_ports_make()
2007 port->inline_data_size = -1; /* < 0 == let the transport choose */ in nvmet_ports_make()
2008 port->max_queue_size = -1; /* < 0 == let the transport choose */ in nvmet_ports_make()
2010 port->disc_addr.portid = cpu_to_le16(portid); in nvmet_ports_make()
2011 port->disc_addr.adrfam = NVMF_ADDR_FAMILY_MAX; in nvmet_ports_make()
2012 port->disc_addr.treq = NVMF_TREQ_DISABLE_SQFLOW; in nvmet_ports_make()
2013 config_group_init_type_name(&port->group, name, &nvmet_port_type); in nvmet_ports_make()
2015 config_group_init_type_name(&port->subsys_group, in nvmet_ports_make()
2017 configfs_add_default_group(&port->subsys_group, &port->group); in nvmet_ports_make()
2019 config_group_init_type_name(&port->referrals_group, in nvmet_ports_make()
2021 configfs_add_default_group(&port->referrals_group, &port->group); in nvmet_ports_make()
2023 config_group_init_type_name(&port->ana_groups_group, in nvmet_ports_make()
2025 configfs_add_default_group(&port->ana_groups_group, &port->group); in nvmet_ports_make()
2027 port->ana_default_group.port = port; in nvmet_ports_make()
2028 port->ana_default_group.grpid = NVMET_DEFAULT_ANA_GRPID; in nvmet_ports_make()
2029 config_group_init_type_name(&port->ana_default_group.group, in nvmet_ports_make()
2032 configfs_add_default_group(&port->ana_default_group.group, in nvmet_ports_make()
2033 &port->ana_groups_group); in nvmet_ports_make()
2035 return &port->group; in nvmet_ports_make()
2058 dhchap_secret = to_host(item)->dhchap_secret; in nvmet_host_dhchap_key_show()
2070 struct nvmet_host *host = to_host(item); in nvmet_host_dhchap_key_store() local
2073 ret = nvmet_auth_set_key(host, page, false); in nvmet_host_dhchap_key_store()
2075 * Re-authentication is a soft state, so keep the in nvmet_host_dhchap_key_store()
2076 * current authentication valid until the host in nvmet_host_dhchap_key_store()
2077 * requests re-authentication. in nvmet_host_dhchap_key_store()
2087 u8 *dhchap_secret = to_host(item)->dhchap_ctrl_secret; in nvmet_host_dhchap_ctrl_key_show()
2091 dhchap_secret = to_host(item)->dhchap_ctrl_secret; in nvmet_host_dhchap_ctrl_key_show()
2103 struct nvmet_host *host = to_host(item); in nvmet_host_dhchap_ctrl_key_store() local
2106 ret = nvmet_auth_set_key(host, page, true); in nvmet_host_dhchap_ctrl_key_store()
2108 * Re-authentication is a soft state, so keep the in nvmet_host_dhchap_ctrl_key_store()
2109 * current authentication valid until the host in nvmet_host_dhchap_ctrl_key_store()
2110 * requests re-authentication. in nvmet_host_dhchap_ctrl_key_store()
2120 struct nvmet_host *host = to_host(item); in nvmet_host_dhchap_hash_show() local
2121 const char *hash_name = nvme_auth_hmac_name(host->dhchap_hash_id); in nvmet_host_dhchap_hash_show()
2129 struct nvmet_host *host = to_host(item); in nvmet_host_dhchap_hash_store() local
2134 return -EINVAL; in nvmet_host_dhchap_hash_store()
2136 return -ENOTSUPP; in nvmet_host_dhchap_hash_store()
2137 host->dhchap_hash_id = hmac_id; in nvmet_host_dhchap_hash_store()
2146 struct nvmet_host *host = to_host(item); in nvmet_host_dhchap_dhgroup_show() local
2147 const char *dhgroup = nvme_auth_dhgroup_name(host->dhchap_dhgroup_id); in nvmet_host_dhchap_dhgroup_show()
2155 struct nvmet_host *host = to_host(item); in nvmet_host_dhchap_dhgroup_store() local
2160 return -EINVAL; in nvmet_host_dhchap_dhgroup_store()
2165 return -EINVAL; in nvmet_host_dhchap_dhgroup_store()
2167 host->dhchap_dhgroup_id = dhgroup_id; in nvmet_host_dhchap_dhgroup_store()
2184 struct nvmet_host *host = to_host(item); in nvmet_host_release() local
2187 kfree(host->dhchap_secret); in nvmet_host_release()
2188 kfree(host->dhchap_ctrl_secret); in nvmet_host_release()
2190 kfree(host); in nvmet_host_release()
2208 struct nvmet_host *host; in nvmet_hosts_make_group() local
2210 host = kzalloc(sizeof(*host), GFP_KERNEL); in nvmet_hosts_make_group()
2211 if (!host) in nvmet_hosts_make_group()
2212 return ERR_PTR(-ENOMEM); in nvmet_hosts_make_group()
2216 host->dhchap_hash_id = NVME_AUTH_HASH_SHA256; in nvmet_hosts_make_group()
2219 config_group_init_type_name(&host->group, name, &nvmet_host_type); in nvmet_hosts_make_group()
2221 return &host->group; in nvmet_hosts_make_group()
2238 return snprintf(page, PAGE_SIZE, "%s\n", nvmet_disc_subsys->subsysnqn); in nvmet_root_discovery_nqn_show()
2249 if (!len || len > NVMF_NQN_FIELD_LEN - 1) in nvmet_root_discovery_nqn_store()
2250 return -EINVAL; in nvmet_root_discovery_nqn_store()
2254 return -ENOMEM; in nvmet_root_discovery_nqn_store()
2265 return -EINVAL; in nvmet_root_discovery_nqn_store()
2268 old_nqn = nvmet_disc_subsys->subsysnqn; in nvmet_root_discovery_nqn_store()
2269 nvmet_disc_subsys->subsysnqn = new_nqn; in nvmet_root_discovery_nqn_store()