Skip to contentSkip to conversation

RFC: Transport identifier

PATCH Martin K. Petersen 9 participants 19 messages Feb 26, 2009 – Feb 28, 2009

Subsystems (16)
SCSI USB InfiniBand s390 +12 more subsystems
lore
Share & tools
lore
#0 lore raw

There are a few cases where it would be useful to know which transport is associated with a scsi_device. For instance when determining whether to send a READ CAPACITY(16) to a device or not:

    static int sd_try_rc16_first(struct scsi_device *sdp)
    {
	if (scsi_device_transport(sdp) == SCSI_TRANSPORT_USB)
	   return 0; /* Run screaming for the hills */
    [...]

This patch implements support for a transport identifier in the scsi_host. The id defaults to SPI and it is explicitly overridden in the host templates for FC, SAS, USB, etc. drivers.

It also looks like the availability of this transport id could improve the sysfs parsing in lsscsi.

---

drivers/firewire/fw-sbp2.c +1 -0
@@ -1622,6 +1622,7 @@ static struct scsi_host_template scsi_dr
 	.cmd_per_lun		= 1,
 	.can_queue		= 1,
 	.sdev_attrs		= sbp2_scsi_sysfs_attrs,
+	.transport_id		= SCSI_TRANSPORT_SBP,
 };
 
 MODULE_AUTHOR("Kristian Hoegsberg <[email protected]>");
drivers/ieee1394/sbp2.c +1 -0
@@ -345,6 +345,7 @@ static struct scsi_host_template sbp2_sh
 	.cmd_per_lun		 = SBP2_MAX_CMDS,
 	.can_queue		 = SBP2_MAX_CMDS,
 	.sdev_attrs		 = sbp2_sysfs_sdev_attrs,
+	.transport_id		 = SCSI_TRANSPORT_SBP,
 };
 
 #define SBP2_ROM_VALUE_WILDCARD ~0         /* match all */
drivers/infiniband/ulp/iser/iscsi_iser.c +1 -0
@@ -603,6 +603,7 @@ static struct scsi_host_template iscsi_i
 	.use_clustering         = DISABLE_CLUSTERING,
 	.proc_name              = "iscsi_iser",
 	.this_id                = -1,
+	.transport_id		= SCSI_TRANSPORT_ISCSI,
 };
 
 static struct iscsi_transport iscsi_iser_transport = {
drivers/infiniband/ulp/srp/ib_srp.c +1 -0
@@ -1594,6 +1594,7 @@ static struct scsi_host_template srp_tem
 	.cmd_per_lun			= SRP_SQ_SIZE,
 	.use_clustering			= ENABLE_CLUSTERING,
 	.shost_attrs			= srp_host_attrs
+	.transport_id			= SCSI_TRANSPORT_ISCSI,
 };
 
 static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
drivers/message/fusion/mptfc.c +1 -0
@@ -131,6 +131,7 @@ static struct scsi_host_template mptfc_d
 	.cmd_per_lun			= 7,
 	.use_clustering			= ENABLE_CLUSTERING,
 	.shost_attrs			= mptscsih_host_attrs,
+	.transport_id			= SCSI_TRANSPORT_FC,
 };
 
 /****************************************************************************
drivers/message/fusion/mptsas.c +1 -0
@@ -1047,6 +1047,7 @@ static struct scsi_host_template mptsas_
 	.cmd_per_lun			= 7,
 	.use_clustering			= ENABLE_CLUSTERING,
 	.shost_attrs			= mptscsih_host_attrs,
+	.transport_id			= SCSI_TRANSPORT_SAS,
 };
 
 static int mptsas_get_linkerrors(struct sas_phy *phy)
drivers/s390/scsi/zfcp_scsi.c +1 -0
@@ -504,6 +504,7 @@ struct fc_function_template zfcp_transpo
 	.show_host_speed = 1,
 	.show_host_port_id = 1,
 	.disable_target_scan = 1,
+	.transport_id = SCSI_TRANSPORT_FC,
 };
 
 struct zfcp_data zfcp_data = {
drivers/scsi/hosts.c +10 -0
@@ -149,6 +149,15 @@ int scsi_host_set_state(struct Scsi_Host
 EXPORT_SYMBOL(scsi_host_set_state);
 
 /**
+ * scsi_host_transport_id - Get the transport for a SCSI host
+ * @shost:	pointer to SCSI host
+ */
+enum scsi_transport_id scsi_host_transport_id(struct Scsi_Host *host)
+{
+	return host->transport_id;
+}
+
+/**
  * scsi_remove_host - remove a scsi host
  * @shost:	a pointer to a scsi host to remove
  **/
@@ -358,6 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct
 	shost->unchecked_isa_dma = sht->unchecked_isa_dma;
 	shost->use_clustering = sht->use_clustering;
 	shost->ordered_tag = sht->ordered_tag;
+	shost->transport_id = sht->transport_id;
 
 	if (sht->supported_mode == MODE_UNKNOWN)
 		/* means we didn't set it ... default to INITIATOR */
