* [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch
@ 2005-02-09 4:18 James.Smart
2005-02-09 8:15 ` Mike Christie
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: James.Smart @ 2005-02-09 4:18 UTC (permalink / raw)
To: linux-scsi
[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]
This patch adds support for FC Remote Ports (which may or may not
be FCP targets) to the fc transport. The attributes for the ports are
in support of HBAAPI. This patch also implements consistent scsi target
id bindings for the remote ports.
This patch also moves the dev_loss attribute from the target-level
fc_transport device to the remote port device. It also deletes the
link_down attribute. The fc_target_block and fc_target_unblock
routines have been replaced by fc_remote_port_block and
fc_remote_port_unblock. The fc_host_block/unblock functions have
been removed (unused).
A new interface has been created - fc_remove_host(), which a driver
must call immediately prior to scsi_remove_host() when unloading.
This tears down the transport, starget, and sdev devices.
The transport, which utilizes the midlayer mods to insert transport
entities between the shost and starget, results in a device tree
such as the following:
/sys/class/fc_host/host4/device/rport-4:0-0/target4:0:0/4:0:0:0
-- James S
[-- Attachment #2: p00002_fc_rport.patch --]
[-- Type: application/octet-stream, Size: 57646 bytes --]
This patch adds support for FC Remote Ports (which may or may not
be FCP targets) to the fc transport. The attributes for the ports are
in support of HBAAPI. This patch also implements consistent scsi target
id bindings for the remote ports.
This patch also moves the dev_loss attribute from the target-level
fc_transport device to the remote port device. It also deletes the
link_down attribute. The fc_target_block and fc_target_unblock
routines have been replaced by fc_remote_port_block and
fc_remote_port_unblock. The fc_host_block/unblock functions have
been removed (unused).
A new interface has been created - fc_remove_host(), which a driver
must call immediately prior to scsi_remove_host() when unloading.
This tears down the transport, starget, and sdev devices.
The transport, which utilizes the midlayer mods to insert transport
entities between the shost and starget, results in a device tree
such as the following:
/sys/class/fc_host/host4/device/rport-4:0-0/target4:0:0/4:0:0:0
Signed-off-by: James Smart <james.smart@emulex.com>
---
b/drivers/scsi/scsi_transport_fc.c | 1047 +++++++++++++++-----
b/include/scsi/scsi_transport_fc.h | 185 ++-
2 files changed, 992 insertions(+), 240 deletions(-)
diff -puN a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
--- a/drivers/scsi/scsi_transport_fc.c 2005-02-08 21:10:36.000000000 -0500
+++ b/drivers/scsi/scsi_transport_fc.c 2005-02-08 21:10:36.000000000 -0500
@@ -16,6 +16,13 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ========
+ *
+ * Copyright (C) 2004-2005 James Smart, Emulex Corporation
+ * Rewrite for host, target, device, and remote port attributes,
+ * statistics, and service functions...
+ *
*/
#include <linux/module.h>
#include <linux/init.h>
@@ -90,8 +97,10 @@ static struct {
char *name;
} fc_port_state_names[] = {
{ FC_PORTSTATE_UNKNOWN, "Unknown" },
+ { FC_PORTSTATE_NOTPRESENT, "Not Present" },
{ FC_PORTSTATE_ONLINE, "Online" },
{ FC_PORTSTATE_OFFLINE, "Offline" },
+ { FC_PORTSTATE_BLOCKED, "Blocked" },
{ FC_PORTSTATE_BYPASSED, "Bypassed" },
{ FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" },
{ FC_PORTSTATE_LINKDOWN, "Linkdown" },
@@ -108,9 +117,10 @@ static struct {
char *name;
int matchlen;
} fc_tgtid_binding_type_names[] = {
+ { FC_TGTID_BIND_NONE, "none", 4 },
{ FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
{ FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
- { FC_TGTID_BIND_BY_ID, "fcportid (FC Address)", 8 },
+ { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 },
};
fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type,
fc_tgtid_binding_type_names)
@@ -139,7 +149,7 @@ get_fc_##title##_names(u32 table_key, ch
}
-/* Convert fc_cos bit values to ascii string name */
+/* Convert FC_COS bit values to ascii string name */
static struct {
u32 value;
char *name;
@@ -153,7 +163,7 @@ static struct {
fc_bitfield_name_search(cos, fc_cos_names)
-/* Convert fc_port_speed bit values to ascii string name */
+/* Convert FC_PORTSPEED bit values to ascii string name */
static struct {
u32 value;
char *name;
@@ -179,67 +189,101 @@ show_fc_fc4s (char *buf, u8 *fc4_list)
}
+/* Convert FC_RPORT_ROLE bit values to ascii string name */
+static struct {
+ u32 value;
+ char *name;
+} fc_remote_port_role_names[] = {
+ { FC_RPORT_ROLE_FCP_TARGET, "FCP Target" },
+ { FC_RPORT_ROLE_FCP_INITIATOR, "FCP Initiator" },
+ { FC_RPORT_ROLE_IP_PORT, "IP Port" },
+};
+fc_bitfield_name_search(remote_port_roles, fc_remote_port_role_names)
+
+/*
+ * Define roles that are specific to port_id. Values are relative to ROLE_MASK.
+ */
+#define FC_WELLKNOWN_PORTID_MASK 0xfffff0
+#define FC_WELLKNOWN_ROLE_MASK 0x00000f
+#define FC_FPORT_PORTID 0x00000e
+#define FC_FABCTLR_PORTID 0x00000d
+#define FC_DIRSRVR_PORTID 0x00000c
+#define FC_TIMESRVR_PORTID 0x00000b
+#define FC_MGMTSRVR_PORTID 0x00000a
+
-static void fc_timeout_blocked_host(void *data);
static void fc_timeout_blocked_tgt(void *data);
+static void fc_rport_terminate(struct fc_rport *rport);
-#define FC_STARGET_NUM_ATTRS 4 /* increase this if you add attributes */
-#define FC_STARGET_OTHER_ATTRS 0 /* increase this if you add "always on"
- * attributes */
-#define FC_HOST_NUM_ATTRS 15
+/*
+ * Attribute counts pre object type...
+ * Increase these values if you add attributes
+ */
+#define FC_STARGET_NUM_ATTRS 3
+#define FC_RPORT_NUM_ATTRS 9
+#define FC_HOST_NUM_ATTRS 19
struct fc_internal {
struct scsi_transport_template t;
struct fc_function_template *f;
- /* The actual attributes */
+
+ /*
+ * For attributes : each object has :
+ * An array of the actual attributes structures
+ * An array of null-terminated pointers to the attribute
+ * structures - used for mid-layer interaction.
+ *
+ * The attribute containers for the starget and host are are
+ * part of the midlayer. As the remote port is specific to the
+ * fc transport, we must provide the attribute container.
+ */
struct class_device_attribute private_starget_attrs[
- FC_STARGET_NUM_ATTRS];
- /* The array of null terminated pointers to attributes
- * needed by scsi_sysfs.c */
- struct class_device_attribute *starget_attrs[
- FC_STARGET_NUM_ATTRS + FC_STARGET_OTHER_ATTRS + 1];
+ FC_STARGET_NUM_ATTRS];
+ struct class_device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1];
struct class_device_attribute private_host_attrs[FC_HOST_NUM_ATTRS];
struct class_device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1];
+
+ struct attribute_container rport_attr_cont;
+ struct class_device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS];
+ struct class_device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1];
};
#define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t)
-static int fc_add_target(struct device *dev)
+static int fc_target_setup(struct device *dev)
{
struct scsi_target *starget = to_scsi_target(dev);
- /*
- * Set default values easily detected by the midlayer as
- * failure cases. The scsi lldd is responsible for initializing
- * all transport attributes to valid values per target.
+ struct fc_rport *rport = starget_to_rport(starget);
+
+ /*
+ * if parent is remote port, use values from remote port.
+ * Otherwise, this host uses the fc_transport, but not the
+ * remote port interface. As such, initialize to known non-values.
*/
- fc_starget_node_name(starget) = -1;
- fc_starget_port_name(starget) = -1;
- fc_starget_port_id(starget) = -1;
- fc_starget_dev_loss_tmo(starget) = -1;
- INIT_WORK(&fc_starget_dev_loss_work(starget),
- fc_timeout_blocked_tgt, starget);
- return 0;
-}
+ if (rport) {
+ fc_starget_node_name(starget) = rport->node_name;
+ fc_starget_port_name(starget) = rport->port_name;
+ fc_starget_port_id(starget) = rport->port_id;
+ } else {
+ fc_starget_node_name(starget) = -1;
+ fc_starget_port_name(starget) = -1;
+ fc_starget_port_id(starget) = -1;
+ }
-static int fc_remove_target(struct device *dev)
-{
- struct scsi_target *starget = to_scsi_target(dev);
- /* Stop the target timer */
- if (cancel_delayed_work(&fc_starget_dev_loss_work(starget)))
- flush_scheduled_work();
return 0;
}
static DECLARE_TRANSPORT_CLASS(fc_transport_class,
"fc_transport",
- fc_add_target,
- fc_remove_target,
+ fc_target_setup,
+ NULL,
NULL);
-static int fc_add_host(struct device *dev)
+static int fc_host_setup(struct device *dev)
{
struct Scsi_Host *shost = dev_to_shost(dev);
+
/*
* Set default values easily detected by the midlayer as
* failure cases. The scsi lldd is responsible for initializing
@@ -272,28 +316,31 @@ static int fc_add_host(struct device *de
sizeof(fc_host_active_fc4s(shost)));
fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
fc_host_fabric_name(shost) = -1;
- fc_host_link_down_tmo(shost) = -1;
fc_host_tgtid_bind_type(shost) = FC_TGTID_BIND_BY_WWPN;
- INIT_WORK(&fc_host_link_down_work(shost),
- fc_timeout_blocked_host, shost);
- return 0;
-}
+ INIT_LIST_HEAD(&fc_host_rports(shost));
+ INIT_LIST_HEAD(&fc_host_rport_bindings(shost));
+ fc_host_next_rport_number(shost) = 0;
+ fc_host_next_target_id(shost) = 0;
-static int fc_remove_host(struct device *dev)
-{
- struct Scsi_Host *shost = dev_to_shost(dev);
- /* Stop the host timer */
- if (cancel_delayed_work(&fc_host_link_down_work(shost)))
- flush_scheduled_work();
return 0;
}
static DECLARE_TRANSPORT_CLASS(fc_host_class,
"fc_host",
- fc_add_host,
- fc_remove_host,
+ fc_host_setup,
+ NULL,
+ NULL);
+
+/*
+ * Setup and Remove actions for remote ports are handled
+ * in the service functions below.
+ */
+static DECLARE_TRANSPORT_CLASS(fc_rport_class,
+ "fc_remote_ports",
+ NULL,
+ NULL,
NULL);
static __init int fc_transport_init(void)
@@ -301,64 +348,228 @@ static __init int fc_transport_init(void
int error = transport_class_register(&fc_host_class);
if (error)
return error;
+ error = transport_class_register(&fc_rport_class);
+ if (error)
+ return error;
return transport_class_register(&fc_transport_class);
}
static void __exit fc_transport_exit(void)
{
transport_class_unregister(&fc_transport_class);
+ transport_class_unregister(&fc_rport_class);
transport_class_unregister(&fc_host_class);
}
+
/*
- * Remote Port (Target) Attribute Management
+ * FC Remote Port Attribute Management
*/
-#define fc_starget_show_function(field, format_string, cast) \
+#define fc_rport_show_function(field, format_string, sz, cast) \
static ssize_t \
-show_fc_starget_##field (struct class_device *cdev, char *buf) \
+show_fc_rport_##field (struct class_device *cdev, char *buf) \
{ \
- struct scsi_target *starget = transport_class_to_starget(cdev); \
- struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
+ struct fc_rport *rport = transport_class_to_rport(cdev); \
+ struct Scsi_Host *shost = rport_to_shost(rport); \
struct fc_internal *i = to_fc_internal(shost->transportt); \
- if (i->f->get_starget_##field) \
- i->f->get_starget_##field(starget); \
- return snprintf(buf, 20, format_string, \
- cast fc_starget_##field(starget)); \
+ if (i->f->get_rport_##field) \
+ i->f->get_rport_##field(rport); \
+ return snprintf(buf, sz, format_string, cast rport->field); \
}
-#define fc_starget_store_function(field, format_string) \
+#define fc_rport_store_function(field) \
static ssize_t \
-store_fc_starget_##field(struct class_device *cdev, const char *buf, \
+store_fc_rport_##field(struct class_device *cdev, const char *buf, \
size_t count) \
{ \
int val; \
- struct scsi_target *starget = transport_class_to_starget(cdev); \
- struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
+ struct fc_rport *rport = transport_class_to_rport(cdev); \
+ struct Scsi_Host *shost = rport_to_shost(rport); \
struct fc_internal *i = to_fc_internal(shost->transportt); \
- \
val = simple_strtoul(buf, NULL, 0); \
- i->f->set_starget_##field(starget, val); \
+ i->f->set_rport_##field(rport, val); \
return count; \
}
-#define fc_starget_rd_attr(field, format_string) \
- fc_starget_show_function(field, format_string, ) \
+#define fc_rport_rd_attr(field, format_string, sz) \
+ fc_rport_show_function(field, format_string, sz, ) \
+static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
+ show_fc_rport_##field, NULL)
+
+#define fc_rport_rd_attr_cast(field, format_string, sz, cast) \
+ fc_rport_show_function(field, format_string, sz, (cast)) \
+static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
+ show_fc_rport_##field, NULL)
+
+#define fc_rport_rw_attr(field, format_string, sz) \
+ fc_rport_show_function(field, format_string, sz, ) \
+ fc_rport_store_function(field) \
+static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \
+ show_fc_rport_##field, \
+ store_fc_rport_##field)
+
+
+#define fc_private_rport_show_function(field, format_string, sz, cast) \
+static ssize_t \
+show_fc_rport_##field (struct class_device *cdev, char *buf) \
+{ \
+ struct fc_rport *rport = transport_class_to_rport(cdev); \
+ return snprintf(buf, sz, format_string, cast rport->field); \
+}
+
+#define fc_private_rport_rd_attr(field, format_string, sz) \
+ fc_private_rport_show_function(field, format_string, sz, ) \
+static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
+ show_fc_rport_##field, NULL)
+
+#define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \
+ fc_private_rport_show_function(field, format_string, sz, (cast)) \
+static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
+ show_fc_rport_##field, NULL)
+
+
+#define fc_private_rport_rd_enum_attr(title, maxlen) \
+static ssize_t \
+show_fc_rport_##title (struct class_device *cdev, char *buf) \
+{ \
+ struct fc_rport *rport = transport_class_to_rport(cdev); \
+ const char *name; \
+ name = get_fc_##title##_name(rport->title); \
+ if (!name) \
+ return -EINVAL; \
+ return snprintf(buf, maxlen, "%s\n", name); \
+} \
+static FC_CLASS_DEVICE_ATTR(rport, title, S_IRUGO, \
+ show_fc_rport_##title, NULL)
+
+
+#define SETUP_RPORT_ATTRIBUTE_RD(field) \
+ i->private_rport_attrs[count] = class_device_attr_rport_##field; \
+ i->private_rport_attrs[count].attr.mode = S_IRUGO; \
+ i->private_rport_attrs[count].store = NULL; \
+ i->rport_attrs[count] = &i->private_rport_attrs[count]; \
+ if (i->f->show_rport_##field) \
+ count++
+
+#define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \
+ i->private_rport_attrs[count] = class_device_attr_rport_##field; \
+ i->private_rport_attrs[count].attr.mode = S_IRUGO; \
+ i->private_rport_attrs[count].store = NULL; \
+ i->rport_attrs[count] = &i->private_rport_attrs[count]; \
+ count++
+
+#define SETUP_RPORT_ATTRIBUTE_RW(field) \
+ i->private_rport_attrs[count] = class_device_attr_rport_##field; \
+ if (!i->f->set_rport_##field) { \
+ i->private_rport_attrs[count].attr.mode = S_IRUGO; \
+ i->private_rport_attrs[count].store = NULL; \
+ } \
+ i->rport_attrs[count] = &i->private_rport_attrs[count]; \
+ if (i->f->show_rport_##field) \
+ count++
+
+
+/* The FC Transport Remote Port Attributes: */
+
+/* Fixed Remote Port Attributes */
+
+fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20);
+
+static ssize_t
+show_fc_rport_supported_classes (struct class_device *cdev, char *buf)
+{
+ struct fc_rport *rport = transport_class_to_rport(cdev);
+ if (rport->supported_classes == FC_COS_UNSPECIFIED)
+ return snprintf(buf, 20, "unspecified\n");
+ return get_fc_cos_names(rport->supported_classes, buf);
+}
+static FC_CLASS_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
+ show_fc_rport_supported_classes, NULL);
+
+/* Dynamic Remote Port Attributes */
+
+fc_rport_rw_attr(dev_loss_tmo, "%d\n", 20);
+
+
+/* Private Remote Port Attributes */
+
+fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
+fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
+fc_private_rport_rd_attr(port_id, "0x%06x\n", 20);
+
+static ssize_t
+show_fc_rport_roles (struct class_device *cdev, char *buf)
+{
+ struct fc_rport *rport = transport_class_to_rport(cdev);
+
+ /* identify any roles that are port_id specific */
+ if ((rport->port_id != -1) &&
+ (rport->port_id & FC_WELLKNOWN_PORTID_MASK) ==
+ FC_WELLKNOWN_PORTID_MASK) {
+ switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
+ case FC_FPORT_PORTID:
+ return snprintf(buf, 30, "Fabric Port\n");
+ case FC_FABCTLR_PORTID:
+ return snprintf(buf, 30, "Fabric Controller\n");
+ case FC_DIRSRVR_PORTID:
+ return snprintf(buf, 30, "Directory Server\n");
+ case FC_TIMESRVR_PORTID:
+ return snprintf(buf, 30, "Time Server\n");
+ case FC_MGMTSRVR_PORTID:
+ return snprintf(buf, 30, "Management Server\n");
+ default:
+ return snprintf(buf, 30, "Unknown Fabric Entity\n");
+ }
+ } else {
+ if (rport->roles == FC_RPORT_ROLE_UNKNOWN)
+ return snprintf(buf, 20, "unknown\n");
+ return get_fc_remote_port_roles_names(rport->roles, buf);
+ }
+}
+static FC_CLASS_DEVICE_ATTR(rport, roles, S_IRUGO,
+ show_fc_rport_roles, NULL);
+
+fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
+fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);
+
+
+
+/*
+ * FC SCSI Target Attribute Management
+ */
+
+/*
+ * Note: in the target show function we recognize when the remote
+ * port is in the heirarchy and do not allow the driver to get
+ * involved in sysfs functions.
+ */
+#define fc_starget_show_function(field, format_string, sz, cast) \
+static ssize_t \
+show_fc_starget_##field (struct class_device *cdev, char *buf) \
+{ \
+ struct scsi_target *starget = transport_class_to_starget(cdev); \
+ struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
+ struct fc_internal *i = to_fc_internal(shost->transportt); \
+ struct fc_rport *rport = starget_to_rport(starget); \
+ if (rport) \
+ fc_starget_##field(starget) = rport->field; \
+ else if (i->f->get_starget_##field) \
+ i->f->get_starget_##field(starget); \
+ return snprintf(buf, sz, format_string, \
+ cast fc_starget_##field(starget)); \
+}
+
+#define fc_starget_rd_attr(field, format_string, sz) \
+ fc_starget_show_function(field, format_string, sz, ) \
static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
show_fc_starget_##field, NULL)
-#define fc_starget_rd_attr_cast(field, format_string, cast) \
- fc_starget_show_function(field, format_string, (cast)) \
+#define fc_starget_rd_attr_cast(field, format_string, sz, cast) \
+ fc_starget_show_function(field, format_string, sz, (cast)) \
static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
show_fc_starget_##field, NULL)
-#define fc_starget_rw_attr(field, format_string) \
- fc_starget_show_function(field, format_string, ) \
- fc_starget_store_function(field, format_string) \
-static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO | S_IWUSR, \
- show_fc_starget_##field, \
- store_fc_starget_##field)
-
#define SETUP_STARGET_ATTRIBUTE_RD(field) \
i->private_starget_attrs[count] = class_device_attr_starget_##field; \
i->private_starget_attrs[count].attr.mode = S_IRUGO; \
@@ -378,10 +589,9 @@ static FC_CLASS_DEVICE_ATTR(starget, fie
count++
/* The FC Tranport Remote Port (Target) Attributes: */
-fc_starget_rd_attr_cast(node_name, "0x%llx\n", unsigned long long);
-fc_starget_rd_attr_cast(port_name, "0x%llx\n", unsigned long long);
-fc_starget_rd_attr(port_id, "0x%06x\n");
-fc_starget_rw_attr(dev_loss_tmo, "%d\n");
+fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
+fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
+fc_starget_rd_attr(port_id, "0x%06x\n", 20);
@@ -400,7 +610,7 @@ show_fc_host_##field (struct class_devic
return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
}
-#define fc_host_store_function(field, format_string) \
+#define fc_host_store_function(field) \
static ssize_t \
store_fc_host_##field(struct class_device *cdev, const char *buf, \
size_t count) \
@@ -426,7 +636,7 @@ static FC_CLASS_DEVICE_ATTR(host, field,
#define fc_host_rw_attr(field, format_string, sz) \
fc_host_show_function(field, format_string, sz, ) \
- fc_host_store_function(field, format_string) \
+ fc_host_store_function(field) \
static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \
show_fc_host_##field, \
store_fc_host_##field)
@@ -584,7 +794,6 @@ fc_host_rd_attr(port_id, "0x%06x\n", 20)
fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
-fc_host_rw_attr(link_down_tmo, "%d\n", 20);
/* Private Host Attributes */
@@ -606,10 +815,22 @@ store_fc_private_host_tgtid_bind_type(st
const char *buf, size_t count)
{
struct Scsi_Host *shost = transport_class_to_shost(cdev);
- enum fc_tgtid_binding_type val;
+ struct fc_rport *rport, *next_rport;
+ enum fc_tgtid_binding_type val;
+ unsigned long flags;
if (get_fc_tgtid_bind_type_match(buf, &val))
return -EINVAL;
+
+ /* if changing bind type, purge all unused consistent bindings */
+ if (val != fc_host_tgtid_bind_type(shost)) {
+ spin_lock_irqsave(shost->host_lock, flags);
+ list_for_each_entry_safe(rport, next_rport,
+ &fc_host_rport_bindings(shost), peers)
+ fc_rport_terminate(rport);
+ spin_unlock_irqrestore(shost->host_lock, flags);
+ }
+
fc_host_tgtid_bind_type(shost) = val;
return count;
}
@@ -732,14 +953,13 @@ static int fc_host_match(struct attribut
if (!scsi_is_host_device(dev))
return 0;
-
shost = dev_to_shost(dev);
if (!shost->transportt || shost->transportt->host_attrs.class
!= &fc_host_class.class)
return 0;
i = to_fc_internal(shost->transportt);
-
+
return &i->t.host_attrs == cont;
}
@@ -758,17 +978,46 @@ static int fc_target_match(struct attrib
return 0;
i = to_fc_internal(shost->transportt);
-
+
return &i->t.target_attrs == cont;
}
+static void fc_rport_dev_release(struct device *dev)
+{
+ put_device(dev->parent);
+}
+
+int scsi_is_fc_rport(const struct device *dev)
+{
+ return dev->release == fc_rport_dev_release;
+}
+EXPORT_SYMBOL(scsi_is_fc_rport);
+
+static int fc_rport_match(struct attribute_container *cont,
+ struct device *dev)
+{
+ struct Scsi_Host *shost;
+ struct fc_internal *i;
+
+ if (!scsi_is_fc_rport(dev))
+ return 0;
+
+ shost = dev_to_shost(dev->parent);
+ if (!shost->transportt || shost->transportt->host_attrs.class
+ != &fc_host_class.class)
+ return 0;
+
+ i = to_fc_internal(shost->transportt);
+
+ return &i->rport_attr_cont == cont;
+}
struct scsi_transport_template *
fc_attach_transport(struct fc_function_template *ft)
{
struct fc_internal *i = kmalloc(sizeof(struct fc_internal),
GFP_KERNEL);
- int count = 0;
+ int count;
if (unlikely(!i))
return NULL;
@@ -790,16 +1039,21 @@ fc_attach_transport(struct fc_function_t
if (ft->get_fc_host_stats)
i->t.host_attrs.statistics = &fc_statistics_group;
+ i->rport_attr_cont.attrs = &i->rport_attrs[0];
+ i->rport_attr_cont.class = &fc_rport_class.class;
+ i->rport_attr_cont.match = fc_rport_match;
+ attribute_container_register(&i->rport_attr_cont);
+
i->f = ft;
-
+
/*
- * setup remote port (target) attributes
+ * Setup SCSI Target Attributes.
*/
- SETUP_STARGET_ATTRIBUTE_RD(port_id);
- SETUP_STARGET_ATTRIBUTE_RD(port_name);
+ count = 0;
SETUP_STARGET_ATTRIBUTE_RD(node_name);
- SETUP_STARGET_ATTRIBUTE_RW(dev_loss_tmo);
+ SETUP_STARGET_ATTRIBUTE_RD(port_name);
+ SETUP_STARGET_ATTRIBUTE_RD(port_id);
BUG_ON(count > FC_STARGET_NUM_ATTRS);
@@ -808,7 +1062,9 @@ fc_attach_transport(struct fc_function_t
i->starget_attrs[count] = NULL;
- /* setup host attributes */
+ /*
+ * Setup SCSI Host Attributes.
+ */
count=0;
SETUP_HOST_ATTRIBUTE_RD(node_name);
SETUP_HOST_ATTRIBUTE_RD(port_name);
@@ -829,7 +1085,6 @@ fc_attach_transport(struct fc_function_t
SETUP_HOST_ATTRIBUTE_RD(active_fc4s);
SETUP_HOST_ATTRIBUTE_RD(speed);
SETUP_HOST_ATTRIBUTE_RD(fabric_name);
- SETUP_HOST_ATTRIBUTE_RW(link_down_tmo);
/* Transport-managed attributes */
SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type);
@@ -839,6 +1094,24 @@ fc_attach_transport(struct fc_function_t
i->host_attrs[count] = NULL;
+ /*
+ * Setup Remote Port Attributes.
+ */
+ count=0;
+ SETUP_RPORT_ATTRIBUTE_RD(maxframe_size);
+ SETUP_RPORT_ATTRIBUTE_RD(supported_classes);
+ SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo);
+ SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name);
+ SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name);
+ SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id);
+ SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles);
+ SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state);
+ SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id);
+
+ BUG_ON(count > FC_RPORT_NUM_ATTRS);
+
+ i->rport_attrs[count] = NULL;
+
return &i->t;
}
EXPORT_SYMBOL(fc_attach_transport);
@@ -849,203 +1122,553 @@ void fc_release_transport(struct scsi_tr
attribute_container_unregister(&i->t.target_attrs);
attribute_container_unregister(&i->t.host_attrs);
+ attribute_container_unregister(&i->rport_attr_cont);
kfree(i);
}
EXPORT_SYMBOL(fc_release_transport);
-
/**
- * fc_device_block - called by target functions to block a scsi device
- * @dev: scsi device
- * @data: unused
+ * fc_remove_host - called to terminate any fc_transport-related elements
+ * for a scsi host.
+ * @rport: remote port to be unblocked.
+ *
+ * This routine is expected to be called immediately preceeding the
+ * a driver's call to scsi_remove_host().
+ *
+ * WARNING: A driver utilizing the fc_transport, which fails to call
+ * this routine prior to scsi_remote_host(), will leave dangling
+ * objects in /sys/class/fc_remote_ports. Access to any of these
+ * objects can result in a system crash !!!
+ *
+ * Notes:
+ * This routine assumes no locks are held on entry.
**/
-static void fc_device_block(struct scsi_device *sdev, void *data)
+void fc_remove_host(struct Scsi_Host *shost)
{
- scsi_internal_device_block(sdev);
+ struct fc_rport *rport, *next_rport;
+
+ /* Remove any remote ports */
+ list_for_each_entry_safe(rport, next_rport,
+ &fc_host_rports(shost), peers)
+ fc_rport_terminate(rport);
+ list_for_each_entry_safe(rport, next_rport,
+ &fc_host_rport_bindings(shost), peers)
+ fc_rport_terminate(rport);
+}
+EXPORT_SYMBOL(fc_remove_host);
+
+
+#define TGT_ALLOC_FAILURE_MSG "%s: FC Transport failed to" \
+ " pre-alloc SCSI Target. Some SCSI devices might not be" \
+ " configured or the FC Transport may only be partially activated" \
+ " on this scsi host%d\n"
+
+static void fc_create_starget(struct fc_rport *rport)
+{
+ struct Scsi_Host *shost = rport_to_shost(rport);
+
+ rport->starget = __scsi_alloc_target(shost, rport->channel,
+ rport->scsi_target_id, &rport->dev);
+ if (likely(rport->starget)) {
+ __scsi_setup_target(rport->starget);
+ scsi_sysfs_add_target(rport->starget);
+ } else
+ dev_printk(KERN_ERR, &rport->dev, TGT_ALLOC_FAILURE_MSG,
+ __FUNCTION__, shost->host_no);
}
/**
- * fc_device_unblock - called by target functions to unblock a scsi device
- * @dev: scsi device
- * @data: unused
+ * fc_create_rport - allocates and creates a remote FC port.
+ * @shost: scsi host the remote port is connected to.
+ * @channel: Channel on shost port connected to.
+ * @ids: The world wide names, fc address, and FC4 port
+ * roles for the remote port.
+ *
+ * Allocates and creates the remoter port structure, including the
+ * class and sysfs creation.
+ *
+ * Notes:
+ * This routine assumes no locks are held on entry.
**/
-static void fc_device_unblock(struct scsi_device *sdev, void *data)
-{
- scsi_internal_device_unblock(sdev);
+struct fc_rport *
+fc_create_rport(struct Scsi_Host *shost, int channel,
+ struct fc_rport_identifiers *ids)
+{
+ struct fc_host_attrs *fc_host =
+ (struct fc_host_attrs *)shost->shost_data;
+ struct fc_internal *fci = to_fc_internal(shost->transportt);
+ struct fc_rport *rport;
+ struct device *dev;
+ unsigned long flags;
+ int error;
+ size_t size;
+
+ size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size);
+ rport = kmalloc(size, GFP_KERNEL);
+ if (unlikely(!rport)) {
+ printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
+ return NULL;
+ }
+ memset(rport, 0, size);
+
+ rport->maxframe_size = -1;
+ rport->supported_classes = FC_COS_UNSPECIFIED;
+ rport->dev_loss_tmo = SCSI_DEVICE_BLOCK_MAX_TIMEOUT;
+ memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name));
+ memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name));
+ rport->port_id = ids->port_id;
+ rport->roles = ids->roles;
+ rport->port_state = FC_PORTSTATE_ONLINE;
+ if (fci->f->dd_fcrport_size)
+ rport->dd_data = &rport[1];
+ rport->channel = channel;
+
+ INIT_WORK(&rport->dev_loss_work, fc_timeout_blocked_tgt, rport);
+
+ spin_lock_irqsave(shost->host_lock, flags);
+
+ rport->number = fc_host->next_rport_number++;
+ if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
+ rport->scsi_target_id = fc_host->next_target_id++;
+ else
+ rport->scsi_target_id = -1;
+ list_add_tail(&rport->peers, &fc_host_rports(shost));
+ get_device(&shost->shost_gendev);
+
+ spin_unlock_irqrestore(shost->host_lock, flags);
+
+ dev = &rport->dev;
+ device_initialize(dev);
+ dev->parent = get_device(&shost->shost_gendev);
+ dev->release = fc_rport_dev_release;
+ sprintf(dev->bus_id, "rport-%d:%d-%d",
+ shost->host_no, channel, rport->number);
+ transport_setup_device(dev);
+
+ error = device_add(dev);
+ if (error) {
+ printk(KERN_ERR "FC Remote Port device_add failed\n");
+ goto delete_rport;
+ }
+ transport_add_device(dev);
+ transport_configure_device(dev);
+
+ if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
+ fc_create_starget(rport);
+
+ return rport;
+
+delete_rport:
+ transport_destroy_device(dev);
+ put_device(dev->parent);
+ spin_lock_irqsave(shost->host_lock, flags);
+ list_del(&rport->peers);
+ put_device(&shost->shost_gendev);
+ spin_unlock_irqrestore(shost->host_lock, flags);
+ put_device(dev->parent);
+ kfree(rport);
+ return NULL;
}
/**
- * fc_timeout_blocked_tgt - Timeout handler for blocked scsi targets
- * that fail to recover in the alloted time.
- * @data: scsi target that failed to reappear in the alloted time.
+ * fc_remote_port_add - notifies the fc transport of the existence
+ * of a remote FC port.
+ * @shost: scsi host the remote port is connected to.
+ * @channel: Channel on shost port connected to.
+ * @ids: The world wide names, fc address, and FC4 port
+ * roles for the remote port.
+ *
+ * The LLDD calls this routine to notify the transport of the existence
+ * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn)
+ * of the port, it's FC address (port_id), and the FC4 roles that are
+ * active for the port.
+ *
+ * For ports that are FCP targets (aka scsi targets), the FC transport
+ * maintains consistent target id bindings on behalf of the LLDD.
+ * A consistent target id binding is an assignment of a target id to
+ * a remote port identifier, which persists while the scsi host is
+ * attached. The remote port can disappear, then later reappear, and
+ * it's target id assignment remains the same. This allows for shifts
+ * in FC addressing (if binding by wwpn or wwnn) with no apparent
+ * changes to the scsi subsystem which is based on scsi host number and
+ * target id values. Bindings are only valid during the attachment of
+ * the scsi host. If the host detaches, then later re-attaches, target
+ * id bindings may change.
+ *
+ * This routine is responsible for returning a remote port structure.
+ * The routine will search the list of remote ports it maintains
+ * internally on behalf of consistent target id mappings. If found, the
+ * remote port structure will be reused. Otherwise, a new remote port
+ * structure will be allocated.
+ *
+ * Whenever a remote port is allocated, a new fc_remote_port class
+ * device is created. Additionally, under the fc_host, a symbolic
+ * link is created to the class device. This allows an administrator
+ * to see all remote ports that the fc_host has visibility of.
+ *
+ * Should not be called from interrupt context.
+ *
+ * Notes:
+ * This routine assumes no locks are held on entry.
**/
-static void fc_timeout_blocked_tgt(void *data)
+struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost, int channel,
+ struct fc_rport_identifiers *ids)
{
- struct scsi_target *starget = (struct scsi_target *)data;
+ struct fc_rport *rport;
+ unsigned long flags;
+ int match = 0;
+
+ if (likely((ids->roles & FC_RPORT_ROLE_FCP_TARGET) &&
+ (fc_host_tgtid_bind_type(shost) != FC_TGTID_BIND_NONE))) {
+
+ /* search for a matching consistent binding */
+
+ spin_lock_irqsave(shost->host_lock, flags);
+
+ list_for_each_entry(rport, &fc_host_rport_bindings(shost),
+ peers) {
+ if (rport->channel != channel)
+ continue;
+
+ switch (fc_host_tgtid_bind_type(shost)) {
+ case FC_TGTID_BIND_BY_WWPN:
+ if (rport->port_name == ids->port_name)
+ match = 1;
+ break;
+ case FC_TGTID_BIND_BY_WWNN:
+ if (rport->node_name == ids->node_name)
+ match = 1;
+ break;
+ case FC_TGTID_BIND_BY_ID:
+ if (rport->port_id == ids->port_id)
+ match = 1;
+ break;
+ case FC_TGTID_BIND_NONE: /* to keep compiler happy */
+ break;
+ }
+
+ if (match) {
+ list_move_tail(&rport->peers,
+ &fc_host_rports(shost));
+ break;
+ }
+ }
+
+ spin_unlock_irqrestore(shost->host_lock, flags);
+
+ if (match) {
+ memcpy(&rport->node_name, &ids->node_name,
+ sizeof(rport->node_name));
+ memcpy(&rport->port_name, &ids->port_name,
+ sizeof(rport->port_name));
+ rport->port_id = ids->port_id;
+ rport->roles = ids->roles;
+ rport->port_state = FC_PORTSTATE_ONLINE;
+ return rport;
+ }
+ }
- dev_printk(KERN_ERR, &starget->dev,
- "blocked target time out: target resuming\n");
+ /* No consistent binding found - create new remote port entry */
+ rport = fc_create_rport(shost, channel, ids);
- /*
- * set the device going again ... if the scsi lld didn't
- * unblock this device, then IO errors will probably
- * result if the host still isn't ready.
- */
- starget_for_each_device(starget, NULL, fc_device_unblock);
+ return rport;
+}
+EXPORT_SYMBOL(fc_remote_port_add);
+
+
+static void fc_remove_sdev(struct scsi_device *sdev, void *data)
+{
+ scsi_remove_device(sdev);
+}
+
+/*
+ * fc_rport_terminate - this routine tears down and deallocates a remote port.
+ * @rport: The remote port to be terminated
+ *
+ * Notes:
+ * This routine assumes no locks are held on entry.
+ */
+extern int lpfc_ext_debug;
+static void
+fc_rport_terminate(struct fc_rport *rport)
+{
+ struct Scsi_Host *shost = rport_to_shost(rport);
+ struct device *dev = &rport->dev;
+ unsigned long flags;
+
+ if (rport->starget) {
+ scsi_forget_target(rport->starget);
+ __scsi_remove_target(rport->starget);
+ }
+
+ transport_remove_device(dev);
+ device_del(dev);
+ transport_destroy_device(dev);
+ spin_lock_irqsave(shost->host_lock, flags);
+ list_del(&rport->peers);
+ spin_unlock_irqrestore(shost->host_lock, flags);
+ put_device(&shost->shost_gendev);
+
+ kfree(rport);
}
/**
- * fc_target_block - block a target by temporarily putting all its scsi devices
- * into the SDEV_BLOCK state.
- * @starget: scsi target managed by this fc scsi lldd.
- *
- * scsi lldd's with a FC transport call this routine to temporarily stop all
- * scsi commands to all devices managed by this scsi target. Called
- * from interrupt or normal process context.
+ * fc_remote_port_delete - notifies the fc transport that a remote
+ * port is no longer in existence.
+ * @rport: The remote port that no longer exists
*
- * Returns zero if successful or error if not
+ * The LLDD calls this routine to notify the transport that a remote
+ * port is no longer part of the topology. Note: Although a port
+ * may no longer be part of the topology, it may persist in the remote
+ * ports displayed by the fc_host. This is done so that target id
+ * mappings (managed via the remote port structures), are always visible
+ * as long as the mapping is valid, regardless of port state,
*
- * Notes:
- * The timeout and timer types are extracted from the fc transport
- * attributes from the caller's target pointer. This routine assumes no
- * locks are held on entry.
+ * If the remote port is not an FCP Target, it will be fully torn down
+ * and deallocated, including the fc_remote_port class device.
+ *
+ * If the remote port is an FCP Target, the port structure will be
+ * marked as Not Present, but will remain as long as there is a valid
+ * SCSI target id mapping associated with the port structure. Validity
+ * is determined by the binding type. If binding by wwpn, then the port
+ * structure is always valid and will not be deallocated until the host
+ * is removed. If binding by wwnn, then the port structure is valid
+ * until another port with the same node name is found in the topology.
+ * If binding by port id (fc address), then the port structure is valid
+ * valid until another port with the same address is identified.
+ *
+ * Called from interrupt or normal process context.
+ *
+ * Notes:
+ * This routine assumes no locks are held on entry.
**/
-int
-fc_target_block(struct scsi_target *starget)
+void
+fc_remote_port_delete(struct fc_rport *rport)
{
- int timeout = fc_starget_dev_loss_tmo(starget);
- struct work_struct *work = &fc_starget_dev_loss_work(starget);
+ struct Scsi_Host *shost = rport_to_shost(rport);
+ struct scsi_target *starget = rport->starget;
+ unsigned long flags;
+
+ /* If no scsi target id mapping or consistent binding type, delete it */
+ if ((rport->scsi_target_id == -1) ||
+ (fc_host_tgtid_bind_type(shost) == FC_TGTID_BIND_NONE)) {
+ fc_rport_terminate(rport);
+ return;
+ }
- if (timeout < 0 || timeout > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
- return -EINVAL;
+ /*
+ * If there is an associated scsi target - delete the attached
+ * scsi devices.
+ */
+ if (starget)
+ starget_for_each_device(starget, NULL, fc_remove_sdev);
- starget_for_each_device(starget, NULL, fc_device_block);
+ spin_lock_irqsave(shost->host_lock, flags);
+ list_move_tail(&rport->peers, &fc_host_rport_bindings(shost));
+ spin_unlock_irqrestore(shost->host_lock, flags);
- /* The scsi lld blocks this target for the timeout period only. */
- schedule_delayed_work(work, timeout * HZ);
+ /*
+ * Note: We do not remove or clear the hostdata area. This allows
+ * host-specific target data to persist along with the
+ * scsi_target_id. It's up to the host to manage it's hostdata area.
+ */
- return 0;
+ /*
+ * Reinitialize port attributes that may change if the port comes back.
+ */
+ rport->maxframe_size = -1;
+ rport->supported_classes = FC_COS_UNSPECIFIED;
+ rport->roles = FC_RPORT_ROLE_UNKNOWN;
+ rport->port_state = FC_PORTSTATE_NOTPRESENT;
+
+ /* remove the identifiers that aren't used in the consisting binding */
+ switch (fc_host_tgtid_bind_type(shost)) {
+ case FC_TGTID_BIND_BY_WWPN:
+ rport->node_name = -1;
+ rport->port_id = -1;
+ break;
+ case FC_TGTID_BIND_BY_WWNN:
+ rport->port_name = -1;
+ rport->port_id = -1;
+ break;
+ case FC_TGTID_BIND_BY_ID:
+ rport->node_name = -1;
+ rport->port_name = -1;
+ break;
+ case FC_TGTID_BIND_NONE: /* to keep compiler happy */
+ break;
+ }
}
-EXPORT_SYMBOL(fc_target_block);
+EXPORT_SYMBOL(fc_remote_port_delete);
/**
- * fc_target_unblock - unblock a target following a fc_target_block request.
- * @starget: scsi target managed by this fc scsi lldd.
+ * fc_remote_port_rolechg - notifies the fc transport that the roles
+ * on a remote may have changed.
+ * @rport: The remote port that changed.
*
- * scsi lld's with a FC transport call this routine to restart IO to all
- * devices associated with the caller's scsi target following a fc_target_block
- * request. Called from interrupt or normal process context.
+ * The LLDD calls this routine to notify the transport that the roles
+ * on a remote port may have changed. The largest effect of this is
+ * if a port now becomes a FCP Target, it must be allocated a
+ * scsi target id. If the port is no longer a FCP target, any
+ * scsi target id value assigned to it will persist in case the
+ * role changes back to include FCP Target. No changes in the scsi
+ * midlayer will be invoked if the role changes (in the expectation
+ * that the role will be resumed. If it doesn't normal error processing
+ * will take place).
+ *
+ * Should not be called from interrupt context.
*
- * Notes:
+ * Notes:
* This routine assumes no locks are held on entry.
**/
void
-fc_target_unblock(struct scsi_target *starget)
+fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
{
- /*
- * Stop the target timer first. Take no action on the del_timer
- * failure as the state machine state change will validate the
- * transaction.
- */
- if (cancel_delayed_work(&fc_starget_dev_loss_work(starget)))
- flush_scheduled_work();
+ struct Scsi_Host *shost = rport_to_shost(rport);
+ struct fc_host_attrs *fc_host =
+ (struct fc_host_attrs *)shost->shost_data;
+ unsigned long flags;
+ int create = 0;
+
+ rport->roles = roles;
+
+ spin_lock_irqsave(shost->host_lock, flags);
+ if ((rport->scsi_target_id == -1) &&
+ (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
+ rport->scsi_target_id = fc_host->next_target_id++;
+ create = 1;
+ }
+ spin_unlock_irqrestore(shost->host_lock, flags);
- starget_for_each_device(starget, NULL, fc_device_unblock);
+ if (create)
+ fc_create_starget(rport);
}
-EXPORT_SYMBOL(fc_target_unblock);
+EXPORT_SYMBOL(fc_remote_port_rolechg);
+
/**
- * fc_timeout_blocked_host - Timeout handler for blocked scsi hosts
+ * fc_device_block - called by target functions to block a scsi device
+ * @dev: scsi device
+ * @data: unused
+ **/
+static void fc_device_block(struct scsi_device *sdev, void *data)
+{
+ scsi_internal_device_block(sdev);
+}
+
+/**
+ * fc_device_unblock - called by target functions to unblock a scsi device
+ * @dev: scsi device
+ * @data: unused
+ **/
+static void fc_device_unblock(struct scsi_device *sdev, void *data)
+{
+ scsi_internal_device_unblock(sdev);
+}
+
+/**
+ * fc_timeout_blocked_tgt - Timeout handler for blocked scsi targets
* that fail to recover in the alloted time.
- * @data: scsi host that failed to recover its devices in the alloted
- * time.
+ * @data: scsi target that failed to reappear in the alloted time.
**/
-static void fc_timeout_blocked_host(void *data)
+static void fc_timeout_blocked_tgt(void *data)
{
- struct Scsi_Host *shost = (struct Scsi_Host *)data;
- struct scsi_device *sdev;
+ struct fc_rport *rport = (struct fc_rport *)data;
+ struct scsi_target *starget = rport->starget;
- dev_printk(KERN_ERR, &shost->shost_gendev,
- "blocked host time out: host resuming\n");
+ if (!starget)
+ return;
- shost_for_each_device(sdev, shost) {
- /*
- * set the device going again ... if the scsi lld didn't
- * unblock this device, then IO errors will probably
- * result if the host still isn't ready.
- */
- scsi_internal_device_unblock(sdev);
- }
+ dev_printk(KERN_ERR, &starget->dev,
+ "blocked target time out: target resuming\n");
+
+ /*
+ * As this only occurs if the remote port (scsi target)
+ * went away and didn't come back - we'll remove
+ * all attached scsi devices.
+ */
+ starget_for_each_device(starget, NULL, fc_remove_sdev);
}
/**
- * fc_host_block - block all scsi devices managed by the calling host temporarily
- * by putting each device in the SDEV_BLOCK state.
- * @shost: scsi host pointer that contains all scsi device siblings.
- *
- * scsi lld's with a FC transport call this routine to temporarily stop all
- * scsi commands to all devices managed by this host. Called
- * from interrupt or normal process context.
+ * fc_remote_port_block - temporarily block any scsi traffic to a remote port.
+ * @rport: remote port to be blocked.
+ *
+ * scsi lldd's with a FC transport call this routine to temporarily stop
+ * all scsi traffic to a remote port. If the port is not a SCSI target,
+ * no action is taken. If the port is a SCSI target, all attached devices
+ * are placed into a SDEV_BLOCK state and a timer is started. The timer is
+ * represents the maximum amount of time the port may be blocked. If the
+ * timer expires, the port is considered non-existent and the attached
+ * scsi devices will be removed.
+ *
+ * Called from interrupt or normal process context.
*
* Returns zero if successful or error if not
*
* Notes:
+ * This routine assumes no locks are held on entry.
+ *
* The timeout and timer types are extracted from the fc transport
- * attributes from the caller's host pointer. This routine assumes no
- * locks are held on entry.
+ * attributes from the caller's rport pointer.
**/
int
-fc_host_block(struct Scsi_Host *shost)
+fc_remote_port_block(struct fc_rport *rport)
{
- struct scsi_device *sdev;
- int timeout = fc_host_link_down_tmo(shost);
- struct work_struct *work = &fc_host_link_down_work(shost);
+ struct scsi_target *starget = rport->starget;
+ int timeout = rport->dev_loss_tmo;
+ struct work_struct *work = &rport->dev_loss_work;
- if (timeout < 0 || timeout > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
- return -EINVAL;
+ if (starget) {
+ if (timeout < 0 || timeout > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
+ return -EINVAL;
- shost_for_each_device(sdev, shost) {
- scsi_internal_device_block(sdev);
- }
+ starget_for_each_device(starget, NULL, fc_device_block);
- schedule_delayed_work(work, timeout * HZ);
+ /* cap the length the devices can be blocked */
+ schedule_delayed_work(work, timeout * HZ);
+ }
+ rport->port_state = FC_PORTSTATE_BLOCKED;
return 0;
}
-EXPORT_SYMBOL(fc_host_block);
+EXPORT_SYMBOL(fc_remote_port_block);
/**
- * fc_host_unblock - unblock all devices managed by this host following a
- * fc_host_block request.
- * @shost: scsi host containing all scsi device siblings to unblock.
+ * fc_remote_port_unblock - restart any blocked scsi traffic to a remote port.
+ * @rport: remote port to be unblocked.
*
- * scsi lld's with a FC transport call this routine to restart IO to all scsi
- * devices managed by the specified scsi host following an fc_host_block
+ * scsi lld's with a FC transport call this routine to restart IO to all
+ * devices associated with the caller's scsi target following a fc_target_block
* request. Called from interrupt or normal process context.
*
- * Notes:
+ * Notes:
* This routine assumes no locks are held on entry.
**/
void
-fc_host_unblock(struct Scsi_Host *shost)
+fc_remote_port_unblock(struct fc_rport *rport)
{
- struct scsi_device *sdev;
+ struct scsi_target *starget = rport->starget;
+ struct work_struct *work = &rport->dev_loss_work;
- /*
- * Stop the host timer first. Take no action on the del_timer
- * failure as the state machine state change will validate the
- * transaction.
- */
- if (cancel_delayed_work(&fc_host_link_down_work(shost)))
- flush_scheduled_work();
+ if (starget) {
+ /*
+ * Stop the target timer first. Take no action on the del_timer
+ * failure as the state machine state change will validate the
+ * transaction.
+ */
+ if (cancel_delayed_work(work))
+ flush_scheduled_work();
- shost_for_each_device(sdev, shost) {
- scsi_internal_device_unblock(sdev);
+ starget_for_each_device(starget, NULL, fc_device_unblock);
}
+
+ rport->port_state = FC_PORTSTATE_ONLINE;
}
-EXPORT_SYMBOL(fc_host_unblock);
+EXPORT_SYMBOL(fc_remote_port_unblock);
+
MODULE_AUTHOR("Martin Hicks");
MODULE_DESCRIPTION("FC Transport Attributes");
diff -puN a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
--- a/include/scsi/scsi_transport_fc.h 2005-02-08 21:10:36.000000000 -0500
+++ b/include/scsi/scsi_transport_fc.h 2005-02-08 21:39:08.000000000 -0500
@@ -16,6 +16,13 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ========
+ *
+ * Copyright (C) 2004-2005 James Smart, Emulex Corporation
+ * Rewrite for host, target, device, and remote port attributes,
+ * statistics, and service functions...
+ *
*/
#ifndef SCSI_TRANSPORT_FC_H
#define SCSI_TRANSPORT_FC_H
@@ -61,8 +68,10 @@ enum fc_port_type {
*/
enum fc_port_state {
FC_PORTSTATE_UNKNOWN,
+ FC_PORTSTATE_NOTPRESENT,
FC_PORTSTATE_ONLINE,
FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */
+ FC_PORTSTATE_BLOCKED,
FC_PORTSTATE_BYPASSED,
FC_PORTSTATE_DIAGNOSTICS,
FC_PORTSTATE_LINKDOWN,
@@ -103,35 +112,134 @@ enum fc_port_state {
* scsi_transport_fc.c (for the ascii descriptions).
*/
enum fc_tgtid_binding_type {
+ FC_TGTID_BIND_NONE,
FC_TGTID_BIND_BY_WWPN,
FC_TGTID_BIND_BY_WWNN,
FC_TGTID_BIND_BY_ID,
};
+/*
+ * FC Remote Port Roles
+ * Note: values are not enumerated, as they can be "or'd" together
+ * for reporting (e.g. report roles). If you alter this list,
+ * you also need to alter scsi_transport_fc.c (for the ascii descriptions).
+ */
+#define FC_RPORT_ROLE_UNKNOWN 0x00
+#define FC_RPORT_ROLE_FCP_TARGET 0x01
+#define FC_RPORT_ROLE_FCP_INITIATOR 0x02
+#define FC_RPORT_ROLE_IP_PORT 0x04
/*
- * FC Remote Port (Target) Attributes
+ * fc_rport_identifiers: This set of data contains all elements
+ * to uniquely identify a remote FC port. The driver uses this data
+ * to report the existence of a remote FC port in the topology. Internally,
+ * the transport uses this data for attributes and to manage consistent
+ * target id bindings.
+ */
+struct fc_rport_identifiers {
+ u64 node_name;
+ u64 port_name;
+ u32 port_id;
+ u32 roles;
+};
+
+/* Macro for use in defining Remote Port attributes */
+#define FC_RPORT_ATTR(_name,_mode,_show,_store) \
+struct class_device_attribute class_device_attr_rport_##_name = \
+ __ATTR(_name,_mode,_show,_store)
+
+
+/*
+ * FC Remote Port Attributes
+ *
+ * This structure exists for each remote FC port that a LLDD notifies
+ * the subsystem of. A remote FC port may or may not be a SCSI Target,
+ * also be a SCSI initiator, IP endpoint, etc. As such, the remote
+ * port is considered a separate entity, independent of "role" (such
+ * as scsi target).
+ *
+ * --
+ *
+ * Attributes are based on HBAAPI V2.0 definitions. Only those
+ * attributes that are determinable by the local port (aka Host)
+ * are contained.
+ *
+ * Fixed attributes are not expected to change. The driver is
+ * expected to set these values after successfully calling
+ * fc_remote_port_add(). The transport fully manages all get functions
+ * w/o driver interaction.
+ *
+ * Dynamic attributes are expected to change. The driver participates
+ * in all get/set operations via functions provided by the driver.
+ *
+ * Private attributes are transport-managed values. They are fully
+ * managed by the transport w/o driver interaction.
+ */
+
+struct fc_rport { /* aka fc_starget_attrs */
+ /* Fixed Attributes */
+ u32 maxframe_size;
+ u32 supported_classes;
+
+ /* Dynamic Attributes */
+ u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
+
+ /* Private (Transport-managed) Attributes */
+ u64 node_name;
+ u64 port_name;
+ u32 port_id;
+ u32 roles;
+ enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */
+ u32 scsi_target_id;
+
+ /* exported data */
+ struct scsi_target *starget;
+ void *dd_data; /* Used for driver-specific storage */
+
+ /* internal data */
+ unsigned int channel;
+ u32 number;
+ struct list_head peers;
+ struct device dev;
+ struct work_struct dev_loss_work;
+} __attribute__((aligned(sizeof(unsigned long))));
+
+#define dev_to_rport(d) \
+ container_of(d, struct fc_rport, dev)
+#define transport_class_to_rport(classdev) \
+ dev_to_rport(classdev->dev)
+#define rport_to_shost(r) \
+ dev_to_shost(r->dev.parent)
+
+/*
+ * FC SCSI Target Attributes
+ *
+ * The SCSI Target is considered an extention of a remote port (as
+ * a remote port can be more than a SCSI Target). Within the scsi
+ * subsystem, we leave the Target as a separate entity. Doing so
+ * provides backward compatibility with prior FC transport api's,
+ * and lets remote ports be handled entirely within the FC transport
+ * and independently from the scsi subsystem. The drawback is that
+ * some data will be duplicated.
*/
struct fc_starget_attrs { /* aka fc_target_attrs */
- int port_id;
+ /* Dynamic Attributes */
u64 node_name;
u64 port_name;
- u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
- struct work_struct dev_loss_work;
+ u32 port_id;
};
-#define fc_starget_port_id(x) \
- (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
#define fc_starget_node_name(x) \
(((struct fc_starget_attrs *)&(x)->starget_data)->node_name)
#define fc_starget_port_name(x) \
(((struct fc_starget_attrs *)&(x)->starget_data)->port_name)
-#define fc_starget_dev_loss_tmo(x) \
- (((struct fc_starget_attrs *)&(x)->starget_data)->dev_loss_tmo)
-#define fc_starget_dev_loss_work(x) \
- (((struct fc_starget_attrs *)&(x)->starget_data)->dev_loss_work)
+#define fc_starget_port_id(x) \
+ (((struct fc_starget_attrs *)&(x)->starget_data)->port_id)
+
+#define starget_to_rport(s) \
+ scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL
/*
@@ -183,6 +291,7 @@ struct fc_host_statistics {
* managed by the transport w/o driver interaction.
*/
+
#define FC_FC4_LIST_SIZE 32
#define FC_SYMBOLIC_NAME_SIZE 256
#define FC_VERSION_STRING_SIZE 64
@@ -210,13 +319,15 @@ struct fc_host_attrs {
u8 active_fc4s[FC_FC4_LIST_SIZE];
u32 speed;
u64 fabric_name;
- u32 link_down_tmo; /* Link Down timeout in seconds. */
/* Private (Transport-managed) Attributes */
enum fc_tgtid_binding_type tgtid_bind_type;
/* internal data */
- struct work_struct link_down_work;
+ struct list_head rports;
+ struct list_head rport_bindings;
+ u32 next_rport_number;
+ u32 next_target_id;
};
#define fc_host_node_name(x) \
@@ -255,21 +366,26 @@ struct fc_host_attrs {
(((struct fc_host_attrs *)(x)->shost_data)->speed)
#define fc_host_fabric_name(x) \
(((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
-#define fc_host_link_down_tmo(x) \
- (((struct fc_host_attrs *)(x)->shost_data)->link_down_tmo)
#define fc_host_tgtid_bind_type(x) \
(((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
-#define fc_host_link_down_work(x) \
- (((struct fc_host_attrs *)(x)->shost_data)->link_down_work)
+#define fc_host_rports(x) \
+ (((struct fc_host_attrs *)(x)->shost_data)->rports)
+#define fc_host_rport_bindings(x) \
+ (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings)
+#define fc_host_next_rport_number(x) \
+ (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number)
+#define fc_host_next_target_id(x) \
+ (((struct fc_host_attrs *)(x)->shost_data)->next_target_id)
/* The functions by which the transport class and the driver communicate */
struct fc_function_template {
- void (*get_starget_port_id)(struct scsi_target *);
+ void (*get_rport_dev_loss_tmo)(struct fc_rport *);
+ void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32);
+
void (*get_starget_node_name)(struct scsi_target *);
void (*get_starget_port_name)(struct scsi_target *);
- void (*get_starget_dev_loss_tmo)(struct scsi_target *);
- void (*set_starget_dev_loss_tmo)(struct scsi_target *, u32);
+ void (*get_starget_port_id)(struct scsi_target *);
void (*get_host_port_id)(struct Scsi_Host *);
void (*get_host_port_type)(struct Scsi_Host *);
@@ -277,22 +393,32 @@ struct fc_function_template {
void (*get_host_active_fc4s)(struct Scsi_Host *);
void (*get_host_speed)(struct Scsi_Host *);
void (*get_host_fabric_name)(struct Scsi_Host *);
- void (*get_host_link_down_tmo)(struct Scsi_Host *);
- void (*set_host_link_down_tmo)(struct Scsi_Host *, u32);
struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
void (*reset_fc_host_stats)(struct Scsi_Host *);
+ /* allocation lengths for host-specific data */
+ u32 dd_fcrport_size;
+
/*
* The driver sets these to tell the transport class it
* wants the attributes displayed in sysfs. If the show_ flag
* is not set, the attribute will be private to the transport
* class
*/
- unsigned long show_starget_port_id:1;
+ /* remote port fixed attributes */
+ unsigned long show_rport_maxframe_size:1;
+ unsigned long show_rport_supported_classes:1;
+ unsigned long show_rport_dev_loss_tmo:1;
+
+ /*
+ * target dynamic attributes
+ * These should all be "1" if the driver uses the remote port
+ * add/delete functions (so attributes reflect rport values).
+ */
unsigned long show_starget_node_name:1;
unsigned long show_starget_port_name:1;
- unsigned long show_starget_dev_loss_tmo:1;
+ unsigned long show_starget_port_id:1;
/* host fixed attributes */
unsigned long show_host_node_name:1;
@@ -314,15 +440,18 @@ struct fc_function_template {
unsigned long show_host_active_fc4s:1;
unsigned long show_host_speed:1;
unsigned long show_host_fabric_name:1;
- unsigned long show_host_link_down_tmo:1;
};
struct scsi_transport_template *fc_attach_transport(struct fc_function_template *);
void fc_release_transport(struct scsi_transport_template *);
-int fc_target_block(struct scsi_target *starget);
-void fc_target_unblock(struct scsi_target *starget);
-int fc_host_block(struct Scsi_Host *shost);
-void fc_host_unblock(struct Scsi_Host *shost);
+void fc_remove_host(struct Scsi_Host *);
+struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost,
+ int channel, struct fc_rport_identifiers *ids);
+void fc_remote_port_delete(struct fc_rport *rport);
+void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles);
+int fc_remote_port_block(struct fc_rport *rport);
+void fc_remote_port_unblock(struct fc_rport *rport);
+int scsi_is_fc_rport(const struct device *);
#endif /* SCSI_TRANSPORT_FC_H */
_
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch
2005-02-09 4:18 [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch James.Smart
@ 2005-02-09 8:15 ` Mike Christie
2005-02-09 18:09 ` Christoph Hellwig
2005-02-09 18:32 ` Andrew Vasquez
2 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2005-02-09 8:15 UTC (permalink / raw)
To: James.Smart; +Cc: linux-scsi
+static void
+fc_rport_terminate(struct fc_rport *rport)
+{
+ struct Scsi_Host *shost = rport_to_shost(rport);
+ struct device *dev = &rport->dev;
+ unsigned long flags;
+
+ if (rport->starget) {
+ scsi_forget_target(rport->starget);
+ __scsi_remove_target(rport->starget);
+ }
+
+ transport_remove_device(dev);
+ device_del(dev);
+ transport_destroy_device(dev);
+ spin_lock_irqsave(shost->host_lock, flags);
+ list_del(&rport->peers);
+ spin_unlock_irqrestore(shost->host_lock, flags);
+ put_device(&shost->shost_gendev);
+
+ kfree(rport);
}
Do you want to free the memory in the struct device's release
function like the scsi_device's release function? If userspace
has a sysfs file open and is reading or writing to it at the
same time you free the memory here, will fun things happen?
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch
2005-02-09 4:18 [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch James.Smart
2005-02-09 8:15 ` Mike Christie
@ 2005-02-09 18:09 ` Christoph Hellwig
2005-02-09 18:32 ` Andrew Vasquez
2 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2005-02-09 18:09 UTC (permalink / raw)
To: James.Smart; +Cc: linux-scsi
This one doesn't apply to scsi-misc + your previous two patches for me.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch
2005-02-09 4:18 [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch James.Smart
2005-02-09 8:15 ` Mike Christie
2005-02-09 18:09 ` Christoph Hellwig
@ 2005-02-09 18:32 ` Andrew Vasquez
2 siblings, 0 replies; 8+ messages in thread
From: Andrew Vasquez @ 2005-02-09 18:32 UTC (permalink / raw)
To: James.Smart; +Cc: linux-scsi
On Tue, 08 Feb 2005, James.Smart@Emulex.Com wrote:
> This patch also moves the dev_loss attribute from the target-level
> fc_transport device to the remote port device. It also deletes the
> link_down attribute. The fc_target_block and fc_target_unblock
> routines have been replaced by fc_remote_port_block and
> fc_remote_port_unblock. The fc_host_block/unblock functions have
> been removed (unused).
>
still trying to track down the following oops:
Unable to handle kernel paging request at virtual address 6b6b6be7
printing eip:
c028ef0f
*pde = 00000000
Oops: 0000 [#1]
SMP
Modules linked in: qla2322 qla2xxx
CPU: 0
EIP: 0060:[<c028ef0f>] Not tainted VLI
EFLAGS: 00010082 (2.6.11-rport)
EIP is at scsi_device_get+0x2f/0x70
eax: 6b6b6b6b ebx: c156aac4 ecx: d9bd1b90 edx: fffffffa
esi: c156ac58 edi: c156aac4 ebp: d9bd1b74 esp: dcc3fe08
ds: 007b es: 007b ss: 0068
Process qla2322_3_dpc (pid: 12662, threadinfo=dcc3e000 task=dfebca40)
Stack: d9bd1b7c d5318000 c028efda 00000286 d9bd1b74 d7487ccc d5318000
c029af10
c028f07d 00000000 db507c74 d7487ccc 00000023 db507d70 c029afbf
d68d07fc
00000000 d53181fc d5319338 e08633d3 c01020b5 c04221ec 00000282
0000002c
Call Trace:
[<c028efda>] __scsi_iterate_devices+0x3a/0x70
[<c029af10>] fc_device_block+0x0/0x10
[<c028f07d>] starget_for_each_device+0x6d/0x80
[<c029afbf>] fc_remote_port_block+0x3f/0x70
[<e08633d3>] qla2x00_mark_device_lost+0x53/0xe0 [qla2xxx]
[<c01020b5>] __down_trylock+0x65/0x80
[<c03097ab>] __down_failed_trylock+0x7/0xc
[<c011be61>] vprintk+0x141/0x160
[<e0867508>] qla2x00_device_resync+0x238/0x2d0 [qla2xxx]
[<e08682d0>] qla2x00_mbx_sem_timeout+0x0/0x10 [qla2xxx]
[<e08668bc>] qla2x00_configure_fabric+0x7c/0x3e0 [qla2xxx]
[<c01f3d54>] vsnprintf+0x394/0x510
[<c01176fd>] __wake_up_locked+0x1d/0x20
[<c01020b5>] __down_trylock+0x65/0x80
[<c03097ab>] __down_failed_trylock+0x7/0xc
[<c011be61>] vprintk+0x141/0x160
[<e086629a>] qla2x00_configure_loop+0x1aa/0x200 [qla2xxx]
[<e086793c>] qla2x00_loop_resync+0x8c/0xd0 [qla2xxx]
[<e0864115>] qla2x00_do_dpc+0x3a5/0x470 [qla2xxx]
[<c010310a>] work_resched+0x5/0x16
[<e0863d70>] qla2x00_do_dpc+0x0/0x470 [qla2xxx]
[<c0101345>] kernel_thread_helper+0x5/0x10
Code: ff ff 53 89 c3 8b 80 a8 02 00 00 83 e8 03 83 f8 01 76 3e 8d b3
94 01 00 00 89 f0 e8 6c cc fb ff 85 c0 ba fa ff ff ff 74 28 8b 03 <8b>
40 7c 8b 10 85 d2 74 1b b8 00 e0 ff ff 21 e0 83 3a 02 8b 40
seems like sdev->shost is bogus when fc_remote_port_block() is
called...
On a side note:
+/*
+ * fc_rport_terminate - this routine tears down and deallocates a remote port.
+ * @rport: The remote port to be terminated
+ *
+ * Notes:
+ * This routine assumes no locks are held on entry.
+ */
+extern int lpfc_ext_debug;
+static void
+fc_rport_terminate(struct fc_rport *rport)
+{
lpfc_ext_debug -- residuals from some test code?
--
AV
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch
@ 2005-02-09 18:07 James.Smart
0 siblings, 0 replies; 8+ messages in thread
From: James.Smart @ 2005-02-09 18:07 UTC (permalink / raw)
To: mikenc; +Cc: linux-scsi
> Do you want to free the memory in the struct device's release
> function like the scsi_device's release function? If userspace
> has a sysfs file open and is reading or writing to it at the
> same time you free the memory here, will fun things happen?
Yep...
Here's a small patch to correct for this...
-- James S
diff -puN a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
--- a/drivers/scsi/scsi_transport_fc.c 2005-02-09 09:04:32.000000000 -0500
+++ b/drivers/scsi/scsi_transport_fc.c 2005-02-09 09:06:33.000000000 -0500
@@ -984,7 +984,9 @@ static int fc_target_match(struct attrib
static void fc_rport_dev_release(struct device *dev)
{
+ struct fc_rport *rport = dev_to_rport(dev);
put_device(dev->parent);
+ kfree(rport);
}
int scsi_is_fc_rport(const struct device *dev)
@@ -1410,8 +1412,6 @@ fc_rport_terminate(struct fc_rport *rpo
list_del(&rport->peers);
spin_unlock_irqrestore(shost->host_lock, flags);
put_device(&shost->shost_gendev);
-
- kfree(rport);
}
/**
_
^ permalink raw reply [flat|nested] 8+ messages in thread* RE: [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch
@ 2005-02-09 19:24 James.Smart
2005-02-09 23:03 ` Andrew Vasquez
0 siblings, 1 reply; 8+ messages in thread
From: James.Smart @ 2005-02-09 19:24 UTC (permalink / raw)
To: andrew.vasquez; +Cc: linux-scsi
> seems like sdev->shost is bogus when fc_remote_port_block() is
> called...
We haven't seen this in our testing....
> lpfc_ext_debug -- residuals from some test code?
yep - thought I had everything, guess not. I'm rebacking to
scsi-misc-2.6 and will repost. This will be taken care of.
-- James
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch
2005-02-09 19:24 James.Smart
@ 2005-02-09 23:03 ` Andrew Vasquez
2005-02-10 18:56 ` Andrew Vasquez
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Vasquez @ 2005-02-09 23:03 UTC (permalink / raw)
To: James.Smart; +Cc: linux-scsi
On Wed, 09 Feb 2005, James.Smart@Emulex.Com wrote:
> > seems like sdev->shost is bogus when fc_remote_port_block() is
> > called...
>
> We haven't seen this in our testing....
>
Actually it's not the sdev->host that's bogus -- it appears the sdev
is referenced after it's been freed -- a reference still present in
the shost->__devices list. Here's the scenario:
* 1 lun connected to HBA1 -- sdev created for the lun via rport:
*** sdev=d76196e8 host=d36f0000 state=2 gdev=d761987c
* mid-layer performs linear scan of non-existent ID's (via
scsi_sysfs_target_initialize():
*** adding sdev=dd2bc738 sdev->siblings=dd2bc740, __dev=d36f0000 id=1 emp=0
...
*** adding sdev=dd2bc738 sdev->siblings=dd2bc740, __dev=d36f0000 id=509 emp=0
*** adding sdev=dd2bc738 sdev->siblings=dd2bc740, __dev=d36f0000 id=510 emp=0
*** adding sdev=dd2bc738 sdev->siblings=dd2bc740, __dev=d36f0000 id=511 emp=0
* remove lun from the fabric (port-side cable pull).
* driver recognizes loss via RSCN, issues fc_remote_port_block(),
starget_for_each_device() -> shost_for_each_device() ->
__scsi_iterate_devices() where scsi_device_get() is called for
reference.
1st sdev valid (ok):
*** ctr=0 sdev=d76196e8 host=d36f0000 state=2 gdev=d761987c id=0
*** sdev=d76196e8 host=d36f0000 state=2 gdev=d761987c
2nd sdev invalid -- note old sdev (dd2bc738) from previous linear
scan:
*** ctr=0 sdev=dd2bc738 host=6b6b6b6b state=1802201963 gdev=dd2bc8cc id=1802201963
*** sdev=dd2bc738 host=6b6b6b6b state=1802201963 gdev=dd2bc8cc
[BLAH]
Unable to handle kernel paging request at virtual address 6b6b6be7
printing eip:
c028ef06
*pde = 00000000
Oops: 0000 [#1]
SMP
Modules linked in: qla2322 qla2xxx
CPU: 0
EIP: 0060:[<c028ef06>] Not tainted VLI
EFLAGS: 00010086 (2.6.11-rport)
EIP is at scsi_device_get+0x56/0xa0
eax: 6b6b6b6b ebx: dd2bc738 ecx: c035f844 edx: fffffffa
esi: dd2bc8cc edi: d36f0000 ebp: 00000001 esp: df693dd4
ds: 007b es: 007b ss: 0068
Process qla2322_1_dpc (pid: 11316, threadinfo=df692000 task=d9fa8530)
Stack: c0341fcc dd2bc738 6b6b6b6b 6b6b6b6b dd2bc8cc dd2bc738 d76196f0 c028f011
c0341ff4 00000000 dd2bc738 6b6b6b6b 6b6b6b6b dd2bc8cc 6b6b6b6b 00000282
d76196e8 d76196e8 ddd7e790 d36f0000 c029af50 c028f0bd 00000000 dbe8512c
Cale Trace:
[<c028f011>] __scsi_iterate_devices+0x71/0xb0
[<c029af50>] fc_device_block+0x0/0x10
[<c028f0bd>] starget_for_each_device+0x6d/0x80
[<c029afff>] fc_remote_port_block+0x3f/0x70
[<e08633d3>] qla2x00_mark_device_lost+0x53/0xe0 [qla2xxx]
signature very consistent.
Another quirk when run with no storage connected to HBAs and the
driver is loaded, then unloaded -- is a consistent BUG() hit in
_raw_spin_lock() via scsi_forget_host():
kernel BUG at include/asm/spinlock.h:149!
invalid operand: 0000 [#1]
SMP
Modules linked in: qla2322 qla2xxx
CPU: 1
EIP: 0060:[<c030b373>] Not tainted VLI
EFLAGS: 00010096 (2.6.11-rport)
EIP is at _spin_lock_irqsave+0x53/0x60
eax: 0000000e ebx: 00000282 ecx: c035f80c edx: 00000082
esi: 6b6b6bab edi: d86f1ecc ebp: d348d530 esp: d86f1ea4
ds: 007b es: 007b ss: 0068
Process rmmod (pid: 11209, threadinfo=d86f0000 task=d348d530)
Stack: c031e548 c030960c 6b6b6ba3 6b6b6bab c030960c 00000000 d348d530 c0117610
00000000 00000000 0000006b d3920000 6b6b6b6b da0c3b74 d3920000 6b6b6b6b
d86f0000 c03097d3 d392002c 0000006b c0297656 6b6b6b63 d3920000 6b6b6b63
Call Trace:
[<c030960c>] __down+0x3c/0xe0
[<c030960c>] __down+0x3c/0xe0
[<c0117610>] default_wake_function+0x0/0x10
[<c03097d3>] __down_failed+0x7/0xc
[<c0297656>] .text.lock.scsi_sysfs+0x8/0x22
[<c0296061>] scsi_forget_host+0x31/0x60
[<c028f3e1>] scsi_remove_host+0x11/0x60
[<e08629df>] qla2x00_remove_one+0x1f/0x40 [qla2xxx]
[<c01f9108>] pci_device_remove+0x28/0x30
[<c024cc04>] device_release_driver+0x74/0x80
[<c024cc28>] driver_detach+0x18/0x30
[<c024d13c>] bus_remove_driver+0x5c/0xa0
[<c024d6c8>] driver_unregister+0x8/0x30
[<c01f933b>] pci_unregister_driver+0xb/0x20
[<c013279e>] sys_delete_module+0x16e/0x190
[<c014b61a>] unmap_vma_list+0x1a/0x30
[<c014b9c5>] do_munmap+0x115/0x160
[<c014ba5a>] sys_munmap+0x4a/0x70
[<c010308d>] sysenter_past_esp+0x52/0x75
Code: 90 80 3e 00 7e f9 fa eb e8 89 d8 8b 74 24 0c 8b 5c 24 08 83 c4 10 c3 c7 04 24 48 e5 31 c0 8b 44
host variable seems to be hosed. Perhaps I'm doing something wrong
during shutdown -- just the standard scsi_remove_host(), I also tried
to add the fc_remove_host() call (as per directed in comments) but
same results occured...
Andrew Vasquez
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch
2005-02-09 23:03 ` Andrew Vasquez
@ 2005-02-10 18:56 ` Andrew Vasquez
0 siblings, 0 replies; 8+ messages in thread
From: Andrew Vasquez @ 2005-02-10 18:56 UTC (permalink / raw)
To: James.Smart, linux-scsi
On Wed, 09 Feb 2005, Andrew Vasquez wrote:
> On Wed, 09 Feb 2005, James.Smart@Emulex.Com wrote:
>
> > > seems like sdev->shost is bogus when fc_remote_port_block() is
> > > called...
> >
> > We haven't seen this in our testing....
> >
>
> Actually it's not the sdev->host that's bogus -- it appears the sdev
> is referenced after it's been freed -- a reference still present in
> the shost->__devices list. Here's the scenario:
>
...
> Unable to handle kernel paging request at virtual address 6b6b6be7
> printing eip:
> c028ef06
> *pde = 00000000
> Oops: 0000 [#1]
> SMP
> Modules linked in: qla2322 qla2xxx
> CPU: 0
> EIP: 0060:[<c028ef06>] Not tainted VLI
> EFLAGS: 00010086 (2.6.11-rport)
> EIP is at scsi_device_get+0x56/0xa0
> eax: 6b6b6b6b ebx: dd2bc738 ecx: c035f844 edx: fffffffa
> esi: dd2bc8cc edi: d36f0000 ebp: 00000001 esp: df693dd4
> ds: 007b es: 007b ss: 0068
> Process qla2322_1_dpc (pid: 11316, threadinfo=df692000 task=d9fa8530)
> Stack: c0341fcc dd2bc738 6b6b6b6b 6b6b6b6b dd2bc8cc dd2bc738 d76196f0 c028f011
> c0341ff4 00000000 dd2bc738 6b6b6b6b 6b6b6b6b dd2bc8cc 6b6b6b6b 00000282
> d76196e8 d76196e8 ddd7e790 d36f0000 c029af50 c028f0bd 00000000 dbe8512c
> Cale Trace:
> [<c028f011>] __scsi_iterate_devices+0x71/0xb0
> [<c029af50>] fc_device_block+0x0/0x10
> [<c028f0bd>] starget_for_each_device+0x6d/0x80
> [<c029afff>] fc_remote_port_block+0x3f/0x70
> [<e08633d3>] qla2x00_mark_device_lost+0x53/0xe0 [qla2xxx]
>
Ok, there seems to also be some sdev reference counting issues --
within scsi_alloc_sdev() we are never tearing-down the the
cooresponding starget references created within
scsi_sysfs_target_initialize().
> Another quirk when run with no storage connected to HBAs and the
> driver is loaded, then unloaded -- is a consistent BUG() hit in
> _raw_spin_lock() via scsi_forget_host():
>
> kernel BUG at include/asm/spinlock.h:149!
> invalid operand: 0000 [#1]
this issue also appears to be fixed with the patch.
--
AV
diff -urd 1.8/drivers/scsi/scsi_scan.c edited/drivers/scsi/scsi_scan.c
--- 1.8/drivers/scsi/scsi_scan.c 2005-02-09 11:30:52 -08:00
+++ edited/drivers/scsi/scsi_scan.c 2005-02-10 10:16:44 -08:00
@@ -248,8 +248,10 @@
spin_lock_init(&sdev->sdev_lock);
sdev->request_queue = scsi_alloc_queue(sdev);
- if (!sdev->request_queue)
- goto out_free_dev;
+ if (!sdev->request_queue) {
+ kfree(sdev);
+ goto out;
+ }
sdev->request_queue->queuedata = sdev;
scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
@@ -284,8 +286,7 @@
out_device_destroy:
transport_destroy_device(&sdev->sdev_gendev);
scsi_free_queue(sdev->request_queue);
-out_free_dev:
- kfree(sdev);
+ put_device(&sdev->sdev_gendev);
out:
if (display_failure_msg)
printk(ALLOC_FAILURE_MSG, __FUNCTION__);
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-02-10 21:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-09 4:18 [PATCH 2/2 scsi-rc-fixes-2.6] FC Remote Port patch James.Smart
2005-02-09 8:15 ` Mike Christie
2005-02-09 18:09 ` Christoph Hellwig
2005-02-09 18:32 ` Andrew Vasquez
-- strict thread matches above, loose matches on Subject: below --
2005-02-09 18:07 James.Smart
2005-02-09 19:24 James.Smart
2005-02-09 23:03 ` Andrew Vasquez
2005-02-10 18:56 ` Andrew Vasquez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox