Skip to contentSkip to conversation

Transport Attributes -- attempt#2

PATCH Martin Hicks 8 participants 14 messages Jan 7, 2004 – Jan 20, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

Here's my next whack at export Transport-specific attributes to sysfs.

This version has the following changes. The person who suggested the change is quoted in brackets.

-Stuck the transport attributes and trancport class pointer into the
host template. (hch)

-Separated the two classes into their own .c files. (jejb)

-Removed attribute overloading. (jejb)

The number of changes that must be done in the host driver are much smaller now, and I think the whole idea is a little cleaner. Removing the attribute overloading really cleaned things up a lot.

There are three patches attached. The core patch, and two driver patches (qla2xxx and qla1280).

Opinions or other comments are welcome.
mh

Signature · 2 lines
Martin Hicks                Wild Open Source Inc.
[email protected]     613-266-2296

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1520 -> 1.1521
# include/scsi/scsi_device.h 1.11 -> 1.12
# include/scsi/scsi_host.h 1.13 -> 1.14
# drivers/scsi/scsi_sysfs.c 1.38 -> 1.39
# drivers/scsi/scsi_scan.c 1.114 -> 1.115
# drivers/scsi/Makefile 1.50 -> 1.51

#	drivers/scsi/Kconfig	1.47    -> 1.48   
#	               (new)	        -> 1.1     drivers/scsi/scsi_transport.c
#	               (new)	        -> 1.1     include/scsi/scsi_transport.h
#	               (new)	        -> 1.1     include/scsi/scsi_transport_pscsi.h
#	               (new)	        -> 1.1     include/scsi/scsi_transport_fc.h
#	               (new)	        -> 1.1     drivers/scsi/scsi_transport_pscsi.c
#	               (new)	        -> 1.1     drivers/scsi/scsi_transport_fc.c

#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/01/07 [email protected] 1.1521
# Add the transport attributes core.
# --------------------------------------------
#

drivers/scsi/Kconfig +19 -0
diff -Nru a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
@@ -196,6 +196,25 @@
 	  there should be no noticeable performance impact as long as you have
 	  logging turned off.
 
+menu "SCSI Transport Attributes (EXPERIMENTAL)"
+	depends on EXPERIMENTAL && SCSI!=n
+
+config SCSI_PSCSI_ATTRS
+	bool "Parallel SCSI Transport Attributes"
+	depends on SCSI
+	help
+	  If you wish to export transport-specific information about
+	  each attached SCSI device to sysfs, say Y.  Otherwise, say N.
+
+config SCSI_FC_ATTRS
+	bool "FiberChannel Transport Attributes"
+	depends on SCSI
+	help
+	  If you wish to export transport-specific information about
+	  each attached FiberChannel device to sysfs, say Y.
+	  Otherwise, say N.
+
+endmenu
 
 menu "SCSI low-level drivers"
 	depends on SCSI!=n
drivers/scsi/Makefile +5 -2
diff -Nru a/drivers/scsi/Makefile b/drivers/scsi/Makefile
@@ -127,14 +127,17 @@
 obj-$(CONFIG_BLK_DEV_SR)	+= sr_mod.o
 obj-$(CONFIG_CHR_DEV_SG)	+= sg.o
 
+obj-$(CONFIG_SCSI_PSCSI_ATTRS)	+= scsi_transport_pscsi.o
+obj-$(CONFIG_SCSI_FC_ATTRS)	+= scsi_transport_fc.o
+
 scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o constants.o \
 				   scsicam.o scsi_error.o scsi_lib.o \
 				   scsi_scan.o scsi_syms.o scsi_sysfs.o \
-				   scsi_devinfo.o
+				   scsi_devinfo.o scsi_transport.o
 scsi_mod-$(CONFIG_SYSCTL)	+= scsi_sysctl.o
 scsi_mod-$(CONFIG_SCSI_PROC_FS)	+= scsi_proc.o
 scsi_mod-$(CONFIG_X86_PC9800)	+= scsi_pc98.o
-			
+
 sd_mod-objs	:= sd.o
 sr_mod-objs	:= sr.o sr_ioctl.o sr_vendor.o
 initio-objs	:= ini9100u.o i91uscsi.o
drivers/scsi/scsi_scan.c +7 -1
diff -Nru a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
@@ -238,7 +238,6 @@
 	}
 
 	if (get_device(&sdev->host->shost_gendev)) {
-
 		device_initialize(&sdev->sdev_gendev);
 		sdev->sdev_gendev.parent = &sdev->host->shost_gendev;
 		sdev->sdev_gendev.bus = &scsi_bus_type;
@@ -251,6 +250,13 @@
 		sdev->sdev_classdev.dev = &sdev->sdev_gendev;
 		sdev->sdev_classdev.class = &sdev_class;
 		snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
+			 "%d:%d:%d:%d", sdev->host->host_no,
+			 sdev->channel, sdev->id, sdev->lun);
+
+		class_device_initialize(&sdev->transport_classdev);
+		sdev->transport_classdev.dev = &sdev->sdev_gendev;
+		sdev->transport_classdev.class = sdev->host->hostt->transport_class;
+		snprintf(sdev->transport_classdev.class_id, BUS_ID_SIZE,
 			 "%d:%d:%d:%d", sdev->host->host_no,
 			 sdev->channel, sdev->id, sdev->lun);
 	} else
drivers/scsi/scsi_sysfs.c +51 -6

85 lines not on this page · raw message

drivers/scsi/scsi_transport.c new file +39 -0
diff -Nru a/drivers/scsi/scsi_transport.c b/drivers/scsi/scsi_transport.c
@@ -0,0 +1,39 @@
+/* 
+ *  Transport specific attributes exported to sysfs.
+ *
+ *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  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
+ */
+
+#include <linux/config.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_transport_pscsi.h>
+#include <scsi/scsi_transport_fc.h>
+
+int scsi_add_transport_attributes(struct scsi_device *sdev)
+{
+	int error, i;
+	struct class_device_attribute **attrs = sdev->host->hostt->transport_attrs;
+
+	for (i = 0; attrs[i]; i++) {
+                error = class_device_create_file(&sdev->transport_classdev,
+                                                 attrs[i]);
+                if (error)
+                        return error;
+        }
+        return 0;
+}
drivers/scsi/scsi_transport_fc.c new file +108 -0

108 lines not on this page · raw message

drivers/scsi/scsi_transport_pscsi.c new file +104 -0

104 lines not on this page · raw message

include/scsi/scsi_device.h +3 -0
diff -Nru a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
@@ -103,6 +103,9 @@
 	struct device		sdev_gendev;
 	struct class_device	sdev_classdev;
 
+	void *			transport_attr_values;
+	struct class_device	transport_classdev;
+
 	enum scsi_device_state sdev_state;
 };
 #define	to_scsi_device(d)	\
include/scsi/scsi_host.h +6 -0
diff -Nru a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
@@ -337,6 +337,12 @@
 	struct device_attribute **sdev_attrs;
 
 	/*
+	 * Pointers to the Transport attributes and the Transport class.
+	 */
+	struct class_device_attribute **transport_attrs;
+	struct class *transport_class;
+
+	/*
 	 * List of hosts per template.
 	 *
 	 * This is only for use by scsi_module.c for legacy templates.
include/scsi/scsi_transport.h new file +39 -0
diff -Nru a/include/scsi/scsi_transport.h b/include/scsi/scsi_transport.h
@@ -0,0 +1,39 @@
+/* 
+ *  Transport specific attributes exported to sysfs.
+ *
+ *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  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
+ */
+#ifndef SCSI_TRANSPORT_H
+#define SCSI_TRANSPORT_H
+
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_transport_pscsi.h>
+#include <scsi/scsi_transport_fc.h>
+
+#define transport_class_to_sdev(class_dev) \
+	container_of(class_dev, struct scsi_device, transport_classdev)
+
+static inline void transport_class_release(struct class_device *class_dev)
+{
+	struct scsi_device *sdev = transport_class_to_sdev(class_dev);
+	put_device(&sdev->sdev_gendev);
+}
+
+extern int scsi_add_transport_attributes(struct scsi_device *sdev);
+extern int scsi_export_transport_attributes(struct scsi_device *sdev);
+
+#endif /* SCSI_TRANSPORT_H */
include/scsi/scsi_transport_fc.h new file +44 -0

