1e48354ceSNicholas Bellinger /*******************************************************************************
2e48354ceSNicholas Bellinger  * This file contains the configfs implementation for iSCSI Target mode
3e48354ceSNicholas Bellinger  * from the LIO-Target Project.
4e48354ceSNicholas Bellinger  *
54c76251eSNicholas Bellinger  * (c) Copyright 2007-2013 Datera, Inc.
6e48354ceSNicholas Bellinger  *
7e48354ceSNicholas Bellinger  * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
8e48354ceSNicholas Bellinger  *
9e48354ceSNicholas Bellinger  * This program is free software; you can redistribute it and/or modify
10e48354ceSNicholas Bellinger  * it under the terms of the GNU General Public License as published by
11e48354ceSNicholas Bellinger  * the Free Software Foundation; either version 2 of the License, or
12e48354ceSNicholas Bellinger  * (at your option) any later version.
13e48354ceSNicholas Bellinger  *
14e48354ceSNicholas Bellinger  * This program is distributed in the hope that it will be useful,
15e48354ceSNicholas Bellinger  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16e48354ceSNicholas Bellinger  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17e48354ceSNicholas Bellinger  * GNU General Public License for more details.
18e48354ceSNicholas Bellinger  ****************************************************************************/
19e48354ceSNicholas Bellinger 
20e48354ceSNicholas Bellinger #include <linux/configfs.h>
21ad7babd2SJörn Engel #include <linux/ctype.h>
22c53181afSPaul Gortmaker #include <linux/export.h>
23c3bc93daSStephen Rothwell #include <linux/inet.h>
24e48354ceSNicholas Bellinger #include <target/target_core_base.h>
25c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h>
26e48354ceSNicholas Bellinger #include <target/target_core_fabric_configfs.h>
27e48354ceSNicholas Bellinger #include <target/target_core_configfs.h>
28e48354ceSNicholas Bellinger #include <target/configfs_macros.h>
292ec5a8c1SNicholas Bellinger #include <target/iscsi/iscsi_transport.h>
30e48354ceSNicholas Bellinger 
3167f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h>
32e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h"
33e48354ceSNicholas Bellinger #include "iscsi_target_device.h"
34e48354ceSNicholas Bellinger #include "iscsi_target_erl0.h"
35e48354ceSNicholas Bellinger #include "iscsi_target_nodeattrib.h"
36e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h"
37e48354ceSNicholas Bellinger #include "iscsi_target_util.h"
38e48354ceSNicholas Bellinger #include "iscsi_target.h"
3967f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_stat.h>
40e48354ceSNicholas Bellinger 
41e48354ceSNicholas Bellinger struct lio_target_configfs_attribute {
42e48354ceSNicholas Bellinger 	struct configfs_attribute attr;
43e48354ceSNicholas Bellinger 	ssize_t (*show)(void *, char *);
44e48354ceSNicholas Bellinger 	ssize_t (*store)(void *, const char *, size_t);
45e48354ceSNicholas Bellinger };
46e48354ceSNicholas Bellinger 
47e48354ceSNicholas Bellinger /* Start items for lio_target_portal_cit */
48e48354ceSNicholas Bellinger 
49e48354ceSNicholas Bellinger static ssize_t lio_target_np_show_sctp(
50e48354ceSNicholas Bellinger 	struct se_tpg_np *se_tpg_np,
51e48354ceSNicholas Bellinger 	char *page)
52e48354ceSNicholas Bellinger {
53e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
54e48354ceSNicholas Bellinger 				struct iscsi_tpg_np, se_tpg_np);
55e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np_sctp;
56e48354ceSNicholas Bellinger 	ssize_t rb;
57e48354ceSNicholas Bellinger 
58e48354ceSNicholas Bellinger 	tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
59e48354ceSNicholas Bellinger 	if (tpg_np_sctp)
60e48354ceSNicholas Bellinger 		rb = sprintf(page, "1\n");
61e48354ceSNicholas Bellinger 	else
62e48354ceSNicholas Bellinger 		rb = sprintf(page, "0\n");
63e48354ceSNicholas Bellinger 
64e48354ceSNicholas Bellinger 	return rb;
65e48354ceSNicholas Bellinger }
66e48354ceSNicholas Bellinger 
67e48354ceSNicholas Bellinger static ssize_t lio_target_np_store_sctp(
68e48354ceSNicholas Bellinger 	struct se_tpg_np *se_tpg_np,
69e48354ceSNicholas Bellinger 	const char *page,
70e48354ceSNicholas Bellinger 	size_t count)
71e48354ceSNicholas Bellinger {
72e48354ceSNicholas Bellinger 	struct iscsi_np *np;
73e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
74e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
75e48354ceSNicholas Bellinger 				struct iscsi_tpg_np, se_tpg_np);
76e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np_sctp = NULL;
77e48354ceSNicholas Bellinger 	u32 op;
78e48354ceSNicholas Bellinger 	int ret;
79e48354ceSNicholas Bellinger 
80ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &op);
81ad7babd2SJörn Engel 	if (ret)
82ad7babd2SJörn Engel 		return ret;
83e48354ceSNicholas Bellinger 	if ((op != 1) && (op != 0)) {
84e48354ceSNicholas Bellinger 		pr_err("Illegal value for tpg_enable: %u\n", op);
85e48354ceSNicholas Bellinger 		return -EINVAL;
86e48354ceSNicholas Bellinger 	}
87e48354ceSNicholas Bellinger 	np = tpg_np->tpg_np;
88e48354ceSNicholas Bellinger 	if (!np) {
89e48354ceSNicholas Bellinger 		pr_err("Unable to locate struct iscsi_np from"
90e48354ceSNicholas Bellinger 				" struct iscsi_tpg_np\n");
91e48354ceSNicholas Bellinger 		return -EINVAL;
92e48354ceSNicholas Bellinger 	}
93e48354ceSNicholas Bellinger 
94e48354ceSNicholas Bellinger 	tpg = tpg_np->tpg;
95e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)
96e48354ceSNicholas Bellinger 		return -EINVAL;
97e48354ceSNicholas Bellinger 
98e48354ceSNicholas Bellinger 	if (op) {
99e48354ceSNicholas Bellinger 		/*
100e48354ceSNicholas Bellinger 		 * Use existing np->np_sockaddr for SCTP network portal reference
101e48354ceSNicholas Bellinger 		 */
102e48354ceSNicholas Bellinger 		tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
103e48354ceSNicholas Bellinger 					np->np_ip, tpg_np, ISCSI_SCTP_TCP);
104e48354ceSNicholas Bellinger 		if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
105e48354ceSNicholas Bellinger 			goto out;
106e48354ceSNicholas Bellinger 	} else {
107e48354ceSNicholas Bellinger 		tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
108e48354ceSNicholas Bellinger 		if (!tpg_np_sctp)
109e48354ceSNicholas Bellinger 			goto out;
110e48354ceSNicholas Bellinger 
111e48354ceSNicholas Bellinger 		ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
112e48354ceSNicholas Bellinger 		if (ret < 0)
113e48354ceSNicholas Bellinger 			goto out;
114e48354ceSNicholas Bellinger 	}
115e48354ceSNicholas Bellinger 
116e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
117e48354ceSNicholas Bellinger 	return count;
118e48354ceSNicholas Bellinger out:
119e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
120e48354ceSNicholas Bellinger 	return -EINVAL;
121e48354ceSNicholas Bellinger }
122e48354ceSNicholas Bellinger 
123e48354ceSNicholas Bellinger TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR);
124e48354ceSNicholas Bellinger 
12572438cddSNicholas Bellinger static ssize_t lio_target_np_show_iser(
12672438cddSNicholas Bellinger 	struct se_tpg_np *se_tpg_np,
12772438cddSNicholas Bellinger 	char *page)
12872438cddSNicholas Bellinger {
12972438cddSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
13072438cddSNicholas Bellinger 				struct iscsi_tpg_np, se_tpg_np);
13172438cddSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np_iser;
13272438cddSNicholas Bellinger 	ssize_t rb;
13372438cddSNicholas Bellinger 
13472438cddSNicholas Bellinger 	tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
13572438cddSNicholas Bellinger 	if (tpg_np_iser)
13672438cddSNicholas Bellinger 		rb = sprintf(page, "1\n");
13772438cddSNicholas Bellinger 	else
13872438cddSNicholas Bellinger 		rb = sprintf(page, "0\n");
13972438cddSNicholas Bellinger 
14072438cddSNicholas Bellinger 	return rb;
14172438cddSNicholas Bellinger }
14272438cddSNicholas Bellinger 
14372438cddSNicholas Bellinger static ssize_t lio_target_np_store_iser(
14472438cddSNicholas Bellinger 	struct se_tpg_np *se_tpg_np,
14572438cddSNicholas Bellinger 	const char *page,
14672438cddSNicholas Bellinger 	size_t count)
14772438cddSNicholas Bellinger {
14872438cddSNicholas Bellinger 	struct iscsi_np *np;
14972438cddSNicholas Bellinger 	struct iscsi_portal_group *tpg;
15072438cddSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
15172438cddSNicholas Bellinger 				struct iscsi_tpg_np, se_tpg_np);
15272438cddSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np_iser = NULL;
15372438cddSNicholas Bellinger 	char *endptr;
15472438cddSNicholas Bellinger 	u32 op;
15558bd0c69SAndy Grover 	int rc = 0;
15672438cddSNicholas Bellinger 
15772438cddSNicholas Bellinger 	op = simple_strtoul(page, &endptr, 0);
15872438cddSNicholas Bellinger 	if ((op != 1) && (op != 0)) {
15972438cddSNicholas Bellinger 		pr_err("Illegal value for tpg_enable: %u\n", op);
16072438cddSNicholas Bellinger 		return -EINVAL;
16172438cddSNicholas Bellinger 	}
16272438cddSNicholas Bellinger 	np = tpg_np->tpg_np;
16372438cddSNicholas Bellinger 	if (!np) {
16472438cddSNicholas Bellinger 		pr_err("Unable to locate struct iscsi_np from"
16572438cddSNicholas Bellinger 				" struct iscsi_tpg_np\n");
16672438cddSNicholas Bellinger 		return -EINVAL;
16772438cddSNicholas Bellinger 	}
16872438cddSNicholas Bellinger 
16972438cddSNicholas Bellinger 	tpg = tpg_np->tpg;
17072438cddSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)
17172438cddSNicholas Bellinger 		return -EINVAL;
17272438cddSNicholas Bellinger 
17372438cddSNicholas Bellinger 	if (op) {
17458bd0c69SAndy Grover 		rc = request_module("ib_isert");
17558bd0c69SAndy Grover 		if (rc != 0) {
17672438cddSNicholas Bellinger 			pr_warn("Unable to request_module for ib_isert\n");
17758bd0c69SAndy Grover 			rc = 0;
17858bd0c69SAndy Grover 		}
17972438cddSNicholas Bellinger 
18072438cddSNicholas Bellinger 		tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
18172438cddSNicholas Bellinger 				np->np_ip, tpg_np, ISCSI_INFINIBAND);
18258bd0c69SAndy Grover 		if (IS_ERR(tpg_np_iser)) {
18358bd0c69SAndy Grover 			rc = PTR_ERR(tpg_np_iser);
18472438cddSNicholas Bellinger 			goto out;
18558bd0c69SAndy Grover 		}
18672438cddSNicholas Bellinger 	} else {
18772438cddSNicholas Bellinger 		tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
18858bd0c69SAndy Grover 		if (tpg_np_iser) {
18972438cddSNicholas Bellinger 			rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
19072438cddSNicholas Bellinger 			if (rc < 0)
19172438cddSNicholas Bellinger 				goto out;
19272438cddSNicholas Bellinger 		}
19358bd0c69SAndy Grover 	}
19472438cddSNicholas Bellinger 
19572438cddSNicholas Bellinger 	iscsit_put_tpg(tpg);
19672438cddSNicholas Bellinger 	return count;
19772438cddSNicholas Bellinger out:
19872438cddSNicholas Bellinger 	iscsit_put_tpg(tpg);
19958bd0c69SAndy Grover 	return rc;
20072438cddSNicholas Bellinger }
20172438cddSNicholas Bellinger 
20272438cddSNicholas Bellinger TF_NP_BASE_ATTR(lio_target, iser, S_IRUGO | S_IWUSR);
20372438cddSNicholas Bellinger 
204e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_portal_attrs[] = {
205e48354ceSNicholas Bellinger 	&lio_target_np_sctp.attr,
20672438cddSNicholas Bellinger 	&lio_target_np_iser.attr,
207e48354ceSNicholas Bellinger 	NULL,
208e48354ceSNicholas Bellinger };
209e48354ceSNicholas Bellinger 
210e48354ceSNicholas Bellinger /* Stop items for lio_target_portal_cit */
211e48354ceSNicholas Bellinger 
212e48354ceSNicholas Bellinger /* Start items for lio_target_np_cit */
213e48354ceSNicholas Bellinger 
214e48354ceSNicholas Bellinger #define MAX_PORTAL_LEN		256
215e48354ceSNicholas Bellinger 
216fceb5bc7SChristoph Hellwig static struct se_tpg_np *lio_target_call_addnptotpg(
217e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,
218e48354ceSNicholas Bellinger 	struct config_group *group,
219e48354ceSNicholas Bellinger 	const char *name)
220e48354ceSNicholas Bellinger {
221e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
222e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np;
223e48354ceSNicholas Bellinger 	char *str, *str2, *ip_str, *port_str;
224e48354ceSNicholas Bellinger 	struct __kernel_sockaddr_storage sockaddr;
225e48354ceSNicholas Bellinger 	struct sockaddr_in *sock_in;
226e48354ceSNicholas Bellinger 	struct sockaddr_in6 *sock_in6;
227e48354ceSNicholas Bellinger 	unsigned long port;
228e48354ceSNicholas Bellinger 	int ret;
229e48354ceSNicholas Bellinger 	char buf[MAX_PORTAL_LEN + 1];
230e48354ceSNicholas Bellinger 
231e48354ceSNicholas Bellinger 	if (strlen(name) > MAX_PORTAL_LEN) {
232e48354ceSNicholas Bellinger 		pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
233e48354ceSNicholas Bellinger 			(int)strlen(name), MAX_PORTAL_LEN);
234e48354ceSNicholas Bellinger 		return ERR_PTR(-EOVERFLOW);
235e48354ceSNicholas Bellinger 	}
236e48354ceSNicholas Bellinger 	memset(buf, 0, MAX_PORTAL_LEN + 1);
2377bbb654eSNicholas Bellinger 	snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
238e48354ceSNicholas Bellinger 
239e48354ceSNicholas Bellinger 	memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage));
240e48354ceSNicholas Bellinger 
241e48354ceSNicholas Bellinger 	str = strstr(buf, "[");
242e48354ceSNicholas Bellinger 	if (str) {
243e48354ceSNicholas Bellinger 		const char *end;
244e48354ceSNicholas Bellinger 
245e48354ceSNicholas Bellinger 		str2 = strstr(str, "]");
246e48354ceSNicholas Bellinger 		if (!str2) {
247e48354ceSNicholas Bellinger 			pr_err("Unable to locate trailing \"]\""
248e48354ceSNicholas Bellinger 				" in IPv6 iSCSI network portal address\n");
249e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
250e48354ceSNicholas Bellinger 		}
251e48354ceSNicholas Bellinger 		str++; /* Skip over leading "[" */
252e48354ceSNicholas Bellinger 		*str2 = '\0'; /* Terminate the IPv6 address */
253e48354ceSNicholas Bellinger 		str2++; /* Skip over the "]" */
254e48354ceSNicholas Bellinger 		port_str = strstr(str2, ":");
255e48354ceSNicholas Bellinger 		if (!port_str) {
256e48354ceSNicholas Bellinger 			pr_err("Unable to locate \":port\""
257e48354ceSNicholas Bellinger 				" in IPv6 iSCSI network portal address\n");
258e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
259e48354ceSNicholas Bellinger 		}
260e48354ceSNicholas Bellinger 		*port_str = '\0'; /* Terminate string for IP */
261e48354ceSNicholas Bellinger 		port_str++; /* Skip over ":" */
262e48354ceSNicholas Bellinger 
26357103d7fSJingoo Han 		ret = kstrtoul(port_str, 0, &port);
264e48354ceSNicholas Bellinger 		if (ret < 0) {
26557103d7fSJingoo Han 			pr_err("kstrtoul() failed for port_str: %d\n", ret);
266e48354ceSNicholas Bellinger 			return ERR_PTR(ret);
267e48354ceSNicholas Bellinger 		}
268e48354ceSNicholas Bellinger 		sock_in6 = (struct sockaddr_in6 *)&sockaddr;
269e48354ceSNicholas Bellinger 		sock_in6->sin6_family = AF_INET6;
270e48354ceSNicholas Bellinger 		sock_in6->sin6_port = htons((unsigned short)port);
271e48354ceSNicholas Bellinger 		ret = in6_pton(str, IPV6_ADDRESS_SPACE,
272e48354ceSNicholas Bellinger 				(void *)&sock_in6->sin6_addr.in6_u, -1, &end);
273e48354ceSNicholas Bellinger 		if (ret <= 0) {
274e48354ceSNicholas Bellinger 			pr_err("in6_pton returned: %d\n", ret);
275e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
276e48354ceSNicholas Bellinger 		}
277e48354ceSNicholas Bellinger 	} else {
278e48354ceSNicholas Bellinger 		str = ip_str = &buf[0];
279e48354ceSNicholas Bellinger 		port_str = strstr(ip_str, ":");
280e48354ceSNicholas Bellinger 		if (!port_str) {
281e48354ceSNicholas Bellinger 			pr_err("Unable to locate \":port\""
282e48354ceSNicholas Bellinger 				" in IPv4 iSCSI network portal address\n");
283e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
284e48354ceSNicholas Bellinger 		}
285e48354ceSNicholas Bellinger 		*port_str = '\0'; /* Terminate string for IP */
286e48354ceSNicholas Bellinger 		port_str++; /* Skip over ":" */
287e48354ceSNicholas Bellinger 
28857103d7fSJingoo Han 		ret = kstrtoul(port_str, 0, &port);
289e48354ceSNicholas Bellinger 		if (ret < 0) {
29057103d7fSJingoo Han 			pr_err("kstrtoul() failed for port_str: %d\n", ret);
291e48354ceSNicholas Bellinger 			return ERR_PTR(ret);
292e48354ceSNicholas Bellinger 		}
293e48354ceSNicholas Bellinger 		sock_in = (struct sockaddr_in *)&sockaddr;
294e48354ceSNicholas Bellinger 		sock_in->sin_family = AF_INET;
295e48354ceSNicholas Bellinger 		sock_in->sin_port = htons((unsigned short)port);
296e48354ceSNicholas Bellinger 		sock_in->sin_addr.s_addr = in_aton(ip_str);
297e48354ceSNicholas Bellinger 	}
298e48354ceSNicholas Bellinger 	tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
299e48354ceSNicholas Bellinger 	ret = iscsit_get_tpg(tpg);
300e48354ceSNicholas Bellinger 	if (ret < 0)
301e48354ceSNicholas Bellinger 		return ERR_PTR(-EINVAL);
302e48354ceSNicholas Bellinger 
303e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
304e48354ceSNicholas Bellinger 		" PORTAL: %s\n",
305e48354ceSNicholas Bellinger 		config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
306e48354ceSNicholas Bellinger 		tpg->tpgt, name);
307e48354ceSNicholas Bellinger 	/*
308e48354ceSNicholas Bellinger 	 * Assume ISCSI_TCP by default.  Other network portals for other
309e48354ceSNicholas Bellinger 	 * iSCSI fabrics:
310e48354ceSNicholas Bellinger 	 *
311e48354ceSNicholas Bellinger 	 * Traditional iSCSI over SCTP (initial support)
312e48354ceSNicholas Bellinger 	 * iSER/TCP (TODO, hardware available)
313e48354ceSNicholas Bellinger 	 * iSER/SCTP (TODO, software emulation with osc-iwarp)
314e48354ceSNicholas Bellinger 	 * iSER/IB (TODO, hardware available)
315e48354ceSNicholas Bellinger 	 *
31620879696SMasanari Iida 	 * can be enabled with attributes under
317e48354ceSNicholas Bellinger 	 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
318e48354ceSNicholas Bellinger 	 *
319e48354ceSNicholas Bellinger 	 */
320e48354ceSNicholas Bellinger 	tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL,
321e48354ceSNicholas Bellinger 				ISCSI_TCP);
322e48354ceSNicholas Bellinger 	if (IS_ERR(tpg_np)) {
323e48354ceSNicholas Bellinger 		iscsit_put_tpg(tpg);
324e1750ba2SThomas Meyer 		return ERR_CAST(tpg_np);
325e48354ceSNicholas Bellinger 	}
326e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
327e48354ceSNicholas Bellinger 
328e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
329e48354ceSNicholas Bellinger 	return &tpg_np->se_tpg_np;
330e48354ceSNicholas Bellinger }
331e48354ceSNicholas Bellinger 
332e48354ceSNicholas Bellinger static void lio_target_call_delnpfromtpg(
333e48354ceSNicholas Bellinger 	struct se_tpg_np *se_tpg_np)
334e48354ceSNicholas Bellinger {
335e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
336e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np;
337e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg;
338e48354ceSNicholas Bellinger 	int ret;
339e48354ceSNicholas Bellinger 
340e48354ceSNicholas Bellinger 	tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
341e48354ceSNicholas Bellinger 	tpg = tpg_np->tpg;
342e48354ceSNicholas Bellinger 	ret = iscsit_get_tpg(tpg);
343e48354ceSNicholas Bellinger 	if (ret < 0)
344e48354ceSNicholas Bellinger 		return;
345e48354ceSNicholas Bellinger 
346e48354ceSNicholas Bellinger 	se_tpg = &tpg->tpg_se_tpg;
347e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
348e48354ceSNicholas Bellinger 		" PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
349e48354ceSNicholas Bellinger 		tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port);
350e48354ceSNicholas Bellinger 
351e48354ceSNicholas Bellinger 	ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
352e48354ceSNicholas Bellinger 	if (ret < 0)
353e48354ceSNicholas Bellinger 		goto out;
354e48354ceSNicholas Bellinger 
355e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
356e48354ceSNicholas Bellinger out:
357e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
358e48354ceSNicholas Bellinger }
359e48354ceSNicholas Bellinger 
360e48354ceSNicholas Bellinger /* End items for lio_target_np_cit */
361e48354ceSNicholas Bellinger 
362e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_attrib_cit */
363e48354ceSNicholas Bellinger 
364e48354ceSNicholas Bellinger #define DEF_NACL_ATTRIB(name)						\
365e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_attrib_show_##name(				\
366e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl,					\
367e48354ceSNicholas Bellinger 	char *page)							\
368e48354ceSNicholas Bellinger {									\
369e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
370e48354ceSNicholas Bellinger 					se_node_acl);			\
371e48354ceSNicholas Bellinger 									\
372b7eec2cdSAndy Grover 	return sprintf(page, "%u\n", nacl->node_attrib.name);		\
373e48354ceSNicholas Bellinger }									\
374e48354ceSNicholas Bellinger 									\
375e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_attrib_store_##name(				\
376e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl,					\
377e48354ceSNicholas Bellinger 	const char *page,						\
378e48354ceSNicholas Bellinger 	size_t count)							\
379e48354ceSNicholas Bellinger {									\
380e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
381e48354ceSNicholas Bellinger 					se_node_acl);			\
382e48354ceSNicholas Bellinger 	u32 val;							\
383e48354ceSNicholas Bellinger 	int ret;							\
384e48354ceSNicholas Bellinger 									\
385ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &val);					\
386ad7babd2SJörn Engel 	if (ret)							\
387ad7babd2SJörn Engel 		return ret;						\
388e48354ceSNicholas Bellinger 	ret = iscsit_na_##name(nacl, val);				\
389e48354ceSNicholas Bellinger 	if (ret < 0)							\
390e48354ceSNicholas Bellinger 		return ret;						\
391e48354ceSNicholas Bellinger 									\
392e48354ceSNicholas Bellinger 	return count;							\
393e48354ceSNicholas Bellinger }
394e48354ceSNicholas Bellinger 
395e48354ceSNicholas Bellinger #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode);
396e48354ceSNicholas Bellinger /*
397e48354ceSNicholas Bellinger  * Define iscsi_node_attrib_s_dataout_timeout
398e48354ceSNicholas Bellinger  */
399e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(dataout_timeout);
400e48354ceSNicholas Bellinger NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR);
401e48354ceSNicholas Bellinger /*
402e48354ceSNicholas Bellinger  * Define iscsi_node_attrib_s_dataout_timeout_retries
403e48354ceSNicholas Bellinger  */
404e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(dataout_timeout_retries);
405e48354ceSNicholas Bellinger NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR);
406e48354ceSNicholas Bellinger /*
407e48354ceSNicholas Bellinger  * Define iscsi_node_attrib_s_default_erl
408e48354ceSNicholas Bellinger  */
409e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(default_erl);
410e48354ceSNicholas Bellinger NACL_ATTR(default_erl, S_IRUGO | S_IWUSR);
411e48354ceSNicholas Bellinger /*
412e48354ceSNicholas Bellinger  * Define iscsi_node_attrib_s_nopin_timeout
413e48354ceSNicholas Bellinger  */
414e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(nopin_timeout);
415e48354ceSNicholas Bellinger NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR);
416e48354ceSNicholas Bellinger /*
417e48354ceSNicholas Bellinger  * Define iscsi_node_attrib_s_nopin_response_timeout
418e48354ceSNicholas Bellinger  */
419e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(nopin_response_timeout);
420e48354ceSNicholas Bellinger NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR);
421e48354ceSNicholas Bellinger /*
422e48354ceSNicholas Bellinger  * Define iscsi_node_attrib_s_random_datain_pdu_offsets
423e48354ceSNicholas Bellinger  */
424e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(random_datain_pdu_offsets);
425e48354ceSNicholas Bellinger NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR);
426e48354ceSNicholas Bellinger /*
427e48354ceSNicholas Bellinger  * Define iscsi_node_attrib_s_random_datain_seq_offsets
428e48354ceSNicholas Bellinger  */
429e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(random_datain_seq_offsets);
430e48354ceSNicholas Bellinger NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR);
431e48354ceSNicholas Bellinger /*
432e48354ceSNicholas Bellinger  * Define iscsi_node_attrib_s_random_r2t_offsets
433e48354ceSNicholas Bellinger  */
434e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(random_r2t_offsets);
435e48354ceSNicholas Bellinger NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR);
436e48354ceSNicholas Bellinger 
437e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
438e48354ceSNicholas Bellinger 	&iscsi_nacl_attrib_dataout_timeout.attr,
439e48354ceSNicholas Bellinger 	&iscsi_nacl_attrib_dataout_timeout_retries.attr,
440e48354ceSNicholas Bellinger 	&iscsi_nacl_attrib_default_erl.attr,
441e48354ceSNicholas Bellinger 	&iscsi_nacl_attrib_nopin_timeout.attr,
442e48354ceSNicholas Bellinger 	&iscsi_nacl_attrib_nopin_response_timeout.attr,
443e48354ceSNicholas Bellinger 	&iscsi_nacl_attrib_random_datain_pdu_offsets.attr,
444e48354ceSNicholas Bellinger 	&iscsi_nacl_attrib_random_datain_seq_offsets.attr,
445e48354ceSNicholas Bellinger 	&iscsi_nacl_attrib_random_r2t_offsets.attr,
446e48354ceSNicholas Bellinger 	NULL,
447e48354ceSNicholas Bellinger };
448e48354ceSNicholas Bellinger 
449e48354ceSNicholas Bellinger /* End items for lio_target_nacl_attrib_cit */
450e48354ceSNicholas Bellinger 
451e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_auth_cit */
452e48354ceSNicholas Bellinger 
453e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_STR(prefix, name, flags)			\
454e48354ceSNicholas Bellinger static ssize_t __iscsi_##prefix##_show_##name(				\
455e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
456e48354ceSNicholas Bellinger 	char *page)							\
457e48354ceSNicholas Bellinger {									\
458e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
459e48354ceSNicholas Bellinger 									\
460e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
461e48354ceSNicholas Bellinger 		return -EPERM;						\
462e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", auth->name);		\
463e48354ceSNicholas Bellinger }									\
464e48354ceSNicholas Bellinger 									\
465e48354ceSNicholas Bellinger static ssize_t __iscsi_##prefix##_store_##name(				\
466e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
467e48354ceSNicholas Bellinger 	const char *page,						\
468e48354ceSNicholas Bellinger 	size_t count)							\
469e48354ceSNicholas Bellinger {									\
470e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
471e48354ceSNicholas Bellinger 									\
472e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
473e48354ceSNicholas Bellinger 		return -EPERM;						\
4742306bfb2SEric Seppanen 	if (count >= sizeof(auth->name))				\
4752306bfb2SEric Seppanen 		return -EINVAL;						\
4760fbfc46fSJörn Engel 	snprintf(auth->name, sizeof(auth->name), "%s", page);		\
477e48354ceSNicholas Bellinger 	if (!strncmp("NULL", auth->name, 4))				\
478e48354ceSNicholas Bellinger 		auth->naf_flags &= ~flags;				\
479e48354ceSNicholas Bellinger 	else								\
480e48354ceSNicholas Bellinger 		auth->naf_flags |= flags;				\
481e48354ceSNicholas Bellinger 									\
482e48354ceSNicholas Bellinger 	if ((auth->naf_flags & NAF_USERID_IN_SET) &&			\
483e48354ceSNicholas Bellinger 	    (auth->naf_flags & NAF_PASSWORD_IN_SET))			\
484e48354ceSNicholas Bellinger 		auth->authenticate_target = 1;				\
485e48354ceSNicholas Bellinger 	else								\
486e48354ceSNicholas Bellinger 		auth->authenticate_target = 0;				\
487e48354ceSNicholas Bellinger 									\
488e48354ceSNicholas Bellinger 	return count;							\
489e48354ceSNicholas Bellinger }
490e48354ceSNicholas Bellinger 
491e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_INT(prefix, name)				\
492e48354ceSNicholas Bellinger static ssize_t __iscsi_##prefix##_show_##name(				\
493e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
494e48354ceSNicholas Bellinger 	char *page)							\
495e48354ceSNicholas Bellinger {									\
496e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
497e48354ceSNicholas Bellinger 									\
498e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
499e48354ceSNicholas Bellinger 		return -EPERM;						\
500e48354ceSNicholas Bellinger 									\
501e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%d\n", auth->name);		\
502e48354ceSNicholas Bellinger }
503e48354ceSNicholas Bellinger 
504e48354ceSNicholas Bellinger #define DEF_NACL_AUTH_STR(name, flags)					\
505e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_STR(nacl_auth, name, flags)			\
506e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_auth_show_##name(				\
507e48354ceSNicholas Bellinger 	struct se_node_acl *nacl,					\
508e48354ceSNicholas Bellinger 	char *page)							\
509e48354ceSNicholas Bellinger {									\
510e48354ceSNicholas Bellinger 	return __iscsi_nacl_auth_show_##name(container_of(nacl,		\
511e48354ceSNicholas Bellinger 			struct iscsi_node_acl, se_node_acl), page);		\
512e48354ceSNicholas Bellinger }									\
513e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_auth_store_##name(				\
514e48354ceSNicholas Bellinger 	struct se_node_acl *nacl,					\
515e48354ceSNicholas Bellinger 	const char *page,						\
516e48354ceSNicholas Bellinger 	size_t count)							\
517e48354ceSNicholas Bellinger {									\
518e48354ceSNicholas Bellinger 	return __iscsi_nacl_auth_store_##name(container_of(nacl,	\
519e48354ceSNicholas Bellinger 			struct iscsi_node_acl, se_node_acl), page, count);	\
520e48354ceSNicholas Bellinger }
521e48354ceSNicholas Bellinger 
522e48354ceSNicholas Bellinger #define DEF_NACL_AUTH_INT(name)						\
523e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_INT(nacl_auth, name)				\
524e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_auth_show_##name(				\
525e48354ceSNicholas Bellinger 	struct se_node_acl *nacl,					\
526e48354ceSNicholas Bellinger 	char *page)							\
527e48354ceSNicholas Bellinger {									\
528e48354ceSNicholas Bellinger 	return __iscsi_nacl_auth_show_##name(container_of(nacl,		\
529e48354ceSNicholas Bellinger 			struct iscsi_node_acl, se_node_acl), page);		\
530e48354ceSNicholas Bellinger }
531e48354ceSNicholas Bellinger 
532e48354ceSNicholas Bellinger #define AUTH_ATTR(_name, _mode)	TF_NACL_AUTH_ATTR(iscsi, _name, _mode);
533e48354ceSNicholas Bellinger #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name);
534e48354ceSNicholas Bellinger 
535e48354ceSNicholas Bellinger /*
536e48354ceSNicholas Bellinger  * One-way authentication userid
537e48354ceSNicholas Bellinger  */
538e48354ceSNicholas Bellinger DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
539e48354ceSNicholas Bellinger AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
540e48354ceSNicholas Bellinger /*
541e48354ceSNicholas Bellinger  * One-way authentication password
542e48354ceSNicholas Bellinger  */
543e48354ceSNicholas Bellinger DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
544e48354ceSNicholas Bellinger AUTH_ATTR(password, S_IRUGO | S_IWUSR);
545e48354ceSNicholas Bellinger /*
546e48354ceSNicholas Bellinger  * Enforce mutual authentication
547e48354ceSNicholas Bellinger  */
548e48354ceSNicholas Bellinger DEF_NACL_AUTH_INT(authenticate_target);
549e48354ceSNicholas Bellinger AUTH_ATTR_RO(authenticate_target);
550e48354ceSNicholas Bellinger /*
551e48354ceSNicholas Bellinger  * Mutual authentication userid
552e48354ceSNicholas Bellinger  */
553e48354ceSNicholas Bellinger DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
554e48354ceSNicholas Bellinger AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
555e48354ceSNicholas Bellinger /*
556e48354ceSNicholas Bellinger  * Mutual authentication password
557e48354ceSNicholas Bellinger  */
558e48354ceSNicholas Bellinger DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
559e48354ceSNicholas Bellinger AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
560e48354ceSNicholas Bellinger 
561e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
562e48354ceSNicholas Bellinger 	&iscsi_nacl_auth_userid.attr,
563e48354ceSNicholas Bellinger 	&iscsi_nacl_auth_password.attr,
564e48354ceSNicholas Bellinger 	&iscsi_nacl_auth_authenticate_target.attr,
565e48354ceSNicholas Bellinger 	&iscsi_nacl_auth_userid_mutual.attr,
566e48354ceSNicholas Bellinger 	&iscsi_nacl_auth_password_mutual.attr,
567e48354ceSNicholas Bellinger 	NULL,
568e48354ceSNicholas Bellinger };
569e48354ceSNicholas Bellinger 
570e48354ceSNicholas Bellinger /* End items for lio_target_nacl_auth_cit */
571e48354ceSNicholas Bellinger 
572e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_param_cit */
573e48354ceSNicholas Bellinger 
574e48354ceSNicholas Bellinger #define DEF_NACL_PARAM(name)						\
575e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_param_show_##name(				\
576e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl,					\
577e48354ceSNicholas Bellinger 	char *page)							\
578e48354ceSNicholas Bellinger {									\
579e48354ceSNicholas Bellinger 	struct iscsi_session *sess;					\
580e48354ceSNicholas Bellinger 	struct se_session *se_sess;					\
581e48354ceSNicholas Bellinger 	ssize_t rb;							\
582e48354ceSNicholas Bellinger 									\
583e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);				\
584e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;					\
585e48354ceSNicholas Bellinger 	if (!se_sess) {							\
586e48354ceSNicholas Bellinger 		rb = snprintf(page, PAGE_SIZE,				\
587e48354ceSNicholas Bellinger 			"No Active iSCSI Session\n");			\
588e48354ceSNicholas Bellinger 	} else {							\
589e48354ceSNicholas Bellinger 		sess = se_sess->fabric_sess_ptr;			\
590e48354ceSNicholas Bellinger 		rb = snprintf(page, PAGE_SIZE, "%u\n",			\
591e48354ceSNicholas Bellinger 			(u32)sess->sess_ops->name);			\
592e48354ceSNicholas Bellinger 	}								\
593e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);			\
594e48354ceSNicholas Bellinger 									\
595e48354ceSNicholas Bellinger 	return rb;							\
596e48354ceSNicholas Bellinger }
597e48354ceSNicholas Bellinger 
598e48354ceSNicholas Bellinger #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name);
599e48354ceSNicholas Bellinger 
600e48354ceSNicholas Bellinger DEF_NACL_PARAM(MaxConnections);
601e48354ceSNicholas Bellinger NACL_PARAM_ATTR(MaxConnections);
602e48354ceSNicholas Bellinger 
603e48354ceSNicholas Bellinger DEF_NACL_PARAM(InitialR2T);
604e48354ceSNicholas Bellinger NACL_PARAM_ATTR(InitialR2T);
605e48354ceSNicholas Bellinger 
606e48354ceSNicholas Bellinger DEF_NACL_PARAM(ImmediateData);
607e48354ceSNicholas Bellinger NACL_PARAM_ATTR(ImmediateData);
608e48354ceSNicholas Bellinger 
609e48354ceSNicholas Bellinger DEF_NACL_PARAM(MaxBurstLength);
610e48354ceSNicholas Bellinger NACL_PARAM_ATTR(MaxBurstLength);
611e48354ceSNicholas Bellinger 
612e48354ceSNicholas Bellinger DEF_NACL_PARAM(FirstBurstLength);
613e48354ceSNicholas Bellinger NACL_PARAM_ATTR(FirstBurstLength);
614e48354ceSNicholas Bellinger 
615e48354ceSNicholas Bellinger DEF_NACL_PARAM(DefaultTime2Wait);
616e48354ceSNicholas Bellinger NACL_PARAM_ATTR(DefaultTime2Wait);
617e48354ceSNicholas Bellinger 
618e48354ceSNicholas Bellinger DEF_NACL_PARAM(DefaultTime2Retain);
619e48354ceSNicholas Bellinger NACL_PARAM_ATTR(DefaultTime2Retain);
620e48354ceSNicholas Bellinger 
621e48354ceSNicholas Bellinger DEF_NACL_PARAM(MaxOutstandingR2T);
622e48354ceSNicholas Bellinger NACL_PARAM_ATTR(MaxOutstandingR2T);
623e48354ceSNicholas Bellinger 
624e48354ceSNicholas Bellinger DEF_NACL_PARAM(DataPDUInOrder);
625e48354ceSNicholas Bellinger NACL_PARAM_ATTR(DataPDUInOrder);
626e48354ceSNicholas Bellinger 
627e48354ceSNicholas Bellinger DEF_NACL_PARAM(DataSequenceInOrder);
628e48354ceSNicholas Bellinger NACL_PARAM_ATTR(DataSequenceInOrder);
629e48354ceSNicholas Bellinger 
630e48354ceSNicholas Bellinger DEF_NACL_PARAM(ErrorRecoveryLevel);
631e48354ceSNicholas Bellinger NACL_PARAM_ATTR(ErrorRecoveryLevel);
632e48354ceSNicholas Bellinger 
633e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
634e48354ceSNicholas Bellinger 	&iscsi_nacl_param_MaxConnections.attr,
635e48354ceSNicholas Bellinger 	&iscsi_nacl_param_InitialR2T.attr,
636e48354ceSNicholas Bellinger 	&iscsi_nacl_param_ImmediateData.attr,
637e48354ceSNicholas Bellinger 	&iscsi_nacl_param_MaxBurstLength.attr,
638e48354ceSNicholas Bellinger 	&iscsi_nacl_param_FirstBurstLength.attr,
639e48354ceSNicholas Bellinger 	&iscsi_nacl_param_DefaultTime2Wait.attr,
640e48354ceSNicholas Bellinger 	&iscsi_nacl_param_DefaultTime2Retain.attr,
641e48354ceSNicholas Bellinger 	&iscsi_nacl_param_MaxOutstandingR2T.attr,
642e48354ceSNicholas Bellinger 	&iscsi_nacl_param_DataPDUInOrder.attr,
643e48354ceSNicholas Bellinger 	&iscsi_nacl_param_DataSequenceInOrder.attr,
644e48354ceSNicholas Bellinger 	&iscsi_nacl_param_ErrorRecoveryLevel.attr,
645e48354ceSNicholas Bellinger 	NULL,
646e48354ceSNicholas Bellinger };
647e48354ceSNicholas Bellinger 
648e48354ceSNicholas Bellinger /* End items for lio_target_nacl_param_cit */
649e48354ceSNicholas Bellinger 
650e48354ceSNicholas Bellinger /* Start items for lio_target_acl_cit */
651e48354ceSNicholas Bellinger 
652e48354ceSNicholas Bellinger static ssize_t lio_target_nacl_show_info(
653e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl,
654e48354ceSNicholas Bellinger 	char *page)
655e48354ceSNicholas Bellinger {
656e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
657e48354ceSNicholas Bellinger 	struct iscsi_conn *conn;
658e48354ceSNicholas Bellinger 	struct se_session *se_sess;
659e48354ceSNicholas Bellinger 	ssize_t rb = 0;
660e48354ceSNicholas Bellinger 
661e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
662e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
663e48354ceSNicholas Bellinger 	if (!se_sess) {
664e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
665e48354ceSNicholas Bellinger 			" Endpoint: %s\n", se_nacl->initiatorname);
666e48354ceSNicholas Bellinger 	} else {
667e48354ceSNicholas Bellinger 		sess = se_sess->fabric_sess_ptr;
668e48354ceSNicholas Bellinger 
669e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "InitiatorName: %s\n",
670e48354ceSNicholas Bellinger 			sess->sess_ops->InitiatorName);
671e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "InitiatorAlias: %s\n",
672e48354ceSNicholas Bellinger 			sess->sess_ops->InitiatorAlias);
673e48354ceSNicholas Bellinger 
6745cdf5a87SAndy Shevchenko 		rb += sprintf(page+rb,
6755cdf5a87SAndy Shevchenko 			      "LIO Session ID: %u   ISID: 0x%6ph  TSIH: %hu  ",
6765cdf5a87SAndy Shevchenko 			      sess->sid, sess->isid, sess->tsih);
677e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "SessionType: %s\n",
678e48354ceSNicholas Bellinger 				(sess->sess_ops->SessionType) ?
679e48354ceSNicholas Bellinger 				"Discovery" : "Normal");
680e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "Session State: ");
681e48354ceSNicholas Bellinger 		switch (sess->session_state) {
682e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_FREE:
683e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_FREE\n");
684e48354ceSNicholas Bellinger 			break;
685e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_ACTIVE:
686e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
687e48354ceSNicholas Bellinger 			break;
688e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_LOGGED_IN:
689e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
690e48354ceSNicholas Bellinger 			break;
691e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_FAILED:
692e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
693e48354ceSNicholas Bellinger 			break;
694e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_IN_CONTINUE:
695e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
696e48354ceSNicholas Bellinger 			break;
697e48354ceSNicholas Bellinger 		default:
698e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "ERROR: Unknown Session"
699e48354ceSNicholas Bellinger 					" State!\n");
700e48354ceSNicholas Bellinger 			break;
701e48354ceSNicholas Bellinger 		}
702e48354ceSNicholas Bellinger 
703e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "---------------------[iSCSI Session"
704e48354ceSNicholas Bellinger 				" Values]-----------------------\n");
705e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "  CmdSN/WR  :  CmdSN/WC  :  ExpCmdSN"
706e48354ceSNicholas Bellinger 				"  :  MaxCmdSN  :     ITT    :     TTT\n");
707e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, " 0x%08x   0x%08x   0x%08x   0x%08x"
708e48354ceSNicholas Bellinger 				"   0x%08x   0x%08x\n",
709e48354ceSNicholas Bellinger 			sess->cmdsn_window,
710e48354ceSNicholas Bellinger 			(sess->max_cmd_sn - sess->exp_cmd_sn) + 1,
711e48354ceSNicholas Bellinger 			sess->exp_cmd_sn, sess->max_cmd_sn,
712e48354ceSNicholas Bellinger 			sess->init_task_tag, sess->targ_xfer_tag);
713e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "----------------------[iSCSI"
714e48354ceSNicholas Bellinger 				" Connections]-------------------------\n");
715e48354ceSNicholas Bellinger 
716e48354ceSNicholas Bellinger 		spin_lock(&sess->conn_lock);
717e48354ceSNicholas Bellinger 		list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
718e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "CID: %hu  Connection"
719e48354ceSNicholas Bellinger 					" State: ", conn->cid);
720e48354ceSNicholas Bellinger 			switch (conn->conn_state) {
721e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_FREE:
722e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
723e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_FREE\n");
724e48354ceSNicholas Bellinger 				break;
725e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_XPT_UP:
726e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
727e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_XPT_UP\n");
728e48354ceSNicholas Bellinger 				break;
729e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_IN_LOGIN:
730e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
731e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_IN_LOGIN\n");
732e48354ceSNicholas Bellinger 				break;
733e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_LOGGED_IN:
734e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
735e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_LOGGED_IN\n");
736e48354ceSNicholas Bellinger 				break;
737e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_IN_LOGOUT:
738e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
739e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_IN_LOGOUT\n");
740e48354ceSNicholas Bellinger 				break;
741e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_LOGOUT_REQUESTED:
742e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
743e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_LOGOUT_REQUESTED\n");
744e48354ceSNicholas Bellinger 				break;
745e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_CLEANUP_WAIT:
746e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
747e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_CLEANUP_WAIT\n");
748e48354ceSNicholas Bellinger 				break;
749e48354ceSNicholas Bellinger 			default:
750e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
751e48354ceSNicholas Bellinger 					"ERROR: Unknown Connection State!\n");
752e48354ceSNicholas Bellinger 				break;
753e48354ceSNicholas Bellinger 			}
754e48354ceSNicholas Bellinger 
755e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "   Address %s %s", conn->login_ip,
756e48354ceSNicholas Bellinger 				(conn->network_transport == ISCSI_TCP) ?
757e48354ceSNicholas Bellinger 				"TCP" : "SCTP");
758e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "  StatSN: 0x%08x\n",
759e48354ceSNicholas Bellinger 				conn->stat_sn);
760e48354ceSNicholas Bellinger 		}
761e48354ceSNicholas Bellinger 		spin_unlock(&sess->conn_lock);
762e48354ceSNicholas Bellinger 	}
763e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
764e48354ceSNicholas Bellinger 
765e48354ceSNicholas Bellinger 	return rb;
766e48354ceSNicholas Bellinger }
767e48354ceSNicholas Bellinger 
768e48354ceSNicholas Bellinger TF_NACL_BASE_ATTR_RO(lio_target, info);
769e48354ceSNicholas Bellinger 
770e48354ceSNicholas Bellinger static ssize_t lio_target_nacl_show_cmdsn_depth(
771e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl,
772e48354ceSNicholas Bellinger 	char *page)
773e48354ceSNicholas Bellinger {
774e48354ceSNicholas Bellinger 	return sprintf(page, "%u\n", se_nacl->queue_depth);
775e48354ceSNicholas Bellinger }
776e48354ceSNicholas Bellinger 
777e48354ceSNicholas Bellinger static ssize_t lio_target_nacl_store_cmdsn_depth(
778e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl,
779e48354ceSNicholas Bellinger 	const char *page,
780e48354ceSNicholas Bellinger 	size_t count)
781e48354ceSNicholas Bellinger {
782e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg = se_nacl->se_tpg;
783e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,
784e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);
785e48354ceSNicholas Bellinger 	struct config_item *acl_ci, *tpg_ci, *wwn_ci;
786e48354ceSNicholas Bellinger 	u32 cmdsn_depth = 0;
787e48354ceSNicholas Bellinger 	int ret;
788e48354ceSNicholas Bellinger 
789ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &cmdsn_depth);
790ad7babd2SJörn Engel 	if (ret)
791ad7babd2SJörn Engel 		return ret;
792e48354ceSNicholas Bellinger 	if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
793e48354ceSNicholas Bellinger 		pr_err("Passed cmdsn_depth: %u exceeds"
794e48354ceSNicholas Bellinger 			" TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
795e48354ceSNicholas Bellinger 			TA_DEFAULT_CMDSN_DEPTH_MAX);
796e48354ceSNicholas Bellinger 		return -EINVAL;
797e48354ceSNicholas Bellinger 	}
798e48354ceSNicholas Bellinger 	acl_ci = &se_nacl->acl_group.cg_item;
799e48354ceSNicholas Bellinger 	if (!acl_ci) {
800e48354ceSNicholas Bellinger 		pr_err("Unable to locatel acl_ci\n");
801e48354ceSNicholas Bellinger 		return -EINVAL;
802e48354ceSNicholas Bellinger 	}
803e48354ceSNicholas Bellinger 	tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
804e48354ceSNicholas Bellinger 	if (!tpg_ci) {
805e48354ceSNicholas Bellinger 		pr_err("Unable to locate tpg_ci\n");
806e48354ceSNicholas Bellinger 		return -EINVAL;
807e48354ceSNicholas Bellinger 	}
808e48354ceSNicholas Bellinger 	wwn_ci = &tpg_ci->ci_group->cg_item;
809e48354ceSNicholas Bellinger 	if (!wwn_ci) {
810e48354ceSNicholas Bellinger 		pr_err("Unable to locate config_item wwn_ci\n");
811e48354ceSNicholas Bellinger 		return -EINVAL;
812e48354ceSNicholas Bellinger 	}
813e48354ceSNicholas Bellinger 
814e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)
815e48354ceSNicholas Bellinger 		return -EINVAL;
816e48354ceSNicholas Bellinger 	/*
817e48354ceSNicholas Bellinger 	 * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1
818e48354ceSNicholas Bellinger 	 */
819e48354ceSNicholas Bellinger 	ret = iscsit_tpg_set_initiator_node_queue_depth(tpg,
820e48354ceSNicholas Bellinger 				config_item_name(acl_ci), cmdsn_depth, 1);
821e48354ceSNicholas Bellinger 
822e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
823e48354ceSNicholas Bellinger 		"InitiatorName: %s\n", config_item_name(wwn_ci),
824e48354ceSNicholas Bellinger 		config_item_name(tpg_ci), cmdsn_depth,
825e48354ceSNicholas Bellinger 		config_item_name(acl_ci));
826e48354ceSNicholas Bellinger 
827e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
828e48354ceSNicholas Bellinger 	return (!ret) ? count : (ssize_t)ret;
829e48354ceSNicholas Bellinger }
830e48354ceSNicholas Bellinger 
831e48354ceSNicholas Bellinger TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR);
832e48354ceSNicholas Bellinger 
83379e62fc3SAndy Grover static ssize_t lio_target_nacl_show_tag(
83479e62fc3SAndy Grover 	struct se_node_acl *se_nacl,
83579e62fc3SAndy Grover 	char *page)
83679e62fc3SAndy Grover {
83779e62fc3SAndy Grover 	return snprintf(page, PAGE_SIZE, "%s", se_nacl->acl_tag);
83879e62fc3SAndy Grover }
83979e62fc3SAndy Grover 
84079e62fc3SAndy Grover static ssize_t lio_target_nacl_store_tag(
84179e62fc3SAndy Grover 	struct se_node_acl *se_nacl,
84279e62fc3SAndy Grover 	const char *page,
84379e62fc3SAndy Grover 	size_t count)
84479e62fc3SAndy Grover {
84579e62fc3SAndy Grover 	int ret;
84679e62fc3SAndy Grover 
84779e62fc3SAndy Grover 	ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
84879e62fc3SAndy Grover 
84979e62fc3SAndy Grover 	if (ret < 0)
85079e62fc3SAndy Grover 		return ret;
85179e62fc3SAndy Grover 	return count;
85279e62fc3SAndy Grover }
85379e62fc3SAndy Grover 
85479e62fc3SAndy Grover TF_NACL_BASE_ATTR(lio_target, tag, S_IRUGO | S_IWUSR);
85579e62fc3SAndy Grover 
856e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_initiator_attrs[] = {
857e48354ceSNicholas Bellinger 	&lio_target_nacl_info.attr,
858e48354ceSNicholas Bellinger 	&lio_target_nacl_cmdsn_depth.attr,
85979e62fc3SAndy Grover 	&lio_target_nacl_tag.attr,
860e48354ceSNicholas Bellinger 	NULL,
861e48354ceSNicholas Bellinger };
862e48354ceSNicholas Bellinger 
863e48354ceSNicholas Bellinger static struct se_node_acl *lio_tpg_alloc_fabric_acl(
864e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg)
865e48354ceSNicholas Bellinger {
866e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl;
867e48354ceSNicholas Bellinger 
868e48354ceSNicholas Bellinger 	acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL);
869e48354ceSNicholas Bellinger 	if (!acl) {
870e48354ceSNicholas Bellinger 		pr_err("Unable to allocate memory for struct iscsi_node_acl\n");
871e48354ceSNicholas Bellinger 		return NULL;
872e48354ceSNicholas Bellinger 	}
873e48354ceSNicholas Bellinger 
874e48354ceSNicholas Bellinger 	return &acl->se_node_acl;
875e48354ceSNicholas Bellinger }
876e48354ceSNicholas Bellinger 
877c7d6a803SChristoph Hellwig static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
878e48354ceSNicholas Bellinger 		const char *name)
879e48354ceSNicholas Bellinger {
880c7d6a803SChristoph Hellwig 	struct iscsi_node_acl *acl =
881c7d6a803SChristoph Hellwig 		container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
882c7d6a803SChristoph Hellwig 	struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group;
883e48354ceSNicholas Bellinger 
88413f6a914SSebastian Andrzej Siewior 	stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
885e48354ceSNicholas Bellinger 				GFP_KERNEL);
886e48354ceSNicholas Bellinger 	if (!stats_cg->default_groups) {
887e48354ceSNicholas Bellinger 		pr_err("Unable to allocate memory for"
888e48354ceSNicholas Bellinger 				" stats_cg->default_groups\n");
889c7d6a803SChristoph Hellwig 		return -ENOMEM;
890e48354ceSNicholas Bellinger 	}
891e48354ceSNicholas Bellinger 
892b7eec2cdSAndy Grover 	stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group;
893e48354ceSNicholas Bellinger 	stats_cg->default_groups[1] = NULL;
894b7eec2cdSAndy Grover 	config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
895e48354ceSNicholas Bellinger 			"iscsi_sess_stats", &iscsi_stat_sess_cit);
896e48354ceSNicholas Bellinger 
897c7d6a803SChristoph Hellwig 	return 0;
898e48354ceSNicholas Bellinger }
899e48354ceSNicholas Bellinger 
900c7d6a803SChristoph Hellwig static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl)
901e48354ceSNicholas Bellinger {
902e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(se_nacl,
903e48354ceSNicholas Bellinger 			struct iscsi_node_acl, se_node_acl);
904e48354ceSNicholas Bellinger 	struct config_item *df_item;
905e48354ceSNicholas Bellinger 	struct config_group *stats_cg;
906e48354ceSNicholas Bellinger 	int i;
907e48354ceSNicholas Bellinger 
908e48354ceSNicholas Bellinger 	stats_cg = &acl->se_node_acl.acl_fabric_stat_group;
909e48354ceSNicholas Bellinger 	for (i = 0; stats_cg->default_groups[i]; i++) {
910e48354ceSNicholas Bellinger 		df_item = &stats_cg->default_groups[i]->cg_item;
911e48354ceSNicholas Bellinger 		stats_cg->default_groups[i] = NULL;
912e48354ceSNicholas Bellinger 		config_item_put(df_item);
913e48354ceSNicholas Bellinger 	}
914e48354ceSNicholas Bellinger 	kfree(stats_cg->default_groups);
915e48354ceSNicholas Bellinger }
916e48354ceSNicholas Bellinger 
917e48354ceSNicholas Bellinger /* End items for lio_target_acl_cit */
918e48354ceSNicholas Bellinger 
919e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_attrib_cit */
920e48354ceSNicholas Bellinger 
921e48354ceSNicholas Bellinger #define DEF_TPG_ATTRIB(name)						\
922e48354ceSNicholas Bellinger 									\
923e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_attrib_show_##name(				\
924e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,				\
925e48354ceSNicholas Bellinger 	char *page)							\
926e48354ceSNicholas Bellinger {									\
927e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
928e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);	\
929e48354ceSNicholas Bellinger 	ssize_t rb;							\
930e48354ceSNicholas Bellinger 									\
931e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
932e48354ceSNicholas Bellinger 		return -EINVAL;						\
933e48354ceSNicholas Bellinger 									\
934b7eec2cdSAndy Grover 	rb = sprintf(page, "%u\n", tpg->tpg_attrib.name);		\
935e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
936e48354ceSNicholas Bellinger 	return rb;							\
937e48354ceSNicholas Bellinger }									\
938e48354ceSNicholas Bellinger 									\
939e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_attrib_store_##name(				\
940e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,				\
941e48354ceSNicholas Bellinger 	const char *page,						\
942e48354ceSNicholas Bellinger 	size_t count)							\
943e48354ceSNicholas Bellinger {									\
944e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
945e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);	\
946e48354ceSNicholas Bellinger 	u32 val;							\
947e48354ceSNicholas Bellinger 	int ret;							\
948e48354ceSNicholas Bellinger 									\
949e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
950e48354ceSNicholas Bellinger 		return -EINVAL;						\
951e48354ceSNicholas Bellinger 									\
952ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &val);					\
953ad7babd2SJörn Engel 	if (ret)							\
954ad7babd2SJörn Engel 		goto out;						\
955e48354ceSNicholas Bellinger 	ret = iscsit_ta_##name(tpg, val);				\
956e48354ceSNicholas Bellinger 	if (ret < 0)							\
957e48354ceSNicholas Bellinger 		goto out;						\
958e48354ceSNicholas Bellinger 									\
959e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
960e48354ceSNicholas Bellinger 	return count;							\
961e48354ceSNicholas Bellinger out:									\
962e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
963e48354ceSNicholas Bellinger 	return ret;							\
964e48354ceSNicholas Bellinger }
965e48354ceSNicholas Bellinger 
966e48354ceSNicholas Bellinger #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
967e48354ceSNicholas Bellinger 
968e48354ceSNicholas Bellinger /*
969e48354ceSNicholas Bellinger  * Define iscsi_tpg_attrib_s_authentication
970e48354ceSNicholas Bellinger  */
971e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(authentication);
972e48354ceSNicholas Bellinger TPG_ATTR(authentication, S_IRUGO | S_IWUSR);
973e48354ceSNicholas Bellinger /*
974e48354ceSNicholas Bellinger  * Define iscsi_tpg_attrib_s_login_timeout
975e48354ceSNicholas Bellinger  */
976e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(login_timeout);
977e48354ceSNicholas Bellinger TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR);
978e48354ceSNicholas Bellinger /*
979e48354ceSNicholas Bellinger  * Define iscsi_tpg_attrib_s_netif_timeout
980e48354ceSNicholas Bellinger  */
981e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(netif_timeout);
982e48354ceSNicholas Bellinger TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR);
983e48354ceSNicholas Bellinger /*
984e48354ceSNicholas Bellinger  * Define iscsi_tpg_attrib_s_generate_node_acls
985e48354ceSNicholas Bellinger  */
986e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(generate_node_acls);
987e48354ceSNicholas Bellinger TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
988e48354ceSNicholas Bellinger /*
989e48354ceSNicholas Bellinger  * Define iscsi_tpg_attrib_s_default_cmdsn_depth
990e48354ceSNicholas Bellinger  */
991e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(default_cmdsn_depth);
992e48354ceSNicholas Bellinger TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR);
993e48354ceSNicholas Bellinger /*
994e48354ceSNicholas Bellinger  Define iscsi_tpg_attrib_s_cache_dynamic_acls
995e48354ceSNicholas Bellinger  */
996e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(cache_dynamic_acls);
997e48354ceSNicholas Bellinger TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
998e48354ceSNicholas Bellinger /*
999e48354ceSNicholas Bellinger  * Define iscsi_tpg_attrib_s_demo_mode_write_protect
1000e48354ceSNicholas Bellinger  */
1001e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(demo_mode_write_protect);
1002e48354ceSNicholas Bellinger TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
1003e48354ceSNicholas Bellinger /*
1004e48354ceSNicholas Bellinger  * Define iscsi_tpg_attrib_s_prod_mode_write_protect
1005e48354ceSNicholas Bellinger  */
1006e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(prod_mode_write_protect);
1007e48354ceSNicholas Bellinger TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
10084c54b6cfSThomas Glanzmann /*
10094c54b6cfSThomas Glanzmann  * Define iscsi_tpg_attrib_s_demo_mode_discovery,
10104c54b6cfSThomas Glanzmann  */
10114c54b6cfSThomas Glanzmann DEF_TPG_ATTRIB(demo_mode_discovery);
10124c54b6cfSThomas Glanzmann TPG_ATTR(demo_mode_discovery, S_IRUGO | S_IWUSR);
1013d1fa7a1dSNicholas Bellinger /*
1014d1fa7a1dSNicholas Bellinger  * Define iscsi_tpg_attrib_s_default_erl
1015d1fa7a1dSNicholas Bellinger  */
1016d1fa7a1dSNicholas Bellinger DEF_TPG_ATTRIB(default_erl);
1017d1fa7a1dSNicholas Bellinger TPG_ATTR(default_erl, S_IRUGO | S_IWUSR);
10188085176fSSagi Grimberg /*
10198085176fSSagi Grimberg  * Define iscsi_tpg_attrib_s_t10_pi
10208085176fSSagi Grimberg  */
10218085176fSSagi Grimberg DEF_TPG_ATTRIB(t10_pi);
10228085176fSSagi Grimberg TPG_ATTR(t10_pi, S_IRUGO | S_IWUSR);
1023901c04a3SNicholas Bellinger /*
1024901c04a3SNicholas Bellinger  * Define iscsi_tpg_attrib_s_fabric_prot_type
1025901c04a3SNicholas Bellinger  */
1026901c04a3SNicholas Bellinger DEF_TPG_ATTRIB(fabric_prot_type);
1027901c04a3SNicholas Bellinger TPG_ATTR(fabric_prot_type, S_IRUGO | S_IWUSR);
1028e48354ceSNicholas Bellinger 
1029e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
1030e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_authentication.attr,
1031e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_login_timeout.attr,
1032e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_netif_timeout.attr,
1033e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_generate_node_acls.attr,
1034e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_default_cmdsn_depth.attr,
1035e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_cache_dynamic_acls.attr,
1036e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_demo_mode_write_protect.attr,
1037e48354ceSNicholas Bellinger 	&iscsi_tpg_attrib_prod_mode_write_protect.attr,
10384c54b6cfSThomas Glanzmann 	&iscsi_tpg_attrib_demo_mode_discovery.attr,
1039d1fa7a1dSNicholas Bellinger 	&iscsi_tpg_attrib_default_erl.attr,
10408085176fSSagi Grimberg 	&iscsi_tpg_attrib_t10_pi.attr,
1041901c04a3SNicholas Bellinger 	&iscsi_tpg_attrib_fabric_prot_type.attr,
1042e48354ceSNicholas Bellinger 	NULL,
1043e48354ceSNicholas Bellinger };
1044e48354ceSNicholas Bellinger 
1045e48354ceSNicholas Bellinger /* End items for lio_target_tpg_attrib_cit */
1046e48354ceSNicholas Bellinger 
1047c3e51442SNicholas Bellinger /* Start items for lio_target_tpg_auth_cit */
1048c3e51442SNicholas Bellinger 
1049c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_STR(prefix, name, flags)					\
1050c3e51442SNicholas Bellinger static ssize_t __iscsi_##prefix##_show_##name(					\
1051c3e51442SNicholas Bellinger 	struct se_portal_group *se_tpg,						\
1052c3e51442SNicholas Bellinger 	char *page)								\
1053c3e51442SNicholas Bellinger {										\
1054c3e51442SNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
1055c3e51442SNicholas Bellinger 				struct iscsi_portal_group, tpg_se_tpg);		\
1056c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
1057c3e51442SNicholas Bellinger 										\
1058c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
1059c3e51442SNicholas Bellinger 		return -EPERM;							\
1060c3e51442SNicholas Bellinger 										\
1061c3e51442SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", auth->name);			\
1062c3e51442SNicholas Bellinger }										\
1063c3e51442SNicholas Bellinger 										\
1064c3e51442SNicholas Bellinger static ssize_t __iscsi_##prefix##_store_##name(					\
1065c3e51442SNicholas Bellinger 	struct se_portal_group *se_tpg,						\
1066c3e51442SNicholas Bellinger 	const char *page,							\
1067c3e51442SNicholas Bellinger 	size_t count)								\
1068c3e51442SNicholas Bellinger {										\
1069c3e51442SNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
1070c3e51442SNicholas Bellinger 				struct iscsi_portal_group, tpg_se_tpg);		\
1071c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
1072c3e51442SNicholas Bellinger 										\
1073c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
1074c3e51442SNicholas Bellinger 		return -EPERM;							\
1075c3e51442SNicholas Bellinger 										\
107637b32c6fSNicholas Bellinger 	snprintf(auth->name, sizeof(auth->name), "%s", page);			\
1077c3e51442SNicholas Bellinger 	if (!(strncmp("NULL", auth->name, 4)))					\
1078c3e51442SNicholas Bellinger 		auth->naf_flags &= ~flags;					\
1079c3e51442SNicholas Bellinger 	else									\
1080c3e51442SNicholas Bellinger 		auth->naf_flags |= flags;					\
1081c3e51442SNicholas Bellinger 										\
1082c3e51442SNicholas Bellinger 	if ((auth->naf_flags & NAF_USERID_IN_SET) &&				\
1083c3e51442SNicholas Bellinger 	    (auth->naf_flags & NAF_PASSWORD_IN_SET))				\
1084c3e51442SNicholas Bellinger 		auth->authenticate_target = 1;					\
1085c3e51442SNicholas Bellinger 	else									\
1086c3e51442SNicholas Bellinger 		auth->authenticate_target = 0;					\
1087c3e51442SNicholas Bellinger 										\
1088c3e51442SNicholas Bellinger 	return count;								\
1089c3e51442SNicholas Bellinger }
1090c3e51442SNicholas Bellinger 
1091c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_INT(prefix, name)					\
1092c3e51442SNicholas Bellinger static ssize_t __iscsi_##prefix##_show_##name(					\
1093c3e51442SNicholas Bellinger 	struct se_portal_group *se_tpg,						\
1094c3e51442SNicholas Bellinger 	char *page)								\
1095c3e51442SNicholas Bellinger {										\
1096c3e51442SNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
1097c3e51442SNicholas Bellinger 				struct iscsi_portal_group, tpg_se_tpg);		\
1098c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
1099c3e51442SNicholas Bellinger 										\
1100c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
1101c3e51442SNicholas Bellinger 		return -EPERM;							\
1102c3e51442SNicholas Bellinger 										\
1103c3e51442SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%d\n", auth->name);			\
1104c3e51442SNicholas Bellinger }
1105c3e51442SNicholas Bellinger 
1106c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_STR(name, flags)						\
1107c3e51442SNicholas Bellinger 	__DEF_TPG_AUTH_STR(tpg_auth, name, flags)				\
1108c3e51442SNicholas Bellinger static ssize_t iscsi_tpg_auth_show_##name(					\
1109c3e51442SNicholas Bellinger 	struct se_portal_group *se_tpg,						\
1110c3e51442SNicholas Bellinger 	char *page)								\
1111c3e51442SNicholas Bellinger {										\
1112c3e51442SNicholas Bellinger 	return __iscsi_tpg_auth_show_##name(se_tpg, page);			\
1113c3e51442SNicholas Bellinger }										\
1114c3e51442SNicholas Bellinger 										\
1115c3e51442SNicholas Bellinger static ssize_t iscsi_tpg_auth_store_##name(					\
1116c3e51442SNicholas Bellinger 	struct se_portal_group *se_tpg,						\
1117c3e51442SNicholas Bellinger 	const char *page,							\
1118c3e51442SNicholas Bellinger 	size_t count)								\
1119c3e51442SNicholas Bellinger {										\
1120c3e51442SNicholas Bellinger 	return __iscsi_tpg_auth_store_##name(se_tpg, page, count);		\
1121c3e51442SNicholas Bellinger }
1122c3e51442SNicholas Bellinger 
1123c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_INT(name)							\
1124c3e51442SNicholas Bellinger 	__DEF_TPG_AUTH_INT(tpg_auth, name)					\
1125c3e51442SNicholas Bellinger static ssize_t iscsi_tpg_auth_show_##name(					\
1126c3e51442SNicholas Bellinger 	struct se_portal_group *se_tpg,						\
1127c3e51442SNicholas Bellinger 	char *page)								\
1128c3e51442SNicholas Bellinger {										\
1129c3e51442SNicholas Bellinger 	return __iscsi_tpg_auth_show_##name(se_tpg, page);			\
1130c3e51442SNicholas Bellinger }
1131c3e51442SNicholas Bellinger 
1132c3e51442SNicholas Bellinger #define TPG_AUTH_ATTR(_name, _mode) TF_TPG_AUTH_ATTR(iscsi, _name, _mode);
1133c3e51442SNicholas Bellinger #define TPG_AUTH_ATTR_RO(_name) TF_TPG_AUTH_ATTR_RO(iscsi, _name);
1134c3e51442SNicholas Bellinger 
1135c3e51442SNicholas Bellinger /*
1136c3e51442SNicholas Bellinger  *  * One-way authentication userid
1137c3e51442SNicholas Bellinger  *   */
1138c3e51442SNicholas Bellinger DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
1139c3e51442SNicholas Bellinger TPG_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1140c3e51442SNicholas Bellinger /*
1141c3e51442SNicholas Bellinger  *  * One-way authentication password
1142c3e51442SNicholas Bellinger  *   */
1143c3e51442SNicholas Bellinger DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
1144c3e51442SNicholas Bellinger TPG_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1145c3e51442SNicholas Bellinger /*
1146c3e51442SNicholas Bellinger  *  * Enforce mutual authentication
1147c3e51442SNicholas Bellinger  *   */
1148c3e51442SNicholas Bellinger DEF_TPG_AUTH_INT(authenticate_target);
1149c3e51442SNicholas Bellinger TPG_AUTH_ATTR_RO(authenticate_target);
1150c3e51442SNicholas Bellinger /*
1151c3e51442SNicholas Bellinger  *  * Mutual authentication userid
1152c3e51442SNicholas Bellinger  *   */
1153c3e51442SNicholas Bellinger DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1154c3e51442SNicholas Bellinger TPG_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1155c3e51442SNicholas Bellinger /*
1156c3e51442SNicholas Bellinger  *  * Mutual authentication password
1157c3e51442SNicholas Bellinger  *   */
1158c3e51442SNicholas Bellinger DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1159c3e51442SNicholas Bellinger TPG_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1160c3e51442SNicholas Bellinger 
1161c3e51442SNicholas Bellinger static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
1162c3e51442SNicholas Bellinger 	&iscsi_tpg_auth_userid.attr,
1163c3e51442SNicholas Bellinger 	&iscsi_tpg_auth_password.attr,
1164c3e51442SNicholas Bellinger 	&iscsi_tpg_auth_authenticate_target.attr,
1165c3e51442SNicholas Bellinger 	&iscsi_tpg_auth_userid_mutual.attr,
1166c3e51442SNicholas Bellinger 	&iscsi_tpg_auth_password_mutual.attr,
1167c3e51442SNicholas Bellinger 	NULL,
1168c3e51442SNicholas Bellinger };
1169c3e51442SNicholas Bellinger 
1170c3e51442SNicholas Bellinger /* End items for lio_target_tpg_auth_cit */
1171c3e51442SNicholas Bellinger 
1172e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_param_cit */
1173e48354ceSNicholas Bellinger 
1174e48354ceSNicholas Bellinger #define DEF_TPG_PARAM(name)						\
1175e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_param_show_##name(				\
1176e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,					\
1177e48354ceSNicholas Bellinger 	char *page)							\
1178e48354ceSNicholas Bellinger {									\
1179e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
1180e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);		\
1181e48354ceSNicholas Bellinger 	struct iscsi_param *param;					\
1182e48354ceSNicholas Bellinger 	ssize_t rb;							\
1183e48354ceSNicholas Bellinger 									\
1184e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
1185e48354ceSNicholas Bellinger 		return -EINVAL;						\
1186e48354ceSNicholas Bellinger 									\
1187e48354ceSNicholas Bellinger 	param = iscsi_find_param_from_key(__stringify(name),		\
1188e48354ceSNicholas Bellinger 				tpg->param_list);			\
1189e48354ceSNicholas Bellinger 	if (!param) {							\
1190e48354ceSNicholas Bellinger 		iscsit_put_tpg(tpg);					\
1191e48354ceSNicholas Bellinger 		return -EINVAL;						\
1192e48354ceSNicholas Bellinger 	}								\
1193e48354ceSNicholas Bellinger 	rb = snprintf(page, PAGE_SIZE, "%s\n", param->value);		\
1194e48354ceSNicholas Bellinger 									\
1195e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
1196e48354ceSNicholas Bellinger 	return rb;							\
1197e48354ceSNicholas Bellinger }									\
1198e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_param_store_##name(				\
1199e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,				\
1200e48354ceSNicholas Bellinger 	const char *page,						\
1201e48354ceSNicholas Bellinger 	size_t count)							\
1202e48354ceSNicholas Bellinger {									\
1203e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
1204e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);		\
1205e48354ceSNicholas Bellinger 	char *buf;							\
1206ad7babd2SJörn Engel 	int ret, len;							\
1207e48354ceSNicholas Bellinger 									\
1208e48354ceSNicholas Bellinger 	buf = kzalloc(PAGE_SIZE, GFP_KERNEL);				\
1209e48354ceSNicholas Bellinger 	if (!buf)							\
1210e48354ceSNicholas Bellinger 		return -ENOMEM;						\
1211ad7babd2SJörn Engel 	len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page);	\
1212ad7babd2SJörn Engel 	if (isspace(buf[len-1]))					\
1213ad7babd2SJörn Engel 		buf[len-1] = '\0'; /* Kill newline */			\
1214e48354ceSNicholas Bellinger 									\
1215e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0) {					\
1216e48354ceSNicholas Bellinger 		kfree(buf);						\
1217e48354ceSNicholas Bellinger 		return -EINVAL;						\
1218e48354ceSNicholas Bellinger 	}								\
1219e48354ceSNicholas Bellinger 									\
1220e48354ceSNicholas Bellinger 	ret = iscsi_change_param_value(buf, tpg->param_list, 1);	\
1221e48354ceSNicholas Bellinger 	if (ret < 0)							\
1222e48354ceSNicholas Bellinger 		goto out;						\
1223e48354ceSNicholas Bellinger 									\
1224e48354ceSNicholas Bellinger 	kfree(buf);							\
1225e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
1226e48354ceSNicholas Bellinger 	return count;							\
1227e48354ceSNicholas Bellinger out:									\
1228e48354ceSNicholas Bellinger 	kfree(buf);							\
1229e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
1230e48354ceSNicholas Bellinger 	return -EINVAL;						\
1231e48354ceSNicholas Bellinger }
1232e48354ceSNicholas Bellinger 
1233e48354ceSNicholas Bellinger #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1234e48354ceSNicholas Bellinger 
1235e48354ceSNicholas Bellinger DEF_TPG_PARAM(AuthMethod);
1236e48354ceSNicholas Bellinger TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR);
1237e48354ceSNicholas Bellinger 
1238e48354ceSNicholas Bellinger DEF_TPG_PARAM(HeaderDigest);
1239e48354ceSNicholas Bellinger TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR);
1240e48354ceSNicholas Bellinger 
1241e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataDigest);
1242e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR);
1243e48354ceSNicholas Bellinger 
1244e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxConnections);
1245e48354ceSNicholas Bellinger TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR);
1246e48354ceSNicholas Bellinger 
1247e48354ceSNicholas Bellinger DEF_TPG_PARAM(TargetAlias);
1248e48354ceSNicholas Bellinger TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR);
1249e48354ceSNicholas Bellinger 
1250e48354ceSNicholas Bellinger DEF_TPG_PARAM(InitialR2T);
1251e48354ceSNicholas Bellinger TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR);
1252e48354ceSNicholas Bellinger 
1253e48354ceSNicholas Bellinger DEF_TPG_PARAM(ImmediateData);
1254e48354ceSNicholas Bellinger TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR);
1255e48354ceSNicholas Bellinger 
1256e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1257e48354ceSNicholas Bellinger TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR);
1258e48354ceSNicholas Bellinger 
1259e004cb25SNicholas Bellinger DEF_TPG_PARAM(MaxXmitDataSegmentLength);
1260e004cb25SNicholas Bellinger TPG_PARAM_ATTR(MaxXmitDataSegmentLength, S_IRUGO | S_IWUSR);
1261e004cb25SNicholas Bellinger 
1262e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxBurstLength);
1263e48354ceSNicholas Bellinger TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR);
1264e48354ceSNicholas Bellinger 
1265e48354ceSNicholas Bellinger DEF_TPG_PARAM(FirstBurstLength);
1266e48354ceSNicholas Bellinger TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR);
1267e48354ceSNicholas Bellinger 
1268e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Wait);
1269e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR);
1270e48354ceSNicholas Bellinger 
1271e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Retain);
1272e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR);
1273e48354ceSNicholas Bellinger 
1274e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxOutstandingR2T);
1275e48354ceSNicholas Bellinger TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR);
1276e48354ceSNicholas Bellinger 
1277e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataPDUInOrder);
1278e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR);
1279e48354ceSNicholas Bellinger 
1280e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataSequenceInOrder);
1281e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR);
1282e48354ceSNicholas Bellinger 
1283e48354ceSNicholas Bellinger DEF_TPG_PARAM(ErrorRecoveryLevel);
1284e48354ceSNicholas Bellinger TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR);
1285e48354ceSNicholas Bellinger 
1286e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarker);
1287e48354ceSNicholas Bellinger TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR);
1288e48354ceSNicholas Bellinger 
1289e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarker);
1290e48354ceSNicholas Bellinger TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR);
1291e48354ceSNicholas Bellinger 
1292e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarkInt);
1293e48354ceSNicholas Bellinger TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR);
1294e48354ceSNicholas Bellinger 
1295e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarkInt);
1296e48354ceSNicholas Bellinger TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR);
1297e48354ceSNicholas Bellinger 
1298e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1299e48354ceSNicholas Bellinger 	&iscsi_tpg_param_AuthMethod.attr,
1300e48354ceSNicholas Bellinger 	&iscsi_tpg_param_HeaderDigest.attr,
1301e48354ceSNicholas Bellinger 	&iscsi_tpg_param_DataDigest.attr,
1302e48354ceSNicholas Bellinger 	&iscsi_tpg_param_MaxConnections.attr,
1303e48354ceSNicholas Bellinger 	&iscsi_tpg_param_TargetAlias.attr,
1304e48354ceSNicholas Bellinger 	&iscsi_tpg_param_InitialR2T.attr,
1305e48354ceSNicholas Bellinger 	&iscsi_tpg_param_ImmediateData.attr,
1306e48354ceSNicholas Bellinger 	&iscsi_tpg_param_MaxRecvDataSegmentLength.attr,
1307e004cb25SNicholas Bellinger 	&iscsi_tpg_param_MaxXmitDataSegmentLength.attr,
1308e48354ceSNicholas Bellinger 	&iscsi_tpg_param_MaxBurstLength.attr,
1309e48354ceSNicholas Bellinger 	&iscsi_tpg_param_FirstBurstLength.attr,
1310e48354ceSNicholas Bellinger 	&iscsi_tpg_param_DefaultTime2Wait.attr,
1311e48354ceSNicholas Bellinger 	&iscsi_tpg_param_DefaultTime2Retain.attr,
1312e48354ceSNicholas Bellinger 	&iscsi_tpg_param_MaxOutstandingR2T.attr,
1313e48354ceSNicholas Bellinger 	&iscsi_tpg_param_DataPDUInOrder.attr,
1314e48354ceSNicholas Bellinger 	&iscsi_tpg_param_DataSequenceInOrder.attr,
1315e48354ceSNicholas Bellinger 	&iscsi_tpg_param_ErrorRecoveryLevel.attr,
1316e48354ceSNicholas Bellinger 	&iscsi_tpg_param_IFMarker.attr,
1317e48354ceSNicholas Bellinger 	&iscsi_tpg_param_OFMarker.attr,
1318e48354ceSNicholas Bellinger 	&iscsi_tpg_param_IFMarkInt.attr,
1319e48354ceSNicholas Bellinger 	&iscsi_tpg_param_OFMarkInt.attr,
1320e48354ceSNicholas Bellinger 	NULL,
1321e48354ceSNicholas Bellinger };
1322e48354ceSNicholas Bellinger 
1323e48354ceSNicholas Bellinger /* End items for lio_target_tpg_param_cit */
1324e48354ceSNicholas Bellinger 
1325e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_cit */
1326e48354ceSNicholas Bellinger 
1327e48354ceSNicholas Bellinger static ssize_t lio_target_tpg_show_enable(
1328e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,
1329e48354ceSNicholas Bellinger 	char *page)
1330e48354ceSNicholas Bellinger {
1331e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,
1332e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);
1333e48354ceSNicholas Bellinger 	ssize_t len;
1334e48354ceSNicholas Bellinger 
1335e48354ceSNicholas Bellinger 	spin_lock(&tpg->tpg_state_lock);
1336e48354ceSNicholas Bellinger 	len = sprintf(page, "%d\n",
1337e48354ceSNicholas Bellinger 			(tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1338e48354ceSNicholas Bellinger 	spin_unlock(&tpg->tpg_state_lock);
1339e48354ceSNicholas Bellinger 
1340e48354ceSNicholas Bellinger 	return len;
1341e48354ceSNicholas Bellinger }
1342e48354ceSNicholas Bellinger 
1343e48354ceSNicholas Bellinger static ssize_t lio_target_tpg_store_enable(
1344e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,
1345e48354ceSNicholas Bellinger 	const char *page,
1346e48354ceSNicholas Bellinger 	size_t count)
1347e48354ceSNicholas Bellinger {
1348e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,
1349e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);
1350e48354ceSNicholas Bellinger 	u32 op;
1351ad7babd2SJörn Engel 	int ret;
1352e48354ceSNicholas Bellinger 
1353ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &op);
1354ad7babd2SJörn Engel 	if (ret)
1355ad7babd2SJörn Engel 		return ret;
1356e48354ceSNicholas Bellinger 	if ((op != 1) && (op != 0)) {
1357e48354ceSNicholas Bellinger 		pr_err("Illegal value for tpg_enable: %u\n", op);
1358e48354ceSNicholas Bellinger 		return -EINVAL;
1359e48354ceSNicholas Bellinger 	}
1360e48354ceSNicholas Bellinger 
1361e48354ceSNicholas Bellinger 	ret = iscsit_get_tpg(tpg);
1362e48354ceSNicholas Bellinger 	if (ret < 0)
1363e48354ceSNicholas Bellinger 		return -EINVAL;
1364e48354ceSNicholas Bellinger 
1365e48354ceSNicholas Bellinger 	if (op) {
1366e48354ceSNicholas Bellinger 		ret = iscsit_tpg_enable_portal_group(tpg);
1367e48354ceSNicholas Bellinger 		if (ret < 0)
1368e48354ceSNicholas Bellinger 			goto out;
1369e48354ceSNicholas Bellinger 	} else {
1370e48354ceSNicholas Bellinger 		/*
1371e48354ceSNicholas Bellinger 		 * iscsit_tpg_disable_portal_group() assumes force=1
1372e48354ceSNicholas Bellinger 		 */
1373e48354ceSNicholas Bellinger 		ret = iscsit_tpg_disable_portal_group(tpg, 1);
1374e48354ceSNicholas Bellinger 		if (ret < 0)
1375e48354ceSNicholas Bellinger 			goto out;
1376e48354ceSNicholas Bellinger 	}
1377e48354ceSNicholas Bellinger 
1378e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
1379e48354ceSNicholas Bellinger 	return count;
1380e48354ceSNicholas Bellinger out:
1381e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
1382e48354ceSNicholas Bellinger 	return -EINVAL;
1383e48354ceSNicholas Bellinger }
1384e48354ceSNicholas Bellinger 
1385e48354ceSNicholas Bellinger TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR);
1386e48354ceSNicholas Bellinger 
1387d4ee46ffSNicholas Bellinger static ssize_t lio_target_tpg_show_dynamic_sessions(
1388d4ee46ffSNicholas Bellinger 	struct se_portal_group *se_tpg,
1389d4ee46ffSNicholas Bellinger 	char *page)
1390d4ee46ffSNicholas Bellinger {
1391d4ee46ffSNicholas Bellinger 	return target_show_dynamic_sessions(se_tpg, page);
1392d4ee46ffSNicholas Bellinger }
1393d4ee46ffSNicholas Bellinger 
1394d4ee46ffSNicholas Bellinger TF_TPG_BASE_ATTR_RO(lio_target, dynamic_sessions);
1395d4ee46ffSNicholas Bellinger 
1396e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrs[] = {
1397e48354ceSNicholas Bellinger 	&lio_target_tpg_enable.attr,
1398d4ee46ffSNicholas Bellinger 	&lio_target_tpg_dynamic_sessions.attr,
1399e48354ceSNicholas Bellinger 	NULL,
1400e48354ceSNicholas Bellinger };
1401e48354ceSNicholas Bellinger 
1402e48354ceSNicholas Bellinger /* End items for lio_target_tpg_cit */
1403e48354ceSNicholas Bellinger 
1404e48354ceSNicholas Bellinger /* Start items for lio_target_tiqn_cit */
1405e48354ceSNicholas Bellinger 
1406fceb5bc7SChristoph Hellwig static struct se_portal_group *lio_target_tiqn_addtpg(
1407e48354ceSNicholas Bellinger 	struct se_wwn *wwn,
1408e48354ceSNicholas Bellinger 	struct config_group *group,
1409e48354ceSNicholas Bellinger 	const char *name)
1410e48354ceSNicholas Bellinger {
1411e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
1412e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1413ad7babd2SJörn Engel 	char *tpgt_str;
1414ad7babd2SJörn Engel 	int ret;
1415ad7babd2SJörn Engel 	u16 tpgt;
1416e48354ceSNicholas Bellinger 
1417e48354ceSNicholas Bellinger 	tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1418e48354ceSNicholas Bellinger 	/*
1419e48354ceSNicholas Bellinger 	 * Only tpgt_# directory groups can be created below
1420e48354ceSNicholas Bellinger 	 * target/iscsi/iqn.superturodiskarry/
1421e48354ceSNicholas Bellinger 	 */
1422e48354ceSNicholas Bellinger 	tpgt_str = strstr(name, "tpgt_");
1423e48354ceSNicholas Bellinger 	if (!tpgt_str) {
1424e48354ceSNicholas Bellinger 		pr_err("Unable to locate \"tpgt_#\" directory"
1425e48354ceSNicholas Bellinger 				" group\n");
1426e48354ceSNicholas Bellinger 		return NULL;
1427e48354ceSNicholas Bellinger 	}
1428e48354ceSNicholas Bellinger 	tpgt_str += 5; /* Skip ahead of "tpgt_" */
1429ad7babd2SJörn Engel 	ret = kstrtou16(tpgt_str, 0, &tpgt);
1430ad7babd2SJörn Engel 	if (ret)
1431ad7babd2SJörn Engel 		return NULL;
1432e48354ceSNicholas Bellinger 
1433e48354ceSNicholas Bellinger 	tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1434e48354ceSNicholas Bellinger 	if (!tpg)
1435e48354ceSNicholas Bellinger 		return NULL;
1436e48354ceSNicholas Bellinger 
14379ac8928eSChristoph Hellwig 	ret = core_tpg_register(&iscsi_ops, wwn, &tpg->tpg_se_tpg,
14389ac8928eSChristoph Hellwig 				tpg, TRANSPORT_TPG_TYPE_NORMAL);
1439e48354ceSNicholas Bellinger 	if (ret < 0)
1440e48354ceSNicholas Bellinger 		return NULL;
1441e48354ceSNicholas Bellinger 
1442e48354ceSNicholas Bellinger 	ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1443e48354ceSNicholas Bellinger 	if (ret != 0)
1444e48354ceSNicholas Bellinger 		goto out;
1445e48354ceSNicholas Bellinger 
1446e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1447e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1448e48354ceSNicholas Bellinger 			name);
1449e48354ceSNicholas Bellinger 	return &tpg->tpg_se_tpg;
1450e48354ceSNicholas Bellinger out:
1451e48354ceSNicholas Bellinger 	core_tpg_deregister(&tpg->tpg_se_tpg);
1452e48354ceSNicholas Bellinger 	kfree(tpg);
1453e48354ceSNicholas Bellinger 	return NULL;
1454e48354ceSNicholas Bellinger }
1455e48354ceSNicholas Bellinger 
1456fceb5bc7SChristoph Hellwig static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1457e48354ceSNicholas Bellinger {
1458e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
1459e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1460e48354ceSNicholas Bellinger 
1461e48354ceSNicholas Bellinger 	tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1462e48354ceSNicholas Bellinger 	tiqn = tpg->tpg_tiqn;
1463e48354ceSNicholas Bellinger 	/*
1464e48354ceSNicholas Bellinger 	 * iscsit_tpg_del_portal_group() assumes force=1
1465e48354ceSNicholas Bellinger 	 */
1466e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1467e48354ceSNicholas Bellinger 	iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1468e48354ceSNicholas Bellinger }
1469e48354ceSNicholas Bellinger 
1470e48354ceSNicholas Bellinger /* End items for lio_target_tiqn_cit */
1471e48354ceSNicholas Bellinger 
1472e48354ceSNicholas Bellinger /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1473e48354ceSNicholas Bellinger 
1474e48354ceSNicholas Bellinger static ssize_t lio_target_wwn_show_attr_lio_version(
1475e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,
1476e48354ceSNicholas Bellinger 	char *page)
1477e48354ceSNicholas Bellinger {
14784c76251eSNicholas Bellinger 	return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1479e48354ceSNicholas Bellinger }
1480e48354ceSNicholas Bellinger 
1481e48354ceSNicholas Bellinger TF_WWN_ATTR_RO(lio_target, lio_version);
1482e48354ceSNicholas Bellinger 
1483e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_wwn_attrs[] = {
1484e48354ceSNicholas Bellinger 	&lio_target_wwn_lio_version.attr,
1485e48354ceSNicholas Bellinger 	NULL,
1486e48354ceSNicholas Bellinger };
1487e48354ceSNicholas Bellinger 
1488fceb5bc7SChristoph Hellwig static struct se_wwn *lio_target_call_coreaddtiqn(
1489e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,
1490e48354ceSNicholas Bellinger 	struct config_group *group,
1491e48354ceSNicholas Bellinger 	const char *name)
1492e48354ceSNicholas Bellinger {
1493e48354ceSNicholas Bellinger 	struct config_group *stats_cg;
1494e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1495e48354ceSNicholas Bellinger 
1496e48354ceSNicholas Bellinger 	tiqn = iscsit_add_tiqn((unsigned char *)name);
1497e48354ceSNicholas Bellinger 	if (IS_ERR(tiqn))
1498e1750ba2SThomas Meyer 		return ERR_CAST(tiqn);
1499e48354ceSNicholas Bellinger 	/*
1500e48354ceSNicholas Bellinger 	 * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
1501e48354ceSNicholas Bellinger 	 */
1502e48354ceSNicholas Bellinger 	stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1503e48354ceSNicholas Bellinger 
150413f6a914SSebastian Andrzej Siewior 	stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6,
1505e48354ceSNicholas Bellinger 				GFP_KERNEL);
1506e48354ceSNicholas Bellinger 	if (!stats_cg->default_groups) {
1507e48354ceSNicholas Bellinger 		pr_err("Unable to allocate memory for"
1508e48354ceSNicholas Bellinger 				" stats_cg->default_groups\n");
1509e48354ceSNicholas Bellinger 		iscsit_del_tiqn(tiqn);
1510e48354ceSNicholas Bellinger 		return ERR_PTR(-ENOMEM);
1511e48354ceSNicholas Bellinger 	}
1512e48354ceSNicholas Bellinger 
1513b7eec2cdSAndy Grover 	stats_cg->default_groups[0] = &tiqn->tiqn_stat_grps.iscsi_instance_group;
1514b7eec2cdSAndy Grover 	stats_cg->default_groups[1] = &tiqn->tiqn_stat_grps.iscsi_sess_err_group;
1515b7eec2cdSAndy Grover 	stats_cg->default_groups[2] = &tiqn->tiqn_stat_grps.iscsi_tgt_attr_group;
1516b7eec2cdSAndy Grover 	stats_cg->default_groups[3] = &tiqn->tiqn_stat_grps.iscsi_login_stats_group;
1517b7eec2cdSAndy Grover 	stats_cg->default_groups[4] = &tiqn->tiqn_stat_grps.iscsi_logout_stats_group;
1518e48354ceSNicholas Bellinger 	stats_cg->default_groups[5] = NULL;
1519b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1520e48354ceSNicholas Bellinger 			"iscsi_instance", &iscsi_stat_instance_cit);
1521b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1522e48354ceSNicholas Bellinger 			"iscsi_sess_err", &iscsi_stat_sess_err_cit);
1523b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1524e48354ceSNicholas Bellinger 			"iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1525b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1526e48354ceSNicholas Bellinger 			"iscsi_login_stats", &iscsi_stat_login_cit);
1527b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1528e48354ceSNicholas Bellinger 			"iscsi_logout_stats", &iscsi_stat_logout_cit);
1529e48354ceSNicholas Bellinger 
1530e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1531e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1532e48354ceSNicholas Bellinger 			" %s\n", name);
1533e48354ceSNicholas Bellinger 	return &tiqn->tiqn_wwn;
1534e48354ceSNicholas Bellinger }
1535e48354ceSNicholas Bellinger 
1536fceb5bc7SChristoph Hellwig static void lio_target_call_coredeltiqn(
1537e48354ceSNicholas Bellinger 	struct se_wwn *wwn)
1538e48354ceSNicholas Bellinger {
1539e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1540e48354ceSNicholas Bellinger 	struct config_item *df_item;
1541e48354ceSNicholas Bellinger 	struct config_group *stats_cg;
1542e48354ceSNicholas Bellinger 	int i;
1543e48354ceSNicholas Bellinger 
1544e48354ceSNicholas Bellinger 	stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1545e48354ceSNicholas Bellinger 	for (i = 0; stats_cg->default_groups[i]; i++) {
1546e48354ceSNicholas Bellinger 		df_item = &stats_cg->default_groups[i]->cg_item;
1547e48354ceSNicholas Bellinger 		stats_cg->default_groups[i] = NULL;
1548e48354ceSNicholas Bellinger 		config_item_put(df_item);
1549e48354ceSNicholas Bellinger 	}
1550e48354ceSNicholas Bellinger 	kfree(stats_cg->default_groups);
1551e48354ceSNicholas Bellinger 
1552e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1553e48354ceSNicholas Bellinger 			tiqn->tiqn);
1554e48354ceSNicholas Bellinger 	iscsit_del_tiqn(tiqn);
1555e48354ceSNicholas Bellinger }
1556e48354ceSNicholas Bellinger 
1557e48354ceSNicholas Bellinger /* End LIO-Target TIQN struct contig_lio_target_cit */
1558e48354ceSNicholas Bellinger 
1559e48354ceSNicholas Bellinger /* Start lio_target_discovery_auth_cit */
1560e48354ceSNicholas Bellinger 
1561e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_STR(name, flags)					\
1562e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_STR(disc, name, flags)				\
1563e48354ceSNicholas Bellinger static ssize_t iscsi_disc_show_##name(					\
1564e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,				\
1565e48354ceSNicholas Bellinger 	char *page)							\
1566e48354ceSNicholas Bellinger {									\
1567e48354ceSNicholas Bellinger 	return __iscsi_disc_show_##name(&iscsit_global->discovery_acl,	\
1568e48354ceSNicholas Bellinger 		page);							\
1569e48354ceSNicholas Bellinger }									\
1570e48354ceSNicholas Bellinger static ssize_t iscsi_disc_store_##name(					\
1571e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,				\
1572e48354ceSNicholas Bellinger 	const char *page,						\
1573e48354ceSNicholas Bellinger 	size_t count)							\
1574e48354ceSNicholas Bellinger {									\
1575e48354ceSNicholas Bellinger 	return __iscsi_disc_store_##name(&iscsit_global->discovery_acl,	\
1576e48354ceSNicholas Bellinger 		page, count);						\
1577e48354ceSNicholas Bellinger }
1578e48354ceSNicholas Bellinger 
1579e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_INT(name)						\
1580e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_INT(disc, name)					\
1581e48354ceSNicholas Bellinger static ssize_t iscsi_disc_show_##name(					\
1582e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,				\
1583e48354ceSNicholas Bellinger 	char *page)							\
1584e48354ceSNicholas Bellinger {									\
1585e48354ceSNicholas Bellinger 	return __iscsi_disc_show_##name(&iscsit_global->discovery_acl,	\
1586e48354ceSNicholas Bellinger 			page);						\
1587e48354ceSNicholas Bellinger }
1588e48354ceSNicholas Bellinger 
1589e48354ceSNicholas Bellinger #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
1590e48354ceSNicholas Bellinger #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
1591e48354ceSNicholas Bellinger 
1592e48354ceSNicholas Bellinger /*
1593e48354ceSNicholas Bellinger  * One-way authentication userid
1594e48354ceSNicholas Bellinger  */
1595e48354ceSNicholas Bellinger DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1596e48354ceSNicholas Bellinger DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1597e48354ceSNicholas Bellinger /*
1598e48354ceSNicholas Bellinger  * One-way authentication password
1599e48354ceSNicholas Bellinger  */
1600e48354ceSNicholas Bellinger DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1601e48354ceSNicholas Bellinger DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1602e48354ceSNicholas Bellinger /*
1603e48354ceSNicholas Bellinger  * Enforce mutual authentication
1604e48354ceSNicholas Bellinger  */
1605e48354ceSNicholas Bellinger DEF_DISC_AUTH_INT(authenticate_target);
1606e48354ceSNicholas Bellinger DISC_AUTH_ATTR_RO(authenticate_target);
1607e48354ceSNicholas Bellinger /*
1608e48354ceSNicholas Bellinger  * Mutual authentication userid
1609e48354ceSNicholas Bellinger  */
1610e48354ceSNicholas Bellinger DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1611e48354ceSNicholas Bellinger DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1612e48354ceSNicholas Bellinger /*
1613e48354ceSNicholas Bellinger  * Mutual authentication password
1614e48354ceSNicholas Bellinger  */
1615e48354ceSNicholas Bellinger DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1616e48354ceSNicholas Bellinger DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1617e48354ceSNicholas Bellinger 
1618e48354ceSNicholas Bellinger /*
1619e48354ceSNicholas Bellinger  * enforce_discovery_auth
1620e48354ceSNicholas Bellinger  */
1621e48354ceSNicholas Bellinger static ssize_t iscsi_disc_show_enforce_discovery_auth(
1622e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,
1623e48354ceSNicholas Bellinger 	char *page)
1624e48354ceSNicholas Bellinger {
1625e48354ceSNicholas Bellinger 	struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1626e48354ceSNicholas Bellinger 
1627e48354ceSNicholas Bellinger 	return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1628e48354ceSNicholas Bellinger }
1629e48354ceSNicholas Bellinger 
1630e48354ceSNicholas Bellinger static ssize_t iscsi_disc_store_enforce_discovery_auth(
1631e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,
1632e48354ceSNicholas Bellinger 	const char *page,
1633e48354ceSNicholas Bellinger 	size_t count)
1634e48354ceSNicholas Bellinger {
1635e48354ceSNicholas Bellinger 	struct iscsi_param *param;
1636e48354ceSNicholas Bellinger 	struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1637e48354ceSNicholas Bellinger 	u32 op;
1638ad7babd2SJörn Engel 	int err;
1639e48354ceSNicholas Bellinger 
1640ad7babd2SJörn Engel 	err = kstrtou32(page, 0, &op);
1641ad7babd2SJörn Engel 	if (err)
1642ad7babd2SJörn Engel 		return -EINVAL;
1643e48354ceSNicholas Bellinger 	if ((op != 1) && (op != 0)) {
1644e48354ceSNicholas Bellinger 		pr_err("Illegal value for enforce_discovery_auth:"
1645e48354ceSNicholas Bellinger 				" %u\n", op);
1646e48354ceSNicholas Bellinger 		return -EINVAL;
1647e48354ceSNicholas Bellinger 	}
1648e48354ceSNicholas Bellinger 
1649e48354ceSNicholas Bellinger 	if (!discovery_tpg) {
1650e48354ceSNicholas Bellinger 		pr_err("iscsit_global->discovery_tpg is NULL\n");
1651e48354ceSNicholas Bellinger 		return -EINVAL;
1652e48354ceSNicholas Bellinger 	}
1653e48354ceSNicholas Bellinger 
1654e48354ceSNicholas Bellinger 	param = iscsi_find_param_from_key(AUTHMETHOD,
1655e48354ceSNicholas Bellinger 				discovery_tpg->param_list);
1656e48354ceSNicholas Bellinger 	if (!param)
1657e48354ceSNicholas Bellinger 		return -EINVAL;
1658e48354ceSNicholas Bellinger 
1659e48354ceSNicholas Bellinger 	if (op) {
1660e48354ceSNicholas Bellinger 		/*
1661e48354ceSNicholas Bellinger 		 * Reset the AuthMethod key to CHAP.
1662e48354ceSNicholas Bellinger 		 */
1663e48354ceSNicholas Bellinger 		if (iscsi_update_param_value(param, CHAP) < 0)
1664e48354ceSNicholas Bellinger 			return -EINVAL;
1665e48354ceSNicholas Bellinger 
1666e48354ceSNicholas Bellinger 		discovery_tpg->tpg_attrib.authentication = 1;
1667e48354ceSNicholas Bellinger 		iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1668e48354ceSNicholas Bellinger 		pr_debug("LIO-CORE[0] Successfully enabled"
1669e48354ceSNicholas Bellinger 			" authentication enforcement for iSCSI"
1670e48354ceSNicholas Bellinger 			" Discovery TPG\n");
1671e48354ceSNicholas Bellinger 	} else {
1672e48354ceSNicholas Bellinger 		/*
1673e48354ceSNicholas Bellinger 		 * Reset the AuthMethod key to CHAP,None
1674e48354ceSNicholas Bellinger 		 */
1675e48354ceSNicholas Bellinger 		if (iscsi_update_param_value(param, "CHAP,None") < 0)
1676e48354ceSNicholas Bellinger 			return -EINVAL;
1677e48354ceSNicholas Bellinger 
1678e48354ceSNicholas Bellinger 		discovery_tpg->tpg_attrib.authentication = 0;
1679e48354ceSNicholas Bellinger 		iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1680e48354ceSNicholas Bellinger 		pr_debug("LIO-CORE[0] Successfully disabled"
1681e48354ceSNicholas Bellinger 			" authentication enforcement for iSCSI"
1682e48354ceSNicholas Bellinger 			" Discovery TPG\n");
1683e48354ceSNicholas Bellinger 	}
1684e48354ceSNicholas Bellinger 
1685e48354ceSNicholas Bellinger 	return count;
1686e48354ceSNicholas Bellinger }
1687e48354ceSNicholas Bellinger 
1688e48354ceSNicholas Bellinger DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR);
1689e48354ceSNicholas Bellinger 
1690e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1691e48354ceSNicholas Bellinger 	&iscsi_disc_userid.attr,
1692e48354ceSNicholas Bellinger 	&iscsi_disc_password.attr,
1693e48354ceSNicholas Bellinger 	&iscsi_disc_authenticate_target.attr,
1694e48354ceSNicholas Bellinger 	&iscsi_disc_userid_mutual.attr,
1695e48354ceSNicholas Bellinger 	&iscsi_disc_password_mutual.attr,
1696e48354ceSNicholas Bellinger 	&iscsi_disc_enforce_discovery_auth.attr,
1697e48354ceSNicholas Bellinger 	NULL,
1698e48354ceSNicholas Bellinger };
1699e48354ceSNicholas Bellinger 
1700e48354ceSNicholas Bellinger /* End lio_target_discovery_auth_cit */
1701e48354ceSNicholas Bellinger 
1702e48354ceSNicholas Bellinger /* Start functions for target_core_fabric_ops */
1703e48354ceSNicholas Bellinger 
1704e48354ceSNicholas Bellinger static char *iscsi_get_fabric_name(void)
1705e48354ceSNicholas Bellinger {
1706e48354ceSNicholas Bellinger 	return "iSCSI";
1707e48354ceSNicholas Bellinger }
1708e48354ceSNicholas Bellinger 
1709e48354ceSNicholas Bellinger static u32 iscsi_get_task_tag(struct se_cmd *se_cmd)
1710e48354ceSNicholas Bellinger {
1711e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1712e48354ceSNicholas Bellinger 
171366c7db68SChristoph Hellwig 	/* only used for printks or comparism with ->ref_task_tag */
171466c7db68SChristoph Hellwig 	return (__force u32)cmd->init_task_tag;
1715e48354ceSNicholas Bellinger }
1716e48354ceSNicholas Bellinger 
1717e48354ceSNicholas Bellinger static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1718e48354ceSNicholas Bellinger {
1719e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1720e48354ceSNicholas Bellinger 
1721e48354ceSNicholas Bellinger 	return cmd->i_state;
1722e48354ceSNicholas Bellinger }
1723e48354ceSNicholas Bellinger 
1724e48354ceSNicholas Bellinger static u32 lio_sess_get_index(struct se_session *se_sess)
1725e48354ceSNicholas Bellinger {
1726e48354ceSNicholas Bellinger 	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1727e48354ceSNicholas Bellinger 
1728e48354ceSNicholas Bellinger 	return sess->session_index;
1729e48354ceSNicholas Bellinger }
1730e48354ceSNicholas Bellinger 
1731e48354ceSNicholas Bellinger static u32 lio_sess_get_initiator_sid(
1732e48354ceSNicholas Bellinger 	struct se_session *se_sess,
1733e48354ceSNicholas Bellinger 	unsigned char *buf,
1734e48354ceSNicholas Bellinger 	u32 size)
1735e48354ceSNicholas Bellinger {
1736e48354ceSNicholas Bellinger 	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1737e48354ceSNicholas Bellinger 	/*
1738e48354ceSNicholas Bellinger 	 * iSCSI Initiator Session Identifier from RFC-3720.
1739e48354ceSNicholas Bellinger 	 */
17405cdf5a87SAndy Shevchenko 	return snprintf(buf, size, "%6phN", sess->isid);
1741e48354ceSNicholas Bellinger }
1742e48354ceSNicholas Bellinger 
1743e48354ceSNicholas Bellinger static int lio_queue_data_in(struct se_cmd *se_cmd)
1744e48354ceSNicholas Bellinger {
1745e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1746e48354ceSNicholas Bellinger 
1747e48354ceSNicholas Bellinger 	cmd->i_state = ISTATE_SEND_DATAIN;
17482ec5a8c1SNicholas Bellinger 	cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
17492ec5a8c1SNicholas Bellinger 
1750e48354ceSNicholas Bellinger 	return 0;
1751e48354ceSNicholas Bellinger }
1752e48354ceSNicholas Bellinger 
1753e48354ceSNicholas Bellinger static int lio_write_pending(struct se_cmd *se_cmd)
1754e48354ceSNicholas Bellinger {
1755e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
17563e1c81a9SNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
1757e48354ceSNicholas Bellinger 
1758e48354ceSNicholas Bellinger 	if (!cmd->immediate_data && !cmd->unsolicited_data)
17593e1c81a9SNicholas Bellinger 		return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1760e48354ceSNicholas Bellinger 
1761e48354ceSNicholas Bellinger 	return 0;
1762e48354ceSNicholas Bellinger }
1763e48354ceSNicholas Bellinger 
1764e48354ceSNicholas Bellinger static int lio_write_pending_status(struct se_cmd *se_cmd)
1765e48354ceSNicholas Bellinger {
1766e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1767e48354ceSNicholas Bellinger 	int ret;
1768e48354ceSNicholas Bellinger 
1769e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->istate_lock);
1770e48354ceSNicholas Bellinger 	ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1771e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->istate_lock);
1772e48354ceSNicholas Bellinger 
1773e48354ceSNicholas Bellinger 	return ret;
1774e48354ceSNicholas Bellinger }
1775e48354ceSNicholas Bellinger 
1776e48354ceSNicholas Bellinger static int lio_queue_status(struct se_cmd *se_cmd)
1777e48354ceSNicholas Bellinger {
1778e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1779e48354ceSNicholas Bellinger 
1780e48354ceSNicholas Bellinger 	cmd->i_state = ISTATE_SEND_STATUS;
17815e8e6b4bSNicholas Bellinger 
17825e8e6b4bSNicholas Bellinger 	if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
17835e8e6b4bSNicholas Bellinger 		iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
17845e8e6b4bSNicholas Bellinger 		return 0;
17855e8e6b4bSNicholas Bellinger 	}
17862ec5a8c1SNicholas Bellinger 	cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
17872ec5a8c1SNicholas Bellinger 
1788e48354ceSNicholas Bellinger 	return 0;
1789e48354ceSNicholas Bellinger }
1790e48354ceSNicholas Bellinger 
1791b79fafacSJoern Engel static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1792e48354ceSNicholas Bellinger {
1793e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1794e48354ceSNicholas Bellinger 
1795e48354ceSNicholas Bellinger 	cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1796e48354ceSNicholas Bellinger 	iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1797e48354ceSNicholas Bellinger }
1798e48354ceSNicholas Bellinger 
1799131e6abcSNicholas Bellinger static void lio_aborted_task(struct se_cmd *se_cmd)
1800131e6abcSNicholas Bellinger {
1801131e6abcSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1802131e6abcSNicholas Bellinger 
1803131e6abcSNicholas Bellinger 	cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1804131e6abcSNicholas Bellinger }
1805131e6abcSNicholas Bellinger 
1806e48354ceSNicholas Bellinger static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1807e48354ceSNicholas Bellinger {
1808e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1809e48354ceSNicholas Bellinger 
1810e48354ceSNicholas Bellinger 	return &tpg->tpg_tiqn->tiqn[0];
1811e48354ceSNicholas Bellinger }
1812e48354ceSNicholas Bellinger 
1813e48354ceSNicholas Bellinger static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1814e48354ceSNicholas Bellinger {
1815e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1816e48354ceSNicholas Bellinger 
1817e48354ceSNicholas Bellinger 	return tpg->tpgt;
1818e48354ceSNicholas Bellinger }
1819e48354ceSNicholas Bellinger 
1820e48354ceSNicholas Bellinger static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1821e48354ceSNicholas Bellinger {
1822e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1823e48354ceSNicholas Bellinger 
1824b7eec2cdSAndy Grover 	return tpg->tpg_attrib.default_cmdsn_depth;
1825e48354ceSNicholas Bellinger }
1826e48354ceSNicholas Bellinger 
1827e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1828e48354ceSNicholas Bellinger {
1829e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1830e48354ceSNicholas Bellinger 
1831b7eec2cdSAndy Grover 	return tpg->tpg_attrib.generate_node_acls;
1832e48354ceSNicholas Bellinger }
1833e48354ceSNicholas Bellinger 
1834e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1835e48354ceSNicholas Bellinger {
1836e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1837e48354ceSNicholas Bellinger 
1838b7eec2cdSAndy Grover 	return tpg->tpg_attrib.cache_dynamic_acls;
1839e48354ceSNicholas Bellinger }
1840e48354ceSNicholas Bellinger 
1841e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_write_protect(
1842e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg)
1843e48354ceSNicholas Bellinger {
1844e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1845e48354ceSNicholas Bellinger 
1846b7eec2cdSAndy Grover 	return tpg->tpg_attrib.demo_mode_write_protect;
1847e48354ceSNicholas Bellinger }
1848e48354ceSNicholas Bellinger 
1849e48354ceSNicholas Bellinger static int lio_tpg_check_prod_mode_write_protect(
1850e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg)
1851e48354ceSNicholas Bellinger {
1852e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1853e48354ceSNicholas Bellinger 
1854b7eec2cdSAndy Grover 	return tpg->tpg_attrib.prod_mode_write_protect;
1855e48354ceSNicholas Bellinger }
1856e48354ceSNicholas Bellinger 
1857901c04a3SNicholas Bellinger static int lio_tpg_check_prot_fabric_only(
1858901c04a3SNicholas Bellinger 	struct se_portal_group *se_tpg)
1859901c04a3SNicholas Bellinger {
1860901c04a3SNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1861901c04a3SNicholas Bellinger 	/*
1862901c04a3SNicholas Bellinger 	 * Only report fabric_prot_type if t10_pi has also been enabled
1863901c04a3SNicholas Bellinger 	 * for incoming ib_isert sessions.
1864901c04a3SNicholas Bellinger 	 */
1865901c04a3SNicholas Bellinger 	if (!tpg->tpg_attrib.t10_pi)
1866901c04a3SNicholas Bellinger 		return 0;
1867901c04a3SNicholas Bellinger 
1868901c04a3SNicholas Bellinger 	return tpg->tpg_attrib.fabric_prot_type;
1869901c04a3SNicholas Bellinger }
1870901c04a3SNicholas Bellinger 
1871e48354ceSNicholas Bellinger static void lio_tpg_release_fabric_acl(
1872e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,
1873e48354ceSNicholas Bellinger 	struct se_node_acl *se_acl)
1874e48354ceSNicholas Bellinger {
1875e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(se_acl,
1876e48354ceSNicholas Bellinger 				struct iscsi_node_acl, se_node_acl);
1877e48354ceSNicholas Bellinger 	kfree(acl);
1878e48354ceSNicholas Bellinger }
1879e48354ceSNicholas Bellinger 
1880e48354ceSNicholas Bellinger /*
1881e48354ceSNicholas Bellinger  * Called with spin_lock_bh(struct se_portal_group->session_lock) held..
1882e48354ceSNicholas Bellinger  *
1883e48354ceSNicholas Bellinger  * Also, this function calls iscsit_inc_session_usage_count() on the
1884e48354ceSNicholas Bellinger  * struct iscsi_session in question.
1885e48354ceSNicholas Bellinger  */
1886e48354ceSNicholas Bellinger static int lio_tpg_shutdown_session(struct se_session *se_sess)
1887e48354ceSNicholas Bellinger {
1888e48354ceSNicholas Bellinger 	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1889e48354ceSNicholas Bellinger 
1890e48354ceSNicholas Bellinger 	spin_lock(&sess->conn_lock);
1891e48354ceSNicholas Bellinger 	if (atomic_read(&sess->session_fall_back_to_erl0) ||
1892e48354ceSNicholas Bellinger 	    atomic_read(&sess->session_logout) ||
1893e48354ceSNicholas Bellinger 	    (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1894e48354ceSNicholas Bellinger 		spin_unlock(&sess->conn_lock);
1895e48354ceSNicholas Bellinger 		return 0;
1896e48354ceSNicholas Bellinger 	}
1897e48354ceSNicholas Bellinger 	atomic_set(&sess->session_reinstatement, 1);
1898e48354ceSNicholas Bellinger 	spin_unlock(&sess->conn_lock);
1899e48354ceSNicholas Bellinger 
1900e48354ceSNicholas Bellinger 	iscsit_stop_time2retain_timer(sess);
190199367f01SNicholas Bellinger 	iscsit_stop_session(sess, 1, 1);
1902e48354ceSNicholas Bellinger 
1903e48354ceSNicholas Bellinger 	return 1;
1904e48354ceSNicholas Bellinger }
1905e48354ceSNicholas Bellinger 
1906e48354ceSNicholas Bellinger /*
1907e48354ceSNicholas Bellinger  * Calls iscsit_dec_session_usage_count() as inverse of
1908e48354ceSNicholas Bellinger  * lio_tpg_shutdown_session()
1909e48354ceSNicholas Bellinger  */
1910e48354ceSNicholas Bellinger static void lio_tpg_close_session(struct se_session *se_sess)
1911e48354ceSNicholas Bellinger {
1912e48354ceSNicholas Bellinger 	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1913e48354ceSNicholas Bellinger 	/*
1914e48354ceSNicholas Bellinger 	 * If the iSCSI Session for the iSCSI Initiator Node exists,
1915e48354ceSNicholas Bellinger 	 * forcefully shutdown the iSCSI NEXUS.
1916e48354ceSNicholas Bellinger 	 */
1917e48354ceSNicholas Bellinger 	iscsit_close_session(sess);
1918e48354ceSNicholas Bellinger }
1919e48354ceSNicholas Bellinger 
1920e48354ceSNicholas Bellinger static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1921e48354ceSNicholas Bellinger {
1922e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1923e48354ceSNicholas Bellinger 
1924e48354ceSNicholas Bellinger 	return tpg->tpg_tiqn->tiqn_index;
1925e48354ceSNicholas Bellinger }
1926e48354ceSNicholas Bellinger 
1927e48354ceSNicholas Bellinger static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1928e48354ceSNicholas Bellinger {
1929e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1930e48354ceSNicholas Bellinger 				se_node_acl);
1931d1fa7a1dSNicholas Bellinger 	struct se_portal_group *se_tpg = se_acl->se_tpg;
1932d1fa7a1dSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,
1933d1fa7a1dSNicholas Bellinger 				struct iscsi_portal_group, tpg_se_tpg);
1934e48354ceSNicholas Bellinger 
1935b7eec2cdSAndy Grover 	acl->node_attrib.nacl = acl;
1936d1fa7a1dSNicholas Bellinger 	iscsit_set_default_node_attribues(acl, tpg);
1937e48354ceSNicholas Bellinger }
1938e48354ceSNicholas Bellinger 
19393e1c81a9SNicholas Bellinger static int lio_check_stop_free(struct se_cmd *se_cmd)
19403e1c81a9SNicholas Bellinger {
1941afc16604SBart Van Assche 	return target_put_sess_cmd(se_cmd);
19423e1c81a9SNicholas Bellinger }
19433e1c81a9SNicholas Bellinger 
1944e48354ceSNicholas Bellinger static void lio_release_cmd(struct se_cmd *se_cmd)
1945e48354ceSNicholas Bellinger {
1946e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1947e48354ceSNicholas Bellinger 
1948cdb72665SNicholas Bellinger 	pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1949d703ce2fSNicholas Bellinger 	iscsit_release_cmd(cmd);
1950e48354ceSNicholas Bellinger }
1951e48354ceSNicholas Bellinger 
19529ac8928eSChristoph Hellwig const struct target_core_fabric_ops iscsi_ops = {
19539ac8928eSChristoph Hellwig 	.module				= THIS_MODULE,
19549ac8928eSChristoph Hellwig 	.name				= "iscsi",
19559ac8928eSChristoph Hellwig 	.get_fabric_name		= iscsi_get_fabric_name,
19569ac8928eSChristoph Hellwig 	.get_fabric_proto_ident		= iscsi_get_fabric_proto_ident,
19579ac8928eSChristoph Hellwig 	.tpg_get_wwn			= lio_tpg_get_endpoint_wwn,
19589ac8928eSChristoph Hellwig 	.tpg_get_tag			= lio_tpg_get_tag,
19599ac8928eSChristoph Hellwig 	.tpg_get_default_depth		= lio_tpg_get_default_depth,
19609ac8928eSChristoph Hellwig 	.tpg_get_pr_transport_id	= iscsi_get_pr_transport_id,
19619ac8928eSChristoph Hellwig 	.tpg_get_pr_transport_id_len	= iscsi_get_pr_transport_id_len,
19629ac8928eSChristoph Hellwig 	.tpg_parse_pr_out_transport_id	= iscsi_parse_pr_out_transport_id,
19639ac8928eSChristoph Hellwig 	.tpg_check_demo_mode		= lio_tpg_check_demo_mode,
19649ac8928eSChristoph Hellwig 	.tpg_check_demo_mode_cache	= lio_tpg_check_demo_mode_cache,
19659ac8928eSChristoph Hellwig 	.tpg_check_demo_mode_write_protect =
19669ac8928eSChristoph Hellwig 			lio_tpg_check_demo_mode_write_protect,
19679ac8928eSChristoph Hellwig 	.tpg_check_prod_mode_write_protect =
19689ac8928eSChristoph Hellwig 			lio_tpg_check_prod_mode_write_protect,
19699ac8928eSChristoph Hellwig 	.tpg_check_prot_fabric_only	= &lio_tpg_check_prot_fabric_only,
19709ac8928eSChristoph Hellwig 	.tpg_alloc_fabric_acl		= lio_tpg_alloc_fabric_acl,
19719ac8928eSChristoph Hellwig 	.tpg_release_fabric_acl		= lio_tpg_release_fabric_acl,
19729ac8928eSChristoph Hellwig 	.tpg_get_inst_index		= lio_tpg_get_inst_index,
19739ac8928eSChristoph Hellwig 	.check_stop_free		= lio_check_stop_free,
19749ac8928eSChristoph Hellwig 	.release_cmd			= lio_release_cmd,
19759ac8928eSChristoph Hellwig 	.shutdown_session		= lio_tpg_shutdown_session,
19769ac8928eSChristoph Hellwig 	.close_session			= lio_tpg_close_session,
19779ac8928eSChristoph Hellwig 	.sess_get_index			= lio_sess_get_index,
19789ac8928eSChristoph Hellwig 	.sess_get_initiator_sid		= lio_sess_get_initiator_sid,
19799ac8928eSChristoph Hellwig 	.write_pending			= lio_write_pending,
19809ac8928eSChristoph Hellwig 	.write_pending_status		= lio_write_pending_status,
19819ac8928eSChristoph Hellwig 	.set_default_node_attributes	= lio_set_default_node_attributes,
19829ac8928eSChristoph Hellwig 	.get_task_tag			= iscsi_get_task_tag,
19839ac8928eSChristoph Hellwig 	.get_cmd_state			= iscsi_get_cmd_state,
19849ac8928eSChristoph Hellwig 	.queue_data_in			= lio_queue_data_in,
19859ac8928eSChristoph Hellwig 	.queue_status			= lio_queue_status,
19869ac8928eSChristoph Hellwig 	.queue_tm_rsp			= lio_queue_tm_rsp,
19879ac8928eSChristoph Hellwig 	.aborted_task			= lio_aborted_task,
19889ac8928eSChristoph Hellwig 	.fabric_make_wwn		= lio_target_call_coreaddtiqn,
19899ac8928eSChristoph Hellwig 	.fabric_drop_wwn		= lio_target_call_coredeltiqn,
19909ac8928eSChristoph Hellwig 	.fabric_make_tpg		= lio_target_tiqn_addtpg,
19919ac8928eSChristoph Hellwig 	.fabric_drop_tpg		= lio_target_tiqn_deltpg,
19929ac8928eSChristoph Hellwig 	.fabric_make_np			= lio_target_call_addnptotpg,
19939ac8928eSChristoph Hellwig 	.fabric_drop_np			= lio_target_call_delnpfromtpg,
1994c7d6a803SChristoph Hellwig 	.fabric_init_nodeacl		= lio_target_init_nodeacl,
1995c7d6a803SChristoph Hellwig 	.fabric_cleanup_nodeacl		= lio_target_cleanup_nodeacl,
1996e48354ceSNicholas Bellinger 
19979ac8928eSChristoph Hellwig 	.tfc_discovery_attrs		= lio_target_discovery_auth_attrs,
19989ac8928eSChristoph Hellwig 	.tfc_wwn_attrs			= lio_target_wwn_attrs,
19999ac8928eSChristoph Hellwig 	.tfc_tpg_base_attrs		= lio_target_tpg_attrs,
20009ac8928eSChristoph Hellwig 	.tfc_tpg_attrib_attrs		= lio_target_tpg_attrib_attrs,
20019ac8928eSChristoph Hellwig 	.tfc_tpg_auth_attrs		= lio_target_tpg_auth_attrs,
20029ac8928eSChristoph Hellwig 	.tfc_tpg_param_attrs		= lio_target_tpg_param_attrs,
20039ac8928eSChristoph Hellwig 	.tfc_tpg_np_base_attrs		= lio_target_portal_attrs,
20049ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_base_attrs	= lio_target_initiator_attrs,
20059ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_attrib_attrs	= lio_target_nacl_attrib_attrs,
20069ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_auth_attrs	= lio_target_nacl_auth_attrs,
20079ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_param_attrs	= lio_target_nacl_param_attrs,
20089ac8928eSChristoph Hellwig };
2009