diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2012-06-18 14:10:39 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2012-06-18 14:10:39 -0400 |
commit | 47fcb6da65e9e74f71f4ec68f1245fc600bec711 (patch) | |
tree | 6ef869c8f5768d8804ace7c36bbd6d493f995ad1 | |
parent | cc2fa3fa320d5f40a12713c104bbe5d3da4636e4 (diff) | |
parent | 9cb604ed45a31419bab3877472691a5da15a3c47 (diff) |
Merge branch 'topic/stowe-cap-cleanup' into next
* topic/stowe-cap-cleanup:
PCI: remove redundant capabilities checking in pci_{save, restore}_pcie_state
PCI: add pci_pcie_cap2() check for PCIe feature capabilities >= v2
PCI: remove redundant checking in PCI Express capability routines
PCI: make pci_ltr_supported() static
-rw-r--r-- | drivers/pci/pci.c | 115 | ||||
-rw-r--r-- | include/linux/pci.h | 1 | ||||
-rw-r--r-- | include/linux/pci_regs.h | 6 |
3 files changed, 73 insertions, 49 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b743a9afb4dd..ae5d96ac2aac 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -254,6 +254,38 @@ int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap) | |||
254 | } | 254 | } |
255 | 255 | ||
256 | /** | 256 | /** |
257 | * pci_pcie_cap2 - query for devices' PCI_CAP_ID_EXP v2 capability structure | ||
258 | * @dev: PCI device to check | ||
259 | * | ||
260 | * Like pci_pcie_cap() but also checks that the PCIe capability version is | ||
261 | * >= 2. Note that v1 capability structures could be sparse in that not | ||
262 | * all register fields were required. v2 requires the entire structure to | ||
263 | * be present size wise, while still allowing for non-implemented registers | ||
264 | * to exist but they must be hardwired to 0. | ||
265 | * | ||
266 | * Due to the differences in the versions of capability structures, one | ||
267 | * must be careful not to try and access non-existant registers that may | ||
268 | * exist in early versions - v1 - of Express devices. | ||
269 | * | ||
270 | * Returns the offset of the PCIe capability structure as long as the | ||
271 | * capability version is >= 2; otherwise 0 is returned. | ||
272 | */ | ||
273 | static int pci_pcie_cap2(struct pci_dev *dev) | ||
274 | { | ||
275 | u16 flags; | ||
276 | int pos; | ||
277 | |||
278 | pos = pci_pcie_cap(dev); | ||
279 | if (pos) { | ||
280 | pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags); | ||
281 | if ((flags & PCI_EXP_FLAGS_VERS) < 2) | ||
282 | pos = 0; | ||
283 | } | ||
284 | |||
285 | return pos; | ||
286 | } | ||
287 | |||
288 | /** | ||
257 | * pci_find_ext_capability - Find an extended capability | 289 | * pci_find_ext_capability - Find an extended capability |
258 | * @dev: PCI device to query | 290 | * @dev: PCI device to query |
259 | * @cap: capability code | 291 | * @cap: capability code |
@@ -755,12 +787,6 @@ EXPORT_SYMBOL(pci_choose_state); | |||
755 | ((flags & PCI_EXP_FLAGS_VERS) > 1 || \ | 787 | ((flags & PCI_EXP_FLAGS_VERS) > 1 || \ |
756 | (type == PCI_EXP_TYPE_ROOT_PORT || \ | 788 | (type == PCI_EXP_TYPE_ROOT_PORT || \ |
757 | type == PCI_EXP_TYPE_RC_EC)) | 789 | type == PCI_EXP_TYPE_RC_EC)) |
758 | #define pcie_cap_has_devctl2(type, flags) \ | ||
759 | ((flags & PCI_EXP_FLAGS_VERS) > 1) | ||
760 | #define pcie_cap_has_lnkctl2(type, flags) \ | ||
761 | ((flags & PCI_EXP_FLAGS_VERS) > 1) | ||
762 | #define pcie_cap_has_sltctl2(type, flags) \ | ||
763 | ((flags & PCI_EXP_FLAGS_VERS) > 1) | ||
764 | 790 | ||
765 | static struct pci_cap_saved_state *pci_find_saved_cap( | 791 | static struct pci_cap_saved_state *pci_find_saved_cap( |
766 | struct pci_dev *pci_dev, char cap) | 792 | struct pci_dev *pci_dev, char cap) |
@@ -803,13 +829,14 @@ static int pci_save_pcie_state(struct pci_dev *dev) | |||
803 | pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]); | 829 | pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]); |
804 | if (pcie_cap_has_rtctl(dev->pcie_type, flags)) | 830 | if (pcie_cap_has_rtctl(dev->pcie_type, flags)) |
805 | pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]); | 831 | pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]); |
806 | if (pcie_cap_has_devctl2(dev->pcie_type, flags)) | ||
807 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &cap[i++]); | ||
808 | if (pcie_cap_has_lnkctl2(dev->pcie_type, flags)) | ||
809 | pci_read_config_word(dev, pos + PCI_EXP_LNKCTL2, &cap[i++]); | ||
810 | if (pcie_cap_has_sltctl2(dev->pcie_type, flags)) | ||
811 | pci_read_config_word(dev, pos + PCI_EXP_SLTCTL2, &cap[i++]); | ||
812 | 832 | ||
833 | pos = pci_pcie_cap2(dev); | ||
834 | if (!pos) | ||
835 | return 0; | ||
836 | |||
837 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &cap[i++]); | ||
838 | pci_read_config_word(dev, pos + PCI_EXP_LNKCTL2, &cap[i++]); | ||
839 | pci_read_config_word(dev, pos + PCI_EXP_SLTCTL2, &cap[i++]); | ||
813 | return 0; | 840 | return 0; |
814 | } | 841 | } |
815 | 842 | ||
@@ -836,12 +863,14 @@ static void pci_restore_pcie_state(struct pci_dev *dev) | |||
836 | pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]); | 863 | pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]); |
837 | if (pcie_cap_has_rtctl(dev->pcie_type, flags)) | 864 | if (pcie_cap_has_rtctl(dev->pcie_type, flags)) |
838 | pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]); | 865 | pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]); |
839 | if (pcie_cap_has_devctl2(dev->pcie_type, flags)) | 866 | |
840 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, cap[i++]); | 867 | pos = pci_pcie_cap2(dev); |
841 | if (pcie_cap_has_lnkctl2(dev->pcie_type, flags)) | 868 | if (!pos) |
842 | pci_write_config_word(dev, pos + PCI_EXP_LNKCTL2, cap[i++]); | 869 | return; |
843 | if (pcie_cap_has_sltctl2(dev->pcie_type, flags)) | 870 | |
844 | pci_write_config_word(dev, pos + PCI_EXP_SLTCTL2, cap[i++]); | 871 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, cap[i++]); |
872 | pci_write_config_word(dev, pos + PCI_EXP_LNKCTL2, cap[i++]); | ||
873 | pci_write_config_word(dev, pos + PCI_EXP_SLTCTL2, cap[i++]); | ||
845 | } | 874 | } |
846 | 875 | ||
847 | 876 | ||
@@ -1916,7 +1945,7 @@ void pci_enable_ari(struct pci_dev *dev) | |||
1916 | { | 1945 | { |
1917 | int pos; | 1946 | int pos; |
1918 | u32 cap; | 1947 | u32 cap; |
1919 | u16 flags, ctrl; | 1948 | u16 ctrl; |
1920 | struct pci_dev *bridge; | 1949 | struct pci_dev *bridge; |
1921 | 1950 | ||
1922 | if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) | 1951 | if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) |
@@ -1927,18 +1956,14 @@ void pci_enable_ari(struct pci_dev *dev) | |||
1927 | return; | 1956 | return; |
1928 | 1957 | ||
1929 | bridge = dev->bus->self; | 1958 | bridge = dev->bus->self; |
1930 | if (!bridge || !pci_is_pcie(bridge)) | 1959 | if (!bridge) |
1931 | return; | 1960 | return; |
1932 | 1961 | ||
1933 | pos = pci_pcie_cap(bridge); | 1962 | /* ARI is a PCIe cap v2 feature */ |
1963 | pos = pci_pcie_cap2(bridge); | ||
1934 | if (!pos) | 1964 | if (!pos) |
1935 | return; | 1965 | return; |
1936 | 1966 | ||
1937 | /* ARI is a PCIe v2 feature */ | ||
1938 | pci_read_config_word(bridge, pos + PCI_EXP_FLAGS, &flags); | ||
1939 | if ((flags & PCI_EXP_FLAGS_VERS) < 2) | ||
1940 | return; | ||
1941 | |||
1942 | pci_read_config_dword(bridge, pos + PCI_EXP_DEVCAP2, &cap); | 1967 | pci_read_config_dword(bridge, pos + PCI_EXP_DEVCAP2, &cap); |
1943 | if (!(cap & PCI_EXP_DEVCAP2_ARI)) | 1968 | if (!(cap & PCI_EXP_DEVCAP2_ARI)) |
1944 | return; | 1969 | return; |
@@ -1951,7 +1976,7 @@ void pci_enable_ari(struct pci_dev *dev) | |||
1951 | } | 1976 | } |
1952 | 1977 | ||
1953 | /** | 1978 | /** |
1954 | * pci_enable_ido - enable ID-based ordering on a device | 1979 | * pci_enable_ido - enable ID-based Ordering on a device |
1955 | * @dev: the PCI device | 1980 | * @dev: the PCI device |
1956 | * @type: which types of IDO to enable | 1981 | * @type: which types of IDO to enable |
1957 | * | 1982 | * |
@@ -1964,7 +1989,8 @@ void pci_enable_ido(struct pci_dev *dev, unsigned long type) | |||
1964 | int pos; | 1989 | int pos; |
1965 | u16 ctrl; | 1990 | u16 ctrl; |
1966 | 1991 | ||
1967 | pos = pci_pcie_cap(dev); | 1992 | /* ID-based Ordering is a PCIe cap v2 feature */ |
1993 | pos = pci_pcie_cap2(dev); | ||
1968 | if (!pos) | 1994 | if (!pos) |
1969 | return; | 1995 | return; |
1970 | 1996 | ||
@@ -1987,10 +2013,8 @@ void pci_disable_ido(struct pci_dev *dev, unsigned long type) | |||
1987 | int pos; | 2013 | int pos; |
1988 | u16 ctrl; | 2014 | u16 ctrl; |
1989 | 2015 | ||
1990 | if (!pci_is_pcie(dev)) | 2016 | /* ID-based Ordering is a PCIe cap v2 feature */ |
1991 | return; | 2017 | pos = pci_pcie_cap2(dev); |
1992 | |||
1993 | pos = pci_pcie_cap(dev); | ||
1994 | if (!pos) | 2018 | if (!pos) |
1995 | return; | 2019 | return; |
1996 | 2020 | ||
@@ -2029,10 +2053,8 @@ int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type) | |||
2029 | u16 ctrl; | 2053 | u16 ctrl; |
2030 | int ret; | 2054 | int ret; |
2031 | 2055 | ||
2032 | if (!pci_is_pcie(dev)) | 2056 | /* OBFF is a PCIe cap v2 feature */ |
2033 | return -ENOTSUPP; | 2057 | pos = pci_pcie_cap2(dev); |
2034 | |||
2035 | pos = pci_pcie_cap(dev); | ||
2036 | if (!pos) | 2058 | if (!pos) |
2037 | return -ENOTSUPP; | 2059 | return -ENOTSUPP; |
2038 | 2060 | ||
@@ -2082,10 +2104,8 @@ void pci_disable_obff(struct pci_dev *dev) | |||
2082 | int pos; | 2104 | int pos; |
2083 | u16 ctrl; | 2105 | u16 ctrl; |
2084 | 2106 | ||
2085 | if (!pci_is_pcie(dev)) | 2107 | /* OBFF is a PCIe cap v2 feature */ |
2086 | return; | 2108 | pos = pci_pcie_cap2(dev); |
2087 | |||
2088 | pos = pci_pcie_cap(dev); | ||
2089 | if (!pos) | 2109 | if (!pos) |
2090 | return; | 2110 | return; |
2091 | 2111 | ||
@@ -2102,15 +2122,13 @@ EXPORT_SYMBOL(pci_disable_obff); | |||
2102 | * RETURNS: | 2122 | * RETURNS: |
2103 | * True if @dev supports latency tolerance reporting, false otherwise. | 2123 | * True if @dev supports latency tolerance reporting, false otherwise. |
2104 | */ | 2124 | */ |
2105 | bool pci_ltr_supported(struct pci_dev *dev) | 2125 | static bool pci_ltr_supported(struct pci_dev *dev) |
2106 | { | 2126 | { |
2107 | int pos; | 2127 | int pos; |
2108 | u32 cap; | 2128 | u32 cap; |
2109 | 2129 | ||
2110 | if (!pci_is_pcie(dev)) | 2130 | /* LTR is a PCIe cap v2 feature */ |
2111 | return false; | 2131 | pos = pci_pcie_cap2(dev); |
2112 | |||
2113 | pos = pci_pcie_cap(dev); | ||
2114 | if (!pos) | 2132 | if (!pos) |
2115 | return false; | 2133 | return false; |
2116 | 2134 | ||
@@ -2118,7 +2136,6 @@ bool pci_ltr_supported(struct pci_dev *dev) | |||
2118 | 2136 | ||
2119 | return cap & PCI_EXP_DEVCAP2_LTR; | 2137 | return cap & PCI_EXP_DEVCAP2_LTR; |
2120 | } | 2138 | } |
2121 | EXPORT_SYMBOL(pci_ltr_supported); | ||
2122 | 2139 | ||
2123 | /** | 2140 | /** |
2124 | * pci_enable_ltr - enable latency tolerance reporting | 2141 | * pci_enable_ltr - enable latency tolerance reporting |
@@ -2139,7 +2156,8 @@ int pci_enable_ltr(struct pci_dev *dev) | |||
2139 | if (!pci_ltr_supported(dev)) | 2156 | if (!pci_ltr_supported(dev)) |
2140 | return -ENOTSUPP; | 2157 | return -ENOTSUPP; |
2141 | 2158 | ||
2142 | pos = pci_pcie_cap(dev); | 2159 | /* LTR is a PCIe cap v2 feature */ |
2160 | pos = pci_pcie_cap2(dev); | ||
2143 | if (!pos) | 2161 | if (!pos) |
2144 | return -ENOTSUPP; | 2162 | return -ENOTSUPP; |
2145 | 2163 | ||
@@ -2174,7 +2192,8 @@ void pci_disable_ltr(struct pci_dev *dev) | |||
2174 | if (!pci_ltr_supported(dev)) | 2192 | if (!pci_ltr_supported(dev)) |
2175 | return; | 2193 | return; |
2176 | 2194 | ||
2177 | pos = pci_pcie_cap(dev); | 2195 | /* LTR is a PCIe cap v2 feature */ |
2196 | pos = pci_pcie_cap2(dev); | ||
2178 | if (!pos) | 2197 | if (!pos) |
2179 | return; | 2198 | return; |
2180 | 2199 | ||
diff --git a/include/linux/pci.h b/include/linux/pci.h index 35884f279bb8..43a007cbdf65 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h | |||
@@ -911,7 +911,6 @@ enum pci_obff_signal_type { | |||
911 | int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type); | 911 | int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type); |
912 | void pci_disable_obff(struct pci_dev *dev); | 912 | void pci_disable_obff(struct pci_dev *dev); |
913 | 913 | ||
914 | bool pci_ltr_supported(struct pci_dev *dev); | ||
915 | int pci_enable_ltr(struct pci_dev *dev); | 914 | int pci_enable_ltr(struct pci_dev *dev); |
916 | void pci_disable_ltr(struct pci_dev *dev); | 915 | void pci_disable_ltr(struct pci_dev *dev); |
917 | int pci_set_ltr(struct pci_dev *dev, int snoop_lat_ns, int nosnoop_lat_ns); | 916 | int pci_set_ltr(struct pci_dev *dev, int snoop_lat_ns, int nosnoop_lat_ns); |
diff --git a/include/linux/pci_regs.h b/include/linux/pci_regs.h index 526d2c4bc3a6..80e8605b5f93 100644 --- a/include/linux/pci_regs.h +++ b/include/linux/pci_regs.h | |||
@@ -521,6 +521,12 @@ | |||
521 | #define PCI_EXP_RTSTA 32 /* Root Status */ | 521 | #define PCI_EXP_RTSTA 32 /* Root Status */ |
522 | #define PCI_EXP_RTSTA_PME 0x10000 /* PME status */ | 522 | #define PCI_EXP_RTSTA_PME 0x10000 /* PME status */ |
523 | #define PCI_EXP_RTSTA_PENDING 0x20000 /* PME pending */ | 523 | #define PCI_EXP_RTSTA_PENDING 0x20000 /* PME pending */ |
524 | /* | ||
525 | * Note that the following PCI Express 'Capability Structure' registers | ||
526 | * were introduced with 'Capability Version' 0x2 (v2). These registers | ||
527 | * do not exist on devices with Capability Version 1. Use pci_pcie_cap2() | ||
528 | * to use these fields safely. | ||
529 | */ | ||
524 | #define PCI_EXP_DEVCAP2 36 /* Device Capabilities 2 */ | 530 | #define PCI_EXP_DEVCAP2 36 /* Device Capabilities 2 */ |
525 | #define PCI_EXP_DEVCAP2_ARI 0x20 /* Alternative Routing-ID */ | 531 | #define PCI_EXP_DEVCAP2_ARI 0x20 /* Alternative Routing-ID */ |
526 | #define PCI_EXP_DEVCAP2_LTR 0x800 /* Latency tolerance reporting */ | 532 | #define PCI_EXP_DEVCAP2_LTR 0x800 /* Latency tolerance reporting */ |