Skip to contentSkip to conversation

first cut at infrastructure for handling different device types in the sas class

RFC In review James Bottomley 4 participants 7 messages Mar 4, 2006 – Mar 6, 2006 SCSI

lore
Share & tools
lore
#0 lore raw

RFC 1/1 first cut at infrastructure for handling different device types in the sas class

This one actually does the end devices, since that's all I really have to work with in my setup. However, I can do the expanders in the same way. The idea is to make the rphy embedded in the enveloping device structure, so the code which doesn't care about type can still treat the code as a simple rphy, and the code that does care can cast out to the device type.

Temporarily, because mptsas doesn't do this, I've put a flag in to indicate whether the rphy is enveloped or not, however, if we enforce this for everything, then eventually that would go away.

The example just creates a separate class for sas_end_device with some simple properties from the end device port page:

hobholes:/sys/class# ls sas_rphy/
rphy-0:0-4  rphy-0:1-5  rphy-0:2-6  rphy-0:3-7
hobholes:/sys/class# ls sas_end_device/
rphy-0:0-4  rphy-0:1-5  rphy-0:2-6  rphy-0:3-7
hobholes:/sys/class# ls sas_end_device/rphy-0\:0-4/
device                      I_T_nexus_loss_timeout  uevent
initiator_response_timeout  ready_led_meaning

If everyone's OK with this, I'll do expanders next.

James

drivers/scsi/sas/sas_discover.c +7 -7
index cd10c52..f1339c4 100644
@@ -204,13 +204,6 @@ static int sas_get_port_device(struct sa
 		return -ENODEV;
 	}
 	phy = container_of(port->phy_list.next, struct asd_sas_phy, port_phy_el);
-	rphy = sas_rphy_alloc(phy->phy);
-	if (!rphy) {
-		spin_unlock_irqrestore(&port->phy_list_lock, flags);
-		kfree(dev);
-		return -ENODEV;
-	}
-	rphy->identify.phy_identifier = phy->phy->identify.phy_identifier;
 	spin_lock(&phy->frame_rcvd_lock);
 	memcpy(dev->frame_rcvd, phy->frame_rcvd, min(sizeof(dev->frame_rcvd),
 					     (size_t)phy->frame_rcvd_size));
