Lines Matching +full:attr +full:- +full:cnt +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (C) 2004-2007 James Smart, Emulex Corporation
16 #include <linux/bsg-lib.h>
74 char *name = NULL; \
78 name = table[i].name; \
82 return name; \
92 if (strncmp(table_key, table[i].name, \
102 /* Convert fc_port_type values to ascii string name */
105 char *name; member
110 { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" },
113 { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection)" },
123 /* Convert fc_host_event_code values to ascii string name */
126 char *name; member
148 /* Convert fc_port_state values to ascii string name */
151 char *name; member
172 /* Convert fc_vport_state values to ascii string name */
175 char *name; member
195 /* Convert fc_tgtid_binding_type values to ascii string name */
198 char *name; member
202 { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
203 { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
224 prefix, table[i].name); \
233 /* Convert FC_COS bit values to ascii string name */
236 char *name; member
247 /* Convert FC_PORTSPEED bit values to ascii string name */
250 char *name; member
284 /* Convert FC_PORT_ROLE bit values to ascii string name */
287 char *name; member
331 * An array of null-terminated pointers to the attribute
332 * structures - used for mid-layer interaction.
365 * remote port interface. As such, initialize to known non-values. in fc_target_setup()
368 fc_starget_node_name(starget) = rport->node_name; in fc_target_setup()
369 fc_starget_port_name(starget) = rport->port_name; in fc_target_setup()
370 fc_starget_port_id(starget) = rport->port_id; in fc_target_setup()
372 fc_starget_node_name(starget) = -1; in fc_target_setup()
373 fc_starget_port_name(starget) = -1; in fc_target_setup()
374 fc_starget_port_id(starget) = -1; in fc_target_setup()
397 fc_host->node_name = -1; in fc_host_setup()
398 fc_host->port_name = -1; in fc_host_setup()
399 fc_host->permanent_port_name = -1; in fc_host_setup()
400 fc_host->supported_classes = FC_COS_UNSPECIFIED; in fc_host_setup()
401 memset(fc_host->supported_fc4s, 0, in fc_host_setup()
402 sizeof(fc_host->supported_fc4s)); in fc_host_setup()
403 fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN; in fc_host_setup()
404 fc_host->maxframe_size = -1; in fc_host_setup()
405 fc_host->max_npiv_vports = 0; in fc_host_setup()
406 memset(fc_host->serial_number, 0, in fc_host_setup()
407 sizeof(fc_host->serial_number)); in fc_host_setup()
408 memset(fc_host->manufacturer, 0, in fc_host_setup()
409 sizeof(fc_host->manufacturer)); in fc_host_setup()
410 memset(fc_host->model, 0, in fc_host_setup()
411 sizeof(fc_host->model)); in fc_host_setup()
412 memset(fc_host->model_description, 0, in fc_host_setup()
413 sizeof(fc_host->model_description)); in fc_host_setup()
414 memset(fc_host->hardware_version, 0, in fc_host_setup()
415 sizeof(fc_host->hardware_version)); in fc_host_setup()
416 memset(fc_host->driver_version, 0, in fc_host_setup()
417 sizeof(fc_host->driver_version)); in fc_host_setup()
418 memset(fc_host->firmware_version, 0, in fc_host_setup()
419 sizeof(fc_host->firmware_version)); in fc_host_setup()
420 memset(fc_host->optionrom_version, 0, in fc_host_setup()
421 sizeof(fc_host->optionrom_version)); in fc_host_setup()
423 fc_host->port_id = -1; in fc_host_setup()
424 fc_host->port_type = FC_PORTTYPE_UNKNOWN; in fc_host_setup()
425 fc_host->port_state = FC_PORTSTATE_UNKNOWN; in fc_host_setup()
426 memset(fc_host->active_fc4s, 0, in fc_host_setup()
427 sizeof(fc_host->active_fc4s)); in fc_host_setup()
428 fc_host->speed = FC_PORTSPEED_UNKNOWN; in fc_host_setup()
429 fc_host->fabric_name = -1; in fc_host_setup()
430 memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name)); in fc_host_setup()
431 memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname)); in fc_host_setup()
432 memset(&fc_host->fpin_stats, 0, sizeof(fc_host->fpin_stats)); in fc_host_setup()
434 fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN; in fc_host_setup()
436 INIT_LIST_HEAD(&fc_host->rports); in fc_host_setup()
437 INIT_LIST_HEAD(&fc_host->rport_bindings); in fc_host_setup()
438 INIT_LIST_HEAD(&fc_host->vports); in fc_host_setup()
439 fc_host->next_rport_number = 0; in fc_host_setup()
440 fc_host->next_target_id = 0; in fc_host_setup()
441 fc_host->next_vport_number = 0; in fc_host_setup()
442 fc_host->npiv_vports_inuse = 0; in fc_host_setup()
444 fc_host->work_q = alloc_workqueue("fc_wq_%d", 0, 0, shost->host_no); in fc_host_setup()
445 if (!fc_host->work_q) in fc_host_setup()
446 return -ENOMEM; in fc_host_setup()
448 fc_host->dev_loss_tmo = fc_dev_loss_tmo; in fc_host_setup()
449 fc_host->devloss_work_q = alloc_workqueue("fc_dl_%d", 0, 0, in fc_host_setup()
450 shost->host_no); in fc_host_setup()
451 if (!fc_host->devloss_work_q) { in fc_host_setup()
452 destroy_workqueue(fc_host->work_q); in fc_host_setup()
453 fc_host->work_q = NULL; in fc_host_setup()
454 return -ENOMEM; in fc_host_setup()
458 /* ignore any bsg add error - we just can't do sgio */ in fc_host_setup()
469 fc_bsg_remove(fc_host->rqst_q); in fc_host_remove()
506 * fc_get_event_number - Obtain the next sequential FC event number
521 * fc_host_post_fc_event - routine to do the work of posting an event
541 const char *name; in fc_host_post_fc_event() local
549 err = -ENOENT; in fc_host_post_fc_event()
553 len = FC_NL_MSGALIGN(sizeof(*event) - sizeof(event->event_data) + data_len); in fc_host_post_fc_event()
557 err = -ENOBUFS; in fc_host_post_fc_event()
563 err = -ENOBUFS; in fc_host_post_fc_event()
568 INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, in fc_host_post_fc_event()
570 event->seconds = ktime_get_real_seconds(); in fc_host_post_fc_event()
571 event->vendor_id = vendor_id; in fc_host_post_fc_event()
572 event->host_no = shost->host_no; in fc_host_post_fc_event()
573 event->event_datalen = data_len; /* bytes */ in fc_host_post_fc_event()
574 event->event_num = event_number; in fc_host_post_fc_event()
575 event->event_code = event_code; in fc_host_post_fc_event()
577 memcpy(event->event_data_flex, data_buf, data_len); in fc_host_post_fc_event()
578 padding = len - offsetof(typeof(*event), event_data_flex) - data_len; in fc_host_post_fc_event()
579 memset(event->event_data_flex + data_len, 0, padding); in fc_host_post_fc_event()
588 name = get_fc_host_event_code_name(event_code); in fc_host_post_fc_event()
590 "%s: Dropped Event : host %d %s data 0x%08x - err %d\n", in fc_host_post_fc_event()
591 __func__, shost->host_no, in fc_host_post_fc_event()
592 (name) ? name : "<unknown>", in fc_host_post_fc_event()
599 * fc_host_post_event - called to post an even on an fc_host.
619 * fc_host_post_vendor_event - called to post a vendor unique event
640 * fc_find_rport_by_wwpn - find the fc_rport pointer for a given wwpn
653 spin_lock_irqsave(shost->host_lock, flags); in fc_find_rport_by_wwpn()
656 if (rport->port_state != FC_PORTSTATE_ONLINE) in fc_find_rport_by_wwpn()
659 if (rport->port_name == wwpn) { in fc_find_rport_by_wwpn()
660 spin_unlock_irqrestore(shost->host_lock, flags); in fc_find_rport_by_wwpn()
665 spin_unlock_irqrestore(shost->host_lock, flags); in fc_find_rport_by_wwpn()
674 stats->li++; in fc_li_stats_update()
677 stats->li_failure_unknown++; in fc_li_stats_update()
680 stats->li_link_failure_count++; in fc_li_stats_update()
683 stats->li_loss_of_sync_count++; in fc_li_stats_update()
686 stats->li_loss_of_signals_count++; in fc_li_stats_update()
689 stats->li_prim_seq_err_count++; in fc_li_stats_update()
692 stats->li_invalid_tx_word_count++; in fc_li_stats_update()
695 stats->li_invalid_crc_count++; in fc_li_stats_update()
698 stats->li_device_specific++; in fc_li_stats_update()
706 stats->dn++; in fc_delivery_stats_update()
709 stats->dn_unknown++; in fc_delivery_stats_update()
712 stats->dn_timeout++; in fc_delivery_stats_update()
715 stats->dn_unable_to_route++; in fc_delivery_stats_update()
718 stats->dn_device_specific++; in fc_delivery_stats_update()
726 stats->cn++; in fc_cn_stats_update()
729 stats->cn_clear++; in fc_cn_stats_update()
732 stats->cn_lost_credit++; in fc_cn_stats_update()
735 stats->cn_credit_stall++; in fc_cn_stats_update()
738 stats->cn_oversubscription++; in fc_cn_stats_update()
741 stats->cn_device_specific++; in fc_cn_stats_update()
746 * fc_fpin_li_stats_update - routine to update Link Integrity
760 u16 event_type = be16_to_cpu(li_desc->event_type); in fc_fpin_li_stats_update()
764 be64_to_cpu(li_desc->attached_wwpn)); in fc_fpin_li_stats_update()
766 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_li_stats_update()
767 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_li_stats_update()
769 fc_li_stats_update(event_type, &attach_rport->fpin_stats); in fc_fpin_li_stats_update()
772 if (be32_to_cpu(li_desc->pname_count) > 0) { in fc_fpin_li_stats_update()
774 i < be32_to_cpu(li_desc->pname_count); in fc_fpin_li_stats_update()
776 wwpn = be64_to_cpu(li_desc->pname_list[i]); in fc_fpin_li_stats_update()
779 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_li_stats_update()
780 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_li_stats_update()
784 &rport->fpin_stats); in fc_fpin_li_stats_update()
789 if (fc_host->port_name == be64_to_cpu(li_desc->attached_wwpn)) in fc_fpin_li_stats_update()
790 fc_li_stats_update(event_type, &fc_host->fpin_stats); in fc_fpin_li_stats_update()
794 * fc_fpin_delivery_stats_update - routine to update Delivery Notification
808 u32 reason_code = be32_to_cpu(dn_desc->deli_reason_code); in fc_fpin_delivery_stats_update()
811 be64_to_cpu(dn_desc->attached_wwpn)); in fc_fpin_delivery_stats_update()
813 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_delivery_stats_update()
814 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_delivery_stats_update()
817 &attach_rport->fpin_stats); in fc_fpin_delivery_stats_update()
820 if (fc_host->port_name == be64_to_cpu(dn_desc->attached_wwpn)) in fc_fpin_delivery_stats_update()
821 fc_delivery_stats_update(reason_code, &fc_host->fpin_stats); in fc_fpin_delivery_stats_update()
825 * fc_fpin_peer_congn_stats_update - routine to update Peer Congestion
840 u16 event_type = be16_to_cpu(pc_desc->event_type); in fc_fpin_peer_congn_stats_update()
844 be64_to_cpu(pc_desc->attached_wwpn)); in fc_fpin_peer_congn_stats_update()
846 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_peer_congn_stats_update()
847 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_peer_congn_stats_update()
849 fc_cn_stats_update(event_type, &attach_rport->fpin_stats); in fc_fpin_peer_congn_stats_update()
852 if (be32_to_cpu(pc_desc->pname_count) > 0) { in fc_fpin_peer_congn_stats_update()
854 i < be32_to_cpu(pc_desc->pname_count); in fc_fpin_peer_congn_stats_update()
856 wwpn = be64_to_cpu(pc_desc->pname_list[i]); in fc_fpin_peer_congn_stats_update()
859 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_peer_congn_stats_update()
860 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_peer_congn_stats_update()
864 &rport->fpin_stats); in fc_fpin_peer_congn_stats_update()
871 * fc_fpin_congn_stats_update - routine to update Congestion
884 fc_cn_stats_update(be16_to_cpu(congn->event_type), in fc_fpin_congn_stats_update()
885 &fc_host->fpin_stats); in fc_fpin_congn_stats_update()
889 * fc_host_fpin_rcv - routine to process a received FPIN.
909 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0]; in fc_host_fpin_rcv()
910 bytes_remain = fpin_len - offsetof(struct fc_els_fpin, fpin_desc); in fc_host_fpin_rcv()
911 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len)); in fc_host_fpin_rcv()
915 dtag = be32_to_cpu(tlv->desc_tag); in fc_host_fpin_rcv()
930 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); in fc_host_fpin_rcv()
984 struct device_attribute *attr, char *buf) \
988 struct fc_internal *i = to_fc_internal(shost->transportt); \
989 if ((i->f->get_rport_##field) && \
990 !((rport->port_state == FC_PORTSTATE_BLOCKED) || \
991 (rport->port_state == FC_PORTSTATE_DELETED) || \
992 (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \
993 i->f->get_rport_##field(rport); \
994 return snprintf(buf, sz, format_string, cast rport->field); \
1000 struct device_attribute *attr, \
1006 struct fc_internal *i = to_fc_internal(shost->transportt); \
1008 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \
1009 (rport->port_state == FC_PORTSTATE_DELETED) || \
1010 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \
1011 return -EBUSY; \
1014 return -EINVAL; \
1015 i->f->set_rport_##field(rport, val); \
1040 struct device_attribute *attr, char *buf) \
1043 return snprintf(buf, sz, format_string, cast rport->field); \
1060 struct device_attribute *attr, char *buf) \
1063 const char *name; \
1064 name = get_fc_##title##_name(rport->title); \
1065 if (!name) \
1066 return -EINVAL; \
1067 return snprintf(buf, maxlen, "%s\n", name); \
1074 i->private_rport_attrs[count] = device_attr_rport_##field; \
1075 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
1076 i->private_rport_attrs[count].store = NULL; \
1077 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
1078 if (i->f->show_rport_##field) \
1082 i->private_rport_attrs[count] = device_attr_rport_##field; \
1083 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
1084 i->private_rport_attrs[count].store = NULL; \
1085 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
1089 i->private_rport_attrs[count] = device_attr_rport_##field; \
1090 if (!i->f->set_rport_##field) { \
1091 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
1092 i->private_rport_attrs[count].store = NULL; \
1094 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
1095 if (i->f->show_rport_##field) \
1100 i->private_rport_attrs[count] = device_attr_rport_##field; \
1101 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
1114 struct device_attribute *attr, char *buf) in show_fc_rport_supported_classes() argument
1117 if (rport->supported_classes == FC_COS_UNSPECIFIED) in show_fc_rport_supported_classes()
1119 return get_fc_cos_names(rport->supported_classes, buf); in show_fc_rport_supported_classes()
1135 return -EINVAL; in fc_str_to_dev_loss()
1140 return -EINVAL; in fc_str_to_dev_loss()
1149 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_rport_set_dev_loss_tmo()
1151 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || in fc_rport_set_dev_loss_tmo()
1152 (rport->port_state == FC_PORTSTATE_DELETED) || in fc_rport_set_dev_loss_tmo()
1153 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) in fc_rport_set_dev_loss_tmo()
1154 return -EBUSY; in fc_rport_set_dev_loss_tmo()
1159 return -EINVAL; in fc_rport_set_dev_loss_tmo()
1165 if (rport->fast_io_fail_tmo == -1 && in fc_rport_set_dev_loss_tmo()
1167 return -EINVAL; in fc_rport_set_dev_loss_tmo()
1169 i->f->set_rport_dev_loss_tmo(rport, val); in fc_rport_set_dev_loss_tmo()
1175 store_fc_rport_dev_loss_tmo(struct device *dev, struct device_attribute *attr, in store_fc_rport_dev_loss_tmo() argument
1202 show_fc_rport_roles (struct device *dev, struct device_attribute *attr, in show_fc_rport_roles() argument
1208 if ((rport->port_id != -1) && in show_fc_rport_roles()
1209 (rport->port_id & FC_WELLKNOWN_PORTID_MASK) == in show_fc_rport_roles()
1211 switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) { in show_fc_rport_roles()
1226 if (rport->roles == FC_PORT_ROLE_UNKNOWN) in show_fc_rport_roles()
1228 return get_fc_port_roles_names(rport->roles, buf); in show_fc_rport_roles()
1235 struct device_attribute *attr, in fc_rport_set_marginal_state() argument
1244 return -EINVAL; in fc_rport_set_marginal_state()
1249 * Allow only Online->Marginal in fc_rport_set_marginal_state()
1251 if (rport->port_state == FC_PORTSTATE_ONLINE) in fc_rport_set_marginal_state()
1252 rport->port_state = port_state; in fc_rport_set_marginal_state()
1253 else if (port_state != rport->port_state) in fc_rport_set_marginal_state()
1254 return -EINVAL; in fc_rport_set_marginal_state()
1259 * Allow only Marginal->Online in fc_rport_set_marginal_state()
1261 if (rport->port_state == FC_PORTSTATE_MARGINAL) in fc_rport_set_marginal_state()
1262 rport->port_state = port_state; in fc_rport_set_marginal_state()
1263 else if (port_state != rport->port_state) in fc_rport_set_marginal_state()
1264 return -EINVAL; in fc_rport_set_marginal_state()
1266 return -EINVAL; in fc_rport_set_marginal_state()
1272 struct device_attribute *attr, char *buf) in show_fc_rport_port_state() argument
1274 const char *name; in show_fc_rport_port_state() local
1277 name = get_fc_port_state_name(rport->port_state); in show_fc_rport_port_state()
1278 if (!name) in show_fc_rport_port_state()
1279 return -EINVAL; in show_fc_rport_port_state()
1281 return snprintf(buf, 20, "%s\n", name); in show_fc_rport_port_state()
1294 struct device_attribute *attr, char *buf) in show_fc_rport_fast_io_fail_tmo() argument
1298 if (rport->fast_io_fail_tmo == -1) in show_fc_rport_fast_io_fail_tmo()
1300 return snprintf(buf, 20, "%d\n", rport->fast_io_fail_tmo); in show_fc_rport_fast_io_fail_tmo()
1305 struct device_attribute *attr, const char *buf, in store_fc_rport_fast_io_fail_tmo() argument
1312 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || in store_fc_rport_fast_io_fail_tmo()
1313 (rport->port_state == FC_PORTSTATE_DELETED) || in store_fc_rport_fast_io_fail_tmo()
1314 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) in store_fc_rport_fast_io_fail_tmo()
1315 return -EBUSY; in store_fc_rport_fast_io_fail_tmo()
1317 rport->fast_io_fail_tmo = -1; in store_fc_rport_fast_io_fail_tmo()
1321 return -EINVAL; in store_fc_rport_fast_io_fail_tmo()
1326 if ((val >= rport->dev_loss_tmo) || in store_fc_rport_fast_io_fail_tmo()
1328 return -EINVAL; in store_fc_rport_fast_io_fail_tmo()
1330 rport->fast_io_fail_tmo = val; in store_fc_rport_fast_io_fail_tmo()
1337 #define fc_rport_fpin_statistic(name) \ argument
1338 static ssize_t fc_rport_fpinstat_##name(struct device *cd, \
1339 struct device_attribute *attr, \
1344 return snprintf(buf, 20, "0x%llx\n", rport->fpin_stats.name); \
1346 static FC_DEVICE_ATTR(rport, fpin_##name, 0444, fc_rport_fpinstat_##name, NULL)
1370 &device_attr_rport_fpin_dn.attr,
1371 &device_attr_rport_fpin_dn_unknown.attr,
1372 &device_attr_rport_fpin_dn_timeout.attr,
1373 &device_attr_rport_fpin_dn_unable_to_route.attr,
1374 &device_attr_rport_fpin_dn_device_specific.attr,
1375 &device_attr_rport_fpin_li.attr,
1376 &device_attr_rport_fpin_li_failure_unknown.attr,
1377 &device_attr_rport_fpin_li_link_failure_count.attr,
1378 &device_attr_rport_fpin_li_loss_of_sync_count.attr,
1379 &device_attr_rport_fpin_li_loss_of_signals_count.attr,
1380 &device_attr_rport_fpin_li_prim_seq_err_count.attr,
1381 &device_attr_rport_fpin_li_invalid_tx_word_count.attr,
1382 &device_attr_rport_fpin_li_invalid_crc_count.attr,
1383 &device_attr_rport_fpin_li_device_specific.attr,
1384 &device_attr_rport_fpin_cn.attr,
1385 &device_attr_rport_fpin_cn_clear.attr,
1386 &device_attr_rport_fpin_cn_lost_credit.attr,
1387 &device_attr_rport_fpin_cn_credit_stall.attr,
1388 &device_attr_rport_fpin_cn_oversubscription.attr,
1389 &device_attr_rport_fpin_cn_device_specific.attr,
1394 .name = "statistics",
1412 struct device_attribute *attr, char *buf) \
1415 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
1416 struct fc_internal *i = to_fc_internal(shost->transportt); \
1419 fc_starget_##field(starget) = rport->field; \
1420 else if (i->f->get_starget_##field) \
1421 i->f->get_starget_##field(starget); \
1437 i->private_starget_attrs[count] = device_attr_starget_##field; \
1438 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
1439 i->private_starget_attrs[count].store = NULL; \
1440 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
1441 if (i->f->show_starget_##field) \
1445 i->private_starget_attrs[count] = device_attr_starget_##field; \
1446 if (!i->f->set_starget_##field) { \
1447 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
1448 i->private_starget_attrs[count].store = NULL; \
1450 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
1451 if (i->f->show_starget_##field) \
1467 struct device_attribute *attr, char *buf) \
1471 struct fc_internal *i = to_fc_internal(shost->transportt); \
1472 if ((i->f->get_vport_##field) && \
1473 !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))) \
1474 i->f->get_vport_##field(vport); \
1475 return snprintf(buf, sz, format_string, cast vport->field); \
1481 struct device_attribute *attr, \
1487 struct fc_internal *i = to_fc_internal(shost->transportt); \
1489 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \
1490 return -EBUSY; \
1493 return -EINVAL; \
1494 i->f->set_vport_##field(vport, val); \
1501 struct device_attribute *attr, \
1506 struct fc_internal *i = to_fc_internal(shost->transportt); \
1507 unsigned int cnt=count; \
1510 if (buf[cnt-1] == '\n') \
1511 cnt--; \
1512 if (cnt > ((slen) - 1)) \
1513 return -EINVAL; \
1514 memcpy(vport->field, buf, cnt); \
1515 i->f->set_vport_##field(vport); \
1539 struct device_attribute *attr, char *buf) \
1542 return snprintf(buf, sz, format_string, cast vport->field); \
1548 struct device_attribute *attr, \
1554 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \
1555 return -EBUSY; \
1558 return -EINVAL; \
1559 vport->field = val; \
1585 struct device_attribute *attr, \
1589 const char *name; \
1590 name = get_fc_##title##_name(vport->title); \
1591 if (!name) \
1592 return -EINVAL; \
1593 return snprintf(buf, maxlen, "%s\n", name); \
1600 i->private_vport_attrs[count] = device_attr_vport_##field; \
1601 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1602 i->private_vport_attrs[count].store = NULL; \
1603 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1604 if (i->f->get_##field) \
1609 i->private_vport_attrs[count] = device_attr_vport_##field; \
1610 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1611 i->private_vport_attrs[count].store = NULL; \
1612 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1616 i->private_vport_attrs[count] = device_attr_vport_##field; \
1617 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1618 if (i->f->field) \
1623 i->private_vport_attrs[count] = device_attr_vport_##field; \
1624 if (!i->f->set_vport_##field) { \
1625 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1626 i->private_vport_attrs[count].store = NULL; \
1628 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1634 i->private_vport_attrs[count] = device_attr_vport_##field; \
1635 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1654 show_fc_vport_roles (struct device *dev, struct device_attribute *attr, in show_fc_vport_roles() argument
1659 if (vport->roles == FC_PORT_ROLE_UNKNOWN) in show_fc_vport_roles()
1661 return get_fc_port_roles_names(vport->roles, buf); in show_fc_vport_roles()
1674 store_fc_vport_delete(struct device *dev, struct device_attribute *attr, in store_fc_vport_delete() argument
1681 spin_lock_irqsave(shost->host_lock, flags); in store_fc_vport_delete()
1682 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) { in store_fc_vport_delete()
1683 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_vport_delete()
1684 return -EBUSY; in store_fc_vport_delete()
1686 vport->flags |= FC_VPORT_DELETING; in store_fc_vport_delete()
1687 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_vport_delete()
1689 fc_queue_work(shost, &vport->vport_delete_work); in store_fc_vport_delete()
1701 store_fc_vport_disable(struct device *dev, struct device_attribute *attr, in store_fc_vport_disable() argument
1707 struct fc_internal *i = to_fc_internal(shost->transportt); in store_fc_vport_disable()
1710 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) in store_fc_vport_disable()
1711 return -EBUSY; in store_fc_vport_disable()
1714 if (vport->vport_state != FC_VPORT_DISABLED) in store_fc_vport_disable()
1715 return -EALREADY; in store_fc_vport_disable()
1717 if (vport->vport_state == FC_VPORT_DISABLED) in store_fc_vport_disable()
1718 return -EALREADY; in store_fc_vport_disable()
1720 return -EINVAL; in store_fc_vport_disable()
1722 stat = i->f->vport_disable(vport, ((*buf == '0') ? false : true)); in store_fc_vport_disable()
1736 struct device_attribute *attr, char *buf) \
1739 struct fc_internal *i = to_fc_internal(shost->transportt); \
1740 if (i->f->get_host_##field) \
1741 i->f->get_host_##field(shost); \
1748 struct device_attribute *attr, \
1753 struct fc_internal *i = to_fc_internal(shost->transportt); \
1758 return -EINVAL; \
1759 i->f->set_host_##field(shost, val); \
1766 struct device_attribute *attr, \
1770 struct fc_internal *i = to_fc_internal(shost->transportt); \
1771 unsigned int cnt=count; \
1774 if (buf[cnt-1] == '\n') \
1775 cnt--; \
1776 if (cnt > ((slen) - 1)) \
1777 return -EINVAL; \
1778 memcpy(fc_host_##field(shost), buf, cnt); \
1779 i->f->set_host_##field(shost); \
1803 struct device_attribute *attr, char *buf) \
1806 struct fc_internal *i = to_fc_internal(shost->transportt); \
1807 const char *name; \
1808 if (i->f->get_host_##title) \
1809 i->f->get_host_##title(shost); \
1810 name = get_fc_##title##_name(fc_host_##title(shost)); \
1811 if (!name) \
1812 return -EINVAL; \
1813 return snprintf(buf, maxlen, "%s\n", name); \
1818 i->private_host_attrs[count] = device_attr_host_##field; \
1819 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1820 i->private_host_attrs[count].store = NULL; \
1821 i->host_attrs[count] = &i->private_host_attrs[count]; \
1822 if (i->f->show_host_##field) \
1826 i->private_host_attrs[count] = device_attr_host_##field; \
1827 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1828 i->private_host_attrs[count].store = NULL; \
1829 i->host_attrs[count] = &i->private_host_attrs[count]; \
1833 i->private_host_attrs[count] = device_attr_host_##field; \
1834 if (!i->f->set_host_##field) { \
1835 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1836 i->private_host_attrs[count].store = NULL; \
1838 i->host_attrs[count] = &i->private_host_attrs[count]; \
1839 if (i->f->show_host_##field) \
1846 struct device_attribute *attr, char *buf) \
1863 i->private_host_attrs[count] = device_attr_host_##field; \
1864 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1865 i->private_host_attrs[count].store = NULL; \
1866 i->host_attrs[count] = &i->private_host_attrs[count]; \
1871 i->private_host_attrs[count] = device_attr_host_##field; \
1872 i->host_attrs[count] = &i->private_host_attrs[count]; \
1881 struct device_attribute *attr, char *buf) in show_fc_host_supported_classes() argument
1895 struct device_attribute *attr, char *buf) in show_fc_host_supported_fc4s() argument
1905 struct device_attribute *attr, char *buf) in show_fc_host_supported_speeds() argument
1938 struct device_attribute *attr, char *buf) in show_fc_host_active_fc4s() argument
1941 struct fc_internal *i = to_fc_internal(shost->transportt); in show_fc_host_active_fc4s()
1943 if (i->f->get_host_active_fc4s) in show_fc_host_active_fc4s()
1944 i->f->get_host_active_fc4s(shost); in show_fc_host_active_fc4s()
1953 struct device_attribute *attr, char *buf) in show_fc_host_speed() argument
1956 struct fc_internal *i = to_fc_internal(shost->transportt); in show_fc_host_speed()
1958 if (i->f->get_host_speed) in show_fc_host_speed()
1959 i->f->get_host_speed(shost); in show_fc_host_speed()
1987 struct device_attribute *attr, char *buf) in show_fc_private_host_tgtid_bind_type() argument
1990 const char *name; in show_fc_private_host_tgtid_bind_type() local
1992 name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost)); in show_fc_private_host_tgtid_bind_type()
1993 if (!name) in show_fc_private_host_tgtid_bind_type()
1994 return -EINVAL; in show_fc_private_host_tgtid_bind_type()
1995 return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name); in show_fc_private_host_tgtid_bind_type()
1999 pos = list_entry((head)->next, typeof(*pos), member)
2003 struct device_attribute *attr, const char *buf, size_t count) in store_fc_private_host_tgtid_bind_type() argument
2011 return -EINVAL; in store_fc_private_host_tgtid_bind_type()
2015 spin_lock_irqsave(shost->host_lock, flags); in store_fc_private_host_tgtid_bind_type()
2019 list_del(&rport->peers); in store_fc_private_host_tgtid_bind_type()
2020 rport->port_state = FC_PORTSTATE_DELETED; in store_fc_private_host_tgtid_bind_type()
2021 fc_queue_work(shost, &rport->rport_delete_work); in store_fc_private_host_tgtid_bind_type()
2023 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_private_host_tgtid_bind_type()
2036 struct device_attribute *attr, const char *buf, size_t count) in store_fc_private_host_issue_lip() argument
2039 struct fc_internal *i = to_fc_internal(shost->transportt); in store_fc_private_host_issue_lip()
2043 if (i->f->issue_fc_host_lip) { in store_fc_private_host_issue_lip()
2044 ret = i->f->issue_fc_host_lip(shost); in store_fc_private_host_issue_lip()
2048 return -ENOENT; in store_fc_private_host_issue_lip()
2056 struct device_attribute *attr, in store_fc_private_host_dev_loss_tmo() argument
2070 spin_lock_irqsave(shost->host_lock, flags); in store_fc_private_host_dev_loss_tmo()
2071 list_for_each_entry(rport, &fc_host->rports, peers) in store_fc_private_host_dev_loss_tmo()
2073 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_private_host_dev_loss_tmo()
2093 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_stat_show()
2095 ssize_t ret = -ENOENT; in fc_stat_show()
2101 if (i->f->get_fc_host_stats) { in fc_stat_show()
2102 stats = (i->f->get_fc_host_stats)(shost); in fc_stat_show()
2111 /* generate a read-only statistics attribute */
2112 #define fc_host_statistic(name) \ argument
2113 static ssize_t show_fcstat_##name(struct device *cd, \
2114 struct device_attribute *attr, \
2118 offsetof(struct fc_host_statistics, name)); \
2120 static FC_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
2155 #define fc_host_fpin_statistic(name) \ argument
2156 static ssize_t fc_host_fpinstat_##name(struct device *cd, \
2157 struct device_attribute *attr, \
2163 return snprintf(buf, 20, "0x%llx\n", fc_host->fpin_stats.name); \
2165 static FC_DEVICE_ATTR(host, fpin_##name, 0444, fc_host_fpinstat_##name, NULL)
2189 fc_reset_statistics(struct device *dev, struct device_attribute *attr, in fc_reset_statistics() argument
2193 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_reset_statistics()
2196 if (i->f->reset_fc_host_stats) { in fc_reset_statistics()
2197 i->f->reset_fc_host_stats(shost); in fc_reset_statistics()
2201 return -ENOENT; in fc_reset_statistics()
2207 &device_attr_host_seconds_since_last_reset.attr,
2208 &device_attr_host_tx_frames.attr,
2209 &device_attr_host_tx_words.attr,
2210 &device_attr_host_rx_frames.attr,
2211 &device_attr_host_rx_words.attr,
2212 &device_attr_host_lip_count.attr,
2213 &device_attr_host_nos_count.attr,
2214 &device_attr_host_error_frames.attr,
2215 &device_attr_host_dumped_frames.attr,
2216 &device_attr_host_link_failure_count.attr,
2217 &device_attr_host_loss_of_sync_count.attr,
2218 &device_attr_host_loss_of_signal_count.attr,
2219 &device_attr_host_prim_seq_protocol_err_count.attr,
2220 &device_attr_host_invalid_tx_word_count.attr,
2221 &device_attr_host_invalid_crc_count.attr,
2222 &device_attr_host_fcp_input_requests.attr,
2223 &device_attr_host_fcp_output_requests.attr,
2224 &device_attr_host_fcp_control_requests.attr,
2225 &device_attr_host_fcp_input_megabytes.attr,
2226 &device_attr_host_fcp_output_megabytes.attr,
2227 &device_attr_host_fcp_packet_alloc_failures.attr,
2228 &device_attr_host_fcp_packet_aborts.attr,
2229 &device_attr_host_fcp_frame_alloc_failures.attr,
2230 &device_attr_host_fc_no_free_exch.attr,
2231 &device_attr_host_fc_no_free_exch_xid.attr,
2232 &device_attr_host_fc_xid_not_found.attr,
2233 &device_attr_host_fc_xid_busy.attr,
2234 &device_attr_host_fc_seq_not_found.attr,
2235 &device_attr_host_fc_non_bls_resp.attr,
2236 &device_attr_host_cn_sig_warn.attr,
2237 &device_attr_host_cn_sig_alarm.attr,
2238 &device_attr_host_reset_statistics.attr,
2239 &device_attr_host_fpin_dn.attr,
2240 &device_attr_host_fpin_dn_unknown.attr,
2241 &device_attr_host_fpin_dn_timeout.attr,
2242 &device_attr_host_fpin_dn_unable_to_route.attr,
2243 &device_attr_host_fpin_dn_device_specific.attr,
2244 &device_attr_host_fpin_li.attr,
2245 &device_attr_host_fpin_li_failure_unknown.attr,
2246 &device_attr_host_fpin_li_link_failure_count.attr,
2247 &device_attr_host_fpin_li_loss_of_sync_count.attr,
2248 &device_attr_host_fpin_li_loss_of_signals_count.attr,
2249 &device_attr_host_fpin_li_prim_seq_err_count.attr,
2250 &device_attr_host_fpin_li_invalid_tx_word_count.attr,
2251 &device_attr_host_fpin_li_invalid_crc_count.attr,
2252 &device_attr_host_fpin_li_device_specific.attr,
2253 &device_attr_host_fpin_cn.attr,
2254 &device_attr_host_fpin_cn_clear.attr,
2255 &device_attr_host_fpin_cn_lost_credit.attr,
2256 &device_attr_host_fpin_cn_credit_stall.attr,
2257 &device_attr_host_fpin_cn_oversubscription.attr,
2258 &device_attr_host_fpin_cn_device_specific.attr,
2263 .name = "statistics",
2278 /* Validate and store the new name */ in fc_parse_wwn()
2286 return -EINVAL; in fc_parse_wwn()
2300 * "Short-cut" sysfs variable to create a new vport on a FC Host.
2302 * will default to a NPIV-based FCP_Initiator; The WWNs are specified
2306 store_fc_host_vport_create(struct device *dev, struct device_attribute *attr, in store_fc_host_vport_create() argument
2312 unsigned int cnt=count; in store_fc_host_vport_create() local
2318 if (buf[cnt-1] == '\n') in store_fc_host_vport_create()
2319 cnt--; in store_fc_host_vport_create()
2322 if ((cnt != (16+1+16)) || (buf[16] != ':')) in store_fc_host_vport_create()
2323 return -EINVAL; in store_fc_host_vport_create()
2339 stat = fc_vport_setup(shost, 0, &shost->shost_gendev, &vid, &vport); in store_fc_host_vport_create()
2347 * "Short-cut" sysfs variable to delete a vport on a FC Host.
2353 store_fc_host_vport_delete(struct device *dev, struct device_attribute *attr, in store_fc_host_vport_delete() argument
2361 unsigned int cnt=count; in store_fc_host_vport_delete() local
2365 if (buf[cnt-1] == '\n') in store_fc_host_vport_delete()
2366 cnt--; in store_fc_host_vport_delete()
2369 if ((cnt != (16+1+16)) || (buf[16] != ':')) in store_fc_host_vport_delete()
2370 return -EINVAL; in store_fc_host_vport_delete()
2380 spin_lock_irqsave(shost->host_lock, flags); in store_fc_host_vport_delete()
2383 list_for_each_entry(vport, &fc_host->vports, peers) { in store_fc_host_vport_delete()
2384 if ((vport->channel == 0) && in store_fc_host_vport_delete()
2385 (vport->port_name == wwpn) && (vport->node_name == wwnn)) { in store_fc_host_vport_delete()
2386 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) in store_fc_host_vport_delete()
2388 vport->flags |= FC_VPORT_DELETING; in store_fc_host_vport_delete()
2393 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_host_vport_delete()
2396 return -ENODEV; in store_fc_host_vport_delete()
2415 if (!shost->transportt || shost->transportt->host_attrs.ac.class in fc_host_match()
2419 i = to_fc_internal(shost->transportt); in fc_host_match()
2421 return &i->t.host_attrs.ac == cont; in fc_host_match()
2433 shost = dev_to_shost(dev->parent); in fc_target_match()
2434 if (!shost->transportt || shost->transportt->host_attrs.ac.class in fc_target_match()
2438 i = to_fc_internal(shost->transportt); in fc_target_match()
2440 return &i->t.target_attrs.ac == cont; in fc_target_match()
2446 put_device(dev->parent); in fc_rport_dev_release()
2452 return dev->release == fc_rport_dev_release; in scsi_is_fc_rport()
2465 shost = dev_to_shost(dev->parent); in fc_rport_match()
2466 if (!shost->transportt || shost->transportt->host_attrs.ac.class in fc_rport_match()
2470 i = to_fc_internal(shost->transportt); in fc_rport_match()
2472 return &i->rport_attr_cont.ac == cont; in fc_rport_match()
2479 put_device(dev->parent); /* release kobj parent */ in fc_vport_dev_release()
2485 return dev->release == fc_vport_dev_release; in scsi_is_fc_vport()
2500 if (!shost->transportt || shost->transportt->host_attrs.ac.class in fc_vport_match()
2504 i = to_fc_internal(shost->transportt); in fc_vport_match()
2505 return &i->vport_attr_cont.ac == cont; in fc_vport_match()
2510 * fc_eh_timed_out - FC Transport I/O timeout intercept handler
2533 struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device)); in fc_eh_timed_out()
2535 if (rport->port_state == FC_PORTSTATE_BLOCKED) in fc_eh_timed_out()
2553 spin_lock_irqsave(shost->host_lock, flags); in fc_user_scan_tgt()
2556 if (rport->scsi_target_id == -1) in fc_user_scan_tgt()
2559 if ((rport->port_state != FC_PORTSTATE_ONLINE) && in fc_user_scan_tgt()
2560 (rport->port_state != FC_PORTSTATE_MARGINAL)) in fc_user_scan_tgt()
2563 if ((channel == rport->channel) && in fc_user_scan_tgt()
2564 (id == rport->scsi_target_id)) { in fc_user_scan_tgt()
2565 spin_unlock_irqrestore(shost->host_lock, flags); in fc_user_scan_tgt()
2566 scsi_scan_target(&rport->dev, channel, id, lun, in fc_user_scan_tgt()
2572 spin_unlock_irqrestore(shost->host_lock, flags); in fc_user_scan_tgt()
2587 if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) || in fc_user_scan()
2588 ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) || in fc_user_scan()
2589 ((lun != SCAN_WILD_CARD) && (lun > shost->max_lun))) in fc_user_scan()
2590 return -EINVAL; in fc_user_scan()
2594 chhi = shost->max_channel + 1; in fc_user_scan()
2602 tgthi = shost->max_id; in fc_user_scan()
2625 i->t.target_attrs.ac.attrs = &i->starget_attrs[0]; in fc_attach_transport()
2626 i->t.target_attrs.ac.class = &fc_transport_class.class; in fc_attach_transport()
2627 i->t.target_attrs.ac.match = fc_target_match; in fc_attach_transport()
2628 i->t.target_size = sizeof(struct fc_starget_attrs); in fc_attach_transport()
2629 transport_container_register(&i->t.target_attrs); in fc_attach_transport()
2631 i->t.host_attrs.ac.attrs = &i->host_attrs[0]; in fc_attach_transport()
2632 i->t.host_attrs.ac.class = &fc_host_class.class; in fc_attach_transport()
2633 i->t.host_attrs.ac.match = fc_host_match; in fc_attach_transport()
2634 i->t.host_size = sizeof(struct fc_host_attrs); in fc_attach_transport()
2635 if (ft->get_fc_host_stats) in fc_attach_transport()
2636 i->t.host_attrs.statistics = &fc_statistics_group; in fc_attach_transport()
2637 transport_container_register(&i->t.host_attrs); in fc_attach_transport()
2639 i->rport_attr_cont.ac.attrs = &i->rport_attrs[0]; in fc_attach_transport()
2640 i->rport_attr_cont.ac.class = &fc_rport_class.class; in fc_attach_transport()
2641 i->rport_attr_cont.ac.match = fc_rport_match; in fc_attach_transport()
2642 i->rport_attr_cont.statistics = &fc_rport_statistics_group; in fc_attach_transport()
2643 transport_container_register(&i->rport_attr_cont); in fc_attach_transport()
2645 i->vport_attr_cont.ac.attrs = &i->vport_attrs[0]; in fc_attach_transport()
2646 i->vport_attr_cont.ac.class = &fc_vport_class.class; in fc_attach_transport()
2647 i->vport_attr_cont.ac.match = fc_vport_match; in fc_attach_transport()
2648 transport_container_register(&i->vport_attr_cont); in fc_attach_transport()
2650 i->f = ft; in fc_attach_transport()
2653 i->t.create_work_queue = 1; in fc_attach_transport()
2655 i->t.user_scan = fc_user_scan; in fc_attach_transport()
2667 i->starget_attrs[count] = NULL; in fc_attach_transport()
2681 if (ft->vport_create) { in fc_attach_transport()
2703 /* Transport-managed attributes */ in fc_attach_transport()
2706 if (ft->issue_fc_host_lip) in fc_attach_transport()
2708 if (ft->vport_create) in fc_attach_transport()
2710 if (ft->vport_delete) in fc_attach_transport()
2715 i->host_attrs[count] = NULL; in fc_attach_transport()
2734 i->rport_attrs[count] = NULL; in fc_attach_transport()
2752 i->vport_attrs[count] = NULL; in fc_attach_transport()
2754 return &i->t; in fc_attach_transport()
2762 transport_container_unregister(&i->t.target_attrs); in fc_release_transport()
2763 transport_container_unregister(&i->t.host_attrs); in fc_release_transport()
2764 transport_container_unregister(&i->rport_attr_cont); in fc_release_transport()
2765 transport_container_unregister(&i->vport_attr_cont); in fc_release_transport()
2772 * fc_queue_work - Queue work to the fc_host workqueue.
2777 * 1 - work queued for execution
2778 * 0 - work is already queued
2779 * -EINVAL - work queue doesn't exist
2787 "when no workqueue created.\n", shost->hostt->name); in fc_queue_work()
2790 return -EINVAL; in fc_queue_work()
2797 * fc_flush_work - Flush a fc_host's workqueue.
2806 "when no workqueue created.\n", shost->hostt->name); in fc_flush_work()
2815 * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue.
2830 "when no workqueue created.\n", shost->hostt->name); in fc_queue_devloss_work()
2833 return -EINVAL; in fc_queue_devloss_work()
2840 * fc_flush_devloss - Flush a fc_host's devloss workqueue.
2849 "when no workqueue created.\n", shost->hostt->name); in fc_flush_devloss()
2859 * fc_remove_host - called to terminate any fc_transport-related elements for a scsi host.
2882 spin_lock_irqsave(shost->host_lock, flags); in fc_remove_host()
2885 list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers) { in fc_remove_host()
2886 vport->flags |= FC_VPORT_DELETING; in fc_remove_host()
2887 fc_queue_work(shost, &vport->vport_delete_work); in fc_remove_host()
2892 &fc_host->rports, peers) { in fc_remove_host()
2893 list_del(&rport->peers); in fc_remove_host()
2894 rport->port_state = FC_PORTSTATE_DELETED; in fc_remove_host()
2895 fc_queue_work(shost, &rport->rport_delete_work); in fc_remove_host()
2899 &fc_host->rport_bindings, peers) { in fc_remove_host()
2900 list_del(&rport->peers); in fc_remove_host()
2901 rport->port_state = FC_PORTSTATE_DELETED; in fc_remove_host()
2902 fc_queue_work(shost, &rport->rport_delete_work); in fc_remove_host()
2905 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remove_host()
2911 if (fc_host->work_q) { in fc_remove_host()
2912 work_q = fc_host->work_q; in fc_remove_host()
2913 fc_host->work_q = NULL; in fc_remove_host()
2918 if (fc_host->devloss_work_q) { in fc_remove_host()
2919 work_q = fc_host->devloss_work_q; in fc_remove_host()
2920 fc_host->devloss_work_q = NULL; in fc_remove_host()
2929 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_terminate_rport_io()
2932 if (i->f->terminate_rport_io) in fc_terminate_rport_io()
2933 i->f->terminate_rport_io(rport); in fc_terminate_rport_io()
2936 * Must unblock to flush queued IO. scsi-ml will fail incoming reqs. in fc_terminate_rport_io()
2938 scsi_target_unblock(&rport->dev, SDEV_TRANSPORT_OFFLINE); in fc_terminate_rport_io()
2942 * fc_starget_delete - called to delete the scsi descendants of an rport
2954 scsi_remove_target(&rport->dev); in fc_starget_delete()
2959 * fc_rport_final_delete - finish rport termination and delete it.
2967 struct device *dev = &rport->dev; in fc_rport_final_delete()
2969 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_rport_final_delete()
2979 if (rport->flags & FC_RPORT_SCAN_PENDING) in fc_rport_final_delete()
2987 spin_lock_irqsave(shost->host_lock, flags); in fc_rport_final_delete()
2988 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) { in fc_rport_final_delete()
2989 spin_unlock_irqrestore(shost->host_lock, flags); in fc_rport_final_delete()
2990 if (!cancel_delayed_work(&rport->fail_io_work)) in fc_rport_final_delete()
2992 if (!cancel_delayed_work(&rport->dev_loss_work)) in fc_rport_final_delete()
2994 cancel_work_sync(&rport->scan_work); in fc_rport_final_delete()
2995 spin_lock_irqsave(shost->host_lock, flags); in fc_rport_final_delete()
2996 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; in fc_rport_final_delete()
2998 spin_unlock_irqrestore(shost->host_lock, flags); in fc_rport_final_delete()
3001 if (rport->scsi_target_id != -1) in fc_rport_final_delete()
3002 fc_starget_delete(&rport->stgt_delete_work); in fc_rport_final_delete()
3011 spin_lock_irqsave(shost->host_lock, flags); in fc_rport_final_delete()
3012 if (!(rport->flags & FC_RPORT_DEVLOSS_CALLBK_DONE) && in fc_rport_final_delete()
3013 (i->f->dev_loss_tmo_callbk)) { in fc_rport_final_delete()
3014 rport->flags |= FC_RPORT_DEVLOSS_CALLBK_DONE; in fc_rport_final_delete()
3017 spin_unlock_irqrestore(shost->host_lock, flags); in fc_rport_final_delete()
3020 i->f->dev_loss_tmo_callbk(rport); in fc_rport_final_delete()
3022 fc_bsg_remove(rport->rqst_q); in fc_rport_final_delete()
3027 scsi_host_put(shost); /* for fc_host->rport list */ in fc_rport_final_delete()
3028 put_device(dev); /* for self-reference */ in fc_rport_final_delete()
3033 * fc_remote_port_create - allocates and creates a remote FC port.
3050 struct fc_internal *fci = to_fc_internal(shost->transportt); in fc_remote_port_create()
3057 size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size); in fc_remote_port_create()
3064 rport->maxframe_size = -1; in fc_remote_port_create()
3065 rport->supported_classes = FC_COS_UNSPECIFIED; in fc_remote_port_create()
3066 rport->dev_loss_tmo = fc_host->dev_loss_tmo; in fc_remote_port_create()
3067 memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name)); in fc_remote_port_create()
3068 memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name)); in fc_remote_port_create()
3069 rport->port_id = ids->port_id; in fc_remote_port_create()
3070 rport->roles = ids->roles; in fc_remote_port_create()
3071 rport->port_state = FC_PORTSTATE_ONLINE; in fc_remote_port_create()
3072 if (fci->f->dd_fcrport_size) in fc_remote_port_create()
3073 rport->dd_data = &rport[1]; in fc_remote_port_create()
3074 rport->channel = channel; in fc_remote_port_create()
3075 rport->fast_io_fail_tmo = -1; in fc_remote_port_create()
3077 INIT_DELAYED_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport); in fc_remote_port_create()
3078 INIT_DELAYED_WORK(&rport->fail_io_work, fc_timeout_fail_rport_io); in fc_remote_port_create()
3079 INIT_WORK(&rport->scan_work, fc_scsi_scan_rport); in fc_remote_port_create()
3080 INIT_WORK(&rport->stgt_delete_work, fc_starget_delete); in fc_remote_port_create()
3081 INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete); in fc_remote_port_create()
3083 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_create()
3085 rport->number = fc_host->next_rport_number++; in fc_remote_port_create()
3086 if ((rport->roles & FC_PORT_ROLE_FCP_TARGET) || in fc_remote_port_create()
3087 (rport->roles & FC_PORT_ROLE_FCP_DUMMY_INITIATOR)) in fc_remote_port_create()
3088 rport->scsi_target_id = fc_host->next_target_id++; in fc_remote_port_create()
3090 rport->scsi_target_id = -1; in fc_remote_port_create()
3091 list_add_tail(&rport->peers, &fc_host->rports); in fc_remote_port_create()
3092 scsi_host_get(shost); /* for fc_host->rport list */ in fc_remote_port_create()
3094 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_create()
3096 dev = &rport->dev; in fc_remote_port_create()
3098 dev->parent = get_device(&shost->shost_gendev); /* parent reference */ in fc_remote_port_create()
3099 dev->release = fc_rport_dev_release; in fc_remote_port_create()
3100 dev_set_name(dev, "rport-%d:%d-%d", in fc_remote_port_create()
3101 shost->host_no, channel, rport->number); in fc_remote_port_create()
3113 /* ignore any bsg add error - we just can't do sgio */ in fc_remote_port_create()
3115 if (rport->roles & FC_PORT_ROLE_FCP_TARGET) { in fc_remote_port_create()
3117 rport->flags |= FC_RPORT_SCAN_PENDING; in fc_remote_port_create()
3118 scsi_queue_work(shost, &rport->scan_work); in fc_remote_port_create()
3125 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_create()
3126 list_del(&rport->peers); in fc_remote_port_create()
3127 scsi_host_put(shost); /* for fc_host->rport list */ in fc_remote_port_create()
3128 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_create()
3129 put_device(dev->parent); in fc_remote_port_create()
3135 * fc_remote_port_add - notify fc transport of the existence of a remote FC port.
3155 * the scsi host. If the host detaches, then later re-attaches, target
3176 struct fc_internal *fci = to_fc_internal(shost->transportt); in fc_remote_port_add()
3190 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_add()
3192 list_for_each_entry(rport, &fc_host->rports, peers) { in fc_remote_port_add()
3194 if ((rport->port_state == FC_PORTSTATE_BLOCKED || in fc_remote_port_add()
3195 rport->port_state == FC_PORTSTATE_NOTPRESENT) && in fc_remote_port_add()
3196 (rport->channel == channel)) { in fc_remote_port_add()
3198 switch (fc_host->tgtid_bind_type) { in fc_remote_port_add()
3201 if (rport->port_name == ids->port_name) in fc_remote_port_add()
3205 if (rport->node_name == ids->node_name) in fc_remote_port_add()
3209 if (rport->port_id == ids->port_id) in fc_remote_port_add()
3216 memcpy(&rport->node_name, &ids->node_name, in fc_remote_port_add()
3217 sizeof(rport->node_name)); in fc_remote_port_add()
3218 memcpy(&rport->port_name, &ids->port_name, in fc_remote_port_add()
3219 sizeof(rport->port_name)); in fc_remote_port_add()
3220 rport->port_id = ids->port_id; in fc_remote_port_add()
3222 rport->port_state = FC_PORTSTATE_ONLINE; in fc_remote_port_add()
3223 rport->roles = ids->roles; in fc_remote_port_add()
3225 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_add()
3227 if (fci->f->dd_fcrport_size) in fc_remote_port_add()
3228 memset(rport->dd_data, 0, in fc_remote_port_add()
3229 fci->f->dd_fcrport_size); in fc_remote_port_add()
3248 if ((rport->scsi_target_id != -1) && in fc_remote_port_add()
3249 (!(ids->roles & FC_PORT_ROLE_FCP_TARGET))) in fc_remote_port_add()
3257 if (!cancel_delayed_work(&rport->fail_io_work)) in fc_remote_port_add()
3259 if (!cancel_delayed_work(&rport->dev_loss_work)) in fc_remote_port_add()
3262 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_add()
3264 rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT | in fc_remote_port_add()
3268 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_add()
3271 if (rport->scsi_target_id != -1) { in fc_remote_port_add()
3272 scsi_target_unblock(&rport->dev, in fc_remote_port_add()
3274 spin_lock_irqsave(shost->host_lock, in fc_remote_port_add()
3276 rport->flags |= FC_RPORT_SCAN_PENDING; in fc_remote_port_add()
3278 &rport->scan_work); in fc_remote_port_add()
3279 spin_unlock_irqrestore(shost->host_lock, in fc_remote_port_add()
3294 if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) { in fc_remote_port_add()
3298 list_for_each_entry(rport, &fc_host->rport_bindings, in fc_remote_port_add()
3300 if (rport->channel != channel) in fc_remote_port_add()
3303 switch (fc_host->tgtid_bind_type) { in fc_remote_port_add()
3305 if (rport->port_name == ids->port_name) in fc_remote_port_add()
3309 if (rport->node_name == ids->node_name) in fc_remote_port_add()
3313 if (rport->port_id == ids->port_id) in fc_remote_port_add()
3321 list_move_tail(&rport->peers, &fc_host->rports); in fc_remote_port_add()
3327 memcpy(&rport->node_name, &ids->node_name, in fc_remote_port_add()
3328 sizeof(rport->node_name)); in fc_remote_port_add()
3329 memcpy(&rport->port_name, &ids->port_name, in fc_remote_port_add()
3330 sizeof(rport->port_name)); in fc_remote_port_add()
3331 rport->port_id = ids->port_id; in fc_remote_port_add()
3332 rport->port_state = FC_PORTSTATE_ONLINE; in fc_remote_port_add()
3333 rport->flags &= ~FC_RPORT_FAST_FAIL_TIMEDOUT; in fc_remote_port_add()
3335 if (fci->f->dd_fcrport_size) in fc_remote_port_add()
3336 memset(rport->dd_data, 0, in fc_remote_port_add()
3337 fci->f->dd_fcrport_size); in fc_remote_port_add()
3338 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_add()
3340 fc_remote_port_rolechg(rport, ids->roles); in fc_remote_port_add()
3345 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_add()
3347 /* No consistent binding found - create new remote port entry */ in fc_remote_port_add()
3356 * fc_remote_port_delete - notifies the fc transport that a remote port is no longer in existence.
3371 * attached to it. However, we want to semi-persist the target id assigned
3387 * scsi target is removed - killing all outstanding i/o and removing the
3402 * Called from normal process context only - cannot be called from interrupt.
3411 unsigned long timeout = rport->dev_loss_tmo; in fc_remote_port_delete()
3422 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_delete()
3424 if ((rport->port_state != FC_PORTSTATE_ONLINE) && in fc_remote_port_delete()
3425 (rport->port_state != FC_PORTSTATE_MARGINAL)) { in fc_remote_port_delete()
3426 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_delete()
3431 * In the past, we if this was not an FCP-Target, we would in fc_remote_port_delete()
3436 * send ELS traffic to re-validate the login. If the rport is in fc_remote_port_delete()
3443 rport->port_state = FC_PORTSTATE_BLOCKED; in fc_remote_port_delete()
3445 rport->flags |= FC_RPORT_DEVLOSS_PENDING; in fc_remote_port_delete()
3447 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_delete()
3449 scsi_block_targets(shost, &rport->dev); in fc_remote_port_delete()
3452 if ((rport->fast_io_fail_tmo != -1) && in fc_remote_port_delete()
3453 (rport->fast_io_fail_tmo < timeout)) in fc_remote_port_delete()
3454 fc_queue_devloss_work(shost, &rport->fail_io_work, in fc_remote_port_delete()
3455 rport->fast_io_fail_tmo * HZ); in fc_remote_port_delete()
3458 fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ); in fc_remote_port_delete()
3463 * fc_remote_port_rolechg - notifies the fc transport that the roles on a remote may have changed.
3490 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_rolechg()
3492 if (rport->scsi_target_id == -1) { in fc_remote_port_rolechg()
3493 rport->scsi_target_id = fc_host->next_target_id++; in fc_remote_port_rolechg()
3495 } else if (!(rport->roles & FC_PORT_ROLE_FCP_TARGET)) in fc_remote_port_rolechg()
3499 rport->roles = roles; in fc_remote_port_rolechg()
3501 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_rolechg()
3516 if (!cancel_delayed_work(&rport->fail_io_work)) in fc_remote_port_rolechg()
3518 if (!cancel_delayed_work(&rport->dev_loss_work)) in fc_remote_port_rolechg()
3521 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_rolechg()
3522 rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT | in fc_remote_port_rolechg()
3525 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_rolechg()
3530 scsi_target_unblock(&rport->dev, SDEV_RUNNING); in fc_remote_port_rolechg()
3532 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_rolechg()
3533 rport->flags |= FC_RPORT_SCAN_PENDING; in fc_remote_port_rolechg()
3534 scsi_queue_work(shost, &rport->scan_work); in fc_remote_port_rolechg()
3535 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_rolechg()
3541 * fc_timeout_deleted_rport - Timeout handler for a deleted remote port.
3553 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_timeout_deleted_rport()
3558 spin_lock_irqsave(shost->host_lock, flags); in fc_timeout_deleted_rport()
3560 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; in fc_timeout_deleted_rport()
3567 if (((rport->port_state == FC_PORTSTATE_ONLINE) || in fc_timeout_deleted_rport()
3568 (rport->port_state == FC_PORTSTATE_MARGINAL)) && in fc_timeout_deleted_rport()
3569 (rport->scsi_target_id != -1) && in fc_timeout_deleted_rport()
3570 !(rport->roles & FC_PORT_ROLE_FCP_TARGET)) { in fc_timeout_deleted_rport()
3571 dev_printk(KERN_ERR, &rport->dev, in fc_timeout_deleted_rport()
3574 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3575 scsi_target_unblock(&rport->dev, SDEV_TRANSPORT_OFFLINE); in fc_timeout_deleted_rport()
3576 fc_queue_work(shost, &rport->stgt_delete_work); in fc_timeout_deleted_rport()
3580 /* NOOP state - we're flushing workq's */ in fc_timeout_deleted_rport()
3581 if (rport->port_state != FC_PORTSTATE_BLOCKED) { in fc_timeout_deleted_rport()
3582 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3583 dev_printk(KERN_ERR, &rport->dev, in fc_timeout_deleted_rport()
3586 (rport->scsi_target_id != -1) ? " and starget" : ""); in fc_timeout_deleted_rport()
3590 if ((fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) || in fc_timeout_deleted_rport()
3591 (rport->scsi_target_id == -1)) { in fc_timeout_deleted_rport()
3592 list_del(&rport->peers); in fc_timeout_deleted_rport()
3593 rport->port_state = FC_PORTSTATE_DELETED; in fc_timeout_deleted_rport()
3594 dev_printk(KERN_ERR, &rport->dev, in fc_timeout_deleted_rport()
3597 (rport->scsi_target_id != -1) ? " and starget" : ""); in fc_timeout_deleted_rport()
3598 fc_queue_work(shost, &rport->rport_delete_work); in fc_timeout_deleted_rport()
3599 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3603 dev_printk(KERN_ERR, &rport->dev, in fc_timeout_deleted_rport()
3607 list_move_tail(&rport->peers, &fc_host->rport_bindings); in fc_timeout_deleted_rport()
3611 * host-specific target data to persist along with the in fc_timeout_deleted_rport()
3618 rport->maxframe_size = -1; in fc_timeout_deleted_rport()
3619 rport->supported_classes = FC_COS_UNSPECIFIED; in fc_timeout_deleted_rport()
3620 rport->roles = FC_PORT_ROLE_UNKNOWN; in fc_timeout_deleted_rport()
3621 rport->port_state = FC_PORTSTATE_NOTPRESENT; in fc_timeout_deleted_rport()
3622 rport->flags &= ~FC_RPORT_FAST_FAIL_TIMEDOUT; in fc_timeout_deleted_rport()
3625 * Pre-emptively kill I/O rather than waiting for the work queue in fc_timeout_deleted_rport()
3629 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3632 spin_lock_irqsave(shost->host_lock, flags); in fc_timeout_deleted_rport()
3634 if (rport->port_state == FC_PORTSTATE_NOTPRESENT) { /* still missing */ in fc_timeout_deleted_rport()
3637 switch (fc_host->tgtid_bind_type) { in fc_timeout_deleted_rport()
3639 rport->node_name = -1; in fc_timeout_deleted_rport()
3640 rport->port_id = -1; in fc_timeout_deleted_rport()
3643 rport->port_name = -1; in fc_timeout_deleted_rport()
3644 rport->port_id = -1; in fc_timeout_deleted_rport()
3647 rport->node_name = -1; in fc_timeout_deleted_rport()
3648 rport->port_name = -1; in fc_timeout_deleted_rport()
3656 * went away and didn't come back - we'll remove in fc_timeout_deleted_rport()
3659 rport->flags |= FC_RPORT_DEVLOSS_CALLBK_DONE; in fc_timeout_deleted_rport()
3660 fc_queue_work(shost, &rport->stgt_delete_work); in fc_timeout_deleted_rport()
3665 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3673 if (do_callback && i->f->dev_loss_tmo_callbk) in fc_timeout_deleted_rport()
3674 i->f->dev_loss_tmo_callbk(rport); in fc_timeout_deleted_rport()
3679 * fc_timeout_fail_rport_io - Timeout handler for a fast io failing on a disconnected SCSI target.
3691 if (rport->port_state != FC_PORTSTATE_BLOCKED) in fc_timeout_fail_rport_io()
3694 rport->flags |= FC_RPORT_FAST_FAIL_TIMEDOUT; in fc_timeout_fail_rport_io()
3699 * fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
3708 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_scsi_scan_rport()
3711 if (((rport->port_state == FC_PORTSTATE_ONLINE) || in fc_scsi_scan_rport()
3712 (rport->port_state == FC_PORTSTATE_MARGINAL)) && in fc_scsi_scan_rport()
3713 (rport->roles & FC_PORT_ROLE_FCP_TARGET) && in fc_scsi_scan_rport()
3714 !(i->f->disable_target_scan)) { in fc_scsi_scan_rport()
3715 scsi_scan_target(&rport->dev, rport->channel, in fc_scsi_scan_rport()
3716 rport->scsi_target_id, SCAN_WILD_CARD, in fc_scsi_scan_rport()
3720 spin_lock_irqsave(shost->host_lock, flags); in fc_scsi_scan_rport()
3721 rport->flags &= ~FC_RPORT_SCAN_PENDING; in fc_scsi_scan_rport()
3722 spin_unlock_irqrestore(shost->host_lock, flags); in fc_scsi_scan_rport()
3726 * fc_block_rport() - Block SCSI eh thread for blocked fc_rport.
3744 spin_lock_irqsave(shost->host_lock, flags); in fc_block_rport()
3745 while (rport->port_state == FC_PORTSTATE_BLOCKED && in fc_block_rport()
3746 !(rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)) { in fc_block_rport()
3747 spin_unlock_irqrestore(shost->host_lock, flags); in fc_block_rport()
3749 spin_lock_irqsave(shost->host_lock, flags); in fc_block_rport()
3751 spin_unlock_irqrestore(shost->host_lock, flags); in fc_block_rport()
3753 if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT) in fc_block_rport()
3761 * fc_block_scsi_eh - Block SCSI eh thread for blocked fc_rport
3776 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); in fc_block_scsi_eh()
3786 * fc_eh_should_retry_cmd - Checks if the cmd should be retried or not
3796 struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device)); in fc_eh_should_retry_cmd()
3798 if ((rport->port_state != FC_PORTSTATE_ONLINE) && in fc_eh_should_retry_cmd()
3799 (scsi_cmd_to_rq(scmd)->cmd_flags & REQ_FAILFAST_TRANSPORT)) { in fc_eh_should_retry_cmd()
3808 * fc_vport_setup - allocates and creates a FC virtual port.
3827 struct fc_internal *fci = to_fc_internal(shost->transportt); in fc_vport_setup()
3836 if ( ! fci->f->vport_create) in fc_vport_setup()
3837 return -ENOENT; in fc_vport_setup()
3839 size = (sizeof(struct fc_vport) + fci->f->dd_fcvport_size); in fc_vport_setup()
3843 return -ENOMEM; in fc_vport_setup()
3846 vport->vport_state = FC_VPORT_UNKNOWN; in fc_vport_setup()
3847 vport->vport_last_state = FC_VPORT_UNKNOWN; in fc_vport_setup()
3848 vport->node_name = ids->node_name; in fc_vport_setup()
3849 vport->port_name = ids->port_name; in fc_vport_setup()
3850 vport->roles = ids->roles; in fc_vport_setup()
3851 vport->vport_type = ids->vport_type; in fc_vport_setup()
3852 if (fci->f->dd_fcvport_size) in fc_vport_setup()
3853 vport->dd_data = &vport[1]; in fc_vport_setup()
3854 vport->shost = shost; in fc_vport_setup()
3855 vport->channel = channel; in fc_vport_setup()
3856 vport->flags = FC_VPORT_CREATING; in fc_vport_setup()
3857 INIT_WORK(&vport->vport_delete_work, fc_vport_sched_delete); in fc_vport_setup()
3859 spin_lock_irqsave(shost->host_lock, flags); in fc_vport_setup()
3861 if (fc_host->npiv_vports_inuse >= fc_host->max_npiv_vports) { in fc_vport_setup()
3862 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_setup()
3864 return -ENOSPC; in fc_vport_setup()
3866 fc_host->npiv_vports_inuse++; in fc_vport_setup()
3867 vport->number = fc_host->next_vport_number++; in fc_vport_setup()
3868 list_add_tail(&vport->peers, &fc_host->vports); in fc_vport_setup()
3869 scsi_host_get(shost); /* for fc_host->vport list */ in fc_vport_setup()
3871 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_setup()
3873 dev = &vport->dev; in fc_vport_setup()
3875 dev->parent = get_device(pdev); /* takes parent reference */ in fc_vport_setup()
3876 dev->release = fc_vport_dev_release; in fc_vport_setup()
3877 dev_set_name(dev, "vport-%d:%d-%d", in fc_vport_setup()
3878 shost->host_no, channel, vport->number); in fc_vport_setup()
3889 error = fci->f->vport_create(vport, ids->disable); in fc_vport_setup()
3899 if (pdev != &shost->shost_gendev) { in fc_vport_setup()
3900 error = sysfs_create_link(&shost->shost_gendev.kobj, in fc_vport_setup()
3901 &dev->kobj, dev_name(dev)); in fc_vport_setup()
3908 spin_lock_irqsave(shost->host_lock, flags); in fc_vport_setup()
3909 vport->flags &= ~FC_VPORT_CREATING; in fc_vport_setup()
3910 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_setup()
3914 shost->host_no, channel); in fc_vport_setup()
3925 spin_lock_irqsave(shost->host_lock, flags); in fc_vport_setup()
3926 list_del(&vport->peers); in fc_vport_setup()
3927 scsi_host_put(shost); /* for fc_host->vport list */ in fc_vport_setup()
3928 fc_host->npiv_vports_inuse--; in fc_vport_setup()
3929 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_setup()
3930 put_device(dev->parent); in fc_vport_setup()
3937 * fc_vport_create - Admin App or LLDD requests creation of a vport
3953 stat = fc_vport_setup(shost, channel, &shost->shost_gendev, in fc_vport_create()
3960 * fc_vport_terminate - Admin App or LLDD requests termination of a vport
3974 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_vport_terminate()
3975 struct device *dev = &vport->dev; in fc_vport_terminate()
3979 if (i->f->vport_delete) in fc_vport_terminate()
3980 stat = i->f->vport_delete(vport); in fc_vport_terminate()
3982 stat = -ENOENT; in fc_vport_terminate()
3984 spin_lock_irqsave(shost->host_lock, flags); in fc_vport_terminate()
3985 vport->flags &= ~FC_VPORT_DELETING; in fc_vport_terminate()
3987 vport->flags |= FC_VPORT_DELETED; in fc_vport_terminate()
3988 list_del(&vport->peers); in fc_vport_terminate()
3989 fc_host->npiv_vports_inuse--; in fc_vport_terminate()
3990 scsi_host_put(shost); /* for fc_host->vport list */ in fc_vport_terminate()
3992 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_terminate()
3997 if (dev->parent != &shost->shost_gendev) in fc_vport_terminate()
3998 sysfs_remove_link(&shost->shost_gendev.kobj, dev_name(dev)); in fc_vport_terminate()
4004 * Removing our self-reference should mean our in fc_vport_terminate()
4008 put_device(dev); /* for self-reference */ in fc_vport_terminate()
4015 * fc_vport_sched_delete - workq-based delete request for a vport
4027 dev_printk(KERN_ERR, vport->dev.parent, in fc_vport_sched_delete()
4029 "shost%d channel %d - error %d\n", __func__, in fc_vport_sched_delete()
4030 dev_name(&vport->dev), vport->shost->host_no, in fc_vport_sched_delete()
4031 vport->channel, stat); in fc_vport_sched_delete()
4040 * fc_bsg_job_timeout - handler for when a bsg request timesout
4049 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_job_timeout()
4052 if (rport && rport->port_state == FC_PORTSTATE_BLOCKED) in fc_bsg_job_timeout()
4057 if (inflight && i->f->bsg_timeout) { in fc_bsg_job_timeout()
4059 err = i->f->bsg_timeout(job); in fc_bsg_job_timeout()
4060 if (err == -EAGAIN) { in fc_bsg_job_timeout()
4064 printk(KERN_ERR "ERROR: FC BSG request timeout - LLD " in fc_bsg_job_timeout()
4075 * fc_bsg_host_dispatch - process fc host bsg requests and dispatch to LLDD
4081 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_host_dispatch()
4082 struct fc_bsg_request *bsg_request = job->request; in fc_bsg_host_dispatch()
4083 struct fc_bsg_reply *bsg_reply = job->reply; in fc_bsg_host_dispatch()
4088 if (job->request_len < cmdlen) { in fc_bsg_host_dispatch()
4089 ret = -ENOMSG; in fc_bsg_host_dispatch()
4094 switch (bsg_request->msgcode) { in fc_bsg_host_dispatch()
4106 if ((!job->request_payload.payload_len) || in fc_bsg_host_dispatch()
4107 (!job->reply_payload.payload_len)) { in fc_bsg_host_dispatch()
4108 ret = -EINVAL; in fc_bsg_host_dispatch()
4116 if ((!job->request_payload.payload_len) || in fc_bsg_host_dispatch()
4117 (!job->reply_payload.payload_len)) { in fc_bsg_host_dispatch()
4118 ret = -EINVAL; in fc_bsg_host_dispatch()
4125 if ((shost->hostt->vendor_id == 0L) || in fc_bsg_host_dispatch()
4126 (bsg_request->rqst_data.h_vendor.vendor_id != in fc_bsg_host_dispatch()
4127 shost->hostt->vendor_id)) { in fc_bsg_host_dispatch()
4128 ret = -ESRCH; in fc_bsg_host_dispatch()
4134 ret = -EBADR; in fc_bsg_host_dispatch()
4138 ret = i->f->bsg_request(job); in fc_bsg_host_dispatch()
4144 BUG_ON(job->reply_len < sizeof(uint32_t)); in fc_bsg_host_dispatch()
4145 bsg_reply->reply_payload_rcv_len = 0; in fc_bsg_host_dispatch()
4146 bsg_reply->result = ret; in fc_bsg_host_dispatch()
4147 job->reply_len = sizeof(uint32_t); in fc_bsg_host_dispatch()
4148 bsg_job_done(job, bsg_reply->result, in fc_bsg_host_dispatch()
4149 bsg_reply->reply_payload_rcv_len); in fc_bsg_host_dispatch()
4155 * fc_bsg_goose_queue - restart rport queue in case it was stopped
4161 struct request_queue *q = rport->rqst_q; in fc_bsg_goose_queue()
4168 * fc_bsg_rport_dispatch - process rport bsg requests and dispatch to LLDD
4174 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_rport_dispatch()
4175 struct fc_bsg_request *bsg_request = job->request; in fc_bsg_rport_dispatch()
4176 struct fc_bsg_reply *bsg_reply = job->reply; in fc_bsg_rport_dispatch()
4181 if (job->request_len < cmdlen) { in fc_bsg_rport_dispatch()
4182 ret = -ENOMSG; in fc_bsg_rport_dispatch()
4187 switch (bsg_request->msgcode) { in fc_bsg_rport_dispatch()
4196 if ((!job->request_payload.payload_len) || in fc_bsg_rport_dispatch()
4197 (!job->reply_payload.payload_len)) { in fc_bsg_rport_dispatch()
4198 ret = -EINVAL; in fc_bsg_rport_dispatch()
4203 ret = -EBADR; in fc_bsg_rport_dispatch()
4207 ret = i->f->bsg_request(job); in fc_bsg_rport_dispatch()
4213 BUG_ON(job->reply_len < sizeof(uint32_t)); in fc_bsg_rport_dispatch()
4214 bsg_reply->reply_payload_rcv_len = 0; in fc_bsg_rport_dispatch()
4215 bsg_reply->result = ret; in fc_bsg_rport_dispatch()
4216 job->reply_len = sizeof(uint32_t); in fc_bsg_rport_dispatch()
4217 bsg_job_done(job, bsg_reply->result, in fc_bsg_rport_dispatch()
4218 bsg_reply->reply_payload_rcv_len); in fc_bsg_rport_dispatch()
4226 if (scsi_is_fc_rport(job->dev)) in fc_bsg_dispatch()
4234 if (rport->port_state == FC_PORTSTATE_BLOCKED && in fc_bsg_rport_prep()
4235 !(rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)) in fc_bsg_rport_prep()
4238 if ((rport->port_state != FC_PORTSTATE_ONLINE) && in fc_bsg_rport_prep()
4239 (rport->port_state != FC_PORTSTATE_MARGINAL)) in fc_bsg_rport_prep()
4256 return -EAGAIN; in fc_bsg_dispatch_prep()
4258 return -EIO; in fc_bsg_dispatch_prep()
4265 * fc_bsg_hostadd - Create and add the bsg hooks so we can receive requests
4272 struct device *dev = &shost->shost_gendev; in fc_bsg_hostadd()
4273 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_hostadd()
4278 fc_host->rqst_q = NULL; in fc_bsg_hostadd()
4280 if (!i->f->bsg_request) in fc_bsg_hostadd()
4281 return -ENOTSUPP; in fc_bsg_hostadd()
4284 "fc_host%d", shost->host_no); in fc_bsg_hostadd()
4286 lim.max_segments = min_not_zero(lim.max_segments, i->f->max_bsg_segments); in fc_bsg_hostadd()
4288 fc_bsg_job_timeout, i->f->dd_bsg_size); in fc_bsg_hostadd()
4291 "fc_host%d: bsg interface failed to initialize - setup queue\n", in fc_bsg_hostadd()
4292 shost->host_no); in fc_bsg_hostadd()
4296 fc_host->rqst_q = q; in fc_bsg_hostadd()
4301 * fc_bsg_rportadd - Create and add the bsg hooks so we can receive requests
4308 struct device *dev = &rport->dev; in fc_bsg_rportadd()
4309 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_rportadd()
4313 rport->rqst_q = NULL; in fc_bsg_rportadd()
4315 if (!i->f->bsg_request) in fc_bsg_rportadd()
4316 return -ENOTSUPP; in fc_bsg_rportadd()
4319 lim.max_segments = min_not_zero(lim.max_segments, i->f->max_bsg_segments); in fc_bsg_rportadd()
4321 fc_bsg_job_timeout, i->f->dd_bsg_size); in fc_bsg_rportadd()
4327 rport->rqst_q = q; in fc_bsg_rportadd()
4333 * fc_bsg_remove - Deletes the bsg hooks on fchosts/rports