1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2e48354ceSNicholas Bellinger /*******************************************************************************
3e48354ceSNicholas Bellinger  * This file contains the configfs implementation for iSCSI Target mode
4e48354ceSNicholas Bellinger  * from the LIO-Target Project.
5e48354ceSNicholas Bellinger  *
64c76251eSNicholas Bellinger  * (c) Copyright 2007-2013 Datera, Inc.
7e48354ceSNicholas Bellinger  *
8e48354ceSNicholas Bellinger  * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9e48354ceSNicholas Bellinger  *
10e48354ceSNicholas Bellinger  ****************************************************************************/
11e48354ceSNicholas Bellinger 
12e48354ceSNicholas Bellinger #include <linux/configfs.h>
13ad7babd2SJörn Engel #include <linux/ctype.h>
14c53181afSPaul Gortmaker #include <linux/export.h>
15c3bc93daSStephen Rothwell #include <linux/inet.h>
168dcf07beSBart Van Assche #include <linux/module.h>
178dcf07beSBart Van Assche #include <net/ipv6.h>
18e48354ceSNicholas Bellinger #include <target/target_core_base.h>
19c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h>
202ec5a8c1SNicholas Bellinger #include <target/iscsi/iscsi_transport.h>
2167f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h>
22e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h"
23e48354ceSNicholas Bellinger #include "iscsi_target_device.h"
24e48354ceSNicholas Bellinger #include "iscsi_target_erl0.h"
25e48354ceSNicholas Bellinger #include "iscsi_target_nodeattrib.h"
26e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h"
27e48354ceSNicholas Bellinger #include "iscsi_target_util.h"
28e48354ceSNicholas Bellinger #include "iscsi_target.h"
2967f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_stat.h>
30e48354ceSNicholas Bellinger 
31e48354ceSNicholas Bellinger 
32e48354ceSNicholas Bellinger /* Start items for lio_target_portal_cit */
33e48354ceSNicholas Bellinger 
to_iscsi_tpg_np(struct config_item * item)342eafd729SChristoph Hellwig static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
35e48354ceSNicholas Bellinger {
362eafd729SChristoph Hellwig 	return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
372eafd729SChristoph Hellwig }
382eafd729SChristoph Hellwig 
lio_target_np_driver_show(struct config_item * item,char * page,enum iscsit_transport_type type)39d4b3fa4bSNicholas Bellinger static ssize_t lio_target_np_driver_show(struct config_item *item, char *page,
40d4b3fa4bSNicholas Bellinger 					 enum iscsit_transport_type type)
412eafd729SChristoph Hellwig {
422eafd729SChristoph Hellwig 	struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
43d4b3fa4bSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np_new;
44e48354ceSNicholas Bellinger 	ssize_t rb;
45e48354ceSNicholas Bellinger 
46d4b3fa4bSNicholas Bellinger 	tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
47d4b3fa4bSNicholas Bellinger 	if (tpg_np_new)
48*c0431febSKonstantin Shelekhin 		rb = sysfs_emit(page, "1\n");
49e48354ceSNicholas Bellinger 	else
50*c0431febSKonstantin Shelekhin 		rb = sysfs_emit(page, "0\n");
51e48354ceSNicholas Bellinger 
52e48354ceSNicholas Bellinger 	return rb;
53e48354ceSNicholas Bellinger }
54e48354ceSNicholas Bellinger 
lio_target_np_driver_store(struct config_item * item,const char * page,size_t count,enum iscsit_transport_type type,const char * mod_name)55d4b3fa4bSNicholas Bellinger static ssize_t lio_target_np_driver_store(struct config_item *item,
56d4b3fa4bSNicholas Bellinger 		const char *page, size_t count, enum iscsit_transport_type type,
57d4b3fa4bSNicholas Bellinger 		const char *mod_name)
58e48354ceSNicholas Bellinger {
592eafd729SChristoph Hellwig 	struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
60e48354ceSNicholas Bellinger 	struct iscsi_np *np;
61e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
62d4b3fa4bSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np_new = NULL;
63e48354ceSNicholas Bellinger 	u32 op;
64d4b3fa4bSNicholas Bellinger 	int rc;
65e48354ceSNicholas Bellinger 
66d4b3fa4bSNicholas Bellinger 	rc = kstrtou32(page, 0, &op);
67d4b3fa4bSNicholas Bellinger 	if (rc)
68d4b3fa4bSNicholas Bellinger 		return rc;
69e48354ceSNicholas Bellinger 	if ((op != 1) && (op != 0)) {
70e48354ceSNicholas Bellinger 		pr_err("Illegal value for tpg_enable: %u\n", op);
71e48354ceSNicholas Bellinger 		return -EINVAL;
72e48354ceSNicholas Bellinger 	}
73e48354ceSNicholas Bellinger 	np = tpg_np->tpg_np;
74e48354ceSNicholas Bellinger 	if (!np) {
75e48354ceSNicholas Bellinger 		pr_err("Unable to locate struct iscsi_np from"
76e48354ceSNicholas Bellinger 				" struct iscsi_tpg_np\n");
77e48354ceSNicholas Bellinger 		return -EINVAL;
78e48354ceSNicholas Bellinger 	}
79e48354ceSNicholas Bellinger 
80e48354ceSNicholas Bellinger 	tpg = tpg_np->tpg;
81e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)
82e48354ceSNicholas Bellinger 		return -EINVAL;
83e48354ceSNicholas Bellinger 
84e48354ceSNicholas Bellinger 	if (op) {
85d4b3fa4bSNicholas Bellinger 		if (strlen(mod_name)) {
86d4b3fa4bSNicholas Bellinger 			rc = request_module(mod_name);
87d4b3fa4bSNicholas Bellinger 			if (rc != 0) {
88d4b3fa4bSNicholas Bellinger 				pr_warn("Unable to request_module for %s\n",
89d4b3fa4bSNicholas Bellinger 					mod_name);
90d4b3fa4bSNicholas Bellinger 				rc = 0;
91d4b3fa4bSNicholas Bellinger 			}
92d4b3fa4bSNicholas Bellinger 		}
93d4b3fa4bSNicholas Bellinger 
94d4b3fa4bSNicholas Bellinger 		tpg_np_new = iscsit_tpg_add_network_portal(tpg,
95d4b3fa4bSNicholas Bellinger 					&np->np_sockaddr, tpg_np, type);
9683337e54SVarun Prakash 		if (IS_ERR(tpg_np_new)) {
9783337e54SVarun Prakash 			rc = PTR_ERR(tpg_np_new);
98e48354ceSNicholas Bellinger 			goto out;
9983337e54SVarun Prakash 		}
100e48354ceSNicholas Bellinger 	} else {
101d4b3fa4bSNicholas Bellinger 		tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
102d4b3fa4bSNicholas Bellinger 		if (tpg_np_new) {
103d4b3fa4bSNicholas Bellinger 			rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
104d4b3fa4bSNicholas Bellinger 			if (rc < 0)
105e48354ceSNicholas Bellinger 				goto out;
106d4b3fa4bSNicholas Bellinger 		}
107e48354ceSNicholas Bellinger 	}
108e48354ceSNicholas Bellinger 
109e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
110e48354ceSNicholas Bellinger 	return count;
111e48354ceSNicholas Bellinger out:
112e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
113d4b3fa4bSNicholas Bellinger 	return rc;
114e48354ceSNicholas Bellinger }
115e48354ceSNicholas Bellinger 
lio_target_np_iser_show(struct config_item * item,char * page)1162eafd729SChristoph Hellwig static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
11772438cddSNicholas Bellinger {
118d4b3fa4bSNicholas Bellinger 	return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
11972438cddSNicholas Bellinger }
12072438cddSNicholas Bellinger 
lio_target_np_iser_store(struct config_item * item,const char * page,size_t count)1212eafd729SChristoph Hellwig static ssize_t lio_target_np_iser_store(struct config_item *item,
1222eafd729SChristoph Hellwig 					const char *page, size_t count)
12372438cddSNicholas Bellinger {
124d4b3fa4bSNicholas Bellinger 	return lio_target_np_driver_store(item, page, count,
125d4b3fa4bSNicholas Bellinger 					  ISCSI_INFINIBAND, "ib_isert");
126d4b3fa4bSNicholas Bellinger }
127d4b3fa4bSNicholas Bellinger CONFIGFS_ATTR(lio_target_np_, iser);
12872438cddSNicholas Bellinger 
lio_target_np_cxgbit_show(struct config_item * item,char * page)129ff7199b0SNicholas Bellinger static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page)
1301c46960eSVarun Prakash {
131ff7199b0SNicholas Bellinger 	return lio_target_np_driver_show(item, page, ISCSI_CXGBIT);
1321c46960eSVarun Prakash }
1331c46960eSVarun Prakash 
lio_target_np_cxgbit_store(struct config_item * item,const char * page,size_t count)134ff7199b0SNicholas Bellinger static ssize_t lio_target_np_cxgbit_store(struct config_item *item,
1351c46960eSVarun Prakash 					  const char *page, size_t count)
1361c46960eSVarun Prakash {
137d4b3fa4bSNicholas Bellinger 	return lio_target_np_driver_store(item, page, count,
138ff7199b0SNicholas Bellinger 					  ISCSI_CXGBIT, "cxgbit");
1391c46960eSVarun Prakash }
140ff7199b0SNicholas Bellinger CONFIGFS_ATTR(lio_target_np_, cxgbit);
14172438cddSNicholas Bellinger 
142e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_portal_attrs[] = {
1432eafd729SChristoph Hellwig 	&lio_target_np_attr_iser,
144ff7199b0SNicholas Bellinger 	&lio_target_np_attr_cxgbit,
145e48354ceSNicholas Bellinger 	NULL,
146e48354ceSNicholas Bellinger };
147e48354ceSNicholas Bellinger 
148e48354ceSNicholas Bellinger /* Stop items for lio_target_portal_cit */
149e48354ceSNicholas Bellinger 
150e48354ceSNicholas Bellinger /* Start items for lio_target_np_cit */
151e48354ceSNicholas Bellinger 
152e48354ceSNicholas Bellinger #define MAX_PORTAL_LEN		256
153e48354ceSNicholas Bellinger 
lio_target_call_addnptotpg(struct se_portal_group * se_tpg,struct config_group * group,const char * name)154fceb5bc7SChristoph Hellwig static struct se_tpg_np *lio_target_call_addnptotpg(
155e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,
156e48354ceSNicholas Bellinger 	struct config_group *group,
157e48354ceSNicholas Bellinger 	const char *name)
158e48354ceSNicholas Bellinger {
159e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
160e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np;
161e48354ceSNicholas Bellinger 	char *str, *str2, *ip_str, *port_str;
1624459e042SSagi Grimberg 	struct sockaddr_storage sockaddr = { };
163e48354ceSNicholas Bellinger 	int ret;
164c22659fbSChaitanya Kulkarni 	char buf[MAX_PORTAL_LEN + 1] = { };
165e48354ceSNicholas Bellinger 
166e48354ceSNicholas Bellinger 	if (strlen(name) > MAX_PORTAL_LEN) {
167e48354ceSNicholas Bellinger 		pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
168e48354ceSNicholas Bellinger 			(int)strlen(name), MAX_PORTAL_LEN);
169e48354ceSNicholas Bellinger 		return ERR_PTR(-EOVERFLOW);
170e48354ceSNicholas Bellinger 	}
1717bbb654eSNicholas Bellinger 	snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
172e48354ceSNicholas Bellinger 
173e48354ceSNicholas Bellinger 	str = strstr(buf, "[");
174e48354ceSNicholas Bellinger 	if (str) {
175e48354ceSNicholas Bellinger 		str2 = strstr(str, "]");
176e48354ceSNicholas Bellinger 		if (!str2) {
177e48354ceSNicholas Bellinger 			pr_err("Unable to locate trailing \"]\""
178e48354ceSNicholas Bellinger 				" in IPv6 iSCSI network portal address\n");
179e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
180e48354ceSNicholas Bellinger 		}
1814459e042SSagi Grimberg 
1824459e042SSagi Grimberg 		ip_str = str + 1; /* Skip over leading "[" */
18376c28f1fSAndy Grover 		*str2 = '\0'; /* Terminate the unbracketed IPv6 address */
18476c28f1fSAndy Grover 		str2++; /* Skip over the \0 */
1854459e042SSagi Grimberg 
186e48354ceSNicholas Bellinger 		port_str = strstr(str2, ":");
187e48354ceSNicholas Bellinger 		if (!port_str) {
188e48354ceSNicholas Bellinger 			pr_err("Unable to locate \":port\""
189e48354ceSNicholas Bellinger 				" in IPv6 iSCSI network portal address\n");
190e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
191e48354ceSNicholas Bellinger 		}
192e48354ceSNicholas Bellinger 		*port_str = '\0'; /* Terminate string for IP */
193e48354ceSNicholas Bellinger 		port_str++; /* Skip over ":" */
194e48354ceSNicholas Bellinger 	} else {
1954459e042SSagi Grimberg 		ip_str = &buf[0];
196e48354ceSNicholas Bellinger 		port_str = strstr(ip_str, ":");
197e48354ceSNicholas Bellinger 		if (!port_str) {
198e48354ceSNicholas Bellinger 			pr_err("Unable to locate \":port\""
199e48354ceSNicholas Bellinger 				" in IPv4 iSCSI network portal address\n");
200e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
201e48354ceSNicholas Bellinger 		}
202e48354ceSNicholas Bellinger 		*port_str = '\0'; /* Terminate string for IP */
203e48354ceSNicholas Bellinger 		port_str++; /* Skip over ":" */
2044459e042SSagi Grimberg 	}
205e48354ceSNicholas Bellinger 
2064459e042SSagi Grimberg 	ret = inet_pton_with_scope(&init_net, AF_UNSPEC, ip_str,
2074459e042SSagi Grimberg 			port_str, &sockaddr);
2084459e042SSagi Grimberg 	if (ret) {
2094459e042SSagi Grimberg 		pr_err("malformed ip/port passed: %s\n", name);
210e48354ceSNicholas Bellinger 		return ERR_PTR(ret);
211e48354ceSNicholas Bellinger 	}
2124459e042SSagi Grimberg 
213a11b8069SDmitry Bogdanov 	tpg = to_iscsi_tpg(se_tpg);
214e48354ceSNicholas Bellinger 	ret = iscsit_get_tpg(tpg);
215e48354ceSNicholas Bellinger 	if (ret < 0)
216e48354ceSNicholas Bellinger 		return ERR_PTR(-EINVAL);
217e48354ceSNicholas Bellinger 
218e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
219e48354ceSNicholas Bellinger 		" PORTAL: %s\n",
220e48354ceSNicholas Bellinger 		config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
221e48354ceSNicholas Bellinger 		tpg->tpgt, name);
222e48354ceSNicholas Bellinger 	/*
223e48354ceSNicholas Bellinger 	 * Assume ISCSI_TCP by default.  Other network portals for other
224e48354ceSNicholas Bellinger 	 * iSCSI fabrics:
225e48354ceSNicholas Bellinger 	 *
226e48354ceSNicholas Bellinger 	 * Traditional iSCSI over SCTP (initial support)
227e48354ceSNicholas Bellinger 	 * iSER/TCP (TODO, hardware available)
228e48354ceSNicholas Bellinger 	 * iSER/SCTP (TODO, software emulation with osc-iwarp)
229e48354ceSNicholas Bellinger 	 * iSER/IB (TODO, hardware available)
230e48354ceSNicholas Bellinger 	 *
23120879696SMasanari Iida 	 * can be enabled with attributes under
232e48354ceSNicholas Bellinger 	 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
233e48354ceSNicholas Bellinger 	 *
234e48354ceSNicholas Bellinger 	 */
23576c28f1fSAndy Grover 	tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
236e48354ceSNicholas Bellinger 				ISCSI_TCP);
237e48354ceSNicholas Bellinger 	if (IS_ERR(tpg_np)) {
238e48354ceSNicholas Bellinger 		iscsit_put_tpg(tpg);
239e1750ba2SThomas Meyer 		return ERR_CAST(tpg_np);
240e48354ceSNicholas Bellinger 	}
241e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
242e48354ceSNicholas Bellinger 
243e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
244e48354ceSNicholas Bellinger 	return &tpg_np->se_tpg_np;
245e48354ceSNicholas Bellinger }
246e48354ceSNicholas Bellinger 
lio_target_call_delnpfromtpg(struct se_tpg_np * se_tpg_np)247e48354ceSNicholas Bellinger static void lio_target_call_delnpfromtpg(
248e48354ceSNicholas Bellinger 	struct se_tpg_np *se_tpg_np)
249e48354ceSNicholas Bellinger {
250e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
251e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np;
252e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg;
253e48354ceSNicholas Bellinger 	int ret;
254e48354ceSNicholas Bellinger 
255e48354ceSNicholas Bellinger 	tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
256e48354ceSNicholas Bellinger 	tpg = tpg_np->tpg;
257e48354ceSNicholas Bellinger 	ret = iscsit_get_tpg(tpg);
258e48354ceSNicholas Bellinger 	if (ret < 0)
259e48354ceSNicholas Bellinger 		return;
260e48354ceSNicholas Bellinger 
261e48354ceSNicholas Bellinger 	se_tpg = &tpg->tpg_se_tpg;
262e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
26369d75574SAndy Grover 		" PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
26469d75574SAndy Grover 		tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
265e48354ceSNicholas Bellinger 
266e48354ceSNicholas Bellinger 	ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
267e48354ceSNicholas Bellinger 	if (ret < 0)
268e48354ceSNicholas Bellinger 		goto out;
269e48354ceSNicholas Bellinger 
270e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
271e48354ceSNicholas Bellinger out:
272e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
273e48354ceSNicholas Bellinger }
274e48354ceSNicholas Bellinger 
275e48354ceSNicholas Bellinger /* End items for lio_target_np_cit */
276e48354ceSNicholas Bellinger 
277e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_attrib_cit */
278e48354ceSNicholas Bellinger 
2792eafd729SChristoph Hellwig #define ISCSI_NACL_ATTR(name)						\
2802eafd729SChristoph Hellwig static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
281e48354ceSNicholas Bellinger 		char *page)						\
282e48354ceSNicholas Bellinger {									\
2832eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = attrib_to_nacl(item);		\
284a11b8069SDmitry Bogdanov 	struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl);		\
285*c0431febSKonstantin Shelekhin 	return sysfs_emit(page, "%u\n", nacl->node_attrib.name);		\
286e48354ceSNicholas Bellinger }									\
287e48354ceSNicholas Bellinger 									\
2882eafd729SChristoph Hellwig static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
2892eafd729SChristoph Hellwig 		const char *page, size_t count)				\
290e48354ceSNicholas Bellinger {									\
2912eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = attrib_to_nacl(item);		\
292a11b8069SDmitry Bogdanov 	struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl);		\
293e48354ceSNicholas Bellinger 	u32 val;							\
294e48354ceSNicholas Bellinger 	int ret;							\
295e48354ceSNicholas Bellinger 									\
296ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &val);					\
297ad7babd2SJörn Engel 	if (ret)							\
298ad7babd2SJörn Engel 		return ret;						\
299e48354ceSNicholas Bellinger 	ret = iscsit_na_##name(nacl, val);				\
300e48354ceSNicholas Bellinger 	if (ret < 0)							\
301e48354ceSNicholas Bellinger 		return ret;						\
302e48354ceSNicholas Bellinger 									\
303e48354ceSNicholas Bellinger 	return count;							\
3042eafd729SChristoph Hellwig }									\
3052eafd729SChristoph Hellwig 									\
3062eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
307e48354ceSNicholas Bellinger 
3082eafd729SChristoph Hellwig ISCSI_NACL_ATTR(dataout_timeout);
3092eafd729SChristoph Hellwig ISCSI_NACL_ATTR(dataout_timeout_retries);
3102eafd729SChristoph Hellwig ISCSI_NACL_ATTR(default_erl);
3112eafd729SChristoph Hellwig ISCSI_NACL_ATTR(nopin_timeout);
3122eafd729SChristoph Hellwig ISCSI_NACL_ATTR(nopin_response_timeout);
3132eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_datain_pdu_offsets);
3142eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_datain_seq_offsets);
3152eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_r2t_offsets);
316e48354ceSNicholas Bellinger 
iscsi_nacl_attrib_authentication_show(struct config_item * item,char * page)317a6e0d179SDmitry Bogdanov static ssize_t iscsi_nacl_attrib_authentication_show(struct config_item *item,
318a6e0d179SDmitry Bogdanov 		char *page)
319a6e0d179SDmitry Bogdanov {
320a6e0d179SDmitry Bogdanov 	struct se_node_acl *se_nacl = attrib_to_nacl(item);
321a6e0d179SDmitry Bogdanov 	struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl);
322a6e0d179SDmitry Bogdanov 
323*c0431febSKonstantin Shelekhin 	return sysfs_emit(page, "%d\n", nacl->node_attrib.authentication);
324a6e0d179SDmitry Bogdanov }
325a6e0d179SDmitry Bogdanov 
iscsi_nacl_attrib_authentication_store(struct config_item * item,const char * page,size_t count)326a6e0d179SDmitry Bogdanov static ssize_t iscsi_nacl_attrib_authentication_store(struct config_item *item,
327a6e0d179SDmitry Bogdanov 		const char *page, size_t count)
328a6e0d179SDmitry Bogdanov {
329a6e0d179SDmitry Bogdanov 	struct se_node_acl *se_nacl = attrib_to_nacl(item);
330a6e0d179SDmitry Bogdanov 	struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl);
331a6e0d179SDmitry Bogdanov 	s32 val;
332a6e0d179SDmitry Bogdanov 	int ret;
333a6e0d179SDmitry Bogdanov 
334a6e0d179SDmitry Bogdanov 	ret = kstrtos32(page, 0, &val);
335a6e0d179SDmitry Bogdanov 	if (ret)
336a6e0d179SDmitry Bogdanov 		return ret;
337a6e0d179SDmitry Bogdanov 	if (val != 0 && val != 1 && val != NA_AUTHENTICATION_INHERITED)
338a6e0d179SDmitry Bogdanov 		return -EINVAL;
339a6e0d179SDmitry Bogdanov 
340a6e0d179SDmitry Bogdanov 	nacl->node_attrib.authentication = val;
341a6e0d179SDmitry Bogdanov 
342a6e0d179SDmitry Bogdanov 	return count;
343a6e0d179SDmitry Bogdanov }
344a6e0d179SDmitry Bogdanov 
345a6e0d179SDmitry Bogdanov CONFIGFS_ATTR(iscsi_nacl_attrib_, authentication);
346a6e0d179SDmitry Bogdanov 
347e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
3482eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_dataout_timeout,
3492eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_dataout_timeout_retries,
3502eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_default_erl,
3512eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_nopin_timeout,
3522eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_nopin_response_timeout,
3532eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
3542eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_random_datain_seq_offsets,
3552eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_random_r2t_offsets,
356a6e0d179SDmitry Bogdanov 	&iscsi_nacl_attrib_attr_authentication,
357e48354ceSNicholas Bellinger 	NULL,
358e48354ceSNicholas Bellinger };
359e48354ceSNicholas Bellinger 
360e48354ceSNicholas Bellinger /* End items for lio_target_nacl_attrib_cit */
361e48354ceSNicholas Bellinger 
362e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_auth_cit */
363e48354ceSNicholas Bellinger 
364e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_STR(prefix, name, flags)			\
3652eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(			\
366e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
367e48354ceSNicholas Bellinger 	char *page)							\
368e48354ceSNicholas Bellinger {									\
369e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
370e48354ceSNicholas Bellinger 									\
371e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
372e48354ceSNicholas Bellinger 		return -EPERM;						\
373e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", auth->name);		\
374e48354ceSNicholas Bellinger }									\
375e48354ceSNicholas Bellinger 									\
3762eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_store(			\
377e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
378e48354ceSNicholas Bellinger 	const char *page,						\
379e48354ceSNicholas Bellinger 	size_t count)							\
380e48354ceSNicholas Bellinger {									\
381e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
382e48354ceSNicholas Bellinger 									\
383e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
384e48354ceSNicholas Bellinger 		return -EPERM;						\
3852306bfb2SEric Seppanen 	if (count >= sizeof(auth->name))				\
3862306bfb2SEric Seppanen 		return -EINVAL;						\
3870fbfc46fSJörn Engel 	snprintf(auth->name, sizeof(auth->name), "%s", page);		\
388e48354ceSNicholas Bellinger 	if (!strncmp("NULL", auth->name, 4))				\
389e48354ceSNicholas Bellinger 		auth->naf_flags &= ~flags;				\
390e48354ceSNicholas Bellinger 	else								\
391e48354ceSNicholas Bellinger 		auth->naf_flags |= flags;				\
392e48354ceSNicholas Bellinger 									\
393e48354ceSNicholas Bellinger 	if ((auth->naf_flags & NAF_USERID_IN_SET) &&			\
394e48354ceSNicholas Bellinger 	    (auth->naf_flags & NAF_PASSWORD_IN_SET))			\
395e48354ceSNicholas Bellinger 		auth->authenticate_target = 1;				\
396e48354ceSNicholas Bellinger 	else								\
397e48354ceSNicholas Bellinger 		auth->authenticate_target = 0;				\
398e48354ceSNicholas Bellinger 									\
399e48354ceSNicholas Bellinger 	return count;							\
400e48354ceSNicholas Bellinger }
401e48354ceSNicholas Bellinger 
4022eafd729SChristoph Hellwig #define DEF_NACL_AUTH_STR(name, flags)					\
4032eafd729SChristoph Hellwig 	__DEF_NACL_AUTH_STR(nacl_auth, name, flags)			\
4042eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item,	\
4052eafd729SChristoph Hellwig 		char *page)						\
4062eafd729SChristoph Hellwig {									\
4072eafd729SChristoph Hellwig 	struct se_node_acl *nacl = auth_to_nacl(item);			\
408a11b8069SDmitry Bogdanov 	return __iscsi_nacl_auth_##name##_show(to_iscsi_nacl(nacl), page);	\
4092eafd729SChristoph Hellwig }									\
4102eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item,	\
4112eafd729SChristoph Hellwig 		const char *page, size_t count)				\
4122eafd729SChristoph Hellwig {									\
4132eafd729SChristoph Hellwig 	struct se_node_acl *nacl = auth_to_nacl(item);			\
414a11b8069SDmitry Bogdanov 	return __iscsi_nacl_auth_##name##_store(to_iscsi_nacl(nacl),	\
415a11b8069SDmitry Bogdanov 						page, count); \
4162eafd729SChristoph Hellwig }									\
4172eafd729SChristoph Hellwig 									\
4182eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_nacl_auth_, name)
4192eafd729SChristoph Hellwig 
4202eafd729SChristoph Hellwig /*
4212eafd729SChristoph Hellwig  * One-way authentication userid
4222eafd729SChristoph Hellwig  */
4232eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
4242eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
4252eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
4262eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
4272eafd729SChristoph Hellwig 
428e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_INT(prefix, name)				\
4292eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(				\
430e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
431e48354ceSNicholas Bellinger 	char *page)							\
432e48354ceSNicholas Bellinger {									\
433e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
434e48354ceSNicholas Bellinger 									\
435e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
436e48354ceSNicholas Bellinger 		return -EPERM;						\
437e48354ceSNicholas Bellinger 									\
438e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%d\n", auth->name);		\
439e48354ceSNicholas Bellinger }
440e48354ceSNicholas Bellinger 
441e48354ceSNicholas Bellinger #define DEF_NACL_AUTH_INT(name)						\
442e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_INT(nacl_auth, name)				\
4432eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item,	\
444e48354ceSNicholas Bellinger 		char *page)						\
445e48354ceSNicholas Bellinger {									\
4462eafd729SChristoph Hellwig 	struct se_node_acl *nacl = auth_to_nacl(item);			\
447a11b8069SDmitry Bogdanov 	return __iscsi_nacl_auth_##name##_show(to_iscsi_nacl(nacl), page);	\
4482eafd729SChristoph Hellwig }									\
4492eafd729SChristoph Hellwig 									\
4502eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
451e48354ceSNicholas Bellinger 
452e48354ceSNicholas Bellinger DEF_NACL_AUTH_INT(authenticate_target);
453e48354ceSNicholas Bellinger 
454e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
4552eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_userid,
4562eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_password,
4572eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_authenticate_target,
4582eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_userid_mutual,
4592eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_password_mutual,
460e48354ceSNicholas Bellinger 	NULL,
461e48354ceSNicholas Bellinger };
462e48354ceSNicholas Bellinger 
463e48354ceSNicholas Bellinger /* End items for lio_target_nacl_auth_cit */
464e48354ceSNicholas Bellinger 
465e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_param_cit */
466e48354ceSNicholas Bellinger 
4672eafd729SChristoph Hellwig #define ISCSI_NACL_PARAM(name)						\
4682eafd729SChristoph Hellwig static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item,	\
469e48354ceSNicholas Bellinger 		char *page)						\
470e48354ceSNicholas Bellinger {									\
4712eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = param_to_nacl(item);		\
4720873fe44SMax Gurtovoy 	struct iscsit_session *sess;					\
473e48354ceSNicholas Bellinger 	struct se_session *se_sess;					\
474e48354ceSNicholas Bellinger 	ssize_t rb;							\
475e48354ceSNicholas Bellinger 									\
476e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);				\
477e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;					\
478e48354ceSNicholas Bellinger 	if (!se_sess) {							\
479e48354ceSNicholas Bellinger 		rb = snprintf(page, PAGE_SIZE,				\
480e48354ceSNicholas Bellinger 			"No Active iSCSI Session\n");			\
481e48354ceSNicholas Bellinger 	} else {							\
482e48354ceSNicholas Bellinger 		sess = se_sess->fabric_sess_ptr;			\
483e48354ceSNicholas Bellinger 		rb = snprintf(page, PAGE_SIZE, "%u\n",			\
484e48354ceSNicholas Bellinger 			(u32)sess->sess_ops->name);			\
485e48354ceSNicholas Bellinger 	}								\
486e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);			\
487e48354ceSNicholas Bellinger 									\
488e48354ceSNicholas Bellinger 	return rb;							\
4892eafd729SChristoph Hellwig }									\
4902eafd729SChristoph Hellwig 									\
4912eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
492e48354ceSNicholas Bellinger 
4932eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxConnections);
4942eafd729SChristoph Hellwig ISCSI_NACL_PARAM(InitialR2T);
4952eafd729SChristoph Hellwig ISCSI_NACL_PARAM(ImmediateData);
4962eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxBurstLength);
4972eafd729SChristoph Hellwig ISCSI_NACL_PARAM(FirstBurstLength);
4982eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DefaultTime2Wait);
4992eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DefaultTime2Retain);
5002eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxOutstandingR2T);
5012eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DataPDUInOrder);
5022eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DataSequenceInOrder);
5032eafd729SChristoph Hellwig ISCSI_NACL_PARAM(ErrorRecoveryLevel);
504e48354ceSNicholas Bellinger 
505e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
5062eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_MaxConnections,
5072eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_InitialR2T,
5082eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_ImmediateData,
5092eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_MaxBurstLength,
5102eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_FirstBurstLength,
5112eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_DefaultTime2Wait,
5122eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_DefaultTime2Retain,
5132eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_MaxOutstandingR2T,
5142eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_DataPDUInOrder,
5152eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_DataSequenceInOrder,
5162eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_ErrorRecoveryLevel,
517e48354ceSNicholas Bellinger 	NULL,
518e48354ceSNicholas Bellinger };
519e48354ceSNicholas Bellinger 
520e48354ceSNicholas Bellinger /* End items for lio_target_nacl_param_cit */
521e48354ceSNicholas Bellinger 
522e48354ceSNicholas Bellinger /* Start items for lio_target_acl_cit */
523e48354ceSNicholas Bellinger 
lio_target_nacl_info_show(struct config_item * item,char * page)5242eafd729SChristoph Hellwig static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
525e48354ceSNicholas Bellinger {
5262eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = acl_to_nacl(item);
5270873fe44SMax Gurtovoy 	struct iscsit_session *sess;
528be36d683SMax Gurtovoy 	struct iscsit_conn *conn;
529e48354ceSNicholas Bellinger 	struct se_session *se_sess;
530e48354ceSNicholas Bellinger 	ssize_t rb = 0;
531109e2381SRoland Dreier 	u32 max_cmd_sn;
532e48354ceSNicholas Bellinger 
533e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
534e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
535e48354ceSNicholas Bellinger 	if (!se_sess) {
536801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, "No active iSCSI Session for Initiator"
537e48354ceSNicholas Bellinger 			" Endpoint: %s\n", se_nacl->initiatorname);
538e48354ceSNicholas Bellinger 	} else {
539e48354ceSNicholas Bellinger 		sess = se_sess->fabric_sess_ptr;
540e48354ceSNicholas Bellinger 
541801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, "InitiatorName: %s\n",
542e48354ceSNicholas Bellinger 			sess->sess_ops->InitiatorName);
543801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, "InitiatorAlias: %s\n",
544e48354ceSNicholas Bellinger 			sess->sess_ops->InitiatorAlias);
545e48354ceSNicholas Bellinger 
546801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb,
5475cdf5a87SAndy Shevchenko 			      "LIO Session ID: %u   ISID: 0x%6ph  TSIH: %hu  ",
5485cdf5a87SAndy Shevchenko 			      sess->sid, sess->isid, sess->tsih);
549801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, "SessionType: %s\n",
550e48354ceSNicholas Bellinger 				(sess->sess_ops->SessionType) ?
551e48354ceSNicholas Bellinger 				"Discovery" : "Normal");
552801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, "Session State: ");
553e48354ceSNicholas Bellinger 		switch (sess->session_state) {
554e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_FREE:
555801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "TARG_SESS_FREE\n");
556e48354ceSNicholas Bellinger 			break;
557e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_ACTIVE:
558801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_ACTIVE\n");
559e48354ceSNicholas Bellinger 			break;
560e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_LOGGED_IN:
561801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_LOGGED_IN\n");
562e48354ceSNicholas Bellinger 			break;
563e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_FAILED:
564801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_FAILED\n");
565e48354ceSNicholas Bellinger 			break;
566e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_IN_CONTINUE:
567801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_IN_CONTINUE\n");
568e48354ceSNicholas Bellinger 			break;
569e48354ceSNicholas Bellinger 		default:
570801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "ERROR: Unknown Session"
571e48354ceSNicholas Bellinger 					" State!\n");
572e48354ceSNicholas Bellinger 			break;
573e48354ceSNicholas Bellinger 		}
574e48354ceSNicholas Bellinger 
575801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, "---------------------[iSCSI Session"
576e48354ceSNicholas Bellinger 				" Values]-----------------------\n");
577801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, "  CmdSN/WR  :  CmdSN/WC  :  ExpCmdSN"
578e48354ceSNicholas Bellinger 				"  :  MaxCmdSN  :     ITT    :     TTT\n");
579109e2381SRoland Dreier 		max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
580801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, " 0x%08x   0x%08x   0x%08x   0x%08x"
581e48354ceSNicholas Bellinger 				"   0x%08x   0x%08x\n",
582e48354ceSNicholas Bellinger 			sess->cmdsn_window,
583109e2381SRoland Dreier 			(max_cmd_sn - sess->exp_cmd_sn) + 1,
584109e2381SRoland Dreier 			sess->exp_cmd_sn, max_cmd_sn,
585e48354ceSNicholas Bellinger 			sess->init_task_tag, sess->targ_xfer_tag);
586801f287cSKonstantin Shelekhin 		rb += sysfs_emit_at(page, rb, "----------------------[iSCSI"
587e48354ceSNicholas Bellinger 				" Connections]-------------------------\n");
588e48354ceSNicholas Bellinger 
589e48354ceSNicholas Bellinger 		spin_lock(&sess->conn_lock);
590e48354ceSNicholas Bellinger 		list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
591801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "CID: %hu  Connection"
592e48354ceSNicholas Bellinger 					" State: ", conn->cid);
593e48354ceSNicholas Bellinger 			switch (conn->conn_state) {
594e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_FREE:
595801f287cSKonstantin Shelekhin 				rb += sysfs_emit_at(page, rb,
596e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_FREE\n");
597e48354ceSNicholas Bellinger 				break;
598e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_XPT_UP:
599801f287cSKonstantin Shelekhin 				rb += sysfs_emit_at(page, rb,
600e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_XPT_UP\n");
601e48354ceSNicholas Bellinger 				break;
602e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_IN_LOGIN:
603801f287cSKonstantin Shelekhin 				rb += sysfs_emit_at(page, rb,
604e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_IN_LOGIN\n");
605e48354ceSNicholas Bellinger 				break;
606e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_LOGGED_IN:
607801f287cSKonstantin Shelekhin 				rb += sysfs_emit_at(page, rb,
608e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_LOGGED_IN\n");
609e48354ceSNicholas Bellinger 				break;
610e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_IN_LOGOUT:
611801f287cSKonstantin Shelekhin 				rb += sysfs_emit_at(page, rb,
612e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_IN_LOGOUT\n");
613e48354ceSNicholas Bellinger 				break;
614e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_LOGOUT_REQUESTED:
615801f287cSKonstantin Shelekhin 				rb += sysfs_emit_at(page, rb,
616e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_LOGOUT_REQUESTED\n");
617e48354ceSNicholas Bellinger 				break;
618e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_CLEANUP_WAIT:
619801f287cSKonstantin Shelekhin 				rb += sysfs_emit_at(page, rb,
620e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_CLEANUP_WAIT\n");
621e48354ceSNicholas Bellinger 				break;
622e48354ceSNicholas Bellinger 			default:
623801f287cSKonstantin Shelekhin 				rb += sysfs_emit_at(page, rb,
624e48354ceSNicholas Bellinger 					"ERROR: Unknown Connection State!\n");
625e48354ceSNicholas Bellinger 				break;
626e48354ceSNicholas Bellinger 			}
627e48354ceSNicholas Bellinger 
628801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "   Address %pISc %s", &conn->login_sockaddr,
629e48354ceSNicholas Bellinger 				(conn->network_transport == ISCSI_TCP) ?
630e48354ceSNicholas Bellinger 				"TCP" : "SCTP");
631801f287cSKonstantin Shelekhin 			rb += sysfs_emit_at(page, rb, "  StatSN: 0x%08x\n",
632e48354ceSNicholas Bellinger 				conn->stat_sn);
633e48354ceSNicholas Bellinger 		}
634e48354ceSNicholas Bellinger 		spin_unlock(&sess->conn_lock);
635e48354ceSNicholas Bellinger 	}
636e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
637e48354ceSNicholas Bellinger 
638e48354ceSNicholas Bellinger 	return rb;
639e48354ceSNicholas Bellinger }
640e48354ceSNicholas Bellinger 
lio_target_nacl_cmdsn_depth_show(struct config_item * item,char * page)6412eafd729SChristoph Hellwig static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
642e48354ceSNicholas Bellinger 		char *page)
643e48354ceSNicholas Bellinger {
644*c0431febSKonstantin Shelekhin 	return sysfs_emit(page, "%u\n", acl_to_nacl(item)->queue_depth);
645e48354ceSNicholas Bellinger }
646e48354ceSNicholas Bellinger 
lio_target_nacl_cmdsn_depth_store(struct config_item * item,const char * page,size_t count)6472eafd729SChristoph Hellwig static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
6482eafd729SChristoph Hellwig 		const char *page, size_t count)
649e48354ceSNicholas Bellinger {
6502eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = acl_to_nacl(item);
651e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg = se_nacl->se_tpg;
652a11b8069SDmitry Bogdanov 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);
653e48354ceSNicholas Bellinger 	struct config_item *acl_ci, *tpg_ci, *wwn_ci;
654e48354ceSNicholas Bellinger 	u32 cmdsn_depth = 0;
655e48354ceSNicholas Bellinger 	int ret;
656e48354ceSNicholas Bellinger 
657ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &cmdsn_depth);
658ad7babd2SJörn Engel 	if (ret)
659ad7babd2SJörn Engel 		return ret;
660e48354ceSNicholas Bellinger 	if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
661e48354ceSNicholas Bellinger 		pr_err("Passed cmdsn_depth: %u exceeds"
662e48354ceSNicholas Bellinger 			" TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
663e48354ceSNicholas Bellinger 			TA_DEFAULT_CMDSN_DEPTH_MAX);
664e48354ceSNicholas Bellinger 		return -EINVAL;
665e48354ceSNicholas Bellinger 	}
666e48354ceSNicholas Bellinger 	acl_ci = &se_nacl->acl_group.cg_item;
667e48354ceSNicholas Bellinger 	if (!acl_ci) {
668e48354ceSNicholas Bellinger 		pr_err("Unable to locatel acl_ci\n");
669e48354ceSNicholas Bellinger 		return -EINVAL;
670e48354ceSNicholas Bellinger 	}
671e48354ceSNicholas Bellinger 	tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
672e48354ceSNicholas Bellinger 	if (!tpg_ci) {
673e48354ceSNicholas Bellinger 		pr_err("Unable to locate tpg_ci\n");
674e48354ceSNicholas Bellinger 		return -EINVAL;
675e48354ceSNicholas Bellinger 	}
676e48354ceSNicholas Bellinger 	wwn_ci = &tpg_ci->ci_group->cg_item;
677e48354ceSNicholas Bellinger 	if (!wwn_ci) {
678e48354ceSNicholas Bellinger 		pr_err("Unable to locate config_item wwn_ci\n");
679e48354ceSNicholas Bellinger 		return -EINVAL;
680e48354ceSNicholas Bellinger 	}
681e48354ceSNicholas Bellinger 
682e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)
683e48354ceSNicholas Bellinger 		return -EINVAL;
684d36ad77fSNicholas Bellinger 
685d36ad77fSNicholas Bellinger 	ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
686e48354ceSNicholas Bellinger 
687e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
688e48354ceSNicholas Bellinger 		"InitiatorName: %s\n", config_item_name(wwn_ci),
689e48354ceSNicholas Bellinger 		config_item_name(tpg_ci), cmdsn_depth,
690e48354ceSNicholas Bellinger 		config_item_name(acl_ci));
691e48354ceSNicholas Bellinger 
692e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
693e48354ceSNicholas Bellinger 	return (!ret) ? count : (ssize_t)ret;
694e48354ceSNicholas Bellinger }
695e48354ceSNicholas Bellinger 
lio_target_nacl_tag_show(struct config_item * item,char * page)6962eafd729SChristoph Hellwig static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
69779e62fc3SAndy Grover {
6982eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
69979e62fc3SAndy Grover }
70079e62fc3SAndy Grover 
lio_target_nacl_tag_store(struct config_item * item,const char * page,size_t count)7012eafd729SChristoph Hellwig static ssize_t lio_target_nacl_tag_store(struct config_item *item,
7022eafd729SChristoph Hellwig 		const char *page, size_t count)
70379e62fc3SAndy Grover {
7042eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = acl_to_nacl(item);
70579e62fc3SAndy Grover 	int ret;
70679e62fc3SAndy Grover 
70779e62fc3SAndy Grover 	ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
70879e62fc3SAndy Grover 
70979e62fc3SAndy Grover 	if (ret < 0)
71079e62fc3SAndy Grover 		return ret;
71179e62fc3SAndy Grover 	return count;
71279e62fc3SAndy Grover }
71379e62fc3SAndy Grover 
7142eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_nacl_, info);
7152eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
7162eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_nacl_, tag);
71779e62fc3SAndy Grover 
718e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_initiator_attrs[] = {
7192eafd729SChristoph Hellwig 	&lio_target_nacl_attr_info,
7202eafd729SChristoph Hellwig 	&lio_target_nacl_attr_cmdsn_depth,
7212eafd729SChristoph Hellwig 	&lio_target_nacl_attr_tag,
722e48354ceSNicholas Bellinger 	NULL,
723e48354ceSNicholas Bellinger };
724e48354ceSNicholas Bellinger 
lio_target_init_nodeacl(struct se_node_acl * se_nacl,const char * name)725c7d6a803SChristoph Hellwig static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
726e48354ceSNicholas Bellinger 		const char *name)
727e48354ceSNicholas Bellinger {
728a11b8069SDmitry Bogdanov 	struct iscsi_node_acl *acl = to_iscsi_nacl(se_nacl);
729e48354ceSNicholas Bellinger 
730b7eec2cdSAndy Grover 	config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
731e48354ceSNicholas Bellinger 			"iscsi_sess_stats", &iscsi_stat_sess_cit);
7321ae1602dSChristoph Hellwig 	configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
7331ae1602dSChristoph Hellwig 			&se_nacl->acl_fabric_stat_group);
734c7d6a803SChristoph Hellwig 	return 0;
735e48354ceSNicholas Bellinger }
736e48354ceSNicholas Bellinger 
737e48354ceSNicholas Bellinger /* End items for lio_target_acl_cit */
738e48354ceSNicholas Bellinger 
739e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_attrib_cit */
740e48354ceSNicholas Bellinger 
741e48354ceSNicholas Bellinger #define DEF_TPG_ATTRIB(name)						\
742e48354ceSNicholas Bellinger 									\
7432eafd729SChristoph Hellwig static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item,	\
744e48354ceSNicholas Bellinger 		char *page)						\
745e48354ceSNicholas Bellinger {									\
7462eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = attrib_to_tpg(item);		\
747a11b8069SDmitry Bogdanov 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);		\
748e48354ceSNicholas Bellinger 	ssize_t rb;							\
749e48354ceSNicholas Bellinger 									\
750e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
751e48354ceSNicholas Bellinger 		return -EINVAL;						\
752e48354ceSNicholas Bellinger 									\
753*c0431febSKonstantin Shelekhin 	rb = sysfs_emit(page, "%u\n", tpg->tpg_attrib.name);		\
754e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
755e48354ceSNicholas Bellinger 	return rb;							\
756e48354ceSNicholas Bellinger }									\
757e48354ceSNicholas Bellinger 									\
7582eafd729SChristoph Hellwig static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
7592eafd729SChristoph Hellwig 		const char *page, size_t count)				\
760e48354ceSNicholas Bellinger {									\
7612eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = attrib_to_tpg(item);		\
762a11b8069SDmitry Bogdanov 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);		\
763e48354ceSNicholas Bellinger 	u32 val;							\
764e48354ceSNicholas Bellinger 	int ret;							\
765e48354ceSNicholas Bellinger 									\
766e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
767e48354ceSNicholas Bellinger 		return -EINVAL;						\
768e48354ceSNicholas Bellinger 									\
769ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &val);					\
770ad7babd2SJörn Engel 	if (ret)							\
771ad7babd2SJörn Engel 		goto out;						\
772e48354ceSNicholas Bellinger 	ret = iscsit_ta_##name(tpg, val);				\
773e48354ceSNicholas Bellinger 	if (ret < 0)							\
774e48354ceSNicholas Bellinger 		goto out;						\
775e48354ceSNicholas Bellinger 									\
776e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
777e48354ceSNicholas Bellinger 	return count;							\
778e48354ceSNicholas Bellinger out:									\
779e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
780e48354ceSNicholas Bellinger 	return ret;							\
7812eafd729SChristoph Hellwig }									\
7822eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
783e48354ceSNicholas Bellinger 
784e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(authentication);
785e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(login_timeout);
786e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(generate_node_acls);
787e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(default_cmdsn_depth);
788e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(cache_dynamic_acls);
789e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(demo_mode_write_protect);
790e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(prod_mode_write_protect);
791e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(demo_mode_discovery);
7924c54b6cfSThomas Glanzmann DEF_TPG_ATTRIB(default_erl);
793d1fa7a1dSNicholas Bellinger DEF_TPG_ATTRIB(t10_pi);
7948085176fSSagi Grimberg DEF_TPG_ATTRIB(fabric_prot_type);
795901c04a3SNicholas Bellinger DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
796a6415cddSDavid Disseldorp DEF_TPG_ATTRIB(login_keys_workaround);
797138d351eSNicholas Bellinger 
798e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
799e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_attr_authentication,
8002eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_login_timeout,
8012eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_generate_node_acls,
8022eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_default_cmdsn_depth,
8032eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_cache_dynamic_acls,
8042eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_demo_mode_write_protect,
8052eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_prod_mode_write_protect,
8062eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_demo_mode_discovery,
8072eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_default_erl,
8082eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_t10_pi,
8092eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_fabric_prot_type,
8102eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
8112eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_login_keys_workaround,
8122eafd729SChristoph Hellwig 	NULL,
813138d351eSNicholas Bellinger };
814e48354ceSNicholas Bellinger 
815e48354ceSNicholas Bellinger /* End items for lio_target_tpg_attrib_cit */
816e48354ceSNicholas Bellinger 
817e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_auth_cit */
818e48354ceSNicholas Bellinger 
819c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_STR(prefix, name, flags)					\
820c3e51442SNicholas Bellinger static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg,	\
821c3e51442SNicholas Bellinger 		char *page)							\
8222eafd729SChristoph Hellwig {										\
823c3e51442SNicholas Bellinger 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);			\
824c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
825a11b8069SDmitry Bogdanov 										\
826c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
827c3e51442SNicholas Bellinger 		return -EPERM;							\
828c3e51442SNicholas Bellinger 										\
829c3e51442SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", auth->name);			\
830c3e51442SNicholas Bellinger }										\
831c3e51442SNicholas Bellinger 										\
832c3e51442SNicholas Bellinger static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
833c3e51442SNicholas Bellinger 		const char *page, size_t count)					\
8342eafd729SChristoph Hellwig {										\
8352eafd729SChristoph Hellwig 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);			\
836c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
837a11b8069SDmitry Bogdanov 										\
838c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
839c3e51442SNicholas Bellinger 		return -EPERM;							\
840c3e51442SNicholas Bellinger 										\
841c3e51442SNicholas Bellinger 	snprintf(auth->name, sizeof(auth->name), "%s", page);			\
842c3e51442SNicholas Bellinger 	if (!(strncmp("NULL", auth->name, 4)))					\
84337b32c6fSNicholas Bellinger 		auth->naf_flags &= ~flags;					\
844c3e51442SNicholas Bellinger 	else									\
845c3e51442SNicholas Bellinger 		auth->naf_flags |= flags;					\
846c3e51442SNicholas Bellinger 										\
847c3e51442SNicholas Bellinger 	if ((auth->naf_flags & NAF_USERID_IN_SET) &&				\
848c3e51442SNicholas Bellinger 	    (auth->naf_flags & NAF_PASSWORD_IN_SET))				\
849c3e51442SNicholas Bellinger 		auth->authenticate_target = 1;					\
850c3e51442SNicholas Bellinger 	else									\
851c3e51442SNicholas Bellinger 		auth->authenticate_target = 0;					\
852c3e51442SNicholas Bellinger 										\
853c3e51442SNicholas Bellinger 	return count;								\
854c3e51442SNicholas Bellinger }
855c3e51442SNicholas Bellinger 
856c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_STR(name, flags)						\
857c3e51442SNicholas Bellinger 	__DEF_TPG_AUTH_STR(tpg_auth, name, flags)				\
8582eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item,		\
8592eafd729SChristoph Hellwig 		char *page)							\
8602eafd729SChristoph Hellwig {										\
8612eafd729SChristoph Hellwig 	return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page);		\
8622eafd729SChristoph Hellwig }										\
8632eafd729SChristoph Hellwig 										\
8642eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item,		\
8652eafd729SChristoph Hellwig 		const char *page, size_t count)					\
8662eafd729SChristoph Hellwig {										\
8672eafd729SChristoph Hellwig 	return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count);	\
8682eafd729SChristoph Hellwig }										\
8692eafd729SChristoph Hellwig 										\
8702eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_auth_, name);
8712eafd729SChristoph Hellwig 
8722eafd729SChristoph Hellwig 
8732eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
8742eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
8752eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
8762eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
8772eafd729SChristoph Hellwig 
8782eafd729SChristoph Hellwig #define __DEF_TPG_AUTH_INT(prefix, name)					\
8792eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg,	\
880c3e51442SNicholas Bellinger 		char *page)								\
8812eafd729SChristoph Hellwig {										\
882c3e51442SNicholas Bellinger 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);			\
883c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
884a11b8069SDmitry Bogdanov 										\
885c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
886c3e51442SNicholas Bellinger 		return -EPERM;							\
887c3e51442SNicholas Bellinger 										\
888c3e51442SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%d\n", auth->name);			\
889c3e51442SNicholas Bellinger }
890c3e51442SNicholas Bellinger 
891c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_INT(name)							\
892c3e51442SNicholas Bellinger 	__DEF_TPG_AUTH_INT(tpg_auth, name)					\
893c3e51442SNicholas Bellinger static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item,		\
894c3e51442SNicholas Bellinger 		char *page) \
8952eafd729SChristoph Hellwig {										\
896c3e51442SNicholas Bellinger 	return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page);		\
897c3e51442SNicholas Bellinger }										\
8982eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
8992eafd729SChristoph Hellwig 
9002eafd729SChristoph Hellwig DEF_TPG_AUTH_INT(authenticate_target);
901c3e51442SNicholas Bellinger 
902c3e51442SNicholas Bellinger static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
903c3e51442SNicholas Bellinger 	&iscsi_tpg_auth_attr_userid,
904c3e51442SNicholas Bellinger 	&iscsi_tpg_auth_attr_password,
9052eafd729SChristoph Hellwig 	&iscsi_tpg_auth_attr_authenticate_target,
9062eafd729SChristoph Hellwig 	&iscsi_tpg_auth_attr_userid_mutual,
9072eafd729SChristoph Hellwig 	&iscsi_tpg_auth_attr_password_mutual,
9082eafd729SChristoph Hellwig 	NULL,
9092eafd729SChristoph Hellwig };
910c3e51442SNicholas Bellinger 
911c3e51442SNicholas Bellinger /* End items for lio_target_tpg_auth_cit */
912c3e51442SNicholas Bellinger 
913c3e51442SNicholas Bellinger /* Start items for lio_target_tpg_param_cit */
914c3e51442SNicholas Bellinger 
915e48354ceSNicholas Bellinger #define DEF_TPG_PARAM(name)						\
916e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item,	\
917e48354ceSNicholas Bellinger 		char *page)						\
9182eafd729SChristoph Hellwig {									\
919e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg = param_to_tpg(item);		\
920e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);		\
9212eafd729SChristoph Hellwig 	struct iscsi_param *param;					\
922a11b8069SDmitry Bogdanov 	ssize_t rb;							\
923e48354ceSNicholas Bellinger 									\
924e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
925e48354ceSNicholas Bellinger 		return -EINVAL;						\
926e48354ceSNicholas Bellinger 									\
927e48354ceSNicholas Bellinger 	param = iscsi_find_param_from_key(__stringify(name),		\
928e48354ceSNicholas Bellinger 				tpg->param_list);			\
929e48354ceSNicholas Bellinger 	if (!param) {							\
930e48354ceSNicholas Bellinger 		iscsit_put_tpg(tpg);					\
931e48354ceSNicholas Bellinger 		return -EINVAL;						\
932e48354ceSNicholas Bellinger 	}								\
933e48354ceSNicholas Bellinger 	rb = snprintf(page, PAGE_SIZE, "%s\n", param->value);		\
934e48354ceSNicholas Bellinger 									\
935e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
936e48354ceSNicholas Bellinger 	return rb;							\
937e48354ceSNicholas Bellinger }									\
938e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
939e48354ceSNicholas Bellinger 		const char *page, size_t count)				\
9402eafd729SChristoph Hellwig {									\
9412eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = param_to_tpg(item);		\
942e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);		\
9432eafd729SChristoph Hellwig 	char *buf;							\
944a11b8069SDmitry Bogdanov 	int ret, len;							\
945e48354ceSNicholas Bellinger 									\
946ad7babd2SJörn Engel 	buf = kzalloc(PAGE_SIZE, GFP_KERNEL);				\
947e48354ceSNicholas Bellinger 	if (!buf)							\
948e48354ceSNicholas Bellinger 		return -ENOMEM;						\
949e48354ceSNicholas Bellinger 	len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page);	\
950e48354ceSNicholas Bellinger 	if (isspace(buf[len-1]))					\
951ad7babd2SJörn Engel 		buf[len-1] = '\0'; /* Kill newline */			\
952ad7babd2SJörn Engel 									\
953ad7babd2SJörn Engel 	if (iscsit_get_tpg(tpg) < 0) {					\
954e48354ceSNicholas Bellinger 		kfree(buf);						\
955e48354ceSNicholas Bellinger 		return -EINVAL;						\
956e48354ceSNicholas Bellinger 	}								\
957e48354ceSNicholas Bellinger 									\
958e48354ceSNicholas Bellinger 	ret = iscsi_change_param_value(buf, tpg->param_list, 1);	\
959e48354ceSNicholas Bellinger 	if (ret < 0)							\
960e48354ceSNicholas Bellinger 		goto out;						\
961e48354ceSNicholas Bellinger 									\
962e48354ceSNicholas Bellinger 	kfree(buf);							\
963e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
964e48354ceSNicholas Bellinger 	return count;							\
965e48354ceSNicholas Bellinger out:									\
966e48354ceSNicholas Bellinger 	kfree(buf);							\
967e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
968e48354ceSNicholas Bellinger 	return -EINVAL;							\
969e48354ceSNicholas Bellinger }									\
970e48354ceSNicholas Bellinger CONFIGFS_ATTR(iscsi_tpg_param_, name)
9712eafd729SChristoph Hellwig 
9722eafd729SChristoph Hellwig DEF_TPG_PARAM(AuthMethod);
973e48354ceSNicholas Bellinger DEF_TPG_PARAM(HeaderDigest);
974e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataDigest);
975e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxConnections);
976e48354ceSNicholas Bellinger DEF_TPG_PARAM(TargetAlias);
977e48354ceSNicholas Bellinger DEF_TPG_PARAM(InitialR2T);
978e48354ceSNicholas Bellinger DEF_TPG_PARAM(ImmediateData);
979e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxRecvDataSegmentLength);
980e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxXmitDataSegmentLength);
981e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxBurstLength);
982e004cb25SNicholas Bellinger DEF_TPG_PARAM(FirstBurstLength);
983e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Wait);
984e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Retain);
985e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxOutstandingR2T);
986e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataPDUInOrder);
987e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataSequenceInOrder);
988e48354ceSNicholas Bellinger DEF_TPG_PARAM(ErrorRecoveryLevel);
989e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarker);
990e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarker);
991e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarkInt);
992e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarkInt);
993e48354ceSNicholas Bellinger 
994e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
995e48354ceSNicholas Bellinger 	&iscsi_tpg_param_attr_AuthMethod,
996e48354ceSNicholas Bellinger 	&iscsi_tpg_param_attr_HeaderDigest,
9972eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DataDigest,
9982eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxConnections,
9992eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_TargetAlias,
10002eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_InitialR2T,
10012eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_ImmediateData,
10022eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
10032eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
10042eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxBurstLength,
10052eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_FirstBurstLength,
10062eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DefaultTime2Wait,
10072eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DefaultTime2Retain,
10082eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxOutstandingR2T,
10092eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DataPDUInOrder,
10102eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DataSequenceInOrder,
10112eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_ErrorRecoveryLevel,
10122eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_IFMarker,
10132eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_OFMarker,
10142eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_IFMarkInt,
10152eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_OFMarkInt,
10162eafd729SChristoph Hellwig 	NULL,
10172eafd729SChristoph Hellwig };
1018e48354ceSNicholas Bellinger 
1019e48354ceSNicholas Bellinger /* End items for lio_target_tpg_param_cit */
1020e48354ceSNicholas Bellinger 
1021e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_cit */
1022e48354ceSNicholas Bellinger 
lio_target_tpg_dynamic_sessions_show(struct config_item * item,char * page)1023e48354ceSNicholas Bellinger static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1024e48354ceSNicholas Bellinger 		char *page)
10252eafd729SChristoph Hellwig {
1026d4ee46ffSNicholas Bellinger 	return target_show_dynamic_sessions(to_tpg(item), page);
1027d4ee46ffSNicholas Bellinger }
10282eafd729SChristoph Hellwig 
1029d4ee46ffSNicholas Bellinger CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1030d4ee46ffSNicholas Bellinger 
10312eafd729SChristoph Hellwig static struct configfs_attribute *lio_target_tpg_attrs[] = {
1032d4ee46ffSNicholas Bellinger 	&lio_target_tpg_attr_dynamic_sessions,
1033e48354ceSNicholas Bellinger 	NULL,
10342eafd729SChristoph Hellwig };
1035e48354ceSNicholas Bellinger 
1036e48354ceSNicholas Bellinger /* End items for lio_target_tpg_cit */
1037e48354ceSNicholas Bellinger 
1038e48354ceSNicholas Bellinger /* Start items for lio_target_tiqn_cit */
1039e48354ceSNicholas Bellinger 
lio_target_tiqn_addtpg(struct se_wwn * wwn,const char * name)1040e48354ceSNicholas Bellinger static struct se_portal_group *lio_target_tiqn_addtpg(struct se_wwn *wwn,
1041e48354ceSNicholas Bellinger 						      const char *name)
1042aa090eabSBart Van Assche {
1043e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
1044e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1045e48354ceSNicholas Bellinger 	char *tpgt_str;
1046e48354ceSNicholas Bellinger 	int ret;
1047ad7babd2SJörn Engel 	u16 tpgt;
1048ad7babd2SJörn Engel 
1049ad7babd2SJörn Engel 	tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1050e48354ceSNicholas Bellinger 	/*
1051e48354ceSNicholas Bellinger 	 * Only tpgt_# directory groups can be created below
1052e48354ceSNicholas Bellinger 	 * target/iscsi/iqn.superturodiskarry/
1053e48354ceSNicholas Bellinger 	 */
1054e48354ceSNicholas Bellinger 	tpgt_str = strstr(name, "tpgt_");
1055e48354ceSNicholas Bellinger 	if (!tpgt_str) {
1056e48354ceSNicholas Bellinger 		pr_err("Unable to locate \"tpgt_#\" directory"
1057e48354ceSNicholas Bellinger 				" group\n");
1058e48354ceSNicholas Bellinger 		return NULL;
1059e48354ceSNicholas Bellinger 	}
1060e48354ceSNicholas Bellinger 	tpgt_str += 5; /* Skip ahead of "tpgt_" */
1061e48354ceSNicholas Bellinger 	ret = kstrtou16(tpgt_str, 0, &tpgt);
1062e48354ceSNicholas Bellinger 	if (ret)
1063ad7babd2SJörn Engel 		return NULL;
1064ad7babd2SJörn Engel 
1065ad7babd2SJörn Engel 	tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1066e48354ceSNicholas Bellinger 	if (!tpg)
1067e48354ceSNicholas Bellinger 		return NULL;
1068e48354ceSNicholas Bellinger 
1069e48354ceSNicholas Bellinger 	ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1070e48354ceSNicholas Bellinger 	if (ret < 0)
1071bc0c94b1SNicholas Bellinger 		goto free_out;
1072e48354ceSNicholas Bellinger 
107312d5a43bStangwenji 	ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1074e48354ceSNicholas Bellinger 	if (ret != 0)
1075e48354ceSNicholas Bellinger 		goto out;
1076e48354ceSNicholas Bellinger 
1077e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1078e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1079e48354ceSNicholas Bellinger 			name);
1080e48354ceSNicholas Bellinger 	return &tpg->tpg_se_tpg;
1081e48354ceSNicholas Bellinger out:
1082e48354ceSNicholas Bellinger 	core_tpg_deregister(&tpg->tpg_se_tpg);
1083e48354ceSNicholas Bellinger free_out:
1084e48354ceSNicholas Bellinger 	kfree(tpg);
108512d5a43bStangwenji 	return NULL;
1086e48354ceSNicholas Bellinger }
1087e48354ceSNicholas Bellinger 
lio_target_tiqn_enabletpg(struct se_portal_group * se_tpg,bool enable)1088e48354ceSNicholas Bellinger static int lio_target_tiqn_enabletpg(struct se_portal_group *se_tpg,
1089e48354ceSNicholas Bellinger 				     bool enable)
1090382731ecSDmitry Bogdanov {
1091382731ecSDmitry Bogdanov 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);
1092382731ecSDmitry Bogdanov 	int ret;
1093a11b8069SDmitry Bogdanov 
1094382731ecSDmitry Bogdanov 	ret = iscsit_get_tpg(tpg);
1095382731ecSDmitry Bogdanov 	if (ret < 0)
1096382731ecSDmitry Bogdanov 		return -EINVAL;
1097382731ecSDmitry Bogdanov 
1098382731ecSDmitry Bogdanov 	if (enable) {
1099382731ecSDmitry Bogdanov 		ret = iscsit_tpg_enable_portal_group(tpg);
1100382731ecSDmitry Bogdanov 		if (ret < 0)
1101382731ecSDmitry Bogdanov 			goto out;
1102382731ecSDmitry Bogdanov 	} else {
1103382731ecSDmitry Bogdanov 		/*
1104382731ecSDmitry Bogdanov 		 * iscsit_tpg_disable_portal_group() assumes force=1
1105382731ecSDmitry Bogdanov 		 */
1106382731ecSDmitry Bogdanov 		ret = iscsit_tpg_disable_portal_group(tpg, 1);
1107382731ecSDmitry Bogdanov 		if (ret < 0)
1108382731ecSDmitry Bogdanov 			goto out;
1109382731ecSDmitry Bogdanov 	}
1110382731ecSDmitry Bogdanov 
1111382731ecSDmitry Bogdanov 	iscsit_put_tpg(tpg);
1112382731ecSDmitry Bogdanov 	return 0;
1113382731ecSDmitry Bogdanov out:
1114382731ecSDmitry Bogdanov 	iscsit_put_tpg(tpg);
1115382731ecSDmitry Bogdanov 	return -EINVAL;
1116382731ecSDmitry Bogdanov }
1117382731ecSDmitry Bogdanov 
lio_target_tiqn_deltpg(struct se_portal_group * se_tpg)1118382731ecSDmitry Bogdanov static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1119382731ecSDmitry Bogdanov {
1120fceb5bc7SChristoph Hellwig 	struct iscsi_portal_group *tpg;
1121e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1122e48354ceSNicholas Bellinger 
1123e48354ceSNicholas Bellinger 	tpg = to_iscsi_tpg(se_tpg);
1124e48354ceSNicholas Bellinger 	tiqn = tpg->tpg_tiqn;
1125a11b8069SDmitry Bogdanov 	/*
1126e48354ceSNicholas Bellinger 	 * iscsit_tpg_del_portal_group() assumes force=1
1127e48354ceSNicholas Bellinger 	 */
1128e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1129e48354ceSNicholas Bellinger 	iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1130e48354ceSNicholas Bellinger }
1131e48354ceSNicholas Bellinger 
1132e48354ceSNicholas Bellinger /* End items for lio_target_tiqn_cit */
1133e48354ceSNicholas Bellinger 
1134e48354ceSNicholas Bellinger /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1135e48354ceSNicholas Bellinger 
lio_target_wwn_lio_version_show(struct config_item * item,char * page)1136e48354ceSNicholas Bellinger static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1137e48354ceSNicholas Bellinger 		char *page)
11382eafd729SChristoph Hellwig {
1139e48354ceSNicholas Bellinger 	return sysfs_emit(page, "Datera Inc. iSCSI Target %s\n", ISCSIT_VERSION);
1140e48354ceSNicholas Bellinger }
1141*c0431febSKonstantin Shelekhin 
1142e48354ceSNicholas Bellinger CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1143e48354ceSNicholas Bellinger 
lio_target_wwn_cpus_allowed_list_show(struct config_item * item,char * page)11442eafd729SChristoph Hellwig static ssize_t lio_target_wwn_cpus_allowed_list_show(
1145e48354ceSNicholas Bellinger 		struct config_item *item, char *page)
1146d72d827fSMingzhe Zou {
1147d72d827fSMingzhe Zou 	return sysfs_emit(page, "%*pbl\n",
1148d72d827fSMingzhe Zou 		       cpumask_pr_args(iscsit_global->allowed_cpumask));
1149*c0431febSKonstantin Shelekhin }
1150d72d827fSMingzhe Zou 
lio_target_wwn_cpus_allowed_list_store(struct config_item * item,const char * page,size_t count)1151d72d827fSMingzhe Zou static ssize_t lio_target_wwn_cpus_allowed_list_store(
1152d72d827fSMingzhe Zou 		struct config_item *item, const char *page, size_t count)
1153d72d827fSMingzhe Zou {
1154d72d827fSMingzhe Zou 	int ret = -ENOMEM;
1155d72d827fSMingzhe Zou 	char *orig;
1156525f447fSMingzhe Zou 	cpumask_var_t new_allowed_cpumask;
1157d72d827fSMingzhe Zou 
1158525f447fSMingzhe Zou 	if (!zalloc_cpumask_var(&new_allowed_cpumask, GFP_KERNEL))
1159525f447fSMingzhe Zou 		goto out;
1160525f447fSMingzhe Zou 
1161525f447fSMingzhe Zou 	orig = kstrdup(page, GFP_KERNEL);
1162d72d827fSMingzhe Zou 	if (!orig)
1163d72d827fSMingzhe Zou 		goto out_free_cpumask;
1164d72d827fSMingzhe Zou 
1165525f447fSMingzhe Zou 	ret = cpulist_parse(orig, new_allowed_cpumask);
1166d72d827fSMingzhe Zou 	if (!ret)
1167525f447fSMingzhe Zou 		cpumask_copy(iscsit_global->allowed_cpumask,
1168525f447fSMingzhe Zou 			     new_allowed_cpumask);
1169525f447fSMingzhe Zou 
1170525f447fSMingzhe Zou 	kfree(orig);
1171d72d827fSMingzhe Zou out_free_cpumask:
1172d72d827fSMingzhe Zou 	free_cpumask_var(new_allowed_cpumask);
1173525f447fSMingzhe Zou out:
1174525f447fSMingzhe Zou 	return ret ? ret : count;
1175525f447fSMingzhe Zou }
1176525f447fSMingzhe Zou 
1177d72d827fSMingzhe Zou CONFIGFS_ATTR(lio_target_wwn_, cpus_allowed_list);
1178d72d827fSMingzhe Zou 
1179d72d827fSMingzhe Zou static struct configfs_attribute *lio_target_wwn_attrs[] = {
1180d72d827fSMingzhe Zou 	&lio_target_wwn_attr_lio_version,
1181e48354ceSNicholas Bellinger 	&lio_target_wwn_attr_cpus_allowed_list,
11822eafd729SChristoph Hellwig 	NULL,
1183d72d827fSMingzhe Zou };
1184e48354ceSNicholas Bellinger 
lio_target_call_coreaddtiqn(struct target_fabric_configfs * tf,struct config_group * group,const char * name)1185e48354ceSNicholas Bellinger static struct se_wwn *lio_target_call_coreaddtiqn(
1186e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,
1187fceb5bc7SChristoph Hellwig 	struct config_group *group,
1188e48354ceSNicholas Bellinger 	const char *name)
1189e48354ceSNicholas Bellinger {
1190e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1191e48354ceSNicholas Bellinger 
1192e48354ceSNicholas Bellinger 	tiqn = iscsit_add_tiqn((unsigned char *)name);
1193e48354ceSNicholas Bellinger 	if (IS_ERR(tiqn))
1194e48354ceSNicholas Bellinger 		return ERR_CAST(tiqn);
1195e48354ceSNicholas Bellinger 
1196e1750ba2SThomas Meyer 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1197e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1198839559e1SChristoph Hellwig 			" %s\n", name);
1199839559e1SChristoph Hellwig 	return &tiqn->tiqn_wwn;
1200839559e1SChristoph Hellwig }
1201839559e1SChristoph Hellwig 
lio_target_add_wwn_groups(struct se_wwn * wwn)1202839559e1SChristoph Hellwig static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1203839559e1SChristoph Hellwig {
1204839559e1SChristoph Hellwig 	struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1205839559e1SChristoph Hellwig 
1206839559e1SChristoph Hellwig 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1207839559e1SChristoph Hellwig 			"iscsi_instance", &iscsi_stat_instance_cit);
1208b7eec2cdSAndy Grover 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1209e48354ceSNicholas Bellinger 			&tiqn->tiqn_wwn.fabric_stat_group);
12101ae1602dSChristoph Hellwig 
12111ae1602dSChristoph Hellwig 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
12121ae1602dSChristoph Hellwig 			"iscsi_sess_err", &iscsi_stat_sess_err_cit);
1213b7eec2cdSAndy Grover 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1214e48354ceSNicholas Bellinger 			&tiqn->tiqn_wwn.fabric_stat_group);
12151ae1602dSChristoph Hellwig 
12161ae1602dSChristoph Hellwig 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
12171ae1602dSChristoph Hellwig 			"iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1218b7eec2cdSAndy Grover 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1219e48354ceSNicholas Bellinger 			&tiqn->tiqn_wwn.fabric_stat_group);
12201ae1602dSChristoph Hellwig 
12211ae1602dSChristoph Hellwig 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
12221ae1602dSChristoph Hellwig 			"iscsi_login_stats", &iscsi_stat_login_cit);
1223b7eec2cdSAndy Grover 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1224e48354ceSNicholas Bellinger 			&tiqn->tiqn_wwn.fabric_stat_group);
12251ae1602dSChristoph Hellwig 
12261ae1602dSChristoph Hellwig 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
12271ae1602dSChristoph Hellwig 			"iscsi_logout_stats", &iscsi_stat_logout_cit);
1228b7eec2cdSAndy Grover 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1229e48354ceSNicholas Bellinger 			&tiqn->tiqn_wwn.fabric_stat_group);
12301ae1602dSChristoph Hellwig }
12311ae1602dSChristoph Hellwig 
lio_target_call_coredeltiqn(struct se_wwn * wwn)1232e48354ceSNicholas Bellinger static void lio_target_call_coredeltiqn(
1233e48354ceSNicholas Bellinger 	struct se_wwn *wwn)
1234fceb5bc7SChristoph Hellwig {
1235e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1236e48354ceSNicholas Bellinger 
1237e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1238e48354ceSNicholas Bellinger 			tiqn->tiqn);
1239e48354ceSNicholas Bellinger 	iscsit_del_tiqn(tiqn);
1240e48354ceSNicholas Bellinger }
1241e48354ceSNicholas Bellinger 
1242e48354ceSNicholas Bellinger /* End LIO-Target TIQN struct contig_lio_target_cit */
1243e48354ceSNicholas Bellinger 
1244e48354ceSNicholas Bellinger /* Start lio_target_discovery_auth_cit */
1245e48354ceSNicholas Bellinger 
1246e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_STR(name, flags)					\
1247e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_STR(disc, name, flags)				\
1248e48354ceSNicholas Bellinger static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1249e48354ceSNicholas Bellinger {									\
12502eafd729SChristoph Hellwig 	return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1251e48354ceSNicholas Bellinger 		page);							\
12522eafd729SChristoph Hellwig }									\
1253e48354ceSNicholas Bellinger static ssize_t iscsi_disc_##name##_store(struct config_item *item,	\
1254e48354ceSNicholas Bellinger 		const char *page, size_t count)				\
12552eafd729SChristoph Hellwig {									\
12562eafd729SChristoph Hellwig 	return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl,	\
1257e48354ceSNicholas Bellinger 		page, count);						\
12582eafd729SChristoph Hellwig 									\
1259e48354ceSNicholas Bellinger }									\
12602eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_disc_, name)
12612eafd729SChristoph Hellwig 
12622eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
12632eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
12642eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
12652eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
12662eafd729SChristoph Hellwig 
12672eafd729SChristoph Hellwig #define DEF_DISC_AUTH_INT(name)						\
1268e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_INT(disc, name)					\
1269e48354ceSNicholas Bellinger static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1270e48354ceSNicholas Bellinger {									\
12712eafd729SChristoph Hellwig 	return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1272e48354ceSNicholas Bellinger 			page);						\
12732eafd729SChristoph Hellwig }									\
1274e48354ceSNicholas Bellinger CONFIGFS_ATTR_RO(iscsi_disc_, name)
12752eafd729SChristoph Hellwig 
12762eafd729SChristoph Hellwig DEF_DISC_AUTH_INT(authenticate_target);
1277e48354ceSNicholas Bellinger 
1278e48354ceSNicholas Bellinger 
iscsi_disc_enforce_discovery_auth_show(struct config_item * item,char * page)1279e48354ceSNicholas Bellinger static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
12802eafd729SChristoph Hellwig 		char *page)
12812eafd729SChristoph Hellwig {
1282e48354ceSNicholas Bellinger 	struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1283e48354ceSNicholas Bellinger 
1284e48354ceSNicholas Bellinger 	return sysfs_emit(page, "%d\n", discovery_auth->enforce_discovery_auth);
1285e48354ceSNicholas Bellinger }
1286*c0431febSKonstantin Shelekhin 
iscsi_disc_enforce_discovery_auth_store(struct config_item * item,const char * page,size_t count)1287e48354ceSNicholas Bellinger static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1288e48354ceSNicholas Bellinger 		const char *page, size_t count)
12892eafd729SChristoph Hellwig {
12902eafd729SChristoph Hellwig 	struct iscsi_param *param;
1291e48354ceSNicholas Bellinger 	struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1292e48354ceSNicholas Bellinger 	u32 op;
1293e48354ceSNicholas Bellinger 	int err;
1294e48354ceSNicholas Bellinger 
1295ad7babd2SJörn Engel 	err = kstrtou32(page, 0, &op);
1296e48354ceSNicholas Bellinger 	if (err)
1297ad7babd2SJörn Engel 		return -EINVAL;
1298ad7babd2SJörn Engel 	if ((op != 1) && (op != 0)) {
1299ad7babd2SJörn Engel 		pr_err("Illegal value for enforce_discovery_auth:"
1300e48354ceSNicholas Bellinger 				" %u\n", op);
1301e48354ceSNicholas Bellinger 		return -EINVAL;
1302e48354ceSNicholas Bellinger 	}
1303e48354ceSNicholas Bellinger 
1304e48354ceSNicholas Bellinger 	if (!discovery_tpg) {
1305e48354ceSNicholas Bellinger 		pr_err("iscsit_global->discovery_tpg is NULL\n");
1306e48354ceSNicholas Bellinger 		return -EINVAL;
1307e48354ceSNicholas Bellinger 	}
1308e48354ceSNicholas Bellinger 
1309e48354ceSNicholas Bellinger 	param = iscsi_find_param_from_key(AUTHMETHOD,
1310e48354ceSNicholas Bellinger 				discovery_tpg->param_list);
1311e48354ceSNicholas Bellinger 	if (!param)
1312e48354ceSNicholas Bellinger 		return -EINVAL;
1313e48354ceSNicholas Bellinger 
1314e48354ceSNicholas Bellinger 	if (op) {
1315e48354ceSNicholas Bellinger 		/*
1316e48354ceSNicholas Bellinger 		 * Reset the AuthMethod key to CHAP.
1317e48354ceSNicholas Bellinger 		 */
1318e48354ceSNicholas Bellinger 		if (iscsi_update_param_value(param, CHAP) < 0)
1319e48354ceSNicholas Bellinger 			return -EINVAL;
1320e48354ceSNicholas Bellinger 
1321e48354ceSNicholas Bellinger 		discovery_tpg->tpg_attrib.authentication = 1;
1322e48354ceSNicholas Bellinger 		iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1323e48354ceSNicholas Bellinger 		pr_debug("LIO-CORE[0] Successfully enabled"
1324e48354ceSNicholas Bellinger 			" authentication enforcement for iSCSI"
1325e48354ceSNicholas Bellinger 			" Discovery TPG\n");
1326e48354ceSNicholas Bellinger 	} else {
1327e48354ceSNicholas Bellinger 		/*
1328e48354ceSNicholas Bellinger 		 * Reset the AuthMethod key to CHAP,None
1329e48354ceSNicholas Bellinger 		 */
1330e48354ceSNicholas Bellinger 		if (iscsi_update_param_value(param, "CHAP,None") < 0)
1331e48354ceSNicholas Bellinger 			return -EINVAL;
1332e48354ceSNicholas Bellinger 
1333e48354ceSNicholas Bellinger 		discovery_tpg->tpg_attrib.authentication = 0;
1334e48354ceSNicholas Bellinger 		iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1335e48354ceSNicholas Bellinger 		pr_debug("LIO-CORE[0] Successfully disabled"
1336e48354ceSNicholas Bellinger 			" authentication enforcement for iSCSI"
1337e48354ceSNicholas Bellinger 			" Discovery TPG\n");
1338e48354ceSNicholas Bellinger 	}
1339e48354ceSNicholas Bellinger 
1340e48354ceSNicholas Bellinger 	return count;
1341e48354ceSNicholas Bellinger }
1342e48354ceSNicholas Bellinger 
1343e48354ceSNicholas Bellinger CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1344e48354ceSNicholas Bellinger 
13452eafd729SChristoph Hellwig static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1346e48354ceSNicholas Bellinger 	&iscsi_disc_attr_userid,
1347e48354ceSNicholas Bellinger 	&iscsi_disc_attr_password,
13482eafd729SChristoph Hellwig 	&iscsi_disc_attr_authenticate_target,
13492eafd729SChristoph Hellwig 	&iscsi_disc_attr_userid_mutual,
13502eafd729SChristoph Hellwig 	&iscsi_disc_attr_password_mutual,
13512eafd729SChristoph Hellwig 	&iscsi_disc_attr_enforce_discovery_auth,
13522eafd729SChristoph Hellwig 	NULL,
13532eafd729SChristoph Hellwig };
1354e48354ceSNicholas Bellinger 
1355e48354ceSNicholas Bellinger /* End lio_target_discovery_auth_cit */
1356e48354ceSNicholas Bellinger 
1357e48354ceSNicholas Bellinger /* Start functions for target_core_fabric_ops */
1358e48354ceSNicholas Bellinger 
iscsi_get_cmd_state(struct se_cmd * se_cmd)1359e48354ceSNicholas Bellinger static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1360e48354ceSNicholas Bellinger {
1361e48354ceSNicholas Bellinger 	struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1362e48354ceSNicholas Bellinger 
136366cd9d4eSMax Gurtovoy 	return cmd->i_state;
1364e48354ceSNicholas Bellinger }
1365e48354ceSNicholas Bellinger 
lio_sess_get_index(struct se_session * se_sess)1366e48354ceSNicholas Bellinger static u32 lio_sess_get_index(struct se_session *se_sess)
1367e48354ceSNicholas Bellinger {
1368e48354ceSNicholas Bellinger 	struct iscsit_session *sess = se_sess->fabric_sess_ptr;
1369e48354ceSNicholas Bellinger 
13700873fe44SMax Gurtovoy 	return sess->session_index;
1371e48354ceSNicholas Bellinger }
1372e48354ceSNicholas Bellinger 
lio_sess_get_initiator_sid(struct se_session * se_sess,unsigned char * buf,u32 size)1373e48354ceSNicholas Bellinger static u32 lio_sess_get_initiator_sid(
1374e48354ceSNicholas Bellinger 	struct se_session *se_sess,
1375e48354ceSNicholas Bellinger 	unsigned char *buf,
1376e48354ceSNicholas Bellinger 	u32 size)
1377e48354ceSNicholas Bellinger {
1378e48354ceSNicholas Bellinger 	struct iscsit_session *sess = se_sess->fabric_sess_ptr;
1379e48354ceSNicholas Bellinger 	/*
13800873fe44SMax Gurtovoy 	 * iSCSI Initiator Session Identifier from RFC-3720.
1381e48354ceSNicholas Bellinger 	 */
1382e48354ceSNicholas Bellinger 	return snprintf(buf, size, "%6phN", sess->isid);
1383e48354ceSNicholas Bellinger }
13845cdf5a87SAndy Shevchenko 
lio_queue_data_in(struct se_cmd * se_cmd)1385e48354ceSNicholas Bellinger static int lio_queue_data_in(struct se_cmd *se_cmd)
1386e48354ceSNicholas Bellinger {
1387e48354ceSNicholas Bellinger 	struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1388e48354ceSNicholas Bellinger 	struct iscsit_conn *conn = cmd->conn;
138966cd9d4eSMax Gurtovoy 
1390be36d683SMax Gurtovoy 	cmd->i_state = ISTATE_SEND_DATAIN;
1391e48354ceSNicholas Bellinger 	return conn->conn_transport->iscsit_queue_data_in(conn, cmd);
1392e48354ceSNicholas Bellinger }
1393a4467018SNicholas Bellinger 
lio_write_pending(struct se_cmd * se_cmd)1394e48354ceSNicholas Bellinger static int lio_write_pending(struct se_cmd *se_cmd)
1395e48354ceSNicholas Bellinger {
1396e48354ceSNicholas Bellinger 	struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1397e48354ceSNicholas Bellinger 	struct iscsit_conn *conn = cmd->conn;
139866cd9d4eSMax Gurtovoy 
1399be36d683SMax Gurtovoy 	if (!cmd->immediate_data && !cmd->unsolicited_data)
1400e48354ceSNicholas Bellinger 		return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1401e48354ceSNicholas Bellinger 
14023e1c81a9SNicholas Bellinger 	return 0;
1403e48354ceSNicholas Bellinger }
1404e48354ceSNicholas Bellinger 
lio_queue_status(struct se_cmd * se_cmd)1405e48354ceSNicholas Bellinger static int lio_queue_status(struct se_cmd *se_cmd)
1406e48354ceSNicholas Bellinger {
1407e48354ceSNicholas Bellinger 	struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1408e48354ceSNicholas Bellinger 	struct iscsit_conn *conn = cmd->conn;
140966cd9d4eSMax Gurtovoy 
1410be36d683SMax Gurtovoy 	cmd->i_state = ISTATE_SEND_STATUS;
1411e48354ceSNicholas Bellinger 
1412e48354ceSNicholas Bellinger 	if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
14135e8e6b4bSNicholas Bellinger 		return iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
14145e8e6b4bSNicholas Bellinger 	}
1415a4467018SNicholas Bellinger 	return conn->conn_transport->iscsit_queue_status(conn, cmd);
14165e8e6b4bSNicholas Bellinger }
1417a4467018SNicholas Bellinger 
lio_queue_tm_rsp(struct se_cmd * se_cmd)1418e48354ceSNicholas Bellinger static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1419e48354ceSNicholas Bellinger {
1420b79fafacSJoern Engel 	struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1421e48354ceSNicholas Bellinger 
142266cd9d4eSMax Gurtovoy 	cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1423e48354ceSNicholas Bellinger 	iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1424e48354ceSNicholas Bellinger }
1425e48354ceSNicholas Bellinger 
lio_aborted_task(struct se_cmd * se_cmd)1426e48354ceSNicholas Bellinger static void lio_aborted_task(struct se_cmd *se_cmd)
1427e48354ceSNicholas Bellinger {
1428131e6abcSNicholas Bellinger 	struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1429131e6abcSNicholas Bellinger 
143066cd9d4eSMax Gurtovoy 	cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1431131e6abcSNicholas Bellinger }
1432131e6abcSNicholas Bellinger 
lio_tpg_get_endpoint_wwn(struct se_portal_group * se_tpg)1433131e6abcSNicholas Bellinger static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1434131e6abcSNicholas Bellinger {
1435e48354ceSNicholas Bellinger 	return to_iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1436e48354ceSNicholas Bellinger }
1437a11b8069SDmitry Bogdanov 
lio_tpg_get_tag(struct se_portal_group * se_tpg)1438e48354ceSNicholas Bellinger static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1439e48354ceSNicholas Bellinger {
1440e48354ceSNicholas Bellinger 	return to_iscsi_tpg(se_tpg)->tpgt;
1441e48354ceSNicholas Bellinger }
1442a11b8069SDmitry Bogdanov 
lio_tpg_get_default_depth(struct se_portal_group * se_tpg)1443e48354ceSNicholas Bellinger static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1444e48354ceSNicholas Bellinger {
1445e48354ceSNicholas Bellinger 	return to_iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1446e48354ceSNicholas Bellinger }
1447a11b8069SDmitry Bogdanov 
lio_tpg_check_demo_mode(struct se_portal_group * se_tpg)1448e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1449e48354ceSNicholas Bellinger {
1450e48354ceSNicholas Bellinger 	return to_iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1451e48354ceSNicholas Bellinger }
1452a11b8069SDmitry Bogdanov 
lio_tpg_check_demo_mode_cache(struct se_portal_group * se_tpg)1453e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1454e48354ceSNicholas Bellinger {
1455e48354ceSNicholas Bellinger 	return to_iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1456e48354ceSNicholas Bellinger }
1457a11b8069SDmitry Bogdanov 
lio_tpg_check_demo_mode_write_protect(struct se_portal_group * se_tpg)1458e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_write_protect(
1459e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg)
1460e48354ceSNicholas Bellinger {
1461e48354ceSNicholas Bellinger 	return to_iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1462e48354ceSNicholas Bellinger }
1463a11b8069SDmitry Bogdanov 
lio_tpg_check_prod_mode_write_protect(struct se_portal_group * se_tpg)1464e48354ceSNicholas Bellinger static int lio_tpg_check_prod_mode_write_protect(
1465e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg)
1466e48354ceSNicholas Bellinger {
1467e48354ceSNicholas Bellinger 	return to_iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1468e48354ceSNicholas Bellinger }
1469a11b8069SDmitry Bogdanov 
lio_tpg_check_prot_fabric_only(struct se_portal_group * se_tpg)1470e48354ceSNicholas Bellinger static int lio_tpg_check_prot_fabric_only(
1471e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg)
1472901c04a3SNicholas Bellinger {
1473901c04a3SNicholas Bellinger 	/*
1474901c04a3SNicholas Bellinger 	 * Only report fabric_prot_type if t10_pi has also been enabled
1475901c04a3SNicholas Bellinger 	 * for incoming ib_isert sessions.
1476901c04a3SNicholas Bellinger 	 */
1477901c04a3SNicholas Bellinger 	if (!to_iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1478901c04a3SNicholas Bellinger 		return 0;
1479a11b8069SDmitry Bogdanov 	return to_iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1480901c04a3SNicholas Bellinger }
1481a11b8069SDmitry Bogdanov 
1482901c04a3SNicholas Bellinger /*
1483901c04a3SNicholas Bellinger  * This function calls iscsit_inc_session_usage_count() on the
1484e48354ceSNicholas Bellinger  * struct iscsit_session in question.
1485d36ad77fSNicholas Bellinger  */
lio_tpg_close_session(struct se_session * se_sess)14860873fe44SMax Gurtovoy static void lio_tpg_close_session(struct se_session *se_sess)
1487e48354ceSNicholas Bellinger {
148844f33d0fSChristoph Hellwig 	struct iscsit_session *sess = se_sess->fabric_sess_ptr;
1489e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
14900873fe44SMax Gurtovoy 
1491d36ad77fSNicholas Bellinger 	spin_lock_bh(&se_tpg->session_lock);
149226a99c19SNicholas Bellinger 	spin_lock(&sess->conn_lock);
1493d36ad77fSNicholas Bellinger 	if (atomic_read(&sess->session_fall_back_to_erl0) ||
1494e48354ceSNicholas Bellinger 	    atomic_read(&sess->session_logout) ||
1495e48354ceSNicholas Bellinger 	    atomic_read(&sess->session_close) ||
1496e48354ceSNicholas Bellinger 	    (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
149757c46e9fSMaurizio Lombardi 		spin_unlock(&sess->conn_lock);
1498e48354ceSNicholas Bellinger 		spin_unlock_bh(&se_tpg->session_lock);
1499e48354ceSNicholas Bellinger 		return;
1500d36ad77fSNicholas Bellinger 	}
150144f33d0fSChristoph Hellwig 	iscsit_inc_session_usage_count(sess);
1502e48354ceSNicholas Bellinger 	atomic_set(&sess->session_reinstatement, 1);
150357c46e9fSMaurizio Lombardi 	atomic_set(&sess->session_fall_back_to_erl0, 1);
1504e48354ceSNicholas Bellinger 	atomic_set(&sess->session_close, 1);
1505197b806aSNicholas Bellinger 	spin_unlock(&sess->conn_lock);
150657c46e9fSMaurizio Lombardi 
1507e48354ceSNicholas Bellinger 	iscsit_stop_time2retain_timer(sess);
1508e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_tpg->session_lock);
1509e48354ceSNicholas Bellinger 
1510d36ad77fSNicholas Bellinger 	iscsit_stop_session(sess, 1, 1);
151126a99c19SNicholas Bellinger 	iscsit_dec_session_usage_count(sess);
151299367f01SNicholas Bellinger }
151357c46e9fSMaurizio Lombardi 
lio_tpg_get_inst_index(struct se_portal_group * se_tpg)1514e48354ceSNicholas Bellinger static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1515e48354ceSNicholas Bellinger {
1516e48354ceSNicholas Bellinger 	return to_iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1517e48354ceSNicholas Bellinger }
1518a11b8069SDmitry Bogdanov 
lio_set_default_node_attributes(struct se_node_acl * se_acl)1519e48354ceSNicholas Bellinger static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1520e48354ceSNicholas Bellinger {
1521e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = to_iscsi_nacl(se_acl);
1522e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg = se_acl->se_tpg;
1523a11b8069SDmitry Bogdanov 	struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);
1524d1fa7a1dSNicholas Bellinger 
1525a11b8069SDmitry Bogdanov 	acl->node_attrib.nacl = acl;
1526e48354ceSNicholas Bellinger 	iscsit_set_default_node_attribues(acl, tpg);
1527b7eec2cdSAndy Grover }
1528d1fa7a1dSNicholas Bellinger 
lio_check_stop_free(struct se_cmd * se_cmd)1529e48354ceSNicholas Bellinger static int lio_check_stop_free(struct se_cmd *se_cmd)
1530e48354ceSNicholas Bellinger {
15313e1c81a9SNicholas Bellinger 	return target_put_sess_cmd(se_cmd);
15323e1c81a9SNicholas Bellinger }
1533afc16604SBart Van Assche 
lio_release_cmd(struct se_cmd * se_cmd)15343e1c81a9SNicholas Bellinger static void lio_release_cmd(struct se_cmd *se_cmd)
15353e1c81a9SNicholas Bellinger {
1536e48354ceSNicholas Bellinger 	struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1537e48354ceSNicholas Bellinger 
153866cd9d4eSMax Gurtovoy 	pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1539e48354ceSNicholas Bellinger 	iscsit_release_cmd(cmd);
1540cdb72665SNicholas Bellinger }
1541d703ce2fSNicholas Bellinger 
1542e48354ceSNicholas Bellinger const struct target_core_fabric_ops iscsi_ops = {
1543e48354ceSNicholas Bellinger 	.module				= THIS_MODULE,
15449ac8928eSChristoph Hellwig 	.fabric_alias			= "iscsi",
15459ac8928eSChristoph Hellwig 	.fabric_name			= "iSCSI",
154659a206b4SDavid Disseldorp 	.node_acl_size			= sizeof(struct iscsi_node_acl),
154730c7ca93SDavid Disseldorp 	.tpg_get_wwn			= lio_tpg_get_endpoint_wwn,
1548144bc4c2SChristoph Hellwig 	.tpg_get_tag			= lio_tpg_get_tag,
15499ac8928eSChristoph Hellwig 	.tpg_get_default_depth		= lio_tpg_get_default_depth,
15509ac8928eSChristoph Hellwig 	.tpg_check_demo_mode		= lio_tpg_check_demo_mode,
15519ac8928eSChristoph Hellwig 	.tpg_check_demo_mode_cache	= lio_tpg_check_demo_mode_cache,
15529ac8928eSChristoph Hellwig 	.tpg_check_demo_mode_write_protect =
15539ac8928eSChristoph Hellwig 			lio_tpg_check_demo_mode_write_protect,
15549ac8928eSChristoph Hellwig 	.tpg_check_prod_mode_write_protect =
15559ac8928eSChristoph Hellwig 			lio_tpg_check_prod_mode_write_protect,
15569ac8928eSChristoph Hellwig 	.tpg_check_prot_fabric_only	= &lio_tpg_check_prot_fabric_only,
15579ac8928eSChristoph Hellwig 	.tpg_get_inst_index		= lio_tpg_get_inst_index,
15589ac8928eSChristoph Hellwig 	.check_stop_free		= lio_check_stop_free,
15599ac8928eSChristoph Hellwig 	.release_cmd			= lio_release_cmd,
15609ac8928eSChristoph Hellwig 	.close_session			= lio_tpg_close_session,
15619ac8928eSChristoph Hellwig 	.sess_get_index			= lio_sess_get_index,
15629ac8928eSChristoph Hellwig 	.sess_get_initiator_sid		= lio_sess_get_initiator_sid,
15639ac8928eSChristoph Hellwig 	.write_pending			= lio_write_pending,
15649ac8928eSChristoph Hellwig 	.set_default_node_attributes	= lio_set_default_node_attributes,
15659ac8928eSChristoph Hellwig 	.get_cmd_state			= iscsi_get_cmd_state,
15669ac8928eSChristoph Hellwig 	.queue_data_in			= lio_queue_data_in,
15679ac8928eSChristoph Hellwig 	.queue_status			= lio_queue_status,
15689ac8928eSChristoph Hellwig 	.queue_tm_rsp			= lio_queue_tm_rsp,
15699ac8928eSChristoph Hellwig 	.aborted_task			= lio_aborted_task,
15709ac8928eSChristoph Hellwig 	.fabric_make_wwn		= lio_target_call_coreaddtiqn,
15719ac8928eSChristoph Hellwig 	.fabric_drop_wwn		= lio_target_call_coredeltiqn,
15729ac8928eSChristoph Hellwig 	.add_wwn_groups			= lio_target_add_wwn_groups,
15739ac8928eSChristoph Hellwig 	.fabric_make_tpg		= lio_target_tiqn_addtpg,
1574839559e1SChristoph Hellwig 	.fabric_enable_tpg		= lio_target_tiqn_enabletpg,
15759ac8928eSChristoph Hellwig 	.fabric_drop_tpg		= lio_target_tiqn_deltpg,
1576382731ecSDmitry Bogdanov 	.fabric_make_np			= lio_target_call_addnptotpg,
15779ac8928eSChristoph Hellwig 	.fabric_drop_np			= lio_target_call_delnpfromtpg,
15789ac8928eSChristoph Hellwig 	.fabric_init_nodeacl		= lio_target_init_nodeacl,
15799ac8928eSChristoph Hellwig 
1580c7d6a803SChristoph Hellwig 	.tfc_discovery_attrs		= lio_target_discovery_auth_attrs,
1581e48354ceSNicholas Bellinger 	.tfc_wwn_attrs			= lio_target_wwn_attrs,
15829ac8928eSChristoph Hellwig 	.tfc_tpg_base_attrs		= lio_target_tpg_attrs,
15839ac8928eSChristoph Hellwig 	.tfc_tpg_attrib_attrs		= lio_target_tpg_attrib_attrs,
15849ac8928eSChristoph Hellwig 	.tfc_tpg_auth_attrs		= lio_target_tpg_auth_attrs,
15859ac8928eSChristoph Hellwig 	.tfc_tpg_param_attrs		= lio_target_tpg_param_attrs,
15869ac8928eSChristoph Hellwig 	.tfc_tpg_np_base_attrs		= lio_target_portal_attrs,
15879ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_base_attrs	= lio_target_initiator_attrs,
15889ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_attrib_attrs	= lio_target_nacl_attrib_attrs,
15899ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_auth_attrs	= lio_target_nacl_auth_attrs,
15909ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_param_attrs	= lio_target_nacl_param_attrs,
15919ac8928eSChristoph Hellwig 
15929ac8928eSChristoph Hellwig 	.write_pending_must_be_called	= true,
1593fbbd4923SBart Van Assche };
1594fbbd4923SBart Van Assche