11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
212d23384SNicholas Bellinger /*******************************************************************************
312d23384SNicholas Bellinger  * Filename:  target_core_stat.c
412d23384SNicholas Bellinger  *
512d23384SNicholas Bellinger  * Modern ConfigFS group context specific statistics based on original
612d23384SNicholas Bellinger  * target_core_mib.c code
712d23384SNicholas Bellinger  *
84c76251eSNicholas Bellinger  * (c) Copyright 2006-2013 Datera, Inc.
912d23384SNicholas Bellinger  *
1012d23384SNicholas Bellinger  * Nicholas A. Bellinger <nab@linux-iscsi.org>
1112d23384SNicholas Bellinger  *
1212d23384SNicholas Bellinger  ******************************************************************************/
1312d23384SNicholas Bellinger 
1412d23384SNicholas Bellinger #include <linux/kernel.h>
1512d23384SNicholas Bellinger #include <linux/module.h>
1612d23384SNicholas Bellinger #include <linux/delay.h>
1712d23384SNicholas Bellinger #include <linux/timer.h>
1812d23384SNicholas Bellinger #include <linux/string.h>
1912d23384SNicholas Bellinger #include <linux/utsname.h>
2012d23384SNicholas Bellinger #include <linux/proc_fs.h>
2112d23384SNicholas Bellinger #include <linux/seq_file.h>
2212d23384SNicholas Bellinger #include <linux/configfs.h>
2312d23384SNicholas Bellinger 
2412d23384SNicholas Bellinger #include <target/target_core_base.h>
25c4795fb2SChristoph Hellwig #include <target/target_core_backend.h>
26c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h>
2712d23384SNicholas Bellinger 
28e26d99aeSChristoph Hellwig #include "target_core_internal.h"
2912d23384SNicholas Bellinger 
3012d23384SNicholas Bellinger #ifndef INITIAL_JIFFIES
3112d23384SNicholas Bellinger #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
3212d23384SNicholas Bellinger #endif
3312d23384SNicholas Bellinger 
3412d23384SNicholas Bellinger #define SCSI_LU_INDEX			1
3512d23384SNicholas Bellinger #define LU_COUNT			1
3612d23384SNicholas Bellinger 
3712d23384SNicholas Bellinger /*
3812d23384SNicholas Bellinger  * SCSI Device Table
3912d23384SNicholas Bellinger  */
4012d23384SNicholas Bellinger 
to_stat_dev(struct config_item * item)412eafd729SChristoph Hellwig static struct se_device *to_stat_dev(struct config_item *item)
4212d23384SNicholas Bellinger {
432eafd729SChristoph Hellwig 	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
442eafd729SChristoph Hellwig 			struct se_dev_stat_grps, scsi_dev_group);
452eafd729SChristoph Hellwig 	return container_of(sgrps, struct se_device, dev_stat_grps);
462eafd729SChristoph Hellwig }
472eafd729SChristoph Hellwig 
target_stat_inst_show(struct config_item * item,char * page)482eafd729SChristoph Hellwig static ssize_t target_stat_inst_show(struct config_item *item, char *page)
492eafd729SChristoph Hellwig {
502eafd729SChristoph Hellwig 	struct se_hba *hba = to_stat_dev(item)->se_hba;
5112d23384SNicholas Bellinger 
5212d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
5312d23384SNicholas Bellinger }
5412d23384SNicholas Bellinger 
target_stat_indx_show(struct config_item * item,char * page)552eafd729SChristoph Hellwig static ssize_t target_stat_indx_show(struct config_item *item, char *page)
5612d23384SNicholas Bellinger {
572eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index);
5812d23384SNicholas Bellinger }
5912d23384SNicholas Bellinger 
target_stat_role_show(struct config_item * item,char * page)602eafd729SChristoph Hellwig static ssize_t target_stat_role_show(struct config_item *item, char *page)
6112d23384SNicholas Bellinger {
6212d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "Target\n");
6312d23384SNicholas Bellinger }
6412d23384SNicholas Bellinger 
target_stat_ports_show(struct config_item * item,char * page)652eafd729SChristoph Hellwig static ssize_t target_stat_ports_show(struct config_item *item, char *page)
6612d23384SNicholas Bellinger {
672eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count);
6812d23384SNicholas Bellinger }
6912d23384SNicholas Bellinger 
702eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_, inst);
712eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_, indx);
722eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_, role);
732eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_, ports);
7412d23384SNicholas Bellinger 
7512d23384SNicholas Bellinger static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
762eafd729SChristoph Hellwig 	&target_stat_attr_inst,
772eafd729SChristoph Hellwig 	&target_stat_attr_indx,
782eafd729SChristoph Hellwig 	&target_stat_attr_role,
792eafd729SChristoph Hellwig 	&target_stat_attr_ports,
8012d23384SNicholas Bellinger 	NULL,
8112d23384SNicholas Bellinger };
8212d23384SNicholas Bellinger 
83ece550b5SBhumika Goyal static const struct config_item_type target_stat_scsi_dev_cit = {
8412d23384SNicholas Bellinger 	.ct_attrs		= target_stat_scsi_dev_attrs,
8512d23384SNicholas Bellinger 	.ct_owner		= THIS_MODULE,
8612d23384SNicholas Bellinger };
8712d23384SNicholas Bellinger 
8812d23384SNicholas Bellinger /*
8912d23384SNicholas Bellinger  * SCSI Target Device Table
9012d23384SNicholas Bellinger  */
to_stat_tgt_dev(struct config_item * item)912eafd729SChristoph Hellwig static struct se_device *to_stat_tgt_dev(struct config_item *item)
9212d23384SNicholas Bellinger {
932eafd729SChristoph Hellwig 	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
942eafd729SChristoph Hellwig 			struct se_dev_stat_grps, scsi_tgt_dev_group);
952eafd729SChristoph Hellwig 	return container_of(sgrps, struct se_device, dev_stat_grps);
962eafd729SChristoph Hellwig }
972eafd729SChristoph Hellwig 
target_stat_tgt_inst_show(struct config_item * item,char * page)982eafd729SChristoph Hellwig static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page)
992eafd729SChristoph Hellwig {
1002eafd729SChristoph Hellwig 	struct se_hba *hba = to_stat_tgt_dev(item)->se_hba;
10112d23384SNicholas Bellinger 
10212d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
10312d23384SNicholas Bellinger }
10412d23384SNicholas Bellinger 
target_stat_tgt_indx_show(struct config_item * item,char * page)1052eafd729SChristoph Hellwig static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page)
10612d23384SNicholas Bellinger {
1072eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index);
10812d23384SNicholas Bellinger }
10912d23384SNicholas Bellinger 
target_stat_tgt_num_lus_show(struct config_item * item,char * page)1102eafd729SChristoph Hellwig static ssize_t target_stat_tgt_num_lus_show(struct config_item *item,
1112eafd729SChristoph Hellwig 		char *page)
11212d23384SNicholas Bellinger {
11312d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
11412d23384SNicholas Bellinger }
11512d23384SNicholas Bellinger 
target_stat_tgt_status_show(struct config_item * item,char * page)1162eafd729SChristoph Hellwig static ssize_t target_stat_tgt_status_show(struct config_item *item,
1172eafd729SChristoph Hellwig 		char *page)
11812d23384SNicholas Bellinger {
1192eafd729SChristoph Hellwig 	if (to_stat_tgt_dev(item)->export_count)
1200fd97ccfSChristoph Hellwig 		return snprintf(page, PAGE_SIZE, "activated");
1210fd97ccfSChristoph Hellwig 	else
1220fd97ccfSChristoph Hellwig 		return snprintf(page, PAGE_SIZE, "deactivated");
12312d23384SNicholas Bellinger }
12412d23384SNicholas Bellinger 
target_stat_tgt_non_access_lus_show(struct config_item * item,char * page)1252eafd729SChristoph Hellwig static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item,
1262eafd729SChristoph Hellwig 		char *page)
12712d23384SNicholas Bellinger {
12812d23384SNicholas Bellinger 	int non_accessible_lus;
12912d23384SNicholas Bellinger 
1302eafd729SChristoph Hellwig 	if (to_stat_tgt_dev(item)->export_count)
13112d23384SNicholas Bellinger 		non_accessible_lus = 0;
1320fd97ccfSChristoph Hellwig 	else
13312d23384SNicholas Bellinger 		non_accessible_lus = 1;
13412d23384SNicholas Bellinger 
13512d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
13612d23384SNicholas Bellinger }
13712d23384SNicholas Bellinger 
target_stat_tgt_resets_show(struct config_item * item,char * page)1382eafd729SChristoph Hellwig static ssize_t target_stat_tgt_resets_show(struct config_item *item,
1392eafd729SChristoph Hellwig 		char *page)
14012d23384SNicholas Bellinger {
141ee480683SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%lu\n",
1422eafd729SChristoph Hellwig 			atomic_long_read(&to_stat_tgt_dev(item)->num_resets));
14312d23384SNicholas Bellinger }
14412d23384SNicholas Bellinger 
target_stat_tgt_aborts_complete_show(struct config_item * item,char * page)145c87ba9c4SNicholas Bellinger static ssize_t target_stat_tgt_aborts_complete_show(struct config_item *item,
146c87ba9c4SNicholas Bellinger 		char *page)
147c87ba9c4SNicholas Bellinger {
148c87ba9c4SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%lu\n",
149c87ba9c4SNicholas Bellinger 			atomic_long_read(&to_stat_tgt_dev(item)->aborts_complete));
150c87ba9c4SNicholas Bellinger }
151c87ba9c4SNicholas Bellinger 
target_stat_tgt_aborts_no_task_show(struct config_item * item,char * page)152c87ba9c4SNicholas Bellinger static ssize_t target_stat_tgt_aborts_no_task_show(struct config_item *item,
153c87ba9c4SNicholas Bellinger 		char *page)
154c87ba9c4SNicholas Bellinger {
155c87ba9c4SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%lu\n",
156c87ba9c4SNicholas Bellinger 			atomic_long_read(&to_stat_tgt_dev(item)->aborts_no_task));
157c87ba9c4SNicholas Bellinger }
158c87ba9c4SNicholas Bellinger 
1592eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_, inst);
1602eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_, indx);
1612eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus);
1622eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_, status);
1632eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus);
1642eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_, resets);
165c87ba9c4SNicholas Bellinger CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_complete);
166c87ba9c4SNicholas Bellinger CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_no_task);
16712d23384SNicholas Bellinger 
16812d23384SNicholas Bellinger static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
1692eafd729SChristoph Hellwig 	&target_stat_tgt_attr_inst,
1702eafd729SChristoph Hellwig 	&target_stat_tgt_attr_indx,
1712eafd729SChristoph Hellwig 	&target_stat_tgt_attr_num_lus,
1722eafd729SChristoph Hellwig 	&target_stat_tgt_attr_status,
1732eafd729SChristoph Hellwig 	&target_stat_tgt_attr_non_access_lus,
1742eafd729SChristoph Hellwig 	&target_stat_tgt_attr_resets,
175c87ba9c4SNicholas Bellinger 	&target_stat_tgt_attr_aborts_complete,
176c87ba9c4SNicholas Bellinger 	&target_stat_tgt_attr_aborts_no_task,
17712d23384SNicholas Bellinger 	NULL,
17812d23384SNicholas Bellinger };
17912d23384SNicholas Bellinger 
180ece550b5SBhumika Goyal static const struct config_item_type target_stat_scsi_tgt_dev_cit = {
18112d23384SNicholas Bellinger 	.ct_attrs		= target_stat_scsi_tgt_dev_attrs,
18212d23384SNicholas Bellinger 	.ct_owner		= THIS_MODULE,
18312d23384SNicholas Bellinger };
18412d23384SNicholas Bellinger 
18512d23384SNicholas Bellinger /*
18612d23384SNicholas Bellinger  * SCSI Logical Unit Table
18712d23384SNicholas Bellinger  */
18812d23384SNicholas Bellinger 
to_stat_lu_dev(struct config_item * item)1892eafd729SChristoph Hellwig static struct se_device *to_stat_lu_dev(struct config_item *item)
19012d23384SNicholas Bellinger {
1912eafd729SChristoph Hellwig 	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
1922eafd729SChristoph Hellwig 			struct se_dev_stat_grps, scsi_lu_group);
1932eafd729SChristoph Hellwig 	return container_of(sgrps, struct se_device, dev_stat_grps);
1942eafd729SChristoph Hellwig }
1952eafd729SChristoph Hellwig 
target_stat_lu_inst_show(struct config_item * item,char * page)1962eafd729SChristoph Hellwig static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page)
1972eafd729SChristoph Hellwig {
1982eafd729SChristoph Hellwig 	struct se_hba *hba = to_stat_lu_dev(item)->se_hba;
19912d23384SNicholas Bellinger 
20012d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
20112d23384SNicholas Bellinger }
20212d23384SNicholas Bellinger 
target_stat_lu_dev_show(struct config_item * item,char * page)2032eafd729SChristoph Hellwig static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page)
20412d23384SNicholas Bellinger {
2052eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
2062eafd729SChristoph Hellwig 			to_stat_lu_dev(item)->dev_index);
20712d23384SNicholas Bellinger }
20812d23384SNicholas Bellinger 
target_stat_lu_indx_show(struct config_item * item,char * page)2092eafd729SChristoph Hellwig static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page)
21012d23384SNicholas Bellinger {
21112d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
21212d23384SNicholas Bellinger }
21312d23384SNicholas Bellinger 
target_stat_lu_lun_show(struct config_item * item,char * page)2142eafd729SChristoph Hellwig static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page)
21512d23384SNicholas Bellinger {
21612d23384SNicholas Bellinger 	/* FIXME: scsiLuDefaultLun */
21712d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
21812d23384SNicholas Bellinger }
21912d23384SNicholas Bellinger 
target_stat_lu_lu_name_show(struct config_item * item,char * page)2202eafd729SChristoph Hellwig static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page)
22112d23384SNicholas Bellinger {
2222eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
22312d23384SNicholas Bellinger 
22412d23384SNicholas Bellinger 	/* scsiLuWwnName */
22512d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n",
2260fd97ccfSChristoph Hellwig 			(strlen(dev->t10_wwn.unit_serial)) ?
2270fd97ccfSChristoph Hellwig 			dev->t10_wwn.unit_serial : "None");
22812d23384SNicholas Bellinger }
22912d23384SNicholas Bellinger 
target_stat_lu_vend_show(struct config_item * item,char * page)2302eafd729SChristoph Hellwig static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page)
23112d23384SNicholas Bellinger {
2322eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
233e3d6f909SAndy Grover 
234b2da4abfSDavid Disseldorp 	return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_VENDOR_LEN)
235b2da4abfSDavid Disseldorp 			"s\n", dev->t10_wwn.vendor);
23612d23384SNicholas Bellinger }
23712d23384SNicholas Bellinger 
target_stat_lu_prod_show(struct config_item * item,char * page)2382eafd729SChristoph Hellwig static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page)
23912d23384SNicholas Bellinger {
2402eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
24112d23384SNicholas Bellinger 
242b2da4abfSDavid Disseldorp 	return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_MODEL_LEN)
243b2da4abfSDavid Disseldorp 			"s\n", dev->t10_wwn.model);
24412d23384SNicholas Bellinger }
24512d23384SNicholas Bellinger 
target_stat_lu_rev_show(struct config_item * item,char * page)2462eafd729SChristoph Hellwig static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page)
24712d23384SNicholas Bellinger {
2482eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
24912d23384SNicholas Bellinger 
250b2da4abfSDavid Disseldorp 	return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_REVISION_LEN)
251b2da4abfSDavid Disseldorp 			"s\n", dev->t10_wwn.revision);
25212d23384SNicholas Bellinger }
25312d23384SNicholas Bellinger 
target_stat_lu_dev_type_show(struct config_item * item,char * page)2542eafd729SChristoph Hellwig static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)
25512d23384SNicholas Bellinger {
2562eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
25712d23384SNicholas Bellinger 
25812d23384SNicholas Bellinger 	/* scsiLuPeripheralType */
25912d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n",
260e3d6f909SAndy Grover 			dev->transport->get_device_type(dev));
26112d23384SNicholas Bellinger }
26212d23384SNicholas Bellinger 
target_stat_lu_status_show(struct config_item * item,char * page)2632eafd729SChristoph Hellwig static ssize_t target_stat_lu_status_show(struct config_item *item, char *page)
26412d23384SNicholas Bellinger {
2652eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
26612d23384SNicholas Bellinger 
26712d23384SNicholas Bellinger 	/* scsiLuStatus */
26812d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n",
2690fd97ccfSChristoph Hellwig 		(dev->export_count) ? "available" : "notavailable");
27012d23384SNicholas Bellinger }
27112d23384SNicholas Bellinger 
target_stat_lu_state_bit_show(struct config_item * item,char * page)2722eafd729SChristoph Hellwig static ssize_t target_stat_lu_state_bit_show(struct config_item *item,
2732eafd729SChristoph Hellwig 		char *page)
27412d23384SNicholas Bellinger {
27512d23384SNicholas Bellinger 	/* scsiLuState */
27612d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "exposed\n");
27712d23384SNicholas Bellinger }
27812d23384SNicholas Bellinger 
target_stat_lu_num_cmds_show(struct config_item * item,char * page)2792eafd729SChristoph Hellwig static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,
2802eafd729SChristoph Hellwig 		char *page)
28112d23384SNicholas Bellinger {
2822eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
28312d23384SNicholas Bellinger 
28412d23384SNicholas Bellinger 	/* scsiLuNumCommands */
285ee480683SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%lu\n",
286ee480683SNicholas Bellinger 			atomic_long_read(&dev->num_cmds));
28712d23384SNicholas Bellinger }
28812d23384SNicholas Bellinger 
target_stat_lu_read_mbytes_show(struct config_item * item,char * page)2892eafd729SChristoph Hellwig static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
2902eafd729SChristoph Hellwig 		char *page)
29112d23384SNicholas Bellinger {
2922eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
29312d23384SNicholas Bellinger 
29412d23384SNicholas Bellinger 	/* scsiLuReadMegaBytes */
295ee480683SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%lu\n",
296ee480683SNicholas Bellinger 			atomic_long_read(&dev->read_bytes) >> 20);
29712d23384SNicholas Bellinger }
29812d23384SNicholas Bellinger 
target_stat_lu_write_mbytes_show(struct config_item * item,char * page)2992eafd729SChristoph Hellwig static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
3002eafd729SChristoph Hellwig 		char *page)
30112d23384SNicholas Bellinger {
3022eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
30312d23384SNicholas Bellinger 
30412d23384SNicholas Bellinger 	/* scsiLuWrittenMegaBytes */
305ee480683SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%lu\n",
306ee480683SNicholas Bellinger 			atomic_long_read(&dev->write_bytes) >> 20);
30712d23384SNicholas Bellinger }
30812d23384SNicholas Bellinger 
target_stat_lu_resets_show(struct config_item * item,char * page)3092eafd729SChristoph Hellwig static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page)
31012d23384SNicholas Bellinger {
3112eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
31212d23384SNicholas Bellinger 
31312d23384SNicholas Bellinger 	/* scsiLuInResets */
3142eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%lu\n",
3152eafd729SChristoph Hellwig 		atomic_long_read(&dev->num_resets));
31612d23384SNicholas Bellinger }
31712d23384SNicholas Bellinger 
target_stat_lu_full_stat_show(struct config_item * item,char * page)3182eafd729SChristoph Hellwig static ssize_t target_stat_lu_full_stat_show(struct config_item *item,
3192eafd729SChristoph Hellwig 		char *page)
32012d23384SNicholas Bellinger {
32112d23384SNicholas Bellinger 	/* FIXME: scsiLuOutTaskSetFullStatus */
32212d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", 0);
32312d23384SNicholas Bellinger }
32412d23384SNicholas Bellinger 
target_stat_lu_hs_num_cmds_show(struct config_item * item,char * page)3252eafd729SChristoph Hellwig static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item,
3262eafd729SChristoph Hellwig 		char *page)
32712d23384SNicholas Bellinger {
32812d23384SNicholas Bellinger 	/* FIXME: scsiLuHSInCommands */
32912d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", 0);
33012d23384SNicholas Bellinger }
33112d23384SNicholas Bellinger 
target_stat_lu_creation_time_show(struct config_item * item,char * page)3322eafd729SChristoph Hellwig static ssize_t target_stat_lu_creation_time_show(struct config_item *item,
3332eafd729SChristoph Hellwig 		char *page)
33412d23384SNicholas Bellinger {
3352eafd729SChristoph Hellwig 	struct se_device *dev = to_stat_lu_dev(item);
33612d23384SNicholas Bellinger 
33712d23384SNicholas Bellinger 	/* scsiLuCreationTime */
33812d23384SNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
33912d23384SNicholas Bellinger 				INITIAL_JIFFIES) * 100 / HZ));
34012d23384SNicholas Bellinger }
34112d23384SNicholas Bellinger 
3422eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, inst);
3432eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, dev);
3442eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, indx);
3452eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, lun);
3462eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, lu_name);
3472eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, vend);
3482eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, prod);
3492eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, rev);
3502eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, dev_type);
3512eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, status);
3522eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, state_bit);
3532eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds);
3542eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes);
3552eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes);
3562eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, resets);
3572eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, full_stat);
3582eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds);
3592eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_lu_, creation_time);
36012d23384SNicholas Bellinger 
36112d23384SNicholas Bellinger static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
3622eafd729SChristoph Hellwig 	&target_stat_lu_attr_inst,
3632eafd729SChristoph Hellwig 	&target_stat_lu_attr_dev,
3642eafd729SChristoph Hellwig 	&target_stat_lu_attr_indx,
3652eafd729SChristoph Hellwig 	&target_stat_lu_attr_lun,
3662eafd729SChristoph Hellwig 	&target_stat_lu_attr_lu_name,
3672eafd729SChristoph Hellwig 	&target_stat_lu_attr_vend,
3682eafd729SChristoph Hellwig 	&target_stat_lu_attr_prod,
3692eafd729SChristoph Hellwig 	&target_stat_lu_attr_rev,
3702eafd729SChristoph Hellwig 	&target_stat_lu_attr_dev_type,
3712eafd729SChristoph Hellwig 	&target_stat_lu_attr_status,
3722eafd729SChristoph Hellwig 	&target_stat_lu_attr_state_bit,
3732eafd729SChristoph Hellwig 	&target_stat_lu_attr_num_cmds,
3742eafd729SChristoph Hellwig 	&target_stat_lu_attr_read_mbytes,
3752eafd729SChristoph Hellwig 	&target_stat_lu_attr_write_mbytes,
3762eafd729SChristoph Hellwig 	&target_stat_lu_attr_resets,
3772eafd729SChristoph Hellwig 	&target_stat_lu_attr_full_stat,
3782eafd729SChristoph Hellwig 	&target_stat_lu_attr_hs_num_cmds,
3792eafd729SChristoph Hellwig 	&target_stat_lu_attr_creation_time,
38012d23384SNicholas Bellinger 	NULL,
38112d23384SNicholas Bellinger };
38212d23384SNicholas Bellinger 
383ece550b5SBhumika Goyal static const struct config_item_type target_stat_scsi_lu_cit = {
38412d23384SNicholas Bellinger 	.ct_attrs		= target_stat_scsi_lu_attrs,
38512d23384SNicholas Bellinger 	.ct_owner		= THIS_MODULE,
38612d23384SNicholas Bellinger };
38712d23384SNicholas Bellinger 
38812d23384SNicholas Bellinger /*
38912d23384SNicholas Bellinger  * Called from target_core_configfs.c:target_core_make_subdev() to setup
39012d23384SNicholas Bellinger  * the target statistics groups + configfs CITs located in target_core_stat.c
39112d23384SNicholas Bellinger  */
target_stat_setup_dev_default_groups(struct se_device * dev)3920fd97ccfSChristoph Hellwig void target_stat_setup_dev_default_groups(struct se_device *dev)
39312d23384SNicholas Bellinger {
3940fd97ccfSChristoph Hellwig 	config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
39512d23384SNicholas Bellinger 			"scsi_dev", &target_stat_scsi_dev_cit);
3961ae1602dSChristoph Hellwig 	configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group,
3971ae1602dSChristoph Hellwig 			&dev->dev_stat_grps.stat_group);
3981ae1602dSChristoph Hellwig 
3990fd97ccfSChristoph Hellwig 	config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
40012d23384SNicholas Bellinger 			"scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
4011ae1602dSChristoph Hellwig 	configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group,
4021ae1602dSChristoph Hellwig 			&dev->dev_stat_grps.stat_group);
4031ae1602dSChristoph Hellwig 
4040fd97ccfSChristoph Hellwig 	config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
40512d23384SNicholas Bellinger 			"scsi_lu", &target_stat_scsi_lu_cit);
4061ae1602dSChristoph Hellwig 	configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group,
4071ae1602dSChristoph Hellwig 			&dev->dev_stat_grps.stat_group);
40812d23384SNicholas Bellinger }
40912d23384SNicholas Bellinger 
41012d23384SNicholas Bellinger /*
41112d23384SNicholas Bellinger  * SCSI Port Table
41212d23384SNicholas Bellinger  */
41312d23384SNicholas Bellinger 
to_stat_port(struct config_item * item)4142eafd729SChristoph Hellwig static struct se_lun *to_stat_port(struct config_item *item)
41512d23384SNicholas Bellinger {
4162eafd729SChristoph Hellwig 	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
4172eafd729SChristoph Hellwig 			struct se_port_stat_grps, scsi_port_group);
4182eafd729SChristoph Hellwig 	return container_of(pgrps, struct se_lun, port_stat_grps);
4192eafd729SChristoph Hellwig }
4202eafd729SChristoph Hellwig 
target_stat_port_inst_show(struct config_item * item,char * page)4212eafd729SChristoph Hellwig static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
4222eafd729SChristoph Hellwig {
4232eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_port(item);
424adf653f9SChristoph Hellwig 	struct se_device *dev;
425adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
42612d23384SNicholas Bellinger 
4274cc987eaSNicholas Bellinger 	rcu_read_lock();
4284cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
429adf653f9SChristoph Hellwig 	if (dev)
4304cc987eaSNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
4314cc987eaSNicholas Bellinger 	rcu_read_unlock();
43212d23384SNicholas Bellinger 	return ret;
43312d23384SNicholas Bellinger }
43412d23384SNicholas Bellinger 
target_stat_port_dev_show(struct config_item * item,char * page)4352eafd729SChristoph Hellwig static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
43612d23384SNicholas Bellinger {
4372eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_port(item);
438adf653f9SChristoph Hellwig 	struct se_device *dev;
439adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
44012d23384SNicholas Bellinger 
4414cc987eaSNicholas Bellinger 	rcu_read_lock();
4424cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
443adf653f9SChristoph Hellwig 	if (dev)
44412d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
4454cc987eaSNicholas Bellinger 	rcu_read_unlock();
44612d23384SNicholas Bellinger 	return ret;
44712d23384SNicholas Bellinger }
44812d23384SNicholas Bellinger 
target_stat_port_indx_show(struct config_item * item,char * page)4492eafd729SChristoph Hellwig static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
45012d23384SNicholas Bellinger {
4512eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_port(item);
452adf653f9SChristoph Hellwig 	struct se_device *dev;
453adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
45412d23384SNicholas Bellinger 
4554cc987eaSNicholas Bellinger 	rcu_read_lock();
4564cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
457adf653f9SChristoph Hellwig 	if (dev)
458*b9e063adSRoman Bolshakov 		ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_tpg->tpg_rtpi);
4594cc987eaSNicholas Bellinger 	rcu_read_unlock();
46012d23384SNicholas Bellinger 	return ret;
46112d23384SNicholas Bellinger }
46212d23384SNicholas Bellinger 
target_stat_port_role_show(struct config_item * item,char * page)4632eafd729SChristoph Hellwig static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
46412d23384SNicholas Bellinger {
4652eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_port(item);
466adf653f9SChristoph Hellwig 	struct se_device *dev;
467adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
46812d23384SNicholas Bellinger 
4694cc987eaSNicholas Bellinger 	rcu_read_lock();
4704cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
471adf653f9SChristoph Hellwig 	if (dev)
47212d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
4734cc987eaSNicholas Bellinger 	rcu_read_unlock();
47412d23384SNicholas Bellinger 	return ret;
47512d23384SNicholas Bellinger }
47612d23384SNicholas Bellinger 
target_stat_port_busy_count_show(struct config_item * item,char * page)4772eafd729SChristoph Hellwig static ssize_t target_stat_port_busy_count_show(struct config_item *item,
4782eafd729SChristoph Hellwig 		char *page)
47912d23384SNicholas Bellinger {
4802eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_port(item);
481adf653f9SChristoph Hellwig 	struct se_device *dev;
482adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
48312d23384SNicholas Bellinger 
4844cc987eaSNicholas Bellinger 	rcu_read_lock();
4854cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
486adf653f9SChristoph Hellwig 	if (dev) {
48712d23384SNicholas Bellinger 		/* FIXME: scsiPortBusyStatuses  */
48812d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
489adf653f9SChristoph Hellwig 	}
4904cc987eaSNicholas Bellinger 	rcu_read_unlock();
49112d23384SNicholas Bellinger 	return ret;
49212d23384SNicholas Bellinger }
49312d23384SNicholas Bellinger 
4942eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_port_, inst);
4952eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_port_, dev);
4962eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_port_, indx);
4972eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_port_, role);
4982eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_port_, busy_count);
49912d23384SNicholas Bellinger 
50012d23384SNicholas Bellinger static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
5012eafd729SChristoph Hellwig 	&target_stat_port_attr_inst,
5022eafd729SChristoph Hellwig 	&target_stat_port_attr_dev,
5032eafd729SChristoph Hellwig 	&target_stat_port_attr_indx,
5042eafd729SChristoph Hellwig 	&target_stat_port_attr_role,
5052eafd729SChristoph Hellwig 	&target_stat_port_attr_busy_count,
50612d23384SNicholas Bellinger 	NULL,
50712d23384SNicholas Bellinger };
50812d23384SNicholas Bellinger 
509ece550b5SBhumika Goyal static const struct config_item_type target_stat_scsi_port_cit = {
51012d23384SNicholas Bellinger 	.ct_attrs		= target_stat_scsi_port_attrs,
51112d23384SNicholas Bellinger 	.ct_owner		= THIS_MODULE,
51212d23384SNicholas Bellinger };
51312d23384SNicholas Bellinger 
51412d23384SNicholas Bellinger /*
51512d23384SNicholas Bellinger  * SCSI Target Port Table
51612d23384SNicholas Bellinger  */
to_stat_tgt_port(struct config_item * item)5172eafd729SChristoph Hellwig static struct se_lun *to_stat_tgt_port(struct config_item *item)
51812d23384SNicholas Bellinger {
5192eafd729SChristoph Hellwig 	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
5202eafd729SChristoph Hellwig 			struct se_port_stat_grps, scsi_tgt_port_group);
5212eafd729SChristoph Hellwig 	return container_of(pgrps, struct se_lun, port_stat_grps);
5222eafd729SChristoph Hellwig }
5232eafd729SChristoph Hellwig 
target_stat_tgt_port_inst_show(struct config_item * item,char * page)5242eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
5252eafd729SChristoph Hellwig 		char *page)
5262eafd729SChristoph Hellwig {
5272eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
528adf653f9SChristoph Hellwig 	struct se_device *dev;
529adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
53012d23384SNicholas Bellinger 
5314cc987eaSNicholas Bellinger 	rcu_read_lock();
5324cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
533adf653f9SChristoph Hellwig 	if (dev)
5344cc987eaSNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
5354cc987eaSNicholas Bellinger 	rcu_read_unlock();
53612d23384SNicholas Bellinger 	return ret;
53712d23384SNicholas Bellinger }
53812d23384SNicholas Bellinger 
target_stat_tgt_port_dev_show(struct config_item * item,char * page)5392eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
5402eafd729SChristoph Hellwig 		char *page)
54112d23384SNicholas Bellinger {
5422eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
543adf653f9SChristoph Hellwig 	struct se_device *dev;
544adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
54512d23384SNicholas Bellinger 
5464cc987eaSNicholas Bellinger 	rcu_read_lock();
5474cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
548adf653f9SChristoph Hellwig 	if (dev)
54912d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
5504cc987eaSNicholas Bellinger 	rcu_read_unlock();
55112d23384SNicholas Bellinger 	return ret;
55212d23384SNicholas Bellinger }
55312d23384SNicholas Bellinger 
target_stat_tgt_port_indx_show(struct config_item * item,char * page)5542eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
5552eafd729SChristoph Hellwig 		char *page)
55612d23384SNicholas Bellinger {
5572eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
558adf653f9SChristoph Hellwig 	struct se_device *dev;
559adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
56012d23384SNicholas Bellinger 
5614cc987eaSNicholas Bellinger 	rcu_read_lock();
5624cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
563adf653f9SChristoph Hellwig 	if (dev)
564*b9e063adSRoman Bolshakov 		ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_tpg->tpg_rtpi);
5654cc987eaSNicholas Bellinger 	rcu_read_unlock();
56612d23384SNicholas Bellinger 	return ret;
56712d23384SNicholas Bellinger }
56812d23384SNicholas Bellinger 
target_stat_tgt_port_name_show(struct config_item * item,char * page)5692eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
5702eafd729SChristoph Hellwig 		char *page)
57112d23384SNicholas Bellinger {
5722eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
573adf653f9SChristoph Hellwig 	struct se_portal_group *tpg = lun->lun_tpg;
574adf653f9SChristoph Hellwig 	struct se_device *dev;
575adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
57612d23384SNicholas Bellinger 
5774cc987eaSNicholas Bellinger 	rcu_read_lock();
5784cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
579adf653f9SChristoph Hellwig 	if (dev)
58012d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
58130c7ca93SDavid Disseldorp 			tpg->se_tpg_tfo->fabric_name,
582*b9e063adSRoman Bolshakov 			lun->lun_tpg->tpg_rtpi);
5834cc987eaSNicholas Bellinger 	rcu_read_unlock();
58412d23384SNicholas Bellinger 	return ret;
58512d23384SNicholas Bellinger }
58612d23384SNicholas Bellinger 
target_stat_tgt_port_port_index_show(struct config_item * item,char * page)5872eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
5882eafd729SChristoph Hellwig 		char *page)
58912d23384SNicholas Bellinger {
5902eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
591adf653f9SChristoph Hellwig 	struct se_portal_group *tpg = lun->lun_tpg;
592adf653f9SChristoph Hellwig 	struct se_device *dev;
593adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
59412d23384SNicholas Bellinger 
5954cc987eaSNicholas Bellinger 	rcu_read_lock();
5964cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
597adf653f9SChristoph Hellwig 	if (dev)
59812d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
599e3d6f909SAndy Grover 			tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
600e3d6f909SAndy Grover 			tpg->se_tpg_tfo->tpg_get_tag(tpg));
6014cc987eaSNicholas Bellinger 	rcu_read_unlock();
60212d23384SNicholas Bellinger 	return ret;
60312d23384SNicholas Bellinger }
60412d23384SNicholas Bellinger 
target_stat_tgt_port_in_cmds_show(struct config_item * item,char * page)6052eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
6062eafd729SChristoph Hellwig 		char *page)
60712d23384SNicholas Bellinger {
6082eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
609adf653f9SChristoph Hellwig 	struct se_device *dev;
610adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
61112d23384SNicholas Bellinger 
6124cc987eaSNicholas Bellinger 	rcu_read_lock();
6134cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
614adf653f9SChristoph Hellwig 	if (dev)
6154cc987eaSNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%lu\n",
6164cc987eaSNicholas Bellinger 			       atomic_long_read(&lun->lun_stats.cmd_pdus));
6174cc987eaSNicholas Bellinger 	rcu_read_unlock();
61812d23384SNicholas Bellinger 	return ret;
61912d23384SNicholas Bellinger }
62012d23384SNicholas Bellinger 
target_stat_tgt_port_write_mbytes_show(struct config_item * item,char * page)6212eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
6222eafd729SChristoph Hellwig 		char *page)
62312d23384SNicholas Bellinger {
6242eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
625adf653f9SChristoph Hellwig 	struct se_device *dev;
626adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
62712d23384SNicholas Bellinger 
6284cc987eaSNicholas Bellinger 	rcu_read_lock();
6294cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
630adf653f9SChristoph Hellwig 	if (dev)
63112d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n",
6324cc987eaSNicholas Bellinger 			(u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20));
6334cc987eaSNicholas Bellinger 	rcu_read_unlock();
63412d23384SNicholas Bellinger 	return ret;
63512d23384SNicholas Bellinger }
63612d23384SNicholas Bellinger 
target_stat_tgt_port_read_mbytes_show(struct config_item * item,char * page)6372eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
6382eafd729SChristoph Hellwig 		char *page)
63912d23384SNicholas Bellinger {
6402eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
641adf653f9SChristoph Hellwig 	struct se_device *dev;
642adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
64312d23384SNicholas Bellinger 
6444cc987eaSNicholas Bellinger 	rcu_read_lock();
6454cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
646adf653f9SChristoph Hellwig 	if (dev)
64712d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n",
6484cc987eaSNicholas Bellinger 				(u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20));
6494cc987eaSNicholas Bellinger 	rcu_read_unlock();
65012d23384SNicholas Bellinger 	return ret;
65112d23384SNicholas Bellinger }
65212d23384SNicholas Bellinger 
target_stat_tgt_port_hs_in_cmds_show(struct config_item * item,char * page)6532eafd729SChristoph Hellwig static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
6542eafd729SChristoph Hellwig 		char *page)
65512d23384SNicholas Bellinger {
6562eafd729SChristoph Hellwig 	struct se_lun *lun = to_stat_tgt_port(item);
657adf653f9SChristoph Hellwig 	struct se_device *dev;
658adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
65912d23384SNicholas Bellinger 
6604cc987eaSNicholas Bellinger 	rcu_read_lock();
6614cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
662adf653f9SChristoph Hellwig 	if (dev) {
66312d23384SNicholas Bellinger 		/* FIXME: scsiTgtPortHsInCommands */
66412d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
665adf653f9SChristoph Hellwig 	}
6664cc987eaSNicholas Bellinger 	rcu_read_unlock();
66712d23384SNicholas Bellinger 	return ret;
66812d23384SNicholas Bellinger }
66912d23384SNicholas Bellinger 
6702eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
6712eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
6722eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
6732eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, name);
6742eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index);
6752eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds);
6762eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
6772eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
6782eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
67912d23384SNicholas Bellinger 
68012d23384SNicholas Bellinger static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
6812eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_inst,
6822eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_dev,
6832eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_indx,
6842eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_name,
6852eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_port_index,
6862eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_in_cmds,
6872eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_write_mbytes,
6882eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_read_mbytes,
6892eafd729SChristoph Hellwig 	&target_stat_tgt_port_attr_hs_in_cmds,
69012d23384SNicholas Bellinger 	NULL,
69112d23384SNicholas Bellinger };
69212d23384SNicholas Bellinger 
693ece550b5SBhumika Goyal static const struct config_item_type target_stat_scsi_tgt_port_cit = {
69412d23384SNicholas Bellinger 	.ct_attrs		= target_stat_scsi_tgt_port_attrs,
69512d23384SNicholas Bellinger 	.ct_owner		= THIS_MODULE,
69612d23384SNicholas Bellinger };
69712d23384SNicholas Bellinger 
69812d23384SNicholas Bellinger /*
69912d23384SNicholas Bellinger  * SCSI Transport Table
7002eafd729SChristoph Hellwig  */
to_transport_stat(struct config_item * item)7012eafd729SChristoph Hellwig static struct se_lun *to_transport_stat(struct config_item *item)
70212d23384SNicholas Bellinger {
7032eafd729SChristoph Hellwig 	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
7042eafd729SChristoph Hellwig 			struct se_port_stat_grps, scsi_transport_group);
7052eafd729SChristoph Hellwig 	return container_of(pgrps, struct se_lun, port_stat_grps);
7062eafd729SChristoph Hellwig }
7072eafd729SChristoph Hellwig 
target_stat_transport_inst_show(struct config_item * item,char * page)7082eafd729SChristoph Hellwig static ssize_t target_stat_transport_inst_show(struct config_item *item,
7092eafd729SChristoph Hellwig 		char *page)
7102eafd729SChristoph Hellwig {
7112eafd729SChristoph Hellwig 	struct se_lun *lun = to_transport_stat(item);
712adf653f9SChristoph Hellwig 	struct se_device *dev;
713adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
71412d23384SNicholas Bellinger 
7154cc987eaSNicholas Bellinger 	rcu_read_lock();
7164cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
717adf653f9SChristoph Hellwig 	if (dev)
7184cc987eaSNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
7194cc987eaSNicholas Bellinger 	rcu_read_unlock();
72012d23384SNicholas Bellinger 	return ret;
72112d23384SNicholas Bellinger }
72212d23384SNicholas Bellinger 
target_stat_transport_device_show(struct config_item * item,char * page)7232eafd729SChristoph Hellwig static ssize_t target_stat_transport_device_show(struct config_item *item,
7242eafd729SChristoph Hellwig 		char *page)
72512d23384SNicholas Bellinger {
7262eafd729SChristoph Hellwig 	struct se_lun *lun = to_transport_stat(item);
727adf653f9SChristoph Hellwig 	struct se_device *dev;
728adf653f9SChristoph Hellwig 	struct se_portal_group *tpg = lun->lun_tpg;
729adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
73012d23384SNicholas Bellinger 
7314cc987eaSNicholas Bellinger 	rcu_read_lock();
7324cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
733adf653f9SChristoph Hellwig 	if (dev) {
73412d23384SNicholas Bellinger 		/* scsiTransportType */
73512d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
73630c7ca93SDavid Disseldorp 			       tpg->se_tpg_tfo->fabric_name);
737adf653f9SChristoph Hellwig 	}
7384cc987eaSNicholas Bellinger 	rcu_read_unlock();
73912d23384SNicholas Bellinger 	return ret;
74012d23384SNicholas Bellinger }
74112d23384SNicholas Bellinger 
target_stat_transport_indx_show(struct config_item * item,char * page)7422eafd729SChristoph Hellwig static ssize_t target_stat_transport_indx_show(struct config_item *item,
7432eafd729SChristoph Hellwig 		char *page)
74412d23384SNicholas Bellinger {
7452eafd729SChristoph Hellwig 	struct se_lun *lun = to_transport_stat(item);
746adf653f9SChristoph Hellwig 	struct se_device *dev;
747adf653f9SChristoph Hellwig 	struct se_portal_group *tpg = lun->lun_tpg;
748adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
74912d23384SNicholas Bellinger 
7504cc987eaSNicholas Bellinger 	rcu_read_lock();
7514cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
752adf653f9SChristoph Hellwig 	if (dev)
75312d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%u\n",
754e3d6f909SAndy Grover 			       tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
7554cc987eaSNicholas Bellinger 	rcu_read_unlock();
75612d23384SNicholas Bellinger 	return ret;
75712d23384SNicholas Bellinger }
75812d23384SNicholas Bellinger 
target_stat_transport_dev_name_show(struct config_item * item,char * page)7592eafd729SChristoph Hellwig static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
7602eafd729SChristoph Hellwig 		char *page)
76112d23384SNicholas Bellinger {
7622eafd729SChristoph Hellwig 	struct se_lun *lun = to_transport_stat(item);
7634cc987eaSNicholas Bellinger 	struct se_device *dev;
764adf653f9SChristoph Hellwig 	struct se_portal_group *tpg = lun->lun_tpg;
76512d23384SNicholas Bellinger 	struct t10_wwn *wwn;
766adf653f9SChristoph Hellwig 	ssize_t ret = -ENODEV;
76712d23384SNicholas Bellinger 
7684cc987eaSNicholas Bellinger 	rcu_read_lock();
7694cc987eaSNicholas Bellinger 	dev = rcu_dereference(lun->lun_se_dev);
770adf653f9SChristoph Hellwig 	if (dev) {
7710fd97ccfSChristoph Hellwig 		wwn = &dev->t10_wwn;
77212d23384SNicholas Bellinger 		/* scsiTransportDevName */
77312d23384SNicholas Bellinger 		ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
774e3d6f909SAndy Grover 				tpg->se_tpg_tfo->tpg_get_wwn(tpg),
77512d23384SNicholas Bellinger 				(strlen(wwn->unit_serial)) ? wwn->unit_serial :
77612d23384SNicholas Bellinger 				wwn->vendor);
777adf653f9SChristoph Hellwig 	}
7784cc987eaSNicholas Bellinger 	rcu_read_unlock();
77912d23384SNicholas Bellinger 	return ret;
78012d23384SNicholas Bellinger }
78112d23384SNicholas Bellinger 
target_stat_transport_proto_id_show(struct config_item * item,char * page)7820ab8ac6fSMike Christie static ssize_t target_stat_transport_proto_id_show(struct config_item *item,
7830ab8ac6fSMike Christie 		char *page)
7840ab8ac6fSMike Christie {
7850ab8ac6fSMike Christie 	struct se_lun *lun = to_transport_stat(item);
7860ab8ac6fSMike Christie 	struct se_device *dev;
7870ab8ac6fSMike Christie 	struct se_portal_group *tpg = lun->lun_tpg;
7880ab8ac6fSMike Christie 	ssize_t ret = -ENODEV;
7890ab8ac6fSMike Christie 
7900ab8ac6fSMike Christie 	rcu_read_lock();
7910ab8ac6fSMike Christie 	dev = rcu_dereference(lun->lun_se_dev);
7920ab8ac6fSMike Christie 	if (dev)
7930ab8ac6fSMike Christie 		ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->proto_id);
7940ab8ac6fSMike Christie 	rcu_read_unlock();
7950ab8ac6fSMike Christie 	return ret;
7960ab8ac6fSMike Christie }
7970ab8ac6fSMike Christie 
7982eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_transport_, inst);
7992eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_transport_, device);
8002eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_transport_, indx);
8012eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_transport_, dev_name);
8020ab8ac6fSMike Christie CONFIGFS_ATTR_RO(target_stat_transport_, proto_id);
80312d23384SNicholas Bellinger 
80412d23384SNicholas Bellinger static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
8052eafd729SChristoph Hellwig 	&target_stat_transport_attr_inst,
8062eafd729SChristoph Hellwig 	&target_stat_transport_attr_device,
8072eafd729SChristoph Hellwig 	&target_stat_transport_attr_indx,
8082eafd729SChristoph Hellwig 	&target_stat_transport_attr_dev_name,
8090ab8ac6fSMike Christie 	&target_stat_transport_attr_proto_id,
81012d23384SNicholas Bellinger 	NULL,
81112d23384SNicholas Bellinger };
81212d23384SNicholas Bellinger 
813ece550b5SBhumika Goyal static const struct config_item_type target_stat_scsi_transport_cit = {
81412d23384SNicholas Bellinger 	.ct_attrs		= target_stat_scsi_transport_attrs,
81512d23384SNicholas Bellinger 	.ct_owner		= THIS_MODULE,
81612d23384SNicholas Bellinger };
81712d23384SNicholas Bellinger 
81812d23384SNicholas Bellinger /*
81912d23384SNicholas Bellinger  * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
82012d23384SNicholas Bellinger  * the target port statistics groups + configfs CITs located in target_core_stat.c
82112d23384SNicholas Bellinger  */
target_stat_setup_port_default_groups(struct se_lun * lun)82212d23384SNicholas Bellinger void target_stat_setup_port_default_groups(struct se_lun *lun)
82312d23384SNicholas Bellinger {
824e3d6f909SAndy Grover 	config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
82512d23384SNicholas Bellinger 			"scsi_port", &target_stat_scsi_port_cit);
8261ae1602dSChristoph Hellwig 	configfs_add_default_group(&lun->port_stat_grps.scsi_port_group,
8271ae1602dSChristoph Hellwig 			&lun->port_stat_grps.stat_group);
8281ae1602dSChristoph Hellwig 
829e3d6f909SAndy Grover 	config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
83012d23384SNicholas Bellinger 			"scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
8311ae1602dSChristoph Hellwig 	configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group,
8321ae1602dSChristoph Hellwig 			&lun->port_stat_grps.stat_group);
8331ae1602dSChristoph Hellwig 
834e3d6f909SAndy Grover 	config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
83512d23384SNicholas Bellinger 			"scsi_transport", &target_stat_scsi_transport_cit);
8361ae1602dSChristoph Hellwig 	configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group,
8371ae1602dSChristoph Hellwig 			&lun->port_stat_grps.stat_group);
83812d23384SNicholas Bellinger }
83912d23384SNicholas Bellinger 
84012d23384SNicholas Bellinger /*
84112d23384SNicholas Bellinger  * SCSI Authorized Initiator Table
84212d23384SNicholas Bellinger  */
84312d23384SNicholas Bellinger 
auth_to_lacl(struct config_item * item)8442eafd729SChristoph Hellwig static struct se_lun_acl *auth_to_lacl(struct config_item *item)
84512d23384SNicholas Bellinger {
8462eafd729SChristoph Hellwig 	struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
8472eafd729SChristoph Hellwig 			struct se_ml_stat_grps, scsi_auth_intr_group);
8482eafd729SChristoph Hellwig 	return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
8492eafd729SChristoph Hellwig }
8502eafd729SChristoph Hellwig 
target_stat_auth_inst_show(struct config_item * item,char * page)8512eafd729SChristoph Hellwig static ssize_t target_stat_auth_inst_show(struct config_item *item,
8522eafd729SChristoph Hellwig 		char *page)
8532eafd729SChristoph Hellwig {
8542eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
85512d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
85612d23384SNicholas Bellinger 	struct se_dev_entry *deve;
85712d23384SNicholas Bellinger 	struct se_portal_group *tpg;
85812d23384SNicholas Bellinger 	ssize_t ret;
85912d23384SNicholas Bellinger 
86029a05deeSNicholas Bellinger 	rcu_read_lock();
86129a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
86229a05deeSNicholas Bellinger 	if (!deve) {
86329a05deeSNicholas Bellinger 		rcu_read_unlock();
86412d23384SNicholas Bellinger 		return -ENODEV;
86512d23384SNicholas Bellinger 	}
86612d23384SNicholas Bellinger 	tpg = nacl->se_tpg;
86712d23384SNicholas Bellinger 	/* scsiInstIndex */
86812d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n",
869e3d6f909SAndy Grover 			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
87029a05deeSNicholas Bellinger 	rcu_read_unlock();
87112d23384SNicholas Bellinger 	return ret;
87212d23384SNicholas Bellinger }
87312d23384SNicholas Bellinger 
target_stat_auth_dev_show(struct config_item * item,char * page)8742eafd729SChristoph Hellwig static ssize_t target_stat_auth_dev_show(struct config_item *item,
8752eafd729SChristoph Hellwig 		char *page)
87612d23384SNicholas Bellinger {
8772eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
87812d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
87912d23384SNicholas Bellinger 	struct se_dev_entry *deve;
88012d23384SNicholas Bellinger 	ssize_t ret;
88112d23384SNicholas Bellinger 
88229a05deeSNicholas Bellinger 	rcu_read_lock();
88329a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
88429a05deeSNicholas Bellinger 	if (!deve) {
88529a05deeSNicholas Bellinger 		rcu_read_unlock();
88612d23384SNicholas Bellinger 		return -ENODEV;
88712d23384SNicholas Bellinger 	}
888ef4f7e4bSDmitry Bogdanov 
88912d23384SNicholas Bellinger 	/* scsiDeviceIndex */
890ef4f7e4bSDmitry Bogdanov 	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index);
89129a05deeSNicholas Bellinger 	rcu_read_unlock();
89212d23384SNicholas Bellinger 	return ret;
89312d23384SNicholas Bellinger }
89412d23384SNicholas Bellinger 
target_stat_auth_port_show(struct config_item * item,char * page)8952eafd729SChristoph Hellwig static ssize_t target_stat_auth_port_show(struct config_item *item,
8962eafd729SChristoph Hellwig 		char *page)
89712d23384SNicholas Bellinger {
8982eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
89912d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
90012d23384SNicholas Bellinger 	struct se_dev_entry *deve;
90112d23384SNicholas Bellinger 	struct se_portal_group *tpg;
90212d23384SNicholas Bellinger 	ssize_t ret;
90312d23384SNicholas Bellinger 
90429a05deeSNicholas Bellinger 	rcu_read_lock();
90529a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
90629a05deeSNicholas Bellinger 	if (!deve) {
90729a05deeSNicholas Bellinger 		rcu_read_unlock();
90812d23384SNicholas Bellinger 		return -ENODEV;
90912d23384SNicholas Bellinger 	}
91012d23384SNicholas Bellinger 	tpg = nacl->se_tpg;
91112d23384SNicholas Bellinger 	/* scsiAuthIntrTgtPortIndex */
912e3d6f909SAndy Grover 	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
91329a05deeSNicholas Bellinger 	rcu_read_unlock();
91412d23384SNicholas Bellinger 	return ret;
91512d23384SNicholas Bellinger }
91612d23384SNicholas Bellinger 
target_stat_auth_indx_show(struct config_item * item,char * page)9172eafd729SChristoph Hellwig static ssize_t target_stat_auth_indx_show(struct config_item *item,
9182eafd729SChristoph Hellwig 		char *page)
91912d23384SNicholas Bellinger {
9202eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
92112d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
92212d23384SNicholas Bellinger 	struct se_dev_entry *deve;
92312d23384SNicholas Bellinger 	ssize_t ret;
92412d23384SNicholas Bellinger 
92529a05deeSNicholas Bellinger 	rcu_read_lock();
92629a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
92729a05deeSNicholas Bellinger 	if (!deve) {
92829a05deeSNicholas Bellinger 		rcu_read_unlock();
92912d23384SNicholas Bellinger 		return -ENODEV;
93012d23384SNicholas Bellinger 	}
93112d23384SNicholas Bellinger 	/* scsiAuthIntrIndex */
93212d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
93329a05deeSNicholas Bellinger 	rcu_read_unlock();
93412d23384SNicholas Bellinger 	return ret;
93512d23384SNicholas Bellinger }
93612d23384SNicholas Bellinger 
target_stat_auth_dev_or_port_show(struct config_item * item,char * page)9372eafd729SChristoph Hellwig static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
9382eafd729SChristoph Hellwig 		char *page)
93912d23384SNicholas Bellinger {
9402eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
94112d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
94212d23384SNicholas Bellinger 	struct se_dev_entry *deve;
94312d23384SNicholas Bellinger 	ssize_t ret;
94412d23384SNicholas Bellinger 
94529a05deeSNicholas Bellinger 	rcu_read_lock();
94629a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
94729a05deeSNicholas Bellinger 	if (!deve) {
94829a05deeSNicholas Bellinger 		rcu_read_unlock();
94912d23384SNicholas Bellinger 		return -ENODEV;
95012d23384SNicholas Bellinger 	}
95112d23384SNicholas Bellinger 	/* scsiAuthIntrDevOrPort */
95212d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
95329a05deeSNicholas Bellinger 	rcu_read_unlock();
95412d23384SNicholas Bellinger 	return ret;
95512d23384SNicholas Bellinger }
95612d23384SNicholas Bellinger 
target_stat_auth_intr_name_show(struct config_item * item,char * page)9572eafd729SChristoph Hellwig static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
9582eafd729SChristoph Hellwig 		char *page)
95912d23384SNicholas Bellinger {
9602eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
96112d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
96212d23384SNicholas Bellinger 	struct se_dev_entry *deve;
96312d23384SNicholas Bellinger 	ssize_t ret;
96412d23384SNicholas Bellinger 
96529a05deeSNicholas Bellinger 	rcu_read_lock();
96629a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
96729a05deeSNicholas Bellinger 	if (!deve) {
96829a05deeSNicholas Bellinger 		rcu_read_unlock();
96912d23384SNicholas Bellinger 		return -ENODEV;
97012d23384SNicholas Bellinger 	}
97112d23384SNicholas Bellinger 	/* scsiAuthIntrName */
97212d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
97329a05deeSNicholas Bellinger 	rcu_read_unlock();
97412d23384SNicholas Bellinger 	return ret;
97512d23384SNicholas Bellinger }
97612d23384SNicholas Bellinger 
target_stat_auth_map_indx_show(struct config_item * item,char * page)9772eafd729SChristoph Hellwig static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
9782eafd729SChristoph Hellwig 		char *page)
97912d23384SNicholas Bellinger {
9802eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
98112d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
98212d23384SNicholas Bellinger 	struct se_dev_entry *deve;
98312d23384SNicholas Bellinger 	ssize_t ret;
98412d23384SNicholas Bellinger 
98529a05deeSNicholas Bellinger 	rcu_read_lock();
98629a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
98729a05deeSNicholas Bellinger 	if (!deve) {
98829a05deeSNicholas Bellinger 		rcu_read_unlock();
98912d23384SNicholas Bellinger 		return -ENODEV;
99012d23384SNicholas Bellinger 	}
99112d23384SNicholas Bellinger 	/* FIXME: scsiAuthIntrLunMapIndex */
99212d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
99329a05deeSNicholas Bellinger 	rcu_read_unlock();
99412d23384SNicholas Bellinger 	return ret;
99512d23384SNicholas Bellinger }
99612d23384SNicholas Bellinger 
target_stat_auth_att_count_show(struct config_item * item,char * page)9972eafd729SChristoph Hellwig static ssize_t target_stat_auth_att_count_show(struct config_item *item,
9982eafd729SChristoph Hellwig 		char *page)
99912d23384SNicholas Bellinger {
10002eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
100112d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
100212d23384SNicholas Bellinger 	struct se_dev_entry *deve;
100312d23384SNicholas Bellinger 	ssize_t ret;
100412d23384SNicholas Bellinger 
100529a05deeSNicholas Bellinger 	rcu_read_lock();
100629a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
100729a05deeSNicholas Bellinger 	if (!deve) {
100829a05deeSNicholas Bellinger 		rcu_read_unlock();
100912d23384SNicholas Bellinger 		return -ENODEV;
101012d23384SNicholas Bellinger 	}
101112d23384SNicholas Bellinger 	/* scsiAuthIntrAttachedTimes */
101212d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
101329a05deeSNicholas Bellinger 	rcu_read_unlock();
101412d23384SNicholas Bellinger 	return ret;
101512d23384SNicholas Bellinger }
101612d23384SNicholas Bellinger 
target_stat_auth_num_cmds_show(struct config_item * item,char * page)10172eafd729SChristoph Hellwig static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
10182eafd729SChristoph Hellwig 		char *page)
101912d23384SNicholas Bellinger {
10202eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
102112d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
102212d23384SNicholas Bellinger 	struct se_dev_entry *deve;
102312d23384SNicholas Bellinger 	ssize_t ret;
102412d23384SNicholas Bellinger 
102529a05deeSNicholas Bellinger 	rcu_read_lock();
102629a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
102729a05deeSNicholas Bellinger 	if (!deve) {
102829a05deeSNicholas Bellinger 		rcu_read_unlock();
102912d23384SNicholas Bellinger 		return -ENODEV;
103012d23384SNicholas Bellinger 	}
103112d23384SNicholas Bellinger 	/* scsiAuthIntrOutCommands */
103229a05deeSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%lu\n",
103329a05deeSNicholas Bellinger 		       atomic_long_read(&deve->total_cmds));
103429a05deeSNicholas Bellinger 	rcu_read_unlock();
103512d23384SNicholas Bellinger 	return ret;
103612d23384SNicholas Bellinger }
103712d23384SNicholas Bellinger 
target_stat_auth_read_mbytes_show(struct config_item * item,char * page)10382eafd729SChristoph Hellwig static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
10392eafd729SChristoph Hellwig 		char *page)
104012d23384SNicholas Bellinger {
10412eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
104212d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
104312d23384SNicholas Bellinger 	struct se_dev_entry *deve;
104412d23384SNicholas Bellinger 	ssize_t ret;
104512d23384SNicholas Bellinger 
104629a05deeSNicholas Bellinger 	rcu_read_lock();
104729a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
104829a05deeSNicholas Bellinger 	if (!deve) {
104929a05deeSNicholas Bellinger 		rcu_read_unlock();
105012d23384SNicholas Bellinger 		return -ENODEV;
105112d23384SNicholas Bellinger 	}
105212d23384SNicholas Bellinger 	/* scsiAuthIntrReadMegaBytes */
105329a05deeSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n",
105429a05deeSNicholas Bellinger 		      (u32)(atomic_long_read(&deve->read_bytes) >> 20));
105529a05deeSNicholas Bellinger 	rcu_read_unlock();
105612d23384SNicholas Bellinger 	return ret;
105712d23384SNicholas Bellinger }
105812d23384SNicholas Bellinger 
target_stat_auth_write_mbytes_show(struct config_item * item,char * page)10592eafd729SChristoph Hellwig static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
10602eafd729SChristoph Hellwig 		char *page)
106112d23384SNicholas Bellinger {
10622eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
106312d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
106412d23384SNicholas Bellinger 	struct se_dev_entry *deve;
106512d23384SNicholas Bellinger 	ssize_t ret;
106612d23384SNicholas Bellinger 
106729a05deeSNicholas Bellinger 	rcu_read_lock();
106829a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
106929a05deeSNicholas Bellinger 	if (!deve) {
107029a05deeSNicholas Bellinger 		rcu_read_unlock();
107112d23384SNicholas Bellinger 		return -ENODEV;
107212d23384SNicholas Bellinger 	}
107312d23384SNicholas Bellinger 	/* scsiAuthIntrWrittenMegaBytes */
107429a05deeSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n",
107529a05deeSNicholas Bellinger 		      (u32)(atomic_long_read(&deve->write_bytes) >> 20));
107629a05deeSNicholas Bellinger 	rcu_read_unlock();
107712d23384SNicholas Bellinger 	return ret;
107812d23384SNicholas Bellinger }
107912d23384SNicholas Bellinger 
target_stat_auth_hs_num_cmds_show(struct config_item * item,char * page)10802eafd729SChristoph Hellwig static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
10812eafd729SChristoph Hellwig 		char *page)
108212d23384SNicholas Bellinger {
10832eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
108412d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
108512d23384SNicholas Bellinger 	struct se_dev_entry *deve;
108612d23384SNicholas Bellinger 	ssize_t ret;
108712d23384SNicholas Bellinger 
108829a05deeSNicholas Bellinger 	rcu_read_lock();
108929a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
109029a05deeSNicholas Bellinger 	if (!deve) {
109129a05deeSNicholas Bellinger 		rcu_read_unlock();
109212d23384SNicholas Bellinger 		return -ENODEV;
109312d23384SNicholas Bellinger 	}
109412d23384SNicholas Bellinger 	/* FIXME: scsiAuthIntrHSOutCommands */
109512d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
109629a05deeSNicholas Bellinger 	rcu_read_unlock();
109712d23384SNicholas Bellinger 	return ret;
109812d23384SNicholas Bellinger }
109912d23384SNicholas Bellinger 
target_stat_auth_creation_time_show(struct config_item * item,char * page)11002eafd729SChristoph Hellwig static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
11012eafd729SChristoph Hellwig 		char *page)
110212d23384SNicholas Bellinger {
11032eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
110412d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
110512d23384SNicholas Bellinger 	struct se_dev_entry *deve;
110612d23384SNicholas Bellinger 	ssize_t ret;
110712d23384SNicholas Bellinger 
110829a05deeSNicholas Bellinger 	rcu_read_lock();
110929a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
111029a05deeSNicholas Bellinger 	if (!deve) {
111129a05deeSNicholas Bellinger 		rcu_read_unlock();
111212d23384SNicholas Bellinger 		return -ENODEV;
111312d23384SNicholas Bellinger 	}
111412d23384SNicholas Bellinger 	/* scsiAuthIntrLastCreation */
111512d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
111612d23384SNicholas Bellinger 				INITIAL_JIFFIES) * 100 / HZ));
111729a05deeSNicholas Bellinger 	rcu_read_unlock();
111812d23384SNicholas Bellinger 	return ret;
111912d23384SNicholas Bellinger }
112012d23384SNicholas Bellinger 
target_stat_auth_row_status_show(struct config_item * item,char * page)11212eafd729SChristoph Hellwig static ssize_t target_stat_auth_row_status_show(struct config_item *item,
11222eafd729SChristoph Hellwig 		char *page)
112312d23384SNicholas Bellinger {
11242eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = auth_to_lacl(item);
112512d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
112612d23384SNicholas Bellinger 	struct se_dev_entry *deve;
112712d23384SNicholas Bellinger 	ssize_t ret;
112812d23384SNicholas Bellinger 
112929a05deeSNicholas Bellinger 	rcu_read_lock();
113029a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
113129a05deeSNicholas Bellinger 	if (!deve) {
113229a05deeSNicholas Bellinger 		rcu_read_unlock();
113312d23384SNicholas Bellinger 		return -ENODEV;
113412d23384SNicholas Bellinger 	}
113512d23384SNicholas Bellinger 	/* FIXME: scsiAuthIntrRowStatus */
113612d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "Ready\n");
113729a05deeSNicholas Bellinger 	rcu_read_unlock();
113812d23384SNicholas Bellinger 	return ret;
113912d23384SNicholas Bellinger }
114012d23384SNicholas Bellinger 
11412eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, inst);
11422eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, dev);
11432eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, port);
11442eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, indx);
11452eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port);
11462eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, intr_name);
11472eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, map_indx);
11482eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, att_count);
11492eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds);
11502eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes);
11512eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes);
11522eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds);
11532eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, creation_time);
11542eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_auth_, row_status);
115512d23384SNicholas Bellinger 
115612d23384SNicholas Bellinger static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
11572eafd729SChristoph Hellwig 	&target_stat_auth_attr_inst,
11582eafd729SChristoph Hellwig 	&target_stat_auth_attr_dev,
11592eafd729SChristoph Hellwig 	&target_stat_auth_attr_port,
11602eafd729SChristoph Hellwig 	&target_stat_auth_attr_indx,
11612eafd729SChristoph Hellwig 	&target_stat_auth_attr_dev_or_port,
11622eafd729SChristoph Hellwig 	&target_stat_auth_attr_intr_name,
11632eafd729SChristoph Hellwig 	&target_stat_auth_attr_map_indx,
11642eafd729SChristoph Hellwig 	&target_stat_auth_attr_att_count,
11652eafd729SChristoph Hellwig 	&target_stat_auth_attr_num_cmds,
11662eafd729SChristoph Hellwig 	&target_stat_auth_attr_read_mbytes,
11672eafd729SChristoph Hellwig 	&target_stat_auth_attr_write_mbytes,
11682eafd729SChristoph Hellwig 	&target_stat_auth_attr_hs_num_cmds,
11692eafd729SChristoph Hellwig 	&target_stat_auth_attr_creation_time,
11702eafd729SChristoph Hellwig 	&target_stat_auth_attr_row_status,
117112d23384SNicholas Bellinger 	NULL,
117212d23384SNicholas Bellinger };
117312d23384SNicholas Bellinger 
1174ece550b5SBhumika Goyal static const struct config_item_type target_stat_scsi_auth_intr_cit = {
117512d23384SNicholas Bellinger 	.ct_attrs		= target_stat_scsi_auth_intr_attrs,
117612d23384SNicholas Bellinger 	.ct_owner		= THIS_MODULE,
117712d23384SNicholas Bellinger };
117812d23384SNicholas Bellinger 
117912d23384SNicholas Bellinger /*
118012d23384SNicholas Bellinger  * SCSI Attached Initiator Port Table
118112d23384SNicholas Bellinger  */
118212d23384SNicholas Bellinger 
iport_to_lacl(struct config_item * item)11832eafd729SChristoph Hellwig static struct se_lun_acl *iport_to_lacl(struct config_item *item)
118412d23384SNicholas Bellinger {
11852eafd729SChristoph Hellwig 	struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
11862eafd729SChristoph Hellwig 			struct se_ml_stat_grps, scsi_att_intr_port_group);
11872eafd729SChristoph Hellwig 	return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
11882eafd729SChristoph Hellwig }
11892eafd729SChristoph Hellwig 
target_stat_iport_inst_show(struct config_item * item,char * page)11902eafd729SChristoph Hellwig static ssize_t target_stat_iport_inst_show(struct config_item *item,
11912eafd729SChristoph Hellwig 		char *page)
11922eafd729SChristoph Hellwig {
11932eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = iport_to_lacl(item);
119412d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
119512d23384SNicholas Bellinger 	struct se_dev_entry *deve;
119612d23384SNicholas Bellinger 	struct se_portal_group *tpg;
119712d23384SNicholas Bellinger 	ssize_t ret;
119812d23384SNicholas Bellinger 
119929a05deeSNicholas Bellinger 	rcu_read_lock();
120029a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
120129a05deeSNicholas Bellinger 	if (!deve) {
120229a05deeSNicholas Bellinger 		rcu_read_unlock();
120312d23384SNicholas Bellinger 		return -ENODEV;
120412d23384SNicholas Bellinger 	}
120512d23384SNicholas Bellinger 	tpg = nacl->se_tpg;
120612d23384SNicholas Bellinger 	/* scsiInstIndex */
120712d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n",
1208e3d6f909SAndy Grover 			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
120929a05deeSNicholas Bellinger 	rcu_read_unlock();
121012d23384SNicholas Bellinger 	return ret;
121112d23384SNicholas Bellinger }
121212d23384SNicholas Bellinger 
target_stat_iport_dev_show(struct config_item * item,char * page)12132eafd729SChristoph Hellwig static ssize_t target_stat_iport_dev_show(struct config_item *item,
12142eafd729SChristoph Hellwig 		char *page)
121512d23384SNicholas Bellinger {
12162eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = iport_to_lacl(item);
121712d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
121812d23384SNicholas Bellinger 	struct se_dev_entry *deve;
121912d23384SNicholas Bellinger 	ssize_t ret;
122012d23384SNicholas Bellinger 
122129a05deeSNicholas Bellinger 	rcu_read_lock();
122229a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
122329a05deeSNicholas Bellinger 	if (!deve) {
122429a05deeSNicholas Bellinger 		rcu_read_unlock();
122512d23384SNicholas Bellinger 		return -ENODEV;
122612d23384SNicholas Bellinger 	}
1227ef4f7e4bSDmitry Bogdanov 
122812d23384SNicholas Bellinger 	/* scsiDeviceIndex */
1229ef4f7e4bSDmitry Bogdanov 	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index);
123029a05deeSNicholas Bellinger 	rcu_read_unlock();
123112d23384SNicholas Bellinger 	return ret;
123212d23384SNicholas Bellinger }
123312d23384SNicholas Bellinger 
target_stat_iport_port_show(struct config_item * item,char * page)12342eafd729SChristoph Hellwig static ssize_t target_stat_iport_port_show(struct config_item *item,
12352eafd729SChristoph Hellwig 		char *page)
123612d23384SNicholas Bellinger {
12372eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = iport_to_lacl(item);
123812d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
123912d23384SNicholas Bellinger 	struct se_dev_entry *deve;
124012d23384SNicholas Bellinger 	struct se_portal_group *tpg;
124112d23384SNicholas Bellinger 	ssize_t ret;
124212d23384SNicholas Bellinger 
124329a05deeSNicholas Bellinger 	rcu_read_lock();
124429a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
124529a05deeSNicholas Bellinger 	if (!deve) {
124629a05deeSNicholas Bellinger 		rcu_read_unlock();
124712d23384SNicholas Bellinger 		return -ENODEV;
124812d23384SNicholas Bellinger 	}
124912d23384SNicholas Bellinger 	tpg = nacl->se_tpg;
125012d23384SNicholas Bellinger 	/* scsiPortIndex */
1251e3d6f909SAndy Grover 	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
125229a05deeSNicholas Bellinger 	rcu_read_unlock();
125312d23384SNicholas Bellinger 	return ret;
125412d23384SNicholas Bellinger }
125512d23384SNicholas Bellinger 
target_stat_iport_indx_show(struct config_item * item,char * page)12562eafd729SChristoph Hellwig static ssize_t target_stat_iport_indx_show(struct config_item *item,
12572eafd729SChristoph Hellwig 		char *page)
125812d23384SNicholas Bellinger {
12592eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = iport_to_lacl(item);
126012d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
126112d23384SNicholas Bellinger 	struct se_session *se_sess;
126212d23384SNicholas Bellinger 	struct se_portal_group *tpg;
126312d23384SNicholas Bellinger 	ssize_t ret;
126412d23384SNicholas Bellinger 
126512d23384SNicholas Bellinger 	spin_lock_irq(&nacl->nacl_sess_lock);
126612d23384SNicholas Bellinger 	se_sess = nacl->nacl_sess;
126712d23384SNicholas Bellinger 	if (!se_sess) {
126812d23384SNicholas Bellinger 		spin_unlock_irq(&nacl->nacl_sess_lock);
126912d23384SNicholas Bellinger 		return -ENODEV;
127012d23384SNicholas Bellinger 	}
127112d23384SNicholas Bellinger 
127212d23384SNicholas Bellinger 	tpg = nacl->se_tpg;
127312d23384SNicholas Bellinger 	/* scsiAttIntrPortIndex */
127412d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n",
1275e3d6f909SAndy Grover 			tpg->se_tpg_tfo->sess_get_index(se_sess));
127612d23384SNicholas Bellinger 	spin_unlock_irq(&nacl->nacl_sess_lock);
127712d23384SNicholas Bellinger 	return ret;
127812d23384SNicholas Bellinger }
127912d23384SNicholas Bellinger 
target_stat_iport_port_auth_indx_show(struct config_item * item,char * page)12802eafd729SChristoph Hellwig static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
12812eafd729SChristoph Hellwig 		char *page)
128212d23384SNicholas Bellinger {
12832eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = iport_to_lacl(item);
128412d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
128512d23384SNicholas Bellinger 	struct se_dev_entry *deve;
128612d23384SNicholas Bellinger 	ssize_t ret;
128712d23384SNicholas Bellinger 
128829a05deeSNicholas Bellinger 	rcu_read_lock();
128929a05deeSNicholas Bellinger 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
129029a05deeSNicholas Bellinger 	if (!deve) {
129129a05deeSNicholas Bellinger 		rcu_read_unlock();
129212d23384SNicholas Bellinger 		return -ENODEV;
129312d23384SNicholas Bellinger 	}
129412d23384SNicholas Bellinger 	/* scsiAttIntrPortAuthIntrIdx */
129512d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
129629a05deeSNicholas Bellinger 	rcu_read_unlock();
129712d23384SNicholas Bellinger 	return ret;
129812d23384SNicholas Bellinger }
129912d23384SNicholas Bellinger 
target_stat_iport_port_ident_show(struct config_item * item,char * page)13002eafd729SChristoph Hellwig static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
13012eafd729SChristoph Hellwig 		char *page)
130212d23384SNicholas Bellinger {
13032eafd729SChristoph Hellwig 	struct se_lun_acl *lacl = iport_to_lacl(item);
130412d23384SNicholas Bellinger 	struct se_node_acl *nacl = lacl->se_lun_nacl;
130512d23384SNicholas Bellinger 	struct se_session *se_sess;
130612d23384SNicholas Bellinger 	struct se_portal_group *tpg;
130712d23384SNicholas Bellinger 	ssize_t ret;
130812d23384SNicholas Bellinger 	unsigned char buf[64];
130912d23384SNicholas Bellinger 
131012d23384SNicholas Bellinger 	spin_lock_irq(&nacl->nacl_sess_lock);
131112d23384SNicholas Bellinger 	se_sess = nacl->nacl_sess;
131212d23384SNicholas Bellinger 	if (!se_sess) {
131312d23384SNicholas Bellinger 		spin_unlock_irq(&nacl->nacl_sess_lock);
131412d23384SNicholas Bellinger 		return -ENODEV;
131512d23384SNicholas Bellinger 	}
131612d23384SNicholas Bellinger 
131712d23384SNicholas Bellinger 	tpg = nacl->se_tpg;
131812d23384SNicholas Bellinger 	/* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
131912d23384SNicholas Bellinger 	memset(buf, 0, 64);
1320e3d6f909SAndy Grover 	if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
13218359cf43SJörn Engel 		tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
132212d23384SNicholas Bellinger 
132312d23384SNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
132412d23384SNicholas Bellinger 	spin_unlock_irq(&nacl->nacl_sess_lock);
132512d23384SNicholas Bellinger 	return ret;
132612d23384SNicholas Bellinger }
132712d23384SNicholas Bellinger 
13282eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_iport_, inst);
13292eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_iport_, dev);
13302eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_iport_, port);
13312eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_iport_, indx);
13322eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx);
13332eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_stat_iport_, port_ident);
133412d23384SNicholas Bellinger 
133512d23384SNicholas Bellinger static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
13362eafd729SChristoph Hellwig 	&target_stat_iport_attr_inst,
13372eafd729SChristoph Hellwig 	&target_stat_iport_attr_dev,
13382eafd729SChristoph Hellwig 	&target_stat_iport_attr_port,
13392eafd729SChristoph Hellwig 	&target_stat_iport_attr_indx,
13402eafd729SChristoph Hellwig 	&target_stat_iport_attr_port_auth_indx,
13412eafd729SChristoph Hellwig 	&target_stat_iport_attr_port_ident,
134212d23384SNicholas Bellinger 	NULL,
134312d23384SNicholas Bellinger };
134412d23384SNicholas Bellinger 
1345ece550b5SBhumika Goyal static const struct config_item_type target_stat_scsi_att_intr_port_cit = {
134612d23384SNicholas Bellinger 	.ct_attrs		= target_stat_scsi_ath_intr_port_attrs,
134712d23384SNicholas Bellinger 	.ct_owner		= THIS_MODULE,
134812d23384SNicholas Bellinger };
134912d23384SNicholas Bellinger 
135012d23384SNicholas Bellinger /*
135112d23384SNicholas Bellinger  * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
135212d23384SNicholas Bellinger  * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
135312d23384SNicholas Bellinger  */
target_stat_setup_mappedlun_default_groups(struct se_lun_acl * lacl)135412d23384SNicholas Bellinger void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
135512d23384SNicholas Bellinger {
1356e3d6f909SAndy Grover 	config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
135712d23384SNicholas Bellinger 			"scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
13581ae1602dSChristoph Hellwig 	configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group,
13591ae1602dSChristoph Hellwig 			&lacl->ml_stat_grps.stat_group);
13601ae1602dSChristoph Hellwig 
1361e3d6f909SAndy Grover 	config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
136212d23384SNicholas Bellinger 			"scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
13631ae1602dSChristoph Hellwig 	configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group,
13641ae1602dSChristoph Hellwig 			&lacl->ml_stat_grps.stat_group);
136512d23384SNicholas Bellinger }
1366