44 lines not on this page · raw message

include/scsi/scsi_transport_pscsi.h new file +42 -0

42 lines not on this page · raw message

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1521 -> 1.1522
# drivers/scsi/Kconfig 1.48 -> 1.49
# drivers/scsi/qla1280.c 1.51 -> 1.52
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/01/07 [email protected] 1.1522
# Export transport attributes from qla1280
# --------------------------------------------
#

drivers/scsi/Kconfig +1 -1
diff -Nru a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
@@ -1210,7 +1210,7 @@
 
 config SCSI_QLOGIC_1280
 	tristate "Qlogic QLA 1280 SCSI support"
-	depends on PCI && SCSI
+	depends on PCI && SCSI && SCSI_PSCSI_ATTRS
 	help
 	  Say Y if you have a QLogic ISP1x80/1x160 SCSI host adapter.
 
drivers/scsi/qla1280.c +44 -0

103 lines not on this page · raw message

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1522 -> 1.1523
# drivers/scsi/qla2xxx/Kconfig 1.1 -> 1.2
# drivers/scsi/qla2xxx/qla_os.c 1.1 -> 1.2
# drivers/scsi/qla2xxx/qla_os.h 1.1 -> 1.2
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/01/07 [email protected] 1.1523
# Export transport attributes from qla2xxx
# --------------------------------------------
#

drivers/scsi/qla2xxx/Kconfig +1 -1
diff -Nru a/drivers/scsi/qla2xxx/Kconfig b/drivers/scsi/qla2xxx/Kconfig
@@ -1,6 +1,6 @@
 config SCSI_QLA2XXX
 	bool "QLogic ISP2xxx PCI/PCI-X Fibre Channel HBA Support"
-	depends on PCI && SCSI
+	depends on PCI && SCSI && SCSI_FC_ATTRS
 	---help---
 	These drivers support the QLogic 2xxx host adapter family of SCSI FCP
 	HBAs.
drivers/scsi/qla2xxx/qla_os.c +53 -4

105 lines not on this page · raw message

drivers/scsi/qla2xxx/qla_os.h +2 -1
diff -Nru a/drivers/scsi/qla2xxx/qla_os.h b/drivers/scsi/qla2xxx/qla_os.h
@@ -56,6 +56,7 @@
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/init.h>
+#include <linux/list.h>
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -91,7 +92,7 @@
 
 #include "scsi.h"
 #include "hosts.h"
-
+#include <scsi/scsi_transport.h>
 #include <scsi/scsicam.h>
 #include <scsi/scsi_ioctl.h>
 
#1 lore raw

+config SCSI_PSCSI_ATTRS
+ bool "Parallel SCSI Transport Attributes"

Quoted 4 lines
Quoted 4 lines

Scan we replacte the PSCSI/pscsi in identifiers with SPI/spi as used in the t10 standards documents please? This is a bit shorter and the correct name. In user-visible string Parallel SCSI is fine with me, but maybe it should rather be

bool "Parallel SCSI (SPI) Transport Attributes"

+obj-$(CONFIG_SCSI_PSCSI_ATTRS) += scsi_transport_pscsi.o
+obj-$(CONFIG_SCSI_FC_ATTRS) += scsi_transport_fc.o

Quoted 4 lines
Quoted 4 lines

This is wrong. Currently the option are bool and you'd build them into the kernel even if the scsi code is modular. Either use scsi_mod-* or make them their own modules using tristate (I still think that's overkill just for the attributes, but jejb seems to like it)

snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
+ "%d:%d:%d:%d", sdev->host->host_no,
+ sdev->channel, sdev->id, sdev->lun);
+
+ class_device_initialize(&sdev->transport_classdev);
+ sdev->transport_classdev.dev = &sdev->sdev_gendev;
+ sdev->transport_classdev.class = sdev->host->hostt->transport_class;
+ snprintf(sdev->transport_classdev.class_id, BUS_ID_SIZE,

Quoted 2 lines
Quoted 2 lines

Out of curiosity: Why do we need _another_ classdev. Can't you reuse the current one?

+ error = class_register(&sdev_class);
+ if (error)
+ goto undo_bus;
+
+#ifdef CONFIG_SCSI_PSCSI_ATTRS
+ error = scsi_pscsi_transport_init();
+ if (error)
+ goto undo_sdev;
+#endif
+#ifdef CONFIG_SCSI_FC_ATTRS
+ error = scsi_fc_transport_init();
+ if (error)
+ goto undo_all;
+#endif

Quoted 2 lines

Please put stubs in the header instead of ifdefs in the code. (And 1:0 for jejb, with the moular approach this would just go away :))

+ out:
return error;
+
+ /* Prevent "unused label" warnings when either of the
+ * transport attributes config options are turned off. */
+ goto undo_all;
+ goto undo_sdev;

Quoted 1 line
Quoted 1 line

Yikes!

+int scsi_add_transport_attributes(struct scsi_device *sdev) +{
+ int error, i;
+ struct class_device_attribute **attrs = sdev->host->hostt->transport_attrs;
+
+ for (i = 0; attrs[i]; i++) {
+ error = class_device_create_file(&sdev->transport_classdev,
+ attrs[i]);
+ if (error)
+ return error;
+ }
+ return 0;
+}

Please merge this into scsi_sysfs.c, no need for another file.

+ struct fc_transport_attrs *ptr;
+
+ ptr = (struct fc_transport_attrs *)
+ kmalloc(sizeof(struct fc_transport_attrs),
+ GFP_KERNEL);

Quoted 1 line
Quoted 1 line

no need to cast here, this is not C++ (fortunately..)

+ INIT_FC_TRANSPORT(ptr);

Quoted 1 line
Quoted 1 line

this is just obsfucation, please kill the macro.

+ ptr = (struct pscsi_transport_attrs *)
+ kmalloc(sizeof(struct pscsi_transport_attrs),
+ GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ INIT_PSCSI_TRANSPORT(ptr);

Quoted 1 line
Quoted 1 line

same comments as above

+ void * transport_attr_values;

Quoted 1 line
Quoted 1 line
	void			*transport_attr_values;

+#define transport_class_to_sdev(class_dev) \
+ container_of(class_dev, struct scsi_device, transport_classdev)

Quoted 1 line
Quoted 1 line

should just go to scsi_device.h

+
+static inline void transport_class_release(struct class_device *class_dev) +{
+ struct scsi_device *sdev = transport_class_to_sdev(class_dev);
+ put_device(&sdev->sdev_gendev);
+}

Quoted 3 lines
Quoted 3 lines

this is callback, thus the inline doesn't make sense at all. just give spi and fc their own copy - that scales better for possible future additions anyway

+extern int scsi_add_transport_attributes(struct scsi_device *sdev);

Quoted 2 lines
Quoted 2 lines

this is internal to the scsi midlayer, thus should go to scsi_priv.h (or be static to scsi_sysfs.c as suggested above)

+extern int scsi_export_transport_attributes(struct scsi_device *sdev);

Quoted 1 line
Quoted 1 line

doesn't seem to exist at all..

+ host->hostt->transport_attrs = pscsi_transport_attrs;
+ host->hostt->transport_class = &pscsi_transport_class;

Quoted 2 lines
Quoted 2 lines

Please set them _directrly_ in the host template.
Currently you're writing to the host template for every found adapter..

+static int
+qla1280_slave_alloc(Scsi_Device *device)

Quoted 1 line
Quoted 1 line

should be struct scsi_device *sdev

+{
+ int error = 0;
+
+ error = pscsi_alloc_transport_attrs(device);
+ if (error)
+ return error;
+
+ return error;
+}

Quoted 5 lines
Quoted 5 lines

Okay, this is ugly as hell, as every driver needs to duplicate this verbosely. Better have a scsi_set_{spi,fc}_transport function that can be called in module_init and then does not only set the calls and attributes (so they don't need to exposed anymore but also a default constructor for the attributes.

+void qla1280_slave_destroy(Scsi_Device *device)
+{
+ pscsi_destroy_transport_attrs(device);
+}

Quoted 4 lines
Quoted 4 lines

I don't think the _destroy_transport_attrs call makes sense, just kfree the transport_attrs field in the core code uncondititionally. If you plan more complex destructors for some reason put a destructor in the host teplate, similar to the constructore mentioned above.

In fact after all the above suggestions it might be useful to have a struct scsi_transport_attribute instead of stuffing all that into the host template (sorry for guiding you into that direction). The most logical interface to set it would be to have a third argument for scsi_host_alloc, but we can't break that interface now, so we should probably add scsi_set_transport(struct Scsi_host *,
struct scsi_transport_template *), then and the driver will do in it's probe rountine, somewhere between scsi_host_alloc and scsi_add_host a scsi_set_transport(shost, &scsi_spi_template);

#2 lore raw
Quoted 9 lines · Christoph Hellwig
drivers/scsi/Kconfig +2 -0
+config SCSI_PSCSI_ATTRS
+	bool "Parallel SCSI Transport Attributes"
Quoted 5 lines
Quoted 5 lines

Scan we replacte the PSCSI/pscsi in identifiers with SPI/spi as used in the t10 standards documents please? This is a bit shorter and the correct name. In user-visible string Parallel SCSI is fine with me, but maybe it should rather be

bool "Parallel SCSI (SPI) Transport Attributes"

okay.

Quoted 10 lines
drivers/scsi/Makefile +2 -0
+obj-$(CONFIG_SCSI_PSCSI_ATTRS)	+= scsi_transport_pscsi.o
+obj-$(CONFIG_SCSI_FC_ATTRS)	+= scsi_transport_fc.o
Quoted 5 lines
Quoted 5 lines

This is wrong. Currently the option are bool and you'd build them into the kernel even if the scsi code is modular. Either use scsi_mod-* or make them their own modules using tristate (I still think that's overkill just for the attributes, but jejb seems to like it)

Agreed. I had the options as tristate inititally, then changed them to bool. I missed changing this stuff.

Quoted 11 lines
drivers/scsi/scsi_scan.c +7 -0
 		snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
+			 "%d:%d:%d:%d", sdev->host->host_no,
+			 sdev->channel, sdev->id, sdev->lun);
+
+		class_device_initialize(&sdev->transport_classdev);
+		sdev->transport_classdev.dev = &sdev->sdev_gendev;
+		sdev->transport_classdev.class = sdev->host->hostt->transport_class;
+		snprintf(sdev->transport_classdev.class_id, BUS_ID_SIZE,
Quoted 3 lines
Quoted 3 lines

Out of curiosity: Why do we need _another_ classdev. Can't you reuse the current one?

It guess we could re-use the scsi_device classdev. This would mean that all the attribute files would show up in /sys/class/scsi_device/w:x:y:z. We would have to export an attribute called "transport" to tell which transport the device is using. I'm agreeable to this solution. I don't much like having an fc_transport and pscsi_transport directory in /sys/class.

Quoted 16 lines
drivers/scsi/scsi_sysfs.c +14 -0
+	error = class_register(&sdev_class);
+	if (error)
+		goto undo_bus;
+
+#ifdef CONFIG_SCSI_PSCSI_ATTRS
+	error = scsi_pscsi_transport_init();
+	if (error)
+		goto undo_sdev;
+#endif
+#ifdef CONFIG_SCSI_FC_ATTRS
+	error = scsi_fc_transport_init();
+	if (error)
+		goto undo_all;
+#endif
Quoted 3 lines
Quoted 2 lines

Please put stubs in the header instead of ifdefs in the code. (And 1:0 for jejb, with the moular approach this would just go away :))

okay.

Quoted 9 lines

+ out:

drivers/scsi/scsi_sysfs.c +5 -0
 	return error;
+
+	/* Prevent "unused label" warnings when either of the
+	 * transport attributes config options are turned off. */
+	goto undo_all;
+	goto undo_sdev;
Quoted 2 lines
Quoted 2 lines

Yikes!

Agreed.

Quoted 5 lines

+extern int scsi_add_transport_attributes(struct scsi_device *sdev);

Quoted 2 lines
Quoted 2 lines

this is internal to the scsi midlayer, thus should go to scsi_priv.h (or be static to scsi_sysfs.c as suggested above)

Okay. I wasn't sure where to put such functions.

Quoted 4 lines

+extern int scsi_export_transport_attributes(struct scsi_device *sdev);

Quoted 1 line
Quoted 1 line

doesn't seem to exist at all..

missed that during a cleanup. Thanks.

Quoted 10 lines
drivers/scsi/qla1280.c +2 -0
+	host->hostt->transport_attrs = pscsi_transport_attrs;
+	host->hostt->transport_class = &pscsi_transport_class;
Quoted 3 lines
Quoted 3 lines

Please set them _directrly_ in the host template.
Currently you're writing to the host template for every found adapter..

drivers/scsi/qla1280.c +2 -0
+static int
+qla1280_slave_alloc(Scsi_Device *device)
Quoted 2 lines
Quoted 2 lines

should be struct scsi_device *sdev

I agree. I'm just following what the rest of the driver does.

Quoted 22 lines
drivers/scsi/qla1280.c +9 -0
+{
+	int error = 0;
+
+	error = pscsi_alloc_transport_attrs(device);
+	if (error)
+		return error;
+
+	return error;
+}
Quoted 6 lines
Quoted 6 lines

Okay, this is ugly as hell, as every driver needs to duplicate this verbosely. Better have a scsi_set_{spi,fc}_transport function that can be called in module_init and then does not only set the calls and attributes (so they don't need to exposed anymore but also a default constructor for the attributes.

drivers/scsi/qla1280.c +4 -0
+void qla1280_slave_destroy(Scsi_Device *device)
+{
+	pscsi_destroy_transport_attrs(device);
+}
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I don't think the _destroy_transport_attrs call makes sense, just kfree the transport_attrs field in the core code uncondititionally. If you plan more complex destructors for some reason put a destructor in the host teplate, similar to the constructore mentioned above.

okay. It should be done wherever the sdev is de-allocated.

Quoted 10 lines

In fact after all the above suggestions it might be useful to have a struct scsi_transport_attribute instead of stuffing all that into the host template (sorry for guiding you into that direction). The most logical interface to set it would be to have a third argument for scsi_host_alloc, but we can't break that interface now, so we should probably add scsi_set_transport(struct Scsi_host *,
struct scsi_transport_template *), then and the driver will do in it's probe rountine, somewhere between scsi_host_alloc and scsi_add_host a scsi_set_transport(shost, &scsi_spi_template);

what do others think about this? This seems nice to me. I'm going to go ahead with working on this.

More feedback is always welcome!
mh

Signature · 2 lines
Martin Hicks                Wild Open Source Inc.
[email protected]     613-266-2296
#3 lore raw
Quoted 9 lines · Martin Hicks
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Out of curiosity: Why do we need _another_ classdev. Can't you reuse the current one?

It guess we could re-use the scsi_device classdev. This would mean that all the attribute files would show up in /sys/class/scsi_device/w:x:y:z. We would have to export an attribute called "transport" to tell which transport the device is using. I'm agreeable to this solution. I don't much like having an fc_transport and pscsi_transport directory in /sys/class.

I disagree with this. We put attributes that apply to all devices in scsi_device classdev. We're implementing a separate transport interface here, so it really does need its own class_device, otherwise separating it from scsi_sysfs and allowing arbitrary transport class creation will become a real pain.

A class is supposed to represent a device interface, and the transport class does just that for transport attributes.

James

#4 lore raw

Transport Attributes -- attempt#3

In reply to Christoph Hellwig

Hi,

Here is round#3 of the patch. I think I've addressed all of the points that were brought up by Christoph last time.

Once again, three patches: core, qla1280 and qla2xxx. The core patch expects to be applied on top of the patch that I sent recently to linux-scsi:

http://marc.theaimsgroup.com/?l=linux-scsi&m=107366419027588&w=2

thanks
mh

Signature · 2 lines
Martin Hicks                Wild Open Source Inc.
[email protected]     613-266-2296

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1492 -> 1.1493
# include/scsi/scsi_device.h 1.11 -> 1.12
# include/scsi/scsi_host.h 1.13 -> 1.14
# drivers/scsi/scsi_sysfs.c 1.38 -> 1.39
# drivers/scsi/scsi_syms.c 1.46 -> 1.47
# drivers/scsi/scsi_scan.c 1.115 -> 1.116
# drivers/scsi/Makefile 1.50 -> 1.51

#	drivers/scsi/Kconfig	1.47    -> 1.48   
#	               (new)	        -> 1.1     include/scsi/scsi_transport.h
#	               (new)	        -> 1.1     drivers/scsi/scsi_transport_spi.c
#	               (new)	        -> 1.1     include/scsi/scsi_transport_spi.h
#	               (new)	        -> 1.1     include/scsi/scsi_transport_fc.h
#	               (new)	        -> 1.1     drivers/scsi/scsi_transport_fc.c

#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/01/14 [email protected] 1.1493
# The core functionality of the Transport Attributes patch. # --------------------------------------------
#

drivers/scsi/Kconfig +19 -0
diff -Nru a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
@@ -196,6 +196,25 @@
 	  there should be no noticeable performance impact as long as you have
 	  logging turned off.
 
+menu "SCSI Transport Attributes (EXPERIMENTAL)"
+	depends on EXPERIMENTAL && SCSI!=n
+
+config SCSI_SPI_ATTRS
+	bool "Parallel SCSI (SPI) Transport Attributes"
+	depends on SCSI
+	help
+	  If you wish to export transport-specific information about
+	  each attached SCSI device to sysfs, say Y.  Otherwise, say N.
+
+config SCSI_FC_ATTRS
+	bool "FiberChannel Transport Attributes"
+	depends on SCSI
+	help
+	  If you wish to export transport-specific information about
+	  each attached FiberChannel device to sysfs, say Y.
+	  Otherwise, say N.
+
+endmenu
 
 menu "SCSI low-level drivers"
 	depends on SCSI!=n
drivers/scsi/Makefile +9 -2
diff -Nru a/drivers/scsi/Makefile b/drivers/scsi/Makefile
@@ -127,14 +127,21 @@
 obj-$(CONFIG_BLK_DEV_SR)	+= sr_mod.o
 obj-$(CONFIG_CHR_DEV_SG)	+= sg.o
 
+ifdef CONFIG_SCSI_SPI_ATTRS
+transport-objs			+= scsi_transport_spi.o
+endif
+ifdef CONFIG_SCSI_FC_ATTRS
+transport-objs			+= scsi_transport_fc.o
+endif
+
 scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o constants.o \
 				   scsicam.o scsi_error.o scsi_lib.o \
 				   scsi_scan.o scsi_syms.o scsi_sysfs.o \
-				   scsi_devinfo.o
+				   scsi_devinfo.o $(transport-objs)
 scsi_mod-$(CONFIG_SYSCTL)	+= scsi_sysctl.o
 scsi_mod-$(CONFIG_SCSI_PROC_FS)	+= scsi_proc.o
 scsi_mod-$(CONFIG_X86_PC9800)	+= scsi_pc98.o
-			
+
 sd_mod-objs	:= sd.o
 sr_mod-objs	:= sr.o sr_ioctl.o sr_vendor.o
 initio-objs	:= ini9100u.o i91uscsi.o
drivers/scsi/scsi_scan.c +26 -1
diff -Nru a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
@@ -35,6 +35,7 @@
 #include <scsi/scsi_driver.h>
 #include <scsi/scsi_devinfo.h>
 #include <scsi/scsi_host.h>
+#include <scsi/scsi_transport.h>
 #include "scsi.h"
 
 #include "scsi_priv.h"
@@ -237,6 +238,16 @@
 			goto out_free_queue;
 	}
 
+	/* Give each shost a default transportt if the driver
+	 * doesn't yet support Transport Attributes */
+	if (!shost->transportt) 
+		shost->transportt = &blank_transport_template;
+
+	if (shost->transportt->setup) {
+		if (shost->transportt->setup(sdev))
+			goto out_cleanup_slave;
+	}
+
 	if (get_device(&sdev->host->shost_gendev)) {
 
 		device_initialize(&sdev->sdev_gendev);
@@ -253,8 +264,15 @@
 		snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
 			 "%d:%d:%d:%d", sdev->host->host_no,
 			 sdev->channel, sdev->id, sdev->lun);
+
+		class_device_initialize(&sdev->transport_classdev);
+		sdev->transport_classdev.dev = &sdev->sdev_gendev;
+		sdev->transport_classdev.class = sdev->host->transportt->class;
+		snprintf(sdev->transport_classdev.class_id, BUS_ID_SIZE,
+			 "%d:%d:%d:%d", sdev->host->host_no,
+			 sdev->channel, sdev->id, sdev->lun);
 	} else
-		goto out_cleanup_slave;
+		goto out_cleanup_transport;
 
 	/*
 	 * If there are any same target siblings, add this to the
@@ -283,6 +301,9 @@
 	spin_unlock_irqrestore(shost->host_lock, flags);
 	return sdev;
 
+out_cleanup_transport:
+	if (shost->transportt->cleanup)
+		shost->transportt->cleanup(sdev);
 out_cleanup_slave:
 	if (shost->hostt->slave_destroy)
 		shost->hostt->slave_destroy(sdev);
@@ -744,6 +765,8 @@
 	} else {
 		if (sdev->host->hostt->slave_destroy)
 			sdev->host->hostt->slave_destroy(sdev);
+		if (sdev->host->transportt->cleanup)
+			sdev->host->transportt->cleanup(sdev);
 		put_device(&sdev->sdev_gendev);
 	}
  out:
@@ -1300,5 +1323,7 @@
 
 	if (sdev->host->hostt->slave_destroy)
 		sdev->host->hostt->slave_destroy(sdev);
+	if (sdev->host->transportt->cleanup)
+		sdev->host->transportt->cleanup(sdev);
 	put_device(&sdev->sdev_gendev);
 }
drivers/scsi/scsi_syms.c +9 -0
diff -Nru a/drivers/scsi/scsi_syms.c b/drivers/scsi/scsi_syms.c
@@ -21,6 +21,8 @@
 #include <scsi/scsi_driver.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_ioctl.h>
+#include <scsi/scsi_transport_spi.h>
+#include <scsi/scsi_transport_fc.h>
 #include <scsi/scsicam.h>
 #include "scsi.h"
 
@@ -107,3 +109,10 @@
  */
 EXPORT_SYMBOL(scsi_add_timer);
 EXPORT_SYMBOL(scsi_delete_timer);
+
+#ifdef CONFIG_SCSI_SPI_ATTRS
+EXPORT_SYMBOL(spi_transport_template);
+#endif
+#ifdef CONFIG_SCSI_FC_ATTRS
+EXPORT_SYMBOL(fc_transport_template);
+#endif
drivers/scsi/scsi_sysfs.c +52 -7

108 lines not on this page · raw message

drivers/scsi/scsi_transport_fc.c new file +121 -0

121 lines not on this page · raw message

drivers/scsi/scsi_transport_spi.c new file +103 -0

103 lines not on this page · raw message

include/scsi/scsi_device.h +5 -0
diff -Nru a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
@@ -103,12 +103,17 @@
 	struct device		sdev_gendev;
 	struct class_device	sdev_classdev;
 
+	void			* transport_attr_values;
+	struct class_device	transport_classdev;
+
 	enum scsi_device_state sdev_state;
 };
 #define	to_scsi_device(d)	\
 	container_of(d, struct scsi_device, sdev_gendev)
 #define	class_to_sdev(d)	\
 	container_of(d, struct scsi_device, sdev_classdev)
+#define transport_class_to_sdev(class_dev) \
+	container_of(class_dev, struct scsi_device, transport_classdev)
 
 extern struct scsi_device *scsi_add_device(struct Scsi_Host *,
 		uint, uint, uint);
include/scsi/scsi_host.h +2 -0
diff -Nru a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
@@ -11,6 +11,7 @@
 struct scsi_device;
 struct Scsi_Host;
 struct scsi_host_cmd_pool;
+struct scsi_transport_template;
 
 
 /*
@@ -395,6 +396,7 @@
 	unsigned int            eh_kill:1; /* set when killing the eh thread */
 	wait_queue_head_t       host_wait;
 	struct scsi_host_template *hostt;
+	struct scsi_transport_template *transportt;
 	volatile unsigned short host_busy;   /* commands actually active on low-level */
 	volatile unsigned short host_failed; /* commands that failed. */
     
include/scsi/scsi_transport.h new file +42 -0

42 lines not on this page · raw message

include/scsi/scsi_transport_fc.h new file +41 -0

41 lines not on this page · raw message

include/scsi/scsi_transport_spi.h new file +42 -0

42 lines not on this page · raw message

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1522 -> 1.1523
# drivers/scsi/Kconfig 1.48 -> 1.49
# drivers/scsi/qla1280.c 1.51 -> 1.52
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/01/14 [email protected] 1.1523
# Transport Attributes additions for qla1280
# --------------------------------------------
#

drivers/scsi/Kconfig +1 -1
diff -Nru a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
@@ -1210,7 +1210,7 @@
 
 config SCSI_QLOGIC_1280
 	tristate "Qlogic QLA 1280 SCSI support"
-	depends on PCI && SCSI
+	depends on PCI && SCSI && SCSI_SPI_ATTRS
 	help
 	  Say Y if you have a QLogic ISP1x80/1x160 SCSI host adapter.
 
drivers/scsi/qla1280.c +23 -0
diff -Nru a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
@@ -324,6 +324,8 @@
 
 #if LINUX_VERSION_CODE >= 0x020545
 #include <scsi/scsi_host.h>
+#include <scsi/scsi_transport.h>
+#include <scsi/scsi_transport_spi.h>
 #include "scsi.h"
 #else
 #include <linux/blk.h>
@@ -949,6 +951,8 @@
 	ha->instance = num_hosts;
 	host->unique_id = ha->instance;
 
+	host->transportt = &spi_transport_template;
+
 	if (qla1280_pci_config(ha)) {
 		printk(KERN_INFO "qla1x160: Unable to configure PCI\n");
 		goto error_mem_alloced;
@@ -1686,12 +1690,14 @@
 qla1280_slave_configure(Scsi_Device *device)
 {
 	struct scsi_qla_host *ha;
+	struct spi_transport_attrs *attrs;
 	int default_depth = 3;
 	int bus = device->channel;
 	int target = device->id;
 	int status = 0;
 	struct nvram *nv;
 	unsigned long flags;
+	int is1x160;
 
 	ha = (struct scsi_qla_host *)device->host->hostdata;
 	nv = &ha->nvram;
@@ -1699,6 +1705,12 @@
 	if (qla1280_check_for_dead_scsi_bus(ha, bus))
 		return 1;
 
+	if (ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP12160 ||
+	    ha->device_id == PCI_DEVICE_ID_QLOGIC_ISP10160)
+		is1x160 = 1;
+	else
+		is1x160 = 0;
+
 	if (device->tagged_supported &&
 	    (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
 		scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
@@ -1736,6 +1748,17 @@
 
 	qla12160_get_target_parameters(ha, device);
 	spin_unlock_irqrestore(HOST_LOCK, flags);
+
+	/* Set the parallel scsi transport attributes */
+	attrs = (struct spi_transport_attrs *)device->transport_attr_values;
+	attrs->period = nv->bus[bus].target[target].sync_period;
+	if (is1x160)
+		attrs->offset = nv->bus[bus].target[target].flags.
+			flags1x160.sync_offset;
+	else
+		attrs->offset = nv->bus[bus].target[target].flags.
+			flags1x80.sync_offset;
+
 	return status;
 }
 

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1523 -> 1.1524
# drivers/scsi/qla2xxx/Kconfig 1.1 -> 1.2
# drivers/scsi/qla2xxx/qla_os.c 1.1 -> 1.2
# drivers/scsi/qla2xxx/qla_os.h 1.1 -> 1.2
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/01/14 [email protected] 1.1524
# Transport Attributes additions for qla2xxx
# --------------------------------------------
#

drivers/scsi/qla2xxx/Kconfig +1 -1
diff -Nru a/drivers/scsi/qla2xxx/Kconfig b/drivers/scsi/qla2xxx/Kconfig
@@ -1,6 +1,6 @@
 config SCSI_QLA2XXX
 	bool "QLogic ISP2xxx PCI/PCI-X Fibre Channel HBA Support"
-	depends on PCI && SCSI
+	depends on PCI && SCSI && SCSI_FC_ATTRS
 	---help---
 	These drivers support the QLogic 2xxx host adapter family of SCSI FCP
 	HBAs.
drivers/scsi/qla2xxx/qla_os.c +19 -5
diff -Nru a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
@@ -1849,7 +1849,7 @@
 }
 
 /**************************************************************************
-* qla2x00_slave_configure
+* qla2xxx_slave_configure
 *
 * Description:
 **************************************************************************/
@@ -1857,6 +1857,8 @@
 qla2xxx_slave_configure(struct scsi_device *sdev)
 {
 	scsi_qla_host_t *ha = to_qla_host(sdev->host);
+	struct fc_transport_attrs *attrs;
+	struct fc_port *fc;
 	int queue_depth;
 
 	if (IS_QLA2100(ha) || IS_QLA2200(ha))
@@ -1883,9 +1885,19 @@
 		     sdev->host->hostt->cmd_per_lun /* 3 */);
 	}
 
-	return (0);
-}
+	attrs = (struct fc_transport_attrs *)sdev->transport_attr_values;
+	list_for_each_entry(fc, &ha->fcports, list) {
+		if (fc->os_target_id == sdev->id) {
+			attrs->port_name = __be64_to_cpu(*(uint64_t *)fc->port_name);
+			attrs->node_name = __be64_to_cpu(*(uint64_t *)fc->node_name);
+			attrs->port_id = fc->d_id.b24;
+			break;
+		}
+	}
 