@@ -237,6 +230,13 @@ static int sas_get_port_device(struct sa
 
 	sas_init_dev(dev);
 
+	rphy = dev->dev_type == SAS_END_DEV ? sas_rphy_end_device_alloc(phy->phy) : sas_rphy_alloc(phy->phy);
+	if (!rphy) {
+		spin_unlock_irqrestore(&port->phy_list_lock, flags);
+		kfree(dev);
+		return -ENODEV;
+	}
+	rphy->identify.phy_identifier = phy->phy->identify.phy_identifier;
 	memcpy(dev->sas_addr, port->attached_sas_addr, SAS_ADDR_SIZE);
 	rphy->identify.sas_address = SAS_ADDR(dev->sas_addr);
 	rphy->identify.initiator_port_protocols = dev->iproto;
drivers/scsi/sas/sas_scsi_host.c +2 -0
index af5fa7e..39ee259 100644
@@ -569,6 +569,8 @@ int sas_slave_configure(struct scsi_devi
 	dev = sdev_to_domain_dev(scsi_dev);
 	sas_ha = dev->port->ha;
 
+	sas_read_port_mode_page(scsi_dev);
+
 	if (scsi_dev->tagged_supported) {
 		scsi_set_tag_type(scsi_dev, MSG_SIMPLE_TAG);
 		scsi_activate_tcq(scsi_dev, SAS_DEF_QD);
drivers/scsi/scsi_transport_sas.c +169 -34

286 lines not on this page · raw message

include/scsi/sas/sas_discover.h +0 -1
index 1584d4e..2be414e 100644
@@ -86,7 +86,6 @@ struct sata_device {
 struct end_device {
 	u8     ms_10:1;
 	u8     ready_led_meaning:1;
-	u8     rl_wlun:1;
 	u16    itnl_timeout; 	  /* 0 if you do not know it */
 	u16    iresp_timeout;
 };
include/scsi/scsi_transport_sas.h +19 -0
index 95e2132..96ede6e 100644
@@ -82,6 +82,10 @@ struct sas_rphy {
 	struct sas_identify	identify;
 	struct list_head	list;
 	u32			scsi_target_id;
+	/* temporary expedient: mark the rphy as being contained 
+	 * within a type specific rphy
+	 * FIXME: pull this out when everything uses the containers */
+	unsigned		contained:1;
 };
 
 #define dev_to_rphy(d) \
@@ -90,6 +94,19 @@ struct sas_rphy {
 	dev_to_rphy((cdev)->dev)
 #define rphy_to_shost(rphy) \
 	dev_to_shost((rphy)->dev.parent)
+#define target_to_rphy(targ) \
+	dev_to_rphy((targ)->dev.parent)
+
+struct sas_rphy_end_device {
+	struct sas_rphy		rphy;
+	/* flags */
+	unsigned		ready_led_meaning:1;
+	/* parameters */
+	u16			I_T_nexus_loss_timeout;
+	u16			initiator_response_timeout;
+};
+#define rphy_to_end_device(r) \
+	container_of((r), struct sas_rphy_end_device, rphy)
 
 
 /* The functions by which the transport class and the driver communicate */
@@ -110,6 +127,7 @@ extern void sas_phy_delete(struct sas_ph
 extern int scsi_is_sas_phy(const struct device *);
 
 extern struct sas_rphy *sas_rphy_alloc(struct sas_phy *);
+extern struct sas_rphy *sas_rphy_end_device_alloc(struct sas_phy *);
 void sas_rphy_free(struct sas_rphy *);
 extern int sas_rphy_add(struct sas_rphy *);
 extern void sas_rphy_delete(struct sas_rphy *);
@@ -118,5 +136,6 @@ extern int scsi_is_sas_rphy(const struct
 extern struct scsi_transport_template *
 sas_attach_transport(struct sas_function_template *);
 extern void sas_release_transport(struct scsi_transport_template *);
+int sas_read_port_mode_page(struct scsi_device *);
 
 #endif /* SCSI_TRANSPORT_SAS_H */
#1 lore raw
Quoted 3 lines · --- James Bottomley

This one actually does the end devices, since that's all I really have to work with in my setup. However, I can do the expanders in the same way.

***************************************************************************

Quoted 4 lines

The idea is to make the rphy embedded in the enveloping device structure, so the code which doesn't care about type can still treat the code as a simple rphy, and the code that does care can cast out to the device type.

***************************************************************************

James, this doesn't make sense in SAS. Maybe you're implementing some other protocol, but what you have here isn't SAS. You need to understand what a port is and what a phy is. Then you need to understand their (mutual) interactions. What each one represents (or doesn't) and their dependencies.

Then you need to understand why you don't want to represent any of those two concepts for anything past your own ports.

True, it's all open sourced in the complete SAS Stack, but reverse-engineering the logic isn't easy without studying the SAS spec.

Quoted 1 line

If everyone's OK with this, I'll do expanders next.

Please don't.

They are done already, sas_expander.c is the file.

#2 lore raw
In reply to James Bottomley
Quoted 10 lines · James Bottomley

This one actually does the end devices, since that's all I really have to work with in my setup. However, I can do the expanders in the same way. The idea is to make the rphy embedded in the enveloping device structure, so the code which doesn't care about type can still treat the code as a simple rphy, and the code that does care can cast out to the device type.

Temporarily, because mptsas doesn't do this, I've put a flag in to indicate whether the rphy is enveloped or not, however, if we enforce this for everything, then eventually that would go away.

Looks good in general, but we should probably kill the rphy naming. That was my invention when doing the transport class, when I still thought we'd add a remote object for every phy in wide links. We ended up having just a remote object only under one of the phys for a wide link so we should probably kill this naming invention. In the end we should probably just have a sas_end_device, sas_expander and sas_sata_device (or just sata_device if we can share code with libata) and the common subset (sas_device?) shouldn't be exposed to userland on it's own.

Quoted 9 lines

/**
+ * sas_rphy_end_device_alloc - allocate an rphy for an end device
+ *
+ * Allocates an SAS remote PHY structure, connected to @parent.
+ *
+ * Returns:
+ * SAS PHY allocated or %NULL if the allocation failed.
+ */
+struct sas_rphy *sas_rphy_end_device_alloc(struct sas_phy *parent)

this should become sas_end_device_alloc, and so on for the other functions.

#3 lore raw
Quoted 8 lines · Christoph Hellwig

Looks good in general, but we should probably kill the rphy naming. That was my invention when doing the transport class, when I still thought we'd add a remote object for every phy in wide links. We ended up having just a remote object only under one of the phys for a wide link so we should probably kill this naming invention. In the end we should probably just have a sas_end_device, sas_expander and sas_sata_device (or just sata_device if we can share code with libata) and the common subset (sas_device?) shouldn't be exposed to userland on it's own.

Yes ... I was going to say eventually that your rphy object is really an rport object.

I think, additionally, it would be nice to display ports in the hierarchy. What I'm thinking of is basically putting phys and ports on the same level but placing the expanders and rports (rphys) under the port directory. Then the phy can have a simple link to the port it's a member of.

Quoted 2 lines

this should become sas_end_device_alloc, and so on for the other functions.

Yes, will do the renaming ... after I spend the day in Chicago.

James

#4 lore raw
Quoted 2 lines · --- James Bottomley

Then the phy can have a simple link to the port it's a
member of.

This is already the case in the SAS stack. Here is an example of wide and narrow ports. The wide port in this example connects to a domain with three cascaded expanders; the narrow port to a SAS disk.

$tree -d /sys/devices/pci0000\:01/0000\:01\:04.0/host11/sas/ha

/sys/devices/pci0000:01/0000:01:04.0/host11/sas/ha

|-- phys
|   |-- 0
|   |   `-- port -> ../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/ports/0
|   |-- 1
|   |-- 2
|   |-- 3
|   |-- 4
|   |   `-- port -> ../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/ports/1
|   |-- 5
|   |   `-- port -> ../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/ports/1
|   |-- 6
|   |   `-- port -> ../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/ports/1
|   `-- 7
|       `-- port -> ../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/ports/1
`-- ports
    |-- 0
    |   |-- domain
    |   |   `-- 500000e000031c12
    |   |       `-- LUNS
    |   |           `-- 0000000000000000
    |   `-- phys
    |       `-- 0 ->
../../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/phys/0
    `-- 1
        |-- domain
        |   `-- 50001c1716010600
        |       |-- 50001c1071609c00
        |       |   |-- 50001c1071609c02
        |       |   |-- 5000c50000102a65
        |       |   |   `-- LUNS
        |       |   |       `-- 0000000000000000
        |       |   `-- 5005076a000001e0
        |       |       |-- 5000c50000513385
        |       |       |   `-- LUNS
        |       |       |       `-- 0000000000000000
        |       |       |-- 5005076a000001ed
        |       |       |   `-- LUNS
        |       |       |       `-- 0000000000000000
        |       |       `-- 5c50000000409c11
        |       |           `-- LUNS
        |       |               `-- 0000000000000000
        |       |-- 50001c1716010603
        |       |-- 50001c171601060d
        |       |   `-- LUNS
        |       |       `-- 0000000000000000
        |       `-- 5000c50000513329
        |           `-- LUNS
        |               `-- 0000000000000000
        `-- phys
            |-- 4 ->
../../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/phys/4
            |-- 5 ->
../../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/phys/5
            |-- 6 ->
../../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/phys/6
            `-- 7 ->

../../../../../../../../../devices/pci0000:01/0000:01:04.0/host11/sas/ha/phys/7

#5 lore raw

Re: [RFC] first cut at infrastructure for handling different devicetypes in the sas class

In reply to James Bottomley
Quoted 6 lines · James Bottomley

This one actually does the end devices, since that's all I really have to work with in my setup. However, I can do the expanders in the same way. The idea is to make the rphy embedded in the enveloping device structure, so the code which doesn't care about type can still treat the code as a simple rphy, and the code that does care can cast out to the device type.

I'm not clear what your intent is here. All the info is there, so I'm not sure
why this change is needed. The sas_transport implementation Christoph
has layed out is a flat model. In /sys/class/sas_phy, you will see all the
phys for both hba and expander all togeather in the tree.The rphy is at the end of a phy link, where it the target protocol could be SMP, STP, SATA, or SAS; e.g. you can see that in rphy->identify.target_port_protocols. You can figure out whether its an end device by the attribute by rphy->indentify.device_type, which could be SAS_END_DEVICE, SAS_EDGE_EXPANDER, SAS_FANOUT_EXPANDER, or SAS_PHY_UNUSED.

Quoted 5 lines

Temporarily, because mptsas doesn't do this, I've put a flag in to indicate whether the rphy is enveloped or not, however, if we enforce this for everything, then eventually that would go away.

Ok, I'm not sure what this comment means, in respect to mptsas.
The mptsas driver is reporting all device types to the transport class, as defined in the SAS spec.

Quoted 1 line

If everyone's OK with this, I'll do expanders next.

Ok, the mptsas driver is already reporing expanders to transport class. This is handled from mptsas.c, in mptsas_probe_one_phy(), when we call sas_phy_add(). When there is any attached devices at
the end of a phy, we call sas_rphy_add(). Both these functions exported from sas_transport, work well for both hba, and expanders.

The patch I sent yesterday is adding support when someone needs to add a expander after the start of day, or reomove one. Its responding to the firmware DISCOVERY event.

Eric Moore

#6 lore raw

Re: [RFC] first cut at infrastructure for handling different devicetypes in the sas class

Quoted 10 lines · Eric

I'm not clear what your intent is here. All the info is there, so I'm not sure why this change is needed. The sas_transport implementation Christoph has layed out is a flat model. In /sys/class/sas_phy, you will see all the phys for both hba and expander all togeather in the tree.The rphy is at the end of a phy link, where it the target protocol could be SMP, STP, SATA, or SAS; e.g. you can see that in rphy->identify.target_port_protocols. You can figure out whether its an end device by the attribute by rphy->indentify.device_type, which could be SAS_END_DEVICE, SAS_EDGE_EXPANDER, SAS_FANOUT_EXPANDER, or
SAS_PHY_UNUSED.

Well, it's not ... the nexus loss timeout parameters weren't available. The intent is to embed the rphys into more representative structures that can have different parameters (an expander has parameters than an end device doesn't and vice versa). Eventually, when the whole lot is converted, the ability to alloc a plain rphy will be revoked and everything will be done via the real device type.

The aic94xx needs a full tree representation for this, so I'm planning to add this to the sas transport class. We really need to work out a way for mptsas to display the tree too. Having different topology views for the same physical SAS topology show up when you change HBA is a bit undesirable.

Quoted 8 lines
Quoted 4 lines

Temporarily, because mptsas doesn't do this, I've put a flag in to indicate whether the rphy is enveloped or not, however, if we enforce this for everything, then eventually that would go away.

Ok, I'm not sure what this comment means, in respect to mptsas. The mptsas driver is reporting all device types to the transport class, as defined in the SAS spec.

It means I couldn't be bothered to add the end device allocations to mptsas, so the code currently understands that there's a separate flag that says whether it can be cast out to the end device or not.

Quoted 11 lines
Quoted 1 line

If everyone's OK with this, I'll do expanders next.

Ok, the mptsas driver is already reporing expanders to transport class. This is handled from mptsas.c, in mptsas_probe_one_phy(), when we call sas_phy_add(). When there is any attached devices at the end of a phy, we call sas_rphy_add(). Both these functions exported from sas_transport, work well for both hba, and expanders.

The patch I sent yesterday is adding support when someone needs to add a expander after the start of day, or reomove one. Its responding to the firmware DISCOVERY event.

Yes, I know. However, I need expander devices that contain the necessary information to be able to perform discovery in the sas transport class, so they'll appear eventually in the same way that this patch adds end devices ... as objects with embedded rphys.

James