28 #include <linux/module.h>
30 #include <linux/slab.h>
32 #include <linux/kernel.h>
38 #include <linux/netlink.h>
53 static void fc_bsg_goose_queue(
struct fc_rport *);
64 static unsigned int fc_dev_loss_tmo = 60;
68 "Maximum number of seconds that the FC transport should"
69 " insulate the loss of a remote port. Once this value is"
70 " exceeded, the scsi target is removed. Value should be"
71 " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT if"
72 " fast_io_fail_tmo is not set.");
78 #define FC_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
79 struct device_attribute device_attr_##_prefix##_##_name = \
80 __ATTR(_name,_mode,_show,_store)
82 #define fc_enum_name_search(title, table_type, table) \
83 static const char *get_fc_##title##_name(enum table_type table_key) \
88 for (i = 0; i < ARRAY_SIZE(table); i++) { \
89 if (table[i].value == table_key) { \
90 name = table[i].name; \
97 #define fc_enum_name_match(title, table_type, table) \
98 static int get_fc_##title##_match(const char *table_key, \
99 enum table_type *value) \
103 for (i = 0; i < ARRAY_SIZE(table); i++) { \
104 if (strncmp(table_key, table[i].name, \
105 table[i].matchlen) == 0) { \
106 *value = table[i].value; \
118 } fc_port_type_names[] = {
129 #define FC_PORTTYPE_MAX_NAMELEN 50
132 #define get_fc_vport_type_name get_fc_port_type_name
136 static const struct {
155 #define FC_HOST_EVENT_CODE_MAX_NAMELEN 30
176 #define FC_PORTSTATE_MAX_NAMELEN 20
196 #define FC_VPORTSTATE_MAX_NAMELEN 24
199 #define get_fc_vport_last_state_name get_fc_vport_state_name
203 static const struct {
217 #define FC_BINDTYPE_MAX_NAMELEN 30
220 #define fc_bitfield_name_search(title, table) \
222 get_fc_##title##_names(u32 table_key, char *buf) \
228 for (i = 0; i < ARRAY_SIZE(table); i++) { \
229 if (table[i].value & table_key) { \
230 len += sprintf(buf + len, "%s%s", \
231 prefix, table[i].name); \
235 len += sprintf(buf + len, "\n"); \
241 static const struct {
271 show_fc_fc4s (
char *
buf,
u8 *fc4_list)
276 len +=
sprintf(buf + len ,
"0x%02x ", *fc4_list);
277 len +=
sprintf(buf + len,
"\n");
283 static const struct {
286 } fc_port_role_names[] = {
296 #define FC_WELLKNOWN_PORTID_MASK 0xfffff0
297 #define FC_WELLKNOWN_ROLE_MASK 0x00000f
298 #define FC_FPORT_PORTID 0x00000e
299 #define FC_FABCTLR_PORTID 0x00000d
300 #define FC_DIRSRVR_PORTID 0x00000c
301 #define FC_TIMESRVR_PORTID 0x00000b
302 #define FC_MGMTSRVR_PORTID 0x00000a
313 #define FC_STARGET_NUM_ATTRS 3
314 #define FC_RPORT_NUM_ATTRS 10
315 #define FC_VPORT_NUM_ATTRS 9
316 #define FC_HOST_NUM_ATTRS 29
348 #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t)
405 sizeof(fc_host->
model));
429 INIT_LIST_HEAD(&fc_host->
rports);
431 INIT_LIST_HEAD(&fc_host->
vports);
455 fc_bsg_hostadd(shost, fc_host);
464 struct Scsi_Host *shost = dev_to_shost(dev);
467 fc_bsg_remove(fc_host->
rqst_q);
555 skblen -
sizeof(*nlh), 0);
565 event->vendor_id = 0;
566 event->host_no = shost->
host_no;
567 event->event_datalen =
sizeof(
u32);
568 event->event_num = event_number;
579 name = get_fc_host_event_code_name(event_code);
581 "%s: Dropped Event : host %d %s data 0x%08x - err %d\n",
583 (name) ? name :
"<unknown>", event_data, err);
612 goto send_vendor_fail;
621 goto send_vendor_fail;
625 skblen -
sizeof(*nlh), 0);
628 goto send_vendor_fail_skb;
636 event->host_no = shost->
host_no;
638 event->event_num = event_number;
646 send_vendor_fail_skb:
650 "%s: Dropped Event : host %d vendor_unique - err %d\n",
651 __func__, shost->
host_no, err);
658 static __init int fc_transport_init(
void)
669 goto unreg_host_class;
672 goto unreg_vport_class;
675 goto unreg_rport_class;
687 static void __exit fc_transport_exit(
void)
699 #define fc_rport_show_function(field, format_string, sz, cast) \
701 show_fc_rport_##field (struct device *dev, \
702 struct device_attribute *attr, char *buf) \
704 struct fc_rport *rport = transport_class_to_rport(dev); \
705 struct Scsi_Host *shost = rport_to_shost(rport); \
706 struct fc_internal *i = to_fc_internal(shost->transportt); \
707 if ((i->f->get_rport_##field) && \
708 !((rport->port_state == FC_PORTSTATE_BLOCKED) || \
709 (rport->port_state == FC_PORTSTATE_DELETED) || \
710 (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \
711 i->f->get_rport_##field(rport); \
712 return snprintf(buf, sz, format_string, cast rport->field); \
715 #define fc_rport_store_function(field) \
717 store_fc_rport_##field(struct device *dev, \
718 struct device_attribute *attr, \
719 const char *buf, size_t count) \
722 struct fc_rport *rport = transport_class_to_rport(dev); \
723 struct Scsi_Host *shost = rport_to_shost(rport); \
724 struct fc_internal *i = to_fc_internal(shost->transportt); \
726 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \
727 (rport->port_state == FC_PORTSTATE_DELETED) || \
728 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \
730 val = simple_strtoul(buf, &cp, 0); \
731 if (*cp && (*cp != '\n')) \
733 i->f->set_rport_##field(rport, val); \
737 #define fc_rport_rd_attr(field, format_string, sz) \
738 fc_rport_show_function(field, format_string, sz, ) \
739 static FC_DEVICE_ATTR(rport, field, S_IRUGO, \
740 show_fc_rport_##field, NULL)
742 #define fc_rport_rd_attr_cast(field, format_string, sz, cast) \
743 fc_rport_show_function(field, format_string, sz, (cast)) \
744 static FC_DEVICE_ATTR(rport, field, S_IRUGO, \
745 show_fc_rport_##field, NULL)
747 #define fc_rport_rw_attr(field, format_string, sz) \
748 fc_rport_show_function(field, format_string, sz, ) \
749 fc_rport_store_function(field) \
750 static FC_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \
751 show_fc_rport_##field, \
752 store_fc_rport_##field)
755 #define fc_private_rport_show_function(field, format_string, sz, cast) \
757 show_fc_rport_##field (struct device *dev, \
758 struct device_attribute *attr, char *buf) \
760 struct fc_rport *rport = transport_class_to_rport(dev); \
761 return snprintf(buf, sz, format_string, cast rport->field); \
764 #define fc_private_rport_rd_attr(field, format_string, sz) \
765 fc_private_rport_show_function(field, format_string, sz, ) \
766 static FC_DEVICE_ATTR(rport, field, S_IRUGO, \
767 show_fc_rport_##field, NULL)
769 #define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \
770 fc_private_rport_show_function(field, format_string, sz, (cast)) \
771 static FC_DEVICE_ATTR(rport, field, S_IRUGO, \
772 show_fc_rport_##field, NULL)
775 #define fc_private_rport_rd_enum_attr(title, maxlen) \
777 show_fc_rport_##title (struct device *dev, \
778 struct device_attribute *attr, char *buf) \
780 struct fc_rport *rport = transport_class_to_rport(dev); \
782 name = get_fc_##title##_name(rport->title); \
785 return snprintf(buf, maxlen, "%s\n", name); \
787 static FC_DEVICE_ATTR(rport, title, S_IRUGO, \
788 show_fc_rport_##title, NULL)
791 #define SETUP_RPORT_ATTRIBUTE_RD(field) \
792 i->private_rport_attrs[count] = device_attr_rport_##field; \
793 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
794 i->private_rport_attrs[count].store = NULL; \
795 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
796 if (i->f->show_rport_##field) \
799 #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \
800 i->private_rport_attrs[count] = device_attr_rport_##field; \
801 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
802 i->private_rport_attrs[count].store = NULL; \
803 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
806 #define SETUP_RPORT_ATTRIBUTE_RW(field) \
807 i->private_rport_attrs[count] = device_attr_rport_##field; \
808 if (!i->f->set_rport_##field) { \
809 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
810 i->private_rport_attrs[count].store = NULL; \
812 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
813 if (i->f->show_rport_##field) \
816 #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(field) \
818 i->private_rport_attrs[count] = device_attr_rport_##field; \
819 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
831 show_fc_rport_supported_classes (
struct device *dev,
836 return snprintf(buf, 20,
"unspecified\n");
840 show_fc_rport_supported_classes,
NULL);
847 static int fc_str_to_dev_loss(
const char *buf,
unsigned long *
val)
852 if ((*cp && (*cp !=
'\n')) || (*val < 0))
863 static int fc_rport_set_dev_loss_tmo(
struct fc_rport *rport,
887 i->f->set_rport_dev_loss_tmo(rport, val);
900 rc = fc_str_to_dev_loss(buf, &val);
904 rc = fc_rport_set_dev_loss_tmo(rport, val);
910 show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo);
927 (rport->
port_id & FC_WELLKNOWN_PORTID_MASK) ==
928 FC_WELLKNOWN_PORTID_MASK) {
929 switch (rport->
port_id & FC_WELLKNOWN_ROLE_MASK) {
931 return snprintf(buf, 30,
"Fabric Port\n");
933 return snprintf(buf, 30,
"Fabric Controller\n");
935 return snprintf(buf, 30,
"Directory Server\n");
937 return snprintf(buf, 30,
"Time Server\n");
939 return snprintf(buf, 30,
"Management Server\n");
941 return snprintf(buf, 30,
"Unknown Fabric Entity\n");
945 return snprintf(buf, 20,
"unknown\n");
946 return get_fc_port_roles_names(rport->
roles, buf);
950 show_fc_rport_roles,
NULL);
959 show_fc_rport_fast_io_fail_tmo (
struct device *dev,
970 store_fc_rport_fast_io_fail_tmo(
struct device *dev,
982 if (
strncmp(buf,
"off", 3) == 0)
986 if ((*cp && (*cp !=
'\n')) || (val < 0))
1001 show_fc_rport_fast_io_fail_tmo, store_fc_rport_fast_io_fail_tmo);
1014 #define fc_starget_show_function(field, format_string, sz, cast) \
1016 show_fc_starget_##field (struct device *dev, \
1017 struct device_attribute *attr, char *buf) \
1019 struct scsi_target *starget = transport_class_to_starget(dev); \
1020 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
1021 struct fc_internal *i = to_fc_internal(shost->transportt); \
1022 struct fc_rport *rport = starget_to_rport(starget); \
1024 fc_starget_##field(starget) = rport->field; \
1025 else if (i->f->get_starget_##field) \
1026 i->f->get_starget_##field(starget); \
1027 return snprintf(buf, sz, format_string, \
1028 cast fc_starget_##field(starget)); \
1031 #define fc_starget_rd_attr(field, format_string, sz) \
1032 fc_starget_show_function(field, format_string, sz, ) \
1033 static FC_DEVICE_ATTR(starget, field, S_IRUGO, \
1034 show_fc_starget_##field, NULL)
1036 #define fc_starget_rd_attr_cast(field, format_string, sz, cast) \
1037 fc_starget_show_function(field, format_string, sz, (cast)) \
1038 static FC_DEVICE_ATTR(starget, field, S_IRUGO, \
1039 show_fc_starget_##field, NULL)
1041 #define SETUP_STARGET_ATTRIBUTE_RD(field) \
1042 i->private_starget_attrs[count] = device_attr_starget_##field; \
1043 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
1044 i->private_starget_attrs[count].store = NULL; \
1045 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
1046 if (i->f->show_starget_##field) \
1049 #define SETUP_STARGET_ATTRIBUTE_RW(field) \
1050 i->private_starget_attrs[count] = device_attr_starget_##field; \
1051 if (!i->f->set_starget_##field) { \
1052 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
1053 i->private_starget_attrs[count].store = NULL; \
1055 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
1056 if (i->f->show_starget_##field) \
1069 #define fc_vport_show_function(field, format_string, sz, cast) \
1071 show_fc_vport_##field (struct device *dev, \
1072 struct device_attribute *attr, char *buf) \
1074 struct fc_vport *vport = transport_class_to_vport(dev); \
1075 struct Scsi_Host *shost = vport_to_shost(vport); \
1076 struct fc_internal *i = to_fc_internal(shost->transportt); \
1077 if ((i->f->get_vport_##field) && \
1078 !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))) \
1079 i->f->get_vport_##field(vport); \
1080 return snprintf(buf, sz, format_string, cast vport->field); \
1083 #define fc_vport_store_function(field) \
1085 store_fc_vport_##field(struct device *dev, \
1086 struct device_attribute *attr, \
1087 const char *buf, size_t count) \
1090 struct fc_vport *vport = transport_class_to_vport(dev); \
1091 struct Scsi_Host *shost = vport_to_shost(vport); \
1092 struct fc_internal *i = to_fc_internal(shost->transportt); \
1094 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \
1096 val = simple_strtoul(buf, &cp, 0); \
1097 if (*cp && (*cp != '\n')) \
1099 i->f->set_vport_##field(vport, val); \
1103 #define fc_vport_store_str_function(field, slen) \
1105 store_fc_vport_##field(struct device *dev, \
1106 struct device_attribute *attr, \
1107 const char *buf, size_t count) \
1109 struct fc_vport *vport = transport_class_to_vport(dev); \
1110 struct Scsi_Host *shost = vport_to_shost(vport); \
1111 struct fc_internal *i = to_fc_internal(shost->transportt); \
1112 unsigned int cnt=count; \
1115 if (buf[cnt-1] == '\n') \
1117 if (cnt > ((slen) - 1)) \
1119 memcpy(vport->field, buf, cnt); \
1120 i->f->set_vport_##field(vport); \
1124 #define fc_vport_rd_attr(field, format_string, sz) \
1125 fc_vport_show_function(field, format_string, sz, ) \
1126 static FC_DEVICE_ATTR(vport, field, S_IRUGO, \
1127 show_fc_vport_##field, NULL)
1129 #define fc_vport_rd_attr_cast(field, format_string, sz, cast) \
1130 fc_vport_show_function(field, format_string, sz, (cast)) \
1131 static FC_DEVICE_ATTR(vport, field, S_IRUGO, \
1132 show_fc_vport_##field, NULL)
1134 #define fc_vport_rw_attr(field, format_string, sz) \
1135 fc_vport_show_function(field, format_string, sz, ) \
1136 fc_vport_store_function(field) \
1137 static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \
1138 show_fc_vport_##field, \
1139 store_fc_vport_##field)
1141 #define fc_private_vport_show_function(field, format_string, sz, cast) \
1143 show_fc_vport_##field (struct device *dev, \
1144 struct device_attribute *attr, char *buf) \
1146 struct fc_vport *vport = transport_class_to_vport(dev); \
1147 return snprintf(buf, sz, format_string, cast vport->field); \
1150 #define fc_private_vport_store_u32_function(field) \
1152 store_fc_vport_##field(struct device *dev, \
1153 struct device_attribute *attr, \
1154 const char *buf, size_t count) \
1157 struct fc_vport *vport = transport_class_to_vport(dev); \
1159 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \
1161 val = simple_strtoul(buf, &cp, 0); \
1162 if (*cp && (*cp != '\n')) \
1164 vport->field = val; \
1169 #define fc_private_vport_rd_attr(field, format_string, sz) \
1170 fc_private_vport_show_function(field, format_string, sz, ) \
1171 static FC_DEVICE_ATTR(vport, field, S_IRUGO, \
1172 show_fc_vport_##field, NULL)
1174 #define fc_private_vport_rd_attr_cast(field, format_string, sz, cast) \
1175 fc_private_vport_show_function(field, format_string, sz, (cast)) \
1176 static FC_DEVICE_ATTR(vport, field, S_IRUGO, \
1177 show_fc_vport_##field, NULL)
1179 #define fc_private_vport_rw_u32_attr(field, format_string, sz) \
1180 fc_private_vport_show_function(field, format_string, sz, ) \
1181 fc_private_vport_store_u32_function(field) \
1182 static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \
1183 show_fc_vport_##field, \
1184 store_fc_vport_##field)
1187 #define fc_private_vport_rd_enum_attr(title, maxlen) \
1189 show_fc_vport_##title (struct device *dev, \
1190 struct device_attribute *attr, \
1193 struct fc_vport *vport = transport_class_to_vport(dev); \
1195 name = get_fc_##title##_name(vport->title); \
1198 return snprintf(buf, maxlen, "%s\n", name); \
1200 static FC_DEVICE_ATTR(vport, title, S_IRUGO, \
1201 show_fc_vport_##title, NULL)
1204 #define SETUP_VPORT_ATTRIBUTE_RD(field) \
1205 i->private_vport_attrs[count] = device_attr_vport_##field; \
1206 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1207 i->private_vport_attrs[count].store = NULL; \
1208 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1209 if (i->f->get_##field) \
1213 #define SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(field) \
1214 i->private_vport_attrs[count] = device_attr_vport_##field; \
1215 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1216 i->private_vport_attrs[count].store = NULL; \
1217 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1220 #define SETUP_VPORT_ATTRIBUTE_WR(field) \
1221 i->private_vport_attrs[count] = device_attr_vport_##field; \
1222 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1227 #define SETUP_VPORT_ATTRIBUTE_RW(field) \
1228 i->private_vport_attrs[count] = device_attr_vport_##field; \
1229 if (!i->f->set_vport_##field) { \
1230 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1231 i->private_vport_attrs[count].store = NULL; \
1233 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1237 #define SETUP_PRIVATE_VPORT_ATTRIBUTE_RW(field) \
1239 i->private_vport_attrs[count] = device_attr_vport_##field; \
1240 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1265 return snprintf(buf, 20,
"unknown\n");
1266 return get_fc_port_roles_names(vport->
roles, buf);
1276 show_fc_vport_symbolic_name, store_fc_vport_symbolic_name);
1280 const char *buf,
size_t count)
1284 unsigned long flags;
1288 spin_unlock_irqrestore(shost->
host_lock, flags);
1292 spin_unlock_irqrestore(shost->
host_lock, flags);
1298 NULL, store_fc_vport_delete);
1321 }
else if (*buf ==
'1') {
1327 stat = i->f->vport_disable(vport, ((*buf ==
'0') ?
false :
true));
1328 return stat ? stat :
count;
1331 NULL, store_fc_vport_disable);
1338 #define fc_host_show_function(field, format_string, sz, cast) \
1340 show_fc_host_##field (struct device *dev, \
1341 struct device_attribute *attr, char *buf) \
1343 struct Scsi_Host *shost = transport_class_to_shost(dev); \
1344 struct fc_internal *i = to_fc_internal(shost->transportt); \
1345 if (i->f->get_host_##field) \
1346 i->f->get_host_##field(shost); \
1347 return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
1350 #define fc_host_store_function(field) \
1352 store_fc_host_##field(struct device *dev, \
1353 struct device_attribute *attr, \
1354 const char *buf, size_t count) \
1357 struct Scsi_Host *shost = transport_class_to_shost(dev); \
1358 struct fc_internal *i = to_fc_internal(shost->transportt); \
1361 val = simple_strtoul(buf, &cp, 0); \
1362 if (*cp && (*cp != '\n')) \
1364 i->f->set_host_##field(shost, val); \
1368 #define fc_host_store_str_function(field, slen) \
1370 store_fc_host_##field(struct device *dev, \
1371 struct device_attribute *attr, \
1372 const char *buf, size_t count) \
1374 struct Scsi_Host *shost = transport_class_to_shost(dev); \
1375 struct fc_internal *i = to_fc_internal(shost->transportt); \
1376 unsigned int cnt=count; \
1379 if (buf[cnt-1] == '\n') \
1381 if (cnt > ((slen) - 1)) \
1383 memcpy(fc_host_##field(shost), buf, cnt); \
1384 i->f->set_host_##field(shost); \
1388 #define fc_host_rd_attr(field, format_string, sz) \
1389 fc_host_show_function(field, format_string, sz, ) \
1390 static FC_DEVICE_ATTR(host, field, S_IRUGO, \
1391 show_fc_host_##field, NULL)
1393 #define fc_host_rd_attr_cast(field, format_string, sz, cast) \
1394 fc_host_show_function(field, format_string, sz, (cast)) \
1395 static FC_DEVICE_ATTR(host, field, S_IRUGO, \
1396 show_fc_host_##field, NULL)
1398 #define fc_host_rw_attr(field, format_string, sz) \
1399 fc_host_show_function(field, format_string, sz, ) \
1400 fc_host_store_function(field) \
1401 static FC_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \
1402 show_fc_host_##field, \
1403 store_fc_host_##field)
1405 #define fc_host_rd_enum_attr(title, maxlen) \
1407 show_fc_host_##title (struct device *dev, \
1408 struct device_attribute *attr, char *buf) \
1410 struct Scsi_Host *shost = transport_class_to_shost(dev); \
1411 struct fc_internal *i = to_fc_internal(shost->transportt); \
1413 if (i->f->get_host_##title) \
1414 i->f->get_host_##title(shost); \
1415 name = get_fc_##title##_name(fc_host_##title(shost)); \
1418 return snprintf(buf, maxlen, "%s\n", name); \
1420 static FC_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
1422 #define SETUP_HOST_ATTRIBUTE_RD(field) \
1423 i->private_host_attrs[count] = device_attr_host_##field; \
1424 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1425 i->private_host_attrs[count].store = NULL; \
1426 i->host_attrs[count] = &i->private_host_attrs[count]; \
1427 if (i->f->show_host_##field) \
1430 #define SETUP_HOST_ATTRIBUTE_RD_NS(field) \
1431 i->private_host_attrs[count] = device_attr_host_##field; \
1432 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1433 i->private_host_attrs[count].store = NULL; \
1434 i->host_attrs[count] = &i->private_host_attrs[count]; \
1437 #define SETUP_HOST_ATTRIBUTE_RW(field) \
1438 i->private_host_attrs[count] = device_attr_host_##field; \
1439 if (!i->f->set_host_##field) { \
1440 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1441 i->private_host_attrs[count].store = NULL; \
1443 i->host_attrs[count] = &i->private_host_attrs[count]; \
1444 if (i->f->show_host_##field) \
1448 #define fc_private_host_show_function(field, format_string, sz, cast) \
1450 show_fc_host_##field (struct device *dev, \
1451 struct device_attribute *attr, char *buf) \
1453 struct Scsi_Host *shost = transport_class_to_shost(dev); \
1454 return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
1457 #define fc_private_host_rd_attr(field, format_string, sz) \
1458 fc_private_host_show_function(field, format_string, sz, ) \
1459 static FC_DEVICE_ATTR(host, field, S_IRUGO, \
1460 show_fc_host_##field, NULL)
1462 #define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \
1463 fc_private_host_show_function(field, format_string, sz, (cast)) \
1464 static FC_DEVICE_ATTR(host, field, S_IRUGO, \
1465 show_fc_host_##field, NULL)
1467 #define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \
1468 i->private_host_attrs[count] = device_attr_host_##field; \
1469 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1470 i->private_host_attrs[count].store = NULL; \
1471 i->host_attrs[count] = &i->private_host_attrs[count]; \
1474 #define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \
1476 i->private_host_attrs[count] = device_attr_host_##field; \
1477 i->host_attrs[count] = &i->private_host_attrs[count]; \
1485 show_fc_host_supported_classes (
struct device *dev,
1491 return snprintf(buf, 20,
"unspecified\n");
1496 show_fc_host_supported_classes,
NULL);
1499 show_fc_host_supported_fc4s (
struct device *dev,
1506 show_fc_host_supported_fc4s,
NULL);
1509 show_fc_host_supported_speeds (
struct device *dev,
1515 return snprintf(buf, 20,
"unknown\n");
1520 show_fc_host_supported_speeds,
NULL);
1526 unsigned long long);
1542 show_fc_host_active_fc4s (
struct device *dev,
1548 if (i->f->get_host_active_fc4s)
1549 i->f->get_host_active_fc4s(shost);
1554 show_fc_host_active_fc4s,
NULL);
1557 show_fc_host_speed (
struct device *dev,
1563 if (i->f->get_host_speed)
1564 i->f->get_host_speed(shost);
1567 return snprintf(buf, 20,
"unknown\n");
1572 show_fc_host_speed,
NULL);
1585 show_fc_host_system_hostname, store_fc_host_system_hostname);
1591 show_fc_private_host_tgtid_bind_type(
struct device *dev,
1600 return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN,
"%s\n", name);
1603 #define get_list_head_entry(pos, head, member) \
1604 pos = list_entry((head)->next, typeof(*pos), member)
1607 store_fc_private_host_tgtid_bind_type(
struct device *dev,
1612 enum fc_tgtid_binding_type
val;
1613 unsigned long flags;
1615 if (get_fc_tgtid_bind_type_match(buf, &val))
1628 spin_unlock_irqrestore(shost->
host_lock, flags);
1636 show_fc_private_host_tgtid_bind_type,
1637 store_fc_private_host_tgtid_bind_type);
1640 store_fc_private_host_issue_lip(
struct device *dev,
1648 if (i->f->issue_fc_host_lip) {
1649 ret = i->f->issue_fc_host_lip(shost);
1650 return ret ? ret:
count;
1657 store_fc_private_host_issue_lip);
1660 store_fc_private_host_dev_loss_tmo(
struct device *dev,
1662 const char *buf,
size_t count)
1670 rc = fc_str_to_dev_loss(buf, &val);
1677 fc_rport_set_dev_loss_tmo(rport, val);
1678 spin_unlock_irqrestore(shost->host_lock, flags);
1684 show_fc_host_dev_loss_tmo,
1685 store_fc_private_host_dev_loss_tmo);
1703 offset %
sizeof(
u64) != 0)
1706 if (i->f->get_fc_host_stats) {
1707 stats = (i->f->get_fc_host_stats)(shost);
1709 ret =
snprintf(buf, 20,
"0x%llx\n",
1710 (
unsigned long long)*(
u64 *)(((
u8 *) stats) + offset));
1717 #define fc_host_statistic(name) \
1718 static ssize_t show_fcstat_##name(struct device *cd, \
1719 struct device_attribute *attr, \
1722 return fc_stat_show(cd, buf, \
1723 offsetof(struct fc_host_statistics, name)); \
1725 static FC_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
1759 const char *buf,
size_t count)
1765 if (i->f->reset_fc_host_stats) {
1766 i->f->reset_fc_host_stats(shost);
1773 fc_reset_statistics);
1775 static struct attribute *fc_statistics_attrs[] = {
1776 &device_attr_host_seconds_since_last_reset.attr,
1777 &device_attr_host_tx_frames.attr,
1778 &device_attr_host_tx_words.attr,
1779 &device_attr_host_rx_frames.attr,
1780 &device_attr_host_rx_words.attr,
1781 &device_attr_host_lip_count.attr,
1782 &device_attr_host_nos_count.attr,
1783 &device_attr_host_error_frames.attr,
1784 &device_attr_host_dumped_frames.attr,
1785 &device_attr_host_link_failure_count.attr,
1786 &device_attr_host_loss_of_sync_count.attr,
1787 &device_attr_host_loss_of_signal_count.attr,
1788 &device_attr_host_prim_seq_protocol_err_count.attr,
1789 &device_attr_host_invalid_tx_word_count.attr,
1790 &device_attr_host_invalid_crc_count.attr,
1791 &device_attr_host_fcp_input_requests.attr,
1792 &device_attr_host_fcp_output_requests.attr,
1793 &device_attr_host_fcp_control_requests.attr,
1794 &device_attr_host_fcp_input_megabytes.attr,
1795 &device_attr_host_fcp_output_megabytes.attr,
1796 &device_attr_host_fcp_packet_alloc_failures.attr,
1797 &device_attr_host_fcp_packet_aborts.attr,
1798 &device_attr_host_fcp_frame_alloc_failures.attr,
1799 &device_attr_host_fc_no_free_exch.attr,
1800 &device_attr_host_fc_no_free_exch_xid.attr,
1801 &device_attr_host_fc_xid_not_found.attr,
1802 &device_attr_host_fc_xid_busy.attr,
1803 &device_attr_host_fc_seq_not_found.attr,
1804 &device_attr_host_fc_non_bls_resp.attr,
1805 &device_attr_host_reset_statistics.attr,
1810 .name =
"statistics",
1811 .attrs = fc_statistics_attrs,
1818 fc_parse_wwn(
const char *
ns,
u64 *nm)
1823 memset(wwn, 0,
sizeof(wwn));
1826 for (i=0, j=0; i < 16; i++) {
1831 j = (j << 4) | value;
1835 wwn[i/2] = j & 0xff;
1840 *nm = wwn_to_u64(wwn);
1854 const char *buf,
size_t count)
1865 if (buf[cnt-1] ==
'\n')
1869 if ((cnt != (16+1+16)) || (buf[16] !=
':'))
1872 stat = fc_parse_wwn(&buf[0], &
vid.port_name);
1876 stat = fc_parse_wwn(&buf[17], &
vid.node_name);
1883 vid.disable =
false;
1886 stat = fc_vport_setup(shost, 0, &shost->shost_gendev, &
vid, &vport);
1887 return stat ? stat :
count;
1890 store_fc_host_vport_create);
1901 const char *buf,
size_t count)
1907 unsigned long flags;
1908 unsigned int cnt=
count;
1912 if (buf[cnt-1] ==
'\n')
1916 if ((cnt != (16+1+16)) || (buf[16] !=
':'))
1919 stat = fc_parse_wwn(&buf[0], &wwpn);
1923 stat = fc_parse_wwn(&buf[17], &wwnn);
1940 spin_unlock_irqrestore(shost->
host_lock, flags);
1946 return stat ? stat :
count;
1949 store_fc_host_vport_delete);
1956 struct fc_internal *
i;
1961 shost = dev_to_shost(dev);
1963 != &fc_host_class.class)
1968 return &i->t.host_attrs.ac ==
cont;
1975 struct fc_internal *
i;
1980 shost = dev_to_shost(dev->
parent);
1982 != &fc_host_class.class)
1987 return &i->t.target_attrs.ac ==
cont;
1990 static void fc_rport_dev_release(
struct device *dev)
1999 return dev->
release == fc_rport_dev_release;
2007 struct fc_internal *
i;
2012 shost = dev_to_shost(dev->
parent);
2014 != &fc_host_class.class)
2019 return &i->rport_attr_cont.ac ==
cont;
2023 static void fc_vport_dev_release(
struct device *dev)
2032 return dev->
release == fc_vport_dev_release;
2041 struct fc_internal *
i;
2049 != &fc_host_class.class)
2053 return &i->vport_attr_cont.ac ==
cont;
2079 static enum blk_eh_timer_return
2085 return BLK_EH_RESET_TIMER;
2087 return BLK_EH_NOT_HANDLED;
2099 unsigned long flags;
2110 if ((channel == rport->
channel) &&
2112 spin_unlock_irqrestore(shost->
host_lock, flags);
2118 spin_unlock_irqrestore(shost->
host_lock, flags);
2154 for ( ; chlo < chhi; chlo++)
2155 for ( ; tgtlo < tgthi; tgtlo++)
2156 fc_user_scan_tgt(shost, chlo, tgtlo, lun);
2165 return i->f->tsk_mgmt_response(shost, nexus, tm_id, result);
2168 static int fc_it_nexus_response(
struct Scsi_Host *shost,
u64 nexus,
int result)
2171 return i->f->it_nexus_response(shost, nexus, result);
2178 struct fc_internal *i = kzalloc(
sizeof(
struct fc_internal),
2184 i->t.target_attrs.ac.attrs = &i->starget_attrs[0];
2185 i->t.target_attrs.ac.class = &fc_transport_class.class;
2186 i->t.target_attrs.ac.match = fc_target_match;
2188 transport_container_register(&i->t.target_attrs);
2190 i->t.host_attrs.ac.attrs = &i->host_attrs[0];
2191 i->t.host_attrs.ac.class = &fc_host_class.class;
2192 i->t.host_attrs.ac.match = fc_host_match;
2195 i->t.host_attrs.statistics = &fc_statistics_group;
2196 transport_container_register(&i->t.host_attrs);
2198 i->rport_attr_cont.ac.attrs = &i->rport_attrs[0];
2199 i->rport_attr_cont.ac.class = &fc_rport_class.class;
2200 i->rport_attr_cont.ac.match = fc_rport_match;
2201 transport_container_register(&i->rport_attr_cont);
2203 i->vport_attr_cont.ac.attrs = &i->vport_attrs[0];
2204 i->vport_attr_cont.ac.class = &fc_vport_class.class;
2205 i->vport_attr_cont.ac.match = fc_vport_match;
2206 transport_container_register(&i->vport_attr_cont);
2211 i->t.create_work_queue = 1;
2213 i->t.eh_timed_out = fc_timed_out;
2215 i->t.user_scan = fc_user_scan;
2218 i->t.tsk_mgmt_response = fc_tsk_mgmt_response;
2219 i->t.it_nexus_response = fc_it_nexus_response;
2326 transport_container_unregister(&i->t.target_attrs);
2327 transport_container_unregister(&i->t.host_attrs);
2328 transport_container_unregister(&i->rport_attr_cont);
2329 transport_container_unregister(&i->vport_attr_cont);
2350 "ERROR: FC host '%s' attempted to queue work, "
2351 "when no workqueue created.\n", shost->
hostt->name);
2369 "ERROR: FC host '%s' attempted to flush work, "
2370 "when no workqueue created.\n", shost->
hostt->name);
2389 unsigned long delay)
2393 "ERROR: FC host '%s' attempted to queue work, "
2394 "when no workqueue created.\n", shost->
hostt->name);
2408 fc_flush_devloss(
struct Scsi_Host *shost)
2412 "ERROR: FC host '%s' attempted to flush work, "
2413 "when no workqueue created.\n", shost->
hostt->name);
2444 unsigned long flags;
2467 spin_unlock_irqrestore(shost->
host_lock, flags);
2474 work_q = fc_host->
work_q;
2488 static void fc_terminate_rport_io(
struct fc_rport *rport)
2494 if (i->f->terminate_rport_io)
2495 i->f->terminate_rport_io(rport);
2515 fc_terminate_rport_io(rport);
2532 unsigned long flags;
2533 int do_callback = 0;
2535 fc_terminate_rport_io(rport);
2551 spin_unlock_irqrestore(shost->
host_lock, flags);
2553 fc_flush_devloss(shost);
2555 fc_flush_devloss(shost);
2559 spin_unlock_irqrestore(shost->
host_lock, flags);
2574 (i->f->dev_loss_tmo_callbk)) {
2578 spin_unlock_irqrestore(shost->
host_lock, flags);
2581 i->f->dev_loss_tmo_callbk(rport);
2583 fc_bsg_remove(rport->
rqst_q);
2607 fc_rport_create(
struct Scsi_Host *shost,
int channel,
2614 unsigned long flags;
2618 size = (
sizeof(
struct fc_rport) + fci->
f->dd_fcrport_size);
2633 if (fci->f->dd_fcrport_size)
2654 spin_unlock_irqrestore(shost->
host_lock, flags);
2659 dev->
release = fc_rport_dev_release;
2672 fc_bsg_rportadd(shost, rport);
2688 spin_unlock_irqrestore(shost->
host_lock, flags);
2739 unsigned long flags;
2743 fc_flush_work(shost);
2755 (rport->
channel == channel)) {
2784 spin_unlock_irqrestore(shost->
host_lock, flags);
2786 if (fci->f->dd_fcrport_size)
2788 fci->f->dd_fcrport_size);
2817 fc_flush_devloss(shost);
2819 fc_flush_devloss(shost);
2827 spin_unlock_irqrestore(shost->
host_lock, flags);
2838 spin_unlock_irqrestore(shost->
host_lock,
2842 fc_bsg_goose_queue(rport);
2859 if (rport->
channel != channel)
2895 if (fci->f->dd_fcrport_size)
2897 fci->f->dd_fcrport_size);
2898 spin_unlock_irqrestore(shost->
host_lock, flags);
2907 spin_unlock_irqrestore(shost->
host_lock, flags);
2913 spin_unlock_irqrestore(shost->
host_lock, flags);
2916 rport = fc_rport_create(shost, channel, ids);
2978 unsigned long flags;
2991 spin_unlock_irqrestore(shost->
host_lock, flags);
3012 spin_unlock_irqrestore(shost->
host_lock, flags);
3016 fc_tgt_it_nexus_destroy(shost, (
unsigned long)rport);
3021 if ((rport->fast_io_fail_tmo != -1) &&
3022 (rport->fast_io_fail_tmo < timeout))
3023 fc_queue_devloss_work(shost, &rport->fail_io_work,
3024 rport->fast_io_fail_tmo *
HZ);
3027 fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout *
HZ);
3056 unsigned long flags;
3065 }
else if (!(rport->
roles & FC_PORT_ROLE_FCP_TARGET))
3068 ret = fc_tgt_it_nexus_create(shost, (
unsigned long)rport,
3077 spin_unlock_irqrestore(shost->
host_lock, flags);
3093 fc_flush_devloss(shost);
3095 fc_flush_devloss(shost);
3101 spin_unlock_irqrestore(shost->
host_lock, flags);
3104 fc_flush_work(shost);
3111 spin_unlock_irqrestore(shost->
host_lock, flags);
3124 fc_timeout_deleted_rport(
struct work_struct *work)
3131 unsigned long flags;
3132 int do_callback = 0;
3147 "blocked FC remote port time out: no longer"
3148 " a FCP target, removing starget\n");
3149 spin_unlock_irqrestore(shost->
host_lock, flags);
3157 spin_unlock_irqrestore(shost->
host_lock, flags);
3159 "blocked FC remote port time out: leaving"
3170 "blocked FC remote port time out: removing"
3174 spin_unlock_irqrestore(shost->
host_lock, flags);
3179 "blocked FC remote port time out: removing target and "
3180 "saving binding\n");
3204 spin_unlock_irqrestore(shost->
host_lock, flags);
3205 fc_terminate_rport_io(rport);
3240 spin_unlock_irqrestore(shost->
host_lock, flags);
3248 if (do_callback && i->f->dev_loss_tmo_callbk)
3249 i->f->dev_loss_tmo_callbk(rport);
3261 fc_timeout_fail_rport_io(
struct work_struct *work)
3270 fc_terminate_rport_io(rport);
3284 unsigned long flags;
3288 !(i->f->disable_target_scan)) {
3295 spin_unlock_irqrestore(shost->
host_lock, flags);
3316 unsigned long flags;
3321 spin_unlock_irqrestore(shost->
host_lock, flags);
3325 spin_unlock_irqrestore(shost->
host_lock, flags);
3350 fc_vport_setup(
struct Scsi_Host *shost,
int channel,
struct device *pdev,
3357 unsigned long flags;
3363 if ( ! fci->f->vport_create)
3366 size = (
sizeof(
struct fc_vport) + fci->
f->dd_fcvport_size);
3379 if (fci->f->dd_fcvport_size)
3389 spin_unlock_irqrestore(shost->
host_lock, flags);
3398 spin_unlock_irqrestore(shost->
host_lock, flags);
3403 dev->
release = fc_vport_dev_release;
3416 error = fci->f->vport_create(vport, ids->
disable);
3419 goto delete_vport_all;
3426 if (pdev != &shost->shost_gendev) {
3428 &dev->
kobj, dev_name(dev));
3431 "%s: Cannot create vport symlinks for "
3433 __func__, dev_name(dev), error);
3437 spin_unlock_irqrestore(shost->
host_lock, flags);
3440 "%s created via shost%d channel %d\n", dev_name(dev),
3456 spin_unlock_irqrestore(shost->
host_lock, flags);
3480 stat = fc_vport_setup(shost, channel, &shost->shost_gendev,
3482 return stat ?
NULL : vport;
3503 unsigned long flags;
3506 if (i->f->vport_delete)
3507 stat = i->f->vport_delete(vport);
3519 spin_unlock_irqrestore(shost->
host_lock, flags);
3524 if (dev->
parent != &shost->shost_gendev)
3555 "%s: %s could not be deleted created via "
3556 "shost%d channel %d - error %d\n", __func__,
3557 dev_name(&vport->
dev), vport->
shost->host_no,
3574 unsigned long flags;
3578 spin_unlock_irqrestore(&job->
job_lock, flags);
3581 spin_unlock_irqrestore(&job->
job_lock, flags);
3602 err = job->
req->errors = job->
reply->result;
3614 WARN_ON(job->
reply->reply_payload_rcv_len > rsp->resid_len);
3617 rsp->resid_len -=
min(job->
reply->reply_payload_rcv_len,
3627 static void fc_bsg_softirq_done(
struct request *
rq)
3630 unsigned long flags;
3635 spin_unlock_irqrestore(&job->
job_lock, flags);
3638 fc_destroy_bsgjob(job);
3645 static enum blk_eh_timer_return
3646 fc_bsg_job_timeout(
struct request *req)
3648 struct fc_bsg_job *job = (
void *) req->special;
3651 unsigned long flags;
3652 int err = 0,
done = 0;
3655 return BLK_EH_RESET_TIMER;
3662 spin_unlock_irqrestore(&job->
job_lock, flags);
3664 if (!
done && i->f->bsg_timeout) {
3666 err = i->f->bsg_timeout(job);
3669 return BLK_EH_RESET_TIMER;
3672 "abort failed with status %d\n", err);
3677 return BLK_EH_NOT_HANDLED;
3679 return BLK_EH_HANDLED;
3685 size_t sz = (
sizeof(
struct scatterlist) * req->nr_phys_segments);
3687 BUG_ON(!req->nr_phys_segments);
3711 struct request *rsp = req->next_rq;
3717 job = kzalloc(
sizeof(
struct fc_bsg_job) + i->f->dd_bsg_size,
3735 if (i->f->dd_bsg_size)
3736 job->
dd_data = (
void *)&job[1];
3740 job->
reply = req->sense;
3746 goto failjob_rls_job;
3748 if (rsp && rsp->bio) {
3751 goto failjob_rls_rqst_payload;
3757 job->
dev = &shost->shost_gendev;
3765 failjob_rls_rqst_payload:
3795 switch (job->
request->msgcode) {
3826 if ((shost->
hostt->vendor_id == 0
L) ||
3827 (job->
request->rqst_data.h_vendor.vendor_id !=
3828 shost->
hostt->vendor_id)) {
3845 ret = i->f->bsg_request(job);
3852 job->
reply->reply_payload_rcv_len = 0;
3855 fc_bsg_jobdone(job);
3865 fc_bsg_goose_queue(
struct fc_rport *rport)
3894 switch (job->
request->msgcode) {
3906 goto fail_rport_msg;
3911 goto fail_rport_msg;
3917 goto fail_rport_msg;
3920 ret = i->f->bsg_request(job);
3927 job->
reply->reply_payload_rcv_len = 0;
3930 fc_bsg_jobdone(job);
3963 req->errors = -
ENXIO;
3964 spin_unlock_irq(q->queue_lock);
3966 spin_lock_irq(q->queue_lock);
3970 spin_unlock_irq(q->queue_lock);
3972 ret = fc_req_to_bsgjob(shost, rport, req);
3976 spin_lock_irq(q->queue_lock);
3985 job->
reply->reply_payload_rcv_len = 0;
3988 fc_bsg_jobdone(job);
3989 spin_lock_irq(q->queue_lock);
3995 ret = fc_bsg_rport_dispatch(q, shost, rport, job);
3997 ret = fc_bsg_host_dispatch(q, shost, job);
4005 spin_lock_irq(q->queue_lock);
4008 spin_unlock_irq(q->queue_lock);
4010 spin_lock_irq(q->queue_lock);
4023 fc_bsg_request_handler(q, shost,
NULL, &shost->shost_gendev);
4034 struct fc_rport *rport = q->queuedata;
4037 fc_bsg_request_handler(q, shost, rport, &rport->
dev);
4049 struct device *dev = &shost->shost_gendev;
4057 if (!i->f->bsg_request)
4060 snprintf(bsg_name,
sizeof(bsg_name),
4066 "initialize - no request queue\n",
4071 q->queuedata =
shost;
4072 queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
4080 "initialize - register queue\n",
4106 if (!i->f->bsg_request)
4112 "initialize - no request queue\n",
4117 q->queuedata =
rport;
4118 queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q);
4126 "initialize - register queue\n",