1 /*******************************************************************************
2  * Filename:  target_core_stat.c
3  *
4  * Modern ConfigFS group context specific statistics based on original
5  * target_core_mib.c code
6  *
7  * (c) Copyright 2006-2013 Datera, Inc.
8  *
9  * Nicholas A. Bellinger <nab@linux-iscsi.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  *
25  ******************************************************************************/
26 
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/delay.h>
30 #include <linux/timer.h>
31 #include <linux/string.h>
32 #include <linux/utsname.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/blkdev.h>
36 #include <linux/configfs.h>
37 #include <scsi/scsi.h>
38 #include <scsi/scsi_device.h>
39 #include <scsi/scsi_host.h>
40 
41 #include <target/target_core_base.h>
42 #include <target/target_core_backend.h>
43 #include <target/target_core_fabric.h>
44 #include <target/target_core_configfs.h>
45 #include <target/configfs_macros.h>
46 
47 #include "target_core_internal.h"
48 
49 #ifndef INITIAL_JIFFIES
50 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
51 #endif
52 
53 #define NONE		"None"
54 #define ISPRINT(a)   ((a >= ' ') && (a <= '~'))
55 
56 #define SCSI_LU_INDEX			1
57 #define LU_COUNT			1
58 
59 /*
60  * SCSI Device Table
61  */
62 
63 CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps);
64 #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode)				\
65 static struct target_stat_scsi_dev_attribute				\
66 			target_stat_scsi_dev_##_name =			\
67 	__CONFIGFS_EATTR(_name, _mode,					\
68 	target_stat_scsi_dev_show_attr_##_name,				\
69 	target_stat_scsi_dev_store_attr_##_name);
70 
71 #define DEV_STAT_SCSI_DEV_ATTR_RO(_name)				\
72 static struct target_stat_scsi_dev_attribute				\
73 			target_stat_scsi_dev_##_name =			\
74 	__CONFIGFS_EATTR_RO(_name,					\
75 	target_stat_scsi_dev_show_attr_##_name);
76 
77 static ssize_t target_stat_scsi_dev_show_attr_inst(
78 	struct se_dev_stat_grps *sgrps, char *page)
79 {
80 	struct se_device *dev =
81 		container_of(sgrps, struct se_device, dev_stat_grps);
82 	struct se_hba *hba = dev->se_hba;
83 
84 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
85 }
86 DEV_STAT_SCSI_DEV_ATTR_RO(inst);
87 
88 static ssize_t target_stat_scsi_dev_show_attr_indx(
89 	struct se_dev_stat_grps *sgrps, char *page)
90 {
91 	struct se_device *dev =
92 		container_of(sgrps, struct se_device, dev_stat_grps);
93 
94 	return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
95 }
96 DEV_STAT_SCSI_DEV_ATTR_RO(indx);
97 
98 static ssize_t target_stat_scsi_dev_show_attr_role(
99 	struct se_dev_stat_grps *sgrps, char *page)
100 {
101 	return snprintf(page, PAGE_SIZE, "Target\n");
102 }
103 DEV_STAT_SCSI_DEV_ATTR_RO(role);
104 
105 static ssize_t target_stat_scsi_dev_show_attr_ports(
106 	struct se_dev_stat_grps *sgrps, char *page)
107 {
108 	struct se_device *dev =
109 		container_of(sgrps, struct se_device, dev_stat_grps);
110 
111 	return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count);
112 }
113 DEV_STAT_SCSI_DEV_ATTR_RO(ports);
114 
115 CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group);
116 
117 static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
118 	&target_stat_scsi_dev_inst.attr,
119 	&target_stat_scsi_dev_indx.attr,
120 	&target_stat_scsi_dev_role.attr,
121 	&target_stat_scsi_dev_ports.attr,
122 	NULL,
123 };
124 
125 static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
126 	.show_attribute		= target_stat_scsi_dev_attr_show,
127 	.store_attribute	= target_stat_scsi_dev_attr_store,
128 };
129 
130 static struct config_item_type target_stat_scsi_dev_cit = {
131 	.ct_item_ops		= &target_stat_scsi_dev_attrib_ops,
132 	.ct_attrs		= target_stat_scsi_dev_attrs,
133 	.ct_owner		= THIS_MODULE,
134 };
135 
136 /*
137  * SCSI Target Device Table
138  */
139 
140 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps);
141 #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode)			\
142 static struct target_stat_scsi_tgt_dev_attribute			\
143 			target_stat_scsi_tgt_dev_##_name =		\
144 	__CONFIGFS_EATTR(_name, _mode,					\
145 	target_stat_scsi_tgt_dev_show_attr_##_name,			\
146 	target_stat_scsi_tgt_dev_store_attr_##_name);
147 
148 #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name)				\
149 static struct target_stat_scsi_tgt_dev_attribute			\
150 			target_stat_scsi_tgt_dev_##_name =		\
151 	__CONFIGFS_EATTR_RO(_name,					\
152 	target_stat_scsi_tgt_dev_show_attr_##_name);
153 
154 static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
155 	struct se_dev_stat_grps *sgrps, char *page)
156 {
157 	struct se_device *dev =
158 		container_of(sgrps, struct se_device, dev_stat_grps);
159 	struct se_hba *hba = dev->se_hba;
160 
161 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
162 }
163 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
164 
165 static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
166 	struct se_dev_stat_grps *sgrps, char *page)
167 {
168 	struct se_device *dev =
169 		container_of(sgrps, struct se_device, dev_stat_grps);
170 
171 	return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
172 }
173 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
174 
175 static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
176 	struct se_dev_stat_grps *sgrps, char *page)
177 {
178 	return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
179 }
180 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
181 
182 static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
183 	struct se_dev_stat_grps *sgrps, char *page)
184 {
185 	struct se_device *dev =
186 		container_of(sgrps, struct se_device, dev_stat_grps);
187 
188 	if (dev->export_count)
189 		return snprintf(page, PAGE_SIZE, "activated");
190 	else
191 		return snprintf(page, PAGE_SIZE, "deactivated");
192 }
193 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
194 
195 static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
196 	struct se_dev_stat_grps *sgrps, char *page)
197 {
198 	struct se_device *dev =
199 		container_of(sgrps, struct se_device, dev_stat_grps);
200 	int non_accessible_lus;
201 
202 	if (dev->export_count)
203 		non_accessible_lus = 0;
204 	else
205 		non_accessible_lus = 1;
206 
207 	return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
208 }
209 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
210 
211 static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
212 	struct se_dev_stat_grps *sgrps, char *page)
213 {
214 	struct se_device *dev =
215 		container_of(sgrps, struct se_device, dev_stat_grps);
216 
217 	return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
218 }
219 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);
220 
221 
222 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev, se_dev_stat_grps, scsi_tgt_dev_group);
223 
224 static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
225 	&target_stat_scsi_tgt_dev_inst.attr,
226 	&target_stat_scsi_tgt_dev_indx.attr,
227 	&target_stat_scsi_tgt_dev_num_lus.attr,
228 	&target_stat_scsi_tgt_dev_status.attr,
229 	&target_stat_scsi_tgt_dev_non_access_lus.attr,
230 	&target_stat_scsi_tgt_dev_resets.attr,
231 	NULL,
232 };
233 
234 static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops = {
235 	.show_attribute		= target_stat_scsi_tgt_dev_attr_show,
236 	.store_attribute	= target_stat_scsi_tgt_dev_attr_store,
237 };
238 
239 static struct config_item_type target_stat_scsi_tgt_dev_cit = {
240 	.ct_item_ops		= &target_stat_scsi_tgt_dev_attrib_ops,
241 	.ct_attrs		= target_stat_scsi_tgt_dev_attrs,
242 	.ct_owner		= THIS_MODULE,
243 };
244 
245 /*
246  * SCSI Logical Unit Table
247  */
248 
249 CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu, se_dev_stat_grps);
250 #define DEV_STAT_SCSI_LU_ATTR(_name, _mode)				\
251 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
252 	__CONFIGFS_EATTR(_name, _mode,					\
253 	target_stat_scsi_lu_show_attr_##_name,				\
254 	target_stat_scsi_lu_store_attr_##_name);
255 
256 #define DEV_STAT_SCSI_LU_ATTR_RO(_name)					\
257 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
258 	__CONFIGFS_EATTR_RO(_name,					\
259 	target_stat_scsi_lu_show_attr_##_name);
260 
261 static ssize_t target_stat_scsi_lu_show_attr_inst(
262 	struct se_dev_stat_grps *sgrps, char *page)
263 {
264 	struct se_device *dev =
265 		container_of(sgrps, struct se_device, dev_stat_grps);
266 	struct se_hba *hba = dev->se_hba;
267 
268 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
269 }
270 DEV_STAT_SCSI_LU_ATTR_RO(inst);
271 
272 static ssize_t target_stat_scsi_lu_show_attr_dev(
273 	struct se_dev_stat_grps *sgrps, char *page)
274 {
275 	struct se_device *dev =
276 		container_of(sgrps, struct se_device, dev_stat_grps);
277 
278 	return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
279 }
280 DEV_STAT_SCSI_LU_ATTR_RO(dev);
281 
282 static ssize_t target_stat_scsi_lu_show_attr_indx(
283 	struct se_dev_stat_grps *sgrps, char *page)
284 {
285 	return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
286 }
287 DEV_STAT_SCSI_LU_ATTR_RO(indx);
288 
289 static ssize_t target_stat_scsi_lu_show_attr_lun(
290 	struct se_dev_stat_grps *sgrps, char *page)
291 {
292 	/* FIXME: scsiLuDefaultLun */
293 	return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
294 }
295 DEV_STAT_SCSI_LU_ATTR_RO(lun);
296 
297 static ssize_t target_stat_scsi_lu_show_attr_lu_name(
298 	struct se_dev_stat_grps *sgrps, char *page)
299 {
300 	struct se_device *dev =
301 		container_of(sgrps, struct se_device, dev_stat_grps);
302 
303 	/* scsiLuWwnName */
304 	return snprintf(page, PAGE_SIZE, "%s\n",
305 			(strlen(dev->t10_wwn.unit_serial)) ?
306 			dev->t10_wwn.unit_serial : "None");
307 }
308 DEV_STAT_SCSI_LU_ATTR_RO(lu_name);
309 
310 static ssize_t target_stat_scsi_lu_show_attr_vend(
311 	struct se_dev_stat_grps *sgrps, char *page)
312 {
313 	struct se_device *dev =
314 		container_of(sgrps, struct se_device, dev_stat_grps);
315 	int i;
316 	char str[sizeof(dev->t10_wwn.vendor)+1];
317 
318 	/* scsiLuVendorId */
319 	for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
320 		str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ?
321 			dev->t10_wwn.vendor[i] : ' ';
322 	str[i] = '\0';
323 	return snprintf(page, PAGE_SIZE, "%s\n", str);
324 }
325 DEV_STAT_SCSI_LU_ATTR_RO(vend);
326 
327 static ssize_t target_stat_scsi_lu_show_attr_prod(
328 	struct se_dev_stat_grps *sgrps, char *page)
329 {
330 	struct se_device *dev =
331 		container_of(sgrps, struct se_device, dev_stat_grps);
332 	int i;
333 	char str[sizeof(dev->t10_wwn.model)+1];
334 
335 	/* scsiLuProductId */
336 	for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
337 		str[i] = ISPRINT(dev->t10_wwn.model[i]) ?
338 			dev->t10_wwn.model[i] : ' ';
339 	str[i] = '\0';
340 	return snprintf(page, PAGE_SIZE, "%s\n", str);
341 }
342 DEV_STAT_SCSI_LU_ATTR_RO(prod);
343 
344 static ssize_t target_stat_scsi_lu_show_attr_rev(
345 	struct se_dev_stat_grps *sgrps, char *page)
346 {
347 	struct se_device *dev =
348 		container_of(sgrps, struct se_device, dev_stat_grps);
349 	int i;
350 	char str[sizeof(dev->t10_wwn.revision)+1];
351 
352 	/* scsiLuRevisionId */
353 	for (i = 0; i < sizeof(dev->t10_wwn.revision); i++)
354 		str[i] = ISPRINT(dev->t10_wwn.revision[i]) ?
355 			dev->t10_wwn.revision[i] : ' ';
356 	str[i] = '\0';
357 	return snprintf(page, PAGE_SIZE, "%s\n", str);
358 }
359 DEV_STAT_SCSI_LU_ATTR_RO(rev);
360 
361 static ssize_t target_stat_scsi_lu_show_attr_dev_type(
362 	struct se_dev_stat_grps *sgrps, char *page)
363 {
364 	struct se_device *dev =
365 		container_of(sgrps, struct se_device, dev_stat_grps);
366 
367 	/* scsiLuPeripheralType */
368 	return snprintf(page, PAGE_SIZE, "%u\n",
369 			dev->transport->get_device_type(dev));
370 }
371 DEV_STAT_SCSI_LU_ATTR_RO(dev_type);
372 
373 static ssize_t target_stat_scsi_lu_show_attr_status(
374 	struct se_dev_stat_grps *sgrps, char *page)
375 {
376 	struct se_device *dev =
377 		container_of(sgrps, struct se_device, dev_stat_grps);
378 
379 	/* scsiLuStatus */
380 	return snprintf(page, PAGE_SIZE, "%s\n",
381 		(dev->export_count) ? "available" : "notavailable");
382 }
383 DEV_STAT_SCSI_LU_ATTR_RO(status);
384 
385 static ssize_t target_stat_scsi_lu_show_attr_state_bit(
386 	struct se_dev_stat_grps *sgrps, char *page)
387 {
388 	/* scsiLuState */
389 	return snprintf(page, PAGE_SIZE, "exposed\n");
390 }
391 DEV_STAT_SCSI_LU_ATTR_RO(state_bit);
392 
393 static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
394 	struct se_dev_stat_grps *sgrps, char *page)
395 {
396 	struct se_device *dev =
397 		container_of(sgrps, struct se_device, dev_stat_grps);
398 
399 	/* scsiLuNumCommands */
400 	return snprintf(page, PAGE_SIZE, "%llu\n",
401 			(unsigned long long)dev->num_cmds);
402 }
403 DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);
404 
405 static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
406 	struct se_dev_stat_grps *sgrps, char *page)
407 {
408 	struct se_device *dev =
409 		container_of(sgrps, struct se_device, dev_stat_grps);
410 
411 	/* scsiLuReadMegaBytes */
412 	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->read_bytes >> 20));
413 }
414 DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
415 
416 static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
417 	struct se_dev_stat_grps *sgrps, char *page)
418 {
419 	struct se_device *dev =
420 		container_of(sgrps, struct se_device, dev_stat_grps);
421 
422 	/* scsiLuWrittenMegaBytes */
423 	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->write_bytes >> 20));
424 }
425 DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
426 
427 static ssize_t target_stat_scsi_lu_show_attr_resets(
428 	struct se_dev_stat_grps *sgrps, char *page)
429 {
430 	struct se_device *dev =
431 		container_of(sgrps, struct se_device, dev_stat_grps);
432 
433 	/* scsiLuInResets */
434 	return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
435 }
436 DEV_STAT_SCSI_LU_ATTR_RO(resets);
437 
438 static ssize_t target_stat_scsi_lu_show_attr_full_stat(
439 	struct se_dev_stat_grps *sgrps, char *page)
440 {
441 	/* FIXME: scsiLuOutTaskSetFullStatus */
442 	return snprintf(page, PAGE_SIZE, "%u\n", 0);
443 }
444 DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
445 
446 static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
447 	struct se_dev_stat_grps *sgrps, char *page)
448 {
449 	/* FIXME: scsiLuHSInCommands */
450 	return snprintf(page, PAGE_SIZE, "%u\n", 0);
451 }
452 DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
453 
454 static ssize_t target_stat_scsi_lu_show_attr_creation_time(
455 	struct se_dev_stat_grps *sgrps, char *page)
456 {
457 	struct se_device *dev =
458 		container_of(sgrps, struct se_device, dev_stat_grps);
459 
460 	/* scsiLuCreationTime */
461 	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
462 				INITIAL_JIFFIES) * 100 / HZ));
463 }
464 DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
465 
466 CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group);
467 
468 static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
469 	&target_stat_scsi_lu_inst.attr,
470 	&target_stat_scsi_lu_dev.attr,
471 	&target_stat_scsi_lu_indx.attr,
472 	&target_stat_scsi_lu_lun.attr,
473 	&target_stat_scsi_lu_lu_name.attr,
474 	&target_stat_scsi_lu_vend.attr,
475 	&target_stat_scsi_lu_prod.attr,
476 	&target_stat_scsi_lu_rev.attr,
477 	&target_stat_scsi_lu_dev_type.attr,
478 	&target_stat_scsi_lu_status.attr,
479 	&target_stat_scsi_lu_state_bit.attr,
480 	&target_stat_scsi_lu_num_cmds.attr,
481 	&target_stat_scsi_lu_read_mbytes.attr,
482 	&target_stat_scsi_lu_write_mbytes.attr,
483 	&target_stat_scsi_lu_resets.attr,
484 	&target_stat_scsi_lu_full_stat.attr,
485 	&target_stat_scsi_lu_hs_num_cmds.attr,
486 	&target_stat_scsi_lu_creation_time.attr,
487 	NULL,
488 };
489 
490 static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
491 	.show_attribute		= target_stat_scsi_lu_attr_show,
492 	.store_attribute	= target_stat_scsi_lu_attr_store,
493 };
494 
495 static struct config_item_type target_stat_scsi_lu_cit = {
496 	.ct_item_ops		= &target_stat_scsi_lu_attrib_ops,
497 	.ct_attrs		= target_stat_scsi_lu_attrs,
498 	.ct_owner		= THIS_MODULE,
499 };
500 
501 /*
502  * Called from target_core_configfs.c:target_core_make_subdev() to setup
503  * the target statistics groups + configfs CITs located in target_core_stat.c
504  */
505 void target_stat_setup_dev_default_groups(struct se_device *dev)
506 {
507 	struct config_group *dev_stat_grp = &dev->dev_stat_grps.stat_group;
508 
509 	config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
510 			"scsi_dev", &target_stat_scsi_dev_cit);
511 	config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
512 			"scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
513 	config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
514 			"scsi_lu", &target_stat_scsi_lu_cit);
515 
516 	dev_stat_grp->default_groups[0] = &dev->dev_stat_grps.scsi_dev_group;
517 	dev_stat_grp->default_groups[1] = &dev->dev_stat_grps.scsi_tgt_dev_group;
518 	dev_stat_grp->default_groups[2] = &dev->dev_stat_grps.scsi_lu_group;
519 	dev_stat_grp->default_groups[3] = NULL;
520 }
521 
522 /*
523  * SCSI Port Table
524  */
525 
526 CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps);
527 #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode)				\
528 static struct target_stat_scsi_port_attribute				\
529 			target_stat_scsi_port_##_name =			\
530 	__CONFIGFS_EATTR(_name, _mode,					\
531 	target_stat_scsi_port_show_attr_##_name,			\
532 	target_stat_scsi_port_store_attr_##_name);
533 
534 #define DEV_STAT_SCSI_PORT_ATTR_RO(_name)				\
535 static struct target_stat_scsi_port_attribute				\
536 			target_stat_scsi_port_##_name =			\
537 	__CONFIGFS_EATTR_RO(_name,					\
538 	target_stat_scsi_port_show_attr_##_name);
539 
540 static ssize_t target_stat_scsi_port_show_attr_inst(
541 	struct se_port_stat_grps *pgrps, char *page)
542 {
543 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
544 	struct se_port *sep;
545 	struct se_device *dev = lun->lun_se_dev;
546 	struct se_hba *hba;
547 	ssize_t ret;
548 
549 	spin_lock(&lun->lun_sep_lock);
550 	sep = lun->lun_sep;
551 	if (!sep) {
552 		spin_unlock(&lun->lun_sep_lock);
553 		return -ENODEV;
554 	}
555 	hba = dev->se_hba;
556 	ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
557 	spin_unlock(&lun->lun_sep_lock);
558 	return ret;
559 }
560 DEV_STAT_SCSI_PORT_ATTR_RO(inst);
561 
562 static ssize_t target_stat_scsi_port_show_attr_dev(
563 	struct se_port_stat_grps *pgrps, char *page)
564 {
565 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
566 	struct se_port *sep;
567 	struct se_device *dev = lun->lun_se_dev;
568 	ssize_t ret;
569 
570 	spin_lock(&lun->lun_sep_lock);
571 	sep = lun->lun_sep;
572 	if (!sep) {
573 		spin_unlock(&lun->lun_sep_lock);
574 		return -ENODEV;
575 	}
576 	ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
577 	spin_unlock(&lun->lun_sep_lock);
578 	return ret;
579 }
580 DEV_STAT_SCSI_PORT_ATTR_RO(dev);
581 
582 static ssize_t target_stat_scsi_port_show_attr_indx(
583 	struct se_port_stat_grps *pgrps, char *page)
584 {
585 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
586 	struct se_port *sep;
587 	ssize_t ret;
588 
589 	spin_lock(&lun->lun_sep_lock);
590 	sep = lun->lun_sep;
591 	if (!sep) {
592 		spin_unlock(&lun->lun_sep_lock);
593 		return -ENODEV;
594 	}
595 	ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
596 	spin_unlock(&lun->lun_sep_lock);
597 	return ret;
598 }
599 DEV_STAT_SCSI_PORT_ATTR_RO(indx);
600 
601 static ssize_t target_stat_scsi_port_show_attr_role(
602 	struct se_port_stat_grps *pgrps, char *page)
603 {
604 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
605 	struct se_device *dev = lun->lun_se_dev;
606 	struct se_port *sep;
607 	ssize_t ret;
608 
609 	if (!dev)
610 		return -ENODEV;
611 
612 	spin_lock(&lun->lun_sep_lock);
613 	sep = lun->lun_sep;
614 	if (!sep) {
615 		spin_unlock(&lun->lun_sep_lock);
616 		return -ENODEV;
617 	}
618 	ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
619 	spin_unlock(&lun->lun_sep_lock);
620 	return ret;
621 }
622 DEV_STAT_SCSI_PORT_ATTR_RO(role);
623 
624 static ssize_t target_stat_scsi_port_show_attr_busy_count(
625 	struct se_port_stat_grps *pgrps, char *page)
626 {
627 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
628 	struct se_port *sep;
629 	ssize_t ret;
630 
631 	spin_lock(&lun->lun_sep_lock);
632 	sep = lun->lun_sep;
633 	if (!sep) {
634 		spin_unlock(&lun->lun_sep_lock);
635 		return -ENODEV;
636 	}
637 	/* FIXME: scsiPortBusyStatuses  */
638 	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
639 	spin_unlock(&lun->lun_sep_lock);
640 	return ret;
641 }
642 DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
643 
644 CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group);
645 
646 static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
647 	&target_stat_scsi_port_inst.attr,
648 	&target_stat_scsi_port_dev.attr,
649 	&target_stat_scsi_port_indx.attr,
650 	&target_stat_scsi_port_role.attr,
651 	&target_stat_scsi_port_busy_count.attr,
652 	NULL,
653 };
654 
655 static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
656 	.show_attribute		= target_stat_scsi_port_attr_show,
657 	.store_attribute	= target_stat_scsi_port_attr_store,
658 };
659 
660 static struct config_item_type target_stat_scsi_port_cit = {
661 	.ct_item_ops		= &target_stat_scsi_port_attrib_ops,
662 	.ct_attrs		= target_stat_scsi_port_attrs,
663 	.ct_owner		= THIS_MODULE,
664 };
665 
666 /*
667  * SCSI Target Port Table
668  */
669 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps);
670 #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode)			\
671 static struct target_stat_scsi_tgt_port_attribute			\
672 			target_stat_scsi_tgt_port_##_name =		\
673 	__CONFIGFS_EATTR(_name, _mode,					\
674 	target_stat_scsi_tgt_port_show_attr_##_name,			\
675 	target_stat_scsi_tgt_port_store_attr_##_name);
676 
677 #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name)				\
678 static struct target_stat_scsi_tgt_port_attribute			\
679 			target_stat_scsi_tgt_port_##_name =		\
680 	__CONFIGFS_EATTR_RO(_name,					\
681 	target_stat_scsi_tgt_port_show_attr_##_name);
682 
683 static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
684 	struct se_port_stat_grps *pgrps, char *page)
685 {
686 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
687 	struct se_device *dev = lun->lun_se_dev;
688 	struct se_port *sep;
689 	struct se_hba *hba;
690 	ssize_t ret;
691 
692 	spin_lock(&lun->lun_sep_lock);
693 	sep = lun->lun_sep;
694 	if (!sep) {
695 		spin_unlock(&lun->lun_sep_lock);
696 		return -ENODEV;
697 	}
698 	hba = dev->se_hba;
699 	ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
700 	spin_unlock(&lun->lun_sep_lock);
701 	return ret;
702 }
703 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
704 
705 static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
706 	struct se_port_stat_grps *pgrps, char *page)
707 {
708 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
709 	struct se_device *dev = lun->lun_se_dev;
710 	struct se_port *sep;
711 	ssize_t ret;
712 
713 	spin_lock(&lun->lun_sep_lock);
714 	sep = lun->lun_sep;
715 	if (!sep) {
716 		spin_unlock(&lun->lun_sep_lock);
717 		return -ENODEV;
718 	}
719 	ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
720 	spin_unlock(&lun->lun_sep_lock);
721 	return ret;
722 }
723 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
724 
725 static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
726 	struct se_port_stat_grps *pgrps, char *page)
727 {
728 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
729 	struct se_port *sep;
730 	ssize_t ret;
731 
732 	spin_lock(&lun->lun_sep_lock);
733 	sep = lun->lun_sep;
734 	if (!sep) {
735 		spin_unlock(&lun->lun_sep_lock);
736 		return -ENODEV;
737 	}
738 	ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
739 	spin_unlock(&lun->lun_sep_lock);
740 	return ret;
741 }
742 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
743 
744 static ssize_t target_stat_scsi_tgt_port_show_attr_name(
745 	struct se_port_stat_grps *pgrps, char *page)
746 {
747 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
748 	struct se_port *sep;
749 	struct se_portal_group *tpg;
750 	ssize_t ret;
751 
752 	spin_lock(&lun->lun_sep_lock);
753 	sep = lun->lun_sep;
754 	if (!sep) {
755 		spin_unlock(&lun->lun_sep_lock);
756 		return -ENODEV;
757 	}
758 	tpg = sep->sep_tpg;
759 
760 	ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
761 		tpg->se_tpg_tfo->get_fabric_name(), sep->sep_index);
762 	spin_unlock(&lun->lun_sep_lock);
763 	return ret;
764 }
765 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
766 
767 static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
768 	struct se_port_stat_grps *pgrps, char *page)
769 {
770 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
771 	struct se_port *sep;
772 	struct se_portal_group *tpg;
773 	ssize_t ret;
774 
775 	spin_lock(&lun->lun_sep_lock);
776 	sep = lun->lun_sep;
777 	if (!sep) {
778 		spin_unlock(&lun->lun_sep_lock);
779 		return -ENODEV;
780 	}
781 	tpg = sep->sep_tpg;
782 
783 	ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
784 		tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
785 		tpg->se_tpg_tfo->tpg_get_tag(tpg));
786 	spin_unlock(&lun->lun_sep_lock);
787 	return ret;
788 }
789 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
790 
791 static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
792 	struct se_port_stat_grps *pgrps, char *page)
793 {
794 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
795 	struct se_port *sep;
796 	ssize_t ret;
797 
798 	spin_lock(&lun->lun_sep_lock);
799 	sep = lun->lun_sep;
800 	if (!sep) {
801 		spin_unlock(&lun->lun_sep_lock);
802 		return -ENODEV;
803 	}
804 
805 	ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus);
806 	spin_unlock(&lun->lun_sep_lock);
807 	return ret;
808 }
809 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
810 
811 static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
812 	struct se_port_stat_grps *pgrps, char *page)
813 {
814 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
815 	struct se_port *sep;
816 	ssize_t ret;
817 
818 	spin_lock(&lun->lun_sep_lock);
819 	sep = lun->lun_sep;
820 	if (!sep) {
821 		spin_unlock(&lun->lun_sep_lock);
822 		return -ENODEV;
823 	}
824 
825 	ret = snprintf(page, PAGE_SIZE, "%u\n",
826 			(u32)(sep->sep_stats.rx_data_octets >> 20));
827 	spin_unlock(&lun->lun_sep_lock);
828 	return ret;
829 }
830 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
831 
832 static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
833 	struct se_port_stat_grps *pgrps, char *page)
834 {
835 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
836 	struct se_port *sep;
837 	ssize_t ret;
838 
839 	spin_lock(&lun->lun_sep_lock);
840 	sep = lun->lun_sep;
841 	if (!sep) {
842 		spin_unlock(&lun->lun_sep_lock);
843 		return -ENODEV;
844 	}
845 
846 	ret = snprintf(page, PAGE_SIZE, "%u\n",
847 			(u32)(sep->sep_stats.tx_data_octets >> 20));
848 	spin_unlock(&lun->lun_sep_lock);
849 	return ret;
850 }
851 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
852 
853 static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
854 	struct se_port_stat_grps *pgrps, char *page)
855 {
856 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
857 	struct se_port *sep;
858 	ssize_t ret;
859 
860 	spin_lock(&lun->lun_sep_lock);
861 	sep = lun->lun_sep;
862 	if (!sep) {
863 		spin_unlock(&lun->lun_sep_lock);
864 		return -ENODEV;
865 	}
866 
867 	/* FIXME: scsiTgtPortHsInCommands */
868 	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
869 	spin_unlock(&lun->lun_sep_lock);
870 	return ret;
871 }
872 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
873 
874 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps,
875 		scsi_tgt_port_group);
876 
877 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
878 	&target_stat_scsi_tgt_port_inst.attr,
879 	&target_stat_scsi_tgt_port_dev.attr,
880 	&target_stat_scsi_tgt_port_indx.attr,
881 	&target_stat_scsi_tgt_port_name.attr,
882 	&target_stat_scsi_tgt_port_port_index.attr,
883 	&target_stat_scsi_tgt_port_in_cmds.attr,
884 	&target_stat_scsi_tgt_port_write_mbytes.attr,
885 	&target_stat_scsi_tgt_port_read_mbytes.attr,
886 	&target_stat_scsi_tgt_port_hs_in_cmds.attr,
887 	NULL,
888 };
889 
890 static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
891 	.show_attribute		= target_stat_scsi_tgt_port_attr_show,
892 	.store_attribute	= target_stat_scsi_tgt_port_attr_store,
893 };
894 
895 static struct config_item_type target_stat_scsi_tgt_port_cit = {
896 	.ct_item_ops		= &target_stat_scsi_tgt_port_attrib_ops,
897 	.ct_attrs		= target_stat_scsi_tgt_port_attrs,
898 	.ct_owner		= THIS_MODULE,
899 };
900 
901 /*
902  * SCSI Transport Table
903 o */
904 
905 CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps);
906 #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode)			\
907 static struct target_stat_scsi_transport_attribute			\
908 			target_stat_scsi_transport_##_name =		\
909 	__CONFIGFS_EATTR(_name, _mode,					\
910 	target_stat_scsi_transport_show_attr_##_name,			\
911 	target_stat_scsi_transport_store_attr_##_name);
912 
913 #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name)				\
914 static struct target_stat_scsi_transport_attribute			\
915 			target_stat_scsi_transport_##_name =		\
916 	__CONFIGFS_EATTR_RO(_name,					\
917 	target_stat_scsi_transport_show_attr_##_name);
918 
919 static ssize_t target_stat_scsi_transport_show_attr_inst(
920 	struct se_port_stat_grps *pgrps, char *page)
921 {
922 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
923 	struct se_device *dev = lun->lun_se_dev;
924 	struct se_port *sep;
925 	struct se_hba *hba;
926 	ssize_t ret;
927 
928 	spin_lock(&lun->lun_sep_lock);
929 	sep = lun->lun_sep;
930 	if (!sep) {
931 		spin_unlock(&lun->lun_sep_lock);
932 		return -ENODEV;
933 	}
934 
935 	hba = dev->se_hba;
936 	ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
937 	spin_unlock(&lun->lun_sep_lock);
938 	return ret;
939 }
940 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
941 
942 static ssize_t target_stat_scsi_transport_show_attr_device(
943 	struct se_port_stat_grps *pgrps, char *page)
944 {
945 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
946 	struct se_port *sep;
947 	struct se_portal_group *tpg;
948 	ssize_t ret;
949 
950 	spin_lock(&lun->lun_sep_lock);
951 	sep = lun->lun_sep;
952 	if (!sep) {
953 		spin_unlock(&lun->lun_sep_lock);
954 		return -ENODEV;
955 	}
956 	tpg = sep->sep_tpg;
957 	/* scsiTransportType */
958 	ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
959 			tpg->se_tpg_tfo->get_fabric_name());
960 	spin_unlock(&lun->lun_sep_lock);
961 	return ret;
962 }
963 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
964 
965 static ssize_t target_stat_scsi_transport_show_attr_indx(
966 	struct se_port_stat_grps *pgrps, char *page)
967 {
968 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
969 	struct se_port *sep;
970 	struct se_portal_group *tpg;
971 	ssize_t ret;
972 
973 	spin_lock(&lun->lun_sep_lock);
974 	sep = lun->lun_sep;
975 	if (!sep) {
976 		spin_unlock(&lun->lun_sep_lock);
977 		return -ENODEV;
978 	}
979 	tpg = sep->sep_tpg;
980 	ret = snprintf(page, PAGE_SIZE, "%u\n",
981 			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
982 	spin_unlock(&lun->lun_sep_lock);
983 	return ret;
984 }
985 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
986 
987 static ssize_t target_stat_scsi_transport_show_attr_dev_name(
988 	struct se_port_stat_grps *pgrps, char *page)
989 {
990 	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
991 	struct se_device *dev = lun->lun_se_dev;
992 	struct se_port *sep;
993 	struct se_portal_group *tpg;
994 	struct t10_wwn *wwn;
995 	ssize_t ret;
996 
997 	spin_lock(&lun->lun_sep_lock);
998 	sep = lun->lun_sep;
999 	if (!sep) {
1000 		spin_unlock(&lun->lun_sep_lock);
1001 		return -ENODEV;
1002 	}
1003 	tpg = sep->sep_tpg;
1004 	wwn = &dev->t10_wwn;
1005 	/* scsiTransportDevName */
1006 	ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
1007 			tpg->se_tpg_tfo->tpg_get_wwn(tpg),
1008 			(strlen(wwn->unit_serial)) ? wwn->unit_serial :
1009 			wwn->vendor);
1010 	spin_unlock(&lun->lun_sep_lock);
1011 	return ret;
1012 }
1013 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
1014 
1015 CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps,
1016 		scsi_transport_group);
1017 
1018 static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
1019 	&target_stat_scsi_transport_inst.attr,
1020 	&target_stat_scsi_transport_device.attr,
1021 	&target_stat_scsi_transport_indx.attr,
1022 	&target_stat_scsi_transport_dev_name.attr,
1023 	NULL,
1024 };
1025 
1026 static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
1027 	.show_attribute		= target_stat_scsi_transport_attr_show,
1028 	.store_attribute	= target_stat_scsi_transport_attr_store,
1029 };
1030 
1031 static struct config_item_type target_stat_scsi_transport_cit = {
1032 	.ct_item_ops		= &target_stat_scsi_transport_attrib_ops,
1033 	.ct_attrs		= target_stat_scsi_transport_attrs,
1034 	.ct_owner		= THIS_MODULE,
1035 };
1036 
1037 /*
1038  * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
1039  * the target port statistics groups + configfs CITs located in target_core_stat.c
1040  */
1041 void target_stat_setup_port_default_groups(struct se_lun *lun)
1042 {
1043 	struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group;
1044 
1045 	config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
1046 			"scsi_port", &target_stat_scsi_port_cit);
1047 	config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
1048 			"scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
1049 	config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
1050 			"scsi_transport", &target_stat_scsi_transport_cit);
1051 
1052 	port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group;
1053 	port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group;
1054 	port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group;
1055 	port_stat_grp->default_groups[3] = NULL;
1056 }
1057 
1058 /*
1059  * SCSI Authorized Initiator Table
1060  */
1061 
1062 CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps);
1063 #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode)			\
1064 static struct target_stat_scsi_auth_intr_attribute			\
1065 			target_stat_scsi_auth_intr_##_name =		\
1066 	__CONFIGFS_EATTR(_name, _mode,					\
1067 	target_stat_scsi_auth_intr_show_attr_##_name,			\
1068 	target_stat_scsi_auth_intr_store_attr_##_name);
1069 
1070 #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name)				\
1071 static struct target_stat_scsi_auth_intr_attribute			\
1072 			target_stat_scsi_auth_intr_##_name =		\
1073 	__CONFIGFS_EATTR_RO(_name,					\
1074 	target_stat_scsi_auth_intr_show_attr_##_name);
1075 
1076 static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1077 	struct se_ml_stat_grps *lgrps, char *page)
1078 {
1079 	struct se_lun_acl *lacl = container_of(lgrps,
1080 			struct se_lun_acl, ml_stat_grps);
1081 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1082 	struct se_dev_entry *deve;
1083 	struct se_portal_group *tpg;
1084 	ssize_t ret;
1085 
1086 	spin_lock_irq(&nacl->device_list_lock);
1087 	deve = nacl->device_list[lacl->mapped_lun];
1088 	if (!deve->se_lun || !deve->se_lun_acl) {
1089 		spin_unlock_irq(&nacl->device_list_lock);
1090 		return -ENODEV;
1091 	}
1092 	tpg = nacl->se_tpg;
1093 	/* scsiInstIndex */
1094 	ret = snprintf(page, PAGE_SIZE, "%u\n",
1095 			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1096 	spin_unlock_irq(&nacl->device_list_lock);
1097 	return ret;
1098 }
1099 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
1100 
1101 static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1102 	struct se_ml_stat_grps *lgrps, char *page)
1103 {
1104 	struct se_lun_acl *lacl = container_of(lgrps,
1105 			struct se_lun_acl, ml_stat_grps);
1106 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1107 	struct se_dev_entry *deve;
1108 	struct se_lun *lun;
1109 	ssize_t ret;
1110 
1111 	spin_lock_irq(&nacl->device_list_lock);
1112 	deve = nacl->device_list[lacl->mapped_lun];
1113 	if (!deve->se_lun || !deve->se_lun_acl) {
1114 		spin_unlock_irq(&nacl->device_list_lock);
1115 		return -ENODEV;
1116 	}
1117 	lun = deve->se_lun;
1118 	/* scsiDeviceIndex */
1119 	ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1120 	spin_unlock_irq(&nacl->device_list_lock);
1121 	return ret;
1122 }
1123 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
1124 
1125 static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1126 	struct se_ml_stat_grps *lgrps, char *page)
1127 {
1128 	struct se_lun_acl *lacl = container_of(lgrps,
1129 			struct se_lun_acl, ml_stat_grps);
1130 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1131 	struct se_dev_entry *deve;
1132 	struct se_portal_group *tpg;
1133 	ssize_t ret;
1134 
1135 	spin_lock_irq(&nacl->device_list_lock);
1136 	deve = nacl->device_list[lacl->mapped_lun];
1137 	if (!deve->se_lun || !deve->se_lun_acl) {
1138 		spin_unlock_irq(&nacl->device_list_lock);
1139 		return -ENODEV;
1140 	}
1141 	tpg = nacl->se_tpg;
1142 	/* scsiAuthIntrTgtPortIndex */
1143 	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1144 	spin_unlock_irq(&nacl->device_list_lock);
1145 	return ret;
1146 }
1147 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
1148 
1149 static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1150 	struct se_ml_stat_grps *lgrps, char *page)
1151 {
1152 	struct se_lun_acl *lacl = container_of(lgrps,
1153 			struct se_lun_acl, ml_stat_grps);
1154 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1155 	struct se_dev_entry *deve;
1156 	ssize_t ret;
1157 
1158 	spin_lock_irq(&nacl->device_list_lock);
1159 	deve = nacl->device_list[lacl->mapped_lun];
1160 	if (!deve->se_lun || !deve->se_lun_acl) {
1161 		spin_unlock_irq(&nacl->device_list_lock);
1162 		return -ENODEV;
1163 	}
1164 	/* scsiAuthIntrIndex */
1165 	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1166 	spin_unlock_irq(&nacl->device_list_lock);
1167 	return ret;
1168 }
1169 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
1170 
1171 static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1172 	struct se_ml_stat_grps *lgrps, char *page)
1173 {
1174 	struct se_lun_acl *lacl = container_of(lgrps,
1175 			struct se_lun_acl, ml_stat_grps);
1176 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1177 	struct se_dev_entry *deve;
1178 	ssize_t ret;
1179 
1180 	spin_lock_irq(&nacl->device_list_lock);
1181 	deve = nacl->device_list[lacl->mapped_lun];
1182 	if (!deve->se_lun || !deve->se_lun_acl) {
1183 		spin_unlock_irq(&nacl->device_list_lock);
1184 		return -ENODEV;
1185 	}
1186 	/* scsiAuthIntrDevOrPort */
1187 	ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
1188 	spin_unlock_irq(&nacl->device_list_lock);
1189 	return ret;
1190 }
1191 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
1192 
1193 static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1194 	struct se_ml_stat_grps *lgrps, char *page)
1195 {
1196 	struct se_lun_acl *lacl = container_of(lgrps,
1197 			struct se_lun_acl, ml_stat_grps);
1198 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1199 	struct se_dev_entry *deve;
1200 	ssize_t ret;
1201 
1202 	spin_lock_irq(&nacl->device_list_lock);
1203 	deve = nacl->device_list[lacl->mapped_lun];
1204 	if (!deve->se_lun || !deve->se_lun_acl) {
1205 		spin_unlock_irq(&nacl->device_list_lock);
1206 		return -ENODEV;
1207 	}
1208 	/* scsiAuthIntrName */
1209 	ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1210 	spin_unlock_irq(&nacl->device_list_lock);
1211 	return ret;
1212 }
1213 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
1214 
1215 static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1216 	struct se_ml_stat_grps *lgrps, char *page)
1217 {
1218 	struct se_lun_acl *lacl = container_of(lgrps,
1219 			struct se_lun_acl, ml_stat_grps);
1220 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1221 	struct se_dev_entry *deve;
1222 	ssize_t ret;
1223 
1224 	spin_lock_irq(&nacl->device_list_lock);
1225 	deve = nacl->device_list[lacl->mapped_lun];
1226 	if (!deve->se_lun || !deve->se_lun_acl) {
1227 		spin_unlock_irq(&nacl->device_list_lock);
1228 		return -ENODEV;
1229 	}
1230 	/* FIXME: scsiAuthIntrLunMapIndex */
1231 	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1232 	spin_unlock_irq(&nacl->device_list_lock);
1233 	return ret;
1234 }
1235 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
1236 
1237 static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1238 	struct se_ml_stat_grps *lgrps, char *page)
1239 {
1240 	struct se_lun_acl *lacl = container_of(lgrps,
1241 			struct se_lun_acl, ml_stat_grps);
1242 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1243 	struct se_dev_entry *deve;
1244 	ssize_t ret;
1245 
1246 	spin_lock_irq(&nacl->device_list_lock);
1247 	deve = nacl->device_list[lacl->mapped_lun];
1248 	if (!deve->se_lun || !deve->se_lun_acl) {
1249 		spin_unlock_irq(&nacl->device_list_lock);
1250 		return -ENODEV;
1251 	}
1252 	/* scsiAuthIntrAttachedTimes */
1253 	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1254 	spin_unlock_irq(&nacl->device_list_lock);
1255 	return ret;
1256 }
1257 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
1258 
1259 static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1260 	struct se_ml_stat_grps *lgrps, char *page)
1261 {
1262 	struct se_lun_acl *lacl = container_of(lgrps,
1263 			struct se_lun_acl, ml_stat_grps);
1264 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1265 	struct se_dev_entry *deve;
1266 	ssize_t ret;
1267 
1268 	spin_lock_irq(&nacl->device_list_lock);
1269 	deve = nacl->device_list[lacl->mapped_lun];
1270 	if (!deve->se_lun || !deve->se_lun_acl) {
1271 		spin_unlock_irq(&nacl->device_list_lock);
1272 		return -ENODEV;
1273 	}
1274 	/* scsiAuthIntrOutCommands */
1275 	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds);
1276 	spin_unlock_irq(&nacl->device_list_lock);
1277 	return ret;
1278 }
1279 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
1280 
1281 static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1282 	struct se_ml_stat_grps *lgrps, char *page)
1283 {
1284 	struct se_lun_acl *lacl = container_of(lgrps,
1285 			struct se_lun_acl, ml_stat_grps);
1286 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1287 	struct se_dev_entry *deve;
1288 	ssize_t ret;
1289 
1290 	spin_lock_irq(&nacl->device_list_lock);
1291 	deve = nacl->device_list[lacl->mapped_lun];
1292 	if (!deve->se_lun || !deve->se_lun_acl) {
1293 		spin_unlock_irq(&nacl->device_list_lock);
1294 		return -ENODEV;
1295 	}
1296 	/* scsiAuthIntrReadMegaBytes */
1297 	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20));
1298 	spin_unlock_irq(&nacl->device_list_lock);
1299 	return ret;
1300 }
1301 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
1302 
1303 static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1304 	struct se_ml_stat_grps *lgrps, char *page)
1305 {
1306 	struct se_lun_acl *lacl = container_of(lgrps,
1307 			struct se_lun_acl, ml_stat_grps);
1308 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1309 	struct se_dev_entry *deve;
1310 	ssize_t ret;
1311 
1312 	spin_lock_irq(&nacl->device_list_lock);
1313 	deve = nacl->device_list[lacl->mapped_lun];
1314 	if (!deve->se_lun || !deve->se_lun_acl) {
1315 		spin_unlock_irq(&nacl->device_list_lock);
1316 		return -ENODEV;
1317 	}
1318 	/* scsiAuthIntrWrittenMegaBytes */
1319 	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20));
1320 	spin_unlock_irq(&nacl->device_list_lock);
1321 	return ret;
1322 }
1323 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
1324 
1325 static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1326 	struct se_ml_stat_grps *lgrps, char *page)
1327 {
1328 	struct se_lun_acl *lacl = container_of(lgrps,
1329 			struct se_lun_acl, ml_stat_grps);
1330 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1331 	struct se_dev_entry *deve;
1332 	ssize_t ret;
1333 
1334 	spin_lock_irq(&nacl->device_list_lock);
1335 	deve = nacl->device_list[lacl->mapped_lun];
1336 	if (!deve->se_lun || !deve->se_lun_acl) {
1337 		spin_unlock_irq(&nacl->device_list_lock);
1338 		return -ENODEV;
1339 	}
1340 	/* FIXME: scsiAuthIntrHSOutCommands */
1341 	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1342 	spin_unlock_irq(&nacl->device_list_lock);
1343 	return ret;
1344 }
1345 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
1346 
1347 static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1348 	struct se_ml_stat_grps *lgrps, char *page)
1349 {
1350 	struct se_lun_acl *lacl = container_of(lgrps,
1351 			struct se_lun_acl, ml_stat_grps);
1352 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1353 	struct se_dev_entry *deve;
1354 	ssize_t ret;
1355 
1356 	spin_lock_irq(&nacl->device_list_lock);
1357 	deve = nacl->device_list[lacl->mapped_lun];
1358 	if (!deve->se_lun || !deve->se_lun_acl) {
1359 		spin_unlock_irq(&nacl->device_list_lock);
1360 		return -ENODEV;
1361 	}
1362 	/* scsiAuthIntrLastCreation */
1363 	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1364 				INITIAL_JIFFIES) * 100 / HZ));
1365 	spin_unlock_irq(&nacl->device_list_lock);
1366 	return ret;
1367 }
1368 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
1369 
1370 static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
1371 	struct se_ml_stat_grps *lgrps, char *page)
1372 {
1373 	struct se_lun_acl *lacl = container_of(lgrps,
1374 			struct se_lun_acl, ml_stat_grps);
1375 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1376 	struct se_dev_entry *deve;
1377 	ssize_t ret;
1378 
1379 	spin_lock_irq(&nacl->device_list_lock);
1380 	deve = nacl->device_list[lacl->mapped_lun];
1381 	if (!deve->se_lun || !deve->se_lun_acl) {
1382 		spin_unlock_irq(&nacl->device_list_lock);
1383 		return -ENODEV;
1384 	}
1385 	/* FIXME: scsiAuthIntrRowStatus */
1386 	ret = snprintf(page, PAGE_SIZE, "Ready\n");
1387 	spin_unlock_irq(&nacl->device_list_lock);
1388 	return ret;
1389 }
1390 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
1391 
1392 CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps,
1393 		scsi_auth_intr_group);
1394 
1395 static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1396 	&target_stat_scsi_auth_intr_inst.attr,
1397 	&target_stat_scsi_auth_intr_dev.attr,
1398 	&target_stat_scsi_auth_intr_port.attr,
1399 	&target_stat_scsi_auth_intr_indx.attr,
1400 	&target_stat_scsi_auth_intr_dev_or_port.attr,
1401 	&target_stat_scsi_auth_intr_intr_name.attr,
1402 	&target_stat_scsi_auth_intr_map_indx.attr,
1403 	&target_stat_scsi_auth_intr_att_count.attr,
1404 	&target_stat_scsi_auth_intr_num_cmds.attr,
1405 	&target_stat_scsi_auth_intr_read_mbytes.attr,
1406 	&target_stat_scsi_auth_intr_write_mbytes.attr,
1407 	&target_stat_scsi_auth_intr_hs_num_cmds.attr,
1408 	&target_stat_scsi_auth_intr_creation_time.attr,
1409 	&target_stat_scsi_auth_intr_row_status.attr,
1410 	NULL,
1411 };
1412 
1413 static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
1414 	.show_attribute		= target_stat_scsi_auth_intr_attr_show,
1415 	.store_attribute	= target_stat_scsi_auth_intr_attr_store,
1416 };
1417 
1418 static struct config_item_type target_stat_scsi_auth_intr_cit = {
1419 	.ct_item_ops		= &target_stat_scsi_auth_intr_attrib_ops,
1420 	.ct_attrs		= target_stat_scsi_auth_intr_attrs,
1421 	.ct_owner		= THIS_MODULE,
1422 };
1423 
1424 /*
1425  * SCSI Attached Initiator Port Table
1426  */
1427 
1428 CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps);
1429 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode)			\
1430 static struct target_stat_scsi_att_intr_port_attribute			\
1431 		target_stat_scsi_att_intr_port_##_name =		\
1432 	__CONFIGFS_EATTR(_name, _mode,					\
1433 	target_stat_scsi_att_intr_port_show_attr_##_name,		\
1434 	target_stat_scsi_att_intr_port_store_attr_##_name);
1435 
1436 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name)			\
1437 static struct target_stat_scsi_att_intr_port_attribute			\
1438 		target_stat_scsi_att_intr_port_##_name =		\
1439 	__CONFIGFS_EATTR_RO(_name,					\
1440 	target_stat_scsi_att_intr_port_show_attr_##_name);
1441 
1442 static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1443 	struct se_ml_stat_grps *lgrps, char *page)
1444 {
1445 	struct se_lun_acl *lacl = container_of(lgrps,
1446 			struct se_lun_acl, ml_stat_grps);
1447 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1448 	struct se_dev_entry *deve;
1449 	struct se_portal_group *tpg;
1450 	ssize_t ret;
1451 
1452 	spin_lock_irq(&nacl->device_list_lock);
1453 	deve = nacl->device_list[lacl->mapped_lun];
1454 	if (!deve->se_lun || !deve->se_lun_acl) {
1455 		spin_unlock_irq(&nacl->device_list_lock);
1456 		return -ENODEV;
1457 	}
1458 	tpg = nacl->se_tpg;
1459 	/* scsiInstIndex */
1460 	ret = snprintf(page, PAGE_SIZE, "%u\n",
1461 			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1462 	spin_unlock_irq(&nacl->device_list_lock);
1463 	return ret;
1464 }
1465 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
1466 
1467 static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1468 	struct se_ml_stat_grps *lgrps, char *page)
1469 {
1470 	struct se_lun_acl *lacl = container_of(lgrps,
1471 			struct se_lun_acl, ml_stat_grps);
1472 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1473 	struct se_dev_entry *deve;
1474 	struct se_lun *lun;
1475 	ssize_t ret;
1476 
1477 	spin_lock_irq(&nacl->device_list_lock);
1478 	deve = nacl->device_list[lacl->mapped_lun];
1479 	if (!deve->se_lun || !deve->se_lun_acl) {
1480 		spin_unlock_irq(&nacl->device_list_lock);
1481 		return -ENODEV;
1482 	}
1483 	lun = deve->se_lun;
1484 	/* scsiDeviceIndex */
1485 	ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1486 	spin_unlock_irq(&nacl->device_list_lock);
1487 	return ret;
1488 }
1489 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
1490 
1491 static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1492 	struct se_ml_stat_grps *lgrps, char *page)
1493 {
1494 	struct se_lun_acl *lacl = container_of(lgrps,
1495 			struct se_lun_acl, ml_stat_grps);
1496 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1497 	struct se_dev_entry *deve;
1498 	struct se_portal_group *tpg;
1499 	ssize_t ret;
1500 
1501 	spin_lock_irq(&nacl->device_list_lock);
1502 	deve = nacl->device_list[lacl->mapped_lun];
1503 	if (!deve->se_lun || !deve->se_lun_acl) {
1504 		spin_unlock_irq(&nacl->device_list_lock);
1505 		return -ENODEV;
1506 	}
1507 	tpg = nacl->se_tpg;
1508 	/* scsiPortIndex */
1509 	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1510 	spin_unlock_irq(&nacl->device_list_lock);
1511 	return ret;
1512 }
1513 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
1514 
1515 static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1516 	struct se_ml_stat_grps *lgrps, char *page)
1517 {
1518 	struct se_lun_acl *lacl = container_of(lgrps,
1519 			struct se_lun_acl, ml_stat_grps);
1520 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1521 	struct se_session *se_sess;
1522 	struct se_portal_group *tpg;
1523 	ssize_t ret;
1524 
1525 	spin_lock_irq(&nacl->nacl_sess_lock);
1526 	se_sess = nacl->nacl_sess;
1527 	if (!se_sess) {
1528 		spin_unlock_irq(&nacl->nacl_sess_lock);
1529 		return -ENODEV;
1530 	}
1531 
1532 	tpg = nacl->se_tpg;
1533 	/* scsiAttIntrPortIndex */
1534 	ret = snprintf(page, PAGE_SIZE, "%u\n",
1535 			tpg->se_tpg_tfo->sess_get_index(se_sess));
1536 	spin_unlock_irq(&nacl->nacl_sess_lock);
1537 	return ret;
1538 }
1539 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
1540 
1541 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1542 	struct se_ml_stat_grps *lgrps, char *page)
1543 {
1544 	struct se_lun_acl *lacl = container_of(lgrps,
1545 			struct se_lun_acl, ml_stat_grps);
1546 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1547 	struct se_dev_entry *deve;
1548 	ssize_t ret;
1549 
1550 	spin_lock_irq(&nacl->device_list_lock);
1551 	deve = nacl->device_list[lacl->mapped_lun];
1552 	if (!deve->se_lun || !deve->se_lun_acl) {
1553 		spin_unlock_irq(&nacl->device_list_lock);
1554 		return -ENODEV;
1555 	}
1556 	/* scsiAttIntrPortAuthIntrIdx */
1557 	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1558 	spin_unlock_irq(&nacl->device_list_lock);
1559 	return ret;
1560 }
1561 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
1562 
1563 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1564 	struct se_ml_stat_grps *lgrps, char *page)
1565 {
1566 	struct se_lun_acl *lacl = container_of(lgrps,
1567 			struct se_lun_acl, ml_stat_grps);
1568 	struct se_node_acl *nacl = lacl->se_lun_nacl;
1569 	struct se_session *se_sess;
1570 	struct se_portal_group *tpg;
1571 	ssize_t ret;
1572 	unsigned char buf[64];
1573 
1574 	spin_lock_irq(&nacl->nacl_sess_lock);
1575 	se_sess = nacl->nacl_sess;
1576 	if (!se_sess) {
1577 		spin_unlock_irq(&nacl->nacl_sess_lock);
1578 		return -ENODEV;
1579 	}
1580 
1581 	tpg = nacl->se_tpg;
1582 	/* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1583 	memset(buf, 0, 64);
1584 	if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
1585 		tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
1586 
1587 	ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1588 	spin_unlock_irq(&nacl->nacl_sess_lock);
1589 	return ret;
1590 }
1591 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
1592 
1593 CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps,
1594 		scsi_att_intr_port_group);
1595 
1596 static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1597 	&target_stat_scsi_att_intr_port_inst.attr,
1598 	&target_stat_scsi_att_intr_port_dev.attr,
1599 	&target_stat_scsi_att_intr_port_port.attr,
1600 	&target_stat_scsi_att_intr_port_indx.attr,
1601 	&target_stat_scsi_att_intr_port_port_auth_indx.attr,
1602 	&target_stat_scsi_att_intr_port_port_ident.attr,
1603 	NULL,
1604 };
1605 
1606 static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
1607 	.show_attribute		= target_stat_scsi_att_intr_port_attr_show,
1608 	.store_attribute	= target_stat_scsi_att_intr_port_attr_store,
1609 };
1610 
1611 static struct config_item_type target_stat_scsi_att_intr_port_cit = {
1612 	.ct_item_ops		= &target_stat_scsi_att_intr_port_attrib_ops,
1613 	.ct_attrs		= target_stat_scsi_ath_intr_port_attrs,
1614 	.ct_owner		= THIS_MODULE,
1615 };
1616 
1617 /*
1618  * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1619  * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1620  */
1621 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1622 {
1623 	struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group;
1624 
1625 	config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
1626 			"scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1627 	config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1628 			"scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1629 
1630 	ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group;
1631 	ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group;
1632 	ml_stat_grp->default_groups[2] = NULL;
1633 }
1634