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 snprintf(fc_host->work_q_name, sizeof(fc_host->work_q_name), in fc_host_setup()
445 "fc_wq_%d", shost->host_no); in fc_host_setup()
446 fc_host->work_q = alloc_workqueue("%s", 0, 0, fc_host->work_q_name); in fc_host_setup()
447 if (!fc_host->work_q) in fc_host_setup()
448 return -ENOMEM; in fc_host_setup()
450 fc_host->dev_loss_tmo = fc_dev_loss_tmo; in fc_host_setup()
451 snprintf(fc_host->devloss_work_q_name, in fc_host_setup()
452 sizeof(fc_host->devloss_work_q_name), in fc_host_setup()
453 "fc_dl_%d", shost->host_no); in fc_host_setup()
454 fc_host->devloss_work_q = alloc_workqueue("%s", 0, 0, in fc_host_setup()
455 fc_host->devloss_work_q_name); in fc_host_setup()
456 if (!fc_host->devloss_work_q) { in fc_host_setup()
457 destroy_workqueue(fc_host->work_q); in fc_host_setup()
458 fc_host->work_q = NULL; in fc_host_setup()
459 return -ENOMEM; in fc_host_setup()
463 /* ignore any bsg add error - we just can't do sgio */ in fc_host_setup()
474 fc_bsg_remove(fc_host->rqst_q); in fc_host_remove()
511 * fc_get_event_number - Obtain the next sequential FC event number
526 * fc_host_post_fc_event - routine to do the work of posting an event
546 const char *name; in fc_host_post_fc_event() local
554 err = -ENOENT; in fc_host_post_fc_event()
558 len = FC_NL_MSGALIGN(sizeof(*event) - sizeof(event->event_data) + data_len); in fc_host_post_fc_event()
562 err = -ENOBUFS; in fc_host_post_fc_event()
568 err = -ENOBUFS; in fc_host_post_fc_event()
573 INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, in fc_host_post_fc_event()
575 event->seconds = ktime_get_real_seconds(); in fc_host_post_fc_event()
576 event->vendor_id = vendor_id; in fc_host_post_fc_event()
577 event->host_no = shost->host_no; in fc_host_post_fc_event()
578 event->event_datalen = data_len; /* bytes */ in fc_host_post_fc_event()
579 event->event_num = event_number; in fc_host_post_fc_event()
580 event->event_code = event_code; in fc_host_post_fc_event()
582 memcpy(event->event_data_flex, data_buf, data_len); in fc_host_post_fc_event()
583 padding = len - offsetof(typeof(*event), event_data_flex) - data_len; in fc_host_post_fc_event()
584 memset(event->event_data_flex + data_len, 0, padding); in fc_host_post_fc_event()
593 name = get_fc_host_event_code_name(event_code); in fc_host_post_fc_event()
595 "%s: Dropped Event : host %d %s data 0x%08x - err %d\n", in fc_host_post_fc_event()
596 __func__, shost->host_no, in fc_host_post_fc_event()
597 (name) ? name : "<unknown>", in fc_host_post_fc_event()
604 * fc_host_post_event - called to post an even on an fc_host.
624 * fc_host_post_vendor_event - called to post a vendor unique event
645 * fc_find_rport_by_wwpn - find the fc_rport pointer for a given wwpn
658 spin_lock_irqsave(shost->host_lock, flags); in fc_find_rport_by_wwpn()
661 if (rport->port_state != FC_PORTSTATE_ONLINE) in fc_find_rport_by_wwpn()
664 if (rport->port_name == wwpn) { in fc_find_rport_by_wwpn()
665 spin_unlock_irqrestore(shost->host_lock, flags); in fc_find_rport_by_wwpn()
670 spin_unlock_irqrestore(shost->host_lock, flags); in fc_find_rport_by_wwpn()
679 stats->li++; in fc_li_stats_update()
682 stats->li_failure_unknown++; in fc_li_stats_update()
685 stats->li_link_failure_count++; in fc_li_stats_update()
688 stats->li_loss_of_sync_count++; in fc_li_stats_update()
691 stats->li_loss_of_signals_count++; in fc_li_stats_update()
694 stats->li_prim_seq_err_count++; in fc_li_stats_update()
697 stats->li_invalid_tx_word_count++; in fc_li_stats_update()
700 stats->li_invalid_crc_count++; in fc_li_stats_update()
703 stats->li_device_specific++; in fc_li_stats_update()
711 stats->dn++; in fc_delivery_stats_update()
714 stats->dn_unknown++; in fc_delivery_stats_update()
717 stats->dn_timeout++; in fc_delivery_stats_update()
720 stats->dn_unable_to_route++; in fc_delivery_stats_update()
723 stats->dn_device_specific++; in fc_delivery_stats_update()
731 stats->cn++; in fc_cn_stats_update()
734 stats->cn_clear++; in fc_cn_stats_update()
737 stats->cn_lost_credit++; in fc_cn_stats_update()
740 stats->cn_credit_stall++; in fc_cn_stats_update()
743 stats->cn_oversubscription++; in fc_cn_stats_update()
746 stats->cn_device_specific++; in fc_cn_stats_update()
751 * fc_fpin_li_stats_update - routine to update Link Integrity
765 u16 event_type = be16_to_cpu(li_desc->event_type); in fc_fpin_li_stats_update()
769 be64_to_cpu(li_desc->attached_wwpn)); in fc_fpin_li_stats_update()
771 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_li_stats_update()
772 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_li_stats_update()
774 fc_li_stats_update(event_type, &attach_rport->fpin_stats); in fc_fpin_li_stats_update()
777 if (be32_to_cpu(li_desc->pname_count) > 0) { in fc_fpin_li_stats_update()
779 i < be32_to_cpu(li_desc->pname_count); in fc_fpin_li_stats_update()
781 wwpn = be64_to_cpu(li_desc->pname_list[i]); in fc_fpin_li_stats_update()
784 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_li_stats_update()
785 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_li_stats_update()
789 &rport->fpin_stats); in fc_fpin_li_stats_update()
794 if (fc_host->port_name == be64_to_cpu(li_desc->attached_wwpn)) in fc_fpin_li_stats_update()
795 fc_li_stats_update(event_type, &fc_host->fpin_stats); in fc_fpin_li_stats_update()
799 * fc_fpin_delivery_stats_update - routine to update Delivery Notification
813 u32 reason_code = be32_to_cpu(dn_desc->deli_reason_code); in fc_fpin_delivery_stats_update()
816 be64_to_cpu(dn_desc->attached_wwpn)); in fc_fpin_delivery_stats_update()
818 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_delivery_stats_update()
819 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_delivery_stats_update()
822 &attach_rport->fpin_stats); in fc_fpin_delivery_stats_update()
825 if (fc_host->port_name == be64_to_cpu(dn_desc->attached_wwpn)) in fc_fpin_delivery_stats_update()
826 fc_delivery_stats_update(reason_code, &fc_host->fpin_stats); in fc_fpin_delivery_stats_update()
830 * fc_fpin_peer_congn_stats_update - routine to update Peer Congestion
845 u16 event_type = be16_to_cpu(pc_desc->event_type); in fc_fpin_peer_congn_stats_update()
849 be64_to_cpu(pc_desc->attached_wwpn)); in fc_fpin_peer_congn_stats_update()
851 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_peer_congn_stats_update()
852 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_peer_congn_stats_update()
854 fc_cn_stats_update(event_type, &attach_rport->fpin_stats); in fc_fpin_peer_congn_stats_update()
857 if (be32_to_cpu(pc_desc->pname_count) > 0) { in fc_fpin_peer_congn_stats_update()
859 i < be32_to_cpu(pc_desc->pname_count); in fc_fpin_peer_congn_stats_update()
861 wwpn = be64_to_cpu(pc_desc->pname_list[i]); in fc_fpin_peer_congn_stats_update()
864 (rport->roles & FC_PORT_ROLE_FCP_TARGET || in fc_fpin_peer_congn_stats_update()
865 rport->roles & FC_PORT_ROLE_NVME_TARGET)) { in fc_fpin_peer_congn_stats_update()
869 &rport->fpin_stats); in fc_fpin_peer_congn_stats_update()
876 * fc_fpin_congn_stats_update - routine to update Congestion
889 fc_cn_stats_update(be16_to_cpu(congn->event_type), in fc_fpin_congn_stats_update()
890 &fc_host->fpin_stats); in fc_fpin_congn_stats_update()
894 * fc_host_fpin_rcv - routine to process a received FPIN.
914 tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0]; in fc_host_fpin_rcv()
915 bytes_remain = fpin_len - offsetof(struct fc_els_fpin, fpin_desc); in fc_host_fpin_rcv()
916 bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len)); in fc_host_fpin_rcv()
920 dtag = be32_to_cpu(tlv->desc_tag); in fc_host_fpin_rcv()
935 bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv); in fc_host_fpin_rcv()
989 struct device_attribute *attr, char *buf) \
993 struct fc_internal *i = to_fc_internal(shost->transportt); \
994 if ((i->f->get_rport_##field) && \
995 !((rport->port_state == FC_PORTSTATE_BLOCKED) || \
996 (rport->port_state == FC_PORTSTATE_DELETED) || \
997 (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \
998 i->f->get_rport_##field(rport); \
999 return snprintf(buf, sz, format_string, cast rport->field); \
1005 struct device_attribute *attr, \
1011 struct fc_internal *i = to_fc_internal(shost->transportt); \
1013 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \
1014 (rport->port_state == FC_PORTSTATE_DELETED) || \
1015 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \
1016 return -EBUSY; \
1019 return -EINVAL; \
1020 i->f->set_rport_##field(rport, val); \
1045 struct device_attribute *attr, char *buf) \
1048 return snprintf(buf, sz, format_string, cast rport->field); \
1065 struct device_attribute *attr, char *buf) \
1068 const char *name; \
1069 name = get_fc_##title##_name(rport->title); \
1070 if (!name) \
1071 return -EINVAL; \
1072 return snprintf(buf, maxlen, "%s\n", name); \
1079 i->private_rport_attrs[count] = device_attr_rport_##field; \
1080 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
1081 i->private_rport_attrs[count].store = NULL; \
1082 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
1083 if (i->f->show_rport_##field) \
1087 i->private_rport_attrs[count] = device_attr_rport_##field; \
1088 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
1089 i->private_rport_attrs[count].store = NULL; \
1090 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
1094 i->private_rport_attrs[count] = device_attr_rport_##field; \
1095 if (!i->f->set_rport_##field) { \
1096 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
1097 i->private_rport_attrs[count].store = NULL; \
1099 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
1100 if (i->f->show_rport_##field) \
1105 i->private_rport_attrs[count] = device_attr_rport_##field; \
1106 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
1119 struct device_attribute *attr, char *buf) in show_fc_rport_supported_classes() argument
1122 if (rport->supported_classes == FC_COS_UNSPECIFIED) in show_fc_rport_supported_classes()
1124 return get_fc_cos_names(rport->supported_classes, buf); in show_fc_rport_supported_classes()
1140 return -EINVAL; in fc_str_to_dev_loss()
1145 return -EINVAL; in fc_str_to_dev_loss()
1154 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_rport_set_dev_loss_tmo()
1156 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || in fc_rport_set_dev_loss_tmo()
1157 (rport->port_state == FC_PORTSTATE_DELETED) || in fc_rport_set_dev_loss_tmo()
1158 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) in fc_rport_set_dev_loss_tmo()
1159 return -EBUSY; in fc_rport_set_dev_loss_tmo()
1164 return -EINVAL; in fc_rport_set_dev_loss_tmo()
1170 if (rport->fast_io_fail_tmo == -1 && in fc_rport_set_dev_loss_tmo()
1172 return -EINVAL; in fc_rport_set_dev_loss_tmo()
1174 i->f->set_rport_dev_loss_tmo(rport, val); in fc_rport_set_dev_loss_tmo()
1180 store_fc_rport_dev_loss_tmo(struct device *dev, struct device_attribute *attr, in store_fc_rport_dev_loss_tmo() argument
1207 show_fc_rport_roles (struct device *dev, struct device_attribute *attr, in show_fc_rport_roles() argument
1213 if ((rport->port_id != -1) && in show_fc_rport_roles()
1214 (rport->port_id & FC_WELLKNOWN_PORTID_MASK) == in show_fc_rport_roles()
1216 switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) { in show_fc_rport_roles()
1231 if (rport->roles == FC_PORT_ROLE_UNKNOWN) in show_fc_rport_roles()
1233 return get_fc_port_roles_names(rport->roles, buf); in show_fc_rport_roles()
1240 struct device_attribute *attr, in fc_rport_set_marginal_state() argument
1249 return -EINVAL; in fc_rport_set_marginal_state()
1254 * Allow only Online->Marginal in fc_rport_set_marginal_state()
1256 if (rport->port_state == FC_PORTSTATE_ONLINE) in fc_rport_set_marginal_state()
1257 rport->port_state = port_state; in fc_rport_set_marginal_state()
1258 else if (port_state != rport->port_state) in fc_rport_set_marginal_state()
1259 return -EINVAL; in fc_rport_set_marginal_state()
1264 * Allow only Marginal->Online in fc_rport_set_marginal_state()
1266 if (rport->port_state == FC_PORTSTATE_MARGINAL) in fc_rport_set_marginal_state()
1267 rport->port_state = port_state; in fc_rport_set_marginal_state()
1268 else if (port_state != rport->port_state) in fc_rport_set_marginal_state()
1269 return -EINVAL; in fc_rport_set_marginal_state()
1271 return -EINVAL; in fc_rport_set_marginal_state()
1277 struct device_attribute *attr, char *buf) in show_fc_rport_port_state() argument
1279 const char *name; in show_fc_rport_port_state() local
1282 name = get_fc_port_state_name(rport->port_state); in show_fc_rport_port_state()
1283 if (!name) in show_fc_rport_port_state()
1284 return -EINVAL; in show_fc_rport_port_state()
1286 return snprintf(buf, 20, "%s\n", name); in show_fc_rport_port_state()
1299 struct device_attribute *attr, char *buf) in show_fc_rport_fast_io_fail_tmo() argument
1303 if (rport->fast_io_fail_tmo == -1) in show_fc_rport_fast_io_fail_tmo()
1305 return snprintf(buf, 20, "%d\n", rport->fast_io_fail_tmo); in show_fc_rport_fast_io_fail_tmo()
1310 struct device_attribute *attr, const char *buf, in store_fc_rport_fast_io_fail_tmo() argument
1317 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || in store_fc_rport_fast_io_fail_tmo()
1318 (rport->port_state == FC_PORTSTATE_DELETED) || in store_fc_rport_fast_io_fail_tmo()
1319 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) in store_fc_rport_fast_io_fail_tmo()
1320 return -EBUSY; in store_fc_rport_fast_io_fail_tmo()
1322 rport->fast_io_fail_tmo = -1; in store_fc_rport_fast_io_fail_tmo()
1326 return -EINVAL; in store_fc_rport_fast_io_fail_tmo()
1331 if ((val >= rport->dev_loss_tmo) || in store_fc_rport_fast_io_fail_tmo()
1333 return -EINVAL; in store_fc_rport_fast_io_fail_tmo()
1335 rport->fast_io_fail_tmo = val; in store_fc_rport_fast_io_fail_tmo()
1342 #define fc_rport_fpin_statistic(name) \ argument
1343 static ssize_t fc_rport_fpinstat_##name(struct device *cd, \
1344 struct device_attribute *attr, \
1349 return snprintf(buf, 20, "0x%llx\n", rport->fpin_stats.name); \
1351 static FC_DEVICE_ATTR(rport, fpin_##name, 0444, fc_rport_fpinstat_##name, NULL)
1375 &device_attr_rport_fpin_dn.attr,
1376 &device_attr_rport_fpin_dn_unknown.attr,
1377 &device_attr_rport_fpin_dn_timeout.attr,
1378 &device_attr_rport_fpin_dn_unable_to_route.attr,
1379 &device_attr_rport_fpin_dn_device_specific.attr,
1380 &device_attr_rport_fpin_li.attr,
1381 &device_attr_rport_fpin_li_failure_unknown.attr,
1382 &device_attr_rport_fpin_li_link_failure_count.attr,
1383 &device_attr_rport_fpin_li_loss_of_sync_count.attr,
1384 &device_attr_rport_fpin_li_loss_of_signals_count.attr,
1385 &device_attr_rport_fpin_li_prim_seq_err_count.attr,
1386 &device_attr_rport_fpin_li_invalid_tx_word_count.attr,
1387 &device_attr_rport_fpin_li_invalid_crc_count.attr,
1388 &device_attr_rport_fpin_li_device_specific.attr,
1389 &device_attr_rport_fpin_cn.attr,
1390 &device_attr_rport_fpin_cn_clear.attr,
1391 &device_attr_rport_fpin_cn_lost_credit.attr,
1392 &device_attr_rport_fpin_cn_credit_stall.attr,
1393 &device_attr_rport_fpin_cn_oversubscription.attr,
1394 &device_attr_rport_fpin_cn_device_specific.attr,
1399 .name = "statistics",
1417 struct device_attribute *attr, char *buf) \
1420 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
1421 struct fc_internal *i = to_fc_internal(shost->transportt); \
1424 fc_starget_##field(starget) = rport->field; \
1425 else if (i->f->get_starget_##field) \
1426 i->f->get_starget_##field(starget); \
1442 i->private_starget_attrs[count] = device_attr_starget_##field; \
1443 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
1444 i->private_starget_attrs[count].store = NULL; \
1445 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
1446 if (i->f->show_starget_##field) \
1450 i->private_starget_attrs[count] = device_attr_starget_##field; \
1451 if (!i->f->set_starget_##field) { \
1452 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
1453 i->private_starget_attrs[count].store = NULL; \
1455 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
1456 if (i->f->show_starget_##field) \
1472 struct device_attribute *attr, char *buf) \
1476 struct fc_internal *i = to_fc_internal(shost->transportt); \
1477 if ((i->f->get_vport_##field) && \
1478 !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))) \
1479 i->f->get_vport_##field(vport); \
1480 return snprintf(buf, sz, format_string, cast vport->field); \
1486 struct device_attribute *attr, \
1492 struct fc_internal *i = to_fc_internal(shost->transportt); \
1494 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \
1495 return -EBUSY; \
1498 return -EINVAL; \
1499 i->f->set_vport_##field(vport, val); \
1506 struct device_attribute *attr, \
1511 struct fc_internal *i = to_fc_internal(shost->transportt); \
1512 unsigned int cnt=count; \
1515 if (buf[cnt-1] == '\n') \
1516 cnt--; \
1517 if (cnt > ((slen) - 1)) \
1518 return -EINVAL; \
1519 memcpy(vport->field, buf, cnt); \
1520 i->f->set_vport_##field(vport); \
1544 struct device_attribute *attr, char *buf) \
1547 return snprintf(buf, sz, format_string, cast vport->field); \
1553 struct device_attribute *attr, \
1559 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \
1560 return -EBUSY; \
1563 return -EINVAL; \
1564 vport->field = val; \
1590 struct device_attribute *attr, \
1594 const char *name; \
1595 name = get_fc_##title##_name(vport->title); \
1596 if (!name) \
1597 return -EINVAL; \
1598 return snprintf(buf, maxlen, "%s\n", name); \
1605 i->private_vport_attrs[count] = device_attr_vport_##field; \
1606 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1607 i->private_vport_attrs[count].store = NULL; \
1608 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1609 if (i->f->get_##field) \
1614 i->private_vport_attrs[count] = device_attr_vport_##field; \
1615 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1616 i->private_vport_attrs[count].store = NULL; \
1617 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1621 i->private_vport_attrs[count] = device_attr_vport_##field; \
1622 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1623 if (i->f->field) \
1628 i->private_vport_attrs[count] = device_attr_vport_##field; \
1629 if (!i->f->set_vport_##field) { \
1630 i->private_vport_attrs[count].attr.mode = S_IRUGO; \
1631 i->private_vport_attrs[count].store = NULL; \
1633 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1639 i->private_vport_attrs[count] = device_attr_vport_##field; \
1640 i->vport_attrs[count] = &i->private_vport_attrs[count]; \
1659 show_fc_vport_roles (struct device *dev, struct device_attribute *attr, in show_fc_vport_roles() argument
1664 if (vport->roles == FC_PORT_ROLE_UNKNOWN) in show_fc_vport_roles()
1666 return get_fc_port_roles_names(vport->roles, buf); in show_fc_vport_roles()
1679 store_fc_vport_delete(struct device *dev, struct device_attribute *attr, in store_fc_vport_delete() argument
1686 spin_lock_irqsave(shost->host_lock, flags); in store_fc_vport_delete()
1687 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) { in store_fc_vport_delete()
1688 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_vport_delete()
1689 return -EBUSY; in store_fc_vport_delete()
1691 vport->flags |= FC_VPORT_DELETING; in store_fc_vport_delete()
1692 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_vport_delete()
1694 fc_queue_work(shost, &vport->vport_delete_work); in store_fc_vport_delete()
1706 store_fc_vport_disable(struct device *dev, struct device_attribute *attr, in store_fc_vport_disable() argument
1712 struct fc_internal *i = to_fc_internal(shost->transportt); in store_fc_vport_disable()
1715 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) in store_fc_vport_disable()
1716 return -EBUSY; in store_fc_vport_disable()
1719 if (vport->vport_state != FC_VPORT_DISABLED) in store_fc_vport_disable()
1720 return -EALREADY; in store_fc_vport_disable()
1722 if (vport->vport_state == FC_VPORT_DISABLED) in store_fc_vport_disable()
1723 return -EALREADY; in store_fc_vport_disable()
1725 return -EINVAL; in store_fc_vport_disable()
1727 stat = i->f->vport_disable(vport, ((*buf == '0') ? false : true)); in store_fc_vport_disable()
1741 struct device_attribute *attr, char *buf) \
1744 struct fc_internal *i = to_fc_internal(shost->transportt); \
1745 if (i->f->get_host_##field) \
1746 i->f->get_host_##field(shost); \
1753 struct device_attribute *attr, \
1758 struct fc_internal *i = to_fc_internal(shost->transportt); \
1763 return -EINVAL; \
1764 i->f->set_host_##field(shost, val); \
1771 struct device_attribute *attr, \
1775 struct fc_internal *i = to_fc_internal(shost->transportt); \
1776 unsigned int cnt=count; \
1779 if (buf[cnt-1] == '\n') \
1780 cnt--; \
1781 if (cnt > ((slen) - 1)) \
1782 return -EINVAL; \
1783 memcpy(fc_host_##field(shost), buf, cnt); \
1784 i->f->set_host_##field(shost); \
1808 struct device_attribute *attr, char *buf) \
1811 struct fc_internal *i = to_fc_internal(shost->transportt); \
1812 const char *name; \
1813 if (i->f->get_host_##title) \
1814 i->f->get_host_##title(shost); \
1815 name = get_fc_##title##_name(fc_host_##title(shost)); \
1816 if (!name) \
1817 return -EINVAL; \
1818 return snprintf(buf, maxlen, "%s\n", name); \
1823 i->private_host_attrs[count] = device_attr_host_##field; \
1824 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1825 i->private_host_attrs[count].store = NULL; \
1826 i->host_attrs[count] = &i->private_host_attrs[count]; \
1827 if (i->f->show_host_##field) \
1831 i->private_host_attrs[count] = device_attr_host_##field; \
1832 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1833 i->private_host_attrs[count].store = NULL; \
1834 i->host_attrs[count] = &i->private_host_attrs[count]; \
1838 i->private_host_attrs[count] = device_attr_host_##field; \
1839 if (!i->f->set_host_##field) { \
1840 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1841 i->private_host_attrs[count].store = NULL; \
1843 i->host_attrs[count] = &i->private_host_attrs[count]; \
1844 if (i->f->show_host_##field) \
1851 struct device_attribute *attr, char *buf) \
1868 i->private_host_attrs[count] = device_attr_host_##field; \
1869 i->private_host_attrs[count].attr.mode = S_IRUGO; \
1870 i->private_host_attrs[count].store = NULL; \
1871 i->host_attrs[count] = &i->private_host_attrs[count]; \
1876 i->private_host_attrs[count] = device_attr_host_##field; \
1877 i->host_attrs[count] = &i->private_host_attrs[count]; \
1886 struct device_attribute *attr, char *buf) in show_fc_host_supported_classes() argument
1900 struct device_attribute *attr, char *buf) in show_fc_host_supported_fc4s() argument
1910 struct device_attribute *attr, char *buf) in show_fc_host_supported_speeds() argument
1943 struct device_attribute *attr, char *buf) in show_fc_host_active_fc4s() argument
1946 struct fc_internal *i = to_fc_internal(shost->transportt); in show_fc_host_active_fc4s()
1948 if (i->f->get_host_active_fc4s) in show_fc_host_active_fc4s()
1949 i->f->get_host_active_fc4s(shost); in show_fc_host_active_fc4s()
1958 struct device_attribute *attr, char *buf) in show_fc_host_speed() argument
1961 struct fc_internal *i = to_fc_internal(shost->transportt); in show_fc_host_speed()
1963 if (i->f->get_host_speed) in show_fc_host_speed()
1964 i->f->get_host_speed(shost); in show_fc_host_speed()
1992 struct device_attribute *attr, char *buf) in show_fc_private_host_tgtid_bind_type() argument
1995 const char *name; in show_fc_private_host_tgtid_bind_type() local
1997 name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost)); in show_fc_private_host_tgtid_bind_type()
1998 if (!name) in show_fc_private_host_tgtid_bind_type()
1999 return -EINVAL; in show_fc_private_host_tgtid_bind_type()
2000 return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name); in show_fc_private_host_tgtid_bind_type()
2004 pos = list_entry((head)->next, typeof(*pos), member)
2008 struct device_attribute *attr, const char *buf, size_t count) in store_fc_private_host_tgtid_bind_type() argument
2016 return -EINVAL; in store_fc_private_host_tgtid_bind_type()
2020 spin_lock_irqsave(shost->host_lock, flags); in store_fc_private_host_tgtid_bind_type()
2024 list_del(&rport->peers); in store_fc_private_host_tgtid_bind_type()
2025 rport->port_state = FC_PORTSTATE_DELETED; in store_fc_private_host_tgtid_bind_type()
2026 fc_queue_work(shost, &rport->rport_delete_work); in store_fc_private_host_tgtid_bind_type()
2028 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_private_host_tgtid_bind_type()
2041 struct device_attribute *attr, const char *buf, size_t count) in store_fc_private_host_issue_lip() argument
2044 struct fc_internal *i = to_fc_internal(shost->transportt); in store_fc_private_host_issue_lip()
2048 if (i->f->issue_fc_host_lip) { in store_fc_private_host_issue_lip()
2049 ret = i->f->issue_fc_host_lip(shost); in store_fc_private_host_issue_lip()
2053 return -ENOENT; in store_fc_private_host_issue_lip()
2061 struct device_attribute *attr, in store_fc_private_host_dev_loss_tmo() argument
2075 spin_lock_irqsave(shost->host_lock, flags); in store_fc_private_host_dev_loss_tmo()
2076 list_for_each_entry(rport, &fc_host->rports, peers) in store_fc_private_host_dev_loss_tmo()
2078 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_private_host_dev_loss_tmo()
2098 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_stat_show()
2100 ssize_t ret = -ENOENT; in fc_stat_show()
2106 if (i->f->get_fc_host_stats) { in fc_stat_show()
2107 stats = (i->f->get_fc_host_stats)(shost); in fc_stat_show()
2116 /* generate a read-only statistics attribute */
2117 #define fc_host_statistic(name) \ argument
2118 static ssize_t show_fcstat_##name(struct device *cd, \
2119 struct device_attribute *attr, \
2123 offsetof(struct fc_host_statistics, name)); \
2125 static FC_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
2160 #define fc_host_fpin_statistic(name) \ argument
2161 static ssize_t fc_host_fpinstat_##name(struct device *cd, \
2162 struct device_attribute *attr, \
2168 return snprintf(buf, 20, "0x%llx\n", fc_host->fpin_stats.name); \
2170 static FC_DEVICE_ATTR(host, fpin_##name, 0444, fc_host_fpinstat_##name, NULL)
2194 fc_reset_statistics(struct device *dev, struct device_attribute *attr, in fc_reset_statistics() argument
2198 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_reset_statistics()
2201 if (i->f->reset_fc_host_stats) { in fc_reset_statistics()
2202 i->f->reset_fc_host_stats(shost); in fc_reset_statistics()
2206 return -ENOENT; in fc_reset_statistics()
2212 &device_attr_host_seconds_since_last_reset.attr,
2213 &device_attr_host_tx_frames.attr,
2214 &device_attr_host_tx_words.attr,
2215 &device_attr_host_rx_frames.attr,
2216 &device_attr_host_rx_words.attr,
2217 &device_attr_host_lip_count.attr,
2218 &device_attr_host_nos_count.attr,
2219 &device_attr_host_error_frames.attr,
2220 &device_attr_host_dumped_frames.attr,
2221 &device_attr_host_link_failure_count.attr,
2222 &device_attr_host_loss_of_sync_count.attr,
2223 &device_attr_host_loss_of_signal_count.attr,
2224 &device_attr_host_prim_seq_protocol_err_count.attr,
2225 &device_attr_host_invalid_tx_word_count.attr,
2226 &device_attr_host_invalid_crc_count.attr,
2227 &device_attr_host_fcp_input_requests.attr,
2228 &device_attr_host_fcp_output_requests.attr,
2229 &device_attr_host_fcp_control_requests.attr,
2230 &device_attr_host_fcp_input_megabytes.attr,
2231 &device_attr_host_fcp_output_megabytes.attr,
2232 &device_attr_host_fcp_packet_alloc_failures.attr,
2233 &device_attr_host_fcp_packet_aborts.attr,
2234 &device_attr_host_fcp_frame_alloc_failures.attr,
2235 &device_attr_host_fc_no_free_exch.attr,
2236 &device_attr_host_fc_no_free_exch_xid.attr,
2237 &device_attr_host_fc_xid_not_found.attr,
2238 &device_attr_host_fc_xid_busy.attr,
2239 &device_attr_host_fc_seq_not_found.attr,
2240 &device_attr_host_fc_non_bls_resp.attr,
2241 &device_attr_host_cn_sig_warn.attr,
2242 &device_attr_host_cn_sig_alarm.attr,
2243 &device_attr_host_reset_statistics.attr,
2244 &device_attr_host_fpin_dn.attr,
2245 &device_attr_host_fpin_dn_unknown.attr,
2246 &device_attr_host_fpin_dn_timeout.attr,
2247 &device_attr_host_fpin_dn_unable_to_route.attr,
2248 &device_attr_host_fpin_dn_device_specific.attr,
2249 &device_attr_host_fpin_li.attr,
2250 &device_attr_host_fpin_li_failure_unknown.attr,
2251 &device_attr_host_fpin_li_link_failure_count.attr,
2252 &device_attr_host_fpin_li_loss_of_sync_count.attr,
2253 &device_attr_host_fpin_li_loss_of_signals_count.attr,
2254 &device_attr_host_fpin_li_prim_seq_err_count.attr,
2255 &device_attr_host_fpin_li_invalid_tx_word_count.attr,
2256 &device_attr_host_fpin_li_invalid_crc_count.attr,
2257 &device_attr_host_fpin_li_device_specific.attr,
2258 &device_attr_host_fpin_cn.attr,
2259 &device_attr_host_fpin_cn_clear.attr,
2260 &device_attr_host_fpin_cn_lost_credit.attr,
2261 &device_attr_host_fpin_cn_credit_stall.attr,
2262 &device_attr_host_fpin_cn_oversubscription.attr,
2263 &device_attr_host_fpin_cn_device_specific.attr,
2268 .name = "statistics",
2283 /* Validate and store the new name */ in fc_parse_wwn()
2291 return -EINVAL; in fc_parse_wwn()
2305 * "Short-cut" sysfs variable to create a new vport on a FC Host.
2307 * will default to a NPIV-based FCP_Initiator; The WWNs are specified
2311 store_fc_host_vport_create(struct device *dev, struct device_attribute *attr, in store_fc_host_vport_create() argument
2317 unsigned int cnt=count; in store_fc_host_vport_create() local
2323 if (buf[cnt-1] == '\n') in store_fc_host_vport_create()
2324 cnt--; in store_fc_host_vport_create()
2327 if ((cnt != (16+1+16)) || (buf[16] != ':')) in store_fc_host_vport_create()
2328 return -EINVAL; in store_fc_host_vport_create()
2344 stat = fc_vport_setup(shost, 0, &shost->shost_gendev, &vid, &vport); in store_fc_host_vport_create()
2352 * "Short-cut" sysfs variable to delete a vport on a FC Host.
2358 store_fc_host_vport_delete(struct device *dev, struct device_attribute *attr, in store_fc_host_vport_delete() argument
2366 unsigned int cnt=count; in store_fc_host_vport_delete() local
2370 if (buf[cnt-1] == '\n') in store_fc_host_vport_delete()
2371 cnt--; in store_fc_host_vport_delete()
2374 if ((cnt != (16+1+16)) || (buf[16] != ':')) in store_fc_host_vport_delete()
2375 return -EINVAL; in store_fc_host_vport_delete()
2385 spin_lock_irqsave(shost->host_lock, flags); in store_fc_host_vport_delete()
2388 list_for_each_entry(vport, &fc_host->vports, peers) { in store_fc_host_vport_delete()
2389 if ((vport->channel == 0) && in store_fc_host_vport_delete()
2390 (vport->port_name == wwpn) && (vport->node_name == wwnn)) { in store_fc_host_vport_delete()
2391 if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) in store_fc_host_vport_delete()
2393 vport->flags |= FC_VPORT_DELETING; in store_fc_host_vport_delete()
2398 spin_unlock_irqrestore(shost->host_lock, flags); in store_fc_host_vport_delete()
2401 return -ENODEV; in store_fc_host_vport_delete()
2420 if (!shost->transportt || shost->transportt->host_attrs.ac.class in fc_host_match()
2424 i = to_fc_internal(shost->transportt); in fc_host_match()
2426 return &i->t.host_attrs.ac == cont; in fc_host_match()
2438 shost = dev_to_shost(dev->parent); in fc_target_match()
2439 if (!shost->transportt || shost->transportt->host_attrs.ac.class in fc_target_match()
2443 i = to_fc_internal(shost->transportt); in fc_target_match()
2445 return &i->t.target_attrs.ac == cont; in fc_target_match()
2451 put_device(dev->parent); in fc_rport_dev_release()
2457 return dev->release == fc_rport_dev_release; in scsi_is_fc_rport()
2470 shost = dev_to_shost(dev->parent); in fc_rport_match()
2471 if (!shost->transportt || shost->transportt->host_attrs.ac.class in fc_rport_match()
2475 i = to_fc_internal(shost->transportt); in fc_rport_match()
2477 return &i->rport_attr_cont.ac == cont; in fc_rport_match()
2484 put_device(dev->parent); /* release kobj parent */ in fc_vport_dev_release()
2490 return dev->release == fc_vport_dev_release; in scsi_is_fc_vport()
2505 if (!shost->transportt || shost->transportt->host_attrs.ac.class in fc_vport_match()
2509 i = to_fc_internal(shost->transportt); in fc_vport_match()
2510 return &i->vport_attr_cont.ac == cont; in fc_vport_match()
2515 * fc_eh_timed_out - FC Transport I/O timeout intercept handler
2538 struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device)); in fc_eh_timed_out()
2540 if (rport->port_state == FC_PORTSTATE_BLOCKED) in fc_eh_timed_out()
2558 spin_lock_irqsave(shost->host_lock, flags); in fc_user_scan_tgt()
2561 if (rport->scsi_target_id == -1) in fc_user_scan_tgt()
2564 if ((rport->port_state != FC_PORTSTATE_ONLINE) && in fc_user_scan_tgt()
2565 (rport->port_state != FC_PORTSTATE_MARGINAL)) in fc_user_scan_tgt()
2568 if ((channel == rport->channel) && in fc_user_scan_tgt()
2569 (id == rport->scsi_target_id)) { in fc_user_scan_tgt()
2570 spin_unlock_irqrestore(shost->host_lock, flags); in fc_user_scan_tgt()
2571 scsi_scan_target(&rport->dev, channel, id, lun, in fc_user_scan_tgt()
2577 spin_unlock_irqrestore(shost->host_lock, flags); in fc_user_scan_tgt()
2592 if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) || in fc_user_scan()
2593 ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) || in fc_user_scan()
2594 ((lun != SCAN_WILD_CARD) && (lun > shost->max_lun))) in fc_user_scan()
2595 return -EINVAL; in fc_user_scan()
2599 chhi = shost->max_channel + 1; in fc_user_scan()
2607 tgthi = shost->max_id; in fc_user_scan()
2630 i->t.target_attrs.ac.attrs = &i->starget_attrs[0]; in fc_attach_transport()
2631 i->t.target_attrs.ac.class = &fc_transport_class.class; in fc_attach_transport()
2632 i->t.target_attrs.ac.match = fc_target_match; in fc_attach_transport()
2633 i->t.target_size = sizeof(struct fc_starget_attrs); in fc_attach_transport()
2634 transport_container_register(&i->t.target_attrs); in fc_attach_transport()
2636 i->t.host_attrs.ac.attrs = &i->host_attrs[0]; in fc_attach_transport()
2637 i->t.host_attrs.ac.class = &fc_host_class.class; in fc_attach_transport()
2638 i->t.host_attrs.ac.match = fc_host_match; in fc_attach_transport()
2639 i->t.host_size = sizeof(struct fc_host_attrs); in fc_attach_transport()
2640 if (ft->get_fc_host_stats) in fc_attach_transport()
2641 i->t.host_attrs.statistics = &fc_statistics_group; in fc_attach_transport()
2642 transport_container_register(&i->t.host_attrs); in fc_attach_transport()
2644 i->rport_attr_cont.ac.attrs = &i->rport_attrs[0]; in fc_attach_transport()
2645 i->rport_attr_cont.ac.class = &fc_rport_class.class; in fc_attach_transport()
2646 i->rport_attr_cont.ac.match = fc_rport_match; in fc_attach_transport()
2647 i->rport_attr_cont.statistics = &fc_rport_statistics_group; in fc_attach_transport()
2648 transport_container_register(&i->rport_attr_cont); in fc_attach_transport()
2650 i->vport_attr_cont.ac.attrs = &i->vport_attrs[0]; in fc_attach_transport()
2651 i->vport_attr_cont.ac.class = &fc_vport_class.class; in fc_attach_transport()
2652 i->vport_attr_cont.ac.match = fc_vport_match; in fc_attach_transport()
2653 transport_container_register(&i->vport_attr_cont); in fc_attach_transport()
2655 i->f = ft; in fc_attach_transport()
2658 i->t.create_work_queue = 1; in fc_attach_transport()
2660 i->t.user_scan = fc_user_scan; in fc_attach_transport()
2672 i->starget_attrs[count] = NULL; in fc_attach_transport()
2686 if (ft->vport_create) { in fc_attach_transport()
2708 /* Transport-managed attributes */ in fc_attach_transport()
2711 if (ft->issue_fc_host_lip) in fc_attach_transport()
2713 if (ft->vport_create) in fc_attach_transport()
2715 if (ft->vport_delete) in fc_attach_transport()
2720 i->host_attrs[count] = NULL; in fc_attach_transport()
2739 i->rport_attrs[count] = NULL; in fc_attach_transport()
2757 i->vport_attrs[count] = NULL; in fc_attach_transport()
2759 return &i->t; in fc_attach_transport()
2767 transport_container_unregister(&i->t.target_attrs); in fc_release_transport()
2768 transport_container_unregister(&i->t.host_attrs); in fc_release_transport()
2769 transport_container_unregister(&i->rport_attr_cont); in fc_release_transport()
2770 transport_container_unregister(&i->vport_attr_cont); in fc_release_transport()
2777 * fc_queue_work - Queue work to the fc_host workqueue.
2782 * 1 - work queued for execution
2783 * 0 - work is already queued
2784 * -EINVAL - work queue doesn't exist
2792 "when no workqueue created.\n", shost->hostt->name); in fc_queue_work()
2795 return -EINVAL; in fc_queue_work()
2802 * fc_flush_work - Flush a fc_host's workqueue.
2811 "when no workqueue created.\n", shost->hostt->name); in fc_flush_work()
2820 * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue.
2835 "when no workqueue created.\n", shost->hostt->name); in fc_queue_devloss_work()
2838 return -EINVAL; in fc_queue_devloss_work()
2845 * fc_flush_devloss - Flush a fc_host's devloss workqueue.
2854 "when no workqueue created.\n", shost->hostt->name); in fc_flush_devloss()
2864 * fc_remove_host - called to terminate any fc_transport-related elements for a scsi host.
2887 spin_lock_irqsave(shost->host_lock, flags); in fc_remove_host()
2890 list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers) { in fc_remove_host()
2891 vport->flags |= FC_VPORT_DELETING; in fc_remove_host()
2892 fc_queue_work(shost, &vport->vport_delete_work); in fc_remove_host()
2897 &fc_host->rports, peers) { in fc_remove_host()
2898 list_del(&rport->peers); in fc_remove_host()
2899 rport->port_state = FC_PORTSTATE_DELETED; in fc_remove_host()
2900 fc_queue_work(shost, &rport->rport_delete_work); in fc_remove_host()
2904 &fc_host->rport_bindings, peers) { in fc_remove_host()
2905 list_del(&rport->peers); in fc_remove_host()
2906 rport->port_state = FC_PORTSTATE_DELETED; in fc_remove_host()
2907 fc_queue_work(shost, &rport->rport_delete_work); in fc_remove_host()
2910 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remove_host()
2916 if (fc_host->work_q) { in fc_remove_host()
2917 work_q = fc_host->work_q; in fc_remove_host()
2918 fc_host->work_q = NULL; in fc_remove_host()
2923 if (fc_host->devloss_work_q) { in fc_remove_host()
2924 work_q = fc_host->devloss_work_q; in fc_remove_host()
2925 fc_host->devloss_work_q = NULL; in fc_remove_host()
2934 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_terminate_rport_io()
2937 if (i->f->terminate_rport_io) in fc_terminate_rport_io()
2938 i->f->terminate_rport_io(rport); in fc_terminate_rport_io()
2941 * Must unblock to flush queued IO. scsi-ml will fail incoming reqs. in fc_terminate_rport_io()
2943 scsi_target_unblock(&rport->dev, SDEV_TRANSPORT_OFFLINE); in fc_terminate_rport_io()
2947 * fc_starget_delete - called to delete the scsi descendants of an rport
2959 scsi_remove_target(&rport->dev); in fc_starget_delete()
2964 * fc_rport_final_delete - finish rport termination and delete it.
2972 struct device *dev = &rport->dev; in fc_rport_final_delete()
2974 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_rport_final_delete()
2984 if (rport->flags & FC_RPORT_SCAN_PENDING) in fc_rport_final_delete()
2992 spin_lock_irqsave(shost->host_lock, flags); in fc_rport_final_delete()
2993 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) { in fc_rport_final_delete()
2994 spin_unlock_irqrestore(shost->host_lock, flags); in fc_rport_final_delete()
2995 if (!cancel_delayed_work(&rport->fail_io_work)) in fc_rport_final_delete()
2997 if (!cancel_delayed_work(&rport->dev_loss_work)) in fc_rport_final_delete()
2999 cancel_work_sync(&rport->scan_work); in fc_rport_final_delete()
3000 spin_lock_irqsave(shost->host_lock, flags); in fc_rport_final_delete()
3001 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; in fc_rport_final_delete()
3003 spin_unlock_irqrestore(shost->host_lock, flags); in fc_rport_final_delete()
3006 if (rport->scsi_target_id != -1) in fc_rport_final_delete()
3007 fc_starget_delete(&rport->stgt_delete_work); in fc_rport_final_delete()
3016 spin_lock_irqsave(shost->host_lock, flags); in fc_rport_final_delete()
3017 if (!(rport->flags & FC_RPORT_DEVLOSS_CALLBK_DONE) && in fc_rport_final_delete()
3018 (i->f->dev_loss_tmo_callbk)) { in fc_rport_final_delete()
3019 rport->flags |= FC_RPORT_DEVLOSS_CALLBK_DONE; in fc_rport_final_delete()
3022 spin_unlock_irqrestore(shost->host_lock, flags); in fc_rport_final_delete()
3025 i->f->dev_loss_tmo_callbk(rport); in fc_rport_final_delete()
3027 fc_bsg_remove(rport->rqst_q); in fc_rport_final_delete()
3032 scsi_host_put(shost); /* for fc_host->rport list */ in fc_rport_final_delete()
3033 put_device(dev); /* for self-reference */ in fc_rport_final_delete()
3038 * fc_remote_port_create - allocates and creates a remote FC port.
3055 struct fc_internal *fci = to_fc_internal(shost->transportt); in fc_remote_port_create()
3062 size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size); in fc_remote_port_create()
3069 rport->maxframe_size = -1; in fc_remote_port_create()
3070 rport->supported_classes = FC_COS_UNSPECIFIED; in fc_remote_port_create()
3071 rport->dev_loss_tmo = fc_host->dev_loss_tmo; in fc_remote_port_create()
3072 memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name)); in fc_remote_port_create()
3073 memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name)); in fc_remote_port_create()
3074 rport->port_id = ids->port_id; in fc_remote_port_create()
3075 rport->roles = ids->roles; in fc_remote_port_create()
3076 rport->port_state = FC_PORTSTATE_ONLINE; in fc_remote_port_create()
3077 if (fci->f->dd_fcrport_size) in fc_remote_port_create()
3078 rport->dd_data = &rport[1]; in fc_remote_port_create()
3079 rport->channel = channel; in fc_remote_port_create()
3080 rport->fast_io_fail_tmo = -1; in fc_remote_port_create()
3082 INIT_DELAYED_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport); in fc_remote_port_create()
3083 INIT_DELAYED_WORK(&rport->fail_io_work, fc_timeout_fail_rport_io); in fc_remote_port_create()
3084 INIT_WORK(&rport->scan_work, fc_scsi_scan_rport); in fc_remote_port_create()
3085 INIT_WORK(&rport->stgt_delete_work, fc_starget_delete); in fc_remote_port_create()
3086 INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete); in fc_remote_port_create()
3088 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_create()
3090 rport->number = fc_host->next_rport_number++; in fc_remote_port_create()
3091 if ((rport->roles & FC_PORT_ROLE_FCP_TARGET) || in fc_remote_port_create()
3092 (rport->roles & FC_PORT_ROLE_FCP_DUMMY_INITIATOR)) in fc_remote_port_create()
3093 rport->scsi_target_id = fc_host->next_target_id++; in fc_remote_port_create()
3095 rport->scsi_target_id = -1; in fc_remote_port_create()
3096 list_add_tail(&rport->peers, &fc_host->rports); in fc_remote_port_create()
3097 scsi_host_get(shost); /* for fc_host->rport list */ in fc_remote_port_create()
3099 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_create()
3101 dev = &rport->dev; in fc_remote_port_create()
3103 dev->parent = get_device(&shost->shost_gendev); /* parent reference */ in fc_remote_port_create()
3104 dev->release = fc_rport_dev_release; in fc_remote_port_create()
3105 dev_set_name(dev, "rport-%d:%d-%d", in fc_remote_port_create()
3106 shost->host_no, channel, rport->number); in fc_remote_port_create()
3118 /* ignore any bsg add error - we just can't do sgio */ in fc_remote_port_create()
3120 if (rport->roles & FC_PORT_ROLE_FCP_TARGET) { in fc_remote_port_create()
3122 rport->flags |= FC_RPORT_SCAN_PENDING; in fc_remote_port_create()
3123 scsi_queue_work(shost, &rport->scan_work); in fc_remote_port_create()
3130 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_create()
3131 list_del(&rport->peers); in fc_remote_port_create()
3132 scsi_host_put(shost); /* for fc_host->rport list */ in fc_remote_port_create()
3133 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_create()
3134 put_device(dev->parent); in fc_remote_port_create()
3140 * fc_remote_port_add - notify fc transport of the existence of a remote FC port.
3160 * the scsi host. If the host detaches, then later re-attaches, target
3181 struct fc_internal *fci = to_fc_internal(shost->transportt); in fc_remote_port_add()
3195 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_add()
3197 list_for_each_entry(rport, &fc_host->rports, peers) { in fc_remote_port_add()
3199 if ((rport->port_state == FC_PORTSTATE_BLOCKED || in fc_remote_port_add()
3200 rport->port_state == FC_PORTSTATE_NOTPRESENT) && in fc_remote_port_add()
3201 (rport->channel == channel)) { in fc_remote_port_add()
3203 switch (fc_host->tgtid_bind_type) { in fc_remote_port_add()
3206 if (rport->port_name == ids->port_name) in fc_remote_port_add()
3210 if (rport->node_name == ids->node_name) in fc_remote_port_add()
3214 if (rport->port_id == ids->port_id) in fc_remote_port_add()
3221 memcpy(&rport->node_name, &ids->node_name, in fc_remote_port_add()
3222 sizeof(rport->node_name)); in fc_remote_port_add()
3223 memcpy(&rport->port_name, &ids->port_name, in fc_remote_port_add()
3224 sizeof(rport->port_name)); in fc_remote_port_add()
3225 rport->port_id = ids->port_id; in fc_remote_port_add()
3227 rport->port_state = FC_PORTSTATE_ONLINE; in fc_remote_port_add()
3228 rport->roles = ids->roles; in fc_remote_port_add()
3230 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_add()
3232 if (fci->f->dd_fcrport_size) in fc_remote_port_add()
3233 memset(rport->dd_data, 0, in fc_remote_port_add()
3234 fci->f->dd_fcrport_size); in fc_remote_port_add()
3253 if ((rport->scsi_target_id != -1) && in fc_remote_port_add()
3254 (!(ids->roles & FC_PORT_ROLE_FCP_TARGET))) in fc_remote_port_add()
3262 if (!cancel_delayed_work(&rport->fail_io_work)) in fc_remote_port_add()
3264 if (!cancel_delayed_work(&rport->dev_loss_work)) in fc_remote_port_add()
3267 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_add()
3269 rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT | in fc_remote_port_add()
3273 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_add()
3276 if (rport->scsi_target_id != -1) { in fc_remote_port_add()
3277 scsi_target_unblock(&rport->dev, in fc_remote_port_add()
3279 spin_lock_irqsave(shost->host_lock, in fc_remote_port_add()
3281 rport->flags |= FC_RPORT_SCAN_PENDING; in fc_remote_port_add()
3283 &rport->scan_work); in fc_remote_port_add()
3284 spin_unlock_irqrestore(shost->host_lock, in fc_remote_port_add()
3299 if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) { in fc_remote_port_add()
3303 list_for_each_entry(rport, &fc_host->rport_bindings, in fc_remote_port_add()
3305 if (rport->channel != channel) in fc_remote_port_add()
3308 switch (fc_host->tgtid_bind_type) { in fc_remote_port_add()
3310 if (rport->port_name == ids->port_name) in fc_remote_port_add()
3314 if (rport->node_name == ids->node_name) in fc_remote_port_add()
3318 if (rport->port_id == ids->port_id) in fc_remote_port_add()
3326 list_move_tail(&rport->peers, &fc_host->rports); in fc_remote_port_add()
3332 memcpy(&rport->node_name, &ids->node_name, in fc_remote_port_add()
3333 sizeof(rport->node_name)); in fc_remote_port_add()
3334 memcpy(&rport->port_name, &ids->port_name, in fc_remote_port_add()
3335 sizeof(rport->port_name)); in fc_remote_port_add()
3336 rport->port_id = ids->port_id; in fc_remote_port_add()
3337 rport->port_state = FC_PORTSTATE_ONLINE; in fc_remote_port_add()
3338 rport->flags &= ~FC_RPORT_FAST_FAIL_TIMEDOUT; in fc_remote_port_add()
3340 if (fci->f->dd_fcrport_size) in fc_remote_port_add()
3341 memset(rport->dd_data, 0, in fc_remote_port_add()
3342 fci->f->dd_fcrport_size); in fc_remote_port_add()
3343 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_add()
3345 fc_remote_port_rolechg(rport, ids->roles); in fc_remote_port_add()
3350 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_add()
3352 /* No consistent binding found - create new remote port entry */ in fc_remote_port_add()
3361 * fc_remote_port_delete - notifies the fc transport that a remote port is no longer in existence.
3376 * attached to it. However, we want to semi-persist the target id assigned
3392 * scsi target is removed - killing all outstanding i/o and removing the
3407 * Called from normal process context only - cannot be called from interrupt.
3416 unsigned long timeout = rport->dev_loss_tmo; in fc_remote_port_delete()
3427 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_delete()
3429 if ((rport->port_state != FC_PORTSTATE_ONLINE) && in fc_remote_port_delete()
3430 (rport->port_state != FC_PORTSTATE_MARGINAL)) { in fc_remote_port_delete()
3431 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_delete()
3436 * In the past, we if this was not an FCP-Target, we would in fc_remote_port_delete()
3441 * send ELS traffic to re-validate the login. If the rport is in fc_remote_port_delete()
3448 rport->port_state = FC_PORTSTATE_BLOCKED; in fc_remote_port_delete()
3450 rport->flags |= FC_RPORT_DEVLOSS_PENDING; in fc_remote_port_delete()
3452 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_delete()
3454 scsi_block_targets(shost, &rport->dev); in fc_remote_port_delete()
3457 if ((rport->fast_io_fail_tmo != -1) && in fc_remote_port_delete()
3458 (rport->fast_io_fail_tmo < timeout)) in fc_remote_port_delete()
3459 fc_queue_devloss_work(shost, &rport->fail_io_work, in fc_remote_port_delete()
3460 rport->fast_io_fail_tmo * HZ); in fc_remote_port_delete()
3463 fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ); in fc_remote_port_delete()
3468 * fc_remote_port_rolechg - notifies the fc transport that the roles on a remote may have changed.
3495 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_rolechg()
3497 if (rport->scsi_target_id == -1) { in fc_remote_port_rolechg()
3498 rport->scsi_target_id = fc_host->next_target_id++; in fc_remote_port_rolechg()
3500 } else if (!(rport->roles & FC_PORT_ROLE_FCP_TARGET)) in fc_remote_port_rolechg()
3504 rport->roles = roles; in fc_remote_port_rolechg()
3506 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_rolechg()
3521 if (!cancel_delayed_work(&rport->fail_io_work)) in fc_remote_port_rolechg()
3523 if (!cancel_delayed_work(&rport->dev_loss_work)) in fc_remote_port_rolechg()
3526 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_rolechg()
3527 rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT | in fc_remote_port_rolechg()
3530 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_rolechg()
3535 scsi_target_unblock(&rport->dev, SDEV_RUNNING); in fc_remote_port_rolechg()
3537 spin_lock_irqsave(shost->host_lock, flags); in fc_remote_port_rolechg()
3538 rport->flags |= FC_RPORT_SCAN_PENDING; in fc_remote_port_rolechg()
3539 scsi_queue_work(shost, &rport->scan_work); in fc_remote_port_rolechg()
3540 spin_unlock_irqrestore(shost->host_lock, flags); in fc_remote_port_rolechg()
3546 * fc_timeout_deleted_rport - Timeout handler for a deleted remote port.
3558 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_timeout_deleted_rport()
3563 spin_lock_irqsave(shost->host_lock, flags); in fc_timeout_deleted_rport()
3565 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; in fc_timeout_deleted_rport()
3572 if (((rport->port_state == FC_PORTSTATE_ONLINE) || in fc_timeout_deleted_rport()
3573 (rport->port_state == FC_PORTSTATE_MARGINAL)) && in fc_timeout_deleted_rport()
3574 (rport->scsi_target_id != -1) && in fc_timeout_deleted_rport()
3575 !(rport->roles & FC_PORT_ROLE_FCP_TARGET)) { in fc_timeout_deleted_rport()
3576 dev_printk(KERN_ERR, &rport->dev, in fc_timeout_deleted_rport()
3579 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3580 scsi_target_unblock(&rport->dev, SDEV_TRANSPORT_OFFLINE); in fc_timeout_deleted_rport()
3581 fc_queue_work(shost, &rport->stgt_delete_work); in fc_timeout_deleted_rport()
3585 /* NOOP state - we're flushing workq's */ in fc_timeout_deleted_rport()
3586 if (rport->port_state != FC_PORTSTATE_BLOCKED) { in fc_timeout_deleted_rport()
3587 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3588 dev_printk(KERN_ERR, &rport->dev, in fc_timeout_deleted_rport()
3591 (rport->scsi_target_id != -1) ? " and starget" : ""); in fc_timeout_deleted_rport()
3595 if ((fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) || in fc_timeout_deleted_rport()
3596 (rport->scsi_target_id == -1)) { in fc_timeout_deleted_rport()
3597 list_del(&rport->peers); in fc_timeout_deleted_rport()
3598 rport->port_state = FC_PORTSTATE_DELETED; in fc_timeout_deleted_rport()
3599 dev_printk(KERN_ERR, &rport->dev, in fc_timeout_deleted_rport()
3602 (rport->scsi_target_id != -1) ? " and starget" : ""); in fc_timeout_deleted_rport()
3603 fc_queue_work(shost, &rport->rport_delete_work); in fc_timeout_deleted_rport()
3604 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3608 dev_printk(KERN_ERR, &rport->dev, in fc_timeout_deleted_rport()
3612 list_move_tail(&rport->peers, &fc_host->rport_bindings); in fc_timeout_deleted_rport()
3616 * host-specific target data to persist along with the in fc_timeout_deleted_rport()
3623 rport->maxframe_size = -1; in fc_timeout_deleted_rport()
3624 rport->supported_classes = FC_COS_UNSPECIFIED; in fc_timeout_deleted_rport()
3625 rport->roles = FC_PORT_ROLE_UNKNOWN; in fc_timeout_deleted_rport()
3626 rport->port_state = FC_PORTSTATE_NOTPRESENT; in fc_timeout_deleted_rport()
3627 rport->flags &= ~FC_RPORT_FAST_FAIL_TIMEDOUT; in fc_timeout_deleted_rport()
3630 * Pre-emptively kill I/O rather than waiting for the work queue in fc_timeout_deleted_rport()
3634 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3637 spin_lock_irqsave(shost->host_lock, flags); in fc_timeout_deleted_rport()
3639 if (rport->port_state == FC_PORTSTATE_NOTPRESENT) { /* still missing */ in fc_timeout_deleted_rport()
3642 switch (fc_host->tgtid_bind_type) { in fc_timeout_deleted_rport()
3644 rport->node_name = -1; in fc_timeout_deleted_rport()
3645 rport->port_id = -1; in fc_timeout_deleted_rport()
3648 rport->port_name = -1; in fc_timeout_deleted_rport()
3649 rport->port_id = -1; in fc_timeout_deleted_rport()
3652 rport->node_name = -1; in fc_timeout_deleted_rport()
3653 rport->port_name = -1; in fc_timeout_deleted_rport()
3661 * went away and didn't come back - we'll remove in fc_timeout_deleted_rport()
3664 rport->flags |= FC_RPORT_DEVLOSS_CALLBK_DONE; in fc_timeout_deleted_rport()
3665 fc_queue_work(shost, &rport->stgt_delete_work); in fc_timeout_deleted_rport()
3670 spin_unlock_irqrestore(shost->host_lock, flags); in fc_timeout_deleted_rport()
3678 if (do_callback && i->f->dev_loss_tmo_callbk) in fc_timeout_deleted_rport()
3679 i->f->dev_loss_tmo_callbk(rport); in fc_timeout_deleted_rport()
3684 * fc_timeout_fail_rport_io - Timeout handler for a fast io failing on a disconnected SCSI target.
3696 if (rport->port_state != FC_PORTSTATE_BLOCKED) in fc_timeout_fail_rport_io()
3699 rport->flags |= FC_RPORT_FAST_FAIL_TIMEDOUT; in fc_timeout_fail_rport_io()
3704 * fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
3713 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_scsi_scan_rport()
3716 if (((rport->port_state == FC_PORTSTATE_ONLINE) || in fc_scsi_scan_rport()
3717 (rport->port_state == FC_PORTSTATE_MARGINAL)) && in fc_scsi_scan_rport()
3718 (rport->roles & FC_PORT_ROLE_FCP_TARGET) && in fc_scsi_scan_rport()
3719 !(i->f->disable_target_scan)) { in fc_scsi_scan_rport()
3720 scsi_scan_target(&rport->dev, rport->channel, in fc_scsi_scan_rport()
3721 rport->scsi_target_id, SCAN_WILD_CARD, in fc_scsi_scan_rport()
3725 spin_lock_irqsave(shost->host_lock, flags); in fc_scsi_scan_rport()
3726 rport->flags &= ~FC_RPORT_SCAN_PENDING; in fc_scsi_scan_rport()
3727 spin_unlock_irqrestore(shost->host_lock, flags); in fc_scsi_scan_rport()
3731 * fc_block_rport() - Block SCSI eh thread for blocked fc_rport.
3749 spin_lock_irqsave(shost->host_lock, flags); in fc_block_rport()
3750 while (rport->port_state == FC_PORTSTATE_BLOCKED && in fc_block_rport()
3751 !(rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)) { in fc_block_rport()
3752 spin_unlock_irqrestore(shost->host_lock, flags); in fc_block_rport()
3754 spin_lock_irqsave(shost->host_lock, flags); in fc_block_rport()
3756 spin_unlock_irqrestore(shost->host_lock, flags); in fc_block_rport()
3758 if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT) in fc_block_rport()
3766 * fc_block_scsi_eh - Block SCSI eh thread for blocked fc_rport
3781 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); in fc_block_scsi_eh()
3791 * fc_eh_should_retry_cmd - Checks if the cmd should be retried or not
3801 struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device)); in fc_eh_should_retry_cmd()
3803 if ((rport->port_state != FC_PORTSTATE_ONLINE) && in fc_eh_should_retry_cmd()
3804 (scsi_cmd_to_rq(scmd)->cmd_flags & REQ_FAILFAST_TRANSPORT)) { in fc_eh_should_retry_cmd()
3813 * fc_vport_setup - allocates and creates a FC virtual port.
3832 struct fc_internal *fci = to_fc_internal(shost->transportt); in fc_vport_setup()
3841 if ( ! fci->f->vport_create) in fc_vport_setup()
3842 return -ENOENT; in fc_vport_setup()
3844 size = (sizeof(struct fc_vport) + fci->f->dd_fcvport_size); in fc_vport_setup()
3848 return -ENOMEM; in fc_vport_setup()
3851 vport->vport_state = FC_VPORT_UNKNOWN; in fc_vport_setup()
3852 vport->vport_last_state = FC_VPORT_UNKNOWN; in fc_vport_setup()
3853 vport->node_name = ids->node_name; in fc_vport_setup()
3854 vport->port_name = ids->port_name; in fc_vport_setup()
3855 vport->roles = ids->roles; in fc_vport_setup()
3856 vport->vport_type = ids->vport_type; in fc_vport_setup()
3857 if (fci->f->dd_fcvport_size) in fc_vport_setup()
3858 vport->dd_data = &vport[1]; in fc_vport_setup()
3859 vport->shost = shost; in fc_vport_setup()
3860 vport->channel = channel; in fc_vport_setup()
3861 vport->flags = FC_VPORT_CREATING; in fc_vport_setup()
3862 INIT_WORK(&vport->vport_delete_work, fc_vport_sched_delete); in fc_vport_setup()
3864 spin_lock_irqsave(shost->host_lock, flags); in fc_vport_setup()
3866 if (fc_host->npiv_vports_inuse >= fc_host->max_npiv_vports) { in fc_vport_setup()
3867 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_setup()
3869 return -ENOSPC; in fc_vport_setup()
3871 fc_host->npiv_vports_inuse++; in fc_vport_setup()
3872 vport->number = fc_host->next_vport_number++; in fc_vport_setup()
3873 list_add_tail(&vport->peers, &fc_host->vports); in fc_vport_setup()
3874 scsi_host_get(shost); /* for fc_host->vport list */ in fc_vport_setup()
3876 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_setup()
3878 dev = &vport->dev; in fc_vport_setup()
3880 dev->parent = get_device(pdev); /* takes parent reference */ in fc_vport_setup()
3881 dev->release = fc_vport_dev_release; in fc_vport_setup()
3882 dev_set_name(dev, "vport-%d:%d-%d", in fc_vport_setup()
3883 shost->host_no, channel, vport->number); in fc_vport_setup()
3894 error = fci->f->vport_create(vport, ids->disable); in fc_vport_setup()
3904 if (pdev != &shost->shost_gendev) { in fc_vport_setup()
3905 error = sysfs_create_link(&shost->shost_gendev.kobj, in fc_vport_setup()
3906 &dev->kobj, dev_name(dev)); in fc_vport_setup()
3913 spin_lock_irqsave(shost->host_lock, flags); in fc_vport_setup()
3914 vport->flags &= ~FC_VPORT_CREATING; in fc_vport_setup()
3915 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_setup()
3919 shost->host_no, channel); in fc_vport_setup()
3930 spin_lock_irqsave(shost->host_lock, flags); in fc_vport_setup()
3931 list_del(&vport->peers); in fc_vport_setup()
3932 scsi_host_put(shost); /* for fc_host->vport list */ in fc_vport_setup()
3933 fc_host->npiv_vports_inuse--; in fc_vport_setup()
3934 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_setup()
3935 put_device(dev->parent); in fc_vport_setup()
3942 * fc_vport_create - Admin App or LLDD requests creation of a vport
3958 stat = fc_vport_setup(shost, channel, &shost->shost_gendev, in fc_vport_create()
3965 * fc_vport_terminate - Admin App or LLDD requests termination of a vport
3979 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_vport_terminate()
3980 struct device *dev = &vport->dev; in fc_vport_terminate()
3984 if (i->f->vport_delete) in fc_vport_terminate()
3985 stat = i->f->vport_delete(vport); in fc_vport_terminate()
3987 stat = -ENOENT; in fc_vport_terminate()
3989 spin_lock_irqsave(shost->host_lock, flags); in fc_vport_terminate()
3990 vport->flags &= ~FC_VPORT_DELETING; in fc_vport_terminate()
3992 vport->flags |= FC_VPORT_DELETED; in fc_vport_terminate()
3993 list_del(&vport->peers); in fc_vport_terminate()
3994 fc_host->npiv_vports_inuse--; in fc_vport_terminate()
3995 scsi_host_put(shost); /* for fc_host->vport list */ in fc_vport_terminate()
3997 spin_unlock_irqrestore(shost->host_lock, flags); in fc_vport_terminate()
4002 if (dev->parent != &shost->shost_gendev) in fc_vport_terminate()
4003 sysfs_remove_link(&shost->shost_gendev.kobj, dev_name(dev)); in fc_vport_terminate()
4009 * Removing our self-reference should mean our in fc_vport_terminate()
4013 put_device(dev); /* for self-reference */ in fc_vport_terminate()
4020 * fc_vport_sched_delete - workq-based delete request for a vport
4032 dev_printk(KERN_ERR, vport->dev.parent, in fc_vport_sched_delete()
4034 "shost%d channel %d - error %d\n", __func__, in fc_vport_sched_delete()
4035 dev_name(&vport->dev), vport->shost->host_no, in fc_vport_sched_delete()
4036 vport->channel, stat); in fc_vport_sched_delete()
4045 * fc_bsg_job_timeout - handler for when a bsg request timesout
4054 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_job_timeout()
4057 if (rport && rport->port_state == FC_PORTSTATE_BLOCKED) in fc_bsg_job_timeout()
4062 if (inflight && i->f->bsg_timeout) { in fc_bsg_job_timeout()
4064 err = i->f->bsg_timeout(job); in fc_bsg_job_timeout()
4065 if (err == -EAGAIN) { in fc_bsg_job_timeout()
4069 printk(KERN_ERR "ERROR: FC BSG request timeout - LLD " in fc_bsg_job_timeout()
4080 * fc_bsg_host_dispatch - process fc host bsg requests and dispatch to LLDD
4086 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_host_dispatch()
4087 struct fc_bsg_request *bsg_request = job->request; in fc_bsg_host_dispatch()
4088 struct fc_bsg_reply *bsg_reply = job->reply; in fc_bsg_host_dispatch()
4093 if (job->request_len < cmdlen) { in fc_bsg_host_dispatch()
4094 ret = -ENOMSG; in fc_bsg_host_dispatch()
4099 switch (bsg_request->msgcode) { in fc_bsg_host_dispatch()
4111 if ((!job->request_payload.payload_len) || in fc_bsg_host_dispatch()
4112 (!job->reply_payload.payload_len)) { in fc_bsg_host_dispatch()
4113 ret = -EINVAL; in fc_bsg_host_dispatch()
4121 if ((!job->request_payload.payload_len) || in fc_bsg_host_dispatch()
4122 (!job->reply_payload.payload_len)) { in fc_bsg_host_dispatch()
4123 ret = -EINVAL; in fc_bsg_host_dispatch()
4130 if ((shost->hostt->vendor_id == 0L) || in fc_bsg_host_dispatch()
4131 (bsg_request->rqst_data.h_vendor.vendor_id != in fc_bsg_host_dispatch()
4132 shost->hostt->vendor_id)) { in fc_bsg_host_dispatch()
4133 ret = -ESRCH; in fc_bsg_host_dispatch()
4139 ret = -EBADR; in fc_bsg_host_dispatch()
4143 ret = i->f->bsg_request(job); in fc_bsg_host_dispatch()
4149 BUG_ON(job->reply_len < sizeof(uint32_t)); in fc_bsg_host_dispatch()
4150 bsg_reply->reply_payload_rcv_len = 0; in fc_bsg_host_dispatch()
4151 bsg_reply->result = ret; in fc_bsg_host_dispatch()
4152 job->reply_len = sizeof(uint32_t); in fc_bsg_host_dispatch()
4153 bsg_job_done(job, bsg_reply->result, in fc_bsg_host_dispatch()
4154 bsg_reply->reply_payload_rcv_len); in fc_bsg_host_dispatch()
4160 * fc_bsg_goose_queue - restart rport queue in case it was stopped
4166 struct request_queue *q = rport->rqst_q; in fc_bsg_goose_queue()
4173 * fc_bsg_rport_dispatch - process rport bsg requests and dispatch to LLDD
4179 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_rport_dispatch()
4180 struct fc_bsg_request *bsg_request = job->request; in fc_bsg_rport_dispatch()
4181 struct fc_bsg_reply *bsg_reply = job->reply; in fc_bsg_rport_dispatch()
4186 if (job->request_len < cmdlen) { in fc_bsg_rport_dispatch()
4187 ret = -ENOMSG; in fc_bsg_rport_dispatch()
4192 switch (bsg_request->msgcode) { in fc_bsg_rport_dispatch()
4201 if ((!job->request_payload.payload_len) || in fc_bsg_rport_dispatch()
4202 (!job->reply_payload.payload_len)) { in fc_bsg_rport_dispatch()
4203 ret = -EINVAL; in fc_bsg_rport_dispatch()
4208 ret = -EBADR; in fc_bsg_rport_dispatch()
4212 ret = i->f->bsg_request(job); in fc_bsg_rport_dispatch()
4218 BUG_ON(job->reply_len < sizeof(uint32_t)); in fc_bsg_rport_dispatch()
4219 bsg_reply->reply_payload_rcv_len = 0; in fc_bsg_rport_dispatch()
4220 bsg_reply->result = ret; in fc_bsg_rport_dispatch()
4221 job->reply_len = sizeof(uint32_t); in fc_bsg_rport_dispatch()
4222 bsg_job_done(job, bsg_reply->result, in fc_bsg_rport_dispatch()
4223 bsg_reply->reply_payload_rcv_len); in fc_bsg_rport_dispatch()
4231 if (scsi_is_fc_rport(job->dev)) in fc_bsg_dispatch()
4239 if (rport->port_state == FC_PORTSTATE_BLOCKED && in fc_bsg_rport_prep()
4240 !(rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)) in fc_bsg_rport_prep()
4243 if ((rport->port_state != FC_PORTSTATE_ONLINE) && in fc_bsg_rport_prep()
4244 (rport->port_state != FC_PORTSTATE_MARGINAL)) in fc_bsg_rport_prep()
4261 return -EAGAIN; in fc_bsg_dispatch_prep()
4263 return -EIO; in fc_bsg_dispatch_prep()
4270 * fc_bsg_hostadd - Create and add the bsg hooks so we can receive requests
4277 struct device *dev = &shost->shost_gendev; in fc_bsg_hostadd()
4278 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_hostadd()
4282 fc_host->rqst_q = NULL; in fc_bsg_hostadd()
4284 if (!i->f->bsg_request) in fc_bsg_hostadd()
4285 return -ENOTSUPP; in fc_bsg_hostadd()
4288 "fc_host%d", shost->host_no); in fc_bsg_hostadd()
4291 i->f->dd_bsg_size); in fc_bsg_hostadd()
4294 "fc_host%d: bsg interface failed to initialize - setup queue\n", in fc_bsg_hostadd()
4295 shost->host_no); in fc_bsg_hostadd()
4300 fc_host->rqst_q = q; in fc_bsg_hostadd()
4305 * fc_bsg_rportadd - Create and add the bsg hooks so we can receive requests
4312 struct device *dev = &rport->dev; in fc_bsg_rportadd()
4313 struct fc_internal *i = to_fc_internal(shost->transportt); in fc_bsg_rportadd()
4316 rport->rqst_q = NULL; in fc_bsg_rportadd()
4318 if (!i->f->bsg_request) in fc_bsg_rportadd()
4319 return -ENOTSUPP; in fc_bsg_rportadd()
4322 fc_bsg_job_timeout, i->f->dd_bsg_size); in fc_bsg_rportadd()
4329 rport->rqst_q = q; in fc_bsg_rportadd()
4335 * fc_bsg_remove - Deletes the bsg hooks on fchosts/rports