2 * FiberChannel transport specific attributes exported to sysfs.
4 * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Copyright (C) 2004-2005 James Smart, Emulex Corporation
23 * Rewrite for host, target, device, and remote port attributes,
24 * statistics, and service functions...
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/sched.h> /* workqueue stuff, HZ */
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <scsi/scsi_cmnd.h>
35 #include <linux/netlink.h>
36 #include <net/netlink.h>
37 #include <scsi/scsi_netlink_fc.h>
38 #include "scsi_priv.h"
40 static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
43 * Redefine so that we can have same named attributes in the
44 * sdev/starget/host objects.
46 #define FC_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
47 struct class_device_attribute class_device_attr_##_prefix##_##_name = \
48 __ATTR(_name,_mode,_show,_store)
50 #define fc_enum_name_search(title, table_type, table) \
51 static const char *get_fc_##title##_name(enum table_type table_key) \
56 for (i = 0; i < ARRAY_SIZE(table); i++) { \
57 if (table[i].value == table_key) { \
58 name = table[i].name; \
65 #define fc_enum_name_match(title, table_type, table) \
66 static int get_fc_##title##_match(const char *table_key, \
67 enum table_type *value) \
71 for (i = 0; i < ARRAY_SIZE(table); i++) { \
72 if (strncmp(table_key, table[i].name, \
73 table[i].matchlen) == 0) { \
74 *value = table[i].value; \
75 return 0; /* success */ \
78 return 1; /* failure */ \
82 /* Convert fc_port_type values to ascii string name */
84 enum fc_port_type value;
86 } fc_port_type_names[] = {
87 { FC_PORTTYPE_UNKNOWN, "Unknown" },
88 { FC_PORTTYPE_OTHER, "Other" },
89 { FC_PORTTYPE_NOTPRESENT, "Not Present" },
90 { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" },
91 { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" },
92 { FC_PORTTYPE_LPORT, "LPort (private loop)" },
93 { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" },
95 fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
96 #define FC_PORTTYPE_MAX_NAMELEN 50
99 /* Convert fc_host_event_code values to ascii string name */
100 static const struct {
101 enum fc_host_event_code value;
103 } fc_host_event_code_names[] = {
104 { FCH_EVT_LIP, "lip" },
105 { FCH_EVT_LINKUP, "link_up" },
106 { FCH_EVT_LINKDOWN, "link_down" },
107 { FCH_EVT_LIPRESET, "lip_reset" },
108 { FCH_EVT_RSCN, "rscn" },
109 { FCH_EVT_ADAPTER_CHANGE, "adapter_chg" },
110 { FCH_EVT_PORT_UNKNOWN, "port_unknown" },
111 { FCH_EVT_PORT_ONLINE, "port_online" },
112 { FCH_EVT_PORT_OFFLINE, "port_offline" },
113 { FCH_EVT_PORT_FABRIC, "port_fabric" },
114 { FCH_EVT_LINK_UNKNOWN, "link_unknown" },
115 { FCH_EVT_VENDOR_UNIQUE, "vendor_unique" },
117 fc_enum_name_search(host_event_code, fc_host_event_code,
118 fc_host_event_code_names)
119 #define FC_HOST_EVENT_CODE_MAX_NAMELEN 30
122 /* Convert fc_port_state values to ascii string name */
124 enum fc_port_state value;
126 } fc_port_state_names[] = {
127 { FC_PORTSTATE_UNKNOWN, "Unknown" },
128 { FC_PORTSTATE_NOTPRESENT, "Not Present" },
129 { FC_PORTSTATE_ONLINE, "Online" },
130 { FC_PORTSTATE_OFFLINE, "Offline" },
131 { FC_PORTSTATE_BLOCKED, "Blocked" },
132 { FC_PORTSTATE_BYPASSED, "Bypassed" },
133 { FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" },
134 { FC_PORTSTATE_LINKDOWN, "Linkdown" },
135 { FC_PORTSTATE_ERROR, "Error" },
136 { FC_PORTSTATE_LOOPBACK, "Loopback" },
137 { FC_PORTSTATE_DELETED, "Deleted" },
139 fc_enum_name_search(port_state, fc_port_state, fc_port_state_names)
140 #define FC_PORTSTATE_MAX_NAMELEN 20
143 /* Convert fc_tgtid_binding_type values to ascii string name */
144 static const struct {
145 enum fc_tgtid_binding_type value;
148 } fc_tgtid_binding_type_names[] = {
149 { FC_TGTID_BIND_NONE, "none", 4 },
150 { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
151 { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
152 { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 },
154 fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type,
155 fc_tgtid_binding_type_names)
156 fc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type,
157 fc_tgtid_binding_type_names)
158 #define FC_BINDTYPE_MAX_NAMELEN 30
161 #define fc_bitfield_name_search(title, table) \
163 get_fc_##title##_names(u32 table_key, char *buf) \
169 for (i = 0; i < ARRAY_SIZE(table); i++) { \
170 if (table[i].value & table_key) { \
171 len += sprintf(buf + len, "%s%s", \
172 prefix, table[i].name); \
176 len += sprintf(buf + len, "\n"); \
181 /* Convert FC_COS bit values to ascii string name */
182 static const struct {
186 { FC_COS_CLASS1, "Class 1" },
187 { FC_COS_CLASS2, "Class 2" },
188 { FC_COS_CLASS3, "Class 3" },
189 { FC_COS_CLASS4, "Class 4" },
190 { FC_COS_CLASS6, "Class 6" },
192 fc_bitfield_name_search(cos, fc_cos_names)
195 /* Convert FC_PORTSPEED bit values to ascii string name */
196 static const struct {
199 } fc_port_speed_names[] = {
200 { FC_PORTSPEED_1GBIT, "1 Gbit" },
201 { FC_PORTSPEED_2GBIT, "2 Gbit" },
202 { FC_PORTSPEED_4GBIT, "4 Gbit" },
203 { FC_PORTSPEED_10GBIT, "10 Gbit" },
204 { FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" },
206 fc_bitfield_name_search(port_speed, fc_port_speed_names)
210 show_fc_fc4s (char *buf, u8 *fc4_list)
214 for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++)
215 len += sprintf(buf + len , "0x%02x ", *fc4_list);
216 len += sprintf(buf + len, "\n");
221 /* Convert FC_RPORT_ROLE bit values to ascii string name */
222 static const struct {
225 } fc_remote_port_role_names[] = {
226 { FC_RPORT_ROLE_FCP_TARGET, "FCP Target" },
227 { FC_RPORT_ROLE_FCP_INITIATOR, "FCP Initiator" },
228 { FC_RPORT_ROLE_IP_PORT, "IP Port" },
230 fc_bitfield_name_search(remote_port_roles, fc_remote_port_role_names)
233 * Define roles that are specific to port_id. Values are relative to ROLE_MASK.
235 #define FC_WELLKNOWN_PORTID_MASK 0xfffff0
236 #define FC_WELLKNOWN_ROLE_MASK 0x00000f
237 #define FC_FPORT_PORTID 0x00000e
238 #define FC_FABCTLR_PORTID 0x00000d
239 #define FC_DIRSRVR_PORTID 0x00000c
240 #define FC_TIMESRVR_PORTID 0x00000b
241 #define FC_MGMTSRVR_PORTID 0x00000a
244 static void fc_timeout_deleted_rport(void *data);
245 static void fc_scsi_scan_rport(void *data);
248 * Attribute counts pre object type...
249 * Increase these values if you add attributes
251 #define FC_STARGET_NUM_ATTRS 3
252 #define FC_RPORT_NUM_ATTRS 9
253 #define FC_HOST_NUM_ATTRS 17
256 struct scsi_transport_template t;
257 struct fc_function_template *f;
260 * For attributes : each object has :
261 * An array of the actual attributes structures
262 * An array of null-terminated pointers to the attribute
263 * structures - used for mid-layer interaction.
265 * The attribute containers for the starget and host are are
266 * part of the midlayer. As the remote port is specific to the
267 * fc transport, we must provide the attribute container.
269 struct class_device_attribute private_starget_attrs[
270 FC_STARGET_NUM_ATTRS];
271 struct class_device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1];
273 struct class_device_attribute private_host_attrs[FC_HOST_NUM_ATTRS];
274 struct class_device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1];
276 struct transport_container rport_attr_cont;
277 struct class_device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS];
278 struct class_device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1];
281 #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t)
283 static int fc_target_setup(struct transport_container *tc, struct device *dev,
284 struct class_device *cdev)
286 struct scsi_target *starget = to_scsi_target(dev);
287 struct fc_rport *rport = starget_to_rport(starget);
290 * if parent is remote port, use values from remote port.
291 * Otherwise, this host uses the fc_transport, but not the
292 * remote port interface. As such, initialize to known non-values.
295 fc_starget_node_name(starget) = rport->node_name;
296 fc_starget_port_name(starget) = rport->port_name;
297 fc_starget_port_id(starget) = rport->port_id;
299 fc_starget_node_name(starget) = -1;
300 fc_starget_port_name(starget) = -1;
301 fc_starget_port_id(starget) = -1;
307 static DECLARE_TRANSPORT_CLASS(fc_transport_class,
313 static int fc_host_setup(struct transport_container *tc, struct device *dev,
314 struct class_device *cdev)
316 struct Scsi_Host *shost = dev_to_shost(dev);
317 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
320 * Set default values easily detected by the midlayer as
321 * failure cases. The scsi lldd is responsible for initializing
322 * all transport attributes to valid values per host.
324 fc_host->node_name = -1;
325 fc_host->port_name = -1;
326 fc_host->permanent_port_name = -1;
327 fc_host->supported_classes = FC_COS_UNSPECIFIED;
328 memset(fc_host->supported_fc4s, 0,
329 sizeof(fc_host->supported_fc4s));
330 fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN;
331 fc_host->maxframe_size = -1;
332 memset(fc_host->serial_number, 0,
333 sizeof(fc_host->serial_number));
335 fc_host->port_id = -1;
336 fc_host->port_type = FC_PORTTYPE_UNKNOWN;
337 fc_host->port_state = FC_PORTSTATE_UNKNOWN;
338 memset(fc_host->active_fc4s, 0,
339 sizeof(fc_host->active_fc4s));
340 fc_host->speed = FC_PORTSPEED_UNKNOWN;
341 fc_host->fabric_name = -1;
342 memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name));
343 memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname));
345 fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN;
347 INIT_LIST_HEAD(&fc_host->rports);
348 INIT_LIST_HEAD(&fc_host->rport_bindings);
349 fc_host->next_rport_number = 0;
350 fc_host->next_target_id = 0;
352 snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d",
354 fc_host->work_q = create_singlethread_workqueue(
355 fc_host->work_q_name);
356 if (!fc_host->work_q)
359 snprintf(fc_host->devloss_work_q_name, KOBJ_NAME_LEN, "fc_dl_%d",
361 fc_host->devloss_work_q = create_singlethread_workqueue(
362 fc_host->devloss_work_q_name);
363 if (!fc_host->devloss_work_q) {
364 destroy_workqueue(fc_host->work_q);
365 fc_host->work_q = NULL;
372 static DECLARE_TRANSPORT_CLASS(fc_host_class,
379 * Setup and Remove actions for remote ports are handled
380 * in the service functions below.
382 static DECLARE_TRANSPORT_CLASS(fc_rport_class,
393 * dev_loss_tmo: the default number of seconds that the FC transport
394 * should insulate the loss of a remote port.
395 * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
397 static unsigned int fc_dev_loss_tmo = 60; /* seconds */
399 module_param_named(dev_loss_tmo, fc_dev_loss_tmo, int, S_IRUGO|S_IWUSR);
400 MODULE_PARM_DESC(dev_loss_tmo,
401 "Maximum number of seconds that the FC transport should"
402 " insulate the loss of a remote port. Once this value is"
403 " exceeded, the scsi target is removed. Value should be"
404 " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT.");
407 * Netlink Infrastructure
410 static atomic_t fc_event_seq;
413 * fc_get_event_number - Obtain the next sequential FC event number
416 * We could have inline'd this, but it would have required fc_event_seq to
417 * be exposed. For now, live with the subroutine call.
418 * Atomic used to avoid lock/unlock...
421 fc_get_event_number(void)
423 return atomic_add_return(1, &fc_event_seq);
425 EXPORT_SYMBOL(fc_get_event_number);
429 * fc_host_post_event - called to post an even on an fc_host.
431 * @shost: host the event occurred on
432 * @event_number: fc event number obtained from get_fc_event_number()
433 * @event_code: fc_host event being posted
434 * @event_data: 32bits of data for the event being posted
437 * This routine assumes no locks are held on entry.
440 fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
441 enum fc_host_event_code event_code, u32 event_data)
444 struct nlmsghdr *nlh;
445 struct fc_nl_event *event;
455 len = FC_NL_MSGALIGN(sizeof(*event));
456 skblen = NLMSG_SPACE(len);
458 skb = alloc_skb(skblen, GFP_KERNEL);
464 nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
465 skblen - sizeof(*nlh), 0);
470 event = NLMSG_DATA(nlh);
472 INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
473 FC_NL_ASYNC_EVENT, len);
474 event->seconds = get_seconds();
475 event->vendor_id = 0;
476 event->host_no = shost->host_no;
477 event->event_datalen = sizeof(u32); /* bytes */
478 event->event_num = event_number;
479 event->event_code = event_code;
480 event->event_data = event_data;
482 err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS);
483 if (err && (err != -ESRCH)) /* filter no recipient errors */
484 /* nlmsg_multicast already kfree_skb'd */
492 name = get_fc_host_event_code_name(event_code);
494 "%s: Dropped Event : host %d %s data 0x%08x - err %d\n",
495 __FUNCTION__, shost->host_no,
496 (name) ? name : "<unknown>", event_data, err);
499 EXPORT_SYMBOL(fc_host_post_event);
503 * fc_host_post_vendor_event - called to post a vendor unique event on
506 * @shost: host the event occurred on
507 * @event_number: fc event number obtained from get_fc_event_number()
508 * @data_len: amount, in bytes, of vendor unique data
509 * @data_buf: pointer to vendor unique data
512 * This routine assumes no locks are held on entry.
515 fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
516 u32 data_len, char * data_buf, u64 vendor_id)
519 struct nlmsghdr *nlh;
520 struct fc_nl_event *event;
526 goto send_vendor_fail;
529 len = FC_NL_MSGALIGN(sizeof(*event) + data_len);
530 skblen = NLMSG_SPACE(len);
532 skb = alloc_skb(skblen, GFP_KERNEL);
535 goto send_vendor_fail;
538 nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
539 skblen - sizeof(*nlh), 0);
542 goto send_vendor_fail_skb;
544 event = NLMSG_DATA(nlh);
546 INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
547 FC_NL_ASYNC_EVENT, len);
548 event->seconds = get_seconds();
549 event->vendor_id = vendor_id;
550 event->host_no = shost->host_no;
551 event->event_datalen = data_len; /* bytes */
552 event->event_num = event_number;
553 event->event_code = FCH_EVT_VENDOR_UNIQUE;
554 memcpy(&event->event_data, data_buf, data_len);
556 err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS);
557 if (err && (err != -ESRCH)) /* filter no recipient errors */
558 /* nlmsg_multicast already kfree_skb'd */
559 goto send_vendor_fail;
563 send_vendor_fail_skb:
567 "%s: Dropped Event : host %d vendor_unique - err %d\n",
568 __FUNCTION__, shost->host_no, err);
571 EXPORT_SYMBOL(fc_host_post_vendor_event);
575 static __init int fc_transport_init(void)
579 atomic_set(&fc_event_seq, 0);
581 error = transport_class_register(&fc_host_class);
584 error = transport_class_register(&fc_rport_class);
587 return transport_class_register(&fc_transport_class);
590 static void __exit fc_transport_exit(void)
592 transport_class_unregister(&fc_transport_class);
593 transport_class_unregister(&fc_rport_class);
594 transport_class_unregister(&fc_host_class);
598 * FC Remote Port Attribute Management
601 #define fc_rport_show_function(field, format_string, sz, cast) \
603 show_fc_rport_##field (struct class_device *cdev, char *buf) \
605 struct fc_rport *rport = transport_class_to_rport(cdev); \
606 struct Scsi_Host *shost = rport_to_shost(rport); \
607 struct fc_internal *i = to_fc_internal(shost->transportt); \
608 if ((i->f->get_rport_##field) && \
609 !((rport->port_state == FC_PORTSTATE_BLOCKED) || \
610 (rport->port_state == FC_PORTSTATE_DELETED) || \
611 (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \
612 i->f->get_rport_##field(rport); \
613 return snprintf(buf, sz, format_string, cast rport->field); \
616 #define fc_rport_store_function(field) \
618 store_fc_rport_##field(struct class_device *cdev, const char *buf, \
622 struct fc_rport *rport = transport_class_to_rport(cdev); \
623 struct Scsi_Host *shost = rport_to_shost(rport); \
624 struct fc_internal *i = to_fc_internal(shost->transportt); \
625 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \
626 (rport->port_state == FC_PORTSTATE_DELETED) || \
627 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \
629 val = simple_strtoul(buf, NULL, 0); \
630 i->f->set_rport_##field(rport, val); \
634 #define fc_rport_rd_attr(field, format_string, sz) \
635 fc_rport_show_function(field, format_string, sz, ) \
636 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
637 show_fc_rport_##field, NULL)
639 #define fc_rport_rd_attr_cast(field, format_string, sz, cast) \
640 fc_rport_show_function(field, format_string, sz, (cast)) \
641 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
642 show_fc_rport_##field, NULL)
644 #define fc_rport_rw_attr(field, format_string, sz) \
645 fc_rport_show_function(field, format_string, sz, ) \
646 fc_rport_store_function(field) \
647 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \
648 show_fc_rport_##field, \
649 store_fc_rport_##field)
652 #define fc_private_rport_show_function(field, format_string, sz, cast) \
654 show_fc_rport_##field (struct class_device *cdev, char *buf) \
656 struct fc_rport *rport = transport_class_to_rport(cdev); \
657 return snprintf(buf, sz, format_string, cast rport->field); \
660 #define fc_private_rport_rd_attr(field, format_string, sz) \
661 fc_private_rport_show_function(field, format_string, sz, ) \
662 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
663 show_fc_rport_##field, NULL)
665 #define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \
666 fc_private_rport_show_function(field, format_string, sz, (cast)) \
667 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
668 show_fc_rport_##field, NULL)
671 #define fc_private_rport_rd_enum_attr(title, maxlen) \
673 show_fc_rport_##title (struct class_device *cdev, char *buf) \
675 struct fc_rport *rport = transport_class_to_rport(cdev); \
677 name = get_fc_##title##_name(rport->title); \
680 return snprintf(buf, maxlen, "%s\n", name); \
682 static FC_CLASS_DEVICE_ATTR(rport, title, S_IRUGO, \
683 show_fc_rport_##title, NULL)
686 #define SETUP_RPORT_ATTRIBUTE_RD(field) \
687 i->private_rport_attrs[count] = class_device_attr_rport_##field; \
688 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
689 i->private_rport_attrs[count].store = NULL; \
690 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
691 if (i->f->show_rport_##field) \
694 #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \
695 i->private_rport_attrs[count] = class_device_attr_rport_##field; \
696 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
697 i->private_rport_attrs[count].store = NULL; \
698 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
701 #define SETUP_RPORT_ATTRIBUTE_RW(field) \
702 i->private_rport_attrs[count] = class_device_attr_rport_##field; \
703 if (!i->f->set_rport_##field) { \
704 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
705 i->private_rport_attrs[count].store = NULL; \
707 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
708 if (i->f->show_rport_##field) \
712 /* The FC Transport Remote Port Attributes: */
714 /* Fixed Remote Port Attributes */
716 fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20);
719 show_fc_rport_supported_classes (struct class_device *cdev, char *buf)
721 struct fc_rport *rport = transport_class_to_rport(cdev);
722 if (rport->supported_classes == FC_COS_UNSPECIFIED)
723 return snprintf(buf, 20, "unspecified\n");
724 return get_fc_cos_names(rport->supported_classes, buf);
726 static FC_CLASS_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
727 show_fc_rport_supported_classes, NULL);
729 /* Dynamic Remote Port Attributes */
732 * dev_loss_tmo attribute
734 fc_rport_show_function(dev_loss_tmo, "%d\n", 20, )
736 store_fc_rport_dev_loss_tmo(struct class_device *cdev, const char *buf,
740 struct fc_rport *rport = transport_class_to_rport(cdev);
741 struct Scsi_Host *shost = rport_to_shost(rport);
742 struct fc_internal *i = to_fc_internal(shost->transportt);
743 if ((rport->port_state == FC_PORTSTATE_BLOCKED) ||
744 (rport->port_state == FC_PORTSTATE_DELETED) ||
745 (rport->port_state == FC_PORTSTATE_NOTPRESENT))
747 val = simple_strtoul(buf, NULL, 0);
748 if ((val < 0) || (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT))
750 i->f->set_rport_dev_loss_tmo(rport, val);
753 static FC_CLASS_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR,
754 show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo);
757 /* Private Remote Port Attributes */
759 fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
760 fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
761 fc_private_rport_rd_attr(port_id, "0x%06x\n", 20);
764 show_fc_rport_roles (struct class_device *cdev, char *buf)
766 struct fc_rport *rport = transport_class_to_rport(cdev);
768 /* identify any roles that are port_id specific */
769 if ((rport->port_id != -1) &&
770 (rport->port_id & FC_WELLKNOWN_PORTID_MASK) ==
771 FC_WELLKNOWN_PORTID_MASK) {
772 switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
773 case FC_FPORT_PORTID:
774 return snprintf(buf, 30, "Fabric Port\n");
775 case FC_FABCTLR_PORTID:
776 return snprintf(buf, 30, "Fabric Controller\n");
777 case FC_DIRSRVR_PORTID:
778 return snprintf(buf, 30, "Directory Server\n");
779 case FC_TIMESRVR_PORTID:
780 return snprintf(buf, 30, "Time Server\n");
781 case FC_MGMTSRVR_PORTID:
782 return snprintf(buf, 30, "Management Server\n");
784 return snprintf(buf, 30, "Unknown Fabric Entity\n");
787 if (rport->roles == FC_RPORT_ROLE_UNKNOWN)
788 return snprintf(buf, 20, "unknown\n");
789 return get_fc_remote_port_roles_names(rport->roles, buf);
792 static FC_CLASS_DEVICE_ATTR(rport, roles, S_IRUGO,
793 show_fc_rport_roles, NULL);
795 fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
796 fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);
801 * FC SCSI Target Attribute Management
805 * Note: in the target show function we recognize when the remote
806 * port is in the heirarchy and do not allow the driver to get
807 * involved in sysfs functions. The driver only gets involved if
808 * it's the "old" style that doesn't use rports.
810 #define fc_starget_show_function(field, format_string, sz, cast) \
812 show_fc_starget_##field (struct class_device *cdev, char *buf) \
814 struct scsi_target *starget = transport_class_to_starget(cdev); \
815 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
816 struct fc_internal *i = to_fc_internal(shost->transportt); \
817 struct fc_rport *rport = starget_to_rport(starget); \
819 fc_starget_##field(starget) = rport->field; \
820 else if (i->f->get_starget_##field) \
821 i->f->get_starget_##field(starget); \
822 return snprintf(buf, sz, format_string, \
823 cast fc_starget_##field(starget)); \
826 #define fc_starget_rd_attr(field, format_string, sz) \
827 fc_starget_show_function(field, format_string, sz, ) \
828 static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
829 show_fc_starget_##field, NULL)
831 #define fc_starget_rd_attr_cast(field, format_string, sz, cast) \
832 fc_starget_show_function(field, format_string, sz, (cast)) \
833 static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
834 show_fc_starget_##field, NULL)
836 #define SETUP_STARGET_ATTRIBUTE_RD(field) \
837 i->private_starget_attrs[count] = class_device_attr_starget_##field; \
838 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
839 i->private_starget_attrs[count].store = NULL; \
840 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
841 if (i->f->show_starget_##field) \
844 #define SETUP_STARGET_ATTRIBUTE_RW(field) \
845 i->private_starget_attrs[count] = class_device_attr_starget_##field; \
846 if (!i->f->set_starget_##field) { \
847 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
848 i->private_starget_attrs[count].store = NULL; \
850 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
851 if (i->f->show_starget_##field) \
854 /* The FC Transport SCSI Target Attributes: */
855 fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
856 fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
857 fc_starget_rd_attr(port_id, "0x%06x\n", 20);
861 * Host Attribute Management
864 #define fc_host_show_function(field, format_string, sz, cast) \
866 show_fc_host_##field (struct class_device *cdev, char *buf) \
868 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
869 struct fc_internal *i = to_fc_internal(shost->transportt); \
870 if (i->f->get_host_##field) \
871 i->f->get_host_##field(shost); \
872 return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
875 #define fc_host_store_function(field) \
877 store_fc_host_##field(struct class_device *cdev, const char *buf, \
881 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
882 struct fc_internal *i = to_fc_internal(shost->transportt); \
884 val = simple_strtoul(buf, NULL, 0); \
885 i->f->set_host_##field(shost, val); \
889 #define fc_host_store_str_function(field, slen) \
891 store_fc_host_##field(struct class_device *cdev, const char *buf, \
894 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
895 struct fc_internal *i = to_fc_internal(shost->transportt); \
896 unsigned int cnt=count; \
898 /* count may include a LF at end of string */ \
899 if (buf[cnt-1] == '\n') \
901 if (cnt > ((slen) - 1)) \
903 memcpy(fc_host_##field(shost), buf, cnt); \
904 i->f->set_host_##field(shost); \
908 #define fc_host_rd_attr(field, format_string, sz) \
909 fc_host_show_function(field, format_string, sz, ) \
910 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
911 show_fc_host_##field, NULL)
913 #define fc_host_rd_attr_cast(field, format_string, sz, cast) \
914 fc_host_show_function(field, format_string, sz, (cast)) \
915 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
916 show_fc_host_##field, NULL)
918 #define fc_host_rw_attr(field, format_string, sz) \
919 fc_host_show_function(field, format_string, sz, ) \
920 fc_host_store_function(field) \
921 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \
922 show_fc_host_##field, \
923 store_fc_host_##field)
925 #define fc_host_rd_enum_attr(title, maxlen) \
927 show_fc_host_##title (struct class_device *cdev, char *buf) \
929 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
930 struct fc_internal *i = to_fc_internal(shost->transportt); \
932 if (i->f->get_host_##title) \
933 i->f->get_host_##title(shost); \
934 name = get_fc_##title##_name(fc_host_##title(shost)); \
937 return snprintf(buf, maxlen, "%s\n", name); \
939 static FC_CLASS_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
941 #define SETUP_HOST_ATTRIBUTE_RD(field) \
942 i->private_host_attrs[count] = class_device_attr_host_##field; \
943 i->private_host_attrs[count].attr.mode = S_IRUGO; \
944 i->private_host_attrs[count].store = NULL; \
945 i->host_attrs[count] = &i->private_host_attrs[count]; \
946 if (i->f->show_host_##field) \
949 #define SETUP_HOST_ATTRIBUTE_RW(field) \
950 i->private_host_attrs[count] = class_device_attr_host_##field; \
951 if (!i->f->set_host_##field) { \
952 i->private_host_attrs[count].attr.mode = S_IRUGO; \
953 i->private_host_attrs[count].store = NULL; \
955 i->host_attrs[count] = &i->private_host_attrs[count]; \
956 if (i->f->show_host_##field) \
960 #define fc_private_host_show_function(field, format_string, sz, cast) \
962 show_fc_host_##field (struct class_device *cdev, char *buf) \
964 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
965 return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
968 #define fc_private_host_rd_attr(field, format_string, sz) \
969 fc_private_host_show_function(field, format_string, sz, ) \
970 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
971 show_fc_host_##field, NULL)
973 #define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \
974 fc_private_host_show_function(field, format_string, sz, (cast)) \
975 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
976 show_fc_host_##field, NULL)
978 #define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \
979 i->private_host_attrs[count] = class_device_attr_host_##field; \
980 i->private_host_attrs[count].attr.mode = S_IRUGO; \
981 i->private_host_attrs[count].store = NULL; \
982 i->host_attrs[count] = &i->private_host_attrs[count]; \
985 #define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \
987 i->private_host_attrs[count] = class_device_attr_host_##field; \
988 i->host_attrs[count] = &i->private_host_attrs[count]; \
993 /* Fixed Host Attributes */
996 show_fc_host_supported_classes (struct class_device *cdev, char *buf)
998 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1000 if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
1001 return snprintf(buf, 20, "unspecified\n");
1003 return get_fc_cos_names(fc_host_supported_classes(shost), buf);
1005 static FC_CLASS_DEVICE_ATTR(host, supported_classes, S_IRUGO,
1006 show_fc_host_supported_classes, NULL);
1009 show_fc_host_supported_fc4s (struct class_device *cdev, char *buf)
1011 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1012 return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost));
1014 static FC_CLASS_DEVICE_ATTR(host, supported_fc4s, S_IRUGO,
1015 show_fc_host_supported_fc4s, NULL);
1018 show_fc_host_supported_speeds (struct class_device *cdev, char *buf)
1020 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1022 if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
1023 return snprintf(buf, 20, "unknown\n");
1025 return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
1027 static FC_CLASS_DEVICE_ATTR(host, supported_speeds, S_IRUGO,
1028 show_fc_host_supported_speeds, NULL);
1031 fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
1032 fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
1033 fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20,
1034 unsigned long long);
1035 fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20);
1036 fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1));
1039 /* Dynamic Host Attributes */
1042 show_fc_host_active_fc4s (struct class_device *cdev, char *buf)
1044 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1045 struct fc_internal *i = to_fc_internal(shost->transportt);
1047 if (i->f->get_host_active_fc4s)
1048 i->f->get_host_active_fc4s(shost);
1050 return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost));
1052 static FC_CLASS_DEVICE_ATTR(host, active_fc4s, S_IRUGO,
1053 show_fc_host_active_fc4s, NULL);
1056 show_fc_host_speed (struct class_device *cdev, char *buf)
1058 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1059 struct fc_internal *i = to_fc_internal(shost->transportt);
1061 if (i->f->get_host_speed)
1062 i->f->get_host_speed(shost);
1064 if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
1065 return snprintf(buf, 20, "unknown\n");
1067 return get_fc_port_speed_names(fc_host_speed(shost), buf);
1069 static FC_CLASS_DEVICE_ATTR(host, speed, S_IRUGO,
1070 show_fc_host_speed, NULL);
1073 fc_host_rd_attr(port_id, "0x%06x\n", 20);
1074 fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
1075 fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
1076 fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
1077 fc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1);
1079 fc_private_host_show_function(system_hostname, "%s\n",
1080 FC_SYMBOLIC_NAME_SIZE + 1, )
1081 fc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE)
1082 static FC_CLASS_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR,
1083 show_fc_host_system_hostname, store_fc_host_system_hostname);
1086 /* Private Host Attributes */
1089 show_fc_private_host_tgtid_bind_type(struct class_device *cdev, char *buf)
1091 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1094 name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost));
1097 return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name);
1100 #define get_list_head_entry(pos, head, member) \
1101 pos = list_entry((head)->next, typeof(*pos), member)
1104 store_fc_private_host_tgtid_bind_type(struct class_device *cdev,
1105 const char *buf, size_t count)
1107 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1108 struct fc_rport *rport;
1109 enum fc_tgtid_binding_type val;
1110 unsigned long flags;
1112 if (get_fc_tgtid_bind_type_match(buf, &val))
1115 /* if changing bind type, purge all unused consistent bindings */
1116 if (val != fc_host_tgtid_bind_type(shost)) {
1117 spin_lock_irqsave(shost->host_lock, flags);
1118 while (!list_empty(&fc_host_rport_bindings(shost))) {
1119 get_list_head_entry(rport,
1120 &fc_host_rport_bindings(shost), peers);
1121 list_del(&rport->peers);
1122 rport->port_state = FC_PORTSTATE_DELETED;
1123 fc_queue_work(shost, &rport->rport_delete_work);
1125 spin_unlock_irqrestore(shost->host_lock, flags);
1128 fc_host_tgtid_bind_type(shost) = val;
1132 static FC_CLASS_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR,
1133 show_fc_private_host_tgtid_bind_type,
1134 store_fc_private_host_tgtid_bind_type);
1137 store_fc_private_host_issue_lip(struct class_device *cdev,
1138 const char *buf, size_t count)
1140 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1141 struct fc_internal *i = to_fc_internal(shost->transportt);
1144 /* ignore any data value written to the attribute */
1145 if (i->f->issue_fc_host_lip) {
1146 ret = i->f->issue_fc_host_lip(shost);
1147 return ret ? ret: count;
1153 static FC_CLASS_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL,
1154 store_fc_private_host_issue_lip);
1157 * Host Statistics Management
1160 /* Show a given an attribute in the statistics group */
1162 fc_stat_show(const struct class_device *cdev, char *buf, unsigned long offset)
1164 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1165 struct fc_internal *i = to_fc_internal(shost->transportt);
1166 struct fc_host_statistics *stats;
1167 ssize_t ret = -ENOENT;
1169 if (offset > sizeof(struct fc_host_statistics) ||
1170 offset % sizeof(u64) != 0)
1173 if (i->f->get_fc_host_stats) {
1174 stats = (i->f->get_fc_host_stats)(shost);
1176 ret = snprintf(buf, 20, "0x%llx\n",
1177 (unsigned long long)*(u64 *)(((u8 *) stats) + offset));
1183 /* generate a read-only statistics attribute */
1184 #define fc_host_statistic(name) \
1185 static ssize_t show_fcstat_##name(struct class_device *cd, char *buf) \
1187 return fc_stat_show(cd, buf, \
1188 offsetof(struct fc_host_statistics, name)); \
1190 static FC_CLASS_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
1192 fc_host_statistic(seconds_since_last_reset);
1193 fc_host_statistic(tx_frames);
1194 fc_host_statistic(tx_words);
1195 fc_host_statistic(rx_frames);
1196 fc_host_statistic(rx_words);
1197 fc_host_statistic(lip_count);
1198 fc_host_statistic(nos_count);
1199 fc_host_statistic(error_frames);
1200 fc_host_statistic(dumped_frames);
1201 fc_host_statistic(link_failure_count);
1202 fc_host_statistic(loss_of_sync_count);
1203 fc_host_statistic(loss_of_signal_count);
1204 fc_host_statistic(prim_seq_protocol_err_count);
1205 fc_host_statistic(invalid_tx_word_count);
1206 fc_host_statistic(invalid_crc_count);
1207 fc_host_statistic(fcp_input_requests);
1208 fc_host_statistic(fcp_output_requests);
1209 fc_host_statistic(fcp_control_requests);
1210 fc_host_statistic(fcp_input_megabytes);
1211 fc_host_statistic(fcp_output_megabytes);
1214 fc_reset_statistics(struct class_device *cdev, const char *buf,
1217 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1218 struct fc_internal *i = to_fc_internal(shost->transportt);
1220 /* ignore any data value written to the attribute */
1221 if (i->f->reset_fc_host_stats) {
1222 i->f->reset_fc_host_stats(shost);
1228 static FC_CLASS_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL,
1229 fc_reset_statistics);
1232 static struct attribute *fc_statistics_attrs[] = {
1233 &class_device_attr_host_seconds_since_last_reset.attr,
1234 &class_device_attr_host_tx_frames.attr,
1235 &class_device_attr_host_tx_words.attr,
1236 &class_device_attr_host_rx_frames.attr,
1237 &class_device_attr_host_rx_words.attr,
1238 &class_device_attr_host_lip_count.attr,
1239 &class_device_attr_host_nos_count.attr,
1240 &class_device_attr_host_error_frames.attr,
1241 &class_device_attr_host_dumped_frames.attr,
1242 &class_device_attr_host_link_failure_count.attr,
1243 &class_device_attr_host_loss_of_sync_count.attr,
1244 &class_device_attr_host_loss_of_signal_count.attr,
1245 &class_device_attr_host_prim_seq_protocol_err_count.attr,
1246 &class_device_attr_host_invalid_tx_word_count.attr,
1247 &class_device_attr_host_invalid_crc_count.attr,
1248 &class_device_attr_host_fcp_input_requests.attr,
1249 &class_device_attr_host_fcp_output_requests.attr,
1250 &class_device_attr_host_fcp_control_requests.attr,
1251 &class_device_attr_host_fcp_input_megabytes.attr,
1252 &class_device_attr_host_fcp_output_megabytes.attr,
1253 &class_device_attr_host_reset_statistics.attr,
1257 static struct attribute_group fc_statistics_group = {
1258 .name = "statistics",
1259 .attrs = fc_statistics_attrs,
1262 static int fc_host_match(struct attribute_container *cont,
1265 struct Scsi_Host *shost;
1266 struct fc_internal *i;
1268 if (!scsi_is_host_device(dev))
1271 shost = dev_to_shost(dev);
1272 if (!shost->transportt || shost->transportt->host_attrs.ac.class
1273 != &fc_host_class.class)
1276 i = to_fc_internal(shost->transportt);
1278 return &i->t.host_attrs.ac == cont;
1281 static int fc_target_match(struct attribute_container *cont,
1284 struct Scsi_Host *shost;
1285 struct fc_internal *i;
1287 if (!scsi_is_target_device(dev))
1290 shost = dev_to_shost(dev->parent);
1291 if (!shost->transportt || shost->transportt->host_attrs.ac.class
1292 != &fc_host_class.class)
1295 i = to_fc_internal(shost->transportt);
1297 return &i->t.target_attrs.ac == cont;
1300 static void fc_rport_dev_release(struct device *dev)
1302 struct fc_rport *rport = dev_to_rport(dev);
1303 put_device(dev->parent);
1307 int scsi_is_fc_rport(const struct device *dev)
1309 return dev->release == fc_rport_dev_release;
1311 EXPORT_SYMBOL(scsi_is_fc_rport);
1313 static int fc_rport_match(struct attribute_container *cont,
1316 struct Scsi_Host *shost;
1317 struct fc_internal *i;
1319 if (!scsi_is_fc_rport(dev))
1322 shost = dev_to_shost(dev->parent);
1323 if (!shost->transportt || shost->transportt->host_attrs.ac.class
1324 != &fc_host_class.class)
1327 i = to_fc_internal(shost->transportt);
1329 return &i->rport_attr_cont.ac == cont;
1334 * fc_timed_out - FC Transport I/O timeout intercept handler
1336 * @scmd: The SCSI command which timed out
1338 * This routine protects against error handlers getting invoked while a
1339 * rport is in a blocked state, typically due to a temporarily loss of
1340 * connectivity. If the error handlers are allowed to proceed, requests
1341 * to abort i/o, reset the target, etc will likely fail as there is no way
1342 * to communicate with the device to perform the requested function. These
1343 * failures may result in the midlayer taking the device offline, requiring
1344 * manual intervention to restore operation.
1346 * This routine, called whenever an i/o times out, validates the state of
1347 * the underlying rport. If the rport is blocked, it returns
1348 * EH_RESET_TIMER, which will continue to reschedule the timeout.
1349 * Eventually, either the device will return, or devloss_tmo will fire,
1350 * and when the timeout then fires, it will be handled normally.
1351 * If the rport is not blocked, normal error handling continues.
1354 * This routine assumes no locks are held on entry.
1356 static enum scsi_eh_timer_return
1357 fc_timed_out(struct scsi_cmnd *scmd)
1359 struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device));
1361 if (rport->port_state == FC_PORTSTATE_BLOCKED)
1362 return EH_RESET_TIMER;
1364 return EH_NOT_HANDLED;
1368 * Must be called with shost->host_lock held
1370 static int fc_user_scan(struct Scsi_Host *shost, uint channel,
1373 struct fc_rport *rport;
1375 list_for_each_entry(rport, &fc_host_rports(shost), peers) {
1376 if (rport->scsi_target_id == -1)
1379 if ((channel == SCAN_WILD_CARD || channel == rport->channel) &&
1380 (id == SCAN_WILD_CARD || id == rport->scsi_target_id)) {
1381 scsi_scan_target(&rport->dev, rport->channel,
1382 rport->scsi_target_id, lun, 1);
1389 struct scsi_transport_template *
1390 fc_attach_transport(struct fc_function_template *ft)
1393 struct fc_internal *i = kzalloc(sizeof(struct fc_internal),
1399 i->t.target_attrs.ac.attrs = &i->starget_attrs[0];
1400 i->t.target_attrs.ac.class = &fc_transport_class.class;
1401 i->t.target_attrs.ac.match = fc_target_match;
1402 i->t.target_size = sizeof(struct fc_starget_attrs);
1403 transport_container_register(&i->t.target_attrs);
1405 i->t.host_attrs.ac.attrs = &i->host_attrs[0];
1406 i->t.host_attrs.ac.class = &fc_host_class.class;
1407 i->t.host_attrs.ac.match = fc_host_match;
1408 i->t.host_size = sizeof(struct fc_host_attrs);
1409 if (ft->get_fc_host_stats)
1410 i->t.host_attrs.statistics = &fc_statistics_group;
1411 transport_container_register(&i->t.host_attrs);
1413 i->rport_attr_cont.ac.attrs = &i->rport_attrs[0];
1414 i->rport_attr_cont.ac.class = &fc_rport_class.class;
1415 i->rport_attr_cont.ac.match = fc_rport_match;
1416 transport_container_register(&i->rport_attr_cont);
1420 /* Transport uses the shost workq for scsi scanning */
1421 i->t.create_work_queue = 1;
1423 i->t.eh_timed_out = fc_timed_out;
1425 i->t.user_scan = fc_user_scan;
1428 * Setup SCSI Target Attributes.
1431 SETUP_STARGET_ATTRIBUTE_RD(node_name);
1432 SETUP_STARGET_ATTRIBUTE_RD(port_name);
1433 SETUP_STARGET_ATTRIBUTE_RD(port_id);
1435 BUG_ON(count > FC_STARGET_NUM_ATTRS);
1437 i->starget_attrs[count] = NULL;
1441 * Setup SCSI Host Attributes.
1444 SETUP_HOST_ATTRIBUTE_RD(node_name);
1445 SETUP_HOST_ATTRIBUTE_RD(port_name);
1446 SETUP_HOST_ATTRIBUTE_RD(permanent_port_name);
1447 SETUP_HOST_ATTRIBUTE_RD(supported_classes);
1448 SETUP_HOST_ATTRIBUTE_RD(supported_fc4s);
1449 SETUP_HOST_ATTRIBUTE_RD(supported_speeds);
1450 SETUP_HOST_ATTRIBUTE_RD(maxframe_size);
1451 SETUP_HOST_ATTRIBUTE_RD(serial_number);
1453 SETUP_HOST_ATTRIBUTE_RD(port_id);
1454 SETUP_HOST_ATTRIBUTE_RD(port_type);
1455 SETUP_HOST_ATTRIBUTE_RD(port_state);
1456 SETUP_HOST_ATTRIBUTE_RD(active_fc4s);
1457 SETUP_HOST_ATTRIBUTE_RD(speed);
1458 SETUP_HOST_ATTRIBUTE_RD(fabric_name);
1459 SETUP_HOST_ATTRIBUTE_RD(symbolic_name);
1460 SETUP_HOST_ATTRIBUTE_RW(system_hostname);
1462 /* Transport-managed attributes */
1463 SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type);
1464 if (ft->issue_fc_host_lip)
1465 SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip);
1467 BUG_ON(count > FC_HOST_NUM_ATTRS);
1469 i->host_attrs[count] = NULL;
1472 * Setup Remote Port Attributes.
1475 SETUP_RPORT_ATTRIBUTE_RD(maxframe_size);
1476 SETUP_RPORT_ATTRIBUTE_RD(supported_classes);
1477 SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo);
1478 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name);
1479 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name);
1480 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id);
1481 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles);
1482 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state);
1483 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id);
1485 BUG_ON(count > FC_RPORT_NUM_ATTRS);
1487 i->rport_attrs[count] = NULL;
1491 EXPORT_SYMBOL(fc_attach_transport);
1493 void fc_release_transport(struct scsi_transport_template *t)
1495 struct fc_internal *i = to_fc_internal(t);
1497 transport_container_unregister(&i->t.target_attrs);
1498 transport_container_unregister(&i->t.host_attrs);
1499 transport_container_unregister(&i->rport_attr_cont);
1503 EXPORT_SYMBOL(fc_release_transport);
1506 * fc_queue_work - Queue work to the fc_host workqueue.
1507 * @shost: Pointer to Scsi_Host bound to fc_host.
1508 * @work: Work to queue for execution.
1511 * 1 - work queued for execution
1512 * 0 - work is already queued
1513 * -EINVAL - work queue doesn't exist
1516 fc_queue_work(struct Scsi_Host *shost, struct work_struct *work)
1518 if (unlikely(!fc_host_work_q(shost))) {
1520 "ERROR: FC host '%s' attempted to queue work, "
1521 "when no workqueue created.\n", shost->hostt->name);
1527 return queue_work(fc_host_work_q(shost), work);
1531 * fc_flush_work - Flush a fc_host's workqueue.
1532 * @shost: Pointer to Scsi_Host bound to fc_host.
1535 fc_flush_work(struct Scsi_Host *shost)
1537 if (!fc_host_work_q(shost)) {
1539 "ERROR: FC host '%s' attempted to flush work, "
1540 "when no workqueue created.\n", shost->hostt->name);
1545 flush_workqueue(fc_host_work_q(shost));
1549 * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue.
1550 * @shost: Pointer to Scsi_Host bound to fc_host.
1551 * @work: Work to queue for execution.
1552 * @delay: jiffies to delay the work queuing
1555 * 0 on success / != 0 for error
1558 fc_queue_devloss_work(struct Scsi_Host *shost, struct work_struct *work,
1559 unsigned long delay)
1561 if (unlikely(!fc_host_devloss_work_q(shost))) {
1563 "ERROR: FC host '%s' attempted to queue work, "
1564 "when no workqueue created.\n", shost->hostt->name);
1570 return queue_delayed_work(fc_host_devloss_work_q(shost), work, delay);
1574 * fc_flush_devloss - Flush a fc_host's devloss workqueue.
1575 * @shost: Pointer to Scsi_Host bound to fc_host.
1578 fc_flush_devloss(struct Scsi_Host *shost)
1580 if (!fc_host_devloss_work_q(shost)) {
1582 "ERROR: FC host '%s' attempted to flush work, "
1583 "when no workqueue created.\n", shost->hostt->name);
1588 flush_workqueue(fc_host_devloss_work_q(shost));
1593 * fc_remove_host - called to terminate any fc_transport-related elements
1595 * @rport: remote port to be unblocked.
1597 * This routine is expected to be called immediately preceeding the
1598 * a driver's call to scsi_remove_host().
1600 * WARNING: A driver utilizing the fc_transport, which fails to call
1601 * this routine prior to scsi_remote_host(), will leave dangling
1602 * objects in /sys/class/fc_remote_ports. Access to any of these
1603 * objects can result in a system crash !!!
1606 * This routine assumes no locks are held on entry.
1609 fc_remove_host(struct Scsi_Host *shost)
1611 struct fc_rport *rport, *next_rport;
1612 struct workqueue_struct *work_q;
1613 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1615 /* Remove any remote ports */
1616 list_for_each_entry_safe(rport, next_rport,
1617 &fc_host->rports, peers) {
1618 list_del(&rport->peers);
1619 rport->port_state = FC_PORTSTATE_DELETED;
1620 fc_queue_work(shost, &rport->rport_delete_work);
1623 list_for_each_entry_safe(rport, next_rport,
1624 &fc_host->rport_bindings, peers) {
1625 list_del(&rport->peers);
1626 rport->port_state = FC_PORTSTATE_DELETED;
1627 fc_queue_work(shost, &rport->rport_delete_work);
1630 /* flush all scan work items */
1631 scsi_flush_work(shost);
1633 /* flush all stgt delete, and rport delete work items, then kill it */
1634 if (fc_host->work_q) {
1635 work_q = fc_host->work_q;
1636 fc_host->work_q = NULL;
1637 destroy_workqueue(work_q);
1640 /* flush all devloss work items, then kill it */
1641 if (fc_host->devloss_work_q) {
1642 work_q = fc_host->devloss_work_q;
1643 fc_host->devloss_work_q = NULL;
1644 destroy_workqueue(work_q);
1647 EXPORT_SYMBOL(fc_remove_host);
1651 * fc_starget_delete - called to delete the scsi decendents of an rport
1652 * (target and all sdevs)
1654 * @data: remote port to be operated on.
1657 fc_starget_delete(void *data)
1659 struct fc_rport *rport = (struct fc_rport *)data;
1660 struct Scsi_Host *shost = rport_to_shost(rport);
1661 unsigned long flags;
1663 spin_lock_irqsave(shost->host_lock, flags);
1664 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
1665 spin_unlock_irqrestore(shost->host_lock, flags);
1666 if (!cancel_delayed_work(&rport->dev_loss_work))
1667 fc_flush_devloss(shost);
1668 spin_lock_irqsave(shost->host_lock, flags);
1669 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1671 spin_unlock_irqrestore(shost->host_lock, flags);
1673 scsi_remove_target(&rport->dev);
1678 * fc_rport_final_delete - finish rport termination and delete it.
1680 * @data: remote port to be deleted.
1683 fc_rport_final_delete(void *data)
1685 struct fc_rport *rport = (struct fc_rport *)data;
1686 struct device *dev = &rport->dev;
1687 struct Scsi_Host *shost = rport_to_shost(rport);
1689 /* Delete SCSI target and sdevs */
1690 if (rport->scsi_target_id != -1)
1691 fc_starget_delete(data);
1694 * if a scan is pending, flush the SCSI Host work_q so that
1695 * that we can reclaim the rport scan work element.
1697 if (rport->flags & FC_RPORT_SCAN_PENDING)
1698 scsi_flush_work(shost);
1700 transport_remove_device(dev);
1702 transport_destroy_device(dev);
1703 put_device(&shost->shost_gendev); /* for fc_host->rport list */
1704 put_device(dev); /* for self-reference */
1709 * fc_rport_create - allocates and creates a remote FC port.
1710 * @shost: scsi host the remote port is connected to.
1711 * @channel: Channel on shost port connected to.
1712 * @ids: The world wide names, fc address, and FC4 port
1713 * roles for the remote port.
1715 * Allocates and creates the remoter port structure, including the
1716 * class and sysfs creation.
1719 * This routine assumes no locks are held on entry.
1722 fc_rport_create(struct Scsi_Host *shost, int channel,
1723 struct fc_rport_identifiers *ids)
1725 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1726 struct fc_internal *fci = to_fc_internal(shost->transportt);
1727 struct fc_rport *rport;
1729 unsigned long flags;
1733 size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size);
1734 rport = kzalloc(size, GFP_KERNEL);
1735 if (unlikely(!rport)) {
1736 printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
1740 rport->maxframe_size = -1;
1741 rport->supported_classes = FC_COS_UNSPECIFIED;
1742 rport->dev_loss_tmo = fc_dev_loss_tmo;
1743 memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name));
1744 memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name));
1745 rport->port_id = ids->port_id;
1746 rport->roles = ids->roles;
1747 rport->port_state = FC_PORTSTATE_ONLINE;
1748 if (fci->f->dd_fcrport_size)
1749 rport->dd_data = &rport[1];
1750 rport->channel = channel;
1752 INIT_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport, rport);
1753 INIT_WORK(&rport->scan_work, fc_scsi_scan_rport, rport);
1754 INIT_WORK(&rport->stgt_delete_work, fc_starget_delete, rport);
1755 INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete, rport);
1757 spin_lock_irqsave(shost->host_lock, flags);
1759 rport->number = fc_host->next_rport_number++;
1760 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
1761 rport->scsi_target_id = fc_host->next_target_id++;
1763 rport->scsi_target_id = -1;
1764 list_add_tail(&rport->peers, &fc_host->rports);
1765 get_device(&shost->shost_gendev); /* for fc_host->rport list */
1767 spin_unlock_irqrestore(shost->host_lock, flags);
1770 device_initialize(dev); /* takes self reference */
1771 dev->parent = get_device(&shost->shost_gendev); /* parent reference */
1772 dev->release = fc_rport_dev_release;
1773 sprintf(dev->bus_id, "rport-%d:%d-%d",
1774 shost->host_no, channel, rport->number);
1775 transport_setup_device(dev);
1777 error = device_add(dev);
1779 printk(KERN_ERR "FC Remote Port device_add failed\n");
1782 transport_add_device(dev);
1783 transport_configure_device(dev);
1785 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
1786 /* initiate a scan of the target */
1787 rport->flags |= FC_RPORT_SCAN_PENDING;
1788 scsi_queue_work(shost, &rport->scan_work);
1794 transport_destroy_device(dev);
1795 spin_lock_irqsave(shost->host_lock, flags);
1796 list_del(&rport->peers);
1797 put_device(&shost->shost_gendev); /* for fc_host->rport list */
1798 spin_unlock_irqrestore(shost->host_lock, flags);
1799 put_device(dev->parent);
1805 * fc_remote_port_add - notifies the fc transport of the existence
1806 * of a remote FC port.
1807 * @shost: scsi host the remote port is connected to.
1808 * @channel: Channel on shost port connected to.
1809 * @ids: The world wide names, fc address, and FC4 port
1810 * roles for the remote port.
1812 * The LLDD calls this routine to notify the transport of the existence
1813 * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn)
1814 * of the port, it's FC address (port_id), and the FC4 roles that are
1815 * active for the port.
1817 * For ports that are FCP targets (aka scsi targets), the FC transport
1818 * maintains consistent target id bindings on behalf of the LLDD.
1819 * A consistent target id binding is an assignment of a target id to
1820 * a remote port identifier, which persists while the scsi host is
1821 * attached. The remote port can disappear, then later reappear, and
1822 * it's target id assignment remains the same. This allows for shifts
1823 * in FC addressing (if binding by wwpn or wwnn) with no apparent
1824 * changes to the scsi subsystem which is based on scsi host number and
1825 * target id values. Bindings are only valid during the attachment of
1826 * the scsi host. If the host detaches, then later re-attaches, target
1827 * id bindings may change.
1829 * This routine is responsible for returning a remote port structure.
1830 * The routine will search the list of remote ports it maintains
1831 * internally on behalf of consistent target id mappings. If found, the
1832 * remote port structure will be reused. Otherwise, a new remote port
1833 * structure will be allocated.
1835 * Whenever a remote port is allocated, a new fc_remote_port class
1836 * device is created.
1838 * Should not be called from interrupt context.
1841 * This routine assumes no locks are held on entry.
1844 fc_remote_port_add(struct Scsi_Host *shost, int channel,
1845 struct fc_rport_identifiers *ids)
1847 struct fc_internal *fci = to_fc_internal(shost->transportt);
1848 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1849 struct fc_rport *rport;
1850 unsigned long flags;
1853 /* ensure any stgt delete functions are done */
1854 fc_flush_work(shost);
1857 * Search the list of "active" rports, for an rport that has been
1858 * deleted, but we've held off the real delete while the target
1859 * is in a "blocked" state.
1861 spin_lock_irqsave(shost->host_lock, flags);
1863 list_for_each_entry(rport, &fc_host->rports, peers) {
1865 if ((rport->port_state == FC_PORTSTATE_BLOCKED) &&
1866 (rport->channel == channel)) {
1868 switch (fc_host->tgtid_bind_type) {
1869 case FC_TGTID_BIND_BY_WWPN:
1870 case FC_TGTID_BIND_NONE:
1871 if (rport->port_name == ids->port_name)
1874 case FC_TGTID_BIND_BY_WWNN:
1875 if (rport->node_name == ids->node_name)
1878 case FC_TGTID_BIND_BY_ID:
1879 if (rport->port_id == ids->port_id)
1885 struct work_struct *work =
1886 &rport->dev_loss_work;
1888 memcpy(&rport->node_name, &ids->node_name,
1889 sizeof(rport->node_name));
1890 memcpy(&rport->port_name, &ids->port_name,
1891 sizeof(rport->port_name));
1892 rport->port_id = ids->port_id;
1894 rport->port_state = FC_PORTSTATE_ONLINE;
1895 rport->roles = ids->roles;
1897 spin_unlock_irqrestore(shost->host_lock, flags);
1899 if (fci->f->dd_fcrport_size)
1900 memset(rport->dd_data, 0,
1901 fci->f->dd_fcrport_size);
1904 * If we were blocked, we were a target.
1905 * If no longer a target, we leave the timer
1906 * running in case the port changes roles
1907 * prior to the timer expiring. If the timer
1908 * fires, the target will be torn down.
1910 if (!(ids->roles & FC_RPORT_ROLE_FCP_TARGET))
1913 /* restart the target */
1916 * Stop the target timer first. Take no action
1917 * on the del_timer failure as the state
1918 * machine state change will validate the
1921 if (!cancel_delayed_work(work))
1922 fc_flush_devloss(shost);
1924 spin_lock_irqsave(shost->host_lock, flags);
1926 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1928 /* initiate a scan of the target */
1929 rport->flags |= FC_RPORT_SCAN_PENDING;
1930 scsi_queue_work(shost, &rport->scan_work);
1932 spin_unlock_irqrestore(shost->host_lock, flags);
1934 scsi_target_unblock(&rport->dev);
1941 /* Search the bindings array */
1942 if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) {
1944 /* search for a matching consistent binding */
1946 list_for_each_entry(rport, &fc_host->rport_bindings,
1948 if (rport->channel != channel)
1951 switch (fc_host->tgtid_bind_type) {
1952 case FC_TGTID_BIND_BY_WWPN:
1953 if (rport->port_name == ids->port_name)
1956 case FC_TGTID_BIND_BY_WWNN:
1957 if (rport->node_name == ids->node_name)
1960 case FC_TGTID_BIND_BY_ID:
1961 if (rport->port_id == ids->port_id)
1964 case FC_TGTID_BIND_NONE: /* to keep compiler happy */
1969 list_move_tail(&rport->peers, &fc_host->rports);
1975 memcpy(&rport->node_name, &ids->node_name,
1976 sizeof(rport->node_name));
1977 memcpy(&rport->port_name, &ids->port_name,
1978 sizeof(rport->port_name));
1979 rport->port_id = ids->port_id;
1980 rport->roles = ids->roles;
1981 rport->port_state = FC_PORTSTATE_ONLINE;
1983 if (fci->f->dd_fcrport_size)
1984 memset(rport->dd_data, 0,
1985 fci->f->dd_fcrport_size);
1987 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
1988 /* initiate a scan of the target */
1989 rport->flags |= FC_RPORT_SCAN_PENDING;
1990 scsi_queue_work(shost, &rport->scan_work);
1991 spin_unlock_irqrestore(shost->host_lock, flags);
1992 scsi_target_unblock(&rport->dev);
1994 spin_unlock_irqrestore(shost->host_lock, flags);
2000 spin_unlock_irqrestore(shost->host_lock, flags);
2002 /* No consistent binding found - create new remote port entry */
2003 rport = fc_rport_create(shost, channel, ids);
2007 EXPORT_SYMBOL(fc_remote_port_add);
2011 * fc_remote_port_delete - notifies the fc transport that a remote
2012 * port is no longer in existence.
2013 * @rport: The remote port that no longer exists
2015 * The LLDD calls this routine to notify the transport that a remote
2016 * port is no longer part of the topology. Note: Although a port
2017 * may no longer be part of the topology, it may persist in the remote
2018 * ports displayed by the fc_host. We do this under 2 conditions:
2019 * - If the port was a scsi target, we delay its deletion by "blocking" it.
2020 * This allows the port to temporarily disappear, then reappear without
2021 * disrupting the SCSI device tree attached to it. During the "blocked"
2022 * period the port will still exist.
2023 * - If the port was a scsi target and disappears for longer than we
2024 * expect, we'll delete the port and the tear down the SCSI device tree
2025 * attached to it. However, we want to semi-persist the target id assigned
2026 * to that port if it eventually does exist. The port structure will
2027 * remain (although with minimal information) so that the target id
2030 * If the remote port is not an FCP Target, it will be fully torn down
2031 * and deallocated, including the fc_remote_port class device.
2033 * If the remote port is an FCP Target, the port will be placed in a
2034 * temporary blocked state. From the LLDD's perspective, the rport no
2035 * longer exists. From the SCSI midlayer's perspective, the SCSI target
2036 * exists, but all sdevs on it are blocked from further I/O. The following
2038 * If the remote port does not return (signaled by a LLDD call to
2039 * fc_remote_port_add()) within the dev_loss_tmo timeout, then the
2040 * scsi target is removed - killing all outstanding i/o and removing the
2041 * scsi devices attached ot it. The port structure will be marked Not
2042 * Present and be partially cleared, leaving only enough information to
2043 * recognize the remote port relative to the scsi target id binding if
2044 * it later appears. The port will remain as long as there is a valid
2045 * binding (e.g. until the user changes the binding type or unloads the
2046 * scsi host with the binding).
2048 * If the remote port returns within the dev_loss_tmo value (and matches
2049 * according to the target id binding type), the port structure will be
2050 * reused. If it is no longer a SCSI target, the target will be torn
2051 * down. If it continues to be a SCSI target, then the target will be
2052 * unblocked (allowing i/o to be resumed), and a scan will be activated
2053 * to ensure that all luns are detected.
2055 * Called from normal process context only - cannot be called from interrupt.
2058 * This routine assumes no locks are held on entry.
2061 fc_remote_port_delete(struct fc_rport *rport)
2063 struct Scsi_Host *shost = rport_to_shost(rport);
2064 int timeout = rport->dev_loss_tmo;
2065 unsigned long flags;
2068 * No need to flush the fc_host work_q's, as all adds are synchronous.
2070 * We do need to reclaim the rport scan work element, so eventually
2071 * (in fc_rport_final_delete()) we'll flush the scsi host work_q if
2072 * there's still a scan pending.
2075 spin_lock_irqsave(shost->host_lock, flags);
2077 /* If no scsi target id mapping, delete it */
2078 if (rport->scsi_target_id == -1) {
2079 list_del(&rport->peers);
2080 rport->port_state = FC_PORTSTATE_DELETED;
2081 fc_queue_work(shost, &rport->rport_delete_work);
2082 spin_unlock_irqrestore(shost->host_lock, flags);
2086 rport->port_state = FC_PORTSTATE_BLOCKED;
2088 rport->flags |= FC_RPORT_DEVLOSS_PENDING;
2090 spin_unlock_irqrestore(shost->host_lock, flags);
2092 scsi_target_block(&rport->dev);
2094 /* cap the length the devices can be blocked until they are deleted */
2095 fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ);
2097 EXPORT_SYMBOL(fc_remote_port_delete);
2100 * fc_remote_port_rolechg - notifies the fc transport that the roles
2101 * on a remote may have changed.
2102 * @rport: The remote port that changed.
2104 * The LLDD calls this routine to notify the transport that the roles
2105 * on a remote port may have changed. The largest effect of this is
2106 * if a port now becomes a FCP Target, it must be allocated a
2107 * scsi target id. If the port is no longer a FCP target, any
2108 * scsi target id value assigned to it will persist in case the
2109 * role changes back to include FCP Target. No changes in the scsi
2110 * midlayer will be invoked if the role changes (in the expectation
2111 * that the role will be resumed. If it doesn't normal error processing
2114 * Should not be called from interrupt context.
2117 * This routine assumes no locks are held on entry.
2120 fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
2122 struct Scsi_Host *shost = rport_to_shost(rport);
2123 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
2124 unsigned long flags;
2127 spin_lock_irqsave(shost->host_lock, flags);
2128 if (roles & FC_RPORT_ROLE_FCP_TARGET) {
2129 if (rport->scsi_target_id == -1) {
2130 rport->scsi_target_id = fc_host->next_target_id++;
2132 } else if (!(rport->roles & FC_RPORT_ROLE_FCP_TARGET))
2136 rport->roles = roles;
2138 spin_unlock_irqrestore(shost->host_lock, flags);
2142 * There may have been a delete timer running on the
2143 * port. Ensure that it is cancelled as we now know
2144 * the port is an FCP Target.
2145 * Note: we know the rport is exists and in an online
2146 * state as the LLDD would not have had an rport
2147 * reference to pass us.
2149 * Take no action on the del_timer failure as the state
2150 * machine state change will validate the
2153 if (!cancel_delayed_work(&rport->dev_loss_work))
2154 fc_flush_devloss(shost);
2156 spin_lock_irqsave(shost->host_lock, flags);
2157 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
2158 spin_unlock_irqrestore(shost->host_lock, flags);
2160 /* ensure any stgt delete functions are done */
2161 fc_flush_work(shost);
2163 /* initiate a scan of the target */
2164 spin_lock_irqsave(shost->host_lock, flags);
2165 rport->flags |= FC_RPORT_SCAN_PENDING;
2166 scsi_queue_work(shost, &rport->scan_work);
2167 spin_unlock_irqrestore(shost->host_lock, flags);
2168 scsi_target_unblock(&rport->dev);
2171 EXPORT_SYMBOL(fc_remote_port_rolechg);
2174 * fc_timeout_deleted_rport - Timeout handler for a deleted remote port that
2175 * was a SCSI target (thus was blocked), and failed
2176 * to return in the alloted time.
2178 * @data: rport target that failed to reappear in the alloted time.
2181 fc_timeout_deleted_rport(void *data)
2183 struct fc_rport *rport = (struct fc_rport *)data;
2184 struct Scsi_Host *shost = rport_to_shost(rport);
2185 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
2186 unsigned long flags;
2188 spin_lock_irqsave(shost->host_lock, flags);
2190 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
2193 * If the port is ONLINE, then it came back. Validate it's still an
2194 * FCP target. If not, tear down the scsi_target on it.
2196 if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
2197 !(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
2198 dev_printk(KERN_ERR, &rport->dev,
2199 "blocked FC remote port time out: no longer"
2200 " a FCP target, removing starget\n");
2201 spin_unlock_irqrestore(shost->host_lock, flags);
2202 scsi_target_unblock(&rport->dev);
2203 fc_queue_work(shost, &rport->stgt_delete_work);
2207 if (rport->port_state != FC_PORTSTATE_BLOCKED) {
2208 spin_unlock_irqrestore(shost->host_lock, flags);
2209 dev_printk(KERN_ERR, &rport->dev,
2210 "blocked FC remote port time out: leaving target alone\n");
2214 if (fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) {
2215 list_del(&rport->peers);
2216 rport->port_state = FC_PORTSTATE_DELETED;
2217 dev_printk(KERN_ERR, &rport->dev,
2218 "blocked FC remote port time out: removing target\n");
2219 fc_queue_work(shost, &rport->rport_delete_work);
2220 spin_unlock_irqrestore(shost->host_lock, flags);
2224 dev_printk(KERN_ERR, &rport->dev,
2225 "blocked FC remote port time out: removing target and "
2226 "saving binding\n");
2228 list_move_tail(&rport->peers, &fc_host->rport_bindings);
2231 * Note: We do not remove or clear the hostdata area. This allows
2232 * host-specific target data to persist along with the
2233 * scsi_target_id. It's up to the host to manage it's hostdata area.
2237 * Reinitialize port attributes that may change if the port comes back.
2239 rport->maxframe_size = -1;
2240 rport->supported_classes = FC_COS_UNSPECIFIED;
2241 rport->roles = FC_RPORT_ROLE_UNKNOWN;
2242 rport->port_state = FC_PORTSTATE_NOTPRESENT;
2244 /* remove the identifiers that aren't used in the consisting binding */
2245 switch (fc_host->tgtid_bind_type) {
2246 case FC_TGTID_BIND_BY_WWPN:
2247 rport->node_name = -1;
2248 rport->port_id = -1;
2250 case FC_TGTID_BIND_BY_WWNN:
2251 rport->port_name = -1;
2252 rport->port_id = -1;
2254 case FC_TGTID_BIND_BY_ID:
2255 rport->node_name = -1;
2256 rport->port_name = -1;
2258 case FC_TGTID_BIND_NONE: /* to keep compiler happy */
2263 * As this only occurs if the remote port (scsi target)
2264 * went away and didn't come back - we'll remove
2265 * all attached scsi devices.
2267 spin_unlock_irqrestore(shost->host_lock, flags);
2269 scsi_target_unblock(&rport->dev);
2270 fc_queue_work(shost, &rport->stgt_delete_work);
2274 * fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
2276 * @data: remote port to be scanned.
2279 fc_scsi_scan_rport(void *data)
2281 struct fc_rport *rport = (struct fc_rport *)data;
2282 struct Scsi_Host *shost = rport_to_shost(rport);
2283 unsigned long flags;
2285 if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
2286 (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
2287 scsi_scan_target(&rport->dev, rport->channel,
2288 rport->scsi_target_id, SCAN_WILD_CARD, 1);
2291 spin_lock_irqsave(shost->host_lock, flags);
2292 rport->flags &= ~FC_RPORT_SCAN_PENDING;
2293 spin_unlock_irqrestore(shost->host_lock, flags);
2297 MODULE_AUTHOR("Martin Hicks");
2298 MODULE_DESCRIPTION("FC Transport Attributes");
2299 MODULE_LICENSE("GPL");
2301 module_init(fc_transport_init);
2302 module_exit(fc_transport_exit);