drivers/scsi/iscsi_tcp.c +1 -0
@@ -836,6 +836,7 @@ static struct scsi_host_template iscsi_s
 	.slave_configure        = iscsi_sw_tcp_slave_configure,
 	.proc_name		= "iscsi_tcp",
 	.this_id		= -1,
+	.transport_id		= SCSI_TRANSPORT_ISCSI,
 };
 
 static struct iscsi_transport iscsi_sw_tcp_transport = {
drivers/scsi/lpfc/lpfc_scsi.c +2 -0
@@ -2956,6 +2956,7 @@ struct scsi_host_template lpfc_template 
 	.use_clustering		= ENABLE_CLUSTERING,
 	.shost_attrs		= lpfc_hba_attrs,
 	.max_sectors		= 0xFFFF,
+	.transport_id		= SCSI_TRANSPORT_FC,
 };
 
 struct scsi_host_template lpfc_vport_template = {
@@ -2976,4 +2977,5 @@ struct scsi_host_template lpfc_vport_tem
 	.use_clustering		= ENABLE_CLUSTERING,
 	.shost_attrs		= lpfc_vport_attrs,
 	.max_sectors		= 0xFFFF,
+	.transport_id		= SCSI_TRANSPORT_FC,
 };
drivers/scsi/megaraid/megaraid_sas.c +1 -0
@@ -1309,6 +1309,7 @@ static struct scsi_host_template megasas
 	.eh_timed_out = megasas_reset_timer,
 	.bios_param = megasas_bios_param,
 	.use_clustering = ENABLE_CLUSTERING,
+	.transport_id = SCSI_TRANSPORT_SAS,
 };
 
 /**
drivers/scsi/qla2xxx/qla_os.c +2 -0
@@ -147,6 +147,7 @@ static struct scsi_host_template qla2x00
 	 */
 	.max_sectors		= 0xFFFF,
 	.shost_attrs		= qla2x00_host_attrs,
+	.transport_id		= SCSI_TRANSPORT_FC,
 };
 
 struct scsi_host_template qla24xx_driver_template = {
@@ -175,6 +176,7 @@ struct scsi_host_template qla24xx_driver
 
 	.max_sectors		= 0xFFFF,
 	.shost_attrs		= qla2x00_host_attrs,
+	.transport_id		= SCSI_TRANSPORT_FC,
 };
 
 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
drivers/scsi/qla4xxx/ql4_os.c +1 -0
@@ -103,6 +103,7 @@ static struct scsi_host_template qla4xxx
 	.sg_tablesize		= SG_ALL,
 
 	.max_sectors		= 0xFFFF,
+	.transport_id		= SCSI_TRANSPORT_ISCSI,
 };
 
 static struct iscsi_transport qla4xxx_iscsi_transport = {
drivers/scsi/scsi_sysfs.c +15 -0
@@ -244,6 +244,20 @@ show_shost_active_mode(struct device *de
 
 static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
 
+/* These strings must match the scsi_transport_id enum in scsi.h */
+static const char * const transport_names[] = {
+	"spi", "fc", "sas", "iscsi", "sbp", "usb", "ata",
+};
+
+static ssize_t
+show_shost_transport_id(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct Scsi_Host *shost = class_to_shost(dev);
+
+	return snprintf(buf, 20, "%s\n", transport_names[shost->transport_id]);
+}
+static DEVICE_ATTR(transport_id, S_IRUGO, show_shost_transport_id, NULL);
+
 shost_rd_attr(unique_id, "%u\n");
 shost_rd_attr(host_busy, "%hu\n");
 shost_rd_attr(cmd_per_lun, "%hd\n");
@@ -268,6 +282,7 @@ static struct attribute *scsi_sysfs_shos
 	&dev_attr_active_mode.attr,
 	&dev_attr_prot_capabilities.attr,
 	&dev_attr_prot_guard_type.attr,
+	&dev_attr_transport_id.attr,
 	NULL
 };
 
drivers/usb/storage/scsiglue.c +3 -1
@@ -553,7 +553,9 @@ struct scsi_host_template usb_stor_host_
 	.sdev_attrs =			sysfs_device_attr_list,
 
 	/* module management */
-	.module =			THIS_MODULE
+	.module =			THIS_MODULE,
+
+	.transport_id = 		SCSI_TRANSPORT_USB,
 };
 
 /* To Report "Illegal Request: Invalid Field in CDB */
include/linux/libata.h +1 -0
@@ -1144,6 +1144,7 @@ extern struct device_attribute *ata_comm
 	.slave_configure	= ata_scsi_slave_config,	\
 	.slave_destroy		= ata_scsi_slave_destroy,	\
 	.bios_param		= ata_std_bios_param,		\
+	.transport_id		= SCSI_TRANSPORT_ATA,		\
 	.sdev_attrs		= ata_common_sdev_attrs
 
 #define ATA_NCQ_SHT(drv_name)					\
include/scsi/scsi.h +12 -0
@@ -533,4 +533,16 @@ static inline __u32 scsi_to_u32(__u8 *pt
 	return (ptr[0]<<24) + (ptr[1]<<16) + (ptr[2]<<8) + ptr[3];
 }
 
