aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@us.ibm.com>2007-01-30 15:07:27 -0500
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2007-02-03 09:15:15 -0500
commit423f7cf467045eab616f97309aed87a54b5e351d (patch)
tree32d1b6fdb65dfa0816bf176bfdf1df2257caa563
parent9abe16c670bd3d4ab5519257514f9f291383d104 (diff)
[SCSI] libsas: Don't BUG when connecting two expanders via wide port
libsas: Don't BUG when connecting two expanders via wide port When a device is connected to an expander, the discovery process goes through sas_ex_discover_dev to figure out what's attached to the phy. If it is the case that the phy being discovered happens to be the second phy of a wide link to an expander, that discover_dev function will incorrectly call sas_ex_discover_expander, which creates another sas_port and tries to attach the other sas_phys to the new port, thus triggering a BUG. The correct thing to do is to check the other ex_phys of the expander to see if there's a sas_port for this sas_phy, and attach the sas_phy to the existing sas_port. This is easily triggered if one enables the phys of a wide port between expanders one by one. This second version of the patch fixes a small regression in the case where all the phys show up at once and we accidentally try to attach to a port that hasn't been created yet. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
-rw-r--r--drivers/scsi/libsas/sas_expander.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index d9b9a008d36d..dc70c180e115 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -678,6 +678,29 @@ static struct domain_device *sas_ex_discover_end_dev(
678 return NULL; 678 return NULL;
679} 679}
680 680
681/* See if this phy is part of a wide port */
682static int sas_ex_join_wide_port(struct domain_device *parent, int phy_id)
683{
684 struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id];
685 int i;
686
687 for (i = 0; i < parent->ex_dev.num_phys; i++) {
688 struct ex_phy *ephy = &parent->ex_dev.ex_phy[i];
689
690 if (ephy == phy)
691 continue;
692
693 if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr,
694 SAS_ADDR_SIZE) && ephy->port) {
695 sas_port_add_phy(ephy->port, phy->phy);
696 phy->phy_state = PHY_DEVICE_DISCOVERED;
697 return 0;
698 }
699 }
700
701 return -ENODEV;
702}
703
681static struct domain_device *sas_ex_discover_expander( 704static struct domain_device *sas_ex_discover_expander(
682 struct domain_device *parent, int phy_id) 705 struct domain_device *parent, int phy_id)
683{ 706{
@@ -810,6 +833,13 @@ static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)
810 return res; 833 return res;
811 } 834 }
812 835
836 res = sas_ex_join_wide_port(dev, phy_id);
837 if (!res) {
838 SAS_DPRINTK("Attaching ex phy%d to wide port %016llx\n",
839 phy_id, SAS_ADDR(ex_phy->attached_sas_addr));
840 return res;
841 }
842
813 switch (ex_phy->attached_dev_type) { 843 switch (ex_phy->attached_dev_type) {
814 case SAS_END_DEV: 844 case SAS_END_DEV:
815 child = sas_ex_discover_end_dev(dev, phy_id); 845 child = sas_ex_discover_end_dev(dev, phy_id);