diff options
author | Tom Peng <tom_peng@usish.com> | 2009-07-17 04:02:04 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2009-07-30 10:54:39 -0400 |
commit | 19252de6818ced0def0551d64a0a2975f52a523d (patch) | |
tree | bdd56c97b5e94a742c5090b53e3f437505c245c1 /drivers | |
parent | a0cc1ecc098e31d03b3265712a3e280a7fabf438 (diff) |
[SCSI] libsas: fix wide port hotplug issues
Hotplug of phys which form wide ports simply does not work at the moment. Fix
this by adding checks at the hotplug points to see if the attached sas address
of the phy already exists (in which case it's part of a wide port) and act
accordingly.
Signed-off-by: Tom Peng <tom_peng@usish.com>
Signed-off-by: Jack Wang <jack_wang@usish.com>
Signed-off-by: Lindar Liu <lindar_liu@usish.com>
Signed-off-by: Kevin Ao <aoqingyun@usish.com>
[jejb: tidied up coding, fixed an error case and made TRUE/FALSE lower
case to fix a ppc64 compile error in linux-next]
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/scsi/libsas/sas_expander.c | 147 |
1 files changed, 107 insertions, 40 deletions
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index 54fa1e42dc4d..b3381959acce 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c | |||
@@ -766,6 +766,7 @@ static int sas_ex_join_wide_port(struct domain_device *parent, int phy_id) | |||
766 | if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr, | 766 | if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr, |
767 | SAS_ADDR_SIZE) && ephy->port) { | 767 | SAS_ADDR_SIZE) && ephy->port) { |
768 | sas_port_add_phy(ephy->port, phy->phy); | 768 | sas_port_add_phy(ephy->port, phy->phy); |
769 | phy->port = ephy->port; | ||
769 | phy->phy_state = PHY_DEVICE_DISCOVERED; | 770 | phy->phy_state = PHY_DEVICE_DISCOVERED; |
770 | return 0; | 771 | return 0; |
771 | } | 772 | } |
@@ -945,11 +946,21 @@ static int sas_ex_discover_dev(struct domain_device *dev, int phy_id) | |||
945 | if (ex->ex_phy[i].phy_state == PHY_VACANT || | 946 | if (ex->ex_phy[i].phy_state == PHY_VACANT || |
946 | ex->ex_phy[i].phy_state == PHY_NOT_PRESENT) | 947 | ex->ex_phy[i].phy_state == PHY_NOT_PRESENT) |
947 | continue; | 948 | continue; |
948 | 949 | /* | |
950 | * Due to races, the phy might not get added to the | ||
951 | * wide port, so we add the phy to the wide port here. | ||
952 | */ | ||
949 | if (SAS_ADDR(ex->ex_phy[i].attached_sas_addr) == | 953 | if (SAS_ADDR(ex->ex_phy[i].attached_sas_addr) == |
950 | SAS_ADDR(child->sas_addr)) | 954 | SAS_ADDR(child->sas_addr)) { |
951 | ex->ex_phy[i].phy_state= PHY_DEVICE_DISCOVERED; | 955 | ex->ex_phy[i].phy_state= PHY_DEVICE_DISCOVERED; |
956 | res = sas_ex_join_wide_port(dev, i); | ||
957 | if (!res) | ||
958 | SAS_DPRINTK("Attaching ex phy%d to wide port %016llx\n", | ||
959 | i, SAS_ADDR(ex->ex_phy[i].attached_sas_addr)); | ||
960 | |||
961 | } | ||
952 | } | 962 | } |
963 | res = 0; | ||
953 | } | 964 | } |
954 | 965 | ||
955 | return res; | 966 | return res; |
@@ -1598,7 +1609,7 @@ static int sas_get_phy_attached_sas_addr(struct domain_device *dev, | |||
1598 | } | 1609 | } |
1599 | 1610 | ||
1600 | static int sas_find_bcast_phy(struct domain_device *dev, int *phy_id, | 1611 | static int sas_find_bcast_phy(struct domain_device *dev, int *phy_id, |
1601 | int from_phy) | 1612 | int from_phy, bool update) |
1602 | { | 1613 | { |
1603 | struct expander_device *ex = &dev->ex_dev; | 1614 | struct expander_device *ex = &dev->ex_dev; |
1604 | int res = 0; | 1615 | int res = 0; |
@@ -1611,7 +1622,9 @@ static int sas_find_bcast_phy(struct domain_device *dev, int *phy_id, | |||
1611 | if (res) | 1622 | if (res) |
1612 | goto out; | 1623 | goto out; |
1613 | else if (phy_change_count != ex->ex_phy[i].phy_change_count) { | 1624 | else if (phy_change_count != ex->ex_phy[i].phy_change_count) { |
1614 | ex->ex_phy[i].phy_change_count = phy_change_count; | 1625 | if (update) |
1626 | ex->ex_phy[i].phy_change_count = | ||
1627 | phy_change_count; | ||
1615 | *phy_id = i; | 1628 | *phy_id = i; |
1616 | return 0; | 1629 | return 0; |
1617 | } | 1630 | } |
@@ -1653,31 +1666,52 @@ out: | |||
1653 | kfree(rg_req); | 1666 | kfree(rg_req); |
1654 | return res; | 1667 | return res; |
1655 | } | 1668 | } |
1669 | /** | ||
1670 | * sas_find_bcast_dev - find the device issue BROADCAST(CHANGE). | ||
1671 | * @dev:domain device to be detect. | ||
1672 | * @src_dev: the device which originated BROADCAST(CHANGE). | ||
1673 | * | ||
1674 | * Add self-configuration expander suport. Suppose two expander cascading, | ||
1675 | * when the first level expander is self-configuring, hotplug the disks in | ||
1676 | * second level expander, BROADCAST(CHANGE) will not only be originated | ||
1677 | * in the second level expander, but also be originated in the first level | ||
1678 | * expander (see SAS protocol SAS 2r-14, 7.11 for detail), it is to say, | ||
1679 | * expander changed count in two level expanders will all increment at least | ||
1680 | * once, but the phy which chang count has changed is the source device which | ||
1681 | * we concerned. | ||
1682 | */ | ||
1656 | 1683 | ||
1657 | static int sas_find_bcast_dev(struct domain_device *dev, | 1684 | static int sas_find_bcast_dev(struct domain_device *dev, |
1658 | struct domain_device **src_dev) | 1685 | struct domain_device **src_dev) |
1659 | { | 1686 | { |
1660 | struct expander_device *ex = &dev->ex_dev; | 1687 | struct expander_device *ex = &dev->ex_dev; |
1661 | int ex_change_count = -1; | 1688 | int ex_change_count = -1; |
1689 | int phy_id = -1; | ||
1662 | int res; | 1690 | int res; |
1691 | struct domain_device *ch; | ||
1663 | 1692 | ||
1664 | res = sas_get_ex_change_count(dev, &ex_change_count); | 1693 | res = sas_get_ex_change_count(dev, &ex_change_count); |
1665 | if (res) | 1694 | if (res) |
1666 | goto out; | 1695 | goto out; |
1667 | if (ex_change_count != -1 && | 1696 | if (ex_change_count != -1 && ex_change_count != ex->ex_change_count) { |
1668 | ex_change_count != ex->ex_change_count) { | 1697 | /* Just detect if this expander phys phy change count changed, |
1669 | *src_dev = dev; | 1698 | * in order to determine if this expander originate BROADCAST, |
1670 | ex->ex_change_count = ex_change_count; | 1699 | * and do not update phy change count field in our structure. |
1671 | } else { | 1700 | */ |
1672 | struct domain_device *ch; | 1701 | res = sas_find_bcast_phy(dev, &phy_id, 0, false); |
1673 | 1702 | if (phy_id != -1) { | |
1674 | list_for_each_entry(ch, &ex->children, siblings) { | 1703 | *src_dev = dev; |
1675 | if (ch->dev_type == EDGE_DEV || | 1704 | ex->ex_change_count = ex_change_count; |
1676 | ch->dev_type == FANOUT_DEV) { | 1705 | SAS_DPRINTK("Expander phy change count has changed\n"); |
1677 | res = sas_find_bcast_dev(ch, src_dev); | 1706 | return res; |
1678 | if (src_dev) | 1707 | } else |
1679 | return res; | 1708 | SAS_DPRINTK("Expander phys DID NOT change\n"); |
1680 | } | 1709 | } |
1710 | list_for_each_entry(ch, &ex->children, siblings) { | ||
1711 | if (ch->dev_type == EDGE_DEV || ch->dev_type == FANOUT_DEV) { | ||
1712 | res = sas_find_bcast_dev(ch, src_dev); | ||
1713 | if (src_dev) | ||
1714 | return res; | ||
1681 | } | 1715 | } |
1682 | } | 1716 | } |
1683 | out: | 1717 | out: |
@@ -1700,24 +1734,26 @@ static void sas_unregister_ex_tree(struct domain_device *dev) | |||
1700 | } | 1734 | } |
1701 | 1735 | ||
1702 | static void sas_unregister_devs_sas_addr(struct domain_device *parent, | 1736 | static void sas_unregister_devs_sas_addr(struct domain_device *parent, |
1703 | int phy_id) | 1737 | int phy_id, bool last) |
1704 | { | 1738 | { |
1705 | struct expander_device *ex_dev = &parent->ex_dev; | 1739 | struct expander_device *ex_dev = &parent->ex_dev; |
1706 | struct ex_phy *phy = &ex_dev->ex_phy[phy_id]; | 1740 | struct ex_phy *phy = &ex_dev->ex_phy[phy_id]; |
1707 | struct domain_device *child, *n; | 1741 | struct domain_device *child, *n; |
1708 | 1742 | if (last) { | |
1709 | list_for_each_entry_safe(child, n, &ex_dev->children, siblings) { | 1743 | list_for_each_entry_safe(child, n, |
1710 | if (SAS_ADDR(child->sas_addr) == | 1744 | &ex_dev->children, siblings) { |
1711 | SAS_ADDR(phy->attached_sas_addr)) { | 1745 | if (SAS_ADDR(child->sas_addr) == |
1712 | if (child->dev_type == EDGE_DEV || | 1746 | SAS_ADDR(phy->attached_sas_addr)) { |
1713 | child->dev_type == FANOUT_DEV) | 1747 | if (child->dev_type == EDGE_DEV || |
1714 | sas_unregister_ex_tree(child); | 1748 | child->dev_type == FANOUT_DEV) |
1715 | else | 1749 | sas_unregister_ex_tree(child); |
1716 | sas_unregister_dev(child); | 1750 | else |
1717 | break; | 1751 | sas_unregister_dev(child); |
1752 | break; | ||
1753 | } | ||
1718 | } | 1754 | } |
1755 | sas_disable_routing(parent, phy->attached_sas_addr); | ||
1719 | } | 1756 | } |
1720 | sas_disable_routing(parent, phy->attached_sas_addr); | ||
1721 | memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); | 1757 | memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE); |
1722 | sas_port_delete_phy(phy->port, phy->phy); | 1758 | sas_port_delete_phy(phy->port, phy->phy); |
1723 | if (phy->port->num_phys == 0) | 1759 | if (phy->port->num_phys == 0) |
@@ -1770,15 +1806,31 @@ static int sas_discover_new(struct domain_device *dev, int phy_id) | |||
1770 | { | 1806 | { |
1771 | struct ex_phy *ex_phy = &dev->ex_dev.ex_phy[phy_id]; | 1807 | struct ex_phy *ex_phy = &dev->ex_dev.ex_phy[phy_id]; |
1772 | struct domain_device *child; | 1808 | struct domain_device *child; |
1773 | int res; | 1809 | bool found = false; |
1810 | int res, i; | ||
1774 | 1811 | ||
1775 | SAS_DPRINTK("ex %016llx phy%d new device attached\n", | 1812 | SAS_DPRINTK("ex %016llx phy%d new device attached\n", |
1776 | SAS_ADDR(dev->sas_addr), phy_id); | 1813 | SAS_ADDR(dev->sas_addr), phy_id); |
1777 | res = sas_ex_phy_discover(dev, phy_id); | 1814 | res = sas_ex_phy_discover(dev, phy_id); |
1778 | if (res) | 1815 | if (res) |
1779 | goto out; | 1816 | goto out; |
1817 | /* to support the wide port inserted */ | ||
1818 | for (i = 0; i < dev->ex_dev.num_phys; i++) { | ||
1819 | struct ex_phy *ex_phy_temp = &dev->ex_dev.ex_phy[i]; | ||
1820 | if (i == phy_id) | ||
1821 | continue; | ||
1822 | if (SAS_ADDR(ex_phy_temp->attached_sas_addr) == | ||
1823 | SAS_ADDR(ex_phy->attached_sas_addr)) { | ||
1824 | found = true; | ||
1825 | break; | ||
1826 | } | ||
1827 | } | ||
1828 | if (found) { | ||
1829 | sas_ex_join_wide_port(dev, phy_id); | ||
1830 | return 0; | ||
1831 | } | ||
1780 | res = sas_ex_discover_devices(dev, phy_id); | 1832 | res = sas_ex_discover_devices(dev, phy_id); |
1781 | if (res) | 1833 | if (!res) |
1782 | goto out; | 1834 | goto out; |
1783 | list_for_each_entry(child, &dev->ex_dev.children, siblings) { | 1835 | list_for_each_entry(child, &dev->ex_dev.children, siblings) { |
1784 | if (SAS_ADDR(child->sas_addr) == | 1836 | if (SAS_ADDR(child->sas_addr) == |
@@ -1793,7 +1845,7 @@ out: | |||
1793 | return res; | 1845 | return res; |
1794 | } | 1846 | } |
1795 | 1847 | ||
1796 | static int sas_rediscover_dev(struct domain_device *dev, int phy_id) | 1848 | static int sas_rediscover_dev(struct domain_device *dev, int phy_id, bool last) |
1797 | { | 1849 | { |
1798 | struct expander_device *ex = &dev->ex_dev; | 1850 | struct expander_device *ex = &dev->ex_dev; |
1799 | struct ex_phy *phy = &ex->ex_phy[phy_id]; | 1851 | struct ex_phy *phy = &ex->ex_phy[phy_id]; |
@@ -1804,11 +1856,11 @@ static int sas_rediscover_dev(struct domain_device *dev, int phy_id) | |||
1804 | switch (res) { | 1856 | switch (res) { |
1805 | case SMP_RESP_NO_PHY: | 1857 | case SMP_RESP_NO_PHY: |
1806 | phy->phy_state = PHY_NOT_PRESENT; | 1858 | phy->phy_state = PHY_NOT_PRESENT; |
1807 | sas_unregister_devs_sas_addr(dev, phy_id); | 1859 | sas_unregister_devs_sas_addr(dev, phy_id, last); |
1808 | goto out; break; | 1860 | goto out; break; |
1809 | case SMP_RESP_PHY_VACANT: | 1861 | case SMP_RESP_PHY_VACANT: |
1810 | phy->phy_state = PHY_VACANT; | 1862 | phy->phy_state = PHY_VACANT; |
1811 | sas_unregister_devs_sas_addr(dev, phy_id); | 1863 | sas_unregister_devs_sas_addr(dev, phy_id, last); |
1812 | goto out; break; | 1864 | goto out; break; |
1813 | case SMP_RESP_FUNC_ACC: | 1865 | case SMP_RESP_FUNC_ACC: |
1814 | break; | 1866 | break; |
@@ -1816,7 +1868,7 @@ static int sas_rediscover_dev(struct domain_device *dev, int phy_id) | |||
1816 | 1868 | ||
1817 | if (SAS_ADDR(attached_sas_addr) == 0) { | 1869 | if (SAS_ADDR(attached_sas_addr) == 0) { |
1818 | phy->phy_state = PHY_EMPTY; | 1870 | phy->phy_state = PHY_EMPTY; |
1819 | sas_unregister_devs_sas_addr(dev, phy_id); | 1871 | sas_unregister_devs_sas_addr(dev, phy_id, last); |
1820 | } else if (SAS_ADDR(attached_sas_addr) == | 1872 | } else if (SAS_ADDR(attached_sas_addr) == |
1821 | SAS_ADDR(phy->attached_sas_addr)) { | 1873 | SAS_ADDR(phy->attached_sas_addr)) { |
1822 | SAS_DPRINTK("ex %016llx phy 0x%x broadcast flutter\n", | 1874 | SAS_DPRINTK("ex %016llx phy 0x%x broadcast flutter\n", |
@@ -1828,12 +1880,27 @@ out: | |||
1828 | return res; | 1880 | return res; |
1829 | } | 1881 | } |
1830 | 1882 | ||
1883 | /** | ||
1884 | * sas_rediscover - revalidate the domain. | ||
1885 | * @dev:domain device to be detect. | ||
1886 | * @phy_id: the phy id will be detected. | ||
1887 | * | ||
1888 | * NOTE: this process _must_ quit (return) as soon as any connection | ||
1889 | * errors are encountered. Connection recovery is done elsewhere. | ||
1890 | * Discover process only interrogates devices in order to discover the | ||
1891 | * domain.For plugging out, we un-register the device only when it is | ||
1892 | * the last phy in the port, for other phys in this port, we just delete it | ||
1893 | * from the port.For inserting, we do discovery when it is the | ||
1894 | * first phy,for other phys in this port, we add it to the port to | ||
1895 | * forming the wide-port. | ||
1896 | */ | ||
1831 | static int sas_rediscover(struct domain_device *dev, const int phy_id) | 1897 | static int sas_rediscover(struct domain_device *dev, const int phy_id) |
1832 | { | 1898 | { |
1833 | struct expander_device *ex = &dev->ex_dev; | 1899 | struct expander_device *ex = &dev->ex_dev; |
1834 | struct ex_phy *changed_phy = &ex->ex_phy[phy_id]; | 1900 | struct ex_phy *changed_phy = &ex->ex_phy[phy_id]; |
1835 | int res = 0; | 1901 | int res = 0; |
1836 | int i; | 1902 | int i; |
1903 | bool last = true; /* is this the last phy of the port */ | ||
1837 | 1904 | ||
1838 | SAS_DPRINTK("ex %016llx phy%d originated BROADCAST(CHANGE)\n", | 1905 | SAS_DPRINTK("ex %016llx phy%d originated BROADCAST(CHANGE)\n", |
1839 | SAS_ADDR(dev->sas_addr), phy_id); | 1906 | SAS_ADDR(dev->sas_addr), phy_id); |
@@ -1848,13 +1915,13 @@ static int sas_rediscover(struct domain_device *dev, const int phy_id) | |||
1848 | SAS_ADDR(changed_phy->attached_sas_addr)) { | 1915 | SAS_ADDR(changed_phy->attached_sas_addr)) { |
1849 | SAS_DPRINTK("phy%d part of wide port with " | 1916 | SAS_DPRINTK("phy%d part of wide port with " |
1850 | "phy%d\n", phy_id, i); | 1917 | "phy%d\n", phy_id, i); |
1851 | goto out; | 1918 | last = false; |
1919 | break; | ||
1852 | } | 1920 | } |
1853 | } | 1921 | } |
1854 | res = sas_rediscover_dev(dev, phy_id); | 1922 | res = sas_rediscover_dev(dev, phy_id, last); |
1855 | } else | 1923 | } else |
1856 | res = sas_discover_new(dev, phy_id); | 1924 | res = sas_discover_new(dev, phy_id); |
1857 | out: | ||
1858 | return res; | 1925 | return res; |
1859 | } | 1926 | } |
1860 | 1927 | ||
@@ -1881,7 +1948,7 @@ int sas_ex_revalidate_domain(struct domain_device *port_dev) | |||
1881 | 1948 | ||
1882 | do { | 1949 | do { |
1883 | phy_id = -1; | 1950 | phy_id = -1; |
1884 | res = sas_find_bcast_phy(dev, &phy_id, i); | 1951 | res = sas_find_bcast_phy(dev, &phy_id, i, true); |
1885 | if (phy_id == -1) | 1952 | if (phy_id == -1) |
1886 | break; | 1953 | break; |
1887 | res = sas_rediscover(dev, phy_id); | 1954 | res = sas_rediscover(dev, phy_id); |