+enum scsi_transport_id {
+	SCSI_TRANSPORT_SPI,
+	SCSI_TRANSPORT_FC,
+	SCSI_TRANSPORT_SAS,
+	SCSI_TRANSPORT_ISCSI,
+	SCSI_TRANSPORT_SBP,
+	SCSI_TRANSPORT_USB,
+	SCSI_TRANSPORT_ATA,
+};
+
+extern enum scsi_transport_id scsi_host_transport_id(struct Scsi_Host *);
+
 #endif /* _SCSI_SCSI_H */
include/scsi/scsi_device.h +5 -0
@@ -455,6 +455,11 @@ static inline int scsi_device_protection
 	return sdev->scsi_level > SCSI_2 && sdev->inquiry[5] & (1<<0);
 }
 
+static inline int scsi_device_transport(struct scsi_device *sdev)
+{
+	return scsi_host_transport_id(sdev->host);
+}
+
 #define MODULE_ALIAS_SCSI_DEVICE(type) \
 	MODULE_ALIAS("scsi:t-" __stringify(type) "*")
 #define SCSI_DEVICE_MODALIAS_FMT "scsi:t-0x%02x"
include/scsi/scsi_host.h +6 -0
@@ -471,6 +471,11 @@ struct scsi_host_template {
 	struct device_attribute **sdev_attrs;
 
 	/*
+	 * Type of transport
+	 */
+	enum scsi_transport_id transport_id;
+
+	/*
 	 * List of hosts per template.
 	 *
 	 * This is only for use by scsi_module.c for legacy templates.
@@ -648,6 +653,7 @@ struct Scsi_Host {
 	
 
 	enum scsi_host_state shost_state;
+	enum scsi_transport_id transport_id;
 
 	/* ldm bits */
 	struct device		shost_gendev, shost_dev;
#1 lore raw
Quoted 19 lines · Martin K. Petersen

There are a few cases where it would be useful to know which transport is associated with a scsi_device.  For instance when determining whether to send a READ CAPACITY(16) to a device or not:

   static int sd_try_rc16_first(struct scsi_device *sdp) {
       if (scsi_device_transport(sdp) == SCSI_TRANSPORT_USB) return 0; /* Run screaming for the hills */ [...]

This patch implements support for a transport identifier in the scsi_host.  The id defaults to SPI and it is explicitly overridden in the host templates for FC, SAS, USB, etc. drivers.

It also looks like the availability of this transport id could improve the sysfs parsing in lsscsi.

[snip]

drivers/scsi/scsi_sysfs.c show_shost_active_mode(struct device *de · line 250

Quoted 4 lines
drivers/scsi/scsi_sysfs.c +4 -0
+/* These strings must match the scsi_transport_id enum in scsi.h */
+static const char * const transport_names[] = {
+       "spi", "fc", "sas", "iscsi", "sbp", "usb", "ata",
+};

Firstly, this should probably mark which name is for which value. (I know it's obvious, but it could get confusing if there are ever user friendly names here.)

[snip]

include/scsi/scsi.h static inline __u32 scsi_to_u32(__u8 *pt · line 544

Quoted 9 lines
include/scsi/scsi.h +9 -0
+enum scsi_transport_id {
+       SCSI_TRANSPORT_SPI,
+       SCSI_TRANSPORT_FC,
+       SCSI_TRANSPORT_SAS,
+       SCSI_TRANSPORT_ISCSI,
+       SCSI_TRANSPORT_SBP,
+       SCSI_TRANSPORT_USB,
+       SCSI_TRANSPORT_ATA,
+};

Should there be a comment here pointing out that the names must also be updated if new items are added?

Thanks,

Signature · 8 lines
Julian Calaby

Email: [email protected]
.Plan: http://sites.google.com/site/juliancalaby/
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 24 lines · Julian Calaby
Quoted 19 lines · Martin K. Petersen

There are a few cases where it would be useful to know which transport is associated with a scsi_device.  For instance when determining whether to send a READ CAPACITY(16) to a device or not:

   static int sd_try_rc16_first(struct scsi_device *sdp) {
       if (scsi_device_transport(sdp) == SCSI_TRANSPORT_USB) return 0; /* Run screaming for the hills */ [...]

This patch implements support for a transport identifier in the scsi_host.  The id defaults to SPI and it is explicitly overridden in the host templates for FC, SAS, USB, etc. drivers.

It also looks like the availability of this transport id could improve the sysfs parsing in lsscsi.

[snip]

Quoted 8 lines

drivers/scsi/scsi_sysfs.c show_shost_active_mode(struct device *de · line 250

Quoted 4 lines
drivers/scsi/scsi_sysfs.c +4 -0
+/* These strings must match the scsi_transport_id enum in scsi.h */
+static const char * const transport_names[] = {
+       "spi", "fc", "sas", "iscsi", "sbp", "usb", "ata",
+};

Firstly, this should probably mark which name is for which value. (I know it's obvious, but it could get confusing if there are ever user friendly names here.)

I like doing this:

static const char * const transport_names[] = {
	[SCSI_TRANSPORT_SPI]		= "spi",
	...
};

Joel

Signature · 14 lines
"It is not the function of our government to keep the citizen from
 falling into error; it is the function of the citizen to keep the
 government from falling into error."
	- Robert H. Jackson

Joel Becker
Principal Software Developer
Oracle
E-mail: [email protected]
Phone: (650) 506-8127
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Joel" == Joel Becker <[email protected]> writes:

Joel> I like doing this:

Joel> static const char * const transport_names[] = {
Joel> [SCSI_TRANSPORT_SPI] = "spi", ...
Joel> };

Joel> Joel

Oh, slick!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw
In reply to Martin K. Petersen
Quoted 10 lines · Martin K. Petersen

There are a few cases where it would be useful to know which transport is associated with a scsi_device. For instance when determining whether to send a READ CAPACITY(16) to a device or not:

    static int sd_try_rc16_first(struct scsi_device *sdp)
    {
	if (scsi_device_transport(sdp) == SCSI_TRANSPORT_USB)
	   return 0; /* Run screaming for the hills */
    [...]
Quoted 6 lines

This patch implements support for a transport identifier in the scsi_host. The id defaults to SPI and it is explicitly overridden in the host templates for FC, SAS, USB, etc. drivers.

It also looks like the availability of this transport id could improve the sysfs parsing in lsscsi.

lsscsi could do with some help detecting the transport. It uses an untidy set of heuristics now that can easily be tripped up by sysfs changes.

It may be helpful to differentiate between a "near end" transport (i.e. between the initiator and the target) and the transport (and possibly different command set) that the logical unit (LU) reports.

Doug Gilbert

#5 lore raw
In reply to Martin K. Petersen
Quoted 25 lines · Martin K. Petersen

There are a few cases where it would be useful to know which transport is associated with a scsi_device. For instance when determining whether to send a READ CAPACITY(16) to a device or not:

    static int sd_try_rc16_first(struct scsi_device *sdp)
    {
	if (scsi_device_transport(sdp) == SCSI_TRANSPORT_USB)
	   return 0; /* Run screaming for the hills */
    [...]

This patch implements support for a transport identifier in the scsi_host. The id defaults to SPI and it is explicitly overridden in the host templates for FC, SAS, USB, etc. drivers.

It also looks like the availability of this transport id could improve the sysfs parsing in lsscsi.

drivers/infiniband/ulp/srp/ib_srp.c static struct scsi_host_template srp_tem · line 1598

Quoted 5 lines
drivers/infiniband/ulp/srp/ib_srp.c +1 -0
@@ -1594,6 +1594,7 @@ static struct scsi_host_template srp_tem
 	.cmd_per_lun			= SRP_SQ_SIZE,
 	.use_clustering			= ENABLE_CLUSTERING,
 	.shost_attrs			= srp_host_attrs
+	.transport_id			= SCSI_TRANSPORT_ISCSI,
 };

This one is a new type, SCSI_TRANSPORT_SRP.

There is a new iscsi driver in Linus and James's current tree in drivers/scsi/cxgb3i. And there is a new fc one in drivers/scsi/fcoe.

maintainer
#6 lore raw
In reply to Martin K. Petersen
Quoted 10 lines · Martin K. Petersen

There are a few cases where it would be useful to know which transport is associated with a scsi_device. For instance when determining whether to send a READ CAPACITY(16) to a device or not:

    static int sd_try_rc16_first(struct scsi_device *sdp)
    {
	if (scsi_device_transport(sdp) == SCSI_TRANSPORT_USB)
	   return 0; /* Run screaming for the hills */
    [...]
Quoted 6 lines

This patch implements support for a transport identifier in the scsi_host. The id defaults to SPI and it is explicitly overridden in the host templates for FC, SAS, USB, etc. drivers.

It also looks like the availability of this transport id could improve the sysfs parsing in lsscsi.

I'd really rather not put transport specific knowledge back into the mid-layer ... the whole idea of the transport classes was to take it out as much as possible.

The other thought is that a lot of devices nowadays are bridged (all SCSI DVDs have SPI to ATA bridges; a lot of high end USB storage or enclosures has USB to ATA bridges), so a single transport identifier doesn't quite cover it.

The final thought is that a lot of what you're looking for is actually in the PROTOCOL field of a VPD inquiry, so it might be possible to use that to obviate a lot of this.

James

#7 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"James" == James Bottomley <[email protected]> writes:

James> I'd really rather not put transport specific knowledge back into James> the mid-layer ... the whole idea of the transport classes was to James> take it out as much as possible.

I felt that implementing transport classes for everything else was a huge overkill for a simple identifier.

James> The other thought is that a lot of devices nowadays are bridged James> (all SCSI DVDs have SPI to ATA bridges; a lot of high end USB James> storage or enclosures has USB to ATA bridges), so a single James> transport identifier doesn't quite cover it.

Nope. And it was not means to be concise. It was meant to be a hint as to what kind of technology was at play.

To a large extent a dubious_transport bit would suffice. But I also wanted to remedy the lsscsi problem while I was at it. As Doug mentioned the current heuristics are icky.

James> The final thought is that a lot of what you're looking for is James> actually in the PROTOCOL field of a VPD inquiry, so it might be James> possible to use that to obviate a lot of this.

You mean the protocol mode page? Or the version descriptors in INQUIRY?

I don't have a single device that provides the version descriptors. Sadly.

I'm fine with the mode page approach, although a quick test shows only very recent drives fill it out. I'll try it on all my spindles in the lab and see what I discover.

Maybe we can reverse the logic a bit and key off of whether the protocol mode page is provided. And consider devices dubious if it's not?

The thing is we need to start sending RC16 to a lot of drives very soon because of the 4KB thing. And as we've seen RC16 breaks a lot of junk devices. So we need a good indicator other than the SCSI rev. because that unfortunately doesn't cut it.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#8 lore raw
Quoted 8 lines · On Thu, 26 Feb 2009 15:32:24 -0500 "Martin K. Petersen"…
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"James" == James Bottomley <[email protected]> writes:

James> I'd really rather not put transport specific knowledge back into James> the mid-layer ... the whole idea of the transport classes was to James> take it out as much as possible.

I felt that implementing transport classes for everything else was a huge overkill for a simple identifier.

But touching every lld is not nice. How about setting shost->transport_id in each transport class (like the attached patch)? I guess that it would be better to move this to transport class completely though.

Quoted 11 lines

James> The other thought is that a lot of devices nowadays are bridged James> (all SCSI DVDs have SPI to ATA bridges; a lot of high end USB James> storage or enclosures has USB to ATA bridges), so a single James> transport identifier doesn't quite cover it.

Nope. And it was not means to be concise. It was meant to be a hint as to what kind of technology was at play.

To a large extent a dubious_transport bit would suffice. But I also wanted to remedy the lsscsi problem while I was at it. As Doug mentioned the current heuristics are icky.

Doug's idea (or something like that) sounds reasonable to me.

Quoted 8 lines

James> The final thought is that a lot of what you're looking for is James> actually in the PROTOCOL field of a VPD inquiry, so it might be James> possible to use that to obviate a lot of this.

You mean the protocol mode page? Or the version descriptors in INQUIRY?

I don't have a single device that provides the version descriptors. Sadly.

I don't too. I checked the PROTOCOL field of a VPD inquiry for other reasons and none of my disk set it.

drivers/scsi/scsi_sysfs.c +41 -0
index da63802..010cc33 100644
@@ -140,6 +140,33 @@ static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
 #define shost_rd_attr(field, format_string) \
 shost_rd_attr2(field, field, format_string)
 
+static const struct {
+	enum scsi_transport_id value;
+	char *name;
+} scsi_transport_names[] = {
+	{SCSI_TRANSPORT_SPI, "spi"},
+	{SCSI_TRANSPORT_FC, "fc"},
+	{SCSI_TRANSPORT_SAS, "sas"},
+	{SCSI_TRANSPORT_ISCSI, "iscsi"},
+	{SCSI_TRANSPORT_SBP, "sbp"},
+	{SCSI_TRANSPORT_USB, "usb"},
+	{SCSI_TRANSPORT_ATA, "ata"},
+};
+
+static const char *scsi_transport_name(enum scsi_transport_id id)
+{
+	int i;
+	char *name = NULL;
+
+	for (i = 0; i < ARRAY_SIZE(scsi_transport_names); i++) {
+		if (scsi_transport_names[i].value == id) {
+			name = scsi_transport_names[i].name;
+			break;
+		}
+	}
+	return name;
+}
+
 /*
  * Create the actual show/store functions and data structures.
  */
@@ -244,6 +271,19 @@ show_shost_active_mode(struct device *dev,
 
 static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
 
+static ssize_t
+show_shost_transport_name(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct Scsi_Host *shost = class_to_shost(dev);
+	const char *name = scsi_transport_name(shost->transport_id);
+
+	if (!name)
+		return -EINVAL;
+	return snprintf(buf, 20, "%s\n", name);
+}
+static DEVICE_ATTR(transport_name, S_IRUGO, show_shost_transport_name, NULL);
+
 shost_rd_attr(unique_id, "%u\n");
 shost_rd_attr(host_busy, "%hu\n");
 shost_rd_attr(cmd_per_lun, "%hd\n");
@@ -268,6 +308,7 @@ static struct attribute *scsi_sysfs_shost_attrs[] = {
 	&dev_attr_active_mode.attr,
 	&dev_attr_prot_capabilities.attr,
 	&dev_attr_prot_guard_type.attr,
+	&dev_attr_transport_name.attr,
 	NULL
 };
 
drivers/scsi/scsi_transport_fc.c +1 -0
index 5f77417..093bdb5 100644
@@ -410,6 +410,7 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev,
 		fc_host->work_q = NULL;
 		return -ENOMEM;
 	}
+	shost->transport_id = SCSI_TRANSPORT_FC;
 
 	return 0;
 }
drivers/scsi/scsi_transport_iscsi.c +1 -0
index 75c9297..9bfbbb8 100644
@@ -253,6 +253,7 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
 						ihost->scan_workq_name);
 	if (!ihost->scan_workq)
 		return -ENOMEM;
+	shost->transport_id = SCSI_TRANSPORT_ISCSI;
 	return 0;
 }
 
drivers/scsi/scsi_transport_sas.c +1 -0
index 50988cb..8335de8 100644
@@ -287,6 +287,7 @@ static int sas_host_setup(struct transport_container *tc, struct device *dev,
 		dev_printk(KERN_ERR, dev, "fail to a bsg device %d\n",
 			   shost->host_no);
 
+	shost->transport_id = SCSI_TRANSPORT_SAS;
 	return 0;
 }
 
drivers/scsi/scsi_transport_srp.c +1 -0
index 21a045e..0533977 100644
@@ -63,6 +63,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
 	struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
 
 	atomic_set(&srp_host->next_port_id, 0);
+	shost->transport_id = SCSI_TRANSPORT_SRP;
 	return 0;
 }
 
include/scsi/scsi.h +10 -0
index a109165..4d1d75e 100644
@@ -533,4 +533,14 @@ static inline __u32 scsi_to_u32(__u8 *ptr)
 	return (ptr[0]<<24) + (ptr[1]<<16) + (ptr[2]<<8) + ptr[3];
 }
 
+enum scsi_transport_id {
+	SCSI_TRANSPORT_SPI = 0,
+	SCSI_TRANSPORT_FC,
+	SCSI_TRANSPORT_SAS,
+	SCSI_TRANSPORT_ISCSI,
+	SCSI_TRANSPORT_SBP,
+	SCSI_TRANSPORT_USB,
+	SCSI_TRANSPORT_ATA,
+};
+
 #endif /* _SCSI_SCSI_H */
include/scsi/scsi_host.h +1 -0
index d123ca8..54fc90f 100644
@@ -648,6 +648,7 @@ struct Scsi_Host {
 	
 
 	enum scsi_host_state shost_state;
+	enum scsi_transport_id transport_id;
 
 	/* ldm bits */
 	struct device		shost_gendev, shost_dev;
#9 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Tomo" == FUJITA Tomonori <[email protected]> writes:

Tomo> How about setting shost->transport_id in each transport class Tomo> (like the attached patch)? I guess that it would be better to Tomo> move this to transport class completely though.

The following patch below sits somewhere between my original take and your patch. Those transports that have classes implemented fill out the id like you did. The ones that don't (ATA, FireWire and USB) set it manually. Best of both worlds, IMHO.

The patch provides a solution for lsscsi scanning. I'll save the scsi_device portion for another time.

Quoted 2 lines
Quoted 2 lines

I don't have a single device that provides the version descriptors. Sadly.

Tomo> I don't too. I checked the PROTOCOL field of a VPD inquiry for Tomo> other reasons and none of my disk set it.

I tested in my lab today and out of about 30 drive models I only had one that had the protocol mode pages filled out. Not a single drive had the version descriptors. I also tried a few USB and FireWire drives. Zilch.

I was planning on rolling an orthogonal patch that exposed device/port protocol. But given the test results I'm not so sure it's worth the effort.

drivers/ata/libata-scsi.c +1 -0
@@ -3215,6 +3215,7 @@ int ata_scsi_add_hosts(struct ata_host *
 		shost->max_lun = 1;
 		shost->max_channel = 1;
 		shost->max_cmd_len = 16;
+		shost->transport_id = SCSI_TRANSPORT_ATA;
 
 		/* Schedule policy is determined by ->qc_defer()
 		 * callback and it needs to see every deferred qc.
drivers/firewire/fw-sbp2.c +1 -0
@@ -1144,6 +1144,7 @@ static int sbp2_probe(struct device *dev
 	if (scsi_add_host(shost, &unit->device) < 0)
 		goto fail_shost_put;
 
+	shost->transport_id = SCSI_TRANSPORT_SBP;
 	fw_device_get(device);
 	fw_unit_get(unit);
 
drivers/ieee1394/sbp2.c +1 -0
@@ -880,6 +880,7 @@ static struct sbp2_lu *sbp2_alloc_device
 	}
 
 	shost->hostdata[0] = (unsigned long)lu;
+	shost->transport_id = SCSI_TRANSPORT_SBP;
 
 	if (!scsi_add_host(shost, &ud->device)) {
 		lu->shost = shost;
drivers/scsi/scsi_sysfs.c +44 -0

62 lines not on this page · raw message

drivers/scsi/scsi_transport_fc.c +1 -0
@@ -410,6 +410,7 @@ static int fc_host_setup(struct transpor
 		fc_host->work_q = NULL;
 		return -ENOMEM;
 	}
+	shost->transport_id = SCSI_TRANSPORT_FC;
 
 	return 0;
 }
drivers/scsi/scsi_transport_iscsi.c +1 -0
@@ -253,6 +253,7 @@ static int iscsi_setup_host(struct trans
 						ihost->scan_workq_name);
 	if (!ihost->scan_workq)
 		return -ENOMEM;
+	shost->transport_id = SCSI_TRANSPORT_ISCSI;
 	return 0;
 }
 
drivers/scsi/scsi_transport_sas.c +1 -0
@@ -287,6 +287,7 @@ static int sas_host_setup(struct transpo
 		dev_printk(KERN_ERR, dev, "fail to a bsg device %d\n",
 			   shost->host_no);
 
+	shost->transport_id = SCSI_TRANSPORT_SAS;
 	return 0;
 }
 
drivers/scsi/scsi_transport_srp.c +1 -0
@@ -63,6 +63,7 @@ static int srp_host_setup(struct transpo
 	struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
 
 	atomic_set(&srp_host->next_port_id, 0);
+	shost->transport_id = SCSI_TRANSPORT_SRP;
 	return 0;
 }
 
drivers/usb/storage/usb.c +1 -0
@@ -1041,6 +1041,7 @@ static int storage_probe(struct usb_inte
 	 * Allow 16-byte CDBs and thus > 2TB
 	 */
 	host->max_cmd_len = 16;
+	host->transport_id = SCSI_TRANSPORT_USB;
 	us = host_to_us(host);
 	memset(us, 0, sizeof(struct us_data));
 	mutex_init(&(us->dev_mutex));
include/scsi/scsi.h +11 -0
@@ -533,4 +533,15 @@ static inline __u32 scsi_to_u32(__u8 *pt
 	return (ptr[0]<<24) + (ptr[1]<<16) + (ptr[2]<<8) + ptr[3];
 }
 
+enum scsi_transport_id {
+	SCSI_TRANSPORT_UNKNOWN = 0,
+	SCSI_TRANSPORT_SPI,
+	SCSI_TRANSPORT_FC,
+	SCSI_TRANSPORT_SAS,
+	SCSI_TRANSPORT_ISCSI,
+	SCSI_TRANSPORT_SBP,
+	SCSI_TRANSPORT_USB,
+	SCSI_TRANSPORT_ATA,
+};
+
 #endif /* _SCSI_SCSI_H */
include/scsi/scsi_host.h +1 -0
@@ -648,6 +648,7 @@ struct Scsi_Host {
 	
 
 	enum scsi_host_state shost_state;
+	enum scsi_transport_id transport_id;
 
 	/* ldm bits */
 	struct device		shost_gendev, shost_dev;
#10 lore raw
Quoted 4 lines · Martin K. Petersen

The following patch below sits somewhere between my original take and your patch. Those transports that have classes implemented fill out the id like you did. The ones that don't (ATA, FireWire and USB) set it manually. Best of both worlds, IMHO.

You seem to have missed the patch to scsi_transport_spi.c. There's also a lot of parallel SCSI drivers that don't use scsi_transport_spi.c yet. I'm OK with them being 'unknown' and eventually people patching them (or perhaps better, converting them to use scsi_transport_spi!), but thought it was worth mentioning.

Quoted 11 lines
drivers/ata/libata-scsi.c +0 -0
drivers/firewire/fw-sbp2.c +0 -0
drivers/ieee1394/sbp2.c +0 -0
drivers/scsi/scsi_sysfs.c +0 -0
drivers/scsi/scsi_transport_fc.c +0 -0
drivers/scsi/scsi_transport_iscsi.c +0 -0
drivers/scsi/scsi_transport_sas.c +0 -0
drivers/scsi/scsi_transport_srp.c +0 -0
drivers/usb/storage/usb.c +0 -0
include/scsi/scsi.h +0 -0
include/scsi/scsi_host.h +0 -0
Signature · 4 lines
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#11 lore raw
Quoted 11 lines · On Fri, 27 Feb 2009 21:50:14 -0700 Matthew Wilcox <[email protected]> wrote:
Quoted 4 lines · Martin K. Petersen

The following patch below sits somewhere between my original take and your patch. Those transports that have classes implemented fill out the id like you did. The ones that don't (ATA, FireWire and USB) set it manually. Best of both worlds, IMHO.

You seem to have missed the patch to scsi_transport_spi.c. There's also a lot of parallel SCSI drivers that don't use scsi_transport_spi.c yet. I'm OK with them being 'unknown' and eventually people patching them (or perhaps better, converting them to use scsi_transport_spi!), but thought it was worth mentioning.

Yeah, that's why my patch sets SCSI_TRANSPORT_SPI to 0. So a lot of parallel SCSI drivers that don't use spi class can get 'spi' properly. It's better to convert them to use spi class but I really doubt someone would do.

#12 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Tomo" == FUJITA Tomonori <[email protected]> writes:

Tomo> Yeah, that's why my patch sets SCSI_TRANSPORT_SPI to 0. So a lot Tomo> of parallel SCSI drivers that don't use spi class can get 'spi' Tomo> properly.

Oh, duh. I added the unknown bits last minute to check for devices that didn't have a class. Shows you how many parallel devices I have left :)

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#13 lore raw
In reply to Martin K. Petersen
Quoted 4 lines · Martin K. Petersen

The thing is we need to start sending RC16 to a lot of drives very soon because of the 4KB thing. And as we've seen RC16 breaks a lot of junk devices. So we need a good indicator other than the SCSI rev. because that unfortunately doesn't cut it.

/Is/ the used transport protocol a good indicator for whether a particular target breaks by READ CAPACITY 16? I have doubts. Command set support is independent of transport protocol support.

Signature · 3 lines
Stefan Richter
-=====-==--= --=- ===--
http://arcgraph.de/sr/
#14 lore raw
Quoted 9 lines · Stefan Richter
Quoted 4 lines · Martin K. Petersen

The thing is we need to start sending RC16 to a lot of drives very soon because of the 4KB thing. And as we've seen RC16 breaks a lot of junk devices. So we need a good indicator other than the SCSI rev. because that unfortunately doesn't cut it.

/Is/ the used transport protocol a good indicator for whether a particular target breaks by READ CAPACITY 16? I have doubts. Command set support is independent of transport protocol support.

You must admit there's a striking correlation between USB devices and completely failing to follow the SCSI spec. Our current workaround of clamping USB devices at a SCSI_2 level does avoid much of the pain.

I can only hope that UAS devices actually implement SCSI instead of flicking bits at random until vista doesn't crash every time you plug it in.

Signature · 4 lines
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#15 lore raw
Quoted 8 lines · Matthew Wilcox
Quoted 3 lines · Stefan Richter

/Is/ the used transport protocol a good indicator for whether a particular target breaks by READ CAPACITY 16? I have doubts. Command set support is independent of transport protocol support.

You must admit there's a striking correlation between USB devices and completely failing to follow the SCSI spec. Our current workaround of clamping USB devices at a SCSI_2 level does avoid much of the pain.

OK, but currently implementations typically are:
1. transport layer driver detects device with known flaws, switches on a device quirk flag,
2. transport layer enables quirk for all devices which it serves by, default, possibly disables quirk for some whitelisted devices.

Pulling the SCSI level down in usb-storage belongs into the latter category.

Martin's proposal for transport identifiers includes the suggestion of a third strategy:
3. transport layer identifies itself, upper layer enable some quirks based on that information (alone or in combination with whatever other information).

So, while it may be prudent to deduct "it's USB" -> "don't try READ CAPACITY 16", why not keep implementing this in way #2?

Signature · 3 lines
Stefan Richter
-=====-==--= --=- ===--
http://arcgraph.de/sr/
maintainer
#16 lore raw
Quoted 16 lines · Stefan Richter
Quoted 8 lines · Matthew Wilcox
Quoted 3 lines · Stefan Richter

/Is/ the used transport protocol a good indicator for whether a particular target breaks by READ CAPACITY 16? I have doubts. Command set support is independent of transport protocol support.

You must admit there's a striking correlation between USB devices and completely failing to follow the SCSI spec. Our current workaround of clamping USB devices at a SCSI_2 level does avoid much of the pain.

OK, but currently implementations typically are:
1. transport layer driver detects device with known flaws, switches on a device quirk flag,
2. transport layer enables quirk for all devices which it serves by, default, possibly disables quirk for some whitelisted devices.

Quoted 7 lines

Pulling the SCSI level down in usb-storage belongs into the latter category.

Martin's proposal for transport identifiers includes the suggestion of a third strategy:
3. transport layer identifies itself, upper layer enable some quirks based on that information (alone or in combination with whatever other information).

Actually, that's the piece of this proposal I'm explicitly saying no to:
we're not going to code transport knowledge into the mid-layer because it's setting us up to get things wrong.

The thing that may be useful in all of this is for udev to get the transport type from sysfs ... I'm not entirely sure about this one, since udev seems to do a pretty good job on its own without an exported identifier, but I can see an explicit one might be useful to it.

Quoted 2 lines

So, while it may be prudent to deduct "it's USB" -> "don't try READ CAPACITY 16", why not keep implementing this in way #2?

We will. That way if a wonderfully compliant USB device comes along (big if, I know) you can white list it in the USB (or SBP-2) layer and pass along its true SCSI compliance level.

James

#17 lore raw
In reply to Stefan Richter
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Stefan" == Stefan Richter <[email protected]> writes:

Stefan> So, while it may be prudent to deduct "it's USB" -> "don't try Stefan> READ CAPACITY 16", why not keep implementing this in way #2?

I predict our scanning will involve much more heuristics than it does now. In relatively near future we will have to start using a less conservative approach to sending commands because 4KB drives and drives with odd alignment require us to use READ CAPACITY(16).

The triggers at the device level which would help (protocol mode pages, version descriptors) are generally not filled out. Not even in brand new enterprise drives.

For DIF I had the luxury of being able to trigger off the PROTECT bit in INQUIRY. And even that broke because some USB devices returned random garbage causing DIF to be enabled by accident.

The other problem we are facing is that right now the reported version kinda-sorta works but that may not continue to be the case. There are several drive vendors that deliberately return a much older version than the command set actually supported by the drive. This is to work around problems in legacy proprietary operating systems.

Originally my plan was to key off of the presence of the block limits VPD page and submit RC16 if that was present. But the VPD is mostly aimed at RAID vendors and I'm told that drive vendors are not going to bother filling it out.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#18 lore raw
In reply to Stefan Richter
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Stefan" == Stefan Richter <[email protected]> writes:

Stefan> particular target breaks by READ CAPACITY 16? I have doubts. Stefan> Command set support is independent of transport protocol Stefan> support.

I think that's a separate discussion we need to have. My original patch facilitates a check like that but it's not the only use for the transport_id.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering