Skip to contentSkip to conversation

minimal SAS transport class

PATCH In review Christoph Hellwig 4 participants 7 messages Aug 15, 2005 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 minimal SAS transport class

This is a minmal, bottom-up SAS transport class. So far it only exposed information about the SAS port/phy and SAS device (scsi target). I hope this will integrate nicely with the top-down work Luben has done once he finally releases it publically, but for now I think we should have something so SAS drivers can go in the tree.

In detail this transport class does:

- introduces a SAS port object between the Scsi_Host and scsi_target, this is used to hold all information specific to the SAS port and PHY - right now they're used interchangable as I haven't found the right abstraction for wide ports yet - if there is a proper solution at all as the SAS spec leaves binding PHYs together to wide ports up to the implementation.
- adds some attributes to the scsi_target, and an API call to preinitialize them.

It does not:

- handle any managment interfaces or chaning of attributes
- any SAS devices that are not scsi targets, most importantly there's no support for SMP and extenders yet
- wide ports (as mentioned above)
- software device discovery (although I know Luben has some nice code for that)
- everythig not mentioned here

A bit of warning: I've only tested this with an SATA disk attached to a SAS HBA so far because I don't have any real SAS storage yet.

To use the transport class you need a patched fusion driver for now, use the LSI tarball at:

ftp://ftp.lsil.com/HostAdapterDrivers/linux/Fusion-MPT/mptlinux-3.02.55-src.tar.gz

plus my patch at:

http://verein.lst.de/~hch/fusion-sas-transport-class.diff

I'll try to port my changes plus basic SAS support over to the mainline driver, but the driver is currently not endian clean which makes it hard for me to actually test it.

drivers/scsi/Kconfig +7 -0
Index: scsi-misc-2.6/drivers/scsi/Kconfig
===================================================================
@@ -229,6 +229,13 @@
 	  each attached iSCSI device to sysfs, say Y.
 	  Otherwise, say N.
 
+config SCSI_SAS_ATTRS
+	tristate "SAS Transport Attributes"
+	depends on SCSI
+	help
+	  If you wish to export transport-specific information about
+	  each attached SAS device to sysfs, say Y.
+
 endmenu
 
 menu "SCSI low-level drivers"
drivers/scsi/Makefile +1 -0
Index: scsi-misc-2.6/drivers/scsi/Makefile
===================================================================
@@ -29,6 +29,7 @@
 obj-$(CONFIG_SCSI_SPI_ATTRS)	+= scsi_transport_spi.o
 obj-$(CONFIG_SCSI_FC_ATTRS) 	+= scsi_transport_fc.o
 obj-$(CONFIG_SCSI_ISCSI_ATTRS)	+= scsi_transport_iscsi.o
+obj-$(CONFIG_SCSI_SAS_ATTRS)	+= scsi_transport_sas.o
 
 obj-$(CONFIG_SCSI_AMIGA7XX)	+= amiga7xx.o	53c7xx.o
 obj-$(CONFIG_A3000_SCSI)	+= a3000.o	wd33c93.o
drivers/scsi/scsi_transport_sas.c new file +491 -0

491 lines not on this page · raw message

include/scsi/scsi_transport_sas.h new file +88 -0

88 lines not on this page · raw message

#1 lore raw

Good stuff, Christoph!

Luben

Quoted 27 lines · --- Christoph Hellwig

This is a minmal, bottom-up SAS transport class. So far it only exposed information about the SAS port/phy and SAS device (scsi target). I hope this will integrate nicely with the top-down work Luben has done once he finally releases it publically, but for now I think we should have something so SAS drivers can go in the tree.

In detail this transport class does:

- introduces a SAS port object between the Scsi_Host and scsi_target, this is used to hold all information specific to the SAS port and PHY - right now they're used interchangable as I haven't found the right abstraction for wide ports yet - if there is a proper solution at all as the SAS spec leaves binding PHYs together to wide ports up to the implementation.
- adds some attributes to the scsi_target, and an API call to preinitialize them.

It does not:

- handle any managment interfaces or chaning of attributes
- any SAS devices that are not scsi targets, most importantly there's no support for SMP and extenders yet
- wide ports (as mentioned above)
- software device discovery (although I know Luben has some nice code for that)
- everythig not mentioned here

Quoted 8 lines

A bit of warning: I've only tested this with an SATA disk attached to a SAS HBA so far because I don't have any real SAS storage yet.

To use the transport class you need a patched fusion driver for now, use the LSI tarball at:

ftp://ftp.lsil.com/HostAdapterDrivers/linux/Fusion-MPT/mptlinux-3.02.55-src.tar.gz

Quoted 157 lines

plus my patch at:

http://verein.lst.de/~hch/fusion-sas-transport-class.diff

I'll try to port my changes plus basic SAS support over to the mainline driver, but the driver is currently not endian clean which makes it hard for me to actually test it.

Index: scsi-misc-2.6/drivers/scsi/Kconfig
===================================================================
--- scsi-misc-2.6.orig/drivers/scsi/Kconfig 2005-08-13 13:53:51.000000000
+0200
+++ scsi-misc-2.6/drivers/scsi/Kconfig 2005-08-15 15:34:56.000000000 +0200

drivers/scsi/Kconfig +7 -0
@@ -229,6 +229,13 @@
 	  each attached iSCSI device to sysfs, say Y.
 	  Otherwise, say N.
 
+config SCSI_SAS_ATTRS
+	tristate "SAS Transport Attributes"
+	depends on SCSI
+	help
+	  If you wish to export transport-specific information about
+	  each attached SAS device to sysfs, say Y.
+
 endmenu
 
 menu "SCSI low-level drivers"

Index: scsi-misc-2.6/drivers/scsi/Makefile
===================================================================
--- scsi-misc-2.6.orig/drivers/scsi/Makefile 2005-08-13 13:53:51.000000000
+0200
+++ scsi-misc-2.6/drivers/scsi/Makefile 2005-08-15 15:35:12.000000000 +0200

drivers/scsi/Makefile +1 -0
@@ -29,6 +29,7 @@
 obj-$(CONFIG_SCSI_SPI_ATTRS)	+= scsi_transport_spi.o
 obj-$(CONFIG_SCSI_FC_ATTRS) 	+= scsi_transport_fc.o
 obj-$(CONFIG_SCSI_ISCSI_ATTRS)	+= scsi_transport_iscsi.o
+obj-$(CONFIG_SCSI_SAS_ATTRS)	+= scsi_transport_sas.o
 
 obj-$(CONFIG_SCSI_AMIGA7XX)	+= amiga7xx.o	53c7xx.o
 obj-$(CONFIG_A3000_SCSI)	+= a3000.o	wd33c93.o

Index: scsi-misc-2.6/drivers/scsi/scsi_transport_sas.c
===================================================================

drivers/scsi/scsi_transport_sas.c new file +0 -0

15:40:00.000000000 +0200

drivers/scsi/scsi_transport_sas.c new file +107 -0
@@ -0,0 +1,491 @@
+/*
+ * Copyright (C) 2005 Dell Inc.
+ *	Released under GPL v2.
+ *
+ * Based on the FC transport class work by James Smart, Emulex Corporation.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/err.h>
+
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_transport.h>
+#include <scsi/scsi_transport_sas.h>
+
+
+#define SAS_TARGET_ATTRS	25
+#define SAS_PORT_ATTRS		25
+
+struct sas_internal {
+	struct scsi_transport_template t;
+	struct sas_function_template *f;
+
+	struct class_device_attribute private_target_attrs[SAS_TARGET_ATTRS];
+	struct class_device_attribute private_port_attrs[SAS_TARGET_ATTRS];
+
+	struct transport_container port_attr_cont;
+
+	/*
+	 * The array of null terminated pointers to attributes
+	 * needed by scsi_sysfs.c
+	 */
+	struct class_device_attribute *target_attrs[SAS_TARGET_ATTRS];
+	struct class_device_attribute *port_attrs[SAS_PORT_ATTRS + 1];
+};
+#define to_sas_internal(tmpl)	container_of(tmpl, struct sas_internal, t)
+
+/*
+ * Hack to allow attributes of the same name in different objects.
+ */
+#define SAS_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
+	struct class_device_attribute class_device_attr_##_prefix##_##_name = \
+	__ATTR(_name,_mode,_show,_store)
+
+
+/*
+ * Pretty printing helpers
+ */
+
+#define sas_bitfield_name_match(title, table)			\
+static ssize_t							\
+get_sas_##title##_names(u32 table_key, char *buf)		\
+{								\
+	char *prefix = "";					\
+	ssize_t len = 0;					\
+	int i;							\
+								\
+	for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) {	\
+		if (table[i].value & table_key) {		\
+			len += sprintf(buf + len, "%s%s",	\
+				prefix, table[i].name);		\
+			prefix = ", ";				\
+		}						\
+	}							\
+	len += sprintf(buf + len, "\n");			\
+	return len;						\
+}
+
+#define sas_bitfield_name_search(title, table)			\
+static ssize_t							\
+get_sas_##title##_names(u32 table_key, char *buf)		\
+{								\
+	ssize_t len = 0;					\
+	int i;							\
+								\
+	for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) {	\
+		if (table[i].value == table_key) {		\
+			len += sprintf(buf + len, "%s",		\
+				table[i].name);			\
+			break;					\
+		}						\
+	}							\
+	len += sprintf(buf + len, "\n");			\
+	return len;						\
+}
+
+static struct {
+	u32		value;
+	char		*name;
+} sas_device_type_names[] = {
+	{ SAS_PHY_UNUSED,		"unused" },
+	{ SAS_END_DEVICE,		"end device" },
+	{ SAS_EDGE_EXPANDER_DEVICE,	"edge expander" },
+	{ SAS_FANOUT_EXPANDER_DEVICE,	"fanout expander" },
+};
+sas_bitfield_name_search(device_type, sas_device_type_names)
+
+
+static struct {
+	u32		value;
+	char		*name;
+} sas_protocol_names[] = {
+	{ SAS_PROTOCOL_SATA,		"sata" },
+	{ SAS_PROTOCOL_SMP,		"smp" },
+	{ SAS_PROTOCOL_STP,		"stp" },
+	{ SAS_PROTOCOL_SSP,		"ssp" },

drivers/scsi/scsi_transport_sas.c line 117

Quoted 10 lines
drivers/scsi/scsi_transport_sas.c new file +10 -0
+};
+sas_bitfield_name_match(protocol, sas_protocol_names)
+
+static struct {
+	u32		value;
+	char		*name;
+} sas_linkspeed_names[] = {
+	{ SAS_LINK_RATE_UNKNOWN,	"Unknown" },
+	{ SAS_PHY_DISABLED,		"Phy disabled" },
+	{ SAS_LINK_RATE_FAILED,		"Link Rate failed" },

=== message truncated ===

#3 lore raw
Quoted 7 lines · Arjan van de Ven
Quoted 1 line · Christoph Hellwig

+EXPORT_SYMBOL(sas_add_target);

should these exports be _GPL? After all they're very much linux specific functionality...

Someone needs this for a binary only driver? ;-)

Luben

#4 lore raw
In reply to Christoph Hellwig

drivers/scsi/scsi_transport_sas.c line 216

Quoted 7 lines
drivers/scsi/scsi_transport_sas.c new file +7 -0
+void sas_add_target(struct sas_port *port, struct sas_identify *attached,
+		uint channel, uint target)
+{
+	if (attached->target_port_protocols &
+	    (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA))
+		scsi_scan_target(&port->dev, channel, target, ~0, 0, attached);
+}

I've a few questions:

1. What kind of device does the Fusion driver export?
Is this a true end device, or is this the LU in the SSP end device?

I.e. since the Fusion card firmware does everything about SAS there is, is also LU discovery done in the firmware, or does the firmware export only the SSP end devices and leave LU discovery to SCSI Core (as the code suggests)?