+	return 0;
+}
+ 
 /**
  * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  * @ha: HA context
@@ -1998,10 +2010,10 @@
 	ha->mmio_length = mmio_len;
 #endif
 
-	return (0);
+	return 0;
 
 iospace_error_exit:
-	return (-ENOMEM);
+	return -ENOMEM;
 }
 
 /*
@@ -2238,6 +2250,8 @@
 
 	sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
 	sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
+
+	host->transportt = &fc_transport_template;
 
 	qla_printk(KERN_INFO, ha, "\n"
 	    " QLogic ISP2xxx PCI/PCI-X Fibre Channel HBA Driver: %s\n"
drivers/scsi/qla2xxx/qla_os.h +3 -1
diff -Nru a/drivers/scsi/qla2xxx/qla_os.h b/drivers/scsi/qla2xxx/qla_os.h
@@ -56,6 +56,7 @@
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/init.h>
+#include <linux/list.h>
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -91,7 +92,8 @@
 
 #include "scsi.h"
 #include "hosts.h"
-
+#include <scsi/scsi_transport.h>
+#include <scsi/scsi_transport_fc.h>
 #include <scsi/scsicam.h>
 #include <scsi/scsi_ioctl.h>
 
#5 lore raw

Re: Transport Attributes -- attempt#3

Quoted 7 lines · Martin Hicks

Here is round#3 of the patch. I think I've addressed all of the points that were brought up by Christoph last time.

Once again, three patches: core, qla1280 and qla2xxx. The core patch expects to be applied on top of the patch that I sent recently to linux-scsi:

Just a few comments below:

[snip]

drivers/scsi/scsi_transport_fc.c line 101

Quoted 6 lines
drivers/scsi/scsi_transport_fc.c new file +6 -0
+
+/* the FiberChannel Tranport Attributes: */
+fc_transport_rd_attr_cast(node_name, "0x%llx\n", unsigned long long);
+fc_transport_rd_attr_cast(port_name, "0x%llx\n", unsigned long long);
+fc_transport_rd_attr(port_id, "0x%x\n");
+

Purely aesthetics : PortIDs are typically viewed as three hex bytes padded with zeros, i.e. 010203. Perhaps this may be more appropriate:

	fc_transport_rd_attr(port_id, "0x%06x\n");

[snip]

drivers/scsi/qla2xxx/qla_os.c line 1893

