30 #include <linux/kernel.h>
31 #include <linux/module.h>
34 #include <linux/string.h>
35 #include <linux/utsname.h>
40 #include <scsi/scsi.h>
52 #ifndef INITIAL_JIFFIES
53 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
57 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
59 #define SCSI_LU_INDEX 1
67 #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
68 static struct target_stat_scsi_dev_attribute \
69 target_stat_scsi_dev_##_name = \
70 __CONFIGFS_EATTR(_name, _mode, \
71 target_stat_scsi_dev_show_attr_##_name, \
72 target_stat_scsi_dev_store_attr_##_name);
74 #define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
75 static struct target_stat_scsi_dev_attribute \
76 target_stat_scsi_dev_##_name = \
77 __CONFIGFS_EATTR_RO(_name, \
78 target_stat_scsi_dev_show_attr_##_name);
80 static ssize_t target_stat_scsi_dev_show_attr_inst(
95 static ssize_t target_stat_scsi_dev_show_attr_indx(
109 static ssize_t target_stat_scsi_dev_show_attr_role(
123 static ssize_t target_stat_scsi_dev_show_attr_ports(
140 &target_stat_scsi_dev_inst.attr,
141 &target_stat_scsi_dev_indx.attr,
142 &target_stat_scsi_dev_role.attr,
143 &target_stat_scsi_dev_ports.attr,
148 .show_attribute = target_stat_scsi_dev_attr_show,
149 .store_attribute = target_stat_scsi_dev_attr_store,
153 .ct_item_ops = &target_stat_scsi_dev_attrib_ops,
154 .ct_attrs = target_stat_scsi_dev_attrs,
163 #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
164 static struct target_stat_scsi_tgt_dev_attribute \
165 target_stat_scsi_tgt_dev_##_name = \
166 __CONFIGFS_EATTR(_name, _mode, \
167 target_stat_scsi_tgt_dev_show_attr_##_name, \
168 target_stat_scsi_tgt_dev_store_attr_##_name);
170 #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
171 static struct target_stat_scsi_tgt_dev_attribute \
172 target_stat_scsi_tgt_dev_##_name = \
173 __CONFIGFS_EATTR_RO(_name, \
174 target_stat_scsi_tgt_dev_show_attr_##_name);
176 static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
191 static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
205 static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
219 static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
232 strcpy(status,
"activated");
235 strcpy(status,
"deactivated");
238 strcpy(status,
"shutdown");
242 strcpy(status,
"offline");
253 static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
259 int non_accessible_lus;
266 non_accessible_lus = 0;
273 non_accessible_lus = 1;
281 static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
299 &target_stat_scsi_tgt_dev_inst.attr,
300 &target_stat_scsi_tgt_dev_indx.attr,
301 &target_stat_scsi_tgt_dev_num_lus.attr,
302 &target_stat_scsi_tgt_dev_status.attr,
303 &target_stat_scsi_tgt_dev_non_access_lus.attr,
304 &target_stat_scsi_tgt_dev_resets.attr,
309 .show_attribute = target_stat_scsi_tgt_dev_attr_show,
310 .store_attribute = target_stat_scsi_tgt_dev_attr_store,
314 .ct_item_ops = &target_stat_scsi_tgt_dev_attrib_ops,
315 .ct_attrs = target_stat_scsi_tgt_dev_attrs,
324 #define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \
325 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
326 __CONFIGFS_EATTR(_name, _mode, \
327 target_stat_scsi_lu_show_attr_##_name, \
328 target_stat_scsi_lu_store_attr_##_name);
330 #define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
331 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
332 __CONFIGFS_EATTR_RO(_name, \
333 target_stat_scsi_lu_show_attr_##_name);
335 static ssize_t target_stat_scsi_lu_show_attr_inst(
350 static ssize_t target_stat_scsi_lu_show_attr_dev(
364 static ssize_t target_stat_scsi_lu_show_attr_indx(
378 static ssize_t target_stat_scsi_lu_show_attr_lun(
392 static ssize_t target_stat_scsi_lu_show_attr_lu_name(
404 dev->
se_sub_dev->t10_wwn.unit_serial :
"None");
408 static ssize_t target_stat_scsi_lu_show_attr_vend(
421 for (i = 0; i <
sizeof(dev->
se_sub_dev->t10_wwn.vendor); i++)
429 static ssize_t target_stat_scsi_lu_show_attr_prod(
442 for (i = 0; i <
sizeof(dev->
se_sub_dev->t10_wwn.vendor); i++)
450 static ssize_t target_stat_scsi_lu_show_attr_rev(
463 for (i = 0; i <
sizeof(dev->
se_sub_dev->t10_wwn.revision); i++)
471 static ssize_t target_stat_scsi_lu_show_attr_dev_type(
487 static ssize_t target_stat_scsi_lu_show_attr_status(
500 "available" :
"notavailable");
504 static ssize_t target_stat_scsi_lu_show_attr_state_bit(
519 static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
535 static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
550 static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
565 static ssize_t target_stat_scsi_lu_show_attr_resets(
580 static ssize_t target_stat_scsi_lu_show_attr_full_stat(
595 static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
610 static ssize_t target_stat_scsi_lu_show_attr_creation_time(
629 &target_stat_scsi_lu_inst.attr,
630 &target_stat_scsi_lu_dev.attr,
631 &target_stat_scsi_lu_indx.attr,
632 &target_stat_scsi_lu_lun.attr,
633 &target_stat_scsi_lu_lu_name.attr,
634 &target_stat_scsi_lu_vend.attr,
635 &target_stat_scsi_lu_prod.attr,
636 &target_stat_scsi_lu_rev.attr,
637 &target_stat_scsi_lu_dev_type.attr,
638 &target_stat_scsi_lu_status.attr,
639 &target_stat_scsi_lu_state_bit.attr,
640 &target_stat_scsi_lu_num_cmds.attr,
641 &target_stat_scsi_lu_read_mbytes.attr,
642 &target_stat_scsi_lu_write_mbytes.attr,
643 &target_stat_scsi_lu_resets.attr,
644 &target_stat_scsi_lu_full_stat.attr,
645 &target_stat_scsi_lu_hs_num_cmds.attr,
646 &target_stat_scsi_lu_creation_time.attr,
651 .show_attribute = target_stat_scsi_lu_attr_show,
652 .store_attribute = target_stat_scsi_lu_attr_store,
656 .ct_item_ops = &target_stat_scsi_lu_attrib_ops,
657 .ct_attrs = target_stat_scsi_lu_attrs,
670 "scsi_dev", &target_stat_scsi_dev_cit);
672 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
674 "scsi_lu", &target_stat_scsi_lu_cit);
687 #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
688 static struct target_stat_scsi_port_attribute \
689 target_stat_scsi_port_##_name = \
690 __CONFIGFS_EATTR(_name, _mode, \
691 target_stat_scsi_port_show_attr_##_name, \
692 target_stat_scsi_port_store_attr_##_name);
694 #define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
695 static struct target_stat_scsi_port_attribute \
696 target_stat_scsi_port_##_name = \
697 __CONFIGFS_EATTR_RO(_name, \
698 target_stat_scsi_port_show_attr_##_name);
700 static ssize_t target_stat_scsi_port_show_attr_inst(
722 static ssize_t target_stat_scsi_port_show_attr_dev(
742 static ssize_t target_stat_scsi_port_show_attr_indx(
761 static ssize_t target_stat_scsi_port_show_attr_role(
784 static ssize_t target_stat_scsi_port_show_attr_busy_count(
807 &target_stat_scsi_port_inst.attr,
808 &target_stat_scsi_port_dev.attr,
809 &target_stat_scsi_port_indx.attr,
810 &target_stat_scsi_port_role.attr,
811 &target_stat_scsi_port_busy_count.attr,
816 .show_attribute = target_stat_scsi_port_attr_show,
817 .store_attribute = target_stat_scsi_port_attr_store,
821 .ct_item_ops = &target_stat_scsi_port_attrib_ops,
822 .ct_attrs = target_stat_scsi_port_attrs,
830 #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
831 static struct target_stat_scsi_tgt_port_attribute \
832 target_stat_scsi_tgt_port_##_name = \
833 __CONFIGFS_EATTR(_name, _mode, \
834 target_stat_scsi_tgt_port_show_attr_##_name, \
835 target_stat_scsi_tgt_port_store_attr_##_name);
837 #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
838 static struct target_stat_scsi_tgt_port_attribute \
839 target_stat_scsi_tgt_port_##_name = \
840 __CONFIGFS_EATTR_RO(_name, \
841 target_stat_scsi_tgt_port_show_attr_##_name);
843 static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
865 static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
885 static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
904 static ssize_t target_stat_scsi_tgt_port_show_attr_name(
927 static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
951 static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
971 static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
992 static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
1013 static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
1035 scsi_tgt_port_group);
1038 &target_stat_scsi_tgt_port_inst.attr,
1039 &target_stat_scsi_tgt_port_dev.attr,
1040 &target_stat_scsi_tgt_port_indx.attr,
1041 &target_stat_scsi_tgt_port_name.attr,
1042 &target_stat_scsi_tgt_port_port_index.attr,
1043 &target_stat_scsi_tgt_port_in_cmds.attr,
1044 &target_stat_scsi_tgt_port_write_mbytes.attr,
1045 &target_stat_scsi_tgt_port_read_mbytes.attr,
1046 &target_stat_scsi_tgt_port_hs_in_cmds.attr,
1051 .show_attribute = target_stat_scsi_tgt_port_attr_show,
1052 .store_attribute = target_stat_scsi_tgt_port_attr_store,
1056 .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops,
1057 .ct_attrs = target_stat_scsi_tgt_port_attrs,
1066 #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
1067 static struct target_stat_scsi_transport_attribute \
1068 target_stat_scsi_transport_##_name = \
1069 __CONFIGFS_EATTR(_name, _mode, \
1070 target_stat_scsi_transport_show_attr_##_name, \
1071 target_stat_scsi_transport_store_attr_##_name);
1073 #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
1074 static struct target_stat_scsi_transport_attribute \
1075 target_stat_scsi_transport_##_name = \
1076 __CONFIGFS_EATTR_RO(_name, \
1077 target_stat_scsi_transport_show_attr_##_name);
1079 static ssize_t target_stat_scsi_transport_show_attr_inst(
1102 static ssize_t target_stat_scsi_transport_show_attr_device(
1125 static ssize_t target_stat_scsi_transport_show_attr_indx(
1147 static ssize_t target_stat_scsi_transport_show_attr_dev_name(
1176 scsi_transport_group);
1179 &target_stat_scsi_transport_inst.attr,
1180 &target_stat_scsi_transport_device.attr,
1181 &target_stat_scsi_transport_indx.attr,
1182 &target_stat_scsi_transport_dev_name.attr,
1187 .show_attribute = target_stat_scsi_transport_attr_show,
1188 .store_attribute = target_stat_scsi_transport_attr_store,
1192 .ct_item_ops = &target_stat_scsi_transport_attrib_ops,
1193 .ct_attrs = target_stat_scsi_transport_attrs,
1206 "scsi_port", &target_stat_scsi_port_cit);
1208 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
1210 "scsi_transport", &target_stat_scsi_transport_cit);
1223 #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
1224 static struct target_stat_scsi_auth_intr_attribute \
1225 target_stat_scsi_auth_intr_##_name = \
1226 __CONFIGFS_EATTR(_name, _mode, \
1227 target_stat_scsi_auth_intr_show_attr_##_name, \
1228 target_stat_scsi_auth_intr_store_attr_##_name);
1230 #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
1231 static struct target_stat_scsi_auth_intr_attribute \
1232 target_stat_scsi_auth_intr_##_name = \
1233 __CONFIGFS_EATTR_RO(_name, \
1234 target_stat_scsi_auth_intr_show_attr_##_name);
1236 static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1261 static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1285 static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1309 static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1331 static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1353 static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1375 static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1397 static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1419 static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1441 static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1463 static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1485 static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1507 static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1530 static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
1553 scsi_auth_intr_group);
1556 &target_stat_scsi_auth_intr_inst.attr,
1557 &target_stat_scsi_auth_intr_dev.attr,
1558 &target_stat_scsi_auth_intr_port.attr,
1559 &target_stat_scsi_auth_intr_indx.attr,
1560 &target_stat_scsi_auth_intr_dev_or_port.attr,
1561 &target_stat_scsi_auth_intr_intr_name.attr,
1562 &target_stat_scsi_auth_intr_map_indx.attr,
1563 &target_stat_scsi_auth_intr_att_count.attr,
1564 &target_stat_scsi_auth_intr_num_cmds.attr,
1565 &target_stat_scsi_auth_intr_read_mbytes.attr,
1566 &target_stat_scsi_auth_intr_write_mbytes.attr,
1567 &target_stat_scsi_auth_intr_hs_num_cmds.attr,
1568 &target_stat_scsi_auth_intr_creation_time.attr,
1569 &target_stat_scsi_auth_intr_row_status.attr,
1574 .show_attribute = target_stat_scsi_auth_intr_attr_show,
1575 .store_attribute = target_stat_scsi_auth_intr_attr_store,
1579 .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops,
1580 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1589 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
1590 static struct target_stat_scsi_att_intr_port_attribute \
1591 target_stat_scsi_att_intr_port_##_name = \
1592 __CONFIGFS_EATTR(_name, _mode, \
1593 target_stat_scsi_att_intr_port_show_attr_##_name, \
1594 target_stat_scsi_att_intr_port_store_attr_##_name);
1596 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
1597 static struct target_stat_scsi_att_intr_port_attribute \
1598 target_stat_scsi_att_intr_port_##_name = \
1599 __CONFIGFS_EATTR_RO(_name, \
1600 target_stat_scsi_att_intr_port_show_attr_##_name);
1602 static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1627 static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1651 static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1675 static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1701 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1723 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1732 unsigned char buf[64];
1745 tpg->
se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
1754 scsi_att_intr_port_group);
1757 &target_stat_scsi_att_intr_port_inst.attr,
1758 &target_stat_scsi_att_intr_port_dev.attr,
1759 &target_stat_scsi_att_intr_port_port.attr,
1760 &target_stat_scsi_att_intr_port_indx.attr,
1761 &target_stat_scsi_att_intr_port_port_auth_indx.attr,
1762 &target_stat_scsi_att_intr_port_port_ident.attr,
1767 .show_attribute = target_stat_scsi_att_intr_port_attr_show,
1768 .store_attribute = target_stat_scsi_att_intr_port_attr_store,
1772 .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops,
1773 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1786 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1788 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);