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>
248dcf07beSBart Van Assche #include <linux/module.h>
258dcf07beSBart Van Assche #include <net/ipv6.h>
26e48354ceSNicholas Bellinger #include <target/target_core_base.h>
27c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h>
282ec5a8c1SNicholas Bellinger #include <target/iscsi/iscsi_transport.h>
2967f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h>
30e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h"
31e48354ceSNicholas Bellinger #include "iscsi_target_device.h"
32e48354ceSNicholas Bellinger #include "iscsi_target_erl0.h"
33e48354ceSNicholas Bellinger #include "iscsi_target_nodeattrib.h"
34e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h"
35e48354ceSNicholas Bellinger #include "iscsi_target_util.h"
36e48354ceSNicholas Bellinger #include "iscsi_target.h"
3767f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_stat.h>
38e48354ceSNicholas Bellinger 
39e48354ceSNicholas Bellinger 
40e48354ceSNicholas Bellinger /* Start items for lio_target_portal_cit */
41e48354ceSNicholas Bellinger 
422eafd729SChristoph Hellwig static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
43e48354ceSNicholas Bellinger {
442eafd729SChristoph Hellwig 	return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
452eafd729SChristoph Hellwig }
462eafd729SChristoph Hellwig 
47d4b3fa4bSNicholas Bellinger static ssize_t lio_target_np_driver_show(struct config_item *item, char *page,
48d4b3fa4bSNicholas Bellinger 					 enum iscsit_transport_type type)
492eafd729SChristoph Hellwig {
502eafd729SChristoph Hellwig 	struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
51d4b3fa4bSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np_new;
52e48354ceSNicholas Bellinger 	ssize_t rb;
53e48354ceSNicholas Bellinger 
54d4b3fa4bSNicholas Bellinger 	tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
55d4b3fa4bSNicholas Bellinger 	if (tpg_np_new)
56e48354ceSNicholas Bellinger 		rb = sprintf(page, "1\n");
57e48354ceSNicholas Bellinger 	else
58e48354ceSNicholas Bellinger 		rb = sprintf(page, "0\n");
59e48354ceSNicholas Bellinger 
60e48354ceSNicholas Bellinger 	return rb;
61e48354ceSNicholas Bellinger }
62e48354ceSNicholas Bellinger 
63d4b3fa4bSNicholas Bellinger static ssize_t lio_target_np_driver_store(struct config_item *item,
64d4b3fa4bSNicholas Bellinger 		const char *page, size_t count, enum iscsit_transport_type type,
65d4b3fa4bSNicholas Bellinger 		const char *mod_name)
66e48354ceSNicholas Bellinger {
672eafd729SChristoph Hellwig 	struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
68e48354ceSNicholas Bellinger 	struct iscsi_np *np;
69e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
70d4b3fa4bSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np_new = NULL;
71e48354ceSNicholas Bellinger 	u32 op;
72d4b3fa4bSNicholas Bellinger 	int rc;
73e48354ceSNicholas Bellinger 
74d4b3fa4bSNicholas Bellinger 	rc = kstrtou32(page, 0, &op);
75d4b3fa4bSNicholas Bellinger 	if (rc)
76d4b3fa4bSNicholas Bellinger 		return rc;
77e48354ceSNicholas Bellinger 	if ((op != 1) && (op != 0)) {
78e48354ceSNicholas Bellinger 		pr_err("Illegal value for tpg_enable: %u\n", op);
79e48354ceSNicholas Bellinger 		return -EINVAL;
80e48354ceSNicholas Bellinger 	}
81e48354ceSNicholas Bellinger 	np = tpg_np->tpg_np;
82e48354ceSNicholas Bellinger 	if (!np) {
83e48354ceSNicholas Bellinger 		pr_err("Unable to locate struct iscsi_np from"
84e48354ceSNicholas Bellinger 				" struct iscsi_tpg_np\n");
85e48354ceSNicholas Bellinger 		return -EINVAL;
86e48354ceSNicholas Bellinger 	}
87e48354ceSNicholas Bellinger 
88e48354ceSNicholas Bellinger 	tpg = tpg_np->tpg;
89e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)
90e48354ceSNicholas Bellinger 		return -EINVAL;
91e48354ceSNicholas Bellinger 
92e48354ceSNicholas Bellinger 	if (op) {
93d4b3fa4bSNicholas Bellinger 		if (strlen(mod_name)) {
94d4b3fa4bSNicholas Bellinger 			rc = request_module(mod_name);
95d4b3fa4bSNicholas Bellinger 			if (rc != 0) {
96d4b3fa4bSNicholas Bellinger 				pr_warn("Unable to request_module for %s\n",
97d4b3fa4bSNicholas Bellinger 					mod_name);
98d4b3fa4bSNicholas Bellinger 				rc = 0;
99d4b3fa4bSNicholas Bellinger 			}
100d4b3fa4bSNicholas Bellinger 		}
101d4b3fa4bSNicholas Bellinger 
102d4b3fa4bSNicholas Bellinger 		tpg_np_new = iscsit_tpg_add_network_portal(tpg,
103d4b3fa4bSNicholas Bellinger 					&np->np_sockaddr, tpg_np, type);
10483337e54SVarun Prakash 		if (IS_ERR(tpg_np_new)) {
10583337e54SVarun Prakash 			rc = PTR_ERR(tpg_np_new);
106e48354ceSNicholas Bellinger 			goto out;
10783337e54SVarun Prakash 		}
108e48354ceSNicholas Bellinger 	} else {
109d4b3fa4bSNicholas Bellinger 		tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
110d4b3fa4bSNicholas Bellinger 		if (tpg_np_new) {
111d4b3fa4bSNicholas Bellinger 			rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
112d4b3fa4bSNicholas Bellinger 			if (rc < 0)
113e48354ceSNicholas Bellinger 				goto out;
114d4b3fa4bSNicholas Bellinger 		}
115e48354ceSNicholas Bellinger 	}
116e48354ceSNicholas Bellinger 
117e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
118e48354ceSNicholas Bellinger 	return count;
119e48354ceSNicholas Bellinger out:
120e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
121d4b3fa4bSNicholas Bellinger 	return rc;
122e48354ceSNicholas Bellinger }
123e48354ceSNicholas Bellinger 
1242eafd729SChristoph Hellwig static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
12572438cddSNicholas Bellinger {
126d4b3fa4bSNicholas Bellinger 	return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
12772438cddSNicholas Bellinger }
12872438cddSNicholas Bellinger 
1292eafd729SChristoph Hellwig static ssize_t lio_target_np_iser_store(struct config_item *item,
1302eafd729SChristoph Hellwig 					const char *page, size_t count)
13172438cddSNicholas Bellinger {
132d4b3fa4bSNicholas Bellinger 	return lio_target_np_driver_store(item, page, count,
133d4b3fa4bSNicholas Bellinger 					  ISCSI_INFINIBAND, "ib_isert");
134d4b3fa4bSNicholas Bellinger }
135d4b3fa4bSNicholas Bellinger CONFIGFS_ATTR(lio_target_np_, iser);
13672438cddSNicholas Bellinger 
137ff7199b0SNicholas Bellinger static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page)
1381c46960eSVarun Prakash {
139ff7199b0SNicholas Bellinger 	return lio_target_np_driver_show(item, page, ISCSI_CXGBIT);
1401c46960eSVarun Prakash }
1411c46960eSVarun Prakash 
142ff7199b0SNicholas Bellinger static ssize_t lio_target_np_cxgbit_store(struct config_item *item,
1431c46960eSVarun Prakash 					  const char *page, size_t count)
1441c46960eSVarun Prakash {
145d4b3fa4bSNicholas Bellinger 	return lio_target_np_driver_store(item, page, count,
146ff7199b0SNicholas Bellinger 					  ISCSI_CXGBIT, "cxgbit");
1471c46960eSVarun Prakash }
148ff7199b0SNicholas Bellinger CONFIGFS_ATTR(lio_target_np_, cxgbit);
14972438cddSNicholas Bellinger 
150e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_portal_attrs[] = {
1512eafd729SChristoph Hellwig 	&lio_target_np_attr_iser,
152ff7199b0SNicholas Bellinger 	&lio_target_np_attr_cxgbit,
153e48354ceSNicholas Bellinger 	NULL,
154e48354ceSNicholas Bellinger };
155e48354ceSNicholas Bellinger 
156e48354ceSNicholas Bellinger /* Stop items for lio_target_portal_cit */
157e48354ceSNicholas Bellinger 
158e48354ceSNicholas Bellinger /* Start items for lio_target_np_cit */
159e48354ceSNicholas Bellinger 
160e48354ceSNicholas Bellinger #define MAX_PORTAL_LEN		256
161e48354ceSNicholas Bellinger 
162fceb5bc7SChristoph Hellwig static struct se_tpg_np *lio_target_call_addnptotpg(
163e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg,
164e48354ceSNicholas Bellinger 	struct config_group *group,
165e48354ceSNicholas Bellinger 	const char *name)
166e48354ceSNicholas Bellinger {
167e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
168e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np;
169e48354ceSNicholas Bellinger 	char *str, *str2, *ip_str, *port_str;
1704459e042SSagi Grimberg 	struct sockaddr_storage sockaddr = { };
171e48354ceSNicholas Bellinger 	int ret;
172e48354ceSNicholas Bellinger 	char buf[MAX_PORTAL_LEN + 1];
173e48354ceSNicholas Bellinger 
174e48354ceSNicholas Bellinger 	if (strlen(name) > MAX_PORTAL_LEN) {
175e48354ceSNicholas Bellinger 		pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
176e48354ceSNicholas Bellinger 			(int)strlen(name), MAX_PORTAL_LEN);
177e48354ceSNicholas Bellinger 		return ERR_PTR(-EOVERFLOW);
178e48354ceSNicholas Bellinger 	}
179e48354ceSNicholas Bellinger 	memset(buf, 0, MAX_PORTAL_LEN + 1);
1807bbb654eSNicholas Bellinger 	snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
181e48354ceSNicholas Bellinger 
182e48354ceSNicholas Bellinger 	str = strstr(buf, "[");
183e48354ceSNicholas Bellinger 	if (str) {
184e48354ceSNicholas Bellinger 		str2 = strstr(str, "]");
185e48354ceSNicholas Bellinger 		if (!str2) {
186e48354ceSNicholas Bellinger 			pr_err("Unable to locate trailing \"]\""
187e48354ceSNicholas Bellinger 				" in IPv6 iSCSI network portal address\n");
188e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
189e48354ceSNicholas Bellinger 		}
1904459e042SSagi Grimberg 
1914459e042SSagi Grimberg 		ip_str = str + 1; /* Skip over leading "[" */
19276c28f1fSAndy Grover 		*str2 = '\0'; /* Terminate the unbracketed IPv6 address */
19376c28f1fSAndy Grover 		str2++; /* Skip over the \0 */
1944459e042SSagi Grimberg 
195e48354ceSNicholas Bellinger 		port_str = strstr(str2, ":");
196e48354ceSNicholas Bellinger 		if (!port_str) {
197e48354ceSNicholas Bellinger 			pr_err("Unable to locate \":port\""
198e48354ceSNicholas Bellinger 				" in IPv6 iSCSI network portal address\n");
199e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
200e48354ceSNicholas Bellinger 		}
201e48354ceSNicholas Bellinger 		*port_str = '\0'; /* Terminate string for IP */
202e48354ceSNicholas Bellinger 		port_str++; /* Skip over ":" */
203e48354ceSNicholas Bellinger 	} else {
2044459e042SSagi Grimberg 		ip_str = &buf[0];
205e48354ceSNicholas Bellinger 		port_str = strstr(ip_str, ":");
206e48354ceSNicholas Bellinger 		if (!port_str) {
207e48354ceSNicholas Bellinger 			pr_err("Unable to locate \":port\""
208e48354ceSNicholas Bellinger 				" in IPv4 iSCSI network portal address\n");
209e48354ceSNicholas Bellinger 			return ERR_PTR(-EINVAL);
210e48354ceSNicholas Bellinger 		}
211e48354ceSNicholas Bellinger 		*port_str = '\0'; /* Terminate string for IP */
212e48354ceSNicholas Bellinger 		port_str++; /* Skip over ":" */
2134459e042SSagi Grimberg 	}
214e48354ceSNicholas Bellinger 
2154459e042SSagi Grimberg 	ret = inet_pton_with_scope(&init_net, AF_UNSPEC, ip_str,
2164459e042SSagi Grimberg 			port_str, &sockaddr);
2174459e042SSagi Grimberg 	if (ret) {
2184459e042SSagi Grimberg 		pr_err("malformed ip/port passed: %s\n", name);
219e48354ceSNicholas Bellinger 		return ERR_PTR(ret);
220e48354ceSNicholas Bellinger 	}
2214459e042SSagi Grimberg 
222e48354ceSNicholas Bellinger 	tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
223e48354ceSNicholas Bellinger 	ret = iscsit_get_tpg(tpg);
224e48354ceSNicholas Bellinger 	if (ret < 0)
225e48354ceSNicholas Bellinger 		return ERR_PTR(-EINVAL);
226e48354ceSNicholas Bellinger 
227e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
228e48354ceSNicholas Bellinger 		" PORTAL: %s\n",
229e48354ceSNicholas Bellinger 		config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
230e48354ceSNicholas Bellinger 		tpg->tpgt, name);
231e48354ceSNicholas Bellinger 	/*
232e48354ceSNicholas Bellinger 	 * Assume ISCSI_TCP by default.  Other network portals for other
233e48354ceSNicholas Bellinger 	 * iSCSI fabrics:
234e48354ceSNicholas Bellinger 	 *
235e48354ceSNicholas Bellinger 	 * Traditional iSCSI over SCTP (initial support)
236e48354ceSNicholas Bellinger 	 * iSER/TCP (TODO, hardware available)
237e48354ceSNicholas Bellinger 	 * iSER/SCTP (TODO, software emulation with osc-iwarp)
238e48354ceSNicholas Bellinger 	 * iSER/IB (TODO, hardware available)
239e48354ceSNicholas Bellinger 	 *
24020879696SMasanari Iida 	 * can be enabled with attributes under
241e48354ceSNicholas Bellinger 	 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
242e48354ceSNicholas Bellinger 	 *
243e48354ceSNicholas Bellinger 	 */
24476c28f1fSAndy Grover 	tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
245e48354ceSNicholas Bellinger 				ISCSI_TCP);
246e48354ceSNicholas Bellinger 	if (IS_ERR(tpg_np)) {
247e48354ceSNicholas Bellinger 		iscsit_put_tpg(tpg);
248e1750ba2SThomas Meyer 		return ERR_CAST(tpg_np);
249e48354ceSNicholas Bellinger 	}
250e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
251e48354ceSNicholas Bellinger 
252e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
253e48354ceSNicholas Bellinger 	return &tpg_np->se_tpg_np;
254e48354ceSNicholas Bellinger }
255e48354ceSNicholas Bellinger 
256e48354ceSNicholas Bellinger static void lio_target_call_delnpfromtpg(
257e48354ceSNicholas Bellinger 	struct se_tpg_np *se_tpg_np)
258e48354ceSNicholas Bellinger {
259e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
260e48354ceSNicholas Bellinger 	struct iscsi_tpg_np *tpg_np;
261e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg;
262e48354ceSNicholas Bellinger 	int ret;
263e48354ceSNicholas Bellinger 
264e48354ceSNicholas Bellinger 	tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
265e48354ceSNicholas Bellinger 	tpg = tpg_np->tpg;
266e48354ceSNicholas Bellinger 	ret = iscsit_get_tpg(tpg);
267e48354ceSNicholas Bellinger 	if (ret < 0)
268e48354ceSNicholas Bellinger 		return;
269e48354ceSNicholas Bellinger 
270e48354ceSNicholas Bellinger 	se_tpg = &tpg->tpg_se_tpg;
271e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
27269d75574SAndy Grover 		" PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
27369d75574SAndy Grover 		tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
274e48354ceSNicholas Bellinger 
275e48354ceSNicholas Bellinger 	ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
276e48354ceSNicholas Bellinger 	if (ret < 0)
277e48354ceSNicholas Bellinger 		goto out;
278e48354ceSNicholas Bellinger 
279e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
280e48354ceSNicholas Bellinger out:
281e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
282e48354ceSNicholas Bellinger }
283e48354ceSNicholas Bellinger 
284e48354ceSNicholas Bellinger /* End items for lio_target_np_cit */
285e48354ceSNicholas Bellinger 
286e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_attrib_cit */
287e48354ceSNicholas Bellinger 
2882eafd729SChristoph Hellwig #define ISCSI_NACL_ATTR(name)						\
2892eafd729SChristoph Hellwig static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
290e48354ceSNicholas Bellinger 		char *page)						\
291e48354ceSNicholas Bellinger {									\
2922eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = attrib_to_nacl(item);		\
293e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
294e48354ceSNicholas Bellinger 					se_node_acl);			\
295e48354ceSNicholas Bellinger 									\
296b7eec2cdSAndy Grover 	return sprintf(page, "%u\n", nacl->node_attrib.name);		\
297e48354ceSNicholas Bellinger }									\
298e48354ceSNicholas Bellinger 									\
2992eafd729SChristoph Hellwig static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
3002eafd729SChristoph Hellwig 		const char *page, size_t count)				\
301e48354ceSNicholas Bellinger {									\
3022eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = attrib_to_nacl(item);		\
303e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
304e48354ceSNicholas Bellinger 					se_node_acl);			\
305e48354ceSNicholas Bellinger 	u32 val;							\
306e48354ceSNicholas Bellinger 	int ret;							\
307e48354ceSNicholas Bellinger 									\
308ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &val);					\
309ad7babd2SJörn Engel 	if (ret)							\
310ad7babd2SJörn Engel 		return ret;						\
311e48354ceSNicholas Bellinger 	ret = iscsit_na_##name(nacl, val);				\
312e48354ceSNicholas Bellinger 	if (ret < 0)							\
313e48354ceSNicholas Bellinger 		return ret;						\
314e48354ceSNicholas Bellinger 									\
315e48354ceSNicholas Bellinger 	return count;							\
3162eafd729SChristoph Hellwig }									\
3172eafd729SChristoph Hellwig 									\
3182eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
319e48354ceSNicholas Bellinger 
3202eafd729SChristoph Hellwig ISCSI_NACL_ATTR(dataout_timeout);
3212eafd729SChristoph Hellwig ISCSI_NACL_ATTR(dataout_timeout_retries);
3222eafd729SChristoph Hellwig ISCSI_NACL_ATTR(default_erl);
3232eafd729SChristoph Hellwig ISCSI_NACL_ATTR(nopin_timeout);
3242eafd729SChristoph Hellwig ISCSI_NACL_ATTR(nopin_response_timeout);
3252eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_datain_pdu_offsets);
3262eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_datain_seq_offsets);
3272eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_r2t_offsets);
328e48354ceSNicholas Bellinger 
329e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
3302eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_dataout_timeout,
3312eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_dataout_timeout_retries,
3322eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_default_erl,
3332eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_nopin_timeout,
3342eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_nopin_response_timeout,
3352eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
3362eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_random_datain_seq_offsets,
3372eafd729SChristoph Hellwig 	&iscsi_nacl_attrib_attr_random_r2t_offsets,
338e48354ceSNicholas Bellinger 	NULL,
339e48354ceSNicholas Bellinger };
340e48354ceSNicholas Bellinger 
341e48354ceSNicholas Bellinger /* End items for lio_target_nacl_attrib_cit */
342e48354ceSNicholas Bellinger 
343e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_auth_cit */
344e48354ceSNicholas Bellinger 
345e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_STR(prefix, name, flags)			\
3462eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(			\
347e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
348e48354ceSNicholas Bellinger 	char *page)							\
349e48354ceSNicholas Bellinger {									\
350e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
351e48354ceSNicholas Bellinger 									\
352e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
353e48354ceSNicholas Bellinger 		return -EPERM;						\
354e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", auth->name);		\
355e48354ceSNicholas Bellinger }									\
356e48354ceSNicholas Bellinger 									\
3572eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_store(			\
358e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
359e48354ceSNicholas Bellinger 	const char *page,						\
360e48354ceSNicholas Bellinger 	size_t count)							\
361e48354ceSNicholas Bellinger {									\
362e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
363e48354ceSNicholas Bellinger 									\
364e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
365e48354ceSNicholas Bellinger 		return -EPERM;						\
3662306bfb2SEric Seppanen 	if (count >= sizeof(auth->name))				\
3672306bfb2SEric Seppanen 		return -EINVAL;						\
3680fbfc46fSJörn Engel 	snprintf(auth->name, sizeof(auth->name), "%s", page);		\
369e48354ceSNicholas Bellinger 	if (!strncmp("NULL", auth->name, 4))				\
370e48354ceSNicholas Bellinger 		auth->naf_flags &= ~flags;				\
371e48354ceSNicholas Bellinger 	else								\
372e48354ceSNicholas Bellinger 		auth->naf_flags |= flags;				\
373e48354ceSNicholas Bellinger 									\
374e48354ceSNicholas Bellinger 	if ((auth->naf_flags & NAF_USERID_IN_SET) &&			\
375e48354ceSNicholas Bellinger 	    (auth->naf_flags & NAF_PASSWORD_IN_SET))			\
376e48354ceSNicholas Bellinger 		auth->authenticate_target = 1;				\
377e48354ceSNicholas Bellinger 	else								\
378e48354ceSNicholas Bellinger 		auth->authenticate_target = 0;				\
379e48354ceSNicholas Bellinger 									\
380e48354ceSNicholas Bellinger 	return count;							\
381e48354ceSNicholas Bellinger }
382e48354ceSNicholas Bellinger 
3832eafd729SChristoph Hellwig #define DEF_NACL_AUTH_STR(name, flags)					\
3842eafd729SChristoph Hellwig 	__DEF_NACL_AUTH_STR(nacl_auth, name, flags)			\
3852eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item,	\
3862eafd729SChristoph Hellwig 		char *page)						\
3872eafd729SChristoph Hellwig {									\
3882eafd729SChristoph Hellwig 	struct se_node_acl *nacl = auth_to_nacl(item);			\
3892eafd729SChristoph Hellwig 	return __iscsi_nacl_auth_##name##_show(container_of(nacl,	\
3902eafd729SChristoph Hellwig 			struct iscsi_node_acl, se_node_acl), page);	\
3912eafd729SChristoph Hellwig }									\
3922eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item,	\
3932eafd729SChristoph Hellwig 		const char *page, size_t count)				\
3942eafd729SChristoph Hellwig {									\
3952eafd729SChristoph Hellwig 	struct se_node_acl *nacl = auth_to_nacl(item);			\
3962eafd729SChristoph Hellwig 	return __iscsi_nacl_auth_##name##_store(container_of(nacl,	\
3972eafd729SChristoph Hellwig 			struct iscsi_node_acl, se_node_acl), page, count); \
3982eafd729SChristoph Hellwig }									\
3992eafd729SChristoph Hellwig 									\
4002eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_nacl_auth_, name)
4012eafd729SChristoph Hellwig 
4022eafd729SChristoph Hellwig /*
4032eafd729SChristoph Hellwig  * One-way authentication userid
4042eafd729SChristoph Hellwig  */
4052eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
4062eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
4072eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
4082eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
4092eafd729SChristoph Hellwig 
410e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_INT(prefix, name)				\
4112eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(				\
412e48354ceSNicholas Bellinger 	struct iscsi_node_acl *nacl,					\
413e48354ceSNicholas Bellinger 	char *page)							\
414e48354ceSNicholas Bellinger {									\
415e48354ceSNicholas Bellinger 	struct iscsi_node_auth *auth = &nacl->node_auth;		\
416e48354ceSNicholas Bellinger 									\
417e48354ceSNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))					\
418e48354ceSNicholas Bellinger 		return -EPERM;						\
419e48354ceSNicholas Bellinger 									\
420e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%d\n", auth->name);		\
421e48354ceSNicholas Bellinger }
422e48354ceSNicholas Bellinger 
423e48354ceSNicholas Bellinger #define DEF_NACL_AUTH_INT(name)						\
424e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_INT(nacl_auth, name)				\
4252eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item,	\
426e48354ceSNicholas Bellinger 		char *page)						\
427e48354ceSNicholas Bellinger {									\
4282eafd729SChristoph Hellwig 	struct se_node_acl *nacl = auth_to_nacl(item);			\
4292eafd729SChristoph Hellwig 	return __iscsi_nacl_auth_##name##_show(container_of(nacl,	\
430e48354ceSNicholas Bellinger 			struct iscsi_node_acl, se_node_acl), page);	\
4312eafd729SChristoph Hellwig }									\
4322eafd729SChristoph Hellwig 									\
4332eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
434e48354ceSNicholas Bellinger 
435e48354ceSNicholas Bellinger DEF_NACL_AUTH_INT(authenticate_target);
436e48354ceSNicholas Bellinger 
437e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
4382eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_userid,
4392eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_password,
4402eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_authenticate_target,
4412eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_userid_mutual,
4422eafd729SChristoph Hellwig 	&iscsi_nacl_auth_attr_password_mutual,
443e48354ceSNicholas Bellinger 	NULL,
444e48354ceSNicholas Bellinger };
445e48354ceSNicholas Bellinger 
446e48354ceSNicholas Bellinger /* End items for lio_target_nacl_auth_cit */
447e48354ceSNicholas Bellinger 
448e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_param_cit */
449e48354ceSNicholas Bellinger 
4502eafd729SChristoph Hellwig #define ISCSI_NACL_PARAM(name)						\
4512eafd729SChristoph Hellwig static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item,	\
452e48354ceSNicholas Bellinger 		char *page)						\
453e48354ceSNicholas Bellinger {									\
4542eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = param_to_nacl(item);		\
455e48354ceSNicholas Bellinger 	struct iscsi_session *sess;					\
456e48354ceSNicholas Bellinger 	struct se_session *se_sess;					\
457e48354ceSNicholas Bellinger 	ssize_t rb;							\
458e48354ceSNicholas Bellinger 									\
459e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);				\
460e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;					\
461e48354ceSNicholas Bellinger 	if (!se_sess) {							\
462e48354ceSNicholas Bellinger 		rb = snprintf(page, PAGE_SIZE,				\
463e48354ceSNicholas Bellinger 			"No Active iSCSI Session\n");			\
464e48354ceSNicholas Bellinger 	} else {							\
465e48354ceSNicholas Bellinger 		sess = se_sess->fabric_sess_ptr;			\
466e48354ceSNicholas Bellinger 		rb = snprintf(page, PAGE_SIZE, "%u\n",			\
467e48354ceSNicholas Bellinger 			(u32)sess->sess_ops->name);			\
468e48354ceSNicholas Bellinger 	}								\
469e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);			\
470e48354ceSNicholas Bellinger 									\
471e48354ceSNicholas Bellinger 	return rb;							\
4722eafd729SChristoph Hellwig }									\
4732eafd729SChristoph Hellwig 									\
4742eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
475e48354ceSNicholas Bellinger 
4762eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxConnections);
4772eafd729SChristoph Hellwig ISCSI_NACL_PARAM(InitialR2T);
4782eafd729SChristoph Hellwig ISCSI_NACL_PARAM(ImmediateData);
4792eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxBurstLength);
4802eafd729SChristoph Hellwig ISCSI_NACL_PARAM(FirstBurstLength);
4812eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DefaultTime2Wait);
4822eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DefaultTime2Retain);
4832eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxOutstandingR2T);
4842eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DataPDUInOrder);
4852eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DataSequenceInOrder);
4862eafd729SChristoph Hellwig ISCSI_NACL_PARAM(ErrorRecoveryLevel);
487e48354ceSNicholas Bellinger 
488e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
4892eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_MaxConnections,
4902eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_InitialR2T,
4912eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_ImmediateData,
4922eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_MaxBurstLength,
4932eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_FirstBurstLength,
4942eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_DefaultTime2Wait,
4952eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_DefaultTime2Retain,
4962eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_MaxOutstandingR2T,
4972eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_DataPDUInOrder,
4982eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_DataSequenceInOrder,
4992eafd729SChristoph Hellwig 	&iscsi_nacl_param_attr_ErrorRecoveryLevel,
500e48354ceSNicholas Bellinger 	NULL,
501e48354ceSNicholas Bellinger };
502e48354ceSNicholas Bellinger 
503e48354ceSNicholas Bellinger /* End items for lio_target_nacl_param_cit */
504e48354ceSNicholas Bellinger 
505e48354ceSNicholas Bellinger /* Start items for lio_target_acl_cit */
506e48354ceSNicholas Bellinger 
5072eafd729SChristoph Hellwig static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
508e48354ceSNicholas Bellinger {
5092eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = acl_to_nacl(item);
510e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
511e48354ceSNicholas Bellinger 	struct iscsi_conn *conn;
512e48354ceSNicholas Bellinger 	struct se_session *se_sess;
513e48354ceSNicholas Bellinger 	ssize_t rb = 0;
514109e2381SRoland Dreier 	u32 max_cmd_sn;
515e48354ceSNicholas Bellinger 
516e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
517e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
518e48354ceSNicholas Bellinger 	if (!se_sess) {
519e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
520e48354ceSNicholas Bellinger 			" Endpoint: %s\n", se_nacl->initiatorname);
521e48354ceSNicholas Bellinger 	} else {
522e48354ceSNicholas Bellinger 		sess = se_sess->fabric_sess_ptr;
523e48354ceSNicholas Bellinger 
524e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "InitiatorName: %s\n",
525e48354ceSNicholas Bellinger 			sess->sess_ops->InitiatorName);
526e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "InitiatorAlias: %s\n",
527e48354ceSNicholas Bellinger 			sess->sess_ops->InitiatorAlias);
528e48354ceSNicholas Bellinger 
5295cdf5a87SAndy Shevchenko 		rb += sprintf(page+rb,
5305cdf5a87SAndy Shevchenko 			      "LIO Session ID: %u   ISID: 0x%6ph  TSIH: %hu  ",
5315cdf5a87SAndy Shevchenko 			      sess->sid, sess->isid, sess->tsih);
532e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "SessionType: %s\n",
533e48354ceSNicholas Bellinger 				(sess->sess_ops->SessionType) ?
534e48354ceSNicholas Bellinger 				"Discovery" : "Normal");
535e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "Session State: ");
536e48354ceSNicholas Bellinger 		switch (sess->session_state) {
537e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_FREE:
538e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_FREE\n");
539e48354ceSNicholas Bellinger 			break;
540e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_ACTIVE:
541e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
542e48354ceSNicholas Bellinger 			break;
543e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_LOGGED_IN:
544e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
545e48354ceSNicholas Bellinger 			break;
546e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_FAILED:
547e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
548e48354ceSNicholas Bellinger 			break;
549e48354ceSNicholas Bellinger 		case TARG_SESS_STATE_IN_CONTINUE:
550e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
551e48354ceSNicholas Bellinger 			break;
552e48354ceSNicholas Bellinger 		default:
553e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "ERROR: Unknown Session"
554e48354ceSNicholas Bellinger 					" State!\n");
555e48354ceSNicholas Bellinger 			break;
556e48354ceSNicholas Bellinger 		}
557e48354ceSNicholas Bellinger 
558e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "---------------------[iSCSI Session"
559e48354ceSNicholas Bellinger 				" Values]-----------------------\n");
560e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "  CmdSN/WR  :  CmdSN/WC  :  ExpCmdSN"
561e48354ceSNicholas Bellinger 				"  :  MaxCmdSN  :     ITT    :     TTT\n");
562109e2381SRoland Dreier 		max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
563e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, " 0x%08x   0x%08x   0x%08x   0x%08x"
564e48354ceSNicholas Bellinger 				"   0x%08x   0x%08x\n",
565e48354ceSNicholas Bellinger 			sess->cmdsn_window,
566109e2381SRoland Dreier 			(max_cmd_sn - sess->exp_cmd_sn) + 1,
567109e2381SRoland Dreier 			sess->exp_cmd_sn, max_cmd_sn,
568e48354ceSNicholas Bellinger 			sess->init_task_tag, sess->targ_xfer_tag);
569e48354ceSNicholas Bellinger 		rb += sprintf(page+rb, "----------------------[iSCSI"
570e48354ceSNicholas Bellinger 				" Connections]-------------------------\n");
571e48354ceSNicholas Bellinger 
572e48354ceSNicholas Bellinger 		spin_lock(&sess->conn_lock);
573e48354ceSNicholas Bellinger 		list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
574e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "CID: %hu  Connection"
575e48354ceSNicholas Bellinger 					" State: ", conn->cid);
576e48354ceSNicholas Bellinger 			switch (conn->conn_state) {
577e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_FREE:
578e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
579e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_FREE\n");
580e48354ceSNicholas Bellinger 				break;
581e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_XPT_UP:
582e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
583e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_XPT_UP\n");
584e48354ceSNicholas Bellinger 				break;
585e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_IN_LOGIN:
586e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
587e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_IN_LOGIN\n");
588e48354ceSNicholas Bellinger 				break;
589e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_LOGGED_IN:
590e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
591e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_LOGGED_IN\n");
592e48354ceSNicholas Bellinger 				break;
593e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_IN_LOGOUT:
594e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
595e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_IN_LOGOUT\n");
596e48354ceSNicholas Bellinger 				break;
597e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_LOGOUT_REQUESTED:
598e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
599e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_LOGOUT_REQUESTED\n");
600e48354ceSNicholas Bellinger 				break;
601e48354ceSNicholas Bellinger 			case TARG_CONN_STATE_CLEANUP_WAIT:
602e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
603e48354ceSNicholas Bellinger 					"TARG_CONN_STATE_CLEANUP_WAIT\n");
604e48354ceSNicholas Bellinger 				break;
605e48354ceSNicholas Bellinger 			default:
606e48354ceSNicholas Bellinger 				rb += sprintf(page+rb,
607e48354ceSNicholas Bellinger 					"ERROR: Unknown Connection State!\n");
608e48354ceSNicholas Bellinger 				break;
609e48354ceSNicholas Bellinger 			}
610e48354ceSNicholas Bellinger 
611dc58f760SAndy Grover 			rb += sprintf(page+rb, "   Address %pISc %s", &conn->login_sockaddr,
612e48354ceSNicholas Bellinger 				(conn->network_transport == ISCSI_TCP) ?
613e48354ceSNicholas Bellinger 				"TCP" : "SCTP");
614e48354ceSNicholas Bellinger 			rb += sprintf(page+rb, "  StatSN: 0x%08x\n",
615e48354ceSNicholas Bellinger 				conn->stat_sn);
616e48354ceSNicholas Bellinger 		}
617e48354ceSNicholas Bellinger 		spin_unlock(&sess->conn_lock);
618e48354ceSNicholas Bellinger 	}
619e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
620e48354ceSNicholas Bellinger 
621e48354ceSNicholas Bellinger 	return rb;
622e48354ceSNicholas Bellinger }
623e48354ceSNicholas Bellinger 
6242eafd729SChristoph Hellwig static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
625e48354ceSNicholas Bellinger 		char *page)
626e48354ceSNicholas Bellinger {
6272eafd729SChristoph Hellwig 	return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
628e48354ceSNicholas Bellinger }
629e48354ceSNicholas Bellinger 
6302eafd729SChristoph Hellwig static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
6312eafd729SChristoph Hellwig 		const char *page, size_t count)
632e48354ceSNicholas Bellinger {
6332eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = acl_to_nacl(item);
634e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg = se_nacl->se_tpg;
635e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,
636e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);
637e48354ceSNicholas Bellinger 	struct config_item *acl_ci, *tpg_ci, *wwn_ci;
638e48354ceSNicholas Bellinger 	u32 cmdsn_depth = 0;
639e48354ceSNicholas Bellinger 	int ret;
640e48354ceSNicholas Bellinger 
641ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &cmdsn_depth);
642ad7babd2SJörn Engel 	if (ret)
643ad7babd2SJörn Engel 		return ret;
644e48354ceSNicholas Bellinger 	if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
645e48354ceSNicholas Bellinger 		pr_err("Passed cmdsn_depth: %u exceeds"
646e48354ceSNicholas Bellinger 			" TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
647e48354ceSNicholas Bellinger 			TA_DEFAULT_CMDSN_DEPTH_MAX);
648e48354ceSNicholas Bellinger 		return -EINVAL;
649e48354ceSNicholas Bellinger 	}
650e48354ceSNicholas Bellinger 	acl_ci = &se_nacl->acl_group.cg_item;
651e48354ceSNicholas Bellinger 	if (!acl_ci) {
652e48354ceSNicholas Bellinger 		pr_err("Unable to locatel acl_ci\n");
653e48354ceSNicholas Bellinger 		return -EINVAL;
654e48354ceSNicholas Bellinger 	}
655e48354ceSNicholas Bellinger 	tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
656e48354ceSNicholas Bellinger 	if (!tpg_ci) {
657e48354ceSNicholas Bellinger 		pr_err("Unable to locate tpg_ci\n");
658e48354ceSNicholas Bellinger 		return -EINVAL;
659e48354ceSNicholas Bellinger 	}
660e48354ceSNicholas Bellinger 	wwn_ci = &tpg_ci->ci_group->cg_item;
661e48354ceSNicholas Bellinger 	if (!wwn_ci) {
662e48354ceSNicholas Bellinger 		pr_err("Unable to locate config_item wwn_ci\n");
663e48354ceSNicholas Bellinger 		return -EINVAL;
664e48354ceSNicholas Bellinger 	}
665e48354ceSNicholas Bellinger 
666e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)
667e48354ceSNicholas Bellinger 		return -EINVAL;
668d36ad77fSNicholas Bellinger 
669d36ad77fSNicholas Bellinger 	ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
670e48354ceSNicholas Bellinger 
671e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
672e48354ceSNicholas Bellinger 		"InitiatorName: %s\n", config_item_name(wwn_ci),
673e48354ceSNicholas Bellinger 		config_item_name(tpg_ci), cmdsn_depth,
674e48354ceSNicholas Bellinger 		config_item_name(acl_ci));
675e48354ceSNicholas Bellinger 
676e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
677e48354ceSNicholas Bellinger 	return (!ret) ? count : (ssize_t)ret;
678e48354ceSNicholas Bellinger }
679e48354ceSNicholas Bellinger 
6802eafd729SChristoph Hellwig static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
68179e62fc3SAndy Grover {
6822eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
68379e62fc3SAndy Grover }
68479e62fc3SAndy Grover 
6852eafd729SChristoph Hellwig static ssize_t lio_target_nacl_tag_store(struct config_item *item,
6862eafd729SChristoph Hellwig 		const char *page, size_t count)
68779e62fc3SAndy Grover {
6882eafd729SChristoph Hellwig 	struct se_node_acl *se_nacl = acl_to_nacl(item);
68979e62fc3SAndy Grover 	int ret;
69079e62fc3SAndy Grover 
69179e62fc3SAndy Grover 	ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
69279e62fc3SAndy Grover 
69379e62fc3SAndy Grover 	if (ret < 0)
69479e62fc3SAndy Grover 		return ret;
69579e62fc3SAndy Grover 	return count;
69679e62fc3SAndy Grover }
69779e62fc3SAndy Grover 
6982eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_nacl_, info);
6992eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
7002eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_nacl_, tag);
70179e62fc3SAndy Grover 
702e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_initiator_attrs[] = {
7032eafd729SChristoph Hellwig 	&lio_target_nacl_attr_info,
7042eafd729SChristoph Hellwig 	&lio_target_nacl_attr_cmdsn_depth,
7052eafd729SChristoph Hellwig 	&lio_target_nacl_attr_tag,
706e48354ceSNicholas Bellinger 	NULL,
707e48354ceSNicholas Bellinger };
708e48354ceSNicholas Bellinger 
709c7d6a803SChristoph Hellwig static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
710e48354ceSNicholas Bellinger 		const char *name)
711e48354ceSNicholas Bellinger {
712c7d6a803SChristoph Hellwig 	struct iscsi_node_acl *acl =
713c7d6a803SChristoph Hellwig 		container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
714e48354ceSNicholas Bellinger 
715b7eec2cdSAndy Grover 	config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
716e48354ceSNicholas Bellinger 			"iscsi_sess_stats", &iscsi_stat_sess_cit);
7171ae1602dSChristoph Hellwig 	configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
7181ae1602dSChristoph Hellwig 			&se_nacl->acl_fabric_stat_group);
719c7d6a803SChristoph Hellwig 	return 0;
720e48354ceSNicholas Bellinger }
721e48354ceSNicholas Bellinger 
722e48354ceSNicholas Bellinger /* End items for lio_target_acl_cit */
723e48354ceSNicholas Bellinger 
724e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_attrib_cit */
725e48354ceSNicholas Bellinger 
726e48354ceSNicholas Bellinger #define DEF_TPG_ATTRIB(name)						\
727e48354ceSNicholas Bellinger 									\
7282eafd729SChristoph Hellwig static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item,	\
729e48354ceSNicholas Bellinger 		char *page)						\
730e48354ceSNicholas Bellinger {									\
7312eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = attrib_to_tpg(item);		\
732e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
733e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);	\
734e48354ceSNicholas Bellinger 	ssize_t rb;							\
735e48354ceSNicholas Bellinger 									\
736e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
737e48354ceSNicholas Bellinger 		return -EINVAL;						\
738e48354ceSNicholas Bellinger 									\
739b7eec2cdSAndy Grover 	rb = sprintf(page, "%u\n", tpg->tpg_attrib.name);		\
740e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
741e48354ceSNicholas Bellinger 	return rb;							\
742e48354ceSNicholas Bellinger }									\
743e48354ceSNicholas Bellinger 									\
7442eafd729SChristoph Hellwig static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
7452eafd729SChristoph Hellwig 		const char *page, size_t count)				\
746e48354ceSNicholas Bellinger {									\
7472eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = attrib_to_tpg(item);		\
748e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
749e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);	\
750e48354ceSNicholas Bellinger 	u32 val;							\
751e48354ceSNicholas Bellinger 	int ret;							\
752e48354ceSNicholas Bellinger 									\
753e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
754e48354ceSNicholas Bellinger 		return -EINVAL;						\
755e48354ceSNicholas Bellinger 									\
756ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &val);					\
757ad7babd2SJörn Engel 	if (ret)							\
758ad7babd2SJörn Engel 		goto out;						\
759e48354ceSNicholas Bellinger 	ret = iscsit_ta_##name(tpg, val);				\
760e48354ceSNicholas Bellinger 	if (ret < 0)							\
761e48354ceSNicholas Bellinger 		goto out;						\
762e48354ceSNicholas Bellinger 									\
763e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
764e48354ceSNicholas Bellinger 	return count;							\
765e48354ceSNicholas Bellinger out:									\
766e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
767e48354ceSNicholas Bellinger 	return ret;							\
7682eafd729SChristoph Hellwig }									\
7692eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
770e48354ceSNicholas Bellinger 
771e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(authentication);
772e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(login_timeout);
773e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(netif_timeout);
774e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(generate_node_acls);
775e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(default_cmdsn_depth);
776e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(cache_dynamic_acls);
777e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(demo_mode_write_protect);
778e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(prod_mode_write_protect);
7794c54b6cfSThomas Glanzmann DEF_TPG_ATTRIB(demo_mode_discovery);
780d1fa7a1dSNicholas Bellinger DEF_TPG_ATTRIB(default_erl);
7818085176fSSagi Grimberg DEF_TPG_ATTRIB(t10_pi);
782901c04a3SNicholas Bellinger DEF_TPG_ATTRIB(fabric_prot_type);
783a6415cddSDavid Disseldorp DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
784138d351eSNicholas Bellinger DEF_TPG_ATTRIB(login_keys_workaround);
785e48354ceSNicholas Bellinger 
786e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
7872eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_authentication,
7882eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_login_timeout,
7892eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_netif_timeout,
7902eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_generate_node_acls,
7912eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_default_cmdsn_depth,
7922eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_cache_dynamic_acls,
7932eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_demo_mode_write_protect,
7942eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_prod_mode_write_protect,
7952eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_demo_mode_discovery,
7962eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_default_erl,
7972eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_t10_pi,
7982eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_fabric_prot_type,
7992eafd729SChristoph Hellwig 	&iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
800138d351eSNicholas Bellinger 	&iscsi_tpg_attrib_attr_login_keys_workaround,
801e48354ceSNicholas Bellinger 	NULL,
802e48354ceSNicholas Bellinger };
803e48354ceSNicholas Bellinger 
804e48354ceSNicholas Bellinger /* End items for lio_target_tpg_attrib_cit */
805e48354ceSNicholas Bellinger 
806c3e51442SNicholas Bellinger /* Start items for lio_target_tpg_auth_cit */
807c3e51442SNicholas Bellinger 
808c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_STR(prefix, name, flags)					\
8092eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg,	\
810c3e51442SNicholas Bellinger 		char *page)							\
811c3e51442SNicholas Bellinger {										\
812c3e51442SNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
813c3e51442SNicholas Bellinger 				struct iscsi_portal_group, tpg_se_tpg);		\
814c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
815c3e51442SNicholas Bellinger 										\
816c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
817c3e51442SNicholas Bellinger 		return -EPERM;							\
818c3e51442SNicholas Bellinger 										\
819c3e51442SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", auth->name);			\
820c3e51442SNicholas Bellinger }										\
821c3e51442SNicholas Bellinger 										\
8222eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
8232eafd729SChristoph Hellwig 		const char *page, size_t count)					\
824c3e51442SNicholas Bellinger {										\
825c3e51442SNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
826c3e51442SNicholas Bellinger 				struct iscsi_portal_group, tpg_se_tpg);		\
827c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
828c3e51442SNicholas Bellinger 										\
829c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
830c3e51442SNicholas Bellinger 		return -EPERM;							\
831c3e51442SNicholas Bellinger 										\
83237b32c6fSNicholas Bellinger 	snprintf(auth->name, sizeof(auth->name), "%s", page);			\
833c3e51442SNicholas Bellinger 	if (!(strncmp("NULL", auth->name, 4)))					\
834c3e51442SNicholas Bellinger 		auth->naf_flags &= ~flags;					\
835c3e51442SNicholas Bellinger 	else									\
836c3e51442SNicholas Bellinger 		auth->naf_flags |= flags;					\
837c3e51442SNicholas Bellinger 										\
838c3e51442SNicholas Bellinger 	if ((auth->naf_flags & NAF_USERID_IN_SET) &&				\
839c3e51442SNicholas Bellinger 	    (auth->naf_flags & NAF_PASSWORD_IN_SET))				\
840c3e51442SNicholas Bellinger 		auth->authenticate_target = 1;					\
841c3e51442SNicholas Bellinger 	else									\
842c3e51442SNicholas Bellinger 		auth->authenticate_target = 0;					\
843c3e51442SNicholas Bellinger 										\
844c3e51442SNicholas Bellinger 	return count;								\
845c3e51442SNicholas Bellinger }
846c3e51442SNicholas Bellinger 
8472eafd729SChristoph Hellwig #define DEF_TPG_AUTH_STR(name, flags)						\
8482eafd729SChristoph Hellwig 	__DEF_TPG_AUTH_STR(tpg_auth, name, flags)				\
8492eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item,		\
8502eafd729SChristoph Hellwig 		char *page)							\
8512eafd729SChristoph Hellwig {										\
8522eafd729SChristoph Hellwig 	return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page);		\
8532eafd729SChristoph Hellwig }										\
8542eafd729SChristoph Hellwig 										\
8552eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item,		\
8562eafd729SChristoph Hellwig 		const char *page, size_t count)					\
8572eafd729SChristoph Hellwig {										\
8582eafd729SChristoph Hellwig 	return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count);	\
8592eafd729SChristoph Hellwig }										\
8602eafd729SChristoph Hellwig 										\
8612eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_auth_, name);
8622eafd729SChristoph Hellwig 
8632eafd729SChristoph Hellwig 
8642eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
8652eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
8662eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
8672eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
8682eafd729SChristoph Hellwig 
869c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_INT(prefix, name)					\
8702eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg,	\
871c3e51442SNicholas Bellinger 		char *page)								\
872c3e51442SNicholas Bellinger {										\
873c3e51442SNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
874c3e51442SNicholas Bellinger 				struct iscsi_portal_group, tpg_se_tpg);		\
875c3e51442SNicholas Bellinger 	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
876c3e51442SNicholas Bellinger 										\
877c3e51442SNicholas Bellinger 	if (!capable(CAP_SYS_ADMIN))						\
878c3e51442SNicholas Bellinger 		return -EPERM;							\
879c3e51442SNicholas Bellinger 										\
880c3e51442SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%d\n", auth->name);			\
881c3e51442SNicholas Bellinger }
882c3e51442SNicholas Bellinger 
883c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_INT(name)							\
884c3e51442SNicholas Bellinger 	__DEF_TPG_AUTH_INT(tpg_auth, name)					\
8852eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item,		\
886c3e51442SNicholas Bellinger 		char *page) \
887c3e51442SNicholas Bellinger {										\
8882eafd729SChristoph Hellwig 	return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page);		\
8892eafd729SChristoph Hellwig }										\
8902eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
891c3e51442SNicholas Bellinger 
892c3e51442SNicholas Bellinger DEF_TPG_AUTH_INT(authenticate_target);
893c3e51442SNicholas Bellinger 
894c3e51442SNicholas Bellinger static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
8952eafd729SChristoph Hellwig 	&iscsi_tpg_auth_attr_userid,
8962eafd729SChristoph Hellwig 	&iscsi_tpg_auth_attr_password,
8972eafd729SChristoph Hellwig 	&iscsi_tpg_auth_attr_authenticate_target,
8982eafd729SChristoph Hellwig 	&iscsi_tpg_auth_attr_userid_mutual,
8992eafd729SChristoph Hellwig 	&iscsi_tpg_auth_attr_password_mutual,
900c3e51442SNicholas Bellinger 	NULL,
901c3e51442SNicholas Bellinger };
902c3e51442SNicholas Bellinger 
903c3e51442SNicholas Bellinger /* End items for lio_target_tpg_auth_cit */
904c3e51442SNicholas Bellinger 
905e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_param_cit */
906e48354ceSNicholas Bellinger 
907e48354ceSNicholas Bellinger #define DEF_TPG_PARAM(name)						\
9082eafd729SChristoph Hellwig static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item,	\
909e48354ceSNicholas Bellinger 		char *page)						\
910e48354ceSNicholas Bellinger {									\
9112eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = param_to_tpg(item);		\
912e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
913e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);		\
914e48354ceSNicholas Bellinger 	struct iscsi_param *param;					\
915e48354ceSNicholas Bellinger 	ssize_t rb;							\
916e48354ceSNicholas Bellinger 									\
917e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0)					\
918e48354ceSNicholas Bellinger 		return -EINVAL;						\
919e48354ceSNicholas Bellinger 									\
920e48354ceSNicholas Bellinger 	param = iscsi_find_param_from_key(__stringify(name),		\
921e48354ceSNicholas Bellinger 				tpg->param_list);			\
922e48354ceSNicholas Bellinger 	if (!param) {							\
923e48354ceSNicholas Bellinger 		iscsit_put_tpg(tpg);					\
924e48354ceSNicholas Bellinger 		return -EINVAL;						\
925e48354ceSNicholas Bellinger 	}								\
926e48354ceSNicholas Bellinger 	rb = snprintf(page, PAGE_SIZE, "%s\n", param->value);		\
927e48354ceSNicholas Bellinger 									\
928e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
929e48354ceSNicholas Bellinger 	return rb;							\
930e48354ceSNicholas Bellinger }									\
9312eafd729SChristoph Hellwig static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
9322eafd729SChristoph Hellwig 		const char *page, size_t count)				\
933e48354ceSNicholas Bellinger {									\
9342eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = param_to_tpg(item);		\
935e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
936e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);		\
937e48354ceSNicholas Bellinger 	char *buf;							\
938ad7babd2SJörn Engel 	int ret, len;							\
939e48354ceSNicholas Bellinger 									\
940e48354ceSNicholas Bellinger 	buf = kzalloc(PAGE_SIZE, GFP_KERNEL);				\
941e48354ceSNicholas Bellinger 	if (!buf)							\
942e48354ceSNicholas Bellinger 		return -ENOMEM;						\
943ad7babd2SJörn Engel 	len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page);	\
944ad7babd2SJörn Engel 	if (isspace(buf[len-1]))					\
945ad7babd2SJörn Engel 		buf[len-1] = '\0'; /* Kill newline */			\
946e48354ceSNicholas Bellinger 									\
947e48354ceSNicholas Bellinger 	if (iscsit_get_tpg(tpg) < 0) {					\
948e48354ceSNicholas Bellinger 		kfree(buf);						\
949e48354ceSNicholas Bellinger 		return -EINVAL;						\
950e48354ceSNicholas Bellinger 	}								\
951e48354ceSNicholas Bellinger 									\
952e48354ceSNicholas Bellinger 	ret = iscsi_change_param_value(buf, tpg->param_list, 1);	\
953e48354ceSNicholas Bellinger 	if (ret < 0)							\
954e48354ceSNicholas Bellinger 		goto out;						\
955e48354ceSNicholas Bellinger 									\
956e48354ceSNicholas Bellinger 	kfree(buf);							\
957e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
958e48354ceSNicholas Bellinger 	return count;							\
959e48354ceSNicholas Bellinger out:									\
960e48354ceSNicholas Bellinger 	kfree(buf);							\
961e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);						\
962e48354ceSNicholas Bellinger 	return -EINVAL;							\
9632eafd729SChristoph Hellwig }									\
9642eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_param_, name)
965e48354ceSNicholas Bellinger 
966e48354ceSNicholas Bellinger DEF_TPG_PARAM(AuthMethod);
967e48354ceSNicholas Bellinger DEF_TPG_PARAM(HeaderDigest);
968e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataDigest);
969e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxConnections);
970e48354ceSNicholas Bellinger DEF_TPG_PARAM(TargetAlias);
971e48354ceSNicholas Bellinger DEF_TPG_PARAM(InitialR2T);
972e48354ceSNicholas Bellinger DEF_TPG_PARAM(ImmediateData);
973e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxRecvDataSegmentLength);
974e004cb25SNicholas Bellinger DEF_TPG_PARAM(MaxXmitDataSegmentLength);
975e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxBurstLength);
976e48354ceSNicholas Bellinger DEF_TPG_PARAM(FirstBurstLength);
977e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Wait);
978e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Retain);
979e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxOutstandingR2T);
980e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataPDUInOrder);
981e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataSequenceInOrder);
982e48354ceSNicholas Bellinger DEF_TPG_PARAM(ErrorRecoveryLevel);
983e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarker);
984e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarker);
985e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarkInt);
986e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarkInt);
987e48354ceSNicholas Bellinger 
988e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
9892eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_AuthMethod,
9902eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_HeaderDigest,
9912eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DataDigest,
9922eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxConnections,
9932eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_TargetAlias,
9942eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_InitialR2T,
9952eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_ImmediateData,
9962eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
9972eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
9982eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxBurstLength,
9992eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_FirstBurstLength,
10002eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DefaultTime2Wait,
10012eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DefaultTime2Retain,
10022eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_MaxOutstandingR2T,
10032eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DataPDUInOrder,
10042eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_DataSequenceInOrder,
10052eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_ErrorRecoveryLevel,
10062eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_IFMarker,
10072eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_OFMarker,
10082eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_IFMarkInt,
10092eafd729SChristoph Hellwig 	&iscsi_tpg_param_attr_OFMarkInt,
1010e48354ceSNicholas Bellinger 	NULL,
1011e48354ceSNicholas Bellinger };
1012e48354ceSNicholas Bellinger 
1013e48354ceSNicholas Bellinger /* End items for lio_target_tpg_param_cit */
1014e48354ceSNicholas Bellinger 
1015e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_cit */
1016e48354ceSNicholas Bellinger 
10172eafd729SChristoph Hellwig static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1018e48354ceSNicholas Bellinger {
10192eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = to_tpg(item);
1020e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,
1021e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);
1022e48354ceSNicholas Bellinger 	ssize_t len;
1023e48354ceSNicholas Bellinger 
1024e48354ceSNicholas Bellinger 	spin_lock(&tpg->tpg_state_lock);
1025e48354ceSNicholas Bellinger 	len = sprintf(page, "%d\n",
1026e48354ceSNicholas Bellinger 			(tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1027e48354ceSNicholas Bellinger 	spin_unlock(&tpg->tpg_state_lock);
1028e48354ceSNicholas Bellinger 
1029e48354ceSNicholas Bellinger 	return len;
1030e48354ceSNicholas Bellinger }
1031e48354ceSNicholas Bellinger 
10322eafd729SChristoph Hellwig static ssize_t lio_target_tpg_enable_store(struct config_item *item,
10332eafd729SChristoph Hellwig 		const char *page, size_t count)
1034e48354ceSNicholas Bellinger {
10352eafd729SChristoph Hellwig 	struct se_portal_group *se_tpg = to_tpg(item);
1036e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,
1037e48354ceSNicholas Bellinger 			struct iscsi_portal_group, tpg_se_tpg);
1038e48354ceSNicholas Bellinger 	u32 op;
1039ad7babd2SJörn Engel 	int ret;
1040e48354ceSNicholas Bellinger 
1041ad7babd2SJörn Engel 	ret = kstrtou32(page, 0, &op);
1042ad7babd2SJörn Engel 	if (ret)
1043ad7babd2SJörn Engel 		return ret;
1044e48354ceSNicholas Bellinger 	if ((op != 1) && (op != 0)) {
1045e48354ceSNicholas Bellinger 		pr_err("Illegal value for tpg_enable: %u\n", op);
1046e48354ceSNicholas Bellinger 		return -EINVAL;
1047e48354ceSNicholas Bellinger 	}
1048e48354ceSNicholas Bellinger 
1049e48354ceSNicholas Bellinger 	ret = iscsit_get_tpg(tpg);
1050e48354ceSNicholas Bellinger 	if (ret < 0)
1051e48354ceSNicholas Bellinger 		return -EINVAL;
1052e48354ceSNicholas Bellinger 
1053e48354ceSNicholas Bellinger 	if (op) {
1054e48354ceSNicholas Bellinger 		ret = iscsit_tpg_enable_portal_group(tpg);
1055e48354ceSNicholas Bellinger 		if (ret < 0)
1056e48354ceSNicholas Bellinger 			goto out;
1057e48354ceSNicholas Bellinger 	} else {
1058e48354ceSNicholas Bellinger 		/*
1059e48354ceSNicholas Bellinger 		 * iscsit_tpg_disable_portal_group() assumes force=1
1060e48354ceSNicholas Bellinger 		 */
1061e48354ceSNicholas Bellinger 		ret = iscsit_tpg_disable_portal_group(tpg, 1);
1062e48354ceSNicholas Bellinger 		if (ret < 0)
1063e48354ceSNicholas Bellinger 			goto out;
1064e48354ceSNicholas Bellinger 	}
1065e48354ceSNicholas Bellinger 
1066e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
1067e48354ceSNicholas Bellinger 	return count;
1068e48354ceSNicholas Bellinger out:
1069e48354ceSNicholas Bellinger 	iscsit_put_tpg(tpg);
1070e48354ceSNicholas Bellinger 	return -EINVAL;
1071e48354ceSNicholas Bellinger }
1072e48354ceSNicholas Bellinger 
1073e48354ceSNicholas Bellinger 
10742eafd729SChristoph Hellwig static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1075d4ee46ffSNicholas Bellinger 		char *page)
1076d4ee46ffSNicholas Bellinger {
10772eafd729SChristoph Hellwig 	return target_show_dynamic_sessions(to_tpg(item), page);
1078d4ee46ffSNicholas Bellinger }
1079d4ee46ffSNicholas Bellinger 
10802eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_tpg_, enable);
10812eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1082d4ee46ffSNicholas Bellinger 
1083e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrs[] = {
10842eafd729SChristoph Hellwig 	&lio_target_tpg_attr_enable,
10852eafd729SChristoph Hellwig 	&lio_target_tpg_attr_dynamic_sessions,
1086e48354ceSNicholas Bellinger 	NULL,
1087e48354ceSNicholas Bellinger };
1088e48354ceSNicholas Bellinger 
1089e48354ceSNicholas Bellinger /* End items for lio_target_tpg_cit */
1090e48354ceSNicholas Bellinger 
1091e48354ceSNicholas Bellinger /* Start items for lio_target_tiqn_cit */
1092e48354ceSNicholas Bellinger 
1093fceb5bc7SChristoph Hellwig static struct se_portal_group *lio_target_tiqn_addtpg(
1094e48354ceSNicholas Bellinger 	struct se_wwn *wwn,
1095e48354ceSNicholas Bellinger 	struct config_group *group,
1096e48354ceSNicholas Bellinger 	const char *name)
1097e48354ceSNicholas Bellinger {
1098e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
1099e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1100ad7babd2SJörn Engel 	char *tpgt_str;
1101ad7babd2SJörn Engel 	int ret;
1102ad7babd2SJörn Engel 	u16 tpgt;
1103e48354ceSNicholas Bellinger 
1104e48354ceSNicholas Bellinger 	tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1105e48354ceSNicholas Bellinger 	/*
1106e48354ceSNicholas Bellinger 	 * Only tpgt_# directory groups can be created below
1107e48354ceSNicholas Bellinger 	 * target/iscsi/iqn.superturodiskarry/
1108e48354ceSNicholas Bellinger 	 */
1109e48354ceSNicholas Bellinger 	tpgt_str = strstr(name, "tpgt_");
1110e48354ceSNicholas Bellinger 	if (!tpgt_str) {
1111e48354ceSNicholas Bellinger 		pr_err("Unable to locate \"tpgt_#\" directory"
1112e48354ceSNicholas Bellinger 				" group\n");
1113e48354ceSNicholas Bellinger 		return NULL;
1114e48354ceSNicholas Bellinger 	}
1115e48354ceSNicholas Bellinger 	tpgt_str += 5; /* Skip ahead of "tpgt_" */
1116ad7babd2SJörn Engel 	ret = kstrtou16(tpgt_str, 0, &tpgt);
1117ad7babd2SJörn Engel 	if (ret)
1118ad7babd2SJörn Engel 		return NULL;
1119e48354ceSNicholas Bellinger 
1120e48354ceSNicholas Bellinger 	tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1121e48354ceSNicholas Bellinger 	if (!tpg)
1122e48354ceSNicholas Bellinger 		return NULL;
1123e48354ceSNicholas Bellinger 
1124bc0c94b1SNicholas Bellinger 	ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1125e48354ceSNicholas Bellinger 	if (ret < 0)
112612d5a43bStangwenji 		goto free_out;
1127e48354ceSNicholas Bellinger 
1128e48354ceSNicholas Bellinger 	ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1129e48354ceSNicholas Bellinger 	if (ret != 0)
1130e48354ceSNicholas Bellinger 		goto out;
1131e48354ceSNicholas Bellinger 
1132e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1133e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1134e48354ceSNicholas Bellinger 			name);
1135e48354ceSNicholas Bellinger 	return &tpg->tpg_se_tpg;
1136e48354ceSNicholas Bellinger out:
1137e48354ceSNicholas Bellinger 	core_tpg_deregister(&tpg->tpg_se_tpg);
113812d5a43bStangwenji free_out:
1139e48354ceSNicholas Bellinger 	kfree(tpg);
1140e48354ceSNicholas Bellinger 	return NULL;
1141e48354ceSNicholas Bellinger }
1142e48354ceSNicholas Bellinger 
1143fceb5bc7SChristoph Hellwig static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1144e48354ceSNicholas Bellinger {
1145e48354ceSNicholas Bellinger 	struct iscsi_portal_group *tpg;
1146e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1147e48354ceSNicholas Bellinger 
1148e48354ceSNicholas Bellinger 	tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1149e48354ceSNicholas Bellinger 	tiqn = tpg->tpg_tiqn;
1150e48354ceSNicholas Bellinger 	/*
1151e48354ceSNicholas Bellinger 	 * iscsit_tpg_del_portal_group() assumes force=1
1152e48354ceSNicholas Bellinger 	 */
1153e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1154e48354ceSNicholas Bellinger 	iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1155e48354ceSNicholas Bellinger }
1156e48354ceSNicholas Bellinger 
1157e48354ceSNicholas Bellinger /* End items for lio_target_tiqn_cit */
1158e48354ceSNicholas Bellinger 
1159e48354ceSNicholas Bellinger /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1160e48354ceSNicholas Bellinger 
11612eafd729SChristoph Hellwig static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1162e48354ceSNicholas Bellinger 		char *page)
1163e48354ceSNicholas Bellinger {
11644c76251eSNicholas Bellinger 	return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1165e48354ceSNicholas Bellinger }
1166e48354ceSNicholas Bellinger 
11672eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1168e48354ceSNicholas Bellinger 
1169e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_wwn_attrs[] = {
11702eafd729SChristoph Hellwig 	&lio_target_wwn_attr_lio_version,
1171e48354ceSNicholas Bellinger 	NULL,
1172e48354ceSNicholas Bellinger };
1173e48354ceSNicholas Bellinger 
1174fceb5bc7SChristoph Hellwig static struct se_wwn *lio_target_call_coreaddtiqn(
1175e48354ceSNicholas Bellinger 	struct target_fabric_configfs *tf,
1176e48354ceSNicholas Bellinger 	struct config_group *group,
1177e48354ceSNicholas Bellinger 	const char *name)
1178e48354ceSNicholas Bellinger {
1179e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn;
1180e48354ceSNicholas Bellinger 
1181e48354ceSNicholas Bellinger 	tiqn = iscsit_add_tiqn((unsigned char *)name);
1182e48354ceSNicholas Bellinger 	if (IS_ERR(tiqn))
1183e1750ba2SThomas Meyer 		return ERR_CAST(tiqn);
1184e48354ceSNicholas Bellinger 
1185839559e1SChristoph Hellwig 	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1186839559e1SChristoph Hellwig 	pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1187839559e1SChristoph Hellwig 			" %s\n", name);
1188839559e1SChristoph Hellwig 	return &tiqn->tiqn_wwn;
1189839559e1SChristoph Hellwig }
1190839559e1SChristoph Hellwig 
1191839559e1SChristoph Hellwig static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1192839559e1SChristoph Hellwig {
1193839559e1SChristoph Hellwig 	struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1194839559e1SChristoph Hellwig 
1195b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1196e48354ceSNicholas Bellinger 			"iscsi_instance", &iscsi_stat_instance_cit);
11971ae1602dSChristoph Hellwig 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
11981ae1602dSChristoph Hellwig 			&tiqn->tiqn_wwn.fabric_stat_group);
11991ae1602dSChristoph Hellwig 
1200b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1201e48354ceSNicholas Bellinger 			"iscsi_sess_err", &iscsi_stat_sess_err_cit);
12021ae1602dSChristoph Hellwig 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
12031ae1602dSChristoph Hellwig 			&tiqn->tiqn_wwn.fabric_stat_group);
12041ae1602dSChristoph Hellwig 
1205b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1206e48354ceSNicholas Bellinger 			"iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
12071ae1602dSChristoph Hellwig 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
12081ae1602dSChristoph Hellwig 			&tiqn->tiqn_wwn.fabric_stat_group);
12091ae1602dSChristoph Hellwig 
1210b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1211e48354ceSNicholas Bellinger 			"iscsi_login_stats", &iscsi_stat_login_cit);
12121ae1602dSChristoph Hellwig 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
12131ae1602dSChristoph Hellwig 			&tiqn->tiqn_wwn.fabric_stat_group);
12141ae1602dSChristoph Hellwig 
1215b7eec2cdSAndy Grover 	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1216e48354ceSNicholas Bellinger 			"iscsi_logout_stats", &iscsi_stat_logout_cit);
12171ae1602dSChristoph Hellwig 	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
12181ae1602dSChristoph Hellwig 			&tiqn->tiqn_wwn.fabric_stat_group);
1219e48354ceSNicholas Bellinger }
1220e48354ceSNicholas Bellinger 
1221fceb5bc7SChristoph Hellwig static void lio_target_call_coredeltiqn(
1222e48354ceSNicholas Bellinger 	struct se_wwn *wwn)
1223e48354ceSNicholas Bellinger {
1224e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1225e48354ceSNicholas Bellinger 
1226e48354ceSNicholas Bellinger 	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1227e48354ceSNicholas Bellinger 			tiqn->tiqn);
1228e48354ceSNicholas Bellinger 	iscsit_del_tiqn(tiqn);
1229e48354ceSNicholas Bellinger }
1230e48354ceSNicholas Bellinger 
1231e48354ceSNicholas Bellinger /* End LIO-Target TIQN struct contig_lio_target_cit */
1232e48354ceSNicholas Bellinger 
1233e48354ceSNicholas Bellinger /* Start lio_target_discovery_auth_cit */
1234e48354ceSNicholas Bellinger 
1235e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_STR(name, flags)					\
1236e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_STR(disc, name, flags)				\
12372eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1238e48354ceSNicholas Bellinger {									\
12392eafd729SChristoph Hellwig 	return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1240e48354ceSNicholas Bellinger 		page);							\
1241e48354ceSNicholas Bellinger }									\
12422eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_store(struct config_item *item,	\
12432eafd729SChristoph Hellwig 		const char *page, size_t count)				\
1244e48354ceSNicholas Bellinger {									\
12452eafd729SChristoph Hellwig 	return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl,	\
1246e48354ceSNicholas Bellinger 		page, count);						\
12472eafd729SChristoph Hellwig 									\
12482eafd729SChristoph Hellwig }									\
12492eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_disc_, name)
12502eafd729SChristoph Hellwig 
12512eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
12522eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
12532eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
12542eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1255e48354ceSNicholas Bellinger 
1256e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_INT(name)						\
1257e48354ceSNicholas Bellinger 	__DEF_NACL_AUTH_INT(disc, name)					\
12582eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1259e48354ceSNicholas Bellinger {									\
12602eafd729SChristoph Hellwig 	return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1261e48354ceSNicholas Bellinger 			page);						\
12622eafd729SChristoph Hellwig }									\
12632eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_disc_, name)
1264e48354ceSNicholas Bellinger 
1265e48354ceSNicholas Bellinger DEF_DISC_AUTH_INT(authenticate_target);
1266e48354ceSNicholas Bellinger 
12672eafd729SChristoph Hellwig 
12682eafd729SChristoph Hellwig static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1269e48354ceSNicholas Bellinger 		char *page)
1270e48354ceSNicholas Bellinger {
1271e48354ceSNicholas Bellinger 	struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1272e48354ceSNicholas Bellinger 
1273e48354ceSNicholas Bellinger 	return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1274e48354ceSNicholas Bellinger }
1275e48354ceSNicholas Bellinger 
12762eafd729SChristoph Hellwig static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
12772eafd729SChristoph Hellwig 		const char *page, size_t count)
1278e48354ceSNicholas Bellinger {
1279e48354ceSNicholas Bellinger 	struct iscsi_param *param;
1280e48354ceSNicholas Bellinger 	struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1281e48354ceSNicholas Bellinger 	u32 op;
1282ad7babd2SJörn Engel 	int err;
1283e48354ceSNicholas Bellinger 
1284ad7babd2SJörn Engel 	err = kstrtou32(page, 0, &op);
1285ad7babd2SJörn Engel 	if (err)
1286ad7babd2SJörn Engel 		return -EINVAL;
1287e48354ceSNicholas Bellinger 	if ((op != 1) && (op != 0)) {
1288e48354ceSNicholas Bellinger 		pr_err("Illegal value for enforce_discovery_auth:"
1289e48354ceSNicholas Bellinger 				" %u\n", op);
1290e48354ceSNicholas Bellinger 		return -EINVAL;
1291e48354ceSNicholas Bellinger 	}
1292e48354ceSNicholas Bellinger 
1293e48354ceSNicholas Bellinger 	if (!discovery_tpg) {
1294e48354ceSNicholas Bellinger 		pr_err("iscsit_global->discovery_tpg is NULL\n");
1295e48354ceSNicholas Bellinger 		return -EINVAL;
1296e48354ceSNicholas Bellinger 	}
1297e48354ceSNicholas Bellinger 
1298e48354ceSNicholas Bellinger 	param = iscsi_find_param_from_key(AUTHMETHOD,
1299e48354ceSNicholas Bellinger 				discovery_tpg->param_list);
1300e48354ceSNicholas Bellinger 	if (!param)
1301e48354ceSNicholas Bellinger 		return -EINVAL;
1302e48354ceSNicholas Bellinger 
1303e48354ceSNicholas Bellinger 	if (op) {
1304e48354ceSNicholas Bellinger 		/*
1305e48354ceSNicholas Bellinger 		 * Reset the AuthMethod key to CHAP.
1306e48354ceSNicholas Bellinger 		 */
1307e48354ceSNicholas Bellinger 		if (iscsi_update_param_value(param, CHAP) < 0)
1308e48354ceSNicholas Bellinger 			return -EINVAL;
1309e48354ceSNicholas Bellinger 
1310e48354ceSNicholas Bellinger 		discovery_tpg->tpg_attrib.authentication = 1;
1311e48354ceSNicholas Bellinger 		iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1312e48354ceSNicholas Bellinger 		pr_debug("LIO-CORE[0] Successfully enabled"
1313e48354ceSNicholas Bellinger 			" authentication enforcement for iSCSI"
1314e48354ceSNicholas Bellinger 			" Discovery TPG\n");
1315e48354ceSNicholas Bellinger 	} else {
1316e48354ceSNicholas Bellinger 		/*
1317e48354ceSNicholas Bellinger 		 * Reset the AuthMethod key to CHAP,None
1318e48354ceSNicholas Bellinger 		 */
1319e48354ceSNicholas Bellinger 		if (iscsi_update_param_value(param, "CHAP,None") < 0)
1320e48354ceSNicholas Bellinger 			return -EINVAL;
1321e48354ceSNicholas Bellinger 
1322e48354ceSNicholas Bellinger 		discovery_tpg->tpg_attrib.authentication = 0;
1323e48354ceSNicholas Bellinger 		iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1324e48354ceSNicholas Bellinger 		pr_debug("LIO-CORE[0] Successfully disabled"
1325e48354ceSNicholas Bellinger 			" authentication enforcement for iSCSI"
1326e48354ceSNicholas Bellinger 			" Discovery TPG\n");
1327e48354ceSNicholas Bellinger 	}
1328e48354ceSNicholas Bellinger 
1329e48354ceSNicholas Bellinger 	return count;
1330e48354ceSNicholas Bellinger }
1331e48354ceSNicholas Bellinger 
13322eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1333e48354ceSNicholas Bellinger 
1334e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
13352eafd729SChristoph Hellwig 	&iscsi_disc_attr_userid,
13362eafd729SChristoph Hellwig 	&iscsi_disc_attr_password,
13372eafd729SChristoph Hellwig 	&iscsi_disc_attr_authenticate_target,
13382eafd729SChristoph Hellwig 	&iscsi_disc_attr_userid_mutual,
13392eafd729SChristoph Hellwig 	&iscsi_disc_attr_password_mutual,
13402eafd729SChristoph Hellwig 	&iscsi_disc_attr_enforce_discovery_auth,
1341e48354ceSNicholas Bellinger 	NULL,
1342e48354ceSNicholas Bellinger };
1343e48354ceSNicholas Bellinger 
1344e48354ceSNicholas Bellinger /* End lio_target_discovery_auth_cit */
1345e48354ceSNicholas Bellinger 
1346e48354ceSNicholas Bellinger /* Start functions for target_core_fabric_ops */
1347e48354ceSNicholas Bellinger 
1348e48354ceSNicholas Bellinger static char *iscsi_get_fabric_name(void)
1349e48354ceSNicholas Bellinger {
1350e48354ceSNicholas Bellinger 	return "iSCSI";
1351e48354ceSNicholas Bellinger }
1352e48354ceSNicholas Bellinger 
1353e48354ceSNicholas Bellinger static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1354e48354ceSNicholas Bellinger {
1355e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1356e48354ceSNicholas Bellinger 
1357e48354ceSNicholas Bellinger 	return cmd->i_state;
1358e48354ceSNicholas Bellinger }
1359e48354ceSNicholas Bellinger 
1360e48354ceSNicholas Bellinger static u32 lio_sess_get_index(struct se_session *se_sess)
1361e48354ceSNicholas Bellinger {
1362e48354ceSNicholas Bellinger 	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1363e48354ceSNicholas Bellinger 
1364e48354ceSNicholas Bellinger 	return sess->session_index;
1365e48354ceSNicholas Bellinger }
1366e48354ceSNicholas Bellinger 
1367e48354ceSNicholas Bellinger static u32 lio_sess_get_initiator_sid(
1368e48354ceSNicholas Bellinger 	struct se_session *se_sess,
1369e48354ceSNicholas Bellinger 	unsigned char *buf,
1370e48354ceSNicholas Bellinger 	u32 size)
1371e48354ceSNicholas Bellinger {
1372e48354ceSNicholas Bellinger 	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1373e48354ceSNicholas Bellinger 	/*
1374e48354ceSNicholas Bellinger 	 * iSCSI Initiator Session Identifier from RFC-3720.
1375e48354ceSNicholas Bellinger 	 */
13765cdf5a87SAndy Shevchenko 	return snprintf(buf, size, "%6phN", sess->isid);
1377e48354ceSNicholas Bellinger }
1378e48354ceSNicholas Bellinger 
1379e48354ceSNicholas Bellinger static int lio_queue_data_in(struct se_cmd *se_cmd)
1380e48354ceSNicholas Bellinger {
1381e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1382a4467018SNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
1383e48354ceSNicholas Bellinger 
1384e48354ceSNicholas Bellinger 	cmd->i_state = ISTATE_SEND_DATAIN;
1385a4467018SNicholas Bellinger 	return conn->conn_transport->iscsit_queue_data_in(conn, cmd);
1386e48354ceSNicholas Bellinger }
1387e48354ceSNicholas Bellinger 
1388e48354ceSNicholas Bellinger static int lio_write_pending(struct se_cmd *se_cmd)
1389e48354ceSNicholas Bellinger {
1390e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
13913e1c81a9SNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
1392e48354ceSNicholas Bellinger 
1393e48354ceSNicholas Bellinger 	if (!cmd->immediate_data && !cmd->unsolicited_data)
13943e1c81a9SNicholas Bellinger 		return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1395e48354ceSNicholas Bellinger 
1396e48354ceSNicholas Bellinger 	return 0;
1397e48354ceSNicholas Bellinger }
1398e48354ceSNicholas Bellinger 
1399e48354ceSNicholas Bellinger static int lio_write_pending_status(struct se_cmd *se_cmd)
1400e48354ceSNicholas Bellinger {
1401e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1402e48354ceSNicholas Bellinger 	int ret;
1403e48354ceSNicholas Bellinger 
1404e48354ceSNicholas Bellinger 	spin_lock_bh(&cmd->istate_lock);
1405e48354ceSNicholas Bellinger 	ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1406e48354ceSNicholas Bellinger 	spin_unlock_bh(&cmd->istate_lock);
1407e48354ceSNicholas Bellinger 
1408e48354ceSNicholas Bellinger 	return ret;
1409e48354ceSNicholas Bellinger }
1410e48354ceSNicholas Bellinger 
1411e48354ceSNicholas Bellinger static int lio_queue_status(struct se_cmd *se_cmd)
1412e48354ceSNicholas Bellinger {
1413e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1414a4467018SNicholas Bellinger 	struct iscsi_conn *conn = cmd->conn;
1415e48354ceSNicholas Bellinger 
1416e48354ceSNicholas Bellinger 	cmd->i_state = ISTATE_SEND_STATUS;
14175e8e6b4bSNicholas Bellinger 
14185e8e6b4bSNicholas Bellinger 	if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1419a4467018SNicholas Bellinger 		return iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
14205e8e6b4bSNicholas Bellinger 	}
1421a4467018SNicholas Bellinger 	return conn->conn_transport->iscsit_queue_status(conn, cmd);
1422e48354ceSNicholas Bellinger }
1423e48354ceSNicholas Bellinger 
1424b79fafacSJoern Engel static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1425e48354ceSNicholas Bellinger {
1426e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1427e48354ceSNicholas Bellinger 
1428e48354ceSNicholas Bellinger 	cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1429e48354ceSNicholas Bellinger 	iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1430e48354ceSNicholas Bellinger }
1431e48354ceSNicholas Bellinger 
1432131e6abcSNicholas Bellinger static void lio_aborted_task(struct se_cmd *se_cmd)
1433131e6abcSNicholas Bellinger {
1434131e6abcSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1435131e6abcSNicholas Bellinger 
1436131e6abcSNicholas Bellinger 	cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1437131e6abcSNicholas Bellinger }
1438131e6abcSNicholas Bellinger 
14392b6eb609SChristoph Hellwig static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
14402b6eb609SChristoph Hellwig {
14412b6eb609SChristoph Hellwig 	return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
14422b6eb609SChristoph Hellwig }
14432b6eb609SChristoph Hellwig 
1444e48354ceSNicholas Bellinger static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1445e48354ceSNicholas Bellinger {
14462b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1447e48354ceSNicholas Bellinger }
1448e48354ceSNicholas Bellinger 
1449e48354ceSNicholas Bellinger static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1450e48354ceSNicholas Bellinger {
14512b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpgt;
1452e48354ceSNicholas Bellinger }
1453e48354ceSNicholas Bellinger 
1454e48354ceSNicholas Bellinger static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1455e48354ceSNicholas Bellinger {
14562b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1457e48354ceSNicholas Bellinger }
1458e48354ceSNicholas Bellinger 
1459e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1460e48354ceSNicholas Bellinger {
14612b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1462e48354ceSNicholas Bellinger }
1463e48354ceSNicholas Bellinger 
1464e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1465e48354ceSNicholas Bellinger {
14662b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1467e48354ceSNicholas Bellinger }
1468e48354ceSNicholas Bellinger 
1469e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_write_protect(
1470e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg)
1471e48354ceSNicholas Bellinger {
14722b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1473e48354ceSNicholas Bellinger }
1474e48354ceSNicholas Bellinger 
1475e48354ceSNicholas Bellinger static int lio_tpg_check_prod_mode_write_protect(
1476e48354ceSNicholas Bellinger 	struct se_portal_group *se_tpg)
1477e48354ceSNicholas Bellinger {
14782b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1479e48354ceSNicholas Bellinger }
1480e48354ceSNicholas Bellinger 
1481901c04a3SNicholas Bellinger static int lio_tpg_check_prot_fabric_only(
1482901c04a3SNicholas Bellinger 	struct se_portal_group *se_tpg)
1483901c04a3SNicholas Bellinger {
1484901c04a3SNicholas Bellinger 	/*
1485901c04a3SNicholas Bellinger 	 * Only report fabric_prot_type if t10_pi has also been enabled
1486901c04a3SNicholas Bellinger 	 * for incoming ib_isert sessions.
1487901c04a3SNicholas Bellinger 	 */
14882b6eb609SChristoph Hellwig 	if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1489901c04a3SNicholas Bellinger 		return 0;
14902b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1491901c04a3SNicholas Bellinger }
1492901c04a3SNicholas Bellinger 
1493e48354ceSNicholas Bellinger /*
1494d36ad77fSNicholas Bellinger  * This function calls iscsit_inc_session_usage_count() on the
1495e48354ceSNicholas Bellinger  * struct iscsi_session in question.
1496e48354ceSNicholas Bellinger  */
149744f33d0fSChristoph Hellwig static void lio_tpg_close_session(struct se_session *se_sess)
1498e48354ceSNicholas Bellinger {
1499e48354ceSNicholas Bellinger 	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1500d36ad77fSNicholas Bellinger 	struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
150126a99c19SNicholas Bellinger 
1502d36ad77fSNicholas Bellinger 	spin_lock_bh(&se_tpg->session_lock);
1503e48354ceSNicholas Bellinger 	spin_lock(&sess->conn_lock);
1504e48354ceSNicholas Bellinger 	if (atomic_read(&sess->session_fall_back_to_erl0) ||
1505e48354ceSNicholas Bellinger 	    atomic_read(&sess->session_logout) ||
1506e48354ceSNicholas Bellinger 	    (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1507e48354ceSNicholas Bellinger 		spin_unlock(&sess->conn_lock);
1508d36ad77fSNicholas Bellinger 		spin_unlock_bh(&se_tpg->session_lock);
150944f33d0fSChristoph Hellwig 		return;
1510e48354ceSNicholas Bellinger 	}
1511e48354ceSNicholas Bellinger 	atomic_set(&sess->session_reinstatement, 1);
1512197b806aSNicholas Bellinger 	atomic_set(&sess->session_fall_back_to_erl0, 1);
1513e48354ceSNicholas Bellinger 	spin_unlock(&sess->conn_lock);
1514e48354ceSNicholas Bellinger 
1515e48354ceSNicholas Bellinger 	iscsit_stop_time2retain_timer(sess);
1516d36ad77fSNicholas Bellinger 	spin_unlock_bh(&se_tpg->session_lock);
151726a99c19SNicholas Bellinger 
151899367f01SNicholas Bellinger 	iscsit_stop_session(sess, 1, 1);
1519e48354ceSNicholas Bellinger 	iscsit_close_session(sess);
1520e48354ceSNicholas Bellinger }
1521e48354ceSNicholas Bellinger 
1522e48354ceSNicholas Bellinger static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1523e48354ceSNicholas Bellinger {
15242b6eb609SChristoph Hellwig 	return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1525e48354ceSNicholas Bellinger }
1526e48354ceSNicholas Bellinger 
1527e48354ceSNicholas Bellinger static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1528e48354ceSNicholas Bellinger {
1529e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1530e48354ceSNicholas Bellinger 				se_node_acl);
1531d1fa7a1dSNicholas Bellinger 	struct se_portal_group *se_tpg = se_acl->se_tpg;
1532d1fa7a1dSNicholas Bellinger 	struct iscsi_portal_group *tpg = container_of(se_tpg,
1533d1fa7a1dSNicholas Bellinger 				struct iscsi_portal_group, tpg_se_tpg);
1534e48354ceSNicholas Bellinger 
1535b7eec2cdSAndy Grover 	acl->node_attrib.nacl = acl;
1536d1fa7a1dSNicholas Bellinger 	iscsit_set_default_node_attribues(acl, tpg);
1537e48354ceSNicholas Bellinger }
1538e48354ceSNicholas Bellinger 
15393e1c81a9SNicholas Bellinger static int lio_check_stop_free(struct se_cmd *se_cmd)
15403e1c81a9SNicholas Bellinger {
1541afc16604SBart Van Assche 	return target_put_sess_cmd(se_cmd);
15423e1c81a9SNicholas Bellinger }
15433e1c81a9SNicholas Bellinger 
1544e48354ceSNicholas Bellinger static void lio_release_cmd(struct se_cmd *se_cmd)
1545e48354ceSNicholas Bellinger {
1546e48354ceSNicholas Bellinger 	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1547e48354ceSNicholas Bellinger 
1548cdb72665SNicholas Bellinger 	pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1549ed88f055SBart Van Assche 	__iscsit_free_cmd(cmd, true);
1550d703ce2fSNicholas Bellinger 	iscsit_release_cmd(cmd);
1551e48354ceSNicholas Bellinger }
1552e48354ceSNicholas Bellinger 
15539ac8928eSChristoph Hellwig const struct target_core_fabric_ops iscsi_ops = {
15549ac8928eSChristoph Hellwig 	.module				= THIS_MODULE,
15559ac8928eSChristoph Hellwig 	.name				= "iscsi",
1556144bc4c2SChristoph Hellwig 	.node_acl_size			= sizeof(struct iscsi_node_acl),
15579ac8928eSChristoph Hellwig 	.get_fabric_name		= iscsi_get_fabric_name,
15589ac8928eSChristoph Hellwig 	.tpg_get_wwn			= lio_tpg_get_endpoint_wwn,
15599ac8928eSChristoph Hellwig 	.tpg_get_tag			= lio_tpg_get_tag,
15609ac8928eSChristoph Hellwig 	.tpg_get_default_depth		= lio_tpg_get_default_depth,
15619ac8928eSChristoph Hellwig 	.tpg_check_demo_mode		= lio_tpg_check_demo_mode,
15629ac8928eSChristoph Hellwig 	.tpg_check_demo_mode_cache	= lio_tpg_check_demo_mode_cache,
15639ac8928eSChristoph Hellwig 	.tpg_check_demo_mode_write_protect =
15649ac8928eSChristoph Hellwig 			lio_tpg_check_demo_mode_write_protect,
15659ac8928eSChristoph Hellwig 	.tpg_check_prod_mode_write_protect =
15669ac8928eSChristoph Hellwig 			lio_tpg_check_prod_mode_write_protect,
15679ac8928eSChristoph Hellwig 	.tpg_check_prot_fabric_only	= &lio_tpg_check_prot_fabric_only,
15689ac8928eSChristoph Hellwig 	.tpg_get_inst_index		= lio_tpg_get_inst_index,
15699ac8928eSChristoph Hellwig 	.check_stop_free		= lio_check_stop_free,
15709ac8928eSChristoph Hellwig 	.release_cmd			= lio_release_cmd,
15719ac8928eSChristoph Hellwig 	.close_session			= lio_tpg_close_session,
15729ac8928eSChristoph Hellwig 	.sess_get_index			= lio_sess_get_index,
15739ac8928eSChristoph Hellwig 	.sess_get_initiator_sid		= lio_sess_get_initiator_sid,
15749ac8928eSChristoph Hellwig 	.write_pending			= lio_write_pending,
15759ac8928eSChristoph Hellwig 	.write_pending_status		= lio_write_pending_status,
15769ac8928eSChristoph Hellwig 	.set_default_node_attributes	= lio_set_default_node_attributes,
15779ac8928eSChristoph Hellwig 	.get_cmd_state			= iscsi_get_cmd_state,
15789ac8928eSChristoph Hellwig 	.queue_data_in			= lio_queue_data_in,
15799ac8928eSChristoph Hellwig 	.queue_status			= lio_queue_status,
15809ac8928eSChristoph Hellwig 	.queue_tm_rsp			= lio_queue_tm_rsp,
15819ac8928eSChristoph Hellwig 	.aborted_task			= lio_aborted_task,
15829ac8928eSChristoph Hellwig 	.fabric_make_wwn		= lio_target_call_coreaddtiqn,
15839ac8928eSChristoph Hellwig 	.fabric_drop_wwn		= lio_target_call_coredeltiqn,
1584839559e1SChristoph Hellwig 	.add_wwn_groups			= lio_target_add_wwn_groups,
15859ac8928eSChristoph Hellwig 	.fabric_make_tpg		= lio_target_tiqn_addtpg,
15869ac8928eSChristoph Hellwig 	.fabric_drop_tpg		= lio_target_tiqn_deltpg,
15879ac8928eSChristoph Hellwig 	.fabric_make_np			= lio_target_call_addnptotpg,
15889ac8928eSChristoph Hellwig 	.fabric_drop_np			= lio_target_call_delnpfromtpg,
1589c7d6a803SChristoph Hellwig 	.fabric_init_nodeacl		= lio_target_init_nodeacl,
1590e48354ceSNicholas Bellinger 
15919ac8928eSChristoph Hellwig 	.tfc_discovery_attrs		= lio_target_discovery_auth_attrs,
15929ac8928eSChristoph Hellwig 	.tfc_wwn_attrs			= lio_target_wwn_attrs,
15939ac8928eSChristoph Hellwig 	.tfc_tpg_base_attrs		= lio_target_tpg_attrs,
15949ac8928eSChristoph Hellwig 	.tfc_tpg_attrib_attrs		= lio_target_tpg_attrib_attrs,
15959ac8928eSChristoph Hellwig 	.tfc_tpg_auth_attrs		= lio_target_tpg_auth_attrs,
15969ac8928eSChristoph Hellwig 	.tfc_tpg_param_attrs		= lio_target_tpg_param_attrs,
15979ac8928eSChristoph Hellwig 	.tfc_tpg_np_base_attrs		= lio_target_portal_attrs,
15989ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_base_attrs	= lio_target_initiator_attrs,
15999ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_attrib_attrs	= lio_target_nacl_attrib_attrs,
16009ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_auth_attrs	= lio_target_nacl_auth_attrs,
16019ac8928eSChristoph Hellwig 	.tfc_tpg_nacl_param_attrs	= lio_target_nacl_param_attrs,
16029ac8928eSChristoph Hellwig };
1603