Quoted 6 lines
drivers/scsi/qla2xxx/qla_os.c +6 -0
+	attrs = (struct fc_transport_attrs *)sdev->transport_attr_values;
+	list_for_each_entry(fc, &ha->fcports, list) {
+		if (fc->os_target_id == sdev->id) {
+			attrs->port_name = __be64_to_cpu(*(uint64_t *)fc->port_name);
+			attrs->node_name = __be64_to_cpu(*(uint64_t *)fc->node_name);
+			attrs->port_id = fc->d_id.b24;

This port_id assignment will not give you what you expect on big-endian machines. Given the previous port_id example value (010203), on BE machines, the attribute will read as 030201 when displayed. A more endian safe way if you want to continue with the pure-type usages (uint64_t/int) rather than byte arrays would be:

	attrs->port_id = fc->d_id.b.domain << 16 |
		fc->d_id.b.area << 8 |
		fc->d_id.b.al_pa;

Regards,
Andrew Vasquez

#6 lore raw

Re: Transport Attributes -- attempt#3

Quoted 12 lines · Andrew Vasquez

drivers/scsi/scsi_transport_fc.c line 101

Quoted 6 lines · Martin Hicks
drivers/scsi/scsi_transport_fc.c new file +6 -0
+
+/* the FiberChannel Tranport Attributes: */
+fc_transport_rd_attr_cast(node_name, "0x%llx\n", unsigned long long);
+fc_transport_rd_attr_cast(port_name, "0x%llx\n", unsigned long long);
+fc_transport_rd_attr(port_id, "0x%x\n");
+

Purely aesthetics : PortIDs are typically viewed as three hex bytes padded with zeros, i.e. 010203. Perhaps this may be more appropriate:

Quoted 1 line
	fc_transport_rd_attr(port_id, "0x%06x\n");

Okay. Will do.

Quoted 15 lines

[snip]

drivers/scsi/qla2xxx/qla_os.c line 1893

Quoted 6 lines
drivers/scsi/qla2xxx/qla_os.c +6 -0
+	attrs = (struct fc_transport_attrs *)sdev->transport_attr_values;
+	list_for_each_entry(fc, &ha->fcports, list) {
+		if (fc->os_target_id == sdev->id) {
+			attrs->port_name = __be64_to_cpu(*(uint64_t *)fc->port_name);
+			attrs->node_name = __be64_to_cpu(*(uint64_t *)fc->node_name);
+			attrs->port_id = fc->d_id.b24;

This port_id assignment will not give you what you expect on big-endian machines. Given the previous port_id example value (010203), on BE machines, the attribute will read as 030201 when displayed. A more endian safe way if you want to continue with the pure-type usages (uint64_t/int) rather than byte arrays would be:

Quoted 3 lines
	attrs->port_id = fc->d_id.b.domain << 16 |
		fc->d_id.b.area << 8 |
		fc->d_id.b.al_pa;

I'll fix that up.

Thanks,
mh

Signature · 1 line
Martin Hicks || [email protected] || PGP/GnuPG: 0x4C7F2BEE
#7 lore raw

Re: Transport Attributes -- attempt#3

In reply to Andrew Vasquez

Hi Andrew,

Quoted 9 lines · Andrew Vasquez

drivers/scsi/scsi_transport_fc.c line 100

Quoted 4 lines
drivers/scsi/scsi_transport_fc.c new file +4 -0
+/* the FiberChannel Tranport Attributes: */
+fc_transport_rd_attr_cast(node_name, "0x%llx\n", unsigned long long);
+fc_transport_rd_attr_cast(port_name, "0x%llx\n", unsigned long long);
+fc_transport_rd_attr(port_id, "0x%x\n");

Purely aesthetics : PortIDs are typically viewed as three hex bytes padded with zeros, i.e. 010203. Perhaps this may be more appropriate:

        fc_transport_rd_attr(port_id, "0x%06x\n");

yes, i'd like to see that too.

but note that most FC switches out there don't support the full range of 239 Domain_IDs (first octet of FC_ID), so for 'most' people, it'd work out correctly anyway (domain_id between 97 and 127).

cheers,

lincoln.

#8 lore raw

Re: Transport Attributes -- attempt#3

In reply to Martin Hicks
Quoted 5 lines · Martin Hicks

Hi,

Here is round#3 of the patch. I think I've addressed all of the points that were brought up by Christoph last time.

Nice, I can now easily see LUN to port mappings, though I don't easily get port to LUN mapping.

Quoted 13 lines

diff -Nru a/drivers/scsi/scsi_syms.c b/drivers/scsi/scsi_syms.c

drivers/scsi/scsi_syms.c +2 -0
@@ -21,6 +21,8 @@
 #include <scsi/scsi_driver.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_ioctl.h>
+#include <scsi/scsi_transport_spi.h>
+#include <scsi/scsi_transport_fc.h>
 #include <scsi/scsicam.h>
 #include "scsi.h"
 

drivers/scsi/scsi_syms.c line 118

Quoted 10 lines
drivers/scsi/scsi_syms.c +7 -0
@@ -107,3 +109,10 @@
  */
 EXPORT_SYMBOL(scsi_add_timer);
 EXPORT_SYMBOL(scsi_delete_timer);
+
+#ifdef CONFIG_SCSI_SPI_ATTRS
+EXPORT_SYMBOL(spi_transport_template);
+#endif
+#ifdef CONFIG_SCSI_FC_ATTRS
+EXPORT_SYMBOL(fc_transport_template);
+#endif

Can you move these exports to their respective source files? scsi_syms.c should go away someday. And then we touch one less scsi core file.

Quoted 37 lines

diff -Nru a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c

drivers/scsi/scsi_sysfs.c +17 -5
@@ -13,6 +13,9 @@
 #include <linux/device.h>
 
 #include <scsi/scsi_host.h>
+#include <scsi/scsi_transport.h>
+#include <scsi/scsi_transport_spi.h>
+#include <scsi/scsi_transport_fc.h>
 #include "scsi.h"
 
 #include "scsi_priv.h"
@@ -162,13 +165,31 @@
 	int error;
 
 	error = bus_register(&scsi_bus_type);
-	if (!error) {
-		error = class_register(&sdev_class);
-		if (error)
-			bus_unregister(&scsi_bus_type);
-	}
+	if (error)
+		return error;
 
+	error = class_register(&sdev_class);
+	if (error)
+		goto undo_bus;
+
+	error = scsi_spi_transport_init();
+	if (error)
+		goto undo_sdev;
+
+	error = scsi_fc_transport_init();
+	if (error)
+		goto undo_all;
+

drivers/scsi/scsi_sysfs.c line 192

Quoted 10 lines
drivers/scsi/scsi_sysfs.c +9 -0
+ out:
 	return error;
+
+ undo_all:
+	scsi_spi_transport_exit();
+ undo_sdev:
+	class_unregister(&sdev_class);
+ undo_bus:
+	bus_unregister(&scsi_bus_type);
+	goto out;

What happened to making the transports their own module? Then their init code can register their class, and we don't need to modify any scsi core files if a new transport file is added.

Or, do a lazy init in the setup functions based on a static (and use a semaphore to prevent races). That would also keep empty class fc_transport and spi_transport directories from showing up for the most scsi users (those with only usb mass storage devices).

drivers/scsi/scsi_sysfs.c

Quoted 4 lines
drivers/scsi/scsi_sysfs.c +4 -0
+/* the FiberChannel Tranport Attributes: */
+fc_transport_rd_attr_cast(node_name, "0x%llx\n", unsigned long long);
+fc_transport_rd_attr_cast(port_name, "0x%llx\n", unsigned long long);
+fc_transport_rd_attr(port_id, "0x%x\n");

These are all per target attributes (are all fc level attributes?).

Does that matter? I think it's ok , though someday we should have a target representation.

Example:

[elm3b79 scsi]$ cat /sys/class/fc_transport/11\:0\:0\:*/port_name | head -4 0x200400a0b80b17a4
0x200400a0b80b17a4
0x200400a0b80b17a4
0x200400a0b80b17a4
[elm3b79 scsi]$ cat /sys/class/fc_transport/11\:0\:0\:*/port_id | head -4 0x210a13
0x210a13
0x210a13
0x210a13
[elm3b79 scsi]$ cat /sys/class/fc_transport/11\:0\:0\:*/node_name | head -4 0x200400a0b80b17a3
0x200400a0b80b17a3
0x200400a0b80b17a3
0x200400a0b80b17a3

-- Patrick Mansfield

#9 lore raw

Re: Transport Attributes -- attempt#3

In reply to Martin Hicks

drivers/scsi/Kconfig line 200

Quoted 2 lines
drivers/scsi/Kconfig +2 -0
+menu "SCSI Transport Attributes (EXPERIMENTAL)"
+	depends on EXPERIMENTAL && SCSI!=n

Do you really need the experimental flags? Actually this option is rather bogus anyway - with your patches posted the qlogic drivers won't compile anymore without those set. So either make it unconditional or let the drives select it.

drivers/scsi/Makefile line 140

Quoted 12 lines
drivers/scsi/Makefile +8 -1
+ifdef CONFIG_SCSI_SPI_ATTRS
+transport-objs			+= scsi_transport_spi.o
+endif
+ifdef CONFIG_SCSI_FC_ATTRS
+transport-objs			+= scsi_transport_fc.o
+endif
+
 scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o constants.o \
 				   scsicam.o scsi_error.o scsi_lib.o \
 				   scsi_scan.o scsi_syms.o scsi_sysfs.o \
-				   scsi_devinfo.o
+				   scsi_devinfo.o $(transport-objs)

This still looks quite overcomplicated, what about a simple:

scsi_mod-$(CONFIG_SCSI_SPI_ATTRS) += scsi_transport_spi.o scsi_mod-$(CONFIG_SCSI_FC_ATTRS) += scsi_transport_fc.o

drivers/scsi/scsi_syms.c line 118

Quoted 6 lines
drivers/scsi/scsi_syms.c +6 -0
+#ifdef CONFIG_SCSI_SPI_ATTRS
+EXPORT_SYMBOL(spi_transport_template);
+#endif
+#ifdef CONFIG_SCSI_FC_ATTRS
+EXPORT_SYMBOL(fc_transport_template);
+#endif

Should just move to the files declaring it.

drivers/scsi/scsi_sysfs.c line 422

Quoted 7 lines
drivers/scsi/scsi_sysfs.c +7 -0
+	if (sdev->transport_classdev.class) {
+		attrs = sdev->host->transportt->attrs;
+		for (i = 0; attrs[i]; i++) {
+			error = class_device_create_file(&sdev->transport_classdev,
+							 attrs[i]);
+			if (error)
+				scsi_remove_device(sdev);

Missing break here, in fact the cleanup mioght better be after a lable you goto to.

drivers/scsi/scsi_sysfs.c line 542

Quoted 3 lines
drivers/scsi/scsi_sysfs.c +3 -0
+/* A blank transport template that is used in drivers that don't
+ * yet implement Transport Attributes */
+struct scsi_transport_template blank_transport_template = { NULL };

The zero-initialization is not needed.

drivers/scsi/scsi_transport_fc.c line 46

Quoted 3 lines
drivers/scsi/scsi_transport_fc.c new file +3 -0
+void scsi_sysfs_cleanup_fc_transport(struct scsi_device *sdev)
+{
+	kfree(sdev->transport_attr_values);

I think you'll have to do the kfree in the device's ->release, but maybe I got all that sysfs-foo wrong :)

include/scsi/scsi_device.h line 106

Quoted 1 line
include/scsi/scsi_device.h +1 -0
+	void			* transport_attr_values;
	void			*transport_attr_values;

include/scsi/scsi_transport.h line 37

Quoted 2 lines
include/scsi/scsi_transport.h new file +2 -0
+	/* Default values for the transport attributes */
+	void *default_attr_values;

Should this really be a void *?

Quoted 1 line

+extern struct scsi_transport_template blank_transport_template;

Should be in scsi_priv.h as it's not exported, no?

#10 lore raw

Re: Transport Attributes -- attempt#3

Quoted 7 lines · Christoph Hellwig

drivers/scsi/Kconfig line 200

Quoted 2 lines
drivers/scsi/Kconfig +2 -0
+menu "SCSI Transport Attributes (EXPERIMENTAL)"
+	depends on EXPERIMENTAL && SCSI!=n

Do you really need the experimental flags? Actually this option is rather bogus anyway - with your patches posted the qlogic drivers won't compile anymore without those set. So either make it unconditional or let the drives select it.

Nope. I just turned it on while I was testing stuff. I will remove it for the next patch, since a few people have tried it out now :-)

Quoted 16 lines

drivers/scsi/Makefile line 140

Quoted 13 lines
drivers/scsi/Makefile +8 -1
+ifdef CONFIG_SCSI_SPI_ATTRS
+transport-objs			+= scsi_transport_spi.o
+endif
+ifdef CONFIG_SCSI_FC_ATTRS
+transport-objs			+= scsi_transport_fc.o
+endif
+
 scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o constants.o \
 				   scsicam.o scsi_error.o scsi_lib.o \
 				   scsi_scan.o scsi_syms.o scsi_sysfs.o \
-				   scsi_devinfo.o
+				   scsi_devinfo.o $(transport-objs)

This still looks quite overcomplicated, what about a simple:

Quoted 2 lines

scsi_mod-$(CONFIG_SCSI_SPI_ATTRS) += scsi_transport_spi.o scsi_mod-$(CONFIG_SCSI_FC_ATTRS) += scsi_transport_fc.o

Okay. I wasn't sure how to do that. My Makefile foo is lacking.

Thanks.

Quoted 5 lines

drivers/scsi/scsi_sysfs.c line 542

Quoted 3 lines
drivers/scsi/scsi_sysfs.c +3 -0
+/* A blank transport template that is used in drivers that don't
+ * yet implement Transport Attributes */
+struct scsi_transport_template blank_transport_template = { NULL };

The zero-initialization is not needed.

right.

Quoted 7 lines

drivers/scsi/scsi_transport_fc.c line 46

Quoted 4 lines
drivers/scsi/scsi_transport_fc.c new file +3 -0
+void scsi_sysfs_cleanup_fc_transport(struct scsi_device *sdev)
+{
+	kfree(sdev->transport_attr_values);

I think you'll have to do the kfree in the device's ->release, but maybe I got all that sysfs-foo wrong :)

I'll take a closer look.

Quoted 4 lines

include/scsi/scsi_transport.h line 37

Quoted 2 lines
include/scsi/scsi_transport.h new file +2 -0
+	/* Default values for the transport attributes */
+	void *default_attr_values;

Should this really be a void *?

I think so. It has to be a struct spi_transport_attrs or a fc_transport_attrs, depending on which transport template we're talking about.

Quoted 4 lines
Quoted 2 lines

+extern struct scsi_transport_template blank_transport_template;

Should be in scsi_priv.h as it's not exported, no?

Yup.

Thanks again,
mh

Signature · 1 line
Martin Hicks || [email protected] || PGP/GnuPG: 0x4C7F2BEE
#11 lore raw

Re: Transport Attributes -- attempt#3

In reply to Martin Hicks

I just submitted a new LLD to linux-scsi and Christoph suggested I use this patch for setting SCSI bus attributes. I looked through the patches and noticed that these are per device attributes. I need to be able to set per SCSI bus attributes. The attributes I would like to be able to set include: initiator ID, maximum bus speed, wide enabled/disabled, and device spinup delay. Would it make sense to create a scsi_bus class or something similar for these types of attributes?

Signature · 3 lines
Brian King
eServer Storage I/O
IBM Linux Technology Center
#12 lore raw

Re: Transport Attributes -- attempt#3

Quoted 7 lines · Brian King

I just submitted a new LLD to linux-scsi and Christoph suggested I use this patch for setting SCSI bus attributes. I looked through the patches and noticed that these are per device attributes. I need to be able to set per SCSI bus attributes. The attributes I would like to be able to set include: initiator ID, maximum bus speed, wide enabled/disabled, and device spinup delay. Would it make sense to create a scsi_bus class or something similar for these types of attributes?

For the IPR driver -

Is the spinup delay for the entire card, not per bus? If so it should be a scsi_host attribute set via shost_attrs. (No one uses shost_attrs, but its use is the same as sdev_attrs usage in 53c700.c)

And are the other values for the actual physical disks? If they are not visible to the host, then there is no bus visible to the host (i.e. scsi core can't see them).

Having the physical disk show up in scsi core as drives is nice for managing them, but if they are ready for writing it could be confusing, and potentially disasterous. We could do hacks to get different behaviour for the disks (so only sg shows up, or so sd shows up read only), like: add a flag in scsi_host; modify the INQUIRY type in the ipr driver; or modify the MODE SENSE page 0x3f (and/or page 0) result in the ipr driver so they show up read only (though on failure of a MODE SENSE they would become writable).

If they were visible to scsi core, the intiator ID (this_id) would be found in the scsi_host, but would need to be added as a sysfs attribute.

We could add a scsi_bus class, but we first need a bus/fabric struct that can include the class, and that in turn requires quite a bit more work to get it in the right place in the driver model tree (we would want a bus/fabric per host:channel pair).

As noted before, we also don't have a target, and the transport attributes (per the patch) show up as per LUN, even though they might be per target, or even per bus/fabric. IMO that is fine for now.

i.e. we have a sysfs tree like this:

`-- pcifoo

    `-- host14
        |-- host_attrs
        |-- 14:0:0:0
        |   `-- sdev_attrs
        `-- 14:0:0:1
            `-- sdev_attrs

But we need something like this:

`-- pcifoo

    `-- host14
        |-- host_attrs
        `-- 14:0
            |-- bus_fabric_attrs
            `-- 14:0:0
                |-- target_attrs
                |-- 14:0:0:0
                |   `-- sdev_attrs
                `-- 14:0:0:1
                    `-- sdev_attrs

And then driver model class or bus code can be used with the above as needed.

-- Patrick Mansfield

#13 lore raw

Re: Transport Attributes -- attempt#3

Quoted 5 lines · Patrick Mansfield

For the IPR driver -

Is the spinup delay for the entire card, not per bus? If so it should be a scsi_host attribute set via shost_attrs. (No one uses shost_attrs, but its use is the same as sdev_attrs usage in 53c700.c)

No, the spinup delay is per bus.

Quoted 3 lines

And are the other values for the actual physical disks? If they are not visible to the host, then there is no bus visible to the host (i.e. scsi core can't see them).

The other values are also for the entire scsi bus, not for individual targets.

Quoted 8 lines

Having the physical disk show up in scsi core as drives is nice for managing them, but if they are ready for writing it could be confusing, and potentially disasterous. We could do hacks to get different behaviour for the disks (so only sg shows up, or so sd shows up read only), like: add a flag in scsi_host; modify the INQUIRY type in the ipr driver; or modify the MODE SENSE page 0x3f (and/or page 0) result in the ipr driver so they show up read only (though on failure of a MODE SENSE they would become writable).

Christoph has suggested I create psuedo devices for them, but not report them to the upper layer drivers, similar to how scsi_get_host_dev works.
This means they won't show up in sysfs, AFAIK. Which would then pose
the problem you mention above of the midlayer not seeing the bus if there are only RAID disks on the bus. For this reason, it might be nice if the devices did get reported in, maybe as sg devices only? There should really be no reason to create an sd device, as it would only cause problems.

Quoted 2 lines

If they were visible to scsi core, the intiator ID (this_id) would be found in the scsi_host, but would need to be added as a sysfs attribute.

Once again, for the adapter, the initiator ID is per bus, rather than per adapter. I could force them to be the same for all busses, however.

Quoted 33 lines

We could add a scsi_bus class, but we first need a bus/fabric struct that can include the class, and that in turn requires quite a bit more work to get it in the right place in the driver model tree (we would want a bus/fabric per host:channel pair).

As noted before, we also don't have a target, and the transport attributes (per the patch) show up as per LUN, even though they might be per target, or even per bus/fabric. IMO that is fine for now.

i.e. we have a sysfs tree like this:

`-- pcifoo

    `-- host14
        |-- host_attrs
        |-- 14:0:0:0
        |   `-- sdev_attrs
        `-- 14:0:0:1
            `-- sdev_attrs

But we need something like this:

`-- pcifoo

    `-- host14
        |-- host_attrs
        `-- 14:0
            |-- bus_fabric_attrs
            `-- 14:0:0
                |-- target_attrs
                |-- 14:0:0:0
                |   `-- sdev_attrs
                `-- 14:0:0:1
                    `-- sdev_attrs
Quoted 2 lines

And then driver model class or bus code can be used with the above as needed.

That seems reasonable to me.

Signature · 3 lines
Brian King
eServer Storage I/O
IBM Linux Technology Center