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 "scsi_priv.h"
37 static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
40 * Redefine so that we can have same named attributes in the
41 * sdev/starget/host objects.
43 #define FC_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
44 struct class_device_attribute class_device_attr_##_prefix##_##_name = \
45 __ATTR(_name,_mode,_show,_store)
47 #define fc_enum_name_search(title, table_type, table) \
48 static const char *get_fc_##title##_name(enum table_type table_key) \
53 for (i = 0; i < ARRAY_SIZE(table); i++) { \
54 if (table[i].value == table_key) { \
55 name = table[i].name; \
62 #define fc_enum_name_match(title, table_type, table) \
63 static int get_fc_##title##_match(const char *table_key, \
64 enum table_type *value) \
68 for (i = 0; i < ARRAY_SIZE(table); i++) { \
69 if (strncmp(table_key, table[i].name, \
70 table[i].matchlen) == 0) { \
71 *value = table[i].value; \
72 return 0; /* success */ \
75 return 1; /* failure */ \
79 /* Convert fc_port_type values to ascii string name */
81 enum fc_port_type value;
83 } fc_port_type_names[] = {
84 { FC_PORTTYPE_UNKNOWN, "Unknown" },
85 { FC_PORTTYPE_OTHER, "Other" },
86 { FC_PORTTYPE_NOTPRESENT, "Not Present" },
87 { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" },
88 { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" },
89 { FC_PORTTYPE_LPORT, "LPort (private loop)" },
90 { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" },
92 fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
93 #define FC_PORTTYPE_MAX_NAMELEN 50
96 /* Convert fc_port_state values to ascii string name */
98 enum fc_port_state value;
100 } fc_port_state_names[] = {
101 { FC_PORTSTATE_UNKNOWN, "Unknown" },
102 { FC_PORTSTATE_NOTPRESENT, "Not Present" },
103 { FC_PORTSTATE_ONLINE, "Online" },
104 { FC_PORTSTATE_OFFLINE, "Offline" },
105 { FC_PORTSTATE_BLOCKED, "Blocked" },
106 { FC_PORTSTATE_BYPASSED, "Bypassed" },
107 { FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" },
108 { FC_PORTSTATE_LINKDOWN, "Linkdown" },
109 { FC_PORTSTATE_ERROR, "Error" },
110 { FC_PORTSTATE_LOOPBACK, "Loopback" },
111 { FC_PORTSTATE_DELETED, "Deleted" },
113 fc_enum_name_search(port_state, fc_port_state, fc_port_state_names)
114 #define FC_PORTSTATE_MAX_NAMELEN 20
117 /* Convert fc_tgtid_binding_type values to ascii string name */
118 static const struct {
119 enum fc_tgtid_binding_type value;
122 } fc_tgtid_binding_type_names[] = {
123 { FC_TGTID_BIND_NONE, "none", 4 },
124 { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
125 { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
126 { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 },
128 fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type,
129 fc_tgtid_binding_type_names)
130 fc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type,
131 fc_tgtid_binding_type_names)
132 #define FC_BINDTYPE_MAX_NAMELEN 30
135 #define fc_bitfield_name_search(title, table) \
137 get_fc_##title##_names(u32 table_key, char *buf) \
143 for (i = 0; i < ARRAY_SIZE(table); i++) { \
144 if (table[i].value & table_key) { \
145 len += sprintf(buf + len, "%s%s", \
146 prefix, table[i].name); \
150 len += sprintf(buf + len, "\n"); \
155 /* Convert FC_COS bit values to ascii string name */
156 static const struct {
160 { FC_COS_CLASS1, "Class 1" },
161 { FC_COS_CLASS2, "Class 2" },
162 { FC_COS_CLASS3, "Class 3" },
163 { FC_COS_CLASS4, "Class 4" },
164 { FC_COS_CLASS6, "Class 6" },
166 fc_bitfield_name_search(cos, fc_cos_names)
169 /* Convert FC_PORTSPEED bit values to ascii string name */
170 static const struct {
173 } fc_port_speed_names[] = {
174 { FC_PORTSPEED_1GBIT, "1 Gbit" },
175 { FC_PORTSPEED_2GBIT, "2 Gbit" },
176 { FC_PORTSPEED_4GBIT, "4 Gbit" },
177 { FC_PORTSPEED_10GBIT, "10 Gbit" },
178 { FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" },
180 fc_bitfield_name_search(port_speed, fc_port_speed_names)
184 show_fc_fc4s (char *buf, u8 *fc4_list)
188 for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++)
189 len += sprintf(buf + len , "0x%02x ", *fc4_list);
190 len += sprintf(buf + len, "\n");
195 /* Convert FC_RPORT_ROLE bit values to ascii string name */
196 static const struct {
199 } fc_remote_port_role_names[] = {
200 { FC_RPORT_ROLE_FCP_TARGET, "FCP Target" },
201 { FC_RPORT_ROLE_FCP_INITIATOR, "FCP Initiator" },
202 { FC_RPORT_ROLE_IP_PORT, "IP Port" },
204 fc_bitfield_name_search(remote_port_roles, fc_remote_port_role_names)
207 * Define roles that are specific to port_id. Values are relative to ROLE_MASK.
209 #define FC_WELLKNOWN_PORTID_MASK 0xfffff0
210 #define FC_WELLKNOWN_ROLE_MASK 0x00000f
211 #define FC_FPORT_PORTID 0x00000e
212 #define FC_FABCTLR_PORTID 0x00000d
213 #define FC_DIRSRVR_PORTID 0x00000c
214 #define FC_TIMESRVR_PORTID 0x00000b
215 #define FC_MGMTSRVR_PORTID 0x00000a
218 static void fc_timeout_deleted_rport(void *data);
219 static void fc_scsi_scan_rport(void *data);
222 * Attribute counts pre object type...
223 * Increase these values if you add attributes
225 #define FC_STARGET_NUM_ATTRS 3
226 #define FC_RPORT_NUM_ATTRS 9
227 #define FC_HOST_NUM_ATTRS 17
230 struct scsi_transport_template t;
231 struct fc_function_template *f;
234 * For attributes : each object has :
235 * An array of the actual attributes structures
236 * An array of null-terminated pointers to the attribute
237 * structures - used for mid-layer interaction.
239 * The attribute containers for the starget and host are are
240 * part of the midlayer. As the remote port is specific to the
241 * fc transport, we must provide the attribute container.
243 struct class_device_attribute private_starget_attrs[
244 FC_STARGET_NUM_ATTRS];
245 struct class_device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1];
247 struct class_device_attribute private_host_attrs[FC_HOST_NUM_ATTRS];
248 struct class_device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1];
250 struct transport_container rport_attr_cont;
251 struct class_device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS];
252 struct class_device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1];
255 #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t)
257 static int fc_target_setup(struct transport_container *tc, struct device *dev,
258 struct class_device *cdev)
260 struct scsi_target *starget = to_scsi_target(dev);
261 struct fc_rport *rport = starget_to_rport(starget);
264 * if parent is remote port, use values from remote port.
265 * Otherwise, this host uses the fc_transport, but not the
266 * remote port interface. As such, initialize to known non-values.
269 fc_starget_node_name(starget) = rport->node_name;
270 fc_starget_port_name(starget) = rport->port_name;
271 fc_starget_port_id(starget) = rport->port_id;
273 fc_starget_node_name(starget) = -1;
274 fc_starget_port_name(starget) = -1;
275 fc_starget_port_id(starget) = -1;
281 static DECLARE_TRANSPORT_CLASS(fc_transport_class,
287 static int fc_host_setup(struct transport_container *tc, struct device *dev,
288 struct class_device *cdev)
290 struct Scsi_Host *shost = dev_to_shost(dev);
291 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
294 * Set default values easily detected by the midlayer as
295 * failure cases. The scsi lldd is responsible for initializing
296 * all transport attributes to valid values per host.
298 fc_host->node_name = -1;
299 fc_host->port_name = -1;
300 fc_host->permanent_port_name = -1;
301 fc_host->supported_classes = FC_COS_UNSPECIFIED;
302 memset(fc_host->supported_fc4s, 0,
303 sizeof(fc_host->supported_fc4s));
304 fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN;
305 fc_host->maxframe_size = -1;
306 memset(fc_host->serial_number, 0,
307 sizeof(fc_host->serial_number));
309 fc_host->port_id = -1;
310 fc_host->port_type = FC_PORTTYPE_UNKNOWN;
311 fc_host->port_state = FC_PORTSTATE_UNKNOWN;
312 memset(fc_host->active_fc4s, 0,
313 sizeof(fc_host->active_fc4s));
314 fc_host->speed = FC_PORTSPEED_UNKNOWN;
315 fc_host->fabric_name = -1;
316 memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name));
317 memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname));
319 fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN;
321 INIT_LIST_HEAD(&fc_host->rports);
322 INIT_LIST_HEAD(&fc_host->rport_bindings);
323 fc_host->next_rport_number = 0;
324 fc_host->next_target_id = 0;
326 snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d",
328 fc_host->work_q = create_singlethread_workqueue(
329 fc_host->work_q_name);
330 if (!fc_host->work_q)
333 snprintf(fc_host->devloss_work_q_name, KOBJ_NAME_LEN, "fc_dl_%d",
335 fc_host->devloss_work_q = create_singlethread_workqueue(
336 fc_host->devloss_work_q_name);
337 if (!fc_host->devloss_work_q) {
338 destroy_workqueue(fc_host->work_q);
339 fc_host->work_q = NULL;
346 static DECLARE_TRANSPORT_CLASS(fc_host_class,
353 * Setup and Remove actions for remote ports are handled
354 * in the service functions below.
356 static DECLARE_TRANSPORT_CLASS(fc_rport_class,
367 * dev_loss_tmo: the default number of seconds that the FC transport
368 * should insulate the loss of a remote port.
369 * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
371 static unsigned int fc_dev_loss_tmo = 60; /* seconds */
373 module_param_named(dev_loss_tmo, fc_dev_loss_tmo, int, S_IRUGO|S_IWUSR);
374 MODULE_PARM_DESC(dev_loss_tmo,
375 "Maximum number of seconds that the FC transport should"
376 " insulate the loss of a remote port. Once this value is"
377 " exceeded, the scsi target is removed. Value should be"
378 " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT.");
381 static __init int fc_transport_init(void)
383 int error = transport_class_register(&fc_host_class);
386 error = transport_class_register(&fc_rport_class);
389 return transport_class_register(&fc_transport_class);
392 static void __exit fc_transport_exit(void)
394 transport_class_unregister(&fc_transport_class);
395 transport_class_unregister(&fc_rport_class);
396 transport_class_unregister(&fc_host_class);
400 * FC Remote Port Attribute Management
403 #define fc_rport_show_function(field, format_string, sz, cast) \
405 show_fc_rport_##field (struct class_device *cdev, char *buf) \
407 struct fc_rport *rport = transport_class_to_rport(cdev); \
408 struct Scsi_Host *shost = rport_to_shost(rport); \
409 struct fc_internal *i = to_fc_internal(shost->transportt); \
410 if ((i->f->get_rport_##field) && \
411 !((rport->port_state == FC_PORTSTATE_BLOCKED) || \
412 (rport->port_state == FC_PORTSTATE_DELETED) || \
413 (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \
414 i->f->get_rport_##field(rport); \
415 return snprintf(buf, sz, format_string, cast rport->field); \
418 #define fc_rport_store_function(field) \
420 store_fc_rport_##field(struct class_device *cdev, const char *buf, \
424 struct fc_rport *rport = transport_class_to_rport(cdev); \
425 struct Scsi_Host *shost = rport_to_shost(rport); \
426 struct fc_internal *i = to_fc_internal(shost->transportt); \
427 if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \
428 (rport->port_state == FC_PORTSTATE_DELETED) || \
429 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \
431 val = simple_strtoul(buf, NULL, 0); \
432 i->f->set_rport_##field(rport, val); \
436 #define fc_rport_rd_attr(field, format_string, sz) \
437 fc_rport_show_function(field, format_string, sz, ) \
438 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
439 show_fc_rport_##field, NULL)
441 #define fc_rport_rd_attr_cast(field, format_string, sz, cast) \
442 fc_rport_show_function(field, format_string, sz, (cast)) \
443 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
444 show_fc_rport_##field, NULL)
446 #define fc_rport_rw_attr(field, format_string, sz) \
447 fc_rport_show_function(field, format_string, sz, ) \
448 fc_rport_store_function(field) \
449 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \
450 show_fc_rport_##field, \
451 store_fc_rport_##field)
454 #define fc_private_rport_show_function(field, format_string, sz, cast) \
456 show_fc_rport_##field (struct class_device *cdev, char *buf) \
458 struct fc_rport *rport = transport_class_to_rport(cdev); \
459 return snprintf(buf, sz, format_string, cast rport->field); \
462 #define fc_private_rport_rd_attr(field, format_string, sz) \
463 fc_private_rport_show_function(field, format_string, sz, ) \
464 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
465 show_fc_rport_##field, NULL)
467 #define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \
468 fc_private_rport_show_function(field, format_string, sz, (cast)) \
469 static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
470 show_fc_rport_##field, NULL)
473 #define fc_private_rport_rd_enum_attr(title, maxlen) \
475 show_fc_rport_##title (struct class_device *cdev, char *buf) \
477 struct fc_rport *rport = transport_class_to_rport(cdev); \
479 name = get_fc_##title##_name(rport->title); \
482 return snprintf(buf, maxlen, "%s\n", name); \
484 static FC_CLASS_DEVICE_ATTR(rport, title, S_IRUGO, \
485 show_fc_rport_##title, NULL)
488 #define SETUP_RPORT_ATTRIBUTE_RD(field) \
489 i->private_rport_attrs[count] = class_device_attr_rport_##field; \
490 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
491 i->private_rport_attrs[count].store = NULL; \
492 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
493 if (i->f->show_rport_##field) \
496 #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \
497 i->private_rport_attrs[count] = class_device_attr_rport_##field; \
498 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
499 i->private_rport_attrs[count].store = NULL; \
500 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
503 #define SETUP_RPORT_ATTRIBUTE_RW(field) \
504 i->private_rport_attrs[count] = class_device_attr_rport_##field; \
505 if (!i->f->set_rport_##field) { \
506 i->private_rport_attrs[count].attr.mode = S_IRUGO; \
507 i->private_rport_attrs[count].store = NULL; \
509 i->rport_attrs[count] = &i->private_rport_attrs[count]; \
510 if (i->f->show_rport_##field) \
514 /* The FC Transport Remote Port Attributes: */
516 /* Fixed Remote Port Attributes */
518 fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20);
521 show_fc_rport_supported_classes (struct class_device *cdev, char *buf)
523 struct fc_rport *rport = transport_class_to_rport(cdev);
524 if (rport->supported_classes == FC_COS_UNSPECIFIED)
525 return snprintf(buf, 20, "unspecified\n");
526 return get_fc_cos_names(rport->supported_classes, buf);
528 static FC_CLASS_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
529 show_fc_rport_supported_classes, NULL);
531 /* Dynamic Remote Port Attributes */
534 * dev_loss_tmo attribute
536 fc_rport_show_function(dev_loss_tmo, "%d\n", 20, )
538 store_fc_rport_dev_loss_tmo(struct class_device *cdev, const char *buf,
542 struct fc_rport *rport = transport_class_to_rport(cdev);
543 struct Scsi_Host *shost = rport_to_shost(rport);
544 struct fc_internal *i = to_fc_internal(shost->transportt);
545 if ((rport->port_state == FC_PORTSTATE_BLOCKED) ||
546 (rport->port_state == FC_PORTSTATE_DELETED) ||
547 (rport->port_state == FC_PORTSTATE_NOTPRESENT))
549 val = simple_strtoul(buf, NULL, 0);
550 if ((val < 0) || (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT))
552 i->f->set_rport_dev_loss_tmo(rport, val);
555 static FC_CLASS_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR,
556 show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo);
559 /* Private Remote Port Attributes */
561 fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
562 fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
563 fc_private_rport_rd_attr(port_id, "0x%06x\n", 20);
566 show_fc_rport_roles (struct class_device *cdev, char *buf)
568 struct fc_rport *rport = transport_class_to_rport(cdev);
570 /* identify any roles that are port_id specific */
571 if ((rport->port_id != -1) &&
572 (rport->port_id & FC_WELLKNOWN_PORTID_MASK) ==
573 FC_WELLKNOWN_PORTID_MASK) {
574 switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
575 case FC_FPORT_PORTID:
576 return snprintf(buf, 30, "Fabric Port\n");
577 case FC_FABCTLR_PORTID:
578 return snprintf(buf, 30, "Fabric Controller\n");
579 case FC_DIRSRVR_PORTID:
580 return snprintf(buf, 30, "Directory Server\n");
581 case FC_TIMESRVR_PORTID:
582 return snprintf(buf, 30, "Time Server\n");
583 case FC_MGMTSRVR_PORTID:
584 return snprintf(buf, 30, "Management Server\n");
586 return snprintf(buf, 30, "Unknown Fabric Entity\n");
589 if (rport->roles == FC_RPORT_ROLE_UNKNOWN)
590 return snprintf(buf, 20, "unknown\n");
591 return get_fc_remote_port_roles_names(rport->roles, buf);
594 static FC_CLASS_DEVICE_ATTR(rport, roles, S_IRUGO,
595 show_fc_rport_roles, NULL);
597 fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
598 fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);
603 * FC SCSI Target Attribute Management
607 * Note: in the target show function we recognize when the remote
608 * port is in the heirarchy and do not allow the driver to get
609 * involved in sysfs functions. The driver only gets involved if
610 * it's the "old" style that doesn't use rports.
612 #define fc_starget_show_function(field, format_string, sz, cast) \
614 show_fc_starget_##field (struct class_device *cdev, char *buf) \
616 struct scsi_target *starget = transport_class_to_starget(cdev); \
617 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
618 struct fc_internal *i = to_fc_internal(shost->transportt); \
619 struct fc_rport *rport = starget_to_rport(starget); \
621 fc_starget_##field(starget) = rport->field; \
622 else if (i->f->get_starget_##field) \
623 i->f->get_starget_##field(starget); \
624 return snprintf(buf, sz, format_string, \
625 cast fc_starget_##field(starget)); \
628 #define fc_starget_rd_attr(field, format_string, sz) \
629 fc_starget_show_function(field, format_string, sz, ) \
630 static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
631 show_fc_starget_##field, NULL)
633 #define fc_starget_rd_attr_cast(field, format_string, sz, cast) \
634 fc_starget_show_function(field, format_string, sz, (cast)) \
635 static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
636 show_fc_starget_##field, NULL)
638 #define SETUP_STARGET_ATTRIBUTE_RD(field) \
639 i->private_starget_attrs[count] = class_device_attr_starget_##field; \
640 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
641 i->private_starget_attrs[count].store = NULL; \
642 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
643 if (i->f->show_starget_##field) \
646 #define SETUP_STARGET_ATTRIBUTE_RW(field) \
647 i->private_starget_attrs[count] = class_device_attr_starget_##field; \
648 if (!i->f->set_starget_##field) { \
649 i->private_starget_attrs[count].attr.mode = S_IRUGO; \
650 i->private_starget_attrs[count].store = NULL; \
652 i->starget_attrs[count] = &i->private_starget_attrs[count]; \
653 if (i->f->show_starget_##field) \
656 /* The FC Transport SCSI Target Attributes: */
657 fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
658 fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
659 fc_starget_rd_attr(port_id, "0x%06x\n", 20);
663 * Host Attribute Management
666 #define fc_host_show_function(field, format_string, sz, cast) \
668 show_fc_host_##field (struct class_device *cdev, char *buf) \
670 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
671 struct fc_internal *i = to_fc_internal(shost->transportt); \
672 if (i->f->get_host_##field) \
673 i->f->get_host_##field(shost); \
674 return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
677 #define fc_host_store_function(field) \
679 store_fc_host_##field(struct class_device *cdev, const char *buf, \
683 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
684 struct fc_internal *i = to_fc_internal(shost->transportt); \
686 val = simple_strtoul(buf, NULL, 0); \
687 i->f->set_host_##field(shost, val); \
691 #define fc_host_store_str_function(field, slen) \
693 store_fc_host_##field(struct class_device *cdev, const char *buf, \
696 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
697 struct fc_internal *i = to_fc_internal(shost->transportt); \
698 unsigned int cnt=count; \
700 /* count may include a LF at end of string */ \
701 if (buf[cnt-1] == '\n') \
703 if (cnt > ((slen) - 1)) \
705 memcpy(fc_host_##field(shost), buf, cnt); \
706 i->f->set_host_##field(shost); \
710 #define fc_host_rd_attr(field, format_string, sz) \
711 fc_host_show_function(field, format_string, sz, ) \
712 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
713 show_fc_host_##field, NULL)
715 #define fc_host_rd_attr_cast(field, format_string, sz, cast) \
716 fc_host_show_function(field, format_string, sz, (cast)) \
717 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
718 show_fc_host_##field, NULL)
720 #define fc_host_rw_attr(field, format_string, sz) \
721 fc_host_show_function(field, format_string, sz, ) \
722 fc_host_store_function(field) \
723 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \
724 show_fc_host_##field, \
725 store_fc_host_##field)
727 #define fc_host_rd_enum_attr(title, maxlen) \
729 show_fc_host_##title (struct class_device *cdev, char *buf) \
731 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
732 struct fc_internal *i = to_fc_internal(shost->transportt); \
734 if (i->f->get_host_##title) \
735 i->f->get_host_##title(shost); \
736 name = get_fc_##title##_name(fc_host_##title(shost)); \
739 return snprintf(buf, maxlen, "%s\n", name); \
741 static FC_CLASS_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
743 #define SETUP_HOST_ATTRIBUTE_RD(field) \
744 i->private_host_attrs[count] = class_device_attr_host_##field; \
745 i->private_host_attrs[count].attr.mode = S_IRUGO; \
746 i->private_host_attrs[count].store = NULL; \
747 i->host_attrs[count] = &i->private_host_attrs[count]; \
748 if (i->f->show_host_##field) \
751 #define SETUP_HOST_ATTRIBUTE_RW(field) \
752 i->private_host_attrs[count] = class_device_attr_host_##field; \
753 if (!i->f->set_host_##field) { \
754 i->private_host_attrs[count].attr.mode = S_IRUGO; \
755 i->private_host_attrs[count].store = NULL; \
757 i->host_attrs[count] = &i->private_host_attrs[count]; \
758 if (i->f->show_host_##field) \
762 #define fc_private_host_show_function(field, format_string, sz, cast) \
764 show_fc_host_##field (struct class_device *cdev, char *buf) \
766 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
767 return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
770 #define fc_private_host_rd_attr(field, format_string, sz) \
771 fc_private_host_show_function(field, format_string, sz, ) \
772 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
773 show_fc_host_##field, NULL)
775 #define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \
776 fc_private_host_show_function(field, format_string, sz, (cast)) \
777 static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
778 show_fc_host_##field, NULL)
780 #define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \
781 i->private_host_attrs[count] = class_device_attr_host_##field; \
782 i->private_host_attrs[count].attr.mode = S_IRUGO; \
783 i->private_host_attrs[count].store = NULL; \
784 i->host_attrs[count] = &i->private_host_attrs[count]; \
787 #define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \
789 i->private_host_attrs[count] = class_device_attr_host_##field; \
790 i->host_attrs[count] = &i->private_host_attrs[count]; \
795 /* Fixed Host Attributes */
798 show_fc_host_supported_classes (struct class_device *cdev, char *buf)
800 struct Scsi_Host *shost = transport_class_to_shost(cdev);
802 if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
803 return snprintf(buf, 20, "unspecified\n");
805 return get_fc_cos_names(fc_host_supported_classes(shost), buf);
807 static FC_CLASS_DEVICE_ATTR(host, supported_classes, S_IRUGO,
808 show_fc_host_supported_classes, NULL);
811 show_fc_host_supported_fc4s (struct class_device *cdev, char *buf)
813 struct Scsi_Host *shost = transport_class_to_shost(cdev);
814 return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost));
816 static FC_CLASS_DEVICE_ATTR(host, supported_fc4s, S_IRUGO,
817 show_fc_host_supported_fc4s, NULL);
820 show_fc_host_supported_speeds (struct class_device *cdev, char *buf)
822 struct Scsi_Host *shost = transport_class_to_shost(cdev);
824 if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
825 return snprintf(buf, 20, "unknown\n");
827 return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
829 static FC_CLASS_DEVICE_ATTR(host, supported_speeds, S_IRUGO,
830 show_fc_host_supported_speeds, NULL);
833 fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
834 fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
835 fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20,
837 fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20);
838 fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1));
841 /* Dynamic Host Attributes */
844 show_fc_host_active_fc4s (struct class_device *cdev, char *buf)
846 struct Scsi_Host *shost = transport_class_to_shost(cdev);
847 struct fc_internal *i = to_fc_internal(shost->transportt);
849 if (i->f->get_host_active_fc4s)
850 i->f->get_host_active_fc4s(shost);
852 return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost));
854 static FC_CLASS_DEVICE_ATTR(host, active_fc4s, S_IRUGO,
855 show_fc_host_active_fc4s, NULL);
858 show_fc_host_speed (struct class_device *cdev, char *buf)
860 struct Scsi_Host *shost = transport_class_to_shost(cdev);
861 struct fc_internal *i = to_fc_internal(shost->transportt);
863 if (i->f->get_host_speed)
864 i->f->get_host_speed(shost);
866 if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
867 return snprintf(buf, 20, "unknown\n");
869 return get_fc_port_speed_names(fc_host_speed(shost), buf);
871 static FC_CLASS_DEVICE_ATTR(host, speed, S_IRUGO,
872 show_fc_host_speed, NULL);
875 fc_host_rd_attr(port_id, "0x%06x\n", 20);
876 fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
877 fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
878 fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
879 fc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1);
881 fc_private_host_show_function(system_hostname, "%s\n",
882 FC_SYMBOLIC_NAME_SIZE + 1, )
883 fc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE)
884 static FC_CLASS_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR,
885 show_fc_host_system_hostname, store_fc_host_system_hostname);
888 /* Private Host Attributes */
891 show_fc_private_host_tgtid_bind_type(struct class_device *cdev, char *buf)
893 struct Scsi_Host *shost = transport_class_to_shost(cdev);
896 name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost));
899 return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name);
902 #define get_list_head_entry(pos, head, member) \
903 pos = list_entry((head)->next, typeof(*pos), member)
906 store_fc_private_host_tgtid_bind_type(struct class_device *cdev,
907 const char *buf, size_t count)
909 struct Scsi_Host *shost = transport_class_to_shost(cdev);
910 struct fc_rport *rport;
911 enum fc_tgtid_binding_type val;
914 if (get_fc_tgtid_bind_type_match(buf, &val))
917 /* if changing bind type, purge all unused consistent bindings */
918 if (val != fc_host_tgtid_bind_type(shost)) {
919 spin_lock_irqsave(shost->host_lock, flags);
920 while (!list_empty(&fc_host_rport_bindings(shost))) {
921 get_list_head_entry(rport,
922 &fc_host_rport_bindings(shost), peers);
923 list_del(&rport->peers);
924 rport->port_state = FC_PORTSTATE_DELETED;
925 fc_queue_work(shost, &rport->rport_delete_work);
927 spin_unlock_irqrestore(shost->host_lock, flags);
930 fc_host_tgtid_bind_type(shost) = val;
934 static FC_CLASS_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR,
935 show_fc_private_host_tgtid_bind_type,
936 store_fc_private_host_tgtid_bind_type);
939 store_fc_private_host_issue_lip(struct class_device *cdev,
940 const char *buf, size_t count)
942 struct Scsi_Host *shost = transport_class_to_shost(cdev);
943 struct fc_internal *i = to_fc_internal(shost->transportt);
946 /* ignore any data value written to the attribute */
947 if (i->f->issue_fc_host_lip) {
948 ret = i->f->issue_fc_host_lip(shost);
949 return ret ? ret: count;
955 static FC_CLASS_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL,
956 store_fc_private_host_issue_lip);
959 * Host Statistics Management
962 /* Show a given an attribute in the statistics group */
964 fc_stat_show(const struct class_device *cdev, char *buf, unsigned long offset)
966 struct Scsi_Host *shost = transport_class_to_shost(cdev);
967 struct fc_internal *i = to_fc_internal(shost->transportt);
968 struct fc_host_statistics *stats;
969 ssize_t ret = -ENOENT;
971 if (offset > sizeof(struct fc_host_statistics) ||
972 offset % sizeof(u64) != 0)
975 if (i->f->get_fc_host_stats) {
976 stats = (i->f->get_fc_host_stats)(shost);
978 ret = snprintf(buf, 20, "0x%llx\n",
979 (unsigned long long)*(u64 *)(((u8 *) stats) + offset));
985 /* generate a read-only statistics attribute */
986 #define fc_host_statistic(name) \
987 static ssize_t show_fcstat_##name(struct class_device *cd, char *buf) \
989 return fc_stat_show(cd, buf, \
990 offsetof(struct fc_host_statistics, name)); \
992 static FC_CLASS_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
994 fc_host_statistic(seconds_since_last_reset);
995 fc_host_statistic(tx_frames);
996 fc_host_statistic(tx_words);
997 fc_host_statistic(rx_frames);
998 fc_host_statistic(rx_words);
999 fc_host_statistic(lip_count);
1000 fc_host_statistic(nos_count);
1001 fc_host_statistic(error_frames);
1002 fc_host_statistic(dumped_frames);
1003 fc_host_statistic(link_failure_count);
1004 fc_host_statistic(loss_of_sync_count);
1005 fc_host_statistic(loss_of_signal_count);
1006 fc_host_statistic(prim_seq_protocol_err_count);
1007 fc_host_statistic(invalid_tx_word_count);
1008 fc_host_statistic(invalid_crc_count);
1009 fc_host_statistic(fcp_input_requests);
1010 fc_host_statistic(fcp_output_requests);
1011 fc_host_statistic(fcp_control_requests);
1012 fc_host_statistic(fcp_input_megabytes);
1013 fc_host_statistic(fcp_output_megabytes);
1016 fc_reset_statistics(struct class_device *cdev, const char *buf,
1019 struct Scsi_Host *shost = transport_class_to_shost(cdev);
1020 struct fc_internal *i = to_fc_internal(shost->transportt);
1022 /* ignore any data value written to the attribute */
1023 if (i->f->reset_fc_host_stats) {
1024 i->f->reset_fc_host_stats(shost);
1030 static FC_CLASS_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL,
1031 fc_reset_statistics);
1034 static struct attribute *fc_statistics_attrs[] = {
1035 &class_device_attr_host_seconds_since_last_reset.attr,
1036 &class_device_attr_host_tx_frames.attr,
1037 &class_device_attr_host_tx_words.attr,
1038 &class_device_attr_host_rx_frames.attr,
1039 &class_device_attr_host_rx_words.attr,
1040 &class_device_attr_host_lip_count.attr,
1041 &class_device_attr_host_nos_count.attr,
1042 &class_device_attr_host_error_frames.attr,
1043 &class_device_attr_host_dumped_frames.attr,
1044 &class_device_attr_host_link_failure_count.attr,
1045 &class_device_attr_host_loss_of_sync_count.attr,
1046 &class_device_attr_host_loss_of_signal_count.attr,
1047 &class_device_attr_host_prim_seq_protocol_err_count.attr,
1048 &class_device_attr_host_invalid_tx_word_count.attr,
1049 &class_device_attr_host_invalid_crc_count.attr,
1050 &class_device_attr_host_fcp_input_requests.attr,
1051 &class_device_attr_host_fcp_output_requests.attr,
1052 &class_device_attr_host_fcp_control_requests.attr,
1053 &class_device_attr_host_fcp_input_megabytes.attr,
1054 &class_device_attr_host_fcp_output_megabytes.attr,
1055 &class_device_attr_host_reset_statistics.attr,
1059 static struct attribute_group fc_statistics_group = {
1060 .name = "statistics",
1061 .attrs = fc_statistics_attrs,
1064 static int fc_host_match(struct attribute_container *cont,
1067 struct Scsi_Host *shost;
1068 struct fc_internal *i;
1070 if (!scsi_is_host_device(dev))
1073 shost = dev_to_shost(dev);
1074 if (!shost->transportt || shost->transportt->host_attrs.ac.class
1075 != &fc_host_class.class)
1078 i = to_fc_internal(shost->transportt);
1080 return &i->t.host_attrs.ac == cont;
1083 static int fc_target_match(struct attribute_container *cont,
1086 struct Scsi_Host *shost;
1087 struct fc_internal *i;
1089 if (!scsi_is_target_device(dev))
1092 shost = dev_to_shost(dev->parent);
1093 if (!shost->transportt || shost->transportt->host_attrs.ac.class
1094 != &fc_host_class.class)
1097 i = to_fc_internal(shost->transportt);
1099 return &i->t.target_attrs.ac == cont;
1102 static void fc_rport_dev_release(struct device *dev)
1104 struct fc_rport *rport = dev_to_rport(dev);
1105 put_device(dev->parent);
1109 int scsi_is_fc_rport(const struct device *dev)
1111 return dev->release == fc_rport_dev_release;
1113 EXPORT_SYMBOL(scsi_is_fc_rport);
1115 static int fc_rport_match(struct attribute_container *cont,
1118 struct Scsi_Host *shost;
1119 struct fc_internal *i;
1121 if (!scsi_is_fc_rport(dev))
1124 shost = dev_to_shost(dev->parent);
1125 if (!shost->transportt || shost->transportt->host_attrs.ac.class
1126 != &fc_host_class.class)
1129 i = to_fc_internal(shost->transportt);
1131 return &i->rport_attr_cont.ac == cont;
1136 * fc_timed_out - FC Transport I/O timeout intercept handler
1138 * @scmd: The SCSI command which timed out
1140 * This routine protects against error handlers getting invoked while a
1141 * rport is in a blocked state, typically due to a temporarily loss of
1142 * connectivity. If the error handlers are allowed to proceed, requests
1143 * to abort i/o, reset the target, etc will likely fail as there is no way
1144 * to communicate with the device to perform the requested function. These
1145 * failures may result in the midlayer taking the device offline, requiring
1146 * manual intervention to restore operation.
1148 * This routine, called whenever an i/o times out, validates the state of
1149 * the underlying rport. If the rport is blocked, it returns
1150 * EH_RESET_TIMER, which will continue to reschedule the timeout.
1151 * Eventually, either the device will return, or devloss_tmo will fire,
1152 * and when the timeout then fires, it will be handled normally.
1153 * If the rport is not blocked, normal error handling continues.
1156 * This routine assumes no locks are held on entry.
1158 static enum scsi_eh_timer_return
1159 fc_timed_out(struct scsi_cmnd *scmd)
1161 struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device));
1163 if (rport->port_state == FC_PORTSTATE_BLOCKED)
1164 return EH_RESET_TIMER;
1166 return EH_NOT_HANDLED;
1170 * Must be called with shost->host_lock held
1172 static int fc_user_scan(struct Scsi_Host *shost, uint channel,
1175 struct fc_rport *rport;
1177 list_for_each_entry(rport, &fc_host_rports(shost), peers) {
1178 if (rport->scsi_target_id == -1)
1181 if ((channel == SCAN_WILD_CARD || channel == rport->channel) &&
1182 (id == SCAN_WILD_CARD || id == rport->scsi_target_id)) {
1183 scsi_scan_target(&rport->dev, rport->channel,
1184 rport->scsi_target_id, lun, 1);
1191 struct scsi_transport_template *
1192 fc_attach_transport(struct fc_function_template *ft)
1195 struct fc_internal *i = kzalloc(sizeof(struct fc_internal),
1201 i->t.target_attrs.ac.attrs = &i->starget_attrs[0];
1202 i->t.target_attrs.ac.class = &fc_transport_class.class;
1203 i->t.target_attrs.ac.match = fc_target_match;
1204 i->t.target_size = sizeof(struct fc_starget_attrs);
1205 transport_container_register(&i->t.target_attrs);
1207 i->t.host_attrs.ac.attrs = &i->host_attrs[0];
1208 i->t.host_attrs.ac.class = &fc_host_class.class;
1209 i->t.host_attrs.ac.match = fc_host_match;
1210 i->t.host_size = sizeof(struct fc_host_attrs);
1211 if (ft->get_fc_host_stats)
1212 i->t.host_attrs.statistics = &fc_statistics_group;
1213 transport_container_register(&i->t.host_attrs);
1215 i->rport_attr_cont.ac.attrs = &i->rport_attrs[0];
1216 i->rport_attr_cont.ac.class = &fc_rport_class.class;
1217 i->rport_attr_cont.ac.match = fc_rport_match;
1218 transport_container_register(&i->rport_attr_cont);
1222 /* Transport uses the shost workq for scsi scanning */
1223 i->t.create_work_queue = 1;
1225 i->t.eh_timed_out = fc_timed_out;
1227 i->t.user_scan = fc_user_scan;
1230 * Setup SCSI Target Attributes.
1233 SETUP_STARGET_ATTRIBUTE_RD(node_name);
1234 SETUP_STARGET_ATTRIBUTE_RD(port_name);
1235 SETUP_STARGET_ATTRIBUTE_RD(port_id);
1237 BUG_ON(count > FC_STARGET_NUM_ATTRS);
1239 i->starget_attrs[count] = NULL;
1243 * Setup SCSI Host Attributes.
1246 SETUP_HOST_ATTRIBUTE_RD(node_name);
1247 SETUP_HOST_ATTRIBUTE_RD(port_name);
1248 SETUP_HOST_ATTRIBUTE_RD(permanent_port_name);
1249 SETUP_HOST_ATTRIBUTE_RD(supported_classes);
1250 SETUP_HOST_ATTRIBUTE_RD(supported_fc4s);
1251 SETUP_HOST_ATTRIBUTE_RD(supported_speeds);
1252 SETUP_HOST_ATTRIBUTE_RD(maxframe_size);
1253 SETUP_HOST_ATTRIBUTE_RD(serial_number);
1255 SETUP_HOST_ATTRIBUTE_RD(port_id);
1256 SETUP_HOST_ATTRIBUTE_RD(port_type);
1257 SETUP_HOST_ATTRIBUTE_RD(port_state);
1258 SETUP_HOST_ATTRIBUTE_RD(active_fc4s);
1259 SETUP_HOST_ATTRIBUTE_RD(speed);
1260 SETUP_HOST_ATTRIBUTE_RD(fabric_name);
1261 SETUP_HOST_ATTRIBUTE_RD(symbolic_name);
1262 SETUP_HOST_ATTRIBUTE_RW(system_hostname);
1264 /* Transport-managed attributes */
1265 SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type);
1266 if (ft->issue_fc_host_lip)
1267 SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip);
1269 BUG_ON(count > FC_HOST_NUM_ATTRS);
1271 i->host_attrs[count] = NULL;
1274 * Setup Remote Port Attributes.
1277 SETUP_RPORT_ATTRIBUTE_RD(maxframe_size);
1278 SETUP_RPORT_ATTRIBUTE_RD(supported_classes);
1279 SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo);
1280 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name);
1281 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name);
1282 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id);
1283 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles);
1284 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state);
1285 SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id);
1287 BUG_ON(count > FC_RPORT_NUM_ATTRS);
1289 i->rport_attrs[count] = NULL;
1293 EXPORT_SYMBOL(fc_attach_transport);
1295 void fc_release_transport(struct scsi_transport_template *t)
1297 struct fc_internal *i = to_fc_internal(t);
1299 transport_container_unregister(&i->t.target_attrs);
1300 transport_container_unregister(&i->t.host_attrs);
1301 transport_container_unregister(&i->rport_attr_cont);
1305 EXPORT_SYMBOL(fc_release_transport);
1308 * fc_queue_work - Queue work to the fc_host workqueue.
1309 * @shost: Pointer to Scsi_Host bound to fc_host.
1310 * @work: Work to queue for execution.
1313 * 1 - work queued for execution
1314 * 0 - work is already queued
1315 * -EINVAL - work queue doesn't exist
1318 fc_queue_work(struct Scsi_Host *shost, struct work_struct *work)
1320 if (unlikely(!fc_host_work_q(shost))) {
1322 "ERROR: FC host '%s' attempted to queue work, "
1323 "when no workqueue created.\n", shost->hostt->name);
1329 return queue_work(fc_host_work_q(shost), work);
1333 * fc_flush_work - Flush a fc_host's workqueue.
1334 * @shost: Pointer to Scsi_Host bound to fc_host.
1337 fc_flush_work(struct Scsi_Host *shost)
1339 if (!fc_host_work_q(shost)) {
1341 "ERROR: FC host '%s' attempted to flush work, "
1342 "when no workqueue created.\n", shost->hostt->name);
1347 flush_workqueue(fc_host_work_q(shost));
1351 * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue.
1352 * @shost: Pointer to Scsi_Host bound to fc_host.
1353 * @work: Work to queue for execution.
1354 * @delay: jiffies to delay the work queuing
1357 * 0 on success / != 0 for error
1360 fc_queue_devloss_work(struct Scsi_Host *shost, struct work_struct *work,
1361 unsigned long delay)
1363 if (unlikely(!fc_host_devloss_work_q(shost))) {
1365 "ERROR: FC host '%s' attempted to queue work, "
1366 "when no workqueue created.\n", shost->hostt->name);
1372 return queue_delayed_work(fc_host_devloss_work_q(shost), work, delay);
1376 * fc_flush_devloss - Flush a fc_host's devloss workqueue.
1377 * @shost: Pointer to Scsi_Host bound to fc_host.
1380 fc_flush_devloss(struct Scsi_Host *shost)
1382 if (!fc_host_devloss_work_q(shost)) {
1384 "ERROR: FC host '%s' attempted to flush work, "
1385 "when no workqueue created.\n", shost->hostt->name);
1390 flush_workqueue(fc_host_devloss_work_q(shost));
1395 * fc_remove_host - called to terminate any fc_transport-related elements
1397 * @rport: remote port to be unblocked.
1399 * This routine is expected to be called immediately preceeding the
1400 * a driver's call to scsi_remove_host().
1402 * WARNING: A driver utilizing the fc_transport, which fails to call
1403 * this routine prior to scsi_remote_host(), will leave dangling
1404 * objects in /sys/class/fc_remote_ports. Access to any of these
1405 * objects can result in a system crash !!!
1408 * This routine assumes no locks are held on entry.
1411 fc_remove_host(struct Scsi_Host *shost)
1413 struct fc_rport *rport, *next_rport;
1414 struct workqueue_struct *work_q;
1415 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1417 /* Remove any remote ports */
1418 list_for_each_entry_safe(rport, next_rport,
1419 &fc_host->rports, peers) {
1420 list_del(&rport->peers);
1421 rport->port_state = FC_PORTSTATE_DELETED;
1422 fc_queue_work(shost, &rport->rport_delete_work);
1425 list_for_each_entry_safe(rport, next_rport,
1426 &fc_host->rport_bindings, peers) {
1427 list_del(&rport->peers);
1428 rport->port_state = FC_PORTSTATE_DELETED;
1429 fc_queue_work(shost, &rport->rport_delete_work);
1432 /* flush all scan work items */
1433 scsi_flush_work(shost);
1435 /* flush all stgt delete, and rport delete work items, then kill it */
1436 if (fc_host->work_q) {
1437 work_q = fc_host->work_q;
1438 fc_host->work_q = NULL;
1439 destroy_workqueue(work_q);
1442 /* flush all devloss work items, then kill it */
1443 if (fc_host->devloss_work_q) {
1444 work_q = fc_host->devloss_work_q;
1445 fc_host->devloss_work_q = NULL;
1446 destroy_workqueue(work_q);
1449 EXPORT_SYMBOL(fc_remove_host);
1453 * fc_starget_delete - called to delete the scsi decendents of an rport
1454 * (target and all sdevs)
1456 * @data: remote port to be operated on.
1459 fc_starget_delete(void *data)
1461 struct fc_rport *rport = (struct fc_rport *)data;
1462 struct Scsi_Host *shost = rport_to_shost(rport);
1463 unsigned long flags;
1465 spin_lock_irqsave(shost->host_lock, flags);
1466 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
1467 spin_unlock_irqrestore(shost->host_lock, flags);
1468 if (!cancel_delayed_work(&rport->dev_loss_work))
1469 fc_flush_devloss(shost);
1470 spin_lock_irqsave(shost->host_lock, flags);
1471 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1473 spin_unlock_irqrestore(shost->host_lock, flags);
1475 scsi_remove_target(&rport->dev);
1480 * fc_rport_final_delete - finish rport termination and delete it.
1482 * @data: remote port to be deleted.
1485 fc_rport_final_delete(void *data)
1487 struct fc_rport *rport = (struct fc_rport *)data;
1488 struct device *dev = &rport->dev;
1489 struct Scsi_Host *shost = rport_to_shost(rport);
1491 /* Delete SCSI target and sdevs */
1492 if (rport->scsi_target_id != -1)
1493 fc_starget_delete(data);
1496 * if a scan is pending, flush the SCSI Host work_q so that
1497 * that we can reclaim the rport scan work element.
1499 if (rport->flags & FC_RPORT_SCAN_PENDING)
1500 scsi_flush_work(shost);
1502 transport_remove_device(dev);
1504 transport_destroy_device(dev);
1505 put_device(&shost->shost_gendev); /* for fc_host->rport list */
1506 put_device(dev); /* for self-reference */
1511 * fc_rport_create - allocates and creates a remote FC port.
1512 * @shost: scsi host the remote port is connected to.
1513 * @channel: Channel on shost port connected to.
1514 * @ids: The world wide names, fc address, and FC4 port
1515 * roles for the remote port.
1517 * Allocates and creates the remoter port structure, including the
1518 * class and sysfs creation.
1521 * This routine assumes no locks are held on entry.
1524 fc_rport_create(struct Scsi_Host *shost, int channel,
1525 struct fc_rport_identifiers *ids)
1527 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1528 struct fc_internal *fci = to_fc_internal(shost->transportt);
1529 struct fc_rport *rport;
1531 unsigned long flags;
1535 size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size);
1536 rport = kzalloc(size, GFP_KERNEL);
1537 if (unlikely(!rport)) {
1538 printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
1542 rport->maxframe_size = -1;
1543 rport->supported_classes = FC_COS_UNSPECIFIED;
1544 rport->dev_loss_tmo = fc_dev_loss_tmo;
1545 memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name));
1546 memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name));
1547 rport->port_id = ids->port_id;
1548 rport->roles = ids->roles;
1549 rport->port_state = FC_PORTSTATE_ONLINE;
1550 if (fci->f->dd_fcrport_size)
1551 rport->dd_data = &rport[1];
1552 rport->channel = channel;
1554 INIT_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport, rport);
1555 INIT_WORK(&rport->scan_work, fc_scsi_scan_rport, rport);
1556 INIT_WORK(&rport->stgt_delete_work, fc_starget_delete, rport);
1557 INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete, rport);
1559 spin_lock_irqsave(shost->host_lock, flags);
1561 rport->number = fc_host->next_rport_number++;
1562 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
1563 rport->scsi_target_id = fc_host->next_target_id++;
1565 rport->scsi_target_id = -1;
1566 list_add_tail(&rport->peers, &fc_host->rports);
1567 get_device(&shost->shost_gendev); /* for fc_host->rport list */
1569 spin_unlock_irqrestore(shost->host_lock, flags);
1572 device_initialize(dev); /* takes self reference */
1573 dev->parent = get_device(&shost->shost_gendev); /* parent reference */
1574 dev->release = fc_rport_dev_release;
1575 sprintf(dev->bus_id, "rport-%d:%d-%d",
1576 shost->host_no, channel, rport->number);
1577 transport_setup_device(dev);
1579 error = device_add(dev);
1581 printk(KERN_ERR "FC Remote Port device_add failed\n");
1584 transport_add_device(dev);
1585 transport_configure_device(dev);
1587 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
1588 /* initiate a scan of the target */
1589 rport->flags |= FC_RPORT_SCAN_PENDING;
1590 scsi_queue_work(shost, &rport->scan_work);
1596 transport_destroy_device(dev);
1597 spin_lock_irqsave(shost->host_lock, flags);
1598 list_del(&rport->peers);
1599 put_device(&shost->shost_gendev); /* for fc_host->rport list */
1600 spin_unlock_irqrestore(shost->host_lock, flags);
1601 put_device(dev->parent);
1607 * fc_remote_port_add - notifies the fc transport of the existence
1608 * of a remote FC port.
1609 * @shost: scsi host the remote port is connected to.
1610 * @channel: Channel on shost port connected to.
1611 * @ids: The world wide names, fc address, and FC4 port
1612 * roles for the remote port.
1614 * The LLDD calls this routine to notify the transport of the existence
1615 * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn)
1616 * of the port, it's FC address (port_id), and the FC4 roles that are
1617 * active for the port.
1619 * For ports that are FCP targets (aka scsi targets), the FC transport
1620 * maintains consistent target id bindings on behalf of the LLDD.
1621 * A consistent target id binding is an assignment of a target id to
1622 * a remote port identifier, which persists while the scsi host is
1623 * attached. The remote port can disappear, then later reappear, and
1624 * it's target id assignment remains the same. This allows for shifts
1625 * in FC addressing (if binding by wwpn or wwnn) with no apparent
1626 * changes to the scsi subsystem which is based on scsi host number and
1627 * target id values. Bindings are only valid during the attachment of
1628 * the scsi host. If the host detaches, then later re-attaches, target
1629 * id bindings may change.
1631 * This routine is responsible for returning a remote port structure.
1632 * The routine will search the list of remote ports it maintains
1633 * internally on behalf of consistent target id mappings. If found, the
1634 * remote port structure will be reused. Otherwise, a new remote port
1635 * structure will be allocated.
1637 * Whenever a remote port is allocated, a new fc_remote_port class
1638 * device is created.
1640 * Should not be called from interrupt context.
1643 * This routine assumes no locks are held on entry.
1646 fc_remote_port_add(struct Scsi_Host *shost, int channel,
1647 struct fc_rport_identifiers *ids)
1649 struct fc_internal *fci = to_fc_internal(shost->transportt);
1650 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1651 struct fc_rport *rport;
1652 unsigned long flags;
1655 /* ensure any stgt delete functions are done */
1656 fc_flush_work(shost);
1659 * Search the list of "active" rports, for an rport that has been
1660 * deleted, but we've held off the real delete while the target
1661 * is in a "blocked" state.
1663 spin_lock_irqsave(shost->host_lock, flags);
1665 list_for_each_entry(rport, &fc_host->rports, peers) {
1667 if ((rport->port_state == FC_PORTSTATE_BLOCKED) &&
1668 (rport->channel == channel)) {
1670 switch (fc_host->tgtid_bind_type) {
1671 case FC_TGTID_BIND_BY_WWPN:
1672 case FC_TGTID_BIND_NONE:
1673 if (rport->port_name == ids->port_name)
1676 case FC_TGTID_BIND_BY_WWNN:
1677 if (rport->node_name == ids->node_name)
1680 case FC_TGTID_BIND_BY_ID:
1681 if (rport->port_id == ids->port_id)
1687 struct work_struct *work =
1688 &rport->dev_loss_work;
1690 memcpy(&rport->node_name, &ids->node_name,
1691 sizeof(rport->node_name));
1692 memcpy(&rport->port_name, &ids->port_name,
1693 sizeof(rport->port_name));
1694 rport->port_id = ids->port_id;
1696 rport->port_state = FC_PORTSTATE_ONLINE;
1697 rport->roles = ids->roles;
1699 spin_unlock_irqrestore(shost->host_lock, flags);
1701 if (fci->f->dd_fcrport_size)
1702 memset(rport->dd_data, 0,
1703 fci->f->dd_fcrport_size);
1706 * If we were blocked, we were a target.
1707 * If no longer a target, we leave the timer
1708 * running in case the port changes roles
1709 * prior to the timer expiring. If the timer
1710 * fires, the target will be torn down.
1712 if (!(ids->roles & FC_RPORT_ROLE_FCP_TARGET))
1715 /* restart the target */
1718 * Stop the target timer first. Take no action
1719 * on the del_timer failure as the state
1720 * machine state change will validate the
1723 if (!cancel_delayed_work(work))
1724 fc_flush_devloss(shost);
1726 spin_lock_irqsave(shost->host_lock, flags);
1728 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1730 /* initiate a scan of the target */
1731 rport->flags |= FC_RPORT_SCAN_PENDING;
1732 scsi_queue_work(shost, &rport->scan_work);
1734 spin_unlock_irqrestore(shost->host_lock, flags);
1736 scsi_target_unblock(&rport->dev);
1743 /* Search the bindings array */
1744 if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) {
1746 /* search for a matching consistent binding */
1748 list_for_each_entry(rport, &fc_host->rport_bindings,
1750 if (rport->channel != channel)
1753 switch (fc_host->tgtid_bind_type) {
1754 case FC_TGTID_BIND_BY_WWPN:
1755 if (rport->port_name == ids->port_name)
1758 case FC_TGTID_BIND_BY_WWNN:
1759 if (rport->node_name == ids->node_name)
1762 case FC_TGTID_BIND_BY_ID:
1763 if (rport->port_id == ids->port_id)
1766 case FC_TGTID_BIND_NONE: /* to keep compiler happy */
1771 list_move_tail(&rport->peers, &fc_host->rports);
1777 memcpy(&rport->node_name, &ids->node_name,
1778 sizeof(rport->node_name));
1779 memcpy(&rport->port_name, &ids->port_name,
1780 sizeof(rport->port_name));
1781 rport->port_id = ids->port_id;
1782 rport->roles = ids->roles;
1783 rport->port_state = FC_PORTSTATE_ONLINE;
1785 if (fci->f->dd_fcrport_size)
1786 memset(rport->dd_data, 0,
1787 fci->f->dd_fcrport_size);
1789 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
1790 /* initiate a scan of the target */
1791 rport->flags |= FC_RPORT_SCAN_PENDING;
1792 scsi_queue_work(shost, &rport->scan_work);
1793 spin_unlock_irqrestore(shost->host_lock, flags);
1794 scsi_target_unblock(&rport->dev);
1796 spin_unlock_irqrestore(shost->host_lock, flags);
1802 spin_unlock_irqrestore(shost->host_lock, flags);
1804 /* No consistent binding found - create new remote port entry */
1805 rport = fc_rport_create(shost, channel, ids);
1809 EXPORT_SYMBOL(fc_remote_port_add);
1813 * fc_remote_port_delete - notifies the fc transport that a remote
1814 * port is no longer in existence.
1815 * @rport: The remote port that no longer exists
1817 * The LLDD calls this routine to notify the transport that a remote
1818 * port is no longer part of the topology. Note: Although a port
1819 * may no longer be part of the topology, it may persist in the remote
1820 * ports displayed by the fc_host. We do this under 2 conditions:
1821 * - If the port was a scsi target, we delay its deletion by "blocking" it.
1822 * This allows the port to temporarily disappear, then reappear without
1823 * disrupting the SCSI device tree attached to it. During the "blocked"
1824 * period the port will still exist.
1825 * - If the port was a scsi target and disappears for longer than we
1826 * expect, we'll delete the port and the tear down the SCSI device tree
1827 * attached to it. However, we want to semi-persist the target id assigned
1828 * to that port if it eventually does exist. The port structure will
1829 * remain (although with minimal information) so that the target id
1832 * If the remote port is not an FCP Target, it will be fully torn down
1833 * and deallocated, including the fc_remote_port class device.
1835 * If the remote port is an FCP Target, the port will be placed in a
1836 * temporary blocked state. From the LLDD's perspective, the rport no
1837 * longer exists. From the SCSI midlayer's perspective, the SCSI target
1838 * exists, but all sdevs on it are blocked from further I/O. The following
1840 * If the remote port does not return (signaled by a LLDD call to
1841 * fc_remote_port_add()) within the dev_loss_tmo timeout, then the
1842 * scsi target is removed - killing all outstanding i/o and removing the
1843 * scsi devices attached ot it. The port structure will be marked Not
1844 * Present and be partially cleared, leaving only enough information to
1845 * recognize the remote port relative to the scsi target id binding if
1846 * it later appears. The port will remain as long as there is a valid
1847 * binding (e.g. until the user changes the binding type or unloads the
1848 * scsi host with the binding).
1850 * If the remote port returns within the dev_loss_tmo value (and matches
1851 * according to the target id binding type), the port structure will be
1852 * reused. If it is no longer a SCSI target, the target will be torn
1853 * down. If it continues to be a SCSI target, then the target will be
1854 * unblocked (allowing i/o to be resumed), and a scan will be activated
1855 * to ensure that all luns are detected.
1857 * Called from normal process context only - cannot be called from interrupt.
1860 * This routine assumes no locks are held on entry.
1863 fc_remote_port_delete(struct fc_rport *rport)
1865 struct Scsi_Host *shost = rport_to_shost(rport);
1866 int timeout = rport->dev_loss_tmo;
1867 unsigned long flags;
1870 * No need to flush the fc_host work_q's, as all adds are synchronous.
1872 * We do need to reclaim the rport scan work element, so eventually
1873 * (in fc_rport_final_delete()) we'll flush the scsi host work_q if
1874 * there's still a scan pending.
1877 spin_lock_irqsave(shost->host_lock, flags);
1879 /* If no scsi target id mapping, delete it */
1880 if (rport->scsi_target_id == -1) {
1881 list_del(&rport->peers);
1882 rport->port_state = FC_PORTSTATE_DELETED;
1883 fc_queue_work(shost, &rport->rport_delete_work);
1884 spin_unlock_irqrestore(shost->host_lock, flags);
1888 rport->port_state = FC_PORTSTATE_BLOCKED;
1890 rport->flags |= FC_RPORT_DEVLOSS_PENDING;
1892 spin_unlock_irqrestore(shost->host_lock, flags);
1894 scsi_target_block(&rport->dev);
1896 /* cap the length the devices can be blocked until they are deleted */
1897 fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ);
1899 EXPORT_SYMBOL(fc_remote_port_delete);
1902 * fc_remote_port_rolechg - notifies the fc transport that the roles
1903 * on a remote may have changed.
1904 * @rport: The remote port that changed.
1906 * The LLDD calls this routine to notify the transport that the roles
1907 * on a remote port may have changed. The largest effect of this is
1908 * if a port now becomes a FCP Target, it must be allocated a
1909 * scsi target id. If the port is no longer a FCP target, any
1910 * scsi target id value assigned to it will persist in case the
1911 * role changes back to include FCP Target. No changes in the scsi
1912 * midlayer will be invoked if the role changes (in the expectation
1913 * that the role will be resumed. If it doesn't normal error processing
1916 * Should not be called from interrupt context.
1919 * This routine assumes no locks are held on entry.
1922 fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
1924 struct Scsi_Host *shost = rport_to_shost(rport);
1925 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1926 unsigned long flags;
1929 spin_lock_irqsave(shost->host_lock, flags);
1930 if (roles & FC_RPORT_ROLE_FCP_TARGET) {
1931 if (rport->scsi_target_id == -1) {
1932 rport->scsi_target_id = fc_host->next_target_id++;
1934 } else if (!(rport->roles & FC_RPORT_ROLE_FCP_TARGET))
1938 rport->roles = roles;
1940 spin_unlock_irqrestore(shost->host_lock, flags);
1944 * There may have been a delete timer running on the
1945 * port. Ensure that it is cancelled as we now know
1946 * the port is an FCP Target.
1947 * Note: we know the rport is exists and in an online
1948 * state as the LLDD would not have had an rport
1949 * reference to pass us.
1951 * Take no action on the del_timer failure as the state
1952 * machine state change will validate the
1955 if (!cancel_delayed_work(&rport->dev_loss_work))
1956 fc_flush_devloss(shost);
1958 spin_lock_irqsave(shost->host_lock, flags);
1959 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1960 spin_unlock_irqrestore(shost->host_lock, flags);
1962 /* ensure any stgt delete functions are done */
1963 fc_flush_work(shost);
1965 /* initiate a scan of the target */
1966 spin_lock_irqsave(shost->host_lock, flags);
1967 rport->flags |= FC_RPORT_SCAN_PENDING;
1968 scsi_queue_work(shost, &rport->scan_work);
1969 spin_unlock_irqrestore(shost->host_lock, flags);
1970 scsi_target_unblock(&rport->dev);
1973 EXPORT_SYMBOL(fc_remote_port_rolechg);
1976 * fc_timeout_deleted_rport - Timeout handler for a deleted remote port that
1977 * was a SCSI target (thus was blocked), and failed
1978 * to return in the alloted time.
1980 * @data: rport target that failed to reappear in the alloted time.
1983 fc_timeout_deleted_rport(void *data)
1985 struct fc_rport *rport = (struct fc_rport *)data;
1986 struct Scsi_Host *shost = rport_to_shost(rport);
1987 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1988 unsigned long flags;
1990 spin_lock_irqsave(shost->host_lock, flags);
1992 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1995 * If the port is ONLINE, then it came back. Validate it's still an
1996 * FCP target. If not, tear down the scsi_target on it.
1998 if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
1999 !(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
2000 dev_printk(KERN_ERR, &rport->dev,
2001 "blocked FC remote port time out: no longer"
2002 " a FCP target, removing starget\n");
2003 spin_unlock_irqrestore(shost->host_lock, flags);
2004 scsi_target_unblock(&rport->dev);
2005 fc_queue_work(shost, &rport->stgt_delete_work);
2009 if (rport->port_state != FC_PORTSTATE_BLOCKED) {
2010 spin_unlock_irqrestore(shost->host_lock, flags);
2011 dev_printk(KERN_ERR, &rport->dev,
2012 "blocked FC remote port time out: leaving target alone\n");
2016 if (fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) {
2017 list_del(&rport->peers);
2018 rport->port_state = FC_PORTSTATE_DELETED;
2019 dev_printk(KERN_ERR, &rport->dev,
2020 "blocked FC remote port time out: removing target\n");
2021 fc_queue_work(shost, &rport->rport_delete_work);
2022 spin_unlock_irqrestore(shost->host_lock, flags);
2026 dev_printk(KERN_ERR, &rport->dev,
2027 "blocked FC remote port time out: removing target and "
2028 "saving binding\n");
2030 list_move_tail(&rport->peers, &fc_host->rport_bindings);
2033 * Note: We do not remove or clear the hostdata area. This allows
2034 * host-specific target data to persist along with the
2035 * scsi_target_id. It's up to the host to manage it's hostdata area.
2039 * Reinitialize port attributes that may change if the port comes back.
2041 rport->maxframe_size = -1;
2042 rport->supported_classes = FC_COS_UNSPECIFIED;
2043 rport->roles = FC_RPORT_ROLE_UNKNOWN;
2044 rport->port_state = FC_PORTSTATE_NOTPRESENT;
2046 /* remove the identifiers that aren't used in the consisting binding */
2047 switch (fc_host->tgtid_bind_type) {
2048 case FC_TGTID_BIND_BY_WWPN:
2049 rport->node_name = -1;
2050 rport->port_id = -1;
2052 case FC_TGTID_BIND_BY_WWNN:
2053 rport->port_name = -1;
2054 rport->port_id = -1;
2056 case FC_TGTID_BIND_BY_ID:
2057 rport->node_name = -1;
2058 rport->port_name = -1;
2060 case FC_TGTID_BIND_NONE: /* to keep compiler happy */
2065 * As this only occurs if the remote port (scsi target)
2066 * went away and didn't come back - we'll remove
2067 * all attached scsi devices.
2069 spin_unlock_irqrestore(shost->host_lock, flags);
2071 scsi_target_unblock(&rport->dev);
2072 fc_queue_work(shost, &rport->stgt_delete_work);
2076 * fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
2078 * @data: remote port to be scanned.
2081 fc_scsi_scan_rport(void *data)
2083 struct fc_rport *rport = (struct fc_rport *)data;
2084 struct Scsi_Host *shost = rport_to_shost(rport);
2085 unsigned long flags;
2087 if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
2088 (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
2089 scsi_scan_target(&rport->dev, rport->channel,
2090 rport->scsi_target_id, SCAN_WILD_CARD, 1);
2093 spin_lock_irqsave(shost->host_lock, flags);
2094 rport->flags &= ~FC_RPORT_SCAN_PENDING;
2095 spin_unlock_irqrestore(shost->host_lock, flags);
2099 MODULE_AUTHOR("Martin Hicks");
2100 MODULE_DESCRIPTION("FC Transport Attributes");
2101 MODULE_LICENSE("GPL");
2103 module_init(fc_transport_init);
2104 module_exit(fc_transport_exit);