2. Since I saw that (end) devices bind to ports, what is the maximum number of ports that the Fusion firmware export?

3. Will control of SATA and STP devices be given to libata or will the Fision firmware make those look like SCSI devices?

Thanks,
Luben

#5 lore raw
Quoted 10 lines · Luben Tuikov

drivers/scsi/scsi_transport_sas.c line 216

Quoted 7 lines
drivers/scsi/scsi_transport_sas.c new file +7 -0
+void sas_add_target(struct sas_port *port, struct sas_identify *attached,
+		uint channel, uint target)
+{
+	if (attached->target_port_protocols &
+	    (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA))
+		scsi_scan_target(&port->dev, channel, target, ~0, 0, attached);
+}

I've a few questions:

Quoted 6 lines

1. What kind of device does the Fusion driver export?
Is this a true end device, or is this the LU in the SSP end device? I.e. since the Fusion card firmware does everything about SAS there is, is also LU discovery done in the firmware, or does the firmware export only the SSP end devices and leave LU discovery to SCSI Core (as the code suggests)?

It seems to give notification for the actual LU, but doing an LU scan works if you use the target ID from those reports. Given that I prefer to do as much as possible in the transport class to have the same behaviour for different HBAs I'd prefer to not rely on the firmware's LU scan.

Quoted 2 lines

2. Since I saw that (end) devices bind to ports, what is the maximum number of ports that the Fusion firmware export?

right now it reports the number of physical ports, that's four or eight for the cards I have. But again I don't have the actual documentation yet.

Quoted 2 lines

3. Will control of SATA and STP devices be given to libata or will the Fision firmware make those look like SCSI devices?

Fusion makes them look like SCSI devices. As I mentioned I tested this patch only with SATA disks. But as the command translation for cards not doing thi in firmware would happen in the ->queuecommand path I don't think the transport class should be involved with it.

#6 lore raw
Quoted 20 lines · Christoph Hellwig
Quoted 10 lines · Luben Tuikov

drivers/scsi/scsi_transport_sas.c line 216

Quoted 7 lines
drivers/scsi/scsi_transport_sas.c new file +7 -0
+void sas_add_target(struct sas_port *port, struct sas_identify *attached,
+		uint channel, uint target)
+{
+	if (attached->target_port_protocols &
+	    (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA))
+		scsi_scan_target(&port->dev, channel, target, ~0, 0, attached);
+}

I've a few questions:

Quoted 6 lines

1. What kind of device does the Fusion driver export?
Is this a true end device, or is this the LU in the SSP end device? I.e. since the Fusion card firmware does everything about SAS there is, is also LU discovery done in the firmware, or does the firmware export only the SSP end devices and leave LU discovery to SCSI Core (as the code suggests)?

Quoted 5 lines

It seems to give notification for the actual LU, but doing an LU scan works if you use the target ID from those reports. Given that I prefer to do as much as possible in the transport class to have the same behaviour for different HBAs I'd prefer to not rely on the firmware's LU scan.

Yes, I see your point.

But you just said it: the FW exports actual LUs. Thus, even if you do a scan, you'll either get the "other" LUs, which the FW has already told you about, or CHECK CONDITION depending on where you sent it and if the device server supports it.

In effect, you can either leave it at LUs or do your own scan, but not both. An agreement is needed between the Firmware and SCSI Core.

Quoted 6 lines
Quoted 2 lines

2. Since I saw that (end) devices bind to ports, what is the maximum number of ports that the Fusion firmware export?

right now it reports the number of physical ports, that's four or eight for the cards I have. But again I don't have the actual documentation yet.

So what is the maximum number of devices it can support?

Quoted 7 lines
Quoted 2 lines

3. Will control of SATA and STP devices be given to libata or will the Fision firmware make those look like SCSI devices?

Fusion makes them look like SCSI devices. As I mentioned I tested this patch only with SATA disks. But as the command translation for cards not doing thi in firmware would happen in the ->queuecommand path I don't think the transport class should be involved with it.

Yes, how can it...

Luben